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