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