Compare commits
72 Commits
weekly_202
...
weekly_202
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0bc453c2cd | ||
|
|
73bcf0ec9a | ||
|
|
49bfc90a63 | ||
|
|
b0708886fa | ||
|
|
a388a3f565 | ||
|
|
280769ae42 | ||
|
|
1f3a6c8143 | ||
|
|
6c0b0dde23 | ||
|
|
76228c3617 | ||
|
|
5de241eb2a | ||
|
|
5e68558280 | ||
|
|
9c71de6a2e | ||
|
|
243b1e26a4 | ||
|
|
47a4fe030b | ||
|
|
577d29aaba | ||
|
|
d9e9631286 | ||
|
|
2bd5b686cf | ||
|
|
8452488bdb | ||
|
|
a04ab13c76 | ||
|
|
338f5d7e7d | ||
|
|
fa68ebfcd1 | ||
|
|
24aa6858ee | ||
|
|
5fb9165c08 | ||
|
|
13f68dcf9c | ||
|
|
f332a06e4c | ||
|
|
1ba32406bb | ||
|
|
249ea71a11 | ||
|
|
814f5affd0 | ||
|
|
4ff66c7f40 | ||
|
|
8f937c8771 | ||
|
|
2845efe801 | ||
|
|
8cc5209181 | ||
|
|
f995c7c7af | ||
|
|
a104497e08 | ||
|
|
b5ae9e25c6 | ||
|
|
c2b5a5897f | ||
|
|
f924cc775b | ||
|
|
5dc9a0f1a6 | ||
|
|
806bd80841 | ||
|
|
c141a92544 | ||
|
|
10c5e2e666 | ||
|
|
da9ce464dd | ||
|
|
f0a435dce1 | ||
|
|
b45cdbda3e | ||
|
|
57455849ca | ||
|
|
ea825345c2 | ||
|
|
f397c63fbd | ||
|
|
fe6ab18cd9 | ||
|
|
c0f5d437d8 | ||
|
|
1ef64e26a1 | ||
|
|
77b1b208d1 | ||
|
|
d17bc9d4ea | ||
|
|
be50721826 | ||
|
|
4e7d2edbe1 | ||
|
|
58610ea87c | ||
|
|
c6ff38edd2 | ||
|
|
1c18c48b1e | ||
|
|
bea394a75e | ||
|
|
272c490618 | ||
|
|
dd041bef5a | ||
|
|
fd925a8163 | ||
|
|
e8e21fcc3e | ||
|
|
c592fe73ec | ||
|
|
4174654bdd | ||
|
|
f3a7a9c602 | ||
|
|
c8dbdaeb12 | ||
|
|
1f05c6a24d | ||
|
|
325b4a49e4 | ||
|
|
1d1f1b06c3 | ||
|
|
16ed05e844 | ||
|
|
7e0dfb79f7 | ||
|
|
34814c58a3 |
36
BUILD.gn
36
BUILD.gn
@@ -34,6 +34,7 @@ LITEOS_MENUCONFIG_H = rebase_path("$root_out_dir/config.h")
|
||||
declare_args() {
|
||||
tee_enable = false
|
||||
liteos_name = "OHOS_Image"
|
||||
liteos_container_enable = false
|
||||
liteos_skip_make = false
|
||||
liteos_is_mini = false
|
||||
}
|
||||
@@ -201,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
|
||||
}
|
||||
@@ -239,6 +244,28 @@ config("misc_config") {
|
||||
asmflags = cflags
|
||||
}
|
||||
|
||||
config("container_config") {
|
||||
if (liteos_container_enable) {
|
||||
cflags = [
|
||||
"-DLOSCFG_KERNEL_CONTAINER",
|
||||
"-DLOSCFG_PID_CONTAINER",
|
||||
"-DLOSCFG_UTS_CONTAINER",
|
||||
"-DLOSCFG_MNT_CONTAINER",
|
||||
"-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",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
config("los_config") {
|
||||
configs = [
|
||||
":arch_config",
|
||||
@@ -249,6 +276,7 @@ config("los_config") {
|
||||
":ssp_config",
|
||||
":warn_config",
|
||||
":misc_config",
|
||||
":container_config",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -271,7 +299,7 @@ config("public") {
|
||||
|
||||
configs += [
|
||||
"$HDFTOPDIR:public",
|
||||
"//drivers/liteos:public",
|
||||
"$DRIVERS_LITEOS_DIR:public",
|
||||
]
|
||||
|
||||
if (HAVE_DEVICE_SDK) {
|
||||
@@ -296,8 +324,8 @@ group("modules") {
|
||||
]
|
||||
|
||||
deps += [
|
||||
"//drivers/liteos",
|
||||
HDFTOPDIR,
|
||||
"$DRIVERS_LITEOS_DIR",
|
||||
"$HDFTOPDIR",
|
||||
]
|
||||
|
||||
if (HAVE_DEVICE_SDK) {
|
||||
@@ -323,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" ]
|
||||
|
||||
256
CHANGELOG.md
256
CHANGELOG.md
@@ -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
|
||||
|
||||
7
Kconfig
7
Kconfig
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -58,6 +58,10 @@ APP_SUBDIRS += mksh
|
||||
APP_SUBDIRS += toybox
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_KERNEL_LMS), y)
|
||||
APP_SUBDIRS += lms
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_USER_INIT_DEBUG), y)
|
||||
APP_SUBDIRS += init
|
||||
endif
|
||||
|
||||
@@ -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" ]
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ int main(int argc, char * const *argv)
|
||||
printf("\n############### Lms Test start ###############\n");
|
||||
char *tmp = (char *)malloc(5000); /* 5000: test mem size */
|
||||
if (tmp == NULL) {
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
LmsMallocTest();
|
||||
LmsReallocTest();
|
||||
@@ -246,4 +246,5 @@ int main(int argc, char * const *argv)
|
||||
LmsFreeTest();
|
||||
free(tmp);
|
||||
printf("\n############### Lms Test End ###############\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
ShellCB *g_shellCB = NULL;
|
||||
|
||||
ShellCB *OsGetShellCb()
|
||||
ShellCB *OsGetShellCb(void)
|
||||
{
|
||||
return g_shellCB;
|
||||
}
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-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:
|
||||
@@ -74,6 +74,10 @@ extern "C" {
|
||||
/* not support prio */
|
||||
#define MQ_PRIO_MAX 1
|
||||
|
||||
#ifndef MAX_MQ_FD
|
||||
#define MAX_MQ_FD CONFIG_NQUEUE_DESCRIPTORS
|
||||
#endif
|
||||
|
||||
typedef union send_receive_t {
|
||||
unsigned oth : 3;
|
||||
unsigned grp : 6;
|
||||
@@ -424,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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-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:
|
||||
@@ -44,16 +44,19 @@
|
||||
|
||||
#define FNONBLOCK O_NONBLOCK
|
||||
|
||||
#ifndef MAX_MQ_FD
|
||||
#define MAX_MQ_FD CONFIG_NQUEUE_DESCRIPTORS
|
||||
#endif
|
||||
|
||||
#ifndef LOSCFG_IPC_CONTAINER
|
||||
/* GLOBALS */
|
||||
STATIC fd_set g_queueFdSet;
|
||||
STATIC struct mqarray g_queueTable[LOSCFG_BASE_IPC_QUEUE_LIMIT];
|
||||
STATIC pthread_mutex_t g_mqueueMutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
||||
STATIC struct mqpersonal *g_mqPrivBuf[MAX_MQ_FD];
|
||||
|
||||
#define IPC_QUEUE_FD_SET g_queueFdSet
|
||||
#define IPC_QUEUE_TABLE g_queueTable
|
||||
#define IPC_QUEUE_MUTEX g_mqueueMutex
|
||||
#define IPC_QUEUE_MQ_PRIV_BUF g_mqPrivBuf
|
||||
#endif
|
||||
|
||||
/* LOCAL FUNCTIONS */
|
||||
STATIC INLINE INT32 MqNameCheck(const CHAR *mqName)
|
||||
{
|
||||
@@ -96,12 +99,12 @@ STATIC INLINE struct mqarray *GetMqueueCBByName(const CHAR *name)
|
||||
UINT32 mylen = strlen(name);
|
||||
|
||||
for (index = 0; index < LOSCFG_BASE_IPC_QUEUE_LIMIT; index++) {
|
||||
if ((g_queueTable[index].mq_name == NULL) || (strlen(g_queueTable[index].mq_name) != mylen)) {
|
||||
if ((IPC_QUEUE_TABLE[index].mq_name == NULL) || (strlen(IPC_QUEUE_TABLE[index].mq_name) != mylen)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strncmp(name, (const CHAR *)(g_queueTable[index].mq_name), mylen) == 0) {
|
||||
return &(g_queueTable[index]);
|
||||
if (strncmp(name, (const CHAR *)(IPC_QUEUE_TABLE[index].mq_name), mylen) == 0) {
|
||||
return &(IPC_QUEUE_TABLE[index]);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
@@ -110,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;
|
||||
@@ -160,18 +165,36 @@ 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;
|
||||
}
|
||||
|
||||
if (g_queueTable[GET_QUEUE_INDEX(mqueueID)].mqcb == NULL) {
|
||||
mqueueCB = &(g_queueTable[GET_QUEUE_INDEX(mqueueID)]);
|
||||
if (IPC_QUEUE_TABLE[GET_QUEUE_INDEX(mqueueID)].mqcb == NULL) {
|
||||
mqueueCB = &(IPC_QUEUE_TABLE[GET_QUEUE_INDEX(mqueueID)]);
|
||||
mqueueCB->mq_id = mqueueID;
|
||||
}
|
||||
|
||||
@@ -198,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:
|
||||
@@ -215,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;
|
||||
}
|
||||
|
||||
@@ -297,7 +315,7 @@ STATIC struct mqpersonal *MqGetPrivDataBuff(mqd_t personal)
|
||||
errno = EBADF;
|
||||
return NULL;
|
||||
}
|
||||
return g_mqPrivBuf[id];
|
||||
return IPC_QUEUE_MQ_PRIV_BUF[id];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -311,13 +329,13 @@ STATIC struct mqpersonal *MqGetPrivDataBuff(mqd_t personal)
|
||||
STATIC INT32 MqAllocSysFd(int maxfdp, struct mqpersonal *privateMqPersonal)
|
||||
{
|
||||
INT32 i;
|
||||
fd_set *fdset = &g_queueFdSet;
|
||||
fd_set *fdset = &IPC_QUEUE_FD_SET;
|
||||
for (i = 0; i < maxfdp; i++) {
|
||||
/* sysFd: used bit setting, and get the index of swtmrID buffer */
|
||||
if (fdset && !(FD_ISSET(i + MQUEUE_FD_OFFSET, fdset))) {
|
||||
FD_SET(i + MQUEUE_FD_OFFSET, fdset);
|
||||
if (!g_mqPrivBuf[i]) {
|
||||
g_mqPrivBuf[i] = privateMqPersonal;
|
||||
if (!IPC_QUEUE_MQ_PRIV_BUF[i]) {
|
||||
IPC_QUEUE_MQ_PRIV_BUF[i] = privateMqPersonal;
|
||||
return i + MQUEUE_FD_OFFSET;
|
||||
}
|
||||
}
|
||||
@@ -328,10 +346,10 @@ STATIC INT32 MqAllocSysFd(int maxfdp, struct mqpersonal *privateMqPersonal)
|
||||
STATIC VOID MqFreeSysFd(mqd_t personal)
|
||||
{
|
||||
INT32 sysFd = (INT32)personal;
|
||||
fd_set *fdset = &g_queueFdSet;
|
||||
fd_set *fdset = &IPC_QUEUE_FD_SET;
|
||||
if (fdset && FD_ISSET(sysFd, fdset)) {
|
||||
FD_CLR(sysFd, fdset);
|
||||
g_mqPrivBuf[sysFd - MQUEUE_FD_OFFSET] = NULL;
|
||||
IPC_QUEUE_MQ_PRIV_BUF[sysFd - MQUEUE_FD_OFFSET] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,7 +359,7 @@ void MqueueRefer(int sysFd)
|
||||
struct mqarray *mqueueCB = NULL;
|
||||
struct mqpersonal *privateMqPersonal = NULL;
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
|
||||
/* Get the personal sysFd and reset personal fd -1 */
|
||||
privateMqPersonal = MqGetPrivDataBuff((mqd_t)sysFd);
|
||||
if (privateMqPersonal == NULL) {
|
||||
@@ -354,7 +372,7 @@ void MqueueRefer(int sysFd)
|
||||
|
||||
privateMqPersonal->mq_refcount++;
|
||||
OUT_UNLOCK:
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -498,7 +516,7 @@ mqd_t mq_open(const char *mqName, int openFlag, ...)
|
||||
return (mqd_t)-1;
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
|
||||
mqueueCB = GetMqueueCBByName(mqName);
|
||||
if ((UINT32)openFlag & (UINT32)O_CREAT) {
|
||||
if (mqueueCB != NULL) {
|
||||
@@ -543,7 +561,7 @@ mqd_t mq_open(const char *mqName, int openFlag, ...)
|
||||
mqFd = (mqd_t)sysFd;
|
||||
}
|
||||
OUT:
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return mqFd;
|
||||
}
|
||||
|
||||
@@ -552,7 +570,7 @@ int mq_close(mqd_t personal)
|
||||
INT32 ret = -1;
|
||||
struct mqpersonal *privateMqPersonal = NULL;
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
|
||||
|
||||
/* Get the personal sysFd and reset personal fd -1 */
|
||||
privateMqPersonal = MqGetPrivDataBuff(personal);
|
||||
@@ -577,7 +595,7 @@ int mq_close(mqd_t personal)
|
||||
MqFreeSysFd(personal);
|
||||
|
||||
OUT_UNLOCK:
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -596,10 +614,10 @@ int OsMqGetAttr(mqd_t personal, struct mq_attr *mqAttr)
|
||||
return -1;
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
|
||||
if (privateMqPersonal->mq_status != MQ_USE_MAGIC) {
|
||||
errno = EBADF;
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -608,7 +626,7 @@ int OsMqGetAttr(mqd_t personal, struct mq_attr *mqAttr)
|
||||
mqAttr->mq_msgsize = mqueueCB->mqcb->queueSize - sizeof(UINT32);
|
||||
mqAttr->mq_curmsgs = mqueueCB->mqcb->readWriteableCnt[OS_QUEUE_READ];
|
||||
mqAttr->mq_flags = privateMqPersonal->mq_flags;
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -626,10 +644,10 @@ int OsMqSetAttr(mqd_t personal, const struct mq_attr *mqSetAttr, struct mq_attr
|
||||
return -1;
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
|
||||
if (privateMqPersonal->mq_status != MQ_USE_MAGIC) {
|
||||
errno = EBADF;
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -641,7 +659,7 @@ int OsMqSetAttr(mqd_t personal, const struct mq_attr *mqSetAttr, struct mq_attr
|
||||
if (((UINT32)mqSetAttr->mq_flags & (UINT32)FNONBLOCK) == (UINT32)FNONBLOCK) {
|
||||
privateMqPersonal->mq_flags = (INT32)((UINT32)privateMqPersonal->mq_flags | (UINT32)FNONBLOCK);
|
||||
}
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -662,7 +680,7 @@ int mq_unlink(const char *mqName)
|
||||
return -1;
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
|
||||
mqueueCB = GetMqueueCBByName(mqName);
|
||||
if (mqueueCB == NULL) {
|
||||
errno = ENOENT;
|
||||
@@ -675,11 +693,11 @@ int mq_unlink(const char *mqName)
|
||||
ret = DoMqueueDelete(mqueueCB);
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return ret;
|
||||
|
||||
ERROUT_UNLOCK:
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -767,7 +785,7 @@ int mq_timedsend(mqd_t personal, const char *msg, size_t msgLen, unsigned int ms
|
||||
OS_MQ_GOTO_ERROUT_IF(!MqParamCheck(personal, msg, msgLen), errno);
|
||||
OS_MQ_GOTO_ERROUT_IF(msgPrio > (MQ_PRIO_MAX - 1), EINVAL);
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
|
||||
privateMqPersonal = MqGetPrivDataBuff(personal);
|
||||
|
||||
OS_MQ_GOTO_ERROUT_UNLOCK_IF(privateMqPersonal == NULL || privateMqPersonal->mq_status != MQ_USE_MAGIC, EBADF);
|
||||
@@ -781,7 +799,7 @@ int mq_timedsend(mqd_t personal, const char *msg, size_t msgLen, unsigned int ms
|
||||
|
||||
OS_MQ_GOTO_ERROUT_UNLOCK_IF(ConvertTimeout(privateMqPersonal->mq_flags, absTimeout, &absTicks) == -1, errno);
|
||||
mqueueID = mqueueCB->mq_id;
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
|
||||
if (LOS_ListEmpty(&mqueueCB->mqcb->readWriteList[OS_QUEUE_READ])) {
|
||||
MqSendNotify(mqueueCB);
|
||||
@@ -793,7 +811,7 @@ int mq_timedsend(mqd_t personal, const char *msg, size_t msgLen, unsigned int ms
|
||||
}
|
||||
return 0;
|
||||
ERROUT_UNLOCK:
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
ERROUT:
|
||||
return -1;
|
||||
}
|
||||
@@ -815,7 +833,7 @@ ssize_t mq_timedreceive(mqd_t personal, char *msg, size_t msgLen, unsigned int *
|
||||
*msgPrio = 0;
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
|
||||
privateMqPersonal = MqGetPrivDataBuff(personal);
|
||||
if (privateMqPersonal == NULL || privateMqPersonal->mq_status != MQ_USE_MAGIC) {
|
||||
errno = EBADF;
|
||||
@@ -839,7 +857,7 @@ ssize_t mq_timedreceive(mqd_t personal, char *msg, size_t msgLen, unsigned int *
|
||||
|
||||
receiveLen = msgLen;
|
||||
mqueueID = mqueueCB->mq_id;
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
|
||||
err = LOS_QueueReadCopy(mqueueID, (VOID *)msg, &receiveLen, (UINT32)absTicks);
|
||||
if (map_errno(err) == ENOERR) {
|
||||
@@ -849,7 +867,7 @@ ssize_t mq_timedreceive(mqd_t personal, char *msg, size_t msgLen, unsigned int *
|
||||
}
|
||||
|
||||
ERROUT_UNLOCK:
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
ERROUT:
|
||||
return -1;
|
||||
}
|
||||
@@ -898,7 +916,7 @@ int OsMqNotify(mqd_t personal, const struct sigevent *sigev)
|
||||
goto ERROUT;
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
|
||||
privateMqPersonal = MqGetPrivDataBuff(personal);
|
||||
if (privateMqPersonal == NULL) {
|
||||
goto OUT_UNLOCK;
|
||||
@@ -936,11 +954,26 @@ int OsMqNotify(mqd_t personal, const struct sigevent *sigev)
|
||||
mqnotify->pid = LOS_GetCurrProcessID();
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
return 0;
|
||||
OUT_UNLOCK:
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
|
||||
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
|
||||
|
||||
@@ -599,13 +599,22 @@ int clock_gettime(clockid_t clockID, struct timespec *tp)
|
||||
|
||||
switch (clockID) {
|
||||
case CLOCK_MONOTONIC_RAW:
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
tmp = OsTimeSpecAdd(hwTime, CLOCK_MONOTONIC_TIME_BASE);
|
||||
tp->tv_sec = tmp.tv_sec;
|
||||
tp->tv_nsec = tmp.tv_nsec;
|
||||
#else
|
||||
tp->tv_sec = hwTime.tv_sec;
|
||||
tp->tv_nsec = hwTime.tv_nsec;
|
||||
#endif
|
||||
break;
|
||||
case CLOCK_MONOTONIC:
|
||||
LOS_SpinLockSave(&g_timeSpin, &intSave);
|
||||
tmp = OsTimeSpecAdd(hwTime, g_accDeltaFromAdj);
|
||||
LOS_SpinUnlockRestore(&g_timeSpin, intSave);
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
tmp = OsTimeSpecAdd(tmp, CLOCK_MONOTONIC_TIME_BASE);
|
||||
#endif
|
||||
tp->tv_sec = tmp.tv_sec;
|
||||
tp->tv_nsec = tmp.tv_nsec;
|
||||
break;
|
||||
@@ -639,7 +648,7 @@ int clock_gettime(clockid_t clockID, struct timespec *tp)
|
||||
|
||||
return 0;
|
||||
|
||||
ERROUT:
|
||||
ERROUT:
|
||||
TIME_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -42,13 +42,13 @@ static int SysMemInfoFill(struct SeqBuf *seqBuf, void *arg)
|
||||
if (LOS_MemInfoGet(m_aucSysMem0, &mem) == LOS_NOK) {
|
||||
return -EBADF;
|
||||
}
|
||||
(void)LosBufPrintf(seqBuf, "\nUsedSize:%25u KB\n", mem.totalUsedSize);
|
||||
(void)LosBufPrintf(seqBuf, "FreeSize:%25u KB\n", mem.totalFreeSize);
|
||||
(void)LosBufPrintf(seqBuf, "MaxFreeNodeSize:%18u KB\n", mem.maxFreeNodeSize);
|
||||
(void)LosBufPrintf(seqBuf, "UsedNodeNum:%22u KB\n", mem.usedNodeNum);
|
||||
(void)LosBufPrintf(seqBuf, "FreeNodeNum:%22u KB\n", mem.freeNodeNum);
|
||||
(void)LosBufPrintf(seqBuf, "\nUsedSize: %u byte\n", mem.totalUsedSize);
|
||||
(void)LosBufPrintf(seqBuf, "FreeSize: %u byte\n", mem.totalFreeSize);
|
||||
(void)LosBufPrintf(seqBuf, "MaxFreeNodeSize: %u byte\n", mem.maxFreeNodeSize);
|
||||
(void)LosBufPrintf(seqBuf, "UsedNodeNum: %u\n", mem.usedNodeNum);
|
||||
(void)LosBufPrintf(seqBuf, "FreeNodeNum: %u\n", mem.freeNodeNum);
|
||||
#ifdef LOSCFG_MEM_WATERLINE
|
||||
(void)LosBufPrintf(seqBuf, "UsageWaterLine:%19u KB\n", mem.freeNodeNum);
|
||||
(void)LosBufPrintf(seqBuf, "UsageWaterLine: %u byte\n", mem.usageWaterLine);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
905
fs/proc/os_adapt/plimits_proc.c
Normal file
905
fs/proc/os_adapt/plimits_proc.c
Normal 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
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -125,10 +125,16 @@ int VfsProcfsRead(struct file *filep, char *buffer, size_t buflen)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
VnodeHold();
|
||||
entry = VnodeToEntry(filep->f_vnode);
|
||||
if (entry == NULL) {
|
||||
VnodeDrop();
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
size = (ssize_t)ReadProcFile(entry, (void *)buffer, buflen);
|
||||
filep->f_pos = entry->pf->fPos;
|
||||
|
||||
VnodeDrop();
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -140,10 +146,16 @@ int VfsProcfsWrite(struct file *filep, const char *buffer, size_t buflen)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
VnodeHold();
|
||||
entry = VnodeToEntry(filep->f_vnode);
|
||||
if (entry == NULL) {
|
||||
VnodeDrop();
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
size = (ssize_t)WriteProcFile(entry, (void *)buffer, buflen);
|
||||
filep->f_pos = entry->pf->fPos;
|
||||
|
||||
VnodeDrop();
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -156,6 +168,7 @@ int VfsProcfsLookup(struct Vnode *parent, const char *name, int len, struct Vnod
|
||||
if (entry == NULL) {
|
||||
return -ENODATA;
|
||||
}
|
||||
|
||||
entry = entry->subdir;
|
||||
while (1) {
|
||||
if (entry == NULL) {
|
||||
@@ -214,21 +227,70 @@ int VfsProcfsUnmount(void *handle, struct Vnode **blkdriver)
|
||||
|
||||
int VfsProcfsStat(struct Vnode *node, struct stat *buf)
|
||||
{
|
||||
VnodeHold();
|
||||
struct ProcDirEntry *entry = VnodeToEntry(node);
|
||||
|
||||
if (entry == NULL) {
|
||||
VnodeDrop();
|
||||
return -EPERM;
|
||||
}
|
||||
(void)memset_s(buf, sizeof(struct stat), 0, sizeof(struct stat));
|
||||
buf->st_mode = entry->mode;
|
||||
|
||||
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;
|
||||
char *buffer = NULL;
|
||||
int buflen = NAME_MAX;
|
||||
unsigned int min_size;
|
||||
unsigned int dst_name_size;
|
||||
unsigned int minSize, dstNameSize;
|
||||
struct ProcDirEntry *pde = NULL;
|
||||
int i = 0;
|
||||
|
||||
@@ -238,28 +300,35 @@ int VfsProcfsReaddir(struct Vnode *node, struct fs_dirent_s *dir)
|
||||
if (node->type != VNODE_TYPE_DIR) {
|
||||
return -ENOTDIR;
|
||||
}
|
||||
VnodeHold();
|
||||
pde = VnodeToEntry(node);
|
||||
if (pde == NULL) {
|
||||
VnodeDrop();
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
while (i < dir->read_cnt) {
|
||||
buffer = (char *)zalloc(sizeof(char) * NAME_MAX);
|
||||
if (buffer == NULL) {
|
||||
VnodeDrop();
|
||||
PRINT_ERR("malloc failed\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
result = ReadProcFile(pde, (void *)buffer, buflen);
|
||||
result = ReadProcFile(pde, (void *)buffer, NAME_MAX);
|
||||
if (result != ENOERR) {
|
||||
free(buffer);
|
||||
break;
|
||||
}
|
||||
dst_name_size = sizeof(dir->fd_dir[i].d_name);
|
||||
min_size = (dst_name_size < NAME_MAX) ? dst_name_size : NAME_MAX;
|
||||
result = strncpy_s(dir->fd_dir[i].d_name, dst_name_size, buffer, min_size);
|
||||
dstNameSize = sizeof(dir->fd_dir[i].d_name);
|
||||
minSize = (dstNameSize < NAME_MAX) ? dstNameSize : NAME_MAX;
|
||||
result = strncpy_s(dir->fd_dir[i].d_name, dstNameSize, buffer, minSize);
|
||||
if (result != EOK) {
|
||||
VnodeDrop();
|
||||
free(buffer);
|
||||
return -ENAMETOOLONG;
|
||||
}
|
||||
dir->fd_dir[i].d_name[dst_name_size - 1] = '\0';
|
||||
dir->fd_dir[i].d_name[dstNameSize - 1] = '\0';
|
||||
dir->fd_position++;
|
||||
dir->fd_dir[i].d_off = dir->fd_position;
|
||||
dir->fd_dir[i].d_reclen = (uint16_t)sizeof(struct dirent);
|
||||
@@ -267,21 +336,26 @@ int VfsProcfsReaddir(struct Vnode *node, struct fs_dirent_s *dir)
|
||||
i++;
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
VnodeDrop();
|
||||
return i;
|
||||
}
|
||||
|
||||
int VfsProcfsOpendir(struct Vnode *node, struct fs_dirent_s *dir)
|
||||
{
|
||||
VnodeHold();
|
||||
struct ProcDirEntry *pde = VnodeToEntry(node);
|
||||
if (pde == NULL) {
|
||||
VnodeDrop();
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
pde->pdirCurrent = pde->subdir;
|
||||
if (pde->pf == NULL) {
|
||||
VnodeDrop();
|
||||
return -EINVAL;
|
||||
}
|
||||
pde->pf->fPos = 0;
|
||||
VnodeDrop();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
@@ -290,8 +364,14 @@ int VfsProcfsOpen(struct file *filep)
|
||||
if (filep == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
VnodeHold();
|
||||
struct Vnode *node = filep->f_vnode;
|
||||
struct ProcDirEntry *pde = VnodeToEntry(node);
|
||||
if (pde == NULL) {
|
||||
VnodeDrop();
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
if (ProcOpen(pde->pf) != OK) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
@@ -303,6 +383,7 @@ int VfsProcfsOpen(struct file *filep)
|
||||
pde->pf->fPos = 0;
|
||||
}
|
||||
filep->f_priv = (void *)pde;
|
||||
VnodeDrop();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
@@ -312,15 +393,22 @@ int VfsProcfsClose(struct file *filep)
|
||||
if (filep == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
VnodeHold();
|
||||
struct Vnode *node = filep->f_vnode;
|
||||
struct ProcDirEntry *pde = VnodeToEntry(node);
|
||||
if ((pde == NULL) || (pde->pf == NULL)) {
|
||||
VnodeDrop();
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
VnodeDrop();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -345,6 +433,10 @@ ssize_t VfsProcfsReadlink(struct Vnode *vnode, char *buffer, size_t bufLen)
|
||||
}
|
||||
|
||||
struct ProcDirEntry *pde = VnodeToEntry(vnode);
|
||||
if (pde == NULL) {
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
if ((pde->procFileOps != NULL) && (pde->procFileOps->readLink != NULL)) {
|
||||
result = pde->procFileOps->readLink(pde, buffer, bufLen);
|
||||
}
|
||||
@@ -365,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 = {
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#include "proc_fs.h"
|
||||
#include "internal.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "user_copy.h"
|
||||
#include "los_memory.h"
|
||||
|
||||
#ifdef LOSCFG_PROC_PROCESS_DIR
|
||||
#include "los_vm_dump.h"
|
||||
@@ -44,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 {
|
||||
@@ -58,18 +65,34 @@ struct ProcessData {
|
||||
unsigned int type;
|
||||
};
|
||||
|
||||
static LosProcessCB *ProcGetProcessCB(struct ProcessData *data)
|
||||
{
|
||||
if (data->process != 0) {
|
||||
return (LosProcessCB *)data->process;
|
||||
}
|
||||
return OsCurrProcessGet();
|
||||
}
|
||||
|
||||
#define PROC_PID_PRIVILEGE 7
|
||||
#define PROC_PID_DIR_LEN 100
|
||||
#ifdef LOSCFG_KERNEL_CONTAINER
|
||||
static ssize_t ProcessContainerLink(unsigned int containerID, ContainerType type, char *buffer, size_t bufLen)
|
||||
{
|
||||
ssize_t count = -1;
|
||||
if (type == PID_CONTAINER) {
|
||||
if ((type == PID_CONTAINER) || (type == PID_CHILD_CONTAINER)) {
|
||||
count = snprintf_s(buffer, bufLen, bufLen - 1, "'pid:[%u]'", containerID);
|
||||
} else if (type == UTS_CONTAINER) {
|
||||
count = snprintf_s(buffer, bufLen, bufLen - 1, "'uts:[%u]'", containerID);
|
||||
} else if (type == MNT_CONTAINER) {
|
||||
count = snprintf_s(buffer, bufLen, bufLen - 1, "'mnt:[%u]'", containerID);
|
||||
} else if (type == IPC_CONTAINER) {
|
||||
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) {
|
||||
@@ -80,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) {
|
||||
@@ -89,23 +114,79 @@ static ssize_t ProcessContainerReadLink(struct ProcDirEntry *entry, char *buffer
|
||||
if (data == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
LosProcessCB *processCB = (LosProcessCB *)data->process;
|
||||
|
||||
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)
|
||||
@@ -129,19 +210,18 @@ static int ProcessMemInfoRead(struct SeqBuf *seqBuf, LosProcessCB *pcb)
|
||||
(void)memcpy_s(heap, sizeof(LosVmMapRegion), pcb->vmSpace->heap, sizeof(LosVmMapRegion));
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
(void)LosBufPrintf(seqBuf, "\nVMSpaceSize: %u KB\n", vmSpace->size);
|
||||
(void)LosBufPrintf(seqBuf, "VMRegionSize: %u KB\n", heap->range.size);
|
||||
(void)LosBufPrintf(seqBuf, "RegionFlags: %s\n", OsGetRegionNameOrFilePath(heap));
|
||||
(void)LosBufPrintf(seqBuf, "ShmidAboutSharedRegion: %u\n", heap->shmid);
|
||||
(void)LosBufPrintf(seqBuf, "VMSpaceRorkFlags: 0x%x\n", heap->forkFlags);
|
||||
(void)LosBufPrintf(seqBuf, "VMRegionRype: 0x%x\n", heap->regionType);
|
||||
(void)LosBufPrintf(seqBuf, "VMSpaceMappingAreaSize: %u KB\n", vmSpace->mapSize);
|
||||
(void)LosBufPrintf(seqBuf, "TLB Asid: %u\n", vmSpace->archMmu.asid);
|
||||
(void)LosBufPrintf(seqBuf, "\nVMSpaceSize: %u byte\n", vmSpace->size);
|
||||
(void)LosBufPrintf(seqBuf, "VMSpaceMapSize: %u byte\n", vmSpace->mapSize);
|
||||
(void)LosBufPrintf(seqBuf, "VM TLB Asid: %u\n", vmSpace->archMmu.asid);
|
||||
(void)LosBufPrintf(seqBuf, "VMHeapSize: %u byte\n", heap->range.size);
|
||||
(void)LosBufPrintf(seqBuf, "VMHeapRegionName: %s\n", OsGetRegionNameOrFilePath(heap));
|
||||
(void)LosBufPrintf(seqBuf, "VMHeapRegionType: 0x%x\n", heap->regionType);
|
||||
(void)LOS_MemFree(m_aucSysMem1, vmSpace);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
#define TIME_CYCLE_TO_US(time) ((((UINT64)time) * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US)
|
||||
static int ProcessCpupRead(struct SeqBuf *seqBuf, LosProcessCB *pcb)
|
||||
{
|
||||
unsigned int intSave;
|
||||
@@ -160,11 +240,10 @@ static int ProcessCpupRead(struct SeqBuf *seqBuf, LosProcessCB *pcb)
|
||||
(void)memcpy_s(processCpup, sizeof(OsCpupBase), pcb->processCpup, sizeof(OsCpupBase));
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
(void)LosBufPrintf(seqBuf, "\nTotalRunningTime: %lu\n", processCpup->allTime);
|
||||
(void)LosBufPrintf(seqBuf, "StartTime: %lu\n", processCpup->startTime);
|
||||
(void)LosBufPrintf(seqBuf, "HistoricalRunningTime: ");
|
||||
(void)LosBufPrintf(seqBuf, "\nTotalRunningTime: %lu us\n", TIME_CYCLE_TO_US(processCpup->allTime));
|
||||
(void)LosBufPrintf(seqBuf, "HistoricalRunningTime:(us) ");
|
||||
for (UINT32 i = 0; i < OS_CPUP_HISTORY_RECORD_NUM + 1; i++) {
|
||||
(void)LosBufPrintf(seqBuf, "%lu ", processCpup->historyTime[i]);
|
||||
(void)LosBufPrintf(seqBuf, "%lu ", TIME_CYCLE_TO_US(processCpup->historyTime[i]));
|
||||
}
|
||||
(void)LosBufPrintf(seqBuf, "\n");
|
||||
(void)LOS_MemFree(m_aucSysMem1, processCpup);
|
||||
@@ -172,6 +251,225 @@ static int ProcessCpupRead(struct SeqBuf *seqBuf, LosProcessCB *pcb)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
static const CHAR *g_monotonic = "monotonic";
|
||||
#define DECIMAL_BASE 10
|
||||
|
||||
static int ProcTimeContainerRead(struct SeqBuf *m, void *v)
|
||||
{
|
||||
int ret;
|
||||
unsigned int intSave;
|
||||
struct timespec64 offsets = {0};
|
||||
|
||||
if ((m == NULL) || (v == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
struct ProcessData *data = (struct ProcessData *)v;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LosProcessCB *processCB = ProcGetProcessCB(data);
|
||||
ret = OsGetTimeContainerMonotonic(processCB, &offsets);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if (ret != LOS_OK) {
|
||||
return -ret;
|
||||
}
|
||||
|
||||
LosBufPrintf(m, "monotonic %lld %ld\n", offsets.tv_sec, offsets.tv_nsec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ProcSetTimensOffset(const char *buf, LosProcessCB *processCB)
|
||||
{
|
||||
unsigned int intSave;
|
||||
struct timespec64 offsets;
|
||||
char *endptr = NULL;
|
||||
|
||||
offsets.tv_sec = strtoll(buf, &endptr, DECIMAL_BASE);
|
||||
offsets.tv_nsec = strtoll(endptr, NULL, DECIMAL_BASE);
|
||||
if (offsets.tv_nsec >= OS_SYS_NS_PER_SECOND) {
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
unsigned int ret = OsSetTimeContainerMonotonic(processCB, &offsets);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if (ret != LOS_OK) {
|
||||
return -ret;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ProcTimeContainerWrite(struct ProcFile *pf, const char *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
(void)ppos;
|
||||
char *kbuf = NULL;
|
||||
int ret;
|
||||
|
||||
if ((pf == NULL) || (count <= 0)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
struct ProcDirEntry *entry = pf->pPDE;
|
||||
if (entry == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
struct ProcessData *data = (struct ProcessData *)entry->data;
|
||||
if (data == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)buf, count)) {
|
||||
kbuf = LOS_MemAlloc(m_aucSysMem1, count + 1);
|
||||
if (kbuf == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (LOS_ArchCopyFromUser(kbuf, buf, count) != 0) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, kbuf);
|
||||
return -EFAULT;
|
||||
}
|
||||
kbuf[count] = '\0';
|
||||
buf = kbuf;
|
||||
}
|
||||
|
||||
ret = strncmp(buf, g_monotonic, strlen(g_monotonic));
|
||||
if (ret != 0) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, kbuf);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
buf += strlen(g_monotonic);
|
||||
ret = ProcSetTimensOffset(buf, ProcGetProcessCB(data));
|
||||
if (ret < 0) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, kbuf);
|
||||
return ret;
|
||||
}
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, kbuf);
|
||||
return count;
|
||||
}
|
||||
|
||||
static const struct ProcFileOperations TIME_CONTAINER_FOPS = {
|
||||
.read = ProcTimeContainerRead,
|
||||
.write = ProcTimeContainerWrite,
|
||||
};
|
||||
#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)) {
|
||||
@@ -180,10 +478,10 @@ static int ProcProcessRead(struct SeqBuf *m, void *v)
|
||||
struct ProcessData *data = (struct ProcessData *)v;
|
||||
switch (data->type) {
|
||||
case PROC_PID_MEM:
|
||||
return ProcessMemInfoRead(m, (LosProcessCB *)data->process);
|
||||
return ProcessMemInfoRead(m, ProcGetProcessCB(data));
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
case PROC_PID_CPUP:
|
||||
return ProcessCpupRead(m, (LosProcessCB *)data->process);
|
||||
return ProcessCpupRead(m, ProcGetProcessCB(data));
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
@@ -198,7 +496,7 @@ static const struct ProcFileOperations PID_FOPS = {
|
||||
static struct ProcProcess g_procProcess[] = {
|
||||
{
|
||||
.name = NULL,
|
||||
.mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH,
|
||||
.mode = S_IFDIR | S_IRWXU | S_IRWXG | S_IROTH,
|
||||
.type = PROC_PID,
|
||||
.fileOps = &PID_FOPS
|
||||
|
||||
@@ -233,6 +531,12 @@ static struct ProcProcess g_procProcess[] = {
|
||||
.type = PID_CONTAINER,
|
||||
.fileOps = &PID_CONTAINER_FOPS
|
||||
},
|
||||
{
|
||||
.name = "container/pid_for_children",
|
||||
.mode = S_IFLNK,
|
||||
.type = PID_CHILD_CONTAINER,
|
||||
.fileOps = &PID_CONTAINER_FOPS
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
{
|
||||
@@ -250,6 +554,62 @@ static struct ProcProcess g_procProcess[] = {
|
||||
.fileOps = &PID_CONTAINER_FOPS
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
{
|
||||
.name = "container/ipc",
|
||||
.mode = S_IFLNK,
|
||||
.type = IPC_CONTAINER,
|
||||
.fileOps = &PID_CONTAINER_FOPS
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
{
|
||||
.name = "container/time",
|
||||
.mode = S_IFLNK,
|
||||
.type = TIME_CONTAINER,
|
||||
.fileOps = &PID_CONTAINER_FOPS
|
||||
},
|
||||
{
|
||||
.name = "container/time_for_children",
|
||||
.mode = S_IFLNK,
|
||||
.type = TIME_CHILD_CONTAINER,
|
||||
.fileOps = &PID_CONTAINER_FOPS
|
||||
},
|
||||
{
|
||||
.name = "time_offsets",
|
||||
.mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
|
||||
.type = TIME_CONTAINER,
|
||||
.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
|
||||
};
|
||||
|
||||
@@ -264,15 +624,24 @@ 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) {
|
||||
return NULL;
|
||||
}
|
||||
if (porcess->name != NULL) {
|
||||
ret = snprintf_s(pidName, PROC_PID_DIR_LEN, PROC_PID_DIR_LEN - 1, "%u/%s", pid, porcess->name);
|
||||
if (pid != OS_INVALID_VALUE) {
|
||||
if (porcess->name != NULL) {
|
||||
ret = snprintf_s(pidName, PROC_PID_DIR_LEN, PROC_PID_DIR_LEN - 1, "%u/%s", pid, porcess->name);
|
||||
} else {
|
||||
ret = snprintf_s(pidName, PROC_PID_DIR_LEN, PROC_PID_DIR_LEN - 1, "%u", pid);
|
||||
}
|
||||
} else {
|
||||
ret = snprintf_s(pidName, PROC_PID_DIR_LEN, PROC_PID_DIR_LEN - 1, "%u", pid);
|
||||
if (porcess->name != NULL) {
|
||||
ret = snprintf_s(pidName, PROC_PID_DIR_LEN, PROC_PID_DIR_LEN - 1, "%s/%s", "self", porcess->name);
|
||||
} else {
|
||||
ret = snprintf_s(pidName, PROC_PID_DIR_LEN, PROC_PID_DIR_LEN - 1, "%s", "self");
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
free(data);
|
||||
@@ -281,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);
|
||||
@@ -306,9 +677,12 @@ int ProcCreateProcessDir(UINT32 pid, uintptr_t process)
|
||||
}
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
((LosProcessCB *)process)->procDir = pidDir;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if (process != 0) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
((LosProcessCB *)process)->procDir = pidDir;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
CREATE_ERROR:
|
||||
@@ -340,7 +714,12 @@ void ProcProcessInit(void)
|
||||
pde->procFileOps = &PROCESS_PROC_FOPS;
|
||||
|
||||
#ifdef LOSCFG_PROC_PROCESS_DIR
|
||||
int ret = ProcCreateProcessDir(OS_USER_ROOT_PROCESS_ID, (uintptr_t)OsGetUserInitProcess());
|
||||
int ret = ProcCreateProcessDir(OS_INVALID_VALUE, 0);
|
||||
if (ret < 0) {
|
||||
PRINT_ERR("Create proc process self dir failed!\n");
|
||||
}
|
||||
|
||||
ret = ProcCreateProcessDir(OS_USER_ROOT_PROCESS_ID, (uintptr_t)OsGetUserInitProcess());
|
||||
if (ret < 0) {
|
||||
PRINT_ERR("Create proc process %d dir failed!\n", OS_USER_ROOT_PROCESS_ID);
|
||||
}
|
||||
|
||||
228
fs/proc/os_adapt/sys_user.c
Normal file
228
fs/proc/os_adapt/sys_user.c
Normal 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
|
||||
@@ -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,19 +379,39 @@ struct ProcDirEntry *CreateProcEntry(const char *name, mode_t mode, struct ProcD
|
||||
return pde;
|
||||
}
|
||||
|
||||
void ProcEntryClearVnode(struct ProcDirEntry *entry)
|
||||
{
|
||||
struct Vnode *item = NULL;
|
||||
struct Vnode *nextItem = NULL;
|
||||
|
||||
VnodeHold();
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, GetVnodeActiveList(), struct Vnode, actFreeEntry) {
|
||||
if ((struct ProcDirEntry *)item->data != entry) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (VnodeFree(item) != LOS_OK) {
|
||||
PRINT_ERR("ProcEntryClearVnode free failed, entry: %s\n", entry->name);
|
||||
}
|
||||
}
|
||||
VnodeDrop();
|
||||
return;
|
||||
}
|
||||
|
||||
static void FreeProcEntry(struct ProcDirEntry *entry)
|
||||
{
|
||||
if (entry == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
entry->data = NULL;
|
||||
free(entry);
|
||||
}
|
||||
|
||||
@@ -401,7 +422,7 @@ void ProcFreeEntry(struct ProcDirEntry *pn)
|
||||
}
|
||||
}
|
||||
|
||||
static void RemoveProcEntryTravalsal(struct ProcDirEntry *pn)
|
||||
void RemoveProcEntryTravalsal(struct ProcDirEntry *pn)
|
||||
{
|
||||
if (pn == NULL) {
|
||||
return;
|
||||
@@ -409,6 +430,8 @@ static void RemoveProcEntryTravalsal(struct ProcDirEntry *pn)
|
||||
RemoveProcEntryTravalsal(pn->next);
|
||||
RemoveProcEntryTravalsal(pn->subdir);
|
||||
|
||||
ProcEntryClearVnode(pn);
|
||||
|
||||
ProcFreeEntry(pn);
|
||||
}
|
||||
|
||||
@@ -438,6 +461,9 @@ void RemoveProcEntry(const char *name, struct ProcDirEntry *parent)
|
||||
spin_unlock(&procfsLock);
|
||||
|
||||
RemoveProcEntryTravalsal(pn->subdir);
|
||||
|
||||
ProcEntryClearVnode(pn);
|
||||
|
||||
ProcFreeEntry(pn);
|
||||
}
|
||||
|
||||
@@ -452,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;
|
||||
}
|
||||
@@ -562,21 +591,17 @@ static int ProcRead(struct ProcDirEntry *pde, char *buf, size_t len)
|
||||
|
||||
struct ProcDirEntry *OpenProcFile(const char *fileName, int flags, ...)
|
||||
{
|
||||
unsigned int intSave;
|
||||
struct ProcDirEntry *pn = ProcFindEntry(fileName);
|
||||
if (pn == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (S_ISREG(pn->mode) && (pn->count != 1)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pn->flags = (unsigned int)(pn->flags) | (unsigned int)flags;
|
||||
atomic_set(&pn->count, PROC_INUSE);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if (ProcOpen(pn->pf) != OK) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -625,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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_ */
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -67,31 +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 options of extended #####################
|
||||
source "kernel/extended/Kconfig"
|
||||
|
||||
@@ -32,10 +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_mnt_container.c",
|
||||
"container/los_pid_container.c",
|
||||
"container/los_uts_container.c",
|
||||
"core/los_bitmap.c",
|
||||
"core/los_info.c",
|
||||
"core/los_process.c",
|
||||
@@ -71,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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,166 +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);
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
(VOID)OsInitRootUtsContainer(&g_rootContainer.utsContainer);
|
||||
#endif
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
(VOID)OsInitRootMntContainer(&g_rootContainer.mntContainer);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC INLINE Container *CreateContainer(VOID)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
UINT32 ret = LOS_OK;
|
||||
|
||||
if (!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET))) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
child->container = parent->container;
|
||||
LOS_AtomicInc(&child->container->rc);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
} else {
|
||||
child->container = CreateContainer();
|
||||
if (child->container == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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
|
||||
return ret;
|
||||
}
|
||||
|
||||
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) {
|
||||
OsPidContainersDestroyAllProcess(processCB);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
OsUtsContainersDestroy(processCB);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
OsMntContainersDestroy(processCB);
|
||||
#endif
|
||||
|
||||
#ifndef LOSCFG_PID_CONTAINER
|
||||
LOS_AtomicDec(&curr->container->rc);
|
||||
if (LOS_AtomicRead(&processCB->container->rc) == 1) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, processCB->container);
|
||||
processCB->container = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
UINT32 OsGetContainerID(Container *container, ContainerType type)
|
||||
{
|
||||
if (container == NULL) {
|
||||
return OS_INVALID_VALUE;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case PID_CONTAINER:
|
||||
return OsGetPidContainerID(container->pidContainer);
|
||||
case UTS_CONTAINER:
|
||||
return OsGetUtsContainerID(container->utsContainer);
|
||||
case MNT_CONTAINER:
|
||||
return OsGetMntContainerID(container->mntContainer);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return OS_INVALID_VALUE;
|
||||
}
|
||||
#endif
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ LITE_OS_SEC_BSS ProcessGroup *g_processGroup = NULL;
|
||||
STATIC INLINE VOID OsInsertPCBToFreeList(LosProcessCB *processCB)
|
||||
{
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
OsPidContainersDestroy(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);
|
||||
@@ -398,13 +404,6 @@ LITE_OS_SEC_TEXT VOID OsProcessResourcesToFree(LosProcessCB *processCB)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
if (OsProcessIsUserMode(processCB)) {
|
||||
delete_files(processCB->files);
|
||||
}
|
||||
processCB->files = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_SECURITY_CAPABILITY
|
||||
if (processCB->user != NULL) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, processCB->user);
|
||||
@@ -442,10 +441,24 @@ LITE_OS_SEC_TEXT VOID OsProcessResourcesToFree(LosProcessCB *processCB)
|
||||
processCB->procDir = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_KERNEL_CONTAINER
|
||||
OsOsContainersDestroyEarly(processCB);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
if (OsProcessIsUserMode(processCB)) {
|
||||
delete_files(processCB->files);
|
||||
}
|
||||
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, ¶m, prio)) {
|
||||
ret = LOS_EPERM;
|
||||
goto EXIT;
|
||||
}
|
||||
#endif
|
||||
|
||||
LosTaskCB *taskCB = processCB->threadGroup;
|
||||
taskCB->ops->schedParamGet(taskCB, ¶m);
|
||||
param.basePrio = prio;
|
||||
|
||||
BOOL needSched = taskCB->ops->schedParamModify(taskCB, ¶m);
|
||||
#ifdef LOSCFG_SECURITY_CAPABILITY
|
||||
if (!OsProcessCapPermitCheck(processCB, ¶m, 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, ¶m);
|
||||
|
||||
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, ¶m);
|
||||
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, ¶m);
|
||||
}
|
||||
|
||||
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, ¶m);
|
||||
|
||||
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, ¶m);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
taskParam.pcName = (CHAR *)name;
|
||||
taskParam.policy = param.policy;
|
||||
taskParam.usTaskPrio = param.priority;
|
||||
taskParam.processID = (UINTPTR)childProcessCB;
|
||||
GetCopyTaskParam(childProcessCB, entry, size, &taskParam, ¶m);
|
||||
|
||||
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)
|
||||
@@ -1893,7 +2047,7 @@ STATIC UINT32 OsCopyMM(UINT32 flags, LosProcessCB *childProcessCB, LosProcessCB
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
status = LOS_VmSpaceClone(runProcessCB->vmSpace, childProcessCB->vmSpace);
|
||||
status = LOS_VmSpaceClone(flags, runProcessCB->vmSpace, childProcessCB->vmSpace);
|
||||
if (status != LOS_OK) {
|
||||
return LOS_ENOMEM;
|
||||
}
|
||||
@@ -1906,11 +2060,20 @@ STATIC UINT32 OsCopyFile(UINT32 flags, LosProcessCB *childProcessCB, LosProcessC
|
||||
if (flags & CLONE_FILES) {
|
||||
childProcessCB->files = runProcessCB->files;
|
||||
} else {
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
if (flags & CLONE_NEWIPC) {
|
||||
OsCurrTaskGet()->cloneIpc = TRUE;
|
||||
}
|
||||
#endif
|
||||
childProcessCB->files = dup_fd(runProcessCB->files);
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
OsCurrTaskGet()->cloneIpc = FALSE;
|
||||
#endif
|
||||
}
|
||||
if (childProcessCB->files == NULL) {
|
||||
return LOS_ENOMEM;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_PROC_PROCESS_DIR
|
||||
INT32 ret = ProcCreateProcessDir(OsGetRootPid(childProcessCB), (UINTPTR)childProcessCB);
|
||||
if (ret < 0) {
|
||||
@@ -1930,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;
|
||||
@@ -1971,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;
|
||||
@@ -1993,7 +2156,6 @@ STATIC UINT32 OsCopyProcessResources(UINT32 flags, LosProcessCB *child, LosProce
|
||||
#ifdef LOSCFG_SECURITY_CAPABILITY
|
||||
OsCopyCapability(run, child);
|
||||
#endif
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
@@ -2008,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);
|
||||
@@ -2050,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;
|
||||
@@ -2061,6 +2243,21 @@ LITE_OS_SEC_TEXT INT32 OsClone(UINT32 flags, UINTPTR sp, UINT32 size)
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
cloneFlag |= CLONE_NEWNS;
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
cloneFlag |= CLONE_NEWIPC;
|
||||
if (((flags & CLONE_NEWIPC) != 0) && ((flags & CLONE_FILES) != 0)) {
|
||||
return -LOS_EINVAL;
|
||||
}
|
||||
#endif
|
||||
#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)) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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, ¶m);
|
||||
initParam->runTimeUs = param.runTimeUs;
|
||||
initParam->deadlineUs = param.deadlineUs;
|
||||
initParam->periodUs = param.periodUs;
|
||||
}
|
||||
} else {
|
||||
initParam->policy = LOS_SCHED_RR;
|
||||
initParam->processID = processID;
|
||||
initParam->consoleID = 0;
|
||||
}
|
||||
|
||||
@@ -42,18 +42,38 @@
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
#include "los_mnt_container_pri.h"
|
||||
#endif
|
||||
#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,
|
||||
PID_CONTAINER,
|
||||
PID_CHILD_CONTAINER,
|
||||
UTS_CONTAINER,
|
||||
MNT_CONTAINER,
|
||||
IPC_CONTAINER,
|
||||
USER_CONTAINER,
|
||||
TIME_CONTAINER,
|
||||
TIME_CHILD_CONTAINER,
|
||||
NET_CONTAINER,
|
||||
CONTAINER_MAX,
|
||||
} ContainerType;
|
||||
|
||||
typedef struct Container {
|
||||
Atomic rc;
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
struct PidContainer *pidContainer;
|
||||
struct PidContainer *pidForChildContainer;
|
||||
#endif
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
struct UtsContainer *utsContainer;
|
||||
@@ -61,18 +81,68 @@ typedef struct Container {
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
struct MntContainer *mntContainer;
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
struct IpcContainer *ipcContainer;
|
||||
#endif
|
||||
#ifdef LOSCFG_TIME_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 */
|
||||
|
||||
73
kernel/base/include/los_credentials_pri.h
Normal file
73
kernel/base/include/los_credentials_pri.h
Normal 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 */
|
||||
98
kernel/base/include/los_ipc_container_pri.h
Normal file
98
kernel/base/include/los_ipc_container_pri.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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_IPC_CONTAINER_PRI_H
|
||||
#define _LOS_IPC_CONTAINER_PRI_H
|
||||
|
||||
#include "los_atomic.h"
|
||||
#include "los_list.h"
|
||||
#include "mqueue.h"
|
||||
#include "fs/file.h"
|
||||
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
struct shmIDSource;
|
||||
struct Container;
|
||||
typedef struct TagQueueCB LosQueueCB;
|
||||
typedef struct OsMux LosMux;
|
||||
typedef LosMux pthread_mutex_t;
|
||||
typedef struct ProcessCB LosProcessCB;
|
||||
|
||||
typedef struct IpcContainer {
|
||||
Atomic rc;
|
||||
LosQueueCB *allQueue;
|
||||
LOS_DL_LIST freeQueueList;
|
||||
fd_set queueFdSet;
|
||||
struct mqarray queueTable[LOSCFG_BASE_IPC_QUEUE_LIMIT];
|
||||
pthread_mutex_t mqueueMutex;
|
||||
struct mqpersonal *mqPrivBuf[MAX_MQ_FD];
|
||||
struct shminfo shmInfo;
|
||||
LosMux sysvShmMux;
|
||||
struct shmIDSource *shmSegs;
|
||||
UINT32 shmUsedPageCount;
|
||||
UINT32 containerID;
|
||||
} IpcContainer;
|
||||
|
||||
UINT32 OsInitRootIpcContainer(IpcContainer **ipcContainer);
|
||||
|
||||
UINT32 OsCopyIpcContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent);
|
||||
|
||||
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)
|
||||
|
||||
#define IPC_QUEUE_FD_SET (OsGetCurrIpcContainer()->queueFdSet)
|
||||
|
||||
#define IPC_QUEUE_TABLE (OsGetCurrIpcContainer()->queueTable)
|
||||
|
||||
#define IPC_QUEUE_MUTEX (OsGetCurrIpcContainer()->mqueueMutex)
|
||||
|
||||
#define IPC_QUEUE_MQ_PRIV_BUF (OsGetCurrIpcContainer()->mqPrivBuf)
|
||||
|
||||
#define IPC_SHM_INFO (OsGetCurrIpcContainer()->shmInfo)
|
||||
|
||||
#define IPC_SHM_SYS_VSHM_MUTEX (OsGetCurrIpcContainer()->sysvShmMux)
|
||||
|
||||
#define IPC_SHM_SEGS (OsGetCurrIpcContainer()->shmSegs)
|
||||
|
||||
#define IPC_SHM_USED_PAGE_COUNT (OsGetCurrIpcContainer()->shmUsedPageCount)
|
||||
|
||||
#endif
|
||||
#endif /* _LOS_IPC_CONTAINER_PRI_H */
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
#ifdef LOSCFG_MNT_CONTAINER
|
||||
typedef struct ProcessCB LosProcessCB;
|
||||
struct Container;
|
||||
|
||||
typedef struct MntContainer {
|
||||
Atomic rc;
|
||||
@@ -52,9 +53,14 @@ UINT32 OsInitRootMntContainer(MntContainer **mntContainer);
|
||||
|
||||
UINT32 OsCopyMntContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent);
|
||||
|
||||
VOID OsMntContainersDestroy(LosProcessCB *curr);
|
||||
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
|
||||
|
||||
62
kernel/base/include/los_net_container_pri.h
Normal file
62
kernel/base/include/los_net_container_pri.h
Normal 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 */
|
||||
@@ -37,11 +37,13 @@
|
||||
typedef struct TagTaskCB LosTaskCB;
|
||||
typedef struct ProcessCB LosProcessCB;
|
||||
struct ProcessGroup;
|
||||
struct Container;
|
||||
|
||||
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;
|
||||
|
||||
@@ -51,6 +53,7 @@ typedef struct PidContainer {
|
||||
Atomic rc;
|
||||
Atomic level;
|
||||
Atomic lock;
|
||||
BOOL referenced;
|
||||
UINT32 containerID;
|
||||
struct PidContainer *parent;
|
||||
struct ProcessGroup *rootPGroup;
|
||||
@@ -67,14 +70,23 @@ 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))
|
||||
|
||||
VOID OsPidContainersDestroyAllProcess(LosProcessCB *processCB);
|
||||
UINT32 OsAllocSpecifiedVpidUnsafe(UINT32 vpid, PidContainer *pidContainer,
|
||||
LosProcessCB *processCB, LosProcessCB *parent);
|
||||
|
||||
VOID OsPidContainersDestroy(LosProcessCB *curr);
|
||||
VOID OsPidContainerDestroyAllProcess(LosProcessCB *processCB);
|
||||
|
||||
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);
|
||||
|
||||
UINT32 OsSetNsPidContainer(UINT32 flags, struct Container *container, struct Container *newContainer);
|
||||
|
||||
UINT32 OsInitRootPidContainer(PidContainer **pidContainer);
|
||||
|
||||
LosProcessCB *OsGetPCBFromVpid(UINT32 vpid);
|
||||
@@ -93,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 */
|
||||
|
||||
@@ -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
|
||||
@@ -131,11 +134,19 @@ typedef struct ProcessCB {
|
||||
#endif
|
||||
struct rlimit *resourceLimit;
|
||||
#ifdef LOSCFG_KERNEL_CONTAINER
|
||||
struct Container *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
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ typedef enum {
|
||||
* @ingroup los_queue
|
||||
* Queue information block structure
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct TagQueueCB {
|
||||
UINT8 *queueHandle; /**< Pointer to a queue handle */
|
||||
UINT16 queueState; /**< Queue state */
|
||||
UINT16 queueLen; /**< Queue length */
|
||||
@@ -108,6 +108,9 @@ typedef struct {
|
||||
* Queue information control block
|
||||
*/
|
||||
extern LosQueueCB *g_allQueue;
|
||||
#ifndef LOSCFG_IPC_CONTAINER
|
||||
#define IPC_ALL_QUEUE g_allQueue
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
@@ -137,7 +140,7 @@ extern LosQueueCB *g_allQueue;
|
||||
* Obtain a handle of the queue that has a specified ID.
|
||||
*
|
||||
*/
|
||||
#define GET_QUEUE_HANDLE(queueID) (((LosQueueCB *)g_allQueue) + GET_QUEUE_INDEX(queueID))
|
||||
#define GET_QUEUE_HANDLE(queueID) (((LosQueueCB *)IPC_ALL_QUEUE) + GET_QUEUE_INDEX(queueID))
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
@@ -196,6 +199,8 @@ extern VOID *OsQueueMailAlloc(UINT32 queueID, VOID *mailPool, UINT32 timeout);
|
||||
*/
|
||||
extern UINT32 OsQueueMailFree(UINT32 queueID, VOID *mailPool, VOID *mailMem);
|
||||
|
||||
extern LosQueueCB *OsAllQueueCBInit(LOS_DL_LIST *freeQueueList);
|
||||
|
||||
extern UINT32 OsQueueInit(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -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);
|
||||
@@ -428,6 +462,9 @@ typedef struct TagTaskCB {
|
||||
#ifdef LOSCFG_PID_CONTAINER
|
||||
PidContainer *pidContainer;
|
||||
#endif
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
BOOL cloneIpc;
|
||||
#endif
|
||||
} LosTaskCB;
|
||||
|
||||
STATIC INLINE BOOL OsTaskIsRunning(const LosTaskCB *taskCB)
|
||||
@@ -460,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();
|
||||
@@ -616,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;
|
||||
@@ -631,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
|
||||
@@ -647,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);
|
||||
@@ -657,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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
70
kernel/base/include/los_time_container_pri.h
Normal file
70
kernel/base/include/los_time_container_pri.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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_TIME_CONTAINER_PRI_H
|
||||
#define _LOS_TIME_CONTAINER_PRI_H
|
||||
#include "time.h"
|
||||
#include "los_atomic.h"
|
||||
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
typedef struct ProcessCB LosProcessCB;
|
||||
struct Container;
|
||||
|
||||
typedef struct TimeContainer {
|
||||
Atomic rc;
|
||||
BOOL frozenOffsets;
|
||||
struct timespec64 monotonic;
|
||||
UINT32 containerID;
|
||||
} TimeContainer;
|
||||
|
||||
UINT32 OsInitRootTimeContainer(TimeContainer **timeContainer);
|
||||
|
||||
UINT32 OsCopyTimeContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent);
|
||||
|
||||
UINT32 OsUnshareTimeContainer(UINTPTR flags, LosProcessCB *curr, struct Container *newContainer);
|
||||
|
||||
UINT32 OsSetNsTimeContainer(UINT32 flags, struct Container *container, struct Container *newContainer);
|
||||
|
||||
VOID OsTimeContainerDestroy(struct Container *container);
|
||||
|
||||
UINT32 OsGetTimeContainerID(TimeContainer *timeContainer);
|
||||
|
||||
TimeContainer *OsGetCurrTimeContainer(VOID);
|
||||
|
||||
UINT32 OsGetTimeContainerMonotonic(LosProcessCB *processCB, struct timespec64 *offsets);
|
||||
|
||||
UINT32 OsSetTimeContainerMonotonic(LosProcessCB *processCB, struct timespec64 *offsets);
|
||||
|
||||
UINT32 OsGetTimeContainerCount(VOID);
|
||||
|
||||
#define CLOCK_MONOTONIC_TIME_BASE (OsGetCurrTimeContainer()->monotonic)
|
||||
|
||||
#endif
|
||||
#endif /* _LOS_TIME_CONTAINER_PRI_H */
|
||||
82
kernel/base/include/los_user_container_pri.h
Normal file
82
kernel/base/include/los_user_container_pri.h
Normal 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
|
||||
@@ -38,6 +38,8 @@
|
||||
#ifdef LOSCFG_UTS_CONTAINER
|
||||
|
||||
typedef struct ProcessCB LosProcessCB;
|
||||
struct Container;
|
||||
|
||||
typedef struct UtsContainer {
|
||||
Atomic rc;
|
||||
UINT32 containerID;
|
||||
@@ -48,10 +50,16 @@ UINT32 OsInitRootUtsContainer(UtsContainer **utsContainer);
|
||||
|
||||
UINT32 OsCopyUtsContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent);
|
||||
|
||||
VOID OsUtsContainersDestroy(LosProcessCB *curr);
|
||||
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 */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-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:
|
||||
@@ -290,7 +290,7 @@ STATUS_T LOS_VmSpaceFree(LosVmSpace *space);
|
||||
STATUS_T LOS_VaddrToPaddrMmap(LosVmSpace *space, VADDR_T vaddr, PADDR_T paddr, size_t len, UINT32 flags);
|
||||
BOOL OsUserVmSpaceInit(LosVmSpace *vmSpace, VADDR_T *virtTtb);
|
||||
LosVmSpace *OsCreateUserVmSpace(VOID);
|
||||
STATUS_T LOS_VmSpaceClone(LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace);
|
||||
STATUS_T LOS_VmSpaceClone(UINT32 cloneFlags, LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace);
|
||||
LosMux *OsGVmSpaceMuxGet(VOID);
|
||||
STATUS_T OsUnMMap(LosVmSpace *space, VADDR_T addr, size_t size);
|
||||
STATUS_T OsVmSpaceRegionFree(LosVmSpace *space);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-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:
|
||||
@@ -34,17 +34,36 @@
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "los_vm_map.h"
|
||||
|
||||
#include "los_process_pri.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* The upper limit size of total shared memory is default 16M */
|
||||
#define SHM_MAX_PAGES 4096
|
||||
#define SHM_MAX (SHM_MAX_PAGES * PAGE_SIZE)
|
||||
#define SHM_MIN 1
|
||||
#define SHM_MNI 192
|
||||
#define SHM_SEG 128
|
||||
#define SHM_ALL (SHM_MAX_PAGES)
|
||||
|
||||
struct shmIDSource {
|
||||
struct shmid_ds ds;
|
||||
UINT32 status;
|
||||
LOS_DL_LIST node;
|
||||
#ifdef LOSCFG_SHELL
|
||||
CHAR ownerName[OS_PCB_NAME_LEN];
|
||||
#endif
|
||||
};
|
||||
|
||||
VOID OsShmFork(LosVmSpace *space, LosVmMapRegion *oldRegion, LosVmMapRegion *newRegion);
|
||||
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
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-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:
|
||||
@@ -37,14 +37,51 @@
|
||||
#include "los_mp.h"
|
||||
#include "los_percpu_pri.h"
|
||||
#include "los_hook.h"
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
#include "los_ipc_container_pri.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_BASE_IPC_QUEUE
|
||||
#if (LOSCFG_BASE_IPC_QUEUE_LIMIT <= 0)
|
||||
#error "queue maxnum cannot be zero"
|
||||
#endif /* LOSCFG_BASE_IPC_QUEUE_LIMIT <= 0 */
|
||||
|
||||
#ifndef LOSCFG_IPC_CONTAINER
|
||||
LITE_OS_SEC_BSS LosQueueCB *g_allQueue = NULL;
|
||||
LITE_OS_SEC_BSS STATIC LOS_DL_LIST g_freeQueueList;
|
||||
#define FREE_QUEUE_LIST g_freeQueueList
|
||||
#endif
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT LosQueueCB *OsAllQueueCBInit(LOS_DL_LIST *freeQueueList)
|
||||
{
|
||||
UINT32 index;
|
||||
|
||||
if (freeQueueList == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
UINT32 size = LOSCFG_BASE_IPC_QUEUE_LIMIT * sizeof(LosQueueCB);
|
||||
/* system resident memory, don't free */
|
||||
LosQueueCB *allQueue = (LosQueueCB *)LOS_MemAlloc(m_aucSysMem0, size);
|
||||
if (allQueue == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(allQueue, size, 0, size);
|
||||
LOS_ListInit(freeQueueList);
|
||||
for (index = 0; index < LOSCFG_BASE_IPC_QUEUE_LIMIT; index++) {
|
||||
LosQueueCB *queueNode = ((LosQueueCB *)allQueue) + index;
|
||||
queueNode->queueID = index;
|
||||
LOS_ListTailInsert(freeQueueList, &queueNode->readWriteList[OS_QUEUE_WRITE]);
|
||||
}
|
||||
|
||||
#ifndef LOSCFG_IPC_CONTAINER
|
||||
if (OsQueueDbgInitHook() != LOS_OK) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, allQueue);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
return allQueue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Description : queue initial
|
||||
@@ -52,27 +89,12 @@ LITE_OS_SEC_BSS STATIC LOS_DL_LIST g_freeQueueList;
|
||||
*/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsQueueInit(VOID)
|
||||
{
|
||||
LosQueueCB *queueNode = NULL;
|
||||
UINT32 index;
|
||||
UINT32 size;
|
||||
|
||||
size = LOSCFG_BASE_IPC_QUEUE_LIMIT * sizeof(LosQueueCB);
|
||||
/* system resident memory, don't free */
|
||||
g_allQueue = (LosQueueCB *)LOS_MemAlloc(m_aucSysMem0, size);
|
||||
#ifndef LOSCFG_IPC_CONTAINER
|
||||
g_allQueue = OsAllQueueCBInit(&g_freeQueueList);
|
||||
if (g_allQueue == NULL) {
|
||||
return LOS_ERRNO_QUEUE_NO_MEMORY;
|
||||
}
|
||||
(VOID)memset_s(g_allQueue, size, 0, size);
|
||||
LOS_ListInit(&g_freeQueueList);
|
||||
for (index = 0; index < LOSCFG_BASE_IPC_QUEUE_LIMIT; index++) {
|
||||
queueNode = ((LosQueueCB *)g_allQueue) + index;
|
||||
queueNode->queueID = index;
|
||||
LOS_ListTailInsert(&g_freeQueueList, &queueNode->readWriteList[OS_QUEUE_WRITE]);
|
||||
}
|
||||
|
||||
if (OsQueueDbgInitHook() != LOS_OK) {
|
||||
return LOS_ERRNO_QUEUE_NO_MEMORY;
|
||||
}
|
||||
#endif
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
@@ -111,14 +133,14 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreate(CHAR *queueName, UINT16 len, UINT32
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (LOS_ListEmpty(&g_freeQueueList)) {
|
||||
if (LOS_ListEmpty(&FREE_QUEUE_LIST)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
OsQueueCheckHook();
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, queue);
|
||||
return LOS_ERRNO_QUEUE_CB_UNAVAILABLE;
|
||||
}
|
||||
|
||||
unusedQueue = LOS_DL_LIST_FIRST(&g_freeQueueList);
|
||||
unusedQueue = LOS_DL_LIST_FIRST(&FREE_QUEUE_LIST);
|
||||
LOS_ListDelete(unusedQueue);
|
||||
queueCB = GET_QUEUE_LIST(unusedQueue);
|
||||
queueCB->queueLen = len;
|
||||
@@ -433,7 +455,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueDelete(UINT32 queueID)
|
||||
queueCB->queueID = SET_QUEUE_ID(GET_QUEUE_COUNT(queueCB->queueID) + 1, GET_QUEUE_INDEX(queueCB->queueID));
|
||||
OsQueueDbgUpdateHook(queueCB->queueID, NULL);
|
||||
|
||||
LOS_ListTailInsert(&g_freeQueueList, &queueCB->readWriteList[OS_QUEUE_WRITE]);
|
||||
LOS_ListTailInsert(&FREE_QUEUE_LIST, &queueCB->readWriteList[OS_QUEUE_WRITE]);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
OsHookCall(LOS_HOOK_TYPE_QUEUE_DELETE, queueCB);
|
||||
ret = LOS_MemFree(m_aucSysMem1, (VOID *)queue);
|
||||
|
||||
@@ -837,6 +837,9 @@ STATIC UINT32 OsMemPoolInit(VOID *pool, UINT32 size)
|
||||
struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)pool;
|
||||
struct OsMemNodeHead *newNode = NULL;
|
||||
struct OsMemNodeHead *endNode = NULL;
|
||||
|
||||
(VOID)memset_s(poolHead, sizeof(struct OsMemPoolHead), 0, sizeof(struct OsMemPoolHead));
|
||||
|
||||
#ifdef LOSCFG_KERNEL_LMS
|
||||
UINT32 resize = 0;
|
||||
if (g_lms != NULL) {
|
||||
@@ -848,7 +851,6 @@ STATIC UINT32 OsMemPoolInit(VOID *pool, UINT32 size)
|
||||
size = (resize == 0) ? size : resize;
|
||||
}
|
||||
#endif
|
||||
(VOID)memset(poolHead, 0, sizeof(struct OsMemPoolHead));
|
||||
|
||||
LOS_SpinInit(&poolHead->spinlock);
|
||||
poolHead->info.pool = pool;
|
||||
@@ -885,9 +887,14 @@ STATIC UINT32 OsMemPoolInit(VOID *pool, UINT32 size)
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_MEM_MUL_POOL
|
||||
STATIC VOID OsMemPoolDeinit(VOID *pool)
|
||||
STATIC VOID OsMemPoolDeinit(const VOID *pool, UINT32 size)
|
||||
{
|
||||
(VOID)memset(pool, 0, sizeof(struct OsMemPoolHead));
|
||||
#ifdef LOSCFG_KERNEL_LMS
|
||||
if (g_lms != NULL) {
|
||||
g_lms->deInit(pool);
|
||||
}
|
||||
#endif
|
||||
(VOID)memset_s(pool, size, 0, sizeof(struct OsMemPoolHead));
|
||||
}
|
||||
|
||||
STATIC UINT32 OsMemPoolAdd(VOID *pool, UINT32 size)
|
||||
@@ -961,7 +968,7 @@ UINT32 LOS_MemInit(VOID *pool, UINT32 size)
|
||||
|
||||
#ifdef LOSCFG_MEM_MUL_POOL
|
||||
if (OsMemPoolAdd(pool, size)) {
|
||||
(VOID)OsMemPoolDeinit(pool);
|
||||
(VOID)OsMemPoolDeInit(pool, size);
|
||||
return OS_ERROR;
|
||||
}
|
||||
#endif
|
||||
@@ -973,17 +980,21 @@ UINT32 LOS_MemInit(VOID *pool, UINT32 size)
|
||||
#ifdef LOSCFG_MEM_MUL_POOL
|
||||
UINT32 LOS_MemDeInit(VOID *pool)
|
||||
{
|
||||
if (pool == NULL) {
|
||||
struct OsMemPoolHead *tmpPool = (struct OsMemPoolHead *)pool;
|
||||
|
||||
if ((tmpPool == NULL) ||
|
||||
(tmpPool->info.pool != pool) ||
|
||||
(tmpPool->info.totalSize <= OS_MEM_MIN_POOL_SIZE)) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
if (OsMemPoolDelete(pool)) {
|
||||
if (OsMemPoolDelete(tmpPool)) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
OsMemPoolDeinit(pool);
|
||||
OsMemPoolDeInit(tmpPool, tmpPool->info.totalSize);
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_MEM_DEINIT, pool);
|
||||
OsHookCall(LOS_HOOK_TYPE_MEM_DEINIT, tmpPool);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
@@ -1896,7 +1907,7 @@ UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_POOL_STATUS *poolStatus)
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
(VOID)memset(poolStatus, 0, sizeof(LOS_MEM_POOL_STATUS));
|
||||
(VOID)memset_s(poolStatus, sizeof(LOS_MEM_POOL_STATUS), 0, sizeof(LOS_MEM_POOL_STATUS));
|
||||
|
||||
struct OsMemNodeHead *tmpNode = NULL;
|
||||
struct OsMemNodeHead *endNode = NULL;
|
||||
@@ -2070,5 +2081,3 @@ BOOL OsMemIsHeapNode(const VOID *ptr)
|
||||
#endif
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,6 +35,9 @@
|
||||
#include "los_queue_pri.h"
|
||||
#include "los_swtmr_pri.h"
|
||||
#include "los_task_pri.h"
|
||||
#ifdef LOSCFG_IPC_CONTAINER
|
||||
#include "los_ipc_container_pri.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_SHELL
|
||||
#include "shcmd.h"
|
||||
@@ -88,7 +91,7 @@ UINT32 OsShellCmdQueueCntGet(VOID)
|
||||
LosQueueCB *queueCB = NULL;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
queueCB = g_allQueue;
|
||||
queueCB = IPC_ALL_QUEUE;
|
||||
for (loop = 0; loop < LOSCFG_BASE_IPC_QUEUE_LIMIT; loop++, queueCB++) {
|
||||
if (queueCB->queueState == OS_QUEUE_INUSED) {
|
||||
queueCnt++;
|
||||
|
||||
@@ -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;
|
||||
|
||||
403
kernel/base/sched/los_deadline.c
Normal file
403
kernel/base/sched/los_deadline.c
Normal 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;
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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, ¶m);
|
||||
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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-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:
|
||||
@@ -241,20 +241,15 @@ STATIC BOOL OsVmSpaceParamCheck(const LosVmSpace *vmSpace)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
STATUS_T LOS_VmSpaceClone(LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace)
|
||||
STATUS_T LOS_VmSpaceClone(UINT32 cloneFlags, LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace)
|
||||
{
|
||||
LosVmMapRegion *oldRegion = NULL;
|
||||
LosVmMapRegion *newRegion = NULL;
|
||||
LosRbNode *pstRbNode = NULL;
|
||||
LosRbNode *pstRbNodeNext = NULL;
|
||||
STATUS_T ret = LOS_OK;
|
||||
UINT32 numPages;
|
||||
PADDR_T paddr;
|
||||
VADDR_T vaddr;
|
||||
UINT32 intSave;
|
||||
LosVmPage *page = NULL;
|
||||
UINT32 flags;
|
||||
UINT32 i;
|
||||
UINT32 flags, i, intSave, numPages;
|
||||
|
||||
if ((OsVmSpaceParamCheck(oldVmSpace) == FALSE) || (OsVmSpaceParamCheck(newVmSpace) == FALSE)) {
|
||||
return LOS_ERRNO_VM_INVALID_ARGS;
|
||||
@@ -270,8 +265,13 @@ STATUS_T LOS_VmSpaceClone(LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace)
|
||||
newVmSpace->heapNow = oldVmSpace->heapNow;
|
||||
(VOID)LOS_MuxAcquire(&oldVmSpace->regionMux);
|
||||
RB_SCAN_SAFE(&oldVmSpace->regionRbTree, pstRbNode, pstRbNodeNext)
|
||||
oldRegion = (LosVmMapRegion *)pstRbNode;
|
||||
newRegion = OsVmRegionDup(newVmSpace, oldRegion, oldRegion->range.base, oldRegion->range.size);
|
||||
LosVmMapRegion *oldRegion = (LosVmMapRegion *)pstRbNode;
|
||||
#if defined(LOSCFG_KERNEL_SHM) && defined(LOSCFG_IPC_CONTAINER)
|
||||
if ((oldRegion->regionFlags & VM_MAP_REGION_FLAG_SHM) && (cloneFlags & CLONE_NEWIPC)) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
LosVmMapRegion *newRegion = OsVmRegionDup(newVmSpace, oldRegion, oldRegion->range.base, oldRegion->range.size);
|
||||
if (newRegion == NULL) {
|
||||
VM_ERR("dup new region failed");
|
||||
ret = LOS_ERRNO_VM_NO_MEMORY;
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-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:
|
||||
@@ -33,7 +33,6 @@
|
||||
#include "string.h"
|
||||
#include "time.h"
|
||||
#include "sys/types.h"
|
||||
#include "sys/shm.h"
|
||||
#include "sys/stat.h"
|
||||
#include "los_config.h"
|
||||
#include "los_init.h"
|
||||
@@ -46,6 +45,8 @@
|
||||
#include "los_process.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "user_copy.h"
|
||||
#include "los_vm_shm_pri.h"
|
||||
#include "sys/shm.h"
|
||||
#ifdef LOSCFG_SHELL
|
||||
#include "shcmd.h"
|
||||
#include "shell.h"
|
||||
@@ -54,20 +55,6 @@
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SHM
|
||||
|
||||
STATIC LosMux g_sysvShmMux;
|
||||
|
||||
/* private macro */
|
||||
#define SYSV_SHM_LOCK() (VOID)LOS_MuxLock(&g_sysvShmMux, LOS_WAIT_FOREVER)
|
||||
#define SYSV_SHM_UNLOCK() (VOID)LOS_MuxUnlock(&g_sysvShmMux)
|
||||
|
||||
/* The upper limit size of total shared memory is default 16M */
|
||||
#define SHM_MAX_PAGES 4096
|
||||
#define SHM_MAX (SHM_MAX_PAGES * PAGE_SIZE)
|
||||
#define SHM_MIN 1
|
||||
#define SHM_MNI 192
|
||||
#define SHM_SEG 128
|
||||
#define SHM_ALL (SHM_MAX_PAGES)
|
||||
|
||||
#define SHM_SEG_FREE 0x2000
|
||||
#define SHM_SEG_USED 0x4000
|
||||
#define SHM_SEG_REMOVE 0x8000
|
||||
@@ -91,57 +78,75 @@ STATIC LosMux g_sysvShmMux;
|
||||
#define SHM_GROUPE_TO_USER 3
|
||||
#define SHM_OTHER_TO_USER 6
|
||||
|
||||
struct shmIDSource {
|
||||
struct shmid_ds ds;
|
||||
UINT32 status;
|
||||
LOS_DL_LIST node;
|
||||
#ifdef LOSCFG_SHELL
|
||||
CHAR ownerName[OS_PCB_NAME_LEN];
|
||||
#endif
|
||||
};
|
||||
#ifndef LOSCFG_IPC_CONTAINER
|
||||
STATIC LosMux g_sysvShmMux;
|
||||
|
||||
/* private data */
|
||||
STATIC struct shminfo g_shmInfo = {
|
||||
.shmmax = SHM_MAX,
|
||||
.shmmin = SHM_MIN,
|
||||
.shmmni = SHM_MNI,
|
||||
.shmseg = SHM_SEG,
|
||||
.shmall = SHM_ALL,
|
||||
};
|
||||
|
||||
STATIC struct shminfo g_shmInfo;
|
||||
STATIC struct shmIDSource *g_shmSegs = NULL;
|
||||
STATIC UINT32 g_shmUsedPageCount;
|
||||
|
||||
UINT32 ShmInit(VOID)
|
||||
#define IPC_SHM_INFO g_shmInfo
|
||||
#define IPC_SHM_SYS_VSHM_MUTEX g_sysvShmMux
|
||||
#define IPC_SHM_SEGS g_shmSegs
|
||||
#define IPC_SHM_USED_PAGE_COUNT g_shmUsedPageCount
|
||||
#endif
|
||||
|
||||
/* private macro */
|
||||
#define SYSV_SHM_LOCK() (VOID)LOS_MuxLock(&IPC_SHM_SYS_VSHM_MUTEX, LOS_WAIT_FOREVER)
|
||||
#define SYSV_SHM_UNLOCK() (VOID)LOS_MuxUnlock(&IPC_SHM_SYS_VSHM_MUTEX)
|
||||
|
||||
struct shmIDSource *OsShmCBInit(LosMux *sysvShmMux, struct shminfo *shmInfo, UINT32 *shmUsedPageCount)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 i;
|
||||
|
||||
ret = LOS_MuxInit(&g_sysvShmMux, NULL);
|
||||
if ((sysvShmMux == NULL) || (shmInfo == NULL) || (shmUsedPageCount == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = LOS_MuxInit(sysvShmMux, NULL);
|
||||
if (ret != LOS_OK) {
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
g_shmSegs = LOS_MemAlloc((VOID *)OS_SYS_MEM_ADDR, sizeof(struct shmIDSource) * g_shmInfo.shmmni);
|
||||
if (g_shmSegs == NULL) {
|
||||
(VOID)LOS_MuxDestroy(&g_sysvShmMux);
|
||||
shmInfo->shmmax = SHM_MAX;
|
||||
shmInfo->shmmin = SHM_MIN;
|
||||
shmInfo->shmmni = SHM_MNI;
|
||||
shmInfo->shmseg = SHM_SEG;
|
||||
shmInfo->shmall = SHM_ALL;
|
||||
|
||||
struct shmIDSource *shmSegs = LOS_MemAlloc((VOID *)OS_SYS_MEM_ADDR, sizeof(struct shmIDSource) * shmInfo->shmmni);
|
||||
if (shmSegs == NULL) {
|
||||
(VOID)LOS_MuxDestroy(sysvShmMux);
|
||||
goto ERROR;
|
||||
}
|
||||
(VOID)memset_s(g_shmSegs, (sizeof(struct shmIDSource) * g_shmInfo.shmmni),
|
||||
0, (sizeof(struct shmIDSource) * g_shmInfo.shmmni));
|
||||
(VOID)memset_s(shmSegs, (sizeof(struct shmIDSource) * shmInfo->shmmni),
|
||||
0, (sizeof(struct shmIDSource) * shmInfo->shmmni));
|
||||
|
||||
for (i = 0; i < g_shmInfo.shmmni; i++) {
|
||||
g_shmSegs[i].status = SHM_SEG_FREE;
|
||||
g_shmSegs[i].ds.shm_perm.seq = i + 1;
|
||||
LOS_ListInit(&g_shmSegs[i].node);
|
||||
for (i = 0; i < shmInfo->shmmni; i++) {
|
||||
shmSegs[i].status = SHM_SEG_FREE;
|
||||
shmSegs[i].ds.shm_perm.seq = i + 1;
|
||||
LOS_ListInit(&shmSegs[i].node);
|
||||
}
|
||||
g_shmUsedPageCount = 0;
|
||||
*shmUsedPageCount = 0;
|
||||
|
||||
return LOS_OK;
|
||||
return shmSegs;
|
||||
|
||||
ERROR:
|
||||
VM_ERR("ShmInit fail\n");
|
||||
return LOS_NOK;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
UINT32 ShmInit(VOID)
|
||||
{
|
||||
#ifndef LOSCFG_IPC_CONTAINER
|
||||
g_shmSegs = OsShmCBInit(&IPC_SHM_SYS_VSHM_MUTEX, &IPC_SHM_INFO, &IPC_SHM_USED_PAGE_COUNT);
|
||||
if (g_shmSegs == NULL) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
#endif
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LOS_MODULE_INIT(ShmInit, LOS_INIT_LEVEL_VM_COMPLETE);
|
||||
@@ -150,10 +155,10 @@ UINT32 ShmDeinit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
(VOID)LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, g_shmSegs);
|
||||
g_shmSegs = NULL;
|
||||
(VOID)LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, IPC_SHM_SEGS);
|
||||
IPC_SHM_SEGS = NULL;
|
||||
|
||||
ret = LOS_MuxDestroy(&g_sysvShmMux);
|
||||
ret = LOS_MuxDestroy(&IPC_SHM_SYS_VSHM_MUTEX);
|
||||
if (ret != LOS_OK) {
|
||||
return -1;
|
||||
}
|
||||
@@ -188,43 +193,63 @@ 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 < g_shmInfo.shmmin) ||
|
||||
(size > g_shmInfo.shmmax)) {
|
||||
if ((*size == 0) || (*size < IPC_SHM_INFO.shmmin) ||
|
||||
(*size > IPC_SHM_INFO.shmmax)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
size = LOS_Align(size, PAGE_SIZE);
|
||||
if ((g_shmUsedPageCount + (size >> PAGE_SHIFT)) > g_shmInfo.shmall) {
|
||||
|
||||
*size = LOS_Align(*size, PAGE_SIZE);
|
||||
if ((IPC_SHM_USED_PAGE_COUNT + (*size >> PAGE_SHIFT)) > IPC_SHM_INFO.shmall) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
for (i = 0; i < g_shmInfo.shmmni; i++) {
|
||||
if (g_shmSegs[i].status & SHM_SEG_FREE) {
|
||||
g_shmSegs[i].status &= ~SHM_SEG_FREE;
|
||||
segNum = i;
|
||||
#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;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (segNum < 0) {
|
||||
if (*segNum < 0) {
|
||||
return -ENOSPC;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
seg = &g_shmSegs[segNum];
|
||||
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);
|
||||
g_shmUsedPageCount += size >> PAGE_SHIFT;
|
||||
IPC_SHM_USED_PAGE_COUNT += size >> PAGE_SHIFT;
|
||||
|
||||
seg->status |= SHM_SEG_USED;
|
||||
seg->ds.shm_perm.mode = (UINT32)shmflg & ACCESSPERMS;
|
||||
@@ -247,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;
|
||||
|
||||
@@ -257,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;
|
||||
}
|
||||
g_shmUsedPageCount -= 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);
|
||||
}
|
||||
@@ -267,8 +297,8 @@ STATIC INT32 ShmFindSegByKey(key_t key)
|
||||
INT32 i;
|
||||
struct shmIDSource *seg = NULL;
|
||||
|
||||
for (i = 0; i < g_shmInfo.shmmni; i++) {
|
||||
seg = &g_shmSegs[i];
|
||||
for (i = 0; i < IPC_SHM_INFO.shmmni; i++) {
|
||||
seg = &IPC_SHM_SEGS[i];
|
||||
if ((seg->status & SHM_SEG_USED) &&
|
||||
(seg->ds.shm_perm.key == key)) {
|
||||
return i;
|
||||
@@ -280,7 +310,7 @@ STATIC INT32 ShmFindSegByKey(key_t key)
|
||||
|
||||
STATIC INT32 ShmSegValidCheck(INT32 segNum, size_t size, INT32 shmFlg)
|
||||
{
|
||||
struct shmIDSource *seg = &g_shmSegs[segNum];
|
||||
struct shmIDSource *seg = &IPC_SHM_SEGS[segNum];
|
||||
|
||||
if (size > seg->ds.shm_segsz) {
|
||||
return -EINVAL;
|
||||
@@ -298,12 +328,12 @@ STATIC struct shmIDSource *ShmFindSeg(int shmid)
|
||||
{
|
||||
struct shmIDSource *seg = NULL;
|
||||
|
||||
if ((shmid < 0) || (shmid >= g_shmInfo.shmmni)) {
|
||||
if ((shmid < 0) || (shmid >= IPC_SHM_INFO.shmmni)) {
|
||||
set_errno(EINVAL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
seg = &g_shmSegs[shmid];
|
||||
seg = &IPC_SHM_SEGS[shmid];
|
||||
if ((seg->status & SHM_SEG_FREE) || ((seg->ds.shm_nattch == 0) && (seg->status & SHM_SEG_REMOVE))) {
|
||||
set_errno(EIDRM);
|
||||
return NULL;
|
||||
@@ -364,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. */
|
||||
@@ -383,8 +413,8 @@ STATIC INT32 ShmSegUsedCount(VOID)
|
||||
INT32 count = 0;
|
||||
struct shmIDSource *seg = NULL;
|
||||
|
||||
for (i = 0; i < g_shmInfo.shmmni; i++) {
|
||||
seg = &g_shmSegs[i];
|
||||
for (i = 0; i < IPC_SHM_INFO.shmmni; i++) {
|
||||
seg = &IPC_SHM_SEGS[i];
|
||||
if (seg->status & SHM_SEG_USED) {
|
||||
count++;
|
||||
}
|
||||
@@ -672,16 +702,16 @@ 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:
|
||||
ret = LOS_ArchCopyToUser(buf, &g_shmInfo, sizeof(struct shminfo));
|
||||
ret = LOS_ArchCopyToUser(buf, &IPC_SHM_INFO, sizeof(struct shminfo));
|
||||
if (ret != 0) {
|
||||
ret = EFAULT;
|
||||
goto ERROR;
|
||||
}
|
||||
ret = g_shmInfo.shmmni;
|
||||
ret = IPC_SHM_INFO.shmmni;
|
||||
break;
|
||||
case SHM_INFO:
|
||||
shmInfo.shm_rss = 0;
|
||||
@@ -695,7 +725,7 @@ INT32 ShmCtl(INT32 shmid, INT32 cmd, struct shmid_ds *buf)
|
||||
ret = EFAULT;
|
||||
goto ERROR;
|
||||
}
|
||||
ret = g_shmInfo.shmmni;
|
||||
ret = IPC_SHM_INFO.shmmni;
|
||||
break;
|
||||
default:
|
||||
VM_ERR("the cmd(%d) is not supported!", cmd);
|
||||
@@ -758,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();
|
||||
@@ -775,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)
|
||||
{
|
||||
@@ -784,8 +835,8 @@ STATIC VOID OsShmInfoCmd(VOID)
|
||||
PRINTK("\r\n------- Shared Memory Segments -------\n");
|
||||
PRINTK("key shmid perms bytes nattch status owner\n");
|
||||
SYSV_SHM_LOCK();
|
||||
for (i = 0; i < g_shmInfo.shmmni; i++) {
|
||||
seg = &g_shmSegs[i];
|
||||
for (i = 0; i < IPC_SHM_INFO.shmmni; i++) {
|
||||
seg = &IPC_SHM_SEGS[i];
|
||||
if (!(seg->status & SHM_SEG_USED)) {
|
||||
continue;
|
||||
}
|
||||
@@ -801,7 +852,7 @@ STATIC VOID OsShmDeleteCmd(INT32 shmid)
|
||||
{
|
||||
struct shmIDSource *seg = NULL;
|
||||
|
||||
if ((shmid < 0) || (shmid >= g_shmInfo.shmmni)) {
|
||||
if ((shmid < 0) || (shmid >= IPC_SHM_INFO.shmmni)) {
|
||||
PRINT_ERR("shmid is invalid: %d\n", shmid);
|
||||
return;
|
||||
}
|
||||
@@ -814,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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
/**
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
65
kernel/extended/container/BUILD.gn
Normal file
65
kernel/extended/container/BUILD.gn
Normal 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 = [ "." ]
|
||||
}
|
||||
63
kernel/extended/container/Makefile
Normal file
63
kernel/extended/container/Makefile
Normal 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)
|
||||
755
kernel/extended/container/los_container.c
Normal file
755
kernel/extended/container/los_container.c
Normal 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
|
||||
209
kernel/extended/container/los_credentials.c
Normal file
209
kernel/extended/container/los_credentials.c
Normal 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
|
||||
222
kernel/extended/container/los_ipc_container.c
Normal file
222
kernel/extended/container/los_ipc_container.c
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* 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_IPC_CONTAINER
|
||||
#include "los_ipc_container_pri.h"
|
||||
#include "los_config.h"
|
||||
#include "los_queue_pri.h"
|
||||
#include "los_vm_shm_pri.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "vnode.h"
|
||||
#include "proc_fs.h"
|
||||
#include "pthread.h"
|
||||
|
||||
#define IPC_INIT_NUM 3
|
||||
|
||||
STATIC UINT32 g_currentIpcContainerNum = 0;
|
||||
|
||||
STATIC IpcContainer *CreateNewIpcContainer(IpcContainer *parent)
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
UINT32 size = sizeof(IpcContainer);
|
||||
IpcContainer *ipcContainer = (IpcContainer *)LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (ipcContainer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(ipcContainer, size, 0, size);
|
||||
|
||||
ipcContainer->allQueue = OsAllQueueCBInit(&ipcContainer->freeQueueList);
|
||||
if (ipcContainer->allQueue == NULL) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, ipcContainer);
|
||||
return NULL;
|
||||
}
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
|
||||
pthread_mutex_init(&ipcContainer->mqueueMutex, &attr);
|
||||
|
||||
ipcContainer->shmSegs = OsShmCBInit(&ipcContainer->sysvShmMux, &ipcContainer->shmInfo,
|
||||
&ipcContainer->shmUsedPageCount);
|
||||
if (ipcContainer->shmSegs == NULL) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, ipcContainer->allQueue);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, ipcContainer);
|
||||
return NULL;
|
||||
}
|
||||
ipcContainer->containerID = OsAllocContainerID();
|
||||
|
||||
if (parent != NULL) {
|
||||
LOS_AtomicSet(&ipcContainer->rc, 1);
|
||||
} else {
|
||||
LOS_AtomicSet(&ipcContainer->rc, 3); /* 3: Three system processes */
|
||||
}
|
||||
return ipcContainer;
|
||||
}
|
||||
|
||||
STATIC UINT32 CreateIpcContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
IpcContainer *parentContainer = parent->container->ipcContainer;
|
||||
IpcContainer *newIpcContainer = CreateNewIpcContainer(parentContainer);
|
||||
if (newIpcContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
g_currentIpcContainerNum++;
|
||||
child->container->ipcContainer = newIpcContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsInitRootIpcContainer(IpcContainer **ipcContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
IpcContainer *newIpcContainer = CreateNewIpcContainer(NULL);
|
||||
if (newIpcContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
g_currentIpcContainerNum++;
|
||||
*ipcContainer = newIpcContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsCopyIpcContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
IpcContainer *currIpcContainer = parent->container->ipcContainer;
|
||||
|
||||
if (!(flags & CLONE_NEWIPC)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LOS_AtomicInc(&currIpcContainer->rc);
|
||||
child->container->ipcContainer = currIpcContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (OsContainerLimitCheck(IPC_CONTAINER, &g_currentIpcContainerNum) != LOS_OK) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
return CreateIpcContainer(child, parent);
|
||||
}
|
||||
|
||||
UINT32 OsUnshareIpcContainer(UINTPTR flags, LosProcessCB *curr, Container *newContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
IpcContainer *parentContainer = curr->container->ipcContainer;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
newContainer->ipcContainer = ipcContainer;
|
||||
g_currentIpcContainerNum++;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
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;
|
||||
if (container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
IpcContainer *ipcContainer = container->ipcContainer;
|
||||
if (ipcContainer == NULL) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&ipcContainer->rc);
|
||||
if (LOS_AtomicRead(&ipcContainer->rc) > 0) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
g_currentIpcContainerNum--;
|
||||
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;
|
||||
}
|
||||
|
||||
UINT32 OsGetIpcContainerID(IpcContainer *ipcContainer)
|
||||
{
|
||||
if (ipcContainer == NULL) {
|
||||
return OS_INVALID_VALUE;
|
||||
}
|
||||
|
||||
return ipcContainer->containerID;
|
||||
}
|
||||
|
||||
IpcContainer *OsGetCurrIpcContainer(VOID)
|
||||
{
|
||||
return OsCurrProcessGet()->container->ipcContainer;
|
||||
}
|
||||
|
||||
UINT32 OsGetIpcContainerCount(VOID)
|
||||
{
|
||||
return g_currentIpcContainerNum;
|
||||
}
|
||||
#endif
|
||||
@@ -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)
|
||||
@@ -44,20 +44,50 @@ LIST_HEAD *GetContainerMntList(VOID)
|
||||
return &OsCurrProcessGet()->container->mntContainer->mountList;
|
||||
}
|
||||
|
||||
STATIC UINT32 CreateMntContainer(MntContainer **newMntContainer)
|
||||
STATIC MntContainer *CreateNewMntContainer(MntContainer *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
MntContainer *mntContainer = (MntContainer *)LOS_MemAlloc(m_aucSysMem1, sizeof(MntContainer));
|
||||
if (mntContainer == NULL) {
|
||||
return ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
mntContainer->containerID = OsAllocContainerID();
|
||||
LOS_AtomicSet(&mntContainer->rc, 1);
|
||||
LOS_ListInit(&mntContainer->mountList);
|
||||
|
||||
if (parent != NULL) {
|
||||
LOS_AtomicSet(&mntContainer->rc, 1);
|
||||
} else {
|
||||
LOS_AtomicSet(&mntContainer->rc, 3); /* 3: Three system processes */
|
||||
}
|
||||
return mntContainer;
|
||||
}
|
||||
|
||||
STATIC UINT32 CreateMntContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
MntContainer *parentContainer = parent->container->mntContainer;
|
||||
MntContainer *newMntContainer = CreateNewMntContainer(parentContainer);
|
||||
if (newMntContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
g_currentMntContainerNum++;
|
||||
*newMntContainer = mntContainer;
|
||||
child->container->mntContainer = newMntContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsInitRootMntContainer(MntContainer **mntContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
MntContainer *newMntContainer = CreateNewMntContainer(NULL);
|
||||
if (newMntContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
g_currentMntContainerNum++;
|
||||
*mntContainer = newMntContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
@@ -94,7 +124,11 @@ UINT32 OsCopyMntContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
ret = CreateMntContainer(&child->container->mntContainer);
|
||||
if (OsContainerLimitCheck(MNT_CONTAINER, &g_currentMntContainerNum) != LOS_OK) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
ret = CreateMntContainer(child, parent);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
@@ -102,6 +136,55 @@ UINT32 OsCopyMntContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
|
||||
return CopyMountList(currMntContainer, child->container->mntContainer);
|
||||
}
|
||||
|
||||
UINT32 OsUnshareMntContainer(UINTPTR flags, LosProcessCB *curr, Container *newContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 ret;
|
||||
MntContainer *parentContainer = curr->container->mntContainer;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
ret = CopyMountList(parentContainer, mntContainer);
|
||||
if (ret != LOS_OK) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, mntContainer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
newContainer->mntContainer = mntContainer;
|
||||
g_currentMntContainerNum++;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
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;
|
||||
@@ -126,26 +209,31 @@ STATIC VOID FreeMountList(LIST_HEAD *mountList)
|
||||
return;
|
||||
}
|
||||
|
||||
VOID OsMntContainersDestroy(LosProcessCB *curr)
|
||||
VOID OsMntContainerDestroy(Container *container)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (curr->container == NULL) {
|
||||
if (container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
MntContainer *mntContainer = curr->container->mntContainer;
|
||||
if (mntContainer != NULL) {
|
||||
if (LOS_AtomicRead(&mntContainer->rc) == 0) {
|
||||
g_currentMntContainerNum--;
|
||||
FreeMountList(&mntContainer->mountList);
|
||||
curr->container->mntContainer = NULL;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, mntContainer);
|
||||
return;
|
||||
}
|
||||
MntContainer *mntContainer = container->mntContainer;
|
||||
if (mntContainer == NULL) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&mntContainer->rc);
|
||||
if (LOS_AtomicRead(&mntContainer->rc) > 0) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
g_currentMntContainerNum--;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
FreeMountList(&mntContainer->mountList);
|
||||
container->mntContainer = NULL;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, mntContainer);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -158,8 +246,8 @@ UINT32 OsGetMntContainerID(MntContainer *mntContainer)
|
||||
return mntContainer->containerID;
|
||||
}
|
||||
|
||||
UINT32 OsInitRootMntContainer(MntContainer **mntContainer)
|
||||
UINT32 OsGetMntContainerCount(VOID)
|
||||
{
|
||||
return CreateMntContainer(mntContainer);
|
||||
return g_currentMntContainerNum;
|
||||
}
|
||||
#endif
|
||||
344
kernel/extended/container/los_net_container.c
Normal file
344
kernel/extended/container/los_net_container.c
Normal 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
|
||||
@@ -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;
|
||||
}
|
||||
@@ -195,7 +215,7 @@ UINT32 OsAllocVtid(LosTaskCB *taskCB, const LosProcessCB *processCB)
|
||||
return taskCB->taskID;
|
||||
}
|
||||
|
||||
VOID OsPidContainersDestroyAllProcess(LosProcessCB *curr)
|
||||
VOID OsPidContainerDestroyAllProcess(LosProcessCB *curr)
|
||||
{
|
||||
INT32 ret;
|
||||
UINT32 intSave;
|
||||
@@ -205,7 +225,7 @@ VOID OsPidContainersDestroyAllProcess(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;
|
||||
}
|
||||
@@ -264,16 +284,56 @@ STATIC PidContainer *CreateNewPidContainer(PidContainer *parent)
|
||||
newPidContainer->parent = parent;
|
||||
if (parent != NULL) {
|
||||
LOS_AtomicSet(&newPidContainer->level, parent->level + 1);
|
||||
newPidContainer->referenced = FALSE;
|
||||
} else {
|
||||
LOS_AtomicSet(&newPidContainer->level, 0);
|
||||
newPidContainer->referenced = TRUE;
|
||||
}
|
||||
return newPidContainer;
|
||||
}
|
||||
|
||||
VOID OsPidContainerDestroy(Container *container, LosProcessCB *processCB)
|
||||
{
|
||||
if (container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
PidContainer *pidContainer = container->pidContainer;
|
||||
if (pidContainer == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (processCB != NULL) {
|
||||
FreeVpid(processCB);
|
||||
}
|
||||
|
||||
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, container->pidForChildContainer);
|
||||
container->pidForChildContainer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if ((container->pidContainer != NULL) && (LOS_AtomicRead(&pidContainer->rc) <= 0)) {
|
||||
g_currentPidContainerNum--;
|
||||
container->pidContainer = NULL;
|
||||
container->pidForChildContainer = NULL;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pidContainer->rootPGroup);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pidContainer);
|
||||
}
|
||||
|
||||
if (processCB != NULL) {
|
||||
OsContainerFree(processCB);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC UINT32 CreatePidContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 ret;
|
||||
UINT32 intSave;
|
||||
|
||||
PidContainer *parentContainer = parent->container->pidContainer;
|
||||
PidContainer *newPidContainer = CreateNewPidContainer(parentContainer);
|
||||
if (newPidContainer == NULL) {
|
||||
@@ -282,18 +342,21 @@ STATIC UINT32 CreatePidContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if ((parentContainer->level + 1) >= PID_CONTAINER_LEVEL_LIMIT) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, newPidContainer);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
g_currentPidContainerNum++;
|
||||
newPidContainer->referenced = TRUE;
|
||||
child->container->pidContainer = newPidContainer;
|
||||
ret = OsAllocSpecifiedVpidUnsafe(OS_USER_ROOT_PROCESS_ID, child, parent);
|
||||
child->container->pidForChildContainer = newPidContainer;
|
||||
ret = OsAllocSpecifiedVpidUnsafe(OS_USER_ROOT_PROCESS_ID, newPidContainer, child, parent);
|
||||
if (ret == OS_INVALID_VALUE) {
|
||||
g_currentPidContainerNum--;
|
||||
FreeVpid(child);
|
||||
child->container->pidContainer = NULL;
|
||||
child->container->pidForChildContainer = NULL;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, newPidContainer);
|
||||
return ENOSPC;
|
||||
@@ -302,27 +365,35 @@ STATIC UINT32 CreatePidContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsPidContainersDestroy(LosProcessCB *curr)
|
||||
STATIC UINT32 AllocVpidFormPidForChildContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
if (curr->container == NULL) {
|
||||
return;
|
||||
}
|
||||
UINT32 ret;
|
||||
PidContainer *pidContainer = parent->container->pidForChildContainer;
|
||||
child->container->pidContainer = pidContainer;
|
||||
child->container->pidForChildContainer = pidContainer;
|
||||
|
||||
PidContainer *pidContainer = curr->container->pidContainer;
|
||||
if (pidContainer != NULL) {
|
||||
FreeVpid(curr);
|
||||
if (LOS_AtomicRead(&pidContainer->rc) == 0) {
|
||||
g_currentPidContainerNum--;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pidContainer);
|
||||
curr->container->pidContainer = NULL;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&curr->container->rc);
|
||||
if (LOS_AtomicRead(&curr->container->rc) == 0) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, curr->container);
|
||||
curr->container = NULL;
|
||||
if (ret == OS_INVALID_VALUE) {
|
||||
FreeVpid(child);
|
||||
child->container->pidContainer = NULL;
|
||||
child->container->pidForChildContainer = NULL;
|
||||
return ENOSPC;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsCopyPidContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID)
|
||||
@@ -330,22 +401,40 @@ UINT32 OsCopyPidContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
|
||||
UINT32 ret;
|
||||
UINT32 intSave;
|
||||
|
||||
if (!(flags & CLONE_NEWPID)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
child->container->pidContainer = parent->container->pidContainer;
|
||||
ret = OsAllocVpid(child);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if (ret == OS_INVALID_VALUE) {
|
||||
PRINT_ERR("[%s] alloc vpid failed\n", __FUNCTION__);
|
||||
return ENOSPC;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
PidContainer *parentPidContainer = parent->container->pidContainer;
|
||||
PidContainer *parentPidContainerForChild = parent->container->pidForChildContainer;
|
||||
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, parent);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if (ret == OS_INVALID_VALUE) {
|
||||
PRINT_ERR("[%s] alloc vpid failed\n", __FUNCTION__);
|
||||
return ENOSPC;
|
||||
}
|
||||
*processID = child->processID;
|
||||
return LOS_OK;
|
||||
}
|
||||
*processID = child->processID;
|
||||
return LOS_OK;
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
ret = CreatePidContainer(child, parent);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
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 = AllocVpidFormPidForChildContainer(child, parent);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
PidContainer *pidContainer = child->container->pidContainer;
|
||||
@@ -357,6 +446,69 @@ UINT32 OsCopyPidContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *pare
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsUnsharePidContainer(UINTPTR flags, LosProcessCB *curr, Container *newContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (!(flags & CLONE_NEWPID)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
newContainer->pidContainer = curr->container->pidContainer;
|
||||
newContainer->pidForChildContainer = curr->container->pidForChildContainer;
|
||||
if (newContainer->pidContainer != newContainer->pidForChildContainer) {
|
||||
LOS_AtomicInc(&newContainer->pidForChildContainer->rc);
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (OsContainerLimitCheck(PID_CONTAINER, &g_currentPidContainerNum) != LOS_OK) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
PidContainer *pidForChild = CreateNewPidContainer(curr->container->pidContainer);
|
||||
if (pidForChild == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (curr->container->pidContainer != curr->container->pidForChildContainer) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pidForChild);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (pidForChild->level >= PID_CONTAINER_LEVEL_LIMIT) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pidForChild);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
g_currentPidContainerNum++;
|
||||
newContainer->pidContainer = curr->container->pidContainer;
|
||||
newContainer->pidForChildContainer = pidForChild;
|
||||
LOS_AtomicSet(&pidForChild->rc, 1);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
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;
|
||||
@@ -441,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) {
|
||||
@@ -449,4 +615,9 @@ UINT32 OsGetPidContainerID(PidContainer *pidContainer)
|
||||
|
||||
return pidContainer->containerID;
|
||||
}
|
||||
|
||||
UINT32 OsGetPidContainerCount(VOID)
|
||||
{
|
||||
return g_currentPidContainerNum;
|
||||
}
|
||||
#endif
|
||||
258
kernel/extended/container/los_time_container.c
Normal file
258
kernel/extended/container/los_time_container.c
Normal file
@@ -0,0 +1,258 @@
|
||||
/*
|
||||
* 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_time_container_pri.h"
|
||||
#include "los_process_pri.h"
|
||||
|
||||
#ifdef LOSCFG_TIME_CONTAINER
|
||||
STATIC UINT32 g_currentTimeContainerNum;
|
||||
|
||||
STATIC TimeContainer *CreateNewTimeContainer(TimeContainer *parent)
|
||||
{
|
||||
UINT32 size = sizeof(TimeContainer);
|
||||
TimeContainer *timeContainer = (TimeContainer *)LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (timeContainer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(timeContainer, size, 0, size);
|
||||
|
||||
timeContainer->containerID = OsAllocContainerID();
|
||||
if (parent != NULL) {
|
||||
timeContainer->frozenOffsets = FALSE;
|
||||
LOS_AtomicSet(&timeContainer->rc, 1);
|
||||
} else {
|
||||
timeContainer->frozenOffsets = TRUE;
|
||||
LOS_AtomicSet(&timeContainer->rc, 3); /* 3: Three system processes */
|
||||
}
|
||||
return timeContainer;
|
||||
}
|
||||
|
||||
STATIC UINT32 CreateTimeContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
TimeContainer *newTimeContainer = parent->container->timeForChildContainer;
|
||||
LOS_AtomicInc(&newTimeContainer->rc);
|
||||
newTimeContainer->frozenOffsets = TRUE;
|
||||
child->container->timeContainer = newTimeContainer;
|
||||
child->container->timeForChildContainer = newTimeContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsInitRootTimeContainer(TimeContainer **timeContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
TimeContainer *newTimeContainer = CreateNewTimeContainer(NULL);
|
||||
if (newTimeContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
*timeContainer = newTimeContainer;
|
||||
g_currentTimeContainerNum++;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsCopyTimeContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
TimeContainer *currTimeContainer = parent->container->timeContainer;
|
||||
|
||||
if (currTimeContainer == parent->container->timeForChildContainer) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LOS_AtomicInc(&currTimeContainer->rc);
|
||||
child->container->timeContainer = currTimeContainer;
|
||||
child->container->timeForChildContainer = currTimeContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (OsContainerLimitCheck(TIME_CONTAINER, &g_currentTimeContainerNum) != LOS_OK) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
return CreateTimeContainer(child, parent);
|
||||
}
|
||||
|
||||
UINT32 OsUnshareTimeContainer(UINTPTR flags, LosProcessCB *curr, Container *newContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (!(flags & CLONE_NEWTIME)) {
|
||||
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);
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (OsContainerLimitCheck(TIME_CONTAINER, &g_currentTimeContainerNum) != LOS_OK) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
TimeContainer *timeForChild = CreateNewTimeContainer(curr->container->timeContainer);
|
||||
if (timeForChild == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (curr->container->timeContainer != curr->container->timeForChildContainer) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, timeForChild);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
(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;
|
||||
}
|
||||
|
||||
UINT32 OsSetNsTimeContainer(UINT32 flags, Container *container, Container *newContainer)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsTimeContainerDestroy(Container *container)
|
||||
{
|
||||
UINT32 intSave;
|
||||
TimeContainer *timeContainer = NULL;
|
||||
TimeContainer *timeForChild = NULL;
|
||||
|
||||
if (container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (container->timeContainer == NULL) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((container->timeForChildContainer != NULL) && (container->timeContainer != container->timeForChildContainer)) {
|
||||
LOS_AtomicDec(&container->timeForChildContainer->rc);
|
||||
if (LOS_AtomicRead(&container->timeForChildContainer->rc) <= 0) {
|
||||
g_currentTimeContainerNum--;
|
||||
timeForChild = container->timeForChildContainer;
|
||||
container->timeForChildContainer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&container->timeContainer->rc);
|
||||
if (LOS_AtomicRead(&container->timeContainer->rc) <= 0) {
|
||||
g_currentTimeContainerNum--;
|
||||
timeContainer = container->timeContainer;
|
||||
container->timeContainer = NULL;
|
||||
container->timeForChildContainer = NULL;
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, timeForChild);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, timeContainer);
|
||||
return;
|
||||
}
|
||||
|
||||
UINT32 OsGetTimeContainerID(TimeContainer *timeContainer)
|
||||
{
|
||||
if (timeContainer == NULL) {
|
||||
return OS_INVALID_VALUE;
|
||||
}
|
||||
|
||||
return timeContainer->containerID;
|
||||
}
|
||||
|
||||
TimeContainer *OsGetCurrTimeContainer(VOID)
|
||||
{
|
||||
return OsCurrProcessGet()->container->timeContainer;
|
||||
}
|
||||
|
||||
UINT32 OsGetTimeContainerMonotonic(LosProcessCB *processCB, struct timespec64 *offsets)
|
||||
{
|
||||
if ((processCB == NULL) || (offsets == NULL)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (OsProcessIsInactive(processCB)) {
|
||||
return ESRCH;
|
||||
}
|
||||
|
||||
TimeContainer *timeContainer = processCB->container->timeForChildContainer;
|
||||
(VOID)memcpy_s(offsets, sizeof(struct timespec64), &timeContainer->monotonic, sizeof(struct timespec64));
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsSetTimeContainerMonotonic(LosProcessCB *processCB, struct timespec64 *offsets)
|
||||
{
|
||||
if ((processCB == NULL) || (offsets == NULL)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (OsProcessIsInactive(processCB)) {
|
||||
return ESRCH;
|
||||
}
|
||||
|
||||
TimeContainer *timeContainer = processCB->container->timeForChildContainer;
|
||||
if (timeContainer->frozenOffsets) {
|
||||
return EACCES;
|
||||
}
|
||||
|
||||
timeContainer->monotonic.tv_sec = offsets->tv_sec;
|
||||
timeContainer->monotonic.tv_nsec = offsets->tv_nsec;
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsGetTimeContainerCount(VOID)
|
||||
{
|
||||
return g_currentTimeContainerNum;
|
||||
}
|
||||
#endif
|
||||
439
kernel/extended/container/los_user_container.c
Normal file
439
kernel/extended/container/los_user_container.c
Normal 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
|
||||
@@ -28,89 +28,16 @@
|
||||
* 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 CreateUtsContainer(UtsContainer **newUtsContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 size = sizeof(UtsContainer);
|
||||
UtsContainer *utsContainer = LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (utsContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
(VOID)memset_s(utsContainer, sizeof(UtsContainer), 0, sizeof(UtsContainer));
|
||||
|
||||
utsContainer->containerID = OsAllocContainerID();
|
||||
LOS_AtomicSet(&utsContainer->rc, 1);
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
g_currentUtsContainerNum += 1;
|
||||
*newUtsContainer = utsContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsCopyUtsContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 ret;
|
||||
UtsContainer *newUtsContainer = NULL;
|
||||
UtsContainer *currUtsContainer = parent->container->utsContainer;
|
||||
|
||||
if (!(flags & CLONE_NEWUTS)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LOS_AtomicInc(&currUtsContainer->rc);
|
||||
child->container->utsContainer = currUtsContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
ret = CreateUtsContainer(&newUtsContainer);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
(VOID)memcpy_s(&newUtsContainer->utsName, sizeof(newUtsContainer->utsName),
|
||||
&currUtsContainer->utsName, sizeof(currUtsContainer->utsName));
|
||||
child->container->utsContainer = newUtsContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsUtsContainersDestroy(LosProcessCB *curr)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (curr->container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
UtsContainer *utsContainer = curr->container->utsContainer;
|
||||
if (utsContainer != NULL) {
|
||||
if (LOS_AtomicRead(&utsContainer->rc) == 0) {
|
||||
g_currentUtsContainerNum--;
|
||||
curr->container->utsContainer = NULL;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, utsContainer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC UINT32 InitUtsContainer(struct utsname *name)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
ret = sprintf_s(name->sysname, sizeof(name->sysname), "%s", KERNEL_NAME);
|
||||
INT32 ret = sprintf_s(name->sysname, sizeof(name->sysname), "%s", KERNEL_NAME);
|
||||
if (ret < 0) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
@@ -137,14 +64,151 @@ STATIC UINT32 InitUtsContainer(struct utsname *name)
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsInitRootUtsContainer(UtsContainer **utsContainer)
|
||||
STATIC UtsContainer *CreateNewUtsContainer(UtsContainer *parent)
|
||||
{
|
||||
UINT32 ret = CreateUtsContainer(utsContainer);
|
||||
UINT32 ret;
|
||||
UINT32 size = sizeof(UtsContainer);
|
||||
UtsContainer *utsContainer = (UtsContainer *)LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (utsContainer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(utsContainer, sizeof(UtsContainer), 0, sizeof(UtsContainer));
|
||||
|
||||
utsContainer->containerID = OsAllocContainerID();
|
||||
if (parent != NULL) {
|
||||
LOS_AtomicSet(&utsContainer->rc, 1);
|
||||
return utsContainer;
|
||||
}
|
||||
LOS_AtomicSet(&utsContainer->rc, 3); /* 3: Three system processes */
|
||||
ret = InitUtsContainer(&utsContainer->utsName);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, utsContainer);
|
||||
return NULL;
|
||||
}
|
||||
return utsContainer;
|
||||
}
|
||||
|
||||
STATIC UINT32 CreateUtsContainer(LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UtsContainer *parentContainer = parent->container->utsContainer;
|
||||
UtsContainer *newUtsContainer = CreateNewUtsContainer(parentContainer);
|
||||
if (newUtsContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
return InitUtsContainer(&(*utsContainer)->utsName);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
g_currentUtsContainerNum++;
|
||||
(VOID)memcpy_s(&newUtsContainer->utsName, sizeof(newUtsContainer->utsName),
|
||||
&parentContainer->utsName, sizeof(parentContainer->utsName));
|
||||
child->container->utsContainer = newUtsContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsInitRootUtsContainer(UtsContainer **utsContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UtsContainer *newUtsContainer = CreateNewUtsContainer(NULL);
|
||||
if (newUtsContainer == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
g_currentUtsContainerNum++;
|
||||
*utsContainer = newUtsContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsCopyUtsContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UtsContainer *currUtsContainer = parent->container->utsContainer;
|
||||
|
||||
if (!(flags & CLONE_NEWUTS)) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LOS_AtomicInc(&currUtsContainer->rc);
|
||||
child->container->utsContainer = currUtsContainer;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (OsContainerLimitCheck(UTS_CONTAINER, &g_currentUtsContainerNum) != LOS_OK) {
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
return CreateUtsContainer(child, parent);
|
||||
}
|
||||
|
||||
UINT32 OsUnshareUtsContainer(UINTPTR flags, LosProcessCB *curr, Container *newContainer)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UtsContainer *parentContainer = curr->container->utsContainer;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
newContainer->utsContainer = utsContainer;
|
||||
g_currentUtsContainerNum++;
|
||||
(VOID)memcpy_s(&utsContainer->utsName, sizeof(utsContainer->utsName),
|
||||
&parentContainer->utsName, sizeof(parentContainer->utsName));
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
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;
|
||||
if (container == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
UtsContainer *utsContainer = container->utsContainer;
|
||||
if (utsContainer == NULL) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&utsContainer->rc);
|
||||
if (LOS_AtomicRead(&utsContainer->rc) > 0) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
g_currentUtsContainerNum--;
|
||||
container->utsContainer = NULL;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, utsContainer);
|
||||
return;
|
||||
}
|
||||
|
||||
struct utsname *OsGetCurrUtsName(VOID)
|
||||
@@ -169,4 +233,8 @@ UINT32 OsGetUtsContainerID(UtsContainer *utsContainer)
|
||||
return utsContainer->containerID;
|
||||
}
|
||||
|
||||
UINT32 OsGetUtsContainerCount(VOID)
|
||||
{
|
||||
return g_currentUtsContainerNum;
|
||||
}
|
||||
#endif
|
||||
@@ -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",
|
||||
".",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -80,20 +80,25 @@ EXIT:
|
||||
STATIC LmsMemListNode *OsLmsGetPoolNodeFromAddr(UINTPTR addr)
|
||||
{
|
||||
LmsMemListNode *current = NULL;
|
||||
LmsMemListNode *previous = NULL;
|
||||
LOS_DL_LIST *listHead = &g_lmsCheckPoolList;
|
||||
|
||||
if (LOS_ListEmpty(&g_lmsCheckPoolList)) {
|
||||
goto EXIT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(current, listHead, LmsMemListNode, node) {
|
||||
if ((addr >= current->poolAddr) && (addr < current->poolAddr + current->poolSize)) {
|
||||
return current;
|
||||
if ((addr < current->poolAddr) || (addr >= (current->poolAddr + current->poolSize))) {
|
||||
continue;
|
||||
}
|
||||
if ((previous == NULL) ||
|
||||
((previous->poolAddr <= current->poolAddr) &&
|
||||
((current->poolAddr + current->poolSize) <= (previous->poolAddr + previous->poolSize)))) {
|
||||
previous = current;
|
||||
}
|
||||
}
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
return previous;
|
||||
}
|
||||
|
||||
STATIC LmsMemListNode *OsLmsCheckPoolCreate(VOID)
|
||||
@@ -123,18 +128,12 @@ UINT32 LOS_LmsCheckPoolAdd(const VOID *pool, UINT32 size)
|
||||
|
||||
LMS_LOCK(intSave);
|
||||
|
||||
lmsPoolNode = OsLmsGetPoolNodeFromAddr((UINTPTR)pool);
|
||||
if (lmsPoolNode != NULL) { /* if pool range already on checklist */
|
||||
if (lmsPoolNode->poolAddr != (UINTPTR)pool) { /* pool is a subset of lmsPoolNode->poolAddr */
|
||||
/* do not add it again, just return */
|
||||
PRINT_DEBUG("[LMS]pool %p already on lms checklist !\n", pool);
|
||||
LMS_UNLOCK(intSave);
|
||||
return size; /* return size indicate the shadow memory init successful */
|
||||
} else { /* Re-initialize the same pool, maybe with different size */
|
||||
/* delete the old node, then add a new one */
|
||||
lmsPoolNode->used = LMS_POOL_UNUSED;
|
||||
LOS_ListDelete(&(lmsPoolNode->node));
|
||||
}
|
||||
lmsPoolNode = OsLmsGetPoolNode(pool);
|
||||
if (lmsPoolNode != NULL) { /* if pool already on checklist */
|
||||
/* Re-initialize the same pool, maybe with different size */
|
||||
/* delete the old node, then add a new one */
|
||||
lmsPoolNode->used = LMS_POOL_UNUSED;
|
||||
LOS_ListDelete(&(lmsPoolNode->node));
|
||||
}
|
||||
|
||||
lmsPoolNode = OsLmsCheckPoolCreate();
|
||||
@@ -150,7 +149,8 @@ UINT32 LOS_LmsCheckPoolAdd(const VOID *pool, UINT32 size)
|
||||
lmsPoolNode->shadowStart = (UINTPTR)poolAddr + realSize;
|
||||
lmsPoolNode->shadowSize = poolAddr + size - lmsPoolNode->shadowStart;
|
||||
/* init shadow value */
|
||||
(VOID)memset((VOID *)lmsPoolNode->shadowStart, LMS_SHADOW_AFTERFREE_U8, lmsPoolNode->shadowSize);
|
||||
(VOID)memset_s((VOID *)lmsPoolNode->shadowStart, lmsPoolNode->shadowSize,
|
||||
LMS_SHADOW_AFTERFREE_U8, lmsPoolNode->shadowSize);
|
||||
|
||||
LOS_ListAdd(&g_lmsCheckPoolList, &(lmsPoolNode->node));
|
||||
|
||||
@@ -179,10 +179,11 @@ Release:
|
||||
|
||||
STATIC UINT32 OsLmsInit(VOID)
|
||||
{
|
||||
(VOID)memset(g_lmsCheckPoolArray, 0, sizeof(g_lmsCheckPoolArray));
|
||||
(VOID)memset_s(g_lmsCheckPoolArray, sizeof(g_lmsCheckPoolArray), 0, sizeof(g_lmsCheckPoolArray));
|
||||
LOS_ListInit(&g_lmsCheckPoolList);
|
||||
static LmsHook hook = {
|
||||
.init = LOS_LmsCheckPoolAdd,
|
||||
.deInit = LOS_LmsCheckPoolDel,
|
||||
.mallocMark = OsLmsLosMallocMark,
|
||||
.freeMark = OsLmsLosFreeMark,
|
||||
.simpleMark = OsLmsSimpleMark,
|
||||
@@ -595,7 +596,7 @@ VOID OsLmsReportError(UINTPTR p, UINT32 size, UINT32 errMod)
|
||||
|
||||
(VOID)LOS_AtomicAdd(&g_checkDepth, 1);
|
||||
LMS_LOCK(intSave);
|
||||
(VOID)memset(&info, 0, sizeof(LmsAddrInfo));
|
||||
(VOID)memset_s(&info, sizeof(LmsAddrInfo), 0, sizeof(LmsAddrInfo));
|
||||
|
||||
PRINT_ERR("***** Kernel Address Sanitizer Error Detected Start *****\n");
|
||||
|
||||
@@ -766,4 +767,4 @@ VOID __asan_handle_no_return(VOID)
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_MODULE_INIT(OsLmsInit, LOS_INIT_LEVEL_KMOD_PREVM);
|
||||
LOS_MODULE_INIT(OsLmsInit, LOS_INIT_LEVEL_KMOD_PREVM);
|
||||
|
||||
@@ -95,6 +95,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
UINT32 (*init)(const VOID *pool, UINT32 size);
|
||||
VOID (*deInit)(const VOID *pool);
|
||||
VOID (*mallocMark)(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
|
||||
VOID (*freeMark)(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
|
||||
VOID (*simpleMark)(UINTPTR startAddr, UINTPTR endAddr, UINT32 value);
|
||||
@@ -132,4 +133,4 @@ extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_handle_no_return(VOID);
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_LMS_PRI_H */
|
||||
#endif /* _LOS_LMS_PRI_H */
|
||||
|
||||
@@ -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")
|
||||
|
||||
46
kernel/extended/plimit/BUILD.gn
Normal file
46
kernel/extended/plimit/BUILD.gn
Normal 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 = [ "." ]
|
||||
}
|
||||
35
kernel/extended/plimit/Makefile
Normal file
35
kernel/extended/plimit/Makefile
Normal 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)
|
||||
599
kernel/extended/plimit/los_devicelimit.c
Normal file
599
kernel/extended/plimit/los_devicelimit.c
Normal file
@@ -0,0 +1,599 @@
|
||||
/*
|
||||
* 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 *acc, INT16 access)
|
||||
{
|
||||
INT32 index = 0;
|
||||
(VOID)memset_s(acc, ACCLEN, 0, ACCLEN);
|
||||
if (access & DEVLIMIT_ACC_READ) {
|
||||
acc[index++] = 'r';
|
||||
}
|
||||
if (access & DEVLIMIT_ACC_WRITE) {
|
||||
acc[index++] = 'w';
|
||||
}
|
||||
if (access & DEVLIMIT_ACC_MKNOD) {
|
||||
acc[index++] = 'm';
|
||||
}
|
||||
}
|
||||
|
||||
STATIC CHAR DevLimitItemTypeToChar(INT16 type)
|
||||
{
|
||||
if (type == DEVLIMIT_DEV_ALL) {
|
||||
return 'a';
|
||||
} else if (type == DEVLIMIT_DEV_CHAR) {
|
||||
return 'c';
|
||||
} else if (type == DEVLIMIT_DEV_BLOCK) {
|
||||
return 'b';
|
||||
}
|
||||
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
|
||||
96
kernel/extended/plimit/los_devicelimit.h
Normal file
96
kernel/extended/plimit/los_devicelimit.h
Normal 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 */
|
||||
249
kernel/extended/plimit/los_ipclimit.c
Normal file
249
kernel/extended/plimit/los_ipclimit.c
Normal 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
|
||||
92
kernel/extended/plimit/los_ipclimit.h
Normal file
92
kernel/extended/plimit/los_ipclimit.h
Normal 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 */
|
||||
223
kernel/extended/plimit/los_memlimit.c
Normal file
223
kernel/extended/plimit/los_memlimit.c
Normal 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
|
||||
69
kernel/extended/plimit/los_memlimit.h
Normal file
69
kernel/extended/plimit/los_memlimit.h
Normal 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 */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user