1 //===-- sanitizer_common_interceptors_netbsd_compat.inc ---------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Common function interceptors for tools like AddressSanitizer,
10 // ThreadSanitizer, MemorySanitizer, etc.
12 // Interceptors for NetBSD old function calls that have been versioned.
14 // NetBSD minimal version supported 9.0.
15 // NetBSD current version supported 9.99.26.
17 //===----------------------------------------------------------------------===//
21 // First undef all mangled symbols.
22 // Next, define compat interceptors.
23 // Finally, undef INIT_ and redefine it.
24 // This allows to avoid preprocessor issues.
33 INTERCEPTOR(int, statvfs, char *path, void *buf) {
35 COMMON_INTERCEPTOR_ENTER(ctx, statvfs, path, buf);
36 if (path) COMMON_INTERCEPTOR_READ_RANGE(ctx, path, internal_strlen(path) + 1);
37 // FIXME: under ASan the call below may write to freed memory and corrupt
39 // https://github.com/google/sanitizers/issues/321.
40 int res = REAL(statvfs)(path, buf);
41 if (!res) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, struct_statvfs90_sz);
45 INTERCEPTOR(int, fstatvfs, int fd, void *buf) {
47 COMMON_INTERCEPTOR_ENTER(ctx, fstatvfs, fd, buf);
48 COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
49 // FIXME: under ASan the call below may write to freed memory and corrupt
51 // https://github.com/google/sanitizers/issues/321.
52 int res = REAL(fstatvfs)(fd, buf);
54 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, struct_statvfs90_sz);
56 COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
62 #define INIT_STATVFS \
63 COMMON_INTERCEPT_FUNCTION(statvfs); \
64 COMMON_INTERCEPT_FUNCTION(fstatvfs); \
65 COMMON_INTERCEPT_FUNCTION(__statvfs90); \
66 COMMON_INTERCEPT_FUNCTION(__fstatvfs90)
68 INTERCEPTOR(int, __getmntinfo13, void **mntbufp, int flags) {
70 COMMON_INTERCEPTOR_ENTER(ctx, __getmntinfo13, mntbufp, flags);
71 int cnt = REAL(__getmntinfo13)(mntbufp, flags);
72 if (cnt > 0 && mntbufp) {
73 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, mntbufp, sizeof(void *));
75 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, *mntbufp, cnt * struct_statvfs90_sz);
80 #undef INIT_GETMNTINFO
81 #define INIT_GETMNTINFO \
82 COMMON_INTERCEPT_FUNCTION(__getmntinfo13); \
83 COMMON_INTERCEPT_FUNCTION(__getmntinfo90)
85 INTERCEPTOR(int, getvfsstat, void *buf, SIZE_T bufsize, int flags) {
87 COMMON_INTERCEPTOR_ENTER(ctx, getvfsstat, buf, bufsize, flags);
88 int ret = REAL(getvfsstat)(buf, bufsize, flags);
90 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, ret * struct_statvfs90_sz);
94 #undef INIT_GETVFSSTAT
95 #define INIT_GETVFSSTAT \
96 COMMON_INTERCEPT_FUNCTION(getvfsstat); \
97 COMMON_INTERCEPT_FUNCTION(__getvfsstat90)
99 INTERCEPTOR(int, statvfs1, const char *path, void *buf, int flags) {
101 COMMON_INTERCEPTOR_ENTER(ctx, statvfs1, path, buf, flags);
102 if (path) COMMON_INTERCEPTOR_READ_RANGE(ctx, path, internal_strlen(path) + 1);
103 int res = REAL(statvfs1)(path, buf, flags);
104 if (!res) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, struct_statvfs90_sz);
108 INTERCEPTOR(int, fstatvfs1, int fd, void *buf, int flags) {
110 COMMON_INTERCEPTOR_ENTER(ctx, fstatvfs1, fd, buf, flags);
111 COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
112 int res = REAL(fstatvfs1)(fd, buf, flags);
114 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, struct_statvfs90_sz);
116 COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
122 #define INIT_STATVFS1 \
123 COMMON_INTERCEPT_FUNCTION(statvfs1); \
124 COMMON_INTERCEPT_FUNCTION(fstatvfs1); \
125 COMMON_INTERCEPT_FUNCTION(__statvfs190); \
126 COMMON_INTERCEPT_FUNCTION(__fstatvfs190)