Compare commits

..

62 Commits

Author SHA1 Message Date
openharmony_ci
04f971084b !1178 fix: /dev/mem 及 /proc/fs_cache 权限漏洞修复
Merge pull request !1178 from yinjiaming/fix
2023-10-16 09:38:00 +00:00
yinjiaming
6daecc8d26 fix: /dev/mem 及 /proc/fs_cache 权限漏洞修复
/dev/mem 和 /proc/fs_cache 存在多余的读写权限,
有被低权限者利用进行攻击的风险,现予以修复。

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: Ie6b537e8cb1de7353dfc357411eba4920a539b4f
2023-10-12 09:52:18 +08:00
openharmony_ci
173cdeb077 !1166 fix: 修复告警
Merge pull request !1166 from Zhaotianyu/20230526fix_codecheck
2023-09-05 13:36:55 +00:00
openharmony_ci
e28271d650 !1174 fix:SysMqNotify系统调用安全增强
Merge pull request !1174 from zhangdengyu/mq_0904
2023-09-04 13:19:17 +00:00
zhangdengyu
27eb4e2334 fix:SysMqNotify系统调用安全增强
Close: #I7YG58

Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com>
Change-Id: Iee5a6c24cd2226e9cab0c4fd37e76194ad068862
2023-09-04 20:43:40 +08:00
openharmony_ci
bd57ef7e2c !1161 添加unittest用例测试工具
Merge pull request !1161 from zhushengle/unittest_tools
2023-09-04 09:12:43 +00:00
zhushengle
342a3eb5c1 feat: 添加unittest用例测试工具
Close #I73IZ3

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I899978a8d8d2edeb30f0ba4d896f6f5abc8a6939
2023-09-04 11:57:15 +08:00
openharmony_ci
63885154d2 !1173 test:调整测试用例
Merge pull request !1173 from zhangdengyu/test_0831
2023-08-31 03:47:11 +00:00
zhangdengyu
95d1eb890a test: 调整测试用例
Close: #I7XBLH

Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com>
Change-Id: Ie58907ea40c062fd1604035945810c53dc7f0bf2
2023-08-31 09:04:51 +08:00
openharmony_ci
0bc453c2cd !1169 修复swtmr遍历不全导致的用例问题
Merge pull request !1169 from wangchen/0726_a
2023-07-26 02:39:24 +00:00
wangchen
73bcf0ec9a Fix: 修复swtmr只在当前核遍历链表的问题
Close #I7NZDT
Signed-off-by: wangchen <wangchen240@huawei.com>
2023-07-26 09:35:58 +08:00
openharmony_ci
49bfc90a63 !1167 容器代码container目录位置变更
Merge pull request !1167 from zwx1232718/master
2023-06-09 09:21:56 +00:00
zwx1232718
b0708886fa container dir change
Signed-off-by: zwx1232718 <zhenghui23@huawei.com>
2023-06-09 16:29:23 +08:00
openharmony_ci
a388a3f565 !1148 修复一些typo错误
Merge pull request !1148 from 景涛/master
2023-06-06 13:36:01 +00:00
arvinzzz
145ff76ab6 refactor: fix codecheck
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: Ib35ca40dc837d78a4c9dc03e44d117088865a5a6
2023-05-26 15:44:47 +08:00
openharmony_ci
280769ae42 !1163 GN脚本规范化
Merge pull request !1163 from zhushengle/GN
2023-05-23 08:43:40 +00:00
zhushengle
1f3a6c8143 feat: GN脚本规范化
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I80b055091a0ff333a859cd35447a851296a67103
2023-05-23 15:56:45 +08:00
openharmony_ci
6c0b0dde23 !1157 test:调整TDD测试用例
Merge pull request !1157 from zhangdengyu/fixTest0424
2023-05-18 12:14:47 +00:00
zhangdengyu
76228c3617 test: TDD用例调整
方案描述:
1、门禁流水线跑单个测试用例.bin文件有时间限制,将用时过长的bin按类型拆分;
2、缩短EDF测试用例的时间;
3、dynload用例改变当前工作路径未恢复导致执行结果的xml文件未生成,在用例结束退出之前恢复当前工作路径。

Close:#I6YIX6

Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com>
Change-Id: I8c6118f9589e8801000ccb0cae9b81e0925696f4
2023-05-18 15:46:12 +08:00
openharmony_ci
5de241eb2a !1160 部件化整改
Merge pull request !1160 from zhushengle/deps
2023-05-09 14:55:31 +00:00
zhushengle
5e68558280 feat: 部件化整改
Close #I71QQ2

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I6f4db7c3775907df06b7186310628fcdee71bdb6
2023-05-09 21:40:00 +08:00
openharmony_ci
9c71de6a2e !1158 Fix : 部件化需求整改
Merge pull request !1158 from yinjiaming/bundle
2023-05-05 08:33:35 +00:00
openharmony_ci
243b1e26a4 !1159 test:修复llvm升级导致tdd用例部分失败问题
Merge pull request !1159 from zhangdengyu/fixLlvmBug0428
2023-05-05 05:14:54 +00:00
yinjiaming
47a4fe030b fix:部件需求整改
修复了脚本扫描出的bundle.json的问题,整改了
不符合规范的路径引用

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: I11c321f8707d3e44dd7ee40dac35cf99907fb864
2023-05-04 11:32:59 +08:00
zhangdengyu
577d29aaba test: 修复llvm升级导致tdd用例部分失败问题
方案描述:
1、llvm升级之后对while(1)死循环和给空指针赋值的场景有错误优化的情况;
   用例中在相关函数之前添加__attribute__((optnone))禁止编译器进行错误优化。

Close:#I6V2LN

Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com>
Change-Id: Ic7150909c12a599aeeb0a55b983dfad7a0631cdc
2023-05-04 09:42:38 +08:00
openharmony_ci
d9e9631286 !1156 Fix : 文档失效链接清理
Merge pull request !1156 from yinjiaming/link
2023-04-23 10:59:05 +00:00
yinjiaming
2bd5b686cf fix:文档失效链接清理
文档中部分链接已失效,现予以清理并更换为有效链接

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: Ib9dfa1e3ec74ed85049aca7c064a6d10a1a3ab46
2023-04-23 18:46:42 +08:00
openharmony_ci
8452488bdb !1149 feat:修复测试用例
Merge pull request !1149 from zhangdengyu/muslUpdate0419
2023-04-21 07:33:16 +00:00
openharmony_ci
a04ab13c76 !1152 修复获取容器信息失败
Merge pull request !1152 from zhushengle/container_bug
2023-04-21 06:40:08 +00:00
zhushengle
338f5d7e7d fix: 修复获取容器信息失败
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ie612d14337f7c24812c74f1510c0a8e6fca1c200
2023-04-20 22:35:20 +08:00
zhangdengyu
fa68ebfcd1 feat: 修复测试用例
方案描述:
musl升级修改了接口部分场景下的错误码,测试用例同步修改。

BREAKING CHANGE:
修复测试用例对外变更描述:
1、socket接口v1.2.0中传入错误参数返回EINVAL错误码,更新之后将返回ENOENT错误码;
2、__nscd_query接口v1.2.0中给传入错误参数返回EAFNOSUPPORT错误码,更新之后将返回ENOENT错误码。

Close: #I6WWES

Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com>
Change-Id: Ib8a1e52b164cf78df917dc28c90f02056a80e1ed
2023-04-19 16:43:20 +08:00
”景涛“
24aa6858ee fix some typo errors
Signed-off-by: ”景涛“ <jingtao3@hust.edu.cn>
2023-04-15 22:16:32 +08:00
openharmony_ci
5fb9165c08 !1139 feat: support EDF
Merge pull request !1139 from zhangdengyu/supportEDF0404
2023-04-09 12:38:18 +00:00
zhangdengyu
13f68dcf9c feat: support EDF
方案描述:
1、liteos_a调度框架支持EDF调度算法,默认优先调度EDF策略的任务
2、用户态musl_c库适配新增调度算法,同步修改相关接口以支持用户态创建EDF进程与线程

BREAKING CHANGE:
support EDF对外变更描述:
以下接口支持SCHED_DEADLINE调度策略:
pthread_attr_getschedparam
pthread_attr_setschedparam
pthread_getschedparam
pthread_setschedparam
pthread_create
sched_getscheduler
sched_getparam
sched_setparam
sched_setscheduler

Close:#I6T3P3

Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com>
Change-Id: Ic9fe6896fcae42ae4ee7fe5dfb8e858a6ed19740
2023-04-09 19:46:26 +08:00
openharmony_ci
f332a06e4c !1134 Ignore warnings for llvm15 upgrade
Merge pull request !1134 from enable_llvm15
2023-04-04 07:03:22 +00:00
guzhihao4
1ba32406bb Ignore warnings for enable llvm15
Issue: #I6LPWU

Signed-off-by: guzhihao4 <guzhihao4@huawei.com>
Change-Id: I7b558fa46239081890ae005de65ba8d2bba1d134
2023-04-03 16:42:22 +08:00
openharmony_ci
249ea71a11 !1135 修复 hm_liteipc.c 处的 typo
Merge pull request !1135 from 邹亚龙/master
2023-04-03 07:53:57 +00:00
Yalong Zou
814f5affd0 fix: 修复 hm_liteipc.c 处的 typo
应拼写成 Receive, 因此此处的函数名称应当是 CheckReceivedMsg.

Signed-off-by: Yalong Zou <yalongz@hust.edu.cn>
2023-03-15 23:04:21 +08:00
openharmony_ci
4ff66c7f40 !1133 fix: 修复网络容器测试失败问题
Merge pull request !1133 from zhushengle/container_net
2023-03-15 02:10:46 +00:00
zhushengle
8f937c8771 fix: 修复网络容器测试失败问题
1.修复网络容器测试失败问题
2.调整测试用例之间的顺序,提高测试用例的稳定性
3.极限压测用例增加延时,等待系统资源回收,增加用例稳定性
4.优化网络容器测试用例重复代码

Close #I6L7VF
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: If800793430c872c432f5fdf2d9c2d968fafb3973
2023-03-09 14:18:24 +08:00
openharmony_ci
2845efe801 !1129 fix:修复内核调用栈解析脚本bug
Merge pull request !1129 from zhangdengyu/fix_debug_script
2023-03-04 06:21:52 +00:00
openharmony_ci
8cc5209181 !1132 feat:修复使用不规范的测试用例
Merge pull request !1132 from zhangdengyu/muslUpdate0303
2023-03-04 05:55:16 +00:00
zhangdengyu
f995c7c7af feat:修复使用不规范的测试用例
1、在编译kernel/liteos_a测试用例时process、extended、libc三个模块出现报错,主要分为以下几种类型:
   1.1、函数返回值为int或其它类型,错误使用了返回NULL的断言宏。修改断言宏返回正确的类型。
   1.2、函数返回值为int或其它类型,错误的return了NULL。修改成正确的返回值类型。
   1.3、waitpid函数第三个参数为int类型,错误传入了NULL。修改成正确的入参类型。
   1.4、使用的断言宏传入的参数一个为int或其他类型,一个为NULL,类似不匹配。修改成匹配的类型。
   1.5、testsuites/unittest/process/basic/pthread/smoke/pthread_test_012.cpp中调用Syscall接口,
        第二个参数为in类型,错误的传入了NULL。修改入参为正确的类型。
2、hb set选择ipcamera_hispark_taurus,编译之后使用nfs将out/hispark_taurus/ipcamera_hispark_taurus/test/unittest/kernel/bin目录中的
   9个测试用例放到单板上进行测试,运行结果全部通过,并生成对应结果从xml文件,其中liteos_a_basic_unittest.bin无xml文件生成是由于gtest框架升级引入。

Close: #I6J7QK

Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com>
Change-Id: Ifa977658bfc47ba85484e06465735cdffef3dbe2
2023-03-03 13:52:19 +08:00
openharmony_ci
a104497e08 !1127 feature: 内核libc升级
Merge pull request !1127 from Zhaotianyu/20230224libc_update
2023-02-28 11:34:24 +00:00
arvinzzz
b5ae9e25c6 feature: fix liteos_a_newlib_kernel compiler error & libc update
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I4a8c2cfb2ba044f000026f738c6da1781cb7db35
2023-02-28 11:07:14 +08:00
openharmony_ci
c2b5a5897f !1126 feat: 支持网络容器
Merge pull request !1126 from zhushengle/net_container
2023-02-28 03:02:24 +00:00
zhangdengyu
f924cc775b fix:修复内核调用栈解析脚本bug
方案描述:
1、修复内核调用栈解析脚本parse_mem_info.sh的bug,将多余符号(`)去除

BREAKING CHANGE:
无

Close:#I6I6BA

Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com>
Change-Id: I0b0d7e5f6e79313e5f517f89395f4195883cfe06
2023-02-27 19:01:03 +08:00
zhushengle
5dc9a0f1a6 feat: 支持网络容器
BREAKING CHANGE:
支持网络容器对外变更:
1.支持网络容器
2.setns, clone, unshare接口支持CLONE_NEWNET

Close #I6HPH2

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ibaa11056982d465d4006680c8d3fa4ae2b9f25b5
2023-02-25 12:30:09 +08:00
openharmony_ci
806bd80841 !1125 支持容器限额
Merge pull request !1125 from zhushengle/container_limit
2023-02-24 01:09:47 +00:00
zhushengle
c141a92544 feat 支持容器限额
BREAKING CHANGE:
支持容器限额对外变更:
1.在proc目录下增加sys/user目录,支持max_容器_container 配额文件

Close #I6HDQK

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ieaac046182f679a6f49cbdc74593ab39fcb31f5f
2023-02-23 22:16:18 +08:00
openharmony_ci
10c5e2e666 !1124 限制对资源控制器的删除以及添加资源控制器测试用例
Merge pull request !1124 from zhushengle/cgroups_test
2023-02-23 09:02:50 +00:00
zhushengle
da9ce464dd feat: 添加cgroups测试用例
Close #I6H2AR

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I31a432b69ea5fbad137aa1bb947fff4b6fc307df
2023-02-23 16:16:31 +08:00
openharmony_ci
f0a435dce1 !1123 支持资源限额控制器
Merge pull request !1123 from zhushengle/cgroups_2
2023-02-23 03:50:44 +00:00
zhushengle
b45cdbda3e feat: 支持cgroups
BREAKING CHANGE:
支持cgroups对外变更:
1.在proc目录下支持plimits目录,支持ipc, pid, memory, devices, sched控制器

Close #I6GVPL

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ib996e07bf148abce9e40290d6188b763b52e89bb
2023-02-23 09:32:17 +08:00
openharmony_ci
57455849ca !1116 支持用户容器
Merge pull request !1116 from zhushengle/user_container
2023-02-16 12:29:01 +00:00
openharmony_ci
ea825345c2 !1115 修复xts用例失败的问题
Merge pull request !1115 from zhangdengyu/fixXtsTestCase
2023-02-11 08:30:42 +00:00
zhushengle
f397c63fbd feat: 支持user容器
Close #I6EC0A
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I5314959e66090b0614ad8d2058dc9dff4f0031b0
2023-02-11 16:21:59 +08:00
zhangdengyu
fe6ab18cd9 feat:修复xts用例中ActsNFSTest失败的问题
1、在kernel/liteos_a/fs/proc/os_adapt/proc_vfs.c中VfsProcfsRead等接口中,
   使用spin_lock造成使用锁失败。

Close: #I6E3AU

Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com>
Change-Id: I00e57d10bc4e4cf7cbc020903fe229a3aa303ae5
2023-02-11 15:09:08 +08:00
openharmony_ci
c0f5d437d8 !1112 feat: 支持setns接口
Merge pull request !1112 from zhushengle/setns
2023-02-09 12:13:51 +00:00
zhushengle
1ef64e26a1 feat: 支持setns接口
BREAKING CHANGE:
支持setns接口对外变更:
1.新增setns接口

Close #I6D9Y0

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I9aacf9e5b8463e8e6c743a0041a5b2b18fdb0e12
2023-02-09 13:52:54 +08:00
openharmony_ci
77b1b208d1 !1109 Fix : 删除冗余函数
Merge pull request !1109 from yinjiaming/fix
2023-02-08 07:04:45 +00:00
yinjiaming
d17bc9d4ea fix:删除冗余的函数
代码扫描工具发现代码中有被注释的多余函数,现删除。

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: I26980061390924d53c77e467b2cab2f56b192a82
2023-02-07 16:46:31 +08:00
319 changed files with 19169 additions and 1861 deletions

View File

@@ -202,6 +202,10 @@ config("warn_config") {
]
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
cflags += [ "-Wno-address-of-packed-member" ]
cflags += [
"-Wno-unused-but-set-variable",
"-Wno-strict-prototypes",
]
}
asmflags = cflags
}
@@ -250,7 +254,14 @@ config("container_config") {
"-DLOSCFG_CHROOT",
"-DLOSCFG_IPC_CONTAINER",
"-DLOSCFG_TIME_CONTAINER",
"-DLOSCFG_USER_CONTAINER",
"-DLOSCFG_NET_CONTAINER",
"-DLOSCFG_PROC_PROCESS_DIR",
"-DLOSCFG_KERNEL_PLIMITS",
"-DLOSCFG_KERNEL_MEM_PLIMIT",
"-DLOSCFG_KERNEL_IPC_PLIMIT",
"-DLOSCFG_KERNEL_DEV_PLIMIT",
"-DLOSCFG_KERNEL_SCHED_PLIMIT",
]
}
}
@@ -288,7 +299,7 @@ config("public") {
configs += [
"$HDFTOPDIR:public",
"//drivers/liteos:public",
"$DRIVERS_LITEOS_DIR:public",
]
if (HAVE_DEVICE_SDK) {
@@ -313,8 +324,8 @@ group("modules") {
]
deps += [
"//drivers/liteos",
HDFTOPDIR,
"$DRIVERS_LITEOS_DIR",
"$HDFTOPDIR",
]
if (HAVE_DEVICE_SDK) {
@@ -340,7 +351,7 @@ group("liteos_a") {
deps += [
":apps",
":tests",
"//third_party/musl/scripts/build_lite:strip",
"$THIRDPARTY_MUSL_DIR/scripts/build_lite:strip",
]
if (liteos_skip_make == false) {
deps += [ ":make" ]

View File

@@ -8,64 +8,64 @@
* A核代码静态告警定期清理 ([9ba725c](https://gitee.com/openharmony/kernel_liteos_a/commits/9ba725c3d486dd28fe9b2489b0f95a65354d7d86)), closes [#I4I0O8](https://gitee.com/openharmony/kernel_liteos_a/issues/I4I0O8)
* change default permission of procfs to 0550 ([a776c04](https://gitee.com/openharmony/kernel_liteos_a/commits/a776c04a3da414f73ef7136a543c029cc6dd75be)), closes [#I4NY49](https://gitee.com/openharmony/kernel_liteos_a/issues/I4NY49)
* change the execFile field in TCB to execVnode ([e4a0662](https://gitee.com/openharmony/kernel_liteos_a/commits/e4a06623ceb49b5bead60d45c0534db88b9c666f)), closes [#I4CLL9](https://gitee.com/openharmony/kernel_liteos_a/issues/I4CLL9)
* close file when process interpretor failed ([a375bf5](https://gitee.com/openharmony/kernel_liteos_a/commits/a375bf5668a5e86e082d0e124b538e423023a259)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* codex 清理 ([9ab3e35](https://gitee.com/openharmony/kernel_liteos_a/commits/9ab3e351d38cdae2ec083048a50a253bc2a3b604)), closes [#I4BL3](https://gitee.com/openharmony/kernel_liteos_a/issues/I4BL3)
* close file when process interpretor failed ([a375bf5](https://gitee.com/openharmony/kernel_liteos_a/commits/a375bf5668a5e86e082d0e124b538e423023a259)), closes [#I4ATQX](https://gitee.com/openharmony/kernel_liteos_a/issues/I4ATQX)
* codex 清理 ([9ab3e35](https://gitee.com/openharmony/kernel_liteos_a/commits/9ab3e351d38cdae2ec083048a50a253bc2a3b604)), closes [#I4BL3S](https://gitee.com/openharmony/kernel_liteos_a/issues/I4BL3S)
* dyload open close failed ([5e87d8c](https://gitee.com/openharmony/kernel_liteos_a/commits/5e87d8c183471166294e2caa041ab4da8570c6a1)), closes [#I452Z7](https://gitee.com/openharmony/kernel_liteos_a/issues/I452Z7)
* fix ppoll ([a55f68f](https://gitee.com/openharmony/kernel_liteos_a/commits/a55f68f957e9f8ad74bd9e0c1b3d27775e0f8c75))
* fix some function declarations ([63fd8bc](https://gitee.com/openharmony/kernel_liteos_a/commits/63fd8bc39b21fffb6990f74e879eefecafad6c88))
* implicit declaration of function 'syscall' in apps/shell ([bd0c083](https://gitee.com/openharmony/kernel_liteos_a/commits/bd0c0835fc58ed5f941dbbc9adfac74253eeb874))
* LOS_Panic和魔法键功能中的使用PRINTK打印依赖任务调度特殊情况下存在打印不出来的问题 ([53addea](https://gitee.com/openharmony/kernel_liteos_a/commits/53addea304de09e0df457b690403ac652bbcea72)), closes [#I4NOC7](https://gitee.com/openharmony/kernel_liteos_a/issues/I4NOC7)
* los_stat_pri.h中缺少依赖的头文件 ([2cd03c5](https://gitee.com/openharmony/kernel_liteos_a/commits/2cd03c55b7a614c648adc965ebfe494d491fe20f)), closes [#I4KEZ1](https://gitee.com/openharmony/kernel_liteos_a/issues/I4KEZ1)
* los_trace.h接口注释错误修正 ([6d24961](https://gitee.com/openharmony/kernel_liteos_a/commits/6d249618aecc216388f9b1a2b48fe0ac6dd19ff2)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* MMU竞态问题修复 ([748e0d8](https://gitee.com/openharmony/kernel_liteos_a/commits/748e0d8ffb6ee9c8757ed056f575e3abc6c10702)), closes [#I2](https://gitee.com/openharmony/kernel_liteos_a/issues/I2)
* **mtd:** 去除mtd对hisilicon驱动的依赖 ([f7d010d](https://gitee.com/openharmony/kernel_liteos_a/commits/f7d010dfa4cb825096267528e131a9e2735d7505)), closes [#I49](https://gitee.com/openharmony/kernel_liteos_a/issues/I49)
* OsFutexWaitParamCheck函数中absTime为0时直接返回不需要打印 ([3f71be7](https://gitee.com/openharmony/kernel_liteos_a/commits/3f71be75355f11037d9de80cc4d7da0f01905003)), closes [#I4D67](https://gitee.com/openharmony/kernel_liteos_a/issues/I4D67)
* OsLockDepCheckIn异常处理中存在g_lockdepAvailable锁嵌套调用, ([bf030b6](https://gitee.com/openharmony/kernel_liteos_a/commits/bf030b6bb5843151a5b8b8736246a1376a5fb9d0)), closes [#I457](https://gitee.com/openharmony/kernel_liteos_a/issues/I457)
* los_trace.h接口注释错误修正 ([6d24961](https://gitee.com/openharmony/kernel_liteos_a/commits/6d249618aecc216388f9b1a2b48fe0ac6dd19ff2)), closes [#I4CYPZ](https://gitee.com/openharmony/kernel_liteos_a/issues/I4CYPZ)
* MMU竞态问题修复 ([748e0d8](https://gitee.com/openharmony/kernel_liteos_a/commits/748e0d8ffb6ee9c8757ed056f575e3abc6c10702)), closes [#I2WARC](https://gitee.com/openharmony/kernel_liteos_a/issues/I2WARC)
* **mtd:** 去除mtd对hisilicon驱动的依赖 ([f7d010d](https://gitee.com/openharmony/kernel_liteos_a/commits/f7d010dfa4cb825096267528e131a9e2735d7505)), closes [#I49FKL](https://gitee.com/openharmony/kernel_liteos_a/issues/I49FKL)
* OsFutexWaitParamCheck函数中absTime为0时直接返回不需要打印 ([3f71be7](https://gitee.com/openharmony/kernel_liteos_a/commits/3f71be75355f11037d9de80cc4d7da0f01905003)), closes [#I4D67E](https://gitee.com/openharmony/kernel_liteos_a/issues/I4D67E)
* OsLockDepCheckIn异常处理中存在g_lockdepAvailable锁嵌套调用, ([bf030b6](https://gitee.com/openharmony/kernel_liteos_a/commits/bf030b6bb5843151a5b8b8736246a1376a5fb9d0)), closes [#I457ZZ](https://gitee.com/openharmony/kernel_liteos_a/issues/I457ZZ)
* pr模板补充说明 ([e3cd485](https://gitee.com/openharmony/kernel_liteos_a/commits/e3cd485db528490a16a8932d734faab263b44bc9))
* same file mode for procfs files ([c79bcd0](https://gitee.com/openharmony/kernel_liteos_a/commits/c79bcd028e1be34b45cba000077230fa2ef95e68)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* same file mode for procfs files ([c79bcd0](https://gitee.com/openharmony/kernel_liteos_a/commits/c79bcd028e1be34b45cba000077230fa2ef95e68)), closes [#I4ACTC](https://gitee.com/openharmony/kernel_liteos_a/issues/I4ACTC)
* shell支持exit退出完善帮助信息特殊处理不可见字符 ([cc6e112](https://gitee.com/openharmony/kernel_liteos_a/commits/cc6e11281e63b6bdc9be8e5d3c39f1258eb2ceaa))
* smp初始化中副核冗余的启动框架调用 ([5ce70a5](https://gitee.com/openharmony/kernel_liteos_a/commits/5ce70a50c3733b6ec8cc4b444837e366ec837f69)), closes [#I4F8A5](https://gitee.com/openharmony/kernel_liteos_a/issues/I4F8A5)
* solve SIGCHLD ignored in sigsuspend() ([5a80d4e](https://gitee.com/openharmony/kernel_liteos_a/commits/5a80d4e1a34c94204a0bb01443bf25a4fdb12750)), closes [#I47](https://gitee.com/openharmony/kernel_liteos_a/issues/I47)
* solve SIGCHLD ignored in sigsuspend() ([5a80d4e](https://gitee.com/openharmony/kernel_liteos_a/commits/5a80d4e1a34c94204a0bb01443bf25a4fdb12750)), closes [#I47CKK](https://gitee.com/openharmony/kernel_liteos_a/issues/I47CKK)
* syscall review bugfix ([214f44e](https://gitee.com/openharmony/kernel_liteos_a/commits/214f44e935277c29d347c50b553a31ea7df36448)), closes [#149](https://gitee.com/openharmony/kernel_liteos_a/issues/149)
* **test:** misc09用例因依赖hosts文件而失败 ([f2f5c5f](https://gitee.com/openharmony/kernel_liteos_a/commits/f2f5c5fdc3202610de173e7046adab4df5e59142)), closes [re#I48IZ0](https://gitee.com/re/issues/I48IZ0)
* **test:** 修复sys部分用例因依赖passwd、group文件而失败 ([614cdcc](https://gitee.com/openharmony/kernel_liteos_a/commits/614cdccf91bd2d220c4c76418b53400ce714c6cb)), closes [re#I48](https://gitee.com/re/issues/I48)
* 中断中调用PRINTK概率卡死导致系统不能正常响应中断 ([9726ba1](https://gitee.com/openharmony/kernel_liteos_a/commits/9726ba11a79f3d2d1e616e12ef0bb44e4fc5cd20)), closes [#I4C9](https://gitee.com/openharmony/kernel_liteos_a/issues/I4C9)
* **test:** misc09用例因依赖hosts文件而失败 ([f2f5c5f](https://gitee.com/openharmony/kernel_liteos_a/commits/f2f5c5fdc3202610de173e7046adab4df5e59142)), closes [#I48IZ0](https://gitee.com/openharmony/kernel_liteos_a/issues/I48IZ0)
* **test:** 修复sys部分用例因依赖passwd、group文件而失败 ([614cdcc](https://gitee.com/openharmony/kernel_liteos_a/commits/614cdccf91bd2d220c4c76418b53400ce714c6cb)), closes [#I48IUC](https://gitee.com/openharmony/kernel_liteos_a/issues/I48IUC)
* 中断中调用PRINTK概率卡死导致系统不能正常响应中断 ([9726ba1](https://gitee.com/openharmony/kernel_liteos_a/commits/9726ba11a79f3d2d1e616e12ef0bb44e4fc5cd20)), closes [#I4C9GC](https://gitee.com/openharmony/kernel_liteos_a/issues/I4C9GC)
* 临终遗言重定向内容缺失task相关信息对应的shell命令中申请的内存需要cacheline对齐 ([48ca854](https://gitee.com/openharmony/kernel_liteos_a/commits/48ca854bf07f8dcda9657f950601043a485a1b33)), closes [#I482S5](https://gitee.com/openharmony/kernel_liteos_a/issues/I482S5)
* 优化liteipc任务状态删除功能重复字段 ([5004ef4](https://gitee.com/openharmony/kernel_liteos_a/commits/5004ef4d87b54fb6d7f748ca8212ae155bcefac5)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* 优化trace buffer初始化删除swtmr 桩中的无效参数 ([b551270](https://gitee.com/openharmony/kernel_liteos_a/commits/b551270ef50cb206360e2eee3dd20ace5cecccb7)), closes [#I4DQ1](https://gitee.com/openharmony/kernel_liteos_a/issues/I4DQ1)
* 修复 virpart.c 不适配的格式化打印问题 ([de29140](https://gitee.com/openharmony/kernel_liteos_a/commits/de29140edf2567f4847876cb1ed5e0b6857420f3)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* 修复A核文档失效的问题 ([456d255](https://gitee.com/openharmony/kernel_liteos_a/commits/456d255a81c2031be8ebecc2bf897af80c3d3c7a)), closes [#I4U7](https://gitee.com/openharmony/kernel_liteos_a/issues/I4U7)
* 修复A核测试用例失败的问题 ([59329ce](https://gitee.com/openharmony/kernel_liteos_a/commits/59329ce7c6b6a00084df427748e6283287a773c0)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* 修复A核测试用例失败的问题 ([be68dc8](https://gitee.com/openharmony/kernel_liteos_a/commits/be68dc8bcaf8d965039ae1d792775f00a08adfac)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* 优化liteipc任务状态删除功能重复字段 ([5004ef4](https://gitee.com/openharmony/kernel_liteos_a/commits/5004ef4d87b54fb6d7f748ca8212ae155bcefac5)), closes [#I4FVHK](https://gitee.com/openharmony/kernel_liteos_a/issues/I4FVHK)
* 优化trace buffer初始化删除swtmr 桩中的无效参数 ([b551270](https://gitee.com/openharmony/kernel_liteos_a/commits/b551270ef50cb206360e2eee3dd20ace5cecccb7)), closes [#I4DQ1X](https://gitee.com/openharmony/kernel_liteos_a/issues/I4DQ1X)
* 修复 virpart.c 不适配的格式化打印问题 ([de29140](https://gitee.com/openharmony/kernel_liteos_a/commits/de29140edf2567f4847876cb1ed5e0b6857420f3)), closes [#I4PEVP](https://gitee.com/openharmony/kernel_liteos_a/issues/I4PEVP)
* 修复A核文档失效的问题 ([456d255](https://gitee.com/openharmony/kernel_liteos_a/commits/456d255a81c2031be8ebecc2bf897af80c3d3c7a)), closes [#I4U7TF](https://gitee.com/openharmony/kernel_liteos_a/issues/I4U7TF)
* 修复A核测试用例失败的问题 ([59329ce](https://gitee.com/openharmony/kernel_liteos_a/commits/59329ce7c6b6a00084df427748e6283287a773c0)), closes [#I4SQDR](https://gitee.com/openharmony/kernel_liteos_a/issues/I4SQDR)
* 修复A核测试用例失败的问题 ([be68dc8](https://gitee.com/openharmony/kernel_liteos_a/commits/be68dc8bcaf8d965039ae1d792775f00a08adfac)), closes [#I4SQDP](https://gitee.com/openharmony/kernel_liteos_a/issues/I4SQDP)
* 修复dispatch单词拼写错误。 ([9b07aec](https://gitee.com/openharmony/kernel_liteos_a/commits/9b07aece2dfa3494cf35e8b388410341508d6224)), closes [#I4BLE8](https://gitee.com/openharmony/kernel_liteos_a/issues/I4BLE8)
* 修复futime提示错误22的BUG ([f2861dd](https://gitee.com/openharmony/kernel_liteos_a/commits/f2861ddfb424af7b99c278273601ce0fab1f37e6))
* 修复jffs2适配层错误释放锁的BUG ([011a55f](https://gitee.com/openharmony/kernel_liteos_a/commits/011a55ff21d95f969abac60bcff96f4c4d7a326d)), closes [#I4FH9](https://gitee.com/openharmony/kernel_liteos_a/issues/I4FH9)
* 修复los_vm_scan.c中内部函数OsInactiveListIsLow冗余代码 ([bc32a1e](https://gitee.com/openharmony/kernel_liteos_a/commits/bc32a1ec0fa5d19c6d2672bcf4a01de5e1be3afb)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* 修复jffs2适配层错误释放锁的BUG ([011a55f](https://gitee.com/openharmony/kernel_liteos_a/commits/011a55ff21d95f969abac60bcff96f4c4d7a326d)), closes [#I4FH9M](https://gitee.com/openharmony/kernel_liteos_a/issues/I4FH9M)
* 修复los_vm_scan.c中内部函数OsInactiveListIsLow冗余代码 ([bc32a1e](https://gitee.com/openharmony/kernel_liteos_a/commits/bc32a1ec0fa5d19c6d2672bcf4a01de5e1be3afb)), closes [#I4HKFF](https://gitee.com/openharmony/kernel_liteos_a/issues/I4HKFF)
* 修复LOSCFG_FS_FAT_CACHE宏关闭后编译失败的BUG ([63e71fe](https://gitee.com/openharmony/kernel_liteos_a/commits/63e71feca05a8d46a49822c713258738740f0712)), closes [#I3T3N0](https://gitee.com/openharmony/kernel_liteos_a/issues/I3T3N0)
* 修复OsVmPhysFreeListAdd和OsVmPhysFreeListAddUnsafe函数内容重复 ([6827bd2](https://gitee.com/openharmony/kernel_liteos_a/commits/6827bd2a22b78aa05e20d6460412fc7b2d738929)), closes [#I4FL95](https://gitee.com/openharmony/kernel_liteos_a/issues/I4FL95)
* 修复PR520缺陷 ([4033891](https://gitee.com/openharmony/kernel_liteos_a/commits/40338918d9132399ee0494d331930a05b7a13c67)), closes [re#I4DEG5](https://gitee.com/re/issues/I4DEG5)
* 修复shcmd.h需要用宏包起来的问题 ([6c4e4b1](https://gitee.com/openharmony/kernel_liteos_a/commits/6c4e4b16abe9c68fea43d40b2d39b4f0ed4bfc9c)), closes [#I4N50](https://gitee.com/openharmony/kernel_liteos_a/issues/I4N50)
* 修复xts权限用例压测异常问题 ([b0d31cb](https://gitee.com/openharmony/kernel_liteos_a/commits/b0d31cb43f5a8d1c3da574b2b957e3b0e98b3067)), closes [#I3ZJ1](https://gitee.com/openharmony/kernel_liteos_a/issues/I3ZJ1)
* 修复硬随机不可用时,地址随机化不可用问题 ([665c152](https://gitee.com/openharmony/kernel_liteos_a/commits/665c152c27bb86395ddd0395279255f6cdaf7255)), closes [#I4D4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4D4)
* 修复进程用例导致门禁概率失败 ([1ed28b4](https://gitee.com/openharmony/kernel_liteos_a/commits/1ed28b4c80cfd222be08b0c2e71e6287e52bb276)), closes [#I4FO0](https://gitee.com/openharmony/kernel_liteos_a/issues/I4FO0)
* 修复进程线程不稳定用例 ([f6ac03d](https://gitee.com/openharmony/kernel_liteos_a/commits/f6ac03d3e3c56236adc5734d4c059f1fbcc9e0c1)), closes [#I4F1](https://gitee.com/openharmony/kernel_liteos_a/issues/I4F1)
* 修复重复执行内存用例导致系统卡死问题 ([6c2b163](https://gitee.com/openharmony/kernel_liteos_a/commits/6c2b163c7d7c696ef89b17a0275f3cddb3d7cefb)), closes [#I4F7](https://gitee.com/openharmony/kernel_liteos_a/issues/I4F7)
* 修改MMU模块的注释错误 ([1a8e22d](https://gitee.com/openharmony/kernel_liteos_a/commits/1a8e22dcf15944153e013d004fd7bbf24557a8c7)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* 共享内存问题修复 ([9fdb80f](https://gitee.com/openharmony/kernel_liteos_a/commits/9fdb80f85f92d0167a0456455a94fc6f679797ce)), closes [#I47X2](https://gitee.com/openharmony/kernel_liteos_a/issues/I47X2)
* 内核ERR打印无进程和线程信息不方便问题定位。 ([cb423f8](https://gitee.com/openharmony/kernel_liteos_a/commits/cb423f845462b8cc474c3cba261dadf3943a08ef)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* 修复PR520缺陷 ([4033891](https://gitee.com/openharmony/kernel_liteos_a/commits/40338918d9132399ee0494d331930a05b7a13c67)), closes [#I4DEG5](https://gitee.com/openharmony/kernel_liteos_a/issues/I4DEG5)
* 修复shcmd.h需要用宏包起来的问题 ([6c4e4b1](https://gitee.com/openharmony/kernel_liteos_a/commits/6c4e4b16abe9c68fea43d40b2d39b4f0ed4bfc9c)), closes [#I4N50W](https://gitee.com/openharmony/kernel_liteos_a/issues/I4N50W)
* 修复xts权限用例压测异常问题 ([b0d31cb](https://gitee.com/openharmony/kernel_liteos_a/commits/b0d31cb43f5a8d1c3da574b2b957e3b0e98b3067)), closes [#I3ZJ1D](https://gitee.com/openharmony/kernel_liteos_a/issues/I3ZJ1D)
* 修复硬随机不可用时,地址随机化不可用问题 ([665c152](https://gitee.com/openharmony/kernel_liteos_a/commits/665c152c27bb86395ddd0395279255f6cdaf7255)), closes [#I4D4TK](https://gitee.com/openharmony/kernel_liteos_a/issues/I4D4TK)
* 修复进程用例导致门禁概率失败 ([1ed28b4](https://gitee.com/openharmony/kernel_liteos_a/commits/1ed28b4c80cfd222be08b0c2e71e6287e52bb276)), closes [#I4FO0N](https://gitee.com/openharmony/kernel_liteos_a/issues/I4FO0N)
* 修复进程线程不稳定用例 ([f6ac03d](https://gitee.com/openharmony/kernel_liteos_a/commits/f6ac03d3e3c56236adc5734d4c059f1fbcc9e0c1)), closes [#I4F1XL](https://gitee.com/openharmony/kernel_liteos_a/issues/I4F1XL)
* 修复重复执行内存用例导致系统卡死问题 ([6c2b163](https://gitee.com/openharmony/kernel_liteos_a/commits/6c2b163c7d7c696ef89b17a0275f3cddb3d7cefb)), closes [#I4F7PO](https://gitee.com/openharmony/kernel_liteos_a/issues/I4F7PO)
* 修改MMU模块的注释错误 ([1a8e22d](https://gitee.com/openharmony/kernel_liteos_a/commits/1a8e22dcf15944153e013d004fd7bbf24557a8c7)), closes [#I4KMMJ](https://gitee.com/openharmony/kernel_liteos_a/issues/I4KMMJ)
* 共享内存问题修复 ([9fdb80f](https://gitee.com/openharmony/kernel_liteos_a/commits/9fdb80f85f92d0167a0456455a94fc6f679797ce)), closes [#I47X2Z](https://gitee.com/openharmony/kernel_liteos_a/issues/I47X2Z)
* 内核ERR打印无进程和线程信息不方便问题定位。 ([cb423f8](https://gitee.com/openharmony/kernel_liteos_a/commits/cb423f845462b8cc474c3cba261dadf3943a08ef)), closes [#I4DAKM](https://gitee.com/openharmony/kernel_liteos_a/issues/I4DAKM)
* 内核ERR级别及以上的打印输出当前进程和线程名 ([540b201](https://gitee.com/openharmony/kernel_liteos_a/commits/540b2017c5460e300365d2039a08abd5945cec6b))
* 内源检视测试用例问题修复 ([a6ac759](https://gitee.com/openharmony/kernel_liteos_a/commits/a6ac7597f85043ba6de3a1b395ca676d85c65ea7))
* 删除冗余的头文件 ([8e614bb](https://gitee.com/openharmony/kernel_liteos_a/commits/8e614bb1616b75bc89eee7ad7da49b7a9c285b47)), closes [#I4KN63](https://gitee.com/openharmony/kernel_liteos_a/issues/I4KN63)
* 增加pselect SYSCALL函数及测试用例 ([f601c16](https://gitee.com/openharmony/kernel_liteos_a/commits/f601c16b9e67d531dda51fc18389a53db4360b7b)), closes [#I45](https://gitee.com/openharmony/kernel_liteos_a/issues/I45)
* 增加内核epoll系统调用 ([2251b8a](https://gitee.com/openharmony/kernel_liteos_a/commits/2251b8a2d1f649422dd67f8551b085a7e0c63ec7)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* 实现了musl库net模块中的一些函数接口和相应的测试用例 ([3d00a7d](https://gitee.com/openharmony/kernel_liteos_a/commits/3d00a7d23a96f29c138cfc1672825b90b9e0c05e)), closes [#I4JQI1](https://gitee.com/openharmony/kernel_liteos_a/issues/I4JQI1)
* 添加进程线程冒烟用例 ([2be5968](https://gitee.com/openharmony/kernel_liteos_a/commits/2be59680f2fb0801b43522cd38cc387c8ff38766)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* 用户态进程主线程退出时,其他子线程刚好进入异常处理流程会导致系统卡死 ([d955790](https://gitee.com/openharmony/kernel_liteos_a/commits/d955790a44a679421798ec1ac2900b4d75dd75a4)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* 增加pselect SYSCALL函数及测试用例 ([f601c16](https://gitee.com/openharmony/kernel_liteos_a/commits/f601c16b9e67d531dda51fc18389a53db4360b7b)), closes [#I45SXU](https://gitee.com/openharmony/kernel_liteos_a/issues/I45SXU)
* 增加内核epoll系统调用 ([2251b8a](https://gitee.com/openharmony/kernel_liteos_a/commits/2251b8a2d1f649422dd67f8551b085a7e0c63ec7)), closes [#I4FXPT](https://gitee.com/openharmony/kernel_liteos_a/issues/I4FXPT)
* 实现了musl库net模块中的一些函数接口和相应的测试用例 ([3d00a7d](https://gitee.com/openharmony/kernel_liteos_a/commits/3d00a7d23a96f29c138cfc1672825b90b9e0c05e)), closes [#I4JQI1](https://gitee.com/openharmony/third_party_musl/issues/I4JQI1)
* 添加进程线程冒烟用例 ([2be5968](https://gitee.com/openharmony/kernel_liteos_a/commits/2be59680f2fb0801b43522cd38cc387c8ff38766)), closes [#I4EOGA](https://gitee.com/openharmony/kernel_liteos_a/issues/I4EOGA)
* 用户态进程主线程退出时,其他子线程刚好进入异常处理流程会导致系统卡死 ([d955790](https://gitee.com/openharmony/kernel_liteos_a/commits/d955790a44a679421798ec1ac2900b4d75dd75a4)), closes [#I4KGBT](https://gitee.com/openharmony/kernel_liteos_a/issues/I4KGBT)
* 编码规范修改 ([d161a0b](https://gitee.com/openharmony/kernel_liteos_a/commits/d161a0b03de046c05fff45a2b625631b4e45a347))
* 编码规范问题修复 ([f60bc94](https://gitee.com/openharmony/kernel_liteos_a/commits/f60bc94cf231bc615ff6603ca0393b8fe33a8c47))
* 编译框架在做编译入口的统一 ([bdb9864](https://gitee.com/openharmony/kernel_liteos_a/commits/bdb9864436a6f128a4c3891bbd63e3c60352689f)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* 解决dmesg -s参数double lock问题 ([e151256](https://gitee.com/openharmony/kernel_liteos_a/commits/e1512566e322eb1fbc8f5d5997f9bfcd022feac7)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* 进程退出前自己回收vmspace中的所有region ([298ccea](https://gitee.com/openharmony/kernel_liteos_a/commits/298ccea3fedaccc651b38973f0455fa1ce12e516)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* 编译框架在做编译入口的统一 ([bdb9864](https://gitee.com/openharmony/kernel_liteos_a/commits/bdb9864436a6f128a4c3891bbd63e3c60352689f)), closes [#I4KRQN](https://gitee.com/openharmony/kernel_liteos_a/issues/I4KRQN)
* 解决dmesg -s参数double lock问题 ([e151256](https://gitee.com/openharmony/kernel_liteos_a/commits/e1512566e322eb1fbc8f5d5997f9bfcd022feac7)), closes [#I4HIJK](https://gitee.com/openharmony/kernel_liteos_a/issues/I4HIJK)
* 进程退出前自己回收vmspace中的所有region ([298ccea](https://gitee.com/openharmony/kernel_liteos_a/commits/298ccea3fedaccc651b38973f0455fa1ce12e516)), closes [#I4CKQC](https://gitee.com/openharmony/kernel_liteos_a/issues/I4CKQC)
* 通过g_uart_fputc_en关闭打印后shell进程不能正常启动 ([d21b05c](https://gitee.com/openharmony/kernel_liteos_a/commits/d21b05c0f69877130366ad37b852a0f30c11809d)), closes [#I4CTY2](https://gitee.com/openharmony/kernel_liteos_a/issues/I4CTY2)
* 针对pr是否同步至release分支增加原因说明规则 ([b37a7b7](https://gitee.com/openharmony/kernel_liteos_a/commits/b37a7b79292d93dae6c4914952b5f3bb509e8721))
* 非当前进程销毁时销毁liteipc时错误的销毁了当前进程的liteipc资源 ([0f0e85b](https://gitee.com/openharmony/kernel_liteos_a/commits/0f0e85b7a6bf76d540925fbf661c483c8dba1cba)), closes [#I4FSA7](https://gitee.com/openharmony/kernel_liteos_a/issues/I4FSA7)
@@ -79,22 +79,22 @@
### Features
* add option SIOCGIFBRDADDR for ioctl ([4ecc473](https://gitee.com/openharmony/kernel_liteos_a/commits/4ecc473843207d259613d26b8ee176d75e7f00fd)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* add sync() to vfs ([f67c4da](https://gitee.com/openharmony/kernel_liteos_a/commits/f67c4dae5141914df2e069dce0196b14780649d8)), closes [#I480](https://gitee.com/openharmony/kernel_liteos_a/issues/I480)
* add option SIOCGIFBRDADDR for ioctl ([4ecc473](https://gitee.com/openharmony/kernel_liteos_a/commits/4ecc473843207d259613d26b8ee176d75e7f00fd)), closes [#I4DNRF](https://gitee.com/openharmony/kernel_liteos_a/issues/I4DNRF)
* add sync() to vfs ([f67c4da](https://gitee.com/openharmony/kernel_liteos_a/commits/f67c4dae5141914df2e069dce0196b14780649d8)), closes [#I480HV](https://gitee.com/openharmony/kernel_liteos_a/issues/I480HV)
* **build:** support gcc toolchain ([6e886d4](https://gitee.com/openharmony/kernel_liteos_a/commits/6e886d4233dec3b82a27642f174b920e5f98f6aa))
* L0-L1 支持Perf ([6e0a3f1](https://gitee.com/openharmony/kernel_liteos_a/commits/6e0a3f10bbbfe29d110c050da927684b6d77b961)), closes [#I47I9](https://gitee.com/openharmony/kernel_liteos_a/issues/I47I9)
* L0~L1 支持Lms ([e748fdb](https://gitee.com/openharmony/kernel_liteos_a/commits/e748fdbe578a1ddd8eb10b2e207042676231ba26)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* liteipc 静态内存优化 ([5237924](https://gitee.com/openharmony/kernel_liteos_a/commits/52379242c109e0cf442784dbe811ff9d42d5f33a)), closes [#I4G4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4G4)
* page cache backed by vnode instead of filep ([38a6b80](https://gitee.com/openharmony/kernel_liteos_a/commits/38a6b804e9291d2fdbd189825ebd7d56165ec51c)), closes [#I44](https://gitee.com/openharmony/kernel_liteos_a/issues/I44)
* L0-L1 支持Perf ([6e0a3f1](https://gitee.com/openharmony/kernel_liteos_a/commits/6e0a3f10bbbfe29d110c050da927684b6d77b961)), closes [#I47I9A](https://gitee.com/openharmony/kernel_liteos_a/issues/I47I9A)
* L0~L1 支持Lms ([e748fdb](https://gitee.com/openharmony/kernel_liteos_a/commits/e748fdbe578a1ddd8eb10b2e207042676231ba26)), closes [#I4HYAV](https://gitee.com/openharmony/kernel_liteos_a/issues/I4HYAV)
* liteipc 静态内存优化 ([5237924](https://gitee.com/openharmony/kernel_liteos_a/commits/52379242c109e0cf442784dbe811ff9d42d5f33a)), closes [#I4G4HP](https://gitee.com/openharmony/kernel_liteos_a/issues/I4G4HP)
* page cache backed by vnode instead of filep ([38a6b80](https://gitee.com/openharmony/kernel_liteos_a/commits/38a6b804e9291d2fdbd189825ebd7d56165ec51c)), closes [#I44TBS](https://gitee.com/openharmony/kernel_liteos_a/issues/I44TBS)
* 提供低功耗默认处理框架 ([212d1bd](https://gitee.com/openharmony/kernel_liteos_a/commits/212d1bd1e806530fe7e7a16ea986cb2c6fb084ed)), closes [#I4KBG9](https://gitee.com/openharmony/kernel_liteos_a/issues/I4KBG9)
* 支持AT_RANDOM以增强用户态栈保护能力 ([06ea037](https://gitee.com/openharmony/kernel_liteos_a/commits/06ea03715f0cfb8728fadd0d9c19a403dc8f6028)), closes [#I4CB8](https://gitee.com/openharmony/kernel_liteos_a/issues/I4CB8)
* 支持L1 低功耗框架 ([64e49ab](https://gitee.com/openharmony/kernel_liteos_a/commits/64e49aba7c9c7d2280c5b3f29f04b17b63209855)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* 支持LOS_TaskJoin 和 LOS_TaskDetach ([37bc11f](https://gitee.com/openharmony/kernel_liteos_a/commits/37bc11fa8837a3019a0a56702f401ec1845f6547)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* 新增解析异常和backtrace信息脚本 ([7019fdf](https://gitee.com/openharmony/kernel_liteos_a/commits/7019fdfcbb33c660e8aa9fd399d5fccbd7e23b49)), closes [#I47](https://gitee.com/openharmony/kernel_liteos_a/issues/I47)
* 支持AT_RANDOM以增强用户态栈保护能力 ([06ea037](https://gitee.com/openharmony/kernel_liteos_a/commits/06ea03715f0cfb8728fadd0d9c19a403dc8f6028)), closes [#I4CB8M](https://gitee.com/openharmony/kernel_liteos_a/issues/I4CB8M)
* 支持L1 低功耗框架 ([64e49ab](https://gitee.com/openharmony/kernel_liteos_a/commits/64e49aba7c9c7d2280c5b3f29f04b17b63209855)), closes [#I4JSOT](https://gitee.com/openharmony/kernel_liteos_a/issues/I4JSOT)
* 支持LOS_TaskJoin 和 LOS_TaskDetach ([37bc11f](https://gitee.com/openharmony/kernel_liteos_a/commits/37bc11fa8837a3019a0a56702f401ec1845f6547)), closes [#I4EENF](https://gitee.com/openharmony/kernel_liteos_a/issues/I4EENF)
* 新增解析异常和backtrace信息脚本 ([7019fdf](https://gitee.com/openharmony/kernel_liteos_a/commits/7019fdfcbb33c660e8aa9fd399d5fccbd7e23b49)), closes [#I47EVQ](https://gitee.com/openharmony/kernel_liteos_a/issues/I47EVQ)
* 调度tick响应时间计算优化 ([f47da44](https://gitee.com/openharmony/kernel_liteos_a/commits/f47da44b39be7fa3e9b5031d7b79b9bef1fd4fbc))
* 调度去进程化,优化进程线程依赖关系 ([dc479fb](https://gitee.com/openharmony/kernel_liteos_a/commits/dc479fb7bd9cb8441e4e47d44b42110ea07d76a2))
* 调度相关模块间依赖优化 ([0e3936c](https://gitee.com/openharmony/kernel_liteos_a/commits/0e3936c4f8b8bcfc48d283a6d53413e0fc0619b3)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* 进程cpup占用率结构优化为动态分配 ([f06e090](https://gitee.com/openharmony/kernel_liteos_a/commits/f06e090a1085a654fd726fbc3c3a1c2bc703d663)), closes [#I4](https://gitee.com/openharmony/kernel_liteos_a/issues/I4)
* 调度相关模块间依赖优化 ([0e3936c](https://gitee.com/openharmony/kernel_liteos_a/commits/0e3936c4f8b8bcfc48d283a6d53413e0fc0619b3)), closes [#I4RPRW](https://gitee.com/openharmony/kernel_liteos_a/issues/I4RPRW)
* 进程cpup占用率结构优化为动态分配 ([f06e090](https://gitee.com/openharmony/kernel_liteos_a/commits/f06e090a1085a654fd726fbc3c3a1c2bc703d663)), closes [#I4GLNT](https://gitee.com/openharmony/kernel_liteos_a/issues/I4GLNT)
* 进程rlimit修改为动态分配,减少静态内存占用 ([cf8446c](https://gitee.com/openharmony/kernel_liteos_a/commits/cf8446c94112ed6993a2e6e71e793d83a72689d5)), closes [#I4EZY5](https://gitee.com/openharmony/kernel_liteos_a/issues/I4EZY5)
### BREAKING CHANGES
@@ -137,33 +137,33 @@ LOS_LmsAddrDisableProtect去能指定内存段的访问保护
### Bug Fixes
* A核代码告警清零 ([698756d](https://gitee.com/openharmony/kernel_liteos_a/commits/698756d1e6dfb11b9f874c02ce6a1496646f2c27)), closes [#I4378](https://gitee.com/openharmony/kernel_liteos_a/issues/I4378)
* A核代码告警清零 ([698756d](https://gitee.com/openharmony/kernel_liteos_a/commits/698756d1e6dfb11b9f874c02ce6a1496646f2c27)), closes [#I4378T](https://gitee.com/openharmony/kernel_liteos_a/issues/I4378T)
* A核告警消除 ([d16bfd0](https://gitee.com/openharmony/kernel_liteos_a/commits/d16bfd005a6dae78df2df3ad55cf21e0716dfae9)), closes [#I46KF6](https://gitee.com/openharmony/kernel_liteos_a/issues/I46KF6)
* 3518平台, 异常测试进程无法正常退出 ([23937a2](https://gitee.com/openharmony/kernel_liteos_a/commits/23937a239f50d1487e89f3184e4f4b933d6842c6)), closes [#I3V8R5](https://gitee.com/openharmony/kernel_liteos_a/issues/I3V8R5)
* add (void) to GetFileMappingList method ([56b8eca](https://gitee.com/openharmony/kernel_liteos_a/commits/56b8ecaf171671c0fe97f1dd1f191bebb7812a51)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* add (void) to GetFileMappingList method ([56b8eca](https://gitee.com/openharmony/kernel_liteos_a/commits/56b8ecaf171671c0fe97f1dd1f191bebb7812a51)), closes [#I3XPXY](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XPXY)
* add capability and amend smoke testcase ([c9d69e2](https://gitee.com/openharmony/kernel_liteos_a/commits/c9d69e2d1bde57c67068cc36f6a79327d5db5daf))
* add fchdir api ([e828cbd](https://gitee.com/openharmony/kernel_liteos_a/commits/e828cbdeac7d60bfd6ed98c75a9958ee8ec7b672))
* add fchmod api ([2f214bf](https://gitee.com/openharmony/kernel_liteos_a/commits/2f214bf4de6c31875c77e84b1763e96bc5ceb669))
* add fststfs api and unitest ([4c57aa2](https://gitee.com/openharmony/kernel_liteos_a/commits/4c57aa26ad3644ce2429effc8e8fe7fd3c52ebc2))
* add product_path parameter for driver build ([88fe4eb](https://gitee.com/openharmony/kernel_liteos_a/commits/88fe4eb3e1eafa6d1e32c7b96579a07f5a8c6e35)), closes [#I3PQ10](https://gitee.com/openharmony/kernel_liteos_a/issues/I3PQ10)
* add product_path parameter for driver build ([88fe4eb](https://gitee.com/openharmony/kernel_liteos_a/commits/88fe4eb3e1eafa6d1e32c7b96579a07f5a8c6e35)), closes [#I3PQ10](https://gitee.com/openharmony/drivers_adapter/issues/I3PQ10)
* add syscall for ppoll & add 2 testcases ([defedb6](https://gitee.com/openharmony/kernel_liteos_a/commits/defedb6fdf0806da4a39e22408544cdfb405f2ff))
* avoid compile warning ignored ([eca711b](https://gitee.com/openharmony/kernel_liteos_a/commits/eca711bb64a7c806ae34c8483cac73fe22b0104f)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* A核codex修改 ([ec977a1](https://gitee.com/openharmony/kernel_liteos_a/commits/ec977a1c7e9ba4ea6621ceb1d0d10e586148208d)), closes [#I40B1](https://gitee.com/openharmony/kernel_liteos_a/issues/I40B1)
* BBOX使用预留物理内存缓存故障日志 ([2ad176e](https://gitee.com/openharmony/kernel_liteos_a/commits/2ad176e587d5ed7106831a25d386a88e26192e2b)), closes [#I41](https://gitee.com/openharmony/kernel_liteos_a/issues/I41)
* avoid compile warning ignored ([eca711b](https://gitee.com/openharmony/kernel_liteos_a/commits/eca711bb64a7c806ae34c8483cac73fe22b0104f)), closes [#I3VOAO](https://gitee.com/openharmony/kernel_liteos_a/issues/I3VOAO)
* A核codex修改 ([ec977a1](https://gitee.com/openharmony/kernel_liteos_a/commits/ec977a1c7e9ba4ea6621ceb1d0d10e586148208d)), closes [#I40B1S](https://gitee.com/openharmony/kernel_liteos_a/issues/I40B1S)
* BBOX使用预留物理内存缓存故障日志 ([2ad176e](https://gitee.com/openharmony/kernel_liteos_a/commits/2ad176e587d5ed7106831a25d386a88e26192e2b)), closes [#I41YIZ](https://gitee.com/openharmony/kernel_liteos_a/issues/I41YIZ)
* bootargs解析与rootfs挂载解耦并支持自定义bootargs参数 ([80473f0](https://gitee.com/openharmony/kernel_liteos_a/commits/80473f0975fe6fd4c4eae3a8a473674ad2dd1293)), closes [#I41CL8](https://gitee.com/openharmony/kernel_liteos_a/issues/I41CL8)
* **build:** clang10.0.1支持lto去掉冗余判断 ([73223ae](https://gitee.com/openharmony/kernel_liteos_a/commits/73223ae7e652b7cd9f1e1848c32b2b2573d07b2a))
* **build:** fix rootfsdir.sh target directory not exist ([21bf2b8](https://gitee.com/openharmony/kernel_liteos_a/commits/21bf2b889931787fb18ca7ea238291fd57e76d51)), closes [#I3NHQ0](https://gitee.com/openharmony/kernel_liteos_a/issues/I3NHQ0)
* **build:** 去除冗余单板相关的宏配置 ([471de36](https://gitee.com/openharmony/kernel_liteos_a/commits/471de3663ea8b63f7448162edc0293b8723dcefc))
* clang10 lld could not recognized Oz ([87a0006](https://gitee.com/openharmony/kernel_liteos_a/commits/87a0006d5e1976fdf5efe4be383921610eb04ec6))
* clang相关编译选项隔离 ([77dcef4](https://gitee.com/openharmony/kernel_liteos_a/commits/77dcef4bc0c92d0141f7a3be0addd4d5cb533b0b)), closes [#I444](https://gitee.com/openharmony/kernel_liteos_a/issues/I444)
* clang相关编译选项隔离 ([77dcef4](https://gitee.com/openharmony/kernel_liteos_a/commits/77dcef4bc0c92d0141f7a3be0addd4d5cb533b0b)), closes [#I444AV](https://gitee.com/openharmony/kernel_liteos_a/issues/I444AV)
* codex ([101a55d](https://gitee.com/openharmony/kernel_liteos_a/commits/101a55d1199530d621f809976f0024aa8295cce8))
* codex clean ([b5370af](https://gitee.com/openharmony/kernel_liteos_a/commits/b5370af822c8e81ed2248ac8aa3bb479a0db9dae)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* codex clean ([b5370af](https://gitee.com/openharmony/kernel_liteos_a/commits/b5370af822c8e81ed2248ac8aa3bb479a0db9dae)), closes [#I3UOFN](https://gitee.com/openharmony/kernel_liteos_a/issues/I3UOFN)
* compile error when fatfs disabled ([fd3f407](https://gitee.com/openharmony/kernel_liteos_a/commits/fd3f4072b5c3dff710013ccdaddf114b0e13f435))
* console compile bug fix ([f8441a0](https://gitee.com/openharmony/kernel_liteos_a/commits/f8441a0cdea301449416b0c0477dc48a05b6ab4e))
* correct spelling ([c66fe03](https://gitee.com/openharmony/kernel_liteos_a/commits/c66fe0313f76ba41992b4864c93cf82934378ad3))
* Correctly handle the return value of LOS_EventRead in QuickstartListen. ([0e0ab81](https://gitee.com/openharmony/kernel_liteos_a/commits/0e0ab81ff9474cffd5e60a8ee741840eac5d737b)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* Correctly handle the return value of LOS_EventRead in QuickstartListen. ([0e0ab81](https://gitee.com/openharmony/kernel_liteos_a/commits/0e0ab81ff9474cffd5e60a8ee741840eac5d737b)), closes [#I3PSLZ](https://gitee.com/openharmony/kernel_liteos_a/issues/I3PSLZ)
* Ctrl-C move out of LOS_MAGIC_KEY_ENABLE ([40f239a](https://gitee.com/openharmony/kernel_liteos_a/commits/40f239a7d4673dc740c853b1011b5072e48385b7))
* Delete useless 'exc interaction' macros and function declarations. ([d2f2679](https://gitee.com/openharmony/kernel_liteos_a/commits/d2f26790716c9f76589c4a7d6fa5518f9ccd743c)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* Delete useless 'exc interaction' macros and function declarations. ([d2f2679](https://gitee.com/openharmony/kernel_liteos_a/commits/d2f26790716c9f76589c4a7d6fa5518f9ccd743c)), closes [#I3SDKY](https://gitee.com/openharmony/kernel_liteos_a/issues/I3SDKY)
* dereference NULL point bug fix ([deaa564](https://gitee.com/openharmony/kernel_liteos_a/commits/deaa564a66b83c9fe19a37b8a061ec9064ece354))
* do not build toybox temporarily ([044f2c7](https://gitee.com/openharmony/kernel_liteos_a/commits/044f2c7c17c68e10aeccc3af0c222cfc722d194c))
* do not override existing libs ([8118408](https://gitee.com/openharmony/kernel_liteos_a/commits/8118408123e75f7f5a4ab9101e388be6bba0dcda))
@@ -173,21 +173,21 @@ LOS_LmsAddrDisableProtect去能指定内存段的访问保护
* Fix kernel page fault exception handling causing system exception. ([a89fb57](https://gitee.com/openharmony/kernel_liteos_a/commits/a89fb57f5795236b93fd19ee2d7a059cae1b2b1b)), closes [#I3RAN4](https://gitee.com/openharmony/kernel_liteos_a/issues/I3RAN4)
* fix length typo ([12d98b1](https://gitee.com/openharmony/kernel_liteos_a/commits/12d98b144b70e726d3fd31ddc9d17ed855d0ec1b))
* fix mq function by enable mq_notify api ([4427142](https://gitee.com/openharmony/kernel_liteos_a/commits/4427142d734df8f95f4599093392904abacc5c93))
* Fix quickstart codingstyle ([2e011b6](https://gitee.com/openharmony/kernel_liteos_a/commits/2e011b672f6b96ea7e0db066a07e3f9fb6ba5df3)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* Fix quickstart codingstyle ([2e011b6](https://gitee.com/openharmony/kernel_liteos_a/commits/2e011b672f6b96ea7e0db066a07e3f9fb6ba5df3)), closes [#I3OPOM](https://gitee.com/openharmony/kernel_liteos_a/issues/I3OPOM)
* fix stored typo ([d25560f](https://gitee.com/openharmony/kernel_liteos_a/commits/d25560f8ac3216670d198cbbb25891c394e0b3c2))
* fix syscall faccessat,fstatfs,fstatat & add 6 testcases ([aa1cd24](https://gitee.com/openharmony/kernel_liteos_a/commits/aa1cd245a5711e5b53c328b688da5ddc2e783d5f))
* fix the inappropriate errno in FatFs ([af61187](https://gitee.com/openharmony/kernel_liteos_a/commits/af61187587411dca38ff62e720451f08f19c1c82)), closes [#I3O8](https://gitee.com/openharmony/kernel_liteos_a/issues/I3O8)
* fix the inappropriate errno in FatFs ([af61187](https://gitee.com/openharmony/kernel_liteos_a/commits/af61187587411dca38ff62e720451f08f19c1c82)), closes [#I3O8IF](https://gitee.com/openharmony/kernel_liteos_a/issues/I3O8IF)
* fix typo in quickstart ([3b2ff4b](https://gitee.com/openharmony/kernel_liteos_a/commits/3b2ff4b71fc5ae1dc74180c33fd66f69da0059d1)), closes [#I3M1S8](https://gitee.com/openharmony/kernel_liteos_a/issues/I3M1S8)
* Fix wrong judgment in los_trace.c to avoid null pointer access. ([4d863e9](https://gitee.com/openharmony/kernel_liteos_a/commits/4d863e985b6372f7895db57b602b662dba5cadd0)), closes [#I3RT9](https://gitee.com/openharmony/kernel_liteos_a/issues/I3RT9)
* Fix wrong judgment in los_trace.c to avoid null pointer access. ([4d863e9](https://gitee.com/openharmony/kernel_liteos_a/commits/4d863e985b6372f7895db57b602b662dba5cadd0)), closes [#I3RT9F](https://gitee.com/openharmony/kernel_liteos_a/issues/I3RT9F)
* Identical condition 'ret<0', second condition is always false. :bug: ([1348809](https://gitee.com/openharmony/kernel_liteos_a/commits/1348809807548dd481286a55a6677a9169fcd705))
* init进程收到子进程退出信号后调用fork重新拉起进程会导致系统卡死 ([35a2f3a](https://gitee.com/openharmony/kernel_liteos_a/commits/35a2f3af33a5dba1e0ba36587efced8fead97223)), closes [#I41](https://gitee.com/openharmony/kernel_liteos_a/issues/I41)
* init进程收到子进程退出信号后调用fork重新拉起进程会导致系统卡死 ([35a2f3a](https://gitee.com/openharmony/kernel_liteos_a/commits/35a2f3af33a5dba1e0ba36587efced8fead97223)), closes [#I41HOY](https://gitee.com/openharmony/kernel_liteos_a/issues/I41HOY)
* kernel crashed after rmdir the umounted folder ([ac0d083](https://gitee.com/openharmony/kernel_liteos_a/commits/ac0d083b1c89c4ad3fdaab0347d11f174d0185cb))
* kernel crashed when delete a umounted folder ([f305d1f](https://gitee.com/openharmony/kernel_liteos_a/commits/f305d1f702a770010125a0f4f0152ffefeeec5c4))
* kernel crashed when delete a umounted folder ([c6e9212](https://gitee.com/openharmony/kernel_liteos_a/commits/c6e921241b1cf26bcbfeea44e20f6b596512e259))
* **kernel_test:** 内核mem/shm冒烟用例重复运行失败 ([0676578](https://gitee.com/openharmony/kernel_liteos_a/commits/0676578aae09c101d79e7a276823e849df293e29)), closes [#I3TH4](https://gitee.com/openharmony/kernel_liteos_a/issues/I3TH4)
* L1 toybox 命令功能实现 ([2ff44c4](https://gitee.com/openharmony/kernel_liteos_a/commits/2ff44c4938d2e66ce60e9497c505eb6e97efc8c2)), closes [#I41N2](https://gitee.com/openharmony/kernel_liteos_a/issues/I41N2)
* **kernel_test:** 内核mem/shm冒烟用例重复运行失败 ([0676578](https://gitee.com/openharmony/kernel_liteos_a/commits/0676578aae09c101d79e7a276823e849df293e29)), closes [#I3TH4W](https://gitee.com/openharmony/kernel_liteos_a/issues/I3TH4W)
* L1 toybox 命令功能实现 ([2ff44c4](https://gitee.com/openharmony/kernel_liteos_a/commits/2ff44c4938d2e66ce60e9497c505eb6e97efc8c2)), closes [#I41N2A](https://gitee.com/openharmony/third_party_toybox/issues/I41N2A)
* liteipc max data size too small ([4dc421e](https://gitee.com/openharmony/kernel_liteos_a/commits/4dc421e3decdaae60219d533c4a93dbc9334e35f))
* LiteOS_A BBOX Codex整改 ([6a5a032](https://gitee.com/openharmony/kernel_liteos_a/commits/6a5a0326d2b18ffacce5d38fb351530973c2f245)), closes [#I43](https://gitee.com/openharmony/kernel_liteos_a/issues/I43)
* LiteOS_A BBOX Codex整改 ([6a5a032](https://gitee.com/openharmony/kernel_liteos_a/commits/6a5a0326d2b18ffacce5d38fb351530973c2f245)), closes [#I43RQU](https://gitee.com/openharmony/kernel_liteos_a/issues/I43RQU)
* Liteos-a创建的文件夹在Ubuntu中不可见 ([a9fc1e0](https://gitee.com/openharmony/kernel_liteos_a/commits/a9fc1e0e5d3e5eb8a34c568a8d147320a9afebe1)), closes [#I3XMY6](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XMY6)
* lookup new vnode may cause parent vnode freeing ([902a11d](https://gitee.com/openharmony/kernel_liteos_a/commits/902a11de9a4b08e799820fb87942cb2171b9e095)), closes [#I3MYP4](https://gitee.com/openharmony/kernel_liteos_a/issues/I3MYP4)
* **mini:** fix compile error in mini liteos_a ([e13cb3b](https://gitee.com/openharmony/kernel_liteos_a/commits/e13cb3bcc4e74d4c49c31d290d686f99a4e81e3f))
@@ -196,117 +196,117 @@ LOS_LmsAddrDisableProtect去能指定内存段的访问保护
* mkdir -p is more robust ([e38f9a9](https://gitee.com/openharmony/kernel_liteos_a/commits/e38f9a98c9d373db8381af707c5996d1fefef64e))
* mksh compile bug fix ([d8263b1](https://gitee.com/openharmony/kernel_liteos_a/commits/d8263b1e91d76706d52df321ef642c1c8297e8e4)), closes [#I3ZMR7](https://gitee.com/openharmony/kernel_liteos_a/issues/I3ZMR7)
* modify event API description ([937734b](https://gitee.com/openharmony/kernel_liteos_a/commits/937734b1e9f5fc52e0ac727549bd2e4b4c864e3c))
* move nuttx head file back ([4c8a86e](https://gitee.com/openharmony/kernel_liteos_a/commits/4c8a86ece7cafa8f74441bacc74c7788c0a1b780)), closes [#I4443](https://gitee.com/openharmony/kernel_liteos_a/issues/I4443)
* nanosleep 接口的rmtp参数被错误清零 ([9458de9](https://gitee.com/openharmony/kernel_liteos_a/commits/9458de9ac664cd75540c8b638b9a6caf82812fc8)), closes [#I41U0](https://gitee.com/openharmony/kernel_liteos_a/issues/I41U0)
* move nuttx head file back ([4c8a86e](https://gitee.com/openharmony/kernel_liteos_a/commits/4c8a86ece7cafa8f74441bacc74c7788c0a1b780)), closes [#I4443Q](https://gitee.com/openharmony/kernel_liteos_a/issues/I4443Q)
* nanosleep 接口的rmtp参数被错误清零 ([9458de9](https://gitee.com/openharmony/kernel_liteos_a/commits/9458de9ac664cd75540c8b638b9a6caf82812fc8)), closes [#I41U0R](https://gitee.com/openharmony/kernel_liteos_a/issues/I41U0R)
* no exception information output, when the system is abnormal ([5bf4d1c](https://gitee.com/openharmony/kernel_liteos_a/commits/5bf4d1c7128e6718611bbec23cb4373bcb3bfe55))
* no exception information output, when the system is abnormal ([28aa777](https://gitee.com/openharmony/kernel_liteos_a/commits/28aa777191e7b41e4f1f346ab79f8688edc59c6d))
* no exception information output, when the system is abnormal after holding ([0ed8adf](https://gitee.com/openharmony/kernel_liteos_a/commits/0ed8adfe3ae59672e284331d40ef3b9e0bc8e094))
* Optimiz macro of quickstart cmd ([cb140a4](https://gitee.com/openharmony/kernel_liteos_a/commits/cb140a4442c02dd0b1925cc58deecbf4da36dcea)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* Optimize /dev/quickstart permissions. ([4e24b57](https://gitee.com/openharmony/kernel_liteos_a/commits/4e24b572897c33e1b2723122c0e13d3931096bae)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* Optimiz macro of quickstart cmd ([cb140a4](https://gitee.com/openharmony/kernel_liteos_a/commits/cb140a4442c02dd0b1925cc58deecbf4da36dcea)), closes [#I3OSYT](https://gitee.com/openharmony/kernel_liteos_a/issues/I3OSYT)
* Optimize /dev/quickstart permissions. ([4e24b57](https://gitee.com/openharmony/kernel_liteos_a/commits/4e24b572897c33e1b2723122c0e13d3931096bae)), closes [#I3OYUQ](https://gitee.com/openharmony/kernel_liteos_a/issues/I3OYUQ)
* Optimize quickstart node implementation ([4abd2e0](https://gitee.com/openharmony/kernel_liteos_a/commits/4abd2e0247b14718bb21756fb446142140d30a88)), closes [#I3R8O8](https://gitee.com/openharmony/kernel_liteos_a/issues/I3R8O8)
* OsGerCurrSchedTimeCycle 函数存在拼写错误 ([53ced1a](https://gitee.com/openharmony/kernel_liteos_a/commits/53ced1a85edc3d06230225ced3916772f432243f)), closes [#I446](https://gitee.com/openharmony/kernel_liteos_a/issues/I446)
* OsGetArgsAddr声明所在头文件不正确 ([14bd753](https://gitee.com/openharmony/kernel_liteos_a/commits/14bd753aa8beb49af887c8d0aedaefa446409760)), closes [#I41](https://gitee.com/openharmony/kernel_liteos_a/issues/I41)
* parent point of vnode found by VfsHashGet should be updated ([f32caa5](https://gitee.com/openharmony/kernel_liteos_a/commits/f32caa52c67eca20d58676be4e0439acbb4c5ac3)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* OsGerCurrSchedTimeCycle 函数存在拼写错误 ([53ced1a](https://gitee.com/openharmony/kernel_liteos_a/commits/53ced1a85edc3d06230225ced3916772f432243f)), closes [#I446CX](https://gitee.com/openharmony/kernel_liteos_a/issues/I446CX)
* OsGetArgsAddr声明所在头文件不正确 ([14bd753](https://gitee.com/openharmony/kernel_liteos_a/commits/14bd753aa8beb49af887c8d0aedaefa446409760)), closes [#I41MWM](https://gitee.com/openharmony/kernel_liteos_a/issues/I41MWM)
* parent point of vnode found by VfsHashGet should be updated ([f32caa5](https://gitee.com/openharmony/kernel_liteos_a/commits/f32caa52c67eca20d58676be4e0439acbb4c5ac3)), closes [#I3NNFA](https://gitee.com/openharmony/kernel_liteos_a/issues/I3NNFA)
* PathCacheFree try to free name field in struct PathCache ([9f47faf](https://gitee.com/openharmony/kernel_liteos_a/commits/9f47faff732609cf2249f104b94ed55f3ef133bb)), closes [#I3NTH9](https://gitee.com/openharmony/kernel_liteos_a/issues/I3NTH9)
* PathCacheMemoryDump miscalculate the RAM usage of PathCache ([87da7c7](https://gitee.com/openharmony/kernel_liteos_a/commits/87da7c794c9bc8e311ae5242820fbf8aefd8d558)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* PathCacheMemoryDump miscalculate the RAM usage of PathCache ([87da7c7](https://gitee.com/openharmony/kernel_liteos_a/commits/87da7c794c9bc8e311ae5242820fbf8aefd8d558)), closes [#I3OBXY](https://gitee.com/openharmony/kernel_liteos_a/issues/I3OBXY)
* Provide a separate configuration macro for boot environment in RAM. ([e28e06b](https://gitee.com/openharmony/kernel_liteos_a/commits/e28e06b08f5b28091153e584cb9d93014a9f2b10))
* Provide a separate configuration macro for boot environment in RAM. ([bc67393](https://gitee.com/openharmony/kernel_liteos_a/commits/bc67393a67f714e0a8165b6103e53699c676341c))
* Provide a separate configuration macro for boot environment in RAM. ([f13b90e](https://gitee.com/openharmony/kernel_liteos_a/commits/f13b90e4308ba3d60683799b9ce62fb3705ac277)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* race condition in liteipc ([7e2aef2](https://gitee.com/openharmony/kernel_liteos_a/commits/7e2aef2480b15f71ee0e089cef4443f578e03dbb)), closes [#I3PW5](https://gitee.com/openharmony/kernel_liteos_a/issues/I3PW5)
* Provide a separate configuration macro for boot environment in RAM. ([f13b90e](https://gitee.com/openharmony/kernel_liteos_a/commits/f13b90e4308ba3d60683799b9ce62fb3705ac277)), closes [#I3OADR](https://gitee.com/openharmony/kernel_liteos_a/issues/I3OADR)
* race condition in liteipc ([7e2aef2](https://gitee.com/openharmony/kernel_liteos_a/commits/7e2aef2480b15f71ee0e089cef4443f578e03dbb)), closes [#I3PW5Y](https://gitee.com/openharmony/kernel_liteos_a/issues/I3PW5Y)
* rebuild mksh depends on rebuild.sh script ([bef4ab9](https://gitee.com/openharmony/kernel_liteos_a/commits/bef4ab9835dec865898c74337dfb7154718b94aa))
* remove redundant headfile ([73a7777](https://gitee.com/openharmony/kernel_liteos_a/commits/73a777777e1b834192f6bb2c0e8bd03c69765c11)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* Remove redundant invalid codes ([fe05df4](https://gitee.com/openharmony/kernel_liteos_a/commits/fe05df40ae710632adb1bd54fb04ad4a8e0c1429)), closes [#I3R70](https://gitee.com/openharmony/kernel_liteos_a/issues/I3R70)
* Show conflicting files for git apply or patch -p command ([35f7957](https://gitee.com/openharmony/kernel_liteos_a/commits/35f79579758644cbcac6005f894be21f34f42b99)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* remove redundant headfile ([73a7777](https://gitee.com/openharmony/kernel_liteos_a/commits/73a777777e1b834192f6bb2c0e8bd03c69765c11)), closes [#I3RTNR](https://gitee.com/openharmony/kernel_liteos_a/issues/I3RTNR)
* Remove redundant invalid codes ([fe05df4](https://gitee.com/openharmony/kernel_liteos_a/commits/fe05df40ae710632adb1bd54fb04ad4a8e0c1429)), closes [#I3R70T](https://gitee.com/openharmony/kernel_liteos_a/issues/I3R70T)
* Show conflicting files for git apply or patch -p command ([35f7957](https://gitee.com/openharmony/kernel_liteos_a/commits/35f79579758644cbcac6005f894be21f34f42b99)), closes [#I3NNUS](https://gitee.com/openharmony/kernel_liteos_a/issues/I3NNUS)
* SIOCGIFCONF ioctl malloc size error in kernel ([bfd27e7](https://gitee.com/openharmony/kernel_liteos_a/commits/bfd27e78b259eedbd4c30548e80c9b4d789d26e1)), closes [#I3XEZ3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XEZ3)
* smp启动代码解耦及内存映射关系解耦 ([3bb3173](https://gitee.com/openharmony/kernel_liteos_a/commits/3bb3173604dc4dea09301f61da402974185dc112)), closes [#I41P8](https://gitee.com/openharmony/kernel_liteos_a/issues/I41P8)
* some branch in format does not release the vnode mutex properly ([9b2b700](https://gitee.com/openharmony/kernel_liteos_a/commits/9b2b700fa0e3a8edadb38f09c917a3e3f013347f)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* smp启动代码解耦及内存映射关系解耦 ([3bb3173](https://gitee.com/openharmony/kernel_liteos_a/commits/3bb3173604dc4dea09301f61da402974185dc112)), closes [#I41P8Y](https://gitee.com/openharmony/kernel_liteos_a/issues/I41P8Y)
* some branch in format does not release the vnode mutex properly ([9b2b700](https://gitee.com/openharmony/kernel_liteos_a/commits/9b2b700fa0e3a8edadb38f09c917a3e3f013347f)), closes [#I3OFAY](https://gitee.com/openharmony/kernel_liteos_a/issues/I3OFAY)
* Sortlink, the response time to insert the node should be inserted into the back of the existing node. ([1323874](https://gitee.com/openharmony/kernel_liteos_a/commits/1323874389030c55fb053fead12ca1c6654d8851)), closes [#I3PSJ8](https://gitee.com/openharmony/kernel_liteos_a/issues/I3PSJ8)
* statfs can't get f_bfree and f_bavail of a FAT12/FAT16 partition ([9503c4a](https://gitee.com/openharmony/kernel_liteos_a/commits/9503c4a9fc30aaa8ea2031d4fb794436f3c98055)), closes [#I3Q0](https://gitee.com/openharmony/kernel_liteos_a/issues/I3Q0)
* SysOpenat返回值应该为进程fd而非系统全局fd。 ([3457c0b](https://gitee.com/openharmony/kernel_liteos_a/commits/3457c0b11debb2cf5d4abe325c2510a750654512)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* the total used vnode number not increased after unlink a file under ([4f514a1](https://gitee.com/openharmony/kernel_liteos_a/commits/4f514a16af5a3f3b9c4ea182de774297afb17f66)), closes [#I3TS1](https://gitee.com/openharmony/kernel_liteos_a/issues/I3TS1)
* tick 动态化计算优化,消除中断执行时间对系统总体时间的影响,保证软件定时器的响应精度。 ([8df3e8c](https://gitee.com/openharmony/kernel_liteos_a/commits/8df3e8c96515a1907455a9bbc61426f43c803c62)), closes [#I43](https://gitee.com/openharmony/kernel_liteos_a/issues/I43)
* statfs can't get f_bfree and f_bavail of a FAT12/FAT16 partition ([9503c4a](https://gitee.com/openharmony/kernel_liteos_a/commits/9503c4a9fc30aaa8ea2031d4fb794436f3c98055)), closes [#I3Q0VS](https://gitee.com/openharmony/kernel_liteos_a/issues/I3Q0VS)
* SysOpenat返回值应该为进程fd而非系统全局fd。 ([3457c0b](https://gitee.com/openharmony/kernel_liteos_a/commits/3457c0b11debb2cf5d4abe325c2510a750654512)), closes [#I3TNAK](https://gitee.com/openharmony/kernel_liteos_a/issues/I3TNAK)
* the total used vnode number not increased after unlink a file under ([4f514a1](https://gitee.com/openharmony/kernel_liteos_a/commits/4f514a16af5a3f3b9c4ea182de774297afb17f66)), closes [#I3TS1Y](https://gitee.com/openharmony/kernel_liteos_a/issues/I3TS1Y)
* tick 动态化计算优化,消除中断执行时间对系统总体时间的影响,保证软件定时器的响应精度。 ([8df3e8c](https://gitee.com/openharmony/kernel_liteos_a/commits/8df3e8c96515a1907455a9bbc61426f43c803c62)), closes [#I43UQJ](https://gitee.com/openharmony/kernel_liteos_a/issues/I43UQJ)
* toybox update ([c3245b3](https://gitee.com/openharmony/kernel_liteos_a/commits/c3245b3ce317eb58c8dad58fdfc7f094b9b9794b))
* toybox命令升级 ([76f45b3](https://gitee.com/openharmony/kernel_liteos_a/commits/76f45b3fb2783d1cab45a6ba08787c29dfa2c948)), closes [#I41N2](https://gitee.com/openharmony/kernel_liteos_a/issues/I41N2)
* toybox命令升级 ([76f45b3](https://gitee.com/openharmony/kernel_liteos_a/commits/76f45b3fb2783d1cab45a6ba08787c29dfa2c948)), closes [#I41N2A](https://gitee.com/openharmony/third_party_toybox/issues/I41N2A)
* update LOS_DL_LIST_IS_END comment ([900269b](https://gitee.com/openharmony/kernel_liteos_a/commits/900269bd4645252d898f6d3b73de01d8548c960c))
* userfs分区的起始地址与大小改为通过bootargs配置 ([2e2b142](https://gitee.com/openharmony/kernel_liteos_a/commits/2e2b14205f4b81c7483ab42d62f144487097e9a4)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* VnodeInUseIter and VnodeFreeAll used to be recursive ([5f6656c](https://gitee.com/openharmony/kernel_liteos_a/commits/5f6656cb36a2ffb0b290aeb53981aba7501e80b2)), closes [#I3NN3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3NN3)
* 以g_sysSchedStartTime是否为0判断时间轴是否生效存在极限场景导致调度时间不生效 ([67ac8c4](https://gitee.com/openharmony/kernel_liteos_a/commits/67ac8c4c586adc371ece56700fd42371ca7fc885)), closes [#I45HP5](https://gitee.com/openharmony/kernel_liteos_a/issues/I45HP5)
* userfs分区的起始地址与大小改为通过bootargs配置 ([2e2b142](https://gitee.com/openharmony/kernel_liteos_a/commits/2e2b14205f4b81c7483ab42d62f144487097e9a4)), closes [#I3XNEY](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XNEY)
* VnodeInUseIter and VnodeFreeAll used to be recursive ([5f6656c](https://gitee.com/openharmony/kernel_liteos_a/commits/5f6656cb36a2ffb0b290aeb53981aba7501e80b2)), closes [#I3NN3U](https://gitee.com/openharmony/kernel_liteos_a/issues/I3NN3U)
* 以g_sysSchedStartTime是否为0判断时间轴是否生效存在极限场景导致调度时间不生效 ([67ac8c4](https://gitee.com/openharmony/kernel_liteos_a/commits/67ac8c4c586adc371ece56700fd42371ca7fc885)), closes [#I45HP5](https://gitee.com/openharmony/kernel_liteos_m/issues/I45HP5)
* 修复FATFS中不同内部接口不支持FAT12/FAT16 FAT表结束标志 ([33f5c70](https://gitee.com/openharmony/kernel_liteos_a/commits/33f5c70e6c8781758d2bfde0f60ca3d6ec7d543f)), closes [#I409R6](https://gitee.com/openharmony/kernel_liteos_a/issues/I409R6)
* 修复kill进程时因liteipc阻塞的进程概率无法退出问题 ([7de43bb](https://gitee.com/openharmony/kernel_liteos_a/commits/7de43bb004a12f926550f0b36ca3c2fa610feb27)), closes [#I3XX7](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XX7)
* 修复kill进程时因liteipc阻塞的进程概率无法退出问题 ([7de43bb](https://gitee.com/openharmony/kernel_liteos_a/commits/7de43bb004a12f926550f0b36ca3c2fa610feb27)), closes [#I3XX7K](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XX7K)
* 修复MagicKey数组越界访问 ([071cd62](https://gitee.com/openharmony/kernel_liteos_a/commits/071cd6268aeaaef702387dacaf4ef1ffbb7618fc)), closes [#I3U4N9](https://gitee.com/openharmony/kernel_liteos_a/issues/I3U4N9)
* 修复mprotect修改地址区间的权限后相应的区间名丢失问题 ([e425187](https://gitee.com/openharmony/kernel_liteos_a/commits/e425187d176a5e09bc5253faefc9cfc8454da0a3)), closes [#I43R40](https://gitee.com/openharmony/kernel_liteos_a/issues/I43R40)
* 修复mq_close关闭后仍然占用文件描述符的问题 ([590c7b4](https://gitee.com/openharmony/kernel_liteos_a/commits/590c7b4e22662781d05ad035a785e985d573ec33)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* 修复mqueue问题 ([26ee8b8](https://gitee.com/openharmony/kernel_liteos_a/commits/26ee8b836e346e641de4ecd72284f5d377bca6f8)), closes [#I43P4](https://gitee.com/openharmony/kernel_liteos_a/issues/I43P4)
* 修复sigwait等待到的信号值与获取的siginfo中的值不一致 ([ed7defb](https://gitee.com/openharmony/kernel_liteos_a/commits/ed7defbd439c345a07159d40eb04433afd530004)), closes [#I3M12](https://gitee.com/openharmony/kernel_liteos_a/issues/I3M12)
* 修复了LOSCFG_FS_FAT_VIRTUAL_PARTITION宏开关错误作用域引起的功能错误 ([acda419](https://gitee.com/openharmony/kernel_liteos_a/commits/acda419a2d773ea890052a16ee66b4872f941fbb)), closes [#I3W1](https://gitee.com/openharmony/kernel_liteos_a/issues/I3W1)
* 修复了内核的VFAT测试用例 ([a8384b5](https://gitee.com/openharmony/kernel_liteos_a/commits/a8384b5db2274d50a350910d7cfd3fc36b4f4103)), closes [#I3XF3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XF3)
* 修复mq_close关闭后仍然占用文件描述符的问题 ([590c7b4](https://gitee.com/openharmony/kernel_liteos_a/commits/590c7b4e22662781d05ad035a785e985d573ec33)), closes [#I3ZQDA](https://gitee.com/openharmony/kernel_liteos_a/issues/I3ZQDA)
* 修复mqueue问题 ([26ee8b8](https://gitee.com/openharmony/kernel_liteos_a/commits/26ee8b836e346e641de4ecd72284f5d377bca6f8)), closes [#I43P4T](https://gitee.com/openharmony/kernel_liteos_a/issues/I43P4T)
* 修复sigwait等待到的信号值与获取的siginfo中的值不一致 ([ed7defb](https://gitee.com/openharmony/kernel_liteos_a/commits/ed7defbd439c345a07159d40eb04433afd530004)), closes [#I3M12H](https://gitee.com/openharmony/kernel_liteos_a/issues/I3M12H)
* 修复了LOSCFG_FS_FAT_VIRTUAL_PARTITION宏开关错误作用域引起的功能错误 ([acda419](https://gitee.com/openharmony/kernel_liteos_a/commits/acda419a2d773ea890052a16ee66b4872f941fbb)), closes [#I3W1IW](https://gitee.com/openharmony/kernel_liteos_a/issues/I3W1IW)
* 修复了内核的VFAT测试用例 ([a8384b5](https://gitee.com/openharmony/kernel_liteos_a/commits/a8384b5db2274d50a350910d7cfd3fc36b4f4103)), closes [#I3XF3R](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XF3R)
* 修复内核access chmod chown接口 ([56a95b9](https://gitee.com/openharmony/kernel_liteos_a/commits/56a95b9ec903f815f9199ac65ca318e00a83b2ed)), closes [#I3Z5L6](https://gitee.com/openharmony/kernel_liteos_a/issues/I3Z5L6)
* 修复内核c库的makefile中被优化函数替换的高频函数依然参与了编译的问题 ([6f6dc4f](https://gitee.com/openharmony/kernel_liteos_a/commits/6f6dc4f24c8ab05a6d42da46a9fa41d74a477bd7)), closes [#I3XGM8](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XGM8)
* 修复内核堆完整性检查逻辑中访问非法指针导致系统异常问题。 ([30f5ab8](https://gitee.com/openharmony/kernel_liteos_a/commits/30f5ab89b72d45f596b15af82a8e8e01add7977d)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* 修复启动框架debug模式下-Werror=maybe-uninitialized告警以及符号链接不进镜像的隐患 ([4c02415](https://gitee.com/openharmony/kernel_liteos_a/commits/4c024159a9600745863e49ee955308470a5b657b)), closes [#I3T5](https://gitee.com/openharmony/kernel_liteos_a/issues/I3T5)
* 修复内核堆完整性检查逻辑中访问非法指针导致系统异常问题。 ([30f5ab8](https://gitee.com/openharmony/kernel_liteos_a/commits/30f5ab89b72d45f596b15af82a8e8e01add7977d)), closes [#I3VJZT](https://gitee.com/openharmony/kernel_liteos_a/issues/I3VJZT)
* 修复启动框架debug模式下-Werror=maybe-uninitialized告警以及符号链接不进镜像的隐患 ([4c02415](https://gitee.com/openharmony/kernel_liteos_a/commits/4c024159a9600745863e49ee955308470a5b657b)), closes [#I3T5HR](https://gitee.com/openharmony/kernel_liteos_a/issues/I3T5HR)
* 修复开机概率挂死 ([2e82c36](https://gitee.com/openharmony/kernel_liteos_a/commits/2e82c361f73b2119613c3571c48faae8ec41d4eb)), closes [#I3SWY2](https://gitee.com/openharmony/kernel_liteos_a/issues/I3SWY2)
* 修复文档链接失效问题 ([42a3a6c](https://gitee.com/openharmony/kernel_liteos_a/commits/42a3a6c51bfca4ade8ce94084ea2f8eb1c86a137)), closes [#I45297](https://gitee.com/openharmony/kernel_liteos_a/issues/I45297)
* 修改/proc/mounts显示格式 ([6860246](https://gitee.com/openharmony/kernel_liteos_a/commits/6860246cfaac6f540665e79bbc4c3d54c419b092)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* 修改clock_gettime接口适配posix标准测试用例011输入clk_id错误时返回值ESRCH为EINVAL. ([f8cf6e6](https://gitee.com/openharmony/kernel_liteos_a/commits/f8cf6e6439ee017fe8e0d4ecfc9949c28fa6775f)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* 修改DoNanoSleep 以纳秒为单位 ([6917e08](https://gitee.com/openharmony/kernel_liteos_a/commits/6917e08431689ccbd5a30e9a39b67016ffb64d0a)), closes [#I3Z9](https://gitee.com/openharmony/kernel_liteos_a/issues/I3Z9)
* 修改某些平台保存bbox日志失败的问题 ([8f6a1dd](https://gitee.com/openharmony/kernel_liteos_a/commits/8f6a1dd33c59164070e8d2fb5abbd3e76ef8ac8e)), closes [#I41](https://gitee.com/openharmony/kernel_liteos_a/issues/I41)
* 修改默认窗口宽度到400 ([09c491c](https://gitee.com/openharmony/kernel_liteos_a/commits/09c491ca1fd6d3110eafb0d07e45b25bdc3bd5d0)), closes [#I40](https://gitee.com/openharmony/kernel_liteos_a/issues/I40)
* 关闭jffs和fat后rootfs配置也被相应关闭导致nand介质的rootfs不可用。 ([0ea476b](https://gitee.com/openharmony/kernel_liteos_a/commits/0ea476b9741fabd3c255c2770688f587920cf509)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* 修改/proc/mounts显示格式 ([6860246](https://gitee.com/openharmony/kernel_liteos_a/commits/6860246cfaac6f540665e79bbc4c3d54c419b092)), closes [#I3XGCS](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XGCS)
* 修改clock_gettime接口适配posix标准测试用例011输入clk_id错误时返回值ESRCH为EINVAL. ([f8cf6e6](https://gitee.com/openharmony/kernel_liteos_a/commits/f8cf6e6439ee017fe8e0d4ecfc9949c28fa6775f)), closes [#I3OUHI](https://gitee.com/openharmony/kernel_liteos_a/issues/I3OUHI)
* 修改DoNanoSleep 以纳秒为单位 ([6917e08](https://gitee.com/openharmony/kernel_liteos_a/commits/6917e08431689ccbd5a30e9a39b67016ffb64d0a)), closes [#I3Z9DP](https://gitee.com/openharmony/kernel_liteos_a/issues/I3Z9DP)
* 修改某些平台保存bbox日志失败的问题 ([8f6a1dd](https://gitee.com/openharmony/kernel_liteos_a/commits/8f6a1dd33c59164070e8d2fb5abbd3e76ef8ac8e)), closes [#I41UTP](https://gitee.com/openharmony/kernel_liteos_a/issues/I41UTP)
* 修改默认窗口宽度到400 ([09c491c](https://gitee.com/openharmony/kernel_liteos_a/commits/09c491ca1fd6d3110eafb0d07e45b25bdc3bd5d0)), closes [#I40LQX](https://gitee.com/openharmony/kernel_liteos_a/issues/I40LQX)
* 关闭jffs和fat后rootfs配置也被相应关闭导致nand介质的rootfs不可用。 ([0ea476b](https://gitee.com/openharmony/kernel_liteos_a/commits/0ea476b9741fabd3c255c2770688f587920cf509)), closes [#I3SBYN](https://gitee.com/openharmony/kernel_liteos_a/issues/I3SBYN)
* 内核态在console初始化完成后使用printf无法正常打印 ([44ce696](https://gitee.com/openharmony/kernel_liteos_a/commits/44ce6969048c2e252f3f9d66fa485c77bdab8ae7)), closes [#I3UG00](https://gitee.com/openharmony/kernel_liteos_a/issues/I3UG00)
* 去掉冗余的strip操作 ([7819d15](https://gitee.com/openharmony/kernel_liteos_a/commits/7819d15b3619681ae37a1349a6bec2440c829ae9)), closes [#I43767](https://gitee.com/openharmony/kernel_liteos_a/issues/I43767)
* 合并进程栈两个地址连续的region ([42f374d](https://gitee.com/openharmony/kernel_liteos_a/commits/42f374dd7a353f1c8227e92fa92827c1c7b32424)), closes [#I43](https://gitee.com/openharmony/kernel_liteos_a/issues/I43)
* 在内核提示No idle TCB时增加打印当前系统任务信息以方便问题定位。 ([11a9b00](https://gitee.com/openharmony/kernel_liteos_a/commits/11a9b00d43a6dbe9fba9f6eb07d78a9d226c28f8)), closes [#I434](https://gitee.com/openharmony/kernel_liteos_a/issues/I434)
* 合并进程栈两个地址连续的region ([42f374d](https://gitee.com/openharmony/kernel_liteos_a/commits/42f374dd7a353f1c8227e92fa92827c1c7b32424)), closes [#I43QYJ](https://gitee.com/openharmony/kernel_liteos_a/issues/I43QYJ)
* 在内核提示No idle TCB时增加打印当前系统任务信息以方便问题定位。 ([11a9b00](https://gitee.com/openharmony/kernel_liteos_a/commits/11a9b00d43a6dbe9fba9f6eb07d78a9d226c28f8)), closes [#I434UC](https://gitee.com/openharmony/kernel_liteos_a/issues/I434UC)
* 增加表头,内容以制表符分栏。 ([e9ad6b7](https://gitee.com/openharmony/kernel_liteos_a/commits/e9ad6b71c3b1136414672cd21b339ded7a02dfb9)), closes [#I3W2M9](https://gitee.com/openharmony/kernel_liteos_a/issues/I3W2M9)
* 将用户态内存调测解析脚本移至tools目录下 ([85b4cb7](https://gitee.com/openharmony/kernel_liteos_a/commits/85b4cb7a67b717984d3ebf68115c7139cc61d690)), closes [#I42T9](https://gitee.com/openharmony/kernel_liteos_a/issues/I42T9)
* 将用户态内存调测解析脚本移至tools目录下 ([85b4cb7](https://gitee.com/openharmony/kernel_liteos_a/commits/85b4cb7a67b717984d3ebf68115c7139cc61d690)), closes [#I42T9A](https://gitee.com/openharmony/kernel_liteos_a/issues/I42T9A)
* 恢复了FATFS设置卷标的功能 ([9515d53](https://gitee.com/openharmony/kernel_liteos_a/commits/9515d53dccc9a6458bfbaf8e15143928f05cb660)), closes [#I3Y5G8](https://gitee.com/openharmony/kernel_liteos_a/issues/I3Y5G8)
* 解决kill进程时无法保证进程的已持有的内核资源合理释放. ([cf89f01](https://gitee.com/openharmony/kernel_liteos_a/commits/cf89f016e93f28f8d72e6f5de08640d08a155908)), closes [#I3S0N0](https://gitee.com/openharmony/kernel_liteos_a/issues/I3S0N0)
* 解决不同环境下计算的rootfs的size偏小导致mcopy造成的disk full错误 ([c54879b](https://gitee.com/openharmony/kernel_liteos_a/commits/c54879b54875abece53b1f64072cfacbd2e1970e)), closes [#I3IA06](https://gitee.com/openharmony/kernel_liteos_a/issues/I3IA06)
* 设置qemu默认userfs大小/修改qemu驱动目录 ([1d952a2](https://gitee.com/openharmony/kernel_liteos_a/commits/1d952a254a6e7ec2f70f7112eb27355cfd01ba4d)), closes [#I3XW96](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XW96) [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* 设置qemu默认userfs大小/修改qemu驱动目录 ([1d952a2](https://gitee.com/openharmony/kernel_liteos_a/commits/1d952a254a6e7ec2f70f7112eb27355cfd01ba4d)), closes [#I3XW96](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XW96)
### Features
* active mksh & toybox ([cacb4f0](https://gitee.com/openharmony/kernel_liteos_a/commits/cacb4f0103ecb2d1b7af54d84957f88d3e9443d2)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* active mksh & toybox ([cacb4f0](https://gitee.com/openharmony/kernel_liteos_a/commits/cacb4f0103ecb2d1b7af54d84957f88d3e9443d2)), closes [#I3VEOG](https://gitee.com/openharmony/kernel_liteos_a/issues/I3VEOG)
* Add /dev/quickstart to support synchronous communication between processes in user mode startup. ([46b63f7](https://gitee.com/openharmony/kernel_liteos_a/commits/46b63f71537789743ed2f3f337c1809ee4900d71)), closes [#I3OHO5](https://gitee.com/openharmony/kernel_liteos_a/issues/I3OHO5)
* add /proc/fd file to dump the pid/fd/path information ([600dded](https://gitee.com/openharmony/kernel_liteos_a/commits/600dded31e80df275ed08c326c0ce3d1857d8dd8)), closes [#I3WB5](https://gitee.com/openharmony/kernel_liteos_a/issues/I3WB5)
* add /proc/fs_cache to display cache info ([231cb6b](https://gitee.com/openharmony/kernel_liteos_a/commits/231cb6be27380948bc48136ae2e02c28450f47a8)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* add /proc/fs_cache to display cache info ([53c6d96](https://gitee.com/openharmony/kernel_liteos_a/commits/53c6d96c6f97cb006216769f8b73f50fba3bc325)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* add /proc/fd file to dump the pid/fd/path information ([600dded](https://gitee.com/openharmony/kernel_liteos_a/commits/600dded31e80df275ed08c326c0ce3d1857d8dd8)), closes [#I3WB5U](https://gitee.com/openharmony/kernel_liteos_a/issues/I3WB5U)
* add /proc/fs_cache to display cache info ([231cb6b](https://gitee.com/openharmony/kernel_liteos_a/commits/231cb6be27380948bc48136ae2e02c28450f47a8)), closes [#I3WWBD](https://gitee.com/openharmony/kernel_liteos_a/issues/I3WWBD)
* add /proc/fs_cache to display cache info ([53c6d96](https://gitee.com/openharmony/kernel_liteos_a/commits/53c6d96c6f97cb006216769f8b73f50fba3bc325)), closes [#I3WESD](https://gitee.com/openharmony/kernel_liteos_a/issues/I3WESD)
* add and fix some syscall ([ce849f2](https://gitee.com/openharmony/kernel_liteos_a/commits/ce849f2145e1569517c5244c9ffcaebed53f3a66))
* add blackbox for liteos_a ([a195aac](https://gitee.com/openharmony/kernel_liteos_a/commits/a195aac9fb60b0163f9eebb29084287d226bd14c)), closes [#I406](https://gitee.com/openharmony/kernel_liteos_a/issues/I406)
* add blackbox for liteos_a ([425975e](https://gitee.com/openharmony/kernel_liteos_a/commits/425975e4811023e31a520979c20ea2562224d9d0)), closes [#I3NN7](https://gitee.com/openharmony/kernel_liteos_a/issues/I3NN7)
* add clear cache cmd to /proc/fs_cache ([3d1cf68](https://gitee.com/openharmony/kernel_liteos_a/commits/3d1cf683f37a6f75e9db2ce1f11ec93159b77663)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* add blackbox for liteos_a ([a195aac](https://gitee.com/openharmony/kernel_liteos_a/commits/a195aac9fb60b0163f9eebb29084287d226bd14c)), closes [#I406NP](https://gitee.com/openharmony/kernel_liteos_a/issues/I406NP)
* add blackbox for liteos_a ([425975e](https://gitee.com/openharmony/kernel_liteos_a/commits/425975e4811023e31a520979c20ea2562224d9d0))
* add clear cache cmd to /proc/fs_cache ([3d1cf68](https://gitee.com/openharmony/kernel_liteos_a/commits/3d1cf683f37a6f75e9db2ce1f11ec93159b77663)), closes [#I3XLPH](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XLPH)
* add liteos patch ability ([98ca844](https://gitee.com/openharmony/kernel_liteos_a/commits/98ca8441fe75ee1c3318a6a09376fd72f5a51350))
* add support for gn build system ([a8805a6](https://gitee.com/openharmony/kernel_liteos_a/commits/a8805a65aab9109b915364fccf36c8328f636e48))
* add uid/gid for ProcFs ([6780659](https://gitee.com/openharmony/kernel_liteos_a/commits/67806596a3c0df9a54893d8c74ebe9da98d7fb06)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* A核proc文件系统在echo模式下新增write的功能 ([f10dd7c](https://gitee.com/openharmony/kernel_liteos_a/commits/f10dd7c135d37a5fb0d78610d5ece5807d01eb1f)), closes [#I3T6](https://gitee.com/openharmony/kernel_liteos_a/issues/I3T6)
* add uid/gid for ProcFs ([6780659](https://gitee.com/openharmony/kernel_liteos_a/commits/67806596a3c0df9a54893d8c74ebe9da98d7fb06)), closes [#I3WGVP](https://gitee.com/openharmony/kernel_liteos_a/issues/I3WGVP)
* A核proc文件系统在echo模式下新增write的功能 ([f10dd7c](https://gitee.com/openharmony/kernel_liteos_a/commits/f10dd7c135d37a5fb0d78610d5ece5807d01eb1f)), closes [#I3T6MZ](https://gitee.com/openharmony/kernel_liteos_a/issues/I3T6MZ)
* build OHOS_Image from kernel ([abf4d8f](https://gitee.com/openharmony/kernel_liteos_a/commits/abf4d8fb252631aca9d46211762880a23be2a0b1))
* **build:** make liteos_config_file available as gn argument ([f9a9077](https://gitee.com/openharmony/kernel_liteos_a/commits/f9a907772f506ca7e2d84e96d4d17cffc7dae50f))
* **build:** 使用xts -notest选项时内核用例不参与编译构建和用例编译配置方式调整 ([9bdf716](https://gitee.com/openharmony/kernel_liteos_a/commits/9bdf716407c125c9877b6f49c2133112c18cdabc))
* don't apply module_swith on configs of config ([f3beb4b](https://gitee.com/openharmony/kernel_liteos_a/commits/f3beb4b273c9a76fbfaffe57302f27d2a74cd2ba))
* enable gn build for toybox and mksh ([c54bfa1](https://gitee.com/openharmony/kernel_liteos_a/commits/c54bfa16e3907482c252e9738192df869c63326e))
* fatfs支持符号链接功能 ([e50cf0b](https://gitee.com/openharmony/kernel_liteos_a/commits/e50cf0be6f6d118022b6d79c5177aece574ba150)), closes [#I3V8D1](https://gitee.com/openharmony/kernel_liteos_a/issues/I3V8D1)
* **file system:** add memory-based romfs ([c4595d2](https://gitee.com/openharmony/kernel_liteos_a/commits/c4595d25042b188570d991a815009764c37f3cb3)), closes [#I3S0](https://gitee.com/openharmony/kernel_liteos_a/issues/I3S0)
* **file system:** add memory-based romfs ([c4595d2](https://gitee.com/openharmony/kernel_liteos_a/commits/c4595d25042b188570d991a815009764c37f3cb3)), closes [#I3S0CP](https://gitee.com/openharmony/kernel_liteos_a/issues/I3S0CP)
* introduce mksh toybox to rootfs ([41c7689](https://gitee.com/openharmony/kernel_liteos_a/commits/41c7689dfa49c52fb15705ce15ef22a278fbf2ef))
* L0-L1 支持Trace ([dc9ec68](https://gitee.com/openharmony/kernel_liteos_a/commits/dc9ec6856fe14aa604f037f55f17a3ba2bafb098)), closes [#I46WA0](https://gitee.com/openharmony/kernel_liteos_a/issues/I46WA0)
* L1支持低功耗投票框架 ([21d8ac8](https://gitee.com/openharmony/kernel_liteos_a/commits/21d8ac8752469f6e0dc2d50d28b75421f665385a)), closes [#I3VS5](https://gitee.com/openharmony/kernel_liteos_a/issues/I3VS5)
* L1支持低功耗投票框架 ([21d8ac8](https://gitee.com/openharmony/kernel_liteos_a/commits/21d8ac8752469f6e0dc2d50d28b75421f665385a)), closes [#I3VS5N](https://gitee.com/openharmony/kernel_liteos_a/issues/I3VS5N)
* **libc:** upgrade optimized-routines to v21.02 ([1ec8d5a](https://gitee.com/openharmony/kernel_liteos_a/commits/1ec8d5a454658e95c4acb821d0878f357f4e82ad))
* **make:** optimize makefiles and remove some unused files ([0e26094](https://gitee.com/openharmony/kernel_liteos_a/commits/0e260949c962158a263d4b0ad45fe9f6843d6e30))
* Open macro for ADC moudule ([c71ec9d](https://gitee.com/openharmony/kernel_liteos_a/commits/c71ec9d7e8574078a9dc2a8463f3141cca3d625a))
* **QEMU_ARM_VIRT_CA7:** 使能FAT文件系统编译选项 ([49856dc](https://gitee.com/openharmony/kernel_liteos_a/commits/49856dc1e0de1c5e92346c83eda641dfb1bb16be))
* support .mkshrc ([51a50c9](https://gitee.com/openharmony/kernel_liteos_a/commits/51a50c95b4cd47b6931523926b728d1c0ff8988b)), closes [#I3Y5](https://gitee.com/openharmony/kernel_liteos_a/issues/I3Y5)
* support link/symlink/readlink ([6eddc86](https://gitee.com/openharmony/kernel_liteos_a/commits/6eddc869d349be59860bfd84ff10b7579a9b00a9)), closes [#I3Q0](https://gitee.com/openharmony/kernel_liteos_a/issues/I3Q0)
* support toybox in qemu ([5618319](https://gitee.com/openharmony/kernel_liteos_a/commits/561831928bb1ad1871b2d60d2bba2d67488cea5f)), closes [#I3V17](https://gitee.com/openharmony/kernel_liteos_a/issues/I3V17)
* timer_create支持以SIGEV_THREAD方式创建定时器 ([e5f6bf0](https://gitee.com/openharmony/kernel_liteos_a/commits/e5f6bf05567c2d193f3746caca502199e7b81e92)), closes [#I3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3)
* support .mkshrc ([51a50c9](https://gitee.com/openharmony/kernel_liteos_a/commits/51a50c95b4cd47b6931523926b728d1c0ff8988b)), closes [#I3Y5KE](https://gitee.com/openharmony/third_party_mksh/issues/I3Y5KE)
* support link/symlink/readlink ([6eddc86](https://gitee.com/openharmony/kernel_liteos_a/commits/6eddc869d349be59860bfd84ff10b7579a9b00a9)), closes [#I3Q0OD](https://gitee.com/openharmony/kernel_liteos_a/issues/I3Q0OD)
* support toybox in qemu ([5618319](https://gitee.com/openharmony/kernel_liteos_a/commits/561831928bb1ad1871b2d60d2bba2d67488cea5f)), closes [#I3V17D](https://gitee.com/openharmony/kernel_liteos_a/issues/I3V17D)
* timer_create支持以SIGEV_THREAD方式创建定时器 ([e5f6bf0](https://gitee.com/openharmony/kernel_liteos_a/commits/e5f6bf05567c2d193f3746caca502199e7b81e92)), closes [#I3SRFI](https://gitee.com/openharmony/kernel_liteos_a/issues/I3SRFI)
* using kconfiglib instead of kconfig ([8784694](https://gitee.com/openharmony/kernel_liteos_a/commits/878469468647a19f704e7ee2af696b0ba8ab775a))
* vfs support sdcard hotplug ([2db80ec](https://gitee.com/openharmony/kernel_liteos_a/commits/2db80ecb389176b53c77807567895470bb180a06)), closes [#I44WH1](https://gitee.com/openharmony/kernel_liteos_a/issues/I44WH1)
* **vfs:** vfs支持FD_CLOEXEC标记 ([27dca4d](https://gitee.com/openharmony/kernel_liteos_a/commits/27dca4d857ef8de6b4bb9302e0dd435be7e3284f)), closes [#I3U81](https://gitee.com/openharmony/kernel_liteos_a/issues/I3U81)
* **vfs:** vfs支持FD_CLOEXEC标记 ([27dca4d](https://gitee.com/openharmony/kernel_liteos_a/commits/27dca4d857ef8de6b4bb9302e0dd435be7e3284f)), closes [#I3U81W](https://gitee.com/openharmony/kernel_liteos_a/issues/I3U81W)
* 删除zpfs冗余代码 ([3393479](https://gitee.com/openharmony/kernel_liteos_a/commits/3393479c52f4a9dfe2394bb32beb4b98fca8e171))
* 基于汇编实现内核对用户态内存清零的功能 ([9db3407](https://gitee.com/openharmony/kernel_liteos_a/commits/9db3407589bb0b2d4a5772faac3130032bc0b8a9)), closes [#I3XXT0](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XXT0)
* 增加mount的MS_RDONLY标志的支持 ([8729f6e](https://gitee.com/openharmony/kernel_liteos_a/commits/8729f6ee57ea57bc664d076ff112c8726fedded9)), closes [#I3Z1W6](https://gitee.com/openharmony/kernel_liteos_a/issues/I3Z1W6)
* 支持killpg和waitid ([dc3cc09](https://gitee.com/openharmony/kernel_liteos_a/commits/dc3cc094a75c6da65d87522930afea06106d3933))
* 新增toybox reboot命令 ([e567a10](https://gitee.com/openharmony/kernel_liteos_a/commits/e567a10d021c3e0fe02d6911dbe8687255c67ffa)), closes [#I3YQ7](https://gitee.com/openharmony/kernel_liteos_a/issues/I3YQ7)
* 给开发者提供系统信息导出Hidumper工具。 ([cb17fa5](https://gitee.com/openharmony/kernel_liteos_a/commits/cb17fa50ed28e6e8f59b7d68ede13c759b983311)), closes [#I3NN7](https://gitee.com/openharmony/kernel_liteos_a/issues/I3NN7)
* 自研shell命令回补 ([7bc68f4](https://gitee.com/openharmony/kernel_liteos_a/commits/7bc68f454ff5fbf415712c9b8479b8c832f68417)), closes [#I44U0](https://gitee.com/openharmony/kernel_liteos_a/issues/I44U0)
* 新增toybox reboot命令 ([e567a10](https://gitee.com/openharmony/kernel_liteos_a/commits/e567a10d021c3e0fe02d6911dbe8687255c67ffa)), closes [#I3YQ7S](https://gitee.com/openharmony/third_party_toybox/issues/I3YQ7S)
* 给开发者提供系统信息导出Hidumper工具。 ([cb17fa5](https://gitee.com/openharmony/kernel_liteos_a/commits/cb17fa50ed28e6e8f59b7d68ede13c759b983311))
* 自研shell命令回补 ([7bc68f4](https://gitee.com/openharmony/kernel_liteos_a/commits/7bc68f454ff5fbf415712c9b8479b8c832f68417)), closes [#I44U0H](https://gitee.com/openharmony/third_party_toybox/issues/I44U0H)
### Performance Improvements
@@ -316,7 +316,7 @@ LOS_LmsAddrDisableProtect去能指定内存段的访问保护
### Reverts
* Revert "fix: 修改默认窗口宽度到400" ([1878849](https://gitee.com/openharmony/kernel_liteos_a/commits/187884937cd087e39a28c033c41033163d6b4766)), closes [#I42X9](https://gitee.com/openharmony/kernel_liteos_a/issues/I42X9)
* Revert "fix: 修改默认窗口宽度到400" ([1878849](https://gitee.com/openharmony/kernel_liteos_a/commits/187884937cd087e39a28c033c41033163d6b4766)), closes [#I42X9V](https://gitee.com/openharmony/kernel_liteos_a/issues/I42X9V)
### BREAKING CHANGES

View File

@@ -235,7 +235,12 @@ config SCHED_DEBUG
depends on DEBUG_VERSION
help
If you wish to build LiteOS with support for sched debug.
config SCHED_EDF_DEBUG
bool "Enable sched EDF debug Feature"
default n
depends on SCHED_DEBUG
help
If you wish to build LiteOS with support for sched debug.
config USER_INIT_DEBUG
bool "Enable user init Debug"
default n

View File

@@ -87,7 +87,7 @@ For compilation, please refer to the [compilation instructions](https://gitee.co
## Contribution<a name="section1371123476304"></a>
[How to involve](https://gitee.com/openharmony/docs/blob/HEAD/en/contribute/contribution.md)
[How to involve](https://gitee.com/openharmony/docs/blob/HEAD/en/contribute/contribution-guide.md)
[Commit message spec](https://gitee.com/openharmony/kernel_liteos_a/wikis/Commit%20message%20%E8%A7%84%E8%8C%83)

View File

@@ -87,6 +87,8 @@ OpenHarmony LiteOS-A内核支持[Hi3516DV300](https://gitee.com/openharmony/docs
编译可以参考:[编译指导](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-pkg-3516-build.md)
测试参考:[单元测试](testsuites/unittest/tools/README.md)
## 贡献<a name="section1371123476304"></a>
[如何贡献](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/contribute/%E5%8F%82%E4%B8%8E%E8%B4%A1%E7%8C%AE.md)

View File

@@ -73,5 +73,5 @@ executable("sample_usr_lms") {
"-Wl,--wrap=strcpy",
"-Wl,--wrap=strcat",
]
deps = [ "//kernel/liteos_a/kernel/extended/lms/usr:usrlmslib" ]
deps = [ "$LITEOSTOPDIR/kernel/extended/lms/usr:usrlmslib" ]
}

View File

@@ -29,7 +29,7 @@
import("//build/lite/config/component/lite_component.gni")
import("//kernel/liteos_a/liteos.gni")
import("//third_party/mksh/mksh.gni")
import("$THIRDPARTY_MKSH_DIR/mksh.gni")
group("mksh") {
deps = [ ":build_mksh" ]
@@ -42,7 +42,7 @@ copy("copy_mksh_src") {
build_ext_component("build_mksh") {
deps = [ ":copy_mksh_src" ]
deps += [ "//third_party/musl:sysroot_lite" ]
deps += [ "$THIRDPARTY_MUSL_DIR:sysroot_lite" ]
exec_path = rebase_path("$target_out_dir/mksh_build")
cflags = [

View File

@@ -44,7 +44,7 @@
ShellCB *g_shellCB = NULL;
ShellCB *OsGetShellCb()
ShellCB *OsGetShellCb(void)
{
return g_shellCB;
}

View File

@@ -29,7 +29,7 @@
import("//build/lite/config/component/lite_component.gni")
import("//kernel/liteos_a/liteos.gni")
import("//third_party/toybox/toybox.gni")
import("$THIRDPARTY_TOYBOX_DIR/toybox.gni")
group("toybox") {
deps = [ ":build_toybox" ]
@@ -51,7 +51,7 @@ build_ext_component("build_toybox") {
":copy_toybox_config",
":copy_toybox_src",
]
deps += [ "//third_party/musl:sysroot_lite" ]
deps += [ "$THIRDPARTY_MUSL_DIR:sysroot_lite" ]
exec_path = rebase_path("$target_out_dir/toybox_build")
cflags = [

View File

@@ -28,10 +28,10 @@
"name": "liteos_a",
"subsystem": "kernel",
"syscap": [
"SystemCapability.Kernel.liteos-a"
"SystemCapability.Kernel.Liteos-A"
],
"features": [],
"adated_system_type": [
"adapted_system_type": [
"small"
],
"rom": "1.5MB",

View File

@@ -428,6 +428,7 @@ extern ssize_t mq_timedreceive(mqd_t personal, char *msg, size_t msgLen,
extern void MqueueRefer(int sysFd);
extern int OsMqNotify(mqd_t personal, const struct sigevent *sigev);
extern VOID OsMqueueCBDestroy(struct mqarray *queueTable);
#ifdef __cplusplus
#if __cplusplus

View File

@@ -113,7 +113,9 @@ STATIC INLINE struct mqarray *GetMqueueCBByName(const CHAR *name)
STATIC INT32 DoMqueueDelete(struct mqarray *mqueueCB)
{
UINT32 ret;
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
OsIPCLimitMqFree();
#endif
if (mqueueCB->mq_name != NULL) {
LOS_MemFree(OS_SYS_MEM_ADDR, mqueueCB->mq_name);
mqueueCB->mq_name = NULL;
@@ -163,11 +165,29 @@ STATIC int SaveMqueueName(const CHAR *mqName, struct mqarray *mqueueCB)
return LOS_OK;
}
STATIC VOID MqueueCBInit(struct mqarray *mqueueCB, const struct mq_attr *attr, INT32 openFlag, UINT32 mode)
{
mqueueCB->unlinkflag = FALSE;
mqueueCB->unlink_ref = 0;
mqueueCB->mq_personal->mq_status = MQ_USE_MAGIC;
mqueueCB->mq_personal->mq_next = NULL;
mqueueCB->mq_personal->mq_posixdes = mqueueCB;
mqueueCB->mq_personal->mq_flags = (INT32)((UINT32)openFlag | ((UINT32)attr->mq_flags & (UINT32)FNONBLOCK));
mqueueCB->mq_personal->mq_mode = mode;
mqueueCB->mq_personal->mq_refcount = 0;
mqueueCB->mq_notify.pid = 0;
}
STATIC struct mqpersonal *DoMqueueCreate(const struct mq_attr *attr, const CHAR *mqName, INT32 openFlag, UINT32 mode)
{
struct mqarray *mqueueCB = NULL;
UINT32 mqueueID;
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
if (OsIPCLimitMqAlloc() != LOS_OK) {
return (struct mqpersonal *)-1;
}
#endif
UINT32 err = LOS_QueueCreate(NULL, attr->mq_maxmsg, &mqueueID, 0, attr->mq_msgsize);
if (map_errno(err) != ENOERR) {
goto ERROUT;
@@ -201,15 +221,7 @@ STATIC struct mqpersonal *DoMqueueCreate(const struct mq_attr *attr, const CHAR
goto ERROUT;
}
mqueueCB->unlinkflag = FALSE;
mqueueCB->unlink_ref = 0;
mqueueCB->mq_personal->mq_status = MQ_USE_MAGIC;
mqueueCB->mq_personal->mq_next = NULL;
mqueueCB->mq_personal->mq_posixdes = mqueueCB;
mqueueCB->mq_personal->mq_flags = (INT32)((UINT32)openFlag | ((UINT32)attr->mq_flags & (UINT32)FNONBLOCK));
mqueueCB->mq_personal->mq_mode = mode;
mqueueCB->mq_personal->mq_refcount = 0;
mqueueCB->mq_notify.pid = 0;
MqueueCBInit(mqueueCB, attr, openFlag, mode);
return mqueueCB->mq_personal;
ERROUT:
@@ -218,6 +230,9 @@ ERROUT:
LOS_MemFree(OS_SYS_MEM_ADDR, mqueueCB->mq_name);
mqueueCB->mq_name = NULL;
}
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
OsIPCLimitMqFree();
#endif
return (struct mqpersonal *)-1;
}
@@ -946,4 +961,19 @@ OUT_UNLOCK:
ERROUT:
return -1;
}
VOID OsMqueueCBDestroy(struct mqarray *queueTable)
{
if (queueTable == NULL) {
return;
}
for (UINT32 index = 0; index < LOSCFG_BASE_IPC_QUEUE_LIMIT; index++) {
struct mqarray *mqueueCB = &(queueTable[index]);
if (mqueueCB->mq_name == NULL) {
continue;
}
(VOID)DoMqueueClose(mqueueCB->mq_personal);
}
}
#endif

View File

@@ -28,7 +28,7 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
import("//third_party/NuttX/NuttX.gni")
import("$THIRDPARTY_NUTTX_DIR/NuttX.gni")
module_switch = defined(LOSCFG_FS_VFS_BLOCK_DEVICE)
module_name = get_path_info(rebase_path("."), "name")

View File

@@ -97,5 +97,5 @@ static const struct file_operations_vfs g_memDevOps = {
int DevMemRegister(void)
{
return register_driver("/dev/mem", &g_memDevOps, 0666, 0); /* 0666: file mode */
return register_driver("/dev/mem", &g_memDevOps, 0644, 0); /* 0644: file mode */
}

View File

@@ -28,7 +28,7 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
import("//third_party/NuttX/NuttX.gni")
import("$THIRDPARTY_NUTTX_DIR/NuttX.gni")
module_switch = defined(LOSCFG_DRIVERS_VIDEO)
module_name = get_path_info(rebase_path("."), "name")

View File

@@ -28,7 +28,7 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
import("//third_party/FatFs/FatFs.gni")
import("$THIRDPARTY_FATFS_DIR/FatFs.gni")
module_switch = defined(LOSCFG_FS_FAT)
module_name = get_path_info(rebase_path("."), "name")

View File

@@ -31,7 +31,7 @@ import("//kernel/liteos_a/liteos.gni")
module_switch = defined(LOSCFG_FS_JFFS)
module_name = get_path_info(rebase_path("."), "name")
linux_path = rebase_path("//kernel/linux/linux-5.10")
linux_path = rebase_path("$KERNEL_LINUX_DIR")
out_path = rebase_path(target_out_dir)
kernel_module(module_name) {

View File

@@ -490,14 +490,14 @@ off_t VfsJffs2Seek(struct file *filep, off_t offset, int whence)
filePos = filep->f_pos;
switch (whence) {
case SEEK_SET:
filePos = offset;
break;
case SEEK_CUR:
filePos += offset;
break;
case SEEK_SET:
filePos = offset;
break;
case SEEK_END:
filePos = node->i_size + offset;
break;

View File

@@ -28,7 +28,7 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
import("//third_party/NuttX/NuttX.gni")
import("$THIRDPARTY_NUTTX_DIR/NuttX.gni")
module_switch = defined(LOSCFG_FS_NFS)
module_name = get_path_info(rebase_path("."), "name")

View File

@@ -38,10 +38,12 @@ kernel_module(module_name) {
"os_adapt/fs_cache_proc.c",
"os_adapt/mem_info.c",
"os_adapt/mounts_proc.c",
"os_adapt/plimits_proc.c",
"os_adapt/power_proc.c",
"os_adapt/proc_init.c",
"os_adapt/proc_vfs.c",
"os_adapt/process_proc.c",
"os_adapt/sys_user.c",
"os_adapt/uptime_proc.c",
"os_adapt/vmm_proc.c",
"src/proc_file.c",

View File

@@ -55,6 +55,16 @@ void ProcSysMemInfoInit(void);
void ProcFileSysInit(void);
#endif
#ifdef LOSCFG_KERNEL_PLIMITS
void ProcLimitsInit(void);
#endif
void ProcEntryClearVnode(struct ProcDirEntry *entry);
void ProcDetachNode(struct ProcDirEntry *pn);
void RemoveProcEntryTravalsal(struct ProcDirEntry *pn);
void ProcPmInit(void);
void ProcVmmInit(void);
@@ -77,6 +87,11 @@ void ProcFsCacheInit(void);
void ProcFdInit(void);
#ifdef LOSCFG_KERNEL_CONTAINER
void *ProcfsContainerGet(int fd, unsigned int *containerType);
void ProcSysUserInit(void);
#endif
#ifdef __cplusplus
#if __cplusplus
}

View File

@@ -93,6 +93,15 @@ struct ProcFileOperations {
ssize_t (*readLink)(struct ProcDirEntry *pde, char *buf, size_t bufLen);
};
#ifdef LOSCFG_KERNEL_PLIMITS
struct ProcDirOperations {
int (*rmdir)(struct ProcDirEntry *parent, struct ProcDirEntry *pde, const char *name);
int (*mkdir)(struct ProcDirEntry *parent, const char *dirName, mode_t mode, struct ProcDirEntry **pde);
};
#endif
#define PROC_DATA_STATIC 0
#define PROC_DATA_FREE 1
struct ProcDirEntry {
uint uid;
uint gid;
@@ -101,6 +110,10 @@ struct ProcDirEntry {
const struct ProcFileOperations *procFileOps;
struct ProcFile *pf;
struct ProcDirEntry *next, *parent, *subdir;
#ifdef LOSCFG_KERNEL_PLIMITS
const struct ProcDirOperations *procDirOps;
#endif
int dataType;
void *data;
atomic_t count; /* open file count */
spinlock_t pdeUnloadLock;
@@ -111,6 +124,11 @@ struct ProcDirEntry {
enum VnodeType type;
};
struct ProcDataParm {
void *data;
int dataType;
};
struct ProcFile {
fmode_t fMode;
spinlock_t fLock;
@@ -274,7 +292,7 @@ extern struct ProcDirEntry *ProcCreate(const char *name, mode_t mode,
*
*/
extern struct ProcDirEntry *ProcCreateData(const char *name, mode_t mode, struct ProcDirEntry *parent,
const struct ProcFileOperations *procFileOps, void *data);
const struct ProcFileOperations *procFileOps, struct ProcDataParm *param);
/**
* @ingroup procfs
* @brief init proc fs
@@ -297,6 +315,7 @@ extern struct ProcDirEntry *ProcCreateData(const char *name, mode_t mode, struct
*/
extern void ProcFsInit(void);
extern struct ProcDirEntry *VnodeToEntry(struct Vnode *node);
#ifdef __cplusplus
#if __cplusplus
}

View File

@@ -207,7 +207,7 @@ static const struct ProcFileOperations FS_CACHE_PROC_FOPS = {
void ProcFsCacheInit(void)
{
struct ProcDirEntry *pde = CreateProcEntry("fs_cache", 0, NULL);
struct ProcDirEntry *pde = CreateProcEntry("fs_cache", 0400, NULL);
if (pde == NULL) {
PRINT_ERR("create fs_cache error!\n");
return;

View File

@@ -0,0 +1,905 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/statfs.h>
#include <stdio.h>
#include <unistd.h>
#include "stdlib.h"
#include "los_printf.h"
#include "los_base.h"
#include "los_seq_buf.h"
#include "internal.h"
#include "proc_fs.h"
#include "los_task_pri.h"
#include "los_process_pri.h"
#include "los_process.h"
#include "show.h"
#include "vnode.h"
#include "proc_file.h"
#include "user_copy.h"
#ifdef LOSCFG_KERNEL_PLIMITS
#include "los_plimits.h"
#define PLIMITS_ENTRY_NAME_MAX 64
#define PLIMITERSET_DELETE_ALLOC 4
#define UNITPTR_NULL ((uintptr_t)(0xFFFFFFFF))
#define PLIMIT_FILE_MODE_READ_WRITE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
#define PLIMIT_FILE_MODE_READ_ONLY (S_IRUSR | S_IRGRP | S_IROTH)
#define PLIMIT_FILE_MODE_WRITE_ONLY (S_IWUSR)
#define PLIMIT_FILE_MODE_MASK_WRITE (~((mode_t)(S_IWUSR)))
#define PLIMIT_FILE_MODE_MASK_NONE (~((mode_t)(0)))
#define LOS_MAX_CACHE (UINT64)(0xFFFFFFFFFFFFFFFF)
#define PLIMIT_CAT_BUF_SIZE 512
#define MAX_PROTECTED_PROCESS_ID 14
#define UNITPTR_NULL ((uintptr_t)(0xFFFFFFFF))
static int ShowPids(struct SeqBuf *seqBuf, VOID *data);
static ssize_t PidMigrateFromProcLimiterSet(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
static ssize_t PidLimitReadPidLimit(struct SeqBuf *seqBuf, VOID *data);
static ssize_t PidLimitReadPriorityLimit(struct SeqBuf *seqBuf, VOID *data);
static ssize_t PriorityLimitVariableWrite(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
static ssize_t PidsMaxVariableWrite(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
static ssize_t ProcLimitsShowLimiters(struct SeqBuf *seqBuf, VOID *data);
static int ProcfsPlimitsMkdir(struct ProcDirEntry *parent, const char *dirName, mode_t mode, struct ProcDirEntry **pde);
static int ProcfsPlimitsRmdir(struct ProcDirEntry *parent, struct ProcDirEntry *pde, const char *name);
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
static ssize_t MemLimitReadLimit(struct SeqBuf *seqBuf, VOID *data);
static ssize_t MemLimitWriteLimit(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
static ssize_t MemLimitStatShow(struct SeqBuf *seqBuf, VOID *data);
#endif
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
static ssize_t IPCLimitReadMqLimit(struct SeqBuf *seqBuf, VOID *data);
static ssize_t IPCLimitWriteMqLimit(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
static ssize_t IPCLimitReadShmLimit(struct SeqBuf *seqBuf, VOID *data);
static ssize_t IPCLimitWriteShmLimit(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
static ssize_t IPCLimitShowStat(struct SeqBuf *seqBuf, VOID *data);
#endif
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
static ssize_t DevLimitWriteAllow(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
static ssize_t DevLimitWriteDeny(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
static ssize_t DevLimitShow(struct SeqBuf *seqBuf, VOID *data);
#endif
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
static ssize_t SchedLimitReadPeriod(struct SeqBuf *seqBuf, VOID *data);
static ssize_t SchedLimitWritePeriod(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
static ssize_t SchedLimitReadQuota(struct SeqBuf *seqBuf, VOID *data);
static ssize_t SchedLimitWriteQuota(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos);
static ssize_t SchedLimitShow(struct SeqBuf *seqBuf, VOID *data);
#endif
struct PLimitsEntryOpt {
int id;
char name[PLIMITS_ENTRY_NAME_MAX];
mode_t mode;
uintptr_t offset;
struct ProcFileOperations ops;
};
static struct ProcDirOperations g_procDirOperations = {
.mkdir = ProcfsPlimitsMkdir,
.rmdir = ProcfsPlimitsRmdir,
};
static struct PLimitsEntryOpt g_plimitsEntryOpts[] = {
{
.id = PROCESS_LIMITER_COUNT,
.name = "plimits.limiters",
.mode = PLIMIT_FILE_MODE_READ_ONLY,
.offset = UNITPTR_NULL,
.ops = {
.read = ProcLimitsShowLimiters,
}
},
{
.id = PROCESS_LIMITER_COUNT,
.name = "plimits.procs",
.mode = PLIMIT_FILE_MODE_READ_WRITE,
.offset = UNITPTR_NULL,
.ops = {
.read = ShowPids,
.write = PidMigrateFromProcLimiterSet,
},
},
{
.id = PROCESS_LIMITER_ID_PIDS,
.name = "pids.max",
.mode = PLIMIT_FILE_MODE_READ_WRITE,
.offset = 0,
.ops = {
.read = PidLimitReadPidLimit,
.write = PidsMaxVariableWrite,
},
},
{
.id = PROCESS_LIMITER_ID_PIDS,
.name = "pids.priority",
.mode = PLIMIT_FILE_MODE_READ_WRITE,
.offset = 0,
.ops = {
.read = PidLimitReadPriorityLimit,
.write = PriorityLimitVariableWrite,
},
},
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
{
.id = PROCESS_LIMITER_ID_MEM,
.name = "memory.limit",
.mode = PLIMIT_FILE_MODE_READ_WRITE,
.offset = 0,
.ops = {
.read = MemLimitReadLimit,
.write = MemLimitWriteLimit,
},
},
{
.id = PROCESS_LIMITER_ID_MEM,
.name = "memory.stat",
.mode = PLIMIT_FILE_MODE_READ_ONLY,
.offset = UNITPTR_NULL,
.ops = {
.read = MemLimitStatShow,
}
},
#endif
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
{
.id = PROCESS_LIMITER_ID_IPC,
.name = "ipc.mq_limit",
.mode = PLIMIT_FILE_MODE_READ_WRITE,
.offset = 0,
.ops = {
.read = IPCLimitReadMqLimit,
.write = IPCLimitWriteMqLimit,
}
},
{
.id = PROCESS_LIMITER_ID_IPC,
.name = "ipc.shm_limit",
.mode = PLIMIT_FILE_MODE_READ_WRITE,
.offset = 0,
.ops = {
.read = IPCLimitReadShmLimit,
.write = IPCLimitWriteShmLimit,
}
},
{
.id = PROCESS_LIMITER_ID_IPC,
.name = "ipc.stat",
.mode = PLIMIT_FILE_MODE_READ_ONLY,
.offset = UNITPTR_NULL,
.ops = {
.read = IPCLimitShowStat,
}
},
#endif
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
{
.id = PROCESS_LIMITER_ID_DEV,
.name = "devices.allow",
.mode = PLIMIT_FILE_MODE_WRITE_ONLY,
.offset = UNITPTR_NULL,
.ops = {
.write = DevLimitWriteAllow,
}
},
{
.id = PROCESS_LIMITER_ID_DEV,
.name = "devices.deny",
.mode = PLIMIT_FILE_MODE_WRITE_ONLY,
.offset = UNITPTR_NULL,
.ops = {
.write = DevLimitWriteDeny,
}
},
{
.id = PROCESS_LIMITER_ID_DEV,
.name = "devices.list",
.mode = PLIMIT_FILE_MODE_READ_ONLY,
.offset = 0,
.ops = {
.read = DevLimitShow,
}
},
#endif
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
{
.id = PROCESS_LIMITER_ID_SCHED,
.name = "sched.period",
.mode = PLIMIT_FILE_MODE_READ_WRITE,
.offset = 0,
.ops = {
.read = SchedLimitReadPeriod,
.write = SchedLimitWritePeriod,
},
},
{
.id = PROCESS_LIMITER_ID_SCHED,
.name = "sched.quota",
.mode = PLIMIT_FILE_MODE_READ_WRITE,
.offset = 0,
.ops = {
.read = SchedLimitReadQuota,
.write = SchedLimitWriteQuota,
},
},
{
.id = PROCESS_LIMITER_ID_SCHED,
.name = "sched.stat",
.mode = PLIMIT_FILE_MODE_READ_ONLY,
.offset = UNITPTR_NULL,
.ops = {
.read = SchedLimitShow,
}
},
#endif
};
static unsigned int MemUserCopy(const char *src, size_t len, char **kbuf)
{
if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, len)) {
char *kernelBuf = LOS_MemAlloc(m_aucSysMem1, len + 1);
if (kernelBuf == NULL) {
return ENOMEM;
}
if (LOS_ArchCopyFromUser(kernelBuf, src, len) != 0) {
(VOID)LOS_MemFree(m_aucSysMem1, kernelBuf);
return EFAULT;
}
kernelBuf[len] = '\0';
*kbuf = kernelBuf;
return 0;
}
return 0;
}
static inline struct ProcDirEntry *GetCurrDirectory(struct ProcDirEntry *dirEntry)
{
return ((dirEntry == NULL) || S_ISDIR(dirEntry->mode)) ? dirEntry : dirEntry->parent;
}
static inline ProcLimiterSet *GetProcLimiterSetFromDirEntry(struct ProcDirEntry *dirEntry)
{
struct ProcDirEntry *currDirectory = GetCurrDirectory(dirEntry);
return (currDirectory == NULL) || (currDirectory->data == NULL) ? NULL : (ProcLimiterSet *)currDirectory->data;
}
static struct ProcDirEntry *ProcCreateLimiterFiles(struct ProcDirEntry *parentEntry,
struct PLimitsEntryOpt *entryOpt,
mode_t mode, void *data)
{
struct ProcDataParm dataParm = {
.data = data,
.dataType = PROC_DATA_STATIC,
};
struct ProcDirEntry *plimitFile = ProcCreateData(entryOpt->name, entryOpt->mode & mode, parentEntry,
&entryOpt->ops, &dataParm);
if (plimitFile == NULL) {
return NULL;
}
return plimitFile;
}
static void ProcLimiterDirEntryInit(struct ProcDirEntry *dirEntry, unsigned mask, mode_t mode)
{
struct ProcDirEntry *currDir = GetCurrDirectory(dirEntry);
if (currDir == NULL) {
return;
}
ProcLimiterSet *plimiterData = (ProcLimiterSet *)currDir->data;
if (plimiterData == NULL) {
return;
}
for (int index = 0; index < (sizeof(g_plimitsEntryOpts) / sizeof(struct PLimitsEntryOpt)); index++) {
struct PLimitsEntryOpt *entryOpt = &g_plimitsEntryOpts[index];
enum ProcLimiterID plimiterType = entryOpt->id;
if (!(BIT(plimiterType) & mask)) {
continue;
}
void *head = (entryOpt->offset == UNITPTR_NULL) ?
plimiterData : (void *)plimiterData->limitsList[plimiterType];
struct ProcDirEntry *entry = ProcCreateLimiterFiles(currDir, entryOpt, mode, head);
if (entry == NULL) {
RemoveProcEntry(currDir->name, NULL);
return;
}
}
return;
}
static ssize_t PLimitsCopyLimits(struct ProcDirEntry *dirEntry)
{
struct ProcDirEntry *parentPde = dirEntry->parent;
ProcLimiterSet *parentPLimits = (ProcLimiterSet *)parentPde->data;
if (parentPLimits == NULL) {
return -EINVAL;
}
ProcLimiterSet *newPLimits = OsPLimitsCreate(parentPLimits);
if (newPLimits == NULL) {
return -ENOMEM;
}
dirEntry->data = (VOID *)newPLimits;
dirEntry->dataType = PROC_DATA_STATIC;
dirEntry->procDirOps = parentPde->procDirOps;
ProcLimiterDirEntryInit(dirEntry, newPLimits->mask, PLIMIT_FILE_MODE_MASK_NONE);
return 0;
}
static int ProcfsPlimitsMkdir(struct ProcDirEntry *parent, const char *dirName, mode_t mode, struct ProcDirEntry **pde)
{
int ret;
if (strcmp(parent->name, "plimits") != 0) {
return -EPERM;
}
struct ProcDirEntry *plimitDir = ProcCreateData(dirName, S_IFDIR | mode, parent, NULL, NULL);
if (plimitDir == NULL) {
return -EINVAL;
}
ret = PLimitsCopyLimits(plimitDir);
if (ret != LOS_OK) {
ProcFreeEntry(plimitDir);
return -ENOSYS;
}
*pde = plimitDir;
return ret;
}
static int ProcfsPlimitsRmdir(struct ProcDirEntry *parent, struct ProcDirEntry *pde, const char *name)
{
if (pde == NULL) {
return -EINVAL;
}
ProcLimiterSet *plimits = GetProcLimiterSetFromDirEntry(pde);
pde->data = NULL;
unsigned ret = OsPLimitsFree(plimits);
if (ret != 0) {
pde->data = plimits;
return -ret;
}
spin_lock(&procfsLock);
ProcDetachNode(pde);
spin_unlock(&procfsLock);
RemoveProcEntryTravalsal(pde->subdir);
ProcFreeEntry(pde);
return 0;
}
static ssize_t ProcLimitsShowLimiters(struct SeqBuf *seqBuf, VOID *data)
{
ProcLimiterSet *plimits = (ProcLimiterSet *)data;
UINT32 mask;
if (plimits == NULL) {
return -LOS_NOK;
}
mask = plimits->mask;
if (mask & BIT(PROCESS_LIMITER_ID_PIDS)) {
LosBufPrintf(seqBuf, "%s ", "pids");
}
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
if (mask & BIT(PROCESS_LIMITER_ID_MEM)) {
LosBufPrintf(seqBuf, "%s ", "memory");
}
#endif
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
if (mask & BIT(PROCESS_LIMITER_ID_IPC)) {
LosBufPrintf(seqBuf, "%s ", "ipc");
}
#endif
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
if (mask & BIT(PROCESS_LIMITER_ID_DEV)) {
LosBufPrintf(seqBuf, "%s ", "devices");
}
#endif
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
if (mask & BIT(PROCESS_LIMITER_ID_SCHED)) {
LosBufPrintf(seqBuf, "%s ", "sched");
}
#endif
return LOS_OK;
}
#define PLIMITS_PID_STR_LENGTH 4
static int ShowPids(struct SeqBuf *seqBuf, VOID *data)
{
unsigned int size, pidMax;
if (data == NULL) {
return -EINVAL;
}
const ProcLimiterSet *plimits = (const ProcLimiterSet *)data;
pidMax = LOS_GetSystemProcessMaximum();
size = pidMax * sizeof(unsigned int);
unsigned int *pids = (unsigned int *)LOS_MemAlloc(m_aucSysMem1, size);
if (pids == NULL) {
return -ENOMEM;
}
(void)memset_s(pids, size, 0, size);
unsigned int ret = OsPLimitsPidsGet(plimits, pids, size);
if (ret != LOS_OK) {
(VOID)LOS_MemFree(m_aucSysMem1, pids);
return -ret;
}
(void)LosBufPrintf(seqBuf, "\n");
for (unsigned int index = 0; index < pidMax; index++) {
if (pids[index] == 0) {
continue;
}
(void)LosBufPrintf(seqBuf, "%u ", index);
}
(void)LOS_MemFree(m_aucSysMem1, pids);
return 0;
}
static long long int GetPidLimitValue(struct ProcFile *pf, const CHAR *buf, size_t count)
{
long long int value;
char *kbuf = NULL;
if ((pf == NULL) || (pf->pPDE == NULL) || (buf == NULL) || (count <= 0)) {
return -EINVAL;
}
unsigned ret = MemUserCopy(buf, count, &kbuf);
if (ret != 0) {
return -ret;
} else if ((ret == 0) && (kbuf != NULL)) {
buf = (const char *)kbuf;
}
if (strspn(buf, "0123456789") != count) {
(void)LOS_MemFree(m_aucSysMem1, kbuf);
return -EINVAL;
}
value = strtoll(buf, NULL, 10); /* 10: decimal */
(void)LOS_MemFree(m_aucSysMem1, kbuf);
return value;
}
static ssize_t PidMigrateFromProcLimiterSet(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
{
(VOID)ppos;
unsigned ret;
long long int pid = GetPidLimitValue(pf, buf, count);
if (pid < 0) {
return pid;
}
ProcLimiterSet *plimits = GetCurrDirectory(pf->pPDE)->data;
ret = OsPLimitsAddPid(plimits, (unsigned int)pid);
if (ret != LOS_OK) {
return -ret;
}
return count;
}
static ssize_t PidLimitReadPidLimit(struct SeqBuf *seqBuf, VOID *data)
{
PidLimit *pidLimit = (PidLimit *)data;
if ((seqBuf == NULL) || (pidLimit == NULL)) {
return -EINVAL;
}
(void)LosBufPrintf(seqBuf, "%u\n", pidLimit->pidLimit);
return 0;
}
static ssize_t PidLimitReadPriorityLimit(struct SeqBuf *seqBuf, VOID *data)
{
PidLimit *pidLimit = (PidLimit *)data;
if ((seqBuf == NULL) || (pidLimit == NULL)) {
return -EINVAL;
}
(void)LosBufPrintf(seqBuf, "%u\n", pidLimit->priorityLimit);
return 0;
}
static ssize_t PriorityLimitVariableWrite(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
{
(void)ppos;
long long int value = GetPidLimitValue(pf, buf, count);
if (value < 0) {
return value;
}
PidLimit *pidLimit = (PidLimit *)pf->pPDE->data;
unsigned ret = PidLimitSetPriorityLimit(pidLimit, (unsigned)value);
if (ret != LOS_OK) {
return -ret;
}
return count;
}
static ssize_t PidsMaxVariableWrite(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
{
(void)ppos;
long long int value = GetPidLimitValue(pf, buf, count);
if (value < 0) {
return value;
}
PidLimit *pidLimit = (PidLimit *)pf->pPDE->data;
unsigned ret = PidLimitSetPidLimit(pidLimit, (unsigned)value);
if (ret != LOS_OK) {
return -ret;
}
return count;
}
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
static ssize_t MemLimitReadLimit(struct SeqBuf *seqBuf, VOID *data)
{
ProcMemLimiter *memLimit = (ProcMemLimiter *)data;
if ((seqBuf == NULL) || (memLimit == NULL)) {
return -EINVAL;
}
(void)LosBufPrintf(seqBuf, "%llu\n", memLimit->limit);
return 0;
}
static ssize_t MemLimitWriteLimit(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
{
(void)ppos;
long long int value = GetPidLimitValue(pf, buf, count);
if ((value < 0) || (value > (long long int)OS_NULL_INT)) {
return value;
}
ProcMemLimiter *memLimit = (ProcMemLimiter *)pf->pPDE->data;
unsigned ret = OsMemLimitSetMemLimit(memLimit, (unsigned long long)value);
if (ret != LOS_OK) {
return -ret;
}
return count;
}
static ssize_t MemLimitStatShow(struct SeqBuf *seqBuf, VOID *data)
{
ProcLimiterSet *plimits = (ProcLimiterSet *)data;
if ((seqBuf == NULL) || (plimits == NULL)) {
return -EINVAL;
}
UINT32 pidMax = LOS_GetSystemProcessMaximum();
UINT32 size = sizeof(ProcMemLimiter) + pidMax * sizeof(unsigned long long);
unsigned long long *usage = (unsigned long long *)LOS_MemAlloc(m_aucSysMem1, size);
if (usage == NULL) {
return -ENOMEM;
}
(void)memset_s(usage, size, 0, size);
unsigned int ret = OsPLimitsMemUsageGet(plimits, usage, size);
if (ret != LOS_OK) {
(VOID)LOS_MemFree(m_aucSysMem1, usage);
return -ret;
}
ProcMemLimiter *memLimit = (ProcMemLimiter *)usage;
unsigned long long *memUsage = (unsigned long long *)((uintptr_t)usage + sizeof(ProcMemLimiter));
(void)LosBufPrintf(seqBuf, "\nMem used: %llu\n", memLimit->usage);
(void)LosBufPrintf(seqBuf, "Mem peak: %llu\n", memLimit->peak);
(void)LosBufPrintf(seqBuf, "Mem failed count: %u\n", memLimit->failcnt);
for (unsigned int index = 0; index < pidMax; index++) {
if (memUsage[index] == 0) {
continue;
}
(void)LosBufPrintf(seqBuf, "PID: %u mem used: %llu \n", index, memUsage[index]);
}
(void)LOS_MemFree(m_aucSysMem1, usage);
return 0;
}
#endif
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
static ssize_t IPCLimitReadMqLimit(struct SeqBuf *seqBuf, VOID *data)
{
ProcIPCLimit *ipcLimit = (ProcIPCLimit *)data;
if ((seqBuf == NULL) || (ipcLimit == NULL)) {
return -EINVAL;
}
(void)LosBufPrintf(seqBuf, "%u\n", ipcLimit->mqCountLimit);
return 0;
}
static ssize_t IPCLimitWriteMqLimit(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
{
(void)ppos;
long long int value = GetPidLimitValue(pf, buf, count);
if (value < 0) {
return value;
}
ProcIPCLimit *ipcLimit = (ProcIPCLimit *)pf->pPDE->data;
unsigned ret = OsIPCLimitSetMqLimit(ipcLimit, (unsigned long long)value);
if (ret != LOS_OK) {
return -ret;
}
return count;
}
static ssize_t IPCLimitReadShmLimit(struct SeqBuf *seqBuf, VOID *data)
{
ProcIPCLimit *ipcLimit = (ProcIPCLimit *)data;
if ((seqBuf == NULL) || (ipcLimit == NULL)) {
return -EINVAL;
}
(void)LosBufPrintf(seqBuf, "%u\n", ipcLimit->shmSizeLimit);
return 0;
}
static ssize_t IPCLimitWriteShmLimit(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
{
(void)ppos;
long long int value = GetPidLimitValue(pf, buf, count);
if ((value < 0) || (value > (long long int)OS_NULL_INT)) {
return value;
}
ProcIPCLimit *ipcLimit = (ProcIPCLimit *)pf->pPDE->data;
unsigned ret = OsIPCLimitSetShmLimit(ipcLimit, (unsigned long long)value);
if (ret != LOS_OK) {
return -ret;
}
return count;
}
static ssize_t IPCLimitShowStat(struct SeqBuf *seqBuf, VOID *data)
{
ProcLimiterSet *plimits = (ProcLimiterSet *)data;
if ((seqBuf == NULL) || (plimits == NULL)) {
return -EINVAL;
}
unsigned int size = sizeof(ProcIPCLimit);
ProcIPCLimit *newIPCLimit = (ProcIPCLimit *)LOS_MemAlloc(m_aucSysMem1, size);
if (newIPCLimit == NULL) {
return -ENOMEM;
}
(void)memset_s(newIPCLimit, size, 0, size);
unsigned int ret = OsPLimitsIPCStatGet(plimits, newIPCLimit, size);
if (ret != LOS_OK) {
(VOID)LOS_MemFree(m_aucSysMem1, newIPCLimit);
return -ret;
}
(void)LosBufPrintf(seqBuf, "mq count: %u\n", newIPCLimit->mqCount);
(void)LosBufPrintf(seqBuf, "mq failed count: %u\n", newIPCLimit->mqFailedCount);
(void)LosBufPrintf(seqBuf, "shm size: %u\n", newIPCLimit->shmSize);
(void)LosBufPrintf(seqBuf, "shm failed count: %u\n", newIPCLimit->shmFailedCount);
(void)LOS_MemFree(m_aucSysMem1, newIPCLimit);
return 0;
}
#endif
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
static ssize_t DevLimitWriteAllow(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
{
(void)ppos;
char *kbuf = NULL;
if ((pf == NULL) || (pf->pPDE == NULL) || (buf == NULL) || (count <= 0)) {
return -EINVAL;
}
unsigned ret = MemUserCopy(buf, count, &kbuf);
if (ret != 0) {
return -ret;
} else if ((ret == 0) && (kbuf != NULL)) {
buf = (const char *)kbuf;
}
ProcLimiterSet *plimit = (ProcLimiterSet *)pf->pPDE->data;
ret = OsDevLimitWriteAllow(plimit, buf, count);
(VOID)LOS_MemFree(m_aucSysMem1, kbuf);
if (ret != LOS_OK) {
return -ret;
}
return count;
}
static ssize_t DevLimitWriteDeny(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
{
(void)ppos;
char *kbuf = NULL;
if ((pf == NULL) || (pf->pPDE == NULL) || (buf == NULL) || (count <= 0)) {
return -EINVAL;
}
unsigned ret = MemUserCopy(buf, count, &kbuf);
if (ret != 0) {
return -ret;
} else if ((ret == 0) && (kbuf != NULL)) {
buf = (const char *)kbuf;
}
ProcLimiterSet *plimit = (ProcLimiterSet *)pf->pPDE->data;
ret = OsDevLimitWriteDeny(plimit, buf, count);
(VOID)LOS_MemFree(m_aucSysMem1, kbuf);
if (ret != LOS_OK) {
return -ret;
}
return count;
}
static ssize_t DevLimitShow(struct SeqBuf *seqBuf, VOID *data)
{
ProcDevLimit *devLimit = (ProcDevLimit *)data;
if ((seqBuf == NULL) || (devLimit == NULL)) {
return -EINVAL;
}
unsigned ret = OsDevLimitShow(devLimit, seqBuf);
if (ret != LOS_OK) {
return -ret;
}
return 0;
}
#endif
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
static ssize_t SchedLimitReadPeriod(struct SeqBuf *seqBuf, VOID *data)
{
ProcSchedLimiter *schedLimit = (ProcSchedLimiter *)data;
if ((seqBuf == NULL) || (schedLimit == NULL)) {
return -EINVAL;
}
(void)LosBufPrintf(seqBuf, "%lld\n", schedLimit->period);
return 0;
}
static ssize_t SchedLimitWritePeriod(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
{
(void)ppos;
long long int value = GetPidLimitValue(pf, buf, count);
if (value < 0) {
return value;
}
ProcSchedLimiter *schedLimit = (ProcSchedLimiter *)pf->pPDE->data;
unsigned ret = OsSchedLimitSetPeriod(schedLimit, (unsigned long long)value);
if (ret != LOS_OK) {
return -ret;
}
return count;
}
static ssize_t SchedLimitReadQuota(struct SeqBuf *seqBuf, VOID *data)
{
ProcSchedLimiter *schedLimit = (ProcSchedLimiter *)data;
if ((seqBuf == NULL) || (schedLimit == NULL)) {
return -EINVAL;
}
(void)LosBufPrintf(seqBuf, "%lld\n", schedLimit->quota);
return 0;
}
static ssize_t SchedLimitWriteQuota(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos)
{
(void)ppos;
long long int value = GetPidLimitValue(pf, buf, count);
if (value < 0) {
return value;
}
ProcSchedLimiter *schedLimit = (ProcSchedLimiter *)pf->pPDE->data;
unsigned ret = OsSchedLimitSetQuota(schedLimit, (unsigned long long)value);
if (ret != LOS_OK) {
return -ret;
}
return count;
}
#define TIME_CYCLE_TO_US(time) ((((UINT64)time) * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US)
#define SCHED_DEFAULT_VALUE (0x101010101010101)
static ssize_t SchedLimitShow(struct SeqBuf *seqBuf, VOID *data)
{
ProcLimiterSet *plimits = (ProcLimiterSet *)data;
if ((seqBuf == NULL) || (plimits == NULL)) {
return -EINVAL;
}
UINT32 pidMax = LOS_GetSystemProcessMaximum();
UINT32 size = pidMax * sizeof(unsigned long long);
unsigned long long *usage = (unsigned long long *)LOS_MemAlloc(m_aucSysMem1, size);
if (usage == NULL) {
return -ENOMEM;
}
(void)memset_s(usage, size, 1, size);
unsigned int ret = OsPLimitsSchedUsageGet(plimits, usage, size);
if (ret != LOS_OK) {
(VOID)LOS_MemFree(m_aucSysMem1, usage);
return -ret;
}
for (unsigned int index = 0; index < pidMax; index++) {
if (usage[index] == SCHED_DEFAULT_VALUE) {
continue;
}
(void)LosBufPrintf(seqBuf, "PID: %u runTime: %llu us\n", index, TIME_CYCLE_TO_US(usage[index]));
}
(void)LOS_MemFree(m_aucSysMem1, usage);
return 0;
}
#endif
#define PROC_PLIMITS_MODE (S_IFDIR | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
void ProcLimitsInit(void)
{
struct ProcDirEntry *parentPDE = CreateProcEntry("plimits", PROC_PLIMITS_MODE, NULL);
if (parentPDE == NULL) {
return;
}
ProcLimiterSet *plimits = OsRootPLimitsGet();
parentPDE->procDirOps = &g_procDirOperations;
parentPDE->data = (VOID *)plimits;
parentPDE->dataType = PROC_DATA_STATIC;
plimits->mask = BIT(PROCESS_LIMITER_ID_PIDS) | BIT(PROCESS_LIMITER_COUNT);
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
plimits->mask |= BIT(PROCESS_LIMITER_ID_MEM);
#endif
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
plimits->mask |= BIT(PROCESS_LIMITER_ID_IPC);
#endif
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
plimits->mask |= BIT(PROCESS_LIMITER_ID_DEV);
#endif
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
plimits->mask |= BIT(PROCESS_LIMITER_ID_SCHED);
#endif
ProcLimiterDirEntryInit(parentPDE, plimits->mask, PLIMIT_FILE_MODE_MASK_WRITE);
return;
}
#endif

View File

@@ -72,6 +72,12 @@ void ProcFsInit(void)
ProcSysMemInfoInit();
ProcFileSysInit();
#endif
#ifdef LOSCFG_KERNEL_PLIMITS
ProcLimitsInit();
#endif
#ifdef LOSCFG_KERNEL_CONTAINER
ProcSysUserInit();
#endif
}
LOS_MODULE_INIT(ProcFsInit, LOS_INIT_LEVEL_KMOD_EXTENDED);

View File

@@ -45,7 +45,7 @@
static struct VnodeOps g_procfsVops;
static struct file_operations_vfs g_procfsFops;
static struct ProcDirEntry *VnodeToEntry(struct Vnode *node)
struct ProcDirEntry *VnodeToEntry(struct Vnode *node)
{
return (struct ProcDirEntry *)(node->data);
}
@@ -132,10 +132,8 @@ int VfsProcfsRead(struct file *filep, char *buffer, size_t buflen)
return -EPERM;
}
spin_lock(&entry->pdeUnloadLock);
size = (ssize_t)ReadProcFile(entry, (void *)buffer, buflen);
filep->f_pos = entry->pf->fPos;
spin_unlock(&entry->pdeUnloadLock);
VnodeDrop();
return size;
}
@@ -155,10 +153,8 @@ int VfsProcfsWrite(struct file *filep, const char *buffer, size_t buflen)
return -EPERM;
}
spin_lock(&entry->pdeUnloadLock);
size = (ssize_t)WriteProcFile(entry, (void *)buffer, buflen);
filep->f_pos = entry->pf->fPos;
spin_unlock(&entry->pdeUnloadLock);
VnodeDrop();
return size;
}
@@ -173,11 +169,9 @@ int VfsProcfsLookup(struct Vnode *parent, const char *name, int len, struct Vnod
return -ENODATA;
}
spin_lock(&procfsLock);
entry = entry->subdir;
while (1) {
if (entry == NULL) {
spin_unlock(&procfsLock);
return -ENOENT;
}
if (EntryMatch(name, len, entry)) {
@@ -185,7 +179,6 @@ int VfsProcfsLookup(struct Vnode *parent, const char *name, int len, struct Vnod
}
entry = entry->next;
}
spin_unlock(&procfsLock);
*vpp = EntryToVnode(entry);
if ((*vpp) == NULL) {
@@ -241,13 +234,58 @@ int VfsProcfsStat(struct Vnode *node, struct stat *buf)
return -EPERM;
}
(void)memset_s(buf, sizeof(struct stat), 0, sizeof(struct stat));
spin_lock(&entry->pdeUnloadLock);
buf->st_mode = entry->mode;
spin_unlock(&entry->pdeUnloadLock);
VnodeDrop();
return LOS_OK;
}
#ifdef LOSCFG_KERNEL_PLIMITS
int VfsProcfsMkdir(struct Vnode *parent, const char *dirName, mode_t mode, struct Vnode **vnode)
{
struct ProcDirEntry *parentEntry = VnodeToEntry(parent);
struct ProcDirEntry *pde = NULL;
if ((parentEntry->procDirOps == NULL) || (parentEntry->procDirOps->mkdir == NULL)) {
return -ENOSYS;
}
int ret = parentEntry->procDirOps->mkdir(parentEntry, dirName, mode, &pde);
if ((ret < 0) || (pde == NULL)) {
return ret;
}
*vnode = EntryToVnode(pde);
(*vnode)->vop = parent->vop;
(*vnode)->parent = parent;
(*vnode)->originMount = parent->originMount;
if ((*vnode)->type == VNODE_TYPE_DIR) {
(*vnode)->mode = S_IFDIR | PROCFS_DEFAULT_MODE;
} else {
(*vnode)->mode = S_IFREG | PROCFS_DEFAULT_MODE;
}
return ret;
}
int VfsProcfsRmdir(struct Vnode *parent, struct Vnode *vnode, const char *dirName)
{
if (parent == NULL) {
return -EINVAL;
}
struct ProcDirEntry *parentEntry = VnodeToEntry(parent);
if ((parentEntry->procDirOps == NULL) || (parentEntry->procDirOps->rmdir == NULL)) {
return -ENOSYS;
}
struct ProcDirEntry *dirEntry = VnodeToEntry(vnode);
int ret = parentEntry->procDirOps->rmdir(parentEntry, dirEntry, dirName);
if (ret < 0) {
return ret;
}
vnode->data = NULL;
return 0;
}
#endif
int VfsProcfsReaddir(struct Vnode *node, struct fs_dirent_s *dir)
{
int result;
@@ -269,11 +307,9 @@ int VfsProcfsReaddir(struct Vnode *node, struct fs_dirent_s *dir)
return -EPERM;
}
spin_lock(&pde->pdeUnloadLock);
while (i < dir->read_cnt) {
buffer = (char *)zalloc(sizeof(char) * NAME_MAX);
if (buffer == NULL) {
spin_unlock(&pde->pdeUnloadLock);
VnodeDrop();
PRINT_ERR("malloc failed\n");
return -ENOMEM;
@@ -288,7 +324,6 @@ int VfsProcfsReaddir(struct Vnode *node, struct fs_dirent_s *dir)
minSize = (dstNameSize < NAME_MAX) ? dstNameSize : NAME_MAX;
result = strncpy_s(dir->fd_dir[i].d_name, dstNameSize, buffer, minSize);
if (result != EOK) {
spin_unlock(&pde->pdeUnloadLock);
VnodeDrop();
free(buffer);
return -ENAMETOOLONG;
@@ -301,7 +336,6 @@ int VfsProcfsReaddir(struct Vnode *node, struct fs_dirent_s *dir)
i++;
free(buffer);
}
spin_unlock(&pde->pdeUnloadLock);
VnodeDrop();
return i;
}
@@ -315,15 +349,12 @@ int VfsProcfsOpendir(struct Vnode *node, struct fs_dirent_s *dir)
return -EINVAL;
}
spin_lock(&pde->pdeUnloadLock);
pde->pdirCurrent = pde->subdir;
if (pde->pf == NULL) {
spin_unlock(&pde->pdeUnloadLock);
VnodeDrop();
return -EINVAL;
}
pde->pf->fPos = 0;
spin_unlock(&pde->pdeUnloadLock);
VnodeDrop();
return LOS_OK;
}
@@ -341,9 +372,7 @@ int VfsProcfsOpen(struct file *filep)
return -EPERM;
}
spin_lock(&pde->pdeUnloadLock);
if (ProcOpen(pde->pf) != OK) {
spin_unlock(&pde->pdeUnloadLock);
return -ENOMEM;
}
if (S_ISREG(pde->mode) && (pde->procFileOps != NULL) && (pde->procFileOps->open != NULL)) {
@@ -354,7 +383,6 @@ int VfsProcfsOpen(struct file *filep)
pde->pf->fPos = 0;
}
filep->f_priv = (void *)pde;
spin_unlock(&pde->pdeUnloadLock);
VnodeDrop();
return LOS_OK;
}
@@ -369,19 +397,17 @@ int VfsProcfsClose(struct file *filep)
VnodeHold();
struct Vnode *node = filep->f_vnode;
struct ProcDirEntry *pde = VnodeToEntry(node);
if (pde == NULL) {
if ((pde == NULL) || (pde->pf == NULL)) {
VnodeDrop();
return -EPERM;
}
spin_lock(&pde->pdeUnloadLock);
pde->pf->fPos = 0;
if ((pde->procFileOps != NULL) && (pde->procFileOps->release != NULL)) {
result = pde->procFileOps->release((struct Vnode *)pde, pde->pf);
}
LosBufRelease(pde->pf->sbuf);
pde->pf->sbuf = NULL;
spin_unlock(&pde->pdeUnloadLock);
VnodeDrop();
return result;
}
@@ -411,11 +437,9 @@ ssize_t VfsProcfsReadlink(struct Vnode *vnode, char *buffer, size_t bufLen)
return -EPERM;
}
spin_lock(&pde->pdeUnloadLock);
if ((pde->procFileOps != NULL) && (pde->procFileOps->readLink != NULL)) {
result = pde->procFileOps->readLink(pde, buffer, bufLen);
}
spin_unlock(&pde->pdeUnloadLock);
return result;
}
@@ -433,6 +457,10 @@ static struct VnodeOps g_procfsVops = {
.Closedir = VfsProcfsClosedir,
.Truncate = VfsProcfsTruncate,
.Readlink = VfsProcfsReadlink,
#ifdef LOSCFG_KERNEL_PLIMITS
.Mkdir = VfsProcfsMkdir,
.Rmdir = VfsProcfsRmdir,
#endif
};
static struct file_operations_vfs g_procfsFops = {

View File

@@ -46,6 +46,11 @@ typedef enum {
#ifdef LOSCFG_KERNEL_CPUP
PROC_PID_CPUP,
#endif
#ifdef LOSCFG_USER_CONTAINER
PROC_UID_MAP,
PROC_GID_MAP,
#endif
PROC_P_TYPE_MAX,
} ProcessDataType;
struct ProcProcess {
@@ -84,6 +89,10 @@ static ssize_t ProcessContainerLink(unsigned int containerID, ContainerType type
count = snprintf_s(buffer, bufLen, bufLen - 1, "'ipc:[%u]'", containerID);
} else if ((type == TIME_CONTAINER) || (type == TIME_CHILD_CONTAINER)) {
count = snprintf_s(buffer, bufLen, bufLen - 1, "'time:[%u]'", containerID);
} else if (type == USER_CONTAINER) {
count = snprintf_s(buffer, bufLen, bufLen - 1, "'user:[%u]'", containerID);
} else if (type == NET_CONTAINER) {
count = snprintf_s(buffer, bufLen, bufLen - 1, "'net:[%u]'", containerID);
}
if (count < 0) {
@@ -94,6 +103,8 @@ static ssize_t ProcessContainerLink(unsigned int containerID, ContainerType type
static ssize_t ProcessContainerReadLink(struct ProcDirEntry *entry, char *buffer, size_t bufLen)
{
char *freeBuf = NULL;
char *buf = buffer;
ssize_t count;
unsigned int intSave;
if (entry == NULL) {
@@ -103,23 +114,79 @@ static ssize_t ProcessContainerReadLink(struct ProcDirEntry *entry, char *buffer
if (data == NULL) {
return -EINVAL;
}
if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)buffer, bufLen)) {
buf = LOS_MemAlloc(m_aucSysMem1, bufLen);
if (buf == NULL) {
return -ENOMEM;
}
(void)memset_s(buf, bufLen, 0, bufLen);
freeBuf = buf;
}
LosProcessCB *processCB = ProcGetProcessCB(data);
SCHEDULER_LOCK(intSave);
UINT32 containerID = OsGetContainerID(processCB->container, (ContainerType)data->type);
UINT32 containerID = OsGetContainerID(processCB, (ContainerType)data->type);
SCHEDULER_UNLOCK(intSave);
if (containerID != OS_INVALID_VALUE) {
return ProcessContainerLink(containerID, (ContainerType)data->type, buffer, bufLen);
count = ProcessContainerLink(containerID, (ContainerType)data->type, buf, bufLen);
} else {
count = strlen("(unknown)");
if (memcpy_s(buf, bufLen, "(unknown)", count + 1) != EOK) {
(void)LOS_MemFree(m_aucSysMem1, freeBuf);
return -EBADF;
}
}
count = strlen("(unknown)");
if (memcpy_s(buffer, bufLen, "(unknown)", count + 1) != EOK) {
return -EBADF;
if (count < 0) {
(void)LOS_MemFree(m_aucSysMem1, freeBuf);
return count;
}
if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)buffer, bufLen)) {
if (LOS_ArchCopyToUser(buffer, buf, bufLen) != 0) {
(void)LOS_MemFree(m_aucSysMem1, freeBuf);
return -EFAULT;
}
}
(void)LOS_MemFree(m_aucSysMem1, freeBuf);
return count;
}
static const struct ProcFileOperations PID_CONTAINER_FOPS = {
.readLink = ProcessContainerReadLink,
};
void *ProcfsContainerGet(int fd, unsigned int *containerType)
{
if ((fd <= 0) || (containerType == NULL)) {
return NULL;
}
VnodeHold();
struct Vnode *vnode = VnodeFind(fd);
if (vnode == NULL) {
VnodeDrop();
return NULL;
}
struct ProcDirEntry *entry = VnodeToEntry(vnode);
if (entry == NULL) {
VnodeDrop();
return NULL;
}
struct ProcessData *data = (struct ProcessData *)entry->data;
if (data == NULL) {
VnodeDrop();
return NULL;
}
void *processCB = (void *)ProcGetProcessCB(data);
*containerType = data->type;
VnodeDrop();
return processCB;
}
#endif /* LOSCFG_KERNEL_CONTAINER */
static int ProcessMemInfoRead(struct SeqBuf *seqBuf, LosProcessCB *pcb)
@@ -288,6 +355,121 @@ static const struct ProcFileOperations TIME_CONTAINER_FOPS = {
};
#endif
#ifdef LOSCFG_USER_CONTAINER
static void *MemdupUserNul(const void *src, size_t len)
{
char *des = NULL;
if (len <= 0) {
return NULL;
}
des = LOS_MemAlloc(OS_SYS_MEM_ADDR, len + 1);
if (des == NULL) {
return NULL;
}
if (LOS_ArchCopyFromUser(des, src, len) != 0) {
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, des);
return NULL;
}
des[len] = '\0';
return des;
}
static LosProcessCB *ProcUidGidMapWriteCheck(struct ProcFile *pf, const char *buf, size_t size,
char **kbuf, ProcessDataType *type)
{
if ((pf == NULL) || (size <= 0) || (size >= PAGE_SIZE)) {
return NULL;
}
struct ProcDirEntry *entry = pf->pPDE;
if (entry == NULL) {
return NULL;
}
struct ProcessData *data = (struct ProcessData *)entry->data;
if (data == NULL) {
return NULL;
}
*kbuf = MemdupUserNul(buf, size);
if (*kbuf == NULL) {
return NULL;
}
*type = (ProcessDataType)data->type;
return ProcGetProcessCB(data);
}
static ssize_t ProcIDMapWrite(struct ProcFile *file, const char *buf, size_t size, loff_t *ppos)
{
(void)ppos;
char *kbuf = NULL;
int ret;
unsigned int intSave;
ProcessDataType type = PROC_P_TYPE_MAX;
LosProcessCB *processCB = ProcUidGidMapWriteCheck(file, buf, size, &kbuf, &type);
if (processCB == NULL) {
return -EINVAL;
}
SCHEDULER_LOCK(intSave);
if ((processCB->credentials == NULL) || (processCB->credentials->userContainer == NULL)) {
SCHEDULER_UNLOCK(intSave);
(void)LOS_MemFree(m_aucSysMem1, kbuf);
return -EINVAL;
}
UserContainer *userContainer = processCB->credentials->userContainer;
if (userContainer->parent == NULL) {
SCHEDULER_UNLOCK(intSave);
(void)LOS_MemFree(m_aucSysMem1, kbuf);
return -EPERM;
}
if (type == PROC_UID_MAP) {
ret = OsUserContainerMapWrite(file, kbuf, size, CAP_SETUID,
&userContainer->uidMap, &userContainer->parent->uidMap);
} else {
ret = OsUserContainerMapWrite(file, kbuf, size, CAP_SETGID,
&userContainer->gidMap, &userContainer->parent->gidMap);
}
SCHEDULER_UNLOCK(intSave);
(void)LOS_MemFree(m_aucSysMem1, kbuf);
return ret;
}
static int ProcIDMapRead(struct SeqBuf *seqBuf, void *v)
{
unsigned int intSave;
if ((seqBuf == NULL) || (v == NULL)) {
return -EINVAL;
}
struct ProcessData *data = (struct ProcessData *)v;
LosProcessCB *processCB = ProcGetProcessCB(data);
SCHEDULER_LOCK(intSave);
if ((processCB->credentials == NULL) || (processCB->credentials->userContainer == NULL)) {
SCHEDULER_UNLOCK(intSave);
return -EINVAL;
}
UserContainer *userContainer = processCB->credentials->userContainer;
if ((userContainer != NULL) && (userContainer->parent == NULL)) {
UidGidExtent uidGidExtent = userContainer->uidMap.extent[0];
SCHEDULER_UNLOCK(intSave);
(void)LosBufPrintf(seqBuf, "%d %d %u\n", uidGidExtent.first, uidGidExtent.lowerFirst,
uidGidExtent.count);
return 0;
}
SCHEDULER_LOCK(intSave);
return 0;
}
static const struct ProcFileOperations UID_GID_MAP_FOPS = {
.read = ProcIDMapRead,
.write = ProcIDMapWrite,
};
#endif
static int ProcProcessRead(struct SeqBuf *m, void *v)
{
if ((m == NULL) || (v == NULL)) {
@@ -400,6 +582,34 @@ static struct ProcProcess g_procProcess[] = {
.fileOps = &TIME_CONTAINER_FOPS
},
#endif
#ifdef LOSCFG_IPC_CONTAINER
{
.name = "container/user",
.mode = S_IFLNK,
.type = USER_CONTAINER,
.fileOps = &PID_CONTAINER_FOPS
},
{
.name = "uid_map",
.mode = 0,
.type = PROC_UID_MAP,
.fileOps = &UID_GID_MAP_FOPS
},
{
.name = "gid_map",
.mode = 0,
.type = PROC_GID_MAP,
.fileOps = &UID_GID_MAP_FOPS
},
#endif
#ifdef LOSCFG_IPC_CONTAINER
{
.name = "container/net",
.mode = S_IFLNK,
.type = NET_CONTAINER,
.fileOps = &PID_CONTAINER_FOPS
},
#endif
#endif
};
@@ -414,6 +624,7 @@ void ProcFreeProcessDir(struct ProcDirEntry *processDir)
static struct ProcDirEntry *ProcCreatePorcess(UINT32 pid, struct ProcProcess *porcess, uintptr_t processCB)
{
int ret;
struct ProcDataParm dataParm;
char pidName[PROC_PID_DIR_LEN] = {0};
struct ProcessData *data = (struct ProcessData *)malloc(sizeof(struct ProcessData));
if (data == NULL) {
@@ -439,7 +650,9 @@ static struct ProcDirEntry *ProcCreatePorcess(UINT32 pid, struct ProcProcess *po
data->process = processCB;
data->type = porcess->type;
struct ProcDirEntry *container = ProcCreateData(pidName, porcess->mode, NULL, porcess->fileOps, (void *)data);
dataParm.data = data;
dataParm.dataType = PROC_DATA_FREE;
struct ProcDirEntry *container = ProcCreateData(pidName, porcess->mode, NULL, porcess->fileOps, &dataParm);
if (container == NULL) {
free(data);
PRINT_ERR("create /proc/%s error!\n", pidName);

228
fs/proc/os_adapt/sys_user.c Normal file
View File

@@ -0,0 +1,228 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/statfs.h>
#include <sys/mount.h>
#include "proc_fs.h"
#include "internal.h"
#include "los_process_pri.h"
#include "user_copy.h"
#include "los_memory.h"
#ifdef LOSCFG_KERNEL_CONTAINER
struct ProcSysUser {
char *name;
mode_t mode;
int type;
const struct ProcFileOperations *fileOps;
};
static unsigned int MemUserCopy(const char *src, size_t len, char **kbuf)
{
if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, len)) {
char *kernelBuf = LOS_MemAlloc(m_aucSysMem1, len + 1);
if (kernelBuf == NULL) {
return ENOMEM;
}
if (LOS_ArchCopyFromUser(kernelBuf, src, len) != 0) {
(VOID)LOS_MemFree(m_aucSysMem1, kernelBuf);
return EFAULT;
}
kernelBuf[len] = '\0';
*kbuf = kernelBuf;
return 0;
}
return 0;
}
static int GetContainerLimitValue(struct ProcFile *pf, const CHAR *buf, size_t count)
{
int value;
char *kbuf = NULL;
if ((pf == NULL) || (pf->pPDE == NULL) || (buf == NULL) || (count <= 0)) {
return -EINVAL;
}
unsigned ret = MemUserCopy(buf, count, &kbuf);
if (ret != 0) {
return -ret;
} else if ((ret == 0) && (kbuf != NULL)) {
buf = (const char *)kbuf;
}
if (strspn(buf, "0123456789") != count) {
(void)LOS_MemFree(m_aucSysMem1, kbuf);
return -EINVAL;
}
value = atoi(buf);
(void)LOS_MemFree(m_aucSysMem1, kbuf);
return value;
}
static ssize_t ProcSysUserWrite(struct ProcFile *pf, const char *buf, size_t size, loff_t *ppos)
{
(void)ppos;
unsigned ret;
int value = GetContainerLimitValue(pf, buf, size);
if (value < 0) {
return -EINVAL;
}
ContainerType type = (ContainerType)(uintptr_t)pf->pPDE->data;
ret = OsSetContainerLimit(type, value);
if (ret != LOS_OK) {
return -EINVAL;
}
return size;
}
static int ProcSysUserRead(struct SeqBuf *seqBuf, void *v)
{
unsigned ret;
if ((seqBuf == NULL) || (v == NULL)) {
return EINVAL;
}
ContainerType type = (ContainerType)(uintptr_t)v;
ret = OsGetContainerLimit(type);
if (ret == OS_INVALID_VALUE) {
return EINVAL;
}
(void)LosBufPrintf(seqBuf, "\nlimit: %u\n", ret);
(void)LosBufPrintf(seqBuf, "count: %u\n", OsGetContainerCount(type));
return 0;
}
static const struct ProcFileOperations SYS_USER_OPT = {
.read = ProcSysUserRead,
.write = ProcSysUserWrite,
};
static struct ProcSysUser g_sysUser[] = {
#ifdef LOSCFG_MNT_CONTAINER
{
.name = "max_mnt_container",
.mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
.type = MNT_CONTAINER,
.fileOps = &SYS_USER_OPT
},
#endif
#ifdef LOSCFG_PID_CONTAINER
{
.name = "max_pid_container",
.mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
.type = PID_CONTAINER,
.fileOps = &SYS_USER_OPT
},
#endif
#ifdef LOSCFG_USER_CONTAINER
{
.name = "max_user_container",
.mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
.type = USER_CONTAINER,
.fileOps = &SYS_USER_OPT
},
#endif
#ifdef LOSCFG_UTS_CONTAINER
{
.name = "max_uts_container",
.mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
.type = UTS_CONTAINER,
.fileOps = &SYS_USER_OPT
},
#endif
#ifdef LOSCFG_UTS_CONTAINER
{
.name = "max_time_container",
.mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
.type = UTS_CONTAINER,
.fileOps = &SYS_USER_OPT
},
#endif
#ifdef LOSCFG_IPC_CONTAINER
{
.name = "max_ipc_container",
.mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
.type = IPC_CONTAINER,
.fileOps = &SYS_USER_OPT
},
#endif
#ifdef LOSCFG_NET_CONTAINER
{
.name = "max_net_container",
.mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
.type = NET_CONTAINER,
.fileOps = &SYS_USER_OPT
},
#endif
};
static int ProcCreateSysUser(struct ProcDirEntry *parent)
{
struct ProcDataParm parm;
for (int index = 0; index < (sizeof(g_sysUser) / sizeof(struct ProcSysUser)); index++) {
struct ProcSysUser *sysUser = &g_sysUser[index];
parm.data = (void *)(uintptr_t)sysUser->type;
parm.dataType = PROC_DATA_STATIC;
struct ProcDirEntry *userFile = ProcCreateData(sysUser->name, sysUser->mode, parent, sysUser->fileOps, &parm);
if (userFile == NULL) {
PRINT_ERR("create /proc/%s/%s error!\n", parent->name, sysUser->name);
return -1;
}
}
return 0;
}
#define PROC_SYS_USER_MODE (S_IFDIR | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
void ProcSysUserInit(void)
{
struct ProcDirEntry *parentPDE = CreateProcEntry("sys", PROC_SYS_USER_MODE, NULL);
if (parentPDE == NULL) {
return;
}
struct ProcDirEntry *pde = CreateProcEntry("user", PROC_SYS_USER_MODE, parentPDE);
if (pde == NULL) {
PRINT_ERR("create /proc/process error!\n");
return;
}
int ret = ProcCreateSysUser(pde);
if (ret < 0) {
PRINT_ERR("Create proc sys user failed!\n");
}
return;
}
#endif

View File

@@ -296,7 +296,7 @@ static int ProcAddNode(struct ProcDirEntry *parent, struct ProcDirEntry *pn)
return 0;
}
static void ProcDetachNode(struct ProcDirEntry *pn)
void ProcDetachNode(struct ProcDirEntry *pn)
{
struct ProcDirEntry *parent = pn->parent;
struct ProcDirEntry **iter = NULL;
@@ -351,11 +351,12 @@ static struct ProcDirEntry *ProcCreateFile(struct ProcDirEntry *parent, const ch
}
pn->procFileOps = procFileOps;
pn->type = VNODE_TYPE_REG;
#ifdef LOSCFG_PROC_PROCESS_DIR
if (S_ISLNK(mode)) {
pn->type = VNODE_TYPE_LNK;
} else {
pn->type = VNODE_TYPE_REG;
pn->type = VNODE_TYPE_VIR_LNK;
}
#endif
ret = ProcAddNode(parent, pn);
if (ret != 0) {
free(pn->pf);
@@ -378,7 +379,7 @@ struct ProcDirEntry *CreateProcEntry(const char *name, mode_t mode, struct ProcD
return pde;
}
static void ProcEntryClearVnode(struct ProcDirEntry *entry)
void ProcEntryClearVnode(struct ProcDirEntry *entry)
{
struct Vnode *item = NULL;
struct Vnode *nextItem = NULL;
@@ -390,7 +391,7 @@ static void ProcEntryClearVnode(struct ProcDirEntry *entry)
}
if (VnodeFree(item) != LOS_OK) {
PRINT_ERR("ProcEntryClearVnode free failed, entry: %s : 0x%x \n", entry->name, item);
PRINT_ERR("ProcEntryClearVnode free failed, entry: %s\n", entry->name);
}
}
VnodeDrop();
@@ -403,18 +404,14 @@ static void FreeProcEntry(struct ProcDirEntry *entry)
return;
}
ProcEntryClearVnode(entry);
spin_lock(&entry->pdeUnloadLock);
if (entry->pf != NULL) {
free(entry->pf);
entry->pf = NULL;
}
if (entry->data != NULL) {
if ((entry->dataType == PROC_DATA_FREE) && (entry->data != NULL)) {
free(entry->data);
entry->data = NULL;
}
spin_unlock(&entry->pdeUnloadLock);
entry->data = NULL;
free(entry);
}
@@ -425,7 +422,7 @@ void ProcFreeEntry(struct ProcDirEntry *pn)
}
}
static void RemoveProcEntryTravalsal(struct ProcDirEntry *pn)
void RemoveProcEntryTravalsal(struct ProcDirEntry *pn)
{
if (pn == NULL) {
return;
@@ -433,6 +430,8 @@ static void RemoveProcEntryTravalsal(struct ProcDirEntry *pn)
RemoveProcEntryTravalsal(pn->next);
RemoveProcEntryTravalsal(pn->subdir);
ProcEntryClearVnode(pn);
ProcFreeEntry(pn);
}
@@ -462,6 +461,9 @@ void RemoveProcEntry(const char *name, struct ProcDirEntry *parent)
spin_unlock(&procfsLock);
RemoveProcEntryTravalsal(pn->subdir);
ProcEntryClearVnode(pn);
ProcFreeEntry(pn);
}
@@ -476,14 +478,17 @@ struct ProcDirEntry *ProcMkdir(const char *name, struct ProcDirEntry *parent)
}
struct ProcDirEntry *ProcCreateData(const char *name, mode_t mode, struct ProcDirEntry *parent,
const struct ProcFileOperations *procFileOps, void *data)
const struct ProcFileOperations *procFileOps, struct ProcDataParm *param)
{
struct ProcDirEntry *pde = CreateProcEntry(name, mode, parent);
if (pde != NULL) {
if (procFileOps != NULL) {
pde->procFileOps = procFileOps;
}
pde->data = data;
if (param != NULL) {
pde->data = param->data;
pde->dataType = param->dataType;
}
}
return pde;
}
@@ -591,16 +596,13 @@ struct ProcDirEntry *OpenProcFile(const char *fileName, int flags, ...)
return NULL;
}
spin_lock(&pn->pdeUnloadLock);
if (S_ISREG(pn->mode) && (pn->count != 1)) {
spin_unlock(&pn->pdeUnloadLock);
return NULL;
}
pn->flags = (unsigned int)(pn->flags) | (unsigned int)flags;
atomic_set(&pn->count, PROC_INUSE);
if (ProcOpen(pn->pf) != OK) {
spin_unlock(&pn->pdeUnloadLock);
return NULL;
}
if (S_ISREG(pn->mode) && (pn->procFileOps != NULL) && (pn->procFileOps->open != NULL)) {
@@ -610,7 +612,6 @@ struct ProcDirEntry *OpenProcFile(const char *fileName, int flags, ...)
pn->pdirCurrent = pn->subdir;
pn->pf->fPos = 0;
}
spin_unlock(&pn->pdeUnloadLock);
return pn;
}
@@ -649,7 +650,6 @@ int WriteProcFile(struct ProcDirEntry *pde, const void *buf, size_t len)
result = pde->procFileOps->write(pde->pf, (const char *)buf, len, &(pde->pf->fPos));
}
spin_unlock(&procfsLock);
return result;
}

View File

@@ -28,7 +28,7 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
import("//third_party/NuttX/NuttX.gni")
import("$THIRDPARTY_NUTTX_DIR/NuttX.gni")
module_switch = defined(LOSCFG_FS_RAMFS)
module_name = get_path_info(rebase_path("."), "name")

View File

@@ -28,7 +28,7 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
import("//third_party/NuttX/NuttX.gni")
import("$THIRDPARTY_NUTTX_DIR/NuttX.gni")
module_switch = defined(LOSCFG_FS_ROMFS)
module_name = get_path_info(rebase_path("."), "name")

View File

@@ -28,17 +28,14 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
import("//third_party/NuttX/NuttX.gni")
import("$THIRDPARTY_NUTTX_DIR/NuttX.gni")
module_switch = defined(LOSCFG_FS_VFS)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"$LITEOSTOPDIR/fs/vfs/epoll/fs_epoll.c",
"$LITEOSTOPDIR/fs/vfs/mount.c",
"$LITEOSTOPDIR/fs/vfs/path_cache.c",
"$LITEOSTOPDIR/fs/vfs/vnode.c",
"$LITEOSTOPDIR/fs/vfs/vnode_hash.c",
"epoll/fs_epoll.c",
"mount.c",
"operation/fullpath.c",
"operation/vfs_chattr.c",
"operation/vfs_check.c",
@@ -55,7 +52,10 @@ kernel_module(module_name) {
"operation/vfs_readv.c",
"operation/vfs_utime.c",
"operation/vfs_writev.c",
"path_cache.c",
"vfs_cmd/vfs_shellcmd.c",
"vnode.c",
"vnode_hash.c",
]
sources += NUTTX_FS_DIRENT_SRC_FILES
sources += NUTTX_FS_DRIVER_SRC_FILES

View File

@@ -101,6 +101,9 @@ enum VnodeType {
VNODE_TYPE_BCHR, /* block char mix device */
VNODE_TYPE_FIFO, /* pipe */
VNODE_TYPE_LNK, /* link */
#ifdef LOSCFG_PROC_PROCESS_DIR
VNODE_TYPE_VIR_LNK, /* virtual link */
#endif
};
struct fs_dirent_s;
@@ -189,4 +192,7 @@ LIST_HEAD* GetVnodeActiveList(void);
LIST_HEAD* GetVnodeVirtualList(void);
int VnodeClearCache(void);
struct Vnode *GetCurrRootVnode(void);
#ifdef LOSCFG_PROC_PROCESS_DIR
struct Vnode *VnodeFind(int fd);
#endif
#endif /* !_VNODE_H_ */

View File

@@ -138,7 +138,7 @@ int VnodeAlloc(struct VnodeOps *vop, struct Vnode **newVnode)
VnodeHold();
vnode = GetFromFreeList();
if ((vnode == NULL) && g_totalVnodeSize < LOSCFG_MAX_VNODE_SIZE) {
vnode = (struct Vnode*)zalloc(sizeof(struct Vnode));
vnode = (struct Vnode *)zalloc(sizeof(struct Vnode));
g_totalVnodeSize++;
}
@@ -716,7 +716,8 @@ void VnodeMemoryDump(void)
PRINTK("Vnode memory size = %d(B)\n", vnodeCount * sizeof(struct Vnode));
}
struct Vnode *GetVnode(INT32 fd)
#ifdef LOSCFG_PROC_PROCESS_DIR
struct Vnode *VnodeFind(int fd)
{
INT32 sysFd;
@@ -734,6 +735,7 @@ struct Vnode *GetVnode(INT32 fd)
return files_get_openfile((int)sysFd);
}
#endif
LIST_HEAD* GetVnodeFreeList()
{

View File

@@ -67,41 +67,6 @@ config PAGE_TABLE_FINE_LOCK
help
This option will enable fine lock for page table.
######################### config options of container ####################
config KERNEL_CONTAINER
bool "Enable container Feature"
default n
depends on KERNEL_VM
config PID_CONTAINER
bool "Enable pid container Feature"
default n
depends on KERNEL_CONTAINER
config UTS_CONTAINER
bool "Enable uts container Feature"
default n
depends on KERNEL_CONTAINER
config MNT_CONTAINER
bool "Enable mnt container Feature"
default n
depends on KERNEL_CONTAINER
config CHROOT
bool "Enable chroot"
default n
depends on MNT_CONTAINER
config IPC_CONTAINER
bool "Enable ipc container Feature"
default n
depends on KERNEL_CONTAINER
config TIME_CONTAINER
bool "Enable time container"
default n
depends on KERNEL_CONTAINER
######################### config options of extended #####################
source "kernel/extended/Kconfig"

View File

@@ -32,12 +32,6 @@ import("//kernel/liteos_a/liteos.gni")
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"container/los_container.c",
"container/los_ipc_container.c",
"container/los_mnt_container.c",
"container/los_pid_container.c",
"container/los_time_container.c",
"container/los_uts_container.c",
"core/los_bitmap.c",
"core/los_info.c",
"core/los_process.c",
@@ -73,6 +67,7 @@ kernel_module(module_name) {
"mp/los_percpu.c",
"mp/los_spinlock.c",
"om/los_err.c",
"sched/los_deadline.c",
"sched/los_idle.c",
"sched/los_priority.c",
"sched/los_sched.c",

View File

@@ -39,7 +39,6 @@ LOCAL_SRCS := $(wildcard ipc/*.c) $(wildcard core/*.c) $(wildcard mem/membox/*.
$(wildcard mp/*.c) \
$(wildcard sched/*.c) \
$(wildcard vm/*.c) \
$(wildcard container/*.c)
LOCAL_FLAGS := $(LITEOS_CFLAGS_INTERWORK) -Wno-frame-address

View File

@@ -1,354 +0,0 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_container_pri.h"
#include "los_process_pri.h"
#ifdef LOSCFG_KERNEL_CONTAINER
STATIC Container g_rootContainer;
STATIC Atomic g_containerCount = 0xF0000000U;
UINT32 OsAllocContainerID(VOID)
{
return LOS_AtomicIncRet(&g_containerCount);
}
VOID OsContainerInitSystemProcess(LosProcessCB *processCB)
{
processCB->container = &g_rootContainer;
LOS_AtomicInc(&processCB->container->rc);
#ifdef LOSCFG_PID_CONTAINER
(VOID)OsAllocSpecifiedVpidUnsafe(processCB->processID, processCB, NULL);
#endif
return;
}
VOID OsInitRootContainer(VOID)
{
#ifdef LOSCFG_PID_CONTAINER
(VOID)OsInitRootPidContainer(&g_rootContainer.pidContainer);
g_rootContainer.pidForChildContainer = g_rootContainer.pidContainer;
#endif
#ifdef LOSCFG_UTS_CONTAINER
(VOID)OsInitRootUtsContainer(&g_rootContainer.utsContainer);
#endif
#ifdef LOSCFG_MNT_CONTAINER
(VOID)OsInitRootMntContainer(&g_rootContainer.mntContainer);
#endif
#ifdef LOSCFG_IPC_CONTAINER
(VOID)OsInitRootIpcContainer(&g_rootContainer.ipcContainer);
#endif
#ifdef LOSCFG_TIME_CONTAINER
(VOID)OsInitRootTimeContainer(&g_rootContainer.timeContainer);
g_rootContainer.timeForChildContainer = g_rootContainer.timeContainer;
#endif
return;
}
STATIC INLINE Container *CreateContainer(VOID)
{
Container *container = (Container *)LOS_MemAlloc(m_aucSysMem1, sizeof(Container));
if (container == NULL) {
return NULL;
}
(VOID)memset_s(container, sizeof(Container), 0, sizeof(Container));
LOS_AtomicInc(&container->rc);
return container;
}
STATIC UINT32 CopyContainers(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID)
{
UINT32 ret = LOS_OK;
/* Pid container initialization must precede other container initialization. */
#ifdef LOSCFG_PID_CONTAINER
ret = OsCopyPidContainer(flags, child, parent, processID);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_UTS_CONTAINER
ret = OsCopyUtsContainer(flags, child, parent);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_MNT_CONTAINER
ret = OsCopyMntContainer(flags, child, parent);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_IPC_CONTAINER
ret = OsCopyIpcContainer(flags, child, parent);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_TIME_CONTAINER
ret = OsCopyTimeContainer(flags, child, parent);
if (ret != LOS_OK) {
return ret;
}
#endif
return ret;
}
/*
* called from clone. This now handles copy for Container and all
* namespaces therein.
*/
UINT32 OsCopyContainers(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID)
{
UINT32 intSave;
#ifdef LOSCFG_TIME_CONTAINER
flags &= ~CLONE_NEWTIME;
#endif
if (!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET | CLONE_NEWTIME))) {
#ifdef LOSCFG_PID_CONTAINER
if (parent->container->pidContainer != parent->container->pidForChildContainer) {
goto CREATE_CONTAINER;
}
#endif
#ifdef LOSCFG_TIME_CONTAINER
if (parent->container->timeContainer != parent->container->timeForChildContainer) {
goto CREATE_CONTAINER;
}
#endif
SCHEDULER_LOCK(intSave);
child->container = parent->container;
LOS_AtomicInc(&child->container->rc);
SCHEDULER_UNLOCK(intSave);
goto COPY_CONTAINERS;
}
#if defined(LOSCFG_PID_CONTAINER) || defined(LOSCFG_TIME_CONTAINER)
CREATE_CONTAINER:
#endif
child->container = CreateContainer();
if (child->container == NULL) {
return ENOMEM;
}
COPY_CONTAINERS:
return CopyContainers(flags, child, parent, processID);
}
VOID OsContainerFree(LosProcessCB *processCB)
{
LOS_AtomicDec(&processCB->container->rc);
if (LOS_AtomicRead(&processCB->container->rc) == 0) {
(VOID)LOS_MemFree(m_aucSysMem1, processCB->container);
processCB->container = NULL;
}
}
VOID OsContainersDestroy(LosProcessCB *processCB)
{
/* All processes in the container must be destroyed before the container is destroyed. */
#ifdef LOSCFG_PID_CONTAINER
if (processCB->processID == OS_USER_ROOT_PROCESS_ID) {
OsPidContainerDestroyAllProcess(processCB);
}
#endif
#ifdef LOSCFG_UTS_CONTAINER
OsUtsContainerDestroy(processCB->container);
#endif
#ifdef LOSCFG_MNT_CONTAINER
OsMntContainerDestroy(processCB->container);
#endif
#ifdef LOSCFG_IPC_CONTAINER
OsIpcContainerDestroy(processCB->container);
#endif
#ifdef LOSCFG_TIME_CONTAINER
OsTimeContainerDestroy(processCB);
#endif
#ifndef LOSCFG_PID_CONTAINER
UINT32 intSave;
SCHEDULER_LOCK(intSave);
OsContainerFree(processCB);
SCHEDULER_UNLOCK(intSave);
#endif
}
UINT32 OsGetContainerID(Container *container, ContainerType type)
{
if (container == NULL) {
return OS_INVALID_VALUE;
}
switch (type) {
#ifdef LOSCFG_PID_CONTAINER
case PID_CONTAINER:
return OsGetPidContainerID(container->pidContainer);
case PID_CHILD_CONTAINER:
return OsGetPidContainerID(container->pidForChildContainer);
#endif
#ifdef LOSCFG_UTS_CONTAINER
case UTS_CONTAINER:
return OsGetUtsContainerID(container->utsContainer);
#endif
#ifdef LOSCFG_MNT_CONTAINER
case MNT_CONTAINER:
return OsGetMntContainerID(container->mntContainer);
#endif
#ifdef LOSCFG_IPC_CONTAINER
case IPC_CONTAINER:
return OsGetIpcContainerID(container->ipcContainer);
#endif
#ifdef LOSCFG_TIME_CONTAINER
case TIME_CONTAINER:
return OsGetTimeContainerID(container->timeContainer);
case TIME_CHILD_CONTAINER:
return OsGetTimeContainerID(container->timeForChildContainer);
#endif
default:
break;
}
return OS_INVALID_VALUE;
}
STATIC VOID UnshareDeInitContainer(UINT32 flags, Container *container)
{
UINT32 intSave;
if (container == NULL) {
return;
}
#ifdef LOSCFG_PID_CONTAINER
UnshareDeInitPidContainer(container);
#endif
#ifdef LOSCFG_UTS_CONTAINER
if ((flags & CLONE_NEWUTS) != 0) {
OsUtsContainerDestroy(container);
}
#endif
#ifdef LOSCFG_MNT_CONTAINER
if ((flags & CLONE_NEWNS) != 0) {
OsMntContainerDestroy(container);
}
#endif
#ifdef LOSCFG_IPC_CONTAINER
if ((flags & CLONE_NEWIPC) != 0) {
OsIpcContainerDestroy(container);
}
#endif
#ifdef LOSCFG_TIME_CONTAINER
UnshareDeInitTimeContainer(container);
#endif
SCHEDULER_LOCK(intSave);
LOS_AtomicDec(&container->rc);
if (LOS_AtomicRead(&container->rc) == 0) {
(VOID)LOS_MemFree(m_aucSysMem1, container);
}
SCHEDULER_UNLOCK(intSave);
}
STATIC UINT32 CreateNewContainers(UINT32 flags, LosProcessCB *curr, Container *newContainer)
{
UINT32 ret = LOS_OK;
#ifdef LOSCFG_PID_CONTAINER
ret = OsUnsharePidContainer(flags, curr, newContainer);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_UTS_CONTAINER
ret = OsUnshareUtsContainer(flags, curr, newContainer);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_MNT_CONTAINER
ret = OsUnshareMntContainer(flags, curr, newContainer);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_IPC_CONTAINER
ret = OsUnshareIpcContainer(flags, curr, newContainer);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_TIME_CONTAINER
ret = OsUnshareTimeContainer(flags, curr, newContainer);
if (ret != LOS_OK) {
return ret;
}
#endif
return ret;
}
INT32 OsUnshare(UINT32 flags)
{
UINT32 ret;
UINT32 intSave;
LosProcessCB *curr = OsCurrProcessGet();
Container *oldContainer = curr->container;
UINT32 unshareFlags = CLONE_NEWPID | CLONE_NEWTIME | CLONE_NEWUTS | CLONE_NEWNS | CLONE_NEWIPC;
if (!(flags & unshareFlags) || ((flags & (~unshareFlags)) != 0)) {
return -EINVAL;
}
Container *newContainer = CreateContainer();
if (newContainer == NULL) {
return -ENOMEM;
}
ret = CreateNewContainers(flags, curr, newContainer);
if (ret != LOS_OK) {
goto EXIT;
}
SCHEDULER_LOCK(intSave);
oldContainer = curr->container;
curr->container = newContainer;
SCHEDULER_UNLOCK(intSave);
UnshareDeInitContainer(flags, oldContainer);
return LOS_OK;
EXIT:
UnshareDeInitContainer(flags, newContainer);
return -ret;
}
#endif

View File

@@ -109,6 +109,7 @@ STATIC VOID GetProcessInfo(ProcessInfo *pcbInfo, const LosProcessCB *processCB)
(VOID)memcpy_s(pcbInfo->name, OS_PCB_NAME_LEN, processCB->processName, OS_PCB_NAME_LEN);
}
#ifdef LOSCFG_KERNEL_VM
STATIC VOID GetProcessMemInfo(ProcessInfo *pcbInfo, const LosProcessCB *processCB, LosVmSpace *vmSpace)
{
/* Process memory usage statistics, idle task defaults to 0 */
@@ -130,6 +131,7 @@ STATIC VOID GetProcessMemInfo(ProcessInfo *pcbInfo, const LosProcessCB *processC
}
}
}
#endif
STATIC VOID GetThreadInfo(ProcessThreadInfo *threadInfo, LosProcessCB *processCB)
{
@@ -182,7 +184,9 @@ UINT32 OsGetProcessThreadInfo(UINT32 pid, ProcessThreadInfo *threadInfo)
return LOS_NOK;
}
#ifdef LOSCFG_KERNEL_VM
GetProcessMemInfo(&threadInfo->processInfo, processCB, processCB->vmSpace);
#endif
SCHEDULER_LOCK(intSave);
GetProcessInfo(&threadInfo->processInfo, processCB);
@@ -210,11 +214,14 @@ STATIC VOID ProcessMemUsageGet(ProcessInfo *pcbArray)
pcbInfo->status = OS_PROCESS_FLAG_UNUSED;
continue;
}
#ifdef LOSCFG_KERNEL_VM
LosVmSpace *vmSpace = processCB->vmSpace;
#endif
SCHEDULER_UNLOCK(intSave);
#ifdef LOSCFG_KERNEL_VM
GetProcessMemInfo(pcbInfo, processCB, vmSpace);
#endif
}
}

View File

@@ -71,7 +71,7 @@ LITE_OS_SEC_BSS ProcessGroup *g_processGroup = NULL;
STATIC INLINE VOID OsInsertPCBToFreeList(LosProcessCB *processCB)
{
#ifdef LOSCFG_PID_CONTAINER
OsPidContainerDestroy(processCB);
OsPidContainerDestroy(processCB->container, processCB);
#endif
UINT32 pid = processCB->processID;
(VOID)memset_s(processCB, sizeof(LosProcessCB), 0, sizeof(LosProcessCB));
@@ -133,7 +133,7 @@ UINT32 OsProcessAddNewTask(UINTPTR processID, LosTaskCB *taskCB, SchedParam *par
return LOS_OK;
}
STATIC ProcessGroup *CreateProcessGroup(LosProcessCB *processCB)
ProcessGroup *OsCreateProcessGroup(LosProcessCB *processCB)
{
ProcessGroup *pgroup = LOS_MemAlloc(m_aucSysMem1, sizeof(ProcessGroup));
if (pgroup == NULL) {
@@ -163,9 +163,15 @@ STATIC VOID ExitProcessGroup(LosProcessCB *processCB, ProcessGroup **pgroup)
LosProcessCB *pgroupCB = OS_GET_PGROUP_LEADER(processCB->pgroup);
LOS_ListDelete(&processCB->subordinateGroupList);
if (LOS_ListEmpty(&processCB->pgroup->processList) && LOS_ListEmpty(&processCB->pgroup->exitProcessList)) {
LOS_ListDelete(&processCB->pgroup->groupList);
#ifdef LOSCFG_PID_CONTAINER
if (processCB->pgroup != OS_ROOT_PGRP(processCB)) {
#endif
LOS_ListDelete(&processCB->pgroup->groupList);
*pgroup = processCB->pgroup;
#ifdef LOSCFG_PID_CONTAINER
}
#endif
pgroupCB->processStatus &= ~OS_PROCESS_FLAG_GROUP_LEADER;
*pgroup = processCB->pgroup;
if (OsProcessIsUnused(pgroupCB) && !(pgroupCB->processStatus & OS_PROCESS_FLAG_EXIT)) {
LOS_ListDelete(&pgroupCB->pendList);
OsInsertPCBToFreeList(pgroupCB);
@@ -436,7 +442,7 @@ LITE_OS_SEC_TEXT VOID OsProcessResourcesToFree(LosProcessCB *processCB)
#endif
#ifdef LOSCFG_KERNEL_CONTAINER
OsContainersDestroy(processCB);
OsOsContainersDestroyEarly(processCB);
#endif
#ifdef LOSCFG_FS_VFS
@@ -446,6 +452,13 @@ LITE_OS_SEC_TEXT VOID OsProcessResourcesToFree(LosProcessCB *processCB)
processCB->files = NULL;
#endif
#ifdef LOSCFG_KERNEL_CONTAINER
OsContainersDestroy(processCB);
#endif
#ifdef LOSCFG_KERNEL_PLIMITS
OsPLimitsDeleteProcess(processCB);
#endif
if (processCB->resourceLimit != NULL) {
(VOID)LOS_MemFree((VOID *)m_aucSysMem0, processCB->resourceLimit);
processCB->resourceLimit = NULL;
@@ -600,7 +613,9 @@ UINT32 OsProcessInit(VOID)
#ifdef LOSCFG_KERNEL_CONTAINER
OsInitRootContainer();
#endif
#ifdef LOSCFG_KERNEL_PLIMITS
OsProcLimiterSetInit();
#endif
SystemProcessEarlyInit(OsGetIdleProcess());
SystemProcessEarlyInit(OsGetUserInitProcess());
SystemProcessEarlyInit(OsGetKernelInitProcess());
@@ -816,7 +831,11 @@ LITE_OS_SEC_TEXT INT32 LOS_GetUserID(VOID)
INT32 uid;
SCHEDULER_LOCK(intSave);
#ifdef LOSCFG_USER_CONTAINER
uid = OsFromKuidMunged(OsCurrentUserContainer(), CurrentCredentials()->uid);
#else
uid = (INT32)OsCurrUserGet()->userID;
#endif
SCHEDULER_UNLOCK(intSave);
return uid;
#else
@@ -831,7 +850,11 @@ LITE_OS_SEC_TEXT INT32 LOS_GetGroupID(VOID)
INT32 gid;
SCHEDULER_LOCK(intSave);
#ifdef LOSCFG_USER_CONTAINER
gid = OsFromKgidMunged(OsCurrentUserContainer(), CurrentCredentials()->gid);
#else
gid = (INT32)OsCurrUserGet()->gid;
#endif
SCHEDULER_UNLOCK(intSave);
return gid;
@@ -855,7 +878,7 @@ STATIC UINT32 OsSystemProcessInit(LosProcessCB *processCB, UINT32 flags, const C
}
#endif
ProcessGroup *pgroup = CreateProcessGroup(processCB);
ProcessGroup *pgroup = OsCreateProcessGroup(processCB);
if (pgroup == NULL) {
ret = LOS_ENOMEM;
goto EXIT;
@@ -869,6 +892,13 @@ STATIC UINT32 OsSystemProcessInit(LosProcessCB *processCB, UINT32 flags, const C
}
#endif
#ifdef LOSCFG_KERNEL_PLIMITS
ret = OsPLimitsAddProcess(NULL, processCB);
if (ret != LOS_OK) {
ret = LOS_ENOMEM;
goto EXIT;
}
#endif
return LOS_OK;
EXIT:
@@ -909,7 +939,37 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSystemProcessCreate(VOID)
return LOS_OK;
}
STATIC INLINE INT32 OsProcessSchedlerParamCheck(INT32 which, INT32 pid, UINT16 prio, UINT16 policy)
INT32 OsSchedulerParamCheck(UINT16 policy, BOOL isThread, const LosSchedParam *param)
{
if (param == NULL) {
return LOS_EINVAL;
}
if ((policy == LOS_SCHED_RR) || (isThread && (policy == LOS_SCHED_FIFO))) {
if ((param->priority < OS_PROCESS_PRIORITY_HIGHEST) ||
(param->priority > OS_PROCESS_PRIORITY_LOWEST)) {
return LOS_EINVAL;
}
return LOS_OK;
}
if (policy == LOS_SCHED_DEADLINE) {
if ((param->runTimeUs < OS_SCHED_EDF_MIN_RUNTIME) || (param->runTimeUs >= param->deadlineUs)) {
return LOS_EINVAL;
}
if ((param->deadlineUs < OS_SCHED_EDF_MIN_DEADLINE) || (param->deadlineUs > OS_SCHED_EDF_MAX_DEADLINE)) {
return LOS_EINVAL;
}
if (param->periodUs < param->deadlineUs) {
return LOS_EINVAL;
}
return LOS_OK;
}
return LOS_EINVAL;
}
STATIC INLINE INT32 ProcessSchedulerParamCheck(INT32 which, INT32 pid, UINT16 policy, const LosSchedParam *param)
{
if (OS_PID_CHECK_INVALID(pid)) {
return LOS_EINVAL;
@@ -919,19 +979,11 @@ STATIC INLINE INT32 OsProcessSchedlerParamCheck(INT32 which, INT32 pid, UINT16 p
return LOS_EINVAL;
}
if (prio > OS_PROCESS_PRIORITY_LOWEST) {
return LOS_EINVAL;
}
if (policy != LOS_SCHED_RR) {
return LOS_EINVAL;
}
return LOS_OK;
return OsSchedulerParamCheck(policy, FALSE, param);
}
#ifdef LOSCFG_SECURITY_CAPABILITY
STATIC BOOL OsProcessCapPermitCheck(const LosProcessCB *processCB, const SchedParam *param, UINT16 prio)
STATIC BOOL OsProcessCapPermitCheck(const LosProcessCB *processCB, const SchedParam *param, UINT16 policy, UINT16 prio)
{
LosProcessCB *runProcess = OsCurrProcessGet();
@@ -941,7 +993,7 @@ STATIC BOOL OsProcessCapPermitCheck(const LosProcessCB *processCB, const SchedPa
}
/* user mode process can reduce the priority of itself */
if ((runProcess->processID == processCB->processID) && (prio > param->basePrio)) {
if ((runProcess->processID == processCB->processID) && (policy == LOS_SCHED_RR) && (prio > param->basePrio)) {
return TRUE;
}
@@ -953,12 +1005,13 @@ STATIC BOOL OsProcessCapPermitCheck(const LosProcessCB *processCB, const SchedPa
}
#endif
LITE_OS_SEC_TEXT INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 prio, UINT16 policy)
LITE_OS_SEC_TEXT INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 policy, const LosSchedParam *schedParam)
{
SchedParam param = { 0 };
BOOL needSched = FALSE;
UINT32 intSave;
INT32 ret = OsProcessSchedlerParamCheck(which, pid, prio, policy);
INT32 ret = ProcessSchedulerParamCheck(which, pid, policy, schedParam);
if (ret != LOS_OK) {
return -ret;
}
@@ -966,22 +1019,45 @@ LITE_OS_SEC_TEXT INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 prio
LosProcessCB *processCB = OS_PCB_FROM_PID(pid);
SCHEDULER_LOCK(intSave);
if (OsProcessIsInactive(processCB)) {
ret = LOS_ESRCH;
goto EXIT;
SCHEDULER_UNLOCK(intSave);
return -LOS_ESRCH;
}
#ifdef LOSCFG_SECURITY_CAPABILITY
if (!OsProcessCapPermitCheck(processCB, &param, prio)) {
ret = LOS_EPERM;
goto EXIT;
}
#endif
LosTaskCB *taskCB = processCB->threadGroup;
taskCB->ops->schedParamGet(taskCB, &param);
param.basePrio = prio;
BOOL needSched = taskCB->ops->schedParamModify(taskCB, &param);
#ifdef LOSCFG_SECURITY_CAPABILITY
if (!OsProcessCapPermitCheck(processCB, &param, policy, schedParam->priority)) {
SCHEDULER_UNLOCK(intSave);
return -LOS_EPERM;
}
#endif
if (param.policy != policy) {
if (policy == LOS_SCHED_DEADLINE) { /* HPF -> EDF */
if (processCB->threadNumber > 1) {
SCHEDULER_UNLOCK(intSave);
return -LOS_EPERM;
}
OsSchedParamInit(taskCB, policy, NULL, schedParam);
needSched = TRUE;
goto TO_SCHED;
} else if (param.policy == LOS_SCHED_DEADLINE) { /* EDF -> HPF */
SCHEDULER_UNLOCK(intSave);
return -LOS_EPERM;
}
}
if (policy == LOS_SCHED_DEADLINE) {
param.runTimeUs = schedParam->runTimeUs;
param.deadlineUs = schedParam->deadlineUs;
param.periodUs = schedParam->periodUs;
} else {
param.basePrio = schedParam->priority;
}
needSched = taskCB->ops->schedParamModify(taskCB, &param);
TO_SCHED:
SCHEDULER_UNLOCK(intSave);
LOS_MpSchedule(OS_MP_CPU_ALL);
@@ -989,25 +1065,26 @@ LITE_OS_SEC_TEXT INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 prio
LOS_Schedule();
}
return LOS_OK;
EXIT:
SCHEDULER_UNLOCK(intSave);
return -ret;
}
LITE_OS_SEC_TEXT INT32 LOS_SetProcessScheduler(INT32 pid, UINT16 policy, UINT16 prio)
LITE_OS_SEC_TEXT INT32 LOS_SetProcessScheduler(INT32 pid, UINT16 policy, const LosSchedParam *schedParam)
{
return OsSetProcessScheduler(LOS_PRIO_PROCESS, pid, prio, policy);
return OsSetProcessScheduler(LOS_PRIO_PROCESS, pid, policy, schedParam);
}
LITE_OS_SEC_TEXT INT32 LOS_GetProcessScheduler(INT32 pid)
LITE_OS_SEC_TEXT INT32 LOS_GetProcessScheduler(INT32 pid, INT32 *policy, LosSchedParam *schedParam)
{
UINT32 intSave;
SchedParam param = { 0 };
if (OS_PID_CHECK_INVALID(pid)) {
return -LOS_EINVAL;
}
if ((policy == NULL) && (schedParam == NULL)) {
return -LOS_EINVAL;
}
SCHEDULER_LOCK(intSave);
LosProcessCB *processCB = OS_PCB_FROM_PID(pid);
if (OsProcessIsUnused(processCB)) {
@@ -1015,14 +1092,48 @@ LITE_OS_SEC_TEXT INT32 LOS_GetProcessScheduler(INT32 pid)
return -LOS_ESRCH;
}
LosTaskCB *taskCB = processCB->threadGroup;
taskCB->ops->schedParamGet(taskCB, &param);
SCHEDULER_UNLOCK(intSave);
return LOS_SCHED_RR;
if (policy != NULL) {
if (param.policy == LOS_SCHED_FIFO) {
*policy = LOS_SCHED_RR;
} else {
*policy = param.policy;
}
}
if (schedParam != NULL) {
if (param.policy == LOS_SCHED_DEADLINE) {
schedParam->runTimeUs = param.runTimeUs;
schedParam->deadlineUs = param.deadlineUs;
schedParam->periodUs = param.periodUs;
} else {
schedParam->priority = param.basePrio;
}
}
return LOS_OK;
}
LITE_OS_SEC_TEXT INT32 LOS_SetProcessPriority(INT32 pid, UINT16 prio)
LITE_OS_SEC_TEXT INT32 LOS_SetProcessPriority(INT32 pid, INT32 prio)
{
return OsSetProcessScheduler(LOS_PRIO_PROCESS, pid, prio, LOS_GetProcessScheduler(pid));
INT32 ret;
INT32 policy;
LosSchedParam param = {
.priority = prio,
};
ret = LOS_GetProcessScheduler(pid, &policy, NULL);
if (ret != LOS_OK) {
return ret;
}
if (policy == LOS_SCHED_DEADLINE) {
return -LOS_EINVAL;
}
return OsSetProcessScheduler(LOS_PRIO_PROCESS, pid, (UINT16)policy, &param);
}
LITE_OS_SEC_TEXT INT32 OsGetProcessPriority(INT32 which, INT32 pid)
@@ -1049,6 +1160,11 @@ LITE_OS_SEC_TEXT INT32 OsGetProcessPriority(INT32 which, INT32 pid)
LosTaskCB *taskCB = processCB->threadGroup;
taskCB->ops->schedParamGet(taskCB, &param);
if (param.policy == LOS_SCHED_DEADLINE) {
SCHEDULER_UNLOCK(intSave);
return -LOS_EINVAL;
}
SCHEDULER_UNLOCK(intSave);
return param.basePrio;
}
@@ -1090,32 +1206,53 @@ STATIC VOID OsWaitInsertWaitListInOrder(LosTaskCB *runTask, LosProcessCB *proces
return;
}
STATIC UINT32 WaitFindSpecifiedProcess(UINT32 pid, LosTaskCB *runTask,
const LosProcessCB *processCB, LosProcessCB **childCB)
{
if (OS_PID_CHECK_INVALID((UINT32)pid)) {
return LOS_ECHILD;
}
LosProcessCB *waitProcess = OS_PCB_FROM_PID(pid);
if (OsProcessIsUnused(waitProcess)) {
return LOS_ECHILD;
}
#ifdef LOSCFG_PID_CONTAINER
if (OsPidContainerProcessParentIsRealParent(waitProcess, processCB)) {
*childCB = (LosProcessCB *)processCB;
return LOS_OK;
}
#endif
/* Wait for the child process whose process number is pid. */
*childCB = OsFindExitChildProcess(processCB, waitProcess);
if (*childCB != NULL) {
return LOS_OK;
}
if (OsFindChildProcess(processCB, waitProcess) != LOS_OK) {
return LOS_ECHILD;
}
runTask->waitFlag = OS_PROCESS_WAIT_PRO;
runTask->waitID = (UINTPTR)waitProcess;
return LOS_OK;
}
STATIC UINT32 OsWaitSetFlag(const LosProcessCB *processCB, INT32 pid, LosProcessCB **child)
{
UINT32 ret;
LosProcessCB *childCB = NULL;
LosTaskCB *runTask = OsCurrTaskGet();
if (pid > 0) {
if (OS_PID_CHECK_INVALID((UINT32)pid)) {
return LOS_ECHILD;
ret = WaitFindSpecifiedProcess((UINT32)pid, runTask, processCB, &childCB);
if (ret != LOS_OK) {
return ret;
}
LosProcessCB *waitProcess = OS_PCB_FROM_PID(pid);
if (OsProcessIsUnused(waitProcess)) {
return LOS_ECHILD;
}
/* Wait for the child process whose process number is pid. */
childCB = OsFindExitChildProcess(processCB, waitProcess);
if (childCB != NULL) {
goto WAIT_BACK;
}
if (OsFindChildProcess(processCB, waitProcess) != LOS_OK) {
return LOS_ECHILD;
}
runTask->waitFlag = OS_PROCESS_WAIT_PRO;
runTask->waitID = (UINTPTR)waitProcess;
} else if (pid == 0) {
/* Wait for any child process in the same process group */
childCB = OsFindGroupExitProcess(processCB->pgroup, OS_INVALID_VALUE);
@@ -1254,6 +1391,15 @@ STATIC INT32 OsWait(INT32 pid, USER INT32 *status, USER siginfo_t *info, UINT32
}
if (childCB != NULL) {
#ifdef LOSCFG_PID_CONTAINER
if (childCB == processCB) {
SCHEDULER_UNLOCK(intSave);
if (status != NULL) {
(VOID)LOS_ArchCopyToUser((VOID *)status, (const VOID *)(&ret), sizeof(INT32));
}
return pid;
}
#endif
return (INT32)OsWaitRecycleChildProcess(childCB, intSave, status, info);
}
@@ -1419,7 +1565,7 @@ STATIC UINT32 OsSetProcessGroupIDUnsafe(UINT32 pid, UINT32 gid, ProcessGroup **p
return LOS_OK;
}
newPGroup = CreateProcessGroup(pgroupCB);
newPGroup = OsCreateProcessGroup(pgroupCB);
if (newPGroup == NULL) {
LOS_ListTailInsert(&oldPGroup->processList, &processCB->subordinateGroupList);
processCB->pgroup = oldPGroup;
@@ -1790,6 +1936,38 @@ STATIC UINT32 OsCopyUser(LosProcessCB *childCB, LosProcessCB *parentCB)
return LOS_OK;
}
STATIC VOID GetCopyTaskParam(LosProcessCB *childProcessCB, UINTPTR entry, UINT32 size,
TSK_INIT_PARAM_S *taskParam, SchedParam *param)
{
UINT32 intSave;
LosTaskCB *runTask = OsCurrTaskGet();
SCHEDULER_LOCK(intSave);
if (OsProcessIsUserMode(childProcessCB)) {
taskParam->pfnTaskEntry = runTask->taskEntry;
taskParam->uwStackSize = runTask->stackSize;
taskParam->userParam.userArea = runTask->userArea;
taskParam->userParam.userMapBase = runTask->userMapBase;
taskParam->userParam.userMapSize = runTask->userMapSize;
} else {
taskParam->pfnTaskEntry = (TSK_ENTRY_FUNC)entry;
taskParam->uwStackSize = size;
}
if (runTask->taskStatus & OS_TASK_FLAG_PTHREAD_JOIN) {
taskParam->uwResved = LOS_TASK_ATTR_JOINABLE;
}
runTask->ops->schedParamGet(runTask, param);
SCHEDULER_UNLOCK(intSave);
taskParam->policy = param->policy;
taskParam->runTimeUs = param->runTimeUs;
taskParam->deadlineUs = param->deadlineUs;
taskParam->periodUs = param->periodUs;
taskParam->usTaskPrio = param->priority;
taskParam->processID = (UINTPTR)childProcessCB;
}
STATIC UINT32 OsCopyTask(UINT32 flags, LosProcessCB *childProcessCB, const CHAR *name, UINTPTR entry, UINT32 size)
{
LosTaskCB *runTask = OsCurrTaskGet();
@@ -1797,28 +1975,8 @@ STATIC UINT32 OsCopyTask(UINT32 flags, LosProcessCB *childProcessCB, const CHAR
UINT32 ret, taskID, intSave;
SchedParam param = { 0 };
SCHEDULER_LOCK(intSave);
if (OsProcessIsUserMode(childProcessCB)) {
taskParam.pfnTaskEntry = runTask->taskEntry;
taskParam.uwStackSize = runTask->stackSize;
taskParam.userParam.userArea = runTask->userArea;
taskParam.userParam.userMapBase = runTask->userMapBase;
taskParam.userParam.userMapSize = runTask->userMapSize;
} else {
taskParam.pfnTaskEntry = (TSK_ENTRY_FUNC)entry;
taskParam.uwStackSize = size;
}
if (runTask->taskStatus & OS_TASK_FLAG_PTHREAD_JOIN) {
taskParam.uwResved = LOS_TASK_ATTR_JOINABLE;
}
runTask->ops->schedParamGet(runTask, &param);
SCHEDULER_UNLOCK(intSave);
taskParam.pcName = (CHAR *)name;
taskParam.policy = param.policy;
taskParam.usTaskPrio = param.priority;
taskParam.processID = (UINTPTR)childProcessCB;
GetCopyTaskParam(childProcessCB, entry, size, &taskParam, &param);
ret = LOS_TaskCreateOnly(&taskID, &taskParam);
if (ret != LOS_OK) {
@@ -1850,30 +2008,26 @@ STATIC UINT32 OsCopyTask(UINT32 flags, LosProcessCB *childProcessCB, const CHAR
STATIC UINT32 OsCopyParent(UINT32 flags, LosProcessCB *childProcessCB, LosProcessCB *runProcessCB)
{
UINT32 ret;
UINT32 intSave;
LosProcessCB *parentProcessCB = NULL;
SCHEDULER_LOCK(intSave);
if (flags & CLONE_PARENT) {
parentProcessCB = runProcessCB->parentProcess;
} else {
parentProcessCB = runProcessCB;
if (childProcessCB->parentProcess == NULL) {
if (flags & CLONE_PARENT) {
parentProcessCB = runProcessCB->parentProcess;
} else {
parentProcessCB = runProcessCB;
}
childProcessCB->parentProcess = parentProcessCB;
LOS_ListTailInsert(&parentProcessCB->childrenList, &childProcessCB->siblingList);
}
childProcessCB->parentProcess = parentProcessCB;
LOS_ListTailInsert(&parentProcessCB->childrenList, &childProcessCB->siblingList);
if (!(flags & CLONE_NEWPID)) {
if (childProcessCB->pgroup == NULL) {
childProcessCB->pgroup = parentProcessCB->pgroup;
LOS_ListTailInsert(&parentProcessCB->pgroup->processList, &childProcessCB->subordinateGroupList);
} else {
if (CreateProcessGroup(childProcessCB) == NULL) {
SCHEDULER_UNLOCK(intSave);
return LOS_ENOMEM;
}
}
ret = OsCopyUser(childProcessCB, parentProcessCB);
SCHEDULER_UNLOCK(intSave);
return ret;
return LOS_OK;
}
STATIC UINT32 OsCopyMM(UINT32 flags, LosProcessCB *childProcessCB, LosProcessCB *runProcessCB)
@@ -1939,11 +2093,6 @@ STATIC UINT32 OsForkInitPCB(UINT32 flags, LosProcessCB *child, const CHAR *name,
UINT32 ret;
LosProcessCB *run = OsCurrProcessGet();
ret = OsInitPCB(child, run->processMode, name);
if (ret != LOS_OK) {
return ret;
}
ret = OsCopyParent(flags, child, run);
if (ret != LOS_OK) {
return ret;
@@ -1980,6 +2129,11 @@ STATIC UINT32 OsCopyProcessResources(UINT32 flags, LosProcessCB *child, LosProce
{
UINT32 ret;
ret = OsCopyUser(child, run);
if (ret != LOS_OK) {
return ret;
}
ret = OsCopyMM(flags, child, run);
if (ret != LOS_OK) {
return ret;
@@ -2016,11 +2170,23 @@ STATIC INT32 OsCopyProcess(UINT32 flags, const CHAR *name, UINTPTR sp, UINT32 si
}
processID = child->processID;
ret = OsInitPCB(child, run->processMode, name);
if (ret != LOS_OK) {
goto ERROR_INIT;
}
#ifdef LOSCFG_KERNEL_CONTAINER
ret = OsCopyContainers(flags, child, run, &processID);
if (ret != LOS_OK) {
goto ERROR_INIT;
}
#ifdef LOSCFG_KERNEL_PLIMITS
ret = OsPLimitsAddProcess(run->plimits, child);
if (ret != LOS_OK) {
goto ERROR_INIT;
}
#endif
#endif
ret = OsForkInitPCB(flags, child, name, sp, size);
@@ -2058,10 +2224,18 @@ LITE_OS_SEC_TEXT INT32 OsClone(UINT32 flags, UINTPTR sp, UINT32 size)
#ifdef LOSCFG_KERNEL_CONTAINER
#ifdef LOSCFG_PID_CONTAINER
cloneFlag |= CLONE_NEWPID;
LosProcessCB *curr = OsCurrProcessGet();
if (((flags & CLONE_NEWPID) != 0) && ((flags & (CLONE_PARENT | CLONE_THREAD)) != 0)) {
return -LOS_EINVAL;
}
if (OS_PROCESS_PID_FOR_CONTAINER_CHECK(curr) && ((flags & CLONE_NEWPID) != 0)) {
return -LOS_EINVAL;
}
if (OS_PROCESS_PID_FOR_CONTAINER_CHECK(curr) && ((flags & (CLONE_PARENT | CLONE_THREAD)) != 0)) {
return -LOS_EINVAL;
}
#endif
#ifdef LOSCFG_UTS_CONTAINER
cloneFlag |= CLONE_NEWUTS;
@@ -2078,6 +2252,12 @@ LITE_OS_SEC_TEXT INT32 OsClone(UINT32 flags, UINTPTR sp, UINT32 size)
#ifdef LOSCFG_TIME_CONTAINER
cloneFlag |= CLONE_NEWTIME;
#endif
#ifdef LOSCFG_USER_CONTAINER
cloneFlag |= CLONE_NEWUSER;
#endif
#ifdef LOSCFG_NET_CONTAINER
cloneFlag |= CLONE_NEWNET;
#endif
#endif
if (flags & (~cloneFlag)) {

View File

@@ -583,7 +583,7 @@ STATIC INLINE BOOL SwtmrRunqueueFind(SortLinkAttribute *swtmrSortLink, SCHED_TL_
STATIC BOOL SwtmrTimeListFind(SCHED_TL_FIND_FUNC checkFunc, UINTPTR arg)
{
for (UINT16 cpuid = 0; cpuid < LOSCFG_KERNEL_CORE_NUM; cpuid++) {
SortLinkAttribute *swtmrSortLink = &g_swtmrRunqueue[ArchCurrCpuid()].swtmrSortLink;
SortLinkAttribute *swtmrSortLink = &g_swtmrRunqueue[cpuid].swtmrSortLink;
if (SwtmrRunqueueFind(swtmrSortLink, checkFunc, arg)) {
return TRUE;
}

View File

@@ -394,7 +394,7 @@ STATIC VOID OsTaskResourcesToFree(LosTaskCB *taskCB)
return;
}
LITE_OS_SEC_TEXT VOID OsTaskCBRecycleToFree()
LITE_OS_SEC_TEXT VOID OsTaskCBRecycleToFree(void)
{
UINT32 intSave;
@@ -543,6 +543,7 @@ STATIC UINT32 TaskCBInit(LosTaskCB *taskCB, const TSK_INIT_PARAM_S *initParam)
UINT32 ret;
UINT32 numCount;
SchedParam schedParam = { 0 };
LosSchedParam initSchedParam = {0};
UINT16 policy = (initParam->policy == LOS_SCHED_NORMAL) ? LOS_SCHED_RR : initParam->policy;
TaskCBBaseInit(taskCB, initParam);
@@ -553,7 +554,14 @@ STATIC UINT32 TaskCBInit(LosTaskCB *taskCB, const TSK_INIT_PARAM_S *initParam)
return ret;
}
ret = OsSchedParamInit(taskCB, policy, &schedParam, initParam);
if (policy == LOS_SCHED_DEADLINE) {
initSchedParam.runTimeUs = initParam->runTimeUs;
initSchedParam.deadlineUs = initParam->deadlineUs;
initSchedParam.periodUs = initParam->periodUs;
} else {
initSchedParam.priority = initParam->usTaskPrio;
}
ret = OsSchedParamInit(taskCB, policy, &schedParam, &initSchedParam);
if (ret != LOS_OK) {
return ret;
}
@@ -1365,6 +1373,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsCreateUserTask(UINTPTR processID, TSK_INIT_PARAM_
UINT32 taskID;
UINT32 ret;
UINT32 intSave;
INT32 policy;
SchedParam param;
ret = OsCreateUserTaskParamCheck(processID, initParam);
if (ret != LOS_OK) {
@@ -1373,14 +1383,25 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsCreateUserTask(UINTPTR processID, TSK_INIT_PARAM_
initParam->uwStackSize = OS_USER_TASK_SYSCALL_STACK_SIZE;
initParam->usTaskPrio = OS_TASK_PRIORITY_LOWEST;
initParam->policy = LOS_SCHED_RR;
if (processID == OS_INVALID_VALUE) {
SCHEDULER_LOCK(intSave);
LosProcessCB *processCB = OsCurrProcessGet();
initParam->processID = (UINTPTR)processCB;
initParam->consoleID = processCB->consoleID;
SCHEDULER_UNLOCK(intSave);
ret = LOS_GetProcessScheduler(processCB->processID, &policy, NULL);
if (ret != LOS_OK) {
return OS_INVALID_VALUE;
}
initParam->policy = policy;
if (policy == LOS_SCHED_DEADLINE) {
OsSchedProcessDefaultSchedParamGet((UINT16)policy, &param);
initParam->runTimeUs = param.runTimeUs;
initParam->deadlineUs = param.deadlineUs;
initParam->periodUs = param.periodUs;
}
} else {
initParam->policy = LOS_SCHED_RR;
initParam->processID = processID;
initParam->consoleID = 0;
}

View File

@@ -45,9 +45,15 @@
#ifdef LOSCFG_IPC_CONTAINER
#include "los_ipc_container_pri.h"
#endif
#ifdef LOSCFG_USER_CONTAINER
#include "los_user_container_pri.h"
#endif
#ifdef LOSCFG_TIME_CONTAINER
#include "los_time_container_pri.h"
#endif
#ifdef LOSCFG_NET_CONTAINER
#include "los_net_container_pri.h"
#endif
typedef enum {
CONTAINER = 0,
@@ -56,8 +62,11 @@ typedef enum {
UTS_CONTAINER,
MNT_CONTAINER,
IPC_CONTAINER,
USER_CONTAINER,
TIME_CONTAINER,
TIME_CHILD_CONTAINER,
NET_CONTAINER,
CONTAINER_MAX,
} ContainerType;
typedef struct Container {
@@ -79,23 +88,61 @@ typedef struct Container {
struct TimeContainer *timeContainer;
struct TimeContainer *timeForChildContainer;
#endif
#ifdef LOSCFG_NET_CONTAINER
struct NetContainer *netContainer;
#endif
} Container;
typedef struct TagContainerLimit {
#ifdef LOSCFG_PID_CONTAINER
UINT32 pidLimit;
#endif
#ifdef LOSCFG_UTS_CONTAINER
UINT32 utsLimit;
#endif
#ifdef LOSCFG_MNT_CONTAINER
UINT32 mntLimit;
#endif
#ifdef LOSCFG_IPC_CONTAINER
UINT32 ipcLimit;
#endif
#ifdef LOSCFG_TIME_CONTAINER
UINT32 timeLimit;
#endif
#ifdef LOSCFG_USER_CONTAINER
UINT32 userLimit;
#endif
#ifdef LOSCFG_NET_CONTAINER
UINT32 netLimit;
#endif
} ContainerLimit;
VOID OsContainerInitSystemProcess(LosProcessCB *processCB);
VOID OsInitRootContainer(VOID);
UINT32 OsCopyContainers(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID);
VOID OsOsContainersDestroyEarly(LosProcessCB *processCB);
VOID OsContainersDestroy(LosProcessCB *processCB);
VOID OsContainerFree(LosProcessCB *processCB);
UINT32 OsAllocContainerID(VOID);
UINT32 OsGetContainerID(Container *container, ContainerType type);
UINT32 OsGetContainerID(LosProcessCB *processCB, ContainerType type);
INT32 OsUnshare(UINT32 flags);
INT32 OsSetNs(INT32 fd, INT32 type);
UINT32 OsGetContainerLimit(ContainerType type);
UINT32 OsContainerLimitCheck(ContainerType type, UINT32 *containerCount);
UINT32 OsSetContainerLimit(ContainerType type, UINT32 value);
UINT32 OsGetContainerCount(ContainerType type);
#endif
#endif /* _LOS_CONTAINER_PRI_H */

View File

@@ -0,0 +1,73 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_CREDENTIALS_PRI_H
#define _LOS_CREDENTIALS_PRI_H
#include "los_atomic.h"
#include "los_list.h"
#ifdef LOSCFG_USER_CONTAINER
struct Container;
struct UserContainer;
typedef struct ProcessCB LosProcessCB;
typedef struct Credentials {
Atomic rc;
UINT32 uid;
UINT32 gid;
UINT32 euid;
UINT32 egid;
struct UserContainer *userContainer;
} Credentials;
UINT32 OsCopyCredentials(unsigned long flags, LosProcessCB *child, LosProcessCB *parent);
UINT32 OsInitRootUserCredentials(Credentials **credentials);
UINT32 OsUnshareUserCredentials(UINTPTR flags, LosProcessCB *curr);
UINT32 OsSetNsUserContainer(struct UserContainer *targetContainer, LosProcessCB *runProcess);
VOID FreeCredential(Credentials *credentials);
VOID OsUserContainerDestroy(LosProcessCB *curr);
UINT32 OsGetUserContainerID(Credentials *credentials);
Credentials *PrepareCredential(LosProcessCB *runProcessCB);
INT32 CommitCredentials(Credentials *newCredentials);
Credentials *CurrentCredentials(VOID);
struct UserContainer *OsCurrentUserContainer(VOID);
#endif
#endif /* _LOS_CREDENTIALS_PRI_H */

View File

@@ -64,12 +64,16 @@ UINT32 OsCopyIpcContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
UINT32 OsUnshareIpcContainer(UINTPTR flags, LosProcessCB *curr, struct Container *newContainer);
UINT32 OsSetNsIpcContainer(UINT32 flags, struct Container *container, struct Container *newContainer);
VOID OsIpcContainerDestroy(struct Container *container);
UINT32 OsGetIpcContainerID(IpcContainer *ipcContainer);
IpcContainer *OsGetCurrIpcContainer(VOID);
UINT32 OsGetIpcContainerCount(VOID);
#define IPC_ALL_QUEUE (OsGetCurrIpcContainer()->allQueue)
#define FREE_QUEUE_LIST (OsGetCurrIpcContainer()->freeQueueList)

View File

@@ -55,9 +55,12 @@ UINT32 OsCopyMntContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
UINT32 OsUnshareMntContainer(UINTPTR flags, LosProcessCB *curr, struct Container *newContainer);
UINT32 OsSetNsMntContainer(UINT32 flags, struct Container *container, struct Container *newContainer);
VOID OsMntContainerDestroy(struct Container *container);
UINT32 OsGetMntContainerID(MntContainer *mntContainer);
UINT32 OsGetMntContainerCount(VOID);
#endif
#endif

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_NET_CONTAINER_PRI_H
#define _LOS_NET_CONTAINER_PRI_H
#include <lwip/net_group.h>
#include <lwip/netif.h>
#include <lwip/ip.h>
#include "los_atomic.h"
#ifdef LOSCFG_NET_CONTAINER
typedef struct ProcessCB LosProcessCB;
struct Container;
typedef struct NetContainer {
Atomic rc;
struct net_group *group;
UINT32 containerID;
} NetContainer;
UINT32 OsInitRootNetContainer(NetContainer **ipcContainer);
UINT32 OsCopyNetContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent);
UINT32 OsUnshareNetContainer(UINTPTR flags, LosProcessCB *curr, struct Container *newContainer);
UINT32 OsSetNsNetContainer(UINT32 flags, struct Container *container, struct Container *newContainer);
VOID OsNetContainerDestroy(struct Container *container);
UINT32 OsGetNetContainerID(NetContainer *ipcContainer);
UINT32 OsGetNetContainerCount(VOID);
#endif
#endif /* _LOS_NET_CONTAINER_PRI_H */

View File

@@ -43,6 +43,7 @@ typedef struct {
UINT32 vid; /* Virtual ID */
UINT32 vpid; /* Virtual parent ID */
UINTPTR cb; /* Control block */
LosProcessCB *realParent; /* process real parent */
LOS_DL_LIST node;
} ProcessVid;
@@ -69,17 +70,22 @@ typedef struct PidContainer {
#define OS_PROCESS_CONTAINER_CHECK(processCB, currProcessCB) \
((processCB)->container->pidContainer != (currProcessCB)->container->pidContainer)
UINT32 OsAllocSpecifiedVpidUnsafe(UINT32 vpid, LosProcessCB *processCB, LosProcessCB *parent);
#define OS_PROCESS_PID_FOR_CONTAINER_CHECK(processCB) \
(((processCB)->container->pidContainer != (processCB)->container->pidForChildContainer) && \
((processCB)->container->pidForChildContainer->referenced == FALSE))
UINT32 OsAllocSpecifiedVpidUnsafe(UINT32 vpid, PidContainer *pidContainer,
LosProcessCB *processCB, LosProcessCB *parent);
VOID OsPidContainerDestroyAllProcess(LosProcessCB *processCB);
VOID OsPidContainerDestroy(LosProcessCB *curr);
VOID OsPidContainerDestroy(struct Container *container, LosProcessCB *processCB);
UINT32 OsCopyPidContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID);
UINT32 OsUnsharePidContainer(UINTPTR flags, LosProcessCB *curr, struct Container *newContainer);
VOID UnshareDeInitPidContainer(struct Container *container);
UINT32 OsSetNsPidContainer(UINT32 flags, struct Container *container, struct Container *newContainer);
UINT32 OsInitRootPidContainer(PidContainer **pidContainer);
@@ -99,4 +105,7 @@ UINT32 OsAllocVtid(LosTaskCB *taskCB, const LosProcessCB *processCB);
UINT32 OsGetPidContainerID(PidContainer *pidContainer);
BOOL OsPidContainerProcessParentIsRealParent(const LosProcessCB *processCB, const LosProcessCB *curr);
UINT32 OsGetPidContainerCount(VOID);
#endif /* _LOS_PID_CONTAINER_PRI_H */

View File

@@ -50,6 +50,9 @@
#ifdef LOSCFG_KERNEL_CONTAINER
#include "los_container_pri.h"
#endif
#ifdef LOSCFG_KERNEL_PLIMITS
#include "los_plimits.h"
#endif
#ifdef __cplusplus
#if __cplusplus
@@ -132,10 +135,18 @@ typedef struct ProcessCB {
struct rlimit *resourceLimit;
#ifdef LOSCFG_KERNEL_CONTAINER
Container *container;
#ifdef LOSCFG_USER_CONTAINER
struct Credentials *credentials;
#endif
#endif
#ifdef LOSCFG_PROC_PROCESS_DIR
struct ProcDirEntry *procDir;
#endif
#ifdef LOSCFG_KERNEL_PLIMITS
ProcLimiterSet *plimits;
LOS_DL_LIST plimitsList; /* plimit process list */
PLimitsData limitStat;
#endif
} LosProcessCB;
extern LosProcessCB *g_processCBArray;
@@ -524,7 +535,7 @@ extern LosVmSpace *OsExecProcessVmSpaceReplace(LosVmSpace *newSpace, UINTPTR sta
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);
extern INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 policy, const LosSchedParam *param);
extern INT32 OsGetProcessPriority(INT32 which, INT32 pid);
extern LosProcessCB *OsGetUserInitProcess(VOID);
extern LosProcessCB *OsGetIdleProcess(VOID);
@@ -541,6 +552,8 @@ extern VOID OsDeleteTaskFromProcess(LosTaskCB *taskCB);
extern VOID OsProcessThreadGroupDestroy(VOID);
extern UINT32 OsGetProcessGroupCB(UINT32 pid, UINTPTR *ppgroupLeader);
extern LosProcessCB *OsGetDefaultProcessCB(VOID);
extern ProcessGroup *OsCreateProcessGroup(LosProcessCB *processCB);
INT32 OsSchedulerParamCheck(UINT16 policy, BOOL isThread, const LosSchedParam *param);
#ifdef __cplusplus
#if __cplusplus
}

View File

@@ -68,6 +68,10 @@ extern "C" {
#define OS_SCHED_TICK_TO_CYCLE(ticks) ((UINT64)ticks * OS_CYCLE_PER_TICK)
#define AFFI_MASK_TO_CPUID(mask) ((UINT16)((mask) - 1))
#define OS_SCHED_EDF_MIN_RUNTIME 100 /* 100 us */
#define OS_SCHED_EDF_MIN_DEADLINE 400 /* 400 us */
#define OS_SCHED_EDF_MAX_DEADLINE 5000000 /* 5 s */
extern UINT32 g_taskScheduled;
#define OS_SCHEDULER_ACTIVE (g_taskScheduled & (1U << ArchCurrCpuid()))
#define OS_SCHEDULER_ALL_ACTIVE (g_taskScheduled == LOSCFG_KERNEL_CPU_MASK)
@@ -98,9 +102,16 @@ typedef struct {
UINT32 queueBitmap;
} HPFRunqueue;
typedef struct {
LOS_DL_LIST root;
LOS_DL_LIST waitList;
UINT64 period;
} EDFRunqueue;
typedef struct {
SortLinkAttribute timeoutQueue; /* task timeout queue */
HPFRunqueue *hpfRunqueue;
EDFRunqueue *edfRunqueue;
UINT64 responseTime; /* Response time for current CPU tick interrupts */
UINT32 responseID; /* The response ID of the current CPU tick interrupt */
LosTaskCB *idleTask; /* idle task id */
@@ -212,30 +223,52 @@ STATIC INLINE VOID OsSchedRunqueuePendingSet(VOID)
OsSchedRunqueue()->schedFlag |= INT_PEND_RESCH;
}
#define LOS_SCHED_NORMAL 0U
#define LOS_SCHED_FIFO 1U
#define LOS_SCHED_RR 2U
#define LOS_SCHED_IDLE 3U
#define LOS_SCHED_NORMAL 0U
#define LOS_SCHED_FIFO 1U
#define LOS_SCHED_RR 2U
#define LOS_SCHED_IDLE 3U
#define LOS_SCHED_DEADLINE 6U
typedef struct {
UINT16 policy;
/* HPF scheduling parameters */
UINT16 basePrio;
UINT16 priority;
UINT32 timeSlice;
/* EDF scheduling parameters */
INT32 runTimeUs;
UINT32 deadlineUs;
UINT32 periodUs;
} SchedParam;
typedef struct {
UINT16 policy; /* This field must be present for all scheduling policies and must be the first in the structure */
UINT16 basePrio;
UINT16 priority;
UINT32 initTimeSlice;
UINT32 priBitmap; /**< Bitmap for recording the change of task priority, the priority can not be greater than 31 */
UINT32 initTimeSlice; /* cycle */
UINT32 priBitmap; /* Bitmap for recording the change of task priority, the priority can not be greater than 31 */
} SchedHPF;
#define EDF_UNUSED 0
#define EDF_NEXT_PERIOD 1
#define EDF_WAIT_FOREVER 2
#define EDF_INIT 3
typedef struct {
UINT16 policy;
UINT16 cpuid;
UINT32 flags;
INT32 runTime; /* cycle */
UINT64 deadline; /* deadline >> runTime */
UINT64 period; /* period >= deadline */
UINT64 finishTime; /* startTime + deadline */
} SchedEDF;
typedef struct {
union {
SchedEDF edf;
SchedHPF hpf;
} Policy;
};
} SchedPolicy;
typedef struct {
@@ -243,6 +276,7 @@ typedef struct {
VOID (*enqueue)(SchedRunqueue *rq, LosTaskCB *taskCB);
VOID (*start)(SchedRunqueue *rq, LosTaskCB *taskCB);
VOID (*exit)(LosTaskCB *taskCB);
UINT64 (*waitTimeGet)(LosTaskCB *taskCB);
UINT32 (*wait)(LosTaskCB *runTask, LOS_DL_LIST *list, UINT32 timeout);
VOID (*wake)(LosTaskCB *taskCB);
BOOL (*schedParamModify)(LosTaskCB *taskCB, const SchedParam *param);
@@ -429,7 +463,7 @@ typedef struct TagTaskCB {
PidContainer *pidContainer;
#endif
#ifdef LOSCFG_IPC_CONTAINER
BOOL cloneIpc;
BOOL cloneIpc;
#endif
} LosTaskCB;
@@ -463,6 +497,12 @@ STATIC INLINE BOOL OsTaskIsBlocked(const LosTaskCB *taskCB)
return ((taskCB->taskStatus & (OS_TASK_STATUS_SUSPENDED | OS_TASK_STATUS_PENDING | OS_TASK_STATUS_DELAY)) != 0);
}
STATIC INLINE BOOL OsSchedPolicyIsEDF(const LosTaskCB *taskCB)
{
const SchedEDF *sched = (const SchedEDF *)&taskCB->sp;
return (sched->policy == LOS_SCHED_DEADLINE);
}
STATIC INLINE LosTaskCB *OsCurrTaskGet(VOID)
{
return (LosTaskCB *)ArchCurrTaskGet();
@@ -619,6 +659,20 @@ STATIC INLINE VOID SchedTaskUnfreeze(LosTaskCB *taskCB)
g_taskScheduled &= ~(1U << (cpuid)); \
} while (0);
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
BOOL OsSchedLimitCheckTime(LosTaskCB *task);
#endif
STATIC INLINE LosTaskCB *EDFRunqueueTopTaskGet(EDFRunqueue *rq)
{
LOS_DL_LIST *root = &rq->root;
if (LOS_ListEmpty(root)) {
return NULL;
}
return LOS_DL_LIST_ENTRY(LOS_DL_LIST_FIRST(root), LosTaskCB, pendList);
}
STATIC INLINE LosTaskCB *HPFRunqueueTopTaskGet(HPFRunqueue *rq)
{
LosTaskCB *newTask = NULL;
@@ -634,6 +688,12 @@ STATIC INLINE LosTaskCB *HPFRunqueueTopTaskGet(HPFRunqueue *rq)
while (bitmap) {
UINT32 priority = CLZ(bitmap);
LOS_DL_LIST_FOR_EACH_ENTRY(newTask, &queueList->priQueList[priority], LosTaskCB, pendList) {
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
if (!OsSchedLimitCheckTime(newTask)) {
bitmap &= ~(1U << (OS_PRIORITY_QUEUE_NUM - priority - 1));
continue;
}
#endif
#ifdef LOSCFG_KERNEL_SMP
if (newTask->cpuAffiMask & (1U << cpuid)) {
#endif
@@ -650,9 +710,16 @@ STATIC INLINE LosTaskCB *HPFRunqueueTopTaskGet(HPFRunqueue *rq)
return NULL;
}
VOID EDFProcessDefaultSchedParamGet(SchedParam *param);
VOID EDFSchedPolicyInit(SchedRunqueue *rq);
UINT32 EDFTaskSchedParamInit(LosTaskCB *taskCB, UINT16 policy,
const SchedParam *parentParam,
const LosSchedParam *param);
VOID HPFSchedPolicyInit(SchedRunqueue *rq);
VOID HPFTaskSchedParamInit(LosTaskCB *taskCB, UINT16 policy,
const SchedParam *parentParam, const TSK_INIT_PARAM_S *param);
const SchedParam *parentParam,
const LosSchedParam *param);
VOID HPFProcessDefaultSchedParamGet(SchedParam *param);
VOID IdleTaskSchedParamInit(LosTaskCB *taskCB);
@@ -660,7 +727,8 @@ VOID IdleTaskSchedParamInit(LosTaskCB *taskCB);
INT32 OsSchedParamCompare(const LosTaskCB *task1, const LosTaskCB *task2);
VOID OsSchedPriorityInheritance(LosTaskCB *owner, const SchedParam *param);
UINT32 OsSchedParamInit(LosTaskCB *taskCB, UINT16 policy,
const SchedParam *parentParam, const TSK_INIT_PARAM_S *param);
const SchedParam *parentParam,
const LosSchedParam *param);
VOID OsSchedProcessDefaultSchedParamGet(UINT16 policy, SchedParam *param);
VOID OsSchedResponseTimeReset(UINT64 responseTime);

View File

@@ -57,9 +57,11 @@ typedef struct {
#ifdef LOSCFG_SCHED_TICK_DEBUG
VOID OsSchedDebugRecordData(VOID);
UINT32 OsShellShowTickResponse(VOID);
UINT32 OsShellShowSchedStatistics(VOID);
UINT32 OsSchedDebugInit(VOID);
#endif
UINT32 OsShellShowSchedStatistics(VOID);
UINT32 OsShellShowEdfSchedStatistics(VOID);
VOID EDFDebugRecord(UINTPTR *taskCB, UINT64 oldFinish);
#endif
#ifdef __cplusplus

View File

@@ -101,6 +101,16 @@ extern "C" {
*/
#define OS_NS_PER_TICK (OS_SYS_NS_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND)
#define OS_US_TO_CYCLE(time, freq) ((((time) / OS_SYS_US_PER_SECOND) * (freq)) + \
(((time) % OS_SYS_US_PER_SECOND) * (freq) / OS_SYS_US_PER_SECOND))
#define OS_SYS_US_TO_CYCLE(time) OS_US_TO_CYCLE((time), OS_SYS_CLOCK)
#define OS_CYCLE_TO_US(cycle, freq) ((((cycle) / (freq)) * OS_SYS_US_PER_SECOND) + \
((cycle) % (freq) * OS_SYS_US_PER_SECOND / (freq)))
#define OS_SYS_CYCLE_TO_US(cycle) OS_CYCLE_TO_US((cycle), OS_SYS_CLOCK)
/**
* @ingroup los_sys
* The maximum length of name.

View File

@@ -54,6 +54,7 @@ extern "C" {
/* scheduler lock */
extern SPIN_LOCK_S g_taskSpin;
#define SCHEDULER_HELD() LOS_SpinHeld(&g_taskSpin)
#define SCHEDULER_LOCK(state) LOS_SpinLockSave(&g_taskSpin, &(state))
#define SCHEDULER_UNLOCK(state) LOS_SpinUnlockRestore(&g_taskSpin, state)

View File

@@ -50,9 +50,9 @@ UINT32 OsCopyTimeContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *par
UINT32 OsUnshareTimeContainer(UINTPTR flags, LosProcessCB *curr, struct Container *newContainer);
VOID UnshareDeInitTimeContainer(struct Container *container);
UINT32 OsSetNsTimeContainer(UINT32 flags, struct Container *container, struct Container *newContainer);
VOID OsTimeContainerDestroy(LosProcessCB *curr);
VOID OsTimeContainerDestroy(struct Container *container);
UINT32 OsGetTimeContainerID(TimeContainer *timeContainer);
@@ -62,6 +62,8 @@ UINT32 OsGetTimeContainerMonotonic(LosProcessCB *processCB, struct timespec64 *o
UINT32 OsSetTimeContainerMonotonic(LosProcessCB *processCB, struct timespec64 *offsets);
UINT32 OsGetTimeContainerCount(VOID);
#define CLOCK_MONOTONIC_TIME_BASE (OsGetCurrTimeContainer()->monotonic)
#endif

View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_USER_CONTAINER_PRI_H
#define _LOS_USER_CONTAINER_PRI_H
#include "los_atomic.h"
#include "los_credentials_pri.h"
#define UID_GID_MAP_MAX_EXTENTS 5
#ifdef LOSCFG_USER_CONTAINER
struct ProcFile;
typedef struct UidGidExtent {
UINT32 first;
UINT32 lowerFirst;
UINT32 count;
} UidGidExtent;
typedef struct UidGidMap {
UINT32 extentCount;
union {
UidGidExtent extent[UID_GID_MAP_MAX_EXTENTS];
};
} UidGidMap;
typedef struct UserContainer {
Atomic rc;
INT32 level;
UINT32 owner;
UINT32 group;
struct UserContainer *parent;
UidGidMap uidMap;
UidGidMap gidMap;
UINT32 containerID;
} UserContainer;
UINT32 OsCreateUserContainer(Credentials *newCredentials, UserContainer *parentUserContainer);
VOID FreeUserContainer(UserContainer *userContainer);
UINT32 OsFromKuidMunged(UserContainer *userContainer, UINT32 kuid);
UINT32 OsFromKgidMunged(UserContainer *userContainer, UINT32 kgid);
UINT32 OsMakeKuid(UserContainer *userContainer, UINT32 uid);
UINT32 OsMakeKgid(UserContainer *userContainer, UINT32 gid);
INT32 OsUserContainerMapWrite(struct ProcFile *fp, CHAR *buf, size_t count,
INT32 capSetid, UidGidMap *map, UidGidMap *parentMap);
UINT32 OsGetUserContainerCount(VOID);
#endif
#endif

View File

@@ -52,10 +52,14 @@ UINT32 OsCopyUtsContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
UINT32 OsUnshareUtsContainer(UINTPTR flags, LosProcessCB *curr, struct Container *newContainer);
UINT32 OsSetNsUtsContainer(UINT32 flags, struct Container *container, struct Container *newContainer);
VOID OsUtsContainerDestroy(struct Container *container);
struct utsname *OsGetCurrUtsName(VOID);
UINT32 OsGetUtsContainerID(UtsContainer *utsContainer);
UINT32 OsGetUtsContainerCount(VOID);
#endif
#endif /* _LOS_UTS_CONTAINER_PRI_H */

View File

@@ -63,6 +63,7 @@ VOID OsShmFork(LosVmSpace *space, LosVmMapRegion *oldRegion, LosVmMapRegion *new
VOID OsShmRegionFree(LosVmSpace *space, LosVmMapRegion *region);
BOOL OsIsShmRegion(LosVmMapRegion *region);
struct shmIDSource *OsShmCBInit(LosMux *sysvShmMux, struct shminfo *shmInfo, UINT32 *shmUsedPageCount);
VOID OsShmCBDestroy(struct shmIDSource *shmSegs, struct shminfo *shmInfo, LosMux *sysvShmMux);
#ifdef __cplusplus
#if __cplusplus
}

View File

@@ -53,6 +53,9 @@
#include "los_sched_pri.h"
#include "los_swtmr_pri.h"
#include "los_info_pri.h"
#ifdef LOSCFG_SCHED_DEBUG
#include "los_statistics_pri.h"
#endif
#define OS_PROCESS_MEM_INFO 0x2U
#undef SHOW
@@ -93,6 +96,8 @@ STATIC UINT8 *ConvertSchedPolicyToString(UINT16 policy)
return (UINT8 *)"RR";
} else if (policy == LOS_SCHED_FIFO) {
return (UINT8 *)"FIFO";
} else if (policy == LOS_SCHED_DEADLINE) {
return (UINT8 *)"EDF";
} else if (policy == LOS_SCHED_IDLE) {
return (UINT8 *)"IDLE";
}
@@ -200,12 +205,10 @@ STATIC UINT8 *ConvertTaskStatusToString(UINT16 taskStatus)
return (UINT8 *)"Suspended";
} else if (taskStatus & OS_TASK_STATUS_DELAY) {
return (UINT8 *)"Delay";
} else if (taskStatus & OS_TASK_STATUS_PEND_TIME) {
return (UINT8 *)"PendTime";
} else if (taskStatus & OS_TASK_STATUS_PENDING) {
if (taskStatus & OS_TASK_STATUS_PEND_TIME) {
return (UINT8 *)"PendTime";
} else {
return (UINT8 *)"Pending";
}
return (UINT8 *)"Pending";
} else if (taskStatus & OS_TASK_STATUS_EXIT) {
return (UINT8 *)"Exit";
}
@@ -413,11 +416,20 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdDumpTask(INT32 argc, const CHAR **argv)
}
goto TASK_HELP;
#endif
#ifdef LOSCFG_SCHED_HPF_DEBUG
} else if (strcmp("-t", argv[0]) == 0) {
if (!OsShellShowSchedStatistics()) {
return LOS_OK;
}
goto TASK_HELP;
#endif
#ifdef LOSCFG_SCHED_EDF_DEBUG
} else if (strcmp("-e", argv[0]) == 0) {
if (!OsShellShowEdfSchedStatistics()) {
return LOS_OK;
}
goto TASK_HELP;
#endif
#endif
} else {
goto TASK_HELP;

View File

@@ -0,0 +1,403 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_sched_pri.h"
#include "los_task_pri.h"
#include "los_process_pri.h"
#include "los_hook.h"
#include "los_tick_pri.h"
#include "los_sys_pri.h"
STATIC EDFRunqueue g_schedEDF;
STATIC VOID EDFDequeue(SchedRunqueue *rq, LosTaskCB *taskCB);
STATIC VOID EDFEnqueue(SchedRunqueue *rq, LosTaskCB *taskCB);
STATIC UINT64 EDFWaitTimeGet(LosTaskCB *taskCB);
STATIC UINT32 EDFWait(LosTaskCB *runTask, LOS_DL_LIST *list, UINT32 ticks);
STATIC VOID EDFWake(LosTaskCB *resumedTask);
STATIC BOOL EDFSchedParamModify(LosTaskCB *taskCB, const SchedParam *param);
STATIC UINT32 EDFSchedParamGet(const LosTaskCB *taskCB, SchedParam *param);
STATIC UINT32 EDFDelay(LosTaskCB *runTask, UINT64 waitTime);
STATIC VOID EDFYield(LosTaskCB *runTask);
STATIC VOID EDFExit(LosTaskCB *taskCB);
STATIC UINT32 EDFSuspend(LosTaskCB *taskCB);
STATIC UINT32 EDFResume(LosTaskCB *taskCB, BOOL *needSched);
STATIC UINT64 EDFTimeSliceGet(const LosTaskCB *taskCB);
STATIC VOID EDFTimeSliceUpdate(SchedRunqueue *rq, LosTaskCB *taskCB, UINT64 currTime);
STATIC INT32 EDFParamCompare(const SchedPolicy *sp1, const SchedPolicy *sp2);
STATIC VOID EDFPriorityInheritance(LosTaskCB *owner, const SchedParam *param);
STATIC VOID EDFPriorityRestore(LosTaskCB *owner, const LOS_DL_LIST *list, const SchedParam *param);
const STATIC SchedOps g_deadlineOps = {
.dequeue = EDFDequeue,
.enqueue = EDFEnqueue,
.waitTimeGet = EDFWaitTimeGet,
.wait = EDFWait,
.wake = EDFWake,
.schedParamModify = EDFSchedParamModify,
.schedParamGet = EDFSchedParamGet,
.delay = EDFDelay,
.yield = EDFYield,
.start = EDFDequeue,
.exit = EDFExit,
.suspend = EDFSuspend,
.resume = EDFResume,
.deadlineGet = EDFTimeSliceGet,
.timeSliceUpdate = EDFTimeSliceUpdate,
.schedParamCompare = EDFParamCompare,
.priorityInheritance = EDFPriorityInheritance,
.priorityRestore = EDFPriorityRestore,
};
STATIC VOID EDFTimeSliceUpdate(SchedRunqueue *rq, LosTaskCB *taskCB, UINT64 currTime)
{
SchedEDF *sched = (SchedEDF *)&taskCB->sp;
LOS_ASSERT(currTime >= taskCB->startTime);
if (taskCB->timeSlice <= 0) {
taskCB->irqUsedTime = 0;
return;
}
INT32 incTime = (currTime - taskCB->startTime - taskCB->irqUsedTime);
LOS_ASSERT(incTime >= 0);
#ifdef LOSCFG_SCHED_EDF_DEBUG
taskCB->schedStat.timeSliceRealTime += incTime;
taskCB->schedStat.allRuntime += (currTime - taskCB->startTime);
#endif
taskCB->timeSlice -= incTime;
taskCB->irqUsedTime = 0;
taskCB->startTime = currTime;
if ((sched->finishTime > currTime) && (taskCB->timeSlice > 0)) {
return;
}
rq->schedFlag |= INT_PEND_RESCH;
if (sched->finishTime <= currTime) {
#ifdef LOSCFG_SCHED_EDF_DEBUG
EDFDebugRecord((UINTPTR *)taskCB, sched->finishTime);
#endif
taskCB->timeSlice = 0;
PrintExcInfo("EDF task %u is timeout, runTime: %d us period: %llu us\n", taskCB->taskID,
(INT32)OS_SYS_CYCLE_TO_US((UINT64)sched->runTime), OS_SYS_CYCLE_TO_US(sched->period));
}
}
STATIC UINT64 EDFTimeSliceGet(const LosTaskCB *taskCB)
{
SchedEDF *sched = (SchedEDF *)&taskCB->sp;
UINT64 endTime = taskCB->startTime + taskCB->timeSlice;
return (endTime > sched->finishTime) ? sched->finishTime : endTime;
}
STATIC VOID DeadlineQueueInsert(EDFRunqueue *rq, LosTaskCB *taskCB)
{
LOS_DL_LIST *root = &rq->root;
if (LOS_ListEmpty(root)) {
LOS_ListTailInsert(root, &taskCB->pendList);
return;
}
LOS_DL_LIST *list = root->pstNext;
do {
LosTaskCB *readyTask = LOS_DL_LIST_ENTRY(list, LosTaskCB, pendList);
if (EDFParamCompare(&readyTask->sp, &taskCB->sp) > 0) {
LOS_ListHeadInsert(list, &taskCB->pendList);
return;
}
list = list->pstNext;
} while (list != root);
LOS_ListHeadInsert(list, &taskCB->pendList);
}
STATIC VOID EDFEnqueue(SchedRunqueue *rq, LosTaskCB *taskCB)
{
LOS_ASSERT(!(taskCB->taskStatus & OS_TASK_STATUS_READY));
EDFRunqueue *erq = rq->edfRunqueue;
SchedEDF *sched = (SchedEDF *)&taskCB->sp;
if (taskCB->timeSlice <= 0) {
#ifdef LOSCFG_SCHED_EDF_DEBUG
UINT64 oldFinish = sched->finishTime;
#endif
UINT64 currTime = OsGetCurrSchedTimeCycle();
if (sched->flags == EDF_INIT) {
sched->finishTime = currTime;
} else if (sched->flags != EDF_NEXT_PERIOD) {
/* The start time of the next period */
sched->finishTime = (sched->finishTime - sched->deadline) + sched->period;
}
/* Calculate the start time of the next period */
while (1) {
/* The deadline of the next period */
UINT64 finishTime = sched->finishTime + sched->deadline;
if ((finishTime <= currTime) || ((sched->finishTime + sched->runTime) > finishTime)) {
/* This period cannot meet the minimum running time, so it is migrated to the next period */
sched->finishTime += sched->period;
continue;
}
break;
}
if (sched->finishTime > currTime) {
/* Wait for the next period to start */
LOS_ListTailInsert(&erq->waitList, &taskCB->pendList);
taskCB->waitTime = OS_SCHED_MAX_RESPONSE_TIME;
if (!OsTaskIsRunning(taskCB)) {
OsSchedTimeoutQueueAdd(taskCB, sched->finishTime);
}
#ifdef LOSCFG_SCHED_EDF_DEBUG
if (oldFinish != sched->finishTime) {
EDFDebugRecord((UINTPTR *)taskCB, oldFinish);
taskCB->schedStat.allRuntime = 0;
taskCB->schedStat.timeSliceRealTime = 0;
taskCB->schedStat.pendTime = 0;
}
#endif
taskCB->taskStatus |= OS_TASK_STATUS_PEND_TIME;
sched->flags = EDF_NEXT_PERIOD;
return;
}
sched->finishTime += sched->deadline;
taskCB->timeSlice = sched->runTime;
sched->flags = EDF_UNUSED;
}
DeadlineQueueInsert(erq, taskCB);
taskCB->taskStatus &= ~(OS_TASK_STATUS_BLOCKED | OS_TASK_STATUS_TIMEOUT);
taskCB->taskStatus |= OS_TASK_STATUS_READY;
}
STATIC VOID EDFDequeue(SchedRunqueue *rq, LosTaskCB *taskCB)
{
(VOID)rq;
LOS_ListDelete(&taskCB->pendList);
taskCB->taskStatus &= ~OS_TASK_STATUS_READY;
}
STATIC VOID EDFExit(LosTaskCB *taskCB)
{
if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
EDFDequeue(OsSchedRunqueue(), taskCB);
} else if (taskCB->taskStatus & OS_TASK_STATUS_PENDING) {
LOS_ListDelete(&taskCB->pendList);
taskCB->taskStatus &= ~OS_TASK_STATUS_PENDING;
}
if (taskCB->taskStatus & (OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND_TIME)) {
OsSchedTimeoutQueueDelete(taskCB);
taskCB->taskStatus &= ~(OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND_TIME);
}
}
STATIC VOID EDFYield(LosTaskCB *runTask)
{
SchedRunqueue *rq = OsSchedRunqueue();
runTask->timeSlice = 0;
runTask->startTime = OsGetCurrSchedTimeCycle();
EDFEnqueue(rq, runTask);
OsSchedResched();
}
STATIC UINT32 EDFDelay(LosTaskCB *runTask, UINT64 waitTime)
{
runTask->taskStatus |= OS_TASK_STATUS_DELAY;
runTask->waitTime = waitTime;
OsSchedResched();
return LOS_OK;
}
STATIC UINT64 EDFWaitTimeGet(LosTaskCB *taskCB)
{
const SchedEDF *sched = (const SchedEDF *)&taskCB->sp;
if (sched->flags != EDF_WAIT_FOREVER) {
taskCB->waitTime += taskCB->startTime;
}
return (taskCB->waitTime >= sched->finishTime) ? sched->finishTime : taskCB->waitTime;
}
STATIC UINT32 EDFWait(LosTaskCB *runTask, LOS_DL_LIST *list, UINT32 ticks)
{
SchedEDF *sched = (SchedEDF *)&runTask->sp;
runTask->taskStatus |= (OS_TASK_STATUS_PENDING | OS_TASK_STATUS_PEND_TIME);
LOS_ListTailInsert(list, &runTask->pendList);
if (ticks != LOS_WAIT_FOREVER) {
runTask->waitTime = OS_SCHED_TICK_TO_CYCLE(ticks);
} else {
sched->flags = EDF_WAIT_FOREVER;
runTask->waitTime = OS_SCHED_MAX_RESPONSE_TIME;
}
if (OsPreemptableInSched()) {
OsSchedResched();
if (runTask->taskStatus & OS_TASK_STATUS_TIMEOUT) {
runTask->taskStatus &= ~OS_TASK_STATUS_TIMEOUT;
return LOS_ERRNO_TSK_TIMEOUT;
}
}
return LOS_OK;
}
STATIC VOID EDFWake(LosTaskCB *resumedTask)
{
LOS_ListDelete(&resumedTask->pendList);
resumedTask->taskStatus &= ~OS_TASK_STATUS_PENDING;
if (resumedTask->taskStatus & OS_TASK_STATUS_PEND_TIME) {
OsSchedTimeoutQueueDelete(resumedTask);
resumedTask->taskStatus &= ~OS_TASK_STATUS_PEND_TIME;
}
if (!(resumedTask->taskStatus & OS_TASK_STATUS_SUSPENDED)) {
#ifdef LOSCFG_SCHED_EDF_DEBUG
resumedTask->schedStat.pendTime += OsGetCurrSchedTimeCycle() - resumedTask->startTime;
resumedTask->schedStat.pendCount++;
#endif
EDFEnqueue(OsSchedRunqueue(), resumedTask);
}
}
STATIC BOOL EDFSchedParamModify(LosTaskCB *taskCB, const SchedParam *param)
{
SchedRunqueue *rq = OsSchedRunqueue();
SchedEDF *sched = (SchedEDF *)&taskCB->sp;
taskCB->timeSlice = 0;
sched->runTime = (INT32)OS_SYS_US_TO_CYCLE(param->runTimeUs);
sched->period = OS_SYS_US_TO_CYCLE(param->periodUs);
if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
EDFDequeue(rq, taskCB);
sched->deadline = OS_SYS_US_TO_CYCLE(param->deadlineUs);
EDFEnqueue(rq, taskCB);
return TRUE;
}
sched->deadline = OS_SYS_US_TO_CYCLE(param->deadlineUs);
if (taskCB->taskStatus & OS_TASK_STATUS_INIT) {
EDFEnqueue(rq, taskCB);
return TRUE;
}
if (taskCB->taskStatus & OS_TASK_STATUS_RUNNING) {
return TRUE;
}
return FALSE;
}
STATIC UINT32 EDFSchedParamGet(const LosTaskCB *taskCB, SchedParam *param)
{
SchedEDF *sched = (SchedEDF *)&taskCB->sp;
param->policy = sched->policy;
param->runTimeUs = (INT32)OS_SYS_CYCLE_TO_US((UINT64)sched->runTime);
param->deadlineUs = OS_SYS_CYCLE_TO_US(sched->deadline);
param->periodUs = OS_SYS_CYCLE_TO_US(sched->period);
return LOS_OK;
}
STATIC UINT32 EDFSuspend(LosTaskCB *taskCB)
{
return LOS_EOPNOTSUPP;
}
STATIC UINT32 EDFResume(LosTaskCB *taskCB, BOOL *needSched)
{
return LOS_EOPNOTSUPP;
}
STATIC INT32 EDFParamCompare(const SchedPolicy *sp1, const SchedPolicy *sp2)
{
const SchedEDF *param1 = (const SchedEDF *)sp1;
const SchedEDF *param2 = (const SchedEDF *)sp2;
return (INT32)(param1->finishTime - param2->finishTime);
}
STATIC VOID EDFPriorityInheritance(LosTaskCB *owner, const SchedParam *param)
{
(VOID)owner;
(VOID)param;
}
STATIC VOID EDFPriorityRestore(LosTaskCB *owner, const LOS_DL_LIST *list, const SchedParam *param)
{
(VOID)owner;
(VOID)list;
(VOID)param;
}
UINT32 EDFTaskSchedParamInit(LosTaskCB *taskCB, UINT16 policy,
const SchedParam *parentParam,
const LosSchedParam *param)
{
(VOID)parentParam;
SchedEDF *sched = (SchedEDF *)&taskCB->sp;
sched->flags = EDF_INIT;
sched->policy = policy;
sched->runTime = (INT32)OS_SYS_US_TO_CYCLE((UINT64)param->runTimeUs);
sched->deadline = OS_SYS_US_TO_CYCLE(param->deadlineUs);
sched->period = OS_SYS_US_TO_CYCLE(param->periodUs);
sched->finishTime = 0;
taskCB->timeSlice = 0;
taskCB->ops = &g_deadlineOps;
return LOS_OK;
}
VOID EDFProcessDefaultSchedParamGet(SchedParam *param)
{
param->runTimeUs = OS_SCHED_EDF_MIN_RUNTIME;
param->deadlineUs = OS_SCHED_EDF_MAX_DEADLINE;
param->periodUs = param->deadlineUs;
}
VOID EDFSchedPolicyInit(SchedRunqueue *rq)
{
if (ArchCurrCpuid() > 0) {
rq->edfRunqueue = &g_schedEDF;
return;
}
EDFRunqueue *erq = &g_schedEDF;
erq->period = OS_SCHED_MAX_RESPONSE_TIME;
LOS_ListInit(&erq->root);
LOS_ListInit(&erq->waitList);
rq->edfRunqueue = erq;
}

View File

@@ -48,6 +48,7 @@ STATIC VOID IdlePriorityRestore(LosTaskCB *owner, const LOS_DL_LIST *list, const
const STATIC SchedOps g_idleOps = {
.dequeue = IdleDequeue,
.enqueue = IdleEnqueue,
.waitTimeGet = NULL,
.wait = IdleWait,
.wake = IdleWake,
.schedParamModify = NULL,

View File

@@ -47,6 +47,7 @@ STATIC HPFRunqueue g_schedHPF;
STATIC VOID HPFDequeue(SchedRunqueue *rq, LosTaskCB *taskCB);
STATIC VOID HPFEnqueue(SchedRunqueue *rq, LosTaskCB *taskCB);
STATIC UINT64 HPFWaitTimeGet(LosTaskCB *taskCB);
STATIC UINT32 HPFWait(LosTaskCB *runTask, LOS_DL_LIST *list, UINT32 ticks);
STATIC VOID HPFWake(LosTaskCB *resumedTask);
STATIC BOOL HPFSchedParamModify(LosTaskCB *taskCB, const SchedParam *param);
@@ -66,6 +67,7 @@ STATIC VOID HPFPriorityRestore(LosTaskCB *owner, const LOS_DL_LIST *list, const
const STATIC SchedOps g_priorityOps = {
.dequeue = HPFDequeue,
.enqueue = HPFEnqueue,
.waitTimeGet = HPFWaitTimeGet,
.wait = HPFWait,
.wake = HPFWake,
.schedParamModify = HPFSchedParamModify,
@@ -94,17 +96,20 @@ STATIC VOID HPFTimeSliceUpdate(SchedRunqueue *rq, LosTaskCB *taskCB, UINT64 curr
if (sched->policy == LOS_SCHED_RR) {
taskCB->timeSlice -= incTime;
#ifdef LOSCFG_SCHED_DEBUG
#ifdef LOSCFG_SCHED_HPF_DEBUG
taskCB->schedStat.timeSliceRealTime += incTime;
#endif
}
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
OsSchedLimitUpdateRuntime(taskCB, currTime, incTime);
#endif
taskCB->irqUsedTime = 0;
taskCB->startTime = currTime;
if (taskCB->timeSlice <= OS_TIME_SLICE_MIN) {
rq->schedFlag |= INT_PEND_RESCH;
}
#ifdef LOSCFG_SCHED_DEBUG
#ifdef LOSCFG_SCHED_HPF_DEBUG
taskCB->schedStat.allRuntime += incTime;
#endif
}
@@ -212,7 +217,7 @@ STATIC INLINE VOID PriQueInsert(HPFRunqueue *rq, LosTaskCB *taskCB)
sched->initTimeSlice = TimeSliceCalculate(rq, sched->basePrio, sched->priority);
taskCB->timeSlice = sched->initTimeSlice;
PriQueTailInsert(rq, sched->basePrio, &taskCB->pendList, sched->priority);
#ifdef LOSCFG_SCHED_DEBUG
#ifdef LOSCFG_SCHED_HPF_DEBUG
taskCB->schedStat.timeSliceTime = taskCB->schedStat.timeSliceRealTime;
taskCB->schedStat.timeSliceCount++;
#endif
@@ -241,7 +246,7 @@ STATIC INLINE VOID PriQueInsert(HPFRunqueue *rq, LosTaskCB *taskCB)
STATIC VOID HPFEnqueue(SchedRunqueue *rq, LosTaskCB *taskCB)
{
#ifdef LOSCFG_SCHED_DEBUG
#ifdef LOSCFG_SCHED_HPF_DEBUG
if (!(taskCB->taskStatus & OS_TASK_STATUS_RUNNING)) {
taskCB->startTime = OsGetCurrSchedTimeCycle();
}
@@ -298,6 +303,12 @@ STATIC UINT32 HPFDelay(LosTaskCB *runTask, UINT64 waitTime)
return LOS_OK;
}
STATIC UINT64 HPFWaitTimeGet(LosTaskCB *taskCB)
{
taskCB->waitTime += taskCB->startTime;
return taskCB->waitTime;
}
STATIC UINT32 HPFWait(LosTaskCB *runTask, LOS_DL_LIST *list, UINT32 ticks)
{
runTask->taskStatus |= OS_TASK_STATUS_PENDING;
@@ -330,7 +341,7 @@ STATIC VOID HPFWake(LosTaskCB *resumedTask)
}
if (!(resumedTask->taskStatus & OS_TASK_STATUS_SUSPENDED)) {
#ifdef LOSCFG_SCHED_DEBUG
#ifdef LOSCFG_SCHED_HPF_DEBUG
resumedTask->schedStat.pendTime += OsGetCurrSchedTimeCycle() - resumedTask->startTime;
resumedTask->schedStat.pendCount++;
#endif
@@ -505,13 +516,13 @@ STATIC VOID HPFPriorityRestore(LosTaskCB *owner, const LOS_DL_LIST *list, const
VOID HPFTaskSchedParamInit(LosTaskCB *taskCB, UINT16 policy,
const SchedParam *parentParam,
const TSK_INIT_PARAM_S *param)
const LosSchedParam *param)
{
SchedHPF *sched = (SchedHPF *)&taskCB->sp;
sched->policy = policy;
if (param != NULL) {
sched->priority = param->usTaskPrio;
sched->priority = param->priority;
} else {
sched->priority = parentParam->priority;
}

View File

@@ -102,15 +102,26 @@ VOID OsSchedExpireTimeUpdate(VOID)
STATIC INLINE VOID SchedTimeoutTaskWake(SchedRunqueue *rq, UINT64 currTime, LosTaskCB *taskCB, BOOL *needSched)
{
#ifndef LOSCFG_SCHED_DEBUG
(VOID)currTime;
#endif
LOS_SpinLock(&g_taskSpin);
if (OsSchedPolicyIsEDF(taskCB)) {
SchedEDF *sched = (SchedEDF *)&taskCB->sp;
if (sched->finishTime <= currTime) {
if (taskCB->timeSlice >= 0) {
PrintExcInfo("EDF task: %u name: %s is timeout, timeout for %llu us.\n",
taskCB->taskID, taskCB->taskName, OS_SYS_CYCLE_TO_US(currTime - sched->finishTime));
}
taskCB->timeSlice = 0;
}
if (sched->flags == EDF_WAIT_FOREVER) {
taskCB->taskStatus &= ~OS_TASK_STATUS_PEND_TIME;
sched->flags = EDF_UNUSED;
}
}
UINT16 tempStatus = taskCB->taskStatus;
if (tempStatus & (OS_TASK_STATUS_PENDING | OS_TASK_STATUS_DELAY)) {
if (tempStatus & (OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_DELAY)) {
taskCB->taskStatus &= ~(OS_TASK_STATUS_PENDING | OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_DELAY);
if (tempStatus & OS_TASK_STATUS_PENDING) {
if (tempStatus & OS_TASK_STATUS_PEND_TIME) {
taskCB->taskStatus |= OS_TASK_STATUS_TIMEOUT;
LOS_ListDelete(&taskCB->pendList);
taskCB->taskMux = NULL;
@@ -118,7 +129,7 @@ STATIC INLINE VOID SchedTimeoutTaskWake(SchedRunqueue *rq, UINT64 currTime, LosT
}
if (!(tempStatus & OS_TASK_STATUS_SUSPENDED)) {
#ifdef LOSCFG_SCHED_DEBUG
#ifdef LOSCFG_SCHED_HPF_DEBUG
taskCB->schedStat.pendTime += currTime - taskCB->startTime;
taskCB->schedStat.pendCount++;
#endif
@@ -212,8 +223,10 @@ VOID OsSchedRunqueueIdleInit(LosTaskCB *idleTask)
UINT32 OsSchedInit(VOID)
{
for (UINT16 cpuId = 0; cpuId < LOSCFG_KERNEL_CORE_NUM; cpuId++) {
HPFSchedPolicyInit(OsSchedRunqueueByID(cpuId));
for (UINT16 cpuid = 0; cpuid < LOSCFG_KERNEL_CORE_NUM; cpuid++) {
SchedRunqueue *rq = OsSchedRunqueueByID(cpuid);
EDFSchedPolicyInit(rq);
HPFSchedPolicyInit(rq);
}
#ifdef LOSCFG_SCHED_TICK_DEBUG
@@ -247,13 +260,15 @@ INT32 OsSchedParamCompare(const LosTaskCB *task1, const LosTaskCB *task2)
return 0;
}
UINT32 OsSchedParamInit(LosTaskCB *taskCB, UINT16 policy, const SchedParam *parentParam, const TSK_INIT_PARAM_S *param)
UINT32 OsSchedParamInit(LosTaskCB *taskCB, UINT16 policy, const SchedParam *parentParam, const LosSchedParam *param)
{
switch (policy) {
case LOS_SCHED_FIFO:
case LOS_SCHED_RR:
HPFTaskSchedParamInit(taskCB, policy, parentParam, param);
break;
case LOS_SCHED_DEADLINE:
return EDFTaskSchedParamInit(taskCB, policy, parentParam, param);
case LOS_SCHED_IDLE:
IdleTaskSchedParamInit(taskCB);
break;
@@ -271,6 +286,9 @@ VOID OsSchedProcessDefaultSchedParamGet(UINT16 policy, SchedParam *param)
case LOS_SCHED_RR:
HPFProcessDefaultSchedParamGet(param);
break;
case LOS_SCHED_DEADLINE:
EDFProcessDefaultSchedParamGet(param);
break;
case LOS_SCHED_IDLE:
default:
PRINT_ERR("Invalid process-level scheduling policy, %u\n", policy);
@@ -281,12 +299,19 @@ VOID OsSchedProcessDefaultSchedParamGet(UINT16 policy, SchedParam *param)
STATIC LosTaskCB *TopTaskGet(SchedRunqueue *rq)
{
LosTaskCB *newTask = HPFRunqueueTopTaskGet(rq->hpfRunqueue);
if (newTask == NULL) {
newTask = rq->idleTask;
LosTaskCB *newTask = EDFRunqueueTopTaskGet(rq->edfRunqueue);
if (newTask != NULL) {
goto FIND;
}
newTask = HPFRunqueueTopTaskGet(rq->hpfRunqueue);
if (newTask != NULL) {
goto FIND;
}
newTask = rq->idleTask;
FIND:
newTask->ops->start(rq, newTask);
return newTask;
}
@@ -387,7 +412,7 @@ STATIC VOID SchedTaskSwitch(SchedRunqueue *rq, LosTaskCB *runTask, LosTaskCB *ne
OsCpupCycleEndStart(runTask, newTask);
#endif
#ifdef LOSCFG_SCHED_DEBUG
#ifdef LOSCFG_SCHED_HPF_DEBUG
UINT64 waitStartTime = newTask->startTime;
#endif
if (runTask->taskStatus & OS_TASK_STATUS_READY) {
@@ -400,14 +425,14 @@ STATIC VOID SchedTaskSwitch(SchedRunqueue *rq, LosTaskCB *runTask, LosTaskCB *ne
runTask->ops->timeSliceUpdate(rq, runTask, newTask->startTime);
if (runTask->taskStatus & (OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_DELAY)) {
OsSchedTimeoutQueueAdd(runTask, runTask->startTime + runTask->waitTime);
OsSchedTimeoutQueueAdd(runTask, runTask->ops->waitTimeGet(runTask));
}
}
UINT64 deadline = newTask->ops->deadlineGet(newTask);
SchedNextExpireTimeSet(newTask->taskID, deadline, runTask->taskID);
#ifdef LOSCFG_SCHED_DEBUG
#ifdef LOSCFG_SCHED_HPF_DEBUG
newTask->schedStat.waitSchedTime += newTask->startTime - waitStartTime;
newTask->schedStat.waitSchedCount++;
runTask->schedStat.runTime = runTask->schedStat.allRuntime;

View File

@@ -99,6 +99,7 @@ UINT32 OsShellShowTickResponse(VOID)
}
#endif
#ifdef LOSCFG_SCHED_HPF_DEBUG
STATIC VOID SchedDataGet(const LosTaskCB *taskCB, UINT64 *runTime, UINT64 *timeSlice,
UINT64 *pendTime, UINT64 *schedWait)
{
@@ -128,6 +129,7 @@ UINT32 OsShellShowSchedStatistics(VOID)
UINT32 taskLinkNum[LOSCFG_KERNEL_CORE_NUM];
UINT32 intSave;
LosTaskCB task;
SchedEDF *sched = NULL;
SCHEDULER_LOCK(intSave);
for (UINT16 cpu = 0; cpu < LOSCFG_KERNEL_CORE_NUM; cpu++) {
@@ -150,6 +152,12 @@ UINT32 OsShellShowSchedStatistics(VOID)
continue;
}
sched = (SchedEDF *)&taskCB->sp;
if (sched->policy == LOS_SCHED_DEADLINE) {
SCHEDULER_UNLOCK(intSave);
continue;
}
(VOID)memcpy_s(&task, sizeof(LosTaskCB), taskCB, sizeof(LosTaskCB));
SCHEDULER_UNLOCK(intSave);
@@ -170,3 +178,168 @@ UINT32 OsShellShowSchedStatistics(VOID)
}
#endif
#ifdef LOSCFG_SCHED_EDF_DEBUG
#define EDF_DEBUG_NODE 20
typedef struct {
UINT32 tid;
INT32 runTimeUs;
UINT64 deadlineUs;
UINT64 periodUs;
UINT64 startTime;
UINT64 finishTime;
UINT64 nextfinishTime;
UINT64 timeSliceUnused;
UINT64 timeSliceRealTime;
UINT64 allRuntime;
UINT64 pendTime;
} EDFDebug;
STATIC EDFDebug g_edfNode[EDF_DEBUG_NODE];
STATIC INT32 g_edfNodePointer = 0;
VOID EDFDebugRecord(UINTPTR *task, UINT64 oldFinish)
{
LosTaskCB *taskCB = (LosTaskCB *)task;
SchedEDF *sched = (SchedEDF *)&taskCB->sp;
SchedParam param;
// when print edf info, will stop record
if (g_edfNodePointer == (EDF_DEBUG_NODE + 1)) {
return;
}
taskCB->ops->schedParamGet(taskCB, &param);
g_edfNode[g_edfNodePointer].tid = taskCB->taskID;
g_edfNode[g_edfNodePointer].runTimeUs =param.runTimeUs;
g_edfNode[g_edfNodePointer].deadlineUs =param.deadlineUs;
g_edfNode[g_edfNodePointer].periodUs =param.periodUs;
g_edfNode[g_edfNodePointer].startTime = taskCB->startTime;
if (taskCB->timeSlice <= 0) {
taskCB->irqUsedTime = 0;
g_edfNode[g_edfNodePointer].timeSliceUnused = 0;
} else {
g_edfNode[g_edfNodePointer].timeSliceUnused = taskCB->timeSlice;
}
g_edfNode[g_edfNodePointer].finishTime = oldFinish;
g_edfNode[g_edfNodePointer].nextfinishTime = sched->finishTime;
g_edfNode[g_edfNodePointer].timeSliceRealTime = taskCB->schedStat.timeSliceRealTime;
g_edfNode[g_edfNodePointer].allRuntime = taskCB->schedStat.allRuntime;
g_edfNode[g_edfNodePointer].pendTime = taskCB->schedStat.pendTime;
g_edfNodePointer++;
if (g_edfNodePointer == EDF_DEBUG_NODE) {
g_edfNodePointer = 0;
}
}
STATIC VOID EDFInfoPrint(int idx)
{
INT32 runTimeUs;
UINT64 deadlineUs;
UINT64 periodUs;
UINT64 startTime;
UINT64 timeSlice;
UINT64 finishTime;
UINT64 nextfinishTime;
UINT64 pendTime;
UINT64 allRuntime;
UINT64 timeSliceRealTime;
CHAR *status = NULL;
startTime = OS_SYS_CYCLE_TO_US(g_edfNode[idx].startTime);
timeSlice = OS_SYS_CYCLE_TO_US(g_edfNode[idx].timeSliceUnused);
finishTime = OS_SYS_CYCLE_TO_US(g_edfNode[idx].finishTime);
nextfinishTime = OS_SYS_CYCLE_TO_US(g_edfNode[idx].nextfinishTime);
pendTime = OS_SYS_CYCLE_TO_US(g_edfNode[idx].pendTime);
allRuntime = OS_SYS_CYCLE_TO_US(g_edfNode[idx].allRuntime);
timeSliceRealTime = OS_SYS_CYCLE_TO_US(g_edfNode[idx].timeSliceRealTime);
runTimeUs = g_edfNode[idx].runTimeUs;
deadlineUs = g_edfNode[idx].deadlineUs;
periodUs = g_edfNode[idx].periodUs;
if (timeSlice > 0) {
status = "TIMEOUT";
} else if (nextfinishTime == finishTime) {
status = "NEXT PERIOD";
} else {
status = "WAIT RUN";
}
PRINTK("%4u%9d%9llu%9llu%12llu%12llu%12llu%9llu%9llu%9llu%9llu %-12s\n",
g_edfNode[idx].tid, runTimeUs, deadlineUs, periodUs,
startTime, finishTime, nextfinishTime, allRuntime, timeSliceRealTime,
timeSlice, pendTime, status);
}
VOID OsEDFDebugPrint(VOID)
{
INT32 max;
UINT32 intSave;
INT32 i;
SCHEDULER_LOCK(intSave);
max = g_edfNodePointer;
g_edfNodePointer = EDF_DEBUG_NODE + 1;
SCHEDULER_UNLOCK(intSave);
PRINTK("\r\nlast %d sched is: (in microsecond)\r\n", EDF_DEBUG_NODE);
PRINTK(" TID RunTime Deadline Period StartTime "
"CurPeriod NextPeriod AllRun RealRun TimeOut WaitTime Status\n");
for (i = max; i < EDF_DEBUG_NODE; i++) {
EDFInfoPrint(i);
}
for (i = 0; i < max; i++) {
EDFInfoPrint(i);
}
SCHEDULER_LOCK(intSave);
g_edfNodePointer = max;
SCHEDULER_UNLOCK(intSave);
}
UINT32 OsShellShowEdfSchedStatistics(VOID)
{
UINT32 intSave;
LosTaskCB task;
UINT64 curTime;
UINT64 deadline;
UINT64 finishTime;
SchedEDF *sched = NULL;
PRINTK("Now Alive EDF Thread:\n");
PRINTK("TID CurTime DeadTime FinishTime taskName\n");
for (UINT32 tid = 0; tid < g_taskMaxNum; tid++) {
LosTaskCB *taskCB = g_taskCBArray + tid;
SCHEDULER_LOCK(intSave);
if (OsTaskIsUnused(taskCB)) {
SCHEDULER_UNLOCK(intSave);
continue;
}
sched = (SchedEDF *)&taskCB->sp;
if (sched->policy != LOS_SCHED_DEADLINE) {
SCHEDULER_UNLOCK(intSave);
continue;
}
(VOID)memcpy_s(&task, sizeof(LosTaskCB), taskCB, sizeof(LosTaskCB));
curTime = OS_SYS_CYCLE_TO_US(HalClockGetCycles());
finishTime = OS_SYS_CYCLE_TO_US(sched->finishTime);
deadline = OS_SYS_CYCLE_TO_US(taskCB->ops->deadlineGet(taskCB));
SCHEDULER_UNLOCK(intSave);
PRINTK("%3u%15llu%15llu%15llu %-32s\n",
task.taskID, curTime, deadline, finishTime, task.taskName);
}
OsEDFDebugPrint();
return LOS_OK;
}
#endif
#endif

View File

@@ -359,6 +359,12 @@ STATUS_T OsVmPageFaultHandler(VADDR_T vaddr, UINT32 flags, ExcContext *frame)
return LOS_ERRNO_VM_ACCESS_DENIED;
}
#ifdef LOSCFG_KERNEL_PLIMITS
if (OsMemLimitCheckAndMemAdd(PAGE_SIZE) != LOS_OK) {
return LOS_ERRNO_VM_NO_MEMORY;
}
#endif
(VOID)LOS_MuxAcquire(&space->regionMux);
region = LOS_RegionFind(space, vaddr);
if (region == NULL) {
@@ -450,6 +456,9 @@ VMM_MAP_FAILED:
}
CHECK_FAILED:
OsFaultTryFixup(frame, excVaddr, &status);
#ifdef LOSCFG_KERNEL_PLIMITS
OsMemLimitMemFree(PAGE_SIZE);
#endif
DONE:
(VOID)LOS_MuxRelease(&space->regionMux);
return status;

View File

@@ -34,7 +34,9 @@
#include "los_vm_phys.h"
#include "los_vm_boot.h"
#include "los_vm_filemap.h"
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
#include "los_plimits.h"
#endif
#ifdef LOSCFG_KERNEL_VM
@@ -81,7 +83,8 @@ VOID OsVmPageStartup(VOID)
* struct LosVmPage occupied, which satisfies the equation:
* nPage * sizeof(LosVmPage) + nPage * PAGE_SIZE = OsVmPhysPageNumGet() * PAGE_SIZE.
*/
nPage = OsVmPhysPageNumGet() * PAGE_SIZE / (sizeof(LosVmPage) + PAGE_SIZE);
UINT32 pageNum = OsVmPhysPageNumGet();
nPage = pageNum * PAGE_SIZE / (sizeof(LosVmPage) + PAGE_SIZE);
g_vmPageArraySize = nPage * sizeof(LosVmPage);
g_vmPageArray = (LosVmPage *)OsVmBootMemAlloc(g_vmPageArraySize);
@@ -89,6 +92,9 @@ VOID OsVmPageStartup(VOID)
OsVmPhysSegAdd();
OsVmPhysInit();
#ifdef LOSCFG_KERNEL_PLIMITS
OsMemLimitSetLimit(pageNum * PAGE_SIZE);
#endif
for (segID = 0; segID < g_vmPhysSegNum; segID++) {
seg = &g_vmPhysSeg[segID];

View File

@@ -52,7 +52,7 @@ STATIC struct VmPhysArea g_physArea[] = {
struct VmPhysSeg g_vmPhysSeg[VM_PHYS_SEG_MAX];
INT32 g_vmPhysSegNum = 0;
LosVmPhysSeg *OsGVmPhysSegGet()
LosVmPhysSeg *OsGVmPhysSegGet(void)
{
return g_vmPhysSeg;
}
@@ -456,6 +456,9 @@ VOID LOS_PhysPagesFreeContiguous(VOID *ptr, size_t nPages)
OsVmPhysPagesFreeContiguous(page, nPages);
LOS_SpinUnlockRestore(&seg->freeListLock, intSave);
#ifdef LOSCFG_KERNEL_PLIMITS
OsMemLimitMemFree(nPages * PAGE_SIZE);
#endif
}
PADDR_T OsKVaddrToPaddr(VADDR_T kvaddr)
@@ -503,6 +506,9 @@ VOID LOS_PhysPageFree(LosVmPage *page)
LOS_SpinUnlockRestore(&seg->freeListLock, intSave);
}
#ifdef LOSCFG_KERNEL_PLIMITS
OsMemLimitMemFree(PAGE_SIZE);
#endif
}
LosVmPage *LOS_PhysPageAlloc(VOID)

View File

@@ -193,41 +193,61 @@ STATIC VOID ShmPagesRefDec(struct shmIDSource *seg)
}
}
STATIC INT32 ShmAllocSeg(key_t key, size_t size, INT32 shmflg)
STATIC INT32 ShmAllocSegCheck(key_t key, size_t *size, INT32 *segNum)
{
INT32 i;
INT32 segNum = -1;
struct shmIDSource *seg = NULL;
size_t count;
if ((size == 0) || (size < IPC_SHM_INFO.shmmin) ||
(size > IPC_SHM_INFO.shmmax)) {
if ((*size == 0) || (*size < IPC_SHM_INFO.shmmin) ||
(*size > IPC_SHM_INFO.shmmax)) {
return -EINVAL;
}
size = LOS_Align(size, PAGE_SIZE);
if ((IPC_SHM_USED_PAGE_COUNT + (size >> PAGE_SHIFT)) > IPC_SHM_INFO.shmall) {
*size = LOS_Align(*size, PAGE_SIZE);
if ((IPC_SHM_USED_PAGE_COUNT + (*size >> PAGE_SHIFT)) > IPC_SHM_INFO.shmall) {
return -ENOMEM;
}
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
if (OsIPCLimitShmAlloc(*size) != LOS_OK) {
return -ENOMEM;
}
#endif
for (i = 0; i < IPC_SHM_INFO.shmmni; i++) {
if (IPC_SHM_SEGS[i].status & SHM_SEG_FREE) {
IPC_SHM_SEGS[i].status &= ~SHM_SEG_FREE;
segNum = i;
*segNum = i;
break;
}
}
if (segNum < 0) {
if (*segNum < 0) {
return -ENOSPC;
}
return 0;
}
STATIC INT32 ShmAllocSeg(key_t key, size_t size, INT32 shmflg)
{
INT32 segNum = -1;
struct shmIDSource *seg = NULL;
size_t count;
INT32 ret = ShmAllocSegCheck(key, &size, &segNum);
if (ret < 0) {
return ret;
}
seg = &IPC_SHM_SEGS[segNum];
count = LOS_PhysPagesAlloc(size >> PAGE_SHIFT, &seg->node);
if (count != (size >> PAGE_SHIFT)) {
(VOID)LOS_PhysPagesFree(&seg->node);
seg->status = SHM_SEG_FREE;
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
OsIPCLimitShmFree(size);
#endif
return -ENOMEM;
}
ShmSetSharedFlag(seg);
IPC_SHM_USED_PAGE_COUNT += size >> PAGE_SHIFT;
@@ -252,7 +272,7 @@ STATIC INT32 ShmAllocSeg(key_t key, size_t size, INT32 shmflg)
return segNum;
}
STATIC INLINE VOID ShmFreeSeg(struct shmIDSource *seg)
STATIC INLINE VOID ShmFreeSeg(struct shmIDSource *seg, UINT32 *shmUsedPageCount)
{
UINT32 count;
@@ -262,7 +282,12 @@ STATIC INLINE VOID ShmFreeSeg(struct shmIDSource *seg)
VM_ERR("free physical pages failed, count = %d, size = %d", count, seg->ds.shm_segsz >> PAGE_SHIFT);
return;
}
IPC_SHM_USED_PAGE_COUNT -= seg->ds.shm_segsz >> PAGE_SHIFT;
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
OsIPCLimitShmFree(seg->ds.shm_segsz);
#endif
if (shmUsedPageCount != NULL) {
(*shmUsedPageCount) -= seg->ds.shm_segsz >> PAGE_SHIFT;
}
seg->status = SHM_SEG_FREE;
LOS_ListInit(&seg->node);
}
@@ -369,7 +394,7 @@ VOID OsShmRegionFree(LosVmSpace *space, LosVmMapRegion *region)
ShmPagesRefDec(seg);
seg->ds.shm_nattch--;
if (seg->ds.shm_nattch <= 0 && (seg->status & SHM_SEG_REMOVE)) {
ShmFreeSeg(seg);
ShmFreeSeg(seg, &IPC_SHM_USED_PAGE_COUNT);
} else {
seg->ds.shm_dtime = time(NULL);
seg->ds.shm_lpid = LOS_GetCurrProcessID(); /* may not be the space's PID. */
@@ -677,7 +702,7 @@ INT32 ShmCtl(INT32 shmid, INT32 cmd, struct shmid_ds *buf)
seg->status |= SHM_SEG_REMOVE;
if (seg->ds.shm_nattch <= 0) {
ShmFreeSeg(seg);
ShmFreeSeg(seg, &IPC_SHM_USED_PAGE_COUNT);
}
break;
case IPC_INFO:
@@ -763,7 +788,7 @@ INT32 ShmDt(const VOID *shmaddr)
seg->ds.shm_nattch--;
if ((seg->ds.shm_nattch <= 0) &&
(seg->status & SHM_SEG_REMOVE)) {
ShmFreeSeg(seg);
ShmFreeSeg(seg, &IPC_SHM_USED_PAGE_COUNT);
} else {
seg->ds.shm_dtime = time(NULL);
seg->ds.shm_lpid = LOS_GetCurrProcessID();
@@ -780,6 +805,27 @@ ERROR:
return -1;
}
VOID OsShmCBDestroy(struct shmIDSource *shmSegs, struct shminfo *shmInfo, LosMux *sysvShmMux)
{
if ((shmSegs == NULL) || (shmInfo == NULL) || (sysvShmMux == NULL)) {
return;
}
for (UINT32 index = 0; index < shmInfo->shmmni; index++) {
struct shmIDSource *seg = &shmSegs[index];
if (seg->status == SHM_SEG_FREE) {
continue;
}
(VOID)LOS_MuxLock(sysvShmMux, LOS_WAIT_FOREVER);
ShmFreeSeg(seg, NULL);
(VOID)LOS_MuxUnlock(sysvShmMux);
}
(VOID)LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, shmSegs);
(VOID)LOS_MuxDestroy(sysvShmMux);
}
#ifdef LOSCFG_SHELL
STATIC VOID OsShmInfoCmd(VOID)
{
@@ -819,7 +865,7 @@ STATIC VOID OsShmDeleteCmd(INT32 shmid)
}
if (seg->ds.shm_nattch <= 0) {
ShmFreeSeg(seg);
ShmFreeSeg(seg, &IPC_SHM_USED_PAGE_COUNT);
}
SYSV_SHM_UNLOCK();
}

View File

@@ -389,6 +389,14 @@ extern UINT32 __heap_end;
#define VERSION_NUM(a, b, c, d) (((a) << 24) | ((b) << 16) | (c) << 8 | (d))
#define KERNEL_OPEN_VERSION_NUM VERSION_NUM(KERNEL_MAJOR, KERNEL_MINOR, KERNEL_PATCH, KERNEL_ITRE)
/**
* @ingroup los_config
* The container limit
*/
#ifndef LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT
#define LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT 10
#endif
/****************************** Exception information configuration ******************************/
#ifdef LOSCFG_SAVE_EXCINFO
/**

View File

@@ -32,6 +32,7 @@ import("//kernel/liteos_a/liteos.gni")
group("extended") {
deps = [
"blackbox",
"container",
"cppsupport",
"cpup",
"dynload",
@@ -42,6 +43,7 @@ group("extended") {
"lms",
"perf",
"pipes",
"plimit",
"power",
"trace",
"vdso",
@@ -51,6 +53,7 @@ group("extended") {
config("public") {
configs = [
"blackbox:public",
"container:public",
"cpup:public",
"dynload:public",
"hidumper:public",
@@ -62,5 +65,6 @@ config("public") {
"perf:public",
"lms:public",
"power:public",
"plimit:public",
]
}

View File

@@ -76,6 +76,31 @@ config KERNEL_PIPE
help
Answer Y to enable LiteOS support pipes.
config KERNEL_PLIMITS
bool "Enable plimits Feature"
default n
depends on KERNEL_EXTKERNEL
config KERNEL_MEM_PLIMIT
bool "Enable mem limits Feature"
default n
depends on KERNEL_PLIMITS
config KERNEL_IPC_PLIMIT
bool "Enable ipc limits Feature"
default n
depends on KERNEL_PLIMITS
config KERNEL_DEV_PLIMIT
bool "Enable dev limits Feature"
default n
depends on KERNEL_PLIMITS
config KERNEL_SCHED_PLIMIT
bool "Enable sched limits Feature"
default n
depends on KERNEL_PLIMITS
config BASE_CORE_HILOG
bool "Enable Hilog"
default y
@@ -88,6 +113,54 @@ config KERNEL_HOOK
default n
depends on KERNEL_EXTKERNEL && DEBUG_VERSION
######################### config options of container ####################
config KERNEL_CONTAINER
bool "Enable container Feature"
default n
depends on KERNEL_VM
config PID_CONTAINER
bool "Enable pid container Feature"
default n
depends on KERNEL_CONTAINER
config UTS_CONTAINER
bool "Enable uts container Feature"
default n
depends on KERNEL_CONTAINER
config MNT_CONTAINER
bool "Enable mnt container Feature"
default n
depends on KERNEL_CONTAINER
config CHROOT
bool "Enable chroot"
default n
depends on MNT_CONTAINER
config IPC_CONTAINER
bool "Enable ipc container Feature"
default n
depends on KERNEL_CONTAINER
config TIME_CONTAINER
bool "Enable time container"
default n
depends on KERNEL_CONTAINER
config USER_CONTAINER
bool "Enable user container"
default n
depends on KERNEL_CONTAINER
config NET_CONTAINER
bool "Enable net container"
default n
depends on KERNEL_CONTAINER
######################### config options of trace #########################
source "kernel/extended/trace/Kconfig"
@@ -104,4 +177,4 @@ source "kernel/extended/perf/Kconfig"
source "kernel/extended/lms/Kconfig"
######################### config options of hilog #########################
source "kernel/extended/hilog/Kconfig"
source "kernel/extended/hilog/Kconfig"

View File

@@ -0,0 +1,65 @@
# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
module_switch = defined(LOSCFG_KERNEL_CONTAINER)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [ "los_container.c" ]
if (defined(LOSCFG_IPC_CONTAINER)) {
sources += [ "los_ipc_container.c" ]
}
if (defined(LOSCFG_MNT_CONTAINER)) {
sources += [ "los_mnt_container.c" ]
}
if (defined(LOSCFG_NET_CONTAINER)) {
sources += [ "los_net_container.c" ]
}
if (defined(LOSCFG_PID_CONTAINER)) {
sources += [ "los_pid_container.c" ]
}
if (defined(LOSCFG_TIME_CONTAINER)) {
sources += [ "los_time_container.c" ]
}
if (defined(LOSCFG_USER_CONTAINER)) {
sources += [
"los_credentials.c",
"los_user_container.c",
]
}
if (defined(LOSCFG_UTS_CONTAINER)) {
sources += [ "los_uts_container.c" ]
}
public_configs = [ ":public" ]
}
config("public") {
include_dirs = [ "." ]
}

View File

@@ -0,0 +1,63 @@
# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
include $(LITEOSTOPDIR)/config.mk
MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard *.c)
ifneq ($(LOSCFG_IPC_CONTAINER), y)
LOCAL_SRCS += $(filter-out los_ipc_container.c, $(LOCAL_SRCS))
endif
ifneq ($(LOSCFG_MNT_CONTAINER), y)
LOCAL_SRCS += $(filter-out los_mnt_container.c, $(LOCAL_SRCS))
endif
ifneq ($(LOSCFG_NET_CONTAINER), y)
LOCAL_SRCS += $(filter-out los_net_container.c, $(LOCAL_SRCS))
endif
ifneq ($(LOSCFG_PID_CONTAINER), y)
LOCAL_SRCS += $(filter-out los_pid_container.c, $(LOCAL_SRCS))
endif
ifneq ($(LOSCFG_TIME_CONTAINER), y)
LOCAL_SRCS += $(filter-out los_time_container.c, $(LOCAL_SRCS))
endif
ifneq ($(LOSCFG_USER_CONTAINER), y)
LOCAL_SRCS += $(filter-out los_credentials.c los_user_container.c, $(LOCAL_SRCS))
endif
ifneq ($(LOSCFG_UTS_CONTAINER), y)
LOCAL_SRCS += $(filter-out los_uts_container.c, $(LOCAL_SRCS))
endif
include $(MODULE)

View File

@@ -0,0 +1,755 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef LOSCFG_KERNEL_CONTAINER
#include "los_container_pri.h"
#include "los_process_pri.h"
#include "internal.h"
STATIC Container g_rootContainer;
STATIC ContainerLimit g_containerLimit;
STATIC Atomic g_containerCount = 0xF0000000U;
#ifdef LOSCFG_USER_CONTAINER
STATIC Credentials *g_rootCredentials = NULL;
#endif
UINT32 OsAllocContainerID(VOID)
{
return LOS_AtomicIncRet(&g_containerCount);
}
VOID OsContainerInitSystemProcess(LosProcessCB *processCB)
{
processCB->container = &g_rootContainer;
#ifdef LOSCFG_USER_CONTAINER
processCB->credentials = g_rootCredentials;
#endif
LOS_AtomicInc(&processCB->container->rc);
#ifdef LOSCFG_PID_CONTAINER
(VOID)OsAllocSpecifiedVpidUnsafe(processCB->processID, processCB->container->pidContainer, processCB, NULL);
#endif
return;
}
UINT32 OsGetContainerLimit(ContainerType type)
{
switch (type) {
#ifdef LOSCFG_PID_CONTAINER
case PID_CONTAINER:
case PID_CHILD_CONTAINER:
return g_containerLimit.pidLimit;
#endif
#ifdef LOSCFG_USER_CONTAINER
case USER_CONTAINER:
return g_containerLimit.userLimit;
#endif
#ifdef LOSCFG_UTS_CONTAINER
case UTS_CONTAINER:
return g_containerLimit.utsLimit;
#endif
#ifdef LOSCFG_MNT_CONTAINER
case MNT_CONTAINER:
return g_containerLimit.mntLimit;
#endif
#ifdef LOSCFG_IPC_CONTAINER
case IPC_CONTAINER:
return g_containerLimit.ipcLimit;
#endif
#ifdef LOSCFG_TIME_CONTAINER
case TIME_CONTAINER:
case TIME_CHILD_CONTAINER:
return g_containerLimit.timeLimit;
#endif
#ifdef LOSCFG_NET_CONTAINER
case NET_CONTAINER:
return g_containerLimit.netLimit;
#endif
default:
break;
}
return OS_INVALID_VALUE;
}
UINT32 OsContainerLimitCheck(ContainerType type, UINT32 *containerCount)
{
UINT32 intSave;
SCHEDULER_LOCK(intSave);
if ((*containerCount) >= OsGetContainerLimit(type)) {
SCHEDULER_UNLOCK(intSave);
return EINVAL;
}
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
UINT32 OsSetContainerLimit(ContainerType type, UINT32 value)
{
UINT32 intSave;
if (value > LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT) {
return EINVAL;
}
SCHEDULER_LOCK(intSave);
switch (type) {
#ifdef LOSCFG_PID_CONTAINER
case PID_CONTAINER:
case PID_CHILD_CONTAINER:
g_containerLimit.pidLimit = value;
break;
#endif
#ifdef LOSCFG_USER_CONTAINER
case USER_CONTAINER:
g_containerLimit.userLimit = value;
break;
#endif
#ifdef LOSCFG_UTS_CONTAINER
case UTS_CONTAINER:
g_containerLimit.utsLimit = value;
break;
#endif
#ifdef LOSCFG_MNT_CONTAINER
case MNT_CONTAINER:
g_containerLimit.mntLimit = value;
break;
#endif
#ifdef LOSCFG_IPC_CONTAINER
case IPC_CONTAINER:
g_containerLimit.ipcLimit = value;
break;
#endif
#ifdef LOSCFG_TIME_CONTAINER
case TIME_CONTAINER:
case TIME_CHILD_CONTAINER:
g_containerLimit.timeLimit = value;
break;
#endif
#ifdef LOSCFG_NET_CONTAINER
case NET_CONTAINER:
g_containerLimit.netLimit = value;
break;
#endif
default:
SCHEDULER_UNLOCK(intSave);
return EINVAL;
}
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
UINT32 OsGetContainerCount(ContainerType type)
{
switch (type) {
#ifdef LOSCFG_PID_CONTAINER
case PID_CONTAINER:
case PID_CHILD_CONTAINER:
return OsGetPidContainerCount();
#endif
#ifdef LOSCFG_USER_CONTAINER
case USER_CONTAINER:
return OsGetUserContainerCount();
#endif
#ifdef LOSCFG_UTS_CONTAINER
case UTS_CONTAINER:
return OsGetUtsContainerCount();
#endif
#ifdef LOSCFG_MNT_CONTAINER
case MNT_CONTAINER:
return OsGetMntContainerCount();
#endif
#ifdef LOSCFG_IPC_CONTAINER
case IPC_CONTAINER:
return OsGetIpcContainerCount();
#endif
#ifdef LOSCFG_TIME_CONTAINER
case TIME_CONTAINER:
case TIME_CHILD_CONTAINER:
return OsGetTimeContainerCount();
#endif
#ifdef LOSCFG_NET_CONTAINER
case NET_CONTAINER:
return OsGetNetContainerCount();
#endif
default:
break;
}
return OS_INVALID_VALUE;
}
VOID OsInitRootContainer(VOID)
{
#ifdef LOSCFG_USER_CONTAINER
g_containerLimit.userLimit = LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT;
OsInitRootUserCredentials(&g_rootCredentials);
#endif
#ifdef LOSCFG_PID_CONTAINER
g_containerLimit.pidLimit = LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT;
(VOID)OsInitRootPidContainer(&g_rootContainer.pidContainer);
g_rootContainer.pidForChildContainer = g_rootContainer.pidContainer;
#endif
#ifdef LOSCFG_UTS_CONTAINER
g_containerLimit.utsLimit = LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT;
(VOID)OsInitRootUtsContainer(&g_rootContainer.utsContainer);
#endif
#ifdef LOSCFG_MNT_CONTAINER
g_containerLimit.mntLimit = LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT;
(VOID)OsInitRootMntContainer(&g_rootContainer.mntContainer);
#endif
#ifdef LOSCFG_IPC_CONTAINER
g_containerLimit.ipcLimit = LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT;
(VOID)OsInitRootIpcContainer(&g_rootContainer.ipcContainer);
#endif
#ifdef LOSCFG_TIME_CONTAINER
g_containerLimit.timeLimit = LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT;
(VOID)OsInitRootTimeContainer(&g_rootContainer.timeContainer);
g_rootContainer.timeForChildContainer = g_rootContainer.timeContainer;
#endif
#ifdef LOSCFG_NET_CONTAINER
g_containerLimit.netLimit = LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT;
(VOID)OsInitRootNetContainer(&g_rootContainer.netContainer);
#endif
return;
}
STATIC INLINE Container *CreateContainer(VOID)
{
Container *container = (Container *)LOS_MemAlloc(m_aucSysMem1, sizeof(Container));
if (container == NULL) {
return NULL;
}
(VOID)memset_s(container, sizeof(Container), 0, sizeof(Container));
LOS_AtomicInc(&container->rc);
return container;
}
STATIC UINT32 CopyContainers(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID)
{
UINT32 ret = LOS_OK;
/* Pid container initialization must precede other container initialization. */
#ifdef LOSCFG_PID_CONTAINER
ret = OsCopyPidContainer(flags, child, parent, processID);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_USER_CONTAINER
ret = OsCopyCredentials(flags, child, parent);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_UTS_CONTAINER
ret = OsCopyUtsContainer(flags, child, parent);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_MNT_CONTAINER
ret = OsCopyMntContainer(flags, child, parent);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_IPC_CONTAINER
ret = OsCopyIpcContainer(flags, child, parent);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_TIME_CONTAINER
ret = OsCopyTimeContainer(flags, child, parent);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_NET_CONTAINER
ret = OsCopyNetContainer(flags, child, parent);
if (ret != LOS_OK) {
return ret;
}
#endif
return ret;
}
STATIC INLINE UINT32 GetContainerFlagsMask(VOID)
{
UINT32 mask = 0;
#ifdef LOSCFG_PID_CONTAINER
mask |= CLONE_NEWPID;
#endif
#ifdef LOSCFG_MNT_CONTAINER
mask |= CLONE_NEWNS;
#endif
#ifdef LOSCFG_IPC_CONTAINER
mask |= CLONE_NEWIPC;
#endif
#ifdef LOSCFG_USER_CONTAINER
mask |= CLONE_NEWUSER;
#endif
#ifdef LOSCFG_TIME_CONTAINER
mask |= CLONE_NEWTIME;
#endif
#ifdef LOSCFG_NET_CONTAINER
mask |= CLONE_NEWNET;
#endif
#ifdef LOSCFG_UTS_CONTAINER
mask |= CLONE_NEWUTS;
#endif
return mask;
}
/*
* called from clone. This now handles copy for Container and all
* namespaces therein.
*/
UINT32 OsCopyContainers(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID)
{
UINT32 intSave;
#ifdef LOSCFG_TIME_CONTAINER
flags &= ~CLONE_NEWTIME;
#endif
if (!(flags & GetContainerFlagsMask())) {
#ifdef LOSCFG_PID_CONTAINER
if (parent->container->pidContainer != parent->container->pidForChildContainer) {
goto CREATE_CONTAINER;
}
#endif
#ifdef LOSCFG_TIME_CONTAINER
if (parent->container->timeContainer != parent->container->timeForChildContainer) {
goto CREATE_CONTAINER;
}
#endif
SCHEDULER_LOCK(intSave);
child->container = parent->container;
LOS_AtomicInc(&child->container->rc);
SCHEDULER_UNLOCK(intSave);
goto COPY_CONTAINERS;
}
#if defined(LOSCFG_PID_CONTAINER) || defined(LOSCFG_TIME_CONTAINER)
CREATE_CONTAINER:
#endif
child->container = CreateContainer();
if (child->container == NULL) {
return ENOMEM;
}
COPY_CONTAINERS:
return CopyContainers(flags, child, parent, processID);
}
VOID OsContainerFree(LosProcessCB *processCB)
{
LOS_AtomicDec(&processCB->container->rc);
if (LOS_AtomicRead(&processCB->container->rc) == 0) {
(VOID)LOS_MemFree(m_aucSysMem1, processCB->container);
processCB->container = NULL;
}
}
VOID OsOsContainersDestroyEarly(LosProcessCB *processCB)
{
/* All processes in the container must be destroyed before the container is destroyed. */
#ifdef LOSCFG_PID_CONTAINER
if (processCB->processID == OS_USER_ROOT_PROCESS_ID) {
OsPidContainerDestroyAllProcess(processCB);
}
#endif
#ifdef LOSCFG_MNT_CONTAINER
OsMntContainerDestroy(processCB->container);
#endif
}
VOID OsContainersDestroy(LosProcessCB *processCB)
{
#ifdef LOSCFG_USER_CONTAINER
OsUserContainerDestroy(processCB);
#endif
#ifdef LOSCFG_UTS_CONTAINER
OsUtsContainerDestroy(processCB->container);
#endif
#ifdef LOSCFG_IPC_CONTAINER
OsIpcContainerDestroy(processCB->container);
#endif
#ifdef LOSCFG_TIME_CONTAINER
OsTimeContainerDestroy(processCB->container);
#endif
#ifdef LOSCFG_NET_CONTAINER
OsNetContainerDestroy(processCB->container);
#endif
#ifndef LOSCFG_PID_CONTAINER
UINT32 intSave;
SCHEDULER_LOCK(intSave);
OsContainerFree(processCB);
SCHEDULER_UNLOCK(intSave);
#endif
}
STATIC VOID DeInitContainers(UINT32 flags, Container *container, LosProcessCB *processCB)
{
UINT32 intSave;
if (container == NULL) {
return;
}
#ifdef LOSCFG_PID_CONTAINER
SCHEDULER_LOCK(intSave);
if ((flags & CLONE_NEWPID) != 0) {
OsPidContainerDestroy(container, processCB);
} else {
OsPidContainerDestroy(container, NULL);
}
SCHEDULER_UNLOCK(intSave);
#endif
#ifdef LOSCFG_UTS_CONTAINER
OsUtsContainerDestroy(container);
#endif
#ifdef LOSCFG_MNT_CONTAINER
OsMntContainerDestroy(container);
#endif
#ifdef LOSCFG_IPC_CONTAINER
OsIpcContainerDestroy(container);
#endif
#ifdef LOSCFG_TIME_CONTAINER
OsTimeContainerDestroy(container);
#endif
#ifdef LOSCFG_NET_CONTAINER
OsNetContainerDestroy(container);
#endif
SCHEDULER_LOCK(intSave);
LOS_AtomicDec(&container->rc);
if (LOS_AtomicRead(&container->rc) == 0) {
(VOID)LOS_MemFree(m_aucSysMem1, container);
}
SCHEDULER_UNLOCK(intSave);
}
UINT32 OsGetContainerID(LosProcessCB *processCB, ContainerType type)
{
Container *container = processCB->container;
if (container == NULL) {
return OS_INVALID_VALUE;
}
switch (type) {
#ifdef LOSCFG_PID_CONTAINER
case PID_CONTAINER:
return OsGetPidContainerID(container->pidContainer);
case PID_CHILD_CONTAINER:
return OsGetPidContainerID(container->pidForChildContainer);
#endif
#ifdef LOSCFG_USER_CONTAINER
case USER_CONTAINER:
return OsGetUserContainerID(processCB->credentials);
#endif
#ifdef LOSCFG_UTS_CONTAINER
case UTS_CONTAINER:
return OsGetUtsContainerID(container->utsContainer);
#endif
#ifdef LOSCFG_MNT_CONTAINER
case MNT_CONTAINER:
return OsGetMntContainerID(container->mntContainer);
#endif
#ifdef LOSCFG_IPC_CONTAINER
case IPC_CONTAINER:
return OsGetIpcContainerID(container->ipcContainer);
#endif
#ifdef LOSCFG_TIME_CONTAINER
case TIME_CONTAINER:
return OsGetTimeContainerID(container->timeContainer);
case TIME_CHILD_CONTAINER:
return OsGetTimeContainerID(container->timeForChildContainer);
#endif
#ifdef LOSCFG_NET_CONTAINER
case NET_CONTAINER:
return OsGetNetContainerID(container->netContainer);
#endif
default:
break;
}
return OS_INVALID_VALUE;
}
STATIC UINT32 UnshareCreateNewContainers(UINT32 flags, LosProcessCB *curr, Container *newContainer)
{
UINT32 ret = LOS_OK;
#ifdef LOSCFG_PID_CONTAINER
ret = OsUnsharePidContainer(flags, curr, newContainer);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_UTS_CONTAINER
ret = OsUnshareUtsContainer(flags, curr, newContainer);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_MNT_CONTAINER
ret = OsUnshareMntContainer(flags, curr, newContainer);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_IPC_CONTAINER
ret = OsUnshareIpcContainer(flags, curr, newContainer);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_TIME_CONTAINER
ret = OsUnshareTimeContainer(flags, curr, newContainer);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_NET_CONTAINER
ret = OsUnshareNetContainer(flags, curr, newContainer);
if (ret != LOS_OK) {
return ret;
}
#endif
return ret;
}
INT32 OsUnshare(UINT32 flags)
{
UINT32 ret;
UINT32 intSave;
LosProcessCB *curr = OsCurrProcessGet();
Container *oldContainer = curr->container;
UINT32 unshareFlags = GetContainerFlagsMask();
if (!(flags & unshareFlags) || ((flags & (~unshareFlags)) != 0)) {
return -EINVAL;
}
#ifdef LOSCFG_USER_CONTAINER
ret = OsUnshareUserCredentials(flags, curr);
if (ret != LOS_OK) {
return ret;
}
if (flags == CLONE_NEWUSER) {
return LOS_OK;
}
#endif
Container *newContainer = CreateContainer();
if (newContainer == NULL) {
return -ENOMEM;
}
ret = UnshareCreateNewContainers(flags, curr, newContainer);
if (ret != LOS_OK) {
goto EXIT;
}
SCHEDULER_LOCK(intSave);
oldContainer = curr->container;
curr->container = newContainer;
SCHEDULER_UNLOCK(intSave);
DeInitContainers(flags, oldContainer, NULL);
return LOS_OK;
EXIT:
DeInitContainers(flags, newContainer, NULL);
return -ret;
}
STATIC UINT32 SetNsGetFlagByContainerType(UINT32 containerType)
{
if (containerType >= (UINT32)CONTAINER_MAX) {
return 0;
}
ContainerType type = (ContainerType)containerType;
switch (type) {
case PID_CONTAINER:
case PID_CHILD_CONTAINER:
return CLONE_NEWPID;
case USER_CONTAINER:
return CLONE_NEWUSER;
case UTS_CONTAINER:
return CLONE_NEWUTS;
case MNT_CONTAINER:
return CLONE_NEWNS;
case IPC_CONTAINER:
return CLONE_NEWIPC;
case TIME_CONTAINER:
case TIME_CHILD_CONTAINER:
return CLONE_NEWTIME;
case NET_CONTAINER:
return CLONE_NEWNET;
default:
break;
}
return 0;
}
STATIC UINT32 SetNsCreateNewContainers(UINT32 flags, Container *newContainer, Container *container)
{
UINT32 ret = LOS_OK;
#ifdef LOSCFG_PID_CONTAINER
ret = OsSetNsPidContainer(flags, container, newContainer);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_UTS_CONTAINER
ret = OsSetNsUtsContainer(flags, container, newContainer);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_MNT_CONTAINER
ret = OsSetNsMntContainer(flags, container, newContainer);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_IPC_CONTAINER
ret = OsSetNsIpcContainer(flags, container, newContainer);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_TIME_CONTAINER
ret = OsSetNsTimeContainer(flags, container, newContainer);
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_NET_CONTAINER
ret = OsSetNsNetContainer(flags, container, newContainer);
if (ret != LOS_OK) {
return ret;
}
#endif
return LOS_OK;
}
STATIC UINT32 SetNsParamCheck(INT32 fd, INT32 type, UINT32 *flag, LosProcessCB **target)
{
UINT32 typeMask = GetContainerFlagsMask();
*flag = (UINT32)(type & typeMask);
UINT32 containerType = 0;
if (((type & (~typeMask)) != 0)) {
return EINVAL;
}
LosProcessCB *processCB = (LosProcessCB *)ProcfsContainerGet(fd, &containerType);
if (processCB == NULL) {
return EBADF;
}
if (*flag == 0) {
*flag = SetNsGetFlagByContainerType(containerType);
}
if ((*flag == 0) || (*flag != SetNsGetFlagByContainerType(containerType))) {
return EINVAL;
}
if (processCB == OsCurrProcessGet()) {
return EINVAL;
}
*target = processCB;
return LOS_OK;
}
INT32 OsSetNs(INT32 fd, INT32 type)
{
UINT32 intSave, ret;
UINT32 flag = 0;
LosProcessCB *curr = OsCurrProcessGet();
LosProcessCB *processCB = NULL;
ret = SetNsParamCheck(fd, type, &flag, &processCB);
if (ret != LOS_OK) {
return -ret;
}
#ifdef LOSCFG_USER_CONTAINER
if (flag == CLONE_NEWUSER) {
SCHEDULER_LOCK(intSave);
if ((processCB->credentials == NULL) || (processCB->credentials->userContainer == NULL)) {
SCHEDULER_UNLOCK(intSave);
return -EBADF;
}
UserContainer *userContainer = processCB->credentials->userContainer;
ret = OsSetNsUserContainer(userContainer, curr);
SCHEDULER_UNLOCK(intSave);
return ret;
}
#endif
Container *newContainer = CreateContainer();
if (newContainer == NULL) {
return -ENOMEM;
}
SCHEDULER_LOCK(intSave);
Container *targetContainer = processCB->container;
if (targetContainer == NULL) {
SCHEDULER_UNLOCK(intSave);
return -EBADF;
}
ret = SetNsCreateNewContainers(flag, newContainer, targetContainer);
if (ret != LOS_OK) {
SCHEDULER_UNLOCK(intSave);
goto EXIT;
}
Container *oldContainer = curr->container;
curr->container = newContainer;
SCHEDULER_UNLOCK(intSave);
DeInitContainers(flag, oldContainer, NULL);
return LOS_OK;
EXIT:
DeInitContainers(flag, newContainer, curr);
return ret;
}
#endif

View File

@@ -0,0 +1,209 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <errno.h>
#include "los_credentials_pri.h"
#include "los_user_container_pri.h"
#include "los_config.h"
#include "los_memory.h"
#include "los_process_pri.h"
#ifdef LOSCFG_USER_CONTAINER
STATIC Credentials *CreateNewCredential(LosProcessCB *parent)
{
UINT32 size = sizeof(Credentials);
Credentials *newCredentials = LOS_MemAlloc(m_aucSysMem1, size);
if (newCredentials == NULL) {
return NULL;
}
if (parent != NULL) {
const Credentials *oldCredentials = parent->credentials;
(VOID)memcpy_s(newCredentials, sizeof(Credentials), oldCredentials, sizeof(Credentials));
LOS_AtomicSet(&newCredentials->rc, 1);
} else {
(VOID)memset_s(newCredentials, sizeof(Credentials), 0, sizeof(Credentials));
LOS_AtomicSet(&newCredentials->rc, 3); /* 3: Three system processes */
}
newCredentials->userContainer = NULL;
return newCredentials;
}
Credentials *PrepareCredential(LosProcessCB *runProcessCB)
{
Credentials *newCredentials = CreateNewCredential(runProcessCB);
if (newCredentials == NULL) {
return NULL;
}
newCredentials->userContainer = runProcessCB->credentials->userContainer;
LOS_AtomicInc(&newCredentials->userContainer->rc);
return newCredentials;
}
VOID FreeCredential(Credentials *credentials)
{
if (credentials == NULL) {
return;
}
if (credentials->userContainer != NULL) {
LOS_AtomicDec(&credentials->userContainer->rc);
if (LOS_AtomicRead(&credentials->userContainer->rc) <= 0) {
FreeUserContainer(credentials->userContainer);
credentials->userContainer = NULL;
}
}
LOS_AtomicDec(&credentials->rc);
if (LOS_AtomicRead(&credentials->rc) <= 0) {
(VOID)LOS_MemFree(m_aucSysMem1, credentials);
}
}
VOID OsUserContainerDestroy(LosProcessCB *curr)
{
UINT32 intSave;
SCHEDULER_LOCK(intSave);
FreeCredential(curr->credentials);
curr->credentials = NULL;
SCHEDULER_UNLOCK(intSave);
return;
}
STATIC Credentials *CreateCredentials(unsigned long flags, LosProcessCB *parent)
{
UINT32 ret;
Credentials *newCredentials = CreateNewCredential(parent);
if (newCredentials == NULL) {
return NULL;
}
if (!(flags & CLONE_NEWUSER)) {
newCredentials->userContainer = parent->credentials->userContainer;
LOS_AtomicInc(&newCredentials->userContainer->rc);
return newCredentials;
}
if (parent != NULL) {
ret = OsCreateUserContainer(newCredentials, parent->credentials->userContainer);
} else {
ret = OsCreateUserContainer(newCredentials, NULL);
}
if (ret != LOS_OK) {
FreeCredential(newCredentials);
return NULL;
}
return newCredentials;
}
UINT32 OsCopyCredentials(unsigned long flags, LosProcessCB *child, LosProcessCB *parent)
{
UINT32 intSave;
SCHEDULER_LOCK(intSave);
child->credentials = CreateCredentials(flags, parent);
SCHEDULER_UNLOCK(intSave);
if (child->credentials == NULL) {
return ENOMEM;
}
return LOS_OK;
}
UINT32 OsInitRootUserCredentials(Credentials **credentials)
{
*credentials = CreateCredentials(CLONE_NEWUSER, NULL);
if (*credentials == NULL) {
return ENOMEM;
}
return LOS_OK;
}
UINT32 OsUnshareUserCredentials(UINTPTR flags, LosProcessCB *curr)
{
UINT32 intSave;
if (!(flags & CLONE_NEWUSER)) {
return LOS_OK;
}
SCHEDULER_LOCK(intSave);
UINT32 ret = OsCreateUserContainer(curr->credentials, curr->credentials->userContainer);
SCHEDULER_UNLOCK(intSave);
return ret;
}
UINT32 OsSetNsUserContainer(struct UserContainer *targetContainer, LosProcessCB *runProcess)
{
Credentials *oldCredentials = runProcess->credentials;
Credentials *newCredentials = CreateNewCredential(runProcess);
if (newCredentials == NULL) {
return ENOMEM;
}
runProcess->credentials = newCredentials;
newCredentials->userContainer = targetContainer;
LOS_AtomicInc(&targetContainer->rc);
FreeCredential(oldCredentials);
return LOS_OK;
}
UINT32 OsGetUserContainerID(Credentials *credentials)
{
if ((credentials == NULL) || (credentials->userContainer == NULL)) {
return OS_INVALID_VALUE;
}
return credentials->userContainer->containerID;
}
INT32 CommitCredentials(Credentials *newCredentials)
{
Credentials *oldCredentials = OsCurrProcessGet()->credentials;
if (LOS_AtomicRead(&newCredentials->rc) < 1) {
return -EINVAL;
}
OsCurrProcessGet()->credentials = newCredentials;
FreeCredential(oldCredentials);
return 0;
}
Credentials *CurrentCredentials(VOID)
{
return OsCurrProcessGet()->credentials;
}
UserContainer *OsCurrentUserContainer(VOID)
{
UserContainer *userContainer = OsCurrProcessGet()->credentials->userContainer;
return userContainer;
}
#endif

View File

@@ -121,6 +121,10 @@ UINT32 OsCopyIpcContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
return LOS_OK;
}
if (OsContainerLimitCheck(IPC_CONTAINER, &g_currentIpcContainerNum) != LOS_OK) {
return EPERM;
}
return CreateIpcContainer(child, parent);
}
@@ -132,10 +136,15 @@ UINT32 OsUnshareIpcContainer(UINTPTR flags, LosProcessCB *curr, Container *newCo
if (!(flags & CLONE_NEWIPC)) {
SCHEDULER_LOCK(intSave);
newContainer->ipcContainer = parentContainer;
LOS_AtomicInc(&parentContainer->rc);
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
if (OsContainerLimitCheck(IPC_CONTAINER, &g_currentIpcContainerNum) != LOS_OK) {
return EPERM;
}
IpcContainer *ipcContainer = CreateNewIpcContainer(parentContainer);
if (ipcContainer == NULL) {
return ENOMEM;
@@ -148,6 +157,19 @@ UINT32 OsUnshareIpcContainer(UINTPTR flags, LosProcessCB *curr, Container *newCo
return LOS_OK;
}
UINT32 OsSetNsIpcContainer(UINT32 flags, Container *container, Container *newContainer)
{
if (flags & CLONE_NEWIPC) {
newContainer->ipcContainer = container->ipcContainer;
LOS_AtomicInc(&container->ipcContainer->rc);
return LOS_OK;
}
newContainer->ipcContainer = OsCurrProcessGet()->container->ipcContainer;
LOS_AtomicInc(&newContainer->ipcContainer->rc);
return LOS_OK;
}
VOID OsIpcContainerDestroy(Container *container)
{
UINT32 intSave;
@@ -169,9 +191,11 @@ VOID OsIpcContainerDestroy(Container *container)
}
g_currentIpcContainerNum--;
SCHEDULER_UNLOCK(intSave);
ShmDeinit();
container->ipcContainer = NULL;
SCHEDULER_UNLOCK(intSave);
OsShmCBDestroy(ipcContainer->shmSegs, &ipcContainer->shmInfo, &ipcContainer->sysvShmMux);
ipcContainer->shmSegs = NULL;
OsMqueueCBDestroy(ipcContainer->queueTable);
(VOID)LOS_MemFree(m_aucSysMem1, ipcContainer->allQueue);
(VOID)LOS_MemFree(m_aucSysMem1, ipcContainer);
return;
@@ -190,4 +214,9 @@ IpcContainer *OsGetCurrIpcContainer(VOID)
{
return OsCurrProcessGet()->container->ipcContainer;
}
UINT32 OsGetIpcContainerCount(VOID)
{
return g_currentIpcContainerNum;
}
#endif

View File

@@ -28,6 +28,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef LOSCFG_MNT_CONTAINER
#include <unistd.h>
#include "los_mnt_container_pri.h"
#include "los_container_pri.h"
@@ -36,7 +37,6 @@
#include "vnode.h"
#include "internal.h"
#ifdef LOSCFG_MNT_CONTAINER
STATIC UINT32 g_currentMntContainerNum;
LIST_HEAD *GetContainerMntList(VOID)
@@ -124,6 +124,10 @@ UINT32 OsCopyMntContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
return LOS_OK;
}
if (OsContainerLimitCheck(MNT_CONTAINER, &g_currentMntContainerNum) != LOS_OK) {
return EPERM;
}
ret = CreateMntContainer(child, parent);
if (ret != LOS_OK) {
return ret;
@@ -141,10 +145,15 @@ UINT32 OsUnshareMntContainer(UINTPTR flags, LosProcessCB *curr, Container *newCo
if (!(flags & CLONE_NEWNS)) {
SCHEDULER_LOCK(intSave);
newContainer->mntContainer = parentContainer;
LOS_AtomicInc(&parentContainer->rc);
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
if (OsContainerLimitCheck(MNT_CONTAINER, &g_currentMntContainerNum) != LOS_OK) {
return EPERM;
}
MntContainer *mntContainer = CreateNewMntContainer(parentContainer);
if (mntContainer == NULL) {
return ENOMEM;
@@ -163,6 +172,19 @@ UINT32 OsUnshareMntContainer(UINTPTR flags, LosProcessCB *curr, Container *newCo
return LOS_OK;
}
UINT32 OsSetNsMntContainer(UINT32 flags, Container *container, Container *newContainer)
{
if (flags & CLONE_NEWNS) {
newContainer->mntContainer = container->mntContainer;
LOS_AtomicInc(&container->mntContainer->rc);
return LOS_OK;
}
newContainer->mntContainer = OsCurrProcessGet()->container->mntContainer;
LOS_AtomicInc(&newContainer->mntContainer->rc);
return LOS_OK;
}
STATIC VOID FreeMountList(LIST_HEAD *mountList)
{
struct Mount *mnt = NULL;
@@ -223,4 +245,9 @@ UINT32 OsGetMntContainerID(MntContainer *mntContainer)
return mntContainer->containerID;
}
UINT32 OsGetMntContainerCount(VOID)
{
return g_currentMntContainerNum;
}
#endif

View File

@@ -0,0 +1,344 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef LOSCFG_NET_CONTAINER
#include <sched.h>
#include "los_net_container_pri.h"
#include "los_config.h"
#include "los_memory.h"
#include "los_process_pri.h"
STATIC UINT32 g_currentNetContainerNum = 0;
STATIC NetContainer *g_rootNetContainer = NULL;
STATIC struct netif *NetifAlloc(VOID)
{
UINT32 size = sizeof(struct netif);
struct netif *netif = LOS_MemAlloc(m_aucSysMem1, size);
if (netif == NULL) {
return NULL;
}
(VOID)memset_s(netif, size, 0, size);
return netif;
}
STATIC VOID FreeNetif(struct netif *netif)
{
if (netif != NULL) {
if (netif->peer != NULL) {
netif_remove(netif->peer);
(VOID)LOS_MemFree(m_aucSysMem1, netif->peer);
}
netif_remove(netif);
(VOID)LOS_MemFree(m_aucSysMem1, netif);
}
}
STATIC UINT32 CreateVethNetif(NetContainer *netContainer, struct netif **veth)
{
struct netif *netif = NetifAlloc();
if (netif == NULL) {
return ENOMEM;
}
veth_init(netif, netContainer->group);
*veth = netif;
return LOS_OK;
}
STATIC UINT32 InitVethPair(NetContainer *netContainer)
{
struct netif *vethOfNetContainer = NULL;
struct netif *vethOfRootNetContainer = NULL;
UINT32 ret = CreateVethNetif(netContainer, &vethOfNetContainer);
if (ret != LOS_OK) {
return ret;
}
ret = CreateVethNetif(g_rootNetContainer, &vethOfRootNetContainer);
if (ret != LOS_OK) {
FreeNetif(vethOfNetContainer);
return ret;
}
vethOfNetContainer->peer = vethOfRootNetContainer;
vethOfRootNetContainer->peer = vethOfNetContainer;
return LOS_OK;
}
STATIC UINT32 InitLoopNetif(NetContainer *netContainer)
{
struct netif *loop_netif = NetifAlloc();
if (loop_netif == NULL) {
return ENOMEM;
}
netContainer->group->loop_netif = loop_netif;
netif_init(netContainer->group);
return LOS_OK;
}
STATIC UINT32 InitContainerNetifs(NetContainer *netContainer)
{
UINT32 ret = InitLoopNetif(netContainer);
if (ret != LOS_OK) {
return ret;
}
return InitVethPair(netContainer);
}
STATIC UINT32 InitNetGroup(NetContainer *netContainer)
{
UINT32 size = sizeof(struct net_group);
struct net_group *group = LOS_MemAlloc(m_aucSysMem1, size);
if (group == NULL) {
return ENOMEM;
}
(VOID)memset_s(group, size, 0, size);
netContainer->group = group;
return LOS_OK;
}
STATIC VOID FreeNetContainerGroup(struct net_group *group)
{
if (group == NULL) {
return;
}
struct netif *freeNetif = group->netif_list;
struct netif *nextNetif = NULL;
while (freeNetif != NULL) {
nextNetif = freeNetif->next;
FreeNetif(freeNetif);
freeNetif = nextNetif;
}
}
VOID OsNetContainerDestroy(Container *container)
{
UINT32 intSave;
if (container == NULL) {
return;
}
SCHEDULER_LOCK(intSave);
NetContainer *netContainer = container->netContainer;
if (netContainer == NULL) {
SCHEDULER_UNLOCK(intSave);
return;
}
LOS_AtomicDec(&netContainer->rc);
if (LOS_AtomicRead(&netContainer->rc) > 0) {
SCHEDULER_UNLOCK(intSave);
return;
}
g_currentNetContainerNum--;
SCHEDULER_UNLOCK(intSave);
FreeNetContainerGroup(netContainer->group);
container->netContainer = NULL;
(VOID)LOS_MemFree(m_aucSysMem1, netContainer->group);
(VOID)LOS_MemFree(m_aucSysMem1, netContainer);
return;
}
STATIC NetContainer *CreateNewNetContainer(NetContainer *parent)
{
NetContainer *netContainer = LOS_MemAlloc(m_aucSysMem1, sizeof(NetContainer));
if (netContainer == NULL) {
return NULL;
}
(VOID)memset_s(netContainer, sizeof(NetContainer), 0, sizeof(NetContainer));
netContainer->containerID = OsAllocContainerID();
if (parent != NULL) {
LOS_AtomicSet(&netContainer->rc, 1);
} else {
LOS_AtomicSet(&netContainer->rc, 3); /* 3: Three system processes */
}
return netContainer;
}
STATIC UINT32 CreateNetContainer(Container *container, NetContainer *parentContainer)
{
UINT32 intSave, ret;
NetContainer *newNetContainer = CreateNewNetContainer(parentContainer);
if (newNetContainer == NULL) {
return ENOMEM;
}
ret = InitNetGroup(newNetContainer);
if (ret != LOS_OK) {
(VOID)LOS_MemFree(m_aucSysMem1, newNetContainer);
return ret;
}
ret = InitContainerNetifs(newNetContainer);
if (ret != LOS_OK) {
(VOID)LOS_MemFree(m_aucSysMem1, newNetContainer->group);
(VOID)LOS_MemFree(m_aucSysMem1, newNetContainer);
return ret;
}
SCHEDULER_LOCK(intSave);
g_currentNetContainerNum++;
container->netContainer = newNetContainer;
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
UINT32 OsCopyNetContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent)
{
UINT32 intSave;
NetContainer *currNetContainer = parent->container->netContainer;
if (!(flags & CLONE_NEWNET)) {
SCHEDULER_LOCK(intSave);
LOS_AtomicInc(&currNetContainer->rc);
child->container->netContainer = currNetContainer;
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
if (OsContainerLimitCheck(NET_CONTAINER, &g_currentNetContainerNum) != LOS_OK) {
return EPERM;
}
return CreateNetContainer(child->container, currNetContainer);
}
UINT32 OsUnshareNetContainer(UINTPTR flags, LosProcessCB *curr, Container *newContainer)
{
UINT32 intSave;
NetContainer *parentContainer = curr->container->netContainer;
if (!(flags & CLONE_NEWNET)) {
SCHEDULER_LOCK(intSave);
newContainer->netContainer = parentContainer;
LOS_AtomicInc(&parentContainer->rc);
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
if (OsContainerLimitCheck(NET_CONTAINER, &g_currentNetContainerNum) != LOS_OK) {
return EPERM;
}
return CreateNetContainer(newContainer, parentContainer);
}
UINT32 OsSetNsNetContainer(UINT32 flags, Container *container, Container *newContainer)
{
if (flags & CLONE_NEWNET) {
newContainer->netContainer = container->netContainer;
LOS_AtomicInc(&container->netContainer->rc);
return LOS_OK;
}
newContainer->netContainer = OsCurrProcessGet()->container->netContainer;
LOS_AtomicInc(&newContainer->netContainer->rc);
return LOS_OK;
}
UINT32 OsGetNetContainerID(NetContainer *netContainer)
{
if (netContainer == NULL) {
return OS_INVALID_VALUE;
}
return netContainer->containerID;
}
STATIC struct net_group *DoGetNetGroupFromCurrProcess(VOID)
{
LosProcessCB *processCB = OsCurrProcessGet();
NetContainer *netContainer = processCB->container->netContainer;
return netContainer->group;
}
STATIC VOID DoSetNetifNetGroup(struct netif *netif, struct net_group *group)
{
netif->group = group;
}
STATIC struct net_group *DoGetNetGroupFromNetif(struct netif *netif)
{
return netif != NULL ? netif->group : NULL;
}
STATIC VOID DoSetIppcbNetGroup(struct ip_pcb *pcb, struct net_group *group)
{
pcb->group = group;
}
STATIC struct net_group *DoGetNetGroupFromIppcb(struct ip_pcb *pcb)
{
return pcb != NULL ? pcb->group : NULL;
}
struct net_group_ops netGroupOps = {
.get_curr_process_net_group = DoGetNetGroupFromCurrProcess,
.set_netif_net_group = DoSetNetifNetGroup,
.get_net_group_from_netif = DoGetNetGroupFromNetif,
.set_ippcb_net_group = DoSetIppcbNetGroup,
.get_net_group_from_ippcb = DoGetNetGroupFromIppcb,
};
UINT32 OsInitRootNetContainer(NetContainer **netContainer)
{
UINT32 intSave;
NetContainer *newNetContainer = CreateNewNetContainer(NULL);
if (newNetContainer == NULL) {
return ENOMEM;
}
newNetContainer->group = get_root_net_group();
set_default_net_group_ops(&netGroupOps);
SCHEDULER_LOCK(intSave);
g_currentNetContainerNum++;
*netContainer = newNetContainer;
g_rootNetContainer = newNetContainer;
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
UINT32 OsGetNetContainerCount(VOID)
{
return g_currentNetContainerNum;
}
#endif

View File

@@ -52,7 +52,18 @@ STATIC VOID FreeVpid(LosProcessCB *processCB)
processVid->vpid = OS_INVALID_VALUE;
LOS_ListTailInsert(&pidContainer->pidFreeList, &processVid->node);
LOS_AtomicDec(&pidContainer->rc);
pidContainer = pidContainer->parent;
PidContainer *parentPidContainer = pidContainer->parent;
if (LOS_AtomicRead(&pidContainer->rc) > 0) {
pidContainer = parentPidContainer;
continue;
}
g_currentPidContainerNum--;
(VOID)LOS_MemFree(m_aucSysMem1, pidContainer->rootPGroup);
(VOID)LOS_MemFree(m_aucSysMem1, pidContainer);
if (pidContainer == processCB->container->pidContainer) {
processCB->container->pidContainer = NULL;
}
pidContainer = parentPidContainer;
}
}
@@ -67,9 +78,9 @@ STATIC ProcessVid *OsGetFreeVpid(PidContainer *pidContainer)
return vpid;
}
UINT32 OsAllocSpecifiedVpidUnsafe(UINT32 vpid, LosProcessCB *processCB, LosProcessCB *parent)
UINT32 OsAllocSpecifiedVpidUnsafe(UINT32 vpid, PidContainer *pidContainer,
LosProcessCB *processCB, LosProcessCB *parent)
{
PidContainer *pidContainer = processCB->container->pidContainer;
if ((pidContainer == NULL) || OS_PID_CHECK_INVALID(vpid)) {
return OS_INVALID_VALUE;
}
@@ -84,14 +95,21 @@ UINT32 OsAllocSpecifiedVpidUnsafe(UINT32 vpid, LosProcessCB *processCB, LosProce
}
processVid->cb = (UINTPTR)processCB;
processVid->realParent = parent;
processCB->processID = vpid;
LOS_ListDelete(&processVid->node);
LOS_AtomicInc(&pidContainer->rc);
if ((vpid == OS_USER_ROOT_PROCESS_ID) && (parent != NULL)) {
ProcessVid *vppidItem = &pidContainer->pidArray[0];
LOS_ListDelete(&vppidItem->node);
vppidItem->cb = (UINTPTR)parent;
if (vpid == OS_USER_ROOT_PROCESS_ID) {
if (parent != NULL) {
ProcessVid *vppidItem = &pidContainer->pidArray[0];
LOS_ListDelete(&vppidItem->node);
vppidItem->cb = (UINTPTR)parent;
}
if (OsCreateProcessGroup(processCB) == NULL) {
return OS_INVALID_VALUE;
}
}
pidContainer = pidContainer->parent;
@@ -110,7 +128,7 @@ UINT32 OsAllocSpecifiedVpidUnsafe(UINT32 vpid, LosProcessCB *processCB, LosProce
return processCB->processID;
}
STATIC UINT32 OsAllocVpid(LosProcessCB *processCB)
STATIC UINT32 OsAllocVpid(LosProcessCB *processCB, LosProcessCB *parent)
{
ProcessVid *oldProcessVid = NULL;
PidContainer *pidContainer = processCB->container->pidContainer;
@@ -127,6 +145,7 @@ STATIC UINT32 OsAllocVpid(LosProcessCB *processCB)
vpid->cb = (UINTPTR)processCB;
if (processCB->processID == OS_INVALID_VALUE) {
processCB->processID = vpid->vid;
vpid->realParent = parent;
} else {
oldProcessVid->vpid = vpid->vid;
}
@@ -158,6 +177,7 @@ VOID OsFreeVtid(LosTaskCB *taskCB)
item->cb = (UINTPTR)g_defaultTaskCB;
vtid = item->vpid;
item->vpid = OS_INVALID_VALUE;
item->realParent = NULL;
LOS_ListTailInsert(&pidContainer->tidFreeList, &item->node);
pidContainer = pidContainer->parent;
}
@@ -205,7 +225,7 @@ VOID OsPidContainerDestroyAllProcess(LosProcessCB *curr)
for (UINT32 index = 2; index < LOSCFG_BASE_CORE_PROCESS_LIMIT; index++) { /* 2: ordinary process */
SCHEDULER_LOCK(intSave);
LosProcessCB *processCB = OS_PCB_FROM_PID(index);
if (OsProcessIsUnused(processCB)) {
if (OsProcessIsUnused(processCB) || (processCB->parentProcess == NULL)) {
SCHEDULER_UNLOCK(intSave);
continue;
}
@@ -272,36 +292,41 @@ STATIC PidContainer *CreateNewPidContainer(PidContainer *parent)
return newPidContainer;
}
VOID OsPidContainerDestroy(LosProcessCB *curr)
VOID OsPidContainerDestroy(Container *container, LosProcessCB *processCB)
{
if (curr->container == NULL) {
if (container == NULL) {
return;
}
PidContainer *pidContainer = curr->container->pidContainer;
PidContainer *pidContainer = container->pidContainer;
if (pidContainer == NULL) {
return;
}
FreeVpid(curr);
if (processCB != NULL) {
FreeVpid(processCB);
}
if (pidContainer != curr->container->pidForChildContainer) {
LOS_AtomicDec(&curr->container->pidForChildContainer->rc);
if (LOS_AtomicRead(&curr->container->pidForChildContainer->rc) <= 0) {
if ((container->pidForChildContainer != NULL) && (pidContainer != container->pidForChildContainer)) {
LOS_AtomicDec(&container->pidForChildContainer->rc);
if (LOS_AtomicRead(&container->pidForChildContainer->rc) <= 0) {
g_currentPidContainerNum--;
(VOID)LOS_MemFree(m_aucSysMem1, curr->container->pidForChildContainer);
curr->container->pidForChildContainer = NULL;
(VOID)LOS_MemFree(m_aucSysMem1, container->pidForChildContainer);
container->pidForChildContainer = NULL;
}
}
if (LOS_AtomicRead(&pidContainer->rc) <= 0) {
if ((container->pidContainer != NULL) && (LOS_AtomicRead(&pidContainer->rc) <= 0)) {
g_currentPidContainerNum--;
curr->container->pidContainer = NULL;
curr->container->pidForChildContainer = NULL;
container->pidContainer = NULL;
container->pidForChildContainer = NULL;
(VOID)LOS_MemFree(m_aucSysMem1, pidContainer->rootPGroup);
(VOID)LOS_MemFree(m_aucSysMem1, pidContainer);
}
OsContainerFree(curr);
if (processCB != NULL) {
OsContainerFree(processCB);
}
}
STATIC UINT32 CreatePidContainer(LosProcessCB *child, LosProcessCB *parent)
@@ -326,7 +351,7 @@ STATIC UINT32 CreatePidContainer(LosProcessCB *child, LosProcessCB *parent)
newPidContainer->referenced = TRUE;
child->container->pidContainer = newPidContainer;
child->container->pidForChildContainer = newPidContainer;
ret = OsAllocSpecifiedVpidUnsafe(OS_USER_ROOT_PROCESS_ID, child, parent);
ret = OsAllocSpecifiedVpidUnsafe(OS_USER_ROOT_PROCESS_ID, newPidContainer, child, parent);
if (ret == OS_INVALID_VALUE) {
g_currentPidContainerNum--;
FreeVpid(child);
@@ -340,20 +365,34 @@ STATIC UINT32 CreatePidContainer(LosProcessCB *child, LosProcessCB *parent)
return LOS_OK;
}
STATIC UINT32 UnshareCreatePidContainer(LosProcessCB *child, LosProcessCB *parent)
STATIC UINT32 AllocVpidFormPidForChildContainer(LosProcessCB *child, LosProcessCB *parent)
{
UINT32 ret;
PidContainer *pidContainer = parent->container->pidForChildContainer;
child->container->pidContainer = pidContainer;
child->container->pidForChildContainer = pidContainer;
if (!pidContainer->referenced) {
pidContainer->referenced = TRUE;
ret = OsAllocSpecifiedVpidUnsafe(OS_USER_ROOT_PROCESS_ID, pidContainer, child, parent);
} else {
ret = OsAllocVpid(child, parent);
if (ret != OS_INVALID_VALUE) {
LosProcessCB *parentProcessCB = (LosProcessCB *)pidContainer->pidArray[OS_USER_ROOT_PROCESS_ID].cb;
child->parentProcess = parentProcessCB;
LOS_ListTailInsert(&parentProcessCB->childrenList, &child->siblingList);
child->pgroup = parentProcessCB->pgroup;
LOS_ListTailInsert(&parentProcessCB->pgroup->processList, &child->subordinateGroupList);
}
}
parent->container->pidForChildContainer->referenced = TRUE;
child->container->pidContainer = parent->container->pidForChildContainer;
child->container->pidForChildContainer = parent->container->pidForChildContainer;
ret = OsAllocSpecifiedVpidUnsafe(OS_USER_ROOT_PROCESS_ID, child, parent);
if (ret == OS_INVALID_VALUE) {
FreeVpid(child);
child->container->pidContainer = NULL;
child->container->pidForChildContainer = NULL;
return ENOSPC;
}
return LOS_OK;
}
@@ -365,12 +404,12 @@ UINT32 OsCopyPidContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
SCHEDULER_LOCK(intSave);
PidContainer *parentPidContainer = parent->container->pidContainer;
PidContainer *parentPidContainerForChild = parent->container->pidForChildContainer;
if ((parentPidContainer == parentPidContainerForChild) || (parentPidContainerForChild->referenced == TRUE)) {
if (parentPidContainer == parentPidContainerForChild) {
/* The current process is not executing unshare */
if (!(flags & CLONE_NEWPID)) {
child->container->pidContainer = parentPidContainer;
child->container->pidForChildContainer = parentPidContainer;
ret = OsAllocVpid(child);
ret = OsAllocVpid(child, parent);
SCHEDULER_UNLOCK(intSave);
if (ret == OS_INVALID_VALUE) {
PRINT_ERR("[%s] alloc vpid failed\n", __FUNCTION__);
@@ -381,13 +420,17 @@ UINT32 OsCopyPidContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
}
SCHEDULER_UNLOCK(intSave);
if (OsContainerLimitCheck(PID_CONTAINER, &g_currentPidContainerNum) != LOS_OK) {
return EPERM;
}
ret = CreatePidContainer(child, parent);
if (ret != LOS_OK) {
return ret;
}
} else {
/* Create the first process after unshare */
ret = UnshareCreatePidContainer(child, parent);
ret = AllocVpidFormPidForChildContainer(child, parent);
SCHEDULER_UNLOCK(intSave);
if (ret != LOS_OK) {
return ret;
@@ -403,28 +446,6 @@ UINT32 OsCopyPidContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
return LOS_OK;
}
VOID UnshareDeInitPidContainer(Container *container)
{
UINT32 intSave;
PidContainer *pidForChildContainer = NULL;
if (container == NULL) {
return;
}
SCHEDULER_LOCK(intSave);
if ((container->pidForChildContainer != NULL) && (container->pidContainer != container->pidForChildContainer)) {
LOS_AtomicDec(&container->pidForChildContainer->rc);
if (LOS_AtomicRead(&container->pidForChildContainer->rc) <= 0) {
g_currentPidContainerNum--;
pidForChildContainer = container->pidForChildContainer;
container->pidForChildContainer = NULL;
container->pidContainer = NULL;
}
}
SCHEDULER_UNLOCK(intSave);
(VOID)LOS_MemFree(m_aucSysMem1, pidForChildContainer);
}
UINT32 OsUnsharePidContainer(UINTPTR flags, LosProcessCB *curr, Container *newContainer)
{
UINT32 intSave;
@@ -439,6 +460,10 @@ UINT32 OsUnsharePidContainer(UINTPTR flags, LosProcessCB *curr, Container *newCo
return LOS_OK;
}
if (OsContainerLimitCheck(PID_CONTAINER, &g_currentPidContainerNum) != LOS_OK) {
return EPERM;
}
PidContainer *pidForChild = CreateNewPidContainer(curr->container->pidContainer);
if (pidForChild == NULL) {
return ENOMEM;
@@ -465,6 +490,25 @@ UINT32 OsUnsharePidContainer(UINTPTR flags, LosProcessCB *curr, Container *newCo
return LOS_OK;
}
UINT32 OsSetNsPidContainer(UINT32 flags, Container *container, Container *newContainer)
{
UINT32 ret = LOS_OK;
LosProcessCB *curr = OsCurrProcessGet();
newContainer->pidContainer = curr->container->pidContainer;
if (flags & CLONE_NEWPID) {
newContainer->pidForChildContainer = container->pidContainer;
LOS_AtomicInc(&container->pidContainer->rc);
return ret;
}
newContainer->pidForChildContainer = curr->container->pidForChildContainer;
if (newContainer->pidContainer != newContainer->pidForChildContainer) {
LOS_AtomicInc(&newContainer->pidForChildContainer->rc);
}
return LOS_OK;
}
UINT32 OsInitRootPidContainer(PidContainer **pidContainer)
{
UINT32 intSave;
@@ -549,6 +593,20 @@ LosTaskCB *OsGetTCBFromVtid(UINT32 vtid)
return (LosTaskCB *)taskVid->cb;
}
BOOL OsPidContainerProcessParentIsRealParent(const LosProcessCB *processCB, const LosProcessCB *curr)
{
if (curr == processCB->parentProcess) {
return FALSE;
}
PidContainer *pidContainer = processCB->container->pidContainer;
ProcessVid *processVid = &pidContainer->pidArray[processCB->processID];
if (processVid->realParent == curr) {
return TRUE;
}
return FALSE;
}
UINT32 OsGetPidContainerID(PidContainer *pidContainer)
{
if (pidContainer == NULL) {
@@ -557,4 +615,9 @@ UINT32 OsGetPidContainerID(PidContainer *pidContainer)
return pidContainer->containerID;
}
UINT32 OsGetPidContainerCount(VOID)
{
return g_currentPidContainerNum;
}
#endif

View File

@@ -96,6 +96,10 @@ UINT32 OsCopyTimeContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *par
return LOS_OK;
}
if (OsContainerLimitCheck(TIME_CONTAINER, &g_currentTimeContainerNum) != LOS_OK) {
return EPERM;
}
return CreateTimeContainer(child, parent);
}
@@ -106,6 +110,7 @@ UINT32 OsUnshareTimeContainer(UINTPTR flags, LosProcessCB *curr, Container *newC
SCHEDULER_LOCK(intSave);
newContainer->timeContainer = curr->container->timeContainer;
newContainer->timeForChildContainer = curr->container->timeForChildContainer;
LOS_AtomicInc(&newContainer->timeContainer->rc);
if (newContainer->timeContainer != newContainer->timeForChildContainer) {
LOS_AtomicInc(&newContainer->timeForChildContainer->rc);
}
@@ -113,6 +118,10 @@ UINT32 OsUnshareTimeContainer(UINTPTR flags, LosProcessCB *curr, Container *newC
return LOS_OK;
}
if (OsContainerLimitCheck(TIME_CONTAINER, &g_currentTimeContainerNum) != LOS_OK) {
return EPERM;
}
TimeContainer *timeForChild = CreateNewTimeContainer(curr->container->timeContainer);
if (timeForChild == NULL) {
return ENOMEM;
@@ -128,65 +137,64 @@ UINT32 OsUnshareTimeContainer(UINTPTR flags, LosProcessCB *curr, Container *newC
(VOID)memcpy_s(&timeForChild->monotonic, sizeof(struct timespec64),
&curr->container->timeContainer->monotonic, sizeof(struct timespec64));
newContainer->timeContainer = curr->container->timeContainer;
LOS_AtomicInc(&newContainer->timeContainer->rc);
newContainer->timeForChildContainer = timeForChild;
g_currentTimeContainerNum++;
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
VOID UnshareDeInitTimeContainer(Container *container)
UINT32 OsSetNsTimeContainer(UINT32 flags, Container *container, Container *newContainer)
{
UINT32 intSave;
TimeContainer *timeForChildContainer = NULL;
if (container == NULL) {
return;
LosProcessCB *curr = OsCurrProcessGet();
if (flags & CLONE_NEWTIME) {
container->timeContainer->frozenOffsets = TRUE;
newContainer->timeContainer = container->timeContainer;
newContainer->timeForChildContainer = container->timeContainer;
LOS_AtomicInc(&container->timeContainer->rc);
return LOS_OK;
}
SCHEDULER_LOCK(intSave);
if ((container->timeForChildContainer != NULL) && (container->timeForChildContainer != container->timeContainer)) {
LOS_AtomicDec(&container->timeForChildContainer->rc);
if (LOS_AtomicRead(&container->timeForChildContainer->rc) <= 0) {
g_currentTimeContainerNum--;
timeForChildContainer = container->timeForChildContainer;
container->timeForChildContainer = NULL;
container->timeContainer = NULL;
}
newContainer->timeContainer = curr->container->timeContainer;
LOS_AtomicInc(&curr->container->timeContainer->rc);
newContainer->timeForChildContainer = curr->container->timeForChildContainer;
if (curr->container->timeContainer != curr->container->timeForChildContainer) {
LOS_AtomicInc(&curr->container->timeForChildContainer->rc);
}
SCHEDULER_UNLOCK(intSave);
(VOID)LOS_MemFree(m_aucSysMem1, timeForChildContainer);
return LOS_OK;
}
VOID OsTimeContainerDestroy(LosProcessCB *curr)
VOID OsTimeContainerDestroy(Container *container)
{
UINT32 intSave;
TimeContainer *timeContainer = NULL;
TimeContainer *timeForChild = NULL;
if (curr->container == NULL) {
if (container == NULL) {
return;
}
SCHEDULER_LOCK(intSave);
if (curr->container->timeContainer == NULL) {
if (container->timeContainer == NULL) {
SCHEDULER_UNLOCK(intSave);
return;
}
if (curr->container->timeContainer != curr->container->timeForChildContainer) {
LOS_AtomicDec(&curr->container->timeForChildContainer->rc);
if (LOS_AtomicRead(&curr->container->timeForChildContainer->rc) <= 0) {
if ((container->timeForChildContainer != NULL) && (container->timeContainer != container->timeForChildContainer)) {
LOS_AtomicDec(&container->timeForChildContainer->rc);
if (LOS_AtomicRead(&container->timeForChildContainer->rc) <= 0) {
g_currentTimeContainerNum--;
timeForChild = curr->container->timeForChildContainer;
curr->container->timeForChildContainer = NULL;
timeForChild = container->timeForChildContainer;
container->timeForChildContainer = NULL;
}
}
LOS_AtomicDec(&curr->container->timeContainer->rc);
if (LOS_AtomicRead(&curr->container->timeContainer->rc) <= 0) {
LOS_AtomicDec(&container->timeContainer->rc);
if (LOS_AtomicRead(&container->timeContainer->rc) <= 0) {
g_currentTimeContainerNum--;
timeContainer = curr->container->timeContainer;
curr->container->timeContainer = NULL;
curr->container->timeForChildContainer = NULL;
timeContainer = container->timeContainer;
container->timeContainer = NULL;
container->timeForChildContainer = NULL;
}
SCHEDULER_UNLOCK(intSave);
(VOID)LOS_MemFree(m_aucSysMem1, timeForChild);
@@ -242,4 +250,9 @@ UINT32 OsSetTimeContainerMonotonic(LosProcessCB *processCB, struct timespec64 *o
timeContainer->monotonic.tv_nsec = offsets->tv_nsec;
return LOS_OK;
}
UINT32 OsGetTimeContainerCount(VOID)
{
return g_currentTimeContainerNum;
}
#endif

View File

@@ -0,0 +1,439 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef LOSCFG_USER_CONTAINER
#include "los_user_container_pri.h"
#include "errno.h"
#include "ctype.h"
#include "los_config.h"
#include "los_memory.h"
#include "proc_fs.h"
#include "user_copy.h"
#include "los_seq_buf.h"
#include "capability_type.h"
#include "capability_api.h"
#include "internal.h"
#define DEFAULT_OVERFLOWUID 65534
#define DEFAULT_OVERFLOWGID 65534
#define LEVEL_MAX 3
#define HEX 16
#define OCT 8
#define DEC 10
UINT32 g_currentUserContainerNum = 0;
UINT32 OsCreateUserContainer(Credentials *newCredentials, UserContainer *parentUserContainer)
{
if (g_currentUserContainerNum >= OsGetContainerLimit(USER_CONTAINER)) {
return EPERM;
}
if ((parentUserContainer != NULL) && (parentUserContainer->level >= LEVEL_MAX)) {
return EINVAL;
}
if ((newCredentials->euid < 0) || (newCredentials->egid < 0)) {
return EINVAL;
}
UserContainer *userContainer = LOS_MemAlloc(m_aucSysMem1, sizeof(UserContainer));
if (userContainer == NULL) {
return ENOMEM;
}
(VOID)memset_s(userContainer, sizeof(UserContainer), 0, sizeof(UserContainer));
g_currentUserContainerNum++;
userContainer->containerID = OsAllocContainerID();
userContainer->parent = parentUserContainer;
newCredentials->userContainer = userContainer;
if (parentUserContainer != NULL) {
LOS_AtomicInc(&parentUserContainer->rc);
LOS_AtomicSet(&userContainer->rc, 1);
userContainer->level = parentUserContainer->level + 1;
userContainer->owner = newCredentials->euid;
userContainer->group = newCredentials->egid;
} else {
LOS_AtomicSet(&userContainer->rc, 3); /* 3: Three system processes */
userContainer->uidMap.extentCount = 1;
userContainer->uidMap.extent[0].count = 4294967295U;
userContainer->gidMap.extentCount = 1;
userContainer->gidMap.extent[0].count = 4294967295U;
}
return LOS_OK;
}
VOID FreeUserContainer(UserContainer *userContainer)
{
UserContainer *parent = NULL;
do {
parent = userContainer->parent;
(VOID)LOS_MemFree(m_aucSysMem1, userContainer);
userContainer->parent = NULL;
userContainer = parent;
g_currentUserContainerNum--;
if (userContainer == NULL) {
break;
}
LOS_AtomicDec(&userContainer->rc);
} while (LOS_AtomicRead(&userContainer->rc) <= 0);
}
STATIC UidGidExtent *MapIdUpBase(UINT32 extents, UidGidMap *map, UINT32 id)
{
UINT32 idx;
UINT32 first;
UINT32 last;
for (idx = 0; idx < extents; idx++) {
first = map->extent[idx].lowerFirst;
last = first + map->extent[idx].count - 1;
if ((id >= first) && (id <= last)) {
return &map->extent[idx];
}
}
return NULL;
}
STATIC UINT32 MapIdUp(UidGidMap *map, UINT32 id)
{
UINT32 extents = map->extentCount;
if (extents > UID_GID_MAP_MAX_EXTENTS) {
return (UINT32)-1;
}
UidGidExtent *extent = MapIdUpBase(extents, map, id);
if (extent != NULL) {
return ((id - extent->lowerFirst) + extent->first);
}
return (UINT32)-1;
}
UINT32 FromKuid(UserContainer *userContainer, UINT32 kuid)
{
return MapIdUp(&userContainer->uidMap, kuid);
}
UINT32 FromKgid(UserContainer *userContainer, UINT32 kgid)
{
return MapIdUp(&userContainer->gidMap, kgid);
}
UINT32 OsFromKuidMunged(UserContainer *userContainer, UINT32 kuid)
{
UINT32 uid = FromKuid(userContainer, kuid);
if (uid == (UINT32)-1) {
uid = DEFAULT_OVERFLOWUID;
}
return uid;
}
UINT32 OsFromKgidMunged(UserContainer *userContainer, UINT32 kgid)
{
UINT32 gid = FromKgid(userContainer, kgid);
if (gid == (UINT32)-1) {
gid = DEFAULT_OVERFLOWGID;
}
return gid;
}
STATIC UidGidExtent *MapIdRangeDownBase(UINT32 extents, UidGidMap *map, UINT32 id, UINT32 count)
{
UINT32 idx;
UINT32 first;
UINT32 last;
UINT32 id2;
id2 = id + count - 1;
for (idx = 0; idx < extents; idx++) {
first = map->extent[idx].first;
last = first + map->extent[idx].count - 1;
if ((id >= first && id <= last) && (id2 >= first && id2 <= last)) {
return &map->extent[idx];
}
}
return NULL;
}
STATIC UINT32 MapIdRangeDown(UidGidMap *map, UINT32 id, UINT32 count)
{
UINT32 extents = map->extentCount;
if (extents > UID_GID_MAP_MAX_EXTENTS) {
return (UINT32)-1;
}
UidGidExtent *extent = MapIdRangeDownBase(extents, map, id, count);
if (extent != NULL) {
return ((id - extent->first) + extent->lowerFirst);
}
return (UINT32)-1;
}
STATIC UINT32 MapIdDown(UidGidMap *map, UINT32 id)
{
return MapIdRangeDown(map, id, 1);
}
UINT32 OsMakeKuid(UserContainer *userContainer, UINT32 uid)
{
return MapIdDown(&userContainer->uidMap, uid);
}
UINT32 OsMakeKgid(UserContainer *userContainer, UINT32 gid)
{
return MapIdDown(&userContainer->gidMap, gid);
}
STATIC INT32 InsertExtent(UidGidMap *idMap, UidGidExtent *extent)
{
if (idMap->extentCount > UID_GID_MAP_MAX_EXTENTS) {
return -EINVAL;
}
UidGidExtent *dest = &idMap->extent[idMap->extentCount];
*dest = *extent;
idMap->extentCount++;
return 0;
}
STATIC BOOL MappingsOverlap(UidGidMap *idMap, UidGidExtent *extent)
{
UINT32 upperFirst = extent->first;
UINT32 lowerFirst = extent->lowerFirst;
UINT32 upperLast = upperFirst + extent->count - 1;
UINT32 lowerLast = lowerFirst + extent->count - 1;
INT32 idx;
for (idx = 0; idx < idMap->extentCount; idx++) {
if (idMap->extentCount > UID_GID_MAP_MAX_EXTENTS) {
return TRUE;
}
UidGidExtent *prev = &idMap->extent[idx];
UINT32 prevUpperFirst = prev->first;
UINT32 prevLowerFirst = prev->lowerFirst;
UINT32 prevUpperLast = prevUpperFirst + prev->count - 1;
UINT32 prevLowerLast = prevLowerFirst + prev->count - 1;
if ((prevUpperFirst <= upperLast) && (prevUpperLast >= upperFirst)) {
return TRUE;
}
if ((prevLowerFirst <= lowerLast) && (prevLowerLast >= lowerFirst)) {
return TRUE;
}
}
return FALSE;
}
STATIC CHAR *SkipSpaces(const CHAR *str)
{
while (isspace(*str)) {
++str;
}
return (CHAR *)str;
}
STATIC UINTPTR StrToUInt(const CHAR *str, CHAR **endp, UINT32 base)
{
unsigned long result = 0;
unsigned long value;
if (*str == '0') {
str++;
if ((*str == 'x') && isxdigit(str[1])) {
base = HEX;
str++;
}
if (!base) {
base = OCT;
}
}
if (!base) {
base = DEC;
}
while (isxdigit(*str) && (value = isdigit(*str) ? *str - '0' : (islower(*str) ?
toupper(*str) : *str) - 'A' + DEC) < base) {
result = result * base + value;
str++;
}
if (endp != NULL) {
*endp = (CHAR *)str;
}
return result;
}
STATIC INT32 ParsePosData(CHAR *pos, UidGidExtent *extent)
{
INT32 ret = -EINVAL;
pos = SkipSpaces(pos);
extent->first = StrToUInt(pos, &pos, DEC);
if (!isspace(*pos)) {
return ret;
}
pos = SkipSpaces(pos);
extent->lowerFirst = StrToUInt(pos, &pos, DEC);
if (!isspace(*pos)) {
return ret;
}
pos = SkipSpaces(pos);
extent->count = StrToUInt(pos, &pos, DEC);
if (*pos && !isspace(*pos)) {
return ret;
}
pos = SkipSpaces(pos);
if (*pos != '\0') {
return ret;
}
return LOS_OK;
}
STATIC INT32 ParseUserData(CHAR *kbuf, UidGidExtent *extent, UidGidMap *newMap)
{
INT32 ret = -EINVAL;
CHAR *pos = NULL;
CHAR *nextLine = NULL;
for (pos = kbuf; pos != NULL; pos = nextLine) {
nextLine = strchr(pos, '\n');
if (nextLine != NULL) {
*nextLine = '\0';
nextLine++;
if (*nextLine == '\0') {
nextLine = NULL;
}
}
if (ParsePosData(pos, extent) != LOS_OK) {
return ret;
}
if ((extent->first == (UINT32)-1) || (extent->lowerFirst == (UINT32)-1)) {
return ret;
}
if ((extent->first + extent->count) <= extent->first) {
return ret;
}
if ((extent->lowerFirst + extent->count) <= extent->lowerFirst) {
return ret;
}
if (MappingsOverlap(newMap, extent)) {
return ret;
}
if ((newMap->extentCount + 1) == UID_GID_MAP_MAX_EXTENTS && (nextLine != NULL)) {
return ret;
}
ret = InsertExtent(newMap, extent);
if (ret < 0) {
return ret;
}
ret = 0;
}
if (newMap->extentCount == 0) {
return -EINVAL;
}
return ret;
}
STATIC INT32 ParentMapIdRange(UidGidMap *newMap, UidGidMap *parentMap)
{
UINT32 idx;
INT32 ret = -EPERM;
for (idx = 0; idx < newMap->extentCount; idx++) {
if (newMap->extentCount > UID_GID_MAP_MAX_EXTENTS) {
return ret;
}
UidGidExtent *extent = &newMap->extent[idx];
UINT32 lowerFirst = MapIdRangeDown(parentMap, extent->lowerFirst, extent->count);
if (lowerFirst == (UINT32) -1) {
return ret;
}
extent->lowerFirst = lowerFirst;
}
return 0;
}
INT32 OsUserContainerMapWrite(struct ProcFile *fp, CHAR *kbuf, size_t count,
INT32 capSetid, UidGidMap *map, UidGidMap *parentMap)
{
UidGidMap newMap = {0};
UidGidExtent extent;
INT32 ret;
if (map->extentCount != 0) {
return -EPERM;
}
if (!IsCapPermit(capSetid)) {
return -EPERM;
}
ret = ParseUserData(kbuf, &extent, &newMap);
if (ret < 0) {
return -EPERM;
}
ret = ParentMapIdRange(&newMap, parentMap);
if (ret < 0) {
return -EPERM;
}
if (newMap.extentCount <= UID_GID_MAP_MAX_EXTENTS) {
size_t mapSize = newMap.extentCount * sizeof(newMap.extent[0]);
ret = memcpy_s(map->extent, sizeof(map->extent), newMap.extent, mapSize);
if (ret != EOK) {
return -EPERM;
}
}
map->extentCount = newMap.extentCount;
return count;
}
UINT32 OsGetUserContainerCount(VOID)
{
return g_currentUserContainerNum;
}
#endif

View File

@@ -28,12 +28,11 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef LOSCFG_UTS_CONTAINER
#include "internal.h"
#include "los_uts_container_pri.h"
#include "los_process_pri.h"
#ifdef LOSCFG_UTS_CONTAINER
STATIC UINT32 g_currentUtsContainerNum;
STATIC UINT32 InitUtsContainer(struct utsname *name)
@@ -135,6 +134,10 @@ UINT32 OsCopyUtsContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
return LOS_OK;
}
if (OsContainerLimitCheck(UTS_CONTAINER, &g_currentUtsContainerNum) != LOS_OK) {
return EPERM;
}
return CreateUtsContainer(child, parent);
}
@@ -146,10 +149,15 @@ UINT32 OsUnshareUtsContainer(UINTPTR flags, LosProcessCB *curr, Container *newCo
if (!(flags & CLONE_NEWUTS)) {
SCHEDULER_LOCK(intSave);
newContainer->utsContainer = parentContainer;
LOS_AtomicInc(&parentContainer->rc);
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
if (OsContainerLimitCheck(UTS_CONTAINER, &g_currentUtsContainerNum) != LOS_OK) {
return EPERM;
}
UtsContainer *utsContainer = CreateNewUtsContainer(parentContainer);
if (utsContainer == NULL) {
return ENOMEM;
@@ -164,6 +172,19 @@ UINT32 OsUnshareUtsContainer(UINTPTR flags, LosProcessCB *curr, Container *newCo
return LOS_OK;
}
UINT32 OsSetNsUtsContainer(UINT32 flags, Container *container, Container *newContainer)
{
if (flags & CLONE_NEWUTS) {
newContainer->utsContainer = container->utsContainer;
LOS_AtomicInc(&container->utsContainer->rc);
return LOS_OK;
}
newContainer->utsContainer = OsCurrProcessGet()->container->utsContainer;
LOS_AtomicInc(&newContainer->utsContainer->rc);
return LOS_OK;
}
VOID OsUtsContainerDestroy(Container *container)
{
UINT32 intSave;
@@ -212,4 +233,8 @@ UINT32 OsGetUtsContainerID(UtsContainer *utsContainer)
return utsContainer->containerID;
}
UINT32 OsGetUtsContainerCount(VOID)
{
return g_currentUtsContainerNum;
}
#endif

View File

@@ -33,7 +33,7 @@ module_switch = defined(LOSCFG_BASE_CORE_HILOG)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"//base/hiviewdfx/hilog_lite/frameworks/featured/hiview_log.c",
"$HIVIEWDFX_HILOG_LITE_DIR/frameworks/featured/hiview_log.c",
"los_hilog.c",
]
@@ -42,8 +42,8 @@ kernel_module(module_name) {
config("public") {
include_dirs = [
"//base/hiviewdfx/hilog_lite/interfaces/native/kits",
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog",
"$HIVIEWDFX_HILOG_LITE_DIR/interfaces/native/kits",
"$HIVIEWDFX_HILOG_LITE_DIR/interfaces/native/kits/hilog",
".",
]
}

View File

@@ -1094,7 +1094,7 @@ ERROR_COPY:
return ret;
}
LITE_OS_SEC_TEXT STATIC UINT32 CheckRecievedMsg(IpcListNode *node, IpcContent *content, LosTaskCB *tcb)
LITE_OS_SEC_TEXT STATIC UINT32 CheckReceivedMsg(IpcListNode *node, IpcContent *content, LosTaskCB *tcb)
{
UINT32 ret = LOS_OK;
if (node == NULL) {
@@ -1184,7 +1184,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 LiteIpcRead(IpcContent *content)
LOS_ListDelete(listNode);
node = LOS_DL_LIST_ENTRY(listNode, IpcListNode, listNode);
SCHEDULER_UNLOCK(intSave);
ret = CheckRecievedMsg(node, content, tcb);
ret = CheckReceivedMsg(node, content, tcb);
if (ret == LOS_OK) {
break;
}

View File

@@ -28,7 +28,7 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
import("//third_party/NuttX/NuttX.gni")
import("$THIRDPARTY_NUTTX_DIR/NuttX.gni")
module_switch = defined(LOSCFG_KERNEL_PIPE)
module_name = get_path_info(rebase_path("."), "name")

View File

@@ -0,0 +1,46 @@
# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
module_switch = true
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"los_devicelimit.c",
"los_ipclimit.c",
"los_memlimit.c",
"los_plimits.c",
"los_processlimit.c",
"los_schedlimit.c",
]
}
config("public") {
include_dirs = [ "." ]
}

View File

@@ -0,0 +1,35 @@
# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
include $(LITEOSTOPDIR)/config.mk
MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard *.c)
include $(MODULE)

View File

@@ -0,0 +1,605 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
#include "los_seq_buf.h"
#include "los_bitmap.h"
#include "los_process_pri.h"
#include "los_devicelimit.h"
#define TYPE_CHAR_LEN (1)
#define DEVICE_NAME_PREFIX_SPACE (1)
#define DEVICE_ACCESS_MAXLEN (3)
#define BUF_SEPARATOR (5)
STATIC ProcDevLimit *g_procDevLimit = NULL;
VOID OsDevLimitInit(UINTPTR limit)
{
ProcDevLimit *deviceLimit = (ProcDevLimit *)limit;
deviceLimit->behavior = DEVLIMIT_DEFAULT_ALLOW;
LOS_ListInit(&(deviceLimit->accessList));
g_procDevLimit = deviceLimit;
}
VOID *OsDevLimitAlloc(VOID)
{
ProcDevLimit *plimit = (ProcDevLimit *)LOS_MemAlloc(m_aucSysMem1, sizeof(ProcDevLimit));
if (plimit == NULL) {
return NULL;
}
(VOID)memset_s(plimit, sizeof(ProcDevLimit), 0, sizeof(ProcDevLimit));
LOS_ListInit(&(plimit->accessList));
plimit->behavior = DEVLIMIT_DEFAULT_NONE;
return (VOID *)plimit;
}
STATIC VOID DevAccessListDelete(ProcDevLimit *devLimit)
{
DevAccessItem *delItem = NULL;
DevAccessItem *tmpItem = NULL;
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(delItem, tmpItem, &devLimit->accessList, DevAccessItem, list) {
LOS_ListDelete(&delItem->list);
(VOID)LOS_MemFree(m_aucSysMem1, (VOID *)delItem);
}
}
VOID OsDevLimitFree(UINTPTR limit)
{
ProcDevLimit *devLimit = (ProcDevLimit *)limit;
if (devLimit == NULL) {
return;
}
DevAccessListDelete(devLimit);
(VOID)LOS_MemFree(m_aucSysMem1, devLimit);
}
STATIC UINT32 DevLimitCopyAccess(ProcDevLimit *devLimitDest, ProcDevLimit *devLimitSrc)
{
DevAccessItem *tmpItem = NULL;
INT32 itemSize = sizeof(DevAccessItem);
devLimitDest->behavior = devLimitSrc->behavior;
LOS_DL_LIST_FOR_EACH_ENTRY(tmpItem, &devLimitSrc->accessList, DevAccessItem, list) {
DevAccessItem *newItem = (DevAccessItem *)LOS_MemAlloc(m_aucSysMem1, itemSize);
if (newItem == NULL) {
return ENOMEM;
}
(VOID)memcpy_s(newItem, sizeof(DevAccessItem), tmpItem, sizeof(DevAccessItem));
LOS_ListTailInsert(&devLimitDest->accessList, &newItem->list);
}
return LOS_OK;
}
VOID OsDevLimitCopy(UINTPTR dest, UINTPTR src)
{
ProcDevLimit *devLimitDest = (ProcDevLimit *)dest;
ProcDevLimit *devLimitSrc = (ProcDevLimit *)src;
(VOID)DevLimitCopyAccess(devLimitDest, devLimitSrc);
devLimitDest->parent = (ProcDevLimit *)src;
}
STATIC INLINE INT32 IsSpace(INT32 c)
{
return (c == ' ' || (unsigned)c - '\t' < BUF_SEPARATOR);
}
STATIC UINT32 ParseItemAccess(const CHAR *buf, DevAccessItem *item)
{
switch (*buf) {
case 'a':
item->type = DEVLIMIT_DEV_ALL;
return LOS_OK;
case 'b':
item->type = DEVLIMIT_DEV_BLOCK;
break;
case 'c':
item->type = DEVLIMIT_DEV_CHAR;
break;
default:
return EINVAL;
}
buf += DEVICE_NAME_PREFIX_SPACE;
if (!IsSpace(*buf)) {
return EINVAL;
}
buf += DEVICE_NAME_PREFIX_SPACE;
for (INT32 count = 0; count < sizeof(item->name) - 1; count++) {
if (IsSpace(*buf)) {
break;
}
item->name[count] = *buf;
buf += TYPE_CHAR_LEN;
}
if (!IsSpace(*buf)) {
return EINVAL;
}
buf += DEVICE_NAME_PREFIX_SPACE;
for (INT32 i = 0; i < DEVICE_ACCESS_MAXLEN; i++) {
switch (*buf) {
case 'r':
item->access |= DEVLIMIT_ACC_READ;
break;
case 'w':
item->access |= DEVLIMIT_ACC_WRITE;
break;
case 'm':
item->access |= DEVLIMIT_ACC_MKNOD;
break;
case '\n':
case '\0':
i = DEVICE_ACCESS_MAXLEN;
break;
default:
return EINVAL;
}
buf += TYPE_CHAR_LEN;
}
return LOS_OK;
}
STATIC BOOL DevLimitMayAllowAll(ProcDevLimit *parent)
{
if (parent == NULL) {
return TRUE;
}
return (parent->behavior == DEVLIMIT_DEFAULT_ALLOW);
}
STATIC BOOL DevLimitHasChildren(ProcLimitSet *procLimitSet, ProcDevLimit *devLimit)
{
ProcLimitSet *parent = procLimitSet;
ProcLimitSet *childProcLimitSet = NULL;
if (devLimit == NULL) {
return FALSE;
}
LOS_DL_LIST_FOR_EACH_ENTRY(childProcLimitSet, &(procLimitSet->childList), ProcLimitSet, childList) {
if (childProcLimitSet == NULL) {
continue;
}
if (childProcLimitSet->parent != parent) {
continue;
}
if (!((childProcLimitSet->mask) & BIT(PROCESS_LIMITER_ID_DEV))) {
continue;
}
return TRUE;
}
return FALSE;
}
STATIC UINT32 DealItemAllAccess(ProcLimitSet *procLimitSet, ProcDevLimit *devLimit,
ProcDevLimit *devParentLimit, INT32 filetype)
{
switch (filetype) {
case DEVLIMIT_ALLOW: {
if (DevLimitHasChildren(procLimitSet, devLimit)) {
return EINVAL;
}
if (!DevLimitMayAllowAll(devParentLimit)) {
return EPERM;
}
DevAccessListDelete(devLimit);
devLimit->behavior = DEVLIMIT_DEFAULT_ALLOW;
if (devParentLimit == NULL) {
break;
}
DevLimitCopyAccess(devLimit, devParentLimit);
break;
}
case DEVLIMIT_DENY: {
if (DevLimitHasChildren(procLimitSet, devLimit)) {
return EINVAL;
}
DevAccessListDelete(devLimit);
devLimit->behavior = DEVLIMIT_DEFAULT_DENY;
break;
}
default:
return EINVAL;
}
return LOS_OK;
}
STATIC BOOL DevLimitMatchItemPartial(LOS_DL_LIST *list, DevAccessItem *item)
{
if ((list == NULL) || (item == NULL)) {
return FALSE;
}
if (LOS_ListEmpty(list)) {
return FALSE;
}
DevAccessItem *walk = NULL;
LOS_DL_LIST_FOR_EACH_ENTRY(walk, list, DevAccessItem, list) {
if (item->type != walk->type) {
continue;
}
if ((strcmp(walk->name, "*") != 0) && (strcmp(item->name, "*") != 0)
&& (strcmp(walk->name, item->name) != 0)) {
continue;
}
if (!(item->access & ~(walk->access))) {
return TRUE;
}
}
return FALSE;
}
STATIC BOOL DevLimitParentAllowsRmItem(ProcDevLimit *devParentLimit, DevAccessItem *item)
{
if (devParentLimit == NULL) {
return TRUE;
}
/* Make sure you're not removing part or a whole item existing in the parent plimits */
return !DevLimitMatchItemPartial(&devParentLimit->accessList, item);
}
STATIC BOOL DevLimitMatchItem(LOS_DL_LIST *list, DevAccessItem *item)
{
if ((list == NULL) || (item == NULL)) {
return FALSE;
}
if (LOS_ListEmpty(list)) {
return FALSE;
}
DevAccessItem *walk = NULL;
LOS_DL_LIST_FOR_EACH_ENTRY(walk, list, DevAccessItem, list) {
if (item->type != walk->type) {
continue;
}
if ((strcmp(walk->name, "*") != 0) && (strcmp(walk->name, item->name) != 0)) {
continue;
}
if (!(item->access & ~(walk->access))) {
return TRUE;
}
}
return FALSE;
}
/**
* This is used to make sure a child plimits won't have more privileges than its parent
*/
STATIC BOOL DevLimitVerifyNewItem(ProcDevLimit *parent, DevAccessItem *item, INT32 currBehavior)
{
if (parent == NULL) {
return TRUE;
}
if (parent->behavior == DEVLIMIT_DEFAULT_ALLOW) {
if (currBehavior == DEVLIMIT_DEFAULT_ALLOW) {
return TRUE;
}
return !DevLimitMatchItemPartial(&parent->accessList, item);
}
return DevLimitMatchItem(&parent->accessList, item);
}
STATIC BOOL DevLimitParentAllowsAddItem(ProcDevLimit *devParentLimit, DevAccessItem *item, INT32 currBehavior)
{
return DevLimitVerifyNewItem(devParentLimit, item, currBehavior);
}
STATIC VOID DevLimitAccessListRm(ProcDevLimit *devLimit, DevAccessItem *item)
{
if ((item == NULL) || (devLimit == NULL)) {
return;
}
DevAccessItem *walk, *tmp = NULL;
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(walk, tmp, &devLimit->accessList, DevAccessItem, list) {
if (walk->type != item->type) {
continue;
}
if (strcmp(walk->name, item->name) != 0) {
continue;
}
walk->access &= ~item->access;
if (!walk->access) {
LOS_ListDelete(&walk->list);
(VOID)LOS_MemFree(m_aucSysMem1, (VOID *)walk);
}
}
}
STATIC UINT32 DevLimitAccessListAdd(ProcDevLimit *devLimit, DevAccessItem *item)
{
if ((item == NULL) || (devLimit == NULL)) {
return ENOMEM;
}
DevAccessItem *walk = NULL;
DevAccessItem *newItem = (DevAccessItem *)LOS_MemAlloc(m_aucSysMem1, sizeof(DevAccessItem));
if (newItem == NULL) {
return ENOMEM;
}
(VOID)memcpy_s(newItem, sizeof(DevAccessItem), item, sizeof(DevAccessItem));
LOS_DL_LIST_FOR_EACH_ENTRY(walk, &devLimit->accessList, DevAccessItem, list) {
if (walk->type != item->type) {
continue;
}
if (strcmp(walk->name, item->name) != 0) {
continue;
}
walk->access |= item->access;
(VOID)LOS_MemFree(m_aucSysMem1, (VOID *)newItem);
newItem = NULL;
}
if (newItem != NULL) {
LOS_ListTailInsert(&devLimit->accessList, &newItem->list);
}
return LOS_OK;
}
/**
* Revalidate permissions
*/
STATIC VOID DevLimitRevalidateActiveItems(ProcDevLimit *devLimit, ProcDevLimit *devParentLimit)
{
if ((devLimit == NULL) || (devParentLimit == NULL)) {
return;
}
DevAccessItem *walK = NULL;
DevAccessItem *tmp = NULL;
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(walK, tmp, &devLimit->accessList, DevAccessItem, list) {
if (!DevLimitParentAllowsAddItem(devParentLimit, walK, devLimit->behavior)) {
DevLimitAccessListRm(devLimit, walK);
}
}
}
/**
* propagates a new item to the children
*/
STATIC UINT32 DevLimitPropagateItem(ProcLimitSet *procLimitSet, ProcDevLimit *devLimit, DevAccessItem *item)
{
UINT32 ret = LOS_OK;
ProcLimitSet *parent = procLimitSet;
ProcLimitSet *childProcLimitSet = NULL;
if ((procLimitSet == NULL) || (item == NULL)) {
return ENOMEM;
}
if (devLimit == NULL) {
return LOS_OK;
}
LOS_DL_LIST_FOR_EACH_ENTRY(childProcLimitSet, &procLimitSet->childList, ProcLimitSet, childList) {
if (childProcLimitSet == NULL) {
continue;
}
if (childProcLimitSet->parent != parent) {
continue;
}
if (!((childProcLimitSet->mask) & BIT(PROCESS_LIMITER_ID_DEV))) {
continue;
}
ProcDevLimit *devLimitChild = (ProcDevLimit *)childProcLimitSet->limitsList[PROCESS_LIMITER_ID_DEV];
if (devLimit->behavior == DEVLIMIT_DEFAULT_ALLOW &&
devLimitChild->behavior == DEVLIMIT_DEFAULT_ALLOW) {
ret = DevLimitAccessListAdd(devLimitChild, item);
} else {
DevLimitAccessListRm(devLimitChild, item);
}
DevLimitRevalidateActiveItems(devLimitChild, (ProcDevLimit *)parent->limitsList[PROCESS_LIMITER_ID_DEV]);
}
return ret;
}
STATIC UINT32 DevLimitUpdateAccess(ProcLimitSet *procLimitSet, const CHAR *buf, INT32 filetype)
{
UINT32 ret;
UINT32 intSave;
DevAccessItem item = {0};
SCHEDULER_LOCK(intSave);
ProcDevLimit *devLimit = (ProcDevLimit *)(procLimitSet->limitsList[PROCESS_LIMITER_ID_DEV]);
ProcDevLimit *devParentLimit = devLimit->parent;
ret = ParseItemAccess(buf, &item);
if (ret != LOS_OK) {
SCHEDULER_UNLOCK(intSave);
return ret;
}
if (item.type == DEVLIMIT_DEV_ALL) {
ret = DealItemAllAccess(procLimitSet, devLimit, devParentLimit, filetype);
SCHEDULER_UNLOCK(intSave);
return ret;
}
switch (filetype) {
case DEVLIMIT_ALLOW: {
if (devLimit->behavior == DEVLIMIT_DEFAULT_ALLOW) {
if (!DevLimitParentAllowsRmItem(devParentLimit, &item)) {
SCHEDULER_UNLOCK(intSave);
return EPERM;
}
DevLimitAccessListRm(devLimit, &item);
break;
}
if (!DevLimitParentAllowsAddItem(devParentLimit, &item, devLimit->behavior)) {
SCHEDULER_UNLOCK(intSave);
return EPERM;
}
ret = DevLimitAccessListAdd(devLimit, &item);
break;
}
case DEVLIMIT_DENY: {
if (devLimit->behavior == DEVLIMIT_DEFAULT_DENY) {
DevLimitAccessListRm(devLimit, &item);
} else {
ret = DevLimitAccessListAdd(devLimit, &item);
}
// update child access list
ret = DevLimitPropagateItem(procLimitSet, devLimit, &item);
break;
}
default:
ret = EINVAL;
break;
}
SCHEDULER_UNLOCK(intSave);
return ret;
}
UINT32 OsDevLimitWriteAllow(ProcLimitSet *plimit, const CHAR *buf, UINT32 size)
{
(VOID)size;
return DevLimitUpdateAccess(plimit, buf, DEVLIMIT_ALLOW);
}
UINT32 OsDevLimitWriteDeny(ProcLimitSet *plimit, const CHAR *buf, UINT32 size)
{
(VOID)size;
return DevLimitUpdateAccess(plimit, buf, DEVLIMIT_DENY);
}
STATIC VOID DevLimitItemSetAccess(CHAR *accArray, INT16 access)
{
INT32 index = 0;
(VOID)memset_s(acc, ACCLEN, 0, ACCLEN);
if (access & DEVLIMIT_ACC_READ) {
accArray[index] = 'r';
index++;
}
if (access & DEVLIMIT_ACC_WRITE) {
accArray[index] = 'w';
index++;
}
if (access & DEVLIMIT_ACC_MKNOD) {
accArray[index] = 'm';
index++;
}
}
STATIC CHAR DevLimitItemTypeToChar(INT16 type)
{
switch (type) {
case DEVLIMIT_DEV_ALL:
return 'a';
case DEVLIMIT_DEV_CHAR:
return 'c';
case DEVLIMIT_DEV_BLOCK:
return 'b';
default:
break;
}
return 'X';
}
UINT32 OsDevLimitShow(ProcDevLimit *devLimit, struct SeqBuf *seqBuf)
{
DevAccessItem *item = NULL;
CHAR acc[ACCLEN];
UINT32 intSave;
if ((devLimit == NULL) || (seqBuf == NULL)) {
return EINVAL;
}
SCHEDULER_LOCK(intSave);
if (devLimit->behavior == DEVLIMIT_DEFAULT_ALLOW) {
DevLimitItemSetAccess(acc, DEVLIMIT_ACC_MASK);
SCHEDULER_UNLOCK(intSave);
LosBufPrintf(seqBuf, "%c %s %s\n", DevLimitItemTypeToChar(DEVLIMIT_DEV_ALL), "*", acc);
return LOS_OK;
}
LOS_DL_LIST_FOR_EACH_ENTRY(item, &devLimit->accessList, DevAccessItem, list) {
DevLimitItemSetAccess(acc, item->access);
LosBufPrintf(seqBuf, "%c %s %s\n", DevLimitItemTypeToChar(item->type), item->name, acc);
}
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
STATIC INLINE INT16 ConversionDevType(INT32 vnodeType)
{
INT16 type = 0;
if (vnodeType == VNODE_TYPE_BLK) {
type = DEVLIMIT_DEV_BLOCK;
} else if (vnodeType == VNODE_TYPE_CHR) {
type = DEVLIMIT_DEV_CHAR;
}
return type;
}
STATIC INLINE INT16 ConversionDevAccess(INT32 flags)
{
INT16 access = 0;
if ((flags & O_ACCMODE) == O_RDONLY) {
access |= DEVLIMIT_ACC_READ;
}
if (flags & O_WRONLY) {
access |= DEVLIMIT_ACC_WRITE;
}
if (flags & O_RDWR) {
access |= DEVLIMIT_ACC_WRITE | DEVLIMIT_ACC_READ;
}
if (flags & O_CREAT) {
access |= DEVLIMIT_ACC_MKNOD;
}
return access;
}
UINT32 OsDevLimitCheckPermission(INT32 vnodeType, const CHAR *pathName, INT32 flags)
{
BOOL matched = FALSE;
DevAccessItem item = {0};
LosProcessCB *run = OsCurrProcessGet();
if ((run == NULL) || (run->plimits == NULL)) {
return LOS_OK;
}
if (pathName == NULL) {
return EINVAL;
}
ProcDevLimit *devLimit = (ProcDevLimit *)run->plimits->limitsList[PROCESS_LIMITER_ID_DEV];
item.type = ConversionDevType(vnodeType);
item.access = ConversionDevAccess(flags);
LOS_ListInit(&(item.list));
(VOID)strncpy_s(item.name, PATH_MAX, pathName, PATH_MAX);
if (devLimit->behavior == DEVLIMIT_DEFAULT_ALLOW) {
matched = !DevLimitMatchItemPartial(&devLimit->accessList, &item);
} else {
matched = DevLimitMatchItem(&devLimit->accessList, &item);
}
if (!matched) {
return EPERM;
}
return LOS_OK;
}
#endif

View File

@@ -0,0 +1,96 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_DEVICELIMIT_H
#define _LOS_DEVICELIMIT_H
#include "los_typedef.h"
#include "los_list.h"
#include "vfs_config.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define DEVLIMIT_ACC_MKNOD 1
#define DEVLIMIT_ACC_READ 2
#define DEVLIMIT_ACC_WRITE 4
#define DEVLIMIT_ACC_MASK (DEVLIMIT_ACC_MKNOD | DEVLIMIT_ACC_READ | DEVLIMIT_ACC_WRITE)
#define DEVLIMIT_DEV_BLOCK 1
#define DEVLIMIT_DEV_CHAR 2
#define DEVLIMIT_DEV_ALL 4 /* all devices */
#define DEVLIMIT_ALLOW 1
#define DEVLIMIT_DENY 2
#define ACCLEN 4
struct SeqBuf;
typedef struct TagPLimiterSet ProcLimitSet;
enum DevLimitBehavior {
DEVLIMIT_DEFAULT_NONE,
DEVLIMIT_DEFAULT_ALLOW,
DEVLIMIT_DEFAULT_DENY,
};
typedef struct DevAccessItem {
INT16 type;
INT16 access;
LOS_DL_LIST list;
CHAR name[PATH_MAX];
} DevAccessItem;
typedef struct ProcDevLimit {
struct ProcDevLimit *parent;
UINT8 allowFile;
UINT8 denyFile;
LOS_DL_LIST accessList; // device belong to devicelimite
enum DevLimitBehavior behavior;
} ProcDevLimit;
VOID OsDevLimitInit(UINTPTR limit);
VOID *OsDevLimitAlloc(VOID);
VOID OsDevLimitFree(UINTPTR limit);
VOID OsDevLimitCopy(UINTPTR dest, UINTPTR src);
UINT32 OsDevLimitWriteAllow(ProcLimitSet *plimit, const CHAR *buf, UINT32 size);
UINT32 OsDevLimitWriteDeny(ProcLimitSet *plimit, const CHAR *buf, UINT32 size);
UINT32 OsDevLimitShow(ProcDevLimit *devLimit, struct SeqBuf *seqBuf);
UINT32 OsDevLimitCheckPermission(INT32 vnodeType, const CHAR *pathName, INT32 flags);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_DEVICELIMIT_H */

View File

@@ -0,0 +1,249 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
#include "los_ipclimit.h"
#include "los_process_pri.h"
STATIC ProcIPCLimit *g_rootIPCLimit = NULL;
#define PLIMIT_IPC_SHM_LIMIT_MAX 0xFFFFFFFF
VOID OsIPCLimitInit(UINTPTR limite)
{
ProcIPCLimit *plimite = (ProcIPCLimit *)limite;
plimite->mqCountLimit = LOSCFG_BASE_IPC_QUEUE_LIMIT;
plimite->shmSizeLimit = PLIMIT_IPC_SHM_LIMIT_MAX;
g_rootIPCLimit = plimite;
}
VOID *OsIPCLimitAlloc(VOID)
{
ProcIPCLimit *plimite = (ProcIPCLimit *)LOS_MemAlloc(m_aucSysMem1, sizeof(ProcIPCLimit));
if (plimite == NULL) {
return NULL;
}
(VOID)memset_s(plimite, sizeof(ProcIPCLimit), 0, sizeof(ProcIPCLimit));
return (VOID *)plimite;
}
VOID OsIPCLimitFree(UINTPTR limite)
{
ProcIPCLimit *plimite = (ProcIPCLimit *)limite;
if (plimite == NULL) {
return;
}
(VOID)LOS_MemFree(m_aucSysMem1, (VOID *)plimite);
}
VOID OsIPCLimitCopy(UINTPTR dest, UINTPTR src)
{
ProcIPCLimit *plimiteDest = (ProcIPCLimit *)dest;
ProcIPCLimit *plimiteSrc = (ProcIPCLimit *)src;
plimiteDest->mqCountLimit = plimiteSrc->mqCountLimit;
plimiteDest->shmSizeLimit = plimiteSrc->shmSizeLimit;
return;
}
BOOL OsIPCLimiteMigrateCheck(UINTPTR curr, UINTPTR parent)
{
ProcIPCLimit *currIpcLimit = (ProcIPCLimit *)curr;
ProcIPCLimit *parentIpcLimit = (ProcIPCLimit *)parent;
if ((currIpcLimit->mqCount + parentIpcLimit->mqCount) >= parentIpcLimit->mqCountLimit) {
return FALSE;
}
if ((currIpcLimit->shmSize + parentIpcLimit->shmSize) >= parentIpcLimit->shmSizeLimit) {
return FALSE;
}
return TRUE;
}
VOID OsIPCLimitMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process)
{
ProcIPCLimit *currIpcLimit = (ProcIPCLimit *)currLimit;
ProcIPCLimit *parentIpcLimit = (ProcIPCLimit *)parentLimit;
LosProcessCB *pcb = (LosProcessCB *)process;
if (pcb == NULL) {
parentIpcLimit->mqCount += currIpcLimit->mqCount;
parentIpcLimit->mqFailedCount += currIpcLimit->mqFailedCount;
parentIpcLimit->shmSize += currIpcLimit->shmSize;
parentIpcLimit->shmFailedCount += currIpcLimit->shmFailedCount;
return;
}
parentIpcLimit->mqCount -= pcb->limitStat.mqCount;
parentIpcLimit->shmSize -= pcb->limitStat.shmSize;
currIpcLimit->mqCount += pcb->limitStat.mqCount;
currIpcLimit->shmSize += pcb->limitStat.shmSize;
}
BOOL OsIPCLimitAddProcessCheck(UINTPTR limit, UINTPTR process)
{
ProcIPCLimit *ipcLimit = (ProcIPCLimit *)limit;
LosProcessCB *pcb = (LosProcessCB *)process;
if ((ipcLimit->mqCount + pcb->limitStat.mqCount) >= ipcLimit->mqCountLimit) {
return FALSE;
}
if ((ipcLimit->shmSize + pcb->limitStat.shmSize) >= ipcLimit->shmSizeLimit) {
return FALSE;
}
return TRUE;
}
VOID OsIPCLimitAddProcess(UINTPTR limit, UINTPTR process)
{
LosProcessCB *pcb = (LosProcessCB *)process;
ProcIPCLimit *plimits = (ProcIPCLimit *)limit;
plimits->mqCount += pcb->limitStat.mqCount;
plimits->shmSize += pcb->limitStat.shmSize;
return;
}
VOID OsIPCLimitDelProcess(UINTPTR limit, UINTPTR process)
{
LosProcessCB *pcb = (LosProcessCB *)process;
ProcIPCLimit *plimits = (ProcIPCLimit *)limit;
plimits->mqCount -= pcb->limitStat.mqCount;
plimits->shmSize -= pcb->limitStat.shmSize;
return;
}
UINT32 OsIPCLimitSetMqLimit(ProcIPCLimit *ipcLimit, UINT32 value)
{
UINT32 intSave;
if ((ipcLimit == NULL) || (value == 0) || (value > LOSCFG_BASE_IPC_QUEUE_LIMIT)) {
return EINVAL;
}
if (ipcLimit == g_rootIPCLimit) {
return EPERM;
}
SCHEDULER_LOCK(intSave);
if (value < ipcLimit->mqCount) {
SCHEDULER_UNLOCK(intSave);
return EINVAL;
}
ipcLimit->mqCountLimit = value;
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
UINT32 OsIPCLimitSetShmLimit(ProcIPCLimit *ipcLimit, UINT32 value)
{
UINT32 intSave;
if ((ipcLimit == NULL) || (value == 0) || (value > PLIMIT_IPC_SHM_LIMIT_MAX)) {
return EINVAL;
}
if (ipcLimit == g_rootIPCLimit) {
return EPERM;
}
SCHEDULER_LOCK(intSave);
if (value < ipcLimit->shmSize) {
SCHEDULER_UNLOCK(intSave);
return EINVAL;
}
ipcLimit->shmSizeLimit = value;
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
UINT32 OsIPCLimitMqAlloc(VOID)
{
UINT32 intSave;
SCHEDULER_LOCK(intSave);
LosProcessCB *run = OsCurrProcessGet();
ProcIPCLimit *ipcLimit = (ProcIPCLimit *)run->plimits->limitsList[PROCESS_LIMITER_ID_IPC];
if (ipcLimit->mqCount >= ipcLimit->mqCountLimit) {
ipcLimit->mqFailedCount++;
SCHEDULER_UNLOCK(intSave);
return EINVAL;
}
run->limitStat.mqCount++;
ipcLimit->mqCount++;
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
VOID OsIPCLimitMqFree(VOID)
{
UINT32 intSave;
SCHEDULER_LOCK(intSave);
LosProcessCB *run = OsCurrProcessGet();
ProcIPCLimit *ipcLimit = (ProcIPCLimit *)run->plimits->limitsList[PROCESS_LIMITER_ID_IPC];
ipcLimit->mqCount--;
run->limitStat.mqCount--;
SCHEDULER_UNLOCK(intSave);
return;
}
UINT32 OsIPCLimitShmAlloc(UINT32 size)
{
UINT32 intSave;
SCHEDULER_LOCK(intSave);
LosProcessCB *run = OsCurrProcessGet();
ProcIPCLimit *ipcLimit = (ProcIPCLimit *)run->plimits->limitsList[PROCESS_LIMITER_ID_IPC];
if ((ipcLimit->shmSize + size) >= ipcLimit->shmSizeLimit) {
ipcLimit->shmFailedCount++;
SCHEDULER_UNLOCK(intSave);
return EINVAL;
}
run->limitStat.shmSize += size;
ipcLimit->shmSize += size;
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
VOID OsIPCLimitShmFree(UINT32 size)
{
UINT32 intSave;
SCHEDULER_LOCK(intSave);
LosProcessCB *run = OsCurrProcessGet();
ProcIPCLimit *ipcLimit = (ProcIPCLimit *)run->plimits->limitsList[PROCESS_LIMITER_ID_IPC];
ipcLimit->shmSize -= size;
run->limitStat.shmSize -= size;
SCHEDULER_UNLOCK(intSave);
return;
}
#endif

View File

@@ -0,0 +1,92 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_IPCLIMIT_H
#define _LOS_IPCLIMIT_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef struct ProcIPCLimit {
UINT32 mqCount;
UINT32 mqFailedCount;
UINT32 mqCountLimit;
UINT32 shmSize;
UINT32 shmFailedCount;
UINT32 shmSizeLimit;
} ProcIPCLimit;
enum IPCStatType {
IPC_STAT_TYPE_MQ = 0,
IPC_STAT_TYPE_SHM = 3,
IPC_STAT_TYPE_BUT // buttock
};
enum IPCStatOffset {
IPC_STAT_OFFSET_MQ = 0,
IPC_STAT_OFFSET_SHM = 3,
IPC_STAT_OFFSET_BUT // buttock
};
enum StatItem {
STAT_ITEM_TOTAL,
STAT_ITEM_FAILED,
STAT_ITEM_LIMIT,
STAT_ITEM_BUT // buttock
};
VOID OsIPCLimitInit(UINTPTR limite);
VOID *OsIPCLimitAlloc(VOID);
VOID OsIPCLimitFree(UINTPTR limite);
VOID OsIPCLimitCopy(UINTPTR dest, UINTPTR src);
BOOL OsIPCLimiteMigrateCheck(UINTPTR curr, UINTPTR parent);
VOID OsIPCLimitMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process);
BOOL OsIPCLimitAddProcessCheck(UINTPTR limit, UINTPTR process);
VOID OsIPCLimitAddProcess(UINTPTR limit, UINTPTR process);
VOID OsIPCLimitDelProcess(UINTPTR limit, UINTPTR process);
UINT32 OsIPCLimitSetMqLimit(ProcIPCLimit *ipcLimit, UINT32 value);
UINT32 OsIPCLimitSetShmLimit(ProcIPCLimit *ipcLimit, UINT32 value);
UINT32 OsIPCLimitMqAlloc(VOID);
VOID OsIPCLimitMqFree(VOID);
UINT32 OsIPCLimitShmAlloc(UINT32 size);
VOID OsIPCLimitShmFree(UINT32 size);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_IPCIMIT_H */

View File

@@ -0,0 +1,223 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
#include <stdlib.h>
#include <securec.h>
#include "los_config.h"
#include "los_hook.h"
#include "los_process_pri.h"
#include "los_plimits.h"
STATIC ProcMemLimiter *g_procMemLimiter = NULL;
VOID OsMemLimiterInit(UINTPTR limite)
{
ProcMemLimiter *procMemLimiter = (ProcMemLimiter *)limite;
procMemLimiter->limit = OS_NULL_INT;
g_procMemLimiter = procMemLimiter;
}
VOID OsMemLimitSetLimit(UINT32 limit)
{
g_procMemLimiter->limit = limit;
}
VOID *OsMemLimiterAlloc(VOID)
{
ProcMemLimiter *plimite = (ProcMemLimiter *)LOS_MemAlloc(m_aucSysMem1, sizeof(ProcMemLimiter));
if (plimite == NULL) {
return NULL;
}
(VOID)memset_s(plimite, sizeof(ProcMemLimiter), 0, sizeof(ProcMemLimiter));
return (VOID *)plimite;
}
VOID OsMemLimiterFree(UINTPTR limite)
{
ProcMemLimiter *plimite = (ProcMemLimiter *)limite;
if (plimite == NULL) {
return;
}
(VOID)LOS_MemFree(m_aucSysMem1, (VOID *)limite);
}
VOID OsMemLimiterCopy(UINTPTR dest, UINTPTR src)
{
ProcMemLimiter *plimiteDest = (ProcMemLimiter *)dest;
ProcMemLimiter *plimiteSrc = (ProcMemLimiter *)src;
plimiteDest->limit = plimiteSrc->limit;
return;
}
BOOL MemLimiteMigrateCheck(UINTPTR curr, UINTPTR parent)
{
ProcMemLimiter *currMemLimit = (ProcMemLimiter *)curr;
ProcMemLimiter *parentMemLimit = (ProcMemLimiter *)parent;
if ((currMemLimit->usage + parentMemLimit->usage) >= parentMemLimit->limit) {
return FALSE;
}
return TRUE;
}
VOID OsMemLimiterMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process)
{
ProcMemLimiter *currMemLimit = (ProcMemLimiter *)currLimit;
ProcMemLimiter *parentMemLimit = (ProcMemLimiter *)parentLimit;
LosProcessCB *pcb = (LosProcessCB *)process;
if (pcb == NULL) {
parentMemLimit->usage += currMemLimit->usage;
parentMemLimit->failcnt += currMemLimit->failcnt;
if (parentMemLimit->peak < parentMemLimit->usage) {
parentMemLimit->peak = parentMemLimit->usage;
}
return;
}
parentMemLimit->usage -= pcb->limitStat.memUsed;
currMemLimit->usage += pcb->limitStat.memUsed;
}
BOOL OsMemLimitAddProcessCheck(UINTPTR limit, UINTPTR process)
{
ProcMemLimiter *memLimit = (ProcMemLimiter *)limit;
LosProcessCB *pcb = (LosProcessCB *)process;
if ((memLimit->usage + pcb->limitStat.memUsed) > memLimit->limit) {
return FALSE;
}
return TRUE;
}
VOID OsMemLimitAddProcess(UINTPTR limit, UINTPTR process)
{
LosProcessCB *pcb = (LosProcessCB *)process;
ProcMemLimiter *plimits = (ProcMemLimiter *)limit;
plimits->usage += pcb->limitStat.memUsed;
if (plimits->peak < plimits->usage) {
plimits->peak = plimits->usage;
}
return;
}
VOID OsMemLimitDelProcess(UINTPTR limit, UINTPTR process)
{
LosProcessCB *pcb = (LosProcessCB *)process;
ProcMemLimiter *plimits = (ProcMemLimiter *)limit;
plimits->usage -= pcb->limitStat.memUsed;
return;
}
UINT32 OsMemLimitSetMemLimit(ProcMemLimiter *memLimit, UINT64 value)
{
UINT32 intSave;
if ((memLimit == NULL) || (value == 0)) {
return EINVAL;
}
if (memLimit == g_procMemLimiter) {
return EPERM;
}
SCHEDULER_LOCK(intSave);
if (value < memLimit->usage) {
SCHEDULER_UNLOCK(intSave);
return EINVAL;
}
memLimit->limit = value;
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
#define MEM_LIMIT_LOCK(state, locked) do { \
if (SCHEDULER_HELD()) { \
locked = TRUE; \
} else { \
SCHEDULER_LOCK(state); \
} \
} while (0)
#define MEM_LIMIT_UNLOCK(state, locked) do { \
if (!locked) { \
SCHEDULER_UNLOCK(state); \
} \
} while (0)
UINT32 OsMemLimitCheckAndMemAdd(UINT32 size)
{
UINT32 intSave;
BOOL locked = FALSE;
MEM_LIMIT_LOCK(intSave, locked);
LosProcessCB *run = OsCurrProcessGet();
UINT32 currProcessID = run->processID;
if ((run == NULL) || (run->plimits == NULL)) {
MEM_LIMIT_UNLOCK(intSave, locked);
return LOS_OK;
}
ProcMemLimiter *memLimit = (ProcMemLimiter *)run->plimits->limitsList[PROCESS_LIMITER_ID_MEM];
if ((memLimit->usage + size) > memLimit->limit) {
memLimit->failcnt++;
MEM_LIMIT_UNLOCK(intSave, locked);
PRINT_ERR("plimits: process %u adjust the memory limit of Plimits group\n", currProcessID);
return ENOMEM;
}
memLimit->usage += size;
run->limitStat.memUsed += size;
if (memLimit->peak < memLimit->usage) {
memLimit->peak = memLimit->usage;
}
MEM_LIMIT_UNLOCK(intSave, locked);
return LOS_OK;
}
VOID OsMemLimitMemFree(UINT32 size)
{
UINT32 intSave;
BOOL locked = FALSE;
MEM_LIMIT_LOCK(intSave, locked);
LosProcessCB *run = OsCurrProcessGet();
if ((run == NULL) || (run->plimits == NULL)) {
MEM_LIMIT_UNLOCK(intSave, locked);
return;
}
ProcMemLimiter *memLimit = (ProcMemLimiter *)run->plimits->limitsList[PROCESS_LIMITER_ID_MEM];
if (run->limitStat.memUsed > size) {
run->limitStat.memUsed -= size;
memLimit->usage -= size;
}
MEM_LIMIT_UNLOCK(intSave, locked);
}
#endif

View File

@@ -0,0 +1,69 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_MEMLIMIT_H
#define _LOS_MEMLIMIT_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef struct ProcMemLimiter {
UINT64 usage;
UINT64 limit;
UINT64 peak;
UINT32 failcnt;
} ProcMemLimiter;
VOID OsMemLimiterInit(UINTPTR limite);
VOID *OsMemLimiterAlloc(VOID);
VOID OsMemLimiterFree(UINTPTR limite);
VOID OsMemLimiterCopy(UINTPTR dest, UINTPTR src);
BOOL MemLimiteMigrateCheck(UINTPTR curr, UINTPTR parent);
VOID OsMemLimiterMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process);
BOOL OsMemLimitAddProcessCheck(UINTPTR limit, UINTPTR process);
VOID OsMemLimitAddProcess(UINTPTR limit, UINTPTR process);
VOID OsMemLimitDelProcess(UINTPTR limit, UINTPTR process);
UINT32 OsMemLimitSetMemLimit(ProcMemLimiter *memLimit, UINT64 value);
VOID OsMemLimitSetLimit(UINTPTR limit);
UINT32 OsMemLimitCheckAndMemAdd(UINT32 size);
VOID OsMemLimitMemFree(UINT32 size);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_MEMLIMIT_H */

View File

@@ -0,0 +1,434 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef LOSCFG_KERNEL_PLIMITS
#include "los_base.h"
#include "los_process_pri.h"
#include "hal_timer.h"
#include "los_plimits.h"
typedef struct PlimiteOperations {
VOID (*LimiterInit)(UINTPTR);
VOID *(*LimiterAlloc)(VOID);
VOID (*LimiterFree)(UINTPTR);
VOID (*LimiterCopy)(UINTPTR, UINTPTR);
BOOL (*LimiterAddProcessCheck)(UINTPTR, UINTPTR);
VOID (*LimiterAddProcess)(UINTPTR, UINTPTR);
VOID (*LimiterDelProcess)(UINTPTR, UINTPTR);
BOOL (*LimiterMigrateCheck)(UINTPTR, UINTPTR);
VOID (*LimiterMigrate)(UINTPTR, UINTPTR, UINTPTR);
} PlimiteOperations;
static PlimiteOperations g_limiteOps[PROCESS_LIMITER_COUNT] = {
[PROCESS_LIMITER_ID_PIDS] = {
.LimiterInit = PidLimiterInit,
.LimiterAlloc = PidLimiterAlloc,
.LimiterFree = PidLimterFree,
.LimiterCopy = PidLimiterCopy,
.LimiterAddProcessCheck = OsPidLimitAddProcessCheck,
.LimiterAddProcess = OsPidLimitAddProcess,
.LimiterDelProcess = OsPidLimitDelProcess,
.LimiterMigrateCheck = PidLimitMigrateCheck,
.LimiterMigrate = NULL,
},
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
[PROCESS_LIMITER_ID_MEM] = {
.LimiterInit = OsMemLimiterInit,
.LimiterAlloc = OsMemLimiterAlloc,
.LimiterFree = OsMemLimiterFree,
.LimiterCopy = OsMemLimiterCopy,
.LimiterAddProcessCheck = OsMemLimitAddProcessCheck,
.LimiterAddProcess = OsMemLimitAddProcess,
.LimiterDelProcess = OsMemLimitDelProcess,
.LimiterMigrateCheck = MemLimiteMigrateCheck,
.LimiterMigrate = OsMemLimiterMigrate,
},
#endif
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
[PROCESS_LIMITER_ID_SCHED] = {
.LimiterInit = OsSchedLimitInit,
.LimiterAlloc = OsSchedLimitAlloc,
.LimiterFree = OsSchedLimitFree,
.LimiterCopy = OsSchedLimitCopy,
.LimiterAddProcessCheck = NULL,
.LimiterAddProcess = NULL,
.LimiterDelProcess = NULL,
.LimiterMigrateCheck = NULL,
.LimiterMigrate = NULL,
},
#endif
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
[PROCESS_LIMITER_ID_DEV] = {
.LimiterInit = OsDevLimitInit,
.LimiterAlloc = OsDevLimitAlloc,
.LimiterFree = OsDevLimitFree,
.LimiterCopy = OsDevLimitCopy,
.LimiterAddProcessCheck = NULL,
.LimiterAddProcess = NULL,
.LimiterDelProcess = NULL,
.LimiterMigrateCheck = NULL,
.LimiterMigrate = NULL,
},
#endif
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
[PROCESS_LIMITER_ID_IPC] = {
.LimiterInit = OsIPCLimitInit,
.LimiterAlloc = OsIPCLimitAlloc,
.LimiterFree = OsIPCLimitFree,
.LimiterCopy = OsIPCLimitCopy,
.LimiterAddProcessCheck = OsIPCLimitAddProcessCheck,
.LimiterAddProcess = OsIPCLimitAddProcess,
.LimiterDelProcess = OsIPCLimitDelProcess,
.LimiterMigrateCheck = OsIPCLimiteMigrateCheck,
.LimiterMigrate = OsIPCLimitMigrate,
},
#endif
};
STATIC ProcLimiterSet *g_rootPLimite = NULL;
ProcLimiterSet *OsRootPLimitsGet(VOID)
{
return g_rootPLimite;
}
UINT32 OsProcLimiterSetInit(VOID)
{
g_rootPLimite = (ProcLimiterSet *)LOS_MemAlloc(m_aucSysMem1, sizeof(ProcLimiterSet));
if (g_rootPLimite == NULL) {
return ENOMEM;
}
(VOID)memset_s(g_rootPLimite, sizeof(ProcLimiterSet), 0, sizeof(ProcLimiterSet));
LOS_ListInit(&g_rootPLimite->childList);
LOS_ListInit(&g_rootPLimite->processList);
ProcLimiterSet *procLimiterSet = g_rootPLimite;
for (INT32 plimiteID = 0; plimiteID < PROCESS_LIMITER_COUNT; ++plimiteID) {
procLimiterSet->limitsList[plimiteID] = (UINTPTR)g_limiteOps[plimiteID].LimiterAlloc();
if (procLimiterSet->limitsList[plimiteID] == (UINTPTR)NULL) {
OsPLimitsFree(procLimiterSet);
return ENOMEM;
}
if (g_limiteOps[plimiteID].LimiterInit != NULL) {
g_limiteOps[plimiteID].LimiterInit(procLimiterSet->limitsList[plimiteID]);
}
}
return LOS_OK;
}
STATIC VOID PLimitsDeleteProcess(LosProcessCB *processCB)
{
if ((processCB == NULL) || (processCB->plimits == NULL)) {
return;
}
ProcLimiterSet *plimits = processCB->plimits;
for (UINT32 limitsID = 0; limitsID < PROCESS_LIMITER_COUNT; limitsID++) {
if (g_limiteOps[limitsID].LimiterDelProcess == NULL) {
continue;
}
g_limiteOps[limitsID].LimiterDelProcess(plimits->limitsList[limitsID], (UINTPTR)processCB);
}
plimits->pidCount--;
LOS_ListDelete(&processCB->plimitsList);
processCB->plimits = NULL;
return;
}
STATIC UINT32 PLimitsAddProcess(ProcLimiterSet *plimits, LosProcessCB *processCB)
{
UINT32 limitsID;
if (plimits == NULL) {
plimits = g_rootPLimite;
}
if (processCB->plimits == g_rootPLimite) {
return EPERM;
}
if (processCB->plimits == plimits) {
return LOS_OK;
}
for (limitsID = 0; limitsID < PROCESS_LIMITER_COUNT; limitsID++) {
if (g_limiteOps[limitsID].LimiterAddProcessCheck == NULL) {
continue;
}
if (!g_limiteOps[limitsID].LimiterAddProcessCheck(plimits->limitsList[limitsID], (UINTPTR)processCB)) {
return EACCES;
}
}
PLimitsDeleteProcess(processCB);
for (limitsID = 0; limitsID < PROCESS_LIMITER_COUNT; limitsID++) {
if (g_limiteOps[limitsID].LimiterAddProcess == NULL) {
continue;
}
g_limiteOps[limitsID].LimiterAddProcess(plimits->limitsList[limitsID], (UINTPTR)processCB);
}
LOS_ListTailInsert(&plimits->processList, &processCB->plimitsList);
plimits->pidCount++;
processCB->plimits = plimits;
return LOS_OK;
}
UINT32 OsPLimitsAddProcess(ProcLimiterSet *plimits, LosProcessCB *processCB)
{
UINT32 intSave;
SCHEDULER_LOCK(intSave);
UINT32 ret = PLimitsAddProcess(plimits, processCB);
SCHEDULER_UNLOCK(intSave);
return ret;
}
UINT32 OsPLimitsAddPid(ProcLimiterSet *plimits, UINT32 pid)
{
UINT32 intSave, ret;
if ((plimits == NULL) || OS_PID_CHECK_INVALID(pid) || (pid == 0)) {
return EINVAL;
}
if (plimits == g_rootPLimite) {
return EPERM;
}
SCHEDULER_LOCK(intSave);
LosProcessCB *processCB = OS_PCB_FROM_PID((unsigned int)pid);
if (OsProcessIsInactive(processCB)) {
SCHEDULER_UNLOCK(intSave);
return EINVAL;
}
ret = PLimitsAddProcess(plimits, processCB);
SCHEDULER_UNLOCK(intSave);
return ret;
}
VOID OsPLimitsDeleteProcess(LosProcessCB *processCB)
{
UINT32 intSave;
SCHEDULER_LOCK(intSave);
PLimitsDeleteProcess(processCB);
SCHEDULER_UNLOCK(intSave);
}
UINT32 OsPLimitsPidsGet(const ProcLimiterSet *plimits, UINT32 *pids, UINT32 size)
{
UINT32 intSave;
LosProcessCB *processCB = NULL;
UINT32 minSize = LOS_GetSystemProcessMaximum() * sizeof(UINT32);
if ((plimits == NULL) || (pids == NULL) || (size < minSize)) {
return EINVAL;
}
SCHEDULER_LOCK(intSave);
LOS_DL_LIST *listHead = (LOS_DL_LIST *)&plimits->processList;
if (LOS_ListEmpty(listHead)) {
SCHEDULER_UNLOCK(intSave);
return EINVAL;
}
LOS_DL_LIST_FOR_EACH_ENTRY(processCB, listHead, LosProcessCB, plimitsList) {
pids[OsGetPid(processCB)] = 1;
}
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
STATIC VOID PLimitsProcessMerge(ProcLimiterSet *currPLimits, ProcLimiterSet *parentPLimits)
{
LOS_DL_LIST *head = &currPLimits->processList;
while (!LOS_ListEmpty(head)) {
LosProcessCB *processCB = LOS_DL_LIST_ENTRY(head->pstNext, LosProcessCB, plimitsList);
PLimitsDeleteProcess(processCB);
PLimitsAddProcess(parentPLimits, processCB);
}
LOS_ListDelete(&currPLimits->childList);
currPLimits->parent = NULL;
return;
}
STATIC UINT32 PLimitsMigrateCheck(ProcLimiterSet *currPLimits, ProcLimiterSet *parentPLimits)
{
for (UINT32 limiteID = 0; limiteID < PROCESS_LIMITER_COUNT; limiteID++) {
UINTPTR currLimit = currPLimits->limitsList[limiteID];
UINTPTR parentLimit = parentPLimits->limitsList[limiteID];
if (g_limiteOps[limiteID].LimiterMigrateCheck == NULL) {
continue;
}
if (!g_limiteOps[limiteID].LimiterMigrateCheck(currLimit, parentLimit)) {
return EPERM;
}
}
return LOS_OK;
}
UINT32 OsPLimitsFree(ProcLimiterSet *currPLimits)
{
UINT32 intSave, ret;
if (currPLimits == NULL) {
return EINVAL;
}
SCHEDULER_LOCK(intSave);
ProcLimiterSet *parentPLimits = currPLimits->parent;
ret = PLimitsMigrateCheck(currPLimits, parentPLimits);
if (ret != LOS_OK) {
SCHEDULER_UNLOCK(intSave);
return ret;
}
PLimitsProcessMerge(currPLimits, parentPLimits);
SCHEDULER_UNLOCK(intSave);
for (INT32 limiteID = 0; limiteID < PROCESS_LIMITER_COUNT; ++limiteID) {
UINTPTR procLimiter = currPLimits->limitsList[limiteID];
if (g_limiteOps[limiteID].LimiterFree != NULL) {
g_limiteOps[limiteID].LimiterFree(procLimiter);
}
}
(VOID)LOS_MemFree(m_aucSysMem1, currPLimits);
return LOS_OK;
}
ProcLimiterSet *OsPLimitsCreate(ProcLimiterSet *parentPLimits)
{
UINT32 intSave;
ProcLimiterSet *newPLimits = (ProcLimiterSet *)LOS_MemAlloc(m_aucSysMem1, sizeof(ProcLimiterSet));
if (newPLimits == NULL) {
return NULL;
}
(VOID)memset_s(newPLimits, sizeof(ProcLimiterSet), 0, sizeof(ProcLimiterSet));
LOS_ListInit(&newPLimits->childList);
LOS_ListInit(&newPLimits->processList);
SCHEDULER_LOCK(intSave);
newPLimits->parent = parentPLimits;
newPLimits->level = parentPLimits->level + 1;
newPLimits->mask = parentPLimits->mask;
for (INT32 plimiteID = 0; plimiteID < PROCESS_LIMITER_COUNT; ++plimiteID) {
newPLimits->limitsList[plimiteID] = (UINTPTR)g_limiteOps[plimiteID].LimiterAlloc();
if (newPLimits->limitsList[plimiteID] == (UINTPTR)NULL) {
SCHEDULER_UNLOCK(intSave);
OsPLimitsFree(newPLimits);
return NULL;
}
if (g_limiteOps[plimiteID].LimiterCopy != NULL) {
g_limiteOps[plimiteID].LimiterCopy(newPLimits->limitsList[plimiteID],
parentPLimits->limitsList[plimiteID]);
}
}
LOS_ListTailInsert(&g_rootPLimite->childList, &newPLimits->childList);
(VOID)PLimitsDeleteProcess(OsCurrProcessGet());
(VOID)PLimitsAddProcess(newPLimits, OsCurrProcessGet());
SCHEDULER_UNLOCK(intSave);
return newPLimits;
}
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
UINT32 OsPLimitsMemUsageGet(ProcLimiterSet *plimits, UINT64 *usage, UINT32 size)
{
UINT32 intSave;
LosProcessCB *processCB = NULL;
UINT32 minSize = LOS_GetSystemProcessMaximum() * sizeof(UINT64) + sizeof(ProcMemLimiter);
ProcMemLimiter *memLimit = (ProcMemLimiter *)usage;
UINT64 *memSuage = (UINT64 *)((UINTPTR)usage + sizeof(ProcMemLimiter));
if ((plimits == NULL) || (usage == NULL) || (size < minSize)) {
return EINVAL;
}
SCHEDULER_LOCK(intSave);
(VOID)memcpy_s(memLimit, sizeof(ProcMemLimiter),
(VOID *)plimits->limitsList[PROCESS_LIMITER_ID_MEM], sizeof(ProcMemLimiter));
LOS_DL_LIST *listHead = (LOS_DL_LIST *)&plimits->processList;
if (LOS_ListEmpty(listHead)) {
SCHEDULER_UNLOCK(intSave);
return EINVAL;
}
LOS_DL_LIST_FOR_EACH_ENTRY(processCB, listHead, LosProcessCB, plimitsList) {
memSuage[OsGetPid(processCB)] = processCB->limitStat.memUsed;
}
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
#endif
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
UINT32 OsPLimitsIPCStatGet(ProcLimiterSet *plimits, ProcIPCLimit *ipc, UINT32 size)
{
UINT32 intSave;
if ((plimits == NULL) || (ipc == NULL) || (size != sizeof(ProcIPCLimit))) {
return EINVAL;
}
SCHEDULER_LOCK(intSave);
(VOID)memcpy_s(ipc, sizeof(ProcIPCLimit),
(VOID *)plimits->limitsList[PROCESS_LIMITER_ID_IPC], sizeof(ProcIPCLimit));
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
#endif
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
UINT32 OsPLimitsSchedUsageGet(ProcLimiterSet *plimits, UINT64 *usage, UINT32 size)
{
UINT32 intSave;
LosProcessCB *processCB = NULL;
UINT32 minSize = LOS_GetSystemProcessMaximum() * sizeof(UINT64);
if ((plimits == NULL) || (usage == NULL) || (size < minSize)) {
return EINVAL;
}
SCHEDULER_LOCK(intSave);
LOS_DL_LIST *listHead = (LOS_DL_LIST *)&plimits->processList;
if (LOS_ListEmpty(listHead)) {
SCHEDULER_UNLOCK(intSave);
return EINVAL;
}
LOS_DL_LIST_FOR_EACH_ENTRY(processCB, listHead, LosProcessCB, plimitsList) {
usage[OsGetPid(processCB)] = processCB->limitStat.allRuntime;
}
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
#endif
#endif

View File

@@ -0,0 +1,114 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_PLIMITS_H
#define _LOS_PLIMITS_H
#include "los_list.h"
#include "los_typedef.h"
#include "los_processlimit.h"
#include "los_memlimit.h"
#include "los_ipclimit.h"
#include "los_devicelimit.h"
#include "los_schedlimit.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/* proc limit set lock */
#define PLIMITS_MIN_PERIOD_IN_US 1000000
#define PLIMITS_MIN_QUOTA_IN_US 1
#define PLIMITS_DELETE_WAIT_TIME 1000
typedef struct ProcessCB LosProcessCB;
enum ProcLimiterID {
PROCESS_LIMITER_ID_PIDS = 0,
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
PROCESS_LIMITER_ID_MEM,
#endif
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
PROCESS_LIMITER_ID_SCHED,
#endif
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
PROCESS_LIMITER_ID_DEV,
#endif
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
PROCESS_LIMITER_ID_IPC,
#endif
PROCESS_LIMITER_COUNT,
};
typedef struct {
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
UINT64 memUsed;
#endif
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
UINT32 mqCount;
UINT32 shmSize;
#endif
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
UINT64 allRuntime;
#endif
} PLimitsData;
typedef struct TagPLimiterSet {
struct TagPLimiterSet *parent; /* plimite parent */
LOS_DL_LIST childList; /* plimite childList */
LOS_DL_LIST processList;
UINT32 pidCount;
UINTPTR limitsList[PROCESS_LIMITER_COUNT]; /* plimite list */
UINT32 mask; /* each bit indicates that a limite exists */
UINT8 level; /* plimits hierarchy level */
} ProcLimiterSet;
typedef struct ProcessCB LosProcessCB;
ProcLimiterSet *OsRootPLimitsGet(VOID);
UINT32 OsPLimitsAddProcess(ProcLimiterSet *plimits, LosProcessCB *processCB);
UINT32 OsPLimitsAddPid(ProcLimiterSet *plimits, UINT32 pid);
VOID OsPLimitsDeleteProcess(LosProcessCB *processCB);
UINT32 OsPLimitsPidsGet(const ProcLimiterSet *plimits, UINT32 *pids, UINT32 size);
UINT32 OsPLimitsFree(ProcLimiterSet *currPLimits);
ProcLimiterSet *OsPLimitsCreate(ProcLimiterSet *parentProcLimiterSet);
UINT32 OsProcLimiterSetInit(VOID);
UINT32 OsPLimitsMemUsageGet(ProcLimiterSet *plimits, UINT64 *usage, UINT32 size);
UINT32 OsPLimitsIPCStatGet(ProcLimiterSet *plimits, ProcIPCLimit *ipc, UINT32 size);
UINT32 OsPLimitsSchedUsageGet(ProcLimiterSet *plimits, UINT64 *usage, UINT32 size);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_PLIMITS_H */

View File

@@ -0,0 +1,182 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef LOSCFG_KERNEL_PLIMITS
#include "los_config.h"
#include "los_process_pri.h"
#include "los_process.h"
#include "los_plimits.h"
#include "los_task_pri.h"
#include "los_processlimit.h"
STATIC PidLimit *g_rootPidLimit = NULL;
VOID PidLimiterInit(UINTPTR limit)
{
PidLimit *pidLimit = (PidLimit *)limit;
if (pidLimit == NULL) {
return;
}
pidLimit->pidLimit = LOS_GetSystemProcessMaximum();
pidLimit->priorityLimit = OS_USER_PROCESS_PRIORITY_HIGHEST;
g_rootPidLimit = pidLimit;
}
VOID *PidLimiterAlloc(VOID)
{
PidLimit *plimite = (PidLimit *)LOS_MemAlloc(m_aucSysMem1, sizeof(PidLimit));
if (plimite == NULL) {
return NULL;
}
(VOID)memset_s(plimite, sizeof(PidLimit), 0, sizeof(PidLimit));
return (VOID *)plimite;
}
VOID PidLimterFree(UINTPTR limit)
{
PidLimit *pidLimit = (PidLimit *)limit;
if (pidLimit == NULL) {
return;
}
(VOID)LOS_MemFree(m_aucSysMem1, (VOID *)limit);
}
BOOL PidLimitMigrateCheck(UINTPTR curr, UINTPTR parent)
{
PidLimit *currPidLimit = (PidLimit *)curr;
PidLimit *parentPidLimit = (PidLimit *)parent;
if ((currPidLimit == NULL) || (parentPidLimit == NULL)) {
return FALSE;
}
if ((currPidLimit->pidCount + parentPidLimit->pidCount) >= parentPidLimit->pidLimit) {
return FALSE;
}
return TRUE;
}
BOOL OsPidLimitAddProcessCheck(UINTPTR limit, UINTPTR process)
{
(VOID)process;
PidLimit *pidLimit = (PidLimit *)limit;
if (pidLimit->pidCount >= pidLimit->pidLimit) {
return FALSE;
}
return TRUE;
}
VOID OsPidLimitAddProcess(UINTPTR limit, UINTPTR process)
{
(VOID)process;
PidLimit *plimits = (PidLimit *)limit;
plimits->pidCount++;
return;
}
VOID OsPidLimitDelProcess(UINTPTR limit, UINTPTR process)
{
(VOID)process;
PidLimit *plimits = (PidLimit *)limit;
plimits->pidCount--;
return;
}
VOID PidLimiterCopy(UINTPTR curr, UINTPTR parent)
{
PidLimit *currPidLimit = (PidLimit *)curr;
PidLimit *parentPidLimit = (PidLimit *)parent;
if ((currPidLimit == NULL) || (parentPidLimit == NULL)) {
return;
}
currPidLimit->pidLimit = parentPidLimit->pidLimit;
currPidLimit->priorityLimit = parentPidLimit->priorityLimit;
currPidLimit->pidCount = 0;
return;
}
UINT32 PidLimitSetPidLimit(PidLimit *pidLimit, UINT32 pidMax)
{
UINT32 intSave;
if ((pidLimit == NULL) || (pidMax > LOS_GetSystemProcessMaximum())) {
return EINVAL;
}
if (pidLimit == g_rootPidLimit) {
return EPERM;
}
SCHEDULER_LOCK(intSave);
if (pidLimit->pidCount >= pidMax) {
SCHEDULER_UNLOCK(intSave);
return EPERM;
}
pidLimit->pidLimit = pidMax;
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
UINT32 PidLimitSetPriorityLimit(PidLimit *pidLimit, UINT32 priority)
{
UINT32 intSave;
if ((pidLimit == NULL) ||
(priority < OS_USER_PROCESS_PRIORITY_HIGHEST) ||
(priority > OS_PROCESS_PRIORITY_LOWEST)) {
return EINVAL;
}
if (pidLimit == g_rootPidLimit) {
return EPERM;
}
SCHEDULER_LOCK(intSave);
pidLimit->priorityLimit = priority;
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
UINT16 OsPidLimitGetPriorityLimit(VOID)
{
UINT32 intSave;
SCHEDULER_LOCK(intSave);
LosProcessCB *run = OsCurrProcessGet();
PidLimit *pidLimit = (PidLimit *)run->plimits->limitsList[PROCESS_LIMITER_ID_PIDS];
UINT16 priority = pidLimit->priorityLimit;
SCHEDULER_UNLOCK(intSave);
return priority;
}
#endif

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_PROCESSLIMIT_H
#define _LOS_PROCESSLIMIT_H
#include "los_list.h"
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef struct PidLimit {
UINT32 pidLimit;
UINT32 priorityLimit;
UINT32 pidCount;
} PidLimit;
VOID PidLimiterInit(UINTPTR limit);
VOID *PidLimiterAlloc(VOID);
VOID PidLimterFree(UINTPTR limit);
VOID PidLimiterCopy(UINTPTR curr, UINTPTR parent);
BOOL PidLimitMigrateCheck(UINTPTR curr, UINTPTR parent);
BOOL OsPidLimitAddProcessCheck(UINTPTR limit, UINTPTR process);
VOID OsPidLimitAddProcess(UINTPTR limit, UINTPTR process);
VOID OsPidLimitDelProcess(UINTPTR limit, UINTPTR process);
UINT32 PidLimitSetPidLimit(PidLimit *pidLimit, UINT32 pidMax);
UINT32 PidLimitSetPriorityLimit(PidLimit *pidLimit, UINT32 priority);
UINT16 OsPidLimitGetPriorityLimit(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@@ -0,0 +1,151 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
#include "los_schedlimit.h"
#include "los_process_pri.h"
STATIC ProcSchedLimiter *g_procSchedLimit = NULL;
VOID OsSchedLimitInit(UINTPTR limit)
{
ProcSchedLimiter *schedLimit = (ProcSchedLimiter *)limit;
schedLimit->period = 0;
schedLimit->quota = 0;
g_procSchedLimit = schedLimit;
}
VOID *OsSchedLimitAlloc(VOID)
{
ProcSchedLimiter *plimit = (ProcSchedLimiter *)LOS_MemAlloc(m_aucSysMem1, sizeof(ProcSchedLimiter));
if (plimit == NULL) {
return NULL;
}
(VOID)memset_s(plimit, sizeof(ProcSchedLimiter), 0, sizeof(ProcSchedLimiter));
return (VOID *)plimit;
}
VOID OsSchedLimitFree(UINTPTR limit)
{
ProcSchedLimiter *schedLimit = (ProcSchedLimiter *)limit;
if (schedLimit == NULL) {
return;
}
(VOID)LOS_MemFree(m_aucSysMem1, (VOID *)limit);
}
VOID OsSchedLimitCopy(UINTPTR dest, UINTPTR src)
{
ProcSchedLimiter *plimitDest = (ProcSchedLimiter *)dest;
ProcSchedLimiter *plimitSrc = (ProcSchedLimiter *)src;
plimitDest->period = plimitSrc->period;
plimitDest->quota = plimitSrc->quota;
return;
}
VOID OsSchedLimitUpdateRuntime(LosTaskCB *runTask, UINT64 currTime, INT32 incTime)
{
LosProcessCB *run = (LosProcessCB *)runTask->processCB;
if ((run == NULL) || (run->plimits == NULL)) {
return;
}
ProcSchedLimiter *schedLimit = (ProcSchedLimiter *)run->plimits->limitsList[PROCESS_LIMITER_ID_SCHED];
run->limitStat.allRuntime += incTime;
if ((schedLimit->period <= 0) || (schedLimit->quota <= 0)) {
return;
}
if ((schedLimit->startTime <= currTime) && (schedLimit->allRuntime < schedLimit->quota)) {
schedLimit->allRuntime += incTime;
return;
}
if (schedLimit->startTime <= currTime) {
schedLimit->startTime = currTime + schedLimit->period;
schedLimit->allRuntime = 0;
}
}
BOOL OsSchedLimitCheckTime(LosTaskCB *task)
{
UINT64 currTime = OsGetCurrSchedTimeCycle();
LosProcessCB *processCB = (LosProcessCB *)task->processCB;
if ((processCB == NULL) || (processCB->plimits == NULL)) {
return TRUE;
}
ProcSchedLimiter *schedLimit = (ProcSchedLimiter *)processCB->plimits->limitsList[PROCESS_LIMITER_ID_SCHED];
if (schedLimit->startTime >= currTime) {
return FALSE;
}
return TRUE;
}
UINT32 OsSchedLimitSetPeriod(ProcSchedLimiter *schedLimit, UINT64 value)
{
UINT32 intSave;
if (schedLimit == NULL) {
return EINVAL;
}
if (schedLimit == g_procSchedLimit) {
return EPERM;
}
SCHEDULER_LOCK(intSave);
schedLimit->period = value;
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
UINT32 OsSchedLimitSetQuota(ProcSchedLimiter *schedLimit, UINT64 value)
{
UINT32 intSave;
if (schedLimit == NULL) {
return EINVAL;
}
if (schedLimit == g_procSchedLimit) {
return EPERM;
}
SCHEDULER_LOCK(intSave);
if (value > (UINT64)schedLimit->period) {
SCHEDULER_UNLOCK(intSave);
return EINVAL;
}
schedLimit->quota = value;
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
#endif

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_SCHEDLIMIT_H
#define _LOS_SCHEDLIMIT_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define CORE_US_PER_SECOND (1000 * 1000) /* 1000 * 1000 us per second */
typedef struct TagTaskCB LosTaskCB;
typedef struct ProcSchedLimiter {
UINT64 startTime;
UINT64 endTime;
UINT64 period;
UINT64 quota;
UINT64 allRuntime;
} ProcSchedLimiter;
VOID OsSchedLimitInit(UINTPTR limit);
VOID *OsSchedLimitAlloc(VOID);
VOID OsSchedLimitFree(UINTPTR limit);
VOID OsSchedLimitCopy(UINTPTR dest, UINTPTR src);
VOID OsSchedLimitUpdateRuntime(LosTaskCB *runTask, UINT64 currTime, INT32 incTime);
UINT32 OsSchedLimitSetPeriod(ProcSchedLimiter *schedLimit, UINT64 value);
UINT32 OsSchedLimitSetQuota(ProcSchedLimiter *schedLimit, UINT64 value);
BOOL OsSchedLimitCheckTime(LosTaskCB *task);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_SCHEDLIMIT_H */

View File

@@ -47,13 +47,13 @@
extern INT32 LOS_Fork(UINT32 flags, const CHAR *name, const TSK_ENTRY_FUNC entry, UINT32 stackSize);
extern INT32 LOS_SetProcessPriority(INT32 pid, UINT16 prio);
extern INT32 LOS_SetProcessPriority(INT32 pid, INT32 prio);
extern INT32 LOS_GetProcessPriority(INT32 pid);
extern INT32 LOS_GetProcessScheduler(INT32 pid);
extern INT32 LOS_GetProcessScheduler(INT32 pid, INT32 *policy, LosSchedParam *schedParam);
extern INT32 LOS_SetProcessScheduler(INT32 pid, UINT16 policy, UINT16 prio);
extern INT32 LOS_SetProcessScheduler(INT32 pid, UINT16 policy, const LosSchedParam *schedParam);
extern UINT32 LOS_GetCurrProcessID(VOID);

View File

@@ -514,8 +514,21 @@ typedef struct tagTskInitParam {
UINT16 consoleID; /**< The console id of task belongs */
UINTPTR processID;
UserTaskParam userParam;
/* edf parameters */
UINT32 runTimeUs;
UINT64 deadlineUs;
UINT64 periodUs;
} TSK_INIT_PARAM_S;
typedef struct {
union {
INT32 priority;
INT32 runTimeUs;
};
INT32 deadlineUs;
INT32 periodUs;
} LosSchedParam;
/**
* @ingroup los_task
* Task name length

Some files were not shown because too many files have changed in this diff Show More