1 /* Emulate sigstack function using sigaltstack.
2 Copyright (C) 1998-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
21 #include <sys/syscall.h>
25 sigstack (struct sigstack
*ss
, struct sigstack
*oss
)
30 stack_t
*osasp
= oss
== NULL
? NULL
: &osas
;
35 /* We have to convert the information. */
36 sas
.ss_sp
= ss
->ss_sp
;
37 sas
.ss_flags
= ss
->ss_onstack
? SS_ONSTACK
: 0;
39 /* For the size of the stack we have no value we can pass to the
40 kernel. This is why this function should not be used. We simply
41 assume that all the memory down to address zero (in case the stack
42 grows down) is available. */
43 sas
.ss_size
= ss
->ss_sp
- NULL
;
48 /* Call the kernel. */
49 result
= __sigaltstack (sasp
, osasp
);
51 /* Convert the result, if wanted and possible. */
52 if (result
== 0 && oss
!= NULL
)
54 oss
->ss_sp
= osas
.ss_sp
;
55 oss
->ss_onstack
= (osas
.ss_flags
& SS_ONSTACK
) != 0;
61 link_warning (sigstack
, "the `sigstack' function is dangerous. `sigaltstack' should be used instead.")