From b4caa850133c79a384c470e5575c6159a689d610 Mon Sep 17 00:00:00 2001 From: arpi Date: Tue, 11 Dec 2001 22:58:14 +0000 Subject: avifile merge. kabi: indent changes really suxxxx git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@3466 b3059339-0415-0410-9bf9-f77b7e298cf2 --- loader/Makefile | 2 +- loader/driver.c | 2 +- loader/ext.c | 28 +- loader/module.c | 178 ++-- loader/registry.c | 52 +- loader/registry.h | 5 + loader/win32.c | 2903 +++++++++++++++++++++++++++----------------------- loader/win32.h | 232 +--- loader/wine/module.h | 59 - 9 files changed, 1706 insertions(+), 1755 deletions(-) (limited to 'loader') 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 +#include "config.h" #include #include #ifdef HAVE_MALLOC_H @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -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 +#include "config.h" #include #include @@ -14,33 +14,8 @@ #include #include #include -/* -#ifdef __linux__ -#include -#include -#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 #include #include @@ -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]) { @@ -366,53 +411,6 @@ 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) */ @@ -420,7 +418,6 @@ 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 ) { @@ -478,28 +474,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) */ @@ -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 +#include "config.h" #include #include @@ -12,8 +12,8 @@ #include #include -#include -#include +#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(;offsetnext = 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) { mutex_list *ml = (mutex_list *)event; dbgprintf("SetEvent(%x) => 0x1\n", event); @@ -730,7 +686,7 @@ void* WINAPI expSetEvent(void* event) return (void *)1; } -void* WINAPI expResetEvent(void* event) +static void* WINAPI expResetEvent(void* event) { mutex_list *ml = (mutex_list *)event; dbgprintf("ResetEvent(0x%x) => 0x1\n", event); @@ -741,7 +697,7 @@ void* WINAPI expResetEvent(void* event) return (void *)1; } -void* WINAPI expWaitForSingleObject(void* object, int duration) +static void* WINAPI expWaitForSingleObject(void* object, int duration) { mutex_list *ml = (mutex_list *)object; // FIXME FIXME FIXME - this value is sometime unititialize !!! @@ -749,14 +705,14 @@ void* WINAPI expWaitForSingleObject(void* object, int duration) mutex_list* pp=mlist; if(object == (void*)0xcfcf9898) { -/** -From GetCurrentThread() documentation: -A pseudo handle is a special constant that is interpreted as the current thread handle. The calling thread can use this handle to specify itself whenever a thread handle is required. Pseudo handles are not inherited by child processes. + /** + From GetCurrentThread() documentation: + A pseudo handle is a special constant that is interpreted as the current thread handle. The calling thread can use this handle to specify itself whenever a thread handle is required. Pseudo handles are not inherited by child processes. -This handle has the maximum possible access to the thread object. For systems that support security descriptors, this is the maximum access allowed by the security descriptor for the calling process. For systems that do not support security descriptors, this is THREAD_ALL_ACCESS. + This handle has the maximum possible access to the thread object. For systems that support security descriptors, this is the maximum access allowed by the security descriptor for the calling process. For systems that do not support security descriptors, this is THREAD_ALL_ACCESS. -The function cannot be used by one thread to create a handle that can be used by other threads to refer to the first thread. The handle is always interpreted as referring to the thread that is using it. A thread can create a "real" handle to itself that can be used by other threads, or inherited by other processes, by specifying the pseudo handle as the source handle in a call to the DuplicateHandle function. -**/ + The function cannot be used by one thread to create a handle that can be used by other threads to refer to the first thread. The handle is always interpreted as referring to the thread that is using it. A thread can create a "real" handle to itself that can be used by other threads, or inherited by other processes, by specifying the pseudo handle as the source handle in a call to the DuplicateHandle function. + **/ dbgprintf("WaitForSingleObject(thread_handle) called\n"); return (void*)WAIT_FAILED; } @@ -765,7 +721,7 @@ The function cannot be used by one thread to create a handle that can be used by // loop below was slightly fixed - its used just for checking if // this object really exists in our list if (!ml) - return (void*) ret; + return (void*) ret; while (pp && (pp->pm != ml->pm)) pp = pp->prev; if (!pp) { @@ -776,46 +732,46 @@ The function cannot be used by one thread to create a handle that can be used by pthread_mutex_lock(ml->pm); switch(ml->type) { - case 0: /* Event */ + case 0: /* Event */ if (duration == 0) { /* Check Only */ - if (ml->state == 1) ret = WAIT_FAILED; - else ret = WAIT_OBJECT_0; + if (ml->state == 1) ret = WAIT_FAILED; + else ret = WAIT_OBJECT_0; } if (duration == -1) { /* INFINITE */ - if (ml->state == 0) - pthread_cond_wait(ml->pc,ml->pm); - if (ml->reset) - ml->state = 0; - ret = WAIT_OBJECT_0; + if (ml->state == 0) + pthread_cond_wait(ml->pc,ml->pm); + if (ml->reset) + ml->state = 0; + ret = WAIT_OBJECT_0; } if (duration > 0) { /* Timed Wait */ - struct timespec abstime; - struct timeval now; - gettimeofday(&now, 0); - abstime.tv_sec = now.tv_sec + (now.tv_usec+duration)/1000000; - abstime.tv_nsec = ((now.tv_usec+duration)%1000000)*1000; - if (ml->state == 0) - ret=pthread_cond_timedwait(ml->pc,ml->pm,&abstime); - if (ret == ETIMEDOUT) ret = WAIT_TIMEOUT; - else ret = WAIT_OBJECT_0; - if (ml->reset) - ml->state = 0; + struct timespec abstime; + struct timeval now; + gettimeofday(&now, 0); + abstime.tv_sec = now.tv_sec + (now.tv_usec+duration)/1000000; + abstime.tv_nsec = ((now.tv_usec+duration)%1000000)*1000; + if (ml->state == 0) + ret=pthread_cond_timedwait(ml->pc,ml->pm,&abstime); + if (ret == ETIMEDOUT) ret = WAIT_TIMEOUT; + else ret = WAIT_OBJECT_0; + if (ml->reset) + ml->state = 0; + } + break; + case 1: /* Semaphore */ + if (duration == 0) { + if(ml->semaphore==0) ret = WAIT_FAILED; + else { + ml->semaphore++; + ret = WAIT_OBJECT_0; + } } - break; - case 1: /* Semaphore */ - if (duration == 0) { - if(ml->semaphore==0) ret = WAIT_FAILED; - else { - ml->semaphore++; - ret = WAIT_OBJECT_0; - } - } if (duration == -1) { - if (ml->semaphore==0) - pthread_cond_wait(ml->pc,ml->pm); - ml->semaphore--; + if (ml->semaphore==0) + pthread_cond_wait(ml->pc,ml->pm); + ml->semaphore--; } - break; + break; } pthread_mutex_unlock(ml->pm); @@ -825,7 +781,7 @@ The function cannot be used by one thread to create a handle that can be used by static BYTE PF[64] = {0,}; -WIN_BOOL WINAPI expIsProcessorFeaturePresent(DWORD v) +static WIN_BOOL WINAPI expIsProcessorFeaturePresent(DWORD v) { WIN_BOOL result; if(v>63)result=0; @@ -848,46 +804,46 @@ static void DumpSystemInfo(const SYSTEM_INFO* si) dbgprintf(" Processor revision: 0x%x\n", si->wProcessorRevision); } -void WINAPI expGetSystemInfo(SYSTEM_INFO* si) +static void WINAPI expGetSystemInfo(SYSTEM_INFO* si) { - /* FIXME: better values for the two entries below... */ - static int cache = 0; - static SYSTEM_INFO cachedsi; - unsigned int regs[4]; - dbgprintf("GetSystemInfo(%p) =>\n", si); + /* FIXME: better values for the two entries below... */ + static int cache = 0; + static SYSTEM_INFO cachedsi; + unsigned int regs[4]; + dbgprintf("GetSystemInfo(%p) =>\n", si); - if (cache) { - memcpy(si,&cachedsi,sizeof(*si)); - DumpSystemInfo(si); - return; - } - memset(PF,0,sizeof(PF)); - - cachedsi.u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL; - cachedsi.dwPageSize = getpagesize(); - - /* FIXME: better values for the two entries below... */ - cachedsi.lpMinimumApplicationAddress = (void *)0x00000000; - cachedsi.lpMaximumApplicationAddress = (void *)0x7FFFFFFF; - cachedsi.dwActiveProcessorMask = 1; - cachedsi.dwNumberOfProcessors = 1; - cachedsi.dwProcessorType = PROCESSOR_INTEL_386; - cachedsi.dwAllocationGranularity = 0x10000; - cachedsi.wProcessorLevel = 5; /* pentium */ - cachedsi.wProcessorRevision = 0x0101; - -#ifdef USE_WIN32DLL - /* mplayer's way to detect PF's */ - { - #include "../cpudetect.h" - extern CpuCaps gCpuCaps; + if (cache) { + memcpy(si,&cachedsi,sizeof(*si)); + DumpSystemInfo(si); + return; + } + memset(PF,0,sizeof(PF)); + + cachedsi.u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL; + cachedsi.dwPageSize = getpagesize(); - if (gCpuCaps.hasMMX) - PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE; - if (gCpuCaps.hasSSE) - PF[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE; - if (gCpuCaps.has3DNow) - PF[PF_AMD3D_INSTRUCTIONS_AVAILABLE] = TRUE; + /* FIXME: better values for the two entries below... */ + cachedsi.lpMinimumApplicationAddress = (void *)0x00000000; + cachedsi.lpMaximumApplicationAddress = (void *)0x7FFFFFFF; + cachedsi.dwActiveProcessorMask = 1; + cachedsi.dwNumberOfProcessors = 1; + cachedsi.dwProcessorType = PROCESSOR_INTEL_386; + cachedsi.dwAllocationGranularity = 0x10000; + cachedsi.wProcessorLevel = 5; /* pentium */ + cachedsi.wProcessorRevision = 0x0101; + +#ifdef MPLAYER + /* mplayer's way to detect PF's */ + { +#include "../cpudetect.h" + extern CpuCaps gCpuCaps; + + if (gCpuCaps.hasMMX) + PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE; + if (gCpuCaps.hasSSE) + PF[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE; + if (gCpuCaps.has3DNow) + PF[PF_AMD3D_INSTRUCTIONS_AVAILABLE] = TRUE; switch(gCpuCaps.cpuType) { @@ -908,280 +864,277 @@ void WINAPI expGetSystemInfo(SYSTEM_INFO* si) } cachedsi.wProcessorRevision = gCpuCaps.cpuStepping; cachedsi.dwNumberOfProcessors = 1; /* hardcoded */ - } + + } #endif /* disable cpuid based detection (mplayer's cpudetect.c does this - see above) */ -#ifndef USE_WIN32DLL +#ifndef MPLAYER #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__svr4__) - do_cpuid(1, regs); - switch ((regs[0] >> 8) & 0xf) { // cpu family - case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386; - cachedsi.wProcessorLevel= 3; - break; - case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486; - cachedsi.wProcessorLevel= 4; - break; - case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; - cachedsi.wProcessorLevel= 5; - break; - case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; - cachedsi.wProcessorLevel= 5; - break; - default:cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; - cachedsi.wProcessorLevel= 5; - break; - } - cachedsi.wProcessorRevision = regs[0] & 0xf; // stepping - if (regs[3] & (1 << 8)) - PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE; - if (regs[3] & (1 << 23)) - PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE; - if (regs[3] & (1 << 25)) - PF[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE; - if (regs[3] & (1 << 31)) - PF[PF_AMD3D_INSTRUCTIONS_AVAILABLE] = TRUE; - cachedsi.dwNumberOfProcessors=1; + do_cpuid(1, regs); + switch ((regs[0] >> 8) & 0xf) { // cpu family + case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386; + cachedsi.wProcessorLevel= 3; + break; + case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486; + cachedsi.wProcessorLevel= 4; + break; + case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; + cachedsi.wProcessorLevel= 5; + break; + case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; + cachedsi.wProcessorLevel= 5; + break; + default:cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; + cachedsi.wProcessorLevel= 5; + break; + } + cachedsi.wProcessorRevision = regs[0] & 0xf; // stepping + if (regs[3] & (1 << 8)) + PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE; + if (regs[3] & (1 << 23)) + PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE; + if (regs[3] & (1 << 25)) + PF[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE; + if (regs[3] & (1 << 31)) + PF[PF_AMD3D_INSTRUCTIONS_AVAILABLE] = TRUE; + cachedsi.dwNumberOfProcessors=1; #endif -#endif /* USE_WIN32DLL */ - +#endif /* MPLAYER */ /* MPlayer: linux detection enabled (based on proc/cpuinfo) for checking fdiv_bug and fpu emulation flags -- alex/MPlayer */ #ifdef __linux__ - { + { char buf[20]; char line[200]; FILE *f = fopen ("/proc/cpuinfo", "r"); if (!f) - return; + return; while (fgets(line,200,f)!=NULL) { - char *s,*value; - - /* NOTE: the ':' is the only character we can rely on */ - if (!(value = strchr(line,':'))) - continue; - /* terminate the valuename */ - *value++ = '\0'; - /* skip any leading spaces */ - while (*value==' ') value++; - if ((s=strchr(value,'\n'))) - *s='\0'; - - /* 2.1 method */ - if (!lstrncmpiA(line, "cpu family",strlen("cpu family"))) { - if (isdigit (value[0])) { - switch (value[0] - '0') { - case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386; - cachedsi.wProcessorLevel= 3; - break; - case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486; - cachedsi.wProcessorLevel= 4; - break; - case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; - cachedsi.wProcessorLevel= 5; - break; - case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; - cachedsi.wProcessorLevel= 5; - break; - default:cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; - cachedsi.wProcessorLevel= 5; - break; - } - } - /* set the CPU type of the current processor */ - sprintf(buf,"CPU %ld",cachedsi.dwProcessorType); - continue; - } - /* old 2.0 method */ - if (!lstrncmpiA(line, "cpu",strlen("cpu"))) { - if ( isdigit (value[0]) && value[1] == '8' && - value[2] == '6' && value[3] == 0 - ) { - switch (value[0] - '0') { - case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386; - cachedsi.wProcessorLevel= 3; - break; - case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486; - cachedsi.wProcessorLevel= 4; - break; - case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; - cachedsi.wProcessorLevel= 5; - break; - case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; - cachedsi.wProcessorLevel= 5; - break; - default:cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; - cachedsi.wProcessorLevel= 5; - break; - } - } - /* set the CPU type of the current processor */ - sprintf(buf,"CPU %ld",cachedsi.dwProcessorType); - continue; - } - if (!lstrncmpiA(line,"fdiv_bug",strlen("fdiv_bug"))) { - if (!lstrncmpiA(value,"yes",3)) - PF[PF_FLOATING_POINT_PRECISION_ERRATA] = TRUE; + char *s,*value; - continue; - } - if (!lstrncmpiA(line,"fpu",strlen("fpu"))) { - if (!lstrncmpiA(value,"no",2)) - PF[PF_FLOATING_POINT_EMULATED] = TRUE; + /* NOTE: the ':' is the only character we can rely on */ + if (!(value = strchr(line,':'))) + continue; + /* terminate the valuename */ + *value++ = '\0'; + /* skip any leading spaces */ + while (*value==' ') value++; + if ((s=strchr(value,'\n'))) + *s='\0'; - continue; + /* 2.1 method */ + if (!lstrncmpiA(line, "cpu family",strlen("cpu family"))) { + if (isdigit (value[0])) { + switch (value[0] - '0') { + case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386; + cachedsi.wProcessorLevel= 3; + break; + case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486; + cachedsi.wProcessorLevel= 4; + break; + case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; + cachedsi.wProcessorLevel= 5; + break; + case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; + cachedsi.wProcessorLevel= 5; + break; + default:cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; + cachedsi.wProcessorLevel= 5; + break; + } } - if (!lstrncmpiA(line,"processor",strlen("processor"))) { - /* processor number counts up...*/ - int x; - - if (sscanf(value,"%d",&x)) - if (x+1>cachedsi.dwNumberOfProcessors) - cachedsi.dwNumberOfProcessors=x+1; - - /* Create a new processor subkey on a multiprocessor - * system - */ - sprintf(buf,"%d",x); + /* set the CPU type of the current processor */ + sprintf(buf,"CPU %ld",cachedsi.dwProcessorType); + continue; + } + /* old 2.0 method */ + if (!lstrncmpiA(line, "cpu",strlen("cpu"))) { + if ( isdigit (value[0]) && value[1] == '8' && + value[2] == '6' && value[3] == 0 + ) { + switch (value[0] - '0') { + case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386; + cachedsi.wProcessorLevel= 3; + break; + case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486; + cachedsi.wProcessorLevel= 4; + break; + case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; + cachedsi.wProcessorLevel= 5; + break; + case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; + cachedsi.wProcessorLevel= 5; + break; + default:cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; + cachedsi.wProcessorLevel= 5; + break; + } } - if (!lstrncmpiA(line,"stepping",strlen("stepping"))) { - int x; + /* set the CPU type of the current processor */ + sprintf(buf,"CPU %ld",cachedsi.dwProcessorType); + continue; + } + if (!lstrncmpiA(line,"fdiv_bug",strlen("fdiv_bug"))) { + if (!lstrncmpiA(value,"yes",3)) + PF[PF_FLOATING_POINT_PRECISION_ERRATA] = TRUE; - if (sscanf(value,"%d",&x)) - cachedsi.wProcessorRevision = x; - } - if + continue; + } + if (!lstrncmpiA(line,"fpu",strlen("fpu"))) { + if (!lstrncmpiA(value,"no",2)) + PF[PF_FLOATING_POINT_EMULATED] = TRUE; + + continue; + } + if (!lstrncmpiA(line,"processor",strlen("processor"))) { + /* processor number counts up...*/ + int x; + + if (sscanf(value,"%d",&x)) + if (x+1>cachedsi.dwNumberOfProcessors) + cachedsi.dwNumberOfProcessors=x+1; + + /* Create a new processor subkey on a multiprocessor + * system + */ + sprintf(buf,"%d",x); + } + if (!lstrncmpiA(line,"stepping",strlen("stepping"))) { + int x; + + if (sscanf(value,"%d",&x)) + cachedsi.wProcessorRevision = x; + } + if ( (!lstrncmpiA(line,"flags",strlen("flags"))) - || (!lstrncmpiA(line,"features",strlen("features"))) ) - { - if (strstr(value,"cx8")) - PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE; - if (strstr(value,"mmx")) - PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE; - if (strstr(value,"tsc")) - PF[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE; - if (strstr(value,"xmm")) - PF[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE; - if (strstr(value,"3dnow")) - PF[PF_AMD3D_INSTRUCTIONS_AVAILABLE] = TRUE; - } + || (!lstrncmpiA(line,"features",strlen("features"))) ) + { + if (strstr(value,"cx8")) + PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE; + if (strstr(value,"mmx")) + PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE; + if (strstr(value,"tsc")) + PF[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE; + if (strstr(value,"xmm")) + PF[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE; + if (strstr(value,"3dnow")) + PF[PF_AMD3D_INSTRUCTIONS_AVAILABLE] = TRUE; + } } fclose (f); -/* - * ad hoc fix for smp machines. - * some problems on WaitForSingleObject,CreateEvent,SetEvent - * CreateThread ...etc.. - * - */ - cachedsi.dwNumberOfProcessors=1; - } + /* + * ad hoc fix for smp machines. + * some problems on WaitForSingleObject,CreateEvent,SetEvent + * CreateThread ...etc.. + * + */ + cachedsi.dwNumberOfProcessors=1; + } #endif /* __linux__ */ - - cache = 1; - memcpy(si,&cachedsi,sizeof(*si)); - DumpSystemInfo(si); + cache = 1; + memcpy(si,&cachedsi,sizeof(*si)); + DumpSystemInfo(si); } -long WINAPI expGetVersion() +static long WINAPI expGetVersion() { dbgprintf("GetVersion() => 0xC0000004\n"); return 0xC0000004;//Windows 95 } -HANDLE WINAPI expHeapCreate(long flags, long init_size, long max_size) +static HANDLE WINAPI expHeapCreate(long flags, long init_size, long max_size) { -// printf("HeapCreate:"); + // printf("HeapCreate:"); HANDLE result; if(init_size==0) - result=(HANDLE)my_mreq(0x110000, 0); + result=(HANDLE)my_mreq(0x110000, 0); else - result=(HANDLE)my_mreq(init_size, 0); + result=(HANDLE)my_mreq((init_size + 0xfff) & 0x7ffff000 , 0); dbgprintf("HeapCreate(flags 0x%x, initial size %d, maximum size %d) => 0x%x\n", flags, init_size, max_size, result); return result; } // this is another dirty hack -// VP31 is releasing one allocated Heap twice +// VP31 is releasing one allocated Heap chunk twice // we will silently ignore this second call... static void* heapfreehack = 0; static int heapfreehackshown = 0; -void* WINAPI expHeapAlloc(HANDLE heap, int flags, int size) +//extern void trapbug(void); +static void* WINAPI expHeapAlloc(HANDLE heap, int flags, int size) { void* z; -// printf("HeapAlloc:"); -/** - Morgan's m3jpeg32.dll v. 2.0 encoder expects that request for - HeapAlloc returns area larger than size argument :-/ - - do we really have to vaste that much memory - I would - suggest to make extra check for this value - FIXME -**/ - //z=my_mreq(size, flags&8); - z=my_mreq((size + 0xfff) & 0x7ffff000, flags&8); + /** + Morgan's m3jpeg32.dll v. 2.0 encoder expects that request for + HeapAlloc returns area larger than size argument :-/ + + actually according to M$ Doc HeapCreate size should be rounded + to page boundaries thus we should simulate this + **/ + //if (size == 22276) trapbug(); + z=my_mreq((size + 0xfff) & 0x7ffff000, (flags & HEAP_ZERO_MEMORY)); 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 %d) => 0x%x\n", heap, flags, size, z); heapfreehack = 0; // reset return z; } -long WINAPI expHeapDestroy(void* heap) +static long WINAPI expHeapDestroy(void* heap) { dbgprintf("HeapDestroy(heap 0x%x) => 1\n", heap); my_release(heap); return 1; } -long WINAPI expHeapFree(int arg1, int arg2, void* ptr) +static long WINAPI expHeapFree(int arg1, int arg2, void* ptr) { dbgprintf("HeapFree(0x%x, 0x%x, pointer 0x%x) => 1\n", arg1, arg2, ptr); if (heapfreehack != ptr && ptr != (void*)0xffffffff) my_release(ptr); else { - if (!heapfreehackshown++) + if (!heapfreehackshown++) printf("Info: HeapFree deallocating same memory twice! (%p)\n", ptr); } heapfreehack = ptr; return 1; } -long WINAPI expHeapSize(int heap, int flags, void* pointer) +static long WINAPI expHeapSize(int heap, int flags, void* pointer) { long result=my_size(pointer); dbgprintf("HeapSize(heap 0x%x, flags 0x%x, pointer 0x%x) => %d\n", heap, flags, pointer, result); return result; } -void* WINAPI expHeapReAlloc(HANDLE heap,int flags,void *lpMem,int size) +static void* WINAPI expHeapReAlloc(HANDLE heap,int flags,void *lpMem,int size) { - long orgsize; - void *newp; - orgsize = my_size(lpMem); + long orgsize = my_size(lpMem); dbgprintf("HeapReAlloc() Size %ld org %d\n",orgsize,size); return my_realloc(lpMem, size); } -long WINAPI expGetProcessHeap(void) +static long WINAPI expGetProcessHeap(void) { dbgprintf("GetProcessHeap() => 1\n"); return 1; } -void* WINAPI expVirtualAlloc(void* v1, long v2, long v3, long v4) +static void* WINAPI expVirtualAlloc(void* v1, long v2, long v3, long v4) { - void* z; - z=VirtualAlloc(v1, v2, v3, v4); + void* z = VirtualAlloc(v1, v2, v3, v4); if(z==0) printf("VirtualAlloc failure\n"); dbgprintf("VirtualAlloc(0x%x, %d, %d, %d) => 0x%x \n",v1,v2,v3,v4, z); return z; } -int WINAPI expVirtualFree(void* v1, int v2, int v3) +static int WINAPI expVirtualFree(void* v1, int v2, int v3) { - int result=VirtualFree(v1,v2,v3); + int result = VirtualFree(v1,v2,v3); dbgprintf("VirtualFree(0x%x, %d, %d) => %d\n",v1,v2,v3, result); return result; } /* we're building a table of critical sections. cs_win pointer uses the DLL - cs_unix is the real structure, we're using cs_win only to identifying cs_unix */ + cs_unix is the real structure, we're using cs_win only to identifying cs_unix */ struct critsecs_list_t { CRITICAL_SECTION *cs_win; @@ -1189,14 +1142,14 @@ struct critsecs_list_t }; /* 'NEWTYPE' is working with VIVO and 3ivX dll (no more segfaults) -- alex */ -//#undef CRITSECS_NEWTYPE -#define CRITSECS_NEWTYPE 1 +#undef CRITSECS_NEWTYPE +//#define CRITSECS_NEWTYPE 1 #ifdef CRITSECS_NEWTYPE #define CRITSECS_LIST_MAX 20 static struct critsecs_list_t critsecs_list[CRITSECS_LIST_MAX]; -int critsecs_get_pos(CRITICAL_SECTION *cs_win) +static int critsecs_get_pos(CRITICAL_SECTION *cs_win) { int i; @@ -1206,7 +1159,7 @@ int critsecs_get_pos(CRITICAL_SECTION *cs_win) return(-1); } -int critsecs_get_unused(void) +static int critsecs_get_unused(void) { int i; @@ -1231,52 +1184,52 @@ struct CRITSECT *critsecs_get_unix(CRITICAL_SECTION *cs_win) #endif #endif -void WINAPI expInitializeCriticalSection(CRITICAL_SECTION* c) +static void WINAPI expInitializeCriticalSection(CRITICAL_SECTION* c) { dbgprintf("InitializeCriticalSection(0x%x)\n", c); -/* if(sizeof(pthread_mutex_t)>sizeof(CRITICAL_SECTION)) - { - printf(" ERROR:::: sizeof(pthread_mutex_t) is %d, expected <=%d!\n", - sizeof(pthread_mutex_t), sizeof(CRITICAL_SECTION)); - return; - }*/ -/* pthread_mutex_init((pthread_mutex_t*)c, NULL); */ + /* if(sizeof(pthread_mutex_t)>sizeof(CRITICAL_SECTION)) + { + printf(" ERROR:::: sizeof(pthread_mutex_t) is %d, expected <=%d!\n", + sizeof(pthread_mutex_t), sizeof(CRITICAL_SECTION)); + return; + }*/ + /* pthread_mutex_init((pthread_mutex_t*)c, NULL); */ #ifdef CRITSECS_NEWTYPE -{ - struct CRITSECT *cs; - int i = critsecs_get_unused(); - - if (i < 0) { - printf("InitializeCriticalSection(%p) - no more space in list\n", c); - return; + struct CRITSECT *cs; + int i = critsecs_get_unused(); + + if (i < 0) + { + printf("InitializeCriticalSection(%p) - no more space in list\n", c); + return; + } + printf("got unused space at %d\n", i); + cs = expmalloc(sizeof(struct CRITSECT)); + if (!cs) + { + printf("InitializeCriticalSection(%p) - out of memory\n", c); + return; + } + pthread_mutex_init(&cs->mutex, NULL); + cs->locked = 0; + critsecs_list[i].cs_win = c; + critsecs_list[i].cs_unix = cs; + dbgprintf("InitializeCriticalSection -> itemno=%d, cs_win=%p, cs_unix=%p\n", + i, c, cs); } -// printf("got unused space at %d\n", i); - cs = expmalloc(sizeof(struct CRITSECT)); - if (!cs) +#else { - printf("InitializeCriticalSection(%p) - out of memory\n", c); - return; + struct CRITSECT* cs = mreq_private(sizeof(struct CRITSECT), 0, AREATYPE_CRITSECT); + pthread_mutex_init(&cs->mutex, NULL); + cs->locked=0; + *(void**)c = cs; } - pthread_mutex_init(&cs->mutex, NULL); - cs->locked = 0; - critsecs_list[i].cs_win = c; - critsecs_list[i].cs_unix = cs; - dbgprintf("InitializeCriticalSection -> itemno=%d, cs_win=%p, cs_unix=%p\n", - i, c, cs); -} -#else -{ - struct CRITSECT* cs = mreq_private(sizeof(struct CRITSECT), 0, AREATYPE_CRITSECT); - pthread_mutex_init(&cs->mutex, NULL); - cs->locked=0; - *(void**)c = cs; -} #endif return; } -void WINAPI expEnterCriticalSection(CRITICAL_SECTION* c) +static void WINAPI expEnterCriticalSection(CRITICAL_SECTION* c) { #ifdef CRITSECS_NEWTYPE struct CRITSECT* cs = critsecs_get_unix(c); @@ -1286,7 +1239,7 @@ void WINAPI expEnterCriticalSection(CRITICAL_SECTION* c) dbgprintf("EnterCriticalSection(0x%x)\n",c); if (!cs) { - printf("entered uninitialized critisec!\n"); + printf("entered uninitialized critisec!\n"); expInitializeCriticalSection(c); #ifdef CRITSECS_NEWTYPE cs=critsecs_get_unix(c); @@ -1303,14 +1256,14 @@ void WINAPI expEnterCriticalSection(CRITICAL_SECTION* c) cs->id=pthread_self(); return; } -void WINAPI expLeaveCriticalSection(CRITICAL_SECTION* c) +static void WINAPI expLeaveCriticalSection(CRITICAL_SECTION* c) { #ifdef CRITSECS_NEWTYPE struct CRITSECT* cs = critsecs_get_unix(c); #else struct CRITSECT* cs=*(struct CRITSECT**)c; #endif -// struct CRITSECT* cs=(struct CRITSECT*)c; + // struct CRITSECT* cs=(struct CRITSECT*)c; dbgprintf("LeaveCriticalSection(0x%x)\n",c); if (!cs) { @@ -1321,41 +1274,45 @@ void WINAPI expLeaveCriticalSection(CRITICAL_SECTION* c) pthread_mutex_unlock(&(cs->mutex)); return; } -void WINAPI expDeleteCriticalSection(CRITICAL_SECTION *c) +static void WINAPI expDeleteCriticalSection(CRITICAL_SECTION *c) { #ifdef CRITSECS_NEWTYPE struct CRITSECT* cs = critsecs_get_unix(c); #else struct CRITSECT* cs=*(struct CRITSECT**)c; #endif -// struct CRITSECT* cs=(struct CRITSECT*)c; + // struct CRITSECT* cs=(struct CRITSECT*)c; dbgprintf("DeleteCriticalSection(0x%x)\n",c); + +#ifndef GARBAGE pthread_mutex_destroy(&(cs->mutex)); -// free(cs); + // released by GarbageCollector in my_relase otherwise +#endif + my_release(cs); #ifdef CRITSECS_NEWTYPE -{ - int i = critsecs_get_pos(c); - - if (i < 0) { - printf("DeleteCriticalSection(%p) error (critsec not found)\n", c); - return; - } + int i = critsecs_get_pos(c); - critsecs_list[i].cs_win = NULL; - expfree(critsecs_list[i].cs_unix); - critsecs_list[i].cs_unix = NULL; - dbgprintf("DeleteCriticalSection -> itemno=%d\n", i); -} + if (i < 0) + { + printf("DeleteCriticalSection(%p) error (critsec not found)\n", c); + return; + } + + critsecs_list[i].cs_win = NULL; + expfree(critsecs_list[i].cs_unix); + critsecs_list[i].cs_unix = NULL; + dbgprintf("DeleteCriticalSection -> itemno=%d\n", i); + } #endif return; } -int WINAPI expGetCurrentThreadId() +static int WINAPI expGetCurrentThreadId() { dbgprintf("GetCurrentThreadId() => %d\n", getpid()); return getpid(); } -int WINAPI expGetCurrentProcess() +static int WINAPI expGetCurrentProcess() { dbgprintf("GetCurrentProcess() => %d\n", getpid()); return getpid(); @@ -1369,7 +1326,7 @@ extern void* fs_seg; //static int tls_count; static int tls_use_map[64]; -int WINAPI expTlsAlloc() +static int WINAPI expTlsAlloc() { int i; for(i=0; i<64; i++) @@ -1381,23 +1338,26 @@ int WINAPI expTlsAlloc() return -1; } -int WINAPI expTlsSetValue(int index, void* value) +static int WINAPI expTlsSetValue(void idx, void* value) { + int index = (int) idx; if((index<0) || (index>64)) return 0; *(void**)((char*)fs_seg+0x88+4*index) = value; return 1; } -void* WINAPI expTlsGetValue(int index) +static void* WINAPI expTlsGetValue(int idx) { + int index = (int) idx; if((index<0) || (index>64)) return 0; return *(void**)((char*)fs_seg+0x88+index); } -int WINAPI expTlsFree(int index) +static int WINAPI expTlsFree(int idx) { + int index = (int) idx; if((index<0) || (index>64)) return 0; tls_use_map[index]=0; @@ -1412,7 +1372,7 @@ struct tls_s { struct tls_s* next; }; -void* WINAPI expTlsAlloc() +static void* WINAPI expTlsAlloc() { if(g_tls==NULL) { @@ -1432,8 +1392,9 @@ void* WINAPI expTlsAlloc() return g_tls; } -int WINAPI expTlsSetValue(tls_t* index, void* value) +static int WINAPI expTlsSetValue(void* idx, void* value) { + tls_t* index = (tls_t*) idx; int result; if(index==0) result=0; @@ -1445,8 +1406,9 @@ int WINAPI expTlsSetValue(tls_t* index, void* value) dbgprintf("TlsSetValue(index 0x%x, value 0x%x) => %d \n", index, value, result ); return result; } -void* WINAPI expTlsGetValue(tls_t* index) +static void* WINAPI expTlsGetValue(void* idx) { + tls_t* index = (tls_t*) idx; void* result; if(index==0) result=0; @@ -1455,8 +1417,9 @@ void* WINAPI expTlsGetValue(tls_t* index) dbgprintf("TlsGetValue(index 0x%x) => 0x%x\n", index, result); return result; } -int WINAPI expTlsFree(tls_t* index) +static int WINAPI expTlsFree(void* idx) { + tls_t* index = (tls_t*) idx; int result; if(index==0) result=0; @@ -1465,7 +1428,7 @@ int WINAPI expTlsFree(tls_t* index) if(index->next) index->next->prev=index->prev; if(index->prev) - index->prev->next=index->next; + index->prev->next=index->next; my_release((void*)index); result=1; } @@ -1474,87 +1437,81 @@ int WINAPI expTlsFree(tls_t* index) } #endif -void* WINAPI expLocalAlloc(int flags, int size) +static void* WINAPI expLocalAlloc(int flags, int size) { - void* z; - if(flags&GMEM_ZEROINIT) - z=my_mreq(size, 1); - else - z=my_mreq(size, 0); - if(z==0) + void* z = my_mreq(size, (flags & GMEM_ZEROINIT)); + if (z == 0) printf("LocalAlloc() failed\n"); dbgprintf("LocalAlloc(%d, flags 0x%x) => 0x%x\n", size, flags, z); return z; } -void* WINAPI expLocalReAlloc(int handle,int size, int flags) +static void* WINAPI expLocalReAlloc(int handle,int size, int flags) { - void *newpointer; - int oldsize; + void *newpointer; + int oldsize; - newpointer=NULL; - if (flags & LMEM_MODIFY) { - dbgprintf("LocalReAlloc MODIFY\n"); - return (void *)handle; - } - oldsize = my_size((void *)handle); - newpointer = my_realloc((void *)handle,size); - dbgprintf("LocalReAlloc(%x %d(old %d), flags 0x%x) => 0x%x\n", handle,size,oldsize, flags,newpointer); + newpointer=NULL; + if (flags & LMEM_MODIFY) { + dbgprintf("LocalReAlloc MODIFY\n"); + return (void *)handle; + } + oldsize = my_size((void *)handle); + newpointer = my_realloc((void *)handle,size); + dbgprintf("LocalReAlloc(%x %d(old %d), flags 0x%x) => 0x%x\n", handle,size,oldsize, flags,newpointer); - return newpointer; + return newpointer; } -void* WINAPI expLocalLock(void* z) +static void* WINAPI expLocalLock(void* z) { dbgprintf("LocalLock(0x%x) => 0x%x\n", z, z); return z; } -void* WINAPI expGlobalAlloc(int flags, int size) +static void* WINAPI expGlobalAlloc(int flags, int size) { void* z; dbgprintf("GlobalAlloc(%d, flags 0x%X)\n", size, flags); - if(flags&GMEM_ZEROINIT) - z=my_mreq(size, 1); - //z=calloc(size, 1); - else - z=my_mreq(size, 0); - //z=malloc(size); + + z=my_mreq(size, (flags & GMEM_ZEROINIT)); + //z=calloc(size, 1); + //z=malloc(size); if(z==0) printf("GlobalAlloc() failed\n"); dbgprintf("GlobalAlloc(%d, flags 0x%x) => 0x%x\n", size, flags, z); return z; } -void* WINAPI expGlobalLock(void* z) +static void* WINAPI expGlobalLock(void* z) { dbgprintf("GlobalLock(0x%x) => 0x%x\n", z, z); return z; } // pvmjpg20 - but doesn't work anyway -int WINAPI expGlobalSize(void* amem) +static int WINAPI expGlobalSize(void* amem) { int size = 100000; #ifdef GARBAGE alloc_header* header = last_alloc; alloc_header* mem = (alloc_header*) amem - 1; if (amem == 0) - return 0; + return 0; pthread_mutex_lock(&memmut); while (header) { - if (header->deadbeef != 0xdeadbeef) - { - printf("FATAL found corrupted memory! %p 0x%lx (%d)\n", header, header->deadbeef, alccnt); - break; - } + if (header->deadbeef != 0xdeadbeef) + { + printf("FATAL found corrupted memory! %p 0x%lx (%d)\n", header, header->deadbeef, alccnt); + break; + } - if (header == mem) - { - size = header->size; - break; - } + if (header == mem) + { + size = header->size; + break; + } - header = header->prev; + header = header->prev; } pthread_mutex_unlock(&memmut); #endif @@ -1562,36 +1519,36 @@ int WINAPI expGlobalSize(void* amem) dbgprintf("GlobalSize(0x%x)\n", amem); return size; } -int WINAPI expLoadStringA(long instance, long id, void* buf, long size) +static int WINAPI expLoadStringA(long instance, long id, void* buf, long size) { int result=LoadStringA(instance, id, buf, size); -// if(buf) + // if(buf) dbgprintf("LoadStringA(instance 0x%x, id 0x%x, buffer 0x%x, size %d) => %d ( %s )\n", - instance, id, buf, size, result, buf); -// else -// dbgprintf("LoadStringA(instance 0x%x, id 0x%x, buffer 0x%x, size %d) => %d\n", -// instance, id, buf, size, result); + instance, id, buf, size, result, buf); + // else + // dbgprintf("LoadStringA(instance 0x%x, id 0x%x, buffer 0x%x, size %d) => %d\n", + // instance, id, buf, size,