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