-
-
Notifications
You must be signed in to change notification settings - Fork 602
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
Provide limited implementation of the tgkill syscall needed by Golang PIE apps #1047
Comments
As I was researching other Golang related issues, I came back at this one, and here is what I am suggesting we do. First of the TEXT runtime·raise(SB),NOSPLIT,$0
MOVL $SYS_getpid, AX
SYSCALL
MOVL AX, R12
MOVL $SYS_gettid, AX
SYSCALL
MOVL AX, SI // arg 2 tid
MOVL R12, DI // arg 1 pid
MOVL sig+0(FP), DX // arg 3
MOVL $SYS_tgkill, AX
SYSCALL
RET When Ctrl-C is called, Golang calls
So I think we have to do:
inline bool is_sig_dfl(const struct sigaction &sa) {
- return (!(sa.sa_flags & SA_SIGINFO) && sa.sa_handler == SIG_DFL);
+ return sa.sa_handler == SIG_DFL;
} I do not understand the original reasoning, but I do not think we should treat the |
inline bool is_sig_dfl(const struct sigaction &sa) {
if (sa.sa_flags & SA_SIGINFO) {
return sa.sa_sigaction == nullptr; // a non-standard Linux extension
} else {
return sa.sa_handler == SIG_DFL;
}
} |
The golang applications use the tgkill syscall to implement the raise() function as the issue #1047 describes. The raise() function is then used to propagate SIGTERM signal to the process when Ctrl-C is pressed. For that reason this patch adds very basic implementation of the tgkill syscall. More specifically it only handles the case where tpid specifies current process or -1 and tid specifies the current thread of the caller which in essence is what Golang raise() passes. In this case the tgkill syscall implementation delegates to kill() otherwise it returns failure. This patch also modifies the implementation of the pthread_kill() to make it consistent with the implementation of the tgkill syscall. The pthread_kill is actually called by raise() (see libc/pthread.cc) so just like with tgkill, we check if specified pthread_t is equal to the current thread and in such case we delegate to kill(). Lastly this patch enhances tst-kill.cc to test raise() and pthread_kill(). Refs #1047 Signed-off-by: Waldemar Kozaczuk <[email protected]> Message-Id: <[email protected]>
The commit 33bea60 fixed the original crash reported by issue #1026. However, when a user presses Ctrl-C on running golang-pie-httpserver app, OSv prints message about unimplemented tgkill syscall instead of exiting gracefully.
The goal of this issue is to provide a limited but reasonable implementation of this syscall to let Golang apps like the one mentioned here exit gracefully.
For more details please see this discussion on OSv dev list.
The text was updated successfully, but these errors were encountered: