annotate loader/ext.c @ 2623:0d8f8d313f9c

fixed fault with --help
author alex
date Fri, 02 Nov 2001 02:21:57 +0000
parents ce45cce7f7a5
children 958d10763c34
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 /********************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 * Stub functions for Wine module
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 ********************************************************/
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 #include <config.h>
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
9 #include <stdio.h>
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
10 #include <stdlib.h>
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 #ifdef HAVE_MALLOC_H
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 #include <malloc.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 #include <unistd.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 #include <sys/mman.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 #include <errno.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 #include <fcntl.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 #include <string.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 #include <stdarg.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 #include <wine/windef.h>
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
21 #include <wine/winbase.h>
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
22 #include <wine/debugtools.h>
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
23 #include <wine/heap.h>
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
24 #include "ext.h"
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
25
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 int dbg_header_err( const char *dbg_channel, const char *func )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 int dbg_header_warn( const char *dbg_channel, const char *func )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 int dbg_header_fixme( const char *dbg_channel, const char *func )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 int dbg_header_trace( const char *dbg_channel, const char *func )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 }
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
42 int dbg_vprintf( const char *format, va_list args )
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 int __vprintf( const char *format, ... )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 #ifdef DETAILED_OUT
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 va_list va;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 va_start(va, format);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 vprintf(format, va);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 va_end(va);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
57 HANDLE WINAPI GetProcessHeap(void)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
62 LPVOID WINAPI HeapAlloc(HANDLE heap, DWORD flags, DWORD size)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 if(flags & 0x8)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 return calloc(size, 1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 return malloc(size);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
70 WIN_BOOL WINAPI HeapFree(HANDLE heap, DWORD flags, LPVOID mem)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 {
128
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
72 if (mem) free(mem);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 static int last_error;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
78 DWORD WINAPI GetLastError(void)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 return last_error;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
83 VOID WINAPI SetLastError(DWORD error)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 {
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
85 last_error=error;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
88 WIN_BOOL WINAPI ReadFile(HANDLE handle, LPVOID mem, DWORD size, LPDWORD result, LPOVERLAPPED flags)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 *result=read(handle, mem, size);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 return *result;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 }
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
93 INT WINAPI lstrcmpiA(LPCSTR c1, LPCSTR c2)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 return strcasecmp(c1,c2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 }
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
97 LPSTR WINAPI lstrcpynA(LPSTR dest, LPCSTR src, INT num)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 {
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
99 return strncpy(dest,src,num);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 }
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
101 INT WINAPI lstrlenA(LPCSTR s)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 return strlen(s);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 }
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
105 INT WINAPI lstrlenW(LPCWSTR s)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 int l;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 if(!s)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 l=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 while(s[l])
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 l++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 return l;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 }
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
115 LPSTR WINAPI lstrcpynWtoA(LPSTR dest, LPCWSTR src, INT count)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 {
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
117 LPSTR result = dest;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 int moved=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 if((dest==0) || (src==0))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 while(moved<count)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 *dest=*src;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 moved++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 if(*src==0)
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
126 break;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 src++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 dest++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 }
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
130 return result;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 int wcsnicmp(const unsigned short* s1, const unsigned short* s2, int n)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 {
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
134 /*
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 if(s1==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 if(s2==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 return;
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
139 */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 while(n>0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 if(*s1<*s2)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 return -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 if(*s1>*s2)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 if(*s1==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 s1++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 s2++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 n--;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
158 WIN_BOOL WINAPI IsBadReadPtr(LPCVOID data, UINT size)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 if(size==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 if(data==NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165 }
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
166 LPSTR HEAP_strdupA(HANDLE heap, DWORD flags, LPCSTR string)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 // return strdup(string);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 char* answ=malloc(strlen(string)+1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 strcpy(answ, string);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 return answ;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 }
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
173 LPWSTR HEAP_strdupAtoW(HANDLE heap, DWORD flags, LPCSTR string)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 int size, i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 short* answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177 if(string==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 size=strlen(string);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 answer=malloc(size+size+2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181 for(i=0; i<=size; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 answer[i]=(short)string[i];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183 return answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
184 }
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
185 LPSTR HEAP_strdupWtoA(HANDLE heap, DWORD flags, LPCWSTR string)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187 int size, i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188 char* answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189 if(string==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
191 size=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192 while(string[size])
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193 size++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194 answer=malloc(size+2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195 for(i=0; i<=size; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
196 answer[i]=(char)string[i];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
197 return answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
199
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200 /***********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
201 * FILE_dommap
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 //#define MAP_PRIVATE
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205 //#define MAP_SHARED
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206 #undef MAP_ANON
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207 LPVOID FILE_dommap( int unix_handle, LPVOID start,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
208 DWORD size_high, DWORD size_low,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209 DWORD offset_high, DWORD offset_low,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210 int prot, int flags )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212 int fd = -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213 int pos;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214 LPVOID ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
216 if (size_high || offset_high)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
217 printf("offsets larger than 4Gb not supported\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
218
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219 if (unix_handle == -1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
220 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
221 #ifdef MAP_ANON
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
222 // printf("Anonymous\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
223 flags |= MAP_ANON;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
224 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225 static int fdzero = -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
226
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
227 if (fdzero == -1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
228 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
229 if ((fdzero = open( "/dev/zero", O_RDONLY )) == -1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
230 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
231 perror( "/dev/zero: open" );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
232 exit(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
235 fd = fdzero;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236 #endif /* MAP_ANON */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
237 /* Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
238 #ifdef MAP_SHARED
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
239 flags &= ~MAP_SHARED;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
240 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
241 #ifdef MAP_PRIVATE
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
242 flags |= MAP_PRIVATE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
243 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
244 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
245 else fd = unix_handle;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
246 // printf("fd %x, start %x, size %x, pos %x, prot %x\n",fd,start,size_low, offset_low, prot);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
247 // if ((ret = mmap( start, size_low, prot,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
248 // flags, fd, offset_low )) != (LPVOID)-1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249 if ((ret = mmap( start, size_low, prot,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
250 MAP_PRIVATE | MAP_FIXED, fd, offset_low )) != (LPVOID)-1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
251 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
252 // printf("address %08x\n", *(int*)ret);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253 // printf("%x\n", ret);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
256
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
257 // printf("mmap %d\n", errno);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
259 /* mmap() failed; if this is because the file offset is not */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
260 /* page-aligned (EINVAL), or because the underlying filesystem */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
261 /* does not support mmap() (ENOEXEC), we do it by hand. */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
262
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
263 if (unix_handle == -1) return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
264 if ((errno != ENOEXEC) && (errno != EINVAL)) return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
265 if (prot & PROT_WRITE)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
266 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
267 /* We cannot fake shared write mappings */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
268 #ifdef MAP_SHARED
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
269 if (flags & MAP_SHARED) return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
270 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
271 #ifdef MAP_PRIVATE
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
272 if (!(flags & MAP_PRIVATE)) return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
273 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
274 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
275 /* printf( "FILE_mmap: mmap failed (%d), faking it\n", errno );*/
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
276 /* Reserve the memory with an anonymous mmap */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
277 ret = FILE_dommap( -1, start, size_high, size_low, 0, 0,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
278 PROT_READ | PROT_WRITE, flags );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
279 if (ret == (LPVOID)-1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
280 // {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
281 // perror(
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
282 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
283 /* Now read in the file */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
284 if ((pos = lseek( fd, offset_low, SEEK_SET )) == -1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
285 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
286 FILE_munmap( ret, size_high, size_low );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
287 // printf("lseek\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
288 return (LPVOID)-1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
289 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
290 read( fd, ret, size_low );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
291 lseek( fd, pos, SEEK_SET ); /* Restore the file pointer */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
292 mprotect( ret, size_low, prot ); /* Set the right protection */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
293 // printf("address %08x\n", *(int*)ret);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
294 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
295 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
296
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
297
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
298 /***********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
299 * FILE_munmap
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
300 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
301 int FILE_munmap( LPVOID start, DWORD size_high, DWORD size_low )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
302 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
303 if (size_high)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
304 printf("offsets larger than 4Gb not supported\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
305 return munmap( start, size_low );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
306 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
307 static int mapping_size=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
308
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
309 struct file_mapping_s;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
310 typedef struct file_mapping_s
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
311 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
312 int mapping_size;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
313 char* name;
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
314 LPVOID handle;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
315 struct file_mapping_s* next;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
316 struct file_mapping_s* prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
317 }file_mapping;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
318 static file_mapping* fm=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
319
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
320
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
321
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
322 #define PAGE_NOACCESS 0x01
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
323 #define PAGE_READONLY 0x02
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
324 #define PAGE_READWRITE 0x04
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
325 #define PAGE_WRITECOPY 0x08
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
326 #define PAGE_EXECUTE 0x10
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
327 #define PAGE_EXECUTE_READ 0x20
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
328 #define PAGE_EXECUTE_READWRITE 0x40
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
329 #define PAGE_EXECUTE_WRITECOPY 0x80
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
330 #define PAGE_GUARD 0x100
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
331 #define PAGE_NOCACHE 0x200
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
332
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
333 HANDLE WINAPI CreateFileMappingA(HANDLE handle, LPSECURITY_ATTRIBUTES lpAttr,
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
334 DWORD flProtect,
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
335 DWORD dwMaxHigh, DWORD dwMaxLow,
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
336 LPCSTR name)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
337 {
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
338 int hFile = (int)handle;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
339 unsigned int len;
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
340 LPVOID answer;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
341 int anon=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
342 int mmap_access=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
343 if(hFile<0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
344 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
345 anon=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
346 hFile=open("/dev/zero", O_RDWR);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
347 if(hFile<0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
348 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
349 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
350 if(!anon)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
351 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
352 len=lseek(hFile, 0, SEEK_END);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
353 lseek(hFile, 0, SEEK_SET);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
354 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
355 else len=dwMaxLow;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
356
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
357 if(flProtect & PAGE_READONLY)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
358 mmap_access |=PROT_READ;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
359 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
360 mmap_access |=PROT_READ|PROT_WRITE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
361
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
362 answer=mmap(NULL, len, mmap_access, MAP_PRIVATE, hFile, 0);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
363 if(anon)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
364 close(hFile);
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
365 if(answer!=(LPVOID)-1)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
366 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
367 if(fm==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
368 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
369 fm=malloc(sizeof(file_mapping));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
370 fm->prev=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
371 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
372 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
373 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
374 fm->next=malloc(sizeof(file_mapping));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
375 fm->next->prev=fm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
376 fm=fm->next;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
377 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
378 fm->next=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
379 fm->handle=answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
380 if(name)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
381 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
382 fm->name=malloc(strlen(name)+1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
383 strcpy(fm->name, name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
384 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
385 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
386 fm->name=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
387 fm->mapping_size=len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
388
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
389 if(anon)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
390 close(hFile);
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
391 return (HANDLE)answer;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
392 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
393 return (HANDLE)0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
394 }
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
395 WIN_BOOL WINAPI UnmapViewOfFile(LPVOID handle)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
396 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
397 file_mapping* p;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
398 int result;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
399 if(fm==0)
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
400 return 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
401 for(p=fm; p; p=p->next)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
402 {
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
403 if(p->handle==handle)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
404 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
405 result=munmap((void*)handle, p->mapping_size);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
406 if(p->next)p->next->prev=p->prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
407 if(p->prev)p->prev->next=p->next;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
408 if(p->name)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
409 free(p->name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
410 if(p==fm)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
411 fm=p->prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
412 free(p);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
413 return result;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
414 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
415 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
416 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
417 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
418 //static int va_size=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
419 struct virt_alloc_s;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
420 typedef struct virt_alloc_s
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
421 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
422 int mapping_size;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
423 char* address;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
424 struct virt_alloc_s* next;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
425 struct virt_alloc_s* prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
426 int state;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
427 }virt_alloc;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
428 static virt_alloc* vm=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
429 #define MEM_COMMIT 0x00001000
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
430 #define MEM_RESERVE 0x00002000
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
431
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
432 LPVOID WINAPI VirtualAlloc(LPVOID address, DWORD size, DWORD type, DWORD protection)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
433 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
434 void* answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
435 int fd=open("/dev/zero", O_RDWR);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
436 size=(size+0xffff)&(~0xffff);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
437 // printf("VirtualAlloc(0x%08X, %d)\n", address
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
438 if(address!=0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
439 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
440 //check whether we can allow to allocate this
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
441 virt_alloc* str=vm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
442 while(str)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
443 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
444 if((unsigned)address>=(unsigned)str->address+str->mapping_size)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
445 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
446 str=str->prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
447 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
448 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
449 if((unsigned)address+size<(unsigned)str->address)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
450 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
451 str=str->prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
452 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
453 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
454 if(str->state==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
455 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
456 #warning FIXME
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
457 if(((unsigned)address+size<(unsigned)str->address+str->mapping_size) && (type & MEM_COMMIT))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
458 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
459 close(fd);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
460 return address; //returning previously reserved memory
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
461 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
462 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
463 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
464 close(fd);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
465 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
466 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
467 answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
468 MAP_FIXED | MAP_PRIVATE, fd, 0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
469 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
470 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
471 answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
472 MAP_PRIVATE, fd, 0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
473 // answer=FILE_dommap(-1, address, 0, size, 0, 0,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
474 // PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
475 close(fd);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
476 if(answer==(void*)-1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
477 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
478 printf("Error no %d\n", errno);
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
479 printf("VirtualAlloc(0x%p, %ld) failed\n", address, size);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
480 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
481 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
482 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
483 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
484 virt_alloc *new_vm=malloc(sizeof(virt_alloc));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
485 new_vm->mapping_size=size;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
486 new_vm->address=answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
487 new_vm->prev=vm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
488 if(type == MEM_RESERVE)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
489 new_vm->state=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
490 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
491 new_vm->state=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
492 if(vm)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
493 vm->next=new_vm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
494 vm=new_vm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
495 vm->next=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
496 // if(va_size!=0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
497 // printf("Multiple VirtualAlloc!\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
498 // printf("answer=0x%08x\n", answer);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
499 return answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
500 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
501 }
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
502 WIN_BOOL WINAPI VirtualFree(LPVOID address, DWORD t1, DWORD t2)//not sure
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
503 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
504 virt_alloc* str=vm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
505 int answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
506 while(str)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
507 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
508 if(address!=str->address)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
509 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
510 str=str->prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
511 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
512 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
513 answer=munmap(str->address, str->mapping_size);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
514 if(str->next)str->next->prev=str->prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
515 if(str->prev)str->prev->next=str->next;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
516 if(vm==str)vm=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
517 free(str);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
518 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
519 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
520 return -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
521 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
522
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
523 INT WINAPI WideCharToMultiByte(UINT codepage, DWORD flags, LPCWSTR src,
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
524 INT srclen,LPSTR dest, INT destlen, LPCSTR defch, WIN_BOOL* used_defch)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
525 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
526 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
527 if(src==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
528 return 0;
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
529 if ((srclen==-1)&&(dest==0)) return 0;
128
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
530 if(srclen==-1){srclen=0; while(src[srclen++]);}
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
531 // for(i=0; i<srclen; i++)
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
532 // printf("%c", src[i]);
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
533 // printf("\n");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
534 if(dest==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
535 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
536 for(i=0; i<srclen; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
537 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
538 src++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
539 if(*src==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
540 return i+1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
541 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
542 return srclen+1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
543 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
544 if(used_defch)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
545 *used_defch=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
546 for(i=0; i<min(srclen, destlen); i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
547 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
548 *dest=(char)*src;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
549 dest++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
550 src++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
551 if(*src==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
552 return i+1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
553 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
554 return min(srclen, destlen);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
555 }
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
556 INT WINAPI MultiByteToWideChar(UINT codepage,DWORD flags, LPCSTR src, INT srclen,
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
557 LPWSTR dest, INT destlen)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
558 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
559 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
560 }
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
561 HANDLE WINAPI OpenFileMappingA(DWORD access, WIN_BOOL prot, LPCSTR name)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
562 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
563 file_mapping* p;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
564 if(fm==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
565 return (HANDLE)0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
566 if(name==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
567 return (HANDLE)0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
568 for(p=fm; p; p=p->prev)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
569 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
570 if(p->name==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
571 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
572 if(strcmp(p->name, name)==0)
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1307
diff changeset
573 return (HANDLE)p->handle;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
574 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
575 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
576 }