[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 5/6] Use CHAR for pipe stream data


  • To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
  • From: "Tu Dinh" <ngoc-tu.dinh@xxxxxxxxxx>
  • Date: Tue, 14 Apr 2026 11:44:28 +0000
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=mte1 header.d=mandrillapp.com header.i="@mandrillapp.com" header.h="From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID:Date:MIME-Version:Content-Type:Content-Transfer-Encoding"; dkim=pass header.s=mte1 header.d=vates.tech header.i="ngoc-tu.dinh@xxxxxxxxxx" header.h="From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID:Date:MIME-Version:Content-Type:Content-Transfer-Encoding"
  • Cc: "Tu Dinh" <ngoc-tu.dinh@xxxxxxxxxx>, "Owen Smith" <owen.smith@xxxxxxxxxx>
  • Delivery-date: Tue, 14 Apr 2026 11:49:31 +0000
  • Feedback-id: 30504962:30504962.20260414:md
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

As the console pipe is a byte stream, it should not use UCHAR or TCHAR.

Also convert the relevant API calls that use stream data to their A
variant.

Signed-off-by: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
---
 src/monitor/monitor.c |  8 ++--
 src/tty/tty.c         | 98 +++++++++++++++++++++----------------------
 2 files changed, 53 insertions(+), 53 deletions(-)

diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index 3ff7d7c..cd58207 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -326,7 +326,7 @@ __RemoveEntryList(
 static VOID
 PutString(
     _In_ HANDLE     Handle,
-    _In_ PUCHAR     Buffer,
+    _In_ PCHAR      Buffer,
     _In_ DWORD      Length
     )
 {
@@ -350,7 +350,7 @@ PutString(
 }
 
 #define ECHO(_Handle, _Buffer) \
-    PutString((_Handle), (PUCHAR)_Buffer, (DWORD)strlen((_Buffer)) * 
sizeof(CHAR))
+    PutString((_Handle), _Buffer, (DWORD)strlen((_Buffer)))
 
 DWORD WINAPI
 ConnectionThread(
@@ -359,7 +359,7 @@ ConnectionThread(
 {
     PMONITOR_CONNECTION Connection = (PMONITOR_CONNECTION)Argument;
     PMONITOR_CONSOLE    Console = Connection->Console;
-    UCHAR               Buffer[MAXIMUM_BUFFER_SIZE];
+    CHAR                Buffer[MAXIMUM_BUFFER_SIZE];
     OVERLAPPED          Overlapped;
     HANDLE              Handle[2];
     DWORD               Length;
@@ -583,7 +583,7 @@ DeviceThread(
     PMONITOR_CONSOLE    Console = (PMONITOR_CONSOLE)Argument;
     OVERLAPPED          Overlapped;
     HANDLE              Device;
-    UCHAR               Buffer[MAXIMUM_BUFFER_SIZE];
+    CHAR                Buffer[MAXIMUM_BUFFER_SIZE];
     DWORD               Length;
     DWORD               Wait;
     HANDLE              Handles[2];
diff --git a/src/tty/tty.c b/src/tty/tty.c
index d58bf96..a04c2ea 100644
--- a/src/tty/tty.c
+++ b/src/tty/tty.c
@@ -53,7 +53,7 @@ typedef struct _TTY_CONTEXT {
     TTY_STREAM          ChildStdIn;
     TTY_STREAM          ChildStdOut;
     TTY_STREAM          Device;
-    TCHAR               UserName[MAXIMUM_BUFFER_SIZE];
+    CHAR                UserName[MAXIMUM_BUFFER_SIZE];
     HANDLE              Token;
     HANDLE              OriginalToken;
     PROCESS_INFORMATION ProcessInfo;
@@ -141,12 +141,12 @@ CreateChild(
     )
 {
     PTTY_CONTEXT            Context = &TtyContext;
-    TCHAR                   CommandLine[] = 
TEXT("c:\\windows\\system32\\cmd.exe /q /a");
+    CHAR                    CommandLine[] = "c:\\windows\\system32\\cmd.exe /q 
/a";
     PVOID                   Environment;
-    PROFILEINFO             ProfileInfo;
+    PROFILEINFOA            ProfileInfo;
     DWORD                   Size;
-    TCHAR                   ProfileDir[MAXIMUM_BUFFER_SIZE];
-    STARTUPINFO             StartupInfo;
+    CHAR                    ProfileDir[MAXIMUM_BUFFER_SIZE];
+    STARTUPINFOA            StartupInfo;
     BOOL                    Success;
 
     Success = CreateEnvironmentBlock(&Environment,
@@ -159,15 +159,15 @@ CreateChild(
     ProfileInfo.dwSize = sizeof (ProfileInfo);
     ProfileInfo.lpUserName = Context->UserName;
 
-    Success = LoadUserProfile(Context->Token, &ProfileInfo);
+    Success = LoadUserProfileA(Context->Token, &ProfileInfo);
     if (!Success)
         return FALSE;
 
     Size = sizeof (ProfileDir);
 
-    Success = GetUserProfileDirectory(Context->Token,
-                                      ProfileDir,
-                                      &Size);
+    Success = GetUserProfileDirectoryA(Context->Token,
+                                       ProfileDir,
+                                       &Size);
     if (!Success)
         return FALSE;
 
@@ -185,17 +185,17 @@ CreateChild(
     StartupInfo.dwFlags |= STARTF_USESTDHANDLES;
 
 #pragma warning(suppress:6335) // leaking handle information
-    Success = CreateProcessAsUser(Context->Token,
-                                  NULL,
-                                  CommandLine,
-                                  NULL,
-                                  NULL,
-                                  TRUE,
-                                  CREATE_UNICODE_ENVIRONMENT,
-                                  Environment,
-                                  ProfileDir,
-                                  &StartupInfo,
-                                  &Context->ProcessInfo);
+    Success = CreateProcessAsUserA(Context->Token,
+                                   NULL,
+                                   CommandLine,
+                                   NULL,
+                                   NULL,
+                                   TRUE,
+                                   CREATE_UNICODE_ENVIRONMENT,
+                                   Environment,
+                                   ProfileDir,
+                                   &StartupInfo,
+                                   &Context->ProcessInfo);
 
     DestroyEnvironmentBlock(Environment);
 
@@ -210,7 +210,7 @@ CreateChild(
 static VOID
 PutCharacter(
     _In_ PTTY_STREAM    Stream,
-    _In_ TCHAR          Character
+    _In_ CHAR           Character
     )
 {
     WriteFile(Stream->Write,
@@ -223,11 +223,11 @@ PutCharacter(
 static VOID
 PutString(
     _In_ PTTY_STREAM    Stream,
-    _In_ PTCHAR         Buffer,
+    _In_ PCHAR          Buffer,
     _In_ DWORD          Length
     )
 {
-    DWORD               Offset;
+    DWORD           Offset;
 
     Offset = 0;
     while (Offset < Length) {
@@ -247,12 +247,12 @@ PutString(
 }
 
 #define ECHO(_Stream, _Buffer) \
-    PutString((_Stream), TEXT(_Buffer), (DWORD)_tcslen(_Buffer))
+    PutString((_Stream), (_Buffer), (DWORD)strlen(_Buffer))
 
 static BOOL
 GetLine(
     _In_ PTTY_STREAM    Stream,
-    _In_ PTCHAR         Buffer,
+    _In_ PCHAR          Buffer,
     _In_ DWORD          NumberOfBytesToRead,
     _Out_ LPDWORD       NumberOfBytesRead,
     _In_ BOOL           NoEcho
@@ -263,8 +263,8 @@ GetLine(
 
     Offset = 0;
     while (Offset < NumberOfBytesToRead) {
-        TCHAR   Sequence[MAXIMUM_BUFFER_SIZE];
-        PTCHAR  Character;
+        CHAR    Sequence[MAXIMUM_BUFFER_SIZE];
+        PCHAR   Character;
         DWORD   Read;
 
         Success = ReadFile(Stream->Read,
@@ -326,20 +326,20 @@ GetLine(
 
 static BOOL
 GetCredentials(
-    _In_ PTCHAR     Password,
-    _In_ DWORD      PasswordSize
+    _Out_writes_z_(PasswordSize) PCHAR  Password,
+    _In_ DWORD                          PasswordSize
     )
 {
     PTTY_CONTEXT    Context = &TtyContext;
-    TCHAR           ComputerName[MAX_COMPUTERNAME_LENGTH + 1];
-    PTCHAR          End;
+    CHAR            ComputerName[MAX_COMPUTERNAME_LENGTH + 1];
+    PCHAR           End;
     DWORD           Size;
     BOOL            Success;
 
     ZeroMemory(ComputerName, sizeof (ComputerName));
     Size = sizeof (ComputerName);
 
-    Success = GetComputerName(ComputerName, &Size);
+    Success = GetComputerNameA(ComputerName, &Size);
     if (!Success)
         return FALSE;
 
@@ -357,13 +357,13 @@ GetCredentials(
     if (!Success)
         return FALSE;
 
-    End = _tcschr(Context->UserName, TEXT('\r'));
+    End = strchr(Context->UserName, '\r');
     if (End == NULL)
         return FALSE;
 
-    *End = TEXT('\0');
+    *End = '\0';
 
-    if (_tcslen(Context->UserName) == 0)
+    if (strlen(Context->UserName) == 0)
         return FALSE;
 
     ECHO(&Context->Device, "Password: ");
@@ -378,7 +378,7 @@ GetCredentials(
     if (!Success)
         return FALSE;
 
-    End = _tcschr(Password, TEXT('\r'));
+    End = strchr(Password, TEXT('\r'));
     if (End == NULL)
         return FALSE;
 
@@ -395,8 +395,8 @@ RequestElevation(
     PTTY_CONTEXT            Context = &TtyContext;
     TOKEN_ELEVATION_TYPE    Elevation;
     DWORD                   Size;
-    TCHAR                   Buffer[MAXIMUM_BUFFER_SIZE];
-    PTCHAR                  End;
+    CHAR                    Buffer[MAXIMUM_BUFFER_SIZE];
+    PCHAR                   End;
     TOKEN_LINKED_TOKEN      LinkedToken;
     BOOL                    Success;
 
@@ -424,18 +424,18 @@ RequestElevation(
     if (!Success)
         return FALSE;
 
-    End = _tcschr(Buffer, TEXT('\r'));
+    End = strchr(Buffer, '\r');
     if (End == NULL)
         return FALSE;
 
-    *End = TEXT('\0');
+    *End = '\0';
 
-    if (_tcslen(Buffer) == 0)
+    if (strlen(Buffer) == 0)
         return FALSE;
 
     ECHO(&Context->Device, "\r\n");
 
-    if (_tcscmp(Buffer, TEXT("yes")) != 0)
+    if (strcmp(Buffer, "yes") != 0)
         return TRUE;
 
     Success = GetTokenInformation(Context->Token,
@@ -553,7 +553,7 @@ _tmain(
     PTTY_CONTEXT        Context = &TtyContext;
     SECURITY_ATTRIBUTES Attributes;
     HANDLE              Handle[3];
-    TCHAR               Password[MAXIMUM_BUFFER_SIZE];
+    CHAR                Password[MAXIMUM_BUFFER_SIZE];
     DWORD               Index;
     BOOL                Success;
 
@@ -594,12 +594,12 @@ _tmain(
     if (!Success)
         ExitProcess(1);
 
-    Success = LogonUser(Context->UserName,
-                        NULL,
-                        Password,
-                        LOGON32_LOGON_INTERACTIVE,
-                        LOGON32_PROVIDER_DEFAULT,
-                        &Context->Token);
+    Success = LogonUserA(Context->UserName,
+                         NULL,
+                         Password,
+                         LOGON32_LOGON_INTERACTIVE,
+                         LOGON32_PROVIDER_DEFAULT,
+                         &Context->Token);
 
     ZeroMemory(Password, sizeof(Password));
 
-- 
2.53.0.windows.2



--
Ngoc Tu Dinh | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.