Description:Process security function rectification.
Reviewed-by:liulei, lihao, likailong Change-Id: Ibacdda2ccbbc991ac9732f2ad09bdb98195203b3
This commit is contained in:
parent
c383ba65ae
commit
4ff3c4bf79
|
@ -203,10 +203,9 @@ STATIC UINT32 InitPthreadData(pthread_t threadID, pthread_attr_t *userAttr,
|
|||
return LOS_NOK;
|
||||
}
|
||||
userAttr->stacksize = taskCB->stackSize;
|
||||
err = memcpy_s(taskCB->taskName, OS_TCB_NAME_LEN, created->name, strlen(created->name));
|
||||
if (err != EOK) {
|
||||
err = OsSetTaskName(taskCB, created->name, FALSE);
|
||||
if (err != LOS_OK) {
|
||||
PRINT_ERR("%s: %d, err: %d\n", __FUNCTION__, __LINE__, err);
|
||||
taskCB->taskName[0] = '\0';
|
||||
return LOS_NOK;
|
||||
}
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
|
@ -224,7 +223,7 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
|||
{
|
||||
pthread_attr_t userAttr;
|
||||
UINT32 ret;
|
||||
CHAR name[PTHREAD_DATA_NAME_MAX];
|
||||
CHAR name[PTHREAD_DATA_NAME_MAX] = {0};
|
||||
STATIC UINT16 pthreadNumber = 1;
|
||||
TSK_INIT_PARAM_S taskInitParam = {0};
|
||||
UINT32 taskHandle;
|
||||
|
@ -236,7 +235,6 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
|||
|
||||
SetPthreadAttr(self, attr, &userAttr);
|
||||
|
||||
(VOID)memset_s(name, sizeof(name), 0, sizeof(name));
|
||||
(VOID)snprintf_s(name, sizeof(name), sizeof(name) - 1, "pth%02d", pthreadNumber);
|
||||
pthreadNumber++;
|
||||
|
||||
|
|
|
@ -555,9 +555,7 @@ STATIC UINT32 OsCreateIdleProcess(VOID)
|
|||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
OS_TCB_FROM_TID(*idleTaskID)->cpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
|
||||
#endif
|
||||
(VOID)memset_s(OS_TCB_FROM_TID(*idleTaskID)->taskName, OS_TCB_NAME_LEN, 0, OS_TCB_NAME_LEN);
|
||||
(VOID)memcpy_s(OS_TCB_FROM_TID(*idleTaskID)->taskName, OS_TCB_NAME_LEN, idleName, strlen(idleName));
|
||||
return LOS_OK;
|
||||
return (UINT32)OsSetTaskName(OS_TCB_FROM_TID(*idleTaskID), idleName, FALSE);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT VOID OsProcessCBRecyleToFree(VOID)
|
||||
|
@ -653,36 +651,35 @@ STATIC VOID OsDeInitPCB(LosProcessCB *processCB)
|
|||
return;
|
||||
}
|
||||
|
||||
STATIC UINT32 OsSetProcessName(LosProcessCB *processCB, const CHAR *name)
|
||||
UINT32 OsSetProcessName(LosProcessCB *processCB, const CHAR *name)
|
||||
{
|
||||
errno_t errRet;
|
||||
UINT32 len;
|
||||
|
||||
if (name != NULL) {
|
||||
len = strlen(name);
|
||||
if (len >= OS_PCB_NAME_LEN) {
|
||||
len = OS_PCB_NAME_LEN - 1; /* 1: Truncate, reserving the termination operator for character turns */
|
||||
}
|
||||
errRet = memcpy_s(processCB->processName, sizeof(CHAR) * OS_PCB_NAME_LEN, name, len);
|
||||
if (errRet != EOK) {
|
||||
processCB->processName[0] = '\0';
|
||||
return LOS_NOK;
|
||||
}
|
||||
processCB->processName[len] = '\0';
|
||||
return LOS_OK;
|
||||
if (processCB == NULL) {
|
||||
return LOS_EINVAL;
|
||||
}
|
||||
|
||||
if (name != NULL) {
|
||||
errRet = strncpy_s(processCB->processName, OS_PCB_NAME_LEN, name, OS_PCB_NAME_LEN - 1);
|
||||
if (errRet == EOK) {
|
||||
return LOS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
(VOID)memset_s(processCB->processName, sizeof(CHAR) * OS_PCB_NAME_LEN, 0, sizeof(CHAR) * OS_PCB_NAME_LEN);
|
||||
switch (processCB->processMode) {
|
||||
case OS_KERNEL_MODE:
|
||||
(VOID)snprintf_s(processCB->processName, sizeof(CHAR) * OS_PCB_NAME_LEN,
|
||||
(sizeof(CHAR) * OS_PCB_NAME_LEN) - 1, "KerProcess%u", processCB->processID);
|
||||
errRet = snprintf_s(processCB->processName, OS_PCB_NAME_LEN, OS_PCB_NAME_LEN - 1,
|
||||
"KerProcess%u", processCB->processID);
|
||||
break;
|
||||
default:
|
||||
(VOID)snprintf_s(processCB->processName, sizeof(CHAR) * OS_PCB_NAME_LEN,
|
||||
(sizeof(CHAR) * OS_PCB_NAME_LEN) - 1, "UserProcess%u", processCB->processID);
|
||||
errRet = snprintf_s(processCB->processName, OS_PCB_NAME_LEN, OS_PCB_NAME_LEN - 1,
|
||||
"UserProcess%u", processCB->processID);
|
||||
break;
|
||||
}
|
||||
|
||||
if (errRet < 0) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
|
@ -715,12 +712,12 @@ STATIC UINT32 OsInitPCB(LosProcessCB *processCB, UINT32 mode, UINT16 priority, U
|
|||
if (OsProcessIsUserMode(processCB)) {
|
||||
space = LOS_MemAlloc(m_aucSysMem0, sizeof(LosVmSpace));
|
||||
if (space == NULL) {
|
||||
PRINT_ERR("%s %d, alloc space failed\n", __FUNCTION__, __LINE__);
|
||||
PRINT_ERR("Init process struct, alloc space memory failed!\n");
|
||||
return LOS_ENOMEM;
|
||||
}
|
||||
VADDR_T *ttb = LOS_PhysPagesAllocContiguous(1);
|
||||
if (ttb == NULL) {
|
||||
PRINT_ERR("%s %d, alloc ttb or space failed\n", __FUNCTION__, __LINE__);
|
||||
PRINT_ERR("Init process struct, alloc ttb failed!\n");
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, space);
|
||||
return LOS_ENOMEM;
|
||||
}
|
||||
|
@ -728,7 +725,7 @@ STATIC UINT32 OsInitPCB(LosProcessCB *processCB, UINT32 mode, UINT16 priority, U
|
|||
retVal = OsUserVmSpaceInit(space, ttb);
|
||||
vmPage = OsVmVaddrToPage(ttb);
|
||||
if ((retVal == FALSE) || (vmPage == NULL)) {
|
||||
PRINT_ERR("create space failed! ret: %d, vmPage: %#x\n", retVal, vmPage);
|
||||
PRINT_ERR("Init process struct, create space failed!\n");
|
||||
processCB->processStatus = OS_PROCESS_FLAG_UNUSED;
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, space);
|
||||
LOS_PhysPagesFreeContiguous(ttb, 1);
|
||||
|
@ -743,7 +740,6 @@ STATIC UINT32 OsInitPCB(LosProcessCB *processCB, UINT32 mode, UINT16 priority, U
|
|||
#ifdef LOSCFG_SECURITY_VID
|
||||
status = VidMapListInit(processCB);
|
||||
if (status != LOS_OK) {
|
||||
PRINT_ERR("VidMapListInit failed!\n");
|
||||
return LOS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
|
@ -839,7 +835,6 @@ STATIC UINT32 OsProcessCreateInit(LosProcessCB *processCB, UINT32 flags, const C
|
|||
ret = LiteIpcPoolInit(&(processCB->ipcInfo));
|
||||
if (ret != LOS_OK) {
|
||||
ret = LOS_ENOMEM;
|
||||
PRINT_ERR("LiteIpcPoolInit failed!\n");
|
||||
goto EXIT;
|
||||
}
|
||||
}
|
||||
|
@ -1224,7 +1219,7 @@ WAIT_BACK:
|
|||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsWaitRecycleChildPorcess(const LosProcessCB *childCB, UINT32 intSave, INT32 *status)
|
||||
STATIC UINT32 OsWaitRecycleChildPorcess(const LosProcessCB *childCB, UINT32 intSave, INT32 *status)
|
||||
{
|
||||
ProcessGroup *group = NULL;
|
||||
UINT32 pid = childCB->processID;
|
||||
|
@ -1246,7 +1241,7 @@ STATIC INT32 OsWaitRecycleChildPorcess(const LosProcessCB *childCB, UINT32 intSa
|
|||
return pid;
|
||||
}
|
||||
|
||||
STATIC INT32 OsWaitChildProcessCheck(LosProcessCB *processCB, INT32 pid, LosProcessCB **childCB)
|
||||
STATIC UINT32 OsWaitChildProcessCheck(LosProcessCB *processCB, INT32 pid, LosProcessCB **childCB)
|
||||
{
|
||||
if (LOS_ListEmpty(&(processCB->childrenList)) && LOS_ListEmpty(&(processCB->exitChildList))) {
|
||||
return LOS_ECHILD;
|
||||
|
@ -1300,7 +1295,7 @@ LITE_OS_SEC_TEXT INT32 LOS_Wait(INT32 pid, USER INT32 *status, UINT32 options, V
|
|||
}
|
||||
|
||||
if (childCB != NULL) {
|
||||
return OsWaitRecycleChildPorcess(childCB, intSave, status);
|
||||
return (INT32)OsWaitRecycleChildPorcess(childCB, intSave, status);
|
||||
}
|
||||
|
||||
if ((options & LOS_WAIT_WNOHANG) != 0) {
|
||||
|
@ -1325,7 +1320,7 @@ LITE_OS_SEC_TEXT INT32 LOS_Wait(INT32 pid, USER INT32 *status, UINT32 options, V
|
|||
goto ERROR;
|
||||
}
|
||||
|
||||
return OsWaitRecycleChildPorcess(childCB, intSave, status);
|
||||
return (INT32)OsWaitRecycleChildPorcess(childCB, intSave, status);
|
||||
|
||||
ERROR:
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
@ -1372,7 +1367,7 @@ STATIC UINT32 OsSetProcessGroupIDUnsafe(UINT32 pid, UINT32 gid, ProcessGroup **g
|
|||
ProcessGroup *oldGroup = NULL;
|
||||
ProcessGroup *newGroup = NULL;
|
||||
LosProcessCB *processCB = OS_PCB_FROM_PID(pid);
|
||||
INT32 ret = OsSetProcessGroupCheck(processCB, gid);
|
||||
UINT32 ret = OsSetProcessGroupCheck(processCB, gid);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -1445,7 +1440,7 @@ LITE_OS_SEC_TEXT INT32 LOS_GetProcessGroupID(UINT32 pid)
|
|||
goto EXIT;
|
||||
}
|
||||
|
||||
gid = processCB->group->groupID;
|
||||
gid = (INT32)processCB->group->groupID;
|
||||
|
||||
EXIT:
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
@ -1457,10 +1452,9 @@ LITE_OS_SEC_TEXT INT32 LOS_GetCurrProcessGroupID(VOID)
|
|||
return LOS_GetProcessGroupID(OsCurrProcessGet()->processID);
|
||||
}
|
||||
|
||||
STATIC VOID *OsUserInitStackAlloc(UINT32 processID, UINT32 *size)
|
||||
STATIC VOID *OsUserInitStackAlloc(LosProcessCB *processCB, UINT32 *size)
|
||||
{
|
||||
LosVmMapRegion *region = NULL;
|
||||
LosProcessCB *processCB = OS_PCB_FROM_PID(processID);
|
||||
UINT32 stackSize = ALIGN(OS_USER_TASK_STACK_SIZE, PAGE_SIZE);
|
||||
|
||||
region = LOS_RegionAlloc(processCB->vmSpace, 0, stackSize,
|
||||
|
@ -1482,7 +1476,6 @@ LITE_OS_SEC_TEXT UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR
|
|||
LosVmSpace *oldSpace, UINTPTR oldFiles)
|
||||
{
|
||||
UINT32 ret;
|
||||
errno_t errRet;
|
||||
const CHAR *processName = NULL;
|
||||
|
||||
if ((processCB == NULL) || (name == NULL)) {
|
||||
|
@ -1492,20 +1485,14 @@ LITE_OS_SEC_TEXT UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR
|
|||
processName = strrchr(name, '/');
|
||||
processName = (processName == NULL) ? name : (processName + 1); /* 1: Do not include '/' */
|
||||
|
||||
ret = OsSetProcessName(processCB, processName);
|
||||
ret = (UINT32)OsSetTaskName(OsCurrTaskGet(), processName, TRUE);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
errRet = memcpy_s(OsCurrTaskGet()->taskName, OS_TCB_NAME_LEN, processCB->processName, OS_PCB_NAME_LEN);
|
||||
if (errRet != EOK) {
|
||||
OsCurrTaskGet()->taskName[0] = '\0';
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
#if (LOSCFG_KERNEL_LITEIPC == YES)
|
||||
ret = LiteIpcPoolInit(&(processCB->ipcInfo));
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("LiteIpcPoolInit failed!\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
#endif
|
||||
|
@ -1524,7 +1511,6 @@ LITE_OS_SEC_TEXT UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR
|
|||
VidMapDestroy(processCB);
|
||||
ret = VidMapListInit(processCB);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("VidMapListInit failed!\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
#endif
|
||||
|
@ -1538,7 +1524,6 @@ LITE_OS_SEC_TEXT UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR
|
|||
|
||||
LITE_OS_SEC_TEXT UINT32 OsExecStart(const TSK_ENTRY_FUNC entry, UINTPTR sp, UINTPTR mapBase, UINT32 mapSize)
|
||||
{
|
||||
LosProcessCB *processCB = NULL;
|
||||
LosTaskCB *taskCB = NULL;
|
||||
TaskContext *taskContext = NULL;
|
||||
UINT32 intSave;
|
||||
|
@ -1556,10 +1541,8 @@ LITE_OS_SEC_TEXT UINT32 OsExecStart(const TSK_ENTRY_FUNC entry, UINTPTR sp, UINT
|
|||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
processCB = OsCurrProcessGet();
|
||||
taskCB = OsCurrTaskGet();
|
||||
|
||||
processCB->threadGroupID = taskCB->taskID;
|
||||
taskCB->userMapBase = mapBase;
|
||||
taskCB->userMapSize = mapSize;
|
||||
taskCB->taskEntry = (TSK_ENTRY_FUNC)entry;
|
||||
|
@ -1573,37 +1556,95 @@ LITE_OS_SEC_TEXT UINT32 OsExecStart(const TSK_ENTRY_FUNC entry, UINTPTR sp, UINT
|
|||
STATIC UINT32 OsUserInitProcessStart(UINT32 processID, TSK_INIT_PARAM_S *param)
|
||||
{
|
||||
UINT32 intSave;
|
||||
INT32 taskID;
|
||||
UINT32 taskID;
|
||||
INT32 ret;
|
||||
|
||||
taskID = OsCreateUserTask(processID, param);
|
||||
if (taskID < 0) {
|
||||
if (taskID == OS_INVALID_VALUE) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = LOS_SetTaskScheduler(taskID, LOS_SCHED_RR, OS_TASK_PRIORITY_LOWEST);
|
||||
if (ret < 0) {
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("User init process set scheduler failed! ERROR:%d \n", ret);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
(VOID)OsTaskDeleteUnsafe(OS_TCB_FROM_TID(taskID), OS_PRO_EXIT_OK, intSave);
|
||||
return -ret;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsUserInitProcess(VOID)
|
||||
STATIC UINT32 OsLoadUserInit(LosProcessCB *processCB)
|
||||
{
|
||||
/* userInitTextStart -----
|
||||
* | user text |
|
||||
*
|
||||
* | user data | initSize
|
||||
* userInitBssStart ---
|
||||
* | user bss | initBssSize
|
||||
* userInitEnd --- -----
|
||||
*/
|
||||
errno_t errRet;
|
||||
INT32 ret;
|
||||
UINT32 size;
|
||||
TSK_INIT_PARAM_S param = { 0 };
|
||||
VOID *stack = NULL;
|
||||
VOID *userText = NULL;
|
||||
CHAR *userInitTextStart = (CHAR *)&__user_init_entry;
|
||||
CHAR *userInitBssStart = (CHAR *)&__user_init_bss;
|
||||
CHAR *userInitEnd = (CHAR *)&__user_init_end;
|
||||
UINT32 initBssSize = userInitEnd - userInitBssStart;
|
||||
UINT32 initSize = userInitEnd - userInitTextStart;
|
||||
VOID *userBss = NULL;
|
||||
VOID *userText = NULL;
|
||||
|
||||
if ((LOS_Align((UINTPTR)userInitTextStart, PAGE_SIZE) != (UINTPTR)userInitTextStart) ||
|
||||
(LOS_Align((UINTPTR)userInitEnd, PAGE_SIZE) != (UINTPTR)userInitEnd)) {
|
||||
return LOS_EINVAL;
|
||||
}
|
||||
|
||||
if ((initSize == 0) || (initSize <= initBssSize)) {
|
||||
return LOS_EINVAL;
|
||||
}
|
||||
|
||||
userText = LOS_PhysPagesAllocContiguous(initSize >> PAGE_SHIFT);
|
||||
if (userText == NULL) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
errRet = memcpy_s(userText, initSize, (VOID *)&__user_init_load_addr, initSize - initBssSize);
|
||||
if (errRet != EOK) {
|
||||
PRINT_ERR("Load user init text, data and bss failed! err : %d\n", errRet);
|
||||
goto ERROR;
|
||||
}
|
||||
ret = LOS_VaddrToPaddrMmap(processCB->vmSpace, (VADDR_T)(UINTPTR)userInitTextStart, LOS_PaddrQuery(userText),
|
||||
initSize, VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE |
|
||||
VM_MAP_REGION_FLAG_PERM_EXECUTE | VM_MAP_REGION_FLAG_PERM_USER);
|
||||
if (ret < 0) {
|
||||
PRINT_ERR("Mmap user init text, data and bss failed! err : %d\n", ret);
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
/* The User init boot segment may not actually exist */
|
||||
if (initBssSize != 0) {
|
||||
userBss = (VOID *)((UINTPTR)userText + userInitBssStart - userInitTextStart);
|
||||
errRet = memset_s(userBss, initBssSize, 0, initBssSize);
|
||||
if (errRet != EOK) {
|
||||
PRINT_ERR("memset user init bss failed! err : %d\n", errRet);
|
||||
goto ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
|
||||
ERROR:
|
||||
(VOID)LOS_PhysPagesFreeContiguous(userText, initSize >> PAGE_SHIFT);
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsUserInitProcess(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 size;
|
||||
TSK_INIT_PARAM_S param = { 0 };
|
||||
VOID *stack = NULL;
|
||||
|
||||
LosProcessCB *processCB = OS_PCB_FROM_PID(g_userInitProcess);
|
||||
ret = OsProcessCreateInit(processCB, OS_USER_MODE, "Init", OS_PROCESS_USERINIT_PRIORITY);
|
||||
|
@ -1611,30 +1652,18 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsUserInitProcess(VOID)
|
|||
return ret;
|
||||
}
|
||||
|
||||
userText = LOS_PhysPagesAllocContiguous(initSize >> PAGE_SHIFT);
|
||||
if (userText == NULL) {
|
||||
ret = LOS_NOK;
|
||||
ret = OsLoadUserInit(processCB);
|
||||
if (ret != LOS_OK) {
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
(VOID)memcpy_s(userText, initSize, (VOID *)&__user_init_load_addr, initSize);
|
||||
ret = LOS_VaddrToPaddrMmap(processCB->vmSpace, (VADDR_T)(UINTPTR)userInitTextStart, LOS_PaddrQuery(userText),
|
||||
initSize, VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE |
|
||||
VM_MAP_REGION_FLAG_PERM_EXECUTE | VM_MAP_REGION_FLAG_PERM_USER);
|
||||
if (ret < 0) {
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
(VOID)memset_s((VOID *)((UINTPTR)userText + userInitBssStart - userInitTextStart), initBssSize, 0, initBssSize);
|
||||
|
||||
stack = OsUserInitStackAlloc(g_userInitProcess, &size);
|
||||
stack = OsUserInitStackAlloc(processCB, &size);
|
||||
if (stack == NULL) {
|
||||
PRINTK("user init process malloc user stack failed!\n");
|
||||
ret = LOS_NOK;
|
||||
PRINT_ERR("Alloc user init process user stack failed!\n");
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
param.pfnTaskEntry = (TSK_ENTRY_FUNC)userInitTextStart;
|
||||
param.pfnTaskEntry = (TSK_ENTRY_FUNC)(CHAR *)&__user_init_entry;
|
||||
param.userParam.userSP = (UINTPTR)stack + size;
|
||||
param.userParam.userMapBase = (UINTPTR)stack;
|
||||
param.userParam.userMapSize = size;
|
||||
|
@ -1648,7 +1677,6 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsUserInitProcess(VOID)
|
|||
return LOS_OK;
|
||||
|
||||
ERROR:
|
||||
(VOID)LOS_PhysPagesFreeContiguous(userText, initSize >> PAGE_SHIFT);
|
||||
OsDeInitPCB(processCB);
|
||||
return ret;
|
||||
}
|
||||
|
@ -1855,7 +1883,7 @@ STATIC UINT32 OsChildSetProcessGroupAndSched(LosProcessCB *child, LosProcessCB *
|
|||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsCopyProcessResources(UINT32 flags, LosProcessCB *child, LosProcessCB *run)
|
||||
STATIC UINT32 OsCopyProcessResources(UINT32 flags, LosProcessCB *child, LosProcessCB *run)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
#if (LOSCFG_KERNEL_LITEIPC == YES)
|
||||
#include "hm_liteipc.h"
|
||||
#endif
|
||||
#include "user_copy.h"
|
||||
#include "los_strncpy_from_user.h"
|
||||
#include "los_vm_syscall.h"
|
||||
#ifdef LOSCFG_ENABLE_OOM_LOOP_TASK
|
||||
#include "los_oom.h"
|
||||
|
@ -107,7 +107,6 @@ VOID OsSetMainTask()
|
|||
{
|
||||
UINT32 i;
|
||||
CHAR *name = "osMain";
|
||||
errno_t ret;
|
||||
|
||||
for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
|
||||
g_mainTask[i].taskStatus = OS_TASK_STATUS_UNUSED;
|
||||
|
@ -117,10 +116,7 @@ VOID OsSetMainTask()
|
|||
g_mainTask[i].lockDep.lockDepth = 0;
|
||||
g_mainTask[i].lockDep.waitLock = NULL;
|
||||
#endif
|
||||
ret = memcpy_s(g_mainTask[i].taskName, OS_TCB_NAME_LEN, name, strlen(name));
|
||||
if (ret != EOK) {
|
||||
g_mainTask[i].taskName[0] = '\0';
|
||||
}
|
||||
(VOID)strncpy_s(g_mainTask[i].taskName, OS_TCB_NAME_LEN, name, OS_TCB_NAME_LEN - 1);
|
||||
LOS_ListInit(&g_mainTask[i].lockList);
|
||||
}
|
||||
}
|
||||
|
@ -702,7 +698,6 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskCBInitBase(LosTaskCB *taskCB,
|
|||
#endif
|
||||
#if (LOSCFG_KERNEL_LITEIPC == YES)
|
||||
LOS_ListInit(&(taskCB->msgListHead));
|
||||
(VOID)memset_s(taskCB->accessMap, sizeof(taskCB->accessMap), 0, sizeof(taskCB->accessMap));
|
||||
#endif
|
||||
taskCB->policy = (initParam->policy == LOS_SCHED_FIFO) ? LOS_SCHED_FIFO : LOS_SCHED_RR;
|
||||
taskCB->taskStatus = OS_TASK_STATUS_INIT;
|
||||
|
@ -717,8 +712,8 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskCBInitBase(LosTaskCB *taskCB,
|
|||
LOS_ListInit(&taskCB->lockList);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsTaskCBInit(LosTaskCB *taskCB, const TSK_INIT_PARAM_S *initParam,
|
||||
const VOID *stackPtr, const VOID *topStack)
|
||||
STATIC UINT32 OsTaskCBInit(LosTaskCB *taskCB, const TSK_INIT_PARAM_S *initParam,
|
||||
const VOID *stackPtr, const VOID *topStack)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 ret;
|
||||
|
@ -749,20 +744,16 @@ LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsTaskCBInit(LosTaskCB *taskCB, const TSK_IN
|
|||
processCB->threadCount++;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
if (initParam->pcName == NULL) {
|
||||
(VOID)memset_s(taskCB->taskName, sizeof(CHAR) * OS_TCB_NAME_LEN, 0, sizeof(CHAR) * OS_TCB_NAME_LEN);
|
||||
(VOID)snprintf_s(taskCB->taskName, sizeof(CHAR) * OS_TCB_NAME_LEN,
|
||||
(sizeof(CHAR) * OS_TCB_NAME_LEN) - 1, "thread%u", numCount);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (mode == OS_KERNEL_MODE) {
|
||||
ret = memcpy_s(taskCB->taskName, sizeof(CHAR) * OS_TCB_NAME_LEN, initParam->pcName, strlen(initParam->pcName));
|
||||
if (ret != EOK) {
|
||||
taskCB->taskName[0] = '\0';
|
||||
if (initParam->pcName != NULL) {
|
||||
ret = (UINT32)OsSetTaskName(taskCB, initParam->pcName, FALSE);
|
||||
if (ret == LOS_OK) {
|
||||
return LOS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
if (snprintf_s(taskCB->taskName, OS_TCB_NAME_LEN, OS_TCB_NAME_LEN - 1, "thread%u", numCount) < 0) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
|
@ -1644,54 +1635,46 @@ EXIT:
|
|||
return INT_NO_RESCH;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT INT32 OsSetCurrTaskName(const CHAR *name)
|
||||
LITE_OS_SEC_TEXT INT32 OsSetTaskName(LosTaskCB *taskCB, const CHAR *name, BOOL setPName)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 strLen;
|
||||
errno_t err;
|
||||
LosTaskCB *runTask = NULL;
|
||||
LosProcessCB *runProcess = NULL;
|
||||
LosProcessCB *processCB = NULL;
|
||||
const CHAR *namePtr = NULL;
|
||||
CHAR nameBuff[OS_TCB_NAME_LEN] = { 0 };
|
||||
|
||||
runTask = OsCurrTaskGet();
|
||||
runProcess = OS_PCB_FROM_PID(runTask->processID);
|
||||
if (runProcess->processMode == OS_USER_MODE) {
|
||||
(VOID)LOS_ArchCopyFromUser(nameBuff, (const VOID *)name, OS_TCB_NAME_LEN);
|
||||
strLen = strnlen(nameBuff, OS_TCB_NAME_LEN);
|
||||
namePtr = nameBuff;
|
||||
} else {
|
||||
strLen = strnlen(name, OS_TCB_NAME_LEN);
|
||||
namePtr = name;
|
||||
if ((taskCB == NULL) || (name == NULL)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (strLen == 0) {
|
||||
err = EINVAL;
|
||||
PRINT_ERR("set task(%u) name failed! %d\n", OsCurrTaskGet()->taskID, err);
|
||||
return err;
|
||||
} else if (strLen == OS_TCB_NAME_LEN) {
|
||||
strLen = strLen - 1;
|
||||
if (LOS_IsUserAddress((VADDR_T)(UINTPTR)name)) {
|
||||
err = LOS_StrncpyFromUser(nameBuff, (const CHAR *)name, OS_TCB_NAME_LEN);
|
||||
if (err < 0) {
|
||||
return -err;
|
||||
}
|
||||
namePtr = nameBuff;
|
||||
} else {
|
||||
namePtr = name;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
|
||||
err = memcpy_s(runTask->taskName, OS_TCB_NAME_LEN, (VOID *)namePtr, strLen);
|
||||
err = strncpy_s(taskCB->taskName, OS_TCB_NAME_LEN, (VOID *)namePtr, OS_TCB_NAME_LEN - 1);
|
||||
if (err != EOK) {
|
||||
runTask->taskName[0] = '\0';
|
||||
err = EINVAL;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
runTask->taskName[strLen] = '\0';
|
||||
|
||||
err = LOS_OK;
|
||||
processCB = OS_PCB_FROM_PID(taskCB->processID);
|
||||
/* if thread is main thread, then set processName as taskName */
|
||||
if (runTask->taskID == runProcess->threadGroupID) {
|
||||
(VOID)memcpy_s(runProcess->processName, OS_PCB_NAME_LEN, (VOID *)runTask->taskName, OS_TCB_NAME_LEN);
|
||||
if ((taskCB->taskID == processCB->threadGroupID) && (setPName == TRUE)) {
|
||||
err = (INT32)OsSetProcessName(processCB, (const CHAR *)taskCB->taskName);
|
||||
if (err != LOS_OK) {
|
||||
err = EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
|
||||
EXIT:
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return err;
|
||||
|
@ -1747,6 +1730,7 @@ LITE_OS_SEC_TEXT VOID OsTaskExitGroup(UINT32 status)
|
|||
(VOID)OsTaskSyncWait(runTask[cpu]);
|
||||
}
|
||||
#endif
|
||||
processCB->threadGroupID = OsCurrTaskGet()->taskID;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
LOS_ASSERT(processCB->threadNumber == 1);
|
||||
|
@ -1838,7 +1822,7 @@ LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsCreateUserTaskParamCheck(UINT32 processID,
|
|||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT INT32 OsCreateUserTask(UINT32 processID, TSK_INIT_PARAM_S *initParam)
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsCreateUserTask(UINT32 processID, TSK_INIT_PARAM_S *initParam)
|
||||
{
|
||||
LosProcessCB *processCB = NULL;
|
||||
UINT32 taskID;
|
||||
|
|
|
@ -479,6 +479,7 @@ extern VOID OsWaitSignalToWakeProcess(LosProcessCB *processCB);
|
|||
extern UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR *name,
|
||||
LosVmSpace *oldAspace, UINTPTR oldFiles);
|
||||
extern UINT32 OsExecStart(const TSK_ENTRY_FUNC entry, UINTPTR sp, UINTPTR mapBase, UINT32 mapSize);
|
||||
extern UINT32 OsSetProcessName(LosProcessCB *processCB, const CHAR *name);
|
||||
extern INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 prio, UINT16 policy, BOOL policyFlag);
|
||||
extern INT32 OsGetProcessPriority(INT32 which, INT32 pid);
|
||||
extern VOID *OsUserStackAlloc(UINT32 processID, UINT32 *size);
|
||||
|
|
|
@ -566,10 +566,10 @@ extern UINT32 OsTaskDeleteUnsafe(LosTaskCB *taskCB, UINT32 status, UINT32 intSav
|
|||
extern VOID OsTaskResourcesToFree(LosTaskCB *taskCB);
|
||||
extern VOID OsRunTaskToDelete(LosTaskCB *taskCB);
|
||||
extern UINT32 OsTaskSyncWait(const LosTaskCB *taskCB);
|
||||
extern INT32 OsCreateUserTask(UINT32 processID, TSK_INIT_PARAM_S *initParam);
|
||||
extern UINT32 OsCreateUserTask(UINT32 processID, TSK_INIT_PARAM_S *initParam);
|
||||
extern INT32 OsTaskSchedulerSetUnsafe(LosTaskCB *taskCB, UINT16 policy, UINT16 priority,
|
||||
BOOL policyFlag, UINT32 intSave);
|
||||
extern INT32 OsSetCurrTaskName(const CHAR *name);
|
||||
extern INT32 OsSetTaskName(LosTaskCB *taskCB, const CHAR *name, BOOL setPName);
|
||||
extern VOID OsTaskCBRecyleToFree(VOID);
|
||||
extern VOID OsTaskExitGroup(UINT32 status);
|
||||
extern VOID OsTaskToExit(LosTaskCB *taskCB, UINT32 status);
|
||||
|
|
|
@ -1342,7 +1342,12 @@ int SysPrctl(int option, ...)
|
|||
}
|
||||
|
||||
name = va_arg(ap, unsigned long);
|
||||
err = OsSetCurrTaskName((const char *)(uintptr_t)name);
|
||||
if (!LOS_IsUserAddress(name)) {
|
||||
err = EFAULT;
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
err = OsSetTaskName(OsCurrTaskGet(), (const char *)(uintptr_t)name, TRUE);
|
||||
if (err != LOS_OK) {
|
||||
goto ERROR;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue