|
|
@ -1,6 +1,6 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
|
|
|
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
|
|
|
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
|
|
|
|
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
* are permitted provided that the following conditions are met:
|
|
|
|
* are permitted provided that the following conditions are met:
|
|
|
@ -53,15 +53,17 @@ int raise(int sig)
|
|
|
|
#define GETUNMASKSET(procmask, pendFlag) ((~(procmask)) & (sigset_t)(pendFlag))
|
|
|
|
#define GETUNMASKSET(procmask, pendFlag) ((~(procmask)) & (sigset_t)(pendFlag))
|
|
|
|
#define UINT64_BIT_SIZE 64
|
|
|
|
#define UINT64_BIT_SIZE 64
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int OsSigIsMember(const sigset_t *set, int signo)
|
|
|
|
int OsSigIsMember(const sigset_t *set, int signo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret = LOS_NOK;
|
|
|
|
int ret = LOS_NOK;
|
|
|
|
/* In musl, sig No bits 00000100 present sig No 3, but 1<< 3 = 00001000, so signo needs minus 1 */
|
|
|
|
/* In musl, sig No bits 00000100 present sig No 3, but 1<< 3 = 00001000, so signo needs minus 1 */
|
|
|
|
|
|
|
|
//在musl中,sig No bits 00000100表示sig No 3,但是在SIGNO2SET中 1<<3 = 00001000,因此signo需要减1
|
|
|
|
signo -= 1;
|
|
|
|
signo -= 1;
|
|
|
|
/* Verify the signal */
|
|
|
|
/* Verify the signal */
|
|
|
|
if (GOOD_SIGNO(signo)) {
|
|
|
|
if (GOOD_SIGNO(signo)) {//有效信号判断
|
|
|
|
/* Check if the signal is in the set */
|
|
|
|
/* Check if the signal is in the set */
|
|
|
|
ret = ((*set & SIGNO2SET((unsigned int)signo)) != 0);
|
|
|
|
ret = ((*set & SIGNO2SET((unsigned int)signo)) != 0);//检查信号是否还在集合中
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
@ -120,7 +122,6 @@ VOID OsClearSigInfoTmpList(sig_cb *sigcb)
|
|
|
|
(VOID)LOS_MemFree(m_aucSysMem0, tmpInfoNode);
|
|
|
|
(VOID)LOS_MemFree(m_aucSysMem0, tmpInfoNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
STATIC INLINE VOID OsSigWaitTaskWake(LosTaskCB *taskCB, INT32 signo)
|
|
|
|
STATIC INLINE VOID OsSigWaitTaskWake(LosTaskCB *taskCB, INT32 signo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sig_cb *sigcb = &taskCB->sig;
|
|
|
|
sig_cb *sigcb = &taskCB->sig;
|
|
|
@ -132,14 +133,14 @@ STATIC INLINE VOID OsSigWaitTaskWake(LosTaskCB *taskCB, INT32 signo)
|
|
|
|
OsSigEmptySet(&sigcb->sigwaitmask);
|
|
|
|
OsSigEmptySet(&sigcb->sigwaitmask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///< 唤醒被挂起的处于等待指定信号的任务
|
|
|
|
STATIC UINT32 OsPendingTaskWake(LosTaskCB *taskCB, INT32 signo)
|
|
|
|
STATIC UINT32 OsPendingTaskWake(LosTaskCB *taskCB, INT32 signo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!OsTaskIsPending(taskCB) || !OsProcessIsUserMode(OS_PCB_FROM_TCB(taskCB))) {
|
|
|
|
if (!OsTaskIsPending(taskCB) || !OsProcessIsUserMode(OS_PCB_FROM_TCB(taskCB))) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ((signo != SIGKILL) && (taskCB->waitFlag != OS_TASK_WAIT_SIGNAL)) {
|
|
|
|
if ((signo != SIGKILL) && (taskCB->waitFlag != OS_TASK_WAIT_SIGNAL)) { // @note_thinking 这个判断会不会有问题 ?
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -153,16 +154,16 @@ STATIC UINT32 OsPendingTaskWake(LosTaskCB *taskCB, INT32 signo)
|
|
|
|
OsTaskWakeClearPendMask(taskCB);
|
|
|
|
OsTaskWakeClearPendMask(taskCB);
|
|
|
|
taskCB->ops->wake(taskCB);
|
|
|
|
taskCB->ops->wake(taskCB);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case OS_TASK_WAIT_SIGNAL:
|
|
|
|
case OS_TASK_WAIT_SIGNAL://等待普通信号
|
|
|
|
OsSigWaitTaskWake(taskCB, signo);
|
|
|
|
OsSigWaitTaskWake(taskCB, signo);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case OS_TASK_WAIT_LITEIPC:
|
|
|
|
case OS_TASK_WAIT_LITEIPC://等待liteipc信号
|
|
|
|
OsTaskWakeClearPendMask(taskCB);
|
|
|
|
OsTaskWakeClearPendMask(taskCB);//重置任务的等待信息
|
|
|
|
taskCB->ops->wake(taskCB);
|
|
|
|
taskCB->ops->wake(taskCB);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case OS_TASK_WAIT_FUTEX:
|
|
|
|
case OS_TASK_WAIT_FUTEX://等待快锁信号
|
|
|
|
OsFutexNodeDeleteFromFutexHash(&taskCB->futex, TRUE, NULL, NULL);
|
|
|
|
OsFutexNodeDeleteFromFutexHash(&taskCB->futex, TRUE, NULL, NULL);//从哈希桶中删除快锁
|
|
|
|
OsTaskWakeClearPendMask(taskCB);
|
|
|
|
OsTaskWakeClearPendMask(taskCB);//重置任务的等待信息
|
|
|
|
taskCB->ops->wake(taskCB);
|
|
|
|
taskCB->ops->wake(taskCB);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
@ -171,7 +172,7 @@ STATIC UINT32 OsPendingTaskWake(LosTaskCB *taskCB, INT32 signo)
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///给任务(线程)发送一个信号
|
|
|
|
int OsTcbDispatch(LosTaskCB *stcb, siginfo_t *info)
|
|
|
|
int OsTcbDispatch(LosTaskCB *stcb, siginfo_t *info)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool masked = FALSE;
|
|
|
|
bool masked = FALSE;
|
|
|
@ -179,19 +180,19 @@ int OsTcbDispatch(LosTaskCB *stcb, siginfo_t *info)
|
|
|
|
|
|
|
|
|
|
|
|
OS_RETURN_IF_NULL(sigcb);
|
|
|
|
OS_RETURN_IF_NULL(sigcb);
|
|
|
|
/* If signo is 0, not send signal, just check process or pthread exist */
|
|
|
|
/* If signo is 0, not send signal, just check process or pthread exist */
|
|
|
|
if (info->si_signo == 0) {
|
|
|
|
if (info->si_signo == 0) {//如果信号为0,则不发送信号,只是作为检查进程和线程是否还存在.
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
masked = (bool)OsSigIsMember(&sigcb->sigprocmask, info->si_signo);
|
|
|
|
masked = (bool)OsSigIsMember(&sigcb->sigprocmask, info->si_signo);//@note_thinking 这里还有 masked= -1的情况要处理!!!
|
|
|
|
if (masked) {
|
|
|
|
if (masked) {//如果信号被屏蔽了,要看等待信号集,sigwaitmask
|
|
|
|
/* If signal is in wait list and mask list, need unblock it */
|
|
|
|
/* If signal is in wait list and mask list, need unblock it */ //如果信号在等待列表和掩码列表中,需要解除阻止
|
|
|
|
if (LOS_ListEmpty(&sigcb->waitList) ||
|
|
|
|
if (LOS_ListEmpty(&sigcb->waitList) ||
|
|
|
|
(!LOS_ListEmpty(&sigcb->waitList) && !OsSigIsMember(&sigcb->sigwaitmask, info->si_signo))) {
|
|
|
|
(!LOS_ListEmpty(&sigcb->waitList) && !OsSigIsMember(&sigcb->sigwaitmask, info->si_signo))) {
|
|
|
|
OsSigAddSet(&sigcb->sigPendFlag, info->si_signo);
|
|
|
|
OsSigAddSet(&sigcb->sigPendFlag, info->si_signo);//将信号加入挂起/待办集
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {//信号没有被屏蔽的处理
|
|
|
|
/* unmasked signal actions */
|
|
|
|
/* unmasked signal actions */
|
|
|
|
OsSigAddSet(&sigcb->sigFlag, info->si_signo);
|
|
|
|
OsSigAddSet(&sigcb->sigFlag, info->si_signo);//不屏蔽的信号集
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (OsAddSigInfoToTmpList(sigcb, info) == LOS_NOK) {
|
|
|
|
if (OsAddSigInfoToTmpList(sigcb, info) == LOS_NOK) {
|
|
|
@ -206,14 +207,15 @@ void OsSigMaskSwitch(LosTaskCB * const rtcb, sigset_t set)
|
|
|
|
sigset_t unmaskset;
|
|
|
|
sigset_t unmaskset;
|
|
|
|
|
|
|
|
|
|
|
|
rtcb->sig.sigprocmask = set;
|
|
|
|
rtcb->sig.sigprocmask = set;
|
|
|
|
unmaskset = GETUNMASKSET(rtcb->sig.sigprocmask, rtcb->sig.sigPendFlag);
|
|
|
|
unmaskset = GETUNMASKSET(rtcb->sig.sigprocmask, rtcb->sig.sigPendFlag);//过滤出没有被屏蔽的信号集
|
|
|
|
if (unmaskset != NULL_SIGNAL_SET) {
|
|
|
|
if (unmaskset != NULL_SIGNAL_SET) {
|
|
|
|
/* pendlist do */
|
|
|
|
/* pendlist do */
|
|
|
|
rtcb->sig.sigFlag |= unmaskset;
|
|
|
|
rtcb->sig.sigFlag |= unmaskset; //加入不屏蔽信号集
|
|
|
|
rtcb->sig.sigPendFlag ^= unmaskset;
|
|
|
|
rtcb->sig.sigPendFlag ^= unmaskset;//从挂起/待办集中去掉unmaskset
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int OsSigprocMask(int how, const sigset_t_l *setl, sigset_t_l *oldsetl)
|
|
|
|
int OsSigprocMask(int how, const sigset_t_l *setl, sigset_t_l *oldsetl)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LosTaskCB *spcb = NULL;
|
|
|
|
LosTaskCB *spcb = NULL;
|
|
|
@ -223,11 +225,11 @@ int OsSigprocMask(int how, const sigset_t_l *setl, sigset_t_l *oldsetl)
|
|
|
|
|
|
|
|
|
|
|
|
SCHEDULER_LOCK(intSave);
|
|
|
|
SCHEDULER_LOCK(intSave);
|
|
|
|
spcb = OsCurrTaskGet();
|
|
|
|
spcb = OsCurrTaskGet();
|
|
|
|
/* If requested, copy the old mask to user. */
|
|
|
|
/* If requested, copy the old mask to user. | 如果需要,请将旧掩码复制给用户*/
|
|
|
|
if (oldsetl != NULL) {
|
|
|
|
if (oldsetl != NULL) {
|
|
|
|
*(sigset_t *)oldsetl = spcb->sig.sigprocmask;
|
|
|
|
*(sigset_t *)oldsetl = spcb->sig.sigprocmask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* If requested, modify the current signal mask. */
|
|
|
|
/* If requested, modify the current signal mask. | 如有要求,修改当前信号屏蔽*/
|
|
|
|
if (setl != NULL) {
|
|
|
|
if (setl != NULL) {
|
|
|
|
set = *(sigset_t *)setl;
|
|
|
|
set = *(sigset_t *)setl;
|
|
|
|
/* Okay, determine what we are supposed to do */
|
|
|
|
/* Okay, determine what we are supposed to do */
|
|
|
@ -236,46 +238,46 @@ int OsSigprocMask(int how, const sigset_t_l *setl, sigset_t_l *oldsetl)
|
|
|
|
* set pointed to by set as the new sigprocmask.
|
|
|
|
* set pointed to by set as the new sigprocmask.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
case SIG_BLOCK:
|
|
|
|
case SIG_BLOCK:
|
|
|
|
spcb->sig.sigprocmask |= set;
|
|
|
|
spcb->sig.sigprocmask |= set;//增加信号屏蔽位
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
/* Set the intersection of the current set and the
|
|
|
|
/* Set the intersection of the current set and the
|
|
|
|
* signal set pointed to by set as the new sigprocmask.
|
|
|
|
* signal set pointed to by set as the new sigprocmask.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
case SIG_UNBLOCK:
|
|
|
|
case SIG_UNBLOCK:
|
|
|
|
spcb->sig.sigprocmask &= ~(set);
|
|
|
|
spcb->sig.sigprocmask &= ~(set);//解除信号屏蔽位
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
/* Set the signal set pointed to by set as the new sigprocmask. */
|
|
|
|
/* Set the signal set pointed to by set as the new sigprocmask. */
|
|
|
|
case SIG_SETMASK:
|
|
|
|
case SIG_SETMASK:
|
|
|
|
spcb->sig.sigprocmask = set;
|
|
|
|
spcb->sig.sigprocmask = set;//设置一个新的屏蔽掩码
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* If pending mask not in sigmask, need set sigflag. */
|
|
|
|
/* If pending mask not in sigmask, need set sigflag. */
|
|
|
|
OsSigMaskSwitch(spcb, spcb->sig.sigprocmask);
|
|
|
|
OsSigMaskSwitch(spcb, spcb->sig.sigprocmask);//更新与屏蔽信号相关的变量
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///让进程的每一个task执行参数函数
|
|
|
|
int OsSigProcessForeachChild(LosProcessCB *spcb, ForEachTaskCB handler, void *arg)
|
|
|
|
int OsSigProcessForeachChild(LosProcessCB *spcb, ForEachTaskCB handler, void *arg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
|
|
/* Visit the main thread last (if present) */
|
|
|
|
/* Visit the main thread last (if present) */
|
|
|
|
LosTaskCB *taskCB = NULL;
|
|
|
|
LosTaskCB *taskCB = NULL;//遍历进程的 threadList 链表,里面存放的都是task节点
|
|
|
|
LOS_DL_LIST_FOR_EACH_ENTRY(taskCB, &(spcb->threadSiblingList), LosTaskCB, threadList) {
|
|
|
|
LOS_DL_LIST_FOR_EACH_ENTRY(taskCB, &(spcb->threadSiblingList), LosTaskCB, threadList) {//遍历进程的任务列表
|
|
|
|
ret = handler(taskCB, arg);
|
|
|
|
ret = handler(taskCB, arg);//回调参数函数
|
|
|
|
OS_RETURN_IF(ret != 0, ret);
|
|
|
|
OS_RETURN_IF(ret != 0, ret);//这个宏的意思就是只有ret = 0时,啥也不处理.其余就返回 ret
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return LOS_OK;
|
|
|
|
return LOS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///信号处理函数,这里就是上面的 handler = SigProcessSignalHandler,见于 OsSigProcessSend
|
|
|
|
static int SigProcessSignalHandler(LosTaskCB *tcb, void *arg)
|
|
|
|
static int SigProcessSignalHandler(LosTaskCB *tcb, void *arg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
struct ProcessSignalInfo *info = (struct ProcessSignalInfo *)arg;
|
|
|
|
struct ProcessSignalInfo *info = (struct ProcessSignalInfo *)arg;//先把参数解出来
|
|
|
|
int ret;
|
|
|
|
int ret;
|
|
|
|
int isMember;
|
|
|
|
int isMember;
|
|
|
|
|
|
|
|
|
|
|
@ -283,128 +285,130 @@ static int SigProcessSignalHandler(LosTaskCB *tcb, void *arg)
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* If the default tcb is not set, then set this one as default. */
|
|
|
|
/* If the default tcb is not setted, then set this one as default. */
|
|
|
|
if (!info->defaultTcb) {
|
|
|
|
if (!info->defaultTcb) {//如果没有默认发送方的任务,即默认参数任务.
|
|
|
|
info->defaultTcb = tcb;
|
|
|
|
info->defaultTcb = tcb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
isMember = OsSigIsMember(&tcb->sig.sigwaitmask, info->sigInfo->si_signo);
|
|
|
|
isMember = OsSigIsMember(&tcb->sig.sigwaitmask, info->sigInfo->si_signo);//任务是否在等待这个信号
|
|
|
|
if (isMember && (!info->awakenedTcb)) {
|
|
|
|
if (isMember && (!info->awakenedTcb)) {//是在等待,并尚未向该任务时发送信号时
|
|
|
|
/* This means the task is waiting for this signal. Stop looking for it and use this tcb.
|
|
|
|
/* This means the task is waiting for this signal. Stop looking for it and use this tcb.
|
|
|
|
* The requirement is: if more than one task in this task group is waiting for the signal,
|
|
|
|
* The requirement is: if more than one task in this task group is waiting for the signal,
|
|
|
|
* then only one indeterminate task in the group will receive the signal.
|
|
|
|
* then only one indeterminate task in the group will receive the signal.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
ret = OsTcbDispatch(tcb, info->sigInfo);
|
|
|
|
ret = OsTcbDispatch(tcb, info->sigInfo);//发送信号,注意这是给其他任务发送信号,tcb不是当前任务
|
|
|
|
OS_RETURN_IF(ret < 0, ret);
|
|
|
|
OS_RETURN_IF(ret < 0, ret);//这种写法很有意思
|
|
|
|
|
|
|
|
|
|
|
|
/* set this tcb as awakenedTcb */
|
|
|
|
/* set this tcb as awakenedTcb */
|
|
|
|
info->awakenedTcb = tcb;
|
|
|
|
info->awakenedTcb = tcb;
|
|
|
|
OS_RETURN_IF(info->receivedTcb != NULL, SIG_STOP_VISIT); /* Stop search */
|
|
|
|
OS_RETURN_IF(info->receivedTcb != NULL, SIG_STOP_VISIT); /* Stop search */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Is this signal unblocked on this thread? */
|
|
|
|
/* Is this signal unblocked on this thread? */
|
|
|
|
isMember = OsSigIsMember(&tcb->sig.sigprocmask, info->sigInfo->si_signo);
|
|
|
|
isMember = OsSigIsMember(&tcb->sig.sigprocmask, info->sigInfo->si_signo);//任务是否屏蔽了这个信号
|
|
|
|
if ((!isMember) && (!info->receivedTcb) && (tcb != info->awakenedTcb)) {
|
|
|
|
if ((!isMember) && (!info->receivedTcb) && (tcb != info->awakenedTcb)) {//没有屏蔽,有唤醒任务没有接收任务.
|
|
|
|
/* if unblockedTcb of this signal is not set, then set it. */
|
|
|
|
/* if unblockedTcb of this signal is not setted, then set it. */
|
|
|
|
if (!info->unblockedTcb) {
|
|
|
|
if (!info->unblockedTcb) {
|
|
|
|
info->unblockedTcb = tcb;
|
|
|
|
info->unblockedTcb = tcb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ret = OsTcbDispatch(tcb, info->sigInfo);
|
|
|
|
ret = OsTcbDispatch(tcb, info->sigInfo);//向任务发送信号
|
|
|
|
OS_RETURN_IF(ret < 0, ret);
|
|
|
|
OS_RETURN_IF(ret < 0, ret);
|
|
|
|
/* set this tcb as receivedTcb */
|
|
|
|
/* set this tcb as receivedTcb */
|
|
|
|
info->receivedTcb = tcb;
|
|
|
|
info->receivedTcb = tcb;//设置这个任务为接收任务
|
|
|
|
OS_RETURN_IF(info->awakenedTcb != NULL, SIG_STOP_VISIT); /* Stop search */
|
|
|
|
OS_RETURN_IF(info->awakenedTcb != NULL, SIG_STOP_VISIT); /* Stop search */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0; /* Keep searching */
|
|
|
|
return 0; /* Keep searching */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///进程收到 SIGKILL 信号后,通知任务tcb处理.
|
|
|
|
static int SigProcessKillSigHandler(LosTaskCB *tcb, void *arg)
|
|
|
|
static int SigProcessKillSigHandler(LosTaskCB *tcb, void *arg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
struct ProcessSignalInfo *info = (struct ProcessSignalInfo *)arg;
|
|
|
|
struct ProcessSignalInfo *info = (struct ProcessSignalInfo *)arg;//转参
|
|
|
|
|
|
|
|
|
|
|
|
return OsPendingTaskWake(tcb, info->sigInfo->si_signo);
|
|
|
|
return OsPendingTaskWake(tcb, info->sigInfo->si_signo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//处理信号发送
|
|
|
|
static void SigProcessLoadTcb(struct ProcessSignalInfo *info, siginfo_t *sigInfo)
|
|
|
|
static void SigProcessLoadTcb(struct ProcessSignalInfo *info, siginfo_t *sigInfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LosTaskCB *tcb = NULL;
|
|
|
|
LosTaskCB *tcb = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (info->awakenedTcb == NULL && info->receivedTcb == NULL) {
|
|
|
|
if (info->awakenedTcb == NULL && info->receivedTcb == NULL) {//信号即没有指定接收task 也没有指定被唤醒task
|
|
|
|
if (info->unblockedTcb) {
|
|
|
|
if (info->unblockedTcb) {//如果进程信号信息体中有阻塞task
|
|
|
|
tcb = info->unblockedTcb;
|
|
|
|
tcb = info->unblockedTcb;//
|
|
|
|
} else if (info->defaultTcb) {
|
|
|
|
} else if (info->defaultTcb) {//如果有默认的发送方task
|
|
|
|
tcb = info->defaultTcb;
|
|
|
|
tcb = info->defaultTcb;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Deliver the signal to the selected task */
|
|
|
|
/* Deliver the signal to the selected task */
|
|
|
|
(void)OsTcbDispatch(tcb, sigInfo);
|
|
|
|
(void)OsTcbDispatch(tcb, sigInfo);//向所选任务发送信号
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///给参数进程发送参数信号
|
|
|
|
int OsSigProcessSend(LosProcessCB *spcb, siginfo_t *sigInfo)
|
|
|
|
int OsSigProcessSend(LosProcessCB *spcb, siginfo_t *sigInfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int ret;
|
|
|
|
struct ProcessSignalInfo info = {
|
|
|
|
struct ProcessSignalInfo info = {
|
|
|
|
.sigInfo = sigInfo,
|
|
|
|
.sigInfo = sigInfo, //信号内容
|
|
|
|
.defaultTcb = NULL,
|
|
|
|
.defaultTcb = NULL, //以下四个值将在OsSigProcessForeachChild中根据条件完善
|
|
|
|
.unblockedTcb = NULL,
|
|
|
|
.unblockedTcb = NULL,
|
|
|
|
.awakenedTcb = NULL,
|
|
|
|
.awakenedTcb = NULL,
|
|
|
|
.receivedTcb = NULL
|
|
|
|
.receivedTcb = NULL
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
//总之是要从进程中找个至少一个任务来接受这个信号,优先级
|
|
|
|
|
|
|
|
//awakenedTcb > receivedTcb > unblockedTcb > defaultTcb
|
|
|
|
if (info.sigInfo == NULL){
|
|
|
|
if (info.sigInfo == NULL){
|
|
|
|
return -EFAULT;
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* visit all taskcb and dispatch signal */ //访问所有任务和分发信号
|
|
|
|
/* visit all taskcb and dispatch signal */
|
|
|
|
if (info.sigInfo->si_signo == SIGKILL) {//需要干掉进程时 SIGKILL = 9, #linux kill 9 14
|
|
|
|
if (info.sigInfo->si_signo == SIGKILL) {
|
|
|
|
OsSigAddSet(&spcb->sigShare, info.sigInfo->si_signo);//信号集中增加信号
|
|
|
|
OsSigAddSet(&spcb->sigShare, info.sigInfo->si_signo);
|
|
|
|
|
|
|
|
(void)OsSigProcessForeachChild(spcb, SigProcessKillSigHandler, &info);
|
|
|
|
(void)OsSigProcessForeachChild(spcb, SigProcessKillSigHandler, &info);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ret = OsSigProcessForeachChild(spcb, SigProcessSignalHandler, &info);
|
|
|
|
ret = OsSigProcessForeachChild(spcb, SigProcessSignalHandler, &info);//进程通知所有task处理信号
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret < 0) {
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SigProcessLoadTcb(&info, sigInfo);
|
|
|
|
SigProcessLoadTcb(&info, sigInfo);//确保能给一个任务发送信号
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///信号集全部清0
|
|
|
|
int OsSigEmptySet(sigset_t *set)
|
|
|
|
int OsSigEmptySet(sigset_t *set)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
*set = NULL_SIGNAL_SET;
|
|
|
|
*set = NULL_SIGNAL_SET;
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Privilege process can't send to kernel and privilege process */
|
|
|
|
/* Privilege process can't send to kernel and privilege process */ //内核进程组和用户特权进程组无法发送
|
|
|
|
static int OsSignalPermissionToCheck(const LosProcessCB *spcb)
|
|
|
|
static int OsSignalPermissionToCheck(const LosProcessCB *spcb)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
UINTPTR gid = (UINTPTR)OS_GET_PGROUP_LEADER(spcb->pgroup);
|
|
|
|
UINTPTR gid = (UINTPTR)OS_GET_PGROUP_LEADER(spcb->pgroup);
|
|
|
|
if (gid == OS_KERNEL_PROCESS_GROUP) {
|
|
|
|
|
|
|
|
|
|
|
|
if (gid == OS_KERNEL_PROCESS_GROUP) {//内核进程组
|
|
|
|
return -EPERM;
|
|
|
|
return -EPERM;
|
|
|
|
} else if (gid == OS_USER_PRIVILEGE_PROCESS_GROUP) {
|
|
|
|
} else if (gid == OS_USER_PRIVILEGE_PROCESS_GROUP) {//用户特权进程组
|
|
|
|
return -EPERM;
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///信号分发,发送信号权限/进程组过滤.
|
|
|
|
STATIC int SendSigPermissionCheck(LosProcessCB *spcb, int permission)
|
|
|
|
STATIC int SendSigPermissionCheck(LosProcessCB *spcb, int permission)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (spcb == NULL) {
|
|
|
|
if (spcb == NULL) {
|
|
|
|
return -ESRCH;
|
|
|
|
return -ESRCH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (OsProcessIsUnused(spcb)) {
|
|
|
|
if (OsProcessIsUnused(spcb)) {//进程是否还在使用,不一定是当前进程但必须是个有效进程
|
|
|
|
return -ESRCH;
|
|
|
|
return -ESRCH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef LOSCFG_SECURITY_CAPABILITY
|
|
|
|
#ifdef LOSCFG_SECURITY_CAPABILITY //启用能力安全模式
|
|
|
|
LosProcessCB *current = OsCurrProcessGet();
|
|
|
|
LosProcessCB *current = OsCurrProcessGet();//获取当前进程,检查当前进程是否有发送信号的权限.
|
|
|
|
/* Kernel process always has kill permission and user process should check permission */
|
|
|
|
/* Kernel process always has kill permission and user process should check permission *///内核进程总是有kill权限,用户进程需要检查权限
|
|
|
|
if (OsProcessIsUserMode(current) && !(current->processStatus & OS_PROCESS_FLAG_EXIT)) {
|
|
|
|
if (OsProcessIsUserMode(current) && !(current->processStatus & OS_PROCESS_FLAG_EXIT)) {//用户进程检查能力范围
|
|
|
|
if ((current != spcb) && (!IsCapPermit(CAP_KILL)) && (current->user->userID != spcb->user->userID)) {
|
|
|
|
if ((current != spcb) && (!IsCapPermit(CAP_KILL)) && (current->user->userID != spcb->user->userID)) {
|
|
|
|
return -EPERM;
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -437,7 +441,7 @@ int OsSendSigToProcess(LosProcessCB *spcb, int sig, int permission)
|
|
|
|
info.si_code = SI_USER;
|
|
|
|
info.si_code = SI_USER;
|
|
|
|
info.si_value.sival_ptr = NULL;
|
|
|
|
info.si_value.sival_ptr = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
return OsSigProcessSend(spcb, &info);
|
|
|
|
return OsSigProcessSend(spcb, &info);//给参数进程发送信号
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int OsDispatch(pid_t pid, siginfo_t *info, int permission)
|
|
|
|
int OsDispatch(pid_t pid, siginfo_t *info, int permission)
|
|
|
@ -470,14 +474,14 @@ int OsKill(pid_t pid, int sig, int permission)
|
|
|
|
return -EINVAL;
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Create the siginfo structure */
|
|
|
|
/* Create the siginfo structure */ //创建信号结构体
|
|
|
|
info.si_signo = sig;
|
|
|
|
info.si_signo = sig; //信号编号
|
|
|
|
info.si_code = SI_USER;
|
|
|
|
info.si_code = SI_USER; //来自用户进程信号
|
|
|
|
info.si_value.sival_ptr = NULL;
|
|
|
|
info.si_value.sival_ptr = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (pid > 0) {
|
|
|
|
if (pid > 0) {
|
|
|
|
/* Send the signal to the specify process */
|
|
|
|
/* Send the signal to the specify process */
|
|
|
|
ret = OsDispatch(pid, &info, permission);
|
|
|
|
ret = OsDispatch(pid, &info, permission);//发送信号
|
|
|
|
} else if (pid == -1) {
|
|
|
|
} else if (pid == -1) {
|
|
|
|
/* Send SIG to all processes */
|
|
|
|
/* Send SIG to all processes */
|
|
|
|
ret = OsSendSignalToAllProcess(&info, permission);
|
|
|
|
ret = OsSendSignalToAllProcess(&info, permission);
|
|
|
@ -489,18 +493,17 @@ int OsKill(pid_t pid, int sig, int permission)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///给发送信号过程加锁
|
|
|
|
int OsKillLock(pid_t pid, int sig)
|
|
|
|
int OsKillLock(pid_t pid, int sig)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int ret;
|
|
|
|
unsigned int intSave;
|
|
|
|
unsigned int intSave;
|
|
|
|
|
|
|
|
|
|
|
|
SCHEDULER_LOCK(intSave);
|
|
|
|
SCHEDULER_LOCK(intSave);
|
|
|
|
ret = OsKill(pid, sig, OS_USER_KILL_PERMISSION);
|
|
|
|
ret = OsKill(pid, sig, OS_USER_KILL_PERMISSION);//用户权限向进程发送信号
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INT32 OsTaskKillUnsafe(UINT32 taskID, INT32 signo)
|
|
|
|
INT32 OsTaskKillUnsafe(UINT32 taskID, INT32 signo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
siginfo_t info;
|
|
|
|
siginfo_t info;
|
|
|
@ -519,7 +522,7 @@ INT32 OsTaskKillUnsafe(UINT32 taskID, INT32 signo)
|
|
|
|
* dispatch rules. */
|
|
|
|
* dispatch rules. */
|
|
|
|
return OsTcbDispatch(taskCB, &info);
|
|
|
|
return OsTcbDispatch(taskCB, &info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///发送信号
|
|
|
|
int OsPthreadKill(UINT32 tid, int signo)
|
|
|
|
int OsPthreadKill(UINT32 tid, int signo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int ret;
|
|
|
@ -537,7 +540,7 @@ int OsPthreadKill(UINT32 tid, int signo)
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///向信号集中加入signo信号
|
|
|
|
int OsSigAddSet(sigset_t *set, int signo)
|
|
|
|
int OsSigAddSet(sigset_t *set, int signo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* Verify the signal */
|
|
|
|
/* Verify the signal */
|
|
|
@ -545,13 +548,13 @@ int OsSigAddSet(sigset_t *set, int signo)
|
|
|
|
return -EINVAL;
|
|
|
|
return -EINVAL;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
/* In musl, sig No bits 00000100 present sig No 3, but 1<< 3 = 00001000, so signo needs minus 1 */
|
|
|
|
/* In musl, sig No bits 00000100 present sig No 3, but 1<< 3 = 00001000, so signo needs minus 1 */
|
|
|
|
signo -= 1;
|
|
|
|
signo -= 1;// 信号范围是 [1 ~ 64 ],而保存变量位的范围是[0 ~ 63]
|
|
|
|
/* Add the signal to the set */
|
|
|
|
/* Add the signal to the set */
|
|
|
|
*set |= SIGNO2SET((unsigned int)signo);
|
|
|
|
*set |= SIGNO2SET((unsigned int)signo);//填充信号集
|
|
|
|
return LOS_OK;
|
|
|
|
return LOS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///获取阻塞当前任务的信号集
|
|
|
|
int OsSigPending(sigset_t *set)
|
|
|
|
int OsSigPending(sigset_t *set)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LosTaskCB *tcb = NULL;
|
|
|
|
LosTaskCB *tcb = NULL;
|
|
|
@ -563,7 +566,7 @@ int OsSigPending(sigset_t *set)
|
|
|
|
|
|
|
|
|
|
|
|
SCHEDULER_LOCK(intSave);
|
|
|
|
SCHEDULER_LOCK(intSave);
|
|
|
|
tcb = OsCurrTaskGet();
|
|
|
|
tcb = OsCurrTaskGet();
|
|
|
|
*set = tcb->sig.sigPendFlag;
|
|
|
|
*set = tcb->sig.sigPendFlag;//被阻塞的信号集
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
return LOS_OK;
|
|
|
|
return LOS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -578,7 +581,7 @@ STATIC int FindFirstSetedBit(UINT64 n)
|
|
|
|
for (count = 0; (count < UINT64_BIT_SIZE) && (n ^ 1ULL); n >>= 1, count++) {}
|
|
|
|
for (count = 0; (count < UINT64_BIT_SIZE) && (n ^ 1ULL); n >>= 1, count++) {}
|
|
|
|
return (count < UINT64_BIT_SIZE) ? count : (-1);
|
|
|
|
return (count < UINT64_BIT_SIZE) ? count : (-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///等待信号时间
|
|
|
|
int OsSigTimedWaitNoLock(sigset_t *set, siginfo_t *info, unsigned int timeout)
|
|
|
|
int OsSigTimedWaitNoLock(sigset_t *set, siginfo_t *info, unsigned int timeout)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LosTaskCB *task = NULL;
|
|
|
|
LosTaskCB *task = NULL;
|
|
|
@ -589,19 +592,19 @@ int OsSigTimedWaitNoLock(sigset_t *set, siginfo_t *info, unsigned int timeout)
|
|
|
|
sigcb = &task->sig;
|
|
|
|
sigcb = &task->sig;
|
|
|
|
|
|
|
|
|
|
|
|
if (sigcb->waitList.pstNext == NULL) {
|
|
|
|
if (sigcb->waitList.pstNext == NULL) {
|
|
|
|
LOS_ListInit(&sigcb->waitList);
|
|
|
|
LOS_ListInit(&sigcb->waitList);//初始化信号等待链表
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* If pendingflag & set > 0, should clear pending flag */
|
|
|
|
/* If pendingflag & set > 0, shound clear pending flag */
|
|
|
|
sigset_t clear = sigcb->sigPendFlag & *set;
|
|
|
|
sigset_t clear = sigcb->sigPendFlag & *set;
|
|
|
|
if (clear) {
|
|
|
|
if (clear) {
|
|
|
|
sigcb->sigPendFlag ^= clear;
|
|
|
|
sigcb->sigPendFlag ^= clear;
|
|
|
|
ret = FindFirstSetedBit((UINT64)clear) + 1;
|
|
|
|
ret = FindFirstSetedBit((UINT64)clear) + 1;
|
|
|
|
OsMoveTmpInfoToUnbInfo(sigcb, ret);
|
|
|
|
OsMoveTmpInfoToUnbInfo(sigcb, ret);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
OsSigAddSet(set, SIGKILL);
|
|
|
|
OsSigAddSet(set, SIGKILL);//kill 9 14 必须要处理
|
|
|
|
OsSigAddSet(set, SIGSTOP);
|
|
|
|
OsSigAddSet(set, SIGSTOP);//终止进程的信号也必须处理
|
|
|
|
|
|
|
|
|
|
|
|
sigcb->sigwaitmask |= *set;
|
|
|
|
sigcb->sigwaitmask |= *set;//按位加到等待集上,也就是说sigwaitmask的信号来了都是要处理的.
|
|
|
|
OsTaskWaitSetPendMask(OS_TASK_WAIT_SIGNAL, sigcb->sigwaitmask, timeout);
|
|
|
|
OsTaskWaitSetPendMask(OS_TASK_WAIT_SIGNAL, sigcb->sigwaitmask, timeout);
|
|
|
|
ret = task->ops->wait(task, &sigcb->waitList, timeout);
|
|
|
|
ret = task->ops->wait(task, &sigcb->waitList, timeout);
|
|
|
|
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
|
|
|
|
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
|
|
|
@ -614,7 +617,7 @@ int OsSigTimedWaitNoLock(sigset_t *set, siginfo_t *info, unsigned int timeout)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///让当前任务等待的信号
|
|
|
|
int OsSigTimedWait(sigset_t *set, siginfo_t *info, unsigned int timeout)
|
|
|
|
int OsSigTimedWait(sigset_t *set, siginfo_t *info, unsigned int timeout)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int ret;
|
|
|
@ -622,12 +625,12 @@ int OsSigTimedWait(sigset_t *set, siginfo_t *info, unsigned int timeout)
|
|
|
|
|
|
|
|
|
|
|
|
SCHEDULER_LOCK(intSave);
|
|
|
|
SCHEDULER_LOCK(intSave);
|
|
|
|
|
|
|
|
|
|
|
|
ret = OsSigTimedWaitNoLock(set, info, timeout);
|
|
|
|
ret = OsSigTimedWaitNoLock(set, info, timeout);//以不加锁的方式等待
|
|
|
|
|
|
|
|
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///通过信号挂起当前任务
|
|
|
|
int OsPause(void)
|
|
|
|
int OsPause(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LosTaskCB *spcb = NULL;
|
|
|
|
LosTaskCB *spcb = NULL;
|
|
|
@ -637,7 +640,7 @@ int OsPause(void)
|
|
|
|
oldSigprocmask = spcb->sig.sigprocmask;
|
|
|
|
oldSigprocmask = spcb->sig.sigprocmask;
|
|
|
|
return OsSigSuspend(&oldSigprocmask);
|
|
|
|
return OsSigSuspend(&oldSigprocmask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///用参数set代替进程的原有掩码,并暂停进程执行,直到收到信号再恢复原有掩码并继续执行进程。
|
|
|
|
int OsSigSuspend(const sigset_t *set)
|
|
|
|
int OsSigSuspend(const sigset_t *set)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
unsigned int intSave;
|
|
|
|
unsigned int intSave;
|
|
|
@ -677,6 +680,7 @@ int OsSigSuspend(const sigset_t *set)
|
|
|
|
return -EINTR;
|
|
|
|
return -EINTR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int OsSigAction(int sig, const sigaction_t *act, sigaction_t *oact)
|
|
|
|
int OsSigAction(int sig, const sigaction_t *act, sigaction_t *oact)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
UINTPTR addr;
|
|
|
|
UINTPTR addr;
|
|
|
@ -685,14 +689,17 @@ int OsSigAction(int sig, const sigaction_t *act, sigaction_t *oact)
|
|
|
|
if (!GOOD_SIGNO(sig) || sig < 1 || act == NULL) {
|
|
|
|
if (!GOOD_SIGNO(sig) || sig < 1 || act == NULL) {
|
|
|
|
return -EINVAL;
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//将数据从用户空间拷贝到内核空间
|
|
|
|
if (LOS_ArchCopyFromUser(&action, act, sizeof(sigaction_t)) != LOS_OK) {
|
|
|
|
if (LOS_ArchCopyFromUser(&action, act, sizeof(sigaction_t)) != LOS_OK) {
|
|
|
|
return -EFAULT;
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (sig == SIGSYS) {
|
|
|
|
if (sig == SIGSYS) {//鸿蒙此处通过错误的系统调用 来安装信号处理函数,有点巧妙.
|
|
|
|
addr = OsGetSigHandler();
|
|
|
|
addr = OsGetSigHandler();//是否已存在信号处理函数
|
|
|
|
if (addr == 0) {
|
|
|
|
if (addr == 0) {//进程没有设置信号处理函数时
|
|
|
|
OsSetSigHandler((unsigned long)(UINTPTR)action.sa_handler);
|
|
|
|
OsSetSigHandler((unsigned long)(UINTPTR)action.sa_handler);//设置进程信号处理函数
|
|
|
|
|
|
|
|
//void (*sa_handler)(int); //信号处理函数——普通版
|
|
|
|
|
|
|
|
//void (*sa_sigaction)(int, siginfo_t *, void *);//信号处理函数——高级版
|
|
|
|
return LOS_OK;
|
|
|
|
return LOS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
return -EINVAL;
|
|
|
@ -717,11 +724,11 @@ VOID OsSigIntUnlock(VOID)
|
|
|
|
(VOID)LOS_AtomicSub((Atomic *)&sigcb->sigIntLock, 1);
|
|
|
|
(VOID)LOS_AtomicSub((Atomic *)&sigcb->sigIntLock, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VOID *OsSaveSignalContext(VOID *sp, VOID *newSp)
|
|
|
|
VOID *OsSaveSignalContext(VOID *sp, VOID *newSp)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
UINTPTR sigHandler;
|
|
|
|
UINTPTR sigHandler;
|
|
|
|
UINT32 intSave;
|
|
|
|
UINT32 intSave;
|
|
|
|
|
|
|
|
|
|
|
|
LosTaskCB *task = OsCurrTaskGet();
|
|
|
|
LosTaskCB *task = OsCurrTaskGet();
|
|
|
|
LosProcessCB *process = OsCurrProcessGet();
|
|
|
|
LosProcessCB *process = OsCurrProcessGet();
|
|
|
|
sig_cb *sigcb = &task->sig;
|
|
|
|
sig_cb *sigcb = &task->sig;
|
|
|
@ -754,7 +761,7 @@ VOID *OsSaveSignalContext(VOID *sp, VOID *newSp)
|
|
|
|
OsProcessExitCodeSignalSet(process, signo);
|
|
|
|
OsProcessExitCodeSignalSet(process, signo);
|
|
|
|
sigcb->sigContext = sp;
|
|
|
|
sigcb->sigContext = sp;
|
|
|
|
|
|
|
|
|
|
|
|
OsInitSignalContext(sp, newSp, sigHandler, signo, sigVal);
|
|
|
|
OsInitSignalContext(sp, newSp, sigHandler, signo, sigVal);//初始化信号上下文
|
|
|
|
|
|
|
|
|
|
|
|
/* sig No bits 00000100 present sig No 3, but 1<< 3 = 00001000, so signo needs minus 1 */
|
|
|
|
/* sig No bits 00000100 present sig No 3, but 1<< 3 = 00001000, so signo needs minus 1 */
|
|
|
|
sigcb->sigFlag ^= 1ULL << (signo - 1);
|
|
|
|
sigcb->sigFlag ^= 1ULL << (signo - 1);
|
|
|
@ -767,6 +774,7 @@ VOID *OsSaveSignalContext(VOID *sp, VOID *newSp)
|
|
|
|
return sp;
|
|
|
|
return sp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VOID *OsRestorSignalContext(VOID *sp)
|
|
|
|
VOID *OsRestorSignalContext(VOID *sp)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
UINT32 intSave;
|
|
|
|
UINT32 intSave;
|
|
|
@ -785,8 +793,8 @@ VOID *OsRestorSignalContext(VOID *sp)
|
|
|
|
VOID *saveContext = sigcb->sigContext;
|
|
|
|
VOID *saveContext = sigcb->sigContext;
|
|
|
|
sigcb->sigContext = NULL;
|
|
|
|
sigcb->sigContext = NULL;
|
|
|
|
sigcb->count--;
|
|
|
|
sigcb->count--;
|
|
|
|
process->sigShare = 0;
|
|
|
|
process->sigShare = 0; //回到用户态,信号共享清0
|
|
|
|
OsProcessExitCodeSignalClear(process);
|
|
|
|
OsProcessExitCodeSignalClear(process);//清空进程退出码
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
return saveContext;
|
|
|
|
return saveContext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|