| 1 | /* $Id: OS2KLDR.h,v 1.1 2001-02-10 11:11:43 bird Exp $ | 
|---|
| 2 | * | 
|---|
| 3 | * OS/2 kernel Loader Stuff. | 
|---|
| 4 | * | 
|---|
| 5 | * Copyright (c) 2001 knut st. osmundsen (knut.stange.osmundsen@mynd.no) | 
|---|
| 6 | * | 
|---|
| 7 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 8 | * | 
|---|
| 9 | */ | 
|---|
| 10 |  | 
|---|
| 11 | #ifndef _OS2KLDR_H_ | 
|---|
| 12 | #define _OS2KLDR_H_ | 
|---|
| 13 |  | 
|---|
| 14 | #ifdef __cplusplus | 
|---|
| 15 | extern "C" { | 
|---|
| 16 | #endif | 
|---|
| 17 |  | 
|---|
| 18 | #pragma pack(1) | 
|---|
| 19 |  | 
|---|
| 20 |  | 
|---|
| 21 | /******************************************************************************* | 
|---|
| 22 | *   Structures and Typedefs                                                    * | 
|---|
| 23 | *******************************************************************************/ | 
|---|
| 24 | typedef struct OTE | 
|---|
| 25 | { | 
|---|
| 26 | ULONG    ote_size;             /* Object virtual size */ | 
|---|
| 27 | ULONG    ote_base;             /* Object base virtual address */ | 
|---|
| 28 | ULONG    ote_flags;            /* Attribute flags */ | 
|---|
| 29 | ULONG    ote_pagemap;          /* Object page map index */ | 
|---|
| 30 | ULONG    ote_mapsize;          /* Num of entries in obj page map */ | 
|---|
| 31 | /*ULONG    ote_reserved;*/ | 
|---|
| 32 | USHORT   ote_sel;              /* Object Selector */ | 
|---|
| 33 | USHORT   ote_hob;              /* Object Handle */ | 
|---|
| 34 | } OTE, *POTE; | 
|---|
| 35 |  | 
|---|
| 36 |  | 
|---|
| 37 | /* ote_flags */ | 
|---|
| 38 | #ifndef __EXE386__ | 
|---|
| 39 | #define OBJREAD       0x00000001L     /* Readable Object */ | 
|---|
| 40 | #define OBJWRITE      0x00000002L     /* Writeable Object */ | 
|---|
| 41 | #define OBJEXEC       0x00000004L     /* Executable Object */ | 
|---|
| 42 | #define OBJRSRC       0x00000008L     /* Resource Object */ | 
|---|
| 43 | #define OBJDISCARD    0x00000010L     /* Object is Discardable */ | 
|---|
| 44 | #define OBJSHARED     0x00000020L     /* Object is Shared */ | 
|---|
| 45 | #define OBJPRELOAD    0x00000040L     /* Object has preload pages */ | 
|---|
| 46 | #define OBJINVALID    0x00000080L     /* Object has invalid pages */ | 
|---|
| 47 | #endif | 
|---|
| 48 | #define OBJZEROFIL      0x00000100L     /* Object has zero-filled pages */ | 
|---|
| 49 | #ifndef __EXE386__ | 
|---|
| 50 | #define OBJRESIDENT   0x00000200L     /* Object is resident */ | 
|---|
| 51 | #define OBJCONTIG     0x00000300L     /* Object is resident and contiguous */ | 
|---|
| 52 | #define OBJDYNAMIC    0x00000400L     /* Object is permanent and long locable */ | 
|---|
| 53 | #define OBJTYPEMASK   0x00000700L     /* Object type mask */ | 
|---|
| 54 | #define OBJALIAS16    0x00001000L     /* 16:16 alias required */ | 
|---|
| 55 | #define OBJBIGDEF     0x00002000L     /* Big/Default bit setting */ | 
|---|
| 56 | #define OBJCONFORM    0x00004000L     /* Object is conforming for code */ | 
|---|
| 57 | #define OBJIOPL       0x00008000L     /* Object I/O privilege level */ | 
|---|
| 58 | #endif | 
|---|
| 59 | #define OBJMADEPRIV     0x40000000L     /* Object is made private for debug (now obsolete) */ | 
|---|
| 60 | #define OBJALLOC        0x80000000L     /* Object is allocated used by loader */ | 
|---|
| 61 |  | 
|---|
| 62 |  | 
|---|
| 63 |  | 
|---|
| 64 |  | 
|---|
| 65 |  | 
|---|
| 66 |  | 
|---|
| 67 | /*************************/ | 
|---|
| 68 | /* warp 3.0 AS SMTEs     */ | 
|---|
| 69 | /* Swap ModuleTableEntry */ | 
|---|
| 70 | /*************************/ | 
|---|
| 71 | typedef struct SMTE | 
|---|
| 72 | { | 
|---|
| 73 | /* lxheader fields */ | 
|---|
| 74 | /*- magic,border,worder,level,cpu,os,ver,mflags */ | 
|---|
| 75 | ULONG   smte_mpages;        /* 00  Module # pages */ | 
|---|
| 76 | ULONG   smte_startobj;      /* 04  Object # for instruction */ | 
|---|
| 77 | ULONG   smte_eip;           /* 08  Extended instruction pointer */ | 
|---|
| 78 | ULONG   smte_stackobj;      /* 0c  Object # for stack pointer */ | 
|---|
| 79 | ULONG   smte_esp;           /* 10  Extended stack pointer */ | 
|---|
| 80 | /*- pagesize*/ | 
|---|
| 81 | ULONG   smte_pageshift;      /* 14  Page alignment shift in .EXE */ | 
|---|
| 82 | ULONG   smte_fixupsize;     /* 18  Fixup section size */ | 
|---|
| 83 | /*- fixupsum,ldrsize,ldrsum*/ | 
|---|
| 84 | POTE    smte_objtab;        /* 1c  Object table offset - POINTER */ | 
|---|
| 85 | ULONG   smte_objcnt;        /* 20  Number of objects in module */ | 
|---|
| 86 | ULONG   smte_objmap;        /* 24  Object page map offset - POINTER */ | 
|---|
| 87 | ULONG   smte_itermap;       /* 28  Object iterated data map offset */ | 
|---|
| 88 | ULONG   smte_rsrctab;       /* 2c  Offset of Resource Table */ | 
|---|
| 89 | ULONG   smte_rsrccnt;       /* 30  Number of resource entries */ | 
|---|
| 90 | ULONG   smte_restab;        /* 34  Offset of resident name table - POINTER */ | 
|---|
| 91 | ULONG   smte_enttab;        /* 38  Offset of Entry Table - POINTER */ | 
|---|
| 92 | ULONG   smte_fpagetab;      /* 3c  Offset of Fixup Page Table - POINTER */ | 
|---|
| 93 | ULONG   smte_frectab;       /* 40  Offset of Fixup Record Table - POINTER */ | 
|---|
| 94 | ULONG   smte_impmod;        /* 44  Offset of Import Module Name Table - POINTER */ | 
|---|
| 95 | /*- impmodcnt*/ | 
|---|
| 96 | ULONG   smte_impproc;       /* 48  Offset of Imp Procedure Name Tab - POINTER */ | 
|---|
| 97 | /*- pagesum*/ | 
|---|
| 98 | ULONG   smte_datapage;      /* 4c  Offset of Enumerated Data Pages */ | 
|---|
| 99 | /*- preload*/ | 
|---|
| 100 | ULONG   smte_nrestab;       /* 50  Offset of Non-resident Names Table */ | 
|---|
| 101 | ULONG   smte_cbnrestab;     /* 54  Size of Non-resident Name Table */ | 
|---|
| 102 | /*- nressum*/ | 
|---|
| 103 | ULONG   smte_autods;        /* 58  Object # for automatic data object */ | 
|---|
| 104 | ULONG   smte_debuginfo;     /* 5c  Offset of the debugging info */ | 
|---|
| 105 | ULONG   smte_debuglen;      /* 60  The len of the debug info in */ | 
|---|
| 106 | /*- instpreload,instdemand*/ | 
|---|
| 107 | ULONG   smte_heapsize;      /* 64  use for converted 16-bit modules */ | 
|---|
| 108 | /*- res3*/ | 
|---|
| 109 | /* extra */ | 
|---|
| 110 | PCHAR   smte_path;          /* 68  full pathname - POINTER */ | 
|---|
| 111 | USHORT  smte_semcount;      /* 6c  Count of threads waiting on MTE semaphore. 0 => semaphore is free */ | 
|---|
| 112 | USHORT  smte_semowner;      /* 6e  Slot number of the owner of MTE semahore */ | 
|---|
| 113 | ULONG   smte_pfilecache;    /* 70  Pointer to file cache for Dos32CacheModule */ | 
|---|
| 114 | ULONG   smte_stacksize;     /* 74  Thread 1 Stack size from the exe header */ | 
|---|
| 115 | USHORT  smte_alignshift;    /* 78  use for converted 16-bit modules */ | 
|---|
| 116 | USHORT  smte_NEexpver;      /* 7a  expver from NE header */ | 
|---|
| 117 | USHORT  smte_pathlen;       /* 7c  length of full pathname */ | 
|---|
| 118 | USHORT  smte_NEexetype;     /* 7e  exetype from NE header */ | 
|---|
| 119 | USHORT  smte_csegpack;      /* 80  count of segs to pack */ | 
|---|
| 120 | } SMTE, *PSMTE; | 
|---|
| 121 |  | 
|---|
| 122 |  | 
|---|
| 123 |  | 
|---|
| 124 |  | 
|---|
| 125 |  | 
|---|
| 126 |  | 
|---|
| 127 |  | 
|---|
| 128 |  | 
|---|
| 129 | /********************/ | 
|---|
| 130 | /* warp 3.0 GA MTEs */ | 
|---|
| 131 | /* ModuleTableEntry */ | 
|---|
| 132 | /********************/ | 
|---|
| 133 | typedef struct MTE | 
|---|
| 134 | { | 
|---|
| 135 | USHORT         mte_flags2; | 
|---|
| 136 | USHORT         mte_handle; | 
|---|
| 137 | PSMTE          mte_swapmte;   /* handle for swapmte */ | 
|---|
| 138 | struct MTE *   mte_link; | 
|---|
| 139 | ULONG          mte_flags1; | 
|---|
| 140 | ULONG          mte_impmodcnt; /* number of entries in Import Module Name Table*/ | 
|---|
| 141 | SFN            mte_sfn;       /*"filehandle"*/ | 
|---|
| 142 | USHORT         mte_usecnt;    /* (.EXE only) - use count */ | 
|---|
| 143 | CHAR           mte_modname[8]; | 
|---|
| 144 | } MTE,*PMTE,**PPMTE; | 
|---|
| 145 |  | 
|---|
| 146 |  | 
|---|
| 147 | /***********/ | 
|---|
| 148 | /* flags 1 */ | 
|---|
| 149 | /***********/ | 
|---|
| 150 | #define NOAUTODS            0x00000000   /* No Auto DS exists */ | 
|---|
| 151 | #define SOLO                0x00000001   /* Auto DS is shared */ | 
|---|
| 152 | #define INSTANCEDS          0x00000002   /* Auto DS is not shared */ | 
|---|
| 153 | #define INSTLIBINIT         0x00000004   /* Perinstance Libinit */ | 
|---|
| 154 | #define GINISETUP           0x00000008   /* Global Init has been setup */ | 
|---|
| 155 | #define NOINTERNFIXUPS        0x00000010 /* internal fixups in .EXE.DLL applied */ | 
|---|
| 156 | #define NOEXTERNFIXUPS      0x00000020   /* external fixups in .EXE.DLL applied */ | 
|---|
| 157 | #define CLASS_PROGRAM       0x00000040   /* Program class */ | 
|---|
| 158 | #define CLASS_GLOBAL        0x00000080   /* Global class */ | 
|---|
| 159 | #define CLASS_SPECIFIC      0x000000C0   /* Specific class, as against global */ | 
|---|
| 160 | #define CLASS_ALL           0x00000000   /* nonspecific class  all modules */ | 
|---|
| 161 | #define CLASS_MASK          0x000000C0 /* */ | 
|---|
| 162 | #define MTEPROCESSED        0x00000100   /* MTE being loaded */ | 
|---|
| 163 | #define USED                0x00000200   /* MTE is referenced  see ldrgc.c */ | 
|---|
| 164 | #define DOSLIB              0x00000400   /* set if DOSCALL1 */ | 
|---|
| 165 | #define DOSMOD              0x00000800   /* set if DOSCALLS */ | 
|---|
| 166 | #define MTE_MEDIAFIXED      0x00001000   /* File Media permits discarding */ | 
|---|
| 167 | #define LDRINVALID          0x00002000   /* module not loadable */ | 
|---|
| 168 | #define PROGRAMMOD          0x00000000   /* program module */ | 
|---|
| 169 | #define DEVDRVMOD           0x00004000   /* device driver module */ | 
|---|
| 170 | #define LIBRARYMOD          0x00008000   /* DLL module */ | 
|---|
| 171 | #define VDDMOD              0x00010000   /* VDD module */ | 
|---|
| 172 | #define MVDMMOD             0x00020000   /* Set if VDD Helper MTE (MVDM.DLL) */ | 
|---|
| 173 | #define INGRAPH             0x00040000   /* In Module Graph  see ldrgc.c */ | 
|---|
| 174 | #define GINIDONE            0x00080000   /* Global Init has finished */ | 
|---|
| 175 | #define MTEADDRALLOCED      0x00100000   /* Allocate specific or not */ | 
|---|
| 176 | #define FSDMOD              0x00200000   /* FSD MTE */ | 
|---|
| 177 | #define FSHMOD              0x00400000   /* FS helper MTE */ | 
|---|
| 178 | #define MTELONGNAMES        0x00800000   /* Module supports longnames */ | 
|---|
| 179 | #define MTE_MEDIACONTIG     0x01000000   /* File Media contiguous memory req */ | 
|---|
| 180 | #define MTE_MEDIA16M        0x02000000   /* File Media requires mem below 16M */ | 
|---|
| 181 | #define MTESWAPONLOAD       0x04000000   /* make code pages swap on load */ | 
|---|
| 182 | #define MTEPORTHOLE         0x08000000   /* porthole module */ | 
|---|
| 183 | #define MTEMODPROT          0x10000000   /* Module has shared memory protected */ | 
|---|
| 184 | #define MTENEWMOD           0x20000000   /* Newly added module */ | 
|---|
| 185 | #define MTEDLLTERM          0x40000000   /* Gets instance termination */ | 
|---|
| 186 | #define MTESYMLOADED        0x80000000   /* Set if debugger symbols loaded */ | 
|---|
| 187 |  | 
|---|
| 188 |  | 
|---|
| 189 | /***********/ | 
|---|
| 190 | /* flags 2 */ | 
|---|
| 191 | /***********/ | 
|---|
| 192 | #define MTEFORMATMASK         0x0003     /* Module format mask */ | 
|---|
| 193 | #define MTEFORMATR1           0x0000     /* Module format reserved */ | 
|---|
| 194 | #define MTEFORMATNE           0x0001     /* Module format NE */ | 
|---|
| 195 | #define MTEFORMATLX           0x0002     /* Module format LX */ | 
|---|
| 196 | #define MTEFORMATR2           0x0003     /* Module format reserved */ | 
|---|
| 197 | #define MTESYSTEMDLL          0x0004     /* DLL exists in system list */ | 
|---|
| 198 | #define MTELOADORATTACH       0x0008     /* Module under load or attach  for init */ | 
|---|
| 199 | #define MTECIRCLEREF          0x0010     /* Module circular reference detection */ | 
|---|
| 200 | #define MTEFREEFIXUPS         0x0020     /* Free system mte's fixup flag d#98488 */ | 
|---|
| 201 | #define MTEPRELOADED          0x0040     /* MTE Preload completed */ | 
|---|
| 202 | #define MTEGETMTEDONE         0x0080     /* GetMTE already resolved */ | 
|---|
| 203 | #define MTEPACKSEGDONE        0x0100     /* Segment packed memory allocated */ | 
|---|
| 204 | #define MTE20LIELIST          0x0200     /* Name present in version20 lie list */ | 
|---|
| 205 | #define MTESYSPROCESSED       0x0400     /* System DLL already processed */ | 
|---|
| 206 | #define MTEDLLONEXTLST        0x1000     /* DLL has term routine on exit list #74177 */ | 
|---|
| 207 |  | 
|---|
| 208 |  | 
|---|
| 209 | #pragma pack() | 
|---|
| 210 |  | 
|---|
| 211 |  | 
|---|
| 212 | #ifndef INCL_OS2KRNL_LDR_NOAPIS         /* Flag to exclude prototypes. */ | 
|---|
| 213 | #ifndef INCL_16     /* 16-bit test - function prototypes for 32-bit code only! */ | 
|---|
| 214 |  | 
|---|
| 215 |  | 
|---|
| 216 | /******************************************************************************* | 
|---|
| 217 | *   Defined Constants And Macros                                               * | 
|---|
| 218 | *******************************************************************************/ | 
|---|
| 219 | #define LDRCALL __stdcall | 
|---|
| 220 |  | 
|---|
| 221 | /** Additional ldrFindModule flag. Or together with the class. */ | 
|---|
| 222 | #define SEARCH_FULL_NAME    0x0001 | 
|---|
| 223 |  | 
|---|
| 224 |  | 
|---|
| 225 | /******************************************************************************* | 
|---|
| 226 | *   Function Prototypes                                                        * | 
|---|
| 227 | *******************************************************************************/ | 
|---|
| 228 | /** | 
|---|
| 229 | * _ldrClose | 
|---|
| 230 | */ | 
|---|
| 231 | extern ULONG LDRCALL ldrClose(  /* retd  0x04 */ | 
|---|
| 232 | SFN p1                      /* ebp + 0x08 */ | 
|---|
| 233 | ); | 
|---|
| 234 |  | 
|---|
| 235 | ULONG LDRCALL myldrClose(SFN); | 
|---|
| 236 |  | 
|---|
| 237 |  | 
|---|
| 238 | /** | 
|---|
| 239 | * _ldrOpen | 
|---|
| 240 | */ | 
|---|
| 241 | extern ULONG LDRCALL ldrOpen(   /* retd  0x0c */ | 
|---|
| 242 | PSFN    p1,                 /* ebp + 0x08 */ | 
|---|
| 243 | PCHAR   p2,                 /* ebp + 0x0c */ | 
|---|
| 244 | PULONG  p3                  /* ebp + 0x10 */ | 
|---|
| 245 | ); | 
|---|
| 246 |  | 
|---|
| 247 | ULONG LDRCALL myldrOpen(PSFN phFile, PSZ pszFilename, PULONG pfl); | 
|---|
| 248 |  | 
|---|
| 249 |  | 
|---|
| 250 | /** | 
|---|
| 251 | * _ldrRead | 
|---|
| 252 | */ | 
|---|
| 253 | extern ULONG LDRCALL ldrRead(   /* retd  0x18 */ | 
|---|
| 254 | SFN     hFile,              /* ebp + 0x08 */ | 
|---|
| 255 | ULONG   ulOffset,           /* ebp + 0x0c */ | 
|---|
| 256 | PVOID   pvBuffer,           /* ebp + 0x10 */ | 
|---|
| 257 | ULONG   fpBuffer,           /* ebp + 0x14 */ | 
|---|
| 258 | ULONG   cbToRead,           /* ebp + 0x18 */ | 
|---|
| 259 | PMTE    pMTE                /* ebp + 0x1c */ | 
|---|
| 260 | ); | 
|---|
| 261 |  | 
|---|
| 262 | ULONG LDRCALL myldrRead( | 
|---|
| 263 | SFN     hFile, | 
|---|
| 264 | ULONG   ulOffset, | 
|---|
| 265 | PVOID   pvBuffer, | 
|---|
| 266 | ULONG   fpBuffer, | 
|---|
| 267 | ULONG   cbToRead, | 
|---|
| 268 | PMTE    pMTE | 
|---|
| 269 | ); | 
|---|
| 270 |  | 
|---|
| 271 |  | 
|---|
| 272 |  | 
|---|
| 273 | /** | 
|---|
| 274 | * _LDRQAppType | 
|---|
| 275 | */ | 
|---|
| 276 | extern ULONG LDRCALL LDRQAppType(   /* retd  0x08 */ | 
|---|
| 277 | ULONG p1,                       /* ebp + 0x08 */ | 
|---|
| 278 | ULONG p2                        /* ebp + 0x0c */ | 
|---|
| 279 | ); | 
|---|
| 280 |  | 
|---|
| 281 | ULONG LDRCALL myLDRQAppType(ULONG,ULONG); | 
|---|
| 282 |  | 
|---|
| 283 |  | 
|---|
| 284 | /** | 
|---|
| 285 | * ldrEnum32bitRelRecs | 
|---|
| 286 | * @param  pMTE           Pointer to MTE for this module. | 
|---|
| 287 | * @param  iObject        Object index. 0-based! | 
|---|
| 288 | * @param  iPageTabl      Page index. 0-based! | 
|---|
| 289 | * @param  pvPage         Pointer to page buffer. | 
|---|
| 290 | * @param  ulPageAddress  Note! Page is not present. | 
|---|
| 291 | * @param  pPTDA | 
|---|
| 292 | * | 
|---|
| 293 | */ | 
|---|
| 294 | extern ULONG LDRCALL ldrEnum32bitRelRecs( /* retd 0x20 */ | 
|---|
| 295 | PMTE pMTE,                      /* ebp + 0x08 */ | 
|---|
| 296 | ULONG iObject,                  /* ebp + 0x0c */ | 
|---|
| 297 | ULONG iPageTable,               /* ebp + 0x10 */ | 
|---|
| 298 | PVOID pvPage,                   /* ebp + 0x14 */ | 
|---|
| 299 | ULONG ulPageAddress,            /* ebp + 0x18 */ | 
|---|
| 300 | PVOID pvPTDA                    /* ebp + 0x1c */ | 
|---|
| 301 | ); | 
|---|
| 302 |  | 
|---|
| 303 | ULONG LDRCALL myldrEnum32bitRelRecs(PMTE, ULONG, ULONG, PVOID, ULONG, PVOID); | 
|---|
| 304 |  | 
|---|
| 305 |  | 
|---|
| 306 |  | 
|---|
| 307 | /** | 
|---|
| 308 | * Loader local variables from KERNEL.SDF. | 
|---|
| 309 | */ | 
|---|
| 310 | typedef struct ldrlv_s /* #memb 12 size 39 (0x027) */ | 
|---|
| 311 | { | 
|---|
| 312 | PMTE        lv_pmte;                /* Pointer to mte. (ldrCreateMte/ldrXXX) */ | 
|---|
| 313 | ULONG       lv_lbufaddr; | 
|---|
| 314 | ULONG       lv_sbufaddr; | 
|---|
| 315 | ULONG       lv_lrecbufaddr; | 
|---|
| 316 | ULONG       lv_srecbufaddr; | 
|---|
| 317 | ULONG       lv_new_exe_off; | 
|---|
| 318 | USHORT      lv_sfn;                 /* Handle to the module being loaded */ | 
|---|
| 319 | USHORT      lv_hobmte; | 
|---|
| 320 | ULONG       lv_objnum; | 
|---|
| 321 | ULONG       lv_csmte;               /* size of the swappable mte heap block. (ldrCreateMte) */ | 
|---|
| 322 | USHORT      lv_class;               /* Object class CLASS_* defines in OS2Krnl (mteflags1) it seems. */ | 
|---|
| 323 | /* CLASS_PROGRAM    Program class. */ | 
|---|
| 324 | /* CLASS_GLOBAL     Global class. */ | 
|---|
| 325 | /* CLASS_SPECIFIC   Specific class, as against global. */ | 
|---|
| 326 | /* CLASS_ALL (0)    Nonspecific class  all modules. */ | 
|---|
| 327 | /* CLASS_MASK       Class mask. */ | 
|---|
| 328 | UCHAR       lv_type;                /* Type of executable image expected loaded. */ | 
|---|
| 329 | } ldrlv_t; | 
|---|
| 330 |  | 
|---|
| 331 |  | 
|---|
| 332 | /* | 
|---|
| 333 | * Values of the lv_type byte. (Qualified guesses.) | 
|---|
| 334 | */ | 
|---|
| 335 | #define LVTYPE_EXE      0               /* Executable program. */ | 
|---|
| 336 | #define LVTYPE_DLL      1               /* Dynamic Link Library. */ | 
|---|
| 337 | #define LVTYPE_DD       2               /* Device Driver. */ | 
|---|
| 338 | #define LVTYPE_IFS      3               /* Installable Filesystem. */ | 
|---|
| 339 | #define LVTYPE_VDD      4               /* Virtual Device Driver (for VDMs). */ | 
|---|
| 340 |  | 
|---|
| 341 |  | 
|---|
| 342 |  | 
|---|
| 343 | /** | 
|---|
| 344 | * ldrOpenPath | 
|---|
| 345 | *  pre 14053. | 
|---|
| 346 | * @returns   OS2 return code. | 
|---|
| 347 | *            pLdrLv->lv_sfn  is set to filename handle. | 
|---|
| 348 | * @param     pachModname   Pointer to modulename. Not zero terminated! | 
|---|
| 349 | * @param     cchModname    Modulename length. | 
|---|
| 350 | * @param     pLdrLv        Loader local variables? (Struct from KERNEL.SDF) | 
|---|
| 351 | * @param     pfl           Pointer to flags which are passed on to ldrOpen. | 
|---|
| 352 | * @sketch | 
|---|
| 353 | *  if !CLASS_GLOBAL or miniifs then | 
|---|
| 354 | *      ldrOpen(pachModName) | 
|---|
| 355 | *  else | 
|---|
| 356 | *      loop until no more libpath elements | 
|---|
| 357 | *          get next libpath element and add it to the modname. | 
|---|
| 358 | *          try open the modname | 
|---|
| 359 | *          if successfull then break the loop. | 
|---|
| 360 | *      endloop | 
|---|
| 361 | *  endif | 
|---|
| 362 | */ | 
|---|
| 363 | extern ULONG LDRCALL ldrOpenPath_old(   /* retd  0x10 */ | 
|---|
| 364 | PCHAR       pachFilename,       /* ebp + 0x08 */ | 
|---|
| 365 | USHORT      cchFilename,        /* ebp + 0x0c */ | 
|---|
| 366 | ldrlv_t *   plv,                /* ebp + 0x10 */ | 
|---|
| 367 | PULONG      pful                /* ebp + 0x14 */ | 
|---|
| 368 | ); | 
|---|
| 369 |  | 
|---|
| 370 | ULONG LDRCALL myldrOpenPath_old(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *plv, PULONG pful); | 
|---|
| 371 |  | 
|---|
| 372 |  | 
|---|
| 373 | /** | 
|---|
| 374 | * ldrOpenPath - ldrOpenPath for build 14053 and above. | 
|---|
| 375 | * | 
|---|
| 376 | * @returns   OS2 return code. | 
|---|
| 377 | *            plv->lv_sfn  is set to filename handle. | 
|---|
| 378 | * @param     pachFilename  Pointer to modulename. Not zero terminated! | 
|---|
| 379 | * @param     cchFilename   Modulename length. | 
|---|
| 380 | * @param     plv           Loader local variables? (Struct from KERNEL.SDF) | 
|---|
| 381 | * @param     pful          Pointer to flags which are passed on to ldrOpen. | 
|---|
| 382 | * @param     lLibPath      New parameter in build 14053. | 
|---|
| 383 | *                          ldrGetMte calls with 1 | 
|---|
| 384 | *                          ldrOpenNewExe calls with 3 | 
|---|
| 385 | *                          This is compared to the initial libpath index. | 
|---|
| 386 | *                              The libpath index is: | 
|---|
| 387 | *                                  BEGINLIBPATH    1 | 
|---|
| 388 | *                                  LIBPATH         2 | 
|---|
| 389 | *                                  ENDLIBPATH      3 | 
|---|
| 390 | *                              The initial libpath index is either 1 or 2. | 
|---|
| 391 | * | 
|---|
| 392 | * @sketch | 
|---|
| 393 | * This is roughly what the original ldrOpenPath does: | 
|---|
| 394 | *      Save pTCBCur->TCBFailErr. | 
|---|
| 395 | *      if !CLASS_GLOBAL or miniifs then | 
|---|
| 396 | *          ldrOpen(pachFilename) | 
|---|
| 397 | *      else | 
|---|
| 398 | *          if beglibpath != NULL then path = 1 else path = 2 | 
|---|
| 399 | *          if (lLibPath < path) | 
|---|
| 400 | *              return ERROR_FILE_NOT_FOUND; (2) | 
|---|
| 401 | *          Allocate buffer. | 
|---|
| 402 | *          loop until no more libpath elements | 
|---|
| 403 | *              get next libpath element and add it to the modname. | 
|---|
| 404 | *              try open the modname | 
|---|
| 405 | *              if successfull then break the loop. | 
|---|
| 406 | *          endloop | 
|---|
| 407 | *          Free buffer. | 
|---|
| 408 | *      endif | 
|---|
| 409 | *      Restore pTCBCur->TCBFailErr. | 
|---|
| 410 | */ | 
|---|
| 411 | extern ULONG LDRCALL ldrOpenPath(  /* retd  0x14 */ | 
|---|
| 412 | PCHAR       pachFilename,      /* ebp + 0x08 */ | 
|---|
| 413 | USHORT      cchFilename,       /* ebp + 0x0c */ | 
|---|
| 414 | ldrlv_t *   plv,               /* ebp + 0x10 */ | 
|---|
| 415 | PULONG      pful,              /* ebp + 0x14 */ | 
|---|
| 416 | ULONG       lLibPath           /* ebp + 0x18 */ | 
|---|
| 417 | ); | 
|---|
| 418 |  | 
|---|
| 419 | ULONG LDRCALL myldrOpenPath(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *plv, PULONG pful, ULONG lLibPath); | 
|---|
| 420 |  | 
|---|
| 421 |  | 
|---|
| 422 | /** | 
|---|
| 423 | * Finds a module if it's loaded. | 
|---|
| 424 | * @returns     NO_ERROR on success. | 
|---|
| 425 | *              OS/2 errorcode on error. | 
|---|
| 426 | * @param       pachFilename    Pointer to module filename. | 
|---|
| 427 | * @param       cchFilename     Length of modulefilename. | 
|---|
| 428 | * @param       usClass         Module class. (CLASS_*) | 
|---|
| 429 | * @param       ppMTE           Pointer to pMTE found. | 
|---|
| 430 | * @sketch | 
|---|
| 431 | */ | 
|---|
| 432 | ULONG LDRCALL ldrFindModule(        /* retd  0x10 */ | 
|---|
| 433 | PCHAR       pachFilename,       /* ebp + 0x08 */ | 
|---|
| 434 | USHORT      cchFilename,        /* ebp + 0x0c */ | 
|---|
| 435 | USHORT      usClass,            /* ebp + 0x10 */ | 
|---|
| 436 | PPMTE       ppMTE               /* ebp + 0x14 */ | 
|---|
| 437 | ); | 
|---|
| 438 |  | 
|---|
| 439 | ULONG LDRCALL myldrFindModule(PCHAR pachFilename, USHORT cchFilename, USHORT usClass, PPMTE ppMTE); | 
|---|
| 440 |  | 
|---|
| 441 |  | 
|---|
| 442 | /** | 
|---|
| 443 | * Checks if a module was loaded using DosLoadModule. | 
|---|
| 444 | * This is called from LDRGetProcAddr and LDRFreeModule. | 
|---|
| 445 | * @returns NO_ERROR if the module was LoadModuled or executable. | 
|---|
| 446 | *          ERROR_INVALID_HANDLE if not LoadModuled. | 
|---|
| 447 | * @param   hmte    MTE handle. | 
|---|
| 448 | * @param   pptda   Pointer to the PTDA of the process calling. (current) | 
|---|
| 449 | * @param   pcUsage Pointer to usage variable. (output) | 
|---|
| 450 | *                  The usage count is returned. | 
|---|
| 451 | * @sketch | 
|---|
| 452 | */ | 
|---|
| 453 | #ifdef _ptda_h_ | 
|---|
| 454 | ULONG LDRCALL ldrWasLoadModuled(        /* retd 0x0c */ | 
|---|
| 455 | HMTE        hmte,                   /* ebp + 0x08 */ | 
|---|
| 456 | PPTDA       pptda,                  /* ebp + 0x0c */ | 
|---|
| 457 | PULONG      pcUsage);               /* ebp + 0x10 */ | 
|---|
| 458 |  | 
|---|
| 459 | ULONG LDRCALL myldrWasLoadModuled(HMTE hmte, PPTDA pptda, PULONG pcUsage); | 
|---|
| 460 | #endif | 
|---|
| 461 |  | 
|---|
| 462 |  | 
|---|
| 463 | /** | 
|---|
| 464 | * LDRGetProcAddr gets address and proctype for a entry point to a module. | 
|---|
| 465 | * @returns NO_ERROR if the module was LoadModuled. | 
|---|
| 466 | *          ERROR_INVALID_HANDLE if not LoadModuled. | 
|---|
| 467 | * @param   hmte            Handle of module. | 
|---|
| 468 | * @param   ulOrdinal       Procedure ordinal. | 
|---|
| 469 | * @param   pszName         Pointer to procedure name. | 
|---|
| 470 | *                          NULL is allowed. Ignored if ulOrdinal is not zero. | 
|---|
| 471 | * @param   pulAddress      Pointer to address variable. (output) | 
|---|
| 472 | * @param   fFlat           TRUE if a flat 0:32 address is to be returned. | 
|---|
| 473 | *                          FALSE if a far 16:16 address is to be returned. | 
|---|
| 474 | * @param   pulProcType     Pointer to procedure type variable. (output) | 
|---|
| 475 | *                          NULL is allowed. (DosQueryProcAddr uses NULL) | 
|---|
| 476 | *                          In user space. | 
|---|
| 477 | * @sketch | 
|---|
| 478 | */ | 
|---|
| 479 | ULONG LDRCALL LDRGetProcAddr(           /* retd 0x14 */ | 
|---|
| 480 | HMTE        hmte,                   /* ebp + 0x08 */ | 
|---|
| 481 | ULONG       ulOrdinal,              /* ebp + 0x0c */ | 
|---|
| 482 | PCSZ        pszName,                /* ebp + 0x10 */ | 
|---|
| 483 | PULONG      pulAddress,             /* ebp + 0x14 */ | 
|---|
| 484 | BOOL        fFlat,                  /* ebp + 0x18 */ | 
|---|
| 485 | PULONG      pulProcType);           /* ebp + 0x1c */ | 
|---|
| 486 |  | 
|---|
| 487 | ULONG LDRCALL myLDRGetProcAddr(HMTE hmte, ULONG ulOrdinal, PCSZ pszName, PULONG pulAddress, BOOL fFlat, PULONG pulProcType); | 
|---|
| 488 |  | 
|---|
| 489 |  | 
|---|
| 490 |  | 
|---|
| 491 | /** | 
|---|
| 492 | * LDRClearSem - Clears the loader semaphore. | 
|---|
| 493 | * (It does some garbage collection on release.) | 
|---|
| 494 | * @returns   NO_ERROR on success. | 
|---|
| 495 | *            OS/2 error on failure. (ERROR_INTERRUPT?) | 
|---|
| 496 | */ | 
|---|
| 497 | extern ULONG LDRCALL LDRClearSem(void); | 
|---|
| 498 |  | 
|---|
| 499 |  | 
|---|
| 500 | /** | 
|---|
| 501 | * LDRRequestSem - Requests the loader semaphore.. | 
|---|
| 502 | * @returns   NO_ERROR if succesfully. | 
|---|
| 503 | *            OS2 errorcode on failure. (ERROR_INTERRUPT?) | 
|---|
| 504 | */ | 
|---|
| 505 | #define LDRRequestSem()   KSEMRequestMutex(pLdrSem, (ULONG)-1) | 
|---|
| 506 |  | 
|---|
| 507 |  | 
|---|
| 508 | /* | 
|---|
| 509 | * Pointer to the loader semaphore. | 
|---|
| 510 | */ | 
|---|
| 511 | #ifdef _OS2KSEM_h_ | 
|---|
| 512 | extern PKSEMMTX    pLdrSem; | 
|---|
| 513 | #endif | 
|---|
| 514 |  | 
|---|
| 515 |  | 
|---|
| 516 | /** | 
|---|
| 517 | * Validates an hMTE and gets the MTE pointer. | 
|---|
| 518 | * @returns   Pointer to MTE on success. | 
|---|
| 519 | *            NULL on error. | 
|---|
| 520 | * @param     hMTE  MTE handle. | 
|---|
| 521 | * @remark    If you wan't to this faster: | 
|---|
| 522 | *              Use the hMTE as a HOB and get the HOB address (by using VMGetHandleInfo). | 
|---|
| 523 | */ | 
|---|
| 524 | extern PMTE LDRCALL ldrValidateMteHandle(HMTE hMTE); | 
|---|
| 525 |  | 
|---|
| 526 |  | 
|---|
| 527 | /** | 
|---|
| 528 | * Gets the pMTE from a hMTE. No checks. | 
|---|
| 529 | * @returns     Pointer to the pMTE for a given hMTE. | 
|---|
| 530 | * @param       hMTE    Module handle. | 
|---|
| 531 | * @sketch | 
|---|
| 532 | */ | 
|---|
| 533 | extern PMTE KRNLCALL ldrASMpMTEFromHandle(HMTE  hMTE); | 
|---|
| 534 |  | 
|---|
| 535 |  | 
|---|
| 536 | /** | 
|---|
| 537 | * Translates a relative filename to a full qualified filename. | 
|---|
| 538 | * @returns NO_ERROR on success. | 
|---|
| 539 | *          Errorcode on error. | 
|---|
| 540 | * @param   pszFilename     Pointer to nullterminated filename. | 
|---|
| 541 | */ | 
|---|
| 542 | extern ULONG LDRCALL ldrTransPath(PSZ pszFilename); | 
|---|
| 543 |  | 
|---|
| 544 |  | 
|---|
| 545 | /** | 
|---|
| 546 | * Sets the VM flags for an executable object. | 
|---|
| 547 | * @returns     void | 
|---|
| 548 | * @param       pMTE        Pointer to the module table entry. | 
|---|
| 549 | * @param       flObj       LX Object flags. | 
|---|
| 550 | * @param       pflFlags1   Pointer to the flFlags1 of VMAllocMem (out). | 
|---|
| 551 | * @param       pflFlags2   Pointer to the flFlags2 of VMAllocMem (out). | 
|---|
| 552 | */ | 
|---|
| 553 | extern VOID LDRCALL  ldrSetVMflags( /* retd  0x10 */ | 
|---|
| 554 | PMTE        pMTE,               /* ebp + 0x08 */ | 
|---|
| 555 | ULONG       flObj,              /* ebp + 0x0c */ | 
|---|
| 556 | PULONG      pflFlags1,          /* ebp + 0x10 */ | 
|---|
| 557 | PULONG      pflFlags2           /* ebp + 0x14 */ | 
|---|
| 558 | ); | 
|---|
| 559 |  | 
|---|
| 560 | VOID LDRCALL myldrSetVMflags(PMTE pMTE, ULONG flObj, PULONG pflFlags1, PULONG pflFlags2); | 
|---|
| 561 |  | 
|---|
| 562 |  | 
|---|
| 563 | /** | 
|---|
| 564 | * Checks if the internal name (first name in the resident nametable) matches | 
|---|
| 565 | * the filename. | 
|---|
| 566 | * @returns     NO_ERROR on success (the name matched). | 
|---|
| 567 | *              ERROR_INVALID_NAME if mismatch. | 
|---|
| 568 | * @param       pMTE    Pointer to the MTE of the module to check.<br> | 
|---|
| 569 | *                      Assumes! that the filename for this module is present in ldrpFileNameBuf. | 
|---|
| 570 | */ | 
|---|
| 571 | extern ULONG LDRCALL    ldrCheckInternalName( /* retd  0x04 */ | 
|---|
| 572 | PMTE        pMTE                /* ebp + 0x08 */ | 
|---|
| 573 | ); | 
|---|
| 574 |  | 
|---|
| 575 | ULONG LDRCALL myldrCheckInternalName(PMTE pMTE); | 
|---|
| 576 |  | 
|---|
| 577 |  | 
|---|
| 578 | /** | 
|---|
| 579 | * Parses a filename to find the name and extention. | 
|---|
| 580 | * @returns Length of the filename without the extention. | 
|---|
| 581 | * @param   pachFilename    Pointer to filename to parse - must have path! | 
|---|
| 582 | * @param   ppachName       Pointer to pointer which should hold the name pointer upon successfull return. | 
|---|
| 583 | * @param   ppachExt        Pointer to pointer which should hold the extention pointer upon successfull return. | 
|---|
| 584 | */ | 
|---|
| 585 | extern ULONG LDRCALL    ldrGetFileName(PSZ pszFilename, PCHAR *ppchName, PCHAR *ppchExt); | 
|---|
| 586 |  | 
|---|
| 587 |  | 
|---|
| 588 | /** | 
|---|
| 589 | * Parses a filename to find the name and extention. | 
|---|
| 590 | * @returns Length of the filename without the extention. | 
|---|
| 591 | * @param   pachFilename    Pointer to filename to parse - path not needed. | 
|---|
| 592 | * @param   ppachName       Pointer to pointer which should hold the name pointer upon successfull return. | 
|---|
| 593 | * @param   ppachExt        Pointer to pointer which should hold the extention pointer upon successfull return. | 
|---|
| 594 | */ | 
|---|
| 595 | extern ULONG LDRCALL    ldrGetFileName2(PSZ pszFilename, PCHAR *ppchName, PCHAR *ppchExt); | 
|---|
| 596 |  | 
|---|
| 597 |  | 
|---|
| 598 | /** | 
|---|
| 599 | * Uppercase a string. | 
|---|
| 600 | * @returns void | 
|---|
| 601 | * @param   pach    String to uppercase. | 
|---|
| 602 | * @param   cch     Length of string. (may include terminator) | 
|---|
| 603 | */ | 
|---|
| 604 | extern VOID LDRCALL     ldrUCaseString(PCHAR pch, unsigned cch); | 
|---|
| 605 |  | 
|---|
| 606 |  | 
|---|
| 607 | /** | 
|---|
| 608 | * Pointer to the loader filename buffer. | 
|---|
| 609 | * Upon return from ldrOpen (and ldrOpenPath which calls ldrOpen) this is | 
|---|
| 610 | * set to the fully qualified filename of the file last opened (successfully). | 
|---|
| 611 | */ | 
|---|
| 612 | extern PSZ *pldrpFileNameBuf; | 
|---|
| 613 | #define ldrpFileNameBuf (*pldrpFileNameBuf) | 
|---|
| 614 |  | 
|---|
| 615 |  | 
|---|
| 616 |  | 
|---|
| 617 | #endif /* INCL_16 (16-bit test - function prototypes for 32-bit code only!) */ | 
|---|
| 618 | #endif /* no loader api test */ | 
|---|
| 619 |  | 
|---|
| 620 |  | 
|---|
| 621 | #ifdef __cplusplus | 
|---|
| 622 | } /* extern "C" */ | 
|---|
| 623 | #endif | 
|---|
| 624 |  | 
|---|
| 625 | #endif | 
|---|