Don't use ntoskrnl.RtlDuplicateUnicodeString, as it is not exported on MS Windows

svn path=/trunk/; revision=26197
This commit is contained in:
Hervé Poussineau 2007-03-28 18:47:35 +00:00
parent d8175ef0a6
commit e2ab9cb060
7 changed files with 69 additions and 20 deletions

View file

@ -9,7 +9,6 @@
* Hervé Poussineau (hpoussin@reactos.com) * Hervé Poussineau (hpoussin@reactos.com)
*/ */
#define NDEBUG
#include "serenum.h" #include "serenum.h"
static NTSTATUS static NTSTATUS
@ -129,15 +128,15 @@ ReportDetectedDevice(
FdoDeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; FdoDeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
RtlZeroMemory(PdoDeviceExtension, sizeof(PDO_DEVICE_EXTENSION)); RtlZeroMemory(PdoDeviceExtension, sizeof(PDO_DEVICE_EXTENSION));
PdoDeviceExtension->Common.IsFDO = FALSE; PdoDeviceExtension->Common.IsFDO = FALSE;
Status = RtlDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, DeviceDescription, &PdoDeviceExtension->DeviceDescription); Status = DuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, DeviceDescription, &PdoDeviceExtension->DeviceDescription);
if (!NT_SUCCESS(Status)) goto ByeBye; if (!NT_SUCCESS(Status)) goto ByeBye;
Status = RtlDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, DeviceId, &PdoDeviceExtension->DeviceId); Status = DuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, DeviceId, &PdoDeviceExtension->DeviceId);
if (!NT_SUCCESS(Status)) goto ByeBye; if (!NT_SUCCESS(Status)) goto ByeBye;
Status = RtlDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, InstanceId, &PdoDeviceExtension->InstanceId); Status = DuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, InstanceId, &PdoDeviceExtension->InstanceId);
if (!NT_SUCCESS(Status)) goto ByeBye; if (!NT_SUCCESS(Status)) goto ByeBye;
Status = RtlDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, HardwareIds, &PdoDeviceExtension->HardwareIds); Status = DuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, HardwareIds, &PdoDeviceExtension->HardwareIds);
if (!NT_SUCCESS(Status)) goto ByeBye; if (!NT_SUCCESS(Status)) goto ByeBye;
Status = RtlDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, CompatibleIds, &PdoDeviceExtension->CompatibleIds); Status = DuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, CompatibleIds, &PdoDeviceExtension->CompatibleIds);
if (!NT_SUCCESS(Status)) goto ByeBye; if (!NT_SUCCESS(Status)) goto ByeBye;
/* Device attached to serial port (Pdo) may delegate work to /* Device attached to serial port (Pdo) may delegate work to

View file

@ -7,7 +7,6 @@
* PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.com) * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.com)
*/ */
#define NDEBUG
#include "serenum.h" #include "serenum.h"
NTSTATUS NTAPI NTSTATUS NTAPI

View file

