⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 win32.c

📁 linux下的MPEG1
💻 C
📖 第 1 页 / 共 5 页
字号:
#if 0    return *(void**)((char*)fs_seg+0x88+4*index);#else    /* does not require fs_seg memory, if everything is right     * we can access FS:xxxx like any win32 code would do.     */    index = 0x88+4*index;     __asm__ __volatile__(	"movl %%fs:(%1),%0" : "=r" (ret) : "r" (index)     );    return ret;#endif}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) => %p\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) => %p\n", handle,size,oldsize, flags,newpointer);    return newpointer;}static void* WINAPI expLocalLock(void* z){    dbgprintf("LocalLock(%p) => %p\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) => %p\n", size, flags, z);    return z;}static void* WINAPI expGlobalLock(void* z){    dbgprintf("GlobalLock(%p) => %p\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)	{	    printf("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(%p)\n", amem);    return size;}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%lx, id 0x%lx, buffer %p, size %ld) => %d ( %s )\n",	      instance, id, buf, size, result, (char *)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 %ld, flags 0x%lx, string %p='%s',"		  "size %ld, dest buffer %p, dest size %d) => %d\n",		  v1, v2, s1, s1, siz1, s2, siz2, result);    else	dbgprintf("MultiByteToWideChar(codepage %ld, flags 0x%lx, string NULL,"		  "size %ld, dest buffer %p, dest size %d) => %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 %ld, flags 0x%lx, src %p, src size %ld, "	      "dest %p, dest size %d, defch %p, used_defch %p)",	      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(%p) => 1\n", c);    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; -- unused */    /*     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(%p, init_count %ld, max_count %ld, name %p='%s') => %p\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(%p, init_count %ld, max_count %ld, name %p='%s') => %p\n",		  v1, init_count, max_count, name, name, mlist);    else	dbgprintf("CreateSemaphoreA(%p, init_count %ld, max_count %ld, name NULL) => %p\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%lx, increment %ld, prev_count %p) => 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%lx, subkey %s, reserved %ld, access 0x%lx, pnewkey %p) => %ld\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%lx) => %ld\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%lx, value %s, reserved %p, data %p, count %p)"	      " => 0x%lx\n", key, value, reserved, data, count, result);    if(data && count)dbgprintf("  read %d bytes: '%s'\n", *count, (char *)data); /* FIXME? */    return result;}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%lx, name %p='%s', reserved=0x%lx,"	      " %p, 0x%lx, 0x%lx, %p, newkey=%p, status=%p) => %ld\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%lx, name '%s', 0x%lx, 0x%lx, data %p -> 0x%x '%s', size=%ld) => %ld",	      key, name, v1, v2, data, *(int*)data, (char *)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%lx, subkey '%s', %p) => %ld\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(%p) => 1 ( %Ld )\n", z, *z);    return 1;}/* * 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;    int            mhz = 0;    kc = kstat_open();    if (kc != NULL)    {	ksp = kstat_lookup(kc, "cpu_info", 0, "cpu_info0");	/* kstat found and name/value pairs? */	if (ksp != NULL && ksp->ks_type == KSTAT_TYPE_NAMED)	{	    /* read the kstat data from the kernel */	    if (kstat_read(kc, ksp, NULL) != -1)	    {		/*		 * lookup desired "clock_MHz" entry, check the expected		 * data type		 */		kdata = (kstat_named_t *)kstat_data_lookup(ksp, "clock_MHz");		if (kdata != NULL && kdata->data_type == KSTAT_DATA_INT32)		    mhz = kdata->value.i32;	    }	}	kstat_close(kc);    }    if (mhz > 0)	return mhz * 1000.;#endif	/* HAVE_LIBKSTAT */    return -1;		// kstat stuff is not available, CPU freq is unknown}/* * Measure CPU freq using the pentium's time stamp counter register (TSC) */static double tsc_freq(){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -