📄 win32.c
字号:
dbgprintf("TlsSetValue(%d,0x%x) => 1\n",index,value);// if((index<0) || (index>64)) if((index>=64)) return 0; *(void**)((char*)fs_seg+0x88+4*index) = value; return 1;}static void* WINAPI expTlsGetValue(DWORD index){ dbgprintf("TlsGetValue(%d)\n",index);// if((index<0) || (index>64)) if((index>=64)) return NULL; return *(void**)((char*)fs_seg+0x88+4*index);}static int WINAPI expTlsFree(int idx){ int index = (int) idx; dbgprintf("TlsFree(%d)\n",index); if((index<0) || (index>64)) return 0; tls_use_map[index]=0; return 1;}#elsestruct tls_s { void* value; int used; struct tls_s* prev; struct tls_s* next;};static void* WINAPI expTlsAlloc(){ if (g_tls == NULL) { g_tls=my_mreq(sizeof(tls_t), 0); g_tls->next=g_tls->prev=NULL; } else { g_tls->next=my_mreq(sizeof(tls_t), 0); g_tls->next->prev=g_tls; g_tls->next->next=NULL; g_tls=g_tls->next; } dbgprintf("TlsAlloc() => 0x%x\n", g_tls); if (g_tls) g_tls->value=0; /* XXX For Divx.dll */ return g_tls;}static int WINAPI expTlsSetValue(void* idx, void* value){ tls_t* index = (tls_t*) idx; int result; if(index==0) result=0; else { index->value=value; result=1; } dbgprintf("TlsSetValue(index 0x%x, value 0x%x) => %d \n", index, value, result ); return result;}static void* WINAPI expTlsGetValue(void* idx){ tls_t* index = (tls_t*) idx; void* result; if(index==0) result=0; else result=index->value; dbgprintf("TlsGetValue(index 0x%x) => 0x%x\n", index, result); return result;}static int WINAPI expTlsFree(void* idx){ tls_t* index = (tls_t*) idx; int result; if(index==0) result=0; else { if(index->next) index->next->prev=index->prev; if(index->prev) index->prev->next=index->next; if (g_tls == index) g_tls = index->prev; my_release((void*)index); result=1; } dbgprintf("TlsFree(index 0x%x) => %d\n", index, result); return result;}#endifstatic void* WINAPI expLocalAlloc(int flags, int size){ 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;}static void* WINAPI expLocalReAlloc(int handle,int size, int flags){ 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); return newpointer;}static void* WINAPI expLocalLock(void* z){ dbgprintf("LocalLock(0x%x) => 0x%x\n", z, z); return z;}static void* WINAPI expGlobalAlloc(int flags, int size){ void* z; dbgprintf("GlobalAlloc(%d, flags 0x%X)\n", size, flags); 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;}static void* WINAPI expGlobalLock(void* z){ dbgprintf("GlobalLock(0x%x) => 0x%x\n", z, z); return z;}// pvmjpg20 - but doesn't work anywaystatic 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; pthread_mutex_lock(&memmut); while (header) { if (header->deadbeef != 0xdeadbeef) { dbgprintf("FATAL found corrupted memory! %p 0x%lx (%d)\n", header, header->deadbeef, alccnt); break; } if (header == mem) { size = header->size; break; } header = header->prev; } pthread_mutex_unlock(&memmut);#endif dbgprintf("GlobalSize(0x%x)\n", amem); return size;}static int WINAPI expLoadIconA( long hinstance, char *name ){ dbgprintf("LoadIconA( %ld, 0x%x ) => 1\n",hinstance,name); return 1;}static int WINAPI expLoadStringA(long instance, long id, void* buf, long size){ int result=LoadStringA(instance, id, buf, size); // 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); return result;}static long WINAPI expMultiByteToWideChar(long v1, long v2, char* s1, long siz1, short* s2, int siz2){#warning FIXME int i; int result; if(s2==0) result=1; else { if(siz1>siz2/2)siz1=siz2/2; for(i=1; i<=siz1; i++) { *s2=*s1; if(!*s1)break; s2++; s1++; } result=i; } if(s1) dbgprintf("MultiByteToWideChar(codepage %d, flags 0x%x, string 0x%x='%s'," "size %d, dest buffer 0x%x, dest size %d) => %d\n", v1, v2, s1, s1, siz1, s2, siz2, result); else dbgprintf("MultiByteToWideChar(codepage %d, flags 0x%x, string NULL," "size %d, dest buffer 0x%x, dest size %d) =>\n", v1, v2, siz1, s2, siz2, result); return result;}static void wch_print(const short* str){ dbgprintf(" src: "); while(*str)dbgprintf("%c", *str++); dbgprintf("\n");}static long WINAPI expWideCharToMultiByte(long v1, long v2, short* s1, long siz1, char* s2, int siz2, char* c3, int* siz3){ int result; dbgprintf("WideCharToMultiByte(codepage %d, flags 0x%x, src 0x%x, src size %d, " "dest 0x%x, dest size %d, defch 0x%x, used_defch 0x%x)", v1, v2, s1, siz1, s2, siz2, c3, siz3); result=WideCharToMultiByte(v1, v2, s1, siz1, s2, siz2, c3, siz3); dbgprintf("=> %d\n", result); //if(s1)wch_print(s1); if(s2)dbgprintf(" dest: %s\n", s2); return result;}static long WINAPI expGetVersionExA(OSVERSIONINFOA* c){ dbgprintf("GetVersionExA(0x%x) => 1\n"); c->dwOSVersionInfoSize=sizeof(*c); c->dwMajorVersion=4; c->dwMinorVersion=0; c->dwBuildNumber=0x4000457;#if 1 // leave it here for testing win9x-only codecs c->dwPlatformId=VER_PLATFORM_WIN32_WINDOWS; strcpy(c->szCSDVersion, " B");#else c->dwPlatformId=VER_PLATFORM_WIN32_NT; // let's not make DLL assume that it can read CR* registers strcpy(c->szCSDVersion, "Service Pack 3");#endif dbgprintf(" Major version: 4\n Minor version: 0\n Build number: 0x4000457\n" " Platform Id: VER_PLATFORM_WIN32_NT\n Version string: 'Service Pack 3'\n"); return 1;}static HANDLE WINAPI expCreateSemaphoreA(char* v1, long init_count, long max_count, char* name){ pthread_mutex_t *pm; pthread_cond_t *pc; /* mutex_list* pp; printf("CreateSemaphoreA(%p = %s)\n", name, (name ? name : "<null>")); pp=mlist; while(pp) { printf("%p => ", pp); pp=pp->prev; } printf("0\n"); */ if(mlist!=NULL) { mutex_list* pp=mlist; if(name!=NULL) do { if((strcmp(pp->name, name)==0) && (pp->type==1)) { dbgprintf("CreateSemaphoreA(0x%x, init_count %d, max_count %d, name 0x%x='%s') => 0x%x\n", v1, init_count, max_count, name, name, mlist); return (HANDLE)mlist; } }while((pp=pp->prev) != NULL); } pm=mreq_private(sizeof(pthread_mutex_t), 0, AREATYPE_MUTEX); pthread_mutex_init(pm, NULL); pc=mreq_private(sizeof(pthread_cond_t), 0, AREATYPE_COND); pthread_cond_init(pc, NULL); if(mlist==NULL) { mlist=mreq_private(sizeof(mutex_list), 00, AREATYPE_EVENT); mlist->next=mlist->prev=NULL; } else { mlist->next=mreq_private(sizeof(mutex_list), 00, AREATYPE_EVENT); mlist->next->prev=mlist; mlist->next->next=NULL; mlist=mlist->next; // printf("new semaphore %p\n", mlist); } mlist->type=1; /* Type Semaphore */ mlist->pm=pm; mlist->pc=pc; mlist->state=0; mlist->reset=0; mlist->semaphore=init_count; if(name!=NULL) strncpy(mlist->name, name, 64); else mlist->name[0]=0; if(pm==NULL) dbgprintf("ERROR::: CreateSemaphoreA failure\n"); if(name) dbgprintf("CreateSemaphoreA(0x%x, init_count %d, max_count %d, name 0x%x='%s') => 0x%x\n", v1, init_count, max_count, name, name, mlist); else dbgprintf("CreateSemaphoreA(0x%x, init_count %d, max_count %d, name 0) => 0x%x\n", v1, init_count, max_count, mlist); return (HANDLE)mlist;}static long WINAPI expReleaseSemaphore(long hsem, long increment, long* prev_count){ // The state of a semaphore object is signaled when its count // is greater than zero and nonsignaled when its count is equal to zero // Each time a waiting thread is released because of the semaphore's signaled // state, the count of the semaphore is decreased by one. mutex_list *ml = (mutex_list *)hsem; pthread_mutex_lock(ml->pm); if (prev_count != 0) *prev_count = ml->semaphore; if (ml->semaphore == 0) pthread_cond_signal(ml->pc); ml->semaphore += increment; pthread_mutex_unlock(ml->pm); dbgprintf("ReleaseSemaphore(semaphore 0x%x, increment %d, prev_count 0x%x) => 1\n", hsem, increment, prev_count); return 1;}static long WINAPI expRegOpenKeyExA(long key, const char* subkey, long reserved, long access, int* newkey){ long result=RegOpenKeyExA(key, subkey, reserved, access, newkey); dbgprintf("RegOpenKeyExA(key 0x%x, subkey %s, reserved %d, access 0x%x, pnewkey 0x%x) => %d\n", key, subkey, reserved, access, newkey, result); if(newkey)dbgprintf(" New key: 0x%x\n", *newkey); return result;}static long WINAPI expRegCloseKey(long key){ long result=RegCloseKey(key); dbgprintf("RegCloseKey(0x%x) => %d\n", key, result); return result;}static long WINAPI expRegQueryValueExA(long key, const char* value, int* reserved, int* type, int* data, int* count){ long result=RegQueryValueExA(key, value, reserved, type, data, count); dbgprintf("RegQueryValueExA(key 0x%x, value %s, reserved 0x%x, data 0x%x, count 0x%x)" " => 0x%x\n", key, value, reserved, data, count, result); if(data && count)dbgprintf(" read %d bytes: '%s'\n", *count, data); return result;}//from wine source dlls/advapi32/registry.cstatic long WINAPI expRegCreateKeyA(long hkey, const char* name, int *retkey){ dbgprintf("RegCreateKeyA(key 0x%x, name 0x%x='%s',newkey=0x%x)\n",hkey,name,retkey); return RegCreateKeyExA( hkey, name, 0, NULL,REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS , NULL, retkey, NULL );}static long WINAPI expRegCreateKeyExA(long key, const char* name, long reserved, void* classs, long options, long security, void* sec_attr, int* newkey, int* status){ long result=RegCreateKeyExA(key, name, reserved, classs, options, security, sec_attr, newkey, status); dbgprintf("RegCreateKeyExA(key 0x%x, name 0x%x='%s', reserved=0x%x," " 0x%x, 0x%x, 0x%x, newkey=0x%x, status=0x%x) => %d\n", key, name, name, reserved, classs, options, security, sec_attr, newkey, status, result); if(!result && newkey) dbgprintf(" New key: 0x%x\n", *newkey); if(!result && status) dbgprintf(" New key status: 0x%x\n", *status); return result;}static long WINAPI expRegSetValueExA(long key, const char* name, long v1, long v2, void* data, long size){ long result=RegSetValueExA(key, name, v1, v2, data, size); dbgprintf("RegSetValueExA(key 0x%x, name '%s', 0x%x, 0x%x, data 0x%x -> 0x%x '%s', size=%d) => %d", key, name, v1, v2, data, *(int*)data, data, size, result); return result;}static long WINAPI expRegOpenKeyA (long hKey, LPCSTR lpSubKey, int* phkResult){ long result=RegOpenKeyExA(hKey, lpSubKey, 0, 0, phkResult); dbgprintf("RegOpenKeyExA(key 0x%x, subkey '%s', 0x%x) => %d\n", hKey, lpSubKey, phkResult, result); if(!result && phkResult) dbgprintf(" New key: 0x%x\n", *phkResult); return result;}static DWORD WINAPI expRegEnumValueA(HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count, LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count){ return RegEnumValueA(hkey, index, value, val_count, reserved, type, data, count);}static DWORD WINAPI expRegEnumKeyExA(HKEY hKey, DWORD dwIndex, LPSTR lpName, LPDWORD lpcbName, LPDWORD lpReserved, LPSTR lpClass, LPDWORD lpcbClass, LPFILETIME lpftLastWriteTime){ return RegEnumKeyExA(hKey, dwIndex, lpName, lpcbName, lpReserved, lpClass, lpcbClass, lpftLastWriteTime);}static long WINAPI expQueryPerformanceCounter(long long* z){ longcount(z); dbgprintf("QueryPerformanceCounter(0x%x) => 1 ( %Ld )\n", z, *z); return 1;}/* * dummy function RegQueryInfoKeyA(), required by vss codecs */static DWORD WINAPI expRegQueryInfoKeyA( HKEY hkey, LPSTR class, LPDWORD class_len, LPDWORD reserved, LPDWORD subkeys, LPDWORD max_subkey, LPDWORD max_class, LPDWORD values, LPDWORD max_value, LPDWORD max_data, LPDWORD security, FILETIME *modif ){ return ERROR_SUCCESS;}/* * return CPU clock (in kHz), using linux's /proc filesystem (/proc/cpuinfo) */static double linux_cpuinfo_freq(){ double freq=-1; FILE *f; char line[200]; char *s,*value; f = fopen ("/proc/cpuinfo", "r"); if (f != NULL) { while (fgets(line,sizeof(line),f)!=NULL) { /* 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'; if (!strncasecmp(line, "cpu MHz",strlen("cpu MHz")) && sscanf(value, "%lf", &freq) == 1) { freq*=1000; break; } } fclose(f); } return freq;}static double solaris_kstat_freq(){#if defined(HAVE_LIBKSTAT) && defined(KSTAT_DATA_INT32) /* * try to extract the CPU speed from the solaris kernel's kstat data */ kstat_ctl_t *kc; kstat_t *ksp; kstat_named_t *kdata;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -