Mercurial > mplayer.hg
annotate loader/win32.c @ 1597:37b81a811cb2
fixed seeking (now allows seeking before start position)
author | arpi |
---|---|
date | Mon, 20 Aug 2001 21:20:39 +0000 |
parents | 228bb6a3e76d |
children | 73c8f54305b1 |
rev | line source |
---|---|
1 | 1 /*********************************************************** |
2 | |
3 Win32 emulation code. Functions that emulate | |
4 responses from corresponding Win32 API calls. | |
5 Since we are not going to be able to load | |
6 virtually any DLL, we can only implement this | |
7 much, adding needed functions with each new codec. | |
128 | 8 |
9 Basic principle of implementation: it's not good | |
10 for DLL to know too much about its environment. | |
1 | 11 |
12 ************************************************************/ | |
13 | |
14 #include <config.h> | |
15 | |
16 #include "win32.h" | |
17 #include <stdio.h> | |
18 #include <pthread.h> | |
128 | 19 #include <errno.h> |
597 | 20 #include <ctype.h> |
21 #include <stdlib.h> | |
1 | 22 #ifdef HAVE_MALLOC_H |
23 #include <malloc.h> | |
24 #endif | |
25 #include <time.h> | |
128 | 26 #include <unistd.h> |
27 #include <fcntl.h> | |
1 | 28 #include <sys/types.h> |
29 #include <sys/time.h> | |
30 #include <sys/timeb.h> | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
31 #if HAVE_LIBKSTAT |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
32 #include <kstat.h> |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
33 #endif |
1 | 34 |
35 #include <wine/winbase.h> | |
36 #include <wine/winreg.h> | |
37 #include <wine/winnt.h> | |
38 #include <wine/winerror.h> | |
39 #include <wine/debugtools.h> | |
40 #include <wine/module.h> | |
41 | |
42 #include <registry.h> | |
43 #include <loader.h> | |
128 | 44 #include <com.h> |
45 | |
1416 | 46 long RegEnumValueA(HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count, |
47 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count); | |
48 | |
128 | 49 char* def_path=WIN32_PATH; |
50 | |
51 static void do_cpuid(unsigned int *regs) | |
52 { | |
53 unsigned int ax; | |
54 ax=1; | |
55 __asm__ __volatile__( | |
56 "pushl %%ebx; pushl %%ecx; pushl %%edx; " | |
57 ".byte 0x0f, 0xa2;" | |
58 "movl %%eax, (%2);" | |
59 "movl %%ebx, 4(%2);" | |
60 "movl %%ecx, 8(%2);" | |
61 "movl %%edx, 12(%2);" | |
62 "popl %%edx; popl %%ecx; popl %%ebx; " | |
63 : "=a" (ax) | |
64 : "0" (ax), "S" (®s)); | |
65 } | |
66 static unsigned int c_localcount_tsc() | |
1 | 67 { |
68 int a; | |
69 __asm__ __volatile__("rdtsc\n\t" | |
70 :"=a"(a) | |
71 : | |
72 :"edx"); | |
73 return a; | |
74 } | |
128 | 75 static void c_longcount_tsc(long long* z) |
1 | 76 { |
77 __asm__ __volatile__( | |
78 "pushl %%ebx\n\t" | |
79 "movl %%eax, %%ebx\n\t" | |
80 "rdtsc\n\t" | |
81 "movl %%eax, 0(%%ebx)\n\t" | |
82 "movl %%edx, 4(%%ebx)\n\t" | |
83 "popl %%ebx\n\t" | |
84 ::"a"(z)); | |
85 } | |
128 | 86 static unsigned int c_localcount_notsc() |
1 | 87 { |
88 struct timeval tv; | |
89 unsigned limit=~0; | |
90 limit/=1000000; | |
91 gettimeofday(&tv, 0); | |
92 return limit*tv.tv_usec; | |
93 } | |
128 | 94 static void c_longcount_notsc(long long* z) |
1 | 95 { |
96 struct timeval tv; | |
97 unsigned long long result; | |
98 unsigned limit=~0; | |
99 if(!z)return; | |
100 limit/=1000000; | |
101 gettimeofday(&tv, 0); | |
102 result=tv.tv_sec; | |
103 result<<=32; | |
104 result+=limit*tv.tv_usec; | |
105 *z=result; | |
106 } | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
107 |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
108 static unsigned int localcount_stub(void); |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
109 static void longcount_stub(long long* z); |
128 | 110 static unsigned int (*localcount)()=localcount_stub; |
111 static void (*longcount)(long long*)=longcount_stub; | |
1 | 112 |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
113 static unsigned int localcount_stub(void) |
128 | 114 { |
115 unsigned int regs[4]; | |
116 do_cpuid(regs); | |
117 if ((regs[3] & 0x00000010) == 0) | |
118 { | |
119 localcount=c_localcount_tsc; | |
120 longcount=c_longcount_tsc; | |
121 } | |
122 else | |
123 { | |
124 localcount=c_localcount_notsc; | |
125 longcount=c_longcount_notsc; | |
126 } | |
127 return localcount(); | |
128 } | |
129 static void longcount_stub(long long* z) | |
1 | 130 { |
128 | 131 unsigned int regs[4]; |
132 do_cpuid(regs); | |
133 if ((regs[3] & 0x00000010) == 0) | |
134 { | |
135 localcount=c_localcount_tsc; | |
136 longcount=c_longcount_tsc; | |
137 } | |
138 else | |
139 { | |
140 localcount=c_localcount_notsc; | |
141 longcount=c_longcount_notsc; | |
142 } | |
143 longcount(z); | |
144 } | |
145 | |
235 | 146 int LOADER_DEBUG=1; |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
147 static inline void dbgprintf(char* fmt, ...) |
128 | 148 { |
235 | 149 #ifdef DETAILED_OUT |
128 | 150 if(LOADER_DEBUG) |
151 { | |
152 FILE* f; | |
153 va_list va; | |
154 va_start(va, fmt); | |
155 f=fopen("./log", "a"); | |
156 vprintf(fmt, va); | |
157 if(f) | |
158 { | |
159 vfprintf(f, fmt, va); | |
160 fsync(fileno(f)); | |
161 fclose(f); | |
162 } | |
163 va_end(va); | |
164 } | |
235 | 165 #endif |
1 | 166 } |
167 char export_names[500][30]={ | |
168 "name1", | |
169 //"name2", | |
170 //"name3" | |
171 }; | |
172 //#define min(x,y) ((x)<(y)?(x):(y)) | |
173 | |
174 static unsigned char* heap=NULL; | |
175 static int heap_counter=0; | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
176 static void test_heap() |
1 | 177 { |
178 int offset=0; | |
179 if(heap==0) | |
180 return; | |
181 while(offset<heap_counter) | |
182 { | |
183 if(*(int*)(heap+offset)!=0x433476) | |
184 { | |
185 printf("Heap corruption at address %d\n", offset); | |
186 return; | |
187 } | |
188 offset+=8+*(int*)(heap+offset+4); | |
189 } | |
190 for(;offset<min(offset+1000, 20000000); offset++) | |
191 if(heap[offset]!=0xCC) | |
192 { | |
193 printf("Free heap corruption at address %d\n", offset); | |
194 } | |
195 } | |
196 #undef MEMORY_DEBUG | |
197 | |
198 #ifdef MEMORY_DEBUG | |
199 | |
200 void* my_mreq(int size, int to_zero) | |
201 { | |
202 static int test=0; | |
203 test++; | |
204 if(test%10==0)printf("Memory: %d bytes allocated\n", heap_counter); | |
205 // test_heap(); | |
206 if(heap==NULL) | |
207 { | |
208 heap=malloc(20000000); | |
209 memset(heap, 0xCC,20000000); | |
210 } | |
211 if(heap==0) | |
212 { | |
213 printf("No enough memory\n"); | |
214 return 0; | |
215 } | |
216 if(heap_counter+size>20000000) | |
217 { | |
218 printf("No enough memory\n"); | |
219 return 0; | |
220 } | |
221 *(int*)(heap+heap_counter)=0x433476; | |
222 heap_counter+=4; | |
223 *(int*)(heap+heap_counter)=size; | |
224 heap_counter+=4; | |
225 printf("Allocated %d bytes of memory: sys %d, user %d-%d\n", size, heap_counter-8, heap_counter, heap_counter+size); | |
226 if(to_zero) | |
227 memset(heap+heap_counter, 0, size); | |
1543 | 228 else |
229 memset(heap+heap_counter, 0xcc, size); | |
1 | 230 heap_counter+=size; |
231 return heap+heap_counter-size; | |
232 } | |
597 | 233 int my_release(void* memory) |
1 | 234 { |
235 // test_heap(); | |
236 if(memory==NULL) | |
237 { | |
238 printf("ERROR: free(0)\n"); | |
239 return 0; | |
240 } | |
241 if(*(int*)(memory-8)!=0x433476) | |
242 { | |
243 printf("MEMORY CORRUPTION !!!!!!!!!!!!!!!!!!!\n"); | |
244 return 0; | |
245 } | |
246 printf("Freed %d bytes of memory\n", *(int*)(memory-4)); | |
247 // memset(memory-8, *(int*)(memory-4), 0xCC); | |
248 return 0; | |
249 } | |
250 | |
251 #else | |
128 | 252 #define GARBAGE |
253 #ifdef GARBAGE | |
254 struct alc_list_t; | |
255 typedef struct alc_list_t { | |
256 int size; | |
597 | 257 void *addr; |
128 | 258 struct alc_list_t *prev; |
259 struct alc_list_t *next; | |
260 }alc_list; | |
261 static alc_list *alclist=NULL; | |
597 | 262 static int alccnt=0; |
128 | 263 #endif |
264 | |
1 | 265 void* my_mreq(int size, int to_zero) |
266 { | |
267 void* answer; | |
268 if(to_zero) | |
269 answer=calloc(size+4, 1); | |
270 else | |
271 answer=malloc(size+4); | |
272 *(int*)answer=size; | |
128 | 273 #ifdef GARBAGE |
274 if (alclist==NULL) { | |
275 alclist=malloc(sizeof(alc_list)); | |
276 alclist->prev=alclist->next=NULL; | |
277 } | |
278 else { | |
279 alclist->next=malloc(sizeof(alc_list)); | |
280 alclist->next->prev=alclist; | |
281 alclist->next->next=NULL; | |
282 alclist=alclist->next; | |
283 } | |
284 alclist->size=size; | |
285 alclist->addr=answer; | |
286 alccnt++; | |
287 #endif | |
288 return (int*)((int)answer+sizeof(int)); | |
1 | 289 } |
597 | 290 int my_release(void* memory) |
1 | 291 { |
128 | 292 #ifdef GARBAGE |
293 alc_list* pp; | |
1 | 294 if(memory==0)return 0; |
128 | 295 if(alclist!=NULL) |
296 { | |
297 pp=alclist; | |
298 if ((pp->prev==NULL) && (pp->next == NULL)){ | |
299 free(pp); | |
300 alclist=NULL; | |
301 } | |
302 else { | |
303 for(;pp;pp=pp->prev) { | |
304 if (pp->addr == memory-4) { | |
305 if (pp->prev) | |
306 pp->prev->next=pp->next; | |
307 if (pp->next) | |
308 pp->next->prev=pp->prev; | |
309 if (pp == alclist) | |
310 alclist=pp->prev; | |
311 free(pp); | |
312 alccnt--; | |
313 break; | |
314 } | |
315 } | |
316 if (pp == NULL) { | |
597 | 317 printf("Not Found %p %d\n",memory-4,alccnt); |
128 | 318 return 0; |
319 } | |
320 } | |
321 } | |
322 #endif | |
1 | 323 free(memory-4); |
324 return 0; | |
325 } | |
326 #endif | |
327 int my_size(char* memory) | |
328 { | |
329 return *(int*)(memory-4); | |
330 } | |
331 | |
332 extern int unk_exp1; | |
333 char extcode[20000];// place for 200 unresolved exports | |
334 int pos=0; | |
335 | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
336 int WINAPI ext_unknown(void) |
1 | 337 { |
338 printf("Unknown func called\n"); | |
339 return 0; | |
340 } | |
341 int WINAPI expIsBadWritePtr(void* ptr, unsigned int count) | |
342 { | |
128 | 343 int result; |
1 | 344 if(count==0) |
128 | 345 result=0; |
346 else | |
1 | 347 if(ptr==0) |
128 | 348 result=1; |
349 else | |
350 result=0; | |
351 dbgprintf("IsBadWritePtr(0x%x, 0x%x) => %d\n", ptr, count, result); | |
352 return result; | |
1 | 353 } |
354 int WINAPI expIsBadReadPtr(void* ptr, unsigned int count) | |
355 { | |
128 | 356 int result; |
1 | 357 if(count==0) |
128 | 358 result=0; |
359 else | |
1 | 360 if(ptr==0) |
128 | 361 result=1; |
362 else | |
363 result=0; | |
364 dbgprintf("IsBadReadPtr(0x%x, 0x%x) => %d\n", ptr, count, result); | |
365 return result; | |
1 | 366 } |
367 void* CDECL expmalloc(int size) | |
368 { | |
369 //printf("malloc"); | |
370 // return malloc(size); | |
371 void* result=my_mreq(size,0); | |
128 | 372 dbgprintf("malloc(0x%x) => 0x%x\n", size,result); |
1 | 373 if(result==0) |
374 printf("WARNING: malloc() failed\n"); | |
375 return result; | |
376 } | |
377 void CDECL expfree(void* mem) | |
378 { | |
379 // return free(mem); | |
128 | 380 dbgprintf("free(0x%x)\n", mem); |
1 | 381 my_release(mem); |
382 } | |
383 void* CDECL expnew(int size) | |
384 { | |
385 // printf("NEW:: Call from address %08x\n STACK DUMP:\n", *(-1+(int*)&size)); | |
386 // printf("%08x %08x %08x %08x\n", | |
387 // size, *(1+(int*)&size), | |
388 // *(2+(int*)&size),*(3+(int*)&size)); | |
128 | 389 void* result=my_mreq(size,0); |
390 dbgprintf("new(0x%x) => 0x%x\n", size, result); | |
1 | 391 if(result==0) |
128 | 392 printf("WARNING: new() failed\n"); |
1 | 393 return result; |
394 | |
395 } | |
396 int CDECL expdelete(void* memory) | |
397 { | |
128 | 398 dbgprintf("delete(0x%x)\n", memory); |
399 my_release(memory); | |
1 | 400 return 0; |
401 } | |
402 int WINAPI expDisableThreadLibraryCalls(int module) | |
403 { | |
128 | 404 dbgprintf("DisableThreadLibraryCalls(0x%x) => 0\n", module); |
1 | 405 return 0; |
406 } | |
407 int CDECL exp_initterm(int v1, int v2) | |
408 { | |
128 | 409 dbgprintf("_initterm(0x%x, 0x%x) => 0\n", v1, v2); |
1 | 410 return 0; |
411 } | |
412 | |
413 void* WINAPI expGetDriverModuleHandle(DRVR* pdrv) | |
414 { | |
128 | 415 void* result; |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
416 if (pdrv==NULL) |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
417 result=NULL; |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
418 else |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
419 result=(void*) pdrv->hDriverModule; |
128 | 420 dbgprintf("GetDriverModuleHandle(0x%x) => 0x%x\n", pdrv, result); |
421 return result; | |
1 | 422 } |
423 | |
424 void* WINAPI expGetModuleHandleA(const char* name) | |
425 { | |
426 WINE_MODREF* wm; | |
128 | 427 void* result; |
428 if(!name) | |
429 result=0; | |
430 else | |
431 { | |
432 wm=MODULE_FindModule(name); | |
433 if(wm==0)result=0; | |
434 else | |
435 result=(void*)(wm->module); | |
436 } | |
437 if(!result) | |
438 { | |
439 if(strcasecmp(name, "kernel32")==0) | |
597 | 440 result=(void *) 0x120; |
128 | 441 } |
442 dbgprintf("GetModuleHandleA('%s') => 0x%x\n", name, result); | |
443 return result; | |
1 | 444 } |
128 | 445 |
1 | 446 struct th_list_t; |
447 typedef struct th_list_t{ | |
448 int id; | |
449 void* thread; | |
450 struct th_list_t* next; | |
451 struct th_list_t* prev; | |
452 }th_list; | |
453 | |
454 static th_list* list=NULL; | |
455 | |
456 | |
457 | |
458 void* WINAPI expCreateThread(void* pSecAttr, long dwStackSize, void* lpStartAddress, | |
459 void* lpParameter, long dwFlags, long* dwThreadId) | |
460 { | |
461 pthread_t *pth; | |
462 // printf("CreateThread:"); | |
463 pth=my_mreq(sizeof(pthread_t), 0); | |
464 pthread_create(pth, NULL, (void*(*)(void*))lpStartAddress, lpParameter); | |
465 if(dwFlags) | |
128 | 466 printf( "WARNING: CreateThread flags not supported\n"); |
1 | 467 if(dwThreadId) |
468 *dwThreadId=(long)pth; | |
469 if(list==NULL) | |
470 { | |
471 list=my_mreq(sizeof(th_list), 1); | |
472 list->next=list->prev=NULL; | |
473 } | |
474 else | |
475 { | |
476 list->next=my_mreq(sizeof(th_list), 0); | |
477 list->next->prev=list; | |
478 list->next->next=NULL; | |
479 list=list->next; | |
480 } | |
481 list->thread=pth; | |
128 | 482 dbgprintf("CreateThread(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x) => 0x%x\n", |
483 pSecAttr, dwStackSize, lpStartAddress, lpParameter, dwFlags, dwThreadId, pth); | |
1 | 484 return pth; |
485 } | |
486 | |
487 struct mutex_list_t; | |
488 | |
489 struct mutex_list_t | |
490 { | |
128 | 491 char type; |
1 | 492 pthread_mutex_t *pm; |
128 | 493 pthread_cond_t *pc; |
494 char state; | |
495 char reset; | |
1 | 496 char name[64]; |
128 | 497 int semaphore; |
1 | 498 struct mutex_list_t* next; |
499 struct mutex_list_t* prev; | |
500 }; | |
501 typedef struct mutex_list_t mutex_list; | |
502 static mutex_list* mlist=NULL; | |
503 void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset, | |
504 char bInitialState, const char* name) | |
505 { | |
506 pthread_mutex_t *pm; | |
128 | 507 pthread_cond_t *pc; |
1 | 508 if(mlist!=NULL) |
509 { | |
510 mutex_list* pp=mlist; | |
511 if(name!=NULL) | |
512 do | |
513 { | |
128 | 514 if((strcmp(pp->name, name)==0) && (pp->type==0)) |
515 { | |
516 dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, 0x%x='%s') => 0x%x\n", | |
517 pSecAttr, bManualReset, bInitialState, name, name, pp->pm); | |
1 | 518 return pp->pm; |
128 | 519 } |
597 | 520 }while((pp=pp->prev)); |
1 | 521 } |
522 pm=my_mreq(sizeof(pthread_mutex_t), 0); | |
523 pthread_mutex_init(pm, NULL); | |
128 | 524 pc=my_mreq(sizeof(pthread_cond_t), 0); |
525 pthread_cond_init(pc, NULL); | |
1 | 526 if(mlist==NULL) |
527 { | |
528 mlist=my_mreq(sizeof(mutex_list), 00); | |
529 mlist->next=mlist->prev=NULL; | |
530 } | |
531 else | |
532 { | |
533 mlist->next=my_mreq(sizeof(mutex_list), 00); | |
128 | 534 mlist->next->prev=mlist; |
1 | 535 mlist->next->next=NULL; |
536 mlist=mlist->next; | |
537 } | |
128 | 538 mlist->type=0; /* Type Event */ |
1 | 539 mlist->pm=pm; |
128 | 540 mlist->pc=pc; |
541 mlist->state=bInitialState; | |
542 mlist->reset=bManualReset; | |
1 | 543 if(name!=NULL) |
544 strncpy(mlist->name, name, 64); | |
545 else | |
546 mlist->name[0]=0; | |
547 if(pm==NULL) | |
548 dbgprintf("ERROR::: CreateEventA failure\n"); | |
128 | 549 /* |
1 | 550 if(bInitialState) |
551 pthread_mutex_lock(pm); | |
128 | 552 */ |
553 if(name) | |
554 dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, 0x%x='%s') => 0x%x\n", | |
555 pSecAttr, bManualReset, bInitialState, name, name, mlist); | |
556 else | |
557 dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, NULL) => 0x%x\n", | |
558 pSecAttr, bManualReset, bInitialState, mlist); | |
559 return mlist; | |
1 | 560 } |
561 | |
562 void* WINAPI expSetEvent(void* event) | |
563 { | |
128 | 564 mutex_list *ml = (mutex_list *)event; |
565 dbgprintf("SetEvent(%x) => 0x1\n", event); | |
566 pthread_mutex_lock(ml->pm); | |
567 if (ml->state == 0) { | |
568 ml->state = 1; | |
569 pthread_cond_signal(ml->pc); | |
570 } | |
571 pthread_mutex_unlock(ml->pm); | |
572 | |
573 return (void *)1; | |
1 | 574 } |
575 void* WINAPI expResetEvent(void* event) | |
576 { | |
128 | 577 mutex_list *ml = (mutex_list *)event; |
578 dbgprintf("ResetEvent(0x%x) => 0x1\n", event); | |
579 pthread_mutex_lock(ml->pm); | |
580 ml->state = 0; | |
581 pthread_mutex_unlock(ml->pm); | |
582 | |
583 return (void *)1; | |
1 | 584 } |
585 | |
586 void* WINAPI expWaitForSingleObject(void* object, int duration) | |
587 { | |
128 | 588 mutex_list *ml = (mutex_list *)object; |
718 | 589 int ret=WAIT_FAILED; // fixed by Zdenek Kabelac |
128 | 590 mutex_list* pp=mlist; |
591 // dbgprintf("WaitForSingleObject(0x%x, duration %d) =>\n",object, duration); | |
718 | 592 // loop below was slightly fixed - its used just for checking if |
593 // this object really exists in our list | |
594 if (!ml) | |
595 return (void*) ret; | |
596 while (pp && (pp->pm != ml->pm)) | |
597 pp = pp->prev; | |
598 if (!pp) { | |
599 //dbgprintf("WaitForSingleObject: NotFound\n"); | |
600 return (void*)ret; | |
601 } | |
128 | 602 |
603 pthread_mutex_lock(ml->pm); | |
604 | |
605 switch(ml->type) { | |
606 case 0: /* Event */ | |
607 if (duration == 0) { /* Check Only */ | |
608 if (ml->state == 1) ret = WAIT_FAILED; | |
609 else ret = WAIT_OBJECT_0; | |
610 } | |
611 if (duration == -1) { /* INFINITE */ | |
612 if (ml->state == 0) | |
613 pthread_cond_wait(ml->pc,ml->pm); | |
614 if (ml->reset) | |
615 ml->state = 0; | |
616 ret = WAIT_OBJECT_0; | |
617 } | |
618 if (duration > 0) { /* Timed Wait */ | |
619 struct timespec abstime; | |
620 struct timeval now; | |
621 gettimeofday(&now, 0); | |
622 abstime.tv_sec = now.tv_sec + (now.tv_usec+duration)/1000000; | |
623 abstime.tv_nsec = ((now.tv_usec+duration)%1000000)*1000; | |
624 if (ml->state == 0) | |
625 ret=pthread_cond_timedwait(ml->pc,ml->pm,&abstime); | |
626 if (ret == ETIMEDOUT) ret = WAIT_TIMEOUT; | |
627 else ret = WAIT_OBJECT_0; | |
628 if (ml->reset) | |
629 ml->state = 0; | |
630 } | |
631 break; | |
632 case 1: /* Semaphore */ | |
633 if (duration == 0) { | |
634 if(ml->semaphore==0) ret = WAIT_FAILED; | |
635 else { | |
636 ml->semaphore++; | |
637 ret = WAIT_OBJECT_0; | |
638 } | |
639 } | |
640 if (duration == -1) { | |
641 if (ml->semaphore==0) | |
642 pthread_cond_wait(ml->pc,ml->pm); | |
643 ml->semaphore--; | |
644 } | |
645 break; | |
646 } | |
647 pthread_mutex_unlock(ml->pm); | |
648 | |
649 dbgprintf("WaitForSingleObject(0x%x, %d): 0x%x => 0x%x \n",object,duration,ml,ret); | |
650 return (void *)ret; | |
1 | 651 } |
652 | |
653 static BYTE PF[64] = {0,}; | |
654 | |
128 | 655 WIN_BOOL WINAPI expIsProcessorFeaturePresent(DWORD v) |
656 { | |
657 WIN_BOOL result; | |
658 if(v>63)result=0; | |
659 else result=PF[v]; | |
660 dbgprintf("IsProcessorFeaturePresent(0x%x) => 0x%x\n", v, result); | |
661 return result; | |
662 } | |
663 | |
664 static void DumpSystemInfo(const SYSTEM_INFO* si) | |
665 { | |
666 dbgprintf(" Processor architecture %d\n", si->u.s.wProcessorArchitecture); | |
667 dbgprintf(" Page size: %d\n", si->dwPageSize); | |
668 dbgprintf(" Minimum app address: %d\n", si->lpMinimumApplicationAddress); | |
669 dbgprintf(" Maximum app address: %d\n", si->lpMaximumApplicationAddress); | |
670 dbgprintf(" Active processor mask: 0x%x\n", si->dwActiveProcessorMask); | |
671 dbgprintf(" Number of processors: %d\n", si->dwNumberOfProcessors); | |
672 dbgprintf(" Processor type: 0x%x\n", si->dwProcessorType); | |
673 dbgprintf(" Allocation granularity: 0x%x\n", si->dwAllocationGranularity); | |
674 dbgprintf(" Processor level: 0x%x\n", si->wProcessorLevel); | |
675 dbgprintf(" Processor revision: 0x%x\n", si->wProcessorRevision); | |
676 } | |
677 | |
1 | 678 void WINAPI expGetSystemInfo(SYSTEM_INFO* si) |
679 { | |
680 /* FIXME: better values for the two entries below... */ | |
681 static int cache = 0; | |
682 static SYSTEM_INFO cachedsi; | |
128 | 683 unsigned int regs[4]; |
1 | 684 HKEY xhkey=0,hkey; |
128 | 685 dbgprintf("GetSystemInfo(0x%d) =>\n"); |
1 | 686 |
687 if (cache) { | |
688 memcpy(si,&cachedsi,sizeof(*si)); | |
128 | 689 DumpSystemInfo(si); |
1 | 690 return; |
691 } | |
692 memset(PF,0,sizeof(PF)); | |
693 | |
694 cachedsi.u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL; | |
695 cachedsi.dwPageSize = getpagesize(); | |
696 | |
697 /* FIXME: better values for the two entries below... */ | |
128 | 698 cachedsi.lpMinimumApplicationAddress = (void *)0x00000000; |
1 | 699 cachedsi.lpMaximumApplicationAddress = (void *)0x7FFFFFFF; |
700 cachedsi.dwActiveProcessorMask = 1; | |
701 cachedsi.dwNumberOfProcessors = 1; | |
702 cachedsi.dwProcessorType = PROCESSOR_INTEL_386; | |
703 cachedsi.dwAllocationGranularity = 0x10000; | |
128 | 704 cachedsi.wProcessorLevel = 5; /* pentium */ |
705 cachedsi.wProcessorRevision = 0x0101; | |
1 | 706 |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
707 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__svr4__) |
128 | 708 do_cpuid(regs); |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
709 switch ((regs[0] >> 8) & 0xf) { // cpu family |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
710 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
711 cachedsi.wProcessorLevel= 3; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
712 break; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
713 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
714 cachedsi.wProcessorLevel= 4; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
715 break; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
716 case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
717 cachedsi.wProcessorLevel= 5; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
718 break; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
719 case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
720 cachedsi.wProcessorLevel= 5; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
721 break; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
722 default:cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
723 cachedsi.wProcessorLevel= 5; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
724 break; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
725 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
726 cachedsi.wProcessorRevision = regs[0] & 0xf; // stepping |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
727 if (regs[3] & (1 << 8)) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
728 PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
729 if (regs[3] & (1 << 23)) |
128 | 730 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE; |
1 | 731 cachedsi.dwNumberOfProcessors=1; |
732 #else | |
733 { | |
734 char buf[20]; | |
735 char line[200]; | |
736 FILE *f = fopen ("/proc/cpuinfo", "r"); | |
737 | |
738 if (!f) | |
739 return; | |
740 xhkey = 0; | |
741 while (fgets(line,200,f)!=NULL) { | |
742 char *s,*value; | |
743 | |
744 /* NOTE: the ':' is the only character we can rely on */ | |
745 if (!(value = strchr(line,':'))) | |
746 continue; | |
747 /* terminate the valuename */ | |
748 *value++ = '\0'; | |
749 /* skip any leading spaces */ | |
750 while (*value==' ') value++; | |
751 if ((s=strchr(value,'\n'))) | |
752 *s='\0'; | |
753 | |
754 /* 2.1 method */ | |
755 if (!lstrncmpiA(line, "cpu family",strlen("cpu family"))) { | |
756 if (isdigit (value[0])) { | |
757 switch (value[0] - '0') { | |
758 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386; | |
759 cachedsi.wProcessorLevel= 3; | |
760 break; | |
761 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486; | |
762 cachedsi.wProcessorLevel= 4; | |
763 break; | |
764 case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; | |
765 cachedsi.wProcessorLevel= 5; | |
766 break; | |
767 case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; | |
768 cachedsi.wProcessorLevel= 5; | |
769 break; | |
770 default:cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; | |
771 cachedsi.wProcessorLevel= 5; | |
772 break; | |
773 } | |
774 } | |
775 /* set the CPU type of the current processor */ | |
1096 | 776 snprintf(buf,20,"CPU %ld",cachedsi.dwProcessorType); |
1 | 777 continue; |
778 } | |
779 /* old 2.0 method */ | |
780 if (!lstrncmpiA(line, "cpu",strlen("cpu"))) { | |
781 if ( isdigit (value[0]) && value[1] == '8' && | |
782 value[2] == '6' && value[3] == 0 | |
783 ) { | |
784 switch (value[0] - '0') { | |
785 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386; | |
786 cachedsi.wProcessorLevel= 3; | |
787 break; | |
788 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486; | |
789 cachedsi.wProcessorLevel= 4; | |
790 break; | |
791 case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; | |
792 cachedsi.wProcessorLevel= 5; | |
793 break; | |
794 case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; | |
795 cachedsi.wProcessorLevel= 5; | |
796 break; | |
797 default:cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; | |
798 cachedsi.wProcessorLevel= 5; | |
799 break; | |
800 } | |
801 } | |
802 /* set the CPU type of the current processor */ | |
1096 | 803 snprintf(buf,20,"CPU %ld",cachedsi.dwProcessorType); |
1 | 804 continue; |
805 } | |
806 if (!lstrncmpiA(line,"fdiv_bug",strlen("fdiv_bug"))) { | |
807 if (!lstrncmpiA(value,"yes",3)) | |
808 PF[PF_FLOATING_POINT_PRECISION_ERRATA] = TRUE; | |
809 | |
810 continue; | |
811 } | |
812 if (!lstrncmpiA(line,"fpu",strlen("fpu"))) { | |
813 if (!lstrncmpiA(value,"no",2)) | |
814 PF[PF_FLOATING_POINT_EMULATED] = TRUE; | |
815 | |
816 continue; | |
817 } | |
818 if (!lstrncmpiA(line,"processor",strlen("processor"))) { | |
819 /* processor number counts up...*/ | |
820 int x; | |
821 | |
822 if (sscanf(value,"%d",&x)) | |
823 if (x+1>cachedsi.dwNumberOfProcessors) | |
824 cachedsi.dwNumberOfProcessors=x+1; | |
825 | |
826 /* Create a new processor subkey on a multiprocessor | |
827 * system | |
828 */ | |
1096 | 829 snprintf(buf,20,"%d",x); |
1 | 830 } |
831 if (!lstrncmpiA(line,"stepping",strlen("stepping"))) { | |
832 int x; | |
833 | |
834 if (sscanf(value,"%d",&x)) | |
835 cachedsi.wProcessorRevision = x; | |
836 } | |
128 | 837 if |
838 ( (!lstrncmpiA(line,"flags",strlen("flags"))) | |
839 || (!lstrncmpiA(line,"features",strlen("features"))) ) | |
840 { | |
1 | 841 if (strstr(value,"cx8")) |
842 PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE; | |
843 if (strstr(value,"mmx")) | |
844 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE; | |
845 | |
846 } | |
847 } | |
848 fclose (f); | |
128 | 849 /* |
850 * ad hoc fix for smp machines. | |
851 * some problems on WaitForSingleObject,CreateEvent,SetEvent | |
852 * CreateThread ...etc.. | |
853 * | |
854 */ | |
855 cachedsi.dwNumberOfProcessors=1; | |
1 | 856 } |
857 #endif /* __FreeBSD__ */ | |
858 memcpy(si,&cachedsi,sizeof(*si)); | |
128 | 859 DumpSystemInfo(si); |
1 | 860 } |
861 | |
862 long WINAPI expGetVersion() | |
863 { | |
128 | 864 dbgprintf("GetVersion() => 0xC0000004\n"); |
865 return 0xC0000004;//Windows 95 | |
1 | 866 } |
867 | |
868 HANDLE WINAPI expHeapCreate(long flags, long init_size, long max_size) | |
869 { | |
870 // printf("HeapCreate:"); | |
128 | 871 HANDLE result; |
1 | 872 if(init_size==0) |
128 | 873 result=(HANDLE)my_mreq(0x110000, 0); |
1 | 874 else |
128 | 875 result=(HANDLE)my_mreq(init_size, 0); |
876 dbgprintf("HeapCreate(flags 0x%x, initial size %d, maximum size %d) => 0x%x\n", flags, init_size, max_size, result); | |
877 return result; | |
1 | 878 } |
879 void* WINAPI expHeapAlloc(HANDLE heap, int flags, int size) | |
880 { | |
881 void* z; | |
882 // printf("HeapAlloc:"); | |
128 | 883 /** |
884 Morgan's m3jpeg32.dll v. 2.0 encoder expects that request for | |
885 HeapAlloc returns area larger than size argument :-/ | |
886 **/ | |
887 z=my_mreq(((size+4095)/4096)*4096, flags&8); | |
1 | 888 // z=HeapAlloc(heap,flags,size); |
889 if(z==0) | |
890 printf("HeapAlloc failure\n"); | |
128 | 891 dbgprintf("HeapAlloc(heap 0x%x, flags 0x%x, size 0x%x) => 0x%x\n", heap, flags, size, z); |
1 | 892 return z; |
893 } | |
894 long WINAPI expHeapDestroy(void* heap) | |
895 { | |
128 | 896 dbgprintf("HeapDestroy(heap 0x%x) => 1\n", heap); |
1 | 897 my_release(heap); |
898 return 1; | |
899 } | |
900 | |
901 long WINAPI expHeapFree(int arg1, int arg2, void* ptr) | |
902 { | |
128 | 903 dbgprintf("HeapFree(0x%x, 0x%x, pointer 0x%x) => 1\n", arg1, arg2, ptr); |
1 | 904 my_release(ptr); |
905 return 1; | |
906 } | |
907 long WINAPI expHeapSize(int heap, int flags, void* pointer) | |
908 { | |
128 | 909 long result=my_size(pointer); |
910 dbgprintf("HeapSize(heap 0x%x, flags 0x%x, pointer 0x%x) => %d\n", heap, flags, pointer, result); | |
911 return result; | |
1 | 912 } |
913 long WINAPI expGetProcessHeap(void) | |
914 { | |
128 | 915 dbgprintf("GetProcessHeap() => 1\n"); |
1 | 916 return 1; |
917 } | |
918 void* WINAPI expVirtualAlloc(void* v1, long v2, long v3, long v4) | |
919 { | |
920 void* z; | |
921 z=VirtualAlloc(v1, v2, v3, v4); | |
922 if(z==0) | |
923 printf("VirtualAlloc failure\n"); | |
128 | 924 dbgprintf("VirtualAlloc(0x%x, %d, %d, %d) => 0x%x \n",v1,v2,v3,v4, z); |
1 | 925 return z; |
926 } | |
927 int WINAPI expVirtualFree(void* v1, int v2, int v3) | |
928 { | |
128 | 929 int result=VirtualFree(v1,v2,v3); |
930 dbgprintf("VirtualFree(0x%x, %d, %d) => %d\n",v1,v2,v3, result); | |
931 return result; | |
1 | 932 } |
933 struct CRITSECT | |
934 { | |
935 pthread_t id; | |
936 pthread_mutex_t mutex; | |
937 int locked; | |
938 }; | |
939 void WINAPI expInitializeCriticalSection(CRITICAL_SECTION* c) | |
940 { | |
941 struct CRITSECT cs; | |
128 | 942 dbgprintf("InitializeCriticalSection(0x%x)\n", c); |
1 | 943 /* if(sizeof(pthread_mutex_t)>sizeof(CRITICAL_SECTION)) |
944 { | |
945 printf(" ERROR:::: sizeof(pthread_mutex_t) is %d, expected <=%d!\n", | |
946 sizeof(pthread_mutex_t), sizeof(CRITICAL_SECTION)); | |
947 return; | |
948 }*/ | |
949 /* pthread_mutex_init((pthread_mutex_t*)c, NULL); */ | |
950 pthread_mutex_init(&cs.mutex, NULL); | |
951 cs.locked=0; | |
952 *(void**)c=malloc(sizeof cs); | |
953 memcpy(*(void**)c, &cs, sizeof cs); | |
954 return; | |
955 } | |
956 void WINAPI expEnterCriticalSection(CRITICAL_SECTION* c) | |
957 { | |
128 | 958 struct CRITSECT* cs=*(struct CRITSECT**)c; |
959 dbgprintf("EnterCriticalSection(0x%x)\n",c); | |
1 | 960 // cs.id=pthread_self(); |
961 if(cs->locked) | |
962 if(cs->id==pthread_self()) | |
963 return; | |
964 pthread_mutex_lock(&(cs->mutex)); | |
965 cs->locked=1; | |
966 cs->id=pthread_self(); | |
967 return; | |
968 } | |
969 void WINAPI expLeaveCriticalSection(CRITICAL_SECTION* c) | |
970 { | |
128 | 971 struct CRITSECT* cs=*(struct CRITSECT**)c; |
972 // struct CRITSECT* cs=(struct CRITSECT*)c; | |
973 dbgprintf("LeaveCriticalSection(0x%x)\n",c); | |
1 | 974 cs->locked=0; |
975 pthread_mutex_unlock(&(cs->mutex)); | |
976 return; | |
977 } | |
978 void WINAPI expDeleteCriticalSection(CRITICAL_SECTION *c) | |
979 { | |
128 | 980 struct CRITSECT* cs=*(struct CRITSECT**)c; |
981 // struct CRITSECT* cs=(struct CRITSECT*)c; | |
982 dbgprintf("DeleteCriticalSection(0x%x)\n",c); | |
983 pthread_mutex_destroy(&(cs->mutex)); | |
984 free(cs); | |
1 | 985 return; |
986 } | |
987 int WINAPI expGetCurrentThreadId() | |
988 { | |
128 | 989 dbgprintf("GetCurrentThreadId() => %d\n", getpid()); |
990 return getpid(); | |
991 } | |
992 int WINAPI expGetCurrentProcess() | |
993 { | |
994 dbgprintf("GetCurrentProcess() => %d\n", getpid()); | |
1 | 995 return getpid(); |
996 } | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
997 |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
998 struct tls_s |
1 | 999 { |
1000 void* value; | |
1001 int used; | |
1002 struct tls_s* prev; | |
1003 struct tls_s* next; | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1004 }; |
1 | 1005 tls_t* g_tls=NULL; |
1006 | |
1007 void* WINAPI expTlsAlloc() | |
1008 { | |
1009 if(g_tls==NULL) | |
1010 { | |
1011 g_tls=my_mreq(sizeof(tls_t), 0); | |
1012 g_tls->next=g_tls->prev=NULL; | |
1013 } | |
1014 else | |
1015 { | |
1016 g_tls->next=my_mreq(sizeof(tls_t), 0); | |
1017 g_tls->next->prev=g_tls; | |
1018 g_tls->next->next=NULL; | |
1019 g_tls=g_tls->next; | |
1020 } | |
128 | 1021 dbgprintf("TlsAlloc() => 0x%x\n", g_tls); |
1022 return g_tls; | |
1 | 1023 } |
1024 | |
1025 int WINAPI expTlsSetValue(tls_t* index, void* value) | |
1026 { | |
128 | 1027 int result; |
1 | 1028 if(index==0) |
128 | 1029 result=0; |
1030 else | |
1031 { | |
1032 index->value=value; | |
1033 result=1; | |
1034 } | |
1035 dbgprintf("TlsSetValue(index 0x%x, value 0x%x) => %d \n", index, value, result ); | |
1036 return result; | |
1 | 1037 } |
1038 void* WINAPI expTlsGetValue(tls_t* index) | |
1039 { | |
128 | 1040 void* result; |
1 | 1041 if(index==0) |
128 | 1042 result=0; |
1043 else | |
1044 result=index->value; | |
1045 dbgprintf("TlsGetValue(index 0x%x) => 0x%x\n", index, result); | |
1046 return result; | |
1 | 1047 } |
1048 int WINAPI expTlsFree(tls_t* index) | |
1049 { | |
128 | 1050 int result; |
1 | 1051 if(index==0) |
128 | 1052 result=0; |
1053 else | |
1054 { | |
1055 if(index->next) | |
1056 index->next->prev=index->prev; | |
1057 if(index->prev) | |
1058 index->prev->next=index->next; | |
1059 my_release((void*)index); | |
1060 result=1; | |
1061 } | |
1062 dbgprintf("TlsFree(index 0x%x) => %d\n", index, result); | |
1063 return result; | |
1 | 1064 } |
1065 void* WINAPI expLocalAlloc(int flags, int size) | |
1066 { | |
1067 void* z; | |
1068 if(flags&GMEM_ZEROINIT) | |
1069 z=my_mreq(size, 1); | |
1070 else | |
1071 z=my_mreq(size, 0); | |
1072 if(z==0) | |
1073 printf("LocalAlloc() failed\n"); | |
128 | 1074 dbgprintf("LocalAlloc(%d, flags 0x%x) => 0x%x\n", size, flags, z); |
1 | 1075 return z; |
1076 } | |
1077 void* WINAPI expLocalLock(void* z) | |
1078 { | |
128 | 1079 dbgprintf("LocalLock(0x%x) => 0x%x\n", z, z); |
1 | 1080 return z; |
1081 } | |
128 | 1082 |
1 | 1083 void* WINAPI expGlobalAlloc(int flags, int size) |
1084 { | |
1085 void* z; | |
1086 dbgprintf("GlobalAlloc(%d, flags 0x%X)\n", size, flags); | |
1087 if(flags&GMEM_ZEROINIT) | |
128 | 1088 z=calloc(size, 1); |
1089 // z=my_mreq(size, 1); | |
1 | 1090 else |
128 | 1091 z=malloc(size); |
1092 // z=my_mreq(size, 0); | |
1 | 1093 if(z==0) |
128 | 1094 printf("GlobalAlloc() failed\n"); |
1095 dbgprintf("GlobalAlloc(%d, flags 0x%x) => 0x%x\n", size, flags, z); | |
1 | 1096 return z; |
1097 } | |
1098 void* WINAPI expGlobalLock(void* z) | |
1099 { | |
128 | 1100 dbgprintf("GlobalLock(0x%x) => 0x%x\n", z, z); |
1 | 1101 return z; |
1102 } | |
1103 int WINAPI expLoadStringA(long instance, long id, void* buf, long size) | |
1104 { | |
128 | 1105 int result=LoadStringA(instance, id, buf, size); |
1106 // if(buf) | |
1107 dbgprintf("LoadStringA(instance 0x%x, id 0x%x, buffer 0x%x, size %d) => %d ( %s )\n", | |
1108 instance, id, buf, size, result, buf); | |
1109 // else | |
1110 // dbgprintf("LoadStringA(instance 0x%x, id 0x%x, buffer 0x%x, size %d) => %d\n", | |
1111 // instance, id, buf, size, result); | |
1112 return result; | |
1 | 1113 } |
1114 | |
128 | 1115 long WINAPI expMultiByteToWideChar(long v1, long v2, char* s1, long siz1, short* s2, int siz2) |
1 | 1116 { |
1117 #warning FIXME | |
128 | 1118 int i; |
1119 int result; | |
1 | 1120 if(s2==0) |
128 | 1121 result=1; |
1122 else | |
1123 { | |
1124 if(siz1>siz2/2)siz1=siz2/2; | |
1125 for(i=1; i<=siz1; i++) | |
1126 { | |
1127 *s2=*s1; | |
1128 if(!*s1)break; | |
1129 s2++; | |
1130 s1++; | |
1131 } | |
1132 result=i; | |
1133 } | |
1134 if(s1) | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1135 dbgprintf("MultiByteToWideChar(codepage %d, flags 0x%x, string 0x%x='%s', " |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1136 "size %d, dest buffer 0x%x, dest size %d) => %d\n", |
128 | 1137 v1, v2, s1, s1, siz1, s2, siz2, result); |
1138 else | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1139 dbgprintf("MultiByteToWideChar(codepage %d, flags 0x%x, string NULL, " |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1140 "size %d, dest buffer 0x%x, dest size %d) =>\n", |
128 | 1141 v1, v2, siz1, s2, siz2, result); |
1142 return result; | |
1143 } | |
1144 static void wch_print(const short* str) | |
1145 { | |
1146 dbgprintf(" src: "); | |
1147 while(*str)dbgprintf("%c", *str++); | |
1148 dbgprintf("\n"); | |
1 | 1149 } |
1150 long WINAPI expWideCharToMultiByte(long v1, long v2, short* s1, long siz1, char* s2, int siz2, char* c3, int* siz3) | |
1151 { | |
1152 int result; | |
128 | 1153 dbgprintf("WideCharToMultiByte(codepage %d, flags 0x%x, src 0x%x, src size %d, " |
1154 "dest 0x%x, dest size %d, defch 0x%x, used_defch 0x%x)", v1, v2, s1, siz1, s2, siz2, c3, siz3); | |
1 | 1155 result=WideCharToMultiByte(v1, v2, s1, siz1, s2, siz2, c3, siz3); |
1156 dbgprintf("=> %d\n", result); | |
128 | 1157 if(s1)wch_print(s1); |
1158 if(s2)dbgprintf(" dest: %s\n", s2); | |
1 | 1159 return result; |
1160 } | |
1161 long WINAPI expGetVersionExA(OSVERSIONINFOA* c) | |
1162 { | |
128 | 1163 dbgprintf("GetVersionExA(0x%x) => 1\n"); |
1164 c->dwOSVersionInfoSize=sizeof(*c); | |
1 | 1165 c->dwMajorVersion=4; |
128 | 1166 c->dwMinorVersion=0; |
1167 c->dwBuildNumber=0x4000457; | |
1 | 1168 c->dwPlatformId=VER_PLATFORM_WIN32_WINDOWS; |
128 | 1169 strcpy(c->szCSDVersion, " B"); |
1170 dbgprintf(" Major version: 4\n Minor version: 0\n Build number: 0x4000457\n" | |
1171 " Platform Id: VER_PLATFORM_WIN32_WINDOWS\n Version string: ' B'\n"); | |
1 | 1172 return 1; |
1173 } | |
1174 HANDLE WINAPI expCreateSemaphoreA(char* v1, long init_count, long max_count, char* name) | |
1175 { | |
128 | 1176 pthread_mutex_t *pm; |
1177 pthread_cond_t *pc; | |
1178 if(mlist!=NULL) | |
1 | 1179 { |
128 | 1180 mutex_list* pp=mlist; |
1181 if(name!=NULL) | |
1182 do | |
1183 { | |
1184 if((strcmp(pp->name, name)==0) && (pp->type==1)) | |
1185 { | |
1186 dbgprintf("CreateSemaphoreA(0x%x, init_count %d, max_count %d, name 0x%x='%s') => 0x%x", | |
1187 v1, init_count, max_count, name, name, mlist); | |
1188 return (HANDLE)mlist; | |
1189 } | |
597 | 1190 }while((pp=pp->prev)); |
1 | 1191 } |
128 | 1192 pm=my_mreq(sizeof(pthread_mutex_t), 0); |
1193 pthread_mutex_init(pm, NULL); | |
1194 pc=my_mreq(sizeof(pthread_cond_t), 0); | |
1195 pthread_cond_init(pc, NULL); | |
1196 if(mlist==NULL) | |
1197 { | |
1198 mlist=my_mreq(sizeof(mutex_list), 00); | |
1199 mlist->next=mlist->prev=NULL; | |
1200 } | |
1201 else | |
1 | 1202 { |
128 | 1203 mlist->next=my_mreq(sizeof(mutex_list), 00); |
1204 mlist->next->prev=mlist; | |
1205 mlist->next->next=NULL; | |
1206 mlist=mlist->next; | |
1 | 1207 } |
128 | 1208 mlist->type=1; /* Type Semaphore */ |
1209 mlist->pm=pm; | |
1210 mlist->pc=pc; | |
1211 mlist->state=0; | |
1212 mlist->reset=0; | |
1213 mlist->semaphore=init_count; | |
1214 if(name!=NULL) | |
1215 strncpy(mlist->name, name, 64); | |
1216 else | |
1217 mlist->name[0]=0; | |
1218 if(pm==NULL) | |
1219 dbgprintf("ERROR::: CreateSemaphoreA failure\n"); | |
1220 if(name) | |
1221 dbgprintf("CreateSemaphoreA(0x%x, init_count %d, max_count %d, name 0x%x='%s') => 0x%x", | |
1222 v1, init_count, max_count, name, name, mlist); | |
1223 else | |
1224 dbgprintf("CreateSemaphoreA(0x%x, init_count %d, max_count %d, name 0) => 0x%x", | |
1225 v1, init_count, max_count, mlist); | |
1226 return (HANDLE)mlist; | |
1 | 1227 } |
1228 | |
1229 long WINAPI expReleaseSemaphore(long hsem, long increment, long* prev_count) | |
1230 { | |
1231 // The state of a semaphore object is signaled when its count | |
1232 // is greater than zero and nonsignaled when its count is equal to zero | |
1233 // Each time a waiting thread is released because of the semaphore's signaled | |
1234 // state, the count of the semaphore is decreased by one. | |
128 | 1235 mutex_list *ml = (mutex_list *)hsem; |
1 | 1236 |
128 | 1237 pthread_mutex_lock(ml->pm); |
1238 if (prev_count != 0) *prev_count = ml->semaphore; | |
1239 if (ml->semaphore == 0) pthread_cond_signal(ml->pc); | |
1240 ml->semaphore += increment; | |
1241 pthread_mutex_unlock(ml->pm); | |
1242 dbgprintf("ReleaseSemaphore(semaphore 0x%x, increment %d, prev_count 0x%x) => 1\n", | |
1243 hsem, increment, prev_count); | |
1244 return 1; | |
1 | 1245 } |
1246 | |
1247 | |
1248 long WINAPI expRegOpenKeyExA(long key, const char* subkey, long reserved, long access, int* newkey) | |
1249 { | |
128 | 1250 long result=RegOpenKeyExA(key, subkey, reserved, access, newkey); |
1251 dbgprintf("RegOpenKeyExA(key 0x%x, subkey %s, reserved %d, access 0x%x, pnewkey 0x%x) => %d\n", | |
1252 key, subkey, reserved, access, newkey, result); | |
1253 if(newkey)dbgprintf(" New key: 0x%x\n", *newkey); | |
1254 return result; | |
1 | 1255 } |
1256 long WINAPI expRegCloseKey(long key) | |
1257 { | |
128 | 1258 long result=RegCloseKey(key); |
1259 dbgprintf("RegCloseKey(0x%x) => %d\n", key, result); | |
1260 return result; | |
1 | 1261 } |
1262 long WINAPI expRegQueryValueExA(long key, const char* value, int* reserved, int* type, int* data, int* count) | |
1263 { | |
128 | 1264 long result=RegQueryValueExA(key, value, reserved, type, data, count); |
1265 dbgprintf("RegQueryValueExA(key 0x%x, value %s, reserved 0x%x, data 0x%x, count 0x%x)" | |
1266 " => 0x%x\n", key, value, reserved, data, count, result); | |
1267 if(data && count)dbgprintf(" read %d bytes: '%s'\n", *count, data); | |
1268 return result; | |
1 | 1269 } |
1270 long WINAPI expRegCreateKeyExA(long key, const char* name, long reserved, | |
1271 void* classs, long options, long security, | |
1272 void* sec_attr, int* newkey, int* status) | |
1273 { | |
128 | 1274 long result=RegCreateKeyExA(key, name, reserved, classs, options, security, sec_attr, newkey, status); |
1275 dbgprintf("RegCreateKeyExA(key 0x%x, name 0x%x='%s', reserved=0x%x," | |
1276 " 0x%x, 0x%x, 0x%x, newkey=0x%x, status=0x%x) => %d\n", | |
1277 key, name, name, reserved, classs, options, security, sec_attr, newkey, status, result); | |
1278 if(!result && newkey) dbgprintf(" New key: 0x%x\n", *newkey); | |
1279 if(!result && status) dbgprintf(" New key status: 0x%x\n", *status); | |
1280 return result; | |
1 | 1281 } |
1282 long WINAPI expRegSetValueExA(long key, const char* name, long v1, long v2, void* data, long size) | |
1283 { | |
128 | 1284 long result=RegSetValueExA(key, name, v1, v2, data, size); |
1285 dbgprintf("RegSetValueExA(key 0x%x, name '%s', 0x%x, 0x%x, data 0x%x -> 0x%x '%s', size=%d) => %d", | |
1286 key, name, v1, v2, data, *(int*)data, data, size, result); | |
1287 return result; | |
1 | 1288 } |
1289 | |
1290 long WINAPI expRegOpenKeyA ( | |
1291 long hKey, | |
1292 LPCSTR lpSubKey, | |
1293 int* phkResult | |
1294 ){ | |
128 | 1295 long result=RegOpenKeyExA(hKey, lpSubKey, 0, 0, phkResult); |
1296 dbgprintf("RegOpenKeyExA(key 0x%x, subkey '%s', 0x%x) => %d\n", | |
1297 hKey, lpSubKey, phkResult, result); | |
1298 if(!result && phkResult) dbgprintf(" New key: 0x%x\n", *phkResult); | |
1299 return result; | |
1 | 1300 } |
1301 | |
1302 long WINAPI expQueryPerformanceCounter(long long* z) | |
1303 { | |
1304 longcount(z); | |
128 | 1305 dbgprintf("QueryPerformanceCounter(0x%x) => 1 ( %Ld )\n", z, *z); |
1 | 1306 return 1; |
1307 } | |
1308 | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1309 /* |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1310 * return CPU clock (in kHz), using linux's /proc filesystem (/proc/cpuinfo) |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1311 */ |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1312 static double linux_cpuinfo_freq() |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1313 { |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1314 double freq=-1; |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1315 FILE *f; |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1316 char line[200]; |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1317 char *s,*value; |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1318 |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1319 f = fopen ("/proc/cpuinfo", "r"); |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1320 if (f != NULL) { |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1321 while (fgets(line,sizeof(line),f)!=NULL) { |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1322 /* NOTE: the ':' is the only character we can rely on */ |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1323 if (!(value = strchr(line,':'))) |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1324 continue; |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1325 /* terminate the valuename */ |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1326 *value++ = '\0'; |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1327 /* skip any leading spaces */ |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1328 while (*value==' ') value++; |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1329 if ((s=strchr(value,'\n'))) |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1330 *s='\0'; |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1331 |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1332 if (!strncasecmp(line, "cpu MHz",strlen("cpu MHz")) |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1333 && sscanf(value, "%lf", &freq) == 1) { |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1334 freq*=1000; |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1335 break; |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1336 } |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1337 } |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1338 fclose(f); |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1339 } |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1340 return freq; |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1341 } |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1342 |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1343 |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1344 static double |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1345 solaris_kstat_freq() |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1346 { |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1347 #if HAVE_LIBKSTAT |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1348 /* |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1349 * try to extract the CPU speed from the solaris kernel's kstat data |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1350 */ |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1351 kstat_ctl_t *kc; |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1352 kstat_t *ksp; |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1353 kstat_named_t *kdata; |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1354 int mhz = 0; |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1355 |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1356 kc = kstat_open(); |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1357 if (kc != NULL) |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1358 { |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1359 ksp = kstat_lookup(kc, "cpu_info", 0, "cpu_info0"); |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1360 |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1361 /* kstat found and name/value pairs? */ |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1362 if (ksp != NULL && ksp->ks_type == KSTAT_TYPE_NAMED) |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1363 { |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1364 /* read the kstat data from the kernel */ |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1365 if (kstat_read(kc, ksp, NULL) != -1) |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1366 { |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1367 /* |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1368 * lookup desired "clock_MHz" entry, check the expected |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1369 * data type |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1370 */ |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1371 kdata = (kstat_named_t *)kstat_data_lookup(ksp, "clock_MHz"); |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1372 if (kdata != NULL && kdata->data_type == KSTAT_DATA_INT32) |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1373 mhz = kdata->value.i32; |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1374 } |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1375 } |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1376 kstat_close(kc); |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1377 } |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1378 |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1379 if (mhz > 0) |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1380 return mhz * 1000.; |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1381 #endif /* HAVE_LIBKSTAT */ |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1382 return -1; // kstat stuff is not available, CPU freq is unknown |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1383 } |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1384 |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1385 /* |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1386 * Measure CPU freq using the pentium's time stamp counter register (TSC) |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1387 */ |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1388 static double tsc_freq() |
1 | 1389 { |
128 | 1390 static double ofreq=0.0; |
1391 int i; | |
1 | 1392 int x,y; |
128 | 1393 i=time(NULL); |
1394 if (ofreq != 0.0) return ofreq; | |
1 | 1395 while(i==time(NULL)); |
1396 x=localcount(); | |
1397 i++; | |
1398 while(i==time(NULL)); | |
1399 y=localcount(); | |
128 | 1400 ofreq = (double)(y-x)/1000.; |
1401 return ofreq; | |
1 | 1402 } |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1403 |
1 | 1404 static double CPU_Freq() |
1405 { | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1406 double freq; |
1 | 1407 |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1408 if ((freq = linux_cpuinfo_freq()) > 0) |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1409 return freq; |
1 | 1410 |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1411 if ((freq = solaris_kstat_freq()) > 0) |
1 | 1412 return freq; |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1413 |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1414 return tsc_freq(); |
1 | 1415 } |
1416 | |
1417 long WINAPI expQueryPerformanceFrequency(long long* z) | |
1418 { | |
1419 *z=(long long)CPU_Freq(); | |
128 | 1420 dbgprintf("QueryPerformanceFrequency(0x%x) => 1 ( %Ld )\n", z, *z); |
1 | 1421 return 1; |
1422 } | |
1423 long WINAPI exptimeGetTime() | |
1424 { | |
1425 struct timeval t; | |
128 | 1426 long result; |
1 | 1427 gettimeofday(&t, 0); |
128 | 1428 result=1000*t.tv_sec+t.tv_usec/1000; |
1429 dbgprintf("timeGetTime() => %d\n", result); | |
1430 return result; | |
1 | 1431 } |
1432 void* WINAPI expLocalHandle(void* v) | |
1433 { | |
128 | 1434 dbgprintf("LocalHandle(0x%x) => 0x%x\n", v, v); |
1 | 1435 return v; |
1436 } | |
1437 void* WINAPI expGlobalHandle(void* v) | |
1438 { | |
128 | 1439 dbgprintf("GlobalHandle(0x%x) => 0x%x\n", v, v); |
1 | 1440 return v; |
1441 } | |
1442 int WINAPI expGlobalUnlock(void* v) | |
1443 { | |
128 | 1444 dbgprintf("GlobalUnlock(0x%x) => 1\n", v); |
1 | 1445 return 1; |
1446 } | |
1447 // | |
1448 void* WINAPI expGlobalFree(void* v) | |
1449 { | |
128 | 1450 dbgprintf("GlobalFree(0x%x) => 0\n", v); |
1451 //my_release(v); | |
1452 free(v); | |
1 | 1453 return 0; |
128 | 1454 } |
1455 | |
1456 | |
1457 void* WINAPI expGlobalReAlloc(void* v, int size, int flags) | |
1458 { | |
1459 void* result=realloc(v, size); | |
1460 dbgprintf("GlobalReAlloc(0x%x, size %d, flags 0x%x) => 0x%x\n", v,size,flags,result); | |
1461 return result; | |
1462 } | |
1 | 1463 |
1464 int WINAPI expLocalUnlock(void* v) | |
1465 { | |
128 | 1466 dbgprintf("LocalUnlock(0x%x) => 1\n", v); |
1 | 1467 return 1; |
1468 } | |
128 | 1469 // |
1 | 1470 void* WINAPI expLocalFree(void* v) |
1471 { | |
128 | 1472 dbgprintf("LocalFree(0x%x) => 0\n", v); |
1 | 1473 my_release(v); |
1474 return 0; | |
1475 } | |
1476 HRSRC WINAPI expFindResourceA(HMODULE module, char* name, char* type) | |
1477 { | |
128 | 1478 HRSRC result=FindResourceA(module, name, type); |
1479 dbgprintf("FindResourceA(module 0x%x, name 0x%x, type 0x%x) => 0x%x\n", module, name, type, result); | |
1480 return result; | |
1 | 1481 } |
128 | 1482 extern HRSRC WINAPI LoadResource(HMODULE, HRSRC); |
1 | 1483 HGLOBAL WINAPI expLoadResource(HMODULE module, HRSRC res) |
1484 { | |
128 | 1485 HGLOBAL result=LoadResource(module, res); |
1486 dbgprintf("LoadResource(module 0x%x, resource 0x%x) => 0x%x\n", module, res, result); | |
1487 return result; | |
1 | 1488 } |
1489 void* WINAPI expLockResource(long res) | |
1490 { | |
128 | 1491 void* result=LockResource(res); |
1492 dbgprintf("LockResource(0x%x) => 0x%x\n", res, result); | |
1493 return result; | |
1 | 1494 } |
1495 int WINAPI expFreeResource(long res) | |
1496 { | |
128 | 1497 int result=FreeResource(res); |
1498 dbgprintf("FreeResource(0x%x) => %d\n", res, result); | |
1499 return result; | |
1 | 1500 } |
1501 //bool fun(HANDLE) | |
1502 //!0 on success | |
1503 int WINAPI expCloseHandle(long v1) | |
1504 { | |
128 | 1505 dbgprintf("CloseHandle(0x%x) => 1\n", v1); |
1 | 1506 return 1; |
1507 } | |
1508 | |
1509 const char* WINAPI expGetCommandLineA() | |
1510 { | |
128 | 1511 dbgprintf("GetCommandLineA() => \"c:\\aviplay.exe\"\n"); |
1 | 1512 return "c:\\aviplay.exe"; |
1513 } | |
128 | 1514 static short envs[]={'p', 'a', 't', 'h', ' ', 'c', ':', '\\', 0, 0}; |
1 | 1515 LPWSTR WINAPI expGetEnvironmentStringsW() |
1516 { | |
128 | 1517 dbgprintf("GetEnvironmentStringsW() => 0\n", envs); |
1518 return 0; | |
1 | 1519 } |
121 | 1520 void * WINAPI expRtlZeroMemory(void *p, size_t len) |
1521 { | |
1522 void* result=memset(p,0,len); | |
1523 dbgprintf("RtlZeroMemory(0x%x, len %d) => 0x%x\n",p,len,result); | |
1524 return result; | |
1525 } | |
1526 void * WINAPI expRtlMoveMemory(void *dst, void *src, size_t len) | |
1527 { | |
1528 void* result=memmove(dst,src,len); | |
1529 dbgprintf("RtlMoveMemory (dest 0x%x, src 0x%x, len %d) => 0x%x\n",dst,src,len,result); | |
1530 return result; | |
1531 } | |
1532 | |
1533 void * WINAPI expRtlFillMemory(void *p, int ch, size_t len) | |
1534 { | |
1535 void* result=memset(p,ch,len); | |
1536 dbgprintf("RtlFillMemory(0x%x, char 0x%x, len %d) => 0x%x\n",p,ch,len,result); | |
1537 return result; | |
1538 } | |
1 | 1539 int WINAPI expFreeEnvironmentStringsW(short* strings) |
1540 { | |
128 | 1541 dbgprintf("FreeEnvironmentStringsW(0x%x) => 1\n", strings); |
1 | 1542 return 1; |
1543 } | |
128 | 1544 int WINAPI expFreeEnvironmentStringsA(char* strings) |
1545 { | |
1546 dbgprintf("FreeEnvironmentStringsA(0x%x) => 1\n", strings); | |
1547 return 1; | |
1548 } | |
1549 static const char ch_envs[]= | |
1550 "__MSVCRT_HEAP_SELECT=__GLOBAL_HEAP_SELECTED,1\r\n" | |
1551 "PATH=C:\\;C:\\windows\\;C:\\windows\\system\r\n"; | |
1 | 1552 LPCSTR WINAPI expGetEnvironmentStrings() |
1553 { | |
128 | 1554 dbgprintf("GetEnvironmentStrings() => 0x%x\n", ch_envs); |
1555 return (LPCSTR)ch_envs; | |
1556 // dbgprintf("GetEnvironmentStrings() => 0\n"); | |
1557 // return 0; | |
1 | 1558 } |
1559 | |
1560 int WINAPI expGetStartupInfoA(STARTUPINFOA *s) | |
1561 { | |
1562 int i; | |
128 | 1563 dbgprintf("GetStartupInfoA(0x%x) => 1\n"); |
1 | 1564 memset(s, 0, sizeof(*s)); |
1565 s->cb=sizeof(*s); | |
128 | 1566 // s->lpReserved="Reserved"; |
1567 // s->lpDesktop="Desktop"; | |
1568 // s->lpTitle="Title"; | |
1569 // s->dwX=s->dwY=0; | |
1570 // s->dwXSize=s->dwYSize=200; | |
1571 s->dwFlags=s->wShowWindow=1; | |
1572 // s->hStdInput=s->hStdOutput=s->hStdError=0x1234; | |
1573 dbgprintf(" cb=%d\n", s->cb); | |
1574 dbgprintf(" lpReserved='%s'\n", s->lpReserved); | |
1575 dbgprintf(" lpDesktop='%s'\n", s->lpDesktop); | |
1576 dbgprintf(" lpTitle='%s'\n", s->lpTitle); | |
1577 dbgprintf(" dwX=%d dwY=%d dwXSize=%d dwYSize=%d\n", | |
1578 s->dwX, s->dwY, s->dwXSize, s->dwYSize); | |
1579 dbgprintf(" dwXCountChars=%d dwYCountChars=%d dwFillAttribute=%d\n", | |
1580 s->dwXCountChars, s->dwYCountChars, s->dwFillAttribute); | |
1581 dbgprintf(" dwFlags=0x%x wShowWindow=0x%x cbReserved2=0x%x\n", | |
1582 s->dwFlags, s->wShowWindow, s->cbReserved2); | |
1583 dbgprintf(" lpReserved2=0x%x hStdInput=0x%x hStdOutput=0x%x hStdError=0x%x\n", | |
1584 s->lpReserved2, s->hStdInput, s->hStdOutput, s->hStdError); | |
1 | 1585 return 1; |
1586 } | |
1587 | |
1588 int WINAPI expGetStdHandle(int z) | |
1589 { | |
128 | 1590 dbgprintf("GetStdHandle(0x%x) => 0x%x\n", z+0x1234); |
1591 return z+0x1234; | |
1 | 1592 } |
1593 int WINAPI expGetFileType(int handle) | |
1594 { | |
128 | 1595 dbgprintf("GetFileType(0x%x) => 0x3 = pipe\n", handle); |
1596 return 0x3; | |
1 | 1597 } |
1598 int WINAPI expSetHandleCount(int count) | |
1599 { | |
128 | 1600 dbgprintf("SetHandleCount(0x%x) => 1\n", count); |
1 | 1601 return 1; |
1602 } | |
1603 int WINAPI expGetACP() | |
1604 { | |
128 | 1605 dbgprintf("GetACP() => 0\n"); |
1 | 1606 return 0; |
1607 } | |
1608 extern WINE_MODREF *MODULE32_LookupHMODULE(HMODULE m); | |
1609 int WINAPI expGetModuleFileNameA(int module, char* s, int len) | |
1610 { | |
1611 WINE_MODREF *mr; | |
128 | 1612 int result; |
1 | 1613 // printf("File name of module %X requested\n", module); |
1614 if(s==0) | |
128 | 1615 result=0; |
1616 else | |
1 | 1617 if(len<35) |
128 | 1618 result=0; |
1619 else | |
1 | 1620 { |
128 | 1621 result=1; |
1622 strcpy(s, "c:\\windows\\system\\"); | |
1623 mr=MODULE32_LookupHMODULE(module); | |
1624 if(mr==0)//oops | |
1625 strcat(s, "aviplay.dll"); | |
1626 else | |
1627 if(strrchr(mr->filename, '/')==NULL) | |
1628 strcat(s, mr->filename); | |
1629 else | |
1630 strcat(s, strrchr(mr->filename, '/')+1); | |
1631 } | |
1632 if(!s) | |
1633 dbgprintf("GetModuleFileNameA(0x%x, 0x%x, %d) => %d\n", | |
1634 module, s, len, result); | |
1 | 1635 else |
128 | 1636 dbgprintf("GetModuleFileNameA(0x%x, 0x%x, %d) => %d ( '%s' )", |
1637 module, s, len, result, s); | |
1638 return result; | |
1 | 1639 } |
1640 | |
1641 int WINAPI expSetUnhandledExceptionFilter(void* filter) | |
1642 { | |
128 | 1643 dbgprintf("SetUnhandledExceptionFilter(0x%x) => 1\n", filter); |
1 | 1644 return 1;//unsupported and probably won't ever be supported |
1645 } | |
1646 extern char* def_path; | |
1647 int WINAPI expLoadLibraryA(char* name) | |
1648 { | |
1649 char qq[256]; | |
128 | 1650 int result; |
713 | 1651 char* lastbc; |
1652 if (!name) | |
1653 return -1; | |
1654 // we skip to the last backslash | |
1655 // this is effectively eliminating weird characters in | |
1656 // the text output windows | |
1657 lastbc = strrchr(name, '\\'); | |
1658 if (lastbc) | |
1659 { | |
1660 int i; | |
1661 lastbc++; | |
1662 for (i = 0; 1 ;i++) | |
1663 { | |
1664 name[i] = *lastbc++; | |
1665 if (!name[i]) | |
1666 break; | |
1667 } | |
1668 } | |
1669 // printf("LoadLibrary wants: %s/%s\n", def_path, name); | |
1670 | |
128 | 1671 if(strncmp(name, "c:\\windows\\", 11)==0)name+=11; |
1416 | 1672 if(strncmp(name, ".\\", 2)==0) name += 2; |
128 | 1673 if(name[0]!='/') |
1674 { | |
1675 strcpy(qq, def_path); | |
1676 strcat(qq, "/"); | |
1416 | 1677 strcat(qq, name); |
128 | 1678 } |
341 | 1679 printf("Loading DLL: %s", qq);fflush(stdout); |
340 | 1680 // printf("Entering LoadLibraryA(%s)\n", name); |
128 | 1681 result=LoadLibraryA(qq); |
341 | 1682 if(!result) printf(" FAILED!\n"); else printf(" OK\n"); |
340 | 1683 // printf("Returned LoadLibraryA(0x%x='%s'), def_path=%s => 0x%x\n", name, name, def_path, result); |
128 | 1684 return result; |
1 | 1685 } |
1686 int WINAPI expFreeLibrary(int module) | |
1687 { | |
128 | 1688 int result=FreeLibrary(module); |
1689 dbgprintf("FreeLibrary(0x%x) => %d\n", module, result); | |
1690 return result; | |
1 | 1691 } |
597 | 1692 void* LookupExternalByName(const char* library, const char* name); |
1 | 1693 void* WINAPI expGetProcAddress(HMODULE mod, char* name) |
1694 { | |
597 | 1695 void *result; |
128 | 1696 if(mod!=0x120) |
1697 result=GetProcAddress(mod, name); | |
1698 else | |
1699 result=LookupExternalByName("kernel32.dll", name); | |
1700 dbgprintf("GetProcAddress(0x%x, '%s') => 0x%x\n", mod, name, result); | |
1701 return result; | |
1 | 1702 } |
1703 | |
1704 long WINAPI expCreateFileMappingA(int hFile, void* lpAttr, | |
1705 long flProtect, long dwMaxHigh, long dwMaxLow, const char* name) | |
1706 { | |
128 | 1707 long result=CreateFileMappingA(hFile, lpAttr, flProtect, dwMaxHigh, dwMaxLow, name); |
1708 if(!name) | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1709 dbgprintf("CreateFileMappingA(file 0x%x, lpAttr 0x%x, " |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1710 "flProtect 0x%x, dwMaxHigh 0x%x, dwMaxLow 0x%x, name 0) => %d\n", |
128 | 1711 hFile, lpAttr, flProtect, dwMaxHigh, dwMaxLow, result); |
1712 else | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1713 dbgprintf("CreateFileMappingA(file 0x%x, lpAttr 0x%x, " |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
1714 "flProtect 0x%x, dwMaxHigh 0x%x, dwMaxLow 0x%x, name 0x%x='%s') => %d\n", |
128 | 1715 hFile, lpAttr, flProtect, dwMaxHigh, dwMaxLow, name, name, result); |
1716 return result; | |
1 | 1717 } |
1718 | |
1719 long WINAPI expOpenFileMappingA(long hFile, long hz, const char* name) | |
1720 { | |
128 | 1721 long result=OpenFileMappingA(hFile, hz, name); |
1722 if(!name) | |
1723 dbgprintf("OpenFileMappingA(0x%x, 0x%x, 0) => %d\n", | |
1724 hFile, hz, result); | |
1725 else | |
1726 dbgprintf("OpenFileMappingA(0x%x, 0x%x, 0x%x='%s') => %d\n", | |
1727 hFile, hz, name, name, result); | |
1728 return result; | |
1 | 1729 } |
1730 | |
1731 void* WINAPI expMapViewOfFile(HANDLE file, DWORD mode, DWORD offHigh, DWORD offLow, DWORD size) | |
1732 { | |
128 | 1733 dbgprintf("MapViewOfFile(0x%x, 0x%x, 0x%x, 0x%x, size %d) => 0x%x\n", |
1734 file,mode,offHigh,offLow,size,(char*)file+offLow); | |
1 | 1735 return (char*)file+offLow; |
1736 } | |
1737 | |
1738 void* WINAPI expUnmapViewOfFile(void* view) | |
1739 { | |
128 | 1740 dbgprintf("UnmapViewOfFile(0x%x) => 0\n", view); |
1 | 1741 return 0; |
1742 } | |
1743 | |
1744 void* WINAPI expSleep(int time) | |
1745 { | |
128 | 1746 dbgprintf("Sleep(%d) => 0\n", time); |
1 | 1747 usleep(time); |
1748 return 0; | |
1749 } | |
1750 // why does IV32 codec want to call this? I don't know ... | |
1751 void* WINAPI expCreateCompatibleDC(int hdc) | |
1752 { | |
128 | 1753 dbgprintf("CreateCompatibleDC(%d) => 0x81\n", hdc); |
1754 return (void*)0x81; | |
1 | 1755 } |
1756 | |
1757 int WINAPI expGetDeviceCaps(int hdc, int unk) | |
1758 { | |
128 | 1759 dbgprintf("GetDeviceCaps(0x%x, %d) => 0\n", hdc, unk); |
1 | 1760 return 0; |
1761 } | |
1762 | |
1763 WIN_BOOL WINAPI expDeleteDC(int hdc) | |
1764 { | |
128 | 1765 dbgprintf("DeleteDC(0x%x) => 0\n", hdc); |
1 | 1766 return 0; |
1767 } | |
1768 | |
1769 int expwsprintfA(char* string, char* format, ...) | |
1770 { | |
1771 va_list va; | |
128 | 1772 int result; |
1 | 1773 va_start(va, format); |
128 | 1774 result=vsprintf(string, format, va); |
1775 dbgprintf("wsprintfA(0x%x, '%s', ...) => %d\n", string, format, result); | |
1776 va_end(va); | |
1777 return result; | |
1 | 1778 } |
1779 | |
1780 int WINAPI expGetPrivateProfileIntA(const char* appname, const char* keyname, int default_value, const char* filename) | |
1781 { | |
1782 int size=255; | |
1783 char buffer[256]; | |
1784 char* fullname; | |
1785 int result; | |
1786 | |
1787 buffer[255]=0; | |
128 | 1788 if(!(appname && keyname && filename) ) |
1789 { | |
1790 dbgprintf("GetPrivateProfileIntA('%s', '%s', %d, '%s') => %d\n", appname, keyname, default_value, filename, default_value ); | |
1791 return default_value; | |
1792 } | |
1 | 1793 fullname=(char*)malloc(50+strlen(appname)+strlen(keyname)+strlen(filename)); |
1794 strcpy(fullname, "Software\\IniFileMapping\\"); | |
1795 strcat(fullname, appname); | |
1796 strcat(fullname, "\\"); | |
1797 strcat(fullname, keyname); | |
1798 strcat(fullname, "\\"); | |
1799 strcat(fullname, filename); | |
1800 result=RegQueryValueExA(HKEY_LOCAL_MACHINE, fullname, NULL, NULL, (int*)buffer, &size); | |
1801 if((size>=0)&&(size<256)) | |
1802 buffer[size]=0; | |
1803 // printf("GetPrivateProfileIntA(%s, %s, %s) -> %s\n", appname, keyname, filename, buffer); | |
1804 free(fullname); | |
1805 if(result) | |
128 | 1806 result=default_value; |
1 | 1807 else |
128 | 1808 result=atoi(buffer); |
1809 dbgprintf("GetPrivateProfileIntA('%s', '%s', %d, '%s') => %d\n", appname, keyname, default_value, filename, result); | |
1810 return result; | |
1 | 1811 } |
128 | 1812 int WINAPI expGetProfileIntA(const char* appname, const char* keyname, int default_value) |
1813 { | |
1814 dbgprintf("GetProfileIntA -> "); | |
1815 // dbgprintf("GetProfileIntA(%s, %s, %d)\n", appname, keyname, default_value); | |
1816 return expGetPrivateProfileIntA(appname, keyname, default_value, "default"); | |
1817 } | |
1818 | |
1 | 1819 int WINAPI expGetPrivateProfileStringA(const char* appname, const char* keyname, |
1820 const char* def_val, char* dest, unsigned int len, const char* filename) | |
1821 { | |
1822 int result; | |
1823 int size; | |
1824 char* fullname; | |
128 | 1825 dbgprintf("GetPrivateProfileStringA('%s', '%s', def_val '%s', 0x%x, 0x%x, '%s')", appname, keyname, def_val, dest, len, filename ); |
1 | 1826 if(!(appname && keyname && filename) ) return 0; |
1827 fullname=(char*)malloc(50+strlen(appname)+strlen(keyname)+strlen(filename)); | |
1828 strcpy(fullname, "Software\\IniFileMapping\\"); | |
1829 strcat(fullname, appname); | |
1830 strcat(fullname, "\\"); | |
1831 strcat(fullname, keyname); | |
1832 strcat(fullname, "\\"); | |
1833 strcat(fullname, filename); | |
1834 size=len; | |
1835 result=RegQueryValueExA(HKEY_LOCAL_MACHINE, fullname, NULL, NULL, (int*)dest, &size); | |
1836 // printf("GetPrivateProfileStringA(%s, %s, %s, %X, %X, %s)\n", appname, keyname, def_val, dest, len, filename ); | |
1837 free(fullname); | |
128 | 1838 if(result) |
1839 { | |
1840 strncpy(dest, def_val, size); | |
1841 if (strlen(def_val)< size) size = strlen(def_val); | |
1842 } | |
1843 dbgprintf(" => %d ( '%s' )\n", size, dest); | |
1 | 1844 return size; |
1845 } | |
1846 int WINAPI expWritePrivateProfileStringA(const char* appname, const char* keyname, | |
1847 const char* string, const char* filename) | |
1848 { | |
1849 int size=256; | |
1850 char* fullname; | |
128 | 1851 dbgprintf("WritePrivateProfileStringA('%s', '%s', '%s', '%s')", appname, keyname, string, filename ); |
1852 if(!(appname && keyname && filename) ) | |
1853 { | |
1854 dbgprintf(" => -1\n"); | |
1855 return -1; | |
1856 } | |
1 | 1857 fullname=(char*)malloc(50+strlen(appname)+strlen(keyname)+strlen(filename)); |
1858 strcpy(fullname, "Software\\IniFileMapping\\"); | |
1859 strcat(fullname, appname); | |
1860 strcat(fullname, "\\"); | |
1861 strcat(fullname, keyname); | |
1862 strcat(fullname, "\\"); | |
1863 strcat(fullname, filename); | |
1864 RegSetValueExA(HKEY_LOCAL_MACHINE, fullname, 0, REG_SZ, (int*)string, strlen(string)); | |
1865 // printf("RegSetValueExA(%s,%d)\n", string, strlen(string)); | |
1866 // printf("WritePrivateProfileStringA(%s, %s, %s, %s)\n", appname, keyname, string, filename ); | |
1867 free(fullname); | |
128 | 1868 dbgprintf(" => 0\n"); |
1 | 1869 return 0; |
1870 } | |
1871 | |
1872 unsigned int _GetPrivateProfileIntA(const char* appname, const char* keyname, INT default_value, const char* filename) | |
1873 { | |
1874 return expGetPrivateProfileIntA(appname, keyname, default_value, filename); | |
1875 } | |
1876 int _GetPrivateProfileStringA(const char* appname, const char* keyname, | |
1877 const char* def_val, char* dest, unsigned int len, const char* filename) | |
1878 { | |
1879 return expGetPrivateProfileStringA(appname, keyname, def_val, dest, len, filename); | |
1880 } | |
1881 int _WritePrivateProfileStringA(const char* appname, const char* keyname, | |
1882 const char* string, const char* filename) | |
1883 { | |
1884 return expWritePrivateProfileStringA(appname, keyname, string, filename); | |
1885 } | |
1886 | |
1887 | |
128 | 1888 |
1 | 1889 int WINAPI expDefDriverProc(int _private, int id, int msg, int arg1, int arg2) |
1890 { | |
128 | 1891 dbgprintf("DefDriverProc(0x%x, 0x%x, 0x%x, 0x%x, 0x%x) => 0\n", _private, id, msg, arg1, arg2); |
1 | 1892 return 0; |
1893 } | |
1894 | |
1895 int WINAPI expSizeofResource(int v1, int v2) | |
1896 { | |
128 | 1897 int result=SizeofResource(v1, v2); |
1898 dbgprintf("SizeofResource(0x%x, 0x%x) => %d\n", v1, v2, result); | |
1899 return result; | |
1 | 1900 } |
1901 | |
1902 int WINAPI expGetLastError() | |
1903 { | |
128 | 1904 int result=GetLastError(); |
1905 dbgprintf("GetLastError() => 0x%x\n", result); | |
1906 return result; | |
1 | 1907 } |
1908 | |
1909 void WINAPI expSetLastError(int error) | |
1910 { | |
128 | 1911 dbgprintf("SetLastError(0x%x)\n", error); |
1 | 1912 SetLastError(error); |
1913 } | |
1914 | |
1915 char* expstrrchr(char* string, int value) | |
1916 { | |
128 | 1917 char* result=strrchr(string, value); |
1918 if(result) | |
1919 dbgprintf("strrchr(0x%x='%s', %d) => 0x%x='%s'", string, string, value, result, result); | |
1920 else | |
1921 dbgprintf("strrchr(0x%x='%s', %d) => 0", string, string, value); | |
1922 return result; | |
1 | 1923 } |
1924 | |
1925 char* expstrchr(char* string, int value) | |
1926 { | |
128 | 1927 char* result=strchr(string, value); |
1928 if(result) | |
1929 dbgprintf("strchr(0x%x='%s', %d) => 0x%x='%s'", string, string, value, result, result); | |
1930 else | |
1931 dbgprintf("strchr(0x%x='%s', %d) => 0", string, string, value); | |
1932 return result; | |
1 | 1933 } |
128 | 1934 int expstrlen(char* str) |
1935 { | |
1936 int result=strlen(str); | |
1937 dbgprintf("strlen(0x%x='%s') => %d\n", str, str, result); | |
1938 return result; | |
1939 } | |
713 | 1940 int expstrcpy(char* str1, const char* str2) |
128 | 1941 { |
713 | 1942 int result= (int) strcpy(str1, str2); |
1943 dbgprintf("strcpy(0x%x, 0x%x='%s') => %d\n", str1, str2, str2, result); | |
128 | 1944 return result; |
1945 } | |
1946 int expstrcmp(const char* str1, const char* str2) | |
1947 { | |
1948 int result=strcmp(str1, str2); | |
1949 dbgprintf("strcmp(0x%x='%s', 0x%x='%s') => %d\n", str1, str1, str2, str2, result); | |
1950 return result; | |
1951 } | |
713 | 1952 int expstrcat(char* str1, const char* str2) |
128 | 1953 { |
713 | 1954 int result= (int) strcat(str1, str2); |
1955 dbgprintf("strcat(0x%x='%s', 0x%x='%s') => %d\n", str1, str1, str2, str2, result); | |
128 | 1956 return result; |
1957 } | |
713 | 1958 int expisalnum(int c) |
128 | 1959 { |
713 | 1960 int result= (int) isalnum(c); |
1961 dbgprintf("isalnum(0x%x='%c' => %d\n", c, c, result); | |
1962 return result; | |
1963 } | |
1964 int expmemmove(void* dest, void* src, int n) | |
1965 { | |
1966 int result= (int) memmove(dest, src, n); | |
1967 dbgprintf("memmove(0x%x, 0x%x, %d) => %d\n", dest, src, n, result); | |
1968 return result; | |
128 | 1969 } |
1970 int expmemcmp(void* dest, void* src, int n) | |
1971 { | |
1972 int result=memcmp(dest, src, n); | |
1973 dbgprintf("memcmp(0x%x, 0x%x, %d) => %d\n", dest, src, n, result); | |
1974 return result; | |
1975 } | |
597 | 1976 void *expmemcpy(void* dest, void* src, int n) |
130 | 1977 { |
597 | 1978 void *result=memcpy(dest, src, n); |
1979 dbgprintf("memcpy(0x%x, 0x%x, %d) => %p\n", dest, src, n, result); | |
130 | 1980 return result; |
1981 } | |
128 | 1982 time_t exptime(time_t* t) |
1983 { | |
1984 time_t result=time(t); | |
1985 dbgprintf("time(0x%x) => %d\n", t, result); | |
1986 return result; | |
1987 } | |
1988 | |
1989 int WINAPI expStringFromGUID2(GUID* guid, char* str, int cbMax) | |
1990 { | |
597 | 1991 int result=snprintf(str, cbMax, "%.8lx-%.4x-%.4x-%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", |
128 | 1992 guid->f1, guid->f2, guid->f3, |
1993 (unsigned char)guid->f4[0], (unsigned char)guid->f4[1], (unsigned char)guid->f4[2], (unsigned char)guid->f4[3], | |
1994 (unsigned char)guid->f4[4], (unsigned char)guid->f4[5], (unsigned char)guid->f4[6], (unsigned char)guid->f4[7]); | |
1995 dbgprintf("StringFromGUID2(0x%x, 0x%x='%s', %d) => %d\n", guid, str, str, cbMax, result); | |
1996 return result; | |
1997 } | |
1998 | |
1 | 1999 |
2000 int WINAPI expGetFileVersionInfoSizeA(const char* name, int* lpHandle) | |
2001 { | |
128 | 2002 dbgprintf("GetFileVersionInfoSizeA(0x%x='%s', 0x%X) => 0\n", name, name, lpHandle); |
1 | 2003 return 0; |
2004 } | |
2005 | |
2006 int WINAPI expIsBadStringPtrW(const short* string, int nchars) | |
2007 { | |
128 | 2008 int result; |
2009 if(string==0)result=1; else result=0; | |
2010 dbgprintf("IsBadStringPtrW(0x%x, %d) => %d", string, nchars, result); | |
2011 if(string)wch_print(string); | |
2012 return result; | |
1 | 2013 } |
713 | 2014 |
2015 int WINAPI expIsBadStringPtrA(const char* string, int nchars) | |
2016 { | |
1416 | 2017 int result=0; |
713 | 2018 // if(string==0)result=1; else result=0; |
2019 // dbgprintf("IsBadStringPtrW(0x%x, %d) => %d", string, nchars, result); | |
2020 // if(string)wch_print(string); | |
2021 return result; | |
2022 } | |
2023 | |
1 | 2024 extern long WINAPI InterlockedExchangeAdd( long* dest, long incr ) |
2025 { | |
2026 long ret; | |
2027 __asm__ __volatile__( "lock; xaddl %0,(%1)" | |
2028 : "=r" (ret) : "r" (dest), "0" (incr) : "memory" ); | |
2029 return ret; | |
2030 } | |
2031 | |
2032 extern long WINAPI expInterlockedIncrement( long* dest ) | |
2033 { | |
128 | 2034 long result=InterlockedExchangeAdd( dest, 1 ) + 1; |
2035 dbgprintf("InterlockedIncrement(0x%x => %d) => %d\n", dest, *dest, result); | |
2036 return result; | |
1 | 2037 } |
2038 extern long WINAPI expInterlockedDecrement( long* dest ) | |
2039 { | |
128 | 2040 long result=InterlockedExchangeAdd( dest, -1 ) - 1; |
2041 dbgprintf("InterlockedDecrement(0x%x => %d) => %d\n", dest, *dest, result); | |
2042 return result; | |
1 | 2043 } |
2044 | |
2045 extern void WINAPI expOutputDebugStringA( const char* string ) | |
2046 { | |
128 | 2047 dbgprintf("OutputDebugStringA(0x%x='%s')\n", string); |
1 | 2048 fprintf(stderr, "DEBUG: %s\n", string); |
2049 } | |
2050 | |
2051 int WINAPI expGetDC(int hwnd) | |
2052 { | |
128 | 2053 dbgprintf("GetDC(0x%x) => 0\n", hwnd); |
1 | 2054 return 0; |
2055 } | |
2056 | |
2057 int WINAPI expGetDesktopWindow() | |
2058 { | |
128 | 2059 dbgprintf("GetDesktopWindow() => 0\n"); |
1 | 2060 return 0; |
2061 } | |
2062 | |
2063 int WINAPI expReleaseDC(int hwnd, int hdc) | |
2064 { | |
128 | 2065 dbgprintf("ReleaseDC(0x%x, 0x%x) => 0\n", hwnd, hdc); |
2066 return 0; | |
2067 } | |
2068 static int cursor[100]; | |
2069 | |
2070 int WINAPI expLoadCursorA(int handle,LPCSTR name) | |
2071 { | |
2072 dbgprintf("LoadCursorA(%d, 0x%x='%s') => 0x%x\n", handle, name, (int)&cursor[0]); | |
2073 return (int)&cursor[0]; | |
2074 } | |
2075 int WINAPI expSetCursor(void *cursor) | |
2076 { | |
2077 dbgprintf("SetCursor(0x%x) => 0x%x\n", cursor, cursor); | |
2078 return (int)cursor; | |
2079 } | |
2080 int WINAPI expGetSystemPaletteEntries(int hdc, int iStartIndex, int nEntries, void* lppe) | |
2081 { | |
2082 dbgprintf("GetSystemPaletteEntries(0x%x, 0x%x, 0x%x, 0x%x) => 0\n", | |
2083 hdc, iStartIndex, nEntries, lppe); | |
1 | 2084 return 0; |
2085 } | |
2086 | |
2087 /* | |
2088 typedef struct _TIME_ZONE_INFORMATION { | |
2089 long Bias; | |
2090 char StandardName[32]; | |
2091 SYSTEMTIME StandardDate; | |
2092 long StandardBias; | |
2093 char DaylightName[32]; | |
2094 SYSTEMTIME DaylightDate; | |
2095 long DaylightBias; | |
2096 } TIME_ZONE_INFORMATION, *LPTIME_ZONE_INFORMATION; | |
2097 */ | |
2098 | |
2099 int WINAPI expGetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation) | |
2100 { | |
128 | 2101 const short name[]={'C', 'e', 'n', 't', 'r', 'a', 'l', ' ', 'S', 't', 'a', |
2102 'n', 'd', 'a', 'r', 'd', ' ', 'T', 'i', 'm', 'e', 0}; | |
2103 const short pname[]={'C', 'e', 'n', 't', 'r', 'a', 'l', ' ', 'D', 'a', 'y', | |
2104 'l', 'i', 'g', 'h', 't', ' ', 'T', 'i', 'm', 'e', 0}; | |
2105 dbgprintf("GetTimeZoneInformation(0x%x) => TIME_ZONE_ID_STANDARD\n"); | |
1 | 2106 memset(lpTimeZoneInformation, 0, sizeof(TIME_ZONE_INFORMATION)); |
128 | 2107 lpTimeZoneInformation->Bias=360;//GMT-6 |
2108 memcpy(lpTimeZoneInformation->StandardName, name, sizeof(name)); | |
2109 lpTimeZoneInformation->StandardDate.wMonth=10; | |
2110 lpTimeZoneInformation->StandardDate.wDay=5; | |
2111 lpTimeZoneInformation->StandardDate.wHour=2; | |
2112 lpTimeZoneInformation->StandardBias=0; | |
2113 memcpy(lpTimeZoneInformation->DaylightName, pname, sizeof(pname)); | |
2114 lpTimeZoneInformation->DaylightDate.wMonth=4; | |
2115 lpTimeZoneInformation->DaylightDate.wDay=1; | |
2116 lpTimeZoneInformation->DaylightDate.wHour=2; | |
2117 lpTimeZoneInformation->DaylightBias=-60; | |
2118 return TIME_ZONE_ID_STANDARD; | |
1 | 2119 } |
2120 | |
2121 void WINAPI expGetLocalTime(SYSTEMTIME* systime) | |
2122 { | |
2123 time_t local_time; | |
2124 struct tm *local_tm; | |
2125 struct timeval tv; | |
2126 | |
128 | 2127 dbgprintf("GetLocalTime(0x%x)\n"); |
1 | 2128 gettimeofday(&tv, NULL); |
2129 local_time=tv.tv_sec; | |
2130 local_tm=localtime(&local_time); | |
2131 | |
2132 systime->wYear = local_tm->tm_year + 1900; | |
2133 systime->wMonth = local_tm->tm_mon + 1; | |
2134 systime->wDayOfWeek = local_tm->tm_wday; | |
2135 systime->wDay = local_tm->tm_mday; | |
2136 systime->wHour = local_tm->tm_hour; | |
2137 systime->wMinute = local_tm->tm_min; | |
2138 systime->wSecond = local_tm->tm_sec; | |
2139 systime->wMilliseconds = (tv.tv_usec / 1000) % 1000; | |
128 | 2140 dbgprintf(" Year: %d\n Month: %d\n Day of week: %d\n" |
2141 " Day: %d\n Hour: %d\n Minute: %d\n Second: %d\n" | |
2142 " Milliseconds: %d\n", | |
2143 systime->wYear, systime->wMonth, systime->wDayOfWeek, systime->wDay, | |
2144 systime->wHour, systime->wMinute, systime->wSecond, systime->wMilliseconds); | |
1 | 2145 } |
2146 | |
2147 int WINAPI expGetSystemTime(SYSTEMTIME* systime) | |
2148 { | |
2149 time_t local_time; | |
2150 struct tm *local_tm; | |
2151 struct timeval tv; | |
2152 | |
128 | 2153 dbgprintf("GetSystemTime(0x%x)\n", systime); |
1 | 2154 gettimeofday(&tv, NULL); |
2155 local_time=tv.tv_sec; | |
2156 local_tm=gmtime(&local_time); | |
2157 | |
2158 systime->wYear = local_tm->tm_year + 1900; | |
2159 systime->wMonth = local_tm->tm_mon + 1; | |
2160 systime->wDayOfWeek = local_tm->tm_wday; | |
2161 systime->wDay = local_tm->tm_mday; | |
2162 systime->wHour = local_tm->tm_hour; | |
2163 systime->wMinute = local_tm->tm_min; | |
2164 systime->wSecond = local_tm->tm_sec; | |
2165 systime->wMilliseconds = (tv.tv_usec / 1000) % 1000; | |
128 | 2166 dbgprintf(" Year: %d\n Month: %d\n Day of week: %d\n" |
2167 " Day: %d\n Hour: %d\n Minute: %d\n Second: %d\n" | |
2168 " Milliseconds: %d\n", | |
2169 systime->wYear, systime->wMonth, systime->wDayOfWeek, systime->wDay, | |
2170 systime->wHour, systime->wMinute, systime->wSecond, systime->wMilliseconds); | |
1 | 2171 } |
2172 | |
2173 int WINAPI expGetEnvironmentVariableA(const char* name, char* field, int size) | |
2174 { | |
128 | 2175 char *p; |
2176 // printf("%s %x %x\n", name, field, size); | |
1 | 2177 if(field)field[0]=0; |
128 | 2178 /* |
2179 p = getenv(name); | |
2180 if (p) strncpy(field,p,size); | |
2181 */ | |
2182 if (strcmp(name,"__MSVCRT_HEAP_SELECT")==0) | |
2183 strcpy(field,"__GLOBAL_HEAP_SELECTED,1"); | |
2184 dbgprintf("GetEnvironmentVariableA(0x%x='%s', 0x%x, %d) => %d\n", name, name, field, size, strlen(field)); | |
2185 return strlen(field); | |
2186 } | |
2187 | |
2188 void* WINAPI expCoTaskMemAlloc(ULONG cb) | |
2189 { | |
2190 return my_mreq(cb, 0); | |
2191 } | |
2192 void WINAPI expCoTaskMemFree(void* cb) | |
2193 { | |
2194 my_release(cb); | |
2195 } | |
2196 | |
2197 void* CoTaskMemAlloc(ULONG cb){return expCoTaskMemAlloc(cb);} | |
2198 void CoTaskMemFree(void* cb){expCoTaskMemFree(cb);} | |
2199 | |
2200 struct COM_OBJECT_INFO | |
2201 { | |
2202 GUID clsid; | |
2203 long (*GetClassObject) (GUID* clsid, GUID* iid, void** ppv); | |
2204 }; | |
2205 | |
2206 static struct COM_OBJECT_INFO* com_object_table=0; | |
2207 static int com_object_size=0; | |
2208 int RegisterComClass(GUID* clsid, GETCLASSOBJECT gcs) | |
2209 { | |
2210 if(!clsid)return -1; | |
2211 if(!gcs)return -1; | |
2212 com_object_table=realloc(com_object_table, sizeof(struct COM_OBJECT_INFO)*(++com_object_size)); | |
2213 com_object_table[com_object_size-1].clsid=*clsid; | |
2214 com_object_table[com_object_size-1].GetClassObject=gcs; | |
2215 return 0; | |
2216 } | |
2217 | |
2218 GUID IID_IUnknown={0x00000000, 0x0000, 0x0000, | |
2219 {0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}; | |
2220 GUID IID_IClassFactory={0x00000001, 0x0000, 0x0000, | |
2221 {0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}; | |
2222 | |
2223 long WINAPI expCoCreateInstance(GUID* rclsid, struct IUnknown* pUnkOuter, | |
2224 long dwClsContext, GUID* riid, void** ppv) | |
2225 { | |
2226 int i; | |
2227 struct COM_OBJECT_INFO* ci=0; | |
2228 for(i=0; i<com_object_size; i++) | |
2229 if(!memcmp(rclsid, &com_object_table[i].clsid, sizeof(GUID))) | |
2230 ci=&com_object_table[i]; | |
2231 if(!ci)return 0x80040154; | |
2232 // in 'real' world we should mess with IClassFactory here | |
2233 i=ci->GetClassObject(rclsid, riid, ppv); | |
2234 return i; | |
2235 } | |
2236 | |
2237 long CoCreateInstance(GUID* rclsid, struct IUnknown* pUnkOuter, | |
2238 long dwClsContext, GUID* riid, void** ppv) | |
2239 { | |
2240 return expCoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv); | |
2241 } | |
2242 | |
2243 int WINAPI | |
2244 expIsRectEmpty( | |
2245 CONST RECT *lprc) | |
2246 { | |
2247 dbgprintf("IsRectEmpty(0x%x)"); | |
2248 if((!lprc) || (lprc->right==lprc->left) || (lprc->top==lprc->bottom)) | |
2249 { | |
2250 dbgprintf(" => TRUE\n"); | |
2251 return TRUE; | |
2252 } | |
2253 dbgprintf(" => FALSE\n"); | |
2254 return FALSE; | |
2255 } | |
2256 | |
2257 int _adjust_fdiv=0; //what's this? | |
2258 | |
2259 | |
2260 | |
2261 | |
2262 unsigned int WINAPI expGetTempPathA(unsigned int len, char* path) | |
2263 { | |
2264 dbgprintf("GetTempPathA(%d, 0x%x)", len, path); | |
2265 if(len<5) | |
2266 { | |
2267 dbgprintf(" => 0\n"); | |
2268 return 0; | |
2269 } | |
2270 strcpy(path, "/tmp"); | |
2271 dbgprintf(" => 5 ( '/tmp' )\n"); | |
2272 return 5; | |
2273 } | |
2274 /* | |
2275 FYI: | |
2276 typedef struct | |
2277 { | |
2278 DWORD dwFileAttributes; | |
2279 FILETIME ftCreationTime; | |
2280 FILETIME ftLastAccessTime; | |
2281 FILETIME ftLastWriteTime; | |
2282 DWORD nFileSizeHigh; | |
2283 DWORD nFileSizeLow; | |
2284 DWORD dwReserved0; | |
2285 DWORD dwReserved1; | |
2286 CHAR cFileName[260]; | |
2287 CHAR cAlternateFileName[14]; | |
2288 } WIN32_FIND_DATAA, *LPWIN32_FIND_DATAA; | |
2289 */ | |
2290 | |
2291 HANDLE WINAPI expFindFirstFileA(LPCSTR s, LPWIN32_FIND_DATAA lpfd) | |
2292 { | |
2293 dbgprintf("FindFirstFileA(0x%x='%s', 0x%x) => 0\n", s, s, lpfd); | |
2294 strcpy(lpfd->cFileName, "msms001.vwp"); | |
2295 strcpy(lpfd->cAlternateFileName, "msms001.vwp"); | |
2296 return (HANDLE)0; | |
2297 } | |
2298 WIN_BOOL WINAPI expFindNextFileA(HANDLE h,LPWIN32_FIND_DATAA p) | |
2299 { | |
2300 dbgprintf("FindNextFileA(0x%x, 0x%x) => 0\n", h, p); | |
1 | 2301 return 0; |
2302 } | |
128 | 2303 WIN_BOOL WINAPI expFindClose(HANDLE h) |
2304 { | |
2305 dbgprintf("FindClose(0x%x) => 0\n", h); | |
2306 return 0; | |
2307 } | |
2308 UINT WINAPI expSetErrorMode(UINT i) | |
2309 { | |
2310 dbgprintf("SetErrorMode(%d) => 0\n", i); | |
2311 return 0; | |
2312 } | |
2313 UINT WINAPI expGetWindowsDirectoryA(LPSTR s,UINT c) | |
2314 { | |
2315 char windir[]="c:\\windows"; | |
2316 int result; | |
2317 strncpy(s, windir, c); | |
2318 result=1+((c<strlen(windir))?c:strlen(windir)); | |
2319 dbgprintf("GetWindowsDirectoryA(0x%x, %d) => %d\n", s, c, result); | |
2320 return result; | |
2321 } | |
2322 | |
2323 WIN_BOOL WINAPI expDeleteFileA(LPCSTR s) | |
2324 { | |
2325 dbgprintf("DeleteFileA(0x%x='%s') => 0\n", s, s); | |
2326 return 0; | |
2327 } | |
2328 WIN_BOOL WINAPI expFileTimeToLocalFileTime(const FILETIME* cpf, LPFILETIME pf) | |
2329 { | |
2330 dbgprintf("FileTimeToLocalFileTime(0x%x, 0x%x) => 0\n", cpf, pf); | |
2331 return 0; | |
2332 } | |
2333 | |
2334 UINT WINAPI expGetTempFileNameA(LPCSTR cs1,LPCSTR cs2,UINT i,LPSTR ps) | |
2335 { | |
2336 char mask[16]="/tmp/AP_XXXXXX"; | |
2337 int result; | |
2338 dbgprintf("GetTempFileNameA(0x%x='%s', 0x%x='%s', %d, 0x%x)", cs1, cs1, cs2, cs2, i, ps); | |
2339 if(i && i<10) | |
2340 { | |
2341 dbgprintf(" => -1\n"); | |
2342 return -1; | |
2343 } | |
2344 result=mkstemp(mask); | |
2345 sprintf(ps, "AP%d", result); | |
2346 dbgprintf(" => %d\n", strlen(ps)); | |
2347 return strlen(ps); | |
2348 } | |
2349 // | |
2350 // This func might need proper implementation if we want AngelPotion codec. | |
2351 // They try to open APmpeg4v1.apl with it. | |
2352 // DLL will close opened file with CloseHandle(). | |
2353 // | |
2354 HANDLE WINAPI expCreateFileA(LPCSTR cs1,DWORD i1,DWORD i2, | |
2355 LPSECURITY_ATTRIBUTES p1, DWORD i3,DWORD i4,HANDLE i5) | |
2356 { | |
2357 dbgprintf("CreateFileA(0x%x='%s', %d, %d, 0x%x, %d, %d, 0x%x)\n", cs1, cs1, i1, | |
2358 i2, p1, i3, i4, i5); | |
2359 if((!cs1) || (strlen(cs1)<2))return -1; | |
2360 if(strncmp(cs1, "AP", 2)) | |
2361 { | |
2362 int result; | |
2363 char* tmp=(char*)malloc(strlen(def_path)+50); | |
2364 strcpy(tmp, def_path); | |
2365 strcat(tmp, "/"); | |
2366 strcat(tmp, "APmpg4v1.apl"); | |
2367 result=open(tmp, O_RDONLY); | |
2368 free(tmp); | |
2369 return result; | |
2370 }; | |
2371 return atoi(cs1+2); | |
2372 } | |
2373 static char sysdir[]="."; | |
2374 LPCSTR WINAPI expGetSystemDirectoryA() | |
2375 { | |
2376 dbgprintf("GetSystemDirectoryA() => 0x%x='%s'\n", sysdir, sysdir); | |
2377 return sysdir; | |
2378 } | |
2379 WIN_BOOL WINAPI expReadFile(HANDLE h,LPVOID pv,DWORD size,LPDWORD rd,LPOVERLAPPED unused) | |
2380 { | |
2381 int result; | |
2382 dbgprintf("ReadFile(%d, 0x%x, %d -> 0x%x)\n", h, pv, size, rd); | |
2383 result=read(h, pv, size); | |
2384 if(rd)*rd=result; | |
2385 if(!result)return 0; | |
2386 return 1; | |
2387 } | |
2388 | |
2389 WIN_BOOL WINAPI expWriteFile(HANDLE h,LPCVOID pv,DWORD size,LPDWORD wr,LPOVERLAPPED unused) | |
2390 { | |
2391 int result; | |
2392 dbgprintf("WriteFile(%d, 0x%x, %d -> 0x%x)\n", h, pv, size, wr); | |
2393 if(h==1234)h=1; | |
2394 result=write(h, pv, size); | |
2395 if(wr)*wr=result; | |
2396 if(!result)return 0; | |
2397 return 1; | |
2398 } | |
2399 DWORD WINAPI expSetFilePointer(HANDLE h, LONG val, LPLONG ext, DWORD whence) | |
2400 { | |
2401 int wh; | |
2402 dbgprintf("SetFilePointer(%d, %d, 0x%x, %d)\n", h, val, ext, whence); | |
2403 //why would DLL want temporary file with >2Gb size? | |
2404 switch(whence) | |
2405 { | |
2406 case FILE_BEGIN: | |
2407 wh=SEEK_SET;break; | |
2408 case FILE_END: | |
2409 wh=SEEK_END;break; | |
2410 case FILE_CURRENT: | |
2411 wh=SEEK_CUR;break; | |
2412 default: | |
2413 return -1; | |
2414 } | |
2415 return lseek(h, val, wh); | |
2416 } | |
2417 | |
2418 HDRVR WINAPI expOpenDriverA(LPCSTR szDriverName, LPCSTR szSectionName, | |
2419 LPARAM lParam2) | |
2420 { | |
2421 dbgprintf("OpenDriverA(0x%x='%s', 0x%x='%s', 0x%x) => -1\n", szDriverName, szDriverName, szSectionName, szSectionName, lParam2); | |
2422 return -1; | |
2423 } | |
2424 HDRVR WINAPI expOpenDriver(LPCSTR szDriverName, LPCSTR szSectionName, | |
2425 LPARAM lParam2) | |
2426 { | |
2427 dbgprintf("OpenDriver(0x%x='%s', 0x%x='%s', 0x%x) => -1\n", szDriverName, szDriverName, szSectionName, szSectionName, lParam2); | |
2428 return -1; | |
2429 } | |
1 | 2430 |
2431 | |
128 | 2432 WIN_BOOL |
2433 WINAPI | |
2434 expGetProcessAffinityMask( | |
2435 HANDLE hProcess, | |
2436 LPDWORD lpProcessAffinityMask, | |
2437 LPDWORD lpSystemAffinityMask | |
2438 ) | |
2439 { | |
2440 dbgprintf("GetProcessAffinityMask(0x%x, 0x%x, 0x%x) => 1\n", | |
2441 hProcess, lpProcessAffinityMask, lpSystemAffinityMask); | |
2442 if(lpProcessAffinityMask)*lpProcessAffinityMask=1; | |
2443 if(lpSystemAffinityMask)*lpSystemAffinityMask=1; | |
2444 return 1; | |
1 | 2445 } |
2446 | |
2447 | |
295
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2448 /****************************************************************************** |
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2449 * RegEnumValueA [ADVAPI32.@] |
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2450 */ |
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2451 DWORD WINAPI expRegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count, |
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2452 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count ) |
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2453 { |
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2454 |
340 | 2455 // printf("RegEnumValueA(%x,%ld,%p,%p,%p,%p,%p,%p)\n", |
2456 // hkey, index, value, val_count, reserved, type, data, count ); | |
1416 | 2457 // return -1; |
128 | 2458 |
1416 | 2459 return RegEnumValueA(hkey, index, value, val_count, |
2460 reserved, type, data, count); | |
2461 | |
295
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2462 } |
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2463 |
128 | 2464 |
713 | 2465 #if 0 |
2466 INT WINAPI expMulDiv(int nNumber,int nNumerator,int nDenominator) | |
2467 { | |
2468 return ((long long)nNumber * (long long)nNumerator) / nDenominator; | |
2469 } | |
2470 #endif | |
2471 | |
2472 int WINAPI expMulDiv(int nNumber, int nNumerator, int nDenominator) | |
2473 { | |
2474 static const long long max_int=0x7FFFFFFFLL; | |
2475 static const long long min_int=-0x80000000LL; | |
2476 long long tmp=(long long)nNumber*(long long)nNumerator; | |
2477 if(!nDenominator)return 1; | |
2478 tmp/=nDenominator; | |
2479 if(tmp<min_int) return 1; | |
2480 if(tmp>max_int) return 1; | |
2481 return (int)tmp; | |
2482 } | |
2483 | |
2484 LONG WINAPI explstrcmpiA(const char* str1, const char* str2) | |
2485 { | |
2486 LONG result=strcasecmp(str1, str2); | |
2487 dbgprintf("strcmpi(0x%x='%s', 0x%x='%s') => %d\n", str1, str1, str2, str2, result); | |
2488 return result; | |
2489 } | |
2490 | |
2491 LONG WINAPI explstrlenA(const char* str1) | |
2492 { | |
2493 LONG result=strlen(str1); | |
2494 dbgprintf("strlen(0x%x='%s') => %d\n", str1, str1, result); | |
2495 return result; | |
2496 } | |
2497 | |
2498 LONG WINAPI explstrcpyA(char* str1, const char* str2) | |
2499 { | |
2500 int result= (int) strcpy(str1, str2); | |
2501 dbgprintf("strcpy(0x%x, 0x%x='%s') => %d\n", str1, str2, str2, result); | |
2502 return result; | |
2503 } | |
128 | 2504 |
497 | 2505 LONG WINAPI expInterlockedExchange(long *dest, long l) |
2506 { | |
2507 long retval; | |
2508 retval = *dest; | |
2509 *dest = l; | |
2510 return retval; | |
2511 } | |
2512 | |
1543 | 2513 int WINAPI expUnknownMFC42_1176() /* exact number of arguments unknown */ |
2514 { | |
2515 dbgprintf("MFC42:1176\n"); | |
2516 return 0; | |
2517 } | |
2518 | |
2519 int WINAPI expUnknownMFC42_1243() /* exact number of arguments unknown */ | |
2520 { | |
2521 dbgprintf("MFC42:1243\n"); | |
2522 return 0; | |
2523 } | |
2524 | |
2525 int UnregisterComClass(GUID* clsid, GETCLASSOBJECT gcs) | |
2526 { | |
2527 int found = 0; | |
2528 int i = 0; | |
2529 if(!clsid || !gcs) | |
2530 return -1; | |
2531 | |
2532 if (com_object_table == 0) | |
2533 printf("Warning: UnregisterComClass() called without any registered class\n"); | |
2534 while (i < com_object_size) | |
2535 { | |
2536 if (found && i > 0) | |
2537 { | |
2538 memcpy(&com_object_table[i - 1].clsid, | |
2539 &com_object_table[i].clsid, sizeof(GUID)); | |
2540 com_object_table[i - 1].GetClassObject = | |
2541 com_object_table[i].GetClassObject; | |
2542 } | |
2543 else if (memcmp(&com_object_table[i].clsid, clsid, sizeof(GUID)) == 0 | |
2544 && com_object_table[i].GetClassObject == gcs) | |
2545 { | |
2546 found++; | |
2547 } | |
2548 i++; | |
2549 } | |
2550 if (found) | |
2551 { | |
2552 if (--com_object_size == 0) | |
2553 { | |
2554 free(com_object_table); | |
2555 com_object_table = 0; | |
2556 } | |
2557 } | |
2558 return 0; | |
2559 } | |
2560 | |
2561 | |
2562 | |
2563 | |
1 | 2564 struct exports |
2565 { | |
2566 char name[64]; | |
2567 int id; | |
2568 void* func; | |
2569 }; | |
2570 struct libs | |
2571 { | |
2572 char name[64]; | |
2573 int length; | |
2574 struct exports* exps; | |
2575 }; | |
2576 | |
2577 #define FF(X,Y) \ | |
2578 {#X, Y, (void*)exp##X}, | |
2579 | |
2580 struct exports exp_kernel32[]={ | |
2581 FF(IsBadWritePtr, 357) | |
2582 FF(IsBadReadPtr, 354) | |
2583 FF(IsBadStringPtrW, -1) | |
713 | 2584 FF(IsBadStringPtrA, -1) |
1 | 2585 FF(DisableThreadLibraryCalls, -1) |
2586 FF(CreateThread, -1) | |
2587 FF(CreateEventA, -1) | |
2588 FF(SetEvent, -1) | |
2589 FF(ResetEvent, -1) | |
2590 FF(WaitForSingleObject, -1) | |
2591 FF(GetSystemInfo, -1) | |
2592 FF(GetVersion, 332) | |
2593 FF(HeapCreate, 461) | |
2594 FF(HeapAlloc, -1) | |
2595 FF(HeapDestroy, -1) | |
2596 FF(HeapFree, -1) | |
2597 FF(HeapSize, -1) | |
2598 FF(GetProcessHeap, -1) | |
2599 FF(VirtualAlloc, -1) | |
2600 FF(VirtualFree, -1) | |
2601 FF(InitializeCriticalSection, -1) | |
2602 FF(EnterCriticalSection, -1) | |
2603 FF(LeaveCriticalSection, -1) | |
2604 FF(DeleteCriticalSection, -1) | |
2605 FF(TlsAlloc, -1) | |
2606 FF(TlsFree, -1) | |
2607 FF(TlsGetValue, -1) | |
2608 FF(TlsSetValue, -1) | |
2609 FF(GetCurrentThreadId, -1) | |
128 | 2610 FF(GetCurrentProcess, -1) |
1 | 2611 FF(LocalAlloc, -1) |
2612 FF(LocalLock, -1) | |
2613 FF(GlobalAlloc, -1) | |
128 | 2614 FF(GlobalReAlloc, -1) |
1 | 2615 FF(GlobalLock, -1) |
2616 FF(MultiByteToWideChar, 427) | |
2617 FF(WideCharToMultiByte, -1) | |
2618 FF(GetVersionExA, -1) | |
2619 FF(CreateSemaphoreA, -1) | |
2620 FF(QueryPerformanceCounter, -1) | |
2621 FF(QueryPerformanceFrequency, -1) | |
2622 FF(LocalHandle, -1) | |
2623 FF(LocalUnlock, -1) | |
2624 FF(LocalFree, -1) | |
2625 FF(GlobalHandle, -1) | |
2626 FF(GlobalUnlock, -1) | |
2627 FF(GlobalFree, -1) | |
2628 FF(LoadResource, -1) | |
2629 FF(ReleaseSemaphore, -1) | |
2630 FF(FindResourceA, -1) | |
2631 FF(LockResource, -1) | |
2632 FF(FreeResource, -1) | |
2633 FF(SizeofResource, -1) | |
2634 FF(CloseHandle, -1) | |
2635 FF(GetCommandLineA, -1) | |
2636 FF(GetEnvironmentStringsW, -1) | |
2637 FF(FreeEnvironmentStringsW, -1) | |
128 | 2638 FF(FreeEnvironmentStringsA, -1) |
1 | 2639 FF(GetEnvironmentStrings, -1) |
2640 FF(GetStartupInfoA, -1) | |
2641 FF(GetStdHandle, -1) | |
2642 FF(GetFileType, -1) | |
2643 FF(SetHandleCount, -1) | |
2644 FF(GetACP, -1) | |
2645 FF(GetModuleFileNameA, -1) | |
2646 FF(SetUnhandledExceptionFilter, -1) | |
2647 FF(LoadLibraryA, -1) | |
2648 FF(GetProcAddress, -1) | |
2649 FF(FreeLibrary, -1) | |
2650 FF(CreateFileMappingA, -1) | |
2651 FF(OpenFileMappingA, -1) | |
2652 FF(MapViewOfFile, -1) | |
2653 FF(UnmapViewOfFile, -1) | |
2654 FF(Sleep, -1) | |
2655 FF(GetModuleHandleA, -1) | |
128 | 2656 FF(GetProfileIntA, -1) |
1 | 2657 FF(GetPrivateProfileIntA, -1) |
2658 FF(GetPrivateProfileStringA, -1) | |
2659 FF(WritePrivateProfileStringA, -1) | |
2660 FF(GetLastError, -1) | |
2661 FF(SetLastError, -1) | |
2662 FF(InterlockedIncrement, -1) | |
2663 FF(InterlockedDecrement, -1) | |
2664 FF(GetTimeZoneInformation, -1) | |
2665 FF(OutputDebugStringA, -1) | |
2666 FF(GetLocalTime, -1) | |
2667 FF(GetSystemTime, -1) | |
2668 FF(GetEnvironmentVariableA, -1) | |
121 | 2669 FF(RtlZeroMemory,-1) |
2670 FF(RtlMoveMemory,-1) | |
2671 FF(RtlFillMemory,-1) | |
128 | 2672 FF(GetTempPathA,-1) |
2673 FF(FindFirstFileA,-1) | |
2674 FF(FindNextFileA,-1) | |
2675 FF(FindClose,-1) | |
2676 FF(FileTimeToLocalFileTime,-1) | |
2677 FF(DeleteFileA,-1) | |
2678 FF(ReadFile,-1) | |
2679 FF(WriteFile,-1) | |
2680 FF(SetFilePointer,-1) | |
2681 FF(GetTempFileNameA,-1) | |
2682 FF(CreateFileA,-1) | |
2683 FF(GetSystemDirectoryA,-1) | |
2684 FF(GetWindowsDirectoryA,-1) | |
2685 FF(SetErrorMode, -1) | |
2686 FF(IsProcessorFeaturePresent, -1) | |
2687 FF(GetProcessAffinityMask, -1) | |
497 | 2688 FF(InterlockedExchange, -1) |
2689 FF(MulDiv, -1) | |
713 | 2690 FF(lstrcmpiA, -1) |
2691 FF(lstrlenA, -1) | |
2692 FF(lstrcpyA, -1) | |
1 | 2693 }; |
2694 | |
2695 struct exports exp_msvcrt[]={ | |
2696 FF(malloc, -1) | |
2697 FF(_initterm, -1) | |
2698 FF(free, -1) | |
2699 {"??3@YAXPAX@Z", -1, expdelete}, | |
2700 {"??2@YAPAXI@Z", -1, expnew}, | |
128 | 2701 {"_adjust_fdiv", -1, (void*)&_adjust_fdiv}, |
1 | 2702 FF(strrchr, -1) |
2703 FF(strchr, -1) | |
128 | 2704 FF(strlen, -1) |
2705 FF(strcpy, -1) | |
2706 FF(strcmp, -1) | |
2707 FF(strcat, -1) | |
713 | 2708 FF(isalnum, -1) |
128 | 2709 FF(memmove, -1) |
2710 FF(memcmp, -1) | |
2711 FF(time, -1) | |
1 | 2712 }; |
2713 struct exports exp_winmm[]={ | |
2714 FF(GetDriverModuleHandle, -1) | |
2715 FF(timeGetTime, -1) | |
2716 FF(DefDriverProc, -1) | |
128 | 2717 FF(OpenDriverA, -1) |
1 | 2718 FF(OpenDriver, -1) |
2719 }; | |
2720 struct exports exp_user32[]={ | |
2721 FF(LoadStringA, -1) | |
2722 FF(wsprintfA, -1) | |
2723 FF(GetDC, -1) | |
2724 FF(GetDesktopWindow, -1) | |
2725 FF(ReleaseDC, -1) | |
128 | 2726 FF(IsRectEmpty, -1) |
2727 FF(LoadCursorA,-1) | |
2728 FF(SetCursor,-1) | |
1 | 2729 }; |
2730 struct exports exp_advapi32[]={ | |
2731 FF(RegOpenKeyA, -1) | |
2732 FF(RegOpenKeyExA, -1) | |
2733 FF(RegCreateKeyExA, -1) | |
2734 FF(RegQueryValueExA, -1) | |
2735 FF(RegSetValueExA, -1) | |
2736 FF(RegCloseKey, -1) | |
295
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2737 //FF(RegEnumValueA, -1) |
1 | 2738 }; |
2739 struct exports exp_gdi32[]={ | |
2740 FF(CreateCompatibleDC, -1) | |
2741 FF(GetDeviceCaps, -1) | |
2742 FF(DeleteDC, -1) | |
2743 FF(GetSystemPaletteEntries, -1) | |
2744 }; | |
2745 struct exports exp_version[]={ | |
2746 FF(GetFileVersionInfoSizeA, -1) | |
2747 }; | |
128 | 2748 struct exports exp_ole32[]={ |
2749 FF(CoTaskMemAlloc, -1) | |
2750 FF(CoTaskMemFree, -1) | |
2751 FF(CoCreateInstance, -1) | |
2752 FF(StringFromGUID2, -1) | |
2753 }; | |
1543 | 2754 struct exports exp_mfc42[]={ |
2755 FF(UnknownMFC42_1176, 1176) | |
2756 FF(UnknownMFC42_1243, 1243) | |
2757 }; | |
130 | 2758 struct exports exp_crtdll[]={ |
2759 FF(memcpy, -1) | |
2760 }; | |
2761 | |
1 | 2762 #define LL(X) \ |
2763 {#X".dll", sizeof(exp_##X)/sizeof(struct exports), exp_##X}, | |
2764 | |
2765 struct libs libraries[]={ | |
2766 LL(kernel32) | |
2767 LL(msvcrt) | |
2768 LL(winmm) | |
2769 LL(user32) | |
2770 LL(advapi32) | |
2771 LL(gdi32) | |
2772 LL(version) | |
128 | 2773 LL(ole32) |
1543 | 2774 LL(mfc42) |
130 | 2775 LL(crtdll) |
1 | 2776 }; |
2777 | |
2778 void* LookupExternal(const char* library, int ordinal) | |
2779 { | |
2780 char* answ; | |
2781 int i,j; | |
2782 if(library==0) | |
2783 { | |
2784 printf("ERROR: library=0\n"); | |
2785 return (void*)ext_unknown; | |
2786 } | |
2787 printf("External func %s:%d\n", library, ordinal); | |
2788 // printf("%x %x\n", &unk_exp1, &unk_exp2); | |
2789 | |
2790 for(i=0; i<sizeof(libraries)/sizeof(struct libs); i++) | |
2791 { | |
2792 if(strcasecmp(library, libraries[i].name)) | |
2793 continue; | |
2794 for(j=0; j<libraries[i].length; j++) | |
2795 { | |
2796 if(ordinal!=libraries[i].exps[j].id) | |
2797 continue; | |
2798 printf("Hit: 0x%08X\n", libraries[i].exps[j].func); | |
2799 return libraries[i].exps[j].func; | |
2800 } | |
2801 } | |
2802 if(pos>150)return 0; | |
2803 answ=(char*)extcode+pos*0x64; | |
2804 memcpy(answ, &unk_exp1, 0x64); | |
2805 *(int*)(answ+9)=pos; | |
2806 *(int*)(answ+47)-=((int)answ-(int)&unk_exp1); | |
2807 sprintf(export_names[pos], "%s:%d", library, ordinal); | |
2808 pos++; | |
2809 return (void*)answ; | |
2810 } | |
2811 | |
2812 void* LookupExternalByName(const char* library, const char* name) | |
2813 { | |
2814 char* answ; | |
2815 int i,j; | |
2816 // return (void*)ext_unknown; | |
2817 if(library==0) | |
2818 { | |
2819 printf("ERROR: library=0\n"); | |
2820 return (void*)ext_unknown; | |
2821 } | |
2822 if(name==0) | |
2823 { | |
2824 printf("ERROR: name=0\n"); | |
2825 return (void*)ext_unknown; | |
2826 } | |
2827 // printf("External func %s:%s\n", library, name); | |
2828 for(i=0; i<sizeof(libraries)/sizeof(struct libs); i++) | |
2829 { | |
2830 if(strcasecmp(library, libraries[i].name)) | |
2831 continue; | |
2832 for(j=0; j<libraries[i].length; j++) | |
2833 { | |
2834 if(strcmp(name, libraries[i].exps[j].name)) | |
2835 continue; | |
2836 // printf("Hit: 0x%08X\n", libraries[i].exps[j].func); | |
2837 return libraries[i].exps[j].func; | |
2838 } | |
2839 } | |
128 | 2840 // printf("%s %s\n", library, name); |
2841 if(pos>150)return 0; | |
1 | 2842 strcpy(export_names[pos], name); |
2843 answ=(char*)extcode+pos*0x64; | |
2844 memcpy(answ, &unk_exp1, 0x64); | |
2845 *(int*)(answ+9)=pos; | |
2846 *(int*)(answ+47)-=((int)answ-(int)&unk_exp1); | |
2847 pos++; | |
2848 return (void*)answ; | |
2849 // memcpy(extcode, &unk_exp1, 0x64); | |
2850 // *(int*)(extcode+52)-=((int)extcode-(int)&unk_exp1); | |
2851 // return (void*)extcode; | |
2852 // printf("Unknown func %s:%s\n", library, name); | |
2853 // return (void*)ext_unknown; | |
2854 } | |
2855 | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1096
diff
changeset
|
2856 int my_garbagecollection(void) |
128 | 2857 { |
2858 #ifdef GARBAGE | |
2859 alc_list* pp,*ppsv; | |
2860 mutex_list* pm,*pmsv; | |
2861 int unfree,unfreecnt; | |
2862 if (mlist != NULL) { | |
2863 pm=mlist; | |
2864 for(;pm;) { | |
2865 if (pm->prev) pm->prev->next=pm->next; | |
2866 if (pm->next) pm->next->prev=pm->prev; | |
2867 if (pm == mlist) mlist=pm->prev; | |
2868 if (pm->pm) { | |
2869 pthread_mutex_destroy(pm->pm); | |
2870 my_release(pm->pm); | |
2871 } | |
2872 if (pm->pc) { | |
2873 pthread_cond_destroy(pm->pc); | |
2874 my_release(pm->pc); | |
2875 } | |
2876 pmsv = pm; | |
2877 pm=pm->prev; | |
2878 my_release(pmsv); | |
2879 } | |
2880 } | |
2881 | |
2882 if (alclist==NULL) return 0; | |
2883 | |
2884 pp=alclist; | |
2885 unfree=unfreecnt=0; | |
2886 for(;pp;) { | |
2887 unfree+=pp->size; | |
2888 unfreecnt++; | |
2889 if (pp->prev) | |
2890 pp->prev->next=pp->next; | |
2891 if (pp->next) | |
2892 pp->next->prev=pp->prev; | |
2893 if (pp == alclist) | |
2894 alclist=pp->prev; | |
2895 free(pp->addr); | |
2896 ppsv = pp; | |
2897 pp=pp->prev; | |
2898 free(ppsv); | |
2899 alccnt--; | |
2900 } | |
597 | 2901 printf("Total Unfree %d bytes cnt %d [%p,%d]\n",unfree,unfreecnt,alclist,alccnt); |
128 | 2902 #endif |
2903 } |