[PATCH] D55014: Add a new interceptor for getvfsstat(2) from NetBSD
Kamil Rytarowski via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 28 11:40:03 PST 2018
krytarowski created this revision.
krytarowski added reviewers: vitalybuka, joerg.
krytarowski added a project: Sanitizers.
Herald added subscribers: llvm-commits, kubamracek.
getvfsstat - gets list of all mounted file systems.
Add a dedicated test.
Repository:
rL LLVM
https://reviews.llvm.org/D55014
Files:
lib/sanitizer_common/sanitizer_common_interceptors.inc
lib/sanitizer_common/sanitizer_platform_interceptors.h
test/sanitizer_common/TestCases/NetBSD/getvfsstat.cc
Index: test/sanitizer_common/TestCases/NetBSD/getvfsstat.cc
===================================================================
--- /dev/null
+++ test/sanitizer_common/TestCases/NetBSD/getvfsstat.cc
@@ -0,0 +1,40 @@
+// 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) {
+ int i, rv;
+ size_t sz;
+ struct statvfs *buf;
+ printf("getvfsstat\n");
+
+ if ((rv = getvfsstat(NULL, 0, ST_WAIT)) == -1)
+ err(EXIT_FAILURE, "getvfsstat");
+
+ sz = rv * sizeof(struct statvfs);
+ buf = (struct statvfs *)malloc(sz);
+ if (!buf)
+ err(EXIT_FAILURE, "malloc");
+
+ if ((rv = getvfsstat(buf, sz, ST_WAIT)) == -1)
+ err(EXIT_FAILURE, "getvfsstat");
+
+ for (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;
+}
Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ 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
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7348,6 +7348,20 @@
#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 @@
INIT_GETMNTINFO;
INIT_MI_VECTOR_HASH;
INIT_SETVBUF;
+ INIT_GETVFSSTAT;
INIT___PRINTF_CHK;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55014.175733.patch
Type: text/x-patch
Size: 2681 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181128/aeb87d09/attachment.bin>
More information about the llvm-commits
mailing list