summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Vorlicek <janvorli@microsoft.com>2015-10-09 20:56:43 +0200
committerJan Vorlicek <janvorli@microsoft.com>2015-10-13 15:39:38 +0200
commitdbd046be21faab7346db55f3dd638162a20f3941 (patch)
tree656033472290e8f0eaebeb3dc16148235859d8ea
parent2e70585b98e6371aae2d00f3fcf537de0a3cfdab (diff)
downloadcoreclr-dbd046be21faab7346db55f3dd638162a20f3941.tar.gz
coreclr-dbd046be21faab7346db55f3dd638162a20f3941.tar.bz2
coreclr-dbd046be21faab7346db55f3dd638162a20f3941.zip
Implement CoCreateGuid using uuid_generate on Unix
We were generating GUIDs on Unix as random numbers. But that is not correct since GUIDs have defined structure with bits having specific meanings. For example, there are four bits that represent the type of the GUID, which means whether the guid is randomly generated, name based on SHA1, time based etc. This change changes the CoCreateGuid to use the uuid_generate function from the uuid library that should generate well-formed GUIDs on Linux and OSX and the uuid_create on FreeBSD.
-rw-r--r--Documentation/building/linux-instructions.md3
-rw-r--r--src/pal/inc/pal.h4
-rw-r--r--src/pal/inc/pal_endian.h21
-rw-r--r--src/pal/inc/rt/palrt.h2
-rw-r--r--src/pal/src/CMakeLists.txt1
-rw-r--r--src/pal/src/config.h.in2
-rw-r--r--src/pal/src/configure.cmake15
-rw-r--r--src/pal/src/misc/miscpalapi.cpp37
-rw-r--r--src/palrt/coguid.cpp11
9 files changed, 78 insertions, 18 deletions
diff --git a/Documentation/building/linux-instructions.md b/Documentation/building/linux-instructions.md
index 73d1b925ab..837f60948a 100644
--- a/Documentation/building/linux-instructions.md
+++ b/Documentation/building/linux-instructions.md
@@ -27,6 +27,7 @@ Install the following packages for the toolchain:
- gettext
- libicu-dev
- liblttng-ust-dev
+- uuid-dev
In order to get lldb-3.6 on Ubuntu 14.04, we need to add an additional package source:
@@ -38,7 +39,7 @@ ellismg@linux:~$ sudo apt-get update
Then install the packages you need:
-`ellismg@linux:~$ sudo apt-get install cmake llvm-3.5 clang-3.5 lldb-3.6 lldb-3.6-dev libunwind8 libunwind8-dev gettext libicu-dev liblttng-ust-dev`
+`ellismg@linux:~$ sudo apt-get install cmake llvm-3.5 clang-3.5 lldb-3.6 lldb-3.6-dev libunwind8 libunwind8-dev gettext libicu-dev liblttng-ust-dev uuid-dev`
You now have all the required components.
diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h
index 575d4a905b..44e9cd4b56 100644
--- a/src/pal/inc/pal.h
+++ b/src/pal/inc/pal.h
@@ -5674,6 +5674,10 @@ ReportEventW (
#define ReportEvent ReportEventA
#endif // !UNICODE
+PALIMPORT
+HRESULT
+PALAPI
+CoCreateGuid(OUT GUID * pguid);
/******************* C Runtime Entrypoints *******************************/
diff --git a/src/pal/inc/pal_endian.h b/src/pal/inc/pal_endian.h
index d0bae64acf..54d06d22b2 100644
--- a/src/pal/inc/pal_endian.h
+++ b/src/pal/inc/pal_endian.h
@@ -14,15 +14,14 @@
#ifndef __PAL_ENDIAN_H__
#define __PAL_ENDIAN_H__
-#if BIGENDIAN
#ifdef __cplusplus
extern "C++" {
-inline UINT16 VAL16(UINT16 x)
+inline UINT16 SWAP16(UINT16 x)
{
return (x >> 8) | (x << 8);
}
-inline UINT32 VAL32(UINT32 x)
+inline UINT32 SWAP32(UINT32 x)
{
return (x >> 24) |
((x >> 8) & 0x0000FF00L) |
@@ -30,6 +29,22 @@ inline UINT32 VAL32(UINT32 x)
(x << 24);
}
+}
+#endif // __cplusplus
+
+#if BIGENDIAN
+#ifdef __cplusplus
+extern "C++" {
+inline UINT16 VAL16(UINT16 x)
+{
+ return SWAP16(x);
+}
+
+inline UINT32 VAL32(UINT32 x)
+{
+ return SWAP32(x);
+}
+
inline UINT64 VAL64(UINT64 x)
{
return ((UINT64)VAL32(x) << 32) | VAL32(x >> 32);
diff --git a/src/pal/inc/rt/palrt.h b/src/pal/inc/rt/palrt.h
index 2c9bf146d4..3e3d178ea4 100644
--- a/src/pal/inc/rt/palrt.h
+++ b/src/pal/inc/rt/palrt.h
@@ -748,8 +748,6 @@ STDAPI CreateStreamOnHGlobal(PVOID hGlobal, BOOL fDeleteOnRelease, interface ISt
STDAPI IIDFromString(LPOLESTR lpsz, IID* lpiid);
STDAPI_(int) StringFromGUID2(REFGUID rguid, LPOLESTR lpsz, int cchMax);
-STDAPI CoCreateGuid(OUT GUID * pguid);
-
/******************* CRYPT **************************************/
#define PUBLICKEYBLOB 0x6
diff --git a/src/pal/src/CMakeLists.txt b/src/pal/src/CMakeLists.txt
index 1e8363969a..f1a254687d 100644
--- a/src/pal/src/CMakeLists.txt
+++ b/src/pal/src/CMakeLists.txt
@@ -221,6 +221,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux)
dl
unwind
unwind-generic
+ uuid
)
endif(CMAKE_SYSTEM_NAME STREQUAL Linux)
diff --git a/src/pal/src/config.h.in b/src/pal/src/config.h.in
index 4c06de0eca..2abb791831 100644
--- a/src/pal/src/config.h.in
+++ b/src/pal/src/config.h.in
@@ -14,6 +14,8 @@
#cmakedefine01 HAVE_PTHREAD_NP_H
#cmakedefine01 HAVE_SYS_LWP_H
#cmakedefine01 HAVE_LIBUNWIND_H
+#cmakedefine01 HAVE_LIBUUID_H
+#cmakedefine01 HAVE_BSD_UUID_H
#cmakedefine01 HAVE_RUNETYPE_H
#cmakedefine01 HAVE_KQUEUE
diff --git a/src/pal/src/configure.cmake b/src/pal/src/configure.cmake
index c89fb27a6c..29dd16a33b 100644
--- a/src/pal/src/configure.cmake
+++ b/src/pal/src/configure.cmake
@@ -28,6 +28,8 @@ check_include_files(sys/lwp.h HAVE_SYS_LWP_H)
check_include_files(libunwind.h HAVE_LIBUNWIND_H)
check_include_files(runetype.h HAVE_RUNETYPE_H)
check_include_files(lttng/tracepoint.h HAVE_LTTNG_TRACEPOINT_H)
+check_include_files(uuid/uuid.h HAVE_LIBUUID_H)
+check_include_files(uuid.h HAVE_BSD_UUID_H)
check_function_exists(kqueue HAVE_KQUEUE)
check_function_exists(getpwuid_r HAVE_GETPWUID_R)
@@ -860,6 +862,10 @@ int main(int argc, char **argv)
}" UNWIND_CONTEXT_IS_UCONTEXT_T)
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
+ if(NOT HAVE_LIBUUID_H)
+ unset(HAVE_LIBUUID_H CACHE)
+ message(FATAL_ERROR "Cannot find libuuid. Try installing uuid-dev or the appropriate packages for your platform")
+ endif()
set(HAVE_COREFOUNDATION 1)
set(HAVE__NSGETENVIRON 1)
set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 1)
@@ -878,6 +884,10 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
unset(HAVE_LIBUNWIND_H CACHE)
message(FATAL_ERROR "Cannot find libunwind. Try installing libunwind8 and libunwind8-dev (or the appropriate packages for your platform)")
endif()
+ if(NOT HAVE_BSD_UUID_H)
+ unset(HAVE_BSD_UUID_H CACHE)
+ message(FATAL_ERROR "Cannot find uuid.h")
+ endif()
set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 0)
set(PAL_PTRACE "ptrace((cmd), (pid), (caddr_t)(addr), (data))")
set(PAL_PT_ATTACH PT_ATTACH)
@@ -905,7 +915,10 @@ else() # Anything else is Linux
unset(HAVE_LTTNG_TRACEPOINT_H CACHE)
message(FATAL_ERROR "Cannot find liblttng-ust-dev. Try installing liblttng-ust-dev (or the appropriate packages for your platform)")
endif()
-
+ if(NOT HAVE_LIBUUID_H)
+ unset(HAVE_LIBUUID_H CACHE)
+ message(FATAL_ERROR "Cannot find libuuid. Try installing uuid-dev or the appropriate packages for your platform")
+ endif()
set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 0)
set(PAL_PTRACE "ptrace((cmd), (pid), (void*)(addr), (data))")
set(PAL_PT_ATTACH PTRACE_ATTACH)
diff --git a/src/pal/src/misc/miscpalapi.cpp b/src/pal/src/misc/miscpalapi.cpp
index 45596a513e..0aeeb89b99 100644
--- a/src/pal/src/misc/miscpalapi.cpp
+++ b/src/pal/src/misc/miscpalapi.cpp
@@ -33,6 +33,14 @@ Revision History:
#include <pthread.h>
#include <dlfcn.h>
+#if HAVE_LIBUUID_H
+#include <uuid/uuid.h>
+#elif HAVE_BSD_UUID_H
+#include <uuid.h>
+#endif
+
+#include <pal_endian.h>
+
#ifdef __APPLE__
#include <mach-o/dyld.h>
#endif // __APPLE__
@@ -311,3 +319,32 @@ PAL_Random(
return bRet;
}
+HRESULT
+PALAPI
+CoCreateGuid(OUT GUID * pguid)
+{
+#if HAVE_LIBUUID_H
+ uuid_generate(*(uuid_t*)pguid);
+
+ // Change the byte order of the Data1, 2 and 3, since the uuid_generate generates them
+ // with big endian while GUIDS need to have them in little endian.
+ pguid->Data1 = SWAP32(pguid->Data1);
+ pguid->Data2 = SWAP16(pguid->Data2);
+ pguid->Data3 = SWAP16(pguid->Data3);
+#elif HAVE_BSD_UUID_H
+ uuid_t uuid;
+ uint32_t status;
+ uuid_create(&uuid, &status);
+ if (status != uuid_s_ok)
+ {
+ ASSERT("Unexpected uuid_create failure (status=%u)\n", status);
+ abort();
+ }
+
+ // Encode the uuid with little endian.
+ uuid_enc_le(pguid, &uuid);
+#else
+ #error Don't know how to generate UUID on this platform
+#endif
+ return 0;
+}
diff --git a/src/palrt/coguid.cpp b/src/palrt/coguid.cpp
index 69398fb427..c78229a15d 100644
--- a/src/palrt/coguid.cpp
+++ b/src/palrt/coguid.cpp
@@ -13,17 +13,6 @@
#include "common.h"
-STDAPI CoCreateGuid(OUT GUID * pguid)
-{
- if (!PAL_Random(FALSE, pguid, sizeof(GUID)))
- {
- DWORD dwError = GetLastError();
- return HRESULT_FROM_WIN32(dwError);
- }
-
- return S_OK;
-}
-
STDAPI_(int) StringFromGUID2(REFGUID rguid, LPOLESTR lptsz, int cchMax)
{
if (cchMax < 39)