From: Paul Floyd Date: Sun, 7 Dec 2025 20:59:40 +0000 (+0100) Subject: FreeBSD and Darwin: clean up fake sigreturn syscall numbers X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48354b20831bbfe6a44ca8d2d700bd8a279c036c;p=thirdparty%2Fvalgrind.git FreeBSD and Darwin: clean up fake sigreturn syscall numbers Firstly make them a bit more similar. Secondly, switch Darwin from using __NR_MAXSYSCALL which changes with every Darwin version to using 1000 like FreeBSD. Change NEWS for macOS 10.13, it has now progressed beyond 'preliminary'. --- diff --git a/NEWS b/NEWS index 0731634f8..0702dbc94 100644 --- a/NEWS +++ b/NEWS @@ -4,9 +4,9 @@ Release 3.27.0 (?? Apr 2025) This release supports X86/Linux, AMD64/Linux, ARM32/Linux, ARM64/Linux, PPC32/Linux, PPC64BE/Linux, PPC64LE/Linux, S390X/Linux, MIPS32/Linux, MIPS64/Linux, RISCV64/Linux, ARM/Android, ARM64/Android, MIPS32/Android, -X86/Android, X86/Solaris, AMD64/Solaris, AMD64/MacOSX 10.12, X86/FreeBSD, -AMD64/FreeBSD and ARM64/FreeBSD There is also preliminary support for -X86/macOS 10.13, AMD64/macOS 10.13 and nanoMIPS/Linux. +X86/Android, X86/Solaris, AMD64/Solaris, X86/macOS, AMD64/macOS. +X86/FreeBSD, AMD64/FreeBSD and ARM64/FreeBSD. There is preliminary support +for nanoMIPS/Linux. macOS is supported up to version 10.13 High Sierra. * ==================== CORE CHANGES =================== diff --git a/coregrind/m_signals.c b/coregrind/m_signals.c index a914cd0c2..1b0200287 100644 --- a/coregrind/m_signals.c +++ b/coregrind/m_signals.c @@ -1041,7 +1041,7 @@ extern void my_sigreturn(void); ".text\n" \ ".globl my_sigreturn\n" \ "my_sigreturn:\n" \ - " movl $" VG_STRINGIFY(__NR_DARWIN_FAKE_SIGRETURN) ",%eax\n" \ + " movl $" VG_STRINGIFY(__NR_darwin_fake_sigreturn) ",%eax\n" \ " int $0x80\n" #elif defined(VGP_amd64_darwin) @@ -1049,7 +1049,7 @@ extern void my_sigreturn(void); ".text\n" \ ".globl my_sigreturn\n" \ "my_sigreturn:\n" \ - " movq $" VG_STRINGIFY(__NR_DARWIN_FAKE_SIGRETURN) ",%rax\n" \ + " movq $" VG_STRINGIFY(__NR_darwin_fake_sigreturn) ",%rax\n" \ " syscall\n" #elif defined(VGP_s390x_linux) diff --git a/coregrind/m_syswrap/priv_syswrap-darwin.h b/coregrind/m_syswrap/priv_syswrap-darwin.h index d3fd32458..579b3d8c6 100644 --- a/coregrind/m_syswrap/priv_syswrap-darwin.h +++ b/coregrind/m_syswrap/priv_syswrap-darwin.h @@ -240,7 +240,7 @@ DECL_TEMPLATE(darwin, kdebug_trace); // 180 DECL_TEMPLATE(darwin, setegid); // 182 DECL_TEMPLATE(darwin, seteuid); // 183 DECL_TEMPLATE(darwin, sigreturn); // 184 -DECL_TEMPLATE(darwin, FAKE_SIGRETURN); +DECL_TEMPLATE(darwin, fake_sigreturn); // 1000 // NYI chud 185 #if DARWIN_VERS >= DARWIN_10_13 // NYI thread_selfcounts // 186 diff --git a/coregrind/m_syswrap/syswrap-darwin.c b/coregrind/m_syswrap/syswrap-darwin.c index 67fdd9e26..0113d388d 100644 --- a/coregrind/m_syswrap/syswrap-darwin.c +++ b/coregrind/m_syswrap/syswrap-darwin.c @@ -9358,7 +9358,7 @@ PRE(swtch_pri) } -PRE(FAKE_SIGRETURN) +PRE(fake_sigreturn) { /* See comments on PRE(sys_rt_sigreturn) in syswrap-amd64-linux.c for an explanation of what follows. */ @@ -9366,7 +9366,7 @@ PRE(FAKE_SIGRETURN) sigframe-x86-darwin.c. */ /* See also comments just below on PRE(sigreturn). */ - PRINT("FAKE_SIGRETURN ( )"); + PRINT("fake_sigreturn ( )"); vg_assert(VG_(is_valid_tid)(tid)); vg_assert(tid >= 1 && tid < VG_N_THREADS); @@ -9430,10 +9430,10 @@ PRE(sigreturn) 1. Change the second argument of VG_(sigframe_destroy) from "Bool isRT" to "UInt sysno", so we can pass the syscall number, so it can distinguish this case from the - __NR_DARWIN_FAKE_SIGRETURN case. + __NR_darwin_fake_sigreturn case. 2. In VG_(sigframe_destroy), look at sysno to distinguish the - cases. For __NR_DARWIN_FAKE_SIGRETURN, behave as at present. + cases. For __NR_darwin_fake_sigreturn, behave as at present. For this case, restore the thread's CPU state (or at least the integer regs) from the ucontext in ARG1 (and do all the other "signal-returns" stuff too). @@ -11542,8 +11542,8 @@ const SyscallTableEntry ML_(syscall_table)[] = { // _____(__NR_ntp_gettime), // 528 // _____(__NR_os_fault_with_payload), // 529 #endif -// _____(__NR_MAXSYSCALL) - MACX_(__NR_DARWIN_FAKE_SIGRETURN, FAKE_SIGRETURN) + + MACX_(__NR_darwin_fake_sigreturn, fake_sigreturn) }; diff --git a/coregrind/m_syswrap/syswrap-freebsd.c b/coregrind/m_syswrap/syswrap-freebsd.c index c2fd35d2b..e1c1dcc14 100644 --- a/coregrind/m_syswrap/syswrap-freebsd.c +++ b/coregrind/m_syswrap/syswrap-freebsd.c @@ -7941,7 +7941,7 @@ const SyscallTableEntry ML_(syscall_table)[] = { BSDX_(__NR_jail_attach_jd, sys_jail_attach_jd), // 597 BSDX_(__NR_jail_remove_jd, sys_jail_remove_jd), // 598 - BSDX_(__NR_fake_sigreturn, sys_fake_sigreturn), // 1000, fake sigreturn + BSDX_(__NR_freebsd_fake_sigreturn, sys_fake_sigreturn), // 1000, fake sigreturn }; diff --git a/coregrind/m_trampoline.S b/coregrind/m_trampoline.S index 0746fd0f1..6ba42613e 100644 --- a/coregrind/m_trampoline.S +++ b/coregrind/m_trampoline.S @@ -960,7 +960,7 @@ VG_(x86_freebsd_SUBST_FOR_sigreturn): pushl %eax pushl %eax /* fake return addr */ /* movl 0x44(%eax), %gs ; restore %gs, not done by sigreturn */ - movl $__NR_fake_sigreturn, %eax + movl $__NR_freebsd_fake_sigreturn, %eax int $0x80 ud2 @@ -987,7 +987,7 @@ VG_(amd64_freebsd_SUBST_FOR_sigreturn): /* This is a very specific sequence which GDB uses to recognize signal handler frames. */ - movq $__NR_fake_sigreturn, %rax + movq $__NR_freebsd_fake_sigreturn, %rax /* running the preprocessor on * src/amd64.amd64/lib/libc/sigreturn.S @@ -1046,7 +1046,7 @@ VG_(trampoline_stuff_start): .global VG_(arm64_freebsd_SUBST_FOR_sigreturn) .type VG_(arm64_freebsd_SUBST_FOR_sigreturn),#function VG_(arm64_freebsd_SUBST_FOR_sigreturn): - mov x8, # __NR_fake_sigreturn + mov x8, # __NR_freebsd_fake_sigreturn mov x0, sp svc #0 .long 0xFFFFFFFF /*illegal insn*/ @@ -1082,7 +1082,7 @@ VG_(trampoline_stuff_start): VG_(x86_darwin_SUBST_FOR_sigreturn): /* XXX does this need to have any special form? (cf x86-linux version) */ - movl $ __NR_DARWIN_FAKE_SIGRETURN, %eax + movl $ __NR_darwin_fake_sigreturn, %eax int $0x80 ud2 @@ -1242,7 +1242,7 @@ VG_(trampoline_stuff_start): VG_(amd64_darwin_SUBST_FOR_sigreturn): /* XXX does this need to have any special form? (cf x86-linux version) */ - movq $ __NR_DARWIN_FAKE_SIGRETURN, %rax + movq $ __NR_darwin_fake_sigreturn, %rax syscall ud2 diff --git a/include/vki/vki-scnums-darwin.h b/include/vki/vki-scnums-darwin.h index ae1618b52..9e5c86964 100644 --- a/include/vki/vki-scnums-darwin.h +++ b/include/vki/vki-scnums-darwin.h @@ -850,26 +850,6 @@ #define __NR_os_fault_with_payload VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(529) #endif /* DARWIN_VERS >= DARWIN_10_13 */ -#if DARWIN_VERS < DARWIN_10_6 -#define __NR_MAXSYSCALL VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(427) -#elif DARWIN_VERS < DARWIN_10_7 -#define __NR_MAXSYSCALL VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(430) -#elif DARWIN_VERS < DARWIN_10_9 -#define __NR_MAXSYSCALL VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(430) -#elif DARWIN_VERS == DARWIN_10_9 -#define __NR_MAXSYSCALL VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(456) -#elif DARWIN_VERS == DARWIN_10_10 -#define __NR_MAXSYSCALL VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(490) -#elif DARWIN_VERS == DARWIN_10_11 -#define __NR_MAXSYSCALL VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(500) -#elif DARWIN_VERS == DARWIN_10_12 -#define __NR_MAXSYSCALL VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(522) -#elif DARWIN_VERS == DARWIN_10_13 -#define __NR_MAXSYSCALL VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(530) -#else -#error unknown darwin version -#endif - -#define __NR_DARWIN_FAKE_SIGRETURN (1 + __NR_MAXSYSCALL) +#define __NR_darwin_fake_sigreturn VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(1000) #endif diff --git a/include/vki/vki-scnums-freebsd.h b/include/vki/vki-scnums-freebsd.h index 83e4430c2..bb6d485b2 100644 --- a/include/vki/vki-scnums-freebsd.h +++ b/include/vki/vki-scnums-freebsd.h @@ -640,6 +640,6 @@ #define __NR_jail_attach_jd 597 #define __NR_jail_remove_jd 598 -#define __NR_fake_sigreturn 1000 +#define __NR_freebsd_fake_sigreturn 1000 #endif /* VKI_UNISTD_FREEBSD_H */