VirtualBox

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

Last change on this file since 62448 was 57358, checked in by vboxsync, 9 years ago

*: scm cleanup run.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/* $Id: mpnotification-r0drv-nt.cpp 57358 2015-08-14 15:16:38Z vboxsync $ */
2/** @file
3 * IPRT - Multiprocessor Event Notifications, Ring-0 Driver, NT.
4 */
5
6/*
7 * Copyright (C) 2008-2015 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
33#include <iprt/mp.h>
34#include <iprt/err.h>
35#include <iprt/cpuset.h>
36#include "r0drv/mp-r0drv.h"
37#include "internal-r0drv-nt.h"
38
39
40#if 0 /* The following is 100% untested code . */
41
42#ifndef KE_PROCESSOR_CHANGE_ADD_EXISTING
43/* Some bits that are missing from our DDK headers. */
44
45typedef enum
46{
47 KeProcessorAddStartNotify = 0,
48 KeProcessorAddCompleteNotify,
49 KeProcessorAddFailureNotify
50} KE_PROCESSOR_CHANGE_NOTIFY_STATE;
51
52typedef struct _KE_PROCESSOR_CHANGE_NOTIFY_CONTEXT
53{
54 KE_PROCESSOR_CHANGE_NOTIFY_STATE State;
55 ULONG NtNumber;
56 NTSTATUS Status;
57} KE_PROCESSOR_CHANGE_NOTIFY_CONTEXT;
58typedef KE_PROCESSOR_CHANGE_NOTIFY_CONTEXT *PKE_PROCESSOR_CHANGE_NOTIFY_CONTEXT;
59
60typedef VOID (__stdcall *PPROCESSOR_CALLBACK_FUNCTION)(PVOID, PKE_PROCESSOR_CHANGE_NOTIFY_CONTEXT, PNTSTATUS);
61
62# define KE_PROCESSOR_CHANGE_ADD_EXISTING 1
63#endif /* !KE_PROCESSOR_CHANGE_ADD_EXISTING */
64
65
66
67/*********************************************************************************************************************************
68* Structures and Typedefs *
69*********************************************************************************************************************************/
70/** Typedef of KeRegisterProcessorChangeCallback. */
71typedef PVOID (__stdcall *PFNMYKEREGISTERPROCESSORCHANGECALLBACK)(PPROCESSOR_CALLBACK_FUNCTION, PVOID, ULONG);
72/** Typedef of KeDeregisterProcessorChangeCallback. */
73typedef VOID (__stdcall *PFNMYKEDEREGISTERPROCESSORCHANGECALLBACK)(PVOID);
74
75
76/*********************************************************************************************************************************
77* Global Variables *
78*********************************************************************************************************************************/
79/** The pointer to KeRegisterProcessorChangeCallback if found. */
80static PFNMYKEREGISTERPROCESSORCHANGECALLBACK g_pfnKeRegisterProcessorChangeCallback = NULL;
81/** The pointer to KeDeregisterProcessorChangeCallback if found. */
82static PFNMYKEDEREGISTERPROCESSORCHANGECALLBACK g_pfnKeDeregisterProcessorChangeCallback = NULL;
83/** The callback handle. */
84static PVOID g_hCallback = NULL;
85
86
87/**
88 * The native callback.
89 *
90 * @param pNotifierBlock Pointer to g_NotifierBlock.
91 * @param ulNativeEvent The native event.
92 * @param pvCpu The cpu id cast into a pointer value.
93 */
94static VOID __stdcall rtMpNotificationNtCallback(PVOID pvUser,
95 PKE_PROCESSOR_CHANGE_NOTIFY_CONTEXT pChangeContext,
96 PNTSTATUS pOperationStatus)
97{
98 NOREF(pvUser);
99 AssertPtr(pChangeContext);
100 AssertPtrNull(pOperationStatus);
101
102 RTCPUID idCpu = pChangeContext->NtNumber;
103 switch (pChangeContext->State)
104 {
105 case KeProcessorAddStartNotify:
106 case KeProcessorAddFailureNotify:
107 break;
108
109 case KeProcessorAddCompleteNotify:
110 /* Update the active CPU set before doing callback round. */
111 RTCpuSetAdd(&g_rtMpNtCpuSet, idCpu);
112 rtMpNotificationDoCallbacks(RTMPEVENT_ONLINE, idCpu);
113 break;
114
115 //case KeProcessorDelCompleteNotify:
116 // rtMpNotificationDoCallbacks(RTMPEVENT_OFFLINE, idCpu);
117 // break;
118
119 default:
120 AssertMsgFailed(("Unexpected state=%d idCpu=%d\n", pChangeContext->State, (int)idCpu));
121 break;
122 }
123
124 *pOperationStatus = STATUS_SUCCESS;
125}
126
127
128DECLHIDDEN(int) rtR0MpNotificationNativeInit(void)
129{
130 /*
131 * Try resolve the symbols.
132 */
133 UNICODE_STRING RoutineName;
134 RtlInitUnicodeString(&RoutineName, L"KeRegisterProcessorChangeCallback");
135 g_pfnKeRegisterProcessorChangeCallback = (PFNMYKEREGISTERPROCESSORCHANGECALLBACK)MmGetSystemRoutineAddress(&RoutineName);
136 if (g_pfnKeRegisterProcessorChangeCallback)
137 {
138 RtlInitUnicodeString(&RoutineName, L"KeDeregisterProcessorChangeCallback");
139 g_pfnKeDeregisterProcessorChangeCallback = (PFNMYKEDEREGISTERPROCESSORCHANGECALLBACK)MmGetSystemRoutineAddress(&RoutineName);
140 if (g_pfnKeDeregisterProcessorChangeCallback)
141 {
142 /*
143 * Try call it.
144 */
145 NTSTATUS ntRc = 0;
146 g_hCallback = g_pfnKeRegisterProcessorChangeCallback(rtMpNotificationNtCallback, &ntRc, KE_PROCESSOR_CHANGE_ADD_EXISTING);
147 if (g_hCallback != NULL)
148 return VINF_SUCCESS;
149
150 /* Genuine failure. */
151 int rc = RTErrConvertFromNtStatus(ntRc);
152 AssertMsgFailed(("ntRc=%#x rc=%d\n", ntRc, rc));
153 return rc;
154 }
155
156 /* this shouldn't happen. */
157 AssertFailed();
158 }
159
160 /* Not supported - success. */
161 g_pfnKeRegisterProcessorChangeCallback = NULL;
162 g_pfnKeDeregisterProcessorChangeCallback = NULL;
163 return VINF_SUCCESS;
164}
165
166
167DECLHIDDEN(void) rtR0MpNotificationNativeTerm(void)
168{
169 if ( g_pfnKeDeregisterProcessorChangeCallback
170 && g_hCallback)
171 {
172 g_pfnKeDeregisterProcessorChangeCallback(g_hCallback);
173 g_hCallback = NULL;
174 }
175}
176
177#else /* Not supported */
178
179DECLHIDDEN(int) rtR0MpNotificationNativeInit(void)
180{
181 return VINF_SUCCESS;
182}
183
184DECLHIDDEN(void) rtR0MpNotificationNativeTerm(void)
185{
186}
187
188#endif /* Not supported */
189
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