diff options
author | arpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2001-12-11 22:58:14 +0000 |
---|---|---|
committer | arpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2001-12-11 22:58:14 +0000 |
commit | b4caa850133c79a384c470e5575c6159a689d610 (patch) | |
tree | 894e4a9d2b8aa8c77c212661f5aedb450b03c6e0 | |
parent | d80b170960adeff96ca05397329ee9ca9528c014 (diff) | |
download | mpv-b4caa850133c79a384c470e5575c6159a689d610.tar.bz2 mpv-b4caa850133c79a384c470e5575c6159a689d610.tar.xz |
avifile merge. kabi: indent changes really suxxxx
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@3466 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r-- | loader/Makefile | 2 | ||||
-rw-r--r-- | loader/driver.c | 2 | ||||
-rw-r--r-- | loader/ext.c | 28 | ||||
-rw-r--r-- | loader/module.c | 178 | ||||
-rw-r--r-- | loader/registry.c | 52 | ||||
-rw-r--r-- | loader/registry.h | 5 | ||||
-rw-r--r-- | loader/win32.c | 2903 | ||||
-rw-r--r-- | loader/win32.h | 232 | ||||
-rw-r--r-- | loader/wine/module.h | 59 |
9 files changed, 1706 insertions, 1755 deletions
diff --git a/loader/Makefile b/loader/Makefile index 446c895f20..2b3d31015d 100644 --- a/loader/Makefile +++ b/loader/Makefile @@ -1,7 +1,7 @@ include ../config.mak # Generated automatically from Makefile.in by configure. -DEFINES=$(WIN32_PATH) -D__WINE__ -Ddbg_printf=__vprintf \ +DEFINES=$(WIN32_PATH) -DMPLAYER -D__WINE__ -Ddbg_printf=__vprintf \ -DTRACE=__vprintf # -DDETAILED_OUT LIB_OBJECTS= ldt_keeper.o pe_image.o module.o \ diff --git a/loader/driver.c b/loader/driver.c index f8de9c61ec..09dc49f8dc 100644 --- a/loader/driver.c +++ b/loader/driver.c @@ -136,7 +136,7 @@ DrvOpen(LPARAM lParam2) if (!(npDriver = DrvAlloc(&hDriver, &uDrvResult))) return ((HDRVR) 0); - if (!(npDriver->hDriverModule = expLoadLibraryA(win32_codec_name))) { + if (!(npDriver->hDriverModule = LoadLibraryA(win32_codec_name))) { printf("Can't open library %s\n", win32_codec_name); DrvFree(hDriver); return ((HDRVR) 0); diff --git a/loader/ext.c b/loader/ext.c index ff69e0818f..0b747b7f0c 100644 --- a/loader/ext.c +++ b/loader/ext.c @@ -5,7 +5,7 @@ * * ********************************************************/ -#include <config.h> +#include "config.h" #include <stdio.h> #include <stdlib.h> #ifdef HAVE_MALLOC_H @@ -17,6 +17,7 @@ #include <fcntl.h> #include <string.h> #include <stdarg.h> +#include <ctype.h> #include <wine/windef.h> #include <wine/winbase.h> #include <wine/debugtools.h> @@ -146,6 +147,7 @@ LPSTR WINAPI lstrcpynWtoA(LPSTR dest, LPCWSTR src, INT count) } return result; } +/* i stands here for ignore case! */ int wcsnicmp(const unsigned short* s1, const unsigned short* s2, int n) { /* @@ -156,17 +158,21 @@ int wcsnicmp(const unsigned short* s1, const unsigned short* s2, int n) */ while(n>0) { - if(*s1<*s2) - return -1; - else - if(*s1>*s2) - return 1; + if (((*s1 | *s2) & 0xff00) || toupper((char)*s1) != toupper((char)*s2)) + { + + if(*s1<*s2) + return -1; else - if(*s1==0) - return 0; - s1++; - s2++; - n--; + if(*s1>*s2) + return 1; + else + if(*s1==0) + return 0; + } + s1++; + s2++; + n--; } return 0; } diff --git a/loader/module.c b/loader/module.c index d53caed9af..2e38b66ea0 100644 --- a/loader/module.c +++ b/loader/module.c @@ -3,7 +3,7 @@ * * Copyright 1995 Alexandre Julliard */ -#include <config.h> +#include "config.h" #include <assert.h> #include <errno.h> @@ -14,33 +14,8 @@ #include <unistd.h> #include <sys/mman.h> #include <sys/types.h> -/* -#ifdef __linux__ -#include <asm/unistd.h> -#include <asm/ldt.h> -#else -#define LDT_ENTRIES 8192 -#define LDT_ENTRY_SIZE 8 - -struct modify_ldt_ldt_s { - unsigned int entry_number; - unsigned long base_addr; - unsigned int limit; - unsigned int seg_32bit:1; - unsigned int contents:2; - unsigned int read_exec_only:1; - unsigned int limit_in_pages:1; - unsigned int seg_not_present:1; - unsigned int useable:1; -}; - -#define MODIFY_LDT_CONTENTS_DATA 0 -#define MODIFY_LDT_CONTENTS_STACK 1 -#define MODIFY_LDT_CONTENTS_CODE 2 -#define __NR_modify_ldt 123 -#endif -*/ + #include <wine/windef.h> #include <wine/winerror.h> #include <wine/heap.h> @@ -71,7 +46,7 @@ modref_list* local_wm=NULL; HANDLE SegptrHeap; -WINE_MODREF *MODULE_FindModule(LPCSTR m) +WINE_MODREF* MODULE_FindModule(LPCSTR m) { modref_list* list=local_wm; TRACE("Module %s request\n", m); @@ -215,7 +190,7 @@ static WIN_BOOL MODULE_InitDll( WINE_MODREF *wm, DWORD type, LPVOID lpReserved ) * NOTE: Assumes that the process critical section is held! * */ -WIN_BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved ) +static WIN_BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved ) { WIN_BOOL retv = TRUE; int i; @@ -276,7 +251,7 @@ WIN_BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved ) * sequence at MODULE_DllProcessAttach. Unless the bForceDetach flag * is set, only DLLs with zero refcount are notified. */ -void MODULE_DllProcessDetach( WINE_MODREF* wm, WIN_BOOL bForceDetach, LPVOID lpReserved ) +static void MODULE_DllProcessDetach( WINE_MODREF* wm, WIN_BOOL bForceDetach, LPVOID lpReserved ) { // WINE_MODREF *wm=local_wm; modref_list* l = local_wm; @@ -291,6 +266,74 @@ void MODULE_DllProcessDetach( WINE_MODREF* wm, WIN_BOOL bForceDetach, LPVOID lpR local_wm = 0;*/ } +/*********************************************************************** + * MODULE_LoadLibraryExA (internal) + * + * Load a PE style module according to the load order. + * + * The HFILE parameter is not used and marked reserved in the SDK. I can + * only guess that it should force a file to be mapped, but I rather + * ignore the parameter because it would be extremely difficult to + * integrate this with different types of module represenations. + * + */ +static WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags ) +{ + DWORD err = GetLastError(); + WINE_MODREF *pwm; + int i; +// module_loadorder_t *plo; + + SetLastError( ERROR_FILE_NOT_FOUND ); + TRACE("Trying native dll '%s'\n", libname); + pwm = PE_LoadLibraryExA(libname, flags); +#ifdef HAVE_LIBDL + if(!pwm) + { + TRACE("Trying ELF dll '%s'\n", libname); + pwm=(WINE_MODREF*)ELFDLL_LoadLibraryExA(libname, flags); + } +#endif +// printf("0x%08x\n", pwm); +// break; + if(pwm) + { + /* Initialize DLL just loaded */ + TRACE("Loaded module '%s' at 0x%08x, \n", libname, pwm->module); + /* Set the refCount here so that an attach failure will */ + /* decrement the dependencies through the MODULE_FreeLibrary call. */ + pwm->refCount++; + + SetLastError( err ); /* restore last error */ + return pwm; + } + + + WARN("Failed to load module '%s'; error=0x%08lx, \n", libname, GetLastError()); + return NULL; +} + +/*********************************************************************** + * MODULE_FreeLibrary + * + * NOTE: Assumes that the process critical section is held! + */ +static WIN_BOOL MODULE_FreeLibrary( WINE_MODREF *wm ) +{ + TRACE("(%s) - START\n", wm->modname ); + + /* Recursively decrement reference counts */ + //MODULE_DecRefCount( wm ); + + /* Call process detach notifications */ + MODULE_DllProcessDetach( wm, FALSE, NULL ); + + PE_UnloadLibrary(wm); + + TRACE("END\n"); + + return TRUE; +} /*********************************************************************** * LoadLibraryExA (KERNEL32) @@ -311,6 +354,8 @@ HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags) return 0; } printf("Loading DLL: '%s'\n", libname); +// if(fs_installed==0) +// install_fs(); while (wm == 0 && listpath[++i]) { @@ -367,60 +412,12 @@ HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags) /*********************************************************************** - * MODULE_LoadLibraryExA (internal) - * - * Load a PE style module according to the load order. - * - * The HFILE parameter is not used and marked reserved in the SDK. I can - * only guess that it should force a file to be mapped, but I rather - * ignore the parameter because it would be extremely difficult to - * integrate this with different types of module represenations. - * - */ -WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags ) -{ - DWORD err = GetLastError(); - WINE_MODREF *pwm; - int i; -// module_loadorder_t *plo; - - SetLastError( ERROR_FILE_NOT_FOUND ); - TRACE("Trying native dll '%s'\n", libname); - pwm = PE_LoadLibraryExA(libname, flags); -#ifdef HAVE_LIBDL - if(!pwm) - { - TRACE("Trying ELF dll '%s'\n", libname); - pwm=(WINE_MODREF*)ELFDLL_LoadLibraryExA(libname, flags); - } -#endif -// printf("0x%08x\n", pwm); -// break; - if(pwm) - { - /* Initialize DLL just loaded */ - TRACE("Loaded module '%s' at 0x%08x, \n", libname, pwm->module); - /* Set the refCount here so that an attach failure will */ - /* decrement the dependencies through the MODULE_FreeLibrary call. */ - pwm->refCount++; - - SetLastError( err ); /* restore last error */ - return pwm; - } - - - WARN("Failed to load module '%s'; error=0x%08lx, \n", libname, GetLastError()); - return NULL; -} - -/*********************************************************************** * LoadLibraryA (KERNEL32) */ HMODULE WINAPI LoadLibraryA(LPCSTR libname) { return LoadLibraryExA(libname,0,0); } - /*********************************************************************** * FreeLibrary */ @@ -430,7 +427,6 @@ WIN_BOOL WINAPI FreeLibrary(HINSTANCE hLibModule) WINE_MODREF *wm; wm=MODULE32_LookupHMODULE(hLibModule); -// wm=local_wm; if ( !wm || !hLibModule ) { @@ -479,28 +475,6 @@ static void MODULE_DecRefCount( WINE_MODREF *wm ) } /*********************************************************************** - * MODULE_FreeLibrary - * - * NOTE: Assumes that the process critical section is held! - */ -WIN_BOOL MODULE_FreeLibrary( WINE_MODREF *wm ) -{ - TRACE("(%s) - START\n", wm->modname ); - - /* Recursively decrement reference counts */ - //MODULE_DecRefCount( wm ); - - /* Call process detach notifications */ - MODULE_DllProcessDetach( wm, FALSE, NULL ); - - PE_UnloadLibrary(wm); - - TRACE("END\n"); - - return TRUE; -} - -/*********************************************************************** * GetProcAddress (KERNEL32.257) */ FARPROC WINAPI GetProcAddress( HMODULE hModule, LPCSTR function ) @@ -551,11 +525,13 @@ static int acounter = 0; void CodecAlloc(void) { acounter++; + //printf("**************CODEC ALLOC %d\n", acounter); } void CodecRelease(void) { acounter--; + //printf("**************CODEC RELEASE %d\n", acounter); if (acounter == 0) { for (;;) diff --git a/loader/registry.c b/loader/registry.c index 217448e162..26fd768177 100644 --- a/loader/registry.c +++ b/loader/registry.c @@ -1,4 +1,4 @@ -#include <config.h> +#include "config.h" #include <stdio.h> #include <stdlib.h> @@ -12,8 +12,8 @@ #include <wine/winnt.h> #include <wine/winerror.h> -#include <ext.h> -#include <registry.h> +#include "ext.h" +#include "registry.h" //#undef TRACE //#define TRACE printf @@ -168,11 +168,10 @@ void free_registry(void) free(regs); regs = 0; } - if (localregpathname) - { + + if (localregpathname && localregpathname != regpathname) free(localregpathname); - localregpathname = 0; - } + localregpathname = 0; } @@ -298,16 +297,21 @@ static void init_registry(void) // can't be free-ed - it's static and probably thread // unsafe structure which is stored in glibc -#ifdef USE_WIN32DLL - // MPlayer: - localregpathname = get_path("registry"); +#ifdef MPLAYER + regpathname = get_path("registry"); + localregpathname = regpathname; #else - // avifile: + // regpathname is an external pointer + // + // registry.c is holding it's own internal pointer + // localregpathname - which is being allocate/deallocated + if (localregpathname == 0) { const char* pthn = regpathname; if (!regpathname) { + // avifile - for now reading data from user's home struct passwd* pwent; pwent = getpwuid(geteuid()); pthn = pwent->pw_dir; @@ -402,16 +406,9 @@ long RegQueryValueExA(long key, const char* value, int* reserved, int* type, int char* c; TRACE("Querying value %s\n", value); if(!regs) - init_registry() -; + init_registry(); + c=build_keyname(key, value); - if (strcmp(value, "AudioReserved001")==0) - { - printf("Query for AudioReserved001 %p %p count: %d\n", type, data, *count); - *(int*)type = REG_DWORD; - *(int*)data = 256; - return 0; - } if(c==NULL) return 1; t=find_value_by_name(c); @@ -446,8 +443,8 @@ long RegCreateKeyExA(long key, const char* name, long reserved, // TRACE("Creating/Opening key %s\n", name); TRACE("Creating/Opening key %s\n", name); if(!regs) - init_registry() -; + init_registry(); + fullname=build_keyname(key, name); if(fullname==NULL) return 1; @@ -509,8 +506,8 @@ long RegSetValueExA(long key, const char* name, long v1, long v2, const void* da char* c; TRACE("Request to set value %s\n", name); if(!regs) - init_registry() -; + init_registry(); + c=build_keyname(key, name); if(c==NULL) return 1; @@ -518,3 +515,10 @@ long RegSetValueExA(long key, const char* name, long v1, long v2, const void* da free(c); return 0; } + +long RegEnumKeyExA(HKEY hKey, DWORD dwIndex, LPSTR lpName, LPDWORD lpcbName, + LPDWORD lpReserved, LPSTR lpClass, LPDWORD lpcbClass, + LPFILETIME lpftLastWriteTime) +{ + return ERROR_NO_MORE_ITEMS; +} diff --git a/loader/registry.h b/loader/registry.h index bb204932ff..45a6be692d 100644 --- a/loader/registry.h +++ b/loader/registry.h @@ -24,7 +24,12 @@ long RegCreateKeyExA(long key, const char* name, long reserved, void* sec_attr, int* newkey, int* status); long RegSetValueExA(long key, const char* name, long v1, long v2, const void* data, long size); + #ifdef __WINE_WINERROR_H + +long RegEnumKeyExA(HKEY hKey, DWORD dwIndex, LPSTR lpName, LPDWORD lpcbName, + LPDWORD lpReserved, LPSTR lpClass, LPDWORD lpcbClass, + LPFILETIME lpftLastWriteTime); long RegEnumValueA(HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count, LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count); #endif diff --git a/loader/win32.c b/loader/win32.c index de455eecb8..780a5d86a2 100644 --- a/loader/win32.c +++ b/loader/win32.c @@ -1,13 +1,13 @@ /*********************************************************** - Win32 emulation code. Functions that emulate - responses from corresponding Win32 API calls. - 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. +Win32 emulation code. Functions that emulate +responses from corresponding Win32 API calls. +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. +Basic principle of implementation: it's not good +for DLL to know too much about its environment. ************************************************************/ @@ -53,12 +53,12 @@ int vsscanf( const char *str, const char *format, va_list ap); /* system has no vsscanf. try to provide one */ static int vsscanf( const char *str, const char *format, va_list ap) { - long p1 = va_arg(ap, long); - long p2 = va_arg(ap, long); - long p3 = va_arg(ap, long); - long p4 = va_arg(ap, long); - long p5 = va_arg(ap, long); - return sscanf(str, format, p1, p2, p3, p4, p5); + long p1 = va_arg(ap, long); + long p2 = va_arg(ap, long); + long p3 = va_arg(ap, long); + long p4 = va_arg(ap, long); + long p5 = va_arg(ap, long); + return sscanf(str, format, p1, p2, p3, p4, p5); } #endif @@ -66,37 +66,43 @@ char* def_path = WIN32_PATH; static void do_cpuid(unsigned int ax, unsigned int *regs) { - __asm__ __volatile__( - "pushl %%ebx; pushl %%ecx; pushl %%edx;" - ".byte 0x0f, 0xa2;" - "movl %%eax, (%2);" - "movl %%ebx, 4(%2);" - "movl %%ecx, 8(%2);" - "movl %%edx, 12(%2);" - "popl %%edx; popl %%ecx; popl %%ebx;" - : "=a" (ax) - : "0" (ax), "S" (regs) + __asm__ __volatile__ + ( + "pushl %%ebx; pushl %%ecx; pushl %%edx;" + ".byte 0x0f, 0xa2;" + "movl %%eax, (%2);" + "movl %%ebx, 4(%2);" + "movl %%ecx, 8(%2);" + "movl %%edx, 12(%2);" + "popl %%edx; popl %%ecx; popl %%ebx;" + : "=a" (ax) + : "0" (ax), "S" (regs) ); } static unsigned int c_localcount_tsc() { int a; - __asm__ __volatile__("rdtsc\n\t" - :"=a"(a) - : - :"edx"); + __asm__ __volatile__ + ( + "rdtsc\n\t" + :"=a"(a) + : + :"edx" + ); return a; } static void c_longcount_tsc(long long* z) { - __asm__ __volatile__( - "pushl %%ebx\n\t" - "movl %%eax, %%ebx\n\t" - "rdtsc\n\t" - "movl %%eax, 0(%%ebx)\n\t" - "movl %%edx, 4(%%ebx)\n\t" - "popl %%ebx\n\t" - ::"a"(z)); + __asm__ __volatile__ + ( + "pushl %%ebx\n\t" + "movl %%eax, %%ebx\n\t" + "rdtsc\n\t" + "movl %%eax, 0(%%ebx)\n\t" + "movl %%edx, 4(%%ebx)\n\t" + "popl %%ebx\n\t" + ::"a"(z) + ); } static unsigned int c_localcount_notsc() { @@ -137,7 +143,7 @@ static unsigned int localcount_stub(void) } else { - localcount=c_localcount_notsc; + localcount=c_localcount_notsc; longcount=c_longcount_notsc; } return localcount(); @@ -153,7 +159,7 @@ static void longcount_stub(long long* z) } else { - localcount=c_localcount_notsc; + localcount=c_localcount_notsc; longcount=c_longcount_notsc; } longcount(z); @@ -168,19 +174,20 @@ static inline void dbgprintf(char* fmt, ...) { FILE* f; va_list va; - va_start(va, fmt); + va_start(va, fmt); f=fopen("./log", "a"); vprintf(fmt, va); - if(f) + fflush(stdout); + if(f) { vfprintf(f, fmt, va); fsync(fileno(f)); - fclose(f); + fclose(f); } va_end(va); } #endif -#ifdef USE_WIN32DLL +#ifdef MPLAYER #include "../mp_msg.h" { char buf[1024]; @@ -195,10 +202,10 @@ static inline void dbgprintf(char* fmt, ...) } -char export_names[500][30]={ -"name1", -//"name2", -//"name3" +char export_names[300][32]={ + "name1", + //"name2", + //"name3" }; //#define min(x,y) ((x)<(y)?(x):(y)) @@ -235,8 +242,8 @@ static void test_heap(void) } for(;offset<min(offset+1000, 20000000); offset++) if(heap[offset]!=0xCC) - { - printf("Free heap corruption at address %d\n", offset); + { + printf("Free heap corruption at address %d\n", offset); } } #undef MEMORY_DEBUG @@ -248,7 +255,7 @@ void* my_mreq(int size, int to_zero) static int test=0; test++; if(test%10==0)printf("Memory: %d bytes allocated\n", heap_counter); -// test_heap(); + // test_heap(); if(heap==NULL) { heap=malloc(20000000); @@ -270,7 +277,7 @@ void* my_mreq(int size, int to_zero) 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; @@ -278,7 +285,7 @@ void* my_mreq(int size, int to_zero) } int my_release(char* memory) { -// test_heap(); + // test_heap(); if(memory==NULL) { printf("ERROR: free(0)\n"); @@ -290,7 +297,7 @@ int my_release(char* memory) return 0; } printf("Freed %d bytes of memory\n", *(int*)(memory-4)); -// memset(memory-8, *(int*)(memory-4), 0xCC); + // memset(memory-8, *(int*)(memory-4), 0xCC); return 0; } @@ -299,7 +306,7 @@ int my_release(char* memory) typedef struct alloc_header_t alloc_header; struct alloc_header_t { -// let's keep allocated data 16 byte aligned + // let's keep allocated data 16 byte aligned alloc_header* prev; alloc_header* next; long deadbeef; @@ -332,11 +339,12 @@ struct CRITSECT void* mreq_private(int size, int to_zero, int type); void* mreq_private(int size, int to_zero, int type) { - alloc_header* header; + int nsize = size + sizeof(alloc_header); + alloc_header* header = malloc(nsize); + if (!header) + return 0; if (to_zero) - header=calloc(size + sizeof(alloc_header), 1); - else - header=malloc(size + sizeof(alloc_header)); + memset(header, 0, nsize); #ifdef GARBAGE if (!last_alloc) { @@ -345,7 +353,7 @@ void* mreq_private(int size, int to_zero, int type) } else { - pthread_mutex_lock(&memmut); + pthread_mutex_lock(&memmut); last_alloc->next = header; /* set next */ } @@ -363,12 +371,6 @@ void* mreq_private(int size, int to_zero, int type) 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; @@ -405,6 +407,7 @@ int my_release(void* memory) //memset(memory, 0xcc, header->size); } + header->deadbeef = 0; prevmem = header->prev; nextmem = header->next; @@ -422,23 +425,29 @@ int my_release(void* memory) pthread_mutex_unlock(&memmut); else pthread_mutex_destroy(&memmut); - + //if (alccnt < 40000) printf("MY_RELEASE: %p\t%ld (%d)\n", header, header->size, alccnt); #else if (memory == 0) return 0; #endif + //memset(header + 1, 0xcc, header->size); free(header); return 0; } #endif +inline void* my_mreq(int size, int to_zero) +{ + return mreq_private(size, to_zero, AREATYPE_CLIENT); +} + static inline int my_size(void* memory) { return ((alloc_header*)memory)[-1].size; } -void* my_realloc(void* memory, int size) +static void* my_realloc(void* memory, int size) { void *ans = memory; int osize = my_size(memory); @@ -453,131 +462,78 @@ void* my_realloc(void* memory, int size) return ans; } -extern int unk_exp1; -char extcode[20000];// place for 200 unresolved exports -int pos=0; +/* + * + * WINE API - native implementation for several win32 libraries + * + */ -int WINAPI ext_unknown() +static int WINAPI ext_unknown() { printf("Unknown func called\n"); return 0; } -int WINAPI expIsBadWritePtr(void* ptr, unsigned int count) + +static int WINAPI expIsBadWritePtr(void* ptr, unsigned int count) { - int result; - if(count==0) - result=0; - else - if(ptr==0) - result=1; - else - result=0; + int result = (count == 0 || ptr != 0) ? 0 : 1; dbgprintf("IsBadWritePtr(0x%x, 0x%x) => %d\n", ptr, count, result); return result; } -int WINAPI expIsBadReadPtr(void* ptr, unsigned int count) +static int WINAPI expIsBadReadPtr(void* ptr, unsigned int count) { - int result; - if(count==0) - result=0; - else - if(ptr==0) - result=1; - else - result=0; + int result = (count == 0 || ptr != 0) ? 0 : 1; dbgprintf("IsBadReadPtr(0x%x, 0x%x) => %d\n", ptr, count, result); return result; } -void* CDECL expmalloc(int size) -{ -//printf("malloc"); -// return malloc(size); - void* result=my_mreq(size,0); - dbgprintf("malloc(0x%x) => 0x%x\n", size,result); - if(result==0) - printf("WARNING: malloc() failed\n"); - return result; -} -void CDECL expfree(void* mem) -{ -// return free(mem); - dbgprintf("free(0x%x)\n", mem); - my_release(mem); -} -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 = 0; - assert(size >= 0); - - result=my_mreq(size,0); - dbgprintf("new(0x%x) => 0x%x\n", size, result); - if (result==0) - printf("WARNING: new() failed\n"); - return result; - -} -int CDECL expdelete(void* memory) -{ - dbgprintf("delete(0x%x)\n", memory); - my_release(memory); - return 0; -} -int WINAPI expDisableThreadLibraryCalls(int module) +static 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) +static HMODULE WINAPI expGetDriverModuleHandle(DRVR* pdrv) { HMODULE result; if (pdrv==NULL) result=0; else - result=pdrv->hDriverModule; + result=pdrv->hDriverModule; dbgprintf("GetDriverModuleHandle(%p) => %p\n", pdrv, result); return result; } #define MODULE_HANDLE_kernel32 ((HMODULE)0x120) -HMODULE WINAPI expGetModuleHandleA(const char* name) +static HMODULE WINAPI expGetModuleHandleA(const char* name) { - WINE_MODREF* wm; - HMODULE result; - if(!name) - result=0; + WINE_MODREF* wm; + HMODULE result; + if(!name) + result=0; + else + { + wm=MODULE_FindModule(name); + if(wm==0)result=0; else - { - wm=MODULE_FindModule(name); - if(wm==0)result=0; - else - result=(HMODULE)(wm->module); - } - if(!result) - { - if(strcasecmp(name, "kernel32")==0) - result=MODULE_HANDLE_kernel32; - } - dbgprintf("GetModuleHandleA('%s') => 0x%x\n", name, result); - return result; + result=(HMODULE)(wm->module); + } + if(!result) + { + if(strcasecmp(name, "kernel32")==0) + result=MODULE_HANDLE_kernel32; + } + dbgprintf("GetModuleHandleA('%s') => 0x%x\n", name, result); + return result; } -void* WINAPI expCreateThread(void* pSecAttr, long dwStackSize, void* lpStartAddress, - void* lpParameter, long dwFlags, long* dwThreadId) +static void* WINAPI expCreateThread(void* pSecAttr, long dwStackSize, + void* lpStartAddress, void* lpParameter, + long dwFlags, long* dwThreadId) { pthread_t *pth; -// printf("CreateThread:"); + // printf("CreateThread:"); pth=my_mreq(sizeof(pthread_t), 0); pthread_create(pth, NULL, (void*(*)(void*))lpStartAddress, lpParameter); if(dwFlags) @@ -598,7 +554,7 @@ void* WINAPI expCreateThread(void* pSecAttr, long dwStackSize, void* lpStartAddr } 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); + pSecAttr, dwStackSize, lpStartAddress, lpParameter, dwFlags, dwThreadId, pth); return pth; } @@ -622,7 +578,7 @@ static mutex_list* mlist=NULL; void destroy_event(void* event) { mutex_list* pp=mlist; -// printf("garbage collector: destroy_event(%x)\n", event); + // printf("garbage collector: destroy_event(%x)\n", event); while(pp) { if(pp==(mutex_list*)event) @@ -633,46 +589,46 @@ void destroy_event(void* event) 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"); -*/ + /* + 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) +static 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"); -*/ + /* + mutex_list* pp; + pp=mlist; + while(pp) + { + printf("%x => ", pp); + pp=pp->prev; + } + printf("0\n"); + */ if(mlist!=NULL) { mutex_list* pp=mlist; if(name!=NULL) - do + do { if((strcmp(pp->name, name)==0) && (pp->type==0)) { dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, 0x%x='%s') => 0x%x\n", - pSecAttr, bManualReset, bInitialState, name, name, pp->pm); + pSecAttr, bManualReset, bInitialState, name, name, pp->pm); return pp->pm; } }while((pp=pp->prev) != NULL); @@ -699,25 +655,25 @@ void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset, mlist->state=bInitialState; mlist->reset=bManualReset; if(name) - strncpy(mlist->name, name, 127); + strncpy(mlist->name, name, 127); else mlist->name[0]=0; if(pm==NULL) dbgprintf("ERROR::: CreateEventA failure\n"); -/* - if(bInitialState) - pthread_mutex_lock(pm); -*/ + /* + if(bInitialState) + pthread_mutex_lock(pm); + */ if(name) - dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, 0x%x='%s') => 0x%x\n", - pSecAttr, bManualReset, bInitialState, name, name, mlist); + dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, 0x%x='%s') => 0x%x\n", + pSecAttr, bManualReset, bInitialState, name, name, mlist); else - dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, NULL) => 0x%x\n", - pSecAttr, bManualReset, bInitialState, mlist); + dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, NULL) => 0x%x\n", + pSecAttr, bManualReset, bInitialState, mlist); return mlist; } -void* WINAPI expSetEvent(void* event) +static void* WINAPI expSetEvent(void* event) |