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