| 1 | /* $Id: myldrOpenPath.cpp,v 1.3 2000-09-22 09:22:40 bird Exp $
|
|---|
| 2 | *
|
|---|
| 3 | * myldrOpenPath - ldrOpenPath used to open executables we'll override
|
|---|
| 4 | * this to altern the search path for DLLs.
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
|---|
| 7 | *
|
|---|
| 8 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 9 | *
|
|---|
| 10 | */
|
|---|
| 11 |
|
|---|
| 12 | /*******************************************************************************
|
|---|
| 13 | * Defined Constants And Macros *
|
|---|
| 14 | *******************************************************************************/
|
|---|
| 15 | #define INCL_DOSERRORS
|
|---|
| 16 | #define INCL_NOPMAPI
|
|---|
| 17 | #define INCL_OS2KRNL_TCB
|
|---|
| 18 | #define INCL_OS2KRNL_PTDA
|
|---|
| 19 |
|
|---|
| 20 | /*******************************************************************************
|
|---|
| 21 | * Header Files *
|
|---|
| 22 | *******************************************************************************/
|
|---|
| 23 | #include <os2.h>
|
|---|
| 24 |
|
|---|
| 25 | #include <memory.h>
|
|---|
| 26 | #include <stdlib.h>
|
|---|
| 27 |
|
|---|
| 28 | #include "devSegDf.h" /* Win32k segment definitions. */
|
|---|
| 29 | #include "log.h"
|
|---|
| 30 | #include "dev32.h"
|
|---|
| 31 | #include "dev32hlp.h"
|
|---|
| 32 | #include <peexe.h>
|
|---|
| 33 | #include <exe386.h>
|
|---|
| 34 | #include "OS2Krnl.h"
|
|---|
| 35 | #include "avl.h"
|
|---|
| 36 | #include "ldrCalls.h"
|
|---|
| 37 | #include "ldr.h"
|
|---|
| 38 | #include "ModuleBase.h"
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 | /**
|
|---|
| 43 | * ldrOpenPath.
|
|---|
| 44 | * myldrOpenPath - opens file eventually searching loader specific paths
|
|---|
| 45 | *
|
|---|
| 46 | * @returns OS2 return code.
|
|---|
| 47 | * plv->lv_sfn is set to filename handle.
|
|---|
| 48 | * @param pachFilename Pointer to modulename. Not zero terminated!
|
|---|
| 49 | * @param cchFilename Modulename length.
|
|---|
| 50 | * @param plv Loader local variables? (Struct from KERNEL.SDF)
|
|---|
| 51 | * @param pful Pointer to flags which are passed on to ldrOpen.
|
|---|
| 52 | * @param lLibPath New parameter in build 14053()
|
|---|
| 53 | * ldrGetMte calls with 1
|
|---|
| 54 | * ldrOpenNewExe calls with 3
|
|---|
| 55 | * This is compared to the initial libpath index.
|
|---|
| 56 | * The libpath index is:
|
|---|
| 57 | * BEGINLIBPATH 1
|
|---|
| 58 | * LIBPATH 2
|
|---|
| 59 | * ENDLIBPATH 3
|
|---|
| 60 | * The initial libpath index is either 1 or 2.
|
|---|
| 61 | * Currently we'll ignore it. (I don't know why ldrGetMte calls ldrOpenPath...)
|
|---|
| 62 | *
|
|---|
| 63 | * @sketch
|
|---|
| 64 | * This is roughly what the original ldrOpenPath does:
|
|---|
| 65 | * Save pTCBCur->TCBFailErr.
|
|---|
| 66 | * if !CLASS_GLOBAL or miniifs then
|
|---|
| 67 | * ldrOpen(pachFilename)
|
|---|
| 68 | * else
|
|---|
| 69 | * if beglibpath != NULL then path = 1 else path = 2
|
|---|
| 70 | * if (lLibPath < path)
|
|---|
| 71 | * return ERROR_FILE_NOT_FOUND; (2)
|
|---|
| 72 | * Allocate buffer.
|
|---|
| 73 | * loop until no more libpath elements
|
|---|
| 74 | * get next libpath element and add it to the modname.
|
|---|
| 75 | * try open the modname
|
|---|
| 76 | * if successfull then break the loop.
|
|---|
| 77 | * endloop
|
|---|
| 78 | * Free buffer.
|
|---|
| 79 | * endif
|
|---|
| 80 | * Restore pTCBCur->TCBFailErr.
|
|---|
| 81 | * @remark This function will change the "Loader state".
|
|---|
| 82 | *
|
|---|
| 83 | */
|
|---|
| 84 | ULONG LDRCALL myldrOpenPath( /* retd 0x14 */
|
|---|
| 85 | PCHAR pachFilename, /* ebp + 0x08 */
|
|---|
| 86 | USHORT cchFilename, /* ebp + 0x0c */
|
|---|
| 87 | ldrlv_t * plv, /* ebp + 0x10 */
|
|---|
| 88 | PULONG pful, /* ebp + 0x14 */
|
|---|
| 89 | ULONG lLibPath /* ebp + 0x18 */
|
|---|
| 90 | )
|
|---|
| 91 | {
|
|---|
| 92 |
|
|---|
| 93 | APIRET rc;
|
|---|
| 94 |
|
|---|
| 95 | #ifdef DEBUG
|
|---|
| 96 | /* !paranoia!
|
|---|
| 97 | * Check that the passed in parameters are valid.
|
|---|
| 98 | * If they aren't we'll log this situation and forward the call to ldrOpenPath.
|
|---|
| 99 | */
|
|---|
| 100 | if ((unsigned)pachFilename < 0x10000
|
|---|
| 101 | || (unsigned)plv < 0x10000
|
|---|
| 102 | || cchFilename == 0
|
|---|
| 103 | || cchFilename >= CCHMAXPATH)
|
|---|
| 104 | {
|
|---|
| 105 | kprintf(("myldrOpenPath: Invalid parameters!!!!\n"
|
|---|
| 106 | " pachFilename 0x%08x cchFilename 0x%04x plv 0x%08x pful=0x%08x\n",
|
|---|
| 107 | pachFilename, cchFilename, plv, pful
|
|---|
| 108 | ));
|
|---|
| 109 | return ldrOpenPath(pachFilename, cchFilename, plv, pful, lLibPath);
|
|---|
| 110 | }
|
|---|
| 111 | #endif
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 | /*
|
|---|
| 115 | * We'll check what type of image being opned and save that piece of
|
|---|
| 116 | * information for use in (my)ldrOpen.
|
|---|
| 117 | */
|
|---|
| 118 | if (plv->lv_type == LVTYPE_EXE)
|
|---|
| 119 | setLdrStateLoadingEXE();
|
|---|
| 120 | else if (plv->lv_type == LVTYPE_DLL)
|
|---|
| 121 | setLdrStateLoadingDLL();
|
|---|
| 122 | else
|
|---|
| 123 | setLdrStateLoadingUnsupported();
|
|---|
| 124 |
|
|---|
| 125 | /*
|
|---|
| 126 | * Overload the behaviour of ldrOpenPath?
|
|---|
| 127 | * - Currently only for DLL loading into the GLOBAL class
|
|---|
| 128 | */
|
|---|
| 129 | if (isLdrStateLoadingDLL()
|
|---|
| 130 | && (plv->lv_class == CLASS_GLOBAL || plv->lv_class == CLASS_ALL))
|
|---|
| 131 | {
|
|---|
| 132 | /*
|
|---|
| 133 | * If the executable being loaded is one of our executables we'll
|
|---|
| 134 | * use our method for finding dynamic link libraries.
|
|---|
| 135 | *
|
|---|
| 136 | * At tkExecPgm time this is quite easy. The executable must have been
|
|---|
| 137 | * opened allready and the OUREXE flag will be set if it's one of our
|
|---|
| 138 | * executables.
|
|---|
| 139 | *
|
|---|
| 140 | * At non-tkExecPgm time it's a bit more difficult. We'll have to get
|
|---|
| 141 | * the local infosegment for the process/thread running and check
|
|---|
| 142 | * if the executable (EXE) hMTE is one of ours. We'll do a lookup in
|
|---|
| 143 | * the AVL tree.
|
|---|
| 144 | *
|
|---|
| 145 | * In both cases the result will have to be a module pointer which we
|
|---|
| 146 | * will invoke the overriding ldrOpenPath by.
|
|---|
| 147 | */
|
|---|
| 148 | PMODULE pExe = NULL; /* Pointer to executable which we're to invoke ldrOpenPath by. */
|
|---|
| 149 | if (isLdrStateExecPgm())
|
|---|
| 150 | {
|
|---|
| 151 | if (isLdrStateLoadingOurEXE())
|
|---|
| 152 | pExe = pExeModule;
|
|---|
| 153 | }
|
|---|
| 154 | else
|
|---|
| 155 | {
|
|---|
| 156 | PPTDA pPTDA = ptdaGetCur();
|
|---|
| 157 | if (pPTDA)
|
|---|
| 158 | {
|
|---|
| 159 | pExe = getModuleByhMTE(ptdaGet_ptda_module(pPTDA));
|
|---|
| 160 | #ifdef DEBUG /* While testing! */
|
|---|
| 161 | kprintf(("myldrOpenPath: getModuleByhMTE returned 0x%08x for hmod=0x%04x\n",
|
|---|
| 162 | pExe, ptdaGet_ptda_module(pPTDA)));
|
|---|
| 163 | #endif
|
|---|
| 164 | }
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | /*
|
|---|
| 168 | * If executable module was found the invoke the overriding ldrOpenPath function.
|
|---|
| 169 | */
|
|---|
| 170 | if (pExe != NULL)
|
|---|
| 171 | {
|
|---|
| 172 | /* We'll have to save the TCBFailErr since we don't want to cause
|
|---|
| 173 | * Hard Errors while searching invalid paths, etc. (ldrOpenPath does this!)
|
|---|
| 174 | */
|
|---|
| 175 | USHORT TCBFailErr_save = tcbGetTCBFailErr(tcbGetCur());
|
|---|
| 176 | rc = pExe->Data.pModule->openPath(pachFilename, cchFilename, plv, pful, lLibPath);
|
|---|
| 177 | tcbSetTCBFailErr(tcbGetCur(), TCBFailErr_save);
|
|---|
| 178 | }
|
|---|
| 179 | else
|
|---|
| 180 | rc = ldrOpenPath(pachFilename, cchFilename, plv, pful, lLibPath);
|
|---|
| 181 | }
|
|---|
| 182 | else
|
|---|
| 183 | rc = ldrOpenPath(pachFilename, cchFilename, plv, pful, lLibPath);
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 | /*
|
|---|
| 187 | * Change Loader State - Clear the type part of the loading bits.
|
|---|
| 188 | */
|
|---|
| 189 | setLdrStateClearLoadingType();
|
|---|
| 190 |
|
|---|
| 191 | return rc;
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 | /**
|
|---|
| 197 | * Wrapper for the old (pre 14053) versions.
|
|---|
| 198 | * the new parameter is set to 3.
|
|---|
| 199 | */
|
|---|
| 200 | ULONG LDRCALL myldrOpenPath_old( /* retd 0x10 */
|
|---|
| 201 | PCHAR pachFilename, /* ebp + 0x08 */
|
|---|
| 202 | USHORT cchFilename, /* ebp + 0x0c */
|
|---|
| 203 | ldrlv_t * plv, /* ebp + 0x10 */
|
|---|
| 204 | PULONG pful /* ebp + 0x14 */
|
|---|
| 205 | )
|
|---|
| 206 | {
|
|---|
| 207 | return myldrOpenPath(pachFilename, cchFilename, plv, pful, 3);
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|