From: Paul Floyd Date: Tue, 18 Oct 2022 21:38:36 +0000 (+0200) Subject: Add auxv entry for usrstack on FreeBSD 14, part 1 X-Git-Tag: VALGRIND_3_20_0~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=121374b287ce39ef0e42e45dfc27ae0949e6f528;p=thirdparty%2Fvalgrind.git Add auxv entry for usrstack on FreeBSD 14, part 1 Previously the user stack was obtained using the kern.usrstack sysctl. This has been moved to auxv in FreeBSD 14. Without this change all programs linked with libthr fail with a panic when they fail to get a valid user stack address. Note also in FreeBSD 14 ASLR has been enabled. This means that there is now some extra difference between the address layout of a standalone executable and the same executable under valgrind. Pre-FreeBSD 14 and under valgrind: lib rtld is loaded after the executable (though a much smaller gap inder valgrind) user stack starts at 0x7ffffffff000 FreeBSD 14 lib rtld is loaded at a much higher address, around 0xeeeecc15000 user stack is at a much lower address, around 0x82073d000 This means that valgrind behaves somewhat as thogh the kern.elf(64|32).aslr.stack sysctl were set to 0. Some more work will be needed for the stack size. There are no plans at the moment to match the FreeBSD 14 memory layout. --- diff --git a/coregrind/m_initimg/initimg-freebsd.c b/coregrind/m_initimg/initimg-freebsd.c index f315a147ff..920ed92911 100644 --- a/coregrind/m_initimg/initimg-freebsd.c +++ b/coregrind/m_initimg/initimg-freebsd.c @@ -713,6 +713,15 @@ Addr setup_client_stack( void* init_sp, // case AT_KPRELOAD: #endif +#if (FREEBSD_VERS >= FREEBSD_14) + case AT_USRSTACKBASE: + auxv->u.a_val = VG_(get_usrstack)(); + break; + case AT_USRSTACKLIM: + auxv->a_type = AT_IGNORE; + break; +#endif + case AT_PHDR: if (info->phdr == 0) auxv->a_type = AT_IGNORE;