1 | /* $Id: mpnotification-r0drv-nt.cpp 9311 2008-06-02 15:27:03Z 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.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 | * 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 |
|
---|
42 |
|
---|
43 | #if /*NTDDI_VERSION >= NTDDI_WS08*/ 0
|
---|
44 | /* The following is 100% untested code which probably doesn't even compile. */
|
---|
45 |
|
---|
46 | /*******************************************************************************
|
---|
47 | * Structures and Typedefs *
|
---|
48 | *******************************************************************************/
|
---|
49 | /** Typedef of KeRegisterProcessorChangeCallback. */
|
---|
50 | typedef PROCESSOR_CALLBACK_HANDLE (__stdcall *PFNMYKEREGISTERPROCESSORCHANGECALLBACK)(IN PPROCESSOR_CALLBACK_FUNCTION, IN PVOID, IN ULONG);
|
---|
51 | /** Typedef of KeDeregisterProcessorChangeCallback. */
|
---|
52 | typedef VOID (__stdcall *PFNMYKEDEREGISTERPROCESSORCHANGECALLBACK)(IN PROCESSOR_CALLBACK_HANDLE);
|
---|
53 |
|
---|
54 |
|
---|
55 | /*******************************************************************************
|
---|
56 | * Global Variables *
|
---|
57 | *******************************************************************************/
|
---|
58 | /** The pointer to KeRegisterProcessorChangeCallback if found. */
|
---|
59 | static PFNMYKEREGISTERPROCESSORCHANGECALLBACK g_pfnKeRegisterProcessorChangeCallback = NULL;
|
---|
60 | /** The pointer to KeDeregisterProcessorChangeCallback if found. */
|
---|
61 | static PFNMYKEDEREGISTERPROCESSORCHANGECALLBACK g_pfnKeDeregisterProcessorChangeCallback = NULL;
|
---|
62 | /** The callback handle. */
|
---|
63 | static PROCESSOR_CALLBACK_HANDLE g_hCallback = NULL;
|
---|
64 |
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * The native callback.
|
---|
68 | *
|
---|
69 | * @param pNotifierBlock Pointer to g_NotifierBlock.
|
---|
70 | * @param ulNativeEvent The native event.
|
---|
71 | * @param pvCpu The cpu id cast into a pointer value.
|
---|
72 | */
|
---|
73 | static VOID __stdcall rtMpNotificationNtCallback(IN PVOID pvUser,
|
---|
74 | IN PKE_PROCESSOR_CHANGE_NOTIFY_CONTEXT pChangeContext,
|
---|
75 | IN OUT PNTSTATUS pOperationStatus)
|
---|
76 | {
|
---|
77 | NOREF(pvUser);
|
---|
78 | AssertPtr(pChangeContext);
|
---|
79 | AssertPtrNull(pOperationStatus);
|
---|
80 |
|
---|
81 | RTCPUID idCpu = pChangeContext->NtNumber;
|
---|
82 | switch (pChangeContext->State)
|
---|
83 | {
|
---|
84 | case KeProcessorAddStartNotify:
|
---|
85 | case KeProcessorAddFailureNotify:
|
---|
86 | break;
|
---|
87 |
|
---|
88 | case KeProcessorAddCompleteNotify:
|
---|
89 | rtMpNotificationDoCallbacks(RTMPEVENT_ONLINE, idCpu);
|
---|
90 | break;
|
---|
91 |
|
---|
92 | //case KeProcessorDelCompleteNotify:
|
---|
93 | // rtMpNotificationDoCallbacks(RTMPEVENT_ONLINE, idCpu);
|
---|
94 | // break;
|
---|
95 |
|
---|
96 | default:
|
---|
97 | AssertMsgFailed(("Unexpected state=%d idCpu=%d\n", pChangeContext->State, (int)idCpu));
|
---|
98 | break;
|
---|
99 | }
|
---|
100 |
|
---|
101 | *pOperationStatus = STATUS_SUCCESS;
|
---|
102 | return 0;
|
---|
103 | }
|
---|
104 |
|
---|
105 |
|
---|
106 | int rtR0MpNotificationNativeInit(void *pvOS)
|
---|
107 | {
|
---|
108 | /*
|
---|
109 | * Try resolve the symbols.
|
---|
110 | */
|
---|
111 | UNICODE_STRING RoutineName;
|
---|
112 | RtlInitUnicodeString(&RoutineName, L"KeRegisterProcessorChangeCallback");
|
---|
113 | g_pfnKeRegisterProcessorChangeCallback = (PFNMYKEREGISTERPROCESSORCHANGECALLBACK)MmGetSystemRoutineAddress(&RoutineName);
|
---|
114 | if (g_pfnKeRegisterProcessorChangeCallback)
|
---|
115 | {
|
---|
116 | RtlInitUnicodeString(&RoutineName, L"KeDeregisterProcessorChangeCallback");
|
---|
117 | g_pfnKeDeregisterProcessorChangeCallback = (PFNMYKEDEREGISTERPROCESSORCHANGECALLBACK)MmGetSystemRoutineAddress(&RoutineName);
|
---|
118 | if (g_pfnKeDeregisterProcessorChangeCallback)
|
---|
119 | {
|
---|
120 | /*
|
---|
121 | * Try call it.
|
---|
122 | */
|
---|
123 | NTSTATUS ntRc = 0;
|
---|
124 | g_hCallback = g_pfnKeRegisterProcessorChangeCallback(rtMpNotificationNtCallback, &ntRc, KE_PROCESSOR_CHANGE_ADD_EXISTING);
|
---|
125 | if (g_hCallback != NULL)
|
---|
126 | return VINF_SUCCESS;
|
---|
127 |
|
---|
128 | /* Genuine failure. */
|
---|
129 | int rc = RTErrConvertFromNtStatus(ntRc);
|
---|
130 | AssertMsgFailed(("ntRc=%#x rc=%d\n", ntRc, rc));
|
---|
131 | return rc;
|
---|
132 | }
|
---|
133 |
|
---|
134 | /* this shouldn't happen. */
|
---|
135 | AssertFailed();
|
---|
136 | }
|
---|
137 |
|
---|
138 | /* Not supported - success. */
|
---|
139 | g_pfnKeRegisterProcessorChangeCallback = NULL;
|
---|
140 | g_pfnKeDeregisterProcessorChangeCallback = NULL;
|
---|
141 | return VINF_SUCCESS;
|
---|
142 | }
|
---|
143 |
|
---|
144 |
|
---|
145 | void rtR0MpNotificationNativeTerm(void *pvOS)
|
---|
146 | {
|
---|
147 | if ( g_pfnKeDeregisterProcessorChangeCallback
|
---|
148 | && g_hCallback)
|
---|
149 | {
|
---|
150 | g_pfnKeDeregisterProcessorChangeCallback(g_hCallback);
|
---|
151 | g_hCallback = NULL;
|
---|
152 | }
|
---|
153 | }
|
---|
154 |
|
---|
155 | #else /* Not supported */
|
---|
156 |
|
---|
157 | int rtR0MpNotificationNativeInit(void *pvOS)
|
---|
158 | {
|
---|
159 | NOREF(pvOS);
|
---|
160 | return VINF_SUCCESS;
|
---|
161 | }
|
---|
162 |
|
---|
163 | void rtR0MpNotificationNativeTerm(void *pvOS)
|
---|
164 | {
|
---|
165 | NOREF(pvOS);
|
---|
166 | }
|
---|
167 |
|
---|
168 | #endif /* Not supported */
|
---|
169 |
|
---|