[LTP] [PATCH] syscalls/waitid10: Fix on ARM, PPC and possibly others
Jan Stancek
jstancek@redhat.com
Tue Apr 19 10:07:48 CEST 2022
On Thu, Mar 10, 2022 at 11:53 AM Cyril Hrubis <chrubis@suse.cz> wrote:
>
> While integer division by zero does trap on x86_64 and causes the SIGFPE
> signal to be delivered it's not the case on all architecutes.
With gcc version 12.0.1 I don't get SIGFPE even on x86:
int main(void)
{
volatile int a, zero = 0;
a = 1 / zero;
}
0x0000000000401020 <+0>: movl $0x0,-0x4(%rsp)
0x0000000000401028 <+8>: mov -0x4(%rsp),%eax
0x000000000040102c <+12>: lea 0x1(%rax),%edx
0x000000000040102f <+15>: cmp $0x2,%edx
0x0000000000401032 <+18>: mov $0x0,%edx
0x0000000000401037 <+23>: cmova %edx,%eax
0x000000000040103a <+26>: mov %eax,-0x8(%rsp)
0x000000000040103e <+30>: xor %eax,%eax
0x0000000000401040 <+32>: ret
It does trigger with a small modification:
@@ -25,9 +25,9 @@ static void run(void)
pidchild = SAFE_FORK();
if (!pidchild) {
- volatile int a, zero = 0;
+ volatile int a = 1, zero = 0;
- a = 1 / zero;
+ a = a / zero;
exit(a);
}
> At least
> on ARM and PPC64LE division by zero simply returns undefined result
> instead.
>
> This patch adds raise(SIGFPE) at the end of the child as a fallback to
> make sure the process is killed with the right signal on all
> architectures.
>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
> testcases/kernel/syscalls/waitid/waitid10.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/testcases/kernel/syscalls/waitid/waitid10.c b/testcases/kernel/syscalls/waitid/waitid10.c
> index 869ef18bd..8c351d120 100644
> --- a/testcases/kernel/syscalls/waitid/waitid10.c
> +++ b/testcases/kernel/syscalls/waitid/waitid10.c
> @@ -28,7 +28,10 @@ static void run(void)
> volatile int a, zero = 0;
>
> a = 1 / zero;
> - exit(a);
> +
> + tst_res(TINFO, "Division by zero didn't trap, raising SIGFPE");
> +
> + raise(SIGFPE);
I agree with Petr, that raise(SIGFPE) would be sufficient for this test.
> }
>
> TST_EXP_PASS(waitid(P_ALL, 0, infop, WEXITED));
> --
> 2.34.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
More information about the ltp
mailing list