2010-04-02 17:57:33 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: BSD - See COPYING.ARM in the top level directory
|
|
|
|
* FILE: ntoskrnl/io/pnpmgr/pnputil.c
|
|
|
|
* PURPOSE: PnP Utility Code
|
|
|
|
* PROGRAMMERS: ReactOS Portable Systems Group
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
|
|
|
|
#include <ntoskrnl.h>
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
/* GLOBALS ********************************************************************/
|
|
|
|
|
|
|
|
/* FUNCTIONS ******************************************************************/
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
PnpFreeUnicodeStringList(IN PUNICODE_STRING UnicodeStringList,
|
|
|
|
IN ULONG StringCount)
|
|
|
|
{
|
|
|
|
ULONG i;
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Go through the list */
|
|
|
|
if (UnicodeStringList)
|
|
|
|
{
|
|
|
|
/* Go through each string */
|
|
|
|
for (i = 0; i < StringCount; i++)
|
|
|
|
{
|
|
|
|
/* Check if it exists */
|
|
|
|
if (UnicodeStringList[i].Buffer)
|
|
|
|
{
|
|
|
|
/* Free it */
|
|
|
|
ExFreePool(UnicodeStringList[i].Buffer);
|
|
|
|
}
|
|
|
|
}
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Free the whole list */
|
|
|
|
ExFreePool(UnicodeStringList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
PnpRegMultiSzToUnicodeStrings(IN PKEY_VALUE_FULL_INFORMATION KeyValueInformation,
|
|
|
|
OUT PUNICODE_STRING *UnicodeStringList,
|
|
|
|
OUT PULONG UnicodeStringCount)
|
|
|
|
{
|
|
|
|
PWCHAR p, pp, ps;
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
ULONG i = 0;
|
|
|
|
SIZE_T n;
|
2010-04-02 17:57:33 +00:00
|
|
|
ULONG Count = 0;
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Validate the key information */
|
|
|
|
if (KeyValueInformation->Type != REG_MULTI_SZ) return STATUS_INVALID_PARAMETER;
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Set the pointers */
|
|
|
|
p = (PWCHAR)((ULONG_PTR)KeyValueInformation +
|
|
|
|
KeyValueInformation->DataOffset);
|
|
|
|
pp = (PWCHAR)((ULONG_PTR)p + KeyValueInformation->DataLength);
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Loop the data */
|
|
|
|
while (p != pp)
|
|
|
|
{
|
|
|
|
/* If we find a NULL, that means one string is done */
|
|
|
|
if (!*p)
|
|
|
|
{
|
|
|
|
/* Add to our string count */
|
|
|
|
Count++;
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Check for a double-NULL, which means we're done */
|
|
|
|
if (((p + 1) == pp) || !(*(p + 1))) break;
|
|
|
|
}
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Go to the next character */
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we looped the whole list over, we missed increment a string, do it */
|
|
|
|
if (p == pp) Count++;
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Allocate the list now that we know how big it is */
|
|
|
|
*UnicodeStringList = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
sizeof(UNICODE_STRING) * Count,
|
|
|
|
'sUpP');
|
|
|
|
if (!(*UnicodeStringList)) return STATUS_INSUFFICIENT_RESOURCES;
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Set pointers for second loop */
|
|
|
|
ps = p = (PWCHAR)((ULONG_PTR)KeyValueInformation +
|
|
|
|
KeyValueInformation->DataOffset);
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Loop again, to do the copy this time */
|
|
|
|
while (p != pp)
|
|
|
|
{
|
|
|
|
/* If we find a NULL, that means one string is done */
|
|
|
|
if (!*p)
|
|
|
|
{
|
|
|
|
/* Check how long this string is */
|
|
|
|
n = (ULONG_PTR)p - (ULONG_PTR)ps + sizeof(UNICODE_NULL);
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Allocate the buffer */
|
|
|
|
(*UnicodeStringList)[i].Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
n,
|
|
|
|
'sUpP');
|
|
|
|
if (!(*UnicodeStringList)[i].Buffer)
|
|
|
|
{
|
|
|
|
/* Back out of everything */
|
|
|
|
PnpFreeUnicodeStringList(*UnicodeStringList, i);
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Copy the string into the buffer */
|
|
|
|
RtlCopyMemory((*UnicodeStringList)[i].Buffer, ps, n);
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Set the lengths */
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
(*UnicodeStringList)[i].MaximumLength = (USHORT)n;
|
|
|
|
(*UnicodeStringList)[i].Length = (USHORT)(n - sizeof(UNICODE_NULL));
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* One more entry done */
|
|
|
|
i++;
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Check for a double-NULL, which means we're done */
|
|
|
|
if (((p + 1) == pp) || !(*(p + 1))) break;
|
|
|
|
|
|
|
|
/* New string */
|
|
|
|
ps = p + 1;
|
|
|
|
}
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* New string */
|
|
|
|
p++;
|
|
|
|
}
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Check if we've reached the last string */
|
|
|
|
if (p == pp)
|
|
|
|
{
|
|
|
|
/* Calculate the string length */
|
|
|
|
n = (ULONG_PTR)p - (ULONG_PTR)ps;
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Allocate the buffer for it */
|
|
|
|
(*UnicodeStringList)[i].Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
n +
|
|
|
|
sizeof(UNICODE_NULL),
|
|
|
|
'sUpP');
|
|
|
|
if (!(*UnicodeStringList)[i].Buffer)
|
|
|
|
{
|
|
|
|
/* Back out of everything */
|
|
|
|
PnpFreeUnicodeStringList(*UnicodeStringList, i);
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Make sure there's an actual string here */
|
|
|
|
if (n) RtlCopyMemory((*UnicodeStringList)[i].Buffer, ps, n);
|
|
|
|
|
|
|
|
/* Null-terminate the string ourselves */
|
|
|
|
(*UnicodeStringList)[i].Buffer[n / sizeof(WCHAR)] = UNICODE_NULL;
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2013-04-04 19:29:36 +00:00
|
|
|
/* Set the lengths */
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
(*UnicodeStringList)[i].Length = (USHORT)n;
|
|
|
|
(*UnicodeStringList)[i].MaximumLength = (USHORT)(n + sizeof(UNICODE_NULL));
|
2010-04-02 17:57:33 +00:00
|
|
|
}
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* And we're done */
|
|
|
|
*UnicodeStringCount = Count;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
PnpRegSzToString(IN PWCHAR RegSzData,
|
|
|
|
IN ULONG RegSzLength,
|
|
|
|
OUT PUSHORT StringLength OPTIONAL)
|
|
|
|
{
|
|
|
|
PWCHAR p, pp;
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Find the end */
|
|
|
|
pp = RegSzData + RegSzLength;
|
|
|
|
for (p = RegSzData; p < pp; p++) if (!*p) break;
|
2014-10-22 19:34:46 +00:00
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
/* Return it */
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
if (StringLength) *StringLength = (USHORT)(p - RegSzData) * sizeof(WCHAR);
|
2010-04-02 17:57:33 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|