-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler-rt] Implement getrandom interception
Summary: Straightforward implementation of `getrandom` syscall and libc hooks. Test Plan: Local MSAN failures caused by uninstrumented `getrandom` calls stop failing. Patch by Andrew Krieger. Reviewers: eugenis, vitalybuka Reviewed By: vitalybuka Subscribers: srhines, kubamracek, dberris, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D65551 llvm-svn: 367999
- Loading branch information
1 parent
dba4dd1
commit ac9ee01
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
compiler-rt/test/sanitizer_common/TestCases/Linux/getrandom.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// RUN: %clangxx -O2 %s -o %t && %run %t | ||
// UNSUPPORTED: android | ||
// | ||
|
||
#include <sys/types.h> | ||
|
||
#if !defined(__GLIBC_PREREQ) | ||
#define __GLIBC_PREREQ(a, b) 0 | ||
#endif | ||
|
||
#if __GLIBC_PREREQ(2, 25) | ||
#include <sys/random.h> | ||
#endif | ||
|
||
int main() { | ||
char buf[16]; | ||
ssize_t n = 1; | ||
#if __GLIBC_PREREQ(2, 25) | ||
n = getrandom(buf, sizeof(buf), 0); | ||
#endif | ||
return (int)(n <= 0); | ||
} |