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