summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMiguel Freitas <miguelfreitas@users.sourceforge.net>2001-11-07 02:15:24 +0000
committerMiguel Freitas <miguelfreitas@users.sourceforge.net>2001-11-07 02:15:24 +0000
commit258777b8039c78817611fefe656cef7ec8c79ef1 (patch)
tree1e837271e500be1175d80c051adfdbd2a70b8044 /src
parent4eecee172b445460e94271f69b70ffc6330c47d4 (diff)
downloadxine-lib-258777b8039c78817611fefe656cef7ec8c79ef1.tar.gz
xine-lib-258777b8039c78817611fefe656cef7ec8c79ef1.tar.bz2
- update win32 loader
- dynamic buffers fixes a lot of audio problems CVS patchset: 974 CVS date: 2001/11/07 02:15:24
Diffstat (limited to 'src')
-rw-r--r--src/libw32dll/w32codec.c99
-rw-r--r--src/libw32dll/wine/Makefile.am4
-rw-r--r--src/libw32dll/wine/afl.c96
-rw-r--r--src/libw32dll/wine/com.h76
-rw-r--r--src/libw32dll/wine/debugtools.h36
-rw-r--r--src/libw32dll/wine/driver.c216
-rw-r--r--src/libw32dll/wine/driver.h16
-rw-r--r--src/libw32dll/wine/elfdll.c28
-rw-r--r--src/libw32dll/wine/ext.c213
-rw-r--r--src/libw32dll/wine/ldt_keeper.c232
-rw-r--r--src/libw32dll/wine/ldt_keeper.h15
-rw-r--r--src/libw32dll/wine/loader.h30
-rw-r--r--src/libw32dll/wine/module.c298
-rw-r--r--src/libw32dll/wine/msacm.h5
-rw-r--r--src/libw32dll/wine/pe_image.c82
-rw-r--r--src/libw32dll/wine/registry.c115
-rw-r--r--src/libw32dll/wine/registry.h37
-rw-r--r--src/libw32dll/wine/resource.c13
-rw-r--r--src/libw32dll/wine/stubs.s16
-rw-r--r--src/libw32dll/wine/vfw.h49
-rw-r--r--src/libw32dll/wine/win32.c2141
-rw-r--r--src/libw32dll/wine/win32.h46
-rw-r--r--src/libw32dll/wine/windef.h8
-rw-r--r--src/libw32dll/wine/wineacm.h27
-rw-r--r--src/libw32dll/wine/winnt.h2
25 files changed, 2768 insertions, 1132 deletions
diff --git a/src/libw32dll/w32codec.c b/src/libw32dll/w32codec.c
index 78974e26a..4c0f57c9d 100644
--- a/src/libw32dll/w32codec.c
+++ b/src/libw32dll/w32codec.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: w32codec.c,v 1.30 2001/09/26 01:18:19 guenter Exp $
+ * $Id: w32codec.c,v 1.31 2001/11/07 02:15:25 miguelfreitas Exp $
*
* routines for using w32 codecs
*
@@ -43,6 +43,9 @@
extern char* win32_codec_name;
extern char* win32_def_path;
+#define AUDIO_BUF_SIZE 16384
+#define AUDIO_OUTBUF_SIZE 300000
+
typedef struct w32v_decoder_s {
video_decoder_t video_decoder;
@@ -71,9 +74,9 @@ typedef struct w32a_decoder_s {
int output_open;
int decoder_ok;
- unsigned char buf[16384];
+ unsigned char *buf;
int size;
- unsigned char sample_buf[40000];
+ unsigned char *sample_buf;
HACMSTREAM srcstream;
int rec_audio_src_size;
int num_channels;
@@ -176,6 +179,8 @@ static char* get_vids_codec_name(w32v_decoder_t *this,
this->yuv_supported=0;
this->yuv_hack_needed=0;
this->flipped=0;
+
+ buf_type &= 0xffff0000;
switch (buf_type) {
case BUF_VIDEO_MSMPEG4_V12:
@@ -284,7 +289,7 @@ static void w32v_init_codec (w32v_decoder_t *this, int buf_type) {
w32v_init_rgb_ycc();
- printf ("init codec...\n");
+ printf ("w32codec: init codec...\n");
memset(&this->o_bih, 0, sizeof(BITMAPINFOHEADER));
this->o_bih.biSize = sizeof(BITMAPINFOHEADER);
@@ -303,7 +308,7 @@ static void w32v_init_codec (w32v_decoder_t *this, int buf_type) {
ICMODE_FASTDECOMPRESS);
if(!this->hic){
- printf ("ICOpen failed! unknown codec %08lx / wrong parameters?\n",
+ printf ("w32codec: ICOpen failed! unknown codec %08lx / wrong parameters?\n",
this->bih.biCompression);
this->decoder_ok = 0;
return;
@@ -311,7 +316,7 @@ static void w32v_init_codec (w32v_decoder_t *this, int buf_type) {
ret = ICDecompressGetFormat(this->hic, &this->bih, &this->o_bih);
if(ret){
- printf("ICDecompressGetFormat (%.4s %08lx/%d) failed: Error %ld\n",
+ printf("w32codec: ICDecompressGetFormat (%.4s %08lx/%d) failed: Error %ld\n",
(char*)&this->o_bih.biCompression,
this->bih.biCompression,
this->bih.biBitCount,
@@ -343,14 +348,14 @@ static void w32v_init_codec (w32v_decoder_t *this, int buf_type) {
ret = ICDecompressQuery(this->hic, &this->bih, &this->o_bih);
if(ret){
- printf("ICDecompressQuery failed: Error %ld\n", (long)ret);
+ printf("w32codec: ICDecompressQuery failed: Error %ld\n", (long)ret);
this->decoder_ok = 0;
return;
}
ret = ICDecompressBegin(this->hic, &this->bih, &this->o_bih);
if(ret){
- printf("ICDecompressBegin failed: Error %ld\n", (long)ret);
+ printf("w32codec: ICDecompressBegin failed: Error %ld\n", (long)ret);
this->decoder_ok = 0;
return;
}
@@ -376,10 +381,11 @@ static void w32v_decode_data (video_decoder_t *this_gen, buf_element_t *buf) {
buf->decoder_info[0]=%d\n",
buf->type, buf, buf->decoder_info[0]);
*/
-
if (buf->decoder_info[0] == 0) {
+ if ( buf->type & 0xff )
+ return;
+
/* init package containing bih */
-
memcpy ( &this->bih, buf->content, sizeof (BITMAPINFOHEADER));
this->video_step = buf->decoder_info[1];
@@ -479,7 +485,7 @@ static void w32v_decode_data (video_decoder_t *this_gen, buf_element_t *buf) {
img->PTS = buf->PTS;
if(ret) {
- printf("Error decompressing frame, err=%ld\n", (long)ret);
+ printf("w32codec: Error decompressing frame, err=%ld\n", (long)ret);
img->bad_frame = 1;
} else
img->bad_frame = 0;
@@ -531,11 +537,14 @@ static int w32a_can_handle (audio_decoder_t *this_gen, int buf_type) {
return ( (codec == BUF_AUDIO_DIVXA) ||
(codec == BUF_AUDIO_MSADPCM) ||
(codec == BUF_AUDIO_IMAADPCM) ||
+ (codec == BUF_AUDIO_ACELPNET) ||
(codec == BUF_AUDIO_MSGSM) );
}
static char* get_auds_codec_name(w32a_decoder_t *this, int buf_type) {
+ buf_type = buf_type & 0xFFFF0000;
+
switch (buf_type) {
case BUF_AUDIO_DIVXA:
return "divxa32.acm";
@@ -543,6 +552,8 @@ static char* get_auds_codec_name(w32a_decoder_t *this, int buf_type) {
return "msadp32.acm";
case BUF_AUDIO_IMAADPCM:
return "imaadp32.acm";
+ case BUF_AUDIO_ACELPNET:
+ return "acelpdec.ax";
case BUF_AUDIO_MSGSM:
return "msgsm32.acm";
}
@@ -558,6 +569,8 @@ static void w32a_init (audio_decoder_t *this_gen, ao_instance_t *audio_out) {
this->audio_out = audio_out;
this->output_open = 0;
this->decoder_ok = 0;
+
+ this->buf = this->sample_buf = NULL;
}
static int w32a_init_audio (w32a_decoder_t *this,
@@ -566,8 +579,9 @@ static int w32a_init_audio (w32a_decoder_t *this,
HRESULT ret;
static WAVEFORMATEX wf;
- /* long in_size=in_fmt_->nBlockAlign; */
+ long in_size=in_fmt_->nBlockAlign;
static WAVEFORMATEX *in_fmt;
+ unsigned long srcsize;
in_fmt = (WAVEFORMATEX *) malloc (64);
@@ -583,7 +597,7 @@ static int w32a_init_audio (w32a_decoder_t *this,
16, in_fmt->nSamplesPerSec,
(in_fmt->nChannels == 2) ? AO_CAP_MODE_STEREO : AO_CAP_MODE_MONO);
if (!this->output_open) {
- printf("ACM_Decoder: Cannot open audio output device\n");
+ printf("w32codec: (ACM_Decoder) Cannot open audio output device\n");
return 0;
}
@@ -602,22 +616,31 @@ static int w32a_init_audio (w32a_decoder_t *this,
NULL,0,0,0);
if(ret){
if(ret==ACMERR_NOTPOSSIBLE)
- printf("ACM_Decoder: Unappropriate audio format\n");
+ printf("w32codec: (ACM_Decoder) Unappropriate audio format\n");
else
- printf("ACM_Decoder: acmStreamOpen error %d", (int) ret);
+ printf("w32codec: (ACM_Decoder) acmStreamOpen error %d", (int) ret);
this->srcstream = 0;
return 0;
}
- /*
acmStreamSize(this->srcstream, in_size, &srcsize, ACM_STREAMSIZEF_SOURCE);
- printf("Audio buffer min. size: %d\n",srcsize);
- */
-
- acmStreamSize(this->srcstream, 16384, (LPDWORD) &this->rec_audio_src_size,
+ printf("w32codec: Audio buffer min. size: %d\n",(int)srcsize);
+ srcsize*=2;
+ if(!srcsize)
+ srcsize=16384;
+
+ acmStreamSize(this->srcstream, srcsize, (LPDWORD) &this->rec_audio_src_size,
ACM_STREAMSIZEF_DESTINATION);
- /* printf("recommended source buffer size: %d\n", this->rec_audio_src_size); */
+ printf("w32codec: Recommended source buffer size: %d\n", this->rec_audio_src_size);
+ if( this->buf )
+ free(this->buf);
+ if( this->sample_buf )
+ free(this->sample_buf);
+
+ this->buf = malloc( 2 * this->rec_audio_src_size );
+ this->sample_buf = malloc( srcsize );
+
this->size = 0;
return 1;
@@ -635,7 +658,9 @@ static void w32a_decode_audio (w32a_decoder_t *this,
memcpy (&this->buf[this->size], data, nSize);
this->size += nSize;
-
+ if( this->size > 2 * this->rec_audio_src_size )
+ printf("w32codec: buffer overflow on w32a_decode_audio\n");
+
while (this->size >= this->rec_audio_src_size) {
memset(&ash, 0, sizeof(ash));
@@ -645,10 +670,10 @@ static void w32a_decode_audio (w32a_decoder_t *this,
ash.pbSrc=this->buf;
ash.cbSrcLength=this->rec_audio_src_size;
ash.pbDst=this->sample_buf;
- ash.cbDstLength=20000;
+ ash.cbDstLength=AUDIO_OUTBUF_SIZE;
hr=acmStreamPrepareHeader(this->srcstream,&ash,0);
if(hr){
- printf("ACM_Decoder: acmStreamPrepareHeader error %d\n",(int)hr);
+ printf("w32codec: (ACM_Decoder) acmStreamPrepareHeader error %d\n",(int)hr);
return;
}
@@ -661,7 +686,7 @@ static void w32a_decode_audio (w32a_decoder_t *this,
hr=acmStreamConvert(this->srcstream,&ash,0);
if(hr){
- /* printf("acmStreamConvert error %d, used %d bytes\n",hr,ash.cbSrcLengthUsed); */
+ printf("w32codec: acmStreamConvert error %d, used %d bytes\n",(int)hr,(int)ash.cbSrcLengthUsed);
ash.cbSrcLengthUsed = this->rec_audio_src_size;
} else {
/*
@@ -683,23 +708,13 @@ static void w32a_decode_audio (w32a_decoder_t *this,
if(ash.cbSrcLengthUsed>=this->size){
this->size=0;
} else {
- unsigned char *pSrc, *pDst;
- int i;
-
this->size-=ash.cbSrcLengthUsed;
-
- pSrc = &this->buf [ash.cbSrcLengthUsed];
- pDst = this->buf;
- for (i=0; i<this->size; i++) {
- *pDst = *pSrc;
- pDst ++;
- pSrc ++;
- }
+ memmove( this->buf, &this->buf [ash.cbSrcLengthUsed], this->size);
}
hr=acmStreamUnprepareHeader(this->srcstream,&ash,0);
if(hr){
- printf("ACM_Decoder: acmStreamUnprepareHeader error %d\n",(int)hr);
+ printf("w32codec: (ACM_Decoder) acmStreamUnprepareHeader error %d\n",(int)hr);
}
}
}
@@ -732,7 +747,14 @@ static void w32a_close (audio_decoder_t *this_gen) {
this->audio_out->close (this->audio_out);
this->output_open = 0;
}
-
+ if( this->buf ) {
+ free(this->buf);
+ this->buf = NULL;
+ }
+ if( this->sample_buf ) {
+ free(this->sample_buf);
+ this->sample_buf = NULL;
+ }
}
static char *w32a_get_id(void) {
@@ -773,6 +795,7 @@ audio_decoder_t *init_audio_decoder_plugin (int iface_version, config_values_t *
w32a_decoder_t *this ;
+
if (iface_version != 2) {
printf( "w32codec: plugin doesn't support plugin API version %d.\n"
"w32codec: this means there's a version mismatch between xine and this "
diff --git a/src/libw32dll/wine/Makefile.am b/src/libw32dll/wine/Makefile.am
index 10f65ffa0..ac7f113ea 100644
--- a/src/libw32dll/wine/Makefile.am
+++ b/src/libw32dll/wine/Makefile.am
@@ -19,7 +19,7 @@ endif
libwine_la_SOURCES = afl.c elfdll.c module.c pe_resource.c \
resource.c win32.c driver.c ext.c \
- pe_image.c registry.c vfl.c
+ pe_image.c registry.c vfl.c ldt_keeper.c
libwine_la_LIBADD = stubs.lo
noinst_HEADERS = avifmt.h elfdll.h msacm.h pshpack1.h winbase.h \
@@ -28,7 +28,7 @@ noinst_HEADERS = avifmt.h elfdll.h msacm.h pshpack1.h winbase.h \
pshpack4.h windows.h winuser.h debugtools.h mmreg.h \
pe_image.h pshpack8.h winerror.h driver.h module.h \
poppack.h vfw.h loader.h registry.h win32.h \
- wineacm.h winestring.h resource.h
+ wineacm.h winestring.h resource.h ldt_keeper.h com.h
stubs.lo: stubs.s
$(CC) -c $(top_srcdir)/src/libw32dll/wine/stubs.s -o stubs.lo
diff --git a/src/libw32dll/wine/afl.c b/src/libw32dll/wine/afl.c
index 9e009d331..e43c0ec02 100644
--- a/src/libw32dll/wine/afl.c
+++ b/src/libw32dll/wine/afl.c
@@ -21,9 +21,6 @@
***************************************************************************/
#include "config.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include "winbase.h"
#include "windef.h"
@@ -34,14 +31,21 @@
#include "winerror.h"
#include "msacm.h"
#include "msacmdrv.h"
-#include "debugtools.h"
#include "wineacm.h"
+#include "ext.h"
+#include "driver.h"
+#include "debugtools.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#pragma pack(1)
#define OpenDriverA DrvOpen
#define CloseDriver DrvClose
-static PWINE_ACMSTREAM ACM_GetStream(HACMSTREAM has)
+extern char *win32_codec_name;
+
+static inline PWINE_ACMSTREAM ACM_GetStream(HACMSTREAM has)
{
return (PWINE_ACMSTREAM)has;
}
@@ -70,7 +74,7 @@ MMRESULT WINAPI acmDriverAddA(PHACMDRIVERID phadid, HINSTANCE hinstModule,
* LoadDriver on it, to be sure we can call SendDriverMessage on the
* hDrvr handle.
*/
- *phadid = (HACMDRIVERID) MSACM_RegisterDriver(NULL, NULL, hinstModule);
+ *phadid = (HACMDRIVERID) MSACM_RegisterDriver(NULL, 0, hinstModule);
/* FIXME: lParam, dwPriority and fdwAdd ignored */
@@ -187,8 +191,7 @@ MMRESULT WINAPI acmDriverOpen(PHACMDRIVER phad, HACMDRIVERID hadid, DWORD fdwOpe
PWINE_ACMDRIVERID padid;
PWINE_ACMDRIVER pad;
ICOPEN icopen;
- /* HDRVR hdrv; */
-
+ HDRVR hdrv;
TRACE("(%p, %x, %08lu)\n", phad, hadid, fdwOpen);
@@ -204,7 +207,8 @@ MMRESULT WINAPI acmDriverOpen(PHACMDRIVER phad, HACMDRIVERID hadid, DWORD fdwOpe
return MMSYSERR_INVALFLAG;
pad = HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMDRIVER));
- if (!pad) return MMSYSERR_NOMEM;
+ if (!pad)
+ return MMSYSERR_NOMEM;
pad->obj.pACMDriverID = padid;
icopen.fccType = mmioFOURCC('a', 'u', 'd', 'c');
@@ -212,7 +216,8 @@ MMRESULT WINAPI acmDriverOpen(PHACMDRIVER phad, HACMDRIVERID hadid, DWORD fdwOpe
icopen.dwSize = sizeof(ICOPEN);
icopen.dwFlags = 0;
- if (!padid->hInstModule)
+ icopen.pV1Reserved = padid->pszFileName;
+ if (!padid->hInstModule)
pad->hDrvr = OpenDriverA((long)&icopen);
else
pad->hDrvr = padid->hInstModule;
@@ -221,7 +226,7 @@ MMRESULT WINAPI acmDriverOpen(PHACMDRIVER phad, HACMDRIVERID hadid, DWORD fdwOpe
HeapFree(MSACM_hHeap, 0, pad);
return MMSYSERR_ERROR;
}
-
+
pad->pfnDriverProc = GetProcAddress(pad->hDrvr, "DriverProc");
/* insert new pad at beg of list */
@@ -230,7 +235,7 @@ MMRESULT WINAPI acmDriverOpen(PHACMDRIVER phad, HACMDRIVERID hadid, DWORD fdwOpe
/* FIXME: Create a WINE_ACMDRIVER32 */
*phad = (HACMDRIVER)pad;
-
+
return MMSYSERR_NOERROR;
}
@@ -264,22 +269,19 @@ PWINE_ACMDRIVERID MSACM_pLastACMDriverID = NULL;
/***********************************************************************
* MSACM_RegisterDriver32()
*/
-PWINE_ACMDRIVERID MSACM_RegisterDriver(LPSTR pszDriverAlias, LPSTR pszFileName,
+PWINE_ACMDRIVERID MSACM_RegisterDriver(const char* pszFileName,
+ WORD wFormatTag,
HINSTANCE hinstModule)
-//
-// File names are stored in driver.c. I reuse this variable to store driver ID
-// in it. If it's <0x10000, it is primary codec for corresponding format.
-//
-{
+{
PWINE_ACMDRIVERID padid;
- TRACE("('%s', '%s', 0x%08x)\n", pszDriverAlias, pszFileName, hinstModule);
+ TRACE("('%s', '%x', 0x%08x)\n", pszFileName, wFormatTag, hinstModule);
padid = (PWINE_ACMDRIVERID) HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMDRIVERID));
- padid->pszDriverAlias = (char*)malloc(strlen(pszDriverAlias)+1);
- strcpy(padid->pszDriverAlias, pszDriverAlias);
+ padid->pszFileName = (char*)malloc(strlen(pszFileName)+1);
+ strcpy(padid->pszFileName, pszFileName);
// 1~strdup(pszDriverAlias);
- padid->pszFileName = pszFileName;
+ padid->wFormatTag = wFormatTag;
padid->hInstModule = hinstModule;
padid->bEnabled = TRUE;
padid->pACMDriverList = NULL;
@@ -294,23 +296,6 @@ PWINE_ACMDRIVERID MSACM_RegisterDriver(LPSTR pszDriverAlias, LPSTR pszFileName,
return padid;
}
-/***********************************************************************
- * MSACM_RegisterAllDrivers32()
- */
-void MSACM_RegisterAllDrivers(void)
-{
- /* LPSTR pszBuffer; */
- /* DWORD dwBufferLength; */
-
- if (MSACM_pFirstACMDriverID)
- return;
-
- MSACM_RegisterDriver("divxa32", (LPSTR)0x161, 0); // DivX/WMA [07]
- MSACM_RegisterDriver("msadp32", (LPSTR)0x2, 0); // MS ADPCM [08]
- MSACM_RegisterDriver("l3codeca", (LPSTR)0x55, 0); // MPEG Layer-3 [12]
-// MSACM_RegisterDriver("imaadp32", (LPSTR)0x11, 0); // IMA ADPCM [13]
-// MSACM_RegisterDriver("msgsm32", (LPSTR)0x32, 0); // MS GSM 6.10 [14]
-}
/***********************************************************************
* MSACM_UnregisterDriver32()
@@ -322,10 +307,8 @@ PWINE_ACMDRIVERID MSACM_UnregisterDriver(PWINE_ACMDRIVERID p)
while (p->pACMDriverList)
acmDriverClose((HACMDRIVER) p->pACMDriverList, 0);
- if (p->pszDriverAlias)
- HeapFree(MSACM_hHeap, 0, p->pszDriverAlias);
-// if (p->pszFileName)
-// HeapFree(MSACM_hHeap, 0, p->pszFileName);
+ if (p->pszFileName)
+ free(p->pszFileName);
if (p == MSACM_pFirstACMDriverID)
MSACM_pFirstACMDriverID = p->pNextACMDriverID;
@@ -414,7 +397,6 @@ MMRESULT WINAPI acmStreamOpen(PHACMSTREAM phas, HACMDRIVER had, PWAVEFORMATEX pw
was = HeapAlloc(MSACM_hHeap, 0, sizeof(*was) + wfxSrcSize + wfxDstSize + ((pwfltr) ? sizeof(WAVEFILTER) : 0));
if (was == NULL)
return MMSYSERR_NOMEM;
-
was->drvInst.cbStruct = sizeof(was->drvInst);
was->drvInst.pwfxSrc = (PWAVEFORMATEX)((LPSTR)was + sizeof(*was));
memcpy(was->drvInst.pwfxSrc, pwfxSrc, wfxSrcSize);
@@ -448,7 +430,7 @@ MMRESULT WINAPI acmStreamOpen(PHACMSTREAM phas, HACMDRIVER had, PWAVEFORMATEX pw
goto errCleanUp;
} else {
PWINE_ACMDRIVERID wadi;
- /* short drv_tag; */
+ short drv_tag;
ret = ACMERR_NOTPOSSIBLE;
/* if(pwfxSrc->wFormatTag==1)//compression
drv_tag=pwfxDst->wFormatTag;
@@ -474,10 +456,22 @@ MMRESULT WINAPI acmStreamOpen(PHACMSTREAM phas, HACMDRIVER had, PWAVEFORMATEX pw
}
}
acmDriverClose(had, 0L);*/
- if(MSACM_pFirstACMDriverID==NULL)
- MSACM_RegisterAllDrivers();
+ //if(MSACM_pFirstACMDriverID==NULL)
+ // MSACM_RegisterAllDrivers();
+
+ for (wadi = MSACM_pFirstACMDriverID; wadi; wadi = wadi->pNextACMDriverID)
+ {
+ /* Check Format */
+ if ((int)wadi->wFormatTag != (int)pwfxSrc->wFormatTag) continue;
+ }
+ if( !wadi )
+ MSACM_RegisterDriver(win32_codec_name, (int)pwfxSrc->wFormatTag, 0);
- for (wadi = MSACM_pFirstACMDriverID; wadi; wadi = wadi->pNextACMDriverID) {
+ for (wadi = MSACM_pFirstACMDriverID; wadi; wadi = wadi->pNextACMDriverID)
+ {
+ /* Check Format */
+ if ((int)wadi->wFormatTag != (int)pwfxSrc->wFormatTag) continue;
+
ret = acmDriverOpen(&had, (HACMDRIVERID)wadi, 0L);
if (ret == MMSYSERR_NOERROR) {
if ((wad = MSACM_GetDriver(had)) != 0) {
@@ -486,6 +480,8 @@ MMRESULT WINAPI acmStreamOpen(PHACMSTREAM phas, HACMDRIVER had, PWAVEFORMATEX pw
was->hAcmDriver = had;
ret = SendDriverMessage(wad->hDrvr, ACMDM_STREAM_OPEN, (DWORD)&was->drvInst, 0L);
+ //lhacm - crash printf("RETOPEN %d\n", ret);
+ //ret = 0;
if (ret == MMSYSERR_NOERROR) {
if (fdwOpen & ACM_STREAMOPENF_QUERY) {
acmDriverClose(had, 0L);
@@ -507,6 +503,7 @@ MMRESULT WINAPI acmStreamOpen(PHACMSTREAM phas, HACMDRIVER had, PWAVEFORMATEX pw
if (phas)
*phas = (HACMSTREAM)was;
TRACE("=> (%d)\n", ret);
+ CodecAlloc();
return ret;
}
errCleanUp:
@@ -533,6 +530,7 @@ MMRESULT WINAPI acmStreamClose(HACMSTREAM has, DWORD fdwClose)
if (was->hAcmDriver)
acmDriverClose(was->hAcmDriver, 0L);
HeapFree(MSACM_hHeap, 0, was);
+ CodecRelease();
}
TRACE("=> (%d)\n", ret);
return ret;
@@ -549,7 +547,7 @@ MMRESULT WINAPI acmStreamConvert(HACMSTREAM has, PACMSTREAMHEADER pash,
PACMDRVSTREAMHEADER padsh;
TRACE("(0x%08x, %p, %ld)\n", has, pash, fdwConvert);
-
+
if ((was = ACM_GetStream(has)) == NULL)
return MMSYSERR_INVALHANDLE;
if (!pash || pash->cbStruct < sizeof(ACMSTREAMHEADER))
diff --git a/src/libw32dll/wine/com.h b/src/libw32dll/wine/com.h
new file mode 100644
index 000000000..10d8bbf08
--- /dev/null
+++ b/src/libw32dll/wine/com.h
@@ -0,0 +1,76 @@
+#ifndef AVIFILE_COM_H
+#define AVIFILE_COM_H
+
+#include <inttypes.h>
+
+/**
+ * Internal functions and structures for COM emulation code.
+ */
+
+#ifndef WIN32
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void* CoTaskMemAlloc(unsigned long cb);
+void CoTaskMemFree(void* cb);
+
+#ifndef GUID_TYPE
+#define GUID_TYPE
+typedef struct
+{
+ uint32_t f1;
+ uint16_t f2;
+ uint16_t f3;
+ uint8_t f4[8];
+} GUID;
+#endif
+
+extern GUID IID_IUnknown;
+extern GUID IID_IClassFactory;
+
+typedef long (*GETCLASSOBJECT) (GUID* clsid, GUID* iid, void** ppv);
+int RegisterComClass(GUID* clsid, GETCLASSOBJECT gcs);
+int UnregisterComClass(GUID* clsid, GETCLASSOBJECT gcs);
+
+#ifndef STDCALL
+#define STDCALL __attribute__((__stdcall__))
+#endif
+
+struct IUnknown;
+struct IClassFactory;
+struct IUnknown_vt
+{
+ long STDCALL (*QueryInterface)(struct IUnknown* _this, GUID* iid, void** ppv);
+ long STDCALL (*AddRef)(struct IUnknown* _this) ;
+ long STDCALL (*Release)(struct IUnknown* _this) ;
+} ;
+struct IUnknown
+{
+ struct IUnknown_vt* vt;
+};
+
+struct IClassFactory_vt
+{
+ long STDCALL (*QueryInterface)(struct IUnknown* _this, GUID* iid, void** ppv);
+ long STDCALL (*AddRef)(struct IUnknown* _this) ;
+ long STDCALL (*Release)(struct IUnknown* _this) ;
+ long STDCALL (*CreateInstance)(struct IClassFactory* _this, struct IUnknown* pUnkOuter, GUID* riid, void** ppvObject);
+};
+
+struct IClassFactory
+{
+ struct IClassFactory_vt* vt;
+};
+
+long CoCreateInstance(GUID* rclsid, struct IUnknown* pUnkOuter,
+ long dwClsContext, GUID* riid, void** ppv);
+
+#ifdef __cplusplus
+};
+#endif /* __cplusplus */
+
+#endif /* WIN32 */
+
+#endif /* AVIFILE_COM_H */
diff --git a/src/libw32dll/wine/debugtools.h b/src/libw32dll/wine/debugtools.h
index 98e963246..58f4bb876 100644
--- a/src/libw32dll/wine/debugtools.h
+++ b/src/libw32dll/wine/debugtools.h
@@ -2,6 +2,8 @@
#ifndef __WINE_DEBUGTOOLS_H
#define __WINE_DEBUGTOOLS_H
+//#ifdef __WINE__ /* Debugging interface is internal to Wine */
+
#include <stdarg.h>
#include "config.h"
#include "windef.h"
@@ -9,7 +11,7 @@
struct _GUID;
#define TRACE __vprintf
-#define dbg_printf __vprintf
+#define dbg_printf __vprintf
/* Internal definitions (do not use these directly) */
@@ -70,27 +72,13 @@ extern int dbg_printf(const char *format, ...) __attribute__((format (printf,1,2
extern int dbg_printf(const char *format, ...);
#endif
-#ifdef __GNUC__
-#define TRACE_(X, Y...)
-#define WARN_(X, Y...)
-#define WARN(X,Y...)
-#define ERR(X,Y...)
-#define FIXME(X,Y...)
-#define DPRINTF(X,Y...)
-#define MESSAGE(X,Y...)
-#define ERR_(X,Y...)
-#define FIXME_(X,Y...)
-#else
-#define WARN_(...)
-#define WARN(...)
-#define TRACE_(...)
-#define ERR(...)
-#define FIXME(...)
-#define DPRINTF(...)
-#define MESSAGE(...)
-#define ERR_(...)
-#define FIXME_(...)
-#endif
+#define TRACE_(X) TRACE
+#define WARN_(X) TRACE
+#define WARN TRACE
+#define ERR_(X) printf
+#define ERR printf
+#define FIXME_(X) TRACE
+#define FIXME TRACE
#define TRACE_ON(X) 1
#define ERR_ON(X) 1
@@ -100,5 +88,9 @@ extern int dbg_printf(const char *format, ...);
#define DEFAULT_DEBUG_CHANNEL(ch) \
extern char dbch_##ch[]; static char * const __dbch_default = dbch_##ch;
+#define DPRINTF dbg_printf
+#define MESSAGE dbg_printf
+
+//#endif /* __WINE__ */
#endif /* __WINE_DEBUGTOOLS_H */
diff --git a/src/libw32dll/wine/driver.c b/src/libw32dll/wine/driver.c
index 08f5f745c..4a67fb343 100644
--- a/src/libw32dll/wine/driver.c
+++ b/src/libw32dll/wine/driver.c
@@ -1,27 +1,44 @@
#include "config.h"
-#include <stdio.h>
-
-#ifdef HAVE_MALLOC_H
-#include <malloc.h>
-#else
-#include <stdlib.h>
-#endif
#include "driver.h"
#include "pe_image.h"
#include "winreg.h"
#include "vfw.h"
-#include "win32.h"
#include "registry.h"
+#include "ldt_keeper.h"
+#include "ext.h"
+#include "win32.h"
+#include "driver.h"
+#include "debugtools.h"
-#ifdef __FreeBSD__
-#include <sys/time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
#endif
+// #define DETAILED_OUT
+
+char* win32_codec_name=NULL; // must be set before calling DrvOpen() !!!
+char* win32_def_path =NULL; // must be set before calling DrvOpen() !!!
+
#if 1
-#define STORE_ALL /**/
-#define REST_ALL /**/
+
+/*
+ * STORE_ALL/REST_ALL seems like an attempt to workaround problems due to
+ * WINAPI/no-WINAPI bustage.
+ *
+ * There should be no need for the STORE_ALL/REST_ALL hack once all
+ * function definitions agree with their prototypes (WINAPI-wise) and
+ * we make sure, that we do not call these functions without a proper
+ * prototype in scope.
+ */
+
+#define STORE_ALL
+#define REST_ALL
#else
+// this asm code doesn't work - why ???
+// kabi@i.am
#define STORE_ALL \
__asm__ ( \
"push %%ebx\n\t" \
@@ -39,17 +56,14 @@
"pop %%ebx\n\t"::)
#endif
-
-
static DWORD dwDrvID = 0;
-
LRESULT WINAPI SendDriverMessage( HDRVR hDriver, UINT message,
- LPARAM lParam1, LPARAM lParam2 )
+ LPARAM lParam1, LPARAM lParam2 )
{
DRVR* module=(DRVR*)hDriver;
int result;
-#ifdef DETAILED_OUT
+#ifdef DETAILED_OUT
printf("SendDriverMessage: driver %X, message %X, arg1 %X, arg2 %X\n", hDriver, message, lParam1, lParam2);
#endif
if(module==0)return -1;
@@ -58,112 +72,134 @@ LRESULT WINAPI SendDriverMessage( HDRVR hDriver, UINT message,
STORE_ALL;
result=module->DriverProc(module->dwDriverID,1,message,lParam1,lParam2);
REST_ALL;
-#ifdef DETAILED_OUT
+#ifdef DETAILED_OUT
printf("\t\tResult: %X\n", result);
-#endif
+#endif
return result;
-}
+}
-static NPDRVR DrvAlloc(HDRVR*lpDriver, LPUINT lpDrvResult)
+static NPDRVR DrvAlloc(HDRVR* lpDriver, LPUINT lpDrvResult)
{
- NPDRVR npDriver;
/* allocate and lock handle */
+ *lpDrvResult = MMSYSERR_INVALPARAM;
if (lpDriver)
{
- if ( (*lpDriver = (HDRVR) malloc(sizeof(DRVR))) )
- {
- if ((npDriver = (NPDRVR) *lpDriver))
- {
- *lpDrvResult = MMSYSERR_NOERROR;
- return (npDriver);
- }
- free((NPDRVR)*lpDriver);
- }
- return (*lpDrvResult = MMSYSERR_NOMEM, (NPDRVR) 0);
+ if ((*lpDriver = (HDRVR) malloc(sizeof(DRVR))) != 0 )
+ {
+ memset((void*)*lpDriver, 0, sizeof(DRVR));
+ *lpDrvResult = MMSYSERR_NOERROR;
+ return (NPDRVR) *lpDriver;
+ }
+ *lpDrvResult = MMSYSERR_NOMEM;
}
- return (*lpDrvResult = MMSYSERR_INVALPARAM, (NPDRVR) 0);
+ return (NPDRVR) 0;
+}
+
+static int needs_free=0;
+void SetCodecPath(const char* path)
+{
+ if(needs_free)free(win32_def_path);
+ if(path==0)
+ {
+ win32_def_path=WIN32_PATH;
+ needs_free=0;
+ return;
+ }
+ win32_def_path=malloc(strlen(path)+1);
+ strcpy(win32_def_path, path);
+ needs_free=1;
}
-
static void DrvFree(HDRVR hDriver)
{
- if(hDriver)
- if(((DRVR*)hDriver)->hDriverModule)
- if(((DRVR*)hDriver)->DriverProc)
- (((DRVR*)hDriver)->DriverProc)(((DRVR*)hDriver)->dwDriverID, hDriver, DRV_CLOSE, 0, 0);
- if(hDriver) {
- if(((DRVR*)hDriver)->hDriverModule)
- if(((DRVR*)hDriver)->DriverProc)
- (((DRVR*)hDriver)->DriverProc)(0, hDriver, DRV_FREE, 0, 0);
- FreeLibrary(((DRVR*)hDriver)->hDriverModule);
- free((NPDRVR)hDriver);
- return;
+ int i;
+
+ Setup_FS_Segment();
+
+ if (hDriver)
+ {
+ if (((DRVR*)hDriver)->hDriverModule)
+ {
+ if (((DRVR*)hDriver)->DriverProc)
+ {
+ (((DRVR*)hDriver)->DriverProc)(((DRVR*)hDriver)->dwDriverID, hDriver, DRV_CLOSE, 0, 0);
+ (((DRVR*)hDriver)->DriverProc)(0, hDriver, DRV_FREE, 0, 0);
+ }
+ FreeLibrary(((DRVR*)hDriver)->hDriverModule);
+ }
+ free((NPDRVR)hDriver);
}
+ return;
}
void DrvClose(HDRVR hdrvr)
{
DrvFree(hdrvr);
+ CodecRelease();
}
-char* win32_codec_name=NULL; // must be set before calling DrvOpen() !!!
-char* win32_def_path =NULL; // must be set before calling DrvOpen() !!!
-
-HDRVR
-DrvOpen(LPARAM lParam2)
+//DrvOpen(LPCSTR lpszDriverName, LPCSTR lpszSectionName, LPARAM lParam2)
+HDRVR DrvOpen(LPARAM lParam2)
{
- // ICOPEN *icopen=(ICOPEN*)lParam2;
UINT uDrvResult;
HDRVR hDriver;
NPDRVR npDriver;
- char unknown[0x24];
-// char* codec_name=icopen->fccHandler;
+ char unknown[0x124];
+ const char* filename = win32_codec_name;
- if (!(npDriver = DrvAlloc(&hDriver, &uDrvResult)))
- return ((HDRVR) 0);
+ npDriver = DrvAlloc(&hDriver, &uDrvResult);
+ if (!npDriver)
+ return (HDRVR) 0;
- if (!(npDriver->hDriverModule = expLoadLibraryA(win32_codec_name))) {
- printf("Can't open library %s\n", win32_codec_name);
- DrvFree(hDriver);
- return ((HDRVR) 0);
+ if (uDrvResult)
+ {
+ DrvFree(hDriver);
+ return (HDRVR) 0;
}
-
- if (!(npDriver->DriverProc = (DRIVERPROC)
- GetProcAddress(npDriver->hDriverModule, "DriverProc"))) {
- printf("Library %s is not a valid codec\n", win32_codec_name);
- FreeLibrary(npDriver->hDriverModule);
- DrvFree(hDriver);
- return ((HDRVR) 0);
+
+ npDriver->hDriverModule = LoadLibraryA(filename);
+
+ if (!npDriver->hDriverModule)
+ {
+ printf("Can't open library %s\n", filename);
+ DrvFree(hDriver);
+ return ((HDRVR) 0);
}
- //TRACE("DriverProc == %X\n", npDriver->DriverProc);
- npDriver->dwDriverID = ++dwDrvID;
+ npDriver->DriverProc = (DRIVERPROC) GetProcAddress(npDriver->hDriverModule,
+ "DriverProc");
+ if (!npDriver->DriverProc)
+ {
+ printf("Library %s is not a valid VfW/ACM codec\n", filename);
+ DrvFree(hDriver);
+ return ((HDRVR) 0);
+ }
- STORE_ALL;
- (npDriver->DriverProc)(0, hDriver, DRV_LOAD, 0, 0);
- REST_ALL;
- //TRACE("DRV_LOAD Ok!\n");
- STORE_ALL;
- (npDriver->DriverProc)(0, hDriver, DRV_ENABLE, 0, 0);
- REST_ALL;
- //TRACE("DRV_ENABLE Ok!\n");
+ TRACE("DriverProc == %X\n", npDriver->DriverProc);
+ npDriver->dwDriverID = ++dwDrvID;
+
+ printf("Loaded DLL driver %s\n", filename);
+
+ Setup_FS_Segment();
- // open driver
STORE_ALL;
- npDriver->dwDriverID=(npDriver->DriverProc)(npDriver->dwDriverID, hDriver, DRV_OPEN,
- (LPARAM) (LPSTR) unknown, lParam2);
+ (npDriver->DriverProc)(0, hDriver, DRV_LOAD, 0, 0);
+ REST_ALL;
+ TRACE("DRV_LOAD Ok!\n");
+ STORE_ALL;
+ (npDriver->DriverProc)(0, hDriver, DRV_ENABLE, 0, 0);
+ REST_ALL;
+ TRACE("DRV_ENABLE Ok!\n");
+
+ // open driver
+ STORE_ALL;
+ npDriver->dwDriverID=(npDriver->DriverProc)(npDriver->dwDriverID, hDriver,
+ DRV_OPEN, (LPARAM) (LPSTR) unknown,
+ lParam2);
REST_ALL;
- //TRACE("DRV_OPEN Ok!(%X)\n", npDriver->dwDriverID);
+ TRACE("DRV_OPEN Ok!(%X)\n", npDriver->dwDriverID);
- if (uDrvResult)
- {
- DrvFree(hDriver);
- hDriver = (HDRVR) 0;
- }
-
- printf("Successfully loaded codec %s\n",win32_codec_name);
-
- return (hDriver);
+ CodecAlloc();
+ return hDriver;
}
-
diff --git a/src/libw32dll/wine/driver.h b/src/libw32dll/wine/driver.h
index e9c9f9d04..545f99c2b 100644
--- a/src/libw32dll/wine/driver.h
+++ b/src/libw32dll/wine/driver.h
@@ -109,7 +109,19 @@ DWORD WINAPI GetDriverFlags( HDRVR hDriver );
#define WINE_GDF_16BIT 0x10000000
#endif
-extern HDRVR DrvOpen(LPARAM lParam2);
-extern void DrvClose(HDRVR hdrvr);
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void SetCodecPath(const char* path);
+void CodecAlloc(void);
+void CodecRelease(void);
+
+HDRVR DrvOpen(LPARAM lParam2);
+void DrvClose(HDRVR hdrvr);
+
+#ifdef __cplusplus
+}
+#endif
#endif /* __WINE_DRIVER_H */
diff --git a/src/libw32dll/wine/elfdll.c b/src/libw32dll/wine/elfdll.c
index b8fe03d74..cc1e9099d 100644
--- a/src/libw32dll/wine/elfdll.c
+++ b/src/libw32dll/wine/elfdll.c
@@ -7,22 +7,19 @@
#ifdef HAVE_LIBDL
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
-
-#include "wine/config.h"
-#include "wine/windef.h"
-//#include "wine/global.h"
-//#include "wine/process.h"
-#include "wine/module.h"
-#include "wine/heap.h"
-#include "wine/elfdll.h"
-#include "wine/debugtools.h"
-#include "wine/winerror.h"
+#include "windef.h"
+#include "module.h"
+#include "heap.h"
+#include "elfdll.h"
+#include "debugtools.h"
+#include "winerror.h"
//DEFAULT_DEBUG_CHANNEL(elfdll)
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
#include <dlfcn.h>
struct modref_list_t;
@@ -40,6 +37,11 @@ modref_list;
extern modref_list* local_wm;
+/*------------------ HACKS -----------------*/
+extern DWORD fixup_imports(WINE_MODREF *wm);
+extern void dump_exports(HMODULE hModule);
+/*---------------- END HACKS ---------------*/
+
//char *extra_ld_library_path = "/usr/lib/win32";
extern char* def_path;
diff --git a/src/libw32dll/wine/ext.c b/src/libw32dll/wine/ext.c
index 85adbc203..5c7576a18 100644
--- a/src/libw32dll/wine/ext.c
+++ b/src/libw32dll/wine/ext.c
@@ -1,5 +1,5 @@
/********************************************************
- *
+ *
*
* Stub functions for Wine module
*
@@ -8,10 +8,10 @@
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
+#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
#include <fcntl.h>
@@ -23,25 +23,37 @@
#include "heap.h"
#include "ext.h"
+#if 0
+//REMOVE SIMPLIFY
+static void* mymalloc(unsigned int size)
+{
+ printf("malloc %d\n", size);
+ return malloc(size);
+}
+
+#undef malloc
+#define malloc mymalloc
+#endif
+
int dbg_header_err( const char *dbg_channel, const char *func )
{
- return 0;
+ return 0;
}
int dbg_header_warn( const char *dbg_channel, const char *func )
{
- return 0;
+ return 0;
}
int dbg_header_fixme( const char *dbg_channel, const char *func )
{
- return 0;
+ return 0;
}
int dbg_header_trace( const char *dbg_channel, const char *func )
{
- return 0;
+ return 0;
}
int dbg_vprintf( const char *format, va_list args )
{
- return 0;
+ return 0;
}
int __vprintf( const char *format, ... )
{
@@ -50,11 +62,10 @@ int __vprintf( const char *format, ... )
va_start(va, format);
vprintf(format, va);
va_end(va);
- fflush(stdout);
#endif
- return 0;
+ return 0;
}
-
+
HANDLE WINAPI GetProcessHeap(void)
{
return 1;
@@ -62,17 +73,22 @@ HANDLE WINAPI GetProcessHeap(void)
LPVOID WINAPI HeapAlloc(HANDLE heap, DWORD flags, DWORD size)
{
- if(flags & 0x8)
- return calloc(size, 1);
- else
- return malloc(size);
+ //static int i = 5;
+ void* m = (flags & 0x8) ? calloc(size, 1) : malloc(size);
+ //printf("HeapAlloc %p %d (%d)\n", m, size, flags);
+ //if (--i == 0)
+ // abort();
+ return m;
}
WIN_BOOL WINAPI HeapFree(HANDLE heap, DWORD flags, LPVOID mem)
{
- free(mem);
+ if (mem) free(mem);
+ //printf("HeapFree %p\n", mem);
+ //if (!mem)
+ // abort();
return 1;
-}
+}
static int last_error;
@@ -81,29 +97,29 @@ DWORD WINAPI GetLastError(void)
return last_error;
}
-void WINAPI SetLastError(DWORD error)
-{
+VOID WINAPI SetLastError(DWORD error)
+{
last_error=error;
-}
+}
WIN_BOOL WINAPI ReadFile(HANDLE handle, LPVOID mem, DWORD size, LPDWORD result, LPOVERLAPPED flags)
{
*result=read(handle, mem, size);
return *result;
-}
+}
INT WINAPI lstrcmpiA(LPCSTR c1, LPCSTR c2)
{
return strcasecmp(c1,c2);
}
-char* WINAPI lstrcpynA(char* dest, const char* src, int num)
+LPSTR WINAPI lstrcpynA(LPSTR dest, LPCSTR src, INT num)
{
return strncpy(dest,src,num);
}
-int WINAPI lstrlenA(const char* s)
+INT WINAPI lstrlenA(LPCSTR s)
{
return strlen(s);
-}
-int WINAPI lstrlenW(LPCWSTR s)
+}
+INT WINAPI lstrlenW(LPCWSTR s)
{
int l;
if(!s)
@@ -115,7 +131,7 @@ int WINAPI lstrlenW(LPCWSTR s)
}
LPSTR WINAPI lstrcpynWtoA(LPSTR dest, LPCWSTR src, INT count)
{
- LPSTR retval = dest;
+ LPSTR result = dest;
int moved=0;
if((dest==0) || (src==0))
return 0;
@@ -128,14 +144,16 @@ LPSTR WINAPI lstrcpynWtoA(LPSTR dest, LPCWSTR src, INT count)
src++;
dest++;
}
- return retval;
+ return result;
}
int wcsnicmp(const unsigned short* s1, const unsigned short* s2, int n)
{
+ /*
if(s1==0)
- return 0;
+ return;
if(s2==0)
- return 0;
+ return;
+ */
while(n>0)
{
if(*s1<*s2)
@@ -151,9 +169,8 @@ int wcsnicmp(const unsigned short* s1, const unsigned short* s2, int n)
n--;
}
return 0;
-}
-
-
+}
+
WIN_BOOL WINAPI IsBadReadPtr(LPCVOID data, UINT size)
{
if(size==0)
@@ -161,7 +178,7 @@ WIN_BOOL WINAPI IsBadReadPtr(LPCVOID data, UINT size)
if(data==NULL)
return 1;
return 0;
-}
+}
LPSTR HEAP_strdupA(HANDLE heap, DWORD flags, LPCSTR string)
{
// return strdup(string);
@@ -176,12 +193,12 @@ LPWSTR HEAP_strdupAtoW(HANDLE heap, DWORD flags, LPCSTR string)
if(string==0)
return 0;
size=strlen(string);
- answer=malloc(size+size+2);
+ answer=malloc(2 * (size + 1));
for(i=0; i<=size; i++)
answer[i]=(short)string[i];
- return answer;
+ return answer;
}
-char* HEAP_strdupWtoA(HANDLE heap, DWORD flags, LPCWSTR string)
+LPSTR HEAP_strdupWtoA(HANDLE heap, DWORD flags, LPCWSTR string)
{
int size, i;
char* answer;
@@ -193,7 +210,7 @@ char* HEAP_strdupWtoA(HANDLE heap, DWORD flags, LPCWSTR string)
answer=malloc(size+2);
for(i=0; i<=size; i++)
answer[i]=(char)string[i];
- return answer;
+ return answer;
}
/***********************************************************************
@@ -249,9 +266,9 @@ LPVOID FILE_dommap( int unix_handle, LPVOID start,
MAP_PRIVATE | MAP_FIXED, fd, offset_low )) != (LPVOID)-1)
{
// printf("address %08x\n", *(int*)ret);
-// printf("%x\n", ret);
+// printf("%x\n", ret);
return ret;
- }
+ }
// printf("mmap %d\n", errno);
@@ -303,14 +320,14 @@ int FILE_munmap( LPVOID start, DWORD size_high, DWORD size_low )
printf("offsets larger than 4Gb not supported\n");
return munmap( start, size_low );
}
-//static int mapping_size=0;
+static int mapping_size=0;
struct file_mapping_s;
typedef struct file_mapping_s
{
int mapping_size;
char* name;
- void* handle;
+ LPVOID handle;
struct file_mapping_s* next;
struct file_mapping_s* prev;
}file_mapping;
@@ -329,27 +346,27 @@ static file_mapping* fm=0;
#define PAGE_GUARD 0x100
#define PAGE_NOCACHE 0x200
-HANDLE WINAPI CreateFileMappingA(HANDLE hFile, LPSECURITY_ATTRIBUTES lpAttr,
+HANDLE WINAPI CreateFileMappingA(HANDLE handle, LPSECURITY_ATTRIBUTES lpAttr,
DWORD flProtect,
- DWORD dwMaxHigh, DWORD dwMaxLow,
+ DWORD dwMaxHigh, DWORD dwMaxLow,
LPCSTR name)
{
- int filedesc = (int)hFile;
+ int hFile = (int)handle;
unsigned int len;
- void* answer;
+ LPVOID answer;
int anon=0;
int mmap_access=0;
- if(filedesc<0)
+ if(hFile<0)
{
anon=1;
- filedesc=open("/dev/zero", O_RDWR);
- if(filedesc<0)
+ hFile=open("/dev/zero", O_RDWR);
+ if(hFile<0)
return 0;
- }
+ }
if(!anon)
- {
- len=lseek(filedesc, 0, SEEK_END);
- lseek(filedesc, 0, SEEK_SET);
+ {
+ len=lseek(hFile, 0, SEEK_END);
+ lseek(hFile, 0, SEEK_SET);
}
else len=dwMaxLow;
@@ -357,46 +374,46 @@ HANDLE WINAPI CreateFileMappingA(HANDLE hFile, LPSECURITY_ATTRIBUTES lpAttr,
mmap_access |=PROT_READ;
else
mmap_access |=PROT_READ|PROT_WRITE;
-
- answer=mmap(NULL, len, mmap_access, MAP_PRIVATE, filedesc, 0);
+
+ answer=mmap(NULL, len, mmap_access, MAP_PRIVATE, hFile, 0);
if(anon)
- close(filedesc);
- if(answer!=(void*)-1)
+ close(hFile);
+ if(answer!=(LPVOID)-1)
{
if(fm==0)
{
fm=malloc(sizeof(file_mapping));
fm->prev=NULL;
- }
+ }
else
{
fm->next=malloc(sizeof(file_mapping));
fm->next->prev=fm;
fm=fm->next;
}
- fm->next=NULL;
+ fm->next=NULL;
fm->handle=answer;
if(name)
{
fm->name=malloc(strlen(name)+1);
strcpy(fm->name, name);
- }
+ }
else
fm->name=NULL;
fm->mapping_size=len;
-
+
if(anon)
- close(filedesc);
+ close(hFile);
return (HANDLE)answer;
}
return (HANDLE)0;
-}
+}
WIN_BOOL WINAPI UnmapViewOfFile(LPVOID handle)
{
file_mapping* p;
int result;
if(fm==0)
- return (HANDLE)0;
+ return 0;
for(p=fm; p; p=p->next)
{
if(p->handle==handle)
@@ -410,10 +427,10 @@ WIN_BOOL WINAPI UnmapViewOfFile(LPVOID handle)
fm=p->prev;
free(p);
return result;
- }
+ }
}
- return 0;
-}
+ return 0;
+}
//static int va_size=0;
struct virt_alloc_s;
typedef struct virt_alloc_s
@@ -428,7 +445,7 @@ static virt_alloc* vm=0;
#define MEM_COMMIT 0x00001000
#define MEM_RESERVE 0x00002000
-void* WINAPI VirtualAlloc(void* address, DWORD size, DWORD type, DWORD protection)
+LPVOID WINAPI VirtualAlloc(LPVOID address, DWORD size, DWORD type, DWORD protection)
{
void* answer;
int fd=open("/dev/zero", O_RDWR);
@@ -436,7 +453,7 @@ void* WINAPI VirtualAlloc(void* address, DWORD size, DWORD type, DWORD protecti
// printf("VirtualAlloc(0x%08X, %d)\n", address
if(address!=0)
{
- //check whether we can allow to allocate this
+ //check whether we can allow to allocate this
virt_alloc* str=vm;
while(str)
{
@@ -444,7 +461,7 @@ void* WINAPI VirtualAlloc(void* address, DWORD size, DWORD type, DWORD protecti
{
str=str->prev;
continue;
- }
+ }
if((unsigned)address+size<(unsigned)str->address)
{
str=str->prev;
@@ -458,16 +475,16 @@ void* WINAPI VirtualAlloc(void* address, DWORD size, DWORD type, DWORD protecti
close(fd);
return address; //returning previously reserved memory
}
- return NULL;
+ return NULL;
}
close(fd);
return NULL;
}
- answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
+ answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_FIXED | MAP_PRIVATE, fd, 0);
- }
+ }
else
- answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
+ 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);
@@ -475,7 +492,7 @@ void* WINAPI VirtualAlloc(void* address, DWORD size, DWORD type, DWORD protecti
if(answer==(void*)-1)
{
printf("Error no %d\n", errno);
- printf("VirtualAlloc(0x%08X, %ld) failed\n", (int) address, size);
+ printf("VirtualAlloc(0x%p, %ld) failed\n", address, size);
return NULL;
}
else
@@ -493,41 +510,43 @@ void* WINAPI VirtualAlloc(void* address, DWORD size, DWORD type, DWORD protecti
vm=new_vm;
vm->next=0;
// if(va_size!=0)
-// printf("Multiple VirtualAlloc!\n");
+// 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, DWORD t1, DWORD t2)//not sure
{
virt_alloc* str=vm;
int answer;
while(str)
{
- if(address!=str->address)
- {
- str=str->prev;
- continue;
- }
- 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;
- free(str);
- return 0;
+ if(address!=str->address)
+ {
+ str=str->prev;
+ continue;
+ }
+ 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;
+ free(str);
+ return 0;
}
return -1;
}
-int WINAPI WideCharToMultiByte(UINT codepage, DWORD flags, LPCWSTR src,
+INT WINAPI WideCharToMultiByte(UINT codepage, DWORD flags, LPCWSTR src,
INT srclen,LPSTR dest, INT destlen, LPCSTR defch, WIN_BOOL* used_defch)
{
int i;
if(src==0)
return 0;
- for(i=0; i<srclen; i++)
- printf("%c", src[i]);
- printf("\n");
+ if ((srclen==-1)&&(dest==0)) return 0;
+ 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++)
@@ -536,10 +555,10 @@ int WINAPI WideCharToMultiByte(UINT codepage, DWORD flags, LPCWSTR src,
if(*src==0)
return i+1;
}
- return srclen+1;
- }
+ return srclen+1;
+ }
if(used_defch)
- *used_defch=0;
+ *used_defch=0;
for(i=0; i<min(srclen, destlen); i++)
{
*dest=(char)*src;
@@ -547,7 +566,7 @@ int WINAPI WideCharToMultiByte(UINT codepage, DWORD flags, LPCWSTR src,
src++;
if(*src==0)
return i+1;
- }
+ }
return min(srclen, destlen);
}
INT WINAPI MultiByteToWideChar(UINT codepage,DWORD flags, LPCSTR src, INT srclen,
@@ -569,5 +588,5 @@ HANDLE WINAPI OpenFileMappingA(DWORD access, WIN_BOOL prot, LPCSTR name)
if(strcmp(p->name, name)==0)
return (HANDLE)p->handle;
}
- return 0;
+ return 0;
}
diff --git a/src/libw32dll/wine/ldt_keeper.c b/src/libw32dll/wine/ldt_keeper.c
new file mode 100644
index 000000000..18ddb22ce
--- /dev/null
+++ b/src/libw32dll/wine/ldt_keeper.c
@@ -0,0 +1,232 @@
+/**
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ * This file MUST be in main library because LDT must
+ * be modified before program creates first thread
+ * - avifile includes this file from C++ code
+ * and initializes it at the start of player!
+ */
+
+#include "ldt_keeper.h"
+
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <unistd.h>
+#ifdef __linux__
+#include <asm/unistd.h>
+#include <asm/ldt.h>
+#else
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+#include <machine/sysarch.h>
+#endif
+
+#ifdef __svr4__
+#include <sys/segment.h>
+#include <sys/sysi86.h>
+
+/* solaris x86: add missing prototype for sysi86() */
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern int sysi86(int, void*);
+#ifdef __cplusplus
+}
+#endif
+
+#ifndef NUMSYSLDTS /* SunOS 2.5.1 does not define NUMSYSLDTS */
+#define NUMSYSLDTS 6 /* Let's hope the SunOS 5.8 value is OK */
+#endif
+
+#define TEB_SEL_IDX NUMSYSLDTS
+#endif
+
+#define LDT_ENTRIES 8192
+#define LDT_ENTRY_SIZE 8
+#pragma pack(4)
+struct modify_ldt_ldt_s {
+ unsigned int entry_number;
+ unsigned long base_addr;
+ unsigned int limit;
+ unsigned int seg_32bit:1;
+ unsigned int contents:2;
+ unsigned int read_exec_only:1;
+ unsigned int limit_in_pages:1;
+ unsigned int seg_not_present:1;
+ unsigned int useable:1;
+};
+
+#define MODIFY_LDT_CONTENTS_DATA 0
+#define MODIFY_LDT_CONTENTS_STACK 1
+#define MODIFY_LDT_CONTENTS_CODE 2
+#endif
+
+
+/* user level (privilege level: 3) ldt (1<<2) segment selector */
+#define LDT_SEL(idx) ((idx) << 3 | 1 << 2 | 3)
+
+#ifndef TEB_SEL_IDX
+#define TEB_SEL_IDX 1
+#endif
+#define TEB_SEL LDT_SEL(TEB_SEL_IDX)
+
+/**
+ *
+ * This should be performed before we create first thread. See remarks
+ * for write_ldt(), linux/kernel/ldt.c.
+ *
+ */
+
+static void* fs_seg = NULL;
+static char* prev_struct = NULL;
+/**
+ * here is a small logical problem with Restore for multithreaded programs -
+ * in C++ we use static class for this...
+ */
+
+#ifdef __cplusplus
+extern "C"
+#endif
+void Setup_FS_Segment(void)
+{
+ __asm__ __volatile__(
+ "movl %0,%%eax; movw %%ax, %%fs" : : "i" (TEB_SEL)
+ );
+}
+
+#ifdef __linux__
+/* XXX: why is this routine from libc redefined here? */
+/* NOTE: the redefined version ignores the count param, count is hardcoded as 16 */
+static int LDT_Modify( 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"(16)//sizeof(*ptr) from kernel point of view
+ :"esi" );
+#else
+ __asm__ __volatile__("int $0x80"
+ : "=a" (res)
+ : "0" (__NR_modify_ldt),
+ "b" (func),
+ "c" (ptr),
+ "d"(16)
+ :"esi");
+#endif /* __PIC__ */
+ if (res >= 0) return res;
+ errno = -res;
+ return -1;
+}
+#endif
+
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+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;
+}
+#endif
+
+void Setup_LDT_Keeper(void)
+{
+ struct modify_ldt_ldt_s array;
+ int fd;
+ int ret;
+
+ if (fs_seg)
+ return;
+
+ prev_struct = 0;
+ fd = open("/dev/zero", O_RDWR);
+ fs_seg = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE,
+ fd, 0);
+ if(fs_seg==(void*)-1)
+ {
+ perror("ERROR: Couldn't allocate memory for fs segment");
+ return;
+ }
+ array.base_addr=(int)fs_seg;
+ array.entry_number=TEB_SEL_IDX;
+ 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=LDT_Modify(0x1, &array, sizeof(struct modify_ldt_ldt_s));
+ if(ret<0)
+ {
+ perror("install_fs");
+ printf("Couldn't install fs segment, expect segfault\n");
+ }
+#endif /*linux*/
+
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+ {
+ unsigned long d[2];
+
+ LDT_EntryToBytes( d, &array );
+ ret = i386_set_ldt(array.entry_number, (union descriptor *)d, 1);
+ if (ret < 0)
+ {
+ perror("install_fs");
+ printf("Couldn't install fs segment, expect segfault\n");
+ printf("Did you reconfigure the kernel with \"options USER_LDT\"?\n");
+ }
+ printf("Set_LDT\n");
+ }
+#endif /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ */
+
+#if defined(__svr4__)
+ {
+ struct ssd ssd;
+ ssd.sel = TEB_SEL;
+ ssd.bo = array.base_addr;
+ ssd.ls = array.limit - array.base_addr;
+ ssd.acc1 = ((array.read_exec_only == 0) << 1) |
+ (array.contents << 2) |
+ 0xf0; /* P(resent) | DPL3 | S */
+ ssd.acc2 = 0x4; /* byte limit, 32-bit segment */
+ if (sysi86(SI86DSCR, &ssd) < 0) {
+ perror("sysi86(SI86DSCR)");
+ printf("Couldn't install fs segment, expect segfault\n");
+ }
+ }
+#endif
+
+ Setup_FS_Segment();
+
+ prev_struct = (char*)malloc(sizeof(char) * 8);
+ *(void**)array.base_addr = prev_struct;
+ close(fd);
+}
+
+void Restore_LDT_Keeper(void)
+{
+ if (fs_seg == 0)
+ return;
+ if (prev_struct)
+ free(prev_struct);
+ munmap((char*)fs_seg, getpagesize());
+ fs_seg = 0;
+}
diff --git a/src/libw32dll/wine/ldt_keeper.h b/src/libw32dll/wine/ldt_keeper.h
new file mode 100644
index 000000000..eec7da298
--- /dev/null
+++ b/src/libw32dll/wine/ldt_keeper.h
@@ -0,0 +1,15 @@
+#ifndef LDT_KEEPER_H
+#define LDT_KEEPER_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+void Setup_FS_Segment(void);
+void Setup_LDT_Keeper(void);
+void Restore_LDT_Keeper(void);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LDT_KEEPER_H */
diff --git a/src/libw32dll/wine/loader.h b/src/libw32dll/wine/loader.h
index d26e0d876..172808ce4 100644
--- a/src/libw32dll/wine/loader.h
+++ b/src/libw32dll/wine/loader.h
@@ -1,23 +1,23 @@
/********************************************************
Win32 binary loader interface
- Copyright 2000 Eugene Smith (divx@euro.ru)
+ Copyright 2000 Eugene Kuznetsov (divx@euro.ru)
Shamelessly stolen from Wine project
*********************************************************/
#ifndef _LOADER_H
#define _LOADER_H
-#include <windef.h>
-#include <driver.h>
-#include <mmreg.h>
-#include <vfw.h>
-#include <msacm.h>
+#include "windef.h"
+#include "driver.h"
+#include "mmreg.h"
+#include "vfw.h"
+#include "msacm.h"
+
#ifdef __cplusplus
extern "C" {
#endif
-void SetCodecPath(const char* path);
unsigned int _GetPrivateProfileIntA(const char* appname, const char* keyname, int default_value, const char* filename);
int _GetPrivateProfileStringA(const char* appname, const char* keyname,
const char* def_val, char* dest, unsigned int len, const char* filename);
@@ -30,7 +30,7 @@ int _WritePrivateProfileStringA(const char* appname, const char* keyname,
MS VFW ( Video For Windows ) interface
**********************************************/
-
+#if D_VFW
long VFWAPIV ICCompress(
HIC hic,long dwFlags,LPBITMAPINFOHEADER lpbiOutput,void* lpData,
LPBITMAPINFOHEADER lpbiInput,void* lpBits,long* lpckid,
@@ -40,7 +40,7 @@ long VFWAPIV ICCompress(
long VFWAPIV ICDecompress(HIC hic,long dwFlags,LPBITMAPINFOHEADER lpbiFormat,void* lpData,LPBITMAPINFOHEADER lpbi,void* lpBits);
-WIN_BOOL VFWAPI ICInfo(long fccType, long fccHandler, ICINFO * lpicinfo);
+WIN_BOOL VFWAPI ICInfo(long fccType, long fccHandler, ICINFO * lpicinfo);
LRESULT VFWAPI ICGetInfo(HIC hic,ICINFO *picinfo, long cb);
HIC VFWAPI ICOpen(long fccType, long fccHandler, UINT wMode);
HIC VFWAPI ICOpenFunction(long fccType, long fccHandler, unsigned int wMode, void* lpfnHandler);
@@ -49,8 +49,8 @@ LRESULT VFWAPI ICClose(HIC hic);
LRESULT VFWAPI ICSendMessage(HIC hic, unsigned int msg, long dw1, long dw2);
HIC VFWAPI ICLocate(long fccType, long fccHandler, LPBITMAPINFOHEADER lpbiIn, LPBITMAPINFOHEADER lpbiOut, short wFlags);
-int VFWAPI ICDoSomething(void);
-
+int VFWAPI ICDoSomething();
+#endif // D_VFW
#define ICCompressGetFormat(hic, lpbiInput, lpbiOutput) \
ICSendMessage( \
hic,ICM_COMPRESS_GET_FORMAT,(long)(void*)(lpbiInput), \
@@ -137,7 +137,7 @@ int VFWAPI ICDoSomething(void);
******************************************************/
-
+#ifdef D_MSACM
MMRESULT WINAPI acmDriverAddA(
PHACMDRIVERID phadid, HINSTANCE hinstModule,
LPARAM lParam, DWORD dwPriority, DWORD fdwAdd
@@ -277,10 +277,12 @@ MMRESULT WINAPI acmStreamSize(
MMRESULT WINAPI acmStreamUnprepareHeader(
HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwUnprepare
);
-void MSACM_RegisterAllDrivers(void);
+#endif // D_MSACM
+
+INT WINAPI LoadStringA( HINSTANCE instance, UINT resource_id,
+ LPSTR buffer, INT buflen );
#ifdef __cplusplus
}
#endif
#endif /* __LOADER_H */
-
diff --git a/src/libw32dll/wine/module.c b/src/libw32dll/wine/module.c
index 0ceb50547..e0495b11b 100644
--- a/src/libw32dll/wine/module.c
+++ b/src/libw32dll/wine/module.c
@@ -12,7 +12,6 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-
#include <sys/mman.h>
#include <sys/types.h>
/*
@@ -48,6 +47,15 @@ struct modify_ldt_ldt_s {
#include "module.h"
#include "pe_image.h"
#include "debugtools.h"
+#ifdef HAVE_LIBDL
+#include <dlfcn.h>
+#include "elfdll.h"
+#endif
+#include "win32.h"
+#include "driver.h"
+
+//#undef TRACE
+//#define TRACE printf
struct modref_list_t;
@@ -55,143 +63,14 @@ typedef struct modref_list_t
{
WINE_MODREF* wm;
struct modref_list_t *next;
- struct modref_list_t *prev;
-}
-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;
-}
-*/
+ struct modref_list_t *prev;
+} modref_list;
-//
-// 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;
+HANDLE SegptrHeap;
+
WINE_MODREF *MODULE_FindModule(LPCSTR m)
{
modref_list* list=local_wm;
@@ -200,14 +79,14 @@ 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;
- }
+ }
TRACE("Resolved to %s\n", list->wm->filename);
return list->wm;
-}
+}
static void MODULE_RemoveFromList(WINE_MODREF *mod)
{
@@ -237,8 +116,9 @@ static void MODULE_RemoveFromList(WINE_MODREF *mod)
return;
}
}
-}
-
+
+}
+
WINE_MODREF *MODULE32_LookupHMODULE(HMODULE m)
{
modref_list* list=local_wm;
@@ -252,10 +132,10 @@ WINE_MODREF *MODULE32_LookupHMODULE(HMODULE m)
list=list->prev;
if(list==NULL)
return NULL;
- }
- TRACE("LookupHMODULE hit %X\n", (int)list->wm);
+ }
+ TRACE("LookupHMODULE hit %p\n", list->wm);
return list->wm;
-}
+}
/*************************************************************************
* MODULE_InitDll
@@ -264,7 +144,7 @@ static WIN_BOOL MODULE_InitDll( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
{
WIN_BOOL retv = TRUE;
- static LPCSTR typeName[] = { "PROCESS_DETACH", "PROCESS_ATTACH",
+ static LPCSTR typeName[] = { "PROCESS_DETACH", "PROCESS_ATTACH",
"THREAD_ATTACH", "THREAD_DETACH" };
assert( wm );
@@ -290,7 +170,7 @@ static WIN_BOOL MODULE_InitDll( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
break;
default:
- ERR("wine_modref type %d not handled.\n", wm->type);
+ ERR("wine_modref type %d not handled.\n", wm->type );
retv = FALSE;
break;
}
@@ -305,14 +185,14 @@ static WIN_BOOL MODULE_InitDll( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
/*************************************************************************
* MODULE_DllProcessAttach
- *
+ *
* Send the process attach notification to all DLLs the given module
* depends on (recursively). This is somewhat complicated due to the fact that
*
* - we have to respect the module dependencies, i.e. modules implicitly
* referenced by another module have to be initialized before the module
* itself can be initialized
- *
+ *
* - the initialization routine of a DLL can itself call LoadLibrary,
* thereby introducing a whole new set of dependencies (even involving
* the 'old' modules) at any time during the whole process
@@ -323,7 +203,7 @@ static WIN_BOOL MODULE_InitDll( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
*
* Furthermore, we need to rearrange the main WINE_MODREF list to allow
* the process *detach* notifications to be sent in the correct order.
- * This must not only take into account module dependencies, but also
+ * This must not only take into account module dependencies, but also
* 'hidden' dependencies created by modules calling LoadLibrary in their
* attach notification routine.
*
@@ -338,7 +218,7 @@ static WIN_BOOL MODULE_InitDll( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
WIN_BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved )
{
WIN_BOOL retv = TRUE;
- /* int i; */
+ int i;
assert( wm );
/* prevent infinite recursion in case of cyclical dependencies */
@@ -372,10 +252,10 @@ WIN_BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved )
local_wm=malloc(sizeof(modref_list));
local_wm->next=local_wm->prev=NULL;
local_wm->wm=wm;
- }
+ }
/* Remove recursion flag */
wm->flags &= ~WINE_MODREF_MARKER;
-
+
if ( retv )
{
retv = MODULE_InitDll( wm, DLL_PROCESS_ATTACH, lpReserved );
@@ -391,16 +271,24 @@ WIN_BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved )
/*************************************************************************
* MODULE_DllProcessDetach
- *
- * Send DLL process detach notifications. See the comment about calling
+ *
+ * Send DLL process detach notifications. See the comment about calling
* sequence at MODULE_DllProcessAttach. Unless the bForceDetach flag
* is set, only DLLs with zero refcount are notified.
*/
void MODULE_DllProcessDetach( WINE_MODREF* wm, WIN_BOOL bForceDetach, LPVOID lpReserved )
{
-// WINE_MODREF *wm=local_wm;
+ // WINE_MODREF *wm=local_wm;
+ modref_list* l = local_wm;
wm->flags &= ~WINE_MODREF_PROCESS_ATTACHED;
MODULE_InitDll( wm, DLL_PROCESS_DETACH, lpReserved );
+/* while (l)
+ {
+ modref_list* f = l;
+ l = l->next;
+ free(f);
+ }
+ local_wm = 0;*/
}
@@ -409,8 +297,14 @@ void MODULE_DllProcessDetach( WINE_MODREF* wm, WIN_BOOL bForceDetach, LPVOID lpR
*/
HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags)
{
- WINE_MODREF *wm;
-
+ WINE_MODREF *wm = 0;
+ char* listpath[] = { "", "", "/usr/lib/win32", "/usr/local/lib/win32", 0 };
+ extern char* win32_def_path;
+ char path[512];
+ char checked[2000];
+ int i = -1;
+
+ checked[0] = 0;
if(!libname)
{
SetLastError(ERROR_INVALID_PARAMETER);
@@ -418,14 +312,46 @@ HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags)
}
// if(fs_installed==0)
// install_fs();
-
- wm = MODULE_LoadLibraryExA( libname, hfile, flags );
+ while (wm == 0 && listpath[++i])
+ {
+ if (i < 2)
+ {
+ if (i == 0)
+ /* check just original file name */
+ strncpy(path, libname, 511);
+ else
+ /* check default user path */
+ strncpy(path, win32_def_path, 300);
+ }
+ else if (strcmp(win32_def_path, listpath[i]))
+ /* path from the list */
+ strncpy(path, listpath[i], 300);
+ else
+ continue;
+
+ if (i > 0)
+ {
+ strcat(path, "/");
+ strncat(path, libname, 100);
+ }
+ path[511] = 0;
+ wm = MODULE_LoadLibraryExA( path, hfile, flags );
+
+ if (!wm)
+ {
+ if (checked[0])
+ strcat(checked, ", ");
+ strcat(checked, path);
+ checked[1500] = 0;
+
+ }
+ }
if ( wm )
{
if ( !MODULE_DllProcessAttach( wm, NULL ) )
{
- WARN_(module, "Attach failed for module '%s', \n", libname);
+ WARN_(module)("Attach failed for module '%s', \n", libname);
MODULE_FreeLibrary(wm);
SetLastError(ERROR_DLL_INIT_FAILED);
MODULE_RemoveFromList(wm);
@@ -433,6 +359,10 @@ HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags)
}
}
+ if (!wm)
+ printf("Win32 LoadLibrary failed to load: %s\n", checked);
+
+
return wm ? wm->module : 0;
}
@@ -452,10 +382,9 @@ WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags )
{
DWORD err = GetLastError();
WINE_MODREF *pwm;
- /* int i; */
+ int i;
// module_loadorder_t *plo;
-
SetLastError( ERROR_FILE_NOT_FOUND );
TRACE("Trying native dll '%s'\n", libname);
pwm = PE_LoadLibraryExA(libname, flags);
@@ -464,8 +393,8 @@ WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags )
{
TRACE("Trying ELF dll '%s'\n", libname);
pwm=(WINE_MODREF*)ELFDLL_LoadLibraryExA(libname, flags);
- }
-#endif
+ }
+#endif
// printf("0x%08x\n", pwm);
// break;
if(pwm)
@@ -480,7 +409,7 @@ WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags )
return pwm;
}
-
+
WARN("Failed to load module '%s'; error=0x%08lx, \n", libname, GetLastError());
return NULL;
}
@@ -508,12 +437,15 @@ WIN_BOOL WINAPI FreeLibrary(HINSTANCE hLibModule)
{
SetLastError( ERROR_INVALID_HANDLE );
return 0;
- }
+ }
else
retv = MODULE_FreeLibrary( wm );
-
+
MODULE_RemoveFromList(wm);
+ /* garbage... */
+ if (local_wm == NULL) my_garbagecollection();
+
return retv;
}
@@ -580,19 +512,19 @@ FARPROC WINAPI GetProcAddress( HMODULE hModule, LPCSTR function )
/***********************************************************************
* MODULE_GetProcAddress (internal)
*/
-FARPROC MODULE_GetProcAddress(
+FARPROC MODULE_GetProcAddress(
HMODULE hModule, /* [in] current module handle */
LPCSTR function, /* [in] function to be looked up */
WIN_BOOL snoop )
{
WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule );
-// WINE_MODREF *wm=local_wm;
+// WINE_MODREF *wm=local_wm;
FARPROC retproc;
if (HIWORD(function))
- TRACE_(win32,"(%08lx,%s)\n",(DWORD)hModule,function);
+ TRACE_(win32)("(%08lx,%s)\n",(DWORD)hModule,function);
else
- TRACE_(win32,"(%08lx,%p)\n",(DWORD)hModule,function);
+ TRACE_(win32)("(%08lx,%p)\n",(DWORD)hModule,function);
if (!wm) {
SetLastError(ERROR_INVALID_HANDLE);
return (FARPROC)0;
@@ -603,9 +535,9 @@ FARPROC MODULE_GetProcAddress(
retproc = PE_FindExportedFunction( wm, function, snoop );
if (!retproc) SetLastError(ERROR_PROC_NOT_FOUND);
return retproc;
-#ifdef HAVE_LIBDL
+#ifdef HAVE_LIBDL
case MODULE32_ELF:
- retproc = (FARPROC) dlsym( wm->module, function);
+ retproc = (FARPROC) dlsym( (void*) wm->module, function);
if (!retproc) SetLastError(ERROR_PROC_NOT_FOUND);
return retproc;
#endif
@@ -616,3 +548,27 @@ FARPROC MODULE_GetProcAddress(
}
}
+static int acounter = 0;
+void CodecAlloc(void)
+{
+ acounter++;
+}
+
+void CodecRelease(void)
+{
+ acounter--;
+ if (acounter == 0)
+ {
+ for (;;)
+ {
+ modref_list* list = local_wm;
+ if (!local_wm)
+ break;
+ //printf("CODECRELEASE %p\n", list);
+ MODULE_FreeLibrary(list->wm);
+ MODULE_RemoveFromList(list->wm);
+ if (local_wm == NULL)
+ my_garbagecollection();
+ }
+ }
+}
diff --git a/src/libw32dll/wine/msacm.h b/src/libw32dll/wine/msacm.h
index c359a4ca1..b1204f974 100644
--- a/src/libw32dll/wine/msacm.h
+++ b/src/libw32dll/wine/msacm.h
@@ -5,6 +5,8 @@
#ifndef __WINE_MSACM_H
#define __WINE_MSACM_H
+#define D_MSACM 1
+
#include "windef.h"
#include "driver.h"
#include "mmreg.h"
@@ -21,7 +23,7 @@ typedef UINT16 MCIDEVICEID16;
typedef UINT MCIDEVICEID;
typedef UINT16 MMRESULT16;
typedef UINT MMRESULT;
-typedef DWORD FOURCC; /* a four character code */
+typedef DWORD FOURCC; /* a four character code */
@@ -931,7 +933,6 @@ MMRESULT WINAPI acmStreamSize(
MMRESULT WINAPI acmStreamUnprepareHeader(
HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwUnprepare
);
-void MSACM_RegisterAllDrivers(void);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/src/libw32dll/wine/pe_image.c b/src/libw32dll/wine/pe_image.c
index 095abf244..d30b5f2bc 100644
--- a/src/libw32dll/wine/pe_image.c
+++ b/src/libw32dll/wine/pe_image.c
@@ -175,7 +175,7 @@ FARPROC PE_FindExportedFunction(
ename = RVA(name[i]);
if (!strcmp( ename, funcName ))
{
- ERR( "%s.%s required a linear search\n", wm->modname, funcName );
+ ERR( "%s.%s required a linear search\n", wm->modname, funcName );
ordinal = ordinals[i];
goto found;
}
@@ -280,7 +280,7 @@ static DWORD fixup_imports( WINE_MODREF *wm )
*/
for (i = 0, pe_imp = pem->pe_import; pe_imp->Name ; pe_imp++) {
- // WINE_MODREF *wmImp;
+ WINE_MODREF *wmImp;
IMAGE_IMPORT_BY_NAME *pe_name;
PIMAGE_THUNK_DATA import_list,thunk_list;
char *name = (char *) RVA(pe_imp->Name);
@@ -302,13 +302,11 @@ static DWORD fixup_imports( WINE_MODREF *wm )
// TRACE("--- Ordinal %s,%d\n", name, ordinal);
- thunk_list->u1.Function=LookupExternal(
- name, ordinal);
+ thunk_list->u1.Function=LookupExternal(name, ordinal);
} else {
pe_name = (PIMAGE_IMPORT_BY_NAME)RVA(import_list->u1.AddressOfData);
// TRACE("--- %s %s.%d\n", pe_name->Name, name, pe_name->Hint);
- thunk_list->u1.Function=LookupExternalByName(
- name, pe_name->Name);
+ thunk_list->u1.Function=LookupExternalByName(name, pe_name->Name);
}
import_list++;
thunk_list++;
@@ -334,8 +332,6 @@ static DWORD fixup_imports( WINE_MODREF *wm )
thunk_list++;
}
}
-
-
}
return 0;
}
@@ -381,7 +377,7 @@ static void do_relocations( unsigned int load_addr, IMAGE_BASE_RELOCATION *r )
char *page = (char*) RVA(r->VirtualAddress);
int count = (r->SizeOfBlock - 8)/2;
int i;
- TRACE_(fixup,"%x relocations for page %lx\n",
+ TRACE_(fixup)("%x relocations for page %lx\n",
count, r->VirtualAddress);
for(i=0;i<count;i++)
@@ -439,7 +435,7 @@ HMODULE PE_LoadImage( int handle, LPCSTR filename, WORD *version )
IMAGE_NT_HEADERS *nt;
IMAGE_SECTION_HEADER *pe_sec;
IMAGE_DATA_DIRECTORY *dir;
- // BY_HANDLE_FILE_INFORMATION bhfi;
+ BY_HANDLE_FILE_INFORMATION bhfi;
int i, rawsize, lowest_va, vma_size, file_size = 0;
DWORD load_addr = 0, aoep, reloc = 0;
// struct get_read_fd_request *req = get_req_buffer();
@@ -596,15 +592,15 @@ HMODULE PE_LoadImage( int handle, LPCSTR filename, WORD *version )
MEM_RESERVE | MEM_COMMIT,
PAGE_EXECUTE_READWRITE );
if (!load_addr) {
- FIXME_(win32,
- "FATAL: Couldn't load module %s (out of memory, %d needed)!\n", filename, vma_size);
+ FIXME_(win32)(
+ "FATAL: Couldn't load module %s (out of memory, %d needed)!\n", filename, vma_size);
goto error;
}
}
TRACE("Load addr is %lx (base %lx), range %x\n",
load_addr, nt->OptionalHeader.ImageBase, vma_size );
- TRACE_(segment,"Loading %s at %lx, range %x\n",
+ TRACE_(segment)("Loading %s at %lx, range %x\n",
filename, load_addr, vma_size );
#if 0
@@ -622,7 +618,7 @@ HMODULE PE_LoadImage( int handle, LPCSTR filename, WORD *version )
0, 0, PROT_EXEC | PROT_WRITE | PROT_READ,
MAP_PRIVATE | MAP_FIXED ) != (void*)load_addr)
{
- ERR_(win32, "Critical Error: failed to map PE header to necessary address.\n");
+ ERR_(win32)( "Critical Error: failed to map PE header to necessary address.\n");
goto error;
}
@@ -640,7 +636,7 @@ HMODULE PE_LoadImage( int handle, LPCSTR filename, WORD *version )
MAP_PRIVATE | MAP_FIXED ) != (void*)RVA(pe_sec->VirtualAddress))
{
- ERR_(win32, "Critical Error: failed to map PE section to necessary address.\n");
+ ERR_(win32)( "Critical Error: failed to map PE section to necessary address.\n");
goto error;
}
if ((pe_sec->SizeOfRawData < pe_sec->Misc.VirtualSize) &&
@@ -670,7 +666,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;
}
@@ -698,7 +695,10 @@ WINE_MODREF *PE_CreateModule( HMODULE hModule,
IMAGE_EXPORT_DIRECTORY *pe_export = NULL;
IMAGE_RESOURCE_DIRECTORY *pe_resource = NULL;
WINE_MODREF *wm;
- // int result;
+ int result;
+
+
+
dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_EXPORT;
if (dir->Size)
@@ -852,6 +852,7 @@ WINE_MODREF *PE_LoadLibraryExA (LPCSTR name, DWORD flags)
return NULL;
}
close(hFile);
+ //printf("^^^^^^^^^^^^^^^^Alloc VM1 %p\n", wm);
return wm;
}
@@ -865,9 +866,14 @@ void PE_UnloadLibrary(WINE_MODREF *wm)
{
TRACE(" unloading %s\n", wm->filename);
- HeapFree( GetProcessHeap(), 0, wm->filename );
- HeapFree( GetProcessHeap(), 0, wm->short_filename );
+ if (wm->filename)
+ free(wm->filename);
+ if (wm->short_filename)
+ free(wm->short_filename);
+ HeapFree( GetProcessHeap(), 0, wm->deps );
+ VirtualFree( (LPVOID)wm->module, 0, MEM_RELEASE );
HeapFree( GetProcessHeap(), 0, wm );
+ //printf("^^^^^^^^^^^^^^^^Free VM1 %p\n", wm);
}
/*****************************************************************************
@@ -876,6 +882,27 @@ void PE_UnloadLibrary(WINE_MODREF *wm)
* due to the PROCESS_Create stuff.
*/
+
+/*
+ * This is a dirty hack.
+ * The win32 DLLs contain an alloca routine, that first probes the soon
+ * to be allocated new memory *below* the current stack pointer in 4KByte
+ * increments. After the mem probing below the current %esp, the stack
+ * pointer is finally decremented to make room for the "alloca"ed memory.
+ * Maybe the probing code is intended to extend the stack on a windows box.
+ * Anyway, the linux kernel does *not* extend the stack by simply accessing
+ * memory below %esp; it segfaults.
+ * The extend_stack_for_dll_alloca() routine just preallocates a big chunk
+ * of memory on the stack, for use by the DLLs alloca routine.
+ */
+static void extend_stack_for_dll_alloca(void)
+{
+#ifndef __FreeBSD__
+ void* mem=alloca(0x20000);
+ *(int*)mem=0x1234;
+#endif
+}
+
/* Called if the library is loaded or freed.
* NOTE: if a thread attaches a DLL, the current thread will only do
* DLL_PROCESS_ATTACH. Only new created threads do DLL_THREAD_ATTACH
@@ -895,25 +922,28 @@ WIN_BOOL PE_InitDLL( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
if(entry==NULL)
entry = (void*)RVA_PTR( wm->module,OptionalHeader.AddressOfEntryPoint );
- TRACE_(relay,"CallTo32(entryproc=%p,module=%08x,type=%ld,res=%p)\n",
+ 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);
+ extend_stack_for_dll_alloca();
retv = entry( wm->module, type, lpReserved );
}
diff --git a/src/libw32dll/wine/registry.c b/src/libw32dll/wine/registry.c
index f29a4d59d..0ca6b2cab 100644
--- a/src/libw32dll/wine/registry.c
+++ b/src/libw32dll/wine/registry.c
@@ -1,9 +1,9 @@
#include "config.h"
#include <stdio.h>
+#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
-#include <stdlib.h>
#include <pwd.h>
#include <sys/types.h>
@@ -13,7 +13,11 @@
#include "winerror.h"
#include "debugtools.h"
-#include "registry.h"
+#include <ext.h>
+#include <registry.h>
+
+//#undef TRACE
+//#define TRACE printf
struct reg_value
{
@@ -23,9 +27,11 @@ struct reg_value
char* value;
};
-static int reg_size=0;
+// ...can be set before init_registry() call
+char* regpathname = 0;
-static struct reg_value* regs=0;
+static int reg_size=0;
+static struct reg_value* regs = 0;
struct reg_handle_s;
typedef struct reg_handle_s
@@ -43,6 +49,7 @@ static reg_handle_t* head=0;
static void create_registry(void);
static void open_registry(void);
static void save_registry(void);
+static void init_registry(void);
@@ -69,21 +76,14 @@ static void open_registry(void)
{
int fd;
int i;
- int len;
- struct passwd* pwent;
- char* pathname;
+ unsigned int len;
if(regs)
{
printf("Multiple open_registry(>\n");
return;
}
- pwent=getpwuid(getuid());
- pathname=(char*)malloc(strlen(pwent->pw_dir)+20);
- strcpy(pathname, pwent->pw_dir);
- strcat(pathname, "/.registry");
- fd=open(pathname, O_RDONLY);
- free(pathname);
- if(fd==-1)
+ fd = open(regpathname, O_RDONLY);
+ if (fd == -1)
{
printf("Creating new registry\n");
create_registry();
@@ -121,25 +121,21 @@ error:
static void save_registry(void)
{
- int fd, i, len;
- struct passwd* pwent;
- char* pathname;
- pwent=getpwuid(getuid());
- pathname=(char*)malloc(strlen(pwent->pw_dir)+20);
- strcpy(pathname, pwent->pw_dir);
- strcat(pathname, "/.registry");
- fd=open(pathname, O_WRONLY | O_CREAT, 00777);
- free(pathname);
- if(fd==-1)
+ int fd, i;
+ if (!regs)
+ init_registry();
+ fd = open(regpathname, O_WRONLY | O_CREAT, 00666);
+ if (fd == -1)
{
- printf("Failed to open registry file for writing.\n");
- return;
+ printf("Failed to open registry file '%s' for writing.\n",
+ regpathname);
+ return;
}
write(fd, &reg_size, 4);
for(i=0; i<reg_size; i++)
{
+ unsigned len=strlen(regs[i].name);
write(fd, &regs[i].type, 4);
- len=strlen(regs[i].name);
write(fd, &len, 4);
write(fd, regs[i].name, len);
write(fd, &regs[i].len, 4);
@@ -147,7 +143,6 @@ static void save_registry(void)
}
close(fd);
}
-#if 0
static reg_handle_t* find_handle_by_name(const char* name)
{
reg_handle_t* t;
@@ -160,7 +155,6 @@ static reg_handle_t* find_handle_by_name(const char* name)
}
return 0;
}
-#endif
static struct reg_value* find_value_by_name(const char* name)
{
int i;
@@ -229,7 +223,7 @@ static char* build_keyname(long key, const char* subkey)
}
static struct reg_value* insert_reg_value(int handle, const char* name, int type, const void* value, int len)
{
- /* reg_handle_t* t; */
+ reg_handle_t* t;
struct reg_value* v;
char* fullname;
if((fullname=build_keyname(handle, name))==NULL)
@@ -263,14 +257,26 @@ static struct reg_value* insert_reg_value(int handle, const char* name, int type
return v;
}
-static void init_registry()
+static void init_registry(void)
{
- printf("Initializing registry\n");
+ 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 (regpathname == 0)
+ {
+ regpathname = (char*)malloc(strlen(pwent->pw_dir)+20);
+ strcpy(regpathname, pwent->pw_dir);
+ strcat(regpathname, "/.registry");
+ }
+
open_registry();
insert_handle(HKEY_LOCAL_MACHINE, "HKLM");
insert_handle(HKEY_CURRENT_USER, "HKCU");
}
-#if 0
+
static reg_handle_t* find_handle_2(long key, const char* subkey)
{
char* full_name;
@@ -290,7 +296,7 @@ static reg_handle_t* find_handle_2(long key, const char* subkey)
free(full_name);
return t;
}
-#endif
+
long RegOpenKeyExA(long key, const char* subkey, long reserved, long access, int* newkey)
{
char* full_name;
@@ -308,10 +314,11 @@ long RegOpenKeyExA(long key, const char* subkey, long reserved, long access, int
if(t==(reg_handle_t*)-1)
return -1;
-
-*/ full_name=build_keyname(key, subkey);
+*/
+ full_name=build_keyname(key, subkey);
if(!full_name)
return -1;
+ TRACE("Opening key Fullname %s\n", full_name);
v=find_value_by_name(full_name);
t=insert_handle(generate_handle(), full_name);
@@ -377,8 +384,8 @@ long RegQueryValueExA(long key, const char* value, int* reserved, int* type, int
return 0;
}
long RegCreateKeyExA(long key, const char* name, long reserved,
- void* classs, long options, long security,
- void* sec_attr, int* newkey, int* status)
+ void* classs, long options, long security,
+ void* sec_attr, int* newkey, int* status)
{
reg_handle_t* t;
char* fullname;
@@ -401,7 +408,10 @@ long RegCreateKeyExA(long key, const char* name, long reserved,
}
else
{
- if (status) *status=REG_OPENED_EXISTING_KEY;
+ // this is a hack as I don't know how RegEnumValueA works
+ if (strstr(fullname, "zlib") || strstr(fullname, "mszh"))
+ return 1;
+ if (status) *status=REG_OPENED_EXISTING_KEY;
}
t=insert_handle(generate_handle(), fullname);
@@ -409,9 +419,34 @@ long RegCreateKeyExA(long key, const char* name, long reserved,
free(fullname);
return 0;
}
+
+long RegEnumValueA(HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count,
+ LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count)
+{
+ // have no idea how this should work
+ //printf("Reg Enum 0x%x %d %p %d data: %p %d %d >%s<\n", hkey, index, value, *val_count, data, *count, reg_size, data);
+ {
+ reg_handle_t* t = find_handle(hkey);
+ if (t)
+ {
+ struct reg_value* v=find_value_by_name(t->name);
+ *count = v->len;
+ memcpy(data, v->value, *count);
+ *val_count = v->len;
+ memcpy(value, v->value, *val_count);
+ if (type)
+ *type = v->type;
+ //printf("Found handle %s\n", v->name);
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
long RegSetValueExA(long key, const char* name, long v1, long v2, const void* data, long size)
{
- /* struct reg_value* t; */
+ struct reg_value* t;
char* c;
TRACE("Request to set value %s\n", name);
if(!regs)
diff --git a/src/libw32dll/wine/registry.h b/src/libw32dll/wine/registry.h
index 2e794799e..9c94043c4 100644
--- a/src/libw32dll/wine/registry.h
+++ b/src/libw32dll/wine/registry.h
@@ -1,24 +1,33 @@
-/********************************************************
-
- Declaration of registry access functions
- Copyright 2000 Eugene Smith (divx@euro.ru)
-
-*********************************************************/
+#ifndef AVIFILE_REGISTRY_H
+#define AVIFILE_REGISTRY_H
+/********************************************************
+ *
+ * Declaration of registry access functions
+ * Copyright 2000 Eugene Kuznetsov (divx@euro.ru)
+ *
+ ********************************************************/
-#ifndef REGISTRY_H
-#define REGISTRY_H
#ifdef __cplusplus
extern "C" {
#endif
-long RegOpenKeyExA(long key, const char* subkey, long reserved, long access, int* newkey);
+
+long RegOpenKeyExA(long key, const char* subkey, long reserved,
+ long access, int* newkey);
long RegCloseKey(long key);
-long RegQueryValueExA(long key, const char* value, int* reserved, int* type, int* data, int* count);
+long RegQueryValueExA(long key, const char* value, int* reserved,
+ int* type, int* data, int* count);
long RegCreateKeyExA(long key, const char* name, long reserved,
- void* classs, long options, long security,
- void* sec_attr, int* newkey, int* status);
-long RegSetValueExA(long key, const char* name, long v1, long v2, const void* data, long size);
+ void* classs, long options, long security,
+ void* sec_attr, int* newkey, int* status);
+long RegSetValueExA(long key, const char* name, long v1, long v2,
+ const void* data, long size);
+#ifdef __WINE_WINERROR_H
+long RegEnumValueA(HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count,
+ LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count);
+#endif
#ifdef __cplusplus
};
#endif
-#endif
+
+#endif // AVIFILE_REGISTRY_H
diff --git a/src/libw32dll/wine/resource.c b/src/libw32dll/wine/resource.c
index f99233805..0169a07fd 100644
--- a/src/libw32dll/wine/resource.c
+++ b/src/libw32dll/wine/resource.c
@@ -7,8 +7,8 @@
#include "config.h"
#include <assert.h>
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -21,7 +21,8 @@
#include "module.h"
#include "debugtools.h"
#include "winerror.h"
-#include "resource.h"
+#include "loader.h"
+
#define CP_ACP 0
WORD WINE_LanguageId=0x409;//english
@@ -100,13 +101,13 @@ static HRSRC RES_FindResource( HMODULE hModule, LPCSTR type,
static DWORD RES_SizeofResource( HMODULE hModule, HRSRC hRsrc)
{
DWORD size = 0;
- /* HRSRC hRsrc32; */
+ HRSRC hRsrc32;
// HMODULE16 hMod16 = MapHModuleLS( hModule );
// NE_MODULE *pModule = NE_GetPtr( hMod16 );
// WINE_MODREF *wm = pModule && pModule->module32?
// MODULE32_LookupHMODULE( pModule->module32 ) : NULL;
- // WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule );
+ WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule );
if ( !hModule || !hRsrc ) return 0;
@@ -129,7 +130,7 @@ static HFILE RES_AccessResource( HMODULE hModule, HRSRC hRsrc )
{
HFILE hFile = HFILE_ERROR;
- // WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule );
+ WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule );
if ( !hModule || !hRsrc ) return HFILE_ERROR;
@@ -146,7 +147,7 @@ static HFILE RES_AccessResource( HMODULE hModule, HRSRC hRsrc )
static HGLOBAL RES_LoadResource( HMODULE hModule, HRSRC hRsrc)
{
HGLOBAL hMem = 0;
- /* HRSRC hRsrc32; */
+ HRSRC hRsrc32;
WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule );
diff --git a/src/libw32dll/wine/stubs.s b/src/libw32dll/wine/stubs.s
index 519eefa58..d2ca31259 100644
--- a/src/libw32dll/wine/stubs.s
+++ b/src/libw32dll/wine/stubs.s
@@ -1,13 +1,7 @@
- .file "stubs.c"
- .version "01.01"
-gcc2_compiled.:
-.section .rodata
-.LC0:
- .string "Called unk_%s\n"
-.text
+ .data
+.LC0: .string "Called unk_%s\n"
.align 4
.globl unk_exp1
- .type unk_exp1,@function
unk_exp1:
pushl %ebp
movl %esp,%ebp
@@ -26,11 +20,5 @@ unk_exp1:
call printf
addl $8,%esp
xorl %eax,%eax
- jmp .L1
- .align 4
-.L1:
leave
ret
-.Lfe1:
- .size unk_exp1,.Lfe1-unk_exp1
- .ident "GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)"
diff --git a/src/libw32dll/wine/vfw.h b/src/libw32dll/wine/vfw.h
index e2bc145d8..f05b8d59b 100644
--- a/src/libw32dll/wine/vfw.h
+++ b/src/libw32dll/wine/vfw.h
@@ -1,5 +1,6 @@
#ifndef __WINE_VFW_H
#define __WINE_VFW_H
+#define D_VFW 1
//#include "pshpack1.h"
#ifdef __cplusplus
extern "C" {
@@ -15,6 +16,8 @@ typedef struct
long bfOffBits;
} BITMAPFILEHEADER;
+#ifndef _BITMAPINFOHEADER_
+#define _BITMAPINFOHEADER_
typedef struct
{
long biSize;
@@ -34,6 +37,8 @@ typedef struct {
int bmiColors[1];
} BITMAPINFO, *LPBITMAPINFO;
#endif
+
+#endif
#define VFWAPI
#define VFWAPIV
#ifndef __WINE_WINDEF_H
@@ -425,7 +430,7 @@ LRESULT VFWAPI ICClose(HIC hic);
LRESULT VFWAPI ICSendMessage(HIC hic, unsigned int msg, long dw1, long dw2);
HIC VFWAPI ICLocate(long fccType, long fccHandler, LPBITMAPINFOHEADER lpbiIn, LPBITMAPINFOHEADER lpbiOut, short wFlags);
-int VFWAPI ICDoSomething();
+int VFWAPI ICDoSomething(void);
long VFWAPIV ICDrawBegin(
HIC hic,
@@ -602,27 +607,27 @@ typedef struct {
typedef struct {
- long cbSize; // set to sizeof(COMPVARS) before
- // calling ICCompressorChoose
- long dwFlags; // see below...
- HIC hic; // HIC of chosen compressor
- long fccType; // basically ICTYPE_VIDEO
- long fccHandler; // handler of chosen compressor or
- // "" or "DIB "
- LPBITMAPINFO lpbiIn; // input format
- LPBITMAPINFO lpbiOut; // output format - will compress to this
- void* lpBitsOut;
- void* lpBitsPrev;
- long lFrame;
- long lKey; // key frames how often?
- long lDataRate; // desired data rate KB/Sec
- long lQ; // desired quality
- long lKeyCount;
- void* lpState; // state of compressor
- long cbState; // size of the state
-} COMPVARS, *PCOMPVARS;
-
-// FLAGS for dwFlags element of COMPVARS structure:
+ long cbSize; // set to sizeof(COMPVARS) before
+ // calling ICCompressorChoose
+ long dwFlags; // see below...
+ HIC hic; // HIC of chosen compressor
+ long fccType; // basically ICTYPE_VIDEO
+ long fccHandler; // handler of chosen compressor or
+ // "" or "DIB "
+ LPBITMAPINFO lpbiIn; // input format
+ LPBITMAPINFO lpbiOut; // output format - will compress to this
+ void* lpBitsOut;
+ void* lpBitsPrev;
+ long lFrame;
+ long lKey; // key frames how often?
+ long lDataRate; // desired data rate KB/Sec
+ long lQ; // desired quality
+ long lKeyCount;
+ void* lpState; // state of compressor
+ long cbState; // size of the state
+} COMPVARS, *PCOMPVARS;
+
+// FLAGS for dwFlags element of COMPVARS structure:
#define AVIERR_OK 0
diff --git a/src/libw32dll/wine/win32.c b/src/libw32dll/wine/win32.c
index fbf40663d..e191fae4f 100644
--- a/src/libw32dll/wine/win32.c
+++ b/src/libw32dll/wine/win32.c
@@ -2,18 +2,34 @@
Win32 emulation code. Functions that emulate
responses from corresponding Win32 API calls.
- Since we are not going to be able to load
+ 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"
-#include "win32.h"
+#include "winbase.h"
+#include "winreg.h"
+#include "winnt.h"
+#include "winerror.h"
+#include "debugtools.h"
+#include "module.h"
+
#include <stdio.h>
+#include "win32.h"
+
+#include "registry.h"
+#include "loader.h"
+#include "com.h"
+
#include <stdlib.h>
-#include <unistd.h>
+#include <assert.h>
+#include <stdarg.h>
#include <ctype.h>
#include <pthread.h>
#include <errno.h>
@@ -21,39 +37,34 @@
#include <malloc.h>
#endif
#include <time.h>
+#include <math.h>
+#include <unistd.h>
+#include <fcntl.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/timeb.h>
-#if HAVE_KSTAT
+#ifdef HAVE_KSTAT
#include <kstat.h>
#endif
-#include "winbase.h"
-#include "winreg.h"
-#include "winnt.h"
-#include "winerror.h"
-#include "debugtools.h"
-#include "module.h"
-#include "resource.h"
-#include "registry.h"
-#include "loader.h"
+int vsscanf( const char *str, const char *format, va_list ap);
+
+extern char* win32_def_path;
-static void
-do_cpuid(unsigned int ax, unsigned int *regs)
+static void do_cpuid(unsigned int ax, unsigned int *regs)
{
- __asm__ __volatile__ (
- "pushl %%ebx; pushl %%ecx; pushl %%edx;"
- ".byte 0x0f, 0xa2;"
- "movl %%eax, (%2);"
- "movl %%ebx, 4(%2);"
- "movl %%ecx, 8(%2);"
- "movl %%edx, 12(%2);"
- "popl %%edx; popl %%ecx; popl %%ebx;"
- : "=a" (ax)
- : "0" (ax), "S" (regs)
- );
+ __asm__ __volatile__(
+ "pushl %%ebx; pushl %%ecx; pushl %%edx;"
+ ".byte 0x0f, 0xa2;"
+ "movl %%eax, (%2);"
+ "movl %%ebx, 4(%2);"
+ "movl %%ecx, 8(%2);"
+ "movl %%edx, 12(%2);"
+ "popl %%edx; popl %%ecx; popl %%ebx;"
+ : "=a" (ax)
+ : "0" (ax), "S" (regs)
+ );
}
-
static unsigned int c_localcount_tsc()
{
int a;
@@ -73,7 +84,7 @@ static void c_longcount_tsc(long long* z)
"movl %%edx, 4(%%ebx)\n\t"
"popl %%ebx\n\t"
::"a"(z));
-}
+}
static unsigned int c_localcount_notsc()
{
struct timeval tv;
@@ -95,22 +106,23 @@ static void c_longcount_notsc(long long* z)
result+=limit*tv.tv_usec;
*z=result;
}
-
static unsigned int localcount_stub(void);
-static void longcount_stub(long long* z);
+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)
+ if ((regs[3] & 0x00000010) != 0)
{
localcount=c_localcount_tsc;
longcount=c_longcount_tsc;
- }
- else
+ }
+ else
{
localcount=c_localcount_notsc;
longcount=c_longcount_notsc;
@@ -121,12 +133,12 @@ static void longcount_stub(long long* z)
{
unsigned int regs[4];
do_cpuid(1, regs);
- if ((regs[3] & 0x00000010) != 0)
+ if ((regs[3] & 0x00000010) != 0)
{
localcount=c_localcount_tsc;
longcount=c_longcount_tsc;
- }
- else
+ }
+ else
{
localcount=c_localcount_notsc;
longcount=c_longcount_notsc;
@@ -134,35 +146,27 @@ static void longcount_stub(long long* z)
longcount(z);
}
-
-int LOADER_DEBUG=1;
-static void dbgprintf(char* fmt, ...)
+int LOADER_DEBUG=1; // active only if compiled with -DDETAILED_OUT
+static inline void dbgprintf(char* fmt, ...)
{
#ifdef DETAILED_OUT
-#if 1
- va_list va;
- va_start(va, fmt);
- vprintf(fmt, va);
- va_end(va);
-#else
- if (LOADER_DEBUG)
+ if(LOADER_DEBUG)
{
FILE* f;
va_list va;
- va_start(va, fmt);
- vprintf(fmt, va);
+ va_start(va, fmt);
f=fopen("./log", "a");
- if(f)
+ vprintf(fmt, va);
+ if(f)
{
vfprintf(f, fmt, va);
fsync(fileno(f));
- fclose(f);
+ fclose(f);
}
va_end(va);
}
#endif
-#endif
-}
+}
char export_names[500][30]={
"name1",
//"name2",
@@ -170,11 +174,13 @@ char export_names[500][30]={
};
//#define min(x,y) ((x)<(y)?(x):(y))
-static unsigned char* heap=NULL;
+void destroy_event(void* event);
+
+static unsigned char* heap=NULL;
static int heap_counter=0;
-static void test_heap()
+static void test_heap(void)
{
- int offset=0;
+ int offset=0;
if(heap==0)
return;
while(offset<heap_counter)
@@ -190,7 +196,7 @@ static void test_heap()
if(heap[offset]!=0xCC)
{
printf("Free heap corruption at address %d\n", offset);
- }
+ }
}
#undef MEMORY_DEBUG
@@ -211,21 +217,23 @@ void* my_mreq(int size, int to_zero)
{
printf("No enough memory\n");
return 0;
- }
+ }
if(heap_counter+size>20000000)
{
printf("No enough memory\n");
return 0;
- }
+ }
*(int*)(heap+heap_counter)=0x433476;
heap_counter+=4;
*(int*)(heap+heap_counter)=size;
heap_counter+=4;
printf("Allocated %d bytes of memory: sys %d, user %d-%d\n", size, heap_counter-8, heap_counter, heap_counter+size);
if(to_zero)
- memset(heap+heap_counter, 0, size);
+ memset(heap+heap_counter, 0, size);
+ else
+ memset(heap+heap_counter, 0xcc, size); // make crash reproducable
heap_counter+=size;
- return heap+heap_counter-size;
+ return heap+heap_counter-size;
}
int my_release(char* memory)
{
@@ -234,7 +242,7 @@ int my_release(char* memory)
{
printf("ERROR: free(0)\n");
return 0;
- }
+ }
if(*(int*)(memory-8)!=0x433476)
{
printf("MEMORY CORRUPTION !!!!!!!!!!!!!!!!!!!\n");
@@ -243,30 +251,151 @@ int my_release(char* memory)
printf("Freed %d bytes of memory\n", *(int*)(memory-4));
// memset(memory-8, *(int*)(memory-4), 0xCC);
return 0;
-}
+}
#else
-void* my_mreq(int size, int to_zero)
+#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
+
+void* mreq_private(int size, int to_zero, int type);
+void* mreq_private(int size, int to_zero, int type)
{
- void* answer;
- if(to_zero)
- answer=calloc(size+4, 1);
+ alloc_header* header;
+ if (to_zero)
+ header=calloc(size + sizeof(alloc_header), 1);
+ else
+ header=malloc(size + sizeof(alloc_header));
+#ifdef GARBAGE
+ if (!last_alloc)
+ {
+ pthread_mutex_init(&memmut, NULL);
+ pthread_mutex_lock(&memmut);
+ }
else
- answer=malloc(size+4);
- *(int*)answer=size;
- return (int*)answer+1;
-}
+ {
+ 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 < 400) printf("MY_REQ: %p\t%d (%d)\n", answer, size, alccnt);
+ return header + 1;
+}
+
+void* my_mreq(int size, int to_zero)
+{
+ return mreq_private(size, to_zero, AREATYPE_CLIENT);
+}
+
+
int my_release(void* memory)
{
- if(memory==0)return 0;
- free(memory-4);
+ alloc_header* header = (alloc_header*) memory - 1;
+#ifdef GARBAGE
+ alloc_header* prevmem;
+ alloc_header* nextmem;
+ if (memory == 0)
+ return 0;
+
+ pthread_mutex_lock(&memmut);
+
+ if (header->deadbeef != 0xdeadbeef)
+ {
+ printf("FATAL releasing corrupted memory!\n");
+ return 0;
+ }
+
+ 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;
+ }
+
+ 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 < 400) printf("MY_RELEASE: %p\t%ld (%d)\n", mem, mem[3], alccnt);
+#else
+ if (memory == 0)
+ return 0;
+#endif
+ free(header);
return 0;
}
#endif
-int my_size(char* memory)
+
+static inline int my_size(void* memory)
+{
+ return ((alloc_header*)memory)[-1].size;
+}
+
+void* my_realloc(void* memory, int size)
{
- return *(int*)(memory-4);
-}
+ void *ans = memory;
+ int osize = my_size(memory);
+ if (memory == NULL)
+ return my_mreq(size, 0);
+ if (osize < size)
+ {
+ ans = my_mreq(size, 0);
+ memcpy(ans, memory, osize);
+ my_release(memory);
+ }
+ return ans;
+}
extern int unk_exp1;
char extcode[20000];// place for 200 unresolved exports
@@ -276,42 +405,47 @@ int WINAPI ext_unknown()
{
printf("Unknown func called\n");
return 0;
-}
+}
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)
@@ -319,53 +453,69 @@ void* CDECL expnew(int size)
// printf("NEW:: Call from address %08x\n STACK DUMP:\n", *(-1+(int*)&size));
// printf("%08x %08x %08x %08x\n",
// size, *(1+(int*)&size),
-// *(2+(int*)&size),*(3+(int*)&size));
- void* result=expmalloc(size);
- dbgprintf("new(%x)\n", size);
- if(result==0)
- {
- dbgprintf("returns 0\n");
- printf("WARNING: malloc() failed\n");
- }
+ // *(2+(int*)&size),*(3+(int*)&size));
+ void* result = 0;
+ assert(size >= 0);
+
+ result=my_mreq(size,0);
+ dbgprintf("new(0x%x) => 0x%x\n", size, result);
+ if (result==0)
+ printf("WARNING: new() failed\n");
return result;
-}
+}
int CDECL expdelete(void* memory)
{
- dbgprintf("delete(%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;
-}
+}
-void* WINAPI expGetDriverModuleHandle(DRVR* pdrv)
+HMODULE WINAPI expGetDriverModuleHandle(DRVR* pdrv)
{
- void *result;
- if (pdrv == NULL)
- result = NULL;
+ HMODULE result;
+ if (pdrv==NULL)
+ result=0;
else
- result = (void*)pdrv->hDriverModule;
- dbgprintf("GetDriverModuleHandle(%x)\n", pdrv);
+ result=pdrv->hDriverModule;
+ dbgprintf("GetDriverModuleHandle(%p) => %p\n", pdrv, result);
return result;
}
-void* WINAPI expGetModuleHandleA(const char* name)
+#define MODULE_HANDLE_kernel32 ((HMODULE)0x120)
+
+HMODULE 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);
+ HMODULE result;
+ if(!name)
+ result=0;
+ else
+ {
+ wm=MODULE_FindModule(name);
+ if(wm==0)result=0;
+ else
+ result=(HMODULE)(wm->module);
+ }
+ if(!result)
+ {
+ if(strcasecmp(name, "kernel32")==0)
+ result=MODULE_HANDLE_kernel32;
+ }
+ dbgprintf("GetModuleHandleA('%s') => 0x%x\n", name, result);
+ return result;
}
+
struct th_list_t;
typedef struct th_list_t{
int id;
@@ -384,13 +534,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);
@@ -402,8 +550,10 @@ void* WINAPI expCreateThread(void* pSecAttr, long dwStackSize, void* lpStartAddr
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%x\n",
+ pSecAttr, dwStackSize, lpStartAddress, lpParameter, dwFlags, dwThreadId, pth);
return pth;
}
@@ -416,18 +566,58 @@ struct mutex_list_t
pthread_cond_t *pc;
char state;
char reset;
- char name[64];
+ 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* WINAPI expCreateEventA(void* pSecAttr, char bManualReset,
+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("0\n");
+*/
+ return;
+ }
+ pp=pp->prev;
+ }
+}
+
+void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset,
char bInitialState, const char* name)
{
pthread_mutex_t *pm;
pthread_cond_t *pc;
+/*
+ mutex_list* pp;
+ pp=mlist;
+ while(pp)
+ {
+ printf("%x => ", pp);
+ pp=pp->prev;
+ }
+ printf("0\n");
+*/
if(mlist!=NULL)
{
mutex_list* pp=mlist;
@@ -440,20 +630,20 @@ void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset,
pSecAttr, bManualReset, bInitialState, name, name, pp->pm);
return pp->pm;
}
- }while((pp=pp->prev));
- }
- pm=my_mreq(sizeof(pthread_mutex_t), 0);
+ }while((pp=pp->prev) != NULL);
+ }
+ pm=mreq_private(sizeof(pthread_mutex_t), 0, AREATYPE_MUTEX);
pthread_mutex_init(pm, NULL);
- pc=my_mreq(sizeof(pthread_cond_t), 0);
+ pc=mreq_private(sizeof(pthread_cond_t), 0, AREATYPE_COND);
pthread_cond_init(pc, NULL);
if(mlist==NULL)
{
- mlist=my_mreq(sizeof(mutex_list), 00);
+ mlist=mreq_private(sizeof(mutex_list), 00, AREATYPE_EVENT);
mlist->next=mlist->prev=NULL;
}
else
{
- mlist->next=my_mreq(sizeof(mutex_list), 00);
+ mlist->next=mreq_private(sizeof(mutex_list), 00, AREATYPE_EVENT);
mlist->next->prev=mlist;
mlist->next->next=NULL;
mlist=mlist->next;
@@ -463,9 +653,9 @@ void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset,
mlist->pc=pc;
mlist->state=bInitialState;
mlist->reset=bManualReset;
- if(name!=NULL)
- strncpy(mlist->name, name, 64);
- else
+ if(name)
+ strncpy(mlist->name, name, 127);
+ else
mlist->name[0]=0;
if(pm==NULL)
dbgprintf("ERROR::: CreateEventA failure\n");
@@ -480,7 +670,7 @@ void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset,
dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, NULL) => 0x%x\n",
pSecAttr, bManualReset, bInitialState, mlist);
return mlist;
-}
+}
void* WINAPI expSetEvent(void* event)
{
@@ -501,7 +691,7 @@ void* WINAPI expResetEvent(void* event)
dbgprintf("ResetEvent(0x%x) => 0x1\n", event);
pthread_mutex_lock(ml->pm);
ml->state = 0;
- pthread_mutex_unlock(ml->pm);
+ pthread_mutex_unlock(ml->pm);
return (void *)1;
}
@@ -509,18 +699,20 @@ void* WINAPI expResetEvent(void* event)
void* WINAPI expWaitForSingleObject(void* object, int duration)
{
mutex_list *ml = (mutex_list *)object;
- int ret=WAIT_FAILED; // fixed by Zdenek Kabelac
+ // FIXME FIXME FIXME - this value is sometime unititialize !!!
+ int ret = WAIT_FAILED;
mutex_list* pp=mlist;
-// dbgprintf("WaitForSingleObject(0x%x, duration %d) =>\n",object, duration);
+ 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;
+ pp = pp->prev;
if (!pp) {
- //dbgprintf("WaitForSingleObject: NotFound\n");
- return (void*)ret;
+ dbgprintf("WaitForSingleObject: NotFound\n");
+ return (void*)ret;
}
pthread_mutex_lock(ml->pm);
@@ -549,7 +741,7 @@ void* WINAPI expWaitForSingleObject(void* object, int duration)
if (ret == ETIMEDOUT) ret = WAIT_TIMEOUT;
else ret = WAIT_OBJECT_0;
if (ml->reset)
- ml->state = 0;
+ ml->state = 0;
}
break;
case 1: /* Semaphore */
@@ -571,19 +763,44 @@ void* WINAPI expWaitForSingleObject(void* object, int duration)
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;
- dbgprintf("GetSystemInfo()\n");
+ unsigned int regs[4];
+ dbgprintf("GetSystemInfo(%p) =>\n", si);
if (cache) {
memcpy(si,&cachedsi,sizeof(*si));
+ DumpSystemInfo(si);
return;
}
memset(PF,0,sizeof(PF));
@@ -592,43 +809,40 @@ 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;
+
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__svr4__)
- {
- unsigned int regs[4];
- 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;
- cachedsi.dwNumberOfProcessors=1;
+ do_cpuid(1, regs);
+ switch ((regs[0] >> 8) & 0xf) { // cpu family
+ case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
+ cachedsi.wProcessorLevel= 3;
+ break;
+ case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
+ cachedsi.wProcessorLevel= 4;
+ break;
+ case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
+ cachedsi.wProcessorLevel= 5;
+ break;
+ case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
+ cachedsi.wProcessorLevel= 5;
+ break;
+ default:cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
+ cachedsi.wProcessorLevel= 5;
+ break;
}
+ cachedsi.wProcessorRevision = regs[0] & 0xf; // stepping
+ if (regs[3] & (1 << 8))
+ PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
+ if (regs[3] & (1 << 23))
+ PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
+ cachedsi.dwNumberOfProcessors=1;
#else
{
char buf[20];
@@ -677,7 +891,7 @@ void WINAPI expGetSystemInfo(SYSTEM_INFO* si)
}
/* old 2.0 method */
if (!lstrncmpiA(line, "cpu",strlen("cpu"))) {
- if ( isdigit (value[0]) && value[1] == '8' &&
+ if ( isdigit (value[0]) && value[1] == '8' &&
value[2] == '6' && value[3] == 0
) {
switch (value[0] - '0') {
@@ -733,8 +947,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"))
@@ -743,81 +959,110 @@ 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__ __NetBSD__ __svr4__*/
+#endif /* __FreeBSD__ */
+ cache = 1;
memcpy(si,&cachedsi,sizeof(*si));
+ DumpSystemInfo(si);
}
long WINAPI expGetVersion()
{
- return 0xC0000A04;//Windows 98
-}
+ dbgprintf("GetVersion() => 0xC0000004\n");
+ return 0xC0000004;//Windows 95
+}
HANDLE WINAPI expHeapCreate(long flags, long init_size, long max_size)
{
// printf("HeapCreate:");
- dbgprintf("HeapCreate(%X, %X, %X)\n", flags, init_size, max_size);
+ HANDLE result;
if(init_size==0)
- return (HANDLE)my_mreq(0x110000, 0);
+ result=(HANDLE)my_mreq(0x110000, 0);
else
- return (HANDLE)my_mreq(init_size, 0);
-}
+ result=(HANDLE)my_mreq(init_size, 0);
+ dbgprintf("HeapCreate(flags 0x%x, initial size %d, maximum size %d) => 0x%x\n", flags, init_size, max_size, result);
+ return result;
+}
void* WINAPI expHeapAlloc(HANDLE heap, int flags, int size)
{
void* z;
- dbgprintf("HeapAlloc(%X, %X, %X)\n", heap, flags, size);
// printf("HeapAlloc:");
- z=my_mreq(size, flags&8);
+/**
+ Morgan's m3jpeg32.dll v. 2.0 encoder expects that request for
+ HeapAlloc returns area larger than size argument :-/
+**/
+ z=my_mreq(((size+4095)/4096)*4096, flags&8);
// z=HeapAlloc(heap,flags,size);
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);
return z;
}
long WINAPI expHeapDestroy(void* heap)
{
- dbgprintf("HeapDestroy(%X)\n", heap);
+ dbgprintf("HeapDestroy(heap 0x%x) => 1\n", heap);
my_release(heap);
return 1;
}
long WINAPI expHeapFree(int arg1, int arg2, void* ptr)
{
- dbgprintf("HeapFree(%X, %X, %X)\n", arg1, arg2, ptr);
+ dbgprintf("HeapFree(0x%x, 0x%x, pointer 0x%x) => 1\n", arg1, arg2, ptr);
my_release(ptr);
return 1;
-}
+}
long WINAPI expHeapSize(int heap, int flags, void* pointer)
{
- return my_size(pointer);
-}
+ long result=my_size(pointer);
+ dbgprintf("HeapSize(heap 0x%x, flags 0x%x, pointer 0x%x) => %d\n", heap, flags, pointer, result);
+ return result;
+}
+void* WINAPI expHeapReAlloc(HANDLE heap,int flags,void *lpMem,int size)
+{
+ long orgsize;
+ void *newp;
+ orgsize = my_size(lpMem);
+ dbgprintf("HeapReAlloc() Size %ld org %d\n",orgsize,size);
+ return my_realloc(lpMem, size);
+}
long WINAPI expGetProcessHeap(void)
{
+ dbgprintf("GetProcessHeap() => 1\n");
return 1;
-}
+}
void* WINAPI expVirtualAlloc(void* v1, long v2, long v3, long v4)
{
void* z;
- dbgprintf("VirtualAlloc(%d %d %d %d) \n",v1,v2,v3,v4);
z=VirtualAlloc(v1, v2, v3, v4);
if(z==0)
printf("VirtualAlloc failure\n");
+ dbgprintf("VirtualAlloc(0x%x, %d, %d, %d) => 0x%x \n",v1,v2,v3,v4, z);
return z;
}
int WINAPI expVirtualFree(void* v1, int v2, int v3)
{
- dbgprintf("VirtualFree(%X %X %X) \n",v1,v2,v3);
- return VirtualFree(v1,v2,v3);
-}
-struct CRITSECT
+ int result=VirtualFree(v1,v2,v3);
+ dbgprintf("VirtualFree(0x%x, %d, %d) => %d\n",v1,v2,v3, result);
+ return result;
+}
+struct CRITSECT
{
pthread_t id;
pthread_mutex_t mutex;
int locked;
};
+
void WINAPI expInitializeCriticalSection(CRITICAL_SECTION* c)
{
struct CRITSECT cs;
- dbgprintf("InitCriticalSection(%X) \n", 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",
@@ -825,16 +1070,22 @@ void WINAPI expInitializeCriticalSection(CRITICAL_SECTION* c)
return;
}*/
/* pthread_mutex_init((pthread_mutex_t*)c, NULL); */
- pthread_mutex_init(&cs.mutex, NULL);
+ pthread_mutex_init(&cs.mutex, NULL);
cs.locked=0;
*(void**)c=malloc(sizeof cs);
memcpy(*(void**)c, &cs, sizeof cs);
return;
-}
+}
void WINAPI expEnterCriticalSection(CRITICAL_SECTION* c)
{
- struct CRITSECT* cs=(struct CRITSECT*)c;
- dbgprintf("EnterCriticalSection(%X) \n",c);
+ struct CRITSECT* cs=*(struct CRITSECT**)c;
+ dbgprintf("EnterCriticalSection(0x%x)\n",c);
+ if (!cs)
+ {
+ expInitializeCriticalSection(c);
+ cs=*(struct CRITSECT**)c;
+ printf("Win32 Warning: Accessed uninitialized Critical Section (%p)!\n", c);
+ }
// cs.id=pthread_self();
if(cs->locked)
if(cs->id==pthread_self())
@@ -843,40 +1094,52 @@ void WINAPI expEnterCriticalSection(CRITICAL_SECTION* c)
cs->locked=1;
cs->id=pthread_self();
return;
-}
+}
void WINAPI expLeaveCriticalSection(CRITICAL_SECTION* c)
{
- struct CRITSECT* cs=(struct CRITSECT*)c;
- dbgprintf("LeaveCriticalSection(%X) \n",c);
+ struct CRITSECT* cs=*(struct CRITSECT**)c;
+// struct CRITSECT* cs=(struct CRITSECT*)c;
+ dbgprintf("LeaveCriticalSection(0x%x)\n",c);
+ if (!cs)
+ {
+ printf("Win32 Warning: Leaving noninitialized Critical Section %p!!\n", c);
+ return;
+ }
cs->locked=0;
pthread_mutex_unlock(&(cs->mutex));
return;
}
void WINAPI expDeleteCriticalSection(CRITICAL_SECTION *c)
{
- dbgprintf("DeleteCriticalSection(%X) \n",c);
- pthread_mutex_destroy((pthread_mutex_t*)c);
+ struct CRITSECT* cs=*(struct CRITSECT**)c;
+// struct CRITSECT* cs=(struct CRITSECT*)c;
+ dbgprintf("DeleteCriticalSection(0x%x)\n",c);
+ pthread_mutex_destroy(&(cs->mutex));
+ free(cs);
return;
}
int WINAPI expGetCurrentThreadId()
{
- dbgprintf("GetCurrentThreadId() \n");
+ dbgprintf("GetCurrentThreadId() => %d\n", getpid());
return getpid();
-}
-
-struct tls_s
+}
+int WINAPI expGetCurrentProcess()
{
+ dbgprintf("GetCurrentProcess() => %d\n", getpid());
+ return getpid();
+}
+
+struct tls_s {
void* value;
int used;
struct tls_s* prev;
struct tls_s* next;
};
-tls_t* g_tls=NULL;
-
+tls_t* g_tls=NULL;
+
void* WINAPI expTlsAlloc()
{
- dbgprintf("TlsAlloc \n");
if(g_tls==NULL)
{
g_tls=my_mreq(sizeof(tls_t), 0);
@@ -889,77 +1152,118 @@ void* WINAPI expTlsAlloc()
g_tls->next->next=NULL;
g_tls=g_tls->next;
}
+ dbgprintf("TlsAlloc() => 0x%x\n", g_tls);
+ g_tls->value=0; /* XXX For Divx.dll */
return g_tls;
}
int WINAPI expTlsSetValue(tls_t* index, void* value)
{
- dbgprintf("TlsSetVal(%X %X) \n", index, value );
+ int result;
if(index==0)
- return 0;
- index->value=value;
- return 1;
+ result=0;
+ else
+ {
+ index->value=value;
+ result=1;
+ }
+ dbgprintf("TlsSetValue(index 0x%x, value 0x%x) => %d \n", index, value, result );
+ return result;
}
void* WINAPI expTlsGetValue(tls_t* index)
{
- dbgprintf("TlsGetVal(%X) \n", index );
+ void* result;
if(index==0)
- return 0;
- return index->value;
+ result=0;
+ else
+ result=index->value;
+ dbgprintf("TlsGetValue(index 0x%x) => 0x%x\n", index, result);
+ return result;
}
int WINAPI expTlsFree(tls_t* index)
{
- dbgprintf("TlsFree(%X) \n", index);
+ int result;
if(index==0)
- return 0;
- if(index->next)
- index->next->prev=index->prev;
- if(index->prev)
- index->prev->next=index->next;
- my_release((void*)index);
- return 1;
-}
-
+ result=0;
+ else
+ {
+ if(index->next)
+ index->next->prev=index->prev;
+ if(index->prev)
+ index->prev->next=index->next;
+ my_release((void*)index);
+ result=1;
+ }
+ dbgprintf("TlsFree(index 0x%x) => %d\n", index, result);
+ return result;
+}
void* WINAPI expLocalAlloc(int flags, int size)
{
void* z;
- dbgprintf("LocalAlloc(%d, flags %X)\n", size, flags);
if(flags&GMEM_ZEROINIT)
z=my_mreq(size, 1);
else
z=my_mreq(size, 0);
if(z==0)
printf("LocalAlloc() failed\n");
+ dbgprintf("LocalAlloc(%d, flags 0x%x) => 0x%x\n", size, flags, z);
return z;
-}
+}
+
+void* WINAPI expLocalReAlloc(int handle,int size, int flags)
+{
+ void *newpointer;
+ int oldsize;
+
+ newpointer=NULL;
+ if (flags & LMEM_MODIFY) {
+ dbgprintf("LocalReAlloc MODIFY\n");
+ return (void *)handle;
+ }
+ oldsize = my_size((void *)handle);
+ newpointer = my_realloc((void *)handle,size);
+ dbgprintf("LocalReAlloc(%x %d(old %d), flags 0x%x) => 0x%x\n", handle,size,oldsize, flags,newpointer);
+
+ return newpointer;
+}
+
void* WINAPI expLocalLock(void* z)
{
- dbgprintf("LocalLock\n");
+ dbgprintf("LocalLock(0x%x) => 0x%x\n", z, z);
return z;
-}
+}
+
void* WINAPI expGlobalAlloc(int flags, int size)
{
void* z;
- dbgprintf("GlobalAlloc(%d, flags 0x%X)\n", size, flags);
+ dbgprintf("GlobalAlloc(%d, flags 0x%X)\n", size, flags);
if(flags&GMEM_ZEROINIT)
z=my_mreq(size, 1);
- else
+ //z=calloc(size, 1);
+ else
z=my_mreq(size, 0);
+ //z=malloc(size);
if(z==0)
- printf("LocalAlloc() failed\n");
+ printf("GlobalAlloc() failed\n");
+ dbgprintf("GlobalAlloc(%d, flags 0x%x) => 0x%x\n", size, flags, z);
return z;
-}
+}
void* WINAPI expGlobalLock(void* z)
{
- dbgprintf("GlobalLock\n");
+ dbgprintf("GlobalLock(0x%x) => 0x%x\n", z, z);
return z;
-}
-
+}
int WINAPI expLoadStringA(long instance, long id, void* buf, long size)
{
- dbgprintf("LoadStringA\n");
- return LoadStringA(instance, id, buf, 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) => %d\n",
+// instance, id, buf, size, result);
+ return result;
+}
long WINAPI expMultiByteToWideChar(long v1, long v2, char* s1, long siz1, short* s2, int siz2)
{
@@ -970,7 +1274,7 @@ long WINAPI expMultiByteToWideChar(long v1, long v2, char* s1, long siz1, short*
result=1;
else
{
- if(siz1>siz2/2)siz1=siz2/2;
+ if(siz1>siz2/2)siz1=siz2/2;
for(i=1; i<=siz1; i++)
{
*s2=*s1;
@@ -981,37 +1285,66 @@ long WINAPI expMultiByteToWideChar(long v1, long v2, char* s1, long siz1, short*
result=i;
}
if(s1)
- dbgprintf("MultiByteToWideChar(codepage %d, flags 0x%x, string 0x%x='%s', "
- "size %d, dest buffer 0x%x, dest size %d) => %d\n",
- v1, v2, s1, s1, siz1, s2, siz2, result);
+ dbgprintf("MultiByteToWideChar(codepage %d, flags 0x%x, string 0x%x='%s',"
+ "size %d, dest buffer 0x%x, dest size %d) => %d\n",
+ 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);
+ 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");
+}
long WINAPI expWideCharToMultiByte(long v1, long v2, short* s1, long siz1, char* s2, int siz2, char* c3, int* siz3)
{
int result;
- dbgprintf("WCh2MB\n");
+ 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("=> %d\n", result);
+ //if(s1)wch_print(s1);
+ if(s2)dbgprintf(" dest: %s\n", s2);
return result;
}
long WINAPI expGetVersionExA(OSVERSIONINFOA* c)
{
- dbgprintf("GetVersionExA\n");
+ dbgprintf("GetVersionExA(0x%x) => 1\n");
+ c->dwOSVersionInfoSize=sizeof(*c);
c->dwMajorVersion=4;
- c->dwMinorVersion=10;
- c->dwBuildNumber=0x40a07ce;
+ c->dwMinorVersion=0;
+ c->dwBuildNumber=0x4000457;
+#if 0
+ // leave it here for testing win9x-only codecs
c->dwPlatformId=VER_PLATFORM_WIN32_WINDOWS;
- strcpy(c->szCSDVersion, "Win98");
+ 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: 4\n Minor version: 0\n Build number: 0x4000457\n"
+ " Platform Id: VER_PLATFORM_WIN32_NT\n Version string: 'Service Pack 3'\n");
return 1;
-}
+}
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("0\n");
+*/
if(mlist!=NULL)
{
mutex_list* pp=mlist;
@@ -1024,23 +1357,24 @@ HANDLE WINAPI expCreateSemaphoreA(char* v1, long init_count, long max_count, cha
v1, init_count, max_count, name, name, mlist);
return (HANDLE)mlist;
}
- }while((pp=pp->prev));
- }
- pm=my_mreq(sizeof(pthread_mutex_t), 0);
+ }while((pp=pp->prev) != NULL);
+ }
+ pm=mreq_private(sizeof(pthread_mutex_t), 0, AREATYPE_MUTEX);
pthread_mutex_init(pm, NULL);
- pc=my_mreq(sizeof(pthread_cond_t), 0);
+ pc=mreq_private(sizeof(pthread_cond_t), 0, AREATYPE_COND);
pthread_cond_init(pc, NULL);
if(mlist==NULL)
{
- mlist=my_mreq(sizeof(mutex_list), 00);
+ mlist=mreq_private(sizeof(mutex_list), 00, AREATYPE_EVENT);
mlist->next=mlist->prev=NULL;
}
else
{
- mlist->next=my_mreq(sizeof(mutex_list), 00);
+ mlist->next=mreq_private(sizeof(mutex_list), 00, AREATYPE_EVENT);
mlist->next->prev=mlist;
mlist->next->next=NULL;
mlist=mlist->next;
+// printf("new semaphore %p\n", mlist);
}
mlist->type=1; /* Type Semaphore */
mlist->pm=pm;
@@ -1062,13 +1396,13 @@ HANDLE WINAPI expCreateSemaphoreA(char* v1, long init_count, long max_count, cha
v1, init_count, max_count, mlist);
return (HANDLE)mlist;
}
-
+
long WINAPI expReleaseSemaphore(long hsem, long increment, long* prev_count)
{
-// The state of a semaphore object is signaled when its 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.
+// state, the count of the semaphore is decreased by one.
mutex_list *ml = (mutex_list *)hsem;
pthread_mutex_lock(ml->pm);
@@ -1084,58 +1418,85 @@ long WINAPI expReleaseSemaphore(long hsem, long increment, long* prev_count)
long WINAPI expRegOpenKeyExA(long key, const char* subkey, long reserved, long access, int* newkey)
{
- dbgprintf("RegOpenKeyExA(%d,%s)\n", key, subkey);
- return RegOpenKeyExA(key, subkey, reserved, access, newkey);
-}
+ long result=RegOpenKeyExA(key, subkey, reserved, access, newkey);
+ dbgprintf("RegOpenKeyExA(key 0x%x, subkey %s, reserved %d, access 0x%x, pnewkey 0x%x) => %d\n",
+ key, subkey, reserved, access, newkey, result);
+ if(newkey)dbgprintf(" New key: 0x%x\n", *newkey);
+ return result;
+}
long WINAPI expRegCloseKey(long key)
{
- dbgprintf("RegCloseKey()\n");
- return RegCloseKey(key);
-}
+ long result=RegCloseKey(key);
+ dbgprintf("RegCloseKey(0x%x) => %d\n", key, result);
+ return result;
+}
long WINAPI expRegQueryValueExA(long key, const char* value, int* reserved, int* type, int* data, int* count)
{
- dbgprintf("RegQueryValueExA()\n");
- return RegQueryValueExA(key, value, reserved, type, data, 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%x\n", key, value, reserved, data, count, result);
+ if(data && count)dbgprintf(" read %d bytes: '%s'\n", *count, data);
+ return result;
+}
long WINAPI expRegCreateKeyExA(long key, const char* name, long reserved,
void* classs, long options, long security,
- void* sec_attr, int* newkey, int* status)
-{
- dbgprintf("RegCreateKeyExA()\n");
- return RegCreateKeyExA(key, name, reserved, classs, options, security, sec_attr, newkey, status);
+ 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) => %d\n",
+ key, name, name, reserved, classs, options, security, sec_attr, newkey, status, result);
+ if(!result && newkey) dbgprintf(" New key: 0x%x\n", *newkey);
+ if(!result && status) dbgprintf(" New key status: 0x%x\n", *status);
+ return result;
}
long WINAPI expRegSetValueExA(long key, const char* name, long v1, long v2, void* data, long size)
{
- dbgprintf("RegSetValueExA()\n");
- return RegSetValueExA(key, name, v1, v2, data, 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;
+}
long WINAPI expRegOpenKeyA (
long hKey,
LPCSTR lpSubKey,
int* phkResult
){
- return RegOpenKeyExA(hKey, lpSubKey, 0, 0, phkResult);
+ long result=RegOpenKeyExA(hKey, lpSubKey, 0, 0, phkResult);
+ dbgprintf("RegOpenKeyExA(key 0x%x, subkey '%s', 0x%x) => %d\n",
+ hKey, lpSubKey, phkResult, result);
+ if(!result && phkResult) dbgprintf(" New key: 0x%x\n", *phkResult);
+ return result;
+}
+
+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);
}
long WINAPI expQueryPerformanceCounter(long long* z)
{
- dbgprintf("QueryPerformanceCounter()\n");
longcount(z);
- return 1;
+ dbgprintf("QueryPerformanceCounter(0x%x) => 1 ( %Ld )\n", z, *z);
+ return 1;
}
-static double
-linux_cpuinfo_freq()
+/*
+ * 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,200,f) != NULL) {
+ while (fgets(line,sizeof(line),f)!=NULL) {
/* NOTE: the ':' is the only character we can rely on */
if (!(value = strchr(line,':')))
continue;
@@ -1157,12 +1518,13 @@ linux_cpuinfo_freq()
return freq;
}
+
static double
solaris_kstat_freq()
{
-#if HAVE_KSTAT
+#if defined(HAVE_LIBKSTAT) && defined(KSTAT_DATA_INT32)
/*
- * try to extact the CPU speed from the solaris kernel's kstat data
+ * try to extract the CPU speed from the solaris kernel's kstat data
*/
kstat_ctl_t *kc;
kstat_t *ksp;
@@ -1194,26 +1556,33 @@ solaris_kstat_freq()
if (mhz > 0)
return mhz * 1000.;
-#endif /* HAVE_KSTAT */
- return -1;
+#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()
{
- int i=time(NULL);
- unsigned int x,y;
+ 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();
- return (double)(y-x)/1000.;
+ ofreq = (double)(y-x)/1000.;
+ return ofreq;
}
static double CPU_Freq()
{
double freq;
-
+
if ((freq = linux_cpuinfo_freq()) > 0)
return freq;
@@ -1225,111 +1594,113 @@ static double CPU_Freq()
long WINAPI expQueryPerformanceFrequency(long long* z)
{
- dbgprintf("QueryPerformanceFrequency()\n");
*z=(long long)CPU_Freq();
- return 1;
+ dbgprintf("QueryPerformanceFrequency(0x%x) => 1 ( %Ld )\n", z, *z);
+ return 1;
}
long WINAPI exptimeGetTime()
{
struct timeval t;
- dbgprintf("timeGetTime()\n");
+ long result;
gettimeofday(&t, 0);
- return 1000*t.tv_sec+t.tv_usec/1000;
+ result=1000*t.tv_sec+t.tv_usec/1000;
+ dbgprintf("timeGetTime() => %d\n", result);
+ return result;
}
void* WINAPI expLocalHandle(void* v)
{
- dbgprintf("LocalHandle\n");
+ dbgprintf("LocalHandle(0x%x) => 0x%x\n", v, v);
return v;
-}
+}
+
void* WINAPI expGlobalHandle(void* v)
{
- dbgprintf("GlobalHandle\n");
+ dbgprintf("GlobalHandle(0x%x) => 0x%x\n", v, v);
return v;
-}
+}
int WINAPI expGlobalUnlock(void* v)
{
- dbgprintf("GlobalUnlock\n");
+ dbgprintf("GlobalUnlock(0x%x) => 1\n", v);
return 1;
}
-//
void* WINAPI expGlobalFree(void* v)
{
- dbgprintf("GlobalFree(%X)\n", v);
+ dbgprintf("GlobalFree(0x%x) => 0\n", v);
my_release(v);
+ //free(v);
return 0;
-}
+}
+
+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%x\n", v,size,flags,result);
+ return result;
+}
int WINAPI expLocalUnlock(void* v)
{
- dbgprintf("LocalUnlock\n");
+ dbgprintf("LocalUnlock(0x%x) => 1\n", v);
return 1;
}
-//
+ //
void* WINAPI expLocalFree(void* v)
{
- dbgprintf("LocalFree(%X)\n", v);
+ dbgprintf("LocalFree(0x%x) => 0\n", v);
my_release(v);
return 0;
-}
-
+}
HRSRC WINAPI expFindResourceA(HMODULE module, char* name, char* type)
{
- dbgprintf("FindResourceA\n");
- return FindResourceA(module, name, type);
+ HRSRC result=FindResourceA(module, name, type);
+ dbgprintf("FindResourceA(module 0x%x, name 0x%x, type 0x%x) => 0x%x\n", module, name, type, result);
+ return result;
}
+extern HRSRC WINAPI LoadResource(HMODULE, HRSRC);
HGLOBAL WINAPI expLoadResource(HMODULE module, HRSRC res)
{
- dbgprintf("LoadResource\n");
- return LoadResource(module, res);;
+ HGLOBAL result=LoadResource(module, res);
+ dbgprintf("LoadResource(module 0x%x, resource 0x%x) => 0x%x\n", module, res, result);
+ return result;
}
void* WINAPI expLockResource(long res)
{
- dbgprintf("LockResource\n");
- return LockResource(res);
-}
+ void* result=LockResource(res);
+ dbgprintf("LockResource(0x%x) => 0x%x\n", res, result);
+ return result;
+}
int WINAPI expFreeResource(long res)
{
- dbgprintf("FreeResource\n");
- return FreeResource(res);
-}
+ int result=FreeResource(res);
+ dbgprintf("FreeResource(0x%x) => %d\n", res, result);
+ return result;
+}
//bool fun(HANDLE)
//!0 on success
int WINAPI expCloseHandle(long v1)
{
- dbgprintf("CloseHandle\n");
+ dbgprintf("CloseHandle(0x%x) => 1\n", v1);
return 1;
-}
+}
const char* WINAPI expGetCommandLineA()
{
- dbgprintf("GetCommandLine\n");
+ dbgprintf("GetCommandLineA() => \"c:\\aviplay.exe\"\n");
return "c:\\aviplay.exe";
}
+static short envs[]={'p', 'a', 't', 'h', ' ', 'c', ':', '\\', 0, 0};
LPWSTR WINAPI expGetEnvironmentStringsW()
{
- static wchar_t envs[]={'p', 'a', 't', 'h', ' ', 'c', ':', '\\', 0, 0};
- dbgprintf("GetEnvStringsW\n");
- return (LPWSTR)envs;
-}
-
-int WINAPI expFreeEnvironmentStringsW(short* strings)
-{
- dbgprintf("FreeEnvStringsW\n");
- return 1;
-}
-LPCSTR WINAPI expGetEnvironmentStrings()
-{
- dbgprintf("GetEnvStrings\n");
- return "\0\0";
+ dbgprintf("GetEnvironmentStringsW() => 0\n", envs);
+ return 0;
}
-
void * WINAPI expRtlZeroMemory(void *p, size_t len)
{
void* result=memset(p,0,len);
dbgprintf("RtlZeroMemory(0x%x, len %d) => 0x%x\n",p,len,result);
return result;
}
-
void * WINAPI expRtlMoveMemory(void *dst, void *src, size_t len)
{
void* result=memmove(dst,src,len);
@@ -1343,159 +1714,243 @@ void * WINAPI expRtlFillMemory(void *p, int ch, size_t len)
dbgprintf("RtlFillMemory(0x%x, char 0x%x, len %d) => 0x%x\n",p,ch,len,result);
return result;
}
+int WINAPI expFreeEnvironmentStringsW(short* strings)
+{
+ dbgprintf("FreeEnvironmentStringsW(0x%x) => 1\n", strings);
+ return 1;
+}
+int WINAPI expFreeEnvironmentStringsA(char* strings)
+{
+ dbgprintf("FreeEnvironmentStringsA(0x%x) => 1\n", strings);
+ return 1;
+}
+static const char ch_envs[]=
+ "__MSVCRT_HEAP_SELECT=__GLOBAL_HEAP_SELECTED,1\r\n"
+ "PATH=C:\\;C:\\windows\\;C:\\windows\\system\r\n";
+LPCSTR WINAPI expGetEnvironmentStrings()
+{
+ dbgprintf("GetEnvironmentStrings() => 0x%x\n", ch_envs);
+ return (LPCSTR)ch_envs;
+// dbgprintf("GetEnvironmentStrings() => 0\n");
+// return 0;
+}
int WINAPI expGetStartupInfoA(STARTUPINFOA *s)
{
- /* int i; */
- dbgprintf("GetStartupInfoA\n");
-/*
- for(i=0; i<sizeof(STARTUPINFOA)/4; i++)
- ((int*)s)[i]=i+0x200;
-*/
+ int i;
+ dbgprintf("GetStartupInfoA(0x%x) => 1\n");
memset(s, 0, sizeof(*s));
s->cb=sizeof(*s);
- s->lpReserved="qwe";
- s->lpDesktop="rty";
- s->lpTitle="uio";
- s->dwX=s->dwY=0;
- s->dwXSize=s->dwYSize=200;
- s->dwFlags=s->wShowWindow=0;
+// 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=%d\n", 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=%d\n",
+ s->dwX, s->dwY, s->dwXSize, s->dwYSize);
+ dbgprintf(" dwXCountChars=%d dwYCountChars=%d dwFillAttribute=%d\n",
+ s->dwXCountChars, s->dwYCountChars, s->dwFillAttribute);
+ dbgprintf(" dwFlags=0x%x wShowWindow=0x%x cbReserved2=0x%x\n",
+ s->dwFlags, s->wShowWindow, s->cbReserved2);
+ dbgprintf(" lpReserved2=0x%x hStdInput=0x%x hStdOutput=0x%x hStdError=0x%x\n",
+ s->lpReserved2, s->hStdInput, s->hStdOutput, s->hStdError);
return 1;
-}
+}
int WINAPI expGetStdHandle(int z)
{
- dbgprintf("GetStdHandle\n");
- dbgprintf("WARNING: Unsupported call: GetStdHandle\n");
- return 1234;
+ dbgprintf("GetStdHandle(0x%x) => 0x%x\n", z+0x1234);
+ return z+0x1234;
}
int WINAPI expGetFileType(int handle)
{
- dbgprintf("GetFileType\n");
- dbgprintf("WARNING: Unsupported call: GetFileType\n");
- return 5678;
+ dbgprintf("GetFileType(0x%x) => 0x3 = pipe\n", handle);
+ return 0x3;
}
int WINAPI expSetHandleCount(int count)
{
- dbgprintf("SetHandleCount\n");
- return 1;
+ dbgprintf("SetHandleCount(0x%x) => 1\n", count);
+ return 1;
}
int WINAPI expGetACP()
{
- dbgprintf("GetACP\n");
- dbgprintf("WARNING: Unsupported call: GetACP\n");
- return 0;
+ dbgprintf("GetACP() => 0\n");
+ return 0;
}
extern WINE_MODREF *MODULE32_LookupHMODULE(HMODULE m);
int WINAPI expGetModuleFileNameA(int module, char* s, int len)
{
WINE_MODREF *mr;
- dbgprintf("GetModuleFileNameA\n");
+ int result;
// printf("File name of module %X requested\n", module);
if(s==0)
- return 0;
+ result=0;
+ else
if(len<35)
- return 0;
- strcpy(s, "c:\\windows\\system\\");
- mr=MODULE32_LookupHMODULE(module);
- if(mr==0)//oops
+ result=0;
+ else
{
- strcat(s, "aviplay.dll");
- return 1;
- }
- if(strrchr(mr->filename, '/')==NULL)
- strcat(s, mr->filename);
+ 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) => %d\n",
+ module, s, len, result);
else
- strcat(s, strrchr(mr->filename, '/')+1);
- return 1;
-}
-
+ dbgprintf("GetModuleFileNameA(0x%x, 0x%x, %d) => %d ( '%s' )",
+ module, s, len, result, s);
+ return result;
+}
+
int WINAPI expSetUnhandledExceptionFilter(void* filter)
{
- dbgprintf("SetUnhandledExcFilter\n");
- return 1;/*unsupported and probably won't ever be supported */
-}
-
-extern char* win32_def_path;
+ dbgprintf("SetUnhandledExceptionFilter(0x%x) => 1\n", filter);
+ return 1;//unsupported and probably won't ever be supported
+}
int WINAPI expLoadLibraryA(char* name)
{
- char qq[256];
- dbgprintf("LoadLibraryA\n");
- printf("They want library %s\n", name);
- strcpy(qq, win32_def_path);
- strcat(qq, "/");
- strcat(qq, name);
- return LoadLibraryA(qq);
-}
+ 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 is loading kernel32.dll
+ if (strcasecmp(name, "kernel32.dll") == 1)
+ return (int) LookupExternal(name, 0);
+
+ result=LoadLibraryA(name);
+ dbgprintf("Returned LoadLibraryA(0x%x='%s'), win32_def_path=%s => 0x%x\n", name, name, win32_def_path, result);
+
+ return result;
+}
int WINAPI expFreeLibrary(int module)
{
- dbgprintf("FreeLibrary\n");
- return FreeLibrary(module);
-}
+ int result=FreeLibrary(module);
+ dbgprintf("FreeLibrary(0x%x) => %d\n", module, result);
+ return result;
+}
void* WINAPI expGetProcAddress(HMODULE mod, char* name)
{
- dbgprintf("GetProcAddress\n");
- return GetProcAddress(mod, name);
-}
+ void* result;
+ if(mod!=MODULE_HANDLE_kernel32)
+ result=GetProcAddress(mod, name);
+ else
+ result=LookupExternalByName("kernel32.dll", name);
+ dbgprintf("GetProcAddress(0x%x, '%s') => 0x%x\n", mod, name, result);
+ return result;
+}
long WINAPI expCreateFileMappingA(int hFile, void* lpAttr,
long flProtect, long dwMaxHigh, long dwMaxLow, const char* name)
{
- dbgprintf("CreateFileMappingA\n");
- return CreateFileMappingA(hFile, lpAttr, flProtect, dwMaxHigh, dwMaxLow, 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) => %d\n",
+ 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') => %d\n",
+ hFile, lpAttr, flProtect, dwMaxHigh, dwMaxLow, name, name, result);
+ return result;
+}
long WINAPI expOpenFileMappingA(long hFile, long hz, const char* name)
{
- dbgprintf("OpenFileMappingA\n");
- return OpenFileMappingA(hFile, hz, name);
+ long result=OpenFileMappingA(hFile, hz, name);
+ if(!name)
+ dbgprintf("OpenFileMappingA(0x%x, 0x%x, 0) => %d\n",
+ hFile, hz, result);
+ else
+ dbgprintf("OpenFileMappingA(0x%x, 0x%x, 0x%x='%s') => %d\n",
+ hFile, hz, name, name, result);
+ return result;
}
void* WINAPI expMapViewOfFile(HANDLE file, DWORD mode, DWORD offHigh, DWORD offLow, DWORD size)
{
- dbgprintf("MapViewOfFile(%d, %x, %x, %x, %x)\n",
- file,mode,offHigh,offLow,size);
+ dbgprintf("MapViewOfFile(0x%x, 0x%x, 0x%x, 0x%x, size %d) => 0x%x\n",
+ file,mode,offHigh,offLow,size,(char*)file+offLow);
return (char*)file+offLow;
}
void* WINAPI expUnmapViewOfFile(void* view)
{
- dbgprintf("UnmapViewOfFile()\n");
+ dbgprintf("UnmapViewOfFile(0x%x) => 0\n", view);
return 0;
}
void* WINAPI expSleep(int time)
{
- dbgprintf("Sleep(%d)\n", time);
+// extern int avm_usleep(int);
+ dbgprintf("Sleep(%d) => 0\n", time);
+// avm_usleep(time);
usleep(time);
return 0;
}
// why does IV32 codec want to call this? I don't know ...
void* WINAPI expCreateCompatibleDC(int hdc)
{
- dbgprintf("CreateCompatibleDC(%d)\n", hdc);
- return (void*)129;
+ dbgprintf("CreateCompatibleDC(%d) => 0x81\n", hdc);
+ return (void*)0x81;
}
int WINAPI expGetDeviceCaps(int hdc, int unk)
{
- dbgprintf("GetDeviceCaps(%d, %d)\n", hdc, unk);
+ dbgprintf("GetDeviceCaps(0x%x, %d) => 0\n", hdc, unk);
return 0;
}
WIN_BOOL WINAPI expDeleteDC(int hdc)
{
- dbgprintf("DeleteDC(%d)\n", hdc);
+ dbgprintf("DeleteDC(0x%x) => 0\n", hdc);
return 0;
}
int expwsprintfA(char* string, char* format, ...)
{
va_list va;
+ int result;
va_start(va, format);
- dbgprintf("wsprintfA\n");
- return vsprintf(string, format, va);
+ result=vsprintf(string, format, va);
+ dbgprintf("wsprintfA(0x%x, '%s', ...) => %d\n", string, format, result);
+ va_end(va);
+ return result;
}
int WINAPI expGetPrivateProfileIntA(const char* appname, const char* keyname, int default_value, const char* filename)
@@ -1504,10 +1959,13 @@ int WINAPI expGetPrivateProfileIntA(const char* appname, const char* keyname, in
char buffer[256];
char* fullname;
int result;
-
+
buffer[255]=0;
- dbgprintf("GetPrivateProfileIntA(%s, %s, %s)\n", appname, keyname, filename );
- if(!(appname && keyname && filename) ) return default_value;
+ if(!(appname && keyname && filename) )
+ {
+ dbgprintf("GetPrivateProfileIntA('%s', '%s', %d, '%s') => %d\n", appname, keyname, default_value, filename, default_value );
+ return default_value;
+ }
fullname=(char*)malloc(50+strlen(appname)+strlen(keyname)+strlen(filename));
strcpy(fullname, "Software\\IniFileMapping\\");
strcat(fullname, appname);
@@ -1519,19 +1977,28 @@ int WINAPI expGetPrivateProfileIntA(const char* appname, const char* keyname, in
if((size>=0)&&(size<256))
buffer[size]=0;
// printf("GetPrivateProfileIntA(%s, %s, %s) -> %s\n", appname, keyname, filename, buffer);
- free(fullname);
+ free(fullname);
if(result)
- return default_value;
+ result=default_value;
else
- return atoi(buffer);
+ result=atoi(buffer);
+ dbgprintf("GetPrivateProfileIntA('%s', '%s', %d, '%s') => %d\n", appname, keyname, default_value, filename, result);
+ return result;
+}
+int WINAPI expGetProfileIntA(const char* appname, const char* keyname, int default_value)
+{
+ dbgprintf("GetProfileIntA -> ");
+// dbgprintf("GetProfileIntA(%s, %s, %d)\n", appname, keyname, default_value);
+ return expGetPrivateProfileIntA(appname, keyname, default_value, "default");
}
+
int WINAPI expGetPrivateProfileStringA(const char* appname, const char* keyname,
const char* def_val, char* dest, unsigned int len, const char* filename)
{
int result;
int size;
char* fullname;
- dbgprintf("GetPrivateProfileStringA(%s, %s, %s, %X, %X, %s)\n", appname, keyname, def_val, dest, len, filename );
+ dbgprintf("GetPrivateProfileStringA('%s', '%s', def_val '%s', 0x%x, 0x%x, '%s')", appname, keyname, def_val, dest, len, filename );
if(!(appname && keyname && filename) ) return 0;
fullname=(char*)malloc(50+strlen(appname)+strlen(keyname)+strlen(filename));
strcpy(fullname, "Software\\IniFileMapping\\");
@@ -1543,19 +2010,26 @@ int WINAPI expGetPrivateProfileStringA(const char* appname, const char* keyname,
size=len;
result=RegQueryValueExA(HKEY_LOCAL_MACHINE, fullname, NULL, NULL, (int*)dest, &size);
// printf("GetPrivateProfileStringA(%s, %s, %s, %X, %X, %s)\n", appname, keyname, def_val, dest, len, filename );
- free(fullname);
- if(!result)
- return size;
- strncpy(dest, def_val, size);
+ free(fullname);
+ if(result)
+ {
+ strncpy(dest, def_val, size);
+ if (strlen(def_val)< size) size = strlen(def_val);
+ }
+ dbgprintf(" => %d ( '%s' )\n", size, dest);
return size;
}
int WINAPI expWritePrivateProfileStringA(const char* appname, const char* keyname,
const char* string, const char* filename)
{
- /* int size=256; */
+ int size=256;
char* fullname;
- dbgprintf("WritePrivateProfileStringA(%s, %s, %s, %s)\n", appname, keyname, string, filename );
- if(!(appname && keyname && filename) ) return -1;
+ dbgprintf("WritePrivateProfileStringA('%s', '%s', '%s', '%s')", appname, keyname, string, filename );
+ if(!(appname && keyname && filename) )
+ {
+ dbgprintf(" => -1\n");
+ return -1;
+ }
fullname=(char*)malloc(50+strlen(appname)+strlen(keyname)+strlen(filename));
strcpy(fullname, "Software\\IniFileMapping\\");
strcat(fullname, appname);
@@ -1566,9 +2040,66 @@ int WINAPI expWritePrivateProfileStringA(const char* appname, const char* keynam
RegSetValueExA(HKEY_LOCAL_MACHINE, fullname, 0, REG_SZ, (int*)string, strlen(string));
// printf("RegSetValueExA(%s,%d)\n", string, strlen(string));
// printf("WritePrivateProfileStringA(%s, %s, %s, %s)\n", appname, keyname, string, filename );
- free(fullname);
+ free(fullname);
+ dbgprintf(" => 0\n");
return 0;
}
+int expsprintf(char* str, const char* format, ...)
+{
+ va_list args;
+ int r;
+ dbgprintf("sprintf(%s, %s)\n", str, format);
+ va_start(args, format);
+ r = vsprintf(str, format, args);
+ va_end(args);
+ return r;
+}
+int expsscanf(const char* str, const char* format, ...)
+{
+ va_list args;
+ int r;
+ dbgprintf("sscanf(%s, %s)\n", str, format);
+ va_start(args, format);
+ r = vsscanf(str, format, args);
+ va_end(args);
+ return r;
+}
+void* expfopen(const char* path, const char* mode)
+{
+ printf("fopen: \"%s\" mode:%s\n", path, mode);
+ //return fopen(path, mode);
+ return fdopen(0, mode); // everything on screen
+}
+int expfprintf(void* stream, const char* format, ...)
+{
+ va_list args;
+ int r = 0;
+#if 1
+ va_start(args, format);
+ r = vfprintf((FILE*) stream, format, args);
+ va_end(args);
+#endif
+ return r;
+}
+
+int expprintf(const char* format, ...)
+{
+ va_list args;
+ int r;
+ va_start(args, format);
+ r = vprintf(format, args);
+ va_end(args);
+ return r;
+}
+
+void* expwcscpy(WCHAR* dst, const WCHAR* src)
+{
+ WCHAR* p = dst;
+ while ((*p++ = *src++))
+ ;
+ return dst;
+}
+
unsigned int _GetPrivateProfileIntA(const char* appname, const char* keyname, INT default_value, const char* filename)
{
@@ -1586,51 +2117,164 @@ int _WritePrivateProfileStringA(const char* appname, const char* keyname,
}
+
int WINAPI expDefDriverProc(int _private, int id, int msg, int arg1, int arg2)
{
- printf("Called DefDriverProc(%X)\n", msg);
+ dbgprintf("DefDriverProc(0x%x, 0x%x, 0x%x, 0x%x, 0x%x) => 0\n", _private, id, msg, arg1, arg2);
return 0;
-}
+}
int WINAPI expSizeofResource(int v1, int v2)
{
- dbgprintf("SizeofResource()\n");
- return SizeofResource(v1, v2);
-}
+ int result=SizeofResource(v1, v2);
+ dbgprintf("SizeofResource(0x%x, 0x%x) => %d\n", v1, v2, result);
+ return result;
+}
int WINAPI expGetLastError()
{
- dbgprintf("GetLastError()\n");
- return GetLastError();
+ int result=GetLastError();
+ dbgprintf("GetLastError() => 0x%x\n", result);
+ return result;
}
void WINAPI expSetLastError(int error)
{
- dbgprintf("SetLastError()\n");
+ dbgprintf("SetLastError(0x%x)\n", error);
SetLastError(error);
-}
+}
char* expstrrchr(char* string, int value)
{
- return strrchr(string, value);
-}
+ char* result=strrchr(string, value);
+ if(result)
+ dbgprintf("strrchr(0x%x='%s', %d) => 0x%x='%s'", string, string, value, result, result);
+ else
+ dbgprintf("strrchr(0x%x='%s', %d) => 0", string, string, value);
+ return result;
+}
char* expstrchr(char* string, int value)
{
- return strchr(string, value);
-}
+ char* result=strchr(string, value);
+ if(result)
+ dbgprintf("strchr(0x%x='%s', %d) => 0x%x='%s'", string, string, value, result, result);
+ else
+ dbgprintf("strchr(0x%x='%s', %d) => 0", string, string, value);
+ return result;
+}
+int expstrlen(char* str)
+{
+ int result=strlen(str);
+ dbgprintf("strlen(0x%x='%s') => %d\n", str, str, result);
+ return result;
+}
+int expstrcpy(char* str1, const char* str2)
+{
+ int result= (int) strcpy(str1, str2);
+ dbgprintf("strcpy(0x%x, 0x%x='%s') => %d\n", str1, str2, str2, result);
+ return result;
+}
+int expstrcmp(const char* str1, const char* str2)
+{
+ int result=strcmp(str1, str2);
+ dbgprintf("strcmp(0x%x='%s', 0x%x='%s') => %d\n", str1, str1, str2, str2, result);
+ return result;
+}
+int expstrcat(char* str1, const char* str2)
+{
+ int result= (int) strcat(str1, str2);
+ dbgprintf("strcat(0x%x='%s', 0x%x='%s') => %d\n", str1, str1, str2, str2, result);
+ return result;
+}
+int expisalnum(int c)
+{
+ int result= (int) isalnum(c);
+ dbgprintf("isalnum(0x%x='%c' => %d\n", c, c, result);
+ return result;
+}
+int expmemmove(void* dest, void* src, int n)
+{
+ int result= (int) memmove(dest, src, n);
+ dbgprintf("memmove(0x%x, 0x%x, %d) => %d\n", dest, src, n, result);
+ return result;
+}
+int expmemcmp(void* dest, void* src, int n)
+{
+ int result=memcmp(dest, src, n);
+ dbgprintf("memcmp(0x%x, 0x%x, %d) => %d\n", dest, src, n, result);
+ return result;
+}
+void *expmemcpy(void* dest, void* src, int n)
+{
+ void *result=memcpy(dest, src, n);
+ dbgprintf("memcpy(0x%x, 0x%x, %d) => %p\n", dest, src, n, result);
+ return result;
+}
+time_t exptime(time_t* t)
+{
+ time_t result=time(t);
+ dbgprintf("time(0x%x) => %d\n", t, result);
+ return result;
+}
+
+int exprand(void)
+{
+ return rand();
+}
+
+double explog10(double x)
+{
+ return log10(x);
+}
+
+double expcos(double x)
+{
+ return cos(x);
+}
+
+double exppow(double x, double y)
+{
+ return pow(x, y);
+}
+
+void expsrand(int seed)
+{
+ srand(seed);
+}
+
+int exp_ftol(float f)
+{
+ return (int)(f+.5);
+}
+
+int WINAPI expStringFromGUID2(GUID* guid, char* str, int cbMax)
+{
+ int result=snprintf(str, cbMax, "%.8x-%.4x-%.4x-%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x",
+ guid->f1, guid->f2, guid->f3,
+ (unsigned char)guid->f4[0], (unsigned char)guid->f4[1],
+ (unsigned char)guid->f4[2], (unsigned char)guid->f4[3],
+ (unsigned char)guid->f4[4], (unsigned char)guid->f4[5],
+ (unsigned char)guid->f4[6], (unsigned char)guid->f4[7]);
+ dbgprintf("StringFromGUID2(0x%x, 0x%x='%s', %d) => %d\n", guid, str, str, cbMax, result);
+ return result;
+}
+
int WINAPI expGetFileVersionInfoSizeA(const char* name, int* lpHandle)
{
- printf("GetFileVersionInfoSizeA(%s,0x%X)\n", name, *lpHandle);
+ dbgprintf("GetFileVersionInfoSizeA(0x%x='%s', 0x%X) => 0\n", name, name, lpHandle);
return 0;
-}
+}
int WINAPI expIsBadStringPtrW(const short* string, int nchars)
{
- if(string==0)return 1;
- return 0;
-}
+ int result;
+ if(string==0)result=1; else result=0;
+ dbgprintf("IsBadStringPtrW(0x%x, %d) => %d", string, nchars, result);
+ if(string)wch_print(string);
+ return result;
+}
extern long WINAPI InterlockedExchangeAdd( long* dest, long incr )
{
long ret;
@@ -1641,51 +2285,107 @@ extern long WINAPI InterlockedExchangeAdd( long* dest, long incr )
extern long WINAPI expInterlockedIncrement( long* dest )
{
- return InterlockedExchangeAdd( dest, 1 ) + 1;
+ long result=InterlockedExchangeAdd( dest, 1 ) + 1;
+ dbgprintf("InterlockedIncrement(0x%x => %d) => %d\n", dest, *dest, result);
+ return result;
}
extern long WINAPI expInterlockedDecrement( long* dest )
{
- return InterlockedExchangeAdd( dest, -1 ) - 1;
+ long result=InterlockedExchangeAdd( dest, -1 ) - 1;
+ dbgprintf("InterlockedDecrement(0x%x => %d) => %d\n", dest, *dest, result);
+ return result;
}
extern void WINAPI expOutputDebugStringA( const char* string )
{
+ dbgprintf("OutputDebugStringA(0x%x='%s')\n", string);
fprintf(stderr, "DEBUG: %s\n", string);
-}
+}
int WINAPI expGetDC(int hwnd)
{
+ dbgprintf("GetDC(0x%x) => 0\n", hwnd);
return 0;
}
int WINAPI expGetDesktopWindow()
{
+ dbgprintf("GetDesktopWindow() => 0\n");
return 0;
}
-
+
int WINAPI expReleaseDC(int hwnd, int hdc)
{
+ dbgprintf("ReleaseDC(0x%x, 0x%x) => 0\n", hwnd, hdc);
return 0;
-}
-
+}
static int cursor[100];
int WINAPI expLoadCursorA(int handle,LPCSTR name)
{
- dbgprintf("LoadCursorA(%d, 0x%x='%s') => 0x%x\n", handle, name, (int)&cursor[0]);
- return (int)&cursor[0];
+ dbgprintf("LoadCursorA(%d, 0x%x='%s') => 0x%x\n", handle, name, (int)&cursor[0]);
+ return (int)&cursor[0];
}
-
int WINAPI expSetCursor(void *cursor)
{
dbgprintf("SetCursor(0x%x) => 0x%x\n", cursor, cursor);
return (int)cursor;
}
+int WINAPI expGetCursorPos(void *cursor)
+{
+ dbgprintf("GetCursorPos(0x%x) => 0x%x\n", cursor, cursor);
+ return 1;
+}
+int WINAPI expRegisterWindowMessageA(char *message)
+{
+ dbgprintf("RegisterWindowMessageA(%s)\n", message);
+ return 1;
+}
+int WINAPI expGetProcessVersion(int pid)
+{
+ dbgprintf("GetProcessVersion(%d)\n", pid);
+ return 1;
+}
+int WINAPI expGetCurrentThread(void)
+{
+ dbgprintf("GetCurrentThread()\n");
+ return 1;
+}
+int WINAPI expGetOEMCP(void)
+{
+ dbgprintf("GetOEMCP()\n");
+ return 1;
+}
+int WINAPI expGetCPInfo(int cp,void *info)
+{
+ dbgprintf("GetCPInfo()\n");
+ return 0;
+}
+int WINAPI expGetSystemMetrics(int index)
+{
+ dbgprintf("GetSystemMetrics(%d)\n", index);
+ return 1;
+}
+int WINAPI expGetSysColor(int index)
+{
+ dbgprintf("GetSysColor(%d)\n", index);
+ return 1;
+}
+int WINAPI expGetSysColorBrush(int index)
+{
+ dbgprintf("GetSysColorBrush(%d)\n", index);
+ return 1;
+}
+
+
int WINAPI expGetSystemPaletteEntries(int hdc, int iStartIndex, int nEntries, void* lppe)
{
+ dbgprintf("GetSystemPaletteEntries(0x%x, 0x%x, 0x%x, 0x%x) => 0\n",
+ hdc, iStartIndex, nEntries, lppe);
return 0;
-}
+}
+
/*
typedef struct _TIME_ZONE_INFORMATION {
long Bias;
@@ -1695,25 +2395,42 @@ typedef struct _TIME_ZONE_INFORMATION {
char DaylightName[32];
SYSTEMTIME DaylightDate;
long DaylightBias;
-} TIME_ZONE_INFORMATION, *LPTIME_ZONE_INFORMATION;
+} TIME_ZONE_INFORMATION, *LPTIME_ZONE_INFORMATION;
*/
int WINAPI expGetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation)
{
+ const short name[]={'C', 'e', 'n', 't', 'r', 'a', 'l', ' ', 'S', 't', 'a',
+ 'n', 'd', 'a', 'r', 'd', ' ', 'T', 'i', 'm', 'e', 0};
+ const short pname[]={'C', 'e', 'n', 't', 'r', 'a', 'l', ' ', 'D', 'a', 'y',
+ 'l', 'i', 'g', 'h', 't', ' ', 'T', 'i', 'm', 'e', 0};
+ dbgprintf("GetTimeZoneInformation(0x%x) => TIME_ZONE_ID_STANDARD\n");
memset(lpTimeZoneInformation, 0, sizeof(TIME_ZONE_INFORMATION));
- return 0;
-}
+ lpTimeZoneInformation->Bias=360;//GMT-6
+ memcpy(lpTimeZoneInformation->StandardName, name, sizeof(name));
+ lpTimeZoneInformation->StandardDate.wMonth=10;
+ lpTimeZoneInformation->StandardDate.wDay=5;
+ lpTimeZoneInformation->StandardDate.wHour=2;
+ lpTimeZoneInformation->StandardBias=0;
+ memcpy(lpTimeZoneInformation->DaylightName, pname, sizeof(pname));
+ lpTimeZoneInformation->DaylightDate.wMonth=4;
+ lpTimeZoneInformation->DaylightDate.wDay=1;
+ lpTimeZoneInformation->DaylightDate.wHour=2;
+ lpTimeZoneInformation->DaylightBias=-60;
+ return TIME_ZONE_ID_STANDARD;
+}
void WINAPI expGetLocalTime(SYSTEMTIME* systime)
{
time_t local_time;
struct tm *local_tm;
struct timeval tv;
-
+
+ dbgprintf("GetLocalTime(0x%x)\n");
gettimeofday(&tv, NULL);
local_time=tv.tv_sec;
local_tm=localtime(&local_time);
-
+
systime->wYear = local_tm->tm_year + 1900;
systime->wMonth = local_tm->tm_mon + 1;
systime->wDayOfWeek = local_tm->tm_wday;
@@ -1722,6 +2439,11 @@ void WINAPI expGetLocalTime(SYSTEMTIME* systime)
systime->wMinute = local_tm->tm_min;
systime->wSecond = local_tm->tm_sec;
systime->wMilliseconds = (tv.tv_usec / 1000) % 1000;
+ dbgprintf(" Year: %d\n Month: %d\n Day of week: %d\n"
+ " Day: %d\n Hour: %d\n Minute: %d\n Second: %d\n"
+ " Milliseconds: %d\n",
+ systime->wYear, systime->wMonth, systime->wDayOfWeek, systime->wDay,
+ systime->wHour, systime->wMinute, systime->wSecond, systime->wMilliseconds);
}
int WINAPI expGetSystemTime(SYSTEMTIME* systime)
@@ -1729,11 +2451,12 @@ int WINAPI expGetSystemTime(SYSTEMTIME* systime)
time_t local_time;
struct tm *local_tm;
struct timeval tv;
-
+
+ dbgprintf("GetSystemTime(0x%x)\n", systime);
gettimeofday(&tv, NULL);
local_time=tv.tv_sec;
local_tm=gmtime(&local_time);
-
+
systime->wYear = local_tm->tm_year + 1900;
systime->wMonth = local_tm->tm_mon + 1;
systime->wDayOfWeek = local_tm->tm_wday;
@@ -1742,38 +2465,384 @@ int WINAPI expGetSystemTime(SYSTEMTIME* systime)
systime->wMinute = local_tm->tm_min;
systime->wSecond = local_tm->tm_sec;
systime->wMilliseconds = (tv.tv_usec / 1000) % 1000;
+ dbgprintf(" Year: %d\n Month: %d\n Day of week: %d\n"
+ " Day: %d\n Hour: %d\n Minute: %d\n Second: %d\n"
+ " Milliseconds: %d\n",
+ systime->wYear, systime->wMonth, systime->wDayOfWeek, systime->wDay,
+ systime->wHour, systime->wMinute, systime->wSecond, systime->wMilliseconds);
return 0;
}
int WINAPI expGetEnvironmentVariableA(const char* name, char* field, int size)
{
- dbgprintf("GetEnvironmentVariableA\n");
- printf("%s %x %x\n", name, *field, size);
+ char *p;
+// printf("%s %x %x\n", name, field, size);
if(field)field[0]=0;
+/*
+ p = getenv(name);
+ if (p) strncpy(field,p,size);
+*/
+ if (strcmp(name,"__MSVCRT_HEAP_SELECT")==0)
+ strcpy(field,"__GLOBAL_HEAP_SELECTED,1");
+ dbgprintf("GetEnvironmentVariableA(0x%x='%s', 0x%x, %d) => %d\n", name, name, field, size, strlen(field));
+ return strlen(field);
+}
+
+void* WINAPI expCoTaskMemAlloc(ULONG cb)
+{
+ return my_mreq(cb, 0);
+}
+void WINAPI expCoTaskMemFree(void* cb)
+{
+ my_release(cb);
+}
+
+void* CoTaskMemAlloc(ULONG cb){return expCoTaskMemAlloc(cb);}
+void CoTaskMemFree(void* cb){expCoTaskMemFree(cb);}
+
+struct COM_OBJECT_INFO
+{
+ GUID clsid;
+ long (*GetClassObject) (GUID* clsid, GUID* iid, void** ppv);
+};
+
+static struct COM_OBJECT_INFO* com_object_table=0;
+static int com_object_size=0;
+int RegisterComClass(GUID* clsid, GETCLASSOBJECT gcs)
+{
+ if(!clsid || !gcs)
+ return -1;
+ com_object_table=realloc(com_object_table, sizeof(struct COM_OBJECT_INFO)*(++com_object_size));
+ com_object_table[com_object_size-1].clsid=*clsid;
+ com_object_table[com_object_size-1].GetClassObject=gcs;
+ return 0;
+}
+
+int UnregisterComClass(GUID* clsid, GETCLASSOBJECT gcs)
+{
+ int found = 0;
+ int i = 0;
+ if(!clsid || !gcs)
+ return -1;
+
+ if (com_object_table == 0)
+ printf("Warning: UnregisterComClass() called without any registered class\n");
+ while (i < com_object_size)
+ {
+ if (found && i > 0)
+ {
+ memcpy(&com_object_table[i - 1].clsid,
+ &com_object_table[i].clsid, sizeof(GUID));
+ com_object_table[i - 1].GetClassObject =
+ com_object_table[i].GetClassObject;
+ }
+ else if (memcmp(&com_object_table[i].clsid, clsid, sizeof(GUID)) == 0
+ && com_object_table[i].GetClassObject == gcs)
+ {
+ found++;
+ }
+ i++;
+ }
+ if (found)
+ {
+ if (--com_object_size == 0)
+ {
+ free(com_object_table);
+ com_object_table = 0;
+ }
+ }
return 0;
}
-int WINAPI expIsRectEmpty(CONST RECT *lprc)
+GUID IID_IUnknown={0x00000000, 0x0000, 0x0000,
+ {0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}};
+GUID IID_IClassFactory={0x00000001, 0x0000, 0x0000,
+ {0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}};
+
+long WINAPI expCoCreateInstance(GUID* rclsid, struct IUnknown* pUnkOuter,
+ long dwClsContext, GUID* riid, void** ppv)
+{
+ int i;
+ struct COM_OBJECT_INFO* ci=0;
+ for(i=0; i<com_object_size; i++)
+ if(!memcmp(rclsid, &com_object_table[i].clsid, sizeof(GUID)))
+ ci=&com_object_table[i];
+ if(!ci)return 0x80040154;
+ // in 'real' world we should mess with IClassFactory here
+ i=ci->GetClassObject(rclsid, riid, ppv);
+ return i;
+}
+
+long CoCreateInstance(GUID* rclsid, struct IUnknown* pUnkOuter,
+ long dwClsContext, GUID* riid, void** ppv)
+{
+ return expCoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv);
+}
+
+int WINAPI expIsRectEmpty( CONST RECT *lprc)
{
dbgprintf("IsRectEmpty(0x%x)");
if((!lprc) || (lprc->right==lprc->left) || (lprc->top==lprc->bottom))
{
- dbgprintf(" => TRUE\n");
- return TRUE;
+ dbgprintf(" => TRUE\n");
+ return TRUE;
}
dbgprintf(" => FALSE\n");
return FALSE;
}
+int _adjust_fdiv=0; //what's this?
+
+
+
+
+unsigned int WINAPI expGetTempPathA(unsigned int len, char* path)
+{
+ dbgprintf("GetTempPathA(%d, 0x%x)", len, path);
+ if(len<5)
+ {
+ dbgprintf(" => 0\n");
+ return 0;
+ }
+ strcpy(path, "/tmp");
+ dbgprintf(" => 5 ( '/tmp' )\n");
+ return 5;
+}
+/*
+FYI:
+typedef struct
+{
+ DWORD dwFileAttributes;
+ FILETIME ftCreationTime;
+ FILETIME ftLastAccessTime;
+ FILETIME ftLastWriteTime;
+ DWORD nFileSizeHigh;
+ DWORD nFileSizeLow;
+ DWORD dwReserved0;
+ DWORD dwReserved1;
+ CHAR cFileName[260];
+ CHAR cAlternateFileName[14];
+} WIN32_FIND_DATAA, *LPWIN32_FIND_DATAA;
+*/
+
+HANDLE WINAPI expFindFirstFileA(LPCSTR s, LPWIN32_FIND_DATAA lpfd)
+{
+ dbgprintf("FindFirstFileA(0x%x='%s', 0x%x) => 0\n", s, s, lpfd);
+ strcpy(lpfd->cFileName, "msms001.vwp");
+ strcpy(lpfd->cAlternateFileName, "msms001.vwp");
+ return (HANDLE)0;
+}
+WIN_BOOL WINAPI expFindNextFileA(HANDLE h,LPWIN32_FIND_DATAA p)
+{
+ dbgprintf("FindNextFileA(0x%x, 0x%x) => 0\n", h, p);
+ return 0;
+}
+WIN_BOOL WINAPI expFindClose(HANDLE h)
+{
+ dbgprintf("FindClose(0x%x) => 0\n", h);
+ return 0;
+}
+UINT WINAPI expSetErrorMode(UINT i)
+{
+ dbgprintf("SetErrorMode(%d) => 0\n", i);
+ return 0;
+}
+UINT WINAPI expGetWindowsDirectoryA(LPSTR s,UINT c)
+{
+ char windir[]="c:\\windows";
+ int result;
+ strncpy(s, windir, c);
+ result=1+((c<strlen(windir))?c:strlen(windir));
+ dbgprintf("GetWindowsDirectoryA(0x%x, %d) => %d\n", s, c, result);
+ return result;
+}
+
+WIN_BOOL WINAPI expDeleteFileA(LPCSTR s)
+{
+ dbgprintf("DeleteFileA(0x%x='%s') => 0\n", s, s);
+ return 0;
+}
+WIN_BOOL WINAPI expFileTimeToLocalFileTime(const FILETIME* cpf, LPFILETIME pf)
+{
+ dbgprintf("FileTimeToLocalFileTime(0x%x, 0x%x) => 0\n", cpf, pf);
+ return 0;
+}
+
+UINT WINAPI expGetTempFileNameA(LPCSTR cs1,LPCSTR cs2,UINT i,LPSTR ps)
+{
+ char mask[16]="/tmp/AP_XXXXXX";
+ int result;
+ dbgprintf("GetTempFileNameA(0x%x='%s', 0x%x='%s', %d, 0x%x)", cs1, cs1, cs2, cs2, i, ps);
+ if(i && i<10)
+ {
+ dbgprintf(" => -1\n");
+ return -1;
+ }
+ result=mkstemp(mask);
+ sprintf(ps, "AP%d", result);
+ dbgprintf(" => %d\n", strlen(ps));
+ return strlen(ps);
+}
+//
+// This func might need proper implementation if we want AngelPotion codec.
+// They try to open APmpeg4v1.apl with it.
+// DLL will close opened file with CloseHandle().
+//
+HANDLE WINAPI expCreateFileA(LPCSTR cs1,DWORD i1,DWORD i2,
+ LPSECURITY_ATTRIBUTES p1, DWORD i3,DWORD i4,HANDLE i5)
+{
+ dbgprintf("CreateFileA(0x%x='%s', %d, %d, 0x%x, %d, %d, 0x%x)\n", cs1, cs1, i1,
+ i2, p1, i3, i4, i5);
+ if((!cs1) || (strlen(cs1)<2))return -1;
+ if(strncmp(cs1, "AP", 2))
+ {
+ int result;
+ char* tmp=(char*)malloc(strlen(win32_def_path)+50);
+ strcpy(tmp, win32_def_path);
+ strcat(tmp, "/");
+ strcat(tmp, "APmpg4v1.apl");
+ result=open(tmp, O_RDONLY);
+ free(tmp);
+ return result;
+ };
+ return atoi(cs1+2);
+}
+static char sysdir[]=".";
+LPCSTR WINAPI expGetSystemDirectoryA()
+{
+ dbgprintf("GetSystemDirectoryA() => 0x%x='%s'\n", sysdir, sysdir);
+ return sysdir;
+}
+WIN_BOOL WINAPI expReadFile(HANDLE h,LPVOID pv,DWORD size,LPDWORD rd,LPOVERLAPPED unused)
+{
+ int result;
+ dbgprintf("ReadFile(%d, 0x%x, %d -> 0x%x)\n", h, pv, size, rd);
+ result=read(h, pv, size);
+ if(rd)*rd=result;
+ if(!result)return 0;
+ return 1;
+}
+
+WIN_BOOL WINAPI expWriteFile(HANDLE h,LPCVOID pv,DWORD size,LPDWORD wr,LPOVERLAPPED unused)
+{
+ int result;
+ dbgprintf("WriteFile(%d, 0x%x, %d -> 0x%x)\n", h, pv, size, wr);
+ if(h==1234)h=1;
+ result=write(h, pv, size);
+ if(wr)*wr=result;
+ if(!result)return 0;
+ return 1;
+}
+DWORD WINAPI expSetFilePointer(HANDLE h, LONG val, LPLONG ext, DWORD whence)
+{
+ int wh;
+ dbgprintf("SetFilePointer(%d, %d, 0x%x, %d)\n", h, val, ext, whence);
+//why would DLL want temporary file with >2Gb size?
+ switch(whence)
+ {
+ case FILE_BEGIN:
+ wh=SEEK_SET;break;
+ case FILE_END:
+ wh=SEEK_END;break;
+ case FILE_CURRENT:
+ wh=SEEK_CUR;break;
+ default:
+ return -1;
+ }
+ return lseek(h, val, wh);
+}
+
+HDRVR WINAPI expOpenDriverA(LPCSTR szDriverName, LPCSTR szSectionName,
+ LPARAM lParam2)
+{
+ dbgprintf("OpenDriverA(0x%x='%s', 0x%x='%s', 0x%x) => -1\n", szDriverName, szDriverName, szSectionName, szSectionName, lParam2);
+ return -1;
+}
+HDRVR WINAPI expOpenDriver(LPCSTR szDriverName, LPCSTR szSectionName,
+ LPARAM lParam2)
+{
+ dbgprintf("OpenDriver(0x%x='%s', 0x%x='%s', 0x%x) => -1\n", szDriverName, szDriverName, szSectionName, szSectionName, lParam2);
+ return -1;
+}
+
+
+WIN_BOOL WINAPI expGetProcessAffinityMask(
+ HANDLE hProcess,
+ LPDWORD lpProcessAffinityMask,
+ LPDWORD lpSystemAffinityMask
+ )
+{
+ dbgprintf("GetProcessAffinityMask(0x%x, 0x%x, 0x%x) => 1\n",
+ hProcess, lpProcessAffinityMask, lpSystemAffinityMask);
+ if(lpProcessAffinityMask)*lpProcessAffinityMask=1;
+ if(lpSystemAffinityMask)*lpSystemAffinityMask=1;
+ return 1;
+}
+
+int WINAPI expMulDiv(int nNumber, int nNumerator, int nDenominator)
+{
+ static const long long max_int=0x7FFFFFFFLL;
+ static const long long min_int=-0x80000000LL;
+ long long tmp=(long long)nNumber*(long long)nNumerator;
+ if(!nDenominator)return 1;
+ tmp/=nDenominator;
+ if(tmp<min_int) return 1;
+ if(tmp>max_int) return 1;
+ return (int)tmp;
+}
+
+LONG WINAPI explstrcmpiA(const char* str1, const char* str2)
+{
+ LONG result=strcasecmp(str1, str2);
+ dbgprintf("strcmpi(0x%x='%s', 0x%x='%s') => %d\n", str1, str1, str2, str2, result);
+ return result;
+}
+
+LONG WINAPI explstrlenA(const char* str1)
+{
+ LONG result=strlen(str1);
+ dbgprintf("strlen(0x%x='%s') => %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);
+ return result;
+}
+LONG WINAPI explstrcpynA(char* str1, const char* str2,int len)
+{
+ int result;
+ if (strlen(str2)>len)
+ result = (int) strncpy(str1, str2,len);
+ else
+ result = (int) strcpy(str1,str2);
+ dbgprintf("strncpy(0x%x, 0x%x='%s' len %d strlen %d) => %x\n", str1, str2, str2,len, strlen(str2),result);
+ return result;
+}
+LONG WINAPI explstrcatA(char* str1, const char* str2)
+{
+ int result= (int) strcat(str1, str2);
+ dbgprintf("strcat(0x%x, 0x%x='%s') => %d\n", str1, str2, str2, result);
+ return result;
+}
+
-//HDRVR WINAPI expOpenDriverA(LPCSTR szDriverName, LPCSTR szSectionName, LPARAM lParam2);
-//HDRVR WINAPI expOpenDriverW(LPCWSTR szDriverName, LPCWSTR szSectionName, LPARAM lParam2);
-HDRVR WINAPI expOpenDriver(LPCSTR szDriverName, LPCSTR szSectionName, LPARAM lParam2){
- printf("winmm32::OpenDriver() called\n");
- return (HDRVR) NULL;
+LONG WINAPI expInterlockedExchange(long *dest, long l)
+{
+ long retval;
+ retval = *dest;
+ *dest = l;
+ return retval;
}
+void WINAPI expInitCommonControls(void)
+{
+ printf("InitCommonControls called!\n");
+ return;
+}
struct exports
{
@@ -1781,7 +2850,7 @@ struct exports
int id;
void* func;
};
-struct libs
+struct libs
{
char name[64];
int length;
@@ -1808,21 +2877,25 @@ FF(HeapAlloc, -1)
FF(HeapDestroy, -1)
FF(HeapFree, -1)
FF(HeapSize, -1)
+FF(HeapReAlloc,-1)
FF(GetProcessHeap, -1)
FF(VirtualAlloc, -1)
FF(VirtualFree, -1)
-FF(InitializeCriticalSection, -1)
+FF(InitializeCriticalSection, -1)
FF(EnterCriticalSection, -1)
-FF(LeaveCriticalSection, -1)
+FF(LeaveCriticalSection, -1)
FF(DeleteCriticalSection, -1)
FF(TlsAlloc, -1)
FF(TlsFree, -1)
FF(TlsGetValue, -1)
FF(TlsSetValue, -1)
FF(GetCurrentThreadId, -1)
-FF(LocalAlloc, -1)
+FF(GetCurrentProcess, -1)
+FF(LocalAlloc, -1)
+FF(LocalReAlloc,-1)
FF(LocalLock, -1)
FF(GlobalAlloc, -1)
+FF(GlobalReAlloc, -1)
FF(GlobalLock, -1)
FF(MultiByteToWideChar, 427)
FF(WideCharToMultiByte, -1)
@@ -1837,7 +2910,7 @@ FF(GlobalHandle, -1)
FF(GlobalUnlock, -1)
FF(GlobalFree, -1)
FF(LoadResource, -1)
-FF(ReleaseSemaphore, -1)
+FF(ReleaseSemaphore, -1)
FF(FindResourceA, -1)
FF(LockResource, -1)
FF(FreeResource, -1)
@@ -1846,7 +2919,8 @@ FF(CloseHandle, -1)
FF(GetCommandLineA, -1)
FF(GetEnvironmentStringsW, -1)
FF(FreeEnvironmentStringsW, -1)
-FF(GetEnvironmentStrings, -1)
+FF(FreeEnvironmentStringsA, -1)
+FF(GetEnvironmentStrings, -1)
FF(GetStartupInfoA, -1)
FF(GetStdHandle, -1)
FF(GetFileType, -1)
@@ -1863,6 +2937,7 @@ FF(MapViewOfFile, -1)
FF(UnmapViewOfFile, -1)
FF(Sleep, -1)
FF(GetModuleHandleA, -1)
+FF(GetProfileIntA, -1)
FF(GetPrivateProfileIntA, -1)
FF(GetPrivateProfileStringA, -1)
FF(WritePrivateProfileStringA, -1)
@@ -1878,6 +2953,33 @@ FF(GetEnvironmentVariableA, -1)
FF(RtlZeroMemory,-1)
FF(RtlMoveMemory,-1)
FF(RtlFillMemory,-1)
+FF(GetTempPathA,-1)
+FF(FindFirstFileA,-1)
+FF(FindNextFileA,-1)
+FF(FindClose,-1)
+FF(FileTimeToLocalFileTime,-1)
+FF(DeleteFileA,-1)
+FF(ReadFile,-1)
+FF(WriteFile,-1)
+FF(SetFilePointer,-1)
+FF(GetTempFileNameA,-1)
+FF(CreateFileA,-1)
+FF(GetSystemDirectoryA,-1)
+FF(GetWindowsDirectoryA,-1)
+FF(SetErrorMode, -1)
+FF(IsProcessorFeaturePresent, -1)
+FF(GetProcessAffinityMask, -1)
+FF(InterlockedExchange, -1)
+FF(MulDiv, -1)
+FF(lstrcmpiA, -1)
+FF(lstrlenA, -1)
+FF(lstrcpyA, -1)
+FF(lstrcatA, -1)
+FF(lstrcpynA,-1)
+FF(GetProcessVersion,-1)
+FF(GetCurrentThread,-1)
+FF(GetOEMCP,-1)
+FF(GetCPInfo,-1)
};
struct exports exp_msvcrt[]={
@@ -1886,13 +2988,34 @@ FF(_initterm, -1)
FF(free, -1)
{"??3@YAXPAX@Z", -1, expdelete},
{"??2@YAPAXI@Z", -1, expnew},
+{"_adjust_fdiv", -1, (void*)&_adjust_fdiv},
FF(strrchr, -1)
FF(strchr, -1)
+FF(strlen, -1)
+FF(strcpy, -1)
+FF(strcmp, -1)
+FF(strcat, -1)
+FF(isalnum, -1)
+FF(memmove, -1)
+FF(memcmp, -1)
+FF(time, -1)
+FF(_ftol,-1)
+FF(rand, -1)
+FF(log10, -1)
+FF(pow, -1)
+FF(cos, -1)
+FF(srand, -1)
+FF(sprintf,-1)
+FF(sscanf,-1)
+FF(fopen,-1)
+FF(fprintf,-1)
+FF(printf,-1)
};
struct exports exp_winmm[]={
FF(GetDriverModuleHandle, -1)
FF(timeGetTime, -1)
FF(DefDriverProc, -1)
+FF(OpenDriverA, -1)
FF(OpenDriver, -1)
};
struct exports exp_user32[]={
@@ -1904,6 +3027,12 @@ FF(ReleaseDC, -1)
FF(IsRectEmpty, -1)
FF(LoadCursorA,-1)
FF(SetCursor,-1)
+FF(GetCursorPos,-1)
+FF(GetCursorPos,-1)
+FF(RegisterWindowMessageA,-1)
+FF(GetSystemMetrics,-1)
+FF(GetSysColor,-1)
+FF(GetSysColorBrush,-1)
};
struct exports exp_advapi32[]={
FF(RegOpenKeyA, -1)
@@ -1912,6 +3041,7 @@ FF(RegCreateKeyExA, -1)
FF(RegQueryValueExA, -1)
FF(RegSetValueExA, -1)
FF(RegCloseKey, -1)
+FF(RegEnumValueA, -1)
};
struct exports exp_gdi32[]={
FF(CreateCompatibleDC, -1)
@@ -1922,6 +3052,21 @@ FF(GetSystemPaletteEntries, -1)
struct exports exp_version[]={
FF(GetFileVersionInfoSizeA, -1)
};
+struct exports exp_ole32[]={
+FF(CoTaskMemAlloc, -1)
+FF(CoTaskMemFree, -1)
+FF(CoCreateInstance, -1)
+FF(StringFromGUID2, -1)
+};
+struct exports exp_crtdll[]={
+FF(memcpy, -1)
+FF(wcscpy, -1)
+};
+struct exports exp_comctl32[]={
+FF(StringFromGUID2, -1)
+FF(InitCommonControls, 17)
+};
+
#define LL(X) \
{#X".dll", sizeof(exp_##X)/sizeof(struct exports), exp_##X},
@@ -1933,8 +3078,12 @@ LL(user32)
LL(advapi32)
LL(gdi32)
LL(version)
+LL(ole32)
+LL(crtdll)
+LL(comctl32)
};
+
void* LookupExternal(const char* library, int ordinal)
{
char* answ;
@@ -1944,7 +3093,6 @@ void* LookupExternal(const char* library, int ordinal)
printf("ERROR: library=0\n");
return (void*)ext_unknown;
}
- printf("External func %s:%d\n", library, ordinal);
// printf("%x %x\n", &unk_exp1, &unk_exp2);
for(i=0; i<sizeof(libraries)/sizeof(struct libs); i++)
@@ -1955,19 +3103,20 @@ void* LookupExternal(const char* library, int ordinal)
{
if(ordinal!=libraries[i].exps[j].id)
continue;
- printf("Hit: 0x%08X\n", (int) libraries[i].exps[j].func);
+ //printf("Hit: 0x%p\n", libraries[i].exps[j].func);
return libraries[i].exps[j].func;
}
}
+ printf("External func %s:%d\n", library, ordinal);
if(pos>150)return 0;
answ=(char*)extcode+pos*0x64;
memcpy(answ, &unk_exp1, 0x64);
*(int*)(answ+9)=pos;
*(int*)(answ+47)-=((int)answ-(int)&unk_exp1);
sprintf(export_names[pos], "%s:%d", library, ordinal);
- pos++;
+ pos++;
return (void*)answ;
-}
+}
void* LookupExternalByName(const char* library, const char* name)
{
@@ -1984,7 +3133,7 @@ void* LookupExternalByName(const char* library, const char* name)
printf("ERROR: name=0\n");
return (void*)ext_unknown;
}
-// printf("External func %s:%s\n", library, name);
+ //printf("External func %s:%s\n", library, name);
for(i=0; i<sizeof(libraries)/sizeof(struct libs); i++)
{
if(strcasecmp(library, libraries[i].name))
@@ -1996,12 +3145,9 @@ void* LookupExternalByName(const char* library, const char* name)
// printf("Hit: 0x%08X\n", libraries[i].exps[j].func);
return libraries[i].exps[j].func;
}
- }// printf("%x %x\n", &unk_exp1, &unk_exp2);
- //printf("Missing (%d) External func %s:%s\n", pos, library, name);
- if(pos>150){
-// printf("Warning! Too many missing externals!\n");
- return 0;
}
+// printf("%s %s\n", library, name);
+ if(pos>150)return 0;
strcpy(export_names[pos], name);
answ=(char*)extcode+pos*0x64;
memcpy(answ, &unk_exp1, 0x64);
@@ -2016,3 +3162,18 @@ void* LookupExternalByName(const char* library, const char* name)
// return (void*)ext_unknown;
}
+void my_garbagecollection(void)
+{
+#ifdef GARBAGE
+ int unfree = 0, unfreecnt = 0;
+
+ while (last_alloc)
+ {
+ alloc_header* mem = last_alloc + 1;
+ unfree += my_size(mem);
+ unfreecnt++;
+ my_release(mem);
+ }
+ printf("Total Unfree %d bytes cnt %d [%p,%d]\n",unfree, unfreecnt, last_alloc, alccnt);
+#endif
+}
diff --git a/src/libw32dll/wine/win32.h b/src/libw32dll/wine/win32.h
index 2969fac16..4ffe31050 100644
--- a/src/libw32dll/wine/win32.h
+++ b/src/libw32dll/wine/win32.h
@@ -1,15 +1,16 @@
-#ifndef win_win32_h
-#define win_win32_h
+#ifndef loader_win32_h
+#define loader_win32_h
#include <time.h>
#include "windef.h"
#include "winbase.h"
+#include "com.h"
extern void* my_mreq(int size, int to_zero);
extern int my_release(void* memory);
-extern int my_size(char* memory);
-extern int my_garbagecollection(void);
+extern void* my_realloc(void *memory,int size);
+extern void my_garbagecollection(void);
typedef struct {
@@ -30,8 +31,8 @@ extern int WINAPI ext_unknown(void);
extern int WINAPI expIsBadWritePtr(void* ptr, unsigned int count);
extern int WINAPI expIsBadReadPtr(void* ptr, unsigned int count);
extern int WINAPI expDisableThreadLibraryCalls(int module);
-extern void* WINAPI expGetDriverModuleHandle(DRVR* pdrv);
-extern void* WINAPI expGetModuleHandleA(const char* name);
+extern HMODULE WINAPI expGetDriverModuleHandle(DRVR* pdrv);
+extern HMODULE WINAPI expGetModuleHandleA(const char* name);
extern void* WINAPI expCreateThread(void* pSecAttr, long dwStackSize, void* lpStartAddress,
void* lpParameter, long dwFlags, long* dwThreadId);
extern void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset,
@@ -47,6 +48,7 @@ extern HANDLE WINAPI expHeapCreate(long flags, long init_size, long max_size);
extern void* WINAPI expHeapAlloc(HANDLE heap, int flags, int size);
extern long WINAPI expHeapDestroy(void* heap);
extern long WINAPI expHeapFree(int arg1, int arg2, void* ptr);
+extern void* WINAPI expHeapReAlloc(HANDLE heap,int flags,void* lpMem,int size);
extern long WINAPI expHeapSize(int heap, int flags, void* pointer);
extern long WINAPI expGetProcessHeap(void);
extern void* WINAPI expVirtualAlloc(void* v1, long v2, long v3, long v4);
@@ -62,6 +64,7 @@ extern int WINAPI expTlsSetValue(tls_t* index, void* value);
extern void* WINAPI expTlsGetValue(tls_t* index);
extern int WINAPI expTlsFree(tls_t* index);
extern void* WINAPI expLocalAlloc(int flags, int size);
+extern void* WINAPI expLocalReAlloc(int handle,int size,int flags);
extern void* WINAPI expLocalLock(void* z);
extern void* WINAPI expGlobalAlloc(int flags, int size);
extern void* WINAPI expGlobalLock(void* z);
@@ -134,9 +137,7 @@ extern int WINAPI expSizeofResource(int v1, int v2);
extern int WINAPI expGetLastError(void);
extern void WINAPI expSetLastError(int error);
extern long WINAPI exptimeGetTime(void);
-/*
extern int WINAPI expStringFromGUID2(GUID* guid, char* str, int cbMax);
-*/
extern int WINAPI expGetFileVersionInfoSizeA(const char* name, int* lpHandle);
extern int WINAPI expIsBadStringPtrW(const short* string, int nchars);
extern int WINAPI expIsBadStringPtrA(const char* string, int nchars);
@@ -148,6 +149,15 @@ extern int WINAPI expGetDesktopWindow(void);
extern int WINAPI expReleaseDC(int hwnd, int hdc);
extern int WINAPI expLoadCursorA(int handle,LPCSTR name);
extern int WINAPI expSetCursor(void *cursor);
+extern int WINAPI expGetCursorPos(void *cursor);
+extern int WINAPI expRegisterWindowMessageA(char *message);
+extern int WINAPI expGetProcessVersion(int pid);
+extern int WINAPI expGetCurrentThread(void);
+extern int WINAPI expGetOEMCP(void);
+extern int WINAPI expGetCPInfo(int cp,void *info);
+extern int WINAPI expGetSysColor(int pid);
+extern int WINAPI expGetSysColorBrush(int pid);
+extern int WINAPI expGetSystemMetrics(int index);
extern int WINAPI expGetSystemPaletteEntries(int hdc, int iStartIndex, int nEntries, void* lppe);
extern int WINAPI expGetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation);
extern void WINAPI expGetLocalTime(SYSTEMTIME* systime);
@@ -155,10 +165,8 @@ extern int WINAPI expGetSystemTime(SYSTEMTIME* systime);
extern int WINAPI expGetEnvironmentVariableA(const char* name, char* field, int size);
extern void* WINAPI expCoTaskMemAlloc(ULONG cb);
extern void WINAPI expCoTaskMemFree(void* cb);
-/*
extern long WINAPI expCoCreateInstance(GUID* rclsid, struct IUnknown* pUnkOuter,
long dwClsContext, GUID* riid, void** ppv);
-*/
extern int WINAPI expIsRectEmpty(CONST RECT *lprc);
extern unsigned int WINAPI expGetTempPathA(unsigned int len, char* path);
extern HANDLE WINAPI expFindFirstFileA(LPCSTR s, LPWIN32_FIND_DATAA lpfd);
@@ -188,7 +196,11 @@ extern INT WINAPI expMulDiv(int nNumber,int nNumerator,int nDenominator);
extern LONG WINAPI explstrcmpiA(const char* str1, const char* str2);
extern LONG WINAPI explstrlenA(const char* str1);
extern LONG WINAPI explstrcpyA(char* str1, const char* str2);
+extern LONG WINAPI explstrcpynA(char* str1, const char* str2,int len);
+extern LONG WINAPI explstrcatA(char* str1, const char* str2);
extern LONG WINAPI expInterlockedExchange(long *dest, long l);
+void WINAPI expInitCommonControls(void);
+
extern void* CDECL expmalloc(int size);
extern void CDECL expfree(void* mem);
@@ -208,7 +220,21 @@ extern int expmemmove(void* dest, void* src, int n);
extern int expmemcmp(void* dest, void* src, int n);
extern void *expmemcpy(void* dest, void* src, int n) ;
extern time_t exptime(time_t* t);
+extern int exprand(void);
+extern void expsrand(int seed);
+extern int exp_ftol(float f);
+extern int expsprintf(char* str, const char* format, ...);
+extern double explog10(double x);
+extern double expcos(double x);
+extern double exppow(double x, double y);
+extern int expsscanf(const char* str, const char* format, ...);
+extern void* expfopen(const char* path, const char* mode);
+extern int expfprintf(void* stream, const char* format, ...);
+extern int expprintf(const char* format, ...);
+extern void* expwcscpy(WCHAR* dst, const WCHAR* src);
+
extern void* LookupExternal(const char* library, int ordinal);
extern void* LookupExternalByName(const char* library, const char* name);
+
#endif
diff --git a/src/libw32dll/wine/windef.h b/src/libw32dll/wine/windef.h
index 01e5175b3..d6e2c5f31 100644
--- a/src/libw32dll/wine/windef.h
+++ b/src/libw32dll/wine/windef.h
@@ -105,7 +105,7 @@ extern "C" {
/* Calling conventions definitions */
-#if defined(__i386__) && !defined(WINE_TYPEDEFS_ONLY)
+#ifdef __i386__
# if defined(__GNUC__) && ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 7)))
# ifndef _EGCS_
#define __stdcall __attribute__((__stdcall__))
@@ -113,7 +113,7 @@ extern "C" {
# define __RESTORE_ES __asm__ __volatile__("pushl %ds\n\tpopl %es")
# endif
# else
-# error You need gcc >= 2.7 to build Wine on a 386
+// # error You need gcc >= 2.7 to build Wine on a 386
# endif
#else
# define __stdcall
@@ -166,8 +166,8 @@ typedef unsigned short WCHAR;
typedef int WIN_BOOL;
typedef double DATE;
typedef double DOUBLE;
-typedef double LONGLONG;
-typedef double ULONGLONG;
+typedef long long LONGLONG;
+typedef unsigned long long ULONGLONG;
/* FIXME: Wine does not compile with strict on, therefore strict
* handles are presently only usable on machines where sizeof(UINT) ==
diff --git a/src/libw32dll/wine/wineacm.h b/src/libw32dll/wine/wineacm.h
index f215d754d..e7604dc64 100644
--- a/src/libw32dll/wine/wineacm.h
+++ b/src/libw32dll/wine/wineacm.h
@@ -1,8 +1,19 @@
+#ifndef WINEACM_H
+#define WINEACM_H
/* -*- tab-width: 8; c-basic-offset: 4 -*- */
/***********************************************************************
* Wine specific - Win32
*/
+
+
+#include "msacmdrv.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* defined(__cplusplus) */
+
+
typedef struct _WINE_ACMDRIVERID *PWINE_ACMDRIVERID;
typedef struct _WINE_ACMDRIVER *PWINE_ACMDRIVER;
@@ -17,6 +28,7 @@ typedef struct _WINE_ACMDRIVER
HDRVR hDrvr;
DRIVERPROC pfnDriverProc;
PWINE_ACMDRIVER pNextACMDriver;
+ int iUsage;
} WINE_ACMDRIVER;
typedef struct _WINE_ACMSTREAM
@@ -29,8 +41,8 @@ typedef struct _WINE_ACMSTREAM
typedef struct _WINE_ACMDRIVERID
{
- LPSTR pszDriverAlias;
LPSTR pszFileName;
+ WORD wFormatTag;
HINSTANCE hInstModule; /* NULL if global */
DWORD dwProcessID; /* ID of process which installed a local driver */
WIN_BOOL bEnabled;
@@ -43,13 +55,18 @@ typedef struct _WINE_ACMDRIVERID
extern HANDLE MSACM_hHeap;
extern PWINE_ACMDRIVERID MSACM_pFirstACMDriverID;
extern PWINE_ACMDRIVERID MSACM_pLastACMDriverID;
-PWINE_ACMDRIVERID MSACM_RegisterDriver(
- LPSTR pszDriverAlias, LPSTR pszFileName,
- HINSTANCE hinstModule);
-void MSACM_RegisterAllDrivers(void);
+
+PWINE_ACMDRIVERID MSACM_RegisterDriver(const char* pszFileName,
+ WORD wFormatTag,
+ HINSTANCE hinstModule);
PWINE_ACMDRIVERID MSACM_UnregisterDriver(PWINE_ACMDRIVERID p);
void MSACM_UnregisterAllDrivers(void);
PWINE_ACMDRIVERID MSACM_GetDriverID(HACMDRIVERID hDriverID);
PWINE_ACMDRIVER MSACM_GetDriver(HACMDRIVER hDriver);
PWINE_ACMOBJ MSACM_GetObj(HACMOBJ hObj);
+#ifdef __cplusplus
+} /* extern "C" */
+#endif /* defined(__cplusplus) */
+
+#endif /* WINEACM_H */
diff --git a/src/libw32dll/wine/winnt.h b/src/libw32dll/wine/winnt.h
index 107172ef8..03f4a777b 100644
--- a/src/libw32dll/wine/winnt.h
+++ b/src/libw32dll/wine/winnt.h
@@ -224,7 +224,7 @@ typedef CONTEXT86 CONTEXT;
#endif /* __i386__ */
/* Alpha context definitions */
-#ifdef _ALPHA_
+#if defined(_ALPHA_) || defined(__alpha__)
#define CONTEXT_ALPHA 0x00020000