提交 4ff3c4bf 编写于 作者: Z zhushengle 提交者: z00451061

Description:Process security function rectification.

Reviewed-by:liulei, lihao, likailong

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