未验证 提交 251abede 编写于 作者: O openharmony_ci 提交者: Gitee

!1090 支持pid容器

Merge pull request !1090 from zhushengle/pid_container
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -102,7 +102,7 @@ typedef struct {
* Return : pointer to the task context
*/
extern VOID *OsTaskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack, BOOL initFlag);
extern VOID OsUserCloneParentStack(VOID *childStack, UINTPTR parentTopOfStask, UINT32 parentStackSize);
extern VOID OsUserCloneParentStack(VOID *childStack, UINTPTR sp, UINTPTR parentTopOfStask, UINT32 parentStackSize);
extern VOID OsUserTaskStackInit(TaskContext *context, UINTPTR taskEntry, UINTPTR stack);
extern VOID OsInitSignalContext(const VOID *sp, VOID *signalContext, UINTPTR sigHandler, UINT32 signo, UINT32 param);
extern void arm_clean_cache_range(UINTPTR start, UINTPTR end);
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -103,7 +103,7 @@ LITE_OS_SEC_TEXT_INIT VOID *OsTaskStackInit(UINT32 taskID, UINT32 stackSize, VOI
return (VOID *)taskContext;
}
LITE_OS_SEC_TEXT VOID OsUserCloneParentStack(VOID *childStack, UINTPTR parentTopOfStack, UINT32 parentStackSize)
VOID OsUserCloneParentStack(VOID *childStack, UINTPTR sp, UINTPTR parentTopOfStack, UINT32 parentStackSize)
{
LosTaskCB *task = OsCurrTaskGet();
sig_cb *sigcb = &task->sig;
......@@ -117,6 +117,10 @@ LITE_OS_SEC_TEXT VOID OsUserCloneParentStack(VOID *childStack, UINTPTR parentTop
(VOID)memcpy_s(childStack, sizeof(TaskContext), cloneStack, sizeof(TaskContext));
((TaskContext *)childStack)->R0 = 0;
if (sp != 0) {
((TaskContext *)childStack)->USP = TRUNCATE(sp, LOSCFG_STACK_POINT_ALIGN_SIZE);
((TaskContext *)childStack)->ULR = 0;
}
}
LITE_OS_SEC_TEXT_INIT VOID OsUserTaskStackInit(TaskContext *context, UINTPTR taskEntry, UINTPTR stack)
......
......@@ -240,9 +240,9 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
taskInitParam.usTaskPrio = (UINT16)userAttr.schedparam.sched_priority;
taskInitParam.uwStackSize = userAttr.stacksize;
if (OsProcessIsUserMode(OsCurrProcessGet())) {
taskInitParam.processID = OsGetKernelInitProcessID();
taskInitParam.processID = (UINTPTR)OsGetKernelInitProcess();
} else {
taskInitParam.processID = OsCurrProcessGet()->processID;
taskInitParam.processID = (UINTPTR)OsCurrProcessGet();
}
if (userAttr.detachstate == PTHREAD_CREATE_DETACHED) {
taskInitParam.uwResved = LOS_TASK_STATUS_DETACHED;
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -117,7 +117,7 @@ STATIC INLINE BOOL ValidTimerID(UINT16 swtmrID)
}
/* check owner of this timer */
if (OS_SWT_FROM_SID(swtmrID)->uwOwnerPid != LOS_GetCurrProcessID()) {
if (OS_SWT_FROM_SID(swtmrID)->uwOwnerPid != (UINTPTR)OsCurrProcessGet()) {
return FALSE;
}
......@@ -484,7 +484,7 @@ static int PthreadGetCputime(clockid_t clockID, struct timespec *ats)
LosTaskCB *task = OsGetTaskCB(tid);
if (OsCurrTaskGet()->processID != task->processID) {
if (OsCurrTaskGet()->processCB != task->processCB) {
return -EINVAL;
}
......@@ -748,7 +748,7 @@ static VOID SwtmrProc(UINTPTR tmrArg)
/* Make sure that the para is valid */
OS_GOTO_EXIT_IF(OS_TID_CHECK_INVALID(arg->tid), EINVAL);
stcb = OsGetTaskCB(arg->tid);
ret = OsUserProcessOperatePermissionsCheck(stcb, stcb->processID);
ret = OsUserProcessOperatePermissionsCheck(stcb, stcb->processCB);
OS_GOTO_EXIT_IF(ret != LOS_OK, -ret);
/* Dispatch the signal to thread, bypassing normal task group thread
......@@ -1087,8 +1087,7 @@ clock_t times(struct tms *buf)
int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue)
{
UINT32 intSave;
LosTaskCB *taskCB = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
LosProcessCB *processCB = OS_PCB_FROM_PID(taskCB->processID);
LosProcessCB *processCB = OsCurrProcessGet();
timer_t timerID = 0;
struct itimerspec spec;
struct itimerspec ospec;
......@@ -1141,8 +1140,7 @@ int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue
int getitimer(int which, struct itimerval *value)
{
LosTaskCB *taskCB = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
LosProcessCB *processCB = OS_PCB_FROM_PID(taskCB->processID);
LosProcessCB *processCB = OsCurrProcessGet();
struct itimerspec spec = {};
int ret = LOS_OK;
......
......@@ -112,7 +112,7 @@ static ssize_t QuickstartIoctl(struct file *filep, int cmd, unsigned long arg)
return QuickstartNotify(arg);
}
if (OsGetUserInitProcessID() != LOS_GetCurrProcessID()) {
if (LOS_GetCurrProcessID() != OS_USER_ROOT_PROCESS_ID) {
PRINT_ERR("Permission denios!\n");
return -EACCES;
}
......
......@@ -259,7 +259,6 @@ int osShellCmdCat(int argc, const char **argv)
init_param.uwStackSize = CAT_TASK_STACK_SIZE;
init_param.pcName = "shellcmd_cat";
init_param.uwResved = LOS_TASK_STATUS_DETACHED | OS_TASK_FLAG_SPECIFIES_PROCESS;
init_param.processID = 2; /* 2: kProcess */
ret = (int)LOS_TaskCreate(&ca_task, &init_param);
if (ret != LOS_OK) {
......
......@@ -67,13 +67,24 @@ config PAGE_TABLE_FINE_LOCK
help
This option will enable fine lock for page table.
######################### config options of container ####################
config KERNEL_CONTAINER
bool "Enable container Feature"
default n
depends on KERNEL_VM
config PID_CONTAINER
bool "Enable PID container Feature"
default n
depends on KERNEL_CONTAINER
######################### config options of extended #####################
source "kernel/extended/Kconfig"
config ENABLE_KERNEL_TEST
bool "Enable kernel test"
default n
help
This option will enable kernel test.
######################### config options of extended #####################
source "kernel/extended/Kconfig"
endmenu
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
# Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
......@@ -32,7 +32,10 @@ import("//kernel/liteos_a/liteos.gni")
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"container/los_container.c",
"container/los_pid_container.c",
"core/los_bitmap.c",
"core/los_info.c",
"core/los_process.c",
"core/los_smp.c",
"core/los_swtmr.c",
......
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
# Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
......@@ -38,7 +38,9 @@ LOCAL_SRCS := $(wildcard ipc/*.c) $(wildcard core/*.c) $(wildcard mem/membox/*.
$(wildcard mem/tlsf/*.c) \
$(wildcard mp/*.c) \
$(wildcard sched/*.c) \
$(wildcard vm/*.c)
$(wildcard vm/*.c) \
$(wildcard container/*.c)
LOCAL_FLAGS := $(LITEOS_CFLAGS_INTERWORK) -Wno-frame-address
......
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_container_pri.h"
#include "los_process_pri.h"
#ifdef LOSCFG_KERNEL_CONTAINER
STATIC Container g_rootContainer;
VOID OsContainerInitSystemProcess(LosProcessCB *processCB)
{
processCB->container = &g_rootContainer;
LOS_AtomicInc(&processCB->container->rc);
#ifdef LOSCFG_PID_CONTAINER
(VOID)OsAllocSpecifiedVpidUnsafe(processCB->processID, processCB, NULL);
#endif
return;
}
VOID OsInitRootContainer(VOID)
{
#ifdef LOSCFG_PID_CONTAINER
OsInitRootPidContainer(&g_rootContainer.pidContainer);
#endif
return;
}
STATIC INLINE Container *CreateContainer(VOID)
{
Container *container = LOS_MemAlloc(m_aucSysMem1, sizeof(Container));
if (container == NULL) {
return NULL;
}
(VOID)memset_s(container, sizeof(Container), 0, sizeof(Container));
LOS_AtomicInc(&container->rc);
return container;
}
/*
* called from clone. This now handles copy for Container and all
* namespaces therein.
*/
UINT32 OsCopyContainers(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID)
{
UINT32 intSave;
UINT32 ret = LOS_OK;
if (!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET))) {
SCHEDULER_LOCK(intSave);
child->container = parent->container;
LOS_AtomicInc(&child->container->rc);
SCHEDULER_UNLOCK(intSave);
} else {
child->container = CreateContainer();
if (child->container == NULL) {
return ENOMEM;
}
}
/* Pid container initialization must precede other container initialization. */
#ifdef LOSCFG_PID_CONTAINER
ret = OsCopyPidContainer(flags, child, parent, processID);
if (ret != LOS_OK) {
return ret;
}
#endif
return ret;
}
VOID OsContainersDestroy(LosProcessCB *processCB)
{
/* All processes in the container must be destroyed before the container is destroyed. */
#ifdef LOSCFG_PID_CONTAINER
if (processCB->processID == 1) {
OsPidContainersDestroyAllProcess(processCB);
}
#endif
#ifndef LOSCFG_PID_CONTAINER
LOS_AtomicDec(&curr->container->rc);
if (LOS_AtomicRead(&processCB->container->rc) == 1) {
(VOID)LOS_MemFree(m_aucSysMem1, processCB->container);
processCB->container = NULL;
}
#endif
}
#endif
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sched.h>
#include "los_pid_container_pri.h"
#include "los_config.h"
#include "los_process_pri.h"
#include "los_container_pri.h"
#ifdef LOSCFG_PID_CONTAINER
STATIC UINT32 g_currentPidContainerNum;
STATIC LosProcessCB *g_defaultProcessCB = NULL;
STATIC LosTaskCB *g_defaultTaskCB = NULL;
STATIC VOID FreeVpid(LosProcessCB *processCB)
{
PidContainer *pidContainer = processCB->container->pidContainer;
UINT32 vpid = processCB->processID;
while ((pidContainer != NULL) && !OS_PID_CHECK_INVALID(vpid)) {
ProcessVid *processVid = &pidContainer->pidArray[vpid];
processVid->cb = (UINTPTR)g_defaultProcessCB;
vpid = processVid->vpid;
processVid->vpid = OS_INVALID_VALUE;
LOS_ListTailInsert(&pidContainer->pidFreeList, &processVid->node);
LOS_AtomicDec(&pidContainer->rc);
pidContainer = pidContainer->parent;
}
}
STATIC ProcessVid *OsGetFreeVpid(PidContainer *pidContainer)
{
if (LOS_ListEmpty(&pidContainer->pidFreeList)) {
return NULL;
}
ProcessVid *vpid = LOS_DL_LIST_ENTRY(LOS_DL_LIST_FIRST(&pidContainer->pidFreeList), ProcessVid, node);
LOS_ListDelete(&vpid->node);
return vpid;
}
UINT32 OsAllocSpecifiedVpidUnsafe(UINT32 vpid, LosProcessCB *processCB, LosProcessCB *parent)
{
PidContainer *pidContainer = processCB->container->pidContainer;
if ((pidContainer == NULL) || OS_PID_CHECK_INVALID(vpid)) {
return OS_INVALID_VALUE;
}
if (LOS_AtomicRead(&pidContainer->lock) > 0) {
return OS_INVALID_VALUE;
}
ProcessVid *processVid = &pidContainer->pidArray[vpid];
if (processVid->cb != (UINTPTR)g_defaultProcessCB) {
return OS_INVALID_VALUE;
}
processVid->cb = (UINTPTR)processCB;
processCB->processID = vpid;
LOS_ListDelete(&processVid->node);
LOS_AtomicInc(&pidContainer->rc);
if ((vpid == OS_USER_ROOT_PROCESS_ID) && (parent != NULL)) {
ProcessVid *vppidItem = &pidContainer->pidArray[0];
LOS_ListDelete(&vppidItem->node);
vppidItem->cb = (UINTPTR)parent;
}
pidContainer = pidContainer->parent;
while (pidContainer != NULL) {
ProcessVid *item = OsGetFreeVpid(pidContainer);
if (item == NULL) {
break;
}
item->cb = (UINTPTR)processCB;
processVid->vpid = item->vid;
LOS_AtomicInc(&pidContainer->rc);
processVid = item;
pidContainer = pidContainer->parent;
}
return processCB->processID;
}
STATIC UINT32 OsAllocVpid(LosProcessCB *processCB)
{
UINT32 intSave;
ProcessVid *oldProcessVid = NULL;
PidContainer *pidContainer = processCB->container->pidContainer;
if ((pidContainer == NULL) || (LOS_AtomicRead(&pidContainer->lock) > 0)) {
return OS_INVALID_VALUE;
}
processCB->processID = OS_INVALID_VALUE;
SCHEDULER_LOCK(intSave);
do {
ProcessVid *vpid = OsGetFreeVpid(pidContainer);
if (vpid == NULL) {
break;
}
vpid->cb = (UINTPTR)processCB;
if (processCB->processID == OS_INVALID_VALUE) {
processCB->processID = vpid->vid;
} else {
oldProcessVid->vpid = vpid->vid;
}
LOS_AtomicInc(&pidContainer->rc);
oldProcessVid = vpid;
pidContainer = pidContainer->parent;
} while (pidContainer != NULL);
SCHEDULER_UNLOCK(intSave);
return processCB->processID;
}
STATIC ProcessVid *OsGetFreeVtid(PidContainer *pidContainer)
{
if (LOS_ListEmpty(&pidContainer->tidFreeList)) {
return NULL;
}
ProcessVid *vtid = LOS_DL_LIST_ENTRY(LOS_DL_LIST_FIRST(&pidContainer->tidFreeList), ProcessVid, node);
LOS_ListDelete(&vtid->node);
return vtid;
}
VOID OsFreeVtid(LosTaskCB *taskCB)
{
PidContainer *pidContainer = taskCB->pidContainer;
UINT32 vtid = taskCB->taskID;
while ((pidContainer != NULL) && !OS_TID_CHECK_INVALID(vtid)) {
ProcessVid *item = &pidContainer->tidArray[vtid];
item->cb = (UINTPTR)g_defaultTaskCB;
vtid = item->vpid;
item->vpid = OS_INVALID_VALUE;
LOS_ListTailInsert(&pidContainer->tidFreeList, &item->node);
pidContainer = pidContainer->parent;
}
taskCB->pidContainer = NULL;
}
UINT32 OsAllocVtid(LosTaskCB *taskCB, const LosProcessCB *processCB)
{
PidContainer *pidContainer = processCB->container->pidContainer;
ProcessVid *oldTaskVid = NULL;
do {
ProcessVid *item = OsGetFreeVtid(pidContainer);
if (item == NULL) {
return OS_INVALID_VALUE;
}
if ((pidContainer->parent != NULL) && (item->vid == 0)) {
item->cb = (UINTPTR)OsCurrTaskGet();
item->vpid = OsCurrTaskGet()->taskID;
continue;
}
item->cb = (UINTPTR)taskCB;
if (taskCB->pidContainer == NULL) {
taskCB->pidContainer = pidContainer;
taskCB->taskID = item->vid;
} else {
oldTaskVid->vpid = item->vid;
}
oldTaskVid = item;
pidContainer = pidContainer->parent;
} while (pidContainer != NULL);
return taskCB->taskID;
}
VOID OsPidContainersDestroyAllProcess(LosProcessCB *curr)
{
INT32 ret;
UINT32 intSave;
PidContainer *pidContainer = curr->container->pidContainer;
LOS_AtomicInc(&pidContainer->lock);
for (UINT32 index = 2; index < LOSCFG_BASE_CORE_PROCESS_LIMIT; index++) { /* 2: ordinary process */
SCHEDULER_LOCK(intSave);
LosProcessCB *processCB = OS_PCB_FROM_PID(index);
if (OsProcessIsUnused(processCB)) {
SCHEDULER_UNLOCK(intSave);
continue;
}
if (curr != processCB->parentProcess) {
LOS_ListDelete(&processCB->siblingList);
if (OsProcessIsInactive(processCB)) {
LOS_ListTailInsert(&curr->exitChildList, &processCB->siblingList);
} else {
LOS_ListTailInsert(&curr->childrenList, &processCB->siblingList);
}
processCB->parentProcess = curr;
}
SCHEDULER_UNLOCK(intSave);
ret = OsKillLock(index, SIGKILL);
if (ret < 0) {
PRINT_ERR("Pid container kill all process failed, pid %u, errno=%d\n", index, -ret);
}
ret = LOS_Wait(index, NULL, 0, NULL);
if (ret != index) {
PRINT_ERR("Pid container wait pid %d failed, errno=%d\n", index, -ret);
}
}
}
STATIC PidContainer *CreateNewPidContainer(PidContainer *parent)
{
UINT32 index;
PidContainer *newPidContainer = (PidContainer *)LOS_MemAlloc(m_aucSysMem1, sizeof(PidContainer));
if (newPidContainer == NULL) {
return NULL;
}
(VOID)memset_s(newPidContainer, sizeof(PidContainer), 0, sizeof(PidContainer));
LOS_ListInit(&newPidContainer->pidFreeList);
for (index = 0; index < LOSCFG_BASE_CORE_PROCESS_LIMIT; index++) {
ProcessVid *vpid = &newPidContainer->pidArray[index];
vpid->vid = index;
vpid->vpid = OS_INVALID_VALUE;
vpid->cb = (UINTPTR)g_defaultProcessCB;
LOS_ListTailInsert(&newPidContainer->pidFreeList, &vpid->node);
}
LOS_ListInit(&newPidContainer->tidFreeList);
for (index = 0; index < LOSCFG_BASE_CORE_TSK_LIMIT; index++) {
ProcessVid *vtid = &newPidContainer->tidArray[index];
vtid->vid = index;
vtid->vpid = OS_INVALID_VALUE;
vtid->cb = (UINTPTR)g_defaultTaskCB;
LOS_ListTailInsert(&newPidContainer->tidFreeList, &vtid->node);
}
newPidContainer->parent = parent;
if (parent != NULL) {
LOS_AtomicSet(&newPidContainer->level, parent->level + 1);
} else {
LOS_AtomicSet(&newPidContainer->level, 0);
}
return newPidContainer;
}
STATIC UINT32 CreatePidContainer(LosProcessCB *child, LosProcessCB *parent)
{
UINT32 intSave;
UINT32 ret;
PidContainer *parentContainer = parent->container->pidContainer;
PidContainer *newPidContainer = CreateNewPidContainer(parentContainer);
if (newPidContainer == NULL) {
return ENOMEM;
}
SCHEDULER_LOCK(intSave);
if ((parentContainer->level + 1) >= PID_CONTAINER_LEVEL_LIMIT) {
SCHEDULER_UNLOCK(intSave);
(VOID)LOS_MemFree(m_aucSysMem1, newPidContainer);
return EINVAL;
}
g_currentPidContainerNum++;
child->container->pidContainer = newPidContainer;
ret = OsAllocSpecifiedVpidUnsafe(OS_USER_ROOT_PROCESS_ID, child, parent);
if (ret == OS_INVALID_VALUE) {
g_currentPidContainerNum--;
FreeVpid(child);
child->container->pidContainer = NULL;
SCHEDULER_UNLOCK(intSave);
(VOID)LOS_MemFree(m_aucSysMem1, newPidContainer);
return ENOSPC;
}
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
VOID OsPidContainersDestroy(LosProcessCB *curr)
{
if (curr->container == NULL) {
return;
}
PidContainer *pidContainer = curr->container->pidContainer;
if (pidContainer != NULL) {
FreeVpid(curr);
if (LOS_AtomicRead(&pidContainer->rc) == 0) {
g_currentPidContainerNum--;
(VOID)LOS_MemFree(m_aucSysMem1, pidContainer);
curr->container->pidContainer = NULL;
}
}
LOS_AtomicDec(&curr->container->rc);
if (LOS_AtomicRead(&curr->container->rc) == 0) {
(VOID)LOS_MemFree(m_aucSysMem1, curr->container);
curr->container = NULL;
}
}
UINT32 OsCopyPidContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID)
{
UINT32 ret;
if (!(flags & CLONE_NEWPID)) {
ret = OsAllocVpid(child);
if (ret == OS_INVALID_VALUE) {
PRINT_ERR("[%s] alloc vpid failed\n", __FUNCTION__);
return ENOSPC;
}
*processID = child->processID;
return LOS_OK;
}
ret = CreatePidContainer(child, parent);
if (ret != LOS_OK) {
return ret;
}
PidContainer *pidContainer = child->container->pidContainer;
if (pidContainer->pidArray[child->processID].vpid == OS_INVALID_VALUE) {
*processID = child->processID;
} else {
*processID = pidContainer->pidArray[child->processID].vpid;
}
return LOS_OK;
}
UINT32 OsInitRootPidContainer(PidContainer **pidContainer)
{
UINT32 intSave;
g_defaultTaskCB = OsGetDefaultTaskCB();
g_defaultProcessCB = OsGetDefaultProcessCB();
PidContainer *newPidContainer = CreateNewPidContainer(NULL);
if (newPidContainer == NULL) {
return ENOMEM;
}
SCHEDULER_LOCK(intSave);
g_currentPidContainerNum++;
*pidContainer = newPidContainer;
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
UINT32 OsGetVpidFromCurrContainer(const LosProcessCB *processCB)
{
UINT32 vpid = processCB->processID;
PidContainer *pidContainer = processCB->container->pidContainer;
PidContainer *currPidContainer = OsCurrTaskGet()->pidContainer;
while (pidContainer != NULL) {
ProcessVid *vid = &pidContainer->pidArray[vpid];
if (currPidContainer != pidContainer) {
vpid = vid->vpid;
pidContainer = pidContainer->parent;
continue;
}
return vid->vid;
}
return OS_INVALID_VALUE;
}
UINT32 OsGetVtidFromCurrContainer(const LosTaskCB *taskCB)
{
UINT32 vtid = taskCB->taskID;
PidContainer *pidContainer = taskCB->pidContainer;
PidContainer *currPidContainer = OsCurrTaskGet()->pidContainer;
while (pidContainer != NULL) {
ProcessVid *vid = &pidContainer->tidArray[vtid];
if (currPidContainer != pidContainer) {
vtid = vid->vpid;
pidContainer = pidContainer->parent;
continue;
}
return vid->vid;
}
return OS_INVALID_VALUE;
}
LosProcessCB *OsGetPCBFromVpid(UINT32 vpid)
{
PidContainer *pidContainer = OsCurrTaskGet()->pidContainer;
ProcessVid *processVid = &pidContainer->pidArray[vpid];
return (LosProcessCB *)processVid->cb;
}
LosTaskCB *OsGetTCBFromVtid(UINT32 vtid)
{
PidContainer *pidContainer = OsCurrTaskGet()->pidContainer;
ProcessVid *taskVid = &pidContainer->tidArray[vtid];
return (LosTaskCB *)taskVid->cb;
}
#endif
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_info_pri.h"
#include "los_task_pri.h"
#include "los_vm_dump.h"
STATIC UINT32 GetCurrParentPid(UINT32 pid, const LosProcessCB *processCB)
{
if (processCB->parentProcess == NULL) {
return 0;
}
#ifdef LOSCFG_PID_CONTAINER
if (pid == OS_USER_ROOT_PROCESS_ID) {
return 0;
}
if (OS_PROCESS_CONTAINER_CHECK(processCB->parentProcess, OsCurrProcessGet())) {
return OsGetVpidFromCurrContainer(processCB->parentProcess);
}
#endif
return processCB->parentProcess->processID;
}
STATIC INLINE UINT32 GetCurrTid(const LosTaskCB *taskCB)
{
#ifdef LOSCFG_PID_CONTAINER
if (taskCB->pidContainer != OsCurrTaskGet()->pidContainer) {
return OsGetVtidFromCurrContainer(taskCB);
}
#endif
return taskCB->taskID;
}
STATIC UINT16 GetProcessStatus(LosProcessCB *processCB)
{
UINT16 status;
LosTaskCB *taskCB = NULL;
if (LOS_ListEmpty(&processCB->threadSiblingList)) {
return processCB->processStatus;
}
status = processCB->processStatus;
LOS_DL_LIST_FOR_EACH_ENTRY(taskCB, &processCB->threadSiblingList, LosTaskCB, threadList) {
status |= (taskCB->taskStatus & 0x00FF);
}
return status;
}
STATIC VOID GetProcessInfo(ProcessInfo *pcbInfo, const LosProcessCB *processCB)
{
SchedParam param = {0};
pcbInfo->pid = OsGetPid(processCB);
pcbInfo->ppid = GetCurrParentPid(pcbInfo->pid, processCB);
pcbInfo->status = GetProcessStatus((LosProcessCB *)processCB);
pcbInfo->mode = processCB->processMode;
if (processCB->pgroup != NULL) {
pcbInfo->pgroupID = OsGetPid(OS_GET_PGROUP_LEADER(processCB->pgroup));
} else {
pcbInfo->pgroupID = -1;
}
#ifdef LOSCFG_SECURITY_CAPABILITY
if (processCB->user != NULL) {
pcbInfo->userID = processCB->user->userID;
} else {
pcbInfo->userID = -1;
}
#else
pcbInfo->userID = 0;
#endif
LosTaskCB *taskCB = processCB->threadGroup;
pcbInfo->threadGroupID = taskCB->taskID;
taskCB->ops->schedParamGet(taskCB, &param);
pcbInfo->policy = LOS_SCHED_RR;
pcbInfo->basePrio = param.basePrio;
pcbInfo->threadNumber = processCB->threadNumber;
#ifdef LOSCFG_KERNEL_CPUP
(VOID)OsGetProcessAllCpuUsageUnsafe(processCB->processCpup, pcbInfo);
#endif
(VOID)memcpy_s(pcbInfo->name, OS_PCB_NAME_LEN, processCB->processName, OS_PCB_NAME_LEN);
}
STATIC VOID GetProcessMemInfo(ProcessInfo *pcbInfo, const LosProcessCB *processCB, LosVmSpace *vmSpace)
{
/* Process memory usage statistics, idle task defaults to 0 */
if (processCB == &g_processCBArray[0]) {
pcbInfo->virtualMem = 0;
pcbInfo->shareMem = 0;
pcbInfo->physicalMem = 0;
} else if (vmSpace == LOS_GetKVmSpace()) {
(VOID)OsShellCmdProcessPmUsage(vmSpace, &pcbInfo->shareMem, &pcbInfo->physicalMem);
pcbInfo->virtualMem = pcbInfo->physicalMem;
} else {
pcbInfo->virtualMem = OsShellCmdProcessVmUsage(vmSpace);
if (pcbInfo->virtualMem == 0) {
pcbInfo->status = OS_PROCESS_FLAG_UNUSED;
return;
}
if (OsShellCmdProcessPmUsage(vmSpace, &pcbInfo->shareMem, &pcbInfo->physicalMem) == 0) {
pcbInfo->status = OS_PROCESS_FLAG_UNUSED;
}
}
}
STATIC VOID GetThreadInfo(ProcessThreadInfo *threadInfo, LosProcessCB *processCB)
{
SchedParam param = {0};
LosTaskCB *taskCB = NULL;
if (LOS_ListEmpty(&processCB->threadSiblingList)) {
threadInfo->threadCount = 0;
return;
}
threadInfo->threadCount = 0;
LOS_DL_LIST_FOR_EACH_ENTRY(taskCB, &processCB->threadSiblingList, LosTaskCB, threadList) {
TaskInfo *taskInfo = &threadInfo->taskInfo[threadInfo->threadCount];
taskInfo->tid = GetCurrTid(taskCB);
taskInfo->pid = OsGetPid(processCB);
taskInfo->status = taskCB->taskStatus;
taskCB->ops->schedParamGet(taskCB, &param);
taskInfo->policy = param.policy;
taskInfo->priority = param.priority;
#ifdef LOSCFG_KERNEL_SMP
taskInfo->currCpu = taskCB->currCpu;
taskInfo->cpuAffiMask = taskCB->cpuAffiMask;
#endif
taskInfo->stackPoint = (UINTPTR)taskCB->stackPointer;
taskInfo->topOfStack = taskCB->topOfStack;
taskInfo->stackSize = taskCB->stackSize;
taskInfo->waitFlag = taskCB->waitFlag;
taskInfo->waitID = taskCB->waitID;
taskInfo->taskMux = taskCB->taskMux;
(VOID)OsStackWaterLineGet((const UINTPTR *)(taskCB->topOfStack + taskCB->stackSize),
(const UINTPTR *)taskCB->topOfStack, &taskInfo->waterLine);
#ifdef LOSCFG_KERNEL_CPUP
(VOID)OsGetTaskAllCpuUsageUnsafe(&taskCB->taskCpup, taskInfo);
#endif
(VOID)memcpy_s(taskInfo->name, OS_TCB_NAME_LEN, taskCB->taskName, OS_TCB_NAME_LEN);
threadInfo->threadCount++;
}
}
UINT32 OsGetProcessThreadInfo(UINT32 pid, ProcessThreadInfo *threadInfo)
{
UINT32 intSave;
if (OS_PID_CHECK_INVALID(pid) || (pid == 0) || (threadInfo == NULL)) {
return LOS_NOK;
}
LosProcessCB *processCB = OS_PCB_FROM_PID(pid);
if (OsProcessIsUnused(processCB)) {
return LOS_NOK;
}
GetProcessMemInfo(&threadInfo->processInfo, processCB, processCB->vmSpace);
SCHEDULER_LOCK(intSave);
GetProcessInfo(&threadInfo->processInfo, processCB);
GetThreadInfo(threadInfo, processCB);
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
STATIC VOID ProcessMemUsageGet(ProcessInfo *pcbArray)
{
UINT32 intSave;
#ifdef LOSCFG_PID_CONTAINER
PidContainer *pidContainer = OsCurrTaskGet()->pidContainer;
for (UINT32 pid = 0; pid < g_processMaxNum; ++pid) {
ProcessVid *processVid = &pidContainer->pidArray[pid];
const LosProcessCB *processCB = (LosProcessCB *)processVid->cb;
#else
for (UINT32 pid = 0; pid < g_processMaxNum; ++pid) {
const LosProcessCB *processCB = OS_PCB_FROM_RPID(pid);
#endif
ProcessInfo *pcbInfo = pcbArray + pid;
SCHEDULER_LOCK(intSave);
if (OsProcessIsUnused(processCB)) {
SCHEDULER_UNLOCK(intSave);
pcbInfo->status = OS_PROCESS_FLAG_UNUSED;
continue;
}
LosVmSpace *vmSpace = processCB->vmSpace;
SCHEDULER_UNLOCK(intSave);
GetProcessMemInfo(pcbInfo, processCB, vmSpace);
}
}
UINT32 OsGetAllProcessInfo(ProcessInfo *pcbArray)
{
UINT32 intSave;
if (pcbArray == NULL) {
return LOS_NOK;
}
ProcessMemUsageGet(pcbArray);
SCHEDULER_LOCK(intSave);
#ifdef LOSCFG_PID_CONTAINER
PidContainer *pidContainer = OsCurrTaskGet()->pidContainer;
for (UINT32 index = 0; index < LOSCFG_BASE_CORE_PROCESS_LIMIT; index++) {
ProcessVid *processVid = &pidContainer->pidArray[index];
LosProcessCB *processCB = (LosProcessCB *)processVid->cb;
#else
for (UINT32 index = 0; index < LOSCFG_BASE_CORE_PROCESS_LIMIT; index++) {
LosProcessCB *processCB = OS_PCB_FROM_RPID(index);
#endif
ProcessInfo *pcbInfo = pcbArray + index;
if (OsProcessIsUnused(processCB)) {
pcbInfo->status = OS_PROCESS_FLAG_UNUSED;
continue;
}
GetProcessInfo(pcbInfo, processCB);
}
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
此差异已折叠。
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -45,11 +45,13 @@ STATIC VOID OsSmpSecondaryInit(VOID *arg)
{
UNUSED(arg);
OsCurrTaskSet(OsGetMainTask());
#ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
OsSwtmrInit();
#endif
OsIdleTaskCreate();
OsIdleTaskCreate((UINTPTR)OsGetIdleProcess());
OsInitCall(LOS_INIT_LEVEL_KMOD_TASK);
OsSchedStart();
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -320,10 +320,10 @@ BOOL OsIsSwtmrTask(const LosTaskCB *taskCB)
return FALSE;
}
LITE_OS_SEC_TEXT_INIT VOID OsSwtmrRecycle(UINT32 processID)
LITE_OS_SEC_TEXT_INIT VOID OsSwtmrRecycle(UINTPTR ownerID)
{
for (UINT16 index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++) {
if (g_swtmrCBArray[index].uwOwnerPid == processID) {
if (g_swtmrCBArray[index].uwOwnerPid == ownerID) {
LOS_SwtmrDelete(index);
}
}
......@@ -524,7 +524,7 @@ STATIC INLINE VOID SwtmrDelete(SWTMR_CTRL_S *swtmr)
/* insert to free list */
LOS_ListTailInsert(&g_swtmrFreeList, &swtmr->stSortList.sortLinkNode);
swtmr->ucState = OS_SWTMR_STATUS_UNUSED;
swtmr->uwOwnerPid = 0;
swtmr->uwOwnerPid = OS_INVALID_VALUE;
SwtmrDebugDataClear(swtmr->usTimerID);
}
......@@ -680,7 +680,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval,
LOS_ListDelete(LOS_DL_LIST_FIRST(&g_swtmrFreeList));
SWTMR_UNLOCK(intSave);
swtmr->uwOwnerPid = OsCurrProcessGet()->processID;
swtmr->uwOwnerPid = (UINTPTR)OsCurrProcessGet();
swtmr->pfnHandler = handler;
swtmr->ucMode = mode;
swtmr->uwOverrun = 0;
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -61,6 +61,9 @@
#ifdef LOSCFG_ENABLE_OOM_LOOP_TASK
#include "los_oom.h"
#endif
#ifdef LOSCFG_KERNEL_CONTAINER
#include "los_container_pri.h"
#endif
#if (LOSCFG_BASE_CORE_TSK_LIMIT <= 0)
#error "task maxnum cannot be zero"
......@@ -81,12 +84,12 @@ STATIC VOID OsConsoleIDSetHook(UINT32 param1,
/* temp task blocks for booting procedure */
LITE_OS_SEC_BSS STATIC LosTaskCB g_mainTask[LOSCFG_KERNEL_CORE_NUM];
LosTaskCB *OsGetMainTask()
LosTaskCB *OsGetMainTask(VOID)
{
return (LosTaskCB *)(g_mainTask + ArchCurrCpuid());
}
VOID OsSetMainTask()
VOID OsSetMainTask(VOID)
{
UINT32 i;
CHAR *name = "osMain";
......@@ -99,7 +102,7 @@ VOID OsSetMainTask()
for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
g_mainTask[i].taskStatus = OS_TASK_STATUS_UNUSED;
g_mainTask[i].taskID = LOSCFG_BASE_CORE_TSK_LIMIT;
g_mainTask[i].processID = OS_KERNEL_PROCESS_GROUP;
g_mainTask[i].processCB = OS_KERNEL_PROCESS_GROUP;
#ifdef LOSCFG_KERNEL_SMP_LOCKDEP
g_mainTask[i].lockDep.lockDepth = 0;
g_mainTask[i].lockDep.waitLock = NULL;
......@@ -110,6 +113,16 @@ VOID OsSetMainTask()
}
}
VOID OsSetMainTaskProcess(UINTPTR processCB)
{
for (UINT32 i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
g_mainTask[i].processCB = processCB;
#ifdef LOSCFG_PID_CONTAINER
g_mainTask[i].pidContainer = OS_PID_CONTAINER_FROM_PCB((LosProcessCB *)processCB);
#endif
}
}
LITE_OS_SEC_TEXT WEAK VOID OsIdleTask(VOID)
{
while (1) {
......@@ -168,7 +181,7 @@ LITE_OS_SEC_TEXT UINT32 OsTaskSetDetachUnsafe(LosTaskCB *taskCB)
return LOS_EINVAL;
}
LITE_OS_SEC_TEXT_INIT UINT32 OsTaskInit(VOID)
LITE_OS_SEC_TEXT_INIT UINT32 OsTaskInit(UINTPTR processCB)
{
UINT32 index;
UINT32 size;
......@@ -192,9 +205,14 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTaskInit(VOID)
for (index = 0; index < g_taskMaxNum; index++) {
g_taskCBArray[index].taskStatus = OS_TASK_STATUS_UNUSED;
g_taskCBArray[index].taskID = index;
g_taskCBArray[index].processCB = processCB;
LOS_ListTailInsert(&g_losFreeTask, &g_taskCBArray[index].pendList);
}
g_taskCBArray[index].taskStatus = OS_TASK_STATUS_UNUSED;
g_taskCBArray[index].taskID = index;
g_taskCBArray[index].processCB = processCB;
ret = OsSchedInit();
EXIT:
......@@ -206,10 +224,10 @@ EXIT:
UINT32 OsGetIdleTaskId(VOID)
{
return OsSchedRunqueueIdleGet();
return OsSchedRunqueueIdleGet()->taskID;
}
LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID)
LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(UINTPTR processID)
{
UINT32 ret;
TSK_INIT_PARAM_S taskInitParam;
......@@ -221,7 +239,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID)
taskInitParam.pcName = "Idle";
taskInitParam.policy = LOS_SCHED_IDLE;
taskInitParam.usTaskPrio = OS_TASK_PRIORITY_LOWEST;
taskInitParam.processID = OsGetIdleProcessID();
taskInitParam.processID = processID;
#ifdef LOSCFG_KERNEL_SMP
taskInitParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
#endif
......@@ -231,7 +249,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID)
}
LosTaskCB *idleTask = OS_TCB_FROM_TID(idleTaskID);
idleTask->taskStatus |= OS_TASK_FLAG_SYSTEM_TASK;
OsSchedRunqueueIdleInit(idleTaskID);
OsSchedRunqueueIdleInit(idleTask);
return LOS_TaskResume(idleTaskID);
}
......@@ -250,7 +268,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_CurTaskIDGet(VOID)
return runTask->taskID;
}
STATIC INLINE UINT32 OsTaskSyncCreate(LosTaskCB *taskCB)
STATIC INLINE UINT32 TaskSyncCreate(LosTaskCB *taskCB)
{
#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
UINT32 ret = LOS_SemCreate(0, &taskCB->syncSignal);
......@@ -310,11 +328,14 @@ STATIC INLINE VOID OsTaskSyncWake(const LosTaskCB *taskCB)
STATIC INLINE VOID OsInsertTCBToFreeList(LosTaskCB *taskCB)
{
#ifdef LOSCFG_PID_CONTAINER
OsFreeVtid(taskCB);
#endif
UINT32 taskID = taskCB->taskID;
(VOID)memset_s(taskCB, sizeof(LosTaskCB), 0, sizeof(LosTaskCB));
taskCB->taskID = taskID;
taskCB->processCB = (UINTPTR)OsGetDefaultProcessCB();
taskCB->taskStatus = OS_TASK_STATUS_UNUSED;
taskCB->processID = OS_INVALID_VALUE;
LOS_ListAdd(&g_losFreeTask, &taskCB->pendList);
}
......@@ -340,12 +361,12 @@ STATIC VOID OsTaskResourcesToFree(LosTaskCB *taskCB)
taskCB->userArea = 0;
SCHEDULER_UNLOCK(intSave);
LosProcessCB *processCB = OS_PCB_FROM_PID(taskCB->processID);
LosProcessCB *processCB = OS_PCB_FROM_TCB(taskCB);
LOS_ASSERT(!(OsProcessVmSpaceGet(processCB) == NULL));
UINT32 ret = OsUnMMap(OsProcessVmSpaceGet(processCB), (UINTPTR)mapBase, mapSize);
if ((ret != LOS_OK) && (mapBase != 0) && !OsProcessIsInit(processCB)) {
PRINT_ERR("process(%u) unmmap user task(%u) stack failed! mapbase: 0x%x size :0x%x, error: %d\n",
taskCB->processID, taskCB->taskID, mapBase, mapSize, ret);
processCB->processID, taskCB->taskID, mapBase, mapSize, ret);
}
#ifdef LOSCFG_KERNEL_LITEIPC
......@@ -416,11 +437,9 @@ LITE_OS_SEC_TEXT_INIT VOID OsTaskEntry(UINT32 taskID)
OsRunningTaskToExit(taskCB, 0);
}
LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsTaskCreateParamCheck(const UINT32 *taskID,
TSK_INIT_PARAM_S *initParam, VOID **pool)
STATIC UINT32 TaskCreateParamCheck(const UINT32 *taskID, TSK_INIT_PARAM_S *initParam)
{
UINT32 poolSize = OS_SYS_MEM_SIZE;
*pool = (VOID *)m_aucSysMem1;
if (taskID == NULL) {
return LOS_ERRNO_TSK_ID_INVALID;
......@@ -430,8 +449,7 @@ LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsTaskCreateParamCheck(const UINT32 *taskID,
return LOS_ERRNO_TSK_PTR_NULL;
}
LosProcessCB *process = OS_PCB_FROM_PID(initParam->processID);
if (!OsProcessIsUserMode(process)) {
if (!OsProcessIsUserMode((LosProcessCB *)initParam->processID)) {
if (initParam->pcName == NULL) {
return LOS_ERRNO_TSK_NAME_EMPTY;
}
......@@ -461,24 +479,47 @@ LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsTaskCreateParamCheck(const UINT32 *taskID,
return LOS_OK;
}
LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskStackAlloc(VOID **topStack, UINT32 stackSize, VOID *pool)
STATIC VOID TaskCBDeInit(LosTaskCB *taskCB)
{
*topStack = (VOID *)LOS_MemAllocAlign(pool, stackSize, LOSCFG_STACK_POINT_ALIGN_SIZE);
UINT32 intSave;
#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
if (taskCB->syncSignal != OS_INVALID_VALUE) {
OsTaskSyncDestroy(taskCB->syncSignal);
taskCB->syncSignal = OS_INVALID_VALUE;
}
#endif
if (taskCB->topOfStack != (UINTPTR)NULL) {
(VOID)LOS_MemFree(m_aucSysMem1, (VOID *)taskCB->topOfStack);
taskCB->topOfStack = (UINTPTR)NULL;
}
SCHEDULER_LOCK(intSave);
LosProcessCB *processCB = OS_PCB_FROM_TCB(taskCB);
if (processCB != OsGetDefaultProcessCB()) {
LOS_ListDelete(&taskCB->threadList);
processCB->threadNumber--;
processCB->threadCount--;
}
OsInsertTCBToFreeList(taskCB);
SCHEDULER_UNLOCK(intSave);
}
STATIC VOID TaskCBBaseInit(LosTaskCB *taskCB, const VOID *stackPtr, const VOID *topStack,
const TSK_INIT_PARAM_S *initParam)
STATIC VOID TaskCBBaseInit(LosTaskCB *taskCB, const TSK_INIT_PARAM_S *initParam)
{
taskCB->stackPointer = (VOID *)stackPtr;
taskCB->stackPointer = NULL;
taskCB->args[0] = initParam->auwArgs[0]; /* 0~3: just for args array index */
taskCB->args[1] = initParam->auwArgs[1];
taskCB->args[2] = initParam->auwArgs[2];
taskCB->args[3] = initParam->auwArgs[3];
taskCB->topOfStack = (UINTPTR)topStack;
taskCB->topOfStack = (UINTPTR)NULL;
taskCB->stackSize = initParam->uwStackSize;
taskCB->taskEntry = initParam->pfnTaskEntry;
taskCB->signal = SIGNAL_NONE;
#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
taskCB->syncSignal = OS_INVALID_VALUE;
#endif
#ifdef LOSCFG_KERNEL_SMP
taskCB->currCpu = OS_TASK_INVALID_CPUID;
taskCB->cpuAffiMask = (initParam->usCpuAffiMask) ?
......@@ -492,29 +533,25 @@ STATIC VOID TaskCBBaseInit(LosTaskCB *taskCB, const VOID *stackPtr, const VOID *
LOS_ListInit(&taskCB->lockList);
SET_SORTLIST_VALUE(&taskCB->sortList, OS_SORT_LINK_INVALID_TIME);
#ifdef LOSCFG_KERNEL_VM
taskCB->futex.index = OS_INVALID_VALUE;
#endif
}
STATIC UINT32 OsTaskCBInit(LosTaskCB *taskCB, const TSK_INIT_PARAM_S *initParam,
const VOID *stackPtr, const VOID *topStack)
STATIC UINT32 TaskCBInit(LosTaskCB *taskCB, const TSK_INIT_PARAM_S *initParam)
{
UINT32 ret;
UINT32 numCount;
SchedParam schedParam = { 0 };
UINT16 policy = (initParam->policy == LOS_SCHED_NORMAL) ? LOS_SCHED_RR : initParam->policy;
TaskCBBaseInit(taskCB, stackPtr, topStack, initParam);
TaskCBBaseInit(taskCB, initParam);
schedParam.policy = policy;
numCount = OsProcessAddNewTask(initParam->processID, taskCB, &schedParam);
#ifdef LOSCFG_KERNEL_VM
taskCB->futex.index = OS_INVALID_VALUE;
if (taskCB->taskStatus & OS_TASK_FLAG_USER_MODE) {
taskCB->userArea = initParam->userParam.userArea;
taskCB->userMapBase = initParam->userParam.userMapBase;
taskCB->userMapSize = initParam->userParam.userMapSize;
OsUserTaskStackInit(taskCB->stackPointer, (UINTPTR)taskCB->taskEntry, initParam->userParam.userSP);
ret = OsProcessAddNewTask(initParam->processID, taskCB, &schedParam, &numCount);
if (ret != LOS_OK) {
return ret;
}
#endif
ret = OsSchedParamInit(taskCB, policy, &schedParam, initParam);
if (ret != LOS_OK) {
......@@ -534,7 +571,27 @@ STATIC UINT32 OsTaskCBInit(LosTaskCB *taskCB, const TSK_INIT_PARAM_S *initParam,
return LOS_OK;
}
LITE_OS_SEC_TEXT LosTaskCB *OsGetFreeTaskCB(VOID)
STATIC UINT32 TaskStackInit(LosTaskCB *taskCB, const TSK_INIT_PARAM_S *initParam)
{
VOID *topStack = (VOID *)LOS_MemAllocAlign(m_aucSysMem1, initParam->uwStackSize, LOSCFG_STACK_POINT_ALIGN_SIZE);
if (topStack == NULL) {
return LOS_ERRNO_TSK_NO_MEMORY;
}
taskCB->topOfStack = (UINTPTR)topStack;
taskCB->stackPointer = OsTaskStackInit(taskCB->taskID, initParam->uwStackSize, topStack, TRUE);
#ifdef LOSCFG_KERNEL_VM
if (taskCB->taskStatus & OS_TASK_FLAG_USER_MODE) {
taskCB->userArea = initParam->userParam.userArea;
taskCB->userMapBase = initParam->userParam.userMapBase;
taskCB->userMapSize = initParam->userParam.userMapSize;
OsUserTaskStackInit(taskCB->stackPointer, (UINTPTR)taskCB->taskEntry, initParam->userParam.userSP);
}
#endif
return LOS_OK;
}
STATIC LosTaskCB *GetFreeTaskCB(VOID)
{
UINT32 intSave;
......@@ -554,37 +611,31 @@ LITE_OS_SEC_TEXT LosTaskCB *OsGetFreeTaskCB(VOID)
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreateOnly(UINT32 *taskID, TSK_INIT_PARAM_S *initParam)
{
UINT32 intSave, errRet;
VOID *topStack = NULL;
VOID *pool = NULL;
errRet = OsTaskCreateParamCheck(taskID, initParam, &pool);
UINT32 errRet = TaskCreateParamCheck(taskID, initParam);
if (errRet != LOS_OK) {
return errRet;
}
LosTaskCB *taskCB = OsGetFreeTaskCB();
LosTaskCB *taskCB = GetFreeTaskCB();
if (taskCB == NULL) {
errRet = LOS_ERRNO_TSK_TCB_UNAVAILABLE;
goto LOS_ERREND;
return LOS_ERRNO_TSK_TCB_UNAVAILABLE;
}
errRet = OsTaskSyncCreate(taskCB);
errRet = TaskCBInit(taskCB, initParam);
if (errRet != LOS_OK) {
goto LOS_ERREND_REWIND_TCB;
goto DEINIT_TCB;
}
OsTaskStackAlloc(&topStack, initParam->uwStackSize, pool);
if (topStack == NULL) {
errRet = LOS_ERRNO_TSK_NO_MEMORY;
goto LOS_ERREND_REWIND_SYNC;
errRet = TaskSyncCreate(taskCB);
if (errRet != LOS_OK) {
goto DEINIT_TCB;
}
VOID *stackPtr = OsTaskStackInit(taskCB->taskID, initParam->uwStackSize, topStack, TRUE);
errRet = OsTaskCBInit(taskCB, initParam, stackPtr, topStack);
errRet = TaskStackInit(taskCB, initParam);
if (errRet != LOS_OK) {
goto LOS_ERREND_TCB_INIT;
goto DEINIT_TCB;
}
if (OsConsoleIDSetHook != NULL) {
OsConsoleIDSetHook(taskCB->taskID, OsCurrTaskGet()->taskID);
}
......@@ -593,17 +644,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreateOnly(UINT32 *taskID, TSK_INIT_PARAM_S
OsHookCall(LOS_HOOK_TYPE_TASK_CREATE, taskCB);
return LOS_OK;
LOS_ERREND_TCB_INIT:
(VOID)LOS_MemFree(pool, topStack);
LOS_ERREND_REWIND_SYNC:
#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
OsTaskSyncDestroy(taskCB->syncSignal);
#endif
LOS_ERREND_REWIND_TCB:
SCHEDULER_LOCK(intSave);
OsInsertTCBToFreeList(taskCB);
SCHEDULER_UNLOCK(intSave);
LOS_ERREND:
DEINIT_TCB:
TaskCBDeInit(taskCB);
return errRet;
}
......@@ -621,9 +663,9 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreate(UINT32 *taskID, TSK_INIT_PARAM_S *in
}
if (OsProcessIsUserMode(OsCurrProcessGet())) {
initParam->processID = OsGetKernelInitProcessID();
initParam->processID = (UINTPTR)OsGetKernelInitProcess();
} else {
initParam->processID = OsCurrProcessGet()->processID;
initParam->processID = (UINTPTR)OsCurrProcessGet();
}
ret = LOS_TaskCreateOnly(taskID, initParam);
......@@ -801,7 +843,7 @@ LITE_OS_SEC_TEXT VOID OsRunningTaskToExit(LosTaskCB *runTask, UINT32 status)
{
UINT32 intSave;
if (OsProcessThreadGroupIDGet(runTask) == runTask->taskID) {
if (OsIsProcessThreadGroup(runTask)) {
OsProcessThreadGroupDestroy();
}
......@@ -812,11 +854,11 @@ LITE_OS_SEC_TEXT VOID OsRunningTaskToExit(LosTaskCB *runTask, UINT32 status)
SCHEDULER_UNLOCK(intSave);
OsTaskResourcesToFree(runTask);
OsProcessResourcesToFree(OS_PCB_FROM_PID(runTask->processID));
OsProcessResourcesToFree(OS_PCB_FROM_TCB(runTask));
SCHEDULER_LOCK(intSave);
OsProcessNaturalExit(OS_PCB_FROM_PID(runTask->processID), status);
OsProcessNaturalExit(OS_PCB_FROM_TCB(runTask), status);
OsTaskReleaseHoldLock(runTask);
OsTaskStatusUnusedSet(runTask);
} else if (runTask->taskStatus & OS_TASK_FLAG_PTHREAD_JOIN) {
......@@ -881,8 +923,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID)
}
SCHEDULER_LOCK(intSave);
if (taskCB->taskStatus & (OS_TASK_STATUS_UNUSED | OS_TASK_FLAG_SYSTEM_TASK | OS_TASK_FLAG_NO_DELETE)) {
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
if (OsTaskIsNotDelete(taskCB)) {
if (OsTaskIsUnused(taskCB)) {
ret = LOS_ERRNO_TSK_NOT_CREATED;
} else {
ret = LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK;
......@@ -1252,8 +1294,8 @@ LITE_OS_SEC_TEXT INT32 OsSetTaskName(LosTaskCB *taskCB, const CHAR *name, BOOL s
err = LOS_OK;
/* if thread is main thread, then set processName as taskName */
if ((taskCB->taskID == OsProcessThreadGroupIDGet(taskCB)) && (setPName == TRUE)) {
err = (INT32)OsSetProcessName(OS_PCB_FROM_PID(taskCB->processID), (const CHAR *)taskCB->taskName);
if (OsIsProcessThreadGroup(taskCB) && (setPName == TRUE)) {
err = (INT32)OsSetProcessName(OS_PCB_FROM_TCB(taskCB), (const CHAR *)taskCB->taskName);
if (err != LOS_OK) {
err = EINVAL;
}
......@@ -1266,16 +1308,16 @@ EXIT:
INT32 OsUserTaskOperatePermissionsCheck(const LosTaskCB *taskCB)
{
return OsUserProcessOperatePermissionsCheck(taskCB, OsCurrProcessGet()->processID);
return OsUserProcessOperatePermissionsCheck(taskCB, (UINTPTR)OsCurrProcessGet());
}
INT32 OsUserProcessOperatePermissionsCheck(const LosTaskCB *taskCB, UINT32 processID)
INT32 OsUserProcessOperatePermissionsCheck(const LosTaskCB *taskCB, UINTPTR processCB)
{
if (taskCB == NULL) {
return LOS_EINVAL;
}
if (processID == OS_INVALID_VALUE) {
if (processCB == (UINTPTR)OsGetDefaultProcessCB()) {
return LOS_EINVAL;
}
......@@ -1283,7 +1325,7 @@ INT32 OsUserProcessOperatePermissionsCheck(const LosTaskCB *taskCB, UINT32 proce
return LOS_EINVAL;
}
if (processID != taskCB->processID) {
if (processCB != taskCB->processCB) {
return LOS_EPERM;
}
......@@ -1318,7 +1360,7 @@ LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsCreateUserTaskParamCheck(UINT32 processID,
return LOS_OK;
}
LITE_OS_SEC_TEXT_INIT UINT32 OsCreateUserTask(UINT32 processID, TSK_INIT_PARAM_S *initParam)
LITE_OS_SEC_TEXT_INIT UINT32 OsCreateUserTask(UINTPTR processID, TSK_INIT_PARAM_S *initParam)
{
UINT32 taskID;
UINT32 ret;
......@@ -1335,7 +1377,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsCreateUserTask(UINT32 processID, TSK_INIT_PARAM_S
if (processID == OS_INVALID_VALUE) {
SCHEDULER_LOCK(intSave);
LosProcessCB *processCB = OsCurrProcessGet();
initParam->processID = processCB->processID;
initParam->processID = (UINTPTR)processCB;
initParam->consoleID = processCB->consoleID;
SCHEDULER_UNLOCK(intSave);
} else {
......@@ -1462,7 +1504,7 @@ UINT32 LOS_TaskJoin(UINT32 taskID, UINTPTR *retval)
return LOS_EINVAL;
}
if (runTask->processID != taskCB->processID) {
if (runTask->processCB != taskCB->processCB) {
SCHEDULER_UNLOCK(intSave);
return LOS_EPERM;
}
......@@ -1505,7 +1547,7 @@ UINT32 LOS_TaskDetach(UINT32 taskID)
return LOS_EINVAL;
}
if (runTask->processID != taskCB->processID) {
if (runTask->processCB != taskCB->processCB) {
SCHEDULER_UNLOCK(intSave);
return LOS_EPERM;
}
......@@ -1525,6 +1567,11 @@ LITE_OS_SEC_TEXT UINT32 LOS_GetSystemTaskMaximum(VOID)
return g_taskMaxNum;
}
LosTaskCB *OsGetDefaultTaskCB(VOID)
{
return &g_taskCBArray[g_taskMaxNum];
}
LITE_OS_SEC_TEXT VOID OsWriteResourceEvent(UINT32 events)
{
(VOID)LOS_EventWrite(&g_resourceEvent, events);
......
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_CONTAINER_PRI_H
#define _LOS_CONTAINER_PRI_H
#include "los_atomic.h"
#ifdef LOSCFG_KERNEL_CONTAINER
#ifdef LOSCFG_PID_CONTAINER
#include "los_pid_container_pri.h"
#endif
typedef struct Container {
Atomic rc;
#ifdef LOSCFG_PID_CONTAINER
struct PidContainer *pidContainer;
struct PidContainer *pidForChildren;
#endif
} Container;
VOID OsContainerInitSystemProcess(LosProcessCB *processCB);
VOID OsInitRootContainer(VOID);
UINT32 OsCopyContainers(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID);
VOID OsContainersDestroy(LosProcessCB *processCB);
#endif
#endif /* _LOS_CONTAINER_PRI_H */
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_INFO_PRI_H
#define _LOS_INFO_PRI_H
#include "los_process_pri.h"
#include "los_sched_pri.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef struct TagTaskInfo {
UINT32 tid;
UINT32 pid;
UINT16 status;
UINT16 policy;
UINT16 priority;
#ifdef LOSCFG_KERNEL_SMP
UINT16 currCpu;
UINT16 cpuAffiMask;
#endif
UINT32 stackSize;
UINTPTR stackPoint;
UINTPTR topOfStack;
UINT32 waitFlag;
UINT32 waitID;
VOID *taskMux;
UINT32 waterLine;
#ifdef LOSCFG_KERNEL_CPUP
UINT32 cpup1sUsage;
UINT32 cpup10sUsage;
UINT32 cpupAllsUsage;
#endif
CHAR name[OS_TCB_NAME_LEN];
} TaskInfo;
typedef struct TagProcessInfo {
UINT32 pid;
UINT32 ppid;
UINT16 status;
UINT16 mode;
UINT32 pgroupID;
UINT32 userID;
UINT16 policy;
UINT32 basePrio;
UINT32 threadGroupID;
UINT32 threadNumber;
#ifdef LOSCFG_KERNEL_VM
UINT32 virtualMem;
UINT32 shareMem;
UINT32 physicalMem;
#endif
#ifdef LOSCFG_KERNEL_CPUP
UINT32 cpup1sUsage;
UINT32 cpup10sUsage;
UINT32 cpupAllsUsage;
#endif
CHAR name[OS_PCB_NAME_LEN];
} ProcessInfo;
typedef struct TagProcessThreadInfo {
ProcessInfo processInfo;
UINT32 threadCount;
TaskInfo taskInfo[LOSCFG_BASE_CORE_TSK_LIMIT];
} ProcessThreadInfo;
UINT32 OsGetAllProcessInfo(ProcessInfo *pcbArray);
UINT32 OsGetProcessThreadInfo(UINT32 pid, ProcessThreadInfo *threadInfo);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_INFO_PRI_H */
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_PID_CONTAINER_PRI_H
#define _LOS_PID_CONTAINER_PRI_H
#include "los_config.h"
#include "los_atomic.h"
#include "los_list.h"
typedef struct TagTaskCB LosTaskCB;
typedef struct ProcessCB LosProcessCB;
struct ProcessGroup;
typedef struct {
UINT32 vid; /* Virtual ID */
UINT32 vpid; /* Virtual parent ID */
UINTPTR cb; /* Control block */
LOS_DL_LIST node;
} ProcessVid;
#define PID_CONTAINER_LEVEL_LIMIT 3
typedef struct PidContainer {
Atomic rc;
Atomic level;
Atomic lock;
struct PidContainer *parent;
struct ProcessGroup *rootPGroup;
LOS_DL_LIST tidFreeList;
ProcessVid tidArray[LOSCFG_BASE_CORE_TSK_LIMIT];
LOS_DL_LIST pidFreeList;
ProcessVid pidArray[LOSCFG_BASE_CORE_PROCESS_LIMIT];
} PidContainer;
#define OS_PID_CONTAINER_FROM_PCB(processCB) ((processCB)->container->pidContainer)
#define OS_ROOT_PGRP(processCB) (OS_PID_CONTAINER_FROM_PCB(processCB)->rootPGroup)
#define OS_PROCESS_CONTAINER_CHECK(processCB, currProcessCB) \
((processCB)->container->pidContainer != (currProcessCB)->container->pidContainer)
UINT32 OsAllocSpecifiedVpidUnsafe(UINT32 vpid, LosProcessCB *processCB, LosProcessCB *parent);
VOID OsPidContainersDestroyAllProcess(LosProcessCB *processCB);
VOID OsPidContainersDestroy(LosProcessCB *curr);
UINT32 OsCopyPidContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID);
UINT32 OsInitRootPidContainer(PidContainer **pidContainer);
LosProcessCB *OsGetPCBFromVpid(UINT32 vpid);
LosTaskCB *OsGetTCBFromVtid(UINT32 vtid);
UINT32 OsGetVpidFromCurrContainer(const LosProcessCB *processCB);
UINT32 OsGetVtidFromCurrContainer(const LosTaskCB *taskCB);
VOID OsFreeVtid(LosTaskCB *taskCB);
UINT32 OsAllocVtid(LosTaskCB *taskCB, const LosProcessCB *processCB);
#endif /* _LOS_PID_CONTAINER_PRI_H */
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -33,6 +33,7 @@
#define _LOS_PROCESS_PRI_H
#include "los_task_pri.h"
#include "sched.h"
#include "los_sem_pri.h"
#include "los_process.h"
#include "los_vm_map.h"
......@@ -46,6 +47,9 @@
#include "vid_type.h"
#endif
#include "sys/resource.h"
#ifdef LOSCFG_KERNEL_CONTAINER
#include "los_container_pri.h"
#endif
#ifdef __cplusplus
#if __cplusplus
......@@ -68,11 +72,11 @@ typedef struct {
} User;
#endif
typedef struct {
UINT32 groupID; /**< Process group ID is the PID of the process that created the group */
LOS_DL_LIST processList; /**< List of processes under this process group */
LOS_DL_LIST exitProcessList; /**< List of closed processes (zombie processes) under this group */
LOS_DL_LIST groupList; /**< Process group list */
typedef struct ProcessGroup {
UINTPTR pgroupLeader; /**< Process group leader is the the process that created the group */
LOS_DL_LIST processList; /**< List of processes under this process group */
LOS_DL_LIST exitProcessList; /**< List of closed processes (zombie processes) under this group */
LOS_DL_LIST groupList; /**< Process group list */
} ProcessGroup;
typedef struct ProcessCB {
......@@ -82,15 +86,15 @@ typedef struct ProcessCB {
running in the process */
UINT16 consoleID; /**< The console id of task belongs */
UINT16 processMode; /**< Kernel Mode:0; User Mode:1; */
UINT32 parentProcessID; /**< Parent process ID */
struct ProcessCB *parentProcess; /**< Parent process */
UINT32 exitCode; /**< Process exit status */
LOS_DL_LIST pendList; /**< Block list to which the process belongs */
LOS_DL_LIST childrenList; /**< Children process list */
LOS_DL_LIST exitChildList; /**< Exit children process list */
LOS_DL_LIST siblingList; /**< Linkage in parent's children list */
ProcessGroup *group; /**< Process group to which a process belongs */
ProcessGroup *pgroup; /**< Process group to which a process belongs */
LOS_DL_LIST subordinateGroupList; /**< Linkage in group list */
UINT32 threadGroupID; /**< Which thread group , is the main thread ID of the process */
LosTaskCB *threadGroup;
LOS_DL_LIST threadSiblingList; /**< List of threads under this process */
volatile UINT32 threadNumber; /**< Number of threads alive under this process */
UINT32 threadCount; /**< Total number of threads created under this process */
......@@ -126,20 +130,25 @@ typedef struct ProcessCB {
OsCpupBase *processCpup; /**< Process cpu usage */
#endif
struct rlimit *resourceLimit;
#ifdef LOSCFG_KERNEL_CONTAINER
struct Container *container;
#endif
} LosProcessCB;
#define CLONE_VM 0x00000100
#define CLONE_FS 0x00000200
#define CLONE_FILES 0x00000400
#define CLONE_SIGHAND 0x00000800
#define CLONE_PTRACE 0x00002000
#define CLONE_VFORK 0x00004000
#define CLONE_PARENT 0x00008000
#define CLONE_THREAD 0x00010000
extern LosProcessCB *g_processCBArray;
extern UINT32 g_processMaxNum;
#define OS_PCB_FROM_PID(processID) (((LosProcessCB *)g_processCBArray) + (processID))
#define OS_PCB_FROM_SIBLIST(ptr) LOS_DL_LIST_ENTRY((ptr), LosProcessCB, siblingList)
#define OS_PCB_FROM_PENDLIST(ptr) LOS_DL_LIST_ENTRY((ptr), LosProcessCB, pendList)
#define OS_PCB_FROM_RPID(processID) (((LosProcessCB *)g_processCBArray) + (processID))
#ifdef LOSCFG_PID_CONTAINER
#define OS_PCB_FROM_PID(processID) OsGetPCBFromVpid(processID)
#else
#define OS_PCB_FROM_PID(processID) OS_PCB_FROM_RPID(processID)
#endif
#define OS_PCB_FROM_TCB(taskCB) ((LosProcessCB *)((taskCB)->processCB))
#define OS_PCB_FROM_TID(taskID) ((LosProcessCB *)(OS_TCB_FROM_TID(taskID)->processCB))
#define OS_GET_PGROUP_LEADER(pgroup) ((LosProcessCB *)((pgroup)->pgroupLeader))
#define OS_PCB_FROM_SIBLIST(ptr) LOS_DL_LIST_ENTRY((ptr), LosProcessCB, siblingList)
#define OS_PCB_FROM_PENDLIST(ptr) LOS_DL_LIST_ENTRY((ptr), LosProcessCB, pendList)
/**
* @ingroup los_process
......@@ -246,12 +255,17 @@ STATIC INLINE BOOL OsProcessIsInactive(const LosProcessCB *processCB)
*/
STATIC INLINE BOOL OsProcessIsDead(const LosProcessCB *processCB)
{
return ((processCB->processStatus & (OS_PROCESS_FLAG_UNUSED | OS_PROCESS_STATUS_ZOMBIES)) != 0);
return ((processCB->processStatus & OS_PROCESS_STATUS_ZOMBIES) != 0);
}
STATIC INLINE BOOL OsProcessIsInit(const LosProcessCB *processCB)
{
return (processCB->processStatus & OS_PROCESS_STATUS_INIT);
return ((processCB->processStatus & OS_PROCESS_STATUS_INIT) != 0);
}
STATIC INLINE BOOL OsProcessIsPGroupLeader(const LosProcessCB *processCB)
{
return ((processCB->processStatus & OS_PROCESS_FLAG_GROUP_LEADER) != 0);
}
/**
......@@ -284,6 +298,24 @@ STATIC INLINE BOOL OsProcessIsInit(const LosProcessCB *processCB)
*/
#define OS_PROCESS_USERINIT_PRIORITY 28
/**
* @ingroup los_process
* ID of the kernel idle process
*/
#define OS_KERNEL_IDLE_PROCESS_ID 0U
/**
* @ingroup los_process
* ID of the user root process
*/
#define OS_USER_ROOT_PROCESS_ID 1U
/**
* @ingroup los_process
* ID of the kernel root process
*/
#define OS_KERNEL_ROOT_PROCESS_ID 2U
#define OS_TASK_DEFAULT_STACK_SIZE 0x2000
#define OS_USER_TASK_SYSCALL_STACK_SIZE 0x3000
#define OS_USER_TASK_STACK_SIZE 0x100000
......@@ -299,8 +331,8 @@ STATIC INLINE BOOL OsProcessIsUserMode(const LosProcessCB *processCB)
#define LOS_PRIO_PGRP 1U
#define LOS_PRIO_USER 2U
#define OS_USER_PRIVILEGE_PROCESS_GROUP 1U
#define OS_KERNEL_PROCESS_GROUP 2U
#define OS_USER_PRIVILEGE_PROCESS_GROUP ((UINTPTR)OsGetUserInitProcess())
#define OS_KERNEL_PROCESS_GROUP ((UINTPTR)OsGetKernelInitProcess())
/*
* Process exit code
......@@ -334,9 +366,6 @@ STATIC INLINE VOID OsProcessExitCodeSet(LosProcessCB *processCB, UINT32 code)
processCB->exitCode |= ((code & 0x000000FFU) << 8U) & 0x0000FF00U; /* 8: Move 8 bits to the left, exitCode */
}
extern LosProcessCB *g_processCBArray;
extern UINT32 g_processMaxNum;
#define OS_PID_CHECK_INVALID(pid) (((UINT32)(pid)) >= g_processMaxNum)
STATIC INLINE BOOL OsProcessIDUserCheckInvalid(UINT32 pid)
......@@ -349,7 +378,7 @@ STATIC INLINE LosProcessCB *OsCurrProcessGet(VOID)
UINT32 intSave;
intSave = LOS_IntLock();
LosProcessCB *runProcess = OS_PCB_FROM_PID(OsCurrTaskGet()->processID);
LosProcessCB *runProcess = OS_PCB_FROM_TCB(OsCurrTaskGet());
LOS_IntRestore(intSave);
return runProcess;
}
......@@ -371,7 +400,7 @@ STATIC INLINE UINT32 OsProcessUserIDGet(const LosTaskCB *taskCB)
UINT32 intSave = LOS_IntLock();
UINT32 uid = OS_INVALID;
LosProcessCB *process = OS_PCB_FROM_PID(taskCB->processID);
LosProcessCB *process = OS_PCB_FROM_TCB(taskCB);
if (process->user != NULL) {
uid = process->user->userID;
}
......@@ -380,14 +409,14 @@ STATIC INLINE UINT32 OsProcessUserIDGet(const LosTaskCB *taskCB)
}
#endif
STATIC INLINE UINT32 OsProcessThreadGroupIDGet(const LosTaskCB *taskCB)
STATIC INLINE BOOL OsIsProcessThreadGroup(const LosTaskCB *taskCB)
{
return OS_PCB_FROM_PID(taskCB->processID)->threadGroupID;
return (OS_PCB_FROM_TCB(taskCB)->threadGroup == taskCB);
}
STATIC INLINE UINT32 OsProcessThreadNumberGet(const LosTaskCB *taskCB)
{
return OS_PCB_FROM_PID(taskCB->processID)->threadNumber;
return OS_PCB_FROM_TCB(taskCB)->threadNumber;
}
#ifdef LOSCFG_KERNEL_VM
......@@ -403,6 +432,17 @@ STATIC INLINE struct Vnode *OsProcessExecVnodeGet(const LosProcessCB *processCB)
return processCB->execVnode;
}
#endif
STATIC INLINE UINT32 OsGetPid(const LosProcessCB *processCB)
{
#ifdef LOSCFG_PID_CONTAINER
if (OS_PROCESS_CONTAINER_CHECK(processCB, OsCurrProcessGet())) {
return OsGetVpidFromCurrContainer(processCB);
}
#endif
return processCB->processID;
}
/*
* return immediately if no child has exited.
*/
......@@ -460,6 +500,7 @@ extern UINTPTR __user_init_entry;
extern UINTPTR __user_init_bss;
extern UINTPTR __user_init_end;
extern UINTPTR __user_init_load_addr;
extern UINT32 OsProcessInit(VOID);
extern UINT32 OsSystemProcessCreate(VOID);
extern VOID OsProcessNaturalExit(LosProcessCB *processCB, UINT32 status);
extern VOID OsProcessCBRecycleToFree(VOID);
......@@ -473,20 +514,21 @@ extern UINT32 OsExecStart(const TSK_ENTRY_FUNC entry, UINTPTR sp, UINTPTR mapBas
extern UINT32 OsSetProcessName(LosProcessCB *processCB, const CHAR *name);
extern INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 prio, UINT16 policy);
extern INT32 OsGetProcessPriority(INT32 which, INT32 pid);
extern UINT32 OsGetUserInitProcessID(VOID);
extern UINT32 OsGetIdleProcessID(VOID);
extern LosProcessCB *OsGetUserInitProcess(VOID);
extern LosProcessCB *OsGetIdleProcess(VOID);
extern INT32 OsSetProcessGroupID(UINT32 pid, UINT32 gid);
extern INT32 OsSetCurrProcessGroupID(UINT32 gid);
extern UINT32 OsGetKernelInitProcessID(VOID);
extern LosProcessCB *OsGetKernelInitProcess(VOID);
extern VOID OsSetSigHandler(UINTPTR addr);
extern UINTPTR OsGetSigHandler(VOID);
extern VOID OsWaitWakeTask(LosTaskCB *taskCB, UINT32 wakePID);
extern INT32 OsSendSignalToProcessGroup(INT32 pid, siginfo_t *info, INT32 permission);
extern INT32 OsSendSignalToAllProcess(siginfo_t *info, INT32 permission);
extern UINT32 OsProcessAddNewTask(UINT32 pid, LosTaskCB *taskCB, SchedParam *param);
extern UINT32 OsProcessAddNewTask(UINTPTR processID, LosTaskCB *taskCB, SchedParam *param, UINT32 *numCount);
extern VOID OsDeleteTaskFromProcess(LosTaskCB *taskCB);
extern VOID OsProcessThreadGroupDestroy(VOID);
extern UINT32 OsGetProcessGroupCB(UINT32 pid, UINTPTR *ppgroupLeader);
extern LosProcessCB *OsGetDefaultProcessCB(VOID);
#ifdef __cplusplus
#if __cplusplus
}
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -52,6 +52,9 @@
#include "hm_liteipc.h"
#endif
#include "los_mp.h"
#ifdef LOSCFG_KERNEL_CONTAINER
#include "los_container_pri.h"
#endif
#ifdef __cplusplus
#if __cplusplus
......@@ -100,7 +103,7 @@ typedef struct {
HPFRunqueue *hpfRunqueue;
UINT64 responseTime; /* Response time for current CPU tick interrupts */
UINT32 responseID; /* The response ID of the current CPU tick interrupt */
UINT32 idleTaskID; /* idle task id */
LosTaskCB *idleTask; /* idle task id */
UINT32 taskLockCnt; /* task lock flag */
UINT32 schedFlag; /* pending scheduler flag */
} SchedRunqueue;
......@@ -199,9 +202,9 @@ STATIC INLINE BOOL OsPreemptableInSched(VOID)
return preemptible;
}
STATIC INLINE UINT32 OsSchedRunqueueIdleGet(VOID)
STATIC INLINE LosTaskCB *OsSchedRunqueueIdleGet(VOID)
{
return OsSchedRunqueue()->idleTaskID;
return OsSchedRunqueue()->idleTask;
}
STATIC INLINE VOID OsSchedRunqueuePendingSet(VOID)
......@@ -409,7 +412,7 @@ typedef struct TagTaskCB {
UINT32 userMapSize; /**< user thread stack size ,real size : userMapSize + USER_STACK_MIN_SIZE */
FutexNode futex;
#endif
UINT32 processID; /**< Which belong process */
UINTPTR processCB; /**< Which belong process */
LOS_DL_LIST joinList; /**< join list */
LOS_DL_LIST lockList; /**< Hold the lock list */
UINTPTR waitID; /**< Wait for the PID or GID of the child process */
......@@ -422,6 +425,9 @@ typedef struct TagTaskCB {
UINTPTR pc;
UINTPTR fp;
#endif
#ifdef LOSCFG_PID_CONTAINER
PidContainer *pidContainer;
#endif
} LosTaskCB;
STATIC INLINE BOOL OsTaskIsRunning(const LosTaskCB *taskCB)
......@@ -660,7 +666,7 @@ VOID OsSchedTick(VOID);
UINT32 OsSchedInit(VOID);
VOID OsSchedStart(VOID);
VOID OsSchedRunqueueIdleInit(UINT32 idleTaskID);
VOID OsSchedRunqueueIdleInit(LosTaskCB *idleTask);
VOID OsSchedRunqueueInit(VOID);
/*
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -151,6 +151,8 @@ typedef struct {
unsigned int count;
} sig_cb;
typedef struct ProcessCB LosProcessCB;
#define SIGEV_THREAD_ID 4
int sys_sigqueue(pid_t, int, const union sigval);
......@@ -165,6 +167,7 @@ int OsSigEmptySet(sigset_t *);
int OsSigAddSet(sigset_t *, int);
int OsSigIsMember(const sigset_t *, int);
int OsKill(pid_t pid, int sig, int permission);
int OsSendSigToProcess(LosProcessCB *spcb, int sig, int permission);
int OsDispatch(pid_t pid, siginfo_t *info, int permission);
int OsSigTimedWait(sigset_t *set, siginfo_t *info, unsigned int timeout);
int OsPause(void);
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -108,7 +108,7 @@ extern UINT32 OsSwtmrGetNextTimeout(VOID);
extern BOOL OsIsSwtmrTask(const LosTaskCB *taskCB);
extern VOID OsSwtmrResponseTimeReset(UINT64 startTime);
extern UINT32 OsSwtmrInit(VOID);
extern VOID OsSwtmrRecycle(UINT32 processID);
extern VOID OsSwtmrRecycle(UINTPTR ownerID);
extern BOOL OsSwtmrWorkQueueFind(SCHED_TL_FIND_FUNC checkFunc, UINTPTR arg);
extern SPIN_LOCK_S g_swtmrSpin;
extern UINT32 OsSwtmrTaskIDGetByCpuid(UINT16 cpuid);
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -192,7 +192,12 @@ extern SPIN_LOCK_S g_taskSpin;
* <ul><li>los_task_pri.h: the header file that contains the API declaration.</li></ul>
* @see
*/
#define OS_TCB_FROM_TID(taskID) (((LosTaskCB *)g_taskCBArray) + (taskID))
#define OS_TCB_FROM_RTID(taskID) (((LosTaskCB *)g_taskCBArray) + (taskID))
#ifdef LOSCFG_PID_CONTAINER
#define OS_TCB_FROM_TID(taskID) OsGetTCBFromVtid(taskID)
#else
#define OS_TCB_FROM_TID(taskID) OS_TCB_FROM_RTID(taskID)
#endif
#ifndef LOSCFG_STACK_POINT_ALIGN_SIZE
#define LOSCFG_STACK_POINT_ALIGN_SIZE (sizeof(UINTPTR) * 2)
......@@ -255,7 +260,12 @@ STATIC INLINE BOOL OsTaskIsUnused(const LosTaskCB *taskCB)
STATIC INLINE BOOL OsTaskIsKilled(const LosTaskCB *taskCB)
{
return ((taskCB->taskStatus & OS_TASK_FLAG_EXIT_KILL) != 0);
return((taskCB->taskStatus & OS_TASK_FLAG_EXIT_KILL) != 0);
}
STATIC INLINE BOOL OsTaskIsNotDelete(const LosTaskCB *taskCB)
{
return ((taskCB->taskStatus & (OS_TASK_STATUS_UNUSED | OS_TASK_FLAG_SYSTEM_TASK | OS_TASK_FLAG_NO_DELETE)) != 0);
}
STATIC INLINE BOOL OsTaskIsUserMode(const LosTaskCB *taskCB)
......@@ -302,8 +312,8 @@ extern BOOL OsTaskCpuAffiSetUnsafe(UINT32 taskID, UINT16 newCpuAffiMask, UINT16
extern VOID OsTaskSchedule(LosTaskCB *, LosTaskCB *);
extern VOID OsTaskContextLoad(LosTaskCB *newTask);
extern VOID OsIdleTask(VOID);
extern UINT32 OsIdleTaskCreate(VOID);
extern UINT32 OsTaskInit(VOID);
extern UINT32 OsIdleTaskCreate(UINTPTR processID);
extern UINT32 OsTaskInit(UINTPTR processCB);
extern UINT32 OsShellCmdDumpTask(INT32 argc, const CHAR **argv);
extern UINT32 OsShellCmdTskInfoGet(UINT32 taskID, VOID *seqfile, UINT16 flag);
extern LosTaskCB *OsGetMainTask(VOID);
......@@ -311,18 +321,20 @@ extern VOID OsSetMainTask(VOID);
extern UINT32 OsGetIdleTaskId(VOID);
extern VOID OsTaskEntry(UINT32 taskID);
extern VOID OsTaskProcSignal(VOID);
extern UINT32 OsCreateUserTask(UINT32 processID, TSK_INIT_PARAM_S *initParam);
extern UINT32 OsCreateUserTask(UINTPTR processID, TSK_INIT_PARAM_S *initParam);
extern INT32 OsSetTaskName(LosTaskCB *taskCB, const CHAR *name, BOOL setPName);
extern VOID OsTaskCBRecycleToFree(VOID);
extern VOID OsRunningTaskToExit(LosTaskCB *runTask, UINT32 status);
extern INT32 OsUserTaskOperatePermissionsCheck(const LosTaskCB *taskCB);
extern INT32 OsUserProcessOperatePermissionsCheck(const LosTaskCB *taskCB, UINT32 processID);
extern INT32 OsUserProcessOperatePermissionsCheck(const LosTaskCB *taskCB, UINTPTR processCB);
extern INT32 OsTcbDispatch(LosTaskCB *stcb, siginfo_t *info);
extern VOID OsWriteResourceEvent(UINT32 events);
extern VOID OsWriteResourceEventUnsafe(UINT32 events);
extern UINT32 OsResourceFreeTaskCreate(VOID);
extern VOID OsTaskInsertToRecycleList(LosTaskCB *taskCB);
extern VOID OsInactiveTaskDelete(LosTaskCB *taskCB);
extern VOID OsSetMainTaskProcess(UINTPTR processCB);
extern LosTaskCB *OsGetDefaultTaskCB(VOID);
#ifdef __cplusplus
#if __cplusplus
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -135,7 +135,7 @@ STATIC INLINE VOID OsSigWaitTaskWake(LosTaskCB *taskCB, INT32 signo)
STATIC UINT32 OsPendingTaskWake(LosTaskCB *taskCB, INT32 signo)
{
if (!OsTaskIsPending(taskCB) || !OsProcessIsUserMode(OS_PCB_FROM_PID(taskCB->processID))) {
if (!OsTaskIsPending(taskCB) || !OsProcessIsUserMode(OS_PCB_FROM_TCB(taskCB))) {
return 0;
}
......@@ -381,8 +381,7 @@ int OsSigEmptySet(sigset_t *set)
/* Privilege process can't send to kernel and privilege process */
static int OsSignalPermissionToCheck(const LosProcessCB *spcb)
{
UINT32 gid = spcb->group->groupID;
UINTPTR gid = (UINTPTR)OS_GET_PGROUP_LEADER(spcb->pgroup);
if (gid == OS_KERNEL_PROCESS_GROUP) {
return -EPERM;
} else if (gid == OS_USER_PRIVILEGE_PROCESS_GROUP) {
......@@ -392,22 +391,16 @@ static int OsSignalPermissionToCheck(const LosProcessCB *spcb)
return 0;
}
int OsDispatch(pid_t pid, siginfo_t *info, int permission)
STATIC int SendSigPermissionCheck(LosProcessCB *spcb, int permission)
{
if (OsProcessIDUserCheckInvalid(pid) || pid < 0) {
if (spcb == NULL) {
return -ESRCH;
}
LosProcessCB *spcb = OS_PCB_FROM_PID(pid);
if (OsProcessIsUnused(spcb)) {
return -ESRCH;
}
/* If the process you want to kill had been inactive, but still exist. should return LOS_OK */
if (OsProcessIsInactive(spcb)) {
return LOS_OK;
}
#ifdef LOSCFG_SECURITY_CAPABILITY
LosProcessCB *current = OsCurrProcessGet();
/* Kernel process always has kill permission and user process should check permission */
......@@ -420,6 +413,50 @@ int OsDispatch(pid_t pid, siginfo_t *info, int permission)
if ((permission == OS_USER_KILL_PERMISSION) && (OsSignalPermissionToCheck(spcb) < 0)) {
return -EPERM;
}
return LOS_OK;
}
int OsSendSigToProcess(LosProcessCB *spcb, int sig, int permission)
{
siginfo_t info;
int ret = SendSigPermissionCheck(spcb, permission);
if (ret != LOS_OK) {
return ret;
}
/* If the process you want to kill had been inactive, but still exist. should return LOS_OK */
if (OsProcessIsInactive(spcb)) {
return LOS_OK;
}
if (!GOOD_SIGNO(sig)) {
return -EINVAL;
}
info.si_signo = sig;
info.si_code = SI_USER;
info.si_value.sival_ptr = NULL;
return OsSigProcessSend(spcb, &info);
}
int OsDispatch(pid_t pid, siginfo_t *info, int permission)
{
if (OsProcessIDUserCheckInvalid(pid) || pid < 0) {
return -ESRCH;
}
LosProcessCB *spcb = OS_PCB_FROM_PID(pid);
int ret = SendSigPermissionCheck(spcb, permission);
if (ret != LOS_OK) {
return ret;
}
/* If the process you want to kill had been inactive, but still exist. should return LOS_OK */
if (OsProcessIsInactive(spcb)) {
return LOS_OK;
}
return OsSigProcessSend(spcb, info);
}
......@@ -706,7 +743,7 @@ VOID *OsSaveSignalContext(VOID *sp, VOID *newSp)
sigcb->sigFlag = 0;
process->sigShare = 0;
SCHEDULER_UNLOCK(intSave);
PRINT_ERR("The signal processing function for the current process pid =%d is NULL!\n", task->processID);
PRINT_ERR("The signal processing function for the current process pid =%d is NULL!\n", process->processID);
return sp;
}
/* One pthread do the share signal */
......
此差异已折叠。
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2022-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -340,7 +340,7 @@ STATIC VOID HPFWake(LosTaskCB *resumedTask)
STATIC BOOL BasePriorityModify(SchedRunqueue *rq, LosTaskCB *taskCB, UINT16 priority)
{
LosProcessCB *processCB = OS_PCB_FROM_PID(taskCB->processID);
LosProcessCB *processCB = OS_PCB_FROM_TCB(taskCB);
BOOL needSched = FALSE;
LOS_DL_LIST_FOR_EACH_ENTRY(taskCB, &processCB->threadSiblingList, LosTaskCB, threadList) {
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -204,10 +204,10 @@ VOID OsSchedRunqueueInit(VOID)
}
}
VOID OsSchedRunqueueIdleInit(UINT32 idleTaskID)
VOID OsSchedRunqueueIdleInit(LosTaskCB *idleTask)
{
SchedRunqueue *rq = OsSchedRunqueue();
rq->idleTaskID = idleTaskID;
rq->idleTask = idleTask;
}
UINT32 OsSchedInit(VOID)
......@@ -284,7 +284,7 @@ STATIC LosTaskCB *TopTaskGet(SchedRunqueue *rq)
LosTaskCB *newTask = HPFRunqueueTopTaskGet(rq->hpfRunqueue);
if (newTask == NULL) {
newTask = OS_TCB_FROM_TID(rq->idleTaskID);
newTask = rq->idleTask;
}
newTask->ops->start(rq, newTask);
......@@ -384,7 +384,7 @@ STATIC VOID SchedTaskSwitch(SchedRunqueue *rq, LosTaskCB *runTask, LosTaskCB *ne
#endif
#ifdef LOSCFG_KERNEL_CPUP
OsCpupCycleEndStart(runTask->taskID, newTask->taskID);
OsCpupCycleEndStart(runTask, newTask);
#endif
#ifdef LOSCFG_SCHED_DEBUG
......
......@@ -145,7 +145,7 @@ UINT32 OsShellShowSchedStatistics(VOID)
for (UINT32 tid = 0; tid < g_taskMaxNum; tid++) {
LosTaskCB *taskCB = g_taskCBArray + tid;
SCHEDULER_LOCK(intSave);
if (OsTaskIsUnused(taskCB) || (taskCB->processID == OsGetIdleProcessID())) {
if (OsTaskIsUnused(taskCB) || (taskCB->processCB == (UINTPTR)OsGetIdleProcess())) {
SCHEDULER_UNLOCK(intSave);
continue;
}
......
......@@ -1420,7 +1420,7 @@ INT32 ConsoleTaskReg(INT32 consoleID, UINT32 taskID)
if (!IsShellEntryRunning(g_console[consoleID - 1]->shellEntryId)) {
g_console[consoleID - 1]->shellEntryId = taskID;
LOS_SpinUnlockRestore(&g_consoleSpin, intSave);
(VOID)OsSetCurrProcessGroupID(OsGetUserInitProcessID());
(VOID)OsSetCurrProcessGroupID(OS_USER_ROOT_PROCESS_ID);
return LOS_OK;
}
LOS_SpinUnlockRestore(&g_consoleSpin, intSave);
......
......@@ -217,7 +217,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsMain(VOID)
startNsec = LOS_CurrNanosec();
#endif
ret = OsTaskInit();
ret = OsProcessInit();
if (ret != LOS_OK) {
return ret;
}
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -120,7 +120,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdCpup(INT32 argc, const CHAR **argv)
return LOS_OK;
}
if (OsProcessIsDead(OS_PCB_FROM_PID(pid))) {
if (OsProcessIsUnused(OS_PCB_FROM_PID(pid)) || OsProcessIsDead(OS_PCB_FROM_PID(pid))) {
PRINTK("\nUnknown pid: %u\n", pid);
return LOS_OK;
}
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -33,6 +33,7 @@
#include "los_base.h"
#include "los_init.h"
#include "los_process_pri.h"
#include "los_info_pri.h"
#include "los_swtmr.h"
......@@ -44,7 +45,7 @@ LITE_OS_SEC_BSS OsIrqCpupCB *g_irqCpup = NULL;
LITE_OS_SEC_BSS STATIC UINT32 cpupMaxNum;
LITE_OS_SEC_BSS STATIC UINT16 cpupHisPos = 0; /* current Sampling point of historyTime */
LITE_OS_SEC_BSS STATIC UINT64 cpuHistoryTime[OS_CPUP_HISTORY_RECORD_NUM + 1];
LITE_OS_SEC_BSS STATIC UINT32 runningTasks[LOSCFG_KERNEL_CORE_NUM];
LITE_OS_SEC_BSS STATIC LosTaskCB *runningTasks[LOSCFG_KERNEL_CORE_NUM];
LITE_OS_SEC_BSS STATIC UINT64 cpupStartCycles = 0;
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
LITE_OS_SEC_BSS UINT64 timeInIrqSwitch[LOSCFG_KERNEL_CORE_NUM];
......@@ -85,10 +86,8 @@ LITE_OS_SEC_TEXT_INIT VOID OsCpupGuard(VOID)
{
UINT16 prevPos;
UINT32 loop;
UINT32 runTaskID;
UINT32 intSave;
UINT64 cycle, cycleIncrement;
LosTaskCB *taskCB = NULL;
LosProcessCB *processCB = NULL;
SCHEDULER_LOCK(intSave);
......@@ -108,7 +107,7 @@ LITE_OS_SEC_TEXT_INIT VOID OsCpupGuard(VOID)
#endif
for (loop = 0; loop < g_processMaxNum; loop++) {
processCB = OS_PCB_FROM_PID(loop);
processCB = OS_PCB_FROM_RPID(loop);
if (processCB->processCpup == NULL) {
continue;
}
......@@ -116,26 +115,27 @@ LITE_OS_SEC_TEXT_INIT VOID OsCpupGuard(VOID)
}
for (loop = 0; loop < g_taskMaxNum; loop++) {
taskCB = OS_TCB_FROM_TID(loop);
LosTaskCB *taskCB = OS_TCB_FROM_RTID(loop);
taskCB->taskCpup.historyTime[prevPos] = taskCB->taskCpup.allTime;
}
for (loop = 0; loop < LOSCFG_KERNEL_CORE_NUM; loop++) {
runTaskID = runningTasks[loop];
if (runTaskID == INVALID_ID) {
LosTaskCB *runTask = runningTasks[loop];
if (runTask == NULL) {
continue;
}
taskCB = OS_TCB_FROM_TID(runTaskID);
/* reacquire the cycle to prevent flip */
cycle = OsGetCpuCycle();
cycleIncrement = cycle - taskCB->taskCpup.startTime;
cycleIncrement = cycle - runTask->taskCpup.startTime;
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
cycleIncrement -= timeInIrqSwitch[loop];
#endif
taskCB->taskCpup.historyTime[prevPos] += cycleIncrement;
processCB = OS_PCB_FROM_PID(taskCB->processID);
processCB->processCpup->historyTime[prevPos] += cycleIncrement;
runTask->taskCpup.historyTime[prevPos] += cycleIncrement;
processCB = OS_PCB_FROM_TCB(runTask);
if (processCB->processCpup != NULL) {
processCB->processCpup->historyTime[prevPos] += cycleIncrement;
}
}
SCHEDULER_UNLOCK(intSave);
......@@ -177,7 +177,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsCpupInit(VOID)
#endif
for (loop = 0; loop < LOSCFG_KERNEL_CORE_NUM; loop++) {
runningTasks[loop] = INVALID_ID;
runningTasks[loop] = NULL;
}
cpupInitFlg = 1;
return LOS_OK;
......@@ -246,13 +246,12 @@ LITE_OS_SEC_TEXT_INIT VOID LOS_CpupReset(VOID)
return;
}
VOID OsCpupCycleEndStart(UINT32 runTaskID, UINT32 newTaskID)
VOID OsCpupCycleEndStart(LosTaskCB *runTask, LosTaskCB *newTask)
{
/* OsCurrTaskGet and OsCurrProcessGet are not allowed to be called. */
LosTaskCB *runTask = OS_TCB_FROM_TID(runTaskID);
OsCpupBase *runTaskCpup = &runTask->taskCpup;
OsCpupBase *newTaskCpup = (OsCpupBase *)&(OS_TCB_FROM_TID(newTaskID)->taskCpup);
OsCpupBase *processCpup = OS_PCB_FROM_PID(runTask->processID)->processCpup;
OsCpupBase *newTaskCpup = &newTask->taskCpup;
OsCpupBase *processCpup = OS_PCB_FROM_TCB(runTask)->processCpup;
UINT64 cpuCycle, cycleIncrement;
UINT16 cpuid = ArchCurrCpuid();
......@@ -275,7 +274,7 @@ VOID OsCpupCycleEndStart(UINT32 runTaskID, UINT32 newTaskID)
}
newTaskCpup->startTime = cpuCycle;
runningTasks[cpuid] = newTaskID;
runningTasks[cpuid] = newTask;
}
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsCpupGetPos(UINT16 mode, UINT16 *curPosPointer, UINT16 *prePosPointer)
......@@ -327,7 +326,6 @@ STATIC UINT32 OsHistorySysCpuUsageUnsafe(UINT16 mode)
UINT64 cpuAllCycle;
UINT16 pos;
UINT16 prePos;
UINT32 idleProcessID;
OsCpupBase *processCpup = NULL;
if (cpupInitFlg == 0) {
......@@ -337,8 +335,7 @@ STATIC UINT32 OsHistorySysCpuUsageUnsafe(UINT16 mode)
OsCpupGetPos(mode, &pos, &prePos);
cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
idleProcessID = OsGetIdleProcessID();
processCpup = OS_PCB_FROM_PID(idleProcessID)->processCpup;
processCpup = OS_PCB_FROM_PID(OS_KERNEL_IDLE_PROCESS_ID)->processCpup;
return (LOS_CPUP_PRECISION - OsCalculateCpupUsage(processCpup, pos, prePos, cpuAllCycle));
}
......@@ -444,7 +441,7 @@ STATIC UINT32 OsCpupUsageParamCheckAndReset(CPUP_INFO_S *cpupInfo, UINT32 len, U
return LOS_OK;
}
LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllProcessCpuUsageUnsafe(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
STATIC UINT32 GetAllProcessCpuUsageUnsafe(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
{
LosProcessCB *processCB = NULL;
UINT64 cpuAllCycle;
......@@ -479,47 +476,52 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_GetAllProcessCpuUsage(UINT16 mode, CPUP_INFO_S
UINT32 ret;
SCHEDULER_LOCK(intSave);
ret = OsGetAllProcessCpuUsageUnsafe(mode, cpupInfo, len);
ret = GetAllProcessCpuUsageUnsafe(mode, cpupInfo, len);
SCHEDULER_UNLOCK(intSave);
return ret;
}
LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllProcessAndTaskCpuUsageUnsafe(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
UINT32 OsGetProcessAllCpuUsageUnsafe(OsCpupBase *processCpup, ProcessInfo *processInfo)
{
UINT64 cpuAllCycle;
UINT16 pos, prePos;
UINT32 taskID;
UINT32 ret;
LosTaskCB *taskCB = NULL;
OsCpupBase *processCpupBase = NULL;
CPUP_INFO_S *processCpup = cpupInfo;
CPUP_INFO_S *taskCpup = (CPUP_INFO_S *)((UINTPTR)cpupInfo + sizeof(CPUP_INFO_S) * g_processMaxNum);
ret = OsCpupUsageParamCheckAndReset(cpupInfo, len, g_taskMaxNum + g_processMaxNum);
if (ret != LOS_OK) {
return ret;
if ((processCpup == NULL) || (processInfo == NULL)) {
return LOS_ERRNO_CPUP_PTR_ERR;
}
OsCpupGetPos(mode, &pos, &prePos);
OsCpupGetPos(CPUP_LAST_ONE_SECONDS, &pos, &prePos);
cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
processInfo->cpup1sUsage = OsCalculateCpupUsage(processCpup, pos, prePos, cpuAllCycle);
for (taskID = 0; taskID < g_taskMaxNum; taskID++) {
taskCB = OS_TCB_FROM_TID(taskID);
if (OsTaskIsUnused(taskCB)) {
continue;
}
OsCpupGetPos(CPUP_LAST_TEN_SECONDS, &pos, &prePos);
cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
processInfo->cpup10sUsage = OsCalculateCpupUsage(processCpup, pos, prePos, cpuAllCycle);
taskCpup[taskID].usage = OsCalculateCpupUsage(&taskCB->taskCpup, pos, prePos, cpuAllCycle);
taskCpup[taskID].status = OS_CPUP_USED;
if (processCpup[taskCB->processID].status == OS_CPUP_UNUSED) {
processCpupBase = OS_PCB_FROM_PID(taskCB->processID)->processCpup;
if (processCpupBase != NULL) {
processCpup[taskCB->processID].usage = OsCalculateCpupUsage(processCpupBase, pos, prePos, cpuAllCycle);
processCpup[taskCB->processID].status = OS_CPUP_USED;
}
}
OsCpupGetPos(CPUP_ALL_TIME, &pos, &prePos);
cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
processInfo->cpupAllsUsage = OsCalculateCpupUsage(processCpup, pos, prePos, cpuAllCycle);
return LOS_OK;
}
UINT32 OsGetTaskAllCpuUsageUnsafe(OsCpupBase *taskCpup, TaskInfo *taskInfo)
{
UINT64 cpuAllCycle;
UINT16 pos, prePos;
if ((taskCpup == NULL) || (taskInfo == NULL)) {
return LOS_ERRNO_CPUP_PTR_ERR;
}
OsCpupGetPos(CPUP_LAST_ONE_SECONDS, &pos, &prePos);
cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
taskInfo->cpup1sUsage = OsCalculateCpupUsage(taskCpup, pos, prePos, cpuAllCycle);
OsCpupGetPos(CPUP_LAST_TEN_SECONDS, &pos, &prePos);
cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
taskInfo->cpup10sUsage = OsCalculateCpupUsage(taskCpup, pos, prePos, cpuAllCycle);
OsCpupGetPos(CPUP_ALL_TIME, &pos, &prePos);
cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
taskInfo->cpupAllsUsage = OsCalculateCpupUsage(taskCpup, pos, prePos, cpuAllCycle);
return LOS_OK;
}
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -65,12 +65,15 @@ typedef struct {
OsCpupBase cpup; /**< irq cpup base */
} OsIrqCpupCB;
typedef struct TagTaskCB LosTaskCB;
typedef struct TagTaskInfo TaskInfo;
typedef struct TagProcessInfo ProcessInfo;
extern UINT32 OsCpupInit(VOID);
extern UINT32 OsCpupGuardCreator(VOID);
extern VOID OsCpupCycleEndStart(UINT32 runTaskID, UINT32 newTaskID);
extern UINT32 OsGetAllTaskCpuUsageUnsafe(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len);
extern UINT32 OsGetAllProcessCpuUsageUnsafe(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len);
extern UINT32 OsGetAllProcessAndTaskCpuUsageUnsafe(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len);
extern VOID OsCpupCycleEndStart(LosTaskCB *runTask, LosTaskCB *newTask);
extern UINT32 OsGetProcessAllCpuUsageUnsafe(OsCpupBase *processCpup, ProcessInfo *processInfo);
extern UINT32 OsGetTaskAllCpuUsageUnsafe(OsCpupBase *taskCpup, TaskInfo *taskInfo);
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
extern UINT32 OsGetAllIrqCpuUsageUnsafe(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len);
extern VOID OsCpupIrqStart(UINT16);
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -316,7 +316,6 @@ STATIC VOID LiteIpcPoolDelete(ProcIpcInfo *ipcInfo, UINT32 processID)
LITE_OS_SEC_TEXT UINT32 LiteIpcPoolDestroy(UINT32 processID)
{
LosProcessCB *pcb = OS_PCB_FROM_PID(processID);
if (pcb->ipcInfo == NULL) {
return LOS_NOK;
}
......@@ -340,10 +339,10 @@ LITE_OS_SEC_TEXT_INIT STATIC IpcTaskInfo *LiteIpcTaskInit(VOID)
}
/* Only when kernenl no longer access ipc node content, can user free the ipc node */
LITE_OS_SEC_TEXT STATIC VOID EnableIpcNodeFreeByUser(UINT32 processID, VOID *buf)
LITE_OS_SEC_TEXT STATIC VOID EnableIpcNodeFreeByUser(LosProcessCB *pcb, VOID *buf)
{
UINT32 intSave;
ProcIpcInfo *ipcInfo = OS_PCB_FROM_PID(processID)->ipcInfo;
ProcIpcInfo *ipcInfo = pcb->ipcInfo;
IpcUsedNode *node = (IpcUsedNode *)malloc(sizeof(IpcUsedNode));
if (node != NULL) {
node->ptr = buf;
......@@ -353,26 +352,26 @@ LITE_OS_SEC_TEXT STATIC VOID EnableIpcNodeFreeByUser(UINT32 processID, VOID *buf
}
}
LITE_OS_SEC_TEXT STATIC VOID *LiteIpcNodeAlloc(UINT32 processID, UINT32 size)
LITE_OS_SEC_TEXT STATIC VOID *LiteIpcNodeAlloc(LosProcessCB *pcb, UINT32 size)
{
VOID *ptr = LOS_MemAlloc(OS_PCB_FROM_PID(processID)->ipcInfo->pool.kvaddr, size);
VOID *ptr = LOS_MemAlloc(pcb->ipcInfo->pool.kvaddr, size);
PRINT_INFO("LiteIpcNodeAlloc pid:%d, pool:%x buf:%x size:%d\n",
processID, OS_PCB_FROM_PID(processID)->ipcInfo->pool.kvaddr, ptr, size);
pcb->processID, pcb->ipcInfo->pool.kvaddr, ptr, size);
return ptr;
}
LITE_OS_SEC_TEXT STATIC UINT32 LiteIpcNodeFree(UINT32 processID, VOID *buf)
LITE_OS_SEC_TEXT STATIC UINT32 LiteIpcNodeFree(LosProcessCB *pcb, VOID *buf)
{
PRINT_INFO("LiteIpcNodeFree pid:%d, pool:%x buf:%x\n",
processID, OS_PCB_FROM_PID(processID)->ipcInfo->pool.kvaddr, buf);
return LOS_MemFree(OS_PCB_FROM_PID(processID)->ipcInfo->pool.kvaddr, buf);
pcb->processID, pcb->ipcInfo->pool.kvaddr, buf);
return LOS_MemFree(pcb->ipcInfo->pool.kvaddr, buf);
}
LITE_OS_SEC_TEXT STATIC BOOL IsIpcNode(UINT32 processID, const VOID *buf)
LITE_OS_SEC_TEXT STATIC BOOL IsIpcNode(LosProcessCB *pcb, const VOID *buf)
{
IpcUsedNode *node = NULL;
UINT32 intSave;
ProcIpcInfo *ipcInfo = OS_PCB_FROM_PID(processID)->ipcInfo;
ProcIpcInfo *ipcInfo = pcb->ipcInfo;
IPC_LOCK(intSave);
LOS_DL_LIST_FOR_EACH_ENTRY(node, &ipcInfo->ipcUsedNodelist, IpcUsedNode, list) {
if (node->ptr == buf) {
......@@ -386,16 +385,16 @@ LITE_OS_SEC_TEXT STATIC BOOL IsIpcNode(UINT32 processID, const VOID *buf)
return FALSE;
}
LITE_OS_SEC_TEXT STATIC INTPTR GetIpcUserAddr(UINT32 processID, INTPTR kernelAddr)
LITE_OS_SEC_TEXT STATIC INTPTR GetIpcUserAddr(const LosProcessCB *pcb, INTPTR kernelAddr)
{
IpcPool pool = OS_PCB_FROM_PID(processID)->ipcInfo->pool;
IpcPool pool = pcb->ipcInfo->pool;
INTPTR offset = (INTPTR)(pool.uvaddr) - (INTPTR)(pool.kvaddr);
return kernelAddr + offset;
}
LITE_OS_SEC_TEXT STATIC INTPTR GetIpcKernelAddr(UINT32 processID, INTPTR userAddr)
LITE_OS_SEC_TEXT STATIC INTPTR GetIpcKernelAddr(const LosProcessCB *pcb, INTPTR userAddr)
{
IpcPool pool = OS_PCB_FROM_PID(processID)->ipcInfo->pool;
IpcPool pool = pcb->ipcInfo->pool;
INTPTR offset = (INTPTR)(pool.uvaddr) - (INTPTR)(pool.kvaddr);
return userAddr - offset;
}
......@@ -409,8 +408,8 @@ LITE_OS_SEC_TEXT STATIC UINT32 CheckUsedBuffer(const VOID *node, IpcListNode **o
((INTPTR)node > (INTPTR)(pool.uvaddr) + pool.poolSize)) {
return -EINVAL;
}
ptr = (VOID *)GetIpcKernelAddr(pcb->processID, (INTPTR)(node));
if (IsIpcNode(pcb->processID, ptr) != TRUE) {
ptr = (VOID *)GetIpcKernelAddr(pcb, (INTPTR)(node));
if (IsIpcNode(pcb, ptr) != TRUE) {
return -EFAULT;
}
*outPtr = (IpcListNode *)ptr;
......@@ -485,13 +484,12 @@ LITE_OS_SEC_TEXT STATIC UINT32 AddServiceAccess(UINT32 taskID, UINT32 serviceHan
}
LosTaskCB *tcb = OS_TCB_FROM_TID(serviceTid);
UINT32 processID = OS_TCB_FROM_TID(taskID)->processID;
LosProcessCB *pcb = OS_PCB_FROM_PID(processID);
LosProcessCB *pcb = OS_PCB_FROM_TID(taskID);
if ((tcb->ipcTaskInfo == NULL) || (pcb->ipcInfo == NULL)) {
PRINT_ERR("Liteipc AddServiceAccess ipc not create! pid %u tid %u\n", processID, tcb->taskID);
PRINT_ERR("Liteipc AddServiceAccess ipc not create! pid %u tid %u\n", pcb->processID, tcb->taskID);
return -EINVAL;
}
tcb->ipcTaskInfo->accessMap[processID] = TRUE;
tcb->ipcTaskInfo->accessMap[pcb->processID] = TRUE;
pcb->ipcInfo->access[serviceTid] = TRUE;
return LOS_OK;
}
......@@ -499,7 +497,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 AddServiceAccess(UINT32 taskID, UINT32 serviceHan
LITE_OS_SEC_TEXT STATIC BOOL HasServiceAccess(UINT32 serviceHandle)
{
UINT32 serviceTid = 0;
UINT32 curProcessID = LOS_GetCurrProcessID();
LosProcessCB *curr = OsCurrProcessGet();
UINT32 ret;
if (serviceHandle >= MAX_SERVICE_NUM) {
return FALSE;
......@@ -512,15 +510,16 @@ LITE_OS_SEC_TEXT STATIC BOOL HasServiceAccess(UINT32 serviceHandle)
PRINT_ERR("Liteipc HasServiceAccess GetTid failed\n");
return FALSE;
}
if (OS_TCB_FROM_TID(serviceTid)->processID == curProcessID) {
LosTaskCB *taskCB = OS_TCB_FROM_TID(serviceTid);
if (taskCB->processCB == (UINTPTR)curr) {
return TRUE;
}
if (OS_TCB_FROM_TID(serviceTid)->ipcTaskInfo == NULL) {
if (taskCB->ipcTaskInfo == NULL) {
return FALSE;
}
return OS_TCB_FROM_TID(serviceTid)->ipcTaskInfo->accessMap[curProcessID];
return taskCB->ipcTaskInfo->accessMap[curr->processID];
}
LITE_OS_SEC_TEXT STATIC UINT32 SetIpcTask(VOID)
......@@ -541,12 +540,12 @@ LITE_OS_SEC_TEXT BOOL IsIpcTaskSet(VOID)
return TRUE;
}
LITE_OS_SEC_TEXT STATIC UINT32 GetIpcTaskID(UINT32 processID, UINT32 *ipcTaskID)
LITE_OS_SEC_TEXT STATIC UINT32 GetIpcTaskID(LosProcessCB *pcb, UINT32 *ipcTaskID)
{
if (OS_PCB_FROM_PID(processID)->ipcInfo->ipcTaskID == INVAILD_ID) {
if (pcb->ipcInfo->ipcTaskID == INVAILD_ID) {
return LOS_NOK;
}
*ipcTaskID = OS_PCB_FROM_PID(processID)->ipcInfo->ipcTaskID;
*ipcTaskID = pcb->ipcInfo->ipcTaskID;
return LOS_OK;
}
......@@ -564,7 +563,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 SendDeathMsg(UINT32 processID, UINT32 serviceHand
pcb->ipcInfo->access[serviceHandle] = FALSE;
ret = GetIpcTaskID(processID, &ipcTaskID);
ret = GetIpcTaskID(pcb, &ipcTaskID);
if (ret != LOS_OK) {
return -EINVAL;
}
......@@ -593,7 +592,7 @@ LITE_OS_SEC_TEXT VOID LiteIpcRemoveServiceHandle(UINT32 taskID)
LOS_DL_LIST *listHead = NULL;
LOS_DL_LIST *listNode = NULL;
IpcListNode *node = NULL;
UINT32 processID = taskCB->processID;
LosProcessCB *pcb = OS_PCB_FROM_TCB(taskCB);
listHead = &(ipcTaskInfo->msgListHead);
do {
......@@ -607,12 +606,12 @@ LITE_OS_SEC_TEXT VOID LiteIpcRemoveServiceHandle(UINT32 taskID)
node = LOS_DL_LIST_ENTRY(listNode, IpcListNode, listNode);
SCHEDULER_UNLOCK(intSave);
(VOID)HandleSpecialObjects(taskCB->taskID, node, TRUE);
(VOID)LiteIpcNodeFree(processID, (VOID *)node);
(VOID)LiteIpcNodeFree(pcb, (VOID *)node);
}
} while (1);
ipcTaskInfo->accessMap[processID] = FALSE;
for (j = 0; j < MAX_SERVICE_NUM; j++) {
ipcTaskInfo->accessMap[pcb->processID] = FALSE;
for (j = 0; j < LOSCFG_BASE_CORE_PROCESS_LIMIT; j++) {
if (ipcTaskInfo->accessMap[j] == TRUE) {
ipcTaskInfo->accessMap[j] = FALSE;
(VOID)SendDeathMsg(j, taskCB->taskID);
......@@ -630,7 +629,7 @@ LITE_OS_SEC_TEXT VOID LiteIpcRemoveServiceHandle(UINT32 taskID)
(VOID)LOS_MuxUnlock(&g_serviceHandleMapMux);
/* run deathHandler */
if (i < MAX_SERVICE_NUM) {
for (j = 0; j < MAX_SERVICE_NUM; j++) {
for (j = 0; j < LOSCFG_BASE_CORE_PROCESS_LIMIT; j++) {
if (ipcTaskInfo->accessMap[j] == TRUE) {
(VOID)SendDeathMsg(j, i);
}
......@@ -686,10 +685,10 @@ LITE_OS_SEC_TEXT STATIC BOOL IsCmsTask(UINT32 taskID)
BOOL ret;
(VOID)LOS_MuxLock(&g_serviceHandleMapMux, LOS_WAIT_FOREVER);
#if (USE_TASKID_AS_HANDLE == 1)
ret = IsCmsSet() ? (OS_TCB_FROM_TID(taskID)->processID == OS_TCB_FROM_TID(g_cmsTask.taskID)->processID) : FALSE;
ret = IsCmsSet() ? (OS_TCB_FROM_TID(taskID)->processCB == OS_TCB_FROM_TID(g_cmsTask.taskID)->processCB) : FALSE;
#else
ret = IsCmsSet() ? (OS_TCB_FROM_TID(taskID)->processID ==
OS_TCB_FROM_TID(g_serviceHandleMap[0].taskID)->processID) : FALSE;
ret = IsCmsSet() ? (OS_TCB_FROM_TID(taskID)->processCB ==
OS_TCB_FROM_TID(g_serviceHandleMap[0].taskID)->processCB) : FALSE;
#endif
(VOID)LOS_MuxUnlock(&g_serviceHandleMapMux);
return ret;
......@@ -702,29 +701,29 @@ LITE_OS_SEC_TEXT STATIC BOOL IsTaskAlive(UINT32 taskID)
return FALSE;
}
tcb = OS_TCB_FROM_TID(taskID);
if (!OsTaskIsUserMode(tcb)) {
return FALSE;
}
if (OsTaskIsUnused(tcb)) {
return FALSE;
}
if (OsTaskIsInactive(tcb)) {
return FALSE;
}
if (!OsTaskIsUserMode(tcb)) {
return FALSE;
}
return TRUE;
}
LITE_OS_SEC_TEXT STATIC UINT32 HandleFd(UINT32 processID, SpecialObj *obj, BOOL isRollback)
LITE_OS_SEC_TEXT STATIC UINT32 HandleFd(const LosProcessCB *pcb, SpecialObj *obj, BOOL isRollback)
{
int ret;
if (isRollback == FALSE) {
ret = CopyFdToProc(obj->content.fd, processID);
ret = CopyFdToProc(obj->content.fd, pcb->processID);
if (ret < 0) {
return ret;
}
obj->content.fd = ret;
} else {
ret = CloseProcFd(obj->content.fd, processID);
ret = CloseProcFd(obj->content.fd, pcb->processID);
if (ret < 0) {
return ret;
}
......@@ -733,7 +732,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 HandleFd(UINT32 processID, SpecialObj *obj, BOOL
return LOS_OK;
}
LITE_OS_SEC_TEXT STATIC UINT32 HandlePtr(UINT32 processID, SpecialObj *obj, BOOL isRollback)
LITE_OS_SEC_TEXT STATIC UINT32 HandlePtr(LosProcessCB *pcb, SpecialObj *obj, BOOL isRollback)
{
VOID *buf = NULL;
UINT32 ret;
......@@ -745,20 +744,20 @@ LITE_OS_SEC_TEXT STATIC UINT32 HandlePtr(UINT32 processID, SpecialObj *obj, BOOL
PRINT_ERR("Liteipc Bad ptr address\n");
return -EINVAL;
}
buf = LiteIpcNodeAlloc(processID, obj->content.ptr.buffSz);
buf = LiteIpcNodeAlloc(pcb, obj->content.ptr.buffSz);
if (buf == NULL) {
PRINT_ERR("Liteipc DealPtr alloc mem failed\n");
return -EINVAL;
}
ret = copy_from_user(buf, obj->content.ptr.buff, obj->content.ptr.buffSz);
if (ret != LOS_OK) {
LiteIpcNodeFree(processID, buf);
LiteIpcNodeFree(pcb, buf);
return ret;
}
obj->content.ptr.buff = (VOID *)GetIpcUserAddr(processID, (INTPTR)buf);
EnableIpcNodeFreeByUser(processID, (VOID *)buf);
obj->content.ptr.buff = (VOID *)GetIpcUserAddr(pcb, (INTPTR)buf);
EnableIpcNodeFreeByUser(pcb, (VOID *)buf);
} else {
(VOID)LiteIpcNodeFree(processID, (VOID *)GetIpcKernelAddr(processID, (INTPTR)obj->content.ptr.buff));
(VOID)LiteIpcNodeFree(pcb, (VOID *)GetIpcKernelAddr(pcb, (INTPTR)obj->content.ptr.buff));
}
return LOS_OK;
}
......@@ -810,13 +809,13 @@ LITE_OS_SEC_TEXT STATIC UINT32 HandleSvc(UINT32 dstTid, SpecialObj *obj, BOOL is
LITE_OS_SEC_TEXT STATIC UINT32 HandleObj(UINT32 dstTid, SpecialObj *obj, BOOL isRollback)
{
UINT32 ret;
UINT32 processID = OS_TCB_FROM_TID(dstTid)->processID;
LosProcessCB *pcb = OS_PCB_FROM_TID(dstTid);
switch (obj->type) {
case OBJ_FD:
ret = HandleFd(processID, obj, isRollback);
ret = HandleFd(pcb, obj, isRollback);
break;
case OBJ_PTR:
ret = HandlePtr(processID, obj, isRollback);
ret = HandlePtr(pcb, obj, isRollback);
break;
case OBJ_SVC:
ret = HandleSvc(dstTid, (SpecialObj *)obj, isRollback);
......@@ -948,8 +947,8 @@ LITE_OS_SEC_TEXT STATIC UINT32 CopyDataFromUser(IpcListNode *node, UINT32 bufSz,
LITE_OS_SEC_TEXT STATIC BOOL IsValidReply(const IpcContent *content)
{
UINT32 curProcessID = LOS_GetCurrProcessID();
IpcListNode *node = (IpcListNode *)GetIpcKernelAddr(curProcessID, (INTPTR)(content->buffToFree));
LosProcessCB *curr = OsCurrProcessGet();
IpcListNode *node = (IpcListNode *)GetIpcKernelAddr(curr, (INTPTR)(content->buffToFree));
IpcMsg *requestMsg = &node->msg;
IpcMsg *replyMsg = content->outMsg;
UINT32 reqDstTid = 0;
......@@ -959,7 +958,7 @@ LITE_OS_SEC_TEXT STATIC BOOL IsValidReply(const IpcContent *content)
(replyMsg->timestamp != requestMsg->timestamp) ||
(replyMsg->target.handle != requestMsg->taskID) ||
(GetTid(requestMsg->target.handle, &reqDstTid) != 0) ||
(OS_TCB_FROM_TID(reqDstTid)->processID != curProcessID)) {
(OS_TCB_FROM_TID(reqDstTid)->processCB != (UINTPTR)curr)) {
return FALSE;
}
return TRUE;
......@@ -1012,7 +1011,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 CheckPara(IpcContent *content, UINT32 *dstTid)
}
#endif
OsHookCall(LOS_HOOK_TYPE_IPC_WRITE_DROP, msg, *dstTid,
(*dstTid == INVAILD_ID) ? INVAILD_ID : OS_TCB_FROM_TID(*dstTid)->processID, 0);
(*dstTid == INVAILD_ID) ? INVAILD_ID : OS_PCB_FROM_TID(*dstTid)->processID, 0);
PRINT_ERR("Liteipc A timeout reply, request timestamp:%lld, now:%lld\n", msg->timestamp, now);
return -ETIME;
}
......@@ -1049,14 +1048,14 @@ LITE_OS_SEC_TEXT STATIC UINT32 LiteIpcWrite(IpcContent *content)
}
LosTaskCB *tcb = OS_TCB_FROM_TID(dstTid);
LosProcessCB *pcb = OS_PCB_FROM_PID(tcb->processID);
LosProcessCB *pcb = OS_PCB_FROM_TCB(tcb);
if (pcb->ipcInfo == NULL) {
PRINT_ERR("pid %u Liteipc not create\n", tcb->processID);
PRINT_ERR("pid %u Liteipc not create\n", pcb->processID);
return -EINVAL;
}
UINT32 bufSz = sizeof(IpcListNode) + msg->dataSz + msg->spObjNum * sizeof(UINT32);
IpcListNode *buf = (IpcListNode *)LiteIpcNodeAlloc(tcb->processID, bufSz);
IpcListNode *buf = (IpcListNode *)LiteIpcNodeAlloc(pcb, bufSz);
if (buf == NULL) {
PRINT_ERR("%s, %d\n", __FUNCTION__, __LINE__);
return -ENOMEM;
......@@ -1079,7 +1078,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 LiteIpcWrite(IpcContent *content)
/* add data to list and wake up dest task */
SCHEDULER_LOCK(intSave);
LOS_ListTailInsert(&(tcb->ipcTaskInfo->msgListHead), &(buf->listNode));
OsHookCall(LOS_HOOK_TYPE_IPC_WRITE, &buf->msg, dstTid, tcb->processID, tcb->waitFlag);
OsHookCall(LOS_HOOK_TYPE_IPC_WRITE, &buf->msg, dstTid, pcb->processID, tcb->waitFlag);
if (tcb->waitFlag == OS_TASK_WAIT_LITEIPC) {
OsTaskWakeClearPendMask(tcb);
tcb->ops->wake(tcb);
......@@ -1091,7 +1090,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 LiteIpcWrite(IpcContent *content)
}
return LOS_OK;
ERROR_COPY:
LiteIpcNodeFree(OS_TCB_FROM_TID(dstTid)->processID, buf);
LiteIpcNodeFree(pcb, buf);
return ret;
}
......@@ -1138,7 +1137,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 CheckRecievedMsg(IpcListNode *node, IpcContent *c
if (ret != LOS_OK) {
OsHookCall(LOS_HOOK_TYPE_IPC_READ_DROP, &node->msg, tcb->waitFlag);
(VOID)HandleSpecialObjects(LOS_CurTaskIDGet(), node, TRUE);
(VOID)LiteIpcNodeFree(LOS_GetCurrProcessID(), (VOID *)node);
(VOID)LiteIpcNodeFree(OsCurrProcessGet(), (VOID *)node);
} else {
OsHookCall(LOS_HOOK_TYPE_IPC_READ, &node->msg, tcb->waitFlag);
}
......@@ -1194,10 +1193,10 @@ LITE_OS_SEC_TEXT STATIC UINT32 LiteIpcRead(IpcContent *content)
}
}
} while (1);
node->msg.data = (VOID *)GetIpcUserAddr(LOS_GetCurrProcessID(), (INTPTR)(node->msg.data));
node->msg.offsets = (VOID *)GetIpcUserAddr(LOS_GetCurrProcessID(), (INTPTR)(node->msg.offsets));
content->inMsg = (VOID *)GetIpcUserAddr(LOS_GetCurrProcessID(), (INTPTR)(&(node->msg)));
EnableIpcNodeFreeByUser(LOS_GetCurrProcessID(), (VOID *)node);
node->msg.data = (VOID *)GetIpcUserAddr(OsCurrProcessGet(), (INTPTR)(node->msg.data));
node->msg.offsets = (VOID *)GetIpcUserAddr(OsCurrProcessGet(), (INTPTR)(node->msg.offsets));
content->inMsg = (VOID *)GetIpcUserAddr(OsCurrProcessGet(), (INTPTR)(&(node->msg)));
EnableIpcNodeFreeByUser(OsCurrProcessGet(), (VOID *)node);
return LOS_OK;
}
......@@ -1248,7 +1247,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 LiteIpcMsgHandle(IpcContent *con)
}
BUFFER_FREE:
if (nodeNeedFree != NULL) {
UINT32 freeRet = LiteIpcNodeFree(LOS_GetCurrProcessID(), nodeNeedFree);
UINT32 freeRet = LiteIpcNodeFree(OsCurrProcessGet(), nodeNeedFree);
ret = (freeRet == LOS_OK) ? ret : freeRet;
}
if (ret != LOS_OK) {
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -75,7 +75,7 @@ typedef struct {
typedef struct {
LOS_DL_LIST msgListHead;
BOOL accessMap[LOSCFG_BASE_CORE_TSK_LIMIT];
BOOL accessMap[LOSCFG_BASE_CORE_PROCESS_LIMIT];
} IpcTaskInfo;
typedef enum {
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -275,7 +275,7 @@ typedef struct tagSwTmrCtrl {
UINTPTR uwArg; /**< Parameter passed in when the callback function
that handles software timer timeout is called */
SWTMR_PROC_FUNC pfnHandler; /**< Callback function that handles software timer timeout */
UINT32 uwOwnerPid; /** Owner of this software timer */
UINTPTR uwOwnerPid; /** Owner of this software timer */
UINT64 startTime; /**< Software timer start time */
} SWTMR_CTRL_S;
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -512,7 +512,7 @@ typedef struct tagTskInitParam {
UINT32 uwResved; /**< It is automatically deleted if set to LOS_TASK_STATUS_DETACHED.
It is unable to be deleted if set to 0. */
UINT16 consoleID; /**< The console id of task belongs */
UINT32 processID;
UINTPTR processID;
UserTaskParam userParam;
} TSK_INIT_PARAM_S;
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -84,6 +84,7 @@ extern int SysWait(int pid, USER int *status, int options, void *rusage);
extern int SysWaitid(idtype_t type, int pid, USER siginfo_t *info, int options, void *rusage);
extern int SysFork(void);
extern int SysVfork(void);
extern int SysClone(int flags, void *stack, int *parentTid, unsigned long tls, int *childTid);
extern unsigned int SysGetPID(void);
extern unsigned int SysGetPPID(void);
extern int SysSetGroupID(unsigned int gid);
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -45,14 +45,15 @@
static int OsPermissionToCheck(unsigned int pid, unsigned int who)
{
int ret = LOS_GetProcessGroupID(pid);
if (ret < 0) {
return ret;
} else if (ret == OS_KERNEL_PROCESS_GROUP) {
uintptr_t pgroupID = 0;
unsigned int ret = OsGetProcessGroupCB(pid, &pgroupID);
if (ret != 0) {
return -ret;
} else if (pgroupID == OS_KERNEL_PROCESS_GROUP) {
return -EPERM;
} else if ((ret == OS_USER_PRIVILEGE_PROCESS_GROUP) && (pid != who)) {
} else if ((pgroupID == OS_USER_PRIVILEGE_PROCESS_GROUP) && (pid != who)) {
return -EPERM;
} else if (pid == OsGetUserInitProcessID()) {
} else if ((UINTPTR)OS_PCB_FROM_PID(pid) == OS_USER_PRIVILEGE_PROCESS_GROUP) {
return -EPERM;
}
......@@ -132,6 +133,10 @@ int SysSchedGetScheduler(int id, int flag)
return (int)param.policy;
}
if (id == 0) {
id = (int)LOS_GetCurrProcessID();
}
return LOS_GetProcessScheduler(id);
}
......@@ -355,9 +360,23 @@ int SysVfork(void)
return OsClone(CLONE_VFORK, 0, 0);
}
int SysClone(int flags, void *stack, int *parentTid, unsigned long tls, int *childTid)
{
(void)parentTid;
(void)tls;
(void)childTid;
return OsClone((UINT32)flags, (UINTPTR)stack, 0);
}
unsigned int SysGetPPID(void)
{
return OsCurrProcessGet()->parentProcessID;
#ifdef LOSCFG_PID_CONTAINER
if (OsCurrProcessGet()->processID == OS_USER_ROOT_PROCESS_ID) {
return 0;
}
#endif
return OsCurrProcessGet()->parentProcess->processID;
}
unsigned int SysGetPID(void)
......@@ -375,8 +394,6 @@ int SysSetProcessGroupID(unsigned int pid, unsigned int gid)
if (gid == 0) {
gid = pid;
} else if (gid <= OS_USER_PRIVILEGE_PROCESS_GROUP) {
return -EPERM;
}
ret = OsPermissionToCheck(pid, gid);
......@@ -908,7 +925,7 @@ int SysSetThreadArea(const char *area)
LosTaskCB *taskCB = OsCurrTaskGet();
SCHEDULER_LOCK(intSave);
LosProcessCB *processCB = OS_PCB_FROM_PID(taskCB->processID);
LosProcessCB *processCB = OS_PCB_FROM_TCB(taskCB);
if (processCB->processMode != OS_USER_MODE) {
ret = EPERM;
goto OUT;
......@@ -1031,8 +1048,12 @@ static int SchedAffinityParameterPreprocess(int id, int flag, unsigned int *task
if (OS_PID_CHECK_INVALID(id)) {
return -ESRCH;
}
*taskID = (id == 0) ? (OsCurrTaskGet()->taskID) : (OS_PCB_FROM_PID((UINT32)id)->threadGroupID);
*processID = (id == 0) ? (OS_TCB_FROM_TID(*taskID)->processID) : id;
LosProcessCB *ProcessCB = OS_PCB_FROM_PID((UINT32)id);
if (ProcessCB->threadGroup == NULL) {
return -ESRCH;
}
*taskID = (id == 0) ? (OsCurrTaskGet()->taskID) : (ProcessCB->threadGroup->taskID);
*processID = (id == 0) ? (OS_PCB_FROM_TID(*taskID)->processID) : id;
} else {
if (OS_TID_CHECK_INVALID(id)) {
return -ESRCH;
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -139,6 +139,7 @@ SYSCALL_HAND_DEF(__NR_shellexec, SysShellExec, UINT32, ARG_NUM_2)
SYSCALL_HAND_DEF(__NR_exit, SysThreadExit, void, ARG_NUM_1)
SYSCALL_HAND_DEF(__NR_fork, SysFork, int, ARG_NUM_0)
SYSCALL_HAND_DEF(__NR_vfork, SysVfork, int, ARG_NUM_0)
SYSCALL_HAND_DEF(__NR_clone, SysClone, int, ARG_NUM_5)
SYSCALL_HAND_DEF(__NR_getpid, SysGetPID, unsigned int, ARG_NUM_0)
SYSCALL_HAND_DEF(__NR_pause, SysPause, int, ARG_NUM_0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册