From 0ac96900815de348484e7484181102c7e9878c09 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 26 Aug 2003 02:28:59 +0000 Subject: [PATCH] Moved 16-bit relay and snoop support to dlls/kernel. --- dlls/kernel/.cvsignore | 1 + dlls/kernel/Makefile.in | 8 + dlls/kernel/ne_module.c | 207 ++++++++++++++++++++++++ if1632/relay.c => dlls/kernel/relay16.c | 0 if1632/snoop.c => dlls/kernel/snoop16.c | 0 dlls/ntdll/.cvsignore | 1 - dlls/ntdll/Makefile.in | 10 +- loader/ne/module.c | 206 ----------------------- 8 files changed, 217 insertions(+), 216 deletions(-) rename if1632/relay.c => dlls/kernel/relay16.c (100%) rename if1632/snoop.c => dlls/kernel/snoop16.c (100%) diff --git a/dlls/kernel/.cvsignore b/dlls/kernel/.cvsignore index fae603de492..3ac609aebcd 100644 --- a/dlls/kernel/.cvsignore +++ b/dlls/kernel/.cvsignore @@ -5,6 +5,7 @@ kernel32.dll.dbg.c kernel32.spec.c kernel32.spec.def krnl386.exe.spec.c +relay16asm.s stress.spec.c system.drv.spec.c toolhelp.spec.c diff --git a/dlls/kernel/Makefile.in b/dlls/kernel/Makefile.in index f5b0e969076..62356d8072d 100644 --- a/dlls/kernel/Makefile.in +++ b/dlls/kernel/Makefile.in @@ -38,8 +38,10 @@ C_SRCS = \ ne_segment.c \ powermgnt.c \ process.c \ + relay16.c \ resource.c \ resource16.c \ + snoop16.c \ stress.c \ string.c \ sync.c \ @@ -59,6 +61,8 @@ C_SRCS16 = \ registry16.c \ system.c +ASM_SRCS = relay16asm.s + RC_SRCS = kernel.rc RC_SRCS16 = \ @@ -67,6 +71,7 @@ RC_SRCS16 = \ MC_SRCS = \ messages/winerr_enu.mc +EXTRA_OBJS = $(ASM_SRCS:.s=.o) SUBDIRS = tests EXTRASUBDIRS = messages nls @@ -74,6 +79,9 @@ EXTRASUBDIRS = messages nls kernel.res: $(MC_SRCS:.mc=.mc.rc) +relay16asm.s: $(WINEBUILD) + $(WINEBUILD) $(DEFS) -o $@ --relay16 + # Special rules for 16-bit resource and spec files krnl386.exe.spec.c: krnl386.exe.spec version16.res diff --git a/dlls/kernel/ne_module.c b/dlls/kernel/ne_module.c index b83bf648516..00232840ebb 100644 --- a/dlls/kernel/ne_module.c +++ b/dlls/kernel/ne_module.c @@ -210,6 +210,16 @@ void __wine_unregister_dll_16( const BUILTIN16_DESCRIPTOR *descr ) } +/********************************************************************** + * NE_RegisterModule + */ +void NE_RegisterModule( NE_MODULE *pModule ) +{ + pModule->next = hFirstModule; + hFirstModule = pModule->self; +} + + /*********************************************************************** * NE_DumpModule */ @@ -363,6 +373,143 @@ void NE_WalkModules(void) } +/*********************************************************************** + * NE_InitResourceHandler + * + * Fill in 'resloader' fields in the resource table. + */ +void NE_InitResourceHandler( NE_MODULE *pModule ) +{ + static FARPROC16 proc; + + NE_TYPEINFO *pTypeInfo = (NE_TYPEINFO *)((char *)pModule + pModule->res_table + 2); + + TRACE("InitResourceHandler[%04x]\n", pModule->self ); + + if (!proc) proc = GetProcAddress16( GetModuleHandle16("KERNEL"), "DefResourceHandler" ); + + while(pTypeInfo->type_id) + { + memcpy_unaligned( &pTypeInfo->resloader, &proc, sizeof(FARPROC16) ); + pTypeInfo = (NE_TYPEINFO *)((char*)(pTypeInfo + 1) + pTypeInfo->count * sizeof(NE_NAMEINFO)); + } +} + + +/*********************************************************************** + * NE_GetOrdinal + * + * Lookup the ordinal for a given name. + */ +WORD NE_GetOrdinal( HMODULE16 hModule, const char *name ) +{ + unsigned char buffer[256], *cpnt; + BYTE len; + NE_MODULE *pModule; + + if (!(pModule = NE_GetPtr( hModule ))) return 0; + if (pModule->flags & NE_FFLAGS_WIN32) return 0; + + TRACE("(%04x,'%s')\n", hModule, name ); + + /* First handle names of the form '#xxxx' */ + + if (name[0] == '#') return atoi( name + 1 ); + + /* Now copy and uppercase the string */ + + strcpy( buffer, name ); + for (cpnt = buffer; *cpnt; cpnt++) *cpnt = FILE_toupper(*cpnt); + len = cpnt - buffer; + + /* First search the resident names */ + + cpnt = (char *)pModule + pModule->name_table; + + /* Skip the first entry (module name) */ + cpnt += *cpnt + 1 + sizeof(WORD); + while (*cpnt) + { + if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len )) + { + WORD ordinal; + memcpy( &ordinal, cpnt + *cpnt + 1, sizeof(ordinal) ); + TRACE(" Found: ordinal=%d\n", ordinal ); + return ordinal; + } + cpnt += *cpnt + 1 + sizeof(WORD); + } + + /* Now search the non-resident names table */ + + if (!pModule->nrname_handle) return 0; /* No non-resident table */ + cpnt = (char *)GlobalLock16( pModule->nrname_handle ); + + /* Skip the first entry (module description string) */ + cpnt += *cpnt + 1 + sizeof(WORD); + while (*cpnt) + { + if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len )) + { + WORD ordinal; + memcpy( &ordinal, cpnt + *cpnt + 1, sizeof(ordinal) ); + TRACE(" Found: ordinal=%d\n", ordinal ); + return ordinal; + } + cpnt += *cpnt + 1 + sizeof(WORD); + } + return 0; +} + + +/*********************************************************************** + * NE_GetEntryPoint + */ +FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal ) +{ + return NE_GetEntryPointEx( hModule, ordinal, TRUE ); +} + +/*********************************************************************** + * NE_GetEntryPointEx + */ +FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop ) +{ + NE_MODULE *pModule; + WORD sel, offset, i; + + ET_ENTRY *entry; + ET_BUNDLE *bundle; + + if (!(pModule = NE_GetPtr( hModule ))) return 0; + assert( !(pModule->flags & NE_FFLAGS_WIN32) ); + + bundle = (ET_BUNDLE *)((BYTE *)pModule + pModule->entry_table); + while ((ordinal < bundle->first + 1) || (ordinal > bundle->last)) + { + if (!(bundle->next)) + return 0; + bundle = (ET_BUNDLE *)((BYTE *)pModule + bundle->next); + } + + entry = (ET_ENTRY *)((BYTE *)bundle+6); + for (i=0; i < (ordinal - bundle->first - 1); i++) + entry++; + + sel = entry->segnum; + memcpy( &offset, &entry->offs, sizeof(WORD) ); + + if (sel == 0xfe) sel = 0xffff; /* constant entry */ + else sel = GlobalHandleToSel16(NE_SEG_TABLE(pModule)[sel-1].hSeg); + if (sel==0xffff) + return (FARPROC16)MAKESEGPTR( sel, offset ); + if (!snoop) + return (FARPROC16)MAKESEGPTR( sel, offset ); + else + return (FARPROC16)SNOOP16_GetProcAddress16(hModule,ordinal,(FARPROC16)MAKESEGPTR( sel, offset )); +} + + /*********************************************************************** * EntryAddrProc (KERNEL.667) Wine-specific export * @@ -1566,6 +1713,66 @@ HINSTANCE16 WINAPI WinExec16( LPCSTR lpCmdLine, UINT16 nCmdShow ) return ret; } +/*********************************************************************** + * GetProcAddress (KERNEL.50) + */ +FARPROC16 WINAPI GetProcAddress16( HMODULE16 hModule, LPCSTR name ) +{ + WORD ordinal; + FARPROC16 ret; + + if (!hModule) hModule = GetCurrentTask(); + hModule = GetExePtr( hModule ); + + if (HIWORD(name) != 0) + { + ordinal = NE_GetOrdinal( hModule, name ); + TRACE("%04x '%s'\n", hModule, name ); + } + else + { + ordinal = LOWORD(name); + TRACE("%04x %04x\n", hModule, ordinal ); + } + if (!ordinal) return (FARPROC16)0; + + ret = NE_GetEntryPoint( hModule, ordinal ); + + TRACE("returning %08x\n", (UINT)ret ); + return ret; +} + + +/*************************************************************************** + * HasGPHandler (KERNEL.338) + */ +SEGPTR WINAPI HasGPHandler16( SEGPTR address ) +{ + HMODULE16 hModule; + int gpOrdinal; + SEGPTR gpPtr; + GPHANDLERDEF *gpHandler; + + if ( (hModule = FarGetOwner16( SELECTOROF(address) )) != 0 + && (gpOrdinal = NE_GetOrdinal( hModule, "__GP" )) != 0 + && (gpPtr = (SEGPTR)NE_GetEntryPointEx( hModule, gpOrdinal, FALSE )) != 0 + && !IsBadReadPtr16( gpPtr, sizeof(GPHANDLERDEF) ) + && (gpHandler = MapSL( gpPtr )) != NULL ) + { + while (gpHandler->selector) + { + if ( SELECTOROF(address) == gpHandler->selector + && OFFSETOF(address) >= gpHandler->rangeStart + && OFFSETOF(address) < gpHandler->rangeEnd ) + return MAKESEGPTR( gpHandler->selector, gpHandler->handler ); + gpHandler++; + } + } + + return 0; +} + + /********************************************************************** * GetModuleHandle (KERNEL.47) * diff --git a/if1632/relay.c b/dlls/kernel/relay16.c similarity index 100% rename from if1632/relay.c rename to dlls/kernel/relay16.c diff --git a/if1632/snoop.c b/dlls/kernel/snoop16.c similarity index 100% rename from if1632/snoop.c rename to dlls/kernel/snoop16.c diff --git a/dlls/ntdll/.cvsignore b/dlls/ntdll/.cvsignore index 6c69916f8f7..3ed4e1eeca9 100644 --- a/dlls/ntdll/.cvsignore +++ b/dlls/ntdll/.cvsignore @@ -2,5 +2,4 @@ Makefile ntdll.dll.dbg.c ntdll.spec.c ntdll.spec.def -relay16.s relay32.s diff --git a/dlls/ntdll/Makefile.in b/dlls/ntdll/Makefile.in index 6a9bc990c8d..03ab3860f5e 100644 --- a/dlls/ntdll/Makefile.in +++ b/dlls/ntdll/Makefile.in @@ -13,8 +13,6 @@ C_SRCS = \ $(TOPOBJDIR)/files/file.c \ $(TOPOBJDIR)/files/profile.c \ $(TOPOBJDIR)/files/smb.c \ - $(TOPOBJDIR)/if1632/relay.c \ - $(TOPOBJDIR)/if1632/snoop.c \ $(TOPOBJDIR)/loader/loadorder.c \ $(TOPOBJDIR)/loader/module.c \ $(TOPOBJDIR)/loader/pe_image.c \ @@ -83,9 +81,7 @@ C_SRCS = \ virtual.c \ wcstring.c -ASM_SRCS = \ - relay16.s \ - relay32.s +ASM_SRCS = relay32.s EXTRA_OBJS = $(ASM_SRCS:.s=.o) @@ -93,7 +89,6 @@ SUBDIRS = tests EXTRASUBDIRS = \ $(TOPOBJDIR)/files \ - $(TOPOBJDIR)/if1632 \ $(TOPOBJDIR)/loader \ $(TOPOBJDIR)/loader/ne \ $(TOPOBJDIR)/memory \ @@ -105,9 +100,6 @@ EXTRASUBDIRS = \ @MAKE_DLL_RULES@ -relay16.s: $(WINEBUILD) - $(WINEBUILD) $(DEFS) -o $@ --relay16 - relay32.s: $(WINEBUILD) $(WINEBUILD) $(DEFS) -o $@ --relay32 diff --git a/loader/ne/module.c b/loader/ne/module.c index 4713bf41716..6803c12624e 100644 --- a/loader/ne/module.c +++ b/loader/ne/module.c @@ -71,153 +71,6 @@ NE_MODULE *NE_GetPtr( HMODULE16 hModule ) } -/********************************************************************** - * NE_RegisterModule - */ -void NE_RegisterModule( NE_MODULE *pModule ) -{ - pModule->next = hFirstModule; - hFirstModule = pModule->self; -} - - -/*********************************************************************** - * NE_InitResourceHandler - * - * Fill in 'resloader' fields in the resource table. - */ -void NE_InitResourceHandler( NE_MODULE *pModule ) -{ - static FARPROC16 proc; - - NE_TYPEINFO *pTypeInfo = (NE_TYPEINFO *)((char *)pModule + pModule->res_table + 2); - - TRACE("InitResourceHandler[%04x]\n", pModule->self ); - - if (!proc) proc = GetProcAddress16( GetModuleHandle16("KERNEL"), "DefResourceHandler" ); - - while(pTypeInfo->type_id) - { - memcpy_unaligned( &pTypeInfo->resloader, &proc, sizeof(FARPROC16) ); - pTypeInfo = (NE_TYPEINFO *)((char*)(pTypeInfo + 1) + pTypeInfo->count * sizeof(NE_NAMEINFO)); - } -} - - -/*********************************************************************** - * NE_GetOrdinal - * - * Lookup the ordinal for a given name. - */ -WORD NE_GetOrdinal( HMODULE16 hModule, const char *name ) -{ - unsigned char buffer[256], *cpnt; - BYTE len; - NE_MODULE *pModule; - - if (!(pModule = NE_GetPtr( hModule ))) return 0; - if (pModule->flags & NE_FFLAGS_WIN32) return 0; - - TRACE("(%04x,'%s')\n", hModule, name ); - - /* First handle names of the form '#xxxx' */ - - if (name[0] == '#') return atoi( name + 1 ); - - /* Now copy and uppercase the string */ - - strcpy( buffer, name ); - for (cpnt = buffer; *cpnt; cpnt++) *cpnt = FILE_toupper(*cpnt); - len = cpnt - buffer; - - /* First search the resident names */ - - cpnt = (char *)pModule + pModule->name_table; - - /* Skip the first entry (module name) */ - cpnt += *cpnt + 1 + sizeof(WORD); - while (*cpnt) - { - if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len )) - { - WORD ordinal; - memcpy( &ordinal, cpnt + *cpnt + 1, sizeof(ordinal) ); - TRACE(" Found: ordinal=%d\n", ordinal ); - return ordinal; - } - cpnt += *cpnt + 1 + sizeof(WORD); - } - - /* Now search the non-resident names table */ - - if (!pModule->nrname_handle) return 0; /* No non-resident table */ - cpnt = (char *)GlobalLock16( pModule->nrname_handle ); - - /* Skip the first entry (module description string) */ - cpnt += *cpnt + 1 + sizeof(WORD); - while (*cpnt) - { - if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len )) - { - WORD ordinal; - memcpy( &ordinal, cpnt + *cpnt + 1, sizeof(ordinal) ); - TRACE(" Found: ordinal=%d\n", ordinal ); - return ordinal; - } - cpnt += *cpnt + 1 + sizeof(WORD); - } - return 0; -} - - -/*********************************************************************** - * NE_GetEntryPoint - */ -FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal ) -{ - return NE_GetEntryPointEx( hModule, ordinal, TRUE ); -} - -/*********************************************************************** - * NE_GetEntryPointEx - */ -FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop ) -{ - NE_MODULE *pModule; - WORD sel, offset, i; - - ET_ENTRY *entry; - ET_BUNDLE *bundle; - - if (!(pModule = NE_GetPtr( hModule ))) return 0; - assert( !(pModule->flags & NE_FFLAGS_WIN32) ); - - bundle = (ET_BUNDLE *)((BYTE *)pModule + pModule->entry_table); - while ((ordinal < bundle->first + 1) || (ordinal > bundle->last)) - { - if (!(bundle->next)) - return 0; - bundle = (ET_BUNDLE *)((BYTE *)pModule + bundle->next); - } - - entry = (ET_ENTRY *)((BYTE *)bundle+6); - for (i=0; i < (ordinal - bundle->first - 1); i++) - entry++; - - sel = entry->segnum; - memcpy( &offset, &entry->offs, sizeof(WORD) ); - - if (sel == 0xfe) sel = 0xffff; /* constant entry */ - else sel = GlobalHandleToSel16(NE_SEG_TABLE(pModule)[sel-1].hSeg); - if (sel==0xffff) - return (FARPROC16)MAKESEGPTR( sel, offset ); - if (!snoop) - return (FARPROC16)MAKESEGPTR( sel, offset ); - else - return (FARPROC16)SNOOP16_GetProcAddress16(hModule,ordinal,(FARPROC16)MAKESEGPTR( sel, offset )); -} - - /********************************************************************** * GetModuleFileName (KERNEL.49) * @@ -342,62 +195,3 @@ HMODULE16 WINAPI GetModuleHandle16( LPCSTR name ) } return 0; } - -/*********************************************************************** - * GetProcAddress (KERNEL.50) - */ -FARPROC16 WINAPI GetProcAddress16( HMODULE16 hModule, LPCSTR name ) -{ - WORD ordinal; - FARPROC16 ret; - - if (!hModule) hModule = GetCurrentTask(); - hModule = GetExePtr( hModule ); - - if (HIWORD(name) != 0) - { - ordinal = NE_GetOrdinal( hModule, name ); - TRACE("%04x '%s'\n", hModule, name ); - } - else - { - ordinal = LOWORD(name); - TRACE("%04x %04x\n", hModule, ordinal ); - } - if (!ordinal) return (FARPROC16)0; - - ret = NE_GetEntryPoint( hModule, ordinal ); - - TRACE("returning %08x\n", (UINT)ret ); - return ret; -} - - -/*************************************************************************** - * HasGPHandler (KERNEL.338) - */ -SEGPTR WINAPI HasGPHandler16( SEGPTR address ) -{ - HMODULE16 hModule; - int gpOrdinal; - SEGPTR gpPtr; - GPHANDLERDEF *gpHandler; - - if ( (hModule = FarGetOwner16( SELECTOROF(address) )) != 0 - && (gpOrdinal = NE_GetOrdinal( hModule, "__GP" )) != 0 - && (gpPtr = (SEGPTR)NE_GetEntryPointEx( hModule, gpOrdinal, FALSE )) != 0 - && !IsBadReadPtr16( gpPtr, sizeof(GPHANDLERDEF) ) - && (gpHandler = MapSL( gpPtr )) != NULL ) - { - while (gpHandler->selector) - { - if ( SELECTOROF(address) == gpHandler->selector - && OFFSETOF(address) >= gpHandler->rangeStart - && OFFSETOF(address) < gpHandler->rangeEnd ) - return MAKESEGPTR( gpHandler->selector, gpHandler->handler ); - gpHandler++; - } - } - - return 0; -}