Compare commits

..

127 Commits

Author SHA1 Message Date
openharmony_ci
b7030357cd !469 -- 为hispark_taurus打开ADC模块编译宏
Merge pull request !469 from 王亚枫/OpenHarmony-2.3-Beta
2021-07-27 14:26:11 +00:00
yafeng_wang
6b4aa6a4c9 feat: Open macro for ADC moudule
Signed-off-by: yafeng_wang <wangyafeng15@huawei.com>
2021-07-27 21:39:27 +08:00
openharmony_ci
650d2b91cd !442 feat: support .mkshrc
Merge pull request !442 from MGY917/mkshrc
2021-07-20 22:55:52 +00:00
openharmony_ci
7b7d64cc87 !404 mount接口支持MS_RDONLY flag
Merge pull request !404 from Far/master
2021-07-20 12:47:43 +00:00
openharmony_ci
70c18b4a75 !444 【WIP】修改OsGetArgsAddr所在头文件
Merge pull request !444 from JING/bootargs
2021-07-20 12:19:10 +00:00
chenjing
14bd753aa8 fix: OsGetArgsAddr声明所在头文件不正确
close #I41MWM

Signed-off-by: chenjing <chenjing139@huawei.com>
Change-Id: Iad136b3b8b63fed63fa69c594ec39bd90d5513b7
2021-07-20 19:30:04 +08:00
Far
8729f6ee57 feat: 增加mount的MS_RDONLY标志的支持
增加mount的MS_RDONLY标志的支持,并修改vfs主要接口相关支持。
1. fatfs lseek接口在分区以MS_RDONLY方式和文件以只读打开时不再能够扩大文件的大小。
2. 直接在镜像中创建storage目录,而不是在挂载根文件系统时创建storage目录。
3. 增加了MS_RDONLY的测试用例。

Close #I3Z1W6

Signed-off-by: Far <yesiyuan2@huawei.com>
2021-07-20 16:21:08 +08:00
Guangyao Ma
51a50c95b4 feat: support .mkshrc
close #I3Y5KE

Signed-off-by: Guangyao Ma <guangyao.ma@outlook.com>
Change-Id: Iea3cfe4da572b1a4e250f90cea24efa2c27ceddb
2021-07-20 14:37:30 +08:00
openharmony_ci
9d3e872454 !441 bootargs解析与rootfs挂载解耦,并支持自定义bootargs参数
Merge pull request !441 from JING/bootargs
2021-07-20 06:17:33 +00:00
chenjing
80473f0975 fix: bootargs解析与rootfs挂载解耦,并支持自定义bootargs参数
1、bootargs解析与rootfs挂载进行解耦;
2、支持开发者自定义bootargs参数,内核存储bootargs中所有参数;
3、开发者可获取bootargs中的参数内容,并自行解析。

close #I41CL8

Change-Id: If384476714854ba0cf64eb70b785eb26737dd3d2
Signed-off-by: chenjing <chenjing139@huawei.com>
2021-07-20 11:48:31 +08:00
openharmony_ci
c40e1464b9 !431 修复FATFS中不同内部接口不支持FAT12/FAT16 FAT表结标志
Merge pull request !431 from Far/fatfs
2021-07-19 06:08:09 +00:00
openharmony_ci
700c3415c4 !435 fix:修复llvm编译环境下内核态内存调测调用栈信息解析有误的问题
Merge pull request !435 from Harylee/mem
2021-07-19 01:42:47 +00:00
openharmony_ci
0973004870 !430 A核 告警清零
Merge pull request !430 from wangchen/xxx
2021-07-17 07:01:18 +00:00
openharmony_ci
d79fd50693 !313 feat: active mksh & toybox
Merge pull request !313 from MGY917/toybox_active
2021-07-15 12:40:12 +00:00
Haryslee
9547133e64 fix:修复llvm编译环境下内核态内存调测调用栈信息解析有误的问题
背景:内核态内存调测调用栈信息在gcc编译环境下是准确的,但是llvm
编译环境下是错误的,分析知,gcc和llvm编译环境下fp和lr的对应关系
是有区别的。
修复:增加llvm编译环境下对lr解析的逻辑,并用编译宏控制。

close #I40TQS

Signed-off-by: Haryslee <lihao189@huawei.com>

Change-Id: If2a7b7a286d91e78dcff2bdeb136fda71e656a79
2021-07-15 19:35:04 +08:00
openharmony_ci
d9ed4b4bf6 !427 fix: 修复lwip2.0 增强在futex中异常挂死问题
Merge pull request !427 from zhushengle/futex
2021-07-15 01:54:41 +00:00
openharmony_ci
60bf2fc517 !432 【DFX子系统】LiteOS_A系统信息dump工具
Merge pull request !432 from pcwlno1/upload_hidumper
2021-07-14 07:48:10 +00:00
qidechun
cb17fa50ed feat: 给开发者提供系统信息导出Hidumper工具。
给开发者提供系统信息DUMP机制,帮助开发者观察系统功能状态,发现潜在问题。

Close #I3NN7D

Signed-off-by: qidechun <qidechun@huawei.com>
2021-07-14 14:49:58 +08:00
openharmony_ci
a531da901d !426 【DFX子系统】【BBoxDetector】LiteOS_A死机重启维测框架
Merge pull request !426 from pcwlno1/upload1
2021-07-14 02:18:05 +00:00
qidechun
a195aac9fb feat: add blackbox for liteos_a
1、在内核增加BlackBox核心框架,对外提供模块回调接口注册和故障处理接口。
2、增加默认的系统模块适配层,处理通用内核态和用户态故障日志抓取和保存。
3、BBOX特性默认关闭,若想使用此特性,请在内核配置文件中增加如下编译选项:
LOSCFG_BLACKBOX=y
LOSCFG_SAVE_EXCINFO=y
LOSCFG_SAVE_EXCINFO可以帮助抓取更多的故障日志。
4、若已经打开BBOX特性,想快速验证此特性,请添加如下编译选项:
LOSCFG_HIDUMPER=y

Close #I406NP

Signed-off-by: qidechun <qidechun@huawei.com>
2021-07-14 09:37:35 +08:00
zhushengle
1157c4a289 fix : futex requeue机制中,头节点的queueList 为NULL, 导致系统异常
queuelist中的普通节点在调整为futexList的节点时,
未校验其queueList的有效性,导致queueList未初始化,
出现访问空指针;且在从旧链表迁移节点到新链表时,
节点从旧链表删除之后又插入到另一个链表中,导致对
旧链表的为NULL判断出错。

Close #I4024F

Change-Id: I506a10fc5740ce16e682c2c419b9d92a82000b86
Signed-off-by: zhushengle <zhushengle@huawei.com>
2021-07-14 09:30:49 +08:00
openharmony_ci
0056b4ade5 !380 修复了杀死掉hilog进程后SecurityCapability门禁用例无法通过的问题
Merge pull request !380 from phchang/fixhilog
2021-07-13 08:21:41 +00:00
openharmony_ci
78a50aff99 !396 修复signal中的关于pipe部分的用例问题
Merge pull request !396 from phchang/fix_pipebug
2021-07-13 08:21:28 +00:00
openharmony_ci
7240fe3bd4 !405 修复mqueue_unittest用例存在偶尔无法通过的问题
Merge pull request !405 from phchang/fix_mq
2021-07-13 08:20:38 +00:00
vcbchang
e7c4b1963a test: 修复mqueue_unittest全量用例ItPosixQueue075与ItPosixQueue097,冒烟用例 ItPosixQueue053用例存在偶尔无法通过的问题
【背景】mqueue_unittest用例ItPosixQueue075、ItPosixQueue053 与ItPosixQueue097用例存在偶尔无法通过的问题,现在将其修复

【修改方案】ItPosixQueue075中原来是通过延时来实现线程同步,现在更改为静态全局变量实现; ItPosixQueue097中的关于g_testCount利用延时来置标志位,实现线程同步。这里通过延时来期望线程调度,写的不合理,这里更改为等待标志位来实现线程同步。

re #I3Z9H9

Signed-off-by: vcbchang <vcbchang@qq.com>
Change-Id: Ib1bb945a5393cb03f4d92e4332e20acd82eb1845
2021-07-13 11:56:50 +08:00
vcbchang
fd6f91bc9f test: 修复signal中的关于pipe部分的用例问题
【背景】signal模块中的pipe用例存在无法通过测试的问题,经查找,pipe用例存在多处bug,这里做以修复

【修改方案】
1 ItPosixPipe002用例存在pipe存在在父进程中没有关闭写端,父进程判断处有编码问题等
2 删掉了一些用例多余的close函数,精简了用例的结构
3 原来用例主子进程依靠延时来实现进程同步,这里更改为使用共享内存的方法来实现

re #I3YPQ8

Signed-off-by: vcbchang <vcbchang@qq.com>
Change-Id: Ic0d0ab20521c9af5e5f1d75e76e047162d978464
2021-07-13 11:52:57 +08:00
Far
33f5c70e6c fix: 修复FATFS中不同内部接口不支持FAT12/FAT16 FAT表结束标志
FATFS内部接口中,仅对FAT32的FAT表结束符0x0FFFFFFF做了判断,而忽略了FAT12和FAT16的结束标志。
这会导致子在FAT12/FAT16中,部分功能异常。

Close #I409R6

Signed-off-by: Far <yesiyuan2@huawei.com>
2021-07-13 10:05:06 +08:00
wangchen
ec977a1c7e fix: A核codex修改
【背景】A核codex扫描告警消除。

【修改方案】
1. 将不可屏蔽告警进行修复。

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

re #I40B1S
Signed-off-by: wangchen <253227059@qq.com>
2021-07-12 20:16:19 +08:00
openharmony_ci
390159f58a !428 kconfig配置文件跟随产品
Merge pull request !428 from Caoruihong/defconfig
2021-07-12 03:25:28 +00:00
openharmony_ci
d8be8aad65 !377 perf: assign '-1' to uninitialized variable: ret
Merge pull request !377 from Joker2770/master
2021-07-12 00:55:51 +00:00
Caoruihong
6d948a42bb chore: place .config files under config dir of products
place .config files under config dir of products

Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: I80c6641ae462d4888a6f3124f92b4c9d7fa1567b
2021-07-10 19:36:44 +08:00
openharmony_ci
72d9aa1bcb !414 内核Kconfig与芯片配置解耦
Merge pull request !414 from Caoruihong/kconfig
2021-07-09 09:33:50 +00:00
openharmony_ci
8390738de5 !414 内核Kconfig与芯片配置解耦
Merge pull request !414 from Caoruihong/kconfig
2021-07-09 09:33:50 +00:00
Guangyao Ma
cacb4f0103 feat: active mksh & toybox
Close #I3VEOG

Change-Id: Ibc73aacf68c65e64b88084edfd3549b3137dde07
Signed-off-by: Guangyao Ma <guangyao.ma@outlook.com>
2021-07-09 17:07:06 +08:00
openharmony_ci
ee54cd8b7e !356 修复内核vfat用例
Merge pull request !356 from Far/test
2021-07-09 08:38:39 +00:00
openharmony_ci
f523d7a98c !339 修复了文件系统中jffs的全量用例和压测用例中出现的问题
Merge pull request !339 from phchang/fixjffs
2021-07-09 08:38:01 +00:00
openharmony_ci
d7387508e3 !402 消除编译告警
Merge pull request !402 from x_xiny/master
2021-07-09 08:37:20 +00:00
x_xiny
e4ff04586f fix:消除编译告警
【背景】
 消除编译告警

【修改方案】
 消除编译告警

 re #I3ZC1R

 Change-Id: I594d0f57e4cbbdb246a6bef1c978a38228123a34

 Signed-off-by: x-xiny <1301913191@qq.com>

Change-Id: I1d75cdcdcf9d06ec28e541cdfea77300da7c6bb1
2021-07-08 20:30:33 +08:00
Caoruihong
8784694686 feat: using kconfiglib instead of kconfig
kconfiglib support the kconfig macro language,
we need this feature to handle product related
Kconfig configuration.

Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: I6bb521e93aab6c67b8bc3ac664b64f5e52089a45
2021-07-08 15:44:47 +08:00
openharmony_ci
b29d9d88ab !412 fix: mksh compile bug fix
Merge pull request !412 from MGY917/fix_waitpid
2021-07-08 03:25:08 +00:00
Guangyao Ma
d8263b1e91 fix: mksh compile bug fix
编译框架整改,需要所有交叉编译指定sysroot以及arch相关的编译选项,用来在编译链
接过程中在指定的sysroot路径下,寻找符合arch要求的依赖库。往往,sysroot选项和
arch选项需要同时出现在编译链接选项中。

close #I3ZMR7

Signed-off-by: Guangyao Ma <guangyao.ma@outlook.com>
Change-Id: If2249721e0e35615b95f5525e57241aae910c212
2021-07-08 10:48:39 +08:00
openharmony_ci
9304a683ad !397 修复内核access chmod chown接口
Merge pull request !397 from JING/kernel
2021-07-08 02:36:56 +00:00
openharmony_ci
78906f4a6c !406 修正最小编译时的错误
Merge pull request !406 from Caoruihong/qemu_mini
2021-07-07 08:29:28 +00:00
openharmony_ci
ee7eb89354 !409 回退 'Pull Request !401 : 【DFX子系统】【BBoxDetector】LiteOS_A死机重启维测框架'
Merge pull request !409 from give-me-five/revert-merge-401-master
2021-07-07 03:06:14 +00:00
Denny
55e5e29005 回退 'Pull Request !401 : 【DFX子系统】【BBoxDetector】LiteOS_A死机重启维测框架' 2021-07-07 10:29:43 +08:00
Caoruihong
ac8c2c6d5b fix: minimal compile
fix compile errors in minimal compilation

Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: I48f4f7b27c684e2c747c1949776c5c4f9e383dec
2021-07-07 00:26:33 +08:00
openharmony_ci
feae60c8fe !401 【DFX子系统】【BBoxDetector】LiteOS_A死机重启维测框架
Merge pull request !401 from pcwlno1/upload10
2021-07-06 08:15:48 +00:00
qidechun
425975e481 feat: add blackbox for liteos_a
1、在内核增加BlackBox核心框架,对外提供模块回调接口注册和故障处理接口。
2、增加默认的系统模块适配层,处理通用内核态和用户态故障日志抓取和保存。

Close #I3NN7V

Signed-off-by: qidechun <qidechun@huawei.com>
2021-07-06 07:49:59 +08:00
openharmony_ci
cc731d1e69 !391 add vibrator liteos defined
Merge pull request !391 from kevin/0625_maste
2021-07-05 12:29:56 +00:00
chenjing
56a95b9ec9 fix: 修复内核access chmod chown接口
1、修复内核的access chmod chown功能;
2、此三个接口的syscall直接调用内核态接口执行操作。

close #I3Z5L6

Signed-off-by: chenjing <chenjing139@huawei.com>
Change-Id: I301f00fb341252b697b04b9970db86f0e7f978df
2021-07-05 16:03:16 +08:00
kevin
3e7622ca78 Merge branch '0625_maste' of https://gitee.com/Kevin-Lau/kernel_liteos_a into 0625_maste 2021-07-05 14:55:57 +08:00
kevin
b1b4ddcc7d feat:add hdf vibrator liteos definition
Change-Id: I0a73f0de3c25e427362fe9d96547c4d847448dda
Signed-off-by: kevin <liufeihu@huawei.com>
2021-07-05 14:53:43 +08:00
kevin
23fd4e55a3 add vibrator liteos defined
Signed-off-by: kevin <liufeihu@huawei.com>
Change-Id: I0a73f0de3c25e427362fe9d96547c4d847448dda
2021-07-01 20:24:46 +08:00
vcbchang
e57dc7762b test: 修复了文件系统中jffs的全量用例和压测用例中出现的问题
【背景】当前的fs中的jffs用例存在运行不通过的问题,现将其一一修复。

【修改方案】
1. 默认storage文件夹没有文件,如果存在,删除后测试
2. BUG中存在判断不通过的情况,可能是移植过程中出现的变量判断错误,修改变量名正确通过
3. 移植过程中没有考虑现在falsh的大小,有时会出现写入量过多而容量不够的情况,则通过减少写入量来解决问题。
4. 为了尽量减少修改的内容,这里主要以更改全局宏大小或者在代码中修改变量的初始值。

【影响】
主要是jffs用例的写入flash的大小发生变化,其余没有影响。

Signed-off-by: vcbchang <vcbchang@qq.com>
Change-Id: I878fe3ad855e0e430bf7f36e066120893f756828
2021-07-01 18:07:51 +08:00
openharmony_ci
003810284c !384 对内核中menuconfig开关的宏使用#ifdef/#ifndef来做预编译判断
Merge pull request !384 from boxi/upload
2021-07-01 07:11:13 +00:00
openharmony_ci
379d602ab6 !376 使能QEMU arm-virt平台的FAT配置选项
Merge pull request !376 from laokz/blk
2021-07-01 06:05:57 +00:00
openharmony_ci
bf7b2c0a3e !386 支持单独编译内核
Merge pull request !386 from Caoruihong/build_alone
2021-07-01 02:41:01 +00:00
boxi
4e4f2d6d7e refactor: 对LiteOS_a内核中menuconfig开关的宏使用#ifdef/#ifndef做预编译处理
LiteOS_a中有部分配置宏进行了重复冗余定义,导致当头文件未被包含时,极易引入错误,
故对menuconfig配置宏进行统一处理,均使用#ifdef/#ifndef作为预编译判断方式

Close #I3YEGS

Change-Id: Ife6db770cc66de1d6199a4f3ba3950e9bfd0e71a
Signed-off-by: boxi <lewis.liulei@huawei.com>
2021-07-01 09:08:18 +08:00
Caoruihong
d7672d47f2 chore: make liteos_a can be built alone
in the liteos_a directory, we used to use `make clean all` command
to build liteos_a kernel for test.

Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: I5ca689c1c44052f7de937d7faa9e4d3534d97380
2021-06-30 18:44:46 +08:00
openharmony_ci
abbeca1cb2 !359 sysroot和CPU架构参数通过BUILD.gn传递给Make
Merge pull request !359 from Caoruihong/sysroot
2021-06-29 08:14:54 +00:00
openharmony_ci
50c8abc521 !371 fix: 修复kill进程时,liteipc阻塞的进程无法退出问题
Merge pull request !371 from zhushengle/p_kill
2021-06-29 05:27:08 +00:00
openharmony_ci
0469e5b849 !378 修复了FATFS设置卷标的功能
Merge pull request !378 from Far/master
2021-06-29 05:13:41 +00:00
openharmony_ci
dfea902a08 !379 fix: 修复内核c库的makefile中被优化函数替换的高频函数依然参与了编译的问题
Merge pull request !379 from Zhaotianyu/0628libc_fix
2021-06-29 04:50:15 +00:00
openharmony_ci
339c467e71 !375 基于汇编实现内核对用户态内存清零的功能
Merge pull request !375 from Harylee/mem
2021-06-29 04:41:02 +00:00
vcbchang
455e42e5b9 test: 修复了杀死掉hilog进程后SecurityCapability门禁用例无法通过的问题
【背景】如果操作系统先执行kill hilog进程,然后再执行SecurityCapability,那么门禁用例将无法通过,原因是该用例先获取了hilog进程的id,但hilog进程已经杀掉了,所以报错

【修改方案】
1. 增加kill 0与错误码判断,如果发现进程已经被干掉的话将不执行相关内容

