-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Preadv2 pwritev2 san reapply #99089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preadv2 pwritev2 san reapply #99089
Conversation
@llvm/pr-subscribers-compiler-rt-sanitizer Author: David CARLIER (devnexen) ChangesFull diff: https://github.com/llvm/llvm-project/pull/99089.diff 3 Files Affected:
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index a6066a6226e1b..032b04a09ae76 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -10264,6 +10264,38 @@ INTERCEPTOR(int, cpuset_getaffinity, int level, int which, __int64_t id, SIZE_T
#define INIT_CPUSET_GETAFFINITY
#endif
+#if SANITIZER_INTERCEPT_PREADV2
+INTERCEPTOR(SSIZE_T, preadv2, int fd, __sanitizer_iovec *iov, int iovcnt,
+ OFF_T offset, int flags) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, preadv2, fd, iov, iovcnt, offset, flags);
+ COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
+ SSIZE_T res = REAL(preadv2)(fd, iov, iovcnt, offset, flags);
+ if (res > 0) write_iovec(ctx, iov, iovcnt, res);
+ if (res >= 0 && fd >= 0) COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
+ return res;
+}
+#define INIT_PREADV2 COMMON_INTERCEPT_FUNCTION(preadv2)
+#else
+#define INIT_PREADV2
+#endif
+
+#if SANITIZER_INTERCEPT_PWRITEV2
+INTERCEPTOR(SSIZE_T, pwritev2, int fd, __sanitizer_iovec *iov, int iovcnt,
+ OFF_T offset, int flags) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, pwritev2, fd, iov, iovcnt, offset, flags);
+ COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
+ if (fd >= 0) COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd);
+ SSIZE_T res = REAL(pwritev2)(fd, iov, iovcnt, offset, flags);
+ if (res > 0) read_iovec(ctx, iov, iovcnt, res);
+ return res;
+}
+#define INIT_PWRITEV2 COMMON_INTERCEPT_FUNCTION(pwritev2)
+#else
+#define INIT_PWRITEV2
+#endif
+
#include "sanitizer_common_interceptors_netbsd_compat.inc"
namespace __sanitizer {
@@ -10583,6 +10615,8 @@ static void InitializeCommonInterceptors() {
INIT___XUNAME;
INIT_ARGP_PARSE;
INIT_CPUSET_GETAFFINITY;
+ INIT_PREADV2;
+ INIT_PWRITEV2;
INIT___PRINTF_CHK;
}
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index de55c736d0e14..c94368b6b0ebb 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -598,6 +598,9 @@
#define SANITIZER_INTERCEPT_PROCCTL SI_FREEBSD
#define SANITIZER_INTERCEPT_ARGP_PARSE SI_GLIBC
#define SANITIZER_INTERCEPT_CPUSET_GETAFFINITY SI_FREEBSD
+// FIXME: also available from musl 1.2.5
+#define SANITIZER_INTERCEPT_PREADV2 SI_GLIBC
+#define SANITIZER_INTERCEPT_PWRITEV2 SI_GLIBC
// This macro gives a way for downstream users to override the above
// interceptor macros irrespective of the platform they are on. They have
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/preadv2.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/preadv2.cpp
new file mode 100644
index 0000000000000..e969420414b96
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/preadv2.cpp
@@ -0,0 +1,29 @@
+// RUN: %clangxx -O0 %s -o %t
+
+// REQUIRES: glibc
+// UNSUPPORTED: target={{.*fuchsia.*}}
+
+#include <assert.h>
+#include <fcntl.h>
+#include <sys/uio.h>
+#include <unistd.h>
+
+int main(void) {
+ int fd = open("/proc/self/stat", O_RDONLY);
+ char bufa[7];
+ char bufb[7];
+ struct iovec vec[2];
+ vec[0].iov_base = bufa + 4;
+ vec[0].iov_len = 1;
+ vec[1].iov_base = bufb;
+ vec[1].iov_len = sizeof(bufb);
+ ssize_t rd = preadv2(fd, vec, 2, 0, 0);
+ assert(rd > 0);
+ vec[0].iov_base = bufa;
+ rd = preadv2(fd, vec, 2, 0, 0);
+ assert(rd > 0);
+ rd = preadv2(fd, vec, 5, -25, 0);
+ assert(rd < 0);
+ close(fd);
+ return 0;
+}
|
You can test this locally with the following command:git-clang-format --diff 81704f6946894538ee1649a88688f604939de7f0 ca57cc24add2a900958322d1e6b24d36726865f6 --extensions h,cpp,inc -- compiler-rt/test/sanitizer_common/TestCases/Linux/preadv2.cpp compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h View the diff from clang-format here.diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 032b04a09a..f48705da0f 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -10271,13 +10271,15 @@ INTERCEPTOR(SSIZE_T, preadv2, int fd, __sanitizer_iovec *iov, int iovcnt,
COMMON_INTERCEPTOR_ENTER(ctx, preadv2, fd, iov, iovcnt, offset, flags);
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
SSIZE_T res = REAL(preadv2)(fd, iov, iovcnt, offset, flags);
- if (res > 0) write_iovec(ctx, iov, iovcnt, res);
- if (res >= 0 && fd >= 0) COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
+ if (res > 0)
+ write_iovec(ctx, iov, iovcnt, res);
+ if (res >= 0 && fd >= 0)
+ COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
return res;
}
-#define INIT_PREADV2 COMMON_INTERCEPT_FUNCTION(preadv2)
+# define INIT_PREADV2 COMMON_INTERCEPT_FUNCTION(preadv2)
#else
-#define INIT_PREADV2
+# define INIT_PREADV2
#endif
#if SANITIZER_INTERCEPT_PWRITEV2
@@ -10286,14 +10288,16 @@ INTERCEPTOR(SSIZE_T, pwritev2, int fd, __sanitizer_iovec *iov, int iovcnt,
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, pwritev2, fd, iov, iovcnt, offset, flags);
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
- if (fd >= 0) COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd);
+ if (fd >= 0)
+ COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd);
SSIZE_T res = REAL(pwritev2)(fd, iov, iovcnt, offset, flags);
- if (res > 0) read_iovec(ctx, iov, iovcnt, res);
+ if (res > 0)
+ read_iovec(ctx, iov, iovcnt, res);
return res;
}
-#define INIT_PWRITEV2 COMMON_INTERCEPT_FUNCTION(pwritev2)
+# define INIT_PWRITEV2 COMMON_INTERCEPT_FUNCTION(pwritev2)
#else
-#define INIT_PWRITEV2
+# define INIT_PWRITEV2
#endif
#include "sanitizer_common_interceptors_netbsd_compat.inc"
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/preadv2.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/preadv2.cpp
index 4ec6f9f690..d7a2396a5e 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/preadv2.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/preadv2.cpp
@@ -8,11 +8,11 @@
#include <unistd.h>
#if !defined(__GLIBC_PREREQ)
-#define __GLIBC_PREREQ(a, b) 0
+# define __GLIBC_PREREQ(a, b) 0
#endif
#if !__GLIBC_PREREQ(2, 26)
-#define preadv2(a, b, c, d, e) preadv(a, b, c, d)
+# define preadv2(a, b, c, d, e) preadv(a, b, c, d)
#endif
int main(void) {
|
This won't address anything unfortunately, since the test is failing on Linux, not Fuchsia. See the message I left on the original PR for details. |
I see but there was no real need to close this PR , just updating it. |
Ah, apologies. |
1d4a17f
to
ca57cc2
Compare
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250969
No description provided.