VirtualBox

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

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

IPRT: Updated (C) year.

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