Skip to content

Commit f130d11

Browse files
committed
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
1 parent 971a89c commit f130d11

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7348,6 +7348,20 @@ INTERCEPTOR(void, setlinebuf, __sanitizer_FILE *stream) {
73487348
#define INIT_SETVBUF
73497349
#endif
73507350

7351+
#if SANITIZER_INTERCEPT_GETVFSSTAT
7352+
INTERCEPTOR(int, getvfsstat, void *buf, SIZE_T bufsize, int flags) {
7353+
void *ctx;
7354+
COMMON_INTERCEPTOR_ENTER(ctx, getvfsstat, buf, bufsize, flags);
7355+
int ret = REAL(getvfsstat)(buf, bufsize, flags);
7356+
if (buf && ret > 0)
7357+
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, ret * struct_statvfs_sz);
7358+
return ret;
7359+
}
7360+
#define INIT_GETVFSSTAT COMMON_INTERCEPT_FUNCTION(getvfsstat)
7361+
#else
7362+
#define INIT_GETVFSSTAT
7363+
#endif
7364+
73517365
static void InitializeCommonInterceptors() {
73527366
static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
73537367
interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -7604,6 +7618,7 @@ static void InitializeCommonInterceptors() {
76047618
INIT_GETMNTINFO;
76057619
INIT_MI_VECTOR_HASH;
76067620
INIT_SETVBUF;
7621+
INIT_GETVFSSTAT;
76077622

76087623
INIT___PRINTF_CHK;
76097624
}

compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,5 +520,6 @@
520520
SI_LINUX || SI_MAC)
521521
#define SANITIZER_INTERCEPT_GETMNTINFO SI_NETBSD
522522
#define SANITIZER_INTERCEPT_MI_VECTOR_HASH SI_NETBSD
523+
#define SANITIZER_INTERCEPT_GETVFSSTAT SI_NETBSD
523524

524525
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
2+
3+
#include <sys/types.h>
4+
5+
#include <sys/statvfs.h>
6+
7+
#include <assert.h>
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
11+
int main(void) {
12+
printf("getvfsstat\n");
13+
14+
int rv = getvfsstat(NULL, 0, ST_WAIT);
15+
assert(rv != -1);
16+
17+
size_t sz = rv * sizeof(struct statvfs);
18+
struct statvfs *buf = (struct statvfs *)malloc(sz);
19+
assert(buf);
20+
21+
rv = getvfsstat(buf, sz, ST_WAIT);
22+
assert(rv != -1);
23+
24+
for (int i = 0; i < rv; i++) {
25+
printf("Filesystem %d\n", i);
26+
printf("\tfstypename=%s\n", buf[i].f_fstypename);
27+
printf("\tmntonname=%s\n", buf[i].f_mntonname);
28+
printf("\tmntfromname=%s\n", buf[i].f_mntfromname);
29+
}
30+
31+
free(buf);
32+
33+
// CHECK: getvfsstat
34+
35+
return 0;
36+
}

0 commit comments

Comments
 (0)