1 | /* $Id: k32QueryOptionsStatus.cpp,v 1.3 2000-09-04 16:40:50 bird Exp $
|
---|
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
|
---|
22 |
|
---|
23 | #define NO_WIN32K_LIB_FUNCTIONS
|
---|
24 |
|
---|
25 | /*******************************************************************************
|
---|
26 | * Header Files *
|
---|
27 | *******************************************************************************/
|
---|
28 | #include <os2.h> /* OS/2 header file. */
|
---|
29 | #include <peexe.h> /* Wine PE structs and definitions. */
|
---|
30 | #include <neexe.h> /* Wine NE structs and definitions. */
|
---|
31 | #include <newexe.h> /* OS/2 NE structs and definitions. */
|
---|
32 | #include <exe386.h> /* OS/2 LX structs and definitions. */
|
---|
33 |
|
---|
34 | #include "devSegDf.h" /* Win32k segment definitions. */
|
---|
35 |
|
---|
36 | #include "malloc.h" /* win32k malloc (resident). Not C library! */
|
---|
37 | #include "smalloc.h" /* win32k swappable heap. */
|
---|
38 | #include "rmalloc.h" /* win32k resident heap. */
|
---|
39 |
|
---|
40 | #include <string.h> /* C library string.h. */
|
---|
41 | #include <stdlib.h> /* C library stdlib.h. */
|
---|
42 | #include <stddef.h> /* C library stddef.h. */
|
---|
43 | #include <stdarg.h> /* C library stdarg.h. */
|
---|
44 |
|
---|
45 | #include "vprintf.h" /* win32k printf and vprintf. Not C library! */
|
---|
46 | #include "dev1632.h" /* Common 16- and 32-bit parts */
|
---|
47 | #include "dev32.h" /* 32-Bit part of the device driver. (SSToDS) */
|
---|
48 | #include "OS2Krnl.h" /* kernel structs. (SFN) */
|
---|
49 | #include "ldrCalls.h" /* ldr* calls. (ldrRead) */
|
---|
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;
|
---|
131 | TmpOptions.ulInfoLevel = options.ulInfoLevel;
|
---|
132 | TmpOptions.fElf = options.fElf;
|
---|
133 | TmpOptions.fUNIXScript = options.fUNIXScript;
|
---|
134 | TmpOptions.fREXXScript = options.fREXXScript;
|
---|
135 | TmpOptions.fJava = options.fJava;
|
---|
136 | TmpOptions.fNoLoader = options.fNoLoader;
|
---|
137 | TmpOptions.cbSwpHeapMax = options.cbSwpHeapMax;
|
---|
138 | TmpOptions.cbResHeapMax = options.cbResHeapMax;
|
---|
139 |
|
---|
140 | rc = TKSuBuff(pOptions, SSToDS(&TmpOptions), sizeof(K32OPTIONS), TK_FUSU_NONFATAL);
|
---|
141 | if (rc != NO_ERROR) /* retry once if we fail. (For some reason it seems to work.) */
|
---|
142 | rc = TKSuBuff(pOptions, SSToDS(&TmpOptions), sizeof(K32OPTIONS), TK_FUSU_NONFATAL);
|
---|
143 | }
|
---|
144 |
|
---|
145 | /*
|
---|
146 | * Get status.
|
---|
147 | */
|
---|
148 | if (rc == NO_ERROR && pStatus)
|
---|
149 | {
|
---|
150 | K32STATUS TmpStatus;
|
---|
151 | HEAPSTATE HeapState;
|
---|
152 |
|
---|
153 | /* initate the temporary structure */
|
---|
154 | memset(SSToDS(&TmpStatus), 0, sizeof(K32STATUS));
|
---|
155 | TmpStatus.cb = sizeof(K32STATUS);
|
---|
156 |
|
---|
157 | /* options */
|
---|
158 | TmpStatus.fQuiet = options.fQuiet;
|
---|
159 | TmpStatus.fKernel = options.fKernel; /* Smp or uni kernel. */
|
---|
160 | TmpStatus.ulBuild = options.ulBuild; /* Kernel build. */
|
---|
161 | TmpStatus.usVerMajor = options.usVerMajor; /* OS/2 major ver - 20 */
|
---|
162 | TmpStatus.usVerMinor = options.usVerMinor; /* OS/2 minor ver - 30,40 */
|
---|
163 |
|
---|
164 | /* swappable heap */
|
---|
165 | if (_swp_state((PHEAPSTATE)SSToDS(&HeapState)) == 0)
|
---|
166 | {
|
---|
167 | TmpStatus.cbSwpHeapInit = options.cbSwpHeapInit; /* Initial heapsize. */
|
---|
168 | TmpStatus.cbSwpHeapFree = HeapState.cbHeapFree; /* Amount of used space. */
|
---|
169 | TmpStatus.cbSwpHeapUsed = HeapState.cbHeapUsed; /* Amount of free space reserved. */
|
---|
170 | TmpStatus.cbSwpHeapSize = HeapState.cbHeapSize; /* Amount of memory used by the heap free and used++. */
|
---|
171 | TmpStatus.cSwpBlocksUsed = HeapState.cBlocksUsed; /* Count of used blocks. */
|
---|
172 | TmpStatus.cSwpBlocksFree = HeapState.cBlocksFree; /* Count of free blocks. */
|
---|
173 | }
|
---|
174 |
|
---|
175 | /* resident heap */
|
---|
176 | if (_res_state((PHEAPSTATE)SSToDS(&HeapState)) == 0)
|
---|
177 | {
|
---|
178 | TmpStatus.cbResHeapInit = options.cbResHeapInit; /* Initial heapsize. */
|
---|
179 | TmpStatus.cbResHeapFree = HeapState.cbHeapFree; /* Amount of used space. */
|
---|
180 | TmpStatus.cbResHeapUsed = HeapState.cbHeapUsed; /* Amount of free space reserved. */
|
---|
181 | TmpStatus.cbResHeapSize = HeapState.cbHeapSize; /* Amount of memory used by the heap free and used++. */
|
---|
182 | TmpStatus.cResBlocksUsed = HeapState.cBlocksUsed; /* Count of used blocks. */
|
---|
183 | TmpStatus.cResBlocksFree = HeapState.cBlocksFree; /* Count of free blocks. */
|
---|
184 | }
|
---|
185 |
|
---|
186 | /* Win32k Build and version; and symfile name or SymDB. */
|
---|
187 | strcpy((char*)SSToDS(TmpStatus.szBuildDate), szBuildDate); /* Date of the win32k build. */
|
---|
188 | strcpy((char*)SSToDS(TmpStatus.szBuildTime), szBuildTime); /* Time of the win32k build. */
|
---|
189 | TmpStatus.ulVersion = PE2LX_VERSION; /* Win32k version */
|
---|
190 | strcpy((char*)SSToDS(TmpStatus.szSymFile), szSymbolFile); /* The name of the symbol file or sym database. */
|
---|
191 |
|
---|
192 | /* Module counts */
|
---|
193 | TmpStatus.cPe2LxModules = Pe2Lx::getLoadedModuleCount();/* Number of Pe2Lx modules currently loaded. */
|
---|
194 | TmpStatus.cElf2LxModules = /*Elf2Lx::getLoadedModuleCount()*/ 0; /* Number of Elf2Lx modules currently loaded. */
|
---|
195 |
|
---|
196 | rc = TKSuBuff(pStatus, SSToDS(&TmpStatus), sizeof(K32STATUS), TK_FUSU_NONFATAL);
|
---|
197 | if (rc != NO_ERROR) /* retry once if we fail. (For some reason it seems to work.) */
|
---|
198 | rc = TKSuBuff(pStatus, SSToDS(&TmpStatus), sizeof(K32STATUS), TK_FUSU_NONFATAL);
|
---|
199 | }
|
---|
200 |
|
---|
201 | /*
|
---|
202 | * Release loader semaphore and return.
|
---|
203 | */
|
---|
204 | LDRClearSem();
|
---|
205 |
|
---|
206 | return rc;
|
---|
207 | }
|
---|
208 |
|
---|