Compare commits

...

4 Commits

Author SHA1 Message Date
openharmony_ci
88a0caae24 !632 fix: 共享内存问题修复
Merge pull request !632 from Harylee/cherry-pick-1632710893
2021-09-27 06:54:52 +00:00
openharmony_ci
99824916dd !630 master分支关于sigwait的修改挑单到TLS
Merge pull request !630 from lnlan/to_LTS
2021-09-27 02:53:36 +00:00
Haryslee
42fdaffe76 fixed 9fdb80f from https://gitee.com/harylee/kernel_liteos_a/pulls/628
fix: 共享内存问题修复

Signed-off-by: Haryslee <lihao189@huawei.com>
背景:父进程移除共享内存并标记SHM_SEG_REMOVE,当子进程资源回收时在
ShmFindSeg接口中判断该共享内存具有SHM_SEG_REMOVE时返回空,但是此时
seg->ds.shm_nattch不为0,不应返回空。
方案:ShmFindSeg接口中增加seg->ds.shm_nattch为0的判断。

close #I47X2Z

Change-Id: I8735cd11ac237b17fa745c50313da0fd0649bb9f
2021-09-27 02:48:14 +00:00
lnlan
ed7defbd43 fix: 修复sigwait等待到的信号值与获取的siginfo中的值不一致
【背景】
集成测试发送两个不同的信号,sigwait第二次等到的仍是第一个信号
经定位,信号在kill时会将相关的siginfo信息拷贝到taskcb的unbinfo中,sigwait
处理时从unbinfo拷贝给用户。若此信号发送时处于屏蔽状态,再有其他信号发送会覆盖
掉unbinfo,此时sigwait等待这个信号获取到的info已经被覆盖
【修改方案】
1. 每个任务添加一个siginfo缓存链表,在处理信号前夕从缓存链表取出info到unbinfo中

【影响】
对现有的产品编译不会有影响。

re #I3M12H

Signed-off-by: lanleinan <lanleinan@163.com>

Change-Id: If4b064c18773f8eca7419c665977260167b09810
2021-09-26 09:57:32 +00:00
4 changed files with 65 additions and 3 deletions

View File

@@ -498,6 +498,7 @@ LITE_OS_SEC_TEXT VOID OsTaskResourcesToFree(LosTaskCB *taskCB)
OsTaskKernelResourcesToFree(syncSignal, topOfStack);
SCHEDULER_LOCK(intSave);
OsClearSigInfoTmpList(&(taskCB->sig));
OsInsertTCBToFreeList(taskCB);
SCHEDULER_UNLOCK(intSave);
}

View File

