Compare commits

..

86 Commits

Author SHA1 Message Date
openharmony_ci
fe69c9dd65 !1043 Fix : pthread_cond_timedwait 函数等待的信号丢失问题
Merge pull request !1043 from yinjiaming/fix
2023-03-31 09:11:33 +00:00
yinjiaming
2374c01bb9 fix:pthread_cond_timedwait解锁后清理的问题
该函数解锁mutex 后先清理事件,导致等的事件丢失

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: I36f8658b1b850734bc029b486fec103f6bd10588
2023-03-31 16:14:31 +08:00
openharmony_ci
66278102ca !1035 使用vprintf来打印va_list类型
Merge pull request !1035 from 乔克叔叔/master
2023-03-22 02:40:55 +00:00
liuwenxin
ecdd47f0c5 fix:使用vprintf来打印va_list类型
Signed-off-by: liuwenxin <liuwenxin11@huawei.com>
2023-03-21 11:14:02 +08:00
openharmony_ci
7dbae99194 !1038 增加los错误码和posix错误码对接接口
Merge pull request !1038 from wangchen/0317_m
2023-03-17 13:02:35 +00:00
root
81784f1c6b fix: 增加los错误码和posix错误码对接接口
方案描述:
1, 增加一个内部接口, 用于los接口返回的错误码转换成posix错误码

BREAKING CHANGE:
无新增接口, 原有接口pthread_create错误时的错误码进行了区分

Close #I6NWNV
Signed-off-by: wangchen <wangchen240@huawei.com>
2023-03-17 16:23:31 +08:00
openharmony_ci
5fa299b4aa !1026 修复task命令打印逻辑问题
Merge pull request !1026 from wangchen/0216_m
2023-03-14 07:54:35 +00:00
root
b02c64dc42 fix: posix用例存在mutex资源泄露
方案描述:
1, 对posix中使用锁之后,增加对锁的释放
2, 修改锁后进入shell, 发现task打印线程信息有异常, 又修复了打印相关的逻辑
fix #I64Y7G
Signed-off-by: wangchen <wangchen240@huawei.com>
2023-03-13 21:53:57 +08:00
openharmony_ci
c5a39437f7 !1007 fix: risc-v架构编译告警修复
Merge pull request !1007 from zhushengle/codex
2023-03-08 06:02:16 +00:00
zhushengle
f211029b12 fix: 修复编译告警
Close #I69TZD

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I5f837b7980b478a02524f8ba056916ca038c544c
2023-03-07 21:37:07 +08:00
openharmony_ci
36d55955ef !1031 newlib error处理
Merge pull request !1031 from 乔克叔叔/master
2023-03-01 08:13:50 +00:00
openharmony_ci
12f6c5d628 !1032 Fix : 配置LOSCFG_BASE_IPC_QUEUE_STATIC后编译错误
Merge pull request !1032 from yinjiaming/fix-1
2023-03-01 08:09:53 +00:00
openharmony_ci
17309e232a !1029 Fix : 打开 LWIP_IPV6 时会有编译错误
Merge pull request !1029 from yinjiaming/fix
2023-03-01 08:09:16 +00:00
liuwenxin
af1afcec6a fix:newlib error解决
close:#I6HL01

Signed-off-by: liuwenxin <liuwenxin11@huawei.com>
2023-03-01 11:52:34 +08:00
yinjiaming
9cef4da850 fix:配置LOSCFG_BASE_IPC_QUEUE_STATIC后编译错误
在target_config.h中配置了LOSCFG_BASE_IPC_QUEUE_STATIC之后编译内核测试套报错
现修复

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: Idf99137f822d5040bdb19e489e0a9234f19e93be
2023-02-27 15:12:13 +08:00
yinjiaming
d058b640e2 fix:打开LWIP_IPV6时有编译错误
更改了出错的参与算数运算的指针的数据类型

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: I6891797cd1afa801faeecf1bfb891f0ac7db7f68
2023-02-27 11:53:54 +08:00
openharmony_ci
4431b587f8 !1027 Panic支持ExcHook
Merge pull request !1027 from zhangdengyu/supportPanicHook
2023-02-22 06:18:48 +00:00
zhangdengyu
809db71acc feat:Panic支持ExcHook
方案描述:
1、在EXC_TYPE枚举中添加EXC_PANIC成员用于Panic支持ExcHook
2、在LOS_Panic接口执行异常处理钩子函数

BREAKING CHANGE:
无

Close: #I6GR6G

Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com>
Change-Id: I99d293622ff6ddbc49348c692512e5b7780460e6
2023-02-21 21:55:01 +08:00
openharmony_ci
b1a7711e15 !1025 Werror开启产生的告警
Merge pull request !1025 from 乔克叔叔/werrror
2023-02-21 06:58:16 +00:00
liuwenxin
3e83ce79c2 fix:告警清理包含三方库屏蔽
【修改说明】此次开启Werror,解决告警产生的报错,以及屏蔽三方库告警

 close #I6ELI9
Signed-off-by: liuwenxin <liuwenxin11@huawei.com>
2023-02-21 10:35:56 +08:00
openharmony_ci
2cadd65301 !1023 fix: pthread_create时序调整
Merge pull request !1023 from Zhaotianyu/20230210pthread_create
2023-02-10 10:31:43 +00:00
arvinzzz
f038492dbc fix: pthread_create内部逻辑时序调整
在线程创建成功后,pthread_create内部先将函数返回值设置好,再进行TaskResume就绪调度状态

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I795c115da612123b67f34cdc57e85eac955bbc08
2023-02-10 17:42:17 +08:00
openharmony_ci
e74deedba3 !1005 Werror开启告警清理
Merge pull request !1005 from 乔克叔叔/second
2023-02-07 03:08:26 +00:00
openharmony_ci
24f52e0259 !987 LMS特性安全合规整改
Merge pull request !987 from JerryH/lms
2023-02-02 01:42:12 +00:00
huangjieliang
d4df4d1e54 feat:LMS模块及堆内存模块非安全函数安全合规整改
Close #I68LEO

Signed-off-by: huangjieliang <huangjieliang@huawei.com>
Change-Id: I38b859dcd1856f27d4577f5311c920d2d8b96385
2023-02-01 16:49:44 +08:00
openharmony_ci
2d1e7e8c29 !1012 Fix : 内核告警清理
Merge pull request !1012 from yinjiaming/warning
2023-02-01 06:33:49 +00:00
liuwenxin
a96f535cd3 fix:Werror开启告警清理
清理Werror开启产生的告警

close:#I68YDW

Signed-off-by: liuwenxin <liuwenxin11@huawei.com>
2023-01-30 10:10:07 +08:00
openharmony_ci
1669455ba9 !972 feat:新增文件系统测试用例
Merge pull request !972 from zhangdengyu/addFsTestCase
2023-01-29 08:54:33 +00:00
zhangdengyu
b637b1d979 test:添加文件系统测试用例
方案描述:
1、对单个接口进行规格测试。
2、对多个接口组合测试模拟上层业务场景。
3、对各接口进行压力测试确保稳定性。

Close: #I62K4B

Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com>
Change-Id: I6c45631094884e0300faa994082d16dda6dd3f1d
2023-01-29 16:22:07 +08:00
openharmony_ci
c6d021bede !1016 refactor: 不同C库malloc归一
Merge pull request !1016 from Zhaotianyu/20230117libc_malloc
2023-01-18 09:56:58 +00:00
arvinzzz
d7f3aef326 refactor: 不同C库的malloc适配归一
1. 不同C库的malloc实现归一化,由原先//kal/libc/musl、//kal/libc/newlib、
   //../../third_party/musl/porting/liteos_m_iccarm/kernel 各自实现,
   统一至//kal/posix/src/malloc.c实现,并实现对三种C库的兼容

2. Kconfig归一化的配套调整,删除Top->"Compat"->"Choose libc implementation"下
   malloc API的开关控制,统一归入"Top"->"Compat"->"Enable POSIX API"下
   "Enable POSIX MALLOC API"进行能力开关控制

BREAKING CHANGE:
Kconfig变更:
删除:
LOSCFG_LIBC_ICCARM_MALLOC
LOSCFG_LIBC_NEWLIB_MALLOC
新增:
LOSCFG_POSIX_MALLOC_API

close: I6AGOW

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I584e337cdb36184cf40c36c4f7c73ab780c31a42
2023-01-18 11:22:01 +08:00
yinjiaming
db32ad90bf Fix:内核告警清理
清除内核代码中的敏感词

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: I734525c036fcfe481d0781d459bc273ef8224791
2023-01-16 16:17:09 +08:00
openharmony_ci
59fbe91d8b !1009 Fix : OsLs 内存泄漏问题
Merge pull request !1009 from yinjiaming/fix
2023-01-13 08:54:49 +00:00
openharmony_ci
c7088f4d0f !1010 告警清理
Merge pull request !1010 from 乔克叔叔/release
2023-01-13 05:42:29 +00:00
liuwenxin
705bfbdc76 fix:release告警清理
release分支告警清理

close:#I6AD15

Signed-off-by: liuwenxin <liuwenxin11@huawei.com>
2023-01-13 11:34:52 +08:00
yinjiaming
9a4e9677bd fix:修复OsLs函数内存泄漏问题
当d = NULL时,path没有释放,现释放path所指向的内存

close #I6A07U

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: Iee9fd8d2171c6fdcf353a48e7af385bbd1660520
2023-01-12 15:30:19 +08:00
openharmony_ci
6134d4bd22 !989 修复-Werror编译选项产生的告警
Merge pull request !989 from 乔克叔叔/lwx
2023-01-11 07:55:48 +00:00
openharmony_ci
c119b7e9e2 !1006 Fix : statfs函数内部判断错误
Merge pull request !1006 from yinjiaming/fix
2023-01-11 07:37:51 +00:00
openharmony_ci
dbf0498bab !1008 fix: 非gcc形态下FUNC_ALIAS编译错误
Merge pull request !1008 from Zhaotianyu/20230111symbol_fix
2023-01-11 06:49:43 +00:00
arvinzzz
68b142cf78 fix: 修复非gcc形态FUNC_ALIAS编译错误
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I7f199366d8173d9fc504f89b26329ea5f7d1eb9e
2023-01-11 10:45:18 +08:00
openharmony_ci
22b7eb87ca !998 fix: 不同C库下gettimeofday特性规格统一
Merge pull request !998 from Zhaotianyu/20230107gettimeofday
2023-01-11 00:46:21 +00:00
arvinzzz
ed50f7e373 fix: 不同libc下gettimeofday特性规格统一
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: Iaaf1fed24101f43c636737294dbe870d2f467b0a
2023-01-10 20:36:34 +08:00
yinjiaming
2f2a0b7a75 fix:修复statfs函数内部判断错误
修复函数调用的是statfs却用stat!=NULL来判断,当文件系统是little_fs时导致死机的问题。

close #I69BXB

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: Ib9784c017f4260433c3f12e352470108ea83ec19
2023-01-10 15:49:01 +08:00
openharmony_ci
1ae62ebf2e !1000 fix:mutex trace中ArchLRGet等接口改变实现方式
Merge pull request !1000 from zhangdengyu/mutexTraceFix
2023-01-10 06:44:48 +00:00
zhangdengyu
25278a02eb fix:mutex trace中ArchLRGet接口改变实现方式
方案描述:
将ArchLRGet接口的实现方式由内联函数修改为宏,
防止产品添加--no_inline等编译选项导致函数无法在调用点展开,
造成由于函数调用过程中函数栈帧的变化带来的LR寄存器中存储的值的变化。

Close #I69D9N

Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com>
Change-Id: If417bc2ec9febf064c63da198faf4ac000d70c52
2023-01-10 14:28:15 +08:00
liuwenxin
52bc16c3db fix:修复-Werror编译选项产生的告警
清理框架定义未使用告警,宏重定义,以及变量定义未使用等告警。

Close #I68RLA

Signed-off-by: liuwenxin <liuwenxin11@huawei.com>
2023-01-10 10:26:22 +08:00
openharmony_ci
733b6e6c6c !988 fix: mktime测试用例不依赖固定时区
Merge pull request !988 from Zhaotianyu/20230104fix_mktime_test
2023-01-04 09:36:32 +00:00
arvinzzz
6562536db7 fix: mktime testcase
Eliminate the effects of different time zones

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I22f0dc7057df642e255bec9a8b663c2b544b107e
2023-01-04 16:39:01 +08:00
openharmony_ci
ddf3dc8237 !985 fix: mktime测试用例配套修改
Merge pull request !985 from Zhaotianyu/20230103fix_mktime_test
2023-01-03 07:45:12 +00:00
arvinzzz
399e7647bb fix: mktime testcase
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I50e0252aa8611e9a269b836c552bfdf33ade8f44
2023-01-03 11:27:26 +08:00
openharmony_ci
f7af2cdf9b !983 修复codecheck告警
Merge pull request !983 from 夏不白/codecheck
2022-12-30 06:19:55 +00:00
xiacong
07091c5a75 fix:修复codecheck告警
1、修复空格、空行使用错误告警;
2、将超过10行的inline函数去除内联符号

fix #I685E3

Signed-off-by: xiacong <xiacong4@huawei.com>
2022-12-30 12:11:01 +08:00
openharmony_ci
6633aabf89 !979 fix: mktime获取的时间缺少时区信息
Merge pull request !979 from Zhaotianyu/20221228mktime_fix
2022-12-29 10:21:38 +00:00
arvinzzz
2a4282f912 fix: The tm struct obtained by mktime lacks timezone information
BREAKING CHANGE:
The tm struct obtained by mktime lacks timezone information
变更API:
time_t mktime(struct tm *tmptr)
原先mktime从入参中获取时区信息进行计算,变更后tm结构体和返回值time_t的计算使用系统g_timezone时区环境变量。

Close I67UIA

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I766cffbff3c1a25bb33cbd245225ee117909af3a
2022-12-29 16:26:08 +08:00
openharmony_ci
685688b21c !977 Fixed compilation problems with niobe407 and neptune100
Merge pull request !977 from 张亚雷/master
2022-12-27 07:21:39 +00:00
mrzhang
67ee38e1e3 fix: Fixed compilation problems with niobe407 and neptune100
Signed-off-by: mrzhang <zhangyalei8@h-partners.com>
2022-12-26 18:25:44 -08:00
openharmony_ci
6cd48f6f90 !965 VfsMpFind接口优化
Merge pull request !965 from Far/vfsmpfind
2022-12-24 03:12:29 +00:00
Far
662aefb700 fix: VfsMpFind optimize
1. provide VfsMpFind which doesn't support mounting recursively;
2. provide a macro to set whether supporting recursive-mount or not.
3. adding path length checking

BREAKING CHANGE:
new config option:
LOSCFG_FS_SUPPORT_MOUNT_TARGET_RECURSIVE

fix #I65XE6
Signed-off-by: Far <yesiyuan2@huawei.com>
Change-Id: I7ae371f0e6fff46db0e2368f905aa22bac864b79
2022-12-24 10:44:11 +08:00
openharmony_ci
83fc93cc84 !974 fix: misc_config中defines未初始化导致编译失败
Merge pull request !974 from Zhaotianyu/20221222misc_config
2022-12-22 07:44:57 +00:00
arvinzzz
b817c490ba fix: 修复misc_config中defines未初始化的错误
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I4eecfc1af2b0cdc39922a8ce299eb8ab6b7c6e8c
2022-12-22 11:28:31 +08:00
openharmony_ci
705e4c323a !973 【重新提交】修复文件系统中不合理的锁操作
Merge pull request !973 from Far/master
2022-12-22 03:10:43 +00:00
Far
b7f906ef8a fix: 修复文件系统不合理的锁操作
1. 移除了fatfs和littlefs中冗余的加锁操作。
2. 增加了配置选项FS_LOCK_TIMEOUT(宏LOSCFG_FS_LOCK_TIMEOUT),提供配置
   文件系统获取锁超时能力。
3. 新增对外接口LOS_FsLock()和LOS_FsUnlock()接口,提供HAL层与文件系统的
   互斥操作。

BREAKING CHANGE:
修复文件系统不合理的锁操作
新增API:
los_fs.h:
int LOS_FsLock(void)
int LOS_FsUnlock(void)
新增配置项:
LOSCFG_FS_LOCK_TIMEOUT(menuconfig FS_LOCK_TIMEOUT)

fix #I66S2J

Signed-off-by: Far <yesiyuan2@huawei.com>
Change-Id: I2ae9b6b5e2c788b2f4a00d9678a0240d00c335eb
2022-12-22 10:41:31 +08:00
openharmony_ci
f9c59d361f !971 回退 'Pull Request !938 : 修复文件系统不合理的锁操作'
Merge pull request !971 from openharmony_ci/revert-merge-938-master
2022-12-19 09:34:33 +00:00
openharmony_ci
fa142daffb 回退 'Pull Request !938 : 修复文件系统不合理的锁操作' 2022-12-19 08:57:11 +00:00
openharmony_ci
4bd0e73512 !969 open接口内存泄漏修复
Merge pull request !969 from wangchen/1217_m
2022-12-17 08:47:28 +00:00
wangchen
0a03a4d875 fix: open接口内存泄漏修复
方案描述:
1, 修改路径正确时打开失败可能的异常

fix #I66KGT
Signed-off-by: wangchen <wangchen240@huawei.com>
2022-12-17 08:16:12 +00:00
openharmony_ci
2a70466456 !963 修复文件系统close中的不合理操作
Merge pull request !963 from Far/NFILE
2022-12-16 03:12:42 +00:00
openharmony_ci
b30349d8ed !938 修复文件系统不合理的锁操作
Merge pull request !938 from Far/master
2022-12-16 03:03:54 +00:00
Far
59ecf4cae8 fix: 修复close接口中无法正常关闭文件的问题
1. close未考虑保留描述符0、1和2,导致fd合法性判断出现错误,这会导致
上限附近的fd不能被正常的关闭
2. 释放file结构体时未在锁的保护中进行,可能存在问题

fix #I65U8S

Signed-off-by: Far <yesiyuan2@huawei.com>
Change-Id: Iaa03a70e18fcb352ca3b99232f50b43d8b13ecf0
2022-12-16 10:53:03 +08:00
Far
9038b6522e fix: 修复文件系统不合理的锁操作
1. 移除了fatfs和littlefs中冗余的加锁操作。
2. 增加了配置选项FS_LOCK_TIMEOUT(宏LOSCFG_FS_LOCK_TIMEOUT),提供文件
   系统锁超时判定能力。
3. 新增对外接口LOS_FsLock()和LOS_FsUnlock()接口,提供HAL层与文件系统的
   互斥操作。

BREAKING CHANGE:
修复文件系统不合理的锁操作
新增API:
int LOS_FsLock(void)
int LOS_FsUnlock(void)
新增配置项:
LOSCFG_FS_LOCK_TIMEOUT(menuconfig FS_LOCK_TIMEOUT)

fix #I6355A

Signed-off-by: Far <yesiyuan2@huawei.com>
Change-Id: Ia980abfac0ee761088313496c7e3c3e9568450b3
2022-12-16 10:42:03 +08:00
openharmony_ci
abb83fd23b !962 refactor: vfs优化
Merge pull request !962 from Zhaotianyu/20221210vfs_opt
2022-12-16 02:03:04 +00:00
arvinzzz
98da8bbdfb refactor: vfs opt
1. vfs重构优化,统一fs模块的对外接口,减少不必要的冗余调用,由fs组件直接提供posix对外接口
  2. vfs与libc关系整理
  3. fs接口实现规范化

BREAKING CHANGE:
删除API:
int LOS_Open(const char *path, int flags, ...);
int LOS_Close(int fd);
ssize_t LOS_Read(int fd, void *buff, size_t bytes);
ssize_t LOS_Write(int fd, const void *buff, size_t bytes);
off_t LOS_Lseek(int fd, off_t off, int whence);
int LOS_Stat(const char *path, struct stat *stat);
int LOS_Statfs(const char *path, struct statfs *buf);
int LOS_Unlink(const char *path);
int LOS_Rename(const char *oldpath, const char *newpath);
int LOS_Fsync(int fd);
DIR *LOS_Opendir(const char *path);
struct dirent *LOS_Readdir(DIR *dir);
int LOS_Closedir(DIR *dir);
int LOS_Mkdir(const char *path, mode_t mode);
int LOS_Rmdir(const char *path);
int LOS_Lstat(const char *path, struct stat *buffer);
int LOS_Fstat(int fd, struct stat *buf);
int LOS_Fcntl(int fd, int cmd, ...);
int LOS_Ioctl(int fd, int req, ...);
ssize_t LOS_Readv(int fd, const struct iovec *iovBuf, int iovcnt);
ssize_t LOS_Writev(int fd, const struct iovec *iovBuf, int iovcnt);
ssize_t LOS_Pread(int fd, void *buff, size_t bytes, off_t off);
ssize_t LOS_Pwrite(int fd, const void *buff, size_t bytes, off_t off);
int LOS_Isatty(int fd);
int LOS_Access(const char *path, int amode);
int LOS_Ftruncate(int fd, off_t length);
int LOS_FsUmount(const char *target);
int LOS_FsUmount2(const char *target, int flag);
int LOS_FsMount(const char *source, const char *target,
                const char *fsType, unsigned long mountflags,
                const void *data);
int OsFcntl(int fd, int cmd, va_list ap);
int OsIoctl(int fd, int req, va_list ap);

Close #I65MNQ

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I3d16852ffb87ab061c22b22f5873eba384842101
2022-12-13 16:56:18 +08:00
openharmony_ci
c7da881469 !934 fix: 对外提供CONFIG_NFILE_DESCRIPTORS宏表示最大可打开fd数量
Merge pull request !934 from Hongjin Li/fs1
2022-12-06 12:10:31 +00:00
openharmony_ci
9cbddd412d !955 feat: 优化CPUP计算方式, 解耦系统调频
Merge pull request !955 from zhushengle/cpup
2022-12-06 07:11:08 +00:00
openharmony_ci
b50b5e7cba !953 对内核模块暴露OsMemNodeHead/OsMemPoolHead等结构体
Merge pull request !953 from Far/los_memory
2022-12-06 04:08:13 +00:00
zhushengle
974182d50c feat: 优化CPUP计算方式, 解耦系统调频
Close #I5R9XG

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I07cb388732b1190943374802f792d32bd666c06e
2022-12-06 10:41:20 +08:00
Hongjin Li
a3ce436841 fix: 提供CONFIG_NFILE_DESCRIPTORS宏标识最大可打开fd数量
提供CONFIG_NFILE_DESCRIPTORS宏,标识最大可打开fd数量。
提供FAT_MAX_OPEN_FILES宏,标识FAT文件系统中最大可打开fd数量。

