[PATCH] D42065: Add new interceptors: access(2), faccessat(2)

Kamil Rytarowski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 17 10:42:02 PST 2018


krytarowski updated this revision to Diff 130211.
krytarowski added a comment.

- add tests
- improve interceptors


Repository:
  rL LLVM

https://reviews.llvm.org/D42065

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_interceptors.h
  test/msan/access.cc
  test/msan/faccessat.cc


Index: test/msan/faccessat.cc
===================================================================
--- /dev/null
+++ test/msan/faccessat.cc
@@ -0,0 +1,7 @@
+// RUN: %clangxx_msan -O0 %s -o %t && %run %t
+// UNSUPPORTED: linux
+
+#include <fcntl.h>
+#include <unistd.h>
+
+int main(void) { return faccessat(AT_FDCWD, "/root", F_OK, 0); }
Index: test/msan/access.cc
===================================================================
--- /dev/null
+++ test/msan/access.cc
@@ -0,0 +1,6 @@
+// RUN: %clangxx_msan -O0 %s -o %t && %run %t
+// UNSUPPORTED: linux
+
+#include <unistd.h>
+
+int main(void) { return access("/root", F_OK); }
Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -434,4 +434,7 @@
 
 #define SANITIZER_INTERCEPT_ACCT SI_NETBSD
 
+#define SANITIZER_INTERCEPT_ACCESS SI_NETBSD
+#define SANITIZER_INTERCEPT_FACCESSAT SI_NETBSD
+
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -6476,6 +6476,32 @@
 #define INIT_ACCT
 #endif
 
+#if SANITIZER_INTERCEPT_ACCESS
+INTERCEPTOR(int, access, const char *path, int mode) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, access, path, mode);
+  if (path)
+    COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1);
+  return REAL(access)(path, mode);
+}
+#define INIT_ACCESS COMMON_INTERCEPT_FUNCTION(access)
+#else
+#define INIT_ACCESS
+#endif
+
+#if SANITIZER_INTERCEPT_FACCESSAT
+INTERCEPTOR(int, faccessat, int fd, const char *path, int mode, int flags) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, faccessat, fd, path, mode, flags);
+  if (path)
+    COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1);
+  return REAL(faccessat)(fd, path, mode, flags);
+}
+#define INIT_FACCESSAT COMMON_INTERCEPT_FUNCTION(faccessat)
+#else
+#define INIT_FACCESSAT
+#endif
+
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
   interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -6688,6 +6714,8 @@
   INIT_WCSLEN;
   INIT_WCSCAT;
   INIT_ACCT;
+  INIT_ACCESS;
+  INIT_FACCESSAT;
 
 #if SANITIZER_NETBSD
   COMMON_INTERCEPT_FUNCTION(__libc_mutex_lock);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42065.130211.patch
Type: text/x-patch
Size: 2572 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180117/6f4a465f/attachment.bin>


More information about the llvm-commits mailing list