Skip to content

Commit 97fd435

Browse files
authored
[rtsan] intercept accept4 syscall. (#117278)
1 parent d457100 commit 97fd435

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-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
@@ -707,6 +707,17 @@ INTERCEPTOR(int, shutdown, int socket, int how) {
707707
return REAL(shutdown)(socket, how);
708708
}
709709

710+
#if SANITIZER_INTERCEPT_ACCEPT4
711+
INTERCEPTOR(int, accept4, int socket, struct sockaddr *address,
712+
socklen_t *address_len, int flags) {
713+
__rtsan_notify_intercepted_call("accept4");
714+
return REAL(accept4)(socket, address, address_len, flags);
715+
}
716+
#define RTSAN_MAYBE_INTERCEPT_ACCEPT4 INTERCEPT_FUNCTION(accept4)
717+
#else
718+
#define RTSAN_MAYBE_INTERCEPT_ACCEPT4
719+
#endif
720+
710721
// I/O Multiplexing
711722

712723
INTERCEPTOR(int, poll, struct pollfd *fds, nfds_t nfds, int timeout) {
@@ -956,6 +967,7 @@ void __rtsan::InitializeInterceptors() {
956967
INTERCEPT_FUNCTION(sendto);
957968
INTERCEPT_FUNCTION(shutdown);
958969
INTERCEPT_FUNCTION(socket);
970+
RTSAN_MAYBE_INTERCEPT_ACCEPT4;
959971

960972
RTSAN_MAYBE_INTERCEPT_SELECT;
961973
INTERCEPT_FUNCTION(pselect);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,16 @@ TEST(TestRtsanInterceptors, AcceptingASocketDiesWhenRealtime) {
860860
ExpectNonRealtimeSurvival(Func);
861861
}
862862

863+
#if SANITIZER_INTERCEPT_ACCEPT4
864+
TEST(TestRtsanInterceptors, Accepting4ASocketDiesWhenRealtime) {
865+
auto Func = []() {
866+
EXPECT_LT(accept4(kNotASocketFd, nullptr, nullptr, 0), 0);
867+
};
868+
ExpectRealtimeDeath(Func, "accept4");
869+
ExpectNonRealtimeSurvival(Func);
870+
}
871+
#endif
872+
863873
TEST(TestRtsanInterceptors, ConnectingASocketDiesWhenRealtime) {
864874
auto Func = []() { EXPECT_NE(connect(kNotASocketFd, nullptr, 0), 0); };
865875
ExpectRealtimeDeath(Func, "connect");

0 commit comments

Comments
 (0)