From cf8446c94112ed6993a2e6e71e793d83a72689d5 Mon Sep 17 00:00:00 2001 From: zhushengle Date: Thu, 21 Oct 2021 20:31:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BF=9B=E7=A8=8Brlimit=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=8A=A8=E6=80=81=E5=88=86=E9=85=8D,?= =?UTF-8?q?=E5=87=8F=E5=B0=91=E9=9D=99=E6=80=81=E5=86=85=E5=AD=98=E5=8D=A0?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close #I4EZY5 Signed-off-by: zhushengle Change-Id: I47ed0ff7a52f72e38875c3308b20e183cc5c4563 --- compat/posix/src/misc.c | 37 +++++++++++++++++++++++---- kernel/base/core/los_process.c | 5 ++++ kernel/base/include/los_process_pri.h | 2 +- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/compat/posix/src/misc.c b/compat/posix/src/misc.c index 821d4217..3950d95c 100644 --- a/compat/posix/src/misc.c +++ b/compat/posix/src/misc.c @@ -40,6 +40,7 @@ #include "los_process_pri.h" #include "los_hw.h" +static struct rlimit g_defaultLimit = { 0 }; /* * Supply some suitable values for constants that may not be present * in all configurations. @@ -154,7 +155,9 @@ pid_t getpid(void) int getrlimit(int resource, struct rlimit *rlim) { + unsigned int intSave; LosProcessCB *pcb = OsCurrProcessGet(); + struct rlimit *resourceLimit = pcb->resourceLimit; switch (resource) { case RLIMIT_NOFILE: @@ -163,8 +166,15 @@ int getrlimit(int resource, struct rlimit *rlim) default: return -EINVAL; } - rlim->rlim_cur = pcb->pl_rlimit[resource].rlim_cur; - rlim->rlim_max = pcb->pl_rlimit[resource].rlim_max; + + if (resourceLimit == NULL) { + resourceLimit = &g_defaultLimit; + } + + SCHEDULER_LOCK(intSave); + rlim->rlim_cur = resourceLimit[resource].rlim_cur; + rlim->rlim_max = resourceLimit[resource].rlim_max; + SCHEDULER_UNLOCK(intSave); return 0; } @@ -175,6 +185,8 @@ int getrlimit(int resource, struct rlimit *rlim) #endif int setrlimit(int resource, const struct rlimit *rlim) { + unsigned int intSave; + struct rlimit *resourceLimit = NULL; LosProcessCB *pcb = OsCurrProcessGet(); if (rlim->rlim_cur > rlim->rlim_max) { @@ -194,8 +206,23 @@ int setrlimit(int resource, const struct rlimit *rlim) default: return -EINVAL; } - pcb->pl_rlimit[resource].rlim_cur = rlim->rlim_cur; - pcb->pl_rlimit[resource].rlim_max = rlim->rlim_max; + if (pcb->resourceLimit == NULL) { + resourceLimit = LOS_MemAlloc((VOID *)m_aucSysMem0, RLIM_NLIMITS * sizeof(struct rlimit)); + if (resourceLimit == NULL) { + return -EINVAL; + } + } + + SCHEDULER_LOCK(intSave); + if (pcb->resourceLimit == NULL) { + pcb->resourceLimit = resourceLimit; + resourceLimit = NULL; + } + pcb->resourceLimit[resource].rlim_cur = rlim->rlim_cur; + pcb->resourceLimit[resource].rlim_max = rlim->rlim_max; + SCHEDULER_UNLOCK(intSave); + + (VOID)LOS_MemFree((VOID *)m_aucSysMem0, resourceLimit); return 0; -} \ No newline at end of file +} diff --git a/kernel/base/core/los_process.c b/kernel/base/core/los_process.c index adf53610..40c1e56b 100644 --- a/kernel/base/core/los_process.c +++ b/kernel/base/core/los_process.c @@ -378,6 +378,11 @@ LITE_OS_SEC_TEXT VOID OsProcessResourcesToFree(LosProcessCB *processCB) (VOID)memset_s(&(processCB->ipcInfo), sizeof(ProcIpcInfo), 0, sizeof(ProcIpcInfo)); } #endif + + if (processCB->resourceLimit != NULL) { + (VOID)LOS_MemFree((VOID *)m_aucSysMem0, processCB->resourceLimit); + processCB->resourceLimit = NULL; + } } LITE_OS_SEC_TEXT STATIC VOID OsRecycleZombiesProcess(LosProcessCB *childCB, ProcessGroup **group) diff --git a/kernel/base/include/los_process_pri.h b/kernel/base/include/los_process_pri.h index 2b64fb57..1e94deaf 100644 --- a/kernel/base/include/los_process_pri.h +++ b/kernel/base/include/los_process_pri.h @@ -127,7 +127,7 @@ typedef struct ProcessCB { #ifdef LOSCFG_KERNEL_CPUP OsCpupBase processCpup; /**< Process cpu usage */ #endif - struct rlimit pl_rlimit[RLIM_NLIMITS]; + struct rlimit *resourceLimit; } LosProcessCB; #define CLONE_VM 0x00000100