import RT-Thread@9217865c without bsp, libcpu and components/net
This commit is contained in:
commit
e2376a3709
1414 changed files with 390370 additions and 0 deletions
13
components/libc/posix/signal/SConscript
Normal file
13
components/libc/posix/signal/SConscript
Normal file
|
@ -0,0 +1,13 @@
|
|||
# RT-Thread building script for component
|
||||
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c') + Glob('*.cpp')
|
||||
CPPPATH = [cwd]
|
||||
|
||||
group = DefineGroup('POSIX', src,
|
||||
depend = ['RT_USING_SIGNALS', 'RT_USING_PTHREADS'],
|
||||
CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
152
components/libc/posix/signal/posix_signal.c
Normal file
152
components/libc/posix/signal/posix_signal.c
Normal file
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017/10/1 Bernard The first version
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/errno.h>
|
||||
|
||||
#include "posix_signal.h"
|
||||
|
||||
#define sig_valid(sig_no) (sig_no >= 0 && sig_no < RT_SIG_MAX)
|
||||
|
||||
void (*signal(int sig, void (*func)(int))) (int)
|
||||
{
|
||||
return rt_signal_install(sig, func);
|
||||
}
|
||||
|
||||
int sigprocmask (int how, const sigset_t *set, sigset_t *oset)
|
||||
{
|
||||
rt_base_t level;
|
||||
rt_thread_t tid;
|
||||
|
||||
tid = rt_thread_self();
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
if (oset) *oset = tid->sig_mask;
|
||||
|
||||
if (set)
|
||||
{
|
||||
switch(how)
|
||||
{
|
||||
case SIG_BLOCK:
|
||||
tid->sig_mask |= *set;
|
||||
break;
|
||||
case SIG_UNBLOCK:
|
||||
tid->sig_mask &= ~*set;
|
||||
break;
|
||||
case SIG_SETMASK:
|
||||
tid->sig_mask = *set;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sigpending (sigset_t *set)
|
||||
{
|
||||
sigprocmask(SIG_SETMASK, RT_NULL, set);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sigsuspend (const sigset_t *set)
|
||||
{
|
||||
int ret = 0;
|
||||
sigset_t origin_set;
|
||||
sigset_t suspend_set;
|
||||
siginfo_t info; /* unless paremeter */
|
||||
|
||||
/* get the origin signal information */
|
||||
sigpending(&origin_set);
|
||||
|
||||
/* set the new signal information */
|
||||
sigprocmask(SIG_BLOCK, set, RT_NULL);
|
||||
sigpending(&suspend_set);
|
||||
|
||||
ret = rt_signal_wait(&suspend_set, &info, RT_WAITING_FOREVER);
|
||||
|
||||
/* restore the original sigprocmask */
|
||||
sigprocmask(SIG_UNBLOCK, (sigset_t *)0xffffUL, RT_NULL);
|
||||
sigprocmask(SIG_BLOCK, &origin_set, RT_NULL);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
|
||||
{
|
||||
rt_sighandler_t old = RT_NULL;
|
||||
|
||||
if (!sig_valid(signum)) return -RT_ERROR;
|
||||
|
||||
if (act)
|
||||
old = rt_signal_install(signum, act->sa_handler);
|
||||
else
|
||||
{
|
||||
old = rt_signal_install(signum, RT_NULL);
|
||||
rt_signal_install(signum, old);
|
||||
}
|
||||
|
||||
if (oldact)
|
||||
oldact->sa_handler = old;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout)
|
||||
{
|
||||
int ret = 0;
|
||||
int tick = RT_WAITING_FOREVER;
|
||||
|
||||
if (timeout)
|
||||
{
|
||||
tick = rt_timespec_to_tick(timeout);
|
||||
}
|
||||
|
||||
ret = rt_signal_wait(set, info, tick);
|
||||
if (ret == 0) return 0;
|
||||
|
||||
errno = ret;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int sigwait(const sigset_t *set, int *sig)
|
||||
{
|
||||
siginfo_t si;
|
||||
if (sigtimedwait(set, &si, 0) < 0)
|
||||
return -1;
|
||||
|
||||
*sig = si.si_signo;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sigwaitinfo(const sigset_t *set, siginfo_t *info)
|
||||
{
|
||||
return sigtimedwait(set, info, NULL);
|
||||
}
|
||||
|
||||
int raise(int sig)
|
||||
{
|
||||
rt_thread_kill(rt_thread_self(), sig);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <sys/types.h>
|
||||
int sigqueue (pid_t pid, int signo, const union sigval value)
|
||||
{
|
||||
/* no support, signal queue */
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
61
components/libc/posix/signal/posix_signal.h
Normal file
61
components/libc/posix/signal/posix_signal.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017/10/1 Bernard The first version
|
||||
*/
|
||||
|
||||
#ifndef POSIX_SIGNAL_H__
|
||||
#define POSIX_SIGNAL_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <sys/signal.h>
|
||||
|
||||
enum rt_signal_value{
|
||||
SIG1 = SIGHUP,
|
||||
SIG2 = SIGINT,
|
||||
SIG3 = SIGQUIT,
|
||||
SIG4 = SIGILL,
|
||||
SIG5 = SIGTRAP,
|
||||
SIG6 = SIGABRT,
|
||||
SIG7 = SIGEMT,
|
||||
SIG8 = SIGFPE,
|
||||
SIG9 = SIGKILL,
|
||||
SIG10 = SIGBUS,
|
||||
SIG11 = SIGSEGV,
|
||||
SIG12 = SIGSYS,
|
||||
SIG13 = SIGPIPE,
|
||||
SIG14 = SIGALRM,
|
||||
SIG15 = SIGTERM,
|
||||
SIG16 = SIGURG,
|
||||
SIG17 = SIGSTOP,
|
||||
SIG18 = SIGTSTP,
|
||||
SIG19 = SIGCONT,
|
||||
SIG20 = SIGCHLD,
|
||||
SIG21 = SIGTTIN,
|
||||
SIG22 = SIGTTOU,
|
||||
SIG23 = SIGPOLL,
|
||||
SIG24 = 24, // SIGXCPU,
|
||||
SIG25 = 25, // SIGXFSZ,
|
||||
SIG26 = 26, // SIGVTALRM,
|
||||
SIG27 = 27, // SIGPROF,
|
||||
SIG28 = SIGWINCH,
|
||||
SIG29 = 29, // SIGLOST,
|
||||
SIG30 = SIGUSR1,
|
||||
SIG31 = SIGUSR2,
|
||||
SIGRT_MIN = 27, // SIGRTMIN,
|
||||
SIGRT_MAX = 31, // SIGRTMAX,
|
||||
SIGMAX = NSIG,
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue