|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [XENCONS PATCH 06/11] Switch from CHAR*/WCHAR* to PSTR/PWSTR
CHAR*/WCHAR* are currently used as string pointers in many places. These
can be safely replaced with PSTR/PWSTR (and their const equivalents) as
they only differ by annotations.
Signed-off-by: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
---
src/monitor/monitor.c | 43 ++++++++++++++++++++----------------------
src/tty/tty.c | 2 +-
src/xencons/console.c | 2 +-
src/xencons/fdo.c | 32 +++++++++++++++----------------
src/xencons/fdo.h | 4 ++--
src/xencons/frontend.c | 36 +++++++++++++++++------------------
src/xencons/frontend.h | 4 ++--
src/xencons/names.h | 18 +++++++++---------
src/xencons/pdo.c | 12 ++++++------
src/xencons/pdo.h | 4 ++--
10 files changed, 77 insertions(+), 80 deletions(-)
diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index 8f2a6a6..cefc3c2 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -73,7 +73,7 @@ typedef struct _MONITOR_CONSOLE {
PWCHAR DevicePath;
HANDLE DeviceHandle;
HDEVNOTIFY DeviceNotification;
- PCHAR DeviceName; // protocol and instance?
+ PSTR DeviceName; // protocol and instance?
HANDLE ExecutableThread;
HANDLE ExecutableEvent;
HANDLE DeviceThread;
@@ -111,8 +111,8 @@ static MONITOR_CONTEXT MonitorContext;
static VOID
#pragma prefast(suppress:6262) // Function uses '1036' bytes of stack: exceeds
/analyze:stacksize'1024'
__Log(
- _In_ const CHAR *Format,
- _In_ ...
+ _In_ PCSTR Format,
+ ...
)
{
#if DBG
@@ -125,10 +125,7 @@ __Log(
HRESULT Result;
va_start(Arguments, Format);
- Result = StringCchVPrintfA(Buffer,
- MAXIMUM_BUFFER_SIZE,
- Format,
- Arguments);
+ Result = StringCchVPrintfA(Buffer, MAXIMUM_BUFFER_SIZE, Format, Arguments);
va_end(Arguments);
if (Result != S_OK && Result != STRSAFE_E_INSUFFICIENT_BUFFER)
@@ -167,12 +164,12 @@ __Log(
#define Log(_Format, ...) \
__Log(__MODULE__ "|" __FUNCTION__ ": " _Format, __VA_ARGS__)
-static PCHAR
+static PSTR
GetErrorMessage(
_In_ HRESULT Error
)
{
- PCHAR Message;
+ PSTR Message;
ULONG Index;
if (!FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
@@ -196,7 +193,7 @@ GetErrorMessage(
return Message;
}
-static const CHAR *
+static PCSTR
ServiceStateName(
_In_ DWORD State
)
@@ -263,7 +260,7 @@ fail1:
Error = GetLastError();
{
- PCHAR Message;
+ PSTR Message;
Message = GetErrorMessage(Error);
Log("fail1 (%s)", Message);
LocalFree(Message);
@@ -668,16 +665,16 @@ fail1:
static BOOL
GetExecutable(
- _In_ PCHAR DeviceName,
- _Out_ PCHAR *Executable
+ _In_ PSTR DeviceName,
+ _Outptr_result_z_ PSTR *Executable
)
{
- PMONITOR_CONTEXT Context = &MonitorContext;
- HKEY Key;
- DWORD MaxValueLength;
- DWORD ExecutableLength;
- DWORD Type;
- HRESULT Error;
+ PMONITOR_CONTEXT Context = &MonitorContext;
+ HKEY Key;
+ DWORD MaxValueLength;
+ DWORD ExecutableLength;
+ DWORD Type;
+ HRESULT Error;
Error = RegOpenKeyExA(Context->ParametersKey,
DeviceName,
@@ -769,7 +766,7 @@ ExecutableThread(
)
{
PMONITOR_CONSOLE Console = (PMONITOR_CONSOLE)Argument;
- PCHAR Executable;
+ PSTR Executable;
PROCESS_INFORMATION ProcessInfo;
STARTUPINFO StartupInfo;
BOOL Success;
@@ -1053,7 +1050,7 @@ fail1:
Error = GetLastError();
{
- PCHAR Message;
+ PSTR Message;
Message = GetErrorMessage(Error);
Log("fail1 (%s)", Message);
LocalFree(Message);
@@ -1313,7 +1310,7 @@ MonitorEnumerate(
Error = GetLastError();
{
- PCHAR Message;
+ PSTR Message;
Message = GetErrorMessage(Error);
Log("fail2 (%s)", Message);
LocalFree(Message);
@@ -1330,7 +1327,7 @@ fail1:
Error = GetLastError();
{
- PCHAR Message;
+ PSTR Message;
Message = GetErrorMessage(Error);
Log("fail1 (%s)", Message);
LocalFree(Message);
diff --git a/src/tty/tty.c b/src/tty/tty.c
index 40d508a..4bfd74d 100644
--- a/src/tty/tty.c
+++ b/src/tty/tty.c
@@ -62,7 +62,7 @@ TTY_CONTEXT TtyContext;
static VOID
#pragma prefast(suppress:6262) // Function uses '1036' bytes of stack: exceeds
/analyze:stacksize'1024'
__Log(
- _In_ const CHAR *Format,
+ _In_ PCSTR Format,
_In_ ...
)
{
diff --git a/src/xencons/console.c b/src/xencons/console.c
index 0dd1825..c679bdb 100644
--- a/src/xencons/console.c
+++ b/src/xencons/console.c
@@ -276,7 +276,7 @@ __ConsoleDeviceControl(
ULONG InputBufferLength;
ULONG OutputBufferLength;
PVOID Buffer;
- PCHAR Value;
+ PSTR Value;
ULONG Length;
NTSTATUS status;
diff --git a/src/xencons/fdo.c b/src/xencons/fdo.c
index dabc830..102e159 100644
--- a/src/xencons/fdo.c
+++ b/src/xencons/fdo.c
@@ -367,7 +367,7 @@ __FdoSetVendorName(
ASSERT(NT_SUCCESS(status));
}
-static FORCEINLINE PCHAR
+static FORCEINLINE PSTR
__FdoGetVendorName(
_In_ PXENCONS_FDO Fdo
)
@@ -375,7 +375,7 @@ __FdoGetVendorName(
return Fdo->VendorName;
}
-PCHAR
+PSTR
FdoGetVendorName(
_In_ PXENCONS_FDO Fdo
)
@@ -398,7 +398,7 @@ __FdoSetName(
ASSERT(NT_SUCCESS(status));
}
-static FORCEINLINE PCHAR
+static FORCEINLINE PSTR
__FdoGetName(
_In_ PXENCONS_FDO Fdo
)
@@ -408,7 +408,7 @@ __FdoGetName(
return Dx->Name;
}
-PCHAR
+PSTR
FdoGetName(
_In_ PXENCONS_FDO Fdo
)
@@ -745,7 +745,7 @@ __FdoEnumerate(
}
if (PdoGetDevicePnpState(Pdo) != Deleted) {
- PCHAR Name;
+ PSTR Name;
BOOLEAN Missing;
Name = PdoGetName(Pdo);
@@ -811,7 +811,7 @@ done:
static FORCEINLINE PANSI_STRING
__FdoMultiSzToUpcaseAnsi(
- _In_ PCHAR Buffer
+ _In_ PSTR Buffer
)
{
PANSI_STRING Ansi;
@@ -905,7 +905,7 @@ FdoScan(
ParametersKey = DriverGetParametersKey();
for (;;) {
- PCHAR Buffer;
+ PSTR Buffer;
PANSI_STRING Devices;
PANSI_STRING UnsupportedDevices;
ULONG Index;
@@ -1009,13 +1009,13 @@ FdoScan(
static FORCEINLINE BOOLEAN
__FdoMatchDistribution(
_In_ PXENCONS_FDO Fdo,
- _In_ PCHAR Buffer
+ _In_ PSTR Buffer
)
{
- PCHAR Vendor;
- PCHAR Product;
- PCHAR Context;
- const CHAR *Text;
+ PSTR Vendor;
+ PSTR Product;
+ PSTR Context;
+ PCSTR Text;
BOOLEAN Match;
ULONG Index;
NTSTATUS status;
@@ -1050,7 +1050,7 @@ __FdoMatchDistribution(
}
}
- Text = "XENCONS";
+ Text = "XENBUS";
if (_stricmp(Product, Text) != 0)
Match = FALSE;
@@ -1071,7 +1071,7 @@ FdoClearDistribution(
_In_ PXENCONS_FDO Fdo
)
{
- PCHAR Buffer;
+ PSTR Buffer;
PANSI_STRING Distributions;
ULONG Index;
NTSTATUS status;
@@ -1137,14 +1137,14 @@ FdoSetDistribution(
ULONG Index;
CHAR Distribution[MAXNAMELEN];
CHAR Vendor[MAXNAMELEN];
- const CHAR *Product;
+ PCSTR Product;
NTSTATUS status;
Trace("====>\n");
Index = 0;
while (Index <= MAXIMUM_INDEX) {
- PCHAR Buffer;
+ PSTR Buffer;
status = RtlStringCbPrintfA(Distribution,
MAXNAMELEN,
diff --git a/src/xencons/fdo.h b/src/xencons/fdo.h
index 3681d5b..d616e40 100644
--- a/src/xencons/fdo.h
+++ b/src/xencons/fdo.h
@@ -43,12 +43,12 @@
#include "driver.h"
-extern PCHAR
+extern PSTR
FdoGetVendorName(
_In_ PXENCONS_FDO Fdo
);
-extern PCHAR
+extern PSTR
FdoGetName(
_In_ PXENCONS_FDO Fdo
);
diff --git a/src/xencons/frontend.c b/src/xencons/frontend.c
index 384a042..24845c5 100644
--- a/src/xencons/frontend.c
+++ b/src/xencons/frontend.c
@@ -65,17 +65,17 @@ typedef enum _FRONTEND_STATE {
struct _XENCONS_FRONTEND {
LONG References;
PXENCONS_PDO Pdo;
- PCHAR Path;
+ PSTR Path;
FRONTEND_STATE State;
KSPIN_LOCK Lock;
PXENCONS_THREAD EjectThread;
KEVENT EjectEvent;
BOOLEAN Online;
- PCHAR BackendPath;
+ PSTR BackendPath;
USHORT BackendDomain;
- PCHAR Name;
- PCHAR Protocol;
+ PSTR Name;
+ PSTR Protocol;
XENBUS_DEBUG_INTERFACE DebugInterface;
XENBUS_SUSPEND_INTERFACE SuspendInterface;
@@ -88,7 +88,7 @@ struct _XENCONS_FRONTEND {
PXENCONS_RING Ring;
};
-static const PCHAR
+static PCSTR
FrontendStateName(
_In_ FRONTEND_STATE State
)
@@ -112,7 +112,7 @@ FrontendStateName(
#undef _STATE_NAME
}
-static const PCHAR
+static PCSTR
XenbusStateName(
_In_ XenbusState State
)
@@ -172,7 +172,7 @@ FrontendGetPdo(
return __FrontendGetPdo(Frontend);
}
-static FORCEINLINE PCHAR
+static FORCEINLINE PSTR
__FrontendGetPath(
_In_ PXENCONS_FRONTEND Frontend
)
@@ -180,7 +180,7 @@ __FrontendGetPath(
return Frontend->Path;
}
-PCHAR
+PSTR
FrontendGetPath(
_In_ PXENCONS_FRONTEND Frontend
)
@@ -188,7 +188,7 @@ FrontendGetPath(
return __FrontendGetPath(Frontend);
}
-static FORCEINLINE PCHAR
+static FORCEINLINE PSTR
__FrontendGetBackendPath(
_In_ PXENCONS_FRONTEND Frontend
)
@@ -196,7 +196,7 @@ __FrontendGetBackendPath(
return Frontend->BackendPath;
}
-PCHAR
+PSTR
FrontendGetBackendPath(
_In_ PXENCONS_FRONTEND Frontend
)
@@ -233,7 +233,7 @@ FrontendIsBackendOnline(
_In_ PXENCONS_FRONTEND Frontend
)
{
- PCHAR Buffer;
+ PSTR Buffer;
BOOLEAN Online;
NTSTATUS status;
@@ -315,7 +315,7 @@ FrontendEjectFailed(
{
KIRQL Irql;
ULONG Length;
- PCHAR Path;
+ PSTR Path;
NTSTATUS status;
KeAcquireSpinLock(&Frontend->Lock, &Irql);
@@ -453,7 +453,7 @@ FrontendWaitForBackendXenbusStateChange(
Timeout.QuadPart = 0;
while (*State == Old && TimeDelta < 120000) {
- PCHAR Buffer;
+ PSTR Buffer;
LARGE_INTEGER Now;
if (Watch != NULL) {
@@ -515,7 +515,7 @@ FrontendAcquireBackend(
_In_ PXENCONS_FRONTEND Frontend
)
{
- PCHAR Buffer;
+ PSTR Buffer;
NTSTATUS status;
Trace("=====>\n");
@@ -735,7 +735,7 @@ FrontendConnect(
{
XenbusState State;
ULONG Attempt;
- PCHAR Buffer;
+ PSTR Buffer;
ULONG Length;
NTSTATUS status;
@@ -1243,7 +1243,7 @@ FrontendGetProperty(
ULONG InputBufferLength;
ULONG OutputBufferLength;
PVOID Buffer;
- PCHAR Value;
+ PSTR Value;
ULONG Length;
NTSTATUS status;
@@ -1493,9 +1493,9 @@ FrontendCreate(
_Out_ PXENCONS_CONSOLE_ABI_CONTEXT *Context
)
{
- PCHAR Name;
+ PSTR Name;
ULONG Length;
- PCHAR Path;
+ PSTR Path;
PXENCONS_FRONTEND Frontend;
NTSTATUS status;
diff --git a/src/xencons/frontend.h b/src/xencons/frontend.h
index e57d083..416c389 100644
--- a/src/xencons/frontend.h
+++ b/src/xencons/frontend.h
@@ -62,12 +62,12 @@ FrontendGetPdo(
_In_ PXENCONS_FRONTEND Frontend
);
-extern PCHAR
+extern PSTR
FrontendGetPath(
_In_ PXENCONS_FRONTEND Frontend
);
-extern PCHAR
+extern PSTR
FrontendGetBackendPath(
_In_ PXENCONS_FRONTEND Frontend
);
diff --git a/src/xencons/names.h b/src/xencons/names.h
index 84519f3..ef6130d 100644
--- a/src/xencons/names.h
+++ b/src/xencons/names.h
@@ -35,7 +35,7 @@
#include <ntddk.h>
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PowerTypeName(
_In_ POWER_STATE_TYPE Type
)
@@ -55,7 +55,7 @@ PowerTypeName(
#undef _POWER_ACTION_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PowerSystemStateName(
_In_ SYSTEM_POWER_STATE State
)
@@ -81,7 +81,7 @@ PowerSystemStateName(
#undef _POWER_SYSTEM_STATE_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PowerDeviceStateName(
_In_ DEVICE_POWER_STATE State
)
@@ -105,7 +105,7 @@ PowerDeviceStateName(
#undef _POWER_DEVICE_STATE_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PowerActionName(
_In_ POWER_ACTION Type
)
@@ -131,7 +131,7 @@ PowerActionName(
#undef _POWER_ACTION_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PowerMinorFunctionName(
_In_ ULONG MinorFunction
)
@@ -154,7 +154,7 @@ PowerMinorFunctionName(
#undef _POWER_MINOR_FUNCTION_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PnpMinorFunctionName(
_In_ ULONG Function
)
@@ -197,7 +197,7 @@ PnpMinorFunctionName(
#undef _PNP_MINOR_FUNCTION_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PartialResourceDescriptorTypeName(
_In_ UCHAR Type
)
@@ -226,7 +226,7 @@ PartialResourceDescriptorTypeName(
#undef _PARTIAL_RESOURCE_DESCRIPTOR_TYPE_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
DeviceUsageTypeName(
_In_ DEVICE_USAGE_NOTIFICATION_TYPE Type
)
@@ -248,7 +248,7 @@ DeviceUsageTypeName(
#undef _DEVICE_USAGE_TYPE_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
MajorFunctionName(
_In_ ULONG Function
)
diff --git a/src/xencons/pdo.c b/src/xencons/pdo.c
index b1d5507..3ddc553 100644
--- a/src/xencons/pdo.c
+++ b/src/xencons/pdo.c
@@ -69,7 +69,7 @@ struct _XENCONS_PDO {
PXENCONS_FDO Fdo;
BOOLEAN Missing;
- const CHAR *Reason;
+ PCSTR Reason;
LONG Eject;
XENBUS_SUSPEND_INTERFACE SuspendInterface;
@@ -195,7 +195,7 @@ __PdoGetDevicePowerState(
static FORCEINLINE VOID
__PdoSetMissing(
_In_ PXENCONS_PDO Pdo,
- _In_ const CHAR *Reason
+ _In_ PCSTR Reason
)
{
Pdo->Reason = Reason;
@@ -205,7 +205,7 @@ __PdoSetMissing(
VOID
PdoSetMissing(
_In_ PXENCONS_PDO Pdo,
- _In_ const CHAR *Reason
+ _In_ PCSTR Reason
)
{
__PdoSetMissing(Pdo, Reason);
@@ -282,7 +282,7 @@ __PdoSetName(
ASSERT(NT_SUCCESS(status));
}
-static FORCEINLINE PCHAR
+static FORCEINLINE PSTR
__PdoGetName(
_In_ PXENCONS_PDO Pdo
)
@@ -292,7 +292,7 @@ __PdoGetName(
return Dx->Name;
}
-PCHAR
+PSTR
PdoGetName(
_In_ PXENCONS_PDO Pdo
)
@@ -300,7 +300,7 @@ PdoGetName(
return __PdoGetName(Pdo);
}
-static FORCEINLINE PCHAR
+static FORCEINLINE PSTR
__PdoGetVendorName(
_In_ PXENCONS_PDO Pdo
)
diff --git a/src/xencons/pdo.h b/src/xencons/pdo.h
index 12b334e..db38da5 100644
--- a/src/xencons/pdo.h
+++ b/src/xencons/pdo.h
@@ -55,7 +55,7 @@ PdoGetDevicePnpState(
extern VOID
PdoSetMissing(
_In_ PXENCONS_PDO Pdo,
- _In_ const CHAR *Reason
+ _In_ PCSTR Reason
);
extern BOOLEAN
@@ -73,7 +73,7 @@ PdoIsEjectRequested(
_In_ PXENCONS_PDO Pdo
);
-extern PCHAR
+extern PSTR
PdoGetName(
_In_ PXENCONS_PDO Pdo
);
--
2.51.0.windows.1
--
Ngoc Tu Dinh | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |