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