Skip to contentSkip to conversation

waitid10: raise SIGFPE directly

PATCH In review Cyril Hrubis 3 participants 6 messages May 12, 2022 – May 13, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 waitid10: raise SIGFPE directly

The SIGFPE for division by zero is actually not send for quite a few architectures (ARM for instance) and even on x86 and x86_64 we need to work around compiler to make it generate code that actually triggers the condition.

So this patch fixes the test in the simplest way possible. the child just directly raises SIGFPE instead.

---
 testcases/kernel/syscalls/waitid/waitid10.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
testcases/kernel/syscalls/waitid/waitid10.c +2 -6
index e75edd07e..388b31cc9 100644
@@ -24,12 +24,8 @@ static void run(void)
 	pid_t pidchild;
 
 	pidchild = SAFE_FORK();
-	if (!pidchild) {
-		volatile int a, zero = 0;
-
-		a = 1 / zero;
-		exit(a);
-	}
+	if (!pidchild)
+		raise(SIGFPE);
 
 	TST_EXP_PASS(waitid(P_ALL, 0, infop, WEXITED));
 	TST_EXP_EQ_LI(infop->si_pid, pidchild);
Signature · 5 lines
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Acked-by on v2 1/1
#1 lore raw
Quoted 10 lines · Cyril Hrubis

The SIGFPE for division by zero is actually not send for quite a few architectures (ARM for instance) and even on x86 and x86_64 we need to work around compiler to make it generate code that actually triggers the condition.

So this patch fixes the test in the simplest way possible. the child just directly raises SIGFPE instead.

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v2 1/1
#2 lore raw
In reply to Cyril Hrubis
Quoted 21 lines · Cyril Hrubis

The SIGFPE for division by zero is actually not send for quite a few architectures (ARM for instance) and even on x86 and x86_64 we need to work around compiler to make it generate code that actually triggers the condition.

So this patch fixes the test in the simplest way possible. the child just directly raises SIGFPE instead.

---
 testcases/kernel/syscalls/waitid/waitid10.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
testcases/kernel/syscalls/waitid/waitid10.c +0 -0
index e75edd07e..388b31cc9 100644
@@ -24,12 +24,8 @@ static void run(void)
        pid_t pidchild;
 

testcases/kernel/syscalls/waitid/waitid10.c static void run(void) · line 29

Quoted 10 lines
testcases/kernel/syscalls/waitid/waitid10.c +2 -6
        pidchild = SAFE_FORK();
-       if (!pidchild) {
-               volatile int a, zero = 0;
-
-               a = 1 / zero;
-               exit(a);
-       }
+       if (!pidchild)
+               raise(SIGFPE);
 

Better to have code comments to explain the reason here, just for better readability.

And vote for merging before the new release as well.

Quoted 11 lines
testcases/kernel/syscalls/waitid/waitid10.c +0 -1
        TST_EXP_PASS(waitid(P_ALL, 0, infop, WEXITED));
        TST_EXP_EQ_LI(infop->si_pid, pidchild);
--

2.35.1

--
Mailing list info: https://lists.linux.it/listinfo/ltp

Signature · 2 lines
Regards,
Li Wang
Signature · 2 lines
-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi!

Quoted 2 lines

Better to have code comments to explain the reason here, just for better readability.

What exactly should we comment there, something as:

Triggering SIGFPE by invalid instruction is not always possible, some architectures does not trap division-by-zero at all and even when it's possible we would have to fight the compiler optimizations that have tendency to remove undefined operations.

Quoted 1 line

And vote for merging before the new release as well.

That's what I'm aiming for.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw
Quoted 5 lines

Triggering SIGFPE by invalid instruction is not always possible, some architectures does not trap division-by-zero at all and even when it's possible we would have to fight the compiler optimizations that have tendency to remove undefined operations.

Looks good.

Signature · 2 lines
Regards,
Li Wang
Signature · 2 lines
-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Hi!
Added comment and pushed, thanks for the reviews.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp