[PATCH] D50937: [Sanitizer] implementing remaining function under OSX

David CARLIER via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 24 09:54:08 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL340621: [Sanitizer] implementing remaining function under OSX (authored by devnexen, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D50937?vs=162397&id=162402#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50937

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
  compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc


Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
@@ -1064,14 +1064,16 @@
   // Do nothing.
 }
 
-// FIXME: implement on this platform.
 bool GetRandom(void *buffer, uptr length, bool blocking) {
-  UNIMPLEMENTED();
+  if (!buffer || !length || length > 256)
+    return false;
+  // arc4random never fails.
+  arc4random_buf(buffer, length);
+  return true;
 }
 
-// FIXME: implement on this platform.
 u32 GetNumberOfCPUs() {
-  UNIMPLEMENTED();
+  return (u32)sysconf(_SC_NPROCESSORS_ONLN);
 }
 
 }  // namespace __sanitizer
Index: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc
@@ -354,7 +354,8 @@
   EXPECT_STREQ("012345678", str.data());
 }
 
-#if SANITIZER_LINUX
+#if SANITIZER_LINUX || SANITIZER_FREEBSD || \
+  SANITIZER_OPENBSD || SANITIZER_MAC || SANITIZER_IOS
 TEST(SanitizerCommon, GetRandom) {
   u8 buffer_1[32], buffer_2[32];
   for (bool blocking : { false, true }) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50937.162402.patch
Type: text/x-patch
Size: 1325 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180824/acd1059d/attachment.bin>


More information about the llvm-commits mailing list