| 1 | /* $Id: myldrRead.cpp,v 1.8 2000-12-11 06:53:53 bird Exp $
|
|---|
| 2 | *
|
|---|
| 3 | * myldrRead - ldrRead.
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright (c) 1998-2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
|---|
| 6 | *
|
|---|
| 7 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 8 | *
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | /*******************************************************************************
|
|---|
| 12 | * Defined Constants And Macros *
|
|---|
| 13 | *******************************************************************************/
|
|---|
| 14 | #define INCL_DOSERRORS
|
|---|
| 15 | #define INCL_NOPMAPI
|
|---|
| 16 |
|
|---|
| 17 | /*******************************************************************************
|
|---|
| 18 | * Header Files *
|
|---|
| 19 | *******************************************************************************/
|
|---|
| 20 | #include <os2.h>
|
|---|
| 21 |
|
|---|
| 22 | #include <memory.h>
|
|---|
| 23 | #include <stdlib.h>
|
|---|
| 24 |
|
|---|
| 25 | #include "devSegDf.h" /* Win32k segment definitions. */
|
|---|
| 26 | #include "log.h"
|
|---|
| 27 | #include "avl.h"
|
|---|
| 28 | #include "dev32.h"
|
|---|
| 29 | #include <peexe.h>
|
|---|
| 30 | #include <exe386.h>
|
|---|
| 31 | #include "OS2Krnl.h"
|
|---|
| 32 | #include "ldrCalls.h"
|
|---|
| 33 | #include "ldr.h"
|
|---|
| 34 | #include "ModuleBase.h"
|
|---|
| 35 | #include "pe2lx.h"
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 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.
|
|---|
| 56 | * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
|---|
| 57 | */
|
|---|
| 58 | ULONG LDRCALL myldrRead(
|
|---|
| 59 | SFN hFile,
|
|---|
| 60 | ULONG ulOffset,
|
|---|
| 61 | PVOID pvBuffer,
|
|---|
| 62 | ULONG fpBuffer,
|
|---|
| 63 | ULONG cbToRead,
|
|---|
| 64 | PMTE pMTE
|
|---|
| 65 | )
|
|---|
| 66 | {
|
|---|
| 67 | ULONG rc;
|
|---|
| 68 |
|
|---|
| 69 | /* Check if this is an overrided handle */
|
|---|
| 70 | if (GetState(hFile) == HSTATE_OUR)
|
|---|
| 71 | {
|
|---|
| 72 | PMODULE pMod;
|
|---|
| 73 | kprintf(("myldrRead: hF=%+04x off=%+08x pB=%+08x fp=%+08x cb=%+04x pMTE=%+08x\n",
|
|---|
| 74 | hFile, ulOffset, pvBuffer, fpBuffer, cbToRead, pMTE));
|
|---|
| 75 |
|
|---|
| 76 | pMod = getModuleBySFN(hFile);
|
|---|
| 77 | if (pMod != NULL)
|
|---|
| 78 | {
|
|---|
| 79 | /* I would love to have a pointer to the MTE */
|
|---|
| 80 | if (pMod->pMTE == NULL && pMTE != NULL)
|
|---|
| 81 | pMod->pMTE = pMTE;
|
|---|
| 82 |
|
|---|
| 83 | if ((pMod->fFlags & MOD_TYPE_MASK) == MOD_TYPE_PE2LX)
|
|---|
| 84 | rc = pMod->Data.pModule->read(ulOffset, pvBuffer, fpBuffer, cbToRead, pMTE);
|
|---|
| 85 | else
|
|---|
| 86 | {
|
|---|
| 87 | kprintf(("myldrRead: Invalid module type, %#x\n", pMod->fFlags & MOD_TYPE_MASK));
|
|---|
| 88 | rc = ERROR_READ_FAULT;
|
|---|
| 89 | }
|
|---|
| 90 | }
|
|---|
| 91 | else
|
|---|
| 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 | }
|
|---|
| 96 | }
|
|---|
| 97 | else
|
|---|
| 98 | {
|
|---|
| 99 | rc = ldrRead(hFile, ulOffset, pvBuffer, fpBuffer, cbToRead, pMTE);
|
|---|
| 100 | }
|
|---|
| 101 | #if 0
|
|---|
| 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));
|
|---|
| 104 | #endif
|
|---|
| 105 |
|
|---|
| 106 | return rc;
|
|---|
| 107 | }
|
|---|