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

📄 win32.c

📁 君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图片解码,浏览,电子书,录音,想学ucos,识货的人就下吧 russblock fmradio explore set
💻 C
📖 第 1 页 / 共 5 页
字号:
/***********************************************************Win32 emulation code. Functions that emulateresponses from corresponding Win32 API calls.Since we are not going to be able to loadvirtually any DLL, we can only implement thismuch, adding needed functions with each new codec.Basic principle of implementation: it's not goodfor DLL to know too much about its environment.************************************************************//* * Modified for use with MPlayer, detailed changelog at * http://svn.mplayerhq.hu/mplayer/trunk/ * $Id: win32.c,v 1.3 2008/04/12 07:14:45 dsqiu Exp $ */#include "config.h"#include "mangle.h"#undef memcpy#define memcpy uc_memcpy#ifdef USE_QTX_CODECS#define QTX#endif#define REALPLAYER//#define LOADLIB_TRY_NATIVE#ifdef QTX#define PSEUDO_SCREEN_WIDTH	/*640*/800#define PSEUDO_SCREEN_HEIGHT	/*480*/600#endif#include "wine/winbase.h"#include "wine/winreg.h"#include "wine/winnt.h"#include "wine/winerror.h"#include "wine/debugtools.h"#include "wine/module.h"#include "wine/winuser.h"#include <mplaylib.h>#include "win32.h"#include "registry.h"#include "loader.h"#include "com.h"#include "ext.h"#include <mplaylib.h>#include <assert.h>#include <stdarg.h>#include <ctype.h>#include <pthread.h>#include <errno.h>#ifdef HAVE_MALLOC_H#include <uclib.h>#endif#include <time.h>#include <math.h>#include <mplaylib.h>#include <fcntl.h>#include <sys/types.h>#include <dirent.h>#include <sys/time.h>#include <sys/timeb.h>#ifdef	HAVE_KSTAT#include <kstat.h>#endif#include <sys/mman.h>#include "osdep/mmap_anon.h"#if HAVE_VSSCANFint vsscanf( const char *str, const char *format, va_list ap);#else/* 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);}#endifchar* 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)	);}static unsigned int c_localcount_tsc(){    int a;    __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)	 :"edx"	);}static unsigned int c_localcount_notsc(){    struct timeval tv;    unsigned limit=~0;    limit/=1000000;    gettimeofday(&tv, 0);    return limit*tv.tv_usec;}static void c_longcount_notsc(long long* z){    struct timeval tv;    unsigned long long result;    unsigned limit=~0;    if(!z)return;    limit/=1000000;    gettimeofday(&tv, 0);    result=tv.tv_sec;    result<<=32;    result+=limit*tv.tv_usec;    *z=result;}static unsigned int localcount_stub(void);static void longcount_stub(long long*);static unsigned int (*localcount)()=localcount_stub;static void (*longcount)(long long*)=longcount_stub;static pthread_mutex_t memmut;static unsigned int localcount_stub(void){    unsigned int regs[4];    do_cpuid(1, regs);    if ((regs[3] & 0x00000010) != 0)    {	localcount=c_localcount_tsc;	longcount=c_longcount_tsc;    }    else    {	localcount=c_localcount_notsc;	longcount=c_longcount_notsc;    }    return localcount();}static void longcount_stub(long long* z){    unsigned int regs[4];    do_cpuid(1, regs);    if ((regs[3] & 0x00000010) != 0)    {	localcount=c_localcount_tsc;	longcount=c_longcount_tsc;    }    else    {	localcount=c_localcount_notsc;	longcount=c_longcount_notsc;    }    longcount(z);}#include "mp_msg.h"int LOADER_DEBUG=1; // active only if compiled with -DDETAILED_OUT//#define DETAILED_OUTstatic inline void dbgprintf(char* fmt, ...){#ifdef DETAILED_OUT    if(LOADER_DEBUG)    {	FILE* f;	va_list va;	va_start(va, fmt);	f=fopen("./log", "a");	vprintf(fmt, va);	fflush(stdout);	if(f)	{	    vfprintf(f, fmt, va);	    fsync(fileno(f));	    fclose(f);	}	va_end(va);    }#endif    if ( mp_msg_test(MSGT_WIN32,MSGL_DBG3) )    {	va_list va;		va_start(va, fmt);	vprintf(fmt, va);//	mp_dbg(MSGT_WIN32, MSGL_DBG3, fmt, va);	va_end(va);    }  fflush(stdout);}char export_names[300][32]={    "name1",    //"name2",    //"name3"};//#define min(x,y) ((x)<(y)?(x):(y))void destroy_event(void* event);struct th_list_t;typedef struct th_list_t{    int id;    void* thread;    struct th_list_t* next;    struct th_list_t* prev;} th_list;// have to be cleared by GARBAGE COLLECTORstatic unsigned char* heap=NULL;static int heap_counter=0;static tls_t* g_tls=NULL;static th_list* list=NULL;static void test_heap(void){    int offset=0;    if(heap==0)	return;    while(offset<heap_counter)    {	if(*(int*)(heap+offset)!=0x433476)	{	    printf("Heap corruption at address %d\n", offset);	    return;	}	offset+=8+*(int*)(heap+offset+4);    }    for(;offset<min(offset+1000, 20000000); offset++)	if(heap[offset]!=0xCC)	{	    printf("Free heap corruption at address %d\n", offset);	}}#undef MEMORY_DEBUG#ifdef MEMORY_DEBUGstatic 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();    if(heap==NULL)    {	heap=malloc(20000000);	memset(heap, 0xCC,20000000);    }    if(heap==0)    {	printf("No enough memory\n");	return 0;    }    if(heap_counter+size>20000000)    {	printf("No enough memory\n");	return 0;    }    *(int*)(heap+heap_counter)=0x433476;    heap_counter+=4;    *(int*)(heap+heap_counter)=size;    heap_counter+=4;    printf("Allocated %d bytes of memory: sys %d, user %d-%d\n", size, heap_counter-8, heap_counter, heap_counter+size);    if(to_zero)	memset(heap+heap_counter, 0, size);    else	memset(heap+heap_counter, 0xcc, size);  // make crash reproducable    heap_counter+=size;    return heap+heap_counter-size;}static int my_release(char* memory){    //    test_heap();    if(memory==NULL)    {	printf("ERROR: free(0)\n");	return 0;    }    if(*(int*)(memory-8)!=0x433476)    {	printf("MEMORY CORRUPTION !!!!!!!!!!!!!!!!!!!\n");	return 0;    }    printf("Freed %d bytes of memory\n", *(int*)(memory-4));    //    memset(memory-8, *(int*)(memory-4), 0xCC);    return 0;}#else#define GARBAGEtypedef struct alloc_header_t alloc_header;struct alloc_header_t{    // let's keep allocated data 16 byte aligned    alloc_header* prev;    alloc_header* next;    long deadbeef;    long size;    long type;    long reserved1;    long reserved2;    long reserved3;};#ifdef GARBAGEstatic alloc_header* last_alloc = NULL;static int alccnt = 0;#endif#define AREATYPE_CLIENT 0#define AREATYPE_EVENT 1#define AREATYPE_MUTEX 2#define AREATYPE_COND 3#define AREATYPE_CRITSECT 4/* -- critical sections -- */struct CRITSECT{    pthread_t id;    pthread_mutex_t mutex;    int locked;    long deadbeef;};void* mreq_private(int size, int to_zero, int type);void* mreq_private(int size, int to_zero, int type){    int nsize = size + sizeof(alloc_header);    alloc_header* header = (alloc_header* ) malloc(nsize);    if (!header)        return 0;    if (to_zero)	memset(header, 0, nsize);#ifdef GARBAGE    if (!last_alloc)    {	pthread_mutex_init(&memmut, NULL);	pthread_mutex_lock(&memmut);    }    else    {	pthread_mutex_lock(&memmut);	last_alloc->next = header;  /* set next */    }    header->prev = last_alloc;    header->next = 0;    last_alloc = header;    alccnt++;    pthread_mutex_unlock(&memmut);#endif    header->deadbeef = 0xdeadbeef;    header->size = size;    header->type = type;    //if (alccnt < 40000) printf("MY_REQ: %p\t%d   t:%d  (cnt:%d)\n",  header, size, type, alccnt);    return header + 1;}static int my_release(void* memory){    alloc_header* header = (alloc_header*) memory - 1;#ifdef GARBAGE    alloc_header* prevmem;    alloc_header* nextmem;    if (memory == 0)	return 0;    if (header->deadbeef != (long) 0xdeadbeef)    {	dbgprintf("FATAL releasing corrupted memory! %p  0x%lx  (%d)\n", header, header->deadbeef, alccnt);	return 0;    }    pthread_mutex_lock(&memmut);    switch(header->type)    {    case AREATYPE_EVENT:	destroy_event(memory);	break;    case AREATYPE_COND:	pthread_cond_destroy((pthread_cond_t*)memory);	break;    case AREATYPE_MUTEX:	pthread_mutex_destroy((pthread_mutex_t*)memory);	break;    case AREATYPE_CRITSECT:	pthread_mutex_destroy(&((struct CRITSECT*)memory)->mutex);	break;    default:	//memset(memory, 0xcc, header->size);	;    }    header->deadbeef = 0;    prevmem = header->prev;    nextmem = header->next;    if (prevmem)	prevmem->next = nextmem;    if (nextmem)	nextmem->prev = prevmem;    if (header == last_alloc)	last_alloc = prevmem;    alccnt--;    if (last_alloc)	pthread_mutex_unlock(&memmut);    else	pthread_mutex_destroy(&memmut);    //if (alccnt < 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;}#endifstatic inline void* my_mreq(int size, int to_zero){    return mreq_private(size, to_zero, AREATYPE_CLIENT);}static int my_size(void* memory){    if(!memory) return 0;    return ((alloc_header*)memory)[-1].size;}static void* my_realloc(void* memory, int size){    void *ans = memory;    int osize;    if (memory == NULL)	return my_mreq(size, 0);    osize = my_size(memory);    if (osize < size)    {	ans = my_mreq(size, 0);	memcpy(ans, memory, osize);	my_release(memory);    }    return ans;}

⌨️ 快捷键说明

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