lib/cobalt: fix incorrect addr passed to sc_cobalt_backtrace syscall
PATCH 1/2 lib/cobalt: fix incorrect addr passed to sc_cobalt_backtrace syscall
The correct value of "frames + skip" should be
&frames[0] + skip * sizeof(void *). But ARM64/XENOMAI_SYSCALL3 expands it to (unsigned long)frames + skip, which means &frames[0] + skip. The sc_cobalt_backtrace syscall gets incorrect addr, then the backtrace of relax is invalid.
Symptom maybe as following:
2/root/latency
316 2 syscall sampling-313
.
Applied this fix:
2/usr/xenomai/bin/latency
293 2 syscall sampling-2900x2970 /usr/xenomai/bin/latency0xffffb0de4cb0 ?0x13a64 /usr/xenomai/lib/libcobalt.so.2.0.00x13b28 /usr/xenomai/lib/libcobalt.so.2.0.00x39a0 /usr/xenomai/bin/latency0x3b5c /usr/xenomai/bin/latency0x17a68 /usr/xenomai/lib/libcobalt.so.2.0.00x7d5b8 /usr/lib/aarch64-linux-gnu/libc.so.60xe5edc /usr/lib/aarch64-linux-gnu/libc.so.6
.
--- lib/cobalt/sigshadow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/cobalt/sigshadow.c +1 -1
@@ -59,7 +59,7 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void *ctxt) nr =backtrace (frames,ARRAY_SIZE (frames));/* Skip the sighandler context. */ skip = nr >3 ?3 :0 ; -XENOMAI_SYSCALL3 (sc_cobalt_backtrace, nr - skip, frames + skip, arg); +XENOMAI_SYSCALL3 (sc_cobalt_backtrace, (nr - skip), (frames + skip), arg);break ;case SIGSHADOW_ACTION_HOME :/*
Signature · 1 line
2.34.1
PATCH 2/2 lib/cobalt: arm64: Fix syscall macro argument casting
The Xenomai syscall macros in the arm64 header file cast their arguments like (unsigned long)__a1. This can cause issues when macro arguments are complex expressions, due to missing parentheses.
Update all syscall macro definitions to use (unsigned long)(__a1) style, ensuring proper evaluation order and preventing potential macro expansion bugs.
--- .../arch/arm64/include/asm/xenomai/syscall.h | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-)
lib/cobalt/arch/arm64/include/asm/xenomai/syscall.h +16 -16
@@ -74,31 +74,31 @@ DEFINE_XENOMAI_SYSCALL(5) __xenomai_do_syscall0(__op)#define XENOMAI_SYSCALL1 (__op, __a1) \ __xenomai_do_syscall1(__op, \ - (unsigned long)__a1) + (unsigned long)(__a1))#define XENOMAI_SYSCALL2 (__op, __a1, __a2) \ __xenomai_do_syscall2(__op, \ - (unsigned long)__a1, \ - (unsigned long)__a2) + (unsigned long)(__a1), \ + (unsigned long)(__a2))#define XENOMAI_SYSCALL3 (__op, __a1, __a2, __a3) \ __xenomai_do_syscall3(__op, \ - (unsigned long)__a1, \ - (unsigned long)__a2, \ - (unsigned long)__a3) + (unsigned long)(__a1), \ + (unsigned long)(__a2), \ + (unsigned long)(__a3))#define XENOMAI_SYSCALL4 (__op, __a1, __a2, __a3, __a4) \ __xenomai_do_syscall4(__op, \ - (unsigned long)__a1, \ - (unsigned long)__a2, \ - (unsigned long)__a3, \ - (unsigned long)__a4) + (unsigned long)(__a1), \ + (unsigned long)(__a2), \ + (unsigned long)(__a3), \ + (unsigned long)(__a4))#define XENOMAI_SYSCALL5 (__op, __a1, __a2, __a3, __a4, __a5) \ __xenomai_do_syscall5(__op, \ - (unsigned long)__a1, \ - (unsigned long)__a2, \ - (unsigned long)__a3, \ - (unsigned long)__a4, \ - (unsigned long)__a5) + (unsigned long)(__a1), \ + (unsigned long)(__a2), \ + (unsigned long)(__a3), \ + (unsigned long)(__a4), \ + (unsigned long)(__a5))#define XENOMAI_SYSBIND (__breq) \ __xenomai_do_syscall1(sc_cobalt_bind, \ - (unsigned long)__breq) + (unsigned long)(__breq))#endif /* !_LIB_COBALT_ARM64_SYSCALL_H */
Signature · 1 line
2.34.1
Re: [PATCH 2/2] lib/cobalt: arm64: Fix syscall macro argument casting
Quoted 7 lines · Haiyang He
The Xenomai syscall macros in the arm64 header file cast their arguments like (unsigned long)__a1. This can cause issues when macro arguments are complex expressions, due to missing parentheses.
Update all syscall macro definitions to use (unsigned long)(__a1) style, ensuring proper evaluation order and preventing potential macro expansion bugs.
Good catch. If we apply that, we do not need patch 1, right?
Re: [PATCH 2/2] lib/cobalt: arm64: Fix syscall macro argument casting
Quoted 10 lines · Florian Bezdeka
Quoted 7 lines · Haiyang He
The Xenomai syscall macros in the arm64 header file cast their arguments like (unsigned long)__a1. This can cause issues when macro arguments are complex expressions, due to missing parentheses.
Update all syscall macro definitions to use (unsigned long)(__a1) style, ensuring proper evaluation order and preventing potential macro expansion bugs.
Good catch. If we apply that, we do not need patch 1, right?
Yes.
And I still prefer both of them. Maybe more cpu arch would be introduced into Xenomai. The way in patch1 has better compatibility.
Haiyang.
Re: [PATCH 2/2] lib/cobalt: arm64: Fix syscall macro argument casting
Quoted 10 lines · Haiyang He
Quoted 9 lines · Florian Bezdeka
Quoted 7 lines · Haiyang He
The Xenomai syscall macros in the arm64 header file cast their arguments like (unsigned long)__a1. This can cause issues when macro arguments are complex expressions, due to missing parentheses.
Update all syscall macro definitions to use (unsigned long)(__a1) style, ensuring proper evaluation order and preventing potential macro expansion bugs.
Quoted 7 lines
Quoted 1 line
Good catch. If we apply that, we do not need patch 1, right?
Yes.
And I still prefer both of them. Maybe more cpu arch would be introduced into Xenomai. The way in patch1 has better compatibility.
I also prefer to make all syscall macro agnostic the parameters that come without braces. I checked arm and x86, and it seems that only arm64 had a problem here. So, I've only merged patch 2 now, enriching it with some impact description derived from patch 1.
Thanks,
Jan
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center