Compare commits

...

71 Commits

Author SHA1 Message Date
openharmony_ci c959698519
!1066 【挑单】time相关系统调用内核栈信息泄露排查
Merge pull request !1066 from zhushengle/cherry-pick-1668148730
2022-11-11 08:12:00 +00:00
zhushengle c2dd72e356 fixed 0b05a46 from https://gitee.com/zhushengle/kernel_liteos_a/pulls/1061
task: time相关系统调用内核栈信息泄露排查

解决方案:
    在涉及从内核拷贝数据到用户态的场景时,先将内核的数据进行清零操作,再填充内核数据
Close #I60M1P

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ia61d4e39b9e190accea477ff5b361e41d0eed2af
2022-11-11 06:38:50 +00:00
openharmony_ci a7080aaa85
!889 FatFs升级r0.14a版本同步3.0分支
Merge pull request !889 from wangchen/05_31_up_a
2022-06-02 07:43:01 +00:00
wangchen 1f7e6fa76f fix: FatFs升级r0.14a版本同步3.0分支
【背景】FatFs升级r0.14a版本同步3.0分支

【修改方案】
将三方库FatFs升级至r0.14a版本
主要修改点为:
适配_mkfs、find_volume接口更新
【影响】
对现有的产品编译不会有影响。
re #I5A7AS
Signed-off-by: wangchen <wangchen64@huawei.com>

Change-Id: I428fcb930fa0ead43ea033d14898fc0a00445933
2022-05-31 08:57:16 +00:00
openharmony_ci efd00c1e0d
!872 内核codex清零
Merge pull request !872 from Kiita/0421_codex
2022-04-25 02:25:39 +00:00
zhangyan ffe7462c7f 内核codex告警清零
Signed-off-by: Kiita <zhanyan@huawei.com>
Change-Id: I6b0bc9ba638f7aa73be754d5c92561fc372de1c6
2022-04-24 03:13:12 +00:00
openharmony_ci 6d7641af53
!812 3.0 LTS 告警清零
Merge pull request !812 from yinjiaming/OpenHarmony-3.0-LTS
2022-03-09 03:54:00 +00:00
yinjiaming 143309945a fix: 3.0 lts 告警清零
【背景】
3.0 lts 告警清零

【修改方案】
添加了强制类型转换

【影响】
对现有的产品编译不会有影响。

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: I6faba4fe43ec127ad2a75b7123d0365b9903045b
2022-03-03 09:15:59 +00:00
openharmony_ci 9c1e902b55
!809 3.0 LTS 告警清零
Merge pull request !809 from yinjiaming/OpenHarmony-3.0-LTS
2022-03-02 03:14:43 +00:00
yinjiaming 84011c89a5 fix: 3.0 LTS 告警清零
【背景】
3.0 LTS 经过扫描有一些告警需要清理

【修改方案】
在需要的地方添加了强制类型转换

【影响】
对现有的产品编译不会有影响。

re #I4UZW3

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: I1f9cd16293b649ea9f9b3c4d3d02b1bfe95114e2
2022-02-23 11:02:55 +00:00
openharmony_ci 89154a3765
!777 [LTS-3.0]修复toybox mv指令能够移动成功,但提示错误22的BUG
Merge pull request !777 from Far/cherry-pick-1641884328
2022-01-12 02:21:53 +00:00
Far 8e6f3f1bfb fix: 修复futime提示错误22的BUG
调用futime时,系统调用接口函数直接使用了file结构体的f_path字段,该字段在退出前被错误地释放了。
避免该问题需要拷贝一份路径

Signed-off-by: Far <yesiyuan2@huawei.com>
Change-Id: Ic0f8e608363da3ed15e252a3f91c46e8397c245e
2022-01-11 16:03:17 +08:00
openharmony_ci d5c8341bb0
!775 【轻量级 PR】:reduce print log if hilog ringbuffer is full
Merge pull request !775 from shenchenkai/N/A
2022-01-11 06:29:33 +00:00
shenchenkai 157fb8b212
reduce print log if hilog ringbuffer is full
Signed-off-by: shenchenkai <shenchenkai@huawei.com>
2022-01-11 04:14:49 +00:00
openharmony_ci 95f7cf16d0
!770 LOS_PaddrToKVaddr函数的实现存在冗余修改
Merge pull request !770 from 闻飞/OpenHarmony-3.0-LTS
2022-01-10 13:19:32 +00:00
wenfei6316 790573d018 fix LOS_PaddrToKVaddr function logical redundancy
Signed-off-by: wenfei6316 <wenfei6316@163.com>
2022-01-07 16:18:14 +08:00
openharmony_ci 246bdd11d8
!760 fix: shell支持exit退出,完善帮助信息,特殊处理不可见字符
Merge pull request !760 from huangshan/cherry-pick-1640932477
2022-01-07 03:20:56 +00:00
huangshan 017d8163ea fixed cc6e112 from https://gitee.com/uhamc/kernel_liteos_a/pulls/702
fix: shell支持exit退出,完善帮助信息,特殊处理不可见字符

Change-Id: Ia6dbff0faed4ec73fcf35691676f1acb2b8df78d
Signed-off-by: huangshan <huangshan9@huawei.com>
2021-12-31 06:34:40 +00:00
openharmony_ci f6d727fed8 !753 fix: implicit declaration of function 'syscall' in apps/shell
Merge pull request !753 from huangshan/673
2021-12-31 06:16:07 +00:00
openharmony_ci a771e39988 !754 fix: 修复Ctrl+C会终止所有进程的问题
Merge pull request !754 from huangshan/cherry-pick-1640571697
2021-12-31 06:16:01 +00:00
openharmony_ci 594f50733e !742 添加bundle.json
Merge pull request !742 from pjscc/OpenHarmony-3.0-LTS
2021-12-31 03:13:18 +00:00
openharmony_ci 10bf30f91f !758 【轻量级 PR】:fix: 修复重复执行内存用例导致系统卡死问题同步
Merge pull request !758 from Harylee/N/A
2021-12-30 08:20:49 +00:00
Harylee 60e77d0ea7
fix: 修复重复执行内存用例导致系统卡死问题同步
Signed-off-by: Haryslee <lihao189@huawei.com>
2021-12-29 11:55:31 +00:00
openharmony_ci 68b477588f !741 [LTS-3.0]修复los_disk_cache_clear有条件编译错误
Merge pull request !741 from Far/cherry-pick-1640053131
2021-12-29 03:43:29 +00:00
pjscc 2f8d12ece1 feat: 添加bundle.json作为hpm包管理描述文件
Signed-off-by: pjscc <pangjiashuai@huawei.com>
2021-12-29 10:41:28 +08:00
huangshan 12d4bc05f4 fixed cdc0877 from https://gitee.com/uhamc/kernel_liteos_a/pulls/693
修复Ctrl+C会终止所有进程的问题

Signed-off-by: huangshan <huangshan9@huawei.com>
Change-Id: I5861569c63fd6c1adf8c702797e4d79eba76211f
2021-12-27 02:21:37 +00:00
uhamc b9d012b026 fix: implicit declaration of function 'syscall' in apps/shell
Change-Id: Id3f56ac53ec5a3c86b04bcb7a4611f2eb77f4b80
Signed-off-by: uhamc <uhamc@foxmail.com>
2021-12-27 10:07:03 +08:00
openharmony_ci b0f642b493 !748 fix: 临终遗言重定向内容缺失task相关信息,对应的shell命令中申请的内存需要cacheline对齐
Merge pull request !748 from zhushengle/OpenHarmony-3.0-LTS
2021-12-25 02:55:52 +00:00
openharmony_ci 6c36623ac7 !746 fix: 修复xts权限用例压测异常问题
Merge pull request !746 from Harylee/cherry-pick-1640220757
2021-12-25 02:10:44 +00:00
zhushengle 9078efccd1 fix: 临终遗言重定向内容缺失task相关信息,对应的shell命令中申请的内存需要cacheline对齐
1.内核打印的地方支持异常时重定向打印信息
2.excinfo 命令中申请的内存64对齐

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I6ccd57b93b4a6e2eeabe5b366e9c0eb262dcad8e
2021-12-24 12:17:41 +08:00
openharmony_ci b7c4acfb78 !745 fix: 非当前进程退出时,销毁liteipc时错误的销毁了当前进程的
Merge pull request !745 from zhushengle/OpenHarmony-3.0-LTS
2021-12-24 03:57:14 +00:00
Haryslee aaa3cc9d7b fixed b0d31cb from https://gitee.com/harylee/kernel_liteos_a/pulls/738
fix: 修复xts权限用例压测异常问题

用例异常时出现Domain fault或者unknown fault,经分析发现是TLB缓存一致性问题,
在缺页异常入口,对上述两种异常类型做异常地址TLB缓存清理即可。

close #I3ZJ1D

Signed-off-by: Haryslee <lihao189@huawei.com>
Change-Id: Ib84e3e87047fcac392b83a4cf6cca0d91754e66f
2021-12-23 00:52:37 +00:00
openharmony_ci dc8853bb78 !743 fix: 优化trace buffer初始化,删除swtmr 桩中的无效参数
Merge pull request !743 from Zhaotianyu/cherry-pick-1640160115
2021-12-22 09:30:55 +00:00
zhushengle 892201f67b fix: 非当前进程退出时,销毁liteipc时错误的销毁了当前进程的
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Icf6688cf0d15efd0c6ef278f3fce37bf3849b03a
2021-12-22 17:24:08 +08:00
LiteOS2021 91709a3599 fixed b551270 from https://gitee.com/arvinzzz/kernel_liteos_a/pulls/660
fix: 优化trace buffer初始化,删除swtmr 桩中的无效参数
    close #I4DQ1X
Signed-off-by: LiteOS2021 <dinglu@huawei.com>

Change-Id: I79b416720f5327749a5884a65a5e61db07f2a17c
2021-12-22 08:02:09 +00:00
Far 332ba8fd65 fixed 63e71fe from https://gitee.com/yesiyuanjim/kernel_liteos_a/pulls/731
fix: 修复LOSCFG_FS_FAT_CACHE宏关闭后编译失败的BUG

1. 在必要处增加宏开关关闭部分代码的编译;
2. 由于驱动是一个独立的内核线程,在一些场景下文件系统会将用户态地址透传给驱动,这会导致内核崩溃。
因此在需要透传用户态地址时增加了一个内核buffer作为中转。

Close #I3T3N0

Signed-off-by: Far <yesiyuan2@huawei.com>
2021-12-21 02:18:52 +00:00
openharmony_ci d9752abcb4 !736 支持产品定制化hilog内核缓存大小
Merge pull request !736 from shenchenkai/OpenHarmony-3.0-LTS
2021-12-18 06:53:05 +00:00
shenchenkai 12cc392f46 Description:[feature] support customized hilog ring buffer size
Change-Id: I5d23deaada5939bbb6fb57505f72c2348bd6afe9
Signed-off-by: shenchenkai <shenchenkai@huawei.com>
2021-12-17 15:56:15 +08:00
openharmony_ci 62aa4aa0b1 !725 Codex警告清零
Merge pull request !725 from yinjiaming/yjm-kernel-fs-20211203
2021-12-03 07:08:29 +00:00
yinjiaming 929a282bad 【背景】
codex 告警清零
【修改方案】
修改和添加了procfs的默认文件模式的宏定义,对进行位操作运算的有符号数进行强制类型转换

【影响】
对现有的产品编译不会有影响。

re #I4KVS7

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
2021-12-03 01:41:48 +00:00
openharmony_ci 8bb15bf8e7 !720 当hilog/hievent驱动缓存出问题时,进行恢复处理
Merge pull request !720 from shenchenkai/cherry-pick-1637986052
2021-11-29 03:55:39 +00:00
openharmony_ci aec7840626 !718 [LTS-3.0]修复jffs2适配层错误释放锁的BUG
Merge pull request !718 from Far/cherry-pick-1637906208
2021-11-27 07:48:22 +00:00
shenchenkai e43e252e14 fixed c121d0e from https://gitee.com/shenchenkai/kernel_liteos_a/pulls/670
Description:[fix] clean hilog/hievent ring buffer after memory verification failed

Change-Id: I9310fe807ec95721be78deb60ed9728ef9b56e48
Signed-off-by: shenchenkai <shenchenkai@huawei.com>
2021-11-27 04:07:32 +00:00
Far ba4ed5a599 fixed 011a55f from https://gitee.com/yesiyuanjim/kernel_liteos_a/pulls/712
fix: 修复jffs2适配层错误释放锁的BUG

修复重复释放jffs2全局锁的BUG

Close #I4FH9M

Signed-off-by: Far <yesiyuan2@huawei.com>
2021-11-26 05:56:54 +00:00
openharmony_ci 55bdf174b8 !700 修改blackbox生成的文件和文件夹权限
Merge pull request !700 from mgceshuang/cherry-pick-1636013017
2021-11-08 02:26:54 +00:00
openharmony_ci c8c3034709 !688 PR665 misc09用例修改挑单到3.0LTS
Merge pull request !688 from pef/OpenHarmony-3.0-LTS
2021-11-04 11:45:23 +00:00
YOUR_NAME f32154f9cb fixed f360b21 from https://gitee.com/mgce/kernel_liteos_a/pulls/698
add blackbox to 2.3

Signed-off-by: YOUR_NAME <mashuang9@huawei.com>
2021-11-04 08:03:37 +00:00
openharmony_ci 60d3f6d5da !689 PR666 关于sys用例修复挑单到3.0TLS
Merge pull request !689 from pef/OpenHarmony-3.0-LTS_sys_test
2021-11-04 02:08:43 +00:00
openharmony_ci 44279b256a !694 PR676 关于ppoll修改挑单到3.0TLS
Merge pull request !694 from pef/OpenHarmony-3.0-1102
2021-11-04 02:08:40 +00:00
lnlan 951d233676 修复ppoll接口"[ERR]OsMemFree check error!"报错
【背景】
1.内核中释放用户空间指针报错:"[ERR]OsMemFree check error!"
2.现有ppoll实现存在问题
3.相关用例需要整理
【修改方案】
1.去掉释放用户空间指针操作
2.更正逻辑错误
3.更正掩码设置与恢复不起作用
4.修复补充现有用例
【影响】
对现有的产品编译不会有影响。

re #I47YWZ

Change-Id: Ib2f60986e9cafb2ea5ef1097ab8552cbb1ede5b4
Signed-off-by: lnlan <lanleinan@163.com>
2021-11-02 11:41:07 +00:00
pef ca70dc4dd1 修复ppoll接口"[ERR]OsMemFree check error!"报错
【背景】
内核中释放用户空间指针报错:"[ERR]OsMemFree check error!"

【修改方案】
修改SysPpoll函数。

【影响】
对现有的产品编译不会有影响。

re #I47YWZ

Change-Id: Id7f86036870d4f32be8fc438b9aad85cdda59546
Signed-off-by: pef <cyd1997@126.com>
2021-11-02 11:40:55 +00:00
teamol a693cd4198 fix: fix ppoll
1.modifications:
modified:   syscall/fs_syscall.c
2.modify 2 testcases:
IO/full/IO_test_ppoll_001.cpp
IO/full/IO_test_ppoll_002.cpp
3.influence:
none

Signed-off-by: pef <cyd1997@126.com>
Change-Id: I85fc091098a6dfef1a4694a3bbc489640ee6dda2
2021-11-02 11:40:25 +00:00
lnlan f249db759d fix(test): 修复sys部分用例因依赖passwd、group文件而失败
【背景】
1.sys部分用例因依赖passwd、group文件而失败

【修改方案】
1.用例执行前检查是否存在这些配置文件,不存在就跳过该用例

re#I48IUC

Change-Id: I787ce4b200f2a7546e57290b7dd073127caa07bb
Signed-off-by: lnlan <lanleinan@163.com>
2021-11-01 01:27:22 +00:00
lnlan 6f0c5d10e2 fix(test): misc09用例因依赖hosts文件而失败
【背景】
1.etc/hosts文件不存在,misc09依赖hosts文件而失败

【修改方案】
1.用例执行前检查是否存在这些配置文件,不存在就跳过该用例

re#I48IZ0

Change-Id: I193cb03770932c1f681cd726ceb383816aa2257a

Signed-off-by: lnlan <lanleinan@163.com>
Change-Id: I3fb7ca1ed5f8cc79a56cd1872f3b303ab325a7a9
2021-11-01 01:21:34 +00:00
openharmony_ci ca8909b8e3 !677 a核ioctl支持SIOCGIFBRDADDR选项
Merge pull request !677 from 刘建东/cherry-pick-1635300058
2021-10-27 08:47:35 +00:00
openharmony_ci 431c9e9d61 !678 signal内存泄露修复挑单到3.0tls
Merge pull request !678 from lnlan/tlsSignalFixed
2021-10-27 06:30:54 +00:00
lnlan d71db99932 fix: 修复PR520缺陷
【背景】
https://gitee.com/openharmony/kernel_liteos_a/pulls/520
上面修改,信号处理时才会释放申请的内存,当信号被屏蔽,且一直发送该信号时,
内存占用会不断变大
【修改方案】
1.
信号发送时已经有该信号的siginfo在链表中时,不再重新申请,重复使用之前的siginfo.

【影响】
对现有的产品编译不会有影响。

re#I4DEG5

Signed-off-by: lanleinan <lanleinan@163.com>

Change-Id: I74b3b7ff0b9efb0179313af9a0c8d1e12d1db5bb
2021-10-27 03:52:39 +00:00
YOUR_NAME 6b54224726 fixed 4ecc473 from https://gitee.com/life-liu/kernel_liteos_a/pulls/659
feat: add option SIOCGIFBRDADDR for ioctl

add option SIOCGIFBRDADDR for ioctl

close: #I4DNRF

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-10-27 02:01:00 +00:00
openharmony_ci 9ac04e886a !653 fix: 进程在退出前回收vmspace中的所有Region
Merge pull request !653 from zhushengle/cherry-pick-1633924550
2021-10-14 02:59:28 +00:00
zhushengle 06b0396945 fixed 298ccea from https://gitee.com/zhushengle/kernel_liteos_a/pulls/631
fix: 进程退出前自己回收vmspace中的所有region

背景:
父进程fork一个子进程,调用waitpid等待子进程结束。
子进程dlopen一个文件a.so,并退出。当守护进程正在
1核回收子进程资源时,父进程在0核运行从waitpid返
回后,同时remove a.so概率失败。

Close #I4CKQC

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ie7940e7c931ced10ee357cf9aa7c64355effed49
2021-10-11 03:55:51 +00:00
openharmony_ci bb3590a448 !648 pagecache优化需求回合到LTS 3.0分支
Merge pull request !648 from LeonChan/pg3
2021-10-08 07:38:41 +00:00
Leon Chan 027fa6136a feat: page cache backed by vnode instead of filep
1, change the owner of page to vnode
2, save the file path in vnode

close: #I4AGBR
Signed-off-by: Leon Chan <chenwei26@huawei.com>
Change-Id: I04f93e344c7231d1731746456babc419a6139e52
Signed-off-by: Leon Chan <chenwei26@huawei.com>
2021-09-30 16:21:03 +08:00
openharmony_ci 532f96d746 !647 将menuconfig 与 update_config功能做成一样
Merge pull request !647 from Caoruihong/cherry-pick-1632974889
2021-09-30 07:19:10 +00:00
Caoruihong d2bc8f2f1b fixed 3dd952b from https://gitee.com/caoruihong/kernel_liteos_a/pulls/646
chore(make): make menuconfig same as update_config

Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: I5c4a1a0601865c1c7d6ae40b829abdb53f13ccd3
2021-09-30 04:08:10 +00:00
Guangyao Ma e5c7549bc2 fix: dyload open close failed
本次提交修复内核加载器,异常情况分支的一个bug:mksh通过exec命令(mksh内置命令
,正常情况下,该命令成功执行会复用mksh进程空间,拉起新的指定进程)。但是如果
进程没有成功加载的情况下,内核加载器的异常分支会错误释放mksh的fd句柄。最终导致
下次拉起其他进程时(fork + exec方式),新的进程会继承fd,映射了早就释放的sysfd
,此时的sysfd可能已经被复用,issue场景下这个sysfd被加载过程中打开的libc.so占用
,exec时会释放procfd->sysfd(错误的映射关系),最终新进程libc.so被关闭。
导致内核崩溃。

close #I452Z7

Signed-off-by: Guangyao Ma <guangyao.ma@outlook.com>
Change-Id: Ifca809f88b5ffcfb879dc5520d1f6adf5cf92bcd
2021-09-30 10:56:11 +08:00
openharmony_ci 832001a6af !645 去除mtd对hisilicon驱动的依赖
Merge pull request !645 from SimonLi/OpenHarmony-3.0-LTS
2021-09-30 02:43:38 +00:00
SimonLi 7d7188c737 fix(mtd): 去除mtd对hisilicon驱动的依赖
【背景】
1. liteos-a内核drivers/mtd/multi_partition/用到了device/hisilicon下的驱动函数实
现,这样导致三方芯片适配时,会依赖hisilicon的驱动。
2. HDF的mtd驱动提供了这几个函数的实现,但是未暴露头文件出来。

【修改方案】
1. 修改BUILD.gn去除/device/hisilicon的依赖。
2. 修改mtd_partition.c,将hisilicon的头文件改为hdf的头文件依赖。

【遗留问题】
liteos-a内核与HDF mtd驱动的分界线还不明确,导致依赖关系不清楚

close: #I49FKL

Signed-off-by: SimonLi <likailong@huawei.com>
2021-09-29 20:51:11 +08:00
openharmony_ci 88a0caae24 !632 fix: 共享内存问题修复
Merge pull request !632 from Harylee/cherry-pick-1632710893
2021-09-27 06:54:52 +00:00
openharmony_ci 99824916dd !630 master分支关于sigwait的修改挑单到TLS
Merge pull request !630 from lnlan/to_LTS
2021-09-27 02:53:36 +00:00
Haryslee 42fdaffe76 fixed 9fdb80f from https://gitee.com/harylee/kernel_liteos_a/pulls/628
fix: 共享内存问题修复

Signed-off-by: Haryslee <lihao189@huawei.com>
背景:父进程移除共享内存并标记SHM_SEG_REMOVE,当子进程资源回收时在
ShmFindSeg接口中判断该共享内存具有SHM_SEG_REMOVE时返回空,但是此时
seg->ds.shm_nattch不为0,不应返回空。
方案:ShmFindSeg接口中增加seg->ds.shm_nattch为0的判断。

close #I47X2Z

Change-Id: I8735cd11ac237b17fa745c50313da0fd0649bb9f
2021-09-27 02:48:14 +00:00
lnlan ed7defbd43 fix: 修复sigwait等待到的信号值与获取的siginfo中的值不一致
【背景】
集成测试发送两个不同的信号,sigwait第二次等到的仍是第一个信号
经定位,信号在kill时会将相关的siginfo信息拷贝到taskcb的unbinfo中,sigwait
处理时从unbinfo拷贝给用户。若此信号发送时处于屏蔽状态,再有其他信号发送会覆盖
掉unbinfo,此时sigwait等待这个信号获取到的info已经被覆盖
【修改方案】
1. 每个任务添加一个siginfo缓存链表,在处理信号前夕从缓存链表取出info到unbinfo中

【影响】
对现有的产品编译不会有影响。

re #I3M12H

Signed-off-by: lanleinan <lanleinan@163.com>

Change-Id: If4b064c18773f8eca7419c665977260167b09810
2021-09-26 09:57:32 +00:00
101 changed files with 1980 additions and 1342 deletions

View File

@ -141,14 +141,14 @@ ifeq ($(origin SYSROOT_PATH),file)
endif
endif
$(KCONFIG_CMDS):
$(filter-out menuconfig,$(KCONFIG_CMDS)):
$(HIDE)$@ $(args)
$(LITEOS_CONFIG_FILE): $(KCONFIG_CONFIG)
$(HIDE)env KCONFIG_CONFIG=$< genconfig --config-out $@ --header-path $(LITEOS_MENUCONFIG_H)
update_config:
$(HIDE)test -f "$(CONFIG)" && cp -v "$(CONFIG)" .config && menuconfig && savedefconfig --out "$(CONFIG)"
update_config menuconfig:
$(HIDE)test -f "$(CONFIG)" && cp -v "$(CONFIG)" .config && menuconfig $(args) && savedefconfig --out "$(CONFIG)"
$(LITEOS_LIBS_TARGET): sysroot
$(HIDE)for dir in $(LIB_SUBDIRS); do $(MAKE) -C $$dir all || exit 1; done

View File

@ -30,7 +30,7 @@
include $(LITEOSTOPDIR)/config.mk
# common flags config
BASE_OPTS := -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE $(LITEOS_GCOV_OPTS)
BASE_OPTS := -D_FORTIFY_SOURCE=2 -D_XOPEN_SOURCE=700 $(LITEOS_GCOV_OPTS)
ASFLAGS :=
CFLAGS := $(LITEOS_COPTS) $(BASE_OPTS) -fPIE

View File

@ -29,9 +29,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include "unistd.h"
#include "shcmd.h"

View File

