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 "src/errno/libc_errno.h"
11 #include "src/signal/linux/signal_utils.h"
13 #include "src/__support/common.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
)) {
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".
31 if (ss
->ss_size
< MINSIGSTKSZ
) {
37 int ret
= __llvm_libc::syscall_impl(SYS_sigaltstack
, ss
, oss
);
45 } // namespace __llvm_libc