1 //===-- Linux implementation of sigaction ---------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/signal/sigaction.h"
10 #include "src/errno/libc_errno.h"
11 #include "src/signal/linux/signal_utils.h"
13 #include "src/__support/common.h"
17 namespace __llvm_libc
{
19 // TOOD: Some architectures will have their signal trampoline functions in the
20 // vdso, use those when available.
22 extern "C" void __restore_rt();
24 LLVM_LIBC_FUNCTION(int, sigaction
,
25 (int signal
, const struct sigaction
*__restrict libc_new
,
26 struct sigaction
*__restrict libc_old
)) {
27 KernelSigaction kernel_new
;
29 kernel_new
= *libc_new
;
30 if (!(kernel_new
.sa_flags
& SA_RESTORER
)) {
31 kernel_new
.sa_flags
|= SA_RESTORER
;
32 kernel_new
.sa_restorer
= __restore_rt
;
36 KernelSigaction kernel_old
;
37 int ret
= __llvm_libc::syscall_impl(
38 SYS_rt_sigaction
, signal
, libc_new
? &kernel_new
: nullptr,
39 libc_old
? &kernel_old
: nullptr, sizeof(sigset_t
));
46 *libc_old
= kernel_old
;
50 } // namespace __llvm_libc