return FALSE;
}
-static BOOLEAN
-CheckStatus(
- IN PTCHAR DriverName,
- OUT PBOOLEAN NeedReboot
- )
-{
- TCHAR StatusKeyName[MAX_PATH];
- HKEY StatusKey;
- HRESULT Result;
- HRESULT Error;
- DWORD ValueLength;
- DWORD Value;
- DWORD Type;
-
- Result = StringCbPrintf(StatusKeyName,
- MAX_PATH,
- SERVICES_KEY "\\%s\\Status",
- DriverName);
- assert(SUCCEEDED(Result));
-
- Error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- StatusKeyName,
- 0,
- KEY_READ,
- &StatusKey);
- if (Error != ERROR_SUCCESS) {
- SetLastError(Error);
- goto fail1;
- }
-
- ValueLength = sizeof (Value);
-
- Error = RegQueryValueEx(StatusKey,
- "NeedReboot",
- NULL,
- &Type,
- (LPBYTE)&Value,
- &ValueLength);
- if (Error != ERROR_SUCCESS) {
- if (Error == ERROR_FILE_NOT_FOUND) {
- Type = REG_DWORD;
- Value = 0;
- } else {
- SetLastError(Error);
- goto fail2;
- }
- }
-
- if (Type != REG_DWORD) {
- SetLastError(ERROR_BAD_FORMAT);
- goto fail3;
- }
-
- *NeedReboot = (Value != 0) ? TRUE : FALSE;
-
- if (*NeedReboot)
- Log("NeedReboot");
-
- RegCloseKey(StatusKey);
-
- return TRUE;
-
-fail3:
- Log("fail3");
-
-fail2:
- Log("fail2");
-
- RegCloseKey(StatusKey);
-
-fail1:
- Error = GetLastError();
-
- {
- PTCHAR Message;
- Message = GetErrorMessage(Error);
- Log("fail1 (%s)", Message);
- LocalFree(Message);
- }
-
- return FALSE;
-}
-
-static BOOLEAN
-RequestReboot(
- IN HDEVINFO DeviceInfoSet,
- IN PSP_DEVINFO_DATA DeviceInfoData
- )
-{
- SP_DEVINSTALL_PARAMS DeviceInstallParams;
- HRESULT Error;
-
- DeviceInstallParams.cbSize = sizeof (DeviceInstallParams);
-
- if (!SetupDiGetDeviceInstallParams(DeviceInfoSet,
- DeviceInfoData,
- &DeviceInstallParams))
- goto fail1;
-
- DeviceInstallParams.Flags |= DI_NEEDREBOOT;
-
- Log("Flags = %08x", DeviceInstallParams.Flags);
-
- if (!SetupDiSetDeviceInstallParams(DeviceInfoSet,
- DeviceInfoData,
- &DeviceInstallParams))
- goto fail2;
-
- return TRUE;
-
-fail2:
- Log("fail2");
-
-fail1:
- Error = GetLastError();
-
- {
- PTCHAR Message;
-
- Message = GetErrorMessage(Error);
- Log("fail1 (%s)", Message);
- LocalFree(Message);
- }
-
- return FALSE;
-}
-
static BOOLEAN
ClearUnplugRequest(
IN PTCHAR ClassName
IN PCOINSTALLER_CONTEXT_DATA Context
)
{
- BOOLEAN NeedReboot;
-
+ UNREFERENCED_PARAMETER(DeviceInfoSet);
+ UNREFERENCED_PARAMETER(DeviceInfoData);
UNREFERENCED_PARAMETER(Context);
- Log("====>");
-
- NeedReboot = FALSE;
-
- (VOID) CheckStatus("XEN", &NeedReboot);
- if (!NeedReboot)
- (VOID) CheckStatus("XENBUS", &NeedReboot);
-
- if (NeedReboot)
- (VOID) RequestReboot(DeviceInfoSet, DeviceInfoData);
-
- Log("<====");
+ Log("<===>");
return NO_ERROR;
}
PLOG_DISPOSITION TraceDisposition;
PLOG_DISPOSITION InfoDisposition;
HANDLE UnplugKey;
- HANDLE StatusKey;
} XEN_DRIVER, *PXEN_DRIVER;
static XEN_DRIVER Driver;
return __DriverGetUnplugKey();
}
-static FORCEINLINE VOID
-__DriverSetStatusKey(
- IN HANDLE Key
- )
-{
- Driver.StatusKey = Key;
-}
-
-static FORCEINLINE HANDLE
-__DriverGetStatusKey(
- VOID
- )
-{
- return Driver.StatusKey;
-}
-
-HANDLE
-DriverGetStatusKey(
- VOID
- )
-{
- return __DriverGetStatusKey();
-}
-
-static FORCEINLINE VOID
-__DriverRequestReboot(
- VOID
- )
-{
- Info("<===>\n");
-
- ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL);
-
- (VOID) RegistryUpdateDwordValue(__DriverGetStatusKey(),
- "NeedReboot",
- 1);
-}
-
XEN_API
NTSTATUS
XenTouch(
fail1:
Info("MODULE '%s' NOT COMPATIBLE (REBOOT REQUIRED)\n", Name);
- __DriverRequestReboot();
return STATUS_INCOMPATIBLE_DRIVER_BLOCKED;
}
{
HANDLE ServiceKey;
HANDLE UnplugKey;
- HANDLE StatusKey;
NTSTATUS status;
ExInitializeDriverRuntime(DrvRtPoolNxOptIn);
__DriverSetUnplugKey(UnplugKey);
- status = RegistryCreateSubKey(ServiceKey,
- "Status",
- REG_OPTION_VOLATILE,
- &StatusKey);
- if (!NT_SUCCESS(status))
- goto fail5;
-
- __DriverSetStatusKey(StatusKey);
-
status = AcpiInitialize();
if (!NT_SUCCESS(status))
- goto fail6;
+ goto fail5;
status = SystemInitialize();
if (!NT_SUCCESS(status))
- goto fail7;
+ goto fail6;
status = HypercallInitialize();
if (!NT_SUCCESS(status))
- goto fail8;
+ goto fail7;
status = BugCheckInitialize();
if (!NT_SUCCESS(status))
- goto fail9;
+ goto fail8;
status = ModuleInitialize();
if (!NT_SUCCESS(status))
- goto fail10;
+ goto fail9;
status = ProcessInitialize();
if (!NT_SUCCESS(status))
- goto fail11;
+ goto fail10;
status = UnplugInitialize();
if (!NT_SUCCESS(status))
- goto fail12;
+ goto fail11;
RegistryCloseKey(ServiceKey);
return STATUS_SUCCESS;
-fail12:
- Error("fail12\n");
-
- ProcessTeardown();
-
fail11:
Error("fail11\n");
- ModuleTeardown();
+ ProcessTeardown();
fail10:
Error("fail10\n");
- BugCheckTeardown();
+ ModuleTeardown();
fail9:
Error("fail9\n");
- HypercallTeardown();
+ BugCheckTeardown();
fail8:
Error("fail8\n");
- SystemTeardown();
+ HypercallTeardown();
fail7:
Error("fail7\n");
- AcpiTeardown();
+ SystemTeardown();
fail6:
Error("fail6\n");
- RegistryCloseKey(StatusKey);
- __DriverSetStatusKey(NULL);
+ AcpiTeardown();
fail5:
Error("fail5\n");
VOID
)
{
- HANDLE StatusKey;
HANDLE UnplugKey;
Trace("====>\n");
SystemTeardown();
- StatusKey = __DriverGetStatusKey();
-
- RegistryCloseKey(StatusKey);
- __DriverSetStatusKey(NULL);
-
UnplugKey = __DriverGetUnplugKey();
RegistryCloseKey(UnplugKey);
CopyFiles=Monitor_CopyFiles
[XenBus_Inst.Services]
+AddService=xenbus_monitor,%SPSVCSINST_STARTSERVICE%,Monitor_Service,Monitor_EventLog
AddService=xenbus,%SPSVCINST_ASSOCSERVICE%,XenBus_Service
AddService=xenfilt,,XenFilt_Service,
-AddService=xenbus_monitor,%SPSVCSINST_STARTSERVICE%,Monitor_Service,Monitor_EventLog
[XenBus_Service]
DisplayName=%XenBusDesc%
typedef struct _XENBUS_DRIVER {
PDRIVER_OBJECT DriverObject;
HANDLE ParametersKey;
- HANDLE StatusKey;
MUTEX Mutex;
LIST_ENTRY List;
return __DriverGetParametersKey();
}
-static FORCEINLINE VOID
-__DriverSetStatusKey(
- IN HANDLE Key
- )
-{
- Driver.StatusKey = Key;
-}
+#define SERVICES_PATH "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services"
-static FORCEINLINE HANDLE
-__DriverGetStatusKey(
- VOID
- )
-{
- return Driver.StatusKey;
-}
+#define SERVICE_KEY(_Name) \
+ SERVICES_PATH ## "\\" ## #_Name
-VOID
-DriverRequestReboot(
+#define REQUEST_KEY \
+ SERVICE_KEY(XENBUS_MONITOR) ## "\\Request"
+
+static FORCEINLINE VOID
+__DriverRequestReboot(
VOID
)
{
- Info("<===>\n");
+ HANDLE RequestKey;
+ ANSI_STRING Ansi[2];
+ NTSTATUS status;
+
+ Info("====>\n");
ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL);
- (VOID) RegistryUpdateDwordValue(__DriverGetStatusKey(),
- "NeedReboot",
- 1);
+ status = RegistryOpenSubKey(NULL,
+ REQUEST_KEY,
+ KEY_ALL_ACCESS,
+ &RequestKey);
+ if (!NT_SUCCESS(status))
+ goto fail1;
+
+ RtlZeroMemory(Ansi, sizeof (Ansi));
+
+ RtlInitAnsiString(&Ansi[0], "XENBUS");
+
+ status = RegistryUpdateSzValue(RequestKey,
+ "Reboot",
+ REG_SZ,
+ Ansi);
+ if (!NT_SUCCESS(status))
+ goto fail2;
+
+ RegistryCloseKey(RequestKey);
+
+ Info("<====\n");
+
+ return;
+
+fail2:
+ Error("fail2\n");
+
+ RegistryCloseKey(RequestKey);
+
+fail1:
+ Error("fail1 (%08x)\n", status);
}
static FORCEINLINE VOID
)
{
HANDLE ParametersKey;
- HANDLE StatusKey;
ASSERT3P(DriverObject, ==, __DriverGetDriverObject());
RtlZeroMemory(&Driver.List, sizeof (LIST_ENTRY));
RtlZeroMemory(&Driver.Mutex, sizeof (MUTEX));
- StatusKey = __DriverGetStatusKey();
- __DriverSetStatusKey(NULL);
-
- RegistryCloseKey(StatusKey);
-
ParametersKey = __DriverGetParametersKey();
RegistryCloseKey(ParametersKey);
{
HANDLE ServiceKey;
HANDLE ParametersKey;
- HANDLE StatusKey;
ULONG Index;
NTSTATUS status;
MINOR_VERSION,
MICRO_VERSION,
BUILD_NUMBER);
- if (!NT_SUCCESS(status))
- goto done;
+ if (!NT_SUCCESS(status)) {
+ __DriverRequestReboot();
+ goto fail1;
+ }
status = RegistryInitialize(RegistryPath);
if (!NT_SUCCESS(status))
- goto fail1;
+ goto fail2;
status = RegistryOpenServiceKey(KEY_READ, &ServiceKey);
if (!NT_SUCCESS(status))
- goto fail2;
+ goto fail3;
status = RegistryOpenSubKey(ServiceKey,
"Parameters",
KEY_READ,
&ParametersKey);
- if (!NT_SUCCESS(status))
- goto fail3;
-
- __DriverSetParametersKey(ParametersKey);
-
- status = RegistryCreateSubKey(ServiceKey,
- "Status",
- REG_OPTION_VOLATILE,
- &StatusKey);
if (!NT_SUCCESS(status))
goto fail4;
- __DriverSetStatusKey(StatusKey);
+ __DriverSetParametersKey(ParametersKey);
RegistryCloseKey(ServiceKey);
InitializeListHead(&Driver.List);
Driver.References = 1;
-done:
Trace("<====\n");
return STATUS_SUCCESS;
fail4:
Error("fail4\n");
- __DriverSetParametersKey(NULL);
-
- RegistryCloseKey(ParametersKey);
+ RegistryCloseKey(ServiceKey);
fail3:
Error("fail3\n");
- RegistryCloseKey(ServiceKey);
+ RegistryTeardown();
fail2:
Error("fail2\n");
- RegistryTeardown();
-
fail1:
Error("fail1 (%08x)\n", status);