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