#undef _NAME
}
+static HKEY
+OpenInterfacesKey(
+ IN PTCHAR ProviderName
+ )
+{
+ HRESULT Result;
+ TCHAR KeyName[MAX_PATH];
+ HKEY Key;
+ HRESULT Error;
+
+ Result = StringCbPrintf(KeyName,
+ MAX_PATH,
+ "%s\\%s\\Interfaces",
+ SERVICES_KEY,
+ ProviderName);
+ if (!SUCCEEDED(Result)) {
+ SetLastError(ERROR_BUFFER_OVERFLOW);
+ goto fail1;
+ }
+
+ Error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+ KeyName,
+ 0,
+ KEY_ALL_ACCESS,
+ &Key);
+ if (Error != ERROR_SUCCESS) {
+ SetLastError(Error);
+ goto fail2;
+ }
+
+ return Key;
+
+fail2:
+ Log("fail2");
+
+fail1:
+ Error = GetLastError();
+
+ {
+ PTCHAR Message;
+ Message = GetErrorMessage(Error);
+ Log("fail1 (%s)", Message);
+ LocalFree(Message);
+ }
+
+ return NULL;
+}
+
+static BOOLEAN
+SubscribeInterface(
+ IN PTCHAR ProviderName,
+ IN PTCHAR SubscriberName,
+ IN PTCHAR InterfaceName,
+ IN DWORD InterfaceVersion
+ )
+{
+ HKEY Key;
+ HKEY InterfacesKey;
+ HRESULT Error;
+
+ InterfacesKey = OpenInterfacesKey(ProviderName);
+ if (InterfacesKey == NULL)
+ goto fail1;
+
+ Error = RegCreateKeyEx(InterfacesKey,
+ SubscriberName,
+ 0,
+ NULL,
+ REG_OPTION_NON_VOLATILE,
+ KEY_ALL_ACCESS,
+ NULL,
+ &Key,
+ NULL);
+ if (Error != ERROR_SUCCESS) {
+ SetLastError(Error);
+ goto fail2;
+ }
+
+ Error = RegSetValueEx(Key,
+ InterfaceName,
+ 0,
+ REG_DWORD,
+ (const BYTE *)&InterfaceVersion,
+ sizeof(DWORD));
+ if (Error != ERROR_SUCCESS) {
+ SetLastError(Error);
+ goto fail3;
+ }
+
+ Log("%s: %s_%s_INTERFACE_VERSION %u",
+ SubscriberName,
+ ProviderName,
+ InterfaceName,
+ InterfaceVersion);
+
+ RegCloseKey(Key);
+ RegCloseKey(InterfacesKey);
+
+ return TRUE;
+
+fail3:
+ RegCloseKey(Key);
+
+fail2:
+ RegCloseKey(InterfacesKey);
+
+fail1:
+ Error = GetLastError();
+
+ {
+ PTCHAR Message;
+ Message = GetErrorMessage(Error);
+ Log("fail1 (%s)", Message);
+ LocalFree(Message);
+ }
+
+ return FALSE;
+}
+
+#define SUBSCRIBE_INTERFACE(_ProviderName, _SubscriberName, _InterfaceName) \
+ do { \
+ (VOID) SubscribeInterface(#_ProviderName, \
+ #_SubscriberName, \
+ #_InterfaceName, \
+ _ProviderName ## _ ## _InterfaceName ## _INTERFACE_VERSION_MAX); \
+ } while (FALSE);
+
+static BOOLEAN
+UnsubscribeInterfaces(
+ IN PTCHAR ProviderName,
+ IN PTCHAR SubscriberName
+ )
+{
+ HKEY InterfacesKey;
+ HRESULT Error;
+
+ Log("%s: %s", SubscriberName, ProviderName);
+
+ InterfacesKey = OpenInterfacesKey(ProviderName);
+ if (InterfacesKey == NULL) {
+ goto fail1;
+ }
+
+ Error = RegDeleteTree(InterfacesKey,
+ SubscriberName);
+ if (Error != ERROR_SUCCESS) {
+ SetLastError(Error);
+ goto fail2;
+ }
+
+ RegCloseKey(InterfacesKey);
+
+ return TRUE;
+
+fail2:
+ RegCloseKey(InterfacesKey);
+
+fail1:
+ Error = GetLastError();
+
+ {
+ PTCHAR Message;
+ Message = GetErrorMessage(Error);
+ Log("fail1 (%s)", Message);
+ LocalFree(Message);
+ }
+
+ return FALSE;
+}
+
static HRESULT
DifInstallPreProcess(
IN HDEVINFO DeviceInfoSet,
UNREFERENCED_PARAMETER(DeviceInfoData);
UNREFERENCED_PARAMETER(Context);
- Log("<===>");
+ Log("====>");
+
+ SUBSCRIBE_INTERFACE(XENBUS, XENIFACE, SUSPEND);
+ SUBSCRIBE_INTERFACE(XENBUS, XENIFACE, SHARED_INFO);
+ SUBSCRIBE_INTERFACE(XENBUS, XENIFACE, STORE);
+
+ Log("<====");
return NO_ERROR;
}
UNREFERENCED_PARAMETER(DeviceInfoData);
UNREFERENCED_PARAMETER(Context);
- Log("<===>");
+ Log("====>");
+
+ UnsubscribeInterfaces("XENBUS", "XENIFACE");
+
+ Log("<====");
return NO_ERROR;
}
return status;
}
-#define SERVICES_KEY L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services"
-
-static FORCEINLINE NTSTATUS
-__FdoQueryInterface(
+static NTSTATUS
+FdoQueryInterface(
IN PXENIFACE_FDO Fdo,
- IN const WCHAR *ProviderName,
- IN const CHAR *InterfaceName,
IN const GUID *Guid,
IN ULONG Version,
OUT PINTERFACE Interface,
IN BOOLEAN Optional
)
{
- UNICODE_STRING Unicode;
- HANDLE InterfacesKey;
- HANDLE SubscriberKey;
KEVENT Event;
IO_STATUS_BLOCK StatusBlock;
PIRP Irp;
ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL);
- Unicode.MaximumLength = (USHORT)((wcslen(SERVICES_KEY) +
- 1 +
- wcslen(ProviderName) +
- 1 +
- wcslen(L"Interfaces") +
- 1) * sizeof (WCHAR));
-
- Unicode.Buffer = __FdoAllocate(Unicode.MaximumLength);
-
- status = STATUS_NO_MEMORY;
- if (Unicode.Buffer == NULL)
- goto fail1;
-
- status = RtlStringCbPrintfW(Unicode.Buffer,
- Unicode.MaximumLength,
- SERVICES_KEY L"\\%ws\\Interfaces",
- ProviderName);
- ASSERT(NT_SUCCESS(status));
-
- Unicode.Length = (USHORT)(wcslen(Unicode.Buffer) * sizeof (WCHAR));
-
- status = RegistryOpenKey(NULL, &Unicode, KEY_READ, &InterfacesKey);
- if (!NT_SUCCESS(status))
- goto fail2;
-
- status = RegistryCreateSubKey(InterfacesKey,
- "XENIFACE",
- REG_OPTION_NON_VOLATILE,
- &SubscriberKey);
- if (!NT_SUCCESS(status))
- goto fail3;
-
KeInitializeEvent(&Event, NotificationEvent, FALSE);
RtlZeroMemory(&StatusBlock, sizeof(IO_STATUS_BLOCK));
status = STATUS_UNSUCCESSFUL;
if (Irp == NULL)
- goto fail4;
+ goto fail1;
StackLocation = IoGetNextIrpStackLocation(Irp);
StackLocation->MinorFunction = IRP_MN_QUERY_INTERFACE;
if (status == STATUS_NOT_SUPPORTED && Optional)
goto done;
- goto fail5;
+ goto fail2;
}
- status = RegistryUpdateDwordValue(SubscriberKey,
- (PCHAR)InterfaceName,
- Version);
- if (!NT_SUCCESS(status))
- goto fail6;
-
done:
- RegistryCloseKey(SubscriberKey);
-
- RegistryCloseKey(InterfacesKey);
-
- __FdoFree(Unicode.Buffer);
-
return STATUS_SUCCESS;
-fail6:
- Error("fail6\n");
-
-fail5:
- Error("fail5\n");
-
-fail4:
- Error("fail4\n");
-
- RegistryCloseKey(SubscriberKey);
-
-fail3:
- Error("fail3\n");
-
- RegistryCloseKey(InterfacesKey);
-
fail2:
Error("fail2\n");
- __FdoFree(Unicode.Buffer);
-
fail1:
Error("fail1 (%08x)\n", status);
_Fdo, \
_ProviderName, \
_InterfaceName, \
- _Version, \
_Interface, \
_Size, \
_Optional) \
- __FdoQueryInterface((_Fdo), \
- L ## #_ProviderName, \
- #_InterfaceName, \
- &GUID_ ## _ProviderName ## _ ## _InterfaceName ## _INTERFACE, \
- (_Version), \
- (_Interface), \
- (_Size), \
- (_Optional))
+ FdoQueryInterface((_Fdo), \
+ &GUID_ ## _ProviderName ## _ ## _InterfaceName ## _INTERFACE, \
+ _ProviderName ## _ ## _InterfaceName ## _INTERFACE_VERSION_MAX, \
+ (_Interface), \
+ (_Size), \
+ (_Optional))
NTSTATUS
FdoCreate(
status = FDO_QUERY_INTERFACE(Fdo,
XENBUS,
SUSPEND,
- XENBUS_SUSPEND_INTERFACE_VERSION_MAX,
(PINTERFACE)&Fdo->SuspendInterface,
sizeof (Fdo->SuspendInterface),
FALSE);
status = FDO_QUERY_INTERFACE(Fdo,
XENBUS,
SHARED_INFO,
- XENBUS_SHARED_INFO_INTERFACE_VERSION_MAX,
(PINTERFACE)&Fdo->SharedInfoInterface,
sizeof (Fdo->SharedInfoInterface),
FALSE);
status = FDO_QUERY_INTERFACE(Fdo,
XENBUS,
STORE,
- XENBUS_STORE_INTERFACE_VERSION_MAX,
(PINTERFACE)&Fdo->StoreInterface,
sizeof (Fdo->StoreInterface),
FALSE);