tsan: fix cross build for FreeBSD by using direct syscalls instead of libsys

This patch can hopefully be dropped in the future; see #24989.

closes #24885
closes #24896

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
This commit is contained in:
Rajiv Singh 2025-10-26 11:12:22 +01:00 committed by Alex Rønne Petersen
parent 67c9d57e27
commit fe783d9ff3
No known key found for this signature in database
2 changed files with 10 additions and 17 deletions

View file

@ -174,8 +174,6 @@ const int FUTEX_WAKE_PRIVATE = FUTEX_WAKE | FUTEX_PRIVATE_FLAG;
# if SANITIZER_FREEBSD # if SANITIZER_FREEBSD
# define SANITIZER_USE_GETENTROPY 1 # define SANITIZER_USE_GETENTROPY 1
extern "C" void *__sys_mmap(void *addr, size_t len, int prot, int flags, int fd,
off_t offset);
# endif # endif
namespace __sanitizer { namespace __sanitizer {
@ -265,9 +263,8 @@ ScopedBlockSignals::~ScopedBlockSignals() { SetSigProcMask(&saved_, nullptr); }
# if !SANITIZER_S390 # if !SANITIZER_S390
uptr internal_mmap(void *addr, uptr length, int prot, int flags, int fd, uptr internal_mmap(void *addr, uptr length, int prot, int flags, int fd,
u64 offset) { u64 offset) {
# if SANITIZER_FREEBSD /* zig patch: use direct syscall for freebsd mmap */
return (uptr)__sys_mmap(addr, length, prot, flags, fd, offset); # if SANITIZER_FREEBSD || SANITIZER_LINUX_USES_64BIT_SYSCALLS
# elif SANITIZER_LINUX_USES_64BIT_SYSCALLS
return internal_syscall(SYSCALL(mmap), (uptr)addr, length, prot, flags, fd, return internal_syscall(SYSCALL(mmap), (uptr)addr, length, prot, flags, fd,
offset); offset);
# else # else
@ -942,6 +939,11 @@ int internal_fork() {
} }
# if SANITIZER_FREEBSD # if SANITIZER_FREEBSD
int internal_sigaction(int signum, const void *act, void *oldact) {
/* zig patch: use direct syscall for freebsd mmap */
return internal_syscall(SYSCALL(sigaction), signum, (uptr)act, (uptr)oldact);
}
int internal_sysctl(const int *name, unsigned int namelen, void *oldp, int internal_sysctl(const int *name, unsigned int namelen, void *oldp,
uptr *oldlenp, const void *newp, uptr newlen) { uptr *oldlenp, const void *newp, uptr newlen) {
return internal_syscall(SYSCALL(__sysctl), name, namelen, oldp, return internal_syscall(SYSCALL(__sysctl), name, namelen, oldp,

View file

@ -69,8 +69,6 @@
# undef MAP_NORESERVE # undef MAP_NORESERVE
# define MAP_NORESERVE 0 # define MAP_NORESERVE 0
extern const Elf_Auxinfo *__elf_aux_vector __attribute__((weak)); extern const Elf_Auxinfo *__elf_aux_vector __attribute__((weak));
extern "C" int __sys_sigaction(int signum, const struct sigaction *act,
struct sigaction *oldact);
# endif # endif
# if SANITIZER_NETBSD # if SANITIZER_NETBSD
@ -100,24 +98,17 @@ namespace __sanitizer {
SANITIZER_WEAK_ATTRIBUTE int real_sigaction(int signum, const void *act, SANITIZER_WEAK_ATTRIBUTE int real_sigaction(int signum, const void *act,
void *oldact); void *oldact);
/* zig patch: use direct syscall for freebsd sigaction (sanitizer_linux.cpp) */
# if !SANITIZER_FREEBSD
int internal_sigaction(int signum, const void *act, void *oldact) { int internal_sigaction(int signum, const void *act, void *oldact) {
# if SANITIZER_FREEBSD
// On FreeBSD, call the sigaction syscall directly (part of libsys in FreeBSD
// 15) since the libc version goes via a global interposing table. Due to
// library initialization order the table can be relocated after the call to
// InitializeDeadlySignals() which then crashes when dereferencing the
// uninitialized pointer in libc.
return __sys_sigaction(signum, (const struct sigaction *)act,
(struct sigaction *)oldact);
# else
# if !SANITIZER_GO # if !SANITIZER_GO
if (&real_sigaction) if (&real_sigaction)
return real_sigaction(signum, act, oldact); return real_sigaction(signum, act, oldact);
# endif # endif
return sigaction(signum, (const struct sigaction *)act, return sigaction(signum, (const struct sigaction *)act,
(struct sigaction *)oldact); (struct sigaction *)oldact);
# endif
} }
# endif
void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top, void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,
uptr *stack_bottom) { uptr *stack_bottom) {