Message ID | 20211019164447.16359-13-imp@bsdimp.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | bsd-user: arm (32-bit) support | expand |
On Tue, Oct 19, 2021 at 11:45 AM Warner Losh <imp@bsdimp.com> wrote: > > Copy of the signal trampoline code for arm, as well as setup_sigtramp to > write it to the stack. > > Signed-off-by: Stacey Son <sson@FreeBSD.org> > Signed-off-by: Warner Losh <imp@bsdimp.com> > --- > bsd-user/arm/target_arch_sigtramp.h | 52 +++++++++++++++++++++++++++++ > 1 file changed, 52 insertions(+) > create mode 100644 bsd-user/arm/target_arch_sigtramp.h > > diff --git a/bsd-user/arm/target_arch_sigtramp.h b/bsd-user/arm/target_arch_sigtramp.h > new file mode 100644 > index 0000000000..ed53d336ed > --- /dev/null > +++ b/bsd-user/arm/target_arch_sigtramp.h > @@ -0,0 +1,52 @@ > +/* > + * arm sysarch() system call emulation > + * > + * Copyright (c) 2013 Stacey D. Son > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation; either version 2 of the License, or > + * (at your option) any later version. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License > + * along with this program; if not, see <http://www.gnu.org/licenses/>. > + */ > + > +#ifndef _TARGET_ARCH_SIGTRAMP_H_ > +#define _TARGET_ARCH_SIGTRAMP_H_ > + > +/* Compare to arm/arm/locore.S ENTRY_NP(sigcode) */ > +static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc, > + unsigned sys_sigreturn) > +{ > + int i; > + uint32_t sys_exit = TARGET_FREEBSD_NR_exit; > + /* > + * The code has to load r7 manually rather than using > + * "ldr r7, =SYS_return to make sure the size of the > + * code is correct. > + */ > + uint32_t sigtramp_code[] = { > + /* 1 */ 0xE1A0000D, /* mov r0, sp */ > + /* 2 */ 0xE2800000 + sigf_uc, /* add r0, r0, #SIGF_UC */ > + /* 3 */ 0xE59F700C, /* ldr r7, [pc, #12] */ > + /* 4 */ 0xEF000000 + sys_sigreturn, /* swi (SYS_sigreturn) */ > + /* 5 */ 0xE59F7008, /* ldr r7, [pc, #8] */ > + /* 6 */ 0xEF000000 + sys_exit, /* swi (SYS_exit)*/ > + /* 7 */ 0xEAFFFFFA, /* b . -16 */ > + /* 8 */ sys_sigreturn, > + /* 9 */ sys_exit > + }; > + > + for (i = 0; i < 9; i++) { > + tswap32s(&sigtramp_code[i]); > + } > + > + return memcpy_to_target(offset, sigtramp_code, TARGET_SZSIGCODE); > +} > +#endif /* _TARGET_ARCH_SIGTRAMP_H_ */ > -- > 2.32.0 > Reviewed-by: Kyle Evans <kevans@FreeBSD.org>
On 10/19/21 9:44 AM, Warner Losh wrote: > + /* > + * The code has to load r7 manually rather than using > + * "ldr r7, =SYS_return to make sure the size of the > + * code is correct. > + */ This comment was applicable to the original freebsd asm source; it has no bearing on the hex instructions below. > + uint32_t sigtramp_code[] = { > + /* 1 */ 0xE1A0000D, /* mov r0, sp */ > + /* 2 */ 0xE2800000 + sigf_uc, /* add r0, r0, #SIGF_UC */ I guess this was a bit of thumb1 source that accidentally became ABI? Otherwise I can't think why you wouldn't squish the mov into the add. Anyway, Reviewed-by: Richard Henderson <richard.henderson@linaro.org> r~
On Thu, Oct 28, 2021 at 9:42 AM Richard Henderson < richard.henderson@linaro.org> wrote: > On 10/19/21 9:44 AM, Warner Losh wrote: > > + /* > > + * The code has to load r7 manually rather than using > > + * "ldr r7, =SYS_return to make sure the size of the > > + * code is correct. > > + */ > > This comment was applicable to the original freebsd asm source; it has no > bearing on the > hex instructions below Yea, the code size will always be correct... > > + uint32_t sigtramp_code[] = { > > + /* 1 */ 0xE1A0000D, /* mov r0, sp */ > > + /* 2 */ 0xE2800000 + sigf_uc, /* add r0, r0, #SIGF_UC */ > > I guess this was a bit of thumb1 source that accidentally became ABI? > Otherwise I can't think why you wouldn't squish the mov into the add. > It's in our ABI. gdb and others know what the sigcode signature looks like for sigreturn so we can't really change it without a lot of pain... So we're kinda stuck with very old-school ARM code sequences for our modern armv7 port. There's likely no reason to have the defensive call to sys_exit either, but like I said, we're kinda stuck with it w/o replacing it in a number of external sources... You may see similar issues with the aarch64 code I'll post next. > Reviewed-by: Richard Henderson <richard.henderson@linaro.org> > thanks! Warner > r~ >
diff --git a/bsd-user/arm/target_arch_sigtramp.h b/bsd-user/arm/target_arch_sigtramp.h new file mode 100644 index 0000000000..ed53d336ed --- /dev/null +++ b/bsd-user/arm/target_arch_sigtramp.h @@ -0,0 +1,52 @@ +/* + * arm sysarch() system call emulation + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef _TARGET_ARCH_SIGTRAMP_H_ +#define _TARGET_ARCH_SIGTRAMP_H_ + +/* Compare to arm/arm/locore.S ENTRY_NP(sigcode) */ +static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc, + unsigned sys_sigreturn) +{ + int i; + uint32_t sys_exit = TARGET_FREEBSD_NR_exit; + /* + * The code has to load r7 manually rather than using + * "ldr r7, =SYS_return to make sure the size of the + * code is correct. + */ + uint32_t sigtramp_code[] = { + /* 1 */ 0xE1A0000D, /* mov r0, sp */ + /* 2 */ 0xE2800000 + sigf_uc, /* add r0, r0, #SIGF_UC */ + /* 3 */ 0xE59F700C, /* ldr r7, [pc, #12] */ + /* 4 */ 0xEF000000 + sys_sigreturn, /* swi (SYS_sigreturn) */ + /* 5 */ 0xE59F7008, /* ldr r7, [pc, #8] */ + /* 6 */ 0xEF000000 + sys_exit, /* swi (SYS_exit)*/ + /* 7 */ 0xEAFFFFFA, /* b . -16 */ + /* 8 */ sys_sigreturn, + /* 9 */ sys_exit + }; + + for (i = 0; i < 9; i++) { + tswap32s(&sigtramp_code[i]); + } + + return memcpy_to_target(offset, sigtramp_code, TARGET_SZSIGCODE); +} +#endif /* _TARGET_ARCH_SIGTRAMP_H_ */