Mercurial > mplayer.hg
annotate loader/ext.c @ 14700:db451cd8ea37
Simplify FAAD instructions.
author | diego |
---|---|
date | Tue, 15 Feb 2005 03:04:56 +0000 |
parents | 374178b2a49a |
children | f5537cc95b02 |
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; | |
13303 | 460 int fd; |
461 long pgsz; | |
462 | |
463 //printf("VirtualAlloc(0x%08X, %u, 0x%08X, 0x%08X)\n", (unsigned)address, size, type, protection); | |
464 | |
465 if ((type&(MEM_RESERVE|MEM_COMMIT)) == 0) return NULL; | |
466 | |
467 fd=open("/dev/zero", O_RDWR); | |
3775 | 468 if(fd<0){ |
469 perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: " ); | |
470 return NULL; | |
471 } | |
13303 | 472 |
473 if (type&MEM_RESERVE && (unsigned)address&0xffff) { | |
474 size += (unsigned)address&0xffff; | |
13827 | 475 address = (unsigned)address&~0xffff; |
13303 | 476 } |
477 pgsz = sysconf(_SC_PAGESIZE); | |
478 if (type&MEM_COMMIT && (unsigned)address%pgsz) { | |
479 size += (unsigned)address%pgsz; | |
480 address -= (unsigned)address%pgsz; | |
481 } | |
482 | |
483 if (type&MEM_RESERVE && size<0x10000) size = 0x10000; | |
484 if (size%pgsz) size += pgsz - size%pgsz; | |
485 | |
1 | 486 if(address!=0) |
487 { | |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
488 //check whether we can allow to allocate this |
1 | 489 virt_alloc* str=vm; |
490 while(str) | |
491 { | |
492 if((unsigned)address>=(unsigned)str->address+str->mapping_size) | |
493 { | |
494 str=str->prev; | |
495 continue; | |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
496 } |
13303 | 497 if((unsigned)address+size<=(unsigned)str->address) |
1 | 498 { |
499 str=str->prev; | |
500 continue; | |
501 } | |
502 if(str->state==0) | |
503 { | |
504 #warning FIXME | |
13303 | 505 if( ((unsigned)address >= (unsigned)str->address) |
506 && ((unsigned)address+size<=(unsigned)str->address+str->mapping_size) | |
507 && (type & MEM_COMMIT)) | |
1 | 508 { |
509 close(fd); | |
510 return address; //returning previously reserved memory | |
511 } | |
13303 | 512 //printf(" VirtualAlloc(...) does not commit or not entirely within reserved, and\n"); |
1 | 513 } |
13303 | 514 /*printf(" VirtualAlloc(...) (0x%08X, %u) overlaps with (0x%08X, %u, state=%d)\n", |
515 (unsigned)address, size, (unsigned)str->address, str->mapping_size, str->state);*/ | |
1 | 516 close(fd); |
517 return NULL; | |
518 } | |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
519 } |
13303 | 520 |
521 answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC, | |
522 MAP_PRIVATE, fd, 0); | |
1 | 523 // answer=FILE_dommap(-1, address, 0, size, 0, 0, |
524 // PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE); | |
3134 | 525 close(fd); |
13303 | 526 if (answer != (void *)-1 && address && answer != address) { |
527 /* It is dangerous to try mmap() with MAP_FIXED since it does not | |
528 always detect conflicts or non-allocation and chaos ensues after | |
529 a successful call but an overlapping or non-allocated region. */ | |
530 munmap(answer, size); | |
531 answer = (void *) -1; | |
532 errno = EINVAL; | |
533 //printf(" VirtualAlloc(...) cannot satisfy requested address but address=NULL would work.\n"); | |
534 } | |
1 | 535 if(answer==(void*)-1) |
536 { | |
13306 | 537 /*printf(" VirtualAlloc(...) mmap(0x%08X, %u, ...) failed with errno=%d (\"%s\")\n", |
538 (unsigned)address, size, errno, strerror(errno));*/ | |
1 | 539 return NULL; |
540 } | |
541 else | |
542 { | |
7386 | 543 virt_alloc *new_vm = (virt_alloc*) malloc(sizeof(virt_alloc)); |
1 | 544 new_vm->mapping_size=size; |
7386 | 545 new_vm->address=(char*)answer; |
1 | 546 new_vm->prev=vm; |
547 if(type == MEM_RESERVE) | |
548 new_vm->state=0; | |
549 else | |
550 new_vm->state=1; | |
551 if(vm) | |
552 vm->next=new_vm; | |
553 vm=new_vm; | |
554 vm->next=0; | |
3134 | 555 //if(va_size!=0) |
556 // printf("Multiple VirtualAlloc!\n"); | |
13303 | 557 //printf(" VirtualAlloc(...) provides (0x%08X, %u)\n", (unsigned)answer, size); |
1 | 558 return answer; |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
559 } |
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
560 } |
13303 | 561 |
3134 | 562 WIN_BOOL WINAPI VirtualFree(LPVOID address, SIZE_T dwSize, DWORD dwFreeType)//not sure |
1 | 563 { |
564 virt_alloc* str=vm; | |
565 int answer; | |
13303 | 566 |
567 //printf("VirtualFree(0x%08X, %d, 0x%08X)\n", (unsigned)address, dwSize, dwFreeType); | |
1 | 568 while(str) |
569 { | |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
570 if(address!=str->address) |
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
571 { |
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
572 str=str->prev; |
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
573 continue; |
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
574 } |
13303 | 575 //printf(" VirtualFree(...) munmap(0x%08X, %d)\n", (unsigned)str->address, str->mapping_size); |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
576 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
|
577 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
|
578 if(str->prev)str->prev->next=str->next; |
3134 | 579 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
|
580 free(str); |
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
581 return 0; |
1 | 582 } |
583 return -1; | |
584 } | |
585 | |
2069 | 586 INT WINAPI WideCharToMultiByte(UINT codepage, DWORD flags, LPCWSTR src, |
587 INT srclen,LPSTR dest, INT destlen, LPCSTR defch, WIN_BOOL* used_defch) | |
1 | 588 { |
589 int i; | |
590 if(src==0) | |
591 return 0; | |
2069 | 592 if ((srclen==-1)&&(dest==0)) return 0; |
128 | 593 if(srclen==-1){srclen=0; while(src[srclen++]);} |
594 // for(i=0; i<srclen; i++) | |
595 // printf("%c", src[i]); | |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
596 // printf("\n"); |
1 | 597 if(dest==0) |
598 { | |
599 for(i=0; i<srclen; i++) | |
600 { | |
601 src++; | |
602 if(*src==0) | |
603 return i+1; | |
604 } | |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
605 return srclen+1; |
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
606 } |
1 | 607 if(used_defch) |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
608 *used_defch=0; |
1 | 609 for(i=0; i<min(srclen, destlen); i++) |
610 { | |
611 *dest=(char)*src; | |
612 dest++; | |
613 src++; | |
614 if(*src==0) | |
615 return i+1; | |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
616 } |
1 | 617 return min(srclen, destlen); |
618 } | |
2069 | 619 INT WINAPI MultiByteToWideChar(UINT codepage,DWORD flags, LPCSTR src, INT srclen, |
620 LPWSTR dest, INT destlen) | |
1 | 621 { |
622 return 0; | |
623 } | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
128
diff
changeset
|
624 HANDLE WINAPI OpenFileMappingA(DWORD access, WIN_BOOL prot, LPCSTR name) |
1 | 625 { |
626 file_mapping* p; | |
627 if(fm==0) | |
628 return (HANDLE)0; | |
629 if(name==0) | |
630 return (HANDLE)0; | |
631 for(p=fm; p; p=p->prev) | |
632 { | |
633 if(p->name==0) | |
634 continue; | |
635 if(strcmp(p->name, name)==0) | |
2069 | 636 return (HANDLE)p->handle; |
1 | 637 } |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
638 return 0; |
1 | 639 } |