Commit 7df1fbb3 authored by Ulrich Weigand's avatar Ulrich Weigand Committed by Alexandre Julliard

Run Winelib applications as 32-bit processes in the initial task.

Simplified/removed several special 'if (__winelib)' cases in Wine main code obsoleted by that change.
parent 718cbaea
......@@ -72,6 +72,7 @@ typedef struct {
ELF_STDCALL_STUB *stubs;
} ELF_MODREF;
extern struct _wine_modref *ELF_CreateDummyModule(LPCSTR,LPCSTR,struct _PDB32 *);
extern HMODULE32 ELF_LoadLibraryEx32A(LPCSTR,struct _PDB32*,HFILE32,DWORD);
extern FARPROC32 ELF_FindExportedFunction(struct _PDB32 *process,struct _wine_modref *wm, LPCSTR funcName);
......
......@@ -5,8 +5,9 @@
#include "xmalloc.h"
extern int PASCAL WinMain(HINSTANCE32,HINSTANCE32,LPSTR,int);
extern BOOL32 MAIN_WinelibInit( int *argc, char *argv[] );
extern void TASK_Reschedule(void);
/* external declaration here because we don't want to depend on Wine headers */
extern HINSTANCE32 MAIN_WinelibInit( int *argc, char *argv[] );
/* Most Windows C/C++ compilers use something like this to */
/* access argc and argv globally: */
......@@ -21,7 +22,7 @@ int main( int argc, char *argv [] )
_ARGC = argc;
_ARGV = (char **)argv;
if (!MAIN_WinelibInit( &argc, argv )) return 0;
if (!(hInstance = MAIN_WinelibInit( &argc, argv ))) return 0;
/* Alloc szCmdParam */
for (i = 1; i < argc; i++) len += strlen(argv[i]) + 1;
......@@ -31,10 +32,6 @@ int main( int argc, char *argv [] )
else lpszCmdParam[0] = '\0';
for (i = 2; i < argc; i++) strcat(strcat(lpszCmdParam, " "), argv[i]);
hInstance = WinExec32( *argv, SW_SHOWNORMAL );
TASK_Reschedule();
InitApp( hInstance );
return WinMain (hInstance, /* hInstance */
0, /* hPrevInstance */
lpszCmdParam, /* lpszCmdParam */
......
......@@ -25,67 +25,24 @@
#include "module.h"
#include "debug.h"
#if defined(HAVE_LIBDL) && defined(HAVE_DLFCN_H)
#define UNIX_DLL_ENDING "so"
#define STUBSIZE 4095
#include <dlfcn.h>
HMODULE32
ELF_LoadLibraryEx32A(LPCSTR libname,PDB32 *process,HANDLE32 hf,DWORD flags) {
WINE_MODREF *wm;
char *modname,*s,*t,*x;
LPVOID *dlhandle;
WINE_MODREF *
ELF_CreateDummyModule( LPCSTR libname, LPCSTR modname, PDB32 *process )
{
PIMAGE_DOS_HEADER dh;
PIMAGE_NT_HEADERS nth;
PIMAGE_SECTION_HEADER sh;
HMODULE32 hmod;
t = HeapAlloc(process->heap,HEAP_ZERO_MEMORY,strlen(libname)+strlen("lib.so")+1);
*t = '\0';
/* copy path to tempvar ... */
s=strrchr(libname,'/');
if (!s)
s=strrchr(libname,'\\');
if (s) {
strncpy(t,libname,s-libname+1);
t[s-libname+1]= '\0';
} else
s = (LPSTR)libname;
modname = s;
/* append "lib" foo ".so" */
strcat(t,"lib");
x = t+strlen(t);
strcat(t,s);
s = strchr(x,'.');
while (s) {
if (!strcasecmp(s,".dll")) {
strcpy(s+1,UNIX_DLL_ENDING);
break;
}
s=strchr(s+1,'.');
}
WINE_MODREF *wm;
HMODULE32 hmod;
/* FIXME: make UNIX filename from DOS fn? */
/* ... and open it */
dlhandle = dlopen(t,RTLD_NOW);
if (!dlhandle) {
HeapFree(process->heap,0,t);
return 0;
}
wm=(WINE_MODREF*)HeapAlloc(process->heap,HEAP_ZERO_MEMORY,sizeof(*wm));
wm->type = MODULE32_ELF;
wm->binfmt.elf.dlhandle = dlhandle;
/* FIXME: hmm, order? */
wm->next = process->modref_list;
process->modref_list = wm;
wm->modname = HEAP_strdupA(process->heap,0,modname);
wm->longname = HEAP_strdupA(process->heap,0,t);
wm->longname = HEAP_strdupA(process->heap,0,libname);
hmod = (HMODULE32)HeapAlloc(process->heap,HEAP_ZERO_MEMORY,sizeof(IMAGE_DOS_HEADER)+sizeof(IMAGE_NT_HEADERS)+sizeof(IMAGE_SECTION_HEADER)+100);
dh = (PIMAGE_DOS_HEADER)hmod;
......@@ -125,8 +82,63 @@ ELF_LoadLibraryEx32A(LPCSTR libname,PDB32 *process,HANDLE32 hf,DWORD flags) {
sh->PointerToRawData = 0;
sh->Characteristics = IMAGE_SCN_CNT_CODE|IMAGE_SCN_CNT_INITIALIZED_DATA|IMAGE_SCN_MEM_EXECUTE|IMAGE_SCN_MEM_READ;
wm->module = hmod;
SNOOP_RegisterDLL(hmod,libname,STUBSIZE/sizeof(ELF_STDCALL_STUB));
return hmod;
return wm;
}
#if defined(HAVE_LIBDL) && defined(HAVE_DLFCN_H)
#define UNIX_DLL_ENDING "so"
#define STUBSIZE 4095
#include <dlfcn.h>
HMODULE32
ELF_LoadLibraryEx32A(LPCSTR libname,PDB32 *process,HANDLE32 hf,DWORD flags) {
WINE_MODREF *wm;
char *modname,*s,*t,*x;
LPVOID *dlhandle;
t = HeapAlloc(process->heap,HEAP_ZERO_MEMORY,strlen(libname)+strlen("lib.so")+1);
*t = '\0';
/* copy path to tempvar ... */
s=strrchr(libname,'/');
if (!s)
s=strrchr(libname,'\\');
if (s) {
strncpy(t,libname,s-libname+1);
t[s-libname+1]= '\0';
} else
s = (LPSTR)libname;
modname = s;
/* append "lib" foo ".so" */
strcat(t,"lib");
x = t+strlen(t);
strcat(t,s);
s = strchr(x,'.');
while (s) {
if (!strcasecmp(s,".dll")) {
strcpy(s+1,UNIX_DLL_ENDING);
break;
}
s=strchr(s+1,'.');
}
/* FIXME: make UNIX filename from DOS fn? */
/* ... and open it */
dlhandle = dlopen(t,RTLD_NOW);
if (!dlhandle) {
HeapFree(process->heap,0,t);
return 0;
}
wm = ELF_CreateDummyModule( t, modname, process );
wm->binfmt.elf.dlhandle = dlhandle;
SNOOP_RegisterDLL(wm->module,libname,STUBSIZE/sizeof(ELF_STDCALL_STUB));
return wm->module;
}
FARPROC32
......
......@@ -407,29 +407,19 @@ static HINSTANCE16 NE_CreateProcess( LPCSTR name, LPCSTR cmd_line, LPCSTR env,
LPSTARTUPINFO32A startup,
LPPROCESS_INFORMATION info )
{
HMODULE16 hModule;
HINSTANCE16 hInstance, hPrevInstance;
NE_MODULE *pModule;
if (__winelib)
{
OFSTRUCT ofs;
lstrcpyn32A( ofs.szPathName, name, sizeof(ofs.szPathName) );
if ((hModule = MODULE_CreateDummyModule( &ofs )) < 32) return hModule;
pModule = (NE_MODULE *)GlobalLock16( hModule );
hInstance = NE_CreateInstance( pModule, &hPrevInstance, FALSE );
}
else
{
hInstance = NE_LoadModule( name, &hPrevInstance, TRUE, FALSE );
if (hInstance < 32) return hInstance;
/* Load module */
if ( !(pModule = NE_GetPtr(hInstance))
|| (pModule->flags & NE_FFLAGS_LIBMODULE))
{
/* FIXME: cleanup */
return 11;
}
hInstance = NE_LoadModule( name, &hPrevInstance, TRUE, FALSE );
if (hInstance < 32) return hInstance;
if ( !(pModule = NE_GetPtr(hInstance))
|| (pModule->flags & NE_FFLAGS_LIBMODULE))
{
/* FIXME: cleanup */
return 11;
}
/* Create a task for this instance */
......@@ -534,8 +524,13 @@ HINSTANCE32 WINAPI LoadModule32( LPCSTR name, LPVOID paramBlock )
/* Get hInstance from process */
pdb = PROCESS_IdToPDB( info.dwProcessId );
tdb = pdb? (TDB *)GlobalLock16( pdb->task ) : NULL;
hInstance = tdb? tdb->hInstance : 0;
if ( pdb->exe_modref )
hInstance = pdb->exe_modref->module;
else
{
tdb = pdb? (TDB *)GlobalLock16( pdb->task ) : NULL;
hInstance = tdb? tdb->hInstance : 0;
}
/* Close off the handles */
CloseHandle( info.hThread );
......@@ -676,7 +671,7 @@ BOOL32 WINAPI CreateProcess32A( LPCSTR lpApplicationName, LPSTR lpCommandLine,
FIXME(module, "(%s,...): STARTF_USEHOTKEY ignored\n", name);
/* Try NE (or winelib) module */
/* Try NE module */
hInstance = NE_CreateProcess( name, cmdline, lpEnvironment,
lpStartupInfo, lpProcessInfo );
......@@ -902,7 +897,6 @@ HINSTANCE32 WINAPI WinExec32( LPCSTR lpCmdLine, UINT32 nCmdShow )
{
HINSTANCE32 handle = 2;
char *p, filename[256];
static int use_load_module = 1;
int spacelimit = 0, exhausted = 0;
LOADPARAMS32 params;
UINT16 paramCmdShow[2];
......@@ -954,10 +948,8 @@ HINSTANCE32 WINAPI WinExec32( LPCSTR lpCmdLine, UINT32 nCmdShow )
/* Now load the executable file */
if (use_load_module)
if (!__winelib)
{
/* Winelib: Use LoadModule() only for the program itself */
if (__winelib) use_load_module = 0;
handle = LoadModule32( filename, &params );
if (handle == 2) /* file not found */
{
......
......@@ -66,7 +66,7 @@ HANDLE32 WINAPI FindResourceEx32A( HMODULE32 hModule, LPCSTR type, LPCSTR name,
*/
HRSRC32 WINAPI FindResourceEx32W( HMODULE32 hModule, LPCWSTR type,
LPCWSTR name, WORD lang )
{ HRSRC32 ret;
{
WINE_MODREF *wm = MODULE32_LookupHMODULE(PROCESS_Current(),hModule);
HRSRC32 hrsrc;
......@@ -75,24 +75,27 @@ HRSRC32 WINAPI FindResourceEx32W( HMODULE32 hModule, LPCWSTR type,
debugres_w (type),
debugres_w (name));
if (__winelib) {
hrsrc = LIBRES_FindResource( hModule, name, type );
if (hrsrc)
return hrsrc;
}
if (wm) {
switch (wm->type) {
case MODULE32_PE:
ret = PE_FindResourceEx32W(wm,name,type,lang);
if ( ret==0 )
ERR(resource,"0x%08x(%s) %s(%s) not found!\n", hModule,wm->modname, debugres_w (name), debugres_w (type));
return ret;
default:
ERR(module,"unknown module type %d\n",wm->type);
break;
}
if (!wm) return (HRSRC32)0;
switch (wm->type)
{
case MODULE32_PE:
hrsrc = PE_FindResourceEx32W(wm,name,type,lang);
break;
case MODULE32_ELF:
hrsrc = LIBRES_FindResource( hModule, name, type );
break;
default:
ERR(module,"unknown module type %d\n",wm->type);
return (HRSRC32)0;
}
return (HRSRC32)0;
if ( !hrsrc )
ERR(resource,"0x%08x(%s) %s(%s) not found!\n", hModule,wm->modname, debugres_w (name), debugres_w (type));
return hrsrc;
}
......@@ -124,16 +127,20 @@ HGLOBAL32 WINAPI LoadResource32(
ERR(resource,"hRsrc is 0, return 0.\n");
return 0;
}
if (wm)
switch (wm->type) {
case MODULE32_PE:
return PE_LoadResource32(wm,hRsrc);
default:
ERR(resource,"unknown module type %d\n",wm->type);
break;
}
if (__winelib)
return LIBRES_LoadResource( hModule, hRsrc );
if (!wm) return 0;
switch (wm->type)
{
case MODULE32_PE:
return PE_LoadResource32(wm,hRsrc);
case MODULE32_ELF:
return LIBRES_LoadResource( hModule, hRsrc );
default:
ERR(resource,"unknown module type %d\n",wm->type);
break;
}
return 0;
}
......@@ -175,23 +182,21 @@ DWORD WINAPI SizeofResource32( HINSTANCE32 hModule, HRSRC32 hRsrc )
WINE_MODREF *wm = MODULE32_LookupHMODULE(PROCESS_Current(),hModule);
TRACE(resource, "module=%08x res=%08x\n", hModule, hRsrc );
if (wm)
switch (wm->type)
{
case MODULE32_PE:
{
DWORD ret;
ret = PE_SizeofResource32(hModule,hRsrc);
if (ret)
return ret;
break;
}
default:
ERR(module,"unknown module type %d\n",wm->type);
break;
}
if (__winelib)
FIXME(module,"Not implemented for WINELIB\n");
if (!wm) return 0;
switch (wm->type)
{
case MODULE32_PE:
return PE_SizeofResource32(hModule,hRsrc);
case MODULE32_ELF:
FIXME(module,"Not implemented for ELF modules\n");
break;
default:
ERR(module,"unknown module type %d\n",wm->type);
break;
}
return 0;
}
......
......@@ -9,6 +9,7 @@
#include "windows.h"
#include "callback.h"
#include "task.h"
#include "syslevel.h"
/**********************************************************************
......@@ -232,6 +233,17 @@ static BOOL32 WINAPI CALLBACK_CallWOWCallback16Ex(
}
/**********************************************************************
* CALLBACK_CallTaskRescheduleProc
*/
static void WINAPI CALLBACK_CallTaskRescheduleProc( void )
{
SYSLEVEL_EnterWin16Lock();
TASK_Reschedule();
SYSLEVEL_LeaveWin16Lock();
}
/**********************************************************************
* CALLBACK_WinelibTable
*
* The callbacks function table for Winelib
......@@ -240,7 +252,7 @@ static const CALLBACKS_TABLE CALLBACK_WinelibTable =
{
CALLBACK_CallRegisterProc, /* CallRegisterShortProc */
CALLBACK_CallRegisterProc, /* CallRegisterLongProc */
TASK_Reschedule, /* CallTaskRescheduleProc */
CALLBACK_CallTaskRescheduleProc, /* CallTaskRescheduleProc */
NULL, /* CallFrom16WndProc */
CALLBACK_CallWndProc, /* CallWndProc */
CALLBACK_CallDriverProc, /* CallDriverProc */
......
......@@ -665,11 +665,9 @@ static HWND32 WIN_CreateWindowEx( CREATESTRUCT32A *cs, ATOM classAtom,
SEGPTR menuName = (SEGPTR)GetClassLong16( hwnd, GCL_MENUNAME );
if (menuName)
{
/* hInstance is still 16-bit in 980215 winelib */
if (HIWORD(cs->hInstance) || __winelib)
if (HIWORD(cs->hInstance))
cs->hMenu = LoadMenu32A(cs->hInstance,PTR_SEG_TO_LIN(menuName));
else
/* doesn't work for winelib, since resources are unicode */
cs->hMenu = LoadMenu16(cs->hInstance,menuName);
if (cs->hMenu) SetMenu32( hwnd, cs->hMenu );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment