Tue Jun 7 08:41:27 1994 Bob Amstadt (bob@pooh) * loader/selector.c (FixupFunctionPrologs): New function to fixup loaded DLL function prologs. It replaces the do nothing code with code that loads DS with the appropriate data segment for the DLL. * misc/cursor.c (LoadCursor): Disabled cursor loading from .EXE or .DLL. The code needs to handle the possibility of multiple cursors in a single directory. Also, it should check to see if the cursor is the right size. * objects/font.c (EnumFonts): Checked for lpLogFontList[i] == NULL * objects/gdiobj.c (SetObjectOwner): Removed stub. Replaced with simple return in gdi.spec. This function is not defined for the retail version of Windows. * memory/heap.c (WIN16_LocalHandleDelta): New function. This is really a dummy that imitates the proper return values. * loader/library.c (GetProcAddress): Fixed definition of IS_BUILTIN_DLL() macro. Mon Jun 6 18:15:40 1994 Bob Amstadt (bob@pooh) * miscemu/int21.c (SeekFile): Needed to return current position in DX:AX. * windows/utility.c (windows_wsprintf): Added support for '#' in format, and fixed bug with "ptr" being incremented too many times. * miscemu/int21.c (OpenExistingFile): Add code to handle opening files read-only and write-only. * loader/wine.c: Segment fixups now done in LoadImage instead of _WinMain. This is necessary to support LoadLibrary(). Sun Jun 5 17:34:24 1994 Erik Bos (erik@hacktic.nl) * [loader/*] - fixed: GetModuleHandle() sometimes returned a wrong handle. - don't init dlls when cs == 0 (lzexpand, doesn't seem to have a init function) - LoadLibrary & LoadImage now return error instead of stopping wine. - moved most of NE-functions into one file. - LoadLibrary() uses w_files list instead of its own list. - NE exectables are now fixed-up and initialised when loaded instead of only once before calling InitTask. * [miscemu/int15.c] [miscemu/int31.c] Added. * [loader/selector.c] Stubs added for {Get|Set}SelectorLimit(), {Get|Set}SelectorBase(). * [misc/main.c] Stub added for IsRomModule(). * [miscemu/int21.c] Some cleanup, added heap for returning data. Jun 6, 94 martin2@trgcorp.solucorp.qc.ca (Martin Ayotte) * [tools/build.c] Change MAX_ORDINALS define to higher value, 1299 entries. (MMSYSTEM doesn't have succesive numbers, some are around 1200). * [windows/utility.c] Bug fix in windows_wsprintf(), (twice increments ...). * [windows/winpos.c] Bug fix in SetWindowPos(), redraw was done if flag was set to SWP_NOREDRAW while SWP_SHOWWINDOW). * [misc/message.c] [controls/combo.c] Add an InvalidateRect() in WM_SHOWWINDOW to statisfy the new 'saveunder'. * [windows/win.c] In CreateWindowEx(), do SetMenu() calls after window creation, just before sending to WM_NCCALCSIZE. * [controls/menu.c] In function SetMenu(), now use SetWindowPos() with flags SWP_FRAMECHANGED to readjust menu area. Function MenuBarCalcSize() redone. Sun May 29 11:08:24 1994 David B. Thomas (dt@yenta.abq.nm.us) * [objects/text.c] Fixed problems associated with DT_WORDBREAK flag. String length was not being properly decremented when lines were folded, and wrapping was not performed when DT_NOCLIP and DT_NOPREFIX were both on in addition to DT_WORDBREAK. Windows does wrapping in this case, and now so does wine. Sun Jun 5 19:17:49 1994 Olaf Flebbe (olaf@dragon) * [edit.c] cp1 was uninitialized iff lineno == 0 * FindFile tests for existance of file even if a full filename was supplied. What about unix file names? * [controls/listbox ] wndPtr was uninitialized for LB_SETTOPINDEX * [misc/property.c] Do not free lpProp. Is it really allocated by malloc? {edited by Bob Amstadt: changed free() to GlobalFree()}
326 lines
8.1 KiB
C
326 lines
8.1 KiB
C
static char RCSId[] = "$Id: wine.c,v 1.2 1993/07/04 04:04:21 root Exp root $";
|
|
static char Copyright[] = "Copyright Robert J. Amstadt, 1993";
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "windows.h"
|
|
#include "callback.h"
|
|
#include "wine.h"
|
|
#include "segmem.h"
|
|
#include <setjmp.h>
|
|
#include "dlls.h"
|
|
extern SEGDESC Segments[];
|
|
extern unsigned short IF1632_Saved16_ss;
|
|
extern unsigned long IF1632_Saved16_ebp;
|
|
extern unsigned long IF1632_Saved16_esp;
|
|
extern unsigned short IF1632_Saved32_ss;
|
|
extern unsigned long IF1632_Saved32_ebp;
|
|
extern unsigned long IF1632_Saved32_esp;
|
|
|
|
extern struct segment_descriptor_s *MakeProcThunks;
|
|
|
|
struct thunk_s
|
|
{
|
|
int used;
|
|
unsigned char thunk[10];
|
|
};
|
|
|
|
/**********************************************************************
|
|
* PushOn16
|
|
*/
|
|
static void
|
|
PushOn16(int size, unsigned int value)
|
|
{
|
|
char *p = (char *) (((unsigned int)IF1632_Saved16_ss << 16) +
|
|
(IF1632_Saved16_esp & 0xffff));
|
|
if (size)
|
|
{
|
|
unsigned long *lp = (unsigned long *) p - 1;
|
|
|
|
*lp = value;
|
|
IF1632_Saved16_esp -= 4;
|
|
}
|
|
else
|
|
{
|
|
unsigned short *sp = (unsigned short *) p - 1;
|
|
|
|
*sp = value;
|
|
IF1632_Saved16_esp -= 2;
|
|
}
|
|
}
|
|
|
|
/**********************************************************************
|
|
* FindDataSegmentForCode
|
|
*/
|
|
static unsigned short
|
|
FindDataSegmentForCode(unsigned long csip)
|
|
{
|
|
unsigned int seg_idx;
|
|
|
|
seg_idx = (unsigned short) (csip >> 19);
|
|
return Segments[seg_idx].owner;
|
|
}
|
|
|
|
/**********************************************************************
|
|
* CallBack16
|
|
*/
|
|
int
|
|
CallBack16(void *func, int n_args, ...)
|
|
{
|
|
va_list ap;
|
|
int i;
|
|
int arg_type, arg_value;
|
|
|
|
va_start(ap, n_args);
|
|
|
|
for (i = 0; i < n_args; i++)
|
|
{
|
|
arg_type = va_arg(ap, int);
|
|
arg_value = va_arg(ap, int);
|
|
PushOn16(arg_type, arg_value);
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
return CallTo16((unsigned int) func,
|
|
FindDataSegmentForCode((unsigned long) func));
|
|
}
|
|
|
|
/**********************************************************************
|
|
* CALLBACK_MakeProcInstance
|
|
*/
|
|
void *
|
|
CALLBACK_MakeProcInstance(void *func, int instance)
|
|
{
|
|
int handle;
|
|
void *new_func;
|
|
struct thunk_s *tp;
|
|
int i;
|
|
|
|
tp = (struct thunk_s *) MakeProcThunks->base_addr;
|
|
for (i = 0; i < 0x10000 / sizeof(*tp); i++, tp++)
|
|
if (!tp->used)
|
|
break;
|
|
|
|
if (tp->used)
|
|
return (void *) 0;
|
|
|
|
tp->thunk[0] = 0xb8;
|
|
tp->thunk[1] = (unsigned char) instance;
|
|
tp->thunk[2] = (unsigned char) (instance >> 8);
|
|
tp->thunk[3] = 0x8e;
|
|
tp->thunk[4] = 0xd8;
|
|
tp->thunk[5] = 0xea;
|
|
memcpy(&tp->thunk[6], &func, 4);
|
|
tp->used = 1;
|
|
|
|
return tp->thunk;
|
|
}
|
|
|
|
/**********************************************************************
|
|
* FreeProcInstance (KERNEL.52)
|
|
*/
|
|
void FreeProcInstance(FARPROC func)
|
|
{
|
|
int handle;
|
|
void *new_func;
|
|
struct thunk_s *tp;
|
|
int i;
|
|
|
|
tp = (struct thunk_s *) MakeProcThunks->base_addr;
|
|
for (i = 0; i < 0x10000 / sizeof(*tp); i++, tp++)
|
|
{
|
|
if ((void *) tp->thunk == (void *) func)
|
|
{
|
|
tp->used = 0;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**********************************************************************
|
|
* CallWindowProc (USER.122)
|
|
*/
|
|
LONG CallWindowProc( FARPROC func, HWND hwnd, WORD message,
|
|
WORD wParam, LONG lParam )
|
|
{
|
|
SpyMessage(hwnd, message, wParam, lParam);
|
|
|
|
if (HIWORD((LONG)func) == WINE_CODE_SELECTOR)
|
|
{
|
|
static struct dll_table_entry_s *user_tab = NULL;
|
|
void *address = (void *) ((LONG) func & 0xffff);
|
|
|
|
if (user_tab == NULL)
|
|
user_tab = FindDLLTable("USER");
|
|
|
|
/* DefWindowProc */
|
|
if (user_tab[107].address == address)
|
|
return DefWindowProc(hwnd, message, wParam, lParam);
|
|
|
|
/* DefDlgProc */
|
|
else if (user_tab[308].address == address)
|
|
return DefDlgProc(hwnd, message, wParam, lParam);
|
|
|
|
/* DefMDIChildProc */
|
|
else if (user_tab[447].address == address)
|
|
return DefMDIChildProc(hwnd, message, wParam, lParam);
|
|
|
|
/* default */
|
|
else
|
|
{
|
|
fprintf(stderr, "wine: Unknown wine callback %08x\n", func);
|
|
exit(1);
|
|
}
|
|
}
|
|
else if (Is16bitAddress(func))
|
|
{
|
|
#ifdef DEBUG_CALLBACK
|
|
printf("CallWindowProc // 16bit func=%08X !\n", func);
|
|
#endif
|
|
PushOn16( CALLBACK_SIZE_WORD, hwnd );
|
|
PushOn16( CALLBACK_SIZE_WORD, message );
|
|
PushOn16( CALLBACK_SIZE_WORD, wParam );
|
|
PushOn16( CALLBACK_SIZE_LONG, lParam );
|
|
return CallTo16((unsigned int) func,
|
|
FindDataSegmentForCode((unsigned long) func));
|
|
}
|
|
else
|
|
{
|
|
#ifdef DEBUG_CALLBACK
|
|
printf("CallWindowProc // 32bit func=%08X !\n", func);
|
|
#endif
|
|
return (*func)(hwnd, message, wParam, lParam);
|
|
}
|
|
}
|
|
|
|
/**********************************************************************
|
|
* CallLineDDAProc
|
|
*/
|
|
void CallLineDDAProc(FARPROC func, short xPos, short yPos, long lParam)
|
|
{
|
|
if (Is16bitAddress(func))
|
|
{
|
|
PushOn16( CALLBACK_SIZE_WORD, xPos );
|
|
PushOn16( CALLBACK_SIZE_WORD, yPos );
|
|
PushOn16( CALLBACK_SIZE_LONG, lParam );
|
|
CallTo16((unsigned int) func,
|
|
FindDataSegmentForCode((unsigned long) func));
|
|
}
|
|
else
|
|
{
|
|
(*func)(xPos, yPos, lParam);
|
|
}
|
|
}
|
|
|
|
/**********************************************************************
|
|
* CallHookProc
|
|
*/
|
|
DWORD CallHookProc( HOOKPROC func, short code, WPARAM wParam, LPARAM lParam )
|
|
{
|
|
if (Is16bitAddress(func))
|
|
{
|
|
PushOn16( CALLBACK_SIZE_WORD, code );
|
|
PushOn16( CALLBACK_SIZE_WORD, wParam );
|
|
PushOn16( CALLBACK_SIZE_LONG, lParam );
|
|
return CallTo16((unsigned int) func,
|
|
FindDataSegmentForCode((unsigned long) func));
|
|
}
|
|
else
|
|
{
|
|
return (*func)( code, wParam, lParam );
|
|
}
|
|
}
|
|
|
|
/**********************************************************************
|
|
* CallGrayStringProc
|
|
*/
|
|
BOOL CallGrayStringProc(FARPROC func, HDC hdc, LPARAM lParam, INT cch )
|
|
{
|
|
if (Is16bitAddress(func))
|
|
{
|
|
PushOn16( CALLBACK_SIZE_WORD, hdc );
|
|
PushOn16( CALLBACK_SIZE_LONG, lParam );
|
|
PushOn16( CALLBACK_SIZE_WORD, cch );
|
|
return CallTo16((unsigned int) func,
|
|
FindDataSegmentForCode((unsigned long) func));
|
|
}
|
|
else
|
|
{
|
|
return (*func)( hdc, lParam, cch );
|
|
}
|
|
}
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
/*
|
|
* The following functions realize the Catch/Throw functionality.
|
|
* My thought is to use the setjmp, longjmp combination to do the
|
|
* major part of this one. All I have to remember, in addition to
|
|
* whatever the jmp_buf contains, is the contents of the 16-bit
|
|
* sp, bp and ss. I do this by storing them in the structure passed
|
|
* to me by the 16-bit program (including my own jmp_buf...).
|
|
* Hopefully there isn't any program that modifies the contents!
|
|
* Bad thing: I have to save part of the stack, since this will
|
|
* get reused on the next call after my return, leaving it in an
|
|
* undefined state.
|
|
*/
|
|
#define STACK_DEPTH_16 28
|
|
|
|
struct special_buffer {
|
|
jmp_buf buffer;
|
|
long regs [6];
|
|
char stack_part [STACK_DEPTH_16];
|
|
} *sb;
|
|
|
|
int Catch (LPCATCHBUF cbuf)
|
|
{
|
|
WORD retval;
|
|
jmp_buf *tmp_jmp;
|
|
char *stack16 = (char *) (((unsigned int)IF1632_Saved16_ss << 16) +
|
|
(IF1632_Saved16_esp & 0xffff));
|
|
|
|
sb = malloc (sizeof (struct special_buffer));
|
|
|
|
sb -> regs [0] = IF1632_Saved16_esp;
|
|
sb -> regs [1] = IF1632_Saved16_ebp;
|
|
sb -> regs [2] = IF1632_Saved16_ss & 0xffff;
|
|
sb -> regs [3] = IF1632_Saved32_esp;
|
|
sb -> regs [4] = IF1632_Saved32_ebp;
|
|
sb -> regs [5] = IF1632_Saved32_ss & 0xffff;
|
|
memcpy (sb -> stack_part, stack16, STACK_DEPTH_16);
|
|
tmp_jmp = &sb -> buffer;
|
|
*((struct special_buffer **)cbuf) = sb;
|
|
|
|
if ((retval = setjmp (*tmp_jmp)))
|
|
{
|
|
IF1632_Saved16_esp = sb -> regs [0];
|
|
IF1632_Saved16_ebp = sb -> regs [1];
|
|
IF1632_Saved16_ss = sb -> regs [2] & 0xffff;
|
|
IF1632_Saved32_esp = sb -> regs [3];
|
|
IF1632_Saved32_ebp = sb -> regs [4];
|
|
IF1632_Saved32_ss = sb -> regs [5] & 0xffff;
|
|
stack16 = (char *) (((unsigned int)IF1632_Saved16_ss << 16) +
|
|
(IF1632_Saved16_esp & 0xffff));
|
|
|
|
memcpy (stack16, sb -> stack_part, STACK_DEPTH_16);
|
|
#ifdef DEBUG_CATCH
|
|
printf ("Been thrown here: %d, retval = %d\n", sb, retval);
|
|
#endif
|
|
free ((void *) sb);
|
|
return (retval);
|
|
} else {
|
|
#ifdef DEBUG_CATCH
|
|
printf ("Will somtime get thrown here: %d\n", sb);
|
|
#endif
|
|
return (retval);
|
|
}
|
|
}
|
|
|
|
void Throw (LPCATCHBUF cbuf, int val)
|
|
{
|
|
sb = *((struct special_buffer **)cbuf);
|
|
#ifdef DEBUG_CATCH
|
|
printf ("Throwing to: %d\n", sb);
|
|
#endif
|
|
longjmp (sb -> buffer, val);
|
|
}
|