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; } 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: test/sanitizer_common/TestCases/NetBSD/getmntinfo.cc =================================================================== --- /dev/null +++ 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 + +#include + +#include +#include +#include + +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; +}