如果只有FAT文件系统,那么CONFIG_NFILE_DESCRIPTORS等于FAT_MAX_OPEN_FILES。
如果有多个文件系统,比如fat+little+yaffs,那么CONFIG_NFILE_DESCRIPTORS应该定义为多个文件系统可打开fd数量之和。

BREAKING CHANGE:

对外提供的CONFIG_NFILE_DESCRIPTORS宏,用来标识最大可打开fd数量。

开发者可以在target_config.h中自定义CONFIG_NFILE_DESCRIPTORS和FAT_MAX_OPEN_FILES宏。

Close #I62WDU

Signed-off-by: Hongjin Li <lihongjin1@huawei.com>
2022-12-06 10:11:13 +08:00
openharmony_ci
588abc0645 !952 fix: 修复低功耗下时间更新缺陷
Merge pull request !952 from zhushengle/pm_timer
2022-12-05 13:02:02 +00:00
zhushengle
7657aadc20 feat: 修复低功耗下时间更新缺陷
1.注释说明低功耗框架中tickLock和tickUnlock两个钩子函数的要求
2.解决极端情况下OsTickTimerBaseReset断言失败的问题

BREAKING CHANGE:
修复低功耗下时间更新缺陷对外变更描述:

低功耗启用另一个低功耗timer时:

LosPmTickTimer 中tickLock函数的功能实现描述由原来的:暂停系统tick timer 修改为:关闭系统tick timer,并将timer的count值清零

LosPmTickTimer 中tickUnlock函数的功能实现描述由原来的:恢复系统tick timer 修改为:重新启动系统tick timer

Close #I5O80Z

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I2ee17518e4a388ff5a1f9e3d8d7c61c81aa3e569
2022-12-05 17:01:37 +08:00
Far
0d1c77c1e0 feat: 对内核模块暴露OsMemNodeHead/OsMemPoolHead
对内核其他模块暴露OsMemNodeHead/OsMemPoolHead等结构体,
以便于对堆内存管理的调测及管理。

fix #I64ONE

Signed-off-by: Far <yesiyuan2@huawei.com>
Change-Id: I2e47d90412368dfdc8d82e6b30c9196e1fdf42f1
2022-12-05 16:41:20 +08:00
openharmony_ci
795c2db917 !933 fs增加注册接口
Merge pull request !933 from wangchen/1124_m
2022-12-01 06:18:16 +00:00
wangchen
2f334bed21 feat: fs增加注册接口
方案描述:
增加注册机制, 并增加重复注册判断

BREAKING CHANGE:
fs增加注册接口
新增API:
int LOS_FsRegister(const char *fsType, const struct MountOps *fsMops,
                   const struct FileOps *fsFops, const struct FsManagement *fsMgt);

fix #I611L2
Signed-off-by: wangchen <wangchen240@huawei.com>
https://gitee.com/openharmony/kernel_liteos_m/issues/I611L2
2022-12-01 02:50:05 +00:00
openharmony_ci
9e4978f57f !947 fix: 使用LOSCFG_FS_FREE_HOOK释放内存
Merge pull request !947 from Hongjin Li/max_open_dirs
2022-12-01 02:50:03 +00:00
Hongjin Li
a859329f28 fix: 使用LOSCFG_FS_FREE_HOOK释放内存
文件系统中使用LOSCFG_FS_FREE_HOOK代替free()来释放内存。

close #I6412J

Signed-off-by: Hongjin Li <lihongjin1@huawei.com>
2022-12-01 09:33:32 +08:00
openharmony_ci
68b8deea89 !937 添加MAX_OPEN_DIRS宏,标识最大可打开dir数量
Merge pull request !937 from Hongjin Li/max_open_dirs
2022-11-29 11:38:36 +00:00
Hongjin Li
a288718c2c fix: 添加LOSCFG_MAX_OPEN_DIRS标识最大可打开dir数量
提供LOSCFG_MAX_OPEN_DIRS宏定义,标识最大可打开dir数量。新增g_dirNum静态变量,标识已打开的dir数量。
在opendir成功时g_dirNum++,在closedir成功时g_dirNum--。

BREAKING CHANGE:
新增LOSCFG_MAX_OPEN_DIRS宏定义,标识最大可打开dir数量。

fix: I62XEA

Signed-off-by: Hongjin Li <lihongjin1@huawei.com>
2022-11-29 19:05:00 +08:00
134 changed files with 4680 additions and 2400 deletions

View File

