summaryrefslogtreecommitdiffstats
path: root/loader
diff options
context:
space:
mode:
authorarpi_esp <arpi_esp@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-03-18 01:01:03 +0000
committerarpi_esp <arpi_esp@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-03-18 01:01:03 +0000
commitd71e31d0f702ebf8f872694f6e0f5d579c8378d3 (patch)
treeb8a816661c678a08769b45d34b394b1b5d04f134 /loader
parent52d76c5f328bdb0268d266b21f91aac571b443f6 (diff)
downloadmpv-d71e31d0f702ebf8f872694f6e0f5d579c8378d3.tar.bz2
mpv-d71e31d0f702ebf8f872694f6e0f5d579c8378d3.tar.xz
DLL loader updated from avifile-0.60beta4
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@129 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'loader')
-rw-r--r--loader/driver.c8
-rw-r--r--loader/ext.c11
-rw-r--r--loader/loader.h4
-rw-r--r--loader/module.c135
-rw-r--r--loader/pe_image.c25
-rw-r--r--loader/registry.c12
-rw-r--r--loader/win32.c1578
-rw-r--r--loader/wine/vfw.h4
-rw-r--r--loader/wine/windef.h6
9 files changed, 1302 insertions, 481 deletions
diff --git a/loader/driver.c b/loader/driver.c
index d682bd295c..bc5143d73a 100644
--- a/loader/driver.c
+++ b/loader/driver.c
@@ -13,8 +13,8 @@
#include <wine/vfw.h>
#include <registry.h>
-//#include "com.h"
-//typedef long STDCALL (*GETCLASS) (GUID*, GUID*, void**);
+#include "com.h"
+typedef long STDCALL (*GETCLASS) (GUID*, GUID*, void**);
#ifdef __FreeBSD__
@@ -118,7 +118,7 @@ void DrvClose(HDRVR hdrvr)
}
-char* def_path=WIN32_PATH; // path to codecs
+extern char* def_path; //=WIN32_PATH; // path to codecs
char* win32_codec_name=NULL; // must be set before calling DrvOpen() !!!
HDRVR
@@ -155,7 +155,7 @@ DrvOpen(LPARAM lParam2)
if (!(npDriver->DriverProc = (DRIVERPROC)
GetProcAddress(npDriver->hDriverModule, "DriverProc"))) {
-#if 1
+#if 0
printf("Library %s is not a VfW/ACM valid codec\n", win32_codec_name);
#else
// Try DirectShow...
diff --git a/loader/ext.c b/loader/ext.c
index e978fac0c4..1b27f9bda2 100644
--- a/loader/ext.c
+++ b/loader/ext.c
@@ -11,7 +11,6 @@
#else
#include <stdlib.h>
#endif
-#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
@@ -47,7 +46,6 @@ int __vprintf( const char *format, ... )
va_start(va, format);
vprintf(format, va);
va_end(va);
- fflush(stdout);
#endif
return 0;
}
@@ -67,7 +65,7 @@ void* HeapAlloc(int heap, int flags, int size)
int HeapFree(int heap, int flags, void* mem)
{
- free(mem);
+ if (mem) free(mem);
return 1;
}
@@ -517,9 +515,10 @@ int WideCharToMultiByte(unsigned int codepage, long flags, const short* src,
int i;
if(src==0)
return 0;
- for(i=0; i<srclen; i++)
- printf("%c", src[i]);
- printf("\n");
+ if(srclen==-1){srclen=0; while(src[srclen++]);}
+// for(i=0; i<srclen; i++)
+// printf("%c", src[i]);
+// printf("\n");
if(dest==0)
{
for(i=0; i<srclen; i++)
diff --git a/loader/loader.h b/loader/loader.h
index f94fe0044d..6b758d0217 100644
--- a/loader/loader.h
+++ b/loader/loader.h
@@ -1,7 +1,7 @@
/********************************************************
Win32 binary loader interface
- Copyright 2000 Eugene Smith (divx@euro.ru)
+ Copyright 2000 Eugene Kuznetsov (divx@euro.ru)
Shamelessly stolen from Wine project
*********************************************************/
@@ -279,6 +279,8 @@ MMRESULT WINAPI acmStreamUnprepareHeader(
);
void MSACM_RegisterAllDrivers(void);
+int WINAPI LoadStringA(long instance, long id, void* buf, long size);
+
#ifdef __cplusplus
}
#endif
diff --git a/loader/module.c b/loader/module.c
index 69cba22c93..61a886d025 100644
--- a/loader/module.c
+++ b/loader/module.c
@@ -59,136 +59,6 @@ typedef struct modref_list_t
}
modref_list;
-
-/***********************************************************************
- * LDT_EntryToBytes
- *
- * Convert an ldt_entry structure to the raw bytes of the descriptor.
- */
-/*static void LDT_EntryToBytes( unsigned long *buffer, const struct modify_ldt_ldt_s *content )
-{
- *buffer++ = ((content->base_addr & 0x0000ffff) << 16) |
- (content->limit & 0x0ffff);
- *buffer = (content->base_addr & 0xff000000) |
- ((content->base_addr & 0x00ff0000)>>16) |
- (content->limit & 0xf0000) |
- (content->contents << 10) |
- ((content->read_exec_only == 0) << 9) |
- ((content->seg_32bit != 0) << 22) |
- ((content->limit_in_pages != 0) << 23) |
- 0xf000;
-}
-*/
-
-//
-// funcs:
-//
-// 0 read LDT
-// 1 write old mode
-// 0x11 write
-//
-/*
-static int modify_ldt( int func, struct modify_ldt_ldt_s *ptr,
- unsigned long count )
-{
- int res;
-#ifdef __PIC__
- __asm__ __volatile__( "pushl %%ebx\n\t"
- "movl %2,%%ebx\n\t"
- "int $0x80\n\t"
- "popl %%ebx"
- : "=a" (res)
- : "0" (__NR_modify_ldt),
- "r" (func),
- "c" (ptr),
- "d" (sizeof(struct modify_ldt_ldt_s)*count) );
-#else
- __asm__ __volatile__("int $0x80"
- : "=a" (res)
- : "0" (__NR_modify_ldt),
- "b" (func),
- "c" (ptr),
- "d" (sizeof(struct modify_ldt_ldt_s)*count) );
-#endif
- if (res >= 0) return res;
- errno = -res;
- return -1;
-}
-static int fs_installed=0;
-static char* fs_seg=0;
-static int install_fs()
-{
- struct modify_ldt_ldt_s array;
- int fd;
- int ret;
- void* prev_struct;
-
- if(fs_installed)
- return 0;
-
- fd=open("/dev/zero", O_RDWR);
- fs_seg=mmap((void*)0xbf000000, 0x30000, PROT_READ | PROT_WRITE, MAP_PRIVATE,
- fd, 0);
- if(fs_seg==0)
- {
- printf("ERROR: Couldn't allocate memory for fs segment\n");
- return -1;
- }
- array.base_addr=((int)fs_seg+0xffff) & 0xffff0000;
- array.entry_number=0x1;
- array.limit=array.base_addr+getpagesize()-1;
- array.seg_32bit=1;
- array.read_exec_only=0;
- array.seg_not_present=0;
- array.contents=MODIFY_LDT_CONTENTS_DATA;
- array.limit_in_pages=0;
-#ifdef linux
- ret=modify_ldt(0x1, &array, 1);
- if(ret<0)
- {
- perror("install_fs");
- MESSAGE("Couldn't install fs segment, expect segfault\n");
- }
-#endif
-
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
- {
- long d[2];
-
- LDT_EntryToBytes( d, &array );
- ret = i386_set_ldt(0x1, (union descriptor *)d, 1);
- if (ret < 0)
- {
- perror("install_fs");
- MESSAGE("Did you reconfigure the kernel with \"options USER_LDT\"?\n");
- }
- }
-#endif
- __asm__
- (
- "movl $0xf,%eax\n\t"
-// "pushw %ax\n\t"
- "movw %ax, %fs\n\t"
- );
- prev_struct=malloc(8);
- *(void**)array.base_addr=prev_struct;
- printf("prev_struct: 0x%X\n", prev_struct);
- close(fd);
-
- fs_installed=1;
- return 0;
-};
-static int uninstall_fs()
-{
- printf("Uninstalling FS segment\n");
- if(fs_seg==0)
- return -1;
- munmap(fs_seg, 0x30000);
- fs_installed=0;
- return 0;
-}
-
-*/
//WINE_MODREF *local_wm=NULL;
modref_list* local_wm=NULL;
@@ -200,7 +70,7 @@ WINE_MODREF *MODULE_FindModule(LPCSTR m)
return NULL;
while(strcmp(m, list->wm->filename))
{
-// printf("%s: %x\n", list->wm->filename, list->wm->module);
+ TRACE("%s: %x\n", list->wm->filename, list->wm->module);
list=list->prev;
if(list==NULL)
return NULL;
@@ -514,6 +384,9 @@ WIN_BOOL WINAPI FreeLibrary(HINSTANCE hLibModule)
MODULE_RemoveFromList(wm);
+ /* garbage... */
+ if (local_wm == NULL) my_garbagecollection();
+
return retv;
}
diff --git a/loader/pe_image.c b/loader/pe_image.c
index cc8eef6746..51af59bd0b 100644
--- a/loader/pe_image.c
+++ b/loader/pe_image.c
@@ -670,7 +670,8 @@ HMODULE PE_LoadImage( int handle, LPCSTR filename, WORD *version )
error:
if (unix_handle != -1) close( unix_handle );
- if (load_addr) VirtualFree( (LPVOID)load_addr, 0, MEM_RELEASE );
+ if (load_addr)
+ VirtualFree( (LPVOID)load_addr, 0, MEM_RELEASE );
UnmapViewOfFile( (LPVOID)hModule );
return 0;
}
@@ -870,6 +871,7 @@ void PE_UnloadLibrary(WINE_MODREF *wm)
HeapFree( GetProcessHeap(), 0, wm->filename );
HeapFree( GetProcessHeap(), 0, wm->short_filename );
+ VirtualFree( (LPVOID)wm->module, 0, MEM_RELEASE );
HeapFree( GetProcessHeap(), 0, wm );
}
@@ -884,6 +886,12 @@ void PE_UnloadLibrary(WINE_MODREF *wm)
* DLL_PROCESS_ATTACH. Only new created threads do DLL_THREAD_ATTACH
* (SDK)
*/
+extern void This_Is_Dirty_Hack()
+{
+ void* mem=alloca(0x20000);
+ *(int*)mem=0x1234;
+}
+
WIN_BOOL PE_InitDLL( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
{
WIN_BOOL retv = TRUE;
@@ -900,23 +908,26 @@ WIN_BOOL PE_InitDLL( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
TRACE_(relay)("CallTo32(entryproc=%p,module=%08x,type=%ld,res=%p)\n",
entry, wm->module, type, lpReserved );
- printf("Entering DllMain(");
+
+
+ TRACE("Entering DllMain(");
switch(type)
{
case DLL_PROCESS_DETACH:
- printf("DLL_PROCESS_DETACH) ");
+ TRACE("DLL_PROCESS_DETACH) ");
break;
case DLL_PROCESS_ATTACH:
- printf("DLL_PROCESS_ATTACH) ");
+ TRACE("DLL_PROCESS_ATTACH) ");
break;
case DLL_THREAD_DETACH:
- printf("DLL_THREAD_DETACH) ");
+ TRACE("DLL_THREAD_DETACH) ");
break;
case DLL_THREAD_ATTACH:
- printf("DLL_THREAD_ATTACH) ");
+ TRACE("DLL_THREAD_ATTACH) ");
break;
}
- printf("for %s\n", wm->filename);
+ TRACE("for %s\n", wm->filename);
+ This_Is_Dirty_Hack();
retv = entry( wm->module, type, lpReserved );
}
diff --git a/loader/registry.c b/loader/registry.c
index a8dfaa0e03..d049cbdf7f 100644
--- a/loader/registry.c
+++ b/loader/registry.c
@@ -11,7 +11,8 @@
#include <wine/winerror.h>
#include <registry.h>
-
+//#undef TRACE
+//#define TRACE printf
struct reg_value
{
int type;
@@ -147,7 +148,6 @@ static void save_registry()
static reg_handle_t* find_handle_by_name(const char* name)
{
reg_handle_t* t;
-// printf("REGISTRY: find_handle_by_name(%s)\n",name);
for(t=head; t; t=t->prev)
{
if(!strcmp(t->name, name))
@@ -160,7 +160,6 @@ static reg_handle_t* find_handle_by_name(const char* name)
static struct reg_value* find_value_by_name(const char* name)
{
int i;
-// printf("REGISTRY: find_value_by_name(%s)\n",name);
for(i=0; i<reg_size; i++)
if(!strcmp(regs[i].name, name))
return regs+i;
@@ -169,7 +168,6 @@ static struct reg_value* find_value_by_name(const char* name)
static reg_handle_t* find_handle(int handle)
{
reg_handle_t* t;
-// printf("REGISTRY: find_handle(%d)\n",handle);
for(t=head; t; t=t->prev)
{
if(t->handle==handle)
@@ -263,7 +261,7 @@ struct reg_value* insert_reg_value(int handle, const char* name, int type, const
static void init_registry()
{
-// printf("Initializing registry\n");
+ printf("Initializing registry\n");
open_registry();
insert_handle(HKEY_LOCAL_MACHINE, "HKLM");
insert_handle(HKEY_CURRENT_USER, "HKCU");
@@ -393,11 +391,11 @@ long RegCreateKeyExA(long key, const char* name, long reserved,
{
int qw=45708;
v=insert_reg_value(key, name, DIR, &qw, 4);
- *status=REG_CREATED_NEW_KEY;
+ if (status) *status=REG_CREATED_NEW_KEY;
// return 0;
}
else
- *status=REG_OPENED_EXISTING_KEY;
+ if (status) *status=REG_OPENED_EXISTING_KEY;
t=insert_handle(generate_handle(), fullname);
*newkey=t->handle;
diff --git a/loader/win32.c b/loader/win32.c
index 06b499afd0..643da26c1e 100644
--- a/loader/win32.c
+++ b/loader/win32.c
@@ -5,6 +5,9 @@
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.
************************************************************/
@@ -13,12 +16,15 @@
#include "win32.h"
#include <stdio.h>
#include <pthread.h>
+#include <errno.h>
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#else
#include <stdlib.h>
#endif
#include <time.h>
+#include <unistd.h>
+#include <fcntl.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/timeb.h>
@@ -32,8 +38,26 @@
#include <registry.h>
#include <loader.h>
-#ifdef USE_TSC
-static unsigned int localcount()
+#include <com.h>
+
+char* def_path=WIN32_PATH;
+
+static void do_cpuid(unsigned int *regs)
+{
+ unsigned int ax;
+ ax=1;
+ __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"
@@ -42,7 +66,7 @@ static unsigned int localcount()
:"edx");
return a;
}
-static void longcount(long long* z)
+static void c_longcount_tsc(long long* z)
{
__asm__ __volatile__(
"pushl %%ebx\n\t"
@@ -53,10 +77,9 @@ static void longcount(long long* z)
"popl %%ebx\n\t"
::"a"(z));
}
-#else
#include <sys/time.h>
#include <unistd.h>
-static unsigned int localcount()
+static unsigned int c_localcount_notsc()
{
struct timeval tv;
unsigned limit=~0;
@@ -64,7 +87,7 @@ static unsigned int localcount()
gettimeofday(&tv, 0);
return limit*tv.tv_usec;
}
-static void longcount(long long* z)
+static void c_longcount_notsc(long long* z)
{
struct timeval tv;
unsigned long long result;
@@ -77,27 +100,62 @@ static void longcount(long long* z)
result+=limit*tv.tv_usec;
*z=result;
}
-#endif
+static unsigned int localcount_stub();
+static void longcount_stub(long long*);
+static unsigned int (*localcount)()=localcount_stub;
+static void (*longcount)(long long*)=longcount_stub;
-void dbgprintf(char* fmt, ...)
+static unsigned int localcount_stub()
{
-#ifdef DETAILED_OUT
-#if 1
- va_list va;
- va_start(va, fmt);
- vprintf(fmt, va);
- va_end(va);
-#else
- va_list va;
- FILE* f;
- va_start(va, fmt);
- f=fopen("./log", "a");
- if(f==0)return;
- vfprintf(f, fmt, va);
- fsync(f);
- fclose(f);
-#endif
-#endif
+ unsigned int regs[4];
+ do_cpuid(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(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);
+}
+
+int LOADER_DEBUG=0;
+inline void dbgprintf(char* fmt, ...)
+{
+ if(LOADER_DEBUG)
+ {
+ FILE* f;
+ va_list va;
+ va_start(va, fmt);
+ f=fopen("./log", "a");
+ vprintf(fmt, va);
+ if(f)
+ {
+ vfprintf(f, fmt, va);
+ fsync(fileno(f));
+ fclose(f);
+ }
+ va_end(va);
+ }
}
char export_names[500][30]={
"name1",
@@ -182,6 +240,19 @@ int my_release(char* memory)
}
#else
+#define GARBAGE
+#ifdef GARBAGE
+struct alc_list_t;
+typedef struct alc_list_t {
+ int size;
+ int addr;
+ struct alc_list_t *prev;
+ struct alc_list_t *next;
+}alc_list;
+static alc_list *alclist=NULL;
+static alccnt=0;
+#endif
+
void* my_mreq(int size, int to_zero)
{
void* answer;
@@ -190,11 +261,56 @@ void* my_mreq(int size, int to_zero)
else
answer=malloc(size+4);
*(int*)answer=size;
- return (int*)answer+1;
+#ifdef GARBAGE
+ if (alclist==NULL) {
+ alclist=malloc(sizeof(alc_list));
+ alclist->prev=alclist->next=NULL;
+ }
+ else {
+ alclist->next=malloc(sizeof(alc_list));
+ alclist->next->prev=alclist;
+ alclist->next->next=NULL;
+ alclist=alclist->next;
+ }
+ alclist->size=size;
+ alclist->addr=answer;
+ alccnt++;
+#endif
+ return (int*)((int)answer+sizeof(int));
}
int my_release(char* memory)
{
+#ifdef GARBAGE
+ alc_list* pp;
if(memory==0)return 0;
+ if(alclist!=NULL)
+ {
+ pp=alclist;
+ if ((pp->prev==NULL) && (pp->next == NULL)){
+ free(pp);
+ alclist=NULL;
+ }
+ else {
+ for(;pp;pp=pp->prev) {
+ if (pp->addr == memory-4) {
+ if (pp->prev)
+ pp->prev->next=pp->next;
+ if (pp->next)
+ pp->next->prev=pp->prev;
+ if (pp == alclist)
+ alclist=pp->prev;
+ free(pp);
+ alccnt--;
+ break;
+ }
+ }
+ if (pp == NULL) {
+ printf("Not Found %x %d\n",memory-4,alccnt);
+ return 0;
+ }
+ }
+ }
+#endif
free(memory-4);
return 0;
}
@@ -215,39 +331,44 @@ int WINAPI ext_unknown()
}
int WINAPI expIsBadWritePtr(void* ptr, unsigned int count)
{
- dbgprintf("IsBadWritePtr(%x, %x)\n", ptr, count);
+ int result;
if(count==0)
- return 0;
+ result=0;
+ else
if(ptr==0)
- return 1;
- return 0;
+ result=1;
+ else
+ result=0;
+ dbgprintf("IsBadWritePtr(0x%x, 0x%x) => %d\n", ptr, count, result);
+ return result;
}
int WINAPI expIsBadReadPtr(void* ptr, unsigned int count)
{
- dbgprintf("IsBadReadPtr(%x, %x)\n", ptr, count);
+ int result;
if(count==0)
- return 0;
+ result=0;
+ else
if(ptr==0)
- return 1;
- return 0;
+ result=1;
+ else
+ result=0;
+ 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(%x)\n", size);
+ dbgprintf("malloc(0x%x) => 0x%x\n", size,result);
if(result==0)
- {
- dbgprintf("returns 0\n");
printf("WARNING: malloc() failed\n");
- }
return result;
}
void CDECL expfree(void* mem)
{
// return free(mem);
- dbgprintf("free(%x)\n", mem);
+ dbgprintf("free(0x%x)\n", mem);
my_release(mem);
}
void* CDECL expnew(int size)
@@ -256,29 +377,27 @@ void* CDECL expnew(int size)
// printf("%08x %08x %08x %08x\n",
// size, *(1+(int*)&size),
// *(2+(int*)&size),*(3+(int*)&size));
- void* result=expmalloc(size);
- dbgprintf("new(%x)\n", size);
+ void* result=my_mreq(size,0);
+ dbgprintf("new(0x%x) => 0x%x\n", size, result);
if(result==0)
- {
- dbgprintf("returns 0\n");
- printf("WARNING: malloc() failed\n");
- }
+ printf("WARNING: new() failed\n");
return result;
}
int CDECL expdelete(void* memory)
{
- dbgprintf("delete(%x)\n", memory);
- expfree(memory);
+ dbgprintf("delete(0x%x)\n", memory);
+ my_release(memory);
return 0;
}
int WINAPI expDisableThreadLibraryCalls(int module)
{
- dbgprintf("DisableThreadLibraryCalls(%x)\n", 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;
}
@@ -291,19 +410,35 @@ typedef struct {
void* WINAPI expGetDriverModuleHandle(DRVR* pdrv)
{
- dbgprintf("GetDriverModuleHandle(%x)\n", pdrv);
- return pdrv->hDriverModule;
+ void* result;
+ if (pdrv==NULL) result=NULL;
+ result=pdrv->hDriverModule;
+ dbgprintf("GetDriverModuleHandle(0x%x) => 0x%x\n", pdrv, result);
+ return result;
}
void* WINAPI expGetModuleHandleA(const char* name)
{
WINE_MODREF* wm;
- dbgprintf("GetModuleHandleA(%s)\n", name);
- if(!name)return 0;
- wm=MODULE_FindModule(name);
- if(wm==0)return 0;
- return (void*)(wm->module);
+ void* result;
+ if(!name)
+ result=0;
+ else
+ {
+ wm=MODULE_FindModule(name);
+ if(wm==0)result=0;
+ else
+ result=(void*)(wm->module);
+ }
+ if(!result)
+ {
+ if(strcasecmp(name, "kernel32")==0)
+ result=0x120;
+ }
+ dbgprintf("GetModuleHandleA('%s') => 0x%x\n", name, result);
+ return result;
}
+
struct th_list_t;
typedef struct th_list_t{
int id;
@@ -322,13 +457,11 @@ void* WINAPI expCreateThread(void* pSecAttr, long dwStackSize, void* lpStartAddr
pthread_t *pth;
// printf("CreateThread:");
pth=my_mreq(sizeof(pthread_t), 0);
- dbgprintf("pthread_create\n");
pthread_create(pth, NULL, (void*(*)(void*))lpStartAddress, lpParameter);
if(dwFlags)
- dbgprintf( "WARNING: CreateThread flags not supported\n");
+ printf( "WARNING: CreateThread flags not supported\n");
if(dwThreadId)
*dwThreadId=(long)pth;
- dbgprintf( "Created thread %08X\n", pth);
if(list==NULL)
{
list=my_mreq(sizeof(th_list), 1);
@@ -342,6 +475,8 @@ void* WINAPI expCreateThread(void* pSecAttr, long dwStackSize, void* lpStartAddr
list=list->next;
}
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);
return pth;
}
@@ -349,8 +484,13 @@ struct mutex_list_t;
struct mutex_list_t
{
+ char type;
pthread_mutex_t *pm;
+ pthread_cond_t *pc;
+ char state;
+ char reset;
char name[64];
+ int semaphore;
struct mutex_list_t* next;
struct mutex_list_t* prev;
};
@@ -359,21 +499,26 @@ static mutex_list* mlist=NULL;
void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset,
char bInitialState, const char* name)
{
-#warning ManualReset
pthread_mutex_t *pm;
- dbgprintf("CreateEvent\n");
+ pthread_cond_t *pc;
if(mlist!=NULL)
{
mutex_list* pp=mlist;
if(name!=NULL)
do
{
- if(strcmp(pp->name, name)==0)
+ 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);
return pp->pm;
+ }
}while(pp=pp->prev);
}
pm=my_mreq(sizeof(pthread_mutex_t), 0);
pthread_mutex_init(pm, NULL);
+ pc=my_mreq(sizeof(pthread_cond_t), 0);
+ pthread_cond_init(pc, NULL);
if(mlist==NULL)
{
mlist=my_mreq(sizeof(mutex_list), 00);
@@ -382,53 +527,158 @@ void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset,
else
{
mlist->next=my_mreq(sizeof(mutex_list), 00);
- mlist->next->prev=mlist->next;
+ mlist->next->prev=mlist;
mlist->next->next=NULL;
mlist=mlist->next;
}
+ mlist->type=0; /* Type Event */
mlist->pm=pm;
+ mlist->pc=pc;
+ mlist->state=bInitialState;
+ mlist->reset=bManualReset;
if(name!=NULL)
strncpy(mlist->name, name, 64);
else
mlist->name[0]=0;
if(pm==NULL)
dbgprintf("ERROR::: CreateEventA failure\n");
+/*
if(bInitialState)
pthread_mutex_lock(pm);
- return pm;
+*/
+ if(name)
+ 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);
+ return mlist;
}
void* WINAPI expSetEvent(void* event)
{
- dbgprintf("Trying to lock %X\n", event);
- pthread_mutex_lock(event);
+ mutex_list *ml = (mutex_list *)event;
+ dbgprintf("SetEvent(%x) => 0x1\n", event);
+ pthread_mutex_lock(ml->pm);
+ if (ml->state == 0) {
+ ml->state = 1;
+ pthread_cond_signal(ml->pc);
+ }
+ pthread_mutex_unlock(ml->pm);
+
+ return (void *)1;
}
void* WINAPI expResetEvent(void* event)
{
- dbgprintf("Unlocking %X\n", event);
- pthread_mutex_unlock(event);
+ mutex_list *ml = (mutex_list *)event;
+ dbgprintf("ResetEvent(0x%x) => 0x1\n", event);
+ pthread_mutex_lock(ml->pm);
+ ml->state = 0;
+ pthread_mutex_unlock(ml->pm);
+
+ return (void *)1;
}
void* WINAPI expWaitForSingleObject(void* object, int duration)
{
-#warning not sure
- dbgprintf("WaitForSingleObject: duration %d\n", duration);
- pthread_mutex_lock(object);
- pthread_mutex_unlock(object);
+ mutex_list *ml = (mutex_list *)object;
+ int ret;
+ mutex_list* pp=mlist;
+// dbgprintf("WaitForSingleObject(0x%x, duration %d) =>\n",object, duration);
+ do {
+ if (pp == NULL) dbgprintf("WaitForSingleObject: NotFound\n");
+ if((pp->pm, mlist->pm)==0)
+ break;;
+ }while(pp=pp->prev);
+
+
+ pthread_mutex_lock(ml->pm);
+
+ switch(ml->type) {
+ case 0: /* Event */
+ if (duration == 0) { /* Check Only */
+ 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 (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;
+ }
+ 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--;
+ }
+ break;
+ }
+ pthread_mutex_unlock(ml->pm);
+
+ dbgprintf("WaitForSingleObject(0x%x, %d): 0x%x => 0x%x \n",object,duration,ml,ret);
+ return (void *)ret;
}
static BYTE PF[64] = {0,};
+WIN_BOOL WINAPI expIsProcessorFeaturePresent(DWORD v)
+{
+ WIN_BOOL result;
+ if(v>63)result=0;
+ else result=PF[v];
+ dbgprintf("IsProcessorFeaturePresent(0x%x) => 0x%x\n", v, result);
+ return result;
+}
+
+static void DumpSystemInfo(const SYSTEM_INFO* si)
+{
+ dbgprintf(" Processor architecture %d\n", si->u.s.wProcessorArchitecture);
+ dbgprintf(" Page size: %d\n", si->dwPageSize);
+ dbgprintf(" Minimum app address: %d\n", si->lpMinimumApplicationAddress);
+ dbgprintf(" Maximum app address: %d\n", si->lpMaximumApplicationAddress);
+ dbgprintf(" Active processor mask: 0x%x\n", si->dwActiveProcessorMask);
+ dbgprintf(" Number of processors: %d\n", si->dwNumberOfProcessors);
+ dbgprintf(" Processor type: 0x%x\n", si->dwProcessorType);
+ dbgprintf(" Allocation granularity: 0x%x\n", si->dwAllocationGranularity);
+ dbgprintf(" Processor level: 0x%x\n", si->wProcessorLevel);
+ dbgprintf(" Processor revision: 0x%x\n", si->wProcessorRevision);
+}
+
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];
HKEY xhkey=0,hkey;
- dbgprintf("GetSystemInfo()\n");
+ dbgprintf("GetSystemInfo(0x%d) =>\n");
if (cache) {
memcpy(si,&cachedsi,sizeof(*si));
+ DumpSystemInfo(si);
return;
}
memset(PF,0,sizeof(PF));
@@ -437,22 +687,22 @@ void WINAPI expGetSystemInfo(SYSTEM_INFO* si)
cachedsi.dwPageSize = getpagesize();
/* FIXME: better values for the two entries below... */
- cachedsi.lpMinimumApplicationAddress = (void *)0x40000000;
+ cachedsi.lpMinimumApplicationAddress = (void *)0x00000000;
cachedsi.lpMaximumApplicationAddress = (void *)0x7FFFFFFF;
cachedsi.dwActiveProcessorMask = 1;
cachedsi.dwNumberOfProcessors = 1;
cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
cachedsi.dwAllocationGranularity = 0x10000;
- cachedsi.wProcessorLevel = 3; /* pentium */
- cachedsi.wProcessorRevision = 0;
+ cachedsi.wProcessorLevel = 5; /* pentium */
+ cachedsi.wProcessorRevision = 0x0101;
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__NetBSD__)
cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
cachedsi.wProcessorLevel= 5;
PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
-#ifdef MMX
- PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
-#endif
+ do_cpuid(regs);
+ if (regs[3] & 0x00800000)
+ PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
cachedsi.dwNumberOfProcessors=1;
#else
{
@@ -559,8 +809,10 @@ void WINAPI expGetSystemInfo(SYSTEM_INFO* si)
if (sscanf(value,"%d",&x))
cachedsi.wProcessorRevision = x;
}
- if ( (!lstrncmpiA(line,"flags",strlen("flags"))) ||
- (!lstrncmpiA(line,"features",strlen("features"))) ) {
+ 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"))
@@ -569,70 +821,89 @@ void WINAPI expGetSystemInfo(SYSTEM_INFO* si)
}
}
fclose (f);
+/*
+ * ad hoc fix for smp machines.
+ * some problems on WaitForSingleObject,CreateEvent,SetEvent
+ * CreateThread ...etc..
+ *
+ */
+ cachedsi.dwNumberOfProcessors=1;
}
#endif /* __FreeBSD__ */
memcpy(si,&cachedsi,sizeof(*si));
+ DumpSystemInfo(si);
}
long WINAPI expGetVersion()
{
- return 0xC0000A04;//Windows 98
+ dbgprintf("GetVersion() => 0xC0000004\n");
+ return 0xC0000004;//Windows 95
}