foss-for-synopsys-dwc-arc-processors / linux

Helpful resources for users & developers of Linux kernel for ARC
22 stars 13 forks source link

Glibc's sigcontext doesn't match kernel's one #53

Closed VVIsaev closed 3 years ago

VVIsaev commented 3 years ago

In glibc we have mcontext with __r30, __r58, __r59; https://github.com/foss-for-synopsys-dwc-arc-processors/glibc/blob/9826b03b747b841f5fc6de2054bf1ef3f5c4bdf3/sysdeps/unix/sysv/linux/arc/sys/ucontext.h#L29 .

When in kernel we don't have these registers in sigcontext: https://elixir.bootlin.com/linux/v5.13-rc5/source/arch/arc/include/uapi/asm/sigcontext.h#L19 https://elixir.bootlin.com/linux/v5.13-rc5/source/arch/arc/include/uapi/asm/ptrace.h#L34 .

I don't think that it actually affects something, just observation that can be fixed or at least commented.

vineetgarc commented 3 years ago

In glibc we have mcontext with __r30, __r58, __r59; https://github.com/foss-for-synopsys-dwc-arc-processors/glibc/blob/9826b03b747b841f5fc6de2054bf1ef3f5c4bdf3/sysdeps/unix/sysv/linux/arc/sys/ucontext.h#L29 .

That is good as we have the right ABI in place.

When in kernel we don't have these registers in sigcontext: https://elixir.bootlin.com/linux/v5.13-rc5/source/arch/arc/include/uapi/asm/sigcontext.h#L19

Yes this could be an issue - we need to preserve these registers across signal handling - looks like when we added the ARCv2 regset, we missed adding it here.

https://elixir.bootlin.com/linux/v5.13-rc5/source/arch/arc/include/uapi/asm/ptrace.h#L34 .

This is likely not an issue (adding Sahahb to confirm). gdb ptrace infrastructure uses user_regs_struct and user_regs_arcv2 explicitly and not struct ucontext interface.

I don't think that it actually affects something, just observation that can be fixed or at least commented.

Well there are 2 potential issues here

  1. Linux kernel is not saving/restoring these registers across signal handling
  2. glibc ABI while correct, is NOT getting the values of those registers populated.
shahab-vahedi commented 3 years ago

gdb ptrace infrastructure uses user_regs_struct and user_regs_arcv2 explicitly and not struct ucontext interface.

Indeed! That is the reason of arc: Add support for ARC HS extra registers in core files commit in binutils.

Nevertheless, your 2 points in the end are correct.

vineetgarc commented 3 years ago

Fix posted http://lists.infradead.org/pipermail/linux-snps-arc/2021-June/005202.html

vineetgarc commented 3 years ago

Merged upstream for 5.13-rc7 inclusion 2021-06-08 96f1b00138cb ARCv2: save ABI registers across signal handling