[NFC][Py Reformat] Added more commits to .git-blame-ignore-revs
[llvm-project.git] / libc / src / signal / linux / sigaction.cpp
blobb3f057ebb5adc0b6f5ed1d8bf68a7823482ed975
1 //===-- Linux implementation of sigaction ---------------------------------===//
2 //
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
6 //
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"
15 #include <signal.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;
28 if (libc_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));
40 if (ret) {
41 libc_errno = -ret;
42 return -1;
45 if (libc_old)
46 *libc_old = kernel_old;
47 return 0;
50 } // namespace __llvm_libc