更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_process_pri.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 * of conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 * to endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef _LOS_PROCESS_PRI_H
33#define _LOS_PROCESS_PRI_H
34
35#include "los_task_pri.h"
36#include "los_sem_pri.h"
37#include "los_process.h"
38#include "los_vm_map.h"
39#ifdef LOSCFG_KERNEL_LITEIPC
40#include "hm_liteipc.h"
41#endif
42#ifdef LOSCFG_SECURITY_CAPABILITY
43#include "capability_type.h"
44#endif
45#ifdef LOSCFG_SECURITY_VID
46#include "vid_type.h"
47#endif
48#include "sys/resource.h"
49
50#ifdef __cplusplus
51#if __cplusplus
52extern "C" {
53#endif /* __cplusplus */
54#endif /* __cplusplus */
55
56#define OS_PCB_NAME_LEN OS_TCB_NAME_LEN
57
58#ifdef LOSCFG_SECURITY_CAPABILITY
59#define OS_GROUPS_NUMBER_MAX 256
60
61/*! 用户描述体*/
62typedef struct {
63 UINT32 userID; ///<用户ID [0,60000],0为root用户
65 UINT32 gid; ///<用户组ID [0,60000],0为root用户组
67 UINT32 groupNumber;///< 用户组数量
68 UINT32 groups[1]; //所属用户组列表,一个用户可属多个用户组
69} User;
70#endif
71/*! 进程组结构体*/
72typedef struct {
73 UINT32 groupID; /**< Process group ID is the PID of the process that created the group | 进程组ID是创建进程组的那个进程的ID*/
74 LOS_DL_LIST processList; /**< List of processes under this process group | 属于该进程组的进程链表*/
75 LOS_DL_LIST exitProcessList; /**< List of closed processes (zombie processes) under this group | 进程组的僵死进程链表*/
76 LOS_DL_LIST groupList; /**< Process group list | 进程组链表,上面挂的都是进程组*/
78
79/**
80 * 进程控制块.
81 */
82typedef struct ProcessCB {
83 CHAR processName[OS_PCB_NAME_LEN]; /**< Process name | 进程名称 */
84 UINT32 processID; /**< Process ID = leader thread ID | 进程ID,由进程池分配,范围[0,64] */
85 UINT16 processStatus; /**< [15:4] Process Status; [3:0] The number of threads currently
86 running in the process | 这里设计很巧妙.用一个变量表示了两层逻辑 数量和状态,点赞! @note_good 从这里也可以看出一个进程可以有多个正在运行的任务*/
87 UINT16 consoleID; /**< The console id of task belongs | 任务的控制台id归属 */
88 UINT16 processMode; /**< Kernel Mode:0; User Mode:1; | 模式指定为内核还是用户进程 */
89 UINT32 parentProcessID; /**< Parent process ID | 父进程ID*/
90 UINT32 exitCode; /**< Process exit status | 进程退出状态码*/
91 LOS_DL_LIST pendList; /**< Block list to which the process belongs | 进程所在的阻塞列表,进程因阻塞挂入相应的链表.*/
92 LOS_DL_LIST childrenList; /**< Children process list | 孩子进程都挂到这里,形成双循环链表*/
93 LOS_DL_LIST exitChildList; /**< Exit children process list | 要退出的孩子进程链表,白发人要送黑发人.*/
94 LOS_DL_LIST siblingList; /**< Linkage in parent's children list | 兄弟进程链表, 56个民族是一家,来自同一个父进程.*/
95 ProcessGroup *group; /**< Process group to which a process belongs | 所属进程组*/
96 LOS_DL_LIST subordinateGroupList; /**< Linkage in group list | 进程组员链表*/
97 UINT32 threadGroupID; /**< Which thread group , is the main thread ID of the process */
98 LOS_DL_LIST threadSiblingList; /**< List of threads under this process | 进程的线程(任务)列表 */
99 volatile UINT32 threadNumber; /**< Number of threads alive under this process | 此进程下的活动线程数*/
100 UINT32 threadCount; /**< Total number of threads created under this process | 在此进程下创建的线程总数*/ //
101 LOS_DL_LIST waitList; /**< The process holds the waitLits to support wait/waitpid | 父进程通过进程等待的方式,回收子进程资源,获取子进程退出信息*/
102#ifdef LOSCFG_KERNEL_SMP
103 UINT32 timerCpu; /**< CPU core number of this task is delayed or pended | 统计各线程被延期或阻塞的时间*/
104#endif
105 UINTPTR sigHandler; /**< Signal handler | 信号处理函数,处理如 SIGSYS 等信号*/
106 sigset_t sigShare; /**< Signal share bit | 信号共享位 sigset_t是个64位的变量,对应64种信号*/
107#ifdef LOSCFG_KERNEL_LITEIPC
108 ProcIpcInfo *ipcInfo; /**< Memory pool for lite ipc | 用于进程间通讯的虚拟设备文件系统,设备装载点为 /dev/lite_ipc*/
109#endif
110#ifdef LOSCFG_KERNEL_VM
111 LosVmSpace *vmSpace; /**< VMM space for processes | 虚拟空间,描述进程虚拟内存的数据结构,linux称为内存描述符 */
112#endif
113#ifdef LOSCFG_FS_VFS
114 struct files_struct *files; /**< Files held by the process | 进程所持有的所有文件,注者称之为进程的文件管理器*/
115#endif //每个进程都有属于自己的文件管理器,记录对文件的操作. 注意:一个文件可以被多个进程操作
116 timer_t timerID; /**< iTimer */
117
118#ifdef LOSCFG_SECURITY_CAPABILITY //安全能力
119 User *user; ///< 进程的拥有者
120 UINT32 capability; ///< 安全能力范围 对应 CAP_SETGID
121#endif
122#ifdef LOSCFG_SECURITY_VID //虚拟ID映射功能
124#endif
125#ifdef LOSCFG_DRIVERS_TZDRIVER
126 struct Vnode *execVnode; /**< Exec bin of the process | 进程的可执行文件 */
127#endif
128 mode_t umask; ///< umask(user file-creatiopn mode mask)为用户文件创建掩码,是创建文件或文件夹时默认权限的基础。
129#ifdef LOSCFG_KERNEL_CPUP
130 OsCpupBase *processCpup; /**< Process cpu usage | 进程占用CPU情况统计*/
131#endif
132 struct rlimit *resourceLimit; ///< 每个进程在运行时系统不会无限制的允许单个进程不断的消耗资源,因此都会设置资源限制。
134
135#define CLONE_VM 0x00000100 ///< 子进程与父进程运行于相同的内存空间
136#define CLONE_FS 0x00000200 ///< 子进程与父进程共享相同的文件系统,包括root、当前目录、umask
137#define CLONE_FILES 0x00000400 ///< 子进程与父进程共享相同的文件描述符(file descriptor)表
138#define CLONE_SIGHAND 0x00000800 ///< 子进程与父进程共享相同的信号处理(signal handler)表
139#define CLONE_PTRACE 0x00002000 ///< 若父进程被trace,子进程也被trace
140#define CLONE_VFORK 0x00004000 ///< 父进程被挂起,直至子进程释放虚拟内存资源
141#define CLONE_PARENT 0x00008000 ///< 创建的子进程的父进程是调用者的父进程,新进程与创建它的进程成了“兄弟”而不是“父子”
142#define CLONE_THREAD 0x00010000 ///< Linux 2.4中增加以支持POSIX线程标准,子进程与父进程共享相同的线程群
143//CLONE_NEWNS 在新的namespace启动子进程,namespace描述了进程的文件hierarchy
144//CLONE_PID 子进程在创建时PID与父进程一致
145#define OS_PCB_FROM_PID(processID) (((LosProcessCB *)g_processCBArray) + (processID))///< 通过数组找到LosProcessCB
146#define OS_PCB_FROM_SIBLIST(ptr) LOS_DL_LIST_ENTRY((ptr), LosProcessCB, siblingList)///< 通过siblingList节点找到 LosProcessCB
147#define OS_PCB_FROM_PENDLIST(ptr) LOS_DL_LIST_ENTRY((ptr), LosProcessCB, pendList) ///< 通过pendlist节点找到 LosProcessCB
148
149/**
150 * @ingroup los_process
151 * Flag that indicates the process or process control block status.
152 *
153 * The process is created but does not participate in scheduling.
154 */
155#define OS_PROCESS_STATUS_INIT OS_TASK_STATUS_INIT
156
157/**
158 * @ingroup los_process
159 * Flag that indicates the process or process control block status.
160 *
161 * The process is ready.
162 */
163#define OS_PROCESS_STATUS_READY OS_TASK_STATUS_READY
164
165/**
166 * @ingroup los_process
167 * Flag that indicates the process or process control block status.
168 *
169 * The process is running.
170 */
171#define OS_PROCESS_STATUS_RUNNING OS_TASK_STATUS_RUNNING
172
173/**
174 * @ingroup los_process
175 * Flag that indicates the process or process control block status.
176 *
177 * The process is pending
178 */
179#define OS_PROCESS_STATUS_PENDING (OS_TASK_STATUS_PENDING | OS_TASK_STATUS_DELAY | OS_TASK_STATUS_SUSPENDED)
180
181/**
182 * @ingroup los_process
183 * Flag that indicates the process or process control block status.
184 *
185 * The process is run out but the resources occupied by the process are not recovered.
186 */
187#define OS_PROCESS_STATUS_ZOMBIES 0x0100U ///< 进程状态: 僵死
188
189/**
190 * @ingroup los_process
191 * Flag that indicates the process or process control block status.
192 *
193 * The process status equal this is process control block unused,
194 * coexisting with OS_PROCESS_STATUS_ZOMBIES means that the control block is not recovered.
195 */
196#define OS_PROCESS_FLAG_UNUSED 0x0200U ///< 进程未使用标签,一般用于进程的初始状态 freelist里面都是这种标签
197
198/**
199 * @ingroup los_process
200 * Flag that indicates the process or process control block status.
201 *
202 * The process has been call exit, it only works with multiple cores.
203 */
204#define OS_PROCESS_FLAG_EXIT 0x0400U ///< 进程退出标签,退出的进程进入回收链表等待回收资源
205
206/**
207 * @ingroup los_process
208 * Flag that indicates the process or process control block status.
209 *
210 * The process is the leader of the process group.
211 */
212#define OS_PROCESS_FLAG_GROUP_LEADER 0x0800U ///< 进程当了进程组领导标签
213
214/**
215 * @ingroup los_process
216 * Flag that indicates the process or process control block status.
217 *
218 * The process has performed the exec operation.
219 */
220#define OS_PROCESS_FLAG_ALREADY_EXEC 0x1000U ///< 进程已执行exec操作 load elf时使用
221
222/**
223 * @ingroup los_process
224 * Flag that indicates the process or process control block status.
225 *
226 * The process is dying or already dying.
227 */ /// 进程不活跃状态定义: 身上贴有退出便签且状态为僵死的进程
228#define OS_PROCESS_STATUS_INACTIVE (OS_PROCESS_FLAG_EXIT | OS_PROCESS_STATUS_ZOMBIES)
229
230/**
231 * @ingroup los_process
232 * Used to check if the process control block is unused.
233 */
234STATIC INLINE BOOL OsProcessIsUnused(const LosProcessCB *processCB)//查下进程是否还在使用?
235{
236 return ((processCB->processStatus & OS_PROCESS_FLAG_UNUSED) != 0);
237}
238
239/**
240 * @ingroup los_process
241 * Used to check if the process is inactive.
242 */ /// 进程不活跃函数定义:身上贴有不使用且不活跃标签的进程
243STATIC INLINE BOOL OsProcessIsInactive(const LosProcessCB *processCB)//查下进程是否不活跃?
244{
245 return ((processCB->processStatus & (OS_PROCESS_FLAG_UNUSED | OS_PROCESS_STATUS_INACTIVE)) != 0);
246}
247
248/**
249 * @ingroup los_process
250 * Used to check if the process is dead.
251 */ /// 进程死啦死啦的定义: 身上贴有不使用且状态为僵死的进程
252STATIC INLINE BOOL OsProcessIsDead(const LosProcessCB *processCB)//查下进程是否死啦死啦滴?
253{
254 return ((processCB->processStatus & (OS_PROCESS_FLAG_UNUSED | OS_PROCESS_STATUS_ZOMBIES)) != 0);
255}
256
257STATIC INLINE BOOL OsProcessIsInit(const LosProcessCB *processCB)
258{
259 return (processCB->processStatus & OS_PROCESS_STATUS_INIT);
260}
261
262/**
263 * @ingroup los_process
264 * The highest priority of a kernel mode process.
265 */
266#define OS_PROCESS_PRIORITY_HIGHEST 0 ///< 进程最高优先级
267
268/**
269 * @ingroup los_process
270 * The lowest priority of a kernel mode process
271 */
272#define OS_PROCESS_PRIORITY_LOWEST 31 ///< 进程最低优先级
273
274/**
275 * @ingroup los_process
276 * The highest priority of a user mode process.
277 */
278#define OS_USER_PROCESS_PRIORITY_HIGHEST 10 ///< 内核模式和用户模式的优先级分割线 10-31 用户级, 0-9内核级
279
280/**
281 * @ingroup los_process
282 * The lowest priority of a user mode process
283 */
284#define OS_USER_PROCESS_PRIORITY_LOWEST OS_PROCESS_PRIORITY_LOWEST ///< 用户进程的最低优先级
285
286/**
287 * @ingroup los_process
288 * User state root process default priority
289 */
290#define OS_PROCESS_USERINIT_PRIORITY 28 ///< 用户进程默认的优先级,28级好低啊
291
292#define OS_TASK_DEFAULT_STACK_SIZE 0x2000 ///< task默认栈大小 8K
293#define OS_USER_TASK_SYSCALL_STACK_SIZE 0x3000 ///< 用户通过系统调用的栈大小 12K ,这时是运行在内核模式下
294#define OS_USER_TASK_STACK_SIZE 0x100000 ///< 用户任务运行在用户空间的栈大小 1M
295
296#define OS_KERNEL_MODE 0x0U ///< 内核态
297#define OS_USER_MODE 0x1U ///< 用户态
298/*! 用户态进程*/
299STATIC INLINE BOOL OsProcessIsUserMode(const LosProcessCB *processCB)
300{
301 return (processCB->processMode == OS_USER_MODE);
302}
303
304#define LOS_PRIO_PROCESS 0U ///< 进程标识
305#define LOS_PRIO_PGRP 1U ///< 进程组标识
306#define LOS_PRIO_USER 2U ///< 用户标识
307
308#define OS_USER_PRIVILEGE_PROCESS_GROUP 1U ///< 用户态进程组ID
309#define OS_KERNEL_PROCESS_GROUP 2U ///< 内核态进程组ID
310
311/*
312 * Process exit code
313 * 31 15 8 7 0
314 * | | exit code | core dump | signal |
315 */
316#define OS_PRO_EXIT_OK 0 ///< 进程正常退出
317/// 置进程退出码第七位为1
318STATIC INLINE VOID OsProcessExitCodeCoreDumpSet(LosProcessCB *processCB)
319{
320 processCB->exitCode |= 0x80U; // 0b10000000
321}
322/// 设置进程退出信号(0 ~ 7)
323STATIC INLINE VOID OsProcessExitCodeSignalSet(LosProcessCB *processCB, UINT32 signal)
324{
325 processCB->exitCode |= signal & 0x7FU;// 0b01111111
326}
327/// 清除进程退出信号(0 ~ 7)
328STATIC INLINE VOID OsProcessExitCodeSignalClear(LosProcessCB *processCB)
329{
330 processCB->exitCode &= (~0x7FU);// 低7位全部清0
331}
332/// 进程退出码是否被设置过,默认是 0 ,如果 & 0x7FU 还是 0 ,说明没有被设置过.
334{
335 return (processCB->exitCode) & 0x7FU;
336}
337/// 设置进程退出号(8 ~ 15)
338STATIC INLINE VOID OsProcessExitCodeSet(LosProcessCB *processCB, UINT32 code)
339{
340 processCB->exitCode |= ((code & 0x000000FFU) << 8U) & 0x0000FF00U; /* 8: Move 8 bits to the left, exitCode */
341}
342
343extern LosProcessCB *g_processCBArray;///< 进程池 OsProcessInit
344extern UINT32 g_processMaxNum;///< 进程最大数量
345
346#define OS_PID_CHECK_INVALID(pid) (((UINT32)(pid)) >= g_processMaxNum)
347/*! 内联函数 进程ID是否有效 */
349{
350 return ((pid >= g_processMaxNum) || (pid == 0));
351}
352/*! 获取当前进程PCB */
353STATIC INLINE LosProcessCB *OsCurrProcessGet(VOID)
354{
355 UINT32 intSave;
356
357 intSave = LOS_IntLock();
358 LosProcessCB *runProcess = OS_PCB_FROM_PID(OsCurrTaskGet()->processID);
359 LOS_IntRestore(intSave);
360 return runProcess;
361}
362
363#ifdef LOSCFG_SECURITY_CAPABILITY
364/*! 获取当前进程的所属用户 */
365STATIC INLINE User *OsCurrUserGet(VOID)
366{
367 User *user = NULL;
368 UINT32 intSave;
369
370 intSave = LOS_IntLock();
371 user = OsCurrProcessGet()->user;
372 LOS_IntRestore(intSave);
373 return user;
374}
375
376STATIC INLINE UINT32 OsProcessUserIDGet(const LosTaskCB *taskCB)
377{
378 UINT32 intSave = LOS_IntLock();
379 UINT32 uid = OS_INVALID;
380
381 LosProcessCB *process = OS_PCB_FROM_PID(taskCB->processID);
382 if (process->user != NULL) {
383 uid = process->user->userID;
384 }
385 LOS_IntRestore(intSave);
386 return uid;
387}
388#endif
389
390STATIC INLINE UINT32 OsProcessThreadGroupIDGet(const LosTaskCB *taskCB)
391{
392 return OS_PCB_FROM_PID(taskCB->processID)->threadGroupID;
393}
394
395STATIC INLINE UINT32 OsProcessThreadNumberGet(const LosTaskCB *taskCB)
396{
397 return OS_PCB_FROM_PID(taskCB->processID)->threadNumber;
398}
399
400#ifdef LOSCFG_KERNEL_VM
401STATIC INLINE LosVmSpace *OsProcessVmSpaceGet(const LosProcessCB *processCB)
402{
403 return processCB->vmSpace;
404}
405#endif
406
407#ifdef LOSCFG_DRIVERS_TZDRIVER
408STATIC INLINE struct Vnode *OsProcessExecVnodeGet(const LosProcessCB *processCB)
409{
410 return processCB->execVnode;
411}
412#endif
413/*
414 * return immediately if no child has exited.
415 */
416#define LOS_WAIT_WNOHANG (1 << 0U) ///< 如果没有孩子进程退出,则立即返回,而不是阻塞在这个函数上等待;如果结束了,则返回该子进程的进程号。
417
418/*
419 * return if a child has stopped (but not traced via ptrace(2)).
420 * Status for traced children which have stopped is provided even
421 * if this option is not specified.
422 */
423#define LOS_WAIT_WUNTRACED (1 << 1U) ///< 如果子进程进入暂停情况则马上返回,不予以理会结束状态。untraced
424#define LOS_WAIT_WSTOPPED (1 << 1U)
425
426/*
427 * Wait for exited processes
428 */
429#define LOS_WAIT_WEXITED (1 << 2U)
430
431/*
432 * return if a stopped child has been resumed by delivery of SIGCONT.
433 * (For Linux-only options, see below.)
434 */
435#define LOS_WAIT_WCONTINUED (1 << 3U) ///< 可获取子进程恢复执行的状态,也就是可获取continued状态 continued
436
437/*
438 * Leave the child in a waitable state;
439 * a later wait call can be used to again retrieve the child status information.
440 */
441#define LOS_WAIT_WNOWAIT (1 << 24U)
442
443/*
444 * Indicates that you are already in a wait state
445 */
446#define OS_PROCESS_WAIT (1 << 15U) ///< 表示已经处于等待状态
447
448/*
449 * Wait for any child process to finish
450 */
451#define OS_PROCESS_WAIT_ANY OS_TASK_WAIT_ANYPROCESS ///< 等待任意子进程完成
452
453/*
454 * Wait for the child process specified by the pid to finish
455 */
456#define OS_PROCESS_WAIT_PRO OS_TASK_WAIT_PROCESS ///< 等待pid指定的子进程完成
457
458/*
459 * Waits for any child process in the specified process group to finish.
460 */
461#define OS_PROCESS_WAIT_GID OS_TASK_WAIT_GID ///< 等待指定进程组中的任意子进程完成
462
463#define OS_PROCESS_INFO_ALL 1
464#define OS_PROCESS_DEFAULT_UMASK 0022 ///< 系统默认的用户掩码(umask),大多数的Linux系统的默认掩码为022。
465//用户掩码的作用是用户在创建文件时从文件的默认权限中去除掩码中的权限。所以文件创建之后的权限实际为:创建文件的权限为:0666-0022=0644。创建文件夹的权限为:0777-0022=0755
466extern UINTPTR __user_init_entry; ///< 第一个用户态进程(init)的入口地址 查看 LITE_USER_SEC_ENTRY
467extern UINTPTR __user_init_bss; ///< 查看 LITE_USER_SEC_BSS ,赋值由liteos.ld完成
468extern UINTPTR __user_init_end; ///< init 进程的用户空间初始化结束地址
469extern UINTPTR __user_init_load_addr;///< init 进程的加载地址 ,由链接器赋值
470extern UINT32 OsSystemProcessCreate(VOID);
471extern VOID OsProcessNaturalExit(LosProcessCB *processCB, UINT32 status);
472extern VOID OsProcessCBRecycleToFree(VOID);
473extern VOID OsProcessResourcesToFree(LosProcessCB *processCB);
474extern UINT32 OsUserInitProcess(VOID);
475extern INT32 OsClone(UINT32 flags, UINTPTR sp, UINT32 size);
476extern VOID OsExecProcessVmSpaceRestore(LosVmSpace *oldSpace);
477extern LosVmSpace *OsExecProcessVmSpaceReplace(LosVmSpace *newSpace, UINTPTR stackBase, INT32 randomDevFD);
478extern UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR *name, LosVmSpace *oldAspace, UINTPTR oldFiles);
479extern UINT32 OsExecStart(const TSK_ENTRY_FUNC entry, UINTPTR sp, UINTPTR mapBase, UINT32 mapSize);
480extern UINT32 OsSetProcessName(LosProcessCB *processCB, const CHAR *name);
481extern INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 prio, UINT16 policy);
482extern INT32 OsGetProcessPriority(INT32 which, INT32 pid);
483extern UINT32 OsGetUserInitProcessID(VOID);
484extern UINT32 OsGetIdleProcessID(VOID);
488extern VOID OsSetSigHandler(UINTPTR addr);
489extern UINTPTR OsGetSigHandler(VOID);
490extern VOID OsWaitWakeTask(LosTaskCB *taskCB, UINT32 wakePID);
491extern INT32 OsSendSignalToProcessGroup(INT32 pid, siginfo_t *info, INT32 permission);
492extern INT32 OsSendSignalToAllProcess(siginfo_t *info, INT32 permission);
493extern UINT32 OsProcessAddNewTask(UINT32 pid, LosTaskCB *taskCB, SchedParam *param);
494extern VOID OsDeleteTaskFromProcess(LosTaskCB *taskCB);
495extern VOID OsProcessThreadGroupDestroy(VOID);
496
497#ifdef __cplusplus
498#if __cplusplus
499}
500#endif /* __cplusplus */
501#endif /* __cplusplus */
502
503#endif
macro EXC_SP_SET reg1 mrc 获取CPU信息 and mov mul reg0 计算当前CPU栈的偏移位置 ldr reg1 相减得到栈顶 mov sp
Definition: asm.h:57
STATIC INLINE VOID LOS_IntRestore(UINT32 intSave)
Restore interrupts. | 恢复到使用LOS_IntLock关闭所有中断之前的状态
Definition: los_hwi.h:337
STATIC INLINE UINT32 LOS_IntLock(VOID)
Disable all interrupts. | 关闭当前处理器所有中断响应
Definition: los_hwi.h:286
VOID *(* TSK_ENTRY_FUNC)(UINTPTR param1, UINTPTR param2, UINTPTR param3, UINTPTR param4)
Define the type of a task entrance function.
Definition: los_task.h:480
LosVmSpace * OsExecProcessVmSpaceReplace(LosVmSpace *newSpace, UINTPTR stackBase, INT32 randomDevFD)
Definition: los_process.c:1541
STATIC INLINE LosVmSpace * OsProcessVmSpaceGet(const LosProcessCB *processCB)
UINT32 OsGetKernelInitProcessID(VOID)
获取内核态根进程
Definition: los_process.c:2249
STATIC INLINE UINT32 OsProcessThreadGroupIDGet(const LosTaskCB *taskCB)
VOID OsDeleteTaskFromProcess(LosTaskCB *taskCB)
Definition: los_process.c:107
INT32 OsSendSignalToAllProcess(siginfo_t *info, INT32 permission)
Definition: los_process.c:242
STATIC INLINE UINT32 OsProcessThreadNumberGet(const LosTaskCB *taskCB)
STATIC INLINE struct Vnode * OsProcessExecVnodeGet(const LosProcessCB *processCB)
STATIC INLINE BOOL OsProcessIsInit(const LosProcessCB *processCB)
VOID OsProcessCBRecycleToFree(VOID)
Definition: los_process.c:625
UINT32 g_processMaxNum
进程最大数量
Definition: los_process.c:86
UINT32 OsSystemProcessCreate(VOID)
Definition: los_process.c:896
VOID OsSetSigHandler(UINTPTR addr)
设置进程的信号处理函数
Definition: los_process.c:2259
UINT32 OsGetUserInitProcessID(VOID)
获取用户态进程的根进程,所有用户进程都是g_processCBArray[g_userInitProcess] fork来的
Definition: los_process.c:2244
VOID OsExecProcessVmSpaceRestore(LosVmSpace *oldSpace)
Definition: los_process.c:1531
STATIC INLINE BOOL OsProcessIsInactive(const LosProcessCB *processCB)
进程不活跃函数定义:身上贴有不使用且不活跃标签的进程
VOID OsProcessResourcesToFree(LosProcessCB *processCB)
Definition: los_process.c:431
STATIC INLINE UINT32 OsProcessUserIDGet(const LosTaskCB *taskCB)
VOID OsProcessNaturalExit(LosProcessCB *processCB, UINT32 status)
Definition: los_process.c:550
UINT32 OsProcessAddNewTask(UINT32 pid, LosTaskCB *taskCB, SchedParam *param)
Definition: los_process.c:116
STATIC INLINE BOOL OsProcessIsDead(const LosProcessCB *processCB)
进程死啦死啦的定义: 身上贴有不使用且状态为僵死的进程
LosProcessCB * g_processCBArray
进程池 OsProcessInit
Definition: los_process.c:80
struct ProcessCB LosProcessCB
INT32 OsSetProcessGroupID(UINT32 pid, UINT32 gid)
Definition: los_process.c:1439
INT32 OsGetProcessPriority(INT32 which, INT32 pid)
接口封装 - 获取进程优先级 which:标识进程,进程组,用户
Definition: los_process.c:1055
UINT32 OsSetProcessName(LosProcessCB *processCB, const CHAR *name)
Definition: los_process.c:704
STATIC INLINE BOOL OsProcessIsUserMode(const LosProcessCB *processCB)
STATIC INLINE User * OsCurrUserGet(VOID)
VOID OsProcessThreadGroupDestroy(VOID)
Definition: los_process.c:2200
UINT32 OsGetIdleProcessID(VOID)
获取内核态空闲进程
Definition: los_process.c:2254
UINT32 OsUserInitProcess(VOID)
Definition: los_process.c:1746
STATIC INLINE VOID OsProcessExitCodeSignalSet(LosProcessCB *processCB, UINT32 signal)
设置进程退出信号(0 ~ 7)
UINTPTR __user_init_load_addr
init 进程的加载地址 ,由链接器赋值
UINTPTR OsGetSigHandler(VOID)
获取进程的信号处理函数
Definition: los_process.c:2264
STATIC INLINE VOID OsProcessExitCodeSignalClear(LosProcessCB *processCB)
清除进程退出信号(0 ~ 7)
UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR *name, LosVmSpace *oldAspace, UINTPTR oldFiles)
进程的回收再利用,被LOS_DoExecveFile调用
Definition: los_process.c:1568
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)
INT32 OsSetCurrProcessGroupID(UINT32 gid)
Definition: los_process.c:1456
STATIC INLINE BOOL OsProcessIDUserCheckInvalid(UINT32 pid)
STATIC INLINE LosProcessCB * OsCurrProcessGet(VOID)
UINT32 OsExecStart(const TSK_ENTRY_FUNC entry, UINTPTR sp, UINTPTR mapBase, UINT32 mapSize)
执行用户态任务, entry为入口函数 ,其中 创建好task,task上下文 等待调度真正执行, sp:栈指针 mapBase:栈底 mapSize:栈大小
Definition: los_process.c:1616
UINTPTR __user_init_end
init 进程的用户空间初始化结束地址
STATIC INLINE VOID OsProcessExitCodeCoreDumpSet(LosProcessCB *processCB)
置进程退出码第七位为1
INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 prio, UINT16 policy)
设置进程调度计划
Definition: los_process.c:983
UINTPTR __user_init_entry
第一个用户态进程(init)的入口地址 查看 LITE_USER_SEC_ENTRY
INT32 OsClone(UINT32 flags, UINTPTR sp, UINT32 size)
OsClone 进程克隆
Definition: los_process.c:2049
VOID OsWaitWakeTask(LosTaskCB *taskCB, UINT32 wakePID)
Definition: los_process.c:326
STATIC INLINE VOID OsProcessExitCodeSet(LosProcessCB *processCB, UINT32 code)
设置进程退出号(8 ~ 15)
INT32 OsSendSignalToProcessGroup(INT32 pid, siginfo_t *info, INT32 permission)
Definition: los_process.c:262
STATIC INLINE LosTaskCB * OsCurrTaskGet(VOID)
unsigned short UINT16
Definition: los_typedef.h:56
signed int INT32
Definition: los_typedef.h:60
unsigned long UINTPTR
Definition: los_typedef.h:68
unsigned int UINT32
Definition: los_typedef.h:57
char CHAR
Definition: los_typedef.h:63
size_t BOOL
Definition: los_typedef.h:88
进程IPC信息,见于进程结构体: LosProcessCB.ipcInfo
Definition: hm_liteipc.h:92
UINT16 processMode
struct rlimit * resourceLimit
每个进程在运行时系统不会无限制的允许单个进程不断的消耗资源,因此都会设置资源限制。
timer_t timerID
LOS_DL_LIST waitList
UINT32 processID
UINTPTR sigHandler
OsCpupBase * processCpup
LOS_DL_LIST siblingList
LOS_DL_LIST childrenList
LOS_DL_LIST subordinateGroupList
UINT32 exitCode
ProcIpcInfo * ipcInfo
sigset_t sigShare
UINT32 threadCount
struct files_struct * files
UINT32 threadGroupID
UINT16 processStatus
CHAR processName[OS_PCB_NAME_LEN]
TimerIdMap timerIdMap
UINT32 timerCpu
User * user
进程的拥有者
UINT16 consoleID
struct Vnode * execVnode
LOS_DL_LIST threadSiblingList
LOS_DL_LIST pendList
volatile UINT32 threadNumber
UINT32 capability
安全能力范围 对应 CAP_SETGID
UINT32 parentProcessID
LOS_DL_LIST exitChildList
ProcessGroup * group
mode_t umask
umask(user file-creatiopn mode mask)为用户文件创建掩码,是创建文件或文件夹时默认权限的基础。
LosVmSpace * vmSpace
LOS_DL_LIST exitProcessList
LOS_DL_LIST processList
LOS_DL_LIST groupList
UINT32 processID
UINT32 groupNumber
用户组数量
UINT32 effUserID
UINT32 userID
用户ID [0,60000],0为root用户
UINT32 gid
用户组ID [0,60000],0为root用户组
UINT32 effGid
虚拟空间,每个进程都有一个属于自己的虚拟内存地址空间
Definition: los_vm_map.h:146
vnode并不包含文件名,因为 vnode和文件名是 1:N 的关系
Definition: vnode.h:164
uint gid
Definition: vnode.h:169
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 ARG_NUM_0 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_6 ARG_NUM_3 ARG_NUM_5 ARG_NUM_7 ARG_NUM_1 ARG_NUM_4 ARG_NUM_5 ARG_NUM_4 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_7 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_7 ARG_NUM_3 ARG_NUM_2 char ARG_NUM_2 ARG_NUM_1 ARG_NUM_0 ARG_NUM_0 ARG_NUM_3 void ARG_NUM_1 ARG_NUM_0 unsigned ARG_NUM_0 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_5 ARG_NUM_3 ARG_NUM_3 ARG_NUM_4 ARG_NUM_1 ARG_NUM_1 ARG_NUM_3 ARG_NUM_2 mode_t