@@ -132,6 +132,11 @@ struct sq_queue_s {
};
typedef struct sq_queue_s sq_queue_t;
typedef struct SigInfoListNode {
struct SigInfoListNode *next;
siginfo_t info;
} SigInfoListNode;
typedef struct {
sigset_t sigFlag;
sigset_t sigPendFlag;
@@ -140,6 +145,7 @@ typedef struct {
LOS_DL_LIST waitList;
sigset_t sigwaitmask; /* Waiting for pending signals */
siginfo_t sigunbinfo; /* Signal info when task unblocked */
SigInfoListNode *tmpInfoListHead; /* Signal info List */
unsigned int sigIntLock;
void *sigContext;
unsigned int count;
@@ -167,6 +173,7 @@ int OsSigSuspend(const sigset_t *set);
VOID OsSigIntLock(VOID);
VOID OsSigIntUnlock(VOID);
INT32 OsTaskKillUnsafe(UINT32 taskID, INT32 signo);
VOID OsClearSigInfoTmpList(sig_cb *sigcb);
#ifdef __cplusplus
#if __cplusplus

View File

@@ -67,11 +67,60 @@ int OsSigIsMember(const sigset_t *set, int signo)
return ret;
}
STATIC VOID OsMoveTmpInfoToUnbInfo(sig_cb *sigcb, INT32 signo)
{
SigInfoListNode *tmpInfoNode = sigcb->tmpInfoListHead;
SigInfoListNode **prevHook = &sigcb->tmpInfoListHead;
INT32 isFirstDel = 1;
while (tmpInfoNode != NULL) {
if (tmpInfoNode->info.si_signo == signo) {
/* In some case, many siginfos have same signo, only last one inserted list need copy to unbinfo. */
if (isFirstDel) {
/* copy tmpinfo to unbinfo. */
(VOID)memcpy_s(&sigcb->sigunbinfo, sizeof(siginfo_t), &tmpInfoNode->info, sizeof(siginfo_t));
isFirstDel = 0;
}
/* delete tmpinfo from tmpList. */
*prevHook = tmpInfoNode->next;
(VOID)LOS_MemFree(m_aucSysMem0, tmpInfoNode);
tmpInfoNode = *prevHook;
continue;
}
prevHook = &tmpInfoNode->next;
tmpInfoNode = tmpInfoNode->next;
}
return;
}
STATIC INT32 OsAddSigInfoToTmpList(sig_cb *sigcb, siginfo_t *info)
{
SigInfoListNode *tmp = (SigInfoListNode *)LOS_MemAlloc(m_aucSysMem0, sizeof(SigInfoListNode));
if (tmp == NULL) {
return LOS_NOK;
}
(VOID)memcpy_s(&tmp->info, sizeof(siginfo_t), info, sizeof(siginfo_t));
tmp->next = sigcb->tmpInfoListHead;
sigcb->tmpInfoListHead = tmp;
return LOS_OK;
}
VOID OsClearSigInfoTmpList(sig_cb *sigcb)
{
while (sigcb->tmpInfoListHead != NULL) {
SigInfoListNode *tmpInfoNode = sigcb->tmpInfoListHead;
sigcb->tmpInfoListHead = sigcb->tmpInfoListHead->next;
(VOID)LOS_MemFree(m_aucSysMem0, tmpInfoNode);
}
}
STATIC INLINE VOID OsSigWaitTaskWake(LosTaskCB *taskCB, INT32 signo)
{
sig_cb *sigcb = &taskCB->sig;
if (!LOS_ListEmpty(&sigcb->waitList) && OsSigIsMember(&sigcb->sigwaitmask, signo)) {
OsMoveTmpInfoToUnbInfo(sigcb, signo);
OsTaskWakeClearPendMask(taskCB);
OsSchedTaskWake(taskCB);
OsSigEmptySet(&sigcb->sigwaitmask);
@@ -141,7 +190,10 @@ int OsTcbDispatch(LosTaskCB *stcb, siginfo_t *info)
/* unmasked signal actions */
OsSigAddSet(&sigcb->sigFlag, info->si_signo);
}
(void) memcpy_s(&sigcb->sigunbinfo, sizeof(siginfo_t), info, sizeof(siginfo_t));
if (OsAddSigInfoToTmpList(sigcb, info) == LOS_NOK) {
return -ENOMEM;
}
return OsPendingTaskWake(stcb, info->si_signo);
}
@@ -516,6 +568,7 @@ int OsSigTimedWaitNoLock(sigset_t *set, siginfo_t *info, unsigned int timeout)
if (clear) {
sigcb->sigPendFlag ^= clear;
ret = FindFirstSetedBit((UINT64)clear) + 1;
OsMoveTmpInfoToUnbInfo(sigcb, ret);
} else {
OsSigAddSet(set, SIGKILL);
OsSigAddSet(set, SIGSTOP);
@@ -529,7 +582,7 @@ int OsSigTimedWaitNoLock(sigset_t *set, siginfo_t *info, unsigned int timeout)
sigcb->sigwaitmask = NULL_SIGNAL_SET;
}
if (info != NULL) {
(void) memcpy_s(info, sizeof(siginfo_t), &sigcb->sigunbinfo, sizeof(siginfo_t));
(VOID)memcpy_s(info, sizeof(siginfo_t), &sigcb->sigunbinfo, sizeof(siginfo_t));
}
return ret;
}
@@ -657,6 +710,7 @@ VOID *OsSaveSignalContext(VOID *sp, VOID *newSp)
sigcb->sigFlag |= process->sigShare;
UINT32 signo = (UINT32)FindFirstSetedBit(sigcb->sigFlag) + 1;
UINT32 sigVal = (UINT32)(UINTPTR)(sigcb->sigunbinfo.si_value.sival_ptr);
OsMoveTmpInfoToUnbInfo(sigcb, signo);
OsProcessExitCodeSignalSet(process, signo);
sigcb->sigContext = sp;

View File

@@ -304,7 +304,7 @@ STATIC struct shmIDSource *ShmFindSeg(int shmid)
}
seg = &g_shmSegs[shmid];
if ((seg->status & SHM_SEG_FREE) || (seg->status & SHM_SEG_REMOVE)) {
if ((seg->status & SHM_SEG_FREE) || ((seg->ds.shm_nattch == 0) && (seg->status & SHM_SEG_REMOVE))) {
set_errno(EIDRM);
return NULL;
}