feat: 支持time容器
BREAKING CHANGE: 支持ipc容器及增强对外变更: 1.clone 支持CLONE_NEWTIME 2.增加”/proc/[pid]/container/time" 用于查询容器信息 3.增加”/proc/[pid]/container/time_for_children" 用于查询容器信息 4.增加”/proc/[pid]/container/pid_for_children" 用于查询容器信息 5.增加”/proc/[pid]/time_offsets" 用于查询和配置time容器信息 Close #I6B0A3 Signed-off-by: zhushengle <zhushengle@huawei.com> Change-Id: I54d79937ca608a10a4384f61e11c88757f833edf
This commit is contained in:
@@ -98,6 +98,11 @@ config IPC_CONTAINER
|
||||
default n
|
||||
depends on KERNEL_CONTAINER
|
||||
|
||||
config TIME_CONTAINER
|
||||
bool "Enable time container"
|
||||
default n
|
||||
depends on KERNEL_CONTAINER
|
||||
|
||||
######################### config options of extended #####################
|
||||
source "kernel/extended/Kconfig"
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ kernel_module(module_name) {
|
||||
"container/los_ipc_container.c",
|
||||
"container/los_mnt_container.c",
|
||||
"container/los_pid_container.c",
|
||||
"container/los_time_container.c",
|
||||
"container/los_uts_container.c",
|
||||
"core/los_bitmap.c",
|
||||
"core/los_info.c",
|
||||
|
||||
@@ -53,6 +53,7 @@ VOID OsInitRootContainer(VOID)
|
||||
{
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
(VOID)OsInitRootPidContainer(&g_rootContainer.pidContainer);
|
||||
g_rootContainer.pidForChildContainer = g_rootContainer.pidContainer;
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
(VOID)OsInitRootUtsContainer(&g_rootContainer.utsContainer);
|
||||
@@ -62,13 +63,17 @@ VOID OsInitRootContainer(VOID)
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
(VOID)OsInitRootIpcContainer(&g_rootContainer.ipcContainer);
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
(VOID)OsInitRootTimeContainer(&g_rootContainer.timeContainer);
|
||||
g_rootContainer.timeForChildContainer = g_rootContainer.timeContainer;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC INLINE Container *CreateContainer(VOID)
|
||||
{
|
||||
Container *container = LOS_MemAlloc(m_aucSysMem1, sizeof(Container));
|
||||
Container *container = (Container *)LOS_MemAlloc(m_aucSysMem1, sizeof(Container));
|
||||
if (container == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -88,7 +93,7 @@ UINT32 OsCopyContainers(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent
|
||||
UINT32 intSave;
|
||||
UINT32 ret = LOS_OK;
|
||||
|
||||
if (!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET))) {
|
||||
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);
|
||||
@@ -124,6 +129,12 @@ UINT32 OsCopyContainers(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
ret = OsCopyTimeContainer(flags, child, parent);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
@@ -149,9 +160,13 @@ VOID OsContainersDestroy(LosProcessCB *processCB)
|
||||
OsIpcContainersDestroy(processCB);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
OsTimeContainersDestroy(processCB);
|
||||
#endif
|
||||
|
||||
#ifndef LOSCFG_PID_CONTAINER
|
||||
LOS_AtomicDec(&curr->container->rc);
|
||||
if (LOS_AtomicRead(&processCB->container->rc) == 1) {
|
||||
if (LOS_AtomicRead(&processCB->container->rc) == 0) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, processCB->container);
|
||||
processCB->container = NULL;
|
||||
}
|
||||
@@ -168,6 +183,8 @@ UINT32 OsGetContainerID(Container *container, ContainerType type)
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
case PID_CONTAINER:
|
||||
return OsGetPidContainerID(container->pidContainer);
|
||||
case PID_CHILD_CONTAINER:
|
||||
return OsGetPidContainerID(container->pidForChildContainer);
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
case UTS_CONTAINER:
|
||||
@@ -180,6 +197,12 @@ UINT32 OsGetContainerID(Container *container, ContainerType type)
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
case IPC_CONTAINER:
|
||||
return OsGetIpcContainerID(container->ipcContainer);
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
case TIME_CONTAINER:
|
||||
return OsGetTimeContainerID(container->timeContainer);
|
||||
case TIME_CHILD_CONTAINER:
|
||||
return OsGetTimeContainerID(container->timeForChildContainer);
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -41,21 +41,20 @@
|
||||
|
||||
STATIC UINT32 g_currentIpcContainerNum = 0;
|
||||
|
||||
STATIC UINT32 CreateIpcContainer(IpcContainer **newIpcContainer)
|
||||
STATIC IpcContainer *CreateNewIpcContainer(IpcContainer *parent)
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
UINT32 intSave;
|
||||
UINT32 size = sizeof(IpcContainer);
|
||||
IpcContainer *ipcContainer = (IpcContainer *)LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (ipcContainer == NULL) {
|
||||
return ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(ipcContainer, size, 0, size);
|
||||
|
||||
ipcContainer->allQueue = OsAllQueueCBInit(&ipcContainer->freeQueueList);
|
||||
if (ipcContainer->allQueue == NULL) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, ipcContainer);
|
||||
return ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
|
||||
@@ -66,22 +65,47 @@ STATIC UINT32 CreateIpcContainer(IpcContainer **newIpcContainer)
|
||||
if (ipcContainer->shmSegs == NULL) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, ipcContainer->allQueue);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, ipcContainer);
|
||||
return NULL;
|
||||
}
|
||||
ipcContainer->containerID = OsAllocContainerID();
|
||||
|
||||
if (parent != NULL) {
|
||||
LOS_AtomicSet(&ipcContainer->rc, 1);
|
||||
} else {
|
||||
LOS_AtomicSet(&ipcContainer->rc, 3); /* 3: Three system processes */
|
||||
}
|
||||
return ipcContainer;
|
||||
}
|
||||
|
||||
STATIC UINT32 CreateIpcContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
IpcContainer *parentContainer = parent->container->ipcContainer;
|
||||
IpcContainer *newIpcContainer = CreateNewIpcContainer(parentContainer);
|
||||
if (newIpcContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
LOS_AtomicSet(&ipcContainer->rc, 1);
|
||||
ipcContainer->containerID = OsAllocContainerID();
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
g_currentIpcContainerNum += 1;
|
||||
*newIpcContainer = ipcContainer;
|
||||
g_currentIpcContainerNum++;
|
||||
child->container->ipcContainer = newIpcContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsInitRootIpcContainer(IpcContainer **ipcContainer)
|
||||
{
|
||||
return CreateIpcContainer(ipcContainer);
|
||||
UINT32 intSave;
|
||||
IpcContainer *newIpcContainer = CreateNewIpcContainer(NULL);
|
||||
if (newIpcContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
g_currentIpcContainerNum++;
|
||||
*ipcContainer = newIpcContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsCopyIpcContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent)
|
||||
@@ -97,7 +121,7 @@ UINT32 OsCopyIpcContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
return CreateIpcContainer(&child->container->ipcContainer);
|
||||
return CreateIpcContainer(child, parent);
|
||||
}
|
||||
|
||||
VOID OsIpcContainersDestroy(LosProcessCB *curr)
|
||||
|
||||
@@ -44,20 +44,50 @@ LIST_HEAD *GetContainerMntList(VOID)
|
||||
return &OsCurrProcessGet()->container->mntContainer->mountList;
|
||||
}
|
||||
|
||||
STATIC UINT32 CreateMntContainer(MntContainer **newMntContainer)
|
||||
STATIC MntContainer *CreateNewMntContainer(MntContainer *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
MntContainer *mntContainer = (MntContainer *)LOS_MemAlloc(m_aucSysMem1, sizeof(MntContainer));
|
||||
if (mntContainer == NULL) {
|
||||
return ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
mntContainer->containerID = OsAllocContainerID();
|
||||
LOS_AtomicSet(&mntContainer->rc, 1);
|
||||
LOS_ListInit(&mntContainer->mountList);
|
||||
|
||||
if (parent != NULL) {
|
||||
LOS_AtomicSet(&mntContainer->rc, 1);
|
||||
} else {
|
||||
LOS_AtomicSet(&mntContainer->rc, 3); /* 3: Three system processes */
|
||||
}
|
||||
return mntContainer;
|
||||
}
|
||||
|
||||
STATIC UINT32 CreateMntContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
MntContainer *parentContainer = parent->container->mntContainer;
|
||||
MntContainer *newMntContainer = CreateNewMntContainer(parentContainer);
|
||||
if (newMntContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
g_currentMntContainerNum++;
|
||||
*newMntContainer = mntContainer;
|
||||
child->container->mntContainer = newMntContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsInitRootMntContainer(MntContainer **mntContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
MntContainer *newMntContainer = CreateNewMntContainer(NULL);
|
||||
if (newMntContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
g_currentMntContainerNum++;
|
||||
*mntContainer = newMntContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
@@ -94,7 +124,7 @@ UINT32 OsCopyMntContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
ret = CreateMntContainer(&child->container->mntContainer);
|
||||
ret = CreateMntContainer(child, parent);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
@@ -158,9 +188,4 @@ UINT32 OsGetMntContainerID(MntContainer *mntContainer)
|
||||
|
||||
return mntContainer->containerID;
|
||||
}
|
||||
|
||||
UINT32 OsInitRootMntContainer(MntContainer **mntContainer)
|
||||
{
|
||||
return CreateMntContainer(mntContainer);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -289,6 +289,7 @@ STATIC UINT32 CreatePidContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
|
||||
g_currentPidContainerNum++;
|
||||
child->container->pidContainer = newPidContainer;
|
||||
child->container->pidForChildContainer = newPidContainer;
|
||||
ret = OsAllocSpecifiedVpidUnsafe(OS_USER_ROOT_PROCESS_ID, child, parent);
|
||||
if (ret == OS_INVALID_VALUE) {
|
||||
g_currentPidContainerNum--;
|
||||
@@ -313,8 +314,9 @@ VOID OsPidContainersDestroy(LosProcessCB *curr)
|
||||
FreeVpid(curr);
|
||||
if (LOS_AtomicRead(&pidContainer->rc) == 0) {
|
||||
g_currentPidContainerNum--;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pidContainer);
|
||||
curr->container->pidContainer = NULL;
|
||||
curr->container->pidForChildContainer = NULL;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pidContainer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,6 +335,7 @@ UINT32 OsCopyPidContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
|
||||
if (!(flags & CLONE_NEWPID)) {
|
||||
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) {
|
||||
|
||||
182
kernel/base/container/los_time_container.c
Normal file
182
kernel/base/container/los_time_container.c
Normal file
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* 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_time_container_pri.h"
|
||||
#include "los_process_pri.h"
|
||||
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
STATIC UINT32 g_currentTimeContainerNum;
|
||||
|
||||
STATIC TimeContainer *CreateNewTimeContainer(TimeContainer *parent)
|
||||
{
|
||||
UINT32 size = sizeof(TimeContainer);
|
||||
TimeContainer *timeContainer = (TimeContainer *)LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (timeContainer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(timeContainer, size, 0, size);
|
||||
|
||||
timeContainer->containerID = OsAllocContainerID();
|
||||
if (parent != NULL) {
|
||||
timeContainer->frozenOffsets = FALSE;
|
||||
LOS_AtomicSet(&timeContainer->rc, 1);
|
||||
} else {
|
||||
timeContainer->frozenOffsets = TRUE;
|
||||
LOS_AtomicSet(&timeContainer->rc, 3); /* 3: Three system processes */
|
||||
}
|
||||
return timeContainer;
|
||||
}
|
||||
|
||||
STATIC UINT32 CreateTimeContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
TimeContainer *parentContainer = parent->container->timeContainer;
|
||||
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;
|
||||
}
|
||||
|
||||
UINT32 OsInitRootTimeContainer(TimeContainer **timeContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
TimeContainer *newTimeContainer = CreateNewTimeContainer(NULL);
|
||||
if (newTimeContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
*timeContainer = newTimeContainer;
|
||||
g_currentTimeContainerNum++;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsCopyTimeContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
TimeContainer *currTimeContainer = parent->container->timeContainer;
|
||||
|
||||
if (!(flags & CLONE_NEWTIME)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (!currTimeContainer->frozenOffsets) {
|
||||
currTimeContainer->frozenOffsets = TRUE;
|
||||
}
|
||||
LOS_AtomicInc(&currTimeContainer->rc);
|
||||
child->container->timeContainer = currTimeContainer;
|
||||
child->container->timeForChildContainer = currTimeContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
return CreateTimeContainer(child, parent);
|
||||
}
|
||||
|
||||
VOID OsTimeContainersDestroy(LosProcessCB *curr)
|
||||
{
|
||||
UINT32 intSave;
|
||||
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) {
|
||||
g_currentTimeContainerNum--;
|
||||
curr->container->timeContainer = NULL;
|
||||
curr->container->timeForChildContainer = NULL;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, timeContainer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
UINT32 OsGetTimeContainerID(TimeContainer *timeContainer)
|
||||
{
|
||||
if (timeContainer == NULL) {
|
||||
return OS_INVALID_VALUE;
|
||||
}
|
||||
|
||||
return timeContainer->containerID;
|
||||
}
|
||||
|
||||
TimeContainer *OsGetCurrTimeContainer(VOID)
|
||||
{
|
||||
return OsCurrProcessGet()->container->timeContainer;
|
||||
}
|
||||
|
||||
UINT32 OsGetTimeContainerMonotonic(LosProcessCB *processCB, struct timespec64 *offsets)
|
||||
{
|
||||
if ((processCB == NULL) || (offsets == NULL)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (OsProcessIsInactive(processCB)) {
|
||||
return ESRCH;
|
||||
}
|
||||
|
||||
TimeContainer *timeContainer = processCB->container->timeForChildContainer;
|
||||
(VOID)memcpy_s(offsets, sizeof(struct timespec64), &timeContainer->monotonic, sizeof(struct timespec64));
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsSetTimeContainerMonotonic(LosProcessCB *processCB, struct timespec64 *offsets)
|
||||
{
|
||||
if ((processCB == NULL) || (offsets == NULL)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (OsProcessIsInactive(processCB)) {
|
||||
return ESRCH;
|
||||
}
|
||||
|
||||
TimeContainer *timeContainer = processCB->container->timeForChildContainer;
|
||||
if (timeContainer->frozenOffsets) {
|
||||
return EACCES;
|
||||
}
|
||||
|
||||
timeContainer->monotonic.tv_sec = offsets->tv_sec;
|
||||
timeContainer->monotonic.tv_nsec = offsets->tv_nsec;
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
@@ -36,82 +36,9 @@
|
||||
|
||||
STATIC UINT32 g_currentUtsContainerNum;
|
||||
|
||||
STATIC UINT32 CreateUtsContainer(UtsContainer **newUtsContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 size = sizeof(UtsContainer);
|
||||
UtsContainer *utsContainer = LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (utsContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
(VOID)memset_s(utsContainer, sizeof(UtsContainer), 0, sizeof(UtsContainer));
|
||||
|
||||
utsContainer->containerID = OsAllocContainerID();
|
||||
LOS_AtomicSet(&utsContainer->rc, 1);
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
g_currentUtsContainerNum += 1;
|
||||
*newUtsContainer = utsContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsCopyUtsContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 ret;
|
||||
UtsContainer *newUtsContainer = NULL;
|
||||
UtsContainer *currUtsContainer = parent->container->utsContainer;
|
||||
|
||||
if (!(flags & CLONE_NEWUTS)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LOS_AtomicInc(&currUtsContainer->rc);
|
||||
child->container->utsContainer = currUtsContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
ret = CreateUtsContainer(&newUtsContainer);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
(VOID)memcpy_s(&newUtsContainer->utsName, sizeof(newUtsContainer->utsName),
|
||||
&currUtsContainer->utsName, sizeof(currUtsContainer->utsName));
|
||||
child->container->utsContainer = newUtsContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsUtsContainersDestroy(LosProcessCB *curr)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (curr->container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
UtsContainer *utsContainer = curr->container->utsContainer;
|
||||
if (utsContainer != NULL) {
|
||||
LOS_AtomicDec(&utsContainer->rc);
|
||||
if (LOS_AtomicRead(&utsContainer->rc) == 0) {
|
||||
g_currentUtsContainerNum--;
|
||||
curr->container->utsContainer = NULL;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, utsContainer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC UINT32 InitUtsContainer(struct utsname *name)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
ret = sprintf_s(name->sysname, sizeof(name->sysname), "%s", KERNEL_NAME);
|
||||
UINT32 ret = sprintf_s(name->sysname, sizeof(name->sysname), "%s", KERNEL_NAME);
|
||||
if (ret < 0) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
@@ -138,14 +65,100 @@ STATIC UINT32 InitUtsContainer(struct utsname *name)
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsInitRootUtsContainer(UtsContainer **utsContainer)
|
||||
STATIC UtsContainer *CreateNewUtsContainer(UtsContainer *parent)
|
||||
{
|
||||
UINT32 ret = CreateUtsContainer(utsContainer);
|
||||
UINT32 ret;
|
||||
UINT32 size = sizeof(UtsContainer);
|
||||
UtsContainer *utsContainer = (UtsContainer *)LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (utsContainer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(utsContainer, sizeof(UtsContainer), 0, sizeof(UtsContainer));
|
||||
|
||||
utsContainer->containerID = OsAllocContainerID();
|
||||
if (parent != NULL) {
|
||||
LOS_AtomicSet(&utsContainer->rc, 1);
|
||||
return utsContainer;
|
||||
}
|
||||
LOS_AtomicSet(&utsContainer->rc, 3); /* 3: Three system processes */
|
||||
ret = InitUtsContainer(&utsContainer->utsName);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, utsContainer);
|
||||
return NULL;
|
||||
}
|
||||
return utsContainer;
|
||||
}
|
||||
|
||||
STATIC UINT32 CreateUtsContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UtsContainer *parentContainer = parent->container->utsContainer;
|
||||
UtsContainer *newUtsContainer = CreateNewUtsContainer(parentContainer);
|
||||
if (newUtsContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
return InitUtsContainer(&(*utsContainer)->utsName);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
g_currentUtsContainerNum++;
|
||||
(VOID)memcpy_s(&newUtsContainer->utsName, sizeof(newUtsContainer->utsName),
|
||||
&parentContainer->utsName, sizeof(parentContainer->utsName));
|
||||
child->container->utsContainer = newUtsContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsInitRootUtsContainer(UtsContainer **utsContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UtsContainer *newUtsContainer = CreateNewUtsContainer(NULL);
|
||||
if (newUtsContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
g_currentUtsContainerNum++;
|
||||
*utsContainer = newUtsContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsCopyUtsContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UtsContainer *currUtsContainer = parent->container->utsContainer;
|
||||
|
||||
if (!(flags & CLONE_NEWUTS)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LOS_AtomicInc(&currUtsContainer->rc);
|
||||
child->container->utsContainer = currUtsContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
return CreateUtsContainer(child, parent);
|
||||
}
|
||||
|
||||
VOID OsUtsContainersDestroy(LosProcessCB *curr)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (curr->container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
UtsContainer *utsContainer = curr->container->utsContainer;
|
||||
if (utsContainer != NULL) {
|
||||
LOS_AtomicDec(&utsContainer->rc);
|
||||
if (LOS_AtomicRead(&utsContainer->rc) == 0) {
|
||||
g_currentUtsContainerNum--;
|
||||
curr->container->utsContainer = NULL;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, utsContainer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
struct utsname *OsGetCurrUtsName(VOID)
|
||||
|
||||
@@ -2075,6 +2075,9 @@ LITE_OS_SEC_TEXT INT32 OsClone(UINT32 flags, UINTPTR sp, UINT32 size)
|
||||
return -LOS_EINVAL;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
cloneFlag |= CLONE_NEWTIME;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (flags & (~cloneFlag)) {
|
||||
|
||||
@@ -45,19 +45,26 @@
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
#include "los_ipc_container_pri.h"
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
#include "los_time_container_pri.h"
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
CONTAINER = 0,
|
||||
PID_CONTAINER,
|
||||
PID_CHILD_CONTAINER,
|
||||
UTS_CONTAINER,
|
||||
MNT_CONTAINER,
|
||||
IPC_CONTAINER,
|
||||
TIME_CONTAINER,
|
||||
TIME_CHILD_CONTAINER,
|
||||
} ContainerType;
|
||||
|
||||
typedef struct Container {
|
||||
Atomic rc;
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
struct PidContainer *pidContainer;
|
||||
struct PidContainer *pidForChildContainer;
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
struct UtsContainer *utsContainer;
|
||||
@@ -68,6 +75,10 @@ typedef struct Container {
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
struct IpcContainer *ipcContainer;
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
struct TimeContainer *timeContainer;
|
||||
struct TimeContainer *timeForChildContainer;
|
||||
#endif
|
||||
} Container;
|
||||
|
||||
VOID OsContainerInitSystemProcess(LosProcessCB *processCB);
|
||||
|
||||
63
kernel/base/include/los_time_container_pri.h
Normal file
63
kernel/base/include/los_time_container_pri.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 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_TIME_CONTAINER_PRI_H
|
||||
#define _LOS_TIME_CONTAINER_PRI_H
|
||||
#include "time.h"
|
||||
#include "los_atomic.h"
|
||||
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
typedef struct ProcessCB LosProcessCB;
|
||||
|
||||
typedef struct TimeContainer {
|
||||
Atomic rc;
|
||||
BOOL frozenOffsets;
|
||||
struct timespec64 monotonic;
|
||||
UINT32 containerID;
|
||||
} TimeContainer;
|
||||
|
||||
UINT32 OsInitRootTimeContainer(TimeContainer **timeContainer);
|
||||
|
||||
UINT32 OsCopyTimeContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent);
|
||||
|
||||
VOID OsTimeContainersDestroy(LosProcessCB *curr);
|
||||
|
||||
UINT32 OsGetTimeContainerID(TimeContainer *timeContainer);
|
||||
|
||||
TimeContainer *OsGetCurrTimeContainer(VOID);
|
||||
|
||||
UINT32 OsGetTimeContainerMonotonic(LosProcessCB *processCB, struct timespec64 *offsets);
|
||||
|
||||
UINT32 OsSetTimeContainerMonotonic(LosProcessCB *processCB, struct timespec64 *offsets);
|
||||
|
||||
#define CLOCK_MONOTONIC_TIME_BASE (OsGetCurrTimeContainer()->monotonic)
|
||||
|
||||
#endif
|
||||
#endif /* _LOS_TIME_CONTAINER_PRI_H */
|
||||
Reference in New Issue
Block a user