Changeset 1274 for trunk/src/kernel32/windllpe2lx.cpp
- Timestamp:
- Oct 14, 1999, 3:39:13 AM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/windllpe2lx.cpp
r956 r1274 1 /* $Id: windllpe2lx.cpp,v 1. 1 1999-09-15 23:39:07 sandervlExp $ */1 /* $Id: windllpe2lx.cpp,v 1.2 1999-10-14 01:37:55 bird Exp $ */ 2 2 3 3 /* … … 5 5 * 6 6 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl) 7 * 7 * Copyright 1999 knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 8 8 * 9 9 * Project Odin Software License can be found in LICENSE.TXT 10 10 * 11 11 */ 12 #define INCL_DOSFILEMGR /* File Manager values */ 13 #define INCL_DOSERRORS /* DOS Error values */ 14 #define INCL_DOSPROCESS /* DOS Process values */ 15 #define INCL_DOSMODULEMGR 16 #define INCL_DOSMISC /* DOS Miscellanous values */ 17 #define INCL_WIN 18 #include <os2wrap.h> //Odin32 OS/2 api wrappers 19 #include <stdio.h> 20 #include <string.h> 12 13 /******************************************************************************* 14 * Defined Constants And Macros * 15 *******************************************************************************/ 16 #define INCL_DOSERRORS /* DOS Error values */ 17 #define INCL_DOSMODULEMGR /* DOS Module management */ 18 19 20 /******************************************************************************* 21 * Header Files * 22 *******************************************************************************/ 23 #include <os2wrap.h> //Odin32 OS/2 api wrappers 24 21 25 #include <stdlib.h> 22 #include <iostream.h> 23 #include < fstream.h>26 27 #include <win32type.h> 24 28 #include <misc.h> 25 #include <win32type.h>26 #include <pefile.h>27 29 #include <windllpe2lx.h> 28 30 #include <wprocess.h> 29 #include "cio.h" 30 #include "oslibmisc.h" 31 #include "oslibdos.h" 32 33 #include "conwin.h" // Windows Header for console only 31 32 #include "cio.h" // I/O 33 #include "oslibmisc.h" // OSLibGetDllName 34 #include "conwin.h" // Windows Header for console only 34 35 #include "console.h" 35 36 36 //****************************************************************************** 37 //****************************************************************************** 38 ULONG WIN32API RegisterPe2LxDll(WIN32DLLENTRY pfnDllEntry, PIMAGE_TLS_CALLBACK *TlsCallbackAddr, 39 LPDWORD TlsIndexAddr, ULONG TlsInitSize, 40 ULONG TlsTotalSize, LPVOID TlsAddress, 41 LONG Win32TableId, LONG NameTableId, LONG VersionResId, 42 LONG Pe2lxVersion, HINSTANCE hinstance, ULONG dwAttachType) 43 { 44 char *name; 45 46 Win32Pe2LxDll *winmod = (Win32Pe2LxDll *)Win32DllBase::findModule(hinstance); 47 if(dwAttachType == 0) 48 { //Process attach 49 if(getenv("WIN32_IOPL2")) { 50 io_init1(); 51 } 52 name = OSLibGetDllName(hinstance); 53 CheckVersion(Pe2lxVersion, name); 54 55 dprintf(("RegisterDll %X %s reason %d\n", hinstance, name, dwAttachType)); 56 dprintf(("RegisterDll Win32TableId = %x", Win32TableId)); 57 dprintf(("RegisterDll NameTableId = %x", NameTableId)); 58 dprintf(("RegisterDll VersionResId = %x", VersionResId)); 59 dprintf(("RegisterDll Pe2lxVersion = %x", Pe2lxVersion)); 60 61 //converted win32 dll loaded by OS/2 loader 62 winmod = new Win32Pe2LxDll(hinstance, NameTableId, Win32TableId, pfnDllEntry); 63 if(winmod == NULL) { 64 eprintf(("Failed to allocate module object!\n")); 65 DebugInt3(); 66 return 0; //fail dll load 67 } 68 winmod->setTLSAddress(TlsAddress); 69 winmod->setTLSInitSize(TlsInitSize); 70 winmod->setTLSTotalSize(TlsTotalSize); 71 winmod->setTLSIndexAddr(TlsIndexAddr); 72 winmod->setTLSCallBackAddr(TlsCallbackAddr); 73 74 /* @@@PH 1998/03/17 console devices initialization */ 75 iConsoleDevicesRegister(); 76 77 //SvL: 19-8-'98 78 winmod->AddRef(); 79 winmod->setVersionId(VersionResId); 80 81 winmod->attachProcess(); 82 } 83 else {//process detach 84 if(winmod != NULL && !fFreeLibrary) { 85 return 0; //don't unload (OS/2 dll unload bug) 86 } 87 //Runtime environment could already be gone, so don't do this 88 // dprintf(("KERNEL32: Dll Removed by FreeLibrary or ExitProcess\n")); 89 } 90 return 1; //success 91 } 92 //****************************************************************************** 93 //****************************************************************************** 94 Win32Pe2LxDll::Win32Pe2LxDll(HINSTANCE hinstance, int NameTableId, int Win32TableId, 95 WIN32DLLENTRY DllEntryPoint) : 96 Win32ImageBase(hinstance), 97 Win32DllBase(hinstance, DllEntryPoint), 98 Win32Pe2LxImage(hinstance, NameTableId, Win32TableId) 99 { 100 dprintf(("Win32Pe2LxDll::Win32Pe2LxDll %s", szModule)); 101 } 102 //****************************************************************************** 103 //****************************************************************************** 37 38 /** 39 * Register an Pe2Lx Dll module. Called from TIBFix code in Dll Pe2Lx module. 40 * @returns 1 on success. 41 * 0 on failure. 42 * @param Pe2LxVersion Pe2Lx version. High bit is Win32k indicator and must be masked off! 43 * @param hInstance Module handle (OS/2). 44 * @param dwAttachType 0 = attach dll 45 * 1 = detach dll 46 * @sketch Try find module. 47 * IF attach process THEN 48 * BEGIN 49 * END 50 * Init I/O. 51 * Get Lib name and match Pe2Lx version with kernel32 version. 52 * Write info to the log. 53 * Try create pe2lx dll object. 54 * Console devices initialization. 55 * Add reference and attach dll to process. 56 * ELSE 57 * BEGIN 58 * IF module found AND not freelibrary THEN 59 * fail (return 0) due to OS/2 bug. 60 * END 61 * return successfully (return 1) 62 * @status completely implemented. 63 * @author Sander van Leeuwen, knut st. osmundsen 64 */ 65 ULONG WIN32API RegisterPe2LxDll(ULONG ulPe2LxVersion, HINSTANCE hinstance, ULONG ulAttachType) 66 { 67 char *pszName; 68 69 //DebugInt3(); 70 71 Win32Pe2LxDll *pWinMod = (Win32Pe2LxDll *)Win32DllBase::findModule(hinstance); 72 if (ulAttachType == 0UL) 73 { /* Process attach */ 74 75 /* Init I/O */ 76 if (getenv("WIN32_IOPL2")) 77 io_init1(); 78 79 /* Get Lib name and match Pe2Lx version with kernel32 version. */ 80 pszName = OSLibGetDllName(hinstance); 81 CheckVersion(ulPe2LxVersion & ~0x80000000UL, pszName); 82 83 /* Write info to the log. */ 84 dprintf(("RegisterPe2LxExe: ulPe2LxVersion = %#x\n", ulPe2LxVersion)); 85 dprintf(("RegisterPe2LxExe: hinstance = %#x\n", hinstance)); 86 dprintf(("RegisterPe2LxExe: ulAttachType = %#x (reason)\n", ulAttachType)); 87 dprintf(("RegisterPe2LxExe: name = %s\n", OSLibGetDllName(hinstance))); 88 89 /* Try create pe2lx dll object. */ 90 try 91 { 92 pWinMod = new Win32Pe2LxDll(hinstance, (ulPe2LxVersion & 0x80000000UL) == 0x80000000UL); 93 if (pWinMod == NULL) 94 throw ((ULONG)ERROR_NOT_ENOUGH_MEMORY); 95 96 /* @@@PH 1998/03/17 Console devices initialization */ 97 iConsoleDevicesRegister(); 98 99 /* Add reference and attach dll to process. */ 100 pWinMod->AddRef(); 101 pWinMod->attachProcess(); 102 } 103 catch(ULONG ul) 104 { 105 eprintf(("RegisterPe2LxDLL: Failed to create module object, ul=%d\n", ul)); 106 DebugInt3(); 107 return 0; /* fail dll load */ 108 } 109 } 110 else 111 { /* process detach */ 112 if (pWinMod != NULL && !fFreeLibrary) 113 return 0; /* don't unload (OS/2 dll unload bug) - see OS2.bugs in root dir. */ 114 115 #if 0 /* Runtime environment could already be gone, so don't do this */ 116 dprintf(("KERNEL32: Dll Removed by FreeLibrary or ExitProcess\n")); 117 #endif 118 } 119 120 return 1; /* success */ 121 } 122 123 124 /** 125 * Constructor - creates an pe2lx dll object from a module handle to a pe2lx dll module. 126 * @param hinstance Module handle. 127 * @param fWin32k TRUE: Win32k module. 128 * FALSE: Pe2Lx module. 129 * @status completely implemented. 130 * @author Sander van Leeuwen, knut st. osmundsen 131 */ 132 Win32Pe2LxDll::Win32Pe2LxDll(HINSTANCE hinstance, BOOL fWin32k) throw(ULONG) 133 : Win32ImageBase(hinstance), 134 Win32DllBase(hinstance, NULL), 135 Win32Pe2LxImage(hinstance, fWin32k) 136 { 137 dprintf(("Win32Pe2LxDll::Win32Pe2LxDll %s", szModule)); 138 /* set entry point. */ 139 dllEntryPoint = (WIN32DLLENTRY)entryPoint; 140 } 141 142 143 /** 144 * Destructor - does nothing. 145 * @status completely implemented. 146 * @author Sander van Leeuwen 147 */ 104 148 Win32Pe2LxDll::~Win32Pe2LxDll() 105 149 { 106 dprintf(("Win32Pe2LxDll::~Win32Pe2LxDll %s", szModule)); 107 } 108 //****************************************************************************** 109 //****************************************************************************** 150 dprintf(("Win32Pe2LxDll::~Win32Pe2LxDll %s", szModule)); 151 } 152 153 154 /** 155 * Gets pointer to an exported procedure by procedure name. 156 * @returns Address of exported procedure. 0UL if not found. 157 * @param name Exported procedure name. 158 * @status completely implemented. 159 * @author Sander van Leeuwen 160 * @remark 161 */ 110 162 ULONG Win32Pe2LxDll::getApi(char *name) 111 163 { 112 APIRET rc; 113 ULONG apiaddr; 114 115 rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr); 116 if(rc) 117 { 118 return(0); 119 } 120 return(apiaddr); 121 } 122 //****************************************************************************** 123 //****************************************************************************** 164 APIRET rc; 165 ULONG ulApiAddr; 166 167 rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&ulApiAddr); 168 return rc == NO_ERROR ? ulApiAddr : 0; 169 } 170 171 172 /** 173 * Gets pointer to an exported procedure by ordinal. 174 * @returns Pointer to an exported procedure. 0UL if not found. 175 * @param ordinal Export ordinal number. 176 * @status completely implemented. 177 * @author Sander van Leeuwen 178 * @remark FIXME: 179 * This function should be implemented for both Exe and Dll images! 180 * It could be done similar in both peldr image and pe2lx images by 181 * accessing PE structures. 182 */ 124 183 ULONG Win32Pe2LxDll::getApi(int ordinal) 125 184 { 126 APIRET rc; 127 ULONG apiaddr; 128 129 rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr); 130 if(rc) return(0); 131 else return(apiaddr); 132 } 133 //****************************************************************************** 134 //****************************************************************************** 185 APIRET rc; 186 ULONG ulApiAddr; 187 188 rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&ulApiAddr); 189 190 return rc == NO_ERROR ? ulApiAddr : 0; 191 } 192 193 194 /** 195 * Simple question: -Native LX dll? 196 * -No! 197 * @returns FALSE. 198 * @status completely implemented. 199 * @author Sander van Leeuwen 200 */ 135 201 BOOL Win32Pe2LxDll::isLxDll() 136 202 { 137 return FALSE; 138 } 139 //****************************************************************************** 140 //****************************************************************************** 203 return FALSE; 204 } 205
Note:
See TracChangeset
for help on using the changeset viewer.