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

[win-pv-devel] [PATCH 1/2] Don't use C runtime versions of toupper() and tolower()



It seems that, despite their trivial functionality, the runtime
implementation insists on converting to Unicode! This means those functions
are actually only safe at PASSIVE_LEVEL.
This patch implements __toupper() and __tolower() as replacements with
no such hidden nastiness and modifies callers to use those.

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/common/util.h | 22 ++++++++++++++++++++++
 src/xen/module.c  |  2 +-
 src/xenbus/fdo.c  |  2 +-
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/common/util.h b/src/common/util.h
index 1a2bb86..c772b1e 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -278,4 +278,26 @@ __strtok_r(
     return Token;
 }
 
+static FORCEINLINE CHAR
+__toupper(
+    IN  CHAR    Character
+    )
+{
+    if (Character < 'a' || Character > 'z')
+        return Character;
+
+    return 'A' + Character - 'a';
+}
+
+static FORCEINLINE CHAR
+__tolower(
+    IN  CHAR    Character
+    )
+{
+    if (Character < 'A' || Character > 'Z')
+        return Character;
+
+    return 'a' + Character - 'A';
+}
+
 #endif  // _COMMON_UTIL_H
diff --git a/src/xen/module.c b/src/xen/module.c
index ed8838a..a5bf3c7 100644
--- a/src/xen/module.c
+++ b/src/xen/module.c
@@ -155,7 +155,7 @@ ModuleAdd(
         if (Name[Index] == '\0')
             break;
 
-        New->Name[Index] = (CHAR)tolower(Name[Index]);
+        New->Name[Index] = __tolower(Name[Index]);
     }
 
     New->Start = Start;
diff --git a/src/xenbus/fdo.c b/src/xenbus/fdo.c
index 00801c9..d079928 100644
--- a/src/xenbus/fdo.c
+++ b/src/xenbus/fdo.c
@@ -1129,7 +1129,7 @@ FdoMultiSzToUpcaseAnsi(
             if (Buffer[Index] == '\0')
                 break;
         } else {
-            Buffer[Index] = (CHAR)toupper(Buffer[Index]);
+            Buffer[Index] = __toupper(Buffer[Index]);
             Index++;
         }
     }
-- 
2.1.1


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel


 


Rackspace

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