@ -7,10 +7,11 @@
* PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.com) * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.com)
*/ */
#define NDEBUG
#include "serenum.h" #include "serenum.h"
#include <stdarg.h> #include <stdarg.h>
static IO_COMPLETION_ROUTINE ForwardIrpAndWaitCompletion;
/* I really want PCSZ strings as last arguments because /* I really want PCSZ strings as last arguments because
* PnP ids are ANSI-encoded in PnP device string * PnP ids are ANSI-encoded in PnP device string
* identification */ * identification */
@ -114,7 +115,7 @@ ForwardIrpAndWait(
KeInitializeEvent(&Event, NotificationEvent, FALSE); KeInitializeEvent(&Event, NotificationEvent, FALSE);
IoCopyCurrentIrpStackLocationToNext(Irp); IoCopyCurrentIrpStackLocationToNext(Irp);
DPRINT("Calling lower device %p [%wZ]\n", LowerDevice, &LowerDevice->DriverObject->DriverName); DPRINT("Calling lower device %p\n", LowerDevice);
IoSetCompletionRoutine(Irp, ForwardIrpAndWaitCompletion, &Event, TRUE, TRUE, TRUE); IoSetCompletionRoutine(Irp, ForwardIrpAndWaitCompletion, &Event, TRUE, TRUE, TRUE);
Status = IoCallDriver(LowerDevice, Irp); Status = IoCallDriver(LowerDevice, Irp);
@ -141,8 +142,7 @@ ForwardIrpToLowerDeviceAndForget(
LowerDevice = DeviceExtension->LowerDevice; LowerDevice = DeviceExtension->LowerDevice;
ASSERT(LowerDevice); ASSERT(LowerDevice);
DPRINT("Calling lower device 0x%p [%wZ]\n", DPRINT("Calling lower device 0x%p\n", LowerDevice);
LowerDevice, &LowerDevice->DriverObject->DriverName);
IoSkipCurrentIrpStackLocation(Irp); IoSkipCurrentIrpStackLocation(Irp);
return IoCallDriver(LowerDevice, Irp); return IoCallDriver(LowerDevice, Irp);
} }
@ -160,8 +160,7 @@ ForwardIrpToAttachedFdoAndForget(
Fdo = DeviceExtension->AttachedFdo; Fdo = DeviceExtension->AttachedFdo;
ASSERT(Fdo); ASSERT(Fdo);
DPRINT("Calling attached Fdo 0x%p [%wZ]\n", DPRINT("Calling attached Fdo 0x%p\n", Fdo);
Fdo, &Fdo->DriverObject->DriverName);
IoSkipCurrentIrpStackLocation(Irp); IoSkipCurrentIrpStackLocation(Irp);
return IoCallDriver(Fdo, Irp); return IoCallDriver(Fdo, Irp);
} }
@ -180,3 +179,48 @@ ForwardIrpAndForget(
IoSkipCurrentIrpStackLocation(Irp); IoSkipCurrentIrpStackLocation(Irp);
return IoCallDriver(LowerDevice, Irp); return IoCallDriver(LowerDevice, Irp);
} }
NTSTATUS
DuplicateUnicodeString(
IN ULONG Flags,
IN PCUNICODE_STRING SourceString,
OUT PUNICODE_STRING DestinationString)
{
if (SourceString == NULL || DestinationString == NULL
|| SourceString->Length > SourceString->MaximumLength
|| (SourceString->Length == 0 && SourceString->MaximumLength > 0 && SourceString->Buffer == NULL)
|| Flags == RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING || Flags >= 4)
{
return STATUS_INVALID_PARAMETER;
}
if ((SourceString->Length == 0)
&& (Flags != (RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE |
RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING)))
{
DestinationString->Length = 0;
DestinationString->MaximumLength = 0;
DestinationString->Buffer = NULL;
}
else
{
USHORT DestMaxLength = SourceString->Length;
if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE)
DestMaxLength += sizeof(UNICODE_NULL);
DestinationString->Buffer = ExAllocatePoolWithTag(PagedPool, DestMaxLength, SERENUM_TAG);
if (DestinationString->Buffer == NULL)
return STATUS_NO_MEMORY;
RtlCopyMemory(DestinationString->Buffer, SourceString->Buffer, SourceString->Length);
DestinationString->Length = SourceString->Length;
DestinationString->MaximumLength = DestMaxLength;
if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE)
DestinationString->Buffer[DestinationString->Length / sizeof(WCHAR)] = 0;
}
return STATUS_SUCCESS;
}

View file

@ -7,7 +7,6 @@
* PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.com) * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.com)
*/ */
#define NDEBUG
#include "serenum.h" #include "serenum.h"
static NTSTATUS static NTSTATUS
@ -70,7 +69,7 @@ SerenumPdoQueryId(
return STATUS_NOT_SUPPORTED; return STATUS_NOT_SUPPORTED;
} }
Status = RtlDuplicateUnicodeString( Status = DuplicateUnicodeString(
RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE,
SourceString, SourceString,
&String); &String);

View file

@ -7,10 +7,14 @@
* PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.com) * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.com)
*/ */
#define NDEBUG
#define INITGUID #define INITGUID
#include "serenum.h" #include "serenum.h"
static DRIVER_DISPATCH SerenumPnp;
static DRIVER_DISPATCH IrpStub;
static DRIVER_UNLOAD DriverUnload;
DRIVER_INITIALIZE DriverEntry;
static NTSTATUS NTAPI static NTSTATUS NTAPI
SerenumPnp( SerenumPnp(
IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_OBJECT DeviceObject,

View file

@ -86,10 +86,7 @@ SerenumDetectLegacyDevice(
/************************************ fdo.c */ /************************************ fdo.c */
NTSTATUS NTAPI DRIVER_ADD_DEVICE SerenumAddDevice;
SerenumAddDevice(
IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT Pdo);
NTSTATUS NTSTATUS
SerenumFdoPnp( SerenumFdoPnp(
@ -123,6 +120,12 @@ ForwardIrpAndForget(
IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp); IN PIRP Irp);
NTSTATUS
DuplicateUnicodeString(
IN ULONG Flags,
IN PCUNICODE_STRING SourceString,
OUT PUNICODE_STRING DestinationString);
/************************************ pdo.c */ /************************************ pdo.c */
NTSTATUS NTSTATUS

View file

@ -1,6 +1,7 @@
<module name="serenum" type="kernelmodedriver" installbase="system32/drivers" installname="serenum.sys"> <module name="serenum" type="kernelmodedriver" installbase="system32/drivers" installname="serenum.sys">
<include base="serenum">.</include> <include base="serenum">.</include>
<define name="__USE_W32API" /> <define name="__USE_W32API" />
<define name="NDEBUG" />
<library>ntoskrnl</library> <library>ntoskrnl</library>
<library>hal</library> <library>hal</library>
<file>detect.c</file> <file>detect.c</file>