[PATCH] D54611: Add new interceptor for getmntinfo(3) from NetBSD

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 16 11:50:18 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rCRT347083: Add new interceptor for getmntinfo(3) from NetBSD (authored by kamil, committed by ).

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D54611

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_interceptors.h
  test/sanitizer_common/TestCases/NetBSD/getmntinfo.cc


Index: test/sanitizer_common/TestCases/NetBSD/getmntinfo.cc
===================================================================
--- test/sanitizer_common/TestCases/NetBSD/getmntinfo.cc
+++ test/sanitizer_common/TestCases/NetBSD/getmntinfo.cc
@@ -0,0 +1,25 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
+
+#include <sys/types.h>
+
+#include <sys/statvfs.h>
+
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(void) {
+  printf("getmntinfo\n");
+
+  struct statvfs *fss;
+  int nfss = getmntinfo(&fss, MNT_NOWAIT);
+  if (nfss <= 0)
+    errx(1, "getmntinfo");
+
+  for (int i = 0; i < nfss; i++)
+    printf("%d: %s\n", i, fss[i].f_fstypename);
+
+  // CHECK: getmntinfo
+
+  return 0;
+}
Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -516,5 +516,6 @@
 #define SANITIZER_INTERCEPT_TTYENT SI_NETBSD
 #define SANITIZER_INTERCEPT_PROTOENT SI_NETBSD
 #define SANITIZER_INTERCEPT_NETENT SI_NETBSD
+#define SANITIZER_INTERCEPT_GETMNTINFO 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
@@ -78,6 +78,7 @@
 #define ctime_r __ctime_r50
 #define devname __devname50
 #define getitimer __getitimer50
+#define getmntinfo __getmntinfo13
 #define getpwent __getpwent50
 #define getpwnam __getpwnam50
 #define getpwnam_r __getpwnam_r50
@@ -7264,6 +7265,23 @@
 #define INIT_NETENT
 #endif
 
+#if SANITIZER_INTERCEPT_GETMNTINFO
+INTERCEPTOR(int, getmntinfo, void **mntbufp, int flags) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, getmntinfo, mntbufp, flags);
+  int cnt = REAL(getmntinfo)(mntbufp, flags);
+  if (cnt > 0 && mntbufp) {
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, mntbufp, sizeof(void *));
+    if (*mntbufp)
+      COMMON_INTERCEPTOR_WRITE_RANGE(ctx, *mntbufp, cnt * struct_statvfs_sz);
+  }
+  return cnt;
+}
+#define INIT_GETMNTINFO COMMON_INTERCEPT_FUNCTION(getmntinfo)
+#else
+#define INIT_GETMNTINFO
+#endif
+
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
   interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -7517,6 +7535,7 @@
   INIT_TTYENT;
   INIT_PROTOENT;
   INIT_NETENT;
+  INIT_GETMNTINFO;
 
   INIT___PRINTF_CHK;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54611.174422.patch
Type: text/x-patch
Size: 2640 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181116/2aae586a/attachment.bin>


More information about the llvm-commits mailing list