From: Paul Floyd Date: Tue, 18 Oct 2022 20:11:32 +0000 (+0200) Subject: Auxv user stack for FreeBSD, part 2 X-Git-Tag: VALGRIND_3_20_0~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=802f2d21d9e0148393845616a329a8041353e2f3;p=thirdparty%2Fvalgrind.git Auxv user stack for FreeBSD, part 2 Try to set the stack limit. --- diff --git a/coregrind/m_initimg/initimg-freebsd.c b/coregrind/m_initimg/initimg-freebsd.c index 920ed92911..43b88948af 100644 --- a/coregrind/m_initimg/initimg-freebsd.c +++ b/coregrind/m_initimg/initimg-freebsd.c @@ -718,7 +718,7 @@ Addr setup_client_stack( void* init_sp, auxv->u.a_val = VG_(get_usrstack)(); break; case AT_USRSTACKLIM: - auxv->a_type = AT_IGNORE; + auxv->u.a_val = VG_(get_usrstacklim)(); break; #endif diff --git a/coregrind/m_main.c b/coregrind/m_main.c index 200da407fb..327a130a80 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -3903,12 +3903,18 @@ UWord voucher_mach_msg_set ( UWord arg1 ) #endif - +#if defined(VGO_freebsd) Word VG_(get_usrstack)(void) { return VG_PGROUNDDN(the_iicii.clstack_end) + VKI_PAGE_SIZE; } +Word VG_(get_usrstacklim)(void) +{ + return the_iifii.clstack_max_size; +} +#endif + /*--------------------------------------------------------------------*/ diff --git a/coregrind/m_syswrap/syswrap-freebsd.c b/coregrind/m_syswrap/syswrap-freebsd.c index 518eaf0871..0fad6aa844 100644 --- a/coregrind/m_syswrap/syswrap-freebsd.c +++ b/coregrind/m_syswrap/syswrap-freebsd.c @@ -2022,7 +2022,7 @@ PRE(sys___sysctl) /* * Special handling cases * - * 1. kern.userstack + * 1. kern.usrstack * This sysctl returns the address of the bottom of the user stack * (that is the highest user stack address, since the stack grows * downwards). Without any special handling this would return the @@ -2034,7 +2034,7 @@ PRE(sys___sysctl) */ if (SARG2 >= 2 && ML_(safe_to_deref)(name, 2*sizeof(int))) { if (name[0] == 1 && name[1] == 33) { - // kern.userstack + // kern.usrstack sysctl_kern_usrstack((SizeT*)ARG3, (SizeT*)ARG4); SET_STATUS_Success(0); } diff --git a/coregrind/pub_core_aspacemgr.h b/coregrind/pub_core_aspacemgr.h index aac2a0a321..1a73ac1a34 100644 --- a/coregrind/pub_core_aspacemgr.h +++ b/coregrind/pub_core_aspacemgr.h @@ -384,9 +384,11 @@ extern Bool VG_(am_search_for_new_segment)(Addr *start, SizeT *size, UInt *prot); #endif +#if defined(VGO_freebsd) /* For kern.usrstack syscall on FreeBSD */ extern Word VG_(get_usrstack)(void); - +extern Word VG_(get_usrstacklim)(void); +#endif #endif // __PUB_CORE_ASPACEMGR_H diff --git a/none/tests/freebsd/auxv.c b/none/tests/freebsd/auxv.c index 9033c3427e..778280b39a 100644 --- a/none/tests/freebsd/auxv.c +++ b/none/tests/freebsd/auxv.c @@ -38,7 +38,7 @@ Elf_AuxStr aux_map[AT_COUNT] = { {"AT_HWCAP", 25}, {"AT_HWCAP2", 26}, // FreeBSD 12 and 11 -// {"AT_COUNT", 27}, +// {"AT_COUNT", 27}, #if (FREEBSD_VERS >= FREEBSD_13_0) {"AT_BSDFLAGS", 27}, {"AT_ARGC", 28}, @@ -46,13 +46,17 @@ Elf_AuxStr aux_map[AT_COUNT] = { {"AT_ENVC", 30}, {"AT_ENVV", 31}, {"AT_PS_STRINGS", 32}, -// {"AT_COUNT", 33}, +// {"AT_COUNT", 33}, #endif #if (FREEBSD_VERS >= FREEBSD_13_1) {"AT_FXRNG", 33}, {"AT_KPRELOAD", 34}, - -// {"AT_COUNT", 35}, +// {"AT_COUNT", 35}, +#endif +#if (FREEBSD_VERS >= FREEBSD_14) + {"AT_USRSTACKBASE", 35}, + {"AT_USRSTACKLIM", 36), +// {"AT_COUNT", 37}, #endif };