| 1 | /* $Id: myldrOpenPath.cpp,v 1.2 2000-09-02 21:08:10 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 | * myldrOpenPath - opens file eventually searching loader specific paths
|
|---|
| 44 | *
|
|---|
| 45 | * @returns OS2 return code.
|
|---|
| 46 | * plv->lv_sfn is set to filename handle.
|
|---|
| 47 | * @param pachFilename Pointer to modulename. Not zero terminated!
|
|---|
| 48 | * @param cchFilename Modulename length.
|
|---|
| 49 | * @param plv Loader local variables? (Struct from KERNEL.SDF)
|
|---|
| 50 | * @param pful Pointer to flags which are passed on to ldrOpen.
|
|---|
| 51 | * @sketch
|
|---|
| 52 | * This is roughly what the original ldrOpenPath does:
|
|---|
| 53 | * Save pTCBCur->TCBFailErr.
|
|---|
| 54 | * if !CLASS_GLOBAL or miniifs then
|
|---|
| 55 | * ldrOpen(pachFilename)
|
|---|
| 56 | * else
|
|---|
| 57 | * loop until no more libpath elements
|
|---|
| 58 | * get next libpath element and add it to the modname.
|
|---|
| 59 | * try open the modname
|
|---|
| 60 | * if successfull then break the loop.
|
|---|
| 61 | * endloop
|
|---|
| 62 | * endif
|
|---|
| 63 | * Restore pTCBCur->TCBFailErr.
|
|---|
| 64 | * @remark This function will change the "Loader state".
|
|---|
| 65 | *
|
|---|
| 66 | */
|
|---|
| 67 | ULONG LDRCALL myldrOpenPath( /* retd 0x10 */
|
|---|
| 68 | PCHAR pachFilename, /* ebp + 0x08 */
|
|---|
| 69 | USHORT cchFilename, /* ebp + 0x0c */
|
|---|
| 70 | ldrlv_t * plv, /* ebp + 0x10 */
|
|---|
| 71 | PULONG pful /* ebp + 0x14 */
|
|---|
| 72 | )
|
|---|
| 73 | {
|
|---|
| 74 |
|
|---|
| 75 | APIRET rc;
|
|---|
| 76 |
|
|---|
| 77 | #ifdef DEBUG
|
|---|
| 78 | /* !paranoia!
|
|---|
| 79 | * Check that the passed in parameters are valid.
|
|---|
| 80 | * If they aren't we'll log this situation and forward the call to ldrOpenPath.
|
|---|
| 81 | */
|
|---|
| 82 | if ((unsigned)pachFilename < 0x10000
|
|---|
| 83 | || (unsigned)plv < 0x10000
|
|---|
| 84 | || cchFilename == 0
|
|---|
| 85 | || cchFilename >= CCHMAXPATH)
|
|---|
| 86 | {
|
|---|
| 87 | kprintf(("myldrOpenPath: Invalid parameters!!!!\n"
|
|---|
| 88 | " pachFilename 0x%08x cchFilename 0x%04x plv 0x%08x pful=0x%08x\n",
|
|---|
| 89 | pachFilename, cchFilename, plv, pful
|
|---|
| 90 | ));
|
|---|
| 91 | return ldrOpenPath(pachFilename, cchFilename, plv, pful);
|
|---|
| 92 | }
|
|---|
| 93 | #endif
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 | /*
|
|---|
| 97 | * We'll check what type of image being opned and save that piece of
|
|---|
| 98 | * information for use in (my)ldrOpen.
|
|---|
| 99 | */
|
|---|
| 100 | if (plv->lv_type == LVTYPE_EXE)
|
|---|
| 101 | setLdrStateLoadingEXE();
|
|---|
| 102 | else if (plv->lv_type == LVTYPE_DLL)
|
|---|
| 103 | setLdrStateLoadingDLL();
|
|---|
| 104 | else
|
|---|
| 105 | setLdrStateLoadingUnsupported();
|
|---|
| 106 |
|
|---|
| 107 | /*
|
|---|
| 108 | * Overload the behaviour of ldrOpenPath?
|
|---|
| 109 | * - Currently only for DLL loading into the GLOBAL class
|
|---|
| 110 | */
|
|---|
| 111 | if (isLdrStateLoadingDLL()
|
|---|
| 112 | && (plv->lv_class == CLASS_GLOBAL || plv->lv_class == CLASS_ALL))
|
|---|
| 113 | {
|
|---|
| 114 | /*
|
|---|
| 115 | * If the executable being loaded is one of our executables we'll
|
|---|
| 116 | * use our method for finding dynamic link libraries.
|
|---|
| 117 | *
|
|---|
| 118 | * At tkExecPgm time this is quite easy. The executable must have been
|
|---|
| 119 | * opened allready and the OUREXE flag will be set if it's one of our
|
|---|
| 120 | * executables.
|
|---|
| 121 | *
|
|---|
| 122 | * At non-tkExecPgm time it's a bit more difficult. We'll have to get
|
|---|
| 123 | * the local infosegment for the process/thread running and check
|
|---|
| 124 | * if the executable (EXE) hMTE is one of ours. We'll do a lookup in
|
|---|
| 125 | * the AVL tree.
|
|---|
| 126 | *
|
|---|
| 127 | * In both cases the result will have to be a module pointer which we
|
|---|
| 128 | * will invoke the overriding ldrOpenPath by.
|
|---|
| 129 | */
|
|---|
| 130 | PMODULE pExe = NULL; /* Pointer to executable which we're to invoke ldrOpenPath by. */
|
|---|
| 131 | if (isLdrStateExecPgm())
|
|---|
| 132 | {
|
|---|
| 133 | if (isLdrStateLoadingOurEXE())
|
|---|
| 134 | pExe = pExeModule;
|
|---|
| 135 | }
|
|---|
| 136 | else
|
|---|
| 137 | {
|
|---|
| 138 | PPTDA pPTDA = ptdaGetCur();
|
|---|
| 139 | if (pPTDA)
|
|---|
| 140 | {
|
|---|
| 141 | pExe = getModuleByhMTE(ptdaGet_ptda_module(pPTDA));
|
|---|
| 142 | #ifdef DEBUG /* While testing! */
|
|---|
| 143 | kprintf(("myldrOpenPath: getModuleByhMTE returned 0x%08x for hmod=0x%04x\n",
|
|---|
| 144 | pExe, ptdaGet_ptda_module(pPTDA)));
|
|---|
| 145 | #endif
|
|---|
| 146 | }
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | /*
|
|---|
| 150 | * If executable module was found the invoke the overriding ldrOpenPath function.
|
|---|
| 151 | */
|
|---|
| 152 | if (pExe != NULL)
|
|---|
| 153 | {
|
|---|
| 154 | /* We'll have to save the TCBFailErr since we don't want to cause
|
|---|
| 155 | * Hard Errors while searching invalid paths, etc. (ldrOpenPath does this!)
|
|---|
| 156 | */
|
|---|
| 157 | USHORT TCBFailErr_save = tcbGetTCBFailErr(tcbGetCur());
|
|---|
| 158 | rc = pExe->Data.pModule->openPath(pachFilename, cchFilename, plv, pful);
|
|---|
| 159 | tcbSetTCBFailErr(tcbGetCur(), TCBFailErr_save);
|
|---|
| 160 | }
|
|---|
| 161 | else
|
|---|
| 162 | rc = ldrOpenPath(pachFilename, cchFilename, plv, pful);
|
|---|
| 163 | }
|
|---|
| 164 | else
|
|---|
| 165 | rc = ldrOpenPath(pachFilename, cchFilename, plv, pful);
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 | /*
|
|---|
| 169 | * Change Loader State - Clear the type part of the loading bits.
|
|---|
| 170 | */
|
|---|
| 171 | setLdrStateClearLoadingType();
|
|---|
| 172 |
|
|---|
| 173 | return rc;
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|