[5118] | 1 | /* $Id: k32QueryOptionsStatus.cpp,v 1.7 2001-02-11 23:43:00 bird Exp $
|
---|
[4164] | 2 | *
|
---|
| 3 | * k32QueryOptionsStatus - Queries the options and/or the status of
|
---|
| 4 | * Win32k.sys driver.
|
---|
| 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 FOR_EXEHDR 1 /* To make all object flags OBJ???. */
|
---|
| 17 | #define INCL_DOSMEMMGR
|
---|
| 18 | #define INCL_DOSERRORS
|
---|
| 19 |
|
---|
| 20 | #define INCL_OS2KRNL_TK
|
---|
| 21 | #define INCL_OS2KRNL_SEM
|
---|
[5086] | 22 | #define INCL_OS2KRNL_LDR
|
---|
[4164] | 23 |
|
---|
| 24 | #define NO_WIN32K_LIB_FUNCTIONS
|
---|
| 25 |
|
---|
| 26 | /*******************************************************************************
|
---|
| 27 | * Header Files *
|
---|
| 28 | *******************************************************************************/
|
---|
| 29 | #include <os2.h> /* OS/2 header file. */
|
---|
| 30 | #include <peexe.h> /* Wine PE structs and definitions. */
|
---|
| 31 | #include <neexe.h> /* Wine NE structs and definitions. */
|
---|
| 32 | #include <newexe.h> /* OS/2 NE structs and definitions. */
|
---|
| 33 | #include <exe386.h> /* OS/2 LX structs and definitions. */
|
---|
| 34 |
|
---|
| 35 | #include "devSegDf.h" /* Win32k segment definitions. */
|
---|
| 36 |
|
---|
| 37 | #include "malloc.h" /* win32k malloc (resident). Not C library! */
|
---|
| 38 | #include "smalloc.h" /* win32k swappable heap. */
|
---|
| 39 | #include "rmalloc.h" /* win32k resident heap. */
|
---|
| 40 |
|
---|
| 41 | #include <string.h> /* C library string.h. */
|
---|
| 42 | #include <stdlib.h> /* C library stdlib.h. */
|
---|
| 43 | #include <stddef.h> /* C library stddef.h. */
|
---|
| 44 | #include <stdarg.h> /* C library stdarg.h. */
|
---|
| 45 |
|
---|
| 46 | #include "vprintf.h" /* win32k printf and vprintf. Not C library! */
|
---|
| 47 | #include "dev1632.h" /* Common 16- and 32-bit parts */
|
---|
| 48 | #include "dev32.h" /* 32-Bit part of the device driver. (SSToDS) */
|
---|
| 49 | #include "OS2Krnl.h" /* kernel structs. (SFN) */
|
---|
| 50 | #include "log.h" /* Logging. */
|
---|
| 51 | #include "avl.h" /* AVL tree. (ldr.h need it) */
|
---|
| 52 | #include "ldr.h" /* ldr helpers. (ldrGetExePath) */
|
---|
| 53 | #include "env.h" /* Environment helpers. */
|
---|
| 54 | #include "modulebase.h" /* ModuleBase class definitions, ++. */
|
---|
| 55 | #include "pe2lx.h" /* Pe2Lx class definitions, ++. */
|
---|
| 56 | #include <versionos2.h> /* Pe2Lx version. */
|
---|
| 57 | #include "options.h" /* Win32k options. */
|
---|
| 58 |
|
---|
| 59 | #include "ProbKrnl.h" /* ProbKrnl variables and definitions. */
|
---|
| 60 | #include "win32k.h" /* Win32k API structures. */
|
---|
| 61 | #include "k32.h" /* Internal Win32k API structures. */
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | /**
|
---|
| 65 | * Queries the options and/or the status of Win32k.sys driver.
|
---|
| 66 | * @returns OS2 returncode.
|
---|
| 67 | * @param pOptions Pointer to options structure. (NULL is allowed)
|
---|
| 68 | * @param pStatus Pointer to status structure. (NULL is allowed)
|
---|
| 69 | * @status completely implelemented.
|
---|
| 70 | * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
| 71 | * @remark One of the pointer may be NULL.
|
---|
| 72 | */
|
---|
| 73 | APIRET k32QueryOptionsStatus(PK32OPTIONS pOptions, PK32STATUS pStatus)
|
---|
| 74 | {
|
---|
| 75 | APIRET rc;
|
---|
| 76 | ULONG cb;
|
---|
| 77 |
|
---|
| 78 | /*
|
---|
| 79 | * Validate parameters.
|
---|
| 80 | * Ensure that the buffer pointer is sensible.
|
---|
| 81 | * Ensure that the structure sizes are correct.
|
---|
| 82 | */
|
---|
| 83 | if (((ULONG)pOptions < 0x10000 && pOptions != NULL)
|
---|
| 84 | ||
|
---|
| 85 | ((ULONG)pStatus < 0x10000 && pStatus != NULL)
|
---|
| 86 | ||
|
---|
| 87 | (pOptions == NULL && pStatus == NULL)
|
---|
| 88 | )
|
---|
| 89 | rc = ERROR_INVALID_PARAMETER;
|
---|
| 90 |
|
---|
| 91 | if (pOptions != NULL)
|
---|
| 92 | {
|
---|
| 93 | rc = TKFuULongNF(SSToDS(&cb), &pOptions->cb);
|
---|
| 94 | if (rc)
|
---|
| 95 | return rc;
|
---|
| 96 | if (cb != sizeof(K32OPTIONS))
|
---|
| 97 | return ERROR_INVALID_PARAMETER;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | if (pStatus != NULL)
|
---|
| 101 | {
|
---|
| 102 | rc = TKFuULongNF(SSToDS(&cb), &pStatus->cb);
|
---|
| 103 | if (rc)
|
---|
| 104 | return rc;
|
---|
| 105 | if (cb != sizeof(K32STATUS))
|
---|
| 106 | return ERROR_INVALID_PARAMETER;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 | /*
|
---|
| 111 | * Take loader semaphore. (We might accessing LDR structures.)
|
---|
| 112 | */
|
---|
| 113 | rc = LDRRequestSem();
|
---|
| 114 | if (rc != NO_ERROR)
|
---|
| 115 | {
|
---|
| 116 | kprintf(("k32QueryOptionsStatus: LDRRequestSem failed with rc = %d\n", rc));
|
---|
| 117 | return rc;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | /*
|
---|
| 121 | * Get options.
|
---|
| 122 | */
|
---|
| 123 | if (pOptions)
|
---|
| 124 | {
|
---|
| 125 | K32OPTIONS TmpOptions;
|
---|
| 126 |
|
---|
| 127 | TmpOptions.cb = sizeof(K32OPTIONS);
|
---|
| 128 | TmpOptions.usCom = options.usCom;
|
---|
| 129 | TmpOptions.fLogging = options.fLogging;
|
---|
| 130 | TmpOptions.fPE = options.fPE;
|
---|
[5051] | 131 | TmpOptions.fPEOneObject = options.fPEOneObject;
|
---|
[4164] | 132 | TmpOptions.ulInfoLevel = options.ulInfoLevel;
|
---|
| 133 | TmpOptions.fElf = options.fElf;
|
---|
| 134 | TmpOptions.fUNIXScript = options.fUNIXScript;
|
---|
| 135 | TmpOptions.fREXXScript = options.fREXXScript;
|
---|
| 136 | TmpOptions.fJava = options.fJava;
|
---|
| 137 | TmpOptions.fNoLoader = options.fNoLoader;
|
---|
[4774] | 138 | TmpOptions.fDllFixes = options.fDllFixes;
|
---|
[5118] | 139 | TmpOptions.fExeFixes = options.fExeFixes;
|
---|
| 140 | TmpOptions.fForcePreload= options.fForcePreload;
|
---|
| 141 | TmpOptions.fApiEnh = options.fApiEnh;
|
---|
[4164] | 142 | TmpOptions.cbSwpHeapMax = options.cbSwpHeapMax;
|
---|
| 143 | TmpOptions.cbResHeapMax = options.cbResHeapMax;
|
---|
| 144 |
|
---|
| 145 | rc = TKSuBuff(pOptions, SSToDS(&TmpOptions), sizeof(K32OPTIONS), TK_FUSU_NONFATAL);
|
---|
| 146 | if (rc != NO_ERROR) /* retry once if we fail. (For some reason it seems to work.) */
|
---|
| 147 | rc = TKSuBuff(pOptions, SSToDS(&TmpOptions), sizeof(K32OPTIONS), TK_FUSU_NONFATAL);
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | /*
|
---|
| 151 | * Get status.
|
---|
| 152 | */
|
---|
| 153 | if (rc == NO_ERROR && pStatus)
|
---|
| 154 | {
|
---|
| 155 | K32STATUS TmpStatus;
|
---|
| 156 | HEAPSTATE HeapState;
|
---|
| 157 |
|
---|
| 158 | /* initate the temporary structure */
|
---|
[4185] | 159 | memset(SSToDS(&TmpStatus), 0, sizeof(K32STATUS));
|
---|
[4164] | 160 | TmpStatus.cb = sizeof(K32STATUS);
|
---|
| 161 |
|
---|
| 162 | /* options */
|
---|
| 163 | TmpStatus.fQuiet = options.fQuiet;
|
---|
| 164 | TmpStatus.fKernel = options.fKernel; /* Smp or uni kernel. */
|
---|
| 165 | TmpStatus.ulBuild = options.ulBuild; /* Kernel build. */
|
---|
| 166 | TmpStatus.usVerMajor = options.usVerMajor; /* OS/2 major ver - 20 */
|
---|
| 167 | TmpStatus.usVerMinor = options.usVerMinor; /* OS/2 minor ver - 30,40 */
|
---|
| 168 |
|
---|
| 169 | /* swappable heap */
|
---|
| 170 | if (_swp_state((PHEAPSTATE)SSToDS(&HeapState)) == 0)
|
---|
| 171 | {
|
---|
| 172 | TmpStatus.cbSwpHeapInit = options.cbSwpHeapInit; /* Initial heapsize. */
|
---|
| 173 | TmpStatus.cbSwpHeapFree = HeapState.cbHeapFree; /* Amount of used space. */
|
---|
| 174 | TmpStatus.cbSwpHeapUsed = HeapState.cbHeapUsed; /* Amount of free space reserved. */
|
---|
| 175 | TmpStatus.cbSwpHeapSize = HeapState.cbHeapSize; /* Amount of memory used by the heap free and used++. */
|
---|
| 176 | TmpStatus.cSwpBlocksUsed = HeapState.cBlocksUsed; /* Count of used blocks. */
|
---|
| 177 | TmpStatus.cSwpBlocksFree = HeapState.cBlocksFree; /* Count of free blocks. */
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | /* resident heap */
|
---|
| 181 | if (_res_state((PHEAPSTATE)SSToDS(&HeapState)) == 0)
|
---|
| 182 | {
|
---|
| 183 | TmpStatus.cbResHeapInit = options.cbResHeapInit; /* Initial heapsize. */
|
---|
| 184 | TmpStatus.cbResHeapFree = HeapState.cbHeapFree; /* Amount of used space. */
|
---|
| 185 | TmpStatus.cbResHeapUsed = HeapState.cbHeapUsed; /* Amount of free space reserved. */
|
---|
| 186 | TmpStatus.cbResHeapSize = HeapState.cbHeapSize; /* Amount of memory used by the heap free and used++. */
|
---|
| 187 | TmpStatus.cResBlocksUsed = HeapState.cBlocksUsed; /* Count of used blocks. */
|
---|
| 188 | TmpStatus.cResBlocksFree = HeapState.cBlocksFree; /* Count of free blocks. */
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | /* Win32k Build and version; and symfile name or SymDB. */
|
---|
[4185] | 192 | strcpy((char*)SSToDS(TmpStatus.szBuildDate), szBuildDate); /* Date of the win32k build. */
|
---|
| 193 | strcpy((char*)SSToDS(TmpStatus.szBuildTime), szBuildTime); /* Time of the win32k build. */
|
---|
[4164] | 194 | TmpStatus.ulVersion = PE2LX_VERSION; /* Win32k version */
|
---|
[4185] | 195 | strcpy((char*)SSToDS(TmpStatus.szSymFile), szSymbolFile); /* The name of the symbol file or sym database. */
|
---|
[4164] | 196 |
|
---|
| 197 | /* Module counts */
|
---|
| 198 | TmpStatus.cPe2LxModules = Pe2Lx::getLoadedModuleCount();/* Number of Pe2Lx modules currently loaded. */
|
---|
| 199 | TmpStatus.cElf2LxModules = /*Elf2Lx::getLoadedModuleCount()*/ 0; /* Number of Elf2Lx modules currently loaded. */
|
---|
| 200 |
|
---|
| 201 | rc = TKSuBuff(pStatus, SSToDS(&TmpStatus), sizeof(K32STATUS), TK_FUSU_NONFATAL);
|
---|
| 202 | if (rc != NO_ERROR) /* retry once if we fail. (For some reason it seems to work.) */
|
---|
| 203 | rc = TKSuBuff(pStatus, SSToDS(&TmpStatus), sizeof(K32STATUS), TK_FUSU_NONFATAL);
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | /*
|
---|
| 207 | * Release loader semaphore and return.
|
---|
| 208 | */
|
---|
| 209 | LDRClearSem();
|
---|
| 210 |
|
---|
| 211 | return rc;
|
---|
| 212 | }
|
---|
| 213 |
|
---|