VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/nt/initterm-r0drv-nt.cpp@ 70204

Last change on this file since 70204 was 70157, checked in by vboxsync, 7 years ago

iprt/r0drv/nt: Fixing NT4, broke it just now.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 20.3 KB
Line 
1/* $Id: initterm-r0drv-nt.cpp 70157 2017-12-15 16:18:28Z vboxsync $ */
2/** @file
3 * IPRT - Initialization & Termination, R0 Driver, NT.
4 */
5
6/*
7 * Copyright (C) 2006-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include "the-nt-kernel.h"
32#include <iprt/asm-amd64-x86.h>
33#include <iprt/dbg.h>
34#include <iprt/err.h>
35#include <iprt/string.h>
36#include "internal/initterm.h"
37#include "internal-r0drv-nt.h"
38#include "symdb.h"
39#include "symdbdata.h"
40
41
42/*********************************************************************************************************************************
43* Global Variables *
44*********************************************************************************************************************************/
45/** ExAllocatePoolWithTag, introduced in W2K. */
46decltype(ExAllocatePoolWithTag) *g_pfnrtExAllocatePoolWithTag;
47/** ExFreePoolWithTag, introduced in W2K. */
48decltype(ExFreePoolWithTag) *g_pfnrtExFreePoolWithTag;
49/** ExSetTimerResolution, introduced in W2K. */
50PFNMYEXSETTIMERRESOLUTION g_pfnrtNtExSetTimerResolution;
51/** KeFlushQueuedDpcs, introduced in XP. */
52PFNMYKEFLUSHQUEUEDDPCS g_pfnrtNtKeFlushQueuedDpcs;
53/** HalRequestIpi, version introduced with windows 7. */
54PFNHALREQUESTIPI_W7PLUS g_pfnrtHalRequestIpiW7Plus;
55/** HalRequestIpi, version valid up to windows vista?? */
56PFNHALREQUESTIPI_PRE_W7 g_pfnrtHalRequestIpiPreW7;
57/** Worker for RTMpPokeCpu. */
58PFNRTSENDIPI g_pfnrtMpPokeCpuWorker;
59/** KeIpiGenericCall - Introduced in Windows Server 2003. */
60PFNRTKEIPIGENERICCALL g_pfnrtKeIpiGenericCall;
61/** KeSetTargetProcessorDpcEx - Introduced in Windows 7. */
62PFNKESETTARGETPROCESSORDPCEX g_pfnrtKeSetTargetProcessorDpcEx;
63/** KeInitializeAffinityEx - Introducted in Windows 7. */
64PFNKEINITIALIZEAFFINITYEX g_pfnrtKeInitializeAffinityEx;
65/** KeAddProcessorAffinityEx - Introducted in Windows 7. */
66PFNKEADDPROCESSORAFFINITYEX g_pfnrtKeAddProcessorAffinityEx;
67/** KeGetProcessorIndexFromNumber - Introducted in Windows 7. */
68PFNKEGETPROCESSORINDEXFROMNUMBER g_pfnrtKeGetProcessorIndexFromNumber;
69/** KeGetProcessorNumberFromIndex - Introducted in Windows 7. */
70PFNKEGETPROCESSORNUMBERFROMINDEX g_pfnrtKeGetProcessorNumberFromIndex;
71/** KeGetCurrentProcessorNumberEx - Introducted in Windows 7. */
72PFNKEGETCURRENTPROCESSORNUMBEREX g_pfnrtKeGetCurrentProcessorNumberEx;
73/** KeQueryActiveProcessors - Introducted in Windows 2000. */
74PFNKEQUERYACTIVEPROCESSORS g_pfnrtKeQueryActiveProcessors;
75/** KeQueryMaximumProcessorCount - Introducted in Vista and obsoleted W7. */
76PFNKEQUERYMAXIMUMPROCESSORCOUNT g_pfnrtKeQueryMaximumProcessorCount;
77/** KeQueryMaximumProcessorCountEx - Introducted in Windows 7. */
78PFNKEQUERYMAXIMUMPROCESSORCOUNTEX g_pfnrtKeQueryMaximumProcessorCountEx;
79/** KeQueryMaximumGroupCount - Introducted in Windows 7. */
80PFNKEQUERYMAXIMUMGROUPCOUNT g_pfnrtKeQueryMaximumGroupCount;
81/** KeQueryActiveProcessorCount - Introducted in Vista and obsoleted W7. */
82PFNKEQUERYACTIVEPROCESSORCOUNT g_pfnrtKeQueryActiveProcessorCount;
83/** KeQueryActiveProcessorCountEx - Introducted in Windows 7. */
84PFNKEQUERYACTIVEPROCESSORCOUNTEX g_pfnrtKeQueryActiveProcessorCountEx;
85/** KeQueryLogicalProcessorRelationship - Introducted in Windows 7. */
86PFNKEQUERYLOGICALPROCESSORRELATIONSHIP g_pfnrtKeQueryLogicalProcessorRelationship;
87/** KeRegisterProcessorChangeCallback - Introducted in Windows 7. */
88PFNKEREGISTERPROCESSORCHANGECALLBACK g_pfnrtKeRegisterProcessorChangeCallback;
89/** KeDeregisterProcessorChangeCallback - Introducted in Windows 7. */
90PFNKEDEREGISTERPROCESSORCHANGECALLBACK g_pfnrtKeDeregisterProcessorChangeCallback;
91/** Pointer to the MmProtectMdlSystemAddress kernel function if it's available.
92 * This API was introduced in XP. */
93decltype(MmProtectMdlSystemAddress) *g_pfnrtMmProtectMdlSystemAddress;
94/** MmAllocatePagesForMdl - Introduced in Windows 2000. */
95decltype(MmAllocatePagesForMdl) *g_pfnrtMmAllocatePagesForMdl;
96/** MmFreePagesFromMdl - Introduced in Windows 2000. */
97decltype(MmFreePagesFromMdl) *g_pfnrtMmFreePagesFromMdl;
98/** MmMapLockedPagesSpecifyCache - Introduced in Windows NT4 SP4. */
99decltype(MmMapLockedPagesSpecifyCache) *g_pfnrtMmMapLockedPagesSpecifyCache;
100/** MmAllocateContiguousMemorySpecifyCache - Introduced in Windows 2000. */
101decltype(MmAllocateContiguousMemorySpecifyCache) *g_pfnrtMmAllocateContiguousMemorySpecifyCache;
102/** RtlGetVersion, introduced in ??. */
103PFNRTRTLGETVERSION g_pfnrtRtlGetVersion;
104#ifndef RT_ARCH_AMD64
105/** KeQueryInterruptTime - exported/new in Windows 2000. */
106PFNRTKEQUERYINTERRUPTTIME g_pfnrtKeQueryInterruptTime;
107/** KeQuerySystemTime - exported/new in Windows 2000. */
108PFNRTKEQUERYSYSTEMTIME g_pfnrtKeQuerySystemTime;
109#endif
110/** KeQueryInterruptTimePrecise - new in Windows 8. */
111PFNRTKEQUERYINTERRUPTTIMEPRECISE g_pfnrtKeQueryInterruptTimePrecise;
112/** KeQuerySystemTimePrecise - new in Windows 8. */
113PFNRTKEQUERYSYSTEMTIMEPRECISE g_pfnrtKeQuerySystemTimePrecise;
114
115/** Offset of the _KPRCB::QuantumEnd field. 0 if not found. */
116uint32_t g_offrtNtPbQuantumEnd;
117/** Size of the _KPRCB::QuantumEnd field. 0 if not found. */
118uint32_t g_cbrtNtPbQuantumEnd;
119/** Offset of the _KPRCB::DpcQueueDepth field. 0 if not found. */
120uint32_t g_offrtNtPbDpcQueueDepth;
121
122/** The combined NT version, see RTNT_MAKE_VERSION. */
123uint32_t g_uRtNtVersion;
124/** The major version number. */
125uint8_t g_uRtNtMajorVer;
126/** The minor version number. */
127uint8_t g_uRtNtMinorVer;
128/** The build number. */
129uint32_t g_uRtNtBuildNo;
130
131/** Pointer to the MmHighestUserAddress kernel variable - can be NULL. */
132uintptr_t const *g_puRtMmHighestUserAddress;
133/** Pointer to the MmSystemRangeStart kernel variable - can be NULL. */
134uintptr_t const *g_puRtMmSystemRangeStart;
135
136
137/**
138 * Determines the NT kernel verison information.
139 *
140 * @param pOsVerInfo Where to return the version information.
141 *
142 * @remarks pOsVerInfo->fSmp is only definitive if @c true.
143 * @remarks pOsVerInfo->uCsdNo is set to MY_NIL_CSD if it cannot be determined.
144 */
145static void rtR0NtGetOsVersionInfo(PRTNTSDBOSVER pOsVerInfo)
146{
147 ULONG ulMajorVersion = 0;
148 ULONG ulMinorVersion = 0;
149 ULONG ulBuildNumber = 0;
150
151 pOsVerInfo->fChecked = PsGetVersion(&ulMajorVersion, &ulMinorVersion, &ulBuildNumber, NULL) == TRUE;
152 pOsVerInfo->uMajorVer = (uint8_t)ulMajorVersion;
153 pOsVerInfo->uMinorVer = (uint8_t)ulMinorVersion;
154 pOsVerInfo->uBuildNo = ulBuildNumber;
155#define MY_NIL_CSD 0x3f
156 pOsVerInfo->uCsdNo = MY_NIL_CSD;
157
158 if (g_pfnrtRtlGetVersion)
159 {
160 RTL_OSVERSIONINFOEXW VerInfo;
161 RT_ZERO(VerInfo);
162 VerInfo.dwOSVersionInfoSize = sizeof(VerInfo);
163
164 NTSTATUS rcNt = g_pfnrtRtlGetVersion(&VerInfo);
165 if (NT_SUCCESS(rcNt))
166 pOsVerInfo->uCsdNo = VerInfo.wServicePackMajor;
167 }
168
169 /* Note! We cannot quite say if something is MP or UNI. So, fSmp is
170 redefined to indicate that it must be MP.
171 Note! RTMpGetCount is not available here. */
172 pOsVerInfo->fSmp = ulMajorVersion >= 6; /* Vista and later has no UNI kernel AFAIK. */
173 if (!pOsVerInfo->fSmp)
174 {
175 if ( g_pfnrtKeQueryMaximumProcessorCountEx
176 && g_pfnrtKeQueryMaximumProcessorCountEx(ALL_PROCESSOR_GROUPS) > 1)
177 pOsVerInfo->fSmp = true;
178 else if ( g_pfnrtKeQueryMaximumProcessorCount
179 && g_pfnrtKeQueryMaximumProcessorCount() > 1)
180 pOsVerInfo->fSmp = true;
181 else if ( g_pfnrtKeQueryActiveProcessors
182 && g_pfnrtKeQueryActiveProcessors() > 1)
183 pOsVerInfo->fSmp = true;
184 else if (KeNumberProcessors > 1)
185 pOsVerInfo->fSmp = true;
186 }
187}
188
189
190/**
191 * Tries a set against the current kernel.
192 *
193 * @retval true if it matched up, global variables are updated.
194 * @retval false otherwise (no globals updated).
195 * @param pSet The data set.
196 * @param pbPrcb Pointer to the processor control block.
197 * @param pszVendor Pointer to the processor vendor string.
198 * @param pOsVerInfo The OS version info.
199 */
200static bool rtR0NtTryMatchSymSet(PCRTNTSDBSET pSet, uint8_t *pbPrcb, const char *pszVendor, PCRTNTSDBOSVER pOsVerInfo)
201{
202 /*
203 * Don't bother trying stuff where the NT kernel version number differs, or
204 * if the build type or SMPness doesn't match up.
205 */
206 if ( pSet->OsVerInfo.uMajorVer != pOsVerInfo->uMajorVer
207 || pSet->OsVerInfo.uMinorVer != pOsVerInfo->uMinorVer
208 || pSet->OsVerInfo.fChecked != pOsVerInfo->fChecked
209 || (!pSet->OsVerInfo.fSmp && pOsVerInfo->fSmp /*must-be-smp*/) )
210 {
211 //DbgPrint("IPRT: #%d Version/type mismatch.\n", pSet - &g_artNtSdbSets[0]);
212 return false;
213 }
214
215 /*
216 * Do the CPU vendor test.
217 *
218 * Note! The MmIsAddressValid call is the real #PF security here as the
219 * __try/__except has limited/no ability to catch everything we need.
220 */
221 char *pszPrcbVendorString = (char *)&pbPrcb[pSet->KPRCB.offVendorString];
222 if (!MmIsAddressValid(&pszPrcbVendorString[4 * 3 - 1]))
223 {
224 //DbgPrint("IPRT: #%d invalid vendor string address.\n", pSet - &g_artNtSdbSets[0]);
225 return false;
226 }
227 __try
228 {
229 if (memcmp(pszPrcbVendorString, pszVendor, RT_MIN(4 * 3, pSet->KPRCB.cbVendorString)) != 0)
230 {
231 //DbgPrint("IPRT: #%d Vendor string mismatch.\n", pSet - &g_artNtSdbSets[0]);
232 return false;
233 }
234 }
235 __except(EXCEPTION_EXECUTE_HANDLER)
236 {
237 DbgPrint("IPRT: %#d Exception\n", pSet - &g_artNtSdbSets[0]);
238 return false;
239 }
240
241 /*
242 * Got a match, update the global variables and report succcess.
243 */
244 g_offrtNtPbQuantumEnd = pSet->KPRCB.offQuantumEnd;
245 g_cbrtNtPbQuantumEnd = pSet->KPRCB.cbQuantumEnd;
246 g_offrtNtPbDpcQueueDepth = pSet->KPRCB.offDpcQueueDepth;
247
248#if 0
249 DbgPrint("IPRT: Using data set #%u for %u.%usp%u build %u %s %s.\n",
250 pSet - &g_artNtSdbSets[0],
251 pSet->OsVerInfo.uMajorVer,
252 pSet->OsVerInfo.uMinorVer,
253 pSet->OsVerInfo.uCsdNo,
254 pSet->OsVerInfo.uBuildNo,
255 pSet->OsVerInfo.fSmp ? "smp" : "uni",
256 pSet->OsVerInfo.fChecked ? "checked" : "free");
257#endif
258 return true;
259}
260
261
262DECLHIDDEN(int) rtR0InitNative(void)
263{
264 /*
265 * Initialize the function pointers.
266 */
267 RTDBGKRNLINFO hKrnlInfo;
268 int rc = RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0/*fFlags*/);
269 AssertRCReturn(rc, rc);
270
271#define GET_SYSTEM_ROUTINE_EX(a_Prf, a_Name, a_pfnType) \
272 do { RT_CONCAT3(g_pfnrt, a_Prf, a_Name) = (a_pfnType)RTR0DbgKrnlInfoGetSymbol(hKrnlInfo, NULL, #a_Name); } while (0)
273#define GET_SYSTEM_ROUTINE(a_Name) GET_SYSTEM_ROUTINE_EX(RT_NOTHING, a_Name, decltype(a_Name) *)
274#define GET_SYSTEM_ROUTINE_PRF(a_Prf,a_Name) GET_SYSTEM_ROUTINE_EX(a_Prf, a_Name, decltype(a_Name) *)
275#define GET_SYSTEM_ROUTINE_TYPE(a_Name, a_pfnType) GET_SYSTEM_ROUTINE_EX(RT_NOTHING, a_Name, a_pfnType)
276
277 GET_SYSTEM_ROUTINE(ExAllocatePoolWithTag);
278 GET_SYSTEM_ROUTINE(ExFreePoolWithTag);
279 GET_SYSTEM_ROUTINE_PRF(Nt,ExSetTimerResolution);
280 GET_SYSTEM_ROUTINE_PRF(Nt,KeFlushQueuedDpcs);
281 GET_SYSTEM_ROUTINE(KeIpiGenericCall);
282 GET_SYSTEM_ROUTINE(KeSetTargetProcessorDpcEx);
283 GET_SYSTEM_ROUTINE(KeInitializeAffinityEx);
284 GET_SYSTEM_ROUTINE(KeAddProcessorAffinityEx);
285 GET_SYSTEM_ROUTINE_TYPE(KeGetProcessorIndexFromNumber, PFNKEGETPROCESSORINDEXFROMNUMBER);
286 GET_SYSTEM_ROUTINE(KeGetProcessorNumberFromIndex);
287 GET_SYSTEM_ROUTINE_TYPE(KeGetCurrentProcessorNumberEx, PFNKEGETCURRENTPROCESSORNUMBEREX);
288 GET_SYSTEM_ROUTINE(KeQueryActiveProcessors);
289 GET_SYSTEM_ROUTINE(KeQueryMaximumProcessorCount);
290 GET_SYSTEM_ROUTINE(KeQueryMaximumProcessorCountEx);
291 GET_SYSTEM_ROUTINE(KeQueryMaximumGroupCount);
292 GET_SYSTEM_ROUTINE(KeQueryActiveProcessorCount);
293 GET_SYSTEM_ROUTINE(KeQueryActiveProcessorCountEx);
294 GET_SYSTEM_ROUTINE(KeQueryLogicalProcessorRelationship);
295 GET_SYSTEM_ROUTINE(KeRegisterProcessorChangeCallback);
296 GET_SYSTEM_ROUTINE(KeDeregisterProcessorChangeCallback);
297 GET_SYSTEM_ROUTINE(MmProtectMdlSystemAddress);
298 GET_SYSTEM_ROUTINE(MmAllocatePagesForMdl);
299 GET_SYSTEM_ROUTINE(MmFreePagesFromMdl);
300 GET_SYSTEM_ROUTINE(MmMapLockedPagesSpecifyCache);
301 GET_SYSTEM_ROUTINE(MmAllocateContiguousMemorySpecifyCache);
302
303 GET_SYSTEM_ROUTINE_TYPE(RtlGetVersion, PFNRTRTLGETVERSION);
304#ifndef RT_ARCH_AMD64
305 GET_SYSTEM_ROUTINE(KeQueryInterruptTime);
306 GET_SYSTEM_ROUTINE(KeQuerySystemTime);
307#endif
308 GET_SYSTEM_ROUTINE_TYPE(KeQueryInterruptTimePrecise, PFNRTKEQUERYINTERRUPTTIMEPRECISE);
309 GET_SYSTEM_ROUTINE_TYPE(KeQuerySystemTimePrecise, PFNRTKEQUERYSYSTEMTIMEPRECISE);
310
311 g_pfnrtHalRequestIpiW7Plus = (PFNHALREQUESTIPI_W7PLUS)RTR0DbgKrnlInfoGetSymbol(hKrnlInfo, NULL, "HalRequestIpi");
312 g_pfnrtHalRequestIpiPreW7 = (PFNHALREQUESTIPI_PRE_W7)g_pfnrtHalRequestIpiW7Plus;
313
314 g_puRtMmHighestUserAddress = (uintptr_t const *)RTR0DbgKrnlInfoGetSymbol(hKrnlInfo, NULL, "MmHighestUserAddress");
315 g_puRtMmSystemRangeStart = (uintptr_t const *)RTR0DbgKrnlInfoGetSymbol(hKrnlInfo, NULL, "MmSystemRangeStart");
316
317 RTR0DbgKrnlInfoRelease(hKrnlInfo);
318
319 /*
320 * HACK ALERT! (and déjà vu warning - remember win32k.sys?)
321 *
322 * Try find _KPRCB::QuantumEnd and _KPRCB::[DpcData.]DpcQueueDepth.
323 * For purpose of verification we use the VendorString member (12+1 chars).
324 *
325 * The offsets was initially derived by poking around with windbg
326 * (dt _KPRCB, !prcb ++, and such like). Systematic harvesting was then
327 * planned using dia2dump, grep and the symbol pack in a manner like this:
328 * dia2dump -type _KDPC_DATA -type _KPRCB EXE\ntkrnlmp.pdb | grep -wE "QuantumEnd|DpcData|DpcQueueDepth|VendorString"
329 *
330 * The final solution ended up using a custom harvester program called
331 * ntBldSymDb that recursively searches thru unpacked symbol packages for
332 * the desired structure offsets. The program assumes that the packages
333 * are unpacked into directories with the same name as the package, with
334 * exception of some of the w2k packages which requires a 'w2k' prefix to
335 * be distinguishable from another.
336 */
337
338 RTNTSDBOSVER OsVerInfo;
339 rtR0NtGetOsVersionInfo(&OsVerInfo);
340
341 /* Publish the version info in globals. */
342 g_uRtNtVersion = RTNT_MAKE_VERSION(OsVerInfo.uMajorVer, OsVerInfo.uMinorVer);
343 g_uRtNtMinorVer = OsVerInfo.uMinorVer;
344 g_uRtNtMajorVer = OsVerInfo.uMajorVer;
345 g_uRtNtBuildNo = OsVerInfo.uBuildNo;
346
347 /*
348 * Gather consistent CPU vendor string and PRCB pointers.
349 */
350 KIRQL OldIrql;
351 KeRaiseIrql(DISPATCH_LEVEL, &OldIrql); /* make sure we stay on the same cpu */
352
353 union
354 {
355 uint32_t auRegs[4];
356 char szVendor[4*3+1];
357 } u;
358 ASMCpuId(0, &u.auRegs[3], &u.auRegs[0], &u.auRegs[2], &u.auRegs[1]);
359 u.szVendor[4*3] = '\0';
360
361 uint8_t *pbPrcb;
362 __try /* Warning. This try/except statement may provide some false safety. */
363 {
364#if defined(RT_ARCH_X86)
365 PKPCR pPcr = (PKPCR)__readfsdword(RT_OFFSETOF(KPCR,SelfPcr));
366 pbPrcb = (uint8_t *)pPcr->Prcb;
367#elif defined(RT_ARCH_AMD64)
368 PKPCR pPcr = (PKPCR)__readgsqword(RT_OFFSETOF(KPCR,Self));
369 pbPrcb = (uint8_t *)pPcr->CurrentPrcb;
370#else
371# error "port me"
372 pbPrcb = NULL;
373#endif
374 }
375 __except(EXCEPTION_EXECUTE_HANDLER)
376 {
377 pbPrcb = NULL;
378 }
379
380 /*
381 * Search the database
382 */
383 if (pbPrcb)
384 {
385 /* Find the best matching kernel version based on build number. */
386 uint32_t iBest = UINT32_MAX;
387 int32_t iBestDelta = INT32_MAX;
388 for (uint32_t i = 0; i < RT_ELEMENTS(g_artNtSdbSets); i++)
389 {
390 if (g_artNtSdbSets[i].OsVerInfo.fChecked != OsVerInfo.fChecked)
391 continue;
392 if (OsVerInfo.fSmp /*must-be-smp*/ && !g_artNtSdbSets[i].OsVerInfo.fSmp)
393 continue;
394
395 int32_t iDelta = RT_ABS((int32_t)OsVerInfo.uBuildNo - (int32_t)g_artNtSdbSets[i].OsVerInfo.uBuildNo);
396 if ( iDelta == 0
397 && (g_artNtSdbSets[i].OsVerInfo.uCsdNo == OsVerInfo.uCsdNo || OsVerInfo.uCsdNo == MY_NIL_CSD))
398 {
399 /* prefect */
400 iBestDelta = iDelta;
401 iBest = i;
402 break;
403 }
404 if ( iDelta < iBestDelta
405 || iBest == UINT32_MAX
406 || ( iDelta == iBestDelta
407 && OsVerInfo.uCsdNo != MY_NIL_CSD
408 && RT_ABS(g_artNtSdbSets[i ].OsVerInfo.uCsdNo - (int32_t)OsVerInfo.uCsdNo)
409 < RT_ABS(g_artNtSdbSets[iBest].OsVerInfo.uCsdNo - (int32_t)OsVerInfo.uCsdNo)
410 )
411 )
412 {
413 iBestDelta = iDelta;
414 iBest = i;
415 }
416 }
417 if (iBest < RT_ELEMENTS(g_artNtSdbSets))
418 {
419 /* Try all sets: iBest -> End; iBest -> Start. */
420 bool fDone = false;
421 int32_t i = iBest;
422 while ( i < RT_ELEMENTS(g_artNtSdbSets)
423 && !(fDone = rtR0NtTryMatchSymSet(&g_artNtSdbSets[i], pbPrcb, u.szVendor, &OsVerInfo)))
424 i++;
425 if (!fDone)
426 {
427 i = (int32_t)iBest - 1;
428 while ( i >= 0
429 && !(fDone = rtR0NtTryMatchSymSet(&g_artNtSdbSets[i], pbPrcb, u.szVendor, &OsVerInfo)))
430 i--;
431 }
432 }
433 else
434 DbgPrint("IPRT: Failed to locate data set.\n");
435 }
436 else
437 DbgPrint("IPRT: Failed to get PCBR pointer.\n");
438
439 KeLowerIrql(OldIrql); /* Lowering the IRQL early in the hope that we may catch exceptions below. */
440
441#ifndef IN_GUEST
442 if (!g_offrtNtPbQuantumEnd && !g_offrtNtPbDpcQueueDepth)
443 DbgPrint("IPRT: Neither _KPRCB::QuantumEnd nor _KPRCB::DpcQueueDepth was not found! Kernel %u.%u %u %s\n",
444 OsVerInfo.uMajorVer, OsVerInfo.uMinorVer, OsVerInfo.uBuildNo, OsVerInfo.fChecked ? "checked" : "free");
445# ifdef DEBUG
446 else
447 DbgPrint("IPRT: _KPRCB:{.QuantumEnd=%x/%d, .DpcQueueDepth=%x/%d} Kernel %u.%u %u %s\n",
448 g_offrtNtPbQuantumEnd, g_cbrtNtPbQuantumEnd, g_offrtNtPbDpcQueueDepth, g_offrtNtPbDpcQueueDepth,
449 OsVerInfo.uMajorVer, OsVerInfo.uMinorVer, OsVerInfo.uBuildNo, OsVerInfo.fChecked ? "checked" : "free");
450# endif
451#endif
452
453 /*
454 * Initialize multi processor stuff. This registers a callback, so
455 * we call rtR0TermNative to do the deregistration on failure.
456 */
457 rc = rtR0MpNtInit(&OsVerInfo);
458 if (RT_FAILURE(rc))
459 {
460 rtR0TermNative();
461 DbgPrint("IPRT: Fatal: rtR0MpNtInit failed: %d\n", rc);
462 return rc;
463 }
464
465 return VINF_SUCCESS;
466}
467
468
469DECLHIDDEN(void) rtR0TermNative(void)
470{
471 rtR0MpNtTerm();
472}
473
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette