summaryrefslogtreecommitdiff
path: root/src/pal
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal')
-rw-r--r--src/pal/inc/pal.h8
-rw-r--r--src/pal/inc/rt/palrt.h3
-rw-r--r--src/pal/src/CMakeLists.txt1
-rw-r--r--src/pal/src/config.h.in2
-rw-r--r--src/pal/src/configure.cmake31
-rw-r--r--src/pal/src/misc/miscpalapi.cpp120
6 files changed, 31 insertions, 134 deletions
diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h
index 18fbdab8bc..462accd4f9 100644
--- a/src/pal/inc/pal.h
+++ b/src/pal/inc/pal.h
@@ -526,10 +526,9 @@ PAL_GetPALDirectoryW(
#endif
PALIMPORT
-BOOL
+VOID
PALAPI
PAL_Random(
- IN BOOL bStrong,
IN OUT LPVOID lpBuffer,
IN DWORD dwLength);
@@ -4876,11 +4875,6 @@ SetThreadIdealProcessorEx(
#define EVENTLOG_AUDIT_SUCCESS 0x0008
#define EVENTLOG_AUDIT_FAILURE 0x0010
-PALIMPORT
-HRESULT
-PALAPI
-CoCreateGuid(OUT GUID * pguid);
-
#if defined FEATURE_PAL_ANSI
#include "palprivate.h"
#endif //FEATURE_PAL_ANSI
diff --git a/src/pal/inc/rt/palrt.h b/src/pal/inc/rt/palrt.h
index af76e0424e..1360a81c43 100644
--- a/src/pal/inc/rt/palrt.h
+++ b/src/pal/inc/rt/palrt.h
@@ -1577,6 +1577,9 @@ EXTERN_C HRESULT PALAPI PAL_CoCreateInstance(REFCLSID rclsid,
// instead of spreading around of if'def FEATURE_PALs for PAL_CoCreateInstance.
#define CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv) PAL_CoCreateInstance(rclsid, riid, ppv)
+STDAPI
+CoCreateGuid(OUT GUID * pguid);
+
/************** verrsrc.h ************************************/
/* ----- VS_VERSION.dwFileFlags ----- */
diff --git a/src/pal/src/CMakeLists.txt b/src/pal/src/CMakeLists.txt
index 3ef0dd12de..0285d8878c 100644
--- a/src/pal/src/CMakeLists.txt
+++ b/src/pal/src/CMakeLists.txt
@@ -345,7 +345,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux)
target_link_libraries(coreclrpal
dl
- uuid
)
if(NOT UNWIND_GENERIC STREQUAL UNWIND_GENERIC-NOTFOUND)
diff --git a/src/pal/src/config.h.in b/src/pal/src/config.h.in
index 5643c1b399..584b28aff4 100644
--- a/src/pal/src/config.h.in
+++ b/src/pal/src/config.h.in
@@ -15,8 +15,6 @@
#cmakedefine01 HAVE_SYS_LWP_H
#cmakedefine01 HAVE_LWP_H
#cmakedefine01 HAVE_LIBUNWIND_H
-#cmakedefine01 HAVE_LIBUUID_H
-#cmakedefine01 HAVE_BSD_UUID_H
#cmakedefine01 HAVE_RUNETYPE_H
#cmakedefine01 HAVE_SYS_SYSCTL_H
#cmakedefine01 HAVE_GNU_LIBNAMES_H
diff --git a/src/pal/src/configure.cmake b/src/pal/src/configure.cmake
index 0f105eee94..a6dd6f49c4 100644
--- a/src/pal/src/configure.cmake
+++ b/src/pal/src/configure.cmake
@@ -48,7 +48,6 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL FreeBSD AND NOT CMAKE_SYSTEM_NAME STREQUAL Net
unset(CMAKE_REQUIRED_FLAGS)
endif()
-check_include_files(uuid/uuid.h HAVE_LIBUUID_H)
check_include_files(sys/sysctl.h HAVE_SYS_SYSCTL_H)
check_include_files(gnu/lib-names.h HAVE_GNU_LIBNAMES_H)
@@ -170,16 +169,6 @@ check_cxx_symbol_exists(_SC_PHYS_PAGES unistd.h HAVE__SC_PHYS_PAGES)
check_cxx_symbol_exists(_SC_AVPHYS_PAGES unistd.h HAVE__SC_AVPHYS_PAGES)
check_cxx_source_runs("
-#include <uuid.h>
-
-int main(void) {
- uuid_t uuid;
- uint32_t status;
- uuid_create(&uuid, &status);
- return 0;
-}" HAVE_BSD_UUID_H)
-
-check_cxx_source_runs("
#include <sys/param.h>
#include <stdlib.h>
@@ -1271,10 +1260,6 @@ if(NOT CLR_CMAKE_PLATFORM_ARCH_ARM AND NOT CLR_CMAKE_PLATFORM_ARCH_ARM64)
endif()
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)
@@ -1291,10 +1276,6 @@ 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)
@@ -1309,10 +1290,6 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL NetBSD)
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), (void*)(addr), (data))")
set(PAL_PT_ATTACH PT_ATTACH)
@@ -1328,10 +1305,6 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL SunOS)
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_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), (caddr_t)(addr), (data))")
set(PAL_PT_ATTACH PT_ATTACH)
@@ -1348,10 +1321,6 @@ 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 0e1234401e..27ff136a06 100644
--- a/src/pal/src/misc/miscpalapi.cpp
+++ b/src/pal/src/misc/miscpalapi.cpp
@@ -34,12 +34,6 @@ Revision History:
#include <pthread.h>
#include <dlfcn.h>
-#if HAVE_BSD_UUID_H
-#include <uuid.h>
-#elif HAVE_LIBUUID_H
-#include <uuid/uuid.h>
-#endif
-
#include <pal_endian.h>
#ifdef __APPLE__
@@ -48,7 +42,6 @@ Revision History:
SET_DEFAULT_DEBUG_CHANNEL(MISC);
-static const char RANDOM_DEVICE_NAME[] ="/dev/random";
static const char URANDOM_DEVICE_NAME[]="/dev/urandom";
/*++
@@ -235,90 +228,64 @@ PAL_GetPALDirectoryA(
return bRet;
}
-BOOL
+VOID
PALAPI
PAL_Random(
- IN BOOL bStrong,
IN OUT LPVOID lpBuffer,
IN DWORD dwLength)
{
int rand_des = -1;
- BOOL bRet = FALSE;
DWORD i;
- char buf;
long num = 0;
- static BOOL sMissingDevRandom;
static BOOL sMissingDevURandom;
static BOOL sInitializedMRand;
PERF_ENTRY(PAL_Random);
- ENTRY("PAL_Random(bStrong=%d, lpBuffer=%p, dwLength=%d)\n",
- bStrong, lpBuffer, dwLength);
+ ENTRY("PAL_Random(lpBuffer=%p, dwLength=%d)\n", lpBuffer, dwLength);
- i = 0;
-
- if (bStrong == TRUE && i < dwLength && !sMissingDevRandom)
+ if (!sMissingDevURandom)
{
- // request non-blocking access to avoid hangs if the /dev/random is exhausted
- // or just simply broken
- if ((rand_des = PAL__open(RANDOM_DEVICE_NAME, O_RDONLY | O_NONBLOCK)) == -1)
+ do
{
- if (errno == ENOENT)
- {
- sMissingDevRandom = TRUE;
- }
- else
- {
- ASSERT("PAL__open() failed, errno:%d (%s)\n", errno, strerror(errno));
- }
-
- // Back off and try /dev/urandom.
+ rand_des = open("/dev/urandom", O_RDONLY, O_CLOEXEC);
}
- else
- {
- for( ; i < dwLength; i++)
- {
- if (read(rand_des, &buf, 1) < 1)
- {
- // the /dev/random pool has been exhausted. Fall back
- // to /dev/urandom for the remainder of the buffer.
- break;
- }
+ while ((rand_des == -1) && (errno == EINTR));
- *(((BYTE*)lpBuffer) + i) ^= buf;
- }
-
- close(rand_des);
- }
- }
-
- if (i < dwLength && !sMissingDevURandom)
- {
- if ((rand_des = PAL__open(URANDOM_DEVICE_NAME, O_RDONLY)) == -1)
+ if (rand_des == -1)
{
if (errno == ENOENT)
{
- sMissingDevURandom = TRUE;
+ sMissingDevURandom = TRUE;
}
else
{
- ASSERT("PAL__open() failed, errno:%d (%s)\n", errno, strerror(errno));
+ ASSERT("PAL__open() failed, errno:%d (%s)\n", errno, strerror(errno));
}
- // Back off and try mrand48.
+ // Back off and try mrand48.
}
else
{
- for( ; i < dwLength; i++)
+ DWORD offset = 0;
+ do
{
- if (read(rand_des, &buf, 1) < 1)
+ DWORD n = read(rand_des, (BYTE*)lpBuffer + offset , dwLength - offset);
+ if (n == -1)
{
- // Fall back to srand48 for the remainder of the buffer.
+ if (errno == EINTR)
+ {
+ continue;
+ }
+ ASSERT("read() failed, errno:%d (%s)\n", errno, strerror(errno));
+
break;
}
- *(((BYTE*)lpBuffer) + i) ^= buf;
+ offset += n;
}
+ while (offset != dwLength);
+
+ _ASSERTE(offset == dwLength);
close(rand_des);
}
@@ -331,9 +298,9 @@ PAL_Random(
}
// always xor srand48 over the whole buffer to get some randomness
- // in case /dev/random is not really random
+ // in case /dev/urandom is not really random
- for(i = 0; i < dwLength; i++)
+ for (i = 0; i < dwLength; i++)
{
if (i % sizeof(long) == 0) {
num = mrand48();
@@ -343,39 +310,6 @@ PAL_Random(
num >>= 8;
}
- bRet = TRUE;
-
- LOGEXIT("PAL_Random returns %d\n", bRet);
+ LOGEXIT("PAL_Random\n");
PERF_EXIT(PAL_Random);
- return bRet;
-}
-
-HRESULT
-PALAPI
-CoCreateGuid(OUT GUID * pguid)
-{
-#if 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);
- PROCAbort();
- }
-
- // Encode the uuid with little endian.
- uuid_enc_le(pguid, &uuid);
-#elif HAVE_LIBUUID_H
- uuid_generate_random(*(uuid_t*)pguid);
-
- // Change the byte order of the Data1, 2 and 3, since the uuid_generate_random
- // 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);
-#else
- #error Don't know how to generate UUID on this platform
-#endif
- return 0;
}