1 //===-- Linux implementation of sigaltstack -------------------------------===//
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/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
)) {
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".
32 if (ss
->ss_size
< MINSIGSTKSZ
) {
38 int ret
= LIBC_NAMESPACE::syscall_impl
<int>(SYS_sigaltstack
, ss
, oss
);
46 } // namespace LIBC_NAMESPACE_DECL