sigaltstack: Add initial implementation of sigaltstack

fix ltp testcase compile error:
ltp/testcases/open_posix_testsuite/conformance/definitions/signal_h/31-1-buildonly.c:16:13: \
error: ‘sigaltstack’ undeclared (first use in this function)
   16 |  dummyvar = sigaltstack;
      |             ^~~~~~~~~~~

Signed-off-by: yangyalei <yangyalei@xiaomi.com>
This commit is contained in:
yangyalei 2023-06-26 14:42:21 +08:00 committed by Xiang Xiao
parent 30367fd4cd
commit 4ecff53e2c
3 changed files with 75 additions and 2 deletions

View file

@ -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

View file

@ -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

View file

@ -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 <signal.h>
#include <errno.h>
#include <string.h>
/****************************************************************************
* 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;
}