@@ -91,8 +91,9 @@ config("dialect_config") {
}
config("misc_config") {
defines = []
if (!defined(LOSCFG_COMPILER_ICCARM)) {
defines = [ "__LITEOS__" ]
defines += [ "__LITEOS__" ]
defines += [ "__LITEOS_M__" ]
}
if (!defined(LOSCFG_DEBUG_VERSION)) {

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -63,12 +63,13 @@ STATIC INLINE UINTPTR ArchMspGet(VOID)
return msp;
}
STATIC INLINE UINTPTR ArchLRGet(VOID)
{
UINTPTR lr;
__asm("mov %0, lr" : "=r" (lr));
return lr;
}
#define ARCH_LR_GET() \
({ \
UINTPTR lr; \
__asm("mov %0, lr" : "=r" (lr)); \
(lr); \
})
#define ArchLRGet ARCH_LR_GET
#elif defined(__CLANG_ARM) || defined(__GNUC__)
STATIC INLINE UINTPTR ArchSpGet(VOID)
{
@@ -91,12 +92,13 @@ STATIC INLINE UINTPTR ArchMspGet(VOID)
return msp;
}
STATIC INLINE UINTPTR ArchLRGet(VOID)
{
UINTPTR lr;
__asm volatile("mov %0, lr" : "=r" (lr));
return lr;
}
#define ARCH_LR_GET() \
({ \
UINTPTR lr; \
__asm volatile("mov %0, lr" : "=r" (lr)); \
(lr); \
})
#define ArchLRGet ARCH_LR_GET
#else
/* Other platforms to be improved */
#endif

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2020, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -43,6 +43,10 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 0)
#error "LOSCFG_PLATFORM_HWI_WITH_ARG must be set to 1 !!!"
#endif
/**
* @ingroup los_arch_interrupt
* Define the type of a hardware interrupt vector table function.

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2020, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -167,6 +167,7 @@ LITE_OS_SEC_TEXT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
HWI_PROC_FUNC hwiHandler,
HwiIrqParam *irqParam)
{
(VOID)hwiMode;
UINT32 intSave;
if (hwiHandler == NULL) {
@@ -283,7 +284,7 @@ STATIC VOID ExcInfoDisplayContext(const LosExcInfo *exc)
ExcBackTrace(taskContext->s0);
}
STATIC VOID ExcInfoDisplay(const LosExcContext *excBufAddr)
STATIC VOID ExcInfoDisplay(VOID)
{
PRINTK("\nException Information \n");
@@ -305,6 +306,11 @@ STATIC VOID ExcInfoDisplay(const LosExcContext *excBufAddr)
WEAK UINT32 HalUnalignedAccessFix(UINTPTR mcause, UINTPTR mepc, UINTPTR mtval, VOID *sp)
{
(VOID)mcause;
(VOID)mepc;
(VOID)mtval;
(VOID)sp;
/* Unaligned access fixes are not supported by default */
PRINTK("Unaligned access fixes are not supported by default!\n");
return LOS_NOK;
@@ -329,7 +335,7 @@ VOID HalExcEntry(const LosExcContext *excBufAddr)
}
}
ExcInfoDisplay(excBufAddr);
ExcInfoDisplay();
if (LOS_TaskIsRunning()) {
PRINTK("----------------All Task information ------------\n");

View File

@@ -43,7 +43,7 @@
judgment condition to support multiple code sections. */
WEAK BOOL OsStackDataIsCodeAddr(UINTPTR value)
{
if ((value >= CODE_START_ADDR) && (value < CODE_END_ADDR)) {
if ((value > CODE_START_ADDR) && (value < CODE_END_ADDR)) {
return TRUE;
}
return FALSE;

View File

@@ -58,6 +58,9 @@
#define OS_CPUP_RECORD_PERIOD (g_sysClock)
#define OS_SYS_CYCLE_TO_US(cycle) ((cycle) / (g_sysClock)) * OS_SYS_US_PER_SECOND + \
((cycle) % (g_sysClock) * OS_SYS_US_PER_SECOND / (g_sysClock))
LITE_OS_SEC_BSS UINT16 g_cpupInitFlg = 0;
LITE_OS_SEC_BSS OsCpupCB *g_cpup = NULL;
LITE_OS_SEC_BSS UINT64 g_lastRecordTime;
@@ -167,6 +170,15 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsCpupInit()
return LOS_OK;
}
/* The calculation time unit is changed to us to decouple the influence of
* system frequency modulation on CPUP
*/
STATIC UINT64 CpupTimeUsGet(VOID)
{
UINT64 time = LOS_SysCycleGet();
return OS_SYS_CYCLE_TO_US(time);
}
/*****************************************************************************
Function : OsTskCycleStart
Description: start task to get cycles count in current task beginning
@@ -183,10 +195,11 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleStart(VOID)
taskID = g_losTask.newTask->taskID;
g_cpup[taskID].cpupID = taskID;
g_cpup[taskID].startTime = LOS_SysCycleGet();
g_cpup[taskID].startTime = CpupTimeUsGet();
return;
}
/*****************************************************************************
Function : OsTskCycleEnd
Description: quit task and get cycle count
@@ -196,7 +209,7 @@ Return : None
LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleEnd(VOID)
{
UINT32 taskID;
UINT64 cpuCycle;
UINT64 cpuTime;
if (g_cpupInitFlg == 0) {
return;
@@ -208,16 +221,17 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleEnd(VOID)
return;
}
cpuCycle = LOS_SysCycleGet();
if (cpuCycle < g_cpup[taskID].startTime) {
cpuCycle += g_cyclesPerTick;
cpuTime = CpupTimeUsGet();
if (cpuTime < g_cpup[taskID].startTime) {
cpuTime += OS_US_PER_TICK;
}
g_cpup[taskID].allTime += (cpuCycle - g_cpup[taskID].startTime);
g_cpup[taskID].allTime += (cpuTime - g_cpup[taskID].startTime);
g_cpup[taskID].startTime = 0;
return;
}
/*****************************************************************************
Function : OsTskCycleEndStart
Description: start task to get cycles count in current task ending
@@ -227,7 +241,7 @@ Return : None
LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleEndStart(VOID)
{
UINT32 taskID;
UINT64 cpuCycle;
UINT64 cpuTime;
UINT16 loopNum;
if (g_cpupInitFlg == 0) {
@@ -235,23 +249,23 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleEndStart(VOID)
}
taskID = g_losTask.runTask->taskID;
cpuCycle = LOS_SysCycleGet();
cpuTime = CpupTimeUsGet();
if (g_cpup[taskID].startTime != 0) {
if (cpuCycle < g_cpup[taskID].startTime) {
cpuCycle += g_cyclesPerTick;
if (cpuTime < g_cpup[taskID].startTime) {
cpuTime += OS_US_PER_TICK;
}
g_cpup[taskID].allTime += (cpuCycle - g_cpup[taskID].startTime);
g_cpup[taskID].allTime += (cpuTime - g_cpup[taskID].startTime);
g_cpup[taskID].startTime = 0;
}
taskID = g_losTask.newTask->taskID;
g_cpup[taskID].cpupID = taskID;
g_cpup[taskID].startTime = cpuCycle;
g_cpup[taskID].startTime = cpuTime;
if ((cpuCycle - g_lastRecordTime) > OS_CPUP_RECORD_PERIOD) {
g_lastRecordTime = cpuCycle;
if ((cpuTime - g_lastRecordTime) > OS_CPUP_RECORD_PERIOD) {
g_lastRecordTime = cpuTime;
for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
g_cpup[loopNum].historyTime[g_hisPos] = g_cpup[loopNum].allTime;
@@ -267,12 +281,12 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleEndStart(VOID)
return;
}
LITE_OS_SEC_TEXT_MINOR static inline UINT16 OsGetPrePos(UINT16 curPos)
LITE_OS_SEC_TEXT_MINOR STATIC INLINE UINT16 OsGetPrePos(UINT16 curPos)
{
return (curPos == 0) ? (OS_CPUP_HISTORY_RECORD_NUM - 1) : (curPos - 1);
}
LITE_OS_SEC_TEXT_MINOR static VOID OsGetPositions(UINT16 mode, UINT16* curPosAddr, UINT16* prePosAddr)
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsGetPositions(UINT16 mode, UINT16* curPosAddr, UINT16* prePosAddr)
{
UINT16 curPos;
UINT16 prePos = 0;
@@ -298,7 +312,7 @@ Return : cpupRet:current CPU usage
*****************************************************************************/
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_SysCpuUsage(VOID)
{
UINT64 cpuCycleAll = 0;
UINT64 cpuTimeAll = 0;
UINT32 cpupRet = 0;
UINT16 loopNum;
UINT32 intSave;
@@ -312,12 +326,12 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_SysCpuUsage(VOID)
OsTskCycleEnd();
for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
cpuCycleAll += g_cpup[loopNum].allTime;
cpuTimeAll += g_cpup[loopNum].allTime;
}
if (cpuCycleAll) {
if (cpuTimeAll) {
cpupRet = LOS_CPUP_PRECISION - (UINT32)((LOS_CPUP_PRECISION *
g_cpup[g_idleTaskID].allTime) / cpuCycleAll);
g_cpup[g_idleTaskID].allTime) / cpuTimeAll);
}
OsTskCycleStart();
@@ -334,7 +348,7 @@ Return : cpupRet:CPU usage history
*****************************************************************************/
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistorySysCpuUsage(UINT16 mode)
{
UINT64 cpuCycleAll = 0;
UINT64 cpuTimeAll = 0;
UINT64 idleCycleAll = 0;
UINT32 cpupRet = 0;
UINT16 loopNum;
@@ -354,9 +368,9 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistorySysCpuUsage(UINT16 mode)
for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
if (mode == CPUP_IN_1S) {
cpuCycleAll += g_cpup[loopNum].historyTime[curPos] - g_cpup[loopNum].historyTime[prePos];
cpuTimeAll += g_cpup[loopNum].historyTime[curPos] - g_cpup[loopNum].historyTime[prePos];
} else {
cpuCycleAll += g_cpup[loopNum].allTime - g_cpup[loopNum].historyTime[curPos];
cpuTimeAll += g_cpup[loopNum].allTime - g_cpup[loopNum].historyTime[curPos];
}
}
@@ -367,8 +381,8 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistorySysCpuUsage(UINT16 mode)
idleCycleAll += g_cpup[g_idleTaskID].allTime - g_cpup[g_idleTaskID].historyTime[curPos];
}
if (cpuCycleAll) {
cpupRet = (LOS_CPUP_PRECISION - (UINT32)((LOS_CPUP_PRECISION * idleCycleAll) / cpuCycleAll));
if (cpuTimeAll) {
cpupRet = (LOS_CPUP_PRECISION - (UINT32)((LOS_CPUP_PRECISION * idleCycleAll) / cpuTimeAll));
}
OsTskCycleStart();
@@ -385,7 +399,7 @@ Return : cpupRet:CPU usage of certain task
*****************************************************************************/
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuUsage(UINT32 taskID)
{
UINT64 cpuCycleAll = 0;
UINT64 cpuTimeAll = 0;
UINT16 loopNum;
UINT32 intSave;
UINT32 cpupRet = 0;
@@ -410,11 +424,11 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuUsage(UINT32 taskID)
if ((g_cpup[loopNum].status & OS_TASK_STATUS_UNUSED) || (g_cpup[loopNum].status == 0)) {
continue;
}
cpuCycleAll += g_cpup[loopNum].allTime;
cpuTimeAll += g_cpup[loopNum].allTime;
}
if (cpuCycleAll) {
cpupRet = (UINT32)((LOS_CPUP_PRECISION * g_cpup[taskID].allTime) / cpuCycleAll);
if (cpuTimeAll) {
cpupRet = (UINT32)((LOS_CPUP_PRECISION * g_cpup[taskID].allTime) / cpuTimeAll);
}
OsTskCycleStart();
@@ -432,8 +446,8 @@ Return : cpupRet:CPU usage history of task
*****************************************************************************/
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistoryTaskCpuUsage(UINT32 taskID, UINT16 mode)
{
UINT64 cpuCycleAll = 0;
UINT64 cpuCycleCurTsk = 0;
UINT64 cpuTimeAll = 0;
UINT64 cpuTimeCurTsk = 0;
UINT16 loopNum, curPos;
UINT16 prePos = 0;
UINT32 intSave;
@@ -463,19 +477,19 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistoryTaskCpuUsage(UINT32 taskID, UINT16 mode
}
if (mode == CPUP_IN_1S) {
cpuCycleAll += g_cpup[loopNum].historyTime[curPos] - g_cpup[loopNum].historyTime[prePos];
cpuTimeAll += g_cpup[loopNum].historyTime[curPos] - g_cpup[loopNum].historyTime[prePos];
} else {
cpuCycleAll += g_cpup[loopNum].allTime - g_cpup[loopNum].historyTime[curPos];
cpuTimeAll += g_cpup[loopNum].allTime - g_cpup[loopNum].historyTime[curPos];
}
}
if (mode == CPUP_IN_1S) {
cpuCycleCurTsk += g_cpup[taskID].historyTime[curPos] - g_cpup[taskID].historyTime[prePos];
cpuTimeCurTsk += g_cpup[taskID].historyTime[curPos] - g_cpup[taskID].historyTime[prePos];
} else {
cpuCycleCurTsk += g_cpup[taskID].allTime - g_cpup[taskID].historyTime[curPos];
cpuTimeCurTsk += g_cpup[taskID].allTime - g_cpup[taskID].historyTime[curPos];
}
if (cpuCycleAll) {
cpupRet = (UINT32)((LOS_CPUP_PRECISION * cpuCycleCurTsk) / cpuCycleAll);
if (cpuTimeAll) {
cpupRet = (UINT32)((LOS_CPUP_PRECISION * cpuTimeCurTsk) / cpuTimeAll);
}
OsTskCycleStart();
@@ -490,8 +504,8 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_AllTaskCpuUsage(CPUP_INFO_S *cpupInfo, UINT16
UINT16 curPos;
UINT16 prePos = 0;
UINT32 intSave;
UINT64 cpuCycleAll = 0;
UINT64 cpuCycleCurTsk = 0;
UINT64 cpuTimeAll = 0;
UINT64 cpuTimeCurTsk = 0;
if (g_cpupInitFlg == 0) {
return LOS_ERRNO_CPUP_NO_INIT;
@@ -513,9 +527,9 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_AllTaskCpuUsage(CPUP_INFO_S *cpupInfo, UINT16
}
if (mode == CPUP_IN_1S) {
cpuCycleAll += g_cpup[loopNum].historyTime[curPos] - g_cpup[loopNum].historyTime[prePos];
cpuTimeAll += g_cpup[loopNum].historyTime[curPos] - g_cpup[loopNum].historyTime[prePos];
} else {
cpuCycleAll += g_cpup[loopNum].allTime - g_cpup[loopNum].historyTime[curPos];
cpuTimeAll += g_cpup[loopNum].allTime - g_cpup[loopNum].historyTime[curPos];
}
}
@@ -526,16 +540,16 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_AllTaskCpuUsage(CPUP_INFO_S *cpupInfo, UINT16
}
if (mode == CPUP_IN_1S) {
cpuCycleCurTsk += g_cpup[loopNum].historyTime[curPos] - g_cpup[loopNum].historyTime[prePos];
cpuTimeCurTsk += g_cpup[loopNum].historyTime[curPos] - g_cpup[loopNum].historyTime[prePos];
} else {
cpuCycleCurTsk += g_cpup[loopNum].allTime - g_cpup[loopNum].historyTime[curPos];
cpuTimeCurTsk += g_cpup[loopNum].allTime - g_cpup[loopNum].historyTime[curPos];
}
cpupInfo[loopNum].usStatus = g_cpup[loopNum].status;
if (cpuCycleAll) {
cpupInfo[loopNum].uwUsage = (UINT32)((LOS_CPUP_PRECISION * cpuCycleCurTsk) / cpuCycleAll);
if (cpuTimeAll) {
cpupInfo[loopNum].uwUsage = (UINT32)((LOS_CPUP_PRECISION * cpuTimeCurTsk) / cpuTimeAll);
}
cpuCycleCurTsk = 0;
cpuTimeCurTsk = 0;
}
OsTskCycleStart();
@@ -606,13 +620,13 @@ LITE_OS_SEC_TEXT_MINOR VOID OsCpupIrqStart(UINT32 intNum)
return;
}
g_irqCpup[intNum].startTime = LOS_SysCycleGet();
g_irqCpup[intNum].startTime = CpupTimeUsGet();
return;
}
LITE_OS_SEC_TEXT_MINOR VOID OsCpupIrqEnd(UINT32 intNum)
{
UINT64 cpuCycle;
UINT64 cpuTime;
UINT64 usedTime;
if (g_irqCpupInitFlg == 0) {
@@ -623,14 +637,14 @@ LITE_OS_SEC_TEXT_MINOR VOID OsCpupIrqEnd(UINT32 intNum)
return;
}
cpuCycle = LOS_SysCycleGet();
if (cpuCycle < g_irqCpup[intNum].startTime) {
cpuCycle += g_cyclesPerTick;
cpuTime = CpupTimeUsGet();
if (cpuTime < g_irqCpup[intNum].startTime) {
cpuTime += OS_US_PER_TICK;
}
g_irqCpup[intNum].cpupID = intNum;
g_irqCpup[intNum].status = OS_CPUP_USED;
usedTime = cpuCycle - g_irqCpup[intNum].startTime;
usedTime = cpuTime - g_irqCpup[intNum].startTime;
if (g_irqCpup[intNum].count <= 1000) { /* 1000, Take 1000 samples */
g_irqCpup[intNum].allTime += usedTime;
@@ -672,12 +686,12 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsGetIrqPositions(UINT16 mode, UINT16* curPos
LITE_OS_SEC_TEXT_MINOR STATIC UINT64 OsGetIrqAllTime(VOID)
{
INT32 i;
UINT64 cpuCycleAll = 0;
UINT64 cpuTimeAll = 0;
for (i = 0; i < OS_CPUP_HISTORY_RECORD_NUM; i++) {
cpuCycleAll += g_cpuHistoryTime[i];
cpuTimeAll += g_cpuHistoryTime[i];
}
return cpuCycleAll;
return cpuTimeAll;
}
LITE_OS_SEC_TEXT_MINOR STATIC UINT64 OsGetIrqAllHisTime(UINT32 num)
@@ -697,8 +711,8 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_GetAllIrqCpuUsage(UINT16 mode, CPUP_INFO_S *cp
UINT16 curPos;
UINT16 prePos = 0;
UINT32 intSave;
UINT64 cpuCycleAll;
UINT64 cpuCycleCurIrq;
UINT64 cpuTimeAll;
UINT64 cpuTimeCurIrq;
if (g_irqCpupInitFlg == 0) {
return LOS_ERRNO_CPUP_NO_INIT;
@@ -712,9 +726,9 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_GetAllIrqCpuUsage(UINT16 mode, CPUP_INFO_S *cp
OsGetIrqPositions(mode, &curPos, &prePos);
if (mode == CPUP_IN_10S) {
cpuCycleAll = OsGetIrqAllTime();
cpuTimeAll = OsGetIrqAllTime();
} else {
cpuCycleAll = g_cpuHistoryTime[curPos] - g_cpuHistoryTime[prePos];
cpuTimeAll = g_cpuHistoryTime[curPos] - g_cpuHistoryTime[prePos];
}
for (loopNum = 0; loopNum < LOSCFG_PLATFORM_HWI_LIMIT; loopNum++) {
@@ -725,13 +739,13 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_GetAllIrqCpuUsage(UINT16 mode, CPUP_INFO_S *cp
cpupInfo[loopNum].usStatus = g_irqCpup[loopNum].status;
if (mode == CPUP_IN_10S) {
cpuCycleCurIrq = OsGetIrqAllHisTime(loopNum);
cpuTimeCurIrq = OsGetIrqAllHisTime(loopNum);
} else {
cpuCycleCurIrq = g_irqCpup[loopNum].historyTime[curPos] - g_irqCpup[loopNum].historyTime[prePos];
cpuTimeCurIrq = g_irqCpup[loopNum].historyTime[curPos] - g_irqCpup[loopNum].historyTime[prePos];
}
if (cpuCycleAll != 0) {
cpupInfo[loopNum].uwUsage = (UINT32)((LOS_CPUP_PRECISION * cpuCycleCurIrq) / cpuCycleAll);
if (cpuTimeAll != 0) {
cpupInfo[loopNum].uwUsage = (UINT32)((LOS_CPUP_PRECISION * cpuTimeCurIrq) / cpuTimeAll);
}
}

View File

@@ -32,7 +32,6 @@ config FS_FAT
default n
depends on FS_VFS
select SUPPORT_FATFS
select KAL_CMSIS
help
Answer Y to enable LiteOS support fat filesystem.

View File

@@ -60,7 +60,6 @@
#endif /* FS_LOCK_TIMEOUT_SEC */
static UINT8 g_workBuffer[FF_MAX_SS];
static pthread_mutex_t g_fatfsMutex = PTHREAD_MUTEX_INITIALIZER;
static char *g_volPath[FF_VOLUMES] = {FF_VOLUME_STRS};
PARTITION VolToPart[] = {
@@ -70,31 +69,6 @@ PARTITION VolToPart[] = {
{ 0, 0, 4, 0, 0 }
};
static int FsLock(void)
{
int ret = 0;
struct timespec absTimeout = {0};
if (!OsCheckKernelRunning()) {
return ret;
}
ret = clock_gettime(CLOCK_REALTIME, &absTimeout);
if (ret != 0) {
PRINT_ERR("clock gettime err 0x%x!\r\n", errno);
return errno;
}
absTimeout.tv_sec += FS_LOCK_TIMEOUT_SEC;
ret = pthread_mutex_timedlock(&g_fatfsMutex, &absTimeout);
return ret;
}
static void FsUnlock(void)
{
if (!OsCheckKernelRunning()) {
return;
}
(void)pthread_mutex_unlock(&g_fatfsMutex);
}
static int FsChangeDrive(const char *path)
{
INT32 res;
@@ -275,95 +249,69 @@ int FatfsMount(struct MountPoint *mp, unsigned long mountflags,
{
FRESULT res;
FATFS *fs = NULL;
int ret;
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
if (mountflags & MS_REMOUNT) {
ret = Remount(mp, mountflags);
FsUnlock();
return ret;
return Remount(mp, mountflags);
}
char *ldPath = GetLdPath(mp->mDev);
if (ldPath == NULL) {
errno = EFAULT;
ret = (int)LOS_NOK;
goto ERROUT;
return (int)LOS_NOK;
}
fs = (FATFS *)LOSCFG_FS_MALLOC_HOOK(sizeof(FATFS));
if (fs == NULL) {
errno = ENOMEM;
ret = (int)LOS_NOK;
goto ERROUT;
PutLdPath(ldPath);
return (int)LOS_NOK;
}
(void)memset_s(fs, sizeof(FATFS), 0, sizeof(FATFS));
res = f_mount(fs, ldPath, 1);
if (res != FR_OK) {
LOSCFG_FS_FREE_HOOK(fs);
PutLdPath(ldPath);
errno = FatfsErrno(res);
return (int)LOS_NOK;
}
mp->mData = (void *)fs;
res = f_mount((FATFS *)mp->mData, ldPath, 1);
if (res != FR_OK) {
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto ERROUT;
}
PutLdPath(ldPath);
FsUnlock();
return (int)LOS_OK;
ERROUT:
LOSCFG_FS_FREE_HOOK(fs);
mp->mData = NULL;
PutLdPath(ldPath);
FsUnlock();
return ret;
}
int FatfsUmount(struct MountPoint *mp)
{
int ret;
int volId;
FRESULT res;
char *ldPath = NULL;
FATFS *fatfs = (FATFS *)mp->mData;
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
char *ldPath = GetLdPath(mp->mDev);
if (ldPath == NULL) {
errno = EFAULT;
ret = (int)LOS_NOK;
goto OUT;
}
/* The volume is not mounted */
if (fatfs->fs_type == 0) {
errno = EINVAL;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
volId = GetPartIdByPartName(mp->mDev);
/* umount is not allowed when a file or directory is opened. */
if (f_checkopenlock(volId) != FR_OK) {
errno = EBUSY;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ldPath = GetLdPath(mp->mDev);
if (ldPath == NULL) {
errno = EFAULT;
return (int)LOS_NOK;
}
res = f_mount((FATFS *)NULL, ldPath, 0);
if (res != FR_OK) {
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
PutLdPath(ldPath);
return (int)LOS_NOK;
}
if (fatfs->win != NULL) {
@@ -373,19 +321,15 @@ int FatfsUmount(struct MountPoint *mp)
LOSCFG_FS_FREE_HOOK(mp->mData);
mp->mData = NULL;
ret = (int)LOS_OK;
OUT:
PutLdPath(ldPath);
FsUnlock();
return ret;
return (int)LOS_OK;
}
int FatfsUmount2(struct MountPoint *mp, int flag)
{
int ret;
UINT32 flags;
FRESULT res;
char *ldPath = NULL;
FATFS *fatfs = (FATFS *)mp->mData;
flags = MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW;
@@ -394,31 +338,23 @@ int FatfsUmount2(struct MountPoint *mp, int flag)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
char *ldPath = GetLdPath(mp->mDev);
if (ldPath == NULL) {
errno = EFAULT;
ret = (int)LOS_NOK;
goto OUT;
}
/* The volume is not mounted */
if (fatfs->fs_type == 0) {
errno = EINVAL;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ldPath = GetLdPath(mp->mDev);
if (ldPath == NULL) {
errno = EFAULT;
return (int)LOS_NOK;
}
res = f_mount((FATFS *)NULL, ldPath, 0);
if (res != FR_OK) {
PutLdPath(ldPath);
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
if (fatfs->win != NULL) {
@@ -428,12 +364,8 @@ int FatfsUmount2(struct MountPoint *mp, int flag)
LOSCFG_FS_FREE_HOOK(mp->mData);
mp->mData = NULL;
ret = (int)LOS_OK;
OUT:
PutLdPath(ldPath);
FsUnlock();
return ret;
return (int)LOS_OK;
}
int FatfsOpen(struct File *file, const char *path, int oflag)
@@ -456,20 +388,12 @@ int FatfsOpen(struct File *file, const char *path, int oflag)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
LOSCFG_FS_FREE_HOOK(fp);
return (int)LOS_NOK;
}
ret = FsChangeDrive(path);
if (ret != (int)LOS_OK) {
PRINT_ERR("FAT open ChangeDrive err 0x%x!\r\n", ret);
errno = ENOENT;
ret = (int)LOS_NOK;
LOSCFG_FS_FREE_HOOK(fp);
goto OUT;
return (int)LOS_NOK;
}
res = f_open(fp, path, fmode);
@@ -477,31 +401,20 @@ int FatfsOpen(struct File *file, const char *path, int oflag)
PRINT_ERR("FAT open err 0x%x!\r\n", res);
LOSCFG_FS_FREE_HOOK(fp);
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
file->fData = (void *)fp;
OUT:
FsUnlock();
return ret;
return (int)LOS_OK;
}
int FatfsClose(struct File *file)
{
FRESULT res;
FIL *fp = (FIL *)file->fData;
int ret;
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
if ((fp == NULL) || (fp->obj.fs == NULL)) {
FsUnlock();
errno = ENOENT;
return (int)LOS_NOK;
}
@@ -509,7 +422,6 @@ int FatfsClose(struct File *file)
res = f_close(fp);
if (res != FR_OK) {
PRINT_ERR("FAT close err 0x%x!\r\n", res);
FsUnlock();
errno = FatfsErrno(res);
return (int)LOS_NOK;
}
@@ -521,7 +433,6 @@ int FatfsClose(struct File *file)
#endif
LOSCFG_FS_FREE_HOOK(file->fData);
file->fData = NULL;
FsUnlock();
return (int)LOS_OK;
}
@@ -531,31 +442,22 @@ ssize_t FatfsRead(struct File *file, char *buf, size_t nbyte)
FRESULT res;
UINT32 lenRead;
FIL *fp = (FIL *)file->fData;
int ret;
if (buf == NULL) {
errno = EFAULT;
return (ssize_t)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (ssize_t)LOS_NOK;
}
if (fp == NULL) {
FsUnlock();
errno = ENOENT;
return (ssize_t)LOS_NOK;
}
res = f_read(fp, buf, nbyte, &lenRead);
if (res != FR_OK) {
FsUnlock();
errno = FatfsErrno(res);
return (ssize_t)LOS_NOK;
}
FsUnlock();
return (ssize_t)lenRead;
}
@@ -566,22 +468,15 @@ ssize_t FatfsWrite(struct File *file, const char *buf, size_t nbyte)
UINT32 lenWrite;
static BOOL overFlow = FALSE;
FIL *fp = (FIL *)file->fData;
int ret;
if (buf == NULL) {
errno = EFAULT;
return (ssize_t)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (ssize_t)LOS_NOK;
}
if ((fp ==NULL) || (fp->obj.fs == NULL)) {
if ((fp == NULL) || (fp->obj.fs == NULL)) {
errno = ENOENT;
goto ERROUT;
return (ssize_t)LOS_NOK;
}
res = f_write(fp, buf, nbyte, &lenWrite);
@@ -592,15 +487,10 @@ ssize_t FatfsWrite(struct File *file, const char *buf, size_t nbyte)
if ((res != FR_OK) || (nbyte != lenWrite)) {
errno = FatfsErrno(res);
goto ERROUT;
return (ssize_t)LOS_NOK;
}
FsUnlock();
return (ssize_t)lenWrite;
ERROUT:
FsUnlock();
return (ssize_t)LOS_NOK;
}
off_t FatfsLseek(struct File *file, off_t offset, int whence)
@@ -608,17 +498,10 @@ off_t FatfsLseek(struct File *file, off_t offset, int whence)
FRESULT res;
off_t pos;
FIL *fp = (FIL *)file->fData;
int ret;
ret = FsLock();
if (ret != 0) {
errno = ret;
return (off_t)LOS_NOK;
}
if ((fp == NULL) || (fp->obj.fs == NULL)) {
errno = ENOENT;
goto ERROUT;
return (off_t)LOS_NOK;
}
if (whence == SEEK_SET) {
@@ -629,22 +512,17 @@ off_t FatfsLseek(struct File *file, off_t offset, int whence)
pos = f_size(fp);
} else {
errno = EINVAL;
goto ERROUT;
return (off_t)LOS_NOK;
}
res = f_lseek(fp, offset + pos);
if (res != FR_OK) {
errno = FatfsErrno(res);
goto ERROUT;
return (off_t)LOS_NOK;
}
pos = f_tell(fp);
FsUnlock();
return pos;
ERROUT:
FsUnlock();
return (off_t)LOS_NOK;
}
/* Remove the specified FILE */
@@ -658,39 +536,26 @@ int FatfsUnlink(struct MountPoint *mp, const char *path)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
if (!mp->mWriteEnable) {
errno = EACCES;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = FsChangeDrive(path);
if (ret != (int)LOS_OK) {
PRINT_ERR("FAT unlink ChangeDrive err 0x%x!\r\n", ret);
errno = ENOENT;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
res = f_unlink(path);
if (res != FR_OK) {
PRINT_ERR("FAT unlink err 0x%x!\r\n", res);
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = (int)LOS_OK;
OUT:
FsUnlock();
return ret;
return (int)LOS_OK;
}
int FatfsStat(struct MountPoint *mp, const char *path, struct stat *buf)
@@ -704,26 +569,18 @@ int FatfsStat(struct MountPoint *mp, const char *path, struct stat *buf)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
ret = FsChangeDrive(path);
if (ret != (int)LOS_OK) {
PRINT_ERR("FAT stat ChangeDrive err 0x%x!\r\n", ret);
errno = ENOENT;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
res = f_stat(path, &fileInfo);
if (res != FR_OK) {
PRINT_ERR("FAT stat err 0x%x!\r\n", res);
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
buf->st_size = fileInfo.fsize;
@@ -740,43 +597,27 @@ int FatfsStat(struct MountPoint *mp, const char *path, struct stat *buf)
buf->st_mode |= S_IFDIR;
}
ret = (int)LOS_OK;
OUT:
FsUnlock();
return ret;
return (int)LOS_OK;
}
/* Synchronize all changes to Flash */
int FatfsSync(struct File *file)
{
int ret;
FRESULT res;
FIL *fp = (FIL *)file->fData;
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
if ((fp == NULL) || (fp->obj.fs == NULL)) {
errno = ENOENT;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
res = f_sync(fp);
if (res != FR_OK) {
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = (int)LOS_OK;
OUT:
FsUnlock();
return ret;
return (int)LOS_OK;
}
int FatfsMkdir(struct MountPoint *mp, const char *path)
@@ -789,38 +630,26 @@ int FatfsMkdir(struct MountPoint *mp, const char *path)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
if (!mp->mWriteEnable) {
errno = EACCES;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = FsChangeDrive(path);
if (ret != (int)LOS_OK) {
PRINT_ERR("FAT mkdir ChangeDrive err 0x%x!\r\n", ret);
errno = ENOENT;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
res = f_mkdir(path);
if (res != FR_OK) {
PRINT_ERR("FAT mkdir err 0x%x!\r\n", res);
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = (int)LOS_OK;
OUT:
FsUnlock();
return ret;
return (int)LOS_OK;
}
int FatfsOpendir(struct Dir *dir, const char *dirName)
@@ -831,47 +660,34 @@ int FatfsOpendir(struct Dir *dir, const char *dirName)
if (dirName == NULL) {
errno = EFAULT;
goto ERROUT;
}
dp = (DIR *)LOSCFG_FS_MALLOC_HOOK(sizeof(DIR));
if (dp == NULL) {
errno = ENOENT;
goto ERROUT;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
goto ERROUT;
return (int)LOS_NOK;
}
ret = FsChangeDrive(dirName);
if (ret != (int)LOS_OK) {
PRINT_ERR("FAT opendir ChangeDrive err 0x%x!\r\n", ret);
errno = ENOENT;
goto ERROUT;
return (int)LOS_NOK;
}
dp = (DIR *)LOSCFG_FS_MALLOC_HOOK(sizeof(DIR));
if (dp == NULL) {
errno = ENOENT;
return (int)LOS_NOK;
}
res = f_opendir(dp, dirName);
if (res != FR_OK) {
PRINT_ERR("FAT opendir err 0x%x!\r\n", res);
LOSCFG_FS_FREE_HOOK(dp);
errno = FatfsErrno(res);
goto ERROUT;
return (int)LOS_NOK;
}
dir->dData = dp;
dir->dOffset = 0;
FsUnlock();
return (int)LOS_OK;
ERROUT:
if (dp != NULL) {
LOSCFG_FS_FREE_HOOK(dp);
}
FsUnlock();
return (int)LOS_NOK;
}
int FatfsReaddir(struct Dir *dir, struct dirent *dent)
@@ -879,7 +695,6 @@ int FatfsReaddir(struct Dir *dir, struct dirent *dent)
FRESULT res;
FILINFO fileInfo = {0};
DIR *dp = NULL;
int ret;
if ((dir == NULL) || (dir->dData == NULL)) {
errno = EBADF;
@@ -887,18 +702,11 @@ int FatfsReaddir(struct Dir *dir, struct dirent *dent)
}
dp = (DIR *)dir->dData;
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
res = f_readdir(dp, &fileInfo);
/* if res not ok or fname is NULL , return NULL */
if ((res != FR_OK) || (fileInfo.fname[0] == 0x0)) {
PRINT_ERR("FAT readdir err 0x%x!\r\n", res);
errno = FatfsErrno(res);
FsUnlock();
return (int)LOS_NOK;
}
@@ -909,7 +717,6 @@ int FatfsReaddir(struct Dir *dir, struct dirent *dent)
} else {
dent->d_type = DT_REG;
}
FsUnlock();
return (int)LOS_OK;
}
@@ -918,7 +725,6 @@ int FatfsClosedir(struct Dir *dir)
{
FRESULT res;
DIR *dp = NULL;
int ret;
if ((dir == NULL) || (dir->dData == NULL)) {
errno = EBADF;
@@ -926,23 +732,15 @@ int FatfsClosedir(struct Dir *dir)
}
dp = dir->dData;
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
res = f_closedir(dp);
if (res != FR_OK) {
PRINT_ERR("FAT closedir err 0x%x!\r\n", res);
FsUnlock();
errno = FatfsErrno(res);
return (int)LOS_NOK;
}
LOSCFG_FS_FREE_HOOK(dir->dData);
dir->dData = NULL;
FsUnlock();
return (int)LOS_OK;
}
@@ -957,38 +755,26 @@ int FatfsRmdir(struct MountPoint *mp, const char *path)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
if (!mp->mWriteEnable) {
errno = EACCES;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = FsChangeDrive(path);
if (ret != (int)LOS_OK) {
PRINT_ERR("FAT rmdir ChangeDrive err 0x%x!\r\n", ret);
errno = ENOENT;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
res = f_rmdir(path);
if (res != FR_OK) {
PRINT_ERR("FAT rmdir err 0x%x!\r\n", res);
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = (int)LOS_OK;
OUT:
FsUnlock();
return ret;
return (int)LOS_OK;
}
int FatfsRename(struct MountPoint *mp, const char *oldName, const char *newName)
@@ -1001,38 +787,26 @@ int FatfsRename(struct MountPoint *mp, const char *oldName, const char *newName)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
if (!mp->mWriteEnable) {
errno = EACCES;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = FsChangeDrive(oldName);
if (ret != (int)LOS_OK) {
PRINT_ERR("FAT f_getfree ChangeDrive err 0x%x!\r\n", ret);
errno = ENOENT;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
res = f_rename(oldName, newName);
if (res != FR_OK) {
PRINT_ERR("FAT frename err 0x%x!\r\n", res);
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = (int)LOS_OK;
OUT:
FsUnlock();
return ret;
return (int)LOS_OK;
}
int FatfsStatfs(const char *path, struct statfs *buf)
@@ -1047,26 +821,18 @@ int FatfsStatfs(const char *path, struct statfs *buf)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
ret = FsChangeDrive(path);
if (ret != FR_OK) {
PRINT_ERR("FAT f_getfree ChangeDrive err %d.", ret);
errno = FatfsErrno(FR_INVALID_PARAMETER);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
res = f_getfree(path, &freeClust, &fs);
if (res != FR_OK) {
PRINT_ERR("FAT f_getfree err 0x%x.", res);
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
buf->f_bfree = freeClust;
buf->f_bavail = freeClust;
@@ -1078,11 +844,7 @@ int FatfsStatfs(const char *path, struct statfs *buf)
buf->f_bsize = FF_MIN_SS * fs->csize;
#endif
ret = (int)LOS_OK;
OUT:
FsUnlock();
return ret;
return (int)LOS_OK;
}
static int DoTruncate(struct File *file, off_t length, UINT32 count)
@@ -1090,7 +852,6 @@ static int DoTruncate(struct File *file, off_t length, UINT32 count)
FRESULT res = FR_OK;
DWORD csz;
FIL *fp = (FIL *)file->fData;
int ret = (int)LOS_OK;
csz = (DWORD)(fp->obj.fs)->csize * SS(fp->obj.fs); /* Cluster size */
if (length > csz * count) {
@@ -1098,8 +859,7 @@ static int DoTruncate(struct File *file, off_t length, UINT32 count)
res = f_expand(fp, 0, (FSIZE_t)(length), FALLOC_FL_KEEP_SIZE);
#else
errno = ENOSYS;
ret = (int)LOS_NOK;
return ret;
return (int)LOS_NOK;
#endif
} else if (length < csz * count) {
res = f_truncate(fp, (FSIZE_t)length);
@@ -1107,14 +867,13 @@ static int DoTruncate(struct File *file, off_t length, UINT32 count)
if (res != FR_OK) {
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
return ret;
return (int)LOS_NOK;
}
fp->obj.objsize = length; /* Set file size to length */
fp->flag |= 0x40; /* Set modified flag */
return ret;
return (int)LOS_OK;
}
int FatfsTruncate(struct File *file, off_t length)
@@ -1123,49 +882,30 @@ int FatfsTruncate(struct File *file, off_t length)
UINT count;
DWORD fclust;
FIL *fp = (FIL *)file->fData;
int ret;
if ((length < 0) || (length > UINT_MAX)) {
errno = EINVAL;
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
if ((fp == NULL) || (fp->obj.fs == NULL)) {
errno = ENOENT;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
res = f_getclustinfo(fp, &fclust, &count);
if (res != FR_OK) {
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = DoTruncate(file, length, count);
if (ret != FR_OK) {
goto OUT;
}
ret = (int)LOS_OK;
OUT:
FsUnlock();
return ret;
return DoTruncate(file, length, count);
}
int FatfsFdisk(const char *dev, int *partTbl, int arrayNum)
{
int pdrv;
FRESULT res;
int ret;
if ((dev == NULL) || (partTbl == NULL)) {
errno = EFAULT;
@@ -1178,25 +918,13 @@ int FatfsFdisk(const char *dev, int *partTbl, int arrayNum)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
ret = (int)LOS_NOK;
goto OUT;
}
res = f_fdisk(pdrv, (DWORD const *)partTbl, g_workBuffer);
if (res != FR_OK) {
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = (int)LOS_OK;
OUT:
FsUnlock();
return ret;
return (int)LOS_OK;
}
int FatfsFormat(const char *partName, void *privData)
@@ -1205,7 +933,6 @@ int FatfsFormat(const char *partName, void *privData)
MKFS_PARM opt = {0};
int option = *(int *)privData;
char *dev = NULL; /* logical driver */
int ret;
if (partName == NULL) {
errno = EFAULT;
@@ -1218,29 +945,17 @@ int FatfsFormat(const char *partName, void *privData)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
PutLdPath(dev);
return (int)LOS_NOK;
}
opt.fmt = option;
opt.n_sect = 0; /* use default allocation unit size depends on the volume
size. */
res = f_mkfs(dev, &opt, g_workBuffer, FF_MAX_SS);
if (res != FR_OK) {
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
PutLdPath(dev);
return (int)LOS_NOK;
}
ret = (int)LOS_OK;
OUT:
PutLdPath(dev);
FsUnlock();
return ret;
return (int)LOS_OK;
}
static struct MountOps g_fatfsMnt = {

View File

@@ -41,8 +41,6 @@
#include "securec.h"
#include "los_fs.h"
static pthread_mutex_t g_fsLocalMutex = PTHREAD_MUTEX_INITIALIZER;
static struct PartitionCfg g_partitionCfg;
static struct DeviceDesc *g_lfsDevice = NULL;
@@ -378,7 +376,6 @@ int LfsReaddir(struct Dir *dir, struct dirent *dent)
ret = lfs_dir_read(lfs, dirInfo, &lfsInfo);
if (ret == TRUE) {
pthread_mutex_lock(&g_fsLocalMutex);
(void)strncpy_s(dent->d_name, sizeof(dent->d_name), lfsInfo.name, strlen(lfsInfo.name) + 1);
if (lfsInfo.type == LFS_TYPE_DIR) {
dent->d_type = DT_DIR;
@@ -387,7 +384,6 @@ int LfsReaddir(struct Dir *dir, struct dirent *dent)
}
dent->d_reclen = lfsInfo.size;
pthread_mutex_unlock(&g_fsLocalMutex);
return LOS_OK;
}
@@ -567,10 +563,7 @@ int LfsClose(struct File *file)
return (int)LOS_NOK;
}
pthread_mutex_lock(&g_fsLocalMutex);
ret = lfs_file_close((lfs_t *)mp->mData, lfsHandle);
pthread_mutex_unlock(&g_fsLocalMutex);
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = (int)LOS_NOK;

View File

@@ -30,6 +30,23 @@
config FS_VFS
bool "Enable FS VFS"
default y
select POSIX_FS_API
help
Answer Y to enable LiteOS support VFS.
if FS_VFS
config FS_LOCK_TIMEOUT
int "Filesystem global lock timeout value in tick. -1 for waiting forever"
default -1
help
The timeout value of getting filesystem lock in tick. -1 for waiting forever
config FS_SUPPORT_MOUNT_TARGET_RECURSIVE
bool "Mount target can be recursive"
default n
depends on FS_VFS
help
Answer Y to enable LiteOS support VFS mount recursively. For example, "/system/bin".
endif

View File

@@ -46,6 +46,7 @@
#include "sys/uio.h"
#include "unistd.h"
#include <stdarg.h>
#include "vfs_maps.h"
#ifdef __cplusplus
#if __cplusplus
@@ -61,41 +62,6 @@ extern "C" {
#define LOSCFG_FS_FREE_HOOK(ptr) LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, ptr)
#endif
int LOS_Open(const char *path, int flags, ...);
int LOS_Close(int fd);
ssize_t LOS_Read(int fd, void *buff, size_t bytes);
ssize_t LOS_Write(int fd, const void *buff, size_t bytes);
off_t LOS_Lseek(int fd, off_t off, int whence);
int LOS_Stat(const char *path, struct stat *stat);
int LOS_Statfs(const char *path, struct statfs *buf);
int LOS_Unlink(const char *path);
int LOS_Rename(const char *oldpath, const char *newpath);
int LOS_Fsync(int fd);
DIR *LOS_Opendir(const char *path);
struct dirent *LOS_Readdir(DIR *dir);
int LOS_Closedir(DIR *dir);
int LOS_Mkdir(const char *path, mode_t mode);
int LOS_Rmdir(const char *path);
int LOS_Lstat(const char *path, struct stat *buffer);
int LOS_Fstat(int fd, struct stat *buf);
int LOS_Fcntl(int fd, int cmd, ...);
int LOS_Ioctl(int fd, int req, ...);
ssize_t LOS_Readv(int fd, const struct iovec *iovBuf, int iovcnt);
ssize_t LOS_Writev(int fd, const struct iovec *iovBuf, int iovcnt);
ssize_t LOS_Pread(int fd, void *buff, size_t bytes, off_t off);
ssize_t LOS_Pwrite(int fd, const void *buff, size_t bytes, off_t off);
int LOS_Isatty(int fd);
int LOS_Access(const char *path, int amode);
int LOS_Ftruncate(int fd, off_t length);
int LOS_FsUmount(const char *target);
int LOS_FsUmount2(const char *target, int flag);
int LOS_FsMount(const char *source, const char *target,
const char *fsType, unsigned long mountflags,
const void *data);
int OsFcntl(int fd, int cmd, va_list ap);
int OsIoctl(int fd, int req, va_list ap);
struct PartitionCfg {
/* partition low-level read func */
int (*readFunc)(int partition, UINT32 *offset, void *buf, UINT32 size);
@@ -152,6 +118,39 @@ int LOS_DiskPartition(const char *dev, const char *fsType, int *lengthArray, int
*/
int LOS_PartitionFormat(const char *partName, char *fsType, void *data);
/*
* @brief new file system callbacks register.
* These callback functions are the adaptation layer implemented by the developer,
* used to interconnect the vfs with the new file system.
*
* LOS_FsRegister must be called after kernel initialization is complete.
*
* @param fsType file system type, don't register the same type fs more than once.
* @param fsMops mount operation of the fs.
* @param fsFops file operation of the fs.
* @param fsMgt management operation of the fs.
*
* @return Return LOS_OK if success.
* Return LOS_NOK if error.
* errno EINVAL: input errors, such as null pointers.
* errno ENOMEM: memory may malloc failed.
*
*/
int LOS_FsRegister(const char *fsType, const struct MountOps *fsMops,
const struct FileOps *fsFops, const struct FsManagement *fsMgt);
/*
* @brief Lock the whole filesystem to forbid filesystem access.
*
* @return Return LOS_NOK if error. Return LOS_OK if seccess.
*/
int LOS_FsLock(void);
/*
* @brief Unlock the whole filesystem to allow filesystem access.
*/
void LOS_FsUnlock(void);
#ifdef __cplusplus
#if __cplusplus
extern "C" {

View File

@@ -49,21 +49,17 @@
#ifdef LOSCFG_FS_FAT
#include "fatfs_conf.h"
#define __FAT_NFILE FAT_MAX_OPEN_FILES
#else
#define __FAT_NFILE 0
#endif
#ifdef LOSCFG_FS_LITTLEFS
#include "lfs_conf.h"
#define __LFS_NFILE LOSCFG_LFS_MAX_OPEN_FILES
#else
#define __LFS_NFILE 0
#endif
#define CONFIG_NFILE_DESCRIPTORS (__FAT_NFILE + __LFS_NFILE)
#ifndef CONFIG_NFILE_DESCRIPTORS
#define CONFIG_NFILE_DESCRIPTORS 256
#endif
#define NR_OPEN_DEFAULT CONFIG_NFILE_DESCRIPTORS
#define NR_OPEN_DEFAULT (CONFIG_NFILE_DESCRIPTORS - MIN_START_FD)
/* time configure */
@@ -88,4 +84,9 @@
#define MAX_DIRENT_NUM 14 // 14 means 4096 length buffer can store 14 dirent, see struct DIR
/* max number of open directories */
#ifndef LOSCFG_MAX_OPEN_DIRS
#define LOSCFG_MAX_OPEN_DIRS 10
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -41,31 +41,33 @@ struct FsMap *VfsFsMapGet(const char *fsType)
{
struct FsMap *curr = g_fsMap;
(void)VfsLock();
(void)LOS_FsLock();
while (curr != NULL) {
if ((curr->fsType != NULL) && (fsType != NULL) &&
(strcmp(curr->fsType, fsType) == 0)) {
(void)VfsUnlock();
LOS_FsUnlock();
return curr;
}
curr = curr->next;
}
VfsUnlock();
LOS_FsUnlock();
return NULL;
}
int OsFsRegister(const char *fsType, struct MountOps *fsMops,
struct FileOps *fsFops, struct FsManagement *fsMgt)
int OsFsRegister(const char *fsType, const struct MountOps *fsMops,
const struct FileOps *fsFops, const struct FsManagement *fsMgt)
{
size_t len;
if ((fsMops == NULL) || (fsFops == NULL)) {
VFS_ERRNO_SET(EINVAL);
return (int)LOS_NOK;
}
struct FsMap *newfs = (struct FsMap *)LOSCFG_FS_MALLOC_HOOK(sizeof(struct FsMap));
if (newfs == NULL) {
PRINT_ERR("Fs register malloc failed, fsType %s.\n", fsType);
VFS_ERRNO_SET(ENOMEM);
return (int)LOS_NOK;
}
(void)memset_s(newfs, sizeof(struct FsMap), 0, sizeof(struct FsMap));
@@ -74,6 +76,7 @@ int OsFsRegister(const char *fsType, struct MountOps *fsMops,
newfs->fsType = LOSCFG_FS_MALLOC_HOOK(len);
if (newfs->fsType == NULL) {
LOSCFG_FS_FREE_HOOK(newfs);
VFS_ERRNO_SET(ENOMEM);
return (int)LOS_NOK;
}
(void)strcpy_s((char *)newfs->fsType, len, fsType);
@@ -83,10 +86,22 @@ int OsFsRegister(const char *fsType, struct MountOps *fsMops,
newfs->fsMgt = fsMgt;
newfs->fsRefs = 0;
(void)VfsLock();
(void)LOS_FsLock();
newfs->next = g_fsMap;
g_fsMap = newfs;
VfsUnlock();
LOS_FsUnlock();
return LOS_OK;
}
int LOS_FsRegister(const char *fsType, const struct MountOps *fsMops,
const struct FileOps *fsFops, const struct FsManagement *fsMgt)
{
if (VfsFsMapGet(fsType) != NULL) {
PRINT_ERR("fsType has been registered or fsType error\n");
VFS_ERRNO_SET(EINVAL);
return (int)LOS_NOK;
}
return OsFsRegister(fsType, fsMops, fsFops, fsMgt);
}

View File

@@ -56,8 +56,8 @@ struct FsMap {
struct FsMap *next;
};
int OsFsRegister(const char *fsType, struct MountOps *fsMops,
struct FileOps *fsFops, struct FsManagement *fsMgt);
int OsFsRegister(const char *fsType, const struct MountOps *fsMops,
const struct FileOps *fsFops, const struct FsManagement *fsMgt);
struct FsMap *VfsFsMapGet(const char *fsType);
#ifdef __cplusplus

View File

@@ -33,6 +33,7 @@
#include "vfs_config.h"
#include "stdlib.h"
#include "string.h"
#include "limits.h"
#include "errno.h"
#include "securec.h"
#include "vfs_operations.h"
@@ -62,14 +63,13 @@ static void MpDeleteFromList(struct MountPoint *mp)
}
}
#if (LOSCFG_FS_SUPPORT_MOUNT_TARGET_RECURSIVE == 1)
struct MountPoint *VfsMpFind(const char *path, const char **pathInMp)
{
struct MountPoint *mp = g_mountPoints;
struct MountPoint *bestMp = NULL;
int bestMatches = 0;
if (path == NULL) {
return NULL;
}
if (pathInMp != NULL) {
*pathInMp = NULL;
}
@@ -121,29 +121,85 @@ struct MountPoint *VfsMpFind(const char *path, const char **pathInMp)
next:
mp = mp->mNext;
}
return bestMp;
}
#else
struct MountPoint *VfsMpFind(const char *path, const char **pathInMp)
{
struct MountPoint *mp = g_mountPoints;
const char *iPath = path;
const char *mPath = NULL;
const char *target = NULL;
STATIC struct MountPoint *VfsMountPointInit(const char *target, const char *fsType, unsigned long mountflags)
if (pathInMp != NULL) {
*pathInMp = NULL;
}
while (*iPath == '/') {
++iPath;
}
while ((mp != NULL) && (mp->mPath != NULL)) {
mPath = mp->mPath;
target = iPath;
while (*mPath == '/') {
++mPath;
}
while ((*mPath != '\0') && (*mPath != '/') &&
(*target != '\0') && (*target != '/')) {
if (*mPath != *target) {
break;
}
++mPath;
++target;
}
if (((*mPath == '\0') || (*mPath == '/')) &&
((*target == '\0') || (*target == '/'))) {
if (pathInMp != NULL) {
*pathInMp = path;
}
return mp;
}
mp = mp->mNext;
}
return NULL;
}
#endif
STATIC struct MountPoint *VfsMountPointInit(const char *source, const char *target,
const char *fsType, unsigned long mountflags)
{
struct MountPoint *mp = NULL;
const char *pathInMp = NULL;
struct FsMap *mFs = NULL;
size_t ssize = 0;
size_t tsize;
/* find mp by target, to see if it was mounted */
mp = VfsMpFind(target, &pathInMp);
if (mp != NULL && pathInMp != NULL) {
errno = EINVAL;
return NULL;
}
/* Find fsMap coresponding to the fsType */
mFs = VfsFsMapGet(fsType);
if ((mFs == NULL) || (mFs->fsMops == NULL) || (mFs->fsMops->mount == NULL)) {
errno = ENODEV;
return NULL;
}
mp = (struct MountPoint *)LOSCFG_FS_MALLOC_HOOK(sizeof(struct MountPoint));
if (source != NULL) {
ssize = strlen(source) + 1;
}
tsize = strlen(target) + 1;
mp = (struct MountPoint *)LOSCFG_FS_MALLOC_HOOK(sizeof(struct MountPoint) + ssize + tsize);
if (mp == NULL) {
errno = ENOMEM;
return NULL;
}
@@ -152,7 +208,20 @@ STATIC struct MountPoint *VfsMountPointInit(const char *target, const char *fsTy
mp->mRefs = 0;
mp->mWriteEnable = (mountflags & MS_RDONLY) ? FALSE : TRUE;
mp->mFs->fsRefs++;
mp->mNext = g_mountPoints;
if (source != NULL && strcpy_s((char *)mp + sizeof(struct MountPoint), ssize, source) != EOK) {
LOSCFG_FS_FREE_HOOK(mp);
errno = ENOMEM;
return NULL;
}
if (strcpy_s((char *)mp + sizeof(struct MountPoint) + ssize, tsize, target) != EOK) {
LOSCFG_FS_FREE_HOOK(mp);
errno = ENOMEM;
return NULL;
}
mp->mDev = source ? (char *)mp + sizeof(struct MountPoint) : NULL;
mp->mPath = (char *)mp + sizeof(struct MountPoint) + ssize;
return mp;
}
@@ -178,51 +247,47 @@ STATIC int VfsRemount(const char *source, const char *target,
return mp->mFs->fsMops->mount(mp, mountflags, data);
}
int LOS_FsMount(const char *source, const char *target,
STATIC int VfsMountPathCheck(const char *target)
{
/* target must begin with '/', for example /system, /data, etc. */
if ((target == NULL) || (target[0] != '/')) {
errno = EINVAL;
return (int)LOS_NOK;
}
if (strlen(target) >= PATH_MAX) {
errno = ENAMETOOLONG;
return (int)LOS_NOK;
}
return LOS_OK;
}
int mount(const char *source, const char *target,
const char *fsType, unsigned long mountflags,
const void *data)
{
size_t len;
int ret;
struct MountPoint *mp = NULL;
/* target must begin with '/', for example /system, /data, etc. */
if ((target == NULL) || (target[0] != '/')) {
if (VfsMountPathCheck(target) != LOS_OK) {
return (int)LOS_NOK;
}
(void)VfsLock();
(void)LOS_FsLock();
if (mountflags & MS_REMOUNT) {
ret = VfsRemount(source, target, fsType, mountflags, data);
VfsUnlock();
LOS_FsUnlock();
return ret;
}
mp = VfsMountPointInit(target, fsType, mountflags);
mp = VfsMountPointInit(source, target, fsType, mountflags);
if (mp == NULL) {
VfsUnlock();
LOS_FsUnlock();
return (int)LOS_NOK;
}
if (source != NULL) {
len = strlen(source) + 1;
mp->mDev = LOSCFG_FS_MALLOC_HOOK(len);
if (mp->mDev == NULL) {
LOSCFG_FS_FREE_HOOK(mp);
VfsUnlock();
return (int)LOS_NOK;
}
(void)strcpy_s((char *)mp->mDev, len, source);
}
len = strlen(target) + 1;
mp->mPath = LOSCFG_FS_MALLOC_HOOK(len);
if (mp->mPath == NULL) {
goto errout;
}
(void)strcpy_s((char *)mp->mPath, len, target);
ret = mp->mFs->fsMops->mount(mp, mountflags, data);
if (ret != 0) {
/* errno is set */
@@ -230,30 +295,28 @@ int LOS_FsMount(const char *source, const char *target,
goto errout;
}
mp->mNext = g_mountPoints;
g_mountPoints = mp;
VfsUnlock();
LOS_FsUnlock();
return LOS_OK;
errout:
LOSCFG_FS_FREE_HOOK((void *)mp->mPath);
LOSCFG_FS_FREE_HOOK((void *)mp->mDev);
LOSCFG_FS_FREE_HOOK(mp);
VfsUnlock();
LOS_FsUnlock();
return (int)LOS_NOK;
}
int LOS_FsUmount(const char *target)
int umount(const char *target)
{
struct MountPoint *mp = NULL;
const char *pathInMp = NULL;
int ret = (int)LOS_NOK;
(void)VfsLock();
if (target == NULL) {
(void)LOS_FsLock();
if (VfsMountPathCheck(target) != LOS_OK) {
goto errout;
}
mp = VfsMpFind(target, &pathInMp);
mp = VfsMpFind(target, NULL);
if ((mp == NULL) || (mp->mRefs != 0)) {
goto errout;
}
@@ -272,16 +335,14 @@ int LOS_FsUmount(const char *target)
/* delete mp from mount list */
MpDeleteFromList(mp);
mp->mFs->fsRefs--;
LOSCFG_FS_FREE_HOOK((void *)mp->mPath);
LOSCFG_FS_FREE_HOOK((void *)mp->mDev);
LOSCFG_FS_FREE_HOOK(mp);
VfsUnlock();
LOS_FsUnlock();
return LOS_OK;
errout:
PRINT_ERR("umount2 failed, target %s.\n", target);
VfsUnlock();
LOS_FsUnlock();
return (int)LOS_NOK;
}
@@ -300,18 +361,17 @@ static void CloseFdsInMp(const struct MountPoint *mp)
}
}
int LOS_FsUmount2(const char *target, int flag)
int umount2(const char *target, int flag)
{
struct MountPoint *mp = NULL;
const char *pathInMp = NULL;
int ret = (int)LOS_NOK;
(void)VfsLock();
if (target == NULL) {
(void)LOS_FsLock();
if (VfsMountPathCheck(target) != LOS_OK) {
goto errout;
}
mp = VfsMpFind(target, &pathInMp);
mp = VfsMpFind(target, NULL);
if ((mp == NULL) || (mp->mRefs != 0) ||
(mp->mFs == NULL) || (mp->mFs->fsMops == NULL) ||
(mp->mFs->fsMops->umount2 == NULL)) {
@@ -332,15 +392,13 @@ int LOS_FsUmount2(const char *target, int flag)
/* delete mp from mount list */
MpDeleteFromList(mp);
mp->mFs->fsRefs--;
LOSCFG_FS_FREE_HOOK((void *)mp->mPath);
LOSCFG_FS_FREE_HOOK((void *)mp->mDev);
LOSCFG_FS_FREE_HOOK(mp);
VfsUnlock();
LOS_FsUnlock();
return LOS_OK;
errout:
PRINT_ERR("umount2 failed, target %s.\n", target);
VfsUnlock();
LOS_FsUnlock();
return (int)LOS_NOK;
}

View File

@@ -52,8 +52,6 @@ extern "C" {
extern UINT32 g_fsMutex;
int OsVfsInit(void);
int VfsLock(void);
void VfsUnlock(void);
#ifdef __cplusplus
#if __cplusplus

View File

@@ -93,20 +93,25 @@ EXIT:
STATIC LmsMemListNode *OsLmsGetPoolNodeFromAddr(UINTPTR addr)
{
LmsMemListNode *current = NULL;
LmsMemListNode *previous = NULL;
LOS_DL_LIST *listHead = &g_lmsCheckPoolList;
if (LOS_ListEmpty(&g_lmsCheckPoolList)) {
goto EXIT;
return NULL;
}
LOS_DL_LIST_FOR_EACH_ENTRY(current, listHead, LmsMemListNode, node) {
if ((addr >= current->poolAddr) && (addr < current->poolAddr + current->poolSize)) {
return current;
if ((addr < current->poolAddr) || (addr >= (current->poolAddr + current->poolSize))) {
continue;
}
if ((previous == NULL) ||
((previous->poolAddr <= current->poolAddr) &&
((current->poolAddr + current->poolSize) <= (previous->poolAddr + previous->poolSize)))) {
previous = current;
}
}
EXIT:
return NULL;
return previous;
}
STATIC LmsMemListNode *OsLmsCheckPoolCreate(VOID)
@@ -136,18 +141,12 @@ UINT32 LOS_LmsCheckPoolAdd(const VOID *pool, UINT32 size)
LMS_LOCK(intSave);
lmsPoolNode = OsLmsGetPoolNodeFromAddr((UINTPTR)pool);
if (lmsPoolNode != NULL) { /* if pool range already on checklist */
if (lmsPoolNode->poolAddr != (UINTPTR)pool) { /* pool is a subset of lmsPoolNode->poolAddr */
/* do not add it again, just return */
PRINT_DEBUG("[LMS]pool %p already on lms checklist !\n", pool);
LMS_UNLOCK(intSave);
return size; /* return size indicate the shadow memory init successful */
} else { /* Re-initialize the same pool, maybe with different size */
/* delete the old node, then add a new one */
lmsPoolNode->used = LMS_POOL_UNUSED;
LOS_ListDelete(&(lmsPoolNode->node));
}
lmsPoolNode = OsLmsGetPoolNode(pool);
if (lmsPoolNode != NULL) { /* if pool already on checklist */
/* Re-initialize the same pool, maybe with different size */
/* delete the old node, then add a new one */
lmsPoolNode->used = LMS_POOL_UNUSED;
LOS_ListDelete(&(lmsPoolNode->node));
}
lmsPoolNode = OsLmsCheckPoolCreate();
@@ -163,7 +162,7 @@ UINT32 LOS_LmsCheckPoolAdd(const VOID *pool, UINT32 size)
lmsPoolNode->shadowStart = (UINTPTR)poolAddr + realSize;
lmsPoolNode->shadowSize = poolAddr + size - lmsPoolNode->shadowStart;
/* init shadow value */
(VOID)memset((VOID *)lmsPoolNode->shadowStart, LMS_SHADOW_AFTERFREE_U8, lmsPoolNode->shadowSize);
(VOID)memset_s((VOID *)lmsPoolNode->shadowStart, lmsPoolNode->shadowSize, LMS_SHADOW_AFTERFREE_U8, lmsPoolNode->shadowSize);
LOS_ListAdd(&g_lmsCheckPoolList, &(lmsPoolNode->node));
@@ -193,10 +192,11 @@ RELEASE:
VOID OsLmsInit(VOID)
{
(VOID)memset(g_lmsCheckPoolArray, 0, sizeof(g_lmsCheckPoolArray));
(VOID)memset_s(g_lmsCheckPoolArray, sizeof(g_lmsCheckPoolArray), 0, sizeof(g_lmsCheckPoolArray));
LOS_ListInit(&g_lmsCheckPoolList);
static LmsHook hook = {
.init = LOS_LmsCheckPoolAdd,
.deInit = LOS_LmsCheckPoolDel,
.mallocMark = OsLmsLosMallocMark,
.freeMark = OsLmsLosFreeMark,
.simpleMark = OsLmsSimpleMark,
@@ -609,7 +609,7 @@ VOID OsLmsReportError(UINTPTR p, UINT32 size, UINT32 errMod)
LMS_LOCK(intSave);
g_checkDepth += 1;
(VOID)memset(&info, 0, sizeof(LmsAddrInfo));
(VOID)memset_s(&info, sizeof(LmsAddrInfo), 0, sizeof(LmsAddrInfo));
PRINT_ERR("***** Kernel Address Sanitizer Error Detected Start *****\n");

View File

@@ -95,6 +95,7 @@ typedef struct {
typedef struct {
UINT32 (*init)(const VOID *pool, UINT32 size);
VOID (*deInit)(const VOID *pool);
VOID (*mallocMark)(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
VOID (*freeMark)(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
VOID (*simpleMark)(UINTPTR startAddr, UINTPTR endAddr, UINT32 value);
@@ -133,4 +134,4 @@ extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_handle_no_return(VOID);
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_LMS_PRI_H */
#endif /* _LOS_LMS_PRI_H */

View File

@@ -125,7 +125,7 @@ int ip6addr_aton(const char *cp, ip6_addr_t *addr)
int squash_pos = ipv6_blocks;
int i;
const unsigned char *sc = (const unsigned char *)cp;
const char *ss = cp-1;
const unsigned char *ss = (const unsigned char *)(cp - 1);
for (; ; sc++) {
if (current_block_index >= ipv6_blocks) {
@@ -142,7 +142,7 @@ int ip6addr_aton(const char *cp, ip6_addr_t *addr)
break;
} else if (*sc == ':') {
if (sc - ss == 1) {
if (sc != cp || sc[1] != ':') {
if (sc != (const unsigned char *)cp || sc[1] != ':') {
return 0; // address begins with a single ':' or contains ":::"
} // else address begins with one valid "::"
} else {
@@ -163,7 +163,7 @@ int ip6addr_aton(const char *cp, ip6_addr_t *addr)
#if LWIP_IPV4
} else if (*sc == '.' && current_block_index < ipv6_blocks - 1) {
ip4_addr_t ip4;
int ret = ip4addr_aton(ss+1, &ip4);
int ret = ip4addr_aton((const char *)(ss + 1), &ip4);
if (!ret) {
return 0;
}

View File

@@ -101,21 +101,27 @@ STATIC VOID OsPmTickTimerStart(LosPmCB *pm)
}
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
if ((tickTimer->timerStop != NULL) && (pm->enterSleepTime != 0)) {
/* Restore the main CPU frequency */
sleepTime = tickTimer->timerCycleGet();
tickTimer->timerStop();
if (tickTimer->timerStop != NULL) {
if (pm->enterSleepTime != 0) {
/* Restore the main CPU frequency */
sleepTime = tickTimer->timerCycleGet();
tickTimer->timerStop();
realSleepTime = OS_SYS_CYCLE_TO_NS(sleepTime, tickTimer->freq);
realSleepTime = OS_SYS_NS_TO_CYCLE(realSleepTime, g_sysClock);
currTime = pm->enterSleepTime + realSleepTime;
pm->enterSleepTime = 0;
realSleepTime = OS_SYS_CYCLE_TO_NS(sleepTime, tickTimer->freq);
realSleepTime = OS_SYS_NS_TO_CYCLE(realSleepTime, g_sysClock);
currTime = pm->enterSleepTime + realSleepTime;
pm->enterSleepTime = 0;
OsTickTimerBaseReset(currTime);
OsSchedResetSchedResponseTime(0);
OsTickTimerBaseReset(currTime);
OsSchedResetSchedResponseTime(0);
/* Restart the system tick timer */
tickTimer->tickUnlock();
}
return;
}
#endif
/* Restore the system tick timer */
tickTimer->tickUnlock();
return;
}
@@ -142,14 +148,21 @@ STATIC BOOL OsPmTickTimerStop(LosPmCB *pm)
sleepCycle = OS_SYS_CYCLE_TO_NS(realSleepTime, g_sysClock);
sleepCycle = OS_SYS_NS_TO_CYCLE(sleepCycle, tickTimer->freq);
if (sleepCycle == 0) {
pm->sysMode = LOS_SYS_NORMAL_SLEEP;
return FALSE;
}
/* The main CPU reduces the frequency */
pm->enterSleepTime = LOS_SysCycleGet();
/* Turn off the system tick timer and clear the count value to zero */
tickTimer->tickLock();
tickTimer->timerStart(sleepCycle);
return TRUE;
}
#endif
/* Pause the system tick timer */
tickTimer->tickLock();
return TRUE;
}
@@ -167,7 +180,7 @@ STATIC VOID OsPmCpuResume(LosPmCB *pm)
STATIC VOID OsPmCpuSuspend(LosPmCB *pm)
{
/* cpu enter low power mode */
/* cpu enter low-power mode */
if (pm->sysMode == LOS_SYS_NORMAL_SLEEP) {
pm->sysctrl->normalSuspend();

View File

@@ -39,7 +39,7 @@
/**
* @ingroup los_pm
* Pm error code: Invalid low power mode.
* Pm error code: Invalid low-power mode.
*
* Value: 0x02002001
*
@@ -141,21 +141,33 @@ typedef enum {
} LOS_PmNodeType;
typedef struct {
UINT32 (*suspend)(UINT32 mode); /* The device enters low power consumption, Unlocked task scheduling. */
VOID (*resume)(UINT32 mode); /* The device exits from low power consumption, Unlocked task scheduling. */
UINT32 (*suspend)(UINT32 mode); /* The device enters low-power consumption, Unlocked task scheduling. */
VOID (*resume)(UINT32 mode); /* The device exits from low-power consumption, Unlocked task scheduling. */
} LosPmDevice;
typedef struct {
UINT32 freq; /* The frequency of the low power timer */
VOID (*timerStart)(UINT64); /* Start the low power timer */
VOID (*timerStop)(VOID); /* Stop the low power timer */
UINT64 (*timerCycleGet)(VOID); /* Gets the running time of the low power timer in unit cycle */
VOID (*tickLock)(VOID); /* Pause the system tick timer */
VOID (*tickUnlock)(VOID); /* Restore the system tick timer */
/* Low-power timer related implementation functions.
* The function is not NULL, the low-power timer is enabled.
*/
UINT32 freq; /* The frequency of the low-power timer */
VOID (*timerStart)(UINT64); /* Start the low-power timer and set the response period */
VOID (*timerStop)(VOID); /* Turn off the low-power timer */
UINT64 (*timerCycleGet)(VOID); /* Gets the time the system sleeps */
/* When the low-power timer is enabled, the function of tickLock is to turn off the system tick timer and
* clear the timer's count value to zero.
* When the low-power timer is disabled, the function of tickLock is to pause the system timer.
*/
VOID (*tickLock)(VOID);
/* When the low-power timer is enabled, the function of tickUnlock is to restart the system tick timer.
* When the low-power timer is disabled, the function of tickUnlock is to restore the system tick timer.
*/
VOID (*tickUnlock)(VOID);
} LosPmTickTimer;
typedef struct {
/* Preparations before the CPU enters low power consumption.
/* Preparations before the CPU enters low-power consumption.
* All modes except normal mode are invoked.
* Unlocked task scheduling.
*/
@@ -203,10 +215,10 @@ typedef struct {
/**
* @ingroup los_pm
* @brief Initialize system low power frame.
* @brief Initialize system low-power frame.
*
* @par Description:
* This API is used to initialize the system low power frame.
* This API is used to initialize the system low-power frame.
*
* @attention None.
*
@@ -221,10 +233,10 @@ UINT32 OsPmInit(VOID);
/**
* @ingroup los_pm
* @brief Whether the low power consumption condition is met.
* @brief Whether the low-power consumption condition is met.
*
* @par Description:
* This API is used to check whether low power consumption is met.
* This API is used to check whether low-power consumption is met.
*
* @attention None.
*
@@ -302,10 +314,10 @@ VOID LOS_PmWakeSet(VOID);
/**
* @ingroup los_pm
* @brief Get the low power mode of the current system.
* @brief Get the low-power mode of the current system.
*
* @par Description:
* This API is used to get the low power mode of the current system.
* This API is used to get the low-power mode of the current system.
*
* @attention None.
*
@@ -320,14 +332,14 @@ LOS_SysSleepEnum LOS_PmModeGet(VOID);
/**
* @ingroup los_pm
* @brief Set low power mode.
* @brief Set low-power mode.
*
* @par Description:
* This API is used to set low power mode.
* This API is used to set low-power mode.
*
* @attention None.
*
* @param mode [IN] low power mode.
* @param mode [IN] low-power mode.
*
* @retval error code, LOS_OK means success.
* @par Dependency:

View File

@@ -181,6 +181,7 @@ VOID OsLs(const CHAR *pathname)
d = opendir(path);
if (d == NULL) {
PRINT_ERR("No such directory = %s\n", path);
free(path);
} else {
PRINTK("Directory %s:\n", path);
do {

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
# Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -35,15 +35,12 @@ choice
config LIBC_MUSL
bool "musl libc"
rsource "musl/Kconfig"
config LIBC_NEWLIB
bool "newlibc"
rsource "newlib/Kconfig"
config LIBC_ICCARM
bool "iar libc"
depends on COMPILER_ICCARM
rsource "iccarm/Kconfig"
endchoice

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) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -33,10 +33,6 @@ import("//third_party/musl/porting/liteos_m/kernel/musl.gni")
module_switch = defined(LOSCFG_LIBC_MUSL)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"fs.c",
"malloc.c",
]
configs += [ "$LITEOSTOPDIR:warn_config" ]
deps = [ "//third_party/musl/porting/liteos_m/kernel" ]

View File

@@ -1,39 +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.
if LIBC_MUSL
config LIBC_MUSL_FS
bool "Enable POSIX file system API support"
default y
depends on FS_VFS
help
This enables POSIX style file system related APIs.
endif # LIBC_MUSL

View File

@@ -1,329 +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.
*/
#define _GNU_SOURCE
#include "los_config.h"
#include <errno.h>
#include <stdarg.h>
#include <dirent.h>
#include <sys/mount.h>
#include <sys/statfs.h>
#include <sys/stat.h>
#include <unistd.h>
#ifdef LOSCFG_LIBC_MUSL_FS
#include "los_fs.h"
int mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data)
{
return LOS_FsMount(source, target, filesystemtype, mountflags, data);
}
int umount(const char *target)
{
return LOS_FsUmount(target);
}
int umount2(const char *target, int flag)
{
return LOS_FsUmount2(target, flag);
}
int open(const char *path, int oflag, ...)
{
va_list vaList;
va_start(vaList, oflag);
int ret;
ret = LOS_Open(path, oflag, vaList);
va_end(vaList);
return ret;
}
int close(int fd)
{
return LOS_Close(fd);
}
ssize_t read(int fd, void *buf, size_t nbyte)
{
return LOS_Read(fd, buf, nbyte);
}
ssize_t write(int fd, const void *buf, size_t nbyte)
{
return LOS_Write(fd, buf, nbyte);
}
off_t lseek(int fd, off_t offset, int whence)
{
return LOS_Lseek(fd, offset, whence);
}
int unlink(const char *path)
{
return LOS_Unlink(path);
}
int fstat(int fd, struct stat *buf)
{
return LOS_Fstat(fd, buf);
}
int stat(const char *path, struct stat *buf)
{
return LOS_Stat(path, buf);
}
int fsync(int fd)
{
return LOS_Fsync(fd);
}
int mkdir(const char *path, mode_t mode)
{
return LOS_Mkdir(path, mode);
}
DIR *opendir(const char *dirName)
{
return LOS_Opendir(dirName);
}
struct dirent *readdir(DIR *dir)
{
return LOS_Readdir(dir);
}
int closedir(DIR *dir)
{
return LOS_Closedir(dir);
}
int rmdir(const char *path)
{
return LOS_Unlink(path);
}
int rename(const char *oldName, const char *newName)
{
return LOS_Rename(oldName, newName);
}
int statfs(const char *path, struct statfs *buf)
{
return LOS_Statfs(path, buf);
}
int ftruncate(int fd, off_t length)
{
return LOS_Ftruncate(fd, length);
}
ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset)
{
return LOS_Pread(fd, buf, nbyte, offset);
}
ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
{
return LOS_Pwrite(fd, buf, nbyte, offset);
}
int access(const char *path, int mode)
{
struct stat st;
if (stat(path, &st) < 0) {
return -1;
}
if ((st.st_mode & S_IFDIR) || (st.st_mode & S_IFREG)) {
return 0;
}
if ((mode & W_OK) && !(st.st_mode & S_IWRITE)) {
return -1;
}
return 0;
}
int fcntl(int fd, int cmd, ...)
{
int ret;
va_list vaList;
va_start(vaList, cmd);
ret = OsFcntl(fd, cmd, vaList);
va_end(vaList);
return ret;
}
int ioctl(int fd, int req, ...)
{
int ret;
va_list vaList;
va_start(vaList, req);
ret = OsIoctl(fd, req, vaList);
va_end(vaList);
return ret;
}
#else /* #ifdef LOSCFG_FS_VFS */
int mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data)
{
return -1;
}
int umount(const char *target)
{
return -1;
}
int umount2(const char *target, int flag)
{
return -1;
}
int open(const char *path, int oflag, ...)
{
return -1;
}
int close(int fd)
{
return -1;
}
ssize_t read(int fd, void *buf, size_t nbyte)
{
return -1;
}
ssize_t write(int fd, const void *buf, size_t nbyte)
{
return -1;
}
off_t lseek(int fd, off_t offset, int whence)
{
return -1;
}
int unlink(const char *path)
{
return -1;
}
int fstat(int fd, struct stat *buf)
{
return -1;
}
int stat(const char *path, struct stat *buf)
{
return -1;
}
int fsync(int fd)
{
return -1;
}
int mkdir(const char *path, mode_t mode)
{
return -1;
}
DIR *opendir(const char *dirName)
{
return NULL;
}
struct dirent *readdir(DIR *dir)
{
return NULL;
}
int closedir(DIR *dir)
{
return -1;
}
int rmdir(const char *path)
{
return -1;
}
int rename(const char *oldName, const char *newName)
{
return -1;
}
int statfs(const char *path, struct statfs *buf)
{
return -1;
}
int ftruncate(int fd, off_t length)
{
return -1;
}
ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset)
{
return -1;
}
ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
{
return -1;
}
int access(const char *path, int mode)
{
return -1;
}
int fcntl(int fd, int cmd, ...)
{
return -1;
}
int ioctl(int fd, int req, ...)
{
return -1;
}
#endif

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) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -33,18 +33,15 @@ module_switch = defined(LOSCFG_LIBC_NEWLIB)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"porting/src/fs.c",
"porting/src/malloc.c",
"porting/src/hook_adapt.c",
"porting/src/network/htonl.c",
"porting/src/network/htons.c",
"porting/src/network/ntohl.c",
"porting/src/network/ntohs.c",
"porting/src/other_adapt.c",
"porting/src/time.c",
]
configs += [ "$LITEOSTOPDIR:warn_config" ]
if (defined(LOSCFG_LIBC_NEWLIB_FS)) {
if (defined(LOSCFG_FS_VFS)) {
sources +=
[ "//third_party/musl/porting/liteos_m/kernel/src/misc/realpath.c" ]
}

View File

@@ -1,45 +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.
if LIBC_NEWLIB
config LIBC_NEWLIB_FS
bool "Enable POSIX file system API support"
default y
depends on FS_VFS
help
This enables POSIX style file system related APIs.
config LIBC_NEWLIB_MALLOC
bool "Enable POSIX malloc/free API support"
default y
help
This enables POSIX malloc/free related APIs.
endif # LIBC_NEWLIB

View File

@@ -49,6 +49,7 @@ typedef struct {
int sem_init(sem_t *sem, int shared, unsigned value);
int sem_destroy(sem_t *sem);
int sem_wait(sem_t *sem);
int sem_trywait(sem_t *sem);
int sem_post(sem_t *sem);
int sem_timedwait(sem_t *__restrict sem, const struct timespec *__restrict timeout);
int sem_getvalue(sem_t *__restrict sem, int *__restrict currVal);

View File

@@ -50,6 +50,7 @@
#define _POSIX_THREAD_PRIORITY_SCHEDULING
#define _UNIX98_THREAD_MUTEX_ATTRIBUTES
#define _POSIX_THREAD_PROCESS_SHARED
#define _POSIX_PRIORITY_SCHEDULING
#include_next <sys/features.h>

View File

@@ -1,271 +0,0 @@
/*
* 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.
*/
#define _GNU_SOURCE
#include "los_config.h"
#include <errno.h>
#include <stdio.h>
#include <stdarg.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#ifdef LOSCFG_LIBC_NEWLIB_FS
#include "los_fs.h"
#endif
#ifdef LOSCFG_LIBC_NEWLIB_FS
int mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data)
{
return LOS_FsMount(source, target, filesystemtype, mountflags, data);
}
int umount(const char *target)
{
return LOS_FsUmount(target);
}
int umount2(const char *target, int flag)
{
return LOS_FsUmount2(target, flag);
}
int _open(const char *path, int oflag, ...)
{
va_list vaList;
va_start(vaList, oflag);
int ret;
ret = LOS_Open(path, oflag);
va_end(vaList);
return ret;
}
int _close(int fd)
{
return LOS_Close(fd);
}
ssize_t _read(int fd, void *buf, size_t nbyte)
{
return LOS_Read(fd, buf, nbyte);
}
ssize_t _write(int fd, const void *buf, size_t nbyte)
{
return LOS_Write(fd, buf, nbyte);
}
off_t _lseek(int fd, off_t offset, int whence)
{
return LOS_Lseek(fd, offset, whence);
}
int _unlink(const char *path)
{
return LOS_Unlink(path);
}
int _fstat(int fd, struct stat *buf)
{
return LOS_Fstat(fd, buf);
}
int _stat(const char *path, struct stat *buf)
{
return LOS_Stat(path, buf);
}
int fsync(int fd)
{
return LOS_Fsync(fd);
}
int mkdir(const char *path, mode_t mode)
{
return LOS_Mkdir(path, mode);
}
DIR *opendir(const char *dirName)
{
return LOS_Opendir(dirName);
}
struct dirent *readdir(DIR *dir)
{
return LOS_Readdir(dir);
}
int closedir(DIR *dir)
{
return LOS_Closedir(dir);
}
int rmdir(const char *path)
{
return LOS_Unlink(path);
}
int rename(const char *oldName, const char *newName)
{
return LOS_Rename(oldName, newName);
}
int statfs(const char *path, struct statfs *buf)
{
return LOS_Statfs(path, buf);
}
int ftruncate(int fd, off_t length)
{
return LOS_Ftruncate(fd, length);
}
int fcntl(int fd, int cmd, ...)
{
int ret;
va_list vaList;
va_start(vaList, cmd);
ret = OsFcntl(fd, cmd, vaList);
va_end(vaList);
return ret;
}
int ioctl(int fd, int req, ...)
{
int ret;
va_list vaList;
va_start(vaList, req);
ret = OsIoctl(fd, req, vaList);
va_end(vaList);
return ret;
}
ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset)
{
return LOS_Pread(fd, buf, nbyte, offset);
}
ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
{
return LOS_Pwrite(fd, buf, nbyte, offset);
}
int access(const char *path, int mode)
{
struct stat st;
if (stat(path, &st) < 0) {
return -1;
}
if ((st.st_mode & S_IFDIR) || (st.st_mode & S_IFREG)) {
return 0;
}
if ((mode & W_OK) && !(st.st_mode & S_IWRITE)) {
return -1;
}
return 0;
}
int remove(const char *filename)
{
int ret = unlink(filename);
if (ret == -EISDIR) {
ret = rmdir(filename);
}
return ret;
}
#else /* #ifdef LOSCFG_FS_VFS */
int _open(const char *path, int oflag, ...)
{
return -1;
}
int _close(int fd)
{
return -1;
}
ssize_t _read(int fd, void *buf, size_t nbyte)
{
return -1;
}
ssize_t _write(int fd, const void *buf, size_t nbyte)
{
return -1;
}
off_t _lseek(int fd, off_t offset, int whence)
{
return -1;
}
int _unlink(const char *path)
{
return -1;
}
int _fstat(int fd, struct stat *buf)
{
return -1;
}
int _stat(const char *path, struct stat *buf)
{
return -1;
}
int access(const char *path, int mode)
{
return -1;
}
int remove(const char *filename)
{
return -1;
}
int fcntl(int fd, int cmd, ...)
{
return -1;
}
int ioctl(int fd, int req, ...)
{
return -1;
}
#endif

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2021-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -35,6 +35,12 @@
#include <unistd.h>
#include <pthread.h>
/*
* fs adapter interface, such as _read, see component/fs
* time adapter interface, such as _gettimeofday, see posix/src/time.c
* malloc adapter interface, such as _malloc_r, see posix/src/malloc.c
*/
int _isatty(int file)
{
return (int)(file <= 2); // 2: stderr
@@ -57,4 +63,3 @@ void _exit(int status)
while (1) {
}
}

View File

@@ -1,115 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "securec.h"
#include "los_config.h"
#include "los_memory.h"
#include <malloc.h>
#ifdef LOSCFG_LIBC_NEWLIB_MALLOC
void *zalloc(size_t size)
{
void *ptr = NULL;
if (size == 0) {
return NULL;
}
ptr = LOS_MemAlloc(OS_SYS_MEM_ADDR, size);
if (ptr != NULL) {
(void)memset_s(ptr, size, 0, size);
}
return ptr;
}
void __wrap__free_r(struct _reent *reent, void *aptr)
{
if (aptr == NULL) {
return;
}
LOS_MemFree(OS_SYS_MEM_ADDR, aptr);
}
size_t __wrap__malloc_usable_size_r(struct _reent *reent, void *aptr)
{
return 0;
}
void *__wrap__malloc_r(struct _reent *reent, size_t nbytes)
{
if (nbytes == 0) {
return NULL;
}
return LOS_MemAlloc(OS_SYS_MEM_ADDR, nbytes);
}
void *__wrap__memalign_r(struct _reent *reent, size_t align, size_t nbytes)
{
if (nbytes == 0) {
return NULL;
}
return LOS_MemAllocAlign(OS_SYS_MEM_ADDR, nbytes, align);
}
void *__wrap__realloc_r(struct _reent *reent, void *aptr, size_t nbytes)
{
if (aptr == NULL) {
return malloc(nbytes);
}
if (nbytes == 0) {
free(aptr);
return NULL;
}
return LOS_MemRealloc(OS_SYS_MEM_ADDR, aptr, nbytes);
}
void *__wrap__calloc_r(struct _reent *reent, size_t nitems, size_t size)
{
size_t real_size;
void *ptr = NULL;
if (nitems == 0 || size == 0) {
return NULL;
}
real_size = (size_t)(nitems * size);
ptr = LOS_MemAlloc(OS_SYS_MEM_ADDR, real_size);
if (ptr != NULL) {
(void)memset_s(ptr, real_size, 0, real_size);
}
return ptr;
}
#endif

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) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -35,6 +35,7 @@ kernel_module(module_name) {
sources = [
"src/errno.c",
"src/libc.c",
"src/map_error.c",
]
configs += [ "$LITEOSTOPDIR:warn_config" ]
@@ -67,6 +68,10 @@ kernel_module(module_name) {
if (defined(LOSCFG_POSIX_SIGNAL_API)) {
sources += [ "src/signal.c" ]
}
if (defined(LOSCFG_POSIX_MALLOC_API)) {
sources += [ "src/malloc.c" ]
}
}
config("public") {

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) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -73,4 +73,17 @@ config POSIX_SIGNAL_API
help
Answer Y to enable LiteOS support POSIX Signal API.
config POSIX_FS_API
bool "Enable POSIX FS API"
default y
depends on FS_VFS
help
Answer Y to enable LiteOS support POSIX FS API.
config POSIX_MALLOC_API
bool "Enable POSIX MALLOC API"
default y
help
Answer Y to enable LiteOS support POSIX MALLOC API.
endif # POSIX_API

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -34,9 +34,15 @@
#include "los_config.h"
#include "los_memory.h"
#if (LOSCFG_LIBC_NEWLIB == 1)
void *__wrap__calloc_r(struct _reent *reent, size_t nitems, size_t size)
#else
void *calloc(size_t nitems, size_t size)
#endif
{
#if (LOSCFG_LIBC_NEWLIB == 1)
(void)reent;
#endif
size_t real_size;
void *ptr = NULL;
@@ -52,8 +58,15 @@ void *calloc(size_t nitems, size_t size)
return ptr;
}
#if (LOSCFG_LIBC_NEWLIB == 1)
void __wrap__free_r(struct _reent *reent, void *ptr)
#else
void free(void *ptr)
#endif
{
#if (LOSCFG_LIBC_NEWLIB == 1)
(void)reent;
#endif
if (ptr == NULL) {
return;
}
@@ -61,8 +74,24 @@ void free(void *ptr)
LOS_MemFree(OS_SYS_MEM_ADDR, ptr);
}
void *malloc(size_t size)
#if (LOSCFG_LIBC_NEWLIB == 1)
size_t __wrap__malloc_usable_size_r(struct _reent *reent, void *aptr)
{
(void)reent;
(void)aptr;
return 0;
}
#endif
#if (LOSCFG_LIBC_NEWLIB == 1)
void *__wrap__malloc_r(struct _reent *reent, size_t size)
#else
void *malloc(size_t size)
#endif
{
#if (LOSCFG_LIBC_NEWLIB == 1)
(void)reent;
#endif
if (size == 0) {
return NULL;
}
@@ -85,8 +114,15 @@ void *zalloc(size_t size)
return ptr;
}
#if (LOSCFG_LIBC_NEWLIB == 1)
void *__wrap__memalign_r(struct _reent *reent, size_t boundary, size_t size)
#else
void *memalign(size_t boundary, size_t size)
#endif
{
#if (LOSCFG_LIBC_NEWLIB == 1)
(void)reent;
#endif
if (size == 0) {
return NULL;
}
@@ -94,8 +130,15 @@ void *memalign(size_t boundary, size_t size)
return LOS_MemAllocAlign(OS_SYS_MEM_ADDR, size, boundary);
}
#if (LOSCFG_LIBC_NEWLIB == 1)
void *__wrap__realloc_r(struct _reent *reent, void *ptr, size_t size)
#else
void *realloc(void *ptr, size_t size)
#endif
{
#if (LOSCFG_LIBC_NEWLIB == 1)
(void)reent;
#endif
if (ptr == NULL) {
return malloc(size);
}
@@ -107,4 +150,3 @@ void *realloc(void *ptr, size_t size)
return LOS_MemRealloc(OS_SYS_MEM_ADDR, ptr, size);
}

100
kal/posix/src/map_error.c Normal file
View File

@@ -0,0 +1,100 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_mux.h"
#include "los_queue.h"
#include "los_sem.h"
#include "los_task.h"
#include <errno.h>
INT32 map_errno(UINT32 err)
{
if (err == LOS_OK) {
return 0;
}
switch (err) {
case LOS_ERRNO_QUEUE_INVALID:
case LOS_ERRNO_QUEUE_WRITE_PTR_NULL:
case LOS_ERRNO_QUEUE_WRITESIZE_ISZERO:
case LOS_ERRNO_QUEUE_SIZE_TOO_BIG:
case LOS_ERRNO_QUEUE_CREAT_PTR_NULL:
case LOS_ERRNO_QUEUE_PARA_ISZERO:
case LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG:
case LOS_ERRNO_TSK_ID_INVALID:
case LOS_ERRNO_TSK_PTR_NULL:
case LOS_ERRNO_TSK_NAME_EMPTY:
case LOS_ERRNO_TSK_ENTRY_NULL:
case LOS_ERRNO_TSK_PRIOR_ERROR:
case LOS_ERRNO_TSK_STKSZ_TOO_LARGE:
case LOS_ERRNO_TSK_STKSZ_TOO_SMALL:
case LOS_ERRNO_TSK_NOT_CREATED:
case OS_ERROR:
case LOS_ERRNO_SEM_INVALID:
case LOS_ERRNO_SEM_UNAVAILABLE:
errno = EINVAL;
break;
case LOS_ERRNO_QUEUE_ISFULL:
case LOS_ERRNO_QUEUE_ISEMPTY:
errno = EAGAIN;
break;
case LOS_ERRNO_QUEUE_CREATE_NO_MEMORY:
case LOS_ERRNO_TSK_TCB_UNAVAILABLE:
case LOS_ERRNO_SEM_ALL_BUSY:
errno = ENOSPC;
break;
case LOS_ERRNO_QUEUE_TIMEOUT:
case LOS_ERRNO_SEM_TIMEOUT:
errno = ETIMEDOUT;
break;
case LOS_ERRNO_QUEUE_CB_UNAVAILABLE:
errno = ENFILE;
break;
case LOS_ERRNO_QUEUE_READ_IN_INTERRUPT:
case LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT:
case LOS_ERRNO_SEM_PEND_INTERR:
errno = EINTR;
break;
case LOS_ERRNO_TSK_NO_MEMORY:
case LOS_ERRNO_SEM_OVERFLOW:
errno = ENOMEM;
break;
case LOS_ERRNO_SEM_PENDED:
errno = EBUSY;
break;
case LOS_ERRNO_SEM_PEND_IN_LOCK:
errno = EPERM;
break;
default:
errno = EINVAL;
break;
}
return errno;
}

View File

@@ -1,6 +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) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -29,28 +28,21 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef COMMON_TEST_H
#define COMMON_TEST_H
#define TESTCOUNT_NUM_1 1
#define TESTCOUNT_NUM_2 2
#define TESTCOUNT_NUM_3 3
#define TESTCOUNT_NUM_4 4
#define TESTCOUNT_NUM_5 5
#define DELAY_TICKS_1 1
#define DELAY_TICKS_5 5
#define DELAY_TICKS_10 10
#define TEST_TASK_STACK_SIZE 0x600
#define TASK_LOOP_NUM 0x10000000
#define TEST_TIME 10
#define THREAD_COUNT_MIN 3
#define THREAD_COUNT_MAX 30
#define THREAD_STACK_SPACE_MAX 4096
#ifndef _POSIX_MAP_ERROR_H
#define _POSIX_MAP_ERROR_H
#ifdef __cplusplus
#if __cplusplus
#endif
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
INT32 map_errno(UINT32 err);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@@ -40,6 +40,7 @@
#include "los_config.h"
#include "los_task.h"
#include "los_debug.h"
#include "map_error.h"
#define PTHREAD_DEFAULT_NAME "pthread"
#define PTHREAD_DEFAULT_NAME_LEN 8
@@ -207,9 +208,10 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
return ret;
}
if (LOS_TaskCreateOnly(&taskID, &taskInitParam) != LOS_OK) {
ret = LOS_TaskCreateOnly(&taskID, &taskInitParam);
if (ret != LOS_OK) {
free((VOID *)(UINTPTR)taskInitParam.uwArg);
return EINVAL;
return map_errno(ret);
}
PthreadData *pthreadData = (PthreadData *)taskInitParam.uwArg;
@@ -221,10 +223,10 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
LOS_ListAdd(&g_pthreadListHead, &pthreadData->threadList);
LOS_IntRestore(intSave);
(void)LOS_TaskResume(taskID);
*thread = (pthread_t)taskID;
(void)LOS_TaskResume(taskID);
return 0;
}

View File

@@ -303,7 +303,6 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
PRINT_ERR("%s: %d failed\n", __FUNCTION__, __LINE__);
}
(VOID)LOS_EventClear(&(cond->event), 0);
ret = (INT32)LOS_EventRead(&(cond->event), 0x0f, LOS_WAITMODE_OR | LOS_WAITMODE_CLR, (UINT32)absTicks);
if (pthread_mutex_lock(mutex) != 0) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2022-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -50,7 +50,6 @@
/* accumulative time delta from discontinuous modify */
STATIC struct timespec g_accDeltaFromSet;
#ifndef __USE_NEWLIB__
STATIC const UINT16 g_daysInMonth[2][13] = {
/* Normal years. */
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
@@ -59,20 +58,18 @@ STATIC const UINT16 g_daysInMonth[2][13] = {
};
STATIC const UINT8 g_montbl[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
#endif
#ifndef __USE_NEWLIB__
#define g_timezone timezone
#if (LOSCFG_LIBC_NEWLIB == 1)
#define TIMEZONE _timezone
#else
#define g_Timezone _timezone
#endif
#define TIMEZONE timezone
/*
* Time zone information, stored in seconds,
* negative values indicate the east of UTC,
* positive values indicate the west of UTC.
*/
long g_timezone = -8 * 60 * 60; // set default to CST(UTC+8)
long TIMEZONE = -8 * 60 * 60; // set default to CST(UTC+8)
#endif
/*
* store register rtc func
@@ -529,7 +526,6 @@ time_t time(time_t *timer)
}
}
#ifndef __USE_NEWLIB__
/*
* Compute the `struct tm' representation of T,
* offset OFFSET seconds east of UTC,
@@ -621,7 +617,7 @@ struct tm *localtime_r(const time_t *timep, struct tm *result)
errno = EFAULT;
return NULL;
}
if (!ConvertSecs2Utc(*timep, -g_timezone, result)) {
if (!ConvertSecs2Utc(*timep, -TIMEZONE, result)) {
errno = EINVAL;
return NULL;
}
@@ -664,7 +660,7 @@ static time_t ConvertUtc2Secs(struct tm *tm)
seconds += (tm->tm_mday - 1) * SECS_PER_DAY;
seconds += tm->tm_hour * SECS_PER_HOUR + tm->tm_min * SECS_PER_MIN + tm->tm_sec;
seconds -= tm->__tm_gmtoff; // sub time zone to get UTC time
seconds += TIMEZONE;
return seconds;
}
@@ -690,7 +686,7 @@ time_t mktime(struct tm *tmptr)
}
timeInSeconds = ConvertUtc2Secs(tmptr);
/* normalize tm_wday and tm_yday */
ConvertSecs2Utc(timeInSeconds, tmptr->__tm_gmtoff, tmptr);
ConvertSecs2Utc(timeInSeconds, -TIMEZONE, tmptr);
return timeInSeconds;
}
@@ -724,18 +720,20 @@ int gettimeofday(struct timeval *tv, void *ptz)
}
if (tz != NULL) {
INT32 timeZone = 0;
if (g_rtcTimeFunc.RtcGetTimezoneHook != NULL) {
g_rtcTimeFunc.RtcGetTimezoneHook(&timeZone);
tz->tz_minuteswest = timezone / SECS_PER_MIN;
INT32 tempTimezone = 0;
g_rtcTimeFunc.RtcGetTimezoneHook(&tempTimezone);
tz->tz_minuteswest = tempTimezone / SECS_PER_MIN;
} else {
tz->tz_minuteswest = g_timezone / SECS_PER_MIN;
tz->tz_minuteswest = TIMEZONE / SECS_PER_MIN;
}
tz->tz_dsttime = 0;
}
return 0;
}
#if (LOSCFG_LIBC_NEWLIB == 1)
FUNC_ALIAS(gettimeofday, _gettimeofday, (struct timeval *tv, void *ptz), int);
#endif
int settimeofday(const struct timeval *tv, const struct timezone *tz)
@@ -755,14 +753,14 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
if (tz != NULL) {
if ((tz->tz_minuteswest >= TIME_ZONE_MIN) &&
(tz->tz_minuteswest <= TIME_ZONE_MAX)) {
g_timezone = tz->tz_minuteswest * SECS_PER_MIN;
TIMEZONE = tz->tz_minuteswest * SECS_PER_MIN;
} else {
errno = EINVAL;
return -1;
}
if (g_rtcTimeFunc.RtcSetTimezoneHook != NULL) {
g_rtcTimeFunc.RtcSetTimezoneHook(g_timezone);
g_rtcTimeFunc.RtcSetTimezoneHook(TIMEZONE);
}
}

View File

@@ -490,6 +490,72 @@ extern UINT32 LOS_MemIntegrityCheck(const VOID *pool);
* </ul>
* @see None.
*/
/* Supposing a Second Level Index: SLI = 3. */
#define OS_MEM_SLI 3
/* Giving 1 free list for each small bucket: 4, 8, 12, up to 124. */
#define OS_MEM_SMALL_BUCKET_COUNT 31
#define OS_MEM_SMALL_BUCKET_MAX_SIZE 128
/* Giving 2^OS_MEM_SLI free lists for each large bucket. */
#define OS_MEM_LARGE_BUCKET_COUNT 24
/* OS_MEM_SMALL_BUCKET_MAX_SIZE to the power of 2 is 7. */
#define OS_MEM_LARGE_START_BUCKET 7
/* The count of free list. */
#define OS_MEM_FREE_LIST_COUNT (OS_MEM_SMALL_BUCKET_COUNT + (OS_MEM_LARGE_BUCKET_COUNT << OS_MEM_SLI))
/* The bitmap is used to indicate whether the free list is empty, 1: not empty, 0: empty. */
#define OS_MEM_BITMAP_WORDS ((OS_MEM_FREE_LIST_COUNT >> 5) + 1)
struct OsMemNodeHead {
#if (LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK == 1)
UINT32 magic;
#endif
#if (LOSCFG_MEM_LEAKCHECK == 1)
UINTPTR linkReg[LOSCFG_MEM_RECORD_LR_CNT];
#endif
union {
struct OsMemNodeHead *prev; /* The prev is used for current node points to the previous node */
struct OsMemNodeHead *next; /* The next is used for sentinel node points to the expand node */
} ptr;
#if (LOSCFG_TASK_MEM_USED == 1)
UINT32 taskID;
UINT32 sizeAndFlag;
#elif (LOSCFG_MEM_FREE_BY_TASKID == 1)
UINT32 taskID : 6;
UINT32 sizeAndFlag : 26;
#else
UINT32 sizeAndFlag;
#endif
};
struct OsMemFreeNodeHead {
struct OsMemNodeHead header;
struct OsMemFreeNodeHead *prev;
struct OsMemFreeNodeHead *next;
};
struct OsMemPoolInfo {
VOID *pool;
UINT32 totalSize;
UINT32 attr;
#if (LOSCFG_MEM_WATERLINE == 1)
UINT32 waterLine; /* Maximum usage size in a memory pool */
UINT32 curUsedSize; /* Current usage size in a memory pool */
#endif
#if (LOSCFG_MEM_MUL_REGIONS == 1)
UINT32 totalGapSize;
#endif
};
struct OsMemPoolHead {
struct OsMemPoolInfo info;
UINT32 freeListBitmap[OS_MEM_BITMAP_WORDS];
struct OsMemFreeNodeHead *freeList[OS_MEM_FREE_LIST_COUNT];
#if (LOSCFG_MEM_MUL_POOL == 1)
VOID *nextPool;
#endif
};
extern VOID LOS_MemUnlockEnable(VOID *pool);
extern UINT32 OsMemSystemInit(VOID);

View File

@@ -453,7 +453,7 @@ extern UINT32 LOS_QueueCreateStatic(const CHAR *queueName,
* first.</li>
* <li>bufferAddr stores the obtained data.</li>
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
* <li>This API cannot be called before the kernel is initialized.</li>
* <li>The argument timeOut is a relative time.</li>
* </ul>
*
@@ -498,7 +498,7 @@ extern UINT32 LOS_QueueReadCopy(UINT32 queueID,
* <ul>
* <li>The specific queue should be created firstly.</li>
* <li>Do not read or write a queue in unblocking modes such as interrupt.</li>
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
* <li>This API cannot be called before the kernel is initialized.</li>
* <li>The data to be written is of the size specified by bufferSize and is stored at the address specified by
* BufferAddr.</li>
* <li>The argument timeOut is a relative time.</li>
@@ -547,7 +547,7 @@ extern UINT32 LOS_QueueWriteCopy(UINT32 queueID,
* read first.</li>
* <li>bufferAddr stores the obtained data address.</li>
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
* <li>This API cannot be called before the kernel is initialized.</li>
* <li>The argument timeOut is a relative time.</li>
* <li>The bufferSize is not really used in LOS_QueueRead, because the interface is only used to
* obtain the address of data.</li>
@@ -592,7 +592,7 @@ extern UINT32 LOS_QueueRead(UINT32 queueID,
* <ul>
* <li>The specific queue should be created firstly.</li>
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
* <li>This API cannot be called before the kernel is initialized.</li>
* <li>The address of the data of the size specified by bufferSize and stored at the address specified by
* BufferAddr is to be written.</li>
* <li>The argument timeOut is a relative time.</li>
@@ -639,7 +639,7 @@ extern UINT32 LOS_QueueWrite(UINT32 queueID,
* @attention
* <ul>
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
* <li>This API cannot be called before the kernel is initialized.</li>
* <li>The address of the data of the size specified by bufferSize and stored at the address specified by
* BufferAddr is to be written.</li>
* <li>The argument timeOut is a relative time.</li>
@@ -686,7 +686,7 @@ extern UINT32 LOS_QueueWriteHead(UINT32 queueID,
* @attention
* <ul>
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
* <li>This API cannot be called before the kernel is initialized.</li>
* <li>The address of the data of the size specified by bufferSize and stored at the address specified by
* BufferAddr is to be written.</li>
* <li>The argument timeOut is a relative time.</li>
@@ -889,7 +889,7 @@ extern LosQueueCB *g_allQueue;
* @attention
* <ul>
* <li>Do not alloc memory in unblocking modes such as interrupt.</li>
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
* <li>This API cannot be called before the kernel is initialized.</li>
* <li>The argument timeOut is a relative time.</li>
* </ul>
*
@@ -913,7 +913,7 @@ extern VOID *OsQueueMailAlloc(UINT32 queueID, VOID *mailPool, UINT32 timeOut);
* This API is used to free a stationary memory for a mail according to queueID.
* @attention
* <ul>
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
* <li>This API cannot be called before the kernel is initialized.</li>
* </ul>
*
* @param queueID [IN] Queue ID. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].

View File

@@ -37,6 +37,7 @@
#include "los_mux.h"
#include "los_queue.h"
#include "los_sem.h"
#include "securec.h"
#if (LOSCFG_PLATFORM_HWI == 1)
#include "los_interrupt.h"
@@ -95,6 +96,8 @@
#include "los_trace_pri.h"
#endif
#define BUFSIZE 256
/*****************************************************************************
Function : LOS_Reboot
Description : system exception, die in here, wait for watchdog.
@@ -110,10 +113,15 @@ LITE_OS_SEC_TEXT_INIT VOID LOS_Reboot(VOID)
LITE_OS_SEC_TEXT_INIT VOID LOS_Panic(const CHAR *fmt, ...)
{
char buf[BUFSIZE] = { 0 };
va_list ap;
va_start(ap, fmt);
PRINT_ERR(fmt, ap);
int len = vsnprintf_s(buf, sizeof(buf), BUFSIZE - 1, fmt, ap);
va_end(ap);
if (len > 0) {
PRINT_ERR("%s\n", buf);
}
OsDoExcHook(EXC_PANIC);
#if (LOSCFG_BACKTRACE_TYPE != 0)
LOS_BackTrace();
#endif

View File

@@ -256,9 +256,9 @@ UINT32 OsGetTaskWaterLine(UINT32 taskID)
}
#if (LOSCFG_BASE_CORE_CPUP == 1)
LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllTskCpupInfo(CPUP_INFO_S **cpuLessOneSec,
CPUP_INFO_S **cpuTenSec,
CPUP_INFO_S **cpuOneSec)
STATIC UINT32 GetAllTskCpupInfo(CPUP_INFO_S **cpuLessOneSec,
CPUP_INFO_S **cpuTenSec,
CPUP_INFO_S **cpuOneSec)
{
if ((cpuLessOneSec == NULL) || (cpuTenSec == NULL) || (cpuOneSec == NULL)) {
return OS_ERROR;
@@ -304,7 +304,26 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllTskCpupInfo(CPUP_INFO_S **cpuLessOneSec,
}
#endif
LITE_OS_SEC_TEXT_MINOR VOID OsPrintAllTskInfoHeader(VOID)
STATIC VOID PrintTskInfo(const LosTaskCB *taskCB)
{
UINT32 semID;
if (taskCB->taskStatus & OS_TASK_STATUS_EXIT) {
PRINTK("%4u%9u%10s%#10x%#10x%#11x%#11x%#10x%#7x",
taskCB->taskID, taskCB->priority, OsConvertTskStatus(taskCB->taskStatus),
taskCB->stackSize, 0, 0, 0, 0, 0);
return;
}
semID = (taskCB->taskSem == NULL) ? OS_NULL_SHORT : (((LosSemCB *)taskCB->taskSem)->semID);
PRINTK("%4u%9u%10s%#10x%#10x%#11x%#11x%#10x%#7x",
taskCB->taskID, taskCB->priority, OsConvertTskStatus(taskCB->taskStatus),
taskCB->stackSize, OsGetTaskWaterLine(taskCB->taskID),
(UINT32)(UINTPTR)taskCB->stackPointer, taskCB->topOfStack, taskCB->eventMask, semID);
return;
}
STATIC VOID PrintTskInfoHeader(VOID)
{
PRINTK("\r\n TID Priority Status StackSize WaterLine StackPoint TopOfStack EventMask SemID");
#if (LOSCFG_TASK_MEM_USED == 1)
@@ -341,7 +360,6 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllTskInfo(VOID)
#if (LOSCFG_KERNEL_PRINTF != 0)
LosTaskCB *taskCB = (LosTaskCB *)NULL;
UINT32 loopNum;
UINT32 semID;
#if (LOSCFG_BASE_CORE_CPUP == 1)
CPUP_INFO_S *cpuLessOneSec = (CPUP_INFO_S *)NULL;
CPUP_INFO_S *cpuTenSec = (CPUP_INFO_S *)NULL;
@@ -354,12 +372,12 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllTskInfo(VOID)
#endif
#if (LOSCFG_BASE_CORE_CPUP == 1)
if (OsGetAllTskCpupInfo(&cpuLessOneSec, &cpuTenSec, &cpuOneSec) != LOS_OK) {
if (GetAllTskCpupInfo(&cpuLessOneSec, &cpuTenSec, &cpuOneSec) != LOS_OK) {
return OS_ERROR;
}
#endif
#endif /* LOSCFG_BASE_CORE_CPUP */
OsPrintAllTskInfoHeader();
PrintTskInfoHeader();
for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
taskCB = (((LosTaskCB *)g_taskCBArray) + loopNum);
@@ -367,11 +385,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllTskInfo(VOID)
continue;
}
semID = (taskCB->taskSem == NULL) ? OS_NULL_SHORT : (((LosSemCB *)taskCB->taskSem)->semID);
PRINTK("%4u%9u%10s%#10x%#10x%#11x%#11x%#10x%#7x",
taskCB->taskID, taskCB->priority, OsConvertTskStatus(taskCB->taskStatus),
taskCB->stackSize, OsGetTaskWaterLine(taskCB->taskID),
(UINT32)(UINTPTR)taskCB->stackPointer, taskCB->topOfStack, taskCB->eventMask, semID);
PrintTskInfo(taskCB);
#if (LOSCFG_TASK_MEM_USED == 1)
PRINTK("%#10x", g_taskMemUsed[loopNum]);
#endif

View File

@@ -64,7 +64,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsUpdateSysTimeBase(VOID)
LITE_OS_SEC_TEXT VOID OsTickTimerBaseReset(UINT64 currTime)
{
LOS_ASSERT(currTime > g_tickTimerBase);
LOS_ASSERT(currTime >= g_tickTimerBase);
g_tickTimerBase = currTime;
}

View File

@@ -59,21 +59,6 @@ VOID *g_poolHead = NULL;
/* The following is the macro definition and interface implementation related to the TLSF. */
/* Supposing a Second Level Index: SLI = 3. */
#define OS_MEM_SLI 3
/* Giving 1 free list for each small bucket: 4, 8, 12, up to 124. */
#define OS_MEM_SMALL_BUCKET_COUNT 31
#define OS_MEM_SMALL_BUCKET_MAX_SIZE 128
/* Giving 2^OS_MEM_SLI free lists for each large bucket. */
#define OS_MEM_LARGE_BUCKET_COUNT 24
/* OS_MEM_SMALL_BUCKET_MAX_SIZE to the power of 2 is 7. */
#define OS_MEM_LARGE_START_BUCKET 7
/* The count of free list. */
#define OS_MEM_FREE_LIST_COUNT (OS_MEM_SMALL_BUCKET_COUNT + (OS_MEM_LARGE_BUCKET_COUNT << OS_MEM_SLI))
/* The bitmap is used to indicate whether the free list is empty, 1: not empty, 0: empty. */
#define OS_MEM_BITMAP_WORDS ((OS_MEM_FREE_LIST_COUNT >> 5) + 1)
#define OS_MEM_BITMAP_MASK 0x1FU
/* Used to find the first bit of 1 in bitmap. */
@@ -120,60 +105,10 @@ STATIC INLINE UINT32 OsMemSlGet(UINT32 size, UINT32 fl)
#error "When enter here, LOSCFG_BASE_CORE_TSK_LIMIT larger than 63 is not support"
#endif
struct OsMemNodeHead {
#if (LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK == 1)
UINT32 magic;
#endif
#if (LOSCFG_MEM_LEAKCHECK == 1)
UINTPTR linkReg[LOSCFG_MEM_RECORD_LR_CNT];
#endif
union {
struct OsMemNodeHead *prev; /* The prev is used for current node points to the previous node */
struct OsMemNodeHead *next; /* The next is used for sentinel node points to the expand node */
} ptr;
#if (LOSCFG_TASK_MEM_USED == 1)
UINT32 taskID;
UINT32 sizeAndFlag;
#elif (LOSCFG_MEM_FREE_BY_TASKID == 1)
UINT32 taskID : 6;
UINT32 sizeAndFlag : 26;
#else
UINT32 sizeAndFlag;
#endif
};
struct OsMemUsedNodeHead {
struct OsMemNodeHead header;
};
struct OsMemFreeNodeHead {
struct OsMemNodeHead header;
struct OsMemFreeNodeHead *prev;
struct OsMemFreeNodeHead *next;
};
struct OsMemPoolInfo {
VOID *pool;
UINT32 totalSize;
UINT32 attr;
#if (LOSCFG_MEM_WATERLINE == 1)
UINT32 waterLine; /* Maximum usage size in a memory pool */
UINT32 curUsedSize; /* Current usage size in a memory pool */
#endif
#if (LOSCFG_MEM_MUL_REGIONS == 1)
UINT32 totalGapSize;
#endif
};
struct OsMemPoolHead {
struct OsMemPoolInfo info;
UINT32 freeListBitmap[OS_MEM_BITMAP_WORDS];
struct OsMemFreeNodeHead *freeList[OS_MEM_FREE_LIST_COUNT];
#if (LOSCFG_MEM_MUL_POOL == 1)
VOID *nextPool;
#endif
};
/* The memory pool support expand. */
#define OS_MEM_POOL_EXPAND_ENABLE 0x01
/* The memory pool support no lock. */
@@ -539,7 +474,7 @@ RETRY:
OsMemFreeNodeAdd(pool, (struct OsMemFreeNodeHead *)newNode);
endNode = OS_MEM_END_NODE(newNode, size);
(VOID)memset(endNode, 0, sizeof(*endNode));
(VOID)memset_s(endNode, sizeof(*endNode), 0, sizeof(*endNode));
endNode->ptr.next = NULL;
OS_MEM_SET_MAGIC(endNode);
OsMemSentinelNodeSet(endNode, NULL, 0);
@@ -649,7 +584,8 @@ STATIC INLINE VOID OsMemLeakCheckInfoRecord(struct OsMemNodeHead *node)
STATIC INLINE VOID OsMemLeakCheckInit(VOID)
{
(VOID)memset(g_leakCheckRecord, 0, sizeof(struct OsMemLeakCheckInfo) * LOSCFG_MEM_LEAKCHECK_RECORD_MAX_NUM);
(VOID)memset_s(g_leakCheckRecord, sizeof(struct OsMemLeakCheckInfo) * LOSCFG_MEM_LEAKCHECK_RECORD_MAX_NUM,
0, sizeof(struct OsMemLeakCheckInfo) * LOSCFG_MEM_LEAKCHECK_RECORD_MAX_NUM);
g_leakCheckRecordCnt = 0;
}
@@ -923,6 +859,9 @@ STATIC UINT32 OsMemPoolInit(VOID *pool, UINT32 size)
struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)pool;
struct OsMemNodeHead *newNode = NULL;
struct OsMemNodeHead *endNode = NULL;
(VOID)memset_s(poolHead, size, 0, sizeof(struct OsMemPoolHead));
#ifdef LOSCFG_KERNEL_LMS
UINT32 resize = 0;
if (g_lms != NULL) {
@@ -934,7 +873,6 @@ STATIC UINT32 OsMemPoolInit(VOID *pool, UINT32 size)
size = (resize == 0) ? size : resize;
}
#endif
(VOID)memset(poolHead, 0, sizeof(struct OsMemPoolHead));
poolHead->info.pool = pool;
poolHead->info.totalSize = size;
@@ -972,9 +910,14 @@ STATIC UINT32 OsMemPoolInit(VOID *pool, UINT32 size)
}
#if (LOSCFG_MEM_MUL_POOL == 1)
STATIC VOID OsMemPoolDeinit(VOID *pool)
STATIC VOID OsMemPoolDeInit(VOID *pool, UINT32 size)
{
(VOID)memset(pool, 0, sizeof(struct OsMemPoolHead));
#ifdef LOSCFG_KERNEL_LMS
if (g_lms != NULL) {
g_lms->deInit(pool);
}
#endif
(VOID)memset_s(pool, size, 0, sizeof(struct OsMemPoolHead));
}
STATIC UINT32 OsMemPoolAdd(VOID *pool, UINT32 size)
@@ -1053,7 +996,7 @@ UINT32 LOS_MemInit(VOID *pool, UINT32 size)
#if (LOSCFG_MEM_MUL_POOL == 1)
if (OsMemPoolAdd(pool, size)) {
(VOID)OsMemPoolDeinit(pool);
(VOID)OsMemPoolDeInit(pool, size);
return LOS_NOK;
}
#endif
@@ -1066,17 +1009,23 @@ UINT32 LOS_MemInit(VOID *pool, UINT32 size)
#if (LOSCFG_MEM_MUL_POOL == 1)
UINT32 LOS_MemDeInit(VOID *pool)
{
if (pool == NULL) {
struct OsMemPoolHead *tmpPool = (struct OsMemPoolHead *)pool;
if (tmpPool == NULL) {
return LOS_NOK;
}
if (OsMemPoolDelete(pool)) {
if ((tmpPool->info.pool != pool) || (tmpPool->info.totalSize <= OS_MEM_MIN_POOL_SIZE)) {
return LOS_NOK;
}
OsMemPoolDeinit(pool);
if (OsMemPoolDelete(tmpPool)) {
return LOS_NOK;
}
OsHookCall(LOS_HOOK_TYPE_MEM_DEINIT, pool);
OsMemPoolDeInit(tmpPool, tmpPool->info.totalSize);
OsHookCall(LOS_HOOK_TYPE_MEM_DEINIT, tmpPool);
return LOS_OK;
}
@@ -2015,7 +1964,7 @@ UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_POOL_STATUS *poolStatus)
return LOS_NOK;
}
(VOID)memset(poolStatus, 0, sizeof(LOS_MEM_POOL_STATUS));
(VOID)memset_s(poolStatus, sizeof(LOS_MEM_POOL_STATUS), 0, sizeof(LOS_MEM_POOL_STATUS));
OsAllMemNodeDoHandle(pool, OsMemNodeInfoGetHandle, (VOID *)poolStatus);
@@ -2297,7 +2246,7 @@ STATIC VOID OsMemExcInfoGetSub(struct OsMemPoolHead *pool, MemInfoCB *memExcInfo
UINT32 taskID = OS_TASK_ERRORID;
UINT32 intSave = 0;
(VOID)memset(memExcInfo, 0, sizeof(MemInfoCB));
(VOID)memset_s(memExcInfo, sizeof(MemInfoCB), 0, sizeof(MemInfoCB));
MEM_LOCK(pool, intSave);
memExcInfo->type = MEM_MANG_MEMORY;

View File

@@ -27,6 +27,7 @@
# 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")
import("//kernel/liteos_m/liteos.gni")
config("include") {
@@ -36,6 +37,8 @@ config("include") {
if (defined(LOSCFG_KERNEL_TEST_FULL)) {
defines += [ "LOS_KERNEL_TEST_FULL=1" ]
}
cflags = warn_config_cflags
asmflags = warn_config_asmflags
}
module_switch = defined(LOSCFG_TEST)

View File

@@ -352,15 +352,10 @@ LITE_TEST_CASE(CmsisFuncTestSuite, TestCmsis004, Function | MediumTest | Level1)
ret = strcmp(staticBuff, strbuff);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ret = osMessageQueueDelete(msgQueueId);
ICUNIT_ASSERT_EQUAL(ret, osOK, ret);
#endif
return LOS_OK;
EXIT:
ret = osMessageQueueDelete(msgQueueId);
ICUNIT_ASSERT_EQUAL(ret, osOK, ret);
#endif
return LOS_OK;
}

View File

@@ -46,7 +46,7 @@ static VOID TaskF01(VOID)
ICUNIT_ASSERT_EQUAL_VOID(g_testAtomicID03, i, g_testAtomicID03);
ICUNIT_ASSERT_EQUAL_VOID(ret, g_testAtomicID03, ret);
LOS_AtomicAdd(&g_testCount, 1);
LOS_AtomicAdd((Atomic *)(&g_testCount), 1);
}
static UINT32 TestCase(VOID)

View File

@@ -33,7 +33,7 @@
#include "osTest.h"
#include "It_los_event.h"
static VOID TaskF01()
static VOID TaskF01(VOID)
{
UINT32 ret;

View File

@@ -47,6 +47,7 @@ static int g_uwIndex;
#else
#define TEST_MAX_NUMBER_HWI (OS_USER_HWI_MAX - HWI_NUM_INT0)
#define TEST_HWI_COUNT (TEST_MAX_NUMBER_HWI - 2)
#undef HWI_NUM_INT0
#define HWI_NUM_INT0 HWI_NUM_INT1
#endif

View File

@@ -43,6 +43,7 @@ static VOID HwiF01(VOID)
return;
}
#undef HWI_NUM_INT0
#define HWI_NUM_INT0 HWI_NUM_TEST1
static UINT32 Testcase(VOID)
{

View File

@@ -33,7 +33,7 @@
#include "los_timer.h"
#include "los_sched.h"
#define myprintf // printf
#define myprintf printf
#define TEST_LOOP 5
static EVENT_CB_S g_pmTestEvent;
static UINT32 g_taskID1, g_taskID2;

View File

@@ -39,7 +39,7 @@ static UINT32 Testcase(VOID)
CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = "";
CHAR buff3[QUEUE_SHORT_BUFFER_LENGTH] = {0};
ret = LOS_QueueCreateStatic("Q1", QUEUE_BASE_NUM, &g_testQueueID01, buff3, 0, QUEUE_BASE_MSGSIZE);
ret = LOS_QueueCreateStatic("Q1", QUEUE_BASE_NUM, &g_testQueueID01, (UINT8 *)buff3, 0, QUEUE_BASE_MSGSIZE);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueWrite(g_testQueueID01, &buff1, QUEUE_BASE_MSGSIZE, 0);

View File

@@ -43,7 +43,7 @@ static UINT32 Testcase(VOID)
g_testQueueID01 = QUEUW_INVALID_VALUE;
ret = LOS_QueueCreateStatic("Q1", QUEUE_BASE_NUM, &g_testQueueID01, buff3, 0, 0);
ret = LOS_QueueCreateStatic("Q1", QUEUE_BASE_NUM, &g_testQueueID01, (UINT8 *)buff3, 0, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_PARA_ISZERO, ret, EXIT);
ret = LOS_QueueWrite(g_testQueueID01, &buff1, QUEUE_BASE_MSGSIZE, 0);

View File

@@ -39,7 +39,7 @@ static UINT32 Testcase(VOID)
CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = "";
CHAR buff3[QUEUE_SHORT_BUFFER_LENGTH] = {0};
ret = LOS_QueueCreateStatic("Q1", QUEUE_BASE_NUM, &g_testQueueID01, buff3, 0, 1);
ret = LOS_QueueCreateStatic("Q1", QUEUE_BASE_NUM, &g_testQueueID01, (UINT8 *)buff3, 0, 1);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueWrite(g_testQueueID01, &buff1, QUEUE_BASE_MSGSIZE, 0);

View File

@@ -42,7 +42,7 @@ static UINT32 Testcase(VOID)
g_testQueueID01 = LOSCFG_BASE_IPC_QUEUE_LIMIT - 1;
ret = LOS_QueueCreateStatic("Q1", QUEUE_OVERSIZE_NUM, &g_testQueueID01, buff3, 0, 0xFFFF);
ret = LOS_QueueCreateStatic("Q1", QUEUE_OVERSIZE_NUM, &g_testQueueID01, (UINT8 *)buff3, 0, 0xFFFF);
ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_SIZE_TOO_BIG, ret, EXIT);
ret = LOS_QueueWrite(g_testQueueID01, &buff1, QUEUE_BASE_MSGSIZE, 0);

View File

@@ -43,7 +43,7 @@ static UINT32 Testcase(VOID)
g_testQueueID01 = QUEUW_INVALID_VALUE;
ret = LOS_QueueCreateStatic("Q1", QUEUE_BASE_NUM, NULL, buff3, 0, QUEUE_BASE_MSGSIZE);
ret = LOS_QueueCreateStatic("Q1", QUEUE_BASE_NUM, NULL, (UINT8 *)buff3, 0, QUEUE_BASE_MSGSIZE);
ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_CREAT_PTR_NULL, ret, EXIT);
ret = LOS_QueueWrite(g_testQueueID01, &buff1, QUEUE_BASE_MSGSIZE, 0);

View File

@@ -36,6 +36,15 @@ EVENT_CB_S g_eventCB0;
EVENT_CB_S g_eventCB1;
EVENT_CB_S g_eventCB2;
EVENT_CB_S g_eventCB3;
UINT32 g_swtmrId1;
UINT32 g_swtmrId2;
UINT32 g_swtmrId3;
UINT32 g_swtmrCountA;
UINT32 g_swtmrCountB;
UINT32 g_swtmrCountC;
UINT32 g_uwsTick1;
UINT32 g_uwsTick2;
UINT32 g_uwsTick3;
VOID ItSuiteLosSwtmr(void)
{

View File

@@ -56,17 +56,17 @@ extern EVENT_CB_S g_eventCB3;
extern UINT32 g_idleTaskID;
static UINT32 g_swtmrId1;
static UINT32 g_swtmrId2;
static UINT32 g_swtmrId3;
extern UINT32 g_swtmrId1;
extern UINT32 g_swtmrId2;
extern UINT32 g_swtmrId3;
static UINT32 g_swtmrCountA;
static UINT32 g_swtmrCountB;
static UINT32 g_swtmrCountC;
extern UINT32 g_swtmrCountA;
extern UINT32 g_swtmrCountB;
extern UINT32 g_swtmrCountC;
static UINT32 g_uwsTick1;
static UINT32 g_uwsTick2;
static UINT32 g_uwsTick3;
extern UINT32 g_uwsTick1;
extern UINT32 g_uwsTick2;
extern UINT32 g_uwsTick3;
extern VOID LOS_GetCpuTick(UINT32 *puwCntHi, UINT32 *puwCntLo);
extern VOID ItSuiteLosSwtmr(VOID);

View File

@@ -48,7 +48,7 @@ static VOID Case1(UINT32 arg)
return;
}
static VOID Case2()
static VOID Case2(VOID)
{
UINT32 ret;

View File

@@ -44,7 +44,7 @@ static VOID Case1(UINT32 arg)
return;
}
static VOID Case2()
static VOID Case2(VOID)
{
UINT32 ret;
UINT32 uwloop = 1000;

View File

@@ -41,7 +41,7 @@ static VOID Case1(UINT32 arg)
g_testCount = 30;
}
static VOID Case2()
static VOID Case2(VOID)
{
// 10, Here, assert that g_testCount is equal to this .
ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 10, g_testCount);
@@ -49,7 +49,7 @@ static VOID Case2()
g_testCount = 20;
}
static VOID Case3()
static VOID Case3(VOID)
{
// 10, Set the number to determine whether the process is as expected.
g_testCount = 10;

View File

@@ -51,7 +51,7 @@ EXIT:
LOS_TaskDelete(g_testTaskID01);
}
static VOID Case2()
static VOID Case2(VOID)
{
UINT32 ret;

View File

@@ -50,14 +50,14 @@ static VOID Case1(UINT32 arg)
g_testCount = 10;
}
static VOID Case2()
static VOID Case2(VOID)
{
// 20, Here, assert that g_testCount is equal to this .
ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 20, g_testCount);
g_testCount++;
}
static VOID Case3()
static VOID Case3(VOID)
{
UINT32 index;

View File

@@ -33,7 +33,7 @@
#include "It_los_swtmr.h"
static VOID Case1()
static VOID Case1(VOID)
{
UINT32 ret;
@@ -43,7 +43,7 @@ static VOID Case1()
}
}
static VOID Case2()
static VOID Case2(VOID)
{
UINT32 ret;
@@ -53,7 +53,7 @@ static VOID Case2()
}
}
static VOID Case3()
static VOID Case3(VOID)
{
UINT32 ret;
@@ -64,7 +64,7 @@ static VOID Case3()
}
}
VOID Case4()
static VOID Case4(VOID)
{
UINT32 ret;
@@ -77,7 +77,7 @@ VOID Case4()
}
}
VOID Case5()
static VOID Case5(VOID)
{
UINT32 ret;
@@ -90,7 +90,7 @@ VOID Case5()
}
}
VOID Case6()
static VOID Case6(VOID)
{
UINT32 ret;

View File

@@ -62,10 +62,10 @@ static UINT32 Testcase(VOID)
OS_SWTMR_ROUSES_IGNORE, OS_SWTMR_ALIGN_SENSITIVE
#endif
);
id2 = swtmrId1;
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
id2 = swtmrId1;
ICUNIT_GOTO_NOT_EQUAL(id1, id2, swtmrId1, EXIT);
ret = LOS_SwtmrDelete(id1);

View File

@@ -69,7 +69,7 @@ static UINT32 Testcase(VOID)
);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
id2 = swtmrId1;
ICUNIT_GOTO_NOT_EQUAL(id1, id2, swtmrId1, EXIT);
ICUNIT_GOTO_NOT_EQUAL(id1, id2, swtmrId1, EXIT1);
ret = LOS_SwtmrDelete(id1);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
@@ -78,9 +78,10 @@ static UINT32 Testcase(VOID)
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
return LOS_OK;
EXIT1:
LOS_SwtmrDelete(id2);
EXIT:
LOS_SwtmrDelete(id1);
LOS_SwtmrDelete(id2);
return LOS_OK;
}

View File

@@ -41,6 +41,7 @@ mqd_t g_mqueueId[LOSCFG_BASE_IPC_QUEUE_CONFIG + 1];
SEM_HANDLE_T g_mqueueSem;
mqd_t g_messageQId;
mqd_t g_gqueue;
TSK_HANDLE_T g_mqueueTaskPID;
VOID TestAssertWaitDelay(UINT32 *testCount, UINT32 flag)
{

View File

@@ -30,6 +30,8 @@
#ifndef IT_POSIX_QUEUE_H
#define IT_POSIX_QUEUE_H
#undef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#include <stdlib.h>
#include <mqueue.h>
@@ -40,6 +42,7 @@
#include <signal.h>
#include <osTest.h>
#include "pthread.h"
#include "unistd.h"
#define MAXMSG5 5
#define MSGLEN 10
@@ -57,18 +60,19 @@
#define MQUEUE_PRIORITY_TEST 0
#define MQUEUE_TIMEOUT_TEST 7
#define MQUEUE_PRIORITY_NUM_TEST 3
#define MQUEUE_MAX_NUM_TEST (LOSCFG_BASE_IPC_QUEUE_CONFIG - QUEUE_EXISTED_NUM)
#define MQ_MAX_MSG_NUM 16
#define MQ_MAX_MSG_LEN 64
#undef HWI_NUM_TEST
#define HWI_NUM_TEST 1
#undef HWI_NUM_TEST1
#define HWI_NUM_TEST1 2
#if (LOSCFG_LIBC_NEWLIB == 1)
#define MQ_PRIO_MAX 1
#endif
#undef LOSCFG_BASE_IPC_QUEUE_CONFIG
#define LOSCFG_BASE_IPC_QUEUE_CONFIG 1024
#define LOS_AtomicInc(a) (++*(a))
#define MqueueTaskDelay(tick) (usleep((tick) * 10000))
@@ -91,7 +95,7 @@ typedef UINT32 SEM_HANDLE_T ;
extern SEM_HANDLE_T g_mqueueSem;
static TSK_HANDLE_T g_mqueueTaskPID;
extern TSK_HANDLE_T g_mqueueTaskPID;
extern CHAR g_gqname[MQUEUE_STANDARD_NAME_LENGTH];
extern CHAR g_mqueueName[LOSCFG_BASE_IPC_QUEUE_CONFIG + 1][MQUEUE_STANDARD_NAME_LENGTH];
extern mqd_t g_mqueueId[LOSCFG_BASE_IPC_QUEUE_CONFIG + 1];
@@ -104,6 +108,7 @@ extern VOID ItSuitePosixMqueue(VOID);
extern UINT32 PosixPthreadInit(pthread_attr_t *attr, int pri);
extern UINT32 PosixPthreadDestroy(pthread_attr_t *attr, pthread_t thread);
extern VOID TestAssertWaitDelay(UINT32 *testCount, UINT32 flag);
extern void TestExtraTaskDelay(UINT32 tick);
VOID ItPosixQueue001(VOID);
VOID ItPosixQueue002(VOID);

View File

@@ -58,7 +58,6 @@ static UINT32 Testcase(VOID)
return LOS_OK;
EXIT1:
mq_close(mqueue);
EXIT:
mq_unlink(mqname);
return LOS_OK;
}

View File

@@ -35,9 +35,6 @@ static UINT32 Testcase(VOID)
CHAR msgrv1[MQUEUE_STANDARD_NAME_LENGTH] = {0};
struct mq_attr attr = {0};
INT32 ret = 0;
INT32 i;
pthread_t pthread1;
pthread_t pthread2;
mqd_t mqueue1;
mqd_t mqueue2;
struct timespec ts;
@@ -59,7 +56,6 @@ static UINT32 Testcase(VOID)
ret = mq_timedreceive(mqueue1, msgrv1, MQUEUE_STANDARD_NAME_LENGTH, NULL, &ts);
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
EXIT:
mq_close(mqueue1);
mq_close(mqueue2);
mq_unlink(mqname);

View File

@@ -34,8 +34,6 @@ static UINT32 Testcase(VOID)
INT32 ret;
CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = "";
mqd_t mqueue;
struct sigevent ev;
struct sigaction act;
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1,
"/mq013_%d", LOS_CurTaskIDGet());

View File

@@ -34,7 +34,6 @@ static UINT32 Testcase(VOID)
INT32 ret;
CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = {0};
mqd_t mqueue;
struct sigevent se;
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1,
"/mq021_%d", LOS_CurTaskIDGet());

View File

@@ -55,7 +55,7 @@ EXIT:
static VOID *PthreadF02(VOID *argument)
{
INT32 j, ret;
INT32 ret;
CHAR msgrcd[MQUEUE_STANDARD_NAME_LENGTH] = "";
@@ -82,8 +82,6 @@ static UINT32 Testcase(VOID)
{
pthread_t newTh1, newTh2;
UINT32 ret;
CHAR msgrcd[MQUEUE_STANDARD_NAME_LENGTH] = "";
const CHAR *msgptr = MQUEUE_SEND_STRING_TEST;
struct mq_attr attr = {0};
pthread_attr_t attr1;

View File

@@ -34,8 +34,6 @@ static UINT32 Testcase(VOID)
CHAR qname[MQUEUE_STANDARD_NAME_LENGTH] = "";
const CHAR *msgptr = MQUEUE_SEND_STRING_TEST;
mqd_t queue;
INT32 unresolved = 0;
INT32 failure = 0;
INT32 ret = 0;
ret = snprintf_s(qname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \

View File

@@ -36,7 +36,7 @@ static VOID *PthreadF01(VOID *argument)
g_testCount = 1;
TestAssertWaitDelay(&g_testCount, 3); // 3, Here, assert the g_testCount.
TestAssertWaitDelay((UINT32 *)&g_testCount, 3); // 3, Here, assert the g_testCount.
ret = mq_send(g_gqueue, msgptr, strlen(msgptr), 0);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
@@ -104,7 +104,7 @@ static UINT32 Testcase(VOID)
ret = pthread_create(&newTh1, &attr1, PthreadF01, NULL);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1);
TestAssertWaitDelay(&g_testCount, 1);
TestAssertWaitDelay((UINT32 *)&g_testCount, 1);
ret = PosixPthreadInit(&attr1, MQUEUE_PTHREAD_PRIORITY_TEST2);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2);
@@ -115,7 +115,7 @@ static UINT32 Testcase(VOID)
ret = MqueueTaskDelay(10); // 10, Set delay time.
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2);
TestAssertWaitDelay(&g_testCount, 4); // 4, Here, assert the g_testCount.
TestAssertWaitDelay((UINT32 *)&g_testCount, 4); // 4, Here, assert the g_testCount.
ret = PosixPthreadDestroy(&attr1, newTh2);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1);

View File

@@ -34,8 +34,6 @@ static UINT32 Testcase(VOID)
CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH], msgrv[MQUEUE_STANDARD_NAME_LENGTH];
mqd_t mqdes;
struct mq_attr attr = {0};
INT32 unresolved = 0;
INT32 failure = 0;
INT32 ret = 0;
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \

View File

@@ -35,8 +35,6 @@ static UINT32 Testcase(VOID)
mqd_t mqdes;
CHAR msgrv[MQUEUE_STANDARD_NAME_LENGTH];
struct mq_attr attr = {0};
INT32 unresolved = 0;
INT32 failure = 0;
INT32 ret = 0;
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \

View File

@@ -34,8 +34,6 @@ static UINT32 Testcase(VOID)
CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = "";
mqd_t mqdes;
struct mq_attr mqstat;
INT32 unresolved = 0;
INT32 failure = 0;
INT32 ret = 0;
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \

View File

@@ -34,8 +34,6 @@ static UINT32 Testcase(VOID)
CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = "";
mqd_t mqdes;
struct mq_attr mqstat, nmqstat;
INT32 unresolved = 0;
INT32 failure = 0;
INT32 ret = 0;
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \

View File

@@ -35,8 +35,6 @@ static UINT32 Testcase(VOID)
mqd_t mqdes;
struct mq_attr mqstat = {0};
struct mq_attr nmqstat = {0};
INT32 unresolved = 0;
INT32 failure = 0;
INT32 ret = 0;
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \

View File

@@ -38,23 +38,7 @@
#include "semaphore.h"
#include "unistd.h"
#ifdef LOSCFG_DEBUG_DEADLOCK
#define TEST_MUTEX_INIT \
{ \
{ 0, 0, 0, 0 }, \
{ \
{ 0, 0 }, { 0, 0 }, 0, 0 \
} \
}
#else
#define TEST_MUTEX_INIT \
{ \
{ 0, 0, 0, 0 }, \
{ \
{ 0, 0 }, 0, 0 \
} \
}
#endif
#define TEST_MUTEX_INIT {0}
#define MUTEX_TEST_DEFAULT_PRIO LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO
#define MUTEX_TEST_HIGH_PRIO (MUTEX_TEST_DEFAULT_PRIO - 6)

View File

@@ -37,7 +37,7 @@ static UINT32 Testcase(VOID)
pthread_mutex_t mutex = TEST_MUTEX_INIT;
sem_t sem;
int pshared;
int pshared = 0;
ret = pthread_mutexattr_init(&mta);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);

View File

@@ -33,7 +33,7 @@
#define THREAD_NUM 5
#define LOOPS 4
static g_value;
static int g_value;
static pthread_mutex_t g_mutex036 = PTHREAD_MUTEX_INITIALIZER;
/* pthread_mutex_lock 1-1.c

View File

@@ -28,13 +28,17 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#undef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#include "It_posix_mutex.h"
#include "unistd.h"
#define THREAD_NUM 6
#define LOOPS 3
static pthread_mutex_t g_mutex040 = PTHREAD_MUTEX_INITIALIZER;
static g_value;
static int g_value;
static void *TaskF01(void *parm)
{

View File

@@ -38,7 +38,7 @@ pthread_t TestPthreadSelf(void)
{
pthread_t tid = pthread_self();
if (tid == 0) {
tid = ((LosTaskCB *)(OsCurrTaskGet()))->taskID;
tid = (pthread_t)(((LosTaskCB *)(OsCurrTaskGet()))->taskID);
}
return tid;
}

View File

@@ -42,11 +42,6 @@
#include "mqueue.h"
#include "signal.h"
/* Some routines are part of the XSI Extensions */
#ifndef WITHOUT_XOPEN
#define _XOPEN_SOURCE 600
#endif
#define PTHREAD_IS_ERROR (-1)
#define PTHREAD_PRIORITY_TEST 20
#define PTHREAD_DEFAULT_STACK_SIZE (LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE)
@@ -69,10 +64,6 @@
#define PTHREAD_EXISTED_SEM_NUM SEM_EXISTED_NUM
/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
#define _POSIX_C_SOURCE 200112L
#define PTHREAD_MUTEX_RECURSIVE 0
#define PTHREAD_MUTEX_ERRORCHECK 0
#define PRIORITY_OTHER (-1)
#define PRIORITY_FIFO 20

View File

@@ -28,6 +28,9 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#undef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#include <securec.h>
#include "osTest.h"
#include "pthread.h"

View File

@@ -102,7 +102,7 @@ char *g_strType[] = {
"FUNCTION", "PRESSURE", "PERFORMANCE"
};
iUINT32 ICunitRunF()
iUINT32 ICunitRunF(void)
{
iUINT32 idx, idx1;
ICUNIT_CASE_S *psubCaseArray;

View File

@@ -231,7 +231,7 @@ void TestCmsis2(void)
}
#endif
VOID TestTaskEntry()
VOID TestTaskEntry(VOID)
{
PRINTF("\t\n --- Test Start --- \n\n");
ICunitInit();

View File

@@ -39,7 +39,6 @@ static_library("posix_test") {
"src/ctype/tolower_test.c",
"src/ctype/toupper_test.c",
"src/errno/strerror_test.c",
"src/fs/posix_fs_func_test.c",
"src/math/math_func_test.c",
"src/mqueue/mqueue_func_test.c",
"src/posix_test.c",
@@ -61,13 +60,20 @@ static_library("posix_test") {
"src/time/time_func_test_01.c",
]
if (defined(LOSCFG_SUPPORT_FATFS) || defined(LOSCFG_SUPPORT_LITTLEFS)) {
deps = [ "src/fs" ]
}
include_dirs = [
"//test/xts/tools/hctest/include",
"src",
]
if (!defined(LOSCFG_COMPILER_ICCARM)) {
cflags = [ "-Wno-error" ]
cflags = [
"-Wno-unused-function",
"-Wno-int-conversion",
]
} else {
cflags = [ "--no_warnings" ]
}

View File

@@ -76,7 +76,7 @@ LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower001, Function | MediumTest
if (ret == 'a') {
LOG("[DEMO] posix ctype test case 1:tolower(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 1:tolower(%c)!=%c fail.\n", a);
LOG("[DEMO] posix ctype test case 1:tolower(%c)!=%c fail.\n", a, ret);
}
TEST_ASSERT_TRUE(ret == 'a');
return 0;
@@ -94,7 +94,7 @@ LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower002, Function | MediumTest
if (ret == 'a') {
LOG("[DEMO] posix ctype test case 2:tolower(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 2:tolower(%c)!=%c fail.\n", a);
LOG("[DEMO] posix ctype test case 2:tolower(%c)!=%c fail.\n", a, ret);
}
TEST_ASSERT_TRUE(ret == 'a');
return 0;
@@ -112,7 +112,7 @@ LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower003, Function | MediumTest
if (ret == 'z') {
LOG("[DEMO] posix ctype test case 3:tolower(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 3:tolower(%c)!=%c fail.\n", a);
LOG("[DEMO] posix ctype test case 3:tolower(%c)!=%c fail.\n", a, ret);
}
TEST_ASSERT_TRUE(ret == 'z');
return 0;
@@ -130,7 +130,7 @@ LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower004, Function | MediumTest
if (ret == 'z') {
LOG("[DEMO] posix ctype test case 4:tolower(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 4:tolower(%c)!=%c fail.\n", a);
LOG("[DEMO] posix ctype test case 4:tolower(%c)!=%c fail.\n", a, ret);
}
TEST_ASSERT_TRUE(ret == 'z');
return 0;
@@ -148,7 +148,7 @@ LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower005, Function | MediumTest
if (ret == '1') {
LOG("[DEMO] posix ctype test case 5(except):tolower(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 5(except):tolower(%c)!=%c fail.\n", a);
LOG("[DEMO] posix ctype test case 5(except):tolower(%c)!=%c fail.\n", a, ret);
}
TEST_ASSERT_TRUE(ret == '1');
return 0;

View File

@@ -76,7 +76,7 @@ LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper001, Function | MediumTest
if (ret == 'A') {
LOG("[DEMO] posix ctype test case 1:toupper(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 1:toupper(%c)!=%c fail.\n", a);
LOG("[DEMO] posix ctype test case 1:toupper(%c)!=%c fail.\n", a, ret);
}
TEST_ASSERT_TRUE(ret == 'A');
return 0;
@@ -94,7 +94,7 @@ LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper002, Function | MediumTest
if (ret == 'A') {
LOG("[DEMO] posix ctype test case 2:toupper(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 2:toupper(%c)!=%c fail.\n", a);
LOG("[DEMO] posix ctype test case 2:toupper(%c)!=%c fail.\n", a, ret);
}
TEST_ASSERT_TRUE(ret == 'A');
return 0;
@@ -112,7 +112,7 @@ LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper003, Function | MediumTest
if (ret == 'Z') {
LOG("[DEMO] posix ctype test case 3:toupper(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 3:toupper(%c)!=%c fail.\n", a);
LOG("[DEMO] posix ctype test case 3:toupper(%c)!=%c fail.\n", a, ret);
}
TEST_ASSERT_TRUE(ret == 'Z');
return 0;
@@ -130,7 +130,7 @@ LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper004, Function | MediumTest
if (ret == 'Z') {
LOG("[DEMO] posix ctype test case 4:toupper(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 4:toupper(%c)!=%c fail.\n", a);
LOG("[DEMO] posix ctype test case 4:toupper(%c)!=%c fail.\n", a, ret);
}
TEST_ASSERT_TRUE(ret == 'Z');
return 0;
@@ -148,7 +148,7 @@ LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper005, Function | MediumTest
if (ret == '1') {
LOG("[DEMO] posix ctype test case 5(except):toupper(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 5(except):toupper(%c)!=%c fail.\n", a);
LOG("[DEMO] posix ctype test case 5(except):toupper(%c)!=%c fail.\n", a, ret);
}
TEST_ASSERT_TRUE(ret == '1');
return 0;

View File

@@ -95,7 +95,8 @@ LITE_TEST_CASE(PosixSysFuncTestSuite, testOsSysStrerror001, Function | MediumTes
LOG("strerror(10) = %s\n", strerror(10));
TEST_ASSERT_EQUAL_STRING("No children", strerror(10));
#endif
return LOS_OK;
};
RUN_TEST_SUITE(PosixSysFuncTestSuite);

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -26,19 +26,36 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
if LIBC_ICCARM
static_library("fs") {
sources = [
"api/posix_fs_access_test.c",
"api/posix_fs_close_test.c",
"api/posix_fs_closedir_test.c",
"api/posix_fs_fstat_test.c",
"api/posix_fs_fsync_test.c",
"api/posix_fs_ftruncate_test.c",
"api/posix_fs_lseek_test.c",
"api/posix_fs_mkdir_test.c",
"api/posix_fs_open_test.c",
"api/posix_fs_opendir_test.c",
"api/posix_fs_pread_test.c",
"api/posix_fs_pwrite_test.c",
"api/posix_fs_read_test.c",
"api/posix_fs_readdir_test.c",
"api/posix_fs_rename_test.c",
"api/posix_fs_rmdir_test.c",
"api/posix_fs_stat_test.c",
"api/posix_fs_statfs_test.c",
"api/posix_fs_unlink_test.c",
"api/posix_fs_write_test.c",
"full/posix_fs_full_test.c",
"posix_fs_func_test.c",
"pressure/posix_fs_pressure_test.c",
]
config LIBC_ICCARM_FS
bool "Enable POSIX file system API support"
default y
depends on FS_VFS
help
This enables POSIX style file system related APIs.
config LIBC_ICCARM_MALLOC
bool "Enable POSIX malloc/free API support"
default y
help
This enables POSIX malloc/free related APIs.
endif # LIBC_ICCARM
include_dirs = [
".",
"../",
"../../../../include",
]
}

View File

@@ -0,0 +1,90 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "posix_fs_test.h"
/* *
* @tc.number SUB_KERNEL_FS_ACCESS_OK
* @tc.name access
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsAccessOK, Function | MediumTest | Level1)
{
int32_t ret;
const char tmpFileName[TEST_BUF_SIZE] = FILE1;
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_HIGH);
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
ret = access(tmpFileName, F_OK);
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
#if (LOSCFG_SUPPORT_FATFS == 1)
ret = access(tmpFileName, R_OK);
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
ret = access(tmpFileName, W_OK);
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
ret = access(tmpFileName, X_OK);
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
#endif
EXIT:
ret = close(fd);
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
ret = unlink(tmpFileName);
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
return POSIX_FS_NO_ERROR;
}
/* *
* @tc.number SUB_KERNEL_FS_ACCESS_EINVAL
* @tc.name access
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsAccessEINVAL, Function | MediumTest | Level1)
{
char *tmpFileName = NULL;
int32_t ret = access(tmpFileName, F_OK);
ICUNIT_ASSERT_EQUAL(errno, EINVAL, POSIX_FS_IS_ERROR);
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
return POSIX_FS_NO_ERROR;
}
void PosixFsAccessTest(void)
{
RUN_ONE_TESTCASE(TestFsAccessOK);
RUN_ONE_TESTCASE(TestFsAccessEINVAL);
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "posix_fs_test.h"
/* *
* @tc.number SUB_KERNEL_FS_CLOSE_OK
* @tc.name close
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsCloseOK, Function | MediumTest | Level1)
{
int32_t ret;
const char tmpFileName[TEST_BUF_SIZE] = FILE1;
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR);
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
ret = close(fd);
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
ret = unlink(tmpFileName);
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
return POSIX_FS_NO_ERROR;
}
void PosixFsCloseTest(void)
{
RUN_ONE_TESTCASE(TestFsCloseOK);
}

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