[NFC][Py Reformat] Added more commits to .git-blame-ignore-revs
[llvm-project.git] / libc / src / signal / linux / sigaltstack.cpp
blob359a643f847bd99a1a3a12c6fb52e5a71dff1243
1 //===-- Linux implementation of sigaltstack -------------------------------===//
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/sigaltstack.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>
16 #include <sys/syscall.h>
18 namespace __llvm_libc {
20 LLVM_LIBC_FUNCTION(int, sigaltstack,
21 (const stack_t *__restrict ss, stack_t *__restrict oss)) {
22 if (ss != nullptr) {
23 unsigned not_ss_disable = ~unsigned(SS_DISABLE);
24 if ((unsigned(ss->ss_flags) & not_ss_disable) != 0) {
25 // Flags cannot have anything other than SS_DISABLE set.
26 // We do the type-casting to unsigned because the |ss_flags|
27 // field of stack_t is of type "int".
28 libc_errno = EINVAL;
29 return -1;
31 if (ss->ss_size < MINSIGSTKSZ) {
32 libc_errno = ENOMEM;
33 return -1;
37 int ret = __llvm_libc::syscall_impl(SYS_sigaltstack, ss, oss);
38 if (ret < 0) {
39 libc_errno = -ret;
40 return -1;
42 return 0;
45 } // namespace __llvm_libc