wine/if1632/builtin.c
Alexandre Julliard 54c2711ff6 Release 980329
Sun Mar 29 15:18:57 1998  Uwe Bonnes <elektron.ikp.physik.tu-darmstadt.de>

	* [msdos/int21.c]
	More verbose Trace messages

Sun Mar 29 15:03:30 1998  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [loader/ne_image.c]
	Terminate relocation chains on 0 offset.

Sun Mar 29 02:35:45 1998  James Juran  <jrj120@psu.edu>

	* [windows/caret.c] [windows/class.c] [windows/clipboard.c]
	Fixed more USER32 ordinal numbers in function documentation.

Sat Mar 28 22:40:23 1997  Andreas Mohr <100.30936@germany.net>

	* [controls/desktop.c]
	Return 1 for WM_NCCREATE in DesktopWndProc.

	* [controls/menu.c]
	Fixed crash when destroying a top popup win that was only created
	but not shown.

	* [ole/typelib.c] [if1632/typelib.spec]
	Implemented OABuildVersion.

	* [windows/win.c]
	Finally fixed ugly bug in GetParent32 that affected window placement:
	Didn't return 0 for windows that have neither WS_POPUP nor
	WS_CHILD set. Now it acts exactly like Windows (at least I hope so ;)

Sat Mar 28 02:26:43 1998  Dimitrie O. Paun  <dimi@mail.cs.toronto.edu>

	* [DEVELOPERS-HINTS] [documentation/debug-msgs]
	Updated documentation on debug messages

	* [include/button.h] [controls/button.c] [include/windows.h]
	[include/combo.h] [controls/combo.c] [controls/commctrl.c]
	[controls/icontitle.c] [controls/listbox.c]	[controls/menu.c]
	[controls/scroll.c] [controls/widgets.c] 
	Changed some 16-bit code to 32-bit code. I am positive this will
	not break anything.

	* [controls/uitools.c] 
	Renamed the prefix of some functions from UITOOLS_ to UITOOLS95_
	to reflect the fact that they implement Win95 look. Maybe we will
	have a UITOOLS31_ in the future. Anyhow, the change is completely
	internal to this file.

	* [*/*.c]
	Changed a lot of [f]printf into appropriate debug messages.

Fri Mar 27 19:56:12 1998  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>
	* [documentation/status/]
	Added directdraw and directsound status.

	* [if1632/thunk.c][ole/*.c][win32/kernel32.c]
	Added some documentation.
	Moved FUNC004 to thunk.c since it seems to be a 16->32 thunk
	(calling conventions and the like still unknown).

Fri Mar 27 09:59:32 1998  Morten Eriksen  <mortene@pvv.org>

	* [loader/resource.c][windows/keyboard.c]
	Implemented CopyAcceleratorTable() and CreateAcceleratorTable().
	
	* [include/compobj.h][ole/compobj.c][relay32/ole32.spec]
	Added implementation of StringFromGUID2(). 

Tue Mar 26 23:12:05 1998  Eric Kohl <ekohl@abo.rhein-zeitung.de>

	* [misc/imagelist.c][relay32/comctl32.spec]
	Implemented new debugging interface.
	Added missing functions (some are empty stubs).
	Changed ordinals in comctl32.spec (now dll version 4.72 comatible).

	* [objects/oembitmaps.c][include/windows.h]
	  [include/bitmaps/*]
	Added missing restore bitmaps for Win95 look.
	Added missing Win95 cursors.

Thu Mar 26 10:18:20 1998  Douglas Ridgway  <ridgway@winehq.com>

	* [programs/view/Makefile.in] [programs/view/view.c]
	Fix compilation, Aldus placeable metafile loading.

	* [graphics/metafiledrv/init.c] [relay32/gdi32.spec] 
	  [objects/metafile.c]
	Implemented various 32 bit versions of regular metafile API.

	* [objects/enhmetafile.c]
	Implemented rendering of a couple of dozen records.

Tue Mar 24 20:06:39 1998  Matthew Becker <mbecker@glasscity.net>

	* [memory/*.c]
	Updated documentation for API manpages.

Mon Mar 23 09:09:00 1998  Alex Korobka <alex@pharm.sunysb.edu>

	* [misc/winsock.c]
	Fixed 32-bit DNS lookup.

Mon Mar 23 23:54:47 1998  Luiz Otavio L. Zorzella  <zorzella@nr.conexware.com>

	* [multimedia/init.c]
	New code for the initialization and gathering of information about
	the MIDI devices, for future use.

Thu Mar 19 00:59:29 1998  Jim Peterson <jspeter@nospam.birch.ee.vt.edu>

	* [windows/win.c]
	Eliminated inaccurate setting of cs->hMenu in
	WIN_CreateWindowEx, along with superfluous SetMenu32 call.

Mon Mar 16 17:40:53 1998  Petter Reinholdtsen <pere@td.org.uit.no>

	* [debugger/dbg.y] [debugger/Makefile.in] [Makefile.in]
	Install wine.sym in $(exec_prefix)/lib and make sure the debugger
	finds it.

Sun Mar 15 22:36:35 1998  Michael Veksler <mveksler@tx.technion.ac.il>

	* [dummy.c] [if1632/gdi.spec]
	Fixed stub declaration of GDI_532, so Hebrew-Word2 kind of works.
1998-03-29 19:44:57 +00:00

410 lines
13 KiB
C

/*
* Built-in modules
*
* Copyright 1996 Alexandre Julliard
*/
#include <assert.h>
#include <ctype.h>
#include <string.h>
#include "windows.h"
#include "builtin32.h"
#include "gdi.h"
#include "global.h"
#include "heap.h"
#include "module.h"
#include "miscemu.h"
#include "neexe.h"
#include "stackframe.h"
#include "user.h"
#include "process.h"
#include "debug.h"
/* Built-in modules descriptors */
/* Don't change these structures! (see tools/build.c) */
typedef struct
{
const char *name; /* DLL name */
void *module_start; /* 32-bit address of the module data */
int module_size; /* Size of the module data */
const BYTE *code_start; /* 32-bit address of DLL code */
const BYTE *data_start; /* 32-bit address of DLL data */
} WIN16_DESCRIPTOR;
typedef struct
{
const WIN16_DESCRIPTOR *descr; /* DLL descriptor */
int flags; /* flags (see below) */
} BUILTIN16_DLL;
/* DLL flags */
#define DLL_FLAG_NOT_USED 0x01 /* Use original Windows DLL if possible */
#define DLL_FLAG_ALWAYS_USED 0x02 /* Always use built-in DLL */
/* 16-bit DLLs */
extern const WIN16_DESCRIPTOR COMMDLG_Descriptor;
extern const WIN16_DESCRIPTOR COMPOBJ_Descriptor;
extern const WIN16_DESCRIPTOR DDEML_Descriptor;
extern const WIN16_DESCRIPTOR GDI_Descriptor;
extern const WIN16_DESCRIPTOR KERNEL_Descriptor;
extern const WIN16_DESCRIPTOR KEYBOARD_Descriptor;
extern const WIN16_DESCRIPTOR LZEXPAND_Descriptor;
extern const WIN16_DESCRIPTOR MMSYSTEM_Descriptor;
extern const WIN16_DESCRIPTOR MOUSE_Descriptor;
extern const WIN16_DESCRIPTOR OLE2CONV_Descriptor;
extern const WIN16_DESCRIPTOR OLE2DISP_Descriptor;
extern const WIN16_DESCRIPTOR OLE2NLS_Descriptor;
extern const WIN16_DESCRIPTOR OLE2PROX_Descriptor;
extern const WIN16_DESCRIPTOR OLE2THK_Descriptor;
extern const WIN16_DESCRIPTOR OLE2_Descriptor;
extern const WIN16_DESCRIPTOR OLECLI_Descriptor;
extern const WIN16_DESCRIPTOR OLESVR_Descriptor;
extern const WIN16_DESCRIPTOR SHELL_Descriptor;
extern const WIN16_DESCRIPTOR SOUND_Descriptor;
extern const WIN16_DESCRIPTOR STORAGE_Descriptor;
extern const WIN16_DESCRIPTOR STRESS_Descriptor;
extern const WIN16_DESCRIPTOR SYSTEM_Descriptor;
extern const WIN16_DESCRIPTOR TOOLHELP_Descriptor;
extern const WIN16_DESCRIPTOR TYPELIB_Descriptor;
extern const WIN16_DESCRIPTOR USER_Descriptor;
extern const WIN16_DESCRIPTOR VER_Descriptor;
extern const WIN16_DESCRIPTOR W32SYS_Descriptor;
extern const WIN16_DESCRIPTOR WIN32S16_Descriptor;
extern const WIN16_DESCRIPTOR WIN87EM_Descriptor;
extern const WIN16_DESCRIPTOR WINASPI_Descriptor;
extern const WIN16_DESCRIPTOR WINDEBUG_Descriptor;
extern const WIN16_DESCRIPTOR WING_Descriptor;
extern const WIN16_DESCRIPTOR WINSOCK_Descriptor;
extern const WIN16_DESCRIPTOR WPROCS_Descriptor;
/* Table of all built-in DLLs */
static BUILTIN16_DLL BuiltinDLLs[] =
{
{ &KERNEL_Descriptor, DLL_FLAG_ALWAYS_USED },
{ &USER_Descriptor, DLL_FLAG_ALWAYS_USED },
{ &GDI_Descriptor, DLL_FLAG_ALWAYS_USED },
{ &SYSTEM_Descriptor, DLL_FLAG_ALWAYS_USED },
{ &WPROCS_Descriptor, DLL_FLAG_ALWAYS_USED },
{ &WINDEBUG_Descriptor, DLL_FLAG_ALWAYS_USED },
{ &COMMDLG_Descriptor, DLL_FLAG_NOT_USED },
{ &COMPOBJ_Descriptor, DLL_FLAG_NOT_USED },
{ &DDEML_Descriptor, DLL_FLAG_NOT_USED },
{ &KEYBOARD_Descriptor, 0 },
{ &LZEXPAND_Descriptor, 0 },
{ &MMSYSTEM_Descriptor, 0 },
{ &MOUSE_Descriptor, 0 },
{ &OLE2CONV_Descriptor, DLL_FLAG_NOT_USED },
{ &OLE2DISP_Descriptor, DLL_FLAG_NOT_USED },
{ &OLE2NLS_Descriptor, DLL_FLAG_NOT_USED },
{ &OLE2PROX_Descriptor, DLL_FLAG_NOT_USED },
{ &OLE2THK_Descriptor, DLL_FLAG_NOT_USED },
{ &OLE2_Descriptor, DLL_FLAG_NOT_USED },
{ &OLECLI_Descriptor, DLL_FLAG_NOT_USED },
{ &OLESVR_Descriptor, DLL_FLAG_NOT_USED },
{ &SHELL_Descriptor, 0 },
{ &SOUND_Descriptor, 0 },
{ &STORAGE_Descriptor, DLL_FLAG_NOT_USED },
{ &STRESS_Descriptor, 0 },
{ &TOOLHELP_Descriptor, 0 },
{ &TYPELIB_Descriptor, DLL_FLAG_NOT_USED },
{ &VER_Descriptor, 0 },
{ &W32SYS_Descriptor, 0 },
{ &WIN32S16_Descriptor, 0 },
{ &WIN87EM_Descriptor, DLL_FLAG_NOT_USED },
{ &WINASPI_Descriptor, 0 },
{ &WING_Descriptor, 0 },
{ &WINSOCK_Descriptor, 0 },
/* Last entry */
{ NULL, 0 }
};
/* Ordinal number for interrupt 0 handler in WPROCS.DLL */
#define FIRST_INTERRUPT_ORDINAL 100
/***********************************************************************
* BUILTIN_DoLoadModule16
*
* Load a built-in Win16 module. Helper function for BUILTIN_LoadModule
* and BUILTIN_Init.
*/
static HMODULE16 BUILTIN_DoLoadModule16( const WIN16_DESCRIPTOR *descr )
{
NE_MODULE *pModule;
int minsize;
SEGTABLEENTRY *pSegTable;
HMODULE16 hModule = GLOBAL_CreateBlock( GMEM_MOVEABLE, descr->module_start,
descr->module_size, 0,
FALSE, FALSE, FALSE, NULL );
if (!hModule) return 0;
FarSetOwner( hModule, hModule );
TRACE(module, "Built-in %s: hmodule=%04x\n",
descr->name, hModule );
pModule = (NE_MODULE *)GlobalLock16( hModule );
pModule->self = hModule;
/* Allocate the code segment */
pSegTable = NE_SEG_TABLE( pModule );
pSegTable->selector = GLOBAL_CreateBlock( GMEM_FIXED, descr->code_start,
pSegTable->minsize, hModule,
TRUE, TRUE, FALSE, NULL );
if (!pSegTable->selector) return 0;
pSegTable++;
/* Allocate the data segment */
minsize = pSegTable->minsize ? pSegTable->minsize : 0x10000;
minsize += pModule->heap_size;
if (minsize > 0x10000) minsize = 0x10000;
pSegTable->selector = GLOBAL_Alloc( GMEM_FIXED, minsize,
hModule, FALSE, FALSE, FALSE );
if (!pSegTable->selector) return 0;
if (pSegTable->minsize) memcpy( GlobalLock16( pSegTable->selector ),
descr->data_start, pSegTable->minsize);
if (pModule->heap_size)
LocalInit( pSegTable->selector, pSegTable->minsize, minsize );
MODULE_RegisterModule( pModule );
return hModule;
}
/***********************************************************************
* BUILTIN_Init
*
* Load all built-in modules marked as 'always used'.
*/
BOOL32 BUILTIN_Init(void)
{
BUILTIN16_DLL *dll;
NE_MODULE *pModule;
WORD vector;
HMODULE16 hModule;
fnBUILTIN_LoadModule = BUILTIN_LoadModule;
for (dll = BuiltinDLLs; dll->descr; dll++)
{
if (dll->flags & DLL_FLAG_ALWAYS_USED)
if (!BUILTIN_DoLoadModule16( dll->descr )) return FALSE;
}
/* Set the USER and GDI heap selectors */
pModule = MODULE_GetPtr( GetModuleHandle16( "USER" ));
USER_HeapSel = (NE_SEG_TABLE( pModule ) + pModule->dgroup - 1)->selector;
pModule = MODULE_GetPtr( GetModuleHandle16( "GDI" ));
GDI_HeapSel = (NE_SEG_TABLE( pModule ) + pModule->dgroup - 1)->selector;
/* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
hModule = GetModuleHandle16( "KERNEL" );
MODULE_SetEntryPoint( hModule, 178, GetWinFlags() );
/* Initialize the real-mode selector entry points */
DOSMEM_InitExports( hModule );
/* Set interrupt vectors from entry points in WPROCS.DLL */
hModule = GetModuleHandle16( "WPROCS" );
for (vector = 0; vector < 256; vector++)
{
FARPROC16 proc = MODULE_GetEntryPoint( hModule,
FIRST_INTERRUPT_ORDINAL+vector);
assert(proc);
INT_SetHandler( vector, proc );
}
return TRUE;
}
/***********************************************************************
* BUILTIN_LoadModule
*
* Load a built-in module. If the 'force' parameter is FALSE, we only
* load the module if it has not been disabled via the -dll option.
*/
HMODULE32 BUILTIN_LoadModule( LPCSTR name, BOOL32 force )
{
BUILTIN16_DLL *table;
char dllname[16], *p;
/* Fix the name in case we have a full path and extension */
if ((p = strrchr( name, '\\' ))) name = p + 1;
lstrcpyn32A( dllname, name, sizeof(dllname) );
if ((p = strrchr( dllname, '.' ))) *p = '\0';
for (table = BuiltinDLLs; table->descr; table++)
if (!lstrcmpi32A( table->descr->name, dllname )) break;
if (!table->descr) return BUILTIN32_LoadModule( name, force,
PROCESS_Current() );
if ((table->flags & DLL_FLAG_NOT_USED) && !force) return 0;
return BUILTIN_DoLoadModule16( table->descr );
}
/***********************************************************************
* BUILTIN_GetEntryPoint16
*
* Return the ordinal and name corresponding to a CS:IP address.
* This is used only by relay debugging.
*/
LPCSTR BUILTIN_GetEntryPoint16( WORD cs, WORD ip, WORD *pOrd )
{
static char buffer[80];
WORD ordinal, i, max_offset;
register BYTE *p;
NE_MODULE *pModule;
if (!(pModule = MODULE_GetPtr( FarGetOwner( GlobalHandle16(cs) ))))
return NULL;
/* Search for the ordinal */
p = (BYTE *)pModule + pModule->entry_table;
max_offset = 0;
ordinal = 1;
*pOrd = 0;
while (*p)
{
switch(p[1])
{
case 0: /* unused */
ordinal += *p;
p += 2;
break;
case 1: /* code segment */
i = *p;
p += 2;
while (i-- > 0)
{
p++;
if ((*(WORD *)p <= ip) && (*(WORD *)p >= max_offset))
{
max_offset = *(WORD *)p;
*pOrd = ordinal;
}
p += 2;
ordinal++;
}
break;
case 0xff: /* moveable (should not happen in built-in modules) */
fprintf( stderr, "Built-in module has moveable entry\n" );
ordinal += *p;
p += 2 + *p * 6;
break;
default: /* other segment */
ordinal += *p;
p += 2 + *p * 3;
break;
}
}
/* Search for the name in the resident names table */
/* (built-in modules have no non-resident table) */
p = (BYTE *)pModule + pModule->name_table;
while (*p)
{
p += *p + 1 + sizeof(WORD);
if (*(WORD *)(p + *p + 1) == *pOrd) break;
}
sprintf( buffer, "%.*s.%d: %.*s",
*((BYTE *)pModule + pModule->name_table),
(char *)pModule + pModule->name_table + 1,
*pOrd, *p, (char *)(p + 1) );
return buffer;
}
/**********************************************************************
* BUILTIN_DefaultIntHandler
*
* Default interrupt handler.
*/
void BUILTIN_DefaultIntHandler( CONTEXT *context )
{
WORD ordinal;
STACK16FRAME *frame = CURRENT_STACK16;
BUILTIN_GetEntryPoint16( frame->entry_cs, frame->entry_ip, &ordinal );
INT_BARF( context, ordinal - FIRST_INTERRUPT_ORDINAL );
}
/***********************************************************************
* BUILTIN_ParseDLLOptions
*
* Set runtime DLL usage flags
*/
BOOL32 BUILTIN_ParseDLLOptions( const char *str )
{
BUILTIN16_DLL *dll;
const char *p;
while (*str)
{
while (*str && isspace(*str)) str++;
if (!*str) return TRUE;
if ((*str != '+') && (*str != '-')) return FALSE;
str++;
if (!(p = strchr( str, ',' ))) p = str + strlen(str);
while ((p > str) && isspace(p[-1])) p--;
if (p == str) return FALSE;
for (dll = BuiltinDLLs; dll->descr; dll++)
{
if (!lstrncmpi32A( str, dll->descr->name, (int)(p - str) ))
{
if (dll->descr->name[(int)(p-str)]) /* only partial match */
continue;
if (str[-1] == '-')
{
if (dll->flags & DLL_FLAG_ALWAYS_USED) return FALSE;
dll->flags |= DLL_FLAG_NOT_USED;
}
else dll->flags &= ~DLL_FLAG_NOT_USED;
break;
}
}
if (!dll->descr)
if (!BUILTIN32_EnableDLL( str, (int)(p - str), (str[-1] == '+') ))
return FALSE;
str = p;
while (*str && (isspace(*str) || (*str == ','))) str++;
}
return TRUE;
}
/***********************************************************************
* BUILTIN_PrintDLLs
*
* Print the list of built-in DLLs that can be disabled.
*/
void BUILTIN_PrintDLLs(void)
{
int i;
BUILTIN16_DLL *dll;
fprintf(stderr,"Example: -dll -ole2 Do not use emulated OLE2.DLL\n");
fprintf(stderr,"Available Win16 DLLs:\n");
for (i = 0, dll = BuiltinDLLs; dll->descr; dll++)
{
if (!(dll->flags & DLL_FLAG_ALWAYS_USED))
fprintf( stderr, "%-9s%c", dll->descr->name,
((++i) % 8) ? ' ' : '\n' );
}
fprintf(stderr,"\n");
BUILTIN32_PrintDLLs();
}