I'm having an issue with ptrace PT_SETREGS on FreeBSD 15.0-ALPHA4 (and ALPHA3) on aarch64.
This seems to be a regression related to FreeBSD 15. It worked OK with FreeBSD 14.0 14.1 and works OK with 14.3.
What should happen.The purpose of the code is to force a call to a polling function if the inferior is blocked in system calls.
All the above works OK apart from X0. Instead of seeing 0x8BADF00D the value is 4 which triggers an assert.
How to reproduce
On FreeBSD 15.0-ALPAH4 arm64. You'll need gmake, gdb and autotools installed.
I've already tried quite a few things
This seems to be a regression related to FreeBSD 15. It worked OK with FreeBSD 14.0 14.1 and works OK with 14.3.
What should happen.The purpose of the code is to force a call to a polling function if the inferior is blocked in system calls.
- Call ptrace PT_GETREGS to get the stack pointer
- Set the registers for the polling function
- ELR the address of the polling function
- LR a phony address (0 - the polling function will return via longjmp())
- SP based on what we got with PT_GETREGS
- X0 argument to the polling function, a check value of 0x8BADF00D
- Call ptrace PT_CONTINUE
All the above works OK apart from X0. Instead of seeing 0x8BADF00D the value is 4 which triggers an assert.
How to reproduce
On FreeBSD 15.0-ALPAH4 arm64. You'll need gmake, gdb and autotools installed.
- glt clone https://sourceware.org/git/valgrind.git
- cd valgrind
- ./autogen.sh
- ./configure
- gmake
- make sure that you have two terminals
- In terminal 1 in the valgrind directory run./vg-in-place --tool=none --vgdb-eror=0 sleep 10000
- In terminal 2 rungdbthen at the gdb prompt - replace {path} with the path containing the valgrind directorytarget remote | {path}/valgrind/coregrind/vgdbthencontinuethenctrl-c
valgrind: m_gdbserver/m_gdbserver.c:883 (void vgPlain_invoke_gdbserver(int, int)): Assertion 'check == 0x8BADF00D' failed.
host stacktrace:
==2874== at 0x380A902C: show_sched_status_wrk (m_libcassert.c:426)
==2874== by 0x380A9353: report_and_quit (m_libcassert.c:497)
==2874== by 0x380A932F: vgPlain_assert_fail (m_libcassert.c:564)
==2874== by 0x38180CB3: vgPlain_invoke_gdbserver (m_gdbserver.c:883)
==2874== by 0xFFFFFFFFFFFFFFFF: ???
sched status:
running_tid=0<br><br>Thread 1: status = VgTs_WaitSys syscall 240 (lwpid 100170)
==2874== at 0x4D27BF4: _nanosleep (in /lib/libsys.so.7)
==2874== by 0x4010ECF: ??? (in /bin/sleep)
==2874== by 0x49718BB: __libc_start1 (in /lib/libc.so.7)
==2874== by 0x4010C9B: ??? (in /bin/sleep)
client stack range: [0x1FBFFFC000 0x1FC0000FFF] client SP: 0x1FC00009A0
valgrind stack range: [0x100278E000 0x100288DFFF] top usage: 12688 of 1048576
I've already tried quite a few things
- Reading back the registers, they are identical.
- Reading the instructions from the address put in ELR they match what I see in the binary with objdump.
- Adding a second argument works OK. The value that I put in X1 appears as the second argument.
- Tried using clang 19 on FreeBSD 14.3 (19 is the default compiler on FreeBSD 15), and it worked OK.