[5086] | 1 | /* $Id: myldrRead.cpp,v 1.9 2001-02-10 11:11:47 bird Exp $
|
---|
[847] | 2 | *
|
---|
[2501] | 3 | * myldrRead - ldrRead.
|
---|
[847] | 4 | *
|
---|
[4164] | 5 | * Copyright (c) 1998-2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
[847] | 6 | *
|
---|
[1678] | 7 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 8 | *
|
---|
[847] | 9 | */
|
---|
| 10 |
|
---|
| 11 | /*******************************************************************************
|
---|
| 12 | * Defined Constants And Macros *
|
---|
| 13 | *******************************************************************************/
|
---|
| 14 | #define INCL_DOSERRORS
|
---|
| 15 | #define INCL_NOPMAPI
|
---|
[5086] | 16 | #define INCL_OS2KRNL_LDR
|
---|
[847] | 17 |
|
---|
| 18 | /*******************************************************************************
|
---|
| 19 | * Header Files *
|
---|
| 20 | *******************************************************************************/
|
---|
| 21 | #include <os2.h>
|
---|
| 22 |
|
---|
[1273] | 23 | #include <memory.h>
|
---|
| 24 | #include <stdlib.h>
|
---|
| 25 |
|
---|
[4164] | 26 | #include "devSegDf.h" /* Win32k segment definitions. */
|
---|
[847] | 27 | #include "log.h"
|
---|
[4164] | 28 | #include "avl.h"
|
---|
[847] | 29 | #include "dev32.h"
|
---|
[1273] | 30 | #include <peexe.h>
|
---|
| 31 | #include <exe386.h>
|
---|
| 32 | #include "OS2Krnl.h"
|
---|
[4164] | 33 | #include "ldr.h"
|
---|
[1678] | 34 | #include "ModuleBase.h"
|
---|
[1273] | 35 | #include "pe2lx.h"
|
---|
[847] | 36 |
|
---|
| 37 |
|
---|
[4164] | 38 | /**
|
---|
| 39 | * Overloads ldrRead.
|
---|
| 40 | * @returns OS/2 return code.
|
---|
| 41 | * @param hFile Filehandle to read from.
|
---|
| 42 | * @param pvBuffer Buffer to read into.
|
---|
| 43 | * @param fpBuffer This is not flags as I first though, but probably a far 16-bit pointer
|
---|
| 44 | * to the buffer.
|
---|
| 45 | * @param cbToRead Count of bytes to read.
|
---|
| 46 | * @param pMTE
|
---|
| 47 | * @sketch IF it's our module THEN
|
---|
| 48 | * Get module pointer. (complain if this failes and backout to ldrRead.)
|
---|
| 49 | * Currently - verify that it's a Pe2Lx module. (complain and fail if not.)
|
---|
| 50 | * Invoke the read method of the module do the requested read operation.
|
---|
| 51 | * Save pMTE if present and not save allready.
|
---|
| 52 | * ENDIF
|
---|
| 53 | * - backout or not our module -
|
---|
| 54 | * forward request to the original ldrRead.
|
---|
| 55 | * @status Completely implemented.
|
---|
[4787] | 56 | * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
[4164] | 57 | */
|
---|
[847] | 58 | ULONG LDRCALL myldrRead(
|
---|
[4164] | 59 | SFN hFile,
|
---|
| 60 | ULONG ulOffset,
|
---|
| 61 | PVOID pvBuffer,
|
---|
| 62 | ULONG fpBuffer,
|
---|
| 63 | ULONG cbToRead,
|
---|
| 64 | PMTE pMTE
|
---|
| 65 | )
|
---|
[847] | 66 | {
|
---|
| 67 | ULONG rc;
|
---|
| 68 |
|
---|
[1273] | 69 | /* Check if this is an overrided handle */
|
---|
| 70 | if (GetState(hFile) == HSTATE_OUR)
|
---|
[847] | 71 | {
|
---|
[1467] | 72 | PMODULE pMod;
|
---|
[4164] | 73 | kprintf(("myldrRead: hF=%+04x off=%+08x pB=%+08x fp=%+08x cb=%+04x pMTE=%+08x\n",
|
---|
| 74 | hFile, ulOffset, pvBuffer, fpBuffer, cbToRead, pMTE));
|
---|
[1273] | 75 |
|
---|
[1467] | 76 | pMod = getModuleBySFN(hFile);
|
---|
| 77 | if (pMod != NULL)
|
---|
[847] | 78 | {
|
---|
| 79 | /* I would love to have a pointer to the MTE */
|
---|
[1467] | 80 | if (pMod->pMTE == NULL && pMTE != NULL)
|
---|
[2501] | 81 | pMod->pMTE = pMTE;
|
---|
[847] | 82 |
|
---|
[1467] | 83 | if ((pMod->fFlags & MOD_TYPE_MASK) == MOD_TYPE_PE2LX)
|
---|
[4164] | 84 | rc = pMod->Data.pModule->read(ulOffset, pvBuffer, fpBuffer, cbToRead, pMTE);
|
---|
[1467] | 85 | else
|
---|
| 86 | {
|
---|
[4164] | 87 | kprintf(("myldrRead: Invalid module type, %#x\n", pMod->fFlags & MOD_TYPE_MASK));
|
---|
[1467] | 88 | rc = ERROR_READ_FAULT;
|
---|
| 89 | }
|
---|
[847] | 90 | }
|
---|
| 91 | else
|
---|
[4164] | 92 | {
|
---|
| 93 | kprintf(("myldrRead: DON'T PANIC! - but I can't get Node ptr! - This is really an IPE!\n"));
|
---|
| 94 | rc = ERROR_READ_FAULT;
|
---|
| 95 | }
|
---|
[847] | 96 | }
|
---|
[4164] | 97 | else
|
---|
| 98 | {
|
---|
| 99 | rc = ldrRead(hFile, ulOffset, pvBuffer, fpBuffer, cbToRead, pMTE);
|
---|
| 100 | }
|
---|
[1467] | 101 | #if 0
|
---|
[4164] | 102 | kprintf(("myldrRead: hF=%+04x off=%+08x pB=%+08x fp=%+08x cb=%+04x pMTE=%+08x rc=%d\n",
|
---|
| 103 | hFile, ulOffset, pvBuffer, fpBuffer, cbToRead, pMTE, rc));
|
---|
[1467] | 104 | #endif
|
---|
[847] | 105 |
|
---|
| 106 | return rc;
|
---|
| 107 | }
|
---|