summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHanhui <sylixos@gmail.com>2019-06-28 13:30:34 (GMT)
committer Hanhui <sylixos@gmail.com>2019-06-19 09:04:04 (GMT)
commit2dd35ef0209c32595962f924f6445673104e568f (patch)
tree1b8c88df354872fbc07bf572aab09984e99ac823
parentfac14cbfadae21b9af6d4d72397bf47c5eec3fcf (diff)
downloadAIC-OS-2dd35ef0209c32595962f924f6445673104e568f.zip
Improve traversal in-process thread operation safety.
-rw-r--r--SylixOS/kernel/interface/ThreadSetPriority.c6
-rw-r--r--SylixOS/loader/src/loader_vpdebug.c9
-rw-r--r--SylixOS/loader/src/loader_vppatch.c6
-rw-r--r--SylixOS/loader/src/loader_vpthread.c19
-rw-r--r--SylixOS/posix/sched/sched.c18
5 files changed, 50 insertions, 8 deletions
diff --git a/SylixOS/kernel/interface/ThreadSetPriority.c b/SylixOS/kernel/interface/ThreadSetPriority.c
index a254bed..8c78905 100644
--- a/SylixOS/kernel/interface/ThreadSetPriority.c
+++ b/SylixOS/kernel/interface/ThreadSetPriority.c
@@ -84,6 +84,12 @@ ULONG API_ThreadSetPriority (LW_OBJECT_HANDLE ulId, UINT8 ucPriority)
ptcb = _K_ptcbTCBIdTable[usIndex];
+ if (ptcb->TCB_iDeleteProcStatus) {
+ __KERNEL_EXIT(); /* 退出内核 */
+ _ErrorHandle(ERROR_THREAD_OTHER_DELETE);
+ return (ERROR_THREAD_OTHER_DELETE);
+ }
+
if (LW_PRIO_IS_EQU(ptcb->TCB_ucPriority, ucPriority)) {
__KERNEL_EXIT(); /* 退出内核 */
return (ERROR_NONE);
diff --git a/SylixOS/loader/src/loader_vpdebug.c b/SylixOS/loader/src/loader_vpdebug.c
index 3309927..12489a3 100644
--- a/SylixOS/loader/src/loader_vpdebug.c
+++ b/SylixOS/loader/src/loader_vpdebug.c
@@ -92,6 +92,9 @@ VOID vprocDebugStop (PVOID pvVProc, PLW_CLASS_TCB ptcbExcp)
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
if (ptcb == ptcbExcp) {
continue; /* 不停止此任务 */
}
@@ -129,6 +132,9 @@ VOID vprocDebugContinue (PVOID pvVProc, PLW_CLASS_TCB ptcbExcp)
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
if (ptcb == ptcbExcp) {
continue; /* 不启动此任务 */
}
@@ -271,6 +277,9 @@ UINT vprocDebugThreadGet (PVOID pvVProc, LW_OBJECT_HANDLE ulId[], UINT uiTa
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
if (uiNum < uiTableNum) {
ulId[uiNum] = ptcb->TCB_ulId;
uiNum++;
diff --git a/SylixOS/loader/src/loader_vppatch.c b/SylixOS/loader/src/loader_vppatch.c
index 4bb300b..d3a74ae 100644
--- a/SylixOS/loader/src/loader_vppatch.c
+++ b/SylixOS/loader/src/loader_vppatch.c
@@ -771,6 +771,9 @@ VOID vprocKillPrepare (pid_t pid, LW_OBJECT_HANDLE ulId)
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
if (ptcb->TCB_ulId == ulId) {
continue; /* 不停止主任务 */
}
@@ -811,6 +814,9 @@ static VOID vprocKillRelease (PLW_CLASS_TCB ptcbCur)
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
if (ptcb == ptcbCur) {
continue;
}
diff --git a/SylixOS/loader/src/loader_vpthread.c b/SylixOS/loader/src/loader_vpthread.c
index 9753fe9..cbf8026 100644
--- a/SylixOS/loader/src/loader_vpthread.c
+++ b/SylixOS/loader/src/loader_vpthread.c
@@ -83,6 +83,7 @@ INT vprocThreadNum (pid_t pid, ULONG *pulNum)
{
LW_LD_VPROC *pvproc;
PLW_LIST_LINE plineTemp;
+ PLW_CLASS_TCB ptcb;
if (!pulNum) {
_ErrorHandle(EINVAL);
@@ -98,6 +99,11 @@ INT vprocThreadNum (pid_t pid, ULONG *pulNum)
for (plineTemp = pvproc->VP_plineThread;
plineTemp != LW_NULL;
plineTemp = _list_line_get_next(plineTemp)) {
+
+ ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
(*pulNum)++;
}
__KERNEL_EXIT(); /* 退出内核 */
@@ -126,6 +132,9 @@ VOID vprocThreadKill (PVOID pvVProc, PLW_CLASS_TCB ptcbExcp)
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
if (ptcb != ptcbExcp) { /* ptcbCur 为主线程 */
_excJobAdd((VOIDFUNCPTR)kill, (PVOID)ptcb->TCB_ulId, (PVOID)SIGKILL, 0, 0, 0, 0);
}
@@ -167,6 +176,9 @@ INT vprocThreadTraversal (pid_t pid,
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
pfunc(ptcb, pvArg0, pvArg1, pvArg2, pvArg3, pvArg4, pvArg5);
}
__KERNEL_EXIT(); /* 退出内核 */
@@ -207,6 +219,9 @@ INT vprocThreadSigaction (PVOID pvVProc, VOIDFUNCPTR pfunc, INT iSigIndex,
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
if (ptcb != ptcbCur) {
pfunc(ptcb, iSigIndex, psigactionNew);
}
@@ -249,6 +264,10 @@ INT vprocThreadAffinity (PVOID pvVProc, size_t stSize, const PLW_CLASS_CPUSET
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
+
if (ptcb == ptcbCur) {
if (!__THREAD_LOCK_GET(ptcb)) { /* 外部没有锁定此任务 */
__KERNEL_ENTER(); /* 进入内核 */
diff --git a/SylixOS/posix/sched/sched.c b/SylixOS/posix/sched/sched.c
index 1edaf70..8d7f331 100644
--- a/SylixOS/posix/sched/sched.c
+++ b/SylixOS/posix/sched/sched.c
@@ -104,16 +104,18 @@ int sched_yield (void)
static VOID __sched_set (PLW_CLASS_TCB ptcb, UINT8 *pucPolicy, UINT8 *pucPriority)
{
- if (pucPriority) {
- if (!LW_PRIO_IS_EQU(ptcb->TCB_ucPriority, *pucPriority)) {
- _SchedSetPrio(ptcb, *pucPriority);
+ if (LW_LIKELY(ptcb)) {
+ if (pucPriority) {
+ if (!LW_PRIO_IS_EQU(ptcb->TCB_ucPriority, *pucPriority)) {
+ _SchedSetPrio(ptcb, *pucPriority);
+ }
}
- }
- if (pucPolicy) {
- ptcb->TCB_ucSchedPolicy = *pucPolicy;
- if (*pucPolicy == LW_OPTION_SCHED_FIFO) {
- ptcb->TCB_usSchedCounter = ptcb->TCB_usSchedSlice; /* 不为零 */
+ if (pucPolicy) {
+ ptcb->TCB_ucSchedPolicy = *pucPolicy;
+ if (*pucPolicy == LW_OPTION_SCHED_FIFO) {
+ ptcb->TCB_usSchedCounter = ptcb->TCB_usSchedSlice; /* 不为零 */
+ }
}
}
}