Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 677ecac

Browse files
committed
Adjust sanitizers for FreeBSD 64-bit inode update
Summary: Very recently, FreeBSD 12 has been updated to use 64-bit inode numbers: <https://svnweb.freebsd.org/changeset/base/318737>. This entails many user-visible changes, but for the sanitizers the modifications are limited in scope: * The `stat` and `lstat` syscalls were removed, and should be replaced with calls to `fstatat`. * The `getdents` syscall was removed, and should be replaced with calls to `getdirentries`. * The layout of `struct dirent` was changed to accomodate 64-bit inode numbers, and a new `d_off` field was added. * The system header <sys/_types.h> now contains a macro `__INO64` to determine whether the system uses 64-bit inode numbers. I tested these changes on both FreeBSD 12.0-CURRENT (after r318959, which adds the `__INO64` macro), and FreeBSD 11.0-STABLE (which still uses 32-bit inode numbers). Reviewers: emaste, kcc, vitalybuka, kubamracek Reviewed By: vitalybuka Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D33600 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@304658 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent e82d511 commit 677ecac

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib/sanitizer_common/sanitizer_linux.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@
6262
#if SANITIZER_FREEBSD
6363
#include <sys/exec.h>
6464
#include <sys/sysctl.h>
65-
#include <vm/vm_param.h>
66-
#include <vm/pmap.h>
6765
#include <machine/atomic.h>
6866
extern "C" {
6967
// <sys/umtx.h> must be included after <errno.h> and <sys/types.h> on
@@ -227,7 +225,8 @@ static void kernel_stat_to_stat(struct kernel_stat *in, struct stat *out) {
227225

228226
uptr internal_stat(const char *path, void *buf) {
229227
#if SANITIZER_FREEBSD
230-
return internal_syscall(SYSCALL(stat), path, buf);
228+
return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path,
229+
(uptr)buf, 0);
231230
#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
232231
return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path,
233232
(uptr)buf, 0);
@@ -251,7 +250,8 @@ uptr internal_stat(const char *path, void *buf) {
251250

252251
uptr internal_lstat(const char *path, void *buf) {
253252
#if SANITIZER_FREEBSD
254-
return internal_syscall(SYSCALL(lstat), path, buf);
253+
return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path,
254+
(uptr)buf, AT_SYMLINK_NOFOLLOW);
255255
#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
256256
return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path,
257257
(uptr)buf, AT_SYMLINK_NOFOLLOW);
@@ -594,7 +594,9 @@ uptr internal_getppid() {
594594
}
595595

596596
uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count) {
597-
#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
597+
#if SANITIZER_FREEBSD
598+
return internal_syscall(SYSCALL(getdirentries), fd, (uptr)dirp, count, NULL);
599+
#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
598600
return internal_syscall(SYSCALL(getdents64), fd, (uptr)dirp, count);
599601
#else
600602
return internal_syscall(SYSCALL(getdents), fd, (uptr)dirp, count);

lib/sanitizer_common/sanitizer_platform_limits_posix.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
// incorporates the map structure.
2424
# define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
2525
((link_map*)((handle) == nullptr ? nullptr : ((char*)(handle) + 544)))
26+
// Get sys/_types.h, because that tells us whether 64-bit inodes are
27+
// used in struct dirent below.
28+
#include <sys/_types.h>
2629
#else
2730
# define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) ((link_map*)(handle))
2831
#endif // !SANITIZER_FREEBSD
@@ -485,7 +488,12 @@ namespace __sanitizer {
485488
};
486489
#elif SANITIZER_FREEBSD
487490
struct __sanitizer_dirent {
491+
#if defined(__INO64)
492+
unsigned long long d_fileno;
493+
unsigned long long d_off;
494+
#else
488495
unsigned int d_fileno;
496+
#endif
489497
unsigned short d_reclen;
490498
// more fields that we don't care about
491499
};

0 commit comments

Comments
 (0)