Mercurial > mplayer.hg
annotate loader/ext.c @ 21614:5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
author | eugeni |
---|---|
date | Sat, 16 Dec 2006 19:17:50 +0000 |
parents | 2de480457872 |
children | 219d577285e1 |
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 * $Id$ |
f5537cc95b02
Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents:
13827
diff
changeset
|
13 */ |
f5537cc95b02
Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents:
13827
diff
changeset
|
14 |
3465 | 15 #include "config.h" |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
128
diff
changeset
|
16 #include <stdio.h> |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
128
diff
changeset
|
17 #include <stdlib.h> |
1 | 18 #ifdef HAVE_MALLOC_H |
19 #include <malloc.h> | |
20 #endif | |
21 #include <unistd.h> | |
22 #include <sys/mman.h> | |
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 { |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
86 static int i = 5; |
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 { |
128 | 96 if (mem) 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); | |
7386 | 200 char* answ = (char*) 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); | |
7386 | 211 answer = (WCHAR*) 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++; | |
7386 | 225 answer = (char*) 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 } |
d9cedf7b8069
added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
18783
diff
changeset
|
253 else |
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 static int mapping_size=0; | |
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 { | |
7386 | 376 fm = (file_mapping*) 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 { | |
7386 | 381 fm->next = (file_mapping*) 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 { | |
7386 | 389 fm->name = (char*) 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; | |
413 if(p->name) | |
414 free(p->name); | |
415 if(p==fm) | |
416 fm=p->prev; | |
417 free(p); | |
418 return result; | |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
419 } |
1 | 420 } |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
421 return 0; |
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
422 } |
1 | 423 //static int va_size=0; |
424 struct virt_alloc_s; | |
425 typedef struct virt_alloc_s | |
426 { | |
427 int mapping_size; | |
428 char* address; | |
429 struct virt_alloc_s* next; | |
430 struct virt_alloc_s* prev; | |
431 int state; | |
432 }virt_alloc; | |
433 static virt_alloc* vm=0; | |
434 #define MEM_COMMIT 0x00001000 | |
435 #define MEM_RESERVE 0x00002000 | |
436 | |
2069 | 437 LPVOID WINAPI VirtualAlloc(LPVOID address, DWORD size, DWORD type, DWORD protection) |
1 | 438 { |
439 void* answer; | |
13303 | 440 int fd; |
441 long pgsz; | |
442 | |
443 //printf("VirtualAlloc(0x%08X, %u, 0x%08X, 0x%08X)\n", (unsigned)address, size, type, protection); | |
444 | |
445 if ((type&(MEM_RESERVE|MEM_COMMIT)) == 0) return NULL; | |
446 | |
447 if (type&MEM_RESERVE && (unsigned)address&0xffff) { | |
448 size += (unsigned)address&0xffff; | |
13827 | 449 address = (unsigned)address&~0xffff; |
13303 | 450 } |
451 pgsz = sysconf(_SC_PAGESIZE); | |
452 if (type&MEM_COMMIT && (unsigned)address%pgsz) { | |
453 size += (unsigned)address%pgsz; | |
454 address -= (unsigned)address%pgsz; | |
455 } | |
456 | |
457 if (type&MEM_RESERVE && size<0x10000) size = 0x10000; | |
458 if (size%pgsz) size += pgsz - size%pgsz; | |
459 | |
1 | 460 if(address!=0) |
461 { | |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
462 //check whether we can allow to allocate this |
1 | 463 virt_alloc* str=vm; |
464 while(str) | |
465 { | |
466 if((unsigned)address>=(unsigned)str->address+str->mapping_size) | |
467 { | |
468 str=str->prev; | |
469 continue; | |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
470 } |
13303 | 471 if((unsigned)address+size<=(unsigned)str->address) |
1 | 472 { |
473 str=str->prev; | |
474 continue; | |
475 } | |
476 if(str->state==0) | |
477 { | |
478 #warning FIXME | |
13303 | 479 if( ((unsigned)address >= (unsigned)str->address) |
480 && ((unsigned)address+size<=(unsigned)str->address+str->mapping_size) | |
481 && (type & MEM_COMMIT)) | |
1 | 482 { |
483 return address; //returning previously reserved memory | |
484 } | |
13303 | 485 //printf(" VirtualAlloc(...) does not commit or not entirely within reserved, and\n"); |
1 | 486 } |
13303 | 487 /*printf(" VirtualAlloc(...) (0x%08X, %u) overlaps with (0x%08X, %u, state=%d)\n", |
488 (unsigned)address, size, (unsigned)str->address, str->mapping_size, str->state);*/ | |
1 | 489 return NULL; |
490 } | |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
491 } |
13303 | 492 |
21187
d9cedf7b8069
added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
18783
diff
changeset
|
493 answer=mmap_anon(address, size, PROT_READ | PROT_WRITE | PROT_EXEC, |
21248 | 494 MAP_PRIVATE, 0); |
1 | 495 // answer=FILE_dommap(-1, address, 0, size, 0, 0, |
496 // 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
|
497 |
13303 | 498 if (answer != (void *)-1 && address && answer != address) { |
499 /* It is dangerous to try mmap() with MAP_FIXED since it does not | |
500 always detect conflicts or non-allocation and chaos ensues after | |
501 a successful call but an overlapping or non-allocated region. */ | |
502 munmap(answer, size); | |
503 answer = (void *) -1; | |
504 errno = EINVAL; | |
505 //printf(" VirtualAlloc(...) cannot satisfy requested address but address=NULL would work.\n"); | |
506 } | |
1 | 507 if(answer==(void*)-1) |
508 { | |
13306 | 509 /*printf(" VirtualAlloc(...) mmap(0x%08X, %u, ...) failed with errno=%d (\"%s\")\n", |
510 (unsigned)address, size, errno, strerror(errno));*/ | |
1 | 511 return NULL; |
512 } | |
513 else | |
514 { | |
7386 | 515 virt_alloc *new_vm = (virt_alloc*) malloc(sizeof(virt_alloc)); |
1 | 516 new_vm->mapping_size=size; |
7386 | 517 new_vm->address=(char*)answer; |
1 | 518 new_vm->prev=vm; |
519 if(type == MEM_RESERVE) | |
520 new_vm->state=0; | |
521 else | |
522 new_vm->state=1; | |
523 if(vm) | |
524 vm->next=new_vm; | |
525 vm=new_vm; | |
526 vm->next=0; | |
3134 | 527 //if(va_size!=0) |
528 // printf("Multiple VirtualAlloc!\n"); | |
13303 | 529 //printf(" VirtualAlloc(...) provides (0x%08X, %u)\n", (unsigned)answer, size); |
1 | 530 return answer; |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
531 } |
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
532 } |
13303 | 533 |
3134 | 534 WIN_BOOL WINAPI VirtualFree(LPVOID address, SIZE_T dwSize, DWORD dwFreeType)//not sure |
1 | 535 { |
536 virt_alloc* str=vm; | |
537 int answer; | |
13303 | 538 |
539 //printf("VirtualFree(0x%08X, %d, 0x%08X)\n", (unsigned)address, dwSize, dwFreeType); | |
1 | 540 while(str) |
541 { | |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
542 if(address!=str->address) |
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
543 { |
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
544 str=str->prev; |
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
545 continue; |
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
546 } |
13303 | 547 //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
|
548 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
|
549 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
|
550 if(str->prev)str->prev->next=str->next; |
3134 | 551 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
|
552 free(str); |
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
553 return 0; |
1 | 554 } |
555 return -1; | |
556 } | |
557 | |
2069 | 558 INT WINAPI WideCharToMultiByte(UINT codepage, DWORD flags, LPCWSTR src, |
559 INT srclen,LPSTR dest, INT destlen, LPCSTR defch, WIN_BOOL* used_defch) | |
1 | 560 { |
561 int i; | |
562 if(src==0) | |
563 return 0; | |
2069 | 564 if ((srclen==-1)&&(dest==0)) return 0; |
128 | 565 if(srclen==-1){srclen=0; while(src[srclen++]);} |
566 // for(i=0; i<srclen; i++) | |
567 // printf("%c", src[i]); | |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
568 // printf("\n"); |
1 | 569 if(dest==0) |
570 { | |
571 for(i=0; i<srclen; i++) | |
572 { | |
573 src++; | |
574 if(*src==0) | |
575 return i+1; | |
576 } | |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
577 return srclen+1; |
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
578 } |
1 | 579 if(used_defch) |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
580 *used_defch=0; |
1 | 581 for(i=0; i<min(srclen, destlen); i++) |
582 { | |
583 *dest=(char)*src; | |
584 dest++; | |
585 src++; | |
586 if(*src==0) | |
587 return i+1; | |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
588 } |
1 | 589 return min(srclen, destlen); |
590 } | |
2069 | 591 INT WINAPI MultiByteToWideChar(UINT codepage,DWORD flags, LPCSTR src, INT srclen, |
592 LPWSTR dest, INT destlen) | |
1 | 593 { |
594 return 0; | |
595 } | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
128
diff
changeset
|
596 HANDLE WINAPI OpenFileMappingA(DWORD access, WIN_BOOL prot, LPCSTR name) |
1 | 597 { |
598 file_mapping* p; | |
599 if(fm==0) | |
600 return (HANDLE)0; | |
601 if(name==0) | |
602 return (HANDLE)0; | |
603 for(p=fm; p; p=p->prev) | |
604 { | |
605 if(p->name==0) | |
606 continue; | |
607 if(strcmp(p->name, name)==0) | |
2069 | 608 return (HANDLE)p->handle; |
1 | 609 } |
2651
958d10763c34
partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents:
2069
diff
changeset
|
610 return 0; |
1 | 611 } |