comparison loader/ext.c @ 2651:958d10763c34

partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
author arpi
date Sat, 03 Nov 2001 19:40:38 +0000
parents ce45cce7f7a5
children 181db9e5a887
comparison
equal deleted inserted replaced
2650:bf7248edcc20 2651:958d10763c34
1 /******************************************************** 1 /********************************************************
2 * 2 *
3 * 3 *
4 * Stub functions for Wine module 4 * Stub functions for Wine module
5 * 5 *
6 * 6 *
7 ********************************************************/ 7 ********************************************************/
21 #include <wine/winbase.h> 21 #include <wine/winbase.h>
22 #include <wine/debugtools.h> 22 #include <wine/debugtools.h>
23 #include <wine/heap.h> 23 #include <wine/heap.h>
24 #include "ext.h" 24 #include "ext.h"
25 25
26 #if 0
27 //REMOVE SIMPLIFY
28 static void* mymalloc(unsigned int size)
29 {
30 printf("malloc %d\n", size);
31 return malloc(size);
32 }
33
34 #undef malloc
35 #define malloc mymalloc
36 #endif
37
26 int dbg_header_err( const char *dbg_channel, const char *func ) 38 int dbg_header_err( const char *dbg_channel, const char *func )
27 { 39 {
28 return 0; 40 return 0;
29 } 41 }
30 int dbg_header_warn( const char *dbg_channel, const char *func ) 42 int dbg_header_warn( const char *dbg_channel, const char *func )
31 { 43 {
32 return 0; 44 return 0;
33 } 45 }
34 int dbg_header_fixme( const char *dbg_channel, const char *func ) 46 int dbg_header_fixme( const char *dbg_channel, const char *func )
35 { 47 {
36 return 0; 48 return 0;
37 } 49 }
38 int dbg_header_trace( const char *dbg_channel, const char *func ) 50 int dbg_header_trace( const char *dbg_channel, const char *func )
39 { 51 {
40 return 0; 52 return 0;
41 } 53 }
42 int dbg_vprintf( const char *format, va_list args ) 54 int dbg_vprintf( const char *format, va_list args )
43 { 55 {
44 return 0; 56 return 0;
45 } 57 }
46 int __vprintf( const char *format, ... ) 58 int __vprintf( const char *format, ... )
47 { 59 {
48 #ifdef DETAILED_OUT 60 #ifdef DETAILED_OUT
49 va_list va; 61 va_list va;
50 va_start(va, format); 62 va_start(va, format);
51 vprintf(format, va); 63 vprintf(format, va);
52 va_end(va); 64 va_end(va);
53 #endif 65 #endif
54 return 0; 66 return 0;
55 } 67 }
56 68
57 HANDLE WINAPI GetProcessHeap(void) 69 HANDLE WINAPI GetProcessHeap(void)
58 { 70 {
59 return 1; 71 return 1;
60 } 72 }
61 73
62 LPVOID WINAPI HeapAlloc(HANDLE heap, DWORD flags, DWORD size) 74 LPVOID WINAPI HeapAlloc(HANDLE heap, DWORD flags, DWORD size)
63 { 75 {
64 if(flags & 0x8) 76 static int i = 5;
65 return calloc(size, 1); 77 void* m = (flags & 0x8) ? calloc(size, 1) : malloc(size);
66 else 78 //printf("HeapAlloc %p %d (%d)\n", m, size, flags);
67 return malloc(size); 79 //if (--i == 0)
80 // abort();
81 return m;
68 } 82 }
69 83
70 WIN_BOOL WINAPI HeapFree(HANDLE heap, DWORD flags, LPVOID mem) 84 WIN_BOOL WINAPI HeapFree(HANDLE heap, DWORD flags, LPVOID mem)
71 { 85 {
72 if (mem) free(mem); 86 if (mem) free(mem);
87 //printf("HeapFree %p\n", mem);
88 //if (!mem)
89 // abort();
73 return 1; 90 return 1;
74 } 91 }
75 92
76 static int last_error; 93 static int last_error;
77 94
78 DWORD WINAPI GetLastError(void) 95 DWORD WINAPI GetLastError(void)
79 { 96 {
80 return last_error; 97 return last_error;
81 } 98 }
82 99
83 VOID WINAPI SetLastError(DWORD error) 100 VOID WINAPI SetLastError(DWORD error)
84 { 101 {
85 last_error=error; 102 last_error=error;
86 } 103 }
87 104
88 WIN_BOOL WINAPI ReadFile(HANDLE handle, LPVOID mem, DWORD size, LPDWORD result, LPOVERLAPPED flags) 105 WIN_BOOL WINAPI ReadFile(HANDLE handle, LPVOID mem, DWORD size, LPDWORD result, LPOVERLAPPED flags)
89 { 106 {
90 *result=read(handle, mem, size); 107 *result=read(handle, mem, size);
91 return *result; 108 return *result;
92 } 109 }
93 INT WINAPI lstrcmpiA(LPCSTR c1, LPCSTR c2) 110 INT WINAPI lstrcmpiA(LPCSTR c1, LPCSTR c2)
94 { 111 {
95 return strcasecmp(c1,c2); 112 return strcasecmp(c1,c2);
96 } 113 }
97 LPSTR WINAPI lstrcpynA(LPSTR dest, LPCSTR src, INT num) 114 LPSTR WINAPI lstrcpynA(LPSTR dest, LPCSTR src, INT num)
99 return strncpy(dest,src,num); 116 return strncpy(dest,src,num);
100 } 117 }
101 INT WINAPI lstrlenA(LPCSTR s) 118 INT WINAPI lstrlenA(LPCSTR s)
102 { 119 {
103 return strlen(s); 120 return strlen(s);
104 } 121 }
105 INT WINAPI lstrlenW(LPCWSTR s) 122 INT WINAPI lstrlenW(LPCWSTR s)
106 { 123 {
107 int l; 124 int l;
108 if(!s) 125 if(!s)
109 return 0; 126 return 0;
150 s1++; 167 s1++;
151 s2++; 168 s2++;
152 n--; 169 n--;
153 } 170 }
154 return 0; 171 return 0;
155 } 172 }
156 173
157
158 WIN_BOOL WINAPI IsBadReadPtr(LPCVOID data, UINT size) 174 WIN_BOOL WINAPI IsBadReadPtr(LPCVOID data, UINT size)
159 { 175 {
160 if(size==0) 176 if(size==0)
161 return 0; 177 return 0;
162 if(data==NULL) 178 if(data==NULL)
163 return 1; 179 return 1;
164 return 0; 180 return 0;
165 } 181 }
166 LPSTR HEAP_strdupA(HANDLE heap, DWORD flags, LPCSTR string) 182 LPSTR HEAP_strdupA(HANDLE heap, DWORD flags, LPCSTR string)
167 { 183 {
168 // return strdup(string); 184 // return strdup(string);
169 char* answ=malloc(strlen(string)+1); 185 char* answ=malloc(strlen(string)+1);
170 strcpy(answ, string); 186 strcpy(answ, string);
175 int size, i; 191 int size, i;
176 short* answer; 192 short* answer;
177 if(string==0) 193 if(string==0)
178 return 0; 194 return 0;
179 size=strlen(string); 195 size=strlen(string);
180 answer=malloc(size+size+2); 196 answer=malloc(2 * (size + 1));
181 for(i=0; i<=size; i++) 197 for(i=0; i<=size; i++)
182 answer[i]=(short)string[i]; 198 answer[i]=(short)string[i];
183 return answer; 199 return answer;
184 } 200 }
185 LPSTR HEAP_strdupWtoA(HANDLE heap, DWORD flags, LPCWSTR string) 201 LPSTR HEAP_strdupWtoA(HANDLE heap, DWORD flags, LPCWSTR string)
186 { 202 {
187 int size, i; 203 int size, i;
188 char* answer; 204 char* answer;
192 while(string[size]) 208 while(string[size])
193 size++; 209 size++;
194 answer=malloc(size+2); 210 answer=malloc(size+2);
195 for(i=0; i<=size; i++) 211 for(i=0; i<=size; i++)
196 answer[i]=(char)string[i]; 212 answer[i]=(char)string[i];
197 return answer; 213 return answer;
198 } 214 }
199 215
200 /*********************************************************************** 216 /***********************************************************************
201 * FILE_dommap 217 * FILE_dommap
202 */ 218 */
248 // flags, fd, offset_low )) != (LPVOID)-1) 264 // flags, fd, offset_low )) != (LPVOID)-1)
249 if ((ret = mmap( start, size_low, prot, 265 if ((ret = mmap( start, size_low, prot,
250 MAP_PRIVATE | MAP_FIXED, fd, offset_low )) != (LPVOID)-1) 266 MAP_PRIVATE | MAP_FIXED, fd, offset_low )) != (LPVOID)-1)
251 { 267 {
252 // printf("address %08x\n", *(int*)ret); 268 // printf("address %08x\n", *(int*)ret);
253 // printf("%x\n", ret); 269 // printf("%x\n", ret);
254 return ret; 270 return ret;
255 } 271 }
256 272
257 // printf("mmap %d\n", errno); 273 // printf("mmap %d\n", errno);
258 274
259 /* mmap() failed; if this is because the file offset is not */ 275 /* mmap() failed; if this is because the file offset is not */
260 /* page-aligned (EINVAL), or because the underlying filesystem */ 276 /* page-aligned (EINVAL), or because the underlying filesystem */
344 { 360 {
345 anon=1; 361 anon=1;
346 hFile=open("/dev/zero", O_RDWR); 362 hFile=open("/dev/zero", O_RDWR);
347 if(hFile<0) 363 if(hFile<0)
348 return 0; 364 return 0;
349 } 365 }
350 if(!anon) 366 if(!anon)
351 { 367 {
352 len=lseek(hFile, 0, SEEK_END); 368 len=lseek(hFile, 0, SEEK_END);
353 lseek(hFile, 0, SEEK_SET); 369 lseek(hFile, 0, SEEK_SET);
354 } 370 }
355 else len=dwMaxLow; 371 else len=dwMaxLow;
356 372
357 if(flProtect & PAGE_READONLY) 373 if(flProtect & PAGE_READONLY)
358 mmap_access |=PROT_READ; 374 mmap_access |=PROT_READ;
359 else 375 else
360 mmap_access |=PROT_READ|PROT_WRITE; 376 mmap_access |=PROT_READ|PROT_WRITE;
361 377
362 answer=mmap(NULL, len, mmap_access, MAP_PRIVATE, hFile, 0); 378 answer=mmap(NULL, len, mmap_access, MAP_PRIVATE, hFile, 0);
363 if(anon) 379 if(anon)
364 close(hFile); 380 close(hFile);
365 if(answer!=(LPVOID)-1) 381 if(answer!=(LPVOID)-1)
366 { 382 {
367 if(fm==0) 383 if(fm==0)
368 { 384 {
369 fm=malloc(sizeof(file_mapping)); 385 fm=malloc(sizeof(file_mapping));
370 fm->prev=NULL; 386 fm->prev=NULL;
371 } 387 }
372 else 388 else
373 { 389 {
374 fm->next=malloc(sizeof(file_mapping)); 390 fm->next=malloc(sizeof(file_mapping));
375 fm->next->prev=fm; 391 fm->next->prev=fm;
376 fm=fm->next; 392 fm=fm->next;
377 } 393 }
378 fm->next=NULL; 394 fm->next=NULL;
379 fm->handle=answer; 395 fm->handle=answer;
380 if(name) 396 if(name)
381 { 397 {
382 fm->name=malloc(strlen(name)+1); 398 fm->name=malloc(strlen(name)+1);
383 strcpy(fm->name, name); 399 strcpy(fm->name, name);
384 } 400 }
385 else 401 else
386 fm->name=NULL; 402 fm->name=NULL;
387 fm->mapping_size=len; 403 fm->mapping_size=len;
388 404
389 if(anon) 405 if(anon)
390 close(hFile); 406 close(hFile);
391 return (HANDLE)answer; 407 return (HANDLE)answer;
392 } 408 }
393 return (HANDLE)0; 409 return (HANDLE)0;
394 } 410 }
395 WIN_BOOL WINAPI UnmapViewOfFile(LPVOID handle) 411 WIN_BOOL WINAPI UnmapViewOfFile(LPVOID handle)
396 { 412 {
397 file_mapping* p; 413 file_mapping* p;
398 int result; 414 int result;
399 if(fm==0) 415 if(fm==0)
409 free(p->name); 425 free(p->name);
410 if(p==fm) 426 if(p==fm)
411 fm=p->prev; 427 fm=p->prev;
412 free(p); 428 free(p);
413 return result; 429 return result;
414 } 430 }
415 } 431 }
416 return 0; 432 return 0;
417 } 433 }
418 //static int va_size=0; 434 //static int va_size=0;
419 struct virt_alloc_s; 435 struct virt_alloc_s;
420 typedef struct virt_alloc_s 436 typedef struct virt_alloc_s
421 { 437 {
422 int mapping_size; 438 int mapping_size;
435 int fd=open("/dev/zero", O_RDWR); 451 int fd=open("/dev/zero", O_RDWR);
436 size=(size+0xffff)&(~0xffff); 452 size=(size+0xffff)&(~0xffff);
437 // printf("VirtualAlloc(0x%08X, %d)\n", address 453 // printf("VirtualAlloc(0x%08X, %d)\n", address
438 if(address!=0) 454 if(address!=0)
439 { 455 {
440 //check whether we can allow to allocate this 456 //check whether we can allow to allocate this
441 virt_alloc* str=vm; 457 virt_alloc* str=vm;
442 while(str) 458 while(str)
443 { 459 {
444 if((unsigned)address>=(unsigned)str->address+str->mapping_size) 460 if((unsigned)address>=(unsigned)str->address+str->mapping_size)
445 { 461 {
446 str=str->prev; 462 str=str->prev;
447 continue; 463 continue;
448 } 464 }
449 if((unsigned)address+size<(unsigned)str->address) 465 if((unsigned)address+size<(unsigned)str->address)
450 { 466 {
451 str=str->prev; 467 str=str->prev;
452 continue; 468 continue;
453 } 469 }
457 if(((unsigned)address+size<(unsigned)str->address+str->mapping_size) && (type & MEM_COMMIT)) 473 if(((unsigned)address+size<(unsigned)str->address+str->mapping_size) && (type & MEM_COMMIT))
458 { 474 {
459 close(fd); 475 close(fd);
460 return address; //returning previously reserved memory 476 return address; //returning previously reserved memory
461 } 477 }
462 return NULL; 478 return NULL;
463 } 479 }
464 close(fd); 480 close(fd);
465 return NULL; 481 return NULL;
466 } 482 }
467 answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC, 483 answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
468 MAP_FIXED | MAP_PRIVATE, fd, 0); 484 MAP_FIXED | MAP_PRIVATE, fd, 0);
469 } 485 }
470 else 486 else
471 answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC, 487 answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
472 MAP_PRIVATE, fd, 0); 488 MAP_PRIVATE, fd, 0);
473 // answer=FILE_dommap(-1, address, 0, size, 0, 0, 489 // answer=FILE_dommap(-1, address, 0, size, 0, 0,
474 // PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE); 490 // PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
475 close(fd); 491 close(fd);
476 if(answer==(void*)-1) 492 if(answer==(void*)-1)
492 if(vm) 508 if(vm)
493 vm->next=new_vm; 509 vm->next=new_vm;
494 vm=new_vm; 510 vm=new_vm;
495 vm->next=0; 511 vm->next=0;
496 // if(va_size!=0) 512 // if(va_size!=0)
497 // printf("Multiple VirtualAlloc!\n"); 513 // printf("Multiple VirtualAlloc!\n");
498 // printf("answer=0x%08x\n", answer); 514 // printf("answer=0x%08x\n", answer);
499 return answer; 515 return answer;
500 } 516 }
501 } 517 }
502 WIN_BOOL WINAPI VirtualFree(LPVOID address, DWORD t1, DWORD t2)//not sure 518 WIN_BOOL WINAPI VirtualFree(LPVOID address, DWORD t1, DWORD t2)//not sure
503 { 519 {
504 virt_alloc* str=vm; 520 virt_alloc* str=vm;
505 int answer; 521 int answer;
506 while(str) 522 while(str)
507 { 523 {
508 if(address!=str->address) 524 if(address!=str->address)
509 { 525 {
510 str=str->prev; 526 str=str->prev;
511 continue; 527 continue;
512 } 528 }
513 answer=munmap(str->address, str->mapping_size); 529 answer=munmap(str->address, str->mapping_size);
514 if(str->next)str->next->prev=str->prev; 530 if(str->next)str->next->prev=str->prev;
515 if(str->prev)str->prev->next=str->next; 531 if(str->prev)str->prev->next=str->next;
516 if(vm==str)vm=0; 532 if(vm==str)vm=0;
517 free(str); 533 free(str);
518 return 0; 534 return 0;
519 } 535 }
520 return -1; 536 return -1;
521 } 537 }
522 538
523 INT WINAPI WideCharToMultiByte(UINT codepage, DWORD flags, LPCWSTR src, 539 INT WINAPI WideCharToMultiByte(UINT codepage, DWORD flags, LPCWSTR src,
528 return 0; 544 return 0;
529 if ((srclen==-1)&&(dest==0)) return 0; 545 if ((srclen==-1)&&(dest==0)) return 0;
530 if(srclen==-1){srclen=0; while(src[srclen++]);} 546 if(srclen==-1){srclen=0; while(src[srclen++]);}
531 // for(i=0; i<srclen; i++) 547 // for(i=0; i<srclen; i++)
532 // printf("%c", src[i]); 548 // printf("%c", src[i]);
533 // printf("\n"); 549 // printf("\n");
534 if(dest==0) 550 if(dest==0)
535 { 551 {
536 for(i=0; i<srclen; i++) 552 for(i=0; i<srclen; i++)
537 { 553 {
538 src++; 554 src++;
539 if(*src==0) 555 if(*src==0)
540 return i+1; 556 return i+1;
541 } 557 }
542 return srclen+1; 558 return srclen+1;
543 } 559 }
544 if(used_defch) 560 if(used_defch)
545 *used_defch=0; 561 *used_defch=0;
546 for(i=0; i<min(srclen, destlen); i++) 562 for(i=0; i<min(srclen, destlen); i++)
547 { 563 {
548 *dest=(char)*src; 564 *dest=(char)*src;
549 dest++; 565 dest++;
550 src++; 566 src++;
551 if(*src==0) 567 if(*src==0)
552 return i+1; 568 return i+1;
553 } 569 }
554 return min(srclen, destlen); 570 return min(srclen, destlen);
555 } 571 }
556 INT WINAPI MultiByteToWideChar(UINT codepage,DWORD flags, LPCSTR src, INT srclen, 572 INT WINAPI MultiByteToWideChar(UINT codepage,DWORD flags, LPCSTR src, INT srclen,
557 LPWSTR dest, INT destlen) 573 LPWSTR dest, INT destlen)
558 { 574 {
570 if(p->name==0) 586 if(p->name==0)
571 continue; 587 continue;
572 if(strcmp(p->name, name)==0) 588 if(strcmp(p->name, name)==0)
573 return (HANDLE)p->handle; 589 return (HANDLE)p->handle;
574 } 590 }
575 return 0; 591 return 0;
576 } 592 }