aboutsummaryrefslogtreecommitdiffhomepage
path: root/loader
diff options
context:
space:
mode:
authorGravatar arpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-11-26 01:17:24 +0000
committerGravatar arpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-11-26 01:17:24 +0000
commit7428fbd444aa3d771e813b881d9c560130e4e9be (patch)
tree691680845617a9e62a22608fdac34c07cd538f3d /loader
parent025117922c684ae081ae5b661fd62ec685343e21 (diff)
avifile sync again... :(
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@3135 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'loader')
-rw-r--r--loader/ext.c21
-rw-r--r--loader/registry.c110
-rw-r--r--loader/registry.h2
-rw-r--r--loader/win32.c84
4 files changed, 134 insertions, 83 deletions
diff --git a/loader/ext.c b/loader/ext.c
index d542ba687c..ff69e0818f 100644
--- a/loader/ext.c
+++ b/loader/ext.c
@@ -450,7 +450,7 @@ LPVOID WINAPI VirtualAlloc(LPVOID address, DWORD size, DWORD type, DWORD protec
void* answer;
int fd=open("/dev/zero", O_RDWR);
size=(size+0xffff)&(~0xffff);
-// printf("VirtualAlloc(0x%08X, %d)\n", address
+ //printf("VirtualAlloc(0x%08X, %d)\n", address, size);
if(address!=0)
{
//check whether we can allow to allocate this
@@ -481,14 +481,14 @@ LPVOID WINAPI VirtualAlloc(LPVOID address, DWORD size, DWORD type, DWORD protec
return NULL;
}
answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_FIXED | MAP_PRIVATE, fd, 0);
+ MAP_FIXED | MAP_PRIVATE, fd, 0);
}
else
- answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_PRIVATE, fd, 0);
+ answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_PRIVATE, fd, 0);
// answer=FILE_dommap(-1, address, 0, size, 0, 0,
// PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
- close(fd);
+ close(fd);
if(answer==(void*)-1)
{
printf("Error no %d\n", errno);
@@ -509,13 +509,13 @@ LPVOID WINAPI VirtualAlloc(LPVOID address, DWORD size, DWORD type, DWORD protec
vm->next=new_vm;
vm=new_vm;
vm->next=0;
-// if(va_size!=0)
-// printf("Multiple VirtualAlloc!\n");
-// printf("answer=0x%08x\n", answer);
+ //if(va_size!=0)
+ // printf("Multiple VirtualAlloc!\n");
+ //printf("answer=0x%08x\n", answer);
return answer;
}
}
-WIN_BOOL WINAPI VirtualFree(LPVOID address, DWORD t1, DWORD t2)//not sure
+WIN_BOOL WINAPI VirtualFree(LPVOID address, SIZE_T dwSize, DWORD dwFreeType)//not sure
{
virt_alloc* str=vm;
int answer;
@@ -526,10 +526,11 @@ WIN_BOOL WINAPI VirtualFree(LPVOID address, DWORD t1, DWORD t2)//not sure
str=str->prev;
continue;
}
+ //printf("VirtualFree(0x%08X, %d - %d)\n", str->address, dwSize, str->mapping_size);
answer=munmap(str->address, str->mapping_size);
if(str->next)str->next->prev=str->prev;
if(str->prev)str->prev->next=str->next;
- if(vm==str)vm=0;
+ if(vm==str)vm=str->prev;
free(str);
return 0;
}
diff --git a/loader/registry.c b/loader/registry.c
index c926f2cdf8..754edb5e70 100644
--- a/loader/registry.c
+++ b/loader/registry.c
@@ -18,21 +18,12 @@
//#undef TRACE
//#define TRACE printf
-struct reg_value
-{
- int type;
- char* name;
- int len;
- char* value;
-};
-
// ...can be set before init_registry() call
char* regpathname = 0;
-static int reg_size=0;
-static struct reg_value* regs = 0;
-struct reg_handle_s;
+static char* localregpathname = 0;
+
typedef struct reg_handle_s
{
int handle;
@@ -41,7 +32,17 @@ typedef struct reg_handle_s
struct reg_handle_s* prev;
} reg_handle_t;
-static reg_handle_t* head=0;
+struct reg_value
+{
+ int type;
+ char* name;
+ int len;
+ char* value;
+};
+
+static struct reg_value* regs = NULL;
+static int reg_size;
+static reg_handle_t* head = NULL;
#define DIR -25
@@ -51,8 +52,6 @@ static void save_registry(void);
static void init_registry(void);
-
-
static void create_registry(void){
if(regs)
{
@@ -69,8 +68,10 @@ static void create_registry(void){
regs[0].value=regs[1].value=NULL;
regs[0].len=regs[1].len=0;
reg_size=2;
+ head = 0;
save_registry();
}
+
static void open_registry(void)
{
int fd;
@@ -81,7 +82,7 @@ static void open_registry(void)
printf("Multiple open_registry(>\n");
return;
}
- fd = open(regpathname, O_RDONLY);
+ fd = open(localregpathname, O_RDONLY);
if (fd == -1)
{
printf("Creating new registry\n");
@@ -90,6 +91,7 @@ static void open_registry(void)
}
read(fd, &reg_size, 4);
regs=(struct reg_value*)malloc(reg_size*sizeof(struct reg_value));
+ head = 0;
for(i=0; i<reg_size; i++)
{
read(fd,&regs[i].type,4);
@@ -106,7 +108,7 @@ static void open_registry(void)
regs[i].value=(char*)malloc(regs[i].len+1);
if(regs[i].value==0)
{
- free(regs[i].name);
+ free(regs[i].name);
reg_size=i+1;
goto error;
}
@@ -123,11 +125,11 @@ static void save_registry(void)
int fd, i;
if (!regs)
init_registry();
- fd = open(regpathname, O_WRONLY | O_CREAT, 00666);
+ fd = open(localregpathname, O_WRONLY | O_CREAT, 00666);
if (fd == -1)
{
printf("Failed to open registry file '%s' for writing.\n",
- regpathname);
+ localregpathname);
return;
}
write(fd, &reg_size, 4);
@@ -142,6 +144,38 @@ static void save_registry(void)
}
close(fd);
}
+
+void free_registry(void)
+{
+ reg_handle_t* t = head;
+ while (t)
+ {
+ reg_handle_t* f = t;
+ if (t->name)
+ free(t->name);
+ t=t->prev;
+ free(f);
+ }
+ head = 0;
+ if (regs)
+ {
+ int i;
+ for(i=0; i<reg_size; i++)
+ {
+ free(regs[i].name);
+ free(regs[i].value);
+ }
+ free(regs);
+ regs = 0;
+ }
+ if (localregpathname)
+ {
+ free(localregpathname);
+ localregpathname = 0;
+ }
+}
+
+
static reg_handle_t* find_handle_by_name(const char* name)
{
reg_handle_t* t;
@@ -237,14 +271,15 @@ static struct reg_value* insert_reg_value(int handle, const char* name, int type
if(regs==0)
create_registry();
regs=(struct reg_value*)realloc(regs, sizeof(struct reg_value)*(reg_size+1));
+ //regs=(struct reg_value*)my_realloc(regs, sizeof(struct reg_value)*(reg_size+1));
v=regs+reg_size;
reg_size++;
}
else
//replacing old one
{
- free(v->value);
- free(v->name);
+ free(v->value);
+ free(v->name);
}
v->type=type;
v->len=len;
@@ -252,26 +287,35 @@ static struct reg_value* insert_reg_value(int handle, const char* name, int type
memcpy(v->value, value, len);
v->name=(char*)malloc(strlen(fullname)+1);
strcpy(v->name, fullname);
+ free(fullname);
save_registry();
return v;
}
static void init_registry(void)
{
- struct passwd* pwent;
TRACE("Initializing registry\n");
- pwent = getpwuid(geteuid());
// can't be free-ed - it's static and probably thread
// unsafe structure which is stored in glibc
-#if 1
+#ifdef USE_WIN32DLL
+ // MPlayer:
regpathname = get_path("registry");
#else
- if (regpathname == 0)
+ // avifile:
+ if (localregpathname == 0)
{
- regpathname = (char*)malloc(strlen(pwent->pw_dir)+20);
- strcpy(regpathname, pwent->pw_dir);
- strcat(regpathname, "/.registry");
+ const char* pthn = regpathname;
+ if (!regpathname)
+ {
+ struct passwd* pwent;
+ pwent = getpwuid(geteuid());
+ pthn = pwent->pw_dir;
+ }
+
+ localregpathname = (char*)malloc(strlen(pthn)+20);
+ strcpy(localregpathname, pthn);
+ strcat(localregpathname, "/.registry");
}
#endif
@@ -352,7 +396,6 @@ long RegCloseKey(long key)
return 1;
}
-extern void trapbug(void);
long RegQueryValueExA(long key, const char* value, int* reserved, int* type, int* data, int* count)
{
struct reg_value* t;
@@ -367,17 +410,14 @@ long RegQueryValueExA(long key, const char* value, int* reserved, int* type, int
printf("Query for AudioReserved001 %p %p count: %d\n", type, data, *count);
*(int*)type = REG_DWORD;
*(int*)data = 256;
- //trapbug();
return 0;
}
if(c==NULL)
- return 1;
- if((t=find_value_by_name(c))==0)
- {
- free(c);
- return 2;
- }
+ return 1;
+ t=find_value_by_name(c);
free(c);
+ if(t==0)
+ return 2;
if(type)
*type=t->type;
if(data)
diff --git a/loader/registry.h b/loader/registry.h
index 9c94043c42..bb204932ff 100644
--- a/loader/registry.h
+++ b/loader/registry.h
@@ -12,6 +12,8 @@
extern "C" {
#endif
+void free_registry(void);
+
long RegOpenKeyExA(long key, const char* subkey, long reserved,
long access, int* newkey);
long RegCloseKey(long key);
diff --git a/loader/win32.c b/loader/win32.c
index 4051462132..12e8852948 100644
--- a/loader/win32.c
+++ b/loader/win32.c
@@ -170,7 +170,7 @@ static inline void dbgprintf(char* fmt, ...)
va_list va;
va_start(va, fmt);
f=fopen("./log", "a");
- vprintf(fmt, va);
+ vprintf(fmt, va);
if(f)
{
vfprintf(f, fmt, va);
@@ -192,8 +192,21 @@ char export_names[500][30]={
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 COLLECTOR
static 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;
@@ -294,6 +307,15 @@ static int alccnt = 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;
+};
void* mreq_private(int size, int to_zero, int type);
void* mreq_private(int size, int to_zero, int type)
@@ -341,6 +363,7 @@ int my_release(void* memory)
#ifdef GARBAGE
alloc_header* prevmem;
alloc_header* nextmem;
+
if (memory == 0)
return 0;
@@ -363,6 +386,11 @@ int my_release(void* memory)
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);
}
prevmem = header->prev;
@@ -382,7 +410,7 @@ 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)
@@ -532,17 +560,6 @@ HMODULE WINAPI expGetModuleHandleA(const char* name)
return result;
}
-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;
-
-static th_list* list=NULL;
-
-
void* WINAPI expCreateThread(void* pSecAttr, long dwStackSize, void* lpStartAddress,
void* lpParameter, long dwFlags, long* dwThreadId)
@@ -1056,9 +1073,11 @@ void* WINAPI expHeapAlloc(HANDLE heap, int flags, int size)
/**
Morgan's m3jpeg32.dll v. 2.0 encoder expects that request for
HeapAlloc returns area larger than size argument :-/
+ - do we really have to vaste that much memory - I would
+ suggest to make extra check for this value - FIXME
**/
- z=my_mreq(((size+4095)/4096)*4096, flags&8);
-// z=HeapAlloc(heap,flags,size);
+ //z=my_mreq(size, flags&8);
+ z=my_mreq((size + 0xfff) & 0x7ffff000, flags&8);
if(z==0)
printf("HeapAlloc failure\n");
dbgprintf("HeapAlloc(heap 0x%x, flags 0x%x, size 0x%x) => 0x%x\n", heap, flags, size, z);
@@ -1075,7 +1094,7 @@ long WINAPI expHeapDestroy(void* heap)
long WINAPI expHeapFree(int arg1, int arg2, void* ptr)
{
dbgprintf("HeapFree(0x%x, 0x%x, pointer 0x%x) => 1\n", arg1, arg2, ptr);
- if (heapfreehack != ptr)
+ if (heapfreehack != ptr && ptr != (void*)0xffffffff)
my_release(ptr);
else
{
@@ -1120,14 +1139,6 @@ int WINAPI expVirtualFree(void* v1, int v2, int v3)
return result;
}
-/* -- critical sections -- */
-struct CRITSECT
-{
- pthread_t id;
- pthread_mutex_t mutex;
- int locked;
-};
-
/* we're building a table of critical sections. cs_win pointer uses the DLL
cs_unix is the real structure, we're using cs_win only to identifying cs_unix */
struct critsecs_list_t
@@ -1214,11 +1225,10 @@ void WINAPI expInitializeCriticalSection(CRITICAL_SECTION* c)
}
#else
{
- struct CRITSECT cs;
- pthread_mutex_init(&cs.mutex, NULL);
- cs.locked=0;
- *(void**)c=malloc(sizeof cs);
- memcpy(*(void**)c, &cs, sizeof cs);
+ struct CRITSECT* cs = mreq_private(sizeof(struct CRITSECT), 0, AREATYPE_CRITSECT);
+ pthread_mutex_init(&cs->mutex, NULL);
+ cs->locked=0;
+ *(void**)c = cs;
}
#endif
return;
@@ -1243,7 +1253,6 @@ void WINAPI expEnterCriticalSection(CRITICAL_SECTION* c)
#endif
printf("Win32 Warning: Accessed uninitialized Critical Section (%p)!\n", c);
}
-// cs.id=pthread_self();
if(cs->locked)
if(cs->id==pthread_self())
return;
@@ -1361,7 +1370,6 @@ struct tls_s {
struct tls_s* next;
};
-tls_t* g_tls=NULL;
void* WINAPI expTlsAlloc()
{
if(g_tls==NULL)
@@ -1717,11 +1725,8 @@ long WINAPI expRegSetValueExA(long key, const char* name, long v1, long v2, void
return result;
}
-long WINAPI expRegOpenKeyA (
-long hKey,
- LPCSTR lpSubKey,
- int* phkResult
-){
+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);
@@ -3119,14 +3124,14 @@ LONG WINAPI explstrcmpiA(const char* str1, const char* str2)
LONG WINAPI explstrlenA(const char* str1)
{
LONG result=strlen(str1);
- dbgprintf("strlen(0x%x='%s') => %d\n", str1, str1, result);
+ dbgprintf("strlen(0x%x='%.50s') => %d\n", str1, str1, result);
return result;
}
LONG WINAPI explstrcpyA(char* str1, const char* str2)
{
int result= (int) strcpy(str1, str2);
- dbgprintf("strcpy(0x%x, 0x%x='%s') => %d\n", str1, str2, str2, result);
+ dbgprintf("strcpy(0x%.50x, 0x%.50x='%.50s') => %d\n", str1, str2, str2, result);
return result;
}
LONG WINAPI explstrcpynA(char* str1, const char* str2,int len)
@@ -3532,6 +3537,7 @@ void my_garbagecollection(void)
#ifdef GARBAGE
int unfree = 0, unfreecnt = 0;
+ free_registry();
while (last_alloc)
{
alloc_header* mem = last_alloc + 1;
@@ -3541,4 +3547,6 @@ void my_garbagecollection(void)
}
printf("Total Unfree %d bytes cnt %d [%p,%d]\n",unfree, unfreecnt, last_alloc, alccnt);
#endif
+ g_tls = NULL;
+ list = NULL;
}