[PATCH] D33600: Adjust sanitizers for FreeBSD 64-bit inode update
Dimitry Andric via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 26 11:04:20 PDT 2017
dim created this revision.
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).
https://reviews.llvm.org/D33600
Files:
lib/sanitizer_common/sanitizer_linux.cc
lib/sanitizer_common/sanitizer_platform_limits_posix.h
Index: lib/sanitizer_common/sanitizer_platform_limits_posix.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -23,6 +23,9 @@
// incorporates the map structure.
# define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
((link_map*)((handle) == nullptr ? nullptr : ((char*)(handle) + 544)))
+// Get sys/_types.h, because that tells us whether 64-bit inodes are
+// used in struct dirent below.
+#include <sys/_types.h>
#else
# define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) ((link_map*)(handle))
#endif // !SANITIZER_FREEBSD
@@ -485,7 +488,13 @@
};
#elif SANITIZER_FREEBSD
struct __sanitizer_dirent {
+#if defined(__INO64)
+ unsigned long long d_fileno;
+ unsigned long long d_off;
+#else
+#warning Using ino32 dirent
unsigned int d_fileno;
+#endif
unsigned short d_reclen;
// more fields that we don't care about
};
Index: lib/sanitizer_common/sanitizer_linux.cc
===================================================================
--- lib/sanitizer_common/sanitizer_linux.cc
+++ lib/sanitizer_common/sanitizer_linux.cc
@@ -237,7 +237,8 @@
uptr internal_stat(const char *path, void *buf) {
#if SANITIZER_FREEBSD
- return internal_syscall(SYSCALL(stat), path, buf);
+ return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path,
+ (uptr)buf, 0);
#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path,
(uptr)buf, 0);
@@ -261,7 +262,8 @@
uptr internal_lstat(const char *path, void *buf) {
#if SANITIZER_FREEBSD
- return internal_syscall(SYSCALL(lstat), path, buf);
+ return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path,
+ (uptr)buf, AT_SYMLINK_NOFOLLOW);
#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path,
(uptr)buf, AT_SYMLINK_NOFOLLOW);
@@ -604,7 +606,9 @@
}
uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count) {
-#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
+#if SANITIZER_FREEBSD
+ return internal_syscall(SYSCALL(getdirentries), fd, (uptr)dirp, count, NULL);
+#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
return internal_syscall(SYSCALL(getdents64), fd, (uptr)dirp, count);
#else
return internal_syscall(SYSCALL(getdents), fd, (uptr)dirp, count);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33600.100436.patch
Type: text/x-patch
Size: 2515 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170526/3e9f35b8/attachment.bin>
More information about the llvm-commits
mailing list