summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKamil Rytarowski <n54@gmx.com>2018-11-30 19:43:53 +0000
committerKamil Rytarowski <n54@gmx.com>2018-11-30 19:43:53 +0000
commitf130d111b68ac28da4143257b1c735b8c813eb69 (patch)
tree63532f278222fc984266a057120b5cad92df2d98
parent971a89ce4ccaae9d3255452e084a631d180325c9 (diff)
downloadbcm5719-llvm-f130d111b68ac28da4143257b1c735b8c813eb69.tar.gz
bcm5719-llvm-f130d111b68ac28da4143257b1c735b8c813eb69.zip
Add a new interceptor for getvfsstat(2) from NetBSD
Summary: getvfsstat - gets list of all mounted file systems. Add a dedicated test. Reviewers: vitalybuka, joerg Reviewed By: vitalybuka Subscribers: kubamracek, llvm-commits, mgorny, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D55014 llvm-svn: 348027
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc15
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h1
-rw-r--r--compiler-rt/test/sanitizer_common/TestCases/NetBSD/getvfsstat.cc36
3 files changed, 52 insertions, 0 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 93958cf226a..eaddfe50848 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7348,6 +7348,20 @@ INTERCEPTOR(void, setlinebuf, __sanitizer_FILE *stream) {
#define INIT_SETVBUF
#endif
+#if SANITIZER_INTERCEPT_GETVFSSTAT
+INTERCEPTOR(int, getvfsstat, void *buf, SIZE_T bufsize, int flags) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, getvfsstat, buf, bufsize, flags);
+ int ret = REAL(getvfsstat)(buf, bufsize, flags);
+ if (buf && ret > 0)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, ret * struct_statvfs_sz);
+ return ret;
+}
+#define INIT_GETVFSSTAT COMMON_INTERCEPT_FUNCTION(getvfsstat)
+#else
+#define INIT_GETVFSSTAT
+#endif
+
static void InitializeCommonInterceptors() {
static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -7604,6 +7618,7 @@ static void InitializeCommonInterceptors() {
INIT_GETMNTINFO;
INIT_MI_VECTOR_HASH;
INIT_SETVBUF;
+ INIT_GETVFSSTAT;
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 6d81611ec00..2216ef3e690 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -520,5 +520,6 @@
SI_LINUX || SI_MAC)
#define SANITIZER_INTERCEPT_GETMNTINFO SI_NETBSD
#define SANITIZER_INTERCEPT_MI_VECTOR_HASH SI_NETBSD
+#define SANITIZER_INTERCEPT_GETVFSSTAT SI_NETBSD
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
diff --git a/compiler-rt/test/sanitizer_common/TestCases/NetBSD/getvfsstat.cc b/compiler-rt/test/sanitizer_common/TestCases/NetBSD/getvfsstat.cc
new file mode 100644
index 00000000000..ea72e41ede0
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/NetBSD/getvfsstat.cc
@@ -0,0 +1,36 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
+
+#include <sys/types.h>
+
+#include <sys/statvfs.h>
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(void) {
+ printf("getvfsstat\n");
+
+ int rv = getvfsstat(NULL, 0, ST_WAIT);
+ assert(rv != -1);
+
+ size_t sz = rv * sizeof(struct statvfs);
+ struct statvfs *buf = (struct statvfs *)malloc(sz);
+ assert(buf);
+
+ rv = getvfsstat(buf, sz, ST_WAIT);
+ assert(rv != -1);
+
+ for (int i = 0; i < rv; i++) {
+ printf("Filesystem %d\n", i);
+ printf("\tfstypename=%s\n", buf[i].f_fstypename);
+ printf("\tmntonname=%s\n", buf[i].f_mntonname);
+ printf("\tmntfromname=%s\n", buf[i].f_mntfromname);
+ }
+
+ free(buf);
+
+ // CHECK: getvfsstat
+
+ return 0;
+}
OpenPOWER on IntegriCloud