| 1 | /* $Id: k32QueryOTEs.cpp,v 1.3 2001-02-10 11:11:44 bird Exp $ | 
|---|
| 2 | * | 
|---|
| 3 | * k32QueryOTEs  -  Get's the object table entries (OTEs) for a given | 
|---|
| 4 | *                  module (given by a module handle). | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no) | 
|---|
| 7 | * | 
|---|
| 8 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 9 | * | 
|---|
| 10 | */ | 
|---|
| 11 |  | 
|---|
| 12 |  | 
|---|
| 13 | /******************************************************************************* | 
|---|
| 14 | *   Defined Constants And Macros                                               * | 
|---|
| 15 | *******************************************************************************/ | 
|---|
| 16 | #define INCL_DOSMEMMGR | 
|---|
| 17 | #define INCL_DOSERRORS | 
|---|
| 18 |  | 
|---|
| 19 | #define INCL_OS2KRNL_TK | 
|---|
| 20 | #define INCL_OS2KRNL_SEM | 
|---|
| 21 | #define INCL_OS2KRNL_LDR | 
|---|
| 22 |  | 
|---|
| 23 | #define NO_WIN32K_LIB_FUNCTIONS | 
|---|
| 24 |  | 
|---|
| 25 | /******************************************************************************* | 
|---|
| 26 | *   Header Files                                                               * | 
|---|
| 27 | *******************************************************************************/ | 
|---|
| 28 | #include <os2.h> | 
|---|
| 29 | #include "devSegDf.h"                   /* Win32k segment definitions. */ | 
|---|
| 30 | #include "OS2Krnl.h" | 
|---|
| 31 | #include "win32k.h" | 
|---|
| 32 | #include "k32.h" | 
|---|
| 33 | #include "options.h" | 
|---|
| 34 | #include "dev32.h" | 
|---|
| 35 | #include "log.h" | 
|---|
| 36 |  | 
|---|
| 37 |  | 
|---|
| 38 | /** | 
|---|
| 39 | * Gets the object table entries for a module. | 
|---|
| 40 | * @returns     OS2 returncode. | 
|---|
| 41 | * @param       hMTE    Module handle (HMTE) of the module. | 
|---|
| 42 | * @param       pQOte   Pointer to output buffer. | 
|---|
| 43 | * @param       cbQOte  Size (in bytes) of the output buffer. | 
|---|
| 44 | * @status      completely implelemented. | 
|---|
| 45 | * @author      knut st. osmundsen (knut.stange.osmundsen@mynd.no) | 
|---|
| 46 | * @remark | 
|---|
| 47 | */ | 
|---|
| 48 | APIRET k32QueryOTEs(HMTE hMTE, PQOTEBUFFER pQOte, ULONG cbQOte) | 
|---|
| 49 | { | 
|---|
| 50 | APIRET  rc; | 
|---|
| 51 | PMTE    pMTE; | 
|---|
| 52 |  | 
|---|
| 53 | /* | 
|---|
| 54 | * Validate parameters. | 
|---|
| 55 | *  Ensure that the buffer pointer is sensible. | 
|---|
| 56 | *  Ensure that the buffer not less than minimum size. | 
|---|
| 57 | */ | 
|---|
| 58 | if ((ULONG)pQOte < 0x10000 || cbQOte < sizeof(QOTEBUFFER)) | 
|---|
| 59 | return ERROR_INVALID_PARAMETER; | 
|---|
| 60 |  | 
|---|
| 61 | /* | 
|---|
| 62 | * Take loader semaphore. (We are accessing LDR structures.) | 
|---|
| 63 | */ | 
|---|
| 64 | rc = LDRRequestSem(); | 
|---|
| 65 | if (rc != NO_ERROR) | 
|---|
| 66 | { | 
|---|
| 67 | kprintf(("k32QueryOTEs: LDRRequestSem failed with rc = %d\n", rc)); | 
|---|
| 68 | return rc; | 
|---|
| 69 | } | 
|---|
| 70 |  | 
|---|
| 71 | /* | 
|---|
| 72 | * Validate and get the MTE pointer. | 
|---|
| 73 | */ | 
|---|
| 74 | pMTE = ldrValidateMteHandle(hMTE); | 
|---|
| 75 | if (pMTE != NULL && pMTE->mte_swapmte != NULL) | 
|---|
| 76 | { | 
|---|
| 77 | /* | 
|---|
| 78 | * Copy data to the output buffer. | 
|---|
| 79 | * 1) First we'll copy the object number. | 
|---|
| 80 | *    If this failes or no object we'll bailout/return. | 
|---|
| 81 | * 2) Then we'll check if the buffer is large enough to hold the | 
|---|
| 82 | *    object info. | 
|---|
| 83 | * 3) Check if LX executable and copy the OTEs to the output buffer. | 
|---|
| 84 | *    If not LX fail. | 
|---|
| 85 | */ | 
|---|
| 86 | rc = TKSuULongNF(&pQOte->cOTEs, &pMTE->mte_swapmte->smte_objcnt); | 
|---|
| 87 | if (rc != NO_ERROR || pQOte->cOTEs == 0) | 
|---|
| 88 | goto bailout; | 
|---|
| 89 |  | 
|---|
| 90 | if ((pMTE->mte_swapmte->smte_objcnt * sizeof(QOTE)) + (sizeof(QOTEBUFFER) - sizeof(QOTE)) | 
|---|
| 91 | > cbQOte) | 
|---|
| 92 | { | 
|---|
| 93 | rc = ERROR_BUFFER_OVERFLOW; | 
|---|
| 94 | goto bailout; | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 | if (pMTE->mte_flags2 & MTEFORMATLX) | 
|---|
| 98 | { | 
|---|
| 99 | rc = TKSuBuff(pQOte->aOTE, | 
|---|
| 100 | pMTE->mte_swapmte->smte_objtab, | 
|---|
| 101 | pMTE->mte_swapmte->smte_objcnt * sizeof(OTE), | 
|---|
| 102 | TK_FUSU_NONFATAL); | 
|---|
| 103 | } | 
|---|
| 104 | else | 
|---|
| 105 | rc = ERROR_BAD_EXE_FORMAT; | 
|---|
| 106 | } | 
|---|
| 107 | else | 
|---|
| 108 | rc = ERROR_INVALID_HANDLE; | 
|---|
| 109 |  | 
|---|
| 110 | bailout: | 
|---|
| 111 | /* | 
|---|
| 112 | * Felease loader semaphore and return | 
|---|
| 113 | */ | 
|---|
| 114 | LDRClearSem(); | 
|---|
| 115 |  | 
|---|
| 116 | return rc; | 
|---|
| 117 | } | 
|---|
| 118 |  | 
|---|