Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,16 @@ INTERCEPTOR(ssize_t, readlinkat, int dirfd, const char *pathname, char *buf,
#define RTSAN_MAYBE_INTERCEPT_READLINKAT
#endif

INTERCEPTOR(int, unlink, const char *pathname) {
__rtsan_notify_intercepted_call("unlink");
return REAL(unlink)(pathname);
}

INTERCEPTOR(int, unlinkat, int fd, const char *pathname, int flag) {
__rtsan_notify_intercepted_call("unlinkat");
return REAL(unlinkat)(fd, pathname, flag);
}

// Streams

INTERCEPTOR(FILE *, fopen, const char *path, const char *mode) {
Expand Down Expand Up @@ -1425,6 +1435,8 @@ void __rtsan::InitializeInterceptors() {
INTERCEPT_FUNCTION(fchdir);
RTSAN_MAYBE_INTERCEPT_READLINK;
RTSAN_MAYBE_INTERCEPT_READLINKAT;
INTERCEPT_FUNCTION(unlink);
INTERCEPT_FUNCTION(unlinkat);
INTERCEPT_FUNCTION(fopen);
RTSAN_MAYBE_INTERCEPT_FOPEN64;
RTSAN_MAYBE_INTERCEPT_FREOPEN64;
Expand Down
12 changes: 12 additions & 0 deletions compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,18 @@ TEST_F(RtsanOpenedFileTest, FwriteDiesWhenRealtime) {
ExpectNonRealtimeSurvival(Func);
}

TEST_F(RtsanOpenedFileTest, UnlinkDiesWhenRealtime) {
auto Func = [&]() { unlink(GetTemporaryFilePath()); };
ExpectRealtimeDeath(Func, "unlink");
ExpectNonRealtimeSurvival(Func);
}

TEST_F(RtsanOpenedFileTest, UnlinkatDiesWhenRealtime) {
auto Func = [&]() { unlinkat(0, GetTemporaryFilePath(), 0); };
ExpectRealtimeDeath(Func, "unlinkat");
ExpectNonRealtimeSurvival(Func);
}

TEST_F(RtsanFileTest, FcloseDiesWhenRealtime) {
FILE *f = fopen(GetTemporaryFilePath(), "w");
EXPECT_THAT(f, Ne(nullptr));
Expand Down