[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

llvm-svn: 340621
This commit is contained in:
David Carlier 2018-08-24 16:53:06 +00:00
parent b8ff56c726
commit 60251a5eb7
2 changed files with 8 additions and 5 deletions

View File

@ -1064,14 +1064,16 @@ void CheckNoDeepBind(const char *filename, int flag) {
// 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

View File

@ -354,7 +354,8 @@ TEST(SanitizerCommon, InternalScopedString) {
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 }) {