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