win32.c
资源名称:vlc-1.0.5.zip [点击查看]
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:138k
源码类别:
midi
开发平台:
Unix_Linux
- /*
- * $Id: 7f4acf121296f902d385b21ad02325ddfe536df4 $
- *
- * Originally distributed under LPGL 2.1 (or later) by the Wine project.
- *
- * Modified for use with MPlayer, detailed CVS changelog at
- * http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
- *
- * File now distributed as part of VLC media player with no modifications.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- */
- /***********************************************************
- 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.
- ************************************************************/
- #include "config.h"
- #ifdef MPLAYER
- #ifdef USE_QTX_CODECS
- #define QTX
- #endif
- #define REALPLAYER
- //#define LOADLIB_TRY_NATIVE
- #endif
- #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 <stdio.h>
- #include "win32.h"
- #include "registry.h"
- #include "loader.h"
- #include "com.h"
- #include "ext.h"
- #include <stdlib.h>
- #include <assert.h>
- #include <stdarg.h>
- #include <ctype.h>
- #include <pthread.h>
- #include <errno.h>
- #ifdef HAVE_MALLOC_H
- #include <malloc.h>
- #endif
- #include <time.h>
- #include <math.h>
- #include <unistd.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
- #if HAVE_VSSCANF
- int 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);
- }
- #endif
- static 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)
- );
- }
- static unsigned int c_localcount_tsc()
- {
- int a;
- __asm__ __volatile__
- (
- "rdtscnt"
- :"=a"(a)
- :
- :"edx"
- );
- return a;
- }
- static void c_longcount_tsc(long long* z)
- {
- __asm__ __volatile__
- (
- "pushl %%ebxnt"
- "movl %%eax, %%ebxnt"
- "rdtscnt"
- "movl %%eax, 0(%%ebx)nt"
- "movl %%edx, 4(%%ebx)nt"
- "popl %%ebxnt"
- ::"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);
- }
- #ifdef MPLAYER
- #include "../mp_msg.h"
- #endif
- int LOADER_DEBUG=1; // active only if compiled with -DDETAILED_OUT
- //#define DETAILED_OUT
- static inline void dbgprintf(const 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
- #ifdef MPLAYER
- if (verbose > 2)
- {
- va_list va;
- va_start(va, fmt);
- vprintf(fmt, va);
- // mp_dbg(MSGT_WIN32, MSGL_DBG3, fmt, va);
- va_end(va);
- }
- fflush(stdout);
- #endif
- }
- 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 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;
- if(heap==0)
- return;
- while(offset<heap_counter)
- {
- if(*(int*)(heap+offset)!=0x433476)
- {
- printf("Heap corruption at address %dn", 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 %dn", offset);
- }
- }
- #undef MEMORY_DEBUG
- #ifdef MEMORY_DEBUG
- static void* my_mreq(int size, int to_zero)
- {
- static int test=0;
- test++;
- if(test%10==0)printf("Memory: %d bytes allocatedn", heap_counter);
- // test_heap();
- if(heap==NULL)
- {
- heap=malloc(20000000);
- memset(heap, 0xCC,20000000);
- }
- if(heap==0)
- {
- printf("No enough memoryn");
- return 0;
- }
- if(heap_counter+size>20000000)
- {
- printf("No enough memoryn");
- 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-%dn", 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 memoryn", *(int*)(memory-4));
- // memset(memory-8, *(int*)(memory-4), 0xCC);
- return 0;
- }
- #else
- #define GARBAGE
- typedef 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 GARBAGE
- static 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: %pt%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: %pt%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
- static 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;
- }
- /*
- *
- * WINE API - native implementation for several win32 libraries
- *
- */
- static int WINAPI ext_unknown()
- {
- printf("Unknown func calledn");
- return 0;
- }
- static int WINAPI expGetVolumeInformationA( const char *root, char *label,
- unsigned int label_len, unsigned int *serial,
- unsigned int *filename_len,unsigned int *flags,
- char *fsname, unsigned int fsname_len )
- {
- dbgprintf("GetVolumeInformationA( %s, 0x%x, %ld, 0x%x, 0x%x, 0x%x, 0x%x, %ld) => 1n",
- root,label,label_len,serial,filename_len,flags,fsname,fsname_len);
- //hack Do not return any real data - do nothing
- return 1;
- }
- static unsigned int WINAPI expGetDriveTypeA( const char *root )
- {
- dbgprintf("GetDriveTypeA( %s ) => %dn",root,DRIVE_FIXED);
- // hack return as Fixed Drive Type
- return DRIVE_FIXED;
- }
- static unsigned int WINAPI expGetLogicalDriveStringsA( unsigned int len, char *buffer )
- {
- dbgprintf("GetLogicalDriveStringsA(%d, 0x%x) => 4n",len,buffer);
- // hack only have one drive c: in this hack
- *buffer++='c';
- *buffer++=':';
- *buffer++='\';
- *buffer++=' ';
- *buffer= ' ';
- return 4; // 1 drive * 4 bytes (includes null)
- }
- static int WINAPI expIsBadWritePtr(void* ptr, unsigned int count)
- {
- int result = (count == 0 || ptr != 0) ? 0 : 1;
- dbgprintf("IsBadWritePtr(0x%x, 0x%x) => %dn", ptr, count, result);
- return result;
- }
- static int WINAPI expIsBadReadPtr(void* ptr, unsigned int count)
- {
- int result = (count == 0 || ptr != 0) ? 0 : 1;
- dbgprintf("IsBadReadPtr(0x%x, 0x%x) => %dn", ptr, count, result);
- return result;
- }
- static int WINAPI expDisableThreadLibraryCalls(int module)
- {
- dbgprintf("DisableThreadLibraryCalls(0x%x) => 0n", module);
- return 0;
- }
- static HMODULE WINAPI expGetDriverModuleHandle(DRVR* pdrv)
- {
- HMODULE result;
- if (pdrv==NULL)
- result=0;
- else
- result=pdrv->hDriverModule;
- dbgprintf("GetDriverModuleHandle(%p) => %pn", pdrv, result);
- return result;
- }
- #define MODULE_HANDLE_kernel32 ((HMODULE)0x120)
- #define MODULE_HANDLE_user32 ((HMODULE)0x121)
- #ifdef QTX
- #define MODULE_HANDLE_wininet ((HMODULE)0x122)
- #define MODULE_HANDLE_ddraw ((HMODULE)0x123)
- #define MODULE_HANDLE_advapi32 ((HMODULE)0x124)
- #endif
- #define MODULE_HANDLE_comdlg32 ((HMODULE)0x125)
- #define MODULE_HANDLE_msvcrt ((HMODULE)0x126)
- #define MODULE_HANDLE_ole32 ((HMODULE)0x127)
- #define MODULE_HANDLE_winmm ((HMODULE)0x128)
- static HMODULE WINAPI expGetModuleHandleA(const char* name)
- {
- WINE_MODREF* wm;
- HMODULE result;
- if(!name)
- #ifdef QTX
- result=1;
- #else
- result=0;
- #endif
- else
- {
- wm=MODULE_FindModule(name);
- if(wm==0)result=0;
- else
- result=(HMODULE)(wm->module);
- }
- if(!result)
- {
- if(name && (strcasecmp(name, "kernel32")==0 || !strcasecmp(name, "kernel32.dll")))
- result=MODULE_HANDLE_kernel32;
- #ifdef QTX
- if(name && strcasecmp(name, "user32")==0)
- result=MODULE_HANDLE_user32;
- #endif
- }
- dbgprintf("GetModuleHandleA('%s') => 0x%xn", name, result);
- return result;
- }
- static void* WINAPI expCreateThread(void* pSecAttr, long dwStackSize,
- void* lpStartAddress, void* lpParameter,
- long dwFlags, long* dwThreadId)
- {
- pthread_t *pth;
- // printf("CreateThread:");
- pth = (pthread_t*) my_mreq(sizeof(pthread_t), 0);
- pthread_create(pth, NULL, (void*(*)(void*))lpStartAddress, lpParameter);
- if(dwFlags)
- printf( "WARNING: CreateThread flags not supportedn");
- if(dwThreadId)
- *dwThreadId=(long)pth;
- if(list==NULL)
- {
- list=my_mreq(sizeof(th_list), 1);
- list->next=list->prev=NULL;
- }
- else
- {
- list->next=my_mreq(sizeof(th_list), 0);
- list->next->prev=list;
- list->next->next=NULL;
- list=list->next;
- }
- list->thread=pth;
- dbgprintf("CreateThread(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x) => 0x%xn",
- pSecAttr, dwStackSize, lpStartAddress, lpParameter, dwFlags, dwThreadId, pth);
- return pth;
- }
- struct mutex_list_t;
- struct mutex_list_t
- {
- char type;
- pthread_mutex_t *pm;
- pthread_cond_t *pc;
- char state;
- char reset;
- char name[128];
- int semaphore;
- struct mutex_list_t* next;
- struct mutex_list_t* prev;
- };
- typedef struct mutex_list_t mutex_list;
- static mutex_list* mlist=NULL;
- void destroy_event(void* event)
- {
- mutex_list* pp=mlist;
- // printf("garbage collector: destroy_event(%x)n", event);
- while(pp)
- {
- if(pp==(mutex_list*)event)
- {
- if(pp->next)
- pp->next->prev=pp->prev;
- if(pp->prev)
- pp->prev->next=pp->next;
- if(mlist==(mutex_list*)event)
- mlist=mlist->prev;
- /*
- pp=mlist;
- while(pp)
- {
- printf("%x => ", pp);
- pp=pp->prev;
- }
- printf("0n");
- */
- return;
- }
- pp=pp->prev;
- }
- }
- 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("0n");
- */
- if(mlist!=NULL)
- {
- mutex_list* pp=mlist;
- if(name!=NULL)
- do
- {
- if((strcmp(pp->name, name)==0) && (pp->type==0))
- {
- dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, 0x%x='%s') => 0x%xn",
- pSecAttr, bManualReset, bInitialState, name, name, pp->pm);
- return pp->pm;
- }
- }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;
- }
- mlist->type=0; /* Type Event */
- mlist->pm=pm;
- mlist->pc=pc;
- mlist->state=bInitialState;
- mlist->reset=bManualReset;
- if(name)
- strncpy(mlist->name, name, 127);
- else
- mlist->name[0]=0;
- if(pm==NULL)
- dbgprintf("ERROR::: CreateEventA failuren");
- /*
- if(bInitialState)
- pthread_mutex_lock(pm);
- */
- if(name)
- dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, 0x%x='%s') => 0x%xn",
- pSecAttr, bManualReset, bInitialState, name, name, mlist);
- else
- dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, NULL) => 0x%xn",
- pSecAttr, bManualReset, bInitialState, mlist);
- return mlist;
- }
- static void* WINAPI expSetEvent(void* event)
- {
- mutex_list *ml = (mutex_list *)event;
- dbgprintf("SetEvent(%x) => 0x1n", 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;
- }
- static void* WINAPI expResetEvent(void* event)
- {
- mutex_list *ml = (mutex_list *)event;
- dbgprintf("ResetEvent(0x%x) => 0x1n", event);
- pthread_mutex_lock(ml->pm);
- ml->state = 0;
- pthread_mutex_unlock(ml->pm);
- return (void *)1;
- }
- static void* WINAPI expWaitForSingleObject(void* object, int duration)
- {
- mutex_list *ml = (mutex_list *)object;
- // FIXME FIXME FIXME - this value is sometime unititialize !!!
- int ret = WAIT_FAILED;
- 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.
- 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.
- **/
- dbgprintf("WaitForSingleObject(thread_handle) calledn");
- return (void*)WAIT_FAILED;
- }
- dbgprintf("WaitForSingleObject(0x%x, duration %d) =>n",object, duration);
- // loop below was slightly fixed - its used just for checking if
- // this object really exists in our list
- if (!ml)
- return (void*) ret;
- while (pp && (pp->pm != ml->pm))
- pp = pp->prev;
- if (!pp) {
- dbgprintf("WaitForSingleObject: NotFoundn");
- return (void*)ret;
- }
- 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;
- }
- #ifdef QTX
- static void* WINAPI expWaitForMultipleObjects(int count, const void** objects,
- int WaitAll, int duration)
- {
- int i;
- void *object;
- void *ret;
- dbgprintf("WaitForMultipleObjects(%d, 0x%x, %d, duration %d) =>n",
- count, objects, WaitAll, duration);
- for (i = 0; i < count; i++)
- {
- object = (void *)objects[i];
- ret = expWaitForSingleObject(object, duration);
- if (WaitAll)
- dbgprintf("WaitAll flag not yet supported...n");
- else
- return ret;
- }
- return NULL;
- }
- static void WINAPI expExitThread(int retcode)
- {
- dbgprintf("ExitThread(%d)n", retcode);
- pthread_exit(&retcode);
- }
- static HANDLE WINAPI expCreateMutexA(void *pSecAttr,
- char bInitialOwner, const char *name)
- {
- HANDLE mlist = (HANDLE)expCreateEventA(pSecAttr, 0, 0, name);
- if (name)
- dbgprintf("CreateMutexA(0x%x, %d, '%s') => 0x%xn",
- pSecAttr, bInitialOwner, name, mlist);
- else
- dbgprintf("CreateMutexA(0x%x, %d, NULL) => 0x%xn",
- pSecAttr, bInitialOwner, mlist);
- #ifndef QTX
- /* 10l to QTX, if CreateMutex returns a real mutex, WaitForSingleObject
- waits for ever, else it works ;) */
- return mlist;
- #endif
- }
- static int WINAPI expReleaseMutex(HANDLE hMutex)
- {
- dbgprintf("ReleaseMutex(%x) => 1n", hMutex);
- /* FIXME:XXX !! not yet implemented */
- return 1;
- }
- #endif
- static int pf_set = 0;
- static BYTE PF[64] = {0,};
- static void DumpSystemInfo(const SYSTEM_INFO* si)
- {
- dbgprintf(" Processor architecture %dn", si->u.s.wProcessorArchitecture);
- dbgprintf(" Page size: %dn", si->dwPageSize);
- dbgprintf(" Minimum app address: %dn", si->lpMinimumApplicationAddress);
- dbgprintf(" Maximum app address: %dn", si->lpMaximumApplicationAddress);
- dbgprintf(" Active processor mask: 0x%xn", si->dwActiveProcessorMask);
- dbgprintf(" Number of processors: %dn", si->dwNumberOfProcessors);
- dbgprintf(" Processor type: 0x%xn", si->dwProcessorType);
- dbgprintf(" Allocation granularity: 0x%xn", si->dwAllocationGranularity);
- dbgprintf(" Processor level: 0x%xn", si->wProcessorLevel);
- dbgprintf(" Processor revision: 0x%xn", si->wProcessorRevision);
- }
- 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);
- if (cache) {
- memcpy(si,&cachedsi,sizeof(*si));
- DumpSystemInfo(si);
- return;
- }
- memset(PF,0,sizeof(PF));
- pf_set = 1;
- 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 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;
- if (gCpuCaps.cpuType == 4)
- {
- cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
- cachedsi.wProcessorLevel = 4;
- }
- else if (gCpuCaps.cpuType >= 5)
- {
- cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
- cachedsi.wProcessorLevel = 5;
- }
- else
- {
- cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
- cachedsi.wProcessorLevel = 3;
- }
- cachedsi.wProcessorRevision = gCpuCaps.cpuStepping;
- cachedsi.dwNumberOfProcessors = 1; /* hardcoded */
- }
- #endif
- /* disable cpuid based detection (mplayer's cpudetect.c does this - see above) */
- #ifndef MPLAYER
- #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__svr4__) || defined(__DragonFly__)
- 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 /* 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;
- 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++ = ' ';
- /* skip any leading spaces */
- while (*value==' ') value++;
- if ((s=strchr(value,'n')))
- *s=' ';
- /* 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;
- 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...*/
- unsigned 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;
- }
- }
- fclose (f);
- /*
- * ad hoc fix for smp machines.
- * some problems on WaitForSingleObject,CreateEvent,SetEvent
- * CreateThread ...etc..
- *
- */
- cachedsi.dwNumberOfProcessors=1;
- }
- #endif /* __linux__ */
- cache = 1;
- memcpy(si,&cachedsi,sizeof(*si));
- DumpSystemInfo(si);
- }
- // avoid undefined expGetSystemInfo
- static WIN_BOOL WINAPI expIsProcessorFeaturePresent(DWORD v)
- {
- WIN_BOOL result = 0;
- if (!pf_set)
- {
- SYSTEM_INFO si;
- expGetSystemInfo(&si);
- }
- if(v<64) result=PF[v];
- dbgprintf("IsProcessorFeaturePresent(0x%x) => 0x%xn", v, result);
- return result;
- }
- static long WINAPI expGetVersion()
- {
- dbgprintf("GetVersion() => 0xC0000004n");
- return 0xC0000004;//Windows 95
- }
- static HANDLE WINAPI expHeapCreate(long flags, long init_size, long max_size)
- {
- // printf("HeapCreate:");
- HANDLE result;
- if(init_size==0)
- result=(HANDLE)my_mreq(0x110000, 0);
- else
- result=(HANDLE)my_mreq((init_size + 0xfff) & 0x7ffff000 , 0);
- dbgprintf("HeapCreate(flags 0x%x, initial size %d, maximum size %d) => 0x%xn", flags, init_size, max_size, result);
- return result;
- }
- // this is another dirty hack
- // VP31 is releasing one allocated Heap chunk twice
- // we will silently ignore this second call...
- static void* heapfreehack = 0;
- static int heapfreehackshown = 0;
- //extern void trapbug(void);
- static void* WINAPI expHeapAlloc(HANDLE heap, int flags, int size)
- {
- void* z;
- /**
- Morgan's m3jpeg32.dll v. 2.0 encoder expects that request for
- HeapAlloc returns area larger than size argument :-/
- actually according to M$ Doc HeapCreate size should be rounded
- to page boundaries thus we should simulate this
- **/
- //if (size == 22276) trapbug();
- z=my_mreq((size + 0xfff) & 0x7ffff000, (flags & HEAP_ZERO_MEMORY));
- if(z==0)
- printf("HeapAlloc failuren");
- dbgprintf("HeapAlloc(heap 0x%x, flags 0x%x, size %d) => 0x%xn", heap, flags, size, z);
- heapfreehack = 0; // reset
- return z;
- }
- static long WINAPI expHeapDestroy(void* heap)
- {
- dbgprintf("HeapDestroy(heap 0x%x) => 1n", heap);
- my_release(heap);
- return 1;
- }
- static long WINAPI expHeapFree(HANDLE heap, DWORD dwFlags, LPVOID lpMem)
- {
- dbgprintf("HeapFree(0x%x, 0x%x, pointer 0x%x) => 1n", heap, dwFlags, lpMem);
- if (heapfreehack != lpMem && lpMem != (void*)0xffffffff
- && lpMem != (void*)0xbdbdbdbd)
- // 0xbdbdbdbd is for i263_drv.drv && libefence
- // it seems to be reading from relased memory
- // EF_PROTECT_FREE doens't show any probleme
- my_release(lpMem);
- else
- {
- if (!heapfreehackshown++)
- printf("Info: HeapFree deallocating same memory twice! (%p)n", lpMem);
- }
- heapfreehack = lpMem;
- return 1;
- }
- static long WINAPI expHeapSize(int heap, int flags, void* pointer)
- {
- long result=my_size(pointer);
- dbgprintf("HeapSize(heap 0x%x, flags 0x%x, pointer 0x%x) => %dn", heap, flags, pointer, result);
- return result;
- }
- static void* WINAPI expHeapReAlloc(HANDLE heap,int flags,void *lpMem,int size)
- {
- long orgsize = my_size(lpMem);
- dbgprintf("HeapReAlloc() Size %ld org %dn",orgsize,size);
- return my_realloc(lpMem, size);
- }
- static long WINAPI expGetProcessHeap(void)
- {
- dbgprintf("GetProcessHeap() => 1n");
- return 1;
- }
- static void* WINAPI expVirtualAlloc(void* v1, long v2, long v3, long v4)
- {
- void* z = VirtualAlloc(v1, v2, v3, v4);
- if(z==0)
- printf("VirtualAlloc failuren");
- dbgprintf("VirtualAlloc(0x%x, %d, %d, %d) => 0x%x n",v1,v2,v3,v4, z);
- return z;
- }
- static int WINAPI expVirtualFree(void* v1, int v2, int v3)
- {
- int result = VirtualFree(v1,v2,v3);
- dbgprintf("VirtualFree(0x%x, %d, %d) => %dn",v1,v2,v3, result);
- return result;
- }
- /* 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
- {
- CRITICAL_SECTION *cs_win;
- struct CRITSECT *cs_unix;
- };
- /* 'NEWTYPE' is working with VIVO, 3ivX and QTX dll (no more segfaults) -- alex */
- #undef CRITSECS_NEWTYPE
- //#define CRITSECS_NEWTYPE 1
- #ifdef CRITSECS_NEWTYPE
- /* increased due to ucod needs more than 32 entries */
- /* and 64 should be enough for everything */
- #define CRITSECS_LIST_MAX 64
- static struct critsecs_list_t critsecs_list[CRITSECS_LIST_MAX];
- static int critsecs_get_pos(CRITICAL_SECTION *cs_win)
- {
- int i;
- for (i=0; i < CRITSECS_LIST_MAX; i++)
- if (critsecs_list[i].cs_win == cs_win)
- return(i);
- return(-1);
- }
- static int critsecs_get_unused(void)
- {
- int i;
- for (i=0; i < CRITSECS_LIST_MAX; i++)
- if (critsecs_list[i].cs_win == NULL)
- return(i);
- return(-1);
- }
- struct CRITSECT *critsecs_get_unix(CRITICAL_SECTION *cs_win)
- {
- int i;
- for (i=0; i < CRITSECS_LIST_MAX; i++)
- if (critsecs_list[i].cs_win == cs_win && critsecs_list[i].cs_unix)
- return(critsecs_list[i].cs_unix);
- return(NULL);
- }
- #endif
- static void WINAPI expInitializeCriticalSection(CRITICAL_SECTION* c)
- {
- dbgprintf("InitializeCriticalSection(0x%x)n", c);
- /* if(sizeof(pthread_mutex_t)>sizeof(CRITICAL_SECTION))
- {
- printf(" ERROR:::: sizeof(pthread_mutex_t) is %d, expected <=%d!n",
- sizeof(pthread_mutex_t), sizeof(CRITICAL_SECTION));
- return;
- }*/
- /* pthread_mutex_init((pthread_mutex_t*)c, NULL); */
- #ifdef CRITSECS_NEWTYPE
- {
- struct CRITSECT *cs;
- int i = critsecs_get_unused();
- if (i < 0)
- {
- printf("InitializeCriticalSection(%p) - no more space in listn", c);
- return;
- }
- dbgprintf("got unused space at %dn", i);
- cs = malloc(sizeof(struct CRITSECT));
- if (!cs)
- {
- printf("InitializeCriticalSection(%p) - out of memoryn", c);
- return;
- }
- pthread_mutex_init(&cs->mutex, NULL);
- cs->locked = 0;
- critsecs_list[i].cs_win = c;
- critsecs_list[i].cs_unix = cs;
- dbgprintf("InitializeCriticalSection -> itemno=%d, cs_win=%p, cs_unix=%pn",
- i, c, cs);
- }
- #else
- {
- struct CRITSECT* cs = mreq_private(sizeof(struct CRITSECT) + sizeof(CRITICAL_SECTION),
- 0, AREATYPE_CRITSECT);
- pthread_mutex_init(&cs->mutex, NULL);
- cs->locked=0;
- cs->deadbeef = 0xdeadbeef;
- *(void**)c = cs;
- }
- #endif
- return;
- }
- static void WINAPI expEnterCriticalSection(CRITICAL_SECTION* c)
- {
- #ifdef CRITSECS_NEWTYPE
- struct CRITSECT* cs = critsecs_get_unix(c);
- #else
- struct CRITSECT* cs = (*(struct CRITSECT**)c);
- #endif
- dbgprintf("EnterCriticalSection(0x%x) %pn",c, cs);
- if (!cs)
- {
- dbgprintf("entered uninitialized critisec!n");
- expInitializeCriticalSection(c);
- #ifdef CRITSECS_NEWTYPE
- cs=critsecs_get_unix(c);
- #else
- cs = (*(struct CRITSECT**)c);
- #endif
- dbgprintf("Win32 Warning: Accessed uninitialized Critical Section (%p)!n", c);
- }
- if(cs->locked)
- if(cs->id==pthread_self())
- return;
- pthread_mutex_lock(&(cs->mutex));
- cs->locked=1;
- cs->id=pthread_self();
- return;
- }
- static void WINAPI expLeaveCriticalSection(CRITICAL_SECTION* c)
- {
- #ifdef CRITSECS_NEWTYPE
- struct CRITSECT* cs = critsecs_get_unix(c);
- #else
- struct CRITSECT* cs = (*(struct CRITSECT**)c);
- #endif
- // struct CRITSECT* cs=(struct CRITSECT*)c;
- dbgprintf("LeaveCriticalSection(0x%x) 0x%xn",c, cs);
- if (!cs)
- {
- dbgprintf("Win32 Warning: Leaving uninitialized Critical Section %p!!n", c);
- return;
- }
- if (cs->locked)
- {
- cs->locked=0;
- pthread_mutex_unlock(&(cs->mutex));
- }
- else
- dbgprintf("Win32 Warning: Unlocking unlocked Critical Section %p!!n", c);
- return;
- }
- static void expfree(void* mem); /* forward declaration */
- static void WINAPI expDeleteCriticalSection(CRITICAL_SECTION *c)
- {
- #ifdef CRITSECS_NEWTYPE
- struct CRITSECT* cs = critsecs_get_unix(c);
- #else
- struct CRITSECT* cs= (*(struct CRITSECT**)c);
- #endif
- // struct CRITSECT* cs=(struct CRITSECT*)c;
- dbgprintf("DeleteCriticalSection(0x%x)n",c);
- if (!cs)
- {
- dbgprintf("Win32 Warning: Deleting uninitialized Critical Section %p!!n", c);
- return;
- }
- if (cs->locked)
- {
- dbgprintf("Win32 Warning: Deleting unlocked Critical Section %p!!n", c);
- pthread_mutex_unlock(&(cs->mutex));
- }
- #ifndef GARBAGE
- pthread_mutex_destroy(&(cs->mutex));
- // released by GarbageCollector in my_relase otherwise
- #endif
- my_release(cs);
- #ifdef CRITSECS_NEWTYPE
- {
- int i = critsecs_get_pos(c);
- if (i < 0)
- {
- printf("DeleteCriticalSection(%p) error (critsec not found)n", c);
- return;
- }
- critsecs_list[i].cs_win = NULL;
- expfree(critsecs_list[i].cs_unix);
- critsecs_list[i].cs_unix = NULL;
- dbgprintf("DeleteCriticalSection -> itemno=%dn", i);
- }
- #endif
- return;
- }
- static int WINAPI expGetCurrentThreadId()
- {
- dbgprintf("GetCurrentThreadId() => %dn", pthread_self());
- return pthread_self();
- }
- static int WINAPI expGetCurrentProcess()
- {
- dbgprintf("GetCurrentProcess() => %dn", getpid());
- return getpid();
- }
- #ifdef QTX
- // this version is required for Quicktime codecs (.qtx/.qts) to work.
- // (they assume some pointers at FS: segment)
- extern void* fs_seg;
- //static int tls_count;
- static int tls_use_map[64];
- static int WINAPI expTlsAlloc()
- {
- int i;
- for(i=0; i<64; i++)
- if(tls_use_map[i]==0)
- {
- tls_use_map[i]=1;
- dbgprintf("TlsAlloc() => %dn",i);
- return i;
- }
- dbgprintf("TlsAlloc() => -1 (ERROR)n");
- return -1;
- }
- //static int WINAPI expTlsSetValue(DWORD index, void* value)
- static int WINAPI expTlsSetValue(int index, void* value)
- {
- dbgprintf("TlsSetValue(%d,0x%x) => 1n",index,value);
- // if((index<0) || (index>64))
- if((index>=64))
- return 0;
- *(void**)((char*)fs_seg+0x88+4*index) = value;
- return 1;
- }
- static void* WINAPI expTlsGetValue(DWORD index)
- {
- dbgprintf("TlsGetValue(%d)n",index);
- // if((index<0) || (index>64))
- if((index>=64)) return NULL;
- return *(void**)((char*)fs_seg+0x88+4*index);
- }
- 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;
- }
- #else
- struct 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%xn", 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%xn", 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) => %dn", index, result);
- return result;
- }
- #endif
- static void* WINAPI expLocalAlloc(int flags, int size)
- {
- void* z = my_mreq(size, (flags & GMEM_ZEROINIT));
- if (z == 0)
- printf("LocalAlloc() failedn");
- dbgprintf("LocalAlloc(%d, flags 0x%x) => 0x%xn", 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 MODIFYn");
- return (void *)handle;
- }
- oldsize = my_size((void *)handle);
- newpointer = my_realloc((void *)handle,size);
- dbgprintf("LocalReAlloc(%x %d(old %d), flags 0x%x) => 0x%xn", handle,size,oldsize, flags,newpointer);
- return newpointer;
- }
- static void* WINAPI expLocalLock(void* z)
- {
- dbgprintf("LocalLock(0x%x) => 0x%xn", 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() failedn");
- dbgprintf("GlobalAlloc(%d, flags 0x%x) => 0x%xn", size, flags, z);
- return z;
- }
- static void* WINAPI expGlobalLock(void* z)
- {
- dbgprintf("GlobalLock(0x%x) => 0x%xn", z, z);
- return z;
- }
- // pvmjpg20 - but doesn't work anyway
- static 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)
- {
- dbgprintf("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(0x%x)n", amem);
- return size;
- }
- static int WINAPI expLoadIconA( long hinstance, char *name )
- {
- dbgprintf("LoadIconA( %ld, 0x%x ) => 1n",hinstance,name);
- return 1;
- }
- 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%x, id 0x%x, buffer 0x%x, size %d) => %d ( %s )n",
- instance, id, buf, size, result, buf);
- // else
- // dbgprintf("LoadStringA(instance 0x%x, id 0x%x, buffer 0x%x, size %d) => %dn",
- // 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 %d, flags 0x%x, string 0x%x='%s',"
- "size %d, dest buffer 0x%x, dest size %d) => %dn",
- v1, v2, s1, s1, siz1, s2, siz2, result);
- else
- dbgprintf("MultiByteToWideChar(codepage %d, flags 0x%x, string NULL,"
- "size %d, dest buffer 0x%x, dest size %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 %d, flags 0x%x, src 0x%x, src size %d, "
- "dest 0x%x, dest size %d, defch 0x%x, used_defch 0x%x)", v1, v2, s1, siz1, s2, siz2, c3, siz3);
- result=WideCharToMultiByte(v1, v2, s1, siz1, s2, siz2, c3, siz3);
- dbgprintf("=> %dn", result);
- //if(s1)wch_print(s1);
- if(s2)dbgprintf(" dest: %sn", s2);
- return result;
- }
- static long WINAPI expGetVersionExA(OSVERSIONINFOA* c)
- {
- dbgprintf("GetVersionExA(0x%x) => 1n");
- 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: 4n Minor version: 0n Build number: 0x4000457n"
- " Platform Id: VER_PLATFORM_WIN32_NTn 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;
- /*
- printf("CreateSemaphoreA(%p = %s)n", name, (name ? name : "<null>"));
- pp=mlist;
- while(pp)
- {
- printf("%p => ", pp);
- pp=pp->prev;
- }
- printf("0n");
- */
- if(mlist!=NULL)
- {
- mutex_list* pp=mlist;
- if(name!=NULL)
- do
- {
- if((strcmp(pp->name, name)==0) && (pp->type==1))
- {
- dbgprintf("CreateSemaphoreA(0x%x, init_count %d, max_count %d, name 0x%x='%s') => 0x%xn",
- 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 %pn", 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 failuren");
- if(name)
- dbgprintf("CreateSemaphoreA(0x%x, init_count %d, max_count %d, name 0x%x='%s') => 0x%xn",
- v1, init_count, max_count, name, name, mlist);
- else
- dbgprintf("CreateSemaphoreA(0x%x, init_count %d, max_count %d, name 0) => 0x%xn",
- 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%x, increment %d, prev_count 0x%x) => 1n",
- 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%x, subkey %s, reserved %d, access 0x%x, pnewkey 0x%x) => %dn",
- key, subkey, reserved, access, newkey, result);
- if(newkey)dbgprintf(" New key: 0x%xn", *newkey);
- return result;
- }
- static long WINAPI expRegCloseKey(long key)
- {
- long result=RegCloseKey(key);
- dbgprintf("RegCloseKey(0x%x) => %dn", 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%x, value %s, reserved 0x%x, data 0x%x, count 0x%x)"
- " => 0x%xn", key, value, reserved, data, count, result);
- if(data && count)dbgprintf(" read %d bytes: '%s'n", *count, data);
- return result;
- }
- //from wine source dlls/advapi32/registry.c
- static long WINAPI expRegCreateKeyA(long hkey, const char* name, int *retkey)
- {
- dbgprintf("RegCreateKeyA(key 0x%x, name 0x%x='%s',newkey=0x%x)n",hkey,name,retkey);
- return RegCreateKeyExA( hkey, name, 0, NULL,REG_OPTION_NON_VOLATILE,
- KEY_ALL_ACCESS , NULL, retkey, NULL );
- }
- 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%x, name 0x%x='%s', reserved=0x%x,"
- " 0x%x, 0x%x, 0x%x, newkey=0x%x, status=0x%x) => %dn",
- key, name, name, reserved, classs, options, security, sec_attr, newkey, status, result);
- if(!result && newkey) dbgprintf(" New key: 0x%xn", *newkey);
- if(!result && status) dbgprintf(" New key status: 0x%xn", *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%x, name '%s', 0x%x, 0x%x, data 0x%x -> 0x%x '%s', size=%d) => %d",
- key, name, v1, v2, data, *(int*)data, 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%x, subkey '%s', 0x%x) => %dn",
- hKey, lpSubKey, phkResult, result);
- if(!result && phkResult) dbgprintf(" New key: 0x%xn", *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(0x%x) => 1 ( %Ld )n", z, *z);
- return 1;
- }
- /*
- * dummy function RegQueryInfoKeyA(), required by vss codecs
- */
- static DWORD WINAPI expRegQueryInfoKeyA( HKEY hkey, LPSTR class, LPDWORD class_len, LPDWORD reserved,
- LPDWORD subkeys, LPDWORD max_subkey, LPDWORD max_class,
- LPDWORD values, LPDWORD max_value, LPDWORD max_data,
- LPDWORD security, FILETIME *modif )
- {
- return ERROR_SUCCESS;
- }
- /*
- * 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++ = ' ';
- /* skip any leading spaces */
- while (*value==' ') value++;
- if ((s=strchr(value,'n')))
- *s=' ';
- 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()
- {
- static double ofreq=0.0;
- int i;
- int x,y;
- i=time(NULL);
- if (ofreq != 0.0) return ofreq;
- while(i==time(NULL));
- x=localcount();
- i++;
- while(i==time(NULL));
- y=localcount();
- ofreq = (double)(y-x)/1000.;
- return ofreq;
- }
- static double CPU_Freq()
- {
- double freq;
- if ((freq = linux_cpuinfo_freq()) > 0)
- return freq;
- if ((freq = solaris_kstat_freq()) > 0)
- return freq;
- return tsc_freq();
- }
- static long WINAPI expQueryPerformanceFrequency(long long* z)
- {
- *z=(long long)CPU_Freq();
- dbgprintf("QueryPerformanceFrequency(0x%x) => 1 ( %Ld )n", z, *z);
- return 1;
- }
- static long WINAPI exptimeGetTime()
- {
- struct timeval t;
- long result;
- gettimeofday(&t, 0);
- result=1000*t.tv_sec+t.tv_usec/1000;
- dbgprintf("timeGetTime() => %dn", result);
- return result;
- }
- static void* WINAPI expLocalHandle(void* v)
- {
- dbgprintf("LocalHandle(0x%x) => 0x%xn", v, v);
- return v;
- }
- static void* WINAPI expGlobalHandle(void* v)
- {
- dbgprintf("GlobalHandle(0x%x) => 0x%xn", v, v);
- return v;
- }
- static int WINAPI expGlobalUnlock(void* v)
- {
- dbgprintf("GlobalUnlock(0x%x) => 1n", v);
- return 1;
- }
- static void* WINAPI expGlobalFree(void* v)
- {
- dbgprintf("GlobalFree(0x%x) => 0n", v);
- my_release(v);
- //free(v);
- return 0;
- }
- static void* WINAPI expGlobalReAlloc(void* v, int size, int flags)
- {
- void* result=my_realloc(v, size);
- //void* result=realloc(v, size);
- dbgprintf("GlobalReAlloc(0x%x, size %d, flags 0x%x) => 0x%xn", v,size,flags,result);
- return result;
- }
- static int WINAPI expLocalUnlock(void* v)
- {
- dbgprintf("LocalUnlock(0x%x) => 1n", v);
- return 1;
- }
- //
- static void* WINAPI expLocalFree(void* v)
- {
- dbgprintf("LocalFree(0x%x) => 0n", v);
- my_release(v);
- return 0;
- }
- static HRSRC WINAPI expFindResourceA(HMODULE module, char* name, char* type)
- {
- HRSRC result;
- result=FindResourceA(module, name, type);
- dbgprintf("FindResourceA(module 0x%x, name 0x%x(%s), type 0x%x(%s)) => 0x%xn",
- module, name, HIWORD(name) ? name : "UNICODE", type, HIWORD(type) ? type : "UNICODE", result);
- return result;
- }
- extern HRSRC WINAPI LoadResource(HMODULE, HRSRC);
- static HGLOBAL WINAPI expLoadResource(HMODULE module, HRSRC res)
- {
- HGLOBAL result=LoadResource(module, res);
- dbgprintf("LoadResource(module 0x%x, resource 0x%x) => 0x%xn", module, res, result);
- return result;
- }
- static void* WINAPI expLockResource(long res)
- {
- void* result=LockResource(res);
- dbgprintf("LockResource(0x%x) => 0x%xn", res, result);
- return result;
- }
- static int WINAPI expFreeResource(long res)
- {
- int result=FreeResource(res);
- dbgprintf("FreeResource(0x%x) => %dn", res, result);
- return result;
- }
- //bool fun(HANDLE)
- //!0 on success
- static int WINAPI expCloseHandle(long v1)
- {
- dbgprintf("CloseHandle(0x%x) => 1n", v1);
- /* do not close stdin,stdout and stderr */
- if (v1 > 2)
- if (!close(v1))
- return 0;
- return 1;
- }
- static const char* WINAPI expGetCommandLineA()
- {
- dbgprintf("GetCommandLineA() => "c:\aviplay.exe"n");
- return "c:\aviplay.exe";
- }
- static short envs[]={'p', 'a', 't', 'h', ' ', 'c', ':', '\', 0, 0};
- static LPWSTR WINAPI expGetEnvironmentStringsW()
- {
- dbgprintf("GetEnvironmentStringsW() => 0n", envs);
- return 0;
- }
- static void * WINAPI expRtlZeroMemory(void *p, size_t len)
- {
- void* result=memset(p,0,len);
- dbgprintf("RtlZeroMemory(0x%x, len %d) => 0x%xn",p,len,result);
- return result;
- }
- static void * WINAPI expRtlMoveMemory(void *dst, void *src, size_t len)
- {
- void* result=memmove(dst,src,len);
- dbgprintf("RtlMoveMemory (dest 0x%x, src 0x%x, len %d) => 0x%xn",dst,src,len,result);
- return result;
- }
- static void * WINAPI expRtlFillMemory(void *p, int ch, size_t len)
- {
- void* result=memset(p,ch,len);
- dbgprintf("RtlFillMemory(0x%x, char 0x%x, len %d) => 0x%xn",p,ch,len,result);
- return result;
- }
- static int WINAPI expFreeEnvironmentStringsW(short* strings)
- {
- dbgprintf("FreeEnvironmentStringsW(0x%x) => 1n", strings);
- return 1;
- }
- static int WINAPI expFreeEnvironmentStringsA(char* strings)
- {
- dbgprintf("FreeEnvironmentStringsA(0x%x) => 1n", strings);
- return 1;
- }
- static const char ch_envs[]=
- "__MSVCRT_HEAP_SELECT=__GLOBAL_HEAP_SELECTED,1rn"
- "PATH=C:\;C:\windows\;C:\windows\systemrn";
- static LPCSTR WINAPI expGetEnvironmentStrings()
- {
- dbgprintf("GetEnvironmentStrings() => 0x%xn", ch_envs);
- return (LPCSTR)ch_envs;
- // dbgprintf("GetEnvironmentStrings() => 0n");
- // return 0;
- }
- static int WINAPI expGetStartupInfoA(STARTUPINFOA *s)
- {
- int i;
- dbgprintf("GetStartupInfoA(0x%x) => 1n");
- memset(s, 0, sizeof(*s));
- s->cb=sizeof(*s);
- // s->lpReserved="Reserved";
- // s->lpDesktop="Desktop";
- // s->lpTitle="Title";
- // s->dwX=s->dwY=0;
- // s->dwXSize=s->dwYSize=200;
- s->dwFlags=s->wShowWindow=1;
- // s->hStdInput=s->hStdOutput=s->hStdError=0x1234;
- dbgprintf(" cb=%dn", s->cb);
- dbgprintf(" lpReserved='%s'n", s->lpReserved);
- dbgprintf(" lpDesktop='%s'n", s->lpDesktop);
- dbgprintf(" lpTitle='%s'n", s->lpTitle);
- dbgprintf(" dwX=%d dwY=%d dwXSize=%d dwYSize=%dn",
- s->dwX, s->dwY, s->dwXSize, s->dwYSize);
- dbgprintf(" dwXCountChars=%d dwYCountChars=%d dwFillAttribute=%dn",
- s->dwXCountChars, s->dwYCountChars, s->dwFillAttribute);
- dbgprintf(" dwFlags=0x%x wShowWindow=0x%x cbReserved2=0x%xn",
- s->dwFlags, s->wShowWindow, s->cbReserved2);
- dbgprintf(" lpReserved2=0x%x hStdInput=0x%x hStdOutput=0x%x hStdError=0x%xn",
- s->lpReserved2, s->hStdInput, s->hStdOutput, s->hStdError);
- return 1;
- }
- static int WINAPI expGetStdHandle(int z)
- {
- dbgprintf("GetStdHandle(0x%x) => 0x%xn", z+0x1234);
- return z+0x1234;
- }
- #ifdef QTX
- #define FILE_HANDLE_quicktimeqts ((HANDLE)0x444)
- #define FILE_HANDLE_quicktimeqtx ((HANDLE)0x445)
- #endif
- static int WINAPI expGetFileType(int handle)
- {
- dbgprintf("GetFileType(0x%x) => 0x3 = pipen", handle);
- return 0x3;
- }
- #ifdef QTX
- static int WINAPI expGetFileAttributesA(char *filename)
- {
- dbgprintf("GetFileAttributesA(%s) => FILE_ATTR_NORMALn", filename);
- if (strstr(filename, "QuickTime.qts"))
- return FILE_ATTRIBUTE_SYSTEM;
- return FILE_ATTRIBUTE_NORMAL;
- }
- #endif
- static int WINAPI expSetHandleCount(int count)
- {
- dbgprintf("SetHandleCount(0x%x) => 1n", count);
- return 1;
- }
- static int WINAPI expGetACP(void)
- {
- dbgprintf("GetACP() => 0n");
- return 0;
- }
- extern WINE_MODREF *MODULE32_LookupHMODULE(HMODULE m);
- static int WINAPI expGetModuleFileNameA(int module, char* s, int len)
- {
- WINE_MODREF *mr;
- int result;
- //printf("File name of module %X (%s) requestedn", module, s);
- if (module == 0 && len >= 12)
- {
- /* return caller program name */
- strcpy(s, "aviplay.dll");
- result=1;
- }
- else if(s==0)
- result=0;
- else
- if(len<35)
- result=0;
- else
- {
- result=1;
- strcpy(s, "c:\windows\system\");
- mr=MODULE32_LookupHMODULE(module);
- if(mr==0)//oops
- strcat(s, "aviplay.dll");
- else
- if(strrchr(mr->filename, '/')==NULL)
- strcat(s, mr->filename);
- else
- strcat(s, strrchr(mr->filename, '/')+1);
- }
- if(!s)
- dbgprintf("GetModuleFileNameA(0x%x, 0x%x, %d) => %dn",
- module, s, len, result);
- else
- dbgprintf("GetModuleFileNameA(0x%x, 0x%x, %d) => %d ( '%s' )n",
- module, s, len, result, s);
- return result;
- }
- static int WINAPI expSetUnhandledExceptionFilter(void* filter)
- {
- dbgprintf("SetUnhandledExceptionFilter(0x%x) => 1n", filter);
- return 1;//unsupported and probably won't ever be supported
- }
- static int WINAPI expLoadLibraryA(char* name)
- {
- int result = 0;
- char* lastbc;
- int i;
- if (!name)
- return -1;
- // we skip to the last backslash
- // this is effectively eliminating weird characters in
- // the text output windows
- lastbc = strrchr(name, '\');
- if (lastbc)
- {
- int i;
- lastbc++;
- for (i = 0; 1 ;i++)
- {
- name[i] = *lastbc++;
- if (!name[i])
- break;
- }
- }
- if(strncmp(name, "c:\windows\", 11)==0) name += 11;
- if(strncmp(name, ".\", 2)==0) name += 2;
- dbgprintf("Entering LoadLibraryA(%s)n", name);
- // PIMJ and VIVO audio are loading kernel32.dll
- if (strcasecmp(name, "kernel32.dll") == 0 || strcasecmp(name, "kernel32") == 0)
- return MODULE_HANDLE_kernel32;
- // return ERROR_SUCCESS; /* yeah, we have also the kernel32 calls */
- /* exported -> do not return failed! */
- if (strcasecmp(name, "user32.dll") == 0 || strcasecmp(name, "user32") == 0)
- // return MODULE_HANDLE_kernel32;
- return MODULE_HANDLE_user32;
- #ifdef QTX
- if (strcasecmp(name, "wininet.dll") == 0 || strcasecmp(name, "wininet") == 0)
- return MODULE_HANDLE_wininet;
- if (strcasecmp(name, "ddraw.dll") == 0 || strcasecmp(name, "ddraw") == 0)
- return MODULE_HANDLE_ddraw;
- if (strcasecmp(name, "advapi32.dll") == 0 || strcasecmp(name, "advapi32") == 0)
- return MODULE_HANDLE_advapi32;
- #endif
- if (strcasecmp(name, "comdlg32.dll") == 0 || strcasecmp(name, "comdlg32") == 0)
- return MODULE_HANDLE_comdlg32;
- if (strcasecmp(name, "msvcrt.dll") == 0 || strcasecmp(name, "msvcrt") == 0)
- return MODULE_HANDLE_msvcrt;
- if (strcasecmp(name, "ole32.dll") == 0 || strcasecmp(name, "ole32") == 0)
- return MODULE_HANDLE_ole32;
- if (strcasecmp(name, "winmm.dll") == 0 || strcasecmp(name, "winmm") == 0)
- return MODULE_HANDLE_winmm;
- result=LoadLibraryA(name);
- dbgprintf("Returned LoadLibraryA(0x%x='%s'), def_path=%s => 0x%xn", name, name, def_path, result);
- return result;
- }
- static int WINAPI expFreeLibrary(int module)
- {
- #ifdef QTX
- int result=0; /* FIXME:XXX: qtx svq3 frees up qt.qts */
- #else
- int result=FreeLibrary(module);
- #endif
- dbgprintf("FreeLibrary(0x%x) => %dn", module, result);
- return result;
- }
- static void* WINAPI expGetProcAddress(HMODULE mod, char* name)
- {
- void* result;
- switch(mod){
- case MODULE_HANDLE_kernel32:
- result=LookupExternalByName("kernel32.dll", name); break;
- case MODULE_HANDLE_user32:
- result=LookupExternalByName("user32.dll", name); break;
- #ifdef QTX
- case MODULE_HANDLE_wininet:
- result=LookupExternalByName("wininet.dll", name); break;
- case MODULE_HANDLE_ddraw:
- result=LookupExternalByName("ddraw.dll", name); break;
- case MODULE_HANDLE_advapi32:
- result=LookupExternalByName("advapi32.dll", name); break;
- #endif
- case MODULE_HANDLE_comdlg32:
- result=LookupExternalByName("comdlg32.dll", name); break;
- case MODULE_HANDLE_msvcrt:
- result=LookupExternalByName("msvcrt.dll", name); break;
- case MODULE_HANDLE_ole32:
- result=LookupExternalByName("ole32.dll", name); break;
- case MODULE_HANDLE_winmm:
- result=LookupExternalByName("winmm.dll", name); break;
- default:
- result=GetProcAddress(mod, name);
- }
- dbgprintf("GetProcAddress(0x%x, '%s') => 0x%xn", mod, name, result);
- return result;
- }
- static long WINAPI expCreateFileMappingA(int hFile, void* lpAttr,
- long flProtect, long dwMaxHigh,
- long dwMaxLow, const char* name)
- {
- long result=CreateFileMappingA(hFile, lpAttr, flProtect, dwMaxHigh, dwMaxLow, name);
- if(!name)
- dbgprintf("CreateFileMappingA(file 0x%x, lpAttr 0x%x,"
- "flProtect 0x%x, dwMaxHigh 0x%x, dwMaxLow 0x%x, name 0) => %dn",
- hFile, lpAttr, flProtect, dwMaxHigh, dwMaxLow, result);
- else
- dbgprintf("CreateFileMappingA(file 0x%x, lpAttr 0x%x,"
- "flProtect 0x%x, dwMaxHigh 0x%x, dwMaxLow 0x%x, name 0x%x='%s') => %dn",
- hFile, lpAttr, flProtect, dwMaxHigh, dwMaxLow, name, name, result);
- return result;
- }
- static long WINAPI expOpenFileMappingA(long hFile, long hz, const char* name)
- {
- long result=OpenFileMappingA(hFile, hz, name);
- if(!name)
- dbgprintf("OpenFileMappingA(0x%x, 0x%x, 0) => %dn",
- hFile, hz, result);
- else
- dbgprintf("OpenFileMappingA(0x%x, 0x%x, 0x%x='%s') => %dn",
- hFile, hz, name, name, result);
- return result;
- }
- static void* WINAPI expMapViewOfFile(HANDLE file, DWORD mode, DWORD offHigh,
- DWORD offLow, DWORD size)
- {
- dbgprintf("MapViewOfFile(0x%x, 0x%x, 0x%x, 0x%x, size %d) => 0x%xn",
- file,mode,offHigh,offLow,size,(char*)file+offLow);
- return (char*)file+offLow;
- }
- static void* WINAPI expUnmapViewOfFile(void* view)
- {
- dbgprintf("UnmapViewOfFile(0x%x) => 0n", view);
- return 0;
- }
- static void* WINAPI expSleep(int time)
- {
- #if HAVE_NANOSLEEP
- /* solaris doesn't have thread safe usleep */
- struct timespec tsp;
- tsp.tv_sec = time / 1000000;
- tsp.tv_nsec = (time % 1000000) * 1000;
- nanosleep(&tsp, NULL);
- #else
- usleep(time);
- #endif
- dbgprintf("Sleep(%d) => 0n", time);
- return 0;
- }
- // why does IV32 codec want to call this? I don't know ...
- static int WINAPI expCreateCompatibleDC(int hdc)
- {
- int dc = 0;//0x81;
- //dbgprintf("CreateCompatibleDC(%d) => 0x81n", hdc);
- dbgprintf("CreateCompatibleDC(%d) => %dn", hdc, dc);
- return dc;
- }
- static int WINAPI expGetDeviceCaps(int hdc, int unk)
- {
- dbgprintf("GetDeviceCaps(0x%x, %d) => 0n", hdc, unk);
- #ifdef QTX
- #define BITSPIXEL 12
- #define PLANES 14
- if (unk == BITSPIXEL)
- return 24;
- if (unk == PLANES)
- return 1;
- #endif
- return 1;
- }
- static WIN_BOOL WINAPI expDeleteDC(int hdc)
- {
- dbgprintf("DeleteDC(0x%x) => 0n", hdc);
- if (hdc == 0x81)
- return 1;
- return 0;
- }
- static WIN_BOOL WINAPI expDeleteObject(int hdc)
- {
- dbgprintf("DeleteObject(0x%x) => 1n", hdc);
- /* FIXME - implement code here */
- return 1;
- }
- /* btvvc32.drv wants this one */
- static void* WINAPI expGetWindowDC(int hdc)
- {
- dbgprintf("GetWindowDC(%d) => 0x0n", hdc);
- return 0;
- }
- #ifdef QTX
- static int WINAPI expGetWindowRect(HWND win, RECT *r)
- {
- dbgprintf("GetWindowRect(0x%x, 0x%x) => 1n", win, r);
- /* (win == 0) => desktop */
- r->right = PSEUDO_SCREEN_WIDTH;
- r->left = 0;
- r->bottom = PSEUDO_SCREEN_HEIGHT;
- r->top = 0;
- return 1;
- }
- static int WINAPI expMonitorFromWindow(HWND win, int flags)
- {
- dbgprintf("MonitorFromWindow(0x%x, 0x%x) => 0n", win, flags);
- return 0;
- }
- static int WINAPI expMonitorFromRect(RECT *r, int flags)
- {
- dbgprintf("MonitorFromRect(0x%x, 0x%x) => 0n", r, flags);
- return 0;
- }
- static int WINAPI expMonitorFromPoint(void *p, int flags)
- {
- dbgprintf("MonitorFromPoint(0x%x, 0x%x) => 0n", p, flags);
- return 0;
- }
- static int WINAPI expEnumDisplayMonitors(void *dc, RECT *r,
- int WINAPI (*callback_proc)(), void *callback_param)
- {
- dbgprintf("EnumDisplayMonitors(0x%x, 0x%x, 0x%x, 0x%x) => ?n",
- dc, r, callback_proc, callback_param);
- return callback_proc(0, dc, r, callback_param);
- }
- #if 0
- typedef struct tagMONITORINFO {
- DWORD cbSize;
- RECT rcMonitor;
- RECT rcWork;
- DWORD dwFlags;
- } MONITORINFO, *LPMONITORINFO;
- #endif
- #define CCHDEVICENAME 8
- typedef struct tagMONITORINFOEX {
- DWORD cbSize;
- RECT rcMonitor;
- RECT rcWork;
- DWORD dwFlags;
- TCHAR szDevice[CCHDEVICENAME];
- } MONITORINFOEX, *LPMONITORINFOEX;
- static int WINAPI expGetMonitorInfoA(void *mon, LPMONITORINFO lpmi)
- {
- dbgprintf("GetMonitorInfoA(0x%x, 0x%x) => 1n", mon, lpmi);
- lpmi->rcMonitor.right = lpmi->rcWork.right = PSEUDO_SCREEN_WIDTH;
- lpmi->rcMonitor.left = lpmi->rcWork.left = 0;
- lpmi->rcMonitor.bottom = lpmi->rcWork.bottom = PSEUDO_SCREEN_HEIGHT;
- lpmi->rcMonitor.top = lpmi->rcWork.top = 0;
- lpmi->dwFlags = 1; /* primary monitor */
- if (lpmi->cbSize == sizeof(MONITORINFOEX))
- {
- LPMONITORINFOEX lpmiex = (LPMONITORINFOEX)lpmi;
- dbgprintf("MONITORINFOEX!n");
- strncpy(lpmiex->szDevice, "Monitor1", CCHDEVICENAME);
- }
- return 1;
- }
- static int WINAPI expEnumDisplayDevicesA(const char *device, int devnum,
- void *dispdev, int flags)
- {
- dbgprintf("EnumDisplayDevicesA(0x%x = %s, %d, 0x%x, %x) => 1n",
- device, device, devnum, dispdev, flags);
- return 1;
- }
- static int WINAPI expIsWindowVisible(HWND win)
- {
- dbgprintf("IsWindowVisible(0x%x) => 1n", win);
- return 1;
- }
- static HWND WINAPI expGetActiveWindow(void)
- {
- dbgprintf("GetActiveWindow() => 0n");
- return (HWND)0;
- }
- static int WINAPI expGetClassNameA(HWND win, LPTSTR classname, int maxcount)
- {
- strncat(classname, "QuickTime", maxcount);
- dbgprintf("GetClassNameA(0x%x, 0x%x, %d) => %dn",
- win, classname, maxcount, strlen(classname));
- return strlen(classname);
- }
- #define LPWNDCLASS void *
- static int WINAPI expGetClassInfoA(HINSTANCE inst, LPCSTR classname, LPWNDCLASS wndclass)
- {
- dbgprintf("GetClassInfoA(0x%x, 0x%x = %s, 0x%x) => 1n", inst,
- classname, classname, wndclass);
- return 1;
- }
- static int WINAPI expGetWindowLongA(HWND win, int index)
- {
- dbgprintf("GetWindowLongA(0x%x, %d) => 0n", win, index);
- return 1;
- }
- static int WINAPI expGetObjectA(HGDIOBJ hobj, int objsize, LPVOID obj)
- {
- dbgprintf("GetObjectA(0x%x, %d, 0x%x) => %dn", hobj, objsize, obj, objsize);
- return objsize;
- }
- static int WINAPI expCreateRectRgn(int x, int y, int width, int height)
- {
- dbgprintf("CreateRectRgn(%d, %d, %d, %d) => 0n", x, y, width, height);
- return 0;
- }
- static int WINAPI expEnumWindows(int (*callback_func)(), void *callback_param)
- {
- int i, i2;
- dbgprintf("EnumWindows(0x%x, 0x%x) => 1n", callback_func, callback_param);
- i = callback_func(0, callback_param);
- i2 = callback_func(1, callback_param);
- return i && i2;
- }
- static int WINAPI expGetWindowThreadProcessId(HWND win, int *pid_data)
- {
- int tid = pthread_self();
- dbgprintf("GetWindowThreadProcessId(0x%x, 0x%x) => %dn",
- win, pid_data, tid);
- if (pid_data)
- *(int*)pid_data = tid;
- return tid;
- }
- //HWND WINAPI CreateWindowExA(DWORD,LPCSTR,LPCSTR,DWORD,INT,INT,
- // INT,INT,HWND,HMENU,HINSTANCE,LPVOID);
- static HWND WINAPI expCreateWindowExA(int exstyle, const char *classname,
- const char *winname, int style, int x, int y, int w, int h,
- HWND parent, HMENU menu, HINSTANCE inst, LPVOID param)
- {
- printf("CreateWindowEx() calledn");
- dbgprintf("CreateWindowEx(%d, 0x%x = %s, 0x%x = %s, %d, %d, %d, %d, %d, 0x%x, 0x%x, 0x%x, 0x%x) => 1n",
- exstyle, classname, classname, winname, winname, style, x, y, w, h,
- parent, menu, inst, param);