【影响】
无其它影响。
Signed-off-by: vcbchang <vcbchang@qq.com>
Change-Id: Icdf357800175eff19acf1f92426469642a697386
2021-06-28 20:31:28 +08:00
arvinzzz
6f6dc4f24c fix: 修复内核c库的makefile中被优化函数替换的高频函数依然参与了编译的问题
1. 更正makefile过滤时被替换函数的不正确路径
2. 防止LOCAL_SRCS再直接+= /*/*.c添加回来

close: #I3XGM8

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I3aff2a60c5a48f2d6c174afa04d30fa6f5514d7e
2021-06-28 17:34:08 +08:00
Caoruihong
9e45086d19 chore: pass sysroot and arch related cflags by BUILD.gn
sysroot and arch related cflags are pass by BUILD.gn now.

Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: Ia6000dd7ed8a8a37e935ace49d8460a919a16566
2021-06-28 16:31:02 +08:00
Far
9515d53dcc fix: 恢复了FATFS设置卷标的功能
Liteos_a FATFS需要提供格式化时设置卷标的功能,该功能在当前系统中缺失。
现在恢复该功能,使用方法与原来一致。即使用set_label设置卷标文本后,调用format对设备格式化。

Close #I3Y5G8

Signed-off-by: Far <yesiyuan2@huawei.com>
2021-06-28 15:43:15 +08:00
Joker2770
e0a27badde perf: assign '-1' to uninitialized variable: ret
Signed-off-by: Joker2770 <1214220480@qq.com>
2021-06-28 09:33:29 +08:00
laokz
49856dc1e0 feat(QEMU_ARM_VIRT_CA7): 使能FAT文件系统编译选项
Signed-off-by: laokz <laokz@foxmail.com>
Change-Id: I0eece39921292498243bd017f168f953a437731c
2021-06-26 18:11:15 +08:00
openharmony_ci
43bdf2f1d3 !372 信号管道用例ItPosixPipe005由于偶现性问题暂时下线
Merge pull request !372 from phchang/fix_pipe
2021-06-26 10:00:22 +00:00
openharmony_ci
eb1900d4db !374 设置qemu默认userfs大小/修改qemu驱动目录
Merge pull request !374 from MGY917/qemu_opti
2021-06-26 09:30:05 +00:00
zhushengle
7de43bb004 fix: 修复kill进程时,因liteipc阻塞的进程概率无法退出问题
kill进程时,会将因为liteipc阻塞的线程唤醒,使其调度并自动退出,由于liteipc阻塞机制为
循环阻塞方式,会导致将因liteipc阻塞的线程唤醒后又进入等待中。此处在唤醒因liteipc阻塞的
线程后检查是否已有kill标志,如果有使其按接收数据失败退出,在返回用户态之前,该线程会进
入退出流程,结束运行。

Close #I3XX7K

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Iec4e298dff4aefd2994289067a35cb5673e323f9
2021-06-26 17:08:48 +08:00
Guangyao Ma
1d952a254a fix: 设置qemu默认userfs大小/修改qemu驱动目录
驱动目录位置不合理,需要调整到/device/qemu/drivers下面

close #I3XW96 #I3XWXD

Change-Id: Ied6b90d2d0631c99f2209f5b72bbd12cdff6b1d5
Signed-off-by: Guangyao Ma <guangyao.ma@outlook.com>
2021-06-26 15:38:19 +08:00
Haryslee
9db3407589 feat: 基于汇编实现内核对用户态内存清零的功能
背景:LOS_UserMemClear接口原有实现是通过在内核中
申请一块堆内存并对其清零,调用copy_to_user来达到
对用户态内存清零的目的,需要使用堆内存。
修改方案:基于汇编实现内核对用户态内存清零的功能。

close #I3XXT0

Change-Id: I27cb1e45559cb75a9b330799fe427abd54f51c15
Signed-off-by: Haryslee <lihao189@huawei.com>
2021-06-26 15:31:42 +08:00
vcbchang
bb6abd8c6b test: 信号管道用例ItPosixPipe005由于偶现性问题暂时下线
【背景】信号管道用例ItPosixPipe005偶尔会失败,经查找,发现是CPU调度所致,延时时间与期望调度不符合,增加延时时间即可

【修改方案】修复了此问题,但是考虑pipe用例整体不稳定,并且pipe用例的pipe函数存在问题,先暂时下线,等pipe部分全部修改完毕后再上线。

re #I3XXPH

Signed-off-by: vcbchang <vcbchang@qq.com>
Change-Id: I21831c9f5ef5700f3b3c8da02f945e0c37f31a6a
2021-06-26 15:27:31 +08:00
openharmony_ci
3cddcb9f66 !355 SIOCGIFCONF iotcl,用户态到内核态申请内存大小错误
Merge pull request !355 from 刘建东/master
2021-06-26 06:50:12 +00:00
YOUR_NAME
bfd27e78b2 fix: SIOCGIFCONF ioctl malloc size error in kernel
use struct ifconf and ifc_buf size malloc memory

close: #I3XEZ3

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-06-26 10:26:40 +08:00
Far
a8384b5db2 fix: 修复了内核的VFAT测试用例
修复内容包括如下:
1. 将memset_s中buffer的大小设置正确;
2. 将用例文件夹名由vfat2修改为vfat;
3. 修复了vfat用例在SetUpTestcase和TearDownTestCase;
4. 全局变量g_fatFilesystem在初始化时设置为2(即FAT32);

Close #I3XF3R

Signed-off-by: Far <yesiyuan2@huawei.com>
2021-06-26 10:13:23 +08:00
openharmony_ci
5db839acef !362 修复在Liteos-a在FATFS中创建的文件夹在Ubuntu中不可见的BUG
Merge pull request !362 from Far/fatfs
2021-06-25 07:20:10 +00:00
openharmony_ci
f4626985fd !368 fix: Identical condition 'ret<0', second condition is always false. 🐛
Merge pull request !368 from Joker2770/master
2021-06-25 07:13:33 +00:00
openharmony_ci
68da7aefc5 !369 修复README_zh-HK.md的链接错误
Merge pull request !369 from SimonLi/fix-doc
2021-06-25 06:20:46 +00:00
SimonLi
f1b4c87bc4 fix(doc): 修复README_zh-HK.md的链接错误
Signed-off-by: SimonLi <likailong@huawei.com>
2021-06-25 14:13:32 +08:00
Joker2770
1348809807 fix: Identical condition 'ret<0', second condition is always false. 🐛
Signed-off-by: Joker2770 <1214220480@qq.com>
2021-06-25 11:26:34 +08:00
openharmony_ci
eb72f78cf1 !363 userfs分区的起始地址与大小改为通过bootargs配置
Merge pull request !363 from JING/rootfs
2021-06-25 01:05:16 +00:00
openharmony_ci
12577eade5 !358 feat: L1支持低功耗投票框架
Merge pull request !358 from zhushengle/pm_v
2021-06-25 00:26:41 +00:00
openharmony_ci
de6db86df3 !364 GetFileMappingList函数实现未加void导致gcc编译报错
Merge pull request !364 from 野生毛霉君/master
2021-06-24 12:47:37 +00:00
mucor
56b8ecaf17 fix: add (void) to GetFileMappingList method
close: #I3XPXY

Signed-off-by: mucor <mucorwang@gmail.com>
2021-06-24 20:32:47 +08:00
openharmony_ci
1e345f18b3 !338 修复rwlock门禁用例多次测试出现的超时不通过的问题
Merge pull request !338 from phchang/rwlock
2021-06-24 10:55:21 +00:00
vcbchang
f793dc1097 test:修复rwlock用例在循环处会卡死的问题
【背景】修复rwlock门禁用例多次测试出现的程序会卡死在某一个地方的问题,经查找程序会卡在循环里面

【修改方案】
1.经测试,发现用例在创建线程后对退出标志位做了初始化,但卡在循环中不动的原因是在创建线程后立刻发生了调度,没有来得及初始化,则发生了错误,故会出现卡在循环中的情况。
而且,由于卡在循环中时线程是同一优先级,可能不会发生调度,故在循环里面加了一句可以调度的语句,防止在一处循环卡的太久。
2.将该用例挪出门禁,待稳定后恢复。
【影响】
对其它用例无影响。

re #I3VUX4

Signed-off-by:vcbchang<vcbchang@qq.com>

Change-Id: Ie0f908001f59bfc832c2519104aa2e3188206910
Signed-off-by: vcbchang <vcbchang@qq.com>
2021-06-24 17:17:27 +08:00
openharmony_ci
112cdebe41 !357 修改/proc/mounts显示格式
Merge pull request !357 from JING/mount
2021-06-24 08:27:32 +00:00
openharmony_ci
a28dcc38c9 !360 增加清除文件系统缓存的维测接口
Merge pull request !360 from 野生毛霉君/master
2021-06-24 07:34:45 +00:00
mucor
3d1cf683f3 feat: add clear cache cmd to /proc/fs_cache
write "clear pathcahe" to clear pathcaches and vnodes
write "clear pagecache" to clear pagecaches
write "clear all" to clear both pathcaches and pagechaches
the cache in use will not be cleared

close: #I3XLPH

Signed-off-by: mucor <mucorwang@gmail.com>
2021-06-24 15:11:50 +08:00
Far
a9fc1e0e5d fix: Liteos-a创建的文件夹在Ubuntu中不可见
Linux的文件夹需要包含"."和".."才会被视为一个有效的目录
通过在新建的文件夹中创建"."和".."目录项修复这个BUG

Close #I3XMY6

Signed-off-by: Far <yesiyuan2@huawei.com>
2021-06-24 15:09:12 +08:00
chenjing
2e2b14205f fix: userfs分区的起始地址与大小改为通过bootargs配置
在内核解析bootargs参数时,加入对userAddr与userSize两个字段的解析。
1、如果bootargs中配置了userAddr与userSize,则使用配置值划分storage分区。
2、如果bootargs中未配置这两个字段,则storage分区默认紧接在rootfs分区后。

close #I3XNEY

Signed-off-by: chenjing <chenjing139@huawei.com>
Change-Id: Iba63ccd7fc3f7efc1d726c4b38beee5df1d64122
2021-06-24 15:03:53 +08:00
openharmony_ci
b8e18ffdf1 !323 fix: 修复内核堆完整性检查逻辑中访问非法指针导致系统异常问题。
Merge pull request !323 from Harylee/mem
2021-06-24 06:45:45 +00:00
zhushengle
21d8ac8752 feat: L1支持低功耗投票框架
功能描述:
  在proc目录下增加power目录,添加powr_mode,power_lock,power_unlock和power_count节点,
  power_mode:节点用于查询和设置系统支持的功耗模式
  power_lock:用于查询和获取低功耗锁,持锁后,将会阻止系统进入低功耗状态
  power_unlock: 用于释放已经持有的低功耗锁,也可查询当前有那些持有低功耗锁
  power_count:用于查询当前持有低功耗锁的个数

Close #I3VS5N

Change-Id: I2e2881cc968eab3c5fa6f9dbd7e8c5e448609407
Signed-off-by: zhushengle <zhushengle@huawei.com>
2021-06-24 14:27:23 +08:00
openharmony_ci
008fa8660d !337 fix: fatfs memory leak
Merge pull request !337 from jianjian/master
2021-06-24 05:36:29 +00:00
chenjing
6860246cfa fix: 修改/proc/mounts显示格式
显示信息内容及格式修改为与posix标准一致,内容包括:
1、挂载设备名
2、挂载点路径
3、文件系统类型
4、挂载选项(此项暂不支持,打印())
5、dump频率(此项暂不支持,值为0)
6、fsck检查次序(此项暂不支持,值为0)

close #I3XGCS

Signed-off-by: chenjing <chenjing139@huawei.com>
Change-Id: I2a8cb093e7c5316feb55fb196bc1b4301d8d0249
2021-06-23 17:10:29 +08:00
openharmony_ci
8a3d188240 !347 修改lwip_enhanced编译脚本,更新lwip_enhanced lwip版本到2.1.2
Merge pull request !347 from 刘建东/master
2021-06-23 02:27:55 +00:00
openharmony_ci
8f0d25225e !351 remove HAVE_VENDOR_CONFIG from hdf Makefile in liteos_a
Merge pull request !351 from yuanbo/master
2021-06-23 02:06:49 +00:00
openharmony_ci
8fe0cc7770 !344 对proc文件系统内的节点增加uid/gid管理
Merge pull request !344 from LeonChan/proc-uid
2021-06-23 01:21:12 +00:00
openharmony_ci
ee4cf83121 !345 add /proc/fd file to dump pid/fd information
Merge pull request !345 from LeonChan/proc_fd
2021-06-23 00:42:13 +00:00
openharmony_ci
702d8d9dde !352 mqueue144与mutex18门禁用例不稳定暂时下线
Merge pull request !352 from phchang/fix_test
2021-06-22 12:14:05 +00:00
vcbchang
290a3c6f92 test: mqueue144与mutex18门禁用例不稳定暂时下线
【背景】mqueue144与mutex18门禁用例不稳定暂时下线

【修改方案】
将ItPosixQueue144.cpp与ItTestPthreadMutex018.cpp门禁用例暂时放入全量用例里面

re: #I3X4PR

Signed-off-by: vcbchang <vcbchang@qq.com>
Change-Id: I470c6bde70aa2b5956ac50a93f56776901774618
2021-06-22 18:53:03 +08:00
chenwei
600dded31e feat: add /proc/fd file to dump the pid/fd/path information
1, for users with privilege, display all users' fd info with the template "Pid  Fd  SysFd Path"
2, for normal user, display its own fd info with the template "Pid Fd Path"

close #I3WB5U

Signed-off-by: chenwei <chenwei26@huawei.com>
2021-06-22 17:27:25 +08:00
chenwei
67806596a3 feat: add uid/gid for ProcFs
close: #I3WGVP

Signed-off-by: chenwei <chenwei26@huawei.com>
2021-06-22 15:40:00 +08:00
yuanbo
88fe4eb3e1 fix: add product_path parameter for driver build
Driver use product_path in hb env as hcs config root path
by default. If it's not exit, try to use device config path.

close: #I3PQ10

Signed-off-by: yuanbo <yuanbo@huawei.com>
2021-06-22 15:18:54 +08:00
openharmony_ci
ca40c79761 !350 增加/proc/fs_cache显示文件系统缓存相关维测信息(重新合入)
Merge pull request !350 from 野生毛霉君/master
2021-06-22 07:18:45 +00:00
mucor
231cb6be27 feat: add /proc/fs_cache to display cache info
add /proc/fs_cache to display vnode, path cache, page cache.
also change some bad virable name

close: #I3WWBD

Signed-off-by: mucor <mucorwang@gmail.com>
2021-06-22 14:53:17 +08:00
openharmony_ci
7f484dfa09 !315 chore: update LOS_BitmapFfz comment
Merge pull request !315 from kenneth/LOS_BitmapFfz
2021-06-22 06:34:45 +00:00
openharmony_ci
1fa6ba3389 !314 chore: update typo in rb tree comments
Merge pull request !314 from kenneth/BR_Tree
2021-06-22 06:34:30 +00:00
openharmony_ci
b7f2df0350 !334 fix: 修改tzset测试用例运行2遍现象
Merge pull request !334 from guweijie/master
2021-06-22 06:29:34 +00:00
openharmony_ci
8bb4538de1 !349 修复当Fatfs开关关闭时,编译失败的问题
Merge pull request !349 from 野生毛霉君/master
2021-06-22 03:04:10 +00:00
kenneth
99d7072332 chore: update LOS_BitmapFfz comment
函数LOS_BitmapFfz有2个参数,注释中只描述了一个参数,丢失了对参数numBits的描述,影响导出API文档。补充函数注释的@param部分。

close #I3U3SF

Signed-off-by: kenneth <459864689@qq.com>
2021-06-22 10:22:46 +08:00
Haryslee
30f5ab89b7 fix: 修复内核堆完整性检查逻辑中访问非法指针导致系统异常问题。
内存完整性校验原有逻辑中当检测到非零异常指针后仍继续访问异常指针
next的内存域导致系统异常。
本次修改后的逻辑为:检测到非零异常指针后直接退出循环,将异常指针
的相关信息输出即可,增加了goto逻辑。对原有功能逻辑无影响。

close #I3VJZT

Change-Id: I5be06a552cf9fd74d8bd78f5cdf04db06eab4f76
Signed-off-by: Haryslee <lihao189@huawei.com>
2021-06-22 09:54:31 +08:00
mucor
fd3f4072b5 fix: compile error when fatfs disabled
close: I3WTLZ

Signed-off-by: mucor <mucorwang@gmail.com>
2021-06-22 09:50:53 +08:00
openharmony_ci
143efc0fab !348 回退 'Pull Request !342 : 增加/proc/fs_cache来显示文件系统缓存维测信息'
Merge pull request !348 from SimonLi/revert-merge-342-master
2021-06-21 13:55:51 +00:00
SimonLi
2f3d7efc24 回退 'Pull Request !342 : 增加/proc/fs_cache来显示文件系统缓存维测信息' 2021-06-21 21:33:52 +08:00
YOUR_NAME
e76c0046f7 chore: update lwip_enhanced lwip version to 2.1.2
update lwip version to 2.1.2 for lwip_enhanced

close: #I3WL4J

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-06-21 21:30:31 +08:00
openharmony_ci
b3120b5498 !342 增加/proc/fs_cache来显示文件系统缓存维测信息
Merge pull request !342 from 野生毛霉君/master
2021-06-21 17:21:02 +08:00
mucor
53c6d96c6f feat: add /proc/fs_cache to display cache info
add /proc/fs_cache to display vnode, path cache, page cache.
also change some bad virable name

close: #I3WESD

Signed-off-by: mucor <mucorwang@gmail.com>
2021-06-21 16:11:06 +08:00
openharmony_ci
3f84ed5075 !340 /proc/mounts显示格式修改
Merge pull request !340 from JING/mount
2021-06-21 15:24:32 +08:00
chenjing
e9ad6b71c3 fix: 增加表头,内容以制表符分栏。
close #I3W2M9

Signed-off-by: chenjing <chenjing139@huawei.com>
Change-Id: If8ba7047e2914a3104182bf017f437c2ae962625
2021-06-21 14:17:03 +08:00
jianjian
fbfd71dfe3 fix: fatfs memory leak
Signed-off-by: jianjian <xingjian_liu@yeah.net>
2021-06-20 13:42:01 +08:00
teamol
e4b6ba56b9 test: fix 2 testcases for API tzset
1.modifications:
testsuites/unittest/time/timer/smoke/timer_test_tzset_001.cpp
testsuites/unittest/time/timer/smoke/timer_test_tzset_002.cpp
testsuites/unittest/time/timer/time_timer_test.cpp

2.influence:
none

Signed-off-by: teamol <28105285@qq.com>
2021-06-18 17:26:48 +08:00
kenneth
6e95771303 chore: update rb tree comments
update typos in rb tree comment

close #I3U73B

Signed-off-by: kenneth <459864689@qq.com>
2021-06-18 11:07:53 +08:00
583 changed files with 5507 additions and 1976 deletions

6
.gitignore vendored
View File

@@ -16,9 +16,9 @@ cscope*
tags
# Menuconfig temp files
/include/config
/include/generated
.config*
/config.h
.config
.config.old
# Build temp files
/platform/board.ld

View File

@@ -73,11 +73,10 @@ lite_subsystem("kernel") {
build_ext_component("make") {
exec_path = rebase_path(".", root_build_dir)
tee_enable = "false"
if (board_name == "hi3516dv300" && enable_tee_ree) {
tee_enable = "tee"
}
prebuilts = "sh build.sh ${board_name} ${ohos_build_compiler} ${root_build_dir} ${ohos_build_type} ${tee_enable} \"${device_company}\" \"${product_path}\""
outdir = rebase_path(get_path_info(".", "out_dir"))
command = "make clean OUTDIR=$outdir && make rootfs VERSION=\"${ohos_version}\" -j 16 OUTDIR=$outdir"
sysroot_path = rebase_path(ohos_current_sysroot)
arch_cflags = string_join(" ", target_arch_cflags)
command = "./build.sh ${board_name} ${ohos_build_compiler} ${root_build_dir} ${ohos_build_type} \"${tee_enable}\""
command += " \"${device_company}\" \"${product_path}\" $outdir \"${ohos_version}\" ${sysroot_path} \"${arch_cflags}\""
command += " \"${device_path}\""
}

56
Kconfig
View File

@@ -52,15 +52,19 @@ endmenu
menu "Platform"
######################### config options of bsp #####################
source "../../kernel/liteos_a/platform/Kconfig"
source "platform/Kconfig"
######################### config options of cpu arch ################
source "../../kernel/liteos_a/arch/Kconfig"
source "arch/Kconfig"
######################### config options of rootfs #####################
source "../../kernel/liteos_a/kernel/common/Kconfig"
source "kernel/common/Kconfig"
######################### config options of patchfs #####################
source "../../kernel/liteos_a/kernel/common/patchfs/Kconfig"
source "kernel/common/patchfs/Kconfig"
######################### config options of blackbox #####################
source "kernel/common/blackbox/Kconfig"
######################### config options of hidumper #####################
source "kernel/common/hidumper/Kconfig"
config QUICK_START
bool "Enable QUICK_START"
@@ -71,27 +75,24 @@ config QUICK_START
endmenu
######################### config options of kernel #####################
source "../../kernel/liteos_a/kernel/Kconfig"
source "kernel/Kconfig"
######################### config options of lib ########################
source "../../kernel/liteos_a/lib/Kconfig"
source "lib/Kconfig"
######################### config options of compatibility ##############
menu "Compat"
source "../../kernel/liteos_a/compat/posix/Kconfig"
source "../../kernel/liteos_a/bsd/Kconfig"
source "compat/posix/Kconfig"
source "bsd/Kconfig"
endmenu
######################### config options of framework ##################
#source "../../frameworks/m2mcomm/Kconfig"
######################## config options of filesystem ##################
menu "FileSystem"
source "../../kernel/liteos_a/fs/vfs/Kconfig"
source "../../kernel/liteos_a/fs/fat/Kconfig"
source "../../kernel/liteos_a/fs/ramfs/Kconfig"
source "../../kernel/liteos_a/fs/romfs/Kconfig"
source "../../kernel/liteos_a/fs/nfs/Kconfig"
source "../../kernel/liteos_a/fs/proc/Kconfig"
source "../../kernel/liteos_a/fs/jffs2/Kconfig"
source "fs/vfs/Kconfig"
source "fs/fat/Kconfig"
source "fs/ramfs/Kconfig"
source "fs/romfs/Kconfig"
source "fs/nfs/Kconfig"
source "fs/proc/Kconfig"
source "fs/jffs2/Kconfig"
config ENABLE_READ_BUFFER
bool "Enable read buffer Option"
default n
@@ -117,7 +118,7 @@ config MAX_PATH_CACHE_SIZE
endmenu
######################## config options of net ############################
source "../../kernel/liteos_a/net/Kconfig"
source "net/Kconfig"
######################## config options of debug ########################
menu "Debug"
@@ -219,14 +220,14 @@ config DEBUG_SEMAPHORE
help
Answer Y to enable debug semaphore.
source "../../kernel/liteos_a/shell/Kconfig"
source "shell/Kconfig"
config NET_LWIP_SACK_TFTP
bool "Enable Tftp"
default y
depends on SHELL && NET_LWIP_SACK && DEBUG_VERSION
help
Answer Y to enable LiteOS support tftp cmd and tftp tool.
source "../../kernel/liteos_a/net/telnet/Kconfig"
source "net/telnet/Kconfig"
config SCHED_DEBUG
bool "Enable sched debug Feature"
default n
@@ -265,7 +266,7 @@ config MEM_LEAKCHECK
help
Answer Y to enable record the LR of Function call stack of Mem operation, it can check the mem leak through the infomations of mem node.
config BASE_MEM_NODE_INTEGRITY_CHECK
bool "Enable integrity check or not "
bool "Enable integrity check or not"
default n
depends on DEBUG_VERSION && MEM_DEBUG
config MEM_WATERLINE
@@ -290,20 +291,25 @@ config DRIVERS
help
Answer Y to enable LiteOS support driver.
source "../../kernel/liteos_a/bsd/dev/usb/Kconfig"
source "bsd/dev/usb/Kconfig"
source "../../drivers/adapter/khdf/liteos/Kconfig"
# Device driver Kconfig import
osource "$(DEVICE_PATH)/Kconfig"
osource "$(DEVICE_PATH)/config/Kconfig"
source "drivers/char/mem/Kconfig"
source "drivers/char/quickstart/Kconfig"
source "drivers/char/random/Kconfig"
source "../../drivers/liteos/tzdriver/Kconfig"
source "drivers/char/video/Kconfig"
source "../../drivers/liteos/tzdriver/Kconfig"
source "../../drivers/liteos/hievent/Kconfig"
endmenu
menu "Security"
source "../../kernel/liteos_a/security/Kconfig"
source "security/Kconfig"
endmenu
menu "Test"

View File

@@ -47,22 +47,17 @@ ROOTFS = rootfs
LITEOS_TARGET = liteos
LITEOS_LIBS_TARGET = libs_target
LITEOS_MENUCONFIG_H = $(LITEOSTOPDIR)/include/generated/autoconf.h
LITEOS_PLATFORM_BASE = $(LITEOSTOPDIR)/platform
export CONFIG_=LOSCFG_
MENUCONFIG_PATH = $(LITEOSTOPDIR)/tools/menuconfig
KCONFIG_FILE_PATH = $(LITEOSTOPDIR)/Kconfig
ifeq ($(OS), Linux)
MENUCONFIG_MCONF := $(MENUCONFIG_PATH)/mconf
MENUCONFIG_CONF := $(MENUCONFIG_PATH)/conf
else
MENUCONFIG_MCONF := $(MENUCONFIG_PATH)/kconfig-mconf.exe
MENUCONFIG_CONF := $(MENUCONFIG_PATH)/kconfig-conf.exe
ifeq ($(PRODUCT_PATH),)
export PRODUCT_PATH=$(LITEOSTOPDIR)/../../device/hisilicon/drivers
endif
$(shell env CONFIG_=$(CONFIG_) $(MENUCONFIG_CONF) -s --olddefconfig $(KCONFIG_FILE_PATH))
ifeq ($(shell which menuconfig),)
$(shell pip install --user kconfiglib >/dev/null)
endif
$(shell env CONFIG_=$(CONFIG_) PRODUCT_PATH=$(PRODUCT_PATH) olddefconfig >/dev/null)
-include $(LITEOSTOPDIR)/tools/build/config.mk
@@ -82,6 +77,9 @@ ROOTFS_DIR = $(OUT)/rootfs
ROOTFS_ZIP = $(OUT)/rootfs.zip
VERSION =
SYSROOT_PATH ?= $(LITEOSTOPDIR)/../../prebuilts/lite/sysroot
export SYSROOT_PATH
all: $(OUT) $(BUILD) $(LITEOS_TARGET) $(APPS)
lib: $(OUT) $(BUILD) $(LITEOS_LIBS_TARGET)
@@ -113,6 +111,15 @@ else
$(HIDE)$(SCRIPTS_PATH)/mklibversion.sh
endif
##### make sysroot #####
sysroot:
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
ifeq ($(wildcard $(SYSROOT_PATH)/usr/include/$(LLVM_TARGET)/),)
$(HIDE)$(MAKE) -C $(SYSROOT_PATH)/build TARGETS=liteos_a_user
endif
$(HIDE)echo "sysroot:" $(abspath $(SYSROOT_PATH))
endif
##### make dynload #####
-include $(LITEOS_MK_PATH)/dynload.mk
@@ -129,26 +136,21 @@ $(OUT): $(LITEOS_MENUCONFIG_H)
$(BUILD):
$(HIDE)mkdir -p $(BUILD)
$(LITEOS_LIBS_TARGET): $(__LIBS)
$(LITEOS_LIBS_TARGET): $(__LIBS) sysroot
$(HIDE)for dir in $(LIB_SUBDIRS); \
do $(MAKE) -C $$dir all || exit 1; \
done
$(HIDE)echo "=============== make lib done ==============="
##### make menuconfig #####
menuconfig:$(MENUCONFIG_MCONF)
$< $(KCONFIG_FILE_PATH)
genconfig:$(MENUCONFIG_CONF)
$(HIDE)mkdir -p include/config include/generated
$< --olddefconfig $(KCONFIG_FILE_PATH)
$< --silentoldconfig $(KCONFIG_FILE_PATH)
menuconfig:
$(HIDE)menuconfig
##### menuconfig end #######
$(LITEOS_MENUCONFIG_H): .config
$(HIDE)$(MAKE) genconfig
$(HIDE)genconfig
$(LITEOS_TARGET): $(__LIBS)
$(LITEOS_TARGET): $(__LIBS) sysroot
$(HIDE)touch $(LOSCFG_ENTRY_SRC)
$(HIDE)for dir in $(LITEOS_SUBDIRS); \
@@ -162,14 +164,14 @@ $(LITEOS_TARGET): $(__LIBS)
$(OBJDUMP) -d $(OUT)/$@ >$(OUT)/$@.asm
# $(NM) -S --size-sort $(OUT)/$@ >$(OUT)/$@.size
$(APPS): $(LITEOS_TARGET)
$(APPS): $(LITEOS_TARGET) sysroot
$(HIDE)$(MAKE) -C apps all
prepare:
$(HIDE)mkdir -p $(OUT)/musl
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
$(HIDE)cp -f $(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/usr/lib/$(LLVM_TARGET)/a7_softfp_neon-vfpv4/libc.so $(OUT)/musl
$(HIDE)cp -f $(LITEOS_COMPILER_PATH)/lib/$(LLVM_TARGET)/c++/a7_softfp_neon-vfpv4/libc++.so $(OUT)/musl
$(HIDE)cp -f $$($(CC) --target=$(LLVM_TARGET) --sysroot=$(SYSROOT_PATH) $(LITEOS_CFLAGS) -print-file-name=libc.so) $(OUT)/musl
$(HIDE)cp -f $$($(GPP) --target=$(LLVM_TARGET) --sysroot=$(SYSROOT_PATH) $(LITEOS_CXXFLAGS) -print-file-name=libc++.so) $(OUT)/musl
else
$(HIDE)cp -f $(LITEOS_COMPILER_PATH)/target/usr/lib/libc.so $(OUT)/musl
$(HIDE)cp -f $(LITEOS_COMPILER_PATH)/arm-linux-musleabi/lib/libstdc++.so.6 $(OUT)/musl
@@ -179,7 +181,7 @@ endif
$(ROOTFSDIR): prepare $(APPS)
$(HIDE)$(MAKE) clean -C apps
$(HIDE)$(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsdir.sh $(OUT)/bin $(OUT)/musl $(ROOTFS_DIR) $(LITEOS_TARGET_DIR)
$(HIDE)$(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsdir.sh $(OUT) $(ROOTFS_DIR) $(LITEOS_TARGET_DIR)
ifneq ($(VERSION),)
$(HIDE)$(LITEOSTOPDIR)/tools/scripts/make_rootfs/releaseinfo.sh "$(VERSION)" $(ROOTFS_DIR) $(LITEOS_TARGET_DIR)
endif
@@ -211,10 +213,11 @@ update_all_config:
$(HIDE)shopt -s globstar && for f in tools/build/config/**/*.config ; \
do \
echo updating $$f; \
test -f $$f && cp $$f .config && $(MENUCONFIG_CONF) -s --olddefconfig $(KCONFIG_FILE_PATH) && $(MENUCONFIG_CONF) --savedefconfig $$f $(KCONFIG_FILE_PATH); \
test -f $$f && cp $$f .config && olddefconfig && savedefconfig --out $$f; \
done
%.config:
$(HIDE)test -f tools/build/config/$@ && cp tools/build/config/$@ .config && $(MENUCONFIG_MCONF) $(KCONFIG_FILE_PATH) && $(MENUCONFIG_CONF) --savedefconfig tools/build/config/$@ $(KCONFIG_FILE_PATH)
update_config:
$(HIDE)test -f "$(CONFIG)" && cp "$(CONFIG)" .config && menuconfig && savedefconfig --out "$(CONFIG)"
.PHONY: all lib clean cleanall $(LITEOS_TARGET) debug release help update_all_config
.PHONY: all lib clean cleanall $(LITEOS_TARGET) debug release help update_all_config update_config
.PHONY: prepare sysroot cleanrootfs $(ROOTFS) $(ROOTFSDIR) $(APPS) menuconfig $(LITEOS_LIBS_TARGET) $(__LIBS) $(OUT)

View File

