fix: 修复容器内存泄露问题
1.修复内存泄露 2.修复获取内核信息单位、描述错误 Close #I6CD5C Signed-off-by: zhushengle <zhushengle@huawei.com> Change-Id: I875bec616064517b21af8e69ef8d6e177ec01ce1
This commit is contained in:
@@ -129,6 +129,10 @@ UINT32 OsCopyContainers(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
flags &= ~CLONE_NEWTIME;
|
||||
#endif
|
||||
|
||||
if (!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET | CLONE_NEWTIME))) {
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
if (parent->container->pidContainer != parent->container->pidForChildContainer) {
|
||||
@@ -159,47 +163,45 @@ COPY_CONTAINERS:
|
||||
return CopyContainers(flags, child, parent, processID);
|
||||
}
|
||||
|
||||
#ifndef LOSCFG_PID_CONTAINER
|
||||
STATIC VOID ContainersFree(LosProcessCB *processCB)
|
||||
VOID OsContainerFree(LosProcessCB *processCB)
|
||||
{
|
||||
UINT32 intSave;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LOS_AtomicDec(&processCB->container->rc);
|
||||
if (LOS_AtomicRead(&processCB->container->rc) == 0) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, processCB->container);
|
||||
processCB->container = NULL;
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
}
|
||||
#endif
|
||||
|
||||
VOID OsContainersDestroy(LosProcessCB *processCB)
|
||||
{
|
||||
/* All processes in the container must be destroyed before the container is destroyed. */
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
if (processCB->processID == OS_USER_ROOT_PROCESS_ID) {
|
||||
OsPidContainersDestroyAllProcess(processCB);
|
||||
OsPidContainerDestroyAllProcess(processCB);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
OsUtsContainersDestroy(processCB->container);
|
||||
OsUtsContainerDestroy(processCB->container);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
OsMntContainersDestroy(processCB->container);
|
||||
OsMntContainerDestroy(processCB->container);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
OsIpcContainersDestroy(processCB->container);
|
||||
OsIpcContainerDestroy(processCB->container);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
OsTimeContainersDestroy(processCB);
|
||||
OsTimeContainerDestroy(processCB);
|
||||
#endif
|
||||
|
||||
#ifndef LOSCFG_PID_CONTAINER
|
||||
ContainersFree(processCB);
|
||||
UINT32 intSave;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
OsContainerFree(processCB);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -240,50 +242,43 @@ UINT32 OsGetContainerID(Container *container, ContainerType type)
|
||||
return OS_INVALID_VALUE;
|
||||
}
|
||||
|
||||
STATIC VOID UnshareDeinitContainerCommon(UINT32 flags, Container *container)
|
||||
{
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
if ((flags & CLONE_NEWUTS) != 0) {
|
||||
OsUtsContainersDestroy(container);
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
if ((flags & CLONE_NEWNS) != 0) {
|
||||
OsMntContainersDestroy(container);
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
if ((flags & CLONE_NEWIPC) != 0) {
|
||||
OsIpcContainersDestroy(container);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC VOID UnshareDeinitContainer(UINT32 flags, Container *container)
|
||||
STATIC VOID UnshareDeInitContainer(UINT32 flags, Container *container)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
if ((container->pidForChildContainer != NULL) && (container->pidForChildContainer != container->pidContainer)) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, container->pidForChildContainer);
|
||||
container->pidForChildContainer = NULL;
|
||||
container->pidContainer = NULL;
|
||||
}
|
||||
UnshareDeInitPidContainer(container);
|
||||
#endif
|
||||
|
||||
UnshareDeinitContainerCommon(flags, container);
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
if ((flags & CLONE_NEWUTS) != 0) {
|
||||
OsUtsContainerDestroy(container);
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
if ((flags & CLONE_NEWNS) != 0) {
|
||||
OsMntContainerDestroy(container);
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
if ((flags & CLONE_NEWIPC) != 0) {
|
||||
OsIpcContainerDestroy(container);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
if ((container->timeForChildContainer != NULL) && (container->timeForChildContainer != container->timeContainer)) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, container->timeForChildContainer);
|
||||
container->timeForChildContainer = NULL;
|
||||
container->timeContainer = NULL;
|
||||
}
|
||||
UnshareDeInitTimeContainer(container);
|
||||
#endif
|
||||
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, container);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LOS_AtomicDec(&container->rc);
|
||||
if (LOS_AtomicRead(&container->rc) == 0) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, container);
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
}
|
||||
|
||||
STATIC UINT32 CreateNewContainers(UINT32 flags, LosProcessCB *curr, Container *newContainer)
|
||||
@@ -328,7 +323,9 @@ INT32 OsUnshare(UINT32 flags)
|
||||
UINT32 intSave;
|
||||
LosProcessCB *curr = OsCurrProcessGet();
|
||||
Container *oldContainer = curr->container;
|
||||
if (!(flags & (CLONE_NEWPID | CLONE_NEWTIME | CLONE_NEWUTS | CLONE_NEWNS | CLONE_NEWIPC))) {
|
||||
UINT32 unshareFlags = CLONE_NEWPID | CLONE_NEWTIME | CLONE_NEWUTS | CLONE_NEWNS | CLONE_NEWIPC;
|
||||
|
||||
if (!(flags & unshareFlags) || ((flags & (~unshareFlags)) != 0)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -347,18 +344,11 @@ INT32 OsUnshare(UINT32 flags)
|
||||
curr->container = newContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
UnshareDeinitContainerCommon(flags, oldContainer);
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LOS_AtomicDec(&oldContainer->rc);
|
||||
if (LOS_AtomicRead(&oldContainer->rc) == 0) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, oldContainer);
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
UnshareDeInitContainer(flags, oldContainer);
|
||||
return LOS_OK;
|
||||
|
||||
EXIT:
|
||||
UnshareDeinitContainer(flags, newContainer);
|
||||
UnshareDeInitContainer(flags, newContainer);
|
||||
return -ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -148,7 +148,7 @@ UINT32 OsUnshareIpcContainer(UINTPTR flags, LosProcessCB *curr, Container *newCo
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsIpcContainersDestroy(Container *container)
|
||||
VOID OsIpcContainerDestroy(Container *container)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (container == NULL) {
|
||||
@@ -157,19 +157,23 @@ VOID OsIpcContainersDestroy(Container *container)
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
IpcContainer *ipcContainer = container->ipcContainer;
|
||||
if (ipcContainer != NULL) {
|
||||
LOS_AtomicDec(&ipcContainer->rc);
|
||||
if (LOS_AtomicRead(&ipcContainer->rc) <= 0) {
|
||||
g_currentIpcContainerNum--;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
ShmDeinit();
|
||||
container->ipcContainer = NULL;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, ipcContainer->allQueue);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, ipcContainer);
|
||||
return;
|
||||
}
|
||||
if (ipcContainer == NULL) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&ipcContainer->rc);
|
||||
if (LOS_AtomicRead(&ipcContainer->rc) > 0) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
g_currentIpcContainerNum--;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
ShmDeinit();
|
||||
container->ipcContainer = NULL;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, ipcContainer->allQueue);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, ipcContainer);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ STATIC VOID FreeMountList(LIST_HEAD *mountList)
|
||||
return;
|
||||
}
|
||||
|
||||
VOID OsMntContainersDestroy(Container *container)
|
||||
VOID OsMntContainerDestroy(Container *container)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (container == NULL) {
|
||||
@@ -196,18 +196,22 @@ VOID OsMntContainersDestroy(Container *container)
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
MntContainer *mntContainer = container->mntContainer;
|
||||
if (mntContainer != NULL) {
|
||||
LOS_AtomicDec(&mntContainer->rc);
|
||||
if (LOS_AtomicRead(&mntContainer->rc) <= 0) {
|
||||
g_currentMntContainerNum--;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
FreeMountList(&mntContainer->mountList);
|
||||
container->mntContainer = NULL;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, mntContainer);
|
||||
return;
|
||||
}
|
||||
if (mntContainer == NULL) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&mntContainer->rc);
|
||||
if (LOS_AtomicRead(&mntContainer->rc) > 0) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
g_currentMntContainerNum--;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
FreeMountList(&mntContainer->mountList);
|
||||
container->mntContainer = NULL;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, mntContainer);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ UINT32 OsAllocVtid(LosTaskCB *taskCB, const LosProcessCB *processCB)
|
||||
return taskCB->taskID;
|
||||
}
|
||||
|
||||
VOID OsPidContainersDestroyAllProcess(LosProcessCB *curr)
|
||||
VOID OsPidContainerDestroyAllProcess(LosProcessCB *curr)
|
||||
{
|
||||
INT32 ret;
|
||||
UINT32 intSave;
|
||||
@@ -264,35 +264,66 @@ STATIC PidContainer *CreateNewPidContainer(PidContainer *parent)
|
||||
newPidContainer->parent = parent;
|
||||
if (parent != NULL) {
|
||||
LOS_AtomicSet(&newPidContainer->level, parent->level + 1);
|
||||
newPidContainer->referenced = FALSE;
|
||||
} else {
|
||||
LOS_AtomicSet(&newPidContainer->level, 0);
|
||||
newPidContainer->referenced = TRUE;
|
||||
}
|
||||
return newPidContainer;
|
||||
}
|
||||
|
||||
VOID OsPidContainerDestroy(LosProcessCB *curr)
|
||||
{
|
||||
if (curr->container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
PidContainer *pidContainer = curr->container->pidContainer;
|
||||
if (pidContainer == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
FreeVpid(curr);
|
||||
|
||||
if (pidContainer != curr->container->pidForChildContainer) {
|
||||
LOS_AtomicDec(&curr->container->pidForChildContainer->rc);
|
||||
if (LOS_AtomicRead(&curr->container->pidForChildContainer->rc) <= 0) {
|
||||
g_currentPidContainerNum--;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, curr->container->pidForChildContainer);
|
||||
curr->container->pidForChildContainer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (LOS_AtomicRead(&pidContainer->rc) <= 0) {
|
||||
g_currentPidContainerNum--;
|
||||
curr->container->pidContainer = NULL;
|
||||
curr->container->pidForChildContainer = NULL;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pidContainer);
|
||||
}
|
||||
|
||||
OsContainerFree(curr);
|
||||
}
|
||||
|
||||
STATIC UINT32 CreatePidContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 ret;
|
||||
PidContainer *newPidContainer = NULL;
|
||||
UINT32 intSave;
|
||||
|
||||
PidContainer *parentContainer = parent->container->pidContainer;
|
||||
if (parentContainer == parent->container->pidForChildContainer) {
|
||||
newPidContainer = CreateNewPidContainer(parentContainer);
|
||||
if (newPidContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
} else {
|
||||
newPidContainer = parent->container->pidForChildContainer;
|
||||
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);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
g_currentPidContainerNum++;
|
||||
newPidContainer->referenced = TRUE;
|
||||
child->container->pidContainer = newPidContainer;
|
||||
child->container->pidForChildContainer = newPidContainer;
|
||||
ret = OsAllocSpecifiedVpidUnsafe(OS_USER_ROOT_PROCESS_ID, child, parent);
|
||||
@@ -300,6 +331,7 @@ STATIC UINT32 CreatePidContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
g_currentPidContainerNum--;
|
||||
FreeVpid(child);
|
||||
child->container->pidContainer = NULL;
|
||||
child->container->pidForChildContainer = NULL;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, newPidContainer);
|
||||
return ENOSPC;
|
||||
@@ -308,32 +340,21 @@ STATIC UINT32 CreatePidContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsPidContainersDestroy(LosProcessCB *curr)
|
||||
STATIC UINT32 UnshareCreatePidContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
if (curr->container == NULL) {
|
||||
return;
|
||||
}
|
||||
UINT32 ret;
|
||||
|
||||
PidContainer *pidContainer = curr->container->pidContainer;
|
||||
if (pidContainer != NULL) {
|
||||
FreeVpid(curr);
|
||||
if (LOS_AtomicRead(&pidContainer->rc) <= 0) {
|
||||
g_currentPidContainerNum--;
|
||||
if ((pidContainer != curr->container->pidForChildContainer) &&
|
||||
(LOS_AtomicRead(&curr->container->pidForChildContainer->rc) <= 0)) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, curr->container->pidForChildContainer);
|
||||
}
|
||||
curr->container->pidContainer = NULL;
|
||||
curr->container->pidForChildContainer = NULL;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pidContainer);
|
||||
}
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&curr->container->rc);
|
||||
if (LOS_AtomicRead(&curr->container->rc) == 0) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, curr->container);
|
||||
curr->container = NULL;
|
||||
parent->container->pidForChildContainer->referenced = TRUE;
|
||||
child->container->pidContainer = parent->container->pidForChildContainer;
|
||||
child->container->pidForChildContainer = parent->container->pidForChildContainer;
|
||||
ret = OsAllocSpecifiedVpidUnsafe(OS_USER_ROOT_PROCESS_ID, child, parent);
|
||||
if (ret == OS_INVALID_VALUE) {
|
||||
FreeVpid(child);
|
||||
child->container->pidContainer = NULL;
|
||||
child->container->pidForChildContainer = NULL;
|
||||
return ENOSPC;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsCopyPidContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID)
|
||||
@@ -341,23 +362,36 @@ UINT32 OsCopyPidContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
|
||||
UINT32 ret;
|
||||
UINT32 intSave;
|
||||
|
||||
if (!(flags & CLONE_NEWPID) && (parent->container->pidContainer == parent->container->pidForChildContainer)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
child->container->pidContainer = parent->container->pidContainer;
|
||||
child->container->pidForChildContainer = parent->container->pidContainer;
|
||||
ret = OsAllocVpid(child);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if (ret == OS_INVALID_VALUE) {
|
||||
PRINT_ERR("[%s] alloc vpid failed\n", __FUNCTION__);
|
||||
return ENOSPC;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
PidContainer *parentPidContainer = parent->container->pidContainer;
|
||||
PidContainer *parentPidContainerForChild = parent->container->pidForChildContainer;
|
||||
if ((parentPidContainer == parentPidContainerForChild) || (parentPidContainerForChild->referenced == TRUE)) {
|
||||
/* The current process is not executing unshare */
|
||||
if (!(flags & CLONE_NEWPID)) {
|
||||
child->container->pidContainer = parentPidContainer;
|
||||
child->container->pidForChildContainer = parentPidContainer;
|
||||
ret = OsAllocVpid(child);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if (ret == OS_INVALID_VALUE) {
|
||||
PRINT_ERR("[%s] alloc vpid failed\n", __FUNCTION__);
|
||||
return ENOSPC;
|
||||
}
|
||||
*processID = child->processID;
|
||||
return LOS_OK;
|
||||
}
|
||||
*processID = child->processID;
|
||||
return LOS_OK;
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
ret = CreatePidContainer(child, parent);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
ret = CreatePidContainer(child, parent);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
/* Create the first process after unshare */
|
||||
ret = UnshareCreatePidContainer(child, parent);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
PidContainer *pidContainer = child->container->pidContainer;
|
||||
@@ -369,13 +403,38 @@ UINT32 OsCopyPidContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID UnshareDeInitPidContainer(Container *container)
|
||||
{
|
||||
UINT32 intSave;
|
||||
PidContainer *pidForChildContainer = NULL;
|
||||
if (container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if ((container->pidForChildContainer != NULL) && (container->pidContainer != container->pidForChildContainer)) {
|
||||
LOS_AtomicDec(&container->pidForChildContainer->rc);
|
||||
if (LOS_AtomicRead(&container->pidForChildContainer->rc) <= 0) {
|
||||
g_currentPidContainerNum--;
|
||||
pidForChildContainer = container->pidForChildContainer;
|
||||
container->pidForChildContainer = NULL;
|
||||
container->pidContainer = NULL;
|
||||
}
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pidForChildContainer);
|
||||
}
|
||||
|
||||
UINT32 OsUnsharePidContainer(UINTPTR flags, LosProcessCB *curr, Container *newContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (!(flags & CLONE_NEWPID)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
newContainer->pidContainer = curr->container->pidContainer;
|
||||
newContainer->pidForChildContainer = curr->container->pidContainer;
|
||||
newContainer->pidForChildContainer = curr->container->pidForChildContainer;
|
||||
if (newContainer->pidContainer != newContainer->pidForChildContainer) {
|
||||
LOS_AtomicInc(&newContainer->pidForChildContainer->rc);
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
@@ -398,8 +457,10 @@ UINT32 OsUnsharePidContainer(UINTPTR flags, LosProcessCB *curr, Container *newCo
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
g_currentPidContainerNum++;
|
||||
newContainer->pidContainer = curr->container->pidContainer;
|
||||
newContainer->pidForChildContainer = pidForChild;
|
||||
LOS_AtomicSet(&pidForChild->rc, 1);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
@@ -56,30 +56,11 @@ STATIC TimeContainer *CreateNewTimeContainer(TimeContainer *parent)
|
||||
STATIC UINT32 CreateTimeContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
TimeContainer *parentContainer = parent->container->timeContainer;
|
||||
if (parentContainer == parent->container->timeForChildContainer) {
|
||||
TimeContainer *newTimeContainer = CreateNewTimeContainer(parentContainer);
|
||||
if (newTimeContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
g_currentTimeContainerNum++;
|
||||
(VOID)memcpy_s(&newTimeContainer->monotonic, sizeof(struct timespec64),
|
||||
&parentContainer->monotonic, sizeof(struct timespec64));
|
||||
child->container->timeContainer = newTimeContainer;
|
||||
child->container->timeForChildContainer = newTimeContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
TimeContainer *newTimeContainer = parent->container->timeForChildContainer;
|
||||
g_currentTimeContainerNum++;
|
||||
LOS_AtomicSet(&newTimeContainer->rc, 1);
|
||||
if (!newTimeContainer->frozenOffsets) {
|
||||
newTimeContainer->frozenOffsets = TRUE;
|
||||
}
|
||||
LOS_AtomicInc(&newTimeContainer->rc);
|
||||
newTimeContainer->frozenOffsets = TRUE;
|
||||
child->container->timeContainer = newTimeContainer;
|
||||
child->container->timeForChildContainer = newTimeContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
@@ -106,7 +87,7 @@ UINT32 OsCopyTimeContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *par
|
||||
UINT32 intSave;
|
||||
TimeContainer *currTimeContainer = parent->container->timeContainer;
|
||||
|
||||
if (!(flags & CLONE_NEWTIME) && (currTimeContainer == parent->container->timeForChildContainer)) {
|
||||
if (currTimeContainer == parent->container->timeForChildContainer) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LOS_AtomicInc(&currTimeContainer->rc);
|
||||
child->container->timeContainer = currTimeContainer;
|
||||
@@ -125,6 +106,9 @@ UINT32 OsUnshareTimeContainer(UINTPTR flags, LosProcessCB *curr, Container *newC
|
||||
SCHEDULER_LOCK(intSave);
|
||||
newContainer->timeContainer = curr->container->timeContainer;
|
||||
newContainer->timeForChildContainer = curr->container->timeForChildContainer;
|
||||
if (newContainer->timeContainer != newContainer->timeForChildContainer) {
|
||||
LOS_AtomicInc(&newContainer->timeForChildContainer->rc);
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
@@ -141,38 +125,72 @@ UINT32 OsUnshareTimeContainer(UINTPTR flags, LosProcessCB *curr, Container *newC
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
(VOID)memcpy_s(&timeForChild->monotonic, sizeof(struct timespec64),
|
||||
&curr->container->timeContainer->monotonic, sizeof(struct timespec64));
|
||||
newContainer->timeContainer = curr->container->timeContainer;
|
||||
newContainer->timeForChildContainer = timeForChild;
|
||||
LOS_AtomicSet(&timeForChild->rc, 0);
|
||||
g_currentTimeContainerNum++;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsTimeContainersDestroy(LosProcessCB *curr)
|
||||
VOID UnshareDeInitTimeContainer(Container *container)
|
||||
{
|
||||
UINT32 intSave;
|
||||
TimeContainer *timeForChildContainer = NULL;
|
||||
if (container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if ((container->timeForChildContainer != NULL) && (container->timeForChildContainer != container->timeContainer)) {
|
||||
LOS_AtomicDec(&container->timeForChildContainer->rc);
|
||||
if (LOS_AtomicRead(&container->timeForChildContainer->rc) <= 0) {
|
||||
g_currentTimeContainerNum--;
|
||||
timeForChildContainer = container->timeForChildContainer;
|
||||
container->timeForChildContainer = NULL;
|
||||
container->timeContainer = NULL;
|
||||
}
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, timeForChildContainer);
|
||||
}
|
||||
|
||||
VOID OsTimeContainerDestroy(LosProcessCB *curr)
|
||||
{
|
||||
UINT32 intSave;
|
||||
TimeContainer *timeContainer = NULL;
|
||||
TimeContainer *timeForChild = NULL;
|
||||
|
||||
if (curr->container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
TimeContainer *timeContainer = curr->container->timeContainer;
|
||||
if (timeContainer != NULL) {
|
||||
LOS_AtomicDec(&timeContainer->rc);
|
||||
if (LOS_AtomicRead(&timeContainer->rc) <= 0) {
|
||||
if (curr->container->timeContainer == NULL) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
if (curr->container->timeContainer != curr->container->timeForChildContainer) {
|
||||
LOS_AtomicDec(&curr->container->timeForChildContainer->rc);
|
||||
if (LOS_AtomicRead(&curr->container->timeForChildContainer->rc) <= 0) {
|
||||
g_currentTimeContainerNum--;
|
||||
curr->container->timeContainer = NULL;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if ((timeContainer != curr->container->timeForChildContainer) &&
|
||||
(LOS_AtomicRead(&curr->container->timeForChildContainer->rc) <= 0)) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, curr->container->timeForChildContainer);
|
||||
}
|
||||
timeForChild = curr->container->timeForChildContainer;
|
||||
curr->container->timeForChildContainer = NULL;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, timeContainer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&curr->container->timeContainer->rc);
|
||||
if (LOS_AtomicRead(&curr->container->timeContainer->rc) <= 0) {
|
||||
g_currentTimeContainerNum--;
|
||||
timeContainer = curr->container->timeContainer;
|
||||
curr->container->timeContainer = NULL;
|
||||
curr->container->timeForChildContainer = NULL;
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, timeForChild);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, timeContainer);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ UINT32 OsUnshareUtsContainer(UINTPTR flags, LosProcessCB *curr, Container *newCo
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsUtsContainersDestroy(Container *container)
|
||||
VOID OsUtsContainerDestroy(Container *container)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (container == NULL) {
|
||||
@@ -173,17 +173,20 @@ VOID OsUtsContainersDestroy(Container *container)
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
UtsContainer *utsContainer = container->utsContainer;
|
||||
if (utsContainer != NULL) {
|
||||
LOS_AtomicDec(&utsContainer->rc);
|
||||
if (LOS_AtomicRead(&utsContainer->rc) <= 0) {
|
||||
g_currentUtsContainerNum--;
|
||||
container->utsContainer = NULL;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, utsContainer);
|
||||
return;
|
||||
}
|
||||
if (utsContainer == NULL) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&utsContainer->rc);
|
||||
if (LOS_AtomicRead(&utsContainer->rc) > 0) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
g_currentUtsContainerNum--;
|
||||
container->utsContainer = NULL;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, utsContainer);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user