[Lldb-commits] [PATCH] Use GUIDs to make pipe names unique on Windows.

Adrian McCarthy amccarth at google.com
Mon Feb 9 16:04:24 PST 2015


Corrected pointer dereference.  The reinterpret_cast is necessary because RPC_CSTR is a pointer to unsigned char and llvm::StringRef doesn't have a constructor for that.  If I ditch the RPC_CSTR and just declare unique_string as a pointer to char, then I'd have to cast it in the call to UuidToString, which is uglier.


http://reviews.llvm.org/D7509

Files:
  cmake/LLDBDependencies.cmake
  source/Host/windows/PipeWindows.cpp

Index: cmake/LLDBDependencies.cmake
===================================================================
--- cmake/LLDBDependencies.cmake
+++ cmake/LLDBDependencies.cmake
@@ -69,6 +69,7 @@
     lldbPluginProcessElfCore
     lldbPluginJITLoaderGDB
     Ws2_32
+    Rpcrt4
     )
 endif ()
 
Index: source/Host/windows/PipeWindows.cpp
===================================================================
--- source/Host/windows/PipeWindows.cpp
+++ source/Host/windows/PipeWindows.cpp
@@ -15,6 +15,7 @@
 
 #include <fcntl.h>
 #include <io.h>
+#include <rpc.h>
 
 #include <atomic>
 #include <string>
@@ -96,14 +97,23 @@
 {
     llvm::SmallString<128> pipe_name;
     Error error;
-    do {
+    ::UUID unique_id;
+    RPC_CSTR unique_string;
+    RPC_STATUS status = ::UuidCreate(&unique_id);
+    if (status == RPC_S_OK || status == RPC_S_UUID_LOCAL_ONLY)
+        status = ::UuidToStringA(&unique_id, &unique_string);
+    if (status == RPC_S_OK)
+    {
         pipe_name = prefix;
         pipe_name += "-";
-        for (unsigned i = 0; i < 6; i++) {
-            pipe_name += "0123456789abcdef"[llvm::sys::Process::GetRandomNumber() & 15];
-        }
-        Error error = CreateNew(pipe_name, child_process_inherit);
-    } while (error.GetError() == ERROR_ALREADY_EXISTS);
+        pipe_name += reinterpret_cast<char *>(unique_string);
+        ::RpcStringFreeA(&unique_string);
+        error = CreateNew(pipe_name, child_process_inherit);
+    }
+    else
+    {
+        error.SetError(status, eErrorTypeWin32);
+    }
     if (error.Success())
         name = pipe_name;
     return error;

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7509.19624.patch
Type: text/x-patch
Size: 1598 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150210/c7208a37/attachment.bin>


More information about the lldb-commits mailing list