Commit 8eb1630c authored by Alexandre Julliard's avatar Alexandre Julliard

Use a memory mapping instead of file I/O to load 16-bit modules.

parent a890293f
......@@ -61,11 +61,12 @@ typedef struct _NE_MODULE
WORD ne_swaparea; /* 3c Min. swap area size */
WORD ne_expver; /* 3e Expected Windows version */
/* From here, these are extra fields not present in normal Windows */
HMODULE module32; /* 40 PE module handle for Win32 modules */
HMODULE16 self; /* 44 Handle for this module */
WORD self_loading_sel; /* 46 Selector used for self-loading apps. */
LPVOID rsrc32_map; /* 48 HRSRC 16->32 map (for 32-bit modules) */
HANDLE fd; /* 4c handle to the binary file */
HMODULE module32; /* PE module handle for Win32 modules */
HMODULE16 self; /* Handle for this module */
WORD self_loading_sel; /* Selector used for self-loading apps. */
LPVOID rsrc32_map; /* HRSRC 16->32 map (for 32-bit modules) */
LPCVOID mapping; /* mapping of the binary file */
SIZE_T mapping_size; /* size of the file mapping */
} NE_MODULE;
typedef struct
......@@ -132,6 +133,14 @@ extern THHOOK *pThhook;
#define NE_MODULE_NAME(pModule) \
(((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName)
#define NE_GET_DATA(pModule,offset,size) \
((const void *)(((offset)+(size) <= pModule->mapping_size) ? \
(const char *)pModule->mapping + (offset) : NULL))
#define NE_READ_DATA(pModule,buffer,offset,size) \
(((offset)+(size) <= pModule->mapping_size) ? \
(memcpy( buffer, (const char *)pModule->mapping + (offset), (size) ), TRUE) : FALSE)
#define CURRENT_STACK16 ((STACK16FRAME*)MapSL((SEGPTR)NtCurrentTeb()->WOW32Reserved))
#define CURRENT_DS (CURRENT_STACK16->ds)
......@@ -158,7 +167,6 @@ extern WORD NE_GetOrdinal( HMODULE16 hModule, const char *name );
extern FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal );
extern FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop );
extern BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset );
extern HANDLE NE_OpenFile( NE_MODULE *pModule );
extern DWORD NE_StartTask(void);
/* ne_segment.c */
......
......@@ -330,53 +330,42 @@ static NE_NAMEINFO *NE_FindResourceFromType( LPBYTE pResTab, NE_TYPEINFO *pTypeI
HGLOBAL16 WINAPI NE_DefResourceHandler( HGLOBAL16 hMemObj, HMODULE16 hModule,
HRSRC16 hRsrc )
{
HANDLE fd;
HGLOBAL16 handle;
WORD sizeShift;
NE_NAMEINFO* pNameInfo;
NE_MODULE* pModule = NE_GetPtr( hModule );
if (pModule && (pModule->ne_flags & NE_FFLAGS_BUILTIN))
{
HGLOBAL16 handle;
WORD sizeShift = *(WORD *)((char *)pModule + pModule->ne_rsrctab);
NE_NAMEINFO* pNameInfo = (NE_NAMEINFO*)((char*)pModule + hRsrc);
if ( hMemObj )
handle = GlobalReAlloc16( hMemObj, pNameInfo->length << sizeShift, 0 );
else
handle = AllocResource16( hModule, hRsrc, 0 );
if (!pModule) return 0;
sizeShift = *(WORD *)((char *)pModule + pModule->ne_rsrctab);
pNameInfo = (NE_NAMEINFO *)((char *)pModule + hRsrc);
if ( hMemObj )
handle = GlobalReAlloc16( hMemObj, pNameInfo->length << sizeShift, 0 );
else
handle = AllocResource16( hModule, hRsrc, 0 );
if ( handle )
if (handle)
{
if (pModule->ne_flags & NE_FFLAGS_BUILTIN)
{
/* NOTE: hRsrcMap points to start of built-in resource data */
memcpy( GlobalLock16( handle ),
(char *)pModule->rsrc32_map + (pNameInfo->offset << sizeShift),
pNameInfo->length << sizeShift );
}
return handle;
}
if (pModule && (fd = NE_OpenFile( pModule )) != INVALID_HANDLE_VALUE)
{
HGLOBAL16 handle;
WORD sizeShift = *(WORD *)((char *)pModule + pModule->ne_rsrctab);
NE_NAMEINFO* pNameInfo = (NE_NAMEINFO*)((char*)pModule + hRsrc);
TRACE("loading, pos=%d, len=%d\n",
(int)pNameInfo->offset << sizeShift,
(int)pNameInfo->length << sizeShift );
if( hMemObj )
handle = GlobalReAlloc16( hMemObj, pNameInfo->length << sizeShift, 0 );
else
handle = AllocResource16( hModule, hRsrc, 0 );
if( handle )
{
DWORD res;
SetFilePointer( fd, (int)pNameInfo->offset << sizeShift, NULL, SEEK_SET );
ReadFile( fd, GlobalLock16( handle ), (int)pNameInfo->length << sizeShift,
&res, NULL );
if (!NE_READ_DATA( pModule, GlobalLock16( handle ),
(int)pNameInfo->offset << sizeShift,
(int)pNameInfo->length << sizeShift ))
{
GlobalFree16( handle );
handle = 0;
}
}
CloseHandle(fd);
return handle;
}
return (HGLOBAL16)0;
return handle;
}
......
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