feta: 支持unshare接口
BREAKING CHANGE: 支持unshare接口对外变更 1.支持unshare接口,flags支持:CLONE_NEWPID, CLONE_NEWTIME, CLONE_NEWUTS Close #I6BE5A Signed-off-by: zhushengle <zhushengle@huawei.com> Change-Id: Ib61abad2fa03a7100bf808e93830f2094fa1c5a6
This commit is contained in:
@@ -84,27 +84,9 @@ STATIC INLINE Container *CreateContainer(VOID)
|
||||
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)
|
||||
STATIC UINT32 CopyContainers(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 | CLONE_NEWTIME))) {
|
||||
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);
|
||||
@@ -139,6 +121,58 @@ UINT32 OsCopyContainers(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
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) {
|
||||
goto CREATE_CONTAINER;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
if (parent->container->timeContainer != parent->container->timeForChildContainer) {
|
||||
goto CREATE_CONTAINER;
|
||||
}
|
||||
#endif
|
||||
SCHEDULER_LOCK(intSave);
|
||||
child->container = parent->container;
|
||||
LOS_AtomicInc(&child->container->rc);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
goto COPY_CONTAINERS;
|
||||
}
|
||||
|
||||
#if defined(LOSCFG_PID_CONTAINER) || defined(LOSCFG_TIME_CONTAINER)
|
||||
CREATE_CONTAINER:
|
||||
#endif
|
||||
child->container = CreateContainer();
|
||||
if (child->container == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
COPY_CONTAINERS:
|
||||
return CopyContainers(flags, child, parent, processID);
|
||||
}
|
||||
|
||||
#ifndef LOSCFG_PID_CONTAINER
|
||||
STATIC VOID ContainersFree(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. */
|
||||
@@ -149,15 +183,15 @@ VOID OsContainersDestroy(LosProcessCB *processCB)
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
OsUtsContainersDestroy(processCB);
|
||||
OsUtsContainersDestroy(processCB->container);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
OsMntContainersDestroy(processCB);
|
||||
OsMntContainersDestroy(processCB->container);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
OsIpcContainersDestroy(processCB);
|
||||
OsIpcContainersDestroy(processCB->container);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
@@ -165,11 +199,7 @@ VOID OsContainersDestroy(LosProcessCB *processCB)
|
||||
#endif
|
||||
|
||||
#ifndef LOSCFG_PID_CONTAINER
|
||||
LOS_AtomicDec(&curr->container->rc);
|
||||
if (LOS_AtomicRead(&processCB->container->rc) == 0) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, processCB->container);
|
||||
processCB->container = NULL;
|
||||
}
|
||||
ContainersFree(processCB);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -209,4 +239,126 @@ 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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
|
||||
UnshareDeinitContainerCommon(flags, container);
|
||||
|
||||
#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;
|
||||
}
|
||||
#endif
|
||||
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, container);
|
||||
}
|
||||
|
||||
STATIC UINT32 CreateNewContainers(UINT32 flags, LosProcessCB *curr, Container *newContainer)
|
||||
{
|
||||
UINT32 ret = LOS_OK;
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
ret = OsUnsharePidContainer(flags, curr, newContainer);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
ret = OsUnshareUtsContainer(flags, curr, newContainer);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
ret = OsUnshareMntContainer(flags, curr, newContainer);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
ret = OsUnshareIpcContainer(flags, curr, newContainer);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
ret = OsUnshareTimeContainer(flags, curr, newContainer);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
INT32 OsUnshare(UINT32 flags)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 intSave;
|
||||
LosProcessCB *curr = OsCurrProcessGet();
|
||||
Container *oldContainer = curr->container;
|
||||
if (!(flags & (CLONE_NEWPID | CLONE_NEWTIME | CLONE_NEWUTS | CLONE_NEWNS | CLONE_NEWIPC))) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
Container *newContainer = CreateContainer();
|
||||
if (newContainer == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ret = CreateNewContainers(flags, curr, newContainer);
|
||||
if (ret != LOS_OK) {
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
oldContainer = curr->container;
|
||||
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);
|
||||
return LOS_OK;
|
||||
|
||||
EXIT:
|
||||
UnshareDeinitContainer(flags, newContainer);
|
||||
return -ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -124,22 +124,46 @@ UINT32 OsCopyIpcContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
|
||||
return CreateIpcContainer(child, parent);
|
||||
}
|
||||
|
||||
VOID OsIpcContainersDestroy(LosProcessCB *curr)
|
||||
UINT32 OsUnshareIpcContainer(UINTPTR flags, LosProcessCB *curr, Container *newContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (curr->container == NULL) {
|
||||
IpcContainer *parentContainer = curr->container->ipcContainer;
|
||||
|
||||
if (!(flags & CLONE_NEWIPC)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
newContainer->ipcContainer = parentContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
IpcContainer *ipcContainer = CreateNewIpcContainer(parentContainer);
|
||||
if (ipcContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
newContainer->ipcContainer = ipcContainer;
|
||||
g_currentIpcContainerNum++;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsIpcContainersDestroy(Container *container)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
IpcContainer *ipcContainer = curr->container->ipcContainer;
|
||||
IpcContainer *ipcContainer = container->ipcContainer;
|
||||
if (ipcContainer != NULL) {
|
||||
LOS_AtomicDec(&ipcContainer->rc);
|
||||
if (LOS_AtomicRead(&ipcContainer->rc) == 0) {
|
||||
if (LOS_AtomicRead(&ipcContainer->rc) <= 0) {
|
||||
g_currentIpcContainerNum--;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
ShmDeinit();
|
||||
curr->container->ipcContainer = NULL;
|
||||
container->ipcContainer = NULL;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, ipcContainer->allQueue);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, ipcContainer);
|
||||
return;
|
||||
|
||||
@@ -132,6 +132,37 @@ UINT32 OsCopyMntContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
|
||||
return CopyMountList(currMntContainer, child->container->mntContainer);
|
||||
}
|
||||
|
||||
UINT32 OsUnshareMntContainer(UINTPTR flags, LosProcessCB *curr, Container *newContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 ret;
|
||||
MntContainer *parentContainer = curr->container->mntContainer;
|
||||
|
||||
if (!(flags & CLONE_NEWNS)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
newContainer->mntContainer = parentContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
MntContainer *mntContainer = CreateNewMntContainer(parentContainer);
|
||||
if (mntContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
ret = CopyMountList(parentContainer, mntContainer);
|
||||
if (ret != LOS_OK) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, mntContainer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
newContainer->mntContainer = mntContainer;
|
||||
g_currentMntContainerNum++;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID FreeMountList(LIST_HEAD *mountList)
|
||||
{
|
||||
struct Mount *mnt = NULL;
|
||||
@@ -156,22 +187,22 @@ STATIC VOID FreeMountList(LIST_HEAD *mountList)
|
||||
return;
|
||||
}
|
||||
|
||||
VOID OsMntContainersDestroy(LosProcessCB *curr)
|
||||
VOID OsMntContainersDestroy(Container *container)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (curr->container == NULL) {
|
||||
if (container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
MntContainer *mntContainer = curr->container->mntContainer;
|
||||
MntContainer *mntContainer = container->mntContainer;
|
||||
if (mntContainer != NULL) {
|
||||
LOS_AtomicDec(&mntContainer->rc);
|
||||
if (LOS_AtomicRead(&mntContainer->rc) == 0) {
|
||||
if (LOS_AtomicRead(&mntContainer->rc) <= 0) {
|
||||
g_currentMntContainerNum--;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
FreeMountList(&mntContainer->mountList);
|
||||
curr->container->mntContainer = NULL;
|
||||
container->mntContainer = NULL;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, mntContainer);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -274,10 +274,15 @@ STATIC UINT32 CreatePidContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 ret;
|
||||
PidContainer *newPidContainer = NULL;
|
||||
PidContainer *parentContainer = parent->container->pidContainer;
|
||||
PidContainer *newPidContainer = CreateNewPidContainer(parentContainer);
|
||||
if (newPidContainer == NULL) {
|
||||
return ENOMEM;
|
||||
if (parentContainer == parent->container->pidForChildContainer) {
|
||||
newPidContainer = CreateNewPidContainer(parentContainer);
|
||||
if (newPidContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
} else {
|
||||
newPidContainer = parent->container->pidForChildContainer;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
@@ -312,8 +317,12 @@ VOID OsPidContainersDestroy(LosProcessCB *curr)
|
||||
PidContainer *pidContainer = curr->container->pidContainer;
|
||||
if (pidContainer != NULL) {
|
||||
FreeVpid(curr);
|
||||
if (LOS_AtomicRead(&pidContainer->rc) == 0) {
|
||||
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);
|
||||
@@ -332,7 +341,7 @@ UINT32 OsCopyPidContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
|
||||
UINT32 ret;
|
||||
UINT32 intSave;
|
||||
|
||||
if (!(flags & CLONE_NEWPID)) {
|
||||
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;
|
||||
@@ -360,6 +369,41 @@ UINT32 OsCopyPidContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
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;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
PidContainer *pidForChild = CreateNewPidContainer(curr->container->pidContainer);
|
||||
if (pidForChild == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (curr->container->pidContainer != curr->container->pidForChildContainer) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pidForChild);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (pidForChild->level >= PID_CONTAINER_LEVEL_LIMIT) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pidForChild);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
newContainer->pidContainer = curr->container->pidContainer;
|
||||
newContainer->pidForChildContainer = pidForChild;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsInitRootPidContainer(PidContainer **pidContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
@@ -57,15 +57,29 @@ STATIC UINT32 CreateTimeContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
TimeContainer *parentContainer = parent->container->timeContainer;
|
||||
TimeContainer *newTimeContainer = CreateNewTimeContainer(parentContainer);
|
||||
if (newTimeContainer == NULL) {
|
||||
return ENOMEM;
|
||||
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++;
|
||||
(VOID)memcpy_s(&newTimeContainer->monotonic, sizeof(struct timespec64),
|
||||
&parentContainer->monotonic, sizeof(struct timespec64));
|
||||
LOS_AtomicSet(&newTimeContainer->rc, 1);
|
||||
if (!newTimeContainer->frozenOffsets) {
|
||||
newTimeContainer->frozenOffsets = TRUE;
|
||||
}
|
||||
child->container->timeContainer = newTimeContainer;
|
||||
child->container->timeForChildContainer = newTimeContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
@@ -92,11 +106,8 @@ UINT32 OsCopyTimeContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *par
|
||||
UINT32 intSave;
|
||||
TimeContainer *currTimeContainer = parent->container->timeContainer;
|
||||
|
||||
if (!(flags & CLONE_NEWTIME)) {
|
||||
if (!(flags & CLONE_NEWTIME) && (currTimeContainer == parent->container->timeForChildContainer)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (!currTimeContainer->frozenOffsets) {
|
||||
currTimeContainer->frozenOffsets = TRUE;
|
||||
}
|
||||
LOS_AtomicInc(&currTimeContainer->rc);
|
||||
child->container->timeContainer = currTimeContainer;
|
||||
child->container->timeForChildContainer = currTimeContainer;
|
||||
@@ -107,6 +118,36 @@ UINT32 OsCopyTimeContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *par
|
||||
return CreateTimeContainer(child, parent);
|
||||
}
|
||||
|
||||
UINT32 OsUnshareTimeContainer(UINTPTR flags, LosProcessCB *curr, Container *newContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (!(flags & CLONE_NEWTIME)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
newContainer->timeContainer = curr->container->timeContainer;
|
||||
newContainer->timeForChildContainer = curr->container->timeForChildContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
TimeContainer *timeForChild = CreateNewTimeContainer(curr->container->timeContainer);
|
||||
if (timeForChild == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (curr->container->timeContainer != curr->container->timeForChildContainer) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, timeForChild);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
newContainer->timeContainer = curr->container->timeContainer;
|
||||
newContainer->timeForChildContainer = timeForChild;
|
||||
LOS_AtomicSet(&timeForChild->rc, 0);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsTimeContainersDestroy(LosProcessCB *curr)
|
||||
{
|
||||
UINT32 intSave;
|
||||
@@ -118,11 +159,15 @@ VOID OsTimeContainersDestroy(LosProcessCB *curr)
|
||||
TimeContainer *timeContainer = curr->container->timeContainer;
|
||||
if (timeContainer != NULL) {
|
||||
LOS_AtomicDec(&timeContainer->rc);
|
||||
if (LOS_AtomicRead(&timeContainer->rc) == 0) {
|
||||
if (LOS_AtomicRead(&timeContainer->rc) <= 0) {
|
||||
g_currentTimeContainerNum--;
|
||||
curr->container->timeContainer = NULL;
|
||||
curr->container->timeForChildContainer = NULL;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if ((timeContainer != curr->container->timeForChildContainer) &&
|
||||
(LOS_AtomicRead(&curr->container->timeForChildContainer->rc) <= 0)) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, curr->container->timeForChildContainer);
|
||||
}
|
||||
curr->container->timeForChildContainer = NULL;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, timeContainer);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -138,20 +138,46 @@ UINT32 OsCopyUtsContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
|
||||
return CreateUtsContainer(child, parent);
|
||||
}
|
||||
|
||||
VOID OsUtsContainersDestroy(LosProcessCB *curr)
|
||||
UINT32 OsUnshareUtsContainer(UINTPTR flags, LosProcessCB *curr, Container *newContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (curr->container == NULL) {
|
||||
UtsContainer *parentContainer = curr->container->utsContainer;
|
||||
|
||||
if (!(flags & CLONE_NEWUTS)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
newContainer->utsContainer = parentContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UtsContainer *utsContainer = CreateNewUtsContainer(parentContainer);
|
||||
if (utsContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
newContainer->utsContainer = utsContainer;
|
||||
g_currentUtsContainerNum++;
|
||||
(VOID)memcpy_s(&utsContainer->utsName, sizeof(utsContainer->utsName),
|
||||
&parentContainer->utsName, sizeof(parentContainer->utsName));
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsUtsContainersDestroy(Container *container)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
UtsContainer *utsContainer = curr->container->utsContainer;
|
||||
UtsContainer *utsContainer = container->utsContainer;
|
||||
if (utsContainer != NULL) {
|
||||
LOS_AtomicDec(&utsContainer->rc);
|
||||
if (LOS_AtomicRead(&utsContainer->rc) == 0) {
|
||||
if (LOS_AtomicRead(&utsContainer->rc) <= 0) {
|
||||
g_currentUtsContainerNum--;
|
||||
curr->container->utsContainer = NULL;
|
||||
container->utsContainer = NULL;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, utsContainer);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user