diff options
3 files changed, 45 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 e3f32c9f342..07cbf00a7fe 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/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 @@ INTERCEPTOR(struct __sanitizer_netent *, getnetbyaddr, u32 net, int type) { #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 @@ static void InitializeCommonInterceptors() { INIT_TTYENT; INIT_PROTOENT; INIT_NETENT; + INIT_GETMNTINFO; 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 851e8125025..0f6fac8f942 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/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 diff --git a/compiler-rt/test/sanitizer_common/TestCases/NetBSD/getmntinfo.cc b/compiler-rt/test/sanitizer_common/TestCases/NetBSD/getmntinfo.cc new file mode 100644 index 00000000000..d27e995a7d6 --- /dev/null +++ b/compiler-rt/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; +} |

