summaryrefslogtreecommitdiffstats
path: root/loader/win32.c
diff options
context:
space:
mode:
Diffstat (limited to 'loader/win32.c')
-rw-r--r--loader/win32.c2903
1 files changed, 1574 insertions, 1329 deletions
diff --git a/loader/win32.c b/loader/win32.c
index de455eecb8..780a5d86a2 100644
--- a/loader/win32.c
+++ b/loader/win32.c
@@ -1,13 +1,13 @@
/***********************************************************
- Win32 emulation code. Functions that emulate
- responses from corresponding Win32 API calls.
- Since we are not going to be able to load
- virtually any DLL, we can only implement this
- much, adding needed functions with each new codec.
+Win32 emulation code. Functions that emulate
+responses from corresponding Win32 API calls.
+Since we are not going to be able to load
+virtually any DLL, we can only implement this
+much, adding needed functions with each new codec.
- Basic principle of implementation: it's not good
- for DLL to know too much about its environment.
+Basic principle of implementation: it's not good
+for DLL to know too much about its environment.
************************************************************/
@@ -53,12 +53,12 @@ int vsscanf( const char *str, const char *format, va_list ap);
/* system has no vsscanf. try to provide one */
static int vsscanf( const char *str, const char *format, va_list ap)
{
- long p1 = va_arg(ap, long);
- long p2 = va_arg(ap, long);
- long p3 = va_arg(ap, long);
- long p4 = va_arg(ap, long);
- long p5 = va_arg(ap, long);
- return sscanf(str, format, p1, p2, p3, p4, p5);
+ long p1 = va_arg(ap, long);
+ long p2 = va_arg(ap, long);
+ long p3 = va_arg(ap, long);
+ long p4 = va_arg(ap, long);
+ long p5 = va_arg(ap, long);
+ return sscanf(str, format, p1, p2, p3, p4, p5);
}
#endif
@@ -66,37 +66,43 @@ char* def_path = WIN32_PATH;
static void do_cpuid(unsigned int ax, unsigned int *regs)
{
- __asm__ __volatile__(
- "pushl %%ebx; pushl %%ecx; pushl %%edx;"
- ".byte 0x0f, 0xa2;"
- "movl %%eax, (%2);"
- "movl %%ebx, 4(%2);"
- "movl %%ecx, 8(%2);"
- "movl %%edx, 12(%2);"
- "popl %%edx; popl %%ecx; popl %%ebx;"
- : "=a" (ax)
- : "0" (ax), "S" (regs)
+ __asm__ __volatile__
+ (
+ "pushl %%ebx; pushl %%ecx; pushl %%edx;"
+ ".byte 0x0f, 0xa2;"
+ "movl %%eax, (%2);"
+ "movl %%ebx, 4(%2);"
+ "movl %%ecx, 8(%2);"
+ "movl %%edx, 12(%2);"
+ "popl %%edx; popl %%ecx; popl %%ebx;"
+ : "=a" (ax)
+ : "0" (ax), "S" (regs)
);
}
static unsigned int c_localcount_tsc()
{
int a;
- __asm__ __volatile__("rdtsc\n\t"
- :"=a"(a)
- :
- :"edx");
+ __asm__ __volatile__
+ (
+ "rdtsc\n\t"
+ :"=a"(a)
+ :
+ :"edx"
+ );
return a;
}
static void c_longcount_tsc(long long* z)
{
- __asm__ __volatile__(
- "pushl %%ebx\n\t"
- "movl %%eax, %%ebx\n\t"
- "rdtsc\n\t"
- "movl %%eax, 0(%%ebx)\n\t"
- "movl %%edx, 4(%%ebx)\n\t"
- "popl %%ebx\n\t"
- ::"a"(z));
+ __asm__ __volatile__
+ (
+ "pushl %%ebx\n\t"
+ "movl %%eax, %%ebx\n\t"
+ "rdtsc\n\t"
+ "movl %%eax, 0(%%ebx)\n\t"
+ "movl %%edx, 4(%%ebx)\n\t"
+ "popl %%ebx\n\t"
+ ::"a"(z)
+ );
}
static unsigned int c_localcount_notsc()
{
@@ -137,7 +143,7 @@ static unsigned int localcount_stub(void)
}
else
{
- localcount=c_localcount_notsc;
+ localcount=c_localcount_notsc;
longcount=c_longcount_notsc;
}
return localcount();
@@ -153,7 +159,7 @@ static void longcount_stub(long long* z)
}
else
{
- localcount=c_localcount_notsc;
+ localcount=c_localcount_notsc;
longcount=c_longcount_notsc;
}
longcount(z);
@@ -168,19 +174,20 @@ static inline void dbgprintf(char* fmt, ...)
{
FILE* f;
va_list va;
- va_start(va, fmt);
+ va_start(va, fmt);
f=fopen("./log", "a");
vprintf(fmt, va);
- if(f)
+ fflush(stdout);
+ if(f)
{
vfprintf(f, fmt, va);
fsync(fileno(f));
- fclose(f);
+ fclose(f);
}
va_end(va);
}
#endif
-#ifdef USE_WIN32DLL
+#ifdef MPLAYER
#include "../mp_msg.h"
{
char buf[1024];
@@ -195,10 +202,10 @@ static inline void dbgprintf(char* fmt, ...)
}
-char export_names[500][30]={
-"name1",
-//"name2",
-//"name3"
+char export_names[300][32]={
+ "name1",
+ //"name2",
+ //"name3"
};
//#define min(x,y) ((x)<(y)?(x):(y))
@@ -235,8 +242,8 @@ static void test_heap(void)
}
for(;offset<min(offset+1000, 20000000); offset++)
if(heap[offset]!=0xCC)
- {
- printf("Free heap corruption at address %d\n", offset);
+ {
+ printf("Free heap corruption at address %d\n", offset);
}
}
#undef MEMORY_DEBUG
@@ -248,7 +255,7 @@ void* my_mreq(int size, int to_zero)
static int test=0;
test++;
if(test%10==0)printf("Memory: %d bytes allocated\n", heap_counter);
-// test_heap();
+ // test_heap();
if(heap==NULL)
{
heap=malloc(20000000);
@@ -270,7 +277,7 @@ void* my_mreq(int size, int to_zero)
heap_counter+=4;
printf("Allocated %d bytes of memory: sys %d, user %d-%d\n", size, heap_counter-8, heap_counter, heap_counter+size);
if(to_zero)
- memset(heap+heap_counter, 0, size);
+ memset(heap+heap_counter, 0, size);
else
memset(heap+heap_counter, 0xcc, size); // make crash reproducable
heap_counter+=size;
@@ -278,7 +285,7 @@ void* my_mreq(int size, int to_zero)
}
int my_release(char* memory)
{
-// test_heap();
+ // test_heap();
if(memory==NULL)
{
printf("ERROR: free(0)\n");
@@ -290,7 +297,7 @@ int my_release(char* memory)
return 0;
}
printf("Freed %d bytes of memory\n", *(int*)(memory-4));
-// memset(memory-8, *(int*)(memory-4), 0xCC);
+ // memset(memory-8, *(int*)(memory-4), 0xCC);
return 0;
}
@@ -299,7 +306,7 @@ int my_release(char* memory)
typedef struct alloc_header_t alloc_header;
struct alloc_header_t
{
-// let's keep allocated data 16 byte aligned
+ // let's keep allocated data 16 byte aligned
alloc_header* prev;
alloc_header* next;
long deadbeef;
@@ -332,11 +339,12 @@ struct CRITSECT
void* mreq_private(int size, int to_zero, int type);
void* mreq_private(int size, int to_zero, int type)
{
- alloc_header* header;
+ int nsize = size + sizeof(alloc_header);
+ alloc_header* header = malloc(nsize);
+ if (!header)
+ return 0;
if (to_zero)
- header=calloc(size + sizeof(alloc_header), 1);
- else
- header=malloc(size + sizeof(alloc_header));
+ memset(header, 0, nsize);
#ifdef GARBAGE
if (!last_alloc)
{
@@ -345,7 +353,7 @@ void* mreq_private(int size, int to_zero, int type)
}
else
{
- pthread_mutex_lock(&memmut);
+ pthread_mutex_lock(&memmut);
last_alloc->next = header; /* set next */
}
@@ -363,12 +371,6 @@ void* mreq_private(int size, int to_zero, int type)
return header + 1;
}
-void* my_mreq(int size, int to_zero)
-{
- return mreq_private(size, to_zero, AREATYPE_CLIENT);
-}
-
-
int my_release(void* memory)
{
alloc_header* header = (alloc_header*) memory - 1;
@@ -405,6 +407,7 @@ int my_release(void* memory)
//memset(memory, 0xcc, header->size);
}
+ header->deadbeef = 0;
prevmem = header->prev;
nextmem = header->next;
@@ -422,23 +425,29 @@ int my_release(void* memory)
pthread_mutex_unlock(&memmut);
else
pthread_mutex_destroy(&memmut);
-
+
//if (alccnt < 40000) printf("MY_RELEASE: %p\t%ld (%d)\n", header, header->size, alccnt);
#else
if (memory == 0)
return 0;
#endif
+ //memset(header + 1, 0xcc, header->size);
free(header);
return 0;
}
#endif
+inline void* my_mreq(int size, int to_zero)
+{
+ return mreq_private(size, to_zero, AREATYPE_CLIENT);
+}
+
static inline int my_size(void* memory)
{
return ((alloc_header*)memory)[-1].size;
}
-void* my_realloc(void* memory, int size)
+static void* my_realloc(void* memory, int size)
{
void *ans = memory;
int osize = my_size(memory);
@@ -453,131 +462,78 @@ void* my_realloc(void* memory, int size)
return ans;
}
-extern int unk_exp1;
-char extcode[20000];// place for 200 unresolved exports
-int pos=0;
+/*
+ *
+ * WINE API - native implementation for several win32 libraries
+ *
+ */
-int WINAPI ext_unknown()
+static int WINAPI ext_unknown()
{
printf("Unknown func called\n");
return 0;
}
-int WINAPI expIsBadWritePtr(void* ptr, unsigned int count)
+
+static int WINAPI expIsBadWritePtr(void* ptr, unsigned int count)
{
- int result;
- if(count==0)
- result=0;
- else
- if(ptr==0)
- result=1;
- else
- result=0;
+ int result = (count == 0 || ptr != 0) ? 0 : 1;
dbgprintf("IsBadWritePtr(0x%x, 0x%x) => %d\n", ptr, count, result);
return result;
}
-int WINAPI expIsBadReadPtr(void* ptr, unsigned int count)
+static int WINAPI expIsBadReadPtr(void* ptr, unsigned int count)
{
- int result;
- if(count==0)
- result=0;
- else
- if(ptr==0)
- result=1;
- else
- result=0;
+ int result = (count == 0 || ptr != 0) ? 0 : 1;
dbgprintf("IsBadReadPtr(0x%x, 0x%x) => %d\n", ptr, count, result);
return result;
}
-void* CDECL expmalloc(int size)
-{
-//printf("malloc");
-// return malloc(size);
- void* result=my_mreq(size,0);
- dbgprintf("malloc(0x%x) => 0x%x\n", size,result);
- if(result==0)
- printf("WARNING: malloc() failed\n");
- return result;
-}
-void CDECL expfree(void* mem)
-{
-// return free(mem);
- dbgprintf("free(0x%x)\n", mem);
- my_release(mem);
-}
-void* CDECL expnew(int size)
-{
-// printf("NEW:: Call from address %08x\n STACK DUMP:\n", *(-1+(int*)&size));
-// printf("%08x %08x %08x %08x\n",
-// size, *(1+(int*)&size),
- // *(2+(int*)&size),*(3+(int*)&size));
- void* result = 0;
- assert(size >= 0);
-
- result=my_mreq(size,0);
- dbgprintf("new(0x%x) => 0x%x\n", size, result);
- if (result==0)
- printf("WARNING: new() failed\n");
- return result;
-
-}
-int CDECL expdelete(void* memory)
-{
- dbgprintf("delete(0x%x)\n", memory);
- my_release(memory);
- return 0;
-}
-int WINAPI expDisableThreadLibraryCalls(int module)
+static int WINAPI expDisableThreadLibraryCalls(int module)
{
dbgprintf("DisableThreadLibraryCalls(0x%x) => 0\n", module);
return 0;
}
-int CDECL exp_initterm(int v1, int v2)
-{
- dbgprintf("_initterm(0x%x, 0x%x) => 0\n", v1, v2);
- return 0;
-}
-HMODULE WINAPI expGetDriverModuleHandle(DRVR* pdrv)
+static HMODULE WINAPI expGetDriverModuleHandle(DRVR* pdrv)
{
HMODULE result;
if (pdrv==NULL)
result=0;
else
- result=pdrv->hDriverModule;
+ result=pdrv->hDriverModule;
dbgprintf("GetDriverModuleHandle(%p) => %p\n", pdrv, result);
return result;
}
#define MODULE_HANDLE_kernel32 ((HMODULE)0x120)
-HMODULE WINAPI expGetModuleHandleA(const char* name)
+static HMODULE WINAPI expGetModuleHandleA(const char* name)
{
- WINE_MODREF* wm;
- HMODULE result;
- if(!name)
- result=0;
+ WINE_MODREF* wm;
+ HMODULE result;
+ if(!name)
+ result=0;
+ else
+ {
+ wm=MODULE_FindModule(name);
+ if(wm==0)result=0;
else
- {
- wm=MODULE_FindModule(name);
- if(wm==0)result=0;
- else
- result=(HMODULE)(wm->module);
- }
- if(!result)
- {
- if(strcasecmp(name, "kernel32")==0)
- result=MODULE_HANDLE_kernel32;
- }
- dbgprintf("GetModuleHandleA('%s') => 0x%x\n", name, result);
- return result;
+ result=(HMODULE)(wm->module);
+ }
+ if(!result)
+ {
+ if(strcasecmp(name, "kernel32")==0)
+ result=MODULE_HANDLE_kernel32;
+ }
+ dbgprintf("GetModuleHandleA('%s') => 0x%x\n", name, result);
+ return result;
}
-void* WINAPI expCreateThread(void* pSecAttr, long dwStackSize, void* lpStartAddress,
- void* lpParameter, long dwFlags, long* dwThreadId)
+static void* WINAPI expCreateThread(void* pSecAttr, long dwStackSize,
+ void* lpStartAddress, void* lpParameter,
+ long dwFlags, long* dwThreadId)
{
pthread_t *pth;
-// printf("CreateThread:");
+ // printf("CreateThread:");
pth=my_mreq(sizeof(pthread_t), 0);
pthread_create(pth, NULL, (void*(*)(void*))lpStartAddress, lpParameter);
if(dwFlags)
@@ -598,7 +554,7 @@ void* WINAPI expCreateThread(void* pSecAttr, long dwStackSize, void* lpStartAddr
}
list->thread=pth;
dbgprintf("CreateThread(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x) => 0x%x\n",
- pSecAttr, dwStackSize, lpStartAddress, lpParameter, dwFlags, dwThreadId, pth);
+ pSecAttr, dwStackSize, lpStartAddress, lpParameter, dwFlags, dwThreadId, pth);
return pth;
}
@@ -622,7 +578,7 @@ static mutex_list* mlist=NULL;
void destroy_event(void* event)
{
mutex_list* pp=mlist;
-// printf("garbage collector: destroy_event(%x)\n", event);
+ // printf("garbage collector: destroy_event(%x)\n", event);
while(pp)
{
if(pp==(mutex_list*)event)
@@ -633,46 +589,46 @@ void destroy_event(void* event)
pp->prev->next=pp->next;
if(mlist==(mutex_list*)event)
mlist=mlist->prev;
-/*
- pp=mlist;
- while(pp)
- {
- printf("%x => ", pp);
- pp=pp->prev;
- }
- printf("0\n");
-*/
+ /*
+ pp=mlist;
+ while(pp)
+ {
+ printf("%x => ", pp);
+ pp=pp->prev;
+ }
+ printf("0\n");
+ */
return;
}
pp=pp->prev;
}
}
-void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset,
- char bInitialState, const char* name)
+static void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset,
+ char bInitialState, const char* name)
{
pthread_mutex_t *pm;
pthread_cond_t *pc;
-/*
- mutex_list* pp;
- pp=mlist;
- while(pp)
- {
- printf("%x => ", pp);
- pp=pp->prev;
- }
- printf("0\n");
-*/
+ /*
+ mutex_list* pp;
+ pp=mlist;
+ while(pp)
+ {
+ printf("%x => ", pp);
+ pp=pp->prev;
+ }
+ printf("0\n");
+ */
if(mlist!=NULL)
{
mutex_list* pp=mlist;
if(name!=NULL)
- do
+ do
{
if((strcmp(pp->name, name)==0) && (pp->type==0))
{
dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, 0x%x='%s') => 0x%x\n",
- pSecAttr, bManualReset, bInitialState, name, name, pp->pm);
+ pSecAttr, bManualReset, bInitialState, name, name, pp->pm);
return pp->pm;
}
}while((pp=pp->prev) != NULL);
@@ -699,25 +655,25 @@ void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset,
mlist->state=bInitialState;
mlist->reset=bManualReset;
if(name)
- strncpy(mlist->name, name, 127);
+ strncpy(mlist->name, name, 127);
else
mlist->name[0]=0;
if(pm==NULL)
dbgprintf("ERROR::: CreateEventA failure\n");
-/*
- if(bInitialState)
- pthread_mutex_lock(pm);
-*/
+ /*
+ if(bInitialState)
+ pthread_mutex_lock(pm);
+ */
if(name)
- dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, 0x%x='%s') => 0x%x\n",
- pSecAttr, bManualReset, bInitialState, name, name, mlist);
+ dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, 0x%x='%s') => 0x%x\n",
+ pSecAttr, bManualReset, bInitialState, name, name, mlist);
else
- dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, NULL) => 0x%x\n",
- pSecAttr, bManualReset, bInitialState, mlist);
+ dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, NULL) => 0x%x\n",
+ pSecAttr, bManualReset, bInitialState, mlist);
return mlist;
}
-void* WINAPI expSetEvent(void* event)
+static void* WINAPI expSetEvent(void* event)
{
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();
+
+ /* 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;
- 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;
+#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 WaitForSingleO