diff --git a/include/signal.h b/include/signal.h index 5f8421aef3a..f60a834201f 100644 --- a/include/signal.h +++ b/include/signal.h @@ -404,6 +404,7 @@ int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *value, FAR const struct timespec *timeout); int sigsuspend(FAR const sigset_t *sigmask); int sigwaitinfo(FAR const sigset_t *set, FAR struct siginfo *value); +int sigaltstack(FAR const stack_t *ss, FAR stack_t *oss); #undef EXTERN #ifdef __cplusplus diff --git a/libs/libc/signal/Make.defs b/libs/libc/signal/Make.defs index 8e7df2c69bd..9c9d81f7baf 100644 --- a/libs/libc/signal/Make.defs +++ b/libs/libc/signal/Make.defs @@ -22,10 +22,9 @@ CSRCS += sig_addset.c sig_delset.c sig_emptyset.c sig_fillset.c CSRCS += sig_nandset.c sig_andset.c sig_orset.c sig_xorset.c -CSRCS += sig_isemptyset.c +CSRCS += sig_isemptyset.c sig_killpg.c sig_altstack.c CSRCS += sig_hold.c sig_ignore.c sig_ismember.c sig_pause.c sig_psignal.c CSRCS += sig_raise.c sig_relse.c sig_set.c sig_signal.c sig_wait.c -CSRCS += sig_killpg.c # Add the signal directory to the build diff --git a/libs/libc/signal/sig_altstack.c b/libs/libc/signal/sig_altstack.c new file mode 100644 index 00000000000..9d7ded47ded --- /dev/null +++ b/libs/libc/signal/sig_altstack.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * libs/libc/signal/sig_altstack.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sigaltstack + * + * Description: + * The sigaltstack() function allows a process to define and examine the + * state of an alternate stack for signal handlers for the current thread. + * Signals that have been explicitly declared to execute on the alternate + * stack shall be delivered on the alternate stack. + * + ****************************************************************************/ + +int sigaltstack(const stack_t *ss, stack_t *oss) +{ + if (ss) + { + if (ss->ss_flags & SS_DISABLE) + { + goto out; + } + + if (ss->ss_size < MINSIGSTKSZ) + { + set_errno(ENOMEM); + return ERROR; + } + + /* not support SS_ONSTACK now */ + + set_errno(EINVAL); + return ERROR; + } + +out: + if (oss) + { + memset(oss, 0, sizeof(*oss)); + oss->ss_flags = SS_DISABLE; + } + + return OK; +}