VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/nt/mpnotification-r0drv-nt.cpp@ 9563

最後變更 在這個檔案從9563是 9563,由 vboxsync 提交於 17 年 前

Cache the KeQueryActiveProcessors() result at init (see crash reading the mask at DPC_LEVEL in SUPDrv-win.cpp).

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 6.0 KB
 
1/* $Id: mpnotification-r0drv-nt.cpp 9563 2008-06-10 11:01:33Z vboxsync $ */
2/** @file
3 * IPRT - Multiprocessor Event Notifications, Ring-0 Driver, NT.
4 */
5
6/*
7 * Copyright (C) 2008 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 *
30 */
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include "the-nt-kernel.h"
36
37#include <iprt/mp.h>
38#include <iprt/err.h>
39#include <iprt/cpuset.h>
40#include "r0drv/mp-r0drv.h"
41#include "internal-r0drv-nt.h"
42
43
44#if /*NTDDI_VERSION >= NTDDI_WS08*/ 0
45/* The following is 100% untested code which probably doesn't even compile. */
46
47/*******************************************************************************
48* Structures and Typedefs *
49*******************************************************************************/
50/** Typedef of KeRegisterProcessorChangeCallback. */
51typedef PROCESSOR_CALLBACK_HANDLE (__stdcall *PFNMYKEREGISTERPROCESSORCHANGECALLBACK)(IN PPROCESSOR_CALLBACK_FUNCTION, IN PVOID, IN ULONG);
52/** Typedef of KeDeregisterProcessorChangeCallback. */
53typedef VOID (__stdcall *PFNMYKEDEREGISTERPROCESSORCHANGECALLBACK)(IN PROCESSOR_CALLBACK_HANDLE);
54
55
56/*******************************************************************************
57* Global Variables *
58*******************************************************************************/
59/** The pointer to KeRegisterProcessorChangeCallback if found. */
60static PFNMYKEREGISTERPROCESSORCHANGECALLBACK g_pfnKeRegisterProcessorChangeCallback = NULL;
61/** The pointer to KeDeregisterProcessorChangeCallback if found. */
62static PFNMYKEDEREGISTERPROCESSORCHANGECALLBACK g_pfnKeDeregisterProcessorChangeCallback = NULL;
63/** The callback handle. */
64static PROCESSOR_CALLBACK_HANDLE g_hCallback = NULL;
65
66
67/**
68 * The native callback.
69 *
70 * @param pNotifierBlock Pointer to g_NotifierBlock.
71 * @param ulNativeEvent The native event.
72 * @param pvCpu The cpu id cast into a pointer value.
73 */
74static VOID __stdcall rtMpNotificationNtCallback(IN PVOID pvUser,
75 IN PKE_PROCESSOR_CHANGE_NOTIFY_CONTEXT pChangeContext,
76 IN OUT PNTSTATUS pOperationStatus)
77{
78 NOREF(pvUser);
79 AssertPtr(pChangeContext);
80 AssertPtrNull(pOperationStatus);
81
82 RTCPUID idCpu = pChangeContext->NtNumber;
83 switch (pChangeContext->State)
84 {
85 case KeProcessorAddStartNotify:
86 case KeProcessorAddFailureNotify:
87 break;
88
89 case KeProcessorAddCompleteNotify:
90 rtMpNotificationDoCallbacks(RTMPEVENT_ONLINE, idCpu);
91 RTCpuSetAdd(&g_rtMpNtCpuSet, idCpu);
92 break;
93
94 //case KeProcessorDelCompleteNotify:
95 // rtMpNotificationDoCallbacks(RTMPEVENT_ONLINE, idCpu);
96 // break;
97
98 default:
99 AssertMsgFailed(("Unexpected state=%d idCpu=%d\n", pChangeContext->State, (int)idCpu));
100 break;
101 }
102
103 *pOperationStatus = STATUS_SUCCESS;
104 return 0;
105}
106
107
108int rtR0MpNotificationNativeInit(void *pvOS)
109{
110 /*
111 * Try resolve the symbols.
112 */
113 UNICODE_STRING RoutineName;
114 RtlInitUnicodeString(&RoutineName, L"KeRegisterProcessorChangeCallback");
115 g_pfnKeRegisterProcessorChangeCallback = (PFNMYKEREGISTERPROCESSORCHANGECALLBACK)MmGetSystemRoutineAddress(&RoutineName);
116 if (g_pfnKeRegisterProcessorChangeCallback)
117 {
118 RtlInitUnicodeString(&RoutineName, L"KeDeregisterProcessorChangeCallback");
119 g_pfnKeDeregisterProcessorChangeCallback = (PFNMYKEDEREGISTERPROCESSORCHANGECALLBACK)MmGetSystemRoutineAddress(&RoutineName);
120 if (g_pfnKeDeregisterProcessorChangeCallback)
121 {
122 /*
123 * Try call it.
124 */
125 NTSTATUS ntRc = 0;
126 g_hCallback = g_pfnKeRegisterProcessorChangeCallback(rtMpNotificationNtCallback, &ntRc, KE_PROCESSOR_CHANGE_ADD_EXISTING);
127 if (g_hCallback != NULL)
128 return VINF_SUCCESS;
129
130 /* Genuine failure. */
131 int rc = RTErrConvertFromNtStatus(ntRc);
132 AssertMsgFailed(("ntRc=%#x rc=%d\n", ntRc, rc));
133 return rc;
134 }
135
136 /* this shouldn't happen. */
137 AssertFailed();
138 }
139
140 /* Not supported - success. */
141 g_pfnKeRegisterProcessorChangeCallback = NULL;
142 g_pfnKeDeregisterProcessorChangeCallback = NULL;
143 return VINF_SUCCESS;
144}
145
146
147void rtR0MpNotificationNativeTerm(void *pvOS)
148{
149 if ( g_pfnKeDeregisterProcessorChangeCallback
150 && g_hCallback)
151 {
152 g_pfnKeDeregisterProcessorChangeCallback(g_hCallback);
153 g_hCallback = NULL;
154 }
155}
156
157#else /* Not supported */
158
159int rtR0MpNotificationNativeInit(void *pvOS)
160{
161 NOREF(pvOS);
162 return VINF_SUCCESS;
163}
164
165void rtR0MpNotificationNativeTerm(void *pvOS)
166{
167 NOREF(pvOS);
168}
169
170#endif /* Not supported */
171
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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