diff options
-rw-r--r-- | loader/ext.c | 144 | ||||
-rw-r--r-- | loader/module.c | 50 | ||||
-rw-r--r-- | loader/pe_image.c | 17 | ||||
-rw-r--r-- | loader/win32.c | 779 | ||||
-rw-r--r-- | loader/win32.h | 15 |
5 files changed, 586 insertions, 419 deletions
diff --git a/loader/ext.c b/loader/ext.c index b6368f0dfd..d542ba687c 100644 --- a/loader/ext.c +++ b/loader/ext.c @@ -1,5 +1,5 @@ /******************************************************** - * + * * * Stub functions for Wine module * @@ -23,25 +23,37 @@ #include <wine/heap.h> #include "ext.h" +#if 0 +//REMOVE SIMPLIFY +static void* mymalloc(unsigned int size) +{ + printf("malloc %d\n", size); + return malloc(size); +} + +#undef malloc +#define malloc mymalloc +#endif + int dbg_header_err( const char *dbg_channel, const char *func ) { - return 0; + return 0; } int dbg_header_warn( const char *dbg_channel, const char *func ) { - return 0; + return 0; } int dbg_header_fixme( const char *dbg_channel, const char *func ) { - return 0; + return 0; } int dbg_header_trace( const char *dbg_channel, const char *func ) { - return 0; + return 0; } int dbg_vprintf( const char *format, va_list args ) { - return 0; + return 0; } int __vprintf( const char *format, ... ) { @@ -51,9 +63,9 @@ int __vprintf( const char *format, ... ) vprintf(format, va); va_end(va); #endif - return 0; + return 0; } - + HANDLE WINAPI GetProcessHeap(void) { return 1; @@ -61,17 +73,22 @@ HANDLE WINAPI GetProcessHeap(void) LPVOID WINAPI HeapAlloc(HANDLE heap, DWORD flags, DWORD size) { - if(flags & 0x8) - return calloc(size, 1); - else - return malloc(size); + static int i = 5; + void* m = (flags & 0x8) ? calloc(size, 1) : malloc(size); + //printf("HeapAlloc %p %d (%d)\n", m, size, flags); + //if (--i == 0) + // abort(); + return m; } WIN_BOOL WINAPI HeapFree(HANDLE heap, DWORD flags, LPVOID mem) { if (mem) free(mem); + //printf("HeapFree %p\n", mem); + //if (!mem) + // abort(); return 1; -} +} static int last_error; @@ -81,15 +98,15 @@ DWORD WINAPI GetLastError(void) } VOID WINAPI SetLastError(DWORD error) -{ +{ last_error=error; -} +} WIN_BOOL WINAPI ReadFile(HANDLE handle, LPVOID mem, DWORD size, LPDWORD result, LPOVERLAPPED flags) { *result=read(handle, mem, size); return *result; -} +} INT WINAPI lstrcmpiA(LPCSTR c1, LPCSTR c2) { return strcasecmp(c1,c2); @@ -101,7 +118,7 @@ LPSTR WINAPI lstrcpynA(LPSTR dest, LPCSTR src, INT num) INT WINAPI lstrlenA(LPCSTR s) { return strlen(s); -} +} INT WINAPI lstrlenW(LPCWSTR s) { int l; @@ -152,9 +169,8 @@ int wcsnicmp(const unsigned short* s1, const unsigned short* s2, int n) n--; } return 0; -} - - +} + WIN_BOOL WINAPI IsBadReadPtr(LPCVOID data, UINT size) { if(size==0) @@ -162,7 +178,7 @@ WIN_BOOL WINAPI IsBadReadPtr(LPCVOID data, UINT size) if(data==NULL) return 1; return 0; -} +} LPSTR HEAP_strdupA(HANDLE heap, DWORD flags, LPCSTR string) { // return strdup(string); @@ -177,10 +193,10 @@ LPWSTR HEAP_strdupAtoW(HANDLE heap, DWORD flags, LPCSTR string) if(string==0) return 0; size=strlen(string); - answer=malloc(size+size+2); + answer=malloc(2 * (size + 1)); for(i=0; i<=size; i++) answer[i]=(short)string[i]; - return answer; + return answer; } LPSTR HEAP_strdupWtoA(HANDLE heap, DWORD flags, LPCWSTR string) { @@ -194,7 +210,7 @@ LPSTR HEAP_strdupWtoA(HANDLE heap, DWORD flags, LPCWSTR string) answer=malloc(size+2); for(i=0; i<=size; i++) answer[i]=(char)string[i]; - return answer; + return answer; } /*********************************************************************** @@ -250,9 +266,9 @@ LPVOID FILE_dommap( int unix_handle, LPVOID start, MAP_PRIVATE | MAP_FIXED, fd, offset_low )) != (LPVOID)-1) { // printf("address %08x\n", *(int*)ret); -// printf("%x\n", ret); +// printf("%x\n", ret); return ret; - } + } // printf("mmap %d\n", errno); @@ -346,9 +362,9 @@ HANDLE WINAPI CreateFileMappingA(HANDLE handle, LPSECURITY_ATTRIBUTES lpAttr, hFile=open("/dev/zero", O_RDWR); if(hFile<0) return 0; - } + } if(!anon) - { + { len=lseek(hFile, 0, SEEK_END); lseek(hFile, 0, SEEK_SET); } @@ -358,8 +374,8 @@ HANDLE WINAPI CreateFileMappingA(HANDLE handle, LPSECURITY_ATTRIBUTES lpAttr, mmap_access |=PROT_READ; else mmap_access |=PROT_READ|PROT_WRITE; - - answer=mmap(NULL, len, mmap_access, MAP_PRIVATE, hFile, 0); + + answer=mmap(NULL, len, mmap_access, MAP_PRIVATE, hFile, 0); if(anon) close(hFile); if(answer!=(LPVOID)-1) @@ -368,30 +384,30 @@ HANDLE WINAPI CreateFileMappingA(HANDLE handle, LPSECURITY_ATTRIBUTES lpAttr, { fm=malloc(sizeof(file_mapping)); fm->prev=NULL; - } + } else { fm->next=malloc(sizeof(file_mapping)); fm->next->prev=fm; fm=fm->next; } - fm->next=NULL; + fm->next=NULL; fm->handle=answer; if(name) { fm->name=malloc(strlen(name)+1); strcpy(fm->name, name); - } + } else fm->name=NULL; fm->mapping_size=len; - + if(anon) close(hFile); return (HANDLE)answer; } return (HANDLE)0; -} +} WIN_BOOL WINAPI UnmapViewOfFile(LPVOID handle) { file_mapping* p; @@ -411,10 +427,10 @@ WIN_BOOL WINAPI UnmapViewOfFile(LPVOID handle) fm=p->prev; free(p); return result; - } + } } - return 0; -} + return 0; +} //static int va_size=0; struct virt_alloc_s; typedef struct virt_alloc_s @@ -437,7 +453,7 @@ LPVOID WINAPI VirtualAlloc(LPVOID address, DWORD size, DWORD type, DWORD protec // printf("VirtualAlloc(0x%08X, %d)\n", address if(address!=0) { - //check whether we can allow to allocate this + //check whether we can allow to allocate this virt_alloc* str=vm; while(str) { @@ -445,7 +461,7 @@ LPVOID WINAPI VirtualAlloc(LPVOID address, DWORD size, DWORD type, DWORD protec { str=str->prev; continue; - } + } if((unsigned)address+size<(unsigned)str->address) { str=str->prev; @@ -459,16 +475,16 @@ LPVOID WINAPI VirtualAlloc(LPVOID address, DWORD size, DWORD type, DWORD protec close(fd); return address; //returning previously reserved memory } - return NULL; + return NULL; } close(fd); return NULL; } - answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC, + answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FIXED | MAP_PRIVATE, fd, 0); - } + } else - answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC, + answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0); // answer=FILE_dommap(-1, address, 0, size, 0, 0, // PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE); @@ -494,28 +510,28 @@ LPVOID WINAPI VirtualAlloc(LPVOID address, DWORD size, DWORD type, DWORD protec vm=new_vm; vm->next=0; // if(va_size!=0) -// printf("Multiple VirtualAlloc!\n"); +// printf("Multiple VirtualAlloc!\n"); // printf("answer=0x%08x\n", answer); return answer; - } -} + } +} WIN_BOOL WINAPI VirtualFree(LPVOID address, DWORD t1, DWORD t2)//not sure { virt_alloc* str=vm; int answer; while(str) { - if(address!=str->address) - { - str=str->prev; - continue; - } - answer=munmap(str->address, str->mapping_size); - if(str->next)str->next->prev=str->prev; - if(str->prev)str->prev->next=str->next; - if(vm==str)vm=0; - free(str); - return 0; + if(address!=str->address) + { + str=str->prev; + continue; + } + answer=munmap(str->address, str->mapping_size); + if(str->next)str->next->prev=str->prev; + if(str->prev)str->prev->next=str->next; + if(vm==str)vm=0; + free(str); + return 0; } return -1; } @@ -530,7 +546,7 @@ INT WINAPI WideCharToMultiByte(UINT codepage, DWORD flags, LPCWSTR src, if(srclen==-1){srclen=0; while(src[srclen++]);} // for(i=0; i<srclen; i++) // printf("%c", src[i]); -// printf("\n"); +// printf("\n"); if(dest==0) { for(i=0; i<srclen; i++) @@ -539,10 +555,10 @@ INT WINAPI WideCharToMultiByte(UINT codepage, DWORD flags, LPCWSTR src, if(*src==0) return i+1; } - return srclen+1; - } + return srclen+1; + } if(used_defch) - *used_defch=0; + *used_defch=0; for(i=0; i<min(srclen, destlen); i++) { *dest=(char)*src; @@ -550,7 +566,7 @@ INT WINAPI WideCharToMultiByte(UINT codepage, DWORD flags, LPCWSTR src, src++; if(*src==0) return i+1; - } + } return min(srclen, destlen); } INT WINAPI MultiByteToWideChar(UINT codepage,DWORD flags, LPCSTR src, INT srclen, @@ -572,5 +588,5 @@ HANDLE WINAPI OpenFileMappingA(DWORD access, WIN_BOOL prot, LPCSTR name) if(strcmp(p->name, name)==0) return (HANDLE)p->handle; } - return 0; + return 0; } diff --git a/loader/module.c b/loader/module.c index c2c88bb74d..d53caed9af 100644 --- a/loader/module.c +++ b/loader/module.c @@ -52,6 +52,10 @@ struct modify_ldt_ldt_s { #include <wine/elfdll.h> #endif #include "win32.h" +//#include "driver.h" + +//#undef TRACE +//#define TRACE printf struct modref_list_t; @@ -60,13 +64,12 @@ typedef struct modref_list_t WINE_MODREF* wm; struct modref_list_t *next; struct modref_list_t *prev; -} -modref_list; +} modref_list; //WINE_MODREF *local_wm=NULL; modref_list* local_wm=NULL; -//HANDLE SegptrHeap; // unused? +HANDLE SegptrHeap; WINE_MODREF *MODULE_FindModule(LPCSTR m) { @@ -113,6 +116,7 @@ static void MODULE_RemoveFromList(WINE_MODREF *mod) return; } } + } WINE_MODREF *MODULE32_LookupHMODULE(HMODULE m) @@ -274,9 +278,17 @@ WIN_BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved ) */ void MODULE_DllProcessDetach( WINE_MODREF* wm, WIN_BOOL bForceDetach, LPVOID lpReserved ) { -// WINE_MODREF *wm=local_wm; + // WINE_MODREF *wm=local_wm; + modref_list* l = local_wm; wm->flags &= ~WINE_MODREF_PROCESS_ATTACHED; MODULE_InitDll( wm, DLL_PROCESS_DETACH, lpReserved ); +/* while (l) + { + modref_list* f = l; + l = l->next; + free(f); + } + local_wm = 0;*/ } @@ -298,11 +310,7 @@ HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags) SetLastError(ERROR_INVALID_PARAMETER); return 0; } - printf("Loading DLL: '%s'\n", libname); - -// if(fs_installed==0) -// install_fs(); while (wm == 0 && listpath[++i]) { @@ -310,7 +318,7 @@ HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags) { if (i == 0) /* check just original file name */ - strncpy(path, libname, 511); + strncpy(path, libname, 511); else /* check default user path */ strncpy(path, def_path, 300); @@ -539,3 +547,27 @@ FARPROC MODULE_GetProcAddress( } } +static int acounter = 0; +void CodecAlloc(void) +{ + acounter++; +} + +void CodecRelease(void) +{ + acounter--; + if (acounter == 0) + { + for (;;) + { + modref_list* list = local_wm; + if (!local_wm) + break; + //printf("CODECRELEASE %p\n", list); + MODULE_FreeLibrary(list->wm); + MODULE_RemoveFromList(list->wm); + if (local_wm == NULL) + my_garbagecollection(); + } + } +} diff --git a/loader/pe_image.c b/loader/pe_image.c index 498e4eeeee..30e7c34da2 100644 --- a/loader/pe_image.c +++ b/loader/pe_image.c @@ -303,13 +303,11 @@ static DWORD fixup_imports( WINE_MODREF *wm ) // TRACE("--- Ordinal %s,%d\n", name, ordinal); - thunk_list->u1.Function=LookupExternal( - name, ordinal); + thunk_list->u1.Function=LookupExternal(name, ordinal); } else { pe_name = (PIMAGE_IMPORT_BY_NAME)RVA(import_list->u1.AddressOfData); // TRACE("--- %s %s.%d\n", pe_name->Name, name, pe_name->Hint); - thunk_list->u1.Function=LookupExternalByName( - name, pe_name->Name); + thunk_list->u1.Function=LookupExternalByName(name, pe_name->Name); } import_list++; thunk_list++; @@ -335,8 +333,6 @@ static DWORD fixup_imports( WINE_MODREF *wm ) thunk_list++; } } - - } return 0; } @@ -857,6 +853,7 @@ WINE_MODREF *PE_LoadLibraryExA (LPCSTR name, DWORD flags) return NULL; } close(hFile); + //printf("^^^^^^^^^^^^^^^^Alloc VM1 %p\n", wm); return wm; } @@ -870,10 +867,14 @@ void PE_UnloadLibrary(WINE_MODREF *wm) { TRACE(" unloading %s\n", wm->filename); - HeapFree( GetProcessHeap(), 0, wm->filename ); - HeapFree( GetProcessHeap(), 0, wm->short_filename ); + if (wm->filename) + free(wm->filename); + if (wm->short_filename) + free(wm->short_filename); + HeapFree( GetProcessHeap(), 0, wm->deps ); VirtualFree( (LPVOID)wm->module, 0, MEM_RELEASE ); HeapFree( GetProcessHeap(), 0, wm ); + //printf("^^^^^^^^^^^^^^^^Free VM1 %p\n", wm); } /***************************************************************************** diff --git a/loader/win32.c b/loader/win32.c index cb91218e0c..a8b8a441eb 100644 --- a/loader/win32.c +++ b/loader/win32.c @@ -2,10 +2,10 @@ Win32 emulation code. Functions that emulate responses from corresponding Win32 API calls. - Since we are not going to be able to load + Since we are not going to be able to load virtually any DLL, we can only implement this much, adding needed functions with each new codec. - + Basic principle of implementation: it's not good for DLL to know too much about its environment. @@ -28,6 +28,7 @@ #include "com.h" #include <stdlib.h> +#include <assert.h> #include <stdarg.h> #include <ctype.h> #include <pthread.h> @@ -36,6 +37,7 @@ #include <malloc.h> #endif #include <time.h> +#include <math.h> #include <unistd.h> #include <fcntl.h> #include <sys/types.h> @@ -45,8 +47,9 @@ #include <kstat.h> #endif +int vsscanf( const char *str, const char *format, va_list ap); -char* def_path=WIN32_PATH; +char* def_path = WIN32_PATH; static void do_cpuid(unsigned int ax, unsigned int *regs) { @@ -81,7 +84,7 @@ static void c_longcount_tsc(long long* z) "movl %%edx, 4(%%ebx)\n\t" "popl %%ebx\n\t" ::"a"(z)); -} +} static unsigned int c_localcount_notsc() { struct timeval tv; @@ -108,16 +111,18 @@ static void longcount_stub(long long*); static unsigned int (*localcount)()=localcount_stub; static void (*longcount)(long long*)=longcount_stub; +static pthread_mutex_t memmut; + static unsigned int localcount_stub(void) { unsigned int regs[4]; do_cpuid(1, regs); - if ((regs[3] & 0x00000010) != 0) + if ((regs[3] & 0x00000010) != 0) { localcount=c_localcount_tsc; longcount=c_longcount_tsc; - } - else + } + else { localcount=c_localcount_notsc; longcount=c_longcount_notsc; @@ -128,12 +133,12 @@ static void longcount_stub(long long* z) { unsigned int regs[4]; do_cpuid(1, regs); - if ((regs[3] & 0x00000010) != 0) + if ((regs[3] & 0x00000010) != 0) { localcount=c_localcount_tsc; longcount=c_longcount_tsc; - } - else + } + else { localcount=c_localcount_notsc; longcount=c_longcount_notsc; @@ -161,7 +166,7 @@ static inline void dbgprintf(char* fmt, ...) va_end(va); } #endif -} +} char export_names[500][30]={ "name1", //"name2", @@ -169,11 +174,13 @@ char export_names[500][30]={ }; //#define min(x,y) ((x)<(y)?(x):(y)) -static unsigned char* heap=NULL; +void destroy_event(void* event); + +static unsigned char* heap=NULL; static int heap_counter=0; static void test_heap(void) { - int offset=0; + int offset=0; if(heap==0) return; while(offset<heap_counter) @@ -189,7 +196,7 @@ static void test_heap(void) if(heap[offset]!=0xCC) { printf("Free heap corruption at address %d\n", offset); - } + } } #undef MEMORY_DEBUG @@ -210,23 +217,23 @@ void* my_mreq(int size, int to_zero) { printf("No enough memory\n"); return 0; - } + } if(heap_counter+size>20000000) { printf("No enough memory\n"); return 0; - } + } *(int*)(heap+heap_counter)=0x433476; heap_counter+=4; *(int*)(heap+heap_counter)=size; heap_counter+=4; printf("Allocated %d bytes of memory: sys %d, user %d-%d\n", size, heap_counter-8, heap_counter, heap_counter+size); if(to_zero) - memset(heap+heap_counter, 0, size); + memset(heap+heap_counter, 0, size); else memset(heap+heap_counter, 0xcc, size); // make crash reproducable heap_counter+=size; - return heap+heap_counter-size; + return heap+heap_counter-size; } int my_release(char* memory) { @@ -235,7 +242,7 @@ int my_release(char* memory) { printf("ERROR: free(0)\n"); return 0; - } + } if(*(int*)(memory-8)!=0x433476) { printf("MEMORY CORRUPTION !!!!!!!!!!!!!!!!!!!\n"); @@ -244,109 +251,150 @@ int my_release(char* memory) printf("Freed %d bytes of memory\n", *(int*)(memory-4)); // memset(memory-8, *(int*)(memory-4), 0xCC); return 0; -} +} #else #define GARBAGE +typedef struct alloc_header_t alloc_header; +struct alloc_header_t +{ +// let's keep allocated data 16 byte aligned + alloc_header* prev; + alloc_header* next; + long deadbeef; + long size; + long type; + long reserved1; + long reserved2; + long reserved3; +}; + #ifdef GARBAGE -struct alc_list_t; -typedef struct alc_list_t { - int size; - void *addr; - struct alc_list_t *prev; - struct alc_list_t *next; -}alc_list; -static alc_list *alclist=NULL; -static int alccnt=0; +static alloc_header* last_alloc = NULL; +static int alccnt = 0; #endif -void* my_mreq(int size, int to_zero) +#define AREATYPE_CLIENT 0 +#define AREATYPE_EVENT 1 +#define AREATYPE_MUTEX 2 +#define AREATYPE_COND 3 + +void* mreq_private(int size, int to_zero, int type); +void* mreq_private(int size, int to_zero, int type) { - void* answer; - if(to_zero) - answer=calloc(size+4, 1); + alloc_header* header; + if (to_zero) + header=calloc(size + sizeof(alloc_header), 1); else - answer=malloc(size+4); - *(int*)answer=size; + header=malloc(size + sizeof(alloc_header)); #ifdef GARBAGE - if (alclist==NULL) { - alclist=malloc(sizeof(alc_list)); - alclist->prev=alclist->next=NULL; + if (!last_alloc) + { + pthread_mutex_init(&memmut, NULL); + pthread_mutex_lock(&memmut); } - else { - alclist->next=malloc(sizeof(alc_list)); - alclist->next->prev=alclist; - alclist->next->next=NULL; - alclist=alclist->next; + else + { + pthread_mutex_lock(&memmut); + last_alloc->next = header; /* set next */ } - alclist->size=size; - alclist->addr=answer; + + header->prev = last_alloc; + header->next = 0; + last_alloc = header; alccnt++; + pthread_mutex_unlock(&memmut); #endif - return (int*)((int)answer+sizeof(int)); -} + header->deadbeef = 0xdeadbeef; + header->size = size; + header->type = type; + + //if (alccnt < 400) printf("MY_REQ: %p\t%d (%d)\n", answer, size, alccnt); + return header + 1; +} + +void* my_mreq(int size, int to_zero) +{ + return mreq_private(size, to_zero, AREATYPE_CLIENT); +} + + int my_release(void* memory) { + alloc_header* header = (alloc_header*) memory - 1; #ifdef GARBAGE - alc_list* pp; - if(memory==0)return 0; - if(alclist!=NULL) + alloc_header* prevmem; + alloc_header* nextmem; + if (memory == 0) + return 0; + + pthread_mutex_lock(&memmut); + + if (header->deadbeef != 0xdeadbeef) { - pp=alclist; - if ((pp->prev==NULL) && (pp->next == NULL)){ - free(pp); - alclist=NULL; - } - else { - for(;pp;pp=pp->prev) { - if (pp->addr == (char*)memory-4) { - if (pp->prev) - pp->prev->next=pp->next; - if (pp->next) - pp->next->prev=pp->prev; - if (pp == alclist) - alclist=pp->prev; - free(pp); - alccnt--; - break; - } - } - if (pp == NULL) { - printf("Not Found %p %d\n",(char*)memory-4,alccnt); - return 0; - } - } + printf("FATAL releasing corrupted memory!\n"); + return 0; } + + switch(header->type) + { + case AREATYPE_EVENT: + destroy_event(memory); + break; + case AREATYPE_COND: + pthread_cond_destroy((pthread_cond_t*)memory); + break; + case AREATYPE_MUTEX: + pthread_mutex_destroy((pthread_mutex_t*)memory); + break; + } + + prevmem = header->prev; + nextmem = header->next; + + if (prevmem) + prevmem->next = nextmem; + if (nextmem) + nextmem->prev = prevmem; + + if (header == last_alloc) + last_alloc = prevmem; + + alccnt--; + + if (last_alloc) + pthread_mutex_unlock(&memmut); + else + pthread_mutex_destroy(&memmut); + + //if (alccnt < 400) printf("MY_RELEASE: %p\t%ld (%d)\n", mem, mem[3], alccnt); +#else + if (memory == 0) + return 0; #endif - free((char*)memory-4); + free(header); return 0; } #endif -int my_size(void* memory) + +static inline int my_size(void* memory) { - return *(int*)((char*)memory-4); -} -void* my_realloc(void* memory,int size) + return ((alloc_header*)memory)[-1].size; +} + +void* my_realloc(void* memory, int size) { - void *ans; -#ifdef GARBAGE - alc_list* pp; - if(memory == NULL)return 0; - pp=alclist; - if(pp == NULL) return 0; - ans=NULL; - for(;pp;pp=pp->prev) { - if (pp->addr == (char*)memory-4) { - ans = realloc(memory-4,size+4); - if (ans == 0) return 0; - pp->size = size; - pp->addr = ans; + void *ans = memory; + int osize = my_size(memory); + if (memory == NULL) + return my_mreq(size, 0); + if (osize < size) + { + ans = my_mreq(size, 0); + memcpy(ans, memory, osize); + my_release(memory); } - } -#else - ans = realloc(memory-4,size+4); -#endif - return ans; + return ans; } extern int unk_exp1; @@ -357,7 +405,7 @@ int WINAPI ext_unknown() { printf("Unknown func called\n"); return 0; -} +} int WINAPI expIsBadWritePtr(void* ptr, unsigned int count) { int result; @@ -405,14 +453,17 @@ void* CDECL expnew(int size) // printf("NEW:: Call from address %08x\n STACK DUMP:\n", *(-1+(int*)&size)); // printf("%08x %08x %08x %08x\n", // size, *(1+(int*)&size), -// *(2+(int*)&size),*(3+(int*)&size)); - void* result=my_mreq(size,0); + // *(2+(int*)&size),*(3+(int*)&size)); + void* result = 0; + assert(size >= 0); + + result=my_mreq(size,0); dbgprintf("new(0x%x) => 0x%x\n", size, result); - if(result==0) + if (result==0) printf("WARNING: new() failed\n"); return result; -} +} int CDECL expdelete(void* memory) { dbgprintf("delete(0x%x)\n", memory); @@ -423,17 +474,17 @@ int WINAPI expDisableThreadLibraryCalls(int module) { dbgprintf("DisableThreadLibraryCalls(0x%x) => 0\n", module); return 0; -} +} int CDECL exp_initterm(int v1, int v2) { dbgprintf("_initterm(0x%x, 0x%x) => 0\n", v1, v2); return 0; -} +} HMODULE WINAPI expGetDriverModuleHandle(DRVR* pdrv) { HMODULE result; - if (pdrv==NULL) + if (pdrv==NULL) result=0; else result=pdrv->hDriverModule; @@ -460,7 +511,7 @@ HMODULE WINAPI expGetModuleHandleA(const char* name) { if(strcasecmp(name, "kernel32")==0) result=MODULE_HANDLE_kernel32; - } + } dbgprintf("GetModuleHandleA('%s') => 0x%x\n", name, result); return result; } @@ -499,7 +550,7 @@ void* WINAPI expCreateThread(void* pSecAttr, long dwStackSize, void* lpStartAddr list->next->prev=list; list->next->next=NULL; list=list->next; - } + } list->thread=pth; dbgprintf("CreateThread(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x) => 0x%x\n", pSecAttr, dwStackSize, lpStartAddress, lpParameter, dwFlags, dwThreadId, pth); @@ -515,18 +566,58 @@ struct mutex_list_t pthread_cond_t *pc; char state; char reset; - char name[64]; + char name[128]; int semaphore; struct mutex_list_t* next; struct mutex_list_t* prev; }; typedef struct mutex_list_t mutex_list; -static mutex_list* mlist=NULL; -void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset, +static mutex_list* mlist=NULL; + +void destroy_event(void* event) +{ + mutex_list* pp=mlist; +// printf("garbage collector: destroy_event(%x)\n", event); + while(pp) + { + if(pp==(mutex_list*)event) + { + if(pp->next) + pp->next->prev=pp->prev; + if(pp->prev) + pp->prev->next=pp->next; + if(mlist==(mutex_list*)event) + mlist=mlist->prev; +/* + pp=mlist; + while(pp) + { + printf("%x => ", pp); + pp=pp->prev; + } + printf("0\n"); +*/ + return; + } + pp=pp->prev; + } +} + +void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset, char bInitialState, const char* name) { pthread_mutex_t *pm; pthread_cond_t *pc; +/* + mutex_list* pp; + pp=mlist; + while(pp) + { + printf("%x => ", pp); + pp=pp->prev; + } + printf("0\n"); +*/ if(mlist!=NULL) { mutex_list* pp=mlist; @@ -540,19 +631,19 @@ void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset, return pp->pm; } }while((pp=pp->prev) != NULL); - } - pm=my_mreq(sizeof(pthread_mutex_t), 0); + } + pm=mreq_private(sizeof(pthread_mutex_t), 0, AREATYPE_MUTEX); pthread_mutex_init(pm, NULL); - pc=my_mreq(sizeof(pthread_cond_t), 0); + pc=mreq_private(sizeof(pthread_cond_t), 0, AREATYPE_COND); pthread_cond_init(pc, NULL); if(mlist==NULL) { - mlist=my_mreq(sizeof(mutex_list), 00); + mlist=mreq_private(sizeof(mutex_list), 00, AREATYPE_EVENT); mlist->next=mlist->prev=NULL; } else { - mlist->next=my_mreq(sizeof(mutex_list), 00); + mlist->next=mreq_private(sizeof(mutex_list), 00, AREATYPE_EVENT); mlist->next->prev=mlist; mlist->next->next=NULL; mlist=mlist->next; @@ -562,9 +653,9 @@ void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset, mlist->pc=pc; mlist->state=bInitialState; mlist->reset=bManualReset; - if(name!=NULL) - strncpy(mlist->name, name, 64); - else + if(name) + strncpy(mlist->name, name, 127); + else mlist->name[0]=0; if(pm==NULL) dbgprintf("ERROR::: CreateEventA failure\n"); @@ -579,7 +670,7 @@ void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset, dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, NULL) => 0x%x\n", pSecAttr, bManualReset, bInitialState, mlist); return mlist; -} +} void* WINAPI expSetEvent(void* event) { @@ -600,7 +691,7 @@ void* WINAPI expResetEvent(void* event) dbgprintf("ResetEvent(0x%x) => 0x1\n", event); pthread_mutex_lock(ml->pm); ml->state = 0; - pthread_mutex_unlock(ml->pm); + pthread_mutex_unlock(ml->pm); return (void *)1; } @@ -650,7 +741,7 @@ void* WINAPI expWaitForSingleObject(void* object, int duration) if (ret == ETIMEDOUT) ret = WAIT_TIMEOUT; else ret = WAIT_OBJECT_0; if (ml->reset) - ml->state = 0; + ml->state = 0; } break; case 1: /* Semaphore */ @@ -672,7 +763,7 @@ void* WINAPI expWaitForSingleObject(void* object, int duration) dbgprintf("WaitForSingleObject(0x%x, %d): 0x%x => 0x%x \n",object,duration,ml,ret); return (void *)ret; -} +} static BYTE PF[64] = {0,}; @@ -820,7 +911,7 @@ void WINAPI expGetSystemInfo(SYSTEM_INFO* si) } /* old 2.0 method */ if (!lstrncmpiA(line, "cpu",strlen("cpu"))) { - if ( isdigit (value[0]) && value[1] == '8' && + if ( isdigit (value[0]) && value[1] == '8' && value[2] == '6' && value[3] == 0 ) { switch (value[0] - '0') { @@ -876,8 +967,8 @@ void WINAPI expGetSystemInfo(SYSTEM_INFO* si) if (sscanf(value,"%d",&x)) cachedsi.wProcessorRevision = x; } - if - ( (!lstrncmpiA(line,"flags",strlen("flags"))) + if + ( (!lstrncmpiA(line,"flags",strlen("flags"))) || (!lstrncmpiA(line,"features",strlen("features"))) ) { if (strstr(value,"cx8")) @@ -911,7 +1002,7 @@ long WINAPI expGetVersion() { dbgprintf("GetVersion() => 0xC0000004\n"); return 0xC0000004;//Windows 95 -} +} HANDLE WINAPI expHeapCreate(long flags, long init_size, long max_size) { @@ -921,9 +1012,9 @@ HANDLE WINAPI expHeapCreate(long flags, long init_size, long max_size) result=(HANDLE)my_mreq(0x110000, 0); else result=(HANDLE)my_mreq(init_size, 0); - dbgprintf("HeapCreate(flags 0x%x, initial size %d, maximum size %d) => 0x%x\n", flags, init_size, max_size, result); + dbgprintf("HeapCreate(flags 0x%x, initial size %d, maximum size %d) => 0x%x\n", flags, init_size, max_size, result); return result; -} +} void* WINAPI expHeapAlloc(HANDLE heap, int flags, int size) { void* z; @@ -932,16 +1023,16 @@ void* WINAPI expHeapAlloc(HANDLE heap, int flags, int size) Morgan's m3jpeg32.dll v. 2.0 encoder expects that request for HeapAlloc returns area larger than size argument :-/ **/ - z=my_mreq(((size+4095)/4096)*4096, flags&8); + z=my_mreq(((size+4095)/4096)*4096, flags&8); // z=HeapAlloc(heap,flags,size); if(z==0) printf("HeapAlloc failure\n"); - dbgprintf("HeapAlloc(heap 0x%x, flags 0x%x, size 0x%x) => 0x%x\n", heap, flags, size, z); + dbgprintf("HeapAlloc(heap 0x%x, flags 0x%x, size 0x%x) => 0x%x\n", heap, flags, size, z); return z; } long WINAPI expHeapDestroy(void* heap) { - dbgprintf("HeapDestroy(heap 0x%x) => 1\n", heap); + dbgprintf("HeapDestroy(heap 0x%x) => 1\n", heap); my_release(heap); return 1; } @@ -951,32 +1042,26 @@ long WINAPI expHeapFree(int arg1, int arg2, void* ptr) dbgprintf("HeapFree(0x%x, 0x%x, pointer 0x%x) => 1\n", arg1 |