Skip to content

Commit e4606ed

Browse files
committed
[compiler-rt] adding preadv2/pwritev2 interceptions.
1 parent d0d05ae commit e4606ed

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10259,6 +10259,38 @@ INTERCEPTOR(int, cpuset_getaffinity, int level, int which, __int64_t id, SIZE_T
1025910259
#define INIT_CPUSET_GETAFFINITY
1026010260
#endif
1026110261

10262+
#if SANITIZER_INTERCEPT_PREADV2
10263+
INTERCEPTOR(SSIZE_T, preadv2, int fd, __sanitizer_iovec *iov, int iovcnt,
10264+
OFF_T offset, int flags) {
10265+
void *ctx;
10266+
COMMON_INTERCEPTOR_ENTER(ctx, preadv2, fd, iov, iovcnt, offset, flags);
10267+
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
10268+
SSIZE_T res = REAL(preadv2)(fd, iov, iovcnt, offset, flags);
10269+
if (res > 0) write_iovec(ctx, iov, iovcnt, res);
10270+
if (res >= 0 && fd >= 0) COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
10271+
return res;
10272+
}
10273+
#define INIT_PREADV2 COMMON_INTERCEPT_FUNCTION(preadv2)
10274+
#else
10275+
#define INIT_PREADV2
10276+
#endif
10277+
10278+
#if SANITIZER_INTERCEPT_PWRITEV2
10279+
INTERCEPTOR(SSIZE_T, pwritev2, int fd, __sanitizer_iovec *iov, int iovcnt,
10280+
OFF_T offset, int flags) {
10281+
void *ctx;
10282+
COMMON_INTERCEPTOR_ENTER(ctx, pwritev2, fd, iov, iovcnt, offset, flags);
10283+
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
10284+
if (fd >= 0) COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd);
10285+
SSIZE_T res = REAL(pwritev2)(fd, iov, iovcnt, offset, flags);
10286+
if (res > 0) read_iovec(ctx, iov, iovcnt, res);
10287+
return res;
10288+
}
10289+
#define INIT_PWRITEV2 COMMON_INTERCEPT_FUNCTION(pwritev2)
10290+
#else
10291+
#define INIT_PWRITEV2
10292+
#endif
10293+
1026210294
#include "sanitizer_common_interceptors_netbsd_compat.inc"
1026310295

1026410296
namespace __sanitizer {
@@ -10578,6 +10610,8 @@ static void InitializeCommonInterceptors() {
1057810610
INIT___XUNAME;
1057910611
INIT_ARGP_PARSE;
1058010612
INIT_CPUSET_GETAFFINITY;
10613+
INIT_PREADV2;
10614+
INIT_PWRITEV2;
1058110615

1058210616
INIT___PRINTF_CHK;
1058310617
}

compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,9 @@
598598
#define SANITIZER_INTERCEPT_PROCCTL SI_FREEBSD
599599
#define SANITIZER_INTERCEPT_ARGP_PARSE SI_GLIBC
600600
#define SANITIZER_INTERCEPT_CPUSET_GETAFFINITY SI_FREEBSD
601+
// FIXME: also available from musl 1.2.5
602+
#define SANITIZER_INTERCEPT_PREADV2 SI_GLIBC
603+
#define SANITIZER_INTERCEPT_PWRITEV2 SI_GLIBC
601604

602605
// This macro gives a way for downstream users to override the above
603606
// interceptor macros irrespective of the platform they are on. They have

0 commit comments

Comments
 (0)