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