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