@@ -15,7 +15,8 @@
OpenHarmony LiteOS-A內核是基於Huawei LiteOS內核演進發展的新一代內核Huawei LiteOS是面向IoT領域構建的輕量級物聯網操作系統。在IoT產業高速發展的潮流中OpenHarmony LiteOS-A內核能夠帶給用戶小體積、低功耗、高性能的體驗以及統一開放的生態系統能力新增了豐富的內核機制、更加全面的POSIX標準接口以及統一驅動框架**HDF**OpenHarmony Driver Foundation為設備廠商提供了更統一的接入方式為OpenHarmony的應用開發者提供了更友好的開發體驗。圖1為OpenHarmony LiteOS-A內核架構圖
**圖 1** OpenHarmony LiteOS-A內核架構圖<a name="fig27311582210"></a>
![](figures/OpenHarmony-LiteOS-A內核架構圖.png "OpenHarmony-LiteOS-A內核架構圖")
![](figures/OpenHarmony-LiteOS-A内核架构图.png "OpenHarmony-LiteOS-A內核架構圖")
## 目錄<a name="section161941989596"></a>
@@ -67,31 +68,31 @@ OpenHarmony LiteOS-A內核是基於Huawei LiteOS內核演進發展的新一代
## 使用說明<a name="section741617511812"></a>
OpenHarmony LiteOS-A內核支持Hi3518EV300[介紹](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Hi3518%E5%BC%80%E5% 8F%91%E6%9D%BF%E4%BB%8B%E7%BB%8D.md)、Hi3516DV300[介紹](https://gitee.com/openharmony/docs/blob/master/zh- cn/device-dev/quick-start/Hi3516%E5%BC%80%E5%8F%91%E6%9D%BF%E4%BB%8B%E7%BB%8D.md))單板,開發者可基於兩種單板開發運行自己的應用程序。
OpenHarmony LiteOS-A內核支持Hi3518EV300[介紹](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Hi3518%E5%BC%80%E5%8F%91%E6%9D%BF%E4%BB%8B%E7%BB%8D.md)、Hi3516DV300[介紹](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Hi3516%E5%BC%80%E5%8F%91%E6%9D%BF%E4%BB%8B%E7%BB%8D.md))單板,開發者可基於兩種單板開發運行自己的應用程序。
### 準備<a name="section1579912573329"></a>
開發者需要在Linux上搭建編譯環境
- Hi3518EV300單板參考[環境搭建](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/%E6%90%AD%E5%BB% BA%E7%8E%AF%E5%A2%83.md)
- Hi3516DV300單板參考[環境搭建](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Hi3516%E6%90%AD%E5%BB %BA%E7%8E%AF%E5%A2%83.md)。
- Hi3518EV300單板參考[環境搭建](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Hi3516%E5%BC%80%E5%8F%91%E6%9D%BF%E4%BB%8B%E7%BB%8D.md)
- Hi3516DV300單板參考[環境搭建](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Hi3516%E6%90%AD%E5%BB%BA%E7%8E%AF%E5%A2%83.md)。
### 獲取源碼<a name="section11443189655"></a>
在Linux服務器上下載並解壓一套源代碼獲取源碼[下載鏈結](https://repo.huaweicloud.com/harmonyos/os/1.0.1/code-1.0.1.tar.gz))。更多源碼獲取方式,參考[源碼獲取](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/%E6%BA%90%E7%A0 %81%E8%8E%B7%E5%8F%96.md)。
在Linux服務器上下載並解壓一套源代碼獲取源碼[下載鏈結](https://repo.huaweicloud.com/harmonyos/os/1.0.1/code-1.0.1.tar.gz))。更多源碼獲取方式,參考[源碼獲取](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/%E6%BA%90%E7%A0%81%E8%8E%B7%E5%8F%96.md)。
### 編譯構建<a name="section2081013992812"></a>
開發者開發第一個應用程序可參考:
- [helloworld for Hi3518EV300](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/%E5%BC%80%E5%8F%91Hi3518%E7% AC%AC%E4%B8%80%E4%B8%AA%E7%A4%BA%E4%BE%8B%E7%A8%8B%E5%BA%8F.md)
- [helloworld for Hi3518EV300](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/%E5%BC%80%E5%8F%91Hi3518%E7%AC%AC%E4%B8%80%E4%B8%AA%E7%A4%BA%E4%BE%8B%E7%A8%8B%E5%BA%8F.md)
- [helloworld for Hi3516DV300](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/%E5%BC%80%E5%8F%91Hi3516%E7% AC%AC%E4%B8%80%E4%B8%AA%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%E7%A4%BA%E4%BE% 8B.md)。
- [helloworld for Hi3516DV300](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/%E5%BC%80%E5%8F%91Hi3516%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%E7%A4%BA%E4%BE%8B.md)。
## 相關倉<a name="section1371113476307"></a>
[內核子系統](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E5%86%85%E6%A0%B8%E5%AD%90%E7%B3 %BB%E7%BB%9F.md)
[內核子系統](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E5%86%85%E6%A0%B8%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
[drivers\_liteos](https://gitee.com/openharmony/drivers_liteos/blob/master/README_zh.md)
**kernel\_liteos\_a**
**kernel\_liteos\_a**

View File

@@ -44,7 +44,7 @@ CFLAGS := -std=c99 -fno-exceptions $(BASE_OPTS) $(LITEOS_COPTS_OPTMIZE)
CXXFLAGS := -std=c++11 -fexceptions -fpermissive -frtti $(BASE_OPTS) $(LITEOS_COPTS_OPTMIZE)
LDCFLAGS := -lc
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
LLVM_SYSROOT := --sysroot=$(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/
LLVM_SYSROOT := --sysroot=$(SYSROOT_PATH) $(ARCH_CFLAGS)
LDCXXFLGS := -lc++ -lc++abi -lc
else
BASE_OPTS += -Wl,-z,relro,-z,now

View File

@@ -34,15 +34,16 @@ LITEOSTOPDIR = $(MKSH_DIR)/../../
include $(MKSH_DIR)/../config.mk
APPS_OUT := $(OUT)/bin
ETC_OUT := $(OUT)/etc
BUILD_DIR := $(MKSH_DIR)/build
BUILD_LOG := $(MKSH_DIR)/build.log
TARGET_OS := OpenHarmony
LOCAL_CFLAGS := -flto -fdata-sections -ffunction-sections -Oz -fstack-protector-strong -D_FORTIFY_SOURCE=2 -mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4
LOCAL_CFLAGS += --target=arm-liteos --sysroot=$(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/
LOCAL_CFLAGS := -flto -fdata-sections -ffunction-sections -Oz -fstack-protector-strong -D_FORTIFY_SOURCE=2
LOCAL_CFLAGS += --target=$(LLVM_TARGET) $(LLVM_SYSROOT)
LOCAL_CFLAGS += -DMKSH_DISABLE_TTY_WARNING -DMKSH_SMALL=1 -DMKSH_ASSUME_UTF8=1 -DMKSH_SMALL_BUT_FAST=0 -DMKSH_S_NOVI=1 -DHAVE_CAN_FSTACKPROTECTORSTRONG=1
LOCAL_CFLAGS += -DMKSH_LESS_CMDLINE_EDITING -DMKSH_LESS_BUILDINS -DMKSH_NO_INITCOMS -DADAPT_FOR_LITEOS_A
LOCAL_LDFLAGS := -Wl,--gc-sections -flto -O2
LOCAL_LDFLAGS := -Wl,--gc-sections -flto -O2 --target=$(LLVM_TARGET) $(LLVM_SYSROOT)
all:$(MKSH)
@@ -61,6 +62,8 @@ endif
$(HIDE)$(STRIP) $(MKSH)
$(HIDE)mkdir -p $(APPS_OUT)
$(HIDE)$(CP) $(MKSH) $(APPS_OUT)
$(HIDE)mkdir -p $(ETC_OUT)
$(HIDE)$(CP) -rf $(BUILD_DIR)/.mkshrc $(ETC_OUT)/
clean:
$(HIDE)$(RM) $(MKSH) $(BUILD_DIR) $(BUILD_LOG)

View File

@@ -33,6 +33,8 @@ APP_SUBDIRS :=
ifeq ($(LOSCFG_SHELL), y)
APP_SUBDIRS += shell
APP_SUBDIRS += mksh
APP_SUBDIRS += toybox
endif
ifeq ($(LOSCFG_USER_INIT_DEBUG), y)
@@ -42,9 +44,3 @@ endif
ifeq ($(LOSCFG_NET_LWIP_SACK_TFTP), y)
APP_SUBDIRS += tftp
endif
#only enable for qemu now
ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
APP_SUBDIRS += mksh
APP_SUBDIRS += toybox
endif

View File

@@ -46,8 +46,8 @@ else
$(HIDE)$(CP) $(LITEOSTHIRDPARTY)/$(TOYBOX)/. $(BUILD_DIR)
$(HIDE)$(CP) -p $(LITEOSTHIRDPARTY)/$(TOYBOX)/porting/liteos_a/. $(BUILD_DIR)
endif
$(HIDE)CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong --target=arm-liteos \
--sysroot=$(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/" CC="$(CC)" OUTNAME=$(OUTNAME) \
$(HIDE)CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong --target=$(LLVM_TARGET) $(LLVM_SYSROOT)" CC="$(CC)" OUTNAME=$(OUTNAME) \
LDFLAGS="--target=$(LLVM_TARGET) $(LLVM_SYSROOT)" \
make -C $(BUILD_DIR) toybox -j> $(BUILD_LOG) 2>&1
$(HIDE)$(CP) $(BUILD_DIR)/$(TOYBOX) .
$(HIDE)$(STRIP) $(TOYBOX)

View File

@@ -65,7 +65,7 @@ LITEOS_FPU_OPTS := -mfpu=$(LOSCFG_ARCH_FPU)
LITEOS_GCCLIB := $(subst cortex-,,$(LOSCFG_ARCH_CPU))_softfp_$(LOSCFG_ARCH_FPU)
endif
LITEOS_CORE_COPTS = $(LITEOS_CPU_OPTS) $(LITEOS_FLOAT_OPTS) $(LITEOS_FPU_OPTS)
LITEOS_CORE_COPTS = $(or $(ARCH_CFLAGS),$(LITEOS_CPU_OPTS) $(LITEOS_FLOAT_OPTS) $(LITEOS_FPU_OPTS))
LITEOS_INTERWORK += $(LITEOS_CORE_COPTS)
LITEOS_NODEBUG += $(LITEOS_CORE_COPTS)
LITEOS_ASOPTS += $(LITEOS_CPU_OPTS)

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2021-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.
*/
#ifndef _ARM_USER_CLEAR_H
#define _ARM_USER_CLEAR_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
size_t _arm_clear_user(void *addr, size_t bytes);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _ARM_USER_CLEAR_H */

View File

@@ -145,7 +145,7 @@ STATIC INLINE VOID ArchCurrUserTaskSet(UINTPTR val)
STATIC INLINE UINT32 ArchCurrCpuid(VOID)
{
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
return ARM_SYSREG_READ(MPIDR) & MPIDR_CPUID_MASK;
#else
return 0;

View File

@@ -0,0 +1,100 @@
/*
* Copyright (c) 2021-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 "asm.h"
.syntax unified
.arm
// size_t _arm_clear_user(void *addr, size_t bytes)
FUNCTION(_arm_clear_user)
push {r0-r6, lr}
cmp r1, #0
beq .Lclear_user_return
tst r0, #7
beq .Lclear_user_aligned
.Lclear_user_byte:
mov r2, #0
0: strb r2, [r0], #1
subs r1, r1, #1
beq .Lclear_user_return
tst r0, #7
bne 0b
.Lclear_user_aligned:
eor r3, r3
eor r4, r4
bics r2, r1, #15
bne .Lclear_user_16bytes
bics r2, r1, #7
bne .Lclear_user_8bytes
b .Lclear_user_remaining
.Lclear_user_16bytes:
eor r5, r5
eor r6, r6
1: stmia r0!, {r3, r4, r5, r6}
subs r2, r2, #16
bne 1b
ands r1, r1, #15
beq .Lclear_user_return
bics r2, r1, #7
beq .Lclear_user_remaining
.Lclear_user_8bytes:
2: stmia r0!, {r3, r4}
ands r1, r1, #7
beq .Lclear_user_return
.Lclear_user_remaining:
mov r2, #0
3: strb r2, [r0], #1
subs r1, r1, #1
bne 3b
.Lclear_user_return:
pop {r0-r6, lr}
mov r0, #0
bx lr
.Lclear_user_err:
pop {r0, r1}
sub r0, r2, r0
sub r0, r1, r0
pop {r2-r6, lr}
bx lr
.pushsection __exc_table, "a"
.long 0b, .Lclear_user_err
.long 1b, .Lclear_user_err
.long 2b, .Lclear_user_err
.long 3b, .Lclear_user_err
.popsection

View File

@@ -51,7 +51,7 @@
__attribute__((aligned(MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS))) \
__attribute__((section(".bss.prebss.translation_table"))) UINT8 \
g_firstPageTable[MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS];
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
__attribute__((aligned(MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS))) \
__attribute__((section(".bss.prebss.translation_table"))) UINT8 \
g_tempPageTable[MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS];
@@ -218,7 +218,7 @@ STATIC UINT32 OsCvtSecCacheFlagsToMMUFlags(UINT32 flags)
switch (flags & VM_MAP_REGION_FLAG_CACHE_MASK) {
case VM_MAP_REGION_FLAG_CACHED:
mmuFlags |= MMU_DESCRIPTOR_L1_TYPE_NORMAL_WRITE_BACK_ALLOCATE;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
mmuFlags |= MMU_DESCRIPTOR_L1_SECTION_SHAREABLE;
#endif
break;
@@ -544,7 +544,7 @@ STATIC UINT32 OsCvtPte2CacheFlagsToMMUFlags(UINT32 flags)
switch (flags & VM_MAP_REGION_FLAG_CACHE_MASK) {
case VM_MAP_REGION_FLAG_CACHED:
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
mmuFlags |= MMU_DESCRIPTOR_L2_SHAREABLE;
#endif
mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_NORMAL_WRITE_BACK_ALLOCATE;
@@ -871,7 +871,7 @@ STATIC VOID OsSetKSectionAttr(UINTPTR virtAddr, BOOL uncached)
kSpace->archMmu.virtTtb = (PTE_T *)g_firstPageTable;
kSpace->archMmu.physTtb = LOS_PaddrQuery(kSpace->archMmu.virtTtb);
status = LOS_ArchMmuUnmap(&kSpace->archMmu, virtAddr,
(bssEndBoundary - virtAddr) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT);
(bssEndBoundary - virtAddr) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT);
if (status != ((bssEndBoundary - virtAddr) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) {
VM_ERR("unmap failed, status: %d", status);
return;
@@ -882,8 +882,8 @@ STATIC VOID OsSetKSectionAttr(UINTPTR virtAddr, BOOL uncached)
flags |= VM_MAP_REGION_FLAG_UNCACHED;
}
status = LOS_ArchMmuMap(&kSpace->archMmu, virtAddr, SYS_MEM_BASE,
(textStart - virtAddr) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT,
flags);
(textStart - virtAddr) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT,
flags);
if (status != ((textStart - virtAddr) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) {
VM_ERR("mmap failed, status: %d", status);
return;
@@ -910,9 +910,9 @@ STATIC VOID OsSetKSectionAttr(UINTPTR virtAddr, BOOL uncached)
flags |= VM_MAP_REGION_FLAG_UNCACHED;
}
status = LOS_ArchMmuMap(&kSpace->archMmu, bssEndBoundary,
SYS_MEM_BASE + bssEndBoundary - virtAddr,
kmallocLength >> MMU_DESCRIPTOR_L2_SMALL_SHIFT,
flags);
SYS_MEM_BASE + bssEndBoundary - virtAddr,
kmallocLength >> MMU_DESCRIPTOR_L2_SMALL_SHIFT,
flags);
if (status != (kmallocLength >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) {
VM_ERR("mmap failed, status: %d", status);
return;

View File

@@ -38,7 +38,6 @@
#include "los_excinfo_pri.h"
#endif
#include "los_sys_stack_pri.h"
#include "los_stackinfo_pri.h"
#ifdef LOSCFG_COREDUMP
#include "los_coredump.h"
#endif
@@ -62,6 +61,9 @@
#ifdef LOSCFG_FS_VFS
#include "console.h"
#endif
#ifdef LOSCFG_BLACKBOX
#include "los_blackbox.h"
#endif
#define INVALID_CPUID 0xFFFF
@@ -75,7 +77,7 @@ VOID OsExcHook(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr);
UINT32 g_curNestCount[LOSCFG_KERNEL_CORE_NUM] = { 0 };
BOOL g_excFromUserMode[LOSCFG_KERNEL_CORE_NUM];
STATIC EXC_PROC_FUNC g_excHook = (EXC_PROC_FUNC)OsExcHook;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
STATIC SPIN_LOCK_INIT(g_excSerializerSpin);
STATIC UINT32 g_currHandleExcPID = OS_INVALID_VALUE;
STATIC UINT32 g_nextExcWaitCpu = INVALID_CPUID;
@@ -531,7 +533,7 @@ STATIC VOID OsExcRestore(VOID)
g_excFromUserMode[currCpuID] = FALSE;
g_intCount[currCpuID] = 0;
g_curNestCount[currCpuID] = 0;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
OsPercpuGet()->excFlag = CPU_RUNNING;
#endif
OsPercpuGet()->taskLockCnt = 0;
@@ -548,7 +550,7 @@ STATIC VOID OsUserExcHandle(ExcContext *excBufAddr)
return;
}
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
LOS_SpinLock(&g_excSerializerSpin);
if (g_nextExcWaitCpu != INVALID_CPUID) {
g_currHandleExcCpuID = g_nextExcWaitCpu;
@@ -563,12 +565,15 @@ STATIC VOID OsUserExcHandle(ExcContext *excBufAddr)
#endif
runProcess->processStatus &= ~OS_PROCESS_FLAG_EXIT;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
#ifdef LOSCFG_FS_VFS
OsWakeConsoleSendTask();
#endif
#endif
#ifdef LOSCFG_BLACKBOX
BBoxNotifyError("USER_CRASH", MODULE_SYSTEM, "Crash in user", 0);
#endif
SCHEDULER_LOCK(intSave);
#ifdef LOSCFG_SAVE_EXCINFO
OsProcessExitCodeCoreDumpSet(runProcess);
@@ -716,14 +721,14 @@ VOID BackTraceSub(UINTPTR regFP)
while (IsValidFP(backFP, stackStart, stackEnd, &kvaddr) == TRUE) {
tmpFP = backFP;
#ifdef LOSCFG_COMPILER_CLANG_LLVM
backFP = *(UINTPTR *)(UINTPTR)kvaddr;
backFP = *(UINTPTR *)(UINTPTR)kvaddr;
if (IsValidFP(tmpFP + POINTER_SIZE, stackStart, stackEnd, &kvaddr) == FALSE) {
PrintExcInfo("traceback backLR check failed, backLP: 0x%x\n", tmpFP + POINTER_SIZE);
return;
}
backLR = *(UINTPTR *)(UINTPTR)kvaddr;
#else
backLR = *(UINTPTR *)(UINTPTR)kvaddr;
backLR = *(UINTPTR *)(UINTPTR)kvaddr;
if (IsValidFP(tmpFP - POINTER_SIZE, stackStart, stackEnd, &kvaddr) == FALSE) {
PrintExcInfo("traceback backFP check failed, backFP: 0x%x\n", tmpFP - POINTER_SIZE);
return;
@@ -909,7 +914,7 @@ VOID OsDataAbortExcHandleEntry(ExcContext *excBufAddr)
#endif /* __LINUX_ARM_ARCH__ */
#endif /* LOSCFG_GDB */
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
#define EXC_WAIT_INTER 50U
#define EXC_WAIT_TIME 2000U
@@ -1007,7 +1012,7 @@ STATIC VOID OsCheckAllCpuStatus(VOID)
OsWaitOtherCoresHandleExcEnd(currCpuID);
} else {
if (g_excFromUserMode[g_currHandleExcCpuID] == TRUE) {
if ((g_currHandleExcCpuID < LOSCFG_KERNEL_CORE_NUM) && (g_excFromUserMode[g_currHandleExcCpuID] == TRUE)) {
g_currHandleExcCpuID = currCpuID;
LOS_SpinUnlock(&g_excSerializerSpin);
target = (UINT32)(OS_MP_CPU_ALL & ~CPUID_TO_AFFI_MASK(currCpuID));
@@ -1027,7 +1032,7 @@ STATIC VOID OsCheckAllCpuStatus(VOID)
STATIC VOID OsCheckCpuStatus(VOID)
{
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
OsCheckAllCpuStatus();
#else
g_currHandleExcCpuID = ArchCurrCpuid();
@@ -1048,7 +1053,7 @@ LITE_OS_SEC_TEXT VOID STATIC OsExcPriorDisposal(ExcContext *excBufAddr)
OsCheckCpuStatus();
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
#ifdef LOSCFG_FS_VFS
/* Wait for the end of the Console task to avoid multicore printing code */
OsWaitConsoleSendTaskPend(OsCurrTaskGet()->taskID);
@@ -1058,6 +1063,11 @@ LITE_OS_SEC_TEXT VOID STATIC OsExcPriorDisposal(ExcContext *excBufAddr)
LITE_OS_SEC_TEXT_INIT STATIC VOID OsPrintExcHead(UINT32 far)
{
#ifdef LOSCFG_BLACKBOX
#ifdef LOSCFG_SAVE_EXCINFO
SetExcInfoIndex(0);
#endif
#endif
#ifdef LOSCFG_KERNEL_VM
/* You are not allowed to add any other print information before this exception information */
if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) {
@@ -1113,7 +1123,7 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAd
OsPrintExcHead(far);
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
OsAllCpuStatusOutput();
#endif
@@ -1125,7 +1135,9 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAd
if (g_curNestCount[ArchCurrCpuid()] == 1) {
#ifdef LOSCFG_SAVE_EXCINFO
if (func != NULL) {
#ifndef LOSCFG_BLACKBOX
SetExcInfoIndex(0);
#endif
OsSysStateSave(&intCount, &lockCount);
OsRecordExcInfoTime();
OsSysStateRestore(intCount, lockCount);
@@ -1154,6 +1166,9 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAd
}
#endif
#ifdef LOSCFG_BLACKBOX
BBoxNotifyError(EVENT_PANIC, MODULE_SYSTEM, "Crash in kernel", 1);
#endif
while (1) {}
}
@@ -1168,7 +1183,7 @@ __attribute__((noinline)) VOID LOS_Panic(const CHAR *fmt, ...)
}
/* stack protector */
UINT32 __stack_chk_guard = 0xd00a0dff;
USED UINT32 __stack_chk_guard = 0xd00a0dff;
VOID __stack_chk_fail(VOID)
{
@@ -1200,7 +1215,11 @@ VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 recordCount, UINT32 jumpCou
framePtr = Get_Fp();
while ((framePtr > stackStart) && (framePtr < stackEnd) && IS_ALIGNED(framePtr, sizeof(CHAR *))) {
tmpFramePtr = framePtr;
#ifdef LOSCFG_COMPILER_CLANG_LLVM
linkReg = *(UINTPTR *)(tmpFramePtr + sizeof(UINTPTR));
#else
linkReg = *(UINTPTR *)framePtr;
#endif
if (index >= jumpCount) {
LR[count++] = linkReg;
if (count == recordCount) {
@@ -1208,7 +1227,11 @@ VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 recordCount, UINT32 jumpCou
}
}
index++;
#ifdef LOSCFG_COMPILER_CLANG_LLVM
framePtr = *(UINTPTR *)framePtr;
#else
framePtr = *(UINTPTR *)(tmpFramePtr - sizeof(UINTPTR));
#endif
}
/* if linkReg is not enough,clean up the last of the effective LR as the end. */

View File

@@ -31,6 +31,7 @@
#include "user_copy.h"
#include "arm_user_copy.h"
#include "arm_user_clear.h"
#include "securec.h"
#include "los_memory.h"
#include "los_vm_map.h"
@@ -96,15 +97,9 @@ INT32 LOS_UserMemClear(unsigned char *buf, UINT32 len)
if (!LOS_IsUserAddressRange((vaddr_t)(UINTPTR)buf, len)) {
(VOID)memset_s(buf, len, 0, len);
} else {
unsigned char *tmp = (unsigned char *)LOS_MemAlloc(OS_SYS_MEM_ADDR, len);
if (tmp == NULL) {
return -ENOMEM;
if (_arm_clear_user(buf, len)) {
return -EFAULT;
}
(VOID)memset_s(tmp, len, 0, len);
if (_arm_user_copy(buf, tmp, len) != 0) {
ret = -EFAULT;
}
LOS_MemFree(OS_SYS_MEM_ADDR, tmp);
}
return ret;
}

View File

@@ -40,7 +40,7 @@ STATIC_ASSERT(OS_USER_HWI_MAX <= 1020, "hwi max is too large!");
STATIC UINT32 g_curIrqNum = 0;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
/*
* filter description
* 0b00: forward to the cpu interfaces specified in cpu_mask
@@ -144,7 +144,7 @@ VOID HalIrqInit(VOID)
/* enable gic distributor control */
GIC_REG_32(GICD_CTLR) = 1;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
/* register inter-processor interrupt */
(VOID)LOS_HwiCreate(LOS_MP_IPI_WAKEUP, 0xa0, 0, OsMpWakeHandler, 0);
(VOID)LOS_HwiCreate(LOS_MP_IPI_SCHEDULE, 0xa0, 0, OsMpScheduleHandler, 0);

View File

@@ -48,7 +48,7 @@ STATIC INLINE UINT64 MpidrToAffinity(UINT64 mpidr)
(MPIDR_AFF_LEVEL(mpidr, 0)));
}
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
STATIC UINT32 NextCpu(UINT32 cpu, UINT32 cpuMask)
{
@@ -399,7 +399,7 @@ VOID HalIrqInit(VOID)
HalIrqInitPercpu();
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
/* register inter-processor interrupt */
LOS_HwiCreate(LOS_MP_IPI_WAKEUP, 0xa0, 0, OsMpWakeHandler, 0);
LOS_HwiCreate(LOS_MP_IPI_SCHEDULE, 0xa0, 0, OsMpScheduleHandler, 0);

View File

@@ -49,7 +49,7 @@ extern VOID HalIrqClear(UINT32 vector);
extern CHAR *HalIrqVersion(VOID);
extern UINT32 HalCurIrqGet(VOID);
extern UINT32 HalIrqSetPrio(UINT32 vector, UINT8 priority);
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
extern VOID HalIrqSendIpi(UINT32 target, UINT32 ipi);
extern VOID HalIrqSetAffinity(UINT32 vector, UINT32 cpuMask);
#endif

View File

@@ -15,7 +15,7 @@ config DRIVERS_USB_HOST_DRIVER
choice
depends on DRIVERS_USB_HOST_DRIVER
prompt "USB HCD"
default y
default DRIVERS_USB_HOST_EHCI
help
Enable EHCI for USB 2.0.
Enable XHCI for USB 3.0

View File

@@ -30,44 +30,65 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set -e
echo "sh param:$1,$2,$3,$4,$5,$6,$7"
destination=".config"
config_file=""
tee=""
outdir="../..$3/test_info/gen/kernel/test"
if [ "$5" = "tee" ]; then
tee="_tee"
fi
product_name="$(basename $7)"
source="tools/build/config/${product_name}_release.config"
if [ "$2" = "clang" ]; then
if [ "$4" = "debug" ]; then
config_file="${product_name}_$2$tee.config"
source="tools/build/config/debug/$config_file"
else
config_file="${product_name}_$2_release$tee.config"
source="tools/build/config/$config_file"
fi
elif [ "$2" = "gcc" ]; then
if [ "$4" = "debug" ]; then
config_file="${product_name}_debug_shell$tee.config"
source="tools/build/config/$config_file"
else
config_file="${product_name}_release$tee.config"
source="tools/build/config/$config_file"
fi
fi
if [ -d "./out" ]; then
rm -rf ./out
fi
if [ -f "$destination" ]; then
rm -rf $destination
fi
if [ ! -f "$source" ]; then
source="$7/config/sys/$config_file"
fi
cp $source $destination
board_name=${1}
ohos_build_compiler=${2}
root_build_dir=${3}
ohos_build_type=${4}
tee_enable=${5}
device_company=${6}
product_path=${7}
outdir=${8}
ohos_version=${9}
sysroot_path=${10}
arch_cflags=${11}
device_path=${12}
mkdir -p $outdir
cp kernel_test.sources $outdir
echo "${board_name}" "${device_company}"
echo "sh param:" "$@"
function main() {
destination=".config"
tee=""
if [ "${tee_enable}" = "true" ]; then
tee="_tee"
fi
config_file="${product_path}/config/${ohos_build_type}${tee}.config"
if [ -f "${config_file}" ]; then
cp "${config_file}" "${destination}"
return
fi
product_name=$(basename "${product_path}")
config_file="${product_name}_release.config"
if [ "${ohos_build_compiler}" = "clang" ]; then
if [ "${ohos_build_type}" = "debug" ]; then
config_file="debug/${product_name}_${ohos_build_compiler}${tee}.config"
else
config_file="${product_name}_${ohos_build_compiler}_release${tee}.config"
fi
elif [ "${ohos_build_compiler}" = "gcc" ]; then
if [ "${ohos_build_type}" = "debug" ]; then
config_file="${product_name}_debug_shell${tee}.config"
else
config_file="${product_name}_release${tee}.config"
fi
fi
cp "tools/build/config/${config_file}" "${destination}"
}
if [ "x" != "x${sysroot_path}" ]; then
export SYSROOT_PATH=${sysroot_path}
fi
if [ "x" != "x${arch_cflags}" ]; then
export ARCH_CFLAGS="${arch_cflags}"
fi
export OUTDIR="${outdir}"
export PRODUCT_PATH="${product_path}"
export DEVICE_PATH="${device_path}"
main && \
make clean && \
make -j rootfs VERSION="${ohos_version}"

View File

@@ -204,7 +204,7 @@ STATIC UINT32 InitPthreadData(pthread_t threadID, pthread_attr_t *userAttr,
PRINT_ERR("%s: %d, err: %d\n", __FUNCTION__, __LINE__, err);
return LOS_NOK;
}
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
if (userAttr->cpuset.__bits[0] > 0) {
taskCB->cpuAffiMask = (UINT16)userAttr->cpuset.__bits[0];
}

View File

@@ -49,7 +49,7 @@ int pthread_attr_init(pthread_attr_t *attr)
attr->stacksize_set = 1;
attr->stacksize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
attr->cpuset.__bits[0] = 0;
#endif
@@ -239,7 +239,7 @@ int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stackSize)
*/
int pthread_attr_setaffinity_np(pthread_attr_t* attr, size_t cpusetsize, const cpu_set_t* cpuset)
{
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
if (attr == NULL) {
return EINVAL;
}
@@ -264,7 +264,7 @@ int pthread_attr_setaffinity_np(pthread_attr_t* attr, size_t cpusetsize, const c
*/
int pthread_attr_getaffinity_np(const pthread_attr_t* attr, size_t cpusetsize, cpu_set_t* cpuset)
{
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
if ((attr == NULL) || (cpuset == NULL) || (cpusetsize != sizeof(cpu_set_t))) {
return EINVAL;
}

View File

@@ -61,7 +61,7 @@ int sched_get_priority_max(int policy)
*/
int sched_setaffinity(pid_t pid, size_t set_size, const cpu_set_t* set)
{
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
UINT32 taskID = (UINT32)pid;
UINT32 ret;
@@ -93,7 +93,7 @@ int sched_setaffinity(pid_t pid, size_t set_size, const cpu_set_t* set)
*/
int sched_getaffinity(pid_t pid, size_t set_size, cpu_set_t* set)
{
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
UINT32 taskID = (UINT32)pid;
UINT16 cpuAffiMask;

View File

@@ -456,7 +456,7 @@ static int PthreadGetCputime(clockid_t clockID, struct timespec *ats)
{
uint64_t runtime;
UINT32 intSave;
UINT32 tid = ((UINT32) ~((clockID) >> CPUCLOCK_ID_OFFSET));
UINT32 tid = ((UINT32) ~((UINT32)(clockID) >> CPUCLOCK_ID_OFFSET));
if (OS_TID_CHECK_INVALID(tid)) {
return -EINVAL;
@@ -482,7 +482,7 @@ static int ProcessGetCputime(clockid_t clockID, struct timespec *ats)
{
UINT64 runtime;
UINT32 intSave;
const pid_t pid = ((pid_t) ~((clockID) >> CPUCLOCK_ID_OFFSET));
const pid_t pid = ((pid_t) ~((UINT32)(clockID) >> CPUCLOCK_ID_OFFSET));
LosProcessCB *spcb = NULL;
if (OsProcessIDUserCheckInvalid(pid) || pid < 0) {
@@ -524,7 +524,7 @@ static int GetCputime(clockid_t clockID, struct timespec *tp)
static int CheckClock(const clockid_t clockID)
{
int error = 0;
const pid_t pid = ((pid_t) ~((clockID) >> CPUCLOCK_ID_OFFSET));
const pid_t pid = ((pid_t) ~((UINT32)(clockID) >> CPUCLOCK_ID_OFFSET));
if (!((UINT32)clockID & CPUCLOCK_PERTHREAD_MASK)) {
LosProcessCB *spcb = NULL;

View File

@@ -725,6 +725,9 @@ INT32 los_alloc_diskid_byname(const CHAR *diskName);
*/
INT32 los_get_diskid_byname(const CHAR *diskName);
los_disk *los_get_mmcdisk_bytype(UINT8 type);
#ifdef __cplusplus
#if __cplusplus
}

View File

@@ -187,6 +187,22 @@ INT32 los_get_diskid_byname(const CHAR *diskName)
return diskID;
}
los_disk *los_get_mmcdisk_bytype(UINT8 type)
{
const CHAR *mmcDevHead = "/dev/mmcblk";
for (INT32 diskId = 0; diskId < SYS_MAX_DISK; diskId++) {
los_disk *disk = get_disk(diskId);
if (disk == NULL) {
continue;
} else if ((disk->type == type) && (strncmp(disk->disk_name, mmcDevHead, strlen(mmcDevHead)) == 0)) {
return disk;
}
}
PRINT_ERR("Cannot find the mmc disk!\n");
return NULL;
}
VOID OsSetUsbStatus(UINT32 diskID)
{
if (diskID < SYS_MAX_DISK) {
@@ -328,11 +344,7 @@ static INT32 DiskAddPart(los_disk *disk, UINT64 sectorStart, UINT64 sectorCount,
VnodeHold();
VnodeLookup(devName, &partDev, 0);
if (ret < 0) {
VnodeDrop();
PRINT_ERR("DiskAddPart : find %s fail!\n", devName);
return VFS_ERROR;
}
part = DiskPartAllocate(partDev, sectorStart, sectorCount);
VnodeDrop();
if (part == NULL) {

View File

@@ -65,7 +65,7 @@ static int RandomHwClose(struct file *filep)
static int RandomHwIoctl(struct file *filep, int cmd, unsigned long arg)
{
int ret;
int ret = -1;
switch (cmd) {
default:
@@ -77,7 +77,7 @@ static int RandomHwIoctl(struct file *filep, int cmd, unsigned long arg)
static ssize_t RandomHwRead(struct file *filep, char *buffer, size_t buflen)
{
int ret;
int ret = -1;
if (g_randomOp.read != NULL) {
ret = g_randomOp.read(buffer, buflen);

View File

@@ -39,7 +39,7 @@ LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/../../device/hisilicon/drivers/include/mtd/common/include
ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/../../device/qemu/arm_virt/config/cfiflash
LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/../../device/qemu/drivers/cfiflash
endif
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)

View File

@@ -46,6 +46,7 @@
#include "los_tables.h"
#include "user_copy.h"
#include "los_vm_filemap.h"
#include "los_hash.h"
#include <time.h>
#include <errno.h>
#include <dirent.h>
@@ -53,7 +54,7 @@
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "los_hash.h"
#include <fcntl.h>
struct VnodeOps fatfs_vops; /* forward define */
@@ -190,7 +191,7 @@ static int fatfs_sync(unsigned long mountflags, FATFS *fs)
{
#ifdef LOSCFG_FS_FAT_CACHE
los_part *part = NULL;
if (mountflags != MS_NOSYNC) {
if (!(mountflags & (MS_NOSYNC | MS_RDONLY))) {
part = get_part((INT)fs->pdrv);
if (part == NULL) {
return -ENODEV;
@@ -238,7 +239,8 @@ static mode_t fatfs_get_mode(BYTE attribute, mode_t fs_mode)
return fs_mode;
}
static enum VnodeType fatfstype_2_vnodetype(BYTE type) {
static enum VnodeType fatfstype_2_vnodetype(BYTE type)
{
switch (type) {
case AM_ARC:
return VNODE_TYPE_REG;
@@ -251,11 +253,13 @@ static enum VnodeType fatfstype_2_vnodetype(BYTE type) {
}
}
static FRESULT init_cluster(DIR *dp_new, FATFS *fs, int type, const char *target, DWORD *clust)
#define DIR_SIZE 32
static FRESULT init_cluster(DIR_FILE *pdfp, DIR *dp_new, FATFS *fs, int type, const char *target, DWORD *clust)
{
FRESULT result;
BYTE *dir = NULL;
QWORD sect;
DWORD pclust;
UINT n;
/* Allocate a new cluster */
@@ -284,24 +288,52 @@ static FRESULT init_cluster(DIR *dp_new, FATFS *fs, int type, const char *target
mem_set(dir, 0, SS(fs));
if (type == AM_LNK && target) {
/* Write target to symlink */
strcpy_s((char *)dir, SS(fs), target);
}
for (n = fs->csize; n > 0; n--) {
#ifndef LOSCFG_FS_FAT_VIRTUAL_PARTITION
fs->winsect = sect++;
fs->wflag = 1;
#else
PARENTFS(fs)->winsect = sect++;
PARENTFS(fs)->wflag = 1;
#endif
result = sync_window(fs);
if (result != FR_OK) {
remove_chain(&(dp_new->obj), *clust, 0);
return result;
(void)strcpy_s((char *)dir, SS(fs), target);
} else {
/* Write the dir cluster */
mem_set(dir, 0, SS(fs));
mem_set(dir + DIR_Name, ' ', 11); /* Create "." entry */
dir[DIR_Name] = '.';
dir[DIR_Attr] = AM_DIR;
st_clust(fs, dir, *clust);
mem_cpy(dir + DIR_SIZE, dir, DIR_SIZE); /* Create ".." entry */
dir[DIR_SIZE + 1] = '.'; /* Add extra "." */
pclust = pdfp->fno.sclst;
if (fs->fs_type == FS_FAT32 && pclust == fs->dirbase) {
pclust = 0;
}
if (type == AM_LNK) {
/* No need to clean the rest sectors of the cluster for symlink */
break;
st_clust(fs, dir + DIR_SIZE, pclust);
}
#ifndef LOSCFG_FS_FAT_VIRTUAL_PARTITION
fs->winsect = sect++;
fs->wflag = 1;
#else
PARENTFS(fs)->winsect = sect++;
PARENTFS(fs)->wflag = 1;
#endif
result = sync_window(fs);
if (result != FR_OK) {
remove_chain(&(dp_new->obj), *clust, 0);
return result;
}
/* Rest of directory cluster should set to be zero */
if (type == AM_DIR) {
mem_set(dir, 0, SS(fs));
for (n = fs->csize - 1; n > 0; n--) {
#ifndef LOSCFG_FS_FAT_VIRTUAL_PARTITION
fs->winsect = sect++;
fs->wflag = 1;
#else
PARENTFS(fs)->winsect = sect++;
PARENTFS(fs)->wflag = 1;
#endif
result = sync_window(fs);
if (result != FR_OK) {
remove_chain(&(dp_new->obj), *clust, 0);
return result;
}
}
}
@@ -366,7 +398,7 @@ static int fatfs_create_obj(struct Vnode *parent, const char *name, int mode, st
}
if (type == AM_DIR || type == AM_LNK) {
result = init_cluster(dp_new, fs, type, target, &clust);
result = init_cluster(dfp, dp_new, fs, type, target, &clust);
if (result != FR_OK) {
goto ERROR_UNLOCK;
}
@@ -576,7 +608,7 @@ int fatfs_open(struct file *filep)
ret = lock_fs(fs);
if (ret == FALSE) {
ret = EBUSY;
goto ERROR_EXIT;
goto ERROR_FREE;
}
fp->dir_sect = dp->sect;
@@ -595,7 +627,7 @@ int fatfs_open(struct file *filep)
fp->buf = (BYTE*) ff_memalloc(SS(fs));
if (fp->buf == NULL) {
ret = ENOMEM;
goto ERROR_FREE;
goto ERROR_UNLOCK;
}
LOS_ListAdd(&finfo->fp_list, &fp->fp_entry);
unlock_fs(fs, FR_OK);
@@ -603,8 +635,9 @@ int fatfs_open(struct file *filep)
filep->f_priv = fp;
return fatfs_sync(vp->originMount->mountFlags, fs);
ERROR_FREE:
ERROR_UNLOCK:
unlock_fs(fs, FR_OK);
ERROR_FREE:
free(fp);
ERROR_EXIT:
return -ret;
@@ -704,6 +737,7 @@ off64_t fatfs_lseek64(struct file *filep, off64_t offset, int whence)
struct Vnode *vp = filep->f_vnode;
DIR_FILE *dfp = (DIR_FILE *)vp->data;
FILINFO *finfo = &(dfp->fno);
struct Mount *mount = vp->originMount;
FSIZE_t fpos;
FRESULT result;
int ret;
@@ -741,6 +775,17 @@ off64_t fatfs_lseek64(struct file *filep, off64_t offset, int whence)
if (ret == FALSE) {
return -EBUSY;
}
if (fpos > finfo->fsize) {
if ((filep->f_oflags & O_ACCMODE) == O_RDONLY) {
result = FR_DENIED;
goto ERROR_EXIT;
}
if (mount->mountFlags & MS_RDONLY) {
result = FR_WRITE_PROTECTED;
goto ERROR_EXIT;
}
}
fp->obj.sclust = finfo->sclst;
fp->obj.objsize = finfo->fsize;
@@ -872,11 +917,13 @@ int fatfs_fallocate64(struct file *filep, int mode, off64_t offset, off64_t len)
return -EBUSY;
}
result = f_expand(fp, (FSIZE_t)offset, (FSIZE_t)len, 1);
if (result == FR_OK && finfo->sclst == 0) {
finfo->sclst = fp->obj.sclust;
if (result == FR_OK) {
if (finfo->sclst == 0) {
finfo->sclst = fp->obj.sclust;
}
result = f_sync(fp);
}
result = f_sync(fp);
unlock_fs(fs, FR_OK);
unlock_fs(fs, result);
return -fatfs_2_vfs(result);
}
@@ -1745,6 +1792,45 @@ static int fatfs_set_part_info(los_part *part)
return 0;
}
static FRESULT fatfs_setlabel(los_part *part)
{
QWORD start_sector = 0;
BYTE fmt = 0;
FATFS fs;
FRESULT result;
#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
fs.vir_flag = FS_PARENT;
fs.parent_fs = &fs;
fs.vir_amount = DISK_ERROR;
fs.vir_avail = FS_VIRDISABLE;
#endif
if (disk_ioctl(fs.pdrv, GET_SECTOR_SIZE, &(fs.ssize)) != RES_OK) {
return -EIO;
}
fs.win = (BYTE *)ff_memalloc(fs.ssize);
if (fs.win == NULL) {
return -ENOMEM;
}
result = find_fat_partition(&fs, part, &fmt, &start_sector);
if (result != FR_OK) {
free(fs.win);
return -fatfs_2_vfs(result);
}
result = init_fatobj(&fs, fmt, start_sector);
if (result != FR_OK) {
free(fs.win);
return -fatfs_2_vfs(result);
}
result = set_volumn_label(&fs, FatLabel);
free(fs.win);
return result;
}
int fatfs_mkfs (struct Vnode *device, int sectors, int option)
{
BYTE *work_buff = NULL;
@@ -1780,19 +1866,22 @@ int fatfs_mkfs (struct Vnode *device, int sectors, int option)
return -fatfs_2_vfs(result);
}
result = fatfs_setlabel(part);
if (result == FR_OK) {
#ifdef LOSCFG_FS_FAT_CACHE
ret = OsSdSync(part->disk_id);
if (ret != 0) {
return -EIO;
}
ret = OsSdSync(part->disk_id);
if (ret != 0) {
return -EIO;
}
#endif
}
ret = fatfs_set_part_info(part);
if (ret != 0) {
return -EIO;
}
return 0;
return -fatfs_2_vfs(result);
}
int fatfs_mkdir(struct Vnode *parent, const char *name, mode_t mode, struct Vnode **vpp)

View File

@@ -113,6 +113,8 @@ extern "C" {
#define FMT_ANY 0x07
#define FMT_ERASE 0x08
extern char FatLabel[LABEL_LEN];
int fatfs_2_vfs(int result);
int fatfs_lookup(struct Vnode *parent, const char *name, int len, struct Vnode **vpp);
int fatfs_create(struct Vnode *parent, const char *name, int mode, struct Vnode **vpp);

View File

@@ -473,7 +473,7 @@ off64_t file_seek64(struct file *filep, off64_t offset, int whence);
*
****************************************************************************/
int files_allocate(struct Vnode *vnode, int oflags, off_t pos,void *priv, int minfd);
int files_allocate(struct Vnode *vnode, int oflags, off_t pos, void *priv, int minfd);
/****************************************************************************
* Name: files_close

View File

@@ -53,6 +53,7 @@ struct Mount {
uint32_t hashseed; /* Random seed for vfshash */
unsigned long mountFlags; /* Flags for mount */
char pathName[PATH_MAX]; /* path name of mount point */
char devName[PATH_MAX]; /* path name of dev point */
};
struct MountOps {
@@ -61,7 +62,8 @@ struct MountOps {
int (*Statfs)(struct Mount *mount, struct statfs *sbp);
};
typedef int (*foreach_mountpoint_t)(const char *mountpoint,
typedef int (*foreach_mountpoint_t)(const char *devpoint,
const char *mountpoint,
struct statfs *statbuf,
void *arg);

View File

@@ -123,7 +123,7 @@ int VfsJffs2Bind(struct Mount *mnt, struct Vnode *blkDriver, const void *data)
partNo = p->patitionnum;
ret = jffs2_mount(partNo, &rootNode);
ret = jffs2_mount(partNo, &rootNode, mnt->mountFlags);
if (ret != 0) {
LOS_MuxUnlock(&g_jffs2FsLock);
return ret;
@@ -323,7 +323,7 @@ ssize_t VfsJffs2Write(struct file *filep, const char *buffer, size_t bufLen)
c = JFFS2_SB_INFO(node->i_sb);
pos = filep->f_pos;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
struct super_block *sb = node->i_sb;
UINT16 gcCpuMask = LOS_TaskCpuAffiGet(sb->s_gc_thread);
UINT32 curTaskId = LOS_CurTaskIDGet();
@@ -717,14 +717,17 @@ ssize_t VfsJffs2Readlink(struct Vnode *vnode, char *buffer, size_t bufLen)
int VfsJffs2Unlink(struct Vnode *parentVnode, struct Vnode *targetVnode, const char *path)
{
int ret;
struct jffs2_inode *parentInode = (struct jffs2_inode *)parentVnode->data;
struct jffs2_inode *targetInode = (struct jffs2_inode *)targetVnode->data;
struct jffs2_inode *parentInode = NULL;
struct jffs2_inode *targetInode = NULL;
if (!parentVnode || !targetVnode) {
PRINTK("%s-%d parentVnode=%x, targetVnode=%x\n", __FUNCTION__, __LINE__, parentVnode, targetVnode);
return -EINVAL;
}
parentInode = (struct jffs2_inode *)parentVnode->data;
targetInode = (struct jffs2_inode *)targetVnode->data;
LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER);
ret = jffs2_unlink(parentInode, targetInode, (const unsigned char *)path);

View File

@@ -45,6 +45,8 @@ extern "C" {
extern spinlock_t procfsLock;
extern bool procfsInit;
void ProcPmInit(void);
void ProcVmmInit(void);
void ProcProcessInit(void);
@@ -63,6 +65,10 @@ extern void ProcMountsInit(void);
extern void ProcUptimeInit(void);
extern void ProcFsCacheInit(void);
extern void ProcFdInit(void);
#ifdef __cplusplus
#if __cplusplus
}

View File

@@ -89,6 +89,8 @@ struct ProcFileOperations {
};
struct ProcDirEntry {
uint uid;
uint gid;
mode_t mode;
int flags;
const struct ProcFileOperations *procFileOps;

142
fs/proc/os_adapt/fd_proc.c Normal file
View File

@@ -0,0 +1,142 @@
/*
* Copyright (c) 2021-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 "proc_fs.h"
#include <stdbool.h>
#include "fs/file.h"
#include "vfs_config.h"
#include "internal.h"
#include "fs/fd_table.h"
#include "los_process.h"
#include "capability_api.h"
#include "capability_type.h"
/*
* Template: Pid Fd [SysFd ] Name
*/
static void FillFdInfo(struct SeqBuf *seqBuf, struct filelist *fileList, unsigned int pid, bool hasPrivilege)
{
int fd;
int sysFd;
char *name = NULL;
struct file *filp = NULL;
struct fd_table_s *fdt = LOS_GetFdTable(pid);
if ((fdt == NULL) || (fdt->proc_fds == NULL)) {
return;
}
(void)sem_wait(&fdt->ft_sem);
for (fd = MIN_START_FD; fd < fdt->max_fds; fd++) {
if (FD_ISSET(fd, fdt->proc_fds)) {
sysFd = fdt->ft_fds[fd].sysFd;
if (sysFd < CONFIG_NFILE_DESCRIPTORS) {
filp = &fileList->fl_files[sysFd];
name = filp->f_path;
} else if (sysFd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)) {
name = "(socks)";
} else if (sysFd < (FD_SETSIZE + CONFIG_NTIME_DESCRIPTORS)) {
name = "(timer)";
} else if (sysFd < (MQUEUE_FD_OFFSET + CONFIG_NQUEUE_DESCRIPTORS)) {
name = "(mqueue)";
} else {
name = "(unknown)";
}
if (hasPrivilege) {
(void)LosBufPrintf(seqBuf, "%u\t%d\t%d\t%s\n", pid, fd, sysFd, name);
} else {
(void)LosBufPrintf(seqBuf, "%u\t%d\t%s\n", pid, fd, name);
}
}
}
(void)sem_post(&fdt->ft_sem);
}
static int FdProcFill(struct SeqBuf *seqBuf, void *v)
{
int pidNum;
bool hasPrivilege;
unsigned int pidMaxNum;
unsigned int *pidList = NULL;
/* privilege user */
if (IsCapPermit(CAP_DAC_READ_SEARCH)) {
pidMaxNum = LOS_GetSystemProcessMaximum();
pidList = (unsigned int *)malloc(pidMaxNum * sizeof(unsigned int));
if (pidList == NULL) {
return -ENOMEM;
}
pidNum = LOS_GetUsedPIDList(pidList, pidMaxNum);
hasPrivilege = true;
(void)LosBufPrintf(seqBuf, "Pid\tFd\tSysFd\tName\n");
} else {
pidNum = 1;
pidList = (unsigned int *)malloc(pidNum * sizeof(unsigned int));
if (pidList == NULL) {
return -ENOMEM;
}
pidList[0] = LOS_GetCurrProcessID();
hasPrivilege = false;
(void)LosBufPrintf(seqBuf, "Pid\tFd\tName\n");
}
struct filelist *fileList = &tg_filelist;
(void)sem_wait(&fileList->fl_sem);
for (int i = 0; i < pidNum; i++) {
FillFdInfo(seqBuf, fileList, pidList[i], hasPrivilege);
}
free(pidList);
(void)sem_post(&fileList->fl_sem);
return 0;
}
static const struct ProcFileOperations FD_PROC_FOPS = {
.read = FdProcFill,
};
void ProcFdInit(void)
{
struct ProcDirEntry *pde = CreateProcEntry("fd", 0, NULL);
if (pde == NULL) {
PRINT_ERR("creat /proc/fd error.\n");
return;
}
pde->procFileOps = &FD_PROC_FOPS;
}

View File

@@ -0,0 +1,221 @@
/*
* Copyright (c) 2021-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 "internal.h"
#include "proc_fs.h"
#include "vnode.h"
#include "path_cache.h"
#include "los_vm_filemap.h"
#ifdef LOSCFG_DEBUG_VERSION
#define CLEAR_ALL_CACHE "clear all"
#define CLEAR_PATH_CACHE "clear pathcache"
#define CLEAR_PAGE_CACHE "clear pagecache"
static char* VnodeTypeToStr(enum VnodeType type) {
switch (type) {
case VNODE_TYPE_UNKNOWN:
return "UKN";
case VNODE_TYPE_REG:
return "REG";
case VNODE_TYPE_DIR:
return "DIR";
case VNODE_TYPE_BLK:
return "BLK";
case VNODE_TYPE_CHR:
return "CHR";
case VNODE_TYPE_BCHR:
return "BCH";
case VNODE_TYPE_FIFO:
return "FIF";
case VNODE_TYPE_LNK:
return "LNK";
default:
return "BAD";
}
}
static int VnodeListProcess(struct SeqBuf *buf, LIST_HEAD* list)
{
int count = 0;
struct Vnode *item = NULL;
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",
item, item->parent, item->data, item->vop, item->hash, item->useCount,
VnodeTypeToStr(item->type), item->gid, item->uid, item->mode);
count++;
}
return count;
}
static int PathCacheListProcess(struct SeqBuf *buf)
{
int count = 0;
LIST_HEAD* bucketList = GetPathCacheList();
for (int i = 0; i < LOSCFG_MAX_PATH_CACHE_SIZE; i++) {
struct PathCache *pc = NULL;
LIST_HEAD *list = &bucketList[i];
LOS_DL_LIST_FOR_EACH_ENTRY(pc, list, struct PathCache, hashEntry) {
LosBufPrintf(buf, "%-3d %-10p %-11p %-10p %-9d %s\n", i, pc,
pc->parentVnode, pc->childVnode, pc->hit, pc->name);
count++;
}
}
return count;
}
static int PageCacheEntryProcess(struct SeqBuf *buf, struct page_mapping *mapping)
{
int total = 0;
LosFilePage *fpage = NULL;
if (mapping == NULL) {
LosBufPrintf(buf, "null]\n");
return total;
}
LOS_DL_LIST_FOR_EACH_ENTRY(fpage, &mapping->page_list, LosFilePage, node) {
LosBufPrintf(buf, "%d,", fpage->pgoff);
total++;
}
LosBufPrintf(buf, "]\n");
return total;
}
static int PageCacheMapProcess(struct SeqBuf *buf)
{
struct file_map *mapList = GetFileMappingList();
char *name = NULL;
struct file_map *curMap = 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);
}
(VOID)LOS_MuxUnlock(&mapList->lock);
return total;
}
static int FsCacheInfoFill(struct SeqBuf *buf, void *arg)
{
int vnodeFree= 0;
int vnodeActive= 0;
int vnodeVirtual= 0;
int vnodeTotal = 0;
int pathCacheTotal = 0;
int pathCacheTotalTry = 0;
int pathCacheTotalHit = 0;
int pageCacheTotal = 0;
int pageCacheTotalTry = 0;
int pageCacheTotalHit = 0;
ResetPathCacheHitInfo(&pathCacheTotalHit, &pathCacheTotalTry);
ResetPageCacheHitInfo(&pageCacheTotalTry, &pageCacheTotalHit);
VnodeHold();
LosBufPrintf(buf, "\n=================================================================\n");
LosBufPrintf(buf, "VnodeAddr ParentAddr DataAddr VnodeOps Hash Ref Type Gid Uid Mode\n");
vnodeVirtual = VnodeListProcess(buf, GetVnodeVirtualList());
vnodeFree = VnodeListProcess(buf, GetVnodeFreeList());
vnodeActive = VnodeListProcess(buf, GetVnodeActiveList());
vnodeTotal = vnodeVirtual + vnodeFree + vnodeActive;
LosBufPrintf(buf, "\n=================================================================\n");
LosBufPrintf(buf, "No. CacheAddr ParentAddr ChildAddr HitCount Name\n");
pathCacheTotal = PathCacheListProcess(buf);
LosBufPrintf(buf, "\n=================================================================\n");
pageCacheTotal = PageCacheMapProcess(buf);
LosBufPrintf(buf, "\n=================================================================\n");
LosBufPrintf(buf, "PathCache Total:%d Try:%d Hit:%d\n",
pathCacheTotal, pathCacheTotalTry, pathCacheTotalHit);
LosBufPrintf(buf, "Vnode Total:%d Free:%d Virtual:%d Active:%d\n",
vnodeTotal, vnodeFree, vnodeVirtual, vnodeActive);
LosBufPrintf(buf, "PageCache total:%d Try:%d Hit:%d\n", pageCacheTotal, pageCacheTotalTry, pageCacheTotalHit);
VnodeDrop();
return 0;
}
static int FsCacheClear(struct ProcFile *pf, const char *buffer, size_t buflen, loff_t *ppos)
{
if (buffer == NULL || buflen < sizeof(CLEAR_ALL_CACHE)) {
return -EINVAL;
}
int vnodeCount = 0;
int pageCount = 0;
if (!strcmp(buffer, CLEAR_ALL_CACHE)) {
vnodeCount = VnodeClearCache();
pageCount = OsTryShrinkMemory(VM_FILEMAP_MAX_SCAN);
} else if (!strcmp(buffer, CLEAR_PAGE_CACHE)) {
pageCount = OsTryShrinkMemory(VM_FILEMAP_MAX_SCAN);
} else if (!strcmp(buffer, CLEAR_PATH_CACHE)) {
vnodeCount = VnodeClearCache();
} else {
return -EINVAL;
}
PRINTK("%d vnodes and related pathcaches cleared\n%d pages cleared\n", vnodeCount, pageCount);
return buflen;
}
static const struct ProcFileOperations FS_CACHE_PROC_FOPS = {
.read = FsCacheInfoFill,
.write = FsCacheClear,
};
void ProcFsCacheInit(void)
{
struct ProcDirEntry *pde = CreateProcEntry("fs_cache", 0, NULL);
if (pde == NULL) {
PRINT_ERR("create fs_cache error!\n");
return;
}
pde->procFileOps = &FS_CACHE_PROC_FOPS;
}
#else
void ProcFsCacheInit(void)
{
/* do nothing in release version */
}
#endif

View File

@@ -32,9 +32,9 @@
#include <sys/statfs.h>
#include <sys/mount.h>
#include "proc_fs.h"
#include "los_trace.h"
#ifdef LOSCFG_KERNEL_TRACE
#include "los_trace.h"
static int KernelTraceProcFill(struct SeqBuf *m, void *v)
{
(void)v;

View File

@@ -38,42 +38,39 @@
#include "fs/mount.h"
#include "internal.h"
static int ShowType(const char *mountPoint, struct statfs *statBuf, void *arg)
static int ShowType(const char *devPoint, const char *mountPoint, struct statfs *statBuf, void *arg)
{
struct SeqBuf *seqBuf = (struct SeqBuf *)arg;
char *type = NULL;
char *name = NULL;
switch (statBuf->f_type) {
case PROCFS_MAGIC:
type = "proc";
name = "proc";
break;
case JFFS2_SUPER_MAGIC:
type = "jffs2";
name = "jffs2";
break;
case NFS_SUPER_MAGIC:
type = "nfs";
name = "nfs";
break;
case TMPFS_MAGIC:
type = "tmpfs";
name = "tmpfs";
break;
case MSDOS_SUPER_MAGIC:
type = "vfat";
name = "fat";
break;
case ZPFS_MAGIC:
type = "zpfs";
name = "zpfs";
break;
default:
return 0;
}
(void)LosBufPrintf(seqBuf, "%s %s %s\n", name, mountPoint, type);
if (strlen(devPoint) == 0) {
(void)LosBufPrintf(seqBuf, "%s %s %s %s %d %d\n", type, mountPoint, type, "()", 0, 0);
} else {
(void)LosBufPrintf(seqBuf, "%s %s %s %s %d %d\n", devPoint, mountPoint, type, "()", 0, 0);
}
return 0;
}

View File

@@ -0,0 +1,178 @@
/*
* 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 <sys/statfs.h>
#include <sys/mount.h>
#include "proc_fs.h"
#include "internal.h"
#ifdef LOSCFG_KERNEL_PM
#include "los_pm.h"
static int PowerLockWrite(struct ProcFile *pf, const char *buf, size_t count, loff_t *ppos)
{
(void)pf;
(void)count;
(void)ppos;
return -LOS_PmLockRequest(buf);
}
static int PowerLockRead(struct SeqBuf *m, void *v)
{
(void)v;
LOS_PmLockInfoShow(m);
return 0;
}
static const struct ProcFileOperations PowerLock = {
.write = PowerLockWrite,
.read = PowerLockRead,
};
static int PowerUnlockWrite(struct ProcFile *pf, const char *buf, size_t count, loff_t *ppos)
{
(void)pf;
(void)count;
(void)ppos;
return -LOS_PmLockRelease(buf);
}
static const struct ProcFileOperations PowerUnlock = {
.write = PowerUnlockWrite,
.read = PowerLockRead,
};
static int PowerModeWrite(struct ProcFile *pf, const char *buf, size_t count, loff_t *ppos)
{
(void)pf;
(void)count;
(void)ppos;
if (buf == NULL) {
return 0;
}
if (strcmp(buf, "normal") != 0) {
return LOS_NOK;
}
return 0;
}
static int PowerModeRead(struct SeqBuf *m, void *v)
{
(void)v;
LosBufPrintf(m, "normal \n");
return 0;
}
static const struct ProcFileOperations PowerMode = {
.write = PowerModeWrite,
.read = PowerModeRead,
};
static int PowerCountRead(struct SeqBuf *m, void *v)
{
(void)v;
UINT32 count = LOS_PmLockCountGet();
LosBufPrintf(m, "%u\n", count);
return 0;
}
static const struct ProcFileOperations PowerCount = {
.write = NULL,
.read = PowerCountRead,
};
#define POWER_FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)
#define OS_POWER_PRIVILEGE 7
void ProcPmInit(void)
{
struct ProcDirEntry *power = CreateProcEntry("power", S_IFDIR | S_IRWXU | S_IRWXG | S_IROTH, NULL);
if (power == NULL) {
PRINT_ERR("create /proc/power error!\n");
return;
}
power->uid = OS_POWER_PRIVILEGE;
power->gid = OS_POWER_PRIVILEGE;
struct ProcDirEntry *mode = CreateProcEntry("power/power_mode", POWER_FILE_MODE, NULL);
if (mode == NULL) {
PRINT_ERR("create /proc/power/power_mode error!\n");
goto FREE_POWER;
}
mode->procFileOps = &PowerMode;
mode->uid = OS_POWER_PRIVILEGE;
mode->gid = OS_POWER_PRIVILEGE;
struct ProcDirEntry *lock = CreateProcEntry("power/power_lock", POWER_FILE_MODE, NULL);
if (lock == NULL) {
PRINT_ERR("create /proc/power/power_lock error!\n");
goto FREE_MODE;
}
lock->procFileOps = &PowerLock;
lock->uid = OS_POWER_PRIVILEGE;
lock->gid = OS_POWER_PRIVILEGE;
struct ProcDirEntry *unlock = CreateProcEntry("power/power_unlock", POWER_FILE_MODE, NULL);
if (unlock == NULL) {
PRINT_ERR("create /proc/power/power_unlock error!\n");
goto FREE_LOCK;
}
unlock->procFileOps = &PowerUnlock;
unlock->uid = OS_POWER_PRIVILEGE;
unlock->gid = OS_POWER_PRIVILEGE;
struct ProcDirEntry *count = CreateProcEntry("power/power_count", S_IRUSR | S_IRGRP | S_IROTH, NULL);
if (count == NULL) {
PRINT_ERR("create /proc/power/power_count error!\n");
goto FREE_UNLOCK;
}
count->procFileOps = &PowerCount;
count->uid = OS_POWER_PRIVILEGE;
count->gid = OS_POWER_PRIVILEGE;
return;
FREE_UNLOCK:
ProcFreeEntry(unlock);
FREE_LOCK:
ProcFreeEntry(lock);
FREE_MODE:
ProcFreeEntry(mode);
FREE_POWER:
ProcFreeEntry(power);
return;
}
#endif

View File

@@ -64,6 +64,11 @@ void ProcFsInit(void)
ProcProcessInit();
ProcUptimeInit();
ProcKernelTraceInit();
ProcFsCacheInit();
ProcFdInit();
#ifdef LOSCFG_KERNEL_PM
ProcPmInit();
#endif
}
LOS_MODULE_INIT(ProcFsInit, LOS_INIT_LEVEL_KMOD_EXTENDED);

View File

@@ -60,11 +60,9 @@ static struct Vnode *EntryToVnode(struct ProcDirEntry *entry)
node->fop = &g_procfsFops;
node->data = entry;
node->type = entry->type;
if (node->type == VNODE_TYPE_DIR) {
node->mode = S_IFDIR | PROCFS_DEFAULT_MODE;
} else {
node->mode = S_IFREG | PROCFS_DEFAULT_MODE;
}
node->uid = entry->uid;
node->gid = entry->gid;
node->mode = entry->mode;
return node;
}

View File

@@ -42,6 +42,9 @@ struct PathCache {
LIST_ENTRY childEntry; /* list entry for cache list in the child vnode */
LIST_ENTRY hashEntry; /* list entry for buckets in the hash table */
uint8_t nameLen; /* length of path component */
#ifdef LOSCFG_DEBUG_VERSION
int hit; /* cache hit count*/
#endif
char name[0]; /* path component name */
};
@@ -52,5 +55,9 @@ int PathCacheLookup(struct Vnode *parent, const char *name, int len, struct Vnod
void VnodePathCacheFree(struct Vnode *vnode);
void PathCacheMemoryDump(void);
void PathCacheDump(void);
LIST_HEAD* GetPathCacheList(void);
#ifdef LOSCFG_DEBUG_VERSION
void ResetPathCacheHitInfo(int *hit, int *try);
#endif
#endif /* _PATH_CACHE_H */

View File

@@ -176,5 +176,9 @@ void VnodeMemoryDump(void);
mode_t GetUmask(void);
int VfsPermissionCheck(uint fuid, uint fgid, mode_t fileMode, int accMode);
int VfsVnodePermissionCheck(const struct Vnode *node, int accMode);
LIST_HEAD* GetVnodeFreeList(void);
LIST_HEAD* GetVnodeActiveList(void);
LIST_HEAD* GetVnodeVirtualList(void);
int VnodeClearCache(void);
#endif /* !_VNODE_H_ */

View File

@@ -41,6 +41,8 @@
#include "stdlib.h"
#include "sys/stat.h"
#include "vnode.h"
#include "fs/mount.h"
#include <fcntl.h>
/****************************************************************************
* Static Functions
@@ -69,6 +71,11 @@ int chattr(const char *pathname, struct IATTR *attr)
goto errout_with_lock;
}
if ((vnode->originMount) && (vnode->originMount->mountFlags & MS_RDONLY)) {
ret = -EROFS;
goto errout_with_lock;
}
/* The way we handle the stat depends on the type of vnode that we
* are dealing with.
*/

View File

@@ -406,7 +406,7 @@ int CopyFdToProc(int fd, unsigned int targetPid)
return -ESRCH;
}
procFd = AssignProcessFd(fdt, 3);
procFd = AssignProcessFd(fdt, 3); // minfd is 3
if (procFd < 0) {
if (sem_post(&semId) == -1) {
PRINT_ERR("sem_post error, errno %d \n", get_errno());

View File

@@ -293,4 +293,11 @@ out:
(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

@@ -35,7 +35,9 @@
#include "dirent.h"
#include "unistd.h"
#include "sys/select.h"
#include "sys/mount.h"
#include "sys/stat.h"
#include "sys/statfs.h"
#include "sys/prctl.h"
#include "fs/fd_table.h"
#include "fs/file.h"
@@ -256,30 +258,70 @@ char *getcwd(char *buf, size_t n)
int chmod(const char *path, mode_t mode)
{
int result;
struct stat buf;
struct IATTR attr = {0};
attr.attr_chg_mode = mode;
attr.attr_chg_valid = CHG_MODE; /* change mode */
int ret;
result = stat(path, &buf);
if (result != ENOERR) {
ret = chattr(path, &attr);
if (ret < 0) {
return VFS_ERROR;
}
return OK;
}
int chown(const char *pathname, uid_t owner, gid_t group)
{
struct IATTR attr = {0};
attr.attr_chg_valid = 0;
int ret;
if (owner != (uid_t)-1) {
attr.attr_chg_uid = owner;
attr.attr_chg_valid |= CHG_UID;
}
if (group != (gid_t)-1) {
attr.attr_chg_gid = group;
attr.attr_chg_valid |= CHG_GID;
}
ret = chattr(pathname, &attr);
if (ret < 0) {
return VFS_ERROR;
}
/* no access/permission control for files now, just return OK if stat is okay*/
return OK;
}
int access(const char *path, int amode)
{
int result;
int ret;
struct stat buf;
struct statfs fsBuf;
result = stat(path, &buf);
ret = statfs(path, &fsBuf);
if (ret != 0) {
if (get_errno() != ENOSYS) {
return VFS_ERROR;
}
/* dev has no statfs ops, need devfs to handle this in feature */
}
if (result != ENOERR) {
if ((fsBuf.f_flags & MS_RDONLY) && ((unsigned int)amode & W_OK)) {
set_errno(EROFS);
return VFS_ERROR;
}
ret = stat(path, &buf);
if (ret != 0) {
return VFS_ERROR;
}
if (VfsPermissionCheck(buf.st_uid, buf.st_gid, buf.st_mode, amode)) {
set_errno(EACCES);
return VFS_ERROR;
}
/* no access/permission control for files now, just return OK if stat is okay*/
return OK;
}

View File

@@ -37,9 +37,11 @@
#include "vfs_config.h"
#include "sys/stat.h"
#include "vnode.h"
#include "fs/mount.h"
#include "string.h"
#include "stdlib.h"
#include "utime.h"
#include <fcntl.h>
/****************************************************************************
* Global Functions
@@ -79,6 +81,12 @@ int utime(const char *path, const struct utimbuf *ptimes)
goto errout_with_path;
}
if ((vnode->originMount) && (vnode->originMount->mountFlags & MS_RDONLY)) {
VnodeDrop();
ret = -EROFS;
goto errout_with_path;
}
if (vnode->vop && vnode->vop->Chattr) {
if (ptimes == NULL) {
/* get current seconds */

View File

@@ -37,6 +37,23 @@
#define PATH_CACHE_HASH_MASK (LOSCFG_MAX_PATH_CACHE_SIZE - 1)
LIST_HEAD g_pathCacheHashEntrys[LOSCFG_MAX_PATH_CACHE_SIZE];
#ifdef LOSCFG_DEBUG_VERSION
static int g_totalPathCacheHit = 0;
static int g_totalPathCacheTry = 0;
#define TRACE_TRY_CACHE() do { g_totalPathCacheTry++; } while (0)
#define TRACE_HIT_CACHE(pc) do { pc->hit++; g_totalPathCacheHit++; } while (0)
void ResetPathCacheHitInfo(int *hit, int *try)
{
*hit = g_totalPathCacheHit;
*try = g_totalPathCacheTry;
g_totalPathCacheHit = 0;
g_totalPathCacheTry = 0;
}
#else
#define TRACE_TRY_CACHE()
#define TRACE_HIT_CACHE(pc)
#endif
int PathCacheInit(void)
{
@@ -50,12 +67,12 @@ void PathCacheDump(void)
{
PRINTK("-------->pathCache dump in\n");
for (int i = 0; i < LOSCFG_MAX_PATH_CACHE_SIZE; i++) {
struct PathCache *nc = NULL;
struct PathCache *pc = NULL;
LIST_HEAD *nhead = &g_pathCacheHashEntrys[i];
LOS_DL_LIST_FOR_EACH_ENTRY(nc, nhead, struct PathCache, hashEntry) {
LOS_DL_LIST_FOR_EACH_ENTRY(pc, nhead, struct PathCache, hashEntry) {
PRINTK(" pathCache dump hash %d item %s %p %p %d\n", i,
nc->name, nc->parentVnode, nc->childVnode, nc->nameLen);
pc->name, pc->parentVnode, pc->childVnode, pc->nameLen);
}
}
PRINTK("-------->pathCache dump out\n");
@@ -94,7 +111,7 @@ static void PathCacheInsert(struct Vnode *parent, struct PathCache *cache, const
struct PathCache *PathCacheAlloc(struct Vnode *parent, struct Vnode *vnode, const char *name, uint8_t len)
{
struct PathCache *nc = NULL;
struct PathCache *pc = NULL;
size_t pathCacheSize;
int ret;
@@ -103,53 +120,55 @@ struct PathCache *PathCacheAlloc(struct Vnode *parent, struct Vnode *vnode, cons
}
pathCacheSize = sizeof(struct PathCache) + len + 1;
nc = (struct PathCache*)zalloc(pathCacheSize);
if (nc == NULL) {
pc = (struct PathCache*)zalloc(pathCacheSize);
if (pc == NULL) {
PRINT_ERR("pathCache alloc failed, no memory!\n");
return NULL;
}
ret = strncpy_s(nc->name, len + 1, name, len);
ret = strncpy_s(pc->name, len + 1, name, len);
if (ret != LOS_OK) {
return NULL;
}
nc->parentVnode = parent;
nc->nameLen = len;
nc->childVnode = vnode;
pc->parentVnode = parent;
pc->nameLen = len;
pc->childVnode = vnode;
LOS_ListAdd((&(parent->childPathCaches)), (&(nc->childEntry)));
LOS_ListAdd((&(vnode->parentPathCaches)), (&(nc->parentEntry)));
LOS_ListAdd((&(parent->childPathCaches)), (&(pc->childEntry)));
LOS_ListAdd((&(vnode->parentPathCaches)), (&(pc->parentEntry)));
PathCacheInsert(parent, nc, name, len);
PathCacheInsert(parent, pc, name, len);
return nc;
return pc;
}
int PathCacheFree(struct PathCache *nc)
int PathCacheFree(struct PathCache *pc)
{
if (nc == NULL) {
if (pc == NULL) {
PRINT_ERR("pathCache free: invalid pathCache\n");
return -ENOENT;
}
LOS_ListDelete(&nc->hashEntry);
LOS_ListDelete(&nc->parentEntry);
LOS_ListDelete(&nc->childEntry);
free(nc);
LOS_ListDelete(&pc->hashEntry);
LOS_ListDelete(&pc->parentEntry);
LOS_ListDelete(&pc->childEntry);
free(pc);
return LOS_OK;
}
int PathCacheLookup(struct Vnode *parent, const char *name, int len, struct Vnode **vnode)
{
struct PathCache *nc = NULL;
struct PathCache *pc = NULL;
int hash = NameHash(name, len, parent) & PATH_CACHE_HASH_MASK;
LIST_HEAD *dhead = &g_pathCacheHashEntrys[hash];
LOS_DL_LIST_FOR_EACH_ENTRY(nc, dhead, struct PathCache, hashEntry) {
if (nc->parentVnode == parent && nc->nameLen == len && !strncmp(nc->name, name, len)) {
*vnode = nc->childVnode;
TRACE_TRY_CACHE();
LOS_DL_LIST_FOR_EACH_ENTRY(pc, dhead, struct PathCache, hashEntry) {
if (pc->parentVnode == parent && pc->nameLen == len && !strncmp(pc->name, name, len)) {
*vnode = pc->childVnode;
TRACE_HIT_CACHE(pc);
return LOS_OK;
}
}
@@ -184,3 +203,8 @@ void VnodePathCacheFree(struct Vnode *vnode)
FreeParentPathCache(vnode);
FreeChildPathCache(vnode);
}
LIST_HEAD* GetPathCacheList()
{
return g_pathCacheHashEntrys;
}

View File

@@ -35,7 +35,7 @@
LIST_HEAD g_vnodeFreeList; /* free vnodes list */
LIST_HEAD g_vnodeVirtualList; /* dev vnodes list */
LIST_HEAD g_vnodeCurrList; /* inuse vnodes list */
LIST_HEAD g_vnodeActiveList; /* inuse vnodes list */
static int g_freeVnodeSize = 0; /* system free vnodes size */
static int g_totalVnodeSize = 0; /* total vnode size */
@@ -57,7 +57,7 @@ int VnodesInit(void)
LOS_ListInit(&g_vnodeFreeList);
LOS_ListInit(&g_vnodeVirtualList);
LOS_ListInit(&g_vnodeCurrList);
LOS_ListInit(&g_vnodeActiveList);
retval = VnodeAlloc(NULL, &g_rootVnode);
if (retval != LOS_OK) {
PRINT_ERR("VnodeInit failed error %d\n", retval);
@@ -94,7 +94,7 @@ struct Vnode *VnodeReclaimLru(void)
struct Vnode *nextItem = NULL;
int releaseCount = 0;
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &g_vnodeCurrList, struct Vnode, actFreeEntry) {
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &g_vnodeActiveList, struct Vnode, actFreeEntry) {
if ((item->useCount > 0) ||
(item->flag & VNODE_FLAG_MOUNT_ORIGIN) ||
(item->flag & VNODE_FLAG_MOUNT_NEW)) {
@@ -152,7 +152,7 @@ int VnodeAlloc(struct VnodeOps *vop, struct Vnode **newVnode)
LOS_ListAdd(&g_vnodeVirtualList, &(vnode->actFreeEntry));
vnode->vop = &g_devfsOps;
} else {
LOS_ListTailInsert(&g_vnodeCurrList, &(vnode->actFreeEntry));
LOS_ListTailInsert(&g_vnodeActiveList, &(vnode->actFreeEntry));
vnode->vop = vop;
}
VnodeDrop();
@@ -204,7 +204,7 @@ int VnodeFreeAll(const struct Mount *mount)
struct Vnode *nextVnode = NULL;
int ret;
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(vnode, nextVnode, &g_vnodeCurrList, struct Vnode, actFreeEntry) {
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(vnode, nextVnode, &g_vnodeActiveList, struct Vnode, actFreeEntry) {
if ((vnode->originMount == mount) && !(vnode->flag & VNODE_FLAG_MOUNT_NEW)) {
ret = VnodeFree(vnode);
if (ret != LOS_OK) {
@@ -220,7 +220,7 @@ BOOL VnodeInUseIter(const struct Mount *mount)
{
struct Vnode *vnode = NULL;
LOS_DL_LIST_FOR_EACH_ENTRY(vnode, &g_vnodeCurrList, struct Vnode, actFreeEntry) {
LOS_DL_LIST_FOR_EACH_ENTRY(vnode, &g_vnodeActiveList, struct Vnode, actFreeEntry) {
if (vnode->originMount == mount) {
if ((vnode->useCount > 0) || (vnode->flag & VNODE_FLAG_MOUNT_ORIGIN)) {
return TRUE;
@@ -294,7 +294,7 @@ static void RefreshLRU(struct Vnode *vnode)
return;
}
LOS_ListDelete(&(vnode->actFreeEntry));
LOS_ListTailInsert(&g_vnodeCurrList, &(vnode->actFreeEntry));
LOS_ListTailInsert(&g_vnodeActiveList, &(vnode->actFreeEntry));
}
static int ProcessVirtualVnode(struct Vnode *parent, uint32_t flags, struct Vnode **vnode)
@@ -612,7 +612,7 @@ void VnodeMemoryDump(void)
struct Vnode *nextItem = NULL;
int vnodeCount = 0;
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &g_vnodeCurrList, struct Vnode, actFreeEntry) {
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &g_vnodeActiveList, struct Vnode, actFreeEntry) {
if ((item->useCount > 0) ||
(item->flag & VNODE_FLAG_MOUNT_ORIGIN) ||
(item->flag & VNODE_FLAG_MOUNT_NEW)) {
@@ -625,3 +625,41 @@ void VnodeMemoryDump(void)
PRINTK("Vnode number = %d\n", vnodeCount);
PRINTK("Vnode memory size = %d(B)\n", vnodeCount * sizeof(struct Vnode));
}
LIST_HEAD* GetVnodeFreeList()
{
return &g_vnodeFreeList;
}
LIST_HEAD* GetVnodeVirtualList()
{
return &g_vnodeVirtualList;
}
LIST_HEAD* GetVnodeActiveList()
{
return &g_vnodeActiveList;
}
int VnodeClearCache()
{
struct Vnode *item = NULL;
struct Vnode *nextItem = NULL;
int count = 0;
VnodeHold();
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &g_vnodeActiveList, struct Vnode, actFreeEntry) {
if ((item->useCount > 0) ||
(item->flag & VNODE_FLAG_MOUNT_ORIGIN) ||
(item->flag & VNODE_FLAG_MOUNT_NEW)) {
continue;
}
if (VnodeFree(item) == LOS_OK) {
count++;
}
}
VnodeDrop();
return count;
}

View File

@@ -89,6 +89,13 @@ config KERNEL_DYNLOAD
help
If you wish to build LiteOS with support for dynamic load.
config KERNEL_PM
bool "Enable Power Management"
default y
depends on KERNEL_EXTKERNEL
help
If you wish to build LiteOS with support for power management.
config ASLR
bool "Enable Address Space Layout Randomization"
default n

View File

@@ -183,7 +183,7 @@ VOID OsWaitWakeTask(LosTaskCB *taskCB, UINT32 wakePID)
{
taskCB->waitID = wakePID;
OsSchedTaskWake(taskCB);
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
LOS_MpSchedule(OS_MP_CPU_ALL);
#endif
}
@@ -312,7 +312,7 @@ LITE_OS_SEC_TEXT VOID OsProcessResourcesToFree(LosProcessCB *processCB)
}
#endif
#if (LOSCFG_KERNEL_LITEIPC == YES)
#ifdef LOSCFG_KERNEL_LITEIPC
if (OsProcessIsUserMode(processCB)) {
LiteIpcPoolDelete(&(processCB->ipcInfo));
(VOID)memset_s(&(processCB->ipcInfo), sizeof(ProcIpcInfo), 0, sizeof(ProcIpcInfo));
@@ -685,7 +685,7 @@ STATIC UINT32 OsProcessCreateInit(LosProcessCB *processCB, UINT32 flags, const C
goto EXIT;
}
#if (LOSCFG_KERNEL_LITEIPC == YES)
#ifdef LOSCFG_KERNEL_LITEIPC
if (OsProcessIsUserMode(processCB)) {
ret = LiteIpcPoolInit(&(processCB->ipcInfo));
if (ret != LOS_OK) {
@@ -1294,7 +1294,7 @@ LITE_OS_SEC_TEXT UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR
return ret;
}
#if (LOSCFG_KERNEL_LITEIPC == YES)
#ifdef LOSCFG_KERNEL_LITEIPC
ret = LiteIpcPoolInit(&(processCB->ipcInfo));
if (ret != LOS_OK) {
return LOS_NOK;
@@ -1690,7 +1690,7 @@ STATIC UINT32 OsCopyProcessResources(UINT32 flags, LosProcessCB *child, LosProce
return ret;
}
#if (LOSCFG_KERNEL_LITEIPC == YES)
#ifdef LOSCFG_KERNEL_LITEIPC
if (OsProcessIsUserMode(child)) {
ret = LiteIpcPoolReInit(&child->ipcInfo, (const ProcIpcInfo *)(&run->ipcInfo));
if (ret != LOS_OK) {
@@ -1794,6 +1794,52 @@ LITE_OS_SEC_TEXT VOID LOS_Exit(INT32 status)
OsProcessExit(OsCurrTaskGet(), (UINT32)status);
}
LITE_OS_SEC_TEXT INT32 LOS_GetUsedPIDList(UINT32 *pidList, INT32 pidMaxNum)
{
LosProcessCB *pcb = NULL;
INT32 num = 0;
UINT32 intSave;
UINT32 pid = 1;
if (pidList == NULL) {
return 0;
}
SCHEDULER_LOCK(intSave);
while (OsProcessIDUserCheckInvalid(pid) == false) {
pcb = OS_PCB_FROM_PID(pid);
pid++;
if (OsProcessIsUnused(pcb)) {
continue;
}
pidList[num] = pcb->processID;
num++;
if (num >= pidMaxNum) {
break;
}
}
SCHEDULER_UNLOCK(intSave);
return num;
}
#ifdef LOSCFG_FS_VFS
LITE_OS_SEC_TEXT struct fd_table_s *LOS_GetFdTable(UINT32 pid)
{
LosProcessCB *pcb = NULL;
struct files_struct *files = NULL;
if (OS_PID_CHECK_INVALID(pid)) {
return NULL;
}
pcb = OS_PCB_FROM_PID(pid);
files = pcb->files;
if (files == NULL) {
return NULL;
}
return files->fdt;
}
#endif
LITE_OS_SEC_TEXT UINT32 LOS_GetCurrProcessID(VOID)
{
return OsCurrProcessGet()->processID;

View File

@@ -127,7 +127,7 @@ STATIC Percpu *OsFindIdleCpu(UINT16 *ildeCpuID)
Percpu *idleCpu = OsPercpuGetByID(0);
*ildeCpuID = 0;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
UINT16 cpuID = 1;
UINT32 nodeNum = idleCpu->taskSortLink.nodeNum + idleCpu->swtmrSortLink.nodeNum;
@@ -174,7 +174,7 @@ VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, Sort
LOS_SpinLockSave(spinLock, &intSave);
SET_SORTLIST_VALUE(node, startTime + (UINT64)waitTicks * OS_CYCLE_PER_TICK);
OsAddNode2SortLink(sortLinkHeader, node);
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
node->cpuid = idleCpu;
if (idleCpu != ArchCurrCpuid()) {
LOS_MpSchedule(CPUID_TO_AFFI_MASK(idleCpu));
@@ -186,7 +186,7 @@ VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, Sort
VOID OsDeleteSortLink(SortLinkList *node, SortLinkType type)
{
UINT32 intSave;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
Percpu *cpu = OsPercpuGetByID(node->cpuid);
#else
Percpu *cpu = OsPercpuGetByID(0);

View File

@@ -38,7 +38,7 @@
#include "los_task_pri.h"
#if (LOSCFG_BASE_CORE_SWTMR == YES)
#ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
#if (LOSCFG_BASE_CORE_SWTMR_LIMIT <= 0)
#error "swtmr maxnum cannot be zero"
#endif /* LOSCFG_BASE_CORE_SWTMR_LIMIT <= 0 */
@@ -84,7 +84,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrTaskCreate(VOID)
swtmrTask.pcName = "Swt_Task";
swtmrTask.usTaskPrio = 0;
swtmrTask.uwResved = LOS_TASK_STATUS_DETACHED;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
swtmrTask.usCpuAffiMask = CPUID_TO_AFFI_MASK(cpuid);
#endif
ret = LOS_TaskCreate(&swtmrTaskID, &swtmrTask);
@@ -533,4 +533,4 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrDelete(UINT16 swtmrID)
return ret;
}
#endif /* LOSCFG_BASE_CORE_SWTMR */
#endif /* LOSCFG_BASE_CORE_SWTMR_ENABLE */

View File

@@ -51,10 +51,10 @@
#ifdef LOSCFG_KERNEL_CPUP
#include "los_cpup_pri.h"
#endif
#if (LOSCFG_BASE_CORE_SWTMR == YES)
#ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
#include "los_swtmr_pri.h"
#endif
#if (LOSCFG_KERNEL_LITEIPC == YES)
#ifdef LOSCFG_KERNEL_LITEIPC
#include "hm_liteipc.h"
#endif
#ifdef LOSCFG_ENABLE_OOM_LOOP_TASK
@@ -98,7 +98,7 @@ VOID OsSetMainTask()
g_mainTask[i].taskStatus = OS_TASK_STATUS_UNUSED;
g_mainTask[i].taskID = LOSCFG_BASE_CORE_TSK_LIMIT;
g_mainTask[i].priority = OS_TASK_PRIORITY_LOWEST;
#if (LOSCFG_KERNEL_SMP_LOCKDEP == YES)
#ifdef LOSCFG_KERNEL_SMP_LOCKDEP
g_mainTask[i].lockDep.lockDepth = 0;
g_mainTask[i].lockDep.waitLock = NULL;
#endif
@@ -208,7 +208,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTaskInit(VOID)
LOS_ListTailInsert(&g_losFreeTask, &g_taskCBArray[index].pendList);
}
#if (LOSCFG_KERNEL_TRACE == YES)
#ifdef LOSCFG_KERNEL_TRACE
LOS_TraceReg(LOS_TRACE_TASK, OsTaskTrace, LOS_TRACE_TASK_NAME, LOS_TRACE_ENABLE);
#endif
@@ -240,7 +240,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID)
taskInitParam.pcName = "Idle";
taskInitParam.usTaskPrio = OS_TASK_PRIORITY_LOWEST;
taskInitParam.processID = OsGetIdleProcessID();
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
taskInitParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
#endif
ret = LOS_TaskCreateOnly(idleTaskID, &taskInitParam);
@@ -381,7 +381,7 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskStackAlloc(VOID **topStack, UINT32 stack
STATIC INLINE UINT32 OsTaskSyncCreate(LosTaskCB *taskCB)
{
#if (LOSCFG_KERNEL_SMP_TASK_SYNC == YES)
#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
UINT32 ret = LOS_SemCreate(0, &taskCB->syncSignal);
if (ret != LOS_OK) {
return LOS_ERRNO_TSK_MP_SYNC_RESOURCE;
@@ -394,7 +394,7 @@ STATIC INLINE UINT32 OsTaskSyncCreate(LosTaskCB *taskCB)
STATIC INLINE VOID OsTaskSyncDestroy(UINT32 syncSignal)
{
#if (LOSCFG_KERNEL_SMP_TASK_SYNC == YES)
#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
(VOID)LOS_SemDelete(syncSignal);
#else
(VOID)syncSignal;
@@ -403,7 +403,7 @@ STATIC INLINE VOID OsTaskSyncDestroy(UINT32 syncSignal)
LITE_OS_SEC_TEXT UINT32 OsTaskSyncWait(const LosTaskCB *taskCB)
{
#if (LOSCFG_KERNEL_SMP_TASK_SYNC == YES)
#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
UINT32 ret = LOS_OK;
LOS_ASSERT(LOS_SpinHeld(&g_taskSpin));
@@ -428,7 +428,7 @@ LITE_OS_SEC_TEXT UINT32 OsTaskSyncWait(const LosTaskCB *taskCB)
STATIC INLINE VOID OsTaskSyncWake(const LosTaskCB *taskCB)
{
#if (LOSCFG_KERNEL_SMP_TASK_SYNC == YES)
#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
(VOID)OsSemPostUnsafe(taskCB->syncSignal, NULL);
#else
(VOID)taskCB;
@@ -485,7 +485,7 @@ LITE_OS_SEC_TEXT VOID OsTaskResourcesToFree(LosTaskCB *taskCB)
processCB->processID, taskCB->taskID, mapBase, mapSize, ret);
}
#if (LOSCFG_KERNEL_LITEIPC == YES)
#ifdef LOSCFG_KERNEL_LITEIPC
LiteIpcRemoveServiceHandle(taskCB);
#endif
}
@@ -494,7 +494,7 @@ LITE_OS_SEC_TEXT VOID OsTaskResourcesToFree(LosTaskCB *taskCB)
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
topOfStack = taskCB->topOfStack;
taskCB->topOfStack = 0;
#if (LOSCFG_KERNEL_SMP_TASK_SYNC == YES)
#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
syncSignal = taskCB->syncSignal;
taskCB->syncSignal = LOSCFG_BASE_IPC_SEM_LIMIT;
#endif
@@ -523,12 +523,12 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskCBInitBase(LosTaskCB *taskCB,
taskCB->taskEntry = initParam->pfnTaskEntry;
taskCB->signal = SIGNAL_NONE;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
taskCB->currCpu = OS_TASK_INVALID_CPUID;
taskCB->cpuAffiMask = (initParam->usCpuAffiMask) ?
initParam->usCpuAffiMask : LOSCFG_KERNEL_CPU_MASK;
#endif
#if (LOSCFG_KERNEL_LITEIPC == YES)
#ifdef LOSCFG_KERNEL_LITEIPC
LOS_ListInit(&(taskCB->msgListHead));
#endif
taskCB->policy = (initParam->policy == LOS_SCHED_FIFO) ? LOS_SCHED_FIFO : LOS_SCHED_RR;
@@ -654,7 +654,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreateOnly(UINT32 *taskID, TSK_INIT_PARAM_S
LOS_ERREND_TCB_INIT:
(VOID)LOS_MemFree(pool, topStack);
LOS_ERREND_REWIND_SYNC:
#if (LOSCFG_KERNEL_SMP_TASK_SYNC == YES)
#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
OsTaskSyncDestroy(taskCB->syncSignal);
#endif
LOS_ERREND_REWIND_TCB:
@@ -769,7 +769,7 @@ LITE_OS_SEC_TEXT_INIT STATIC BOOL OsTaskSuspendCheckOnRun(LosTaskCB *taskCB, UIN
/* init default out return value */
*ret = LOS_OK;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
/* ASYNCHRONIZED. No need to do task lock checking */
if (taskCB->currCpu != ArchCurrCpuid()) {
taskCB->signal = SIGNAL_SUSPEND;
@@ -909,7 +909,7 @@ STATIC BOOL OsRunTaskToDeleteCheckOnRun(LosTaskCB *taskCB, UINT32 *ret)
/* init default out return value */
*ret = LOS_OK;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
/* ASYNCHRONIZED. No need to do task lock checking */
if (taskCB->currCpu != ArchCurrCpuid()) {
/*
@@ -994,7 +994,7 @@ LITE_OS_SEC_TEXT UINT32 OsTaskDeleteUnsafe(LosTaskCB *taskCB, UINT32 status, UIN
SCHEDULER_LOCK(intSave);
}
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
LOS_ASSERT(OsPercpuGet()->taskLockCnt == 1);
#else
LOS_ASSERT(OsPercpuGet()->taskLockCnt == 0);
@@ -1235,7 +1235,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoGet(UINT32 taskID, TSK_INFO_S *taskInf
LITE_OS_SEC_TEXT BOOL OsTaskCpuAffiSetUnsafe(UINT32 taskID, UINT16 newCpuAffiMask, UINT16 *oldCpuAffiMask)
{
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
taskCB->cpuAffiMask = newCpuAffiMask;
@@ -1286,7 +1286,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuAffiSet(UINT32 taskID, UINT16 cpuAffiMa
LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskCpuAffiGet(UINT32 taskID)
{
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
#define INVALID_CPU_AFFI_MASK 0
LosTaskCB *taskCB = NULL;
UINT16 cpuAffiMask;
@@ -1346,7 +1346,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTaskProcSignal(VOID)
/* suspend killed task may fail, ignore the result */
(VOID)LOS_TaskSuspend(runTask->taskID);
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
} else if (runTask->signal & SIGNAL_AFFI) {
runTask->signal &= ~SIGNAL_AFFI;
@@ -1406,13 +1406,14 @@ STATIC VOID OsExitGroupActiveTaskKilled(LosProcessCB *processCB, LosTaskCB *task
INT32 ret;
taskCB->taskStatus |= OS_TASK_FLAG_EXIT_KILL;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
/* The other core that the thread is running on and is currently running in a non-system call */
if (!taskCB->sig.sigIntLock && (taskCB->taskStatus & OS_TASK_STATUS_RUNNING)) {
taskCB->signal = SIGNAL_KILL;
LOS_MpSchedule(taskCB->currCpu);
} else
#endif
#ifdef LOSCFG_KERNEL_VM
{
ret = OsTaskKillUnsafe(taskCB->taskID, SIGKILL);
if (ret != LOS_OK) {
@@ -1420,6 +1421,7 @@ STATIC VOID OsExitGroupActiveTaskKilled(LosProcessCB *processCB, LosTaskCB *task
taskCB->processID, OsCurrTaskGet()->taskID, taskCB->taskID, ret);
}
}
#endif
if (!(taskCB->taskStatus & OS_TASK_FLAG_PTHREAD_JOIN)) {
taskCB->taskStatus |= OS_TASK_FLAG_PTHREAD_JOIN;

View File

@@ -57,7 +57,7 @@ LITE_OS_SEC_TEXT VOID OsTickHandler(VOID)
OsVdsoTimevalUpdate();
#endif
#if (LOSCFG_BASE_CORE_TICK_HW_TIME == YES)
#ifdef LOSCFG_BASE_CORE_TICK_HW_TIME
HalClockIrqClear(); /* diff from every platform */
#endif

View File

@@ -43,7 +43,7 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
typedef enum {
CPU_RUNNING = 0, /* cpu is running */
CPU_HALT, /* cpu in the halt */
@@ -66,7 +66,7 @@ typedef struct {
UINT32 swtmrTaskID; /* software timer task id */
UINT32 schedFlag; /* pending scheduler flag */
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
UINT32 excFlag; /* cpu halt or exc flag */
#endif
} Percpu;

View File

@@ -36,7 +36,7 @@
#include "los_sem_pri.h"
#include "los_process.h"
#include "los_vm_map.h"
#if (LOSCFG_KERNEL_LITEIPC == YES)
#ifdef LOSCFG_KERNEL_LITEIPC
#include "hm_liteipc.h"
#endif
#ifdef LOSCFG_SECURITY_CAPABILITY
@@ -96,12 +96,12 @@ typedef struct ProcessCB {
volatile UINT32 threadNumber; /**< Number of threads alive under this process */
UINT32 threadCount; /**< Total number of threads created under this process */
LOS_DL_LIST waitList; /**< The process holds the waitLits to support wait/waitpid */
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
UINT32 timerCpu; /**< CPU core number of this task is delayed or pended */
#endif
UINTPTR sigHandler; /**< Signal handler */
sigset_t sigShare; /**< Signal share bit */
#if (LOSCFG_KERNEL_LITEIPC == YES)
#ifdef LOSCFG_KERNEL_LITEIPC
ProcIpcInfo ipcInfo; /**< Memory pool for lite ipc */
#endif
#ifdef LOSCFG_KERNEL_VM

View File

@@ -112,7 +112,7 @@ STATIC INLINE BOOL OsPreemptableInSched(VOID)
{
BOOL preemptable = FALSE;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
/*
* For smp systems, schedule must hold the task spinlock, and this counter
* will increase by 1 in that case.

View File

@@ -50,7 +50,7 @@ typedef enum {
typedef struct {
LOS_DL_LIST sortLinkNode;
UINT64 responseTime;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
UINT32 cpuid;
#endif
} SortLinkList;

View File

@@ -45,7 +45,9 @@
#include "los_cpup_pri.h"
#endif
#ifdef LOSCFG_KERNEL_TRACE
#include "los_trace.h"
#endif
#ifdef __cplusplus
#if __cplusplus
@@ -344,14 +346,14 @@ typedef struct {
INT32 errorNo; /**< Error Num */
UINT32 signal; /**< Task signal */
sig_cb sig;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
UINT16 currCpu; /**< CPU core number of this task is running on */
UINT16 lastCpu; /**< CPU core number of this task is running on last time */
UINT16 cpuAffiMask; /**< CPU affinity mask, support up to 16 cores */
#if (LOSCFG_KERNEL_SMP_TASK_SYNC == YES)
#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
UINT32 syncSignal; /**< Synchronization for signal handling */
#endif
#if (LOSCFG_KERNEL_SMP_LOCKDEP == YES)
#ifdef LOSCFG_KERNEL_SMP_LOCKDEP
LockDep lockDep;
#endif
#endif
@@ -368,7 +370,7 @@ typedef struct {
UINTPTR waitID; /**< Wait for the PID or GID of the child process */
UINT16 waitFlag; /**< The type of child process that is waiting, belonging to a group or parent,
a specific child process, or any child process */
#if (LOSCFG_KERNEL_LITEIPC == YES)
#ifdef LOSCFG_KERNEL_LITEIPC
UINT32 ipcStatus;
LOS_DL_LIST msgListHead;
BOOL accessMap[LOSCFG_BASE_CORE_TSK_LIMIT];

View File

@@ -206,6 +206,10 @@ VOID OsMarkPageDirty(LosFilePage *fpage, LosVmMapRegion *region, int off, int le
typedef struct ProcessCB LosProcessCB;
VOID OsVmmFileRegionFree(struct file *filep, LosProcessCB *processCB);
#ifdef LOSCFG_DEBUG_VERSION
VOID ResetPageCacheHitInfo(int *try, int *hit);
struct file_map* GetFileMappingList(void);
#endif
#ifdef __cplusplus
#if __cplusplus
}

View File

@@ -35,7 +35,7 @@
#include "los_mp.h"
#include "los_percpu_pri.h"
#include "los_sched_pri.h"
#if (LOSCFG_BASE_CORE_SWTMR == YES)
#ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
#include "los_exc.h"
#endif

View File

@@ -38,7 +38,7 @@
#include "los_sched_pri.h"
#if (LOSCFG_BASE_IPC_MUX == YES)
#ifdef LOSCFG_BASE_IPC_MUX
#define MUTEXATTR_TYPE_MASK 0x0FU
LITE_OS_SEC_TEXT UINT32 LOS_MuxAttrInit(LosMuxAttr *attr)
@@ -560,5 +560,5 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxUnlock(LosMux *mutex)
return ret;
}
#endif /* (LOSCFG_BASE_IPC_MUX == YES) */
#endif /* LOSCFG_BASE_IPC_MUX */

View File

@@ -38,7 +38,7 @@
#include "los_percpu_pri.h"
#if (LOSCFG_BASE_IPC_QUEUE == YES)
#ifdef LOSCFG_BASE_IPC_QUEUE
#if (LOSCFG_BASE_IPC_QUEUE_LIMIT <= 0)
#error "queue maxnum cannot be zero"
#endif /* LOSCFG_BASE_IPC_QUEUE_LIMIT <= 0 */
@@ -493,5 +493,5 @@ QUEUE_END:
return ret;
}
#endif /* (LOSCFG_BASE_IPC_QUEUE == YES) */
#endif /* LOSCFG_BASE_IPC_QUEUE */

View File

@@ -40,7 +40,7 @@
#include "los_percpu_pri.h"
#if (LOSCFG_BASE_IPC_SEM == YES)
#ifdef LOSCFG_BASE_IPC_SEM
#if (LOSCFG_BASE_IPC_SEM_LIMIT <= 0)
#error "sem maxnum cannot be zero"
@@ -283,5 +283,5 @@ LITE_OS_SEC_TEXT UINT32 LOS_SemPost(UINT32 semHandle)
return ret;
}
#endif /* (LOSCFG_BASE_IPC_SEM == YES) */
#endif /* LOSCFG_BASE_IPC_SEM */

View File

@@ -101,11 +101,13 @@ STATIC UINT32 OsPendingTaskWake(LosTaskCB *taskCB, INT32 signo)
case OS_TASK_WAIT_SIGNAL:
OsSigWaitTaskWake(taskCB, signo);
break;
#ifdef LOSCFG_KERNEL_LITEIPC
case OS_TASK_WAIT_LITEIPC:
taskCB->ipcStatus &= ~IPC_THREAD_STATUS_PEND;
OsTaskWakeClearPendMask(taskCB);
OsSchedTaskWake(taskCB);
break;
#endif
case OS_TASK_WAIT_FUTEX:
OsFutexNodeDeleteFromFutexHash(&taskCB->futex, TRUE, NULL, NULL);
OsTaskWakeClearPendMask(taskCB);
@@ -132,7 +134,7 @@ int OsTcbDispatch(LosTaskCB *stcb, siginfo_t *info)
if (masked) {
/* If signal is in wait list and mask list, need unblock it */
if (LOS_ListEmpty(&sigcb->waitList) ||
(!LOS_ListEmpty(&sigcb->waitList) && !OsSigIsMember(&sigcb->sigwaitmask, info->si_signo))) {
(!LOS_ListEmpty(&sigcb->waitList) && !OsSigIsMember(&sigcb->sigwaitmask, info->si_signo))) {
OsSigAddSet(&sigcb->sigPendFlag, info->si_signo);
}
} else {
@@ -308,7 +310,7 @@ int OsSigProcessSend(LosProcessCB *spcb, siginfo_t *sigInfo)
.receivedTcb = NULL
};
if (info.sigInfo == NULL){
if (info.sigInfo == NULL) {
return -EFAULT;
}

View File

@@ -147,7 +147,7 @@ struct OsMemPoolInfo {
VOID *pool;
UINT32 totalSize;
UINT32 attr;
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
#ifdef LOSCFG_MEM_WATERLINE
UINT32 waterLine; /* Maximum usage size in a memory pool */
UINT32 curUsedSize; /* Current usage size in a memory pool */
#endif
@@ -230,7 +230,7 @@ STATIC INLINE VOID OsMemNodeSetTaskID(struct OsMemUsedNodeHead *node)
}
#endif
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
#ifdef LOSCFG_MEM_WATERLINE
STATIC INLINE VOID OsMemWaterUsedRecord(struct OsMemPoolHead *pool, UINT32 size)
{
pool->info.curUsedSize += size;
@@ -775,7 +775,7 @@ STATIC UINT32 OsMemPoolInit(VOID *pool, UINT32 size)
endNode->ptr.prev = newNode;
OS_MEM_NODE_SET_USED_FLAG(endNode->sizeAndFlag);
#endif
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
#ifdef LOSCFG_MEM_WATERLINE
poolHead->info.curUsedSize = sizeof(struct OsMemPoolHead) + OS_MEM_NODE_HEAD_SIZE;
poolHead->info.waterLine = poolHead->info.curUsedSize;
#endif
@@ -1171,7 +1171,7 @@ STATIC INLINE UINT32 OsMemFree(struct OsMemPoolHead *pool, struct OsMemNodeHead
return ret;
}
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
#ifdef LOSCFG_MEM_WATERLINE
pool->info.curUsedSize -= OS_MEM_NODE_GET_SIZE(node->sizeAndFlag);
#endif
@@ -1256,14 +1256,14 @@ UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
STATIC INLINE VOID OsMemReAllocSmaller(VOID *pool, UINT32 allocSize, struct OsMemNodeHead *node, UINT32 nodeSize)
{
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
#ifdef LOSCFG_MEM_WATERLINE
struct OsMemPoolHead *poolInfo = (struct OsMemPoolHead *)pool;
#endif
node->sizeAndFlag = nodeSize;
if ((allocSize + OS_MEM_NODE_HEAD_SIZE + OS_MEM_MIN_ALLOC_SIZE) <= nodeSize) {
OsMemSplitNode(pool, node, allocSize);
OS_MEM_NODE_SET_USED_FLAG(node->sizeAndFlag);
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
#ifdef LOSCFG_MEM_WATERLINE
poolInfo->info.curUsedSize -= nodeSize - allocSize;
#endif
}
@@ -1595,13 +1595,15 @@ STATIC VOID OsMemPoolHeadCheck(const struct OsMemPoolHead *pool)
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);
goto OUT;
}
}
}
OUT:
if (flag) {
PRINTK("mem pool info: poolAddr: %#x, poolSize: 0x%x\n", pool, pool->info.totalSize);
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
#ifdef LOSCFG_MEM_WATERLINE
PRINTK("mem pool info: poolWaterLine: 0x%x, poolCurUsedSize: 0x%x\n", pool->info.waterLine,
pool->info.curUsedSize);
#endif
@@ -1842,7 +1844,7 @@ UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_POOL_STATUS *poolStatus)
OsMemInfoGet(poolInfo, tmpNode, poolStatus);
}
#endif
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
#ifdef LOSCFG_MEM_WATERLINE
poolStatus->usageWaterLine = poolInfo->info.waterLine;
#endif
MEM_UNLOCK(poolInfo, intSave);
@@ -1859,7 +1861,7 @@ STATIC VOID OsMemInfoPrint(VOID *pool)
return;
}
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
#ifdef LOSCFG_MEM_WATERLINE
PRINTK("pool addr pool size used size free size "
"max free node size used node num free node num UsageWaterLine\n");
PRINTK("--------------- -------- ------- -------- "

View File

@@ -119,9 +119,21 @@ UINT32 OsShellCmdSwtmrCntGet(VOID)
LITE_OS_SEC_TEXT_MINOR VOID OsShellCmdSystemInfoGet(VOID)
{
UINT8 isTaskEnable = YES;
UINT8 isSemEnable = LOSCFG_BASE_IPC_SEM;
UINT8 isQueueEnable = LOSCFG_BASE_IPC_QUEUE;
UINT8 isSwtmrEnable = LOSCFG_BASE_CORE_SWTMR;
#ifdef LOSCFG_BASE_IPC_SEM
UINT8 isSemEnable = YES;
#else
UINT8 isSemEnable = NO;
#endif
#ifdef LOSCFG_BASE_IPC_QUEUE
UINT8 isQueueEnable = YES;
#else
UINT8 isQueueEnable = NO;
#endif
#ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
UINT8 isSwtmrEnable = YES;
#else
UINT8 isSwtmrEnable = NO;
#endif
PRINTK("\n Module Used Total Enabled\n");
PRINTK("--------------------------------------------\n");

View File

@@ -85,12 +85,18 @@ STATIC UINT32 *taskWaterLine = NULL;
#define OS_TASK_ALL_INFO_LEN (g_taskMaxNum * (sizeof(LosTaskCB) + sizeof(UINT32)))
#ifdef LOSCFG_FS_VFS
#if defined(LOSCFG_BLACKBOX) && defined(LOSCFG_SAVE_EXCINFO)
#define SaveExcInfo(arg, ...) WriteExcInfoToBuf(arg, ##__VA_ARGS__)
#else
#define SaveExcInfo(arg, ...)
#endif
#define PROCESS_INFO_SHOW(seqBuf, arg...) do { \
if (seqBuf != NULL) { \
(void)LosBufPrintf((struct SeqBuf *)seqBuf, ##arg); \
} else { \
PRINTK(arg); \
} \
SaveExcInfo(arg); \
} while (0)
#else
#define PROCESS_INFO_SHOW(seqBuf, arg...) PRINTK(arg)
@@ -428,7 +434,7 @@ EXIT:
STATIC VOID OsShellCmdTskInfoTitle(VOID *seqBuf, UINT16 flag)
{
PROCESS_INFO_SHOW(seqBuf, "\r\n TID PID ");
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
PROCESS_INFO_SHOW(seqBuf, "Affi CPU ");
#endif
PROCESS_INFO_SHOW(seqBuf, " Status StackSize WaterLine ");
@@ -456,7 +462,7 @@ STATIC INLINE VOID OsShellTskInfoData(const LosTaskCB *taskCB, VOID *seqBuf, UIN
#endif
PROCESS_INFO_SHOW(seqBuf, " %4u%5u", taskCB->taskID, taskCB->processID);
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
PROCESS_INFO_SHOW(seqBuf, "%#5x%4d ", taskCB->cpuAffiMask, (INT16)(taskCB->currCpu));
#endif

View File

@@ -37,7 +37,7 @@
#include "los_exc.h"
#if (LOSCFG_KERNEL_SMP_LOCKDEP == YES)
#ifdef LOSCFG_KERNEL_SMP_LOCKDEP
#define LOCKDEP_GET_NAME(lockDep, index) (((SPIN_LOCK_S *)((lockDep)->heldLocks[(index)].lockPtr))->name)
#define LOCKDEP_GET_ADDR(lockDep, index) ((lockDep)->heldLocks[(index)].lockAddr)

View File

@@ -36,7 +36,7 @@
#include "los_swtmr.h"
#include "los_task_pri.h"
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
VOID LOS_MpSchedule(UINT32 target)
{

View File

@@ -30,7 +30,7 @@
*/
#include "los_spinlock.h"
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
#include "los_sched_pri.h"

View File

@@ -32,7 +32,7 @@
#include "los_task_pri.h"
#if (LOSCFG_KERNEL_SCHED_STATISTICS == YES)
#ifdef LOSCFG_KERNEL_SCHED_STATISTICS
#define HIGHTASKPRI 16
#define NS_PER_MS 1000000
#define DECIMAL_TO_PERCENTAGE 100
@@ -212,7 +212,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsShellMpStaticStart(VOID)
for (loop = 0; loop < g_taskMaxNum; loop++) {
taskCB = (((LosTaskCB *)g_taskCBArray) + loop);
if (taskCB->taskStatus & OS_TASK_STATUS_RUNNING) {
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
cpuid = taskCB->currCpu;
#endif
if ((UINT32)(OS_TASK_INVALID_CPUID) == cpuid) {
@@ -293,7 +293,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsShellMpStaticStop(VOID)
for (loop = 0; loop < g_taskMaxNum; loop++) {
taskCB = (((LosTaskCB *)g_taskCBArray) + loop);
if (taskCB->taskStatus & OS_TASK_STATUS_RUNNING) {
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
cpuid = taskCB->currCpu;
#endif
if (cpuid == (UINT32)(OS_TASK_INVALID_CPUID)) {

View File

@@ -39,7 +39,7 @@
#endif
#include "los_hw_tick_pri.h"
#include "los_tick_pri.h"
#if (LOSCFG_BASE_CORE_TSK_MONITOR == YES)
#ifdef LOSCFG_BASE_CORE_TSK_MONITOR
#include "los_stackinfo_pri.h"
#endif
#include "los_mp.h"
@@ -443,7 +443,7 @@ STATIC INLINE VOID OsSchedWakePendTimeTask(UINT64 currTime, LosTaskCB *taskCB, B
if (tempStatus & (OS_TASK_STATUS_PENDING | OS_TASK_STATUS_DELAY)) {
taskCB->taskStatus &= ~(OS_TASK_STATUS_PENDING | OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_DELAY);
if (tempStatus & OS_TASK_STATUS_PENDING) {
#if (LOSCFG_KERNEL_LITEIPC == YES)
#ifdef LOSCFG_KERNEL_LITEIPC
taskCB->ipcStatus &= ~IPC_THREAD_STATUS_PEND;
#endif
taskCB->taskStatus |= OS_TASK_STATUS_TIMEOUT;
@@ -819,7 +819,7 @@ STATIC LosTaskCB *OsGetTopTask(VOID)
UINT32 bitmap;
LosTaskCB *newTask = NULL;
UINT32 processBitmap = g_sched->queueBitmap;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
UINT32 cpuid = ArchCurrCpuid();
#endif
@@ -830,11 +830,11 @@ STATIC LosTaskCB *OsGetTopTask(VOID)
while (bitmap) {
priority = CLZ(bitmap);
LOS_DL_LIST_FOR_EACH_ENTRY(newTask, &queueList->priQueueList[priority], LosTaskCB, pendList) {
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
if (newTask->cpuAffiMask & (1U << cpuid)) {
#endif
goto FIND_TASK;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
}
#endif
}
@@ -869,7 +869,7 @@ VOID OsSchedStart(VOID)
OsSchedSetStartTime(HalClockGetCycles());
newTask->startTime = OsGerCurrSchedTimeCycle();
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
/*
* attention: current cpu needs to be set, in case first task deletion
* may fail because this flag mismatch with the real current cpu.
@@ -889,7 +889,7 @@ VOID OsSchedStart(VOID)
OsTaskContextLoad(newTask);
}
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
VOID OsSchedToUserReleaseLock(VOID)
{
/* The scheduling lock needs to be released before returning to user mode */
@@ -900,7 +900,7 @@ VOID OsSchedToUserReleaseLock(VOID)
}
#endif
#if (LOSCFG_BASE_CORE_TSK_MONITOR == YES)
#ifdef LOSCFG_BASE_CORE_TSK_MONITOR
STATIC VOID OsTaskStackCheck(LosTaskCB *runTask, LosTaskCB *newTask)
{
if (!OS_STACK_MAGIC_CHECK(runTask->topOfStack)) {
@@ -917,9 +917,9 @@ STATIC VOID OsTaskStackCheck(LosTaskCB *runTask, LosTaskCB *newTask)
STATIC INLINE VOID OsSchedSwitchCheck(LosTaskCB *runTask, LosTaskCB *newTask)
{
#if (LOSCFG_BASE_CORE_TSK_MONITOR == YES)
#ifdef LOSCFG_BASE_CORE_TSK_MONITOR
OsTaskStackCheck(runTask, newTask);
#endif /* LOSCFG_BASE_CORE_TSK_MONITOR == YES */
#endif /* LOSCFG_BASE_CORE_TSK_MONITOR */
OsTraceTaskSchedule(newTask, runTask);
}
@@ -955,7 +955,7 @@ STATIC VOID OsSchedTaskSwicth(LosTaskCB *runTask, LosTaskCB *newTask)
runTask->taskStatus &= ~OS_TASK_STATUS_RUNNING;
newTask->taskStatus |= OS_TASK_STATUS_RUNNING;
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
/* mask new running task's owner processor */
runTask->currCpu = OS_TASK_INVALID_CPUID;
newTask->currCpu = ArchCurrCpuid();
@@ -1043,7 +1043,7 @@ VOID OsSchedIrqEndCheckNeedSched(VOID)
VOID OsSchedResched(VOID)
{
LOS_ASSERT(LOS_SpinHeld(&g_taskSpin));
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
LOS_ASSERT(OsPercpuGet()->taskLockCnt == 1);
#else
LOS_ASSERT(OsPercpuGet()->taskLockCnt == 0);

View File

@@ -41,10 +41,30 @@
#include "los_vm_fault.h"
#include "los_process_pri.h"
#include "los_vm_lock.h"
#ifdef LOSCFG_FS_VFS
#include "vnode.h"
#endif
#ifndef UNUSED
#define UNUSED(x) (VOID)x
#define UNUSED(x) (VOID)(x)
#endif
#ifdef LOSCFG_DEBUG_VERSION
static int g_totalPageCacheTry = 0;
static int g_totalPageCacheHit = 0;
#define TRACE_TRY_CACHE() do { g_totalPageCacheTry++; } while (0)
#define TRACE_HIT_CACHE() do { g_totalPageCacheHit++; } while (0)
VOID ResetPageCacheHitInfo(int *try, int *hit)
{
*try = g_totalPageCacheTry;
*hit = g_totalPageCacheHit;
g_totalPageCacheHit = 0;
g_totalPageCacheTry = 0;
}
#else
#define TRACE_TRY_CACHE()
#define TRACE_HIT_CACHE()
#endif
#ifdef LOSCFG_KERNEL_VM
@@ -365,7 +385,9 @@ INT32 OsVmmFileFault(LosVmMapRegion *region, LosVmPgFault *vmf)
/* get or create a new cache node */
LOS_SpinLockSave(&mapping->list_lock, &intSave);
fpage = OsFindGetEntry(mapping, vmf->pgoff);
TRACE_TRY_CACHE();
if (fpage != NULL) {
TRACE_HIT_CACHE();
OsPageRefIncLocked(fpage);
} else {
fpage = OsPageCacheAlloc(mapping, vmf->pgoff);

View File

@@ -34,7 +34,6 @@
#include "los_vm_zone.h"
#include "los_vm_common.h"
#include "los_vm_map.h"
#include "los_vm_lock.h"
#include "los_memory.h"

View File

@@ -1135,7 +1135,7 @@ DONE:
LosMux *OsGVmSpaceMuxGet(VOID)
{
return &g_vmSpaceListMux;
return &g_vmSpaceListMux;
}
STATIC INLINE BOOL OsMemLargeAlloc(UINT32 size)

View File

@@ -37,7 +37,7 @@
#include "los_vm_phys.h"
#include "los_vm_filemap.h"
#include "los_process_pri.h"
#if (LOSCFG_BASE_CORE_SWTMR == YES)
#ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
#include "los_swtmr_pri.h"
#endif
@@ -55,12 +55,12 @@ LITE_OS_SEC_TEXT_MINOR STATIC UINT32 OomScoreProcess(LosProcessCB *candidateProc
{
UINT32 actualPm;
#if (LOSCFG_KERNEL_SMP != YES)
#ifndef LOSCFG_KERNEL_SMP
(VOID)LOS_MuxAcquire(&candidateProcess->vmSpace->regionMux);
#endif
/* we only consider actual physical memory here. */
OsUProcessPmUsage(candidateProcess->vmSpace, NULL, &actualPm);
#if (LOSCFG_KERNEL_SMP != YES)
#ifndef LOSCFG_KERNEL_SMP
(VOID)LOS_MuxRelease(&candidateProcess->vmSpace->regionMux);
#endif
return actualPm;

View File

@@ -31,13 +31,13 @@ include $(LITEOSTOPDIR)/config.mk
MODULE_NAME := rootfs
LOCAL_SRCS := $(wildcard los_rootfs.c)
LOCAL_SRCS := $(wildcard los_rootfs.c los_bootargs.c)
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/kernel/common \
ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/../../device/qemu/arm_virt/config/cfiflash
LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/../../device/qemu/drivers/cfiflash
endif
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)

View File

@@ -0,0 +1,10 @@
config BLACKBOX
bool "Enable BlackBox"
default n
help
Answer Y to enable LiteOS support blackbox
config LOG_ROOT_PATH
string "unknown"
help
define the default log path of blackbox

View File

@@ -0,0 +1,14 @@
include $(LITEOSTOPDIR)/config.mk
MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard *.c)
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/kernel/common \
-I $(LITEOSTOPDIR)/kernel/common/blackbox \
-I $(LITEOSTOPDIR)/syscall
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
include $(MODULE)

View File

@@ -0,0 +1,91 @@
/*
* Copyright (c) 2021-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.
*/
#ifndef LOS_BLACKBOX_H
#define LOS_BLACKBOX_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#include "stdarg.h"
#include "los_typedef.h"
#define PATH_MAX_LEN 256
#define EVENT_MAX_LEN 32
#define MODULE_MAX_LEN 32
#define ERROR_DESC_MAX_LEN 512
#ifndef LOSCFG_LOG_ROOT_PATH
#define LOSCFG_LOG_ROOT_PATH "/storage/data/log"
#endif
#define KERNEL_FAULT_LOG_PATH LOSCFG_LOG_ROOT_PATH "/kernel_fault.log"
#define USER_FAULT_LOG_PATH LOSCFG_LOG_ROOT_PATH "/user_fault.log"
#define MODULE_SYSTEM "SYSTEM"
#define EVENT_SYSREBOOT "SYSREBOOT"
#define EVENT_LONGPRESS "LONGPRESS"
#define EVENT_COMBINATIONKEY "COMBINATIONKEY"
#define EVENT_SUBSYSREBOOT "SUBSYSREBOOT"
#define EVENT_POWEROFF "POWEROFF"
#define EVENT_PANIC "PANIC"
#define EVENT_SYS_WATCHDOG "SYSWATCHDOG"
#define EVENT_HUNGTASK "HUNGTASK"
#define EVENT_BOOTFAIL "BOOTFAIL"
struct ErrorInfo {
char event[EVENT_MAX_LEN];
char module[MODULE_MAX_LEN];
char errorDesc[ERROR_DESC_MAX_LEN];
};
struct ModuleOps {
char module[MODULE_MAX_LEN];
void (*Dump)(const char *logDir, struct ErrorInfo *info);
void (*Reset)(struct ErrorInfo *info);
int (*GetLastLogInfo)(struct ErrorInfo *info);
int (*SaveLastLog)(const char *logDir, struct ErrorInfo *info);
};
int BBoxRegisterModuleOps(struct ModuleOps *ops);
int BBoxNotifyError(const char event[EVENT_MAX_LEN],
const char module[MODULE_MAX_LEN],
const char errorDesc[ERROR_DESC_MAX_LEN],
int needSysReset);
int OsBBoxDriverInit(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@@ -0,0 +1,127 @@
/*
* Copyright (c) 2021-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.
*/
/* ------------ includes ------------ */
#include "los_blackbox_common.h"
#ifdef LOSCFG_LIB_LIBC
#include "stdlib.h"
#include "unistd.h"
#endif
#ifdef LOSCFG_FS_VFS
#include "fs/fs.h"
#endif
#include "securec.h"
#include "los_memory.h"
/* ------------ local macroes ------------ */
/* ------------ local prototypes ------------ */
/* ------------ local function declarations ------------ */
/* ------------ global function declarations ------------ */
/* ------------ local variables ------------ */
/* ------------ function definitions ------------ */
int FullWriteFile(const char *filePath, const char *buf, size_t bufSize, int isAppend)
{
#ifdef LOSCFG_FS_VFS
int fd;
int totalToWrite = (int)bufSize;
int totalWrite = 0;
if (filePath == NULL || buf == NULL || bufSize == 0) {
BBOX_PRINT_ERR("filePath: %p, buf: %p, bufSize: %lu!\n", filePath, buf, bufSize);
return -1;
}
if (!IsLogPartReady()) {
BBOX_PRINT_ERR("log path [%s] isn't ready to be written!\n", LOSCFG_LOG_ROOT_PATH);
return -1;
}
fd = open(filePath, O_CREAT | O_RDWR | (isAppend ? O_APPEND : O_TRUNC), 0644);
if (fd < 0) {
BBOX_PRINT_ERR("Create file [%s] failed, fd: %d!\n", filePath, fd);
return -1;
}
while (totalToWrite > 0) {
int writeThisTime = write(fd, buf, totalToWrite);
if (writeThisTime < 0) {
BBOX_PRINT_ERR("Failed to write file [%s]!\n", filePath);
(void)close(fd);
return -1;
}
buf += writeThisTime;
totalToWrite -= writeThisTime;
totalWrite += writeThisTime;
}
(void)close(fd);
return (totalWrite == (int)bufSize) ? 0 : -1;
#else
(VOID)filePath;
(VOID)buf;
(VOID)bufSize;
(VOID)isAppend;
return -1;
#endif
}
int SaveBasicErrorInfo(const char *filePath, struct ErrorInfo *info)
{
char *buf = NULL;
if (filePath == NULL || info == NULL) {
BBOX_PRINT_ERR("filePath: %p, event: %p!\n", filePath, info);
return -1;
}
buf = LOS_MemAlloc(m_aucSysMem1, ERROR_INFO_MAX_LEN);
if (buf == NULL) {
BBOX_PRINT_ERR("LOS_MemAlloc failed!\n");
return -1;
}
(void)memset_s(buf, ERROR_INFO_MAX_LEN, 0, ERROR_INFO_MAX_LEN);
(void)snprintf_s(buf, ERROR_INFO_MAX_LEN, ERROR_INFO_MAX_LEN - 1,
ERROR_INFO_HEADER_FORMAT, info->event, info->module, info->errorDesc);
*(buf + ERROR_INFO_MAX_LEN - 1) = '\0';
(void)FullWriteFile(filePath, buf, strlen(buf), 0);
(void)LOS_MemFree(m_aucSysMem1, buf);
return 0;
}
#ifdef LOSCFG_FS_VFS
bool IsLogPartReady(void)
{
return access(LOSCFG_LOG_ROOT_PATH, W_OK) == 0;
}
#else
bool IsLogPartReady(void)
{
return TRUE;
}
#endif

View File

@@ -0,0 +1,61 @@
/*
* Copyright (c) 2021-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.
*/
#ifndef LOS_BLACKBOX_COMMON_H
#define LOS_BLACKBOX_COMMON_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#include "los_blackbox.h"
#include "los_printf.h"
#include "los_typedef.h"
#define ERROR_INFO_HEADER_FORMAT "#### error info ####\nevent: %s\nmodule: %s\nerrorDesc: %s\n"
#define ERROR_INFO_MAX_LEN 768
#define Min(a, b) (((a) > (b)) ? (b) : (a))
#define BBOX_PRINT_ERR(format, ...) PRINTK("bbox: func: %s, line: %d, Err: " \
format, __func__, __LINE__, ##__VA_ARGS__)
#define BBOX_PRINT_INFO(format, ...) PRINTK("bbox: Info: " format, ##__VA_ARGS__)
int FullWriteFile(const char *filePath, const char *buf, size_t bufSize, int isAppend);
int SaveBasicErrorInfo(const char *filePath, struct ErrorInfo *info);
bool IsLogPartReady(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@@ -0,0 +1,458 @@
/*
* Copyright (c) 2021-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.
*/
/* ------------ includes ------------ */
#include "los_blackbox.h"
#include "los_blackbox_common.h"
#include "los_blackbox_detector.h"
#ifdef LOSCFG_LIB_LIBC
#include "stdlib.h"
#include "unistd.h"
#endif
#include "los_base.h"
#include "los_config.h"
#include "los_excinfo_pri.h"
#include "los_hw.h"
#include "los_init.h"
#include "los_memory.h"
#include "los_sem.h"
#include "los_syscall.h"
#include "los_task_pri.h"
#include "securec.h"
#include "sys/reboot.h"
/* ------------ local macroes ------------ */
#define LOG_WAIT_TIMES 10
#define LOG_PART_WAIT_TIME 1000
/* ------------ local prototypes ------------ */
typedef struct BBoxOps {
LOS_DL_LIST opsList;
struct ModuleOps ops;
} BBoxOps;
/* ------------ local function declarations ------------ */
/* ------------ global function declarations ------------ */
/* ------------ local variables ------------ */
static bool g_bboxInitSucc = FALSE;
static UINT32 g_opsListSem = 0;
static UINT32 g_tempErrInfoSem = 0;
static UINT32 g_tempErrLogSaveSem = 0;
static LOS_DL_LIST_HEAD(g_opsList);
struct ErrorInfo *g_tempErrInfo;
/* ------------ function definitions ------------ */
static void FormatErrorInfo(struct ErrorInfo *info,
const char event[EVENT_MAX_LEN],
const char module[MODULE_MAX_LEN],
const char errorDesc[ERROR_DESC_MAX_LEN])
{
if (info == NULL || event == NULL || module == NULL || errorDesc == NULL) {
BBOX_PRINT_ERR("info: %p, event: %p, module: %p, errorDesc: %p!\n", info, event, module, errorDesc);
return;
}
(void)memset_s(info, sizeof(*info), 0, sizeof(*info));
(void)strncpy_s(info->event, sizeof(info->event), event, Min(strlen(event), sizeof(info->event) - 1));
(void)strncpy_s(info->module, sizeof(info->module), module, Min(strlen(module), sizeof(info->module) - 1));
(void)strncpy_s(info->errorDesc, sizeof(info->errorDesc), errorDesc,
Min(strlen(errorDesc), sizeof(info->errorDesc) - 1));
}
#ifdef LOSCFG_FS_VFS
static void WaitForLogPart(void)
{
BBOX_PRINT_INFO("wait for log part [%s] begin!\n", LOSCFG_LOG_ROOT_PATH);
while (!IsLogPartReady()) {
LOS_Msleep(LOG_PART_WAIT_TIME);
}
BBOX_PRINT_INFO("wait for log part [%s] end!\n", LOSCFG_LOG_ROOT_PATH);
}
#else
static void WaitForLogPart(void)
{
int i = 0;
BBOX_PRINT_INFO("wait for log part [%s] begin!\n", LOSCFG_LOG_ROOT_PATH);
while (i++ < LOG_WAIT_TIMES) {
LOS_Msleep(LOG_PART_WAIT_TIME);
}
BBOX_PRINT_INFO("wait for log part [%s] end!\n", LOSCFG_LOG_ROOT_PATH);
}
#endif
static bool FindModuleOps(struct ErrorInfo *info, BBoxOps **ops)
{
bool found = false;
if (info == NULL || ops == NULL) {
BBOX_PRINT_ERR("info: %p, ops: %p!\n", info, ops);
return found;
}
LOS_DL_LIST_FOR_EACH_ENTRY(*ops, &g_opsList, BBoxOps, opsList) {
if (*ops != NULL && strcmp((*ops)->ops.module, info->module) == 0) {
found = true;
break;
}
}
if (!found) {
BBOX_PRINT_ERR("[%s] hasn't been registered!\n", info->module);
}
return found;
}
static void InvokeModuleOps(struct ErrorInfo *info, BBoxOps *ops)
{
if (info == NULL || ops == NULL) {
BBOX_PRINT_ERR("info: %p, ops: %p!\n", info, ops);
return;
}
if (ops->ops.Dump != NULL) {
BBOX_PRINT_INFO("[%s] starts dumping log!\n", ops->ops.module);
ops->ops.Dump(LOSCFG_LOG_ROOT_PATH, info);
BBOX_PRINT_INFO("[%s] ends dumping log!\n", ops->ops.module);
}
if (ops->ops.Reset != NULL) {
BBOX_PRINT_INFO("[%s] starts resetting!\n", ops->ops.module);
ops->ops.Reset(info);
BBOX_PRINT_INFO("[%s] ends resetting!\n", ops->ops.module);
}
}
static void SaveLastLog(const char *logDir)
{
struct ErrorInfo *info = NULL;
BBoxOps *ops = NULL;
info = LOS_MemAlloc(m_aucSysMem1, sizeof(*info));
if (info == NULL) {
BBOX_PRINT_ERR("LOS_MemAlloc failed!\n");
return;
}
if (LOS_SemPend(g_opsListSem, LOS_WAIT_FOREVER) != LOS_OK) {
BBOX_PRINT_ERR("Request g_opsListSem failed!\n");
(void)LOS_MemFree(m_aucSysMem1, info);
return;
}
LOS_DL_LIST_FOR_EACH_ENTRY(ops, &g_opsList, BBoxOps, opsList) {
if (ops == NULL) {
BBOX_PRINT_ERR("ops: NULL, please check it!\n");
continue;
}
if (ops->ops.GetLastLogInfo != NULL && ops->ops.SaveLastLog != NULL) {
(void)memset_s(info, sizeof(*info), 0, sizeof(*info));
if (ops->ops.GetLastLogInfo(info) != 0) {
BBOX_PRINT_ERR("[%s] failed to get log info!\n", ops->ops.module);
continue;
}
BBOX_PRINT_INFO("[%s] starts saving log!\n", ops->ops.module);
if (ops->ops.SaveLastLog(logDir, info) != 0) {
BBOX_PRINT_ERR("[%s] failed to save log!\n", ops->ops.module);
} else {
BBOX_PRINT_INFO("[%s] ends saving log!\n", ops->ops.module);
BBOX_PRINT_INFO("[%s] starts uploading event [%s]\n", info->module, info->event);
#ifdef LOSCFG_FS_VFS
(void)UploadEventByFile(KERNEL_FAULT_LOG_PATH);
#else
BBOX_PRINT_INFO("LOSCFG_FS_VFS isn't defined!\n");
#endif
BBOX_PRINT_INFO("[%s] ends uploading event [%s]\n", info->module, info->event);
}
} else {
BBOX_PRINT_ERR("module [%s], GetLastLogInfo: %p, SaveLastLog: %p!\n",
ops->ops.module, ops->ops.GetLastLogInfo, ops->ops.SaveLastLog);
}
}
(void)LOS_SemPost(g_opsListSem);
(void)LOS_MemFree(m_aucSysMem1, info);
}
static void SaveLogWithoutReset(struct ErrorInfo *info)
{
BBoxOps *ops = NULL;
if (info == NULL) {
BBOX_PRINT_ERR("info is NULL!\n");
return;
}
if (LOS_SemPend(g_opsListSem, LOS_WAIT_FOREVER) != LOS_OK) {
BBOX_PRINT_ERR("Request g_opsListSem failed!\n");
return;
}
if (!FindModuleOps(info, &ops)) {
(void)LOS_SemPost(g_opsListSem);
return;
}
if (ops->ops.Dump == NULL && ops->ops.Reset == NULL) {
(void)LOS_SemPost(g_opsListSem);
if (SaveBasicErrorInfo(USER_FAULT_LOG_PATH, info) == 0) {
BBOX_PRINT_INFO("[%s] starts uploading event [%s]\n", info->module, info->event);
#ifdef LOSCFG_FS_VFS
(void)UploadEventByFile(USER_FAULT_LOG_PATH);
#else
BBOX_PRINT_INFO("LOSCFG_FS_VFS isn't defined!\n");
#endif
BBOX_PRINT_INFO("[%s] ends uploading event [%s]\n", info->module, info->event);
}
return;
}
InvokeModuleOps(info, ops);
(void)LOS_SemPost(g_opsListSem);
}
static void SaveTempErrorLog(void)
{
if (LOS_SemPend(g_tempErrInfoSem, LOS_WAIT_FOREVER) != LOS_OK) {
BBOX_PRINT_ERR("Request g_tempErrInfoSem failed!\n");
return;
}
if (g_tempErrInfo == NULL) {
BBOX_PRINT_ERR("g_tempErrInfo is NULL!\n");
(void)LOS_SemPost(g_tempErrInfoSem);
return;
}
if (strlen(g_tempErrInfo->event) != 0) {
SaveLogWithoutReset(g_tempErrInfo);
}
(void)LOS_SemPost(g_tempErrInfoSem);
}
static void SaveLogWithReset(struct ErrorInfo *info)
{
int ret;
BBoxOps *ops = NULL;
if (info == NULL) {
BBOX_PRINT_ERR("info is NULL!\n");
return;
}
if (!FindModuleOps(info, &ops)) {
return;
}
InvokeModuleOps(info, ops);
ret = SysReboot(0, 0, RB_AUTOBOOT);
BBOX_PRINT_INFO("SysReboot, ret: %d\n", ret);
}
static void SaveTempErrorInfo(const char event[EVENT_MAX_LEN],
const char module[MODULE_MAX_LEN],
const char errorDesc[ERROR_DESC_MAX_LEN])
{
if (event == NULL || module == NULL || errorDesc == NULL) {
BBOX_PRINT_ERR("event: %p, module: %p, errorDesc: %p!\n", event, module, errorDesc);
return;
}
if (LOS_SemPend(g_tempErrInfoSem, LOS_NO_WAIT) != LOS_OK) {
BBOX_PRINT_ERR("Request g_tempErrInfoSem failed!\n");
return;
}
FormatErrorInfo(g_tempErrInfo, event, module, errorDesc);
(void)LOS_SemPost(g_tempErrInfoSem);
}
static int SaveErrorLog(UINTPTR uwParam1, UINTPTR uwParam2, UINTPTR uwParam3, UINTPTR uwParam4)
{
const char *logDir = (const char *)uwParam1;
(void)uwParam2;
(void)uwParam3;
(void)uwParam4;
#ifdef LOSCFG_FS_VFS
WaitForLogPart();
#endif
SaveLastLog(logDir);
while (1) {
if (LOS_SemPend(g_tempErrLogSaveSem, LOS_WAIT_FOREVER) != LOS_OK) {
BBOX_PRINT_ERR("Request g_tempErrLogSaveSem failed!\n");
continue;
}
SaveTempErrorLog();
}
return 0;
}
#ifdef LOSCFG_BLACKBOX_DEBUG
static void PrintModuleOps(void)
{
struct BBoxOps *ops = NULL;
BBOX_PRINT_INFO("The following modules have been registered!\n");
LOS_DL_LIST_FOR_EACH_ENTRY(ops, &g_opsList, BBoxOps, opsList) {
if (ops == NULL) {
continue;
}
BBOX_PRINT_INFO("module: %s, Dump: %p, Reset: %p, GetLastLogInfo: %p, SaveLastLog: %p\n",
ops->ops.module, ops->ops.Dump, ops->ops.Reset, ops->ops.GetLastLogInfo, ops->ops.SaveLastLog);
}
}
#endif
int BBoxRegisterModuleOps(struct ModuleOps *ops)
{
BBoxOps *newOps = NULL;
BBoxOps *temp = NULL;
if (!g_bboxInitSucc) {
BBOX_PRINT_ERR("BlackBox isn't initialized successfully!\n");
return -1;
}
if (ops == NULL) {
BBOX_PRINT_ERR("ops is NULL!\n");
return -1;
}
newOps = LOS_MemAlloc(m_aucSysMem1, sizeof(*newOps));
if (newOps == NULL) {
BBOX_PRINT_ERR("LOS_MemAlloc failed!\n");
return -1;
}
(void)memset_s(newOps, sizeof(*newOps), 0, sizeof(*newOps));
(void)memcpy_s(&newOps->ops, sizeof(newOps->ops), ops, sizeof(*ops));
if (LOS_SemPend(g_opsListSem, LOS_WAIT_FOREVER) != LOS_OK) {
BBOX_PRINT_ERR("Request g_opsListSem failed!\n");
(void)LOS_MemFree(m_aucSysMem1, newOps);
return -1;
}
if (LOS_ListEmpty(&g_opsList)) {
goto __out;
}
LOS_DL_LIST_FOR_EACH_ENTRY(temp, &g_opsList, BBoxOps, opsList) {
if (temp == NULL) {
continue;
}
if (strcmp(temp->ops.module, ops->module) == 0) {
BBOX_PRINT_ERR("module [%s] has been registered!\n", ops->module);
(void)LOS_SemPost(g_opsListSem);
(void)LOS_MemFree(m_aucSysMem1, newOps);
return -1;
}
}
__out:
LOS_ListTailInsert(&g_opsList, &newOps->opsList);
(void)LOS_SemPost(g_opsListSem);
BBOX_PRINT_INFO("module [%s] is registered successfully!\n", ops->module);
#ifdef LOSCFG_BLACKBOX_DEBUG
PrintModuleOps();
#endif
return 0;
}
int BBoxNotifyError(const char event[EVENT_MAX_LEN],
const char module[MODULE_MAX_LEN],
const char errorDesc[ERROR_DESC_MAX_LEN],
int needSysReset)
{
if (event == NULL || module == NULL || errorDesc == NULL) {
BBOX_PRINT_ERR("event: %p, module: %p, errorDesc: %p!\n", event, module, errorDesc);
return -1;
}
if (!g_bboxInitSucc) {
BBOX_PRINT_ERR("BlackBox isn't initialized successfully!\n");
return -1;
}
if (needSysReset == 0) {
SaveTempErrorInfo(event, module, errorDesc);
(void)LOS_SemPost(g_tempErrLogSaveSem);
} else {
struct ErrorInfo *info = LOS_MemAlloc(m_aucSysMem1, sizeof(struct ErrorInfo));
if (info == NULL) {
BBOX_PRINT_ERR("LOS_MemAlloc failed!\n");
return -1;
}
FormatErrorInfo(info, event, module, errorDesc);
SaveLogWithReset(info);
(void)LOS_MemFree(m_aucSysMem1, info);
}
return 0;
}
int OsBBoxDriverInit(void)
{
UINT32 taskID;
TSK_INIT_PARAM_S taskParam;
if (LOS_BinarySemCreate(1, &g_opsListSem) != LOS_OK) {
BBOX_PRINT_ERR("Create g_opsListSem failed!\n");
return LOS_NOK;
}
if (LOS_BinarySemCreate(1, &g_tempErrInfoSem) != LOS_OK) {
BBOX_PRINT_ERR("Create g_tempErrInfoSem failed!\n");
goto __err;
}
if (LOS_BinarySemCreate(0, &g_tempErrLogSaveSem) != LOS_OK) {
BBOX_PRINT_ERR("Create g_tempErrLogSaveSem failed!\n");
goto __err;
}
LOS_ListInit(&g_opsList);
g_tempErrInfo = LOS_MemAlloc(m_aucSysMem1, sizeof(*g_tempErrInfo));
if (g_tempErrInfo == NULL) {
BBOX_PRINT_ERR("LOS_MemAlloc failed!\n");
goto __err;
}
(void)memset_s(g_tempErrInfo, sizeof(*g_tempErrInfo), 0, sizeof(*g_tempErrInfo));
(void)memset_s(&taskParam, sizeof(taskParam), 0, sizeof(taskParam));
taskParam.auwArgs[0] = (UINTPTR)LOSCFG_LOG_ROOT_PATH;
taskParam.pfnTaskEntry = (TSK_ENTRY_FUNC)SaveErrorLog;
taskParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
taskParam.pcName = "SaveErrorLog";
taskParam.usTaskPrio = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
taskParam.uwResved = LOS_TASK_STATUS_DETACHED;
#ifdef LOSCFG_KERNEL_SMP
taskParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
#endif
(void)LOS_TaskCreate(&taskID, &taskParam);
g_bboxInitSucc = TRUE;
return LOS_OK;
__err:
if (g_opsListSem != 0) {
(void)LOS_SemDelete(g_opsListSem);
}
if (g_tempErrInfoSem != 0) {
(void)LOS_SemDelete(g_tempErrInfoSem);
}
if (g_tempErrLogSaveSem != 0) {
(void)LOS_SemDelete(g_tempErrLogSaveSem);
}
return LOS_NOK;
}
LOS_MODULE_INIT(OsBBoxDriverInit, LOS_INIT_LEVEL_ARCH);

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 2021-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.
*/
/* ------------ includes ------------ */
#include "los_blackbox_detector.h"
#include "los_blackbox_common.h"
#ifdef LOSCFG_LIB_LIBC
#include "stdlib.h"
#include "unistd.h"
#endif
/* ------------ local macroes ------------ */
/* ------------ local prototypes ------------ */
/* ------------ local function declarations ------------ */
/* ------------ global function declarations ------------ */
/* ------------ local variables ------------ */
/* ------------ function definitions ------------ */
int UploadEventByFile(const char *filePath)
{
if (filePath == NULL) {
BBOX_PRINT_ERR("filePath is NULL\n");
return -1;
}
return 0;
}
int UploadEventByStream(const char *buf, size_t bufSize)
{
if (buf == NULL || bufSize == 0) {
BBOX_PRINT_ERR("buf: %p, bufSize: %u\n", buf, (UINT32)bufSize);
return -1;
}
return 0;
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2021-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.
*/
#ifndef LOS_BLACKBOX_DETECTOR_H
#define LOS_BLACKBOX_DETECTOR_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#include "los_typedef.h"
int UploadEventByFile(const char *filePath);
int UploadEventByStream(const char *buf, size_t bufSize);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@@ -0,0 +1,265 @@
/*
* Copyright (c) 2021-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.
*/
/* ------------ includes ------------ */
#include "los_blackbox_system_adapter.h"
#include "los_blackbox_common.h"
#include "los_blackbox_detector.h"
#ifdef LOSCFG_LIB_LIBC
#include "stdlib.h"
#include "unistd.h"
#endif
#include "los_base.h"
#include "los_config.h"
#ifdef LOSCFG_SAVE_EXCINFO
#include "los_excinfo_pri.h"
#endif
#include "los_hw.h"
#include "los_init.h"
#include "los_memory.h"
#include "los_vm_phys.h"
#include "los_vm_common.h"
#include "securec.h"
/* ------------ local macroes ------------ */
#define MEM_OVERLAP_COUNT 50
#define LOG_FLAG "GOODLOG"
#define FAULT_LOG_SIZE 0x4000 /* 16KB */
/* ------------ local prototypes ------------ */
struct FaultLogInfo {
char flag[8]; /* 8 is the length of the flag */
int len; /* length of the fault log saved by the module excinfo */
struct ErrorInfo info;
};
/* ------------ local function declarations ------------ */
/* ------------ global function declarations ------------ */
/* ------------ local variables ------------ */
static char *g_logBuffer = NULL;
/* ------------ function definitions ------------ */
static void SaveFaultLog(const char *filePath, const char *dataBuf, size_t bufSize, struct ErrorInfo *info)
{
(void)SaveBasicErrorInfo(filePath, info);
(void)FullWriteFile(filePath, dataBuf, bufSize, 1);
}
#ifdef LOSCFG_SAVE_EXCINFO
static void WriteExcFile(UINT32 startAddr, UINT32 space, UINT32 rwFlag, char *buf)
{
(void)startAddr;
(void)space;
(void)rwFlag;
(void)buf;
}
#endif
static void RegisterExcInfoHook(void)
{
if (g_logBuffer != NULL) {
#ifdef LOSCFG_SAVE_EXCINFO
LOS_ExcInfoRegHook(0, FAULT_LOG_SIZE - sizeof(struct FaultLogInfo),
g_logBuffer + sizeof(struct FaultLogInfo), WriteExcFile);
#endif
} else {
BBOX_PRINT_ERR("Alloc mem failed!\n");
}
}
static int AllocLogBuffer(void)
{
int i = 0;
size_t nPages = ROUNDUP(FAULT_LOG_SIZE, PAGE_SIZE) >> PAGE_SHIFT;
void *tempBuffer[MEM_OVERLAP_COUNT] = { NULL };
for (i = 0; i < MEM_OVERLAP_COUNT; i++) {
tempBuffer[i] = LOS_PhysPagesAllocContiguous(nPages);
}
for (i = 0; i < (MEM_OVERLAP_COUNT - 1); i++) {
LOS_PhysPagesFreeContiguous(tempBuffer[i], nPages);
}
g_logBuffer = tempBuffer[i];
BBOX_PRINT_INFO("g_logBuffer: %p for blackbox!\n", g_logBuffer);
return (g_logBuffer != NULL) ? 0 : -1;
}
static void Dump(const char *logDir, struct ErrorInfo *info)
{
struct FaultLogInfo *pLogInfo = NULL;
if (logDir == NULL || info == NULL) {
BBOX_PRINT_ERR("logDir: %p, info: %p!\n", logDir, info);
return;
}
if (g_logBuffer == NULL) {
BBOX_PRINT_ERR("g_logBuffer is NULL, alloc physical pages failed!\n");
return;
}
if (strcmp(info->event, EVENT_PANIC) == 0) {
pLogInfo = (struct FaultLogInfo *)g_logBuffer;
(void)memset_s(pLogInfo, sizeof(*pLogInfo), 0, sizeof(*pLogInfo));
#ifdef LOSCFG_SAVE_EXCINFO
pLogInfo->len = GetExcInfoIndex();
#else
pLogInfo->len = 0;
#endif
(void)memcpy_s(&pLogInfo->flag, sizeof(pLogInfo->flag), LOG_FLAG, strlen(LOG_FLAG));
(void)memcpy_s(&pLogInfo->info, sizeof(pLogInfo->info), info, sizeof(*info));
DCacheFlushRange((UINTPTR)g_logBuffer, (UINTPTR)(g_logBuffer + FAULT_LOG_SIZE));
} else {
#ifdef LOSCFG_SAVE_EXCINFO
SaveFaultLog(USER_FAULT_LOG_PATH, g_logBuffer + sizeof(struct FaultLogInfo),
Min(FAULT_LOG_SIZE - sizeof(struct FaultLogInfo), GetExcInfoIndex()), info);
#else
SaveFaultLog(USER_FAULT_LOG_PATH, g_logBuffer + sizeof(struct FaultLogInfo), 0, info);
#endif
}
}
static void Reset(struct ErrorInfo *info)
{
if (info == NULL) {
BBOX_PRINT_ERR("info is NULL!\n");
return;
}
if (strcmp(info->event, EVENT_PANIC) != 0) {
BBOX_PRINT_INFO("[%s] starts uploading event [%s]\n", info->module, info->event);
(void)UploadEventByFile(USER_FAULT_LOG_PATH);
BBOX_PRINT_INFO("[%s] ends uploading event [%s]\n", info->module, info->event);
}
}
static int GetLastLogInfo(struct ErrorInfo *info)
{
struct FaultLogInfo *pLogInfo = NULL;
if (info == NULL) {
BBOX_PRINT_ERR("info is NULL!\n");
return -1;
}
if (g_logBuffer == NULL) {
BBOX_PRINT_ERR("g_logBuffer is NULL, alloc physical pages failed!\n");
return -1;
}
pLogInfo = (struct FaultLogInfo *)g_logBuffer;
if (memcmp(pLogInfo->flag, LOG_FLAG, strlen(LOG_FLAG)) == 0) {
(void)memcpy_s(info, sizeof(*info), &pLogInfo->info, sizeof(pLogInfo->info));
return 0;
}
return -1;
}
static int SaveLastLog(const char *logDir, struct ErrorInfo *info)
{
#ifdef LOSCFG_FS_VFS
struct FaultLogInfo *pLogInfo = NULL;
if (logDir == NULL || info == NULL) {
BBOX_PRINT_ERR("logDir: %p, info: %p!\n", logDir, info);
return -1;
}
if (g_logBuffer == NULL) {
BBOX_PRINT_ERR("g_logBuffer is NULL, alloc physical pages failed!\n");
return -1;
}
pLogInfo = (struct FaultLogInfo *)g_logBuffer;
if (memcmp(pLogInfo->flag, LOG_FLAG, strlen(LOG_FLAG)) == 0) {
SaveFaultLog(KERNEL_FAULT_LOG_PATH, g_logBuffer + sizeof(*pLogInfo),
Min(FAULT_LOG_SIZE - sizeof(*pLogInfo), pLogInfo->len), info);
}
(void)memset_s(g_logBuffer, FAULT_LOG_SIZE, 0, FAULT_LOG_SIZE);
BBOX_PRINT_INFO("[%s] starts uploading event [%s]\n", info->module, info->event);
(void)UploadEventByFile(KERNEL_FAULT_LOG_PATH);
BBOX_PRINT_INFO("[%s] ends uploading event [%s]\n", info->module, info->event);
return 0;
#else
(VOID)logDir;
(VOID)info;
BBOX_PRINT_ERR("LOSCFG_FS_VFS isn't defined!\n");
return -1;
#endif
}
#ifdef LOSCFG_BLACKBOX_TEST
static void BBoxTest(void)
{
struct ModuleOps ops = {
.module = "MODULE_TEST",
.Dump = NULL,
.Reset = NULL,
.GetLastLogInfo = NULL,
.SaveLastLog = NULL,
};
if (BBoxRegisterModuleOps(&ops) != 0) {
BBOX_PRINT_ERR("BBoxRegisterModuleOps failed!\n");
return;
}
BBoxNotifyError("EVENT_TEST1", "MODULE_TEST", "Test BBoxNotifyError111", 0);
}
#endif
int OsBBoxSystemAdapterInit(void)
{
struct ModuleOps ops = {
.module = MODULE_SYSTEM,
.Dump = Dump,
.Reset = Reset,
.GetLastLogInfo = GetLastLogInfo,
.SaveLastLog = SaveLastLog,
};
/* allocate buffer for kmsg */
if (AllocLogBuffer() == 0) {
RegisterExcInfoHook();
if (BBoxRegisterModuleOps(&ops) != 0) {
BBOX_PRINT_ERR("BBoxRegisterModuleOps failed!\n");
LOS_PhysPagesFreeContiguous(g_logBuffer, ROUNDUP(FAULT_LOG_SIZE, PAGE_SIZE) >> PAGE_SHIFT);
g_logBuffer = NULL;
return LOS_NOK;
}
} else {
BBOX_PRINT_ERR("AllocLogBuffer failed!\n");
}
#ifdef LOSCFG_BLACKBOX_TEST
BBoxTest();
#endif
return LOS_OK;
}
LOS_MODULE_INIT(OsBBoxSystemAdapterInit, LOS_INIT_LEVEL_PLATFORM);

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2021-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.
*/
#ifndef LOS_BLACKBOX_SYSTEM_ADAPTER_H
#define LOS_BLACKBOX_SYSTEM_ADAPTER_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#include "los_blackbox.h"
#include "los_blackbox_common.h"
int OsBBoxSystemAdapterInit(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@@ -437,10 +437,10 @@ STATIC VOID StoreReadChar(CONSOLE_CB *consoleCB, char ch, INT32 readcount)
VOID KillPgrp()
{
INT32 consoleId = -1;
INT32 consoleId;
LosProcessCB *process = OsCurrProcessGet();
if ((process->consoleID > CONSOLE_NUM -1 ) || (process->consoleID < 0)) {
if ((process->consoleID > CONSOLE_NUM - 1) || (process->consoleID < 0)) {
return;
}
@@ -872,7 +872,7 @@ STATIC INT32 ConsoleGetTermios(unsigned long arg)
return -EFAULT;
}
if(LOS_ArchCopyToUser((VOID *)arg, &consoleCB->consoleTermios, sizeof(struct termios)) != 0) {
if (LOS_ArchCopyToUser((VOID *)arg, &consoleCB->consoleTermios, sizeof(struct termios)) != 0) {
return -EFAULT;
} else {
return LOS_OK;
@@ -1662,7 +1662,7 @@ STATIC UINT32 ConsoleSendTask(UINTPTR param)
return LOS_OK;
}
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
VOID OsWaitConsoleSendTaskPend(UINT32 taskID)
{
UINT32 i;

View File

@@ -120,7 +120,7 @@ extern INT32 FilepWrite(struct file *filep, const struct file_operations_vfs *fo
extern INT32 FilepPoll(struct file *filep, const struct file_operations_vfs *fops, poll_table *fds);
extern INT32 FilepIoctl(struct file *filep, const struct file_operations_vfs *fops, INT32 cmd, unsigned long arg);
extern INT32 GetFilepOps(const struct file *filep, struct file **privFilep, const struct file_operations_vfs **fops);
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_KERNEL_SMP
extern VOID OsWaitConsoleSendTaskPend(UINT32 taskID);
extern VOID OsWakeConsoleSendTask(VOID);
#endif

View File

@@ -0,0 +1,5 @@
config HIDUMPER
bool "Enable hidumper"
default n
help
Answer Y to enable LiteOS support hidumper

View File

@@ -0,0 +1,13 @@
include $(LITEOSTOPDIR)/config.mk
MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard *.c)
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/kernel/common \
-I $(LITEOSTOPDIR)/kernel/common/hidumper \
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
include $(MODULE)

View File

@@ -0,0 +1,381 @@
/*
* Copyright (c) 2021-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.
*/
/* ------------ includes ------------ */
#include "los_hidumper.h"
#ifdef LOSCFG_BLACKBOX
#include "los_blackbox.h"
#endif
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
#include "los_cpup_pri.h"
#endif
#include "los_hwi_pri.h"
#include "los_init.h"
#include "los_mp.h"
#include "los_mux.h"
#include "los_printf.h"
#include "los_process_pri.h"
#include "los_task_pri.h"
#include "los_vm_dump.h"
#include "los_vm_lock.h"
#include "los_vm_map.h"
#ifdef LOSCFG_FS_VFS
#include "fs/file.h"
#endif
#include "fs/driver.h"
#include "securec.h"
#ifdef LOSCFG_LIB_LIBC
#include "unistd.h"
#endif
#include "user_copy.h"
/* ------------ local macroes ------------ */
#define CPUP_TYPE_COUNT 3
#define HIDUMPER_DEVICE "/dev/hidumper"
#define HIDUMPER_DEVICE_MODE 0666
#define KERNEL_FAULT_ADDR 0x1
#define KERNEL_FAULT_VALUE 0x2
#define READ_BUF_SIZE 128
#define SYS_INFO_HEADER "************ sys info ***********"
#define CPU_USAGE_HEADER "************ cpu usage ***********"
#define MEM_USAGE_HEADER "************ mem usage ***********"
#define PAGE_USAGE_HEADER "************ physical page usage ***********"
#define TASK_INFO_HEADER "************ task info ***********"
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
#endif
#define REPLACE_INTERFACE(dst, src, type, func) {\
if (((type *)src)->func != NULL) {\
((type *)dst)->func = ((type *)src)->func;\
} else {\
PRINT_ERR("%s->%s is NULL!\n", #src, #func);\
}\
}
#define INVOKE_INTERFACE(adapter, type, func) {\
if (((type *)adapter)->func != NULL) {\
((type *)adapter)->func();\
} else {\
PRINT_ERR("%s->%s is NULL!\n", #adapter, #func);\
}\
}
/* ------------ local prototypes ------------ */
/* ------------ local function declarations ------------ */
STATIC INT32 HiDumperOpen(struct file *filep);
STATIC INT32 HiDumperClose(struct file *filep);
STATIC INT32 HiDumperIoctl(struct file *filep, INT32 cmd, unsigned long arg);
/* ------------ global function declarations ------------ */
#ifdef LOSCFG_SHELL
extern VOID OsShellCmdSystemInfoGet(VOID);
extern UINT32 OsShellCmdFree(INT32 argc, const CHAR *argv[]);
extern UINT32 OsShellCmdUname(INT32 argc, const CHAR *argv[]);
extern UINT32 OsShellCmdDumpPmm(VOID);
#endif
/* ------------ local variables ------------ */
static struct HiDumperAdapter g_adapter;
STATIC struct file_operations_vfs g_hidumperDevOps = {
HiDumperOpen, /* open */
HiDumperClose, /* close */
NULL, /* read */
NULL, /* write */
NULL, /* seek */
HiDumperIoctl, /* ioctl */
NULL, /* mmap */
#ifndef CONFIG_DISABLE_POLL
NULL, /* poll */
#endif
NULL, /* unlink */
};
/* ------------ function definitions ------------ */
STATIC INT32 HiDumperOpen(struct file *filep)
{
(VOID)filep;
return 0;
}
STATIC INT32 HiDumperClose(struct file *filep)
{
(VOID)filep;
return 0;
}
static void DumpSysInfo(void)
{
PRINTK("\n%s\n", SYS_INFO_HEADER);
#ifdef LOSCFG_SHELL
const char *argv[1] = {"-a"};
(VOID)OsShellCmdUname(ARRAY_SIZE(argv), &argv[0]);
(VOID)OsShellCmdSystemInfoGet();
#else
PRINTK("\nUnsupported!\n");
#endif
}
#ifdef LOSCFG_KERNEL_CPUP
static void DoDumpCpuUsageUnsafe(CPUP_INFO_S *processCpupAll,
CPUP_INFO_S *processCpup10s,
CPUP_INFO_S *processCpup1s)
{
UINT32 pid;
PRINTK("%-32s PID CPUUSE CPUUSE10S CPUUSE1S\n", "PName");
for (pid = 0; pid < g_processMaxNum; pid++) {
LosProcessCB *processCB = g_processCBArray + pid;
if (OsProcessIsUnused(processCB)) {
continue;
}
PRINTK("%-32s %u %5u.%1u%8u.%1u%7u.%-1u\n",
processCB->processName, processCB->processID,
processCpupAll[pid].usage / LOS_CPUP_PRECISION_MULT,
processCpupAll[pid].usage % LOS_CPUP_PRECISION_MULT,
processCpup10s[pid].usage / LOS_CPUP_PRECISION_MULT,
processCpup10s[pid].usage % LOS_CPUP_PRECISION_MULT,
processCpup1s[pid].usage / LOS_CPUP_PRECISION_MULT,
processCpup1s[pid].usage % LOS_CPUP_PRECISION_MULT);
}
}
#endif
static void DumpCpuUsageUnsafe(void)
{
PRINTK("\n%s\n", CPU_USAGE_HEADER);
#ifdef LOSCFG_KERNEL_CPUP
UINT32 size;
CPUP_INFO_S *processCpup = NULL;
CPUP_INFO_S *processCpupAll = NULL;
CPUP_INFO_S *processCpup10s = NULL;
CPUP_INFO_S *processCpup1s = NULL;
size = sizeof(*processCpup) * g_processMaxNum * CPUP_TYPE_COUNT;
processCpup = LOS_MemAlloc(m_aucSysMem1, size);
if (processCpup == NULL) {
PRINT_ERR("func: %s, LOS_MemAlloc failed, Line: %d\n", __func__, __LINE__);
return;
}
processCpupAll = processCpup;
processCpup10s = processCpupAll + g_processMaxNum;
processCpup1s = processCpup10s + g_processMaxNum;
(VOID)memset_s(processCpup, size, 0, size);
LOS_GetAllProcessCpuUsage(CPUP_ALL_TIME, processCpupAll, g_processMaxNum * sizeof(CPUP_INFO_S));
LOS_GetAllProcessCpuUsage(CPUP_LAST_TEN_SECONDS, processCpup10s, g_processMaxNum * sizeof(CPUP_INFO_S));
LOS_GetAllProcessCpuUsage(CPUP_LAST_ONE_SECONDS, processCpup1s, g_processMaxNum * sizeof(CPUP_INFO_S));
DoDumpCpuUsageUnsafe(processCpupAll, processCpup10s, processCpup1s);
(VOID)LOS_MemFree(m_aucSysMem1, processCpup);
#else
PRINTK("\nUnsupported!\n");
#endif
}
static void DumpMemUsage(void)
{
PRINTK("\n%s\n", MEM_USAGE_HEADER);
#ifdef LOSCFG_SHELL
PRINTK("Unit: KB\n");
const char *argv[1] = {"-k"};
(VOID)OsShellCmdFree(ARRAY_SIZE(argv), &argv[0]);
PRINTK("%s\n", PAGE_USAGE_HEADER);
(VOID)OsShellCmdDumpPmm();
#else
PRINTK("\nUnsupported!\n");
#endif
}
static void DumpTaskInfo(void)
{
PRINTK("\n%s\n", TASK_INFO_HEADER);
#ifdef LOSCFG_SHELL
(VOID)OsShellCmdTskInfoGet(OS_ALL_TASK_MASK, NULL, OS_PROCESS_INFO_ALL);
#else
PRINTK("\nUnsupported!\n");
#endif
}
#ifdef LOSCFG_BLACKBOX
static void PrintFileData(INT32 fd)
{
#ifdef LOSCFG_FS_VFS
CHAR buf[READ_BUF_SIZE];
if (fd < 0) {
PRINT_ERR("fd: %d!\n", fd);
return;
}
(void)memset_s(buf, sizeof(buf), 0, sizeof(buf));
while (read(fd, buf, sizeof(buf) - 1) > 0) {
PRINTK("%s", buf);
(void)memset_s(buf, sizeof(buf), 0, sizeof(buf));
}
#else
(VOID)fd;
PRINT_ERR("LOSCFG_FS_VFS isn't defined!\n");
#endif
}
static void PrintFile(const char *filePath, const char *pHeader)
{
#ifdef LOSCFG_FS_VFS
int fd;
if (filePath == NULL || pHeader == NULL) {
PRINT_ERR("filePath: %p, pHeader: %p\n", filePath, pHeader);
return;
}
fd = open(filePath, O_RDONLY);
if (fd >= 0) {
PRINTK("\n%s\n", pHeader);
PrintFileData(fd);
(void)close(fd);
} else {
PRINT_ERR("Open [%s] failed or there's no fault log!\n", filePath);
}
#else
(VOID)filePath;
(VOID)pHeader;
PRINT_ERR("LOSCFG_FS_VFS isn't defined!\n");
#endif
}
#endif
static void DumpFaultLog(void)
{
#ifdef LOSCFG_BLACKBOX
PrintFile(KERNEL_FAULT_LOG_PATH, "************kernel fault info************");
PrintFile(USER_FAULT_LOG_PATH, "************user fault info************");
#endif
}
static void DumpMemData(struct MemDumpParam *param)
{
PRINTK("\nDumpType: %d\n", param->type);
PRINTK("Unsupported now!\n");
}
static void InjectKernelCrash(void)
{
#ifdef LOSCFG_DEBUG_VERSION
*((INT32 *)KERNEL_FAULT_ADDR) = KERNEL_FAULT_VALUE;
#else
PRINTK("\nUnsupported!\n");
#endif
}
static INT32 HiDumperIoctl(struct file *filep, INT32 cmd, unsigned long arg)
{
INT32 ret = 0;
switch (cmd) {
case HIDUMPER_DUMP_ALL:
INVOKE_INTERFACE(&g_adapter, struct HiDumperAdapter, DumpSysInfo);
INVOKE_INTERFACE(&g_adapter, struct HiDumperAdapter, DumpCpuUsage);
INVOKE_INTERFACE(&g_adapter, struct HiDumperAdapter, DumpMemUsage);
INVOKE_INTERFACE(&g_adapter, struct HiDumperAdapter, DumpTaskInfo);
break;
case HIDUMPER_CPU_USAGE:
INVOKE_INTERFACE(&g_adapter, struct HiDumperAdapter, DumpCpuUsage);
break;
case HIDUMPER_MEM_USAGE:
INVOKE_INTERFACE(&g_adapter, struct HiDumperAdapter, DumpMemUsage);
break;
case HIDUMPER_TASK_INFO:
INVOKE_INTERFACE(&g_adapter, struct HiDumperAdapter, DumpTaskInfo);
break;
case HIDUMPER_INJECT_KERNEL_CRASH:
INVOKE_INTERFACE(&g_adapter, struct HiDumperAdapter, InjectKernelCrash);
break;
case HIDUMPER_DUMP_FAULT_LOG:
INVOKE_INTERFACE(&g_adapter, struct HiDumperAdapter, DumpFaultLog);
break;
case HIDUMPER_MEM_DATA:
if (g_adapter.DumpMemData != NULL) {
g_adapter.DumpMemData((struct MemDumpParam *)arg);
}
break;
default:
ret = EPERM;
PRINTK("Invalid CMD: 0x%x\n", (UINT32)cmd);
break;
}
return ret;
}
static void RegisterCommonAdapter(void)
{
struct HiDumperAdapter adapter;
adapter.DumpSysInfo = DumpSysInfo;
adapter.DumpCpuUsage = DumpCpuUsageUnsafe;
adapter.DumpMemUsage = DumpMemUsage;
adapter.DumpTaskInfo = DumpTaskInfo;
adapter.DumpFaultLog = DumpFaultLog;
adapter.DumpMemData = DumpMemData;
adapter.InjectKernelCrash = InjectKernelCrash;
HiDumperRegisterAdapter(&adapter);
}
int HiDumperRegisterAdapter(struct HiDumperAdapter *pAdapter)
{
if (pAdapter == NULL) {
PRINT_ERR("pAdapter: %p\n", pAdapter);
return -1;
}
REPLACE_INTERFACE(&g_adapter, pAdapter, struct HiDumperAdapter, DumpSysInfo);
REPLACE_INTERFACE(&g_adapter, pAdapter, struct HiDumperAdapter, DumpCpuUsage);
REPLACE_INTERFACE(&g_adapter, pAdapter, struct HiDumperAdapter, DumpMemUsage);
REPLACE_INTERFACE(&g_adapter, pAdapter, struct HiDumperAdapter, DumpTaskInfo);
REPLACE_INTERFACE(&g_adapter, pAdapter, struct HiDumperAdapter, DumpFaultLog);
REPLACE_INTERFACE(&g_adapter, pAdapter, struct HiDumperAdapter, DumpMemData);
REPLACE_INTERFACE(&g_adapter, pAdapter, struct HiDumperAdapter, InjectKernelCrash);
return 0;
}
int OsHiDumperDriverInit(void)
{
INT32 ret;
#ifdef LOSCFG_DEBUG_VERSION
RegisterCommonAdapter();
ret = register_driver(HIDUMPER_DEVICE, &g_hidumperDevOps, HIDUMPER_DEVICE_MODE, NULL);
if (ret != 0) {
PRINT_ERR("Hidumper register driver failed!\n");
return -1;
}
#endif
return 0;
}
LOS_MODULE_INIT(OsHiDumperDriverInit, LOS_INIT_LEVEL_KMOD_EXTENDED);

View File

@@ -0,0 +1,88 @@
/*
* Copyright (c) 2021-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.
*/
#ifndef LOS_HIDUMPER_H
#define LOS_HIDUMPER_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifndef __user
#define __user
#endif
#define PATH_MAX_LEN 256
enum MemDumpType {
DUMP_TO_STDOUT,
DUMP_REGION_TO_STDOUT,
DUMP_TO_FILE,
DUMP_REGION_TO_FILE
};
struct MemDumpParam {
enum MemDumpType type;
unsigned long long start;
unsigned long long size;
char filePath[PATH_MAX_LEN];
};
struct HiDumperAdapter {
void (*DumpSysInfo)(void);
void (*DumpCpuUsage)(void);
void (*DumpMemUsage)(void);
void (*DumpTaskInfo)(void);
void (*DumpFaultLog)(void);
void (*DumpMemData)(struct MemDumpParam *param);
void (*InjectKernelCrash)(void);
};
#define HIDUMPER_IOC_BASE 'd'
#define HIDUMPER_DUMP_ALL _IO(HIDUMPER_IOC_BASE, 1)
#define HIDUMPER_CPU_USAGE _IO(HIDUMPER_IOC_BASE, 2)
#define HIDUMPER_MEM_USAGE _IO(HIDUMPER_IOC_BASE, 3)
#define HIDUMPER_TASK_INFO _IO(HIDUMPER_IOC_BASE, 4)
#define HIDUMPER_INJECT_KERNEL_CRASH _IO(HIDUMPER_IOC_BASE, 5)
#define HIDUMPER_DUMP_FAULT_LOG _IO(HIDUMPER_IOC_BASE, 6)
#define HIDUMPER_MEM_DATA _IOW(HIDUMPER_IOC_BASE, 7, struct MemDumpParam)
int HiDumperRegisterAdapter(struct HiDumperAdapter *pAdapter);
int OsHiDumperDriverInit(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@@ -0,0 +1,245 @@
/*
* 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 "los_bootargs.h"
#include "los_base.h"
#include "string.h"
#if defined(LOSCFG_STORAGE_SPINOR) || defined(LOSCFG_STORAGE_SPINAND) || defined(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7)
#include "mtd_list.h"
#endif
#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
#include "cfiflash.h"
#endif
#ifdef LOSCFG_STORAGE_EMMC
#include "disk.h"
#endif
STATIC CHAR *g_cmdLine = NULL;
STATIC UINT64 g_alignSize = 0;
STATIC struct BootArgs g_bootArgs[MAX_ARGS_NUM] = {0};
INT32 LOS_GetCmdLine() {
int ret = 0;
g_cmdLine = (CHAR *)malloc(COMMAND_LINE_SIZE);
if (g_cmdLine == NULL) {
PRINT_ERR("Malloc g_cmdLine space error!\n");
return LOS_NOK;
}
#ifdef LOSCFG_STORAGE_EMMC
los_disk *emmcDisk = los_get_mmcdisk_bytype(EMMC);
if (emmcDisk == NULL) {
PRINT_ERR("Get EMMC disk failed!\n");
goto ERROUT;
}
g_alignSize = EMMC_SEC_SIZE;
ret = los_disk_read(emmcDisk->disk_id, g_cmdLine, COMMAND_LINE_ADDR / EMMC_SEC_SIZE,
COMMAND_LINE_SIZE / EMMC_SEC_SIZE, TRUE);
if (ret == 0) {
return LOS_OK;
}
#endif
#ifdef LOSCFG_STORAGE_SPINOR
struct MtdDev *mtd = GetMtd("spinor");
if (mtd == NULL) {
PRINT_ERR("Get spinor mtd failed!\n");
goto ERROUT;
}
g_alignSize = mtd->eraseSize;
ret = mtd->read(mtd, COMMAND_LINE_ADDR, COMMAND_LINE_SIZE, g_cmdLine);
if (ret == COMMAND_LINE_SIZE) {
return LOS_OK;
}
#endif
#ifdef LOSCFG_STORAGE_SPINAND
struct MtdDev *mtd = GetMtd("nand");
if (mtd == NULL) {
PRINT_ERR("Get nand mtd failed!\n");
goto ERROUT;
}
g_alignSize = mtd->eraseSize;
ret = mtd->read(mtd, COMMAND_LINE_ADDR, COMMAND_LINE_SIZE, g_cmdLine);
if (ret == COMMAND_LINE_SIZE) {
return LOS_OK;
}
#endif
#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
struct MtdDev *mtd = GetCfiMtdDev();
if (mtd == NULL) {
PRINT_ERR("Get CFI mtd failed!\n");
goto ERROUT;
}
g_alignSize = mtd->eraseSize;
ret = mtd->read(mtd, CFIFLASH_BOOTARGS_ADDR, COMMAND_LINE_SIZE, g_cmdLine);
if (ret == COMMAND_LINE_SIZE) {
return LOS_OK;
}
#endif
PRINT_ERR("Read cmdline error!\n");
ERROUT:
free(g_cmdLine);
g_cmdLine = NULL;
return LOS_NOK;
}
VOID LOS_FreeCmdLine() {
if (g_cmdLine != NULL) {
free(g_cmdLine);
g_cmdLine = NULL;
}
}
STATIC INT32 GetBootargs(CHAR **args)
{
#ifdef LOSCFG_BOOTENV_RAM
*args = OsGetArgsAddr();
return LOS_OK;
#else
INT32 i;
INT32 len = 0;
CHAR *tmp = NULL;
const CHAR *bootargsName = "bootargs=";
if (g_cmdLine == NULL) {
PRINT_ERR("Should call LOS_GetCmdLine() first!\n");
return LOS_NOK;
}
for (i = 0; i < COMMAND_LINE_SIZE; i += len + 1) {
len = strlen(g_cmdLine + i);
tmp = strstr(g_cmdLine + i, bootargsName);
if (tmp != NULL) {
*args = tmp + strlen(bootargsName);
return LOS_OK;
}
}
PRINT_ERR("Cannot find bootargs!\n");
return LOS_NOK;
#endif
}
INT32 LOS_ParseBootargs() {
INT32 idx = 0;
INT32 ret;
CHAR *args;
CHAR *argName;
CHAR *argValue;
ret = GetBootargs(&args);
if (ret != LOS_OK) {
return LOS_NOK;
}
while ((argValue = strsep(&args, " ")) != NULL) {
argName = strsep(&argValue, "=");
if (argValue == NULL) {
/* If the argument is not compliance with the format 'foo=bar' */
g_bootArgs[idx].argName = argName;
g_bootArgs[idx].argValue = argName;
} else {
g_bootArgs[idx].argName = argName;
g_bootArgs[idx].argValue = argValue;
}
if (++idx >= MAX_ARGS_NUM) {
/* Discard the rest arguments */
break;
}
}
return LOS_OK;
}
INT32 LOS_GetArgValue(CHAR *argName, CHAR **argValue) {
INT32 idx = 0;
while (idx < MAX_ARGS_NUM) {
if (g_bootArgs[idx].argName == NULL) {
break;
}
if (strcmp(argName, g_bootArgs[idx].argName) == 0) {
*argValue = g_bootArgs[idx].argValue;
return LOS_OK;
}
idx++;
}
return LOS_NOK;
}
UINT64 LOS_GetAlignsize() {
return g_alignSize;
}
UINT64 LOS_SizeStrToNum(CHAR *value)
{
UINT64 num = 0;
/* If the string is a hexadecimal value */
if (sscanf_s(value, "0x%x", &num) > 0) {
value += strlen("0x");
if (strspn(value, "0123456789abcdefABCDEF") < strlen(value)) {
goto ERROUT;
}
return num;
}
/* If the string is a decimal value in unit *Bytes */
INT32 ret = sscanf_s(value, "%d", &num);
INT32 decOffset = strspn(value, "0123456789");
CHAR *endPos = value + decOffset;
if ((ret <= 0) || (decOffset < (strlen(value) - 1))) {
goto ERROUT;
}
if (strlen(endPos) == 0) {
return num;
} else if (strcasecmp(endPos, "k") == 0) {
num = num * BYTES_PER_KBYTE;
} else if (strcasecmp(endPos, "m") == 0) {
num = num * BYTES_PER_MBYTE;
} else if (strcasecmp(endPos, "g") == 0) {
num = num * BYTES_PER_GBYTE;
} else {
goto ERROUT;
}
return num;
ERROUT:
PRINT_ERR("Invalid value string \"%s\"!\n", value);
return num;
}

View File

@@ -0,0 +1,61 @@
/*
* 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.
*/
#ifndef _LOS_BOOTARGS_H
#define _LOS_BOOTARGS_H
#include "los_typedef.h"
#define BYTES_PER_GBYTE (1 << 30)
#define BYTES_PER_MBYTE (1 << 20)
#define BYTES_PER_KBYTE (1 << 10)
#define COMMAND_LINE_ADDR (LOSCFG_BOOTENV_ADDR * BYTES_PER_KBYTE)
#define COMMAND_LINE_SIZE 1024
#define MAX_ARGS_NUM 100
#ifdef LOSCFG_STORAGE_EMMC
#define EMMC_SEC_SIZE 512
#endif
struct BootArgs {
CHAR *argName;
CHAR *argValue;
};
INT32 LOS_GetCmdLine(VOID);
VOID LOS_FreeCmdLine(VOID);
INT32 LOS_ParseBootargs(VOID);
INT32 LOS_GetArgValue(CHAR *argName, CHAR **argValue);
UINT64 LOS_GetAlignsize(VOID);
UINT64 LOS_SizeStrToNum(CHAR *value);
#ifdef LOSCFG_BOOTENV_RAM
CHAR *OsGetArgsAddr(VOID);
#endif
#endif /* _LOS_BOOTARGS_H */

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