66#ifdef LOSCFG_SECURITY_VID
69#ifdef LOSCFG_SECURITY_CAPABILITY
72#ifdef LOSCFG_KERNEL_DYNLOAD
122 SCHEDULER_LOCK(intSave);
139#ifdef LOSCFG_KERNEL_VM
149 SCHEDULER_UNLOCK(intSave);
172 processCB = OS_PCB_FROM_PID(pid);
174 processCB->
group = group;
191 groupProcessCB->
processStatus &= ~OS_PROCESS_FLAG_GROUP_LEADER;
192 *group = processCB->
group;
199 processCB->
group = NULL;
216 PRINT_INFO(
"%s failed! group id = %u\n", __FUNCTION__, gid);
223 INT32 ret, success, err;
238 return success ? LOS_OK : ret;
244 INT32 ret, success, err;
258 return success ? LOS_OK : ret;
281 if ((childCB->
processID == pid) || (pid == OS_INVALID_VALUE)) {
286 PRINT_INFO(
"%s find exit process : %d failed in group : %u\n", __FUNCTION__, pid, group->
groupID);
306 PRINT_INFO(
"%s is find the child : %d failed in parent : %u\n", __FUNCTION__, childPid, processCB->
processID);
316 if ((childPid == OS_INVALID_VALUE) || (exitChild->
processID == childPid)) {
321 PRINT_INFO(
"%s is find the exit child : %d failed in parent : %u\n", __FUNCTION__, childPid, processCB->
processID);
330#ifdef LOSCFG_KERNEL_SMP
343 while (list->
pstNext != head) {
344 taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(list));
350 pid = OS_INVALID_VALUE;
357 if (taskCB->
waitFlag != OS_PROCESS_WAIT_PRO) {
373 BOOL findSpecified = FALSE;
380 if (findSpecified == TRUE) {
398 if (findSpecified == TRUE) {
399 while (list->
pstNext != head) {
400 taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(list));
406 while (list->
pstNext != head) {
407 taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(list));
408 if (taskCB->
waitFlag == OS_PROCESS_WAIT_GID) {
415 if (findSpecified == FALSE) {
417 findSpecified = TRUE;
433#ifdef LOSCFG_KERNEL_VM
442 processCB->
files = NULL;
445#ifdef LOSCFG_SECURITY_CAPABILITY
446 if (processCB->
user != NULL) {
448 processCB->
user = NULL;
455#ifdef LOSCFG_SECURITY_VID
462#ifdef LOSCFG_KERNEL_LITEIPC
466#ifdef LOSCFG_KERNEL_CPUP
469 SCHEDULER_LOCK(intSave);
471 SCHEDULER_UNLOCK(intSave);
495 }
else if (childCB->
processStatus & OS_PROCESS_FLAG_GROUP_LEADER) {
520 for (nextList = childHead; ;) {
521 childCB = OS_PCB_FROM_SIBLIST(nextList);
524 if (nextList == childHead) {
529 parentCB = OS_PCB_FROM_PID(parentID);
574#ifdef LOSCFG_KERNEL_VM
630 SCHEDULER_LOCK(intSave);
637 SCHEDULER_UNLOCK(intSave);
641 SCHEDULER_LOCK(intSave);
643#ifdef LOSCFG_KERNEL_VM
654 if ((processCB->
processStatus & OS_PROCESS_FLAG_GROUP_LEADER) ||
661#ifdef LOSCFG_KERNEL_VM
662 SCHEDULER_UNLOCK(intSave);
664 SCHEDULER_LOCK(intSave);
668 SCHEDULER_UNLOCK(intSave);
677 if (processCB == NULL) {
683 SCHEDULER_LOCK(intSave);
689 if (processCB->
group != NULL) {
696 SCHEDULER_UNLOCK(intSave);
708 if (processCB == NULL) {
713 errRet = strncpy_s(processCB->
processName, OS_PCB_NAME_LEN, name, OS_PCB_NAME_LEN - 1);
721 errRet = snprintf_s(processCB->
processName, OS_PCB_NAME_LEN, OS_PCB_NAME_LEN - 1,
725 errRet = snprintf_s(processCB->
processName, OS_PCB_NAME_LEN, OS_PCB_NAME_LEN - 1,
743 processCB->
umask = OS_PROCESS_DEFAULT_UMASK;
751#ifdef LOSCFG_KERNEL_VM
754 if (processCB->
vmSpace == NULL) {
763#ifdef LOSCFG_KERNEL_CPUP
770#ifdef LOSCFG_SECURITY_VID
772 if (status != LOS_OK) {
776#ifdef LOSCFG_SECURITY_CAPABILITY
787#ifdef LOSCFG_SECURITY_CAPABILITY
811 SCHEDULER_LOCK(intSave);
813 for (count = 0; count < user->
groupNumber; count++) {
814 if (user->
groups[count] == gid) {
815 SCHEDULER_UNLOCK(intSave);
820 SCHEDULER_UNLOCK(intSave);
828#ifdef LOSCFG_SECURITY_CAPABILITY
832 SCHEDULER_LOCK(intSave);
834 SCHEDULER_UNLOCK(intSave);
844#ifdef LOSCFG_SECURITY_CAPABILITY
848 SCHEDULER_LOCK(intSave);
850 SCHEDULER_UNLOCK(intSave);
869 if (processCB->
files == NULL) {
881#ifdef LOSCFG_SECURITY_CAPABILITY
883 if (processCB->
user == NULL) {
914 ret =
OsInitPCB(idleProcess, OS_KERNEL_MODE,
"KIdle");
922#ifdef LOSCFG_SECURITY_CAPABILITY
923 idleProcess->
user = kerInitProcess->
user;
941 if (OS_PID_CHECK_INVALID(pid)) {
945 if (which != LOS_PRIO_PROCESS) {
949 if (prio > OS_PROCESS_PRIORITY_LOWEST) {
953 if (policy != LOS_SCHED_RR) {
960#ifdef LOSCFG_SECURITY_CAPABILITY
994 SCHEDULER_LOCK(intSave);
1000#ifdef LOSCFG_SECURITY_CAPABILITY
1012 SCHEDULER_UNLOCK(intSave);
1015 if (needSched && OS_SCHEDULER_ACTIVE) {
1021 SCHEDULER_UNLOCK(intSave);
1034 if (OS_PID_CHECK_INVALID(pid)) {
1038 SCHEDULER_LOCK(intSave);
1041 SCHEDULER_UNLOCK(intSave);
1045 SCHEDULER_UNLOCK(intSave);
1047 return LOS_SCHED_RR;
1061 if (OS_PID_CHECK_INVALID(pid)) {
1065 if (which != LOS_PRIO_PROCESS) {
1070 SCHEDULER_LOCK(intSave);
1072 SCHEDULER_UNLOCK(intSave);
1079 SCHEDULER_UNLOCK(intSave);
1098 if (runTask->
waitFlag == OS_PROCESS_WAIT_GID) {
1099 while (list->
pstNext != head) {
1100 taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(list));
1101 if (taskCB->
waitFlag == OS_PROCESS_WAIT_PRO) {
1107 }
else if (runTask->
waitFlag == OS_PROCESS_WAIT_ANY) {
1108 while (list->
pstNext != head) {
1109 taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(list));
1110 if (taskCB->
waitFlag != OS_PROCESS_WAIT_ANY) {
1120 (VOID)runTask->
ops->
wait(runTask, list->
pstNext, LOS_WAIT_FOREVER);
1134 if (childCB != NULL) {
1139 if (ret != LOS_OK) {
1142 runTask->
waitFlag = OS_PROCESS_WAIT_PRO;
1144 }
else if (pid == 0) {
1147 if (childCB != NULL) {
1151 runTask->
waitFlag = OS_PROCESS_WAIT_GID;
1152 }
else if (pid == -1) {
1155 if (childCB != NULL) {
1159 runTask->
waitFlag = OS_PROCESS_WAIT_ANY;
1163 if (group == NULL) {
1168 if (childCB != NULL) {
1173 runTask->
waitFlag = OS_PROCESS_WAIT_GID;
1189#ifdef LOSCFG_SECURITY_CAPABILITY
1190 if (childCB->
user != NULL) {
1196 SCHEDULER_UNLOCK(intSave);
1198 if (status != NULL) {
1199 if (mode == OS_USER_MODE) {
1207 siginfo_t tempinfo = { 0 };
1209 tempinfo.si_signo = SIGCHLD;
1210 tempinfo.si_errno = 0;
1211 tempinfo.si_pid = pid;
1212 tempinfo.si_uid = uid;
1218 if ((exitCode & 0x7f) == 0) {
1219 tempinfo.si_code = CLD_EXITED;
1220 tempinfo.si_status = (exitCode >> 8U);
1222 tempinfo.si_code = (exitCode & 0x80) ? CLD_DUMPED : CLD_KILLED;
1223 tempinfo.si_status = (exitCode & 0x7f);
1226 if (mode == OS_USER_MODE) {
1227 (VOID)
LOS_ArchCopyToUser((VOID *)(info), (
const VOID *)(&(tempinfo)),
sizeof(siginfo_t));
1229 (VOID)memcpy_s((VOID *)(info),
sizeof(siginfo_t), (
const VOID *)(&(tempinfo)),
sizeof(siginfo_t));
1247 UINT32 flag = LOS_WAIT_WNOHANG | LOS_WAIT_WUNTRACED | LOS_WAIT_WCONTINUED;
1249 flag = ~flag & options;
1254 if ((options & (LOS_WAIT_WCONTINUED | LOS_WAIT_WUNTRACED)) != 0) {
1255 return LOS_EOPNOTSUPP;
1258 if (OS_INT_ACTIVE) {
1274 SCHEDULER_LOCK(intSave);
1276 if (ret != LOS_OK) {
1281 if (childCB != NULL) {
1285 if ((options & LOS_WAIT_WNOHANG) != 0) {
1295 if (runTask->
waitID == OS_INVALID_VALUE) {
1300 childCB = OS_PCB_FROM_PID(runTask->
waitID);
1301 if (!(childCB->
processStatus & OS_PROCESS_STATUS_ZOMBIES)) {
1309 SCHEDULER_UNLOCK(intSave);
1319 if (ret != LOS_OK) {
1323 return OsWait(pid, status, NULL, options, NULL);
1328 UINT32 flag = LOS_WAIT_WNOHANG | LOS_WAIT_WSTOPPED | LOS_WAIT_WCONTINUED | LOS_WAIT_WEXITED | LOS_WAIT_WNOWAIT;
1330 flag = ~flag & options;
1331 if ((flag != 0) || (options == 0)) {
1339 if ((options & (LOS_WAIT_WSTOPPED | LOS_WAIT_WCONTINUED | LOS_WAIT_WNOWAIT)) != 0) {
1340 return LOS_EOPNOTSUPP;
1343 if (OS_INT_ACTIVE) {
1357 if (ret != LOS_OK) {
1361 return OsWait(pid, NULL, info, options, NULL);
1379 if (processCB->
processStatus & OS_PROCESS_FLAG_ALREADY_EXEC) {
1388 if (!(groupProcessCB->
processStatus & OS_PROCESS_FLAG_GROUP_LEADER)) {
1406 if (ret != LOS_OK) {
1414 oldGroup = processCB->
group;
1418 if (newGroup != NULL) {
1420 processCB->
group = newGroup;
1425 if (newGroup == NULL) {
1427 processCB->
group = oldGroup;
1428 if (*group != NULL) {
1430 processCB = OS_PCB_FROM_PID(oldGroup->
groupID);
1445 if ((OS_PID_CHECK_INVALID(pid)) || (OS_PID_CHECK_INVALID(gid))) {
1449 SCHEDULER_LOCK(intSave);
1451 SCHEDULER_UNLOCK(intSave);
1467 if (OS_PID_CHECK_INVALID(pid)) {
1471 SCHEDULER_LOCK(intSave);
1472 processCB = OS_PCB_FROM_PID(pid);
1481 SCHEDULER_UNLOCK(intSave);
1490#ifdef LOSCFG_KERNEL_VM
1496 SCHEDULER_LOCK(intSave);
1498 SCHEDULER_UNLOCK(intSave);
1499 PRINT_ERR(
"No idle PCB in the system!\n");
1503 processCB = OS_PCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&
g_freeProcess));
1505 SCHEDULER_UNLOCK(intSave);
1516 VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_READ |
1517 VM_MAP_REGION_FLAG_PERM_WRITE, 0);
1518 if (region == NULL) {
1530#ifdef LOSCFG_KERNEL_DYNLOAD
1536 processCB->
vmSpace = oldSpace;
1550 processCB->
vmSpace = newSpace;
1572 const CHAR *processName = NULL;
1574 if ((processCB == NULL) || (name == NULL)) {
1578 processName = strrchr(name,
'/');
1579 processName = (processName == NULL) ? name : (processName + 1);
1582 if (ret != LOS_OK) {
1586#ifdef LOSCFG_KERNEL_LITEIPC
1602#ifdef LOSCFG_SECURITY_VID
1605 if (ret != LOS_OK) {
1620 if (entry == NULL) {
1624 if ((
sp == 0) || (
LOS_Align(
sp, LOSCFG_STACK_POINT_ALIGN_SIZE) !=
sp)) {
1628 if ((mapBase == 0) || (mapSize == 0) || (
sp <= mapBase) || (
sp > (mapBase + mapSize))) {
1633 SCHEDULER_LOCK(intSave);
1643 SCHEDULER_UNLOCK(intSave);
1654 if (taskID == OS_INVALID_VALUE) {
1659 if (ret != LOS_OK) {
1660 PRINT_ERR(
"User init process set priority failed! ERROR:%d \n", ret);
1664 SCHEDULER_LOCK(intSave);
1666 SCHEDULER_UNLOCK(intSave);
1669 if (ret != LOS_OK) {
1670 PRINT_ERR(
"User init process set scheduler failed! ERROR:%d \n", ret);
1696 UINT32 initBssSize = userInitEnd - userInitBssStart;
1697 UINT32 initSize = userInitEnd - userInitTextStart;
1698 VOID *userBss = NULL;
1699 VOID *userText = NULL;
1706 if ((initSize == 0) || (initSize <= initBssSize)) {
1711 if (userText == NULL) {
1716 if (errRet != EOK) {
1717 PRINT_ERR(
"Load user init text, data and bss failed! err : %d\n", errRet);
1721 initSize, VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE |
1722 VM_MAP_REGION_FLAG_FIXED | VM_MAP_REGION_FLAG_PERM_EXECUTE |
1723 VM_MAP_REGION_FLAG_PERM_USER);
1725 PRINT_ERR(
"Mmap user init text, data and bss failed! err : %d\n", ret);
1730 if (initBssSize != 0) {
1731 userBss = (VOID *)((
UINTPTR)userText + userInitBssStart - userInitTextStart);
1732 errRet = memset_s(userBss, initBssSize, 0, initBssSize);
1733 if (errRet != EOK) {
1734 PRINT_ERR(
"memset user init bss failed! err : %d\n", errRet);
1755 if (ret != LOS_OK) {
1760 if (ret != LOS_OK) {
1765 if (stack == NULL) {
1766 PRINT_ERR(
"Alloc user init process user stack failed!\n");
1774 param.
uwResved = OS_TASK_FLAG_PTHREAD_JOIN;
1776 if (ret != LOS_OK) {
1790#ifdef LOSCFG_SECURITY_CAPABILITY
1793 if (childCB->
user == NULL) {
1797 (VOID)memcpy_s(childCB->
user, size, parentCB->
user, size);
1807 UINT32 ret, taskID, intSave;
1810 SCHEDULER_LOCK(intSave);
1821 if (runTask->
taskStatus & OS_TASK_FLAG_PTHREAD_JOIN) {
1822 taskParam.
uwResved = LOS_TASK_ATTR_JOINABLE;
1826 SCHEDULER_UNLOCK(intSave);
1834 if (ret != LOS_OK) {
1835 if (ret == LOS_ERRNO_TSK_TCB_UNAVAILABLE) {
1841 LosTaskCB *childTaskCB = OS_TCB_FROM_TID(taskID);
1844 if (childTaskCB->
taskStatus & OS_TASK_STATUS_RUNNING) {
1845 childTaskCB->
taskStatus &= ~OS_TASK_STATUS_RUNNING;
1847 if (OS_SCHEDULER_ACTIVE) {
1848 LOS_Panic(
"Clone thread status not running error status: 0x%x\n", childTaskCB->
taskStatus);
1850 childTaskCB->
taskStatus &= ~OS_TASK_STATUS_UNUSED;
1854 SCHEDULER_LOCK(intSave);
1856 SCHEDULER_UNLOCK(intSave);
1867 SCHEDULER_LOCK(intSave);
1869 if (flags & CLONE_PARENT) {
1872 parentProcessCB = runProcessCB;
1877 childProcessCB->
group = parentProcessCB->
group;
1879 ret =
OsCopyUser(childProcessCB, parentProcessCB);
1881 SCHEDULER_UNLOCK(intSave);
1894 if (flags & CLONE_VM) {
1895 SCHEDULER_LOCK(intSave);
1898 SCHEDULER_UNLOCK(intSave);
1903 if (status != LOS_OK) {
1912 if (flags & CLONE_FILES) {
1917 if (childProcessCB->
files == NULL) {
1933 if (ret != LOS_OK) {
1938 if (ret != LOS_OK) {
1952 SCHEDULER_LOCK(intSave);
1953 if (run->
group->
groupID == OS_USER_PRIVILEGE_PROCESS_GROUP) {
1955 if (ret != LOS_OK) {
1956 SCHEDULER_UNLOCK(intSave);
1963 SCHEDULER_UNLOCK(intSave);
1974 if (ret != LOS_OK) {
1979 if (ret != LOS_OK) {
1983#ifdef LOSCFG_KERNEL_LITEIPC
1992#ifdef LOSCFG_SECURITY_CAPABILITY
2005 if (child == NULL) {
2011 if (ret != LOS_OK) {
2016 if (ret != LOS_OK) {
2021 if (ret != LOS_OK) {
2026 if (OS_SCHEDULER_ACTIVE) {
2051 UINT32 cloneFlag = CLONE_PARENT | CLONE_THREAD | CLONE_VFORK | CLONE_VM;
2053 if (flags & (~cloneFlag)) {
2054 PRINT_WARN(
"Clone dont support some flags!\n");
2062 UINT32 cloneFlag = CLONE_PARENT | CLONE_THREAD | CLONE_VFORK | CLONE_FILES;
2064 if (flags & (~cloneFlag)) {
2065 PRINT_WARN(
"Clone dont support some flags!\n");
2068 flags |= CLONE_FILES;
2093 SCHEDULER_LOCK(intSave);
2095 SCHEDULER_UNLOCK(intSave);
2096 PRINT_ERR(
"Kernel-state processes with multiple threads are not allowed to exit directly\n");
2099 SCHEDULER_UNLOCK(intSave);
2122 if (pidList == NULL) {
2125 SCHEDULER_LOCK(intSave);
2127 pcb = OS_PCB_FROM_PID(pid);
2134 if (num >= pidMaxNum) {
2138 SCHEDULER_UNLOCK(intSave);
2148 if (OS_PID_CHECK_INVALID(pid)) {
2151 pcb = OS_PCB_FROM_PID(pid);
2153 if (files == NULL) {
2166#ifdef LOSCFG_KERNEL_VM
2171 taskCB->
taskStatus |= OS_TASK_FLAG_EXIT_KILL;
2172#ifdef LOSCFG_KERNEL_SMP
2175 taskCB->
signal = SIGNAL_KILL;
2181 if (ret != LOS_OK) {
2182 PRINT_ERR(
"pid %u exit, Exit task group %u kill %u failed! ERROR: %d\n",
2187 if (!(taskCB->
taskStatus & OS_TASK_FLAG_PTHREAD_JOIN)) {
2188 taskCB->
taskStatus |= OS_TASK_FLAG_PTHREAD_JOIN;
2193 if (ret != LOS_OK) {
2194 PRINT_ERR(
"pid %u exit, Exit task group %u to wait others task %u(0x%x) exit failed! ERROR: %d\n",
2202#ifdef LOSCFG_KERNEL_VM
2207 SCHEDULER_LOCK(intSave);
2209 SCHEDULER_UNLOCK(intSave);
2222 !(taskCB->
taskStatus & OS_TASK_STATUS_RUNNING)) {
2224 }
else if (taskCB != currTask) {
2230 }
while (head != list->
pstNext);
2232 SCHEDULER_UNLOCK(intSave);
macro EXC_SP_SET stackSize
macro EXC_SP_SET reg1 mrc 获取CPU信息 and mov mul reg0 计算当前CPU栈的偏移位置 ldr reg1 相减得到栈顶 mov sp
BOOL IsCapPermit(UINT32 capIndex)
VOID OsInitCapability(LosProcessCB *processCB)
初始化进程安全能力
VOID OsCopyCapability(LosProcessCB *from, LosProcessCB *to)
进程间安全能力的拷贝
struct files_struct * dup_fd(struct files_struct *oldf)
复制FD
void delete_files_snapshot(struct files_struct *files)
删除文件管理器快照
struct ProcessCB LosProcessCB
void delete_files(struct files_struct *files)
删除参数进程的文件管理器
struct files_struct * alloc_files(void)
为进程分配文件管理器,其中包含fd总数,(0,1,2)默认给了stdin,stdout,stderr
void CloseOnExec(struct files_struct *files)
LITE_OS_SEC_TEXT UINTPTR LOS_Align(UINTPTR addr, UINT32 boundary)
Align the value (addr) by some bytes (boundary) you specify.
NORETURN VOID LOS_Panic(const CHAR *fmt,...)
Kernel panic function.
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListTailInsert(LOS_DL_LIST *list, LOS_DL_LIST *node)
Insert a node to the tail of a doubly linked list.
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListHeadInsert(LOS_DL_LIST *list, LOS_DL_LIST *node)
Insert a node to the head of a doubly linked list.
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListTailInsertList(LOS_DL_LIST *oldList, LOS_DL_LIST *newList)
Insert a doubly list to the tail of a doubly linked list.
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelete(LOS_DL_LIST *node)
LITE_OS_SEC_ALW_INLINE STATIC INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *list)
Identify whether a specified doubly linked list is empty. | 判断链表是否为空
VOID * LOS_MemAlloc(VOID *pool, UINT32 size)
从指定内存池中申请size长度的内存,注意这可不是从内核堆空间中申请内存
UINT8 * m_aucSysMem1
系统动态内存池地址的起始地址 @note_thinking 能否不要用 0,1来命名核心变量 ???
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
释放从指定动态内存中申请的内存
UINT8 * m_aucSysMem0
异常交互动态内存池地址的起始地址,当不支持异常交互特性时,m_aucSysMem0等于m_aucSysMem1。
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID)
Delete a task.
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreateOnly(UINT32 *taskID, TSK_INIT_PARAM_S *initParam)
LOS_TaskCreateOnly 创建任务,并使该任务进入suspend状态,不对该任务进行调度。如果需要调度,可以调用LOS_TaskResume使该任务进入ready状态
LITE_OS_SEC_TEXT INT32 LOS_SetTaskScheduler(INT32 taskID, UINT16 policy, UINT16 priority)
Set the scheduling policy and priority for the task.
VOID LOS_Schedule(VOID)
Trigger active task scheduling.
VOID *(* TSK_ENTRY_FUNC)(UINTPTR param1, UINTPTR param2, UINTPTR param3, UINTPTR param4)
Define the type of a task entrance function.
LITE_OS_SEC_TEXT ProcIpcInfo * LiteIpcPoolReInit(const ProcIpcInfo *parent)
LiteIpcPoolReInit 重新初始化进程的IPC消息内存池
LITE_OS_SEC_TEXT UINT32 LiteIpcPoolDestroy(UINT32 processID)
销毁指定进程的IPC池
VOID LOS_ArchMmuContextSwitch(LosArchMmu *archMmu)
LOS_ArchMmuContextSwitch 切换MMU上下文
VOID OsUserCloneParentStack(VOID *childStack, UINTPTR parentTopOfStask, UINT32 parentStackSize)
把父任务上下文克隆给子任务
VOID * OsTaskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack, BOOL initFlag)
内核态任务运行栈初始化
VOID OsUserTaskStackInit(TaskContext *context, UINTPTR taskEntry, UINTPTR stack)
用户态运行栈初始化,此时上下文还在内核区
UINT32 OsGetRndOffset(INT32 randomDevFD)
VOID LOS_MpSchedule(UINT32 target)
LITE_OS_SEC_TEXT UINT32 OsExecStart(const TSK_ENTRY_FUNC entry, UINTPTR sp, UINTPTR mapBase, UINT32 mapSize)
执行用户态任务, entry为入口函数 ,其中 创建好task,task上下文 等待调度真正执行, sp:栈指针 mapBase:栈底 mapSize:栈大小
STATIC UINT32 OsCopyProcessResources(UINT32 flags, LosProcessCB *child, LosProcessCB *run)
拷贝进程资源
STATIC UINT32 OsInitPCB(LosProcessCB *processCB, UINT32 mode, const CHAR *name)
STATIC UINT32 OsCopyParent(UINT32 flags, LosProcessCB *childProcessCB, LosProcessCB *runProcessCB)
LITE_OS_SEC_BSS LosProcessCB * g_processCBArray
进程池数组
STATIC ProcessGroup * OsFindProcessGroup(UINT32 gid)
STATIC VOID * OsUserInitStackAlloc(LosProcessCB *processCB, UINT32 *size)
LITE_OS_SEC_BSS UINT32 g_kernelIdleProcess
0号进程 内核态idle进程,由Kprocess fork
LITE_OS_SEC_TEXT INT32 OsGetProcessPriority(INT32 which, INT32 pid)
接口封装 - 获取进程优先级 which:标识进程,进程组,用户
LITE_OS_SEC_TEXT UINT32 OsGetIdleProcessID(VOID)
获取内核态空闲进程
LITE_OS_SEC_TEXT INT32 LOS_GetUsedPIDList(UINT32 *pidList, INT32 pidMaxNum)
LOS_GetUsedPIDList 获取使用中的进程列表
LITE_OS_SEC_TEXT INT32 OsSendSignalToProcessGroup(INT32 pid, siginfo_t *info, INT32 permission)
LITE_OS_SEC_TEXT UINT32 OsGetUserInitProcessID(VOID)
获取用户态进程的根进程,所有用户进程都是g_processCBArray[g_userInitProcess] fork来的
VOID OsDeleteTaskFromProcess(LosTaskCB *taskCB)
STATIC INLINE INT32 OsProcessSchedlerParamCheck(INT32 which, INT32 pid, UINT16 prio, UINT16 policy)
进程调度参数检查
STATIC UINT32 OsSetProcessGroupIDUnsafe(UINT32 pid, UINT32 gid, ProcessGroup **group)
STATIC UINT32 OsChildSetProcessGroupAndSched(LosProcessCB *child, LosProcessCB *run)
STATIC UINT32 OsCopyFile(UINT32 flags, LosProcessCB *childProcessCB, LosProcessCB *runProcessCB)
拷贝进程文件描述符(proc_fd)信息
STATIC VOID ThreadGroupActiveTaskKilled(LosTaskCB *taskCB)
按指定状态退出指定进程
LITE_OS_SEC_TEXT INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 prio, UINT16 policy)
设置进程调度计划
LITE_OS_SEC_TEXT_INIT UINT32 OsUserInitProcess(VOID)
LITE_OS_SEC_TEXT INT32 LOS_GetUserID(VOID)
LITE_OS_SEC_TEXT UINT32 OsGetKernelInitProcessID(VOID)
获取内核态根进程
LITE_OS_SEC_TEXT INT32 LOS_Waitid(INT32 pid, USER siginfo_t *info, UINT32 options, VOID *rusage)
LITE_OS_SEC_BSS UINT32 g_processMaxNum
进程最大数量,默认64个
LITE_OS_SEC_TEXT INT32 LOS_Fork(UINT32 flags, const CHAR *name, const TSK_ENTRY_FUNC entry, UINT32 stackSize)
LITE_OS_SEC_TEXT VOID OsExecProcessVmSpaceRestore(LosVmSpace *oldSpace)
LITE_OS_SEC_TEXT INT32 LOS_GetProcessScheduler(INT32 pid)
获得指定进程的调度策略
LITE_OS_SEC_TEXT VOID OsSetSigHandler(UINTPTR addr)
设置进程的信号处理函数
STATIC VOID OsExitProcessGroup(LosProcessCB *processCB, ProcessGroup **group)
STATIC UINT32 OsCopyTask(UINT32 flags, LosProcessCB *childProcessCB, const CHAR *name, UINTPTR entry, UINT32 size)
LITE_OS_SEC_TEXT INT32 LOS_SetProcessPriority(INT32 pid, UINT16 prio)
接口封装 - 设置进程优先级
LITE_OS_SEC_TEXT VOID LOS_Exit(INT32 status)
LOS_Exit 进程退出
LITE_OS_SEC_TEXT UINTPTR OsGetSigHandler(VOID)
获取进程的信号处理函数
STATIC UINT32 OsCopyUser(LosProcessCB *childCB, LosProcessCB *parentCB)
拷贝用户信息 直接用memcpy_s
LITE_OS_SEC_TEXT INT32 LOS_GetGroupID(VOID)
STATIC VOID OsDealAliveChildProcess(LosProcessCB *processCB)
VOID OsProcessNaturalExit(LosProcessCB *processCB, UINT32 status)
LITE_OS_SEC_TEXT LosVmSpace * OsExecProcessVmSpaceReplace(LosVmSpace *newSpace, UINTPTR stackBase, INT32 randomDevFD)
LITE_OS_SEC_BSS UINT32 g_kernelInitProcess
2号进程 内核态初始Kprocess进程,内核态下其他进程由它 fork
LITE_OS_SEC_TEXT INT32 LOS_Wait(INT32 pid, USER INT32 *status, UINT32 options, VOID *rusage)
UINT32 OsProcessAddNewTask(UINT32 pid, LosTaskCB *taskCB, SchedParam *param)
STATIC VOID OsChildProcessResourcesFree(const LosProcessCB *processCB)
STATIC UINT32 OsWaitOptionsCheck(UINT32 options)
LITE_OS_SEC_TEXT INT32 LOS_GetProcessGroupID(UINT32 pid)
LITE_OS_SEC_BSS UINT32 g_userInitProcess
1号进程 用户态的初始init进程,用户态下其他进程由它 fork
STATIC INT32 OsCopyProcess(UINT32 flags, const CHAR *name, UINTPTR sp, UINT32 size)
拷贝进程
STATIC BOOL OsProcessCapPermitCheck(const LosProcessCB *processCB, const SchedParam *param, UINT16 prio)
STATIC VOID OsWaitCheckAndWakeParentProcess(LosProcessCB *parentCB, const LosProcessCB *processCB)
STATIC BOOL OsWaitWakeSpecifiedProcess(LOS_DL_LIST *head, const LosProcessCB *processCB, LOS_DL_LIST **anyList)
STATIC UINT32 OsForkInitPCB(UINT32 flags, LosProcessCB *child, const CHAR *name, UINTPTR sp, UINT32 size)
LITE_OS_SEC_TEXT struct fd_table_s * LOS_GetFdTable(UINT32 pid)
LITE_OS_SEC_TEXT VOID OsProcessThreadGroupDestroy(VOID)
LITE_OS_SEC_TEXT UINT32 LOS_GetSystemProcessMaximum(VOID)
获取系统支持的最大进程数目
LITE_OS_SEC_TEXT INT32 OsSetProcessGroupID(UINT32 pid, UINT32 gid)
STATIC UINT32 OsWaitRecycleChildProcess(const LosProcessCB *childCB, UINT32 intSave, INT32 *status, siginfo_t *info)
等待回收孩子进程 @note_thinking 这样写Porcess不太好吧
STATIC User * OsCreateUser(UINT32 userID, UINT32 gid, UINT32 size)
STATIC UINT32 OsCopyMM(UINT32 flags, LosProcessCB *childProcessCB, LosProcessCB *runProcessCB)
LITE_OS_SEC_TEXT VOID OsProcessCBRecycleToFree(VOID)
UINT32 OsSetProcessName(LosProcessCB *processCB, const CHAR *name)
STATIC UINT32 OsWaitSetFlag(const LosProcessCB *processCB, INT32 pid, LosProcessCB **child)
设置等待子进程退出方式方法
STATIC UINT32 OsUserInitProcessStart(LosProcessCB *processCB, TSK_INIT_PARAM_S *param)
用户进程开始初始化
LITE_OS_SEC_TEXT INT32 LOS_GetCurrProcessGroupID(VOID)
获取当前进程的组ID
STATIC UINT32 OsWaitidOptionsCheck(UINT32 options)
STATIC LosProcessCB * OsFindGroupExitProcess(ProcessGroup *group, INT32 pid)
LITE_OS_SEC_TEXT INT32 OsSendSignalToAllProcess(siginfo_t *info, INT32 permission)
LITE_OS_SEC_TEXT UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR *name, LosVmSpace *oldSpace, UINTPTR oldFiles)
进程的回收再利用,被LOS_DoExecveFile调用
LITE_OS_SEC_TEXT_INIT UINT32 OsSystemProcessCreate(VOID)
STATIC VOID OsWaitInsertWaitListInOrder(LosTaskCB *runTask, LosProcessCB *processCB)
LITE_OS_SEC_BSS ProcessGroup * g_processGroup
全局进程组,负责管理所有进程组
STATIC UINT32 OsLoadUserInit(LosProcessCB *processCB)
STATIC LosProcessCB * OsFindExitChildProcess(const LosProcessCB *processCB, INT32 childPid)
LITE_OS_SEC_TEXT INT32 LOS_SetProcessScheduler(INT32 pid, UINT16 policy, UINT16 prio)
设置指定进程的调度参数,包括优先级和调度策略
STATIC UINT32 OsSetProcessGroupCheck(const LosProcessCB *processCB, UINT32 gid)
设置进程组检查
STATIC UINT32 OsWaitChildProcessCheck(LosProcessCB *processCB, INT32 pid, LosProcessCB **childCB)
检查要等待的孩子进程
LITE_OS_SEC_TEXT VOID OsProcessResourcesToFree(LosProcessCB *processCB)
LITE_OS_SEC_DATA_INIT STATIC LOS_DL_LIST g_processRecycleList
需要回收的进程列表
STATIC INT32 OsWait(INT32 pid, USER INT32 *status, USER siginfo_t *info, UINT32 options, VOID *rusage)
等待子进程结束并回收子进程,返回已经终止的子进程的进程ID号,并清除僵死进程。
LITE_OS_SEC_TEXT STATIC VOID OsRecycleZombiesProcess(LosProcessCB *childCB, ProcessGroup **group)
LITE_OS_SEC_TEXT INT32 OsClone(UINT32 flags, UINTPTR sp, UINT32 size)
OsClone 进程克隆
STATIC LosProcessCB * OsGetFreePCB(VOID)
为用户态任务分配栈空间
LITE_OS_SEC_TEXT INT32 OsSetCurrProcessGroupID(UINT32 gid)
LITE_OS_SEC_TEXT INT32 LOS_GetProcessPriority(INT32 pid)
接口封装 - 获取指定进程优先级
STATIC ProcessGroup * OsCreateProcessGroup(UINT32 pid)
创建进程组
STATIC UINT32 OsProcessInit(VOID)
STATIC INT32 OsSendSignalToSpecifyProcessGroup(ProcessGroup *group, siginfo_t *info, INT32 permission)
STATIC UINT32 OsFindChildProcess(const LosProcessCB *processCB, INT32 childPid)
STATIC UINT32 OsProcessCreateInit(LosProcessCB *processCB, UINT32 flags, const CHAR *name)
VOID OsWaitWakeTask(LosTaskCB *taskCB, UINT32 wakePID)
LITE_OS_SEC_TEXT UINT32 LOS_GetCurrProcessID(VOID)
获取当前进程的进程ID
STATIC INLINE VOID OsInsertPCBToFreeList(LosProcessCB *processCB)
将进程插入到空闲链表中
LITE_OS_SEC_DATA_INIT STATIC LOS_DL_LIST g_freeProcess
空闲状态下的进程链表, .个人觉得应该取名为 g_freeProcessList @note_thinking
LITE_OS_SEC_TEXT BOOL LOS_CheckInGroups(UINT32 gid)
STATIC VOID OsDeInitPCB(LosProcessCB *processCB)
STATIC INLINE BOOL OsProcessIsInactive(const LosProcessCB *processCB)
进程不活跃函数定义:身上贴有不使用且不活跃标签的进程
STATIC INLINE BOOL OsProcessIsUserMode(const LosProcessCB *processCB)
STATIC INLINE User * OsCurrUserGet(VOID)
UINTPTR __user_init_load_addr
init 进程的加载地址 ,由链接器赋值
STATIC INLINE BOOL OsProcessExitCodeSignalIsSet(LosProcessCB *processCB)
进程退出码是否被设置过,默认是 0 ,如果 & 0x7FU 还是 0 ,说明没有被设置过.
UINTPTR __user_init_bss
查看 LITE_USER_SEC_BSS ,赋值由liteos.ld完成
STATIC INLINE BOOL OsProcessIsUnused(const LosProcessCB *processCB)
STATIC INLINE BOOL OsProcessIDUserCheckInvalid(UINT32 pid)
STATIC INLINE LosProcessCB * OsCurrProcessGet(VOID)
UINTPTR __user_init_end
init 进程的用户空间初始化结束地址
UINTPTR __user_init_entry
第一个用户态进程(init)的入口地址 查看 LITE_USER_SEC_ENTRY
STATIC INLINE VOID OsProcessExitCodeSet(LosProcessCB *processCB, UINT32 code)
设置进程退出号(8 ~ 15)
STATIC INLINE LosTaskCB * OsCurrTaskGet(VOID)
STATIC INLINE SchedRunqueue * OsSchedRunqueue(VOID)
STATIC INLINE BOOL OsTaskIsInactive(const LosTaskCB *taskCB)
VOID OsSchedProcessDefaultSchedParamGet(UINT16 policy, SchedParam *param)
int OsDispatch(pid_t pid, siginfo_t *info, int permission)
信号分发,发送信号权限/进程组过滤.
int OsKill(pid_t pid, int sig, int permission)
INT32 OsTaskKillUnsafe(UINT32 taskID, INT32 signo)
LITE_OS_SEC_TEXT_INIT VOID OsSwtmrRecycle(UINT32 processID)
回收指定进程的软时钟
LITE_OS_SEC_TEXT VOID OsTaskCBRecycleToFree()
LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID)
创建一个空闲任务
UINT32 OsGetIdleTaskId(VOID)
获取IdletaskId,每个CPU核都对Task进行了内部管理,做到真正的并行处理
LITE_OS_SEC_TEXT UINT32 OsTaskJoinPendUnsafe(LosTaskCB *taskCB)
挂起任务,任务进入等待链表,Join代表是支持通过一个任务去唤醒其他的任务
LITE_OS_SEC_TEXT INT32 OsSetTaskName(LosTaskCB *taskCB, const CHAR *name, BOOL setPName)
LITE_OS_SEC_TEXT VOID OsWriteResourceEvent(UINT32 events)
VOID OsTaskInsertToRecycleList(LosTaskCB *taskCB)
LITE_OS_SEC_TEXT VOID OsInactiveTaskDelete(LosTaskCB *taskCB)
LITE_OS_SEC_TEXT VOID OsRunningTaskToExit(LosTaskCB *runTask, UINT32 status)
LITE_OS_SEC_TEXT_INIT UINT32 OsCreateUserTask(UINT32 processID, TSK_INIT_PARAM_S *initParam)
创建一个用户态任务
PADDR_T LOS_PaddrQuery(VOID *vaddr)
通过虚拟地址查询映射的物理地址
STATUS_T LOS_VmSpaceFree(LosVmSpace *space)
LosVmSpace * OsCreateUserVmSpace(VOID)
创建用户进程空间
STATIC INLINE VOID LOS_SetRegionTypeAnon(LosVmMapRegion *region)
设为匿名swap映射线性区
STATUS_T LOS_VmSpaceClone(LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace)
LosVmSpace * LOS_GetKVmSpace(VOID)
内核空间只有g_kVmSpace一个,所有的内核进程都共用一个内核空间
STATUS_T LOS_VaddrToPaddrMmap(LosVmSpace *space, VADDR_T vaddr, PADDR_T paddr, size_t len, UINT32 flags)
LosVmMapRegion * LOS_RegionAlloc(LosVmSpace *vmSpace, VADDR_T vaddr, size_t len, UINT32 regionFlags, VM_OFFSET_T pgoff)
STATUS_T OsVmSpaceRegionFree(LosVmSpace *space)
STATUS_T OsUnMMap(LosVmSpace *space, VADDR_T addr, size_t size)
VOID * LOS_PhysPagesAllocContiguous(size_t nPages)
分配连续的物理页
VOID LOS_PhysPagesFreeContiguous(VOID *ptr, size_t nPages)
释放指定页数地址连续的物理内存
内存管理单元(英语:memory management unit,缩写为MMU),有时称作分页内存管理单元(英语:paged memory management unit,缩写为PMMU)。
struct LOS_DL_LIST * pstNext
进程IPC信息,见于进程结构体: LosProcessCB.ipcInfo
struct rlimit * resourceLimit
每个进程在运行时系统不会无限制的允许单个进程不断的消耗资源,因此都会设置资源限制。
LOS_DL_LIST subordinateGroupList
struct files_struct * files
CHAR processName[OS_PCB_NAME_LEN]
LOS_DL_LIST threadSiblingList
volatile UINT32 threadNumber
LOS_DL_LIST exitChildList
mode_t umask
umask(user file-creatiopn mode mask)为用户文件创建掩码,是创建文件或文件夹时默认权限的基础。
LOS_DL_LIST exitProcessList
VOID(* enqueue)(SchedRunqueue *rq, LosTaskCB *taskCB)
入队列
UINT32(* wait)(LosTaskCB *runTask, LOS_DL_LIST *list, UINT32 timeout)
任务等待
VOID(* wake)(LosTaskCB *taskCB)
任务唤醒
BOOL(* schedParamModify)(LosTaskCB *taskCB, const SchedParam *param)
修改调度参数
UINT32(* schedParamGet)(const LosTaskCB *taskCB, SchedParam *param)
获取调度参数
sig_cb sig
信号控制块,用于异步通信,类似于 linux singal模块
UINTPTR userMapBase
用户空间的栈顶位置,内存来自用户空间,和topOfStack有本质的区别.
UINTPTR userArea
用户空间的堆区开始位置
UINT32 userID
用户ID [0,60000],0为root用户
UINT32 gid
用户组ID [0,60000],0为root用户组
UINT32 userMapSize
用户空间的栈大小,栈底 = userMapBase + userMapSize
UINTPTR userArea
用户空间的堆区开始位置
UINTPTR userMapBase
用户空间的栈顶位置.
UINTPTR userSP
用户空间当前栈指针位置
虚拟空间,每个进程都有一个属于自己的虚拟内存地址空间
struct fd_table_s * fdt
持有的文件表
unsigned int sigIntLock
信号中断锁
sigset_t sigprocmask
Signals that are blocked | 任务屏蔽了哪些信号
TSK_ENTRY_FUNC pfnTaskEntry
UserTaskParam userParam
任务用户态运行时任何参数
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void
size_t LOS_ArchCopyToUser(void *dst, const void *src, size_t len)
从内核空间拷贝到用户空间
void VidMapDestroy(LosProcessCB *processCB)
销毁虚拟ID映射
UINT32 VidMapListInit(LosProcessCB *processCB)