[compiler-rt] r340621 - [Sanitizer] implementing remaining function under OSX
David Carlier via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 24 09:53:06 PDT 2018
Author: devnexen
Date: Fri Aug 24 09:53:06 2018
New Revision: 340621
URL: http://llvm.org/viewvc/llvm-project?rev=340621&view=rev
Log:
[Sanitizer] implementing remaining function under OSX
- GetRandom and GetnumberOfCPUs using sys call for the former.
- enabling unit tests for the other oses.
Reviewers: kubamracek
Reviewed By: kubamracek
Differential Revision: https://reviews.llvm.org/D50937
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=340621&r1=340620&r2=340621&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Fri Aug 24 09:53:06 2018
@@ -1064,14 +1064,16 @@ void CheckNoDeepBind(const char *filenam
// 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
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc?rev=340621&r1=340620&r2=340621&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc Fri Aug 24 09:53:06 2018
@@ -354,7 +354,8 @@ TEST(SanitizerCommon, InternalScopedStri
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 }) {
More information about the llvm-commits
mailing list