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