-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[sanitizer_common] Fix TgKill on Solaris #98000
[sanitizer_common] Fix TgKill on Solaris #98000
Conversation
While working on safestack on Solaris, I noticed that the `TgKill` implementation is wrong here: `TgKill` is supposed to return `-1` on error, while `thr_kill` returns `errno` instead. This patch compensates for that. This went unnoticed so far since `TgKill` has been unused. Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11` together with a subsequent patch to make safestack actually work on Solaris.
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Rainer Orth (rorth) ChangesWhile working on safestack on Solaris, I noticed that the This went unnoticed so far since Tested on Full diff: https://github.com/llvm/llvm-project/pull/98000.diff 1 Files Affected:
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 12df3ef73da4bc..eec9d652630f95 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -563,7 +563,9 @@ int TgKill(pid_t pid, tid_t tid, int sig) {
return internal_syscall(SYSCALL(thr_kill2), pid, tid, sig);
# elif SANITIZER_SOLARIS
(void)pid;
- return thr_kill(tid, sig);
+ errno = thr_kill(tid, sig);
+ // TgKill is expected to return -1 on error, not an errno.
+ return errno != 0 ? -1 : 0;
# endif
}
# endif
|
safestack currently uses its own portability layer in `safestack_platform.h`. This is both wasteful and leads to errors easily avoided by using the well-tested functions in `sanitizer_common` instead. This is particularly notable when ([safestack] Support multilib testing E.g. all Linux/i386 tests `FAIL`ed with ``` safestack CHECK failed: /vol/llvm/src/llvm-project/local/compiler-rt/lib/safestack/safestack.cpp:95 MAP_FAILED != addr ``` because the safestack `mmap` implementation doesn't work there. Thus this patch switches safestack to use the `sanitizer_common` code instead. It's mostly obvious, with the exception of `TgKill`: - The `sanitizer_common` Linux `TgKill` implementation is wrong: while safestack used `syscall(SYS_tgkill)`, `sanitizer_common` has `internal_syscall(SYSCALL(tgkill))` instead. However, the latter (based on using the `syscall` insn directly on x86_64) returns `errno` instead of the expeccted `-1`. Besides, `TgKill` had to be moved to `sanitizer_linux_libcdep.cpp`, otherwise the `Sanitizer-x86_64-Test-Nolibc` test failed to link with an undefined reference to `syscall`. - On Solaris, a similar issue with `thr_kill` went unnoticed before because `sanitizer_common` `TgKill` wasn't used. ([sanitizer_common] Fix TgKill on Solaris)[llvm#98000] was merged into this patch. - On 32-bit Linux/sparc, `pthread-cleanup.c` would `FAIL` because a `tid_t` (`uint64_t`) `tid` arg was passed to `syscall(SYS_tgkill)` while `tid` is actually a `pid_t` (`int`). Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, `x86_64-pc-solaris2.11`, and `sparc64-unknown-linux-gnu`.
Summary: While working on safestack on Solaris, I noticed that the `TgKill` implementation is wrong here: `TgKill` is supposed to return `-1` on error, while `thr_kill` returns `errno` instead. This patch compensates for that. This went unnoticed so far since `TgKill` has been unused. Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11` together with a subsequent patch to make safestack actually work on Solaris. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D59822428
Summary: While working on safestack on Solaris, I noticed that the `TgKill` implementation is wrong here: `TgKill` is supposed to return `-1` on error, while `thr_kill` returns `errno` instead. This patch compensates for that. This went unnoticed so far since `TgKill` has been unused. Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11` together with a subsequent patch to make safestack actually work on Solaris. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251717
While working on safestack on Solaris, I noticed that the
TgKill
implementation is wrong here:TgKill
is supposed to return-1
on error, whilethr_kill
returnserrno
instead. This patch compensates for that.This went unnoticed so far since
TgKill
has been unused.Tested on
amd64-pc-solaris2.11
andsparcv9-sun-solaris2.11
together with a subsequent patch to make safestack actually work on Solaris.