Skip to content

Commit a8fb2d0

Browse files
authored
[compiler-rt][rtsan] adding unlink/unlinkat interception. (llvm#128292)
1 parent 929d70a commit a8fb2d0

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,16 @@ INTERCEPTOR(ssize_t, readlinkat, int dirfd, const char *pathname, char *buf,
275275
#define RTSAN_MAYBE_INTERCEPT_READLINKAT
276276
#endif
277277

278+
INTERCEPTOR(int, unlink, const char *pathname) {
279+
__rtsan_notify_intercepted_call("unlink");
280+
return REAL(unlink)(pathname);
281+
}
282+
283+
INTERCEPTOR(int, unlinkat, int fd, const char *pathname, int flag) {
284+
__rtsan_notify_intercepted_call("unlinkat");
285+
return REAL(unlinkat)(fd, pathname, flag);
286+
}
287+
278288
// Streams
279289

280290
INTERCEPTOR(FILE *, fopen, const char *path, const char *mode) {
@@ -1425,6 +1435,8 @@ void __rtsan::InitializeInterceptors() {
14251435
INTERCEPT_FUNCTION(fchdir);
14261436
RTSAN_MAYBE_INTERCEPT_READLINK;
14271437
RTSAN_MAYBE_INTERCEPT_READLINKAT;
1438+
INTERCEPT_FUNCTION(unlink);
1439+
INTERCEPT_FUNCTION(unlinkat);
14281440
INTERCEPT_FUNCTION(fopen);
14291441
RTSAN_MAYBE_INTERCEPT_FOPEN64;
14301442
RTSAN_MAYBE_INTERCEPT_FREOPEN64;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,18 @@ TEST_F(RtsanOpenedFileTest, FwriteDiesWhenRealtime) {
863863
ExpectNonRealtimeSurvival(Func);
864864
}
865865

866+
TEST_F(RtsanOpenedFileTest, UnlinkDiesWhenRealtime) {
867+
auto Func = [&]() { unlink(GetTemporaryFilePath()); };
868+
ExpectRealtimeDeath(Func, "unlink");
869+
ExpectNonRealtimeSurvival(Func);
870+
}
871+
872+
TEST_F(RtsanOpenedFileTest, UnlinkatDiesWhenRealtime) {
873+
auto Func = [&]() { unlinkat(0, GetTemporaryFilePath(), 0); };
874+
ExpectRealtimeDeath(Func, "unlinkat");
875+
ExpectNonRealtimeSurvival(Func);
876+
}
877+
866878
TEST_F(RtsanFileTest, FcloseDiesWhenRealtime) {
867879
FILE *f = fopen(GetTemporaryFilePath(), "w");
868880
EXPECT_THAT(f, Ne(nullptr));

0 commit comments

Comments
 (0)