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