[RISCV] Rename a lambda to have plural nouns to reflect that it contains a loop. NFC
[llvm-project.git] / libc / src / signal / linux / sigaltstack.cpp
blobc19394cd1791222cf8260730bf753259c4174c2b
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 "hdr/types/stack_t.h"
11 #include "src/__support/macros/config.h"
12 #include "src/errno/libc_errno.h"
13 #include "src/signal/linux/signal_utils.h"
15 #include "src/__support/common.h"
17 #include <sys/syscall.h>
19 namespace LIBC_NAMESPACE_DECL {
21 LLVM_LIBC_FUNCTION(int, sigaltstack,
22 (const stack_t *__restrict ss, stack_t *__restrict oss)) {
23 if (ss != nullptr) {
24 unsigned not_ss_disable = ~unsigned(SS_DISABLE);
25 if ((unsigned(ss->ss_flags) & not_ss_disable) != 0) {
26 // Flags cannot have anything other than SS_DISABLE set.
27 // We do the type-casting to unsigned because the |ss_flags|
28 // field of stack_t is of type "int".
29 libc_errno = EINVAL;
30 return -1;
32 if (ss->ss_size < MINSIGSTKSZ) {
33 libc_errno = ENOMEM;
34 return -1;
38 int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_sigaltstack, ss, oss);
39 if (ret < 0) {
40 libc_errno = -ret;
41 return -1;
43 return 0;
46 } // namespace LIBC_NAMESPACE_DECL