@ -43,8 +43,13 @@ extern "C" {
#define SHELL_ENTRY_STACKSIZE 0x1000
#define SHELL_TASK_STACKSIZE 0x3000
#define SHELL_EXEC_COMMAND "exec "
#define SHELL_EXEC_COMMAND_BYTES 5
#define SHELL_EXEC_COMMAND "exec"
#define SHELL_EXEC_COMMAND_BYTES 4
#define CMD_EXEC_COMMAND SHELL_EXEC_COMMAND" "
#define CMD_EXEC_COMMAND_BYTES (SHELL_EXEC_COMMAND_BYTES+1)
#define CMD_EXIT_COMMAND "exit"
#define CMD_EXIT_COMMAND_BYTES 4
#define CMD_EXIT_CODE_BASE_DEC 10
#define CONSOLE_IOC_MAGIC 'c'
#define CONSOLE_CONTROL_REG_USERTASK _IO(CONSOLE_IOC_MAGIC, 7)
@ -57,6 +62,7 @@ extern "C" {
typedef void (*OutputFunc)(const char *fmt, ...);
extern int ShellTaskInit(ShellCB *shellCB);
extern int ShellEntryInit(ShellCB *shellCB);
extern void ChildExec(const char *cmdName, char *const paramArray[]);
extern void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB);
extern int ShellNotify(ShellCB *shellCB);

View File

@ -29,6 +29,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include "show.h"
#include "shmsg.h"
#include "shcmd.h"
@ -95,6 +97,9 @@ static int DoShellExec(char **argv)
int ret = SH_NOK;
char *cmdLine = NULL;
if (strncmp(argv[0], SHELL_EXEC_COMMAND, SHELL_EXEC_COMMAND_BYTES) == 0) {
ChildExec(argv[1], argv + 1);
}
for (i = 0; argv[i]; i++) {
len += strlen(argv[i]);
}
@ -121,7 +126,7 @@ int main(int argc, char **argv)
int ret = SH_NOK;
ShellCB *shellCB = NULL;
if (!strcmp(argv[0], "shell") && argv[1]) {
if (argc > 1) {
ret = DoShellExec(argv + 1);
return ret;
}

View File

@ -29,6 +29,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include "stdlib.h"
#include "stdio.h"
#include "unistd.h"
@ -42,7 +44,10 @@
#include "shell_pri.h"
#include "shcmd.h"
#define CHAR_CTRL_C '\x03'
#define CHAR_CTRL_DEL '\x7F'
#define VISIABLE_CHAR(ch) ((ch) > 0x1F && (ch) < 0x7F)
char *GetCmdline(ShellCB *shellCB)
{
@ -200,7 +205,21 @@ void ParseEnterKey(OutputFunc outputFunc, ShellCB *shellCB)
shellCB->shellBuf[shellCB->shellBufOffset] = '\0';
}
NOTIFY:
outputFunc("\n");
shellCB->shellBufOffset = 0;
ShellTaskNotify(shellCB);
}
void ParseCancelKey(OutputFunc outputFunc, ShellCB *shellCB)
{
if ((shellCB == NULL) || (outputFunc == NULL)) {
return;
}
if (shellCB->shellBufOffset <= (SHOW_MAX_LEN - 1)) {
shellCB->shellBuf[0] = CHAR_CTRL_C;
shellCB->shellBuf[1] = '\0';
}
shellCB->shellBufOffset = 0;
ShellTaskNotify(shellCB);
}
@ -236,7 +255,7 @@ void ParseTabKey(OutputFunc outputFunc, ShellCB *shellCB)
void ParseNormalChar(char ch, OutputFunc outputFunc, ShellCB *shellCB)
{
if ((shellCB == NULL) || (outputFunc == NULL)) {
if ((shellCB == NULL) || (outputFunc == NULL) || !VISIABLE_CHAR(ch)) {
return;
}
@ -254,7 +273,7 @@ void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB)
const char ch = c;
int ret;
if ((shellCB->shellBufOffset == 0) && (ch != '\n') && (ch != '\0')) {
if ((shellCB->shellBufOffset == 0) && (ch != '\n') && (ch != CHAR_CTRL_C) && (ch != '\0')) {
(void)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN);
}
@ -263,8 +282,11 @@ void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB)
case '\n': /* enter */
ParseEnterKey(outputFunc, shellCB);
break;
case CHAR_CTRL_C: /* ctrl + c */
ParseCancelKey(outputFunc, shellCB);
break;
case '\b': /* backspace */
case 0x7F: /* delete(0x7F) */
case CHAR_CTRL_DEL: /* delete(0x7F) */
ParseDeleteKey(outputFunc, shellCB);
break;
case '\t': /* tab */
@ -329,40 +351,80 @@ char *GetCmdName(const char *cmdline, unsigned int len)
return cmdName;
}
void ChildExec(const char *cmdName, char *const paramArray[])
{
int ret;
pid_t gid;
ret = setpgrp();
if (ret == -1) {
exit(1);
}
gid = getpgrp();
if (gid < 0) {
printf("get group id failed, pgrpid %d, errno %d\n", gid, errno);
}
ret = tcsetpgrp(STDIN_FILENO, gid);
if (ret != 0) {
printf("tcsetpgrp failed, errno %d\n", errno);
}
ret = execve(cmdName, paramArray, NULL);
if (ret == -1) {
perror("execve");
exit(-1);
}
}
int CheckExit(const char *cmdName, const CmdParsed *cmdParsed)
{
int ret = 0;
if (strlen(cmdName) != CMD_EXIT_COMMAND_BYTES || strncmp(cmdName, CMD_EXIT_COMMAND, CMD_EXIT_COMMAND_BYTES) != 0) {
return 0;
}
if (cmdParsed->paramCnt > 1) {
printf("exit: too many arguments\n");
return -1;
}
if (cmdParsed->paramCnt == 1) {
char *p;
ret = strtol(cmdParsed->paramArray[0], &p, CMD_EXIT_CODE_BASE_DEC);
if (*p != '\0') {
printf("exit: bad number: %s\n", cmdParsed->paramArray[0]);
return -1;
}
}
exit(ret);
}
static void DoCmdExec(const char *cmdName, const char *cmdline, unsigned int len, const CmdParsed *cmdParsed)
{
int ret;
pid_t forkPid;
pid_t gid;
if (strncmp(cmdline, SHELL_EXEC_COMMAND, SHELL_EXEC_COMMAND_BYTES) == 0) {
if (strncmp(cmdline, CMD_EXEC_COMMAND, CMD_EXEC_COMMAND_BYTES) == 0) {
forkPid = fork();
if (forkPid < 0) {
printf("Faild to fork from shell\n");
return;
} else if (forkPid == 0) {
ret = setpgrp();
if (ret == -1) {
exit(1);
}
gid = getpgrp();
if (gid < 0) {
printf("get group id failed, pgrpid %d, errno %d\n", gid, errno);
}
ret = tcsetpgrp(STDIN_FILENO, gid);
ChildExec(cmdParsed->paramArray[0], cmdParsed->paramArray);
} else {
waitpid(forkPid, 0, 0);
ret = tcsetpgrp(STDIN_FILENO, getpid());
if (ret != 0) {
printf("tcsetpgrp failed, errno %d\n", errno);
}
ret = execve((const char *)cmdParsed->paramArray[0], (char * const *)cmdParsed->paramArray, NULL);
if (ret == -1) {
perror("execve");
exit(-1);
}
}
} else {
if (CheckExit(cmdName, cmdParsed) < 0) {
return;
}
(void)syscall(__NR_shellexec, cmdName, cmdline);
}
}
@ -417,7 +479,7 @@ unsigned int PreHandleCmdline(const char *input, char **output, unsigned int *ou
unsigned int removeLen = strlen("./"); /* "./" needs to be removed if it exists */
unsigned int ret;
char *newCmd = NULL;
char *execCmd = SHELL_EXEC_COMMAND;
char *execCmd = CMD_EXEC_COMMAND;
const char *cmdBuf = input;
unsigned int cmdBufLen = strlen(cmdBuf);
char *shiftStr = (char *)malloc(cmdBufLen + 1);
@ -520,7 +582,11 @@ static void ShellCmdProcess(ShellCB *shellCB)
if (buf == NULL) {
break;
}
if (buf[0] == CHAR_CTRL_C) {
printf("^C");
buf[0] = '\n';
}
printf("\n");
ExecCmdline(buf);
ShellSaveHistoryCmd(buf, shellCB);
shellCB->cmdMaskKeyLink = shellCB->cmdHistoryKeyLink;

View File

@ -790,7 +790,7 @@ STATUS_T LOS_ArchMmuDestroy(LosArchMmu *archMmu)
LOS_PhysPageFree(page);
}
OsArmWriteTlbiasid(archMmu->asid);
OsArmWriteTlbiasidis(archMmu->asid);
OsFreeAsid(archMmu->asid);
#endif
(VOID)LOS_MuxDestroy(&archMmu->mtx);

View File

@ -228,7 +228,8 @@ UINT32 OsArmSharedPageFault(UINT32 excType, ExcContext *frame, UINT32 far, UINT3
break;
}
default:
ret = LOS_ERRNO_VM_NOT_FOUND;
OsArmWriteTlbimvaais(ROUNDDOWN(far, PAGE_SIZE));
ret = LOS_OK;
break;
}
#if defined(LOSCFG_KERNEL_SMP) && defined(LOSCFG_DEBUG_VERSION)
@ -276,8 +277,8 @@ STATIC const CHAR *g_excTypeString[] = {
#ifdef LOSCFG_KERNEL_VM
STATIC VADDR_T OsGetTextRegionBase(LosVmMapRegion *region, LosProcessCB *runProcess)
{
struct file *curFilep = NULL;
struct file *lastFilep = NULL;
struct Vnode *curVnode = NULL;
struct Vnode *lastVnode = NULL;
LosVmMapRegion *curRegion = NULL;
LosVmMapRegion *lastRegion = NULL;
@ -296,9 +297,9 @@ STATIC VADDR_T OsGetTextRegionBase(LosVmMapRegion *region, LosProcessCB *runProc
if ((lastRegion == NULL) || !LOS_IsRegionFileValid(lastRegion)) {
goto DONE;
}
curFilep = curRegion->unTypeData.rf.file;
lastFilep = lastRegion->unTypeData.rf.file;
} while (!strcmp(curFilep->f_path, lastFilep->f_path));
curVnode = curRegion->unTypeData.rf.vnode;
lastVnode = lastRegion->unTypeData.rf.vnode;
} while (curVnode == lastVnode);
DONE:
#ifdef LOSCFG_KERNEL_DYNLOAD
@ -454,7 +455,7 @@ STATIC VOID OsDumpExcVaddrRegion(LosVmSpace *space, LosVmMapRegion *region)
mmuFlag = FALSE;
}
PrintExcInfo(" 0x%08x 0x%08x 0x%08x\n",
startVaddr, LOS_PaddrToKVaddr(startPaddr), (UINT32)pageCount << PAGE_SHIFT);
startVaddr, (UINTPTR)LOS_PaddrToKVaddr(startPaddr), (UINT32)pageCount << PAGE_SHIFT);
pageCount = 0;
startPaddr = 0;
}
@ -515,7 +516,7 @@ VOID OsDumpContextMem(const ExcContext *excBufAddr)
for (excReg = &(excBufAddr->R0); count <= DUMPREGS; excReg++, count++) {
if (IS_VALID_ADDR(*excReg)) {
PrintExcInfo("\ndump mem around R%u:%p", count, (*excReg));
PrintExcInfo("\ndump mem around R%u:0x%x", count, (*excReg));
OsDumpMemByte(DUMPSIZE, ((*excReg) - (DUMPSIZE >> 1)));
}
}
@ -811,7 +812,7 @@ VOID OsCallStackInfo(VOID)
PrintExcInfo("runTask->stackPointer = 0x%x\n"
"runTask->topOfStack = 0x%x\n"
"text_start:0x%x,text_end:0x%x\n",
stackPointer, runTask->topOfStack, &__text_start, &__text_end);
(UINTPTR)stackPointer, runTask->topOfStack, &__text_start, &__text_end);
while ((stackPointer > (UINT32 *)runTask->topOfStack) && (count < OS_MAX_BACKTRACE)) {
if ((*stackPointer > (UINTPTR)(&__text_start)) &&
@ -994,10 +995,12 @@ STATIC VOID OsCheckAllCpuStatus(VOID)
g_currHandleExcCpuID = currCpuID;
g_currHandleExcPID = OsCurrProcessGet()->processID;
LOS_SpinUnlock(&g_excSerializerSpin);
#ifndef LOSCFG_SAVE_EXCINFO
if (g_excFromUserMode[currCpuID] == FALSE) {
target = (UINT32)(OS_MP_CPU_ALL & ~CPUID_TO_AFFI_MASK(currCpuID));
HalIrqSendIpi(target, LOS_MP_IPI_HALT);
}
#endif
} else if (g_excFromUserMode[currCpuID] == TRUE) {
/* Both cores raise exceptions, and the current core is a user-mode exception.
* Both cores are abnormal and come from the same process
@ -1022,11 +1025,12 @@ STATIC VOID OsCheckAllCpuStatus(VOID)
while (1) {}
}
}
#ifndef LOSCFG_SAVE_EXCINFO
/* use halt ipi to stop other active cores */
if (g_excFromUserMode[ArchCurrCpuid()] == FALSE) {
WaitAllCpuStop(currCpuID);
}
#endif
}
#endif

View File

@ -46,7 +46,7 @@ INT32 LOS_StrncpyFromUser(CHAR *dst, const CHAR *src, INT32 count)
}
maxCount = (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, (size_t)count)) ? \
count : (USER_ASPACE_TOP_MAX - (UINTPTR)src);
count : (INT32)(USER_ASPACE_TOP_MAX - (UINTPTR)src);
for (i = 0; i < maxCount; ++i) {
if (LOS_GetUser(&character, src + offset) != LOS_OK) {

59
bundle.json Normal file
View File

@ -0,0 +1,59 @@
{
"name": "@ohos/kernel_liteos_a",
"version": "",
"description": "liteos-a内核",
"homePage": "https://gitee.com/openharmony",
"license": "BSD 3-clause",
"repository": "https://gitee.com/openharmony/kernel_liteos_a",
"domain": "os",
"language": "",
"publishAs": "code-segment",
"private": false,
"scripts": {},
"tags": [
"kernel"
],
"keywords": [
"kernel",
"liteos-a"
],
"envs": [],
"dirs": [],
"author": {
"name": "",
"email": "",
"url": ""
},
"contributors": [
{
"name": "",
"email": "",
"url": ""
}
],
"segment": {
"destPath": "kernel/liteos_a"
},
"component": {
"name": "liteos-a",
"subsystem": "liteos_a",
"syscap": [
"SystemCapability.Kernel.liteos-a"
],
"features": [],
"adated_system_type": [
"small"
],
"rom": "",
"ram": "",
"deps": {
"components": [],
"third_party": []
},
"build": {
"sub_component": [],
"inner_kits": [],
"test": []
}
}
}

View File

@ -231,7 +231,7 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
SetPthreadAttr(self, attr, &userAttr);
(VOID)snprintf_s(name, sizeof(name), sizeof(name) - 1, "pth%02d", pthreadNumber);
(VOID)snprintf_s(name, sizeof(name), sizeof(name) - 1, "pth%02u", pthreadNumber);
pthreadNumber++;
taskInitParam.pcName = name;

View File

@ -165,6 +165,10 @@ extern "C" {
#define DISK_ATA_GET_MODEL 21 /* Get model name */
#define DISK_ATA_GET_SN 22 /* Get serial number */
#ifdef LOSCFG_FS_FAT_CACHE
#define DISK_DIRECT_BUFFER_SIZE 4 /* los_disk direct io buffer when bcache is off */
#endif
typedef enum _disk_status_ {
STAT_UNUSED,
STAT_INUSED,
@ -187,6 +191,9 @@ typedef struct _los_disk_ {
CHAR *disk_name;
LOS_DL_LIST head; /* link head of all the partitions */
struct pthread_mutex disk_mutex;
#ifndef LOSCFG_FS_FAT_CACHE
UINT8 *buff;
#endif
} los_disk;
typedef struct _los_part_ {

View File

@ -36,6 +36,10 @@
#include "sys/mount.h"
#include "linux/spinlock.h"
#include "path_cache.h"
#ifndef LOSCFG_FS_FAT_CACHE
#include "los_vm_common.h"
#include "user_copy.h"
#endif
los_disk g_sysDisk[SYS_MAX_DISK];
los_part g_sysPart[SYS_MAX_PART];
@ -799,6 +803,78 @@ INT32 DiskPartitionRegister(los_disk *disk)
return ENOERR;
}
#ifndef LOSCFG_FS_FAT_CACHE
static INT32 disk_read_directly(los_disk *disk, VOID *buf, UINT64 sector, UINT32 count)
{
INT32 result = VFS_ERROR;
struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops;
if ((bops == NULL) || (bops->read == NULL)) {
return VFS_ERROR;
}
if (LOS_IsUserAddressRange((VADDR_T)buf, count * disk->sector_size)) {
UINT32 cnt = 0;
UINT8 *buffer = disk->buff;
for (; count != 0; count -= cnt) {
cnt = (count > DISK_DIRECT_BUFFER_SIZE) ? DISK_DIRECT_BUFFER_SIZE : count;
result = bops->read(disk->dev, buffer, sector, cnt);
if (result == (INT32)cnt) {
result = ENOERR;
} else {
break;
}
if (LOS_CopyFromKernel(buf, disk->sector_size * cnt, buffer, disk->sector_size * cnt)) {
result = VFS_ERROR;
break;
}
buf = (UINT8 *)buf + disk->sector_size * cnt;
sector += cnt;
}
} else {
result = bops->read(disk->dev, buf, sector, count);
if (result == count) {
result = ENOERR;
}
}
return result;
}
static INT32 disk_write_directly(los_disk *disk, const VOID *buf, UINT64 sector, UINT32 count)
{
struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops;
INT32 result = VFS_ERROR;
if ((bops == NULL) || (bops->read == NULL)) {
return VFS_ERROR;
}
if (LOS_IsUserAddressRange((VADDR_T)buf, count * disk->sector_size)) {
UINT32 cnt = 0;
UINT8 *buffer = disk->buff;
for (; count != 0; count -= cnt) {
cnt = (count > DISK_DIRECT_BUFFER_SIZE) ? DISK_DIRECT_BUFFER_SIZE : count;
if (LOS_CopyToKernel(buffer, disk->sector_size * cnt, buf, disk->sector_size * cnt)) {
result = VFS_ERROR;
break;
}
result = bops->write(disk->dev, buffer, sector, cnt);
if (result == (INT32)cnt) {
result = ENOERR;
} else {
break;
}
buf = (UINT8 *)buf + disk->sector_size * cnt;
sector += cnt;
}
} else {
result = bops->write(disk->dev, buf, sector, count);
if (result == count) {
result = ENOERR;
}
}
return result;
}
#endif
INT32 los_disk_read(INT32 drvID, VOID *buf, UINT64 sector, UINT32 count, BOOL useRead)
{
#ifdef LOSCFG_FS_FAT_CACHE
@ -837,21 +913,14 @@ INT32 los_disk_read(INT32 drvID, VOID *buf, UINT64 sector, UINT32 count, BOOL us
PRINT_ERR("los_disk_read read err = %d, sector = %llu, len = %u\n", result, sector, len);
}
} else {
#endif
result = VFS_ERROR;
}
#else
if (disk->dev == NULL) {
goto ERROR_HANDLE;
}
struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops;
if ((bops != NULL) && (bops->read != NULL)) {
result = bops->read(disk->dev, (UINT8 *)buf, sector, count);
if (result == (INT32)count) {
result = ENOERR;
}
}
#ifdef LOSCFG_FS_FAT_CACHE
}
result = disk_read_directly(disk, buf, sector, count);
#endif
if (result != ENOERR) {
goto ERROR_HANDLE;
}
@ -900,18 +969,14 @@ INT32 los_disk_write(INT32 drvID, const VOID *buf, UINT64 sector, UINT32 count)
PRINT_ERR("los_disk_write write err = %d, sector = %llu, len = %u\n", result, sector, len);
}
} else {
#endif
struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops;
if ((bops != NULL) && (bops->write != NULL)) {
result = bops->write(disk->dev, (UINT8 *)buf, sector, count);
if (result == (INT32)count) {
result = ENOERR;
}
result = VFS_ERROR;
}
#ifdef LOSCFG_FS_FAT_CACHE
#else
if (disk->dev == NULL) {
goto ERROR_HANDLE;
}
result = disk_write_directly(disk, buf, sector, count);
#endif
if (result != ENOERR) {
goto ERROR_HANDLE;
}
@ -1153,7 +1218,8 @@ ERROR_HANDLE:
INT32 los_disk_cache_clear(INT32 drvID)
{
INT32 result;
INT32 result = ENOERR;
#ifdef LOSCFG_FS_FAT_CACHE
los_part *part = get_part(drvID);
los_disk *disk = NULL;
@ -1161,7 +1227,7 @@ INT32 los_disk_cache_clear(INT32 drvID)
return VFS_ERROR;
}
result = OsSdSync(part->disk_id);
if (result != 0) {
if (result != ENOERR) {
PRINTK("[ERROR]disk_cache_clear SD sync failed!\n");
return result;
}
@ -1174,7 +1240,7 @@ INT32 los_disk_cache_clear(INT32 drvID)
DISK_LOCK(&disk->disk_mutex);
result = BcacheClearCache(disk->bcache);
DISK_UNLOCK(&disk->disk_mutex);
#endif
return result;
}
@ -1324,6 +1390,10 @@ static INT32 DiskDeinit(los_disk *disk)
#ifdef LOSCFG_FS_FAT_CACHE
DiskCacheDeinit(disk);
#else
if (disk->buff != NULL) {
free(disk->buff);
}
#endif
disk->dev = NULL;
@ -1344,12 +1414,15 @@ static INT32 DiskDeinit(los_disk *disk)
return ENOERR;
}
static VOID OsDiskInitSub(const CHAR *diskName, INT32 diskID, los_disk *disk,
struct geometry *diskInfo, struct Vnode *blkDriver)
static UINT32 OsDiskInitSub(const CHAR *diskName, INT32 diskID, los_disk *disk,
struct geometry *diskInfo, struct Vnode *blkDriver)
{
pthread_mutexattr_t attr;
#ifdef LOSCFG_FS_FAT_CACHE
OsBcache *bc = DiskCacheInit((UINT32)diskID, diskInfo, blkDriver);
if (bc == NULL) {
return VFS_ERROR;
}
disk->bcache = bc;
#endif
@ -1358,6 +1431,16 @@ static VOID OsDiskInitSub(const CHAR *diskName, INT32 diskID, los_disk *disk,
(VOID)pthread_mutex_init(&disk->disk_mutex, &attr);
DiskStructInit(diskName, diskID, diskInfo, blkDriver, disk);
#ifndef LOSCFG_FS_FAT_CACHE
disk->buff = malloc(diskInfo->geo_sectorsize * DISK_DIRECT_BUFFER_SIZE);
if (disk->buff == NULL) {
PRINT_ERR("OsDiskInitSub: direct buffer of disk init failed\n");
return VFS_ERROR;
}
#endif
return ENOERR;
}
INT32 los_disk_init(const CHAR *diskName, const struct block_operations *bops,
@ -1382,14 +1465,12 @@ INT32 los_disk_init(const CHAR *diskName, const struct block_operations *bops,
ret = VnodeLookup(diskName, &blkDriver, 0);
if (ret < 0) {
VnodeDrop();
PRINT_ERR("disk_init : find %s fail!\n", diskName);
ret = ENOENT;
goto DISK_FIND_ERROR;
}
struct block_operations *bops2 = (struct block_operations *)((struct drv_data *)blkDriver->data)->ops;
if ((bops2 == NULL) || (bops2->geometry == NULL) ||
(bops2->geometry(blkDriver, &diskInfo) != 0)) {
if ((bops2 == NULL) || (bops2->geometry == NULL) || (bops2->geometry(blkDriver, &diskInfo) != 0)) {
goto DISK_BLKDRIVER_ERROR;
}
@ -1397,7 +1478,12 @@ INT32 los_disk_init(const CHAR *diskName, const struct block_operations *bops,
goto DISK_BLKDRIVER_ERROR;
}
OsDiskInitSub(diskName, diskID, disk, &diskInfo, blkDriver);
ret = OsDiskInitSub(diskName, diskID, disk, &diskInfo, blkDriver);
if (ret != ENOERR) {
(VOID)DiskDeinit(disk);
VnodeDrop();
return VFS_ERROR;
}
VnodeDrop();
if (DiskDivideAndPartitionRegister(info, disk) != ENOERR) {
(VOID)DiskDeinit(disk);

View File

@ -37,10 +37,7 @@ kernel_module(module_name) {
"src/mtd_shellcmd.c",
]
include_dirs = [
"$LITEOSTOPDIR/fs/jffs2/include",
"//device/hisilicon/drivers/include/mtd/common/include",
]
include_dirs = [ "$LITEOSTOPDIR/fs/jffs2/include" ]
if (defined(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7)) {
include_dirs += [ "//device/qemu/drivers/cfiflash" ]

View File

@ -35,8 +35,8 @@ LOCAL_SRCS := $(wildcard src/*.c)
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/fs/jffs2/include \
-I $(LITEOSTOPDIR)/drivers/mtd/multi_partition/include \
-I $(LITEOSTOPDIR)/../../device/hisilicon/drivers/include/mtd/common/include
-I $(LITEOSTOPDIR)/../../drivers/framework/model/storage/include \
-I $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/model/storage/include
ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/../../device/qemu/drivers/cfiflash

View File

@ -37,7 +37,7 @@
#include "los_config.h"
#include "los_mux.h"
#include "fs/driver.h"
#include "mtd_common.h"
#include "mtd_legacy_lite.h"
#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
#include "cfiflash.h"

View File

@ -47,6 +47,7 @@
#include "user_copy.h"
#include "los_vm_filemap.h"
#include "los_hash.h"
#include "los_vm_common.h"
#include <time.h>
#include <errno.h>
#include <dirent.h>
@ -1848,6 +1849,7 @@ int fatfs_mkfs (struct Vnode *device, int sectors, int option)
BYTE *work_buff = NULL;
los_part *part = NULL;
FRESULT result;
MKFS_PARM opt = {0};
int ret;
part = los_part_find(device);
@ -1872,7 +1874,9 @@ int fatfs_mkfs (struct Vnode *device, int sectors, int option)
return -ENOMEM;
}
result = _mkfs(part, sectors, option, work_buff, FF_MAX_SS);
opt.n_sect = sectors;
opt.fmt = (BYTE)option;
result = _mkfs(part, &opt, work_buff, FF_MAX_SS);
free(work_buff);
if (result != FR_OK) {
return -fatfs_2_vfs(result);
@ -2032,45 +2036,18 @@ static UINT get_oldest_time(DIR_FILE df[], DWORD *oldest_time, UINT len)
return index;
}
int fatfs_fscheck(struct Vnode* vp, struct fs_dirent_s *dir)
static FRESULT fscheck(DIR *dp)
{
FATFS *fs = (FATFS *)vp->originMount->data;
DIR_FILE df[CHECK_FILE_NUM] = {0};
DIR *dp = NULL;
FILINFO *finfo = &(((DIR_FILE *)(vp->data))->fno);
FILINFO fno;
DWORD old_time = -1;
DWORD time;
UINT count;
UINT index = 0;
los_part *part = NULL;
UINT count;
DWORD time;
DWORD old_time = -1;
FRESULT result;
int ret;
if (fs->fs_type != FS_FAT32) {
return -EINVAL;
}
if ((finfo->fattrib & AM_DIR) == 0) {
return -ENOTDIR;
}
ret = fatfs_opendir(vp, dir);
if (ret < 0) {
return ret;
}
ret = lock_fs(fs);
if (ret == FALSE) {
result = FR_TIMEOUT;
goto ERROR_WITH_DIR;
}
dp = (DIR *)dir->u.fs_dir;
dp->obj.id = fs->id;
for (count = 0; count < CHECK_FILE_NUM; count++) {
if ((result = f_readdir(dp, &fno)) != FR_OK) {
goto ERROR_UNLOCK;
return result;
} else {
if (fno.fname[0] == 0 || fno.fname[0] == (TCHAR)0xFF) {
break;
@ -2095,15 +2072,50 @@ int fatfs_fscheck(struct Vnode* vp, struct fs_dirent_s *dir)
index = get_oldest_time(df, &old_time, CHECK_FILE_NUM);
}
}
if (result != FR_OK) {
goto ERROR_UNLOCK;
index = 0;
while (result == FR_OK && index < count) {
result = f_fcheckfat(&df[index]);
++index;
}
for (index = 0; index < count; index++) {
result = f_fcheckfat(&df[index]);
if (result != FR_OK) {
goto ERROR_UNLOCK;
}
return result;
}
int fatfs_fscheck(struct Vnode* vp, struct fs_dirent_s *dir)
{
FATFS *fs = (FATFS *)vp->originMount->data;
DIR *dp = NULL;
FILINFO *finfo = &(((DIR_FILE *)(vp->data))->fno);
#ifdef LOSCFG_FS_FAT_CACHE
los_part *part = NULL;
#endif
FRESULT result;
int ret;
if (fs->fs_type != FS_FAT32) {
return -EINVAL;
}
if ((finfo->fattrib & AM_DIR) == 0) {
return -ENOTDIR;
}
ret = fatfs_opendir(vp, dir);
if (ret < 0) {
return ret;
}
ret = lock_fs(fs);
if (ret == FALSE) {
result = FR_TIMEOUT;
goto ERROR_WITH_DIR;
}
dp = (DIR *)dir->u.fs_dir;
dp->obj.id = fs->id;
result = fscheck(dp);
if (result != FR_OK) {
goto ERROR_UNLOCK;
}
unlock_fs(fs, FR_OK);
@ -2180,6 +2192,207 @@ ERROUT:
return -fatfs_2_vfs(res);
}
ssize_t fatfs_readpage(struct Vnode *vnode, char *buff, off_t pos)
{
FATFS *fs = (FATFS *)(vnode->originMount->data);
DIR_FILE *dfp = (DIR_FILE *)(vnode->data);
FILINFO *finfo = &(dfp->fno);
FAT_ENTRY *ep = &(dfp->fat_entry);
DWORD clust;
DWORD sclust;
QWORD sect;
QWORD step;
QWORD n;
size_t position; /* byte offset */
BYTE *buf = (BYTE *)buff;
size_t buflen = PAGE_SIZE;
FRESULT result;
int ret;
ret = lock_fs(fs);
if (ret == FALSE) {
result = FR_TIMEOUT;
goto ERROR_OUT;
}
if (finfo->fsize <= pos) {
result = FR_OK;
goto ERROR_UNLOCK;
}
if (ep->clst == 0) {
ep->clst = finfo->sclst;
}
if (pos >= ep->pos) {
clust = ep->clst;
position = ep->pos;
} else {
clust = finfo->sclst;
position = 0;
}
/* Get to the current cluster */
n = pos / SS(fs) / fs->csize - position / SS(fs) / fs->csize;
while (n--) {
clust = get_fat(&(dfp->f_dir.obj), clust);
if ((clust == BAD_CLUSTER) || (clust == DISK_ERROR)) {
result = FR_DISK_ERR;
goto ERROR_UNLOCK;
}
}
/* Get to the currnet sector */
sect = clst2sect(fs, clust);
sect += (pos / SS(fs)) & (fs->csize - 1);
/* How many sectors do we need to read once */
if (fs->csize < buflen / SS(fs)) {
step = fs->csize;
} else {
step = buflen / SS(fs);
}
n = 0;
sclust = clust;
while (n < buflen / SS(fs)) {
if (disk_read(fs->pdrv, buf, sect, step) != RES_OK) {
result = FR_DISK_ERR;
goto ERROR_UNLOCK;
}
n += step;
if (n >= buflen / SS(fs)) {
break;
}
/* As cluster size is aligned, it must jump to next cluster when cluster size is less than pagesize */
clust = get_fat(&(dfp->f_dir.obj), clust);
if ((clust == BAD_CLUSTER) || (clust == DISK_ERROR)) {
result = FR_DISK_ERR;
goto ERROR_UNLOCK;
} else if (fatfs_is_last_cluster(fs, clust)) {
break; /* read end */
}
sect = clst2sect(fs, clust);
buf += step * SS(fs);
}
ep->clst = sclust;
ep->pos = pos;
unlock_fs(fs, FR_OK);
return (ssize_t)min(finfo->fsize - pos, n * SS(fs));
ERROR_UNLOCK:
unlock_fs(fs, result);
ERROR_OUT:
return -fatfs_2_vfs(result);
}
ssize_t fatfs_writepage(struct Vnode *vnode, char *buff, off_t pos, size_t buflen)
{
FATFS *fs = (FATFS *)(vnode->originMount->data);
DIR_FILE *dfp = (DIR_FILE *)(vnode->data);
FILINFO *finfo = &(dfp->fno);
FAT_ENTRY *ep = &(dfp->fat_entry);
DWORD clust;
DWORD sclst;
QWORD sect;
QWORD step;
QWORD n;
size_t position; /* byte offset */
BYTE *buf = (BYTE *)buff;
FRESULT result;
FIL fil;
int ret;
ret = lock_fs(fs);
if (ret == FALSE) {
result = FR_TIMEOUT;
goto ERROR_OUT;
}
if (finfo->fsize <= pos) {
result = FR_OK;
goto ERROR_UNLOCK;
}
if (ep->clst == 0) {
ep->clst = finfo->sclst;
}
if (pos >= ep->pos) {
clust = ep->clst;
position = ep->pos;
} else {
clust = finfo->sclst;
position = 0;
}
/* Get to the current cluster */
n = pos / SS(fs) / fs->csize - position / SS(fs) / fs->csize;
while (n--) {
clust = get_fat(&(dfp->f_dir.obj), clust);
if ((clust == BAD_CLUSTER) || (clust == DISK_ERROR)) {
result = FR_DISK_ERR;
goto ERROR_UNLOCK;
}
}
/* Get to the currnet sector */
sect = clst2sect(fs, clust);
sect += (pos / SS(fs)) & (fs->csize - 1);
/* How many sectors do we need to read once */
if (fs->csize < buflen / SS(fs)) {
step = fs->csize;
} else {
step = buflen / SS(fs);
}
n = 0;
sclst = clust;
while (n < buflen / SS(fs)) {
if (disk_write(fs->pdrv, buf, sect, step) != RES_OK) {
result = FR_DISK_ERR;
goto ERROR_UNLOCK;
}
n += step;
if (n >= buflen / SS(fs)) {
break;
}
/* As cluster size is aligned, it must jump to next cluster when cluster size is less than pagesize */
clust = get_fat(&(dfp->f_dir.obj), clust);
if ((clust == BAD_CLUSTER) || (clust == DISK_ERROR)) {
result = FR_DISK_ERR;
goto ERROR_UNLOCK;
} else if (fatfs_is_last_cluster(fs, clust)) {
break; /* read end */
}
sect = clst2sect(fs, clust);
buf += step * SS(fs);
}
ep->clst = sclst;
ep->pos = pos;
fil.obj.fs = fs;
if (update_filbuff(finfo, &fil, NULL) < 0) {
result = FR_DISK_ERR;
goto ERROR_UNLOCK;
}
unlock_fs(fs, FR_OK);
return (ssize_t)min(finfo->fsize - pos, n * SS(fs));
ERROR_UNLOCK:
unlock_fs(fs, result);
ERROR_OUT:
return -fatfs_2_vfs(result);
}
struct VnodeOps fatfs_vops = {
/* file ops */
.Getattr = fatfs_stat,
@ -2187,6 +2400,8 @@ struct VnodeOps fatfs_vops = {
.Lookup = fatfs_lookup,
.Rename = fatfs_rename,
.Create = fatfs_create,
.ReadPage = fatfs_readpage,
.WritePage = fatfs_writepage,
.Unlink = fatfs_unlink,
.Reclaim = fatfs_reclaim,
.Truncate = fatfs_truncate,

View File

@ -146,7 +146,7 @@ int fatfs_fscheck(struct Vnode* vnode, struct fs_dirent_s *dir);
FRESULT find_fat_partition(FATFS *fs, los_part *part, BYTE *format, QWORD *start_sector);
FRESULT init_fatobj(FATFS *fs, BYTE fmt, QWORD start_sector);
FRESULT _mkfs(los_part *partition, int sector, int opt, BYTE *work, UINT len);
FRESULT _mkfs(los_part *partition, const MKFS_PARM *opt, BYTE *work, UINT len);
#ifdef __cplusplus
#if __cplusplus

View File

@ -525,7 +525,7 @@ FRESULT f_checkvirpart(FATFS *fs, const TCHAR *path, BYTE vol)
}
/* Lock the filesystem object */
res = find_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */
res = mount_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */
if (res != FR_OK) {
LEAVE_FF(fs, res);
}
@ -683,7 +683,7 @@ FRESULT f_makevirpart(FATFS *fs, const TCHAR *path, BYTE vol)
}
/* Lock the filesystem object */
res = find_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */
res = mount_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */
if (res != FR_OK) {
LEAVE_FF(fs, res);
}
@ -774,7 +774,7 @@ FRESULT f_getvirfree(const TCHAR *path, DWORD *nclst, DWORD *cclst)
DIR dj;
/* Find volume to Update the global FSINFO */
res = find_volume(&path, &fs, 0);
res = mount_volume(&path, &fs, 0);
if (res != FR_OK) {
LEAVE_FF(fs, res);
}

View File

@ -41,81 +41,6 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/* vfs/fs_file_mapping.c ****************************************************/
/****************************************************************************
* Name: init_file_mapping
*
* Description:
* Init the global management structure of path <-> page_mapping
*
****************************************************************************/
extern UINT32 init_file_mapping(void);
/****************************************************************************
* Name: add_mapping
*
* Description:
* Create a new path <-> page_mapping mapping and add to global list.
*
****************************************************************************/
extern void add_mapping(struct file *filep, const char *fullpath);
/****************************************************************************
* Name: find_mapping
*
* Description:
* Find the page_mapping for path in global list.
*
****************************************************************************/
extern struct page_mapping *find_mapping(const char *path);
/****************************************************************************
* Name: remove_mapping
*
* Description:
* Drop all the page-caches for the file, and then remove mapping between
* the file and pagecache.
* ex_filp NULL: do not exclude any file, just matching the fullpath;
* ex_filp not NULL: exclude it, which means, ex_filp can be open.
*
****************************************************************************/
extern int remove_mapping(const char *fullpath);
/****************************************************************************
* Name: rename_mapping
*
* Description:
* Rename the mapping from global path <-> page_mapping list.
*
****************************************************************************/
extern void rename_mapping(const char *src, const char *dst);
/****************************************************************************
* Name: dec_mapping
*
* Description:
* Decrease the refcnt of mapping.
*
****************************************************************************/
extern void dec_mapping_nolock(struct page_mapping *mapping);
/****************************************************************************
* Name: update_file_path
*
* Description:
* Update the path in file descriptors when do renaming.
*
****************************************************************************/
extern int update_file_path(const char *old_path, const char *new_path);
/**
* @ingroup fs
* @brief Initializes the vfs filesystem

View File

@ -201,13 +201,13 @@ int VfsJffs2Lookup(struct Vnode *parentVnode, const char *path, int len, struct
}
(void)VfsHashGet(parentVnode->originMount, node->i_ino, &newVnode, NULL, NULL);
LOS_MuxUnlock(&g_jffs2FsLock);
if (newVnode) {
if (newVnode->data == NULL) {
LOS_Panic("#####VfsHashGet error#####\n");
}
newVnode->parent = parentVnode;
*ppVnode = newVnode;
LOS_MuxUnlock(&g_jffs2FsLock);
return 0;
}
ret = VnodeAlloc(&g_jffs2Vops, &newVnode);
@ -276,7 +276,7 @@ int VfsJffs2Close(struct file *filep)
return 0;
}
ssize_t VfsJffs2Read(struct file *filep, char *buffer, size_t bufLen)
ssize_t VfsJffs2ReadPage(struct Vnode *vnode, char *buffer, off_t off)
{
struct jffs2_inode *node = NULL;
struct jffs2_inode_info *f = NULL;
@ -285,6 +285,32 @@ ssize_t VfsJffs2Read(struct file *filep, char *buffer, size_t bufLen)
LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER);
node = (struct jffs2_inode *)vnode->data;
f = JFFS2_INODE_INFO(node);
c = JFFS2_SB_INFO(node->i_sb);
off_t pos = min(node->i_size, off);
ssize_t len = min(PAGE_SIZE, (node->i_size - pos));
ret = jffs2_read_inode_range(c, f, (unsigned char *)buffer, off, len);
if (ret) {
LOS_MuxUnlock(&g_jffs2FsLock);
return ret;
}
node->i_atime = Jffs2CurSec();
LOS_MuxUnlock(&g_jffs2FsLock);
return len;
}
ssize_t VfsJffs2Read(struct file *filep, char *buffer, size_t bufLen)
{
struct jffs2_inode *node = NULL;
struct jffs2_inode_info *f = NULL;
struct jffs2_sb_info *c = NULL;
int ret;
LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER);
node = (struct jffs2_inode *)filep->f_vnode->data;
f = JFFS2_INODE_INFO(node);
c = JFFS2_SB_INFO(node->i_sb);
@ -293,7 +319,6 @@ ssize_t VfsJffs2Read(struct file *filep, char *buffer, size_t bufLen)
off_t len = min(bufLen, (node->i_size - pos));
ret = jffs2_read_inode_range(c, f, (unsigned char *)buffer, filep->f_pos, len);
if (ret) {
PRINTK("VfsJffs2Read(): read_inode_range failed %d\n", ret);
LOS_MuxUnlock(&g_jffs2FsLock);
return ret;
}
@ -305,6 +330,59 @@ ssize_t VfsJffs2Read(struct file *filep, char *buffer, size_t bufLen)
return len;
}
ssize_t VfsJffs2WritePage(struct Vnode *vnode, char *buffer, off_t pos, size_t buflen)
{
struct jffs2_inode *node = NULL;
struct jffs2_inode_info *f = NULL;
struct jffs2_sb_info *c = NULL;
struct jffs2_raw_inode ri = {0};
struct IATTR attr = {0};
int ret;
uint32_t writtenLen;
LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER);
node = (struct jffs2_inode *)vnode->data;
f = JFFS2_INODE_INFO(node);
c = JFFS2_SB_INFO(node->i_sb);
if (pos < 0) {
LOS_MuxUnlock(&g_jffs2FsLock);
return -EINVAL;
}
ri.ino = cpu_to_je32(f->inocache->ino);
ri.mode = cpu_to_jemode(node->i_mode);
ri.uid = cpu_to_je16(node->i_uid);
ri.gid = cpu_to_je16(node->i_gid);
ri.atime = ri.ctime = ri.mtime = cpu_to_je32(Jffs2CurSec());
if (pos > node->i_size) {
int err;
attr.attr_chg_valid = CHG_SIZE;
attr.attr_chg_size = pos;
err = jffs2_setattr(node, &attr);
if (err) {
LOS_MuxUnlock(&g_jffs2FsLock);
return err;
}
}
ri.isize = cpu_to_je32(node->i_size);
ret = jffs2_write_inode_range(c, f, &ri, (unsigned char *)buffer, pos, buflen, &writtenLen);
if (ret) {
node->i_mtime = node->i_ctime = je32_to_cpu(ri.mtime);
LOS_MuxUnlock(&g_jffs2FsLock);
return ret;
}
node->i_mtime = node->i_ctime = je32_to_cpu(ri.mtime);
LOS_MuxUnlock(&g_jffs2FsLock);
return (ssize_t)writtenLen;
}
ssize_t VfsJffs2Write(struct file *filep, const char *buffer, size_t bufLen)
{
struct jffs2_inode *node = NULL;
@ -878,6 +956,8 @@ const struct MountOps jffs_operations = {
struct VnodeOps g_jffs2Vops = {
.Lookup = VfsJffs2Lookup,
.Create = VfsJffs2Create,
.ReadPage = VfsJffs2ReadPage,
.WritePage = VfsJffs2WritePage,
.Rename = VfsJffs2Rename,
.Mkdir = VfsJffs2Mkdir,
.Getattr = VfsJffs2Stat,

View File

@ -53,6 +53,9 @@ extern "C" {
typedef unsigned short fmode_t;
#define PROC_ERROR (-1)
/* Default file mode for procfs */
#define PROCFS_DEFAULT_MODE 0550
/* 64bit hashes as llseek() offset (for directories) */
#define FMODE_64BITHASH ((fmode_t)0x400)
/* 32bit hashes as llseek() offset (for directories) */

View File

@ -75,7 +75,7 @@ static void FillFdInfo(struct SeqBuf *seqBuf, struct filelist *fileList, unsigne
}
if (hasPrivilege) {
(void)LosBufPrintf(seqBuf, "%u\t%d\t%6d <%d>\t%s\n", pid, fd, sysFd, filp ? filp->f_refcount : 1, name);
(void)LosBufPrintf(seqBuf, "%u\t%d\t%6d <%lu>\t%s\n", pid, fd, sysFd, filp ? filp->f_refcount : 1, name);
} else {
(void)LosBufPrintf(seqBuf, "%u\t%d\t%s\n", pid, fd, name);
}

View File

@ -71,9 +71,9 @@ static int VnodeListProcess(struct SeqBuf *buf, LIST_HEAD* list)
struct Vnode *nextItem = NULL;
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, list, struct Vnode, actFreeEntry) {
LosBufPrintf(buf, "%-10p %-10p %-10p %10p 0x%08x %-3d %-4s %-3d %-3d %o\n",
LosBufPrintf(buf, "%-10p %-10p %-10p %10p 0x%08x %-3d %-4s %-3d %-3d %-8o\t%s\n",
item, item->parent, item->data, item->vop, item->hash, item->useCount,
VnodeTypeToStr(item->type), item->gid, item->uid, item->mode);
VnodeTypeToStr(item->type), item->gid, item->uid, item->mode, item->filePath);
count++;
}
@ -104,7 +104,7 @@ static int PageCacheEntryProcess(struct SeqBuf *buf, struct page_mapping *mappin
int total = 0;
LosFilePage *fpage = NULL;
if (mapping == NULL) {
if (mapping->nrpages == 0) {
LosBufPrintf(buf, "null]\n");
return total;
}
@ -119,18 +119,18 @@ static int PageCacheEntryProcess(struct SeqBuf *buf, struct page_mapping *mappin
static int PageCacheMapProcess(struct SeqBuf *buf)
{
struct file_map *mapList = GetFileMappingList();
char *name = NULL;
struct file_map *curMap = NULL;
LIST_HEAD *vnodeList = GetVnodeActiveList();
struct page_mapping *mapping = NULL;
struct Vnode *vnode = NULL;
int total = 0;
(VOID)LOS_MuxLock(&mapList->lock, LOS_WAIT_FOREVER);
LOS_DL_LIST_FOR_EACH_ENTRY(curMap, &mapList->head, struct file_map, head) {
name = curMap->rename ? curMap->rename: curMap->owner;
LosBufPrintf(buf, "%s:[", name);
total += PageCacheEntryProcess(buf, &curMap->mapping);
VnodeHold();
LOS_DL_LIST_FOR_EACH_ENTRY(vnode, vnodeList, struct Vnode, actFreeEntry) {
mapping = &vnode->mapping;
LosBufPrintf(buf, "%p, %s:[", vnode, vnode->filePath);
total += PageCacheEntryProcess(buf, mapping);
}
(VOID)LOS_MuxUnlock(&mapList->lock);
VnodeDrop();
return total;
}

View File

@ -45,7 +45,7 @@ void ProcFsInit(void)
{
int ret;
ret = mkdir(PROCFS_MOUNT_POINT, 0);
ret = mkdir(PROCFS_MOUNT_POINT, PROCFS_DEFAULT_MODE);
if (ret < 0) {
PRINT_ERR("failed to mkdir %s, errno = %d\n", PROCFS_MOUNT_POINT, get_errno());
return;

View File

@ -41,8 +41,6 @@
#include "los_tables.h"
#include "internal.h"
#define PROCFS_DEFAULT_MODE 0555
#ifdef LOSCFG_FS_PROC
static struct VnodeOps g_procfsVops;
static struct file_operations_vfs g_procfsFops;

View File

@ -49,7 +49,7 @@ static struct ProcFile g_procPf = {
static struct ProcDirEntry g_procRootDirEntry = {
.nameLen = 5,
.mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH,
.mode = S_IFDIR | PROCFS_DEFAULT_MODE,
.count = ATOMIC_INIT(1),
.procFileOps = NULL,
.parent = &g_procRootDirEntry,

View File

@ -40,7 +40,6 @@ kernel_module(module_name) {
"operation/vfs_fallocate.c",
"operation/vfs_fallocate64.c",
"operation/vfs_fcntl.c",
"operation/vfs_file_mapping.c",
"operation/vfs_force_umount.c",
"operation/vfs_init.c",
"operation/vfs_other.c",

View File

@ -125,12 +125,16 @@ struct Vnode {
LIST_ENTRY actFreeEntry; /* vnode active/free list entry */
struct Mount *originMount; /* fs info about this vnode */
struct Mount *newMount; /* fs info about who mount on this vnode */
char *filePath; /* file path of the vnode */
struct page_mapping mapping; /* page mapping of the vnode */
};
struct VnodeOps {
int (*Create)(struct Vnode *parent, const char *name, int mode, struct Vnode **vnode);
int (*Lookup)(struct Vnode *parent, const char *name, int len, struct Vnode **vnode);
int (*Open)(struct Vnode *vnode, int fd, int mode, int flags);
ssize_t (*ReadPage)(struct Vnode *vnode, char *buffer, off_t pos);
ssize_t (*WritePage)(struct Vnode *vnode, char *buffer, off_t pos, size_t buflen);
int (*Close)(struct Vnode *vnode);
int (*Reclaim)(struct Vnode *vnode);
int (*Unlink)(struct Vnode *parent, struct Vnode *vnode, const char *fileName);

View File

@ -134,7 +134,7 @@ int fallocate64(int fd, int mode, off64_t offset, off64_t len)
return VFS_ERROR;
}
if (filep->f_oflags & O_DIRECTORY)
if ((unsigned int)filep->f_oflags & O_DIRECTORY)
{
set_errno(EBADF);
return VFS_ERROR;

View File

@ -1,303 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "fs/file.h"
#include "fs/file.h"
#include "fs/fs_operation.h"
#include "unistd.h"
#include "los_mux.h"
#include "los_list.h"
#include "los_atomic.h"
#include "los_vm_filemap.h"
#ifdef LOSCFG_KERNEL_VM
static struct file_map g_file_mapping = {0};
uint init_file_mapping()
{
uint ret;
LOS_ListInit(&g_file_mapping.head);
ret = LOS_MuxInit(&g_file_mapping.lock, NULL);
if (ret != LOS_OK) {
PRINT_ERR("Create mutex for file map of page cache failed, (ret=%u)\n", ret);
}
return ret;
}
static void clear_file_mapping(const struct page_mapping *mapping)
{
unsigned int i = 3; /* file start fd */
struct file *filp = NULL;
while (i < CONFIG_NFILE_DESCRIPTORS) {
filp = &tg_filelist.fl_files[i];
if (filp->f_mapping == mapping) {
filp->f_mapping = NULL;
}
i++;
}
}
static struct page_mapping *find_mapping_nolock(const char *fullpath)
{
char *map_name = NULL;
struct file_map *fmap = NULL;
int name_len = strlen(fullpath);
LOS_DL_LIST_FOR_EACH_ENTRY(fmap, &g_file_mapping.head, struct file_map, head) {
map_name = fmap->rename ? fmap->rename: fmap->owner;
if ((name_len == fmap->name_len) && !strcmp(map_name, fullpath)) {
return &fmap->mapping;
}
}
return NULL;
}
void add_mapping(struct file *filep, const char *fullpath)
{
int path_len;
status_t retval;
struct file_map *fmap = NULL;
struct page_mapping *mapping = NULL;
if (filep == NULL || fullpath == NULL) {
return;
}
(VOID)LOS_MuxLock(&g_file_mapping.lock, LOS_WAIT_FOREVER);
mapping = find_mapping_nolock(fullpath);
if (mapping) {
LOS_AtomicInc(&mapping->ref);
filep->f_mapping = mapping;
mapping->host = filep;
goto out;
}
path_len = strlen(fullpath);
fmap = (struct file_map *)zalloc(sizeof(struct file_map) + path_len + 1);
if (!fmap) {
PRINT_WARN("%s %d, Mem alloc failed.\n", __FUNCTION__, __LINE__);
goto out;
}
LOS_AtomicSet(&fmap->mapping.ref, 1);
fmap->name_len = path_len;
(void)strcpy_s(fmap->owner, path_len + 1, fullpath);
LOS_ListInit(&fmap->mapping.page_list);
LOS_SpinInit(&fmap->mapping.list_lock);
retval = LOS_MuxInit(&fmap->mapping.mux_lock, NULL);
if (retval != LOS_OK) {
PRINT_ERR("%s %d, Create mutex for mapping.mux_lock failed, status: %d\n", __FUNCTION__, __LINE__, retval);
goto out;
}
LOS_ListTailInsert(&g_file_mapping.head, &fmap->head);
filep->f_mapping = &fmap->mapping;
filep->f_mapping->host = filep;
out:
(VOID)LOS_MuxUnlock(&g_file_mapping.lock);
}
int remove_mapping_nolock(struct page_mapping *mapping)
{
struct file_map *fmap = NULL;
if (mapping == NULL) {
set_errno(EINVAL);
return EINVAL;
}
(VOID)LOS_MuxDestroy(&mapping->mux_lock);
clear_file_mapping(mapping);
OsFileCacheRemove(mapping);
fmap = LOS_DL_LIST_ENTRY(mapping, struct file_map, mapping);
LOS_ListDelete(&fmap->head);
if (fmap->rename) {
LOS_MemFree(m_aucSysMem0, fmap->rename);
}
LOS_MemFree(m_aucSysMem0, fmap);
return OK;
}
void dec_mapping_nolock(struct page_mapping *mapping)
{
if (mapping == NULL) {
return;
}
(VOID)LOS_MuxLock(&g_file_mapping.lock, LOS_WAIT_FOREVER);
if (LOS_AtomicRead(&mapping->ref) > 0) {
LOS_AtomicDec(&mapping->ref);
}
if (LOS_AtomicRead(&mapping->ref) <= 0) {
remove_mapping_nolock(mapping);
} else {
OsFileCacheFlush(mapping);
}
(VOID)LOS_MuxUnlock(&g_file_mapping.lock);
}
int remove_mapping(const char *fullpath)
{
int ret;
struct filelist *f_list = NULL;
struct page_mapping *mapping = NULL;
f_list = &tg_filelist;
ret = sem_wait(&f_list->fl_sem);
if (ret < 0) {
PRINTK("sem_wait error, ret=%d\n", ret);
return VFS_ERROR;
}
(VOID)LOS_MuxLock(&g_file_mapping.lock, LOS_WAIT_FOREVER);
mapping = find_mapping_nolock(fullpath);
if (mapping) {
ret = remove_mapping_nolock(mapping);
}
(VOID)LOS_MuxUnlock(&g_file_mapping.lock);
(void)sem_post(&f_list->fl_sem);
return OK;
}
void rename_mapping(const char *src_path, const char *dst_path)
{
int ret;
char *tmp = NULL;
int path_len;
struct file_map *fmap = NULL;
struct page_mapping *mapping = NULL;
if (src_path == NULL || dst_path == NULL) {
return;
}
path_len = strlen(dst_path);
/* protect the whole list in case of this node been deleted just after we found it */
(VOID)LOS_MuxLock(&g_file_mapping.lock, LOS_WAIT_FOREVER);
mapping = find_mapping_nolock(src_path);
if (!mapping) {
goto out;
}
fmap = LOS_DL_LIST_ENTRY(mapping, struct file_map, mapping);
tmp = LOS_MemAlloc(m_aucSysMem0, path_len + 1);
if (!tmp) {
PRINT_ERR("%s-%d: Mem alloc failed, path length(%d)\n", __FUNCTION__, __LINE__, path_len);
goto out;
}
ret = strncpy_s(tmp, path_len, dst_path, strlen(dst_path));
if (ret != 0) {
(VOID)LOS_MemFree(m_aucSysMem0, tmp);
goto out;
}
tmp[path_len] = '\0';
fmap->rename = tmp;
out:
(VOID)LOS_MuxUnlock(&g_file_mapping.lock);
}
int update_file_path(const char *old_path, const char *new_path)
{
struct filelist *f_list = NULL;
struct file *filp = NULL;
int ret;
f_list = &tg_filelist;
ret = sem_wait(&f_list->fl_sem);
if (ret < 0) {
PRINTK("sem_wait error, ret=%d\n", ret);
return VFS_ERROR;
}
(VOID)LOS_MuxLock(&g_file_mapping.lock, LOS_WAIT_FOREVER);
for (int i = 3; i < CONFIG_NFILE_DESCRIPTORS; i++) {
if (!get_bit(i)) {
continue;
}
filp = &tg_filelist.fl_files[i];
if (filp->f_path == NULL || strcmp(filp->f_path, old_path)) {
continue;
}
int len = strlen(new_path) + 1;
char *tmp_path = LOS_MemAlloc(m_aucSysMem0, len);
if (tmp_path == NULL) {
PRINT_ERR("%s-%d: Mem alloc failed, path length(%d)\n", __FUNCTION__, __LINE__, len);
ret = VFS_ERROR;
goto out;
}
ret = strncpy_s(tmp_path, strlen(new_path) + 1, new_path, len);
if (ret != 0) {
(VOID)LOS_MemFree(m_aucSysMem0, tmp_path);
PRINT_ERR("%s-%d: strcpy failed.\n", __FUNCTION__, __LINE__);
ret = VFS_ERROR;
goto out;
}
free(filp->f_path);
filp->f_path = tmp_path;
}
ret = LOS_OK;
out:
(VOID)LOS_MuxUnlock(&g_file_mapping.lock);
(void)sem_post(&f_list->fl_sem);
return ret;
}
#ifdef LOSCFG_DEBUG_VERSION
struct file_map* GetFileMappingList(void)
{
return &g_file_mapping;
}
#endif
#endif

View File

@ -59,34 +59,27 @@ void los_vfs_init(void)
retval = VnodesInit();
if (retval != LOS_OK) {
PRINT_ERR("los_vfs_init VnodeInit failed error %d\n", retval);
PRINT_ERR("los_vfs_init VnodeInit failed error %u\n", retval);
return;
}
retval = PathCacheInit();
if (retval != LOS_OK) {
PRINT_ERR("los_vfs_init PathCacheInit failed error %d\n", retval);
PRINT_ERR("los_vfs_init PathCacheInit failed error %u\n", retval);
return;
}
retval = VnodeHashInit();
if (retval != LOS_OK) {
PRINT_ERR("los_vfs_init VnodeHashInit failed error %d\n", retval);
PRINT_ERR("los_vfs_init VnodeHashInit failed error %u\n", retval);
return;
}
retval = VnodeDevInit();
if (retval != LOS_OK) {
PRINT_ERR("los_vfs_init VnodeDevInit failed error %d\n", retval);
PRINT_ERR("los_vfs_init VnodeDevInit failed error %u\n", retval);
return;
}
#ifdef LOSCFG_KERNEL_VM
retval = init_file_mapping();
if (retval != LOS_OK) {
PRINT_ERR("Page cache file map init failed\n");
return;
}
#endif
g_vfs_init = true;
}

View File

@ -535,7 +535,7 @@ static void PrintFileInfo64(const struct stat64 *stat64Info, const char *name)
dirFlag = '-';
}
PRINTK("%c%s%s%s %-8lld u:%-5d g:%-5d %-10s\n", dirFlag,
PRINTK("%c%s%s%s %-8lld u:%-5u g:%-5u %-10s\n", dirFlag,
str[0], str[1], str[UGO_NUMS - 1], stat64Info->st_size, stat64Info->st_uid, stat64Info->st_gid, name);
}
@ -561,7 +561,7 @@ static void PrintFileInfo(const struct stat *statInfo, const char *name)
dirFlag = '-';
}
PRINTK("%c%s%s%s %-8lld u:%-5d g:%-5d %-10s\n", dirFlag,
PRINTK("%c%s%s%s %-8lld u:%-5u g:%-5u %-10s\n", dirFlag,
str[0], str[1], str[UGO_NUMS - 1], statInfo->st_size, statInfo->st_uid, statInfo->st_gid, name);
}
@ -736,7 +736,7 @@ void lsfd(void)
while (i < CONFIG_NFILE_DESCRIPTORS) {
node = files_get_openfile(i);
if (node) {
PRINTK("%5d %s\n", i, f_list->fl_files[i].f_path);
PRINTK("%5u %s\n", i, f_list->fl_files[i].f_path);
}
i++;
}

View File

@ -71,7 +71,7 @@ void PathCacheDump(void)
LIST_HEAD *nhead = &g_pathCacheHashEntrys[i];
LOS_DL_LIST_FOR_EACH_ENTRY(pc, nhead, struct PathCache, hashEntry) {
PRINTK(" pathCache dump hash %d item %s %p %p %d\n", i,
PRINTK(" pathCache dump hash %d item %s %p %p %u\n", i,
pc->name, pc->parentVnode, pc->childVnode, pc->nameLen);
}
}

View File

@ -65,6 +65,7 @@ int VnodesInit(void)
}
g_rootVnode->mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR;
g_rootVnode->type = VNODE_TYPE_DIR;
g_rootVnode->filePath = "/";
return LOS_OK;
}
@ -155,6 +156,11 @@ int VnodeAlloc(struct VnodeOps *vop, struct Vnode **newVnode)
LOS_ListTailInsert(&g_vnodeActiveList, &(vnode->actFreeEntry));
vnode->vop = vop;
}
LOS_ListInit(&vnode->mapping.page_list);
LOS_SpinInit(&vnode->mapping.list_lock);
(VOID)LOS_MuxInit(&vnode->mapping.mux_lock, NULL);
vnode->mapping.host = vnode;
VnodeDrop();
*newVnode = vnode;
@ -182,6 +188,9 @@ int VnodeFree(struct Vnode *vnode)
vnode->vop->Reclaim(vnode);
}
if (vnode->filePath) {
free(vnode->filePath);
}
if (vnode->vop == &g_devfsOps) {
/* for dev vnode, just free it */
free(vnode->data);
@ -363,6 +372,8 @@ STEP_FINISH:
int VnodeLookupAt(const char *path, struct Vnode **result, uint32_t flags, struct Vnode *orgVnode)
{
int ret;
int vnodePathLen;
char *vnodePath = NULL;
struct Vnode *startVnode = NULL;
char *normalizedPath = NULL;
@ -391,7 +402,12 @@ int VnodeLookupAt(const char *path, struct Vnode **result, uint32_t flags, struc
if (currentDir == NULL || *currentDir == '\0') {
// return target or parent vnode as result
*result = currentVnode;
goto OUT_FREE_PATH;
if (currentVnode->filePath == NULL) {
currentVnode->filePath = normalizedPath;
} else {
free(normalizedPath);
}
return ret;
} else if (VfsVnodePermissionCheck(currentVnode, EXEC_OP)) {
ret = -EACCES;
goto OUT_FREE_PATH;
@ -401,13 +417,28 @@ int VnodeLookupAt(const char *path, struct Vnode **result, uint32_t flags, struc
// no such file, lookup failed
goto OUT_FREE_PATH;
}
if (currentVnode->filePath == NULL) {
vnodePathLen = currentDir - normalizedPath;
vnodePath = malloc(vnodePathLen + 1);
if (vnodePath == NULL) {
ret = -ENOMEM;
goto OUT_FREE_PATH;
}
ret = strncpy_s(vnodePath, vnodePathLen + 1, normalizedPath, vnodePathLen);
if (ret != EOK) {
ret = -ENAMETOOLONG;
free(vnodePath);
goto OUT_FREE_PATH;
}
currentVnode->filePath = vnodePath;
currentVnode->filePath[vnodePathLen] = 0;
}
}
OUT_FREE_PATH:
if (normalizedPath) {
free(normalizedPath);
}
return ret;
}
@ -534,6 +565,9 @@ int VnodeCreate(struct Vnode *parent, const char *name, int mode, struct Vnode *
newVnode->uid = parent->uid;
newVnode->gid = parent->gid;
newVnode->mode = mode;
/* The 'name' here is not full path, but for device we don't depend on this path, it's just a name for DFx.
When we have devfs, we can get a fullpath. */
newVnode->filePath = strdup(name);
*vnode = newVnode;
return 0;
@ -635,7 +669,7 @@ void VnodeMemoryDump(void)
}
PRINTK("Vnode number = %d\n", vnodeCount);
PRINTK("Vnode memory size = %d(B)\n", vnodeCount * sizeof(struct Vnode));
PRINTK("Vnode memory size = %u(B)\n", vnodeCount * sizeof(struct Vnode));
}
LIST_HEAD* GetVnodeFreeList()

View File

@ -338,10 +338,16 @@ STATIC VOID OsWaitCheckAndWakeParentProcess(LosProcessCB *parentCB, const LosPro
LITE_OS_SEC_TEXT VOID OsProcessResourcesToFree(LosProcessCB *processCB)
{
if (!(processCB->processStatus & (OS_PROCESS_STATUS_INIT | OS_PROCESS_STATUS_RUNNING))) {
PRINT_ERR("The process(%d) has no permission to release process(%d) resources!\n",
PRINT_ERR("The process(%u) has no permission to release process(%u) resources!\n",
OsCurrProcessGet()->processID, processCB->processID);
}
#ifdef LOSCFG_KERNEL_VM
if (OsProcessIsUserMode(processCB)) {
(VOID)OsVmSpaceRegionFree(processCB->vmSpace);
}
#endif
#ifdef LOSCFG_FS_VFS
if (OsProcessIsUserMode(processCB)) {
delete_files(processCB->files);
@ -368,7 +374,7 @@ LITE_OS_SEC_TEXT VOID OsProcessResourcesToFree(LosProcessCB *processCB)
#ifdef LOSCFG_KERNEL_LITEIPC
if (OsProcessIsUserMode(processCB)) {
LiteIpcPoolDelete(&(processCB->ipcInfo));
LiteIpcPoolDelete(&(processCB->ipcInfo), processCB->processID);
(VOID)memset_s(&(processCB->ipcInfo), sizeof(ProcIpcInfo), 0, sizeof(ProcIpcInfo));
}
#endif
@ -546,11 +552,11 @@ LITE_OS_SEC_TEXT VOID OsProcessCBRecycleToFree(VOID)
/* Clear the bottom 4 bits of process status */
OsInsertPCBToFreeList(processCB);
}
SCHEDULER_UNLOCK(intSave);
#ifdef LOSCFG_KERNEL_VM
SCHEDULER_UNLOCK(intSave);
(VOID)LOS_VmSpaceFree(space);
#endif
SCHEDULER_LOCK(intSave);
#endif
}
SCHEDULER_UNLOCK(intSave);

View File

@ -478,7 +478,7 @@ LITE_OS_SEC_TEXT VOID OsTaskResourcesToFree(LosTaskCB *taskCB)
LOS_ASSERT(!(processCB->vmSpace == NULL));
UINT32 ret = OsUnMMap(processCB->vmSpace, (UINTPTR)mapBase, mapSize);
if ((ret != LOS_OK) && (mapBase != 0) && !(processCB->processStatus & OS_PROCESS_STATUS_INIT)) {
PRINT_ERR("process(%u) ummap user task(%u) stack failed! mapbase: 0x%x size :0x%x, error: %d\n",
PRINT_ERR("process(%u) ummap user task(%u) stack failed! mapbase: 0x%x size :0x%x, error: %u\n",
processCB->processID, taskCB->taskID, mapBase, mapSize, ret);
}
@ -498,6 +498,7 @@ LITE_OS_SEC_TEXT VOID OsTaskResourcesToFree(LosTaskCB *taskCB)
OsTaskKernelResourcesToFree(syncSignal, topOfStack);
SCHEDULER_LOCK(intSave);
OsClearSigInfoTmpList(&(taskCB->sig));
OsInsertTCBToFreeList(taskCB);
SCHEDULER_UNLOCK(intSave);
}

View File

@ -121,7 +121,7 @@ typedef struct ProcessCB {
TimerIdMap timerIdMap;
#endif
#ifdef LOSCFG_DRIVERS_TZDRIVER
struct file *execFile; /**< Exec bin of the process */
struct Vnode *execVnode; /**< Exec bin of the process */
#endif
mode_t umask;
#ifdef LOSCFG_KERNEL_CPUP

View File

@ -132,6 +132,11 @@ struct sq_queue_s {
};
typedef struct sq_queue_s sq_queue_t;
typedef struct SigInfoListNode {
struct SigInfoListNode *next;
siginfo_t info;
} SigInfoListNode;
typedef struct {
sigset_t sigFlag;
sigset_t sigPendFlag;
@ -140,6 +145,7 @@ typedef struct {
LOS_DL_LIST waitList;
sigset_t sigwaitmask; /* Waiting for pending signals */
siginfo_t sigunbinfo; /* Signal info when task unblocked */
SigInfoListNode *tmpInfoListHead; /* Signal info List */
unsigned int sigIntLock;
void *sigContext;
unsigned int count;
@ -167,6 +173,7 @@ int OsSigSuspend(const sigset_t *set);
VOID OsSigIntLock(VOID);
VOID OsSigIntUnlock(VOID);
INT32 OsTaskKillUnsafe(UINT32 taskID, INT32 signo);
VOID OsClearSigInfoTmpList(sig_cb *sigcb);
#ifdef __cplusplus
#if __cplusplus

View File

@ -44,6 +44,8 @@
#include "los_vm_zone.h"
#include "los_vm_common.h"
struct Vnode;
#ifdef __cplusplus
#if __cplusplus
extern "C" {
@ -91,8 +93,8 @@ struct VmMapRegion {
UINT8 regionType; /**< vm region type: ANON, FILE, DEV */
union {
struct VmRegionFile {
unsigned int fileMagic;
struct file *file;
int f_oflags;
struct Vnode *vnode;
const LosVmFileOps *vmFOps;
} rf;
struct VmRegionAnon {
@ -290,6 +292,8 @@ LosVmSpace *OsCreateUserVmSpace(VOID);
STATUS_T LOS_VmSpaceClone(LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace);
LosMux *OsGVmSpaceMuxGet(VOID);
STATUS_T OsUnMMap(LosVmSpace *space, VADDR_T addr, size_t size);
STATUS_T OsVmSpaceRegionFree(LosVmSpace *space);
/**
* thread safety
* it is used to malloc continuous virtual memory, no sure for continuous physical memory.

View File

@ -519,7 +519,7 @@ STATIC INT32 OsFutexWaitParamCheck(const UINT32 *userVaddr, UINT32 flags, UINT32
}
if (flags && (OsFutexKeyShmPermCheck(userVaddr, flags) != LOS_OK)) {
PRINT_ERR("Futex wait param check failed! error shared memory perm userVaddr: 0x%x\n", userVaddr);
PRINT_ERR("Futex wait param check failed! error shared memory perm userVaddr: 0x%x\n", (UINTPTR)userVaddr);
return LOS_EINVAL;
}
@ -663,12 +663,12 @@ STATIC INT32 OsFutexWakeParamCheck(const UINT32 *userVaddr, UINT32 flags)
}
if ((vaddr % sizeof(INT32)) || (vaddr < OS_FUTEX_KEY_BASE) || (vaddr >= OS_FUTEX_KEY_MAX)) {
PRINT_ERR("Futex wake param check failed! error userVaddr: 0x%x\n", userVaddr);
PRINT_ERR("Futex wake param check failed! error userVaddr: 0x%x\n", (UINTPTR)userVaddr);
return LOS_EINVAL;
}
if (flags && (OsFutexKeyShmPermCheck(userVaddr, flags) != LOS_OK)) {
PRINT_ERR("Futex wake param check failed! error shared memory perm userVaddr: 0x%x\n", userVaddr);
PRINT_ERR("Futex wake param check failed! error shared memory perm userVaddr: 0x%x\n", (UINTPTR)userVaddr);
return LOS_EINVAL;
}
@ -941,12 +941,12 @@ STATIC INT32 OsFutexRequeueParamCheck(const UINT32 *oldUserVaddr, UINT32 flags,
}
if ((oldVaddr % sizeof(INT32)) || (oldVaddr < OS_FUTEX_KEY_BASE) || (oldVaddr >= OS_FUTEX_KEY_MAX)) {
PRINT_ERR("Futex requeue param check failed! error old userVaddr: 0x%x\n", oldUserVaddr);
PRINT_ERR("Futex requeue param check failed! error old userVaddr: 0x%x\n", (UINTPTR)oldUserVaddr);
return LOS_EINVAL;
}
if ((newVaddr % sizeof(INT32)) || (newVaddr < OS_FUTEX_KEY_BASE) || (newVaddr >= OS_FUTEX_KEY_MAX)) {
PRINT_ERR("Futex requeue param check failed! error new userVaddr: 0x%x\n", newUserVaddr);
PRINT_ERR("Futex requeue param check failed! error new userVaddr: 0x%x\n", (UINTPTR)newUserVaddr);
return LOS_EINVAL;
}

View File

@ -67,11 +67,67 @@ int OsSigIsMember(const sigset_t *set, int signo)
return ret;
}
STATIC VOID OsMoveTmpInfoToUnbInfo(sig_cb *sigcb, INT32 signo)
{
SigInfoListNode *tmpInfoNode = sigcb->tmpInfoListHead;
SigInfoListNode **prevHook = &sigcb->tmpInfoListHead;
while (tmpInfoNode != NULL) {
if (tmpInfoNode->info.si_signo == signo) {
/* copy tmpinfo to unbinfo. */
(VOID)memcpy_s(&sigcb->sigunbinfo, sizeof(siginfo_t), &tmpInfoNode->info, sizeof(siginfo_t));
/* delete tmpinfo from tmpList. */
*prevHook = tmpInfoNode->next;
(VOID)LOS_MemFree(m_aucSysMem0, tmpInfoNode);
tmpInfoNode = *prevHook;
break;
}
prevHook = &tmpInfoNode->next;
tmpInfoNode = tmpInfoNode->next;
}
}
STATIC INT32 OsAddSigInfoToTmpList(sig_cb *sigcb, siginfo_t *info)
{
/* try to find the old siginfo */
SigInfoListNode *tmp = sigcb->tmpInfoListHead;
while (tmp != NULL) {
if (tmp->info.si_signo == info->si_signo) {
/* found it, break. */
break;
}
tmp = tmp->next;
}
if (tmp == NULL) {
/* none, alloc new one */
tmp = (SigInfoListNode *)LOS_MemAlloc(m_aucSysMem0, sizeof(SigInfoListNode));
if (tmp == NULL) {
return LOS_NOK;
}
tmp->next = sigcb->tmpInfoListHead;
sigcb->tmpInfoListHead = tmp;
}
(VOID)memcpy_s(&tmp->info, sizeof(siginfo_t), info, sizeof(siginfo_t));
return LOS_OK;
}
VOID OsClearSigInfoTmpList(sig_cb *sigcb)
{
while (sigcb->tmpInfoListHead != NULL) {
SigInfoListNode *tmpInfoNode = sigcb->tmpInfoListHead;
sigcb->tmpInfoListHead = sigcb->tmpInfoListHead->next;
(VOID)LOS_MemFree(m_aucSysMem0, tmpInfoNode);
}
}
STATIC INLINE VOID OsSigWaitTaskWake(LosTaskCB *taskCB, INT32 signo)
{
sig_cb *sigcb = &taskCB->sig;
if (!LOS_ListEmpty(&sigcb->waitList) && OsSigIsMember(&sigcb->sigwaitmask, signo)) {
OsMoveTmpInfoToUnbInfo(sigcb, signo);
OsTaskWakeClearPendMask(taskCB);
OsSchedTaskWake(taskCB);
OsSigEmptySet(&sigcb->sigwaitmask);
@ -141,7 +197,10 @@ int OsTcbDispatch(LosTaskCB *stcb, siginfo_t *info)
/* unmasked signal actions */
OsSigAddSet(&sigcb->sigFlag, info->si_signo);
}
(void) memcpy_s(&sigcb->sigunbinfo, sizeof(siginfo_t), info, sizeof(siginfo_t));
if (OsAddSigInfoToTmpList(sigcb, info) == LOS_NOK) {
return -ENOMEM;
}
return OsPendingTaskWake(stcb, info->si_signo);
}
@ -159,28 +218,22 @@ void OsSigMaskSwitch(LosTaskCB * const rtcb, sigset_t set)
}
}
int OsSigprocMask(int how, const sigset_t_l *setl, sigset_t_l *oldset)
int OsSigprocMask(int how, const sigset_t_l *setl, sigset_t_l *oldsetl)
{
LosTaskCB *spcb = NULL;
sigset_t oldSigprocmask;
int ret = LOS_OK;
unsigned int intSave;
sigset_t set;
int retVal;
if (setl != NULL) {
retVal = LOS_ArchCopyFromUser(&set, &(setl->sig[0]), sizeof(sigset_t));
if (retVal != 0) {
return -EFAULT;
}
}
SCHEDULER_LOCK(intSave);
spcb = OsCurrTaskGet();
/* If requested, copy the old mask to user. */
oldSigprocmask = spcb->sig.sigprocmask;
if (oldsetl != NULL) {
*(sigset_t *)oldsetl = spcb->sig.sigprocmask;
}
/* If requested, modify the current signal mask. */
if (setl != NULL) {
set = *(sigset_t *)setl;
/* Okay, determine what we are supposed to do */
switch (how) {
/* Set the union of the current set and the signal
@ -208,12 +261,6 @@ int OsSigprocMask(int how, const sigset_t_l *setl, sigset_t_l *oldset)
}
SCHEDULER_UNLOCK(intSave);
if (oldset != NULL) {
retVal = LOS_ArchCopyToUser(&(oldset->sig[0]), &oldSigprocmask, sizeof(sigset_t));
if (retVal != 0) {
return -EFAULT;
}
}
return ret;
}
@ -516,6 +563,7 @@ int OsSigTimedWaitNoLock(sigset_t *set, siginfo_t *info, unsigned int timeout)
if (clear) {
sigcb->sigPendFlag ^= clear;
ret = FindFirstSetedBit((UINT64)clear) + 1;
OsMoveTmpInfoToUnbInfo(sigcb, ret);
} else {
OsSigAddSet(set, SIGKILL);
OsSigAddSet(set, SIGSTOP);
@ -529,7 +577,7 @@ int OsSigTimedWaitNoLock(sigset_t *set, siginfo_t *info, unsigned int timeout)
sigcb->sigwaitmask = NULL_SIGNAL_SET;
}
if (info != NULL) {
(void) memcpy_s(info, sizeof(siginfo_t), &sigcb->sigunbinfo, sizeof(siginfo_t));
(VOID)memcpy_s(info, sizeof(siginfo_t), &sigcb->sigunbinfo, sizeof(siginfo_t));
}
return ret;
}
@ -650,13 +698,14 @@ VOID *OsSaveSignalContext(VOID *sp, VOID *newSp)
sigcb->sigFlag = 0;
process->sigShare = 0;
SCHEDULER_UNLOCK(intSave);
PRINT_ERR("The signal processing function for the current process pid =%d is NULL!\n", task->processID);
PRINT_ERR("The signal processing function for the current process pid =%u is NULL!\n", task->processID);
return sp;
}
/* One pthread do the share signal */
sigcb->sigFlag |= process->sigShare;
UINT32 signo = (UINT32)FindFirstSetedBit(sigcb->sigFlag) + 1;
UINT32 sigVal = (UINT32)(UINTPTR)(sigcb->sigunbinfo.si_value.sival_ptr);
OsMoveTmpInfoToUnbInfo(sigcb, signo);
OsProcessExitCodeSignalSet(process, signo);
sigcb->sigContext = sp;
@ -683,7 +732,7 @@ VOID *OsRestorSignalContext(VOID *sp)
SCHEDULER_LOCK(intSave);
if (sigcb->count != 1) {
SCHEDULER_UNLOCK(intSave);
PRINT_ERR("sig error count : %d\n", sigcb->count);
PRINT_ERR("sig error count : %u\n", sigcb->count);
return sp;
}

View File

@ -312,7 +312,7 @@ STATIC INLINE struct OsMemNodeHead *PreSentinelNodeGet(const VOID *pool, const s
sentinelNode = OS_MEM_END_NODE(pool, ((struct OsMemPoolHead *)pool)->info.totalSize);
while (sentinelNode != NULL) {
if (OsMemIsLastSentinelNode(sentinelNode)) {
PRINT_ERR("PreSentinelNodeGet can not find node %#x\n", node);
PRINT_ERR("PreSentinelNodeGet can not find node %#x\n", (UINTPTR)node);
return NULL;
}
nextNode = OsMemSentinelNodeGet(sentinelNode);
@ -363,7 +363,7 @@ STATIC INLINE BOOL TryShrinkPool(const VOID *pool, const struct OsMemNodeHead *n
}
if (OsMemLargeNodeFree(node) != LOS_OK) {
PRINT_ERR("TryShrinkPool free %#x failed!\n", node);
PRINT_ERR("TryShrinkPool free %#x failed!\n", (UINTPTR)node);
return FALSE;
}
@ -1474,13 +1474,13 @@ STATIC UINT32 OsMemAddrValidCheckPrint(const VOID *pool, struct OsMemFreeNodeHea
if (((*tmpNode)->prev != NULL) && !OsMemAddrValidCheck(pool, (*tmpNode)->prev)) {
PRINT_ERR("[%s], %d, memory check error!\n"
" freeNode.prev:%#x is out of legal mem range\n",
__FUNCTION__, __LINE__, (*tmpNode)->prev);
__FUNCTION__, __LINE__, (UINTPTR)(*tmpNode)->prev);
return LOS_NOK;
}
if (((*tmpNode)->next != NULL) && !OsMemAddrValidCheck(pool, (*tmpNode)->next)) {
PRINT_ERR("[%s], %d, memory check error!\n"
" freeNode.next:%#x is out of legal mem range\n",
__FUNCTION__, __LINE__, (*tmpNode)->next);
__FUNCTION__, __LINE__, (UINTPTR)(*tmpNode)->next);
return LOS_NOK;
}
return LOS_OK;
@ -1538,7 +1538,7 @@ STATIC VOID OsMemPoolHeadCheck(const struct OsMemPoolHead *pool)
if (OsMemFreeListNodeCheck(pool, tmpNode)) {
flag = 1;
PRINT_ERR("FreeListIndex: %u, node: %#x, bNode: %#x, prev: %#x, next: %#x\n",
index, tmpNode, tmpNode->header.ptr.prev, tmpNode->prev, tmpNode->next);
index, (UINTPTR)tmpNode, (UINTPTR)tmpNode->header.ptr.prev, (UINTPTR)tmpNode->prev, (UINTPTR)tmpNode->next);
goto OUT;
}
}
@ -1546,7 +1546,7 @@ STATIC VOID OsMemPoolHeadCheck(const struct OsMemPoolHead *pool)
OUT:
if (flag) {
PRINTK("mem pool info: poolAddr: %#x, poolSize: 0x%x\n", pool, pool->info.totalSize);
PRINTK("mem pool info: poolAddr: %#x, poolSize: 0x%x\n", (UINTPTR)pool, pool->info.totalSize);
#ifdef LOSCFG_MEM_WATERLINE
PRINTK("mem pool info: poolWaterLine: 0x%x, poolCurUsedSize: 0x%x\n", pool->info.waterLine,
pool->info.curUsedSize);
@ -1559,7 +1559,7 @@ OUT:
size = OS_MEM_NODE_GET_SIZE(sentinel->sizeAndFlag);
node = OsMemSentinelNodeGet(sentinel);
sentinel = OS_MEM_END_NODE(node, size);
PRINTK("expand node info: nodeAddr: %#x, nodeSize: 0x%x\n", node, size);
PRINTK("expand node info: nodeAddr: %#x, nodeSize: 0x%x\n", (UINTPTR)node, size);
}
#endif
}
@ -1606,23 +1606,23 @@ STATIC VOID OsMemNodeInfo(const struct OsMemNodeHead *tmpNode,
if (OS_MEM_NODE_GET_USED_FLAG(tmpNode->sizeAndFlag)) {
usedNode = (struct OsMemUsedNodeHead *)tmpNode;
PRINTK("\n broken node head: %#x %#x %#x, ",
usedNode->header.ptr.prev, usedNode->header.magic, usedNode->header.sizeAndFlag);
(UINTPTR)usedNode->header.ptr.prev, usedNode->header.magic, usedNode->header.sizeAndFlag);
} else {
freeNode = (struct OsMemFreeNodeHead *)tmpNode;
PRINTK("\n broken node head: %#x %#x %#x %#x, ",
freeNode->header.ptr.prev, freeNode->next, freeNode->prev, freeNode->header.magic,
freeNode->header.sizeAndFlag);
(UINTPTR)freeNode->header.ptr.prev, (UINTPTR)freeNode->next, (UINTPTR)freeNode->prev,
freeNode->header.magic, freeNode->header.sizeAndFlag);
}
if (OS_MEM_NODE_GET_USED_FLAG(preNode->sizeAndFlag)) {
usedNode = (struct OsMemUsedNodeHead *)preNode;
PRINTK("prev node head: %#x %#x %#x\n",
usedNode->header.ptr.prev, usedNode->header.magic, usedNode->header.sizeAndFlag);
(UINTPTR)usedNode->header.ptr.prev, usedNode->header.magic, usedNode->header.sizeAndFlag);
} else {
freeNode = (struct OsMemFreeNodeHead *)preNode;
PRINTK("prev node head: %#x %#x %#x %#x, ",
freeNode->header.ptr.prev, freeNode->next, freeNode->prev, freeNode->header.magic,
freeNode->header.sizeAndFlag);
(UINTPTR)freeNode->header.ptr.prev, (UINTPTR)freeNode->next, (UINTPTR)freeNode->prev,
freeNode->header.magic, freeNode->header.sizeAndFlag);
}
#ifdef LOSCFG_MEM_LEAKCHECK
@ -1630,11 +1630,11 @@ STATIC VOID OsMemNodeInfo(const struct OsMemNodeHead *tmpNode,
#endif
PRINTK("\n---------------------------------------------\n");
PRINTK(" dump mem tmpNode:%#x ~ %#x\n", tmpNode, ((UINTPTR)tmpNode + OS_MEM_NODE_DUMP_SIZE));
PRINTK(" dump mem tmpNode:%#x ~ %#x\n", (UINTPTR)tmpNode, ((UINTPTR)tmpNode + OS_MEM_NODE_DUMP_SIZE));
OsDumpMemByte(OS_MEM_NODE_DUMP_SIZE, (UINTPTR)tmpNode);
PRINTK("\n---------------------------------------------\n");
if (preNode != tmpNode) {
PRINTK(" dump mem :%#x ~ tmpNode:%#x\n", ((UINTPTR)tmpNode - OS_MEM_NODE_DUMP_SIZE), tmpNode);
PRINTK(" dump mem :%#x ~ tmpNode:%#x\n", ((UINTPTR)tmpNode - OS_MEM_NODE_DUMP_SIZE), (UINTPTR)tmpNode);
OsDumpMemByte(OS_MEM_NODE_DUMP_SIZE, ((UINTPTR)tmpNode - OS_MEM_NODE_DUMP_SIZE));
PRINTK("\n---------------------------------------------\n");
}
@ -1669,10 +1669,10 @@ STATIC VOID OsMemIntegrityCheckError(struct OsMemPoolHead *pool,
}
MEM_UNLOCK(pool, intSave);
LOS_Panic("cur node: %#x\npre node: %#x\npre node was allocated by task:%s\n",
tmpNode, preNode, taskCB->taskName);
(UINTPTR)tmpNode, (UINTPTR)preNode, taskCB->taskName);
#else
MEM_UNLOCK(pool, intSave);
LOS_Panic("Memory interity check error, cur node: %#x, pre node: %#x\n", tmpNode, preNode);
LOS_Panic("Memory interity check error, cur node: %#x, pre node: %#x\n", (UINTPTR)tmpNode, (UINTPTR)preNode);
#endif
}
@ -1753,7 +1753,7 @@ UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_POOL_STATUS *poolStatus)
}
if ((pool == NULL) || (poolInfo->info.pool != pool)) {
PRINT_ERR("wrong mem pool addr: %#x, line:%d\n", poolInfo, __LINE__);
PRINT_ERR("wrong mem pool addr: %#x, line:%d\n", (UINTPTR)poolInfo, __LINE__);
return LOS_NOK;
}

View File

@ -100,7 +100,7 @@ VOID OsExcStackInfo(VOID)
stack = (UINTPTR *)((UINTPTR)stackTop + g_stackInfo[index].stackSize);
(VOID)OsStackWaterLineGet(stack, stackTop, &size);
PrintExcInfo("%11s %-5d %-10p 0x%-8x 0x%-4x\n", g_stackInfo[index].stackName,
PrintExcInfo("%11s %-5u %-10p 0x%-8x 0x%-4x\n", g_stackInfo[index].stackName,
LOSCFG_KERNEL_CORE_NUM - 1 - cpuid, stackTop, g_stackInfo[index].stackSize, size);
}
}

View File

@ -63,7 +63,7 @@ VOID OsDumpMemByte(size_t length, UINTPTR addr)
}
while (dataLen) {
if (IS_ALIGNED(count, sizeof(CHAR *))) {
PRINTK("\n 0x%lx :", alignAddr);
PRINTK("\n 0x%lx :", (UINTPTR)alignAddr);
#ifdef LOSCFG_SAVE_EXCINFO
WriteExcInfoToBuf("\n 0x%lx :", alignAddr);
#endif

View File

@ -111,7 +111,7 @@ STATIC VOID OsLockDepDumpLock(const LosTaskCB *task, const SPIN_LOCK_S *lock,
PrintExcInfo("lockdep check failed\n");
PrintExcInfo("error type : %s\n", OsLockDepErrorStringGet(errType));
PrintExcInfo("request addr : 0x%x\n", requestAddr);
PrintExcInfo("request addr : 0x%x\n", (UINTPTR)requestAddr);
while (1) {
PrintExcInfo("task name : %s\n", temp->taskName);
@ -121,7 +121,7 @@ STATIC VOID OsLockDepDumpLock(const LosTaskCB *task, const SPIN_LOCK_S *lock,
for (i = 0; i < lockDep->lockDepth; i++) {
if (lockDep->heldLocks[i].lockPtr == lock) {
PrintExcInfo("[%d] %s <-- addr:0x%x\n", i, LOCKDEP_GET_NAME(lockDep, i),
LOCKDEP_GET_ADDR(lockDep, i));
(UINTPTR)LOCKDEP_GET_ADDR(lockDep, i));
} else {
PrintExcInfo("[%d] %s \n", i, LOCKDEP_GET_NAME(lockDep, i));
}

View File

@ -920,7 +920,7 @@ VOID OsSchedStart(VOID)
OsPercpuGet()->responseID = OS_INVALID;
OsSchedSetNextExpireTime(newTask->startTime, newTask->taskID, newTask->startTime + newTask->timeSlice, OS_INVALID);
PRINTK("cpu %d entering scheduler\n", cpuid);
PRINTK("cpu %u entering scheduler\n", cpuid);
OsTaskContextLoad(newTask);
}
@ -939,7 +939,7 @@ VOID OsSchedToUserReleaseLock(VOID)
STATIC VOID OsTaskStackCheck(LosTaskCB *runTask, LosTaskCB *newTask)
{
if (!OS_STACK_MAGIC_CHECK(runTask->topOfStack)) {
LOS_Panic("CURRENT task ID: %s:%d stack overflow!\n", runTask->taskName, runTask->taskID);
LOS_Panic("CURRENT task ID: %s:%u stack overflow!\n", runTask->taskName, runTask->taskID);
}
if (((UINTPTR)(newTask->stackPointer) <= newTask->topOfStack) ||

View File

@ -38,6 +38,7 @@
#include "los_mmu_descriptor_v6.h"
#ifdef LOSCFG_FS_VFS
#include "fs/file.h"
#include "vnode.h"
#endif
#include "los_printf.h"
#include "los_vm_page.h"
@ -55,13 +56,13 @@
const CHAR *OsGetRegionNameOrFilePath(LosVmMapRegion *region)
{
struct file *filep = NULL;
struct Vnode *vnode = NULL;
if (region == NULL) {
return "";
#ifdef LOSCFG_FS_VFS
} else if (LOS_IsRegionFileValid(region)) {
filep = region->unTypeData.rf.file;
return filep->f_path;
vnode = region->unTypeData.rf.vnode;
return vnode->filePath;
#endif
} else if (region->regionFlags & VM_MAP_REGION_FLAG_HEAP) {
return "HEAP";
@ -373,8 +374,8 @@ VOID OsDumpRegion2(LosVmSpace *space, LosVmMapRegion *region)
if (flagsStr == NULL) {
return;
}
PRINTK("\t %#010x %-32.32s %#010x %#010x %-15.15s %4d %4d\n",
region, OsGetRegionNameOrFilePath(region), region->range.base,
PRINTK("\t %#010x %-32.32s %#010x %#010x %-15.15s %4u %4u\n",
(UINTPTR)region, OsGetRegionNameOrFilePath(region), region->range.base,
region->range.size, flagsStr, regionPages, pssPages);
(VOID)LOS_MemFree(m_aucSysMem0, flagsStr);
}
@ -394,7 +395,7 @@ VOID OsDumpAspace(LosVmSpace *space)
spacePages = OsCountAspacePages(space);
PRINTK("\r\n PID aspace name base size pages \n");
PRINTK(" ---- ------ ---- ---- ----- ----\n");
PRINTK(" %-4d %#010x %-10.10s %#010x %#010x %d\n", pcb->processID, space, pcb->processName,
PRINTK(" %-4u %#010x %-10.10s %#010x %#010x %u\n", pcb->processID, space, pcb->processName,
space->base, space->size, spacePages);
PRINTK("\r\n\t region name base size mmu_flags pages pg/ref\n");
PRINTK("\t ------ ---- ---- ---- --------- ----- -----\n");
@ -467,7 +468,7 @@ VOID OsDumpPte(VADDR_T vaddr)
}
return;
ERR:
PRINTK("%s, error vaddr: %#x, l2Table: %#x, l2Index: %#x\n", __FUNCTION__, vaddr, l2Table, l2Index);
PRINTK("%s, error vaddr: %#x, l2Table: %#x, l2Index: %#x\n", __FUNCTION__, vaddr, (UINTPTR)l2Table, l2Index);
}
UINT32 OsVmPhySegPagesGet(LosVmPhysSeg *seg)
@ -504,7 +505,7 @@ VOID OsVmPhysDump(VOID)
PRINTK("\r\n phys_seg base size free_pages \n");
PRINTK(" -------- ------- ---------- --------- \n");
#endif
PRINTK(" 0x%08x 0x%08x 0x%08x %8u \n", seg, seg->start, seg->size, segFreePages);
PRINTK(" 0x%08x 0x%08x 0x%08x %8u \n", (UINTPTR)seg, seg->start, seg->size, segFreePages);
totalFreePages += segFreePages;
totalPages += (seg->size >> PAGE_SHIFT);

View File

@ -45,6 +45,10 @@
#include "los_process_pri.h"
#include "arm.h"
#ifdef LOSCFG_FS_VFS
#include "vnode.h"
#endif
#ifdef LOSCFG_KERNEL_VM
@ -106,11 +110,11 @@ STATIC STATUS_T OsDoReadFault(LosVmMapRegion *region, LosVmPgFault *vmPgFault)
return LOS_OK;
}
if (region->unTypeData.rf.vmFOps == NULL || region->unTypeData.rf.vmFOps->fault == NULL) {
VM_ERR("region args invalid, file path: %s", region->unTypeData.rf.file->f_path);
VM_ERR("region args invalid, file path: %s", region->unTypeData.rf.vnode->filePath);
return LOS_ERRNO_VM_INVALID_ARGS;
}
(VOID)LOS_MuxAcquire(&region->unTypeData.rf.file->f_mapping->mux_lock);
(VOID)LOS_MuxAcquire(&region->unTypeData.rf.vnode->mapping.mux_lock);
ret = region->unTypeData.rf.vmFOps->fault(region, vmPgFault);
if (ret == LOS_OK) {
paddr = LOS_PaddrQuery(vmPgFault->pageKVaddr);
@ -124,14 +128,14 @@ STATIC STATUS_T OsDoReadFault(LosVmMapRegion *region, LosVmPgFault *vmPgFault)
if (ret < 0) {
VM_ERR("LOS_ArchMmuMap failed");
OsDelMapInfo(region, vmPgFault, false);
(VOID)LOS_MuxRelease(&region->unTypeData.rf.file->f_mapping->mux_lock);
(VOID)LOS_MuxRelease(&region->unTypeData.rf.vnode->mapping.mux_lock);
return LOS_ERRNO_VM_NO_MEMORY;
}
(VOID)LOS_MuxRelease(&region->unTypeData.rf.file->f_mapping->mux_lock);
(VOID)LOS_MuxRelease(&region->unTypeData.rf.vnode->mapping.mux_lock);
return LOS_OK;
}
(VOID)LOS_MuxRelease(&region->unTypeData.rf.file->f_mapping->mux_lock);
(VOID)LOS_MuxRelease(&region->unTypeData.rf.vnode->mapping.mux_lock);
return LOS_ERRNO_VM_NO_MEMORY;
}
@ -145,8 +149,8 @@ STATIC LosVmPage *OsCowUnmapOrg(LosArchMmu *archMmu, LosVmMapRegion *region, Los
LosFilePage *fpage = NULL;
VADDR_T vaddr = (VADDR_T)vmf->vaddr;
LOS_SpinLockSave(&region->unTypeData.rf.file->f_mapping->list_lock, &intSave);
fpage = OsFindGetEntry(region->unTypeData.rf.file->f_mapping, vmf->pgoff);
LOS_SpinLockSave(&region->unTypeData.rf.vnode->mapping.list_lock, &intSave);
fpage = OsFindGetEntry(&region->unTypeData.rf.vnode->mapping, vmf->pgoff);
if (fpage != NULL) {
oldPage = fpage->vmPage;
OsSetPageLocked(oldPage);
@ -159,7 +163,7 @@ STATIC LosVmPage *OsCowUnmapOrg(LosArchMmu *archMmu, LosVmMapRegion *region, Los
} else {
LOS_ArchMmuUnmap(archMmu, vaddr, 1);
}
LOS_SpinUnlockRestore(&region->unTypeData.rf.file->f_mapping->list_lock, intSave);
LOS_SpinUnlockRestore(&region->unTypeData.rf.vnode->mapping.list_lock, intSave);
return oldPage;
}
@ -197,11 +201,11 @@ status_t OsDoCowFault(LosVmMapRegion *region, LosVmPgFault *vmPgFault)
newPaddr = VM_PAGE_TO_PHYS(newPage);
kvaddr = OsVmPageToVaddr(newPage);
(VOID)LOS_MuxAcquire(&region->unTypeData.rf.file->f_mapping->mux_lock);
(VOID)LOS_MuxAcquire(&region->unTypeData.rf.vnode->mapping.mux_lock);
ret = region->unTypeData.rf.vmFOps->fault(region, vmPgFault);
if (ret != LOS_OK) {
VM_ERR("call region->vm_ops->fault fail");
(VOID)LOS_MuxRelease(&region->unTypeData.rf.file->f_mapping->mux_lock);
(VOID)LOS_MuxRelease(&region->unTypeData.rf.vnode->mapping.mux_lock);
goto ERR_OUT;
}
@ -227,10 +231,10 @@ status_t OsDoCowFault(LosVmMapRegion *region, LosVmPgFault *vmPgFault)
if (ret < 0) {
VM_ERR("LOS_ArchMmuMap failed");
ret = LOS_ERRNO_VM_NO_MEMORY;
(VOID)LOS_MuxRelease(&region->unTypeData.rf.file->f_mapping->mux_lock);
(VOID)LOS_MuxRelease(&region->unTypeData.rf.vnode->mapping.mux_lock);
goto ERR_OUT;
}
(VOID)LOS_MuxRelease(&region->unTypeData.rf.file->f_mapping->mux_lock);
(VOID)LOS_MuxRelease(&region->unTypeData.rf.vnode->mapping.mux_lock);
if (oldPage != NULL) {
OsCleanPageLocked(oldPage);
@ -273,17 +277,17 @@ status_t OsDoSharedFault(LosVmMapRegion *region, LosVmPgFault *vmPgFault)
return LOS_ERRNO_VM_NO_MEMORY;
}
LOS_SpinLockSave(&region->unTypeData.rf.file->f_mapping->list_lock, &intSave);
fpage = OsFindGetEntry(region->unTypeData.rf.file->f_mapping, vmPgFault->pgoff);
LOS_SpinLockSave(&region->unTypeData.rf.vnode->mapping.list_lock, &intSave);
fpage = OsFindGetEntry(&region->unTypeData.rf.vnode->mapping, vmPgFault->pgoff);
if (fpage) {
OsMarkPageDirty(fpage, region, 0, 0);
}
LOS_SpinUnlockRestore(&region->unTypeData.rf.file->f_mapping->list_lock, intSave);
LOS_SpinUnlockRestore(&region->unTypeData.rf.vnode->mapping.list_lock, intSave);
return LOS_OK;
}
(VOID)LOS_MuxAcquire(&region->unTypeData.rf.file->f_mapping->mux_lock);
(VOID)LOS_MuxAcquire(&region->unTypeData.rf.vnode->mapping.mux_lock);
ret = region->unTypeData.rf.vmFOps->fault(region, vmPgFault);
if (ret == LOS_OK) {
paddr = LOS_PaddrQuery(vmPgFault->pageKVaddr);
@ -297,14 +301,14 @@ status_t OsDoSharedFault(LosVmMapRegion *region, LosVmPgFault *vmPgFault)
if (ret < 0) {
VM_ERR("LOS_ArchMmuMap failed. ret=%d", ret);
OsDelMapInfo(region, vmPgFault, TRUE);
(VOID)LOS_MuxRelease(&region->unTypeData.rf.file->f_mapping->mux_lock);
(VOID)LOS_MuxRelease(&region->unTypeData.rf.vnode->mapping.mux_lock);
return LOS_ERRNO_VM_NO_MEMORY;
}
(VOID)LOS_MuxRelease(&region->unTypeData.rf.file->f_mapping->mux_lock);
(VOID)LOS_MuxRelease(&region->unTypeData.rf.vnode->mapping.mux_lock);
return LOS_OK;
}
(VOID)LOS_MuxRelease(&region->unTypeData.rf.file->f_mapping->mux_lock);
(VOID)LOS_MuxRelease(&region->unTypeData.rf.vnode->mapping.mux_lock);
return ret;
}
@ -382,7 +386,7 @@ STATUS_T OsVmPageFaultHandler(VADDR_T vaddr, UINT32 flags, ExcContext *frame)
vaddr = ROUNDDOWN(vaddr, PAGE_SIZE);
#ifdef LOSCFG_FS_VFS
if (LOS_IsRegionFileValid(region)) {
if (region->unTypeData.rf.file->f_mapping == NULL) {
if (region->unTypeData.rf.vnode == NULL) {
goto CHECK_FAILED;
}
vmPgFault.vaddr = vaddr;

View File

@ -172,17 +172,17 @@ VOID OsVmmFileRemove(LosVmMapRegion *region, LosArchMmu *archMmu, VM_OFFSET_T pg
UINT32 intSave;
vaddr_t vaddr;
paddr_t paddr = 0;
struct file *file = NULL;
struct Vnode *vnode = NULL;
struct page_mapping *mapping = NULL;
LosFilePage *fpage = NULL;
LosFilePage *tmpPage = NULL;
LosVmPage *mapPage = NULL;
if (!LOS_IsRegionFileValid(region) || (region->unTypeData.rf.file->f_mapping == NULL)) {
if (!LOS_IsRegionFileValid(region) || (region->unTypeData.rf.vnode == NULL)) {
return;
}
file = region->unTypeData.rf.file;
mapping = file->f_mapping;
vnode = region->unTypeData.rf.vnode;
mapping = &vnode->mapping;
vaddr = region->range.base + ((UINT32)(pgoff - region->pgOff) << PAGE_SHIFT);
status_t status = LOS_ArchMmuQuery(archMmu, vaddr, &paddr, NULL);
@ -232,15 +232,15 @@ VOID OsMarkPageDirty(LosFilePage *fpage, LosVmMapRegion *region, INT32 off, INT3
}
}
STATIC UINT32 GetDirtySize(LosFilePage *fpage, struct file *file)
STATIC UINT32 GetDirtySize(LosFilePage *fpage, struct Vnode *vnode)
{
UINT32 fileSize;
UINT32 dirtyBegin;
UINT32 dirtyEnd;
struct stat buf_stat;
if (stat(file->f_path, &buf_stat) != OK) {
VM_ERR("FlushDirtyPage get file size failed. (filepath=%s)", file->f_path);
if (stat(vnode->filePath, &buf_stat) != OK) {
VM_ERR("FlushDirtyPage get file size failed. (filePath=%s)", vnode->filePath);
return 0;
}
@ -264,31 +264,29 @@ STATIC INT32 OsFlushDirtyPage(LosFilePage *fpage)
UINT32 ret;
size_t len;
char *buff = NULL;
VM_OFFSET_T oldPos;
struct file *file = fpage->mapping->host;
if ((file == NULL) || (file->f_vnode == NULL)) {
VM_ERR("page cache file error");
struct Vnode *vnode = fpage->mapping->host;
if (vnode == NULL) {
VM_ERR("page cache vnode error");
return LOS_NOK;
}
oldPos = file_seek(file, 0, SEEK_CUR);
buff = (char *)OsVmPageToVaddr(fpage->vmPage);
file_seek(file, (((UINT32)fpage->pgoff << PAGE_SHIFT) + fpage->dirtyOff), SEEK_SET);
len = fpage->dirtyEnd - fpage->dirtyOff;
len = (len == 0) ? GetDirtySize(fpage, file) : len;
len = (len == 0) ? GetDirtySize(fpage, vnode) : len;
if (len == 0) {
OsCleanPageDirty(fpage->vmPage);
(VOID)file_seek(file, oldPos, SEEK_SET);
return LOS_OK;
}
ret = file_write(file, (VOID *)buff, len);
buff = (char *)OsVmPageToVaddr(fpage->vmPage);
/* actually, we did not update the fpage->dirtyOff */
ret = vnode->vop->WritePage(vnode, (VOID *)buff, fpage->pgoff, len);
if (ret <= 0) {
VM_ERR("WritePage error ret %d", ret);
} else {
OsCleanPageDirty(fpage->vmPage);
}
ret = (ret <= 0) ? LOS_NOK : LOS_OK;
OsCleanPageDirty(fpage->vmPage);
(VOID)file_seek(file, oldPos, SEEK_SET);
return ret;
}
@ -336,15 +334,17 @@ VOID OsDelMapInfo(LosVmMapRegion *region, LosVmPgFault *vmf, BOOL cleanDirty)
UINT32 intSave;
LosMapInfo *info = NULL;
LosFilePage *fpage = NULL;
struct page_mapping *mapping = NULL;
if (!LOS_IsRegionFileValid(region) || (region->unTypeData.rf.file->f_mapping == NULL) || (vmf == NULL)) {
if (!LOS_IsRegionFileValid(region) || (region->unTypeData.rf.vnode == NULL) || (vmf == NULL)) {
return;
}
LOS_SpinLockSave(&region->unTypeData.rf.file->f_mapping->list_lock, &intSave);
fpage = OsFindGetEntry(region->unTypeData.rf.file->f_mapping, vmf->pgoff);
mapping = &region->unTypeData.rf.vnode->mapping;
LOS_SpinLockSave(&mapping->list_lock, &intSave);
fpage = OsFindGetEntry(mapping, vmf->pgoff);
if (fpage == NULL) {
LOS_SpinUnlockRestore(&region->unTypeData.rf.file->f_mapping->list_lock, intSave);
LOS_SpinUnlockRestore(&mapping->list_lock, intSave);
return;
}
@ -356,31 +356,30 @@ VOID OsDelMapInfo(LosVmMapRegion *region, LosVmPgFault *vmf, BOOL cleanDirty)
fpage->n_maps--;
LOS_ListDelete(&info->node);
LOS_AtomicDec(&fpage->vmPage->refCounts);
LOS_SpinUnlockRestore(&region->unTypeData.rf.file->f_mapping->list_lock, intSave);
LOS_SpinUnlockRestore(&mapping->list_lock, intSave);
LOS_MemFree(m_aucSysMem0, info);
return;
}
LOS_SpinUnlockRestore(&region->unTypeData.rf.file->f_mapping->list_lock, intSave);
LOS_SpinUnlockRestore(&mapping->list_lock, intSave);
}
INT32 OsVmmFileFault(LosVmMapRegion *region, LosVmPgFault *vmf)
{
INT32 ret;
VM_OFFSET_T oldPos;
VOID *kvaddr = NULL;
UINT32 intSave;
bool newCache = false;
struct file *file = NULL;
struct Vnode *vnode = NULL;
struct page_mapping *mapping = NULL;
LosFilePage *fpage = NULL;
if (!LOS_IsRegionFileValid(region) || (region->unTypeData.rf.file->f_mapping == NULL) || (vmf == NULL)) {
if (!LOS_IsRegionFileValid(region) || (region->unTypeData.rf.vnode == NULL) || (vmf == NULL)) {
VM_ERR("Input param is NULL");
return LOS_NOK;
}
file = region->unTypeData.rf.file;
mapping = file->f_mapping;
vnode = region->unTypeData.rf.vnode;
mapping = &vnode->mapping;
/* get or create a new cache node */
LOS_SpinLockSave(&mapping->list_lock, &intSave);
@ -404,10 +403,7 @@ INT32 OsVmmFileFault(LosVmMapRegion *region, LosVmPgFault *vmf)
/* read file to new page cache */
if (newCache) {
oldPos = file_seek(file, 0, SEEK_CUR);
file_seek(file, fpage->pgoff << PAGE_SHIFT, SEEK_SET);
ret = file_read(file, kvaddr, PAGE_SIZE);
file_seek(file, oldPos, SEEK_SET);
ret = vnode->vop->ReadPage(vnode, kvaddr, fpage->pgoff << PAGE_SHIFT);
if (ret == 0) {
VM_ERR("Failed to read from file!");
OsReleaseFpage(mapping, fpage);
@ -505,8 +501,9 @@ LosVmFileOps g_commVmOps = {
INT32 OsVfsFileMmap(struct file *filep, LosVmMapRegion *region)
{
region->unTypeData.rf.vmFOps = &g_commVmOps;
region->unTypeData.rf.file = filep;
region->unTypeData.rf.fileMagic = filep->f_magicnum;
region->unTypeData.rf.vnode = filep->f_vnode;
region->unTypeData.rf.f_oflags = filep->f_oflags;
return ENOERR;
}
@ -516,11 +513,11 @@ STATUS_T OsNamedMMap(struct file *filep, LosVmMapRegion *region)
if (filep == NULL) {
return LOS_ERRNO_VM_MAP_FAILED;
}
file_hold(filep);
vnode = filep->f_vnode;
if (vnode == NULL) {
return LOS_ERRNO_VM_MAP_FAILED;
}
VnodeHold();
vnode->useCount++;
VnodeDrop();
if (filep->ops != NULL && filep->ops->mmap != NULL) {
if (vnode->type == VNODE_TYPE_CHR || vnode->type == VNODE_TYPE_BLK) {
LOS_SetRegionTypeDev(region);
@ -529,12 +526,15 @@ STATUS_T OsNamedMMap(struct file *filep, LosVmMapRegion *region)
}
int ret = filep->ops->mmap(filep, region);
if (ret != LOS_OK) {
file_release(filep);
return LOS_ERRNO_VM_MAP_FAILED;
}
} else {
VM_ERR("mmap file type unknown");
file_release(filep);
return LOS_ERRNO_VM_MAP_FAILED;
}
file_release(filep);
return LOS_OK;
}
@ -600,40 +600,7 @@ LosFilePage *OsPageCacheAlloc(struct page_mapping *mapping, VM_OFFSET_T pgoff)
return fpage;
}
#ifdef LOSCFG_FS_VFS
VOID OsVmmFileRegionFree(struct file *filep, LosProcessCB *processCB)
{
int ret;
LosVmSpace *space = NULL;
LosVmMapRegion *region = NULL;
LosRbNode *pstRbNode = NULL;
LosRbNode *pstRbNodeTmp = NULL;
if (processCB == NULL) {
processCB = OsCurrProcessGet();
}
space = processCB->vmSpace;
if (space != NULL) {
(VOID)LOS_MuxAcquire(&space->regionMux);
/* free the regions associated with filep */
RB_SCAN_SAFE(&space->regionRbTree, pstRbNode, pstRbNodeTmp)
region = (LosVmMapRegion *)pstRbNode;
if (LOS_IsRegionFileValid(region)) {
if (region->unTypeData.rf.file != filep) {
continue;
}
ret = LOS_RegionFree(space, region);
if (ret != LOS_OK) {
VM_ERR("free region error, space %p, region %p", space, region);
}
}
RB_SCAN_SAFE_END(&space->regionRbTree, pstRbNode, pstRbNodeTmp)
(VOID)LOS_MuxRelease(&space->regionMux);
}
}
#endif
#else
#ifndef LOSCFG_FS_VFS
INT32 OsVfsFileMmap(struct file *filep, LosVmMapRegion *region)
{
UNUSED(filep);
@ -642,3 +609,4 @@ INT32 OsVfsFileMmap(struct file *filep, LosVmMapRegion *region)
}
#endif
#endif

View File

@ -42,6 +42,7 @@
#include "los_process_pri.h"
#ifdef LOSCFG_FS_VFS
#include "fs/file.h"
#include "vnode.h"
#endif
#include "los_task.h"
#include "los_memory_pri.h"
@ -308,12 +309,12 @@ STATUS_T LOS_VmSpaceClone(LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace)
#ifdef LOSCFG_FS_VFS
if (LOS_IsRegionFileValid(oldRegion)) {
LosFilePage *fpage = NULL;
LOS_SpinLockSave(&oldRegion->unTypeData.rf.file->f_mapping->list_lock, &intSave);
fpage = OsFindGetEntry(oldRegion->unTypeData.rf.file->f_mapping, newRegion->pgOff + i);
LOS_SpinLockSave(&oldRegion->unTypeData.rf.vnode->mapping.list_lock, &intSave);
fpage = OsFindGetEntry(&oldRegion->unTypeData.rf.vnode->mapping, newRegion->pgOff + i);
if ((fpage != NULL) && (fpage->vmPage == page)) { /* cow page no need map */
OsAddMapInfo(fpage, &newVmSpace->archMmu, vaddr);
}
LOS_SpinUnlockRestore(&oldRegion->unTypeData.rf.file->f_mapping->list_lock, intSave);
LOS_SpinUnlockRestore(&oldRegion->unTypeData.rf.vnode->mapping.list_lock, intSave);
}
#endif
}
@ -436,13 +437,9 @@ VADDR_T OsAllocSpecificRange(LosVmSpace *vmSpace, VADDR_T vaddr, size_t len, UIN
BOOL LOS_IsRegionFileValid(LosVmMapRegion *region)
{
struct file *filep = NULL;
if ((region != NULL) && (LOS_IsRegionTypeFile(region)) &&
(region->unTypeData.rf.file != NULL)) {
filep = region->unTypeData.rf.file;
if (region->unTypeData.rf.fileMagic == filep->f_magicnum) {
return TRUE;
}
(region->unTypeData.rf.vnode != NULL)) {
return TRUE;
}
return FALSE;
}
@ -465,6 +462,7 @@ LosVmMapRegion *OsCreateRegion(VADDR_T vaddr, size_t len, UINT32 regionFlags, un
return region;
}
memset_s(region, sizeof(LosVmMapRegion), 0, sizeof(LosVmMapRegion));
region->range.base = vaddr;
region->range.size = len;
region->pgOff = offset;
@ -624,6 +622,9 @@ STATUS_T LOS_RegionFree(LosVmSpace *space, LosVmMapRegion *region)
#ifdef LOSCFG_FS_VFS
if (LOS_IsRegionFileValid(region)) {
OsFilePagesRemove(space, region);
VnodeHold();
region->unTypeData.rf.vnode->useCount--;
VnodeDrop();
} else
#endif
@ -675,8 +676,11 @@ LosVmMapRegion *OsVmRegionDup(LosVmSpace *space, LosVmMapRegion *oldRegion, VADD
#ifdef LOSCFG_FS_VFS
if (LOS_IsRegionTypeFile(oldRegion)) {
newRegion->unTypeData.rf.vmFOps = oldRegion->unTypeData.rf.vmFOps;
newRegion->unTypeData.rf.file = oldRegion->unTypeData.rf.file;
newRegion->unTypeData.rf.fileMagic = oldRegion->unTypeData.rf.fileMagic;
newRegion->unTypeData.rf.vnode = oldRegion->unTypeData.rf.vnode;
newRegion->unTypeData.rf.f_oflags = oldRegion->unTypeData.rf.f_oflags;
VnodeHold();
newRegion->unTypeData.rf.vnode->useCount++;
VnodeDrop();
}
#endif
@ -840,13 +844,47 @@ ERR_REGION_SPLIT:
return status;
}
STATUS_T LOS_VmSpaceFree(LosVmSpace *space)
STATIC VOID OsVmSpaceAllRegionFree(LosVmSpace *space)
{
LosVmMapRegion *region = NULL;
LosRbNode *pstRbNode = NULL;
LosRbNode *pstRbNodeNext = NULL;
STATUS_T ret;
/* free all of the regions */
RB_SCAN_SAFE(&space->regionRbTree, pstRbNode, pstRbNodeNext)
LosVmMapRegion *region = (LosVmMapRegion *)pstRbNode;
if (region->range.size == 0) {
VM_ERR("space free, region: %#x flags: %#x, base:%#x, size: %#x",
region, region->regionFlags, region->range.base, region->range.size);
}
STATUS_T ret = LOS_RegionFree(space, region);
if (ret != LOS_OK) {
VM_ERR("free region error, space %p, region %p", space, region);
}
RB_SCAN_SAFE_END(&space->regionRbTree, pstRbNode, pstRbNodeNext)
return;
}
STATUS_T OsVmSpaceRegionFree(LosVmSpace *space)
{
if (space == NULL) {
return LOS_ERRNO_VM_INVALID_ARGS;
}
if (space == &g_kVmSpace) {
VM_ERR("try to free kernel aspace, not allowed");
return LOS_OK;
}
(VOID)LOS_MuxAcquire(&space->regionMux);
OsVmSpaceAllRegionFree(space);
(VOID)LOS_MuxRelease(&space->regionMux);
return LOS_OK;
}
STATUS_T LOS_VmSpaceFree(LosVmSpace *space)
{
if (space == NULL) {
return LOS_ERRNO_VM_INVALID_ARGS;
}
@ -858,19 +896,10 @@ STATUS_T LOS_VmSpaceFree(LosVmSpace *space)
/* pop it out of the global aspace list */
(VOID)LOS_MuxAcquire(&space->regionMux);
LOS_ListDelete(&space->node);
/* free all of the regions */
RB_SCAN_SAFE(&space->regionRbTree, pstRbNode, pstRbNodeNext)
region = (LosVmMapRegion *)pstRbNode;
if (region->range.size == 0) {
VM_ERR("space free, region: %#x flags: %#x, base:%#x, size: %#x",
region, region->regionFlags, region->range.base, region->range.size);
}
ret = LOS_RegionFree(space, region);
if (ret != LOS_OK) {
VM_ERR("free region error, space %p, region %p", space, region);
}
RB_SCAN_SAFE_END(&space->regionRbTree, pstRbNode, pstRbNodeNext)
OsVmSpaceAllRegionFree(space);
/* make sure the current thread does not map the aspace */
LosProcessCB *currentProcess = OsCurrProcessGet();
@ -1181,5 +1210,3 @@ VOID LOS_KernelFree(VOID *ptr)
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, ptr);
}
}

View File

@ -163,7 +163,7 @@ STATIC VOID OsVmPhysFreeListAdd(LosVmPage *page, UINT8 order)
struct VmFreeList *list = NULL;
if (page->segID >= VM_PHYS_SEG_MAX) {
LOS_Panic("The page segment id(%d) is invalid\n", page->segID);
LOS_Panic("The page segment id(%u) is invalid\n", page->segID);
}
page->order = order;
@ -180,7 +180,7 @@ STATIC VOID OsVmPhysFreeListAddUnsafe(LosVmPage *page, UINT8 order)
struct VmFreeList *list = NULL;
if (page->segID >= VM_PHYS_SEG_MAX) {
LOS_Panic("The page segment id(%d) is invalid\n", page->segID);
LOS_Panic("The page segment id(%u) is invalid\n", page->segID);
}
page->order = order;
@ -242,7 +242,7 @@ LosVmPage *OsVmPhysToPage(paddr_t pa, UINT8 segID)
paddr_t offset;
if (segID >= VM_PHYS_SEG_MAX) {
LOS_Panic("The page segment id(%d) is invalid\n", segID);
LOS_Panic("The page segment id(%u) is invalid\n", segID);
}
seg = &g_vmPhysSeg[segID];
if ((pa < seg->start) || (pa >= (seg->start + seg->size))) {
@ -479,16 +479,6 @@ VOID LOS_PhysPagesFreeContiguous(VOID *ptr, size_t nPages)
VADDR_T *LOS_PaddrToKVaddr(PADDR_T paddr)
{
struct VmPhysSeg *seg = NULL;
UINT32 segID;
for (segID = 0; segID < g_vmPhysSegNum; segID++) {
seg = &g_vmPhysSeg[segID];
if ((paddr >= seg->start) && (paddr < (seg->start + seg->size))) {
return (VADDR_T *)(UINTPTR)(paddr - SYS_MEM_BASE + KERNEL_ASPACE_BASE);
}
}
return (VADDR_T *)(UINTPTR)(paddr - SYS_MEM_BASE + KERNEL_ASPACE_BASE);
}

View File

@ -177,7 +177,7 @@ STATIC INLINE BOOL OsProtMprotectPermCheck(unsigned long prot, LosVmMapRegion *r
{
UINT32 protFlags = 0;
UINT32 permFlags = 0;
UINT32 fileFlags = (((region->unTypeData).rf).file)->f_oflags;
UINT32 fileFlags = region->unTypeData.rf.f_oflags;
permFlags |= ((fileFlags & O_ACCMODE) ^ O_RDONLY) ? 0 : VM_MAP_REGION_FLAG_PERM_READ;
permFlags |= (fileFlags & O_WRONLY) ? VM_MAP_REGION_FLAG_PERM_WRITE : 0;
permFlags |= (fileFlags & O_RDWR) ? (VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE) : 0;
@ -220,7 +220,7 @@ VOID *LOS_DoBrk(VOID *addr)
size = (UINTPTR)addr - (UINTPTR)space->heapBase;
size = ROUNDUP(size, PAGE_SIZE);
alignAddr = (CHAR *)(UINTPTR)(space->heapBase) + size;
PRINT_INFO("brk addr %p , size 0x%x, alignAddr %p, align %d\n", addr, size, alignAddr, PAGE_SIZE);
PRINT_INFO("brk addr %p , size 0x%x, alignAddr %p, align %u\n", addr, size, alignAddr, PAGE_SIZE);
(VOID)LOS_MuxAcquire(&space->regionMux);
if (addr < (VOID *)(UINTPTR)space->heapNow) {

View File

@ -210,10 +210,10 @@ LITE_OS_SEC_TEXT_MINOR VOID OomSetCheckInterval(UINT32 checkInterval)
{
if ((checkInterval >= OOM_CHECK_MIN) && (checkInterval <= OOM_CHECK_MAX)) {
g_oomCB->checkInterval = checkInterval;
PRINTK("[oom] set oom check interval (%d)ms successful\n",
PRINTK("[oom] set oom check interval (%u)ms successful\n",
g_oomCB->checkInterval);
} else {
PRINTK("[oom] set oom check interval (%d)ms failed, should be in [%d, %d]\n",
PRINTK("[oom] set oom check interval (%u)ms failed, should be in [%d, %d]\n",
g_oomCB->checkInterval, OOM_CHECK_MIN, OOM_CHECK_MAX);
}
}

View File

@ -304,7 +304,7 @@ STATIC struct shmIDSource *ShmFindSeg(int shmid)
}
seg = &g_shmSegs[shmid];
if ((seg->status & SHM_SEG_FREE) || (seg->status & SHM_SEG_REMOVE)) {
if ((seg->status & SHM_SEG_FREE) || ((seg->ds.shm_nattch == 0) && (seg->status & SHM_SEG_REMOVE))) {
set_errno(EIDRM);
return NULL;
}

View File

@ -43,7 +43,8 @@
/* ------------ local macroes ------------ */
#ifdef LOSCFG_FS_VFS
#define BBOX_DIR_MODE 0777
#define BBOX_DIR_MODE 0750
#define BBOX_FILE_MODE 0640
#endif
/* ------------ local prototypes ------------ */
@ -69,7 +70,7 @@ int FullWriteFile(const char *filePath, const char *buf, size_t bufSize, int isA
BBOX_PRINT_ERR("log path [%s] isn't ready to be written!\n", LOSCFG_BLACKBOX_LOG_ROOT_PATH);
return -1;
}
fd = open(filePath, O_CREAT | O_RDWR | (isAppend ? O_APPEND : O_TRUNC), 0644);
fd = open(filePath, O_CREAT | O_RDWR | (isAppend ? O_APPEND : O_TRUNC), BBOX_FILE_MODE);
if (fd < 0) {
BBOX_PRINT_ERR("Create file [%s] failed, fd: %d!\n", filePath, fd);
return -1;
@ -216,4 +217,4 @@ int CreateLogDir(const char *dirPath)
(void)dirPath;
return -1;
}
#endif
#endif

View File

@ -214,7 +214,7 @@ UINT64 LOS_SizeStrToNum(CHAR *value)
UINT64 num = 0;
/* If the string is a hexadecimal value */
if (sscanf_s(value, "0x%x", &num) > 0) {
if (sscanf_s(value, "0x%x", (UINTPTR)(&num)) > 0) {
value += strlen("0x");
if (strspn(value, "0123456789abcdefABCDEF") < strlen(value)) {
goto ERROUT;
@ -223,7 +223,7 @@ UINT64 LOS_SizeStrToNum(CHAR *value)
}
/* If the string is a decimal value in unit *Bytes */
INT32 ret = sscanf_s(value, "%d", &num);
INT32 ret = sscanf_s(value, "%llu", &num);
INT32 decOffset = strspn(value, "0123456789");
CHAR *endPos = value + decOffset;
if ((ret <= 0) || (decOffset < (strlen(value) - 1))) {

View File

@ -89,7 +89,7 @@ typedef struct {
LD_ELF_EHDR elfEhdr;
LD_ELF_PHDR *elfPhdr;
UINT32 fileLen;
INT32 fd;
INT32 procfd;
} ELFInfo;
typedef struct {

View File

@ -68,6 +68,24 @@ static int OsELFOpen(const CHAR *fileName, INT32 oflags)
}
AssociateSystemFd(procFd, ret);
return procFd;
}
static int OsELFClose(int procFd)
{
int ret;
/* Process procfd convert to system global procfd */
int sysfd = DisassociateProcessFd(procFd);
if (sysfd < 0) {
return -EBADF;
}
ret = close(sysfd);
if (ret < 0) {
AssociateSystemFd(procFd, sysfd);
return -get_errno();
}
FreeProcessFd(procFd);
return ret;
}
@ -101,10 +119,15 @@ STATIC INT32 OsGetFileLength(UINT32 *fileLen, const CHAR *fileName)
return LOS_OK;
}
STATIC INT32 OsReadELFInfo(INT32 fd, UINT8 *buffer, size_t readSize, off_t offset)
STATIC INT32 OsReadELFInfo(INT32 procfd, UINT8 *buffer, size_t readSize, off_t offset)
{
ssize_t byteNum;
off_t returnPos;
INT32 fd = GetAssociatedSystemFd(procfd);
if (fd < 0) {
PRINT_ERR("%s[%d], Invalid procfd!\n", __FUNCTION__, __LINE__);
return LOS_NOK;
}
if (readSize > 0) {
returnPos = lseek(fd, offset, SEEK_SET);
@ -178,8 +201,8 @@ STATIC VOID OsLoadInit(ELFLoadInfo *loadInfo)
#else
loadInfo->oldFiles = NULL;
#endif
loadInfo->execInfo.fd = INVALID_FD;
loadInfo->interpInfo.fd = INVALID_FD;
loadInfo->execInfo.procfd = INVALID_FD;
loadInfo->interpInfo.procfd = INVALID_FD;
}
STATIC INT32 OsReadEhdr(const CHAR *fileName, ELFInfo *elfInfo, BOOL isExecFile)
@ -196,17 +219,21 @@ STATIC INT32 OsReadEhdr(const CHAR *fileName, ELFInfo *elfInfo, BOOL isExecFile)
PRINT_ERR("%s[%d], Failed to open ELF file: %s!\n", __FUNCTION__, __LINE__, fileName);
return ret;
}
elfInfo->fd = ret;
elfInfo->procfd = ret;
#ifdef LOSCFG_DRIVERS_TZDRIVER
if (isExecFile) {
ret = fs_getfilep(elfInfo->fd, &OsCurrProcessGet()->execFile);
struct file *filep;
ret = fs_getfilep(GetAssociatedSystemFd(elfInfo->procfd), &filep);
if (ret) {
PRINT_ERR("%s[%d], Failed to get struct file %s!\n", __FUNCTION__, __LINE__, fileName);
/* File will be closed by OsLoadELFFile */
return ret;
}
OsCurrProcessGet()->execVnode = filep->f_vnode;
}
#endif
ret = OsReadELFInfo(elfInfo->fd, (UINT8 *)&elfInfo->elfEhdr, sizeof(LD_ELF_EHDR), 0);
ret = OsReadELFInfo(elfInfo->procfd, (UINT8 *)&elfInfo->elfEhdr, sizeof(LD_ELF_EHDR), 0);
if (ret != LOS_OK) {
PRINT_ERR("%s[%d]\n", __FUNCTION__, __LINE__);
return -EIO;
@ -246,7 +273,7 @@ STATIC INT32 OsReadPhdrs(ELFInfo *elfInfo, BOOL isExecFile)
return -ENOMEM;
}
ret = OsReadELFInfo(elfInfo->fd, (UINT8 *)elfInfo->elfPhdr, size, elfEhdr->elfPhoff);
ret = OsReadELFInfo(elfInfo->procfd, (UINT8 *)elfInfo->elfPhdr, size, elfEhdr->elfPhoff);
if (ret != LOS_OK) {
(VOID)LOS_MemFree(m_aucSysMem0, elfInfo->elfPhdr);
elfInfo->elfPhdr = NULL;
@ -287,7 +314,7 @@ STATIC INT32 OsReadInterpInfo(ELFLoadInfo *loadInfo)
return -ENOMEM;
}
ret = OsReadELFInfo(loadInfo->execInfo.fd, (UINT8 *)elfInterpName, elfPhdr->fileSize, elfPhdr->offset);
ret = OsReadELFInfo(loadInfo->execInfo.procfd, (UINT8 *)elfInterpName, elfPhdr->fileSize, elfPhdr->offset);
if (ret != LOS_OK) {
PRINT_ERR("%s[%d]\n", __FUNCTION__, __LINE__);
ret = -EIO;
@ -397,7 +424,7 @@ INT32 OsGetKernelVaddr(const LosVmSpace *space, VADDR_T vaddr, VADDR_T *kvaddr)
PADDR_T paddr = 0;
if ((space == NULL) || (vaddr == 0) || (kvaddr == NULL)) {
PRINT_ERR("%s[%d], space: %#x, vaddr: %#x\n", __FUNCTION__, __LINE__, space, vaddr);
PRINT_ERR("%s[%d], space: %#x, vaddr: %#x\n", __FUNCTION__, __LINE__, (UINTPTR)space, vaddr);
return LOS_NOK;
}
@ -450,13 +477,14 @@ STATIC INT32 OsSetBss(const LD_ELF_PHDR *elfPhdr, INT32 fd, UINTPTR bssStart, UI
return LOS_OK;
}
STATIC INT32 OsMmapELFFile(INT32 fd, const LD_ELF_PHDR *elfPhdr, const LD_ELF_EHDR *elfEhdr, UINTPTR *elfLoadAddr,
STATIC INT32 OsMmapELFFile(INT32 procfd, const LD_ELF_PHDR *elfPhdr, const LD_ELF_EHDR *elfEhdr, UINTPTR *elfLoadAddr,
UINT32 mapSize, UINTPTR *loadBase)
{
const LD_ELF_PHDR *elfPhdrTemp = elfPhdr;
UINTPTR vAddr, mapAddr, bssStart;
UINT32 bssEnd, elfProt, elfFlags;
INT32 ret, i;
INT32 fd = GetAssociatedSystemFd(procfd);
for (i = 0; i < elfEhdr->elfPhNum; ++i, ++elfPhdrTemp) {
if (elfPhdrTemp->type != LD_PT_LOAD) {
@ -510,7 +538,7 @@ STATIC INT32 OsMmapELFFile(INT32 fd, const LD_ELF_PHDR *elfPhdr, const LD_ELF_EH
return LOS_OK;
}
STATIC INT32 OsLoadInterpBinary(const ELFLoadInfo *loadInfo, UINTPTR *interpMapBase)
STATIC INT32 OsLoadInterpBinary(ELFLoadInfo *loadInfo, UINTPTR *interpMapBase)
{
UINTPTR loadBase = 0;
UINT32 mapSize;
@ -522,14 +550,13 @@ STATIC INT32 OsLoadInterpBinary(const ELFLoadInfo *loadInfo, UINTPTR *interpMapB
return -EINVAL;
}
ret = OsMmapELFFile(loadInfo->interpInfo.fd, loadInfo->interpInfo.elfPhdr, &loadInfo->interpInfo.elfEhdr,
ret = OsMmapELFFile(loadInfo->interpInfo.procfd, loadInfo->interpInfo.elfPhdr, &loadInfo->interpInfo.elfEhdr,
interpMapBase, mapSize, &loadBase);
if (ret != LOS_OK) {
PRINT_ERR("%s[%d]\n", __FUNCTION__, __LINE__);
return ret;
}
return LOS_OK;
return ret;
}
STATIC CHAR *OsGetParamPtr(CHAR * const *ptr, INT32 index)
@ -546,7 +573,7 @@ STATIC CHAR *OsGetParamPtr(CHAR * const *ptr, INT32 index)
}
ret = LOS_GetUser(&userStrPtr, (UINTPTR *)(ptr + index));
if (ret != LOS_OK) {
PRINT_ERR("%s[%d], %#x\n", __FUNCTION__, __LINE__, ptr);
PRINT_ERR("%s[%d], %#x\n", __FUNCTION__, __LINE__, (UINTPTR)ptr);
return NULL;
}
@ -841,7 +868,7 @@ STATIC INT32 OsPutParamToStack(ELFLoadInfo *loadInfo, const UINTPTR *auxVecInfo,
size = LOS_ArchCopyToUser(argsPtr, auxVecInfo, vecIndex * sizeof(UINTPTR));
if (size != 0) {
PRINT_ERR("%s[%d], Failed to copy strings! Bytes not copied: %d\n", __FUNCTION__, __LINE__, size);
PRINT_ERR("%s[%d], Failed to copy strings! Bytes not copied: %u\n", __FUNCTION__, __LINE__, size);
return -EFAULT;
}
@ -911,15 +938,19 @@ STATIC INT32 OsLoadELFSegment(ELFLoadInfo *loadInfo)
}
}
ret = OsMmapELFFile(loadInfo->execInfo.fd, loadInfo->execInfo.elfPhdr, &loadInfo->execInfo.elfEhdr,
ret = OsMmapELFFile(loadInfo->execInfo.procfd, loadInfo->execInfo.elfPhdr, &loadInfo->execInfo.elfEhdr,
&loadInfo->loadAddr, mapSize, &loadBase);
OsELFClose(loadInfo->execInfo.procfd);
loadInfo->execInfo.procfd = INVALID_FD;
if (ret != LOS_OK) {
PRINT_ERR("%s[%d]\n", __FUNCTION__, __LINE__);
return ret;
}
if (loadInfo->interpInfo.fd != INVALID_FD) {
if (loadInfo->interpInfo.procfd != INVALID_FD) {
ret = OsLoadInterpBinary(loadInfo, &interpMapBase);
OsELFClose(loadInfo->interpInfo.procfd);
loadInfo->interpInfo.procfd = INVALID_FD;
if (ret != LOS_OK) {
return ret;
}
@ -974,12 +1005,12 @@ STATIC VOID OsDeInitLoadInfo(ELFLoadInfo *loadInfo)
STATIC VOID OsDeInitFiles(ELFLoadInfo *loadInfo)
{
if (loadInfo->execInfo.fd != INVALID_FD) {
(VOID)close(loadInfo->execInfo.fd);
if (loadInfo->execInfo.procfd != INVALID_FD) {
(VOID)OsELFClose(loadInfo->execInfo.procfd);
}
if (loadInfo->interpInfo.fd != INVALID_FD) {
(VOID)close(loadInfo->interpInfo.fd);
if (loadInfo->interpInfo.procfd != INVALID_FD) {
(VOID)OsELFClose(loadInfo->interpInfo.procfd);
}
#ifdef LOSCFG_FS_VFS
delete_files_snapshot((struct files_struct *)loadInfo->oldFiles);

View File

@ -111,7 +111,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsLiteIpcInit(VOID)
}
ret = (UINT32)register_driver(LITEIPC_DRIVER, &g_liteIpcFops, LITEIPC_DRIVER_MODE, NULL);
if (ret != LOS_OK) {
PRINT_ERR("register lite_ipc driver failed:%d\n", ret);
PRINT_ERR("register lite_ipc driver failed:%u\n", ret);
}
LOS_ListInit(&(g_ipcPendlist));
for (i = 0; i < LOSCFG_BASE_CORE_PROCESS_LIMIT; i++) {
@ -254,11 +254,10 @@ LITE_OS_SEC_TEXT UINT32 LiteIpcPoolReInit(ProcIpcInfo *child, const ProcIpcInfo
return LOS_OK;
}
LITE_OS_SEC_TEXT VOID LiteIpcPoolDelete(ProcIpcInfo *ipcInfo)
LITE_OS_SEC_TEXT VOID LiteIpcPoolDelete(ProcIpcInfo *ipcInfo, UINT32 processID)
{
UINT32 intSave;
IpcUsedNode *node = NULL;
UINT32 processID = LOS_GetCurrProcessID();
if (ipcInfo->pool.kvaddr != NULL) {
LOS_VFree(ipcInfo->pool.kvaddr);
ipcInfo->pool.kvaddr = NULL;
@ -295,15 +294,15 @@ LITE_OS_SEC_TEXT STATIC VOID EnableIpcNodeFreeByUser(UINT32 processID, VOID *buf
LITE_OS_SEC_TEXT STATIC VOID *LiteIpcNodeAlloc(UINT32 processID, UINT32 size)
{
VOID *ptr = LOS_MemAlloc(OS_PCB_FROM_PID(processID)->ipcInfo.pool.kvaddr, size);
PRINT_INFO("LiteIpcNodeAlloc pid:%d, pool:%x buf:%x size:%d\n",
processID, OS_PCB_FROM_PID(processID)->ipcInfo.pool.kvaddr, ptr, size);
PRINT_INFO("LiteIpcNodeAlloc pid:%u, pool:%x buf:%x size:%u\n",
processID, (UINTPTR)OS_PCB_FROM_PID(processID)->ipcInfo.pool.kvaddr, (UINTPTR)ptr, size);
return ptr;
}
LITE_OS_SEC_TEXT STATIC UINT32 LiteIpcNodeFree(UINT32 processID, VOID *buf)
{
PRINT_INFO("LiteIpcNodeFree pid:%d, pool:%x buf:%x\n",
processID, OS_PCB_FROM_PID(processID)->ipcInfo.pool.kvaddr, buf);
PRINT_INFO("LiteIpcNodeFree pid:%u, pool:%x buf:%x\n",
processID, (UINTPTR)OS_PCB_FROM_PID(processID)->ipcInfo.pool.kvaddr, (UINTPTR)buf);
return LOS_MemFree(OS_PCB_FROM_PID(processID)->ipcInfo.pool.kvaddr, buf);
}
@ -455,7 +454,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 SetIpcTask(VOID)
OsCurrProcessGet()->ipcInfo.ipcTaskID = LOS_CurTaskIDGet();
return OsCurrProcessGet()->ipcInfo.ipcTaskID;
}
PRINT_ERR("curprocess %d IpcTask already set!\n", OsCurrProcessGet()->processID);
PRINT_ERR("curprocess %u IpcTask already set!\n", OsCurrProcessGet()->processID);
return -EINVAL;
}
@ -812,7 +811,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 CopyDataFromUser(IpcListNode *node, UINT32 bufSz,
node->msg.offsets = (VOID *)((UINTPTR)node + sizeof(IpcListNode) + msg->dataSz);
ret = copy_from_user((VOID *)(node->msg.offsets), msg->offsets, msg->spObjNum * sizeof(UINT32));
if (ret != LOS_OK) {
PRINT_DEBUG("%s, %d, %x, %x, %d\n", __FUNCTION__, __LINE__, node->msg.offsets, msg->offsets, msg->spObjNum);
PRINT_DEBUG("%s, %d, %x, %x, %u\n", __FUNCTION__, __LINE__, (UINTPTR)node->msg.offsets, (UINTPTR)msg->offsets, msg->spObjNum);
return ret;
}
} else {
@ -899,7 +898,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 CheckPara(IpcContent *content, UINT32 *dstTid)
#endif
OsHookCall(LOS_HOOK_TYPE_IPC_WRITE_DROP, msg, *dstTid,
(*dstTid == INVAILD_ID) ? INVAILD_ID : OS_TCB_FROM_TID(*dstTid)->processID, 0);
PRINT_ERR("A timeout reply, request timestamp:%lld, now:%lld\n", msg->timestamp, now);
PRINT_ERR("A timeout reply, request timestamp:%llu, now:%llu\n", msg->timestamp, now);
return -ETIME;
}
#endif
@ -1091,7 +1090,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 LiteIpcMsgHandle(IpcContent *con)
if ((content->flag & BUFF_FREE) == BUFF_FREE) {
ret = CheckUsedBuffer(content->buffToFree, &nodeNeedFree);
if (ret != LOS_OK) {
PRINT_ERR("CheckUsedBuffer failed:%d\n", ret);
PRINT_ERR("CheckUsedBuffer failed:%u\n", ret);
return ret;
}
}
@ -1137,7 +1136,7 @@ BUFFER_FREE:
UINT32 offset = LOS_OFF_SET_OF(IpcContent, inMsg);
ret = copy_to_user((char*)con + offset, (char*)content + offset, sizeof(IpcMsg *));
if (ret != LOS_OK) {
PRINT_ERR("%s, %d, %d\n", __FUNCTION__, __LINE__, ret);
PRINT_ERR("%s, %d, %u\n", __FUNCTION__, __LINE__, ret);
return -EINVAL;
}
}
@ -1198,15 +1197,15 @@ LITE_OS_SEC_TEXT int LiteIpcIoctl(struct file *filep, int cmd, unsigned long arg
}
switch (cmd) {
case IPC_SET_CMS:
return SetCms(arg);
return (INT32)SetCms(arg);
case IPC_CMS_CMD:
return HandleCmsCmd((CmsCmdContent *)(UINTPTR)arg);
return (INT32)HandleCmsCmd((CmsCmdContent *)(UINTPTR)arg);
case IPC_SET_IPC_THREAD:
if (IsCmsSet() == FALSE) {
PRINT_ERR("ServiceManager not set!\n");
return -EINVAL;
}
return SetIpcTask();
return (INT32)SetIpcTask();
case IPC_SEND_RECV_MSG:
if (arg == 0) {
return -EINVAL;
@ -1217,12 +1216,12 @@ LITE_OS_SEC_TEXT int LiteIpcIoctl(struct file *filep, int cmd, unsigned long arg
}
ret = LiteIpcMsgHandle((IpcContent *)(UINTPTR)arg);
if (ret != LOS_OK) {
return ret;
return (INT32)ret;
}
break;
default:
PRINT_ERR("Unknow liteipc ioctl cmd:%d\n", cmd);
return -EINVAL;
}
return ret;
return (INT32)ret;
}

View File

@ -184,7 +184,7 @@ extern UINT32 LiteIpcPoolInit(ProcIpcInfo *ipcInfo);
extern UINT32 LiteIpcPoolReInit(ProcIpcInfo *childIpcInfo, const ProcIpcInfo *parentIpcInfo);
/* delete process liteipc memory pool */
extern VOID LiteIpcPoolDelete(ProcIpcInfo *ipcInfo);
extern VOID LiteIpcPoolDelete(ProcIpcInfo *ipcInfo, UINT32 processID);
/* remove service handle and send death notify */
extern VOID LiteIpcRemoveServiceHandle(LosTaskCB *taskCB);

View File

@ -211,7 +211,7 @@ STATIC VOID LOS_TraceSwtmrExpired(const SWTMR_CTRL_S *swtmr)
STATIC VOID LOS_TraceSwtmrStart(const SWTMR_CTRL_S *swtmr)
{
LOS_TRACE(SWTMR_START, swtmr->usTimerID, swtmr->ucMode, swtmr->uwCount, swtmr->uwInterval, 0);
LOS_TRACE(SWTMR_START, swtmr->usTimerID, swtmr->ucMode, swtmr->uwInterval);
}
STATIC VOID LOS_TraceSwtmrStop(const SWTMR_CTRL_S *swtmr)

View File

@ -265,10 +265,15 @@ STATIC UINT32 OsTraceInit(VOID)
}
#endif
#ifdef LOSCFG_RECORDER_MODE_OFFLINE
ret = OsTraceBufInit(LOSCFG_TRACE_BUFFER_SIZE);
if (ret != LOS_OK) {
goto LOS_RELEASE;
#ifdef LOSCFG_TRACE_CONTROL_AGENT
(VOID)LOS_TaskDelete(g_traceTaskId);
#endif
goto LOS_ERREND;
}
#endif
OsTraceHookInstall();
OsTraceCnvInit();
@ -283,10 +288,6 @@ STATIC UINT32 OsTraceInit(VOID)
g_traceState = TRACE_STARTED;
#endif
return LOS_OK;
LOS_RELEASE:
#ifdef LOSCFG_TRACE_CONTROL_AGENT
LOS_TaskDelete(g_traceTaskId);
#endif
LOS_ERREND:
return ret;
}

View File

@ -120,7 +120,6 @@ typedef struct {
extern UINT32 OsTraceGetMaskTid(UINT32 taskId);
extern VOID OsTraceSetObj(ObjData *obj, const LosTaskCB *tcb);
extern VOID OsTraceWriteOrSendEvent(const TraceEventFrame *frame);
extern UINT32 OsTraceBufInit(UINT32 size);
extern VOID OsTraceObjAdd(UINT32 eventType, UINT32 taskId);
extern BOOL OsTraceIsEnable(VOID);
extern OfflineHead *OsTraceRecordGet(VOID);
@ -143,6 +142,7 @@ extern VOID OsTraceSendNotify(UINT32 type, UINT32 value);
#define OsTraceReset()
#define OsTraceRecordDump(toClient)
#else
extern UINT32 OsTraceBufInit(UINT32 size);
extern VOID OsTraceReset(VOID);
extern VOID OsTraceRecordDump(BOOL toClient);
#define OsTraceNotifyStart()

View File

@ -37,12 +37,6 @@ UINT32 OsTraceGetMaskTid(UINT32 taskId)
return taskId;
}
UINT32 OsTraceBufInit(UINT32 size)
{
(VOID)size;
return LOS_OK;
}
VOID OsTraceSendHead(VOID)
{
TraceBaseHeaderInfo head = {

View File

@ -347,7 +347,7 @@ extern TRACE_EVENT_HOOK g_traceEventHook;
#define TASK_RESUME_PARAMS(taskId, taskStatus, prio) taskId, taskStatus, prio
#define TASK_SIGNAL_PARAMS(taskId, signal, schedFlag) // taskId, signal, schedFlag
#define SWTMR_START_PARAMS(swtmrId, mode, overrun, interval, expiry) swtmrId, mode, overrun, interval, expiry
#define SWTMR_START_PARAMS(swtmrId, mode, interval) swtmrId, mode, interval
#define SWTMR_DELETE_PARAMS(swtmrId) swtmrId
#define SWTMR_EXPIRED_PARAMS(swtmrId) swtmrId
#define SWTMR_STOP_PARAMS(swtmrId) swtmrId

View File

@ -1568,7 +1568,7 @@ static void lwip_ping_usage(void)
"\n ping [-n cnt] [-w interval] [-l data_len] destination"
"\n ping [-t] [-w interval] destination"
"\n ping -k");
PRINTK("\n -t means ping forever, user can use -k to stop the forever ping");
PRINTK("\n -t means ping forever, user can use -k to stop the forever ping\n");
}
LWIP_STATIC int osPingFunc(u32_t destip, u32_t cnt, u32_t interval, u32_t data_len)

View File

@ -1174,6 +1174,25 @@ static u8_t lwip_ioctl_internal_SIOCGIFMTU(struct ifreq *ifr)
}
}
static u8_t lwip_ioctl_internal_SIOCGIFBRDADDR(struct ifreq *ifr)
{
struct netif *netif = NULL;
struct sockaddr_in *sock_in = NULL;
/* get netif subnet broadcast addr */
netif = netif_find(ifr->ifr_name);
if (netif == NULL) {
return ENODEV;
}
if (ip4_addr_isany_val(*(ip_2_ip4(&netif->netmask)))) {
return ENXIO;
}
sock_in = (struct sockaddr_in *)&ifr->ifr_addr;
sock_in->sin_family = AF_INET;
sock_in->sin_addr.s_addr = (ip_2_ip4(&((netif)->ip_addr))->addr | ~(ip_2_ip4(&netif->netmask)->addr));
return 0;
}
#endif /* LWIP_IOCTL_IF */
#if LWIP_NETIF_ETHTOOL
@ -1436,6 +1455,13 @@ static u8_t lwip_ioctl_impl(const struct lwip_sock *sock, long cmd, void *argp)
case SIOCSIFMTU:
err = lwip_ioctl_internal_SIOCSIFMTU(ifr);
break;
case SIOCGIFBRDADDR:
if (is_ipv6 != 0) {
err = EINVAL;
} else {
err = lwip_ioctl_internal_SIOCGIFBRDADDR(ifr);
}
break;
#endif /* LWIP_IOCTL_IF */
#if LWIP_NETIF_ETHTOOL
case SIOCETHTOOL:
@ -1549,6 +1575,7 @@ int socks_ioctl(int sockfd, long cmd, void *argp)
case SIOCGIFMTU:
case SIOCSIFMTU:
case SIOCETHTOOL:
case SIOCGIFBRDADDR:
nbytes = sizeof(struct ifreq);
break;
default:

View File

@ -80,3 +80,19 @@ config HRTIMER_ENABLE
help
Enable High-resolution timer support
config HILOG
tristate "Hilog support"
default y
help
hilog buffer manager.
Hilog is a simple log manager for OpenHarmonyOS.
log string write to /dev/hilog, and the hilog driver copy it
to the ring buffer. Ring buffer can be read from userspace.
config HILOG_BUFFER_SIZE
int "hilog buffer size"
default 4096
help
Define the default ring buffer size of hilog

View File

@ -67,6 +67,9 @@ STATIC SPIN_LOCK_INIT(g_consoleSpin);
#define CONSOLE_SEND_TASK_EXIT 0x04U
#define CONSOLE_SEND_TASK_RUNNING 0x10U
#define SHELL_ENTRY_NAME "ShellEntry"
#define SHELL_ENTRY_NAME_LEN 10
CONSOLE_CB *g_console[CONSOLE_NUM];
#define MIN(a, b) ((a) < (b) ? (a) : (b))
@ -436,17 +439,16 @@ STATIC VOID StoreReadChar(CONSOLE_CB *consoleCB, char ch, INT32 readcount)
}
}
VOID KillPgrp()
VOID KillPgrp(UINT16 consoleId)
{
INT32 consoleId;
LosProcessCB *process = OsCurrProcessGet();
if ((process->consoleID > CONSOLE_NUM - 1) || (process->consoleID < 0)) {
if ((consoleId > CONSOLE_NUM) || (consoleId <= 0)) {
return;
}
CONSOLE_CB *consoleCB = g_console[consoleId-1];
/* the default of consoleCB->pgrpId is -1, may not be set yet, avoid killing all processes */
if (consoleCB->pgrpId < 0) {
return;
}
consoleId = process->consoleID;
CONSOLE_CB *consoleCB = g_console[consoleId];
(VOID)OsKillLock(consoleCB->pgrpId, SIGINT);
}
@ -1044,39 +1046,24 @@ STATIC INT32 OsConsoleFileInit(CONSOLE_CB *consoleCB)
INT32 ret;
struct Vnode *vnode = NULL;
struct file *filep = NULL;
CHAR *fullpath = NULL;
ret = vfs_normalize_path(NULL, consoleCB->name, &fullpath);
if (ret < 0) {
return EINVAL;
}
VnodeHold();
ret = VnodeLookup(fullpath, &vnode, 0);
ret = VnodeLookup(consoleCB->name, &vnode, 0);
if (ret != LOS_OK) {
ret = EACCES;
goto ERROUT_WITH_FULLPATH;
goto ERROUT;
}
consoleCB->fd = files_allocate(vnode, O_RDWR, (off_t)0, consoleCB, STDERR_FILENO + 1);
if (consoleCB->fd < 0) {
filep = files_allocate(vnode, O_RDWR, 0, consoleCB, FILE_START_FD);
if (filep == NULL) {
ret = EMFILE;
goto ERROUT_WITH_FULLPATH;
goto ERROUT;
}
ret = fs_getfilep(consoleCB->fd, &filep);
if (ret < 0) {
ret = EPERM;
goto ERROUT_WITH_FULLPATH;
}
filep->f_path = fullpath;
filep->ops = (struct file_operations_vfs *)((struct drv_data *)vnode->data)->ops;
VnodeDrop();
return LOS_OK;
consoleCB->fd = filep->fd;
ERROUT_WITH_FULLPATH:
ERROUT:
VnodeDrop();
free(fullpath);
return ret;
}
@ -1458,15 +1445,31 @@ BOOL ConsoleEnable(VOID)
return FALSE;
}
BOOL IsShellEntryRunning(UINT32 shellEntryId)
{
LosTaskCB *taskCB;
if (shellEntryId == SHELL_ENTRYID_INVALID) {
return FALSE;
}
taskCB = OsGetTaskCB(shellEntryId);
return !OsTaskIsUnused(taskCB) &&
(strlen(taskCB->taskName) == SHELL_ENTRY_NAME_LEN &&
strncmp(taskCB->taskName, SHELL_ENTRY_NAME, SHELL_ENTRY_NAME_LEN) == 0);
}
INT32 ConsoleTaskReg(INT32 consoleID, UINT32 taskID)
{
if (g_console[consoleID - 1]->shellEntryId == SHELL_ENTRYID_INVALID) {
UINT32 intSave;
LOS_SpinLockSave(&g_consoleSpin, &intSave);
if (!IsShellEntryRunning(g_console[consoleID - 1]->shellEntryId)) {
g_console[consoleID - 1]->shellEntryId = taskID;
LOS_SpinUnlockRestore(&g_consoleSpin, intSave);
(VOID)OsSetCurrProcessGroupID(OsGetUserInitProcessID());
return LOS_OK;
}
return LOS_NOK;
LOS_SpinUnlockRestore(&g_consoleSpin, intSave);
return g_console[consoleID - 1]->shellEntryId == taskID ? LOS_OK : LOS_NOK;
}
BOOL SetSerialNonBlock(const CONSOLE_CB *consoleCB)

View File

@ -124,7 +124,7 @@ extern INT32 GetFilepOps(const struct file *filep, struct file **privFilep, cons
extern VOID OsWaitConsoleSendTaskPend(UINT32 taskID);
extern VOID OsWakeConsoleSendTask(VOID);
#endif
extern VOID KillPgrp(VOID);
extern VOID KillPgrp(UINT16 consoleId);
/* console ioctl */
#define CONSOLE_IOC_MAGIC 'c'

View File

@ -170,16 +170,17 @@ VOID OsRecordExcInfoTime(VOID)
#ifdef LOSCFG_SHELL
INT32 OsShellCmdReadExcInfo(INT32 argc, CHAR **argv)
{
#define EXCINFO_ALIGN_SIZE 64
UINT32 recordSpace = GetRecordSpace();
(VOID)argc;
(VOID)argv;
CHAR *buf = (CHAR*)LOS_MemAlloc((void *)OS_SYS_MEM_ADDR, recordSpace + 1);
CHAR *buf = (CHAR*)LOS_MemAllocAlign((void *)OS_SYS_MEM_ADDR, recordSpace + 1, EXCINFO_ALIGN_SIZE);
if (buf == NULL) {
return LOS_NOK;
}
(void)memset_s(buf, recordSpace + 1, 0, recordSpace + 1);
(VOID)memset_s(buf, recordSpace + 1, 0, recordSpace + 1);
log_read_write_fn hook = GetExcInfoRW();
if (hook != NULL) {

View File

@ -41,7 +41,7 @@
#include "los_vm_lock.h"
#include "user_copy.h"
#define HILOG_BUFFER 4096
#define HILOG_BUFFER LOSCFG_HILOG_BUFFER_SIZE
#define DRIVER_MODE 0666
#define HILOG_DRIVER "/dev/hilog"
@ -148,7 +148,7 @@ static int HiLogBufferCopy(unsigned char *dst, unsigned dstLen, unsigned char *s
static int HiLogReadRingBuffer(unsigned char *buffer, size_t bufLen)
{
size_t retval;
int retval;
size_t bufLeft = HILOG_BUFFER - g_hiLogDev.headOffset;
if (bufLeft > bufLen) {
retval = HiLogBufferCopy(buffer, bufLen, HiLogBufferHead(), bufLen);
@ -179,7 +179,7 @@ static ssize_t HiLogRead(struct file *filep, char *buffer, size_t bufLen)
}
if (bufLen < header.len + sizeof(header)) {
dprintf("buffer too small,bufLen=%d, header.len=%d,%d\n", bufLen, header.len, header.hdrSize);
dprintf("buffer too small,bufLen=%u, header.len=%u,%u\n", bufLen, header.len, header.hdrSize);
retval = -ENOMEM;
goto out;
}
@ -201,6 +201,13 @@ static ssize_t HiLogRead(struct file *filep, char *buffer, size_t bufLen)
HiLogBufferDec(header.len);
retval = header.len + sizeof(header);
out:
if (retval == -ENOMEM) {
// clean ring buffer
g_hiLogDev.writeOffset = 0;
g_hiLogDev.headOffset = 0;
g_hiLogDev.size = 0;
g_hiLogDev.count = 0;
}
(VOID)LOS_MuxRelease(&g_hiLogDev.mtx);
return retval;
}
@ -231,7 +238,7 @@ static void HiLogHeadInit(struct HiLogEntry *header, size_t len)
ret = clock_gettime(CLOCK_REALTIME, &now);
if (ret != 0) {
dprintf("In %s line %d,clock_gettime fail", __FUNCTION__, __LINE__);
dprintf("In %s line %d,clock_gettime fail\n", __FUNCTION__, __LINE__);
return;
}
@ -248,6 +255,9 @@ static void HiLogCoverOldLog(size_t bufLen)
int retval;
struct HiLogEntry header;
size_t totalSize = bufLen + sizeof(struct HiLogEntry);
static int dropLogLines = 0;
static int isLastTimeFull = 0;
int isThisTimeFull = 0;
while (totalSize + g_hiLogDev.size > HILOG_BUFFER) {
retval = HiLogReadRingBuffer((unsigned char *)&header, sizeof(header));
@ -255,9 +265,20 @@ static void HiLogCoverOldLog(size_t bufLen)
break;
}
dropLogLines++;
isThisTimeFull = 1;
isLastTimeFull = 1;
HiLogBufferDec(sizeof(header));
HiLogBufferDec(header.len);
}
if (isLastTimeFull == 1 && isThisTimeFull == 0) {
/* so we can only print one log if hilog ring buffer is full in a short time */
if (dropLogLines > 0) {
dprintf("hilog ringbuffer full, drop %d line(s) log\n", dropLogLines);
}
isLastTimeFull = 0;
dropLogLines = 0;
}
}
int HiLogWriteInternal(const char *buffer, size_t bufLen)
@ -318,7 +339,7 @@ static void HiLogDeviceInit(void)
{
g_hiLogDev.buffer = LOS_MemAlloc((VOID *)OS_SYS_MEM_ADDR, HILOG_BUFFER);
if (g_hiLogDev.buffer == NULL) {
dprintf("In %s line %d,LOS_MemAlloc fail", __FUNCTION__, __LINE__);
dprintf("In %s line %d,LOS_MemAlloc fail\n", __FUNCTION__, __LINE__);
}
init_waitqueue_head(&g_hiLogDev.wq);

View File

@ -118,14 +118,14 @@ STATIC VOID OsMagicMemCheck(VOID)
}
#endif
INT32 CheckMagicKey(CHAR key)
INT32 CheckMagicKey(CHAR key, UINT16 consoleId)
{
#ifdef LOSCFG_ENABLE_MAGICKEY
INT32 i;
STATIC UINT32 magicKeySwitch = 0;
if (key == 0x03) { /* ctrl + c */
KillPgrp();
KillPgrp(consoleId);
return 0;
} else if (key == 0x12) { /* ctrl + r */
magicKeySwitch = ~magicKeySwitch;

View File

@ -46,7 +46,7 @@ typedef struct {
CHAR magicKey;
} MagicKeyOp;
extern INT32 CheckMagicKey(CHAR key);
extern INT32 CheckMagicKey(CHAR key, UINT16 consoleId);
#ifdef __cplusplus
#if __cplusplus

View File

@ -46,7 +46,7 @@
#include "los_excinfo_pri.h"
#endif
#include "los_exc_pri.h"
#include "los_sched_pri.h"
#define SIZEBUF 256
@ -94,7 +94,7 @@ STATIC VOID ConsoleOutput(const CHAR *str, UINT32 len)
for (;;) {
cnt = write(STDOUT_FILENO, str + writen, (size_t)toWrite);
if ((cnt < 0) || (toWrite == cnt)) {
if ((cnt < 0) || ((cnt == 0) && ((!OsPreemptable()) || (OS_INT_ACTIVE))) || (toWrite == cnt)) {
break;
}
writen += cnt;
@ -202,12 +202,22 @@ __attribute__ ((noinline)) VOID dprintf(const CHAR *fmt, ...)
va_list ap;
va_start(ap, fmt);
OsVprintf(fmt, ap, CONSOLE_OUTPUT);
#ifdef LOSCFG_SAVE_EXCINFO
if (OsGetSystemStatus() == OS_SYSTEM_EXC_CURR_CPU) {
WriteExcBufVa(fmt, ap);
}
#endif
va_end(ap);
}
VOID LkDprintf(const CHAR *fmt, va_list ap)
{
OsVprintf(fmt, ap, CONSOLE_OUTPUT);
#ifdef LOSCFG_SAVE_EXCINFO
if (OsGetSystemStatus() == OS_SYSTEM_EXC_CURR_CPU) {
WriteExcBufVa(fmt, ap);
}
#endif
}
#ifdef LOSCFG_SHELL_DMESG
@ -273,6 +283,11 @@ VOID LOS_LkPrint(INT32 level, const CHAR *func, INT32 line, const CHAR *fmt, ...
va_start(ap, fmt);
OsVprintf(fmt, ap, CONSOLE_OUTPUT);
#ifdef LOSCFG_SAVE_EXCINFO
if (OsGetSystemStatus() == OS_SYSTEM_EXC_CURR_CPU) {
WriteExcBufVa(fmt, ap);
}
#endif
va_end(ap);
}
#endif

View File

@ -31,6 +31,10 @@
#include "shcmd.h"
#define DEFAULT_SCREEN_WIDTH 80
#define MAX_CMD_KEY_WIDTH 12
#define CMD_ITEM_PER_LINE (DEFAULT_SCREEN_WIDTH / (MAX_CMD_KEY_WIDTH + 1))
UINT32 OsShellCmdHelp(UINT32 argc, const CHAR **argv)
{
UINT32 loop = 0;
@ -45,15 +49,16 @@ UINT32 OsShellCmdHelp(UINT32 argc, const CHAR **argv)
PRINTK("*******************shell commands:*************************\n");
LOS_DL_LIST_FOR_EACH_ENTRY(curCmdItem, &(cmdInfo->cmdList.list), CmdItemNode, list) {
if ((loop & (8 - 1)) == 0) { /* 8 - 1:just align print */
if ((loop % CMD_ITEM_PER_LINE) == 0) { /* just align print */
PRINTK("\n");
}
PRINTK("%-12s ", curCmdItem->cmd->cmdKey);
PRINTK("%-12s ", curCmdItem->cmd->cmdKey);
loop++;
}
PRINTK("\n");
PRINTK("\n\nAfter shell prompt \"OHOS # \":\n"
"Use `<cmd> [args ...]` to run built-in shell commands listed above.\n"
"Use `exec <cmd> [args ...]` or `./<cmd> [args ...]` to run external commands.\n");
return 0;
}

View File

@ -118,7 +118,10 @@ static int GetFullpathNull(int fd, const char *path, char **filePath)
if (ret < 0) {
return -get_errno();
}
fullPath = file->f_path;
fullPath = strdup(file->f_path);
if (fullPath == NULL) {
ret = -ENOMEM;
}
} else {
ret = GetFullpath(fd, path, &fullPath);
if (ret < 0) {
@ -307,7 +310,7 @@ int SysOpen(const char *path, int oflags, ...)
goto ERROUT;
}
if (oflags & O_CLOEXEC) {
if ((unsigned int)oflags & O_CLOEXEC) {
SetCloexecFlag(procFd);
}
@ -1640,7 +1643,7 @@ int SysOpenat(int dirfd, const char *path, int oflags, ...)
goto ERROUT;
}
if (oflags & O_CLOEXEC) {
if ((unsigned int)oflags & O_CLOEXEC) {
SetCloexecFlag(procFd);
}
@ -2462,36 +2465,35 @@ int SysFstatfs64(int fd, size_t sz, struct statfs *buf)
int SysPpoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, const sigset_t *sigMask, int nsig)
{
int timeout;
int ret;
sigset_t_l origMask;
sigset_t_l setl;
if (sigMask == NULL) {
ret = -EINVAL;
return ret;
}
int timeout, retVal;
sigset_t_l origMask = {0};
sigset_t_l set = {0};
CHECK_ASPACE(tmo_p, sizeof(struct timespec));
CHECK_ASPACE(sigMask, sizeof(sigset_t));
CPY_FROM_USER(tmo_p);
CPY_FROM_USER(sigMask);
timeout = (tmo_p == NULL) ? -1 : (tmo_p->tv_sec * OS_SYS_US_PER_MS + tmo_p->tv_nsec / OS_SYS_NS_PER_MS);
if (timeout & 0x80000000) {
ret = -EINVAL;
return ret;
if (tmo_p != NULL) {
timeout = tmo_p->tv_sec * OS_SYS_US_PER_MS + tmo_p->tv_nsec / OS_SYS_NS_PER_MS;
if (timeout < 0) {
return -EINVAL;
}
} else {
timeout = -1;
}
setl.sig[0] = *sigMask;
OsSigprocMask(SIG_SETMASK, &setl, &origMask);
ret = SysPoll(fds, nfds, timeout);
if (ret < 0) {
ret = -get_errno();
}
OsSigprocMask(SIG_SETMASK, &origMask, NULL);
PointerFree(tmo_pbak);
PointerFree(sigMaskbak);
return (ret == -1) ? -get_errno() : ret;
if (sigMask != NULL) {
retVal = LOS_ArchCopyFromUser(&set, sigMask, sizeof(sigset_t));
if (retVal != 0) {
return -EFAULT;
}
(VOID)OsSigprocMask(SIG_SETMASK, &set, &origMask);
} else {
(VOID)OsSigprocMask(SIG_SETMASK, NULL, &origMask);
}
retVal = SysPoll(fds, nfds, timeout);
(VOID)OsSigprocMask(SIG_SETMASK, &origMask, NULL);
return retVal;
}
#endif

View File

@ -29,6 +29,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "syscall_pub.h"
#include "mqueue.h"
#include <errno.h>
#include <sys/types.h>
@ -36,6 +37,7 @@
#include "time_posix.h"
#include "user_copy.h"
#include "los_signal.h"
#include "los_process_pri.h"
#include "los_strncpy_from_user.h"
#include "fs/file.h"
@ -229,8 +231,14 @@ int SysSigAction(int sig, const sigaction_t *restrict sa, sigaction_t *restrict
int SysSigprocMask(int how, const sigset_t_l *restrict setl, sigset_t_l *restrict oldl, size_t sigsetsize)
{
/* Let nxsig_procmask do all of the work */
return OsSigprocMask(how, setl, oldl);
CHECK_ASPACE(setl, sizeof(sigset_t_l));
CHECK_ASPACE(oldl, sizeof(sigset_t_l));
CPY_FROM_USER(setl);
CPY_FROM_USER(oldl);
/* Let OsSigprocMask do all of the work */
int ret = OsSigprocMask(how, setl, oldl);
CPY_TO_USER(oldl);
return ret;
}
int SysKill(pid_t pid, int sig)

View File

@ -104,7 +104,7 @@ VOID OsArmA32SyscallHandle(TaskContext *regs)
UINT32 cmd = regs->reserved2;
if (cmd >= SYS_CALL_NUM) {
PRINT_ERR("Syscall ID: error %d !!!\n", cmd);
PRINT_ERR("Syscall ID: error %u !!!\n", cmd);
return;
}
@ -112,7 +112,7 @@ VOID OsArmA32SyscallHandle(TaskContext *regs)
nArgs = g_syscallNArgs[cmd / NARG_PER_BYTE]; /* 4bit per nargs */
nArgs = (cmd & 1) ? (nArgs >> NARG_BITS) : (nArgs & NARG_MASK);
if ((handle == 0) || (nArgs > ARG_NUM_7)) {
PRINT_ERR("Unsupport syscall ID: %d nArgs: %d\n", cmd, nArgs);
PRINT_ERR("Unsupport syscall ID: %u nArgs: %u\n", cmd, nArgs);
regs->R0 = -ENOSYS;
return;
}

View File

@ -110,7 +110,7 @@ Please deal with the "char *" by function:UserPathCopy.
#define CPY_FROM_USER(ptr) \
__typeof(*ptr) ptr##cpy = {0}, *ptr##bak = ptr; \
if (ptr != NULL) { \
if (LOS_ArchCopyFromUser((void*)&ptr##cpy, ptr, sizeof(*ptr)) != 0) { \
if (LOS_ArchCopyFromUser((void*)&ptr##cpy, ptr##bak, sizeof(*ptr##bak)) != 0) { \
set_errno(EFAULT); \
return -get_errno(); \
} \

View File

@ -109,7 +109,7 @@ int SysSetiTimer(int which, const struct itimerval *value, struct itimerval *ova
{
int ret;
struct itimerval svalue;
struct itimerval sovalue;
struct itimerval sovalue = { 0 };
if (value == NULL) {
errno = EINVAL;
@ -137,7 +137,7 @@ int SysSetiTimer(int which, const struct itimerval *value, struct itimerval *ova
int SysGetiTimer(int which, struct itimerval *value)
{
int ret;
struct itimerval svalue;
struct itimerval svalue = { 0 };
if (value == NULL) {
errno = EINVAL;
@ -189,7 +189,7 @@ int SysTimerCreate(clockid_t clockID, struct ksigevent *evp, timer_t *timerID)
int SysTimerGettime(timer_t timerID, struct itimerspec *value)
{
int ret;
struct itimerspec svalue;
struct itimerspec svalue = { 0 };
if (value == NULL) {
errno = EINVAL;
@ -213,7 +213,7 @@ int SysTimerSettime(timer_t timerID, int flags, const struct itimerspec *value,
{
int ret;
struct itimerspec svalue;
struct itimerspec soldValue;
struct itimerspec soldValue = { 0 };
if (value == NULL) {
errno = EINVAL;
@ -285,7 +285,7 @@ int SysClockSettime(clockid_t clockID, const struct timespec *tp)
int SysClockGettime(clockid_t clockID, struct timespec *tp)
{
int ret;
struct timespec stp;
struct timespec stp = { 0 };
if (tp == NULL) {
errno = EINVAL;
@ -308,7 +308,7 @@ int SysClockGettime(clockid_t clockID, struct timespec *tp)
int SysClockGetres(clockid_t clockID, struct timespec *tp)
{
int ret;
struct timespec stp;
struct timespec stp = { 0 };
if (tp == NULL) {
errno = EINVAL;
@ -356,7 +356,7 @@ int SysNanoSleep(const struct timespec *rqtp, struct timespec *rmtp)
{
int ret;
struct timespec srqtp;
struct timespec srmtp;
struct timespec srmtp = { 0 };
if (!rqtp || LOS_ArchCopyFromUser(&srqtp, rqtp, sizeof(struct timespec))) {
errno = EFAULT;
@ -384,7 +384,7 @@ int SysNanoSleep(const struct timespec *rqtp, struct timespec *rmtp)
clock_t SysTimes(struct tms *buf)
{
clock_t ret;
struct tms sbuf;
struct tms sbuf = { 0 };
if (buf == NULL) {
errno = EFAULT;
@ -436,7 +436,7 @@ int SysClockGettime64(clockid_t clockID, struct timespec64 *tp)
{
int ret;
struct timespec t;
struct timespec64 stp;
struct timespec64 stp = { 0 };
if (tp == NULL) {
errno = EINVAL;
@ -463,7 +463,7 @@ int SysClockGetres64(clockid_t clockID, struct timespec64 *tp)
{
int ret;
struct timespec t;
struct timespec64 stp;
struct timespec64 stp = { 0 };
if (tp == NULL) {
errno = EINVAL;
@ -525,7 +525,7 @@ int SysTimerGettime64(timer_t timerID, struct itimerspec64 *value)
{
int ret;
struct itimerspec val;
struct itimerspec64 svalue;
struct itimerspec64 svalue = { 0 };
if (value == NULL) {
errno = EINVAL;
@ -584,6 +584,7 @@ int SysTimerSettime64(timer_t timerID, int flags, const struct itimerspec64 *val
}
if (oldValue != NULL) {
(void)memset_s(&soldValue, sizeof(struct itimerspec64), 0, sizeof(struct itimerspec64));
soldValue.it_interval.tv_sec = oldVal.it_interval.tv_sec;
soldValue.it_interval.tv_nsec = oldVal.it_interval.tv_nsec;
soldValue.it_value.tv_sec = oldVal.it_value.tv_sec;

View File

@ -85,6 +85,7 @@ sources_full = [
"full/IO_test_strncasecmp_l_002.cpp",
"full/IO_test_ppoll_001.cpp",
"full/IO_test_ppoll_002.cpp",
"full/IO_test_ppoll_003.cpp",
]
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) {

View File

@ -127,12 +127,11 @@ extern VOID IO_TEST_DCNGETTEXT_002(VOID);
extern VOID IO_TEST_DCGETTEXT_001(VOID);
extern VOID IO_TEST_DCGETTEXT_002(VOID);
extern VOID IO_TEST_GETTEXT_001(VOID);
extern VOID IO_TEST_PPOLL_001(void);
extern VOID IO_TEST_PPOLL_002(void);
extern VOID IO_TEST_PSELECT_001(void);
extern VOID IO_TEST_STRFMON_L_001(VOID);
extern VOID IO_TEST_STRFMON_L_002(VOID);
extern VOID IO_TEST_PPOLL_001(VOID);
extern VOID IO_TEST_PPOLL_002(VOID);
extern VOID IO_TEST_PPOLL_003(VOID);
#endif

View File

@ -30,143 +30,91 @@
*/
#include "It_test_IO.h"
#include <poll.h>
#include "signal.h"
#include "pthread.h"
#define LISTEN_FD_NUM 10
#define POLL_EVENTS 1
const int BUF_SIZE = 128;
const int DELAY_TIME = 200;
int pipeFdPpoll[LISTEN_FD_NUM][2];
static pthread_t g_tid = -1;
extern int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, const sigset_t *sigmask);
static INT32 pipeFdPpoll[2];
static INT32 g_step = 1;
static CHAR strBuf[] = "hello world.";
static struct pollfd pfd;
static void *pthread_01(void)
static void *pthread_01(void *arg)
{
static int count = 0;
int total_num = 0;
int times = 3;
int i, ret;
struct pollfd fds[LISTEN_FD_NUM] = { 0 };
char buffer[20];
struct timespec t = { 3,0 };
sigset_t sigset;
/* TEST_PRINT("[INFO]%s:%d,%s,Create thread %d\n", __FILE__, __LINE__, __func__, count); */
count++;
sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM); /* 把SIGALRM 信号添加到sigset 信号集中 */
sigaddset(&sigset, SIGUSR1);
for (i = 0; i < LISTEN_FD_NUM; i++) {
fds[i].fd = pipeFdPpoll[i][0];
fds[i].events = POLL_EVENTS;
INT32 retVal;
CHAR buf[BUF_SIZE];
/* 执行ppoll监视文件描述符 */
while (g_step < 3) { /* 3, 3rd step */
usleep(DELAY_TIME);
}
while (times--) {
ret = ppoll(fds, LISTEN_FD_NUM, &t, &sigset);
total_num += ((ret > 0) ? ret : 0);
if (ret <= 0) {
continue;
}
for (i = 0; i < LISTEN_FD_NUM; i++) {
if (fds[i].revents & POLL_EVENTS) {
ret = read(fds[i].fd, buffer, 12);
ICUNIT_GOTO_EQUAL(ret, 12, ret, EXIT);
ret = strcmp(buffer, "hello world");
TEST_PRINT("[EVENT]%s:%d,%s,buffer=%s\n", __FILE__, __LINE__, __func__, buffer);
}
}
if (total_num == LISTEN_FD_NUM) {
break;
}
g_step++;
retVal = ppoll(&pfd, 1, NULL, NULL);
ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal);
while (g_step < 5) { /* 5, 5th step */
usleep(DELAY_TIME);
}
g_step++;
/* 判断revents */
if (pfd.revents & POLLIN) {
memset_s(buf, sizeof(buf), 0, sizeof(buf));
retVal = read(pfd.fd, buf, BUF_SIZE);
ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal);
/* ICUNIT_GOTO_EQUAL(total_num, 10, -1, EXIT); */
/* TEST_PRINT("[INFO]%s:%d,%s,total_num=%d\n", __FILE__, __LINE__, __func__, total_num); */
EXIT:
return nullptr;
retVal = strcmp(strBuf, buf);
ICUNIT_ASSERT_EQUAL_NULL(retVal, 0, retVal);
}
while (g_step < 6) { /* 6, 6th step */
usleep(DELAY_TIME);
}
pthread_exit(NULL);
}
static UINT32 testcase1(VOID)
STATIC UINT32 testcase(VOID)
{
int i;
int ret;
int count = 0;
for (i = 0; i < LISTEN_FD_NUM; i++) {
ret = pipe(pipeFdPpoll[i]);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,pipeFdPpoll[%d][0]=%d\n", __FILE__, __LINE__, __func__, ret, i, pipeFdPpoll[i][0]);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,pipeFdPpoll[%d][0]=%d\n", __FILE__, __LINE__, __func__, ret, i, pipeFdPpoll[i][1]);
INT32 retVal;
pthread_t tid;
/* 建立管道 */
while (g_step < 1) { /* 1, 1st step */
usleep(DELAY_TIME);
}
errno = 0;
ret = pthread_create(&g_tid, nullptr, (void *(*)(void *))pthread_01, nullptr);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
errno = 0;
for (i = 0; i < LISTEN_FD_NUM; i++) {
if ((pipeFdPpoll[i][1] != 9) && (pipeFdPpoll[i][1] != 10) && (pipeFdPpoll[i][1] != 11)) {
ret = write(pipeFdPpoll[i][1], "hello world!", 12); /* 12, "hello world" length and '\0' */
}
ICUNIT_GOTO_EQUAL(ret, 12, ret, EXIT);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
retVal = pipe(pipeFdPpoll);
ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal);
g_step++;
/* 设置pfd */
pfd.fd = pipeFdPpoll[0];
pfd.events = POLLIN;
/* 开辟线程执行 ppoll */
while (g_step < 2) { /* 2, 2nd step */
usleep(DELAY_TIME);
}
#if 1 /* write looply */
while(1) {
if (count++ > 3) {
break;
}
sleep(1);
for (i = 0; i < LISTEN_FD_NUM; i++) {
errno = 0;
ret = pthread_create(&g_tid, nullptr, (void *(*)(void *))pthread_01, nullptr);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
if ((pipeFdPpoll[i][1] == 13) || (pipeFdPpoll[i][1] == 14) || (pipeFdPpoll[i][1] == 15)) {
errno = 0;
ret = write(pipeFdPpoll[i][1], "World HELLO!", 12); /* 12, "hello world" length and '\0' */
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,pipeFdPpoll[%d][1]=%d,count=%d\n", __FILE__, __LINE__, __func__, ret,i, pipeFdPpoll[i][1], count);
}
/* ICUNIT_GOTO_EQUAL(ret, 12, ret, EXIT); */
}
retVal = pthread_create(&tid, NULL, pthread_01, NULL);
ICUNIT_ASSERT_EQUAL(retVal, 0, retVal);
g_step++;
/* 向管道写入数据 */
while (g_step < 4) { /* 4, 4th step */
usleep(DELAY_TIME);
}
#endif
pthread_join(g_tid, nullptr);
for (i = 0; i < LISTEN_FD_NUM; i++) {
close(pipeFdPpoll[i][0]);
close(pipeFdPpoll[i][1]);
}
return LOS_OK;
EXIT:
for (i = 0; i < LISTEN_FD_NUM; i++) {
close(pipeFdPpoll[i][0]);
close(pipeFdPpoll[i][1]);
}
return LOS_NOK;
}
static UINT32 testcase(VOID)
{
testcase1();
sleep(1);
retVal = write(pipeFdPpoll[1], "hello world.", sizeof(strBuf));
ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal);
g_step++;
pthread_join(tid, NULL);
return LOS_OK;
}
VOID IO_TEST_PPOLL_001(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
}

View File

@ -30,83 +30,87 @@
*/
#include "It_test_IO.h"
#include "time.h"
#include "signal.h"
#include <poll.h>
#include <fcntl.h>
#include <unistd.h>
#include <strings.h>
#include "pthread.h"
#define BUF_LEN 20
#define MAX_SCAN_FDSET 10 /* define poll's listened FD set's size */
#define POLL_WAIT_TIMEOUT 10*1000 /* ms */
const int BUF_SIZE = 128;
const int DELAY_TIME = 200;
extern int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, const sigset_t *sigmask);
void work_ppoll(int fd)
static int pipeFdPpoll[2];
static int g_step = 1;
static char strBuf[] = "hello world.";
static struct pollfd pfd;
static void *pthread_01(void *arg)
{
int ret = 0;
int i = 0;
char recv_buf[BUF_LEN];
sigset_t sigset;
struct timespec t;
struct pollfd scan_fdset[MAX_SCAN_FDSET];
int scan_fdset_num = 10;
int count = 5;
bzero(recv_buf, BUF_LEN);
sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM); /* add SIGALRM to sigset */
sigaddset(&sigset, SIGUSR1); /* add SIGUSR1 to sigset */
bzero(&t, sizeof(struct timespec));
t.tv_sec = 10;
t.tv_nsec = 0;
bzero(scan_fdset, sizeof(struct pollfd) * MAX_SCAN_FDSET);
scan_fdset[0].fd = fd;
/* attention:in the book《UNIX网络编程第一卷》P162 metions:POLLERR,POLLHUP,POLLNVAL\
those error signals can not be set in events. */
/* they will return in revents,while the proper condition happens. */
scan_fdset[0].events = POLLOUT; /* set the signal needed to be listened:POLLOUT/POLLIN */
/* set other elements in the array as invalid. */
for (i = 1; i < MAX_SCAN_FDSET; i++) {
/* scan_fdset[i].fd = -1; */
scan_fdset[i].fd = fd;
scan_fdset[i].events = POLLOUT; /* set the signal needed to be listened. */
int retVal;
char buf[BUF_SIZE];
const struct timespec timeout = {10000, 0};
/* 执行ppoll监视文件描述符 */
while (g_step < 4) { /* 4, 4th step */
usleep(DELAY_TIME);
}
/* scan_fdset_num = 1; */ /* 表示当前的scan_fdset[] 数组中只使用前面1 个元素存放需要监听的扫描符 */
while (count--) {
ret = ppoll(scan_fdset, scan_fdset_num, &t, &sigset);
for (i = 0; i < MAX_SCAN_FDSET; i++) {
if (scan_fdset[i].revents & POLLOUT) {
TEST_PRINT("[INFO]%s:%d,%s,fd have signal!\n", __FILE__, __LINE__, __func__);
ret = read(fd, recv_buf, BUF_LEN);
if (-1 == ret) {
TEST_PRINT("[INFO]%s:%d,%s,read error!\n", __FILE__, __LINE__, __func__);
continue;
}
TEST_PRINT("[INFO]%s:%d,%s,recv_buf=%s\n", __FILE__, __LINE__, __func__, recv_buf);
}
TEST_PRINT("[INFO]%s:%d,%s,scan_fdset[i].revents=%d\n", __FILE__, __LINE__, __func__, scan_fdset[i].revents);
}
g_step++;
retVal = ppoll(&pfd, 1, &timeout, NULL);
ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal);
/* 判断revents */
if (pfd.revents & POLLIN) {
memset_s(buf, sizeof(buf), 0, sizeof(buf));
retVal = read(pfd.fd, buf, BUF_SIZE);
ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal);
retVal = strcmp(strBuf, buf);
ICUNIT_ASSERT_EQUAL_NULL(retVal, 0, retVal);
}
while (g_step < 5) { /* 5, 5th step */
usleep(DELAY_TIME);
}
pthread_exit(NULL);
}
static UINT32 testcase(VOID)
{
int fd;
char *filename = FILEPATH_775;
int retVal;
pthread_t tid;
/* 建立管道 */
while (g_step < 1) {
usleep(DELAY_TIME);
}
retVal = pipe(pipeFdPpoll);
ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal);
g_step++;
/* 设置pfd */
pfd.fd = pipeFdPpoll[0];
pfd.events = POLLIN;
/* 向管道写入数据 */
while (g_step < 2) { /* 2, 2nd step */
usleep(DELAY_TIME);
}
sleep(1);
retVal = write(pipeFdPpoll[1], "hello world.", sizeof(strBuf));
ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal);
g_step++;
fd = open(filename, O_RDWR);
TEST_PRINT("[INFO]%s:%d,%s,fd=%d\n", __FILE__, __LINE__, __func__, fd);
work_ppoll(fd);
/* 开辟线程执行 ppoll */
while (g_step < 3) { /* 3, 3rd step */
usleep(DELAY_TIME);
}
retVal = pthread_create(&tid, NULL, pthread_01, NULL);
ICUNIT_ASSERT_EQUAL(retVal, 0, retVal);
g_step++;
pthread_join(tid, NULL);
return LOS_OK;
}
VOID IO_TEST_PPOLL_002(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
}

View File

@ -0,0 +1,152 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "It_test_IO.h"
#include "pthread.h"
#include "signal.h"
const int BUF_SIZE = 128;
const int DELAY_TIME = 200;
static INT32 pipeFdPpoll[2];
static INT32 g_step = 1;
static CHAR strBuf[] = "hello world.";
static struct pollfd pfd;
static sigset_t sigMask;
static UINT32 count = 0;
static void signalHandle(INT32 sigNum)
{
g_step++;
return;
}
static void *pthread_01(void *arg)
{
INT32 retVal;
CHAR buf[BUF_SIZE];
(void)signal(SIGUSR1, signalHandle);
while (1) {
/* 执行ppoll监视文件描述符 */
while (g_step < 2) { /* 2, 2nd step */
usleep(DELAY_TIME);
}
g_step++;
retVal = ppoll(&pfd, 1, NULL, &sigMask);
ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal);
/* 判断revents */
if (pfd.revents & POLLIN) {
memset_s(buf, sizeof(buf), 0, sizeof(buf));
retVal = read(pfd.fd, buf, BUF_SIZE);
ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal);
retVal = strcmp(strBuf, buf);
ICUNIT_ASSERT_EQUAL_NULL(retVal, 0, retVal);
count++;
} else {
ICUNIT_ASSERT_NOT_EQUAL_NULL(pfd.revents & POLLIN, 0, pfd.revents & POLLIN);
}
g_step++;
if (g_step >= 7) { /* 7, 7th step */
ICUNIT_ASSERT_EQUAL_NULL(count, 2, count); /* 2, 2nd step */
pthread_exit(NULL);
}
}
return LOS_OK;
}
static UINT32 testcase(VOID)
{
INT32 retVal;
pthread_t tid;
/* 建立管道 */
while (g_step < 1) {
usleep(DELAY_TIME);
}
retVal = pipe(pipeFdPpoll);
ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal);
/* 设置pfd sigmask */
pfd.fd = pipeFdPpoll[0];
pfd.events = POLLIN;
pfd.revents = 0x0;
sigemptyset(&sigMask);
sigaddset(&sigMask, SIGUSR1);
/* 开辟线程执行 ppoll */
retVal = pthread_create(&tid, NULL, pthread_01, NULL);
ICUNIT_ASSERT_EQUAL(retVal, 0, retVal);
g_step++;
/* 向管道写入数据 */
while (g_step < 3) { /* 3, 3ed step */
usleep(DELAY_TIME);
}
sleep(1); /* 保证先挂起再写入数据 */
retVal = write(pipeFdPpoll[1], "hello world.", sizeof(strBuf));
ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal);
/* 向线程发送信号 */
while (g_step < 5) { /* 5, 5th step */
usleep(DELAY_TIME);
}
sleep(1); /* 保证先挂起再发送信号 */
retVal = pthread_kill(tid, SIGUSR1);
ICUNIT_ASSERT_EQUAL(retVal, 0, retVal);
/* 继续向管道写入数据 */
ICUNIT_ASSERT_EQUAL(g_step, 5, g_step); /* 5, sth。判断挂起解除之前信号没有被处理 */
retVal = write(pipeFdPpoll[1], "hello world.", sizeof(strBuf));
ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal);
while (g_step < 7) { /* 7, 7th step */
usleep(DELAY_TIME);
}
ICUNIT_ASSERT_EQUAL(count, 2, count); /* 2, 2nd step */
/* 等待退出 */
pthread_join(tid, NULL);
return LOS_OK;
}
VOID IO_TEST_PPOLL_003(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@ -115,6 +115,17 @@ HWTEST_F(IoTest, IO_TEST_PPOLL_002, TestSize.Level0)
IO_TEST_PPOLL_002();
}
/* *
* @tc.name: IO_TEST_PPOLL_003
* @tc.desc: function for IoTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(IoTest, IO_TEST_PPOLL_003, TestSize.Level0)
{
IO_TEST_PPOLL_003();
}
/* *
* @tc.name: IT_STDLIB_POLL_002
* @tc.desc: function for IoTest

View File

@ -107,6 +107,8 @@
#define HWI_NUM_INTVALID OS_HWI_MAX_NUM
#define writel(value, address) WRITE_UINT32(value, address)
extern UINT32 PrepareFileEnv(CHAR *pathList[], CHAR *streamList[], INT32 streamLen[], INT32 listCnt);
extern UINT32 RecoveryFileEnv(CHAR *pathList[], INT32 listCnt);
extern UINT32 PosixPthreadInit(pthread_attr_t *attr, int pri);
extern UINT32 PosixPthreadDestroy(pthread_attr_t *attr, pthread_t thread);
@ -233,18 +235,6 @@ UINT32 LosTaskDelay(UINT32 tick);
#define TEST_TASKDELAY_20TICK 20
#define TEST_TASKDELAY_50TICK 50
#ifdef TEST3731
#define TestTimer2ValueGet(temp) READ_UINT32(temp, TIMER1_REG_BASE + TIMER_VALUE)
#elif defined TEST3559
#define TestTimer2ValueGet(temp) READ_UINT32(temp, TIMER3_REG_BASE + TIMER_VALUE)
#else
#define TestTimer2ValueGet(temp) READ_UINT32(temp, TIMER2_REG_BASE + TIMER_VALUE)
#endif
extern void TestTimer2Config(void);
#define REALTIME(time) (UINT32)((UINT64)(0xffffffff - time) * 1000 / OS_SYS_CLOCK) /* accuracy:ms */
#define HW_TMI(time) (UINT32)((UINT64)(0xffffffff - time) * 1000 / (OS_SYS_CLOCK / 1000000)) /* accuracy:ns */
#define uart_printf_func printf
#ifndef VFS_STAT_PRINTF
@ -268,7 +258,6 @@ extern void TestTimer2Config(void);
#endif
extern UINT32 g_shellTestQueueID;
extern int g_min_mempool_size;
extern UINT32 g_testCount;
extern UINT32 g_testCount1;
extern UINT32 g_testCount2;
@ -400,10 +389,6 @@ void Test_usb_shellcmd(controller_type ctype, device_type dtype, usb_test_type t
extern int Gettid(void);
#define COLOR(c) "\033[" c "m"
#define COLOR_RED(text) COLOR("1;31") text COLOR("0")
#define COLOR_GREEN(text) COLOR("1;32") text COLOR("0")
/* like the ctime/asctime api, use static buffer, though not thread-safe. */
static inline const char *Curtime()
{

View File

@ -129,6 +129,70 @@ VOID test_init_spinor(VOID);
VOID test_deinit_jffs(VOID);
VOID test_mtd_jffs(VOID);
UINT32 PrepareFileEnv(CHAR *pathList[], CHAR *streamList[], INT32 streamLen[], INT32 listCnt)
{
CHAR nameBuf[256] = {0};
for (UINT32 i = 0; i < listCnt; i++) {
UINT32 ret = access(pathList[i], 0);
if (ret == 0) {
ret = memcpy_s(nameBuf, sizeof(nameBuf), pathList[i], strlen(pathList[i]) + 1);
if (ret != 0) {
return -1;
}
ret = strcat_s(nameBuf, sizeof(nameBuf), "_bak_for_test");
if (ret != 0) {
return -1;
}
ret = rename(pathList[i], nameBuf);
if (ret != 0) {
return -1;
}
}
FILE *fp = fopen(pathList[i], "w");
if (fp == NULL) {
return -1;
}
ret = fwrite(streamList[i], 1, streamLen[i], fp);
if (ret != streamLen[i]) {
(VOID)fclose(fp);
return -1;
}
ret = fclose(fp);
if (ret != 0) {
printf("%d\n", errno);
}
}
return 0;
}
UINT32 RecoveryFileEnv(CHAR *pathList[], INT32 listCnt)
{
UINT32 ret;
CHAR nameBuf[256] = {0};
for (UINT32 i = 0; i < listCnt; i++) {
ret = remove(pathList[i]);
if (ret != 0) {
printf("ret = %d, err = %d\n", ret, errno);
}
ret = memcpy_s(nameBuf, sizeof(nameBuf), pathList[i], strlen(pathList[i]) + 1);
if (ret != 0) {
return -1;
}
ret = strcat_s(nameBuf, sizeof(nameBuf), "_bak_for_test");
if (ret != 0) {
return -1;
}
ret = access(nameBuf, 0);
if (ret == 0) {
ret = rename(nameBuf, pathList[i]);
if (ret != 0) {
return -1;
}
}
}
return 0;
}
VOID Wfi(VOID)
{
__asm__ __volatile__("wfi" : : : "memory");

View File

@ -30,14 +30,29 @@
*/
#include "It_test_misc.h"
static UINT32 TestCase(VOID)
STATIC UINT32 TestCase(VOID)
{
long ret;
INT32 ret;
CHAR *hostsFileStream = "127.0.0.1 localhost\n192.168.1.3 hisilicon\n::1 localhost\n";
CHAR *pathList[] = {"/etc/hosts"};
CHAR *streamList[] = {hostsFileStream};
INT32 streamLen[] = {strlen(hostsFileStream)};
ret = PrepareFileEnv(pathList, streamList, streamLen, 1);
if (ret != 0) {
printf("error: need some env files, but prepare is not ok");
(VOID)RecoveryFileEnv(pathList, 1);
return -1;
}
ret = gethostid();
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret);
ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, ERROUT);
(VOID)RecoveryFileEnv(pathList, 1);
return 0;
ERROUT:
(VOID)RecoveryFileEnv(pathList, 1);
return -1;
}
VOID ItTestMisc009(VOID)

View File

@ -51,6 +51,8 @@
#define FE_UPWARD 0x800
#define FE_TOWARDZERO 0xc00
extern CHAR *g_groupFileStream;
extern CHAR *g_passwdFileStream;
extern VOID ItTestSys001(VOID);
extern VOID IT_TEST_SYS_002(VOID);
extern VOID IT_TEST_SYS_003(VOID);
@ -78,7 +80,7 @@ extern VOID ItTestSys024(VOID);
extern VOID ItTestSys025(VOID);
extern VOID ItTestSys026(VOID);
extern VOID ItTestSys027(VOID);
extern VOID IT_TEST_SYS_028(VOID);
extern VOID ItTestSys028(VOID);
extern VOID ItTestSys029(VOID);
extern VOID IT_TEST_SYS_030(VOID);
extern VOID IT_TEST_SYS_031(VOID);

View File

@ -30,51 +30,66 @@
*/
#include "It_test_sys.h"
static UINT32 TestCase(VOID)
STATIC UINT32 TestCase(VOID)
{
struct passwd *user1 = nullptr;
struct passwd *user2 = nullptr;
struct passwd *user3 = nullptr;
struct passwd *user4 = nullptr;
INT32 ret;
CHAR *pathList[] = {"/etc/group", "/etc/passwd"};
CHAR *streamList[] = {g_groupFileStream, g_passwdFileStream};
INT32 streamLen[] = {strlen(g_groupFileStream), strlen(g_passwdFileStream)};
ret = PrepareFileEnv(pathList, streamList, streamLen, 2); /* 2, group & passwd */
if (ret != 0) {
printf("error: need some env file, but prepare is not ok");
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
user1 = getpwnam("root");
ICUNIT_ASSERT_NOT_EQUAL(user1, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1);
ICUNIT_GOTO_NOT_EQUAL(user1, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_uid, 0, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_gid, 0, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1, ERROUT);
user2 = getpwnam("daemon");
ICUNIT_ASSERT_NOT_EQUAL(user2, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user2->pw_uid, 1, -1);
ICUNIT_ASSERT_EQUAL(user2->pw_gid, 1, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_gecos, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1);
ICUNIT_GOTO_NOT_EQUAL(user2, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_name, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user2->pw_uid, 1, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user2->pw_gid, 1, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_gecos, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
user3 = getpwnam("bin");
ICUNIT_ASSERT_NOT_EQUAL(user3, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_name, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user3->pw_uid, 2, -1);
ICUNIT_ASSERT_EQUAL(user3->pw_gid, 2, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_gecos, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_dir, "/bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1);
ICUNIT_GOTO_NOT_EQUAL(user3, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_name, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user3->pw_uid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_EQUAL(user3->pw_gid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_STRING_EQUAL(user3->pw_gecos, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_dir, "/bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
user4 = getpwnam("lyw");
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT);
user4 = getpwnam("");
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT);
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return 0;
ERROUT:
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
VOID ItTestSys018(VOID)

View File

@ -30,7 +30,7 @@
*/
#include "It_test_sys.h"
static UINT32 TestCase(VOID)
STATIC UINT32 TestCase(VOID)
{
struct passwd pwd;
struct passwd *user1 = nullptr;
@ -38,61 +38,75 @@ static UINT32 TestCase(VOID)
struct passwd *user3 = nullptr;
struct passwd *user4 = nullptr;
struct passwd *user5 = nullptr;
char buf1[1024] = { 0 };
char buf2[2] = { 0 };
int ret;
CHAR buf1[1024] = { 0 }; /* 1024, buffer for test */
CHAR buf2[2] = { 0 }; /* 2, for test,this buffer is not enough large to save data */
INT32 ret;
CHAR *pathList[] = {"/etc/group", "/etc/passwd"};
CHAR *streamList[] = {g_groupFileStream, g_passwdFileStream};
INT32 streamLen[] = {strlen(g_groupFileStream), strlen(g_passwdFileStream)};
ret = PrepareFileEnv(pathList, streamList, streamLen, 2); /* 2, group & passwd */
if (ret != 0) {
printf("error: need some env file, but prepare is not ok");
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
ret = getpwnam_r("root", &pwd, buf1, sizeof(buf1), &user1);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(user1, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1);
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROUT);
ICUNIT_GOTO_NOT_EQUAL(user1, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_uid, 0, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_gid, 0, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1, ERROUT);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(pwd.pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(pwd.pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_shell, "/bin/bash", -1);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_name, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(pwd.pw_uid, 0, -1, ERROUT);
ICUNIT_GOTO_EQUAL(pwd.pw_gid, 0, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_gecos, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_dir, "/root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_shell, "/bin/bash", -1, ERROUT);
ret = getpwnam_r("daemon", &pwd, buf1, sizeof(buf1), &user2);
ICUNIT_ASSERT_NOT_EQUAL(user2, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user2->pw_uid, 1, -1);
ICUNIT_ASSERT_EQUAL(user2->pw_gid, 1, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_gecos, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1);
ICUNIT_GOTO_NOT_EQUAL(user2, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_name, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user2->pw_uid, 1, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user2->pw_gid, 1, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_gecos, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
ret = getpwnam_r("bin", &pwd, buf1, sizeof(buf1), &user3);
ICUNIT_ASSERT_NOT_EQUAL(user3, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_name, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user3->pw_uid, 2, -1);
ICUNIT_ASSERT_EQUAL(user3->pw_gid, 2, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_gecos, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_dir, "/bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1);
ICUNIT_GOTO_NOT_EQUAL(user3, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_name, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user3->pw_uid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_EQUAL(user3->pw_gid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_STRING_EQUAL(user3->pw_gecos, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_dir, "/bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
ret = getpwnam_r("root", &pwd, buf2, sizeof(buf2), &user4);
ICUNIT_ASSERT_EQUAL(ret, ERANGE, ret);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
ICUNIT_GOTO_EQUAL(ret, ERANGE, ret, ERROUT);
ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT);
ret = getpwnam_r(nullptr, &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_EQUAL(ret, 0, -1);
ICUNIT_GOTO_EQUAL(ret, 0, -1, ERROUT);
ret = getpwnam_r("", &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1);
ICUNIT_GOTO_NOT_EQUAL(ret, 0, -1, ERROUT);
ret = getpwnam_r("sssssss", &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1);
ICUNIT_GOTO_NOT_EQUAL(ret, 0, -1, ERROUT);
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return 0;
ERROUT:
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
VOID ItTestSys019(VOID)

View File

@ -30,53 +30,68 @@
*/
#include "It_test_sys.h"
static UINT32 TestCase(VOID)
STATIC UINT32 TestCase(VOID)
{
struct passwd *user1 = nullptr;
struct passwd *user2 = nullptr;
struct passwd *user3 = nullptr;
struct passwd *user4 = nullptr;
INT32 ret;
CHAR *pathList[] = {"/etc/group", "/etc/passwd"};
CHAR *streamList[] = {g_groupFileStream, g_passwdFileStream};
INT32 streamLen[] = {strlen(g_groupFileStream), strlen(g_passwdFileStream)};
ret = PrepareFileEnv(pathList, streamList, streamLen, 2); /* 2, group & passwd */
if (ret != 0) {
printf("error: need some env file, but prepare is not ok");
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
user1 = getpwuid(0);
ICUNIT_ASSERT_NOT_EQUAL(user1, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1);
ICUNIT_GOTO_NOT_EQUAL(user1, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_uid, 0, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_gid, 0, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1, ERROUT);
user2 = getpwuid(1);
ICUNIT_ASSERT_NOT_EQUAL(user2, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user2->pw_uid, 1, -1);
ICUNIT_ASSERT_EQUAL(user2->pw_gid, 1, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_gecos, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1);
ICUNIT_GOTO_NOT_EQUAL(user2, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_name, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user2->pw_uid, 1, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user2->pw_gid, 1, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_gecos, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
user3 = getpwuid(2);
ICUNIT_ASSERT_NOT_EQUAL(user3, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_name, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user3->pw_uid, 2, -1);
ICUNIT_ASSERT_EQUAL(user3->pw_gid, 2, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_gecos, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_dir, "/bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1);
user3 = getpwuid(2); /* 2, from etc/group */
ICUNIT_GOTO_NOT_EQUAL(user3, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_name, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user3->pw_uid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_EQUAL(user3->pw_gid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_STRING_EQUAL(user3->pw_gecos, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_dir, "/bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
user4 = getpwuid(200);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT);
user4 = getpwuid(-100);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT);
user4 = getpwuid(100000);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT);
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return 0;
ERROUT:
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
VOID ItTestSys020(VOID)

View File

@ -30,7 +30,7 @@
*/
#include "It_test_sys.h"
static UINT32 TestCase(VOID)
STATIC UINT32 TestCase(VOID)
{
struct passwd pwd;
struct passwd *user1 = nullptr;
@ -38,69 +38,83 @@ static UINT32 TestCase(VOID)
struct passwd *user3 = nullptr;
struct passwd *user4 = nullptr;
struct passwd *user5 = nullptr;
char buf1[1024] = { 0 };
char buf2[2] = { 0 };
int ret;
CHAR buf1[1024] = { 0 }; /* 1024, buffer for test */
CHAR buf2[2] = { 0 }; /* 2, for test,this buffer is not enough large to save data */
INT32 ret;
CHAR *pathList[] = {"/etc/group", "/etc/passwd"};
CHAR *streamList[] = {g_groupFileStream, g_passwdFileStream};
INT32 streamLen[] = {strlen(g_groupFileStream), strlen(g_passwdFileStream)};
ret = PrepareFileEnv(pathList, streamList, streamLen, 2); /* 2, group & passwd */
if (ret != 0) {
printf("error: need some env file, but prepare is not ok");
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
ret = getpwuid_r(0, &pwd, buf1, sizeof(buf1), &user1);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(user1, NULL, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1);
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROUT);
ICUNIT_GOTO_NOT_EQUAL(user1, NULL, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_uid, 0, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_gid, 0, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1, ERROUT);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(pwd.pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(pwd.pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_shell, "/bin/bash", -1);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_name, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(pwd.pw_uid, 0, -1, ERROUT);
ICUNIT_GOTO_EQUAL(pwd.pw_gid, 0, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_gecos, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_dir, "/root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_shell, "/bin/bash", -1, ERROUT);
ret = getpwuid_r(1, &pwd, buf1, sizeof(buf1), &user2);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(user2, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user2->pw_uid, 1, -1);
ICUNIT_ASSERT_EQUAL(user2->pw_gid, 1, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_gecos, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1);
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROUT);
ICUNIT_GOTO_NOT_EQUAL(user2, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_name, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user2->pw_uid, 1, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user2->pw_gid, 1, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_gecos, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
ret = getpwuid_r(2, &pwd, buf1, sizeof(buf1), &user3);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(user3, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_name, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user3->pw_uid, 2, -1);
ICUNIT_ASSERT_EQUAL(user3->pw_gid, 2, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_gecos, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_dir, "/bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1);
ret = getpwuid_r(2, &pwd, buf1, sizeof(buf1), &user3); /* 2, from etc/group */
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROUT);
ICUNIT_GOTO_NOT_EQUAL(user3, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_name, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user3->pw_uid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_EQUAL(user3->pw_gid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_STRING_EQUAL(user3->pw_gecos, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_dir, "/bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
ret = getpwuid_r(0, &pwd, buf2, sizeof(buf2), &user4);
ICUNIT_ASSERT_EQUAL(ret, ERANGE, ret);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
ICUNIT_GOTO_EQUAL(ret, ERANGE, ret, ERROUT);
ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT);
ret = getpwuid_r(200, &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_EQUAL(user5, nullptr, -1);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1);
ret = getpwuid_r(200, &pwd, buf1, sizeof(buf1), &user5); /* 200, invalid param for test */
ICUNIT_GOTO_EQUAL(user5, nullptr, -1, ERROUT);
ICUNIT_GOTO_NOT_EQUAL(ret, 0, -1, ERROUT);
ret = getpwuid_r(100000, &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_EQUAL(user5, nullptr, -1);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1);
ret = getpwuid_r(100000, &pwd, buf1, sizeof(buf1), &user5); /* 100000, invalid param for test */
ICUNIT_GOTO_EQUAL(user5, nullptr, -1, ERROUT);
ICUNIT_GOTO_NOT_EQUAL(ret, 0, -1, ERROUT);
ret = getpwuid_r(-100, &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_EQUAL(user5, nullptr, -1);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1);
ret = getpwuid_r(-100, &pwd, buf1, sizeof(buf1), &user5); /* -100, invalid param for test */
ICUNIT_GOTO_EQUAL(user5, nullptr, -1, ERROUT);
ICUNIT_GOTO_NOT_EQUAL(ret, 0, -1, ERROUT);
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return 0;
ERROUT:
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
VOID ItTestSys021(VOID)

View File

@ -30,47 +30,64 @@
*/
#include "It_test_sys.h"
static UINT32 TestCase(VOID)
STATIC UINT32 TestCase(VOID)
{
struct passwd *user1 = nullptr;
struct passwd *user2 = nullptr;
INT32 ret;
CHAR *pathList[] = {"/etc/group", "/etc/passwd"};
CHAR *streamList[] = {g_groupFileStream, g_passwdFileStream};
INT32 streamLen[] = {strlen(g_groupFileStream), strlen(g_passwdFileStream)};
ret = PrepareFileEnv(pathList, streamList, streamLen, 2); /* 2, group & passwd */
if (ret != 0) {
printf("error: need some env file, but prepare is not ok");
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
user1 = getpwent();
ICUNIT_ASSERT_NOT_EQUAL(user1, NULL, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1);
ICUNIT_GOTO_NOT_EQUAL(user1, NULL, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_uid, 0, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_gid, 0, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1, ERROUT);
user1 = getpwent();
ICUNIT_ASSERT_NOT_EQUAL(user1, NULL, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 1, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 1, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/usr/sbin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/usr/sbin/nologin", -1);
ICUNIT_GOTO_NOT_EQUAL(user1, NULL, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_uid, 1, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_gid, 1, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/usr/sbin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
user1 = getpwent();
ICUNIT_ASSERT_NOT_EQUAL(user1, NULL, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 2, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 2, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/usr/sbin/nologin", -1);
ICUNIT_GOTO_NOT_EQUAL(user1, NULL, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_uid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_EQUAL(user1->pw_gid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
setpwent();
user2 = getpwent();
ICUNIT_ASSERT_NOT_EQUAL(user2, NULL, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, user1->pw_name, -1);
ICUNIT_GOTO_NOT_EQUAL(user2, NULL, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_name, user1->pw_name, -1, ERROUT);
setpwent();
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return 0;
ERROUT:
setpwent();
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
VOID ItTestSys022(VOID)

View File

@ -31,39 +31,55 @@
#include "It_test_sys.h"
#include "grp.h"
static UINT32 TestCase(VOID)
STATIC UINT32 TestCase(VOID)
{
struct group *grp1 = nullptr;
struct group *grp2 = nullptr;
struct group *grp3 = nullptr;
struct group *grp4 = nullptr;
INT32 ret;
CHAR *pathList[] = {"/etc/group"};
CHAR *streamList[] = {g_groupFileStream};
INT32 streamLen[] = {strlen(g_groupFileStream)};
ret = PrepareFileEnv(pathList, streamList, streamLen, 1);
if (ret != 0) {
printf("error: need some env file, but prepare is not ok");
(VOID)RecoveryFileEnv(pathList, 1);
return -1;
}
grp1 = getgrent();
ICUNIT_ASSERT_NOT_EQUAL(grp1, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(grp1->gr_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(grp1->gr_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(grp1->gr_gid, 0, -1);
ICUNIT_GOTO_NOT_EQUAL(grp1, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(grp1->gr_name, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(grp1->gr_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(grp1->gr_gid, 0, -1, ERROUT);
grp2 = getgrent();
ICUNIT_ASSERT_NOT_EQUAL(grp2, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(grp2->gr_name, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(grp2->gr_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(grp2->gr_gid, 1, -1);
ICUNIT_GOTO_NOT_EQUAL(grp2, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(grp2->gr_name, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(grp2->gr_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(grp2->gr_gid, 1, -1, ERROUT);
grp3 = getgrent();
ICUNIT_ASSERT_NOT_EQUAL(grp3, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(grp3->gr_name, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(grp3->gr_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(grp3->gr_gid, 2, -1);
ICUNIT_GOTO_NOT_EQUAL(grp3, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(grp3->gr_name, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(grp3->gr_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(grp3->gr_gid, 2, -1, ERROUT); /* 2, from etc/group */
setgrent();
grp4 = getgrent();
ICUNIT_ASSERT_NOT_EQUAL(grp4, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(grp1->gr_name, grp4->gr_name, -1);
ICUNIT_GOTO_NOT_EQUAL(grp4, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(grp1->gr_name, grp4->gr_name, -1, ERROUT);
setgrent();
(VOID)RecoveryFileEnv(pathList, 1);
return 0;
ERROUT:
setgrent();
(VOID)RecoveryFileEnv(pathList, 1);
return -1;
}
VOID ItTestSys023(VOID)

View File

@ -34,17 +34,17 @@
#define GROUPFILE "/etc/group"
static int TestCase0(void)
STATIC INT32 TestCase0(void)
{
struct group getNam1 = { nullptr };
struct group *getNam2 = nullptr;
struct group getData1 = { nullptr };
struct group *getData2 = nullptr;
struct group *groupRet = nullptr;
char buf[1000];
size_t len = 1000;
CHAR buf[1000]; /* 1000, buffer for test */
size_t len = sizeof(buf);
int ret = getgrgid_r(0, &getNam1, buf, len, &getNam2);
INT32 ret = getgrgid_r(0, &getNam1, buf, len, &getNam2);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(getNam2, nullptr, getNam2);
@ -73,17 +73,17 @@ static int TestCase0(void)
return 0;
}
static int TestCase1(void)
STATIC INT32 TestCase1(void)
{
int len = 1000;
char buf[1000];
INT32 len = 1000;
CHAR buf[1000];
struct group getNam1 = { nullptr };
struct group *getNam2 = nullptr;
struct group getData1 = { nullptr };
struct group *getData2 = nullptr;
struct group *groupRet = nullptr;
int ret = getgrgid_r(-1, &getNam1, buf, len, &getNam2);
INT32 ret = getgrgid_r(-1, &getNam1, buf, len, &getNam2);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(errno, EAFNOSUPPORT, errno);
errno = 0;
@ -103,39 +103,33 @@ static int TestCase1(void)
ICUNIT_ASSERT_EQUAL(errno, EAFNOSUPPORT, errno);
errno = 0;
remove(GROUPFILE);
ret = getgrgid_r(0, &getNam1, buf, len, &getNam2);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno);
errno = 0;
groupRet = getgrgid(0);
ICUNIT_ASSERT_EQUAL(groupRet, 0, ret);
ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno);
errno = 0;
groupRet = getgrnam("root");
ICUNIT_ASSERT_EQUAL(groupRet, 0, ret);
ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno);
errno = 0;
ret = getgrnam_r("root", &getData1, buf, len, &getData2);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno);
return 0;
}
static int TestCase(void)
STATIC INT32 TestCase(void)
{
int ret = TestCase0();
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
CHAR *pathList[] = {"/etc/group"};
CHAR *streamList[] = {g_groupFileStream};
INT32 streamLen[] = {strlen(g_groupFileStream)};
INT32 ret = PrepareFileEnv(pathList, streamList, streamLen, 1);
if (ret != 0) {
printf("error: need some env file, but prepare is not ok");
(VOID)RecoveryFileEnv(pathList, 1);
return -1;
}
ret = TestCase0();
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROUT);
ret = TestCase1();
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_GOTO_EQUAL(ret, 0, re, ERROUT);
(VOID)RecoveryFileEnv(pathList, 1);
return 0;
ERROUT:
(VOID)RecoveryFileEnv(pathList, 1);
return -1;
}
VOID ItTestSys025(VOID)

View File

@ -31,20 +31,30 @@
static UINT32 TestCase(VOID)
{
int ret;
int ret, status;
pid_t pid = fork();
if (pid == 0) {
ret = setpriority(PRIO_PROCESS, 0, 15); /* 15, set priority for test */
if (ret != 0) {
exit(0);
}
ret = nice(0);
ICUNIT_ASSERT_EQUAL(ret, 15, ret);
exit(ret);
} else {
ret = nice(-15);
ret = waitpid(pid, &status, 0);
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
status = WEXITSTATUS(status);
ICUNIT_ASSERT_EQUAL(status, 15, status); /* 15, set priority for test */
ret = nice(-40); /* -40, set invaild priority for test */
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
}
return 0;
}
VOID IT_TEST_SYS_028(VOID)
VOID ItTestSys028(VOID)
{
TEST_ADD_CASE(IT_TEST_SYS_028, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
TEST_ADD_CASE(ItTestSys028, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}

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