Compare commits

..

512 Commits

Author SHA1 Message Date
openharmony_ci
cc6b4e3b06 !1046 Fix : pthread_cond_timedwait 信号丢失问题修复挑单到3.0-LTS 分支
Merge pull request !1046 from yinjiaming/cherry-pick-1680507888
2023-04-10 09:20:52 +00:00
yinjiaming
d13b497b01 fixed 2374c01 from https://gitee.com/hgbveiu743/kernel_liteos_m/pulls/1043
fix:pthread_cond_timedwait解锁后清理的问题
该函数解锁mutex 后先清理事件,导致等的事件丢失

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: I36f8658b1b850734bc029b486fec103f6bd10588
2023-04-03 07:44:51 +00:00
openharmony_ci
887a845874 !724 fix: 修复系统时间比RTC时间过快的问题
Merge pull request !724 from zhushengle/tick_3.0.0
2022-06-25 10:12:26 +00:00
zhushengle
8ee33a771b fix: 修复系统时间比RTC时间过快的问题
1.标记在时间接口中更新base后在中断中不再更新base
2.优化tick计算

Close #I5DCRB

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I525e6e996fd40890b52c1c749ef0bad20c8136d8
2022-06-25 09:45:45 +08:00
openharmony_ci
c182540a92 !716 fix:ping命令访问野指针及内存泄漏问题修复
Merge pull request !716 from Zhaotianyu/0617ping_fix
2022-06-18 10:06:29 +00:00
arvinzzz
d837ed3e9d fix: ping命令内访问野指针及内存泄漏
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
2022-06-17 16:54:51 +08:00
openharmony_ci
a2371f1b27 !706 【3.0-LTS】 littlefs接口缺乏锁的保护
Merge pull request !706 from Far/OpenHarmony-3.0-LTS
2022-06-13 07:53:29 +00:00
Far
8245cd5cd0 fix: 修复littlefs适配层锁的问题
littlefs适配lfs_api.c中调用littlefs原生接口未用锁保护,修复之

Close #I5BVO3

Signed-off-by: Far <yesiyuan2@huawei.com>
Change-Id: I18e99d2be27c9de86acd1610b58168d9190203bd
2022-06-13 14:04:44 +08:00
openharmony_ci
b9311b9aa0 !696 FatFs升级r0.14a版本同步3.0分支
Merge pull request !696 from wangchen/05_31_up_m
2022-06-02 07:43:02 +00:00
wangchen
8cf75d80fd fix: FatFs升级r0.14a版本同步3.0分支
【背景】FatFs升级r0.14a版本同步3.0分支

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

Change-Id: I571f458a19d04520c86ab0ed63edcabb25d80e5e
2022-05-31 09:00:54 +00:00
openharmony_ci
4491d561c7 !679 内核codex清零
Merge pull request !679 from Kiita/0421_codex
2022-04-25 04:36:10 +00:00
zhangyan
1bf61bb4b0 内核codex告警清零
Signed-off-by: Kiita <zhanyan@huawei.com>
Change-Id: Ie510061dd37e4bafcb208e08311f43ef3119040c
2022-04-24 09:05:50 +00:00
openharmony_ci
b62463abc5 !594 处理M核编译告警
Merge pull request !594 from yinjiaming/OpenHarmony-3.0-LTS
2022-02-15 01:21:53 +00:00
yinjiaming
6ffea886d3 fix: 编译告警清零
【背景】

3.0 LTS 告警清零

【修改方案】
添加了安全函数的检查,将不安全的函数改写为安全函数

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

re #I4TM2U

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: I4479172e755821916aa6f299607fdceac763d468
2022-02-14 12:41:52 +00:00
openharmony_ci
9de6f57cda !549 挑单 pthread_create创建的线程未设置detach属性,主动退出后,OsGetAllTskInfo调用后,相关的任务名为乱码
Merge pull request !549 from wangchen/exit_3
2022-01-18 03:54:25 +00:00
openharmony_ci
307ab396a5 !548 挑单 L0 pthread_cond_timedwait接口存在计算溢出
Merge pull request !548 from wangchen/cond_3
2022-01-18 03:53:40 +00:00
wangchen
96b2eaeab6 fix: thread_create创建的线程未设置detach属性,主动退出后,OsGetAllTskInfo调用后,相关的任务名为乱码
【背景】thread_create创建的线程未设置detach属性,主动退出后,OsGetAllTskInfo调用后,相关的任务名为乱码

【修改方案】
修改线程退出流程
【影响】
对现有的产品编译不会有影响。

re #I4R4D3
Signed-off-by: wangchen <wangchen64@huawei.com>
2022-01-17 08:02:20 +00:00
wangchen
58e67dde3b fix: L0 pthread_cond_timedwait接口实现存在的几个问题
【背景】L0 pthread_cond_timedwait接口存在计算溢出

【修改方案】
1,新增abstick 相关修改,先判断再转成32位,避免截断
2,LOS_Event相关函数返回值的处理已存在,无需处理
【影响】
对现有的产品编译不会有影响。

re #I4R4A5
Signed-off-by: wangchen <wangchen64@huawei.com>
2022-01-17 07:14:09 +00:00
openharmony_ci
f74067b24f !519 chore: shell体验优化
Merge pull request !519 from huangshan/cherry-pick-1640932575
2022-01-07 03:21:00 +00:00
huangshan
86bc68744d fixed 57cff79 from https://gitee.com/uhamc/kernel_liteos_m/pulls/386
chore: shell完善帮助信息,特殊处理不可见字符

Signed-off-by: huangshan <huangshan9@huawei.com>
Change-Id: I3cbc559c388b5d5a524783c1f55c1e569a44465c
2021-12-31 06:36:18 +00:00
openharmony_ci
39db69b6bf !478 添加bundle.json
Merge pull request !478 from pjscc/OpenHarmony-3.0-LTS
2021-12-31 03:13:18 +00:00
openharmony_ci
87c6e9476d !500 【fix】api_shell.c 宏修改
Merge pull request !500 from pef/lts_sync
2021-12-30 08:20:32 +00:00
openharmony_ci
94537e17ae !507 fix:在非静态初始化条件下pthread_mutex_lock,没有经过init初始化就可以对已销毁的锁进行加锁 挑单到3.0分支
Merge pull request !507 from x_xiny/fix_pthread_mutex_lock
2021-12-29 07:21:32 +00:00
openharmony_ci
9717eafff7 !514 fix the compile warning
Merge pull request !514 from laojr1/OpenHarmony-3.0-LTS
2021-12-29 06:23:04 +00:00
老家荣
0712c2df56 chore: 解决 cmsis_liteos2.c:115:23: warning 编译告警
Signed-off-by: laojr1 <laojr1@midea.com>
2021-12-29 14:11:44 +08:00
pjscc
50b4e91f91 feat: 添加bundle.json作为hpm包管理描述文件
Signed-off-by: pjscc <pangjiashuai@huawei.com>
2021-12-29 10:33:46 +08:00
openharmony_ci
443d9deb9b !483 fix: 修复los_interrupt.c文件中HalHwiInit函数里未使能未对齐异常问题
Merge pull request !483 from kenneth/cherry-pick-1640158553
2021-12-29 00:54:26 +00:00
kenneth
caa28225a8 fixed d32e25f from https://gitee.com/rtos_yuan/kernel_liteos_m/pulls/362
fix: 修复los_interrupt.c文件中HalHwiInit函数里未使能未对齐异常问题

修复los_interrupt.c文件中HalHwiInit函数里未使能未对齐异常问题

close #I4EJGR

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-12-28 09:13:14 +08:00
openharmony_ci
fdb12dbe31 !486 fix: 移除los_arch_interrupt.h文件中冗余声明的函数VOID OsExcInit(VOID)
Merge pull request !486 from kenneth/cherry-pick-1640158838
2021-12-28 00:54:46 +00:00
openharmony_ci
8ebfe352f5 !490 fix: gcc编译testsuite编译问题修复
Merge pull request !490 from kenneth/cherry-pick-1640160367
2021-12-28 00:53:56 +00:00
x-xiny
2332f34a79 fix:在非静态初始化条件下pthread_mutex_lock,没有经过init初始化就可以对已销毁的锁进行加锁
【背景】
 在非静态初始化条件下pthread_mutex_lock,没有经过init初始化就可以对已销毁的锁进行加锁

【修改方案】
 在pthread_mutex_destroy中将mutex的magic标记字段清除

 re #I4I7OA

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

Change-Id: I5d4cceff852e20e659a7cd06acf27cc6f381962c
2021-12-27 06:23:22 +00:00
pef
314af71a48 fix: 将未定义小写"true","false"改为"TRUE","FALSE"。
【背景】
api_shell.c文件使用小写的true和false 却没有定义
[OHOS ERROR] ../../../kernel/liteos_m/components/net/lwip-2.1/porting/src/api_shell.c:342:25: error: 'false' undeclared (first use in this function)
[OHOS ERROR]      BOOL timeout_flag = false;
编译报错。
【修改方案】
1. 将未定义的 true,false改为已定义的宏TRUE,FALSE。

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

re #I43D20

Change-Id: If66adab35f2315d0caca2a487960be887567126b
Signed-off-by: pef <cyd1997@126.com>
2021-12-27 09:55:08 +08:00
openharmony_ci
2ef5ff366e !488 fix: 删除LOS_TRACE 记录SWTMR_START中的无效字段
Merge pull request !488 from Zhaotianyu/cherry-pick-1640159998
2021-12-23 08:46:38 +00:00
openharmony_ci
5acd9b36ff !481 fix:修复Fault异常模块中FPU宏等问题
Merge pull request !481 from kenneth/cherry-pick-1640158227
2021-12-23 07:17:18 +00:00
openharmony_ci
314102c234 !485 fix: los_exc.S中_ExcInMsp主栈中异常处理函数中异常返回类型错误
Merge pull request !485 from kenneth/cherry-pick-1640158674
2021-12-23 07:15:36 +00:00
openharmony_ci
b31437fe27 !489 fix: 解决los_pm.c:743:19: warning 编译告警
Merge pull request !489 from kenneth/cherry-pick-1640160304
2021-12-23 07:11:28 +00:00
openharmony_ci
a2852d8bce !482 fix:hook层LOS_HOOK_TYPE_SEM_PEND的runningTask入参可能为空
Merge pull request !482 from Zhaotianyu/cherry-pick-1640158494
2021-12-22 09:33:02 +00:00
openharmony_ci
0ce46a3989 !484 fix:修复不能开启硬浮点选项的问题
Merge pull request !484 from Zhaotianyu/cherry-pick-1640158615
2021-12-22 09:32:42 +00:00
openharmony_ci
b5db6ee2d4 !487 解决gmtime和localtime接口由于g_tm全局变量导致的竞态问题
Merge pull request !487 from JerryH/cherry-pick-1640159938
2021-12-22 08:47:05 +00:00
kenneth
f0ed09be65 fixed f7d26b8 from https://gitee.com/rtos_yuan/kernel_liteos_m/pulls/343
fix: gcc编译testsuite编译问题修复

修复It_los_mem.h中没有定义LOS_DLNK_NODE_HEAD_SIZE、MIN_DLNK_POOL_SIZE,编译告警等问题。

close #I4DAOU

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-12-22 08:06:07 +00:00
kenneth
802e01de21 fixed 0c72c8b from https://gitee.com/rtos_yuan/kernel_liteos_m/pulls/340
fix: 解决los_pm.c:743:19: warning 编译告警

修复PRINT_ERR函数格式化参数数目不一致。

close #I4D4L8

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-12-22 08:05:04 +00:00
LiteOS2021
d95a1523f2 fixed afbc9a5 from https://gitee.com/arvinzzz/kernel_liteos_m/pulls/348
fix: 优化trace buffer初始化,删除swtmr 桩中的无效参数
close #I4DPR7

Signed-off-by: LiteOS2021 <dinglu@huawei.com>
2021-12-22 07:59:58 +00:00
JerryH
0a1df72f7e fixed 1454b76 from https://gitee.com/JerryH1011/kernel_liteos_m/pulls/454
fix: 解决gmtime和localtime接口由于g_tm全局变量导致的竞态问题

删除全局变量,接口使用自己的内部静态变量,避免竞态

Close #I4LW3H

Signed-off-by: JerryH <huangjieliang@huawei.com>
Change-Id: I3c74b1897b3909df93d21b9d521af270cc6fc610
2021-12-22 07:59:00 +00:00
kenneth
48484444ce fixed 136952f from https://gitee.com/rtos_yuan/kernel_liteos_m/pulls/342
fix: 移除los_arch_interrupt.h文件中冗余声明的函数VOID OsExcInit(VOID)

VOID OsExcInit(VOID)函数的注释中参数描述错误,并且该函数并没有在C源文件中使用到,需要删除。

close #I4D9OO

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-12-22 07:40:38 +00:00
kenneth
6240af2522 fixed c51df7a from https://gitee.com/rtos_yuan/kernel_liteos_m/pulls/363
fix: los_exc.S中_ExcInMsp主栈中异常处理函数中异常返回类型错误

修复los_exc.S中_ExcInMsp主栈中异常处理函数中异常返回类型错误

close #I4EJI4

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-12-22 07:37:56 +00:00
arvinzzz
b1b46451e7 fixed 988fd85 from https://gitee.com/arvinzzz/kernel_liteos_m/pulls/300
fix: 支持硬浮点编译

1. 通过本工程的gn编译时,需要在device目录下,单板的关于内核的config.gn中指定-mfloat-abi的等级,并在单板相关代码的编译选项中保持-mfloat-abi一致
2. 通过本工程的Makefile编译时,需要在kernel/liteos_m/targets/下添加单板相关的代码配置,在Makefile中设置-mfloat-abi即可
3. 通过IDE编译本工程时,需要在IDE的汇编文件相关编译选项中加入 -imacros $(LITEOSTOPDIR)/kernel/include/los_config.h,保证浮点等级在汇编文件中生效

close: #I48KJP
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: Ibf9b750b922be2530de349981d55e40b5919933f
2021-12-22 07:36:56 +00:00
arvinzzz
54936c19bd fixed 3fd22ac from https://gitee.com/arvinzzz/kernel_liteos_m/pulls/324
fix: 修复hook层LOS_HOOK_TYPE_SEM_PEND的runningTask入参可能为空

在校验完semPend之后,就获取好runningTask并且与semPend关联

close: #I4BU4P
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: Ib56a1a1db8e4471d9e2adb0b7c3d8b17b1f87b8d
2021-12-22 07:34:56 +00:00
kenneth
7a6242549f fixed 2da043c from https://gitee.com/rtos_yuan/kernel_liteos_m/pulls/367
fix:修复Fault异常模块中FPU宏等问题

去掉不必要的宏判断__FPU_PRESENT;参数变量名称 uwPid改为pid,和函数HalExcHandleEntry的参数保持一致

close #I4D575

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-12-22 07:30:27 +00:00
openharmony_ci
07ef35ccdf !467 pthread_cond_timedwait接口不规范
Merge pull request !467 from wangchen/posix_cond
2021-12-20 03:53:26 +00:00
wangchen
08e3025ec5 fix: pthread_cond_timedwait接口入参不规范
【背景】pthread_cond_timedwait函数的入参时间应该是绝对时间

【修改方案】
1,修改为相对时间
2,每次等待事件前清理

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

re #I4MVUO
Signed-off-by: wangchen <253227059@qq.com>
2021-12-20 01:39:45 +00:00
openharmony_ci
ae2c3c5823 !463 fix: tick中断处理时,无挂起任务时应更新当前运行任务的时间片, 并触发一次调度
Merge pull request !463 from zhushengle/cherry-pick-1639542040
2021-12-17 03:25:22 +00:00
zhushengle
d32fea7096 fixed ea12d40 from https://gitee.com/zhushengle/kernel_liteos_m/pulls/456
fix: tick中断处理时,无挂起任务时应更新当前运行任务的时间片, 并触发一次调度

Close #I4LRZG

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I4472fb50c775b832688aa7a555498901a80e2999
2021-12-15 04:20:42 +00:00
openharmony_ci
915e5b9517 !438 fix: 取消cpu进入低功耗前开中断操作,优化注册机制
Merge pull request !438 from zhushengle/cherry-pick-1638271705
2021-12-03 09:26:16 +00:00
zhushengle
6e665e6771 fixed bd39e9e from https://gitee.com/zhushengle/kernel_liteos_m/pulls/435
fix: 取消cpu进入低功耗前开中断操作

    开中断导致低功耗流程非原子,容易造成流程出错。
    提供低功耗默认处理函数,优化注册机制

Close #I4KDP8
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ied8bab691e7725e207b8b3cfb058f851eafe3052
2021-11-30 11:28:25 +00:00
openharmony_ci
a338ba8f69 !391 补充内存释放函数和去除多余参数。
Merge pull request !391 from pef/OpenHarmony-3.0-LTS
2021-11-25 08:33:08 +00:00
pef
81d02b4fea 补充内存释放函数和去除多余参数。
【背景】
1.有手动申请内存在return前未释放。
2.PRINTK存在多余参数

【修改方案】
1. 添加free(fullpath),释放内存。
2. 去掉多余参数。

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

Change-Id: Ifa74d5b443e98b03c10a34cca4ce6eaebfb2a120
Signed-off-by: pef <cyd1997@126.com>
2021-11-25 03:21:20 +00:00
openharmony_ci
bd607c8922 !388 fix: 修复cortex-m系列系统提供的timer在低频下时间不准的问题
Merge pull request !388 from zhushengle/cherry-pick-1636507317
2021-11-11 02:38:39 +00:00
zhushengle
f23481e041 fixed 3e569ba from https://gitee.com/zhushengle/kernel_liteos_m/pulls/385
fix: 修复cortex-m系列系统提供的timer在低频下时间不准的问题

触发场景:
    cpu主频比较高,timer频率较低时,当SysTick->VAL == 0时,
触发tick中断,在中断中系统将当前周期累加到基准时间里,在中
断结束更新tick响应时间时,会更新系统基准时间(为了让时间更
加准确)此时由于SysTick->VAL任然等于0,接口HalGetTickCycle
返回的仍然是当前周期,导致该周期被累加了两次。

解决方案:
    接口HalGetTickCycle在SysTick->VAL == 0时返回0.
因为SysTick->VAL == 0时,必然会触发tick中断,周期
的累加是由中断处理的,此时只需要返回0即可。

Close #I4HBGR
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Iba6e8799b0ae851fc94aa23867b2360a4245994d
2021-11-10 01:21:57 +00:00
openharmony_ci
792b131d55 !379 修改inet_addr等宏为函数,外层调用可不包含lwip头文件
Merge pull request !379 from 刘建东/cherry-pick-1635579054
2021-10-30 08:57:44 +00:00
YOUR_NAME
3969fbfac8 fixed b30e913 from https://gitee.com/life-liu/kernel_liteos_m/pulls/377
fix: switch inet_addr to a function

switch inet_addr to a function

close: #I4G4I4

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-10-30 07:30:54 +00:00
openharmony_ci
33e2b5e085 !376 m核优化lwip默认配置
Merge pull request !376 from 刘建东/cherry-pick-1635479803
2021-10-30 03:08:58 +00:00
YOUR_NAME
79099bb28c fixed b2e3849 from https://gitee.com/life-liu/kernel_liteos_m/pulls/375
fix: optimize default configuration

optimize default configuration

close: #I4FSC9

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-10-29 14:46:02 +08:00
openharmony_ci
11e8e895d3 !373 m核ioctl支持SIOCGIFBRDADDR选项
Merge pull request !373 from 刘建东/cherry-pick-1635300312
2021-10-29 02:19:05 +00:00
YOUR_NAME
a562b67f90 fixed 33ee492 from https://gitee.com/life-liu/kernel_liteos_m/pulls/360
feat: add option SIOCGIFBRDADDR for ioctl

add option SIOCGIFBRDADDR for ioctl

close: #I4EGNG

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-10-27 02:05:13 +00:00
openharmony_ci
fafd3b66d4 !365 fix:修复文件系统vfs层未正确判空g_fs的问题
Merge pull request !365 from Far/cherry-pick-1634701427
2021-10-20 04:18:58 +00:00
Far
5e3a29dd97 fix:修复文件系统vfs层未正确判空g_fs的问题
Close #I4ELVA

Signed-off-by: Far <yesiyuan2@huawei.com>
Change-Id: Id8cbbd6c65df0411f22af11412f01b57fa8c27d1
2021-10-20 11:50:35 +08:00
openharmony_ci
d1d19e088d !352 fix: 调用LOS_TaskDetach操作已退出的joinable的任务时,未正确回收该任务
Merge pull request !352 from zhushengle/cherry-pick-1634283734
2021-10-15 10:38:32 +00:00
zhushengle
2c85b0ec6d fixed 49c93b3 from https://gitee.com/zhushengle/kernel_liteos_m/pulls/351
fix: 调用LOS_TaskDetach操作已退出的joinable的任务时,未正确回收该任务

Close #I4DZL7
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Iac88818317c07807d0636712025f2c75b3b1f766
2021-10-15 07:42:15 +00:00
openharmony_ci
773613af16 !333 fix: OS_TASK_STACK_PROTECT_SIZE undeclared error
Merge pull request !333 from kenneth/mpu-3.0
2021-09-29 03:49:03 +00:00
openharmony_ci
0f0e4dfafd !334 fix: LOS_QueueInfoGet函数统计等待读写任务有误
Merge pull request !334 from kenneth/queue-3.0
2021-09-29 02:57:37 +00:00
kenneth
2a5a515f50 fix: fix OS_TASK_STACK_PROTECT_SIZE undeclared error
当开启LOSCFG_EXC_HARDWARE_STACK_PROTECTION宏时,增加定义OS_TASK_STACK_PROTECT_SIZE宏

close #I4C5RW

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-09-28 10:30:49 +08:00
kenneth
215a1f6dc0 fix: LOS_QueueInfoGet函数统计等待读写任务有误
LOS_QueueInfoGet使用32位无符号数组来记录阻塞队列的任务,每个数组元素的每个bit位对应一个任务编号。
比如第一个数组元素的32个bit位对应任务编号0-31,第二个数组元素的32个bit位对应任务编号32-63....计算任务对应的数组的bit位数时使用
掩码OS_WAIT_TASK_ARRAY_ELEMENT_MASK的值应该为31,不应该依赖任务最大数目。

close #I4C6P2

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-09-28 10:18:41 +08:00
openharmony_ci
093af869d5 !329 解决dailycheck告警
Merge pull request !329 from Caoruihong/cherry-pick-1632647820
2021-09-26 10:14:11 +00:00
openharmony_ci
ef8d27db07 !329 解决dailycheck告警
Merge pull request !329 from Caoruihong/cherry-pick-1632647820
2021-09-26 10:14:10 +00:00
openharmony_ci
b22234dd6a !326 fix: 添加文件版权头等信息
Merge pull request !326 from Harylee/cherry-pick-1632645903
2021-09-26 09:34:41 +00:00
Caoruihong
5169a23adf fixed 4aba2c0 from https://gitee.com/caoruihong/kernel_liteos_m/pulls/327
chore: fix dailycheck issues

master --> HEAD
remove useless @since

Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: Id3452cccdcc823c374f873cf4905015351580d15
2021-09-26 09:17:00 +00:00
Haryslee
bc42e348d0 fixed cf4e017 from https://gitee.com/harylee/kernel_liteos_m/pulls/325
fix: 添加文件版权头等信息

close #I4BXBH

Signed-off-by: Haryslee <lihao189@huawei.com>
Change-Id: Id798eec0473a9b8e18b1c8be31f3dd6babb879b0
2021-09-26 08:45:03 +00:00
openharmony_ci
93cc5747a2 !322 feat: 支持posix 和 cmsis join能力
Merge pull request !322 from zhushengle/cherry-pick-1632465410
2021-09-24 08:10:40 +00:00
zhushengle
96b4c460e2 fixed ecfdf7f from https://gitee.com/zhushengle/kernel_liteos_m/pulls/311
feat: 支持posix 和 cmsis join能力

支持API:
  LOS_TaskJoin
  LOS_TaskDeatch
  pthread_join
  pthread_deatch
  osThreadJoin
  osThreadDetach
Close #I44V26

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ib61e69c280eef2e4b3b79d9bba7bbd5a300c7fe4
2021-09-24 06:36:51 +00:00
openharmony_ci
23f634bde5 !319 fix: 修复pthread_create行为与posix不一致问题
Merge pull request !319 from zhushengle/cherry-pick-1632447173
2021-09-24 06:10:15 +00:00
openharmony_ci
aee17ecfa6 !320 cherry-pick PR259: 完善CMSIS-RTOS V2部分接口(osSemaphoreNew,osThreadJoin)
Merge pull request !320 from Caoruihong/cherry-pick-1632450240
2021-09-24 02:26:39 +00:00
Caoruihong
9b160141c4 fixed d478152 from https://gitee.com/caoruihong/kernel_liteos_m/pulls/259
feat(cmsis): support max_count for osSemaphoreNew

Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: Iacb6cb7771ae32ea1ca645c72fda241e8e85d422
2021-09-24 02:24:01 +00:00
zhushengle
3141961013 fixed 2b1e5a7 from https://gitee.com/zhushengle/kernel_liteos_m/pulls/308
fix: 修复pthread_create行为与posix不一致问题

1.提升posix接口和LOS接口的兼容性
2.支持优先级继承属性

Close #I49W9F
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I4d9df778a559f094dd3062e5e7030e3a03c884ec
2021-09-24 01:32:54 +00:00
openharmony_ci
51a6c21315 !315 fix: risc-v 低功耗下存在功能问题
Merge pull request !315 from zhushengle/cherry-pick-1631945741
2021-09-22 03:55:32 +00:00
zhushengle
c5a9ba4abf fixed 9f185b5 from https://gitee.com/zhushengle/kernel_liteos_m/pulls/314
fix: pm模块解冻线程时存在删除空链表且时间片频繁唤醒系统

1.如果冻结线程状态为delay,则此时pendlist为NULL,解冻时不需要delete
2.低功耗时关闭时间片,减少时间片频繁唤醒系统
3.risc-v 中64位相加存在溢出
Close #I4AKUS

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Icb9e8f7df8488635f9660d3932b06fa6f57e6133
2021-09-18 06:15:45 +00:00
openharmony_ci
7fa979c67c !313 挑单 shell模块task命令踩内存问题修改
Merge pull request !313 from wangchen/shell_lts
2021-09-17 07:46:26 +00:00
wangchen
b5e84d5516 fix: shell模块task命令踩内存问题修改
【背景】定期M核代码消除。

【修改方案】
1,对task命令中获取内存信息时的入参进行调整,避免引起内存问题

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

re #II4AIAQ
Signed-off-by: wangchen <253227059@qq.com>
2021-09-17 14:35:27 +08:00
openharmony_ci
c277e8d543 !309 feat: 低功耗支持冻结线程等需求
Merge pull request !309 from zhushengle/cherry-pick-1631622669
2021-09-15 00:58:09 +00:00
zhushengle
230a2f348f fixed 9b5739a from https://gitee.com/zhushengle/kernel_liteos_m/pulls/298
feat: 低功耗支持冻结线程等需求

1.支持低功耗时冻结线程
2.支持延时锁
3.低功耗与idle分离
4.支持对接电源管组件的低功耗接口
LOS_PmReadLock --- 常阻塞,低功耗线程阻塞于该接口,当系统无任何模块持锁时会唤醒低功耗线程, 触发低功耗流程
LOS_PmSuspend --- 进入低功耗流程
Close #I49FJF

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I009255cfa1852b109dd8bfaf9c779e976660d621
2021-09-14 12:31:10 +00:00
openharmony_ci
92e3844061 !303 fix: 修复pm编译告警导致内核编译失败
Merge pull request !303 from zhushengle/cherry-pick-1631346536
2021-09-11 08:52:28 +00:00
zhushengle
088a6d5bbd fixed 18b0524 from https://gitee.com/zhushengle/kernel_liteos_m/pulls/301
fix: 修复pm编译告警导致内核编译失败

Close #I49MIN
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I6b448790b170bf5980d16698ecfff27bda6c3600
2021-09-11 07:48:56 +00:00
openharmony_ci
d4d6489fb9 !297 fix: 优化低功耗流程
Merge pull request !297 from zhushengle/cherry-pick-1631173853
2021-09-09 09:00:36 +00:00
zhushengle
c1b2b15a87 fixed c6600d9 from https://gitee.com/zhushengle/kernel_liteos_m/pulls/281
fix: 优化低功耗流程

1.normal和其它模式分离,流程分层化,使得结构较为清晰
2.tick timer处理实现优化为注册对应机制则默认支持,不注册则不执行,简化使用逻辑
3.添加 pm测试用例
Close #I46VXK

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I7810ce0ca12dce96972399adf88e8319bb487905
2021-09-09 07:50:56 +00:00
openharmony_ci
1d9a5820f2 !291 修复HalTickStart错误的函数参数定义
Merge pull request !291 from 野生毛霉君/master
2021-09-07 06:11:28 +00:00
mucor
4443b74ea6 fix: fix bad params def in HalTickStart
close: #I48YWT

Signed-off-by: mucor <mucorwang@gmail.com>
2021-09-07 11:40:17 +08:00
openharmony_ci
6e1bdfe1de !275 fix: 内核模块编译增加-Werror编译选项,且清除内核编译告警
Merge pull request !275 from zhushengle/Werror
2021-09-06 11:16:42 +00:00
zhushengle
3798091d87 fix: 内核模块编译增加-Werror编译选项,且清除内核编译告警
Close #I46E6S

Change-Id: If1362c02a0a344da881a9bf90e41f0a43ba33609
Signed-off-by: zhushengle <zhushengle@huawei.com>
2021-09-06 16:16:43 +08:00
openharmony_ci
459cabf7de !286 按任务统计已经alloc的内存大小
Merge pull request !286 from lnlan/taskinfo
2021-09-01 01:48:21 +00:00
lnlan
475db62db1 feat: los_memory.c代码重复率处理
【背景】
los_memory.c中有4处遍历内存节点的操作,重复率较高
【修改方案】
1.提取一个遍历内存节点的函数,入参可传入处理函数来应对不同处理场景
【影响】
对现有的产品编译不会有影响。

re #I44WNU

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

Change-Id: Iafd25be39e76ee29e4fb27e5ef65f1888cc23f02
2021-08-31 02:30:30 +00:00
openharmony_ci
d46c69ee78 !266 新增内存分析工具
Merge pull request !266 from Denny/memtools
2021-08-30 07:14:07 +00:00
openharmony_ci
047203b7fb !287 修复software timer线程 readsize在第一次循环后可能未被正确赋值的问题
Merge pull request !287 from xfan1024/master
2021-08-28 09:06:20 +00:00
xiaofan
61cbf83f5d fix:修复software timer线程
readsize在第一次循环后可能未被正确赋值的问题

Signed-off-by: xiaofan <xiaofan@iscas.ac.cn>
2021-08-28 16:23:37 +08:00
lnlan
53117f9f47 feat: 按任务统计已经alloc的内存大小
【背景】
m核需补充shell命令,按任务统计已经alloc的内存大小
【修改方案】
1.新增在task命令中,在打印task
info前遍历所有内存节点,统计各任务所占用的内存节
点大小,在打印时将其打出。
2.内存节点中,taskid所占位数随系统最大任务数调整
【影响】
对现有的产品编译不会有影响。

re #I44WNU

Signed-off-by: lanleinan <lanleinan@163.com>
Change-Id: I080b5dd056966784c0752408f9e320ca0e97c7f7
2021-08-28 06:14:34 +00:00
openharmony_ci
75f975c424 !279 feat: 完善m核qemu串口驱动,支持shell输入
Merge pull request !279 from lnlan/shell_fix
2021-08-26 02:03:22 +00:00
lnlan
c4dc5ab0f8 feat: 完善m核qemu串口驱动,支持shell输入
【背景】
m核qemu需完善串口驱动,支持shell输入
【修改方案】
1.完善串口驱动
2.添加shell任务,获取串口输入并下发处理
【影响】
对现有的产品编译不会有影响。

re #I46N7F

Signed-off-by: lanleinan <lanleinan@163.com>
Change-Id: Ib58d4e633081743e64412cb65aa209d3356d6c1c
2021-08-26 01:15:17 +00:00
openharmony_ci
c8015dcb49 !282 m核lwip增加dhcp_is_bound接口
Merge pull request !282 from 刘建东/master
2021-08-24 10:30:36 +00:00
openharmony_ci
7719bb28e5 !283 M核编译配置修改
Merge pull request !283 from wangchen/gn_codex
2021-08-24 07:05:59 +00:00
YOUR_NAME
84a180d585 feat: add interface of dhcp_is_bound
add interface of dhcp_is_bound

close: #I46W08

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-08-24 11:34:03 +08:00
wangchen
deff7c921f fix: M核编译配置修改
【背景】完善M核编译配置选项。

【修改方案】
1,在build.gn中添加config.gni的包含
2,修改部分build.gn中的格式规范问题

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

re #I46XEA
Signed-off-by: wangchen <253227059@qq.com>
2021-08-24 10:57:48 +08:00
openharmony_ci
e4e3caccf2 !272 m核lwip和hilog解耦,简化配置
Merge pull request !272 from 刘建东/master
2021-08-23 02:48:58 +00:00
openharmony_ci
19aa1bb5bc !278 M核告警消除
Merge pull request !278 from wangchen/m_codex
2021-08-21 09:34:31 +00:00
openharmony_ci
9996ef80d6 !269 M33平台GCC环境下TZ增加默认选项适配
Merge pull request !269 from wangchen/new_tz
2021-08-21 09:31:36 +00:00
wangchen
f63c45930c 【背景】M33平台GCC环境下TZ默认开启TZ。
【修改方案】
1,在M33平台下增加默认选项及开关
2,删除build.gn编译tz的部分,该部分由使用者编译在安全态
3,修改tz初始化的一个问题

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

re #I45UYU
Signed-off-by: wangchen <253227059@qq.com>
2021-08-20 20:01:01 +08:00
wangchen
5a9d53b644 fix: M核告警消除
【背景】定期M核代码消除。

【修改方案】
1,根据工具扫描结果,对代码告警进行更改

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

re #I46LHG
Signed-off-by: wangchen <253227059@qq.com>
2021-08-20 18:44:33 +08:00
YOUR_NAME
be03374c3c refactor: decouple lwip and hilog for liteos_m
decouple lwip and hilog for liteos_m

close: #I46DAH

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-08-20 16:17:32 +08:00
openharmony_ci
4e11ded476 !267 fix: 删除延时节点后,存在时间无法有效刷新的场景
Merge pull request !267 from zhushengle/sched
2021-08-19 00:39:21 +00:00
openharmony_ci
8023547244 !270 解决中断操作等接口头文件位置变更,引入的编译问题
Merge pull request !270 from JerryH/hwi
2021-08-18 07:31:59 +00:00
JerryH
013a953926 fix: 修复中断操作接口头文件位置变更,导致的编译错误
close #I4665Z

Signed-off-by: JerryH <huangjieliang@huawei.com>
Change-Id: I5596179dea198dfe571420a7640abb00587abee1
2021-08-18 14:47:59 +08:00
openharmony_ci
97c4a5813f !249 堆内存算法支持多段非连续性内存区域
Merge pull request !249 from kenneth/multiple_mem
2021-08-17 07:43:18 +00:00
openharmony_ci
ada151d89b !268 删除m核lwip未使用的头文件和宏
Merge pull request !268 from 刘建东/master
2021-08-17 07:26:21 +00:00
kenneth
0facb0c017 feat: support non-continuous memory regions
The multiple non-continuous memory regions are supported when the macro
LOSCFG_MEM_MUL_REGIONS is enabled. The array of the type LOS_MEM_REGION should be defined,
and each array element defines the start address and the length for each memory regions, \
begining from the lower address to the higher memory address.

close #I43XOP

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-08-17 09:07:04 +08:00
YOUR_NAME
7ad3a22b4d fix: delete unused symbols for default config
delete unused symbols for default config

close: #I45HN3

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-08-16 17:54:52 +08:00
zhushengle
0a87c04d58 fix: 删除延时节点后,存在时间无法有效刷新的场景
1.从延时队列上删除延时节点时,如果该延时节点的响应时间比当前系统tick的响应时间小时,
将tick的响应时间修改为OS_SCHED_MAX_RESPONSE_TIME,以保证tick响应时间能够被刷新。
2.任务切换时,若g_schedResponseID为旧任务的taskID时(tick的响应时间为旧任务的时间片
结束时间),将tick的响应时间修改为OS_SCHED_MAX_RESPONSE_TIME。
Close #I45I9Y

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ia77b789a10112935b719e8f733ba33835894e060
2021-08-14 15:53:28 +08:00
denny
ee3403deaf feat: 新增ROM/RAM分析工具
Signed-off-by: denny <denny.shenwei@huawei.com>
2021-08-14 15:19:47 +08:00
openharmony_ci
02beb6b04d !265 fix: 以g_sysSchedStartTime是否为0判断时间轴是否生效存在极限场景导致调度时间不生效
Merge pull request !265 from zhushengle/sched_time
2021-08-14 06:23:30 +00:00
zhushengle
509cf59bef fix: 以g_sysSchedStartTime是否为0判断时间轴是否生效存在极限场景导致调度时间不生效
初始化调度时间不以g_sysSchedStartTime是否为0为界限,而以g_sysSchedStartTime是否为64位最大值,
为界限, 避免特殊以下场景:调度开启时系统时间为0,导致初始化的g_sysSchedStartTime还是0,导致
调度启动后获取的调度时间轴始终为0.

Close #I45HP5

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ie0ef4e7d149f09ac466c649c0f2d6538f5322439
2021-08-14 11:30:46 +08:00
openharmony_ci
2868891bc8 !264 feat: L0 arm qemu剥离工具链头文件
Merge pull request !264 from give-me-five/master
2021-08-12 09:07:09 +00:00
silen
67d74559d1 feat: L0 armquem 剥离工具链
Change-Id: I19c13fd24141271087948fad9434558b823df62b
Signed-off-by: silen <wuyunjie@huawei.com>
2021-08-12 16:23:31 +08:00
openharmony_ci
251a597bb4 !263 fix: 修复文档链接失效问题
Merge pull request !263 from Harylee/qemu
2021-08-12 07:51:49 +00:00
Haryslee
5d53c84812 fix: 修复文档链接失效问题
close #I4529I

Signed-off-by: Haryslee <lihao189@huawei.com>
Change-Id: Ia3c885789f11bcbfeafaabf1c835bee93bcc54c0
2021-08-12 14:59:13 +08:00
openharmony_ci
af5bc32e38 !261 宏LOSCFG_SUPPORT_FATFS在fs.c中存在使用问题,导致无fatfs的情况下,编译出错
Merge pull request !261 from zhangfanfan2/master
2021-08-12 02:01:00 +00:00
zhangfanfan2
c1614ce2b4 fix: 宏LOSCFG_SUPPORT_FATFS在fs.c中存在使用问题,导致无fatfs的情况下,编译出错
代码中使用#ifdef LOSCFG_SUPPORT_FATFS控制业务逻辑,但LOSCFG_SUPPORT_FATFS的
默认定义为:#define LOSCFG_SUPPORT_FATFS 0,这样#ifdef LOSCFG_SUPPORT_FATFS控制
的逻辑一定会被编译。修改方式:使用的地方统一为#if的形式

close: #I44XNR

Signed-off-by: zff <zhangfanfan2@huawei.com>
2021-08-11 09:32:09 +00:00
openharmony_ci
93f029b430 !250 某些编译器下编译告警消除
Merge pull request !250 from 野生毛霉君/master
2021-08-11 09:23:07 +00:00
openharmony_ci
fa0b8b0dcb !227 feat: 支持native动态加载组件
Merge pull request !227 from Harylee/mem
2021-08-11 03:14:24 +00:00
Haryslee
d75383400e feat: 支持native动态加载组件
1.【需求描述】
动态库开发部分:
gcc的sample code。
提供生成暴露接口生成机制,并允许产品新增需要暴露的接口。
提供可以判断库允许资源大小的能力,并提供相关工具辅助开发者确定开发的库要求的资源是否可以满足。

动态库运行部分:
提供elf load的api,可以加载指定路径下的库,并完成符号重映射等运行准备。
提供elf 暴露符号调用的api,用于调用库的api。
elf加载&链接异常时,有明确错误记录,返回明确错误类型。
提供elf 卸载的api。

2.【方案描述】
(1) 通过灌段的形式记录需要导出符号的地址信息,用于暴露内核对外的接口,在加载链接器中通过查询
对应的符号信息获取符号地址。
(2) 加载链接时,解析共享库并将共享库中可加载段通过文件系统读入内存中,并对共享库中未定义的、
需要重定位的符号进行重定位。需要调用符号时,根据符号名通过哈希表即可查询共享库提供的对应符号
的地址。

BREAKING CHANGE:
新增4个对外接口,声明在los_dynlink.h文件中,分别为:
(1) LOS_DynlinkInit: 动态加载模块初始化。
(2) LOS_SoLoad: 加载指定路径的共享库。
(3) LOS_FindSym: 根据共享库句柄查找指定符号。
(4) LOS_SoUnload: 卸载共享库。

close #I418HJ

Signed-off-by: Haryslee <lihao189@huawei.com>
Change-Id: I7669b7ef20096294f9d1094c85ac6602fefad354
2021-08-10 20:26:40 +08:00
openharmony_ci
669f619040 !258 添加MPU功能的开关宏
Merge pull request !258 from JerryH/mpu
2021-08-10 12:01:26 +00:00
JerryH
9709d29b87 fix: 增加MPU功能的开关宏,默认关闭
close #I3WE0S

Signed-off-by: JerryH <huangjieliang@huawei.com>
Change-Id: Id193fd555877ac0c6b5b43e5dd5ede32531b86c4
2021-08-10 19:27:14 +08:00
openharmony_ci
11bca47b6e !247 fix: tick 动态化计算优化,减小中断执行时间对系统总体时间的影响,保证软件定时器的响应精度。
Merge pull request !247 from zhushengle/tick_sched
2021-08-10 06:16:34 +00:00
zhushengle
2118c84616 fix: tick 动态化计算优化,减小中断执行时间对系统总体时间的影响,保证软件定时器的响应精度。
方案描述:
    1.周期软件定时器超时添加一个startTime字段,用于记录当前软件定时器的开始计时的时间,
    在定时器响应时,开始时间修改为上一次响应的结束时间(消除了中断执行时间对软件定时器
    的影响)。
    2. 在执行tick中断的过程当中,持有tick动态计算锁,保证在该过程中不会触发tick周期
    的计算,在tick中断结束时统一计算设置。 --- 提升tick中断的执行效率
    3. 在设置tick周期时,减掉tick中断执行的时间,减小周期动态化带来的时间误差
    4.新增LOSCFG_BASE_CORE_TICK_PER_SECOND_MINI配置宏,用于配置tick中断的最小响应精度
Close #I3YGP1

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ia53e4accce497bce870557c2c3387ce51fa3fed3
2021-08-09 21:16:22 +08:00
openharmony_ci
7fe9cc9aa0 !253 fix: L0 net 编译修复
Merge pull request !253 from give-me-five/master
2021-08-09 03:46:44 +00:00
silen
299813cdb4 fix: net compile fix
Change-Id: Ieb264f28e831f867d833a66fa25fec57e740a162
Signed-off-by: silen <wuyunjie@huawei.com>
2021-08-09 10:01:23 +08:00
openharmony_ci
870cf67c51 !252 新增OAT配置文件,用作oat扫描
Merge pull request !252 from SimonLi/master
2021-08-05 16:42:50 +00:00
SimonLi
f64457162c chore(oat): 新增OAT配置文件,用作oat扫描
Signed-off-by: SimonLi <likailong@huawei.com>
2021-08-06 00:29:03 +08:00
openharmony_ci
c8064436dd !251 修复licese
Merge pull request !251 from lnlan/fix_stl
2021-08-05 15:16:52 +00:00
lnlan
218d16f85f style:修改 liteos_a unittest 测试文件的 licence 注释
【背景】解除告警
【修改方案】
 格式化修改告警文件的文件头注释格式

re #I44497

Signed-off-by: lanleinan <lanleinan@163.com>
Change-Id: Id2d61deb9d9a14d5e29b915c3a64c75e11e12eda
2021-08-05 14:32:21 +00:00
mucor
8dea15c4fc fix: compile warning fix
close: #I4330B
Signed-off-by: mucor <mucorwang@gmail.com>
2021-08-05 21:02:42 +08:00
openharmony_ci
56dfd80ea5 !242 cmsis添加ThreadFlags接口支持
Merge pull request !242 from 野生毛霉君/master
2021-08-05 12:31:09 +00:00
mucor
cea551e99e feat: add cmsis ThreadFlags support
close: I43AYB

Signed-off-by: mucor <mucorwang@gmail.com>
2021-08-05 17:01:20 +08:00
openharmony_ci
b195b40bf2 !245 解决arm9编译冲突的问题
Merge pull request !245 from JerryH/arm9
2021-08-03 11:57:47 +00:00
openharmony_ci
1a56599021 !244 backatrace代码段判断函数解耦
Merge pull request !244 from JerryH/backtrace-bugfix
2021-08-03 11:37:55 +00:00
JerryH
c1a6245368 fix: 解决arm9编译冲突问题
close #I420PQ

Signed-off-by: JerryH <huangjieliang@huawei.com>
Change-Id: I788de96b176ae73541f1dc0577262b57179151a7
2021-08-03 10:27:20 +08:00
JerryH
8692ed33a3 fix: backtrace代码段判断函数定义成弱函数,如果有多个代码段,那么可根据实际情况重定义
close #I420SD

Signed-off-by: JerryH <huangjieliang@huawei.com>
Change-Id: Id2e89e11df8aeb906cdd36b2c40c51c2e140a569
2021-08-02 15:43:01 +08:00
openharmony_ci
ff7da435cf !243 fix: qemu中,timer模块缺少头文件
Merge pull request !243 from give-me-five/master
2021-08-02 03:43:09 +00:00
silen
12fed74722 fix: timer qemu 头文件缺失
Change-Id: I763ee6f0d013d84f36da9a7cb6d369f3d02e6c45
Signed-off-by: silen <wuyunjie@huawei.com>
2021-08-02 10:37:47 +08:00
openharmony_ci
4fd6a663ac !235 fix: 修复QUEUE_INFO_S中waitReadTask无法保存大于32的任务编号
Merge pull request !235 from kenneth/master
2021-08-02 02:07:12 +00:00
openharmony_ci
23d56f4b2a !241 M核代码告警清零
Merge pull request !241 from wangchen/m_codex
2021-07-31 03:40:50 +00:00
openharmony_ci
8f5cefe41a !225 fix: 在内核初始化前期启动tick timer
Merge pull request !225 from zhushengle/tick
2021-07-31 02:59:35 +00:00
openharmony_ci
1d33f5e4b0 !234 feat: L0 支持Trace
Merge pull request !234 from LiteOS/master
2021-07-31 02:58:59 +00:00
wangchen
cb5f862eaf fix: M核代码告警清零
【背景】定期M核代码告警清零。

【修改方案】
根据工具扫描结果,对代码告警进行更改。

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

re #I4386N
Signed-off-by: wangchen <253227059@qq.com>
2021-07-30 18:34:08 +08:00
openharmony_ci
3027311003 !239 fix: L0 支持smoke测试用例
Merge pull request !239 from zhushengle/smoke_test
2021-07-30 06:06:21 +00:00
openharmony_ci
3b37750f37 !240 Mutex锁释放后,无任务持有的情况下,owner未清空
Merge pull request !240 from zhangfanfan2/master
2021-07-30 03:21:26 +00:00
YOUR_NAME
c136cfdf97 fix: Mutex锁释放后,无任务持有的情况下,owner未清空
close: #I40OC8

Signed-off-by: zff <zhangfanfan2@huawei.com>
Change-Id: Ia06c4dc7f6d0a24a9ea05b37599ffac4f359a29f
2021-07-30 09:44:41 +08:00
LiteOS2021
56c93a641b feat: L0 支持Trace
1.【需求描述】
 L0 支持Trace,提供两种工作模式:在线模式、离线缓存模式, 用于按时间线追踪系统事件,如任务切换、中断、ipc等。
2.【方案描述】
 (1).在内核模块预置静态代码桩
  (2).触发桩后,收集系统上下文信息
  (3).离线模式则写入内存,用户可通过dump导出;
  (4).在线模式通过pipeline对接IDE进行可视化解析和展示;

BREAKING CHANGE:
1.新增一系列trace的对外API,位于los_trace.h中.
LOS_TRACE_EASY简易插桩
LOS_TRACE标准插桩
LOS_TraceInit配置Trace缓冲区的地址和大小
LOS_TraceStart开启事件记录
LOS_TraceStop停止事件记录
LOS_TraceRecordDump输出Trace缓冲区数据
LOS_TraceRecordGet获取Trace缓冲区的首地址
LOS_TraceReset清除Trace缓冲区中的事件
LOS_TraceEventMaskSet设置事件掩码,仅记录某些模块的事件
LOS_TraceHwiFilterHookReg注册过滤特定中断号事件的钩子函数

Close #I41Y9Y

Signed-off-by: LiteOS2021 <dinglu@huawei.com>
2021-07-30 09:29:37 +08:00
openharmony_ci
285d90979b !238 M33 平台 trust zone 适配修改
Merge pull request !238 from wangchen/tz_fix
2021-07-29 12:40:50 +00:00
zhushengle
3ad5942301 fix: 支持smoke 测试用例
默认只运行smoke测试用例,如需要运行全量测试用例,
请在target_config.h中添加配置项: LOS_KERNEL_TEST_FULL
或在config.json中配置enable_ohos_kernel_liteos_m_test_full
Close #I424RX

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I1f72a7666bf30631090e3e00faf6c432105dec17
2021-07-29 20:31:22 +08:00
openharmony_ci
7bd5a806e9 !232 feat: open shell
Merge pull request !232 from give-me-five/master
2021-07-29 07:06:08 +00:00
silen
911a767992 fix: open shell & fix qemu compile
Change-Id: Ia7488c02db7a41e0f681d008882b7c2721e6b207
Signed-off-by: silen <wuyunjie@huawei.com>
2021-07-29 11:19:03 +08:00
wangchen
15a2c17f79 fix: trustzone 中断适配
【背景】当前无法使用 trustzone。

【修改方案】
由于tz需要使用svc中断,因此删除之前使用的HalExcSvcCall的地方,改为HalSVCHandler

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

re #I42TFV
Signed-off-by: wangchen <253227059@qq.com>
2021-07-28 17:40:03 +08:00
kenneth
704cca97b1 fix: 修复QUEUE_INFO_S中waitReadTask无法保存大于32的任务编号
根据任务最大数创建waitReadTask数组来保存任务编号信息

close #I41N78

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-07-28 11:19:39 +08:00
openharmony_ci
6b732ca351 !237 fix: risc-v 锁中断在调度后失效
Merge pull request !237 from zhushengle/risc-v
2021-07-28 02:40:28 +00:00
openharmony_ci
71c76e8b08 !236 补充两个获取最高\最低优先级的接口
Merge pull request !236 from lnlan/add_prio
2021-07-28 02:11:05 +00:00
zhushengle
70f3aa1c11 fix: risc-v 锁中断在调度后失效
risc-v架构中,由于执行完mret指令之后,未将mstatus.mpie位清除,
导致锁中断后调度保存上下文信息后, 恢复上下文时误将中断打开。

Close #I42OLJ
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ib97b8bd0fc56bd4b2a7e5c474cb240db4e9c2419
2021-07-28 08:57:45 +08:00
lnlan
c24c38b084 feat(kernel): 补充获取最高、最低优先级接口
【背景】
补充获取最高、最低优先级接口
【修改方案】
pthread补充这两个接口
int sched_get_priority_min(int policy)
int sched_get_priority_max(int policy)
【影响】
对现有的产品编译不会有影响。

re #I42HM7

Signed-off-by: lnlanc <lanleinan@163.com>
Change-Id: Id2ffc07e606ad497e8036f45dab1fa6a5ba981b3
2021-07-27 11:21:05 +00:00
openharmony_ci
403d6dc428 !231 riscv_nuclei 编译失败
Merge pull request !231 from zhushengle/riscv_nuclei
2021-07-21 09:27:34 +00:00
zhushengle
d3fb23cca0 fix: riscv_nuclei 编译失败
riscv_nuclei编译失败原因:
1.采用Makefile编译,未包含power模块
2.安全函数库重复包含,导致链接时报重定义错误

Close #I41PQJ
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Id3d20cdb6050fa01aff432be8a9e21dc3c590e29
2021-07-21 14:56:33 +08:00
zhushengle
b3841ed1dd fix: 在内核初始化前期启动tick timer
解决系统未初始化完成前无timer可用的问题。

Close #I410F0
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I3799b9b0ff03cb1dfe80a97816a484df28ae49fd
2021-07-21 10:02:42 +08:00
openharmony_ci
10f683da91 !230 fix: ping cmd compile fail
Merge pull request !230 from give-me-five/master
2021-07-21 01:39:06 +00:00
silen
ae05de3ffd fix: ping cmd compile fail
Change-Id: I692de82275b8da03ac51b493b2f74148c96574d0
Signed-off-by: silen <wuyunjie@huawei.com>
2021-07-21 08:50:28 +08:00
openharmony_ci
d5e46ad863 !229 los_swtmr.h不满足自包含要求对los_config.h存在依赖,但未包含los_config.h
Merge pull request !229 from zhangfanfan2/master
2021-07-20 08:09:27 +00:00
YOUR_NAME
ad8e96a00f fix: los_swtmr.h不满足自包含要求对los_config.h存在依赖,但未包含los_config.h
close: #I40DHM

Signed-off-by: zff <zhangfanfan2@huawei.com>
Change-Id: I6903d2ece13ab0a4aadbc65f737c5f5a0f0a357a
2021-07-20 14:23:40 +08:00
openharmony_ci
b3481b1fa1 !228 fix: 修复L0的cpup功能失效,恢复功能。
Merge pull request !228 from give-me-five/master
2021-07-19 13:40:49 +00:00
silen
c842251bab fix: cpup funciton repair
Change-Id: I42951b0c0aa16267b6a86a0e95929ae4dccf28ad
Signed-off-by: silen <wuyunjie@huawei.com>
2021-07-19 14:44:03 +08:00
openharmony_ci
ba27241b02 !226 fix: L0 shell去除冗余头文件及优化代码
Merge pull request !226 from give-me-five/master
2021-07-19 02:15:52 +00:00
openharmony_ci
0526c14017 !224 feat: 新增LOSCFG_BASE_CORE_TSK_SWITCH_HOOK 宏定义配置
Merge pull request !224 from zhushengle/task
2021-07-19 01:37:43 +00:00
silen
fd2227e5c8 fix: l0 shell adapt new master
Change-Id: Ia4e0c848b76e8fda7c5a2f9e1b2246b2a09947a4
Signed-off-by: silen <wuyunjie@huawei.com>
2021-07-17 19:54:44 +08:00
zhushengle
39efd6fb30 feat: 新增LOSCFG_BASE_CORE_TSK_SWITCH_HOOK 宏定义配置
优化原任务切换对外函数钩子调用为通过宏定义实现

Close #I40Q9O

Change-Id: Ie5ab75d04e2a63cb992be968d25e876fd91ee591
Signed-off-by: zhushengle <zhushengle@huawei.com>
2021-07-15 09:44:03 +08:00
openharmony_ci
f2466c4165 !223 fix: task命令的打印偏位,以及copyright遗漏
Merge pull request !223 from give-me-five/master
2021-07-15 01:37:55 +00:00
silen
ad15bbd6a4 fix: 修复task命令格式错误,增加copyright
Change-Id: Ib573f981b2a83ab6f75741dd4a670c0ef3adf3f8
Signed-off-by: silen <wuyunjie@huawei.com>
2021-07-14 16:27:30 +08:00
openharmony_ci
bbce405227 !218 feat: L0 新增shell功能,增加命令ls cd等
Merge pull request !218 from give-me-five/master
2021-07-14 03:33:18 +00:00
openharmony_ci
c7b91d7a31 !222 优化arm9调度汇编代码,任务执行默认system模式,解决多种模式使用混乱问题
Merge pull request !222 from JerryH/arm9
2021-07-14 03:11:52 +00:00
silen
97283b7c5d feat: add L0 shell function
Change-Id: I7f10bd365455c32006c22a9f6e2368fe6c229a6a
Signed-off-by: silen <wuyunjie@huawei.com>
2021-07-13 22:04:30 +08:00
JerryH1011
97b5b0837b feat: Support arm9 fiq swi mode and using system mode.
close: #I3WLCN

Change-Id: Id14c4e903ca3c3271faf2ecdf6791163ac93b9a8
Signed-off-by: JerryH1011 <huangjieliang@huawei.com>
2021-07-13 20:23:21 +08:00
openharmony_ci
73a99977de !215 [待合并]fix: 清理残留无效的trace代码
Merge pull request !215 from Zhaotianyu/0708trace_delete
2021-07-13 09:01:57 +00:00
arvinzzz
3c48951857 fix: 清理残留无效的trace代码
1. 删除残留无用的trace代码
2. 调整los_error.h中失效的错误类型定义
3. 整理los_config.h中的特性控制宏

close: #I3ZMB4
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I9f03c486b54ae66308f0dac1aa003dd2a5ef5b84
2021-07-13 11:31:32 +08:00
openharmony_ci
453f91d09c !216 m核增加getifaddrs接口
Merge pull request !216 from 刘建东/master
2021-07-12 06:37:18 +00:00
YOUR_NAME
948501ac73 feat: provide getifaddrs for liteos_m
provide getifaddrs for liteos_m

close: #I400S5

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-07-12 10:49:33 +08:00
openharmony_ci
1ab9813256 !205 L0 LiteOS-M支持ARM9架构
Merge pull request !205 from JerryH/master
2021-07-12 00:44:56 +00:00
JerryH1011
6d7c9dfe59 feat: Support arm9
close: #I3WLCN

Change-Id: Id8e3ce9a9a7749cb27b52562e6d506803b38d9af
Signed-off-by: JerryH1011 <huangjieliang@huawei.com>
2021-07-12 06:39:24 +08:00
openharmony_ci
bf045e3eba !213 消除编译告警
Merge pull request !213 from x_xiny/master
2021-07-09 08:37:18 +00:00
x_xiny
d8c8c22666 fix:消除编译告警
【背景】
 消除编译告警

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

 re #I3ZC1R

 Change-Id: If5748c7ed420a9ff822c20ffb17dee2815e9bddc

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

Change-Id: Id78631543b0c41f11e1c3594200a3ad43543bbf5
2021-07-09 10:05:31 +08:00
openharmony_ci
cda85bf1b0 !214 删除README中多余的changelog信息
Merge pull request !214 from 野生毛霉君/master
2021-07-06 12:41:48 +00:00
mucor
37ef8ca7ae fix: remove changelog in README
close: #I3ZECY

Signed-off-by: mucor <mucorwang@gmail.com>
2021-07-06 20:37:15 +08:00
openharmony_ci
2e621bc323 !212 littlefs stat 接口支持获取文件类型
Merge pull request !212 from LeonChan/little-stat
2021-07-06 09:31:36 +00:00
Leon Chan
ceaed2dc86 feat: add file type support for LfsStat
close #I3ZCDR
Signed-off-by: Leon Chan <chenwei26@huawei.com>
2021-07-06 16:00:13 +08:00
openharmony_ci
aa6385ce16 !210 risc-v gn 编译框架添加汇编编译选项
Merge pull request !210 from zhushengle/CI
2021-07-05 06:54:51 +00:00
zhushengle
76dc343c88 feat: risc-v gn 编译框架添加汇编编译选项
Close #I3YS5Y

Change-Id: I380bc3442222ba18a0eebba4022ad6ca032e3de2
Signed-off-by: zhushengle <zhushengle@huawei.com>
2021-07-05 09:26:45 +08:00
openharmony_ci
77338f4c2b !209 littlefs错误码设置不正确
Merge pull request !209 from LeonChan/little-errno
2021-07-01 07:36:01 +00:00
openharmony_ci
e5179be5b5 !208 feat: L0 测试用例支持risc-v qemu 编译运行
Merge pull request !208 from zhushengle/test
2021-07-01 03:34:31 +00:00
Leon Chan
452f36403d fix: littlefs inappropriate return value and errno
return value and errno conforming to the POSIX.1.2008 standards

close: #I3YIVT
Signed-off-by: Leon Chan <chenwei26@huawei.com>
2021-06-30 18:38:01 +08:00
zhushengle
2dd6c080da feat: L0 测试用例支持risc-v qemu 编译运行
Close #I3YILG

Change-Id: I85e77596ae390ff153e1a423a6ec1b7cb9247bcc
Signed-off-by: zhushengle <zhushengle@huawei.com>
2021-06-30 16:17:43 +08:00
openharmony_ci
c56f5bc7bd !203 M33平台支持GCC环境的Trustzone
Merge pull request !203 from wangchen/tz
2021-06-30 00:38:05 +00:00
wangchen
d469da29c6 feat: M33平台支持GCC环境的Trustzone
【背景】M33平台当前仅支持IAR环境的tz,不满足云雀平台需求。

【修改方案】
1. 将 M33当前已有的IAR trustzone修改为gcc可用。

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

re #I3Y85I
Signed-off-by: wangchen <253227059@qq.com>
2021-06-29 15:16:57 +08:00
openharmony_ci
7fcf7ee3e6 !202 m核lwip提供gn编译脚本
Merge pull request !202 from 刘建东/master
2021-06-28 12:32:54 +00:00
YOUR_NAME
8515f0dc8f chore: provide lwip gn file for liteos_m
provide lwip gn file for liteos_m

close: #I3Y2WZ

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-06-28 17:13:44 +08:00
openharmony_ci
66f242f85b !201 littlefs编译告警消除
Merge pull request !201 from LeonChan/lc-compile-warnings
2021-06-28 09:11:23 +00:00
openharmony_ci
80f02595d7 !200 littlefs opendir失败时增加错误回滚
Merge pull request !200 from LeonChan/lc-opendir-bug-fix
2021-06-28 09:10:32 +00:00
Leon Chan
75f61870a0 fix: compile warnings
1, function prototypes: LfsSeek, LfsCloseDir
2, fix some other minor warnings and remove some while spaces

close: #I3Y57X
Signed-off-by: Leon Chan <chenwei26@huawei.com>
Change-Id: Id8b77c8a6b2e8d2b9bc5f02e22bfc6a15d70f648
2021-06-28 15:42:28 +08:00
Leon Chan
82fad6c36f fix: rollback resources when opendir failed
close: #I3Y577
Signed-off-by: Leon Chan <chenwei26@huawei.com>
2021-06-28 15:29:31 +08:00
openharmony_ci
59225cb6df !198 重构kal/posix的BUILD.gn编译脚本,添加对musl c库的依赖
Merge pull request !198 from Caoruihong/liteos_m_build_gn
2021-06-28 00:35:34 +00:00
Caoruihong
bfa25fcaa3 feat: add deps to musl and securec
add deps to musl, and securec.
fwrap.c's contents are moved to musl.

Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: Ib451736798efd9745c6fbbbe5f355eea13477031
2021-06-26 18:04:27 +08:00
openharmony_ci
586d9a18b3 !199 M核littlefs当文件open失败时,需要回收fd,否则会有fd泄露
Merge pull request !199 from li_zan/master
2021-06-26 08:22:24 +00:00
li_zan
b458e12ed5 fix: M核littlefs当文件open失败时,需要回收fd,否则会有fd泄露
close:#I3XU6R

Signed-off-by: li_zan <371442490@qq.com>
2021-06-26 09:33:57 +08:00
openharmony_ci
eca03e5ed6 !195 feat: L0新增posix接口sem_getvalue
Merge pull request !195 from x_xiny/master
2021-06-24 07:15:06 +00:00
openharmony_ci
2e92427d8f !194 修复littlefs的多分区挂载时,对pathname的处理逻辑异常
Merge pull request !194 from li_zan/master
2021-06-24 05:05:07 +00:00
openharmony_ci
ef4bdf6d10 !197 调度过程低概率触发OsSchedTaskEnQueue断言,导致系统异常
Merge pull request !197 from zhangfanfan2/master
2021-06-24 05:03:00 +00:00
x_xiny
8649b14591 feat: m核新增posix接口sem_getvalue
【背景】
 m核新增posix接口适配

【修改方案】
 接口新增sem_getvalue,并在内核适配相应接口

【影响】
 无

 re #I3WW8S

 Signed-off-by: x_xiny <1301913191@qq.com>
 Change-Id: I65a4baa242aaedc2fec9b6ed705dbb1ddb6e70c9

Change-Id: Id4c38a5dd4ac4e90f1bd032a39dcb97ce29de5f9
2021-06-24 10:43:44 +08:00
li_zan
b0119f6185 Merge branch 'master' of gitee.com:openharmony/kernel_liteos_m into master 2021-06-24 01:33:46 +00:00
li_zan
b55cfc1ba7 fix: 修复littlefs的多分区挂载时,对pathname的处理逻辑异常
close:#I3WWFA

Signed-off-by: li_zan <371442490@qq.com>
2021-06-24 09:31:15 +08:00
YOUR_NAME
e5e9289a08 fix: 调度过程低概率触发OsSchedTaskEnQueue断言,导致系统异常
当任务A调用LOS_EventRead阻塞开中断后,突然响应中断B,此时任务A已入阻塞链表,
任务状态为OS_TASK_STATUS_PEND | OS_TASK_STATUS_RUNNING;而B的回调函数中调用
LOS_EventWrite唤醒任务A,这个过程会调用OsSchedTaskWake,将任务A从阻塞链表中
取出,并去除OS_TASK_STATUS_PEND状态,且调用OsSchedTaskEnQueue将任务A添
加到调度队列并增加OS_TASK_STATUS_READY状态。OsSchedTaskWake全部流程完成后,
会开中断并调用LOS_Schedule,在LOS_Schedule流程中由于当前任务为A,且状态为
OS_TASK_STATUS_RUNNING | OS_TASK_STATUS_READY,会再次调用OsSchedTaskEnQueue,
从而被OsSchedTaskEnQueue断言拦住。修改方式:当任务状态含有OS_TASK_STATUS_RUNNING时
OsSchedTaskWake中不调用OsSchedTaskEnQueue。

close: #I3VX9Y

Signed-off-by: zff <zhangfanfan2@huawei.com>
Change-Id: I28f33d25504ade47469980fd6bb0b922bf4756da
2021-06-23 19:25:58 +08:00
openharmony_ci
1f4b7aa85d !196 新增函数regcomp,regfree和regexec支持
Merge pull request !196 from zhangfanfan2/master
2021-06-23 10:31:36 +00:00
YOUR_NAME
86d5544a3f fix: 新增函数regcomp,regfree和regexec支持
close: #I3U9LE

Signed-off-by: zff <zhangfanfan2@huawei.com>
Change-Id: Iff1180b89958b4d8c339a73f9a5f59cb47707c74
2021-06-23 15:27:50 +08:00
openharmony_ci
d0efdfc20d !169 feat: L0支持低功耗投票框架
Merge pull request !169 from zhushengle/PM
2021-06-22 11:55:22 +00:00
zhushengle
558ce14bec feat: L0 支持低功耗框架
1.【需求描述】
 L0 支持低功耗投票框架, 使内核与应用、驱动分离开,通过注册及投票机制控制系统的低功耗模式,
  减低系统功耗,提升设备电池寿命。
2.【方案描述】
 (1).提供注册机制,使驱动与内核分离
  (2).提供投票机制,判断系统运行模式
  (3).记录持锁设备,便于回溯
  进入:系统运行进入idle任务时判断当前的功耗模式,如果上层应用未对当前功耗模式(deep和shutdown)
 持锁,则系统准备进入当前模式,首先所有设备依次进入当前模式,如果有设备进入当前模式失败,则恢复
 已进入当前模式的所有设备,并且功耗模式变为normal模式;设备依次进入当前功耗模式后cpu再进入当前
 功耗模式。
  恢复:功耗模式为deep时,需要恢复逻辑,时系统恢复运行。当有中断出发时,系统会退出低功耗模式,
  恢复顺序为:首先cpu先恢复,然后设备依次恢复。

BREAKING CHANGE:
1.原调度中基于tick timer的低功耗扩展和当前的pm模块合并,删除原对外接口LOS_SchedSleepInit,
 变为pm模块统一提供的LOS_PmRegistered接口.
2.原来在arch los_timer.h下提供的低功耗模式为枚举LOS_SysSleepEnum,其中OS_SYS_NORMAL_SLEEP
  和OS_SYS_DEEP_SLEEP不符合对外定义,统一修改为LOS_SYS_NORMAL_SLEEP和LOS_SYS_DEEP_SLEEP,
  并移至los_pm.h中.
3.VOID HalEnterSleep(LOS_SysSleepEnum sleep) 变更为UINT32 HalEnterSleep(VOID).

Close #I3UDNV

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Id5382c42c8055ba7850895a3f575130a73e38a65
2021-06-22 13:15:06 +08:00
openharmony_ci
9fc34614d1 !184 feat: add LOS_ListHeadInsert function
Merge pull request !184 from kenneth/LOS_ListHeadInsert
2021-06-21 12:39:25 +08:00
openharmony_ci
8df07fe3cc !182 fix: add API LOS_HwiCreate、LOS_HwiDelete
Merge pull request !182 from kenneth/HWI
2021-06-21 12:38:07 +08:00
openharmony_ci
0f7d2fcf07 !193 fix: 延时队列为NULL时,返回的响应时间为64位最大值,导致无法更新tick timer的响应周期
Merge pull request !193 from zhushengle/sched
2021-06-18 10:09:31 +08:00
openharmony_ci
0247e421c7 !192 修复M核上musl库缺失strdup.c的问题
Merge pull request !192 from li_zan/master
2021-06-18 09:43:14 +08:00
kenneth
430b186be7 feat: add LOS_ListHeadInsert function
注释中@see部分提到了函数LOS_ListHeadInsert,但是该函数没有定义,增加该函数的定义。

close #I3TAQA

Signed-off-by: kenneth <459864689@qq.com>
2021-06-18 09:01:25 +08:00
kenneth
eb668eb9e0 fix: add API LOS_HwiCreate and LOS_HwDelete
新增对外接口LOS_HwiCreate、LOS_HwiDelete

close #I3R75F

Signed-off-by: kenneth <459864689@qq.com>
2021-06-18 08:53:22 +08:00
li_zan
139f83af39 fix: 修复M核上musl库缺失strdup,c的问题
close:#I3VZSI

Signed-off-by: li_zan <371442490@qq.com>
2021-06-17 20:28:47 +08:00
zhushengle
bcec32e389 fix: 延时队列为NULL时,返回的响应时间为64位最大值,导致无法更新tick timer的响应周期
问题描述:
  当g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME,且nextExpireTime =(UINT64-1时,
  表示系统的延时队列已为NULL, 此时tick timer 中应该设置为最大值,但由于判断
  g_schedResponseTime - nextExpireTime >= OS_CYCLE_PER_TICK,导致条件不成立,直接返回,
  无法将其设置为最大值,导致tick 中断一直频繁响应。
解决方案:
  将延时队列为NULL时的返回值以及idle线程的时间片修改为OS_SCHED_MAX_RESPONSE_TIME - OS_CYCLE_PER_TICK,
  保证延时队列为NULL,能够正常设置tick响应的最大值。

Close #I3W1LF

Change-Id: I0d09119240ae5a50ddcb0c96fb23cd3d6e70b892
Signed-off-by: zhushengle <zhushengle@huawei.com>
2021-06-17 20:23:13 +08:00
openharmony_ci
491920548c !191 修复littlefs编译fs.c缺少头文件件依赖配置
Merge pull request !191 from li_zan/master
2021-06-17 19:24:50 +08:00
li_zan
7259289bd9 fix: 修复littlefs编译fs.c缺少头文件件依赖配置+若干musl库的缺失问题+多分区规格宏配置问题
close:#I3VT11

Signed-off-by: li_zan <371442490@qq.com>
2021-06-17 17:03:41 +08:00
openharmony_ci
6e162a9318 !190 修正有关makefile文件中bounds_checking_function的路径配置
Merge pull request !190 from Caoruihong/master
2021-06-17 09:30:40 +08:00
openharmony_ci
94e620acd0 !189 fix: fix backtrace check issue
Merge pull request !189 from rtos-lover/bt_fix
2021-06-16 21:00:44 +08:00
Caoruihong
5c0a6fffea chore: bounds_checking_function is under //third_party
the copy of bounds_checking_function under components was removed,
we should use the copy of bounds_checking_function under //third_party

Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: Ib5c392f4d592a2fe6f26f6c1e1ea60f1faa836b9
2021-06-16 17:54:58 +08:00
rtos-lover
b6664e66f1 fix: fix backtrace check issue
fix issue that when memleak check is enabled, backtace is not enabled

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3VTKD

Signed-off-by: rtos-lover <zhushangyuan@hotmail.com>
2021-06-16 17:12:41 +08:00
openharmony_ci
468ce69f27 !180 update: rename LOS_BackTraceInit
Merge pull request !180 from kenneth/BackTraceInit
2021-06-16 13:45:04 +08:00
openharmony_ci
48067a0596 !178 littlefs三方源码采用GN编译修改上库+默认Mount路径可配置
Merge pull request !178 from li_zan/master
2021-06-16 10:58:13 +08:00
kenneth
a0a32188ff update: rename LOS_BackTraceInit
change function name LOS_BackTraceInit and involve it in los_init.c when macro is not set to 0

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3SYQQ

Signed-off-by: kenneth <459864689@qq.com>
2021-06-16 08:51:00 +08:00
li_zan
bdb614bc2b fix: littlefs三方源码采用GN编译修改上库
close:I3VJ6X

Signed-off-by: li_zan <371442490@qq.com>
2021-06-15 19:56:50 +08:00
openharmony_ci
3c35617816 !179 通过public_configs方式对外提供cmsis和posix的对外头文件路径
Merge pull request !179 from Caoruihong/master
2021-06-15 16:48:41 +08:00
Caoruihong
420e781f33 chore: adjust path of posix header files
path of posix header files are exposed via public_configs
of //kernel/liteos_m/kal/posix

Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: Id838549e1a952d6ddb8664792570f265edfbd91c
2021-06-15 12:11:12 +08:00
openharmony_ci
749bd8a481 !176 musl归一化后调整libc的构建
Merge pull request !176 from Caoruihong/porting2
2021-06-11 17:36:29 +08:00
openharmony_ci
9b656ac3c1 !172 fix: fix print format compilation warning
Merge pull request !172 from kenneth/printf_format_warning
2021-06-11 13:19:52 +08:00
Caoruihong
a5660c2217 chore: remove the files copied from musl
copied and auto-generated files are redundant and should not be tracked.

Change-Id: I22bb3a1873ba6e0be3008306624b50772cdc91b5
Signed-off-by: Caoruihong <crh.cao@huawei.com>
2021-06-11 11:26:58 +08:00
openharmony_ci
a3ab46ec31 !175 修复M核littlefs GN编译的若干错误
Merge pull request !175 from li_zan/master
2021-06-11 11:23:45 +08:00
li_zan
d77828e206 fix: 修复M核littlefs GN编译的若干错误
close:I3V7ZH

Signed-off-by: li_zan <371442490@qq.com>
2021-06-11 09:48:32 +08:00
kenneth
ef12c89c7a fix: fix print format compilation warning
fix print format compilation warning by changing 0x%x to 0x%p

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3OFSQ

Signed-off-by: kenneth <459864689@qq.com>
2021-06-10 14:52:47 +08:00
openharmony_ci
db89b353e9 !166 修复fatfs文件系统中部分指针访问前未判空、全局变量保护不完全问题。
Merge pull request !166 from JING/fatfs
2021-06-10 13:21:37 +08:00
openharmony_ci
9781662cea !135 添加backtrace for riscv在不打开frame-pointer的提前下
Merge pull request !135 from JerryH/backtrace
2021-06-09 11:46:03 +08:00
JerryH
97a5b6d8dc Merge branch 'master' of gitee.com:openharmony/kernel_liteos_m into backtrace 2021-06-09 10:41:58 +08:00
openharmony_ci
0ba33abcd1 !174 m核上littlefs新增错误码功能
Merge pull request !174 from li_zan/master
2021-06-09 09:48:44 +08:00
li_zan
a062378631 fix: m核上littlefs新增错误码功能
close:#I3UVMQ

Signed-off-by: li_zan <371442490@qq.com>
2021-06-08 19:13:44 +08:00
openharmony_ci
bd307591b4 !173 fs接口用例补充
Merge pull request !173 from wangchen/testsuit
2021-06-07 23:02:46 +08:00
wangchen
2a95af5bf1 feat: 补充fs相关函数用例
【背景】当前fs部分函数缺少配套用例。

【修改方案】
1. 在unittest目录下新增fopen等17个接口的用例。

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

re #I3UQ4F
Signed-off-by: wangchen <253227059@qq.com>
2021-06-07 21:59:22 +08:00
openharmony_ci
2f6ab80a06 !170 解决fclose等函数工具链重定义问题
Merge pull request !170 from wangchen/master
2021-06-07 21:02:56 +08:00
openharmony_ci
f3a3114ac7 !163 mbedtls适配l0
Merge pull request !163 from 野生毛霉君/master
2021-06-07 14:38:27 +08:00
openharmony_ci
7ab7ae7ae7 !137 fix: fix typos
Merge pull request !137 from rtos-lover/los_sched.c
2021-06-05 13:53:35 +08:00
wangchen
b244ad4ad0 feat: 解决fclose等函数工具链重定义问题
【背景】当前部分单板编译fclose等函数时与对应的gcc工具链重定义。

【修改方案】
1. fclose等函数新增weak定义,并恢复与musl源码一致。
2.外层添加wrap函数,用于配合gcc的--wrap选项。

【影响】
对现有的产品编译不会有影响,报重定义的工程需单独在自己的build.gn中添加
--wrap=xxx。

re #I3UG6O

Signed-off-by: wangchen <253227059@qq.com>
2021-06-05 11:30:16 +08:00
chenjing
bc7a914bce fix: protect from accssing NULL pointer, access g_handle after fslock
close #I3UCX3

Signed-off-by: chenjing <chenjing139@huawei.com>
Change-Id: Ie4d5c1923c2d49e283c77f46d01784bed065a507
2021-06-04 16:20:11 +08:00
mucor
761b86096c fix(mbedtls): mbedtls l0 support
close: #I3UBJA
Signed-off-by: mucor <mucorwang@gmail.com>
2021-06-04 16:07:06 +08:00
openharmony_ci
beea9963f7 !161 fix: fix NULL、UNUSED redefined issue
Merge pull request !161 from kenneth/NULL_redefined3
2021-06-04 14:51:52 +08:00
openharmony_ci
3d2a102d35 !160 fix: fatfs中宏FS_LOCK_TIMEMOUT_SEC拼写错误
Merge pull request !160 from zhushengle/fs
2021-06-04 14:47:51 +08:00
openharmony_ci
58c330f594 !159 fix: remove project files
Merge pull request !159 from kenneth/README.md
2021-06-04 14:46:21 +08:00
openharmony_ci
af9b9ee7fe !157 fix: comment error
Merge pull request !157 from kenneth/los_backtrace.h2
2021-06-04 14:44:56 +08:00
openharmony_ci
9d77efe6aa !156 fix: correct the counter of exception type
Merge pull request !156 from kenneth/los_arch_interrupt.h2
2021-06-04 14:44:41 +08:00
openharmony_ci
70713c705f !155 fix: fix typo in comment
Merge pull request !155 from kenneth/los_queue_want2
2021-06-04 14:44:09 +08:00
openharmony_ci
162673b546 !154 fix: change cpup retval range
Merge pull request !154 from kenneth/LOS_HistorySysCpuUsage2
2021-06-04 14:43:42 +08:00
kenneth
765bd55199 fix: fix NULL UNUSED redefined issue
change NULL、 UNUSED macro definition

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3E9S3

Signed-off-by: kenneth <459864689@qq.com>
2021-06-04 10:58:43 +08:00
zhushengle
42dc308369 fix: Fixed a spelling error in FS_LOCK_TIMEOUT_SEC.
Close #I3TL66

Change-Id: Id7facf210d7bc3c29c631e2f0b48a332e7f1348c
Signed-off-by: zhushengle <zhushengle@huawei.com>
2021-06-04 10:40:44 +08:00
kenneth
4ad01ced93 fix: remove project files
update README.md file to remove the project files

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3U5QQ

Signed-off-by: kenneth <459864689@qq.com>
2021-06-04 09:43:39 +08:00
kenneth
a37b73d759 fix: comment error
correct typo in comments

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3SLNU

Signed-off-by: kenneth <459864689@qq.com>
2021-06-03 20:49:18 +08:00
kenneth
bff65877a2 fix: correct the counter of exception type
correct the counter of exception type from 19 to 21

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3SR54

Signed-off-by: kenneth <459864689@qq.com>
2021-06-03 20:45:12 +08:00
kenneth
811d3fae8a fix: fix typo in comment
The word wantted is misspelled and should be changed to wanted. And expected-size is better than wanted size.

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3RW6C

Signed-off-by: kenneth <459864689@qq.com>
2021-06-03 20:39:33 +08:00
kenneth
d00a35ba92 fix: change cpup retval range
change cpup range from 100 to 1000

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3SXJ7

Signed-off-by: kenneth <459864689@qq.com>
2021-06-03 20:34:28 +08:00
openharmony_ci
a9857c8b2f !151 修复littlefs部分缺失功能:1、open接口的flag适配。2、mount功能增强
Merge pull request !151 from li_zan/master
2021-06-03 20:18:46 +08:00
li_zan
51335629d0 Fix: littlefs some bug
Signed-off-by: li_zan <371442490@qq.com>
2021-06-03 19:33:09 +08:00
openharmony_ci
d636a6f27c !152 删除MQ内冗余的重复宏定义
Merge pull request !152 from give-me-five/master
2021-06-03 18:27:50 +08:00
give-me-five
6d7291660a fix: 删除MQ内冗余的重复宏定义
【背景】
去除多余宏定义
【修改方案】
宏定义规格有重复定义问题,需要删除。
【影响】
无
re #I3U5BE:删除重复定义的mq宏
2021-06-03 17:42:15 +08:00
openharmony_ci
05937ee49c !144 调整hook类型和位置,提升调试的易用性
Merge pull request !144 from Zhaotianyu/0529hook_fix
2021-06-03 15:18:33 +08:00
openharmony_ci
804f5a809f !130 fix: fix macro typo
Merge pull request !130 from kenneth/STACK_PROTECTION
2021-06-03 15:14:10 +08:00
Zhaotianyu
b4cfdcfbf5 Merge branch 'master' of gitee.com:openharmony/kernel_liteos_m into 0529hook_fix 2021-06-03 11:08:31 +08:00
openharmony_ci
caba05985b !147 fix: fix readme link issue
Merge pull request !147 from kenneth/readme_update
2021-06-02 17:10:22 +08:00
openharmony_ci
5bd69a9ea6 !143 修复timer_settime接口功能缺陷
Merge pull request !143 from Zhaotianyu/0529timer_fix
2021-06-02 17:06:36 +08:00
openharmony_ci
fb2117c598 !146 修复不规范的copyright
Merge pull request !146 from Zhaotianyu/0524copyright
2021-06-02 16:50:56 +08:00
arvinzzz
a5f4e37e53 fix: 修复timer_settime只设置第一次到期时间时,到期时间不准的缺陷
close: #I3TCHA

Change-Id: Ie5c2ab74a8cbbd86dce913b53ae791f8f2da5133

Signed-off-by: arvinzzz <fcykztyu@163.com>
Change-Id: I571b0a3577026011aabcb0235985ea3e9be4441c
2021-06-02 16:37:53 +08:00
kenneth
9e332c69a5 fix: fix readme link issue
update links to docs

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3TX4Q

Signed-off-by: kenneth <459864689@qq.com>
2021-06-02 15:37:34 +08:00
openharmony_ci
d4409bfba4 !142 fix: update arch_spec.md
Merge pull request !142 from rtos_shang/arch_spec_md
2021-06-02 15:34:41 +08:00
arvinzzz
2d9bbd2769 fix: 修复不规范的copyright
close: #I3SPJ1
Change-Id: I6cb01024ef342a0190f5dc9f6cb3a1e815692832

Signed-off-by: arvinzzz <fcykztyu@163.com>
Change-Id: I45c63592b08d29587778209de6af17f932dc86d0
2021-06-02 11:07:59 +08:00
arvinzzz
369320de37 fix: 调整hook类型和位置,方便调试
close: #I3TGZS
Change-Id: Idba021ec7595d2f25a23102b6610e0f29cdd1209
Signed-off-by: arvinzzz <fcykztyu@163.com>

Change-Id: I9f1f745c6389de8bd8ca589bd1a3dc5311962527
2021-06-02 10:28:24 +08:00
arvinzzz
e4b5d4ebe9 fix: 修复timer_settime只设置第一次到期时间时,到期时间不准的缺陷
close: #I3TCHA

Change-Id: Ie5c2ab74a8cbbd86dce913b53ae791f8f2da5133
Signed-off-by: arvinzzz <fcykztyu@163.com>
2021-06-02 09:44:20 +08:00
YOUR_NAME
ca1792aa4b feat(liteos_m): support backtrace for riscv
Support backtrace for riscv when the compilation option(-fno-omit-frame-pointer) is not turned on.

fix #I3RVXY

Change-Id: Ie7d8a223167e5c540367bc96db646b821dae9fd0
2021-05-25 11:10:28 +08:00
rtos_shang
2a2ef7d708 change according to comments 2021-05-25 10:12:19 +08:00
rtos_shang
0752400a10 change according to review comments 2021-05-25 10:08:42 +08:00
rtos_shang
cf43988523 fix: update arch_spec.md
update arch_spec.md, add Chinese edition of arch_spec_zh.md and add link to readme files

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3QQ93 https://gitee.com/openharmony/kernel_liteos_m/issues/I3J7RS
2021-05-21 11:33:24 +08:00
openharmony_ci
6e1fb96998 !139 修复hook模块在c99编译标准下编译出错
Merge pull request !139 from Zhaotianyu/0520hook_fix
2021-05-20 17:07:39 +08:00
openharmony_ci
8856114e62 !134 M核littlefs支持多分区挂载
Merge pull request !134 from li_zan/master
2021-05-20 16:26:16 +08:00
arvinzzz
a078c3086f fix: The hook module fails to compile under the c99 compilation standard.
close: #I3S4ME

Change-Id: I335dde049e1646cb7fb32f8e156878994f254c8b
2021-05-20 15:42:20 +08:00
li_zan
3181b4395d Add Multi mount func 2021-05-20 15:36:54 +08:00
li_zan
45c72e7927 Add Multi mount func 2021-05-20 14:21:04 +08:00
openharmony_ci
2b6a7d91e9 !136 fix: fix LOS_TaskNameGet comment
Merge pull request !136 from rtos-lover/los_task.h
2021-05-20 11:30:23 +08:00
openharmony_ci
619fd42ded !101 将符号链接改回实体文件或目录
Merge pull request !101 from Caoruihong/remove_third_party
2021-05-20 09:32:26 +08:00
rtos-lover
191644e441 fix: fix typos
Correct words function、procedure

close  https://gitee.com/openharmony/kernel_liteos_m/issues/I3RR6A
2021-05-19 14:49:13 +08:00
rtos-lover
c70b28bf78 fix: fix LOS_TaskNameGet comment
fix comment for the function LOS_TaskNameGet

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3QJVY
2021-05-19 14:33:51 +08:00
openharmony_ci
930e92ebe2 !131 fix: fix destroy typo
Merge pull request !131 from kenneth/los_event.h
2021-05-19 13:37:20 +08:00
openharmony_ci
be5344ae75 !132 fix: correct ECB in comment
Merge pull request !132 from kenneth/los_sem.c
2021-05-19 13:35:43 +08:00
openharmony_ci
456bef2141 !133 fix: fix length typo
Merge pull request !133 from kenneth/los_queue.h
2021-05-19 13:35:03 +08:00
kenneth
e772ccb3cc fix: change queuePosion to queuePosition 2021-05-19 08:35:48 +08:00
openharmony_ci
0e14ddffd3 !129 fix: fix __cplusplus typo
Merge pull request !129 from kenneth/task_sample.h
2021-05-18 14:02:05 +08:00
openharmony_ci
c66e3cb52e !128 fix: fix comment typo issue
Merge pull request !128 from kenneth/resource.h
2021-05-18 14:01:15 +08:00
kenneth
98d65801de fix: fix length typo
correct length、there、necessary spell

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3QQA8
2021-05-18 11:23:43 +08:00
kenneth
e2aeb1ff1d fix: correct ECB in comment
change ECBs to semaphore CBs, and remove extra blank

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3RPRQ
2021-05-18 11:09:48 +08:00
kenneth
4ba6259e94 fix: fix destroy typo
change LOS_ERRNO_EVENT_SHOULD_NOT_DESTORY to LOS_ERRNO_EVENT_SHOULD_NOT_DESTROYED

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3RQXS
2021-05-18 10:53:39 +08:00
kenneth
16003604a9 fix: fix macro typo
change LOSCFG_EXC_HRADWARE_STACK_PROTECTION to LOSCFG_EXC_HARDWARE_STACK_PROTECTION

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3NUX6
2021-05-18 10:02:03 +08:00
kenneth
c3eb3e59e6 fix: fix __cplusplus typo
remove extra c in macro definition  __cpluscplus

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3QQAF
2021-05-18 09:51:34 +08:00
kenneth
0c2a675e2d fix: fix comment typo issue
The extentions is changed to extensions

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3R970
2021-05-18 09:45:49 +08:00
openharmony_ci
bb84279cc2 !112 fix: fix function name
Merge pull request !112 from rtos-lover/los_sched
2021-05-18 09:42:55 +08:00
Caoruihong
8d353084d6 remove symlinks which is not supported on windows platform
use submodules instead of symlinks for bounds_checking_function and cmsis_os2.h

Change-Id: I105c3d2c537d9c3c725adf1265a3312df4286916
2021-05-17 22:28:19 +08:00
openharmony_ci
3feb4f26f3 !125 增强L0 低功耗可扩展性
Merge pull request !125 from zhushengle/sleep
2021-05-17 22:08:19 +08:00
openharmony_ci
5ef2efb347 !118 支持IAR工具的Cortex-m33 TrustZone
Merge pull request !118 from JerryH/master
2021-05-17 21:59:13 +08:00
openharmony_ci
517282d51c !121 新增M核文件系统vfs层,支持多种文件系统类型
Merge pull request !121 from JING/seren
2021-05-17 18:58:18 +08:00
chenjing
5479dd66d7 fix: add liteos_m vfs
Close #I3R493

Change-Id: Ic799182b46c6c04c879d1b2202bda6b1f2cf40df
2021-05-17 15:57:44 +08:00
openharmony_ci
e52008ba6e !123 m核编译存在libsec_kernel.a核libsec_static.a两份安全函数库,需要优化
Merge pull request !123 from zhangfanfan2/other
2021-05-15 14:46:16 +08:00
openharmony_ci
8ef21e0b41 !115 fix: correct spelling
Merge pull request !115 from rtos-lover/los_swtmr
2021-05-15 09:45:21 +08:00
openharmony_ci
62f6531539 !114 fix: correct typo
Merge pull request !114 from rtos-lover/los_task
2021-05-15 09:44:01 +08:00
openharmony_ci
439368edc1 !111 fix: correct typo in los_memory.c
Merge pull request !111 from rtos-lover/los_mem
2021-05-15 09:42:02 +08:00
openharmony_ci
0be2ecfdd0 !110 fix: corrent spelling
Merge pull request !110 from rtos-lover/los_debug
2021-05-15 09:41:16 +08:00
openharmony_ci
a47fc7beb3 !107 fix:enum misspell
Merge pull request !107 from Harylee/fix
2021-05-15 09:40:27 +08:00
zhushengle
43c04f6f5c fix:Low power expansion.
Close #I3RCHR

Change-Id: I8db9ae791b234b8237ce5a8e56d4d6581833b9ee
2021-05-14 17:08:47 +08:00
openharmony_ci
4166768998 !122 LOS_IntLock的返回类型实际为UINT32,不需要定义为UINTPTR,需要修改
Merge pull request !122 from zhangfanfan2/master
2021-05-14 16:11:11 +08:00
openharmony_ci
92c28e1fe7 !124 解决内存泄漏检测错误判断及删除冗余判断
Merge pull request !124 from JerryH/mem
2021-05-14 16:07:53 +08:00
YOUR_NAME
eac4a04153 Fix memory leak check and interity error check.
Delete redundant judgments.

Close #I3P10Y and #I3QNLT

Change-Id: I94ff34099bc39345ef5490f185f70c4b87bfd415
2021-05-14 14:49:17 +08:00
YOUR_NAME
bcc34e22ed fix: modify the return type of LOS_IntLock from UINTPTR to UINT32.
Change-Id: I6207e5cb7d612a154a88de4e9e274c67127361d8
2021-05-14 11:33:05 +08:00
zhangfanfan2
1144b75f3f fix: remove libsec_kernel 2021-05-13 20:46:46 +08:00
openharmony_ci
748a827560 !104 add: add environment setup and compilation into document
Merge pull request !104 from kenneth/master
2021-05-12 17:30:59 +08:00
openharmony_ci
e7a3659b33 !109 XX产品上,存在使用littlefs文件系统重复打开文件会新创建Fd,与预期不一致,改为返回失败
Merge pull request !109 from li_zan/master
2021-05-12 11:05:14 +08:00
openharmony_ci
658c340644 !109 XX产品上,存在使用littlefs文件系统重复打开文件会新创建Fd,与预期不一致,改为返回失败
Merge pull request !109 from li_zan/master
2021-05-12 11:05:13 +08:00
li_zan
7d9976cd90 Add already opened file logic 2021-05-11 20:30:31 +08:00
openharmony_ci
acf317a8cd !119 支持sleep函数
Merge pull request !119 from zhangfanfan2/master
2021-05-11 20:02:05 +08:00
zhangfanfan2
03be5e6e92 feature: Add sleep function 2021-05-11 16:48:35 +08:00
openharmony_ci
d38087fa2f !67 LiteOs-m内核posix接口修改和用例补充
Merge pull request !67 from babu_g/noEmployeeNum_ChangeID_13651229_guanzehui
2021-05-11 16:47:41 +08:00
YOUR_NAME
c70ef201f3 Add Cortex-m33 TrustZone about IAR
close #I3MX1F

Change-Id: I449b01ad7ac714412a26bb9f3a6b723a6c74ca3f
2021-05-11 10:45:52 +08:00
openharmony_ci
bb90e629cb !117 修正tm_gmtoff字段的含义
Merge pull request !117 from Caoruihong/gmtoff
2021-05-11 09:47:40 +08:00
li_zan
602c9f6dfa Add already opened file logic 2021-05-08 17:00:11 +08:00
li_zan
96d2f2910e Add already opened file logic 2021-05-08 15:18:01 +08:00
li_zan
3a4a8b0680 Add already opened file logic 2021-05-08 15:14:45 +08:00
openharmony_ci
7a72b0069a !113 fix: modify event API description
Merge pull request !113 from MGY917/master
2021-05-08 13:10:43 +08:00
li_zan
4aeaf030a2 Add already opened file logic 2021-05-08 11:31:27 +08:00
Caoruihong
9b498e651e fix tm_gmtoff
tm_gmtoff is opposite of timezone despite daylight saving.
timezone(global variable): seconds west of UTC, not adjusted for daylight saving.
tm_gmtoff(member of struct tm): seconds east of UTC, including adjustment for daylight saving.

Change-Id: If2e76b7da64989fb2df063ce4101d317474a7ab7
2021-05-08 11:17:02 +08:00
li_zan
49e9044529 Add already opened file logic 2021-05-08 11:14:33 +08:00
rtos-lover
dd5cefb0da fix: correct spelling
correct some typos in los_swtmr.c It_los_queue_head_019.c

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3PYLH
2021-05-08 10:30:25 +08:00
rtos-lover
3ceface13e fix: correct typo
correct typos in los_task.c

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3PYHW?from=project-issue
2021-05-08 10:23:02 +08:00
Guangyao Ma
9481f1d840 fix: modify event API description
Change-Id: I62a819f3407fb933e0bb2ff2e97eda6e643acafb
2021-05-08 10:17:11 +08:00
rtos-lover
f7d50d0fbf fix: fix function name
correct function name OsSchedSetIdleTaskSchedParam

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3PXEX
2021-05-08 10:12:52 +08:00
rtos-lover
e7ea50f131 fix: correct spelling
correct type in los_memory.c

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3PYC3
2021-05-08 10:06:01 +08:00
rtos-lover
02ac3ade30 fix:correct spelling
corrent those typos in log_debug.h los_exc.S

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3PVZV
2021-05-08 10:00:57 +08:00
kenneth
259fb54b3c fix: change to OpenHarmony LiteOS-M 2021-05-08 09:29:40 +08:00
kenneth
be57ece9ce fix: update macro to config item 2021-05-07 20:44:58 +08:00
kenneth
656fd1e422 fix:update according to review comments
the latest OpenHarmony code is needed.
2021-05-07 20:43:54 +08:00
li_zan
94c0727e1d Add already opened file logic 2021-05-07 15:25:42 +08:00
li_zan
cd292f8428 Add already opened file logic 2021-05-07 11:35:51 +08:00
li_zan
a99f817c23 Add already opened file logic 2021-05-07 11:35:08 +08:00
openharmony_ci
167b4d0c37 !87 合入某功能产品在M核上文件系统littlefs的适配代码
Merge pull request !87 from li_zan/master
2021-05-07 10:10:16 +08:00
openharmony_ci
9991911927 !98 fix:Scheduling optimization, test case adaptation modification
Merge pull request !98 from zhushengle/test
2021-05-06 21:19:06 +08:00
zhushengle
1a7a6b9ffe fix:Scheduling optimization, test case adaptation modification.
Close #I3OING

Change-Id: Ia131ebb46e92578081f2df93010eaf305dfbf977
2021-05-06 19:35:02 +08:00
openharmony_ci
4163a99123 !108 fix:delete redundant local variable
Merge pull request !108 from Harylee/delete
2021-05-06 19:28:22 +08:00
openharmony_ci
111f9476ea !106 fix: misspell
Merge pull request !106 from Harylee/update_osal
2021-05-06 19:25:26 +08:00
openharmony_ci
b57d33ba07 !105 L0 swtmr_align定时器在相同周期时,count计算错误,且相同响应时间时,后插入的节点应该位于已存在节点的后面
Merge pull request !105 from zhushengle/swtmr
2021-05-06 19:17:02 +08:00
kenneth
a38365ed09 fix: change description according to review 2021-05-06 19:04:59 +08:00
kenneth
4dc0d313d1 fix: update according to review comments 2021-05-06 17:05:22 +08:00
Haryslee
fcf7db5022 fix:delete redundant local variable
Change-Id: Ia3a01d91866a96f8b47c66a4af0042254e24f69f
2021-05-06 15:21:54 +08:00
Haryslee
26ed722cf0 fix:enum misspell
Change-Id: I0ae966a7738fe087e222dc1441c8409a1e1661e0
2021-05-06 15:07:15 +08:00
Haryslee
30578a6a68 fix: misspell
Change-Id: I29c6df3ea2e1c23529373de74aa634be0c3de114
2021-05-06 11:46:52 +08:00
zhushengle
5cda1e77cc fix:The SWTMR_ALIGN timer calculates the count error for the same period, and for the same response time, the later-inserted node should be behind the existing node.
Close #I3PS5B

Change-Id: I15317e64ea3376a4880e8eb0a3af3e3e8449ba08
2021-05-06 10:37:24 +08:00
kenneth
5c19fd4bec fix: update doc usage 2021-05-06 10:23:53 +08:00
kenneth
954c2fcfb5 fix: update document description 2021-05-06 10:20:47 +08:00
kenneth
85b18bdfce add: add introduction on project example 2021-05-06 10:11:04 +08:00
kenneth
d4c77b729b add: add ninja、gn compilation 2021-05-06 09:55:59 +08:00
li_zan
9bebc0fb82 add littlefs code 2021-04-30 17:02:42 +08:00
li_zan
2d21fca6e8 add littlefs code 2021-04-30 16:29:10 +08:00
li_zan
928827f62e add littlefs code 2021-04-30 15:16:34 +08:00
li_zan
580ef55f7e add littlefs code 2021-04-30 14:33:00 +08:00
openharmony_ci
58023d89c5 !91 fix LOS_MEMBOX_ALIGNED macro name
Merge pull request !91 from rtos-lover/master
2021-04-30 08:36:11 +08:00
openharmony_ci
6c83107292 !91 fix LOS_MEMBOX_ALIGNED macro name
Merge pull request !91 from rtos-lover/master
2021-04-30 08:36:10 +08:00
openharmony_ci
032f96e7d6 !102 fix: include file log_config.h in los_mpu.c
Merge pull request !102 from kenneth/master
2021-04-30 08:35:44 +08:00
openharmony_ci
b69ac58a97 !103 fix: modify type INLNIE
Merge pull request !103 from tel5021/master
2021-04-30 08:35:26 +08:00
openharmony_ci
0a65cfb651 !100 fix: L0 GN compilation problem
Merge pull request !100 from zhushengle/SIG
2021-04-29 16:37:19 +08:00
tel5021
294a6d246b fix: modify type INLNIE 2021-04-29 16:03:21 +08:00
kenneth
1932d714a5 fix: include file log_config.h in los_mpu.c
include log_config.h in kernel\arch\arm\cortex-m7\iar\los_mpu.c to solve compilation issue

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3OHY2
2021-04-29 15:23:44 +08:00
zhushengle
2f9bfcc6ee fix: L0 GN compilation problem
Close: #I3ORHS
Change-Id: Ia105084336f2ba66f91546226a9383646a0148ce
2021-04-29 10:38:54 +08:00
openharmony_ci
4f39369e13 !99 刷新submodule并将其URL改为使用相对路径
Merge pull request !99 from Caoruihong/relative_url
2021-04-29 09:17:16 +08:00
openharmony_ci
814e70270b !90 fix: remove targets project files
Merge pull request !90 from kenneth/master
2021-04-29 08:37:31 +08:00
Caoruihong
3ae790b065 use relative url for submodules
Change-Id: I3445dfb7b62888a2f6674fdebd364fb1727c61aa
2021-04-29 00:55:52 +08:00
openharmony_ci
1f725147f3 !96 fix:Fixed kernel error with header protector and header comment description.
Merge pull request !96 from zhushengle/others
2021-04-28 09:09:07 +08:00
openharmony_ci
f65e14bf3b !97 使内核使用正确的securec库
Merge pull request !97 from Caoruihong/securec_m
2021-04-27 21:11:06 +08:00
openharmony_ci
e638d1a41a !60 Add support for Nuclei RISC-V 32 bit processor in LiteOS-M of OpenHarmony
Merge pull request !60 from linzewenTin/dev_nuclei
2021-04-27 20:43:55 +08:00
Caoruihong
9cc5b79da1 use liteos_m specific securec build configuration
Change-Id: Id1ca03e0c7456724c1ba55fef4dbd07ba6213285
2021-04-27 16:54:32 +08:00
openharmony_ci
6c1ce1c1cc !84 style: align with first param line
Merge pull request !84 from MGY917/master
2021-04-27 11:40:12 +08:00
openharmony_ci
5b9eed0328 !95 fix:Scheduling module code to join GN compilation.
Merge pull request !95 from zhushengle/gn
2021-04-26 21:30:56 +08:00
openharmony_ci
4e568d1cbf !92 先使用顶层third_party, 后继再改用本仓库中的third_party
Merge pull request !92 from Caoruihong/top_third_party
2021-04-26 21:23:14 +08:00
openharmony_ci
667d0992f0 !94 恢复hos_cmsis_adp.h
Merge pull request !94 from Caoruihong/restore_hos_cmsis_adp_h
2021-04-26 21:23:04 +08:00
zhushengle
3907238b0f fix:Fixed kernel error with header protector and header comment description.
Close #I3O4SF

Change-Id: I544cde728fb8131d199a21be440ae02da2fe21fb
2021-04-26 21:13:55 +08:00
Caoruihong
19ccb7c76c restore hos_cmsis_adp.h
Change-Id: I9a37ebec3ea4e94652a723ae612691b9888705ed
2021-04-26 18:57:39 +08:00
zhushengle
8bf166b418 fix: Scheduling module code to join GN compilation.
Close #I3OA95

Change-Id: I19b25af29a078be048274ca98d970f3554491138
2021-04-26 18:57:33 +08:00
openharmony_ci
524317fa9f !89 fix:Fixed comment description for OS_TSK_GET_INDEX error
Merge pull request !89 from zhushengle/master
2021-04-26 18:53:19 +08:00
openharmony_ci
2659b02d2d !93 先保留CMSIS和SECUREC组件的旧的路径可用
Merge pull request !93 from Caoruihong/keep_old_path
2021-04-26 18:49:55 +08:00
Caoruihong
3db2a98360 keep old path available
Change-Id: I0b97d5f82386c6d642b94c390e24eede81cd7c54
2021-04-26 18:27:52 +08:00
Caoruihong
4d556fbe90 use top third_party
Change-Id: I382b10ef7a6adc328777349bce142e58895f7c8d
2021-04-26 17:11:56 +08:00
linzewen
70620b1cb6 Kernel: Remove unused function
Signed-off-by: linzewen <linzewen@nucleisys.com>
2021-04-25 20:58:53 -07:00
linzewen
4475439ca1 Kernel:Fix typo
Signed-off-by: linzewen <linzewen@nucleisys.com>
2021-04-25 20:08:41 -07:00
linzewen
dab3a81ac7 Kernel: Update task switch and delete some unused variables
Signed-off-by: linzewen <linzewen@nucleisys.com>
2021-04-25 19:55:37 -07:00
rtos-lover
fced8992cf fix: fix LOS_MEMBOX_ALIGNED macro name
change LOS_MEMBOX_ALLIGNED to fix LOS_MEMBOX_ALIGNED
2021-04-26 09:42:24 +08:00
kenneth
f39da5a6da fix: remove targets project files
remove cortex-m3_stm32f103_simulator_keil、cortex-m4_stm32f429ig_fire-challenger_iar、cortex-m7_nucleo_f767zi_gcc project files

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3NTW6?from=project-issue
2021-04-26 09:30:58 +08:00
li_zan
ac46317e0f add littlefs code 2021-04-25 20:42:35 +08:00
li_zan
10b416e74f add littlefs code 2021-04-25 17:41:42 +08:00
zhushengle
912bf69866 fix:Fixed comment description for OS_TSK_GET_INDEX error 2021-04-25 17:40:11 +08:00
openharmony_ci
b8cd812303 !83 fix:Provide a system CPU wait interface
Merge pull request !83 from zhushengle/master
2021-04-25 17:32:38 +08:00
linzewen
1639cf484d Target:Fix typo
Signed-off-by: linzewen <linzewen@nucleisys.com>
2021-04-25 02:25:13 -07:00
linzewen
2f3ea928df Target:Update demo soc config file and fix typo
Signed-off-by: linzewen <linzewen@nucleisys.com>
2021-04-25 02:19:24 -07:00
linzewen
24a847a111 Target: Update RV-STAR config file and fix some typo
Signed-off-by: linzewen <linzewen@nucleisys.com>
2021-04-25 02:19:24 -07:00
linzewen
6c60393567 kernel: update nuclei risc-v porting code
Signed-off-by: linzewen <linzewen@nucleisys.com>
2021-04-25 02:19:24 -07:00
linzewen
b4f5bc433c Update nuclei demo soc to latest version
Based on Nuclei SDK v0.3.1

Signed-off-by: linzewen <linzewen@nucleisys.com>
2021-04-25 02:19:24 -07:00
linzewen
4170e57f18 Fix some issues
Move some functions from head file to c file
Change interrupt function argument
The "hwiPrio" argument high 16 bit for level and low 16 bit for priority

Signed-off-by: linzewen <linzewen@nucleisys.com>
2021-04-25 02:19:24 -07:00
linzewen
2f3ded2a11 Add makefile based project for Nuclei RV_STAR board
Setup tools for compilment and entering GCC folder under riscv_nuclei_gd32vf103_soc_gcc
Using "make all" command to compile project
Using "make clean" command to clean project
Using "make debug" command to debug project
Using "make upload" command to upload project
OS configurations is under "OS_CONFIG" folder
Most information can be found in README.md

Signed-off-by: linzewen <linzewen@nucleisys.com>
2021-04-25 02:19:24 -07:00
linzewen
746d56b7b9 Add makefile based project for Nuclei ddr200T board
Setup tools for compilment and entering GCC folder under riscv_nuclei_demo_soc_gcc
Using "make all" command to compile project
Using "make clean" command to clean project
Using "make debug" command to debug project
Using "make upload" command to upload project
OS configurations is under "OS_CONFIG" folder
Most information can be found in README.md

Signed-off-by: linzewen <linzewen@nucleisys.com>
2021-04-25 02:19:24 -07:00
linzewen
6c8da43bc9 Add Nuclei RISC-V support
This kernel is setup for rv32 arch with gcc compiler.

Signed-off-by: linzewen <linzewen@nucleisys.com>
2021-04-25 02:19:24 -07:00
openharmony_ci
f96848e4ce !85 fix some typos
Merge pull request !85 from kenneth/master
2021-04-25 15:30:16 +08:00
li_zan
3ae9d36049 add littlefs code 2021-04-24 11:50:43 +08:00
li_zan
606bd9ca08 add littlefs code 2021-04-24 11:23:49 +08:00
openharmony_ci
8168885709 !82 加入FatFs同时修正BUILD.gn中third_party路径
Merge pull request !82 from Caoruihong/fix_thirdparty_path
2021-04-23 17:57:13 +08:00
zhushengle
adaf6cf7c5 fix:Change the interface to LOS_UDelay and change the input parameter to microsecond.
Close #I3NT3Y

Change-Id: Iae33e0aff59480342b07bb4fd2e66969a09affb3
2021-04-23 17:33:27 +08:00
kenneth
f6b8cab253 fix: fix some typo issues
change 'LOS_MOUDLE_ID' to 'LOS_MODULE_ID', change 'a interrupt' to 'an interrupt', change 'HalIsIntAcvive' to 'HalIsIntActive' and other typos.

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3NNOQ, https://gitee.com/openharmony/kernel_liteos_m/issues/I3NNR6, https://gitee.com/openharmony/kernel_liteos_m/issues/I3NNTL, https://gitee.com/openharmony/kernel_liteos_m/issues/I3NNQ1
2021-04-23 17:19:01 +08:00
Guangyao Ma
c6d36f5915 style: align with first param line
Change-Id: Ifc14322a05a624d5c24ef4dca25c1ad7299aeed1
2021-04-23 17:10:47 +08:00
zhushengle
9656d852ab fix:Add LOS_SysDelay declaration.
Close #I3NT3Y

Change-Id: I14a1edc3f9aa06cba28ad51a12f21f6fdcf14fd0
2021-04-23 15:38:11 +08:00
zhushengle
583d177de0 fix:Provide a CPU delay interface
Close #I3NT3Y

Change-Id: I30c984a95a77cbddabdae2900ab8fcf9d7eac1ac
2021-04-23 14:50:27 +08:00
openharmony_ci
3ca3a3e250 !80 fix: fix some misspell in comments
Merge pull request !80 from rtos-lover/master
2021-04-23 14:42:16 +08:00
Caoruihong
ad1e09ff77 add third_party FatFs and fix BUILD.gn
Change-Id: I456530ca5282d6c4b0904d04ae0a0a5ff155391a
2021-04-23 12:05:48 +08:00
openharmony_ci
18aa697589 !64 liteos_m 调度优化及低功耗设计
Merge pull request !64 from zhushengle/sched
2021-04-23 11:01:40 +08:00
zhushengle
afdda22821 fix:Solution of conflict
Change-Id: If2565e5942ca019865720d56dd8bda1617044e6d
2021-04-22 14:33:20 +08:00
openharmony_ci
23360db35c !81 posix模块编译中增加 pthread_cond.c
Merge pull request !81 from zhangfanfan2/master
2021-04-22 13:57:04 +08:00
openharmony_ci
77581810c3 !77 通过git submodule使用third_party组件
Merge pull request !77 from Caoruihong/third_party
2021-04-22 11:48:25 +08:00
zhangfanfan2
0a22391490 feature:add "pthread_cond.c" to compile in posix module 2021-04-22 11:46:37 +08:00
openharmony_ci
424f7ad6dc !79 将NORETURN声明放到函数前,KEIL不支持放在函数后
Merge pull request !79 from Caoruihong/fix_noreturn
2021-04-22 11:26:45 +08:00
openharmony_ci
8e3a4325e0 !36 Fixed mixed CH and En characters
Merge pull request !36 from davidinux/master
2021-04-21 22:18:01 +08:00
rtos-lover
457281427b fix: fix misspell in comments
change misspell __cpluscplus to __cplusplus

close https://gitee.com/openharmony/kernel_liteos_m/issues/I3NG3P?from=project-issue
2021-04-21 18:29:53 +08:00
Caoruihong
14f0d7286a move noreturn attribute in front
Change-Id: I267fa3fcaa068fe9465231a5edac531b1b539eda
2021-04-21 17:19:07 +08:00
Caoruihong
b70f2c3e91 use third_party by git submodules
Change-Id: I1e2fe3e887c5ec528921534d4618d89d8cf90759
2021-04-21 16:53:49 +08:00
zhushengle
793d2139b2 fix:Solution of conflict.
Close #I3IK07

Change-Id: I6913691a28c90b54fbda233209d43b981884f10c
2021-04-20 14:56:26 +08:00
openharmony_ci
4474869a07 !75 删除无用的__cplusplus,移除不必要的文件x权限
Merge pull request !75 from Caoruihong/cplusplus
2021-04-20 09:01:48 +08:00
Caoruihong
3cea0e42b1 remove __cplusplus guards in .c files
Change-Id: Ie25b83a42d3ca35c3a6d624ef01f425a85957d7f
2021-04-19 18:19:28 +08:00
openharmony_ci
f278a00483 !73 修复LOS_MemInfoGet接口入参无清零的问题
Merge pull request !73 from JerryH/master
2021-04-19 14:19:20 +08:00
YOUR_NAME
d642d90a7d IssueNo:#I3IDB0
Description:Fix the problem that the interface does not reset the output parameter.
Sig:liteos_m
Feature or Bugfix:Bugfix
Binary Source:No

Change-Id: I9e6f7a6813c4eb70b22681fc6a4994eae44a1b64
2021-04-17 16:22:29 +08:00
zhushengle
bad8c3d53b IssueNo:#I3IK07
Description:LOS_SysCycleGet replace HalCpuCycleGet
Sig:kernel
Feature or Bugfix:Feature
Binary Source:No

Change-Id: Ife3a4d351818f718f58d3624b5ee6dd127113378
2021-04-17 16:07:51 +08:00
zhushengle
c5f517667a IssueNo:#I3IK07
Description:Resolve the conflict.
Feature or Bugfix:Feature
Binary Source:No

Change-Id: I882dcb9e523cab30e6ab4889099984fe0302f92e
2021-04-17 11:03:45 +08:00
zhushengle
3ae472f739 IssueNo:#I3IK07
Description:HalGetCpuCycle cancel the weak attribute
Sig:kernel
Feature or Bugfix:Feature
Binary Source:No

Change-Id: Ic88577e70626f760a8831ef98d7cda95b9dfaad4
2021-04-17 10:49:39 +08:00
openharmony_ci
d11a206619 !72 为LOS_Panic等函数添加noreturn属性
Merge pull request !72 from Caoruihong/noreturn
2021-04-17 09:24:12 +08:00
openharmony_ci
7fdbff3851 !66 优化HalSetRtcTime之类接口定义及说明
Merge pull request !66 from Caoruihong/RtcTime
2021-04-17 09:23:49 +08:00
Caoruihong
6bf6efdc7e add noreturn attribute for LOS_Panic LOS_Reboot and HalSysExit
Change-Id: I65bbdd3d60aa754a389f9371649a96483d2a6f8a
2021-04-16 19:32:01 +08:00
zhushengle
49be405820 Merge remote-tracking branch 'origin/master' into HEAD
Change-Id: I9a1458b1344f89ca04cab96c3599c9cfea757929
2021-04-16 19:22:07 +08:00
zhushengle
57f6e1f181 IssueNo:I3IK07
Description:liteos_m scheduling optimization and low power design.
Sig:kernel
Feature or Bugfix:Feature
Binary Source:No

Change-Id: I6ccbe267ec20f93f97032c5b006c3214eb099daa
2021-04-16 18:54:47 +08:00
openharmony_ci
530b738dec !71 【轻量级 PR】:fix osEventFlagsGet for #I3IP98
Merge pull request !71 from Caoruihong/N/A
2021-04-16 15:30:17 +08:00
Caoruihong
a5338840c0 fix osEventFlagsGet for #I3IP98 2021-04-16 14:48:32 +08:00
Caoruihong
1732679354 optimize Hal<Set/Get>Rtc<Time/Timezone> APIs
Change-Id: I2ba4b2d05c59f6c7532526fff0f2587b5b6719f0
2021-04-16 11:58:05 +08:00
openharmony_ci
a09d38a983 !70 lwip适配内核posix接口
Merge pull request !70 from 刘建东/master
2021-04-16 08:02:51 +08:00
openharmony_ci
e000ba3941 !69 新增hook适配层在其他平台上中断trace的支持
Merge pull request !69 from Zhaotianyu/0415hook
2021-04-16 07:55:30 +08:00
YOUR_NAME
92c4e63ae7 IssueNo:#I3IMWT
Description:use posix instead of lwip self
Feature or Bugfix:Bugfix
Binary Source:No
2021-04-15 20:00:41 +08:00
openharmony_ci
a03c2bb664 !68 支持osThreadNew函数attr为NULL时创建线程,同时修正线程优先级的转换
Merge pull request !68 from Caoruihong/osThreadNew
2021-04-15 18:35:44 +08:00
arvinzzz
84a9f65597 Description: The hook adaptation layer adds support for interrupts on other platforms.
Change-Id: I09636885b2edf893322ea5fb0eabef02266875a0
2021-04-15 15:53:30 +08:00
Caoruihong
2b88a46965 support osThreadNew with NULL attr parameter and fix priority issues
Change-Id: Ie26b6878f8742207545e55372f724872a932542a
2021-04-15 00:12:37 +08:00
zhushengle
628cdcbea0 IssueNo:#I3IK07
Description:liteos_m scheduling optimization and low power design.
Sig:kernel
Feature or Bugfix:Feature
Binary Source:No

Change-Id: I56bb190c73c8d7497ddbf2ad49ad522143008117
2021-04-14 17:27:42 +08:00
guanzehui
8b23ffca0d Description: opensource check,modify posix and unittest,add unit fuzz test case
Team: OTHERS
Feature or Bugfix:Feature
Binary Source:No
PrivateCode(Yes/No):No
Change-Id: Ia95966e595109db01440cffa062cf3aff4faa3b8
ChangeID:13651229
2021-04-14 14:34:48 +08:00
zhushengle
cd30e62998 IssueNo:#I3IK07
Description:liteos_m scheduling optimization and low power design.
Sig:kernel
Feature or Bugfix:Feature
Binary Source:No

Change-Id: I5b692a503ce6128626eec8f9a37742d7caa1fea9
2021-04-14 09:22:36 +08:00
zhushengle
f685eeb97d IssueNo:#I3IK07
Description:liteos_m scheduling optimization and low power design.
Sig:kernel
Feature or Bugfix:Feature
Binary Source:No

Change-Id: If913b673c9b69039b51ca416be0a77ebccf2773b
2021-04-13 21:48:04 +08:00
openharmony_ci
f6151020de !63 lwip适配内核posix接口
Merge pull request !63 from 刘建东/master
2021-04-13 14:22:18 +08:00
YOUR_NAME
788f9d2b4f IssueNo:#I3IBCL
Description:use posix instead of lwip self
Feature or Bugfix:Bugfix
Binary Source:No
2021-04-12 21:34:37 +08:00
YOUR_NAME
eca2fae28a IssueNo:#I3IBCL
Description:use posix instead of lwip self
Feature or Bugfix:Bugfix
Binary Source:No
2021-04-12 20:37:22 +08:00
YOUR_NAME
247959fcbc IssueNo:#I3IBCL
Description:use posix instead of lwip self
Feature or Bugfix:Bugfix
Binary Source:No
2021-04-12 10:57:50 +08:00
YOUR_NAME
80fe0c7d2a IssueNo:#I3IBCL
Description:use posix instead of lwip self
Feature or Bugfix:Bugfix
Binary Source:No
2021-04-12 10:26:02 +08:00
openharmony_ci
c6a520b7f8 !58 Add issue and PR template for master
Merge pull request !58 from 马明帅/add_issus_pr_template_for_master
2021-04-11 09:46:55 +08:00
openharmony_ci
45a8a3812c !52 heap初始化做address以及size的对齐检查
Merge pull request !52 from 金永生/los_heap
2021-04-10 09:03:51 +08:00
openharmony_ci
63d340305c !56 修复limits.h中部分宏定义
Merge pull request !56 from Zhaotianyu/0406limits
2021-04-09 17:17:57 +08:00
arvinzzz
caffe81339 IssueNo:#I3HGTM
Description: Fix some macro definitions of limits.h.
Feature or Bugfix: Bugfix
Binary Source:NA

Change-Id: I419c712f8605f8a0d2d6cb0b6c3831cea0e742e1
2021-04-09 10:05:57 +08:00
openharmony_ci
2c17c08c03 !61 mq_getattr & setattr interface add
Merge pull request !61 from give-me-five/master
2021-04-08 14:28:37 +08:00
openharmony_ci
1ffc972340 !62 Fix the issue that interrupt vector array alignment
Merge pull request !62 from Harylee/os
2021-04-08 14:27:12 +08:00
wuyunjie
d731b1aeb5 mqattr set get
Change-Id: I990a50335f6c2a9deaef87d445a970d4f398a0a5
2021-04-08 10:26:39 +08:00
Haryslee
6f92ee70bd Fix the issue that interrupt vector array alignment
Change-Id: I3200eff0e5b048135cd05ffa4e7559633088dc03
2021-04-07 20:02:13 +08:00
openharmony_ci
f2d61153c6 !57 L0 testsuit upload
Merge pull request !57 from give-me-five/master
2021-04-07 16:36:15 +08:00
mamingshuai
e367306278 add issue and pr template 2021-04-07 14:49:54 +08:00
x_xiny
449f27d5cb add l0 testsuits
Change-Id: I523269c97053f484d5cb0d94397269e41eaae86c
2021-04-07 11:19:43 +08:00
openharmony_ci
4fc4b8c9c1 !55 【轻量级 PR】:fix pthread_create timing bug
Merge pull request !55 from Caoruihong/N/A
2021-04-02 18:01:27 +08:00
Caoruihong
5b2c3f2c89 fix pthread_create timing bug 2021-04-02 16:18:19 +08:00
openharmony_ci
1d2ec9d05d !54 add hook framework
Merge pull request !54 from Zhaotianyu/master
2021-04-02 15:36:02 +08:00
arvinzzz
62caa74382 Description: add hook framework
Change-Id: I45c37c3c92e74e676818e713fa46b3a9fe970e68
2021-04-01 11:26:49 +08:00
金永生
9af0cd4891 modify:heapInit:check the heap addr and size for configured alignsize, if not, return err 2021-03-30 19:43:21 +08:00
openharmony_ci
9a9ffb0770 !49 使用01替换YES NO的依赖
Merge pull request !49 from 刘建东/master
2021-03-30 10:55:03 +08:00
YOUR_NAME
efc0c4455a IssueNo:#I3E5C3
Description:use 0 1 instead of YES NO
Sig:phone
Feature or Bugfix:Bugfix
Binary Source:No
2021-03-30 10:07:13 +08:00
openharmony_ci
dd02d2980c !46 添加基于MPU功能的任务栈保护机制
Merge pull request !46 from JerryH/master
2021-03-29 14:27:37 +08:00
openharmony_ci
024c18741b !47 L0 posix接口新增
Merge pull request !47 from give-me-five/noEmployeeNum_ChangeID_13439291_wuyunjie
2021-03-27 16:46:43 +08:00
YOUR_NAME
f5b7a2ed60 IssueNo:I3DGV9
Description:Add task stack protection by mpu.
Sig:liteos_m
Feature or Bugfix:Feature
Binary Source: No

Change-Id: I13e301379756f61677eeb44be41928cbf21e3eaa
2021-03-27 10:21:50 +08:00
davidinux
742f65d876 Interrupt typo fixed 2021-03-22 11:37:38 +01:00
davidinux
e8ae0fe38f Fixed mixed En ad Ch characters 2021-03-22 11:15:32 +01:00
1797 changed files with 168755 additions and 247604 deletions

View File

@@ -1,6 +1,6 @@
### 相关的Issue
### 原因(目的、解决的问题等)

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
# 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:
@@ -27,37 +27,67 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
declare_args() {
enable_ohos_kernel_liteos_m_cppsupport = true
enable_ohos_kernel_liteos_m_cpup = true
enable_ohos_kernel_liteos_m_exchook = true
enable_ohos_kernel_liteos_m_kal = true
enable_ohos_kernel_liteos_m_fs = true
enable_ohos_kernel_liteos_m_backtrace = true
import("config.gni")
LITEOS_LOS_CONFIG_H = rebase_path("$LITEOSTOPDIR/kernel/include/los_config.h")
config("los_config") {
cflags = [ "-Werror" ]
asmflags = [
"-DCLZ=CLZ",
"-imacros",
"$LITEOS_LOS_CONFIG_H",
]
include_dirs = [
"//kernel/liteos_m/kernel/include",
"//kernel/liteos_m/kernel/arch/include",
"//kernel/liteos_m/utils",
"//third_party/bounds_checking_function/include",
]
}
group("kernel") {
deps = [
"components/bounds_checking_function:sec",
"kernel:kernel",
"utils:utils",
"//third_party/bounds_checking_function:libsec_static",
]
if (enable_ohos_kernel_liteos_m_cppsupport == true) {
if (enable_ohos_kernel_liteos_m_cppsupport) {
deps += [ "components/cppsupport:cppsupport" ]
}
if (enable_ohos_kernel_liteos_m_cpup == true) {
if (enable_ohos_kernel_liteos_m_cpup) {
deps += [ "components/cpup:cpup" ]
}
if (enable_ohos_kernel_liteos_m_exchook == true) {
if (enable_ohos_kernel_liteos_m_exchook) {
deps += [ "components/exchook:exchook" ]
}
if (enable_ohos_kernel_liteos_m_backtrace == true) {
if (enable_ohos_kernel_liteos_m_backtrace) {
deps += [ "components/backtrace:backtrace" ]
}
if (enable_ohos_kernel_liteos_m_fs == true) {
if (enable_ohos_kernel_liteos_m_fs) {
deps += [ "components/fs:fs" ]
}
if (enable_ohos_kernel_liteos_m_kal == true) {
if (enable_ohos_kernel_liteos_m_pm) {
deps += [ "components/power:pm" ]
}
if (enable_ohos_kernel_liteos_m_trace) {
deps += [ "components/trace:trace" ]
}
if (enable_ohos_kernel_liteos_m_kal) {
deps += [ "kal:kal" ]
}
if (enable_ohos_kernel_liteos_m_shell) {
deps += [ "components/shell:shell" ]
}
if (enable_ohos_kernel_liteos_m_test) {
deps += [ "testsuits:test" ]
}
if (enable_ohos_kernel_liteos_m_lwip) {
deps += [ ohos_kernel_liteos_m_lwip_path ]
}
if (enable_ohos_kernel_liteos_m_dynlink) {
deps += [ "components/dynlink:dynlink" ]
}
}

86
OAT.xml Normal file
View File

@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This is the configuration file template for OpenHarmony OSS Audit Tool, please copy it to your project root dir and modify it refer to OpenHarmony/tools_oat/README.
-->
<configuration>
<oatconfig>
<licensefile></licensefile>
<policylist>
<policy name="projectPolicy" desc="">
<policyitem type="copyright" name="Huawei Technologies Co., Ltd. All rights reserved." path=".*" desc="original liteos copyright"/>
<policyitem type="license" name="BSD-3-Clause" path=".*" desc="Liteos kernel use bsd3 license"/>
<policyitem type="license" name="BSD-3-Clause" path=".*" desc="Liteos kernel use bsd3 license"/>
</policy>
</policylist>
<filefilterlist>
<filefilter name="defaultFilter" desc="文件属于FreeBSD仓库软连接本仓库屏蔽告警在FreeBSD仓库进行处理">
<filteritem type="filepath" name="kernel/arch/risc-v/nuclei/gcc/nmsis/Library/.*" desc="文件属于三方芯片的二进制代码,属于社区贡献,不用提供额外的说明"/>
<filteritem type="filepath" name="targets/riscv_nuclei_demo_soc_gcc/.*" desc="文件属于nuclei三方芯片的源代码文件头说明跟随liteos_m/LICENSE不用额外说明"/>
<filteritem type="filepath" name="targets/riscv_nuclei_gd32vf103_soc_gcc/.*" desc="文件属于nuclei三方芯片的源代码文件头说明跟随liteos_m/LICENSE不用额外说明"/>
<filteritem type="filepath" name="NOTICE" desc="NOTICE文件"/>
<filteritem type="filepath" name="kernel/arch/risc-v/nuclei" desc="该文件的license为apache 2.0符合"/>
</filefilter>
<filefilter name="defaultFilter" desc="Files not to check">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="defaultPolicyFilter" desc="Filters for compatibilitylicense header policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="licenseFileNamePolicyFilter" desc="Filters for LICENSE file policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="readmeOpenSourcefileNamePolicyFilter" desc="Filters for README.OpenSource file policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
</filefilterlist>
<licensematcherlist>
<!--licensematcher name="uvwxyz License" desc="If the scanning result is InvalidLicense, you can define matching rules here. Note that quotation marks must be escaped.">
<licensetext name="
uvwxyz license textA xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
" desc=""/>
<licensetext name="
uvwxyz license textB xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
" desc=""/>
</licensematcher-->
</licensematcherlist>
</oatconfig>
</configuration>

View File

@@ -15,11 +15,18 @@ The OpenHarmony LiteOS Cortex-M is the kernel designed for the lightweight opera
## Directory Structure<a name="section161941989596"></a>
The directory structure is listed as below, for the detailed directories, please refer to [arch_spec.md](arch_spec.md).
```
/kernel/liteos_m
├── components # Optional components
│ ├── backtrace # Backtrace support
│ ├── cppsupport # C++ support
── cpup # CPU possession (CPUP)
── cpup # CPU possession (CPUP)
│ ├── dynlink # Dynamic loader & linker
│ ├── exchook # Exception hook
│ ├── fs # File system
│ └── net # Network support
├── kal # Kernel abstraction layer
│ ├── cmsis # CMSIS-compliant API support
│ └── posix # POSIX API support
@@ -62,18 +69,9 @@ make clean; make
After the compilation is successful, the executable file **NUCLEO-F767.hex** is generated in the **cortex-m7\_nucleo\_f767zi\_gcc/build** directory. Burn the file to the corresponding board using STM32 ST-LINK Utility.
## Change Log
v1.0.1
1. removed these KAL apis: `KalThreadGetInfo`,`KalDelayUs`,`KalTimerCreate`,`KalTimerStart`,`KalTimerChange`,`KalTimerStop`,`KalTimerDelete`,`KalTimerIsRunning`,`KalTickToMs`,`KalMsToTick`,`KalGetMemInfo`
2. add some POSIX apis
v1.0
1. first release
## Repositories Involved<a name="section1371113476307"></a>
[Kernel subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/kernel.md)
[Kernel subsystem](https://gitee.com/openharmony/docs/blob/HEAD/en/readme/kernel.md)
**kernel\_liteos\_m**

View File

@@ -15,11 +15,18 @@ OpenHarmony LiteOS-M内核是面向IoT领域构建的轻量级物联网操作系
## 目录<a name="section161941989596"></a>
目录结构如下,详细目录请参考[arch_spec_zh.md](arch_spec_zh.md)。
```
/kernel/liteos_m
├── components # 可选组件
│ ├── backtrace # 回溯栈支持
│ ├── cppsupport # C++支持
── cpup # CPUP功能
── cpup # CPUP功能
│ ├── dynlink # 动态加载与链接
│ ├── exchook # 异常钩子
│ ├── fs # 文件系统
│ └── net # Network功能
├── kal # 内核抽象层
│ ├── cmsis # cmsis标准接口支持
│ └── posix # posix标准接口支持
@@ -41,39 +48,80 @@ OpenHarmony LiteOS-M内核是面向IoT领域构建的轻量级物联网操作系
## 使用说明<a name="section3732185231214"></a>
LiteOS-M内核提供了三种芯片架构的工程位于targets目录。三种架构的工程编译及使用方式如下
OpenHarmony LiteOS-M内核的编译构建系统是一个基于gn和ninja的组件化构建系统支持按组件配置、裁剪和拼装按需构建出定制化的产品。本文主要介绍如何基于gn和ninja编译LiteOS-M工程GCC+Makefile、IAR、Keil MDK等编译方式可以参考社区爱好者贡献的站点。
### 搭建系统基础环境
在搭建各个开发板环境前需要完成OpenHarmony系统基础环境搭建。系统基础环境主要是指OpenHarmony的编译环境和开发环境详细介绍请参考官方站点[Ubuntu编译环境准备](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/device-dev/quick-start/quickstart-lite-env-setup-linux.md)。开发者需要根据环境搭建文档完成下述软件的安装Python3.7+、gn、ninja、hb。对于LiteOS-M内核还需要安装Make构建工具和[ARM GCC编译工具链](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)。
### 获取OpenHarmony源码
开发者需要在Linux服务器上通过Git克隆获取OpenHarmony最新源码详细的源码获取方式请见[源码获取](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/device-dev/get-code/sourcecode-acquire.md)。获取OpenHarmony完整仓代码后假设克隆目录为`~/openHarmony`
### 获取示例工程源码
以开发板Nucleo-F767Zi为例演示如何编译运行`OpenHarmony LiteOS-M`内核工程。在本地目录,执行下述命令克隆示例代码。
```
git clone https://gitee.com/harylee/nucleo_f767zi.git
```
假设克隆到的代码目录为`~/nucleo_f767zi`。 执行如下命令把代码目录的`device``vendor`目录复制到`openHarmony`工程的相应目录。
```
mkdir ~/openHarmony/device/st
cp -r ~/nucleo_f767zi/device/st/nucleo_f767zi ~/openHarmony/device/st/nucleo_f767zi
chmod +x ~/openHarmony/device/st/nucleo_f767zi/build.sh
cp -r ~/nucleo_f767zi/vendor/st ~/openHarmony/vendor/st
```
关于示例代码目录的说明,可以参考资料站点[板级目录规范](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/device-dev/porting/transplant-chip-board-overview.md)。如果需要自行移植开发板,请参考[板级系统移植](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/device-dev/porting/transplant-chip-board.md)。
### 编译运行
编译运行前,交叉编译工具链`bin`目录配置到`PATH`环境变量中或者配置`device/st/nucleo_f767zi/liteos_m/config.gni`文件中`board_toolchain_path`配置项为交叉编译工具链`bin`目录。
`OpenHarmony`根目录,执行`hb set`设置产品路径,选择`nucleo_f767zi`产品,然后执行`hb build`开启编译。如下:
```
user@dev:~/OpenHarmony$ hb set
[OHOS INFO] Input code path: # 直接按回车然后选择nucleo_f767zi产品即可
OHOS Which product do you need? nucleo_f767zi@st
user@dev:~/OpenHarmony$ hb build
```
最终的镜像生成在`~/openHarmony/out/nucleo_f767zi/`目录中,通过`STM32 ST-LINK Utility`软件将镜像文件下载至单板查看运行效果。
### 社区移植工程链接
LiteOS-M内核移植的具体开发板的工程由社区开发者提供可以访问社区开发者代码仓获取。如果您移植支持了更多开发板可以提供链接给我们进行社区分享。
- cortex-m3
kernel/liteos\_m/targets/cortex-m3\_stm32f103\_simulator\_keil目录是基于STM32F103芯片架构构建的keil工程目录keil开发工具可通过网络下载并安装。进入cortex-m3\_stm32f103\_simulator\_keil/project目录双击los\_demo.uvproj文件即可打开相应工程编译成功后即可通过JLINK或者STM32 ST-LINK Utility烧录至对应单板。
- STM32F103 https://gitee.com/rtos_lover/stm32f103_simulator_keil
该仓包含OpenHarmony LiteOS-M内核基于STM32F103芯片架构构建的Keil工程支持Keil MDK方式进行编译。
- cortex-m4
kernel/liteos\_m/targets/cortex-m4\_stm32f429ig\_fire-challenger\_iar目录是基于STM32F429IG芯片架构构建的IAR工程目录IAR开发工具可通过网络下载并安装。进入cortex-m4\_stm32f429ig\_fire-challenger\_iar/project目录双击los\_demo.eww文件即可打开相应工程编译成功后即可通过JLINK或者STM32 ST-LINK Utility烧录至对应单板。
- 野火挑战者STM32F429IGTb https://gitee.com/harylee/stm32f429ig_firechallenger
该仓包含OpenHarmony LiteOS-M内核移植支持`野火挑战者STM32F429IGTb`开发板的工程代码支持Ninja、GCC、IAR等方式进行编译。
- cortex-m7
kernel/liteos\_m/targets/cortex-m7\_nucleo\_f767zi\_gcc目录是基于STM32F767ZI芯片架构构建的Makefile工程目录。编译方式如下
- Nucleo-F767ZI https://gitee.com/harylee/nucleo_f767zi
```
cd kernel/liteos_m/targets/cortex-m7_nucleo_f767zi_gcc
make clean; make
```
编译成功后在cortex-m7\_nucleo\_f767zi\_gcc/build目录下生成NUCLEO-F767.hex可执行文件通过烧录工具STM32 ST-LINK Utility烧录到对应的单板。
## 修改日志
v1.0.1
1. 删除以下KAL接口: `KalThreadGetInfo`,`KalDelayUs`,`KalTimerCreate`,`KalTimerStart`,`KalTimerChange`,`KalTimerStop`,`KalTimerDelete`,`KalTimerIsRunning`,`KalTickToMs`,`KalMsToTick`,`KalGetMemInfo`
2. 添加部分POSIX接口
v1.0
1. 首次发布
该仓包含OpenHarmony LiteOS-M内核移植支持`Nucleo-F767ZI`开发板的工程代码支持Ninja、GCC、IAR等方式进行编译。
## 相关仓<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/HEAD/zh-cn/readme/%E5%86%85%E6%A0%B8%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
**kernel\_liteos\_m**

View File

@@ -1,52 +1,77 @@
```
.
├── components --- 可选组件可裁剪依赖kernel
│   ├── cppsupport --- C++支持
│   ── cpup --- CPUP功能
├── kal --- 内核抽象层
│   ├── cmsis --- cmsis标准支持
│   ── posix --- posix标准支持
├── kernel --- 内核最小功能集支持
│   ── arch --- 硬件架构相关
│   │   ├── arm --- arm32架构
│   │   │   └── cortex-m4 --- cortex-m4架构
│   │   │   └── iar ---
│   │   │   ├── los_atomic.h
│   │   │   ├── los_context.h
│   │   │   ├── los_interrupt.h
│   │   │   └── los_mpu.h
├── components --- Components available for porting and header files exposed externally
│   ├── backtrace --- Backtrace
│   ── cppsupport --- C++
│   ├── cpup --- CPUP
│   ├── dynlink --- Dynamic loader & linker
│   ── exchook --- Exception hook
│   ├── fs --- File System
│   ── net --- Network
├── kal --- Kernel Abstraction Layer, APIs exposed externally, including CMSIS APIs and part of POSIX APIs
│   ├── cmsis --- CMSIS
│   └── posix --- POSIX
├── kernel --- Code for defining the minimum kernel function set
│   ├── arch --- Code of the kernel instruction architecture layer
│   │   ├── arm --- ARM32 architecture
│   │   │   ├── cortex-m3 --- Cortex-m3 architecture
│   │   │   │ └── keil --- Implementation of the Keil toolchain
│   │   │   ├── cortex-m33 --- Cortex-m33 architecture
│   │   │   │ │── gcc --- Implementation of the GCC toolchain
│   │   │   │ └── iar --- Implementation of the IAR toolchain
│   │   │   └── cortex-m4 --- Cortex-m4 architecture
│   │   │   │ │── gcc --- Implementation of the GCC toolchain
│   │   │   │ └── iar --- Implementation of the IAR toolchain
│   │   │   └── cortex-m7 --- Cortex-m7 architecture
│   │   │   │ │── gcc --- Implementation of the GCC toolchain
│   │   │   │ └── iar --- Implementation of the IAR toolchain
│   │   ├── risc-v --- Risc-v architecture
│   │   │ ├── nuclei --- Nuclei architecture
│   │   │   │ └── gcc --- Implementation of the GCC toolchain
│   │   │ └── riscv32 --- Riscv32 architecture
│   │   │   │ └── gcc --- Implementation of the GCC toolchain
│   │   └── include
│   │   ├── los_arch_atomic.h --- 定义通用arch的原子操作
│   │   ├── los_arch_context.h --- 定义通用arch的上下文切换
│   │   ├── los_arch.h --- 定义通用arch初始化
│   │   ── los_arch_interrupt.h --- 定义通用arch中断
│   │   ├── los_arch.h --- Arch initialization
│   │   ├── los_atomic.h --- Atomic operations
│   │   ├── los_context.h --- Context switch
│   │   ── los_interrupt.h --- Interrupts
│   │   ├── los_mpu.h --- Memory protection unit operations
│   │   └── los_timer.h --- Timer operations
│   ├── include
│   │   ├── los_config.h --- 功能开关和配置参数
│   │   ├── los_event.h --- 事件
│   │   ├── los_liteos.h --- liteos最小功能集对外提供的头文件
│   │   ├── los_memory.h --- 堆内存管理
│   │   ├── los_mutex.h --- 互斥锁
│   │   ├── los_queue.h --- 队列
│   │   ├── los_scheduler.h --- 调度算法
│   │   ├── los_sem.h --- 信号量
│   │   ├── los_task.h --- 任务
│   │   ── los_timer.h --- 定时器
│   │   ├── los_config.h --- Configuration parameters
│   │   ├── los_event.h --- Events management
│   │   ├── los_membox.h --- Membox management
│   │   ├── los_memory.h --- Heap memory management
│   │   ├── los_mux.h --- Mutex
│   │   ├── los_queue.h --- Queue
│   │   ├── los_sched.h --- Scheduler
│   │   ├── los_sem.h --- Semaphores
│   │   ├── los_sortlink.h --- Sort link
│   │   ── los_swtmr.h --- Timer
│   │   ├── los_task.h --- Tasks
│   │   └── los_tick.h --- Tick
│   └── src
├── targets
│   └── targets
│   └── cortex-m4_stm32f429ig_fire-challenger_iar
   ├── board
   ├── dprintf.c
   ├── Libraries
   ── main.c
│   ├── project
│   ├── target_config.h --- 板级配置功能开关和配置参数
│   └── Utilities
│   └── riscv_nuclei_demo_soc_gcc
├── GCC --- Compilation config
├── OS_CONFIG --- Board config
├── SoC --- SOC codes
── Src --- Application codes
│   └── riscv_nuclei_gd32vf103_soc_gcc
│   └── riscv_sifive_fe310_gcc
└── utils
├── include
│   ├── los_compiler.h --- 编译工具配置,类型定义
│   ├── los_debug.h --- debugprintf相关
│   ├── los_error.h --- 错误定义
│   └── los_list.h
├── internal
├── BUILD.gn --- Gn build config file
├── los_compiler.h --- Compiler configuration
├── los_debug.c --- Debugging facilities
── los_debug.h
├── los_error.c --- Errors codes and definitions
├── los_error.h
├── los_hook.c --- Hook function facilities
├── los_hook.h
├── los_list.h --- Doubly linked list
└── los_reg.h --- Register macros
└── src
```

77
arch_spec_zh.md Normal file
View File

@@ -0,0 +1,77 @@
```
.
├── components --- 移植可选组件,依赖内核,单独对外提供头文件
│   ├── backtrace --- 回溯栈支持
│   ├── cppsupport --- C++支持
│   ├── cpup --- CPUP功能
│   ├── dynlink --- 动态加载与链接
│   ├── exchook --- 异常钩子
│   ├── fs --- 文件系统
│   └── net --- 网络功能
├── kal --- 内核抽象层提供内核对外接口当前支持CMSIS接口和部分POSIX接口
│   ├── cmsis --- CMSIS标准支持
│   └── posix --- POSIX标准支持
├── kernel --- 内核最小功能集代码
│   ├── arch --- 内核指令架构层代码
│   │   ├── arm --- ARM32架构
│   │   │   ├── cortex-m3 --- Cortex-m3架构
│   │   │   │ └── keil --- Keil编译工具链实现
│   │   │   ├── cortex-m33 --- Cortex-m33架构
│   │   │   │ │── gcc --- GCC编译工具链实现
│   │   │   │ └── iar --- IAR编译工具链实现
│   │   │   └── cortex-m4 --- Cortex-m4架构
│   │   │   │ │── gcc --- GCC编译工具链实现
│   │   │   │ └── iar --- IAR编译工具链实现
│   │   │   └── cortex-m7 --- Cortex-m7架构
│   │   │   │ │── gcc --- GCC编译工具链实现
│   │   │   │ └── iar --- IAR编译工具链实现
│   │   ├── risc-v --- Risc-v架构
│   │   │ ├── nuclei --- Nuclei架构
│   │   │   │ └── gcc --- GCC编译工具链实现
│   │   │ └── riscv32 --- Riscv32架构
│   │   │   │ └── gcc --- GCC编译工具链实现
│   │   └── include
│   │   ├── los_arch.h --- 定义arch初始化
│   │   ├── los_atomic.h --- 定义通用arch原子操作
│   │   ├── los_context.h --- 定义通用arch上下文切换
│   │   ├── los_interrupt.h --- 定义通用arch中断
│   │   ├── los_mpu.h --- 定义通用arch内存保护
│   │   └── los_timer.h --- 定义通用arch定时器
│   ├── include
│   │   ├── los_config.h --- 功能开关和配置参数
│   │   ├── los_event.h --- 事件
│   │   ├── los_membox.h --- 静态内存管理
│   │   ├── los_memory.h --- 动态内存管理
│   │   ├── los_mux.h --- 互斥锁
│   │   ├── los_queue.h --- 队列
│   │   ├── los_sched.h --- 调度算法
│   │   ├── los_sem.h --- 信号量
│   │   ├── los_sortlink.h --- 排序链表
│   │   ├── los_swtmr.h --- 定时器
│   │   ├── los_task.h --- 任务
│   │   └── los_tick.h --- Tick时钟
   └── src
├── targets
│   └── targets
│   └── riscv_nuclei_demo_soc_gcc
│ │ ├── GCC --- 编译相关
│ │ ├── OS_CONFIG --- 开发板配置功能开关和配置参数
│ │ ├── SoC --- SOC相关代码
│ │ └── Src --- Application相关代码
│   └── riscv_nuclei_gd32vf103_soc_gcc
│   └── riscv_sifive_fe310_gcc
└── utils
├── internal
├── BUILD.gn --- Gn构建文件
├── los_compiler.h --- 编译工具配置,类型定义
├── los_debug.c --- Debugprintf相关
├── los_debug.h
├── los_error.c --- 错误处理
├── los_error.h
├── los_hook.c --- 钩子函数注册和调用
├── los_hook.h
├── los_list.h --- 双向链表
└── los_reg.h --- 寄存器读写宏定义
└── src
```

59
bundle.json Normal file
View File

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

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
# 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:
@@ -27,14 +27,10 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_m/config.gni")
static_library("backtrace") {
sources = [ "los_backtrace.c" ]
include_dirs = [
"../../kernel/include",
"../../kernel/arch/include",
"../../utils",
"./",
"//third_party/bounds_checking_function/include",
]
configs += [ "$LITEOSTOPDIR:los_config" ]
}

View File

@@ -33,13 +33,19 @@
#include "los_task.h"
#include "los_debug.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_BACKTRACE_TYPE != 0)
/* This function is used to judge whether the data in the stack is a code section address.
The default code section is only one, but there may be more than one. Modify the
judgment condition to support multiple code sections. */
WEAK BOOL OsStackDataIsCodeAddr(UINTPTR value)
{
if ((value >= CODE_START_ADDR) && (value < CODE_END_ADDR)) {
return TRUE;
}
return FALSE;
}
#if (LOSCFG_BACKTRACE_TYPE == 1)
#define OS_BACKTRACE_START 2
/* Thumb instruction, so the pc must be an odd number */
@@ -117,7 +123,7 @@ STATIC INLINE UINT32 OsStackAddrGet(UINTPTR *stackStart, UINTPTR *stackEnd, UINT
{
if (SP != 0) {
*stackStart = SP;
if ((SP >= CODE_START_ADDR) && (SP < CSTACK_END_ADDR)) {
if ((SP >= CSTACK_START_ADDR) && (SP < CSTACK_END_ADDR)) {
*stackEnd = CSTACK_END_ADDR;
} else {
UINT32 taskID = LOS_CurTaskIDGet();
@@ -125,7 +131,7 @@ STATIC INLINE UINT32 OsStackAddrGet(UINTPTR *stackStart, UINTPTR *stackEnd, UINT
*stackEnd = (UINTPTR)taskCB->topOfStack + taskCB->stackSize;
if ((SP < (UINTPTR)taskCB->topOfStack) || (SP >= *stackEnd)) {
PRINT_ERR("msp statck [0x%x, 0x%x], cur task stack [0x%x, 0x%x], cur sp(0x%x) is overflow!\n",
CODE_START_ADDR, CSTACK_END_ADDR, (UINTPTR)taskCB->topOfStack, *stackEnd, SP);
CSTACK_START_ADDR, CSTACK_END_ADDR, (UINTPTR)taskCB->topOfStack, *stackEnd, SP);
return LOS_NOK;
}
}
@@ -133,9 +139,9 @@ STATIC INLINE UINT32 OsStackAddrGet(UINTPTR *stackStart, UINTPTR *stackEnd, UINT
if (HalSpGet() != HalPspGet()) {
*stackStart = HalMspGet();
*stackEnd = CSTACK_END_ADDR;
if ((*stackStart < CODE_START_ADDR) || (*stackStart >= CSTACK_END_ADDR)) {
if ((*stackStart < CSTACK_START_ADDR) || (*stackStart >= CSTACK_END_ADDR)) {
PRINT_ERR("msp stack [0x%x, 0x%x], cur sp(0x%x) is overflow!\n",
CODE_START_ADDR, CSTACK_END_ADDR, *stackStart);
CSTACK_START_ADDR, CSTACK_END_ADDR, *stackStart);
return LOS_NOK;
}
PRINTK("msp, start = %x, end = %x\n", *stackStart, *stackEnd);
@@ -145,7 +151,7 @@ STATIC INLINE UINT32 OsStackAddrGet(UINTPTR *stackStart, UINTPTR *stackEnd, UINT
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
*stackEnd = (UINTPTR)taskCB->topOfStack + taskCB->stackSize;
if ((*stackStart < (UINTPTR)taskCB->topOfStack) || (*stackStart >= *stackEnd)) {
PRINT_ERR("psp stack [0x%x, 0x%x], cur sp(0x%x) is overflow, cur task id is %d!\n",
PRINT_ERR("psp stack [0x%x, 0x%x], cur sp(0x%x) is overflow, cur task id is %u!\n",
taskCB->topOfStack, *stackEnd, *stackStart, taskID);
return LOS_NOK;
}
@@ -184,7 +190,172 @@ STATIC INLINE UINTPTR OsAddrIsValid(UINTPTR sp)
return pc;
}
#elif (LOSCFG_BACKTRACE_TYPE == 2)
STATIC INLINE BOOL OsBackTraceFpCheck(UINT32 value);
#define OS_BACKTRACE_START 1
#define OS_RA_OFFSET 4
#define OS_FP_OFFSET 8
#define OS_FP_ALIGN(value) (((UINT32)(value) & (UINT32)(LOSCFG_STACK_POINT_ALIGN_SIZE - 1)) == 0)
#define OS_FP_CHECK(value) (((UINT32)(value) != FP_INIT_VALUE) && OS_FP_ALIGN(value))
STATIC INLINE UINTPTR OsFpGet(VOID)
{
UINTPTR fp = 0;
__asm volatile("mv %0, s0" : "=r"(fp));
dsb();
return fp;
}
VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP)
{
UNUSED(SP);
UINT32 backFp = OsFpGet();
UINT32 tmpFp;
UINT32 backRa;
UINT32 count = 0;
UINT32 index = 0;
if (LR == NULL) {
return;
}
while (OS_FP_CHECK(backFp)) {
tmpFp = backFp;
backRa = *((UINT32 *)(UINTPTR)(tmpFp - OS_RA_OFFSET));
backFp = *((UINT32 *)(UINTPTR)(tmpFp - OS_FP_OFFSET));
if (index++ < jumpCount) {
continue;
}
LR[count] = backRa;
count++;
if ((count == LRSize) || (backFp == tmpFp) ||
(!OsStackDataIsCodeAddr(backRa))) {
break;
}
}
if (count < LRSize) {
LR[count] = 0;
}
}
#elif (LOSCFG_BACKTRACE_TYPE == 3)
#define OS_BACKTRACE_START 1
#define OS_JALX_INS_MASK 0x7F
#define OS_JAL_INS_LOW 0x6F
#define OS_JAL_16_INS_MASK 0x2001
#define OS_JALR_INS_LOW 0x67
#define OS_JALR_16_INS_MASK 0x9002
#define OS_JR_16_INS_MASK 0x8002
#define OS_J_16_INS_MASK 0xA001
STATIC INLINE BOOL OsInsIsJump(UINTPTR addr)
{
UINT16 ins1 = *((UINT16 *)addr);
UINT16 ins2 = *((UINT16 *)(addr + 2)); // 2, for the mask
/* Jal ins */
if (((ins1 & OS_JALX_INS_MASK) == OS_JAL_INS_LOW) ||
((ins1 & OS_JAL_16_INS_MASK) == OS_JAL_16_INS_MASK) ||
((ins2 & OS_JAL_16_INS_MASK) == OS_JAL_16_INS_MASK)) {
return TRUE;
}
/* Jalr ins */
if (((ins1 & OS_JALX_INS_MASK) == OS_JALR_INS_LOW) ||
((ins1 & OS_JALR_16_INS_MASK) == OS_JALR_16_INS_MASK) ||
((ins2 & OS_JALR_16_INS_MASK) == OS_JALR_16_INS_MASK)) {
return TRUE;
}
/* Jr ins */
if (((ins1 & OS_JR_16_INS_MASK) == OS_JR_16_INS_MASK) ||
((ins2 & OS_JR_16_INS_MASK) == OS_JR_16_INS_MASK)) {
return TRUE;
}
/* J ins */
if (((ins1 & OS_J_16_INS_MASK) == OS_J_16_INS_MASK) ||
((ins2 & OS_J_16_INS_MASK) == OS_J_16_INS_MASK)) {
return TRUE;
}
return FALSE;
}
STATIC INLINE UINTPTR OsSpGet(VOID)
{
UINTPTR sp = 0;
__asm volatile("mv %0, sp" : "=r"(sp));
dsb();
return sp;
}
STATIC INLINE UINT32 OsStackAddrGet(UINTPTR *stackStart, UINTPTR *stackEnd, UINTPTR SP)
{
if (SP != 0) {
*stackStart = SP;
if ((SP >= CSTACK_START_ADDR) && (SP < CSTACK_END_ADDR)) {
*stackEnd = CSTACK_END_ADDR;
} else {
UINT32 taskID = LOS_CurTaskIDGet();
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
*stackEnd = (UINTPTR)taskCB->topOfStack + taskCB->stackSize;
if ((SP < (UINTPTR)taskCB->topOfStack) || (SP >= *stackEnd)) {
PRINT_ERR("msp statck [0x%x, 0x%x], cur task stack [0x%x, 0x%x], cur sp(0x%x) is overflow!\n",
CSTACK_START_ADDR, CSTACK_END_ADDR, (UINTPTR)taskCB->topOfStack, *stackEnd, SP);
return LOS_NOK;
}
}
} else {
if (!LOS_TaskIsRunning()) {
*stackStart = OsSpGet();
*stackEnd = CSTACK_END_ADDR;
if ((*stackStart < CSTACK_START_ADDR) || (*stackStart >= CSTACK_END_ADDR)) {
PRINT_ERR("msp stack [0x%x, 0x%x], cur sp(0x%x) is overflow!\n",
CSTACK_START_ADDR, CSTACK_END_ADDR, *stackStart);
return LOS_NOK;
}
} else {
*stackStart = OsSpGet();
UINT32 taskID = LOS_CurTaskIDGet();
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
*stackEnd = (UINTPTR)taskCB->topOfStack + taskCB->stackSize;
if ((*stackStart < (UINTPTR)taskCB->topOfStack) || (*stackStart >= *stackEnd)) {
PRINT_ERR("psp stack [0x%x, 0x%x], cur sp(0x%x) is overflow, cur task id is %d!\n",
taskCB->topOfStack, *stackEnd, *stackStart, taskID);
return LOS_NOK;
}
}
}
return LOS_OK;
}
STATIC INLINE UINTPTR OsAddrIsValid(UINTPTR sp)
{
UINTPTR pc;
BOOL ret;
pc = *((UINTPTR *)sp);
ret = OsStackDataIsCodeAddr(pc);
if (ret == FALSE) {
return 0;
}
ret = OsInsIsJump(pc - sizeof(UINTPTR));
if (ret == FALSE) {
return 0;
}
return pc;
}
#else
#error Unknown backtrace type.
#endif
#if (LOSCFG_BACKTRACE_TYPE == 1) || (LOSCFG_BACKTRACE_TYPE == 3)
VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP)
{
if (LR == NULL) {
@@ -223,57 +394,6 @@ VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP)
LR[count] = 0;
}
}
#elif (LOSCFG_BACKTRACE_TYPE == 2)
STATIC INLINE BOOL OsBackTraceFpCheck(UINT32 value);
#define OS_BACKTRACE_START 1
#define OS_RA_OFFSET 4
#define OS_FP_OFFSET 8
#define OS_FP_ALIGN(value) (((UINT32)(value) & (UINT32)(LOSCFG_STACK_POINT_ALIGN_SIZE - 1)) == 0)
#define OS_FP_CHECK(value) (((UINT32)(value) != FP_INIT_VALUE) && OS_FP_ALIGN(value))
STATIC INLINE UINTPTR OsFpGet(VOID)
{
UINTPTR fp = 0;
__asm volatile("mv %0, s0" : "=r"(fp));
dsb();
return fp;
}
VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP)
{
UNUSED(SP);
UINT32 backFp = OsFpGet();
UINT32 tmpFp;
UINT32 backRa;
UINT32 count = 0;
UINT32 index = 0;
if (LR == NULL) {
return;
}
while (OS_FP_CHECK(backFp)) {
tmpFp = backFp;
backRa = *((UINT32 *)(UINTPTR)(tmpFp - OS_RA_OFFSET));
backFp = *((UINT32 *)(UINTPTR)(tmpFp - OS_FP_OFFSET));
if (index++ < jumpCount) {
continue;
}
LR[count] = backRa;
count++;
if ((count == LRSize) || (backFp == tmpFp) ||
(!OsStackDataIsCodeAddr(backRa))) {
break;
}
}
if (count < LRSize) {
LR[count] = 0;
}
}
#else
#error Unknown backtrace type.
#endif
VOID LOS_BackTrace(VOID)
@@ -293,20 +413,15 @@ VOID LOS_BackTrace(VOID)
if (LR[index] == 0) {
break;
}
PRINTK("traceback %d -- lr = 0x%x\r\n", index, LR[index]);
PRINTK("traceback %u -- lr = 0x%x\r\n", index, LR[index]);
}
PRINTK("----- traceback end -----\r\n");
}
VOID LOS_BackTraceInit(VOID)
VOID OSBackTraceInit(VOID)
{
OsBackTraceHookSet(LOS_RecordLR);
}
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@@ -46,7 +46,7 @@ extern "C" {
#if (LOSCFG_BACKTRACE_TYPE != 0)
#if (LOSCFG_BACKTRACE_TYPE == 1)
/* The default name of the code section and CSTACK section are given below,
and the user can be adjust it according to the linker script file. */
and the user can adjust it according to the linker script file. */
#if defined(__ICCARM__)
/* The default code section name is .text */
#define CODE_SECTION_NAME ".text"
@@ -56,7 +56,7 @@ extern "C" {
#pragma section=CSTACK_SECTION_NAME
/* Default only one code section. In fact, there may be more than one.
You can define more than one and modify the OsStackDataIsCodeAddr function
You can define more than one and redefine the OsStackDataIsCodeAddr function
to support searching in multiple code sections */
#define CODE_START_ADDR ((UINTPTR)__section_begin(CODE_SECTION_NAME))
#define CODE_END_ADDR ((UINTPTR)__section_end(CODE_SECTION_NAME))
@@ -84,16 +84,16 @@ extern CHAR *CODE_SECTION_START(CODE_SECTION_NAME);
extern CHAR *CODE_SECTION_END(CODE_SECTION_NAME);
/* Default only one code section. In fact, there may be more than one.
You can define more than one and modify the OsStackDataIsCodeAddr function
You can define more than one and redefine the OsStackDataIsCodeAddr function
to support searching in multiple code sections */
#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START(CODE_SECTION_NAME))
#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END(CODE_SECTION_NAME))
#define CSTACK_START_ADDR ((UINTPTR)&CSTACK_SECTION_START(CSTACK_SECTION_NAME))
#define CSTACK_END_ADDR ((UINTPTR)&CSTACK_SECTION_END(CSTACK_SECTION_NAME))
#elif defined(__GNUC__)
/* The defalut code section start address */
/* The default code section start address */
#define CODE_SECTION_START _stext
/* The defalut code section end address */
/* The default code section end address */
#define CODE_SECTION_END _etext
/* The default C stack section start address */
#define CSTACK_SECTION_START _sstack
@@ -106,7 +106,7 @@ extern CHAR *CSTACK_SECTION_START;
extern CHAR *CSTACK_SECTION_END;
/* Default only one code section. In fact, there may be more than one.
You can define more than one and modify the OsStackDataIsCodeAddr function
You can define more than one and redefine the OsStackDataIsCodeAddr function
to support searching in multiple code sections */
#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START)
#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END)
@@ -115,37 +115,34 @@ extern CHAR *CSTACK_SECTION_END;
#else
#error Unknown compiler.
#endif
#elif (LOSCFG_BACKTRACE_TYPE == 2)
#elif (LOSCFG_BACKTRACE_TYPE == 2) || (LOSCFG_BACKTRACE_TYPE == 3)
#if defined(__GNUC__)
/* The defalut code section start address */
/* The default code section start address */
#define CODE_SECTION_START __text_start
/* The defalut code section end address */
/* The default code section end address */
#define CODE_SECTION_END __text_end
/* The default C stack section start address */
#define CSTACK_SECTION_START __except_stack_top
/* The default C stack section end address */
#define CSTACK_SECTION_END __start_and_irq_stack_top
extern CHAR *CODE_SECTION_START;
extern CHAR *CODE_SECTION_END;
extern CHAR *CSTACK_SECTION_START;
extern CHAR *CSTACK_SECTION_END;
#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START)
#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END)
#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START)
#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END)
#define CSTACK_START_ADDR ((UINTPTR)&CSTACK_SECTION_START)
#define CSTACK_END_ADDR ((UINTPTR)&CSTACK_SECTION_END)
#else
#error Unknown compiler.
#endif
#endif
/* This function is used to judge whether the data in the stack is a code section address.
The default code section is only one, but there may be more than one. Modify the
judgment condition to support multiple code sections. */
STATIC INLINE BOOL OsStackDataIsCodeAddr(UINTPTR value)
{
if ((value >= CODE_START_ADDR) && (value < CODE_END_ADDR)) {
return TRUE;
}
return FALSE;
}
/* This function is currently used to register the memory leak check hook,
other uses do not need to be called temporarily. */
VOID LOS_BackTraceInit(VOID);
VOID OSBackTraceInit(VOID);
/* This function is used to print the function call stack. */
VOID LOS_BackTrace(VOID);

View File

@@ -1,74 +0,0 @@
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
static_library("sec") {
include_dirs = [ "//third_party/bounds_checking_function/include" ]
sources = [
"//third_party/bounds_checking_function/src/fscanf_s.c",
"//third_party/bounds_checking_function/src/fwscanf_s.c",
"//third_party/bounds_checking_function/src/gets_s.c",
"//third_party/bounds_checking_function/src/memcpy_s.c",
"//third_party/bounds_checking_function/src/memmove_s.c",
"//third_party/bounds_checking_function/src/memset_s.c",
"//third_party/bounds_checking_function/src/scanf_s.c",
"//third_party/bounds_checking_function/src/securecutil.c",
"//third_party/bounds_checking_function/src/secureinput_a.c",
"//third_party/bounds_checking_function/src/secureinput_w.c",
"//third_party/bounds_checking_function/src/secureprintoutput_a.c",
"//third_party/bounds_checking_function/src/secureprintoutput_w.c",
"//third_party/bounds_checking_function/src/snprintf_s.c",
"//third_party/bounds_checking_function/src/sprintf_s.c",
"//third_party/bounds_checking_function/src/sscanf_s.c",
"//third_party/bounds_checking_function/src/strcat_s.c",
"//third_party/bounds_checking_function/src/strcpy_s.c",
"//third_party/bounds_checking_function/src/strncat_s.c",
"//third_party/bounds_checking_function/src/strncpy_s.c",
"//third_party/bounds_checking_function/src/strtok_s.c",
"//third_party/bounds_checking_function/src/swprintf_s.c",
"//third_party/bounds_checking_function/src/swscanf_s.c",
"//third_party/bounds_checking_function/src/vfscanf_s.c",
"//third_party/bounds_checking_function/src/vfwscanf_s.c",
"//third_party/bounds_checking_function/src/vscanf_s.c",
"//third_party/bounds_checking_function/src/vsnprintf_s.c",
"//third_party/bounds_checking_function/src/vsprintf_s.c",
"//third_party/bounds_checking_function/src/vsscanf_s.c",
"//third_party/bounds_checking_function/src/vswprintf_s.c",
"//third_party/bounds_checking_function/src/vswscanf_s.c",
"//third_party/bounds_checking_function/src/vwscanf_s.c",
"//third_party/bounds_checking_function/src/wcscat_s.c",
"//third_party/bounds_checking_function/src/wcscpy_s.c",
"//third_party/bounds_checking_function/src/wcsncat_s.c",
"//third_party/bounds_checking_function/src/wcsncpy_s.c",
"//third_party/bounds_checking_function/src/wcstok_s.c",
"//third_party/bounds_checking_function/src/wmemcpy_s.c",
"//third_party/bounds_checking_function/src/wmemmove_s.c",
"//third_party/bounds_checking_function/src/wscanf_s.c",
]
}

View File

@@ -1 +0,0 @@
Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.

View File

@@ -1,124 +0,0 @@
木兰宽松许可证, 第2版
2020年1月 http://license.coscl.org.cn/MulanPSL2
您对“软件”的复制、使用、修改及分发受木兰宽松许可证第2版“本许可证”的如下条款的约束
0. 定义
“软件” 是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。
“贡献” 是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。
“贡献者” 是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。
“法人实体” 是指提交贡献的机构及其“关联实体”。
“关联实体” 是指对“本许可证”下的行为方而言控制、受控制或与其共同受控制的机构此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。
1. 授予版权许可
每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。
2. 授予专利许可
每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。
3. 无商标许可
“本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可但您为满足第4条规定的声明义务而必须使用除外。
4. 分发限制
您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。
5. 免责声明与责任限制
“软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。
6. 语言
“本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。
条款结束
如何将木兰宽松许可证第2版应用到您的软件
如果您希望将木兰宽松许可证第2版应用到您的新软件为了方便接收者查阅建议您完成如下三步
1 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字;
2 请您在软件包的一级目录下创建以“LICENSE”为名的文件将整个许可证文本放入该文件中
3 请将如下声明文本放入每个源文件的头部注释中。
Copyright (c) [Year] [name of copyright holder]
[Software Name] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
Mulan Permissive Software License,Version 2
Mulan Permissive Software License,Version 2 (Mulan PSL v2)
January 2020 http://license.coscl.org.cn/MulanPSL2
Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions:
0. Definition
Software means the program and related documents which are licensed under this License and comprise all Contribution(s).
Contribution means the copyrightable work licensed by a particular Contributor under this License.
Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License.
Legal Entity means the entity making a Contribution and all its Affiliates.
Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, 'control' means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity.
1. Grant of Copyright License
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not.
2. Grant of Patent License
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken.
3. No Trademark License
No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in section 4.
4. Distribution Restriction
You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software.
5. Disclaimer of Warranty and Limitation of Liability
THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT'S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
6. Language
THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL.
END OF THE TERMS AND CONDITIONS
How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software
To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps:
Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner;
Create a file named "LICENSE" which contains the whole context of this License in the first directory of your software package;
Attach the statement to the appropriate annotated syntax at the beginning of each source file.
Copyright (c) [Year] [name of copyright holder]
[Software Name] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.

View File

@@ -1,13 +0,0 @@
[
{
"Name" : "bounds_checking_function",
"License" : "Mulan Permissive Software LicenseVersion 2",
"License File" : "LICENSE",
"Version Number" : "v1.1.10",
"Owner" : "jianghan2@huawei.com",
"PDM Number" : "05835DMT",
"Upstream URL" : "https://gitee.com/openeuler/bounds_checking_function",
"Use Application URL" : "http://pdm.huawei.com/Windchill/hwdispatcher/iris/?status=view&pboid=OR:ext.huawei.huaweipbo.HuaweiPBO:70160914898&virtualid=basicinfo&lang=en",
"Description" : "following the standard of C11 Annex K (bound-checking interfaces), functions of the common memory/string operation classes, such as memcpy_s, strcpy_s, are selected and implemented."
}
]

View File

@@ -1,9 +0,0 @@
# bounds_checking_function
#### Description
- following the standard of C11 Annex K (bound-checking interfaces), functions of the common memory/string operation classes, such as memcpy_s, strcpy_s, are selected and implemented.
- other standard functions in C11 Annex K will be analyzed in the future and implemented in this organization if necessary.
- handles the release, update, and maintenance of bounds_checking_function.

View File

@@ -1,6 +0,0 @@
# bounds_checking_function
#### 介绍
- 遵循C11 Annex K (Bounds-checking interfaces)的标准,选取并实现了常见的内存/字符串操作类的函数如memcpy_s、strcpy_s等函数。
- 未来将分析C11 Annex K中的其他标准函数如果有必要将在该组织中实现。
- 处理边界检查函数的版本发布、更新以及维护。

View File

@@ -1,623 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: The user of this secure c library should include this header file in you source code.
* This header file declare all supported API prototype of the library,
* such as memcpy_s, strcpy_s, wcscpy_s,strcat_s, strncat_s, sprintf_s, scanf_s, and so on.
* Author: lishunda
* Create: 2014-02-25
*/
#ifndef SECUREC_H_5D13A042_DC3F_4ED9_A8D1_882811274C27
#define SECUREC_H_5D13A042_DC3F_4ED9_A8D1_882811274C27
#include "securectype.h"
#ifndef SECUREC_HAVE_STDARG_H
#define SECUREC_HAVE_STDARG_H 1
#endif
#if SECUREC_HAVE_STDARG_H
#include <stdarg.h>
#endif
#ifndef SECUREC_HAVE_ERRNO_H
#define SECUREC_HAVE_ERRNO_H 1
#endif
/* EINVAL ERANGE may defined in errno.h */
#if SECUREC_HAVE_ERRNO_H
#if SECUREC_IN_KERNEL
#include <linux/errno.h>
#else
#include <errno.h>
#endif
#endif
/* Define error code */
#if defined(SECUREC_NEED_ERRNO_TYPE) || !defined(__STDC_WANT_LIB_EXT1__) || \
(defined(__STDC_WANT_LIB_EXT1__) && (!__STDC_WANT_LIB_EXT1__))
#ifndef SECUREC_DEFINED_ERRNO_TYPE
#define SECUREC_DEFINED_ERRNO_TYPE
/* Just check whether macrodefinition exists. */
#ifndef errno_t
typedef int errno_t;
#endif
#endif
#endif
/* Success */
#ifndef EOK
#define EOK 0
#endif
#ifndef EINVAL
/* The src buffer is not correct and destination buffer cant not be reset */
#define EINVAL 22
#endif
#ifndef EINVAL_AND_RESET
/* Once the error is detected, the dest buffer must be reseted! Value is 22 or 128 */
#define EINVAL_AND_RESET 150
#endif
#ifndef ERANGE
/* The destination buffer is not long enough and destination buffer can not be reset */
#define ERANGE 34
#endif
#ifndef ERANGE_AND_RESET
/* Once the error is detected, the dest buffer must be reseted! Value is 34 or 128 */
#define ERANGE_AND_RESET 162
#endif
#ifndef EOVERLAP_AND_RESET
/* Once the buffer overlap is detected, the dest buffer must be reseted! Value is 54 or 128 */
#define EOVERLAP_AND_RESET 182
#endif
/* If you need export the function of this library in Win32 dll, use __declspec(dllexport) */
#ifndef SECUREC_API
#if defined(SECUREC_DLL_EXPORT)
#define SECUREC_API __declspec(dllexport)
#elif defined(SECUREC_DLL_IMPORT)
#define SECUREC_API __declspec(dllimport)
#else
/*
* Standardized function declaration. If a security function is declared in the your code,
* it may cause a compilation alarm,Please delete the security function you declared.
* Adding extern under windows will cause the system to have inline functions to expand,
* so do not add the extern in default
*/
#if defined(_MSC_VER)
#define SECUREC_API
#else
#define SECUREC_API extern
#endif
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if SECUREC_ENABLE_MEMSET
/*
* Description: The memset_s function copies the value of c (converted to an unsigned char) into each of
* the first count characters of the object pointed to by dest.
* Parameter: dest - destination address
* Parameter: destMax - The maximum length of destination buffer
* Parameter: c - the value to be copied
* Parameter: count - copies count bytes of value to dest
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t memset_s(void *dest, size_t destMax, int c, size_t count);
#endif
#ifndef SECUREC_ONLY_DECLARE_MEMSET
#define SECUREC_ONLY_DECLARE_MEMSET 0
#endif
#if !SECUREC_ONLY_DECLARE_MEMSET
#if SECUREC_ENABLE_MEMMOVE
/*
* Description: The memmove_s function copies n characters from the object pointed to by src
* into the object pointed to by dest.
* Parameter: dest - destination address
* Parameter: destMax - The maximum length of destination buffer
* Parameter: src - source address
* Parameter: count - copies count bytes from the src
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count);
#endif
#if SECUREC_ENABLE_MEMCPY
/*
* Description: The memcpy_s function copies n characters from the object pointed to
* by src into the object pointed to by dest.
* Parameter: dest - destination address
* Parameter: destMax - The maximum length of destination buffer
* Parameter: src - source address
* Parameter: count - copies count bytes from the src
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count);
#endif
#if SECUREC_ENABLE_STRCPY
/*
* Description: The strcpy_s function copies the string pointed to by strSrc (including
* the terminating null character) into the array pointed to by strDest
* Parameter: strDest - destination address
* Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
* Parameter: strSrc - source address
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc);
#endif
#if SECUREC_ENABLE_STRNCPY
/*
* Description: The strncpy_s function copies not more than n successive characters (not including
* the terminating null character) from the array pointed to by strSrc to the array pointed to by strDest.
* Parameter: strDest - destination address
* Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
* Parameter: strSrc - source address
* Parameter: count - copies count characters from the src
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, size_t count);
#endif
#if SECUREC_ENABLE_STRCAT
/*
* Description: The strcat_s function appends a copy of the string pointed to by strSrc (including
* the terminating null character) to the end of the string pointed to by strDest.
* Parameter: strDest - destination address
* Parameter: destMax - The maximum length of destination buffer(including the terminating null wide character)
* Parameter: strSrc - source address
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc);
#endif
#if SECUREC_ENABLE_STRNCAT
/*
* Description: The strncat_s function appends not more than n successive characters (not including
* the terminating null character)
* from the array pointed to by strSrc to the end of the string pointed to by strDest.
* Parameter: strDest - destination address
* Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
* Parameter: strSrc - source address
* Parameter: count - copies count characters from the src
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count);
#endif
#if SECUREC_ENABLE_VSPRINTF
/*
* Description: The vsprintf_s function is equivalent to the vsprintf function except for the parameter destMax
* and the explicit runtime-constraints violation
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
* Parameter: destMax - The maximum length of destination buffer(including the terminating null wide characte)
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of characters printed(not including the terminating null byte '\0'),
* If an error occurred Return: -1.
*/
SECUREC_API int vsprintf_s(char *strDest, size_t destMax, const char *format,
va_list argList) SECUREC_ATTRIBUTE(3, 0);
#endif
#if SECUREC_ENABLE_SPRINTF
/*
* Description: The sprintf_s function is equivalent to the sprintf function except for the parameter destMax
* and the explicit runtime-constraints violation
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
* Parameter: format - fromat string
* Return: the number of characters printed(not including the terminating null byte '\0'),
* If an error occurred Return: -1.
*/
SECUREC_API int sprintf_s(char *strDest, size_t destMax, const char *format, ...) SECUREC_ATTRIBUTE(3, 4);
#endif
#if SECUREC_ENABLE_VSNPRINTF
/*
* Description: The vsnprintf_s function is equivalent to the vsnprintf function except for
* the parameter destMax/count and the explicit runtime-constraints violation
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
* Parameter: count - do not write more than count bytes to strDest(not including the terminating null byte '\0')
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of characters printed(not including the terminating null byte '\0'),
* If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs
*/
SECUREC_API int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format,
va_list argList) SECUREC_ATTRIBUTE(4, 0);
#endif
#if SECUREC_ENABLE_SNPRINTF
/*
* Description: The snprintf_s function is equivalent to the snprintf function except for
* the parameter destMax/count and the explicit runtime-constraints violation
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
* Parameter: count - do not write more than count bytes to strDest(not including the terminating null byte '\0')
* Parameter: format - fromat string
* Return: the number of characters printed(not including the terminating null byte '\0'),
* If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs
*/
SECUREC_API int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format,
...) SECUREC_ATTRIBUTE(4, 5);
#endif
#if SECUREC_SNPRINTF_TRUNCATED
/*
* Description: The vsnprintf_truncated_s function is equivalent to the vsnprintf_s function except
* no count parameter and return value
* Parameter: strDest - produce output according to a format ,write to the character string strDest
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of characters printed(not including the terminating null byte '\0'),
* If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs
*/
SECUREC_API int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format,
va_list argList) SECUREC_ATTRIBUTE(3, 0);
/*
* Description: The snprintf_truncated_s function is equivalent to the snprintf_2 function except
* no count parameter and return value
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
* Parameter: format - fromat string
* Return: the number of characters printed(not including the terminating null byte '\0'),
* If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs
*/
SECUREC_API int snprintf_truncated_s(char *strDest, size_t destMax,
const char *format, ...) SECUREC_ATTRIBUTE(3, 4);
#endif
#if SECUREC_ENABLE_SCANF
/*
* Description: The scanf_s function is equivalent to fscanf_s with the argument stdin
* interposed before the arguments to scanf_s
* Parameter: format - fromat string
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int scanf_s(const char *format, ...);
#endif
#if SECUREC_ENABLE_VSCANF
/*
* Description: The vscanf_s function is equivalent to scanf_s, with the variable argument list replaced by argList
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int vscanf_s(const char *format, va_list argList);
#endif
#if SECUREC_ENABLE_SSCANF
/*
* Description: The sscanf_s function is equivalent to fscanf_s, except that input is obtained from a
* string (specified by the argument buffer) rather than from a stream
* Parameter: buffer - read character from buffer
* Parameter: format - fromat string
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int sscanf_s(const char *buffer, const char *format, ...);
#endif
#if SECUREC_ENABLE_VSSCANF
/*
* Description: The vsscanf_s function is equivalent to sscanf_s, with the variable argument list
* replaced by argList
* Parameter: buffer - read character from buffer
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int vsscanf_s(const char *buffer, const char *format, va_list argList);
#endif
#if SECUREC_ENABLE_FSCANF
/*
* Description: The fscanf_s function is equivalent to fscanf except that the c, s, and [ conversion specifiers
* apply to a pair of arguments (unless assignment suppression is indicated by a*)
* Parameter: stream - stdio file stream
* Parameter: format - fromat string
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int fscanf_s(FILE *stream, const char *format, ...);
#endif
#if SECUREC_ENABLE_VFSCANF
/*
* Description: The vfscanf_s function is equivalent to fscanf_s, with the variable argument list
* replaced by argList
* Parameter: stream - stdio file stream
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int vfscanf_s(FILE *stream, const char *format, va_list argList);
#endif
#if SECUREC_ENABLE_STRTOK
/*
* Description: The strtok_s function parses a string into a sequence of strToken,
* replace all characters in strToken string that match to strDelimit set with 0.
* On the first call to strtok_s the string to be parsed should be specified in strToken.
* In each subsequent call that should parse the same string, strToken should be NULL
* Parameter: strToken - the string to be delimited
* Parameter: strDelimit - specifies a set of characters that delimit the tokens in the parsed string
* Parameter: context - is a pointer to a char * variable that is used internally by strtok_s function
* Return: On the first call returns the address of the first non \0 character, otherwise NULL is returned.
* In subsequent calls, the strtoken is set to NULL, and the context set is the same as the previous call,
* return NULL if the *context string length is equal 0, otherwise return *context.
*/
SECUREC_API char *strtok_s(char *strToken, const char *strDelimit, char **context);
#endif
#if SECUREC_ENABLE_GETS && !SECUREC_IN_KERNEL
/*
* Description: The gets_s function reads at most one less than the number of characters specified
* by destMax from the stream pointed to by stdin, into the array pointed to by buffer
* Parameter: buffer - destination address
* Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
* Return: buffer if there was no runtime-constraint violation,If an error occurred Return: NULL.
*/
SECUREC_API char *gets_s(char *buffer, size_t destMax);
#endif
#if SECUREC_ENABLE_WCHAR_FUNC
#if SECUREC_ENABLE_MEMCPY
/*
* Description: The wmemcpy_s function copies n successive wide characters from the object pointed to
* by src into the object pointed to by dest.
* Parameter: dest - destination address
* Parameter: destMax - The maximum length of destination buffer
* Parameter: src - source address
* Parameter: count - copies count wide characters from the src
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count);
#endif
#if SECUREC_ENABLE_MEMMOVE
/*
* Description: The wmemmove_s function copies n successive wide characters from the object
* pointed to by src into the object pointed to by dest.
* Parameter: dest - destination address
* Parameter: destMax - The maximum length of destination buffer
* Parameter: src - source address
* Parameter: count - copies count wide characters from the src
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count);
#endif
#if SECUREC_ENABLE_STRCPY
/*
* Description: The wcscpy_s function copies the wide string pointed to by strSrc (including theterminating
* null wide character) into the array pointed to by strDest
* Parameter: strDest - destination address
* Parameter: destMax - The maximum length of destination buffer
* Parameter: strSrc - source address
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc);
#endif
#if SECUREC_ENABLE_STRNCPY
/*
* Description: The wcsncpy_s function copies not more than n successive wide characters (not including the
* terminating null wide character) from the array pointed to by strSrc to the array pointed to by strDest
* Parameter: strDest - destination address
* Parameter: destMax - The maximum length of destination buffer(including the terminating wide character)
* Parameter: strSrc - source address
* Parameter: count - copies count wide characters from the src
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count);
#endif
#if SECUREC_ENABLE_STRCAT
/*
* Description: The wcscat_s function appends a copy of the wide string pointed to by strSrc (including the
* terminating null wide character) to the end of the wide string pointed to by strDest
* Parameter: strDest - destination address
* Parameter: destMax - The maximum length of destination buffer(including the terminating wide character)
* Parameter: strSrc - source address
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc);
#endif
#if SECUREC_ENABLE_STRNCAT
/*
* Description: The wcsncat_s function appends not more than n successive wide characters (not including the
* terminating null wide character) from the array pointed to by strSrc to the end of the wide string pointed to
* by strDest.
* Parameter: strDest - destination address
* Parameter: destMax - The maximum length of destination buffer(including the terminating wide character)
* Parameter: strSrc - source address
* Parameter: count - copies count wide characters from the src
* Return: EOK if there was no runtime-constraint violation
*/
SECUREC_API errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count);
#endif
#if SECUREC_ENABLE_STRTOK
/*
* Description: The wcstok_s function is the wide-character equivalent of the strtok_s function
* Parameter: strToken - the string to be delimited
* Parameter: strDelimit - specifies a set of characters that delimit the tokens in the parsed string
* Parameter: context - is a pointer to a char * variable that is used internally by strtok_s function
* Return: a pointer to the first character of a token, or a null pointer if there is no token
* or there is a runtime-constraint violation.
*/
SECUREC_API wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context);
#endif
#if SECUREC_ENABLE_VSPRINTF
/*
* Description: The vswprintf_s function is the wide-character equivalent of the vsprintf_s function
* Parameter: strDest - produce output according to a format ,write to the character string strDest
* Parameter: destMax - The maximum length of destination buffer(including the terminating null )
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of characters printed(not including the terminating null wide characte),
* If an error occurred Return: -1.
*/
SECUREC_API int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList);
#endif
#if SECUREC_ENABLE_SPRINTF
/*
* Description: The swprintf_s function is the wide-character equivalent of the sprintf_s function
* Parameter: strDest - produce output according to a format ,write to the character string strDest
* Parameter: destMax - The maximum length of destination buffer(including the terminating null )
* Parameter: format - fromat string
* Return: the number of characters printed(not including the terminating null wide characte),
* If an error occurred Return: -1.
*/
SECUREC_API int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...);
#endif
#if SECUREC_ENABLE_FSCANF
/*
* Description: The fwscanf_s function is the wide-character equivalent of the fscanf_s function
* Parameter: stream - stdio file stream
* Parameter: format - fromat string
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int fwscanf_s(FILE *stream, const wchar_t *format, ...);
#endif
#if SECUREC_ENABLE_VFSCANF
/*
* Description: The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function
* Parameter: stream - stdio file stream
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList);
#endif
#if SECUREC_ENABLE_SCANF
/*
* Description: The wscanf_s function is the wide-character equivalent of the scanf_s function
* Parameter: format - fromat string
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int wscanf_s(const wchar_t *format, ...);
#endif
#if SECUREC_ENABLE_VSCANF
/*
* Description: The vwscanf_s function is the wide-character equivalent of the vscanf_s function
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int vwscanf_s(const wchar_t *format, va_list argList);
#endif
#if SECUREC_ENABLE_SSCANF
/*
* Description: The swscanf_s function is the wide-character equivalent of the sscanf_s function
* Parameter: buffer - read character from buffer
* Parameter: format - fromat string
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...);
#endif
#if SECUREC_ENABLE_VSSCANF
/*
* Description: The vswscanf_s function is the wide-character equivalent of the vsscanf_s function
* Parameter: buffer - read character from buffer
* Parameter: format - fromat string
* Parameter: argList - instead of a variable number of arguments
* Return: the number of input items assigned, If an error occurred Return: -1.
*/
SECUREC_API int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList);
#endif
#endif /* SECUREC_ENABLE_WCHAR_FUNC */
#endif
/* Those functions are used by macro ,must declare hare , also for without function declaration warning */
extern errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, size_t count);
extern errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc);
#if SECUREC_WITH_PERFORMANCE_ADDONS
/* Those functions are used by macro */
extern errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count);
extern errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count);
extern errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src, size_t count);
extern errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src, size_t count);
/* The strcpy_sp is a macro, not a function in performance optimization mode. */
#define strcpy_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \
__builtin_constant_p((src))) ? \
SECUREC_STRCPY_SM((dest), (destMax), (src)) : \
strcpy_s((dest), (destMax), (src)))
/* The strncpy_sp is a macro, not a function in performance optimization mode. */
#define strncpy_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \
__builtin_constant_p((destMax)) && \
__builtin_constant_p((src))) ? \
SECUREC_STRNCPY_SM((dest), (destMax), (src), (count)) : \
strncpy_s((dest), (destMax), (src), (count)))
/* The strcat_sp is a macro, not a function in performance optimization mode. */
#define strcat_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \
__builtin_constant_p((src))) ? \
SECUREC_STRCAT_SM((dest), (destMax), (src)) : \
strcat_s((dest), (destMax), (src)))
/* The strncat_sp is a macro, not a function in performance optimization mode. */
#define strncat_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \
__builtin_constant_p((destMax)) && \
__builtin_constant_p((src))) ? \
SECUREC_STRNCAT_SM((dest), (destMax), (src), (count)) : \
strncat_s((dest), (destMax), (src), (count)))
/* The memcpy_sp is a macro, not a function in performance optimization mode. */
#define memcpy_sp(dest, destMax, src, count) (__builtin_constant_p((count)) ? \
(SECUREC_MEMCPY_SM((dest), (destMax), (src), (count))) : \
(__builtin_constant_p((destMax)) ? \
(((size_t)(destMax) > 0 && \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \
memcpy_sOptTc((dest), (destMax), (src), (count)) : ERANGE) : \
memcpy_sOptAsm((dest), (destMax), (src), (count))))
/* The memset_sp is a macro, not a function in performance optimization mode. */
#define memset_sp(dest, destMax, c, count) (__builtin_constant_p((count)) ? \
(SECUREC_MEMSET_SM((dest), (destMax), (c), (count))) : \
(__builtin_constant_p((destMax)) ? \
(((((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \
memset_sOptTc((dest), (destMax), (c), (count)) : ERANGE) : \
memset_sOptAsm((dest), (destMax), (c), (count))))
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,570 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: Define internal used macro and data type. The marco of SECUREC_ON_64BITS
* will be determined in this header file, which is a switch for part
* of code. Some macro are used to supress warning by MS compiler.
* Author: lishunda
* Create: 2014-02-25
*/
#ifndef SECURECTYPE_H_A7BBB686_AADA_451B_B9F9_44DACDAE18A7
#define SECURECTYPE_H_A7BBB686_AADA_451B_B9F9_44DACDAE18A7
#ifndef SECUREC_USING_STD_SECURE_LIB
#if defined(_MSC_VER) && _MSC_VER >= 1400
#if defined(__STDC_WANT_SECURE_LIB__) && (!__STDC_WANT_SECURE_LIB__)
/* Security functions have been provided since vs2005, default use of system library functions */
#define SECUREC_USING_STD_SECURE_LIB 0
#else
#define SECUREC_USING_STD_SECURE_LIB 1
#endif
#else
#define SECUREC_USING_STD_SECURE_LIB 0
#endif
#endif
/* Compatibility with older Secure C versions, shielding VC symbol redefinition warning */
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && (!SECUREC_USING_STD_SECURE_LIB)
#ifndef SECUREC_DISABLE_CRT_FUNC
#define SECUREC_DISABLE_CRT_FUNC 1
#endif
#ifndef SECUREC_DISABLE_CRT_IMP
#define SECUREC_DISABLE_CRT_IMP 1
#endif
#else /* MSC VER */
#ifndef SECUREC_DISABLE_CRT_FUNC
#define SECUREC_DISABLE_CRT_FUNC 0
#endif
#ifndef SECUREC_DISABLE_CRT_IMP
#define SECUREC_DISABLE_CRT_IMP 0
#endif
#endif
#if SECUREC_DISABLE_CRT_FUNC
#ifdef __STDC_WANT_SECURE_LIB__
#undef __STDC_WANT_SECURE_LIB__
#endif
#define __STDC_WANT_SECURE_LIB__ 0
#endif
#if SECUREC_DISABLE_CRT_IMP
#ifdef _CRTIMP_ALTERNATIVE
#undef _CRTIMP_ALTERNATIVE
#endif
#define _CRTIMP_ALTERNATIVE /* Comment microsoft *_s function */
#endif
/* Compile in kernel under macro control */
#ifndef SECUREC_IN_KERNEL
#ifdef __KERNEL__
#define SECUREC_IN_KERNEL 1
#else
#define SECUREC_IN_KERNEL 0
#endif
#endif
#if SECUREC_IN_KERNEL
#ifndef SECUREC_ENABLE_SCANF_FILE
#define SECUREC_ENABLE_SCANF_FILE 0
#endif
#ifndef SECUREC_ENABLE_WCHAR_FUNC
#define SECUREC_ENABLE_WCHAR_FUNC 0
#endif
#else /* SECUREC_IN_KERNEL */
#ifndef SECUREC_ENABLE_SCANF_FILE
#define SECUREC_ENABLE_SCANF_FILE 1
#endif
#ifndef SECUREC_ENABLE_WCHAR_FUNC
#define SECUREC_ENABLE_WCHAR_FUNC 1
#endif
#endif
/* Default secure function declaration, default declarations for non-standard functions */
#ifndef SECUREC_SNPRINTF_TRUNCATED
#define SECUREC_SNPRINTF_TRUNCATED 1
#endif
#if SECUREC_USING_STD_SECURE_LIB
#if defined(_MSC_VER) && _MSC_VER >= 1400
/* Declare secure functions that are not available in the VS compiler */
#ifndef SECUREC_ENABLE_MEMSET
#define SECUREC_ENABLE_MEMSET 1
#endif
/* VS 2005 have vsnprintf_s function */
#ifndef SECUREC_ENABLE_VSNPRINTF
#define SECUREC_ENABLE_VSNPRINTF 0
#endif
#ifndef SECUREC_ENABLE_SNPRINTF
/* VS 2005 have vsnprintf_s function Adapt the snprintf_s of the security function */
#define snprintf_s _snprintf_s
#define SECUREC_ENABLE_SNPRINTF 0
#endif
/* Before VS 2010 do not have v functions */
#if _MSC_VER <= 1600 || defined(SECUREC_FOR_V_SCANFS)
#ifndef SECUREC_ENABLE_VFSCANF
#define SECUREC_ENABLE_VFSCANF 1
#endif
#ifndef SECUREC_ENABLE_VSCANF
#define SECUREC_ENABLE_VSCANF 1
#endif
#ifndef SECUREC_ENABLE_VSSCANF
#define SECUREC_ENABLE_VSSCANF 1
#endif
#endif
#else /* MSC VER */
#ifndef SECUREC_ENABLE_MEMSET
#define SECUREC_ENABLE_MEMSET 0
#endif
#ifndef SECUREC_ENABLE_SNPRINTF
#define SECUREC_ENABLE_SNPRINTF 0
#endif
#ifndef SECUREC_ENABLE_VSNPRINTF
#define SECUREC_ENABLE_VSNPRINTF 0
#endif
#endif
#ifndef SECUREC_ENABLE_MEMMOVE
#define SECUREC_ENABLE_MEMMOVE 0
#endif
#ifndef SECUREC_ENABLE_MEMCPY
#define SECUREC_ENABLE_MEMCPY 0
#endif
#ifndef SECUREC_ENABLE_STRCPY
#define SECUREC_ENABLE_STRCPY 0
#endif
#ifndef SECUREC_ENABLE_STRNCPY
#define SECUREC_ENABLE_STRNCPY 0
#endif
#ifndef SECUREC_ENABLE_STRCAT
#define SECUREC_ENABLE_STRCAT 0
#endif
#ifndef SECUREC_ENABLE_STRNCAT
#define SECUREC_ENABLE_STRNCAT 0
#endif
#ifndef SECUREC_ENABLE_SPRINTF
#define SECUREC_ENABLE_SPRINTF 0
#endif
#ifndef SECUREC_ENABLE_VSPRINTF
#define SECUREC_ENABLE_VSPRINTF 0
#endif
#ifndef SECUREC_ENABLE_SSCANF
#define SECUREC_ENABLE_SSCANF 0
#endif
#ifndef SECUREC_ENABLE_VSSCANF
#define SECUREC_ENABLE_VSSCANF 0
#endif
#ifndef SECUREC_ENABLE_SCANF
#define SECUREC_ENABLE_SCANF 0
#endif
#ifndef SECUREC_ENABLE_VSCANF
#define SECUREC_ENABLE_VSCANF 0
#endif
#ifndef SECUREC_ENABLE_FSCANF
#define SECUREC_ENABLE_FSCANF 0
#endif
#ifndef SECUREC_ENABLE_VFSCANF
#define SECUREC_ENABLE_VFSCANF 0
#endif
#ifndef SECUREC_ENABLE_STRTOK
#define SECUREC_ENABLE_STRTOK 0
#endif
#ifndef SECUREC_ENABLE_GETS
#define SECUREC_ENABLE_GETS 0
#endif
#else /* SECUREC USE STD SECURE LIB */
#ifndef SECUREC_ENABLE_MEMSET
#define SECUREC_ENABLE_MEMSET 1
#endif
#ifndef SECUREC_ENABLE_MEMMOVE
#define SECUREC_ENABLE_MEMMOVE 1
#endif
#ifndef SECUREC_ENABLE_MEMCPY
#define SECUREC_ENABLE_MEMCPY 1
#endif
#ifndef SECUREC_ENABLE_STRCPY
#define SECUREC_ENABLE_STRCPY 1
#endif
#ifndef SECUREC_ENABLE_STRNCPY
#define SECUREC_ENABLE_STRNCPY 1
#endif
#ifndef SECUREC_ENABLE_STRCAT
#define SECUREC_ENABLE_STRCAT 1
#endif
#ifndef SECUREC_ENABLE_STRNCAT
#define SECUREC_ENABLE_STRNCAT 1
#endif
#ifndef SECUREC_ENABLE_SPRINTF
#define SECUREC_ENABLE_SPRINTF 1
#endif
#ifndef SECUREC_ENABLE_VSPRINTF
#define SECUREC_ENABLE_VSPRINTF 1
#endif
#ifndef SECUREC_ENABLE_SNPRINTF
#define SECUREC_ENABLE_SNPRINTF 1
#endif
#ifndef SECUREC_ENABLE_VSNPRINTF
#define SECUREC_ENABLE_VSNPRINTF 1
#endif
#ifndef SECUREC_ENABLE_SSCANF
#define SECUREC_ENABLE_SSCANF 1
#endif
#ifndef SECUREC_ENABLE_VSSCANF
#define SECUREC_ENABLE_VSSCANF 1
#endif
#ifndef SECUREC_ENABLE_SCANF
#if SECUREC_ENABLE_SCANF_FILE
#define SECUREC_ENABLE_SCANF 1
#else
#define SECUREC_ENABLE_SCANF 0
#endif
#endif
#ifndef SECUREC_ENABLE_VSCANF
#if SECUREC_ENABLE_SCANF_FILE
#define SECUREC_ENABLE_VSCANF 1
#else
#define SECUREC_ENABLE_VSCANF 0
#endif
#endif
#ifndef SECUREC_ENABLE_FSCANF
#if SECUREC_ENABLE_SCANF_FILE
#define SECUREC_ENABLE_FSCANF 1
#else
#define SECUREC_ENABLE_FSCANF 0
#endif
#endif
#ifndef SECUREC_ENABLE_VFSCANF
#if SECUREC_ENABLE_SCANF_FILE
#define SECUREC_ENABLE_VFSCANF 1
#else
#define SECUREC_ENABLE_VFSCANF 0
#endif
#endif
#ifndef SECUREC_ENABLE_STRTOK
#define SECUREC_ENABLE_STRTOK 1
#endif
#ifndef SECUREC_ENABLE_GETS
#define SECUREC_ENABLE_GETS 1
#endif
#endif /* SECUREC_USE_STD_SECURE_LIB */
#if !SECUREC_ENABLE_SCANF_FILE
#if SECUREC_ENABLE_FSCANF
#undef SECUREC_ENABLE_FSCANF
#define SECUREC_ENABLE_FSCANF 0
#endif
#if SECUREC_ENABLE_VFSCANF
#undef SECUREC_ENABLE_VFSCANF
#define SECUREC_ENABLE_VFSCANF 0
#endif
#if SECUREC_ENABLE_SCANF
#undef SECUREC_ENABLE_SCANF
#define SECUREC_ENABLE_SCANF 0
#endif
#if SECUREC_ENABLE_FSCANF
#undef SECUREC_ENABLE_FSCANF
#define SECUREC_ENABLE_FSCANF 0
#endif
#endif
#if SECUREC_IN_KERNEL
#include <linux/kernel.h>
#include <linux/module.h>
#else
#ifndef SECUREC_HAVE_STDIO_H
#define SECUREC_HAVE_STDIO_H 1
#endif
#ifndef SECUREC_HAVE_STRING_H
#define SECUREC_HAVE_STRING_H 1
#endif
#ifndef SECUREC_HAVE_STDLIB_H
#define SECUREC_HAVE_STDLIB_H 1
#endif
#if SECUREC_HAVE_STDIO_H
#include <stdio.h>
#endif
#if SECUREC_HAVE_STRING_H
#include <string.h>
#endif
#if SECUREC_HAVE_STDLIB_H
#include <stdlib.h>
#endif
#endif
/*
* If you need high performance, enable the SECUREC_WITH_PERFORMANCE_ADDONS macro, default is enable.
* The macro is automatically closed on the windows platform and linux kernel
*/
#ifndef SECUREC_WITH_PERFORMANCE_ADDONS
#if SECUREC_IN_KERNEL
#define SECUREC_WITH_PERFORMANCE_ADDONS 0
#else
#define SECUREC_WITH_PERFORMANCE_ADDONS 1
#endif
#endif
/* If enable SECUREC_COMPATIBLE_WIN_FORMAT, the output format will be compatible to Windows. */
#if (defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)) && !defined(SECUREC_COMPATIBLE_LINUX_FORMAT)
#ifndef SECUREC_COMPATIBLE_WIN_FORMAT
#define SECUREC_COMPATIBLE_WIN_FORMAT
#endif
#endif
#if defined(SECUREC_COMPATIBLE_WIN_FORMAT)
/* On windows platform, can't use optimized function for there is no __builtin_constant_p like function */
/* If need optimized macro, can define this: define __builtin_constant_p(x) 0 */
#ifdef SECUREC_WITH_PERFORMANCE_ADDONS
#undef SECUREC_WITH_PERFORMANCE_ADDONS
#define SECUREC_WITH_PERFORMANCE_ADDONS 0
#endif
#endif
#if defined(__VXWORKS__) || defined(__vxworks) || defined(__VXWORKS) || defined(_VXWORKS_PLATFORM_) || \
defined(SECUREC_VXWORKS_VERSION_5_4)
#ifndef SECUREC_VXWORKS_PLATFORM
#define SECUREC_VXWORKS_PLATFORM
#endif
#endif
/* If enable SECUREC_COMPATIBLE_LINUX_FORMAT, the output format will be compatible to Linux. */
#if !defined(SECUREC_COMPATIBLE_WIN_FORMAT) && !defined(SECUREC_VXWORKS_PLATFORM)
#ifndef SECUREC_COMPATIBLE_LINUX_FORMAT
#define SECUREC_COMPATIBLE_LINUX_FORMAT
#endif
#endif
#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT
#ifndef SECUREC_HAVE_STDDEF_H
#define SECUREC_HAVE_STDDEF_H 1
#endif
/* Some system may no stddef.h */
#if SECUREC_HAVE_STDDEF_H
#if !SECUREC_IN_KERNEL
#include <stddef.h>
#endif
#endif
#endif
/*
* Add the -DSECUREC_SUPPORT_FORMAT_WARNING=1 compiler option to supoort -Wformat=2.
* Default does not check the format is that the same data type in the actual code.
* In the product is different in the original data type definition of VxWorks and Linux.
*/
#ifndef SECUREC_SUPPORT_FORMAT_WARNING
#define SECUREC_SUPPORT_FORMAT_WARNING 0
#endif
#if SECUREC_SUPPORT_FORMAT_WARNING
#define SECUREC_ATTRIBUTE(x, y) __attribute__((format(printf, (x), (y))))
#else
#define SECUREC_ATTRIBUTE(x, y)
#endif
/*
* Add the -DSECUREC_SUPPORT_BUILTIN_EXPECT=0 compiler option, if complier can not support __builtin_expect.
*/
#ifndef SECUREC_SUPPORT_BUILTIN_EXPECT
#define SECUREC_SUPPORT_BUILTIN_EXPECT 1
#endif
#if SECUREC_SUPPORT_BUILTIN_EXPECT && defined(__GNUC__) && ((__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3)))
/*
* This is a built-in function that can be used without a declaration, if warning for declaration not found occurred,
* you can add -DSECUREC_NEED_BUILTIN_EXPECT_DECLARE to complier options
*/
#ifdef SECUREC_NEED_BUILTIN_EXPECT_DECLARE
long __builtin_expect(long exp, long c);
#endif
#define SECUREC_LIKELY(x) __builtin_expect(!!(x), 1)
#define SECUREC_UNLIKELY(x) __builtin_expect(!!(x), 0)
#else
#define SECUREC_LIKELY(x) (x)
#define SECUREC_UNLIKELY(x) (x)
#endif
/* Define the max length of the string */
#ifndef SECUREC_STRING_MAX_LEN
#define SECUREC_STRING_MAX_LEN 0x7fffffffUL
#endif
#define SECUREC_WCHAR_STRING_MAX_LEN (SECUREC_STRING_MAX_LEN / sizeof(wchar_t))
/* Add SECUREC_MEM_MAX_LEN for memcpy and memmove */
#ifndef SECUREC_MEM_MAX_LEN
#define SECUREC_MEM_MAX_LEN 0x7fffffffUL
#endif
#define SECUREC_WCHAR_MEM_MAX_LEN (SECUREC_MEM_MAX_LEN / sizeof(wchar_t))
#if SECUREC_STRING_MAX_LEN > 0x7fffffffUL
#error "max string is 2G"
#endif
#if (defined(__GNUC__) && defined(__SIZEOF_POINTER__))
#if (__SIZEOF_POINTER__ != 4) && (__SIZEOF_POINTER__ != 8)
#error "unsupported system"
#endif
#endif
#if defined(_WIN64) || defined(WIN64) || defined(__LP64__) || defined(_LP64)
#define SECUREC_ON_64BITS
#endif
#if (!defined(SECUREC_ON_64BITS) && defined(__GNUC__) && defined(__SIZEOF_POINTER__))
#if __SIZEOF_POINTER__ == 8
#define SECUREC_ON_64BITS
#endif
#endif
#if defined(__SVR4) || defined(__svr4__)
#define SECUREC_ON_SOLARIS
#endif
#if (defined(__hpux) || defined(_AIX) || defined(SECUREC_ON_SOLARIS))
#define SECUREC_ON_UNIX
#endif
/*
* Codes should run under the macro SECUREC_COMPATIBLE_LINUX_FORMAT in unknow system on default,
* and strtold.
* The function strtold is referenced first at ISO9899:1999(C99), and some old compilers can
* not support these functions. Here provides a macro to open these functions:
* SECUREC_SUPPORT_STRTOLD -- If defined, strtold will be used
*/
#ifndef SECUREC_SUPPORT_STRTOLD
#define SECUREC_SUPPORT_STRTOLD 0
#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT))
#if defined(__USE_ISOC99) || \
(defined(_AIX) && defined(_ISOC99_SOURCE)) || \
(defined(__hpux) && defined(__ia64)) || \
(defined(SECUREC_ON_SOLARIS) && (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
defined(_STDC_C99) || defined(__EXTENSIONS__))
#undef SECUREC_SUPPORT_STRTOLD
#define SECUREC_SUPPORT_STRTOLD 1
#endif
#endif
#if ((defined(SECUREC_WRLINUX_BELOW4) || defined(_WRLINUX_BELOW4_)))
#undef SECUREC_SUPPORT_STRTOLD
#define SECUREC_SUPPORT_STRTOLD 0
#endif
#endif
#if SECUREC_WITH_PERFORMANCE_ADDONS
#ifndef SECUREC_TWO_MIN
#define SECUREC_TWO_MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
/* For strncpy_s performance optimization */
#define SECUREC_STRNCPY_SM(dest, destMax, src, count) \
(((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
(SECUREC_TWO_MIN((size_t)(count), strlen(src)) + 1) <= (size_t)(destMax)) ? \
(((size_t)(count) < strlen(src)) ? (memcpy((dest), (src), (count)), *((char *)(dest) + (count)) = '\0', EOK) : \
(memcpy((dest), (src), strlen(src) + 1), EOK)) : (strncpy_error((dest), (destMax), (src), (count))))
#define SECUREC_STRCPY_SM(dest, destMax, src) \
(((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
(strlen(src) + 1) <= (size_t)(destMax)) ? (memcpy((dest), (src), strlen(src) + 1), EOK) : \
(strcpy_error((dest), (destMax), (src))))
/* For strcat_s performance optimization */
#if defined(__GNUC__)
#define SECUREC_STRCAT_SM(dest, destMax, src) ({ \
int catRet_ = EOK; \
if ((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \
char *catTmpDst_ = (char *)(dest); \
size_t catRestSize_ = (destMax); \
while (catRestSize_ > 0 && *catTmpDst_ != '\0') { \
++catTmpDst_; \
--catRestSize_; \
} \
if (catRestSize_ == 0) { \
catRet_ = EINVAL; \
} else if ((strlen(src) + 1) <= catRestSize_) { \
memcpy(catTmpDst_, (src), strlen(src) + 1); \
catRet_ = EOK; \
} else { \
catRet_ = ERANGE; \
} \
if (catRet_ != EOK) { \
catRet_ = strcat_s((dest), (destMax), (src)); \
} \
} else { \
catRet_ = strcat_s((dest), (destMax), (src)); \
} \
catRet_; \
})
#else
#define SECUREC_STRCAT_SM(dest, destMax, src) strcat_s((dest), (destMax), (src))
#endif
/* For strncat_s performance optimization */
#if defined(__GNUC__)
#define SECUREC_STRNCAT_SM(dest, destMax, src, count) ({ \
int ncatRet_ = EOK; \
if ((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
(((unsigned long long)(count) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \
char *ncatTmpDest_ = (char *)(dest); \
size_t ncatRestSize_ = (size_t)(destMax); \
while (ncatRestSize_ > 0 && *ncatTmpDest_ != '\0') { \
++ncatTmpDest_; \
--ncatRestSize_; \
} \
if (ncatRestSize_ == 0) { \
ncatRet_ = EINVAL; \
} else if ((SECUREC_TWO_MIN((count), strlen(src)) + 1) <= ncatRestSize_) { \
if ((size_t)(count) < strlen(src)) { \
memcpy(ncatTmpDest_, (src), (count)); \
*(ncatTmpDest_ + (count)) = '\0'; \
} else { \
memcpy(ncatTmpDest_, (src), strlen(src) + 1); \
} \
} else { \
ncatRet_ = ERANGE; \
} \
if (ncatRet_ != EOK) { \
ncatRet_ = strncat_s((dest), (destMax), (src), (count)); \
} \
} else { \
ncatRet_ = strncat_s((dest), (destMax), (src), (count)); \
} \
ncatRet_; \
})
#else
#define SECUREC_STRNCAT_SM(dest, destMax, src, count) strncat_s((dest), (destMax), (src), (count))
#endif
/* This macro do not check buffer overlap by default */
#define SECUREC_MEMCPY_SM(dest, destMax, src, count) \
(!(((size_t)(destMax) == 0) || \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \
((size_t)(count) > (size_t)(destMax)) || ((void *)(dest)) == NULL || ((void *)(src) == NULL)) ? \
(memcpy((dest), (src), (count)), EOK) : \
(memcpy_s((dest), (destMax), (src), (count))))
#define SECUREC_MEMSET_SM(dest, destMax, c, count) \
(!((((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \
((void *)(dest) == NULL) || ((size_t)(count) > (size_t)(destMax))) ? \
(memset((dest), (c), (count)), EOK) : \
(memset_s((dest), (destMax), (c), (count))))
#endif
#endif

View File

@@ -1,54 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: fscanf_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securec.h"
/*
* <FUNCTION DESCRIPTION>
* The fscanf_s function is equivalent to fscanf except that the c, s,
* and [ conversion specifiers apply to a pair of arguments (unless assignment suppression is indicated by a*)
* The fscanf function reads data from the current position of stream into
* the locations given by argument (if any). Each argument must be a pointer
* to a variable of a type that corresponds to a type specifier in format.
* format controls the interpretation of the input fields and has the same
* form and function as the format argument for scanf.
*
* <INPUT PARAMETERS>
* stream Pointer to FILE structure.
* format Format control string, see Format Specifications.
* ... Optional arguments.
*
* <OUTPUT PARAMETERS>
* ... The convered value stored in user assigned address
*
* <RETURN VALUE>
* Each of these functions returns the number of fields successfully converted
* and assigned; the return value does not include fields that were read but
* not assigned. A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int fscanf_s(FILE *stream, const char *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vfscanf_s(stream, format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: fwscanf_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securec.h"
/*
* <FUNCTION DESCRIPTION>
* The fwscanf_s function is the wide-character equivalent of the fscanf_s function
* The fwscanf_s function reads data from the current position of stream into
* the locations given by argument (if any). Each argument must be a pointer
* to a variable of a type that corresponds to a type specifier in format.
* format controls the interpretation of the input fields and has the same
* form and function as the format argument for scanf.
*
* <INPUT PARAMETERS>
* stream Pointer to FILE structure.
* format Format control string, see Format Specifications.
* ... Optional arguments.
*
* <OUTPUT PARAMETERS>
* ... The converted value stored in user assigned address
*
* <RETURN VALUE>
* Each of these functions returns the number of fields successfully converted
* and assigned; the return value does not include fields that were read but
* not assigned. A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int fwscanf_s(FILE *stream, const wchar_t *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vfwscanf_s(stream, format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}

View File

@@ -1,72 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: gets_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securecutil.h"
/*
* The parameter size is buffer size in byte
*/
SECUREC_INLINE void SecTrimCRLF(char *buffer, size_t size)
{
size_t len = strlen(buffer);
--len; /* Unsigned integer wrapping is accepted and is checked afterwards */
while (len < size && (buffer[len] == '\r' || buffer[len] == '\n')) {
buffer[len] = '\0';
--len; /* Unsigned integer wrapping is accepted and is checked next loop */
}
}
/*
* <FUNCTION DESCRIPTION>
* The gets_s function reads at most one less than the number of characters
* specified by destMax from the std input stream, into the array pointed to by buffer
* The line consists of all characters up to and including
* the first newline character ('\n'). gets_s then replaces the newline
* character with a null character ('\0') before returning the line.
* If the first character read is the end-of-file character, a null character
* is stored at the beginning of buffer and NULL is returned.
*
* <INPUT PARAMETERS>
* buffer Storage location for input string.
* destMax The size of the buffer.
*
* <OUTPUT PARAMETERS>
* buffer is updated
*
* <RETURN VALUE>
* buffer Successful operation
* NULL Improper parameter or read fail
*/
char *gets_s(char *buffer, size_t destMax)
{
#ifdef SECUREC_COMPATIBLE_WIN_FORMAT
size_t bufferSize = ((destMax == (size_t)(-1)) ? SECUREC_STRING_MAX_LEN : destMax);
#else
size_t bufferSize = destMax;
#endif
if (buffer == NULL || bufferSize == 0 || bufferSize > SECUREC_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_PARAMTER("gets_s");
return NULL;
}
if (fgets(buffer, (int)bufferSize, SECUREC_STREAM_STDIN) != NULL) {
SecTrimCRLF(buffer, bufferSize);
return buffer;
}
return NULL;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,564 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: memcpy_s function
* Author: lishunda
* Create: 2014-02-25
*/
/*
* [Standardize-exceptions] Use unsafe function: Portability
* [reason] Use unsafe function to implement security function to maintain platform compatibility.
* And sufficient input validation is performed before calling
*/
#include "securecutil.h"
#ifndef SECUREC_MEMCOPY_WITH_PERFORMANCE
#define SECUREC_MEMCOPY_WITH_PERFORMANCE 0
#endif
#if SECUREC_WITH_PERFORMANCE_ADDONS || SECUREC_MEMCOPY_WITH_PERFORMANCE
#ifndef SECUREC_MEMCOPY_THRESHOLD_SIZE
#define SECUREC_MEMCOPY_THRESHOLD_SIZE 64UL
#endif
#define SECUREC_SMALL_MEM_COPY(dest, src, count) do { \
if (SECUREC_ADDR_ALIGNED_8(dest) && SECUREC_ADDR_ALIGNED_8(src)) { \
/* Use struct assignment */ \
switch (count) { \
case 1: \
*(unsigned char *)(dest) = *(const unsigned char *)(src); \
break; \
case 2: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 2); \
break; \
case 3: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 3); \
break; \
case 4: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 4); \
break; \
case 5: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 5); \
break; \
case 6: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 6); \
break; \
case 7: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 7); \
break; \
case 8: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 8); \
break; \
case 9: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 9); \
break; \
case 10: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 10); \
break; \
case 11: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 11); \
break; \
case 12: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 12); \
break; \
case 13: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 13); \
break; \
case 14: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 14); \
break; \
case 15: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 15); \
break; \
case 16: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 16); \
break; \
case 17: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 17); \
break; \
case 18: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 18); \
break; \
case 19: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 19); \
break; \
case 20: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 20); \
break; \
case 21: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 21); \
break; \
case 22: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 22); \
break; \
case 23: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 23); \
break; \
case 24: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 24); \
break; \
case 25: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 25); \
break; \
case 26: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 26); \
break; \
case 27: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 27); \
break; \
case 28: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 28); \
break; \
case 29: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 29); \
break; \
case 30: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 30); \
break; \
case 31: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 31); \
break; \
case 32: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 32); \
break; \
case 33: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 33); \
break; \
case 34: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 34); \
break; \
case 35: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 35); \
break; \
case 36: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 36); \
break; \
case 37: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 37); \
break; \
case 38: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 38); \
break; \
case 39: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 39); \
break; \
case 40: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 40); \
break; \
case 41: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 41); \
break; \
case 42: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 42); \
break; \
case 43: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 43); \
break; \
case 44: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 44); \
break; \
case 45: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 45); \
break; \
case 46: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 46); \
break; \
case 47: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 47); \
break; \
case 48: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 48); \
break; \
case 49: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 49); \
break; \
case 50: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 50); \
break; \
case 51: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 51); \
break; \
case 52: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 52); \
break; \
case 53: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 53); \
break; \
case 54: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 54); \
break; \
case 55: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 55); \
break; \
case 56: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 56); \
break; \
case 57: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 57); \
break; \
case 58: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 58); \
break; \
case 59: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 59); \
break; \
case 60: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 60); \
break; \
case 61: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 61); \
break; \
case 62: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 62); \
break; \
case 63: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 63); \
break; \
case 64: \
SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 64); \
break; \
default: \
/* Do nothing */ \
break; \
} /* END switch */ \
} else { \
unsigned char *tmpDest_ = (unsigned char *)(dest); \
const unsigned char *tmpSrc_ = (const unsigned char *)(src); \
switch (count) { \
case 64: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 63: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 62: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 61: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 60: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 59: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 58: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 57: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 56: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 55: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 54: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 53: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 52: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 51: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 50: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 49: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 48: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 47: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 46: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 45: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 44: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 43: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 42: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 41: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 40: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 39: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 38: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 37: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 36: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 35: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 34: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 33: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 32: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 31: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 30: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 29: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 28: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 27: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 26: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 25: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 24: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 23: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 22: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 21: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 20: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 19: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 18: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 17: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 16: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 15: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 14: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 13: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 12: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 11: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 10: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 9: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 8: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 7: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 6: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 5: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 4: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 3: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 2: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 1: \
*(tmpDest_++) = *(tmpSrc_++); \
/* fall-through */ /* FALLTHRU */ \
default: \
/* Do nothing */ \
break; \
} \
} \
} SECUREC_WHILE_ZERO
/*
* Performance optimization
*/
#define SECUREC_MEMCPY_OPT(dest, src, count) do { \
if ((count) > SECUREC_MEMCOPY_THRESHOLD_SIZE) { \
SECUREC_MEMCPY_WARP_OPT((dest), (src), (count)); \
} else { \
SECUREC_SMALL_MEM_COPY((dest), (src), (count)); \
} \
} SECUREC_WHILE_ZERO
#endif
/*
* Handling errors
*/
SECUREC_INLINE errno_t SecMemcpyError(void *dest, size_t destMax, const void *src, size_t count)
{
if (destMax == 0 || destMax > SECUREC_MEM_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("memcpy_s");
return ERANGE;
}
if (dest == NULL || src == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("memcpy_s");
if (dest != NULL) {
(void)memset(dest, 0, destMax);
return EINVAL_AND_RESET;
}
return EINVAL;
}
if (count > destMax) {
(void)memset(dest, 0, destMax);
SECUREC_ERROR_INVALID_RANGE("memcpy_s");
return ERANGE_AND_RESET;
}
if (SECUREC_MEMORY_IS_OVERLAP(dest, src, count)) {
(void)memset(dest, 0, destMax);
SECUREC_ERROR_BUFFER_OVERLAP("memcpy_s");
return EOVERLAP_AND_RESET;
}
/* Count is 0 or dest equal src also ret EOK */
return EOK;
}
#if defined(SECUREC_COMPATIBLE_WIN_FORMAT)
/*
* The fread API in windows will call memcpy_s and pass 0xffffffff to destMax.
* To avoid the failure of fread, we don't check desMax limit.
*/
#define SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count) (SECUREC_LIKELY((count) <= (destMax) && \
(dest) != NULL && (src) != NULL && \
(count) > 0 && SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count))))
#else
#define SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count) (SECUREC_LIKELY((count) <= (destMax) && \
(dest) != NULL && (src) != NULL && (destMax) <= SECUREC_MEM_MAX_LEN && \
(count) > 0 && SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count))))
#endif
/*
* <FUNCTION DESCRIPTION>
* The memcpy_s function copies n characters from the object pointed to by src into the object pointed to by dest
*
* <INPUT PARAMETERS>
* dest Destination buffer.
* destMax Size of the destination buffer.
* src Buffer to copy from.
* count Number of characters to copy
*
* <OUTPUT PARAMETERS>
* dest buffer is updated.
*
* <RETURN VALUE>
* EOK Success
* EINVAL dest is NULL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
* EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
* ERANGE destMax > SECUREC_MEM_MAX_LEN or destMax is 0
* ERANGE_AND_RESET count > destMax and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
* and dest != NULL and src != NULL
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and
* count <= destMax destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN and dest != NULL
* and src != NULL and dest != src
*
* if an error occured, dest will be filled with 0.
* If the source and destination overlap, the behavior of memcpy_s is undefined.
* Use memmove_s to handle overlapping regions.
*/
errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count)
{
if (SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count)) {
#if SECUREC_MEMCOPY_WITH_PERFORMANCE
SECUREC_MEMCPY_OPT(dest, src, count);
#else
SECUREC_MEMCPY_WARP_OPT(dest, src, count);
#endif
return EOK;
}
/* Meet some runtime violation, return error code */
return SecMemcpyError(dest, destMax, src, count);
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(memcpy_s);
#endif
#if SECUREC_WITH_PERFORMANCE_ADDONS
/*
* Performance optimization
*/
errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src, size_t count)
{
if (SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count)) {
SECUREC_MEMCPY_OPT(dest, src, count);
return EOK;
}
/* Meet some runtime violation, return error code */
return SecMemcpyError(dest, destMax, src, count);
}
/* Trim judgement on "destMax <= SECUREC_MEM_MAX_LEN" */
errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src, size_t count)
{
if (SECUREC_LIKELY(count <= destMax && dest != NULL && src != NULL && \
count > 0 && SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count)))) {
SECUREC_MEMCPY_OPT(dest, src, count);
return EOK;
}
/* Meet some runtime violation, return error code */
return SecMemcpyError(dest, destMax, src, count);
}
#endif

View File

@@ -1,119 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: memmove_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securecutil.h"
#ifdef SECUREC_NOT_CALL_LIBC_CORE_API
/*
* Implementing memory data movement
*/
SECUREC_INLINE void SecUtilMemmove(void *dst, const void *src, size_t count)
{
unsigned char *pDest = (unsigned char *)dst;
const unsigned char *pSrc = (const unsigned char *)src;
size_t maxCount = count;
if (dst <= src || pDest >= (pSrc + maxCount)) {
/*
* Non-Overlapping Buffers
* Copy from lower addresses to higher addresses
*/
while (maxCount > 0) {
--maxCount;
*pDest = *pSrc;
++pDest;
++pSrc;
}
} else {
/*
* Overlapping Buffers
* Copy from higher addresses to lower addresses
*/
pDest = pDest + maxCount - 1;
pSrc = pSrc + maxCount - 1;
while (maxCount > 0) {
--maxCount;
*pDest = *pSrc;
--pDest;
--pSrc;
}
}
}
#endif
/*
* <FUNCTION DESCRIPTION>
* The memmove_s function copies count bytes of characters from src to dest.
* This function can be assigned correctly when memory overlaps.
* <INPUT PARAMETERS>
* dest Destination object.
* destMax Size of the destination buffer.
* src Source object.
* count Number of characters to copy.
*
* <OUTPUT PARAMETERS>
* dest buffer is uptdated.
*
* <RETURN VALUE>
* EOK Success
* EINVAL dest is NULL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
* EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
* ERANGE destMax > SECUREC_MEM_MAX_LEN or destMax is 0
* ERANGE_AND_RESET count > destMax and dest != NULL and src != NULL and destMax != 0
* and destMax <= SECUREC_MEM_MAX_LEN
*
* If an error occured, dest will be filled with 0 when dest and destMax valid.
* If some regions of the source area and the destination overlap, memmove_s
* ensures that the original source bytes in the overlapping region are copied
* before being overwritten.
*/
errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count)
{
if (destMax == 0 || destMax > SECUREC_MEM_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("memmove_s");
return ERANGE;
}
if (dest == NULL || src == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("memmove_s");
if (dest != NULL) {
(void)memset(dest, 0, destMax);
return EINVAL_AND_RESET;
}
return EINVAL;
}
if (count > destMax) {
(void)memset(dest, 0, destMax);
SECUREC_ERROR_INVALID_RANGE("memmove_s");
return ERANGE_AND_RESET;
}
if (dest == src) {
return EOK;
}
if (count > 0) {
#ifdef SECUREC_NOT_CALL_LIBC_CORE_API
SecUtilMemmove(dest, src, count);
#else
/* Use underlying memmove for performance consideration */
(void)memmove(dest, src, count);
#endif
}
return EOK;
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(memmove_s);
#endif

View File

@@ -1,509 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: memset_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securecutil.h"
#define SECUREC_MEMSET_PARAM_OK(dest, destMax, count) (SECUREC_LIKELY((destMax) <= SECUREC_MEM_MAX_LEN && \
(dest) != NULL && (count) <= (destMax)))
#if SECUREC_WITH_PERFORMANCE_ADDONS
/* Use union to clear strict-aliasing warning */
typedef union {
SecStrBuf32 buf32;
SecStrBuf31 buf31;
SecStrBuf30 buf30;
SecStrBuf29 buf29;
SecStrBuf28 buf28;
SecStrBuf27 buf27;
SecStrBuf26 buf26;
SecStrBuf25 buf25;
SecStrBuf24 buf24;
SecStrBuf23 buf23;
SecStrBuf22 buf22;
SecStrBuf21 buf21;
SecStrBuf20 buf20;
SecStrBuf19 buf19;
SecStrBuf18 buf18;
SecStrBuf17 buf17;
SecStrBuf16 buf16;
SecStrBuf15 buf15;
SecStrBuf14 buf14;
SecStrBuf13 buf13;
SecStrBuf12 buf12;
SecStrBuf11 buf11;
SecStrBuf10 buf10;
SecStrBuf9 buf9;
SecStrBuf8 buf8;
SecStrBuf7 buf7;
SecStrBuf6 buf6;
SecStrBuf5 buf5;
SecStrBuf4 buf4;
SecStrBuf3 buf3;
SecStrBuf2 buf2;
} SecStrBuf32Union;
/* C standard initializes the first member of the consortium. */
static const SecStrBuf32 g_allZero = {{
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
}};
static const SecStrBuf32 g_allFF = {{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
}};
/* Clear coversion warning strict aliasing" */
SECUREC_INLINE const SecStrBuf32Union *SecStrictAliasingCast(const SecStrBuf32 *buf)
{
return (const SecStrBuf32Union *)buf;
}
#ifndef SECUREC_MEMSET_THRESHOLD_SIZE
#define SECUREC_MEMSET_THRESHOLD_SIZE 32UL
#endif
#define SECUREC_UNALIGNED_SET(dest, c, count) do { \
unsigned char *pDest_ = (unsigned char *)(dest); \
switch (count) { \
case 32: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 31: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 30: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 29: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 28: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 27: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 26: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 25: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 24: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 23: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 22: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 21: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 20: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 19: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 18: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 17: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 16: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 15: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 14: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 13: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 12: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 11: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 10: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 9: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 8: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 7: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 6: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 5: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 4: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 3: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 2: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
case 1: \
*(pDest_++) = (unsigned char)(c); \
/* fall-through */ /* FALLTHRU */ \
default: \
/* Do nothing */ \
break; \
} \
} SECUREC_WHILE_ZERO
#define SECUREC_SET_VALUE_BY_STRUCT(dest, dataName, n) do { \
*(SecStrBuf##n *)(dest) = *(const SecStrBuf##n *)(&((SecStrictAliasingCast(&(dataName)))->buf##n)); \
} SECUREC_WHILE_ZERO
#define SECUREC_ALIGNED_SET_OPT_ZERO_FF(dest, c, count) do { \
switch (c) { \
case 0: \
switch (count) { \
case 1: \
*(unsigned char *)(dest) = (unsigned char)0; \
break; \
case 2: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 2); \
break; \
case 3: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 3); \
break; \
case 4: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 4); \
break; \
case 5: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 5); \
break; \
case 6: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 6); \
break; \
case 7: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 7); \
break; \
case 8: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 8); \
break; \
case 9: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 9); \
break; \
case 10: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 10); \
break; \
case 11: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 11); \
break; \
case 12: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 12); \
break; \
case 13: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 13); \
break; \
case 14: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 14); \
break; \
case 15: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 15); \
break; \
case 16: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 16); \
break; \
case 17: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 17); \
break; \
case 18: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 18); \
break; \
case 19: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 19); \
break; \
case 20: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 20); \
break; \
case 21: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 21); \
break; \
case 22: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 22); \
break; \
case 23: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 23); \
break; \
case 24: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 24); \
break; \
case 25: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 25); \
break; \
case 26: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 26); \
break; \
case 27: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 27); \
break; \
case 28: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 28); \
break; \
case 29: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 29); \
break; \
case 30: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 30); \
break; \
case 31: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 31); \
break; \
case 32: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 32); \
break; \
default: \
/* Do nothing */ \
break; \
} \
break; \
case 0xFF: \
switch (count) { \
case 1: \
*(unsigned char *)(dest) = (unsigned char)0xffU; \
break; \
case 2: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 2); \
break; \
case 3: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 3); \
break; \
case 4: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 4); \
break; \
case 5: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 5); \
break; \
case 6: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 6); \
break; \
case 7: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 7); \
break; \
case 8: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 8); \
break; \
case 9: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 9); \
break; \
case 10: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 10); \
break; \
case 11: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 11); \
break; \
case 12: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 12); \
break; \
case 13: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 13); \
break; \
case 14: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 14); \
break; \
case 15: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 15); \
break; \
case 16: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 16); \
break; \
case 17: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 17); \
break; \
case 18: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 18); \
break; \
case 19: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 19); \
break; \
case 20: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 20); \
break; \
case 21: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 21); \
break; \
case 22: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 22); \
break; \
case 23: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 23); \
break; \
case 24: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 24); \
break; \
case 25: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 25); \
break; \
case 26: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 26); \
break; \
case 27: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 27); \
break; \
case 28: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 28); \
break; \
case 29: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 29); \
break; \
case 30: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 30); \
break; \
case 31: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 31); \
break; \
case 32: \
SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 32); \
break; \
default: \
/* Do nothing */ \
break; \
} \
break; \
default: \
SECUREC_UNALIGNED_SET((dest), (c), (count)); \
break; \
} /* END switch */ \
} SECUREC_WHILE_ZERO
#define SECUREC_SMALL_MEM_SET(dest, c, count) do { \
if (SECUREC_ADDR_ALIGNED_8((dest))) { \
SECUREC_ALIGNED_SET_OPT_ZERO_FF((dest), (c), (count)); \
} else { \
SECUREC_UNALIGNED_SET((dest), (c), (count)); \
} \
} SECUREC_WHILE_ZERO
/*
* Performance optimization
*/
#define SECUREC_MEMSET_OPT(dest, c, count) do { \
if ((count) > SECUREC_MEMSET_THRESHOLD_SIZE) { \
SECUREC_MEMSET_WARP_OPT((dest), (c), (count)); \
} else { \
SECUREC_SMALL_MEM_SET((dest), (c), (count)); \
} \
} SECUREC_WHILE_ZERO
#endif
/*
* Handling errors
*/
SECUREC_INLINE errno_t SecMemsetError(void *dest, size_t destMax, int c, size_t count)
{
/* Check destMax is 0 compatible with _sp macro */
if (destMax == 0 || destMax > SECUREC_MEM_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("memset_s");
return ERANGE;
}
if (dest == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("memset_s");
return EINVAL;
}
if (count > destMax) {
(void)memset(dest, c, destMax); /* Set entire buffer to value c */
SECUREC_ERROR_INVALID_RANGE("memset_s");
return ERANGE_AND_RESET;
}
return EOK;
}
/*
* <FUNCTION DESCRIPTION>
* The memset_s function copies the value of c (converted to an unsigned char)
* into each of the first count characters of the object pointed to by dest.
*
* <INPUT PARAMETERS>
* dest Pointer to destination.
* destMax The size of the buffer.
* c Character to set.
* count Number of characters.
*
* <OUTPUT PARAMETERS>
* dest buffer is uptdated.
*
* <RETURN VALUE>
* EOK Success
* EINVAL dest == NULL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
* ERANGE destMax > SECUREC_MEM_MAX_LEN or (destMax is 0 and count > destMax)
* ERANGE_AND_RESET count > destMax and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN and dest != NULL
*
* if return ERANGE_AND_RESET then fill dest to c ,fill length is destMax
*/
errno_t memset_s(void *dest, size_t destMax, int c, size_t count)
{
if (SECUREC_MEMSET_PARAM_OK(dest, destMax, count)) {
SECUREC_MEMSET_WARP_OPT(dest, c, count);
return EOK;
}
/* Meet some runtime violation, return error code */
return SecMemsetError(dest, destMax, c, count);
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(memset_s);
#endif
#if SECUREC_WITH_PERFORMANCE_ADDONS
/*
* Performance optimization
*/
errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count)
{
if (SECUREC_MEMSET_PARAM_OK(dest, destMax, count)) {
SECUREC_MEMSET_OPT(dest, c, count);
return EOK;
}
/* Meet some runtime violation, return error code */
return SecMemsetError(dest, destMax, c, count);
}
/*
* Performance optimization, trim judgement on "destMax <= SECUREC_MEM_MAX_LEN"
*/
errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count)
{
if (SECUREC_LIKELY(count <= destMax && dest != NULL)) {
SECUREC_MEMSET_OPT(dest, c, count);
return EOK;
}
/* Meet some runtime violation, return error code */
return SecMemsetError(dest, destMax, c, count);
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,52 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: scanf_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securec.h"
/*
* <FUNCTION DESCRIPTION>
* The scanf_s function is equivalent to fscanf_s with the argument stdin interposed before the arguments to scanf_s
* The scanf_s function reads data from the standard input stream stdin and
* writes the data into the location that's given by argument. Each argument
* must be a pointer to a variable of a type that corresponds to a type specifier
* in format. If copying occurs between strings that overlap, the behavior is
* undefined.
*
* <INPUT PARAMETERS>
* format Format control string.
* ... Optional arguments.
*
* <OUTPUT PARAMETERS>
* ... The converted value stored in user assigned address
*
* <RETURN VALUE>
* Returns the number of fields successfully converted and assigned;
* the return value does not include fields that were read but not assigned.
* A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int scanf_s(const char *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vscanf_s(format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}

View File

@@ -1,194 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: Define macro, data struct, and declare function prototype,
* which is used by input.inl, secureinput_a.c and secureinput_w.c.
* Author: lishunda
* Create: 2014-02-25
*/
#ifndef SEC_INPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C
#define SEC_INPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C
#include "securecutil.h"
#define SECUREC_SCANF_EINVAL (-1)
#define SECUREC_SCANF_ERROR_PARA (-2)
/* For internal stream flag */
#define SECUREC_MEM_STR_FLAG 0x01U
#define SECUREC_FILE_STREAM_FLAG 0x02U
#define SECUREC_PIPE_STREAM_FLAG 0x04U
#define SECUREC_LOAD_FILE_TO_MEM_FLAG 0x08U
#define SECUREC_UCS_BOM_HEADER_SIZE 2U
#define SECUREC_UCS_BOM_HEADER_BE_1ST 0xfeU
#define SECUREC_UCS_BOM_HEADER_BE_2ST 0xffU
#define SECUREC_UCS_BOM_HEADER_LE_1ST 0xffU
#define SECUREC_UCS_BOM_HEADER_LE_2ST 0xfeU
#define SECUREC_UTF8_BOM_HEADER_SIZE 3U
#define SECUREC_UTF8_BOM_HEADER_1ST 0xefU
#define SECUREC_UTF8_BOM_HEADER_2ND 0xbbU
#define SECUREC_UTF8_BOM_HEADER_3RD 0xbfU
#define SECUREC_UTF8_LEAD_1ST 0xe0U
#define SECUREC_UTF8_LEAD_2ND 0x80U
#define SECUREC_BEGIN_WITH_UCS_BOM(s, len) ((len) >= SECUREC_UCS_BOM_HEADER_SIZE && \
(((unsigned char)((s)[0]) == SECUREC_UCS_BOM_HEADER_LE_1ST && \
(unsigned char)((s)[1]) == SECUREC_UCS_BOM_HEADER_LE_2ST) || \
((unsigned char)((s)[0]) == SECUREC_UCS_BOM_HEADER_BE_1ST && \
(unsigned char)((s)[1]) == SECUREC_UCS_BOM_HEADER_BE_2ST)))
#define SECUREC_BEGIN_WITH_UTF8_BOM(s, len) ((len) >= SECUREC_UTF8_BOM_HEADER_SIZE && \
(unsigned char)((s)[0]) == SECUREC_UTF8_BOM_HEADER_1ST && \
(unsigned char)((s)[1]) == SECUREC_UTF8_BOM_HEADER_2ND && \
(unsigned char)((s)[2]) == SECUREC_UTF8_BOM_HEADER_3RD)
#ifdef SECUREC_FOR_WCHAR
#define SECUREC_BOM_HEADER_SIZE SECUREC_UCS_BOM_HEADER_SIZE
#define SECUREC_BEGIN_WITH_BOM(s, len) SECUREC_BEGIN_WITH_UCS_BOM((s), (len))
#else
#define SECUREC_BOM_HEADER_SIZE SECUREC_UTF8_BOM_HEADER_SIZE
#define SECUREC_BEGIN_WITH_BOM(s, len) SECUREC_BEGIN_WITH_UTF8_BOM((s), (len))
#endif
typedef struct {
unsigned int flag; /* Mark the properties of input stream */
char *base; /* The pointer to the header of buffered string */
const char *cur; /* The pointer to next read position */
size_t count; /* The size of buffered string in bytes */
#if SECUREC_ENABLE_SCANF_FILE
FILE *pf; /* The file pointer */
size_t fileRealRead;
long oriFilePos; /* The original position of file offset when fscanf is called */
#if !SECUREC_USE_STD_UNGETC
unsigned int lastChar; /* The char code of last input */
int fUnGet; /* The boolean flag of pushing a char back to read stream */
#endif
#endif
} SecFileStream;
#if SECUREC_ENABLE_SCANF_FILE && !SECUREC_USE_STD_UNGETC
#define SECUREC_FILE_STREAM_INIT_FILE(stream, fp) do { \
(stream)->pf = (fp); \
(stream)->fileRealRead = 0; \
(stream)->oriFilePos = 0; \
(stream)->lastChar = 0; \
(stream)->fUnGet = 0; \
} SECUREC_WHILE_ZERO
#elif SECUREC_ENABLE_SCANF_FILE && SECUREC_USE_STD_UNGETC
#define SECUREC_FILE_STREAM_INIT_FILE(stream, fp) do { \
(stream)->pf = (fp); \
(stream)->fileRealRead = 0; \
(stream)->oriFilePos = 0; \
} SECUREC_WHILE_ZERO
#else
/* Disable file */
#define SECUREC_FILE_STREAM_INIT_FILE(stream, fp)
#endif
/* This initialization for eliminating redundant initialization. */
#define SECUREC_FILE_STREAM_FROM_STRING(stream, buf, cnt) do { \
(stream)->flag = SECUREC_MEM_STR_FLAG; \
(stream)->base = NULL; \
(stream)->cur = (buf); \
(stream)->count = (cnt); \
SECUREC_FILE_STREAM_INIT_FILE((stream), NULL); \
} SECUREC_WHILE_ZERO
/* This initialization for eliminating redundant initialization. */
#define SECUREC_FILE_STREAM_FROM_FILE(stream, fp) do { \
(stream)->flag = SECUREC_FILE_STREAM_FLAG; \
(stream)->base = NULL; \
(stream)->cur = NULL; \
(stream)->count = 0; \
SECUREC_FILE_STREAM_INIT_FILE((stream), (fp)); \
} SECUREC_WHILE_ZERO
/* This initialization for eliminating redundant initialization. */
#define SECUREC_FILE_STREAM_FROM_STDIN(stream) do { \
(stream)->flag = SECUREC_PIPE_STREAM_FLAG; \
(stream)->base = NULL; \
(stream)->cur = NULL; \
(stream)->count = 0; \
SECUREC_FILE_STREAM_INIT_FILE((stream), SECUREC_STREAM_STDIN); \
} SECUREC_WHILE_ZERO
#ifdef __cplusplus
extern "C" {
#endif
int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList);
void SecClearDestBuf(const char *buffer, const char *format, va_list argList);
#ifdef SECUREC_FOR_WCHAR
int SecInputSW(SecFileStream *stream, const wchar_t *cFormat, va_list argList);
void SecClearDestBufW(const wchar_t *buffer, const wchar_t *format, va_list argList);
#endif
/* 20150105 For software and hardware decoupling,such as UMG */
#ifdef SECUREC_SYSAPI4VXWORKS
#ifdef feof
#undef feof
#endif
extern int feof(FILE *stream);
#endif
#if defined(SECUREC_SYSAPI4VXWORKS) || defined(SECUREC_CTYPE_MACRO_ADAPT)
#ifndef isspace
#define isspace(c) (((c) == ' ') || ((c) == '\t') || ((c) == '\r') || ((c) == '\n'))
#endif
#ifndef iswspace
#define iswspace(c) (((c) == L' ') || ((c) == L'\t') || ((c) == L'\r') || ((c) == L'\n'))
#endif
#ifndef isascii
#define isascii(c) (((unsigned char)(c)) <= 0x7f)
#endif
#ifndef isupper
#define isupper(c) ((c) >= 'A' && (c) <= 'Z')
#endif
#ifndef islower
#define islower(c) ((c) >= 'a' && (c) <= 'z')
#endif
#ifndef isalpha
#define isalpha(c) (isupper(c) || (islower(c)))
#endif
#ifndef isdigit
#define isdigit(c) ((c) >= '0' && (c) <= '9')
#endif
#ifndef isxupper
#define isxupper(c) ((c) >= 'A' && (c) <= 'F')
#endif
#ifndef isxlower
#define isxlower(c) ((c) >= 'a' && (c) <= 'f')
#endif
#ifndef isxdigit
#define isxdigit(c) (isdigit(c) || isxupper(c) || isxlower(c))
#endif
#endif
#ifdef __cplusplus
}
#endif
/* Reserved file operation macro interface, s is FILE *, i is fileno zero. */
#ifndef SECUREC_LOCK_FILE
#define SECUREC_LOCK_FILE(s)
#endif
#ifndef SECUREC_UNLOCK_FILE
#define SECUREC_UNLOCK_FILE(s)
#endif
#ifndef SECUREC_LOCK_STDIN
#define SECUREC_LOCK_STDIN(i, s)
#endif
#ifndef SECUREC_UNLOCK_STDIN
#define SECUREC_UNLOCK_STDIN(i, s)
#endif
#endif

View File

@@ -1,43 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: Provides internal functions used by this library, such as memory
* copy and memory move. Besides, include some helper function for
* printf family API, such as SecVsnprintfImpl
* Author: lishunda
* Create: 2014-02-25
*/
/* Avoid duplicate header files,not include securecutil.h */
#include "securecutil.h"
#if defined(ANDROID) && (SECUREC_HAVE_WCTOMB || SECUREC_HAVE_MBTOWC)
#include <wchar.h>
#if SECUREC_HAVE_WCTOMB
/*
* Convert wide characters to narrow multi-bytes
*/
int wctomb(char *s, wchar_t wc)
{
return wcrtomb(s, wc, NULL);
}
#endif
#if SECUREC_HAVE_MBTOWC
/*
* Converting narrow multi-byte characters to wide characters
*/
int mbtowc(wchar_t *pwc, const char *s, size_t n)
{
return mbrtowc(pwc, s, n, NULL);
}
#endif
#endif

View File

@@ -1,559 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: Define macro, data struct, and declare internal used function prototype,
* which is used by secure functions.
* Author: lishunda
* Create: 2014-02-25
*/
#ifndef SECURECUTIL_H_46C86578_F8FF_4E49_8E64_9B175241761F
#define SECURECUTIL_H_46C86578_F8FF_4E49_8E64_9B175241761F
#include "securec.h"
#if (defined(_MSC_VER)) && (_MSC_VER >= 1400)
/* Shield compilation alerts using discarded functions and Constant expression to maximize code compatibility */
#define SECUREC_MASK_MSVC_CRT_WARNING __pragma(warning(push)) \
__pragma(warning(disable : 4996 4127))
#define SECUREC_END_MASK_MSVC_CRT_WARNING __pragma(warning(pop))
#else
#define SECUREC_MASK_MSVC_CRT_WARNING
#define SECUREC_END_MASK_MSVC_CRT_WARNING
#endif
#define SECUREC_WHILE_ZERO SECUREC_MASK_MSVC_CRT_WARNING while (0) SECUREC_END_MASK_MSVC_CRT_WARNING
/* Automatically identify the platform that supports strnlen function, and use this function to improve performance */
#ifndef SECUREC_HAVE_STRNLEN
#if (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 700) || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L)
#if SECUREC_IN_KERNEL
#define SECUREC_HAVE_STRNLEN 0
#else
#if defined(__GLIBC__) && __GLIBC__ >= 2 && defined(__GLIBC_MINOR__) && __GLIBC_MINOR__ >= 10
#define SECUREC_HAVE_STRNLEN 1
#else
#define SECUREC_HAVE_STRNLEN 0
#endif
#endif
#else
#define SECUREC_HAVE_STRNLEN 0
#endif
#endif
#if SECUREC_IN_KERNEL
/* In kernel disbale functions */
#ifndef SECUREC_ENABLE_SCANF_FILE
#define SECUREC_ENABLE_SCANF_FILE 0
#endif
#ifndef SECUREC_ENABLE_SCANF_FLOAT
#define SECUREC_ENABLE_SCANF_FLOAT 0
#endif
#ifndef SECUREC_ENABLE_SPRINTF_FLOAT
#define SECUREC_ENABLE_SPRINTF_FLOAT 0
#endif
#ifndef SECUREC_HAVE_MBTOWC
#define SECUREC_HAVE_MBTOWC 0
#endif
#ifndef SECUREC_HAVE_WCTOMB
#define SECUREC_HAVE_WCTOMB 0
#endif
#ifndef SECUREC_HAVE_WCHART
#define SECUREC_HAVE_WCHART 0
#endif
#else /* Not in kernel */
/* Systems that do not support file, can define this macro to 0. */
#ifndef SECUREC_ENABLE_SCANF_FILE
#define SECUREC_ENABLE_SCANF_FILE 1
#endif
#ifndef SECUREC_ENABLE_SCANF_FLOAT
#define SECUREC_ENABLE_SCANF_FLOAT 1
#endif
/* Systems that do not support float, can define this macro to 0. */
#ifndef SECUREC_ENABLE_SPRINTF_FLOAT
#define SECUREC_ENABLE_SPRINTF_FLOAT 1
#endif
#ifndef SECUREC_HAVE_MBTOWC
#define SECUREC_HAVE_MBTOWC 1
#endif
#ifndef SECUREC_HAVE_WCTOMB
#define SECUREC_HAVE_WCTOMB 1
#endif
#ifndef SECUREC_HAVE_WCHART
#define SECUREC_HAVE_WCHART 1
#endif
#endif
#ifndef SECUREC_USE_STD_UNGETC
#define SECUREC_USE_STD_UNGETC 1
#endif
#ifndef SECUREC_ENABLE_INLINE
#define SECUREC_ENABLE_INLINE 0
#endif
#ifndef SECUREC_INLINE
#if SECUREC_ENABLE_INLINE
#define SECUREC_INLINE static inline
#else
#define SECUREC_INLINE static
#endif
#endif
#ifndef SECUREC_WARP_OUTPUT
#if SECUREC_IN_KERNEL
#define SECUREC_WARP_OUTPUT 1
#else
#define SECUREC_WARP_OUTPUT 0
#endif
#endif
#ifndef SECUREC_STREAM_STDIN
#define SECUREC_STREAM_STDIN stdin
#endif
#define SECUREC_MUL_SIXTEEN(x) ((x) << 4U)
#define SECUREC_MUL_EIGHT(x) ((x) << 3U)
#define SECUREC_MUL_TEN(x) ((((x) << 2U) + (x)) << 1U)
/* Limited format input and output width, use signed integer */
#define SECUREC_MAX_WIDTH_LEN_DIV_TEN 21474836
#define SECUREC_MAX_WIDTH_LEN (SECUREC_MAX_WIDTH_LEN_DIV_TEN * 10)
/* Is the x multiplied by 10 greater than */
#define SECUREC_MUL_TEN_ADD_BEYOND_MAX(x) (((x) > SECUREC_MAX_WIDTH_LEN_DIV_TEN))
#define SECUREC_FLOAT_BUFSIZE (309 + 40) /* Max length of double value */
#define SECUREC_FLOAT_BUFSIZE_LB (4932 + 40) /* Max length of long double value */
#define SECUREC_FLOAT_DEFAULT_PRECISION 6
/* This macro does not handle pointer equality or integer overflow */
#define SECUREC_MEMORY_NO_OVERLAP(dest, src, count) \
(((src) < (dest) && ((const char *)(src) + (count)) <= (char *)(dest)) || \
((dest) < (src) && ((char *)(dest) + (count)) <= (const char *)(src)))
#define SECUREC_MEMORY_IS_OVERLAP(dest, src, count) \
(((src) < (dest) && ((const char *)(src) + (count)) > (char *)(dest)) || \
((dest) < (src) && ((char *)(dest) + (count)) > (const char *)(src)))
/*
* Check whether the strings overlap, len is the length of the string not include terminator
* Length is related to data type char or wchar , do not force conversion of types
*/
#define SECUREC_STRING_NO_OVERLAP(dest, src, len) \
(((src) < (dest) && ((src) + (len)) < (dest)) || \
((dest) < (src) && ((dest) + (len)) < (src)))
/*
* Check whether the strings overlap for strcpy wcscpy function, dest len and src Len are not include terminator
* Length is related to data type char or wchar , do not force conversion of types
*/
#define SECUREC_STRING_IS_OVERLAP(dest, src, len) \
(((src) < (dest) && ((src) + (len)) >= (dest)) || \
((dest) < (src) && ((dest) + (len)) >= (src)))
/*
* Check whether the strings overlap for strcat wcscat function, dest len and src Len are not include terminator
* Length is related to data type char or wchar , do not force conversion of types
*/
#define SECUREC_CAT_STRING_IS_OVERLAP(dest, destLen, src, srcLen) \
(((dest) < (src) && ((dest) + (destLen) + (srcLen)) >= (src)) || \
((src) < (dest) && ((src) + (srcLen)) >= (dest)))
#if SECUREC_HAVE_STRNLEN
#define SECUREC_CALC_STR_LEN(str, maxLen, outLen) do { \
*(outLen) = strnlen((str), (maxLen)); \
} SECUREC_WHILE_ZERO
#define SECUREC_CALC_STR_LEN_OPT(str, maxLen, outLen) do { \
if ((maxLen) > 8) { \
/* Optimization or len less then 8 */ \
if (*((str) + 0) == '\0') { \
*(outLen) = 0; \
} else if (*((str) + 1) == '\0') { \
*(outLen) = 1; \
} else if (*((str) + 2) == '\0') { \
*(outLen) = 2; \
} else if (*((str) + 3) == '\0') { \
*(outLen) = 3; \
} else if (*((str) + 4) == '\0') { \
*(outLen) = 4; \
} else if (*((str) + 5) == '\0') { \
*(outLen) = 5; \
} else if (*((str) + 6) == '\0') { \
*(outLen) = 6; \
} else if (*((str) + 7) == '\0') { \
*(outLen) = 7; \
} else if (*((str) + 8) == '\0') { \
/* Optimization with a length of 8 */ \
*(outLen) = 8; \
} else { \
/* The offset is 8 because the performance of 8 byte alignment is high */ \
*(outLen) = 8 + strnlen((str) + 8, (maxLen) - 8); \
} \
} else { \
SECUREC_CALC_STR_LEN((str), (maxLen), (outLen)); \
} \
} SECUREC_WHILE_ZERO
#else
#define SECUREC_CALC_STR_LEN(str, maxLen, outLen) do { \
const char *strEnd_ = (const char *)(str); \
size_t availableSize_ = (size_t)(maxLen); \
while (availableSize_ > 0 && *strEnd_ != '\0') { \
--availableSize_; \
++strEnd_; \
} \
*(outLen) = (size_t)(strEnd_ - (str)); \
} SECUREC_WHILE_ZERO
#define SECUREC_CALC_STR_LEN_OPT SECUREC_CALC_STR_LEN
#endif
#define SECUREC_CALC_WSTR_LEN(str, maxLen, outLen) do { \
const wchar_t *strEnd_ = (const wchar_t *)(str); \
size_t len_ = 0; \
while (len_ < (maxLen) && *strEnd_ != L'\0') { \
++len_; \
++strEnd_; \
} \
*(outLen) = len_; \
} SECUREC_WHILE_ZERO
/*
* Performance optimization, product may disable inline function.
* Using function pointer for MEMSET to prevent compiler optimization when cleaning up memory.
*/
#ifdef SECUREC_USE_ASM
#define SECUREC_MEMSET_FUNC_OPT memset_opt
#define SECUREC_MEMCPY_FUNC_OPT memcpy_opt
#else
#define SECUREC_MEMSET_FUNC_OPT memset
#define SECUREC_MEMCPY_FUNC_OPT memcpy
#endif
#define SECUREC_MEMCPY_WARP_OPT(dest, src, count) (void)SECUREC_MEMCPY_FUNC_OPT((dest), (src), (count))
#ifndef SECUREC_MEMSET_INDIRECT_USE
/* Can be turned off for scenarios that do not allow pointer calls */
#define SECUREC_MEMSET_INDIRECT_USE 1
#endif
#if SECUREC_MEMSET_INDIRECT_USE
#define SECUREC_MEMSET_WARP_OPT(dest, value, count) do { \
void *(* const volatile fn_)(void *s_, int c_, size_t n_) = SECUREC_MEMSET_FUNC_OPT; \
(void)(*fn_)((dest), (value), (count)); \
} SECUREC_WHILE_ZERO
#else
#define SECUREC_MEMSET_WARP_OPT(dest, value, count) (void)SECUREC_MEMSET_FUNC_OPT((dest), (value), (count))
#endif
#ifdef SECUREC_FORMAT_OUTPUT_INPUT
#if defined(SECUREC_COMPATIBLE_WIN_FORMAT) || defined(__ARMCC_VERSION)
typedef __int64 SecInt64;
typedef unsigned __int64 SecUnsignedInt64;
#if defined(__ARMCC_VERSION)
typedef unsigned int SecUnsignedInt32;
#else
typedef unsigned __int32 SecUnsignedInt32;
#endif
#else
typedef unsigned int SecUnsignedInt32;
typedef long long SecInt64;
typedef unsigned long long SecUnsignedInt64;
#endif
#ifdef SECUREC_FOR_WCHAR
#if defined(SECUREC_VXWORKS_PLATFORM) && !defined(__WINT_TYPE__)
typedef wchar_t wint_t;
#endif
#ifndef WEOF
#define WEOF ((wchar_t)(-1))
#endif
#define SECUREC_CHAR(x) L ## x
typedef wchar_t SecChar;
typedef wchar_t SecUnsignedChar;
typedef wint_t SecInt;
typedef wint_t SecUnsignedInt;
#else /* no SECUREC_FOR_WCHAR */
#define SECUREC_CHAR(x) (x)
typedef char SecChar;
typedef unsigned char SecUnsignedChar;
typedef int SecInt;
typedef unsigned int SecUnsignedInt;
#endif
#endif
/*
* Determine whether the address is 8-byte aligned
* Some systems do not have uintptr_t type, so use NULL to clear tool alarm 507
*/
#define SECUREC_ADDR_ALIGNED_8(addr) ((((size_t)(addr)) & 7U) == 0) /* Use 7 to check aligned 8 */
/*
* If you define the memory allocation function, you need to define the function prototype.
* You can define this macro as a header file.
*/
#if defined(SECUREC_MALLOC_PROTOTYPE)
SECUREC_MALLOC_PROTOTYPE
#endif
#ifndef SECUREC_MALLOC
#define SECUREC_MALLOC(x) malloc((size_t)(x))
#endif
#ifndef SECUREC_FREE
#define SECUREC_FREE(x) free((void *)(x))
#endif
/* Improve performance with struct assignment, buf1 is not defined to avoid tool false positive */
#define SECUREC_COPY_VALUE_BY_STRUCT(dest, src, n) do { \
*(SecStrBuf##n *)(void *)(dest) = *(const SecStrBuf##n *)(const void *)(src); \
} SECUREC_WHILE_ZERO
typedef struct {
unsigned char buf[2]; /* Performance optimization code structure assignment length 2 bytes */
} SecStrBuf2;
typedef struct {
unsigned char buf[3]; /* Performance optimization code structure assignment length 3 bytes */
} SecStrBuf3;
typedef struct {
unsigned char buf[4]; /* Performance optimization code structure assignment length 4 bytes */
} SecStrBuf4;
typedef struct {
unsigned char buf[5]; /* Performance optimization code structure assignment length 5 bytes */
} SecStrBuf5;
typedef struct {
unsigned char buf[6]; /* Performance optimization code structure assignment length 6 bytes */
} SecStrBuf6;
typedef struct {
unsigned char buf[7]; /* Performance optimization code structure assignment length 7 bytes */
} SecStrBuf7;
typedef struct {
unsigned char buf[8]; /* Performance optimization code structure assignment length 8 bytes */
} SecStrBuf8;
typedef struct {
unsigned char buf[9]; /* Performance optimization code structure assignment length 9 bytes */
} SecStrBuf9;
typedef struct {
unsigned char buf[10]; /* Performance optimization code structure assignment length 10 bytes */
} SecStrBuf10;
typedef struct {
unsigned char buf[11]; /* Performance optimization code structure assignment length 11 bytes */
} SecStrBuf11;
typedef struct {
unsigned char buf[12]; /* Performance optimization code structure assignment length 12 bytes */
} SecStrBuf12;
typedef struct {
unsigned char buf[13]; /* Performance optimization code structure assignment length 13 bytes */
} SecStrBuf13;
typedef struct {
unsigned char buf[14]; /* Performance optimization code structure assignment length 14 bytes */
} SecStrBuf14;
typedef struct {
unsigned char buf[15]; /* Performance optimization code structure assignment length 15 bytes */
} SecStrBuf15;
typedef struct {
unsigned char buf[16]; /* Performance optimization code structure assignment length 16 bytes */
} SecStrBuf16;
typedef struct {
unsigned char buf[17]; /* Performance optimization code structure assignment length 17 bytes */
} SecStrBuf17;
typedef struct {
unsigned char buf[18]; /* Performance optimization code structure assignment length 18 bytes */
} SecStrBuf18;
typedef struct {
unsigned char buf[19]; /* Performance optimization code structure assignment length 19 bytes */
} SecStrBuf19;
typedef struct {
unsigned char buf[20]; /* Performance optimization code structure assignment length 20 bytes */
} SecStrBuf20;
typedef struct {
unsigned char buf[21]; /* Performance optimization code structure assignment length 21 bytes */
} SecStrBuf21;
typedef struct {
unsigned char buf[22]; /* Performance optimization code structure assignment length 22 bytes */
} SecStrBuf22;
typedef struct {
unsigned char buf[23]; /* Performance optimization code structure assignment length 23 bytes */
} SecStrBuf23;
typedef struct {
unsigned char buf[24]; /* Performance optimization code structure assignment length 24 bytes */
} SecStrBuf24;
typedef struct {
unsigned char buf[25]; /* Performance optimization code structure assignment length 25 bytes */
} SecStrBuf25;
typedef struct {
unsigned char buf[26]; /* Performance optimization code structure assignment length 26 bytes */
} SecStrBuf26;
typedef struct {
unsigned char buf[27]; /* Performance optimization code structure assignment length 27 bytes */
} SecStrBuf27;
typedef struct {
unsigned char buf[28]; /* Performance optimization code structure assignment length 28 bytes */
} SecStrBuf28;
typedef struct {
unsigned char buf[29]; /* Performance optimization code structure assignment length 29 bytes */
} SecStrBuf29;
typedef struct {
unsigned char buf[30]; /* Performance optimization code structure assignment length 30 bytes */
} SecStrBuf30;
typedef struct {
unsigned char buf[31]; /* Performance optimization code structure assignment length 31 bytes */
} SecStrBuf31;
typedef struct {
unsigned char buf[32]; /* Performance optimization code structure assignment length 32 bytes */
} SecStrBuf32;
typedef struct {
unsigned char buf[33]; /* Performance optimization code structure assignment length 33 bytes */
} SecStrBuf33;
typedef struct {
unsigned char buf[34]; /* Performance optimization code structure assignment length 34 bytes */
} SecStrBuf34;
typedef struct {
unsigned char buf[35]; /* Performance optimization code structure assignment length 35 bytes */
} SecStrBuf35;
typedef struct {
unsigned char buf[36]; /* Performance optimization code structure assignment length 36 bytes */
} SecStrBuf36;
typedef struct {
unsigned char buf[37]; /* Performance optimization code structure assignment length 37 bytes */
} SecStrBuf37;
typedef struct {
unsigned char buf[38]; /* Performance optimization code structure assignment length 38 bytes */
} SecStrBuf38;
typedef struct {
unsigned char buf[39]; /* Performance optimization code structure assignment length 39 bytes */
} SecStrBuf39;
typedef struct {
unsigned char buf[40]; /* Performance optimization code structure assignment length 40 bytes */
} SecStrBuf40;
typedef struct {
unsigned char buf[41]; /* Performance optimization code structure assignment length 41 bytes */
} SecStrBuf41;
typedef struct {
unsigned char buf[42]; /* Performance optimization code structure assignment length 42 bytes */
} SecStrBuf42;
typedef struct {
unsigned char buf[43]; /* Performance optimization code structure assignment length 43 bytes */
} SecStrBuf43;
typedef struct {
unsigned char buf[44]; /* Performance optimization code structure assignment length 44 bytes */
} SecStrBuf44;
typedef struct {
unsigned char buf[45]; /* Performance optimization code structure assignment length 45 bytes */
} SecStrBuf45;
typedef struct {
unsigned char buf[46]; /* Performance optimization code structure assignment length 46 bytes */
} SecStrBuf46;
typedef struct {
unsigned char buf[47]; /* Performance optimization code structure assignment length 47 bytes */
} SecStrBuf47;
typedef struct {
unsigned char buf[48]; /* Performance optimization code structure assignment length 48 bytes */
} SecStrBuf48;
typedef struct {
unsigned char buf[49]; /* Performance optimization code structure assignment length 49 bytes */
} SecStrBuf49;
typedef struct {
unsigned char buf[50]; /* Performance optimization code structure assignment length 50 bytes */
} SecStrBuf50;
typedef struct {
unsigned char buf[51]; /* Performance optimization code structure assignment length 51 bytes */
} SecStrBuf51;
typedef struct {
unsigned char buf[52]; /* Performance optimization code structure assignment length 52 bytes */
} SecStrBuf52;
typedef struct {
unsigned char buf[53]; /* Performance optimization code structure assignment length 53 bytes */
} SecStrBuf53;
typedef struct {
unsigned char buf[54]; /* Performance optimization code structure assignment length 54 bytes */
} SecStrBuf54;
typedef struct {
unsigned char buf[55]; /* Performance optimization code structure assignment length 55 bytes */
} SecStrBuf55;
typedef struct {
unsigned char buf[56]; /* Performance optimization code structure assignment length 56 bytes */
} SecStrBuf56;
typedef struct {
unsigned char buf[57]; /* Performance optimization code structure assignment length 57 bytes */
} SecStrBuf57;
typedef struct {
unsigned char buf[58]; /* Performance optimization code structure assignment length 58 bytes */
} SecStrBuf58;
typedef struct {
unsigned char buf[59]; /* Performance optimization code structure assignment length 59 bytes */
} SecStrBuf59;
typedef struct {
unsigned char buf[60]; /* Performance optimization code structure assignment length 60 bytes */
} SecStrBuf60;
typedef struct {
unsigned char buf[61]; /* Performance optimization code structure assignment length 61 bytes */
} SecStrBuf61;
typedef struct {
unsigned char buf[62]; /* Performance optimization code structure assignment length 62 bytes */
} SecStrBuf62;
typedef struct {
unsigned char buf[63]; /* Performance optimization code structure assignment length 63 bytes */
} SecStrBuf63;
typedef struct {
unsigned char buf[64]; /* Performance optimization code structure assignment length 64 bytes */
} SecStrBuf64;
/*
* User can change the error handler by modify the following definition,
* such as logging the detail error in file.
*/
#if defined(_DEBUG) || defined(DEBUG)
#if defined(SECUREC_ERROR_HANDLER_BY_ASSERT)
#define SECUREC_ERROR_INVALID_PARAMTER(msg) assert(msg "invalid argument" == NULL)
#define SECUREC_ERROR_INVALID_RANGE(msg) assert(msg "invalid dest buffer size" == NULL)
#define SECUREC_ERROR_BUFFER_OVERLAP(msg) assert(msg "buffer overlap" == NULL)
#elif defined(SECUREC_ERROR_HANDLER_BY_PRINTF)
#if SECUREC_IN_KERNEL
#define SECUREC_ERROR_INVALID_PARAMTER(msg) printk("%s invalid argument\n", msg)
#define SECUREC_ERROR_INVALID_RANGE(msg) printk("%s invalid dest buffer size\n", msg)
#define SECUREC_ERROR_BUFFER_OVERLAP(msg) printk("%s buffer overlap\n", msg)
#else
#define SECUREC_ERROR_INVALID_PARAMTER(msg) printf("%s invalid argument\n", msg)
#define SECUREC_ERROR_INVALID_RANGE(msg) printf("%s invalid dest buffer size\n", msg)
#define SECUREC_ERROR_BUFFER_OVERLAP(msg) printf("%s buffer overlap\n", msg)
#endif
#elif defined(SECUREC_ERROR_HANDLER_BY_FILE_LOG)
#define SECUREC_ERROR_INVALID_PARAMTER(msg) LogSecureCRuntimeError(msg " EINVAL\n")
#define SECUREC_ERROR_INVALID_RANGE(msg) LogSecureCRuntimeError(msg " ERANGE\n")
#define SECUREC_ERROR_BUFFER_OVERLAP(msg) LogSecureCRuntimeError(msg " EOVERLAP\n")
#endif
#endif
/* Default handler is none */
#ifndef SECUREC_ERROR_INVALID_PARAMTER
#define SECUREC_ERROR_INVALID_PARAMTER(msg)
#endif
#ifndef SECUREC_ERROR_INVALID_RANGE
#define SECUREC_ERROR_INVALID_RANGE(msg)
#endif
#ifndef SECUREC_ERROR_BUFFER_OVERLAP
#define SECUREC_ERROR_BUFFER_OVERLAP(msg)
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Assembly language memory copy and memory set for X86 or MIPS ... */
#ifdef SECUREC_USE_ASM
void *memcpy_opt(void *dest, const void *src, size_t n);
void *memset_opt(void *s, int c, size_t n);
#endif
#if defined(SECUREC_ERROR_HANDLER_BY_FILE_LOG)
void LogSecureCRuntimeError(const char *errDetail);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif

View File

@@ -1,39 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: By defining data type for ANSI string and including "input.inl",
* this file generates real underlying function used by scanf family API.
* Author: lishunda
* Create: 2014-02-25
*/
#define SECUREC_FORMAT_OUTPUT_INPUT 1
#ifdef SECUREC_FOR_WCHAR
#undef SECUREC_FOR_WCHAR
#endif
#include "secinput.h"
#include "input.inl"
SECUREC_INLINE int SecIsDigit(SecInt ch)
{
/* SecInt to unsigned char clear 571, use bit mask to clear negative return of ch */
return isdigit((int)((unsigned int)(unsigned char)(ch) & 0xffU));
}
SECUREC_INLINE int SecIsXdigit(SecInt ch)
{
return isxdigit((int)((unsigned int)(unsigned char)(ch) & 0xffU));
}
SECUREC_INLINE int SecIsSpace(SecInt ch)
{
return isspace((int)((unsigned int)(unsigned char)(ch) & 0xffU));
}

View File

@@ -1,78 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: By defining data type for UNICODE string and including "input.inl",
* this file generates real underlying function used by scanf family API.
* Author: lishunda
* Create: 2014-02-25
*/
/* If some platforms don't have wchar.h, dont't include it */
#if !(defined(SECUREC_VXWORKS_PLATFORM))
/* If there is no macro below, it will cause vs2010 compiling alarm */
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
#ifndef __STDC_WANT_SECURE_LIB__
/* The order of adjustment is to eliminate alarm of Duplicate Block */
#define __STDC_WANT_SECURE_LIB__ 0
#endif
#ifndef _CRTIMP_ALTERNATIVE
#define _CRTIMP_ALTERNATIVE /* Comment microsoft *_s function */
#endif
#endif
#include <wchar.h>
#endif
/* fix redefined */
#undef SECUREC_ENABLE_WCHAR_FUNC
/* Disable wchar func to clear vs warning */
#define SECUREC_ENABLE_WCHAR_FUNC 0
#define SECUREC_FORMAT_OUTPUT_INPUT 1
#ifndef SECUREC_FOR_WCHAR
#define SECUREC_FOR_WCHAR
#endif
#include "secinput.h"
#include "input.inl"
SECUREC_INLINE unsigned int SecWcharHighBits(SecInt ch)
{
/* Convert int to unsigned int clear 571 */
return ((unsigned int)(int)ch & (~0xffU));
}
SECUREC_INLINE unsigned char SecWcharLowByte(SecInt ch)
{
/* Convert int to unsigned int clear 571 */
return (unsigned char)((unsigned int)(int)ch & 0xffU);
}
SECUREC_INLINE int SecIsDigit(SecInt ch)
{
if (SecWcharHighBits(ch) != 0) {
return 0; /* Same as isdigit */
}
return isdigit((int)SecWcharLowByte(ch));
}
SECUREC_INLINE int SecIsXdigit(SecInt ch)
{
if (SecWcharHighBits(ch) != 0) {
return 0; /* Same as isxdigit */
}
return isxdigit((int)SecWcharLowByte(ch));
}
SECUREC_INLINE int SecIsSpace(SecInt ch)
{
return iswspace((wint_t)(int)(ch));
}

View File

@@ -1,124 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: Define macro, enum, data struct, and declare internal used function
* prototype, which is used by output.inl, secureprintoutput_w.c and
* secureprintoutput_a.c.
* Author: lishunda
* Create: 2014-02-25
*/
#ifndef SECUREPRINTOUTPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C
#define SECUREPRINTOUTPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C
#include "securecutil.h"
/*
* Flag definitions.
* Using macros instead of enumerations is because some of the enumerated types under the compiler are 16bit.
*/
#define SECUREC_FLAG_SIGN 0x00001U
#define SECUREC_FLAG_SIGN_SPACE 0x00002U
#define SECUREC_FLAG_LEFT 0x00004U
#define SECUREC_FLAG_LEADZERO 0x00008U
#define SECUREC_FLAG_LONG 0x00010U
#define SECUREC_FLAG_SHORT 0x00020U
#define SECUREC_FLAG_SIGNED 0x00040U
#define SECUREC_FLAG_ALTERNATE 0x00080U
#define SECUREC_FLAG_NEGATIVE 0x00100U
#define SECUREC_FLAG_FORCE_OCTAL 0x00200U
#define SECUREC_FLAG_LONG_DOUBLE 0x00400U
#define SECUREC_FLAG_WIDECHAR 0x00800U
#define SECUREC_FLAG_LONGLONG 0x01000U
#define SECUREC_FLAG_CHAR 0x02000U
#define SECUREC_FLAG_POINTER 0x04000U
#define SECUREC_FLAG_I64 0x08000U
#define SECUREC_FLAG_PTRDIFF 0x10000U
#define SECUREC_FLAG_SIZE 0x20000U
#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT
#define SECUREC_FLAG_INTMAX 0x40000U
#endif
/* State definitions. Identify the status of the current format */
typedef enum {
STAT_NORMAL,
STAT_PERCENT,
STAT_FLAG,
STAT_WIDTH,
STAT_DOT,
STAT_PRECIS,
STAT_SIZE,
STAT_TYPE,
STAT_INVALID
} SecFmtState;
/* Format output buffer pointer and available size */
typedef struct {
int count;
char *cur;
} SecPrintfStream;
#ifndef SECUREC_BUFFER_SIZE
#if SECUREC_IN_KERNEL
#define SECUREC_BUFFER_SIZE 32
#elif defined(SECUREC_STACK_SIZE_LESS_THAN_1K)
/*
* SECUREC BUFFER SIZE Can not be less than 23
* The length of the octal representation of 64-bit integers with zero lead
*/
#define SECUREC_BUFFER_SIZE 256
#else
#define SECUREC_BUFFER_SIZE 512
#endif
#endif
#if SECUREC_BUFFER_SIZE < 23
#error SECUREC_BUFFER_SIZE Can not be less than 23
#endif
/* Buffer size for wchar, use 4 to make the compiler aligns as 8 bytes as possible */
#define SECUREC_WCHAR_BUFFER_SIZE 4
#define SECUREC_MAX_PRECISION SECUREC_BUFFER_SIZE
/* Max. # bytes in multibyte char ,see MB_LEN_MAX */
#define SECUREC_MB_LEN 16
/* The return value of the internal function, which is returned when truncated */
#define SECUREC_PRINTF_TRUNCATE (-2)
#define SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, maxLimit) \
((format) == NULL || (strDest) == NULL || (destMax) == 0 || (destMax) > (maxLimit))
#define SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, maxLimit) do { \
if ((strDest) != NULL && (destMax) > 0 && (destMax) <= (maxLimit)) { \
*(strDest) = '\0'; \
} \
} SECUREC_WHILE_ZERO
#ifdef SECUREC_COMPATIBLE_WIN_FORMAT
#define SECUREC_VSNPRINTF_PARAM_ERROR(format, strDest, destMax, count, maxLimit) \
(((format) == NULL || (strDest) == NULL || (destMax) == 0 || (destMax) > (maxLimit)) || \
((count) > (SECUREC_STRING_MAX_LEN - 1) && (count) != (size_t)(-1)))
#else
#define SECUREC_VSNPRINTF_PARAM_ERROR(format, strDest, destMax, count, maxLimit) \
(((format) == NULL || (strDest) == NULL || (destMax) == 0 || (destMax) > (maxLimit)) || \
((count) > (SECUREC_STRING_MAX_LEN - 1)))
#endif
#ifdef __cplusplus
extern "C" {
#endif
int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list argList);
#ifdef SECUREC_FOR_WCHAR
int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar, const wchar_t *format, va_list argList);
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,174 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: By defining corresponding macro for ANSI string and including "output.inl",
* this file generates real underlying function used by printf family API.
* Author: lishunda
* Create: 2014-02-25
*/
#define SECUREC_FORMAT_OUTPUT_INPUT 1
#ifdef SECUREC_FOR_WCHAR
#undef SECUREC_FOR_WCHAR
#endif
#include "secureprintoutput.h"
#if SECUREC_WARP_OUTPUT
#define SECUREC_FORMAT_FLAG_TABLE_SIZE 128
SECUREC_INLINE const char *SecSkipKnownFlags(const char *format)
{
static const unsigned char flagTable[SECUREC_FORMAT_FLAG_TABLE_SIZE] = {
/*
* Known flag is "0123456789 +-#hlLwZzjqt*I$"
*/
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
};
const char *fmt = format;
while (*fmt != '\0') {
char fmtChar = *fmt;
if ((unsigned char)fmtChar > 0x7f) { /* 0x7f is upper limit of format char value */
break;
}
if (flagTable[(unsigned char)fmtChar] == 0) {
break;
}
++fmt;
}
return fmt;
}
SECUREC_INLINE int SecFormatContainN(const char *format)
{
const char *fmt = format;
while (*fmt != '\0') {
++fmt;
/* Skip normal char */
if (*(fmt - 1) != '%') {
continue;
}
/* Meet %% */
if (*fmt == '%') {
++fmt; /* Point to the character after the %. Correct handling %%xx */
continue;
}
/* Now parse %..., fmt point to the character after the % */
fmt = SecSkipKnownFlags(fmt);
if (*fmt == 'n') {
return 1;
}
}
return 0;
}
/*
* Multi character formatted output implementation, the count include \0 character, must be greater than zero
*/
int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list argList)
{
int retVal;
if (SecFormatContainN(format) != 0) {
string[0] = '\0';
return -1;
}
retVal = vsnprintf(string, count, format, argList);
if (retVal >= (int)count) { /* The size_t to int is ok, count max is SECUREC_STRING_MAX_LEN */
/* The buffer was too small; we return truncation */
string[count - 1] = '\0';
return SECUREC_PRINTF_TRUNCATE;
}
if (retVal < 0) {
string[0] = '\0'; /* Empty the dest strDest */
return -1;
}
return retVal;
}
#else
#if SECUREC_IN_KERNEL
#include <linux/ctype.h>
#endif
#ifndef EOF
#define EOF (-1)
#endif
#include "output.inl"
/*
* Multi character formatted output implementation
*/
int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list argList)
{
SecPrintfStream str;
int retVal;
str.count = (int)count; /* The count include \0 character, must be greater than zero */
str.cur = string;
retVal = SecOutputS(&str, format, argList);
if (retVal >= 0) {
if (SecPutZeroChar(&str) == 0) {
return retVal;
}
}
if (str.count < 0) {
/* The buffer was too small, then truncate */
string[count - 1] = '\0';
return SECUREC_PRINTF_TRUNCATE;
}
string[0] = '\0'; /* Empty the dest string */
return -1;
}
/*
* Write a wide character
*/
SECUREC_INLINE void SecWriteMultiChar(char ch, int num, SecPrintfStream *f, int *pnumwritten)
{
int count;
for (count = num; count > 0; --count) {
--f->count; /* f -> count may be negative,indicating insufficient space */
if (f->count < 0) {
*pnumwritten = -1;
return;
}
*(f->cur) = ch;
++f->cur;
*pnumwritten = *pnumwritten + 1;
}
}
/*
* Write string function, where this function is called, make sure that len is greater than 0
*/
SECUREC_INLINE void SecWriteString(const char *string, int len, SecPrintfStream *f, int *pnumwritten)
{
const char *str = string;
int count;
for (count = len; count > 0; --count) {
--f->count; /* f -> count may be negative,indicating insufficient space */
if (f->count < 0) {
*pnumwritten = -1;
return;
}
*(f->cur) = *str;
++f->cur;
++str;
}
*pnumwritten = *pnumwritten + (int)(size_t)(str - string);
}
#endif

View File

@@ -1,149 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: By defining corresponding macro for UNICODE string and including "output.inl",
* this file generates real underlying function used by printf family API.
* Author: lishunda
* Create: 2014-02-25
*/
/* If some platforms don't have wchar.h, dont't include it */
#if !(defined(SECUREC_VXWORKS_PLATFORM))
/* If there is no macro above, it will cause compiling alarm */
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
#ifndef _CRTIMP_ALTERNATIVE
#define _CRTIMP_ALTERNATIVE /* Comment microsoft *_s function */
#endif
#ifndef __STDC_WANT_SECURE_LIB__
#define __STDC_WANT_SECURE_LIB__ 0
#endif
#endif
#include <wchar.h>
#endif
/* fix redefined */
#undef SECUREC_ENABLE_WCHAR_FUNC
/* Disable wchar func to clear vs warning */
#define SECUREC_ENABLE_WCHAR_FUNC 0
#define SECUREC_FORMAT_OUTPUT_INPUT 1
#ifndef SECUREC_FOR_WCHAR
#define SECUREC_FOR_WCHAR
#endif
#if defined(SECUREC_WARP_OUTPUT) && SECUREC_WARP_OUTPUT
#undef SECUREC_WARP_OUTPUT
#define SECUREC_WARP_OUTPUT 0
#endif
#include "secureprintoutput.h"
SECUREC_INLINE void SecWriteCharW(wchar_t ch, SecPrintfStream *f, int *pnumwritten);
SECUREC_INLINE int SecPutWcharStrEndingZero(SecPrintfStream *str, int zeroCount);
#include "output.inl"
/*
* Wide character formatted output implementation
*/
int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar, const wchar_t *format, va_list argList)
{
SecPrintfStream str;
int retVal; /* If initialization causes e838 */
str.cur = (char *)string;
/* This count include \0 character, Must be greater than zero */
str.count = (int)(sizeInWchar * sizeof(wchar_t));
retVal = SecOutputSW(&str, format, argList);
if (retVal >= 0) {
if (SecPutWcharStrEndingZero(&str, (int)sizeof(wchar_t)) == 0) {
return retVal;
}
}
if (str.count < 0) {
/* The buffer was too small, then truncate */
string[sizeInWchar - 1] = L'\0';
return SECUREC_PRINTF_TRUNCATE;
}
string[0] = L'\0'; /* Empty the dest string */
return -1;
}
/*
* Output a wide character zero end into the SecPrintfStream structure
*/
SECUREC_INLINE int SecPutWcharStrEndingZero(SecPrintfStream *str, int zeroCount)
{
int count;
for (count = zeroCount; count > 0; --count) {
if (SecPutZeroChar(str) != 0) {
return -1;
}
}
return 0;
}
/*
* Output a wide character into the SecPrintfStream structure
*/
SECUREC_INLINE int SecPutCharW(wchar_t ch, SecPrintfStream *f)
{
f->count -= (int)sizeof(wchar_t); /* f -> count may be negative,indicating insufficient space */
if (f->count >= 0) {
*(wchar_t *)(void *)(f->cur) = ch;
f->cur += sizeof(wchar_t);
return 0;
}
return -1;
}
/*
* Output a wide character into the SecPrintfStream structure, returns the number of characters written
*/
SECUREC_INLINE void SecWriteCharW(wchar_t ch, SecPrintfStream *f, int *pnumwritten)
{
if (SecPutCharW(ch, f) == 0) {
*pnumwritten = *pnumwritten + 1;
} else {
*pnumwritten = -1;
}
}
/*
* Output multiple wide character into the SecPrintfStream structure, returns the number of characters written
*/
SECUREC_INLINE void SecWriteMultiCharW(wchar_t ch, int num, SecPrintfStream *f, int *pnumwritten)
{
int count;
for (count = num; count > 0; --count) {
SecWriteCharW(ch, f, pnumwritten);
if (*pnumwritten == -1) {
break;
}
}
}
/*
* Output a wide string into the SecPrintfStream structure, returns the number of characters written
*/
SECUREC_INLINE void SecWriteStringW(const wchar_t *string, int len, SecPrintfStream *f, int *pnumwritten)
{
const wchar_t *str = string;
int count;
for (count = len; count > 0; --count) {
SecWriteCharW(*str, f, pnumwritten);
++str;
if (*pnumwritten == -1) {
break;
}
}
}

View File

@@ -1,111 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: snprintf_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securec.h"
#if SECUREC_ENABLE_SNPRINTF
/*
* <FUNCTION DESCRIPTION>
* The snprintf_s function is equivalent to the snprintf function
* except for the parameter destMax/count and the explicit runtime-constraints violation
* The snprintf_s function formats and stores count or fewer characters in
* strDest and appends a terminating null. Each argument (if any) is converted
* and output according to the corresponding format specification in format.
* The formatting is consistent with the printf family of functions; If copying
* occurs between strings that overlap, the behavior is undefined.
*
* <INPUT PARAMETERS>
* strDest Storage location for the output.
* destMax The size of the storage location for output. Size
* in bytes for snprintf_s or size in words for snwprintf_s.
* count Maximum number of character to store.
* format Format-control string.
* ... Optional arguments.
*
* <OUTPUT PARAMETERS>
* strDest is updated
*
* <RETURN VALUE>
* return the number of characters written, not including the terminating null
* return -1 if an error occurs.
* return -1 if count < destMax and the output string has been truncated
*
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*
*/
int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vsnprintf_s(strDest, destMax, count, format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(snprintf_s);
#endif
#endif
#if SECUREC_SNPRINTF_TRUNCATED
/*
* <FUNCTION DESCRIPTION>
* The snprintf_truncated_s function is equivalent to the snprintf function
* except for the parameter destMax/count and the explicit runtime-constraints violation
* The snprintf_truncated_s function formats and stores count or fewer characters in
* strDest and appends a terminating null. Each argument (if any) is converted
* and output according to the corresponding format specification in format.
* The formatting is consistent with the printf family of functions; If copying
* occurs between strings that overlap, the behavior is undefined.
*
* <INPUT PARAMETERS>
* strDest Storage location for the output.
* destMax The size of the storage location for output. Size
* in bytes for snprintf_truncated_s or size in words for snwprintf_s.
* format Format-control string.
* ... Optional arguments.
*
* <OUTPUT PARAMETERS>
* strDest is updated
*
* <RETURN VALUE>
* return the number of characters written, not including the terminating null
* return -1 if an error occurs.
* return destMax-1 if output string has been truncated
*
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*
*/
int snprintf_truncated_s(char *strDest, size_t destMax, const char *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vsnprintf_truncated_s(strDest, destMax, format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(snprintf_truncated_s);
#endif
#endif

View File

@@ -1,59 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: sprintf_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securec.h"
/*
* <FUNCTION DESCRIPTION>
* The sprintf_s function is equivalent to the sprintf function
* except for the parameter destMax and the explicit runtime-constraints violation
* The sprintf_s function formats and stores a series of characters and values
* in strDest. Each argument (if any) is converted and output according to
* the corresponding format specification in format. The format consists of
* ordinary characters and has the same form and function as the format argument
* for printf. A null character is appended after the last character written.
* If copying occurs between strings that overlap, the behavior is undefined.
*
* <INPUT PARAMETERS>
* strDest Storage location for output.
* destMax Maximum number of characters to store.
* format Format-control string.
* ... Optional arguments
*
* <OUTPUT PARAMETERS>
* strDest is updated
*
* <RETURN VALUE>
* return the number of bytes stored in strDest, not counting the terminating null character.
* return -1 if an error occurred.
*
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
int sprintf_s(char *strDest, size_t destMax, const char *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vsprintf_s(strDest, destMax, format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(sprintf_s);
#endif

View File

@@ -1,59 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: sscanf_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securec.h"
/*
* <FUNCTION DESCRIPTION>
* The sscanf_s function is equivalent to fscanf_s,
* except that input is obtained from a string (specified by the argument buffer) rather than from a stream
* The sscanf function reads data from buffer into the location given by each
* argument. Every argument must be a pointer to a variable with a type that
* corresponds to a type specifier in format. The format argument controls the
* interpretation of the input fields and has the same form and function as
* the format argument for the scanf function.
* If copying takes place between strings that overlap, the behavior is undefined.
*
* <INPUT PARAMETERS>
* buffer Stored data.
* format Format control string, see Format Specifications.
* ... Optional arguments.
*
* <OUTPUT PARAMETERS>
* ... The converted value stored in user assigned address
*
* <RETURN VALUE>
* Each of these functions returns the number of fields successfully converted
* and assigned; the return value does not include fields that were read but
* not assigned.
* A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int sscanf_s(const char *buffer, const char *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vsscanf_s(buffer, format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(sscanf_s);
#endif

View File

@@ -1,102 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: strcat_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securecutil.h"
/*
* Befor this function, the basic parameter checking has been done
*/
SECUREC_INLINE errno_t SecDoCat(char *strDest, size_t destMax, const char *strSrc)
{
size_t destLen;
size_t srcLen;
size_t maxSrcLen;
SECUREC_CALC_STR_LEN(strDest, destMax, &destLen);
/* Only optimize strSrc, do not apply this function to strDest */
maxSrcLen = destMax - destLen;
SECUREC_CALC_STR_LEN_OPT(strSrc, maxSrcLen, &srcLen);
if (SECUREC_CAT_STRING_IS_OVERLAP(strDest, destLen, strSrc, srcLen)) {
strDest[0] = '\0';
if (strDest + destLen <= strSrc && destLen == destMax) {
SECUREC_ERROR_INVALID_PARAMTER("strcat_s");
return EINVAL_AND_RESET;
}
SECUREC_ERROR_BUFFER_OVERLAP("strcat_s");
return EOVERLAP_AND_RESET;
}
if (srcLen + destLen >= destMax || strDest == strSrc) {
strDest[0] = '\0';
if (destLen == destMax) {
SECUREC_ERROR_INVALID_PARAMTER("strcat_s");
return EINVAL_AND_RESET;
}
SECUREC_ERROR_INVALID_RANGE("strcat_s");
return ERANGE_AND_RESET;
}
SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, srcLen + 1); /* Single character length include \0 */
return EOK;
}
/*
* <FUNCTION DESCRIPTION>
* The strcat_s function appends a copy of the string pointed to by strSrc (including the terminating null character)
* to the end of the string pointed to by strDest.
* The initial character of strSrc overwrites the terminating null character of strDest.
* strcat_s will return EOVERLAP_AND_RESET if the source and destination strings overlap.
*
* Note that the second parameter is the total size of the buffer, not the
* remaining size.
*
* <INPUT PARAMETERS>
* strDest Null-terminated destination string buffer.
* destMax Size of the destination string buffer.
* strSrc Null-terminated source string buffer.
*
* <OUTPUT PARAMETERS>
* strDest is updated
*
* <RETURN VALUE>
* EOK Success
* EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN
* EINVAL_AND_RESET (strDest unterminated and all other parameters are valid) or
* (strDest != NULL and strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN)
* ERANGE destMax is 0 and destMax > SECUREC_STRING_MAX_LEN
* ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
*
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc)
{
if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("strcat_s");
return ERANGE;
}
if (strDest == NULL || strSrc == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("strcat_s");
if (strDest != NULL) {
strDest[0] = '\0';
return EINVAL_AND_RESET;
}
return EINVAL;
}
return SecDoCat(strDest, destMax, strSrc);
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(strcat_s);
#endif

View File

@@ -1,349 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: strcpy_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securecutil.h"
#ifndef SECUREC_STRCPY_WITH_PERFORMANCE
#define SECUREC_STRCPY_WITH_PERFORMANCE 1
#endif
#define SECUREC_STRCPY_PARAM_OK(strDest, destMax, strSrc) ((destMax) > 0 && \
(destMax) <= SECUREC_STRING_MAX_LEN && (strDest) != NULL && (strSrc) != NULL && (strDest) != (strSrc))
#if (!SECUREC_IN_KERNEL) && SECUREC_STRCPY_WITH_PERFORMANCE
#ifndef SECUREC_STRCOPY_THRESHOLD_SIZE
#define SECUREC_STRCOPY_THRESHOLD_SIZE 32UL
#endif
/* The purpose of converting to void is to clean up the alarm */
#define SECUREC_SMALL_STR_COPY(strDest, strSrc, lenWithTerm) do { \
if (SECUREC_ADDR_ALIGNED_8(strDest) && SECUREC_ADDR_ALIGNED_8(strSrc)) { \
/* Use struct assignment */ \
switch (lenWithTerm) { \
case 1: \
*(strDest) = *(strSrc); \
break; \
case 2: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 2); \
break; \
case 3: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 3); \
break; \
case 4: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 4); \
break; \
case 5: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 5); \
break; \
case 6: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 6); \
break; \
case 7: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 7); \
break; \
case 8: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 8); \
break; \
case 9: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 9); \
break; \
case 10: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 10); \
break; \
case 11: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 11); \
break; \
case 12: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 12); \
break; \
case 13: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 13); \
break; \
case 14: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 14); \
break; \
case 15: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 15); \
break; \
case 16: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 16); \
break; \
case 17: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 17); \
break; \
case 18: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 18); \
break; \
case 19: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 19); \
break; \
case 20: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 20); \
break; \
case 21: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 21); \
break; \
case 22: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 22); \
break; \
case 23: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 23); \
break; \
case 24: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 24); \
break; \
case 25: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 25); \
break; \
case 26: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 26); \
break; \
case 27: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 27); \
break; \
case 28: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 28); \
break; \
case 29: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 29); \
break; \
case 30: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 30); \
break; \
case 31: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 31); \
break; \
case 32: \
SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 32); \
break; \
default: \
/* Do nothing */ \
break; \
} /* END switch */ \
} else { \
char *tmpStrDest_ = (char *)(strDest); \
const char *tmpStrSrc_ = (const char *)(strSrc); \
switch (lenWithTerm) { \
case 32: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 31: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 30: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 29: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 28: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 27: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 26: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 25: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 24: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 23: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 22: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 21: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 20: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 19: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 18: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 17: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 16: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 15: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 14: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 13: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 12: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 11: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 10: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 9: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 8: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 7: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 6: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 5: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 4: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 3: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 2: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
case 1: \
*(tmpStrDest_++) = *(tmpStrSrc_++); \
/* fall-through */ /* FALLTHRU */ \
default: \
/* Do nothing */ \
break; \
} \
} \
} SECUREC_WHILE_ZERO
#endif
#if SECUREC_IN_KERNEL || (!SECUREC_STRCPY_WITH_PERFORMANCE)
#define SECUREC_STRCPY_OPT(dest, src, lenWithTerm) SECUREC_MEMCPY_WARP_OPT((dest), (src), (lenWithTerm))
#else
/*
* Performance optimization. lenWithTerm include '\0'
*/
#define SECUREC_STRCPY_OPT(dest, src, lenWithTerm) do { \
if ((lenWithTerm) > SECUREC_STRCOPY_THRESHOLD_SIZE) { \
SECUREC_MEMCPY_WARP_OPT((dest), (src), (lenWithTerm)); \
} else { \
SECUREC_SMALL_STR_COPY((dest), (src), (lenWithTerm)); \
} \
} SECUREC_WHILE_ZERO
#endif
/*
* Check Src Range
*/
SECUREC_INLINE errno_t CheckSrcRange(char *strDest, size_t destMax, const char *strSrc)
{
size_t tmpDestMax = destMax;
const char *tmpSrc = strSrc;
/* Use destMax as boundary checker and destMax must be greater than zero */
while (*tmpSrc != '\0' && tmpDestMax > 0) {
++tmpSrc;
--tmpDestMax;
}
if (tmpDestMax == 0) {
strDest[0] = '\0';
SECUREC_ERROR_INVALID_RANGE("strcpy_s");
return ERANGE_AND_RESET;
}
return EOK;
}
/*
* Handling errors
*/
errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc)
{
if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("strcpy_s");
return ERANGE;
}
if (strDest == NULL || strSrc == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("strcpy_s");
if (strDest != NULL) {
strDest[0] = '\0';
return EINVAL_AND_RESET;
}
return EINVAL;
}
return CheckSrcRange(strDest, destMax, strSrc);
}
/*
* <FUNCTION DESCRIPTION>
* The strcpy_s function copies the string pointed to strSrc
* (including the terminating null character) into the array pointed to by strDest
* The destination string must be large enough to hold the source string,
* including the terminating null character. strcpy_s will return EOVERLAP_AND_RESET
* if the source and destination strings overlap.
*
* <INPUT PARAMETERS>
* strDest Location of destination string buffer
* destMax Size of the destination string buffer.
* strSrc Null-terminated source string buffer.
*
* <OUTPUT PARAMETERS>
* strDest is updated.
*
* <RETURN VALUE>
* EOK Success
* EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN
* EINVAL_AND_RESET strDest != NULL and strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN
* ERANGE destMax is 0 and destMax > SECUREC_STRING_MAX_LEN
* ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
*
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc)
{
if (SECUREC_STRCPY_PARAM_OK(strDest, destMax, strSrc)) {
size_t srcStrLen;
SECUREC_CALC_STR_LEN(strSrc, destMax, &srcStrLen);
++srcStrLen; /* The length include '\0' */
if (srcStrLen <= destMax) {
/* Use mem overlap check include '\0' */
if (SECUREC_MEMORY_NO_OVERLAP(strDest, strSrc, srcStrLen)) {
/* Performance optimization srcStrLen include '\0' */
SECUREC_STRCPY_OPT(strDest, strSrc, srcStrLen);
return EOK;
} else {
strDest[0] = '\0';
SECUREC_ERROR_BUFFER_OVERLAP("strcpy_s");
return EOVERLAP_AND_RESET;
}
}
}
return strcpy_error(strDest, destMax, strSrc);
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(strcpy_s);
#endif

View File

@@ -1,120 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: strncat_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securecutil.h"
/*
* Befor this function, the basic parameter checking has been done
*/
SECUREC_INLINE errno_t SecDoCatLimit(char *strDest, size_t destMax, const char *strSrc, size_t count)
{
size_t destLen;
size_t srcLen;
SECUREC_CALC_STR_LEN(strDest, destMax, &destLen);
/*
* The strSrc is no longer optimized. The reason is that when count is small,
* the efficiency of strnlen is higher than that of self realization.
*/
SECUREC_CALC_STR_LEN(strSrc, count, &srcLen);
if (SECUREC_CAT_STRING_IS_OVERLAP(strDest, destLen, strSrc, srcLen)) {
strDest[0] = '\0';
if (strDest + destLen <= strSrc && destLen == destMax) {
SECUREC_ERROR_INVALID_PARAMTER("strncat_s");
return EINVAL_AND_RESET;
}
SECUREC_ERROR_BUFFER_OVERLAP("strncat_s");
return EOVERLAP_AND_RESET;
}
if (srcLen + destLen >= destMax || strDest == strSrc) {
strDest[0] = '\0';
if (destLen == destMax) {
SECUREC_ERROR_INVALID_PARAMTER("strncat_s");
return EINVAL_AND_RESET;
}
SECUREC_ERROR_INVALID_RANGE("strncat_s");
return ERANGE_AND_RESET;
}
SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, srcLen); /* No terminator */
*(strDest + destLen + srcLen) = '\0';
return EOK;
}
/*
* <FUNCTION DESCRIPTION>
* The strncat_s function appends not more than n successive characters
* (not including the terminating null character)
* from the array pointed to by strSrc to the end of the string pointed to by strDest
* The strncat_s function try to append the first D characters of strSrc to
* the end of strDest, where D is the lesser of count and the length of strSrc.
* If appending those D characters will fit within strDest (whose size is given
* as destMax) and still leave room for a null terminator, then those characters
* are appended, starting at the original terminating null of strDest, and a
* new terminating null is appended; otherwise, strDest[0] is set to the null
* character.
*
* <INPUT PARAMETERS>
* strDest Null-terminated destination string.
* destMax Size of the destination buffer.
* strSrc Null-terminated source string.
* count Number of character to append, or truncate.
*
* <OUTPUT PARAMETERS>
* strDest is updated
*
* <RETURN VALUE>
* EOK Success
* EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN
* EINVAL_AND_RESET (strDest unterminated and all other parameters are valid)or
* (strDest != NULL and strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN)
* ERANGE destMax is 0 and destMax > SECUREC_STRING_MAX_LEN
* ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
*
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count)
{
if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("strncat_s");
return ERANGE;
}
if (strDest == NULL || strSrc == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("strncat_s");
if (strDest != NULL) {
strDest[0] = '\0';
return EINVAL_AND_RESET;
}
return EINVAL;
}
if (count > SECUREC_STRING_MAX_LEN) {
#ifdef SECUREC_COMPATIBLE_WIN_FORMAT
if (count == (size_t)(-1)) {
/* Windows internal functions may pass in -1 when calling this function */
return SecDoCatLimit(strDest, destMax, strSrc, destMax);
}
#endif
strDest[0] = '\0';
SECUREC_ERROR_INVALID_RANGE("strncat_s");
return ERANGE_AND_RESET;
}
return SecDoCatLimit(strDest, destMax, strSrc, count);
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(strncat_s);
#endif

View File

@@ -1,141 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: strncpy_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securecutil.h"
#if defined(SECUREC_COMPATIBLE_WIN_FORMAT)
#define SECUREC_STRNCPY_PARAM_OK(strDest, destMax, strSrc, count) \
(((destMax) > 0 && (destMax) <= SECUREC_STRING_MAX_LEN && (strDest) != NULL && (strSrc) != NULL && \
((count) <= SECUREC_STRING_MAX_LEN || (count) == ((size_t)(-1))) && (count) > 0))
#else
#define SECUREC_STRNCPY_PARAM_OK(strDest, destMax, strSrc, count) \
(((destMax) > 0 && (destMax) <= SECUREC_STRING_MAX_LEN && (strDest) != NULL && (strSrc) != NULL && \
(count) <= SECUREC_STRING_MAX_LEN && (count) > 0))
#endif
/*
* Check Src Count Range
*/
SECUREC_INLINE errno_t CheckSrcCountRange(char *strDest, size_t destMax, const char *strSrc, size_t count)
{
size_t tmpDestMax = destMax;
size_t tmpCount = count;
const char *endPos = strSrc;
/* Use destMax and count as boundary checker and destMax must be greater than zero */
while (*(endPos) != '\0' && tmpDestMax > 0 && tmpCount > 0) {
++endPos;
--tmpCount;
--tmpDestMax;
}
if (tmpDestMax == 0) {
strDest[0] = '\0';
SECUREC_ERROR_INVALID_RANGE("strncpy_s");
return ERANGE_AND_RESET;
}
return EOK;
}
/*
* Handling errors, when dest euqal src return EOK
*/
errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, size_t count)
{
if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("strncpy_s");
return ERANGE;
}
if (strDest == NULL || strSrc == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("strncpy_s");
if (strDest != NULL) {
strDest[0] = '\0';
return EINVAL_AND_RESET;
}
return EINVAL;
}
if (count > SECUREC_STRING_MAX_LEN) {
strDest[0] = '\0'; /* Clear dest string */
SECUREC_ERROR_INVALID_RANGE("strncpy_s");
return ERANGE_AND_RESET;
}
if (count == 0) {
strDest[0] = '\0';
return EOK;
}
return CheckSrcCountRange(strDest, destMax, strSrc, count);
}
/*
* <FUNCTION DESCRIPTION>
* The strncpy_s function copies not more than n successive characters (not including the terminating null character)
* from the array pointed to by strSrc to the array pointed to by strDest.
*
* <INPUT PARAMETERS>
* strDest Destination string.
* destMax The size of the destination string, in characters.
* strSrc Source string.
* count Number of characters to be copied.
*
* <OUTPUT PARAMETERS>
* strDest is updated
*
* <RETURN VALUE>
* EOK Success
* EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN
* EINVAL_AND_RESET strDest != NULL and strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN
* ERANGE destMax is 0 and destMax > SECUREC_STRING_MAX_LEN
* ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
*
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, size_t count)
{
if (SECUREC_STRNCPY_PARAM_OK(strDest, destMax, strSrc, count)) {
size_t minCpLen; /* Use it to store the maxi length limit */
if (count < destMax) {
SECUREC_CALC_STR_LEN(strSrc, count, &minCpLen); /* No ending terminator */
} else {
size_t tmpCount = destMax;
#ifdef SECUREC_COMPATIBLE_WIN_FORMAT
if (count == ((size_t)(-1))) {
tmpCount = destMax - 1;
}
#endif
SECUREC_CALC_STR_LEN(strSrc, tmpCount, &minCpLen); /* No ending terminator */
if (minCpLen == destMax) {
strDest[0] = '\0';
SECUREC_ERROR_INVALID_RANGE("strncpy_s");
return ERANGE_AND_RESET;
}
}
if (SECUREC_STRING_NO_OVERLAP(strDest, strSrc, minCpLen) || strDest == strSrc) {
/* Not overlap */
SECUREC_MEMCPY_WARP_OPT(strDest, strSrc, minCpLen); /* Copy string without terminator */
strDest[minCpLen] = '\0';
return EOK;
} else {
strDest[0] = '\0';
SECUREC_ERROR_BUFFER_OVERLAP("strncpy_s");
return EOVERLAP_AND_RESET;
}
}
return strncpy_error(strDest, destMax, strSrc, count);
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(strncpy_s);
#endif

View File

@@ -1,117 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: strtok_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securecutil.h"
SECUREC_INLINE int SecIsInDelimit(char ch, const char *strDelimit)
{
const char *ctl = strDelimit;
while (*ctl != '\0' && *ctl != ch) {
++ctl;
}
return (int)(*ctl != '\0');
}
/*
* Find beginning of token (skip over leading delimiters).
* Note that there is no token if this loop sets string to point to the terminal null.
*/
SECUREC_INLINE char *SecFindBegin(char *strToken, const char *strDelimit)
{
char *token = strToken;
while (*token != '\0') {
if (SecIsInDelimit(*token, strDelimit) != 0) {
++token;
continue;
}
/* Don't find any delimiter in string header, break the loop */
break;
}
return token;
}
/*
* Find rest of token
*/
SECUREC_INLINE char *SecFindRest(char *strToken, const char *strDelimit)
{
/* Find the rest of the token. If it is not the end of the string, put a null there */
char *token = strToken;
while (*token != '\0') {
if (SecIsInDelimit(*token, strDelimit) != 0) {
/* Find a delimiter, set string termintor */
*token = '\0';
++token;
break;
}
++token;
}
return token;
}
/*
* Find the final position pointer
*/
SECUREC_INLINE char *SecUpdateToken(char *strToken, const char *strDelimit, char **context)
{
/* Point to updated position. Record string position for next search in the context */
*context = SecFindRest(strToken, strDelimit);
/* Determine if a token has been found. */
if (*context == strToken) {
return NULL;
}
return strToken;
}
/*
* <FUNCTION DESCRIPTION>
* The strtok_s function parses a string into a sequence of strToken,
* replace all characters in strToken string that match to strDelimit set with 0.
* On the first call to strtok_s the string to be parsed should be specified in strToken.
* In each subsequent call that should parse the same string, strToken should be NULL
* <INPUT PARAMETERS>
* strToken String containing token or tokens.
* strDelimit Set of delimiter characters.
* context Used to store position information between calls
* to strtok_s
* <OUTPUT PARAMETERS>
* context is updated
* <RETURN VALUE>
* On the first call returns the address of the first non \0 character, otherwise NULL is returned.
* In subsequent calls, the strtoken is set to NULL, and the context set is the same as the previous call,
* return NULL if the *context string length is equal 0, otherwise return *context.
*/
char *strtok_s(char *strToken, const char *strDelimit, char **context)
{
char *orgToken = strToken;
/* Validate delimiter and string context */
if (context == NULL || strDelimit == NULL) {
return NULL;
}
/* Valid input string and string pointer from where to search */
if (orgToken == NULL && *context == NULL) {
return NULL;
}
/* If string is null, continue searching from previous string position stored in context */
if (orgToken == NULL) {
orgToken = *context;
}
orgToken = SecFindBegin(orgToken, strDelimit);
return SecUpdateToken(orgToken, strDelimit, context);
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(strtok_s);
#endif

View File

@@ -1,49 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: swprintf_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securec.h"
/*
* <FUNCTION DESCRIPTION>
* The swprintf_s function is the wide-character equivalent of the sprintf_s function
*
* <INPUT PARAMETERS>
* strDest Storage location for the output.
* destMax Maximum number of characters to store.
* format Format-control string.
* ... Optional arguments
*
* <OUTPUT PARAMETERS>
* strDest is updated
*
* <RETURN VALUE>
* return the number of wide characters stored in strDest, not counting the terminating null wide character.
* return -1 if an error occurred.
*
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vswprintf_s(strDest, destMax, format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}

View File

@@ -1,55 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: swscanf_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securec.h"
/*
* <FUNCTION DESCRIPTION>
* The swscanf_s function is the wide-character equivalent of the sscanf_s function
* The swscanf_s function reads data from buffer into the location given by
* each argument. Every argument must be a pointer to a variable with a type
* that corresponds to a type specifier in format. The format argument controls
* the interpretation of the input fields and has the same form and function
* as the format argument for the scanf function. If copying takes place between
* strings that overlap, the behavior is undefined.
*
* <INPUT PARAMETERS>
* buffer Stored data.
* format Format control string, see Format Specifications.
* ... Optional arguments.
*
* <OUTPUT PARAMETERS>
* ... the converted value stored in user assigned address
*
* <RETURN VALUE>
* Each of these functions returns the number of fields successfully converted
* and assigned; The return value does not include fields that were read but not
* assigned.
* A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vswscanf_s(buffer, format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}

View File

@@ -1,65 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: vfscanf_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "secinput.h"
/*
* <FUNCTION DESCRIPTION>
* The vfscanf_s function is equivalent to fscanf_s, with the variable argument list replaced by argList
* The vfscanf_s function reads data from the current position of stream into
* the locations given by argument (if any). Each argument must be a pointer
* to a variable of a type that corresponds to a type specifier in format.
* format controls the interpretation of the input fields and has the same
* form and function as the format argument for scanf.
*
* <INPUT PARAMETERS>
* stream Pointer to FILE structure.
* format Format control string, see Format Specifications.
* argList pointer to list of arguments
*
* <OUTPUT PARAMETERS>
* argList the converted value stored in user assigned address
*
* <RETURN VALUE>
* Each of these functions returns the number of fields successfully converted
* and assigned; the return value does not include fields that were read but
* not assigned. A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int vfscanf_s(FILE *stream, const char *format, va_list argList)
{
int retVal; /* If initialization causes e838 */
SecFileStream fStr;
if (stream == NULL || format == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("vfscanf_s");
return SECUREC_SCANF_EINVAL;
}
if (stream == SECUREC_STREAM_STDIN) {
return vscanf_s(format, argList);
}
SECUREC_LOCK_FILE(stream);
SECUREC_FILE_STREAM_FROM_FILE(&fStr, stream);
retVal = SecInputS(&fStr, format, argList);
SECUREC_UNLOCK_FILE(stream);
if (retVal < 0) {
SECUREC_ERROR_INVALID_PARAMTER("vfscanf_s");
return SECUREC_SCANF_EINVAL;
}
return retVal;
}

View File

@@ -1,68 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: vfwscanf_s function
* Author: lishunda
* Create: 2014-02-25
*/
#ifndef SECUREC_FOR_WCHAR
#define SECUREC_FOR_WCHAR
#endif
#include "secinput.h"
/*
* <FUNCTION DESCRIPTION>
* The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function
* The vfwscanf_s function reads data from the current position of stream into
* the locations given by argument (if any). Each argument must be a pointer
* to a variable of a type that corresponds to a type specifier in format.
* format controls the interpretation of the input fields and has the same form
* and function as the format argument for scanf.
*
* <INPUT PARAMETERS>
* stream Pointer to FILE structure.
* format Format control string, see Format Specifications.
* argList pointer to list of arguments
*
* <OUTPUT PARAMETERS>
* argList the converted value stored in user assigned address
*
* <RETURN VALUE>
* Each of these functions returns the number of fields successfully converted
* and assigned; the return value does not include fields that were read but
* not assigned. A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList)
{
int retVal; /* If initialization causes e838 */
SecFileStream fStr;
if (stream == NULL || format == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s");
return SECUREC_SCANF_EINVAL;
}
if (stream == SECUREC_STREAM_STDIN) {
return vwscanf_s(format, argList);
}
SECUREC_LOCK_FILE(stream);
SECUREC_FILE_STREAM_FROM_FILE(&fStr, stream);
retVal = SecInputSW(&fStr, format, argList);
SECUREC_UNLOCK_FILE(stream);
if (retVal < 0) {
SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s");
return SECUREC_SCANF_EINVAL;
}
return retVal;
}

View File

@@ -1,64 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: vscanf_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "secinput.h"
/*
* <FUNCTION DESCRIPTION>
* The vscanf_s function is equivalent to scanf_s, with the variable argument list replaced by argList,
* The vscanf_s function reads data from the standard input stream stdin and
* writes the data into the location that's given by argument. Each argument
* must be a pointer to a variable of a type that corresponds to a type specifier
* in format. If copying occurs between strings that overlap, the behavior is
* undefined.
*
* <INPUT PARAMETERS>
* format Format control string.
* argList pointer to list of arguments
*
* <OUTPUT PARAMETERS>
* argList the converted value stored in user assigned address
*
* <RETURN VALUE>
* Returns the number of fields successfully converted and assigned;
* the return value does not include fields that were read but not assigned.
* A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int vscanf_s(const char *format, va_list argList)
{
int retVal; /* If initialization causes e838 */
SecFileStream fStr;
SECUREC_FILE_STREAM_FROM_STDIN(&fStr);
/*
* The "va_list" has different definition on different platform, so we can't use argList == NULL
* To determine it's invalid. If you has fixed platform, you can check some fields to validate it,
* such as "argList == NULL" or argList.xxx != NULL or *(size_t *)&argList != 0.
*/
if (format == NULL || fStr.pf == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("vscanf_s");
return SECUREC_SCANF_EINVAL;
}
SECUREC_LOCK_STDIN(0, fStr.pf);
retVal = SecInputS(&fStr, format, argList);
SECUREC_UNLOCK_STDIN(0, fStr.pf);
if (retVal < 0) {
SECUREC_ERROR_INVALID_PARAMTER("vscanf_s");
return SECUREC_SCANF_EINVAL;
}
return retVal;
}

View File

@@ -1,139 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: vsnprintf_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "secureprintoutput.h"
#if SECUREC_ENABLE_VSNPRINTF
/*
* <FUNCTION DESCRIPTION>
* The vsnprintf_s function is equivalent to the vsnprintf function
* except for the parameter destMax/count and the explicit runtime-constraints violation
* The vsnprintf_s function takes a pointer to an argument list, then formats
* and writes up to count characters of the given data to the memory pointed
* to by strDest and appends a terminating null.
*
* <INPUT PARAMETERS>
* strDest Storage location for the output.
* destMax The size of the strDest for output.
* count Maximum number of character to write(not including
* the terminating NULL)
* format Format-control string.
* argList pointer to list of arguments.
*
* <OUTPUT PARAMETERS>
* strDest is updated
*
* <RETURN VALUE>
* return the number of characters written, not including the terminating null
* return -1 if an error occurs.
* return -1 if count < destMax and the output string has been truncated
*
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format, va_list argList)
{
int retVal;
if (SECUREC_VSNPRINTF_PARAM_ERROR(format, strDest, destMax, count, SECUREC_STRING_MAX_LEN)) {
SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_STRING_MAX_LEN);
SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_s");
return -1;
}
if (destMax > count) {
retVal = SecVsnprintfImpl(strDest, count + 1, format, argList);
if (retVal == SECUREC_PRINTF_TRUNCATE) { /* To keep dest buffer not destroyed 2014.2.18 */
/* The string has been truncated, return -1 */
return -1; /* To skip error handler, return strlen(strDest) or -1 */
}
} else {
retVal = SecVsnprintfImpl(strDest, destMax, format, argList);
#ifdef SECUREC_COMPATIBLE_WIN_FORMAT
if (retVal == SECUREC_PRINTF_TRUNCATE && count == (size_t)(-1)) {
return -1;
}
#endif
}
if (retVal < 0) {
strDest[0] = '\0'; /* Empty the dest strDest */
if (retVal == SECUREC_PRINTF_TRUNCATE) {
/* Buffer too small */
SECUREC_ERROR_INVALID_RANGE("vsnprintf_s");
}
SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_s");
return -1;
}
return retVal;
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(vsnprintf_s);
#endif
#endif
#if SECUREC_SNPRINTF_TRUNCATED
/*
* <FUNCTION DESCRIPTION>
* The vsnprintf_truncated_s function is equivalent to the vsnprintf function
* except for the parameter destMax/count and the explicit runtime-constraints violation
* The vsnprintf_truncated_s function takes a pointer to an argument list, then formats
* and writes up to count characters of the given data to the memory pointed
* to by strDest and appends a terminating null.
*
* <INPUT PARAMETERS>
* strDest Storage location for the output.
* destMax The size of the strDest for output.
* the terminating NULL)
* format Format-control string.
* argList pointer to list of arguments.
*
* <OUTPUT PARAMETERS>
* strDest is updated
*
* <RETURN VALUE>
* return the number of characters written, not including the terminating null
* return -1 if an error occurs.
* return destMax-1 if output string has been truncated
*
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format, va_list argList)
{
int retVal;
if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, SECUREC_STRING_MAX_LEN)) {
SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_STRING_MAX_LEN);
SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_truncated_s");
return -1;
}
retVal = SecVsnprintfImpl(strDest, destMax, format, argList);
if (retVal < 0) {
if (retVal == SECUREC_PRINTF_TRUNCATE) {
return (int)(destMax - 1); /* To skip error handler, return strlen(strDest) */
}
strDest[0] = '\0'; /* Empty the dest strDest */
SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_truncated_s");
return -1;
}
return retVal;
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(vsnprintf_truncated_s);
#endif
#endif

View File

@@ -1,68 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: vsprintf_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "secureprintoutput.h"
/*
* <FUNCTION DESCRIPTION>
* The vsprintf_s function is equivalent to the vsprintf function
* except for the parameter destMax and the explicit runtime-constraints violation
* The vsprintf_s function takes a pointer to an argument list, and then formats
* and writes the given data to the memory pointed to by strDest.
* The function differ from the non-secure versions only in that the secure
* versions support positional parameters.
*
* <INPUT PARAMETERS>
* strDest Storage location for the output.
* destMax Size of strDest
* format Format specification.
* argList pointer to list of arguments
*
* <OUTPUT PARAMETERS>
* strDest is updated
*
* <RETURN VALUE>
* return the number of characters written, not including the terminating null character,
* return -1 if an error occurs.
*
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
int vsprintf_s(char *strDest, size_t destMax, const char *format, va_list argList)
{
int retVal; /* If initialization causes e838 */
if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, SECUREC_STRING_MAX_LEN)) {
SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_STRING_MAX_LEN);
SECUREC_ERROR_INVALID_PARAMTER("vsprintf_s");
return -1;
}
retVal = SecVsnprintfImpl(strDest, destMax, format, argList);
if (retVal < 0) {
strDest[0] = '\0';
if (retVal == SECUREC_PRINTF_TRUNCATE) {
/* Buffer is too small */
SECUREC_ERROR_INVALID_RANGE("vsprintf_s");
}
SECUREC_ERROR_INVALID_PARAMTER("vsprintf_s");
return -1;
}
return retVal;
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(vsprintf_s);
#endif

View File

@@ -1,88 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: vsscanf_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "secinput.h"
#if defined(SECUREC_VXWORKS_PLATFORM) && !SECUREC_IN_KERNEL && \
(!defined(SECUREC_SYSAPI4VXWORKS) && !defined(SECUREC_CTYPE_MACRO_ADAPT))
#include <ctype.h>
#endif
/*
* <NAME>
* vsscanf_s
*
*
* <FUNCTION DESCRIPTION>
* The vsscanf_s function is equivalent to sscanf_s, with the variable argument list replaced by argList
* The vsscanf_s function reads data from buffer into the location given by
* each argument. Every argument must be a pointer to a variable with a type
* that corresponds to a type specifier in format. The format argument controls
* the interpretation of the input fields and has the same form and function
* as the format argument for the scanf function.
* If copying takes place between strings that overlap, the behavior is undefined.
*
* <INPUT PARAMETERS>
* buffer Stored data
* format Format control string, see Format Specifications.
* argList pointer to list of arguments
*
* <OUTPUT PARAMETERS>
* argList the converted value stored in user assigned address
*
* <RETURN VALUE>
* Each of these functions returns the number of fields successfully converted
* and assigned; the return value does not include fields that were read but
* not assigned. A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int vsscanf_s(const char *buffer, const char *format, va_list argList)
{
size_t count; /* If initialization causes e838 */
int retVal;
SecFileStream fStr;
/* Validation section */
if (buffer == NULL || format == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s");
return SECUREC_SCANF_EINVAL;
}
count = strlen(buffer);
if (count == 0 || count > SECUREC_STRING_MAX_LEN) {
SecClearDestBuf(buffer, format, argList);
SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s");
return SECUREC_SCANF_EINVAL;
}
#if defined(SECUREC_VXWORKS_PLATFORM) && !SECUREC_IN_KERNEL
/*
* On vxworks platform when buffer is white string, will set first %s argument tu zero.like following useage:
* " \v\f\t\r\n", "%s", str, strSize
* Do not check all character, just first and last character then consider it is white string
*/
if (isspace((int)(unsigned char)buffer[0]) != 0 && isspace((int)(unsigned char)buffer[count - 1]) != 0) {
SecClearDestBuf(buffer, format, argList);
}
#endif
SECUREC_FILE_STREAM_FROM_STRING(&fStr, buffer, count);
retVal = SecInputS(&fStr, format, argList);
if (retVal < 0) {
SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s");
return SECUREC_SCANF_EINVAL;
}
return retVal;
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(vsscanf_s);
#endif

View File

@@ -1,63 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: vswprintf_s function
* Author: lishunda
* Create: 2014-02-25
*/
#ifndef SECUREC_FOR_WCHAR
#define SECUREC_FOR_WCHAR
#endif
#include "secureprintoutput.h"
/*
* <FUNCTION DESCRIPTION>
* The vswprintf_s function is the wide-character equivalent of the vsprintf_s function
*
* <INPUT PARAMETERS>
* strDest Storage location for the output.
* destMax Maximum number of characters to store
* format Format specification.
* argList pointer to list of arguments
*
* <OUTPUT PARAMETERS>
* strDest is updated
*
* <RETURN VALUE>
* return the number of wide characters stored in strDest, not counting the terminating null wide character.
* return -1 if an error occurred.
*
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList)
{
int retVal; /* If initialization causes e838 */
if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, SECUREC_WCHAR_STRING_MAX_LEN)) {
SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_WCHAR_STRING_MAX_LEN);
SECUREC_ERROR_INVALID_PARAMTER("vswprintf_s");
return -1;
}
retVal = SecVswprintfImpl(strDest, destMax, format, argList);
if (retVal < 0) {
strDest[0] = L'\0';
if (retVal == SECUREC_PRINTF_TRUNCATE) {
/* Buffer too small */
SECUREC_ERROR_INVALID_RANGE("vswprintf_s");
}
SECUREC_ERROR_INVALID_PARAMTER("vswprintf_s");
return -1;
}
return retVal;
}

View File

@@ -1,80 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: vswscanf_s function
* Author: lishunda
* Create: 2014-02-25
*/
#ifndef SECUREC_FOR_WCHAR
#define SECUREC_FOR_WCHAR
#endif
#include "secinput.h"
SECUREC_INLINE size_t SecWcslen(const wchar_t *s)
{
const wchar_t *end = s;
while (*end != L'\0') {
++end;
}
return ((size_t)((end - s)));
}
/*
* <FUNCTION DESCRIPTION>
* The vswscanf_s function is the wide-character equivalent of the vsscanf_s function
* The vsscanf_s function reads data from buffer into the location given by
* each argument. Every argument must be a pointer to a variable with a type
* that corresponds to a type specifier in format.
* The format argument controls the interpretation of the input fields and
* has the same form and function as the format argument for the scanf function.
* If copying takes place between strings that overlap, the behavior is undefined.
*
* <INPUT PARAMETERS>
* buffer Stored data
* format Format control string, see Format Specifications.
* argList pointer to list of arguments
*
* <OUTPUT PARAMETERS>
* argList the converted value stored in user assigned address
*
* <RETURN VALUE>
* Each of these functions returns the number of fields successfully converted
* and assigned; the return value does not include fields that were read but
* not assigned. A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList)
{
size_t count; /* If initialization causes e838 */
SecFileStream fStr;
int retVal;
/* Validation section */
if (buffer == NULL || format == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s");
return SECUREC_SCANF_EINVAL;
}
count = SecWcslen(buffer);
if (count == 0 || count > SECUREC_WCHAR_STRING_MAX_LEN) {
SecClearDestBufW(buffer, format, argList);
SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s");
return SECUREC_SCANF_EINVAL;
}
SECUREC_FILE_STREAM_FROM_STRING(&fStr, (const char *)buffer, count * sizeof(wchar_t));
retVal = SecInputSW(&fStr, format, argList);
if (retVal < 0) {
SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s");
return SECUREC_SCANF_EINVAL;
}
return retVal;
}

View File

@@ -1,65 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: vwscanf_s function
* Author: lishunda
* Create: 2014-02-25
*/
#ifndef SECUREC_FOR_WCHAR
#define SECUREC_FOR_WCHAR
#endif
#include "secinput.h"
/*
* <FUNCTION DESCRIPTION>
* The vwscanf_s function is the wide-character equivalent of the vscanf_s function
* The vwscanf_s function is the wide-character version of vscanf_s. The
* function reads data from the standard input stream stdin and writes the
* data into the location that's given by argument. Each argument must be a
* pointer to a variable of a type that corresponds to a type specifier in
* format. If copying occurs between strings that overlap, the behavior is
* undefined.
*
* <INPUT PARAMETERS>
* format Format control string.
* argList pointer to list of arguments
*
* <OUTPUT PARAMETERS>
* argList the converted value stored in user assigned address
*
* <RETURN VALUE>
* Returns the number of fields successfully converted and assigned;
* the return value does not include fields that were read but not assigned.
* A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int vwscanf_s(const wchar_t *format, va_list argList)
{
int retVal; /* If initialization causes e838 */
SecFileStream fStr;
SECUREC_FILE_STREAM_FROM_STDIN(&fStr);
if (format == NULL || fStr.pf == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("vwscanf_s");
return SECUREC_SCANF_EINVAL;
}
SECUREC_LOCK_STDIN(0, fStr.pf);
retVal = SecInputSW(&fStr, format, argList);
SECUREC_UNLOCK_STDIN(0, fStr.pf);
if (retVal < 0) {
SECUREC_ERROR_INVALID_PARAMTER("vwscanf_s");
return SECUREC_SCANF_EINVAL;
}
return retVal;
}

View File

@@ -1,108 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: wcscat_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securecutil.h"
/*
* Befor this function, the basic parameter checking has been done
*/
SECUREC_INLINE errno_t SecDoCatW(wchar_t *strDest, size_t destMax, const wchar_t *strSrc)
{
size_t destLen;
size_t srcLen;
size_t maxCount; /* Store the maximum available count */
/* To calculate the length of a wide character, the parameter must be a wide character */
SECUREC_CALC_WSTR_LEN(strDest, destMax, &destLen);
maxCount = destMax - destLen;
SECUREC_CALC_WSTR_LEN(strSrc, maxCount, &srcLen);
if (SECUREC_CAT_STRING_IS_OVERLAP(strDest, destLen, strSrc, srcLen)) {
strDest[0] = L'\0';
if (strDest + destLen <= strSrc && destLen == destMax) {
SECUREC_ERROR_INVALID_PARAMTER("wcscat_s");
return EINVAL_AND_RESET;
}
SECUREC_ERROR_BUFFER_OVERLAP("wcscat_s");
return EOVERLAP_AND_RESET;
}
if (srcLen + destLen >= destMax || strDest == strSrc) {
strDest[0] = L'\0';
if (destLen == destMax) {
SECUREC_ERROR_INVALID_PARAMTER("wcscat_s");
return EINVAL_AND_RESET;
}
SECUREC_ERROR_INVALID_RANGE("wcscat_s");
return ERANGE_AND_RESET;
}
/* Copy single character length include \0 */
SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, (srcLen + 1) * sizeof(wchar_t));
return EOK;
}
/*
* <FUNCTION DESCRIPTION>
* The wcscat_s function appends a copy of the wide string pointed to by strSrc
* (including the terminating null wide character)
* to the end of the wide string pointed to by strDest.
* The arguments and return value of wcscat_s are wide-character strings.
*
* The wcscat_s function appends strSrc to strDest and terminates the resulting
* string with a null character. The initial character of strSrc overwrites the
* terminating null character of strDest. wcscat_s will return EOVERLAP_AND_RESET if the
* source and destination strings overlap.
*
* Note that the second parameter is the total size of the buffer, not the
* remaining size.
*
* <INPUT PARAMETERS>
* strDest Null-terminated destination string buffer.
* destMax Size of the destination string buffer.
* strSrc Null-terminated source string buffer.
*
* <OUTPUT PARAMETERS>
* strDest is updated
*
* <RETURN VALUE>
* EOK Success
* EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
* EINVAL_AND_RESET (strDest unterminated and all other parameters are valid) or
* (strDest != NULL and strSrc is NULLL and destMax != 0
* and destMax <= SECUREC_WCHAR_STRING_MAX_LEN)
* ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0
* ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
*
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc)
{
if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("wcscat_s");
return ERANGE;
}
if (strDest == NULL || strSrc == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("wcscat_s");
if (strDest != NULL) {
strDest[0] = L'\0';
return EINVAL_AND_RESET;
}
return EINVAL;
}
return SecDoCatW(strDest, destMax, strSrc);
}

View File

@@ -1,87 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: wcscpy_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securecutil.h"
SECUREC_INLINE errno_t SecDoCpyW(wchar_t *strDest, size_t destMax, const wchar_t *strSrc)
{
size_t srcStrLen;
SECUREC_CALC_WSTR_LEN(strSrc, destMax, &srcStrLen);
if (srcStrLen == destMax) {
strDest[0] = L'\0';
SECUREC_ERROR_INVALID_RANGE("wcscpy_s");
return ERANGE_AND_RESET;
}
if (strDest == strSrc) {
return EOK;
}
if (SECUREC_STRING_NO_OVERLAP(strDest, strSrc, srcStrLen)) {
/* Performance optimization, srcStrLen is single character length include '\0' */
SECUREC_MEMCPY_WARP_OPT(strDest, strSrc, (srcStrLen + 1) * sizeof(wchar_t));
return EOK;
} else {
strDest[0] = L'\0';
SECUREC_ERROR_BUFFER_OVERLAP("wcscpy_s");
return EOVERLAP_AND_RESET;
}
}
/*
* <FUNCTION DESCRIPTION>
* The wcscpy_s function copies the wide string pointed to by strSrc
* (including theterminating null wide character) into the array pointed to by strDest
* <INPUT PARAMETERS>
* strDest Destination string buffer
* destMax Size of the destination string buffer.
* strSrc Null-terminated source string buffer.
*
* <OUTPUT PARAMETERS>
* strDest is updated.
*
* <RETURN VALUE>
* EOK Success
* EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
* EINVAL_AND_RESET strDest != NULL and strSrc is NULLL and destMax != 0
* and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
* ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0
* ERANGE_AND_RESET destMax <= length of strSrc and strDest != strSrc
* and strDest != NULL and strSrc != NULL and destMax != 0
* and destMax <= SECUREC_WCHAR_STRING_MAX_LEN and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and destMax != 0
* and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
* and strDest != NULL and strSrc !=NULL and strDest != strSrc
*
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc)
{
if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("wcscpy_s");
return ERANGE;
}
if (strDest == NULL || strSrc == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("wcscpy_s");
if (strDest != NULL) {
strDest[0] = L'\0';
return EINVAL_AND_RESET;
}
return EINVAL;
}
return SecDoCpyW(strDest, destMax, strSrc);
}

View File

@@ -1,114 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: wcsncat_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securecutil.h"
/*
* Befor this function, the basic parameter checking has been done
*/
SECUREC_INLINE errno_t SecDoCatLimitW(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count)
{
/* To calculate the length of a wide character, the parameter must be a wide character */
size_t destLen;
size_t srcLen;
SECUREC_CALC_WSTR_LEN(strDest, destMax, &destLen);
SECUREC_CALC_WSTR_LEN(strSrc, count, &srcLen);
if (SECUREC_CAT_STRING_IS_OVERLAP(strDest, destLen, strSrc, srcLen)) {
strDest[0] = L'\0';
if (strDest + destLen <= strSrc && destLen == destMax) {
SECUREC_ERROR_INVALID_PARAMTER("wcsncat_s");
return EINVAL_AND_RESET;
}
SECUREC_ERROR_BUFFER_OVERLAP("wcsncat_s");
return EOVERLAP_AND_RESET;
}
if (srcLen + destLen >= destMax || strDest == strSrc) {
strDest[0] = L'\0';
if (destLen == destMax) {
SECUREC_ERROR_INVALID_PARAMTER("wcsncat_s");
return EINVAL_AND_RESET;
}
SECUREC_ERROR_INVALID_RANGE("wcsncat_s");
return ERANGE_AND_RESET;
}
SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, srcLen * sizeof(wchar_t)); /* no terminator */
*(strDest + destLen + srcLen) = L'\0';
return EOK;
}
/*
* <FUNCTION DESCRIPTION>
* The wcsncat_s function appends not more than n successive wide characters
* (not including the terminating null wide character)
* from the array pointed to by strSrc to the end of the wide string pointed to by strDest.
*
* The wcsncat_s function try to append the first D characters of strSrc to
* the end of strDest, where D is the lesser of count and the length of strSrc.
* If appending those D characters will fit within strDest (whose size is
* given as destMax) and still leave room for a null terminator, then those
* characters are appended, starting at the original terminating null of
* strDest, and a new terminating null is appended; otherwise, strDest[0] is
* set to the null character.
*
* <INPUT PARAMETERS>
* strDest Null-terminated destination string.
* destMax Size of the destination buffer.
* strSrc Null-terminated source string.
* count Number of character to append, or truncate.
*
* <OUTPUT PARAMETERS>
* strDest is updated
*
* <RETURN VALUE>
* EOK Success
* EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
* EINVAL_AND_RESET (strDest unterminated and all other parameters are valid) or
* (strDest != NULL and strSrc is NULLL and destMax != 0 and
* destMax <= SECUREC_WCHAR_STRING_MAX_LEN)
* ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0
* ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
*
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count)
{
if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("wcsncat_s");
return ERANGE;
}
if (strDest == NULL || strSrc == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("wcsncat_s");
if (strDest != NULL) {
strDest[0] = L'\0';
return EINVAL_AND_RESET;
}
return EINVAL;
}
if (count > SECUREC_WCHAR_STRING_MAX_LEN) {
#ifdef SECUREC_COMPATIBLE_WIN_FORMAT
if (count == ((size_t)(-1))) {
/* Windows internal functions may pass in -1 when calling this function */
return SecDoCatLimitW(strDest, destMax, strSrc, destMax);
}
#endif
strDest[0] = L'\0';
SECUREC_ERROR_INVALID_RANGE("wcsncat_s");
return ERANGE_AND_RESET;
}
return SecDoCatLimitW(strDest, destMax, strSrc, count);
}

View File

@@ -1,108 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: wcsncpy_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securecutil.h"
SECUREC_INLINE errno_t SecDoCpyLimitW(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count)
{
size_t srcStrLen;
if (count < destMax) {
SECUREC_CALC_WSTR_LEN(strSrc, count, &srcStrLen);
} else {
SECUREC_CALC_WSTR_LEN(strSrc, destMax, &srcStrLen);
}
if (srcStrLen == destMax) {
strDest[0] = L'\0';
SECUREC_ERROR_INVALID_RANGE("wcsncpy_s");
return ERANGE_AND_RESET;
}
if (strDest == strSrc) {
return EOK;
}
if (SECUREC_STRING_NO_OVERLAP(strDest, strSrc, srcStrLen)) {
/* Performance optimization srcStrLen not include '\0' */
SECUREC_MEMCPY_WARP_OPT(strDest, strSrc, srcStrLen * sizeof(wchar_t));
*(strDest + srcStrLen) = L'\0';
return EOK;
} else {
strDest[0] = L'\0';
SECUREC_ERROR_BUFFER_OVERLAP("wcsncpy_s");
return EOVERLAP_AND_RESET;
}
}
/*
* <FUNCTION DESCRIPTION>
* The wcsncpy_s function copies not more than n successive wide characters
* (not including the terminating null wide character)
* from the array pointed to by strSrc to the array pointed to by strDest
*
* <INPUT PARAMETERS>
* strDest Destination string.
* destMax The size of the destination string, in characters.
* strSrc Source string.
* count Number of characters to be copied.
*
* <OUTPUT PARAMETERS>
* strDest is updated
*
* <RETURN VALUE>
* EOK Success
* EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
* EINVAL_AND_RESET strDest != NULL and strSrc is NULLL and destMax != 0
* and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
* ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0
* ERANGE_AND_RESET count > SECUREC_WCHAR_STRING_MAX_LEN or
* (destMax <= length of strSrc and destMax <= count and strDest != strSrc
* and strDest != NULL and strSrc != NULL and destMax != 0 and
* destMax <= SECUREC_WCHAR_STRING_MAX_LEN and not overlap)
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
*
*
* If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
*/
errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count)
{
if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("wcsncpy_s");
return ERANGE;
}
if (strDest == NULL || strSrc == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("wcsncpy_s");
if (strDest != NULL) {
strDest[0] = L'\0';
return EINVAL_AND_RESET;
}
return EINVAL;
}
if (count > SECUREC_WCHAR_STRING_MAX_LEN) {
#ifdef SECUREC_COMPATIBLE_WIN_FORMAT
if (count == (size_t)(-1)) {
return SecDoCpyLimitW(strDest, destMax, strSrc, destMax - 1);
}
#endif
strDest[0] = L'\0'; /* Clear dest string */
SECUREC_ERROR_INVALID_RANGE("wcsncpy_s");
return ERANGE_AND_RESET;
}
if (count == 0) {
strDest[0] = L'\0';
return EOK;
}
return SecDoCpyLimitW(strDest, destMax, strSrc, count);
}

View File

@@ -1,113 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: wcstok_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securecutil.h"
SECUREC_INLINE int SecIsInDelimitW(wchar_t ch, const wchar_t *strDelimit)
{
const wchar_t *ctl = strDelimit;
while (*ctl != L'\0' && *ctl != ch) {
++ctl;
}
return (int)(*ctl != L'\0');
}
/*
* Find beginning of token (skip over leading delimiters).
* Note that there is no token if this loop sets string to point to the terminal null.
*/
SECUREC_INLINE wchar_t *SecFindBeginW(wchar_t *strToken, const wchar_t *strDelimit)
{
wchar_t *token = strToken;
while (*token != L'\0') {
if (SecIsInDelimitW(*token, strDelimit) != 0) {
++token;
continue;
}
/* Don't find any delimiter in string header, break the loop */
break;
}
return token;
}
/*
* Find the end of the token. If it is not the end of the string, put a null there.
*/
SECUREC_INLINE wchar_t *SecFindRestW(wchar_t *strToken, const wchar_t *strDelimit)
{
wchar_t *token = strToken;
while (*token != L'\0') {
if (SecIsInDelimitW(*token, strDelimit) != 0) {
/* Find a delimiter, set string termintor */
*token = L'\0';
++token;
break;
}
++token;
}
return token;
}
/*
* Update Token wide character function
*/
SECUREC_INLINE wchar_t *SecUpdateTokenW(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context)
{
/* Point to updated position. Record string position for next search in the context */
*context = SecFindRestW(strToken, strDelimit);
/* Determine if a token has been found */
if (*context == strToken) {
return NULL;
}
return strToken;
}
/*
* <NAME>
* wcstok_s
*
*
* <FUNCTION DESCRIPTION>
* The wcstok_s function is the wide-character equivalent of the strtok_s function
*
* <INPUT PARAMETERS>
* strToken String containing token or tokens.
* strDelimit Set of delimiter characters.
* context Used to store position information between calls to
* wcstok_s.
*
* <OUTPUT PARAMETERS>
* context is updated
* <RETURN VALUE>
* The wcstok_s function is the wide-character equivalent of the strtok_s function
*/
wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context)
{
wchar_t *orgToken = strToken;
/* Validation section */
if (context == NULL || strDelimit == NULL) {
return NULL;
}
if (orgToken == NULL && *context == NULL) {
return NULL;
}
/* If string==NULL, continue with previous string */
if (orgToken == NULL) {
orgToken = *context;
}
orgToken = SecFindBeginW(orgToken, strDelimit);
return SecUpdateTokenW(orgToken, strDelimit, context);
}

View File

@@ -1,67 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: wmemcpy_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securecutil.h"
/*
* <FUNCTION DESCRIPTION>
* The wmemcpy_s function copies n successive wide characters
* from the object pointed to by src into the object pointed to by dest.t.
*
* <INPUT PARAMETERS>
* dest Destination buffer.
* destMax Size of the destination buffer.
* src Buffer to copy from.
* count Number of characters to copy.
*
* <OUTPUT PARAMETERS>
* dest buffer is uptdated.
*
* <RETURN VALUE>
* EOK Success
* EINVAL dest is NULL and destMax != 0 and count <= destMax
* and destMax <= SECUREC_WCHAR_MEM_MAX_LEN
* EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0
* and destMax <= SECUREC_WCHAR_MEM_MAX_LEN and count <= destMax
* ERANGE destMax > SECUREC_WCHAR_MEM_MAX_LEN or destMax is 0 or
* (count > destMax and dest is NULL and destMax != 0
* and destMax <= SECUREC_WCHAR_MEM_MAX_LEN)
* ERANGE_AND_RESET count > destMax and dest != NULL and destMax != 0
* and destMax <= SECUREC_WCHAR_MEM_MAX_LEN
* EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and
* count <= destMax destMax != 0 and destMax <= SECUREC_WCHAR_MEM_MAX_LEN
* and dest != NULL and src != NULL and dest != src
*
* if an error occured, dest will be filled with 0 when dest and destMax valid .
* If the source and destination overlap, the behavior of wmemcpy_s is undefined.
* Use wmemmove_s to handle overlapping regions.
*/
errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count)
{
if (destMax == 0 || destMax > SECUREC_WCHAR_MEM_MAX_LEN) {
SECUREC_ERROR_INVALID_PARAMTER("wmemcpy_s");
return ERANGE;
}
if (count > destMax) {
SECUREC_ERROR_INVALID_PARAMTER("wmemcpy_s");
if (dest != NULL) {
(void)memset(dest, 0, destMax * sizeof(wchar_t));
return ERANGE_AND_RESET;
}
return ERANGE;
}
return memcpy_s(dest, destMax * sizeof(wchar_t), src, count * sizeof(wchar_t));
}

View File

@@ -1,66 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: wmemmove_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securecutil.h"
/*
* <FUNCTION DESCRIPTION>
* The wmemmove_s function copies n successive wide characters from the object pointed
* to by src into the object pointed to by dest.
*
* <INPUT PARAMETERS>
* dest Destination buffer.
* destMax Size of the destination buffer.
* src Source object.
* count Number of bytes or character to copy.
*
* <OUTPUT PARAMETERS>
* dest is updated.
*
* <RETURN VALUE>
* EOK Success
* EINVAL dest is NULL and destMax != 0 and count <= destMax
* and destMax <= SECUREC_WCHAR_MEM_MAX_LEN
* EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0
* and destMax <= SECUREC_WCHAR_MEM_MAX_LEN and count <= destMax
* ERANGE destMax > SECUREC_WCHAR_MEM_MAX_LEN or destMax is 0 or
* (count > destMax and dest is NULL and destMax != 0
* and destMax <= SECUREC_WCHAR_MEM_MAX_LEN)
* ERANGE_AND_RESET count > destMax and dest != NULL and destMax != 0
* and destMax <= SECUREC_WCHAR_MEM_MAX_LEN
*
*
* If an error occured, dest will be filled with 0 when dest and destMax valid.
* If some regions of the source area and the destination overlap, wmemmove_s
* ensures that the original source bytes in the overlapping region are copied
* before being overwritten
*/
errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count)
{
if (destMax == 0 || destMax > SECUREC_WCHAR_MEM_MAX_LEN) {
SECUREC_ERROR_INVALID_PARAMTER("wmemmove_s");
return ERANGE;
}
if (count > destMax) {
SECUREC_ERROR_INVALID_PARAMTER("wmemmove_s");
if (dest != NULL) {
(void)memset(dest, 0, destMax * sizeof(wchar_t));
return ERANGE_AND_RESET;
}
return ERANGE;
}
return memmove_s(dest, destMax * sizeof(wchar_t), src, count * sizeof(wchar_t));
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
* Licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Description: wscanf_s function
* Author: lishunda
* Create: 2014-02-25
*/
#include "securec.h"
/*
* <NAME>
* <FUNCTION DESCRIPTION>
* The wscanf_s function is the wide-character equivalent of the scanf_s function
* The wscanf_s function reads data from the standard input stream stdin and
* writes the data into the location that's given by argument. Each argument
* must be a pointer to a variable of a type that corresponds to a type specifier
* in format. If copying occurs between strings that overlap, the behavior is
* undefined.
*
* <INPUT PARAMETERS>
* format Format control string.
* ... Optional arguments.
*
* <OUTPUT PARAMETERS>
* ... the converted value stored in user assigned address
*
* <RETURN VALUE>
* Returns the number of fields successfully converted and assigned;
* the return value does not include fields that were read but not assigned.
* A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int wscanf_s(const wchar_t *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vwscanf_s(format, argList);
va_end(argList);
(void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
# 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:
@@ -27,11 +27,10 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_m/config.gni")
static_library("cppsupport") {
sources = [ "los_cppsupport.c" ]
include_dirs = [
"../../utils",
"./",
]
configs += [ "$LITEOSTOPDIR:los_config" ]
}

View File

@@ -31,12 +31,6 @@
#include "los_cppsupport.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef VOID (*InitFunc)(VOID);
INT32 LOS_CppSystemInit(UINTPTR initArrayStart, UINTPTR initArrayEnd)
@@ -44,17 +38,10 @@ INT32 LOS_CppSystemInit(UINTPTR initArrayStart, UINTPTR initArrayEnd)
UINTPTR *start;
InitFunc initFunc = NULL;
for (start = (UINTPTR *)initArrayStart; start < (UINTPTR *)initArrayEnd; start++){
for (start = (UINTPTR *)initArrayStart; start < (UINTPTR *)initArrayEnd; start++) {
initFunc = (InitFunc)(*start);
initFunc();
}
return 0;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
# 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:
@@ -27,14 +27,10 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_m/config.gni")
static_library("cpup") {
sources = [ "los_cpup.c" ]
include_dirs = [
"../../kernel/include",
"../../kernel/arch/include",
"../../utils",
"./",
"//third_party/bounds_checking_function/include",
]
configs += [ "$LITEOSTOPDIR:los_config" ]
}

47
components/cpup/los_cpup.c Executable file → Normal file
View File

@@ -33,12 +33,7 @@
#include "securec.h"
#include "los_memory.h"
#include "los_debug.h"
#include "los_timer.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#include "los_tick.h"
#if (LOSCFG_BASE_CORE_CPUP == 1)
@@ -61,15 +56,6 @@ LITE_OS_SEC_BSS OsCpupCB *g_cpup = NULL;
LITE_OS_SEC_BSS UINT64 g_lastRecordTime;
LITE_OS_SEC_BSS UINT16 g_hisPos; /* <current Sampling point of historyTime */
LITE_OS_SEC_TEXT_MINOR STATIC INLINE UINT64 OsGetCurrentCyclesCount(VOID)
{
UINT32 high = 0;
UINT32 low = 0;
HalGetCpuCycle(&high, &low);
return (((UINT64)high << 32) + low); // 32 means bits of word
}
/*****************************************************************************
Function : OsCpupInit
Description: initialization of CPUP
@@ -110,7 +96,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleStart(VOID)
taskID = g_losTask.newTask->taskID;
g_cpup[taskID].cpupID = taskID;
g_cpup[taskID].startTime = OsGetCurrentCyclesCount();
g_cpup[taskID].startTime = LOS_SysCycleGet();
return;
}
@@ -135,7 +121,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleEnd(VOID)
return;
}
cpuCycle = OsGetCurrentCyclesCount();
cpuCycle = LOS_SysCycleGet();
if (cpuCycle < g_cpup[taskID].startTime) {
cpuCycle += g_cyclesPerTick;
@@ -163,7 +149,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleEndStart(VOID)
}
taskID = g_losTask.runTask->taskID;
cpuCycle = OsGetCurrentCyclesCount();
cpuCycle = LOS_SysCycleGet();
if (g_cpup[taskID].startTime != 0) {
if (cpuCycle < g_cpup[taskID].startTime) {
@@ -229,7 +215,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_SysCpuUsage(VOID)
UINT64 cpuCycleAll = 0;
UINT32 cpupRet = 0;
UINT16 loopNum;
UINTPTR intSave;
UINT32 intSave;
if (g_cpupInitFlg == 0) {
return LOS_ERRNO_CPUP_NO_INIT;
@@ -268,7 +254,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistorySysCpuUsage(UINT16 mode)
UINT16 loopNum;
UINT16 curPos;
UINT16 prePos = 0;
UINTPTR intSave;
UINT32 intSave;
if (g_cpupInitFlg == 0) {
return LOS_ERRNO_CPUP_NO_INIT;
@@ -315,7 +301,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuUsage(UINT32 taskID)
{
UINT64 cpuCycleAll = 0;
UINT16 loopNum;
UINTPTR intSave;
UINT32 intSave;
UINT32 cpupRet = 0;
if (g_cpupInitFlg == 0) {
@@ -364,7 +350,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistoryTaskCpuUsage(UINT32 taskID, UINT16 mode
UINT64 cpuCycleCurTsk = 0;
UINT16 loopNum, curPos;
UINT16 prePos = 0;
UINTPTR intSave;
UINT32 intSave;
UINT32 cpupRet = 0;
if (g_cpupInitFlg == 0) {
@@ -417,7 +403,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_AllTaskCpuUsage(CPUP_INFO_S *cpupInfo, UINT16
UINT16 loopNum;
UINT16 curPos;
UINT16 prePos = 0;
UINTPTR intSave;
UINT32 intSave;
UINT64 cpuCycleAll = 0;
UINT64 cpuCycleCurTsk = 0;
@@ -495,7 +481,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CpupUsageMonitor(CPUP_TYPE_E type, CPUP_MODE_E
PRINTK("\nSysCpuUsage in <1s: ");
}
ret = LOS_HistorySysCpuUsage(mode);
PRINTK("%d.%d", ret / LOS_CPUP_PRECISION_MULT, ret % LOS_CPUP_PRECISION_MULT);
PRINTK("%u.%u", ret / LOS_CPUP_PRECISION_MULT, ret % LOS_CPUP_PRECISION_MULT);
break;
case TASK_CPU_USAGE:
@@ -509,11 +495,11 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CpupUsageMonitor(CPUP_TYPE_E type, CPUP_MODE_E
return OS_ERROR;
}
if (mode == CPUP_IN_10S) {
PRINTK("\nCPUusage of taskID %d in 10s: ", taskID);
PRINTK("\nCPUusage of taskID %u in 10s: ", taskID);
} else if (mode == CPUP_IN_1S) {
PRINTK("\nCPUusage of taskID %d in 1s: ", taskID);
PRINTK("\nCPUusage of taskID %u in 1s: ", taskID);
} else {
PRINTK("\nCPUusage of taskID %d in <1s: ", taskID);
PRINTK("\nCPUusage of taskID %u in <1s: ", taskID);
}
ret = LOS_HistoryTaskCpuUsage(taskID, mode);
PRINTK("%u.%u", ret / LOS_CPUP_PRECISION_MULT, ret % LOS_CPUP_PRECISION_MULT);
@@ -528,10 +514,3 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CpupUsageMonitor(CPUP_TYPE_E type, CPUP_MODE_E
}
#endif /* LOSCFG_BASE_CORE_CPUP */
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@@ -179,7 +179,183 @@ extern UINT32 OsCpupInit(VOID);
*/
extern VOID OsTskCycleEndStart(VOID);
/**
* @ingroup los_cpup
* Count the CPU usage structures of all tasks.
*/
typedef struct tagCpupInfo {
UINT16 usStatus; /**< save the cur task status */
UINT32 uwUsage; /**< Usage. The value range is [0,1000]. */
} CPUP_INFO_S;
/**
* @ingroup los_monitor
* Type of the CPU usage query.
*/
typedef enum {
SYS_CPU_USAGE = 0, /* system cpu occupancy rate */
TASK_CPU_USAGE, /* task cpu occupancy rate */
} CPUP_TYPE_E;
/**
* @ingroup los_monitor
* Mode of the CPU usage query.
*/
typedef enum {
CPUP_IN_10S = 0, /* cpu occupancy rate in 10s */
CPUP_IN_1S, /* cpu occupancy rate in 1s */
CPUP_LESS_THAN_1S, /* cpu occupancy rate less than 1s, if the input mode is none of them, it will be this. */
} CPUP_MODE_E;
/**
* @ingroup los_cpup
* @brief Obtain the current CPU usage.
*
* @par Description:
* This API is used to obtain the current CPU usage.
* @attention
* <ul>
* <li>This API can be called only after the CPU usage is initialized. Otherwise, error codes will be returned.</li>
* <li> The precision of the CPU usage can be adjusted by changing the value of the CPUP_PRECISION macro.</li>
* </ul>
*
* @param None.
*
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
* @retval #cpup [0,1000], current CPU usage, of which the precision is adjustable.
* @par Dependency:
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
* @see LOS_SysCpuUsage
*/
extern UINT32 LOS_SysCpuUsage(VOID);
/**
* @ingroup los_cpup
* @brief Obtain the historical CPU usage.
*
* @par Description:
* This API is used to obtain the historical CPU usage.
* @attention
* <ul>
* <li>This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be obtained.</li>
* </ul>
*
* @param mode [IN] UINT16. Task mode. The parameter value 0 indicates that the CPU usage within 10s will be
* obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained. Other values
* indicate that the CPU usage in the period that is less than 1s will be obtained.
*
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
* @retval #cpup [0,1000], historical CPU usage, of which the precision is adjustable.
* @par Dependency:
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
* @see LOS_HistoryTaskCpuUsage
*/
extern UINT32 LOS_HistorySysCpuUsage(UINT16 mode);
/**
* @ingroup los_cpup
* @brief Obtain the CPU usage of a specified task.
*
* @par Description:
* This API is used to obtain the CPU usage of a task specified by a passed-in task ID.
* @attention
* <ul>
* <li>This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be obtained.</li>
* <li>The passed-in task ID must be valid and the task specified by the task ID must be created. Otherwise,
* the CPU usage fails to be obtained.</li>
* </ul>
*
* @param taskID [IN] UINT32. Task ID.
*
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
* @retval #OS_ERRNO_CPUP_TSK_ID_INVALID 0x02001e05: The target task ID is invalid.
* @retval #OS_ERRNO_CPUP_THREAD_NO_CREATED 0x02001e04: The target thread is not created.
* @retval #cpup [0,1000], CPU usage of the specified task.
* @par Dependency:
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
* @see LOS_HistoryTaskCpuUsage
*/
extern UINT32 LOS_TaskCpuUsage(UINT32 taskID);
/**
* @ingroup los_cpup
* @brief Obtain the historical CPU usage of a specified task.
*
* @par Description:
* This API is used to obtain the historical CPU usage of a task specified by a passed-in task ID.
* @attention
* <ul>
* <li>This API can be called only after the CPU usage is initialized. Otherwise,
* the CPU usage fails to be obtained.</li>
* <li>The passed-in task ID must be valid and the task specified by the task ID must be created. Otherwise,
* the CPU usage fails to be obtained.</li>
* </ul>
*
* @param taskID [IN] UINT32. Task ID.
* @param mode [IN] UINT16. Task mode. The parameter value 0 indicates that the CPU usage within 10s
* will be obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained.
* Other values indicate that the CPU usage in the period that is less than 1s will be obtained.
*
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
* @retval #OS_ERRNO_CPUP_TSK_ID_INVALID 0x02001e05: The target task ID is invalid.
* @retval #OS_ERRNO_CPUP_THREAD_NO_CREATED 0x02001e04: The target thread is not created.
* @retval #cpup [0,1000], CPU usage of the specified task.
* @par Dependency:
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
* @see LOS_HistorySysCpuUsage
*/
extern UINT32 LOS_HistoryTaskCpuUsage(UINT32 taskID, UINT16 mode);
/**
* @ingroup los_cpup
* @brief Obtain the CPU usage of all tasks.
*
* @par Description:
* This API is used to obtain the CPU usage of all tasks according to maximum number of threads.
* @attention
* <ul>
* <li>This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be obtained.</li>
* <li>The input parameter pointer must not be NULL, Otherwise, the CPU usage fails to be obtained.</li>
* </ul>
*
* @param cpupInfo [OUT]Type. CPUP_INFO_S* Pointer to the task CPUP information structure to be obtained.
* @param mode [IN] UINT16. Task mode. The parameter value 0 indicates that the CPU usage within 10s
* will be obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained.
* Other values indicate that the CPU usage in the period that is less than 1s will be obtained.
*
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
* @retval #OS_ERRNO_CPUP_TASK_PTR_NULL 0x02001e01: The input parameter pointer is NULL.
* @retval #LOS_OK 0x00000000: The CPU usage of all tasks is successfully obtained.
* @par Dependency:
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
* @see LOS_SysCpuUsage
*/
extern UINT32 LOS_AllTaskCpuUsage(CPUP_INFO_S *cpupInfo, UINT16 mode);
/**
* @ingroup los_monitor
* @brief Obtain CPU usage history of certain task.
*
* @par Description:
* This API is used to obtain CPU usage history of certain task.
* @attention
* <ul>
* <li>This API can be called only after the CPU usage is initialized. Otherwise, -1 will be returned.</li>
* <li> Only in SYS_CPU_USAGE type, uwTaskID is invalid.</li>
* </ul>
*
* @param type [IN] cpup type, SYS_CPU_USAGE and TASK_CPU_USAGE
* @param mode [IN] mode,CPUP_IN_10S = usage in 10s,CPUP_IN_1S = usage in last 1s,
* CPUP_LESS_THAN_1S = less than 1s, if the input mode is none of them, it will be as CPUP_LESS_THAN_1S.
* @param taskID [IN] task ID, Only in SYS_CPU_USAGE type, taskID is invalid
*
* @retval #OS_ERROR -1:CPU usage info obtain failed.
* @retval #LOS_OK 0:CPU usage info is successfully obtained.
* @par Dependency:
* <ul><li>los_monitor.h: the header file that contains the API declaration.</li></ul>
* @see LOS_CpupUsageMonitor
*/
extern UINT32 LOS_CpupUsageMonitor(CPUP_TYPE_E type, CPUP_MODE_E mode, UINT32 taskID);
#ifdef __cplusplus
#if __cplusplus

View File

@@ -0,0 +1,48 @@
# 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.
import("//kernel/liteos_m/config.gni")
config("dynlink_config") {
include_dirs = [ "./" ]
if (arch == "arm") {
include_dirs += [ "../../kernel/arch/arm/include" ]
} else {
assert(false,
"Dynlink module does not support for other archs except for arm!")
}
}
static_library("dynlink") {
sources = [ "los_dynlink.c" ]
public_configs = [ ":dynlink_config" ]
configs += [ "$LITEOSTOPDIR:los_config" ]
deps = [ "//kernel/liteos_m/kal/posix" ]
}

935
components/dynlink/los_dynlink.c Executable file
View File

@@ -0,0 +1,935 @@
/*
* 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 "los_dynlink.h"
#include "stdlib.h"
#include "string.h"
#include "unistd.h"
#include "fcntl.h"
#include "errno.h"
#include "limits.h"
#include "sys/stat.h"
#include "securec.h"
#include "arch_elf.h"
#include "los_task.h"
#include "los_debug.h"
#include "los_mux.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_DYNLINK == 1)
#if defined(__ICCARM__) || defined(__CC_ARM)
/**
* Place instructions below in .icf linker file:
*
* keep {section .TABLE.START};
* keep {section .sym.*};
* keep {section .table.end};
* define block SYMBOL_TABLE with fixed order
* {
* section .TABLE.START,
* section .sym.*,
* section .table.end
* };
* place in ROM_region {readonly, block SYMBOL_TABLE};
*/
const SymInfo symTableStart __attribute__((section(".TABLE.START"))) = {
.name = "start",
.addr = 0
};
const SymInfo symTableEnd __attribute__((section(".table.end"))) = {
.name = "end",
.addr = 0
};
#pragma section=".TABLE.START"
#pragma section=".table.end"
#elif defined(__CLANG_ARM) || defined(__GNUC__)
/**
* Place instructions below in rodata segment of .ld linker file:
*
* __sym_table_start = .;
* KEEP(*( SORT (.sym.*)));
* __sym_table_end = .;
*/
extern char __sym_table_start[];
extern char __sym_table_end[];
#else
#error Unknown compiler.
#endif
STATIC LOS_DL_LIST g_dynSharedObjLink;
STATIC UINT32 g_dynlinkMux;
STATIC DynSharedObj *OsIsPreLoaded(const CHAR *fileName)
{
DynSharedObj *dso = NULL;
LOS_DL_LIST_FOR_EACH_ENTRY(dso, &g_dynSharedObjLink, DynSharedObj, dsoNode) {
if (!strcmp(fileName, dso->fileName)) {
++dso->ref;
return dso;
}
}
return NULL;
}
STATIC INT32 OsVerifyEhdr(const LD_ELF_EHDR *ehdr, UINT32 fileLen)
{
if (memcmp(ehdr->e_ident, LD_ELFMAG, LD_SELFMAG) != LOS_OK) {
PRINT_ERR("The file is not elf format\n");
return LOS_NOK;
}
if (ehdr->e_type != ET_DYN) {
PRINT_ERR("The file is not shared library\n");
return LOS_NOK;
}
if (!check_arch(ehdr)) {
PRINT_ERR("The file can not load in current platform\n");
return LOS_NOK;
}
if (ehdr->e_phnum > PHDR_NUM_MAX) {
PRINT_ERR("The num of program header is out of limit\n");
return LOS_NOK;
}
if (ehdr->e_phoff > fileLen) {
PRINT_ERR("The offset of program header is invalid, elf file is bad\n");
return LOS_NOK;
}
return LOS_OK;
}
STATIC INT32 OsReadELFInfo(INT32 fd, UINT8 *buffer, size_t readSize, off_t offset)
{
ssize_t byteNum;
off_t returnPos;
if (readSize > 0) {
returnPos = lseek(fd, offset, SEEK_SET);
if (returnPos != offset) {
PRINT_ERR("Failed to seek the position!, offset: %#x\n", offset);
return LOS_NOK;
}
byteNum = read(fd, buffer, readSize);
if (byteNum <= 0) {
PRINT_ERR("Failed to read from offset: %#x!\n", offset);
return LOS_NOK;
}
}
return LOS_OK;
}
STATIC INT32 OsGetFileLength(UINT32 *fileLen, const CHAR *fileName)
{
struct stat buf;
INT32 ret;
ret = stat(fileName, &buf);
if (ret < 0) {
PRINT_ERR("Failed to stat file: %s, errno: %d\n", fileName, errno);
return LOS_NOK;
}
if (buf.st_size > FILE_LENGTH_MAX) {
PRINT_ERR("The file: %s length is out of limit!\n", fileName);
return LOS_NOK;
}
*fileLen = (UINT32)buf.st_size;
return LOS_OK;
}
STATIC INT32 OsReadEhdr(INT32 fd, UINT32 fileLen, DynLinkInfo *dlInfo)
{
INT32 ret;
ret = OsReadELFInfo(fd, (UINT8 *)&dlInfo->elfEhdr, sizeof(LD_ELF_EHDR), 0);
if (ret != LOS_OK) {
return -EIO;
}
ret = OsVerifyEhdr(&dlInfo->elfEhdr, fileLen);
if (ret != LOS_OK) {
return -ELIBBAD;
}
return LOS_OK;
}
STATIC INT32 OsReadPhdrs(INT32 fd, UINT32 fileLen, DynLinkInfo *dlInfo)
{
INT32 ret;
UINT32 size;
LD_ELF_EHDR *ehdr = &dlInfo->elfEhdr;
if ((ehdr->e_phnum == 0) || (ehdr->e_phentsize != sizeof(LD_ELF_PHDR))) {
goto ERR;
}
size = sizeof(LD_ELF_PHDR) * ehdr->e_phnum;
if ((ehdr->e_phoff + size) > fileLen) {
goto ERR;
}
dlInfo->elfPhdr = (LD_ELF_PHDR *)LOS_MemAlloc(OS_SYS_MEM_ADDR, size);
if (dlInfo->elfPhdr == NULL) {
return -ENOMEM;
}
ret = OsReadELFInfo(fd, (UINT8 *)dlInfo->elfPhdr, size, ehdr->e_phoff);
if (ret != LOS_OK) {
LOS_MemFree(OS_SYS_MEM_ADDR, dlInfo->elfPhdr);
return -EIO;
}
return LOS_OK;
ERR:
PRINT_ERR("the file is bad\n");
return -ELIBBAD;
}
STATIC DynSharedObj *OsLoadInit(const CHAR *fileName, VOID *pool)
{
DynSharedObj *dso = NULL;
UINT32 allocSize, nameLen;
UINT32 fileLen = 0;
INT32 ret;
nameLen = strlen(fileName);
if (nameLen > PATH_MAX) {
PRINT_ERR("file name length is too long\n");
errno = ENAMETOOLONG;
return NULL;
}
allocSize = sizeof(DynSharedObj) + nameLen + 1;
dso = (DynSharedObj *)LOS_MemAlloc(OS_SYS_MEM_ADDR, allocSize);
if (dso == NULL) {
PRINT_ERR("failed to alloc for dso\n");
errno = ENOMEM;
return NULL;
}
(VOID)memset_s(dso, allocSize, 0, allocSize);
dso->dlInfo = (DynLinkInfo *)LOS_MemAlloc(OS_SYS_MEM_ADDR, sizeof(DynLinkInfo));
if (dso->dlInfo == NULL) {
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
PRINT_ERR("failed to alloc for loadInfo\n");
errno = ENOMEM;
return NULL;
}
(VOID)memset_s(dso->dlInfo, sizeof(DynLinkInfo), 0, sizeof(DynLinkInfo));
ret = OsGetFileLength(&fileLen, fileName);
if (ret != LOS_OK) {
errno = ENOENT;
goto ERR1;
}
dso->fd = open(fileName, O_RDONLY);
if (dso->fd < 0) {
PRINT_ERR("Failed to open ELF file: %s!\n", fileName);
goto ERR1;
}
ret = OsReadEhdr(dso->fd, fileLen, dso->dlInfo);
if (ret != LOS_OK) {
errno = -ret;
goto ERR2;
}
ret = OsReadPhdrs(dso->fd, fileLen, dso->dlInfo);
if (ret != LOS_OK) {
errno = -ret;
goto ERR2;
}
strcpy(dso->buf, fileName);
dso->fileName = dso->buf;
dso->ref = 1;
dso->pool = (pool ? pool : OS_SYS_MEM_ADDR);
LOS_ListInit(&dso->dsoNode);
return dso;
ERR2:
close(dso->fd);
ERR1:
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
return NULL;
}
STATIC INT32 OsReserveSpace(const DynLinkInfo *dlInfo, UINT32 *boundary)
{
const LD_ELF_PHDR *elfPhdrTemp = dlInfo->elfPhdr;
INT32 phdrNum = dlInfo->elfEhdr.e_phnum;
UINTPTR addrMin = SIZE_MAX;
UINTPTR addrMax = 0;
UINT32 offStart = 0;
UINT64 size;
INT32 i;
for (i = 0; i < phdrNum; ++i, ++elfPhdrTemp) {
if (elfPhdrTemp->p_type == PT_TLS) {
PRINT_ERR("unsupport tls\n");
return 0;
}
if (elfPhdrTemp->p_type != PT_LOAD) {
continue;
}
if (*boundary == 0) {
*boundary = elfPhdrTemp->p_align;
}
if (elfPhdrTemp->p_vaddr < addrMin) {
addrMin = elfPhdrTemp->p_vaddr;
offStart = elfPhdrTemp->p_offset;
}
if ((elfPhdrTemp->p_vaddr + elfPhdrTemp->p_memsz) > addrMax) {
addrMax = elfPhdrTemp->p_vaddr + elfPhdrTemp->p_memsz;
}
}
if ((addrMin == addrMax) || (addrMax < addrMin)) {
return 0;
}
size = ELF_ALIGN_UP(addrMax, *boundary) - ELF_ALIGN_DOWN(addrMin, *boundary) + ELF_ALIGN_DOWN(offStart, *boundary);
return (size > UINT_MAX) ? 0 : (UINT32)size;
}
STATIC UINTPTR OsDoLoadFile(INT32 fd, UINTPTR addr, const LD_ELF_PHDR *elfPhdr, UINT32 boundary)
{
INT32 ret;
UINT32 offset = elfPhdr->p_offset - ELF_ALIGN_OFFSET(elfPhdr->p_vaddr, boundary);
UINT32 size = elfPhdr->p_filesz + ELF_ALIGN_OFFSET(elfPhdr->p_vaddr, boundary);
if (size == 0) {
return 0;
}
addr = ELF_ALIGN_DOWN(addr, boundary);
ret = OsReadELFInfo(fd, (UINT8 *)addr, size, offset);
if (ret != LOS_OK) {
return 0;
}
return addr;
}
STATIC INT32 OsLoadELFFile(DynSharedObj *dso, UINT32 boundary)
{
DynLinkInfo *dlInfo = dso->dlInfo;
const LD_ELF_PHDR *elfPhdrTemp = dlInfo->elfPhdr;
const LD_ELF_EHDR *elfEhdr = &dlInfo->elfEhdr;
UINTPTR loadBase = dso->loadBase;
UINTPTR vAddr, loadAddr, bssStart, bssEnd;
INT32 i;
for (i = 0; i < elfEhdr->e_phnum; ++i, ++elfPhdrTemp) {
if (elfPhdrTemp->p_type != PT_LOAD) {
continue;
}
if ((elfPhdrTemp->p_flags & PF_R) == 0) {
return -ENOEXEC;
}
vAddr = elfPhdrTemp->p_vaddr;
loadAddr = OsDoLoadFile(dso->fd, (vAddr + loadBase), elfPhdrTemp, boundary);
if (loadAddr == 0) {
return -EFAULT;
}
if ((elfPhdrTemp->p_memsz > elfPhdrTemp->p_filesz) && (elfPhdrTemp->p_flags & PF_W)) {
bssStart = loadAddr + ELF_ALIGN_OFFSET(vAddr, boundary) + elfPhdrTemp->p_filesz;
bssEnd = loadAddr + ELF_ALIGN_OFFSET(vAddr, boundary) + elfPhdrTemp->p_memsz;
(VOID)memset_s((VOID *)bssStart, bssEnd - bssStart, 0, bssEnd - bssStart);
}
}
return LOS_OK;
}
STATIC INT32 OsLoadLibrary(DynSharedObj *dso)
{
UINT32 loadSize;
UINT32 boundary = 0;
INT32 ret;
loadSize = OsReserveSpace(dso->dlInfo, &boundary);
if (loadSize == 0) {
PRINT_ERR("failed to reserve space!\n");
return -EINVAL;
}
dso->loadBase = (UINTPTR)LOS_MemAllocAlign(dso->pool, loadSize, boundary);
if (dso->loadBase == 0) {
PRINT_ERR("failed to alloc memory for loading shared library\n");
return -ENOMEM;
}
ret = OsLoadELFFile(dso, boundary);
if (ret != LOS_OK) {
LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
PRINT_ERR("failed to load shared library\n");
return ret;
}
return LOS_OK;
}
STATIC INT32 OsGetDynBase(DynSharedObj *dso)
{
DynLinkInfo *dlInfo = dso->dlInfo;
const LD_ELF_PHDR *elfPhdrTemp = dlInfo->elfPhdr;
INT32 phdrNum = dlInfo->elfEhdr.e_phnum;
INT32 i;
for (i = 0; i < phdrNum; ++i, ++elfPhdrTemp) {
if (elfPhdrTemp->p_type != PT_DYNAMIC) {
continue;
}
dlInfo->dynBase = dso->loadBase + elfPhdrTemp->p_vaddr;
return LOS_OK;
}
return LOS_NOK;
}
STATIC INT32 OsParseDynamic(DynSharedObj *dso)
{
LD_ELF_DYN *dyn = NULL;
DynLinkInfo *dlInfo = dso->dlInfo;
RelocInfoTab *relInfoTab = &dlInfo->relInfoTab;
for (dyn = (LD_ELF_DYN *)dlInfo->dynBase; dyn->d_tag != DT_NULL; ++dyn) {
switch (dyn->d_tag) {
case DT_NEEDED:
PRINT_ERR("shared library should not depend on others\n");
return -ENOTSUP;
case DT_TEXTREL:
PRINT_ERR("you should recompile shared library with -fPIC\n");
return -EFAULT;
case DT_HASH:
dlInfo->hashTab = (UINT32 *)(dso->loadBase + dyn->d_un.d_ptr);
break;
case DT_SYMTAB:
dlInfo->symTab = (LD_ELF_SYM *)(dso->loadBase + dyn->d_un.d_ptr);
break;
case DT_STRTAB:
dlInfo->symStrings = (CHAR *)(dso->loadBase + dyn->d_un.d_ptr);
break;
case DT_REL:
relInfoTab->rel.relTab = dso->loadBase + dyn->d_un.d_ptr;
relInfoTab->rel.relEntSize = sizeof(LD_ELF_REL);
break;
case DT_RELSZ:
relInfoTab->rel.relTabSize = dyn->d_un.d_val;
break;
case DT_RELA:
relInfoTab->rela.relTab = dso->loadBase + dyn->d_un.d_ptr;
relInfoTab->rela.relEntSize = sizeof(LD_ELF_RELA);
break;
case DT_RELASZ:
relInfoTab->rela.relTabSize = dyn->d_un.d_val;
break;
case DT_JMPREL:
relInfoTab->jmpRel.relTab = dso->loadBase + dyn->d_un.d_ptr;
break;
case DT_PLTRELSZ:
relInfoTab->jmpRel.relTabSize = dyn->d_un.d_val;
break;
case DT_PLTREL:
relInfoTab->jmpRel.relEntSize = (dyn->d_un.d_val == DT_REL) ? sizeof(LD_ELF_REL) : sizeof(LD_ELF_RELA);
default:
break;
}
}
return LOS_OK;
}
STATIC UINT32 OsGetHashVal(const CHAR *name)
{
UINT32 hashVal = 0;
UINT32 tmp;
const UINT8 *str = (const UINT8 *)name;
while (*str) {
hashVal = (*str) + (hashVal << WORD_SHIFT);
tmp = hashVal & HASH_MASK;
if (tmp != 0) {
hashVal ^= tmp >> HASH_SHIFT;
}
hashVal &= ~tmp;
++str;
}
return hashVal;
}
STATIC LD_ELF_SYM *OsFindSymInDso(const DynLinkInfo *dlInfo, const CHAR *name)
{
LD_ELF_SYM *symTab = dlInfo->symTab;
LD_ELF_SYM *sym = NULL;
CHAR *symStr = dlInfo->symStrings;
UINT32 *hashTab = dlInfo->hashTab;
UINT32 bucketNum = hashTab[0];
UINT32 *bucket = &hashTab[BUCKET_IDX];
UINT32 *chain = &bucket[bucketNum];
UINT32 hashVal = OsGetHashVal(name);
UINT32 symIdx;
for (symIdx = bucket[hashVal % bucketNum]; symIdx; symIdx = chain[symIdx]) {
if (strcmp(name, symStr + symTab[symIdx].st_name) != 0) {
continue;
}
sym = symTab + symIdx;
if ((sym->st_value == 0) || (sym->st_shndx == 0)) {
return NULL;
}
return symTab + symIdx;
}
return NULL;
}
STATIC SymInfo *OsFindSymInTable(const CHAR *name)
{
#if defined(__ICCARM__) || defined(__CC_ARM)
SymInfo *symTab = (SymInfo *)__section_end(".TABLE.START");
UINT32 symTableSize = ((UINTPTR)__section_begin(".table.end") -
(UINTPTR)__section_end(".TABLE.START")) / sizeof(SymInfo);
#elif defined(__CLANG_ARM) || defined(__GNUC__)
SymInfo *symTab = (SymInfo *)__sym_table_start;
UINT32 symTableSize = (__sym_table_end - __sym_table_start) / sizeof(SymInfo);
#endif
INT32 startIdx = 0;
INT32 endIdx = symTableSize - 1;
INT32 ret, midIdx;
while (startIdx <= endIdx) {
midIdx = startIdx + ((UINT32)(endIdx - startIdx) >> 1);
ret = strcmp(symTab[midIdx].name, name);
if (ret > 0) {
endIdx = midIdx - 1;
} else if (ret < 0) {
startIdx = midIdx + 1;
} else {
return symTab + midIdx;
}
}
return NULL;
}
STATIC UINTPTR OsFindSym(const DynSharedObj *dso, INT32 symIdx)
{
DynLinkInfo *dlInfo = dso->dlInfo;
CHAR *symStrings = dlInfo->symStrings;
CHAR *symStr = NULL;
LD_ELF_SYM *symTab = dlInfo->symTab;
LD_ELF_SYM *sym = NULL;
LD_ELF_SYM *symInDso = NULL;
SymInfo *symInTab = NULL;
sym = symTab + symIdx;
symStr = symStrings + sym->st_name;
if ((symInDso = OsFindSymInDso(dlInfo, symStr)) != NULL) {
return dso->loadBase + symInDso->st_value;
} else if ((symInTab = OsFindSymInTable(symStr)) != NULL) {
return symInTab->addr;
} else {
PRINT_ERR("failed to relocate %s, symbol: %s not found\n", dso->fileName, symStr);
return 0;
}
}
STATIC INT32 OsDoReloc(const DynSharedObj *dso, INT32 type, UINTPTR relocAddr, UINT32 addend, UINTPTR symAddr)
{
switch (type) {
case R_ARCH_NONE:
break;
case R_ARCH_GLOB_DAT:
case R_ARCH_JUMP_SLOT:
*(UINTPTR *)relocAddr = symAddr + addend;
break;
case R_ARCH_ABS32:
*(UINTPTR *)relocAddr = symAddr + ((addend != 0) ? addend : *(UINTPTR *)relocAddr);
break;
case R_ARCH_RELATIVE:
*(UINTPTR *)relocAddr = dso->loadBase + ((addend != 0) ? addend : *(UINTPTR *)relocAddr);
break;
default:
PRINT_ERR("failed to relocate %s, unsupported reloc type: %d\n", dso->fileName, type);
return -ENOTSUP;
}
return LOS_OK;
}
STATIC INT32 OsDoRelocSyms(DynSharedObj *dso, RelocInfo *relInfo)
{
UINT32 relStride = relInfo->relEntSize / sizeof(UINT32);
UINT32 *relTab = (UINT32 *)relInfo->relTab;
UINT32 addend;
UINTPTR relocAddr, symAddr;
INT32 i, symIdx, ret, type;
for (i = 0; i < relInfo->relTabSize; i += relInfo->relEntSize, relTab += relStride) {
type = REL_TYPE(relTab[1]);
if (type == R_ARCH_NONE) {
continue;
}
symIdx = REL_SYM(relTab[1]);
if (symIdx == 0) {
symAddr = 0;
} else {
symAddr = OsFindSym(dso, symIdx);
if (symAddr == 0) {
return -EFAULT;
}
}
relocAddr = dso->loadBase + relTab[0];
addend = (relInfo->relEntSize == sizeof(LD_ELF_REL)) ? 0 : relTab[relStride - 1];
ret = OsDoReloc(dso, type, relocAddr, addend, symAddr);
if (ret != LOS_OK) {
return ret;
}
}
return LOS_OK;
}
STATIC INT32 OsRelocSyms(DynSharedObj *dso)
{
DynLinkInfo *dlInfo = dso->dlInfo;
RelocInfo *relInfo = (RelocInfo *)&dlInfo->relInfoTab;
INT32 relTypes = sizeof(RelocInfoTab) / sizeof(RelocInfo);
INT32 i, ret;
for (i = 0; i < relTypes; ++i, ++relInfo) {
if (relInfo->relTab == 0) {
continue;
}
ret = OsDoRelocSyms(dso, relInfo);
if (ret != LOS_OK) {
return ret;
}
}
return LOS_OK;
}
STATIC INT32 OsDoDynLink(DynSharedObj *dso)
{
INT32 ret;
ret = OsGetDynBase(dso);
if (ret != LOS_OK) {
PRINT_ERR("there are no dynamic segments in elf file\n");
return -ELIBBAD;
}
ret = OsParseDynamic(dso);
if (ret != LOS_OK) {
return ret;
}
ret = OsRelocSyms(dso);
if (ret != LOS_OK) {
return ret;
}
return LOS_OK;
}
STATIC VOID OsDeLoadInit(DynSharedObj *dso)
{
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo->elfPhdr);
dso->dlInfo->elfPhdr = NULL;
close(dso->fd);
}
STATIC VOID OsGetInitFini(DynSharedObj *dso)
{
LD_ELF_DYN *dyn = NULL;
DynLinkInfo *dlInfo = dso->dlInfo;
InitFiniTab *initFiniTab = &dso->initFiniTab;
for (dyn = (LD_ELF_DYN *)dlInfo->dynBase; dyn->d_tag != DT_NULL; ++dyn) {
switch (dyn->d_tag) {
case DT_INIT:
initFiniTab->init.func = dyn->d_un.d_ptr;
break;
case DT_INIT_ARRAY:
initFiniTab->init.array = dyn->d_un.d_ptr;
break;
case DT_INIT_ARRAYSZ:
initFiniTab->init.arraySz = dyn->d_un.d_val;
break;
case DT_FINI:
initFiniTab->fini.func = dyn->d_un.d_ptr;
break;
case DT_FINI_ARRAY:
initFiniTab->fini.array = dyn->d_un.d_ptr;
break;
case DT_FINI_ARRAYSZ:
initFiniTab->fini.arraySz = dyn->d_un.d_val;
break;
default:
break;
}
}
}
STATIC VOID OsDoInit(DynSharedObj *dso)
{
InitFiniTab *initFiniTab = &dso->initFiniTab;
INIT_FINI_FUNC initFunc = NULL;
UINTPTR *func = NULL;
UINT32 funcNum;
OsGetInitFini(dso);
if (initFiniTab->init.func != 0) {
initFunc = (INIT_FINI_FUNC)(dso->loadBase + initFiniTab->init.func);
initFunc();
}
if (initFiniTab->init.array == 0) {
return;
}
funcNum = initFiniTab->init.arraySz / sizeof(UINTPTR);
func = (UINTPTR *)(dso->loadBase + initFiniTab->init.array);
while (funcNum--) {
initFunc = (INIT_FINI_FUNC)(*func);
initFunc();
++func;
}
}
VOID *LOS_SoLoad(const CHAR *fileName, VOID *pool)
{
INT32 ret;
DynSharedObj *dso = NULL;
if (fileName == NULL) {
PRINT_ERR("invalid file name\n");
errno = EINVAL;
return NULL;
}
(VOID)LOS_MuxPend(g_dynlinkMux, LOS_WAIT_FOREVER);
dso = OsIsPreLoaded(fileName);
if (dso != NULL) {
(VOID)LOS_MuxPost(g_dynlinkMux);
return dso;
}
dso = OsLoadInit(fileName, pool);
if (dso == NULL) {
(VOID)LOS_MuxPost(g_dynlinkMux);
return NULL;
}
ret = OsLoadLibrary(dso);
if (ret != LOS_OK) {
errno = -ret;
goto ERR1;
}
ret = OsDoDynLink(dso);
if (ret != LOS_OK) {
errno = -ret;
goto ERR2;
}
OsDoInit(dso);
LOS_ListAdd(&g_dynSharedObjLink, &dso->dsoNode);
(VOID)LOS_MuxPost(g_dynlinkMux);
OsDeLoadInit(dso);
return dso;
ERR2:
LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
ERR1:
close(dso->fd);
(VOID)LOS_MuxPost(g_dynlinkMux);
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo->elfPhdr);
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
return NULL;
}
STATIC DynSharedObj *OsCheckHandle(VOID *handle)
{
DynSharedObj *dso = NULL;
LOS_DL_LIST_FOR_EACH_ENTRY(dso, &g_dynSharedObjLink, DynSharedObj, dsoNode) {
if (handle == dso) {
return dso;
}
}
return NULL;
}
VOID *LOS_FindSym(VOID *handle, const CHAR *name)
{
LD_ELF_SYM *sym = NULL;
DynSharedObj *dso = NULL;
VOID *symAddr = NULL;
if ((handle == NULL) || (name == NULL)) {
goto ERR;
}
(VOID)LOS_MuxPend(g_dynlinkMux, LOS_WAIT_FOREVER);
dso = OsCheckHandle(handle);
if (dso == NULL) {
(VOID)LOS_MuxPost(g_dynlinkMux);
goto ERR;
}
sym = OsFindSymInDso(dso->dlInfo, name);
if (sym == NULL) {
(VOID)LOS_MuxPost(g_dynlinkMux);
PRINT_ERR("failed to find symbol: %s\n", name);
errno = EFAULT;
return NULL;
}
symAddr = (VOID *)(dso->loadBase + sym->st_value);
(VOID)LOS_MuxPost(g_dynlinkMux);
return symAddr;
ERR:
PRINT_ERR("invalid input param\n");
errno = EINVAL;
return NULL;
}
STATIC VOID OsDoFini(DynSharedObj *dso)
{
InitFiniTab *initFiniTab = &dso->initFiniTab;
INIT_FINI_FUNC finiFunc = NULL;
UINTPTR *func = NULL;
UINT32 funcNum;
if (initFiniTab->fini.array != 0) {
funcNum = initFiniTab->fini.arraySz / sizeof(UINTPTR);
func = (UINTPTR *)(dso->loadBase + initFiniTab->fini.array) + funcNum;
while (funcNum--) {
--func;
finiFunc = (INIT_FINI_FUNC)(*func);
finiFunc();
}
}
if (initFiniTab->fini.func != 0) {
finiFunc = (INIT_FINI_FUNC)(dso->loadBase + initFiniTab->fini.func);
finiFunc();
}
}
INT32 LOS_SoUnload(VOID *handle)
{
DynSharedObj *dso = NULL;
if (handle == NULL) {
goto ERR;
}
(VOID)LOS_MuxPend(g_dynlinkMux, LOS_WAIT_FOREVER);
dso = OsCheckHandle(handle);
if (dso == NULL) {
(VOID)LOS_MuxPost(g_dynlinkMux);
goto ERR;
}
if (dso->ref > 1) {
--dso->ref;
(VOID)LOS_MuxPost(g_dynlinkMux);
return LOS_OK;
}
OsDoFini(dso);
LOS_ListDelete(&dso->dsoNode);
(VOID)LOS_MuxPost(g_dynlinkMux);
LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
return LOS_OK;
ERR:
PRINT_ERR("invalid handle\n");
errno = EINVAL;
return LOS_NOK;
}
INT32 LOS_DynlinkInit(VOID)
{
UINT32 ret;
LOS_ListInit(&g_dynSharedObjLink);
ret = LOS_MuxCreate(&g_dynlinkMux);
if (ret != LOS_OK) {
return LOS_NOK;
}
return LOS_OK;
}
#endif /* LOSCFG_DYNLINK */
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

201
components/dynlink/los_dynlink.h Executable file
View File

@@ -0,0 +1,201 @@
/*
* 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_DYNLINK_H
#define _LOS_DYNLINK_H
#include "elf.h"
#include "los_compiler.h"
#include "los_list.h"
#include "los_memory.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef LOSCFG_AARCH64
typedef Elf64_Ehdr LD_ELF_EHDR;
typedef Elf64_Phdr LD_ELF_PHDR;
typedef Elf64_Sym LD_ELF_SYM;
typedef Elf64_Dyn LD_ELF_DYN;
typedef Elf64_Rel LD_ELF_REL;
typedef Elf64_Rela LD_ELF_RELA;
#define REL_TYPE(x) ELF64_R_TYPE(x)
#define REL_SYM(x) ELF64_R_SYM(x)
#define REL_INFO ELF64_R_INFO
#else
typedef Elf32_Ehdr LD_ELF_EHDR;
typedef Elf32_Phdr LD_ELF_PHDR;
typedef Elf32_Sym LD_ELF_SYM;
typedef Elf32_Dyn LD_ELF_DYN;
typedef Elf32_Rel LD_ELF_REL;
typedef Elf32_Rela LD_ELF_RELA;
#define REL_TYPE(x) ELF32_R_TYPE(x)
#define REL_SYM(x) ELF32_R_SYM(x)
#define REL_INFO ELF32_R_INFO
#endif
#define LD_ELFMAG "\177ELF"
#define LD_SELFMAG 4
#define PHDR_NUM_MAX 128
#define DYNAMIC_CNT 32
#define HASH_MASK 0xf0000000
#define WORD_SHIFT 4
#define HASH_SHIFT 24
#define BUCKET_IDX 2
#define ELF_ALIGN_UP(a, b) (((a) + ((b) - 1)) & ~((b) - 1))
#define ELF_ALIGN_DOWN(a, b) ((a) & ~((b) - 1))
#define ELF_ALIGN_OFFSET(a, b) ((a) & ((b) - 1))
#ifndef PATH_MAX
#define PATH_MAX 256
#endif
#ifndef FILE_LENGTH_MAX
#define FILE_LENGTH_MAX 0x40000
#endif
typedef VOID (*INIT_FINI_FUNC)(VOID);
typedef struct {
UINTPTR relTab;
UINT32 relTabSize;
UINT32 relEntSize;
} RelocInfo;
typedef struct {
RelocInfo rel;
RelocInfo rela;
RelocInfo jmpRel;
} RelocInfoTab;
typedef struct {
UINTPTR func;
UINTPTR array;
UINT32 arraySz;
} InitFiniInfo;
typedef struct {
InitFiniInfo init;
InitFiniInfo fini;
} InitFiniTab;
typedef struct {
LD_ELF_EHDR elfEhdr;
LD_ELF_PHDR *elfPhdr;
UINTPTR dynBase;
UINT32 *hashTab;
LD_ELF_SYM *symTab;
CHAR *symStrings;
RelocInfoTab relInfoTab;
} DynLinkInfo;
typedef struct {
CHAR *fileName;
INT32 fd;
DynLinkInfo *dlInfo;
UINTPTR loadBase;
InitFiniTab initFiniTab;
LOS_DL_LIST dsoNode;
UINT32 ref;
VOID *pool;
CHAR buf[];
} DynSharedObj;
typedef struct {
CHAR *name;
UINTPTR addr;
} SymInfo;
#define SYM_EXPORT(func) \
const SymInfo sym_##func __attribute__((section(".sym."#func))) = { \
.name = #func, \
.addr = (UINTPTR)func \
};
/*
* @brief Load the shared library file named by the NULL-terminated string filename and
* return a valid handle for the loaded library.
*
* @param fileName The name pointer of shared library.
* @param pool The heap for shared library to load. If the parameter, pool, is NULL, then
* the dynamic loader & linker module will use the default heap and the pool is not NULL,
* then the shared library will be loaded to the heap by pool.
*
* @note When the heap, pool, is not NULL, you should call LOS_MemInit() to initialize the
* pool before calling LOS_SoLoad(). By the way, the system will comsume a certain amount
* of memory to initialize the pool. LOS_SoLoad must not be called in interrupt callback.
*
* @return Return NULL if error. Return non-NULL if success.
*/
VOID *LOS_SoLoad(const CHAR *fileName, VOID *pool);
/*
* @brief Get the address of symbol named by the parameter, name, from the parameter, handle.
*
* @param handle The handle for the loaded shared library.
* @param name The name of symbol to search.
*
* @note LOS_FindSym must not be called in interrupt callback.
*
* @return Return NULL if error. Return non-NULL if success.
*/
VOID *LOS_FindSym(VOID *handle, const CHAR *name);
/*
* @brief Decrement the reference count on the loaded shared library refered to by handle.
* If the reference count drops to zero, then the library is unloaded.
*
* This function validates that the handle is valid.
*
* @param handle The handle for the loaded shared library by LOS_SoLoad() interface.
*
* @note LOS_SoUnload must not be called in interrupt callback.
*
* @return Return 1 if error. Return 0 if success.
*/
INT32 LOS_SoUnload(VOID *handle);
/*
* @brief Initialization for dynamic loader & linker module.
*
* @param VOID.
*
* @return Return LOS_NOK if error. Return LOS_OK if success.
*/
INT32 LOS_DynlinkInit(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_DYNLINK_H */

View File

@@ -0,0 +1,65 @@
#!/bin/bash
# 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.
# Description: The script is used to calculate the memory size that the specified shared library
# will occupy when loading to the RAM.
READELF=readelf
RM=rm
SIZE=0x0
SIZE_ALL=0x0
SIZE_MAX=0
TMP_FILE=tmp.txt
if [ $# -lt 1 ]; then
echo "Usage: ./so_parse lib.so"
exit 1
fi
parse_line()
{
MEM_SIZE=$(echo $1 | awk '{print $6}')
echo ${MEM_SIZE}
}
${READELF} -l $1 | while read line; do
HEAD_STRING=$(echo ${line} | awk '{print $1}')
if [[ "${HEAD_STRING}" == *"LOAD"* ]]; then
SIZE=`parse_line "${line}"`
SIZE=`echo ${SIZE}`
SIZE_ALL=$((SIZE_ALL+SIZE))
fi
echo ${SIZE_ALL} >> ${TMP_FILE}
done
NEED_SIZE=`tail -n 1 ${TMP_FILE}`
echo "${NEED_SIZE} kb memory to reserve for $1!"
${RM} -f ${TMP_FILE}

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
# 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:
@@ -27,16 +27,13 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_m/config.gni")
static_library("exchook") {
sources = [
"los_exc_info.c",
"los_exchook.c",
]
include_dirs = [
"../../kernel/arch/include",
"../../kernel/include",
"../../utils",
"./",
"//third_party/bounds_checking_function/include",
]
configs += [ "$LITEOSTOPDIR:los_config" ]
}

View File

@@ -38,11 +38,6 @@
#include "los_membox.h"
#include "los_memory.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_PLATFORM_EXC == 1)
#define EXC_MSG_ARRAY_INIT_VALUE 0xff
@@ -300,9 +295,4 @@ VOID OsExcMsgDumpInit(VOID)
}
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

6
components/exchook/los_exchook.c Executable file → Normal file
View File

@@ -54,7 +54,7 @@ STATIC VOID DoExcHookInRegOrder(EXC_TYPE excType, struct Node *node)
STATIC VOID DoExcHook(EXC_TYPE excType)
{
UINTPTR intSave;
UINT32 intSave;
if (excType >= EXC_TYPE_END) {
return;
}
@@ -88,7 +88,7 @@ STATIC struct Node *GetFreeNode(VOID)
UINT32 LOS_RegExcHook(EXC_TYPE excType, ExcHookFn excHookFn)
{
UINTPTR intSave;
UINT32 intSave;
struct Node *node = NULL;
if (excType >= EXC_TYPE_END || excHookFn == NULL) {
return LOS_ERRNO_SYS_PTR_NULL;
@@ -110,7 +110,7 @@ UINT32 LOS_RegExcHook(EXC_TYPE excType, ExcHookFn excHookFn)
UINT32 LOS_UnRegExcHook(EXC_TYPE excType, ExcHookFn excHookFn)
{
UINTPTR intSave;
UINT32 intSave;
struct Node *node = NULL;
struct Node *preNode = NULL;
if (excType >= EXC_TYPE_END || excHookFn == NULL) {

0
components/exchook/los_exchook.h Executable file → Normal file
View File

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
# 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:
@@ -27,13 +27,32 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
static_library("fs_operations") {
sources = [ "./fs.c" ]
include_dirs = [
"../../../kernel/arch/include",
"../../../kernel/include",
"../../../utils",
"../../../kal/posix/include",
"./",
]
deps = [ "//kernel/liteos_m/kal/posix" ]
}
declare_args() {
enable_ohos_kernel_liteos_m_fatfs = true
enable_ohos_kernel_liteos_m_littlefs = true
}
group("fs") {
deps = []
if (enable_ohos_kernel_liteos_m_fatfs == true) {
deps += [ ".:fs_operations" ]
if (enable_ohos_kernel_liteos_m_fatfs) {
deps += [ "fatfs:fatfs" ]
}
if (enable_ohos_kernel_liteos_m_littlefs) {
deps += [ "littlefs:littlefs" ]
}
}

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
# 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:
@@ -29,19 +29,23 @@
static_library("fatfs") {
sources = [
"//third_party/FatFs/source/diskio.c",
"//third_party/FatFs/source/ff.c",
"//third_party/FatFs/source/ffsystem.c",
"//third_party/FatFs/source/ffunicode.c",
"fatfs.c",
"fs.c",
]
include_dirs = [
"../",
"../../../kernel/arch/include",
"../../../kernel/include",
"../../../utils",
"../../../kal/cmsis",
"../../../kal",
"../../../kal/posix/include",
"./",
"//third_party/bounds_checking_function/include",
"//third_party/FatFs/source/",
]
deps = [ "//kernel/liteos_m/kal/posix" ]
}

164
components/fs/fatfs/fatfs.c Executable file → Normal file
View File

@@ -29,22 +29,20 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE 1
#include "ff.h"
#if FF_USE_EXPAND
#define _GNU_SOURCE
#endif
#include "fatfs.h"
#include "errno.h"
#include "stdbool.h"
#include "limits.h"
#include "pthread.h"
#include "time.h"
#include "securec.h"
#include "los_compiler.h"
#include "los_debug.h"
#include "cmsis_os.h"
#include "cmsis_os2.h"
#include "fs_operations.h"
#define FS_SUCCESS 0
#define FS_FAILURE (-1)
/* the max name length of different parts should not bigger than 32 */
#define FS_DRIVE_NAME_MAX_LEN 32
@@ -52,9 +50,9 @@
#define FAT_MAX_OPEN_DIRS 8
#endif /* FAT_MAX_OPEN_DIRS */
#ifndef FS_LOCK_TIMEMOUT_SEC
#define FS_LOCK_TIMEMOUT_SEC 15
#endif /* FS_LOCK_TIMEMOUT_SEC */
#ifndef FS_LOCK_TIMEOUT_SEC
#define FS_LOCK_TIMEOUT_SEC 15
#endif /* FS_LOCK_TIMEOUT_SEC */
#define PART_NAME 0x0
#define VOLUME_NAME 0x1
@@ -90,7 +88,7 @@ static int FsLock(void)
PRINTK("clock gettime err 0x%x!\r\n", errno);
return errno;
}
absTimeout.tv_sec += FS_LOCK_TIMEMOUT_SEC;
absTimeout.tv_sec += FS_LOCK_TIMEOUT_SEC;
ret = pthread_mutex_timedlock(&g_fsMutex, &absTimeout);
return ret;
}
@@ -624,14 +622,21 @@ int fatfs_close(int fd)
FRESULT res;
INT32 ret;
ret = FsLock();
if (ret != 0) {
errno = ret;
return FS_FAILURE;
}
if (!IsValidFd(fd)) {
FsUnlock();
errno = EBADF;
return FS_FAILURE;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
if (g_handle[fd].fil.obj.fs == NULL) {
FsUnlock();
errno = ENOENT;
return FS_FAILURE;
}
@@ -670,10 +675,6 @@ ssize_t fatfs_read(int fd, void *buf, size_t nbyte)
errno = EFAULT;
return FS_FAILURE;
}
if (!IsValidFd(fd)) {
errno = EBADF;
return FS_FAILURE;
}
ret = FsLock();
if (ret != 0) {
@@ -681,6 +682,18 @@ ssize_t fatfs_read(int fd, void *buf, size_t nbyte)
return FS_FAILURE;
}
if (!IsValidFd(fd)) {
FsUnlock();
errno = EBADF;
return FS_FAILURE;
}
if (g_handle[fd].fil.obj.fs == NULL) {
FsUnlock();
errno = ENOENT;
return FS_FAILURE;
}
res = f_read(&g_handle[fd].fil, buf, nbyte, &lenRead);
if (res != FR_OK) {
FsUnlock();
@@ -703,10 +716,6 @@ ssize_t fatfs_write(int fd, const void *buf, size_t nbyte)
errno = EFAULT;
return FS_FAILURE;
}
if (!IsValidFd(fd)) {
errno = EBADF;
return FS_FAILURE;
}
ret = FsLock();
if (ret != 0) {
@@ -714,15 +723,27 @@ ssize_t fatfs_write(int fd, const void *buf, size_t nbyte)
return FS_FAILURE;
}
if (!IsValidFd(fd)) {
errno = EBADF;
goto ERROUT;
}
if (g_handle[fd].fil.obj.fs == NULL) {
errno = ENOENT;
goto ERROUT;
}
if (!FsCheckByID(g_handle[fd].fil.obj.fs->id)) {
errno = EACCES;
goto ERROUT;
}
res = f_write(&g_handle[fd].fil, buf, nbyte, &lenWrite);
if ((res == FR_OK) && (lenWrite == 0) && (nbyte != 0) && (overFlow == FALSE)) {
overFlow = TRUE;
PRINTK("FAT write err 0x%x!\r\n", fd);
}
if ((res != FR_OK) || (nbyte != lenWrite)) {
errno = FatfsErrno(res);
goto ERROUT;
@@ -742,17 +763,22 @@ off_t fatfs_lseek(int fd, off_t offset, int whence)
INT32 ret;
off_t pos;
if (!IsValidFd(fd)) {
errno = EBADF;
return FS_FAILURE;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return FS_FAILURE;
}
if (!IsValidFd(fd)) {
errno = EBADF;
goto ERROUT;
}
if (g_handle[fd].fil.obj.fs == NULL) {
errno = ENOENT;
goto ERROUT;
}
if (whence == SEEK_SET) {
pos = 0;
} else if (whence == SEEK_CUR) {
@@ -834,10 +860,6 @@ int fatfs_fstat(int fd, struct stat *buf)
errno = EFAULT;
return FS_FAILURE;
}
if (!IsValidFd(fd)) {
errno = EBADF;
return FS_FAILURE;
}
ret = FsLock();
if (ret != 0) {
@@ -845,6 +867,18 @@ int fatfs_fstat(int fd, struct stat *buf)
return FS_FAILURE;
}
if (!IsValidFd(fd)) {
FsUnlock();
errno = EBADF;
return FS_FAILURE;
}
if (g_handle[fd].fil.obj.fs == NULL) {
FsUnlock();
errno = ENOENT;
return FS_FAILURE;
}
buf->st_size = f_size(&g_handle[fd].fil);
buf->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH |
S_IWUSR | S_IWGRP | S_IWOTH |
@@ -881,6 +915,7 @@ int fatfs_stat(const char *path, struct stat *buf)
ret = FS_FAILURE;
goto OUT;
}
res = f_stat(path, &fileInfo);
if (res != FR_OK) {
PRINTK("FAT stat err 0x%x!\r\n", res);
@@ -916,22 +951,30 @@ int fatfs_fsync(int fd)
FRESULT res;
INT32 ret;
if (!IsValidFd(fd)) {
errno = EBADF;
return FS_FAILURE;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return FS_FAILURE;
}
if (!IsValidFd(fd)) {
errno = EBADF;
ret = FS_FAILURE;
goto OUT;
}
if (g_handle[fd].fil.obj.fs == NULL) {
errno = ENOENT;
ret = FS_FAILURE;
goto OUT;
}
if (!FsCheckByID(g_handle[fd].fil.obj.fs->id)) {
errno = EACCES;
ret = FS_FAILURE;
goto OUT;
}
res = f_sync(&g_handle[fd].fil);
if (res != FR_OK) {
errno = FatfsErrno(res);
@@ -1259,8 +1302,8 @@ OUT:
static int do_truncate(int fd, off_t length, UINT count)
{
FRESULT res;
INT32 ret = FR_OK;
FRESULT res = FR_OK;
INT32 ret = FS_SUCCESS;
DWORD csz;
csz = (DWORD)(g_handle[fd].fil.obj.fs)->csize * SS(g_handle[fd].fil.obj.fs); /* Cluster size */
@@ -1295,11 +1338,6 @@ int fatfs_ftruncate(int fd, off_t length)
UINT count;
DWORD fclust;
if (!IsValidFd(fd)) {
errno = EBADF;
return FS_FAILURE;
}
if ((length < 0) || (length > UINT_MAX)) {
errno = EINVAL;
return FS_FAILURE;
@@ -1311,6 +1349,18 @@ int fatfs_ftruncate(int fd, off_t length)
return FS_FAILURE;
}
if (!IsValidFd(fd)) {
errno = EBADF;
ret = FS_FAILURE;
goto OUT;
}
if (g_handle[fd].fil.obj.fs == NULL) {
errno = ENOENT;
ret = FS_FAILURE;
goto OUT;
}
if (!FsCheckByID(g_handle[fd].fil.obj.fs->id)) {
errno = EACCES;
ret = FS_FAILURE;
@@ -1382,6 +1432,7 @@ int fatfs_format(const char *dev, int sectors, int option)
INT32 index;
FRESULT res;
INT32 ret;
MKFS_PARM opt = {0};
if (dev == NULL) {
errno = EFAULT;
@@ -1408,7 +1459,9 @@ int fatfs_format(const char *dev, int sectors, int option)
goto OUT;
}
res = f_mkfs(dev, option, sectors, g_workBuffer, FF_MAX_SS);
opt.n_sect = sectors;
opt.fmt = (BYTE)option;
res = f_mkfs(dev, &opt, g_workBuffer, FF_MAX_SS);
if (res != FR_OK) {
errno = FatfsErrno(res);
ret = FS_FAILURE;
@@ -1421,3 +1474,28 @@ OUT:
FsUnlock();
return ret;
}
struct MountOps g_fatfsMnt = {
.Mount = fatfs_mount,
.Umount = fatfs_umount,
.Umount2 = fatfs_umount2,
.Statfs = fatfs_statfs,
};
struct FileOps g_fatfsFops = {
.Mkdir = fatfs_mkdir,
.Unlink = fatfs_unlink,
.Rmdir = fatfs_rmdir,
.Opendir = fatfs_opendir,
.Readdir = fatfs_readdir,
.Closedir = fatfs_closedir,
.Open = fatfs_open,
.Close = fatfs_close,
.Write = fatfs_write,
.Read = fatfs_read,
.Seek = fatfs_lseek,
.Rename = fatfs_rename,
.Getattr = fatfs_stat,
.Fsync = fatfs_fsync,
.Fstat = fatfs_fstat,
};

0
components/fs/fatfs/fatfs.h Executable file → Normal file
View File

288
components/fs/fatfs/fs.c → components/fs/fs.c Executable file → Normal file
View File

@@ -28,8 +28,11 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "fs_operations.h"
#include "los_config.h"
#if (LOSCFG_SUPPORT_FATFS == 1)
#include "fatfs.h"
#endif
#include "dirent.h"
#include "errno.h"
#include "fcntl.h"
@@ -42,6 +45,9 @@
#include "sys/stat.h"
#include "unistd.h"
struct FsMap g_fsmap[MAX_FILESYSTEM_LEN] = {0};
struct FsMap *g_fs = NULL;
#ifdef LOSCFG_NET_LWIP_SACK
#include "lwip/lwipopts.h"
#include "lwip/sockets.h"
@@ -92,12 +98,12 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz
size_t tmpLen = strlen(cwd) + strlen(path) + offset;
char *tmpBuf = (char *)malloc(tmpLen);
if (tmpBuf == NULL) {
return 0;
return FS_SUCCESS;
}
if (-1 == sprintf_s(tmpBuf, tmpLen, "/%s/%s/", cwd, path)) {
free(tmpBuf);
return 0;
return FS_SUCCESS;
}
char *p;
@@ -106,7 +112,7 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz
while ((p = strstr(tmpBuf, "/./")) != NULL) {
if (EOK != memmove_s(p, tmpLen - (p - tmpBuf), p + offset, tmpLen - (p - tmpBuf) - offset)) {
free(tmpBuf);
return 0;
return FS_SUCCESS;
}
}
@@ -114,7 +120,7 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz
while ((p = strstr(tmpBuf, "//")) != NULL) {
if (EOK != memmove_s(p, tmpLen - (p - tmpBuf), p + 1, tmpLen - (p - tmpBuf) - 1)) {
free(tmpBuf);
return 0;
return FS_SUCCESS;
}
}
@@ -127,7 +133,7 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz
}
if (EOK != memmove_s(start, tmpLen - (start - tmpBuf), p + offset, tmpLen - (p - tmpBuf) - offset)) {
free(tmpBuf);
return 0;
return FS_SUCCESS;
}
}
@@ -144,7 +150,7 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz
if (EOK != memcpy_s(buf, bufSize, tmpBuf, (((totalLen + 1) > bufSize) ? bufSize : (totalLen + 1)))) {
free(tmpBuf);
return 0;
return FS_SUCCESS;
}
buf[bufSize - 1] = 0;
@@ -153,21 +159,87 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz
}
#endif
static void InitMountInfo(void)
{
#if (LOSCFG_SUPPORT_FATFS == 1)
extern struct MountOps g_fatfsMnt;
extern struct FileOps g_fatfsFops;
g_fsmap[0].fileSystemtype = strdup("fat");
g_fsmap[0].fsMops = &g_fatfsMnt;
g_fsmap[0].fsFops = &g_fatfsFops;
#endif
#if (LOSCFG_SUPPORT_LITTLEFS == 1)
extern struct MountOps g_lfsMnt;
extern struct FileOps g_lfsFops;
g_fsmap[1].fileSystemtype = strdup("littlefs");
g_fsmap[1].fsMops = &g_lfsMnt;
g_fsmap[1].fsFops = &g_lfsFops;
#endif
}
static struct FsMap *MountFindfs(const char *fileSystemtype)
{
struct FsMap *m = NULL;
for (int i = 0; i < MAX_FILESYSTEM_LEN; i++) {
m = &(g_fsmap[i]);
if (m->fileSystemtype && strcmp(fileSystemtype, m->fileSystemtype) == 0) {
return m;
}
}
return NULL;
}
int mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data)
{
return fatfs_mount(source, target, filesystemtype, mountflags, data);
static int initFlag = 0;
if (initFlag == 0) {
InitMountInfo();
initFlag = 1;
}
g_fs = MountFindfs(filesystemtype);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsMops == NULL || g_fs->fsMops->Mount == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsMops->Mount(source, target, filesystemtype, mountflags, data);
}
int umount(const char *target)
{
return fatfs_umount(target);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsMops == NULL || g_fs->fsMops->Umount == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsMops->Umount(target);
}
int umount2(const char *target, int flag)
{
return fatfs_umount2(target, flag);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsMops == NULL || g_fs->fsMops->Umount2 == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsMops->Umount2(target, flag);
}
int open(const char *path, int oflag, ...)
@@ -176,30 +248,30 @@ int open(const char *path, int oflag, ...)
unsigned flags = O_RDONLY | O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_LARGEFILE | O_TRUNC | O_EXCL | O_DIRECTORY;
if ((unsigned)oflag & ~flags) {
errno = EINVAL;
return -1;
return FS_FAILURE;
}
size_t pathLen = strlen(path) + 1;
char *canonicalPath = (char *)malloc(pathLen);
if (!canonicalPath) {
errno = ENOMEM;
return -1;
return FS_FAILURE;
}
if (GetCanonicalPath(NULL, path, canonicalPath, pathLen) == 0) {
FREE_AND_SET_NULL(canonicalPath);
errno = ENOMEM;
return -1;
return FS_FAILURE;
}
if (strcmp(canonicalPath, RANDOM_DEV_PATH) == 0) {
FREE_AND_SET_NULL(canonicalPath);
if ((O_ACCMODE & (unsigned)oflag) != O_RDONLY) {
errno = EPERM;
return -1;
return FS_FAILURE;
}
if ((unsigned)oflag & O_DIRECTORY) {
errno = ENOTDIR;
return -1;
return FS_FAILURE;
}
return RANDOM_DEV_FD;
}
@@ -207,21 +279,29 @@ int open(const char *path, int oflag, ...)
FREE_AND_SET_NULL(canonicalPath);
if ((unsigned)oflag & O_DIRECTORY) {
errno = EPERM;
return -1;
return FS_FAILURE;
}
errno = EISDIR;
return -1;
return FS_FAILURE;
}
FREE_AND_SET_NULL(canonicalPath);
#endif
return fatfs_open(path, oflag);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Open == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Open(path, oflag);
}
int close(int fd)
{
#ifdef LOSCFG_RANDOM_DEV
if (fd == RANDOM_DEV_FD) {
return 0;
return FS_SUCCESS;
}
#endif
#ifdef LOSCFG_NET_LWIP_SACK
@@ -229,7 +309,15 @@ int close(int fd)
return closesocket(fd);
}
#endif
return fatfs_close(fd);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Close == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Close(fd);
}
ssize_t read(int fd, void *buf, size_t nbyte)
@@ -237,19 +325,19 @@ ssize_t read(int fd, void *buf, size_t nbyte)
#ifdef LOSCFG_RANDOM_DEV
if (fd == RANDOM_DEV_FD) {
if (nbyte == 0) {
return 0;
return FS_SUCCESS;
}
if (buf == NULL) {
errno = EINVAL;
return -1;
return FS_FAILURE;
}
if (nbyte > 1024) {
if (nbyte > 1024) { /* 1024, max random_size */
nbyte = 1024; /* hks_generate_random: random_size must <= 1024 */
}
struct hks_blob key = {HKS_BLOB_TYPE_RAW, (uint8_t *)buf, nbyte};
if (hks_generate_random(&key) != 0) {
errno = EIO;
return -1;
return FS_FAILURE;
}
return (ssize_t)nbyte;
}
@@ -259,7 +347,15 @@ ssize_t read(int fd, void *buf, size_t nbyte)
return recv(fd, buf, nbyte, 0);
}
#endif
return fatfs_read(fd, buf, nbyte);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Read == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Read(fd, buf, nbyte);
}
ssize_t write(int fd, const void *buf, size_t nbyte)
@@ -267,7 +363,7 @@ ssize_t write(int fd, const void *buf, size_t nbyte)
#ifdef LOSCFG_RANDOM_DEV
if (fd == RANDOM_DEV_FD) {
errno = EBADF; /* "/dev/random" is readonly */
return -1;
return FS_FAILURE;
}
#endif
#ifdef LOSCFG_NET_LWIP_SACK
@@ -275,70 +371,182 @@ ssize_t write(int fd, const void *buf, size_t nbyte)
return send(fd, buf, nbyte, 0);
}
#endif
return fatfs_write(fd, buf, nbyte);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Write == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Write(fd, buf, nbyte);
}
off_t lseek(int fd, off_t offset, int whence)
{
return fatfs_lseek(fd, offset, whence);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Seek == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Seek(fd, offset, whence);
}
int unlink(const char *path)
{
return fatfs_unlink(path);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Unlink == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Unlink(path);
}
int fstat(int fd, struct stat *buf)
{
return fatfs_fstat(fd, buf);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Fstat == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Fstat(fd, buf);
}
int stat(const char *path, struct stat *buf)
{
return fatfs_stat(path, buf);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Getattr == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Getattr(path, buf);
}
int fsync(int fd)
{
return fatfs_fsync(fd);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Fsync == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Fsync(fd);
}
int mkdir(const char *path, mode_t mode)
{
return fatfs_mkdir(path, mode);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Mkdir == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Mkdir(path, mode);
}
DIR *opendir(const char *dirName)
{
return fatfs_opendir(dirName);
if (g_fs == NULL) {
errno = ENODEV;
return NULL;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Opendir == NULL) {
errno = ENOSYS;
return NULL;
}
return g_fs->fsFops->Opendir(dirName);
}
struct dirent *readdir(DIR *dir)
{
return fatfs_readdir(dir);
if (g_fs == NULL) {
errno = ENODEV;
return NULL;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Readdir == NULL) {
errno = ENOSYS;
return NULL;
}
return g_fs->fsFops->Readdir(dir);
}
int closedir(DIR *dir)
{
return fatfs_closedir(dir);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Closedir == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Closedir(dir);
}
int rmdir(const char *path)
{
return fatfs_rmdir(path);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Rmdir == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Rmdir(path);
}
int rename(const char *oldName, const char *newName)
{
return fatfs_rename(oldName, newName);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Rename == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Rename(oldName, newName);
}
int statfs(const char *path, struct statfs *buf)
{
return fatfs_statfs(path, buf);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsMops == NULL || g_fs->fsMops->Statfs == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsMops->Statfs(path, buf);
}
int ftruncate(int fd, off_t length)
{
return fatfs_ftruncate(fd, length);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Ftruncate == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Ftruncate(fd, length);
}

View File

@@ -0,0 +1,80 @@
/*
* 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.
*/
#ifndef _FS_OPERATIONS_H_
#define _FS_OPERATIONS_H_
#include "fcntl.h"
#include "dirent.h"
#include "unistd.h"
#include "sys/mount.h"
#include "sys/stat.h"
#include "sys/statfs.h"
#define FS_SUCCESS 0
#define FS_FAILURE (-1)
#define MAX_FILESYSTEM_LEN 2
struct MountOps {
int (*Mount)(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags,
const void *data);
int (*Umount)(const char* target);
int (*Umount2)(const char* target, int flag);
int (*Statfs)(const char *path, struct statfs *buf);
};
struct FsMap {
const char *fileSystemtype;
const struct MountOps *fsMops;
const struct FileOps *fsFops;
};
struct FileOps {
int (*Open)(const char *path, int openFlag, ...);
int (*Close)(int fd);
int (*Unlink)(const char *fileName);
int (*Rmdir)(const char *dirName);
int (*Mkdir)(const char *dirName, mode_t mode);
struct dirent *(*Readdir)(DIR *dir);
DIR *(*Opendir)(const char *dirName);
int (*Closedir)(DIR *dir);
int (*Read)(int fd, void *buf, size_t len);
int (*Write)(int fd, const void *buf, size_t len);
off_t (*Seek)(int fd, off_t offset, int whence);
int (*Getattr)(const char *path, struct stat *buf);
int (*Rename)(const char *oldName, const char *newName);
int (*Fsync)(int fd);
int (*Fstat)(int fd, struct stat *buf);
int (*Stat)(const char *path, struct stat *buf);
int (*Ftruncate)(int fd, off_t length);
};
#endif /* _FS_OPERATIONS_H_ */

View File

@@ -0,0 +1,49 @@
# 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.
static_library("littlefs") {
sources = [
"//third_party/littlefs/lfs.c",
"//third_party/littlefs/lfs_util.c",
"lfs_api.c",
]
include_dirs = [
"../../../kernel/arch/include",
"../../../kernel/include",
"../../../utils",
"../../../kal/cmsis",
"../../../kal/posix/include",
"./",
"../",
"//third_party/littlefs",
]
deps = [ "//kernel/liteos_m/kal/posix" ]
}

View File

@@ -0,0 +1,869 @@
/*
* 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.
*/
#define _GNU_SOURCE 1
#include "lfs_api.h"
#include "los_config.h"
#include "los_mux.h"
#include "los_debug.h"
#include "securec.h"
lfs_t g_lfs;
FileDirInfo g_lfsDir[LFS_MAX_OPEN_DIRS] = {0};
struct FileOpInfo g_fsOp[LOSCFG_LFS_MAX_MOUNT_SIZE] = {0};
static LittleFsHandleStruct g_handle[LITTLE_FS_MAX_OPEN_FILES] = {0};
struct dirent g_nameValue;
static const char *g_littlefsMntName[LOSCFG_LFS_MAX_MOUNT_SIZE] = {"/a", "/b", "/c"};
#define LFS_MUTEX_UNINIT (-1)
static UINT32 g_lfsMutex = LFS_MUTEX_UNINIT;
static int LfsLock(void)
{
if (LOS_MuxPend(g_lfsMutex, LOS_WAIT_FOREVER) != LOS_OK) {
PRINT_ERR("LfsLock failed!");
return LOS_NOK;
}
return LOS_OK;
}
static void LfsUnlock(void)
{
(void)LOS_MuxPost(g_lfsMutex);
}
LittleFsHandleStruct *LfsAllocFd(const char *fileName, int *fd)
{
for (int i = 0; i < LITTLE_FS_MAX_OPEN_FILES; i++) {
if (g_handle[i].useFlag == 0) {
*fd = i;
g_handle[i].useFlag = 1;
g_handle[i].pathName = strdup(fileName);
return &(g_handle[i]);
}
}
*fd = INVALID_FD;
return NULL;
}
static void LfsFreeFd(int fd)
{
g_handle[fd].useFlag = 0;
if (g_handle[fd].pathName != NULL) {
free((void *)g_handle[fd].pathName);
g_handle[fd].pathName = NULL;
}
if (g_handle[fd].lfsHandle != NULL) {
g_handle[fd].lfsHandle = NULL;
}
}
BOOL CheckFileIsOpen(const char *fileName)
{
for (int i = 0; i < LITTLE_FS_MAX_OPEN_FILES; i++) {
if (g_handle[i].useFlag == 1) {
if (strcmp(g_handle[i].pathName, fileName) == 0) {
return TRUE;
}
}
}
return FALSE;
}
static BOOL LfsFdIsValid(int fd)
{
if (fd >= LITTLE_FS_MAX_OPEN_FILES || fd < 0) {
return FALSE;
}
if (g_handle[fd].lfsHandle == NULL) {
return FALSE;
}
return TRUE;
}
FileDirInfo *GetFreeDir(const char *dirName)
{
for (int i = 0; i < LFS_MAX_OPEN_DIRS; i++) {
if (g_lfsDir[i].useFlag == 0) {
g_lfsDir[i].useFlag = 1;
g_lfsDir[i].dirName = strdup(dirName);
return &(g_lfsDir[i]);
}
}
return NULL;
}
void FreeDirInfo(const char *dirName)
{
for (int i = 0; i < LFS_MAX_OPEN_DIRS; i++) {
if (g_lfsDir[i].useFlag == 1 && strcmp(g_lfsDir[i].dirName, dirName) == 0) {
g_lfsDir[i].useFlag = 0;
if (g_lfsDir[i].dirName) {
free(g_lfsDir[i].dirName);
g_lfsDir[i].dirName = NULL;
}
}
}
}
BOOL CheckDirIsOpen(const char *dirName)
{
for (int i = 0; i < LFS_MAX_OPEN_DIRS; i++) {
if (g_lfsDir[i].useFlag == 1) {
if (strcmp(g_lfsDir[i].dirName, dirName) == 0) {
return TRUE;
}
}
}
return FALSE;
}
int GetFirstLevelPathLen(const char *pathName)
{
int len = 1;
for (int i = 1; i < strlen(pathName) + 1; i++) {
if (pathName[i] == '/') {
break;
}
len++;
}
return len;
}
BOOL CheckPathIsMounted(const char *pathName, struct FileOpInfo **fileOpInfo)
{
char tmpName[LITTLEFS_MAX_LFN_LEN] = {0};
int len = GetFirstLevelPathLen(pathName);
for (int i = 0; i < LOSCFG_LFS_MAX_MOUNT_SIZE; i++) {
if (g_fsOp[i].useFlag == 1) {
(void)strncpy_s(tmpName, LITTLEFS_MAX_LFN_LEN, pathName, len);
if (strcmp(tmpName, g_fsOp[i].dirName) == 0) {
*fileOpInfo = &(g_fsOp[i]);
return TRUE;
}
}
}
return FALSE;
}
struct FileOpInfo *AllocMountRes(const char* target, const struct FileOps *fileOps)
{
for (int i = 0; i < LOSCFG_LFS_MAX_MOUNT_SIZE; i++) {
if (g_fsOp[i].useFlag == 0 && strcmp(target, g_littlefsMntName[i]) == 0) {
g_fsOp[i].useFlag = 1;
g_fsOp[i].fsVops = fileOps;
g_fsOp[i].dirName = strdup(target);
return &(g_fsOp[i]);
}
}
return NULL;
}
int SetDefaultMountPath(int pathNameIndex, const char* target)
{
if (pathNameIndex >= LOSCFG_LFS_MAX_MOUNT_SIZE) {
return VFS_ERROR;
}
g_littlefsMntName[pathNameIndex] = strdup(target);
return VFS_OK;
}
struct FileOpInfo *GetMountRes(const char *target, int *mountIndex)
{
for (int i = 0; i < LOSCFG_LFS_MAX_MOUNT_SIZE; i++) {
if (g_fsOp[i].useFlag == 1) {
if (g_fsOp[i].dirName && strcmp(target, g_fsOp[i].dirName) == 0) {
*mountIndex = i;
return &(g_fsOp[i]);
}
}
}
return NULL;
}
int FreeMountResByIndex(int mountIndex)
{
if (mountIndex < 0 || mountIndex >= LOSCFG_LFS_MAX_MOUNT_SIZE) {
return VFS_ERROR;
}
if (g_fsOp[mountIndex].useFlag == 1 && g_fsOp[mountIndex].dirName != NULL) {
g_fsOp[mountIndex].useFlag = 0;
free(g_fsOp[mountIndex].dirName);
g_fsOp[mountIndex].dirName = NULL;
}
return VFS_OK;
}
int FreeMountRes(const char *target)
{
for (int i = 0; i < LOSCFG_LFS_MAX_MOUNT_SIZE; i++) {
if (g_fsOp[i].useFlag == 1) {
if (g_fsOp[i].dirName && strcmp(target, g_fsOp[i].dirName) == 0) {
g_fsOp[i].useFlag = 0;
free(g_fsOp[i].dirName);
g_fsOp[i].dirName = NULL;
return VFS_OK;
}
}
}
return VFS_ERROR;
}
static int ConvertFlagToLfsOpenFlag (int oflags)
{
int lfsOpenFlag = 0;
if (oflags & O_CREAT) {
lfsOpenFlag |= LFS_O_CREAT;
}
if (oflags & O_EXCL) {
lfsOpenFlag |= LFS_O_EXCL;
}
if (oflags & O_TRUNC) {
lfsOpenFlag |= LFS_O_TRUNC;
}
if (oflags & O_APPEND) {
lfsOpenFlag |= LFS_O_APPEND;
}
if (oflags & O_RDWR) {
lfsOpenFlag |= LFS_O_RDWR;
}
if (oflags & O_WRONLY) {
lfsOpenFlag |= LFS_O_WRONLY;
}
if (oflags & O_RDONLY) {
lfsOpenFlag |= LFS_O_RDONLY;
}
return lfsOpenFlag;
}
static int LittlefsErrno(int result)
{
return (result < 0) ? -result : result;
}
const struct MountOps g_lfsMnt = {
.Mount = LfsMount,
.Umount = LfsUmount,
};
const struct FileOps g_lfsFops = {
.Mkdir = LfsMkdir,
.Unlink = LfsUnlink,
.Rmdir = LfsRmdir,
.Opendir = LfsOpendir,
.Readdir = LfsReaddir,
.Closedir = LfsClosedir,
.Open = LfsOpen,
.Close = LfsClose,
.Write = LfsWrite,
.Read = LfsRead,
.Seek = LfsSeek,
.Rename = LfsRename,
.Getattr = LfsStat,
.Fsync = LfsFsync,
};
int LfsMount(const char *source, const char *target, const char *fileSystemType, unsigned long mountflags,
const void *data)
{
int ret;
struct FileOpInfo *fileOpInfo = NULL;
if (g_lfsMutex == LFS_MUTEX_UNINIT) {
if (LOS_MuxCreate(&g_lfsMutex) != LOS_OK) {
errno = EBUSY;
return VFS_ERROR;
}
}
if (LfsLock() != LOS_OK) {
errno = EAGAIN;
return VFS_ERROR;
}
if (target == NULL || fileSystemType == NULL || data == NULL) {
errno = EFAULT;
ret = VFS_ERROR;
goto errout;
}
if (strcmp(fileSystemType, "littlefs") != 0) {
errno = ENODEV;
ret = VFS_ERROR;
goto errout;
}
if (CheckPathIsMounted(target, &fileOpInfo)) {
errno = EBUSY;
ret = VFS_ERROR;
goto errout;
}
// select free mount resource
fileOpInfo = AllocMountRes(target, &g_lfsFops);
if (fileOpInfo == NULL) {
errno = ENODEV;
ret = VFS_ERROR;
goto errout;
}
ret = lfs_mount(&(fileOpInfo->lfsInfo), (struct lfs_config*)data);
if (ret != 0) {
ret = lfs_format(&(fileOpInfo->lfsInfo), (struct lfs_config*)data);
if (ret == 0) {
ret = lfs_mount(&(fileOpInfo->lfsInfo), (struct lfs_config*)data);
}
}
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = VFS_ERROR;
}
errout:
LfsUnlock();
return ret;
}
int LfsUmount(const char *target)
{
int ret;
int mountIndex = -1;
struct FileOpInfo *fileOpInfo = NULL;
if (target == NULL) {
errno = EFAULT;
return VFS_ERROR;
}
if (LfsLock() != LOS_OK) {
errno = EAGAIN;
return VFS_ERROR;
}
fileOpInfo = GetMountRes(target, &mountIndex);
if (fileOpInfo == NULL) {
errno = ENOENT;
LfsUnlock();
return VFS_ERROR;
}
ret = lfs_unmount(&(fileOpInfo->lfsInfo));
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = VFS_ERROR;
}
(void)FreeMountResByIndex(mountIndex);
LfsUnlock();
return ret;
}
int LfsUnlink(const char *fileName)
{
int ret;
struct FileOpInfo *fileOpInfo = NULL;
if (fileName == NULL) {
errno = EFAULT;
return VFS_ERROR;
}
if (LfsLock() != LOS_OK) {
errno = EAGAIN;
return VFS_ERROR;
}
if (CheckPathIsMounted(fileName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
errno = ENOENT;
LfsUnlock();
return VFS_ERROR;
}
ret = lfs_remove(&(fileOpInfo->lfsInfo), fileName);
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = VFS_ERROR;
}
LfsUnlock();
return ret;
}
int LfsMkdir(const char *dirName, mode_t mode)
{
int ret;
struct FileOpInfo *fileOpInfo = NULL;
if (dirName == NULL) {
errno = EFAULT;
return VFS_ERROR;
}
if (LfsLock() != LOS_OK) {
errno = EAGAIN;
return VFS_ERROR;
}
if (CheckPathIsMounted(dirName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
errno = ENOENT;
LfsUnlock();
return VFS_ERROR;
}
ret = lfs_mkdir(&(fileOpInfo->lfsInfo), dirName);
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = VFS_ERROR;
}
LfsUnlock();
return ret;
}
int LfsRmdir(const char *dirName)
{
int ret;
struct FileOpInfo *fileOpInfo = NULL;
if (dirName == NULL) {
errno = EFAULT;
return VFS_ERROR;
}
if (LfsLock() != LOS_OK) {
errno = EAGAIN;
return VFS_ERROR;
}
if (CheckPathIsMounted(dirName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
errno = ENOENT;
LfsUnlock();
return VFS_ERROR;
}
ret = lfs_remove(&(fileOpInfo->lfsInfo), dirName);
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = VFS_ERROR;
}
LfsUnlock();
return ret;
}
DIR *LfsOpendir(const char *dirName)
{
int ret;
struct FileOpInfo *fileOpInfo = NULL;
if (dirName == NULL) {
errno = EFAULT;
return NULL;
}
if (LfsLock() != LOS_OK) {
errno = EAGAIN;
return NULL;
}
if (CheckPathIsMounted(dirName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
errno = ENOENT;
goto errout;
}
if (CheckDirIsOpen(dirName)) {
errno = EBUSY;
goto errout;
}
FileDirInfo *dirInfo = GetFreeDir(dirName);
if (dirInfo == NULL) {
errno = ENFILE;
goto errout;
}
ret = lfs_dir_open(&(fileOpInfo->lfsInfo), (lfs_dir_t *)(&(dirInfo->dir)), dirName);
if (ret != 0) {
FreeDirInfo(dirName);
errno = LittlefsErrno(ret);
goto errout;
}
dirInfo->lfsHandle = &(fileOpInfo->lfsInfo);
LfsUnlock();
return (DIR *)dirInfo;
errout:
LfsUnlock();
return NULL;
}
struct dirent *LfsReaddir(DIR *dir)
{
int ret;
struct lfs_info lfsInfo;
FileDirInfo *dirInfo = (FileDirInfo *)dir;
if (dirInfo == NULL || dirInfo->lfsHandle == NULL) {
errno = EBADF;
return NULL;
}
if (LfsLock() != LOS_OK) {
errno = EAGAIN;
return NULL;
}
ret = lfs_dir_read(dirInfo->lfsHandle, (lfs_dir_t *)(&(dirInfo->dir)), &lfsInfo);
if (ret == TRUE) {
(void)strncpy_s(g_nameValue.d_name, sizeof(g_nameValue.d_name), lfsInfo.name, strlen(lfsInfo.name) + 1);
if (lfsInfo.type == LFS_TYPE_DIR) {
g_nameValue.d_type = DT_DIR;
} else if (lfsInfo.type == LFS_TYPE_REG) {
g_nameValue.d_type = DT_REG;
}
g_nameValue.d_reclen = lfsInfo.size;
LfsUnlock();
return &g_nameValue;
}
if (ret != 0) {
errno = LittlefsErrno(ret);
}
LfsUnlock();
return NULL;
}
int LfsClosedir(DIR *dir)
{
int ret;
FileDirInfo *dirInfo = (FileDirInfo *)dir;
if (dirInfo == NULL || dirInfo->lfsHandle == NULL) {
errno = EBADF;
return VFS_ERROR;
}
if (LfsLock() != LOS_OK) {
errno = EAGAIN;
return VFS_ERROR;
}
ret = lfs_dir_close(dirInfo->lfsHandle, (lfs_dir_t *)(&(dirInfo->dir)));
FreeDirInfo(dirInfo->dirName);
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = VFS_ERROR;
}
LfsUnlock();
return ret;
}
int LfsOpen(const char *pathName, int openFlag, int mode)
{
int fd = INVALID_FD;
int err = INVALID_FD;
struct FileOpInfo *fileOpInfo = NULL;
if (pathName == NULL) {
errno = EFAULT;
return INVALID_FD;
}
if (LfsLock() != LOS_OK) {
errno = EAGAIN;
return VFS_ERROR;
}
if (CheckPathIsMounted(pathName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
errno = ENOENT;
goto errout;
}
// if file is already open, return invalid fd
if (CheckFileIsOpen(pathName)) {
errno = EBUSY;
goto errout;
}
LittleFsHandleStruct *fsHandle = LfsAllocFd(pathName, &fd);
if (fd == INVALID_FD) {
errno = ENFILE;
goto errout;
}
int lfsOpenFlag = ConvertFlagToLfsOpenFlag(openFlag);
err = lfs_file_open(&(fileOpInfo->lfsInfo), &(fsHandle->file), pathName, lfsOpenFlag);
if (err != 0) {
LfsFreeFd(fd);
errno = LittlefsErrno(err);
goto errout;
}
g_handle[fd].lfsHandle = &(fileOpInfo->lfsInfo);
LfsUnlock();
return fd;
errout:
LfsUnlock();
return INVALID_FD;
}
int LfsRead(int fd, void *buf, unsigned int len)
{
int ret;
if (buf == NULL) {
errno = EFAULT;
return VFS_ERROR;
}
if (LfsLock() != LOS_OK) {
errno = EAGAIN;
return VFS_ERROR;
}
if (LfsFdIsValid(fd) == FALSE) {
errno = EBADF;
LfsUnlock();
return VFS_ERROR;
}
ret = lfs_file_read(g_handle[fd].lfsHandle, &(g_handle[fd].file), buf, len);
if (ret < 0) {
errno = LittlefsErrno(ret);
ret = VFS_ERROR;
}
LfsUnlock();
return ret;
}
int LfsWrite(int fd, const void *buf, unsigned int len)
{
int ret;
if (buf == NULL) {
errno = EFAULT;
return VFS_ERROR;
}
if (LfsLock() != LOS_OK) {
errno = EAGAIN;
return VFS_ERROR;
}
if (LfsFdIsValid(fd) == FALSE) {
errno = EBADF;
LfsUnlock();
return VFS_ERROR;
}
ret = lfs_file_write(g_handle[fd].lfsHandle, &(g_handle[fd].file), buf, len);
if (ret < 0) {
errno = LittlefsErrno(ret);
ret = VFS_ERROR;
}
LfsUnlock();
return ret;
}
off_t LfsSeek(int fd, off_t offset, int whence)
{
off_t ret;
if (LfsLock() != LOS_OK) {
errno = EAGAIN;
return VFS_ERROR;
}
if (LfsFdIsValid(fd) == FALSE) {
errno = EBADF;
LfsUnlock();
return VFS_ERROR;
}
ret = (off_t)lfs_file_seek(g_handle[fd].lfsHandle, &(g_handle[fd].file), offset, whence);
if (ret < 0) {
errno = LittlefsErrno(ret);
ret = VFS_ERROR;
}
LfsUnlock();
return ret;
}
int LfsClose(int fd)
{
int ret;
if (LfsLock() != LOS_OK) {
errno = EAGAIN;
return VFS_ERROR;
}
if (LfsFdIsValid(fd) == FALSE) {
errno = EBADF;
LfsUnlock();
return VFS_ERROR;
}
ret = lfs_file_close(g_handle[fd].lfsHandle, &(g_handle[fd].file));
LfsFreeFd(fd);
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = VFS_ERROR;
}
LfsUnlock();
return ret;
}
int LfsRename(const char *oldName, const char *newName)
{
int ret;
struct FileOpInfo *fileOpInfo = NULL;
if (oldName == NULL || newName == NULL) {
errno = EFAULT;
return VFS_ERROR;
}
if (LfsLock() != LOS_OK) {
errno = EAGAIN;
return VFS_ERROR;
}
if (CheckPathIsMounted(oldName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
errno = ENOENT;
LfsUnlock();
return VFS_ERROR;
}
ret = lfs_rename(&(fileOpInfo->lfsInfo), oldName, newName);
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = VFS_ERROR;
}
LfsUnlock();
return ret;
}
int LfsStat(const char *path, struct stat *buf)
{
int ret;
struct lfs_info info;
struct FileOpInfo *fileOpInfo = NULL;
if (path == NULL || buf == NULL) {
errno = EFAULT;
return VFS_ERROR;
}
if (LfsLock() != LOS_OK) {
errno = EAGAIN;
return VFS_ERROR;
}
if (CheckPathIsMounted(path, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
errno = ENOENT;
LfsUnlock();
return VFS_ERROR;
}
ret = lfs_stat(&(fileOpInfo->lfsInfo), path, &info);
if (ret == 0) {
buf->st_size = info.size;
if (info.type == LFS_TYPE_REG) {
buf->st_mode = S_IFREG;
} else {
buf->st_mode = S_IFDIR;
}
} else {
errno = LittlefsErrno(ret);
ret = VFS_ERROR;
}
LfsUnlock();
return ret;
}
int LfsFsync(int fd)
{
int ret;
if (LfsLock() != LOS_OK) {
errno = EAGAIN;
return VFS_ERROR;
}
if (LfsFdIsValid(fd) == FALSE) {
errno = EBADF;
LfsUnlock();
return VFS_ERROR;
}
ret = lfs_file_sync(g_handle[fd].lfsHandle, &(g_handle[fd].file));
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = VFS_ERROR;
}
LfsUnlock();
return ret;
}

View File

@@ -0,0 +1,119 @@
/*
* 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.
*/
#ifndef _LFS_API_H_
#define _LFS_API_H_
#include "bits/alltypes.h"
#include "fcntl.h"
#include "sys/stat.h"
#include "dirent.h"
#include "errno.h"
#include "fs_operations.h"
#include "lfs.h"
#include "lfs_util.h"
#include "memory.h"
#define INVALID_FD (-1)
typedef unsigned mode_t;
#ifndef VFS_ERROR
#define VFS_ERROR (-1)
#endif
#ifndef VFS_OK
#define VFS_OK 0
#endif
typedef struct {
uint8_t useFlag;
const char *pathName;
lfs_t *lfsHandle;
lfs_file_t file;
} LittleFsHandleStruct;
struct FileOpInfo {
uint8_t useFlag;
const struct FileOps *fsVops;
char *dirName;
lfs_t lfsInfo;
};
typedef struct {
uint8_t useFlag;
char *dirName;
lfs_t *lfsHandle;
lfs_dir_t dir;
} FileDirInfo;
#define LITTLE_FS_MAX_OPEN_FILES 100
#define LITTLE_FS_STANDARD_NAME_LENGTH 50
#define LITTLE_FS_MAX_NAME_LEN 255
#define MAX_DEF_BUF_NUM 21
#define MAX_BUFFER_LEN 100
#define MAX_WRITE_FILE_LEN 500
#define MAX_READ_FILE_LEN 500
#define LITTLEFS_MAX_LFN_LEN 255
#ifndef LFS_MAX_OPEN_DIRS
#define LFS_MAX_OPEN_DIRS 10
#endif
LittleFsHandleStruct *GetFreeFd(int *fd);
int InitMountInfo(const char *fileSystemType, const struct MountOps *fsMops);
int LfsMount(const char *source, const char *target, const char *fileSystemType, unsigned long mountflags,
const void *data);
int LfsUmount(const char *target);
int LfsUnlink(const char *fileName);
int LfsMkdir(const char *dirName, mode_t mode);
int LfsRmdir(const char *dirName);
DIR *LfsOpendir(const char *dirName);
struct dirent *LfsReaddir(DIR *dir);
int LfsClosedir(DIR *dir);
int LfsOpen(const char *pathName, int openFlag, int mode);
int LfsRead(int fd, void *buf, unsigned int len);
int LfsWrite(int fd, const void *buf, unsigned int len);
off_t LfsSeek(int fd, off_t offset, int whence);
int LfsClose(int fd);
int LfsRename(const char *oldName, const char *newName);
int LfsStat(const char *path, struct stat *buf);
int LfsFsync(int fd);
int SetDefaultMountPath(int pathNameIndex, const char* target);
const struct FsMap *MountFindfs(const char *filesystemtype);
#endif /* _LFS_API_H_ */

View File

@@ -0,0 +1,52 @@
# 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.
import("//third_party/lwip/lwip.gni")
import("lwip_porting.gni")
config("lwip_depends") {
defines = [ "_BSD_SOURCE = 1" ]
}
static_library("lwip") {
include_dirs = [
"//kernel/liteos_m/kal/posix/include",
"//kernel/liteos_m/kernel/arch/include",
]
include_dirs += LWIP_PORTING_INCLUDE_DIRS
include_dirs += LWIP_INCLUDE_DIRS
sources = LWIP_PORTING_FILES + LWIPNOAPPSFILES
sources -= [ "$LWIPDIR/api/sockets.c" ]
configs += [ ":lwip_depends" ]
deps = [ "//kernel/liteos_m/kal/posix" ]
}

View File

@@ -39,6 +39,27 @@
#define NETIFAPI_VAR_ALLOC(name) API_VAR_ALLOC(struct netifapi_msg, MEMP_NETIFAPI_MSG, name, ERR_MEM)
#define NETIFAPI_VAR_FREE(name) API_VAR_FREE(MEMP_NETIFAPI_MSG, name)
#if LWIP_DHCP
#include <lwip/dhcp.h>
#include <lwip/prot/dhcp.h>
err_t dhcp_is_bound(struct netif *netif)
{
struct dhcp *dhcp = NULL;
LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG);
dhcp = netif_dhcp_data(netif);
LWIP_ERROR("netif->dhcp != NULL", (dhcp != NULL), return ERR_ARG);
if (dhcp->state == DHCP_STATE_BOUND) {
return ERR_OK;
} else {
return ERR_INPROGRESS;
}
}
#endif /* LWIP_DHCP */
static struct netif *netif_find_by_name(const char *name)
{
struct netif *netif = NULL;

View File

@@ -0,0 +1,334 @@
/*
* 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 "lwip/opt.h"
#if LWIP_IFADDRS
#if (LWIP_IPV4 || LWIP_IPV6) && LWIP_SOCKET
#include "ifaddrs.h"
#include <stdlib.h>
#include "lwip/sys.h"
#include "lwip/tcpip.h"
#include "lwip/priv/sockets_priv.h"
#include "lwip/mem.h"
#include "lwip/netif.h"
#include "lwip/dhcp.h"
struct ifaddrs_storage {
struct ifaddrs ifa;
union {
struct sockaddr sa;
struct sockaddr_in s4;
#if LWIP_IPV6
struct sockaddr_in6 s6;
#endif
} addr, netmask, dstaddr;
char name[IFNAMSIZ];
};
struct getifaddrs_arg {
struct ifaddrs **ifap;
sys_sem_t cb_completed;
int ret;
};
static int tcpip_init_finish = 1;
void lwip_freeifaddrs(struct ifaddrs *ifa);
static void ifaddrs_add_tail(struct ifaddrs **ifap, struct ifaddrs *ifaddr)
{
struct ifaddrs *temp = NULL;
ifaddr->ifa_next = NULL;
if (*ifap == NULL) {
*ifap = ifaddr;
return;
}
for (temp = *ifap; temp->ifa_next != NULL; temp = temp->ifa_next) {
/* nothing */
}
temp->ifa_next = ifaddr;
}
static struct ifaddrs_storage *new_ifaddrs_storage(void)
{
struct ifaddrs *ifaddr = NULL;
struct ifaddrs_storage *if_storage = NULL;
if_storage = (struct ifaddrs_storage *)mem_malloc(sizeof(struct ifaddrs_storage));
if (if_storage != NULL) {
(void)memset_s((void*)if_storage, sizeof(struct ifaddrs_storage), 0, sizeof(struct ifaddrs_storage));
ifaddr = &if_storage->ifa;
ifaddr->ifa_name = if_storage->name;
ifaddr->ifa_addr = &if_storage->addr.sa;
ifaddr->ifa_netmask = &if_storage->netmask.sa;
ifaddr->ifa_dstaddr = &if_storage->dstaddr.sa;
}
return if_storage;
}
static int get_ifa_name(struct netif *netif, struct ifaddrs *ifaddr)
{
int ret;
if (netif->link_layer_type == LOOPBACK_IF) {
ifaddr->ifa_flags |= IFF_LOOPBACK;
ret = snprintf_s(ifaddr->ifa_name, NETIF_NAMESIZE, (NETIF_NAMESIZE - 1), "%.2s", netif->name);
} else {
ret = snprintf_s(ifaddr->ifa_name, NETIF_NAMESIZE, (NETIF_NAMESIZE - 1), "%s", netif_get_name(netif));
}
return ret;
}
#if LWIP_IPV4
static int get_ipv4_ifaddr(struct netif *netif, struct ifaddrs *ifaddr)
{
struct sockaddr_in *addr_in = NULL;
if (netif->flags & NETIF_FLAG_UP) {
ifaddr->ifa_flags |= IFF_UP;
}
if (netif->flags & NETIF_FLAG_ETHARP) {
ifaddr->ifa_flags = ifaddr->ifa_flags & ((unsigned int)(~IFF_NOARP));
} else {
ifaddr->ifa_flags |= IFF_NOARP;
}
if (netif->flags & NETIF_FLAG_BROADCAST) {
ifaddr->ifa_flags |= IFF_BROADCAST;
}
#if LWIP_DHCP
if (dhcp_supplied_address(netif)) {
ifaddr->ifa_flags |= IFF_DYNAMIC;
}
#endif
#if LWIP_IGMP
if (netif->flags & NETIF_FLAG_IGMP) {
ifaddr->ifa_flags |= IFF_MULTICAST;
}
#endif
if (netif->flags & NETIF_FLAG_LINK_UP) {
ifaddr->ifa_flags |= IFF_RUNNING;
}
#if LWIP_HAVE_LOOPIF
if (netif->link_layer_type == LOOPBACK_IF) {
addr_in = (struct sockaddr_in *)ifaddr->ifa_addr;
addr_in->sin_family = AF_INET;
addr_in->sin_addr.s_addr = ((ip4_addr_t *)&netif->ip_addr)->addr;
} else
#endif
{
addr_in = (struct sockaddr_in *)ifaddr->ifa_addr;
addr_in->sin_family = AF_INET;
addr_in->sin_addr.s_addr = ((ip4_addr_t *)&netif->ip_addr)->addr;
addr_in = (struct sockaddr_in *)ifaddr->ifa_netmask;
addr_in->sin_family = AF_INET;
addr_in->sin_addr.s_addr = ((ip4_addr_t *)&netif->netmask)->addr;
addr_in = (struct sockaddr_in *)ifaddr->ifa_broadaddr;
addr_in->sin_family = AF_INET;
addr_in->sin_addr.s_addr = (((ip4_addr_t *)&netif->ip_addr)->addr & ((ip4_addr_t *)&netif->netmask)->addr) |
~((ip4_addr_t *)&netif->netmask)->addr;
}
return get_ifa_name(netif, ifaddr);
}
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
/* Stack support to retrieve the below flags for ipv6
IFF_UP
IFF_MULTICAST
IFF_RUNNING
IFF_LOOPBACK
*/
static int get_ipv6_ifaddr(struct netif *netif, struct ifaddrs *ifaddr, int tmp_index)
{
struct sockaddr_in6 *addr_in6 = NULL;
/* As of now supports the below falgs only */
if (netif->flags & NETIF_FLAG_UP) {
ifaddr->ifa_flags |= IFF_UP;
}
#if LWIP_IPV6_MLD
if (netif->flags & NETIF_FLAG_MLD6) {
ifaddr->ifa_flags |= IFF_MULTICAST;
}
#endif
if (netif->flags & NETIF_FLAG_LINK_UP) {
ifaddr->ifa_flags |= IFF_RUNNING;
}
addr_in6 = (struct sockaddr_in6 *)ifaddr->ifa_addr;
addr_in6->sin6_family = AF_INET6;
inet6_addr_from_ip6addr(&addr_in6->sin6_addr, (ip6_addr_t *)&netif->ip6_addr[tmp_index]);
return get_ifa_name(netif, ifaddr);
}
#endif
static void getifaddrs_internal(struct getifaddrs_arg *arg)
{
struct netif *netif = NULL;
struct ifaddrs *ifaddr = NULL;
struct ifaddrs_storage *if_storage = NULL;
#if LWIP_IPV6
int n;
#endif
arg->ret = ENOMEM;
for (netif = netif_list; netif != NULL; netif = netif->next) {
#if LWIP_IPV4
if_storage = new_ifaddrs_storage();
if (if_storage == NULL) {
lwip_freeifaddrs(
*(arg->ifap)); /* ifap is assigned to NULL in getifaddrs, so garbage value will not be there */
arg->ret = ENOMEM;
goto RETURN;
}
/* if get one or more netif info, then getifaddrs return 0(OK) */
arg->ret = 0;
ifaddr = &if_storage->ifa;
(void)get_ipv4_ifaddr(netif, ifaddr);
ifaddrs_add_tail(arg->ifap, ifaddr);
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
for (n = 0; n < LWIP_IPV6_NUM_ADDRESSES; n++) {
if ((netif->ip6_addr_state[n] & IP6_ADDR_VALID) == 0) {
continue;
}
if_storage = new_ifaddrs_storage();
if (if_storage == NULL) {
lwip_freeifaddrs(
*(arg->ifap)); /* ifap is assigned to NULL in getifaddrs, so garbage value will not be there */
arg->ret = ENOMEM;
goto RETURN;
}
/* if get one or more netif info, then getifaddrs return 0(OK) */
arg->ret = 0;
ifaddr = &if_storage->ifa;
(void)get_ipv6_ifaddr(netif, ifaddr, n);
ifaddrs_add_tail(arg->ifap, ifaddr);
}
#endif
}
RETURN:
#if !LWIP_TCPIP_CORE_LOCKING
sys_sem_signal(&arg->cb_completed);
#endif
return;
}
int lwip_getifaddrs(struct ifaddrs **ifap)
{
struct getifaddrs_arg arg;
LWIP_ERROR("lwip_getifaddrs : ifap is NULL", (ifap != NULL), return ERR_ARG);
*ifap = NULL;
if (!tcpip_init_finish) {
set_errno(EACCES);
return -1;
}
arg.ret = 0;
arg.ifap = ifap;
#if LWIP_TCPIP_CORE_LOCKING
LOCK_TCPIP_CORE();
getifaddrs_internal(&arg);
UNLOCK_TCPIP_CORE();
#else
if (sys_sem_new(&arg.cb_completed, 0) != ERR_OK) {
set_errno(ENOMEM);
return -1;
}
tcpip_callback((tcpip_callback_fn)getifaddrs_internal, &arg);
(void)sys_arch_sem_wait(&arg.cb_completed, 0);
sys_sem_free(&arg.cb_completed);
#endif
if (arg.ret != 0) {
set_errno(arg.ret);
*ifap = NULL;
return -1;
}
return 0;
}
static void freeifaddrs_iteration(struct ifaddrs *ifa)
{
if (ifa == NULL) {
return;
}
if (ifa->ifa_next != NULL) {
freeifaddrs_iteration(ifa->ifa_next);
}
mem_free(ifa);
}
void lwip_freeifaddrs(struct ifaddrs *ifa)
{
freeifaddrs_iteration(ifa);
}
int getifaddrs(struct ifaddrs **ifap)
{
return lwip_getifaddrs(ifap);
}
void freeifaddrs(struct ifaddrs *ifa)
{
lwip_freeifaddrs(ifa);
}
#endif /* (LWIP_IPV4 || LWIP_IPV6) && LWIP_SOCKET */
#endif /* LWIP_IFADDRS */

View File

@@ -0,0 +1,45 @@
# 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.
import("//kernel/liteos_m/config.gni")
LWIP_PORTING_DIR = "//kernel/liteos_m/components/net/lwip-2.1"
LWIP_PORTING_INCLUDE_DIRS = [ "$LWIP_PORTING_DIR/porting/include" ]
LWIP_PORTING_FILES = [
"$LWIP_PORTING_DIR/porting/src/driverif.c",
"$LWIP_PORTING_DIR/porting/src/lwip_init.c",
"$LWIP_PORTING_DIR/porting/src/netdb_porting.c",
"$LWIP_PORTING_DIR/porting/src/sockets_porting.c",
"$LWIP_PORTING_DIR/porting/src/sys_arch.c",
"$LWIP_PORTING_DIR/enhancement/src/fixme.c",
"$LWIP_PORTING_DIR/enhancement/src/lwip_ifaddrs.c",
]
if (enable_ohos_kernel_liteos_m_shell) {
LWIP_PORTING_FILES += [ "$LWIP_PORTING_DIR/porting/src/api_shell.c" ]
}

View File

@@ -44,7 +44,6 @@
#include <stdio.h>
#include <stdlib.h>
#include "securec.h"
#include "memory_pool.h"
#ifdef htons
#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
@@ -94,33 +93,17 @@
#define LWIP_RAND rand
extern void HilogPrintf(const char *fmt, ...);
#ifndef HILOG_INFO
#define HILOG_INFO(...)
#ifndef HILOG_MODULE_APP
#define HILOG_MODULE_APP 0
#endif
#ifndef LWIP_LOGGER
#define LWIP_LOGGER(msg)
#endif
#ifndef HILOG_ERROR
#define HILOG_ERROR(...)
#endif
#define LWIP_PLATFORM_DIAG(vars) HilogPrintf vars
#define LWIP_PLATFORM_ASSERT(x) do {HILOG_ERROR(HILOG_MODULE_APP, \
"Assertion \"%s\" errno %d line %d in %s\n", \
x, errno, __LINE__, __FILE__);} while (0)
#define mem_clib_malloc LWIP_MEM_ALLOC
#define mem_clib_free LWIP_MEM_FREE
#define mem_clib_calloc LWIP_MEM_CALLOC
extern void LwipLogPrintf(const char *fmt, ...);
#define LWIP_PLATFORM_DIAG(vars) LwipLogPrintf vars
#define LWIP_PLATFORM_ASSERT(x) do { \
LWIP_PLATFORM_DIAG(("Assertion \"%s\" failed at line %d in %s\n", x, __LINE__, __FILE__)); \
} while (0)
#define init_waitqueue_head(...)
#define poll_check_waiters(...)
#define IOCTL_CMD_CASE_HANDLER()
#define DNS_SERVER_ADDRESS(ipaddr) (ip4_addr_set_u32(ipaddr, ipaddr_addr("114.114.114.114")))
#define DNS_SERVER_ADDRESS_SECONDARY(ipaddr) (ip4_addr_set_u32(ipaddr, ipaddr_addr("114.114.115.115")))
#endif /* _LWIP_PORTING_CC_H_ */

View File

@@ -0,0 +1,49 @@
/*
* 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.
*/
#ifndef LWIP_API_SHELL_H
#define LWIP_API_SHELL_H
#include "arch/cc.h"
#include "lwip/opt.h"
#if defined (__cplusplus) && __cplusplus
extern "C" {
#endif
u32_t lwip_ifconfig(int argc, const char **argv);
u32_t OsShellPing(int argc, const char **argv);
LWIP_STATIC int OsPingFunc(u32_t *parg);
#if defined (__cplusplus) && __cplusplus
}
#endif
#endif /* LWIP_HDR_API_SHELL_H */

View File

@@ -1,38 +1,38 @@
/*
* 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.
*/
/**
* @brief Configures the USART Peripheral.
* @param None
* @retval None
*/
void USART_Config(void);
/*
* 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 _LWIP_PORTING_DHCP_H_
#define _LWIP_PORTING_DHCP_H_
#include_next <lwip/dhcp.h>
err_t dhcp_is_bound(struct netif *netif);
#endif /* _LWIP_PORTING_DHCP_H_ */

View File

@@ -43,9 +43,6 @@
(ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr))
/* directly map this to the lwip internal functions */
#define inet_addr(cp) ipaddr_addr(cp)
#define inet_aton(cp, addr) ip4addr_aton(cp, (ip4_addr_t*)addr)
#define inet_ntoa(addr) ip4addr_ntoa((const ip4_addr_t*)&(addr))
#define inet_ntoa_r(addr, buf, buflen) ip4addr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen)
#endif /* LWIP_IPV4 */
#if LWIP_IPV6

View File

@@ -134,7 +134,7 @@
#define LWIP_NETIF_LOOPBACK 1
#define LWIP_POSIX_SOCKETS_IO_NAMES 0
#define LWIP_RAW 1
#define LWIP_SOCKET_OFFSET FAT_MAX_OPEN_FILES
#define LWIP_SOCKET_OFFSET 0
#define LWIP_SO_RCVBUF 1
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_SNDTIMEO 1
@@ -216,79 +216,15 @@
#define LWIP_ENABLE_NET_CAPABILITY 1
#define LWIP_ENABLE_CAP_NET_BROADCAST 0
// Options for GT
// Options for liteos_m
#undef LWIP_NETIF_PROMISC
#define LWIP_NETIF_PROMISC 0
#undef LWIP_ICMP
#define LWIP_ICMP 0
#undef LWIP_DHCP
#define LWIP_DHCP 0
#undef LWIP_IGMP
#define LWIP_IGMP 0
#define MEMP_MEM_MALLOC 1
#undef LWIP_IPV6
#define LWIP_IPV6 0
#undef LWIP_IPV6_DHCP6
#define LWIP_IPV6_DHCP6 0
#undef TCP_SND_BUF
#define TCP_SND_BUF (65535 / 3)
#undef TCP_WND
#define TCP_WND ((TCP_SND_BUF * 2) / 3)
#undef TCP_SND_QUEUELEN
#define TCP_SND_QUEUELEN (2 * (TCP_SND_BUF / TCP_MSS))
#undef MEMP_NUM_NETDB
#define MEMP_NUM_NETDB 1
#undef MEMP_NUM_ARP_QUEUE
#define MEMP_NUM_ARP_QUEUE 4
#undef MEMP_NUM_NETBUF
#define MEMP_NUM_NETBUF 12
#undef MEMP_NUM_NETCONN
#define MEMP_NUM_NETCONN 32
#undef MEMP_NUM_PBUF
#define MEMP_NUM_PBUF 0
#undef PBUF_POOL_SIZE
#define PBUF_POOL_SIZE 0
#undef MEMP_NUM_RAW_PCB
#define MEMP_NUM_RAW_PCB 8
#undef MEMP_NUM_REASSDATA
#define MEMP_NUM_REASSDATA 12
#undef MEMP_NUM_TCPIP_MSG_API
#define MEMP_NUM_TCPIP_MSG_API 32
#undef MEMP_NUM_TCPIP_MSG_INPKT
#define MEMP_NUM_TCPIP_MSG_INPKT 32
#undef MEMP_NUM_TCP_PCB
#define MEMP_NUM_TCP_PCB 8
#undef MEMP_NUM_TCP_PCB_LISTEN
#define MEMP_NUM_TCP_PCB_LISTEN 4
#undef MEMP_NUM_TCP_SEG
#define MEMP_NUM_TCP_SEG 64
#undef MEMP_NUM_UDP_PCB
#define MEMP_NUM_UDP_PCB 4
#undef TCPIP_THREAD_STACKSIZE
#define TCPIP_THREAD_STACKSIZE 0x1000
#undef LWIP_SOCKET_SELECT
#define LWIP_SOCKET_SELECT 1

View File

@@ -72,6 +72,8 @@ extern "C" {
err_t driverif_init(struct netif *netif);
void driverif_input(struct netif *netif, struct pbuf *p);
#define netif_get_name(netif) ((netif)->full_name)
#ifdef __cplusplus
}
#endif

View File

@@ -41,7 +41,6 @@
#include <limits.h>
#include <fcntl.h>
#include_next <lwip/sockets.h>
#include <fatfs.h>
#ifdef __cplusplus
extern "C" {

View File

@@ -0,0 +1,613 @@
/*
* 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.
*/
#define LWIP_STATIC static
#define DHCP_STATE_OFF 0
#define LWIP_EXT_POLL_SUPPORT 1
#include "lwip/api.h"
#include "lwip/netdb.h"
#include "lwip/stats.h"
#include "lwip/err.h"
#include "lwip/ip_addr.h"
#include "lwip/icmp.h"
#include "los_config.h"
#include <string.h>
#include "shcmd.h"
#include "shell.h"
#include "los_debug.h"
#include "los_task.h"
/* Forward Declarations [START] */
#ifndef LWIP_TESTBED
LWIP_STATIC
#endif
int print_netif(struct netif *netif, char *print_buf, unsigned int buf_len);
#ifndef LWIP_TESTBED
LWIP_STATIC
#endif
void lwip_ifconfig_show_internal(void *arg);
#if LWIP_DNS
LWIP_STATIC unsigned int get_hostip(const char *hname);
#ifndef LWIP_TESTBED
LWIP_STATIC
#endif
struct hostent *gethostnameinfo(const char *host, char *tmphstbuf, size_t hstbuflen);
#endif /* LWIP_DNS */
#define PRINT_BUF_LEN 1024
struct ifconfig_option {
char iface[IFNAMSIZ];
unsigned int option;
ip_addr_t ip_addr;
ip_addr_t netmask;
ip_addr_t gw;
unsigned char ethaddr[6];
u16_t mtu;
/* when using telnet, print to the telnet socket will result in system */
/* deadlock. So we cahe the prinf data to a buf, and when the tcpip */
/* callback returns, then print the data out to the telnet socket */
sys_sem_t cb_completed;
char cb_print_buf[PRINT_BUF_LEN];
unsigned int print_len;
};
#ifndef LWIP_TESTBED
LWIP_STATIC
#endif
int print_netif(struct netif *netif, char *print_buf, unsigned int buf_len)
{
int i, ret;
char *tmp = print_buf;
if (buf_len < 1) {
goto out;
}
if (netif->link_layer_type == LOOPBACK_IF) {
ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%s\t", netif->name);
} else {
ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%s%u\t", netif->name, netif->num);
}
if ((ret <= 0) || ((unsigned int)ret >= buf_len))
goto out;
tmp += ret;
buf_len -= (unsigned int)ret;
#if LWIP_IPV4
ret = snprintf_s(tmp, buf_len, (buf_len - 1), "ip:%s ", ipaddr_ntoa(&netif->ip_addr));
if ((ret <= 0) || ((unsigned int)ret >= buf_len))
goto out;
tmp += ret;
buf_len -= (unsigned int)ret;
ret = snprintf_s(tmp, buf_len, (buf_len - 1), "netmask:%s ", ipaddr_ntoa(&netif->netmask));
if ((ret <= 0) || ((unsigned int)ret >= buf_len))
goto out;
tmp += ret;
buf_len -= (unsigned int)ret;
ret = snprintf_s(tmp, buf_len, (buf_len - 1), "gateway:%s\n", ipaddr_ntoa(&netif->gw));
if ((ret <= 0) || ((unsigned int)ret >= buf_len))
goto out;
tmp += ret;
buf_len -= (unsigned int)ret;
#endif
ret = snprintf_s(tmp, buf_len, (buf_len - 1), "\tHWaddr ");
if ((ret <= 0) || ((unsigned int)ret >= buf_len))
goto out;
tmp += ret;
buf_len -= (unsigned int)ret;
for (i = 0; i < netif->hwaddr_len - 1; i++) {
ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%02x:", netif->hwaddr[i]);
if ((ret <= 0) || ((unsigned int)ret >= buf_len))
goto out;
tmp += ret;
buf_len -= (unsigned int)ret;
}
ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%02x", netif->hwaddr[i]);
if ((ret <= 0) || ((unsigned int)ret >= buf_len))
goto out;
tmp += ret;
buf_len -= (unsigned int)ret;
ret = snprintf_s(tmp, buf_len, (buf_len - 1), " MTU:%d %s", netif->mtu,
netif->flags & NETIF_FLAG_UP ? "Running" : "Stop");
if ((ret <= 0) || ((unsigned int)ret >= buf_len))
goto out;
tmp += ret;
buf_len -= (unsigned int)ret;
if (netif_default == netif && netif_is_up(netif)) {
ret = snprintf_s(tmp, buf_len, (buf_len - 1), " %s", "Default");
if ((ret <= 0) || ((unsigned int)ret >= buf_len))
goto out;
tmp += ret;
buf_len -= (unsigned int)ret;
}
ret = snprintf_s(tmp, buf_len, (buf_len - 1), " %s\n", netif->flags & NETIF_FLAG_LINK_UP ? "Link UP" : "Link Down");
if ((ret <= 0) || ((unsigned int)ret >= buf_len))
goto out;
tmp += ret;
out:
return (int)(tmp - print_buf);
}
#ifndef LWIP_TESTBED
LWIP_STATIC
#endif
void lwip_ifconfig_show_internal(void *arg)
{
struct netif *netif = NULL;
struct ifconfig_option *ifconfig_cmd = (struct ifconfig_option *)arg;
int ret;
if (netif_list == NULL) {
ret = snprintf_s(ifconfig_cmd->cb_print_buf, PRINT_BUF_LEN - ifconfig_cmd->print_len,
((PRINT_BUF_LEN - ifconfig_cmd->print_len) - 1), "Device not init\n");
if ((ret > 0) && ((unsigned int)ret < (PRINT_BUF_LEN - ifconfig_cmd->print_len))) {
ifconfig_cmd->print_len += (unsigned int)ret;
}
sys_sem_signal(&ifconfig_cmd->cb_completed);
return;
}
if (ifconfig_cmd->iface[0] == '\0') {
/* display all netif */
for (netif = netif_list; netif != NULL; netif = netif->next) {
ret = print_netif(netif, ifconfig_cmd->cb_print_buf + ifconfig_cmd->print_len,
PRINT_BUF_LEN - ifconfig_cmd->print_len);
ifconfig_cmd->print_len += (unsigned int)ret;
}
} else {
netif = netif_find(ifconfig_cmd->iface);
if (netif == NULL) {
ret = snprintf_s(ifconfig_cmd->cb_print_buf + ifconfig_cmd->print_len,
(PRINT_BUF_LEN - ifconfig_cmd->print_len),
((PRINT_BUF_LEN - ifconfig_cmd->print_len) - 1), "Device not found\n");
if ((ret > 0) && ((unsigned int)ret < (PRINT_BUF_LEN - ifconfig_cmd->print_len))) {
ifconfig_cmd->print_len += (unsigned int)ret;
}
sys_sem_signal(&ifconfig_cmd->cb_completed);
return;
}
ret = print_netif(netif, ifconfig_cmd->cb_print_buf + ifconfig_cmd->print_len,
PRINT_BUF_LEN - ifconfig_cmd->print_len);
ifconfig_cmd->print_len += (unsigned int)ret;
}
sys_sem_signal(&ifconfig_cmd->cb_completed);
}
/*lint -e838 -e438*/
u32_t lwip_ifconfig(int argc, const char **argv)
{
static struct ifconfig_option ifconfig_cmd;
err_t ret;
#if LWIP_STATS
u32_t stat_err_cnt;
u32_t stat_drop_cnt;
u32_t stat_rx_or_tx_cnt;
u32_t stat_rx_or_tx_bytes;
#endif
(void)memset_s(&ifconfig_cmd, sizeof(ifconfig_cmd), 0, sizeof(ifconfig_cmd));
if (sys_sem_new(&ifconfig_cmd.cb_completed, 0) != ERR_OK) {
PRINTK("%s: sys_sem_new fail\n", __FUNCTION__);
return 1;
}
/* Get the interface */
/* no more arguments, show all the interface state. */
ret = tcpip_callback(lwip_ifconfig_show_internal, &ifconfig_cmd);
if (ret != ERR_OK) {
sys_sem_free(&ifconfig_cmd.cb_completed);
PRINTK("ifconfig : internal error, l:%d err:%d\n", __LINE__, ret);
return 1;
}
(void)sys_arch_sem_wait(&ifconfig_cmd.cb_completed, 0);
sys_sem_free(&ifconfig_cmd.cb_completed);
ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] = '\0';
PRINTK("%s", ifconfig_cmd.cb_print_buf);
return 0;
}
/*lint +e838 +e438*/
#if LWIP_DNS
#ifndef LWIP_TESTBED
LWIP_STATIC
#endif
struct hostent *gethostnameinfo(const char *host, char *tmphstbuf, size_t hstbuflen)
{
static struct hostent hostbuf;
struct hostent *hp = NULL;
int res;
int herr;
if (tmphstbuf == NULL)
return NULL;
res = lwip_gethostbyname_r(host, &hostbuf, tmphstbuf, hstbuflen, &hp, &herr);
/* Check for errors. */
if (res || hp == NULL) {
return NULL;
}
return hp;
}
LWIP_STATIC unsigned int get_hostip(const char *hname)
{
unsigned int ip = 0;
int ret;
const size_t hstbuflen = 1024;
char *tmphstbuf = NULL;
tmphstbuf = (char *)zalloc(sizeof(char) * hstbuflen);
if (tmphstbuf == NULL)
return 0;
struct hostent *pent = gethostnameinfo(hname, tmphstbuf, hstbuflen);
if (pent == NULL || pent->h_addr == NULL) {
free(tmphstbuf);
return 0;
}
ret = memcpy_s(&ip, sizeof(ip), pent->h_addr, 4);
if (ret != 0) {
free(tmphstbuf);
return 0;
}
free(tmphstbuf);
return ip;
}
#endif
static int ping_taskid = -1;
static int ping_kill = 0;
#define LWIP_SHELL_CMD_PING_TIMEOUT 2000
#define LWIP_SHELL_CMD_PING_RETRY_TIMES 4
#define PING_ZERO_DATA_LEN 8
static void lwip_ping_usage(void)
{
PRINTK("Usage:\n ping [ip]\n");
}
LWIP_STATIC int OsPingFunc(u32_t *parg)
{
int sfd;
struct sockaddr_in to;
struct pbuf *pbuf_resp = NULL;
struct icmp_echo_hdr *iecho = NULL;
struct icmp_echo_hdr *iecho_resp = NULL;
struct ip_hdr *iphdr_resp = NULL;
u32_t iecho_len;
s16_t ip_hlen;
u32_t forever;
u32_t i;
u32_t succ_cnt = 0;
u32_t failed_cnt = 0;
struct timespec start, end;
long timout_ms;
struct pollfd pfd;
long rtt;
int ret = 0;
u32_t intrvl;
char *data_buf = NULL;
BOOL timeout_flag = FALSE;
char buf[50];
u32_t destip = parg[0];
u32_t cnt = parg[1];
u32_t interval = parg[2];
u32_t data_len = parg[3];
iecho_len = sizeof(struct icmp_echo_hdr) + data_len;
sfd = lwip_socket(PF_INET, SOCK_RAW, IPPROTO_ICMP);
if (sfd < 0) {
perror("Ping socket");
return -1;
}
pbuf_resp = pbuf_alloc(PBUF_RAW, IP_HLEN + sizeof(struct icmp_echo_hdr), PBUF_RAM);
if (pbuf_resp == NULL) {
PRINTK("Ping: pbuf_resp malloc failed\n");
ret = -1;
goto FAILURE;
}
iecho = (struct icmp_echo_hdr *)mem_malloc(iecho_len);
if (iecho == NULL) {
PRINTK("Ping: echo request malloc failed\n");
ret = -1;
goto FAILURE;
}
to.sin_family = AF_INET;
to.sin_addr.s_addr = destip; /* already in network order */
to.sin_port = 0;
if (data_len > PING_ZERO_DATA_LEN) {
(void)memset_s(iecho, sizeof(struct icmp_echo_hdr) + PING_ZERO_DATA_LEN,
0, sizeof(struct icmp_echo_hdr) + PING_ZERO_DATA_LEN);
data_buf = (char *)iecho + sizeof(struct icmp_echo_hdr) + PING_ZERO_DATA_LEN;
for (i = 0; i < data_len - PING_ZERO_DATA_LEN; i++) {
*(data_buf + i) = i + 0x10;
}
} else {
(void)memset_s(iecho, sizeof(struct icmp_echo_hdr) + data_len, 0, sizeof(struct icmp_echo_hdr) + data_len);
}
iecho->id = htons((u16_t)LOS_CurTaskIDGet());
ICMPH_TYPE_SET(iecho, (u8_t)ICMP_ECHO);
forever = (cnt ? 0 : 1);
i = 0;
while (!ping_kill && (forever || (i < cnt))) {
iecho->seqno = htons((u16_t)i);
iecho->chksum = 0;
iecho->chksum = inet_chksum((void *)iecho, iecho_len);
ret = sendto(sfd, iecho, iecho_len, 0, (struct sockaddr *)&to, (socklen_t)sizeof(to));
if (ret < 0) {
perror("Ping: sending ICMP echo request failed\n");
goto FAILURE;
}
/* capture the start time to calculate RTT */
(void)clock_gettime(CLOCK_MONOTONIC_RAW, &start);
/* poll for ICMP echo response msg */
pfd.fd = sfd;
do {
pfd.events = POLLIN;
pfd.revents = 0;
timeout_flag = FALSE;
ret = poll(&pfd, 1, LWIP_SHELL_CMD_PING_TIMEOUT);
if (ret < 0) {
perror("Ping: poll\n");
goto FAILURE;
} else if (ret == 0) {
/* first type timeout event */
timeout_flag = TRUE;
break;
}
ret = recv(sfd, pbuf_resp->payload, pbuf_resp->len, MSG_DONTWAIT);
if (ret < 0) {
perror("Ping: recv echo reply failed\n");
goto FAILURE;
}
/* Accessing ip header and icmp header */
iphdr_resp = pbuf_resp->payload;
ip_hlen = (IPH_HL(iphdr_resp) << 2);
if (pbuf_header(pbuf_resp, -ip_hlen)) {
/* this failure will never happen, but failure handle is written just to be in safe side */
PRINTK("Ping : memory management failure\n");
goto FAILURE;
}
iecho_resp = (struct icmp_echo_hdr *)pbuf_resp->payload;
/* Reverting back pbuf to its original state */
if (pbuf_header(pbuf_resp, ip_hlen)) {
/* this failure will never happen, but failure handle is written just to be in safe side */
PRINTK("ping : memory management failure\n");
goto FAILURE;
}
if ((iphdr_resp->src.addr != to.sin_addr.s_addr) ||
((ICMPH_TYPE(iecho_resp) == ICMP_ECHO) && (iphdr_resp->src.addr == to.sin_addr.s_addr))) {
/* second type timeout event */
(void)clock_gettime(CLOCK_MONOTONIC_RAW, &end);
timout_ms = ((end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000);
timout_ms = LWIP_SHELL_CMD_PING_TIMEOUT - timout_ms;
} else {
timout_ms = 0;
break;
}
} while (timout_ms >= 0);
/* all timeout events are true timeout */
if ((timout_ms < 0) || (timeout_flag == TRUE)) {
failed_cnt++;
i++;
PRINTK("\nPing: destination unreachable ...");
continue;
}
/* capture the end time to calculate round trip time */
(void)clock_gettime(CLOCK_MONOTONIC_RAW, &end);
rtt = ((end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000);
if (iphdr_resp->src.addr == to.sin_addr.s_addr) {
switch (ICMPH_TYPE(iecho_resp)) {
case ICMP_ER:
PRINTK("\n[%u]Reply from %s: ", i, inet_ntop(AF_INET, &to.sin_addr, buf, sizeof(buf)));
if (rtt > 0) {
PRINTK("time=%ims ", rtt);
} else {
PRINTK("time<1ms ");
}
PRINTK("TTL=%u", iphdr_resp->_ttl);
/* delay 1s for every successful ping */
intrvl = interval;
do {
if (intrvl < 1000) {
sys_msleep(intrvl);
break;
}
intrvl -= 1000;
sys_msleep(1000);
if (ping_kill == 1)
break;
} while (intrvl > 0);
succ_cnt++;
break;
case ICMP_DUR:
PRINTK("\nPing: destination host unreachable ...");
break;
case ICMP_SQ:
PRINTK("\nPing: source quench ...");
break;
case ICMP_RD:
PRINTK("\nPing: redirect ...");
break;
case ICMP_TE:
PRINTK("\nPing: time exceeded ...");
break;
case ICMP_PP:
PRINTK("\nPing: parameter problem ...");
break;
default:
PRINTK("\nPing: unknow error ...");
break;
}
i++;
}
}
PRINTK("\n--- %s ping statistics ---\n", inet_ntop(AF_INET, &to.sin_addr, buf, sizeof(buf)));
PRINTK("%u packets transmitted, %u received, %u loss\n", i, succ_cnt, failed_cnt);
FAILURE:
ping_kill = 0;
(void)lwip_close(sfd);
if (pbuf_resp != NULL) {
(void)pbuf_free(pbuf_resp);
}
if (iecho != NULL) {
mem_free(iecho);
}
return ret;
}
static void ping_cmd(u32_t *parg)
{
int ret;
ret = OsPingFunc(parg);
if (ret < 0) {
PRINTK("Ping cmd failed due to some errors\n");
}
ping_taskid = -1;
}
u32_t OsShellPing(int argc, const char **argv)
{
int ret;
u32_t i = 0;
u32_t count = 0;
int count_set = 0;
u32_t interval = 1000; /* default ping interval */
u32_t data_len = 48; /* default data length */
ip4_addr_t dst_ipaddr;
TSK_INIT_PARAM_S stPingTask;
u32_t *parg = NULL;
if ((argc < 1) || (argv == NULL)) {
PRINTK("Ping: require dest ipaddr at least\n");
goto ping_error;
}
if (!count_set) {
count = LWIP_SHELL_CMD_PING_RETRY_TIMES;
}
/* initialize dst IP address */
if (argc <= 0) {
goto ping_error;
}
#if LWIP_DNS
dst_ipaddr.addr = get_hostip(argv[i]);
#endif /* LWIP_DNS */
if (dst_ipaddr.addr == IPADDR_NONE || dst_ipaddr.addr == IPADDR_ANY) {
PRINTK("Invalid dest ipaddr: NONE or ANY\n");
return LOS_NOK;
}
parg = (u32_t *)malloc(4 * sizeof(int));
if (parg == NULL) {
return LOS_NOK;
}
parg[0] = dst_ipaddr.addr;
parg[1] = count;
parg[2] = interval;
parg[3] = data_len;
/* start one task if ping forever or ping count greater than 60 */
if (count == 0 || count > LWIP_SHELL_CMD_PING_RETRY_TIMES) {
if (ping_taskid > 0) {
free(parg);
PRINTK("Ping task already running and only support one now\n");
return LOS_NOK;
}
stPingTask.pfnTaskEntry = (TSK_ENTRY_FUNC)ping_cmd;
stPingTask.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
stPingTask.pcName = "ping_task";
stPingTask.usTaskPrio = 8; /* higher than shell */
stPingTask.uwResved = LOS_TASK_STATUS_DETACHED;
stPingTask.uwArg = (UINTPTR)parg;
ret = LOS_TaskCreate((UINT32 *)(&ping_taskid), &stPingTask);
if (ret != LOS_OK) {
PRINTK("ping_task create failed 0x%08x.\n", ret);
count = LWIP_SHELL_CMD_PING_RETRY_TIMES;
} else {
return LOS_OK;
}
}
/* two cases:
1, ping cout less than LWIP_SHELL_CMD_PING_RETRY_TIMES;
2, ping task create failed;
*/
if (OsPingFunc(parg) < 0) {
PRINTK("Ping cmd failed due some errors\n");
}
free(parg);
return LOS_OK;
ping_error:
lwip_ping_usage();
return LOS_NOK;
}

View File

@@ -31,10 +31,31 @@
#include "lwip/netdb.h"
#if LWIP_DNS && LWIP_SOCKET
struct hostent *gethostbyname(const char *name)
{
if (name == NULL) {
return NULL;
}
return lwip_gethostbyname(name);
}
}
int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result,
int *h_errnop)
{
return lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop);
}
void freeaddrinfo(struct addrinfo *res)
{
lwip_freeaddrinfo(res);
}
int getaddrinfo(const char *restrict nodename, const char *restrict servname, const struct addrinfo *restrict hints,
struct addrinfo **restrict res)
{
return lwip_getaddrinfo(nodename, servname, hints, res);
}
#endif

View File

@@ -29,10 +29,12 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "lwip/sockets.h"
#include "lwip/priv/tcpip_priv.h"
#include "lwip/priv/sockets_priv.h"
#include <lwip/sockets.h>
#if !LWIP_COMPAT_SOCKETS
#if LWIP_SOCKET
#define CHECK_NULL_PTR(ptr) do { if ((ptr) == NULL) { set_errno(EFAULT); return -1; } } while (0)
@@ -159,6 +161,27 @@ int inet_pton(int af, const char *src, void *dst)
return lwip_inet_pton(af, src, dst);
}
#ifndef LWIP_INET_ADDR_FUNC
in_addr_t inet_addr(const char *cp)
{
return ipaddr_addr(cp);
}
#endif
#ifndef LWIP_INET_NTOA_FUNC
char *inet_ntoa(struct in_addr addr)
{
return ip4addr_ntoa((const ip4_addr_t*)&(addr));
}
#endif
#ifndef LWIP_INET_ATON_FUNC
int inet_aton(const char *cp, struct in_addr *addr)
{
return ip4addr_aton(cp, (ip4_addr_t*)addr);
}
#endif
int ioctlsocket(int s, long cmd, void *argp)
{
return lwip_ioctl(s, cmd, argp);
@@ -178,4 +201,87 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout)
}
#endif
#endif /* !LWIP_COMPAT_SOCKETS */
unsigned int if_nametoindex(const char *ifname)
{
return lwip_if_nametoindex(ifname);
}
#endif
#endif /* !LWIP_COMPAT_SOCKETS */
#define IOCTL_CMD_CASE_HANDLER() do { \
err_t err; \
struct lwip_ioctl_apimsg msg; \
msg.sock = sock; \
msg.cmd = cmd; \
msg.argp = argp; \
\
err = tcpip_api_call(lwip_do_ioctl_impl, &msg.call); \
if (err != ENOSYS) { \
sock_set_errno(sock, err); \
done_socket(sock); \
return -(err != ERR_OK); \
} \
} while (0)
struct lwip_ioctl_apimsg {
struct tcpip_api_call_data call;
struct lwip_sock *sock;
long cmd;
void *argp;
};
static err_t lwip_do_ioctl_impl(struct tcpip_api_call_data *call);
#include "../api/sockets.c"
static u8_t lwip_ioctl_internal_SIOCGIFBRDADDR(struct ifreq *ifr)
{
struct netif *netif = NULL;
struct sockaddr_in *sock_in = NULL;
/* get netif subnet broadcast addr */
netif = netif_find(ifr->ifr_name);
if (netif == NULL) {
return ENODEV;
}
if (ip4_addr_isany_val(*(ip_2_ip4(&netif->netmask)))) {
return ENXIO;
}
sock_in = (struct sockaddr_in *)&ifr->ifr_addr;
sock_in->sin_family = AF_INET;
sock_in->sin_addr.s_addr = (ip_2_ip4(&((netif)->ip_addr))->addr | ~(ip_2_ip4(&netif->netmask)->addr));
return 0;
}
static u8_t lwip_ioctl_impl(const struct lwip_sock *sock, long cmd, void *argp)
{
u8_t err = 0;
struct ifreq *ifr = (struct ifreq *)argp;
bool is_ipv6 = 0;
/* allow it only on IPv6 sockets... */
is_ipv6 = NETCONNTYPE_ISIPV6((unsigned int)(sock->conn->type));
switch ((u32_t)cmd) {
case SIOCGIFBRDADDR:
if (is_ipv6 != 0) {
err = EINVAL;
} else {
err = lwip_ioctl_internal_SIOCGIFBRDADDR(ifr);
}
break;
default:
err = ENOSYS;
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(UNIMPL: 0x%lx)\n", cmd));
break;
}
return err;
}
static err_t lwip_do_ioctl_impl(struct tcpip_api_call_data *call)
{
struct lwip_ioctl_apimsg *msg = (struct lwip_ioctl_apimsg *)(void *)call;
return lwip_ioctl_impl(msg->sock, msg->cmd, msg->argp);
}

16
components/net/lwip-2.1/porting/src/sys_arch.c Executable file → Normal file
View File

@@ -38,7 +38,7 @@
#include <los_sem.h>
#include <los_mux.h>
#include "cmsis_os2.h"
#include <los_timer.h>
#include <los_tick.h>
#include <los_config.h>
#ifndef LOSCFG_KERNEL_SMP
@@ -82,8 +82,7 @@ sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg,
void sys_init(void)
{
/* set rand seed to make random sequence diff on every startup */
UINT32 seedhsb, seedlsb;
HalGetCpuCycle(&seedhsb, &seedlsb);
UINT32 seedlsb = (UINT32)LOS_SysCycleGet();
srand(seedlsb);
}
@@ -181,7 +180,10 @@ err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
return ERR_ARG;
}
err_t sys_mbox_trypost_fromisr(sys_mbox_t *mbox, void *msg);
err_t sys_mbox_trypost_fromisr(sys_mbox_t *mbox, void *msg)
{
return ERR_ARG;
}
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeoutMs)
{
@@ -322,7 +324,7 @@ void sys_mutex_set_invalid(sys_mutex_t *mutex)
*mutex = LOSCFG_BASE_IPC_MUX_LIMIT;
}
void HilogPrintf(const char *fmt, ...)
void LwipLogPrintf(const char *fmt, ...)
{
if ((fmt == NULL) || (strlen(fmt) == 0)) {
return;
@@ -335,8 +337,8 @@ void HilogPrintf(const char *fmt, ...)
len = vsprintf_s(buf, sizeof(buf) - 1, fmt, ap);
va_end(ap);
if (len < 0) {
HILOG_INFO(HILOG_MODULE_APP, "log param invalid or buf is not enough.");
LWIP_LOGGER("log param invalid or buf is not enough.");
return;
}
HILOG_INFO(HILOG_MODULE_APP, buf);
LWIP_LOGGER(buf);
}

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