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