Skip to content

Commit cf1319f

Browse files
authored
[compiler-rt] Mark more calls as blocking (#77789)
If we're in a blocking call, we need to run the signal immediately, as the call may not return for a very long time (if ever). Not running the handler can cause deadlocks if the rest of the program waits (in one way or another) for the signal handler to execute. I've gone through the list of functions in sanitizer_common_interceptors and marked as blocking those that I know can block, but I don't claim the list to be exhaustive. In particular, I did not mark libc FILE* functions as blocking, because these can end up calling user functions. To do that correctly, /I think/ it would be necessary to clear the "is in blocking call" flag inside the fopencookie wrappers. The test for the bug (deadlock) uses the read call (which is the one that I ran into originally), but the same kind of test could be written for any other blocking syscall.
1 parent 4a21e3a commit cf1319f

File tree

3 files changed

+107
-39
lines changed

3 files changed

+107
-39
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ INTERCEPTOR(SSIZE_T, read, int fd, void *ptr, SIZE_T count) {
974974
// FIXME: under ASan the call below may write to freed memory and corrupt
975975
// its metadata. See
976976
// https://github.com/google/sanitizers/issues/321.
977-
SSIZE_T res = REAL(read)(fd, ptr, count);
977+
SSIZE_T res = COMMON_INTERCEPTOR_BLOCK_REAL(read)(fd, ptr, count);
978978
if (res > 0) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ptr, res);
979979
if (res >= 0 && fd >= 0) COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
980980
return res;
@@ -1009,7 +1009,7 @@ INTERCEPTOR(SSIZE_T, pread, int fd, void *ptr, SIZE_T count, OFF_T offset) {
10091009
// FIXME: under ASan the call below may write to freed memory and corrupt
10101010
// its metadata. See
10111011
// https://github.com/google/sanitizers/issues/321.
1012-
SSIZE_T res = REAL(pread)(fd, ptr, count, offset);
1012+
SSIZE_T res = COMMON_INTERCEPTOR_BLOCK_REAL(pread)(fd, ptr, count, offset);
10131013
if (res > 0) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ptr, res);
10141014
if (res >= 0 && fd >= 0) COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
10151015
return res;
@@ -1027,7 +1027,7 @@ INTERCEPTOR(SSIZE_T, pread64, int fd, void *ptr, SIZE_T count, OFF64_T offset) {
10271027
// FIXME: under ASan the call below may write to freed memory and corrupt
10281028
// its metadata. See
10291029
// https://github.com/google/sanitizers/issues/321.
1030-
SSIZE_T res = REAL(pread64)(fd, ptr, count, offset);
1030+
SSIZE_T res = COMMON_INTERCEPTOR_BLOCK_REAL(pread64)(fd, ptr, count, offset);
10311031
if (res > 0) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ptr, res);
10321032
if (res >= 0 && fd >= 0) COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
10331033
return res;
@@ -1043,7 +1043,7 @@ INTERCEPTOR_WITH_SUFFIX(SSIZE_T, readv, int fd, __sanitizer_iovec *iov,
10431043
void *ctx;
10441044
COMMON_INTERCEPTOR_ENTER(ctx, readv, fd, iov, iovcnt);
10451045
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
1046-
SSIZE_T res = REAL(readv)(fd, iov, iovcnt);
1046+
SSIZE_T res = COMMON_INTERCEPTOR_BLOCK_REAL(readv)(fd, iov, iovcnt);
10471047
if (res > 0) write_iovec(ctx, iov, iovcnt, res);
10481048
if (res >= 0 && fd >= 0) COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
10491049
return res;
@@ -1059,7 +1059,7 @@ INTERCEPTOR(SSIZE_T, preadv, int fd, __sanitizer_iovec *iov, int iovcnt,
10591059
void *ctx;
10601060
COMMON_INTERCEPTOR_ENTER(ctx, preadv, fd, iov, iovcnt, offset);
10611061
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
1062-
SSIZE_T res = REAL(preadv)(fd, iov, iovcnt, offset);
1062+
SSIZE_T res = COMMON_INTERCEPTOR_BLOCK_REAL(preadv)(fd, iov, iovcnt, offset);
10631063
if (res > 0) write_iovec(ctx, iov, iovcnt, res);
10641064
if (res >= 0 && fd >= 0) COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
10651065
return res;
@@ -1075,7 +1075,8 @@ INTERCEPTOR(SSIZE_T, preadv64, int fd, __sanitizer_iovec *iov, int iovcnt,
10751075
void *ctx;
10761076
COMMON_INTERCEPTOR_ENTER(ctx, preadv64, fd, iov, iovcnt, offset);
10771077
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
1078-
SSIZE_T res = REAL(preadv64)(fd, iov, iovcnt, offset);
1078+
SSIZE_T res =
1079+
COMMON_INTERCEPTOR_BLOCK_REAL(preadv64)(fd, iov, iovcnt, offset);
10791080
if (res > 0) write_iovec(ctx, iov, iovcnt, res);
10801081
if (res >= 0 && fd >= 0) COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
10811082
return res;
@@ -1091,8 +1092,9 @@ INTERCEPTOR(SSIZE_T, write, int fd, void *ptr, SIZE_T count) {
10911092
COMMON_INTERCEPTOR_ENTER(ctx, write, fd, ptr, count);
10921093
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
10931094
if (fd >= 0) COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd);
1094-
SSIZE_T res = REAL(write)(fd, ptr, count);
1095-
// FIXME: this check should be _before_ the call to REAL(write), not after
1095+
SSIZE_T res = COMMON_INTERCEPTOR_BLOCK_REAL(write)(fd, ptr, count);
1096+
// FIXME: this check should be _before_ the call to
1097+
// COMMON_INTERCEPTOR_BLOCK_REAL(write), not after
10961098
if (res > 0) COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, res);
10971099
return res;
10981100
}
@@ -1121,7 +1123,7 @@ INTERCEPTOR(SSIZE_T, pwrite, int fd, void *ptr, SIZE_T count, OFF_T offset) {
11211123
COMMON_INTERCEPTOR_ENTER(ctx, pwrite, fd, ptr, count, offset);
11221124
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
11231125
if (fd >= 0) COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd);
1124-
SSIZE_T res = REAL(pwrite)(fd, ptr, count, offset);
1126+
SSIZE_T res = COMMON_INTERCEPTOR_BLOCK_REAL(pwrite)(fd, ptr, count, offset);
11251127
if (res > 0) COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, res);
11261128
return res;
11271129
}
@@ -1137,7 +1139,7 @@ INTERCEPTOR(SSIZE_T, pwrite64, int fd, void *ptr, OFF64_T count,
11371139
COMMON_INTERCEPTOR_ENTER(ctx, pwrite64, fd, ptr, count, offset);
11381140
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
11391141
if (fd >= 0) COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd);
1140-
SSIZE_T res = REAL(pwrite64)(fd, ptr, count, offset);
1142+
SSIZE_T res = COMMON_INTERCEPTOR_BLOCK_REAL(pwrite64)(fd, ptr, count, offset);
11411143
if (res > 0) COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, res);
11421144
return res;
11431145
}
@@ -1153,7 +1155,7 @@ INTERCEPTOR_WITH_SUFFIX(SSIZE_T, writev, int fd, __sanitizer_iovec *iov,
11531155
COMMON_INTERCEPTOR_ENTER(ctx, writev, fd, iov, iovcnt);
11541156
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
11551157
if (fd >= 0) COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd);
1156-
SSIZE_T res = REAL(writev)(fd, iov, iovcnt);
1158+
SSIZE_T res = COMMON_INTERCEPTOR_BLOCK_REAL(writev)(fd, iov, iovcnt);
11571159
if (res > 0) read_iovec(ctx, iov, iovcnt, res);
11581160
return res;
11591161
}
@@ -1169,7 +1171,7 @@ INTERCEPTOR(SSIZE_T, pwritev, int fd, __sanitizer_iovec *iov, int iovcnt,
11691171
COMMON_INTERCEPTOR_ENTER(ctx, pwritev, fd, iov, iovcnt, offset);
11701172
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
11711173
if (fd >= 0) COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd);
1172-
SSIZE_T res = REAL(pwritev)(fd, iov, iovcnt, offset);
1174+
SSIZE_T res = COMMON_INTERCEPTOR_BLOCK_REAL(pwritev)(fd, iov, iovcnt, offset);
11731175
if (res > 0) read_iovec(ctx, iov, iovcnt, res);
11741176
return res;
11751177
}
@@ -1185,7 +1187,8 @@ INTERCEPTOR(SSIZE_T, pwritev64, int fd, __sanitizer_iovec *iov, int iovcnt,
11851187
COMMON_INTERCEPTOR_ENTER(ctx, pwritev64, fd, iov, iovcnt, offset);
11861188
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
11871189
if (fd >= 0) COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd);
1188-
SSIZE_T res = REAL(pwritev64)(fd, iov, iovcnt, offset);
1190+
SSIZE_T res =
1191+
COMMON_INTERCEPTOR_BLOCK_REAL(pwritev64)(fd, iov, iovcnt, offset);
11891192
if (res > 0) read_iovec(ctx, iov, iovcnt, res);
11901193
return res;
11911194
}
@@ -2549,7 +2552,7 @@ INTERCEPTOR_WITH_SUFFIX(int, wait, int *status) {
25492552
// FIXME: under ASan the call below may write to freed memory and corrupt
25502553
// its metadata. See
25512554
// https://github.com/google/sanitizers/issues/321.
2552-
int res = REAL(wait)(status);
2555+
int res = COMMON_INTERCEPTOR_BLOCK_REAL(wait)(status);
25532556
if (res != -1 && status)
25542557
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, status, sizeof(*status));
25552558
return res;
@@ -2567,7 +2570,7 @@ INTERCEPTOR_WITH_SUFFIX(int, waitid, int idtype, int id, void *infop,
25672570
// FIXME: under ASan the call below may write to freed memory and corrupt
25682571
// its metadata. See
25692572
// https://github.com/google/sanitizers/issues/321.
2570-
int res = REAL(waitid)(idtype, id, infop, options);
2573+
int res = COMMON_INTERCEPTOR_BLOCK_REAL(waitid)(idtype, id, infop, options);
25712574
if (res != -1 && infop)
25722575
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, infop, siginfo_t_sz);
25732576
return res;
@@ -2578,7 +2581,7 @@ INTERCEPTOR_WITH_SUFFIX(int, waitpid, int pid, int *status, int options) {
25782581
// FIXME: under ASan the call below may write to freed memory and corrupt
25792582
// its metadata. See
25802583
// https://github.com/google/sanitizers/issues/321.
2581-
int res = REAL(waitpid)(pid, status, options);
2584+
int res = COMMON_INTERCEPTOR_BLOCK_REAL(waitpid)(pid, status, options);
25822585
if (res != -1 && status)
25832586
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, status, sizeof(*status));
25842587
return res;
@@ -2589,7 +2592,7 @@ INTERCEPTOR(int, wait3, int *status, int options, void *rusage) {
25892592
// FIXME: under ASan the call below may write to freed memory and corrupt
25902593
// its metadata. See
25912594
// https://github.com/google/sanitizers/issues/321.
2592-
int res = REAL(wait3)(status, options, rusage);
2595+
int res = COMMON_INTERCEPTOR_BLOCK_REAL(wait3)(status, options, rusage);
25932596
if (res != -1) {
25942597
if (status) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, status, sizeof(*status));
25952598
if (rusage) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, rusage, struct_rusage_sz);
@@ -2603,7 +2606,8 @@ INTERCEPTOR(int, __wait4, int pid, int *status, int options, void *rusage) {
26032606
// FIXME: under ASan the call below may write to freed memory and corrupt
26042607
// its metadata. See
26052608
// https://github.com/google/sanitizers/issues/321.
2606-
int res = REAL(__wait4)(pid, status, options, rusage);
2609+
int res =
2610+
COMMON_INTERCEPTOR_BLOCK_REAL(__wait4)(pid, status, options, rusage);
26072611
if (res != -1) {
26082612
if (status) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, status, sizeof(*status));
26092613
if (rusage) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, rusage, struct_rusage_sz);
@@ -2618,7 +2622,7 @@ INTERCEPTOR(int, wait4, int pid, int *status, int options, void *rusage) {
26182622
// FIXME: under ASan the call below may write to freed memory and corrupt
26192623
// its metadata. See
26202624
// https://github.com/google/sanitizers/issues/321.
2621-
int res = REAL(wait4)(pid, status, options, rusage);
2625+
int res = COMMON_INTERCEPTOR_BLOCK_REAL(wait4)(pid, status, options, rusage);
26222626
if (res != -1) {
26232627
if (status) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, status, sizeof(*status));
26242628
if (rusage) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, rusage, struct_rusage_sz);
@@ -2996,7 +3000,7 @@ INTERCEPTOR(int, accept, int fd, void *addr, unsigned *addrlen) {
29963000
COMMON_INTERCEPTOR_READ_RANGE(ctx, addrlen, sizeof(*addrlen));
29973001
addrlen0 = *addrlen;
29983002
}
2999-
int fd2 = REAL(accept)(fd, addr, addrlen);
3003+
int fd2 = COMMON_INTERCEPTOR_BLOCK_REAL(accept)(fd, addr, addrlen);
30003004
if (fd2 >= 0) {
30013005
if (fd >= 0) COMMON_INTERCEPTOR_FD_SOCKET_ACCEPT(ctx, fd, fd2);
30023006
if (addr && addrlen)
@@ -3021,7 +3025,7 @@ INTERCEPTOR(int, accept4, int fd, void *addr, unsigned *addrlen, int f) {
30213025
// FIXME: under ASan the call below may write to freed memory and corrupt
30223026
// its metadata. See
30233027
// https://github.com/google/sanitizers/issues/321.
3024-
int fd2 = REAL(accept4)(fd, addr, addrlen, f);
3028+
int fd2 = COMMON_INTERCEPTOR_BLOCK_REAL(accept4)(fd, addr, addrlen, f);
30253029
if (fd2 >= 0) {
30263030
if (fd >= 0) COMMON_INTERCEPTOR_FD_SOCKET_ACCEPT(ctx, fd, fd2);
30273031
if (addr && addrlen)
@@ -3045,7 +3049,7 @@ INTERCEPTOR(int, paccept, int fd, void *addr, unsigned *addrlen,
30453049
addrlen0 = *addrlen;
30463050
}
30473051
if (set) COMMON_INTERCEPTOR_READ_RANGE(ctx, set, sizeof(*set));
3048-
int fd2 = REAL(paccept)(fd, addr, addrlen, set, f);
3052+
int fd2 = COMMON_INTERCEPTOR_BLOCK_REAL(paccept)(fd, addr, addrlen, set, f);
30493053
if (fd2 >= 0) {
30503054
if (fd >= 0) COMMON_INTERCEPTOR_FD_SOCKET_ACCEPT(ctx, fd, fd2);
30513055
if (addr && addrlen)
@@ -3126,7 +3130,7 @@ INTERCEPTOR(SSIZE_T, recvmsg, int fd, struct __sanitizer_msghdr *msg,
31263130
// FIXME: under ASan the call below may write to freed memory and corrupt
31273131
// its metadata. See
31283132
// https://github.com/google/sanitizers/issues/321.
3129-
SSIZE_T res = REAL(recvmsg)(fd, msg, flags);
3133+
SSIZE_T res = COMMON_INTERCEPTOR_BLOCK_REAL(recvmsg)(fd, msg, flags);
31303134
if (res >= 0) {
31313135
if (fd >= 0) COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
31323136
if (msg) {
@@ -3147,7 +3151,8 @@ INTERCEPTOR(int, recvmmsg, int fd, struct __sanitizer_mmsghdr *msgvec,
31473151
void *ctx;
31483152
COMMON_INTERCEPTOR_ENTER(ctx, recvmmsg, fd, msgvec, vlen, flags, timeout);
31493153
if (timeout) COMMON_INTERCEPTOR_READ_RANGE(ctx, timeout, struct_timespec_sz);
3150-
int res = REAL(recvmmsg)(fd, msgvec, vlen, flags, timeout);
3154+
int res =
3155+
COMMON_INTERCEPTOR_BLOCK_REAL(recvmmsg)(fd, msgvec, vlen, flags, timeout);
31513156
if (res >= 0) {
31523157
if (fd >= 0) COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
31533158
for (int i = 0; i < res; ++i) {
@@ -3225,7 +3230,7 @@ INTERCEPTOR(SSIZE_T, sendmsg, int fd, struct __sanitizer_msghdr *msg,
32253230
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
32263231
COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd);
32273232
}
3228-
SSIZE_T res = REAL(sendmsg)(fd, msg, flags);
3233+
SSIZE_T res = COMMON_INTERCEPTOR_BLOCK_REAL(sendmsg)(fd, msg, flags);
32293234
if (common_flags()->intercept_send && res >= 0 && msg)
32303235
read_msghdr(ctx, msg, res);
32313236
return res;
@@ -3244,7 +3249,7 @@ INTERCEPTOR(int, sendmmsg, int fd, struct __sanitizer_mmsghdr *msgvec,
32443249
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
32453250
COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd);
32463251
}
3247-
int res = REAL(sendmmsg)(fd, msgvec, vlen, flags);
3252+
int res = COMMON_INTERCEPTOR_BLOCK_REAL(sendmmsg)(fd, msgvec, vlen, flags);
32483253
if (res >= 0 && msgvec) {
32493254
for (int i = 0; i < res; ++i) {
32503255
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, &msgvec[i].msg_len,
@@ -3267,15 +3272,16 @@ INTERCEPTOR(int, msgsnd, int msqid, const void *msgp, SIZE_T msgsz,
32673272
COMMON_INTERCEPTOR_ENTER(ctx, msgsnd, msqid, msgp, msgsz, msgflg);
32683273
if (msgp)
32693274
COMMON_INTERCEPTOR_READ_RANGE(ctx, msgp, sizeof(long) + msgsz);
3270-
int res = REAL(msgsnd)(msqid, msgp, msgsz, msgflg);
3275+
int res = COMMON_INTERCEPTOR_BLOCK_REAL(msgsnd)(msqid, msgp, msgsz, msgflg);
32713276
return res;
32723277
}
32733278

32743279
INTERCEPTOR(SSIZE_T, msgrcv, int msqid, void *msgp, SIZE_T msgsz,
32753280
long msgtyp, int msgflg) {
32763281
void *ctx;
32773282
COMMON_INTERCEPTOR_ENTER(ctx, msgrcv, msqid, msgp, msgsz, msgtyp, msgflg);
3278-
SSIZE_T len = REAL(msgrcv)(msqid, msgp, msgsz, msgtyp, msgflg);
3283+
SSIZE_T len =
3284+
COMMON_INTERCEPTOR_BLOCK_REAL(msgrcv)(msqid, msgp, msgsz, msgtyp, msgflg);
32793285
if (len != -1)
32803286
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, msgp, sizeof(long) + len);
32813287
return len;
@@ -6119,7 +6125,7 @@ INTERCEPTOR(int, flopen, const char *path, int flags, ...) {
61196125
if (path) {
61206126
COMMON_INTERCEPTOR_READ_RANGE(ctx, path, internal_strlen(path) + 1);
61216127
}
6122-
return REAL(flopen)(path, flags, mode);
6128+
return COMMON_INTERCEPTOR_BLOCK_REAL(flopen)(path, flags, mode);
61236129
}
61246130

61256131
INTERCEPTOR(int, flopenat, int dirfd, const char *path, int flags, ...) {
@@ -6132,7 +6138,7 @@ INTERCEPTOR(int, flopenat, int dirfd, const char *path, int flags, ...) {
61326138
if (path) {
61336139
COMMON_INTERCEPTOR_READ_RANGE(ctx, path, internal_strlen(path) + 1);
61346140
}
6135-
return REAL(flopenat)(dirfd, path, flags, mode);
6141+
return COMMON_INTERCEPTOR_BLOCK_REAL(flopenat)(dirfd, path, flags, mode);
61366142
}
61376143

61386144
#define INIT_FLOPEN \
@@ -6717,7 +6723,7 @@ INTERCEPTOR(SSIZE_T, recv, int fd, void *buf, SIZE_T len, int flags) {
67176723
void *ctx;
67186724
COMMON_INTERCEPTOR_ENTER(ctx, recv, fd, buf, len, flags);
67196725
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
6720-
SSIZE_T res = REAL(recv)(fd, buf, len, flags);
6726+
SSIZE_T res = COMMON_INTERCEPTOR_BLOCK_REAL(recv)(fd, buf, len, flags);
67216727
if (res > 0) {
67226728
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, Min((SIZE_T)res, len));
67236729
}
@@ -6734,7 +6740,8 @@ INTERCEPTOR(SSIZE_T, recvfrom, int fd, void *buf, SIZE_T len, int flags,
67346740
SIZE_T srcaddr_sz;
67356741
if (srcaddr) srcaddr_sz = *addrlen;
67366742
(void)srcaddr_sz; // prevent "set but not used" warning
6737-
SSIZE_T res = REAL(recvfrom)(fd, buf, len, flags, srcaddr, addrlen);
6743+
SSIZE_T res = COMMON_INTERCEPTOR_BLOCK_REAL(recvfrom)(fd, buf, len, flags,
6744+
srcaddr, addrlen);
67386745
if (res > 0)
67396746
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, Min((SIZE_T)res, len));
67406747
if (res >= 0 && srcaddr)
@@ -6757,7 +6764,7 @@ INTERCEPTOR(SSIZE_T, send, int fd, void *buf, SIZE_T len, int flags) {
67576764
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
67586765
COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd);
67596766
}
6760-
SSIZE_T res = REAL(send)(fd, buf, len, flags);
6767+
SSIZE_T res = COMMON_INTERCEPTOR_BLOCK_REAL(send)(fd, buf, len, flags);
67616768
if (common_flags()->intercept_send && res > 0)
67626769
COMMON_INTERCEPTOR_READ_RANGE(ctx, buf, Min((SIZE_T)res, len));
67636770
return res;
@@ -6772,7 +6779,8 @@ INTERCEPTOR(SSIZE_T, sendto, int fd, void *buf, SIZE_T len, int flags,
67726779
COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd);
67736780
}
67746781
// Can't check dstaddr as it may have uninitialized padding at the end.
6775-
SSIZE_T res = REAL(sendto)(fd, buf, len, flags, dstaddr, addrlen);
6782+
SSIZE_T res = COMMON_INTERCEPTOR_BLOCK_REAL(sendto)(fd, buf, len, flags,
6783+
dstaddr, addrlen);
67766784
if (common_flags()->intercept_send && res > 0)
67776785
COMMON_INTERCEPTOR_READ_RANGE(ctx, buf, Min((SIZE_T)res, len));
67786786
return res;
@@ -6789,7 +6797,7 @@ INTERCEPTOR(int, eventfd_read, int fd, __sanitizer_eventfd_t *value) {
67896797
void *ctx;
67906798
COMMON_INTERCEPTOR_ENTER(ctx, eventfd_read, fd, value);
67916799
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
6792-
int res = REAL(eventfd_read)(fd, value);
6800+
int res = COMMON_INTERCEPTOR_BLOCK_REAL(eventfd_read)(fd, value);
67936801
if (res == 0) {
67946802
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, value, sizeof(*value));
67956803
if (fd >= 0) COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
@@ -6803,7 +6811,7 @@ INTERCEPTOR(int, eventfd_write, int fd, __sanitizer_eventfd_t value) {
68036811
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
68046812
COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd);
68056813
}
6806-
int res = REAL(eventfd_write)(fd, value);
6814+
int res = COMMON_INTERCEPTOR_BLOCK_REAL(eventfd_write)(fd, value);
68076815
return res;
68086816
}
68096817
#define INIT_EVENTFD_READ_WRITE \
@@ -7426,7 +7434,8 @@ INTERCEPTOR(int, open_by_handle_at, int mount_fd, struct file_handle* handle,
74267434
COMMON_INTERCEPTOR_READ_RANGE(
74277435
ctx, &sanitizer_handle->f_handle, sanitizer_handle->handle_bytes);
74287436

7429-
return REAL(open_by_handle_at)(mount_fd, handle, flags);
7437+
return COMMON_INTERCEPTOR_BLOCK_REAL(open_by_handle_at)(mount_fd, handle,
7438+
flags);
74307439
}
74317440

74327441
#define INIT_OPEN_BY_HANDLE_AT COMMON_INTERCEPT_FUNCTION(open_by_handle_at)

compiler-rt/test/tsan/pthread_atfork_deadlock3.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ void *worker(void *main) {
2828
}
2929

3030
void atfork() {
31+
write(2, "in atfork\n", strlen("in atfork\n"));
3132
barrier_wait(&barrier);
3233
barrier_wait(&barrier);
33-
write(2, "in atfork\n", strlen("in atfork\n"));
3434
static volatile long a;
3535
__atomic_fetch_add(&a, 1, __ATOMIC_RELEASE);
3636
}
3737

3838
void afterfork() {
39+
write(2, "in afterfork\n", strlen("in afterfork\n"));
3940
barrier_wait(&barrier);
4041
barrier_wait(&barrier);
41-
write(2, "in afterfork\n", strlen("in afterfork\n"));
4242
static volatile long a;
4343
__atomic_fetch_add(&a, 1, __ATOMIC_RELEASE);
4444
}

0 commit comments

Comments
 (0)