Skip to content

Commit b2b3cb5

Browse files
authored
[compiler-rt][rtsan] memffd_create for linux interception. (#132571)
1 parent fb44f00 commit b2b3cb5

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,17 @@ INTERCEPTOR(int, shm_unlink, const char *name) {
10311031
return REAL(shm_unlink)(name);
10321032
}
10331033

1034+
#if !SANITIZER_APPLE
1035+
// is supported by freebsd too
1036+
INTERCEPTOR(int, memfd_create, const char *path, unsigned int flags) {
1037+
__rtsan_notify_intercepted_call("memfd_create");
1038+
return REAL(memfd_create)(path, flags);
1039+
}
1040+
#define RTSAN_MAYBE_INTERCEPT_MEMFD_CREATE INTERCEPT_FUNCTION(memfd_create)
1041+
#else
1042+
#define RTSAN_MAYBE_INTERCEPT_MEMFD_CREATE
1043+
#endif
1044+
10341045
// Sockets
10351046
INTERCEPTOR(int, getaddrinfo, const char *node, const char *service,
10361047
const struct addrinfo *hints, struct addrinfo **res) {
@@ -1465,6 +1476,7 @@ void __rtsan::InitializeInterceptors() {
14651476
INTERCEPT_FUNCTION(mincore);
14661477
INTERCEPT_FUNCTION(shm_open);
14671478
INTERCEPT_FUNCTION(shm_unlink);
1479+
RTSAN_MAYBE_INTERCEPT_MEMFD_CREATE;
14681480
RTSAN_MAYBE_INTERCEPT_MEMALIGN;
14691481
RTSAN_MAYBE_INTERCEPT_PVALLOC;
14701482

compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,14 @@ TEST(TestRtsanInterceptors, ShmUnlinkDiesWhenRealtime) {
302302
ExpectNonRealtimeSurvival(Func);
303303
}
304304

305+
#if !SANITIZER_APPLE
306+
TEST(TestRtsanInterceptors, MemfdCreateDiesWhenRealtime) {
307+
auto Func = []() { memfd_create("/rtsan_test_memfd_create", MFD_CLOEXEC); };
308+
ExpectRealtimeDeath(Func, "memfd_create");
309+
ExpectNonRealtimeSurvival(Func);
310+
}
311+
#endif
312+
305313
/*
306314
Sleeping
307315
*/

0 commit comments

Comments
 (0)