Compare commits
60 Commits
weekly_202
...
weekly_202
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ff66c7f40 | ||
|
|
8f937c8771 | ||
|
|
2845efe801 | ||
|
|
8cc5209181 | ||
|
|
f995c7c7af | ||
|
|
a104497e08 | ||
|
|
b5ae9e25c6 | ||
|
|
c2b5a5897f | ||
|
|
f924cc775b | ||
|
|
5dc9a0f1a6 | ||
|
|
806bd80841 | ||
|
|
c141a92544 | ||
|
|
10c5e2e666 | ||
|
|
da9ce464dd | ||
|
|
f0a435dce1 | ||
|
|
b45cdbda3e | ||
|
|
57455849ca | ||
|
|
ea825345c2 | ||
|
|
f397c63fbd | ||
|
|
fe6ab18cd9 | ||
|
|
c0f5d437d8 | ||
|
|
1ef64e26a1 | ||
|
|
77b1b208d1 | ||
|
|
d17bc9d4ea | ||
|
|
be50721826 | ||
|
|
4e7d2edbe1 | ||
|
|
58610ea87c | ||
|
|
c6ff38edd2 | ||
|
|
1c18c48b1e | ||
|
|
bea394a75e | ||
|
|
272c490618 | ||
|
|
dd041bef5a | ||
|
|
fd925a8163 | ||
|
|
e8e21fcc3e | ||
|
|
c592fe73ec | ||
|
|
4174654bdd | ||
|
|
f3a7a9c602 | ||
|
|
c8dbdaeb12 | ||
|
|
1f05c6a24d | ||
|
|
325b4a49e4 | ||
|
|
1d1f1b06c3 | ||
|
|
16ed05e844 | ||
|
|
7e0dfb79f7 | ||
|
|
34814c58a3 | ||
|
|
c0c9bbdfb4 | ||
|
|
e2d903b663 | ||
|
|
d4794ebc38 | ||
|
|
3be7409a28 | ||
|
|
0c7dd0f911 | ||
|
|
41619f004d | ||
|
|
be9cee4c21 | ||
|
|
6c8735cb9e | ||
|
|
8701e73c9f | ||
|
|
c403fdf8ed | ||
|
|
251abede16 | ||
|
|
20782299ce | ||
|
|
0b141e052b | ||
|
|
46cc84331a | ||
|
|
e816896dc4 | ||
|
|
ebc3f30524 |
24
BUILD.gn
24
BUILD.gn
@@ -34,6 +34,7 @@ LITEOS_MENUCONFIG_H = rebase_path("$root_out_dir/config.h")
|
||||
declare_args() {
|
||||
tee_enable = false
|
||||
liteos_name = "OHOS_Image"
|
||||
liteos_container_enable = false
|
||||
liteos_skip_make = false
|
||||
liteos_is_mini = false
|
||||
}
|
||||
@@ -239,6 +240,28 @@ config("misc_config") {
|
||||
asmflags = cflags
|
||||
}
|
||||
|
||||
config("container_config") {
|
||||
if (liteos_container_enable) {
|
||||
cflags = [
|
||||
"-DLOSCFG_KERNEL_CONTAINER",
|
||||
"-DLOSCFG_PID_CONTAINER",
|
||||
"-DLOSCFG_UTS_CONTAINER",
|
||||
"-DLOSCFG_MNT_CONTAINER",
|
||||
"-DLOSCFG_CHROOT",
|
||||
"-DLOSCFG_IPC_CONTAINER",
|
||||
"-DLOSCFG_TIME_CONTAINER",
|
||||
"-DLOSCFG_USER_CONTAINER",
|
||||
"-DLOSCFG_NET_CONTAINER",
|
||||
"-DLOSCFG_PROC_PROCESS_DIR",
|
||||
"-DLOSCFG_KERNEL_PLIMITS",
|
||||
"-DLOSCFG_KERNEL_MEM_PLIMIT",
|
||||
"-DLOSCFG_KERNEL_IPC_PLIMIT",
|
||||
"-DLOSCFG_KERNEL_DEV_PLIMIT",
|
||||
"-DLOSCFG_KERNEL_SCHED_PLIMIT",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
config("los_config") {
|
||||
configs = [
|
||||
":arch_config",
|
||||
@@ -249,6 +272,7 @@ config("los_config") {
|
||||
":ssp_config",
|
||||
":warn_config",
|
||||
":misc_config",
|
||||
":container_config",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,10 @@ APP_SUBDIRS += mksh
|
||||
APP_SUBDIRS += toybox
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_KERNEL_LMS), y)
|
||||
APP_SUBDIRS += lms
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_USER_INIT_DEBUG), y)
|
||||
APP_SUBDIRS += init
|
||||
endif
|
||||
|
||||
@@ -231,7 +231,7 @@ int main(int argc, char * const *argv)
|
||||
printf("\n############### Lms Test start ###############\n");
|
||||
char *tmp = (char *)malloc(5000); /* 5000: test mem size */
|
||||
if (tmp == NULL) {
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
LmsMallocTest();
|
||||
LmsReallocTest();
|
||||
@@ -246,4 +246,5 @@ int main(int argc, char * const *argv)
|
||||
LmsFreeTest();
|
||||
free(tmp);
|
||||
printf("\n############### Lms Test End ###############\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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:
|
||||
@@ -74,6 +74,10 @@ extern "C" {
|
||||
/* not support prio */
|
||||
#define MQ_PRIO_MAX 1
|
||||
|
||||
#ifndef MAX_MQ_FD
|
||||
#define MAX_MQ_FD CONFIG_NQUEUE_DESCRIPTORS
|
||||
#endif
|
||||
|
||||
typedef union send_receive_t {
|
||||
unsigned oth : 3;
|
||||
unsigned grp : 6;
|
||||
@@ -424,6 +428,7 @@ extern ssize_t mq_timedreceive(mqd_t personal, char *msg, size_t msgLen,
|
||||
|
||||
extern void MqueueRefer(int sysFd);
|
||||
extern int OsMqNotify(mqd_t personal, const struct sigevent *sigev);
|
||||
extern VOID OsMqueueCBDestroy(struct mqarray *queueTable);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -53,21 +53,27 @@
|
||||
|
||||
int uname(struct utsname *name)
|
||||
{
|
||||
INT32 ret;
|
||||
const char *cpuInfo = NULL;
|
||||
|
||||
if (name == NULL) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
struct utsname *currentUtsName = OsGetCurrUtsName();
|
||||
if (currentUtsName == NULL) {
|
||||
return -EFAULT;
|
||||
}
|
||||
(VOID)memcpy_s(name, sizeof(struct utsname), currentUtsName, sizeof(struct utsname));
|
||||
#else
|
||||
|
||||
(VOID)strcpy_s(name->sysname, sizeof(name->sysname), KERNEL_NAME);
|
||||
(VOID)strcpy_s(name->nodename, sizeof(name->nodename), "hisilicon");
|
||||
ret = sprintf_s(name->version, sizeof(name->version), "%s %u.%u.%u.%u %s %s",
|
||||
KERNEL_NAME, KERNEL_MAJOR, KERNEL_MINOR, KERNEL_PATCH, KERNEL_ITRE, __DATE__, __TIME__);
|
||||
(VOID)strcpy_s(name->nodename, sizeof(name->nodename), KERNEL_NODE_NAME);
|
||||
INT32 ret = sprintf_s(name->version, sizeof(name->version), "%s %u.%u.%u.%u %s %s",
|
||||
KERNEL_NAME, KERNEL_MAJOR, KERNEL_MINOR, KERNEL_PATCH, KERNEL_ITRE, __DATE__, __TIME__);
|
||||
if (ret < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
cpuInfo = LOS_CpuInfo();
|
||||
const char *cpuInfo = LOS_CpuInfo();
|
||||
(VOID)strcpy_s(name->machine, sizeof(name->machine), cpuInfo);
|
||||
ret = sprintf_s(name->release, sizeof(name->release), "%u.%u.%u.%u",
|
||||
KERNEL_MAJOR, KERNEL_MINOR, KERNEL_PATCH, KERNEL_ITRE);
|
||||
@@ -76,6 +82,7 @@ int uname(struct utsname *name)
|
||||
}
|
||||
|
||||
name->domainname[0] = '\0';
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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:
|
||||
@@ -44,16 +44,19 @@
|
||||
|
||||
#define FNONBLOCK O_NONBLOCK
|
||||
|
||||
#ifndef MAX_MQ_FD
|
||||
#define MAX_MQ_FD CONFIG_NQUEUE_DESCRIPTORS
|
||||
#endif
|
||||
|
||||
#ifndef LOSCFG_IPC_CONTAINER
|
||||
/* GLOBALS */
|
||||
STATIC fd_set g_queueFdSet;
|
||||
STATIC struct mqarray g_queueTable[LOSCFG_BASE_IPC_QUEUE_LIMIT];
|
||||
STATIC pthread_mutex_t g_mqueueMutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
||||
STATIC struct mqpersonal *g_mqPrivBuf[MAX_MQ_FD];
|
||||
|
||||
#define IPC_QUEUE_FD_SET g_queueFdSet
|
||||
#define IPC_QUEUE_TABLE g_queueTable
|
||||
#define IPC_QUEUE_MUTEX g_mqueueMutex
|
||||
#define IPC_QUEUE_MQ_PRIV_BUF g_mqPrivBuf
|
||||
#endif
|
||||
|
||||
/* LOCAL FUNCTIONS */
|
||||
STATIC INLINE INT32 MqNameCheck(const CHAR *mqName)
|
||||
{
|
||||
@@ -96,12 +99,12 @@ STATIC INLINE struct mqarray *GetMqueueCBByName(const CHAR *name)
|
||||
UINT32 mylen = strlen(name);
|
||||
|
||||
for (index = 0; index < LOSCFG_BASE_IPC_QUEUE_LIMIT; index++) {
|
||||
if ((g_queueTable[index].mq_name == NULL) || (strlen(g_queueTable[index].mq_name) != mylen)) {
|
||||
if ((IPC_QUEUE_TABLE[index].mq_name == NULL) || (strlen(IPC_QUEUE_TABLE[index].mq_name) != mylen)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strncmp(name, (const CHAR *)(g_queueTable[index].mq_name), mylen) == 0) {
|
||||
return &(g_queueTable[index]);
|
||||
if (strncmp(name, (const CHAR *)(IPC_QUEUE_TABLE[index].mq_name), mylen) == 0) {
|
||||
return &(IPC_QUEUE_TABLE[index]);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
@@ -110,7 +113,9 @@ STATIC INLINE struct mqarray *GetMqueueCBByName(const CHAR *name)
|
||||
STATIC INT32 DoMqueueDelete(struct mqarray *mqueueCB)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
|
||||
OsIPCLimitMqFree();
|
||||
#endif
|
||||
if (mqueueCB->mq_name != NULL) {
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, mqueueCB->mq_name);
|
||||
mqueueCB->mq_name = NULL;
|
||||
@@ -160,18 +165,36 @@ STATIC int SaveMqueueName(const CHAR *mqName, struct mqarray *mqueueCB)
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID MqueueCBInit(struct mqarray *mqueueCB, const struct mq_attr *attr, INT32 openFlag, UINT32 mode)
|
||||
{
|
||||
mqueueCB->unlinkflag = FALSE;
|
||||
mqueueCB->unlink_ref = 0;
|
||||
mqueueCB->mq_personal->mq_status = MQ_USE_MAGIC;
|
||||
mqueueCB->mq_personal->mq_next = NULL;
|
||||
mqueueCB->mq_personal->mq_posixdes = mqueueCB;
|
||||
mqueueCB->mq_personal->mq_flags = (INT32)((UINT32)openFlag | ((UINT32)attr->mq_flags & (UINT32)FNONBLOCK));
|
||||
mqueueCB->mq_personal->mq_mode = mode;
|
||||
mqueueCB->mq_personal->mq_refcount = 0;
|
||||
mqueueCB->mq_notify.pid = 0;
|
||||
}
|
||||
|
||||
STATIC struct mqpersonal *DoMqueueCreate(const struct mq_attr *attr, const CHAR *mqName, INT32 openFlag, UINT32 mode)
|
||||
{
|
||||
struct mqarray *mqueueCB = NULL;
|
||||
UINT32 mqueueID;
|
||||
|
||||
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
|
||||
if (OsIPCLimitMqAlloc() != LOS_OK) {
|
||||
return (struct mqpersonal *)-1;
|
||||
}
|
||||
#endif
|
||||
UINT32 err = LOS_QueueCreate(NULL, attr->mq_maxmsg, &mqueueID, 0, attr->mq_msgsize);
|
||||
if (map_errno(err) != ENOERR) {
|
||||
goto ERROUT;
|
||||
}
|
||||
|
||||
if (g_queueTable[GET_QUEUE_INDEX(mqueueID)].mqcb == NULL) {
|
||||
mqueueCB = &(g_queueTable[GET_QUEUE_INDEX(mqueueID)]);
|
||||
if (IPC_QUEUE_TABLE[GET_QUEUE_INDEX(mqueueID)].mqcb == NULL) {
|
||||
mqueueCB = &(IPC_QUEUE_TABLE[GET_QUEUE_INDEX(mqueueID)]);
|
||||
mqueueCB->mq_id = mqueueID;
|
||||
}
|
||||
|
||||
@@ -198,15 +221,7 @@ STATIC struct mqpersonal *DoMqueueCreate(const struct mq_attr *attr, const CHAR
|
||||
goto ERROUT;
|
||||
}
|
||||
|
||||
mqueueCB->unlinkflag = FALSE;
|
||||
mqueueCB->unlink_ref = 0;
|
||||
mqueueCB->mq_personal->mq_status = MQ_USE_MAGIC;
|
||||
mqueueCB->mq_personal->mq_next = NULL;
|
||||
mqueueCB->mq_personal->mq_posixdes = mqueueCB;
|
||||
mqueueCB->mq_personal->mq_flags = (INT32)((UINT32)openFlag | ((UINT32)attr->mq_flags & (UINT32)FNONBLOCK));
|
||||
mqueueCB->mq_personal->mq_mode = mode;
|
||||
mqueueCB->mq_personal->mq_refcount = 0;
|
||||
mqueueCB->mq_notify.pid = 0;
|
||||
MqueueCBInit(mqueueCB, attr, openFlag, mode);
|
||||
|
||||
return mqueueCB->mq_personal;
|
||||
ERROUT:
|
||||
@@ -215,6 +230,9 @@ ERROUT:
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, mqueueCB->mq_name);
|
||||
mqueueCB->mq_name = NULL;
|
||||
}
|
||||
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
|
||||
OsIPCLimitMqFree();
|
||||
#endif
|
||||
return (struct mqpersonal *)-1;
|
||||
}
|
||||
|
||||
@@ -297,7 +315,7 @@ STATIC struct mqpersonal *MqGetPrivDataBuff(mqd_t personal)
|
||||
errno = EBADF;
|
||||
return NULL;
|
||||
}
|
||||
return g_mqPrivBuf[id];
|
||||
return IPC_QUEUE_MQ_PRIV_BUF[id];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -311,13 +329,13 @@ STATIC struct mqpersonal *MqGetPrivDataBuff(mqd_t personal)
|
||||
STATIC INT32 MqAllocSysFd(int maxfdp, struct mqpersonal *privateMqPersonal)
|
||||
{
|
||||
INT32 i;
|
||||
fd_set *fdset = &g_queueFdSet;
|
||||
fd_set *fdset = &IPC_QUEUE_FD_SET;
|
||||
for (i = 0; i < maxfdp; i++) {
|
||||
/* sysFd: used bit setting, and get the index of swtmrID buffer */
|
||||
if (fdset && !(FD_ISSET(i + MQUEUE_FD_OFFSET, fdset))) {
|
||||
FD_SET(i + MQUEUE_FD_OFFSET, fdset);
|
||||
if (!g_mqPrivBuf[i]) {
|
||||
g_mqPrivBuf[i] = privateMqPersonal;
|
||||
if (!IPC_QUEUE_MQ_PRIV_BUF[i]) {
|
||||
IPC_QUEUE_MQ_PRIV_BUF[i] = privateMqPersonal;
|
||||
return i + MQUEUE_FD_OFFSET;
|
||||
}
|
||||
}
|
||||
@@ -328,10 +346,10 @@ STATIC INT32 MqAllocSysFd(int maxfdp, struct mqpersonal *privateMqPersonal)
|
||||
STATIC VOID MqFreeSysFd(mqd_t personal)
|
||||
{
|
||||
INT32 sysFd = (INT32)personal;
|
||||
fd_set *fdset = &g_queueFdSet;
|
||||
fd_set *fdset = &IPC_QUEUE_FD_SET;
|
||||
if (fdset && FD_ISSET(sysFd, fdset)) {
|
||||
FD_CLR(sysFd, fdset);
|
||||
g_mqPrivBuf[sysFd - MQUEUE_FD_OFFSET] = NULL;
|
||||
IPC_QUEUE_MQ_PRIV_BUF[sysFd - MQUEUE_FD_OFFSET] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,7 +359,7 @@ void MqueueRefer(int sysFd)
|
||||
struct mqarray *mqueueCB = NULL;
|
||||
struct mqpersonal *privateMqPersonal = NULL;
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
|
||||
/* Get the personal sysFd and reset personal fd -1 */
|
||||
privateMqPersonal = MqGetPrivDataBuff((mqd_t)sysFd);
|
||||
if (privateMqPersonal == NULL) {
|
||||
@@ -354,7 +372,7 @@ void MqueueRefer(int sysFd)
|
||||
|
||||
privateMqPersonal->mq_refcount++;
|
||||
OUT_UNLOCK:
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -498,7 +516,7 @@ mqd_t mq_open(const char *mqName, int openFlag, ...)
|
||||
return (mqd_t)-1;
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
|
||||
mqueueCB = GetMqueueCBByName(mqName);
|
||||
if ((UINT32)openFlag & (UINT32)O_CREAT) {
|
||||
if (mqueueCB != NULL) {
|
||||
@@ -543,7 +561,7 @@ mqd_t mq_open(const char *mqName, int openFlag, ...)
|
||||
mqFd = (mqd_t)sysFd;
|
||||
}
|
||||
OUT:
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return mqFd;
|
||||
}
|
||||
|
||||
@@ -552,7 +570,7 @@ int mq_close(mqd_t personal)
|
||||
INT32 ret = -1;
|
||||
struct mqpersonal *privateMqPersonal = NULL;
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
|
||||
|
||||
/* Get the personal sysFd and reset personal fd -1 */
|
||||
privateMqPersonal = MqGetPrivDataBuff(personal);
|
||||
@@ -577,7 +595,7 @@ int mq_close(mqd_t personal)
|
||||
MqFreeSysFd(personal);
|
||||
|
||||
OUT_UNLOCK:
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -596,10 +614,10 @@ int OsMqGetAttr(mqd_t personal, struct mq_attr *mqAttr)
|
||||
return -1;
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
|
||||
if (privateMqPersonal->mq_status != MQ_USE_MAGIC) {
|
||||
errno = EBADF;
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -608,7 +626,7 @@ int OsMqGetAttr(mqd_t personal, struct mq_attr *mqAttr)
|
||||
mqAttr->mq_msgsize = mqueueCB->mqcb->queueSize - sizeof(UINT32);
|
||||
mqAttr->mq_curmsgs = mqueueCB->mqcb->readWriteableCnt[OS_QUEUE_READ];
|
||||
mqAttr->mq_flags = privateMqPersonal->mq_flags;
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -626,10 +644,10 @@ int OsMqSetAttr(mqd_t personal, const struct mq_attr *mqSetAttr, struct mq_attr
|
||||
return -1;
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
|
||||
if (privateMqPersonal->mq_status != MQ_USE_MAGIC) {
|
||||
errno = EBADF;
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -641,7 +659,7 @@ int OsMqSetAttr(mqd_t personal, const struct mq_attr *mqSetAttr, struct mq_attr
|
||||
if (((UINT32)mqSetAttr->mq_flags & (UINT32)FNONBLOCK) == (UINT32)FNONBLOCK) {
|
||||
privateMqPersonal->mq_flags = (INT32)((UINT32)privateMqPersonal->mq_flags | (UINT32)FNONBLOCK);
|
||||
}
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -662,7 +680,7 @@ int mq_unlink(const char *mqName)
|
||||
return -1;
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
|
||||
mqueueCB = GetMqueueCBByName(mqName);
|
||||
if (mqueueCB == NULL) {
|
||||
errno = ENOENT;
|
||||
@@ -675,11 +693,11 @@ int mq_unlink(const char *mqName)
|
||||
ret = DoMqueueDelete(mqueueCB);
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return ret;
|
||||
|
||||
ERROUT_UNLOCK:
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -767,7 +785,7 @@ int mq_timedsend(mqd_t personal, const char *msg, size_t msgLen, unsigned int ms
|
||||
OS_MQ_GOTO_ERROUT_IF(!MqParamCheck(personal, msg, msgLen), errno);
|
||||
OS_MQ_GOTO_ERROUT_IF(msgPrio > (MQ_PRIO_MAX - 1), EINVAL);
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
|
||||
privateMqPersonal = MqGetPrivDataBuff(personal);
|
||||
|
||||
OS_MQ_GOTO_ERROUT_UNLOCK_IF(privateMqPersonal == NULL || privateMqPersonal->mq_status != MQ_USE_MAGIC, EBADF);
|
||||
@@ -781,7 +799,7 @@ int mq_timedsend(mqd_t personal, const char *msg, size_t msgLen, unsigned int ms
|
||||
|
||||
OS_MQ_GOTO_ERROUT_UNLOCK_IF(ConvertTimeout(privateMqPersonal->mq_flags, absTimeout, &absTicks) == -1, errno);
|
||||
mqueueID = mqueueCB->mq_id;
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
|
||||
if (LOS_ListEmpty(&mqueueCB->mqcb->readWriteList[OS_QUEUE_READ])) {
|
||||
MqSendNotify(mqueueCB);
|
||||
@@ -793,7 +811,7 @@ int mq_timedsend(mqd_t personal, const char *msg, size_t msgLen, unsigned int ms
|
||||
}
|
||||
return 0;
|
||||
ERROUT_UNLOCK:
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
ERROUT:
|
||||
return -1;
|
||||
}
|
||||
@@ -815,7 +833,7 @@ ssize_t mq_timedreceive(mqd_t personal, char *msg, size_t msgLen, unsigned int *
|
||||
*msgPrio = 0;
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
|
||||
privateMqPersonal = MqGetPrivDataBuff(personal);
|
||||
if (privateMqPersonal == NULL || privateMqPersonal->mq_status != MQ_USE_MAGIC) {
|
||||
errno = EBADF;
|
||||
@@ -839,7 +857,7 @@ ssize_t mq_timedreceive(mqd_t personal, char *msg, size_t msgLen, unsigned int *
|
||||
|
||||
receiveLen = msgLen;
|
||||
mqueueID = mqueueCB->mq_id;
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
|
||||
err = LOS_QueueReadCopy(mqueueID, (VOID *)msg, &receiveLen, (UINT32)absTicks);
|
||||
if (map_errno(err) == ENOERR) {
|
||||
@@ -849,7 +867,7 @@ ssize_t mq_timedreceive(mqd_t personal, char *msg, size_t msgLen, unsigned int *
|
||||
}
|
||||
|
||||
ERROUT_UNLOCK:
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
ERROUT:
|
||||
return -1;
|
||||
}
|
||||
@@ -898,7 +916,7 @@ int OsMqNotify(mqd_t personal, const struct sigevent *sigev)
|
||||
goto ERROUT;
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
|
||||
privateMqPersonal = MqGetPrivDataBuff(personal);
|
||||
if (privateMqPersonal == NULL) {
|
||||
goto OUT_UNLOCK;
|
||||
@@ -936,11 +954,26 @@ int OsMqNotify(mqd_t personal, const struct sigevent *sigev)
|
||||
mqnotify->pid = LOS_GetCurrProcessID();
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return 0;
|
||||
OUT_UNLOCK:
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
ERROUT:
|
||||
return -1;
|
||||
}
|
||||
|
||||
VOID OsMqueueCBDestroy(struct mqarray *queueTable)
|
||||
{
|
||||
if (queueTable == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (UINT32 index = 0; index < LOSCFG_BASE_IPC_QUEUE_LIMIT; index++) {
|
||||
struct mqarray *mqueueCB = &(queueTable[index]);
|
||||
if (mqueueCB->mq_name == NULL) {
|
||||
continue;
|
||||
}
|
||||
(VOID)DoMqueueClose(mqueueCB->mq_personal);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
@@ -599,13 +599,22 @@ int clock_gettime(clockid_t clockID, struct timespec *tp)
|
||||
|
||||
switch (clockID) {
|
||||
case CLOCK_MONOTONIC_RAW:
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
tmp = OsTimeSpecAdd(hwTime, CLOCK_MONOTONIC_TIME_BASE);
|
||||
tp->tv_sec = tmp.tv_sec;
|
||||
tp->tv_nsec = tmp.tv_nsec;
|
||||
#else
|
||||
tp->tv_sec = hwTime.tv_sec;
|
||||
tp->tv_nsec = hwTime.tv_nsec;
|
||||
#endif
|
||||
break;
|
||||
case CLOCK_MONOTONIC:
|
||||
LOS_SpinLockSave(&g_timeSpin, &intSave);
|
||||
tmp = OsTimeSpecAdd(hwTime, g_accDeltaFromAdj);
|
||||
LOS_SpinUnlockRestore(&g_timeSpin, intSave);
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
tmp = OsTimeSpecAdd(tmp, CLOCK_MONOTONIC_TIME_BASE);
|
||||
#endif
|
||||
tp->tv_sec = tmp.tv_sec;
|
||||
tp->tv_nsec = tmp.tv_nsec;
|
||||
break;
|
||||
@@ -639,7 +648,7 @@ int clock_gettime(clockid_t clockID, struct timespec *tp)
|
||||
|
||||
return 0;
|
||||
|
||||
ERROUT:
|
||||
ERROUT:
|
||||
TIME_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
@@ -748,7 +757,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 +1096,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 +1149,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;
|
||||
}
|
||||
|
||||
@@ -59,6 +59,9 @@ struct files_struct {
|
||||
spinlock_t workdir_lock;
|
||||
char workdir[PATH_MAX];
|
||||
#endif
|
||||
#ifdef LOSCFG_CHROOT
|
||||
struct Vnode *rootVnode;
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef struct ProcessCB LosProcessCB;
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#define MS_NOSYNC 2
|
||||
|
||||
struct MountOps;
|
||||
struct fsmap_t;
|
||||
|
||||
struct Mount {
|
||||
LIST_ENTRY mountList; /* mount list */
|
||||
@@ -69,8 +70,11 @@ typedef int (*foreach_mountpoint_t)(const char *devpoint,
|
||||
struct statfs *statbuf,
|
||||
void *arg);
|
||||
|
||||
struct Mount* MountAlloc(struct Vnode* vnode, struct MountOps* mop);
|
||||
LIST_HEAD* GetMountList(void);
|
||||
struct Mount *MountAlloc(struct Vnode *vnode, struct MountOps *mop);
|
||||
LIST_HEAD *GetMountList(void);
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
LIST_HEAD *GetMountCache(void);
|
||||
#endif
|
||||
int foreach_mountpoint(foreach_mountpoint_t handler, void *arg);
|
||||
int ForceUmountDev(struct Vnode *dev);
|
||||
#endif
|
||||
|
||||
@@ -34,12 +34,16 @@ module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
sources = [
|
||||
"os_adapt/fd_proc.c",
|
||||
"os_adapt/file_sys.c",
|
||||
"os_adapt/fs_cache_proc.c",
|
||||
"os_adapt/mem_info.c",
|
||||
"os_adapt/mounts_proc.c",
|
||||
"os_adapt/plimits_proc.c",
|
||||
"os_adapt/power_proc.c",
|
||||
"os_adapt/proc_init.c",
|
||||
"os_adapt/proc_vfs.c",
|
||||
"os_adapt/process_proc.c",
|
||||
"os_adapt/sys_user.c",
|
||||
"os_adapt/uptime_proc.c",
|
||||
"os_adapt/vmm_proc.c",
|
||||
"src/proc_file.c",
|
||||
|
||||
@@ -4,3 +4,8 @@ config FS_PROC
|
||||
depends on FS_VFS
|
||||
help
|
||||
Answer Y to enable LiteOS support proc filesystem.
|
||||
|
||||
config PROC_PROCESS_DIR
|
||||
bool "Enable Process mount directory"
|
||||
default n
|
||||
depends on FS_PROC
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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,6 +45,26 @@ extern "C" {
|
||||
extern spinlock_t procfsLock;
|
||||
extern bool procfsInit;
|
||||
|
||||
#ifdef LOSCFG_PROC_PROCESS_DIR
|
||||
int ProcCreateProcessDir(UINT32 pid, uintptr_t process);
|
||||
|
||||
void ProcFreeProcessDir(struct ProcDirEntry *processDir);
|
||||
|
||||
void ProcSysMemInfoInit(void);
|
||||
|
||||
void ProcFileSysInit(void);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_KERNEL_PLIMITS
|
||||
void ProcLimitsInit(void);
|
||||
#endif
|
||||
|
||||
void ProcEntryClearVnode(struct ProcDirEntry *entry);
|
||||
|
||||
void ProcDetachNode(struct ProcDirEntry *pn);
|
||||
|
||||
void RemoveProcEntryTravalsal(struct ProcDirEntry *pn);
|
||||
|
||||
void ProcPmInit(void);
|
||||
|
||||
void ProcVmmInit(void);
|
||||
@@ -57,15 +77,20 @@ struct ProcDirEntry *ProcFindEntry(const char *path);
|
||||
|
||||
void ProcFreeEntry(struct ProcDirEntry *pde);
|
||||
|
||||
extern int ProcStat(const char *file, struct ProcStat *buf);
|
||||
int ProcStat(const char *file, struct ProcStat *buf);
|
||||
|
||||
extern void ProcMountsInit(void);
|
||||
void ProcMountsInit(void);
|
||||
|
||||
extern void ProcUptimeInit(void);
|
||||
void ProcUptimeInit(void);
|
||||
|
||||
extern void ProcFsCacheInit(void);
|
||||
void ProcFsCacheInit(void);
|
||||
|
||||
extern void ProcFdInit(void);
|
||||
void ProcFdInit(void);
|
||||
|
||||
#ifdef LOSCFG_KERNEL_CONTAINER
|
||||
void *ProcfsContainerGet(int fd, unsigned int *containerType);
|
||||
void ProcSysUserInit(void);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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:
|
||||
@@ -82,6 +82,7 @@ typedef unsigned short fmode_t;
|
||||
#define FMODE_READ ((fmode_t)0x1)
|
||||
|
||||
struct ProcFile;
|
||||
struct ProcDirEntry;
|
||||
|
||||
struct ProcFileOperations {
|
||||
char *name;
|
||||
@@ -89,8 +90,18 @@ struct ProcFileOperations {
|
||||
int (*open)(struct Vnode *vnode, struct ProcFile *pf);
|
||||
int (*release)(struct Vnode *vnode, struct ProcFile *pf);
|
||||
int (*read)(struct SeqBuf *m, void *v);
|
||||
ssize_t (*readLink)(struct ProcDirEntry *pde, char *buf, size_t bufLen);
|
||||
};
|
||||
|
||||
#ifdef LOSCFG_KERNEL_PLIMITS
|
||||
struct ProcDirOperations {
|
||||
int (*rmdir)(struct ProcDirEntry *parent, struct ProcDirEntry *pde, const char *name);
|
||||
int (*mkdir)(struct ProcDirEntry *parent, const char *dirName, mode_t mode, struct ProcDirEntry **pde);
|
||||
};
|
||||
#endif
|
||||
|
||||
#define PROC_DATA_STATIC 0
|
||||
#define PROC_DATA_FREE 1
|
||||
struct ProcDirEntry {
|
||||
uint uid;
|
||||
uint gid;
|
||||
@@ -99,6 +110,10 @@ struct ProcDirEntry {
|
||||
const struct ProcFileOperations *procFileOps;
|
||||
struct ProcFile *pf;
|
||||
struct ProcDirEntry *next, *parent, *subdir;
|
||||
#ifdef LOSCFG_KERNEL_PLIMITS
|
||||
const struct ProcDirOperations *procDirOps;
|
||||
#endif
|
||||
int dataType;
|
||||
void *data;
|
||||
atomic_t count; /* open file count */
|
||||
spinlock_t pdeUnloadLock;
|
||||
@@ -109,6 +124,11 @@ struct ProcDirEntry {
|
||||
enum VnodeType type;
|
||||
};
|
||||
|
||||
struct ProcDataParm {
|
||||
void *data;
|
||||
int dataType;
|
||||
};
|
||||
|
||||
struct ProcFile {
|
||||
fmode_t fMode;
|
||||
spinlock_t fLock;
|
||||
@@ -244,6 +264,35 @@ extern struct ProcDirEntry *ProcMkdir(const char *name, struct ProcDirEntry *par
|
||||
extern struct ProcDirEntry *ProcCreate(const char *name, mode_t mode,
|
||||
struct ProcDirEntry *parent, const struct ProcFileOperations *procFops);
|
||||
|
||||
/**
|
||||
* @ingroup procfs
|
||||
* @brief create a proc node
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to create the node by 'name' and parent vnode,
|
||||
* And assignment operation function
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This interface should be called after system initialization.</li>
|
||||
* <li>The parameter name should be a valid string.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param name [IN] Type #const char * The name of the node to be created.
|
||||
* @param mode [IN] Type #mode_t the mode of create's node.
|
||||
* @param parent [IN] Type #struct ProcDirEntry * the parent node of the node to be created.
|
||||
* @param procFops [IN] Type #const struct ProcFileOperations * operation function of the node.
|
||||
* @param data [IN] Type #void * data of the node.
|
||||
*
|
||||
* @retval #NULL Create failed.
|
||||
* @retval #ProcDirEntry* Create successfully.
|
||||
* @par Dependency:
|
||||
* <ul><li>proc_fs.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*
|
||||
*/
|
||||
extern struct ProcDirEntry *ProcCreateData(const char *name, mode_t mode, struct ProcDirEntry *parent,
|
||||
const struct ProcFileOperations *procFileOps, struct ProcDataParm *param);
|
||||
/**
|
||||
* @ingroup procfs
|
||||
* @brief init proc fs
|
||||
@@ -266,6 +315,7 @@ extern struct ProcDirEntry *ProcCreate(const char *name, mode_t mode,
|
||||
*/
|
||||
extern void ProcFsInit(void);
|
||||
|
||||
extern struct ProcDirEntry *VnodeToEntry(struct Vnode *node);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
69
fs/proc/os_adapt/file_sys.c
Normal file
69
fs/proc/os_adapt/file_sys.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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 "fs/fs.h"
|
||||
#include "proc_fs.h"
|
||||
#include "proc_file.h"
|
||||
#include "errno.h"
|
||||
#include "sys/mount.h"
|
||||
|
||||
extern struct fsmap_t g_fsmap[];
|
||||
extern struct fsmap_t g_fsmap_end;
|
||||
|
||||
static int FsFileSysProcRead(struct SeqBuf *seqBuf, void *buf)
|
||||
{
|
||||
(void)buf;
|
||||
|
||||
struct fsmap_t *m = NULL;
|
||||
for (m = &g_fsmap[0]; m != &g_fsmap_end; ++m) {
|
||||
if (m->fs_filesystemtype) {
|
||||
if (m->is_bdfs == true) {
|
||||
(void)LosBufPrintf(seqBuf, "\n %s\n", m->fs_filesystemtype);
|
||||
} else {
|
||||
(void)LosBufPrintf(seqBuf, "%s %s\n", "nodev", m->fs_filesystemtype);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct ProcFileOperations FILESYS_PROC_FOPS = {
|
||||
.read = FsFileSysProcRead,
|
||||
};
|
||||
|
||||
void ProcFileSysInit(void)
|
||||
{
|
||||
struct ProcDirEntry *pde = CreateProcEntry("filesystems", 0, NULL);
|
||||
if (pde == NULL) {
|
||||
PRINT_ERR("creat /proc/filesystems error!\n");
|
||||
return;
|
||||
}
|
||||
pde->procFileOps = &FILESYS_PROC_FOPS;
|
||||
}
|
||||
69
fs/proc/os_adapt/mem_info.c
Normal file
69
fs/proc/os_adapt/mem_info.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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 "internal.h"
|
||||
#include "proc_fs.h"
|
||||
#include "vnode.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_vm_filemap.h"
|
||||
#include "los_memory_pri.h"
|
||||
|
||||
static int SysMemInfoFill(struct SeqBuf *seqBuf, void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
LOS_MEM_POOL_STATUS mem = {0};
|
||||
if (LOS_MemInfoGet(m_aucSysMem0, &mem) == LOS_NOK) {
|
||||
return -EBADF;
|
||||
}
|
||||
(void)LosBufPrintf(seqBuf, "\nUsedSize: %u byte\n", mem.totalUsedSize);
|
||||
(void)LosBufPrintf(seqBuf, "FreeSize: %u byte\n", mem.totalFreeSize);
|
||||
(void)LosBufPrintf(seqBuf, "MaxFreeNodeSize: %u byte\n", mem.maxFreeNodeSize);
|
||||
(void)LosBufPrintf(seqBuf, "UsedNodeNum: %u\n", mem.usedNodeNum);
|
||||
(void)LosBufPrintf(seqBuf, "FreeNodeNum: %u\n", mem.freeNodeNum);
|
||||
#ifdef LOSCFG_MEM_WATERLINE
|
||||
(void)LosBufPrintf(seqBuf, "UsageWaterLine: %u byte\n", mem.usageWaterLine);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct ProcFileOperations SYS_MEMINFO_PROC_FOPS = {
|
||||
.read = SysMemInfoFill,
|
||||
};
|
||||
|
||||
void ProcSysMemInfoInit(void)
|
||||
{
|
||||
struct ProcDirEntry *pde = CreateProcEntry("meminfo", 0, NULL);
|
||||
if (pde == NULL) {
|
||||
PRINT_ERR("create mem_info error!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
pde->procFileOps = &SYS_MEMINFO_PROC_FOPS;
|
||||
}
|
||||
905
fs/proc/os_adapt/plimits_proc.c
Normal file
905
fs/proc/os_adapt/plimits_proc.c
Normal file
@@ -0,0 +1,905 @@
|
||||
/*
|
||||
* 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 <sys/statfs.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "stdlib.h"
|
||||
#include "los_printf.h"
|
||||
#include "los_base.h"
|
||||
#include "los_seq_buf.h"
|
||||
#include "internal.h"
|
||||
#include "proc_fs.h"
|
||||
#include "los_task_pri.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "los_process.h"
|
||||
#include "show.h"
|
||||
#include "vnode.h"
|
||||
#include "proc_file.h"
|
||||
#include "user_copy.h"
|
||||
|
||||
#ifdef LOSCFG_KERNEL_PLIMITS
|
||||
#include "los_plimits.h"
|
||||
|
||||
#define PLIMITS_ENTRY_NAME_MAX 64
|
||||
#define PLIMITERSET_DELETE_ALLOC 4
|
||||
#define UNITPTR_NULL ((uintptr_t)(0xFFFFFFFF))
|
||||
#define PLIMIT_FILE_MODE_READ_WRITE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
|
||||
#define PLIMIT_FILE_MODE_READ_ONLY (S_IRUSR | S_IRGRP | S_IROTH)
|
||||
#define PLIMIT_FILE_MODE_WRITE_ONLY (S_IWUSR)
|
||||
#define PLIMIT_FILE_MODE_MASK_WRITE (~((mode_t)(S_IWUSR)))
|
||||
#define PLIMIT_FILE_MODE_MASK_NONE (~((mode_t)(0)))
|
||||
#define LOS_MAX_CACHE (UINT64)(0xFFFFFFFFFFFFFFFF)
|
||||
#define PLIMIT_CAT_BUF_SIZE 512
|
||||
#define MAX_PROTECTED_PROCESS_ID 14
|
||||
#define UNITPTR_NULL ((uintptr_t)(0xFFFFFFFF))
|
||||
|
||||
static int ShowPids(struct SeqBuf *seqBuf, VOID *data);
|
||||
static ssize_t PidMigrateFromProcLimiterSet(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
|
||||
static ssize_t PidLimitReadPidLimit(struct SeqBuf *seqBuf, VOID *data);
|
||||
static ssize_t PidLimitReadPriorityLimit(struct SeqBuf *seqBuf, VOID *data);
|
||||
static ssize_t PriorityLimitVariableWrite(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
|
||||
static ssize_t PidsMaxVariableWrite(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
|
||||
static ssize_t ProcLimitsShowLimiters(struct SeqBuf *seqBuf, VOID *data);
|
||||
static int ProcfsPlimitsMkdir(struct ProcDirEntry *parent, const char *dirName, mode_t mode, struct ProcDirEntry **pde);
|
||||
static int ProcfsPlimitsRmdir(struct ProcDirEntry *parent, struct ProcDirEntry *pde, const char *name);
|
||||
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
|
||||
static ssize_t MemLimitReadLimit(struct SeqBuf *seqBuf, VOID *data);
|
||||
static ssize_t MemLimitWriteLimit(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
|
||||
static ssize_t MemLimitStatShow(struct SeqBuf *seqBuf, VOID *data);
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
|
||||
static ssize_t IPCLimitReadMqLimit(struct SeqBuf *seqBuf, VOID *data);
|
||||
static ssize_t IPCLimitWriteMqLimit(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
|
||||
static ssize_t IPCLimitReadShmLimit(struct SeqBuf *seqBuf, VOID *data);
|
||||
static ssize_t IPCLimitWriteShmLimit(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
|
||||
static ssize_t IPCLimitShowStat(struct SeqBuf *seqBuf, VOID *data);
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
|
||||
static ssize_t DevLimitWriteAllow(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
|
||||
static ssize_t DevLimitWriteDeny(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
|
||||
static ssize_t DevLimitShow(struct SeqBuf *seqBuf, VOID *data);
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
|
||||
static ssize_t SchedLimitReadPeriod(struct SeqBuf *seqBuf, VOID *data);
|
||||
static ssize_t SchedLimitWritePeriod(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
|
||||
static ssize_t SchedLimitReadQuota(struct SeqBuf *seqBuf, VOID *data);
|
||||
static ssize_t SchedLimitWriteQuota(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
|
||||
static ssize_t SchedLimitShow(struct SeqBuf *seqBuf, VOID *data);
|
||||
#endif
|
||||
|
||||
struct PLimitsEntryOpt {
|
||||
int id;
|
||||
char name[PLIMITS_ENTRY_NAME_MAX];
|
||||
mode_t mode;
|
||||
uintptr_t offset;
|
||||
struct ProcFileOperations ops;
|
||||
};
|
||||
|
||||
static struct ProcDirOperations g_procDirOperations = {
|
||||
.mkdir = ProcfsPlimitsMkdir,
|
||||
.rmdir = ProcfsPlimitsRmdir,
|
||||
};
|
||||
|
||||
static struct PLimitsEntryOpt g_plimitsEntryOpts[] = {
|
||||
{
|
||||
.id = PROCESS_LIMITER_COUNT,
|
||||
.name = "plimits.limiters",
|
||||
.mode = PLIMIT_FILE_MODE_READ_ONLY,
|
||||
.offset = UNITPTR_NULL,
|
||||
.ops = {
|
||||
.read = ProcLimitsShowLimiters,
|
||||
}
|
||||
},
|
||||
{
|
||||
.id = PROCESS_LIMITER_COUNT,
|
||||
.name = "plimits.procs",
|
||||
.mode = PLIMIT_FILE_MODE_READ_WRITE,
|
||||
.offset = UNITPTR_NULL,
|
||||
.ops = {
|
||||
.read = ShowPids,
|
||||
.write = PidMigrateFromProcLimiterSet,
|
||||
},
|
||||
},
|
||||
{
|
||||
.id = PROCESS_LIMITER_ID_PIDS,
|
||||
.name = "pids.max",
|
||||
.mode = PLIMIT_FILE_MODE_READ_WRITE,
|
||||
.offset = 0,
|
||||
.ops = {
|
||||
.read = PidLimitReadPidLimit,
|
||||
.write = PidsMaxVariableWrite,
|
||||
},
|
||||
},
|
||||
{
|
||||
.id = PROCESS_LIMITER_ID_PIDS,
|
||||
.name = "pids.priority",
|
||||
.mode = PLIMIT_FILE_MODE_READ_WRITE,
|
||||
.offset = 0,
|
||||
.ops = {
|
||||
.read = PidLimitReadPriorityLimit,
|
||||
.write = PriorityLimitVariableWrite,
|
||||
},
|
||||
},
|
||||
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
|
||||
{
|
||||
.id = PROCESS_LIMITER_ID_MEM,
|
||||
.name = "memory.limit",
|
||||
.mode = PLIMIT_FILE_MODE_READ_WRITE,
|
||||
.offset = 0,
|
||||
.ops = {
|
||||
.read = MemLimitReadLimit,
|
||||
.write = MemLimitWriteLimit,
|
||||
},
|
||||
},
|
||||
{
|
||||
.id = PROCESS_LIMITER_ID_MEM,
|
||||
.name = "memory.stat",
|
||||
.mode = PLIMIT_FILE_MODE_READ_ONLY,
|
||||
.offset = UNITPTR_NULL,
|
||||
.ops = {
|
||||
.read = MemLimitStatShow,
|
||||
}
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
|
||||
{
|
||||
.id = PROCESS_LIMITER_ID_IPC,
|
||||
.name = "ipc.mq_limit",
|
||||
.mode = PLIMIT_FILE_MODE_READ_WRITE,
|
||||
.offset = 0,
|
||||
.ops = {
|
||||
.read = IPCLimitReadMqLimit,
|
||||
.write = IPCLimitWriteMqLimit,
|
||||
}
|
||||
},
|
||||
{
|
||||
.id = PROCESS_LIMITER_ID_IPC,
|
||||
.name = "ipc.shm_limit",
|
||||
.mode = PLIMIT_FILE_MODE_READ_WRITE,
|
||||
.offset = 0,
|
||||
.ops = {
|
||||
.read = IPCLimitReadShmLimit,
|
||||
.write = IPCLimitWriteShmLimit,
|
||||
}
|
||||
},
|
||||
{
|
||||
.id = PROCESS_LIMITER_ID_IPC,
|
||||
.name = "ipc.stat",
|
||||
.mode = PLIMIT_FILE_MODE_READ_ONLY,
|
||||
.offset = UNITPTR_NULL,
|
||||
.ops = {
|
||||
.read = IPCLimitShowStat,
|
||||
}
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
|
||||
{
|
||||
.id = PROCESS_LIMITER_ID_DEV,
|
||||
.name = "devices.allow",
|
||||
.mode = PLIMIT_FILE_MODE_WRITE_ONLY,
|
||||
.offset = UNITPTR_NULL,
|
||||
.ops = {
|
||||
.write = DevLimitWriteAllow,
|
||||
}
|
||||
},
|
||||
{
|
||||
.id = PROCESS_LIMITER_ID_DEV,
|
||||
.name = "devices.deny",
|
||||
.mode = PLIMIT_FILE_MODE_WRITE_ONLY,
|
||||
.offset = UNITPTR_NULL,
|
||||
.ops = {
|
||||
.write = DevLimitWriteDeny,
|
||||
}
|
||||
},
|
||||
{
|
||||
.id = PROCESS_LIMITER_ID_DEV,
|
||||
.name = "devices.list",
|
||||
.mode = PLIMIT_FILE_MODE_READ_ONLY,
|
||||
.offset = 0,
|
||||
.ops = {
|
||||
.read = DevLimitShow,
|
||||
}
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
|
||||
{
|
||||
.id = PROCESS_LIMITER_ID_SCHED,
|
||||
.name = "sched.period",
|
||||
.mode = PLIMIT_FILE_MODE_READ_WRITE,
|
||||
.offset = 0,
|
||||
.ops = {
|
||||
.read = SchedLimitReadPeriod,
|
||||
.write = SchedLimitWritePeriod,
|
||||
},
|
||||
},
|
||||
{
|
||||
.id = PROCESS_LIMITER_ID_SCHED,
|
||||
.name = "sched.quota",
|
||||
.mode = PLIMIT_FILE_MODE_READ_WRITE,
|
||||
.offset = 0,
|
||||
.ops = {
|
||||
.read = SchedLimitReadQuota,
|
||||
.write = SchedLimitWriteQuota,
|
||||
},
|
||||
},
|
||||
{
|
||||
.id = PROCESS_LIMITER_ID_SCHED,
|
||||
.name = "sched.stat",
|
||||
.mode = PLIMIT_FILE_MODE_READ_ONLY,
|
||||
.offset = UNITPTR_NULL,
|
||||
.ops = {
|
||||
.read = SchedLimitShow,
|
||||
}
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
static unsigned int MemUserCopy(const char *src, size_t len, char **kbuf)
|
||||
{
|
||||
if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, len)) {
|
||||
char *kernelBuf = LOS_MemAlloc(m_aucSysMem1, len + 1);
|
||||
if (kernelBuf == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
if (LOS_ArchCopyFromUser(kernelBuf, src, len) != 0) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, kernelBuf);
|
||||
return EFAULT;
|
||||
}
|
||||
kernelBuf[len] = '\0';
|
||||
*kbuf = kernelBuf;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline struct ProcDirEntry *GetCurrDirectory(struct ProcDirEntry *dirEntry)
|
||||
{
|
||||
return ((dirEntry == NULL) || S_ISDIR(dirEntry->mode)) ? dirEntry : dirEntry->parent;
|
||||
}
|
||||
|
||||
static inline ProcLimiterSet *GetProcLimiterSetFromDirEntry(struct ProcDirEntry *dirEntry)
|
||||
{
|
||||
struct ProcDirEntry *currDirectory = GetCurrDirectory(dirEntry);
|
||||
return (currDirectory == NULL) || (currDirectory->data == NULL) ? NULL : (ProcLimiterSet *)currDirectory->data;
|
||||
}
|
||||
|
||||
static struct ProcDirEntry *ProcCreateLimiterFiles(struct ProcDirEntry *parentEntry,
|
||||
struct PLimitsEntryOpt *entryOpt,
|
||||
mode_t mode, void *data)
|
||||
{
|
||||
struct ProcDataParm dataParm = {
|
||||
.data = data,
|
||||
.dataType = PROC_DATA_STATIC,
|
||||
};
|
||||
struct ProcDirEntry *plimitFile = ProcCreateData(entryOpt->name, entryOpt->mode & mode, parentEntry,
|
||||
&entryOpt->ops, &dataParm);
|
||||
if (plimitFile == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return plimitFile;
|
||||
}
|
||||
|
||||
static void ProcLimiterDirEntryInit(struct ProcDirEntry *dirEntry, unsigned mask, mode_t mode)
|
||||
{
|
||||
struct ProcDirEntry *currDir = GetCurrDirectory(dirEntry);
|
||||
if (currDir == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
ProcLimiterSet *plimiterData = (ProcLimiterSet *)currDir->data;
|
||||
if (plimiterData == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int index = 0; index < (sizeof(g_plimitsEntryOpts) / sizeof(struct PLimitsEntryOpt)); index++) {
|
||||
struct PLimitsEntryOpt *entryOpt = &g_plimitsEntryOpts[index];
|
||||
enum ProcLimiterID plimiterType = entryOpt->id;
|
||||
if (!(BIT(plimiterType) & mask)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
void *head = (entryOpt->offset == UNITPTR_NULL) ?
|
||||
plimiterData : (void *)plimiterData->limitsList[plimiterType];
|
||||
struct ProcDirEntry *entry = ProcCreateLimiterFiles(currDir, entryOpt, mode, head);
|
||||
if (entry == NULL) {
|
||||
RemoveProcEntry(currDir->name, NULL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static ssize_t PLimitsCopyLimits(struct ProcDirEntry *dirEntry)
|
||||
{
|
||||
struct ProcDirEntry *parentPde = dirEntry->parent;
|
||||
ProcLimiterSet *parentPLimits = (ProcLimiterSet *)parentPde->data;
|
||||
if (parentPLimits == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ProcLimiterSet *newPLimits = OsPLimitsCreate(parentPLimits);
|
||||
if (newPLimits == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
dirEntry->data = (VOID *)newPLimits;
|
||||
dirEntry->dataType = PROC_DATA_STATIC;
|
||||
dirEntry->procDirOps = parentPde->procDirOps;
|
||||
ProcLimiterDirEntryInit(dirEntry, newPLimits->mask, PLIMIT_FILE_MODE_MASK_NONE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ProcfsPlimitsMkdir(struct ProcDirEntry *parent, const char *dirName, mode_t mode, struct ProcDirEntry **pde)
|
||||
{
|
||||
int ret;
|
||||
if (strcmp(parent->name, "plimits") != 0) {
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
struct ProcDirEntry *plimitDir = ProcCreateData(dirName, S_IFDIR | mode, parent, NULL, NULL);
|
||||
if (plimitDir == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = PLimitsCopyLimits(plimitDir);
|
||||
if (ret != LOS_OK) {
|
||||
ProcFreeEntry(plimitDir);
|
||||
return -ENOSYS;
|
||||
}
|
||||
*pde = plimitDir;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ProcfsPlimitsRmdir(struct ProcDirEntry *parent, struct ProcDirEntry *pde, const char *name)
|
||||
{
|
||||
if (pde == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ProcLimiterSet *plimits = GetProcLimiterSetFromDirEntry(pde);
|
||||
pde->data = NULL;
|
||||
|
||||
unsigned ret = OsPLimitsFree(plimits);
|
||||
if (ret != 0) {
|
||||
pde->data = plimits;
|
||||
return -ret;
|
||||
}
|
||||
|
||||
spin_lock(&procfsLock);
|
||||
ProcDetachNode(pde);
|
||||
spin_unlock(&procfsLock);
|
||||
|
||||
RemoveProcEntryTravalsal(pde->subdir);
|
||||
|
||||
ProcFreeEntry(pde);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t ProcLimitsShowLimiters(struct SeqBuf *seqBuf, VOID *data)
|
||||
{
|
||||
ProcLimiterSet *plimits = (ProcLimiterSet *)data;
|
||||
UINT32 mask;
|
||||
if (plimits == NULL) {
|
||||
return -LOS_NOK;
|
||||
}
|
||||
mask = plimits->mask;
|
||||
|
||||
if (mask & BIT(PROCESS_LIMITER_ID_PIDS)) {
|
||||
LosBufPrintf(seqBuf, "%s ", "pids");
|
||||
}
|
||||
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
|
||||
if (mask & BIT(PROCESS_LIMITER_ID_MEM)) {
|
||||
LosBufPrintf(seqBuf, "%s ", "memory");
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
|
||||
if (mask & BIT(PROCESS_LIMITER_ID_IPC)) {
|
||||
LosBufPrintf(seqBuf, "%s ", "ipc");
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
|
||||
if (mask & BIT(PROCESS_LIMITER_ID_DEV)) {
|
||||
LosBufPrintf(seqBuf, "%s ", "devices");
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
|
||||
if (mask & BIT(PROCESS_LIMITER_ID_SCHED)) {
|
||||
LosBufPrintf(seqBuf, "%s ", "sched");
|
||||
}
|
||||
#endif
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#define PLIMITS_PID_STR_LENGTH 4
|
||||
static int ShowPids(struct SeqBuf *seqBuf, VOID *data)
|
||||
{
|
||||
unsigned int size, pidMax;
|
||||
if (data == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
const ProcLimiterSet *plimits = (const ProcLimiterSet *)data;
|
||||
pidMax = LOS_GetSystemProcessMaximum();
|
||||
size = pidMax * sizeof(unsigned int);
|
||||
unsigned int *pids = (unsigned int *)LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (pids == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
(void)memset_s(pids, size, 0, size);
|
||||
|
||||
unsigned int ret = OsPLimitsPidsGet(plimits, pids, size);
|
||||
if (ret != LOS_OK) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pids);
|
||||
return -ret;
|
||||
}
|
||||
|
||||
(void)LosBufPrintf(seqBuf, "\n");
|
||||
for (unsigned int index = 0; index < pidMax; index++) {
|
||||
if (pids[index] == 0) {
|
||||
continue;
|
||||
}
|
||||
(void)LosBufPrintf(seqBuf, "%u ", index);
|
||||
}
|
||||
(void)LOS_MemFree(m_aucSysMem1, pids);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long long int GetPidLimitValue(struct ProcFile *pf, const CHAR *buf, size_t count)
|
||||
{
|
||||
long long int value;
|
||||
char *kbuf = NULL;
|
||||
|
||||
if ((pf == NULL) || (pf->pPDE == NULL) || (buf == NULL) || (count <= 0)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
unsigned ret = MemUserCopy(buf, count, &kbuf);
|
||||
if (ret != 0) {
|
||||
return -ret;
|
||||
} else if ((ret == 0) && (kbuf != NULL)) {
|
||||
buf = (const char *)kbuf;
|
||||
}
|
||||
|
||||
if (strspn(buf, "0123456789") != count) {
|
||||
(void)LOS_MemFree(m_aucSysMem1, kbuf);
|
||||
return -EINVAL;
|
||||
}
|
||||
value = strtoll(buf, NULL, 10); /* 10: decimal */
|
||||
(void)LOS_MemFree(m_aucSysMem1, kbuf);
|
||||
return value;
|
||||
}
|
||||
|
||||
static ssize_t PidMigrateFromProcLimiterSet(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
(VOID)ppos;
|
||||
unsigned ret;
|
||||
|
||||
long long int pid = GetPidLimitValue(pf, buf, count);
|
||||
if (pid < 0) {
|
||||
return pid;
|
||||
}
|
||||
|
||||
ProcLimiterSet *plimits = GetCurrDirectory(pf->pPDE)->data;
|
||||
ret = OsPLimitsAddPid(plimits, (unsigned int)pid);
|
||||
if (ret != LOS_OK) {
|
||||
return -ret;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t PidLimitReadPidLimit(struct SeqBuf *seqBuf, VOID *data)
|
||||
{
|
||||
PidLimit *pidLimit = (PidLimit *)data;
|
||||
if ((seqBuf == NULL) || (pidLimit == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
(void)LosBufPrintf(seqBuf, "%u\n", pidLimit->pidLimit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t PidLimitReadPriorityLimit(struct SeqBuf *seqBuf, VOID *data)
|
||||
{
|
||||
PidLimit *pidLimit = (PidLimit *)data;
|
||||
if ((seqBuf == NULL) || (pidLimit == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
(void)LosBufPrintf(seqBuf, "%u\n", pidLimit->priorityLimit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t PriorityLimitVariableWrite(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
(void)ppos;
|
||||
long long int value = GetPidLimitValue(pf, buf, count);
|
||||
if (value < 0) {
|
||||
return value;
|
||||
}
|
||||
|
||||
PidLimit *pidLimit = (PidLimit *)pf->pPDE->data;
|
||||
unsigned ret = PidLimitSetPriorityLimit(pidLimit, (unsigned)value);
|
||||
if (ret != LOS_OK) {
|
||||
return -ret;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t PidsMaxVariableWrite(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
(void)ppos;
|
||||
long long int value = GetPidLimitValue(pf, buf, count);
|
||||
if (value < 0) {
|
||||
return value;
|
||||
}
|
||||
|
||||
PidLimit *pidLimit = (PidLimit *)pf->pPDE->data;
|
||||
unsigned ret = PidLimitSetPidLimit(pidLimit, (unsigned)value);
|
||||
if (ret != LOS_OK) {
|
||||
return -ret;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
|
||||
static ssize_t MemLimitReadLimit(struct SeqBuf *seqBuf, VOID *data)
|
||||
{
|
||||
ProcMemLimiter *memLimit = (ProcMemLimiter *)data;
|
||||
if ((seqBuf == NULL) || (memLimit == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
(void)LosBufPrintf(seqBuf, "%llu\n", memLimit->limit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t MemLimitWriteLimit(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
(void)ppos;
|
||||
long long int value = GetPidLimitValue(pf, buf, count);
|
||||
if ((value < 0) || (value > (long long int)OS_NULL_INT)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
ProcMemLimiter *memLimit = (ProcMemLimiter *)pf->pPDE->data;
|
||||
unsigned ret = OsMemLimitSetMemLimit(memLimit, (unsigned long long)value);
|
||||
if (ret != LOS_OK) {
|
||||
return -ret;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t MemLimitStatShow(struct SeqBuf *seqBuf, VOID *data)
|
||||
{
|
||||
ProcLimiterSet *plimits = (ProcLimiterSet *)data;
|
||||
if ((seqBuf == NULL) || (plimits == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
UINT32 pidMax = LOS_GetSystemProcessMaximum();
|
||||
UINT32 size = sizeof(ProcMemLimiter) + pidMax * sizeof(unsigned long long);
|
||||
unsigned long long *usage = (unsigned long long *)LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (usage == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
(void)memset_s(usage, size, 0, size);
|
||||
|
||||
unsigned int ret = OsPLimitsMemUsageGet(plimits, usage, size);
|
||||
if (ret != LOS_OK) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, usage);
|
||||
return -ret;
|
||||
}
|
||||
|
||||
ProcMemLimiter *memLimit = (ProcMemLimiter *)usage;
|
||||
unsigned long long *memUsage = (unsigned long long *)((uintptr_t)usage + sizeof(ProcMemLimiter));
|
||||
(void)LosBufPrintf(seqBuf, "\nMem used: %llu\n", memLimit->usage);
|
||||
(void)LosBufPrintf(seqBuf, "Mem peak: %llu\n", memLimit->peak);
|
||||
(void)LosBufPrintf(seqBuf, "Mem failed count: %u\n", memLimit->failcnt);
|
||||
|
||||
for (unsigned int index = 0; index < pidMax; index++) {
|
||||
if (memUsage[index] == 0) {
|
||||
continue;
|
||||
}
|
||||
(void)LosBufPrintf(seqBuf, "PID: %u mem used: %llu \n", index, memUsage[index]);
|
||||
}
|
||||
(void)LOS_MemFree(m_aucSysMem1, usage);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
|
||||
static ssize_t IPCLimitReadMqLimit(struct SeqBuf *seqBuf, VOID *data)
|
||||
{
|
||||
ProcIPCLimit *ipcLimit = (ProcIPCLimit *)data;
|
||||
if ((seqBuf == NULL) || (ipcLimit == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
(void)LosBufPrintf(seqBuf, "%u\n", ipcLimit->mqCountLimit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t IPCLimitWriteMqLimit(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
(void)ppos;
|
||||
long long int value = GetPidLimitValue(pf, buf, count);
|
||||
if (value < 0) {
|
||||
return value;
|
||||
}
|
||||
|
||||
ProcIPCLimit *ipcLimit = (ProcIPCLimit *)pf->pPDE->data;
|
||||
unsigned ret = OsIPCLimitSetMqLimit(ipcLimit, (unsigned long long)value);
|
||||
if (ret != LOS_OK) {
|
||||
return -ret;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t IPCLimitReadShmLimit(struct SeqBuf *seqBuf, VOID *data)
|
||||
{
|
||||
ProcIPCLimit *ipcLimit = (ProcIPCLimit *)data;
|
||||
if ((seqBuf == NULL) || (ipcLimit == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
(void)LosBufPrintf(seqBuf, "%u\n", ipcLimit->shmSizeLimit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t IPCLimitWriteShmLimit(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
(void)ppos;
|
||||
long long int value = GetPidLimitValue(pf, buf, count);
|
||||
if ((value < 0) || (value > (long long int)OS_NULL_INT)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
ProcIPCLimit *ipcLimit = (ProcIPCLimit *)pf->pPDE->data;
|
||||
unsigned ret = OsIPCLimitSetShmLimit(ipcLimit, (unsigned long long)value);
|
||||
if (ret != LOS_OK) {
|
||||
return -ret;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t IPCLimitShowStat(struct SeqBuf *seqBuf, VOID *data)
|
||||
{
|
||||
ProcLimiterSet *plimits = (ProcLimiterSet *)data;
|
||||
if ((seqBuf == NULL) || (plimits == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
unsigned int size = sizeof(ProcIPCLimit);
|
||||
ProcIPCLimit *newIPCLimit = (ProcIPCLimit *)LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (newIPCLimit == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
(void)memset_s(newIPCLimit, size, 0, size);
|
||||
|
||||
unsigned int ret = OsPLimitsIPCStatGet(plimits, newIPCLimit, size);
|
||||
if (ret != LOS_OK) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, newIPCLimit);
|
||||
return -ret;
|
||||
}
|
||||
|
||||
(void)LosBufPrintf(seqBuf, "mq count: %u\n", newIPCLimit->mqCount);
|
||||
(void)LosBufPrintf(seqBuf, "mq failed count: %u\n", newIPCLimit->mqFailedCount);
|
||||
(void)LosBufPrintf(seqBuf, "shm size: %u\n", newIPCLimit->shmSize);
|
||||
(void)LosBufPrintf(seqBuf, "shm failed count: %u\n", newIPCLimit->shmFailedCount);
|
||||
(void)LOS_MemFree(m_aucSysMem1, newIPCLimit);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
|
||||
static ssize_t DevLimitWriteAllow(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
(void)ppos;
|
||||
char *kbuf = NULL;
|
||||
|
||||
if ((pf == NULL) || (pf->pPDE == NULL) || (buf == NULL) || (count <= 0)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
unsigned ret = MemUserCopy(buf, count, &kbuf);
|
||||
if (ret != 0) {
|
||||
return -ret;
|
||||
} else if ((ret == 0) && (kbuf != NULL)) {
|
||||
buf = (const char *)kbuf;
|
||||
}
|
||||
|
||||
ProcLimiterSet *plimit = (ProcLimiterSet *)pf->pPDE->data;
|
||||
ret = OsDevLimitWriteAllow(plimit, buf, count);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, kbuf);
|
||||
if (ret != LOS_OK) {
|
||||
return -ret;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t DevLimitWriteDeny(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
(void)ppos;
|
||||
char *kbuf = NULL;
|
||||
|
||||
if ((pf == NULL) || (pf->pPDE == NULL) || (buf == NULL) || (count <= 0)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
unsigned ret = MemUserCopy(buf, count, &kbuf);
|
||||
if (ret != 0) {
|
||||
return -ret;
|
||||
} else if ((ret == 0) && (kbuf != NULL)) {
|
||||
buf = (const char *)kbuf;
|
||||
}
|
||||
|
||||
ProcLimiterSet *plimit = (ProcLimiterSet *)pf->pPDE->data;
|
||||
ret = OsDevLimitWriteDeny(plimit, buf, count);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, kbuf);
|
||||
if (ret != LOS_OK) {
|
||||
return -ret;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t DevLimitShow(struct SeqBuf *seqBuf, VOID *data)
|
||||
{
|
||||
ProcDevLimit *devLimit = (ProcDevLimit *)data;
|
||||
if ((seqBuf == NULL) || (devLimit == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
unsigned ret = OsDevLimitShow(devLimit, seqBuf);
|
||||
if (ret != LOS_OK) {
|
||||
return -ret;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
|
||||
static ssize_t SchedLimitReadPeriod(struct SeqBuf *seqBuf, VOID *data)
|
||||
{
|
||||
ProcSchedLimiter *schedLimit = (ProcSchedLimiter *)data;
|
||||
if ((seqBuf == NULL) || (schedLimit == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
(void)LosBufPrintf(seqBuf, "%lld\n", schedLimit->period);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t SchedLimitWritePeriod(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
(void)ppos;
|
||||
long long int value = GetPidLimitValue(pf, buf, count);
|
||||
if (value < 0) {
|
||||
return value;
|
||||
}
|
||||
|
||||
ProcSchedLimiter *schedLimit = (ProcSchedLimiter *)pf->pPDE->data;
|
||||
unsigned ret = OsSchedLimitSetPeriod(schedLimit, (unsigned long long)value);
|
||||
if (ret != LOS_OK) {
|
||||
return -ret;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t SchedLimitReadQuota(struct SeqBuf *seqBuf, VOID *data)
|
||||
{
|
||||
ProcSchedLimiter *schedLimit = (ProcSchedLimiter *)data;
|
||||
if ((seqBuf == NULL) || (schedLimit == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
(void)LosBufPrintf(seqBuf, "%lld\n", schedLimit->quota);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t SchedLimitWriteQuota(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
(void)ppos;
|
||||
long long int value = GetPidLimitValue(pf, buf, count);
|
||||
if (value < 0) {
|
||||
return value;
|
||||
}
|
||||
|
||||
ProcSchedLimiter *schedLimit = (ProcSchedLimiter *)pf->pPDE->data;
|
||||
unsigned ret = OsSchedLimitSetQuota(schedLimit, (unsigned long long)value);
|
||||
if (ret != LOS_OK) {
|
||||
return -ret;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
#define TIME_CYCLE_TO_US(time) ((((UINT64)time) * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US)
|
||||
#define SCHED_DEFAULT_VALUE (0x101010101010101)
|
||||
|
||||
static ssize_t SchedLimitShow(struct SeqBuf *seqBuf, VOID *data)
|
||||
{
|
||||
ProcLimiterSet *plimits = (ProcLimiterSet *)data;
|
||||
if ((seqBuf == NULL) || (plimits == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
UINT32 pidMax = LOS_GetSystemProcessMaximum();
|
||||
UINT32 size = pidMax * sizeof(unsigned long long);
|
||||
unsigned long long *usage = (unsigned long long *)LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (usage == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
(void)memset_s(usage, size, 1, size);
|
||||
|
||||
unsigned int ret = OsPLimitsSchedUsageGet(plimits, usage, size);
|
||||
if (ret != LOS_OK) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, usage);
|
||||
return -ret;
|
||||
}
|
||||
|
||||
for (unsigned int index = 0; index < pidMax; index++) {
|
||||
if (usage[index] == SCHED_DEFAULT_VALUE) {
|
||||
continue;
|
||||
}
|
||||
(void)LosBufPrintf(seqBuf, "PID: %u runTime: %llu us\n", index, TIME_CYCLE_TO_US(usage[index]));
|
||||
}
|
||||
(void)LOS_MemFree(m_aucSysMem1, usage);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define PROC_PLIMITS_MODE (S_IFDIR | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
|
||||
void ProcLimitsInit(void)
|
||||
{
|
||||
struct ProcDirEntry *parentPDE = CreateProcEntry("plimits", PROC_PLIMITS_MODE, NULL);
|
||||
if (parentPDE == NULL) {
|
||||
return;
|
||||
}
|
||||
ProcLimiterSet *plimits = OsRootPLimitsGet();
|
||||
parentPDE->procDirOps = &g_procDirOperations;
|
||||
parentPDE->data = (VOID *)plimits;
|
||||
parentPDE->dataType = PROC_DATA_STATIC;
|
||||
plimits->mask = BIT(PROCESS_LIMITER_ID_PIDS) | BIT(PROCESS_LIMITER_COUNT);
|
||||
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
|
||||
plimits->mask |= BIT(PROCESS_LIMITER_ID_MEM);
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
|
||||
plimits->mask |= BIT(PROCESS_LIMITER_ID_IPC);
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
|
||||
plimits->mask |= BIT(PROCESS_LIMITER_ID_DEV);
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
|
||||
plimits->mask |= BIT(PROCESS_LIMITER_ID_SCHED);
|
||||
#endif
|
||||
ProcLimiterDirEntryInit(parentPDE, plimits->mask, PLIMIT_FILE_MODE_MASK_WRITE);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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:
|
||||
@@ -68,6 +68,16 @@ void ProcFsInit(void)
|
||||
#ifdef LOSCFG_KERNEL_PM
|
||||
ProcPmInit();
|
||||
#endif
|
||||
#ifdef LOSCFG_PROC_PROCESS_DIR
|
||||
ProcSysMemInfoInit();
|
||||
ProcFileSysInit();
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_PLIMITS
|
||||
ProcLimitsInit();
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_CONTAINER
|
||||
ProcSysUserInit();
|
||||
#endif
|
||||
}
|
||||
|
||||
LOS_MODULE_INIT(ProcFsInit, LOS_INIT_LEVEL_KMOD_EXTENDED);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2021-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,7 +45,7 @@
|
||||
static struct VnodeOps g_procfsVops;
|
||||
static struct file_operations_vfs g_procfsFops;
|
||||
|
||||
static struct ProcDirEntry *VnodeToEntry(struct Vnode *node)
|
||||
struct ProcDirEntry *VnodeToEntry(struct Vnode *node)
|
||||
{
|
||||
return (struct ProcDirEntry *)(node->data);
|
||||
}
|
||||
@@ -125,10 +125,16 @@ int VfsProcfsRead(struct file *filep, char *buffer, size_t buflen)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
VnodeHold();
|
||||
entry = VnodeToEntry(filep->f_vnode);
|
||||
if (entry == NULL) {
|
||||
VnodeDrop();
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
size = (ssize_t)ReadProcFile(entry, (void *)buffer, buflen);
|
||||
filep->f_pos = entry->pf->fPos;
|
||||
|
||||
VnodeDrop();
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -140,10 +146,16 @@ int VfsProcfsWrite(struct file *filep, const char *buffer, size_t buflen)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
VnodeHold();
|
||||
entry = VnodeToEntry(filep->f_vnode);
|
||||
if (entry == NULL) {
|
||||
VnodeDrop();
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
size = (ssize_t)WriteProcFile(entry, (void *)buffer, buflen);
|
||||
filep->f_pos = entry->pf->fPos;
|
||||
|
||||
VnodeDrop();
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -156,6 +168,7 @@ int VfsProcfsLookup(struct Vnode *parent, const char *name, int len, struct Vnod
|
||||
if (entry == NULL) {
|
||||
return -ENODATA;
|
||||
}
|
||||
|
||||
entry = entry->subdir;
|
||||
while (1) {
|
||||
if (entry == NULL) {
|
||||
@@ -214,21 +227,70 @@ int VfsProcfsUnmount(void *handle, struct Vnode **blkdriver)
|
||||
|
||||
int VfsProcfsStat(struct Vnode *node, struct stat *buf)
|
||||
{
|
||||
VnodeHold();
|
||||
struct ProcDirEntry *entry = VnodeToEntry(node);
|
||||
|
||||
if (entry == NULL) {
|
||||
VnodeDrop();
|
||||
return -EPERM;
|
||||
}
|
||||
(void)memset_s(buf, sizeof(struct stat), 0, sizeof(struct stat));
|
||||
buf->st_mode = entry->mode;
|
||||
|
||||
VnodeDrop();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_PLIMITS
|
||||
int VfsProcfsMkdir(struct Vnode *parent, const char *dirName, mode_t mode, struct Vnode **vnode)
|
||||
{
|
||||
struct ProcDirEntry *parentEntry = VnodeToEntry(parent);
|
||||
struct ProcDirEntry *pde = NULL;
|
||||
if ((parentEntry->procDirOps == NULL) || (parentEntry->procDirOps->mkdir == NULL)) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
int ret = parentEntry->procDirOps->mkdir(parentEntry, dirName, mode, &pde);
|
||||
if ((ret < 0) || (pde == NULL)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
*vnode = EntryToVnode(pde);
|
||||
(*vnode)->vop = parent->vop;
|
||||
(*vnode)->parent = parent;
|
||||
(*vnode)->originMount = parent->originMount;
|
||||
if ((*vnode)->type == VNODE_TYPE_DIR) {
|
||||
(*vnode)->mode = S_IFDIR | PROCFS_DEFAULT_MODE;
|
||||
} else {
|
||||
(*vnode)->mode = S_IFREG | PROCFS_DEFAULT_MODE;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int VfsProcfsRmdir(struct Vnode *parent, struct Vnode *vnode, const char *dirName)
|
||||
{
|
||||
if (parent == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
struct ProcDirEntry *parentEntry = VnodeToEntry(parent);
|
||||
if ((parentEntry->procDirOps == NULL) || (parentEntry->procDirOps->rmdir == NULL)) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
struct ProcDirEntry *dirEntry = VnodeToEntry(vnode);
|
||||
int ret = parentEntry->procDirOps->rmdir(parentEntry, dirEntry, dirName);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
vnode->data = NULL;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int VfsProcfsReaddir(struct Vnode *node, struct fs_dirent_s *dir)
|
||||
{
|
||||
int result;
|
||||
char *buffer = NULL;
|
||||
int buflen = NAME_MAX;
|
||||
unsigned int min_size;
|
||||
unsigned int dst_name_size;
|
||||
unsigned int minSize, dstNameSize;
|
||||
struct ProcDirEntry *pde = NULL;
|
||||
int i = 0;
|
||||
|
||||
@@ -238,28 +300,35 @@ int VfsProcfsReaddir(struct Vnode *node, struct fs_dirent_s *dir)
|
||||
if (node->type != VNODE_TYPE_DIR) {
|
||||
return -ENOTDIR;
|
||||
}
|
||||
VnodeHold();
|
||||
pde = VnodeToEntry(node);
|
||||
if (pde == NULL) {
|
||||
VnodeDrop();
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
while (i < dir->read_cnt) {
|
||||
buffer = (char *)zalloc(sizeof(char) * NAME_MAX);
|
||||
if (buffer == NULL) {
|
||||
VnodeDrop();
|
||||
PRINT_ERR("malloc failed\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
result = ReadProcFile(pde, (void *)buffer, buflen);
|
||||
result = ReadProcFile(pde, (void *)buffer, NAME_MAX);
|
||||
if (result != ENOERR) {
|
||||
free(buffer);
|
||||
break;
|
||||
}
|
||||
dst_name_size = sizeof(dir->fd_dir[i].d_name);
|
||||
min_size = (dst_name_size < NAME_MAX) ? dst_name_size : NAME_MAX;
|
||||
result = strncpy_s(dir->fd_dir[i].d_name, dst_name_size, buffer, min_size);
|
||||
dstNameSize = sizeof(dir->fd_dir[i].d_name);
|
||||
minSize = (dstNameSize < NAME_MAX) ? dstNameSize : NAME_MAX;
|
||||
result = strncpy_s(dir->fd_dir[i].d_name, dstNameSize, buffer, minSize);
|
||||
if (result != EOK) {
|
||||
VnodeDrop();
|
||||
free(buffer);
|
||||
return -ENAMETOOLONG;
|
||||
}
|
||||
dir->fd_dir[i].d_name[dst_name_size - 1] = '\0';
|
||||
dir->fd_dir[i].d_name[dstNameSize - 1] = '\0';
|
||||
dir->fd_position++;
|
||||
dir->fd_dir[i].d_off = dir->fd_position;
|
||||
dir->fd_dir[i].d_reclen = (uint16_t)sizeof(struct dirent);
|
||||
@@ -267,19 +336,26 @@ int VfsProcfsReaddir(struct Vnode *node, struct fs_dirent_s *dir)
|
||||
i++;
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
VnodeDrop();
|
||||
return i;
|
||||
}
|
||||
|
||||
int VfsProcfsOpendir(struct Vnode *node, struct fs_dirent_s *dir)
|
||||
{
|
||||
VnodeHold();
|
||||
struct ProcDirEntry *pde = VnodeToEntry(node);
|
||||
if (pde == NULL) {
|
||||
VnodeDrop();
|
||||
return -EINVAL;
|
||||
}
|
||||
pde->pdirCurrent = pde->subdir;
|
||||
pde->pf->fPos = 0;
|
||||
|
||||
pde->pdirCurrent = pde->subdir;
|
||||
if (pde->pf == NULL) {
|
||||
VnodeDrop();
|
||||
return -EINVAL;
|
||||
}
|
||||
pde->pf->fPos = 0;
|
||||
VnodeDrop();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
@@ -288,8 +364,14 @@ int VfsProcfsOpen(struct file *filep)
|
||||
if (filep == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
VnodeHold();
|
||||
struct Vnode *node = filep->f_vnode;
|
||||
struct ProcDirEntry *pde = VnodeToEntry(node);
|
||||
if (pde == NULL) {
|
||||
VnodeDrop();
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
if (ProcOpen(pde->pf) != OK) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
@@ -301,6 +383,7 @@ int VfsProcfsOpen(struct file *filep)
|
||||
pde->pf->fPos = 0;
|
||||
}
|
||||
filep->f_priv = (void *)pde;
|
||||
VnodeDrop();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
@@ -310,15 +393,22 @@ int VfsProcfsClose(struct file *filep)
|
||||
if (filep == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
VnodeHold();
|
||||
struct Vnode *node = filep->f_vnode;
|
||||
struct ProcDirEntry *pde = VnodeToEntry(node);
|
||||
if ((pde == NULL) || (pde->pf == NULL)) {
|
||||
VnodeDrop();
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
pde->pf->fPos = 0;
|
||||
if ((pde->procFileOps != NULL) && (pde->procFileOps->release != NULL)) {
|
||||
result = pde->procFileOps->release((struct Vnode *)pde, pde->pf);
|
||||
}
|
||||
LosBufRelease(pde->pf->sbuf);
|
||||
pde->pf->sbuf = NULL;
|
||||
|
||||
VnodeDrop();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -335,6 +425,24 @@ int VfsProcfsClosedir(struct Vnode *vp, struct fs_dirent_s *dir)
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
ssize_t VfsProcfsReadlink(struct Vnode *vnode, char *buffer, size_t bufLen)
|
||||
{
|
||||
int result = -EINVAL;
|
||||
if (vnode == NULL) {
|
||||
return result;
|
||||
}
|
||||
|
||||
struct ProcDirEntry *pde = VnodeToEntry(vnode);
|
||||
if (pde == NULL) {
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
if ((pde->procFileOps != NULL) && (pde->procFileOps->readLink != NULL)) {
|
||||
result = pde->procFileOps->readLink(pde, buffer, bufLen);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const struct MountOps procfs_operations = {
|
||||
.Mount = VfsProcfsMount,
|
||||
.Unmount = NULL,
|
||||
@@ -347,7 +455,12 @@ static struct VnodeOps g_procfsVops = {
|
||||
.Readdir = VfsProcfsReaddir,
|
||||
.Opendir = VfsProcfsOpendir,
|
||||
.Closedir = VfsProcfsClosedir,
|
||||
.Truncate = VfsProcfsTruncate
|
||||
.Truncate = VfsProcfsTruncate,
|
||||
.Readlink = VfsProcfsReadlink,
|
||||
#ifdef LOSCFG_KERNEL_PLIMITS
|
||||
.Mkdir = VfsProcfsMkdir,
|
||||
.Rmdir = VfsProcfsRmdir,
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct file_operations_vfs g_procfsFops = {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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:
|
||||
@@ -32,7 +32,640 @@
|
||||
#include <sys/statfs.h>
|
||||
#include <sys/mount.h>
|
||||
#include "proc_fs.h"
|
||||
#include "internal.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "user_copy.h"
|
||||
#include "los_memory.h"
|
||||
|
||||
#ifdef LOSCFG_PROC_PROCESS_DIR
|
||||
#include "los_vm_dump.h"
|
||||
|
||||
typedef enum {
|
||||
PROC_PID,
|
||||
PROC_PID_MEM,
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
PROC_PID_CPUP,
|
||||
#endif
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
PROC_UID_MAP,
|
||||
PROC_GID_MAP,
|
||||
#endif
|
||||
PROC_P_TYPE_MAX,
|
||||
} ProcessDataType;
|
||||
|
||||
struct ProcProcess {
|
||||
char *name;
|
||||
mode_t mode;
|
||||
int type;
|
||||
const struct ProcFileOperations *fileOps;
|
||||
};
|
||||
|
||||
struct ProcessData {
|
||||
uintptr_t process;
|
||||
unsigned int type;
|
||||
};
|
||||
|
||||
static LosProcessCB *ProcGetProcessCB(struct ProcessData *data)
|
||||
{
|
||||
if (data->process != 0) {
|
||||
return (LosProcessCB *)data->process;
|
||||
}
|
||||
return OsCurrProcessGet();
|
||||
}
|
||||
|
||||
#define PROC_PID_PRIVILEGE 7
|
||||
#define PROC_PID_DIR_LEN 100
|
||||
#ifdef LOSCFG_KERNEL_CONTAINER
|
||||
static ssize_t ProcessContainerLink(unsigned int containerID, ContainerType type, char *buffer, size_t bufLen)
|
||||
{
|
||||
ssize_t count = -1;
|
||||
if ((type == PID_CONTAINER) || (type == PID_CHILD_CONTAINER)) {
|
||||
count = snprintf_s(buffer, bufLen, bufLen - 1, "'pid:[%u]'", containerID);
|
||||
} else if (type == UTS_CONTAINER) {
|
||||
count = snprintf_s(buffer, bufLen, bufLen - 1, "'uts:[%u]'", containerID);
|
||||
} else if (type == MNT_CONTAINER) {
|
||||
count = snprintf_s(buffer, bufLen, bufLen - 1, "'mnt:[%u]'", containerID);
|
||||
} else if (type == IPC_CONTAINER) {
|
||||
count = snprintf_s(buffer, bufLen, bufLen - 1, "'ipc:[%u]'", containerID);
|
||||
} else if ((type == TIME_CONTAINER) || (type == TIME_CHILD_CONTAINER)) {
|
||||
count = snprintf_s(buffer, bufLen, bufLen - 1, "'time:[%u]'", containerID);
|
||||
} else if (type == USER_CONTAINER) {
|
||||
count = snprintf_s(buffer, bufLen, bufLen - 1, "'user:[%u]'", containerID);
|
||||
} else if (type == NET_CONTAINER) {
|
||||
count = snprintf_s(buffer, bufLen, bufLen - 1, "'net:[%u]'", containerID);
|
||||
}
|
||||
|
||||
if (count < 0) {
|
||||
return -EBADF;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t ProcessContainerReadLink(struct ProcDirEntry *entry, char *buffer, size_t bufLen)
|
||||
{
|
||||
ssize_t count;
|
||||
unsigned int intSave;
|
||||
if (entry == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
struct ProcessData *data = (struct ProcessData *)entry->data;
|
||||
if (data == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
LosProcessCB *processCB = ProcGetProcessCB(data);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
UINT32 containerID = OsGetContainerID(processCB, (ContainerType)data->type);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if (containerID != OS_INVALID_VALUE) {
|
||||
return ProcessContainerLink(containerID, (ContainerType)data->type, buffer, bufLen);
|
||||
}
|
||||
count = strlen("(unknown)");
|
||||
if (memcpy_s(buffer, bufLen, "(unknown)", count + 1) != EOK) {
|
||||
return -EBADF;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static const struct ProcFileOperations PID_CONTAINER_FOPS = {
|
||||
.readLink = ProcessContainerReadLink,
|
||||
};
|
||||
|
||||
void *ProcfsContainerGet(int fd, unsigned int *containerType)
|
||||
{
|
||||
if ((fd <= 0) || (containerType == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VnodeHold();
|
||||
struct Vnode *vnode = VnodeFind(fd);
|
||||
if (vnode == NULL) {
|
||||
VnodeDrop();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct ProcDirEntry *entry = VnodeToEntry(vnode);
|
||||
if (entry == NULL) {
|
||||
VnodeDrop();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct ProcessData *data = (struct ProcessData *)entry->data;
|
||||
if (data == NULL) {
|
||||
VnodeDrop();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *processCB = (void *)ProcGetProcessCB(data);
|
||||
*containerType = data->type;
|
||||
VnodeDrop();
|
||||
return processCB;
|
||||
}
|
||||
|
||||
#endif /* LOSCFG_KERNEL_CONTAINER */
|
||||
|
||||
static int ProcessMemInfoRead(struct SeqBuf *seqBuf, LosProcessCB *pcb)
|
||||
{
|
||||
unsigned int intSave;
|
||||
unsigned int size = sizeof(LosVmSpace) + sizeof(LosVmMapRegion);
|
||||
LosVmSpace *vmSpace = (LosVmSpace *)LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (vmSpace == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
(void)memset_s(vmSpace, size, 0, size);
|
||||
LosVmMapRegion *heap = (LosVmMapRegion *)((char *)vmSpace + sizeof(LosVmSpace));
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (OsProcessIsInactive(pcb)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(void)LOS_MemFree(m_aucSysMem1, vmSpace);
|
||||
return -EINVAL;
|
||||
}
|
||||
(void)memcpy_s(vmSpace, sizeof(LosVmSpace), pcb->vmSpace, sizeof(LosVmSpace));
|
||||
(void)memcpy_s(heap, sizeof(LosVmMapRegion), pcb->vmSpace->heap, sizeof(LosVmMapRegion));
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
(void)LosBufPrintf(seqBuf, "\nVMSpaceSize: %u byte\n", vmSpace->size);
|
||||
(void)LosBufPrintf(seqBuf, "VMSpaceMapSize: %u byte\n", vmSpace->mapSize);
|
||||
(void)LosBufPrintf(seqBuf, "VM TLB Asid: %u\n", vmSpace->archMmu.asid);
|
||||
(void)LosBufPrintf(seqBuf, "VMHeapSize: %u byte\n", heap->range.size);
|
||||
(void)LosBufPrintf(seqBuf, "VMHeapRegionName: %s\n", OsGetRegionNameOrFilePath(heap));
|
||||
(void)LosBufPrintf(seqBuf, "VMHeapRegionType: 0x%x\n", heap->regionType);
|
||||
(void)LOS_MemFree(m_aucSysMem1, vmSpace);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
#define TIME_CYCLE_TO_US(time) ((((UINT64)time) * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US)
|
||||
static int ProcessCpupRead(struct SeqBuf *seqBuf, LosProcessCB *pcb)
|
||||
{
|
||||
unsigned int intSave;
|
||||
OsCpupBase *processCpup = (OsCpupBase *)LOS_MemAlloc(m_aucSysMem1, sizeof(OsCpupBase));
|
||||
if (processCpup == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
(void)memset_s(processCpup, sizeof(OsCpupBase), 0, sizeof(OsCpupBase));
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (OsProcessIsInactive(pcb)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, processCpup);
|
||||
return -EINVAL;
|
||||
}
|
||||
(void)memcpy_s(processCpup, sizeof(OsCpupBase), pcb->processCpup, sizeof(OsCpupBase));
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
(void)LosBufPrintf(seqBuf, "\nTotalRunningTime: %lu us\n", TIME_CYCLE_TO_US(processCpup->allTime));
|
||||
(void)LosBufPrintf(seqBuf, "HistoricalRunningTime:(us) ");
|
||||
for (UINT32 i = 0; i < OS_CPUP_HISTORY_RECORD_NUM + 1; i++) {
|
||||
(void)LosBufPrintf(seqBuf, "%lu ", TIME_CYCLE_TO_US(processCpup->historyTime[i]));
|
||||
}
|
||||
(void)LosBufPrintf(seqBuf, "\n");
|
||||
(void)LOS_MemFree(m_aucSysMem1, processCpup);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
static const CHAR *g_monotonic = "monotonic";
|
||||
#define DECIMAL_BASE 10
|
||||
|
||||
static int ProcTimeContainerRead(struct SeqBuf *m, void *v)
|
||||
{
|
||||
int ret;
|
||||
unsigned int intSave;
|
||||
struct timespec64 offsets = {0};
|
||||
|
||||
if ((m == NULL) || (v == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
struct ProcessData *data = (struct ProcessData *)v;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LosProcessCB *processCB = ProcGetProcessCB(data);
|
||||
ret = OsGetTimeContainerMonotonic(processCB, &offsets);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if (ret != LOS_OK) {
|
||||
return -ret;
|
||||
}
|
||||
|
||||
LosBufPrintf(m, "monotonic %lld %ld\n", offsets.tv_sec, offsets.tv_nsec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ProcSetTimensOffset(const char *buf, LosProcessCB *processCB)
|
||||
{
|
||||
unsigned int intSave;
|
||||
struct timespec64 offsets;
|
||||
char *endptr = NULL;
|
||||
|
||||
offsets.tv_sec = strtoll(buf, &endptr, DECIMAL_BASE);
|
||||
offsets.tv_nsec = strtoll(endptr, NULL, DECIMAL_BASE);
|
||||
if (offsets.tv_nsec >= OS_SYS_NS_PER_SECOND) {
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
unsigned int ret = OsSetTimeContainerMonotonic(processCB, &offsets);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if (ret != LOS_OK) {
|
||||
return -ret;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ProcTimeContainerWrite(struct ProcFile *pf, const char *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
(void)ppos;
|
||||
char *kbuf = NULL;
|
||||
int ret;
|
||||
|
||||
if ((pf == NULL) || (count <= 0)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
struct ProcDirEntry *entry = pf->pPDE;
|
||||
if (entry == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
struct ProcessData *data = (struct ProcessData *)entry->data;
|
||||
if (data == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)buf, count)) {
|
||||
kbuf = LOS_MemAlloc(m_aucSysMem1, count + 1);
|
||||
if (kbuf == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (LOS_ArchCopyFromUser(kbuf, buf, count) != 0) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, kbuf);
|
||||
return -EFAULT;
|
||||
}
|
||||
kbuf[count] = '\0';
|
||||
buf = kbuf;
|
||||
}
|
||||
|
||||
ret = strncmp(buf, g_monotonic, strlen(g_monotonic));
|
||||
if (ret != 0) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, kbuf);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
buf += strlen(g_monotonic);
|
||||
ret = ProcSetTimensOffset(buf, ProcGetProcessCB(data));
|
||||
if (ret < 0) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, kbuf);
|
||||
return ret;
|
||||
}
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, kbuf);
|
||||
return count;
|
||||
}
|
||||
|
||||
static const struct ProcFileOperations TIME_CONTAINER_FOPS = {
|
||||
.read = ProcTimeContainerRead,
|
||||
.write = ProcTimeContainerWrite,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
|
||||
static void *MemdupUserNul(const void *src, size_t len)
|
||||
{
|
||||
char *des = NULL;
|
||||
if (len <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
des = LOS_MemAlloc(OS_SYS_MEM_ADDR, len + 1);
|
||||
if (des == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (LOS_ArchCopyFromUser(des, src, len) != 0) {
|
||||
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, des);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
des[len] = '\0';
|
||||
return des;
|
||||
}
|
||||
|
||||
static LosProcessCB *ProcUidGidMapWriteCheck(struct ProcFile *pf, const char *buf, size_t size,
|
||||
char **kbuf, ProcessDataType *type)
|
||||
{
|
||||
if ((pf == NULL) || (size <= 0) || (size >= PAGE_SIZE)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct ProcDirEntry *entry = pf->pPDE;
|
||||
if (entry == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct ProcessData *data = (struct ProcessData *)entry->data;
|
||||
if (data == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*kbuf = MemdupUserNul(buf, size);
|
||||
if (*kbuf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
*type = (ProcessDataType)data->type;
|
||||
return ProcGetProcessCB(data);
|
||||
}
|
||||
|
||||
static ssize_t ProcIDMapWrite(struct ProcFile *file, const char *buf, size_t size, loff_t *ppos)
|
||||
{
|
||||
(void)ppos;
|
||||
char *kbuf = NULL;
|
||||
int ret;
|
||||
unsigned int intSave;
|
||||
ProcessDataType type = PROC_P_TYPE_MAX;
|
||||
LosProcessCB *processCB = ProcUidGidMapWriteCheck(file, buf, size, &kbuf, &type);
|
||||
if (processCB == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if ((processCB->credentials == NULL) || (processCB->credentials->userContainer == NULL)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(void)LOS_MemFree(m_aucSysMem1, kbuf);
|
||||
return -EINVAL;
|
||||
}
|
||||
UserContainer *userContainer = processCB->credentials->userContainer;
|
||||
if (userContainer->parent == NULL) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(void)LOS_MemFree(m_aucSysMem1, kbuf);
|
||||
return -EPERM;
|
||||
}
|
||||
if (type == PROC_UID_MAP) {
|
||||
ret = OsUserContainerMapWrite(file, kbuf, size, CAP_SETUID,
|
||||
&userContainer->uidMap, &userContainer->parent->uidMap);
|
||||
} else {
|
||||
ret = OsUserContainerMapWrite(file, kbuf, size, CAP_SETGID,
|
||||
&userContainer->gidMap, &userContainer->parent->gidMap);
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(void)LOS_MemFree(m_aucSysMem1, kbuf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ProcIDMapRead(struct SeqBuf *seqBuf, void *v)
|
||||
{
|
||||
unsigned int intSave;
|
||||
if ((seqBuf == NULL) || (v == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
struct ProcessData *data = (struct ProcessData *)v;
|
||||
LosProcessCB *processCB = ProcGetProcessCB(data);
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if ((processCB->credentials == NULL) || (processCB->credentials->userContainer == NULL)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return -EINVAL;
|
||||
}
|
||||
UserContainer *userContainer = processCB->credentials->userContainer;
|
||||
if ((userContainer != NULL) && (userContainer->parent == NULL)) {
|
||||
UidGidExtent uidGidExtent = userContainer->uidMap.extent[0];
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(void)LosBufPrintf(seqBuf, "%d %d %u\n", uidGidExtent.first, uidGidExtent.lowerFirst,
|
||||
uidGidExtent.count);
|
||||
return 0;
|
||||
}
|
||||
SCHEDULER_LOCK(intSave);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct ProcFileOperations UID_GID_MAP_FOPS = {
|
||||
.read = ProcIDMapRead,
|
||||
.write = ProcIDMapWrite,
|
||||
};
|
||||
#endif
|
||||
|
||||
static int ProcProcessRead(struct SeqBuf *m, void *v)
|
||||
{
|
||||
if ((m == NULL) || (v == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
struct ProcessData *data = (struct ProcessData *)v;
|
||||
switch (data->type) {
|
||||
case PROC_PID_MEM:
|
||||
return ProcessMemInfoRead(m, ProcGetProcessCB(data));
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
case PROC_PID_CPUP:
|
||||
return ProcessCpupRead(m, ProcGetProcessCB(data));
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static const struct ProcFileOperations PID_FOPS = {
|
||||
.read = ProcProcessRead,
|
||||
};
|
||||
|
||||
static struct ProcProcess g_procProcess[] = {
|
||||
{
|
||||
.name = NULL,
|
||||
.mode = S_IFDIR | S_IRWXU | S_IRWXG | S_IROTH,
|
||||
.type = PROC_PID,
|
||||
.fileOps = &PID_FOPS
|
||||
|
||||
},
|
||||
{
|
||||
.name = "meminfo",
|
||||
.mode = 0,
|
||||
.type = PROC_PID_MEM,
|
||||
.fileOps = &PID_FOPS
|
||||
},
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
{
|
||||
.name = "cpup",
|
||||
.mode = 0,
|
||||
.type = PROC_PID_CPUP,
|
||||
.fileOps = &PID_FOPS
|
||||
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_CONTAINER
|
||||
{
|
||||
.name = "container",
|
||||
.mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH,
|
||||
.type = CONTAINER,
|
||||
.fileOps = &PID_CONTAINER_FOPS
|
||||
|
||||
},
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
{
|
||||
.name = "container/pid",
|
||||
.mode = S_IFLNK,
|
||||
.type = PID_CONTAINER,
|
||||
.fileOps = &PID_CONTAINER_FOPS
|
||||
},
|
||||
{
|
||||
.name = "container/pid_for_children",
|
||||
.mode = S_IFLNK,
|
||||
.type = PID_CHILD_CONTAINER,
|
||||
.fileOps = &PID_CONTAINER_FOPS
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
{
|
||||
.name = "container/uts",
|
||||
.mode = S_IFLNK,
|
||||
.type = UTS_CONTAINER,
|
||||
.fileOps = &PID_CONTAINER_FOPS
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
{
|
||||
.name = "container/mnt",
|
||||
.mode = S_IFLNK,
|
||||
.type = MNT_CONTAINER,
|
||||
.fileOps = &PID_CONTAINER_FOPS
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
{
|
||||
.name = "container/ipc",
|
||||
.mode = S_IFLNK,
|
||||
.type = IPC_CONTAINER,
|
||||
.fileOps = &PID_CONTAINER_FOPS
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
{
|
||||
.name = "container/time",
|
||||
.mode = S_IFLNK,
|
||||
.type = TIME_CONTAINER,
|
||||
.fileOps = &PID_CONTAINER_FOPS
|
||||
},
|
||||
{
|
||||
.name = "container/time_for_children",
|
||||
.mode = S_IFLNK,
|
||||
.type = TIME_CHILD_CONTAINER,
|
||||
.fileOps = &PID_CONTAINER_FOPS
|
||||
},
|
||||
{
|
||||
.name = "time_offsets",
|
||||
.mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
|
||||
.type = TIME_CONTAINER,
|
||||
.fileOps = &TIME_CONTAINER_FOPS
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
{
|
||||
.name = "container/user",
|
||||
.mode = S_IFLNK,
|
||||
.type = USER_CONTAINER,
|
||||
.fileOps = &PID_CONTAINER_FOPS
|
||||
},
|
||||
{
|
||||
.name = "uid_map",
|
||||
.mode = 0,
|
||||
.type = PROC_UID_MAP,
|
||||
.fileOps = &UID_GID_MAP_FOPS
|
||||
},
|
||||
{
|
||||
.name = "gid_map",
|
||||
.mode = 0,
|
||||
.type = PROC_GID_MAP,
|
||||
.fileOps = &UID_GID_MAP_FOPS
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
{
|
||||
.name = "container/net",
|
||||
.mode = S_IFLNK,
|
||||
.type = NET_CONTAINER,
|
||||
.fileOps = &PID_CONTAINER_FOPS
|
||||
},
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
void ProcFreeProcessDir(struct ProcDirEntry *processDir)
|
||||
{
|
||||
if (processDir == NULL) {
|
||||
return;
|
||||
}
|
||||
RemoveProcEntry(processDir->name, NULL);
|
||||
}
|
||||
|
||||
static struct ProcDirEntry *ProcCreatePorcess(UINT32 pid, struct ProcProcess *porcess, uintptr_t processCB)
|
||||
{
|
||||
int ret;
|
||||
struct ProcDataParm dataParm;
|
||||
char pidName[PROC_PID_DIR_LEN] = {0};
|
||||
struct ProcessData *data = (struct ProcessData *)malloc(sizeof(struct ProcessData));
|
||||
if (data == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (pid != OS_INVALID_VALUE) {
|
||||
if (porcess->name != NULL) {
|
||||
ret = snprintf_s(pidName, PROC_PID_DIR_LEN, PROC_PID_DIR_LEN - 1, "%u/%s", pid, porcess->name);
|
||||
} else {
|
||||
ret = snprintf_s(pidName, PROC_PID_DIR_LEN, PROC_PID_DIR_LEN - 1, "%u", pid);
|
||||
}
|
||||
} else {
|
||||
if (porcess->name != NULL) {
|
||||
ret = snprintf_s(pidName, PROC_PID_DIR_LEN, PROC_PID_DIR_LEN - 1, "%s/%s", "self", porcess->name);
|
||||
} else {
|
||||
ret = snprintf_s(pidName, PROC_PID_DIR_LEN, PROC_PID_DIR_LEN - 1, "%s", "self");
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
free(data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data->process = processCB;
|
||||
data->type = porcess->type;
|
||||
dataParm.data = data;
|
||||
dataParm.dataType = PROC_DATA_FREE;
|
||||
struct ProcDirEntry *container = ProcCreateData(pidName, porcess->mode, NULL, porcess->fileOps, &dataParm);
|
||||
if (container == NULL) {
|
||||
free(data);
|
||||
PRINT_ERR("create /proc/%s error!\n", pidName);
|
||||
return NULL;
|
||||
}
|
||||
return container;
|
||||
}
|
||||
|
||||
int ProcCreateProcessDir(UINT32 pid, uintptr_t process)
|
||||
{
|
||||
unsigned int intSave;
|
||||
struct ProcDirEntry *pidDir = NULL;
|
||||
for (int index = 0; index < (sizeof(g_procProcess) / sizeof(struct ProcProcess)); index++) {
|
||||
struct ProcProcess *procProcess = &g_procProcess[index];
|
||||
struct ProcDirEntry *dir = ProcCreatePorcess(pid, procProcess, process);
|
||||
if (dir == NULL) {
|
||||
PRINT_ERR("create /proc/%s error!\n", procProcess->name);
|
||||
goto CREATE_ERROR;
|
||||
}
|
||||
if (index == 0) {
|
||||
pidDir = dir;
|
||||
}
|
||||
}
|
||||
|
||||
if (process != 0) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
((LosProcessCB *)process)->procDir = pidDir;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
CREATE_ERROR:
|
||||
if (pidDir != NULL) {
|
||||
RemoveProcEntry(pidDir->name, NULL);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#endif /* LOSCFG_PROC_PROCESS_DIR */
|
||||
|
||||
static int ProcessProcFill(struct SeqBuf *m, void *v)
|
||||
{
|
||||
@@ -52,7 +685,18 @@ void ProcProcessInit(void)
|
||||
PRINT_ERR("create /proc/process error!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
pde->procFileOps = &PROCESS_PROC_FOPS;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_PROC_PROCESS_DIR
|
||||
int ret = ProcCreateProcessDir(OS_INVALID_VALUE, 0);
|
||||
if (ret < 0) {
|
||||
PRINT_ERR("Create proc process self dir failed!\n");
|
||||
}
|
||||
|
||||
ret = ProcCreateProcessDir(OS_USER_ROOT_PROCESS_ID, (uintptr_t)OsGetUserInitProcess());
|
||||
if (ret < 0) {
|
||||
PRINT_ERR("Create proc process %d dir failed!\n", OS_USER_ROOT_PROCESS_ID);
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
228
fs/proc/os_adapt/sys_user.c
Normal file
228
fs/proc/os_adapt/sys_user.c
Normal file
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* 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 <sys/statfs.h>
|
||||
#include <sys/mount.h>
|
||||
#include "proc_fs.h"
|
||||
#include "internal.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "user_copy.h"
|
||||
#include "los_memory.h"
|
||||
|
||||
#ifdef LOSCFG_KERNEL_CONTAINER
|
||||
struct ProcSysUser {
|
||||
char *name;
|
||||
mode_t mode;
|
||||
int type;
|
||||
const struct ProcFileOperations *fileOps;
|
||||
};
|
||||
|
||||
static unsigned int MemUserCopy(const char *src, size_t len, char **kbuf)
|
||||
{
|
||||
if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, len)) {
|
||||
char *kernelBuf = LOS_MemAlloc(m_aucSysMem1, len + 1);
|
||||
if (kernelBuf == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
if (LOS_ArchCopyFromUser(kernelBuf, src, len) != 0) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, kernelBuf);
|
||||
return EFAULT;
|
||||
}
|
||||
kernelBuf[len] = '\0';
|
||||
*kbuf = kernelBuf;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int GetContainerLimitValue(struct ProcFile *pf, const CHAR *buf, size_t count)
|
||||
{
|
||||
int value;
|
||||
char *kbuf = NULL;
|
||||
|
||||
if ((pf == NULL) || (pf->pPDE == NULL) || (buf == NULL) || (count <= 0)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
unsigned ret = MemUserCopy(buf, count, &kbuf);
|
||||
if (ret != 0) {
|
||||
return -ret;
|
||||
} else if ((ret == 0) && (kbuf != NULL)) {
|
||||
buf = (const char *)kbuf;
|
||||
}
|
||||
|
||||
if (strspn(buf, "0123456789") != count) {
|
||||
(void)LOS_MemFree(m_aucSysMem1, kbuf);
|
||||
return -EINVAL;
|
||||
}
|
||||
value = atoi(buf);
|
||||
(void)LOS_MemFree(m_aucSysMem1, kbuf);
|
||||
return value;
|
||||
}
|
||||
|
||||
static ssize_t ProcSysUserWrite(struct ProcFile *pf, const char *buf, size_t size, loff_t *ppos)
|
||||
{
|
||||
(void)ppos;
|
||||
unsigned ret;
|
||||
int value = GetContainerLimitValue(pf, buf, size);
|
||||
if (value < 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ContainerType type = (ContainerType)(uintptr_t)pf->pPDE->data;
|
||||
ret = OsSetContainerLimit(type, value);
|
||||
if (ret != LOS_OK) {
|
||||
return -EINVAL;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
static int ProcSysUserRead(struct SeqBuf *seqBuf, void *v)
|
||||
{
|
||||
unsigned ret;
|
||||
if ((seqBuf == NULL) || (v == NULL)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
ContainerType type = (ContainerType)(uintptr_t)v;
|
||||
ret = OsGetContainerLimit(type);
|
||||
if (ret == OS_INVALID_VALUE) {
|
||||
return EINVAL;
|
||||
}
|
||||
(void)LosBufPrintf(seqBuf, "\nlimit: %u\n", ret);
|
||||
(void)LosBufPrintf(seqBuf, "count: %u\n", OsGetContainerCount(type));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct ProcFileOperations SYS_USER_OPT = {
|
||||
.read = ProcSysUserRead,
|
||||
.write = ProcSysUserWrite,
|
||||
};
|
||||
|
||||
static struct ProcSysUser g_sysUser[] = {
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
{
|
||||
.name = "max_mnt_container",
|
||||
.mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
|
||||
.type = MNT_CONTAINER,
|
||||
.fileOps = &SYS_USER_OPT
|
||||
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
{
|
||||
.name = "max_pid_container",
|
||||
.mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
|
||||
.type = PID_CONTAINER,
|
||||
.fileOps = &SYS_USER_OPT
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
{
|
||||
.name = "max_user_container",
|
||||
.mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
|
||||
.type = USER_CONTAINER,
|
||||
.fileOps = &SYS_USER_OPT
|
||||
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
{
|
||||
.name = "max_uts_container",
|
||||
.mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
|
||||
.type = UTS_CONTAINER,
|
||||
.fileOps = &SYS_USER_OPT
|
||||
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
{
|
||||
.name = "max_time_container",
|
||||
.mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
|
||||
.type = UTS_CONTAINER,
|
||||
.fileOps = &SYS_USER_OPT
|
||||
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
{
|
||||
.name = "max_ipc_container",
|
||||
.mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
|
||||
.type = IPC_CONTAINER,
|
||||
.fileOps = &SYS_USER_OPT
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_CONTAINER
|
||||
{
|
||||
.name = "max_net_container",
|
||||
.mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
|
||||
.type = NET_CONTAINER,
|
||||
.fileOps = &SYS_USER_OPT
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
static int ProcCreateSysUser(struct ProcDirEntry *parent)
|
||||
{
|
||||
struct ProcDataParm parm;
|
||||
for (int index = 0; index < (sizeof(g_sysUser) / sizeof(struct ProcSysUser)); index++) {
|
||||
struct ProcSysUser *sysUser = &g_sysUser[index];
|
||||
parm.data = (void *)(uintptr_t)sysUser->type;
|
||||
parm.dataType = PROC_DATA_STATIC;
|
||||
struct ProcDirEntry *userFile = ProcCreateData(sysUser->name, sysUser->mode, parent, sysUser->fileOps, &parm);
|
||||
if (userFile == NULL) {
|
||||
PRINT_ERR("create /proc/%s/%s error!\n", parent->name, sysUser->name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define PROC_SYS_USER_MODE (S_IFDIR | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
|
||||
void ProcSysUserInit(void)
|
||||
{
|
||||
struct ProcDirEntry *parentPDE = CreateProcEntry("sys", PROC_SYS_USER_MODE, NULL);
|
||||
if (parentPDE == NULL) {
|
||||
return;
|
||||
}
|
||||
struct ProcDirEntry *pde = CreateProcEntry("user", PROC_SYS_USER_MODE, parentPDE);
|
||||
if (pde == NULL) {
|
||||
PRINT_ERR("create /proc/process error!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = ProcCreateSysUser(pde);
|
||||
if (ret < 0) {
|
||||
PRINT_ERR("Create proc sys user failed!\n");
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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:
|
||||
@@ -296,7 +296,7 @@ static int ProcAddNode(struct ProcDirEntry *parent, struct ProcDirEntry *pn)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ProcDetachNode(struct ProcDirEntry *pn)
|
||||
void ProcDetachNode(struct ProcDirEntry *pn)
|
||||
{
|
||||
struct ProcDirEntry *parent = pn->parent;
|
||||
struct ProcDirEntry **iter = NULL;
|
||||
@@ -352,6 +352,11 @@ static struct ProcDirEntry *ProcCreateFile(struct ProcDirEntry *parent, const ch
|
||||
|
||||
pn->procFileOps = procFileOps;
|
||||
pn->type = VNODE_TYPE_REG;
|
||||
#ifdef LOSCFG_PROC_PROCESS_DIR
|
||||
if (S_ISLNK(mode)) {
|
||||
pn->type = VNODE_TYPE_VIR_LNK;
|
||||
}
|
||||
#endif
|
||||
ret = ProcAddNode(parent, pn);
|
||||
if (ret != 0) {
|
||||
free(pn->pf);
|
||||
@@ -374,15 +379,39 @@ struct ProcDirEntry *CreateProcEntry(const char *name, mode_t mode, struct ProcD
|
||||
return pde;
|
||||
}
|
||||
|
||||
void ProcEntryClearVnode(struct ProcDirEntry *entry)
|
||||
{
|
||||
struct Vnode *item = NULL;
|
||||
struct Vnode *nextItem = NULL;
|
||||
|
||||
VnodeHold();
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, GetVnodeActiveList(), struct Vnode, actFreeEntry) {
|
||||
if ((struct ProcDirEntry *)item->data != entry) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (VnodeFree(item) != LOS_OK) {
|
||||
PRINT_ERR("ProcEntryClearVnode free failed, entry: %s\n", entry->name);
|
||||
}
|
||||
}
|
||||
VnodeDrop();
|
||||
return;
|
||||
}
|
||||
|
||||
static void FreeProcEntry(struct ProcDirEntry *entry)
|
||||
{
|
||||
if (entry == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (entry->pf != NULL) {
|
||||
free(entry->pf);
|
||||
entry->pf = NULL;
|
||||
}
|
||||
if ((entry->dataType == PROC_DATA_FREE) && (entry->data != NULL)) {
|
||||
free(entry->data);
|
||||
}
|
||||
entry->data = NULL;
|
||||
free(entry);
|
||||
}
|
||||
|
||||
@@ -393,7 +422,7 @@ void ProcFreeEntry(struct ProcDirEntry *pn)
|
||||
}
|
||||
}
|
||||
|
||||
static void RemoveProcEntryTravalsal(struct ProcDirEntry *pn)
|
||||
void RemoveProcEntryTravalsal(struct ProcDirEntry *pn)
|
||||
{
|
||||
if (pn == NULL) {
|
||||
return;
|
||||
@@ -401,6 +430,8 @@ static void RemoveProcEntryTravalsal(struct ProcDirEntry *pn)
|
||||
RemoveProcEntryTravalsal(pn->next);
|
||||
RemoveProcEntryTravalsal(pn->subdir);
|
||||
|
||||
ProcEntryClearVnode(pn);
|
||||
|
||||
ProcFreeEntry(pn);
|
||||
}
|
||||
|
||||
@@ -430,6 +461,9 @@ void RemoveProcEntry(const char *name, struct ProcDirEntry *parent)
|
||||
spin_unlock(&procfsLock);
|
||||
|
||||
RemoveProcEntryTravalsal(pn->subdir);
|
||||
|
||||
ProcEntryClearVnode(pn);
|
||||
|
||||
ProcFreeEntry(pn);
|
||||
}
|
||||
|
||||
@@ -444,14 +478,17 @@ struct ProcDirEntry *ProcMkdir(const char *name, struct ProcDirEntry *parent)
|
||||
}
|
||||
|
||||
struct ProcDirEntry *ProcCreateData(const char *name, mode_t mode, struct ProcDirEntry *parent,
|
||||
const struct ProcFileOperations *procFileOps, void *data)
|
||||
const struct ProcFileOperations *procFileOps, struct ProcDataParm *param)
|
||||
{
|
||||
struct ProcDirEntry *pde = CreateProcEntry(name, mode, parent);
|
||||
if (pde != NULL) {
|
||||
if (procFileOps != NULL) {
|
||||
pde->procFileOps = procFileOps;
|
||||
}
|
||||
pde->data = data;
|
||||
if (param != NULL) {
|
||||
pde->data = param->data;
|
||||
pde->dataType = param->dataType;
|
||||
}
|
||||
}
|
||||
return pde;
|
||||
}
|
||||
@@ -529,7 +566,7 @@ static int ProcRead(struct ProcDirEntry *pde, char *buf, size_t len)
|
||||
|
||||
if (sb->buf == NULL) {
|
||||
// only read once to build the storage buffer
|
||||
if (pde->procFileOps->read(sb, NULL) != 0) {
|
||||
if (pde->procFileOps->read(sb, pde->data) != 0) {
|
||||
return PROC_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -554,21 +591,17 @@ static int ProcRead(struct ProcDirEntry *pde, char *buf, size_t len)
|
||||
|
||||
struct ProcDirEntry *OpenProcFile(const char *fileName, int flags, ...)
|
||||
{
|
||||
unsigned int intSave;
|
||||
struct ProcDirEntry *pn = ProcFindEntry(fileName);
|
||||
if (pn == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (S_ISREG(pn->mode) && (pn->count != 1)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pn->flags = (unsigned int)(pn->flags) | (unsigned int)flags;
|
||||
atomic_set(&pn->count, PROC_INUSE);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if (ProcOpen(pn->pf) != OK) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -617,7 +650,6 @@ int WriteProcFile(struct ProcDirEntry *pde, const void *buf, size_t len)
|
||||
result = pde->procFileOps->write(pde->pf, (const char *)buf, len, &(pde->pf->fPos));
|
||||
}
|
||||
spin_unlock(&procfsLock);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,6 +101,9 @@ enum VnodeType {
|
||||
VNODE_TYPE_BCHR, /* block char mix device */
|
||||
VNODE_TYPE_FIFO, /* pipe */
|
||||
VNODE_TYPE_LNK, /* link */
|
||||
#ifdef LOSCFG_PROC_PROCESS_DIR
|
||||
VNODE_TYPE_VIR_LNK, /* virtual link */
|
||||
#endif
|
||||
};
|
||||
|
||||
struct fs_dirent_s;
|
||||
@@ -127,6 +130,9 @@ struct Vnode {
|
||||
struct Mount *newMount; /* fs info about who mount on this vnode */
|
||||
char *filePath; /* file path of the vnode */
|
||||
struct page_mapping mapping; /* page mapping of the vnode */
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
int mntCount; /* ref count of mounts */
|
||||
#endif
|
||||
};
|
||||
|
||||
struct VnodeOps {
|
||||
@@ -185,5 +191,8 @@ LIST_HEAD* GetVnodeFreeList(void);
|
||||
LIST_HEAD* GetVnodeActiveList(void);
|
||||
LIST_HEAD* GetVnodeVirtualList(void);
|
||||
int VnodeClearCache(void);
|
||||
|
||||
struct Vnode *GetCurrRootVnode(void);
|
||||
#ifdef LOSCFG_PROC_PROCESS_DIR
|
||||
struct Vnode *VnodeFind(int fd);
|
||||
#endif
|
||||
#endif /* !_VNODE_H_ */
|
||||
|
||||
@@ -37,11 +37,16 @@
|
||||
#include "stdlib.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
#include "los_mnt_container_pri.h"
|
||||
static LIST_HEAD *g_mountCache = NULL;
|
||||
#else
|
||||
static LIST_HEAD *g_mountList = NULL;
|
||||
#endif
|
||||
|
||||
struct Mount* MountAlloc(struct Vnode* vnodeBeCovered, struct MountOps* fsop)
|
||||
struct Mount *MountAlloc(struct Vnode *vnodeBeCovered, struct MountOps *fsop)
|
||||
{
|
||||
struct Mount* mnt = (struct Mount*)zalloc(sizeof(struct Mount));
|
||||
struct Mount *mnt = (struct Mount *)zalloc(sizeof(struct Mount));
|
||||
if (mnt == NULL) {
|
||||
PRINT_ERR("MountAlloc failed no memory!\n");
|
||||
return NULL;
|
||||
@@ -62,7 +67,26 @@ struct Mount* MountAlloc(struct Vnode* vnodeBeCovered, struct MountOps* fsop)
|
||||
return mnt;
|
||||
}
|
||||
|
||||
LIST_HEAD* GetMountList()
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
LIST_HEAD *GetMountList(void)
|
||||
{
|
||||
return GetContainerMntList();
|
||||
}
|
||||
|
||||
LIST_HEAD *GetMountCache(void)
|
||||
{
|
||||
if (g_mountCache == NULL) {
|
||||
g_mountCache = zalloc(sizeof(LIST_HEAD));
|
||||
if (g_mountCache == NULL) {
|
||||
PRINT_ERR("init cache mount list failed, no memory.");
|
||||
return NULL;
|
||||
}
|
||||
LOS_ListInit(g_mountCache);
|
||||
}
|
||||
return g_mountCache;
|
||||
}
|
||||
#else
|
||||
LIST_HEAD* GetMountList(void)
|
||||
{
|
||||
if (g_mountList == NULL) {
|
||||
g_mountList = zalloc(sizeof(LIST_HEAD));
|
||||
@@ -74,3 +98,4 @@ LIST_HEAD* GetMountList()
|
||||
}
|
||||
return g_mountList;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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:
|
||||
@@ -482,7 +482,7 @@ exit_with_nomem:
|
||||
return (char *)NULL;
|
||||
}
|
||||
|
||||
static void PrintFileInfo64(const struct stat64 *stat64Info, const char *name)
|
||||
static void PrintFileInfo64(const struct stat64 *stat64Info, const char *name, const char *linkName)
|
||||
{
|
||||
mode_t mode;
|
||||
char str[UGO_NUMS][UGO_NUMS + 1] = {0};
|
||||
@@ -504,11 +504,18 @@ static void PrintFileInfo64(const struct stat64 *stat64Info, const char *name)
|
||||
dirFlag = '-';
|
||||
}
|
||||
|
||||
PRINTK("%c%s%s%s %-8lld u:%-5d g:%-5d %-10s\n", dirFlag,
|
||||
str[0], str[1], str[UGO_NUMS - 1], stat64Info->st_size, stat64Info->st_uid, stat64Info->st_gid, name);
|
||||
if (S_ISLNK(stat64Info->st_mode)) {
|
||||
PRINTK("%c%s%s%s %-8lld u:%-5d g:%-5d %-10s -> %s\n", dirFlag,
|
||||
str[0], str[1], str[UGO_NUMS - 1], stat64Info->st_size,
|
||||
stat64Info->st_uid, stat64Info->st_gid, name, linkName);
|
||||
} else {
|
||||
PRINTK("%c%s%s%s %-8lld u:%-5d g:%-5d %-10s\n", dirFlag,
|
||||
str[0], str[1], str[UGO_NUMS - 1], stat64Info->st_size,
|
||||
stat64Info->st_uid, stat64Info->st_gid, name);
|
||||
}
|
||||
}
|
||||
|
||||
static void PrintFileInfo(const struct stat *statInfo, const char *name)
|
||||
static void PrintFileInfo(const struct stat *statInfo, const char *name, const char *linkName)
|
||||
{
|
||||
mode_t mode;
|
||||
char str[UGO_NUMS][UGO_NUMS + 1] = {0};
|
||||
@@ -530,19 +537,33 @@ static void PrintFileInfo(const struct stat *statInfo, const char *name)
|
||||
dirFlag = '-';
|
||||
}
|
||||
|
||||
PRINTK("%c%s%s%s %-8lld u:%-5d g:%-5d %-10s\n", dirFlag,
|
||||
str[0], str[1], str[UGO_NUMS - 1], statInfo->st_size, statInfo->st_uid, statInfo->st_gid, name);
|
||||
if (S_ISLNK(statInfo->st_mode)) {
|
||||
PRINTK("%c%s%s%s %-8lld u:%-5d g:%-5d %-10s -> %s\n", dirFlag,
|
||||
str[0], str[1], str[UGO_NUMS - 1], statInfo->st_size,
|
||||
statInfo->st_uid, statInfo->st_gid, name, linkName);
|
||||
} else {
|
||||
PRINTK("%c%s%s%s %-8lld u:%-5d g:%-5d %-10s\n", dirFlag,
|
||||
str[0], str[1], str[UGO_NUMS - 1], statInfo->st_size,
|
||||
statInfo->st_uid, statInfo->st_gid, name);
|
||||
}
|
||||
}
|
||||
|
||||
int LsFile(const char *path)
|
||||
{
|
||||
struct stat64 stat64Info;
|
||||
struct stat statInfo;
|
||||
char linkName[NAME_MAX] = { 0 };
|
||||
|
||||
if (stat64(path, &stat64Info) == 0) {
|
||||
PrintFileInfo64(&stat64Info, path);
|
||||
if (S_ISLNK(stat64Info.st_mode)) {
|
||||
readlink(path, linkName, NAME_MAX);
|
||||
}
|
||||
PrintFileInfo64(&stat64Info, path, (const char *)linkName);
|
||||
} else if (stat(path, &statInfo) == 0) {
|
||||
PrintFileInfo(&statInfo, path);
|
||||
if (S_ISLNK(statInfo.st_mode)) {
|
||||
readlink(path, linkName, NAME_MAX);
|
||||
}
|
||||
PrintFileInfo(&statInfo, path, (const char *)linkName);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
@@ -554,6 +575,7 @@ int LsDir(const char *path)
|
||||
{
|
||||
struct stat statInfo = { 0 };
|
||||
struct stat64 stat64Info = { 0 };
|
||||
char linkName[NAME_MAX] = { 0 };
|
||||
DIR *d = NULL;
|
||||
char *fullpath = NULL;
|
||||
char *fullpath_bak = NULL;
|
||||
@@ -569,28 +591,34 @@ int LsDir(const char *path)
|
||||
pdirent = readdir(d);
|
||||
if (pdirent == NULL) {
|
||||
break;
|
||||
} else {
|
||||
if (!strcmp(pdirent->d_name, ".") || !strcmp(pdirent->d_name, "..")) {
|
||||
continue;
|
||||
}
|
||||
(void)memset_s(&statInfo, sizeof(struct stat), 0, sizeof(struct stat));
|
||||
(void)memset_s(&stat64Info, sizeof(struct stat), 0, sizeof(struct stat));
|
||||
fullpath = ls_get_fullpath(path, pdirent);
|
||||
if (fullpath == NULL) {
|
||||
(void)closedir(d);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fullpath_bak = fullpath;
|
||||
if (stat64(fullpath, &stat64Info) == 0) {
|
||||
PrintFileInfo64(&stat64Info, pdirent->d_name);
|
||||
} else if (stat(fullpath, &statInfo) == 0) {
|
||||
PrintFileInfo(&statInfo, pdirent->d_name);
|
||||
} else {
|
||||
PRINTK("BAD file: %s\n", pdirent->d_name);
|
||||
}
|
||||
free(fullpath_bak);
|
||||
}
|
||||
if (!strcmp(pdirent->d_name, ".") || !strcmp(pdirent->d_name, "..")) {
|
||||
continue;
|
||||
}
|
||||
(void)memset_s(&statInfo, sizeof(struct stat), 0, sizeof(struct stat));
|
||||
(void)memset_s(&stat64Info, sizeof(struct stat), 0, sizeof(struct stat));
|
||||
(void)memset_s(&linkName, sizeof(linkName), 0, sizeof(linkName));
|
||||
fullpath = ls_get_fullpath(path, pdirent);
|
||||
if (fullpath == NULL) {
|
||||
(void)closedir(d);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fullpath_bak = fullpath;
|
||||
if (stat64(fullpath, &stat64Info) == 0) {
|
||||
if (S_ISLNK(stat64Info.st_mode)) {
|
||||
readlink(fullpath, linkName, NAME_MAX);
|
||||
}
|
||||
PrintFileInfo64(&stat64Info, pdirent->d_name, linkName);
|
||||
} else if (stat(fullpath, &statInfo) == 0) {
|
||||
if (S_ISLNK(statInfo.st_mode)) {
|
||||
readlink(fullpath, linkName, NAME_MAX);
|
||||
}
|
||||
PrintFileInfo(&statInfo, pdirent->d_name, linkName);
|
||||
} else {
|
||||
PRINTK("BAD file: %s\n", pdirent->d_name);
|
||||
}
|
||||
free(fullpath_bak);
|
||||
} while (1);
|
||||
(void)closedir(d);
|
||||
|
||||
@@ -730,3 +758,45 @@ mode_t SysUmask(mode_t mask)
|
||||
return oldUmask;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_CHROOT
|
||||
int chroot(const char *path)
|
||||
{
|
||||
int ret;
|
||||
struct Vnode *vnode = NULL;
|
||||
|
||||
if (!path) {
|
||||
set_errno(EFAULT);
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (!strlen(path)) {
|
||||
set_errno(ENOENT);
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (strlen(path) > PATH_MAX) {
|
||||
set_errno(ENAMETOOLONG);
|
||||
return VFS_ERROR;
|
||||
}
|
||||
VnodeHold();
|
||||
ret = VnodeLookup(path, &vnode, 0);
|
||||
if (ret != LOS_OK) {
|
||||
VnodeDrop();
|
||||
return ret;
|
||||
}
|
||||
|
||||
LosProcessCB *curr = OsCurrProcessGet();
|
||||
if ((curr->files == NULL) || (curr->files->rootVnode == NULL)) {
|
||||
VnodeDrop();
|
||||
return VFS_ERROR;
|
||||
}
|
||||
if (curr->files->rootVnode->useCount > 0) {
|
||||
curr->files->rootVnode->useCount--;
|
||||
}
|
||||
vnode->useCount++;
|
||||
curr->files->rootVnode = vnode;
|
||||
|
||||
VnodeDrop();
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -29,9 +29,11 @@
|
||||
*/
|
||||
|
||||
#include "los_mux.h"
|
||||
#include "vnode.h"
|
||||
#include "fs/dirent_fs.h"
|
||||
#include "path_cache.h"
|
||||
#include "vnode.h"
|
||||
#include "los_process.h"
|
||||
#include "los_process_pri.h"
|
||||
|
||||
LIST_HEAD g_vnodeFreeList; /* free vnodes list */
|
||||
LIST_HEAD g_vnodeVirtualList; /* dev vnodes list */
|
||||
@@ -67,6 +69,13 @@ int VnodesInit(void)
|
||||
g_rootVnode->type = VNODE_TYPE_DIR;
|
||||
g_rootVnode->filePath = "/";
|
||||
|
||||
#ifdef LOSCFG_CHROOT
|
||||
LosProcessCB *processCB = OsGetKernelInitProcess();
|
||||
if (processCB->files != NULL) {
|
||||
g_rootVnode->useCount++;
|
||||
processCB->files->rootVnode = g_rootVnode;
|
||||
}
|
||||
#endif
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
@@ -281,7 +290,7 @@ static int PreProcess(const char *originPath, struct Vnode **startVnode, char **
|
||||
|
||||
ret = vfs_normalize_path(NULL, originPath, &absolutePath);
|
||||
if (ret == LOS_OK) {
|
||||
*startVnode = g_rootVnode;
|
||||
*startVnode = GetCurrRootVnode();
|
||||
*path = absolutePath;
|
||||
}
|
||||
|
||||
@@ -293,7 +302,21 @@ static struct Vnode *ConvertVnodeIfMounted(struct Vnode *vnode)
|
||||
if ((vnode == NULL) || !(vnode->flag & VNODE_FLAG_MOUNT_ORIGIN)) {
|
||||
return vnode;
|
||||
}
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
LIST_HEAD *mntList = GetMountList();
|
||||
struct Mount *mnt = NULL;
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(mnt, mntList, struct Mount, mountList) {
|
||||
if ((mnt != NULL) && (mnt->vnodeBeCovered == vnode)) {
|
||||
return mnt->vnodeCovered;
|
||||
}
|
||||
}
|
||||
if (strcmp(vnode->filePath, "/dev") == 0) {
|
||||
return vnode->newMount->vnodeCovered;
|
||||
}
|
||||
return vnode;
|
||||
#else
|
||||
return vnode->newMount->vnodeCovered;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void RefreshLRU(struct Vnode *vnode)
|
||||
@@ -394,7 +417,7 @@ int VnodeLookupAt(const char *path, struct Vnode **result, uint32_t flags, struc
|
||||
}
|
||||
|
||||
if (normalizedPath[1] == '\0' && normalizedPath[0] == '/') {
|
||||
*result = g_rootVnode;
|
||||
*result = GetCurrRootVnode();
|
||||
free(normalizedPath);
|
||||
return LOS_OK;
|
||||
}
|
||||
@@ -454,7 +477,7 @@ int VnodeLookup(const char *path, struct Vnode **vnode, uint32_t flags)
|
||||
|
||||
int VnodeLookupFullpath(const char *fullpath, struct Vnode **vnode, uint32_t flags)
|
||||
{
|
||||
return VnodeLookupAt(fullpath, vnode, flags, g_rootVnode);
|
||||
return VnodeLookupAt(fullpath, vnode, flags, GetCurrRootVnode());
|
||||
}
|
||||
|
||||
static void ChangeRootInternal(struct Vnode *rootOld, char *dirname)
|
||||
@@ -496,6 +519,17 @@ void ChangeRoot(struct Vnode *rootNew)
|
||||
{
|
||||
struct Vnode *rootOld = g_rootVnode;
|
||||
g_rootVnode = rootNew;
|
||||
#ifdef LOSCFG_CHROOT
|
||||
LosProcessCB *curr = OsCurrProcessGet();
|
||||
if ((curr->files != NULL) &&
|
||||
(curr->files->rootVnode != NULL) &&
|
||||
(curr->files->rootVnode->useCount > 0)) {
|
||||
curr->files->rootVnode->useCount--;
|
||||
}
|
||||
rootNew->useCount++;
|
||||
curr->files->rootVnode = rootNew;
|
||||
#endif
|
||||
|
||||
ChangeRootInternal(rootOld, "proc");
|
||||
ChangeRootInternal(rootOld, "dev");
|
||||
}
|
||||
@@ -682,6 +716,27 @@ void VnodeMemoryDump(void)
|
||||
PRINTK("Vnode memory size = %d(B)\n", vnodeCount * sizeof(struct Vnode));
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_PROC_PROCESS_DIR
|
||||
struct Vnode *VnodeFind(int fd)
|
||||
{
|
||||
INT32 sysFd;
|
||||
|
||||
if (fd < 0) {
|
||||
PRINT_ERR("Error. fd is invalid as %d\n", fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Process fd convert to system global fd */
|
||||
sysFd = GetAssociatedSystemFd(fd);
|
||||
if (sysFd < 0) {
|
||||
PRINT_ERR("Error. sysFd is invalid as %d\n", sysFd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return files_get_openfile((int)sysFd);
|
||||
}
|
||||
#endif
|
||||
|
||||
LIST_HEAD* GetVnodeFreeList()
|
||||
{
|
||||
return &g_vnodeFreeList;
|
||||
@@ -719,3 +774,13 @@ int VnodeClearCache(void)
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
struct Vnode *GetCurrRootVnode(void)
|
||||
{
|
||||
#ifdef LOSCFG_CHROOT
|
||||
LosProcessCB *curr = OsCurrProcessGet();
|
||||
return curr->files->rootVnode;
|
||||
#else
|
||||
return g_rootVnode;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -67,13 +67,59 @@ 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 UTS_CONTAINER
|
||||
bool "Enable uts container Feature"
|
||||
default n
|
||||
depends on KERNEL_CONTAINER
|
||||
|
||||
config MNT_CONTAINER
|
||||
bool "Enable mnt container Feature"
|
||||
default n
|
||||
depends on KERNEL_CONTAINER
|
||||
|
||||
config CHROOT
|
||||
bool "Enable chroot"
|
||||
default n
|
||||
depends on MNT_CONTAINER
|
||||
|
||||
config IPC_CONTAINER
|
||||
bool "Enable ipc container Feature"
|
||||
default n
|
||||
depends on KERNEL_CONTAINER
|
||||
|
||||
config TIME_CONTAINER
|
||||
bool "Enable time container"
|
||||
default n
|
||||
depends on KERNEL_CONTAINER
|
||||
|
||||
config USER_CONTAINER
|
||||
bool "Enable user container"
|
||||
default n
|
||||
depends on KERNEL_CONTAINER
|
||||
|
||||
config NET_CONTAINER
|
||||
bool "Enable net container"
|
||||
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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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,17 @@ 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_credentials.c",
|
||||
"container/los_ipc_container.c",
|
||||
"container/los_mnt_container.c",
|
||||
"container/los_net_container.c",
|
||||
"container/los_pid_container.c",
|
||||
"container/los_time_container.c",
|
||||
"container/los_user_container.c",
|
||||
"container/los_uts_container.c",
|
||||
"core/los_bitmap.c",
|
||||
"core/los_info.c",
|
||||
"core/los_process.c",
|
||||
"core/los_smp.c",
|
||||
"core/los_swtmr.c",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
|
||||
|
||||
755
kernel/base/container/los_container.c
Normal file
755
kernel/base/container/los_container.c
Normal file
@@ -0,0 +1,755 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef LOSCFG_KERNEL_CONTAINER
|
||||
#include "los_container_pri.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "internal.h"
|
||||
|
||||
STATIC Container g_rootContainer;
|
||||
STATIC ContainerLimit g_containerLimit;
|
||||
STATIC Atomic g_containerCount = 0xF0000000U;
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
STATIC Credentials *g_rootCredentials = NULL;
|
||||
#endif
|
||||
|
||||
UINT32 OsAllocContainerID(VOID)
|
||||
{
|
||||
return LOS_AtomicIncRet(&g_containerCount);
|
||||
}
|
||||
|
||||
VOID OsContainerInitSystemProcess(LosProcessCB *processCB)
|
||||
{
|
||||
processCB->container = &g_rootContainer;
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
processCB->credentials = g_rootCredentials;
|
||||
#endif
|
||||
LOS_AtomicInc(&processCB->container->rc);
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
(VOID)OsAllocSpecifiedVpidUnsafe(processCB->processID, processCB->container->pidContainer, processCB, NULL);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
UINT32 OsGetContainerLimit(ContainerType type)
|
||||
{
|
||||
switch (type) {
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
case PID_CONTAINER:
|
||||
case PID_CHILD_CONTAINER:
|
||||
return g_containerLimit.pidLimit;
|
||||
#endif
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
case USER_CONTAINER:
|
||||
return g_containerLimit.userLimit;
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
case UTS_CONTAINER:
|
||||
return g_containerLimit.utsLimit;
|
||||
#endif
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
case MNT_CONTAINER:
|
||||
return g_containerLimit.mntLimit;
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
case IPC_CONTAINER:
|
||||
return g_containerLimit.ipcLimit;
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
case TIME_CONTAINER:
|
||||
case TIME_CHILD_CONTAINER:
|
||||
return g_containerLimit.timeLimit;
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_CONTAINER
|
||||
case NET_CONTAINER:
|
||||
return g_containerLimit.netLimit;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return OS_INVALID_VALUE;
|
||||
}
|
||||
|
||||
UINT32 OsContainerLimitCheck(ContainerType type, UINT32 *containerCount)
|
||||
{
|
||||
UINT32 intSave;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if ((*containerCount) >= OsGetContainerLimit(type)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EINVAL;
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsSetContainerLimit(ContainerType type, UINT32 value)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
if (value > LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
switch (type) {
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
case PID_CONTAINER:
|
||||
case PID_CHILD_CONTAINER:
|
||||
g_containerLimit.pidLimit = value;
|
||||
break;
|
||||
#endif
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
case USER_CONTAINER:
|
||||
g_containerLimit.userLimit = value;
|
||||
break;
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
case UTS_CONTAINER:
|
||||
g_containerLimit.utsLimit = value;
|
||||
break;
|
||||
#endif
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
case MNT_CONTAINER:
|
||||
g_containerLimit.mntLimit = value;
|
||||
break;
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
case IPC_CONTAINER:
|
||||
g_containerLimit.ipcLimit = value;
|
||||
break;
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
case TIME_CONTAINER:
|
||||
case TIME_CHILD_CONTAINER:
|
||||
g_containerLimit.timeLimit = value;
|
||||
break;
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_CONTAINER
|
||||
case NET_CONTAINER:
|
||||
g_containerLimit.netLimit = value;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EINVAL;
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsGetContainerCount(ContainerType type)
|
||||
{
|
||||
switch (type) {
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
case PID_CONTAINER:
|
||||
case PID_CHILD_CONTAINER:
|
||||
return OsGetPidContainerCount();
|
||||
#endif
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
case USER_CONTAINER:
|
||||
return OsGetUserContainerCount();
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
case UTS_CONTAINER:
|
||||
return OsGetUtsContainerCount();
|
||||
#endif
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
case MNT_CONTAINER:
|
||||
return OsGetMntContainerCount();
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
case IPC_CONTAINER:
|
||||
return OsGetIpcContainerCount();
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
case TIME_CONTAINER:
|
||||
case TIME_CHILD_CONTAINER:
|
||||
return OsGetTimeContainerCount();
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_CONTAINER
|
||||
case NET_CONTAINER:
|
||||
return OsGetNetContainerCount();
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return OS_INVALID_VALUE;
|
||||
}
|
||||
|
||||
VOID OsInitRootContainer(VOID)
|
||||
{
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
g_containerLimit.userLimit = LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT;
|
||||
OsInitRootUserCredentials(&g_rootCredentials);
|
||||
#endif
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
g_containerLimit.pidLimit = LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT;
|
||||
(VOID)OsInitRootPidContainer(&g_rootContainer.pidContainer);
|
||||
g_rootContainer.pidForChildContainer = g_rootContainer.pidContainer;
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
g_containerLimit.utsLimit = LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT;
|
||||
(VOID)OsInitRootUtsContainer(&g_rootContainer.utsContainer);
|
||||
#endif
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
g_containerLimit.mntLimit = LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT;
|
||||
(VOID)OsInitRootMntContainer(&g_rootContainer.mntContainer);
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
g_containerLimit.ipcLimit = LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT;
|
||||
(VOID)OsInitRootIpcContainer(&g_rootContainer.ipcContainer);
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
g_containerLimit.timeLimit = LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT;
|
||||
(VOID)OsInitRootTimeContainer(&g_rootContainer.timeContainer);
|
||||
g_rootContainer.timeForChildContainer = g_rootContainer.timeContainer;
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_CONTAINER
|
||||
g_containerLimit.netLimit = LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT;
|
||||
(VOID)OsInitRootNetContainer(&g_rootContainer.netContainer);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC INLINE Container *CreateContainer(VOID)
|
||||
{
|
||||
Container *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;
|
||||
}
|
||||
|
||||
STATIC UINT32 CopyContainers(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID)
|
||||
{
|
||||
UINT32 ret = LOS_OK;
|
||||
/* 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
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
ret = OsCopyCredentials(flags, child, parent);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
ret = OsCopyUtsContainer(flags, child, parent);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
ret = OsCopyMntContainer(flags, child, parent);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
ret = OsCopyIpcContainer(flags, child, parent);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
ret = OsCopyTimeContainer(flags, child, parent);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_CONTAINER
|
||||
ret = OsCopyNetContainer(flags, child, parent);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 GetContainerFlagsMask(VOID)
|
||||
{
|
||||
UINT32 mask = 0;
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
mask |= CLONE_NEWPID;
|
||||
#endif
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
mask |= CLONE_NEWNS;
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
mask |= CLONE_NEWIPC;
|
||||
#endif
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
mask |= CLONE_NEWUSER;
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
mask |= CLONE_NEWTIME;
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_CONTAINER
|
||||
mask |= CLONE_NEWNET;
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
mask |= CLONE_NEWUTS;
|
||||
#endif
|
||||
return mask;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
flags &= ~CLONE_NEWTIME;
|
||||
#endif
|
||||
|
||||
if (!(flags & GetContainerFlagsMask())) {
|
||||
#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);
|
||||
}
|
||||
|
||||
VOID OsContainerFree(LosProcessCB *processCB)
|
||||
{
|
||||
LOS_AtomicDec(&processCB->container->rc);
|
||||
if (LOS_AtomicRead(&processCB->container->rc) == 0) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, processCB->container);
|
||||
processCB->container = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
VOID OsOsContainersDestroyEarly(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) {
|
||||
OsPidContainerDestroyAllProcess(processCB);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
OsMntContainerDestroy(processCB->container);
|
||||
#endif
|
||||
}
|
||||
|
||||
VOID OsContainersDestroy(LosProcessCB *processCB)
|
||||
{
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
OsUserContainerDestroy(processCB);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
OsUtsContainerDestroy(processCB->container);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
OsIpcContainerDestroy(processCB->container);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
OsTimeContainerDestroy(processCB->container);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_NET_CONTAINER
|
||||
OsNetContainerDestroy(processCB->container);
|
||||
#endif
|
||||
|
||||
#ifndef LOSCFG_PID_CONTAINER
|
||||
UINT32 intSave;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
OsContainerFree(processCB);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC VOID DeInitContainers(UINT32 flags, Container *container, LosProcessCB *processCB)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if ((flags & CLONE_NEWPID) != 0) {
|
||||
OsPidContainerDestroy(container, processCB);
|
||||
} else {
|
||||
OsPidContainerDestroy(container, NULL);
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
OsUtsContainerDestroy(container);
|
||||
#endif
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
OsMntContainerDestroy(container);
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
OsIpcContainerDestroy(container);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
OsTimeContainerDestroy(container);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_NET_CONTAINER
|
||||
OsNetContainerDestroy(container);
|
||||
#endif
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LOS_AtomicDec(&container->rc);
|
||||
if (LOS_AtomicRead(&container->rc) == 0) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, container);
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
}
|
||||
|
||||
UINT32 OsGetContainerID(LosProcessCB *processCB, ContainerType type)
|
||||
{
|
||||
Container *container = processCB->container;
|
||||
if (container == NULL) {
|
||||
return OS_INVALID_VALUE;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
case PID_CONTAINER:
|
||||
return OsGetPidContainerID(container->pidContainer);
|
||||
case PID_CHILD_CONTAINER:
|
||||
return OsGetPidContainerID(container->pidForChildContainer);
|
||||
#endif
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
case USER_CONTAINER:
|
||||
return OsGetUserContainerID(processCB->credentials);
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
case UTS_CONTAINER:
|
||||
return OsGetUtsContainerID(container->utsContainer);
|
||||
#endif
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
case MNT_CONTAINER:
|
||||
return OsGetMntContainerID(container->mntContainer);
|
||||
#endif
|
||||
#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
|
||||
#ifdef LOSCFG_NET_CONTAINER
|
||||
case NET_CONTAINER:
|
||||
return OsGetNetContainerID(container->netContainer);
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return OS_INVALID_VALUE;
|
||||
}
|
||||
|
||||
STATIC UINT32 UnshareCreateNewContainers(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
|
||||
#ifdef LOSCFG_NET_CONTAINER
|
||||
ret = OsUnshareNetContainer(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;
|
||||
UINT32 unshareFlags = GetContainerFlagsMask();
|
||||
if (!(flags & unshareFlags) || ((flags & (~unshareFlags)) != 0)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
ret = OsUnshareUserCredentials(flags, curr);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
if (flags == CLONE_NEWUSER) {
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
Container *newContainer = CreateContainer();
|
||||
if (newContainer == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ret = UnshareCreateNewContainers(flags, curr, newContainer);
|
||||
if (ret != LOS_OK) {
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
oldContainer = curr->container;
|
||||
curr->container = newContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
DeInitContainers(flags, oldContainer, NULL);
|
||||
return LOS_OK;
|
||||
|
||||
EXIT:
|
||||
DeInitContainers(flags, newContainer, NULL);
|
||||
return -ret;
|
||||
}
|
||||
|
||||
STATIC UINT32 SetNsGetFlagByContainerType(UINT32 containerType)
|
||||
{
|
||||
if (containerType >= (UINT32)CONTAINER_MAX) {
|
||||
return 0;
|
||||
}
|
||||
ContainerType type = (ContainerType)containerType;
|
||||
switch (type) {
|
||||
case PID_CONTAINER:
|
||||
case PID_CHILD_CONTAINER:
|
||||
return CLONE_NEWPID;
|
||||
case USER_CONTAINER:
|
||||
return CLONE_NEWUSER;
|
||||
case UTS_CONTAINER:
|
||||
return CLONE_NEWUTS;
|
||||
case MNT_CONTAINER:
|
||||
return CLONE_NEWNS;
|
||||
case IPC_CONTAINER:
|
||||
return CLONE_NEWIPC;
|
||||
case TIME_CONTAINER:
|
||||
case TIME_CHILD_CONTAINER:
|
||||
return CLONE_NEWTIME;
|
||||
case NET_CONTAINER:
|
||||
return CLONE_NEWNET;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC UINT32 SetNsCreateNewContainers(UINT32 flags, Container *newContainer, Container *container)
|
||||
{
|
||||
UINT32 ret = LOS_OK;
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
ret = OsSetNsPidContainer(flags, container, newContainer);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
ret = OsSetNsUtsContainer(flags, container, newContainer);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
ret = OsSetNsMntContainer(flags, container, newContainer);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
ret = OsSetNsIpcContainer(flags, container, newContainer);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
ret = OsSetNsTimeContainer(flags, container, newContainer);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_CONTAINER
|
||||
ret = OsSetNsNetContainer(flags, container, newContainer);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 SetNsParamCheck(INT32 fd, INT32 type, UINT32 *flag, LosProcessCB **target)
|
||||
{
|
||||
UINT32 typeMask = GetContainerFlagsMask();
|
||||
*flag = (UINT32)(type & typeMask);
|
||||
UINT32 containerType = 0;
|
||||
|
||||
if (((type & (~typeMask)) != 0)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
LosProcessCB *processCB = (LosProcessCB *)ProcfsContainerGet(fd, &containerType);
|
||||
if (processCB == NULL) {
|
||||
return EBADF;
|
||||
}
|
||||
|
||||
if (*flag == 0) {
|
||||
*flag = SetNsGetFlagByContainerType(containerType);
|
||||
}
|
||||
|
||||
if ((*flag == 0) || (*flag != SetNsGetFlagByContainerType(containerType))) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (processCB == OsCurrProcessGet()) {
|
||||
return EINVAL;
|
||||
}
|
||||
*target = processCB;
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
INT32 OsSetNs(INT32 fd, INT32 type)
|
||||
{
|
||||
UINT32 intSave, ret;
|
||||
UINT32 flag = 0;
|
||||
LosProcessCB *curr = OsCurrProcessGet();
|
||||
LosProcessCB *processCB = NULL;
|
||||
|
||||
ret = SetNsParamCheck(fd, type, &flag, &processCB);
|
||||
if (ret != LOS_OK) {
|
||||
return -ret;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
if (flag == CLONE_NEWUSER) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if ((processCB->credentials == NULL) || (processCB->credentials->userContainer == NULL)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return -EBADF;
|
||||
}
|
||||
UserContainer *userContainer = processCB->credentials->userContainer;
|
||||
ret = OsSetNsUserContainer(userContainer, curr);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
Container *newContainer = CreateContainer();
|
||||
if (newContainer == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
Container *targetContainer = processCB->container;
|
||||
if (targetContainer == NULL) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return -EBADF;
|
||||
}
|
||||
|
||||
ret = SetNsCreateNewContainers(flag, newContainer, targetContainer);
|
||||
if (ret != LOS_OK) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
Container *oldContainer = curr->container;
|
||||
curr->container = newContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
DeInitContainers(flag, oldContainer, NULL);
|
||||
return LOS_OK;
|
||||
|
||||
EXIT:
|
||||
DeInitContainers(flag, newContainer, curr);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
209
kernel/base/container/los_credentials.c
Normal file
209
kernel/base/container/los_credentials.c
Normal file
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
* 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 <errno.h>
|
||||
#include "los_credentials_pri.h"
|
||||
#include "los_user_container_pri.h"
|
||||
#include "los_config.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_process_pri.h"
|
||||
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
STATIC Credentials *CreateNewCredential(LosProcessCB *parent)
|
||||
{
|
||||
UINT32 size = sizeof(Credentials);
|
||||
Credentials *newCredentials = LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (newCredentials == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (parent != NULL) {
|
||||
const Credentials *oldCredentials = parent->credentials;
|
||||
(VOID)memcpy_s(newCredentials, sizeof(Credentials), oldCredentials, sizeof(Credentials));
|
||||
LOS_AtomicSet(&newCredentials->rc, 1);
|
||||
} else {
|
||||
(VOID)memset_s(newCredentials, sizeof(Credentials), 0, sizeof(Credentials));
|
||||
LOS_AtomicSet(&newCredentials->rc, 3); /* 3: Three system processes */
|
||||
}
|
||||
newCredentials->userContainer = NULL;
|
||||
return newCredentials;
|
||||
}
|
||||
|
||||
Credentials *PrepareCredential(LosProcessCB *runProcessCB)
|
||||
{
|
||||
Credentials *newCredentials = CreateNewCredential(runProcessCB);
|
||||
if (newCredentials == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
newCredentials->userContainer = runProcessCB->credentials->userContainer;
|
||||
LOS_AtomicInc(&newCredentials->userContainer->rc);
|
||||
return newCredentials;
|
||||
}
|
||||
|
||||
VOID FreeCredential(Credentials *credentials)
|
||||
{
|
||||
if (credentials == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (credentials->userContainer != NULL) {
|
||||
LOS_AtomicDec(&credentials->userContainer->rc);
|
||||
if (LOS_AtomicRead(&credentials->userContainer->rc) <= 0) {
|
||||
FreeUserContainer(credentials->userContainer);
|
||||
credentials->userContainer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&credentials->rc);
|
||||
if (LOS_AtomicRead(&credentials->rc) <= 0) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, credentials);
|
||||
}
|
||||
}
|
||||
|
||||
VOID OsUserContainerDestroy(LosProcessCB *curr)
|
||||
{
|
||||
UINT32 intSave;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
FreeCredential(curr->credentials);
|
||||
curr->credentials = NULL;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC Credentials *CreateCredentials(unsigned long flags, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 ret;
|
||||
Credentials *newCredentials = CreateNewCredential(parent);
|
||||
if (newCredentials == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(flags & CLONE_NEWUSER)) {
|
||||
newCredentials->userContainer = parent->credentials->userContainer;
|
||||
LOS_AtomicInc(&newCredentials->userContainer->rc);
|
||||
return newCredentials;
|
||||
}
|
||||
|
||||
if (parent != NULL) {
|
||||
ret = OsCreateUserContainer(newCredentials, parent->credentials->userContainer);
|
||||
} else {
|
||||
ret = OsCreateUserContainer(newCredentials, NULL);
|
||||
}
|
||||
if (ret != LOS_OK) {
|
||||
FreeCredential(newCredentials);
|
||||
return NULL;
|
||||
}
|
||||
return newCredentials;
|
||||
}
|
||||
|
||||
UINT32 OsCopyCredentials(unsigned long flags, LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
child->credentials = CreateCredentials(flags, parent);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if (child->credentials == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsInitRootUserCredentials(Credentials **credentials)
|
||||
{
|
||||
*credentials = CreateCredentials(CLONE_NEWUSER, NULL);
|
||||
if (*credentials == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsUnshareUserCredentials(UINTPTR flags, LosProcessCB *curr)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (!(flags & CLONE_NEWUSER)) {
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
UINT32 ret = OsCreateUserContainer(curr->credentials, curr->credentials->userContainer);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
UINT32 OsSetNsUserContainer(struct UserContainer *targetContainer, LosProcessCB *runProcess)
|
||||
{
|
||||
Credentials *oldCredentials = runProcess->credentials;
|
||||
Credentials *newCredentials = CreateNewCredential(runProcess);
|
||||
if (newCredentials == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
runProcess->credentials = newCredentials;
|
||||
newCredentials->userContainer = targetContainer;
|
||||
LOS_AtomicInc(&targetContainer->rc);
|
||||
FreeCredential(oldCredentials);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsGetUserContainerID(Credentials *credentials)
|
||||
{
|
||||
if ((credentials == NULL) || (credentials->userContainer == NULL)) {
|
||||
return OS_INVALID_VALUE;
|
||||
}
|
||||
|
||||
return credentials->userContainer->containerID;
|
||||
}
|
||||
|
||||
INT32 CommitCredentials(Credentials *newCredentials)
|
||||
{
|
||||
Credentials *oldCredentials = OsCurrProcessGet()->credentials;
|
||||
|
||||
if (LOS_AtomicRead(&newCredentials->rc) < 1) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
OsCurrProcessGet()->credentials = newCredentials;
|
||||
FreeCredential(oldCredentials);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Credentials *CurrentCredentials(VOID)
|
||||
{
|
||||
return OsCurrProcessGet()->credentials;
|
||||
}
|
||||
|
||||
UserContainer *OsCurrentUserContainer(VOID)
|
||||
{
|
||||
UserContainer *userContainer = OsCurrProcessGet()->credentials->userContainer;
|
||||
return userContainer;
|
||||
}
|
||||
#endif
|
||||
222
kernel/base/container/los_ipc_container.c
Normal file
222
kernel/base/container/los_ipc_container.c
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
#include "los_ipc_container_pri.h"
|
||||
#include "los_config.h"
|
||||
#include "los_queue_pri.h"
|
||||
#include "los_vm_shm_pri.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "vnode.h"
|
||||
#include "proc_fs.h"
|
||||
#include "pthread.h"
|
||||
|
||||
#define IPC_INIT_NUM 3
|
||||
|
||||
STATIC UINT32 g_currentIpcContainerNum = 0;
|
||||
|
||||
STATIC IpcContainer *CreateNewIpcContainer(IpcContainer *parent)
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
UINT32 size = sizeof(IpcContainer);
|
||||
IpcContainer *ipcContainer = (IpcContainer *)LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (ipcContainer == NULL) {
|
||||
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 NULL;
|
||||
}
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
|
||||
pthread_mutex_init(&ipcContainer->mqueueMutex, &attr);
|
||||
|
||||
ipcContainer->shmSegs = OsShmCBInit(&ipcContainer->sysvShmMux, &ipcContainer->shmInfo,
|
||||
&ipcContainer->shmUsedPageCount);
|
||||
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;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
g_currentIpcContainerNum++;
|
||||
child->container->ipcContainer = newIpcContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsInitRootIpcContainer(IpcContainer **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)
|
||||
{
|
||||
UINT32 intSave;
|
||||
IpcContainer *currIpcContainer = parent->container->ipcContainer;
|
||||
|
||||
if (!(flags & CLONE_NEWIPC)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LOS_AtomicInc(&currIpcContainer->rc);
|
||||
child->container->ipcContainer = currIpcContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (OsContainerLimitCheck(IPC_CONTAINER, &g_currentIpcContainerNum) != LOS_OK) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
return CreateIpcContainer(child, parent);
|
||||
}
|
||||
|
||||
UINT32 OsUnshareIpcContainer(UINTPTR flags, LosProcessCB *curr, Container *newContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
IpcContainer *parentContainer = curr->container->ipcContainer;
|
||||
|
||||
if (!(flags & CLONE_NEWIPC)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
newContainer->ipcContainer = parentContainer;
|
||||
LOS_AtomicInc(&parentContainer->rc);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (OsContainerLimitCheck(IPC_CONTAINER, &g_currentIpcContainerNum) != LOS_OK) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
IpcContainer *ipcContainer = CreateNewIpcContainer(parentContainer);
|
||||
if (ipcContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
newContainer->ipcContainer = ipcContainer;
|
||||
g_currentIpcContainerNum++;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsSetNsIpcContainer(UINT32 flags, Container *container, Container *newContainer)
|
||||
{
|
||||
if (flags & CLONE_NEWIPC) {
|
||||
newContainer->ipcContainer = container->ipcContainer;
|
||||
LOS_AtomicInc(&container->ipcContainer->rc);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
newContainer->ipcContainer = OsCurrProcessGet()->container->ipcContainer;
|
||||
LOS_AtomicInc(&newContainer->ipcContainer->rc);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsIpcContainerDestroy(Container *container)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
IpcContainer *ipcContainer = container->ipcContainer;
|
||||
if (ipcContainer == NULL) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&ipcContainer->rc);
|
||||
if (LOS_AtomicRead(&ipcContainer->rc) > 0) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
g_currentIpcContainerNum--;
|
||||
container->ipcContainer = NULL;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
OsShmCBDestroy(ipcContainer->shmSegs, &ipcContainer->shmInfo, &ipcContainer->sysvShmMux);
|
||||
ipcContainer->shmSegs = NULL;
|
||||
OsMqueueCBDestroy(ipcContainer->queueTable);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, ipcContainer->allQueue);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, ipcContainer);
|
||||
return;
|
||||
}
|
||||
|
||||
UINT32 OsGetIpcContainerID(IpcContainer *ipcContainer)
|
||||
{
|
||||
if (ipcContainer == NULL) {
|
||||
return OS_INVALID_VALUE;
|
||||
}
|
||||
|
||||
return ipcContainer->containerID;
|
||||
}
|
||||
|
||||
IpcContainer *OsGetCurrIpcContainer(VOID)
|
||||
{
|
||||
return OsCurrProcessGet()->container->ipcContainer;
|
||||
}
|
||||
|
||||
UINT32 OsGetIpcContainerCount(VOID)
|
||||
{
|
||||
return g_currentIpcContainerNum;
|
||||
}
|
||||
#endif
|
||||
253
kernel/base/container/los_mnt_container.c
Normal file
253
kernel/base/container/los_mnt_container.c
Normal file
@@ -0,0 +1,253 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
#include <unistd.h>
|
||||
#include "los_mnt_container_pri.h"
|
||||
#include "los_container_pri.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "sys/mount.h"
|
||||
#include "vnode.h"
|
||||
#include "internal.h"
|
||||
|
||||
STATIC UINT32 g_currentMntContainerNum;
|
||||
|
||||
LIST_HEAD *GetContainerMntList(VOID)
|
||||
{
|
||||
return &OsCurrProcessGet()->container->mntContainer->mountList;
|
||||
}
|
||||
|
||||
STATIC MntContainer *CreateNewMntContainer(MntContainer *parent)
|
||||
{
|
||||
MntContainer *mntContainer = (MntContainer *)LOS_MemAlloc(m_aucSysMem1, sizeof(MntContainer));
|
||||
if (mntContainer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
mntContainer->containerID = OsAllocContainerID();
|
||||
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++;
|
||||
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;
|
||||
}
|
||||
|
||||
STATIC UINT32 CopyMountList(MntContainer *parentContainer, MntContainer *newContainer)
|
||||
{
|
||||
struct Mount *mnt = NULL;
|
||||
VnodeHold();
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(mnt, &parentContainer->mountList, struct Mount, mountList) {
|
||||
struct Mount *newMnt = (struct Mount *)zalloc(sizeof(struct Mount));
|
||||
if (newMnt == NULL) {
|
||||
VnodeDrop();
|
||||
return ENOMEM;
|
||||
}
|
||||
*newMnt = *mnt;
|
||||
LOS_ListTailInsert(&newContainer->mountList, &newMnt->mountList);
|
||||
newMnt->vnodeCovered->mntCount++;
|
||||
}
|
||||
VnodeDrop();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsCopyMntContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 intSave;
|
||||
MntContainer *currMntContainer = parent->container->mntContainer;
|
||||
|
||||
if (!(flags & CLONE_NEWNS)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LOS_AtomicInc(&currMntContainer->rc);
|
||||
child->container->mntContainer = currMntContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (OsContainerLimitCheck(MNT_CONTAINER, &g_currentMntContainerNum) != LOS_OK) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
ret = CreateMntContainer(child, parent);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
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;
|
||||
LOS_AtomicInc(&parentContainer->rc);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (OsContainerLimitCheck(MNT_CONTAINER, &g_currentMntContainerNum) != LOS_OK) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
UINT32 OsSetNsMntContainer(UINT32 flags, Container *container, Container *newContainer)
|
||||
{
|
||||
if (flags & CLONE_NEWNS) {
|
||||
newContainer->mntContainer = container->mntContainer;
|
||||
LOS_AtomicInc(&container->mntContainer->rc);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
newContainer->mntContainer = OsCurrProcessGet()->container->mntContainer;
|
||||
LOS_AtomicInc(&newContainer->mntContainer->rc);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID FreeMountList(LIST_HEAD *mountList)
|
||||
{
|
||||
struct Mount *mnt = NULL;
|
||||
struct Mount *nextMnt = NULL;
|
||||
|
||||
VnodeHold();
|
||||
if (LOS_ListEmpty(mountList)) {
|
||||
VnodeDrop();
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(mnt, nextMnt, mountList, struct Mount, mountList) {
|
||||
if (mnt->vnodeCovered->mntCount > 0) {
|
||||
mnt->vnodeCovered->mntCount--;
|
||||
LOS_ListDelete(&mnt->mountList);
|
||||
free(mnt);
|
||||
} else {
|
||||
umount(mnt->pathName);
|
||||
}
|
||||
}
|
||||
VnodeDrop();
|
||||
return;
|
||||
}
|
||||
|
||||
VOID OsMntContainerDestroy(Container *container)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
MntContainer *mntContainer = container->mntContainer;
|
||||
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;
|
||||
}
|
||||
|
||||
UINT32 OsGetMntContainerID(MntContainer *mntContainer)
|
||||
{
|
||||
if (mntContainer == NULL) {
|
||||
return OS_INVALID_VALUE;
|
||||
}
|
||||
|
||||
return mntContainer->containerID;
|
||||
}
|
||||
|
||||
UINT32 OsGetMntContainerCount(VOID)
|
||||
{
|
||||
return g_currentMntContainerNum;
|
||||
}
|
||||
#endif
|
||||
344
kernel/base/container/los_net_container.c
Normal file
344
kernel/base/container/los_net_container.c
Normal file
@@ -0,0 +1,344 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef LOSCFG_NET_CONTAINER
|
||||
#include <sched.h>
|
||||
#include "los_net_container_pri.h"
|
||||
#include "los_config.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_process_pri.h"
|
||||
|
||||
STATIC UINT32 g_currentNetContainerNum = 0;
|
||||
STATIC NetContainer *g_rootNetContainer = NULL;
|
||||
|
||||
STATIC struct netif *NetifAlloc(VOID)
|
||||
{
|
||||
UINT32 size = sizeof(struct netif);
|
||||
struct netif *netif = LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (netif == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(netif, size, 0, size);
|
||||
|
||||
return netif;
|
||||
}
|
||||
|
||||
STATIC VOID FreeNetif(struct netif *netif)
|
||||
{
|
||||
if (netif != NULL) {
|
||||
if (netif->peer != NULL) {
|
||||
netif_remove(netif->peer);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, netif->peer);
|
||||
}
|
||||
netif_remove(netif);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, netif);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC UINT32 CreateVethNetif(NetContainer *netContainer, struct netif **veth)
|
||||
{
|
||||
struct netif *netif = NetifAlloc();
|
||||
if (netif == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
veth_init(netif, netContainer->group);
|
||||
|
||||
*veth = netif;
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 InitVethPair(NetContainer *netContainer)
|
||||
{
|
||||
struct netif *vethOfNetContainer = NULL;
|
||||
struct netif *vethOfRootNetContainer = NULL;
|
||||
|
||||
UINT32 ret = CreateVethNetif(netContainer, &vethOfNetContainer);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = CreateVethNetif(g_rootNetContainer, &vethOfRootNetContainer);
|
||||
if (ret != LOS_OK) {
|
||||
FreeNetif(vethOfNetContainer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
vethOfNetContainer->peer = vethOfRootNetContainer;
|
||||
vethOfRootNetContainer->peer = vethOfNetContainer;
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 InitLoopNetif(NetContainer *netContainer)
|
||||
{
|
||||
struct netif *loop_netif = NetifAlloc();
|
||||
if (loop_netif == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
netContainer->group->loop_netif = loop_netif;
|
||||
netif_init(netContainer->group);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 InitContainerNetifs(NetContainer *netContainer)
|
||||
{
|
||||
UINT32 ret = InitLoopNetif(netContainer);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
return InitVethPair(netContainer);
|
||||
}
|
||||
|
||||
STATIC UINT32 InitNetGroup(NetContainer *netContainer)
|
||||
{
|
||||
UINT32 size = sizeof(struct net_group);
|
||||
struct net_group *group = LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (group == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
(VOID)memset_s(group, size, 0, size);
|
||||
|
||||
netContainer->group = group;
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID FreeNetContainerGroup(struct net_group *group)
|
||||
{
|
||||
if (group == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct netif *freeNetif = group->netif_list;
|
||||
struct netif *nextNetif = NULL;
|
||||
|
||||
while (freeNetif != NULL) {
|
||||
nextNetif = freeNetif->next;
|
||||
FreeNetif(freeNetif);
|
||||
freeNetif = nextNetif;
|
||||
}
|
||||
}
|
||||
|
||||
VOID OsNetContainerDestroy(Container *container)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
NetContainer *netContainer = container->netContainer;
|
||||
if (netContainer == NULL) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&netContainer->rc);
|
||||
if (LOS_AtomicRead(&netContainer->rc) > 0) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
g_currentNetContainerNum--;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
FreeNetContainerGroup(netContainer->group);
|
||||
container->netContainer = NULL;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, netContainer->group);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, netContainer);
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC NetContainer *CreateNewNetContainer(NetContainer *parent)
|
||||
{
|
||||
NetContainer *netContainer = LOS_MemAlloc(m_aucSysMem1, sizeof(NetContainer));
|
||||
if (netContainer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(netContainer, sizeof(NetContainer), 0, sizeof(NetContainer));
|
||||
|
||||
netContainer->containerID = OsAllocContainerID();
|
||||
|
||||
if (parent != NULL) {
|
||||
LOS_AtomicSet(&netContainer->rc, 1);
|
||||
} else {
|
||||
LOS_AtomicSet(&netContainer->rc, 3); /* 3: Three system processes */
|
||||
}
|
||||
return netContainer;
|
||||
}
|
||||
|
||||
STATIC UINT32 CreateNetContainer(Container *container, NetContainer *parentContainer)
|
||||
{
|
||||
UINT32 intSave, ret;
|
||||
NetContainer *newNetContainer = CreateNewNetContainer(parentContainer);
|
||||
if (newNetContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
ret = InitNetGroup(newNetContainer);
|
||||
if (ret != LOS_OK) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, newNetContainer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = InitContainerNetifs(newNetContainer);
|
||||
if (ret != LOS_OK) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, newNetContainer->group);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, newNetContainer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
g_currentNetContainerNum++;
|
||||
container->netContainer = newNetContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsCopyNetContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
NetContainer *currNetContainer = parent->container->netContainer;
|
||||
|
||||
if (!(flags & CLONE_NEWNET)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LOS_AtomicInc(&currNetContainer->rc);
|
||||
child->container->netContainer = currNetContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (OsContainerLimitCheck(NET_CONTAINER, &g_currentNetContainerNum) != LOS_OK) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
return CreateNetContainer(child->container, currNetContainer);
|
||||
}
|
||||
|
||||
UINT32 OsUnshareNetContainer(UINTPTR flags, LosProcessCB *curr, Container *newContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
NetContainer *parentContainer = curr->container->netContainer;
|
||||
|
||||
if (!(flags & CLONE_NEWNET)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
newContainer->netContainer = parentContainer;
|
||||
LOS_AtomicInc(&parentContainer->rc);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (OsContainerLimitCheck(NET_CONTAINER, &g_currentNetContainerNum) != LOS_OK) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
return CreateNetContainer(newContainer, parentContainer);
|
||||
}
|
||||
|
||||
UINT32 OsSetNsNetContainer(UINT32 flags, Container *container, Container *newContainer)
|
||||
{
|
||||
if (flags & CLONE_NEWNET) {
|
||||
newContainer->netContainer = container->netContainer;
|
||||
LOS_AtomicInc(&container->netContainer->rc);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
newContainer->netContainer = OsCurrProcessGet()->container->netContainer;
|
||||
LOS_AtomicInc(&newContainer->netContainer->rc);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsGetNetContainerID(NetContainer *netContainer)
|
||||
{
|
||||
if (netContainer == NULL) {
|
||||
return OS_INVALID_VALUE;
|
||||
}
|
||||
|
||||
return netContainer->containerID;
|
||||
}
|
||||
|
||||
STATIC struct net_group *DoGetNetGroupFromCurrProcess(VOID)
|
||||
{
|
||||
LosProcessCB *processCB = OsCurrProcessGet();
|
||||
NetContainer *netContainer = processCB->container->netContainer;
|
||||
return netContainer->group;
|
||||
}
|
||||
|
||||
STATIC VOID DoSetNetifNetGroup(struct netif *netif, struct net_group *group)
|
||||
{
|
||||
netif->group = group;
|
||||
}
|
||||
|
||||
STATIC struct net_group *DoGetNetGroupFromNetif(struct netif *netif)
|
||||
{
|
||||
return netif != NULL ? netif->group : NULL;
|
||||
}
|
||||
|
||||
STATIC VOID DoSetIppcbNetGroup(struct ip_pcb *pcb, struct net_group *group)
|
||||
{
|
||||
pcb->group = group;
|
||||
}
|
||||
|
||||
STATIC struct net_group *DoGetNetGroupFromIppcb(struct ip_pcb *pcb)
|
||||
{
|
||||
return pcb != NULL ? pcb->group : NULL;
|
||||
}
|
||||
|
||||
struct net_group_ops netGroupOps = {
|
||||
.get_curr_process_net_group = DoGetNetGroupFromCurrProcess,
|
||||
.set_netif_net_group = DoSetNetifNetGroup,
|
||||
.get_net_group_from_netif = DoGetNetGroupFromNetif,
|
||||
.set_ippcb_net_group = DoSetIppcbNetGroup,
|
||||
.get_net_group_from_ippcb = DoGetNetGroupFromIppcb,
|
||||
};
|
||||
|
||||
UINT32 OsInitRootNetContainer(NetContainer **netContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
NetContainer *newNetContainer = CreateNewNetContainer(NULL);
|
||||
if (newNetContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
newNetContainer->group = get_root_net_group();
|
||||
set_default_net_group_ops(&netGroupOps);
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
g_currentNetContainerNum++;
|
||||
*netContainer = newNetContainer;
|
||||
g_rootNetContainer = newNetContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsGetNetContainerCount(VOID)
|
||||
{
|
||||
return g_currentNetContainerNum;
|
||||
}
|
||||
#endif
|
||||
623
kernel/base/container/los_pid_container.c
Normal file
623
kernel/base/container/los_pid_container.c
Normal file
@@ -0,0 +1,623 @@
|
||||
/*
|
||||
* 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 *parentPidContainer = pidContainer->parent;
|
||||
if (LOS_AtomicRead(&pidContainer->rc) > 0) {
|
||||
pidContainer = parentPidContainer;
|
||||
continue;
|
||||
}
|
||||
g_currentPidContainerNum--;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pidContainer->rootPGroup);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pidContainer);
|
||||
if (pidContainer == processCB->container->pidContainer) {
|
||||
processCB->container->pidContainer = NULL;
|
||||
}
|
||||
pidContainer = parentPidContainer;
|
||||
}
|
||||
}
|
||||
|
||||
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, PidContainer *pidContainer,
|
||||
LosProcessCB *processCB, LosProcessCB *parent)
|
||||
{
|
||||
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;
|
||||
processVid->realParent = parent;
|
||||
processCB->processID = vpid;
|
||||
LOS_ListDelete(&processVid->node);
|
||||
LOS_AtomicInc(&pidContainer->rc);
|
||||
|
||||
if (vpid == OS_USER_ROOT_PROCESS_ID) {
|
||||
if (parent != NULL) {
|
||||
ProcessVid *vppidItem = &pidContainer->pidArray[0];
|
||||
LOS_ListDelete(&vppidItem->node);
|
||||
vppidItem->cb = (UINTPTR)parent;
|
||||
}
|
||||
|
||||
if (OsCreateProcessGroup(processCB) == NULL) {
|
||||
return OS_INVALID_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
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, LosProcessCB *parent)
|
||||
{
|
||||
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;
|
||||
do {
|
||||
ProcessVid *vpid = OsGetFreeVpid(pidContainer);
|
||||
if (vpid == NULL) {
|
||||
break;
|
||||
}
|
||||
vpid->cb = (UINTPTR)processCB;
|
||||
if (processCB->processID == OS_INVALID_VALUE) {
|
||||
processCB->processID = vpid->vid;
|
||||
vpid->realParent = parent;
|
||||
} else {
|
||||
oldProcessVid->vpid = vpid->vid;
|
||||
}
|
||||
LOS_AtomicInc(&pidContainer->rc);
|
||||
oldProcessVid = vpid;
|
||||
pidContainer = pidContainer->parent;
|
||||
} while (pidContainer != NULL);
|
||||
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;
|
||||
item->realParent = NULL;
|
||||
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 OsPidContainerDestroyAllProcess(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) || (processCB->parentProcess == NULL)) {
|
||||
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));
|
||||
|
||||
newPidContainer->containerID = OsAllocContainerID();
|
||||
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);
|
||||
newPidContainer->referenced = FALSE;
|
||||
} else {
|
||||
LOS_AtomicSet(&newPidContainer->level, 0);
|
||||
newPidContainer->referenced = TRUE;
|
||||
}
|
||||
return newPidContainer;
|
||||
}
|
||||
|
||||
VOID OsPidContainerDestroy(Container *container, LosProcessCB *processCB)
|
||||
{
|
||||
if (container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
PidContainer *pidContainer = container->pidContainer;
|
||||
if (pidContainer == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (processCB != NULL) {
|
||||
FreeVpid(processCB);
|
||||
}
|
||||
|
||||
if ((container->pidForChildContainer != NULL) && (pidContainer != container->pidForChildContainer)) {
|
||||
LOS_AtomicDec(&container->pidForChildContainer->rc);
|
||||
if (LOS_AtomicRead(&container->pidForChildContainer->rc) <= 0) {
|
||||
g_currentPidContainerNum--;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, container->pidForChildContainer);
|
||||
container->pidForChildContainer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if ((container->pidContainer != NULL) && (LOS_AtomicRead(&pidContainer->rc) <= 0)) {
|
||||
g_currentPidContainerNum--;
|
||||
container->pidContainer = NULL;
|
||||
container->pidForChildContainer = NULL;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pidContainer->rootPGroup);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pidContainer);
|
||||
}
|
||||
|
||||
if (processCB != NULL) {
|
||||
OsContainerFree(processCB);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC UINT32 CreatePidContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 intSave;
|
||||
|
||||
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) {
|
||||
(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, newPidContainer, child, parent);
|
||||
if (ret == OS_INVALID_VALUE) {
|
||||
g_currentPidContainerNum--;
|
||||
FreeVpid(child);
|
||||
child->container->pidContainer = NULL;
|
||||
child->container->pidForChildContainer = NULL;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, newPidContainer);
|
||||
return ENOSPC;
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 AllocVpidFormPidForChildContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 ret;
|
||||
PidContainer *pidContainer = parent->container->pidForChildContainer;
|
||||
child->container->pidContainer = pidContainer;
|
||||
child->container->pidForChildContainer = pidContainer;
|
||||
|
||||
if (!pidContainer->referenced) {
|
||||
pidContainer->referenced = TRUE;
|
||||
ret = OsAllocSpecifiedVpidUnsafe(OS_USER_ROOT_PROCESS_ID, pidContainer, child, parent);
|
||||
} else {
|
||||
ret = OsAllocVpid(child, parent);
|
||||
if (ret != OS_INVALID_VALUE) {
|
||||
LosProcessCB *parentProcessCB = (LosProcessCB *)pidContainer->pidArray[OS_USER_ROOT_PROCESS_ID].cb;
|
||||
child->parentProcess = parentProcessCB;
|
||||
LOS_ListTailInsert(&parentProcessCB->childrenList, &child->siblingList);
|
||||
child->pgroup = parentProcessCB->pgroup;
|
||||
LOS_ListTailInsert(&parentProcessCB->pgroup->processList, &child->subordinateGroupList);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 intSave;
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
PidContainer *parentPidContainer = parent->container->pidContainer;
|
||||
PidContainer *parentPidContainerForChild = parent->container->pidForChildContainer;
|
||||
if (parentPidContainer == parentPidContainerForChild) {
|
||||
/* The current process is not executing unshare */
|
||||
if (!(flags & CLONE_NEWPID)) {
|
||||
child->container->pidContainer = parentPidContainer;
|
||||
child->container->pidForChildContainer = parentPidContainer;
|
||||
ret = OsAllocVpid(child, parent);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if (ret == OS_INVALID_VALUE) {
|
||||
PRINT_ERR("[%s] alloc vpid failed\n", __FUNCTION__);
|
||||
return ENOSPC;
|
||||
}
|
||||
*processID = child->processID;
|
||||
return LOS_OK;
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
if (OsContainerLimitCheck(PID_CONTAINER, &g_currentPidContainerNum) != LOS_OK) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
ret = CreatePidContainer(child, parent);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
/* Create the first process after unshare */
|
||||
ret = AllocVpidFormPidForChildContainer(child, parent);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
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 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->pidForChildContainer;
|
||||
if (newContainer->pidContainer != newContainer->pidForChildContainer) {
|
||||
LOS_AtomicInc(&newContainer->pidForChildContainer->rc);
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (OsContainerLimitCheck(PID_CONTAINER, &g_currentPidContainerNum) != LOS_OK) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
g_currentPidContainerNum++;
|
||||
newContainer->pidContainer = curr->container->pidContainer;
|
||||
newContainer->pidForChildContainer = pidForChild;
|
||||
LOS_AtomicSet(&pidForChild->rc, 1);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsSetNsPidContainer(UINT32 flags, Container *container, Container *newContainer)
|
||||
{
|
||||
UINT32 ret = LOS_OK;
|
||||
LosProcessCB *curr = OsCurrProcessGet();
|
||||
newContainer->pidContainer = curr->container->pidContainer;
|
||||
|
||||
if (flags & CLONE_NEWPID) {
|
||||
newContainer->pidForChildContainer = container->pidContainer;
|
||||
LOS_AtomicInc(&container->pidContainer->rc);
|
||||
return ret;
|
||||
}
|
||||
|
||||
newContainer->pidForChildContainer = curr->container->pidForChildContainer;
|
||||
if (newContainer->pidContainer != newContainer->pidForChildContainer) {
|
||||
LOS_AtomicInc(&newContainer->pidForChildContainer->rc);
|
||||
}
|
||||
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 OsGetVpidFromRootContainer(const LosProcessCB *processCB)
|
||||
{
|
||||
UINT32 vpid = processCB->processID;
|
||||
PidContainer *pidContainer = processCB->container->pidContainer;
|
||||
while (pidContainer != NULL) {
|
||||
ProcessVid *vid = &pidContainer->pidArray[vpid];
|
||||
if (pidContainer->parent != NULL) {
|
||||
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;
|
||||
}
|
||||
|
||||
BOOL OsPidContainerProcessParentIsRealParent(const LosProcessCB *processCB, const LosProcessCB *curr)
|
||||
{
|
||||
if (curr == processCB->parentProcess) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
PidContainer *pidContainer = processCB->container->pidContainer;
|
||||
ProcessVid *processVid = &pidContainer->pidArray[processCB->processID];
|
||||
if (processVid->realParent == curr) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
UINT32 OsGetPidContainerID(PidContainer *pidContainer)
|
||||
{
|
||||
if (pidContainer == NULL) {
|
||||
return OS_INVALID_VALUE;
|
||||
}
|
||||
|
||||
return pidContainer->containerID;
|
||||
}
|
||||
|
||||
UINT32 OsGetPidContainerCount(VOID)
|
||||
{
|
||||
return g_currentPidContainerNum;
|
||||
}
|
||||
#endif
|
||||
258
kernel/base/container/los_time_container.c
Normal file
258
kernel/base/container/los_time_container.c
Normal file
@@ -0,0 +1,258 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
TimeContainer *newTimeContainer = parent->container->timeForChildContainer;
|
||||
LOS_AtomicInc(&newTimeContainer->rc);
|
||||
newTimeContainer->frozenOffsets = TRUE;
|
||||
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 (currTimeContainer == parent->container->timeForChildContainer) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LOS_AtomicInc(&currTimeContainer->rc);
|
||||
child->container->timeContainer = currTimeContainer;
|
||||
child->container->timeForChildContainer = currTimeContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (OsContainerLimitCheck(TIME_CONTAINER, &g_currentTimeContainerNum) != LOS_OK) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
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;
|
||||
LOS_AtomicInc(&newContainer->timeContainer->rc);
|
||||
if (newContainer->timeContainer != newContainer->timeForChildContainer) {
|
||||
LOS_AtomicInc(&newContainer->timeForChildContainer->rc);
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (OsContainerLimitCheck(TIME_CONTAINER, &g_currentTimeContainerNum) != LOS_OK) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
(VOID)memcpy_s(&timeForChild->monotonic, sizeof(struct timespec64),
|
||||
&curr->container->timeContainer->monotonic, sizeof(struct timespec64));
|
||||
newContainer->timeContainer = curr->container->timeContainer;
|
||||
LOS_AtomicInc(&newContainer->timeContainer->rc);
|
||||
newContainer->timeForChildContainer = timeForChild;
|
||||
g_currentTimeContainerNum++;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsSetNsTimeContainer(UINT32 flags, Container *container, Container *newContainer)
|
||||
{
|
||||
LosProcessCB *curr = OsCurrProcessGet();
|
||||
if (flags & CLONE_NEWTIME) {
|
||||
container->timeContainer->frozenOffsets = TRUE;
|
||||
newContainer->timeContainer = container->timeContainer;
|
||||
newContainer->timeForChildContainer = container->timeContainer;
|
||||
LOS_AtomicInc(&container->timeContainer->rc);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
newContainer->timeContainer = curr->container->timeContainer;
|
||||
LOS_AtomicInc(&curr->container->timeContainer->rc);
|
||||
newContainer->timeForChildContainer = curr->container->timeForChildContainer;
|
||||
if (curr->container->timeContainer != curr->container->timeForChildContainer) {
|
||||
LOS_AtomicInc(&curr->container->timeForChildContainer->rc);
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsTimeContainerDestroy(Container *container)
|
||||
{
|
||||
UINT32 intSave;
|
||||
TimeContainer *timeContainer = NULL;
|
||||
TimeContainer *timeForChild = NULL;
|
||||
|
||||
if (container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (container->timeContainer == NULL) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((container->timeForChildContainer != NULL) && (container->timeContainer != container->timeForChildContainer)) {
|
||||
LOS_AtomicDec(&container->timeForChildContainer->rc);
|
||||
if (LOS_AtomicRead(&container->timeForChildContainer->rc) <= 0) {
|
||||
g_currentTimeContainerNum--;
|
||||
timeForChild = container->timeForChildContainer;
|
||||
container->timeForChildContainer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&container->timeContainer->rc);
|
||||
if (LOS_AtomicRead(&container->timeContainer->rc) <= 0) {
|
||||
g_currentTimeContainerNum--;
|
||||
timeContainer = container->timeContainer;
|
||||
container->timeContainer = NULL;
|
||||
container->timeForChildContainer = NULL;
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, timeForChild);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, timeContainer);
|
||||
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;
|
||||
}
|
||||
|
||||
UINT32 OsGetTimeContainerCount(VOID)
|
||||
{
|
||||
return g_currentTimeContainerNum;
|
||||
}
|
||||
#endif
|
||||
439
kernel/base/container/los_user_container.c
Normal file
439
kernel/base/container/los_user_container.c
Normal file
@@ -0,0 +1,439 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
#include "los_user_container_pri.h"
|
||||
#include "errno.h"
|
||||
#include "ctype.h"
|
||||
#include "los_config.h"
|
||||
#include "los_memory.h"
|
||||
#include "proc_fs.h"
|
||||
#include "user_copy.h"
|
||||
#include "los_seq_buf.h"
|
||||
#include "capability_type.h"
|
||||
#include "capability_api.h"
|
||||
#include "internal.h"
|
||||
|
||||
#define DEFAULT_OVERFLOWUID 65534
|
||||
#define DEFAULT_OVERFLOWGID 65534
|
||||
#define LEVEL_MAX 3
|
||||
#define HEX 16
|
||||
#define OCT 8
|
||||
#define DEC 10
|
||||
|
||||
UINT32 g_currentUserContainerNum = 0;
|
||||
|
||||
UINT32 OsCreateUserContainer(Credentials *newCredentials, UserContainer *parentUserContainer)
|
||||
{
|
||||
if (g_currentUserContainerNum >= OsGetContainerLimit(USER_CONTAINER)) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
if ((parentUserContainer != NULL) && (parentUserContainer->level >= LEVEL_MAX)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if ((newCredentials->euid < 0) || (newCredentials->egid < 0)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
UserContainer *userContainer = LOS_MemAlloc(m_aucSysMem1, sizeof(UserContainer));
|
||||
if (userContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
(VOID)memset_s(userContainer, sizeof(UserContainer), 0, sizeof(UserContainer));
|
||||
|
||||
g_currentUserContainerNum++;
|
||||
userContainer->containerID = OsAllocContainerID();
|
||||
userContainer->parent = parentUserContainer;
|
||||
newCredentials->userContainer = userContainer;
|
||||
if (parentUserContainer != NULL) {
|
||||
LOS_AtomicInc(&parentUserContainer->rc);
|
||||
LOS_AtomicSet(&userContainer->rc, 1);
|
||||
userContainer->level = parentUserContainer->level + 1;
|
||||
userContainer->owner = newCredentials->euid;
|
||||
userContainer->group = newCredentials->egid;
|
||||
} else {
|
||||
LOS_AtomicSet(&userContainer->rc, 3); /* 3: Three system processes */
|
||||
userContainer->uidMap.extentCount = 1;
|
||||
userContainer->uidMap.extent[0].count = 4294967295U;
|
||||
userContainer->gidMap.extentCount = 1;
|
||||
userContainer->gidMap.extent[0].count = 4294967295U;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID FreeUserContainer(UserContainer *userContainer)
|
||||
{
|
||||
UserContainer *parent = NULL;
|
||||
do {
|
||||
parent = userContainer->parent;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, userContainer);
|
||||
userContainer->parent = NULL;
|
||||
userContainer = parent;
|
||||
g_currentUserContainerNum--;
|
||||
if (userContainer == NULL) {
|
||||
break;
|
||||
}
|
||||
LOS_AtomicDec(&userContainer->rc);
|
||||
} while (LOS_AtomicRead(&userContainer->rc) <= 0);
|
||||
}
|
||||
|
||||
STATIC UidGidExtent *MapIdUpBase(UINT32 extents, UidGidMap *map, UINT32 id)
|
||||
{
|
||||
UINT32 idx;
|
||||
UINT32 first;
|
||||
UINT32 last;
|
||||
|
||||
for (idx = 0; idx < extents; idx++) {
|
||||
first = map->extent[idx].lowerFirst;
|
||||
last = first + map->extent[idx].count - 1;
|
||||
if ((id >= first) && (id <= last)) {
|
||||
return &map->extent[idx];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC UINT32 MapIdUp(UidGidMap *map, UINT32 id)
|
||||
{
|
||||
UINT32 extents = map->extentCount;
|
||||
if (extents > UID_GID_MAP_MAX_EXTENTS) {
|
||||
return (UINT32)-1;
|
||||
}
|
||||
|
||||
UidGidExtent *extent = MapIdUpBase(extents, map, id);
|
||||
if (extent != NULL) {
|
||||
return ((id - extent->lowerFirst) + extent->first);
|
||||
}
|
||||
|
||||
return (UINT32)-1;
|
||||
}
|
||||
|
||||
UINT32 FromKuid(UserContainer *userContainer, UINT32 kuid)
|
||||
{
|
||||
return MapIdUp(&userContainer->uidMap, kuid);
|
||||
}
|
||||
|
||||
UINT32 FromKgid(UserContainer *userContainer, UINT32 kgid)
|
||||
{
|
||||
return MapIdUp(&userContainer->gidMap, kgid);
|
||||
}
|
||||
|
||||
UINT32 OsFromKuidMunged(UserContainer *userContainer, UINT32 kuid)
|
||||
{
|
||||
UINT32 uid = FromKuid(userContainer, kuid);
|
||||
if (uid == (UINT32)-1) {
|
||||
uid = DEFAULT_OVERFLOWUID;
|
||||
}
|
||||
return uid;
|
||||
}
|
||||
|
||||
UINT32 OsFromKgidMunged(UserContainer *userContainer, UINT32 kgid)
|
||||
{
|
||||
UINT32 gid = FromKgid(userContainer, kgid);
|
||||
if (gid == (UINT32)-1) {
|
||||
gid = DEFAULT_OVERFLOWGID;
|
||||
}
|
||||
return gid;
|
||||
}
|
||||
|
||||
STATIC UidGidExtent *MapIdRangeDownBase(UINT32 extents, UidGidMap *map, UINT32 id, UINT32 count)
|
||||
{
|
||||
UINT32 idx;
|
||||
UINT32 first;
|
||||
UINT32 last;
|
||||
UINT32 id2;
|
||||
|
||||
id2 = id + count - 1;
|
||||
for (idx = 0; idx < extents; idx++) {
|
||||
first = map->extent[idx].first;
|
||||
last = first + map->extent[idx].count - 1;
|
||||
if ((id >= first && id <= last) && (id2 >= first && id2 <= last)) {
|
||||
return &map->extent[idx];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC UINT32 MapIdRangeDown(UidGidMap *map, UINT32 id, UINT32 count)
|
||||
{
|
||||
UINT32 extents = map->extentCount;
|
||||
if (extents > UID_GID_MAP_MAX_EXTENTS) {
|
||||
return (UINT32)-1;
|
||||
}
|
||||
|
||||
UidGidExtent *extent = MapIdRangeDownBase(extents, map, id, count);
|
||||
if (extent != NULL) {
|
||||
return ((id - extent->first) + extent->lowerFirst);
|
||||
}
|
||||
|
||||
return (UINT32)-1;
|
||||
}
|
||||
|
||||
STATIC UINT32 MapIdDown(UidGidMap *map, UINT32 id)
|
||||
{
|
||||
return MapIdRangeDown(map, id, 1);
|
||||
}
|
||||
|
||||
UINT32 OsMakeKuid(UserContainer *userContainer, UINT32 uid)
|
||||
{
|
||||
return MapIdDown(&userContainer->uidMap, uid);
|
||||
}
|
||||
|
||||
UINT32 OsMakeKgid(UserContainer *userContainer, UINT32 gid)
|
||||
{
|
||||
return MapIdDown(&userContainer->gidMap, gid);
|
||||
}
|
||||
|
||||
STATIC INT32 InsertExtent(UidGidMap *idMap, UidGidExtent *extent)
|
||||
{
|
||||
if (idMap->extentCount > UID_GID_MAP_MAX_EXTENTS) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
UidGidExtent *dest = &idMap->extent[idMap->extentCount];
|
||||
*dest = *extent;
|
||||
idMap->extentCount++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC BOOL MappingsOverlap(UidGidMap *idMap, UidGidExtent *extent)
|
||||
{
|
||||
UINT32 upperFirst = extent->first;
|
||||
UINT32 lowerFirst = extent->lowerFirst;
|
||||
UINT32 upperLast = upperFirst + extent->count - 1;
|
||||
UINT32 lowerLast = lowerFirst + extent->count - 1;
|
||||
INT32 idx;
|
||||
|
||||
for (idx = 0; idx < idMap->extentCount; idx++) {
|
||||
if (idMap->extentCount > UID_GID_MAP_MAX_EXTENTS) {
|
||||
return TRUE;
|
||||
}
|
||||
UidGidExtent *prev = &idMap->extent[idx];
|
||||
UINT32 prevUpperFirst = prev->first;
|
||||
UINT32 prevLowerFirst = prev->lowerFirst;
|
||||
UINT32 prevUpperLast = prevUpperFirst + prev->count - 1;
|
||||
UINT32 prevLowerLast = prevLowerFirst + prev->count - 1;
|
||||
|
||||
if ((prevUpperFirst <= upperLast) && (prevUpperLast >= upperFirst)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if ((prevLowerFirst <= lowerLast) && (prevLowerLast >= lowerFirst)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
STATIC CHAR *SkipSpaces(const CHAR *str)
|
||||
{
|
||||
while (isspace(*str)) {
|
||||
++str;
|
||||
}
|
||||
|
||||
return (CHAR *)str;
|
||||
}
|
||||
|
||||
STATIC UINTPTR StrToUInt(const CHAR *str, CHAR **endp, UINT32 base)
|
||||
{
|
||||
unsigned long result = 0;
|
||||
unsigned long value;
|
||||
|
||||
if (*str == '0') {
|
||||
str++;
|
||||
if ((*str == 'x') && isxdigit(str[1])) {
|
||||
base = HEX;
|
||||
str++;
|
||||
}
|
||||
if (!base) {
|
||||
base = OCT;
|
||||
}
|
||||
}
|
||||
if (!base) {
|
||||
base = DEC;
|
||||
}
|
||||
while (isxdigit(*str) && (value = isdigit(*str) ? *str - '0' : (islower(*str) ?
|
||||
toupper(*str) : *str) - 'A' + DEC) < base) {
|
||||
result = result * base + value;
|
||||
str++;
|
||||
}
|
||||
if (endp != NULL) {
|
||||
*endp = (CHAR *)str;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
STATIC INT32 ParsePosData(CHAR *pos, UidGidExtent *extent)
|
||||
{
|
||||
INT32 ret = -EINVAL;
|
||||
pos = SkipSpaces(pos);
|
||||
extent->first = StrToUInt(pos, &pos, DEC);
|
||||
if (!isspace(*pos)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
pos = SkipSpaces(pos);
|
||||
extent->lowerFirst = StrToUInt(pos, &pos, DEC);
|
||||
if (!isspace(*pos)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
pos = SkipSpaces(pos);
|
||||
extent->count = StrToUInt(pos, &pos, DEC);
|
||||
if (*pos && !isspace(*pos)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
pos = SkipSpaces(pos);
|
||||
if (*pos != '\0') {
|
||||
return ret;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 ParseUserData(CHAR *kbuf, UidGidExtent *extent, UidGidMap *newMap)
|
||||
{
|
||||
INT32 ret = -EINVAL;
|
||||
CHAR *pos = NULL;
|
||||
CHAR *nextLine = NULL;
|
||||
|
||||
for (pos = kbuf; pos != NULL; pos = nextLine) {
|
||||
nextLine = strchr(pos, '\n');
|
||||
if (nextLine != NULL) {
|
||||
*nextLine = '\0';
|
||||
nextLine++;
|
||||
if (*nextLine == '\0') {
|
||||
nextLine = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (ParsePosData(pos, extent) != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((extent->first == (UINT32)-1) || (extent->lowerFirst == (UINT32)-1)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((extent->first + extent->count) <= extent->first) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((extent->lowerFirst + extent->count) <= extent->lowerFirst) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (MappingsOverlap(newMap, extent)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((newMap->extentCount + 1) == UID_GID_MAP_MAX_EXTENTS && (nextLine != NULL)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = InsertExtent(newMap, extent);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
if (newMap->extentCount == 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
STATIC INT32 ParentMapIdRange(UidGidMap *newMap, UidGidMap *parentMap)
|
||||
{
|
||||
UINT32 idx;
|
||||
INT32 ret = -EPERM;
|
||||
for (idx = 0; idx < newMap->extentCount; idx++) {
|
||||
if (newMap->extentCount > UID_GID_MAP_MAX_EXTENTS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
UidGidExtent *extent = &newMap->extent[idx];
|
||||
UINT32 lowerFirst = MapIdRangeDown(parentMap, extent->lowerFirst, extent->count);
|
||||
if (lowerFirst == (UINT32) -1) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
extent->lowerFirst = lowerFirst;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
INT32 OsUserContainerMapWrite(struct ProcFile *fp, CHAR *kbuf, size_t count,
|
||||
INT32 capSetid, UidGidMap *map, UidGidMap *parentMap)
|
||||
{
|
||||
UidGidMap newMap = {0};
|
||||
UidGidExtent extent;
|
||||
INT32 ret;
|
||||
|
||||
if (map->extentCount != 0) {
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
if (!IsCapPermit(capSetid)) {
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
ret = ParseUserData(kbuf, &extent, &newMap);
|
||||
if (ret < 0) {
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
ret = ParentMapIdRange(&newMap, parentMap);
|
||||
if (ret < 0) {
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
if (newMap.extentCount <= UID_GID_MAP_MAX_EXTENTS) {
|
||||
size_t mapSize = newMap.extentCount * sizeof(newMap.extent[0]);
|
||||
ret = memcpy_s(map->extent, sizeof(map->extent), newMap.extent, mapSize);
|
||||
if (ret != EOK) {
|
||||
return -EPERM;
|
||||
}
|
||||
}
|
||||
|
||||
map->extentCount = newMap.extentCount;
|
||||
return count;
|
||||
}
|
||||
|
||||
UINT32 OsGetUserContainerCount(VOID)
|
||||
{
|
||||
return g_currentUserContainerNum;
|
||||
}
|
||||
#endif
|
||||
240
kernel/base/container/los_uts_container.c
Normal file
240
kernel/base/container/los_uts_container.c
Normal file
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
#include "internal.h"
|
||||
#include "los_uts_container_pri.h"
|
||||
#include "los_process_pri.h"
|
||||
|
||||
STATIC UINT32 g_currentUtsContainerNum;
|
||||
|
||||
STATIC UINT32 InitUtsContainer(struct utsname *name)
|
||||
{
|
||||
INT32 ret = sprintf_s(name->sysname, sizeof(name->sysname), "%s", KERNEL_NAME);
|
||||
if (ret < 0) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
ret = sprintf_s(name->nodename, sizeof(name->nodename), "%s", KERNEL_NODE_NAME);
|
||||
if (ret < 0) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
ret = sprintf_s(name->version, sizeof(name->version), "%s %u.%u.%u.%u %s %s",
|
||||
KERNEL_NAME, KERNEL_MAJOR, KERNEL_MINOR, KERNEL_PATCH, KERNEL_ITRE, __DATE__, __TIME__);
|
||||
if (ret < 0) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
const char *cpuInfo = LOS_CpuInfo();
|
||||
ret = sprintf_s(name->machine, sizeof(name->machine), "%s", cpuInfo);
|
||||
if (ret < 0) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
ret = sprintf_s(name->release, sizeof(name->release), "%u.%u.%u.%u",
|
||||
KERNEL_MAJOR, KERNEL_MINOR, KERNEL_PATCH, KERNEL_ITRE);
|
||||
if (ret < 0) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
name->domainname[0] = '\0';
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UtsContainer *CreateNewUtsContainer(UtsContainer *parent)
|
||||
{
|
||||
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) {
|
||||
(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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (OsContainerLimitCheck(UTS_CONTAINER, &g_currentUtsContainerNum) != LOS_OK) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
return CreateUtsContainer(child, parent);
|
||||
}
|
||||
|
||||
UINT32 OsUnshareUtsContainer(UINTPTR flags, LosProcessCB *curr, Container *newContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UtsContainer *parentContainer = curr->container->utsContainer;
|
||||
|
||||
if (!(flags & CLONE_NEWUTS)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
newContainer->utsContainer = parentContainer;
|
||||
LOS_AtomicInc(&parentContainer->rc);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (OsContainerLimitCheck(UTS_CONTAINER, &g_currentUtsContainerNum) != LOS_OK) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
UINT32 OsSetNsUtsContainer(UINT32 flags, Container *container, Container *newContainer)
|
||||
{
|
||||
if (flags & CLONE_NEWUTS) {
|
||||
newContainer->utsContainer = container->utsContainer;
|
||||
LOS_AtomicInc(&container->utsContainer->rc);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
newContainer->utsContainer = OsCurrProcessGet()->container->utsContainer;
|
||||
LOS_AtomicInc(&newContainer->utsContainer->rc);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsUtsContainerDestroy(Container *container)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
UtsContainer *utsContainer = container->utsContainer;
|
||||
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;
|
||||
}
|
||||
|
||||
struct utsname *OsGetCurrUtsName(VOID)
|
||||
{
|
||||
Container *container = OsCurrProcessGet()->container;
|
||||
if (container == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
UtsContainer *utsContainer = container->utsContainer;
|
||||
if (utsContainer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return &utsContainer->utsName;
|
||||
}
|
||||
|
||||
UINT32 OsGetUtsContainerID(UtsContainer *utsContainer)
|
||||
{
|
||||
if (utsContainer == NULL) {
|
||||
return OS_INVALID_VALUE;
|
||||
}
|
||||
|
||||
return utsContainer->containerID;
|
||||
}
|
||||
|
||||
UINT32 OsGetUtsContainerCount(VOID)
|
||||
{
|
||||
return g_currentUtsContainerNum;
|
||||
}
|
||||
#endif
|
||||
256
kernel/base/core/los_info.c
Normal file
256
kernel/base/core/los_info.c
Normal file
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* 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, ¶m);
|
||||
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);
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
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, ¶m);
|
||||
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;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
GetProcessMemInfo(&threadInfo->processInfo, processCB, processCB->vmSpace);
|
||||
#endif
|
||||
|
||||
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;
|
||||
}
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
LosVmSpace *vmSpace = processCB->vmSpace;
|
||||
#endif
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
GetProcessMemInfo(pcbInfo, processCB, vmSpace);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
VOID *stackPtr = OsTaskStackInit(taskCB->taskID, initParam->uwStackSize, topStack, TRUE);
|
||||
errRet = OsTaskCBInit(taskCB, initParam, stackPtr, topStack);
|
||||
errRet = TaskSyncCreate(taskCB);
|
||||
if (errRet != LOS_OK) {
|
||||
goto LOS_ERREND_TCB_INIT;
|
||||
goto DEINIT_TCB;
|
||||
}
|
||||
|
||||
errRet = TaskStackInit(taskCB, initParam);
|
||||
if (errRet != LOS_OK) {
|
||||
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);
|
||||
|
||||
148
kernel/base/include/los_container_pri.h
Normal file
148
kernel/base/include/los_container_pri.h
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* 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
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
#include "los_uts_container_pri.h"
|
||||
#endif
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
#include "los_mnt_container_pri.h"
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
#include "los_ipc_container_pri.h"
|
||||
#endif
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
#include "los_user_container_pri.h"
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
#include "los_time_container_pri.h"
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_CONTAINER
|
||||
#include "los_net_container_pri.h"
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
CONTAINER = 0,
|
||||
PID_CONTAINER,
|
||||
PID_CHILD_CONTAINER,
|
||||
UTS_CONTAINER,
|
||||
MNT_CONTAINER,
|
||||
IPC_CONTAINER,
|
||||
USER_CONTAINER,
|
||||
TIME_CONTAINER,
|
||||
TIME_CHILD_CONTAINER,
|
||||
NET_CONTAINER,
|
||||
CONTAINER_MAX,
|
||||
} ContainerType;
|
||||
|
||||
typedef struct Container {
|
||||
Atomic rc;
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
struct PidContainer *pidContainer;
|
||||
struct PidContainer *pidForChildContainer;
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
struct UtsContainer *utsContainer;
|
||||
#endif
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
struct MntContainer *mntContainer;
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
struct IpcContainer *ipcContainer;
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
struct TimeContainer *timeContainer;
|
||||
struct TimeContainer *timeForChildContainer;
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_CONTAINER
|
||||
struct NetContainer *netContainer;
|
||||
#endif
|
||||
} Container;
|
||||
|
||||
typedef struct TagContainerLimit {
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
UINT32 pidLimit;
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
UINT32 utsLimit;
|
||||
#endif
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
UINT32 mntLimit;
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
UINT32 ipcLimit;
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
UINT32 timeLimit;
|
||||
#endif
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
UINT32 userLimit;
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_CONTAINER
|
||||
UINT32 netLimit;
|
||||
#endif
|
||||
} ContainerLimit;
|
||||
|
||||
VOID OsContainerInitSystemProcess(LosProcessCB *processCB);
|
||||
|
||||
VOID OsInitRootContainer(VOID);
|
||||
|
||||
UINT32 OsCopyContainers(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID);
|
||||
|
||||
VOID OsOsContainersDestroyEarly(LosProcessCB *processCB);
|
||||
|
||||
VOID OsContainersDestroy(LosProcessCB *processCB);
|
||||
|
||||
VOID OsContainerFree(LosProcessCB *processCB);
|
||||
|
||||
UINT32 OsAllocContainerID(VOID);
|
||||
|
||||
UINT32 OsGetContainerID(LosProcessCB *processCB, ContainerType type);
|
||||
|
||||
INT32 OsUnshare(UINT32 flags);
|
||||
|
||||
INT32 OsSetNs(INT32 fd, INT32 type);
|
||||
|
||||
UINT32 OsGetContainerLimit(ContainerType type);
|
||||
|
||||
UINT32 OsContainerLimitCheck(ContainerType type, UINT32 *containerCount);
|
||||
|
||||
UINT32 OsSetContainerLimit(ContainerType type, UINT32 value);
|
||||
|
||||
UINT32 OsGetContainerCount(ContainerType type);
|
||||
#endif
|
||||
#endif /* _LOS_CONTAINER_PRI_H */
|
||||
73
kernel/base/include/los_credentials_pri.h
Normal file
73
kernel/base/include/los_credentials_pri.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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_CREDENTIALS_PRI_H
|
||||
#define _LOS_CREDENTIALS_PRI_H
|
||||
|
||||
#include "los_atomic.h"
|
||||
#include "los_list.h"
|
||||
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
struct Container;
|
||||
struct UserContainer;
|
||||
typedef struct ProcessCB LosProcessCB;
|
||||
|
||||
typedef struct Credentials {
|
||||
Atomic rc;
|
||||
UINT32 uid;
|
||||
UINT32 gid;
|
||||
UINT32 euid;
|
||||
UINT32 egid;
|
||||
struct UserContainer *userContainer;
|
||||
} Credentials;
|
||||
|
||||
UINT32 OsCopyCredentials(unsigned long flags, LosProcessCB *child, LosProcessCB *parent);
|
||||
|
||||
UINT32 OsInitRootUserCredentials(Credentials **credentials);
|
||||
|
||||
UINT32 OsUnshareUserCredentials(UINTPTR flags, LosProcessCB *curr);
|
||||
|
||||
UINT32 OsSetNsUserContainer(struct UserContainer *targetContainer, LosProcessCB *runProcess);
|
||||
|
||||
VOID FreeCredential(Credentials *credentials);
|
||||
|
||||
VOID OsUserContainerDestroy(LosProcessCB *curr);
|
||||
|
||||
UINT32 OsGetUserContainerID(Credentials *credentials);
|
||||
|
||||
Credentials *PrepareCredential(LosProcessCB *runProcessCB);
|
||||
|
||||
INT32 CommitCredentials(Credentials *newCredentials);
|
||||
|
||||
Credentials *CurrentCredentials(VOID);
|
||||
|
||||
struct UserContainer *OsCurrentUserContainer(VOID);
|
||||
#endif
|
||||
#endif /* _LOS_CREDENTIALS_PRI_H */
|
||||
108
kernel/base/include/los_info_pri.h
Normal file
108
kernel/base/include/los_info_pri.h
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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 */
|
||||
98
kernel/base/include/los_ipc_container_pri.h
Normal file
98
kernel/base/include/los_ipc_container_pri.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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_IPC_CONTAINER_PRI_H
|
||||
#define _LOS_IPC_CONTAINER_PRI_H
|
||||
|
||||
#include "los_atomic.h"
|
||||
#include "los_list.h"
|
||||
#include "mqueue.h"
|
||||
#include "fs/file.h"
|
||||
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
struct shmIDSource;
|
||||
struct Container;
|
||||
typedef struct TagQueueCB LosQueueCB;
|
||||
typedef struct OsMux LosMux;
|
||||
typedef LosMux pthread_mutex_t;
|
||||
typedef struct ProcessCB LosProcessCB;
|
||||
|
||||
typedef struct IpcContainer {
|
||||
Atomic rc;
|
||||
LosQueueCB *allQueue;
|
||||
LOS_DL_LIST freeQueueList;
|
||||
fd_set queueFdSet;
|
||||
struct mqarray queueTable[LOSCFG_BASE_IPC_QUEUE_LIMIT];
|
||||
pthread_mutex_t mqueueMutex;
|
||||
struct mqpersonal *mqPrivBuf[MAX_MQ_FD];
|
||||
struct shminfo shmInfo;
|
||||
LosMux sysvShmMux;
|
||||
struct shmIDSource *shmSegs;
|
||||
UINT32 shmUsedPageCount;
|
||||
UINT32 containerID;
|
||||
} IpcContainer;
|
||||
|
||||
UINT32 OsInitRootIpcContainer(IpcContainer **ipcContainer);
|
||||
|
||||
UINT32 OsCopyIpcContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent);
|
||||
|
||||
UINT32 OsUnshareIpcContainer(UINTPTR flags, LosProcessCB *curr, struct Container *newContainer);
|
||||
|
||||
UINT32 OsSetNsIpcContainer(UINT32 flags, struct Container *container, struct Container *newContainer);
|
||||
|
||||
VOID OsIpcContainerDestroy(struct Container *container);
|
||||
|
||||
UINT32 OsGetIpcContainerID(IpcContainer *ipcContainer);
|
||||
|
||||
IpcContainer *OsGetCurrIpcContainer(VOID);
|
||||
|
||||
UINT32 OsGetIpcContainerCount(VOID);
|
||||
|
||||
#define IPC_ALL_QUEUE (OsGetCurrIpcContainer()->allQueue)
|
||||
|
||||
#define FREE_QUEUE_LIST (OsGetCurrIpcContainer()->freeQueueList)
|
||||
|
||||
#define IPC_QUEUE_FD_SET (OsGetCurrIpcContainer()->queueFdSet)
|
||||
|
||||
#define IPC_QUEUE_TABLE (OsGetCurrIpcContainer()->queueTable)
|
||||
|
||||
#define IPC_QUEUE_MUTEX (OsGetCurrIpcContainer()->mqueueMutex)
|
||||
|
||||
#define IPC_QUEUE_MQ_PRIV_BUF (OsGetCurrIpcContainer()->mqPrivBuf)
|
||||
|
||||
#define IPC_SHM_INFO (OsGetCurrIpcContainer()->shmInfo)
|
||||
|
||||
#define IPC_SHM_SYS_VSHM_MUTEX (OsGetCurrIpcContainer()->sysvShmMux)
|
||||
|
||||
#define IPC_SHM_SEGS (OsGetCurrIpcContainer()->shmSegs)
|
||||
|
||||
#define IPC_SHM_USED_PAGE_COUNT (OsGetCurrIpcContainer()->shmUsedPageCount)
|
||||
|
||||
#endif
|
||||
#endif /* _LOS_IPC_CONTAINER_PRI_H */
|
||||
66
kernel/base/include/los_mnt_container_pri.h
Normal file
66
kernel/base/include/los_mnt_container_pri.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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_MNT_CONTAINER_PRI_H
|
||||
#define _LOS_MNT_CONTAINER_PRI_H
|
||||
|
||||
#include "fs/mount.h"
|
||||
#include "sched.h"
|
||||
#include "los_atomic.h"
|
||||
#include "vnode.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
typedef struct ProcessCB LosProcessCB;
|
||||
struct Container;
|
||||
|
||||
typedef struct MntContainer {
|
||||
Atomic rc;
|
||||
UINT32 containerID;
|
||||
LIST_HEAD mountList;
|
||||
} MntContainer;
|
||||
|
||||
LIST_HEAD *GetContainerMntList(VOID);
|
||||
|
||||
UINT32 OsInitRootMntContainer(MntContainer **mntContainer);
|
||||
|
||||
UINT32 OsCopyMntContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent);
|
||||
|
||||
UINT32 OsUnshareMntContainer(UINTPTR flags, LosProcessCB *curr, struct Container *newContainer);
|
||||
|
||||
UINT32 OsSetNsMntContainer(UINT32 flags, struct Container *container, struct Container *newContainer);
|
||||
|
||||
VOID OsMntContainerDestroy(struct Container *container);
|
||||
|
||||
UINT32 OsGetMntContainerID(MntContainer *mntContainer);
|
||||
|
||||
UINT32 OsGetMntContainerCount(VOID);
|
||||
#endif
|
||||
#endif
|
||||
62
kernel/base/include/los_net_container_pri.h
Normal file
62
kernel/base/include/los_net_container_pri.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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_NET_CONTAINER_PRI_H
|
||||
#define _LOS_NET_CONTAINER_PRI_H
|
||||
#include <lwip/net_group.h>
|
||||
#include <lwip/netif.h>
|
||||
#include <lwip/ip.h>
|
||||
#include "los_atomic.h"
|
||||
|
||||
#ifdef LOSCFG_NET_CONTAINER
|
||||
typedef struct ProcessCB LosProcessCB;
|
||||
struct Container;
|
||||
|
||||
typedef struct NetContainer {
|
||||
Atomic rc;
|
||||
struct net_group *group;
|
||||
UINT32 containerID;
|
||||
} NetContainer;
|
||||
|
||||
UINT32 OsInitRootNetContainer(NetContainer **ipcContainer);
|
||||
|
||||
UINT32 OsCopyNetContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent);
|
||||
|
||||
UINT32 OsUnshareNetContainer(UINTPTR flags, LosProcessCB *curr, struct Container *newContainer);
|
||||
|
||||
UINT32 OsSetNsNetContainer(UINT32 flags, struct Container *container, struct Container *newContainer);
|
||||
|
||||
VOID OsNetContainerDestroy(struct Container *container);
|
||||
|
||||
UINT32 OsGetNetContainerID(NetContainer *ipcContainer);
|
||||
|
||||
UINT32 OsGetNetContainerCount(VOID);
|
||||
#endif
|
||||
#endif /* _LOS_NET_CONTAINER_PRI_H */
|
||||
111
kernel/base/include/los_pid_container_pri.h
Normal file
111
kernel/base/include/los_pid_container_pri.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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;
|
||||
struct Container;
|
||||
|
||||
typedef struct {
|
||||
UINT32 vid; /* Virtual ID */
|
||||
UINT32 vpid; /* Virtual parent ID */
|
||||
UINTPTR cb; /* Control block */
|
||||
LosProcessCB *realParent; /* process real parent */
|
||||
LOS_DL_LIST node;
|
||||
} ProcessVid;
|
||||
|
||||
#define PID_CONTAINER_LEVEL_LIMIT 3
|
||||
|
||||
typedef struct PidContainer {
|
||||
Atomic rc;
|
||||
Atomic level;
|
||||
Atomic lock;
|
||||
BOOL referenced;
|
||||
UINT32 containerID;
|
||||
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)
|
||||
|
||||
#define OS_PROCESS_PID_FOR_CONTAINER_CHECK(processCB) \
|
||||
(((processCB)->container->pidContainer != (processCB)->container->pidForChildContainer) && \
|
||||
((processCB)->container->pidForChildContainer->referenced == FALSE))
|
||||
|
||||
UINT32 OsAllocSpecifiedVpidUnsafe(UINT32 vpid, PidContainer *pidContainer,
|
||||
LosProcessCB *processCB, LosProcessCB *parent);
|
||||
|
||||
VOID OsPidContainerDestroyAllProcess(LosProcessCB *processCB);
|
||||
|
||||
VOID OsPidContainerDestroy(struct Container *container, LosProcessCB *processCB);
|
||||
|
||||
UINT32 OsCopyPidContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID);
|
||||
|
||||
UINT32 OsUnsharePidContainer(UINTPTR flags, LosProcessCB *curr, struct Container *newContainer);
|
||||
|
||||
UINT32 OsSetNsPidContainer(UINT32 flags, struct Container *container, struct Container *newContainer);
|
||||
|
||||
UINT32 OsInitRootPidContainer(PidContainer **pidContainer);
|
||||
|
||||
LosProcessCB *OsGetPCBFromVpid(UINT32 vpid);
|
||||
|
||||
LosTaskCB *OsGetTCBFromVtid(UINT32 vtid);
|
||||
|
||||
UINT32 OsGetVpidFromCurrContainer(const LosProcessCB *processCB);
|
||||
|
||||
UINT32 OsGetVpidFromRootContainer(const LosProcessCB *processCB);
|
||||
|
||||
UINT32 OsGetVtidFromCurrContainer(const LosTaskCB *taskCB);
|
||||
|
||||
VOID OsFreeVtid(LosTaskCB *taskCB);
|
||||
|
||||
UINT32 OsAllocVtid(LosTaskCB *taskCB, const LosProcessCB *processCB);
|
||||
|
||||
UINT32 OsGetPidContainerID(PidContainer *pidContainer);
|
||||
|
||||
BOOL OsPidContainerProcessParentIsRealParent(const LosProcessCB *processCB, const LosProcessCB *curr);
|
||||
|
||||
UINT32 OsGetPidContainerCount(VOID);
|
||||
#endif /* _LOS_PID_CONTAINER_PRI_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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,12 @@
|
||||
#include "vid_type.h"
|
||||
#endif
|
||||
#include "sys/resource.h"
|
||||
#ifdef LOSCFG_KERNEL_CONTAINER
|
||||
#include "los_container_pri.h"
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_PLIMITS
|
||||
#include "los_plimits.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
@@ -68,11 +75,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 +89,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 +133,36 @@ typedef struct ProcessCB {
|
||||
OsCpupBase *processCpup; /**< Process cpu usage */
|
||||
#endif
|
||||
struct rlimit *resourceLimit;
|
||||
#ifdef LOSCFG_KERNEL_CONTAINER
|
||||
Container *container;
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
struct Credentials *credentials;
|
||||
#endif
|
||||
#endif
|
||||
#ifdef LOSCFG_PROC_PROCESS_DIR
|
||||
struct ProcDirEntry *procDir;
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_PLIMITS
|
||||
ProcLimiterSet *plimits;
|
||||
LOS_DL_LIST plimitsList; /* plimit process list */
|
||||
PLimitsData limitStat;
|
||||
#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 +269,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 +312,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 +345,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 +380,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 +392,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 +414,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 +423,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 +446,26 @@ 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;
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 OsGetRootPid(const LosProcessCB *processCB)
|
||||
{
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
return OsGetVpidFromRootContainer(processCB);
|
||||
#else
|
||||
return processCB->processID;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* return immediately if no child has exited.
|
||||
*/
|
||||
@@ -460,6 +523,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 +537,22 @@ 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);
|
||||
extern ProcessGroup *OsCreateProcessGroup(LosProcessCB *processCB);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ typedef enum {
|
||||
* @ingroup los_queue
|
||||
* Queue information block structure
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct TagQueueCB {
|
||||
UINT8 *queueHandle; /**< Pointer to a queue handle */
|
||||
UINT16 queueState; /**< Queue state */
|
||||
UINT16 queueLen; /**< Queue length */
|
||||
@@ -108,6 +108,9 @@ typedef struct {
|
||||
* Queue information control block
|
||||
*/
|
||||
extern LosQueueCB *g_allQueue;
|
||||
#ifndef LOSCFG_IPC_CONTAINER
|
||||
#define IPC_ALL_QUEUE g_allQueue
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
@@ -137,7 +140,7 @@ extern LosQueueCB *g_allQueue;
|
||||
* Obtain a handle of the queue that has a specified ID.
|
||||
*
|
||||
*/
|
||||
#define GET_QUEUE_HANDLE(queueID) (((LosQueueCB *)g_allQueue) + GET_QUEUE_INDEX(queueID))
|
||||
#define GET_QUEUE_HANDLE(queueID) (((LosQueueCB *)IPC_ALL_QUEUE) + GET_QUEUE_INDEX(queueID))
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
@@ -196,6 +199,8 @@ extern VOID *OsQueueMailAlloc(UINT32 queueID, VOID *mailPool, UINT32 timeout);
|
||||
*/
|
||||
extern UINT32 OsQueueMailFree(UINT32 queueID, VOID *mailPool, VOID *mailMem);
|
||||
|
||||
extern LosQueueCB *OsAllQueueCBInit(LOS_DL_LIST *freeQueueList);
|
||||
|
||||
extern UINT32 OsQueueInit(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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,12 @@ typedef struct TagTaskCB {
|
||||
UINTPTR pc;
|
||||
UINTPTR fp;
|
||||
#endif
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
PidContainer *pidContainer;
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
BOOL cloneIpc;
|
||||
#endif
|
||||
} LosTaskCB;
|
||||
|
||||
STATIC INLINE BOOL OsTaskIsRunning(const LosTaskCB *taskCB)
|
||||
@@ -610,6 +619,10 @@ STATIC INLINE VOID SchedTaskUnfreeze(LosTaskCB *taskCB)
|
||||
g_taskScheduled &= ~(1U << (cpuid)); \
|
||||
} while (0);
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
|
||||
BOOL OsSchedLimitCheckTime(LosTaskCB *task);
|
||||
#endif
|
||||
|
||||
STATIC INLINE LosTaskCB *HPFRunqueueTopTaskGet(HPFRunqueue *rq)
|
||||
{
|
||||
LosTaskCB *newTask = NULL;
|
||||
@@ -625,6 +638,12 @@ STATIC INLINE LosTaskCB *HPFRunqueueTopTaskGet(HPFRunqueue *rq)
|
||||
while (bitmap) {
|
||||
UINT32 priority = CLZ(bitmap);
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(newTask, &queueList->priQueList[priority], LosTaskCB, pendList) {
|
||||
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
|
||||
if (!OsSchedLimitCheckTime(newTask)) {
|
||||
bitmap &= ~(1U << (OS_PRIORITY_QUEUE_NUM - priority - 1));
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
if (newTask->cpuAffiMask & (1U << cpuid)) {
|
||||
#endif
|
||||
@@ -660,7 +679,7 @@ VOID OsSchedTick(VOID);
|
||||
UINT32 OsSchedInit(VOID);
|
||||
VOID OsSchedStart(VOID);
|
||||
|
||||
VOID OsSchedRunqueueIdleInit(UINT32 idleTaskID);
|
||||
VOID OsSchedRunqueueIdleInit(LosTaskCB *idleTask);
|
||||
VOID OsSchedRunqueueInit(VOID);
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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:
|
||||
@@ -54,6 +54,7 @@ extern "C" {
|
||||
|
||||
/* scheduler lock */
|
||||
extern SPIN_LOCK_S g_taskSpin;
|
||||
#define SCHEDULER_HELD() LOS_SpinHeld(&g_taskSpin)
|
||||
#define SCHEDULER_LOCK(state) LOS_SpinLockSave(&g_taskSpin, &(state))
|
||||
#define SCHEDULER_UNLOCK(state) LOS_SpinUnlockRestore(&g_taskSpin, state)
|
||||
|
||||
@@ -192,7 +193,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 +261,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 +313,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 +322,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
|
||||
|
||||
70
kernel/base/include/los_time_container_pri.h
Normal file
70
kernel/base/include/los_time_container_pri.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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;
|
||||
struct Container;
|
||||
|
||||
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);
|
||||
|
||||
UINT32 OsUnshareTimeContainer(UINTPTR flags, LosProcessCB *curr, struct Container *newContainer);
|
||||
|
||||
UINT32 OsSetNsTimeContainer(UINT32 flags, struct Container *container, struct Container *newContainer);
|
||||
|
||||
VOID OsTimeContainerDestroy(struct Container *container);
|
||||
|
||||
UINT32 OsGetTimeContainerID(TimeContainer *timeContainer);
|
||||
|
||||
TimeContainer *OsGetCurrTimeContainer(VOID);
|
||||
|
||||
UINT32 OsGetTimeContainerMonotonic(LosProcessCB *processCB, struct timespec64 *offsets);
|
||||
|
||||
UINT32 OsSetTimeContainerMonotonic(LosProcessCB *processCB, struct timespec64 *offsets);
|
||||
|
||||
UINT32 OsGetTimeContainerCount(VOID);
|
||||
|
||||
#define CLOCK_MONOTONIC_TIME_BASE (OsGetCurrTimeContainer()->monotonic)
|
||||
|
||||
#endif
|
||||
#endif /* _LOS_TIME_CONTAINER_PRI_H */
|
||||
82
kernel/base/include/los_user_container_pri.h
Normal file
82
kernel/base/include/los_user_container_pri.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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_USER_CONTAINER_PRI_H
|
||||
#define _LOS_USER_CONTAINER_PRI_H
|
||||
|
||||
#include "los_atomic.h"
|
||||
#include "los_credentials_pri.h"
|
||||
|
||||
#define UID_GID_MAP_MAX_EXTENTS 5
|
||||
|
||||
#ifdef LOSCFG_USER_CONTAINER
|
||||
struct ProcFile;
|
||||
|
||||
typedef struct UidGidExtent {
|
||||
UINT32 first;
|
||||
UINT32 lowerFirst;
|
||||
UINT32 count;
|
||||
} UidGidExtent;
|
||||
|
||||
typedef struct UidGidMap {
|
||||
UINT32 extentCount;
|
||||
union {
|
||||
UidGidExtent extent[UID_GID_MAP_MAX_EXTENTS];
|
||||
};
|
||||
} UidGidMap;
|
||||
|
||||
typedef struct UserContainer {
|
||||
Atomic rc;
|
||||
INT32 level;
|
||||
UINT32 owner;
|
||||
UINT32 group;
|
||||
struct UserContainer *parent;
|
||||
UidGidMap uidMap;
|
||||
UidGidMap gidMap;
|
||||
UINT32 containerID;
|
||||
} UserContainer;
|
||||
|
||||
UINT32 OsCreateUserContainer(Credentials *newCredentials, UserContainer *parentUserContainer);
|
||||
|
||||
VOID FreeUserContainer(UserContainer *userContainer);
|
||||
|
||||
UINT32 OsFromKuidMunged(UserContainer *userContainer, UINT32 kuid);
|
||||
|
||||
UINT32 OsFromKgidMunged(UserContainer *userContainer, UINT32 kgid);
|
||||
|
||||
UINT32 OsMakeKuid(UserContainer *userContainer, UINT32 uid);
|
||||
|
||||
UINT32 OsMakeKgid(UserContainer *userContainer, UINT32 gid);
|
||||
|
||||
INT32 OsUserContainerMapWrite(struct ProcFile *fp, CHAR *buf, size_t count,
|
||||
INT32 capSetid, UidGidMap *map, UidGidMap *parentMap);
|
||||
|
||||
UINT32 OsGetUserContainerCount(VOID);
|
||||
#endif
|
||||
#endif
|
||||
65
kernel/base/include/los_uts_container_pri.h
Normal file
65
kernel/base/include/los_uts_container_pri.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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_UTS_CONTAINER_PRI_H
|
||||
#define _LOS_UTS_CONTAINER_PRI_H
|
||||
|
||||
#include "sys/utsname.h"
|
||||
#include "sched.h"
|
||||
#include "los_atomic.h"
|
||||
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
|
||||
typedef struct ProcessCB LosProcessCB;
|
||||
struct Container;
|
||||
|
||||
typedef struct UtsContainer {
|
||||
Atomic rc;
|
||||
UINT32 containerID;
|
||||
struct utsname utsName;
|
||||
} UtsContainer;
|
||||
|
||||
UINT32 OsInitRootUtsContainer(UtsContainer **utsContainer);
|
||||
|
||||
UINT32 OsCopyUtsContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent);
|
||||
|
||||
UINT32 OsUnshareUtsContainer(UINTPTR flags, LosProcessCB *curr, struct Container *newContainer);
|
||||
|
||||
UINT32 OsSetNsUtsContainer(UINT32 flags, struct Container *container, struct Container *newContainer);
|
||||
|
||||
VOID OsUtsContainerDestroy(struct Container *container);
|
||||
|
||||
struct utsname *OsGetCurrUtsName(VOID);
|
||||
|
||||
UINT32 OsGetUtsContainerID(UtsContainer *utsContainer);
|
||||
|
||||
UINT32 OsGetUtsContainerCount(VOID);
|
||||
#endif
|
||||
#endif /* _LOS_UTS_CONTAINER_PRI_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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:
|
||||
@@ -290,7 +290,7 @@ STATUS_T LOS_VmSpaceFree(LosVmSpace *space);
|
||||
STATUS_T LOS_VaddrToPaddrMmap(LosVmSpace *space, VADDR_T vaddr, PADDR_T paddr, size_t len, UINT32 flags);
|
||||
BOOL OsUserVmSpaceInit(LosVmSpace *vmSpace, VADDR_T *virtTtb);
|
||||
LosVmSpace *OsCreateUserVmSpace(VOID);
|
||||
STATUS_T LOS_VmSpaceClone(LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace);
|
||||
STATUS_T LOS_VmSpaceClone(UINT32 cloneFlags, LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace);
|
||||
LosMux *OsGVmSpaceMuxGet(VOID);
|
||||
STATUS_T OsUnMMap(LosVmSpace *space, VADDR_T addr, size_t size);
|
||||
STATUS_T OsVmSpaceRegionFree(LosVmSpace *space);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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:
|
||||
@@ -34,17 +34,36 @@
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "los_vm_map.h"
|
||||
|
||||
#include "los_process_pri.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* The upper limit size of total shared memory is default 16M */
|
||||
#define SHM_MAX_PAGES 4096
|
||||
#define SHM_MAX (SHM_MAX_PAGES * PAGE_SIZE)
|
||||
#define SHM_MIN 1
|
||||
#define SHM_MNI 192
|
||||
#define SHM_SEG 128
|
||||
#define SHM_ALL (SHM_MAX_PAGES)
|
||||
|
||||
struct shmIDSource {
|
||||
struct shmid_ds ds;
|
||||
UINT32 status;
|
||||
LOS_DL_LIST node;
|
||||
#ifdef LOSCFG_SHELL
|
||||
CHAR ownerName[OS_PCB_NAME_LEN];
|
||||
#endif
|
||||
};
|
||||
|
||||
VOID OsShmFork(LosVmSpace *space, LosVmMapRegion *oldRegion, LosVmMapRegion *newRegion);
|
||||
VOID OsShmRegionFree(LosVmSpace *space, LosVmMapRegion *region);
|
||||
BOOL OsIsShmRegion(LosVmMapRegion *region);
|
||||
|
||||
struct shmIDSource *OsShmCBInit(LosMux *sysvShmMux, struct shminfo *shmInfo, UINT32 *shmUsedPageCount);
|
||||
VOID OsShmCBDestroy(struct shmIDSource *shmSegs, struct shminfo *shmInfo, LosMux *sysvShmMux);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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:
|
||||
@@ -37,14 +37,51 @@
|
||||
#include "los_mp.h"
|
||||
#include "los_percpu_pri.h"
|
||||
#include "los_hook.h"
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
#include "los_ipc_container_pri.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_BASE_IPC_QUEUE
|
||||
#if (LOSCFG_BASE_IPC_QUEUE_LIMIT <= 0)
|
||||
#error "queue maxnum cannot be zero"
|
||||
#endif /* LOSCFG_BASE_IPC_QUEUE_LIMIT <= 0 */
|
||||
|
||||
#ifndef LOSCFG_IPC_CONTAINER
|
||||
LITE_OS_SEC_BSS LosQueueCB *g_allQueue = NULL;
|
||||
LITE_OS_SEC_BSS STATIC LOS_DL_LIST g_freeQueueList;
|
||||
#define FREE_QUEUE_LIST g_freeQueueList
|
||||
#endif
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT LosQueueCB *OsAllQueueCBInit(LOS_DL_LIST *freeQueueList)
|
||||
{
|
||||
UINT32 index;
|
||||
|
||||
if (freeQueueList == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
UINT32 size = LOSCFG_BASE_IPC_QUEUE_LIMIT * sizeof(LosQueueCB);
|
||||
/* system resident memory, don't free */
|
||||
LosQueueCB *allQueue = (LosQueueCB *)LOS_MemAlloc(m_aucSysMem0, size);
|
||||
if (allQueue == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(allQueue, size, 0, size);
|
||||
LOS_ListInit(freeQueueList);
|
||||
for (index = 0; index < LOSCFG_BASE_IPC_QUEUE_LIMIT; index++) {
|
||||
LosQueueCB *queueNode = ((LosQueueCB *)allQueue) + index;
|
||||
queueNode->queueID = index;
|
||||
LOS_ListTailInsert(freeQueueList, &queueNode->readWriteList[OS_QUEUE_WRITE]);
|
||||
}
|
||||
|
||||
#ifndef LOSCFG_IPC_CONTAINER
|
||||
if (OsQueueDbgInitHook() != LOS_OK) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, allQueue);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
return allQueue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Description : queue initial
|
||||
@@ -52,27 +89,12 @@ LITE_OS_SEC_BSS STATIC LOS_DL_LIST g_freeQueueList;
|
||||
*/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsQueueInit(VOID)
|
||||
{
|
||||
LosQueueCB *queueNode = NULL;
|
||||
UINT32 index;
|
||||
UINT32 size;
|
||||
|
||||
size = LOSCFG_BASE_IPC_QUEUE_LIMIT * sizeof(LosQueueCB);
|
||||
/* system resident memory, don't free */
|
||||
g_allQueue = (LosQueueCB *)LOS_MemAlloc(m_aucSysMem0, size);
|
||||
#ifndef LOSCFG_IPC_CONTAINER
|
||||
g_allQueue = OsAllQueueCBInit(&g_freeQueueList);
|
||||
if (g_allQueue == NULL) {
|
||||
return LOS_ERRNO_QUEUE_NO_MEMORY;
|
||||
}
|
||||
(VOID)memset_s(g_allQueue, size, 0, size);
|
||||
LOS_ListInit(&g_freeQueueList);
|
||||
for (index = 0; index < LOSCFG_BASE_IPC_QUEUE_LIMIT; index++) {
|
||||
queueNode = ((LosQueueCB *)g_allQueue) + index;
|
||||
queueNode->queueID = index;
|
||||
LOS_ListTailInsert(&g_freeQueueList, &queueNode->readWriteList[OS_QUEUE_WRITE]);
|
||||
}
|
||||
|
||||
if (OsQueueDbgInitHook() != LOS_OK) {
|
||||
return LOS_ERRNO_QUEUE_NO_MEMORY;
|
||||
}
|
||||
#endif
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
@@ -111,14 +133,14 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreate(CHAR *queueName, UINT16 len, UINT32
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (LOS_ListEmpty(&g_freeQueueList)) {
|
||||
if (LOS_ListEmpty(&FREE_QUEUE_LIST)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
OsQueueCheckHook();
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, queue);
|
||||
return LOS_ERRNO_QUEUE_CB_UNAVAILABLE;
|
||||
}
|
||||
|
||||
unusedQueue = LOS_DL_LIST_FIRST(&g_freeQueueList);
|
||||
unusedQueue = LOS_DL_LIST_FIRST(&FREE_QUEUE_LIST);
|
||||
LOS_ListDelete(unusedQueue);
|
||||
queueCB = GET_QUEUE_LIST(unusedQueue);
|
||||
queueCB->queueLen = len;
|
||||
@@ -433,7 +455,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueDelete(UINT32 queueID)
|
||||
queueCB->queueID = SET_QUEUE_ID(GET_QUEUE_COUNT(queueCB->queueID) + 1, GET_QUEUE_INDEX(queueCB->queueID));
|
||||
OsQueueDbgUpdateHook(queueCB->queueID, NULL);
|
||||
|
||||
LOS_ListTailInsert(&g_freeQueueList, &queueCB->readWriteList[OS_QUEUE_WRITE]);
|
||||
LOS_ListTailInsert(&FREE_QUEUE_LIST, &queueCB->readWriteList[OS_QUEUE_WRITE]);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
OsHookCall(LOS_HOOK_TYPE_QUEUE_DELETE, queueCB);
|
||||
ret = LOS_MemFree(m_aucSysMem1, (VOID *)queue);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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 */
|
||||
|
||||
@@ -837,6 +837,9 @@ STATIC UINT32 OsMemPoolInit(VOID *pool, UINT32 size)
|
||||
struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)pool;
|
||||
struct OsMemNodeHead *newNode = NULL;
|
||||
struct OsMemNodeHead *endNode = NULL;
|
||||
|
||||
(VOID)memset_s(poolHead, sizeof(struct OsMemPoolHead), 0, sizeof(struct OsMemPoolHead));
|
||||
|
||||
#ifdef LOSCFG_KERNEL_LMS
|
||||
UINT32 resize = 0;
|
||||
if (g_lms != NULL) {
|
||||
@@ -848,7 +851,6 @@ STATIC UINT32 OsMemPoolInit(VOID *pool, UINT32 size)
|
||||
size = (resize == 0) ? size : resize;
|
||||
}
|
||||
#endif
|
||||
(VOID)memset(poolHead, 0, sizeof(struct OsMemPoolHead));
|
||||
|
||||
LOS_SpinInit(&poolHead->spinlock);
|
||||
poolHead->info.pool = pool;
|
||||
@@ -885,9 +887,14 @@ STATIC UINT32 OsMemPoolInit(VOID *pool, UINT32 size)
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_MEM_MUL_POOL
|
||||
STATIC VOID OsMemPoolDeinit(VOID *pool)
|
||||
STATIC VOID OsMemPoolDeinit(const VOID *pool, UINT32 size)
|
||||
{
|
||||
(VOID)memset(pool, 0, sizeof(struct OsMemPoolHead));
|
||||
#ifdef LOSCFG_KERNEL_LMS
|
||||
if (g_lms != NULL) {
|
||||
g_lms->deInit(pool);
|
||||
}
|
||||
#endif
|
||||
(VOID)memset_s(pool, size, 0, sizeof(struct OsMemPoolHead));
|
||||
}
|
||||
|
||||
STATIC UINT32 OsMemPoolAdd(VOID *pool, UINT32 size)
|
||||
@@ -961,7 +968,7 @@ UINT32 LOS_MemInit(VOID *pool, UINT32 size)
|
||||
|
||||
#ifdef LOSCFG_MEM_MUL_POOL
|
||||
if (OsMemPoolAdd(pool, size)) {
|
||||
(VOID)OsMemPoolDeinit(pool);
|
||||
(VOID)OsMemPoolDeInit(pool, size);
|
||||
return OS_ERROR;
|
||||
}
|
||||
#endif
|
||||
@@ -973,17 +980,21 @@ UINT32 LOS_MemInit(VOID *pool, UINT32 size)
|
||||
#ifdef LOSCFG_MEM_MUL_POOL
|
||||
UINT32 LOS_MemDeInit(VOID *pool)
|
||||
{
|
||||
if (pool == NULL) {
|
||||
struct OsMemPoolHead *tmpPool = (struct OsMemPoolHead *)pool;
|
||||
|
||||
if ((tmpPool == NULL) ||
|
||||
(tmpPool->info.pool != pool) ||
|
||||
(tmpPool->info.totalSize <= OS_MEM_MIN_POOL_SIZE)) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
if (OsMemPoolDelete(pool)) {
|
||||
if (OsMemPoolDelete(tmpPool)) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
OsMemPoolDeinit(pool);
|
||||
OsMemPoolDeInit(tmpPool, tmpPool->info.totalSize);
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_MEM_DEINIT, pool);
|
||||
OsHookCall(LOS_HOOK_TYPE_MEM_DEINIT, tmpPool);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
@@ -1896,7 +1907,7 @@ UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_POOL_STATUS *poolStatus)
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
(VOID)memset(poolStatus, 0, sizeof(LOS_MEM_POOL_STATUS));
|
||||
(VOID)memset_s(poolStatus, sizeof(LOS_MEM_POOL_STATUS), 0, sizeof(LOS_MEM_POOL_STATUS));
|
||||
|
||||
struct OsMemNodeHead *tmpNode = NULL;
|
||||
struct OsMemNodeHead *endNode = NULL;
|
||||
@@ -2070,5 +2081,3 @@ BOOL OsMemIsHeapNode(const VOID *ptr)
|
||||
#endif
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,6 +35,9 @@
|
||||
#include "los_queue_pri.h"
|
||||
#include "los_swtmr_pri.h"
|
||||
#include "los_task_pri.h"
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
#include "los_ipc_container_pri.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_SHELL
|
||||
#include "shcmd.h"
|
||||
@@ -88,7 +91,7 @@ UINT32 OsShellCmdQueueCntGet(VOID)
|
||||
LosQueueCB *queueCB = NULL;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
queueCB = g_allQueue;
|
||||
queueCB = IPC_ALL_QUEUE;
|
||||
for (loop = 0; loop < LOSCFG_BASE_IPC_QUEUE_LIMIT; loop++, queueCB++) {
|
||||
if (queueCB->queueState == OS_QUEUE_INUSED) {
|
||||
queueCnt++;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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:
|
||||
@@ -47,36 +47,14 @@
|
||||
#include "los_excinfo_pri.h"
|
||||
#endif
|
||||
#include "los_process_pri.h"
|
||||
#include "los_vm_dump.h"
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
#include "fs/file.h"
|
||||
#endif
|
||||
#include "los_sched_pri.h"
|
||||
#include "los_swtmr_pri.h"
|
||||
#include "los_info_pri.h"
|
||||
|
||||
#define OS_PROCESS_MEM_INFO 0x2U
|
||||
#define OS_PROCESS_INFO_LEN (g_processMaxNum * (sizeof(LosProcessCB)))
|
||||
#define OS_PROCESS_GROUP_INFO_LEN (g_processMaxNum * sizeof(UINT32))
|
||||
#define OS_PROCESS_UID_INFO_LEN (g_processMaxNum * sizeof(UINT32))
|
||||
#define OS_PROCESS_MEM_ALL_INFO_LEN (g_processMaxNum * PROCESS_MEMINFO_LEN)
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
#define OS_PROCESS_CPUP_LEN (g_processMaxNum * sizeof(CPUP_INFO_S))
|
||||
#define OS_PROCESS_AND_TASK_CPUP_LEN ((g_processMaxNum + g_taskMaxNum) * sizeof(CPUP_INFO_S))
|
||||
#define OS_PROCESS_CPUP_ALLINFO_LEN (OS_PROCESS_AND_TASK_CPUP_LEN * 3)
|
||||
STATIC VOID TaskCpupInfoBaseGet(UINTPTR base, const CPUP_INFO_S **, const CPUP_INFO_S **, const CPUP_INFO_S **);
|
||||
STATIC VOID ProcessCpupInfoBaseGet(UINTPTR base, const CPUP_INFO_S **, const CPUP_INFO_S **, const CPUP_INFO_S **);
|
||||
#else
|
||||
#define OS_PROCESS_CPUP_ALLINFO_LEN 0
|
||||
#endif
|
||||
#define OS_PROCESS_ALL_INFO_LEN (g_processMaxNum * (sizeof(LosProcessCB) + sizeof(UINT32)) + \
|
||||
OS_PROCESS_CPUP_ALLINFO_LEN + OS_PROCESS_UID_INFO_LEN)
|
||||
|
||||
#define OS_INVALID_SEM_ID 0xFFFFFFFF
|
||||
#define OS_TASK_WATER_LINE_SIZE (g_taskMaxNum * sizeof(UINT32))
|
||||
#define OS_TASK_INFO_LEN (g_taskMaxNum * sizeof(LosTaskCB))
|
||||
#define OS_TASK_SCHED_INFO_LEN (g_taskMaxNum * sizeof(SchedParam))
|
||||
#define OS_TASK_ALL_INFO_LEN (g_taskMaxNum * (sizeof(LosTaskCB) + sizeof(UINT32) + sizeof(SchedParam)))
|
||||
|
||||
#undef SHOW
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
#if defined(LOSCFG_BLACKBOX) && defined(LOSCFG_SAVE_EXCINFO)
|
||||
@@ -96,9 +74,6 @@ STATIC VOID ProcessCpupInfoBaseGet(UINTPTR base, const CPUP_INFO_S **, const CPU
|
||||
#define SHOW(arg...) PRINTK(arg)
|
||||
#endif
|
||||
|
||||
#define VM_INDEX PROCESS_VM_INDEX
|
||||
#define SM_INDEX PROCESS_SM_INDEX
|
||||
#define PM_INDEX PROCESS_PM_INDEX
|
||||
#define CPUP_MULT LOS_CPUP_PRECISION_MULT
|
||||
|
||||
STATIC UINT8 *ConvertProcessModeToString(UINT16 mode)
|
||||
@@ -143,9 +118,11 @@ STATIC VOID ProcessInfoTitle(VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
SHOW("\r\n PID PPID PGID UID Mode Status Policy Priority MTID TTotal");
|
||||
if (flag & OS_PROCESS_INFO_ALL) {
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
SHOW(" VirtualMem ShareMem PhysicalMem");
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
SHOW(" CPUUSE CPUUSE10s CPUUSE1s");
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
@@ -157,157 +134,56 @@ STATIC VOID ProcessInfoTitle(VOID *seqBuf, UINT16 flag)
|
||||
SHOW(" PName\n");
|
||||
}
|
||||
|
||||
STATIC VOID AllProcessDataShow(const LosProcessCB *pcbArray, const SchedParam *param,
|
||||
UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
|
||||
STATIC VOID ProcessDataShow(const ProcessInfo *processInfo, VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
const INT32 *group = (const INT32 *)((UINTPTR)pcbArray + OS_PROCESS_INFO_LEN);
|
||||
const INT32 *user = (const INT32 *)((UINTPTR)group + OS_PROCESS_GROUP_INFO_LEN);
|
||||
const UINT32 *memArray = (const UINT32 *)((UINTPTR)pcbArray + OS_PROCESS_ALL_INFO_LEN);
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
const CPUP_INFO_S *cpupAll = NULL;
|
||||
const CPUP_INFO_S *cpup10s = NULL;
|
||||
const CPUP_INFO_S *cpup1s = NULL;
|
||||
ProcessCpupInfoBaseGet(cpupInfo, &cpupAll, &cpup10s, &cpup1s);
|
||||
#else
|
||||
(VOID)cpupInfo;
|
||||
#endif
|
||||
|
||||
for (UINT32 pid = 1; pid < g_processMaxNum; ++pid) {
|
||||
const LosProcessCB *processCB = pcbArray + pid;
|
||||
if (OsProcessIsUnused(processCB)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SHOW("%5u%6d%5d%6d%7s%8s%7s%9u%5u%7u", pid, (INT32)processCB->parentProcessID, group[pid], user[pid],
|
||||
ConvertProcessModeToString(processCB->processMode), ConvertProcessStatusToString(processCB->processStatus),
|
||||
ConvertSchedPolicyToString(LOS_SCHED_RR), param[processCB->threadGroupID].basePrio,
|
||||
processCB->threadGroupID, processCB->threadNumber);
|
||||
|
||||
if (flag & OS_PROCESS_INFO_ALL) {
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
const UINT32 *memUsage = &memArray[pid * PROCESS_VM_INDEX_MAX];
|
||||
SHOW("%#11x%#9x%#12x", memUsage[VM_INDEX], memUsage[SM_INDEX], memUsage[PM_INDEX]);
|
||||
}
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
SHOW("%4u.%-2u%7u.%-2u%6u.%-2u ", cpupAll[pid].usage / CPUP_MULT, cpupAll[pid].usage % CPUP_MULT,
|
||||
cpup10s[pid].usage / CPUP_MULT, cpup10s[pid].usage % CPUP_MULT,
|
||||
cpup1s[pid].usage / CPUP_MULT, cpup1s[pid].usage % CPUP_MULT);
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
} else {
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
SHOW("%7u.%-2u ", cpup10s[pid].usage / CPUP_MULT, cpup10s[pid].usage % CPUP_MULT);
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
}
|
||||
SHOW("%-32s\n", processCB->processName);
|
||||
}
|
||||
}
|
||||
SHOW("%5u%6u%5d%6d%7s%8s%7s%9u%5u%7u", processInfo->pid, processInfo->ppid, processInfo->pgroupID,
|
||||
processInfo->userID, ConvertProcessModeToString(processInfo->mode),
|
||||
ConvertProcessStatusToString(processInfo->status),
|
||||
ConvertSchedPolicyToString(processInfo->policy), processInfo->basePrio,
|
||||
processInfo->threadGroupID, processInfo->threadNumber);
|
||||
|
||||
if (flag & OS_PROCESS_INFO_ALL) {
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
STATIC VOID ProcessMemUsageGet(LosProcessCB *pcbArray)
|
||||
{
|
||||
UINT32 intSave, memUsed;
|
||||
UINT32 *memArray = (UINT32 *)((UINTPTR)pcbArray + OS_PROCESS_ALL_INFO_LEN);
|
||||
|
||||
for (UINT32 pid = 0; pid < g_processMaxNum; ++pid) {
|
||||
const LosProcessCB *processCB = g_processCBArray + pid;
|
||||
UINT32 *proMemUsage = &memArray[pid * PROCESS_VM_INDEX_MAX];
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (OsProcessIsUnused(processCB)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
pcbArray[pid].processStatus = OS_PROCESS_FLAG_UNUSED;
|
||||
continue;
|
||||
}
|
||||
|
||||
LosVmSpace *vmSpace = processCB->vmSpace;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
/* Process memory usage statistics, idle task defaults to 0 */
|
||||
if (pid == OsGetIdleProcessID()) {
|
||||
proMemUsage[VM_INDEX] = 0;
|
||||
proMemUsage[SM_INDEX] = 0;
|
||||
proMemUsage[PM_INDEX] = 0;
|
||||
} else if (vmSpace == LOS_GetKVmSpace()) {
|
||||
(VOID)OsShellCmdProcessPmUsage(vmSpace, &proMemUsage[SM_INDEX], &proMemUsage[PM_INDEX]);
|
||||
proMemUsage[VM_INDEX] = proMemUsage[PM_INDEX];
|
||||
} else {
|
||||
memUsed = OsShellCmdProcessVmUsage(vmSpace);
|
||||
if (memUsed == 0) {
|
||||
pcbArray[pid].processStatus = OS_PROCESS_FLAG_UNUSED;
|
||||
continue;
|
||||
}
|
||||
proMemUsage[VM_INDEX] = memUsed;
|
||||
memUsed = OsShellCmdProcessPmUsage(vmSpace, &proMemUsage[SM_INDEX], &proMemUsage[PM_INDEX]);
|
||||
if (memUsed == 0) {
|
||||
pcbArray[pid].processStatus = OS_PROCESS_FLAG_UNUSED;
|
||||
}
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
SHOW("%#11x%#9x%#12x", processInfo->virtualMem, processInfo->shareMem, processInfo->physicalMem);
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
SHOW("%4u.%-2u%7u.%-2u%6u.%-2u ",
|
||||
processInfo->cpupAllsUsage / CPUP_MULT, processInfo->cpupAllsUsage % CPUP_MULT,
|
||||
processInfo->cpup10sUsage / CPUP_MULT, processInfo->cpup10sUsage % CPUP_MULT,
|
||||
processInfo->cpup1sUsage / CPUP_MULT, processInfo->cpup1sUsage % CPUP_MULT);
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
} else {
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
SHOW("%7u.%-2u ", processInfo->cpup10sUsage / CPUP_MULT, processInfo->cpup10sUsage % CPUP_MULT);
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
}
|
||||
SHOW("%-32s\n", processInfo->name);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define OS_TASK_STATUS_MASK 0x00FF
|
||||
STATIC VOID ProcessInfoGet(LosProcessCB **pcbArray, LosTaskCB **tcbArray, SchedParam **schedParam)
|
||||
STATIC VOID AllProcessDataShow(const ProcessInfo *pcbArray, VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
INT32 *group = (INT32 *)((UINTPTR)*pcbArray + OS_PROCESS_INFO_LEN);
|
||||
INT32 *user = (INT32 *)((UINTPTR)group + OS_PROCESS_GROUP_INFO_LEN);
|
||||
SchedParam *param = (SchedParam *)((UINTPTR)*tcbArray + OS_TASK_INFO_LEN);
|
||||
*schedParam = param;
|
||||
|
||||
for (UINT32 tid = 0; tid < g_taskMaxNum; tid++) {
|
||||
const LosTaskCB *taskCB = *tcbArray + tid;
|
||||
if (OsTaskIsUnused(taskCB)) {
|
||||
for (UINT32 pid = 1; pid < g_processMaxNum; ++pid) {
|
||||
const ProcessInfo *processInfo = pcbArray + pid;
|
||||
if (processInfo->status & OS_PROCESS_FLAG_UNUSED) {
|
||||
continue;
|
||||
}
|
||||
|
||||
LosProcessCB *processCB = *pcbArray + taskCB->processID;
|
||||
if (!OsProcessIsDead(processCB) && !OsProcessIsInit(processCB)) {
|
||||
processCB->processStatus |= (taskCB->taskStatus & OS_TASK_STATUS_MASK);
|
||||
}
|
||||
taskCB->ops->schedParamGet(taskCB, ¶m[tid]);
|
||||
}
|
||||
|
||||
for (UINT32 pid = 0; pid < g_processMaxNum; ++pid) {
|
||||
const LosProcessCB *processCB = *pcbArray + pid;
|
||||
if (OsProcessIsUnused(processCB)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (processCB->group != NULL) {
|
||||
group[processCB->processID] = processCB->group->groupID;
|
||||
} else {
|
||||
group[processCB->processID] = -1;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_SECURITY_CAPABILITY
|
||||
if (processCB->user != NULL) {
|
||||
user[processCB->processID] = processCB->user->userID;
|
||||
} else {
|
||||
user[processCB->processID] = -1;
|
||||
}
|
||||
#else
|
||||
user[processCB->processID] = 0;
|
||||
#endif
|
||||
ProcessDataShow(processInfo, seqBuf, flag);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID ProcessInfoShow(const LosProcessCB *pcbArray, const SchedParam *param,
|
||||
UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
|
||||
STATIC VOID ProcessInfoShow(const ProcessInfo *pcbArray, VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
const CPUP_INFO_S *cpupAll = NULL;
|
||||
const CPUP_INFO_S *cpup10s = NULL;
|
||||
const CPUP_INFO_S *cpup1s = NULL;
|
||||
ProcessCpupInfoBaseGet(cpupInfo, &cpupAll, &cpup10s, &cpup1s);
|
||||
UINT32 pid = OsGetIdleProcessID();
|
||||
UINT32 sysUsage = LOS_CPUP_PRECISION - cpupAll[pid].usage;
|
||||
|
||||
UINT32 pid = OS_KERNEL_IDLE_PROCESS_ID;
|
||||
UINT32 sysUsage = LOS_CPUP_PRECISION - pcbArray[pid].cpup10sUsage;
|
||||
SHOW("\n allCpu(%%): %4u.%02u sys, %4u.%02u idle\n", sysUsage / CPUP_MULT, sysUsage % CPUP_MULT,
|
||||
cpupAll[pid].usage / CPUP_MULT, cpupAll[pid].usage % CPUP_MULT);
|
||||
pcbArray[pid].cpup10sUsage / CPUP_MULT, pcbArray[pid].cpup10sUsage % CPUP_MULT);
|
||||
#endif
|
||||
|
||||
ProcessInfoTitle(seqBuf, flag);
|
||||
AllProcessDataShow(pcbArray, param, cpupInfo, seqBuf, flag);
|
||||
AllProcessDataShow(pcbArray, seqBuf, flag);
|
||||
}
|
||||
|
||||
STATIC UINT8 *ConvertTaskStatusToString(UINT16 taskStatus)
|
||||
@@ -337,33 +213,13 @@ STATIC UINT8 *ConvertTaskStatusToString(UINT16 taskStatus)
|
||||
return (UINT8 *)"Invalid";
|
||||
}
|
||||
|
||||
STATIC VOID TaskWaterLineGet(UINTPTR waterLineBase, LosTaskCB *tcbArray)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 *taskWaterLine = (UINT32 *)waterLineBase;
|
||||
|
||||
for (UINT32 tid = 0; tid < g_taskMaxNum; ++tid) {
|
||||
const LosTaskCB *taskCB = g_taskCBArray + tid;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (OsTaskIsUnused(taskCB)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
tcbArray[tid].taskStatus = OS_TASK_STATUS_UNUSED;
|
||||
continue;
|
||||
}
|
||||
|
||||
(VOID)OsStackWaterLineGet((const UINTPTR *)((UINTPTR)taskCB->topOfStack + taskCB->stackSize),
|
||||
(const UINTPTR *)taskCB->topOfStack, &taskWaterLine[taskCB->taskID]);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_SHELL_CMD_DEBUG
|
||||
#define OS_PEND_REASON_MAX_LEN 20
|
||||
|
||||
STATIC CHAR *CheckTaskWaitFlag(const LosTaskCB *taskCB, UINTPTR *lockID)
|
||||
STATIC CHAR *CheckTaskWaitFlag(const TaskInfo *taskInfo, UINTPTR *lockID)
|
||||
{
|
||||
*lockID = taskCB->waitID;
|
||||
switch (taskCB->waitFlag) {
|
||||
*lockID = taskInfo->waitID;
|
||||
switch (taskInfo->waitFlag) {
|
||||
case OS_TASK_WAIT_PROCESS:
|
||||
return "Child";
|
||||
case OS_TASK_WAIT_GID:
|
||||
@@ -395,23 +251,23 @@ STATIC CHAR *CheckTaskWaitFlag(const LosTaskCB *taskCB, UINTPTR *lockID)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC VOID TaskPendingReasonInfoGet(const LosTaskCB *taskCB, CHAR *pendReason, UINT32 maxLen, UINTPTR *lockID)
|
||||
STATIC VOID TaskPendingReasonInfoGet(const TaskInfo *taskInfo, CHAR *pendReason, UINT32 maxLen, UINTPTR *lockID)
|
||||
{
|
||||
CHAR *reason = NULL;
|
||||
|
||||
if (!(taskCB->taskStatus & OS_TASK_STATUS_PENDING)) {
|
||||
reason = (CHAR *)ConvertTaskStatusToString(taskCB->taskStatus);
|
||||
if (!(taskInfo->status & OS_TASK_STATUS_PENDING)) {
|
||||
reason = (CHAR *)ConvertTaskStatusToString(taskInfo->status);
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
reason = CheckTaskWaitFlag(taskCB, lockID);
|
||||
reason = CheckTaskWaitFlag(taskInfo, lockID);
|
||||
if (reason == NULL) {
|
||||
reason = "Others";
|
||||
}
|
||||
|
||||
if (taskCB->taskMux != NULL) {
|
||||
*lockID = (UINTPTR)taskCB->taskMux;
|
||||
LosTaskCB *owner = ((LosMux *)taskCB->taskMux)->owner;
|
||||
if (taskInfo->taskMux != NULL) {
|
||||
*lockID = (UINTPTR)taskInfo->taskMux;
|
||||
LosTaskCB *owner = ((LosMux *)taskInfo->taskMux)->owner;
|
||||
if (owner != NULL) {
|
||||
if (snprintf_s(pendReason, maxLen, maxLen - 1, "Mutex-%u", owner->taskID) == EOK) {
|
||||
return;
|
||||
@@ -448,210 +304,133 @@ STATIC VOID TaskInfoTitle(VOID *seqBuf, UINT16 flag)
|
||||
SHOW(" TaskName\n");
|
||||
}
|
||||
|
||||
STATIC VOID AllTaskInfoDataShow(const LosTaskCB *allTaskArray, UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
|
||||
STATIC VOID TaskInfoDataShow(const TaskInfo *taskInfo, VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
const SchedParam *param = (const SchedParam *)((UINTPTR)allTaskArray + OS_TASK_INFO_LEN);
|
||||
const UINT32 *waterLine = (const UINT32 *)((UINTPTR)allTaskArray + OS_TASK_INFO_LEN + OS_TASK_SCHED_INFO_LEN);
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
const CPUP_INFO_S *cpupAll = NULL;
|
||||
const CPUP_INFO_S *cpup10s = NULL;
|
||||
const CPUP_INFO_S *cpup1s = NULL;
|
||||
TaskCpupInfoBaseGet(cpupInfo, &cpupAll, &cpup10s, &cpup1s);
|
||||
#else
|
||||
(VOID)cpupInfo;
|
||||
#endif
|
||||
for (UINT32 pid = 1; pid < g_processMaxNum; ++pid) {
|
||||
for (UINT32 tid = 0; tid < g_taskMaxNum; ++tid) {
|
||||
const LosTaskCB *taskCB = allTaskArray + tid;
|
||||
if (OsTaskIsUnused(taskCB) || (taskCB->processID != pid)) {
|
||||
continue;
|
||||
}
|
||||
#ifdef LOSCFG_SHELL_CMD_DEBUG
|
||||
UINTPTR lockID = 0;
|
||||
CHAR pendReason[OS_PEND_REASON_MAX_LEN] = { 0 };
|
||||
UINTPTR lockID = 0;
|
||||
CHAR pendReason[OS_PEND_REASON_MAX_LEN] = { 0 };
|
||||
#endif
|
||||
SHOW(" %4u%5u", tid, taskCB->processID);
|
||||
SHOW(" %4u%5u", taskInfo->tid, taskInfo->pid);
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
SHOW("%#5x%4d ", taskCB->cpuAffiMask, (INT16)(taskCB->currCpu));
|
||||
SHOW("%#5x%4d ", taskInfo->cpuAffiMask, (INT16)(taskInfo->currCpu));
|
||||
#endif
|
||||
SHOW("%9s%7s%9u%#10x%#10x", ConvertTaskStatusToString(taskCB->taskStatus),
|
||||
ConvertSchedPolicyToString(param[tid].policy), param[tid].priority, taskCB->stackSize, waterLine[tid]);
|
||||
if (flag & OS_PROCESS_INFO_ALL) {
|
||||
SHOW("%9s%7s%9u%#10x%#10x", ConvertTaskStatusToString(taskInfo->status),
|
||||
ConvertSchedPolicyToString(taskInfo->policy), taskInfo->priority, taskInfo->stackSize, taskInfo->waterLine);
|
||||
if (flag & OS_PROCESS_INFO_ALL) {
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
SHOW("%4u.%-2u%7u.%-2u%6u.%-2u ", cpupAll[tid].usage / CPUP_MULT, cpupAll[tid].usage % CPUP_MULT,
|
||||
cpup10s[tid].usage / CPUP_MULT, cpup10s[tid].usage % CPUP_MULT,
|
||||
cpup1s[tid].usage / CPUP_MULT, cpup1s[tid].usage % CPUP_MULT);
|
||||
SHOW("%4u.%-2u%7u.%-2u%6u.%-2u ", taskInfo->cpupAllsUsage / CPUP_MULT, taskInfo->cpupAllsUsage % CPUP_MULT,
|
||||
taskInfo->cpup10sUsage / CPUP_MULT, taskInfo->cpup10sUsage % CPUP_MULT,
|
||||
taskInfo->cpup1sUsage / CPUP_MULT, taskInfo->cpup1sUsage % CPUP_MULT);
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
#ifdef LOSCFG_SHELL_CMD_DEBUG
|
||||
TaskPendingReasonInfoGet(taskCB, pendReason, OS_PEND_REASON_MAX_LEN, &lockID);
|
||||
SHOW("%#12x%#12x%11s%#11x", taskCB->stackPointer, taskCB->topOfStack, pendReason, lockID);
|
||||
TaskPendingReasonInfoGet(taskInfo, pendReason, OS_PEND_REASON_MAX_LEN, &lockID);
|
||||
SHOW("%#12x%#12x%11s%#11x", taskInfo->stackPoint, taskInfo->topOfStack, pendReason, lockID);
|
||||
#endif
|
||||
} else {
|
||||
} else {
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
SHOW("%8u.%-2u ", cpup10s[tid].usage / CPUP_MULT, cpup10s[tid].usage % CPUP_MULT);
|
||||
SHOW("%8u.%-2u ", taskInfo->cpup10sUsage / CPUP_MULT, taskInfo->cpup10sUsage % CPUP_MULT);
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
}
|
||||
SHOW(" %-32s\n", taskCB->taskName);
|
||||
}
|
||||
}
|
||||
SHOW(" %-32s\n", taskInfo->name);
|
||||
}
|
||||
|
||||
STATIC VOID ProcessTaskInfoDataShow(const ProcessThreadInfo *allTaskInfo, VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
for (UINT32 index = 0; index < allTaskInfo->threadCount; index++) {
|
||||
const TaskInfo *taskInfo = &allTaskInfo->taskInfo[index];
|
||||
TaskInfoDataShow(taskInfo, seqBuf, flag);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID TaskInfoData(const LosTaskCB *allTaskArray, UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
|
||||
STATIC VOID TaskInfoData(const ProcessThreadInfo *allTaskInfo, VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
ProcessInfoTitle(seqBuf, flag);
|
||||
ProcessDataShow(&allTaskInfo->processInfo, seqBuf, flag);
|
||||
TaskInfoTitle(seqBuf, flag);
|
||||
AllTaskInfoDataShow(allTaskArray, cpupInfo, seqBuf, flag);
|
||||
ProcessTaskInfoDataShow(allTaskInfo, seqBuf, flag);
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
STATIC VOID TaskCpupInfoBaseGet(UINTPTR base, const CPUP_INFO_S **cpupAll,
|
||||
const CPUP_INFO_S **cpup10s, const CPUP_INFO_S **cpup1s)
|
||||
{
|
||||
UINTPTR processCpupAll = base + OS_PROCESS_UID_INFO_LEN;
|
||||
*cpupAll = (CPUP_INFO_S *)(processCpupAll + OS_PROCESS_CPUP_LEN);
|
||||
UINTPTR processCpup10s = processCpupAll + OS_PROCESS_AND_TASK_CPUP_LEN;
|
||||
*cpup10s = (CPUP_INFO_S *)(processCpup10s + OS_PROCESS_CPUP_LEN);
|
||||
UINTPTR processCpup1s = processCpup10s + OS_PROCESS_AND_TASK_CPUP_LEN;
|
||||
*cpup1s = (CPUP_INFO_S *)(processCpup1s + OS_PROCESS_CPUP_LEN);
|
||||
}
|
||||
|
||||
STATIC VOID ProcessCpupInfoBaseGet(UINTPTR base, const CPUP_INFO_S **cpupAll,
|
||||
const CPUP_INFO_S **cpup10s, const CPUP_INFO_S **cpup1s)
|
||||
{
|
||||
*cpupAll = (CPUP_INFO_S *)(base + OS_PROCESS_UID_INFO_LEN);
|
||||
*cpup10s = (CPUP_INFO_S *)((UINTPTR)*cpupAll + OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
*cpup1s = (CPUP_INFO_S *)((UINTPTR)*cpup10s + OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
}
|
||||
|
||||
STATIC VOID TaskCpupInfoGet(UINTPTR base)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
CPUP_INFO_S *processCpupAll = (CPUP_INFO_S *)(base + OS_PROCESS_UID_INFO_LEN);
|
||||
CPUP_INFO_S *processCpup10s = (CPUP_INFO_S *)((UINTPTR)processCpupAll + OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
CPUP_INFO_S *processCpup1s = (CPUP_INFO_S *)((UINTPTR)processCpup10s + OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
(VOID)OsGetAllProcessAndTaskCpuUsageUnsafe(CPUP_ALL_TIME, processCpupAll, OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
(VOID)OsGetAllProcessAndTaskCpuUsageUnsafe(CPUP_LAST_TEN_SECONDS, processCpup10s, OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
(VOID)OsGetAllProcessAndTaskCpuUsageUnsafe(CPUP_LAST_ONE_SECONDS, processCpup1s, OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* | pcb | group | user | task and process cpup | process mem | tcb | sched param | task water line |
|
||||
*/
|
||||
STATIC VOID ProcessAndTaskInfoGet(LosProcessCB **pcbArray, LosTaskCB **tcbArray,
|
||||
SchedParam **schedParam, UINTPTR *cpupInfo, UINT16 flag)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 processInfoLen = OS_PROCESS_ALL_INFO_LEN;
|
||||
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
processInfoLen += OS_PROCESS_MEM_ALL_INFO_LEN;
|
||||
}
|
||||
#endif
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
(VOID)memcpy_s(*pcbArray, OS_PROCESS_INFO_LEN, g_processCBArray, OS_PROCESS_INFO_LEN);
|
||||
*tcbArray = (LosTaskCB *)((UINTPTR)*pcbArray + processInfoLen);
|
||||
(VOID)memcpy_s(*tcbArray, OS_TASK_INFO_LEN, g_taskCBArray, OS_TASK_INFO_LEN);
|
||||
|
||||
ProcessInfoGet(pcbArray, tcbArray, schedParam);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
*cpupInfo = (UINTPTR)*pcbArray + OS_PROCESS_INFO_LEN + OS_PROCESS_GROUP_INFO_LEN;
|
||||
TaskCpupInfoGet(*cpupInfo);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
ProcessMemUsageGet(*pcbArray);
|
||||
}
|
||||
#endif
|
||||
|
||||
TaskWaterLineGet((UINTPTR)*tcbArray + OS_TASK_INFO_LEN + OS_TASK_SCHED_INFO_LEN, *tcbArray);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 taskID, VOID *seqBuf, UINT16 flag)
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 processID, VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
UINT32 size;
|
||||
LosProcessCB *pcbArray = NULL;
|
||||
LosTaskCB *tcbArray = NULL;
|
||||
SchedParam *schedParam = NULL;
|
||||
UINTPTR cpupInfo = 0;
|
||||
|
||||
if (taskID == OS_ALL_TASK_MASK) {
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
size = OS_PROCESS_ALL_INFO_LEN + OS_PROCESS_MEM_ALL_INFO_LEN + OS_TASK_ALL_INFO_LEN;
|
||||
} else {
|
||||
size = OS_PROCESS_ALL_INFO_LEN + OS_TASK_ALL_INFO_LEN;
|
||||
}
|
||||
pcbArray = (LosProcessCB *)LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (processID == OS_ALL_TASK_MASK) {
|
||||
size = sizeof(ProcessInfo) * g_processMaxNum;
|
||||
ProcessInfo *pcbArray = (ProcessInfo *)LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (pcbArray == NULL) {
|
||||
PRINT_ERR("Memory is not enough to save task info!\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
(VOID)memset_s(pcbArray, size, 0, size);
|
||||
ProcessAndTaskInfoGet(&pcbArray, &tcbArray, &schedParam, &cpupInfo, flag);
|
||||
ProcessInfoShow(pcbArray, schedParam, cpupInfo, seqBuf, flag);
|
||||
TaskInfoData(tcbArray, cpupInfo, seqBuf, flag);
|
||||
|
||||
OsGetAllProcessInfo(pcbArray);
|
||||
ProcessInfoShow((const ProcessInfo *)pcbArray, seqBuf, flag);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pcbArray);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
ProcessThreadInfo *threadInfo = (ProcessThreadInfo *)LOS_MemAlloc(m_aucSysMem1, sizeof(ProcessThreadInfo));
|
||||
if (threadInfo == NULL) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
(VOID)memset_s(threadInfo, sizeof(ProcessThreadInfo), 0, sizeof(ProcessThreadInfo));
|
||||
|
||||
if (OsGetProcessThreadInfo(processID, threadInfo) != LOS_OK) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
TaskInfoData(threadInfo, seqBuf, flag);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, threadInfo);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdDumpTask(INT32 argc, const CHAR **argv)
|
||||
{
|
||||
INT32 processID = OS_ALL_TASK_MASK;
|
||||
UINT32 flag = 0;
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
flag |= OS_PROCESS_MEM_INFO;
|
||||
#endif
|
||||
|
||||
if (argc >= 2) { /* 2: The task shell name restricts the parameters */
|
||||
if (argc == 0) {
|
||||
return OsShellCmdTskInfoGet((UINT32)processID, NULL, flag);
|
||||
}
|
||||
|
||||
if (argc >= 3) { /* 3: The task shell name restricts the parameters */
|
||||
goto TASK_HELP;
|
||||
}
|
||||
|
||||
if (argc == 1) {
|
||||
if (strcmp("-a", argv[0]) == 0) {
|
||||
flag |= OS_PROCESS_INFO_ALL;
|
||||
if ((argc == 1) && (strcmp("-a", argv[0]) == 0)) {
|
||||
flag |= OS_PROCESS_INFO_ALL;
|
||||
} else if ((argc == 2) && (strcmp("-p", argv[0]) == 0)) { /* 2: Two parameters */
|
||||
flag |= OS_PROCESS_INFO_ALL;
|
||||
processID = atoi(argv[1]);
|
||||
#ifdef LOSCFG_SCHED_DEBUG
|
||||
#ifdef LOSCFG_SCHED_TICK_DEBUG
|
||||
} else if (strcmp("-i", argv[0]) == 0) {
|
||||
if (!OsShellShowTickResponse()) {
|
||||
return LOS_OK;
|
||||
}
|
||||
goto TASK_HELP;
|
||||
#endif
|
||||
} else if (strcmp("-t", argv[0]) == 0) {
|
||||
if (!OsShellShowSchedStatistics()) {
|
||||
return LOS_OK;
|
||||
}
|
||||
goto TASK_HELP;
|
||||
#endif
|
||||
} else {
|
||||
goto TASK_HELP;
|
||||
} else if (strcmp("-i", argv[0]) == 0) {
|
||||
if (!OsShellShowTickResponse()) {
|
||||
return LOS_OK;
|
||||
}
|
||||
goto TASK_HELP;
|
||||
#endif
|
||||
} else if (strcmp("-t", argv[0]) == 0) {
|
||||
if (!OsShellShowSchedStatistics()) {
|
||||
return LOS_OK;
|
||||
}
|
||||
goto TASK_HELP;
|
||||
#endif
|
||||
} else {
|
||||
goto TASK_HELP;
|
||||
}
|
||||
|
||||
return OsShellCmdTskInfoGet(OS_ALL_TASK_MASK, NULL, flag);
|
||||
return OsShellCmdTskInfoGet((UINT32)processID, NULL, flag);
|
||||
|
||||
TASK_HELP:
|
||||
PRINTK("Unknown option: %s\n", argv[0]);
|
||||
PRINTK("Usage:\n");
|
||||
PRINTK(" task --- Basic information about all created processes.\n");
|
||||
PRINTK(" task -a --- Complete information about all created processes.\n");
|
||||
PRINTK(" task --- Basic information about all created processes.\n");
|
||||
PRINTK(" task -a --- Complete information about all created processes.\n");
|
||||
PRINTK(" task -p [pid] --- Complete information about specifies processes and its task.\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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:
|
||||
@@ -98,6 +98,9 @@ STATIC VOID HPFTimeSliceUpdate(SchedRunqueue *rq, LosTaskCB *taskCB, UINT64 curr
|
||||
taskCB->schedStat.timeSliceRealTime += incTime;
|
||||
#endif
|
||||
}
|
||||
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
|
||||
OsSchedLimitUpdateRuntime(taskCB, currTime, incTime);
|
||||
#endif
|
||||
taskCB->irqUsedTime = 0;
|
||||
taskCB->startTime = currTime;
|
||||
if (taskCB->timeSlice <= OS_TIME_SLICE_MIN) {
|
||||
@@ -340,7 +343,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) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
@@ -359,6 +359,12 @@ STATUS_T OsVmPageFaultHandler(VADDR_T vaddr, UINT32 flags, ExcContext *frame)
|
||||
return LOS_ERRNO_VM_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_PLIMITS
|
||||
if (OsMemLimitCheckAndMemAdd(PAGE_SIZE) != LOS_OK) {
|
||||
return LOS_ERRNO_VM_NO_MEMORY;
|
||||
}
|
||||
#endif
|
||||
|
||||
(VOID)LOS_MuxAcquire(&space->regionMux);
|
||||
region = LOS_RegionFind(space, vaddr);
|
||||
if (region == NULL) {
|
||||
@@ -450,6 +456,9 @@ VMM_MAP_FAILED:
|
||||
}
|
||||
CHECK_FAILED:
|
||||
OsFaultTryFixup(frame, excVaddr, &status);
|
||||
#ifdef LOSCFG_KERNEL_PLIMITS
|
||||
OsMemLimitMemFree(PAGE_SIZE);
|
||||
#endif
|
||||
DONE:
|
||||
(VOID)LOS_MuxRelease(&space->regionMux);
|
||||
return status;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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:
|
||||
@@ -241,20 +241,15 @@ STATIC BOOL OsVmSpaceParamCheck(const LosVmSpace *vmSpace)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
STATUS_T LOS_VmSpaceClone(LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace)
|
||||
STATUS_T LOS_VmSpaceClone(UINT32 cloneFlags, LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace)
|
||||
{
|
||||
LosVmMapRegion *oldRegion = NULL;
|
||||
LosVmMapRegion *newRegion = NULL;
|
||||
LosRbNode *pstRbNode = NULL;
|
||||
LosRbNode *pstRbNodeNext = NULL;
|
||||
STATUS_T ret = LOS_OK;
|
||||
UINT32 numPages;
|
||||
PADDR_T paddr;
|
||||
VADDR_T vaddr;
|
||||
UINT32 intSave;
|
||||
LosVmPage *page = NULL;
|
||||
UINT32 flags;
|
||||
UINT32 i;
|
||||
UINT32 flags, i, intSave, numPages;
|
||||
|
||||
if ((OsVmSpaceParamCheck(oldVmSpace) == FALSE) || (OsVmSpaceParamCheck(newVmSpace) == FALSE)) {
|
||||
return LOS_ERRNO_VM_INVALID_ARGS;
|
||||
@@ -270,8 +265,13 @@ STATUS_T LOS_VmSpaceClone(LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace)
|
||||
newVmSpace->heapNow = oldVmSpace->heapNow;
|
||||
(VOID)LOS_MuxAcquire(&oldVmSpace->regionMux);
|
||||
RB_SCAN_SAFE(&oldVmSpace->regionRbTree, pstRbNode, pstRbNodeNext)
|
||||
oldRegion = (LosVmMapRegion *)pstRbNode;
|
||||
newRegion = OsVmRegionDup(newVmSpace, oldRegion, oldRegion->range.base, oldRegion->range.size);
|
||||
LosVmMapRegion *oldRegion = (LosVmMapRegion *)pstRbNode;
|
||||
#if defined(LOSCFG_KERNEL_SHM) && defined(LOSCFG_IPC_CONTAINER)
|
||||
if ((oldRegion->regionFlags & VM_MAP_REGION_FLAG_SHM) && (cloneFlags & CLONE_NEWIPC)) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
LosVmMapRegion *newRegion = OsVmRegionDup(newVmSpace, oldRegion, oldRegion->range.base, oldRegion->range.size);
|
||||
if (newRegion == NULL) {
|
||||
VM_ERR("dup new region failed");
|
||||
ret = LOS_ERRNO_VM_NO_MEMORY;
|
||||
|
||||
@@ -34,7 +34,9 @@
|
||||
#include "los_vm_phys.h"
|
||||
#include "los_vm_boot.h"
|
||||
#include "los_vm_filemap.h"
|
||||
|
||||
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
|
||||
#include "los_plimits.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
|
||||
@@ -81,7 +83,8 @@ VOID OsVmPageStartup(VOID)
|
||||
* struct LosVmPage occupied, which satisfies the equation:
|
||||
* nPage * sizeof(LosVmPage) + nPage * PAGE_SIZE = OsVmPhysPageNumGet() * PAGE_SIZE.
|
||||
*/
|
||||
nPage = OsVmPhysPageNumGet() * PAGE_SIZE / (sizeof(LosVmPage) + PAGE_SIZE);
|
||||
UINT32 pageNum = OsVmPhysPageNumGet();
|
||||
nPage = pageNum * PAGE_SIZE / (sizeof(LosVmPage) + PAGE_SIZE);
|
||||
g_vmPageArraySize = nPage * sizeof(LosVmPage);
|
||||
g_vmPageArray = (LosVmPage *)OsVmBootMemAlloc(g_vmPageArraySize);
|
||||
|
||||
@@ -89,6 +92,9 @@ VOID OsVmPageStartup(VOID)
|
||||
|
||||
OsVmPhysSegAdd();
|
||||
OsVmPhysInit();
|
||||
#ifdef LOSCFG_KERNEL_PLIMITS
|
||||
OsMemLimitSetLimit(pageNum * PAGE_SIZE);
|
||||
#endif
|
||||
|
||||
for (segID = 0; segID < g_vmPhysSegNum; segID++) {
|
||||
seg = &g_vmPhysSeg[segID];
|
||||
|
||||
@@ -456,6 +456,9 @@ VOID LOS_PhysPagesFreeContiguous(VOID *ptr, size_t nPages)
|
||||
OsVmPhysPagesFreeContiguous(page, nPages);
|
||||
|
||||
LOS_SpinUnlockRestore(&seg->freeListLock, intSave);
|
||||
#ifdef LOSCFG_KERNEL_PLIMITS
|
||||
OsMemLimitMemFree(nPages * PAGE_SIZE);
|
||||
#endif
|
||||
}
|
||||
|
||||
PADDR_T OsKVaddrToPaddr(VADDR_T kvaddr)
|
||||
@@ -503,6 +506,9 @@ VOID LOS_PhysPageFree(LosVmPage *page)
|
||||
|
||||
LOS_SpinUnlockRestore(&seg->freeListLock, intSave);
|
||||
}
|
||||
#ifdef LOSCFG_KERNEL_PLIMITS
|
||||
OsMemLimitMemFree(PAGE_SIZE);
|
||||
#endif
|
||||
}
|
||||
|
||||
LosVmPage *LOS_PhysPageAlloc(VOID)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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,7 +33,6 @@
|
||||
#include "string.h"
|
||||
#include "time.h"
|
||||
#include "sys/types.h"
|
||||
#include "sys/shm.h"
|
||||
#include "sys/stat.h"
|
||||
#include "los_config.h"
|
||||
#include "los_init.h"
|
||||
@@ -46,6 +45,8 @@
|
||||
#include "los_process.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "user_copy.h"
|
||||
#include "los_vm_shm_pri.h"
|
||||
#include "sys/shm.h"
|
||||
#ifdef LOSCFG_SHELL
|
||||
#include "shcmd.h"
|
||||
#include "shell.h"
|
||||
@@ -54,20 +55,6 @@
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SHM
|
||||
|
||||
STATIC LosMux g_sysvShmMux;
|
||||
|
||||
/* private macro */
|
||||
#define SYSV_SHM_LOCK() (VOID)LOS_MuxLock(&g_sysvShmMux, LOS_WAIT_FOREVER)
|
||||
#define SYSV_SHM_UNLOCK() (VOID)LOS_MuxUnlock(&g_sysvShmMux)
|
||||
|
||||
/* The upper limit size of total shared memory is default 16M */
|
||||
#define SHM_MAX_PAGES 4096
|
||||
#define SHM_MAX (SHM_MAX_PAGES * PAGE_SIZE)
|
||||
#define SHM_MIN 1
|
||||
#define SHM_MNI 192
|
||||
#define SHM_SEG 128
|
||||
#define SHM_ALL (SHM_MAX_PAGES)
|
||||
|
||||
#define SHM_SEG_FREE 0x2000
|
||||
#define SHM_SEG_USED 0x4000
|
||||
#define SHM_SEG_REMOVE 0x8000
|
||||
@@ -91,57 +78,75 @@ STATIC LosMux g_sysvShmMux;
|
||||
#define SHM_GROUPE_TO_USER 3
|
||||
#define SHM_OTHER_TO_USER 6
|
||||
|
||||
struct shmIDSource {
|
||||
struct shmid_ds ds;
|
||||
UINT32 status;
|
||||
LOS_DL_LIST node;
|
||||
#ifdef LOSCFG_SHELL
|
||||
CHAR ownerName[OS_PCB_NAME_LEN];
|
||||
#endif
|
||||
};
|
||||
#ifndef LOSCFG_IPC_CONTAINER
|
||||
STATIC LosMux g_sysvShmMux;
|
||||
|
||||
/* private data */
|
||||
STATIC struct shminfo g_shmInfo = {
|
||||
.shmmax = SHM_MAX,
|
||||
.shmmin = SHM_MIN,
|
||||
.shmmni = SHM_MNI,
|
||||
.shmseg = SHM_SEG,
|
||||
.shmall = SHM_ALL,
|
||||
};
|
||||
|
||||
STATIC struct shminfo g_shmInfo;
|
||||
STATIC struct shmIDSource *g_shmSegs = NULL;
|
||||
STATIC UINT32 g_shmUsedPageCount;
|
||||
|
||||
UINT32 ShmInit(VOID)
|
||||
#define IPC_SHM_INFO g_shmInfo
|
||||
#define IPC_SHM_SYS_VSHM_MUTEX g_sysvShmMux
|
||||
#define IPC_SHM_SEGS g_shmSegs
|
||||
#define IPC_SHM_USED_PAGE_COUNT g_shmUsedPageCount
|
||||
#endif
|
||||
|
||||
/* private macro */
|
||||
#define SYSV_SHM_LOCK() (VOID)LOS_MuxLock(&IPC_SHM_SYS_VSHM_MUTEX, LOS_WAIT_FOREVER)
|
||||
#define SYSV_SHM_UNLOCK() (VOID)LOS_MuxUnlock(&IPC_SHM_SYS_VSHM_MUTEX)
|
||||
|
||||
struct shmIDSource *OsShmCBInit(LosMux *sysvShmMux, struct shminfo *shmInfo, UINT32 *shmUsedPageCount)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 i;
|
||||
|
||||
ret = LOS_MuxInit(&g_sysvShmMux, NULL);
|
||||
if ((sysvShmMux == NULL) || (shmInfo == NULL) || (shmUsedPageCount == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = LOS_MuxInit(sysvShmMux, NULL);
|
||||
if (ret != LOS_OK) {
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
g_shmSegs = LOS_MemAlloc((VOID *)OS_SYS_MEM_ADDR, sizeof(struct shmIDSource) * g_shmInfo.shmmni);
|
||||
if (g_shmSegs == NULL) {
|
||||
(VOID)LOS_MuxDestroy(&g_sysvShmMux);
|
||||
shmInfo->shmmax = SHM_MAX;
|
||||
shmInfo->shmmin = SHM_MIN;
|
||||
shmInfo->shmmni = SHM_MNI;
|
||||
shmInfo->shmseg = SHM_SEG;
|
||||
shmInfo->shmall = SHM_ALL;
|
||||
|
||||
struct shmIDSource *shmSegs = LOS_MemAlloc((VOID *)OS_SYS_MEM_ADDR, sizeof(struct shmIDSource) * shmInfo->shmmni);
|
||||
if (shmSegs == NULL) {
|
||||
(VOID)LOS_MuxDestroy(sysvShmMux);
|
||||
goto ERROR;
|
||||
}
|
||||
(VOID)memset_s(g_shmSegs, (sizeof(struct shmIDSource) * g_shmInfo.shmmni),
|
||||
0, (sizeof(struct shmIDSource) * g_shmInfo.shmmni));
|
||||
(VOID)memset_s(shmSegs, (sizeof(struct shmIDSource) * shmInfo->shmmni),
|
||||
0, (sizeof(struct shmIDSource) * shmInfo->shmmni));
|
||||
|
||||
for (i = 0; i < g_shmInfo.shmmni; i++) {
|
||||
g_shmSegs[i].status = SHM_SEG_FREE;
|
||||
g_shmSegs[i].ds.shm_perm.seq = i + 1;
|
||||
LOS_ListInit(&g_shmSegs[i].node);
|
||||
for (i = 0; i < shmInfo->shmmni; i++) {
|
||||
shmSegs[i].status = SHM_SEG_FREE;
|
||||
shmSegs[i].ds.shm_perm.seq = i + 1;
|
||||
LOS_ListInit(&shmSegs[i].node);
|
||||
}
|
||||
g_shmUsedPageCount = 0;
|
||||
*shmUsedPageCount = 0;
|
||||
|
||||
return LOS_OK;
|
||||
return shmSegs;
|
||||
|
||||
ERROR:
|
||||
VM_ERR("ShmInit fail\n");
|
||||
return LOS_NOK;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
UINT32 ShmInit(VOID)
|
||||
{
|
||||
#ifndef LOSCFG_IPC_CONTAINER
|
||||
g_shmSegs = OsShmCBInit(&IPC_SHM_SYS_VSHM_MUTEX, &IPC_SHM_INFO, &IPC_SHM_USED_PAGE_COUNT);
|
||||
if (g_shmSegs == NULL) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
#endif
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LOS_MODULE_INIT(ShmInit, LOS_INIT_LEVEL_VM_COMPLETE);
|
||||
@@ -150,10 +155,10 @@ UINT32 ShmDeinit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
(VOID)LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, g_shmSegs);
|
||||
g_shmSegs = NULL;
|
||||
(VOID)LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, IPC_SHM_SEGS);
|
||||
IPC_SHM_SEGS = NULL;
|
||||
|
||||
ret = LOS_MuxDestroy(&g_sysvShmMux);
|
||||
ret = LOS_MuxDestroy(&IPC_SHM_SYS_VSHM_MUTEX);
|
||||
if (ret != LOS_OK) {
|
||||
return -1;
|
||||
}
|
||||
@@ -188,43 +193,63 @@ STATIC VOID ShmPagesRefDec(struct shmIDSource *seg)
|
||||
}
|
||||
}
|
||||
|
||||
STATIC INT32 ShmAllocSeg(key_t key, size_t size, INT32 shmflg)
|
||||
STATIC INT32 ShmAllocSegCheck(key_t key, size_t *size, INT32 *segNum)
|
||||
{
|
||||
INT32 i;
|
||||
INT32 segNum = -1;
|
||||
struct shmIDSource *seg = NULL;
|
||||
size_t count;
|
||||
|
||||
if ((size == 0) || (size < g_shmInfo.shmmin) ||
|
||||
(size > g_shmInfo.shmmax)) {
|
||||
if ((*size == 0) || (*size < IPC_SHM_INFO.shmmin) ||
|
||||
(*size > IPC_SHM_INFO.shmmax)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
size = LOS_Align(size, PAGE_SIZE);
|
||||
if ((g_shmUsedPageCount + (size >> PAGE_SHIFT)) > g_shmInfo.shmall) {
|
||||
|
||||
*size = LOS_Align(*size, PAGE_SIZE);
|
||||
if ((IPC_SHM_USED_PAGE_COUNT + (*size >> PAGE_SHIFT)) > IPC_SHM_INFO.shmall) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
for (i = 0; i < g_shmInfo.shmmni; i++) {
|
||||
if (g_shmSegs[i].status & SHM_SEG_FREE) {
|
||||
g_shmSegs[i].status &= ~SHM_SEG_FREE;
|
||||
segNum = i;
|
||||
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
|
||||
if (OsIPCLimitShmAlloc(*size) != LOS_OK) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (i = 0; i < IPC_SHM_INFO.shmmni; i++) {
|
||||
if (IPC_SHM_SEGS[i].status & SHM_SEG_FREE) {
|
||||
IPC_SHM_SEGS[i].status &= ~SHM_SEG_FREE;
|
||||
*segNum = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (segNum < 0) {
|
||||
if (*segNum < 0) {
|
||||
return -ENOSPC;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
seg = &g_shmSegs[segNum];
|
||||
STATIC INT32 ShmAllocSeg(key_t key, size_t size, INT32 shmflg)
|
||||
{
|
||||
INT32 segNum = -1;
|
||||
struct shmIDSource *seg = NULL;
|
||||
size_t count;
|
||||
|
||||
INT32 ret = ShmAllocSegCheck(key, &size, &segNum);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
seg = &IPC_SHM_SEGS[segNum];
|
||||
count = LOS_PhysPagesAlloc(size >> PAGE_SHIFT, &seg->node);
|
||||
if (count != (size >> PAGE_SHIFT)) {
|
||||
(VOID)LOS_PhysPagesFree(&seg->node);
|
||||
seg->status = SHM_SEG_FREE;
|
||||
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
|
||||
OsIPCLimitShmFree(size);
|
||||
#endif
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ShmSetSharedFlag(seg);
|
||||
g_shmUsedPageCount += size >> PAGE_SHIFT;
|
||||
IPC_SHM_USED_PAGE_COUNT += size >> PAGE_SHIFT;
|
||||
|
||||
seg->status |= SHM_SEG_USED;
|
||||
seg->ds.shm_perm.mode = (UINT32)shmflg & ACCESSPERMS;
|
||||
@@ -247,7 +272,7 @@ STATIC INT32 ShmAllocSeg(key_t key, size_t size, INT32 shmflg)
|
||||
return segNum;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID ShmFreeSeg(struct shmIDSource *seg)
|
||||
STATIC INLINE VOID ShmFreeSeg(struct shmIDSource *seg, UINT32 *shmUsedPageCount)
|
||||
{
|
||||
UINT32 count;
|
||||
|
||||
@@ -257,7 +282,12 @@ STATIC INLINE VOID ShmFreeSeg(struct shmIDSource *seg)
|
||||
VM_ERR("free physical pages failed, count = %d, size = %d", count, seg->ds.shm_segsz >> PAGE_SHIFT);
|
||||
return;
|
||||
}
|
||||
g_shmUsedPageCount -= seg->ds.shm_segsz >> PAGE_SHIFT;
|
||||
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
|
||||
OsIPCLimitShmFree(seg->ds.shm_segsz);
|
||||
#endif
|
||||
if (shmUsedPageCount != NULL) {
|
||||
(*shmUsedPageCount) -= seg->ds.shm_segsz >> PAGE_SHIFT;
|
||||
}
|
||||
seg->status = SHM_SEG_FREE;
|
||||
LOS_ListInit(&seg->node);
|
||||
}
|
||||
@@ -267,8 +297,8 @@ STATIC INT32 ShmFindSegByKey(key_t key)
|
||||
INT32 i;
|
||||
struct shmIDSource *seg = NULL;
|
||||
|
||||
for (i = 0; i < g_shmInfo.shmmni; i++) {
|
||||
seg = &g_shmSegs[i];
|
||||
for (i = 0; i < IPC_SHM_INFO.shmmni; i++) {
|
||||
seg = &IPC_SHM_SEGS[i];
|
||||
if ((seg->status & SHM_SEG_USED) &&
|
||||
(seg->ds.shm_perm.key == key)) {
|
||||
return i;
|
||||
@@ -280,7 +310,7 @@ STATIC INT32 ShmFindSegByKey(key_t key)
|
||||
|
||||
STATIC INT32 ShmSegValidCheck(INT32 segNum, size_t size, INT32 shmFlg)
|
||||
{
|
||||
struct shmIDSource *seg = &g_shmSegs[segNum];
|
||||
struct shmIDSource *seg = &IPC_SHM_SEGS[segNum];
|
||||
|
||||
if (size > seg->ds.shm_segsz) {
|
||||
return -EINVAL;
|
||||
@@ -298,12 +328,12 @@ STATIC struct shmIDSource *ShmFindSeg(int shmid)
|
||||
{
|
||||
struct shmIDSource *seg = NULL;
|
||||
|
||||
if ((shmid < 0) || (shmid >= g_shmInfo.shmmni)) {
|
||||
if ((shmid < 0) || (shmid >= IPC_SHM_INFO.shmmni)) {
|
||||
set_errno(EINVAL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
seg = &g_shmSegs[shmid];
|
||||
seg = &IPC_SHM_SEGS[shmid];
|
||||
if ((seg->status & SHM_SEG_FREE) || ((seg->ds.shm_nattch == 0) && (seg->status & SHM_SEG_REMOVE))) {
|
||||
set_errno(EIDRM);
|
||||
return NULL;
|
||||
@@ -364,7 +394,7 @@ VOID OsShmRegionFree(LosVmSpace *space, LosVmMapRegion *region)
|
||||
ShmPagesRefDec(seg);
|
||||
seg->ds.shm_nattch--;
|
||||
if (seg->ds.shm_nattch <= 0 && (seg->status & SHM_SEG_REMOVE)) {
|
||||
ShmFreeSeg(seg);
|
||||
ShmFreeSeg(seg, &IPC_SHM_USED_PAGE_COUNT);
|
||||
} else {
|
||||
seg->ds.shm_dtime = time(NULL);
|
||||
seg->ds.shm_lpid = LOS_GetCurrProcessID(); /* may not be the space's PID. */
|
||||
@@ -383,8 +413,8 @@ STATIC INT32 ShmSegUsedCount(VOID)
|
||||
INT32 count = 0;
|
||||
struct shmIDSource *seg = NULL;
|
||||
|
||||
for (i = 0; i < g_shmInfo.shmmni; i++) {
|
||||
seg = &g_shmSegs[i];
|
||||
for (i = 0; i < IPC_SHM_INFO.shmmni; i++) {
|
||||
seg = &IPC_SHM_SEGS[i];
|
||||
if (seg->status & SHM_SEG_USED) {
|
||||
count++;
|
||||
}
|
||||
@@ -672,16 +702,16 @@ INT32 ShmCtl(INT32 shmid, INT32 cmd, struct shmid_ds *buf)
|
||||
|
||||
seg->status |= SHM_SEG_REMOVE;
|
||||
if (seg->ds.shm_nattch <= 0) {
|
||||
ShmFreeSeg(seg);
|
||||
ShmFreeSeg(seg, &IPC_SHM_USED_PAGE_COUNT);
|
||||
}
|
||||
break;
|
||||
case IPC_INFO:
|
||||
ret = LOS_ArchCopyToUser(buf, &g_shmInfo, sizeof(struct shminfo));
|
||||
ret = LOS_ArchCopyToUser(buf, &IPC_SHM_INFO, sizeof(struct shminfo));
|
||||
if (ret != 0) {
|
||||
ret = EFAULT;
|
||||
goto ERROR;
|
||||
}
|
||||
ret = g_shmInfo.shmmni;
|
||||
ret = IPC_SHM_INFO.shmmni;
|
||||
break;
|
||||
case SHM_INFO:
|
||||
shmInfo.shm_rss = 0;
|
||||
@@ -695,7 +725,7 @@ INT32 ShmCtl(INT32 shmid, INT32 cmd, struct shmid_ds *buf)
|
||||
ret = EFAULT;
|
||||
goto ERROR;
|
||||
}
|
||||
ret = g_shmInfo.shmmni;
|
||||
ret = IPC_SHM_INFO.shmmni;
|
||||
break;
|
||||
default:
|
||||
VM_ERR("the cmd(%d) is not supported!", cmd);
|
||||
@@ -758,7 +788,7 @@ INT32 ShmDt(const VOID *shmaddr)
|
||||
seg->ds.shm_nattch--;
|
||||
if ((seg->ds.shm_nattch <= 0) &&
|
||||
(seg->status & SHM_SEG_REMOVE)) {
|
||||
ShmFreeSeg(seg);
|
||||
ShmFreeSeg(seg, &IPC_SHM_USED_PAGE_COUNT);
|
||||
} else {
|
||||
seg->ds.shm_dtime = time(NULL);
|
||||
seg->ds.shm_lpid = LOS_GetCurrProcessID();
|
||||
@@ -775,6 +805,27 @@ ERROR:
|
||||
return -1;
|
||||
}
|
||||
|
||||
VOID OsShmCBDestroy(struct shmIDSource *shmSegs, struct shminfo *shmInfo, LosMux *sysvShmMux)
|
||||
{
|
||||
if ((shmSegs == NULL) || (shmInfo == NULL) || (sysvShmMux == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (UINT32 index = 0; index < shmInfo->shmmni; index++) {
|
||||
struct shmIDSource *seg = &shmSegs[index];
|
||||
if (seg->status == SHM_SEG_FREE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
(VOID)LOS_MuxLock(sysvShmMux, LOS_WAIT_FOREVER);
|
||||
ShmFreeSeg(seg, NULL);
|
||||
(VOID)LOS_MuxUnlock(sysvShmMux);
|
||||
}
|
||||
|
||||
(VOID)LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, shmSegs);
|
||||
(VOID)LOS_MuxDestroy(sysvShmMux);
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_SHELL
|
||||
STATIC VOID OsShmInfoCmd(VOID)
|
||||
{
|
||||
@@ -784,8 +835,8 @@ STATIC VOID OsShmInfoCmd(VOID)
|
||||
PRINTK("\r\n------- Shared Memory Segments -------\n");
|
||||
PRINTK("key shmid perms bytes nattch status owner\n");
|
||||
SYSV_SHM_LOCK();
|
||||
for (i = 0; i < g_shmInfo.shmmni; i++) {
|
||||
seg = &g_shmSegs[i];
|
||||
for (i = 0; i < IPC_SHM_INFO.shmmni; i++) {
|
||||
seg = &IPC_SHM_SEGS[i];
|
||||
if (!(seg->status & SHM_SEG_USED)) {
|
||||
continue;
|
||||
}
|
||||
@@ -801,7 +852,7 @@ STATIC VOID OsShmDeleteCmd(INT32 shmid)
|
||||
{
|
||||
struct shmIDSource *seg = NULL;
|
||||
|
||||
if ((shmid < 0) || (shmid >= g_shmInfo.shmmni)) {
|
||||
if ((shmid < 0) || (shmid >= IPC_SHM_INFO.shmmni)) {
|
||||
PRINT_ERR("shmid is invalid: %d\n", shmid);
|
||||
return;
|
||||
}
|
||||
@@ -814,7 +865,7 @@ STATIC VOID OsShmDeleteCmd(INT32 shmid)
|
||||
}
|
||||
|
||||
if (seg->ds.shm_nattch <= 0) {
|
||||
ShmFreeSeg(seg);
|
||||
ShmFreeSeg(seg, &IPC_SHM_USED_PAGE_COUNT);
|
||||
}
|
||||
SYSV_SHM_UNLOCK();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -373,6 +373,7 @@ extern UINT32 __heap_end;
|
||||
*/
|
||||
#define _T(x) x
|
||||
#define KERNEL_NAME "Huawei LiteOS"
|
||||
#define KERNEL_NODE_NAME "hisilicon"
|
||||
#define KERNEL_SEP " "
|
||||
#define _V(v) _T(KERNEL_NAME)_T(KERNEL_SEP)_T(v)
|
||||
|
||||
@@ -388,6 +389,14 @@ extern UINT32 __heap_end;
|
||||
#define VERSION_NUM(a, b, c, d) (((a) << 24) | ((b) << 16) | (c) << 8 | (d))
|
||||
#define KERNEL_OPEN_VERSION_NUM VERSION_NUM(KERNEL_MAJOR, KERNEL_MINOR, KERNEL_PATCH, KERNEL_ITRE)
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* The container limit
|
||||
*/
|
||||
#ifndef LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT
|
||||
#define LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT 10
|
||||
#endif
|
||||
|
||||
/****************************** Exception information configuration ******************************/
|
||||
#ifdef LOSCFG_SAVE_EXCINFO
|
||||
/**
|
||||
|
||||
@@ -42,6 +42,7 @@ group("extended") {
|
||||
"lms",
|
||||
"perf",
|
||||
"pipes",
|
||||
"plimit",
|
||||
"power",
|
||||
"trace",
|
||||
"vdso",
|
||||
@@ -62,5 +63,6 @@ config("public") {
|
||||
"perf:public",
|
||||
"lms:public",
|
||||
"power:public",
|
||||
"plimit:public",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -76,6 +76,31 @@ config KERNEL_PIPE
|
||||
help
|
||||
Answer Y to enable LiteOS support pipes.
|
||||
|
||||
config KERNEL_PLIMITS
|
||||
bool "Enable plimits Feature"
|
||||
default n
|
||||
depends on KERNEL_EXTKERNEL
|
||||
|
||||
config KERNEL_MEM_PLIMIT
|
||||
bool "Enable mem limits Feature"
|
||||
default n
|
||||
depends on KERNEL_PLIMITS
|
||||
|
||||
config KERNEL_IPC_PLIMIT
|
||||
bool "Enable ipc limits Feature"
|
||||
default n
|
||||
depends on KERNEL_PLIMITS
|
||||
|
||||
config KERNEL_DEV_PLIMIT
|
||||
bool "Enable dev limits Feature"
|
||||
default n
|
||||
depends on KERNEL_PLIMITS
|
||||
|
||||
config KERNEL_SCHED_PLIMIT
|
||||
bool "Enable sched limits Feature"
|
||||
default n
|
||||
depends on KERNEL_PLIMITS
|
||||
|
||||
config BASE_CORE_HILOG
|
||||
bool "Enable Hilog"
|
||||
default y
|
||||
@@ -104,4 +129,4 @@ source "kernel/extended/perf/Kconfig"
|
||||
source "kernel/extended/lms/Kconfig"
|
||||
|
||||
######################### config options of hilog #########################
|
||||
source "kernel/extended/hilog/Kconfig"
|
||||
source "kernel/extended/hilog/Kconfig"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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 {
|
||||
|
||||
@@ -80,20 +80,25 @@ EXIT:
|
||||
STATIC LmsMemListNode *OsLmsGetPoolNodeFromAddr(UINTPTR addr)
|
||||
{
|
||||
LmsMemListNode *current = NULL;
|
||||
LmsMemListNode *previous = NULL;
|
||||
LOS_DL_LIST *listHead = &g_lmsCheckPoolList;
|
||||
|
||||
if (LOS_ListEmpty(&g_lmsCheckPoolList)) {
|
||||
goto EXIT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(current, listHead, LmsMemListNode, node) {
|
||||
if ((addr >= current->poolAddr) && (addr < current->poolAddr + current->poolSize)) {
|
||||
return current;
|
||||
if ((addr < current->poolAddr) || (addr >= (current->poolAddr + current->poolSize))) {
|
||||
continue;
|
||||
}
|
||||
if ((previous == NULL) ||
|
||||
((previous->poolAddr <= current->poolAddr) &&
|
||||
((current->poolAddr + current->poolSize) <= (previous->poolAddr + previous->poolSize)))) {
|
||||
previous = current;
|
||||
}
|
||||
}
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
return previous;
|
||||
}
|
||||
|
||||
STATIC LmsMemListNode *OsLmsCheckPoolCreate(VOID)
|
||||
@@ -123,18 +128,12 @@ UINT32 LOS_LmsCheckPoolAdd(const VOID *pool, UINT32 size)
|
||||
|
||||
LMS_LOCK(intSave);
|
||||
|
||||
lmsPoolNode = OsLmsGetPoolNodeFromAddr((UINTPTR)pool);
|
||||
if (lmsPoolNode != NULL) { /* if pool range already on checklist */
|
||||
if (lmsPoolNode->poolAddr != (UINTPTR)pool) { /* pool is a subset of lmsPoolNode->poolAddr */
|
||||
/* do not add it again, just return */
|
||||
PRINT_DEBUG("[LMS]pool %p already on lms checklist !\n", pool);
|
||||
LMS_UNLOCK(intSave);
|
||||
return size; /* return size indicate the shadow memory init successful */
|
||||
} else { /* Re-initialize the same pool, maybe with different size */
|
||||
/* delete the old node, then add a new one */
|
||||
lmsPoolNode->used = LMS_POOL_UNUSED;
|
||||
LOS_ListDelete(&(lmsPoolNode->node));
|
||||
}
|
||||
lmsPoolNode = OsLmsGetPoolNode(pool);
|
||||
if (lmsPoolNode != NULL) { /* if pool already on checklist */
|
||||
/* Re-initialize the same pool, maybe with different size */
|
||||
/* delete the old node, then add a new one */
|
||||
lmsPoolNode->used = LMS_POOL_UNUSED;
|
||||
LOS_ListDelete(&(lmsPoolNode->node));
|
||||
}
|
||||
|
||||
lmsPoolNode = OsLmsCheckPoolCreate();
|
||||
@@ -150,7 +149,8 @@ UINT32 LOS_LmsCheckPoolAdd(const VOID *pool, UINT32 size)
|
||||
lmsPoolNode->shadowStart = (UINTPTR)poolAddr + realSize;
|
||||
lmsPoolNode->shadowSize = poolAddr + size - lmsPoolNode->shadowStart;
|
||||
/* init shadow value */
|
||||
(VOID)memset((VOID *)lmsPoolNode->shadowStart, LMS_SHADOW_AFTERFREE_U8, lmsPoolNode->shadowSize);
|
||||
(VOID)memset_s((VOID *)lmsPoolNode->shadowStart, lmsPoolNode->shadowSize,
|
||||
LMS_SHADOW_AFTERFREE_U8, lmsPoolNode->shadowSize);
|
||||
|
||||
LOS_ListAdd(&g_lmsCheckPoolList, &(lmsPoolNode->node));
|
||||
|
||||
@@ -179,10 +179,11 @@ Release:
|
||||
|
||||
STATIC UINT32 OsLmsInit(VOID)
|
||||
{
|
||||
(VOID)memset(g_lmsCheckPoolArray, 0, sizeof(g_lmsCheckPoolArray));
|
||||
(VOID)memset_s(g_lmsCheckPoolArray, sizeof(g_lmsCheckPoolArray), 0, sizeof(g_lmsCheckPoolArray));
|
||||
LOS_ListInit(&g_lmsCheckPoolList);
|
||||
static LmsHook hook = {
|
||||
.init = LOS_LmsCheckPoolAdd,
|
||||
.deInit = LOS_LmsCheckPoolDel,
|
||||
.mallocMark = OsLmsLosMallocMark,
|
||||
.freeMark = OsLmsLosFreeMark,
|
||||
.simpleMark = OsLmsSimpleMark,
|
||||
@@ -595,7 +596,7 @@ VOID OsLmsReportError(UINTPTR p, UINT32 size, UINT32 errMod)
|
||||
|
||||
(VOID)LOS_AtomicAdd(&g_checkDepth, 1);
|
||||
LMS_LOCK(intSave);
|
||||
(VOID)memset(&info, 0, sizeof(LmsAddrInfo));
|
||||
(VOID)memset_s(&info, sizeof(LmsAddrInfo), 0, sizeof(LmsAddrInfo));
|
||||
|
||||
PRINT_ERR("***** Kernel Address Sanitizer Error Detected Start *****\n");
|
||||
|
||||
@@ -766,4 +767,4 @@ VOID __asan_handle_no_return(VOID)
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_MODULE_INIT(OsLmsInit, LOS_INIT_LEVEL_KMOD_PREVM);
|
||||
LOS_MODULE_INIT(OsLmsInit, LOS_INIT_LEVEL_KMOD_PREVM);
|
||||
|
||||
@@ -95,6 +95,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
UINT32 (*init)(const VOID *pool, UINT32 size);
|
||||
VOID (*deInit)(const VOID *pool);
|
||||
VOID (*mallocMark)(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
|
||||
VOID (*freeMark)(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
|
||||
VOID (*simpleMark)(UINTPTR startAddr, UINTPTR endAddr, UINT32 value);
|
||||
@@ -132,4 +133,4 @@ extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_handle_no_return(VOID);
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_LMS_PRI_H */
|
||||
#endif /* _LOS_LMS_PRI_H */
|
||||
|
||||
46
kernel/extended/plimit/BUILD.gn
Normal file
46
kernel/extended/plimit/BUILD.gn
Normal file
@@ -0,0 +1,46 @@
|
||||
# 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.
|
||||
|
||||
import("//kernel/liteos_a/liteos.gni")
|
||||
|
||||
module_switch = true
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
sources = [
|
||||
"los_devicelimit.c",
|
||||
"los_ipclimit.c",
|
||||
"los_memlimit.c",
|
||||
"los_plimits.c",
|
||||
"los_processlimit.c",
|
||||
"los_schedlimit.c",
|
||||
]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
}
|
||||
35
kernel/extended/plimit/Makefile
Normal file
35
kernel/extended/plimit/Makefile
Normal file
@@ -0,0 +1,35 @@
|
||||
# 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 $(LITEOSTOPDIR)/config.mk
|
||||
|
||||
MODULE_NAME := $(notdir $(shell pwd))
|
||||
|
||||
LOCAL_SRCS := $(wildcard *.c)
|
||||
|
||||
include $(MODULE)
|
||||
599
kernel/extended/plimit/los_devicelimit.c
Normal file
599
kernel/extended/plimit/los_devicelimit.c
Normal file
@@ -0,0 +1,599 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
|
||||
#include "los_seq_buf.h"
|
||||
#include "los_bitmap.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "los_devicelimit.h"
|
||||
|
||||
#define TYPE_CHAR_LEN (1)
|
||||
#define DEVICE_NAME_PREFIX_SPACE (1)
|
||||
#define DEVICE_ACCESS_MAXLEN (3)
|
||||
#define BUF_SEPARATOR (5)
|
||||
|
||||
STATIC ProcDevLimit *g_procDevLimit = NULL;
|
||||
|
||||
VOID OsDevLimitInit(UINTPTR limit)
|
||||
{
|
||||
ProcDevLimit *deviceLimit = (ProcDevLimit *)limit;
|
||||
deviceLimit->behavior = DEVLIMIT_DEFAULT_ALLOW;
|
||||
LOS_ListInit(&(deviceLimit->accessList));
|
||||
g_procDevLimit = deviceLimit;
|
||||
}
|
||||
|
||||
VOID *OsDevLimitAlloc(VOID)
|
||||
{
|
||||
ProcDevLimit *plimit = (ProcDevLimit *)LOS_MemAlloc(m_aucSysMem1, sizeof(ProcDevLimit));
|
||||
if (plimit == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(plimit, sizeof(ProcDevLimit), 0, sizeof(ProcDevLimit));
|
||||
LOS_ListInit(&(plimit->accessList));
|
||||
plimit->behavior = DEVLIMIT_DEFAULT_NONE;
|
||||
return (VOID *)plimit;
|
||||
}
|
||||
|
||||
STATIC VOID DevAccessListDelete(ProcDevLimit *devLimit)
|
||||
{
|
||||
DevAccessItem *delItem = NULL;
|
||||
DevAccessItem *tmpItem = NULL;
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(delItem, tmpItem, &devLimit->accessList, DevAccessItem, list) {
|
||||
LOS_ListDelete(&delItem->list);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, (VOID *)delItem);
|
||||
}
|
||||
}
|
||||
|
||||
VOID OsDevLimitFree(UINTPTR limit)
|
||||
{
|
||||
ProcDevLimit *devLimit = (ProcDevLimit *)limit;
|
||||
if (devLimit == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
DevAccessListDelete(devLimit);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, devLimit);
|
||||
}
|
||||
|
||||
STATIC UINT32 DevLimitCopyAccess(ProcDevLimit *devLimitDest, ProcDevLimit *devLimitSrc)
|
||||
{
|
||||
DevAccessItem *tmpItem = NULL;
|
||||
INT32 itemSize = sizeof(DevAccessItem);
|
||||
devLimitDest->behavior = devLimitSrc->behavior;
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(tmpItem, &devLimitSrc->accessList, DevAccessItem, list) {
|
||||
DevAccessItem *newItem = (DevAccessItem *)LOS_MemAlloc(m_aucSysMem1, itemSize);
|
||||
if (newItem == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
(VOID)memcpy_s(newItem, sizeof(DevAccessItem), tmpItem, sizeof(DevAccessItem));
|
||||
LOS_ListTailInsert(&devLimitDest->accessList, &newItem->list);
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsDevLimitCopy(UINTPTR dest, UINTPTR src)
|
||||
{
|
||||
ProcDevLimit *devLimitDest = (ProcDevLimit *)dest;
|
||||
ProcDevLimit *devLimitSrc = (ProcDevLimit *)src;
|
||||
(VOID)DevLimitCopyAccess(devLimitDest, devLimitSrc);
|
||||
devLimitDest->parent = (ProcDevLimit *)src;
|
||||
}
|
||||
|
||||
STATIC INLINE INT32 IsSpace(INT32 c)
|
||||
{
|
||||
return (c == ' ' || (unsigned)c - '\t' < BUF_SEPARATOR);
|
||||
}
|
||||
|
||||
STATIC UINT32 ParseItemAccess(const CHAR *buf, DevAccessItem *item)
|
||||
{
|
||||
switch (*buf) {
|
||||
case 'a':
|
||||
item->type = DEVLIMIT_DEV_ALL;
|
||||
return LOS_OK;
|
||||
case 'b':
|
||||
item->type = DEVLIMIT_DEV_BLOCK;
|
||||
break;
|
||||
case 'c':
|
||||
item->type = DEVLIMIT_DEV_CHAR;
|
||||
break;
|
||||
default:
|
||||
return EINVAL;
|
||||
}
|
||||
buf += DEVICE_NAME_PREFIX_SPACE;
|
||||
if (!IsSpace(*buf)) {
|
||||
return EINVAL;
|
||||
}
|
||||
buf += DEVICE_NAME_PREFIX_SPACE;
|
||||
|
||||
for (INT32 count = 0; count < sizeof(item->name) - 1; count++) {
|
||||
if (IsSpace(*buf)) {
|
||||
break;
|
||||
}
|
||||
item->name[count] = *buf;
|
||||
buf += TYPE_CHAR_LEN;
|
||||
}
|
||||
if (!IsSpace(*buf)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
buf += DEVICE_NAME_PREFIX_SPACE;
|
||||
for (INT32 i = 0; i < DEVICE_ACCESS_MAXLEN; i++) {
|
||||
switch (*buf) {
|
||||
case 'r':
|
||||
item->access |= DEVLIMIT_ACC_READ;
|
||||
break;
|
||||
case 'w':
|
||||
item->access |= DEVLIMIT_ACC_WRITE;
|
||||
break;
|
||||
case 'm':
|
||||
item->access |= DEVLIMIT_ACC_MKNOD;
|
||||
break;
|
||||
case '\n':
|
||||
case '\0':
|
||||
i = DEVICE_ACCESS_MAXLEN;
|
||||
break;
|
||||
default:
|
||||
return EINVAL;
|
||||
}
|
||||
buf += TYPE_CHAR_LEN;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC BOOL DevLimitMayAllowAll(ProcDevLimit *parent)
|
||||
{
|
||||
if (parent == NULL) {
|
||||
return TRUE;
|
||||
}
|
||||
return (parent->behavior == DEVLIMIT_DEFAULT_ALLOW);
|
||||
}
|
||||
|
||||
STATIC BOOL DevLimitHasChildren(ProcLimitSet *procLimitSet, ProcDevLimit *devLimit)
|
||||
{
|
||||
ProcLimitSet *parent = procLimitSet;
|
||||
ProcLimitSet *childProcLimitSet = NULL;
|
||||
if (devLimit == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(childProcLimitSet, &(procLimitSet->childList), ProcLimitSet, childList) {
|
||||
if (childProcLimitSet == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (childProcLimitSet->parent != parent) {
|
||||
continue;
|
||||
}
|
||||
if (!((childProcLimitSet->mask) & BIT(PROCESS_LIMITER_ID_DEV))) {
|
||||
continue;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
STATIC UINT32 DealItemAllAccess(ProcLimitSet *procLimitSet, ProcDevLimit *devLimit,
|
||||
ProcDevLimit *devParentLimit, INT32 filetype)
|
||||
{
|
||||
switch (filetype) {
|
||||
case DEVLIMIT_ALLOW: {
|
||||
if (DevLimitHasChildren(procLimitSet, devLimit)) {
|
||||
return EINVAL;
|
||||
}
|
||||
if (!DevLimitMayAllowAll(devParentLimit)) {
|
||||
return EPERM;
|
||||
}
|
||||
DevAccessListDelete(devLimit);
|
||||
devLimit->behavior = DEVLIMIT_DEFAULT_ALLOW;
|
||||
if (devParentLimit == NULL) {
|
||||
break;
|
||||
}
|
||||
DevLimitCopyAccess(devLimit, devParentLimit);
|
||||
break;
|
||||
}
|
||||
case DEVLIMIT_DENY: {
|
||||
if (DevLimitHasChildren(procLimitSet, devLimit)) {
|
||||
return EINVAL;
|
||||
}
|
||||
DevAccessListDelete(devLimit);
|
||||
devLimit->behavior = DEVLIMIT_DEFAULT_DENY;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return EINVAL;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC BOOL DevLimitMatchItemPartial(LOS_DL_LIST *list, DevAccessItem *item)
|
||||
{
|
||||
if ((list == NULL) || (item == NULL)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (LOS_ListEmpty(list)) {
|
||||
return FALSE;
|
||||
}
|
||||
DevAccessItem *walk = NULL;
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(walk, list, DevAccessItem, list) {
|
||||
if (item->type != walk->type) {
|
||||
continue;
|
||||
}
|
||||
if ((strcmp(walk->name, "*") != 0) && (strcmp(item->name, "*") != 0)
|
||||
&& (strcmp(walk->name, item->name) != 0)) {
|
||||
continue;
|
||||
}
|
||||
if (!(item->access & ~(walk->access))) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
STATIC BOOL DevLimitParentAllowsRmItem(ProcDevLimit *devParentLimit, DevAccessItem *item)
|
||||
{
|
||||
if (devParentLimit == NULL) {
|
||||
return TRUE;
|
||||
}
|
||||
/* Make sure you're not removing part or a whole item existing in the parent plimits */
|
||||
return !DevLimitMatchItemPartial(&devParentLimit->accessList, item);
|
||||
}
|
||||
|
||||
STATIC BOOL DevLimitMatchItem(LOS_DL_LIST *list, DevAccessItem *item)
|
||||
{
|
||||
if ((list == NULL) || (item == NULL)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (LOS_ListEmpty(list)) {
|
||||
return FALSE;
|
||||
}
|
||||
DevAccessItem *walk = NULL;
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(walk, list, DevAccessItem, list) {
|
||||
if (item->type != walk->type) {
|
||||
continue;
|
||||
}
|
||||
if ((strcmp(walk->name, "*") != 0) && (strcmp(walk->name, item->name) != 0)) {
|
||||
continue;
|
||||
}
|
||||
if (!(item->access & ~(walk->access))) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used to make sure a child plimits won't have more privileges than its parent
|
||||
*/
|
||||
STATIC BOOL DevLimitVerifyNewItem(ProcDevLimit *parent, DevAccessItem *item, INT32 currBehavior)
|
||||
{
|
||||
if (parent == NULL) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (parent->behavior == DEVLIMIT_DEFAULT_ALLOW) {
|
||||
if (currBehavior == DEVLIMIT_DEFAULT_ALLOW) {
|
||||
return TRUE;
|
||||
}
|
||||
return !DevLimitMatchItemPartial(&parent->accessList, item);
|
||||
}
|
||||
return DevLimitMatchItem(&parent->accessList, item);
|
||||
}
|
||||
|
||||
STATIC BOOL DevLimitParentAllowsAddItem(ProcDevLimit *devParentLimit, DevAccessItem *item, INT32 currBehavior)
|
||||
{
|
||||
return DevLimitVerifyNewItem(devParentLimit, item, currBehavior);
|
||||
}
|
||||
|
||||
STATIC VOID DevLimitAccessListRm(ProcDevLimit *devLimit, DevAccessItem *item)
|
||||
{
|
||||
if ((item == NULL) || (devLimit == NULL)) {
|
||||
return;
|
||||
}
|
||||
DevAccessItem *walk, *tmp = NULL;
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(walk, tmp, &devLimit->accessList, DevAccessItem, list) {
|
||||
if (walk->type != item->type) {
|
||||
continue;
|
||||
}
|
||||
if (strcmp(walk->name, item->name) != 0) {
|
||||
continue;
|
||||
}
|
||||
walk->access &= ~item->access;
|
||||
if (!walk->access) {
|
||||
LOS_ListDelete(&walk->list);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, (VOID *)walk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
STATIC UINT32 DevLimitAccessListAdd(ProcDevLimit *devLimit, DevAccessItem *item)
|
||||
{
|
||||
if ((item == NULL) || (devLimit == NULL)) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
DevAccessItem *walk = NULL;
|
||||
DevAccessItem *newItem = (DevAccessItem *)LOS_MemAlloc(m_aucSysMem1, sizeof(DevAccessItem));
|
||||
if (newItem == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
(VOID)memcpy_s(newItem, sizeof(DevAccessItem), item, sizeof(DevAccessItem));
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(walk, &devLimit->accessList, DevAccessItem, list) {
|
||||
if (walk->type != item->type) {
|
||||
continue;
|
||||
}
|
||||
if (strcmp(walk->name, item->name) != 0) {
|
||||
continue;
|
||||
}
|
||||
walk->access |= item->access;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, (VOID *)newItem);
|
||||
newItem = NULL;
|
||||
}
|
||||
|
||||
if (newItem != NULL) {
|
||||
LOS_ListTailInsert(&devLimit->accessList, &newItem->list);
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Revalidate permissions
|
||||
*/
|
||||
STATIC VOID DevLimitRevalidateActiveItems(ProcDevLimit *devLimit, ProcDevLimit *devParentLimit)
|
||||
{
|
||||
if ((devLimit == NULL) || (devParentLimit == NULL)) {
|
||||
return;
|
||||
}
|
||||
DevAccessItem *walK = NULL;
|
||||
DevAccessItem *tmp = NULL;
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(walK, tmp, &devLimit->accessList, DevAccessItem, list) {
|
||||
if (!DevLimitParentAllowsAddItem(devParentLimit, walK, devLimit->behavior)) {
|
||||
DevLimitAccessListRm(devLimit, walK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* propagates a new item to the children
|
||||
*/
|
||||
STATIC UINT32 DevLimitPropagateItem(ProcLimitSet *procLimitSet, ProcDevLimit *devLimit, DevAccessItem *item)
|
||||
{
|
||||
UINT32 ret = LOS_OK;
|
||||
ProcLimitSet *parent = procLimitSet;
|
||||
ProcLimitSet *childProcLimitSet = NULL;
|
||||
|
||||
if ((procLimitSet == NULL) || (item == NULL)) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
if (devLimit == NULL) {
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(childProcLimitSet, &procLimitSet->childList, ProcLimitSet, childList) {
|
||||
if (childProcLimitSet == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (childProcLimitSet->parent != parent) {
|
||||
continue;
|
||||
}
|
||||
if (!((childProcLimitSet->mask) & BIT(PROCESS_LIMITER_ID_DEV))) {
|
||||
continue;
|
||||
}
|
||||
ProcDevLimit *devLimitChild = (ProcDevLimit *)childProcLimitSet->limitsList[PROCESS_LIMITER_ID_DEV];
|
||||
if (devLimit->behavior == DEVLIMIT_DEFAULT_ALLOW &&
|
||||
devLimitChild->behavior == DEVLIMIT_DEFAULT_ALLOW) {
|
||||
ret = DevLimitAccessListAdd(devLimitChild, item);
|
||||
} else {
|
||||
DevLimitAccessListRm(devLimitChild, item);
|
||||
}
|
||||
DevLimitRevalidateActiveItems(devLimitChild, (ProcDevLimit *)parent->limitsList[PROCESS_LIMITER_ID_DEV]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
STATIC UINT32 DevLimitUpdateAccess(ProcLimitSet *procLimitSet, const CHAR *buf, INT32 filetype)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 intSave;
|
||||
DevAccessItem item = {0};
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
ProcDevLimit *devLimit = (ProcDevLimit *)(procLimitSet->limitsList[PROCESS_LIMITER_ID_DEV]);
|
||||
ProcDevLimit *devParentLimit = devLimit->parent;
|
||||
|
||||
ret = ParseItemAccess(buf, &item);
|
||||
if (ret != LOS_OK) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return ret;
|
||||
}
|
||||
if (item.type == DEVLIMIT_DEV_ALL) {
|
||||
ret = DealItemAllAccess(procLimitSet, devLimit, devParentLimit, filetype);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return ret;
|
||||
}
|
||||
switch (filetype) {
|
||||
case DEVLIMIT_ALLOW: {
|
||||
if (devLimit->behavior == DEVLIMIT_DEFAULT_ALLOW) {
|
||||
if (!DevLimitParentAllowsRmItem(devParentLimit, &item)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EPERM;
|
||||
}
|
||||
DevLimitAccessListRm(devLimit, &item);
|
||||
break;
|
||||
}
|
||||
if (!DevLimitParentAllowsAddItem(devParentLimit, &item, devLimit->behavior)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EPERM;
|
||||
}
|
||||
ret = DevLimitAccessListAdd(devLimit, &item);
|
||||
break;
|
||||
}
|
||||
case DEVLIMIT_DENY: {
|
||||
if (devLimit->behavior == DEVLIMIT_DEFAULT_DENY) {
|
||||
DevLimitAccessListRm(devLimit, &item);
|
||||
} else {
|
||||
ret = DevLimitAccessListAdd(devLimit, &item);
|
||||
}
|
||||
// update child access list
|
||||
ret = DevLimitPropagateItem(procLimitSet, devLimit, &item);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ret = EINVAL;
|
||||
break;
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
UINT32 OsDevLimitWriteAllow(ProcLimitSet *plimit, const CHAR *buf, UINT32 size)
|
||||
{
|
||||
(VOID)size;
|
||||
return DevLimitUpdateAccess(plimit, buf, DEVLIMIT_ALLOW);
|
||||
}
|
||||
|
||||
UINT32 OsDevLimitWriteDeny(ProcLimitSet *plimit, const CHAR *buf, UINT32 size)
|
||||
{
|
||||
(VOID)size;
|
||||
return DevLimitUpdateAccess(plimit, buf, DEVLIMIT_DENY);
|
||||
}
|
||||
|
||||
STATIC VOID DevLimitItemSetAccess(CHAR *acc, INT16 access)
|
||||
{
|
||||
INT32 index = 0;
|
||||
(VOID)memset_s(acc, ACCLEN, 0, ACCLEN);
|
||||
if (access & DEVLIMIT_ACC_READ) {
|
||||
acc[index++] = 'r';
|
||||
}
|
||||
if (access & DEVLIMIT_ACC_WRITE) {
|
||||
acc[index++] = 'w';
|
||||
}
|
||||
if (access & DEVLIMIT_ACC_MKNOD) {
|
||||
acc[index++] = 'm';
|
||||
}
|
||||
}
|
||||
|
||||
STATIC CHAR DevLimitItemTypeToChar(INT16 type)
|
||||
{
|
||||
if (type == DEVLIMIT_DEV_ALL) {
|
||||
return 'a';
|
||||
} else if (type == DEVLIMIT_DEV_CHAR) {
|
||||
return 'c';
|
||||
} else if (type == DEVLIMIT_DEV_BLOCK) {
|
||||
return 'b';
|
||||
}
|
||||
return 'X';
|
||||
}
|
||||
|
||||
UINT32 OsDevLimitShow(ProcDevLimit *devLimit, struct SeqBuf *seqBuf)
|
||||
{
|
||||
DevAccessItem *item = NULL;
|
||||
CHAR acc[ACCLEN];
|
||||
UINT32 intSave;
|
||||
|
||||
if ((devLimit == NULL) || (seqBuf == NULL)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (devLimit->behavior == DEVLIMIT_DEFAULT_ALLOW) {
|
||||
DevLimitItemSetAccess(acc, DEVLIMIT_ACC_MASK);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
LosBufPrintf(seqBuf, "%c %s %s\n", DevLimitItemTypeToChar(DEVLIMIT_DEV_ALL), "*", acc);
|
||||
return LOS_OK;
|
||||
}
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(item, &devLimit->accessList, DevAccessItem, list) {
|
||||
DevLimitItemSetAccess(acc, item->access);
|
||||
LosBufPrintf(seqBuf, "%c %s %s\n", DevLimitItemTypeToChar(item->type), item->name, acc);
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INLINE INT16 ConversionDevType(INT32 vnodeType)
|
||||
{
|
||||
INT16 type = 0;
|
||||
if (vnodeType == VNODE_TYPE_BLK) {
|
||||
type = DEVLIMIT_DEV_BLOCK;
|
||||
} else if (vnodeType == VNODE_TYPE_CHR) {
|
||||
type = DEVLIMIT_DEV_CHAR;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
STATIC INLINE INT16 ConversionDevAccess(INT32 flags)
|
||||
{
|
||||
INT16 access = 0;
|
||||
if ((flags & O_ACCMODE) == O_RDONLY) {
|
||||
access |= DEVLIMIT_ACC_READ;
|
||||
}
|
||||
if (flags & O_WRONLY) {
|
||||
access |= DEVLIMIT_ACC_WRITE;
|
||||
}
|
||||
if (flags & O_RDWR) {
|
||||
access |= DEVLIMIT_ACC_WRITE | DEVLIMIT_ACC_READ;
|
||||
}
|
||||
if (flags & O_CREAT) {
|
||||
access |= DEVLIMIT_ACC_MKNOD;
|
||||
}
|
||||
return access;
|
||||
}
|
||||
|
||||
UINT32 OsDevLimitCheckPermission(INT32 vnodeType, const CHAR *pathName, INT32 flags)
|
||||
{
|
||||
BOOL matched = FALSE;
|
||||
DevAccessItem item = {0};
|
||||
LosProcessCB *run = OsCurrProcessGet();
|
||||
if ((run == NULL) || (run->plimits == NULL)) {
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (pathName == NULL) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
ProcDevLimit *devLimit = (ProcDevLimit *)run->plimits->limitsList[PROCESS_LIMITER_ID_DEV];
|
||||
|
||||
item.type = ConversionDevType(vnodeType);
|
||||
item.access = ConversionDevAccess(flags);
|
||||
LOS_ListInit(&(item.list));
|
||||
(VOID)strncpy_s(item.name, PATH_MAX, pathName, PATH_MAX);
|
||||
|
||||
if (devLimit->behavior == DEVLIMIT_DEFAULT_ALLOW) {
|
||||
matched = !DevLimitMatchItemPartial(&devLimit->accessList, &item);
|
||||
} else {
|
||||
matched = DevLimitMatchItem(&devLimit->accessList, &item);
|
||||
}
|
||||
if (!matched) {
|
||||
return EPERM;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
96
kernel/extended/plimit/los_devicelimit.h
Normal file
96
kernel/extended/plimit/los_devicelimit.h
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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_DEVICELIMIT_H
|
||||
#define _LOS_DEVICELIMIT_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "los_list.h"
|
||||
#include "vfs_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define DEVLIMIT_ACC_MKNOD 1
|
||||
#define DEVLIMIT_ACC_READ 2
|
||||
#define DEVLIMIT_ACC_WRITE 4
|
||||
#define DEVLIMIT_ACC_MASK (DEVLIMIT_ACC_MKNOD | DEVLIMIT_ACC_READ | DEVLIMIT_ACC_WRITE)
|
||||
|
||||
#define DEVLIMIT_DEV_BLOCK 1
|
||||
#define DEVLIMIT_DEV_CHAR 2
|
||||
#define DEVLIMIT_DEV_ALL 4 /* all devices */
|
||||
|
||||
#define DEVLIMIT_ALLOW 1
|
||||
#define DEVLIMIT_DENY 2
|
||||
|
||||
#define ACCLEN 4
|
||||
|
||||
struct SeqBuf;
|
||||
typedef struct TagPLimiterSet ProcLimitSet;
|
||||
|
||||
enum DevLimitBehavior {
|
||||
DEVLIMIT_DEFAULT_NONE,
|
||||
DEVLIMIT_DEFAULT_ALLOW,
|
||||
DEVLIMIT_DEFAULT_DENY,
|
||||
};
|
||||
|
||||
typedef struct DevAccessItem {
|
||||
INT16 type;
|
||||
INT16 access;
|
||||
LOS_DL_LIST list;
|
||||
CHAR name[PATH_MAX];
|
||||
} DevAccessItem;
|
||||
|
||||
typedef struct ProcDevLimit {
|
||||
struct ProcDevLimit *parent;
|
||||
UINT8 allowFile;
|
||||
UINT8 denyFile;
|
||||
LOS_DL_LIST accessList; // device belong to devicelimite
|
||||
enum DevLimitBehavior behavior;
|
||||
} ProcDevLimit;
|
||||
|
||||
VOID OsDevLimitInit(UINTPTR limit);
|
||||
VOID *OsDevLimitAlloc(VOID);
|
||||
VOID OsDevLimitFree(UINTPTR limit);
|
||||
VOID OsDevLimitCopy(UINTPTR dest, UINTPTR src);
|
||||
UINT32 OsDevLimitWriteAllow(ProcLimitSet *plimit, const CHAR *buf, UINT32 size);
|
||||
UINT32 OsDevLimitWriteDeny(ProcLimitSet *plimit, const CHAR *buf, UINT32 size);
|
||||
UINT32 OsDevLimitShow(ProcDevLimit *devLimit, struct SeqBuf *seqBuf);
|
||||
UINT32 OsDevLimitCheckPermission(INT32 vnodeType, const CHAR *pathName, INT32 flags);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif /* _LOS_DEVICELIMIT_H */
|
||||
249
kernel/extended/plimit/los_ipclimit.c
Normal file
249
kernel/extended/plimit/los_ipclimit.c
Normal file
@@ -0,0 +1,249 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
|
||||
#include "los_ipclimit.h"
|
||||
#include "los_process_pri.h"
|
||||
|
||||
STATIC ProcIPCLimit *g_rootIPCLimit = NULL;
|
||||
#define PLIMIT_IPC_SHM_LIMIT_MAX 0xFFFFFFFF
|
||||
|
||||
VOID OsIPCLimitInit(UINTPTR limite)
|
||||
{
|
||||
ProcIPCLimit *plimite = (ProcIPCLimit *)limite;
|
||||
plimite->mqCountLimit = LOSCFG_BASE_IPC_QUEUE_LIMIT;
|
||||
plimite->shmSizeLimit = PLIMIT_IPC_SHM_LIMIT_MAX;
|
||||
g_rootIPCLimit = plimite;
|
||||
}
|
||||
|
||||
VOID *OsIPCLimitAlloc(VOID)
|
||||
{
|
||||
ProcIPCLimit *plimite = (ProcIPCLimit *)LOS_MemAlloc(m_aucSysMem1, sizeof(ProcIPCLimit));
|
||||
if (plimite == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(plimite, sizeof(ProcIPCLimit), 0, sizeof(ProcIPCLimit));
|
||||
return (VOID *)plimite;
|
||||
}
|
||||
|
||||
VOID OsIPCLimitFree(UINTPTR limite)
|
||||
{
|
||||
ProcIPCLimit *plimite = (ProcIPCLimit *)limite;
|
||||
if (plimite == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, (VOID *)plimite);
|
||||
}
|
||||
|
||||
VOID OsIPCLimitCopy(UINTPTR dest, UINTPTR src)
|
||||
{
|
||||
ProcIPCLimit *plimiteDest = (ProcIPCLimit *)dest;
|
||||
ProcIPCLimit *plimiteSrc = (ProcIPCLimit *)src;
|
||||
plimiteDest->mqCountLimit = plimiteSrc->mqCountLimit;
|
||||
plimiteDest->shmSizeLimit = plimiteSrc->shmSizeLimit;
|
||||
return;
|
||||
}
|
||||
|
||||
BOOL OsIPCLimiteMigrateCheck(UINTPTR curr, UINTPTR parent)
|
||||
{
|
||||
ProcIPCLimit *currIpcLimit = (ProcIPCLimit *)curr;
|
||||
ProcIPCLimit *parentIpcLimit = (ProcIPCLimit *)parent;
|
||||
if ((currIpcLimit->mqCount + parentIpcLimit->mqCount) >= parentIpcLimit->mqCountLimit) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((currIpcLimit->shmSize + parentIpcLimit->shmSize) >= parentIpcLimit->shmSizeLimit) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
VOID OsIPCLimitMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process)
|
||||
{
|
||||
ProcIPCLimit *currIpcLimit = (ProcIPCLimit *)currLimit;
|
||||
ProcIPCLimit *parentIpcLimit = (ProcIPCLimit *)parentLimit;
|
||||
LosProcessCB *pcb = (LosProcessCB *)process;
|
||||
|
||||
if (pcb == NULL) {
|
||||
parentIpcLimit->mqCount += currIpcLimit->mqCount;
|
||||
parentIpcLimit->mqFailedCount += currIpcLimit->mqFailedCount;
|
||||
parentIpcLimit->shmSize += currIpcLimit->shmSize;
|
||||
parentIpcLimit->shmFailedCount += currIpcLimit->shmFailedCount;
|
||||
return;
|
||||
}
|
||||
|
||||
parentIpcLimit->mqCount -= pcb->limitStat.mqCount;
|
||||
parentIpcLimit->shmSize -= pcb->limitStat.shmSize;
|
||||
currIpcLimit->mqCount += pcb->limitStat.mqCount;
|
||||
currIpcLimit->shmSize += pcb->limitStat.shmSize;
|
||||
}
|
||||
|
||||
BOOL OsIPCLimitAddProcessCheck(UINTPTR limit, UINTPTR process)
|
||||
{
|
||||
ProcIPCLimit *ipcLimit = (ProcIPCLimit *)limit;
|
||||
LosProcessCB *pcb = (LosProcessCB *)process;
|
||||
if ((ipcLimit->mqCount + pcb->limitStat.mqCount) >= ipcLimit->mqCountLimit) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((ipcLimit->shmSize + pcb->limitStat.shmSize) >= ipcLimit->shmSizeLimit) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
VOID OsIPCLimitAddProcess(UINTPTR limit, UINTPTR process)
|
||||
{
|
||||
LosProcessCB *pcb = (LosProcessCB *)process;
|
||||
ProcIPCLimit *plimits = (ProcIPCLimit *)limit;
|
||||
plimits->mqCount += pcb->limitStat.mqCount;
|
||||
plimits->shmSize += pcb->limitStat.shmSize;
|
||||
return;
|
||||
}
|
||||
|
||||
VOID OsIPCLimitDelProcess(UINTPTR limit, UINTPTR process)
|
||||
{
|
||||
LosProcessCB *pcb = (LosProcessCB *)process;
|
||||
ProcIPCLimit *plimits = (ProcIPCLimit *)limit;
|
||||
|
||||
plimits->mqCount -= pcb->limitStat.mqCount;
|
||||
plimits->shmSize -= pcb->limitStat.shmSize;
|
||||
return;
|
||||
}
|
||||
|
||||
UINT32 OsIPCLimitSetMqLimit(ProcIPCLimit *ipcLimit, UINT32 value)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
if ((ipcLimit == NULL) || (value == 0) || (value > LOSCFG_BASE_IPC_QUEUE_LIMIT)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (ipcLimit == g_rootIPCLimit) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (value < ipcLimit->mqCount) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
ipcLimit->mqCountLimit = value;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsIPCLimitSetShmLimit(ProcIPCLimit *ipcLimit, UINT32 value)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
if ((ipcLimit == NULL) || (value == 0) || (value > PLIMIT_IPC_SHM_LIMIT_MAX)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (ipcLimit == g_rootIPCLimit) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (value < ipcLimit->shmSize) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
ipcLimit->shmSizeLimit = value;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsIPCLimitMqAlloc(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LosProcessCB *run = OsCurrProcessGet();
|
||||
ProcIPCLimit *ipcLimit = (ProcIPCLimit *)run->plimits->limitsList[PROCESS_LIMITER_ID_IPC];
|
||||
if (ipcLimit->mqCount >= ipcLimit->mqCountLimit) {
|
||||
ipcLimit->mqFailedCount++;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
run->limitStat.mqCount++;
|
||||
ipcLimit->mqCount++;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsIPCLimitMqFree(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LosProcessCB *run = OsCurrProcessGet();
|
||||
ProcIPCLimit *ipcLimit = (ProcIPCLimit *)run->plimits->limitsList[PROCESS_LIMITER_ID_IPC];
|
||||
ipcLimit->mqCount--;
|
||||
run->limitStat.mqCount--;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
UINT32 OsIPCLimitShmAlloc(UINT32 size)
|
||||
{
|
||||
UINT32 intSave;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LosProcessCB *run = OsCurrProcessGet();
|
||||
ProcIPCLimit *ipcLimit = (ProcIPCLimit *)run->plimits->limitsList[PROCESS_LIMITER_ID_IPC];
|
||||
if ((ipcLimit->shmSize + size) >= ipcLimit->shmSizeLimit) {
|
||||
ipcLimit->shmFailedCount++;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
run->limitStat.shmSize += size;
|
||||
ipcLimit->shmSize += size;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsIPCLimitShmFree(UINT32 size)
|
||||
{
|
||||
UINT32 intSave;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LosProcessCB *run = OsCurrProcessGet();
|
||||
ProcIPCLimit *ipcLimit = (ProcIPCLimit *)run->plimits->limitsList[PROCESS_LIMITER_ID_IPC];
|
||||
ipcLimit->shmSize -= size;
|
||||
run->limitStat.shmSize -= size;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
92
kernel/extended/plimit/los_ipclimit.h
Normal file
92
kernel/extended/plimit/los_ipclimit.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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_IPCLIMIT_H
|
||||
#define _LOS_IPCLIMIT_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct ProcIPCLimit {
|
||||
UINT32 mqCount;
|
||||
UINT32 mqFailedCount;
|
||||
UINT32 mqCountLimit;
|
||||
UINT32 shmSize;
|
||||
UINT32 shmFailedCount;
|
||||
UINT32 shmSizeLimit;
|
||||
} ProcIPCLimit;
|
||||
|
||||
enum IPCStatType {
|
||||
IPC_STAT_TYPE_MQ = 0,
|
||||
IPC_STAT_TYPE_SHM = 3,
|
||||
IPC_STAT_TYPE_BUT // buttock
|
||||
};
|
||||
|
||||
enum IPCStatOffset {
|
||||
IPC_STAT_OFFSET_MQ = 0,
|
||||
IPC_STAT_OFFSET_SHM = 3,
|
||||
IPC_STAT_OFFSET_BUT // buttock
|
||||
};
|
||||
|
||||
enum StatItem {
|
||||
STAT_ITEM_TOTAL,
|
||||
STAT_ITEM_FAILED,
|
||||
STAT_ITEM_LIMIT,
|
||||
STAT_ITEM_BUT // buttock
|
||||
};
|
||||
|
||||
VOID OsIPCLimitInit(UINTPTR limite);
|
||||
VOID *OsIPCLimitAlloc(VOID);
|
||||
VOID OsIPCLimitFree(UINTPTR limite);
|
||||
VOID OsIPCLimitCopy(UINTPTR dest, UINTPTR src);
|
||||
BOOL OsIPCLimiteMigrateCheck(UINTPTR curr, UINTPTR parent);
|
||||
VOID OsIPCLimitMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process);
|
||||
BOOL OsIPCLimitAddProcessCheck(UINTPTR limit, UINTPTR process);
|
||||
VOID OsIPCLimitAddProcess(UINTPTR limit, UINTPTR process);
|
||||
VOID OsIPCLimitDelProcess(UINTPTR limit, UINTPTR process);
|
||||
UINT32 OsIPCLimitSetMqLimit(ProcIPCLimit *ipcLimit, UINT32 value);
|
||||
UINT32 OsIPCLimitSetShmLimit(ProcIPCLimit *ipcLimit, UINT32 value);
|
||||
UINT32 OsIPCLimitMqAlloc(VOID);
|
||||
VOID OsIPCLimitMqFree(VOID);
|
||||
UINT32 OsIPCLimitShmAlloc(UINT32 size);
|
||||
VOID OsIPCLimitShmFree(UINT32 size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_IPCIMIT_H */
|
||||
223
kernel/extended/plimit/los_memlimit.c
Normal file
223
kernel/extended/plimit/los_memlimit.c
Normal file
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
|
||||
#include <stdlib.h>
|
||||
#include <securec.h>
|
||||
#include "los_config.h"
|
||||
#include "los_hook.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "los_plimits.h"
|
||||
|
||||
STATIC ProcMemLimiter *g_procMemLimiter = NULL;
|
||||
|
||||
VOID OsMemLimiterInit(UINTPTR limite)
|
||||
{
|
||||
ProcMemLimiter *procMemLimiter = (ProcMemLimiter *)limite;
|
||||
procMemLimiter->limit = OS_NULL_INT;
|
||||
g_procMemLimiter = procMemLimiter;
|
||||
}
|
||||
|
||||
VOID OsMemLimitSetLimit(UINT32 limit)
|
||||
{
|
||||
g_procMemLimiter->limit = limit;
|
||||
}
|
||||
|
||||
VOID *OsMemLimiterAlloc(VOID)
|
||||
{
|
||||
ProcMemLimiter *plimite = (ProcMemLimiter *)LOS_MemAlloc(m_aucSysMem1, sizeof(ProcMemLimiter));
|
||||
if (plimite == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(plimite, sizeof(ProcMemLimiter), 0, sizeof(ProcMemLimiter));
|
||||
return (VOID *)plimite;
|
||||
}
|
||||
|
||||
VOID OsMemLimiterFree(UINTPTR limite)
|
||||
{
|
||||
ProcMemLimiter *plimite = (ProcMemLimiter *)limite;
|
||||
if (plimite == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, (VOID *)limite);
|
||||
}
|
||||
|
||||
VOID OsMemLimiterCopy(UINTPTR dest, UINTPTR src)
|
||||
{
|
||||
ProcMemLimiter *plimiteDest = (ProcMemLimiter *)dest;
|
||||
ProcMemLimiter *plimiteSrc = (ProcMemLimiter *)src;
|
||||
plimiteDest->limit = plimiteSrc->limit;
|
||||
return;
|
||||
}
|
||||
|
||||
BOOL MemLimiteMigrateCheck(UINTPTR curr, UINTPTR parent)
|
||||
{
|
||||
ProcMemLimiter *currMemLimit = (ProcMemLimiter *)curr;
|
||||
ProcMemLimiter *parentMemLimit = (ProcMemLimiter *)parent;
|
||||
if ((currMemLimit->usage + parentMemLimit->usage) >= parentMemLimit->limit) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
VOID OsMemLimiterMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process)
|
||||
{
|
||||
ProcMemLimiter *currMemLimit = (ProcMemLimiter *)currLimit;
|
||||
ProcMemLimiter *parentMemLimit = (ProcMemLimiter *)parentLimit;
|
||||
LosProcessCB *pcb = (LosProcessCB *)process;
|
||||
|
||||
if (pcb == NULL) {
|
||||
parentMemLimit->usage += currMemLimit->usage;
|
||||
parentMemLimit->failcnt += currMemLimit->failcnt;
|
||||
if (parentMemLimit->peak < parentMemLimit->usage) {
|
||||
parentMemLimit->peak = parentMemLimit->usage;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
parentMemLimit->usage -= pcb->limitStat.memUsed;
|
||||
currMemLimit->usage += pcb->limitStat.memUsed;
|
||||
}
|
||||
|
||||
BOOL OsMemLimitAddProcessCheck(UINTPTR limit, UINTPTR process)
|
||||
{
|
||||
ProcMemLimiter *memLimit = (ProcMemLimiter *)limit;
|
||||
LosProcessCB *pcb = (LosProcessCB *)process;
|
||||
if ((memLimit->usage + pcb->limitStat.memUsed) > memLimit->limit) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
VOID OsMemLimitAddProcess(UINTPTR limit, UINTPTR process)
|
||||
{
|
||||
LosProcessCB *pcb = (LosProcessCB *)process;
|
||||
ProcMemLimiter *plimits = (ProcMemLimiter *)limit;
|
||||
plimits->usage += pcb->limitStat.memUsed;
|
||||
if (plimits->peak < plimits->usage) {
|
||||
plimits->peak = plimits->usage;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
VOID OsMemLimitDelProcess(UINTPTR limit, UINTPTR process)
|
||||
{
|
||||
LosProcessCB *pcb = (LosProcessCB *)process;
|
||||
ProcMemLimiter *plimits = (ProcMemLimiter *)limit;
|
||||
|
||||
plimits->usage -= pcb->limitStat.memUsed;
|
||||
return;
|
||||
}
|
||||
|
||||
UINT32 OsMemLimitSetMemLimit(ProcMemLimiter *memLimit, UINT64 value)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if ((memLimit == NULL) || (value == 0)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (memLimit == g_procMemLimiter) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (value < memLimit->usage) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
memLimit->limit = value;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#define MEM_LIMIT_LOCK(state, locked) do { \
|
||||
if (SCHEDULER_HELD()) { \
|
||||
locked = TRUE; \
|
||||
} else { \
|
||||
SCHEDULER_LOCK(state); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define MEM_LIMIT_UNLOCK(state, locked) do { \
|
||||
if (!locked) { \
|
||||
SCHEDULER_UNLOCK(state); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
UINT32 OsMemLimitCheckAndMemAdd(UINT32 size)
|
||||
{
|
||||
UINT32 intSave;
|
||||
BOOL locked = FALSE;
|
||||
MEM_LIMIT_LOCK(intSave, locked);
|
||||
LosProcessCB *run = OsCurrProcessGet();
|
||||
UINT32 currProcessID = run->processID;
|
||||
if ((run == NULL) || (run->plimits == NULL)) {
|
||||
MEM_LIMIT_UNLOCK(intSave, locked);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
ProcMemLimiter *memLimit = (ProcMemLimiter *)run->plimits->limitsList[PROCESS_LIMITER_ID_MEM];
|
||||
if ((memLimit->usage + size) > memLimit->limit) {
|
||||
memLimit->failcnt++;
|
||||
MEM_LIMIT_UNLOCK(intSave, locked);
|
||||
PRINT_ERR("plimits: process %u adjust the memory limit of Plimits group\n", currProcessID);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
memLimit->usage += size;
|
||||
run->limitStat.memUsed += size;
|
||||
if (memLimit->peak < memLimit->usage) {
|
||||
memLimit->peak = memLimit->usage;
|
||||
}
|
||||
MEM_LIMIT_UNLOCK(intSave, locked);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsMemLimitMemFree(UINT32 size)
|
||||
{
|
||||
UINT32 intSave;
|
||||
BOOL locked = FALSE;
|
||||
MEM_LIMIT_LOCK(intSave, locked);
|
||||
LosProcessCB *run = OsCurrProcessGet();
|
||||
if ((run == NULL) || (run->plimits == NULL)) {
|
||||
MEM_LIMIT_UNLOCK(intSave, locked);
|
||||
return;
|
||||
}
|
||||
|
||||
ProcMemLimiter *memLimit = (ProcMemLimiter *)run->plimits->limitsList[PROCESS_LIMITER_ID_MEM];
|
||||
if (run->limitStat.memUsed > size) {
|
||||
run->limitStat.memUsed -= size;
|
||||
memLimit->usage -= size;
|
||||
}
|
||||
MEM_LIMIT_UNLOCK(intSave, locked);
|
||||
}
|
||||
#endif
|
||||
69
kernel/extended/plimit/los_memlimit.h
Normal file
69
kernel/extended/plimit/los_memlimit.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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_MEMLIMIT_H
|
||||
#define _LOS_MEMLIMIT_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct ProcMemLimiter {
|
||||
UINT64 usage;
|
||||
UINT64 limit;
|
||||
UINT64 peak;
|
||||
UINT32 failcnt;
|
||||
} ProcMemLimiter;
|
||||
|
||||
VOID OsMemLimiterInit(UINTPTR limite);
|
||||
VOID *OsMemLimiterAlloc(VOID);
|
||||
VOID OsMemLimiterFree(UINTPTR limite);
|
||||
VOID OsMemLimiterCopy(UINTPTR dest, UINTPTR src);
|
||||
BOOL MemLimiteMigrateCheck(UINTPTR curr, UINTPTR parent);
|
||||
VOID OsMemLimiterMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process);
|
||||
BOOL OsMemLimitAddProcessCheck(UINTPTR limit, UINTPTR process);
|
||||
VOID OsMemLimitAddProcess(UINTPTR limit, UINTPTR process);
|
||||
VOID OsMemLimitDelProcess(UINTPTR limit, UINTPTR process);
|
||||
UINT32 OsMemLimitSetMemLimit(ProcMemLimiter *memLimit, UINT64 value);
|
||||
VOID OsMemLimitSetLimit(UINTPTR limit);
|
||||
UINT32 OsMemLimitCheckAndMemAdd(UINT32 size);
|
||||
VOID OsMemLimitMemFree(UINT32 size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_MEMLIMIT_H */
|
||||
434
kernel/extended/plimit/los_plimits.c
Normal file
434
kernel/extended/plimit/los_plimits.c
Normal file
@@ -0,0 +1,434 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef LOSCFG_KERNEL_PLIMITS
|
||||
#include "los_base.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "hal_timer.h"
|
||||
#include "los_plimits.h"
|
||||
|
||||
typedef struct PlimiteOperations {
|
||||
VOID (*LimiterInit)(UINTPTR);
|
||||
VOID *(*LimiterAlloc)(VOID);
|
||||
VOID (*LimiterFree)(UINTPTR);
|
||||
VOID (*LimiterCopy)(UINTPTR, UINTPTR);
|
||||
BOOL (*LimiterAddProcessCheck)(UINTPTR, UINTPTR);
|
||||
VOID (*LimiterAddProcess)(UINTPTR, UINTPTR);
|
||||
VOID (*LimiterDelProcess)(UINTPTR, UINTPTR);
|
||||
BOOL (*LimiterMigrateCheck)(UINTPTR, UINTPTR);
|
||||
VOID (*LimiterMigrate)(UINTPTR, UINTPTR, UINTPTR);
|
||||
} PlimiteOperations;
|
||||
|
||||
static PlimiteOperations g_limiteOps[PROCESS_LIMITER_COUNT] = {
|
||||
[PROCESS_LIMITER_ID_PIDS] = {
|
||||
.LimiterInit = PidLimiterInit,
|
||||
.LimiterAlloc = PidLimiterAlloc,
|
||||
.LimiterFree = PidLimterFree,
|
||||
.LimiterCopy = PidLimiterCopy,
|
||||
.LimiterAddProcessCheck = OsPidLimitAddProcessCheck,
|
||||
.LimiterAddProcess = OsPidLimitAddProcess,
|
||||
.LimiterDelProcess = OsPidLimitDelProcess,
|
||||
.LimiterMigrateCheck = PidLimitMigrateCheck,
|
||||
.LimiterMigrate = NULL,
|
||||
},
|
||||
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
|
||||
[PROCESS_LIMITER_ID_MEM] = {
|
||||
.LimiterInit = OsMemLimiterInit,
|
||||
.LimiterAlloc = OsMemLimiterAlloc,
|
||||
.LimiterFree = OsMemLimiterFree,
|
||||
.LimiterCopy = OsMemLimiterCopy,
|
||||
.LimiterAddProcessCheck = OsMemLimitAddProcessCheck,
|
||||
.LimiterAddProcess = OsMemLimitAddProcess,
|
||||
.LimiterDelProcess = OsMemLimitDelProcess,
|
||||
.LimiterMigrateCheck = MemLimiteMigrateCheck,
|
||||
.LimiterMigrate = OsMemLimiterMigrate,
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
|
||||
[PROCESS_LIMITER_ID_SCHED] = {
|
||||
.LimiterInit = OsSchedLimitInit,
|
||||
.LimiterAlloc = OsSchedLimitAlloc,
|
||||
.LimiterFree = OsSchedLimitFree,
|
||||
.LimiterCopy = OsSchedLimitCopy,
|
||||
.LimiterAddProcessCheck = NULL,
|
||||
.LimiterAddProcess = NULL,
|
||||
.LimiterDelProcess = NULL,
|
||||
.LimiterMigrateCheck = NULL,
|
||||
.LimiterMigrate = NULL,
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
|
||||
[PROCESS_LIMITER_ID_DEV] = {
|
||||
.LimiterInit = OsDevLimitInit,
|
||||
.LimiterAlloc = OsDevLimitAlloc,
|
||||
.LimiterFree = OsDevLimitFree,
|
||||
.LimiterCopy = OsDevLimitCopy,
|
||||
.LimiterAddProcessCheck = NULL,
|
||||
.LimiterAddProcess = NULL,
|
||||
.LimiterDelProcess = NULL,
|
||||
.LimiterMigrateCheck = NULL,
|
||||
.LimiterMigrate = NULL,
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
|
||||
[PROCESS_LIMITER_ID_IPC] = {
|
||||
.LimiterInit = OsIPCLimitInit,
|
||||
.LimiterAlloc = OsIPCLimitAlloc,
|
||||
.LimiterFree = OsIPCLimitFree,
|
||||
.LimiterCopy = OsIPCLimitCopy,
|
||||
.LimiterAddProcessCheck = OsIPCLimitAddProcessCheck,
|
||||
.LimiterAddProcess = OsIPCLimitAddProcess,
|
||||
.LimiterDelProcess = OsIPCLimitDelProcess,
|
||||
.LimiterMigrateCheck = OsIPCLimiteMigrateCheck,
|
||||
.LimiterMigrate = OsIPCLimitMigrate,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC ProcLimiterSet *g_rootPLimite = NULL;
|
||||
|
||||
ProcLimiterSet *OsRootPLimitsGet(VOID)
|
||||
{
|
||||
return g_rootPLimite;
|
||||
}
|
||||
|
||||
UINT32 OsProcLimiterSetInit(VOID)
|
||||
{
|
||||
g_rootPLimite = (ProcLimiterSet *)LOS_MemAlloc(m_aucSysMem1, sizeof(ProcLimiterSet));
|
||||
if (g_rootPLimite == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
(VOID)memset_s(g_rootPLimite, sizeof(ProcLimiterSet), 0, sizeof(ProcLimiterSet));
|
||||
|
||||
LOS_ListInit(&g_rootPLimite->childList);
|
||||
LOS_ListInit(&g_rootPLimite->processList);
|
||||
|
||||
ProcLimiterSet *procLimiterSet = g_rootPLimite;
|
||||
for (INT32 plimiteID = 0; plimiteID < PROCESS_LIMITER_COUNT; ++plimiteID) {
|
||||
procLimiterSet->limitsList[plimiteID] = (UINTPTR)g_limiteOps[plimiteID].LimiterAlloc();
|
||||
if (procLimiterSet->limitsList[plimiteID] == (UINTPTR)NULL) {
|
||||
OsPLimitsFree(procLimiterSet);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
if (g_limiteOps[plimiteID].LimiterInit != NULL) {
|
||||
g_limiteOps[plimiteID].LimiterInit(procLimiterSet->limitsList[plimiteID]);
|
||||
}
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID PLimitsDeleteProcess(LosProcessCB *processCB)
|
||||
{
|
||||
if ((processCB == NULL) || (processCB->plimits == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ProcLimiterSet *plimits = processCB->plimits;
|
||||
for (UINT32 limitsID = 0; limitsID < PROCESS_LIMITER_COUNT; limitsID++) {
|
||||
if (g_limiteOps[limitsID].LimiterDelProcess == NULL) {
|
||||
continue;
|
||||
}
|
||||
g_limiteOps[limitsID].LimiterDelProcess(plimits->limitsList[limitsID], (UINTPTR)processCB);
|
||||
}
|
||||
plimits->pidCount--;
|
||||
LOS_ListDelete(&processCB->plimitsList);
|
||||
processCB->plimits = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC UINT32 PLimitsAddProcess(ProcLimiterSet *plimits, LosProcessCB *processCB)
|
||||
{
|
||||
UINT32 limitsID;
|
||||
if (plimits == NULL) {
|
||||
plimits = g_rootPLimite;
|
||||
}
|
||||
|
||||
if (processCB->plimits == g_rootPLimite) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
if (processCB->plimits == plimits) {
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
for (limitsID = 0; limitsID < PROCESS_LIMITER_COUNT; limitsID++) {
|
||||
if (g_limiteOps[limitsID].LimiterAddProcessCheck == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!g_limiteOps[limitsID].LimiterAddProcessCheck(plimits->limitsList[limitsID], (UINTPTR)processCB)) {
|
||||
return EACCES;
|
||||
}
|
||||
}
|
||||
|
||||
PLimitsDeleteProcess(processCB);
|
||||
|
||||
for (limitsID = 0; limitsID < PROCESS_LIMITER_COUNT; limitsID++) {
|
||||
if (g_limiteOps[limitsID].LimiterAddProcess == NULL) {
|
||||
continue;
|
||||
}
|
||||
g_limiteOps[limitsID].LimiterAddProcess(plimits->limitsList[limitsID], (UINTPTR)processCB);
|
||||
}
|
||||
|
||||
LOS_ListTailInsert(&plimits->processList, &processCB->plimitsList);
|
||||
plimits->pidCount++;
|
||||
processCB->plimits = plimits;
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsPLimitsAddProcess(ProcLimiterSet *plimits, LosProcessCB *processCB)
|
||||
{
|
||||
UINT32 intSave;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
UINT32 ret = PLimitsAddProcess(plimits, processCB);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
UINT32 OsPLimitsAddPid(ProcLimiterSet *plimits, UINT32 pid)
|
||||
{
|
||||
UINT32 intSave, ret;
|
||||
if ((plimits == NULL) || OS_PID_CHECK_INVALID(pid) || (pid == 0)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (plimits == g_rootPLimite) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LosProcessCB *processCB = OS_PCB_FROM_PID((unsigned int)pid);
|
||||
if (OsProcessIsInactive(processCB)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
ret = PLimitsAddProcess(plimits, processCB);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
VOID OsPLimitsDeleteProcess(LosProcessCB *processCB)
|
||||
{
|
||||
UINT32 intSave;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
PLimitsDeleteProcess(processCB);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
}
|
||||
|
||||
UINT32 OsPLimitsPidsGet(const ProcLimiterSet *plimits, UINT32 *pids, UINT32 size)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosProcessCB *processCB = NULL;
|
||||
UINT32 minSize = LOS_GetSystemProcessMaximum() * sizeof(UINT32);
|
||||
if ((plimits == NULL) || (pids == NULL) || (size < minSize)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LOS_DL_LIST *listHead = (LOS_DL_LIST *)&plimits->processList;
|
||||
if (LOS_ListEmpty(listHead)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(processCB, listHead, LosProcessCB, plimitsList) {
|
||||
pids[OsGetPid(processCB)] = 1;
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID PLimitsProcessMerge(ProcLimiterSet *currPLimits, ProcLimiterSet *parentPLimits)
|
||||
{
|
||||
LOS_DL_LIST *head = &currPLimits->processList;
|
||||
while (!LOS_ListEmpty(head)) {
|
||||
LosProcessCB *processCB = LOS_DL_LIST_ENTRY(head->pstNext, LosProcessCB, plimitsList);
|
||||
PLimitsDeleteProcess(processCB);
|
||||
PLimitsAddProcess(parentPLimits, processCB);
|
||||
}
|
||||
LOS_ListDelete(&currPLimits->childList);
|
||||
currPLimits->parent = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC UINT32 PLimitsMigrateCheck(ProcLimiterSet *currPLimits, ProcLimiterSet *parentPLimits)
|
||||
{
|
||||
for (UINT32 limiteID = 0; limiteID < PROCESS_LIMITER_COUNT; limiteID++) {
|
||||
UINTPTR currLimit = currPLimits->limitsList[limiteID];
|
||||
UINTPTR parentLimit = parentPLimits->limitsList[limiteID];
|
||||
if (g_limiteOps[limiteID].LimiterMigrateCheck == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!g_limiteOps[limiteID].LimiterMigrateCheck(currLimit, parentLimit)) {
|
||||
return EPERM;
|
||||
}
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsPLimitsFree(ProcLimiterSet *currPLimits)
|
||||
{
|
||||
UINT32 intSave, ret;
|
||||
if (currPLimits == NULL) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
ProcLimiterSet *parentPLimits = currPLimits->parent;
|
||||
ret = PLimitsMigrateCheck(currPLimits, parentPLimits);
|
||||
if (ret != LOS_OK) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
PLimitsProcessMerge(currPLimits, parentPLimits);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
for (INT32 limiteID = 0; limiteID < PROCESS_LIMITER_COUNT; ++limiteID) {
|
||||
UINTPTR procLimiter = currPLimits->limitsList[limiteID];
|
||||
if (g_limiteOps[limiteID].LimiterFree != NULL) {
|
||||
g_limiteOps[limiteID].LimiterFree(procLimiter);
|
||||
}
|
||||
}
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, currPLimits);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
ProcLimiterSet *OsPLimitsCreate(ProcLimiterSet *parentPLimits)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
ProcLimiterSet *newPLimits = (ProcLimiterSet *)LOS_MemAlloc(m_aucSysMem1, sizeof(ProcLimiterSet));
|
||||
if (newPLimits == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(newPLimits, sizeof(ProcLimiterSet), 0, sizeof(ProcLimiterSet));
|
||||
LOS_ListInit(&newPLimits->childList);
|
||||
LOS_ListInit(&newPLimits->processList);
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
newPLimits->parent = parentPLimits;
|
||||
newPLimits->level = parentPLimits->level + 1;
|
||||
newPLimits->mask = parentPLimits->mask;
|
||||
|
||||
for (INT32 plimiteID = 0; plimiteID < PROCESS_LIMITER_COUNT; ++plimiteID) {
|
||||
newPLimits->limitsList[plimiteID] = (UINTPTR)g_limiteOps[plimiteID].LimiterAlloc();
|
||||
if (newPLimits->limitsList[plimiteID] == (UINTPTR)NULL) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
OsPLimitsFree(newPLimits);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (g_limiteOps[plimiteID].LimiterCopy != NULL) {
|
||||
g_limiteOps[plimiteID].LimiterCopy(newPLimits->limitsList[plimiteID],
|
||||
parentPLimits->limitsList[plimiteID]);
|
||||
}
|
||||
}
|
||||
LOS_ListTailInsert(&g_rootPLimite->childList, &newPLimits->childList);
|
||||
|
||||
(VOID)PLimitsDeleteProcess(OsCurrProcessGet());
|
||||
(VOID)PLimitsAddProcess(newPLimits, OsCurrProcessGet());
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return newPLimits;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
|
||||
UINT32 OsPLimitsMemUsageGet(ProcLimiterSet *plimits, UINT64 *usage, UINT32 size)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosProcessCB *processCB = NULL;
|
||||
UINT32 minSize = LOS_GetSystemProcessMaximum() * sizeof(UINT64) + sizeof(ProcMemLimiter);
|
||||
ProcMemLimiter *memLimit = (ProcMemLimiter *)usage;
|
||||
UINT64 *memSuage = (UINT64 *)((UINTPTR)usage + sizeof(ProcMemLimiter));
|
||||
if ((plimits == NULL) || (usage == NULL) || (size < minSize)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
(VOID)memcpy_s(memLimit, sizeof(ProcMemLimiter),
|
||||
(VOID *)plimits->limitsList[PROCESS_LIMITER_ID_MEM], sizeof(ProcMemLimiter));
|
||||
LOS_DL_LIST *listHead = (LOS_DL_LIST *)&plimits->processList;
|
||||
if (LOS_ListEmpty(listHead)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(processCB, listHead, LosProcessCB, plimitsList) {
|
||||
memSuage[OsGetPid(processCB)] = processCB->limitStat.memUsed;
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
|
||||
UINT32 OsPLimitsIPCStatGet(ProcLimiterSet *plimits, ProcIPCLimit *ipc, UINT32 size)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if ((plimits == NULL) || (ipc == NULL) || (size != sizeof(ProcIPCLimit))) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
(VOID)memcpy_s(ipc, sizeof(ProcIPCLimit),
|
||||
(VOID *)plimits->limitsList[PROCESS_LIMITER_ID_IPC], sizeof(ProcIPCLimit));
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
|
||||
UINT32 OsPLimitsSchedUsageGet(ProcLimiterSet *plimits, UINT64 *usage, UINT32 size)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosProcessCB *processCB = NULL;
|
||||
UINT32 minSize = LOS_GetSystemProcessMaximum() * sizeof(UINT64);
|
||||
if ((plimits == NULL) || (usage == NULL) || (size < minSize)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LOS_DL_LIST *listHead = (LOS_DL_LIST *)&plimits->processList;
|
||||
if (LOS_ListEmpty(listHead)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(processCB, listHead, LosProcessCB, plimitsList) {
|
||||
usage[OsGetPid(processCB)] = processCB->limitStat.allRuntime;
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
114
kernel/extended/plimit/los_plimits.h
Normal file
114
kernel/extended/plimit/los_plimits.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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_PLIMITS_H
|
||||
#define _LOS_PLIMITS_H
|
||||
|
||||
#include "los_list.h"
|
||||
#include "los_typedef.h"
|
||||
#include "los_processlimit.h"
|
||||
#include "los_memlimit.h"
|
||||
#include "los_ipclimit.h"
|
||||
#include "los_devicelimit.h"
|
||||
#include "los_schedlimit.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* proc limit set lock */
|
||||
#define PLIMITS_MIN_PERIOD_IN_US 1000000
|
||||
#define PLIMITS_MIN_QUOTA_IN_US 1
|
||||
#define PLIMITS_DELETE_WAIT_TIME 1000
|
||||
typedef struct ProcessCB LosProcessCB;
|
||||
|
||||
enum ProcLimiterID {
|
||||
PROCESS_LIMITER_ID_PIDS = 0,
|
||||
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
|
||||
PROCESS_LIMITER_ID_MEM,
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
|
||||
PROCESS_LIMITER_ID_SCHED,
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
|
||||
PROCESS_LIMITER_ID_DEV,
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
|
||||
PROCESS_LIMITER_ID_IPC,
|
||||
#endif
|
||||
PROCESS_LIMITER_COUNT,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
|
||||
UINT64 memUsed;
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
|
||||
UINT32 mqCount;
|
||||
UINT32 shmSize;
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
|
||||
UINT64 allRuntime;
|
||||
#endif
|
||||
} PLimitsData;
|
||||
|
||||
typedef struct TagPLimiterSet {
|
||||
struct TagPLimiterSet *parent; /* plimite parent */
|
||||
LOS_DL_LIST childList; /* plimite childList */
|
||||
LOS_DL_LIST processList;
|
||||
UINT32 pidCount;
|
||||
UINTPTR limitsList[PROCESS_LIMITER_COUNT]; /* plimite list */
|
||||
UINT32 mask; /* each bit indicates that a limite exists */
|
||||
UINT8 level; /* plimits hierarchy level */
|
||||
} ProcLimiterSet;
|
||||
|
||||
typedef struct ProcessCB LosProcessCB;
|
||||
ProcLimiterSet *OsRootPLimitsGet(VOID);
|
||||
UINT32 OsPLimitsAddProcess(ProcLimiterSet *plimits, LosProcessCB *processCB);
|
||||
UINT32 OsPLimitsAddPid(ProcLimiterSet *plimits, UINT32 pid);
|
||||
VOID OsPLimitsDeleteProcess(LosProcessCB *processCB);
|
||||
UINT32 OsPLimitsPidsGet(const ProcLimiterSet *plimits, UINT32 *pids, UINT32 size);
|
||||
UINT32 OsPLimitsFree(ProcLimiterSet *currPLimits);
|
||||
ProcLimiterSet *OsPLimitsCreate(ProcLimiterSet *parentProcLimiterSet);
|
||||
UINT32 OsProcLimiterSetInit(VOID);
|
||||
|
||||
UINT32 OsPLimitsMemUsageGet(ProcLimiterSet *plimits, UINT64 *usage, UINT32 size);
|
||||
UINT32 OsPLimitsIPCStatGet(ProcLimiterSet *plimits, ProcIPCLimit *ipc, UINT32 size);
|
||||
UINT32 OsPLimitsSchedUsageGet(ProcLimiterSet *plimits, UINT64 *usage, UINT32 size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_PLIMITS_H */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user