Skip to content

Commit e21b804

Browse files
authored
[compiler-rt][rtsan] socketpair interception. (#124107)
1 parent cfdd7d7 commit e21b804

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,11 @@ INTERCEPTOR(int, setsockopt, int socket, int level, int option,
10881088
#define RTSAN_MAYBE_INTERCEPT_SETSOCKOPT
10891089
#endif
10901090

1091+
INTERCEPTOR(int, socketpair, int domain, int type, int protocol, int pair[2]) {
1092+
__rtsan_notify_intercepted_call("socketpair");
1093+
return REAL(socketpair)(domain, type, protocol, pair);
1094+
}
1095+
10911096
// I/O Multiplexing
10921097

10931098
INTERCEPTOR(int, poll, struct pollfd *fds, nfds_t nfds, int timeout) {
@@ -1459,6 +1464,7 @@ void __rtsan::InitializeInterceptors() {
14591464
RTSAN_MAYBE_INTERCEPT_GETPEERNAME;
14601465
RTSAN_MAYBE_INTERCEPT_GETSOCKOPT;
14611466
RTSAN_MAYBE_INTERCEPT_SETSOCKOPT;
1467+
INTERCEPT_FUNCTION(socketpair);
14621468

14631469
RTSAN_MAYBE_INTERCEPT_SELECT;
14641470
INTERCEPT_FUNCTION(pselect);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,13 @@ TEST(TestRtsanInterceptors, SetsockoptOnASocketDiesWhenRealtime) {
13511351
}
13521352
#endif
13531353

1354+
TEST(TestRtsanInterceptors, SocketpairDiesWhenRealtime) {
1355+
int pair[2]{};
1356+
auto Func = [&pair]() { socketpair(0, 0, 0, pair); };
1357+
ExpectRealtimeDeath(Func, "socketpair");
1358+
ExpectNonRealtimeSurvival(Func);
1359+
}
1360+
13541361
/*
13551362
I/O Multiplexing
13561363
*/

0 commit comments

Comments
 (0)