comparison loader/win32.c @ 128:28091b3caff9

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