summaryrefslogtreecommitdiff
path: root/components/libc
diff options
context:
space:
mode:
authorWBI\nxf44444 <[email protected]>2022-01-26 01:43:05 +0800
committerWBI\nxf44444 <[email protected]>2022-01-26 01:43:05 +0800
commit8b0f50b7e211ee32ab08ba085ecd74588c3a3c63 (patch)
tree75440be5ecd30cc1403a9387851c0530ed057981 /components/libc
parent3be35fecae513b07c35bd6f3992bf7824434bdd6 (diff)
parent32a5668593c578b85560338c29d76f3a252c8dbc (diff)
Update i2c driver, add read ACK and BUS status check
Diffstat (limited to 'components/libc')
-rw-r--r--components/libc/Kconfig60
-rw-r--r--components/libc/aio/SConscript11
-rw-r--r--components/libc/compilers/armlibc/README.md6
-rw-r--r--components/libc/compilers/armlibc/SConscript13
-rw-r--r--components/libc/compilers/armlibc/dirent.h62
-rw-r--r--components/libc/compilers/armlibc/fcntl.h18
-rw-r--r--components/libc/compilers/armlibc/libc.c43
-rw-r--r--components/libc/compilers/armlibc/libc.h28
-rw-r--r--components/libc/compilers/armlibc/libc_syms.c49
-rw-r--r--components/libc/compilers/armlibc/mem_std.c42
-rw-r--r--components/libc/compilers/armlibc/stdio.c75
-rw-r--r--components/libc/compilers/armlibc/sys/README.md1
-rw-r--r--components/libc/compilers/armlibc/sys/errno.h14
-rw-r--r--components/libc/compilers/armlibc/sys/ioctl.h15
-rw-r--r--components/libc/compilers/armlibc/sys/mman.h58
-rw-r--r--components/libc/compilers/armlibc/sys/stat.h8
-rw-r--r--components/libc/compilers/armlibc/sys/unistd.h76
-rw-r--r--components/libc/compilers/armlibc/syscall_mem.c71
-rw-r--r--components/libc/compilers/armlibc/syscalls.c (renamed from components/libc/compilers/armlibc/stubs.c)251
-rw-r--r--components/libc/compilers/common/SConscript20
-rw-r--r--components/libc/compilers/common/compiler_private.h17
-rw-r--r--components/libc/compilers/common/dirent.h (renamed from components/libc/compilers/dlib/dirent.h)29
-rw-r--r--components/libc/compilers/common/extension/SConscript14
-rw-r--r--components/libc/compilers/common/extension/fcntl.h71
-rw-r--r--components/libc/compilers/common/extension/readme.md4
-rw-r--r--components/libc/compilers/common/extension/sys/errno.h585
-rw-r--r--components/libc/compilers/common/extension/sys/select.h58
-rw-r--r--components/libc/compilers/common/extension/sys/stat.h83
-rw-r--r--components/libc/compilers/common/extension/sys/types.h (renamed from components/libc/compilers/armlibc/sys/types.h)24
-rw-r--r--components/libc/compilers/common/extension/sys/unistd.h49
-rw-r--r--components/libc/compilers/common/extension/unistd.h (renamed from components/libc/compilers/armlibc/unistd.h)4
-rw-r--r--components/libc/compilers/common/readme.md11
-rw-r--r--components/libc/compilers/common/stdlib.c45
-rw-r--r--components/libc/compilers/common/sys/ioctl.h274
-rw-r--r--components/libc/compilers/common/sys/signal.h232
-rw-r--r--components/libc/compilers/common/sys/statfs.h25
-rw-r--r--components/libc/compilers/common/sys/time.h147
-rw-r--r--components/libc/compilers/common/sys/vfs.h16
-rw-r--r--components/libc/compilers/common/termios.h19
-rw-r--r--components/libc/compilers/common/time.c881
-rw-r--r--components/libc/compilers/common/unistd.c26
-rw-r--r--components/libc/compilers/dlib/README.md6
-rw-r--r--components/libc/compilers/dlib/SConscript10
-rw-r--r--components/libc/compilers/dlib/environ.c2
-rw-r--r--components/libc/compilers/dlib/fcntl.h8
-rw-r--r--components/libc/compilers/dlib/libc.c44
-rw-r--r--components/libc/compilers/dlib/rmtx.c60
-rw-r--r--components/libc/compilers/dlib/stdio.c58
-rw-r--r--components/libc/compilers/dlib/sys/README.md1
-rw-r--r--components/libc/compilers/dlib/sys/errno.h16
-rw-r--r--components/libc/compilers/dlib/sys/signal.h16
-rw-r--r--components/libc/compilers/dlib/sys/stat.h8
-rw-r--r--components/libc/compilers/dlib/sys/types.h25
-rw-r--r--components/libc/compilers/dlib/sys/unistd.h50
-rw-r--r--components/libc/compilers/dlib/syscall_close.c27
-rw-r--r--components/libc/compilers/dlib/syscall_lseek.c34
-rw-r--r--components/libc/compilers/dlib/syscall_mem.c41
-rw-r--r--components/libc/compilers/dlib/syscall_open.c101
-rw-r--r--components/libc/compilers/dlib/syscall_read.c56
-rw-r--r--components/libc/compilers/dlib/syscall_remove.c32
-rw-r--r--components/libc/compilers/dlib/syscall_write.c73
-rw-r--r--components/libc/compilers/dlib/syscalls.c19
-rw-r--r--components/libc/compilers/dlib/syscalls.h10
-rw-r--r--components/libc/compilers/dlib/unistd.h14
-rw-r--r--components/libc/compilers/minilibc/SConscript15
-rw-r--r--components/libc/compilers/minilibc/ctype.c49
-rw-r--r--components/libc/compilers/minilibc/ctype.h18
-rw-r--r--components/libc/compilers/minilibc/errno.h16
-rw-r--r--components/libc/compilers/minilibc/inttypes.h14
-rw-r--r--components/libc/compilers/minilibc/math.c176
-rw-r--r--components/libc/compilers/minilibc/math.h20
-rw-r--r--components/libc/compilers/minilibc/qsort.c52
-rw-r--r--components/libc/compilers/minilibc/rand.c43
-rw-r--r--components/libc/compilers/minilibc/signal.h20
-rw-r--r--components/libc/compilers/minilibc/stddef.h15
-rw-r--r--components/libc/compilers/minilibc/stdint.h266
-rw-r--r--components/libc/compilers/minilibc/stdio.h26
-rw-r--r--components/libc/compilers/minilibc/stdlib.c75
-rw-r--r--components/libc/compilers/minilibc/stdlib.h33
-rw-r--r--components/libc/compilers/minilibc/string.c630
-rw-r--r--components/libc/compilers/minilibc/string.h69
-rw-r--r--components/libc/compilers/minilibc/sys/mman.h58
-rw-r--r--components/libc/compilers/minilibc/sys/stat.h44
-rw-r--r--components/libc/compilers/minilibc/sys/time.h54
-rw-r--r--components/libc/compilers/minilibc/sys/types.h50
-rw-r--r--components/libc/compilers/minilibc/time.c287
-rw-r--r--components/libc/compilers/minilibc/time.h24
-rw-r--r--components/libc/compilers/newlib/README.md7
-rw-r--r--components/libc/compilers/newlib/SConscript32
-rw-r--r--components/libc/compilers/newlib/fcntl.h24
-rw-r--r--components/libc/compilers/newlib/legacy/SConscript15
-rw-r--r--components/libc/compilers/newlib/legacy/_select/SConscript20
-rw-r--r--components/libc/compilers/newlib/legacy/_select/readme.md2
-rw-r--r--components/libc/compilers/newlib/legacy/_select/sys/select.h58
-rw-r--r--components/libc/compilers/newlib/libc.c50
-rw-r--r--components/libc/compilers/newlib/libc.h45
-rw-r--r--components/libc/compilers/newlib/machine/time.h17
-rw-r--r--components/libc/compilers/newlib/stdio.c80
-rw-r--r--components/libc/compilers/newlib/sys/dirent.h65
-rw-r--r--components/libc/compilers/newlib/sys/mman.h58
-rw-r--r--components/libc/compilers/newlib/sys/statfs.h21
-rw-r--r--components/libc/compilers/newlib/sys/termios.h8
-rw-r--r--components/libc/compilers/newlib/syscalls.c542
-rw-r--r--components/libc/compilers/readme.md1
-rw-r--r--components/libc/getline/README.md30
-rw-r--r--components/libc/getline/SConscript13
-rw-r--r--components/libc/getline/UNLICENSE24
-rw-r--r--components/libc/getline/posix_getline.c79
-rw-r--r--components/libc/getline/posix_getline.h24
-rw-r--r--components/libc/libdl/SConscript14
-rw-r--r--components/libc/posix-info.txt324
-rw-r--r--components/libc/posix/Kconfig80
-rw-r--r--components/libc/posix/SConscript15
-rw-r--r--components/libc/posix/delay/SConscript (renamed from components/libc/time/SConscript)5
-rw-r--r--components/libc/posix/delay/delay.c87
-rw-r--r--components/libc/posix/delay/delay.h21
-rw-r--r--components/libc/posix/io/README.md10
-rw-r--r--components/libc/posix/io/SConscript15
-rw-r--r--components/libc/posix/io/aio/SConscript11
-rw-r--r--components/libc/posix/io/aio/aio.c (renamed from components/libc/aio/posix_aio.c)393
-rw-r--r--components/libc/posix/io/aio/aio.h (renamed from components/libc/aio/posix_aio.h)10
-rw-r--r--components/libc/posix/io/mman/SConscript11
-rw-r--r--components/libc/posix/io/mman/mman.c (renamed from components/libc/mmap/posix_mmap.c)8
-rw-r--r--components/libc/posix/io/mman/sys/mman.h (renamed from components/libc/compilers/dlib/sys/mman.h)8
-rw-r--r--components/libc/posix/io/poll/SConscript17
-rw-r--r--components/libc/posix/io/poll/poll.c227
-rw-r--r--components/libc/posix/io/poll/poll.h50
-rw-r--r--components/libc/posix/io/poll/select.c177
-rw-r--r--components/libc/posix/io/stdio/SConscript22
-rw-r--r--components/libc/posix/io/stdio/libc.c158
-rw-r--r--components/libc/posix/io/stdio/libc.h (renamed from components/libc/compilers/dlib/libc.h)13
-rw-r--r--components/libc/posix/io/termios/SConscript11
-rw-r--r--components/libc/posix/io/termios/termios.c (renamed from components/libc/termios/posix_termios.c)11
-rw-r--r--components/libc/posix/io/termios/termios.h (renamed from components/libc/termios/posix_termios.h)9
-rw-r--r--components/libc/posix/ipc/Kconfig36
-rw-r--r--components/libc/posix/ipc/SConscript20
-rw-r--r--components/libc/posix/ipc/mqueue.c (renamed from components/libc/pthreads/mqueue.c)16
-rw-r--r--components/libc/posix/ipc/mqueue.h (renamed from components/libc/pthreads/mqueue.h)7
-rw-r--r--components/libc/posix/ipc/semaphore.c (renamed from components/libc/pthreads/semaphore.c)15
-rw-r--r--components/libc/posix/ipc/semaphore.h (renamed from components/libc/pthreads/semaphore.h)6
-rw-r--r--components/libc/posix/ipc/system-v/sys/ipc.h16
-rw-r--r--components/libc/posix/ipc/system-v/sys/msg.h16
-rw-r--r--components/libc/posix/ipc/system-v/sys/sem.h14
-rw-r--r--components/libc/posix/ipc/system-v/sys/shm.h16
-rw-r--r--components/libc/posix/libdl/SConscript12
-rw-r--r--components/libc/posix/libdl/arch/arm.c (renamed from components/libc/libdl/arch/arm.c)4
-rw-r--r--components/libc/posix/libdl/arch/riscv.c60
-rw-r--r--components/libc/posix/libdl/arch/x86.c (renamed from components/libc/libdl/arch/x86.c)10
-rw-r--r--components/libc/posix/libdl/dlclose.c (renamed from components/libc/libdl/dlclose.c)2
-rw-r--r--components/libc/posix/libdl/dlelf.c (renamed from components/libc/libdl/dlelf.c)114
-rw-r--r--components/libc/posix/libdl/dlelf.h (renamed from components/libc/libdl/dlelf.h)110
-rw-r--r--components/libc/posix/libdl/dlerror.c (renamed from components/libc/libdl/dlerror.c)6
-rw-r--r--components/libc/posix/libdl/dlfcn.h (renamed from components/libc/libdl/dlfcn.h)4
-rw-r--r--components/libc/posix/libdl/dlmodule.c (renamed from components/libc/libdl/dlmodule.c)28
-rw-r--r--components/libc/posix/libdl/dlmodule.h (renamed from components/libc/libdl/dlmodule.h)2
-rw-r--r--components/libc/posix/libdl/dlopen.c (renamed from components/libc/libdl/dlopen.c)6
-rw-r--r--components/libc/posix/libdl/dlsym.c (renamed from components/libc/libdl/dlsym.c)4
-rw-r--r--components/libc/posix/libdl/dlsyms.c (renamed from components/libc/compilers/newlib/libc_syms.c)7
-rw-r--r--components/libc/posix/pthreads/SConscript9
-rw-r--r--components/libc/posix/pthreads/posix_types.h (renamed from components/libc/pthreads/posix_types.h)14
-rw-r--r--components/libc/posix/pthreads/pthread.c (renamed from components/libc/pthreads/pthread.c)156
-rw-r--r--components/libc/posix/pthreads/pthread.h (renamed from components/libc/pthreads/pthread.h)32
-rw-r--r--components/libc/posix/pthreads/pthread_attr.c (renamed from components/libc/pthreads/pthread_attr.c)26
-rw-r--r--components/libc/posix/pthreads/pthread_barrier.c (renamed from components/libc/pthreads/pthread_barrier.c)2
-rw-r--r--components/libc/posix/pthreads/pthread_cond.c (renamed from components/libc/pthreads/pthread_cond.c)12
-rw-r--r--components/libc/posix/pthreads/pthread_internal.h (renamed from components/libc/pthreads/pthread_internal.h)9
-rw-r--r--components/libc/posix/pthreads/pthread_mutex.c (renamed from components/libc/pthreads/pthread_mutex.c)48
-rw-r--r--components/libc/posix/pthreads/pthread_rwlock.c (renamed from components/libc/pthreads/pthread_rwlock.c)10
-rw-r--r--components/libc/posix/pthreads/pthread_spin.c (renamed from components/libc/pthreads/pthread_spin.c)2
-rw-r--r--components/libc/posix/pthreads/pthread_tls.c (renamed from components/libc/pthreads/pthread_tls.c)7
-rw-r--r--components/libc/posix/pthreads/sched.c (renamed from components/libc/pthreads/sched.c)17
-rw-r--r--components/libc/posix/pthreads/sched.h (renamed from components/libc/pthreads/sched.h)3
-rw-r--r--components/libc/posix/readme.md11
-rw-r--r--components/libc/posix/signal/SConscript (renamed from components/libc/mmap/SConscript)4
-rw-r--r--components/libc/posix/signal/posix_signal.c (renamed from components/libc/signal/posix_signal.c)52
-rw-r--r--components/libc/posix/signal/posix_signal.h (renamed from components/libc/signal/posix_signal.h)3
-rw-r--r--components/libc/pthreads/SConscript22
-rw-r--r--components/libc/signal/SConscript13
-rw-r--r--components/libc/termios/SConscript13
-rw-r--r--components/libc/time/clock_time.c188
-rw-r--r--components/libc/time/clock_time.h52
-rw-r--r--components/libc/time/posix_sleep.c30
182 files changed, 5522 insertions, 4966 deletions
diff --git a/components/libc/Kconfig b/components/libc/Kconfig
index 65c8d44225..71547e7970 100644
--- a/components/libc/Kconfig
+++ b/components/libc/Kconfig
@@ -1,62 +1,10 @@
menu "POSIX layer and C standard library"
-config RT_USING_LIBC
- bool "Enable libc APIs from toolchain"
- default y
-
-config RT_USING_PTHREADS
- bool "Enable pthreads APIs"
- default n
-
-if RT_USING_PTHREADS
- config PTHREAD_NUM_MAX
- int "Maximum number of pthreads"
+config RT_LIBC_DEFAULT_TIMEZONE
+ int "Set the default time zone (UTC+)"
+ range -12 12
default 8
-endif
-
-if RT_USING_LIBC && RT_USING_DFS
- config RT_USING_POSIX
- bool "Enable POSIX layer for poll/select, stdin etc"
- select RT_USING_DFS_DEVFS
- default y
-
- if RT_USING_POSIX
- config RT_USING_POSIX_MMAP
- bool "Enable mmap() API"
- default n
-
- config RT_USING_POSIX_TERMIOS
- bool "Enable termios APIs"
- default n
-
- config RT_USING_POSIX_GETLINE
- bool "Enable getline()/getdelim() APIs"
- default n
-
- config RT_USING_POSIX_AIO
- bool "Enable AIO"
- default n
- endif
-
-endif
-
-if RT_USING_LIBC
- config RT_USING_MODULE
- bool "Enable dynamic module with dlopen/dlsym/dlclose feature"
- default n
-
- if RT_USING_MODULE
- config RT_USING_CUSTOM_DLMODULE
- bool "Enable load dynamic module by custom"
- default n
- endif
-
-endif
-if RT_USING_LIBC != y
- config RT_LIBC_USING_TIME
- bool "Enable TIME FUNCTIONS WITHOUT COMPILER'S LIBC"
- default y
-endif
+source "$RTT_DIR/components/libc/posix/Kconfig"
endmenu
diff --git a/components/libc/aio/SConscript b/components/libc/aio/SConscript
deleted file mode 100644
index f10462e9c4..0000000000
--- a/components/libc/aio/SConscript
+++ /dev/null
@@ -1,11 +0,0 @@
-# RT-Thread building script for component
-
-from building import *
-
-cwd = GetCurrentDir()
-src = Glob('*.c') + Glob('*.cpp')
-CPPPATH = [cwd]
-
-group = DefineGroup('libc', src, depend = ['RT_USING_POSIX', 'RT_USING_POSIX_AIO'], CPPPATH = CPPPATH)
-
-Return('group')
diff --git a/components/libc/compilers/armlibc/README.md b/components/libc/compilers/armlibc/README.md
index 4d2a73b6be..fc0d750234 100644
--- a/components/libc/compilers/armlibc/README.md
+++ b/components/libc/compilers/armlibc/README.md
@@ -1,9 +1,3 @@
# ARMLIB (Keil-MDK) porting for RT-Thread
-Please define RT_USING_LIBC and compile RT-Thread with Keil-MDK compiler.
-
-
-
-## More Information
-
https://www.keil.com/support/man/docs/armlib/ \ No newline at end of file
diff --git a/components/libc/compilers/armlibc/SConscript b/components/libc/compilers/armlibc/SConscript
index 52f7a6d93a..bd3ac8dffc 100644
--- a/components/libc/compilers/armlibc/SConscript
+++ b/components/libc/compilers/armlibc/SConscript
@@ -1,21 +1,12 @@
from building import *
Import('rtconfig')
-src = Glob('*.c') + Glob('*.cpp')
-cwd = GetCurrentDir()
+src = Glob('*.c')
group = []
-CPPPATH = [cwd]
CPPDEFINES = ['RT_USING_ARM_LIBC']
-if GetDepend('RT_USING_DFS') == False:
- SrcRemove(src, ['stdio.c'])
-
-if GetDepend('RT_USING_MODULE') == False:
- SrcRemove(src, ['libc_syms.c'])
-
if rtconfig.PLATFORM == 'armcc' or rtconfig.PLATFORM == 'armclang':
- group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'],
- CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
+ group = DefineGroup('Compiler', src, depend = [''], CPPDEFINES = CPPDEFINES)
Return('group')
diff --git a/components/libc/compilers/armlibc/dirent.h b/components/libc/compilers/armlibc/dirent.h
deleted file mode 100644
index d3bc58cbc5..0000000000
--- a/components/libc/compilers/armlibc/dirent.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __RTT_DIRENT_H__
-#define __RTT_DIRENT_H__
-
-#include <rtthread.h>
-#include <rtlibc.h>
-
-/*
-* dirent.h - format of directory entries
- * Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html
- */
-
-/* File types */
-#define FT_REGULAR 0 /* regular file */
-#define FT_SOCKET 1 /* socket file */
-#define FT_DIRECTORY 2 /* directory */
-#define FT_USER 3 /* user defined */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef HAVE_DIR_STRUCTURE
-typedef struct
-{
- int fd; /* directory file */
- char buf[512];
- int num;
- int cur;
-} DIR;
-#endif
-
-#ifndef HAVE_DIRENT_STRUCTURE
-struct dirent
-{
- rt_uint8_t d_type; /* The type of the file */
- rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */
- rt_uint16_t d_reclen; /* length of this record */
- char d_name[256]; /* The null-terminated file name */
-};
-#endif
-
-int closedir(DIR *);
-DIR *opendir(const char *);
-struct dirent *readdir(DIR *);
-int readdir_r(DIR *, struct dirent *, struct dirent **);
-void rewinddir(DIR *);
-void seekdir(DIR *, long int);
-long telldir(DIR *);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/components/libc/compilers/armlibc/fcntl.h b/components/libc/compilers/armlibc/fcntl.h
deleted file mode 100644
index 3e650a8471..0000000000
--- a/components/libc/compilers/armlibc/fcntl.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef FCNTL_H__
-#define FCNTL_H__
-
-#include <rtconfig.h>
-
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
-
-#endif
diff --git a/components/libc/compilers/armlibc/libc.c b/components/libc/compilers/armlibc/libc.c
deleted file mode 100644
index fee390d4b4..0000000000
--- a/components/libc/compilers/armlibc/libc.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/10/15 bernard the first version
- */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <rtthread.h>
-
-#include "libc.h"
-
-#ifdef RT_USING_PTHREADS
-#include <pthread.h>
-#endif
-
-int libc_system_init(void)
-{
-#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS)
- rt_device_t dev_console;
-
- dev_console = rt_console_get_device();
- if (dev_console)
- {
- #if defined(RT_USING_POSIX)
- libc_stdio_set_console(dev_console->parent.name, O_RDWR);
- #else
- libc_stdio_set_console(dev_console->parent.name, O_WRONLY);
- #endif
- }
-#endif
-
-#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT
- pthread_system_init();
-#endif
-
- return 0;
-}
-INIT_COMPONENT_EXPORT(libc_system_init);
diff --git a/components/libc/compilers/armlibc/libc.h b/components/libc/compilers/armlibc/libc.h
deleted file mode 100644
index b9b1b6212d..0000000000
--- a/components/libc/compilers/armlibc/libc.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/10/15 bernard the first version
- */
-#ifndef __RTT_LIBC_H__
-#define __RTT_LIBC_H__
-
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-int libc_system_init(void);
-
-int libc_stdio_set_console(const char* device_name, int mode);
-int libc_stdio_get_console(void);
-int libc_stdio_read(void* buffer, size_t size);
-int libc_stdio_write(const void* buffer, size_t size);
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/components/libc/compilers/armlibc/libc_syms.c b/components/libc/compilers/armlibc/libc_syms.c
deleted file mode 100644
index 0e1c42d899..0000000000
--- a/components/libc/compilers/armlibc/libc_syms.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <time.h>
-
-#include <rtm.h>
-
-/* some export routines for module */
-
-RTM_EXPORT(strstr);
-RTM_EXPORT(strlen);
-RTM_EXPORT(strchr);
-RTM_EXPORT(strcpy);
-RTM_EXPORT(strncpy);
-RTM_EXPORT(strcmp);
-RTM_EXPORT(strncmp);
-RTM_EXPORT(strcat);
-RTM_EXPORT(strtol);
-
-RTM_EXPORT(memcpy);
-RTM_EXPORT(memcmp);
-RTM_EXPORT(memmove);
-RTM_EXPORT(memset);
-RTM_EXPORT(memchr);
-
-RTM_EXPORT(toupper);
-RTM_EXPORT(atoi);
-
-#ifdef RT_USING_RTC
-RTM_EXPORT(localtime);
-RTM_EXPORT(time);
-#endif
-
-/* import the full stdio for printf */
-#if defined(RT_USING_MODULE) && defined(__MICROLIB)
-#error "[RT_USING_LIBC] Please use standard libc but not microlib."
-#endif
-
-RTM_EXPORT(puts);
-RTM_EXPORT(printf);
diff --git a/components/libc/compilers/armlibc/mem_std.c b/components/libc/compilers/armlibc/mem_std.c
deleted file mode 100644
index e160104a25..0000000000
--- a/components/libc/compilers/armlibc/mem_std.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * 2014-08-03 bernard Add file header.
- */
-
-#include "rtthread.h"
-
-#ifdef RT_USING_HEAP
-
-#ifdef __CC_ARM
-/* avoid the heap and heap-using library functions supplied by arm */
-#pragma import(__use_no_heap)
-#endif
-
-void *malloc(size_t n)
-{
- return rt_malloc(n);
-}
-RTM_EXPORT(malloc);
-
-void *realloc(void *rmem, size_t newsize)
-{
- return rt_realloc(rmem, newsize);
-}
-RTM_EXPORT(realloc);
-
-void *calloc(size_t nelem, size_t elsize)
-{
- return rt_calloc(nelem, elsize);
-}
-RTM_EXPORT(calloc);
-
-void free(void *rmem)
-{
- rt_free(rmem);
-}
-RTM_EXPORT(free);
-#endif
diff --git a/components/libc/compilers/armlibc/stdio.c b/components/libc/compilers/armlibc/stdio.c
deleted file mode 100644
index 5262a4dd92..0000000000
--- a/components/libc/compilers/armlibc/stdio.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/10/15 bernard implement stdio for armcc.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <rtthread.h>
-#include "libc.h"
-
-#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS)
-#include <dfs_posix.h>
-
-#define STDIO_DEVICE_NAME_MAX 32
-
-static int std_fd = -1;
-int libc_stdio_set_console(const char* device_name, int mode)
-{
- int fd;
- char name[STDIO_DEVICE_NAME_MAX];
-
- snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
- name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
-
- fd = open(name, mode, 0);
- if (fd >= 0)
- {
- if (std_fd >= 0)
- {
- close(std_fd);
- }
- std_fd = fd;
- }
-
- return std_fd;
-}
-
-int libc_stdio_get_console(void)
-{
- return std_fd;
-}
-
-int libc_stdio_read(void *buffer, size_t size)
-{
- if (std_fd >= 0)
- {
- return read(std_fd, buffer, size);
- }
- else
- {
- rt_kprintf("Illegal stdio input!\n");
- return 0;
- }
-}
-
-int libc_stdio_write(const void *buffer, size_t size)
-{
- if (std_fd >= 0)
- {
- return write(std_fd, buffer, size);
- }
- else
- {
- rt_kprintf("Illegal stdio output!\n");
- return size;
- }
-}
-#endif
diff --git a/components/libc/compilers/armlibc/sys/README.md b/components/libc/compilers/armlibc/sys/README.md
deleted file mode 100644
index 7ad10a7d43..0000000000
--- a/components/libc/compilers/armlibc/sys/README.md
+++ /dev/null
@@ -1 +0,0 @@
-Because Keil MDK leaks some system header file, we put them in here. \ No newline at end of file
diff --git a/components/libc/compilers/armlibc/sys/errno.h b/components/libc/compilers/armlibc/sys/errno.h
deleted file mode 100644
index 9c4307ebfb..0000000000
--- a/components/libc/compilers/armlibc/sys/errno.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef SYS_ERRNO_H__
-#define SYS_ERRNO_H__
-
-#include <rtthread.h>
-
-#endif
diff --git a/components/libc/compilers/armlibc/sys/ioctl.h b/components/libc/compilers/armlibc/sys/ioctl.h
deleted file mode 100644
index 033a57014a..0000000000
--- a/components/libc/compilers/armlibc/sys/ioctl.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2020-09-01 Meco Man First Version
- */
-#ifndef _SYS_IOCTL_H
-#define _SYS_IOCTL_H
-
-
-
-#endif
diff --git a/components/libc/compilers/armlibc/sys/mman.h b/components/libc/compilers/armlibc/sys/mman.h
deleted file mode 100644
index 8c61b32b7c..0000000000
--- a/components/libc/compilers/armlibc/sys/mman.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/11/30 Bernard The first version.
- */
-
-#ifndef _SYS_MMAN_H
-#define _SYS_MMAN_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MAP_FAILED ((void *) -1)
-
-#define MAP_SHARED 0x01
-#define MAP_PRIVATE 0x02
-#define MAP_TYPE 0x0f
-#define MAP_FIXED 0x10
-#define MAP_ANON 0x20
-#define MAP_ANONYMOUS MAP_ANON
-#define MAP_NORESERVE 0x4000
-#define MAP_GROWSDOWN 0x0100
-#define MAP_DENYWRITE 0x0800
-#define MAP_EXECUTABLE 0x1000
-#define MAP_LOCKED 0x2000
-#define MAP_POPULATE 0x8000
-#define MAP_NONBLOCK 0x10000
-#define MAP_STACK 0x20000
-#define MAP_HUGETLB 0x40000
-#define MAP_FILE 0
-
-#define PROT_NONE 0
-#define PROT_READ 1
-#define PROT_WRITE 2
-#define PROT_EXEC 4
-#define PROT_GROWSDOWN 0x01000000
-#define PROT_GROWSUP 0x02000000
-
-#define MS_ASYNC 1
-#define MS_INVALIDATE 2
-#define MS_SYNC 4
-
-#define MCL_CURRENT 1
-#define MCL_FUTURE 2
-#define MCL_ONFAULT 4
-
-void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off);
-int munmap (void *start, size_t len);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/components/libc/compilers/armlibc/sys/stat.h b/components/libc/compilers/armlibc/sys/stat.h
deleted file mode 100644
index ce95230e88..0000000000
--- a/components/libc/compilers/armlibc/sys/stat.h
+++ /dev/null
@@ -1,8 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
diff --git a/components/libc/compilers/armlibc/sys/unistd.h b/components/libc/compilers/armlibc/sys/unistd.h
deleted file mode 100644
index 73a73a267e..0000000000
--- a/components/libc/compilers/armlibc/sys/unistd.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2020-12-16 Meco Man add usleep
- */
-#ifndef _SYS_UNISTD_H
-#define _SYS_UNISTD_H
-
-#include <rtconfig.h>
-#include "types.h"
-
-#ifdef RT_USING_DFS
-
-#define STDIN_FILENO 0 /* standard input file descriptor */
-#define STDOUT_FILENO 1 /* standard output file descriptor */
-#define STDERR_FILENO 2 /* standard error file descriptor */
-
-#include <dfs_posix.h>
-#else
-#define _FREAD 0x0001 /* read enabled */
-#define _FWRITE 0x0002 /* write enabled */
-#define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */
-#define _FMARK 0x0010 /* internal; mark during gc() */
-#define _FDEFER 0x0020 /* internal; defer for next gc pass */
-#define _FASYNC 0x0040 /* signal pgrp when data ready */
-#define _FSHLOCK 0x0080 /* BSD flock() shared lock present */
-#define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */
-#define _FCREAT 0x0200 /* open with file create */
-#define _FTRUNC 0x0400 /* open with truncation */
-#define _FEXCL 0x0800 /* error on open if file exists */
-#define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */
-#define _FSYNC 0x2000 /* do all writes synchronously */
-#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */
-#define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */
-#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */
-
-
-#ifndef O_RDONLY
-#define O_RDONLY 0 /* +1 == FREAD */
-#endif
-#ifndef O_WRONLY
-#define O_WRONLY 1 /* +1 == FWRITE */
-#endif
-#ifndef O_RDWR
-#define O_RDWR 2 /* +1 == FREAD|FWRITE */
-#endif
-#ifndef O_APPEND
-#define O_APPEND _FAPPEND
-#endif
-#ifndef O_CREAT
-#define O_CREAT _FCREAT
-#endif
-#ifndef O_TRUNC
-#define O_TRUNC _FTRUNC
-#endif
-#ifndef O_EXCL
-#define O_EXCL _FEXCL
-#endif
-#ifndef O_SYNC
-#define O_SYNC _FSYNC
-#endif
-
-#endif
-
-
-int isatty (int fd);
-char * ttyname (int desc);
-
-unsigned int sleep(unsigned int seconds);
-int usleep(useconds_t usec);
-
-#endif /* _SYS_UNISTD_H */
diff --git a/components/libc/compilers/armlibc/syscall_mem.c b/components/libc/compilers/armlibc/syscall_mem.c
new file mode 100644
index 0000000000..b5403dfaf3
--- /dev/null
+++ b/components/libc/compilers/armlibc/syscall_mem.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2014-08-03 bernard Add file header
+ * 2021-11-13 Meco Man implement no-heap warning
+ */
+
+#include <rtthread.h>
+#include <stddef.h>
+
+#ifndef RT_USING_HEAP
+#define DBG_TAG "armlibc.syscall.mem"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
+#define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\
+ RT_ASSERT(0);\
+ }while(0)
+#endif /* RT_USING_HEAP */
+
+#ifdef __CC_ARM
+/* avoid the heap and heap-using library functions supplied by arm */
+#pragma import(__use_no_heap)
+#endif /* __CC_ARM */
+
+void *malloc(size_t n)
+{
+#ifdef RT_USING_HEAP
+ return rt_malloc(n);
+#else
+ _NO_HEAP_ERROR();
+ return RT_NULL;
+#endif
+}
+RTM_EXPORT(malloc);
+
+void *realloc(void *rmem, size_t newsize)
+{
+#ifdef RT_USING_HEAP
+ return rt_realloc(rmem, newsize);
+#else
+ _NO_HEAP_ERROR();
+ return RT_NULL;
+#endif
+}
+RTM_EXPORT(realloc);
+
+void *calloc(size_t nelem, size_t elsize)
+{
+#ifdef RT_USING_HEAP
+ return rt_calloc(nelem, elsize);
+#else
+ _NO_HEAP_ERROR();
+ return RT_NULL;
+#endif
+}
+RTM_EXPORT(calloc);
+
+void free(void *rmem)
+{
+#ifdef RT_USING_HEAP
+ rt_free(rmem);
+#else
+ _NO_HEAP_ERROR();
+#endif
+}
+RTM_EXPORT(free);
diff --git a/components/libc/compilers/armlibc/stubs.c b/components/libc/compilers/armlibc/syscalls.c
index b4cc13799e..82c0f38b4f 100644
--- a/components/libc/compilers/armlibc/stubs.c
+++ b/components/libc/compilers/armlibc/syscalls.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -9,21 +9,28 @@
* 2013-11-24 aozima fixed _sys_read()/_sys_write() issues.
* 2014-08-03 bernard If using msh, use system() implementation
* in msh.
- * 2020-08-05 Meco Man fixed _sys_flen() compiling-warning when
+ * 2020-08-05 Meco Man fixed _sys_flen() compiling-warning when
* RT_USING_DFS is not defined
+ * 2020-02-13 Meco Man re-implement exit() and abort()
+ * 2020-02-14 Meco Man implement _sys_tmpnam()
*/
-#include <string.h>
#include <rt_sys.h>
-
-#include "rtthread.h"
+#include <rtthread.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <compiler_private.h>
+#ifdef RT_USING_POSIX_STDIO
#include "libc.h"
+#endif /* RT_USING_POSIX_STDIO */
-#ifdef RT_USING_DFS
-#include "dfs_posix.h"
-#endif
+#define DBG_TAG "armlibc.syscalls"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
-#ifdef __CLANG_ARM
+#ifdef __clang__
__asm(".global __use_no_semihosting\n\t");
#else
#pragma import(__use_no_semihosting_swi)
@@ -49,10 +56,10 @@ const char __stderr_name[] = "STDERR";
*/
FILEHANDLE _sys_open(const char *name, int openmode)
{
-#ifdef RT_USING_DFS
+#ifdef DFS_USING_POSIX
int fd;
int mode = O_RDONLY;
-#endif
+#endif /* DFS_USING_POSIX */
/* Register standard Input Output devices. */
if (strcmp(name, __stdin_name) == 0)
@@ -62,8 +69,9 @@ FILEHANDLE _sys_open(const char *name, int openmode)
if (strcmp(name, __stderr_name) == 0)
return (STDERR);
-#ifndef RT_USING_DFS
- return -1;
+#ifndef DFS_USING_POSIX
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
+ return 0; /* error */
#else
/* Correct openmode from fopen to open */
if (openmode & OPEN_PLUS)
@@ -93,21 +101,23 @@ FILEHANDLE _sys_open(const char *name, int openmode)
fd = open(name, mode, 0);
if (fd < 0)
- return -1;
+ return 0; /* error */
else
return fd;
-#endif
+#endif /* DFS_USING_POSIX */
}
int _sys_close(FILEHANDLE fh)
{
-#ifndef RT_USING_DFS
- return 0;
-#else
- if (fh <= STDERR) return 0;
+#ifdef DFS_USING_POSIX
+ if (fh <= STDERR)
+ return 0; /* error */
return close(fh);
-#endif
+#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
+ return 0;
+#endif /* DFS_USING_POSIX */
}
/*
@@ -137,77 +147,96 @@ int _sys_close(FILEHANDLE fh)
*/
int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
{
-#ifdef RT_USING_DFS
+#ifdef DFS_USING_POSIX
int size;
-#endif
if (fh == STDIN)
{
-#ifdef RT_USING_POSIX
- size = libc_stdio_read(buf, len);
- return len - size;
+#ifdef RT_USING_POSIX_STDIO
+ if (libc_stdio_get_console() < 0)
+ {
+ LOG_W("Do not invoke standard output before initializing Compiler");
+ return 0; /* error, but keep going */
+ }
+ size = read(STDIN_FILENO, buf, len);
+ return len - size; /* success */
#else
- /* no stdin */
- return -1;
-#endif
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_STDIO);
+ return 0; /* error */
+#endif /* RT_USING_POSIX_STDIO */
+ }
+ else if (fh == STDOUT || fh == STDERR)
+ {
+ return -1; /* 100% error */
}
-
- if ((fh == STDOUT) || (fh == STDERR))
- return -1;
-
-#ifndef RT_USING_DFS
- return 0;
-#else
- size = read(fh, buf, len);
- if (size >= 0)
- return len - size;
else
- return -1;
-#endif
+ {
+ size = read(fh, buf, len);
+ if (size >= 0)
+ {
+ return len - size; /* success */
+ }
+ else
+ {
+ return 0; /* error */
+ }
+ }
+#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
+ return 0; /* error */
+#endif /* DFS_USING_POSIX */
}
/*
* Write to a file. Returns 0 on success, negative on error, and
* the number of characters _not_ written on partial success.
* `mode' exists for historical reasons and must be ignored.
+ * The return value is either:
+ * A positive number representing the number of characters not written
+ * (so any nonzero return value denotes a failure of some sort).
+ * A negative number indicating an error.
*/
int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
{
-#ifdef RT_USING_DFS
+#ifdef DFS_USING_POSIX
int size;
-#endif
+#endif /* DFS_USING_POSIX */
- if ((fh == STDOUT) || (fh == STDERR))
+ if (fh == STDOUT || fh == STDERR)
{
-#if !defined(RT_USING_CONSOLE) || !defined(RT_USING_DEVICE)
- return 0;
-#else
-#ifdef RT_USING_POSIX
- size = libc_stdio_write(buf, len);
- return len - size;
-#else
- if (rt_console_get_device())
+#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
+ rt_device_t console;
+ console = rt_console_get_device();
+ if (console)
{
- rt_device_write(rt_console_get_device(), -1, buf, len);
- return 0;
+ rt_device_write(console, -1, buf, len);
}
-
- return -1;
-#endif
-#endif
- }
-
- if (fh == STDIN) return -1;
-
-#ifndef RT_USING_DFS
- return 0;
+ return 0; /* success */
#else
- size = write(fh, buf, len);
- if (size >= 0)
- return len - size;
+ return 0; /* error */
+#endif /* defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) */
+ }
+ else if (fh == STDIN)
+ {
+ return -1; /* 100% error */
+ }
else
- return -1;
-#endif
+ {
+#ifdef DFS_USING_POSIX
+ size = write(fh, buf, len);
+ if (size >= 0)
+ {
+ return len - size; /* success */
+ }
+ else
+ {
+ return 0; /* error */
+ }
+#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
+ return 0; /* error */
+#endif /* DFS_USING_POSIX */
+ }
}
/*
@@ -216,16 +245,16 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
*/
int _sys_seek(FILEHANDLE fh, long pos)
{
+#ifdef DFS_USING_POSIX
if (fh < STDERR)
- return -1;
-
-#ifndef RT_USING_DFS
- return -1;
-#else
+ return 0; /* error */
/* position is relative to the start of file fh */
return lseek(fh, pos, 0);
-#endif
+#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
+ return 0; /* error */
+#endif /* DFS_USING_POSIX */
}
/**
@@ -233,7 +262,8 @@ int _sys_seek(FILEHANDLE fh, long pos)
*/
int _sys_tmpnam(char *name, int fileno, unsigned maxlength)
{
- return -1;
+ rt_snprintf(name, maxlength, "tem%03d", fileno);
+ return 1;
}
char *_sys_command_string(char *cmd, int len)
@@ -246,17 +276,16 @@ char *_sys_command_string(char *cmd, int len)
void _ttywrch(int ch)
{
#ifdef RT_USING_CONSOLE
- char c;
-
- c = (char)ch;
- rt_kprintf(&c);
-#endif
+ rt_kprintf("%c", (char)ch);
+#endif /* RT_USING_CONSOLE */
}
+/* for exit() and abort() */
RT_WEAK void _sys_exit(int return_code)
{
- /* TODO: perhaps exit the thread which is invoking this function */
- while (1);
+ extern void __rt_libc_exit(int status);
+ __rt_libc_exit(return_code);
+ while(1);
}
/**
@@ -267,17 +296,18 @@ RT_WEAK void _sys_exit(int return_code)
*/
long _sys_flen(FILEHANDLE fh)
{
-#ifdef RT_USING_DFS
+#ifdef DFS_USING_POSIX
struct stat stat;
if (fh < STDERR)
- return -1;
+ return 0; /* error */
fstat(fh, &stat);
return stat.st_size;
#else
- return -1;
-#endif
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
+ return 0;
+#endif /* DFS_USING_POSIX */
}
int _sys_istty(FILEHANDLE fh)
@@ -290,44 +320,43 @@ int _sys_istty(FILEHANDLE fh)
int remove(const char *filename)
{
-#ifndef RT_USING_DFS
- return -1;
-#else
+#ifdef DFS_USING_POSIX
return unlink(filename);
-#endif
-}
-
-#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) && defined(RT_USING_MODULE) && defined(RT_USING_DFS)
-/* use system(const char *string) implementation in the msh */
#else
-int system(const char *string)
-{
- RT_ASSERT(0);
- for (;;);
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
+ return 0; /* error */
+#endif /* DFS_USING_POSIX */
}
-#endif
#ifdef __MICROLIB
#include <stdio.h>
-int fputc(int c, FILE *f)
+int fputc(int c, FILE *f)
{
- char ch[2] = {0};
-
- ch[0] = c;
- rt_kprintf(&ch[0]);
+#ifdef RT_USING_CONSOLE
+ rt_kprintf("%c", (char)c);
return 1;
+#else
+ return 0; /* error */
+#endif /* RT_USING_CONSOLE */
}
-int fgetc(FILE *f)
+int fgetc(FILE *f)
{
-#ifdef RT_USING_POSIX
+#ifdef RT_USING_POSIX_STDIO
char ch;
- if (libc_stdio_read(&ch, 1) == 1)
- return ch;
-#endif
+ if (libc_stdio_get_console() < 0)
+ {
+ LOG_W("Do not invoke standard output before initializing Compiler");
+ return 0;
+ }
- return -1;
+ if(read(STDIN_FILENO, &ch, 1) == 1)
+ return ch;
+#endif /* RT_USING_POSIX_STDIO */
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_STDIO);
+ return 0; /* error */
}
-#endif
+
+#endif /* __MICROLIB */
diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript
index 2407301405..8db8f2c94a 100644
--- a/components/libc/compilers/common/SConscript
+++ b/components/libc/compilers/common/SConscript
@@ -1,22 +1,22 @@
from building import *
-
Import('rtconfig')
src = []
cwd = GetCurrentDir()
group = []
CPPPATH = [cwd]
+CPPDEFINES = []
+
+if rtconfig.CROSS_TOOL == 'keil':
+ CPPDEFINES += ['__CLK_TCK=RT_TICK_PER_SECOND']
-if GetDepend('RT_USING_LIBC'):
- src += Glob('*.c')
-else:
- if GetDepend('RT_LIBC_USING_TIME') and not GetDepend('RT_USING_MINILIBC'):
- src += ['time.c']
+src += Glob('*.c')
-if GetDepend('RT_USING_POSIX') == False:
- SrcRemove(src, ['unistd.c'])
+group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
-if not GetDepend('RT_USING_MINILIBC') and (GetDepend('RT_USING_LIBC') or GetDepend('RT_LIBC_USING_TIME')):
- group = DefineGroup('libc', src, depend = [''], CPPPATH = CPPPATH)
+list = os.listdir(cwd)
+for item in list:
+ if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
+ group = group + SConscript(os.path.join(item, 'SConscript'))
Return('group')
diff --git a/components/libc/compilers/common/compiler_private.h b/components/libc/compilers/common/compiler_private.h
new file mode 100644
index 0000000000..7f6b42e837
--- /dev/null
+++ b/components/libc/compilers/common/compiler_private.h
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-12-26 Meco Man First Version
+ */
+
+#ifndef __COMPILER_PRIVATE_H__
+#define __COMPILER_PRIVATE_H__
+
+#define _WARNING_WITHOUT_FS "Please enable RT_USING_POSIX_FS"
+#define _WARNING_WITHOUT_STDIO "Please enable RT_USING_POSIX_FS and RT_USING_POSIX_STDIO"
+
+#endif /* __COMPILER_PRIVATE_H__ */
diff --git a/components/libc/compilers/dlib/dirent.h b/components/libc/compilers/common/dirent.h
index 4c897cc550..a9c7ef856d 100644
--- a/components/libc/compilers/dlib/dirent.h
+++ b/components/libc/compilers/common/dirent.h
@@ -1,16 +1,20 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
-#ifndef __RTT_DIRENT_H__
-#define __RTT_DIRENT_H__
-#include <rtthread.h>
-#include <rtlibc.h>
+#ifndef __DIRENT_H__
+#define __DIRENT_H__
+
+#include <rtdef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
/*
* dirent.h - format of directory entries
@@ -23,27 +27,32 @@
#define FT_DIRECTORY 2 /* directory */
#define FT_USER 3 /* user defined */
-#ifdef __cplusplus
-extern "C" {
-#endif
+#define DT_UNKNOWN 0x00
+#define DT_REG 0x01
+#define DT_DIR 0x02
#ifndef HAVE_DIR_STRUCTURE
+#define HAVE_DIR_STRUCTURE
typedef struct
{
int fd; /* directory file */
char buf[512];
int num;
int cur;
-} DIR;
+}DIR;
#endif
#ifndef HAVE_DIRENT_STRUCTURE
+#define HAVE_DIRENT_STRUCTURE
+
+#define DIRENT_NAME_MAX 256
+
struct dirent
{
rt_uint8_t d_type; /* The type of the file */
rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */
rt_uint16_t d_reclen; /* length of this record */
- char d_name[256]; /* The null-terminated file name */
+ char d_name[DIRENT_NAME_MAX]; /* The null-terminated file name */
};
#endif
diff --git a/components/libc/compilers/common/extension/SConscript b/components/libc/compilers/common/extension/SConscript
new file mode 100644
index 0000000000..dbc26ac177
--- /dev/null
+++ b/components/libc/compilers/common/extension/SConscript
@@ -0,0 +1,14 @@
+from building import *
+
+Import('rtconfig')
+
+src = []
+cwd = GetCurrentDir()
+CPPPATH = [cwd]
+group = []
+
+src += Glob('*.c')
+
+if rtconfig.PLATFORM != 'gcc' or rtconfig.ARCH == 'sim':
+ group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH)
+Return('group')
diff --git a/components/libc/compilers/common/extension/fcntl.h b/components/libc/compilers/common/extension/fcntl.h
new file mode 100644
index 0000000000..ac642abcbb
--- /dev/null
+++ b/components/libc/compilers/common/extension/fcntl.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-09-02 Meco Man First version
+ */
+
+#ifndef __FCNTL_H__
+#define __FCNTL_H__
+
+#include "sys/types.h"
+
+#define O_RDONLY 00
+#define O_WRONLY 01
+#define O_RDWR 02
+
+#define O_CREAT 0100
+#define O_EXCL 0200
+#define O_NOCTTY 0400
+#define O_TRUNC 01000
+#define O_APPEND 02000
+#define O_NONBLOCK 04000
+#define O_DSYNC 010000
+#define O_SYNC 04010000
+#define O_RSYNC 04010000
+#define O_BINARY 0100000
+#define O_DIRECTORY 0200000
+#define O_NOFOLLOW 0400000
+#define O_CLOEXEC 02000000
+
+#define O_ASYNC 020000
+#define O_DIRECT 040000
+#define O_LARGEFILE 0100000
+#define O_NOATIME 01000000
+#define O_PATH 010000000
+#define O_TMPFILE 020200000
+#define O_NDELAY O_NONBLOCK
+
+#define O_SEARCH O_PATH
+#define O_EXEC O_PATH
+
+#define O_ACCMODE (03|O_SEARCH)
+
+#define F_DUPFD 0
+#define F_GETFD 1
+#define F_SETFD 2
+#define F_GETFL 3
+#define F_SETFL 4
+
+#define F_SETOWN 8
+#define F_GETOWN 9
+#define F_SETSIG 10
+#define F_GETSIG 11
+
+#define F_GETLK 12
+#define F_SETLK 13
+#define F_SETLKW 14
+
+#define F_SETOWN_EX 15
+#define F_GETOWN_EX 16
+
+#define F_GETOWNER_UIDS 17
+
+int open(const char *file, int flags, ...);
+int fcntl(int fildes, int cmd, ...);
+int creat(const char *path, mode_t mode);
+
+#endif
diff --git a/components/libc/compilers/common/extension/readme.md b/components/libc/compilers/common/extension/readme.md
new file mode 100644
index 0000000000..ca0df69246
--- /dev/null
+++ b/components/libc/compilers/common/extension/readme.md
@@ -0,0 +1,4 @@
+## Attentions
+
+This folder is "common" for toolchains, which only support ISO C, as an extension part, such as Keil-MDK and IAR.
+
diff --git a/components/libc/compilers/common/extension/sys/errno.h b/components/libc/compilers/common/extension/sys/errno.h
new file mode 100644
index 0000000000..d53ce4b386
--- /dev/null
+++ b/components/libc/compilers/common/extension/sys/errno.h
@@ -0,0 +1,585 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-05-22 Meco Man The first version.
+ */
+
+#ifndef __SYS_ERRNO_H__
+#define __SYS_ERRNO_H__
+
+#if defined(__ARMCC_VERSION)
+/*
+defined in armcc/errno.h
+
+#define EDOM 1
+#define ERANGE 2
+#define EILSEQ 4
+#define ESIGNUM 3
+#define EINVAL 5
+#define ENOMEM 6
+*/
+
+#define ERROR_BASE_NO 7
+
+#elif defined(__IAR_SYSTEMS_ICC__)
+/* defined in iar/errno.h
+#define EDOM 33
+#define ERANGE 34
+#define EFPOS 35
+#define EILSEQ 36
+*/
+#define ERROR_BASE_NO 36
+
+#else
+#define ERROR_BASE_NO 0
+#endif
+
+#if defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__)
+#include <errno.h>
+
+#ifndef EPERM
+#define EPERM (ERROR_BASE_NO + 1)
+#endif
+
+#ifndef ENOENT
+#define ENOENT (ERROR_BASE_NO + 2)
+#endif
+
+#ifndef ESRCH
+#define ESRCH (ERROR_BASE_NO + 3)
+#endif
+
+#ifndef EINTR
+#define EINTR (ERROR_BASE_NO + 4)
+#endif
+
+#ifndef EIO
+#define EIO (ERROR_BASE_NO + 5)
+#endif
+
+#ifndef ENXIO
+#define ENXIO (ERROR_BASE_NO + 6)
+#endif
+
+#ifndef E2BIG
+#define E2BIG (ERROR_BASE_NO + 7)
+#endif
+
+#ifndef ENOEXEC
+#define ENOEXEC (ERROR_BASE_NO + 8)
+#endif
+
+#ifndef EBADF
+#define EBADF (ERROR_BASE_NO + 9)
+#endif
+
+#ifndef ECHILD
+#define ECHILD (ERROR_BASE_NO + 10)
+#endif
+
+#ifndef EAGAIN
+#define EAGAIN (ERROR_BASE_NO + 11)
+#endif
+
+#ifndef ENOMEM
+#define ENOMEM (ERROR_BASE_NO + 12)
+#endif
+
+#ifndef EACCES
+#define EACCES (ERROR_BASE_NO + 13)
+#endif
+
+#ifndef EFAULT
+#define EFAULT (ERROR_BASE_NO + 14)
+#endif
+
+#ifndef ENOTBLK
+#define ENOTBLK (ERROR_BASE_NO + 15)
+#endif
+
+#ifndef EBUSY
+#define EBUSY (ERROR_BASE_NO + 16)
+#endif
+
+#ifndef EEXIST
+#define EEXIST (ERROR_BASE_NO + 17)
+#endif
+
+#ifndef EXDEV
+#define EXDEV (ERROR_BASE_NO + 18)
+#endif
+
+#ifndef ENODEV
+#define ENODEV (ERROR_BASE_NO + 19)
+#endif
+
+#ifndef ENOTDIR
+#define ENOTDIR (ERROR_BASE_NO + 20)
+#endif
+
+#ifndef EISDIR
+#define EISDIR (ERROR_BASE_NO + 21)
+#endif
+
+#ifndef EINVAL
+#define EINVAL (ERROR_BASE_NO + 22)
+#endif
+
+#ifndef ENFILE
+#define ENFILE (ERROR_BASE_NO + 23)
+#endif
+
+#ifndef EMFILE
+#define EMFILE (ERROR_BASE_NO + 24)
+#endif
+
+#ifndef ENOTTY
+#define ENOTTY (ERROR_BASE_NO + 25)
+#endif
+
+#ifndef ETXTBSY
+#define ETXTBSY (ERROR_BASE_NO + 26)
+#endif
+
+#ifndef EFBIG
+#define EFBIG (ERROR_BASE_NO + 27)
+#endif
+
+#ifndef ENOSPC
+#define ENOSPC (ERROR_BASE_NO + 28)
+#endif
+
+#ifndef ESPIPE
+#define ESPIPE (ERROR_BASE_NO + 29)
+#endif
+
+#ifndef EROFS
+#define EROFS (ERROR_BASE_NO + 30)
+#endif
+
+#ifndef EMLINK
+#define EMLINK (ERROR_BASE_NO + 31)
+#endif
+
+#ifndef EPIPE
+#define EPIPE (ERROR_BASE_NO + 32)
+#endif
+
+#ifndef EDOM
+#define EDOM (ERROR_BASE_NO + 33)
+#endif
+
+#ifndef ERANGE
+#define ERANGE (ERROR_BASE_NO + 34)
+#endif
+
+#ifndef EDEADLK
+#define EDEADLK (ERROR_BASE_NO + 35)
+#endif
+
+#ifndef ENAMETOOLONG
+#define ENAMETOOLONG (ERROR_BASE_NO + 36)
+#endif
+
+#ifndef ENOLCK
+#define ENOLCK (ERROR_BASE_NO + 37)
+#endif
+
+#ifndef ENOSYS
+#define ENOSYS (ERROR_BASE_NO + 38)
+#endif
+
+#ifndef ENOTEMPTY
+#define ENOTEMPTY (ERROR_BASE_NO + 39)
+#endif
+
+#ifndef ELOOP
+#define ELOOP (ERROR_BASE_NO + 40)
+#endif
+
+#ifndef EWOULDBLOCK
+#define EWOULDBLOCK EAGAIN
+#endif
+
+#ifndef ENOMSG
+#define ENOMSG (ERROR_BASE_NO + 42)
+#endif
+
+#ifndef EIDRM
+#define EIDRM (ERROR_BASE_NO + 43)
+#endif
+
+#ifndef ECHRNG
+#define ECHRNG (ERROR_BASE_NO + 44)
+#endif
+
+#ifndef EL2NSYNC
+#define EL2NSYNC (ERROR_BASE_NO + 45)
+#endif
+
+#ifndef EL3HLT
+#define EL3HLT (ERROR_BASE_NO + 46)
+#endif
+
+#ifndef EL3RST
+#define EL3RST (ERROR_BASE_NO + 47)
+#endif
+
+#ifndef ELNRNG
+#define ELNRNG (ERROR_BASE_NO + 48)
+#endif
+
+#ifndef EUNATCH
+#define EUNATCH (ERROR_BASE_NO + 49)
+#endif
+
+#ifndef ENOCSI
+#define ENOCSI (ERROR_BASE_NO + 50)
+#endif
+
+#ifndef EL2HLT
+#define EL2HLT (ERROR_BASE_NO + 51)
+#endif
+
+#ifndef EBADE
+#define EBADE (ERROR_BASE_NO + 52)
+#endif
+
+#ifndef EBADR
+#define EBADR (ERROR_BASE_NO + 53)
+#endif
+
+#ifndef EXFULL
+#define EXFULL (ERROR_BASE_NO + 54)
+#endif
+
+#ifndef ENOANO
+#define ENOANO (ERROR_BASE_NO + 55)
+#endif
+
+#ifndef EBADRQC
+#define EBADRQC (ERROR_BASE_NO + 56)
+#endif
+
+#ifndef EBADSLT
+#define EBADSLT (ERROR_BASE_NO + 57)
+#endif
+
+#ifndef EDEADLOCK
+#define EDEADLOCK EDEADLK
+#endif
+
+#ifndef EBFONT
+#define EBFONT (ERROR_BASE_NO + 59)
+#endif
+
+#ifndef ENOSTR
+#define ENOSTR (ERROR_BASE_NO + 60)
+#endif
+
+#ifndef ENODATA
+#define ENODATA (ERROR_BASE_NO + 61)
+#endif
+
+#ifndef ETIME
+#define ETIME (ERROR_BASE_NO + 62)
+#endif
+
+#ifndef ENOSR
+#define ENOSR (ERROR_BASE_NO + 63)
+#endif
+
+#ifndef ENONET
+#define ENONET (ERROR_BASE_NO + 64)
+#endif
+
+#ifndef ENOPKG
+#define ENOPKG (ERROR_BASE_NO + 65)
+#endif
+
+#ifndef EREMOTE
+#define EREMOTE (ERROR_BASE_NO + 66)
+#endif
+
+#ifndef ENOLINK
+#define ENOLINK (ERROR_BASE_NO + 67)
+#endif
+
+#ifndef EADV
+#define EADV (ERROR_BASE_NO + 68)
+#endif
+
+#ifndef ESRMNT
+#define ESRMNT (ERROR_BASE_NO + 69)
+#endif
+
+#ifndef ECOMM
+#define ECOMM (ERROR_BASE_NO + 70)
+#endif
+
+#ifndef EPROTO
+#define EPROTO (ERROR_BASE_NO + 71)
+#endif
+
+#ifndef EMULTIHOP
+#define EMULTIHOP (ERROR_BASE_NO + 72)
+#endif
+
+#ifndef EDOTDOT
+#define EDOTDOT (ERROR_BASE_NO + 73)
+#endif
+
+#ifndef EBADMSG
+#define EBADMSG (ERROR_BASE_NO + 74)
+#endif
+
+#ifndef EOVERFLOW
+#define EOVERFLOW (ERROR_BASE_NO + 75)
+#endif
+
+#ifndef ENOTUNIQ
+#define ENOTUNIQ (ERROR_BASE_NO + 76)
+#endif
+
+#ifndef EBADFD
+#define EBADFD (ERROR_BASE_NO + 77)
+#endif
+
+#ifndef EREMCHG
+#define EREMCHG (ERROR_BASE_NO + 78)
+#endif
+
+#ifndef ELIBACC
+#define ELIBACC (ERROR_BASE_NO + 79)
+#endif
+
+#ifndef ELIBBAD
+#define ELIBBAD (ERROR_BASE_NO + 80)
+#endif
+
+#ifndef ELIBSCN
+#define ELIBSCN (ERROR_BASE_NO + 81)
+#endif
+
+#ifndef ELIBMAX
+#define ELIBMAX (ERROR_BASE_NO + 82)
+#endif
+
+#ifndef ELIBEXEC
+#define ELIBEXEC (ERROR_BASE_NO + 83)
+#endif
+
+#ifndef EILSEQ
+#define EILSEQ (ERROR_BASE_NO + 84)
+#endif
+
+#ifndef ERESTART
+#define ERESTART (ERROR_BASE_NO + 85)
+#endif
+
+#ifndef ESTRPIPE
+#define ESTRPIPE (ERROR_BASE_NO + 86)
+#endif
+
+#ifndef EUSERS
+#define EUSERS (ERROR_BASE_NO + 87)
+#endif
+
+#ifndef ENOTSOCK
+#define ENOTSOCK (ERROR_BASE_NO + 88)
+#endif
+
+#ifndef EDESTADDRREQ
+#define EDESTADDRREQ (ERROR_BASE_NO + 89)
+#endif
+
+#ifndef EMSGSIZE
+#define EMSGSIZE (ERROR_BASE_NO + 90)
+#endif
+
+#ifndef EPROTOTYPE
+#define EPROTOTYPE (ERROR_BASE_NO + 91)
+#endif
+
+#ifndef ENOPROTOOPT
+#define ENOPROTOOPT (ERROR_BASE_NO + 92)
+#endif
+
+#ifndef EPROTONOSUPPORT
+#define EPROTONOSUPPORT (ERROR_BASE_NO + 93)
+#endif
+
+#ifndef ESOCKTNOSUPPORT
+#define ESOCKTNOSUPPORT (ERROR_BASE_NO + 94)
+#endif
+
+#ifndef EOPNOTSUPP
+#define EOPNOTSUPP (ERROR_BASE_NO + 95)
+#endif
+
+#ifndef ENOTSUP
+#define ENOTSUP EOPNOTSUPP
+#endif
+
+#ifndef EPFNOSUPPORT
+#define EPFNOSUPPORT (ERROR_BASE_NO + 96)
+#endif
+
+#ifndef EAFNOSUPPORT
+#define EAFNOSUPPORT (ERROR_BASE_NO + 97)
+#endif
+
+#ifndef EADDRINUSE
+#define EADDRINUSE (ERROR_BASE_NO + 98)
+#endif
+
+#ifndef EADDRNOTAVAIL
+#define EADDRNOTAVAIL (ERROR_BASE_NO + 99)
+#endif
+
+#ifndef ENETDOWN
+#define ENETDOWN (ERROR_BASE_NO + 100)
+#endif
+
+#ifndef ENETUNREACH
+#define ENETUNREACH (ERROR_BASE_NO + 101)
+#endif
+
+#ifndef ENETRESET
+#define ENETRESET (ERROR_BASE_NO + 102)
+#endif
+
+#ifndef ECONNABORTED
+#define ECONNABORTED (ERROR_BASE_NO + 103)
+#endif
+
+#ifndef ECONNRESET
+#define ECONNRESET (ERROR_BASE_NO + 104)
+#endif
+
+#ifndef ENOBUFS
+#define ENOBUFS (ERROR_BASE_NO + 105)
+#endif
+
+#ifndef EISCONN
+#define EISCONN (ERROR_BASE_NO + 106)
+#endif
+
+#ifndef ENOTCONN
+#define ENOTCONN (ERROR_BASE_NO + 107)
+#endif
+
+#ifndef ESHUTDOWN
+#define ESHUTDOWN (ERROR_BASE_NO + 108)
+#endif
+
+#ifndef ETOOMANYREFS
+#define ETOOMANYREFS (ERROR_BASE_NO + 109)
+#endif
+
+#ifndef ETIMEDOUT
+#define ETIMEDOUT (ERROR_BASE_NO + 110)
+#endif
+
+#ifndef ECONNREFUSED
+#define ECONNREFUSED (ERROR_BASE_NO + 111)
+#endif
+
+#ifndef EHOSTDOWN
+#define EHOSTDOWN (ERROR_BASE_NO + 112)
+#endif
+
+#ifndef EHOSTUNREACH
+#define EHOSTUNREACH (ERROR_BASE_NO + 113)
+#endif
+
+#ifndef EALREADY
+#define EALREADY (ERROR_BASE_NO + 114)
+#endif
+
+#ifndef EINPROGRESS
+#define EINPROGRESS (ERROR_BASE_NO + 115)
+#endif
+
+#ifndef ESTALE
+#define ESTALE (ERROR_BASE_NO + 116)
+#endif
+
+#ifndef EUCLEAN
+#define EUCLEAN (ERROR_BASE_NO + 117)
+#endif
+
+#ifndef ENOTNAM
+#define ENOTNAM (ERROR_BASE_NO + 118)
+#endif
+
+#ifndef ENAVAIL
+#define ENAVAIL (ERROR_BASE_NO + 119)
+#endif
+
+#ifndef EISNAM
+#define EISNAM (ERROR_BASE_NO + 120)
+#endif
+
+#ifndef EREMOTEIO
+#define EREMOTEIO (ERROR_BASE_NO + 121)
+#endif
+
+#ifndef EDQUOT
+#define EDQUOT (ERROR_BASE_NO + 122)
+#endif
+
+#ifndef ENOMEDIUM
+#define ENOMEDIUM (ERROR_BASE_NO + 123)
+#endif
+
+#ifndef EMEDIUMTYPE
+#define EMEDIUMTYPE (ERROR_BASE_NO + 124)
+#endif
+
+#ifndef ECANCELED
+#define ECANCELED (ERROR_BASE_NO + 125)
+#endif
+
+#ifndef ENOKEY
+#define ENOKEY (ERROR_BASE_NO + 126)
+#endif
+
+#ifndef EKEYEXPIRED
+#define EKEYEXPIRED (ERROR_BASE_NO + 127)
+#endif
+
+#ifndef EKEYREVOKED
+#define EKEYREVOKED (ERROR_BASE_NO + 128)
+#endif
+
+#ifndef EKEYREJECTED
+#define EKEYREJECTED (ERROR_BASE_NO + 129)
+#endif
+
+#ifndef EOWNERDEAD
+#define EOWNERDEAD (ERROR_BASE_NO + 130)
+#endif
+
+#ifndef ENOTRECOVERABLE
+#define ENOTRECOVERABLE (ERROR_BASE_NO + 131)
+#endif
+
+#ifndef ERFKILL
+#define ERFKILL (ERROR_BASE_NO + 132)
+#endif
+
+#ifndef EHWPOISON
+#define EHWPOISON (ERROR_BASE_NO + 133)
+#endif
+
+#elif defined(_WIN32)
+#include <errno.h>
+
+#endif /* defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__) */
+
+#endif /* __SYS_ERRNO_H__ */
diff --git a/components/libc/compilers/common/extension/sys/select.h b/components/libc/compilers/common/extension/sys/select.h
new file mode 100644
index 0000000000..44f9b4ed91
--- /dev/null
+++ b/components/libc/compilers/common/extension/sys/select.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-07-21 Meco Man The first version
+ * 2021-12-25 Meco Man Handle newlib 2.2.0 or lower version
+ */
+
+#ifndef __SYS_SELECT_H__
+#define __SYS_SELECT_H__
+
+#include <rtconfig.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#ifdef _WIN32
+#include <winsock.h>
+#endif
+
+#ifndef FD_SETSIZE
+#define FD_SETSIZE 32
+#endif
+
+#ifdef SAL_USING_POSIX
+#ifdef FD_SETSIZE
+#undef FD_SETSIZE
+#endif
+#define FD_SETSIZE DFS_FD_MAX
+#endif /* SAL_USING_POSIX */
+
+typedef long fd_mask;
+
+#ifndef _WIN32
+#ifndef _SYS_TYPES_FD_SET /* Newlib 2.2.0 or lower version */
+#define NBBY 8 /* number of bits in a byte */
+#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
+#ifndef howmany
+#define howmany(x,y) (((x)+((y)-1))/(y))
+#endif /* howmany */
+
+typedef struct _types_fd_set {
+ fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
+} _types_fd_set;
+#define fd_set _types_fd_set
+
+#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
+#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
+#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
+#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
+#endif /* _SYS_TYPES_FD_SET */
+
+int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
+#endif /* _WIN32 */
+
+#endif /* __SYS_SELECT_H__ */
diff --git a/components/libc/compilers/common/extension/sys/stat.h b/components/libc/compilers/common/extension/sys/stat.h
new file mode 100644
index 0000000000..107c15decf
--- /dev/null
+++ b/components/libc/compilers/common/extension/sys/stat.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-09-02 Meco Man First version
+ */
+
+#ifndef __SYS_STAT_H__
+#define __SYS_STAT_H__
+
+#include <sys/types.h>
+#include <sys/time.h>
+
+#define S_IFMT 00170000
+#define S_IFSOCK 0140000
+#define S_IFLNK 0120000
+#define S_IFREG 0100000
+#define S_IFBLK 0060000
+#define S_IFDIR 0040000
+#define S_IFCHR 0020000
+#define S_IFIFO 0010000
+#define S_ISUID 0004000
+#define S_ISGID 0002000
+#define S_ISVTX 0001000
+
+#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
+#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
+#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
+#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
+#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
+#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
+
+#define S_IRWXU 00700
+#define S_IRUSR 00400
+#define S_IWUSR 00200
+#define S_IXUSR 00100
+
+#define S_IRWXG 00070
+#define S_IRGRP 00040
+#define S_IWGRP 00020
+#define S_IXGRP 00010
+
+#define S_IRWXO 00007
+#define S_IROTH 00004
+#define S_IWOTH 00002
+#define S_IXOTH 00001
+
+struct stat
+{
+ struct rt_device *st_dev;
+ uint16_t st_ino;
+ uint16_t st_mode;
+ uint16_t st_nlink;
+ uint16_t st_uid;
+ uint16_t st_gid;
+ struct rt_device *st_rdev;
+ uint32_t st_size;
+ time_t st_atime;
+ long st_spare1;
+ time_t st_mtime;
+ long st_spare2;
+ time_t st_ctime;
+ long st_spare3;
+ uint32_t st_blksize;
+ uint32_t st_blocks;
+ long st_spare4[2];
+};
+
+int chmod(const char *, mode_t);
+int fchmod(int, mode_t);
+int fstat(int, struct stat *);
+int lstat(const char *, struct stat *);
+int mkdir(const char *, mode_t);
+int mkfifo(const char *, mode_t);
+int mknod(const char *, mode_t, dev_t);
+int stat(const char *, struct stat *);
+mode_t umask(mode_t);
+
+#endif
diff --git a/components/libc/compilers/armlibc/sys/types.h b/components/libc/compilers/common/extension/sys/types.h
index 78fee1bb99..85cd4fea21 100644
--- a/components/libc/compilers/armlibc/sys/types.h
+++ b/components/libc/compilers/common/extension/sys/types.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -8,19 +8,35 @@
* 2020-09-05 Meco Man fix bugs
* 2020-12-16 Meco Man add useconds_t
*/
-#ifndef __TYPES_H__
-#define __TYPES_H__
+
+#ifndef __SYS_TYPES_H__
+#define __SYS_TYPES_H__
#include <stdint.h>
+#include <stddef.h>
+#include <time.h>
typedef int32_t clockid_t;
typedef int32_t key_t; /* Used for interprocess communication. */
-typedef int32_t pid_t; /* Used for process IDs and process group IDs. */
+typedef int pid_t; /* Used for process IDs and process group IDs. */
+typedef unsigned short uid_t;
+typedef unsigned short gid_t;
+typedef signed long off_t;
+typedef int mode_t;
#ifndef ARCH_CPU_64BIT
typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */
#else
typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */
#endif
+typedef unsigned long __timer_t;
+typedef __timer_t timer_t;
+typedef long suseconds_t; /* microseconds. */
typedef unsigned long useconds_t; /* microseconds (unsigned) */
+typedef unsigned long dev_t;
+
+typedef unsigned int u_int;
+typedef unsigned char u_char;
+typedef unsigned long u_long;
+
#endif
diff --git a/components/libc/compilers/common/extension/sys/unistd.h b/components/libc/compilers/common/extension/sys/unistd.h
new file mode 100644
index 0000000000..29ec3f70c4
--- /dev/null
+++ b/components/libc/compilers/common/extension/sys/unistd.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2020-12-16 Meco Man add usleep
+ * 2021-09-11 Meco Man move functions from dfs_posix.h to unistd.h
+ */
+
+#ifndef __SYS_UNISTD_H__
+#define __SYS_UNISTD_H__
+
+#include <stddef.h>
+#include "types.h" /* <sys/types.h> */
+
+#define STDIN_FILENO 0 /* standard input file descriptor */
+#define STDOUT_FILENO 1 /* standard output file descriptor */
+#define STDERR_FILENO 2 /* standard error file descriptor */
+
+unsigned alarm(unsigned __secs);
+ssize_t read(int fd, void *buf, size_t len);
+ssize_t write(int fd, const void *buf, size_t len);
+off_t lseek(int fd, off_t offset, int whence);
+int pause(void);
+int fsync(int fildes);
+long sysconf(int __name);
+int unlink(const char *pathname);
+int close(int d);
+int ftruncate(int fd, off_t length);
+int rmdir(const char *path);
+int chdir(const char *path);
+char *getcwd(char *buf, size_t size);
+int access(const char *path, int amode);
+int pipe(int fildes[2]);
+int isatty(int fd);
+char *ttyname(int desc);
+unsigned int sleep(unsigned int seconds);
+int usleep(useconds_t usec);
+pid_t gettid(void);
+pid_t getpid(void);
+pid_t getppid(void);
+uid_t getuid(void);
+uid_t geteuid(void);
+gid_t getgid(void);
+gid_t getegid(void);
+
+#endif /* _SYS_UNISTD_H */
diff --git a/components/libc/compilers/armlibc/unistd.h b/components/libc/compilers/common/extension/unistd.h
index 736fc219a8..4dd71c842e 100644
--- a/components/libc/compilers/armlibc/unistd.h
+++ b/components/libc/compilers/common/extension/unistd.h
@@ -1,10 +1,10 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
-#include "sys/unistd.h"
+#include "sys/unistd.h"
diff --git a/components/libc/compilers/common/readme.md b/components/libc/compilers/common/readme.md
index 99797d933c..82e23f8970 100644
--- a/components/libc/compilers/common/readme.md
+++ b/components/libc/compilers/common/readme.md
@@ -1,10 +1 @@
-## Attentions
-
-1. This folder is "common" for armlibc newlibc and dlib. It's not "common" for minilibc.
-
-2. If you want to add new .c files, please do not forget to fix SConscript file too. eg:
-
-```python
-if GetDepend('RT_USING_POSIX') == False:
- SrcRemove(src, ['unistd.c'])
-``` \ No newline at end of file
+This folder is "common" for all toolchains. \ No newline at end of file
diff --git a/components/libc/compilers/common/stdlib.c b/components/libc/compilers/common/stdlib.c
new file mode 100644
index 0000000000..6cc0b9fdac
--- /dev/null
+++ b/components/libc/compilers/common/stdlib.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-02-15 Meco Man first version
+ */
+
+#include <rtthread.h>
+
+#define DBG_TAG "stdlib"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
+void __rt_libc_exit(int status)
+{
+ rt_thread_t self = rt_thread_self();
+
+ if (self != RT_NULL)
+ {
+ LOG_E("thread:%s exit:%d!", self->name, status);
+ rt_thread_control(self, RT_THREAD_CTRL_CLOSE, RT_NULL);
+ }
+}
+
+#ifdef RT_USING_MSH
+int system(const char *command)
+{
+ extern int msh_exec(char *cmd, rt_size_t length);
+
+ int ret = -RT_ENOMEM;
+ char *cmd = rt_strdup(command);
+
+ if (cmd)
+ {
+ ret = msh_exec(cmd, rt_strlen(cmd));
+ rt_free(cmd);
+ }
+
+ return ret;
+}
+RTM_EXPORT(system);
+#endif
diff --git a/components/libc/compilers/common/sys/ioctl.h b/components/libc/compilers/common/sys/ioctl.h
new file mode 100644
index 0000000000..0b1edca699
--- /dev/null
+++ b/components/libc/compilers/common/sys/ioctl.h
@@ -0,0 +1,274 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2020-09-01 Meco Man First Version
+ */
+
+#ifndef __SYS_IOCTL_H__
+#define __SYS_IOCTL_H__
+
+#ifdef _WIN32
+#include <winsock.h>
+#endif
+
+struct winsize
+{
+ unsigned short ws_row;
+ unsigned short ws_col;
+ unsigned short ws_xpixel;
+ unsigned short ws_ypixel;
+};
+
+/*
+ * Direction bits, which any architecture can choose to override
+ * before including this file.
+ */
+
+#ifndef _IOC_NONE
+#define _IOC_NONE 0U
+#endif
+
+#ifndef _IOC_WRITE
+#define _IOC_WRITE 1U
+#endif
+
+#ifndef _IOC_READ
+#define _IOC_READ 2U
+#endif
+
+#ifndef _IOC
+#define _IOC(a,b,c,d) (((a)<<30) | ((b)<<8) | (c) | ((d)<<16))
+#endif
+
+#ifndef _IO
+#define _IO(a,b) _IOC(_IOC_NONE, (a), (b), 0)
+#endif
+
+#ifndef _IOW
+#define _IOW(a,b,c) _IOC(_IOC_WRITE, (a), (b), sizeof(c))
+#endif
+
+#ifndef _IOR
+#define _IOR(a,b,c) _IOC(_IOC_READ, (a), (b), sizeof(c))
+#endif
+
+#ifndef _IOWR
+#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE, (a), (b), sizeof(c))
+#endif
+
+#ifndef FIONREAD
+#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */
+#endif
+
+#ifndef FIONBIO
+#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */
+#endif
+
+#ifndef FIOASYNC
+#define FIOASYNC _IOW('f', 125, int) /* set/clear async i/o */
+#endif
+
+#ifndef FIONWRITE
+#define FIONWRITE _IOR('f', 121, int) /* get # bytes outstanding in send queue */
+#endif
+
+/* Socket I/O Controls */
+#ifndef SIOCSHIWAT
+#define SIOCSHIWAT _IOW('s', 0, int) /* set high watermark */
+#define SIOCGHIWAT _IOR('s', 1, int) /* get high watermark */
+#define SIOCSLOWAT _IOW('s', 2, int) /* set low watermark */
+#define SIOCGLOWAT _IOR('s', 3, int) /* get low watermark */
+#define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */
+#endif
+
+#define TCGETS 0x5401
+#define TCSETS 0x5402
+#define TCSETSW 0x5403
+#define TCSETSF 0x5404
+#define TCGETA 0x5405
+#define TCSETA 0x5406
+#define TCSETAW 0x5407
+#define TCSETAF 0x5408
+#define TCSBRK 0x5409
+#define TCXONC 0x540A
+#define TCFLSH 0x540B
+#define TIOCEXCL 0x540C
+#define TIOCNXCL 0x540D
+#define TIOCSCTTY 0x540E
+#define TIOCGPGRP 0x540F
+#define TIOCSPGRP 0x5410
+#define TIOCOUTQ 0x5411
+#define TIOCSTI 0x5412
+#define TIOCGWINSZ 0x5413
+#define TIOCSWINSZ 0x5414
+#define TIOCMGET 0x5415
+#define TIOCMBIS 0x5416
+#define TIOCMBIC 0x5417
+#define TIOCMSET 0x5418
+#define TIOCGSOFTCAR 0x5419
+#define TIOCSSOFTCAR 0x541A
+#define TIOCINQ FIONREAD
+#define TIOCLINUX 0x541C
+#define TIOCCONS 0x541D
+#define TIOCGSERIAL 0x541E
+#define TIOCSSERIAL 0x541F
+#define TIOCPKT 0x5420
+#define TIOCNOTTY 0x5422
+#define TIOCSETD 0x5423
+#define TIOCGETD 0x5424
+#define TCSBRKP 0x5425
+#define TIOCSBRK 0x5427
+#define TIOCCBRK 0x5428
+#define TIOCGSID 0x5429
+#define TIOCGRS485 0x542E
+#define TIOCSRS485 0x542F
+#define TIOCGPTN 0x80045430
+#define TIOCSPTLCK 0x40045431
+#define TIOCGDEV 0x80045432
+#define TCGETX 0x5432
+#define TCSETX 0x5433
+#define TCSETXF 0x5434
+#define TCSETXW 0x5435
+#define TIOCSIG 0x40045436
+#define TIOCVHANGUP 0x5437
+#define TIOCGPKT 0x80045438
+#define TIOCGPTLCK 0x80045439
+#define TIOCGEXCL 0x80045440
+
+#define FIONCLEX 0x5450
+#define FIOCLEX 0x5451
+
+#define TIOCSERCONFIG 0x5453
+#define TIOCSERGWILD 0x5454
+#define TIOCSERSWILD 0x5455
+#define TIOCGLCKTRMIOS 0x5456
+#define TIOCSLCKTRMIOS 0x5457
+#define TIOCSERGSTRUCT 0x5458
+#define TIOCSERGETLSR 0x5459
+#define TIOCSERGETMULTI 0x545A
+#define TIOCSERSETMULTI 0x545B
+
+#define TIOCMIWAIT 0x545C
+#define TIOCGICOUNT 0x545D
+#define FIOQSIZE 0x5460
+
+#define TIOCPKT_DATA 0
+#define TIOCPKT_FLUSHREAD 1
+#define TIOCPKT_FLUSHWRITE 2
+#define TIOCPKT_STOP 4
+#define TIOCPKT_START 8
+#define TIOCPKT_NOSTOP 16
+#define TIOCPKT_DOSTOP 32
+#define TIOCPKT_IOCTL 64
+
+#define TIOCSER_TEMT 0x01
+
+#define TIOCM_LE 0x001
+#define TIOCM_DTR 0x002
+#define TIOCM_RTS 0x004
+#define TIOCM_ST 0x008
+#define TIOCM_SR 0x010
+#define TIOCM_CTS 0x020
+#define TIOCM_CAR 0x040
+#define TIOCM_RNG 0x080
+#define TIOCM_DSR 0x100
+#define TIOCM_CD TIOCM_CAR
+#define TIOCM_RI TIOCM_RNG
+#define TIOCM_OUT1 0x2000
+#define TIOCM_OUT2 0x4000
+#define TIOCM_LOOP 0x8000
+
+#define N_TTY 0
+#define N_SLIP 1
+#define N_MOUSE 2
+#define N_PPP 3
+#define N_STRIP 4
+#define N_AX25 5
+#define N_X25 6
+#define N_6PACK 7
+#define N_MASC 8
+#define N_R3964 9
+#define N_PROFIBUS_FDL 10
+#define N_IRDA 11
+#define N_SMSBLOCK 12
+#define N_HDLC 13
+#define N_SYNC_PPP 14
+#define N_HCI 15
+
+#define FIOSETOWN 0x8901
+#define SIOCSPGRP 0x8902
+#define FIOGETOWN 0x8903
+#define SIOCGPGRP 0x8904
+#define SIOCGSTAMP 0x8906
+#define SIOCGSTAMPNS 0x8907
+
+#define SIOCADDRT 0x890B
+#define SIOCDELRT 0x890C
+#define SIOCRTMSG 0x890D
+
+#define SIOCGIFNAME 0x8910
+#define SIOCSIFLINK 0x8911
+#define SIOCGIFCONF 0x8912
+#define SIOCGIFFLAGS 0x8913
+#define SIOCSIFFLAGS 0x8914
+#define SIOCGIFADDR 0x8915
+#define SIOCSIFADDR 0x8916
+#define SIOCGIFDSTADDR 0x8917
+#define SIOCSIFDSTADDR 0x8918
+#define SIOCGIFBRDADDR 0x8919
+#define SIOCSIFBRDADDR 0x891a
+#define SIOCGIFNETMASK 0x891b
+#define SIOCSIFNETMASK 0x891c
+#define SIOCGIFMETRIC 0x891d
+#define SIOCSIFMETRIC 0x891e
+#define SIOCGIFMEM 0x891f
+#define SIOCSIFMEM 0x8920
+#define SIOCGIFMTU 0x8921
+#define SIOCSIFMTU 0x8922
+#define SIOCSIFNAME 0x8923
+#define SIOCSIFHWADDR 0x8924
+#define SIOCGIFENCAP 0x8925
+#define SIOCSIFENCAP 0x8926
+#define SIOCGIFHWADDR 0x8927
+#define SIOCGIFSLAVE 0x8929
+#define SIOCSIFSLAVE 0x8930
+#define SIOCADDMULTI 0x8931
+#define SIOCDELMULTI 0x8932
+#define SIOCGIFINDEX 0x8933
+#define SIOGIFINDEX SIOCGIFINDEX
+#define SIOCSIFPFLAGS 0x8934
+#define SIOCGIFPFLAGS 0x8935
+#define SIOCDIFADDR 0x8936
+#define SIOCSIFHWBROADCAST 0x8937
+#define SIOCGIFCOUNT 0x8938
+
+#define SIOCGIFBR 0x8940
+#define SIOCSIFBR 0x8941
+
+#define SIOCGIFTXQLEN 0x8942
+#define SIOCSIFTXQLEN 0x8943
+
+#define SIOCDARP 0x8953
+#define SIOCGARP 0x8954
+#define SIOCSARP 0x8955
+
+#define SIOCDRARP 0x8960
+#define SIOCGRARP 0x8961
+#define SIOCSRARP 0x8962
+
+#define SIOCGIFMAP 0x8970
+#define SIOCSIFMAP 0x8971
+
+#define SIOCADDDLCI 0x8980
+#define SIOCDELDLCI 0x8981
+
+#define SIOCDEVPRIVATE 0x89F0
+#define SIOCPROTOPRIVATE 0x89E0
+
+int ioctl(int fildes, int cmd, ...);
+
+#endif
diff --git a/components/libc/compilers/common/sys/signal.h b/components/libc/compilers/common/sys/signal.h
new file mode 100644
index 0000000000..041dd765b7
--- /dev/null
+++ b/components/libc/compilers/common/sys/signal.h
@@ -0,0 +1,232 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2017-09-12 Bernard The first version
+ * 2021-07-21 Meco Man move to libc/common
+ */
+
+#ifndef __SYS_SIGNAL_H__
+#define __SYS_SIGNAL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <sys/types.h>
+
+
+/* sigev_notify values
+ NOTE: P1003.1c/D10, p. 34 adds SIGEV_THREAD. */
+
+#define SIGEV_NONE 1 /* No asynchronous notification shall be delivered */
+ /* when the event of interest occurs. */
+#define SIGEV_SIGNAL 2 /* A queued signal, with an application defined */
+ /* value, shall be delivered when the event of */
+ /* interest occurs. */
+#define SIGEV_THREAD 3 /* A notification function shall be called to */
+ /* perform notification. */
+
+/* Signal Generation and Delivery, P1003.1b-1993, p. 63
+ NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and
+ sigev_notify_attributes to the sigevent structure. */
+union sigval
+{
+ int sival_int; /* Integer signal value */
+ void *sival_ptr; /* Pointer signal value */
+};
+
+struct sigevent
+{
+ int sigev_notify; /* Notification type */
+ int sigev_signo; /* Signal number */
+ union sigval sigev_value; /* Signal value */
+ void (*sigev_notify_function)( union sigval );
+ /* Notification function */
+ void *sigev_notify_attributes; /* Notification Attributes, really pthread_attr_t */
+};
+
+struct siginfo
+{
+ uint16_t si_signo;
+ uint16_t si_code;
+
+ union sigval si_value;
+};
+typedef struct siginfo siginfo_t;
+
+#define SI_USER 0x01 /* Signal sent by kill(). */
+#define SI_QUEUE 0x02 /* Signal sent by sigqueue(). */
+#define SI_TIMER 0x03 /* Signal generated by expiration of a timer set by timer_settime(). */
+#define SI_ASYNCIO 0x04 /* Signal generated by completion of an asynchronous I/O request. */
+#define SI_MESGQ 0x05 /* Signal generated by arrival of a message on an empty message queue. */
+
+typedef void (*_sig_func_ptr)(int);
+typedef unsigned long sigset_t;
+
+struct sigaction
+{
+ _sig_func_ptr sa_handler;
+ sigset_t sa_mask;
+ int sa_flags;
+};
+
+/*
+ * Structure used in sigaltstack call.
+ */
+typedef struct sigaltstack
+{
+ void *ss_sp; /* Stack base or pointer. */
+ int ss_flags; /* Flags. */
+ size_t ss_size; /* Stack size. */
+} stack_t;
+
+#define SIG_SETMASK 0 /* set mask with sigprocmask() */
+#define SIG_BLOCK 1 /* set of signals to block */
+#define SIG_UNBLOCK 2 /* set of signals to, well, unblock */
+
+#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0)
+#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0)
+#define sigemptyset(what) (*(what) = 0, 0)
+#define sigfillset(what) (*(what) = ~(0), 0)
+#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)
+
+int sigprocmask (int how, const sigset_t *set, sigset_t *oset);
+int sigpending (sigset_t *set);
+int sigsuspend (const sigset_t *set);
+
+#include "time.h"
+int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout);
+int sigwait(const sigset_t *set, int *sig);
+int sigwaitinfo(const sigset_t *set, siginfo_t *info);
+int raise(int sig);
+int sigqueue(pid_t pid, int signo, const union sigval value);
+int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
+
+#ifdef __ARMCC_VERSION
+#define SIGHUP 1
+/* #define SIGINT 2 */
+#define SIGQUIT 3
+/* #define SIGILL 4 */
+#define SIGTRAP 5
+/* #define SIGABRT 6 */
+#define SIGEMT 7
+/* #define SIGFPE 8 */
+#define SIGKILL 9
+#define SIGBUS 10
+/* #define SIGSEGV 11 */
+#define SIGSYS 12
+#define SIGPIPE 13
+#define SIGALRM 14
+/* #define SIGTERM 15 */
+#define SIGURG 16
+#define SIGSTOP 17
+#define SIGTSTP 18
+#define SIGCONT 19
+#define SIGCHLD 20
+#define SIGTTIN 21
+#define SIGTTOU 22
+#define SIGPOLL 23
+#define SIGWINCH 24
+#define SIGXCPU 24 /* exceeded CPU time limit */
+#define SIGXFSZ 25 /* exceeded file size limit */
+#define SIGVTALRM 26 /* virtual time alarm */
+/* #define SIGUSR1 25 */
+/* #define SIGUSR2 26 */
+#define SIGRTMIN 27
+#define SIGRTMAX 31
+#define NSIG 32
+
+#include <signal.h>
+
+#elif defined(__IAR_SYSTEMS_ICC__)
+#define SIGHUP 1
+#define SIGINT 2
+#define SIGQUIT 3
+#define SIGILL 4
+#define SIGTRAP 5
+/* #define SIGABRT 6 */
+#define SIGEMT 7
+#define SIGFPE 8
+#define SIGKILL 9
+#define SIGBUS 10
+#define SIGSEGV 11
+#define SIGSYS 12
+#define SIGPIPE 13
+#define SIGALRM 14
+#define SIGTERM 15
+#define SIGURG 16
+#define SIGSTOP 17
+#define SIGTSTP 18
+#define SIGCONT 19
+#define SIGCHLD 20
+#define SIGTTIN 21
+#define SIGTTOU 22
+#define SIGPOLL 23
+#define SIGWINCH 24
+#define SIGXCPU 24 /* exceeded CPU time limit */
+#define SIGXFSZ 25 /* exceeded file size limit */
+#define SIGVTALRM 26 /* virtual time alarm */
+#define SIGUSR1 25
+#define SIGUSR2 26
+#define SIGRTMIN 27
+#define SIGRTMAX 31
+#define NSIG 32
+
+#include <signal.h>
+
+#elif defined(__GNUC__)
+#define SIGHUP 1 /* hangup */
+#define SIGINT 2 /* interrupt */
+#define SIGQUIT 3 /* quit */
+#define SIGILL 4 /* illegal instruction (not reset when caught) */
+#define SIGTRAP 5 /* trace trap (not reset when caught) */
+#define SIGIOT 6 /* IOT instruction */
+#define SIGABRT 6 /* used by abort, replace SIGIOT in the future */
+#define SIGEMT 7 /* EMT instruction */
+#define SIGFPE 8 /* floating point exception */
+#define SIGKILL 9 /* kill (cannot be caught or ignored) */
+#define SIGBUS 10 /* bus error */
+#define SIGSEGV 11 /* segmentation violation */
+#define SIGSYS 12 /* bad argument to system call */
+#define SIGPIPE 13 /* write on a pipe with no one to read it */
+#define SIGALRM 14 /* alarm clock */
+#define SIGTERM 15 /* software termination signal from kill */
+#define SIGURG 16 /* urgent condition on IO channel */
+#define SIGSTOP 17 /* sendable stop signal not from tty */
+#define SIGTSTP 18 /* stop signal from tty */
+#define SIGCONT 19 /* continue a stopped process */
+#define SIGCHLD 20 /* to parent on child stop or exit */
+#define SIGCLD 20 /* System V name for SIGCHLD */
+#define SIGTTIN 21 /* to readers pgrp upon background tty read */
+#define SIGTTOU 22 /* like TTIN for output if (tp->t_local&LTOSTOP) */
+#define SIGIO 23 /* input/output possible signal */
+#define SIGPOLL SIGIO /* System V name for SIGIO */
+#define SIGXCPU 24 /* exceeded CPU time limit */
+#define SIGXFSZ 25 /* exceeded file size limit */
+#define SIGVTALRM 26 /* virtual time alarm */
+#define SIGPROF 27 /* profiling time alarm */
+#define SIGWINCH 28 /* window changed */
+#define SIGLOST 29 /* resource lost (eg, record-lock lost) */
+#define SIGUSR1 30 /* user defined signal 1 */
+#define SIGUSR2 31 /* user defined signal 2 */
+#define NSIG 32 /* signal 0 implied */
+
+#ifndef _SIGNAL_H_
+/* Some applications take advantage of the fact that <sys/signal.h>
+ * and <signal.h> are equivalent in glibc. Allow for that here. */
+#include <signal.h>
+#endif
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/components/libc/compilers/common/sys/statfs.h b/components/libc/compilers/common/sys/statfs.h
new file mode 100644
index 0000000000..a86a789475
--- /dev/null
+++ b/components/libc/compilers/common/sys/statfs.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ */
+
+#ifndef __SYS_STATFS_H__
+#define __SYS_STATFS_H__
+
+#include <stddef.h>
+
+struct statfs
+{
+ size_t f_bsize; /* block size */
+ size_t f_blocks; /* total data blocks in file system */
+ size_t f_bfree; /* free blocks in file system */
+};
+
+int statfs(const char *path, struct statfs *buf);
+int fstatfs(int fd, struct statfs *buf);
+
+#endif
diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h
index 28a977c1f9..a3af31b20b 100644
--- a/components/libc/compilers/common/sys/time.h
+++ b/components/libc/compilers/common/sys/time.h
@@ -1,55 +1,152 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020-09-07 Meco Man combine gcc armcc iccarm
+ * 2021-02-12 Meco Man move all definitions located in <clock_time.h> to this file
*/
-#ifndef _SYS_TIME_H_
-#define _SYS_TIME_H_
+#ifndef __SYS_TIME_H__
+#define __SYS_TIME_H__
+
+#include <rtconfig.h>
+#include <sys/types.h>
+#include <stdint.h>
#include <time.h>
+#ifdef _WIN32
+#include <winsock.h> /* for struct timeval */
+#endif
#ifdef __cplusplus
extern "C" {
#endif
-/*
- * Skip define timespec for IAR version over 8.10.1 where __VER__ is 8010001.
- */
-#if defined ( __ICCARM__ ) && (__VER__ >= 8010001)
-#define _TIMESPEC_DEFINED
-#endif
+/* timezone */
+#define DST_NONE 0 /* not on dst */
+#define DST_USA 1 /* USA style dst */
+#define DST_AUST 2 /* Australian style dst */
+#define DST_WET 3 /* Western European dst */
+#define DST_MET 4 /* Middle European dst */
+#define DST_EET 5 /* Eastern European dst */
+#define DST_CAN 6 /* Canada */
+#define DST_GB 7 /* Great Britain and Eire */
+#define DST_RUM 8 /* Rumania */
+#define DST_TUR 9 /* Turkey */
+#define DST_AUSTALT 10 /* Australian style with shift in 1986 */
+struct timezone
+{
+ int tz_minuteswest; /* minutes west of Greenwich */
+ int tz_dsttime; /* type of dst correction */
+};
-#ifndef _TIMEVAL_DEFINED
+#if !defined(_TIMEVAL_DEFINED) && !defined(_WIN32)
#define _TIMEVAL_DEFINED
-/*
- * Structure returned by gettimeofday(2) system call,
- * and used in other calls.
- */
-struct timeval {
- long tv_sec; /* seconds */
- long tv_usec; /* and microseconds */
+struct timeval
+{
+ time_t tv_sec; /* seconds */
+ suseconds_t tv_usec; /* and microseconds */
};
-#endif /* _TIMEVAL_DEFINED */
+#endif
-#if !defined __GNUC__ && !defined __ICCARM__
-struct timespec {
+#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && \
+ !(defined(__ICCARM__) && (__VER__ >= 8010001)) && \
+ !defined(_WIN32)
+struct timespec
+{
time_t tv_sec; /* seconds */
long tv_nsec; /* and nanoseconds */
};
-#endif
-struct timezone {
- int tz_minuteswest; /* minutes west of Greenwich */
- int tz_dsttime; /* type of dst correction */
+/*
+ * Structure defined by POSIX.1b to be like a itimerval, but with
+ * timespecs. Used in the timer_*() system calls.
+ */
+struct itimerspec
+{
+ struct timespec it_interval;
+ struct timespec it_value;
};
+#endif
-int gettimeofday(struct timeval *tp, void *ignore);
+int stime(const time_t *t);
+time_t timegm(struct tm * const t);
+int gettimeofday(struct timeval *tv, struct timezone *tz);
+int settimeofday(const struct timeval *tv, const struct timezone *tz);
+#if defined(__ARMCC_VERSION) || defined (__ICCARM__)
struct tm *gmtime_r(const time_t *timep, struct tm *r);
+struct tm* localtime_r(const time_t* t, struct tm* r);
+char* asctime_r(const struct tm *t, char *buf);
+char *ctime_r(const time_t * tim_p, char * result);
+#elif defined(_WIN32)
+struct tm* gmtime_r(const time_t* timep, struct tm* r);
+struct tm* gmtime(const time_t* t);
+struct tm* localtime_r(const time_t* t, struct tm* r);
+struct tm* localtime(const time_t* t);
+time_t mktime(struct tm* const t);
+char* asctime_r(const struct tm* t, char* buf);
+char* ctime_r(const time_t* tim_p, char* result);
+char* ctime(const time_t* tim_p);
+time_t time(time_t* t);
+#endif
+
+#ifdef RT_USING_POSIX_DELAY
+int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
+#endif /* RT_USING_POSIX_DELAY */
+
+#if defined(RT_USING_POSIX_CLOCK) || defined (RT_USING_POSIX_TIMER)
+/* POSIX clock and timer */
+#define MILLISECOND_PER_SECOND 1000UL
+#define MICROSECOND_PER_SECOND 1000000UL
+#define NANOSECOND_PER_SECOND 1000000000UL
+
+#define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / RT_TICK_PER_SECOND)
+#define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND)
+#define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND)
+
+#ifndef CLOCK_REALTIME
+#define CLOCK_REALTIME 1
+#endif
+
+#define CLOCK_CPUTIME_ID 2
+
+#ifndef CLOCK_PROCESS_CPUTIME_ID
+#define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID
+#endif
+#ifndef CLOCK_THREAD_CPUTIME_ID
+#define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID
+#endif
+
+#ifndef CLOCK_MONOTONIC
+#define CLOCK_MONOTONIC 4
+#endif
+#endif /* defined(RT_USING_POSIX_CLOCK) || defined (RT_USING_POSIX_TIMER) */
+
+#ifdef RT_USING_POSIX_CLOCK
+int clock_getres (clockid_t clockid, struct timespec *res);
+int clock_gettime (clockid_t clockid, struct timespec *tp);
+int clock_settime (clockid_t clockid, const struct timespec *tp);
+int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, struct timespec *rmtp);
+int rt_timespec_to_tick(const struct timespec *time);
+#endif /* RT_USING_POSIX_CLOCK */
+
+#ifdef RT_USING_POSIX_TIMER
+#include "signal.h"
+int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid);
+int timer_delete(timer_t timerid);
+int timer_getoverrun(timer_t timerid);
+int timer_gettime(timer_t timerid, struct itimerspec *its);
+int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
+ struct itimerspec *ovalue);
+#endif /* RT_USING_POSIX_TIMER */
+
+/* timezone */
+void tz_set(int8_t tz);
+int8_t tz_get(void);
+int8_t tz_is_dst(void);
#ifdef __cplusplus
}
diff --git a/components/libc/compilers/common/sys/vfs.h b/components/libc/compilers/common/sys/vfs.h
new file mode 100644
index 0000000000..a9330df002
--- /dev/null
+++ b/components/libc/compilers/common/sys/vfs.h
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-09-11 Meco Man First version
+ */
+
+#ifndef __SYS_VFS_H__
+#define __SYS_VFS_H__
+
+#include "statfs.h" /* <sys/statfs.h> */
+
+#endif
diff --git a/components/libc/compilers/common/termios.h b/components/libc/compilers/common/termios.h
deleted file mode 100644
index 414d0c0cb3..0000000000
--- a/components/libc/compilers/common/termios.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef _TERMIOS_H__
-#define _TERMIOS_H__
-
-#include <rtconfig.h>
-
-#ifdef RT_USING_POSIX_TERMIOS
-#include <sys/types.h>
-#include <posix_termios.h>
-#endif
-
-#endif
diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c
index 99dab71eb4..71755b8bbb 100644
--- a/components/libc/compilers/common/time.c
+++ b/components/libc/compilers/common/time.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -7,15 +7,43 @@
* Date Author Notes
* 2019-08-21 zhangjun copy from minilibc
* 2020-09-07 Meco Man combine gcc armcc iccarm
+ * 2021-02-05 Meco Man add timegm()
+ * 2021-02-07 Meco Man fixed gettimeofday()
+ * 2021-02-08 Meco Man add settimeofday() stime()
+ * 2021-02-10 Meco Man add ctime_r() and re-implement ctime()
+ * 2021-02-11 Meco Man fix bug #3183 - align days[] and months[] to 4 bytes
+ * 2021-02-12 Meco Man add errno
+ * 2012-12-08 Bernard <clock_time.c> fix the issue of _timevalue.tv_usec initialization,
+ * which found by Rob <[email protected]>
+ * 2021-02-12 Meco Man move all of the functions located in <clock_time.c> to this file
+ * 2021-03-15 Meco Man fixed a bug of leaking memory in asctime()
+ * 2021-05-01 Meco Man support fixed timezone
+ * 2021-07-21 Meco Man implement that change/set timezone APIs
*/
-#include <sys/time.h>
+#include "sys/time.h"
+#include <sys/errno.h>
#include <rtthread.h>
+#include <rthw.h>
+#include <unistd.h>
+#ifdef RT_USING_POSIX_DELAY
+#include <delay.h>
+#endif
+#ifdef RT_USING_RTC
+#include <rtdevice.h>
+#endif
-#if !defined (__IAR_SYSTEMS_ICC__)
+#define DBG_TAG "time"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
+#define _WARNING_NO_RTC "Cannot find a RTC device!"
+
+/* seconds per day */
+#define SPD 24*60*60
/* days per month -- nonleap! */
-const short __spm[13] =
+static const short __spm[13] =
{
0,
(31),
@@ -31,13 +59,11 @@ const short __spm[13] =
(31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30),
(31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31),
};
-static const char days[] = "Sun Mon Tue Wed Thu Fri Sat ";
-static const char months[] = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
-/* seconds per day */
-#define SPD 24*60*60
+ALIGN(4) static const char *days = "Sun Mon Tue Wed Thu Fri Sat ";
+ALIGN(4) static const char *months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
-int __isleap(int year)
+static int __isleap(int year)
{
/* every fourth year is a leap year except for century years that are
* not divisible by 400. */
@@ -45,6 +71,106 @@ int __isleap(int year)
return (!(year % 4) && ((year % 100) || !(year % 400)));
}
+static void num2str(char *c, int i)
+{
+ c[0] = i / 10 + '0';
+ c[1] = i % 10 + '0';
+}
+
+/**
+ * Get time from RTC device (without timezone, UTC+0)
+ * @param tv: struct timeval
+ * @return the operation status, RT_EOK on successful
+ */
+static rt_err_t get_timeval(struct timeval *tv)
+{
+#ifdef RT_USING_RTC
+ static rt_device_t device = RT_NULL;
+ rt_err_t rst = -RT_ERROR;
+
+ if (tv == RT_NULL)
+ return -RT_EINVAL;
+
+ /* default is 0 */
+ tv->tv_sec = 0;
+ tv->tv_usec = 0;
+
+ /* optimization: find rtc device only first */
+ if (device == RT_NULL)
+ {
+ device = rt_device_find("rtc");
+ }
+
+ /* read timestamp from RTC device */
+ if (device != RT_NULL)
+ {
+ if (rt_device_open(device, 0) == RT_EOK)
+ {
+ rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &tv->tv_sec);
+ rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIMEVAL, tv);
+ rt_device_close(device);
+ }
+ }
+ else
+ {
+ /* LOG_W will cause a recursive printing if ulog timestamp function is enabled */
+ rt_kprintf(_WARNING_NO_RTC);
+ return -RT_ENOSYS;
+ }
+
+ return rst;
+
+#else
+ /* LOG_W will cause a recursive printing if ulog timestamp function is enabled */
+ rt_kprintf(_WARNING_NO_RTC);
+ return -RT_ENOSYS;
+#endif /* RT_USING_RTC */
+}
+
+/**
+ * Set time to RTC device (without timezone)
+ * @param tv: struct timeval
+ * @return the operation status, RT_EOK on successful
+ */
+static int set_timeval(struct timeval *tv)
+{
+#ifdef RT_USING_RTC
+ static rt_device_t device = RT_NULL;
+ rt_err_t rst = -RT_ERROR;
+
+ if (tv == RT_NULL)
+ return -RT_EINVAL;
+
+ /* optimization: find rtc device only first */
+ if (device == RT_NULL)
+ {
+ device = rt_device_find("rtc");
+ }
+
+ /* read timestamp from RTC device */
+ if (device != RT_NULL)
+ {
+ if (rt_device_open(device, 0) == RT_EOK)
+ {
+ rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &tv->tv_sec);
+ rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIMEVAL, tv);
+ rt_device_close(device);
+ }
+ }
+ else
+ {
+ LOG_W(_WARNING_NO_RTC);
+ return -RT_ENOSYS;
+ }
+
+ return rst;
+
+#else
+ LOG_W(_WARNING_NO_RTC);
+ return -RT_ENOSYS;
+#endif /* RT_USING_RTC */
+}
+
struct tm *gmtime_r(const time_t *timep, struct tm *r)
{
time_t i;
@@ -78,32 +204,174 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r)
;
r->tm_mon = i;
r->tm_mday += work - __spm[i];
+
+ r->tm_isdst = tz_is_dst();
return r;
}
+RTM_EXPORT(gmtime_r);
struct tm* gmtime(const time_t* t)
{
static struct tm tmp;
return gmtime_r(t, &tmp);
}
+RTM_EXPORT(gmtime);
-/*TODO timezone is not supprt now */
struct tm* localtime_r(const time_t* t, struct tm* r)
{
- return gmtime_r(t, r);
+ time_t local_tz;
+
+ local_tz = *t + (time_t)tz_get() * 3600;
+ return gmtime_r(&local_tz, r);
}
+RTM_EXPORT(localtime_r);
struct tm* localtime(const time_t* t)
{
static struct tm tmp;
return localtime_r(t, &tmp);
}
+RTM_EXPORT(localtime);
time_t mktime(struct tm * const t)
{
+ time_t timestamp;
+
+ timestamp = timegm(t);
+ timestamp = timestamp - 3600 * (time_t)tz_get();
+ return timestamp;
+}
+RTM_EXPORT(mktime);
+
+char* asctime_r(const struct tm *t, char *buf)
+{
+ /* Checking input validity */
+ if ((int)rt_strlen(days) <= (t->tm_wday << 2) || (int)rt_strlen(months) <= (t->tm_mon << 2))
+ {
+ LOG_W("asctime_r: the input parameters exceeded the limit, please check it.");
+ *(int*) buf = *(int*) days;
+ *(int*) (buf + 4) = *(int*) months;
+ num2str(buf + 8, t->tm_mday);
+ if (buf[8] == '0')
+ buf[8] = ' ';
+ buf[10] = ' ';
+ num2str(buf + 11, t->tm_hour);
+ buf[13] = ':';
+ num2str(buf + 14, t->tm_min);
+ buf[16] = ':';
+ num2str(buf + 17, t->tm_sec);
+ buf[19] = ' ';
+ num2str(buf + 20, 2000 / 100);
+ num2str(buf + 22, 2000 % 100);
+ buf[24] = '\n';
+ buf[25] = '\0';
+ return buf;
+ }
+
+ /* "Wed Jun 30 21:49:08 1993\n" */
+ *(int*) buf = *(int*) (days + (t->tm_wday << 2));
+ *(int*) (buf + 4) = *(int*) (months + (t->tm_mon << 2));
+ num2str(buf + 8, t->tm_mday);
+ if (buf[8] == '0')
+ buf[8] = ' ';
+ buf[10] = ' ';
+ num2str(buf + 11, t->tm_hour);
+ buf[13] = ':';
+ num2str(buf + 14, t->tm_min);
+ buf[16] = ':';
+ num2str(buf + 17, t->tm_sec);
+ buf[19] = ' ';
+ num2str(buf + 20, (t->tm_year + 1900) / 100);
+ num2str(buf + 22, (t->tm_year + 1900) % 100);
+ buf[24] = '\n';
+ buf[25] = '\0';
+ return buf;
+}
+RTM_EXPORT(asctime_r);
+
+char* asctime(const struct tm *timeptr)
+{
+ static char buf[26];
+ return asctime_r(timeptr, buf);
+}
+RTM_EXPORT(asctime);
+
+char *ctime_r(const time_t * tim_p, char * result)
+{
+ struct tm tm;
+ return asctime_r(localtime_r(tim_p, &tm), result);
+}
+RTM_EXPORT(ctime_r);
+
+char* ctime(const time_t *tim_p)
+{
+ return asctime(localtime(tim_p));
+}
+RTM_EXPORT(ctime);
+
+/**
+ * Returns the current time.
+ *
+ * @param time_t * t the timestamp pointer, if not used, keep NULL.
+ *
+ * @return The value ((time_t)-1) is returned if the calendar time is not available.
+ * If timer is not a NULL pointer, the return value is also stored in timer.
+ *
+ */
+RT_WEAK time_t time(time_t *t)
+{
+ struct timeval now;
+
+ if(get_timeval(&now) == RT_EOK)
+ {
+ if (t)
+ {
+ *t = now.tv_sec;
+ }
+ return now.tv_sec;
+ }
+ else
+ {
+ rt_set_errno(EFAULT);
+ return ((time_t)-1);
+ }
+}
+RTM_EXPORT(time);
+
+RT_WEAK clock_t clock(void)
+{
+ return rt_tick_get();
+}
+RTM_EXPORT(clock);
+
+int stime(const time_t *t)
+{
+ struct timeval tv;
+
+ if (!t)
+ {
+ rt_set_errno(EFAULT);
+ return -1;
+ }
+
+ tv.tv_sec = *t;
+ if (set_timeval(&tv) == RT_EOK)
+ {
+ return 0;
+ }
+ else
+ {
+ rt_set_errno(EFAULT);
+ return -1;
+ }
+}
+RTM_EXPORT(stime);
+
+time_t timegm(struct tm * const t)
+{
register time_t day;
register time_t i;
- register time_t years = t->tm_year - 70;
+ register time_t years = (time_t)t->tm_year - 70;
if (t->tm_sec > 60)
{
@@ -172,121 +440,566 @@ time_t mktime(struct tm * const t)
i = 60;
return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec;
}
+RTM_EXPORT(timegm);
-static void num2str(char *c, int i)
+int gettimeofday(struct timeval *tv, struct timezone *tz)
{
- c[0] = i / 10 + '0';
- c[1] = i % 10 + '0';
-}
+ /* The use of the timezone structure is obsolete;
+ * the tz argument should normally be specified as NULL.
+ * The tz_dsttime field has never been used under Linux.
+ * Thus, the following is purely of historic interest.
+ */
+ if(tz != RT_NULL)
+ {
+ tz->tz_dsttime = DST_NONE;
+ tz->tz_minuteswest = -(tz_get() * 60);
+ }
-char* asctime_r(const struct tm *t, char *buf)
-{
- /* "Wed Jun 30 21:49:08 1993\n" */
- *(int*) buf = *(int*) (days + (t->tm_wday << 2));
- *(int*) (buf + 4) = *(int*) (months + (t->tm_mon << 2));
- num2str(buf + 8, t->tm_mday);
- if (buf[8] == '0')
- buf[8] = ' ';
- buf[10] = ' ';
- num2str(buf + 11, t->tm_hour);
- buf[13] = ':';
- num2str(buf + 14, t->tm_min);
- buf[16] = ':';
- num2str(buf + 17, t->tm_sec);
- buf[19] = ' ';
- num2str(buf + 20, (t->tm_year + 1900) / 100);
- num2str(buf + 22, (t->tm_year + 1900) % 100);
- buf[24] = '\n';
- return buf;
+ if (tv != RT_NULL && get_timeval(tv) == RT_EOK)
+ {
+ return 0;
+ }
+ else
+ {
+ rt_set_errno(EFAULT);
+ return -1;
+ }
}
+RTM_EXPORT(gettimeofday);
-char* asctime(const struct tm *timeptr)
+int settimeofday(const struct timeval *tv, const struct timezone *tz)
{
- static char buf[25];
- return asctime_r(timeptr, buf);
+ /* The use of the timezone structure is obsolete;
+ * the tz argument should normally be specified as NULL.
+ * The tz_dsttime field has never been used under Linux.
+ * Thus, the following is purely of historic interest.
+ */
+ if (tv != RT_NULL
+ && tv->tv_usec >= 0
+ && set_timeval((struct timeval *)tv) == RT_EOK)
+ {
+ return 0;
+ }
+ else
+ {
+ rt_set_errno(EINVAL);
+ return -1;
+ }
}
+RTM_EXPORT(settimeofday);
+
+/* inherent in the toolchain */
+RTM_EXPORT(difftime);
+RTM_EXPORT(strftime);
-char* ctime(const time_t *timep)
+#ifdef RT_USING_POSIX_DELAY
+int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
{
- return asctime(localtime(timep));
+ sleep(rqtp->tv_sec);
+ ndelay(rqtp->tv_nsec);
+ return 0;
}
+RTM_EXPORT(nanosleep);
+#endif /* RT_USING_POSIX_DELAY */
-#endif /* __IAR_SYSTEMS_ICC__ */
-
-int gettimeofday(struct timeval *tp, void *ignore)
+#ifdef RT_USING_POSIX_CLOCK
+#ifdef RT_USING_RTC
+static volatile struct timeval _timevalue;
+static int _rt_clock_time_system_init()
{
+ register rt_base_t level;
time_t time = 0;
-#ifdef RT_USING_DEVICE
+ rt_tick_t tick;
rt_device_t device;
+
device = rt_device_find("rtc");
- RT_ASSERT(device != RT_NULL);
- rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time);
- if (tp != RT_NULL)
+ if (device != RT_NULL)
+ {
+ /* get realtime seconds */
+ if(rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time) == RT_EOK)
+ {
+ level = rt_hw_interrupt_disable();
+ tick = rt_tick_get(); /* get tick */
+ _timevalue.tv_usec = (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK;
+ _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1;
+ rt_hw_interrupt_enable(level);
+ return 0;
+ }
+ }
+
+ level = rt_hw_interrupt_disable();
+ _timevalue.tv_usec = 0;
+ _timevalue.tv_sec = 0;
+ rt_hw_interrupt_enable(level);
+
+ return -1;
+}
+INIT_COMPONENT_EXPORT(_rt_clock_time_system_init);
+#endif /* RT_USING_RTC */
+
+int clock_getres(clockid_t clockid, struct timespec *res)
+{
+#ifndef RT_USING_RTC
+ LOG_W(_WARNING_NO_RTC);
+ return -1;
+#else
+ int ret = 0;
+
+ if (res == RT_NULL)
+ {
+ rt_set_errno(EINVAL);
+ return -1;
+ }
+
+ switch (clockid)
{
- tp->tv_sec = time;
- tp->tv_usec = 0;
+ case CLOCK_REALTIME:
+ res->tv_sec = 0;
+ res->tv_nsec = NANOSECOND_PER_SECOND/RT_TICK_PER_SECOND;
+ break;
+
+#ifdef RT_USING_CPUTIME
+ case CLOCK_CPUTIME_ID:
+ res->tv_sec = 0;
+ res->tv_nsec = clock_cpu_getres();
+ break;
+#endif
+
+ default:
+ ret = -1;
+ rt_set_errno(EINVAL);
+ break;
}
+
+ return ret;
+#endif /* RT_USING_RTC */
+}
+RTM_EXPORT(clock_getres);
+
+int clock_gettime(clockid_t clockid, struct timespec *tp)
+{
+#ifndef RT_USING_RTC
+ LOG_W(_WARNING_NO_RTC);
+ return -1;
#else
- tv->tv_sec = 0;
- tv->tv_usec = 0;
+ int ret = 0;
+
+ if (tp == RT_NULL)
+ {
+ rt_set_errno(EINVAL);
+ return -1;
+ }
+
+ switch (clockid)
+ {
+ case CLOCK_REALTIME:
+ {
+ int tick;
+ register rt_base_t level;
+
+ level = rt_hw_interrupt_disable();
+ tick = rt_tick_get(); /* get tick */
+ tp->tv_sec = _timevalue.tv_sec + tick / RT_TICK_PER_SECOND;
+ tp->tv_nsec = (_timevalue.tv_usec + (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK) * 1000;
+ rt_hw_interrupt_enable(level);
+ }
+ break;
+
+#ifdef RT_USING_CPUTIME
+ case CLOCK_CPUTIME_ID:
+ {
+ float unit = 0;
+ long long cpu_tick;
+
+ unit = clock_cpu_getres();
+ cpu_tick = clock_cpu_gettime();
+
+ tp->tv_sec = ((int)(cpu_tick * unit)) / NANOSECOND_PER_SECOND;
+ tp->tv_nsec = ((int)(cpu_tick * unit)) % NANOSECOND_PER_SECOND;
+ }
+ break;
#endif
+ default:
+ rt_set_errno(EINVAL);
+ ret = -1;
+ }
+
+ return ret;
+#endif /* RT_USING_RTC */
+}
+RTM_EXPORT(clock_gettime);
+
+int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, struct timespec *rmtp)
+{
+ if ((clockid != CLOCK_REALTIME) || (rqtp == RT_NULL))
+ {
+ rt_set_errno(EINVAL);
+ return -1;
+ }
+
+ return nanosleep(rqtp, rmtp);
+}
+
+int clock_settime(clockid_t clockid, const struct timespec *tp)
+{
+#ifndef RT_USING_RTC
+ LOG_W(_WARNING_NO_RTC);
+ return -1;
+#else
+ register rt_base_t level;
+ int second;
+ rt_tick_t tick;
+ rt_device_t device;
+
+ if ((clockid != CLOCK_REALTIME) || (tp == RT_NULL))
+ {
+ rt_set_errno(EINVAL);
+ return -1;
+ }
+
+ /* get second */
+ second = tp->tv_sec;
+
+ level = rt_hw_interrupt_disable();
+ tick = rt_tick_get(); /* get tick */
+ /* update timevalue */
+ _timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK;
+ _timevalue.tv_sec = second - tick/RT_TICK_PER_SECOND - 1;
+ rt_hw_interrupt_enable(level);
+
+ /* update for RTC device */
+ device = rt_device_find("rtc");
+ if (device != RT_NULL)
+ {
+ /* set realtime seconds */
+ if(rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second) == RT_EOK)
+ {
+ return 0;
+ }
+ }
- return time;
+ return -1;
+#endif /* RT_USING_RTC */
}
+RTM_EXPORT(clock_settime);
+
+int rt_timespec_to_tick(const struct timespec *time)
+{
+ int tick;
+ int nsecond, second;
+ struct timespec tp;
+ RT_ASSERT(time != RT_NULL);
+
+ tick = RT_WAITING_FOREVER;
+ if (time != NULL)
+ {
+ /* get current tp */
+ clock_gettime(CLOCK_REALTIME, &tp);
+
+ if ((time->tv_nsec - tp.tv_nsec) < 0)
+ {
+ nsecond = NANOSECOND_PER_SECOND - (tp.tv_nsec - time->tv_nsec);
+ second = time->tv_sec - tp.tv_sec - 1;
+ }
+ else
+ {
+ nsecond = time->tv_nsec - tp.tv_nsec;
+ second = time->tv_sec - tp.tv_sec;
+ }
+
+ tick = second * RT_TICK_PER_SECOND + nsecond * RT_TICK_PER_SECOND / NANOSECOND_PER_SECOND;
+ if (tick < 0) tick = 0;
+ }
+
+ return tick;
+}
+RTM_EXPORT(rt_timespec_to_tick);
+
+#endif /* RT_USING_POSIX_CLOCK */
+
+#ifdef RT_USING_POSIX_TIMER
+
+#define ACTIVE 1
+#define NOT_ACTIVE 0
+
+struct timer_obj
+{
+ struct rt_timer timer;
+ void (*sigev_notify_function)(union sigval val);
+ union sigval val;
+ struct timespec interval; /* Reload value */
+ rt_uint32_t reload; /* Reload value in ms */
+ rt_uint32_t status;
+};
+
+static void rtthread_timer_wrapper(void *timerobj)
+{
+ struct timer_obj *timer;
+
+ timer = (struct timer_obj *)timerobj;
+
+ if (timer->reload == 0U)
+ {
+ timer->status = NOT_ACTIVE;
+ }
+
+ if(timer->sigev_notify_function != RT_NULL)
+ {
+ (timer->sigev_notify_function)(timer->val);
+ }
+}
/**
- * Returns the current time.
+ * @brief Create a per-process timer.
*
- * @param time_t * t the timestamp pointer, if not used, keep NULL.
+ * This API does not accept SIGEV_THREAD as valid signal event notification
+ * type.
*
- * @return time_t return timestamp current.
+ * See IEEE 1003.1
+ */
+int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid)
+{
+ static int num = 0;
+ struct timer_obj *timer;
+ char timername[RT_NAME_MAX] = {0};
+
+ if (clockid != CLOCK_MONOTONIC || evp == NULL ||
+ (evp->sigev_notify != SIGEV_NONE &&
+ evp->sigev_notify != SIGEV_SIGNAL))
+ {
+ rt_set_errno(EINVAL);
+ return -RT_ERROR;
+ }
+
+ timer = rt_malloc(sizeof(struct timer_obj));
+ if(timer == RT_NULL)
+ {
+ rt_set_errno(ENOMEM);
+ return -RT_ENOMEM;
+ }
+
+ RT_ASSERT(evp->sigev_notify_function != RT_NULL);
+ rt_snprintf(timername, RT_NAME_MAX, "psx_tm%02d", num++);
+ num %= 100;
+ timer->sigev_notify_function = evp->sigev_notify_function;
+ timer->val = evp->sigev_value;
+ timer->interval.tv_sec = 0;
+ timer->interval.tv_nsec = 0;
+ timer->reload = 0U;
+ timer->status = NOT_ACTIVE;
+
+ if (evp->sigev_notify == SIGEV_NONE)
+ {
+ rt_timer_init(&timer->timer, timername, RT_NULL, RT_NULL, 0, RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_SOFT_TIMER);
+ }
+ else
+ {
+ rt_timer_init(&timer->timer, timername, rtthread_timer_wrapper, timer, 0, RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_SOFT_TIMER);
+ }
+
+ *timerid = (timer_t)timer;
+
+ return RT_EOK;
+}
+RTM_EXPORT(timer_create);
+
+/**
+ * @brief Delete a per-process timer.
*
+ * See IEEE 1003.1
*/
-/* for IAR 6.2 later Compiler */
-#if defined (__IAR_SYSTEMS_ICC__) && (__VER__) >= 6020000
-#pragma module_name = "?time"
-#if _DLIB_TIME_USES_64
-time_t __time64(time_t *t)
-#else
-time_t __time32(time_t *t)
-#endif
-#else
-time_t time(time_t *t)
-#endif
+int timer_delete(timer_t timerid)
{
- time_t time_now = 0;
+ struct timer_obj *timer = (struct timer_obj *)timerid;
-#ifdef RT_USING_RTC
- static rt_device_t device = RT_NULL;
+ if (timer == RT_NULL)
+ {
+ rt_set_errno(EINVAL);
+ return -RT_ERROR;
+ }
- /* optimization: find rtc device only first. */
- if (device == RT_NULL)
+ if (timer->status == ACTIVE)
{
- device = rt_device_find("rtc");
+ timer->status = NOT_ACTIVE;
+ rt_timer_stop(&timer->timer);
}
- /* read timestamp from RTC device. */
- if (device != RT_NULL)
+ rt_free(timer);
+
+ return RT_EOK;
+}
+RTM_EXPORT(timer_delete);
+
+/**
+ *
+ * Return the overrun count for the last timer expiration.
+ * It is subefficient to create a new structure to get overrun count.
+ **/
+int timer_getoverrun(timer_t timerid)
+{
+ rt_set_errno(ENOSYS);
+ return -RT_ERROR;
+}
+
+/**
+ * @brief Get amount of time left for expiration on a per-process timer.
+ *
+ * See IEEE 1003.1
+ */
+int timer_gettime(timer_t timerid, struct itimerspec *its)
+{
+ struct timer_obj *timer = (struct timer_obj *)timerid;
+ rt_tick_t remaining;
+ rt_uint32_t seconds, nanoseconds;
+
+ if (timer == NULL)
{
- if (rt_device_open(device, 0) == RT_EOK)
+ rt_set_errno(EINVAL);
+ return -RT_ERROR;
+ }
+
+ if (its == NULL)
+ {
+ rt_set_errno(EFAULT);
+ return -RT_ERROR;
+ }
+
+ if (timer->status == ACTIVE)
+ {
+ rt_tick_t remain_tick;
+
+ rt_timer_control(&timer->timer, RT_TIMER_CTRL_GET_REMAIN_TIME, &remain_tick);
+
+ /* 'remain_tick' is minimum-unit in the RT-Thread' timer,
+ * so the seconds, nanoseconds will be calculated by 'remain_tick'.
+ */
+ remaining = remain_tick - rt_tick_get();
+
+ /* calculate 'second' */
+ seconds = remaining / RT_TICK_PER_SECOND;
+
+ /* calculate 'nanosecond'; To avoid lost of accuracy, because "RT_TICK_PER_SECOND" maybe 100, 1000, 1024 and so on.
+ *
+ * remain_tick millisecond remain_tick * MILLISECOND_PER_SECOND
+ * ------------------------- = -------------------------- ---> millisecond = -------------------------------------------
+ * RT_TICK_PER_SECOND MILLISECOND_PER_SECOND RT_TICK_PER_SECOND
+ *
+ * remain_tick * MILLISECOND_PER_SECOND remain_tick * MILLISECOND_PER_SECOND * MICROSECOND_PER_SECOND
+ * millisecond = ---------------------------------------- ---> nanosecond = -------------------------------------------------------------------
+ * RT_TICK_PER_SECOND RT_TICK_PER_SECOND
+ *
+ */
+ nanoseconds = (((remaining % RT_TICK_PER_SECOND) * MILLISECOND_PER_SECOND) * MICROSECOND_PER_SECOND) / RT_TICK_PER_SECOND ;
+
+ its->it_value.tv_sec = (rt_int32_t)seconds;
+ its->it_value.tv_nsec = (rt_int32_t)nanoseconds;
+ }
+ else
+ {
+ /* Timer is disarmed */
+ its->it_value.tv_sec = 0;
+ its->it_value.tv_nsec = 0;
+ }
+
+ /* The interval last set by timer_settime() */
+ its->it_interval = timer->interval;
+ return RT_EOK;
+}
+RTM_EXPORT(timer_gettime);
+
+/**
+ * @brief Sets expiration time of per-process timer.
+ *
+ * See IEEE 1003.1
+ */
+int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
+ struct itimerspec *ovalue)
+{
+ struct timer_obj *timer = (struct timer_obj *)timerid;
+
+ if (timer == NULL ||
+ value->it_interval.tv_nsec < 0 ||
+ value->it_interval.tv_nsec >= NANOSECOND_PER_SECOND ||
+ value->it_value.tv_nsec < 0 ||
+ value->it_value.tv_nsec >= NANOSECOND_PER_SECOND)
+ {
+ rt_set_errno(EINVAL);
+ return -RT_ERROR;
+ }
+
+ if (value == NULL || ovalue == NULL)
+ {
+ rt_set_errno(EFAULT);
+ return -RT_ERROR;
+ }
+
+ /* Save time to expire and old reload value. */
+ if (ovalue != NULL)
+ {
+ timer_gettime(timerid, ovalue);
+ }
+
+ /* Stop the timer if the value is 0 */
+ if ((value->it_value.tv_sec == 0) && (value->it_value.tv_nsec == 0))
+ {
+ if (timer->status == ACTIVE)
{
- rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now);
- rt_device_close(device);
+ rt_timer_stop(&timer->timer);
}
+
+ timer->status = NOT_ACTIVE;
+ return RT_EOK;
}
-#endif /* RT_USING_RTC */
- /* if t is not NULL, write timestamp to *t */
- if (t != RT_NULL)
+ /* calculate timer period(tick); To avoid lost of accuracy, because "RT_TICK_PER_SECOND" maybe 100, 1000, 1024 and so on.
+ *
+ * tick nanosecond nanosecond * RT_TICK_PER_SECOND
+ * ------------------------- = -------------------------- ---> tick = -------------------------------------
+ * RT_TICK_PER_SECOND NANOSECOND_PER_SECOND NANOSECOND_PER_SECOND
+ *
+ */
+ timer->reload = (value->it_interval.tv_sec * RT_TICK_PER_SECOND) + (value->it_interval.tv_nsec * RT_TICK_PER_SECOND) / NANOSECOND_PER_SECOND;
+ timer->interval.tv_sec = value->it_interval.tv_sec;
+ timer->interval.tv_nsec = value->it_interval.tv_nsec;
+
+ if (timer->status == ACTIVE)
{
- *t = time_now;
+ rt_timer_stop(&timer->timer);
}
- return time_now;
+ timer->status = ACTIVE;
+ rt_timer_control(&timer->timer, RT_TIMER_CTRL_SET_TIME, (void *)timer->reload);
+ rt_timer_control(&timer->timer, RT_TIMER_CTRL_SET_PERIODIC, RT_NULL);
+ rt_timer_start(&timer->timer);
+
+ return RT_EOK;
}
+RTM_EXPORT(timer_settime);
+#endif /* RT_USING_POSIX_TIMER */
-RT_WEAK clock_t clock(void)
+
+/* timezone */
+#ifndef RT_LIBC_DEFAULT_TIMEZONE
+#define RT_LIBC_DEFAULT_TIMEZONE 8
+#endif
+
+static volatile int8_t _current_timezone = RT_LIBC_DEFAULT_TIMEZONE;
+
+void tz_set(int8_t tz)
{
- return rt_tick_get();
+ register rt_base_t level;
+ level = rt_hw_interrupt_disable();
+ _current_timezone = tz;
+ rt_hw_interrupt_enable(level);
+}
+
+int8_t tz_get(void)
+{
+ return _current_timezone;
+}
+
+int8_t tz_is_dst(void)
+{
+ return 0;
}
diff --git a/components/libc/compilers/common/unistd.c b/components/libc/compilers/common/unistd.c
deleted file mode 100644
index df970b2b59..0000000000
--- a/components/libc/compilers/common/unistd.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2020-09-01 Meco Man First Version
- */
-
-#include <unistd.h>
-
-#ifdef RT_USING_POSIX_TERMIOS
-#include "termios.h"
-
-int isatty(int fd)
-{
- struct termios ts;
- return(tcgetattr(fd,&ts) != -1);/*true if no error (is a tty)*/
-}
-#endif
-
-char *ttyname(int fd)
-{
- return "/dev/tty0"; /*TODO: need to add more specific*/
-}
diff --git a/components/libc/compilers/dlib/README.md b/components/libc/compilers/dlib/README.md
index acd08f9074..e4d70e8135 100644
--- a/components/libc/compilers/dlib/README.md
+++ b/components/libc/compilers/dlib/README.md
@@ -1,9 +1,3 @@
# DLIB (IAR) porting for RT-Thread
-Please define RT_USING_LIBC and compile RT-Thread with IAR compiler.
-
-
-
-## More Information
-
http://www.iarsys.co.jp/download/LMS2/arm/7502/ewarm7502doc/arm/doc/EWARM_DevelopmentGuide.ENU.pdf P.130 \ No newline at end of file
diff --git a/components/libc/compilers/dlib/SConscript b/components/libc/compilers/dlib/SConscript
index 75a5812fab..e11ea65b97 100644
--- a/components/libc/compilers/dlib/SConscript
+++ b/components/libc/compilers/dlib/SConscript
@@ -1,26 +1,20 @@
from building import *
-
Import('rtconfig')
src = Glob('*.c')
-cwd = GetCurrentDir()
group = []
-CPPPATH = [cwd]
CPPDEFINES = ['RT_USING_DLIBC']
if rtconfig.PLATFORM == 'iar':
-
- if GetDepend('RT_USING_DFS'):
+ if GetDepend('DFS_USING_POSIX'):
from distutils.version import LooseVersion
from iar import IARVersion
CPPDEFINES = CPPDEFINES + ['_DLIB_FILE_DESCRIPTOR']
-
if LooseVersion(IARVersion()) < LooseVersion("8.20.1"):
CPPDEFINES = CPPDEFINES + ['_DLIB_THREAD_SUPPORT']
- group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'],
- CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
+ group = DefineGroup('Compiler', src, depend = [''], CPPDEFINES = CPPDEFINES)
Return('group')
diff --git a/components/libc/compilers/dlib/environ.c b/components/libc/compilers/dlib/environ.c
index ac19758838..84b04fda55 100644
--- a/components/libc/compilers/dlib/environ.c
+++ b/components/libc/compilers/dlib/environ.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/dlib/fcntl.h b/components/libc/compilers/dlib/fcntl.h
deleted file mode 100644
index ce95230e88..0000000000
--- a/components/libc/compilers/dlib/fcntl.h
+++ /dev/null
@@ -1,8 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
diff --git a/components/libc/compilers/dlib/libc.c b/components/libc/compilers/dlib/libc.c
deleted file mode 100644
index 8b42411a6b..0000000000
--- a/components/libc/compilers/dlib/libc.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/10/15 bernard the first version
- */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <rtthread.h>
-
-#include "libc.h"
-
-#ifdef RT_USING_PTHREADS
-#include <pthread.h>
-#endif
-
-int libc_system_init(void)
-{
-#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS)
- rt_device_t dev_console;
-
- dev_console = rt_console_get_device();
- if (dev_console)
- {
- #if defined(RT_USING_POSIX)
- libc_stdio_set_console(dev_console->parent.name, O_RDWR);
- #else
- libc_stdio_set_console(dev_console->parent.name, O_WRONLY);
- #endif
- }
-#endif
-
-#if defined (RT_USING_PTHREADS) && !defined (RT_USING_COMPONENTS_INIT)
- pthread_system_init();
-#endif
-
- return 0;
-}
-INIT_COMPONENT_EXPORT(libc_system_init);
-
diff --git a/components/libc/compilers/dlib/rmtx.c b/components/libc/compilers/dlib/rmtx.c
deleted file mode 100644
index 69405c8f6a..0000000000
--- a/components/libc/compilers/dlib/rmtx.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2015-01-28 Bernard first version
- */
-#include <rtthread.h>
-#include <yfuns.h>
-
-/*
- * for IAR compiler, we recommand to define _DLIB_THREAD_SUPPORT
- * as 2 for dlib multi-thread support.
- */
-
-#if _DLIB_THREAD_SUPPORT
-typedef void* _Rmtx;
-void _Mtxinit(_Rmtx *m)
-{
- rt_mutex_t mutex;
-
- RT_ASSERT(m != RT_NULL);
-
- mutex = (rt_mutex_t)m;
- rt_mutex_init(mutex, "iarMtx", RT_IPC_FLAG_FIFO);
-}
-
-void _Mtxdst(_Rmtx *m)
-{
- rt_mutex_t mutex;
-
- RT_ASSERT(m != RT_NULL);
-
- mutex = (rt_mutex_t)m;
- rt_mutex_detach(mutex);
-}
-
-void _Mtxlock(_Rmtx *m)
-{
- rt_mutex_t mutex;
-
- RT_ASSERT(m != RT_NULL);
-
- mutex = (rt_mutex_t)m;
- rt_mutex_take(mutex, RT_WAITING_FOREVER);
-}
-
-void _Mtxunlock(_Rmtx *m)
-{
- rt_mutex_t mutex;
-
- RT_ASSERT(m != RT_NULL);
-
- mutex = (rt_mutex_t)m;
- rt_mutex_release(mutex);
-}
-#endif
-
diff --git a/components/libc/compilers/dlib/stdio.c b/components/libc/compilers/dlib/stdio.c
deleted file mode 100644
index b35ade7a38..0000000000
--- a/components/libc/compilers/dlib/stdio.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/10/15 bernard implement stdio for IAR dlib.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <rtthread.h>
-#include "libc.h"
-
-#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS)
-#include <dfs_posix.h>
-
-#define STDIO_DEVICE_NAME_MAX 32
-
-static int std_fd = -1;
-int libc_stdio_set_console(const char* device_name, int mode)
-{
- int fd;
- char name[STDIO_DEVICE_NAME_MAX];
-
- snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
- name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
-
- fd = open(name, mode, 0);
- if (fd >= 0)
- {
- if (std_fd >= 0)
- {
- close(std_fd);
- }
- std_fd = fd;
- }
-
- return std_fd;
-}
-
-int libc_stdio_get_console(void) {
- return std_fd;
-}
-
-int libc_stdio_read(void *buffer, size_t size)
-{
- return read(std_fd, buffer, size);
-}
-
-int libc_stdio_write(const void *buffer, size_t size)
-{
- return write(std_fd, buffer, size);
-}
-#endif
diff --git a/components/libc/compilers/dlib/sys/README.md b/components/libc/compilers/dlib/sys/README.md
deleted file mode 100644
index 4f0d203180..0000000000
--- a/components/libc/compilers/dlib/sys/README.md
+++ /dev/null
@@ -1 +0,0 @@
-Because IAR leaks some system header file, we put them in here. \ No newline at end of file
diff --git a/components/libc/compilers/dlib/sys/errno.h b/components/libc/compilers/dlib/sys/errno.h
deleted file mode 100644
index 1ad4c8acc0..0000000000
--- a/components/libc/compilers/dlib/sys/errno.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2019-07-08 Bernard The first version
- */
-
-#ifndef SYS_ERRNO_H__
-#define SYS_ERRNO_H__
-
-#include <errno.h>
-
-#endif
diff --git a/components/libc/compilers/dlib/sys/signal.h b/components/libc/compilers/dlib/sys/signal.h
deleted file mode 100644
index 22adb1228b..0000000000
--- a/components/libc/compilers/dlib/sys/signal.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2019-07-08 Bernard The first version
- */
-
-#ifndef SYS_SIGNAL_H__
-#define SYS_SIGNAL_H__
-
-#include <libc/libc_signal.h>
-
-#endif
diff --git a/components/libc/compilers/dlib/sys/stat.h b/components/libc/compilers/dlib/sys/stat.h
deleted file mode 100644
index ce95230e88..0000000000
--- a/components/libc/compilers/dlib/sys/stat.h
+++ /dev/null
@@ -1,8 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
diff --git a/components/libc/compilers/dlib/sys/types.h b/components/libc/compilers/dlib/sys/types.h
deleted file mode 100644
index 7dbeddcaa9..0000000000
--- a/components/libc/compilers/dlib/sys/types.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2020-12-16 Meco Man add useconds_t
- */
-#ifndef __TYPES_H__
-#define __TYPES_H__
-
-#include <stdint.h>
-
-typedef int32_t clockid_t;
-typedef int32_t key_t; /* Used for interprocess communication. */
-typedef int32_t pid_t; /* Used for process IDs and process group IDs. */
-#ifndef ARCH_CPU_64BIT
-typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */
-#else
-typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */
-#endif
-typedef unsigned long useconds_t; /* microseconds (unsigned) */
-
-#endif
diff --git a/components/libc/compilers/dlib/sys/unistd.h b/components/libc/compilers/dlib/sys/unistd.h
deleted file mode 100644
index 6d99cd6c55..0000000000
--- a/components/libc/compilers/dlib/sys/unistd.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2020-12-16 Meco Man add usleep
- */
-#ifndef _SYS_UNISTD_H
-#define _SYS_UNISTD_H
-
-#include <rtconfig.h>
-#include "types.h"
-
-#ifdef RT_USING_DFS
-
-#define STDIN_FILENO 0 /* standard input file descriptor */
-#define STDOUT_FILENO 1 /* standard output file descriptor */
-#define STDERR_FILENO 2 /* standard error file descriptor */
-
-#include <dfs_posix.h>
-#else
-#define _FREAD 0x0001 /* read enabled */
-#define _FWRITE 0x0002 /* write enabled */
-#define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */
-#define _FMARK 0x0010 /* internal; mark during gc() */
-#define _FDEFER 0x0020 /* internal; defer for next gc pass */
-#define _FASYNC 0x0040 /* signal pgrp when data ready */
-#define _FSHLOCK 0x0080 /* BSD flock() shared lock present */
-#define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */
-#define _FCREAT 0x0200 /* open with file create */
-#define _FTRUNC 0x0400 /* open with truncation */
-#define _FEXCL 0x0800 /* error on open if file exists */
-#define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */
-#define _FSYNC 0x2000 /* do all writes synchronously */
-#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */
-#define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */
-#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */
-
-#endif
-
-
-int isatty (int fd);
-char * ttyname (int desc);
-
-unsigned int sleep(unsigned int seconds);
-int usleep(useconds_t usec);
-
-#endif /* _SYS_UNISTD_H */
diff --git a/components/libc/compilers/dlib/syscall_close.c b/components/libc/compilers/dlib/syscall_close.c
index f46162deb7..736023023d 100644
--- a/components/libc/compilers/dlib/syscall_close.c
+++ b/components/libc/compilers/dlib/syscall_close.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -7,23 +7,32 @@
* Date Author Notes
* 2015-01-28 Bernard first version
*/
+
#include <rtthread.h>
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
-#include <yfuns.h>
+#include <LowLevelIOInterface.h>
+#include <unistd.h>
+#include <compiler_private.h>
+#define DBG_TAG "dlib.syscall.close"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
+/*
+ * The "__close" function should close the file corresponding to
+ * "handle". It should return 0 on success and nonzero on failure.
+ */
#pragma module_name = "?__close"
+
int __close(int handle)
{
if (handle == _LLIO_STDOUT ||
handle == _LLIO_STDERR ||
handle == _LLIO_STDIN)
return _LLIO_ERROR;
-
-#ifdef RT_USING_DFS
+#ifdef DFS_USING_POSIX
return close(handle);
#else
- return 0;
-#endif
+ LOG_W(_WARNING_WITHOUT_FS);
+ return _LLIO_ERROR;
+#endif /* DFS_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_lseek.c b/components/libc/compilers/dlib/syscall_lseek.c
index b79cc410b7..b2c47e71c9 100644
--- a/components/libc/compilers/dlib/syscall_lseek.c
+++ b/components/libc/compilers/dlib/syscall_lseek.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -7,23 +7,41 @@
* Date Author Notes
* 2015-01-28 Bernard first version
*/
+
#include <rtthread.h>
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
-#include <yfuns.h>
+#include <LowLevelIOInterface.h>
+#include <unistd.h>
+#include <compiler_private.h>
+#define DBG_TAG "dlib.syscall.lseek"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
+/*
+ * The "__lseek" function makes the next file operation (__read or
+ * __write) act on a new location. The parameter "whence" specifies
+ * how the "offset" parameter should be interpreted according to the
+ * following table:
+ *
+ * 0 (=SEEK_SET) - Goto location "offset".
+ * 1 (=SEEK_CUR) - Go "offset" bytes from the current location.
+ * 2 (=SEEK_END) - Go to "offset" bytes from the end.
+ *
+ * This function should return the current file position, or -1 on
+ * failure.
+ */
#pragma module_name = "?__lseek"
+
long __lseek(int handle, long offset, int whence)
{
if (handle == _LLIO_STDOUT ||
handle == _LLIO_STDERR ||
handle == _LLIO_STDIN)
return _LLIO_ERROR;
-
-#ifdef RT_USING_DFS
+#ifdef DFS_USING_POSIX
return lseek(handle, offset, whence);
#else
+ LOG_W(_WARNING_WITHOUT_FS);
return _LLIO_ERROR;
-#endif
+#endif /* DFS_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_mem.c b/components/libc/compilers/dlib/syscall_mem.c
index 236ef1c12d..2de0974e4e 100644
--- a/components/libc/compilers/dlib/syscall_mem.c
+++ b/components/libc/compilers/dlib/syscall_mem.c
@@ -1,32 +1,61 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2015-01-28 Bernard first version
+ * 2021-11-13 Meco Man implement no-heap warning
*/
+
#include <rtthread.h>
+#include <stddef.h>
-#ifdef RT_USING_HEAP
-void *malloc(rt_size_t n)
+#ifndef RT_USING_HEAP
+#define DBG_TAG "dlib.syscall.mem"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+#define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\
+ RT_ASSERT(0);\
+ }while(0)
+#endif /* RT_USING_HEAP */
+
+void *malloc(size_t n)
{
+#ifdef RT_USING_HEAP
return rt_malloc(n);
+#else
+ _NO_HEAP_ERROR();
+ return RT_NULL;
+#endif
}
-void *realloc(void *rmem, rt_size_t newsize)
+void *realloc(void *rmem, size_t newsize)
{
+#ifdef RT_USING_HEAP
return rt_realloc(rmem, newsize);
+#else
+ _NO_HEAP_ERROR();
+ return RT_NULL;
+#endif
}
-void *calloc(rt_size_t nelem, rt_size_t elsize)
+void *calloc(size_t nelem, size_t elsize)
{
+#ifdef RT_USING_HEAP
return rt_calloc(nelem, elsize);
+#else
+ _NO_HEAP_ERROR();
+ return RT_NULL;
+#endif
}
void free(void *rmem)
{
+#ifdef RT_USING_HEAP
rt_free(rmem);
-}
+#else
+ _NO_HEAP_ERROR();
#endif
+}
diff --git a/components/libc/compilers/dlib/syscall_open.c b/components/libc/compilers/dlib/syscall_open.c
index 96e02dc32a..4d557db4b0 100644
--- a/components/libc/compilers/dlib/syscall_open.c
+++ b/components/libc/compilers/dlib/syscall_open.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -9,66 +9,75 @@
*/
#include <rtthread.h>
-#include <yfuns.h>
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
+#include <LowLevelIOInterface.h>
+#include <fcntl.h>
+#include <compiler_private.h>
+#define DBG_TAG "dlib.syscall.open"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
+/*
+ * The "__open" function opens the file named "filename" as specified
+ * by "mode".
+ */
#pragma module_name = "?__open"
int __open(const char *filename, int mode)
{
-#ifndef RT_USING_DFS
- return _LLIO_ERROR;
-#else
- int handle;
- int open_mode = O_RDONLY;
-
- if (mode & _LLIO_CREAT)
- {
- open_mode |= O_CREAT;
+#ifdef DFS_USING_POSIX
+ int handle;
+ int open_mode = O_RDONLY;
- /* Check what we should do with it if it exists. */
- if (mode & _LLIO_APPEND)
+ if (mode & _LLIO_CREAT)
{
- /* Append to the existing file. */
- open_mode |= O_APPEND;
+ open_mode |= O_CREAT;
+
+ /* Check what we should do with it if it exists. */
+ if (mode & _LLIO_APPEND)
+ {
+ /* Append to the existing file. */
+ open_mode |= O_APPEND;
+ }
+
+ if (mode & _LLIO_TRUNC)
+ {
+ /* Truncate the existsing file. */
+ open_mode |= O_TRUNC;
+ }
}
- if (mode & _LLIO_TRUNC)
+ if (mode & _LLIO_TEXT)
{
- /* Truncate the existsing file. */
- open_mode |= O_TRUNC;
+ /* we didn't support text mode */
}
- }
-
- if (mode & _LLIO_TEXT)
- {
- /* we didn't support text mode */
- }
- switch (mode & _LLIO_RDWRMASK)
- {
- case _LLIO_RDONLY:
- break;
+ switch (mode & _LLIO_RDWRMASK)
+ {
+ case _LLIO_RDONLY:
+ break;
- case _LLIO_WRONLY:
- open_mode |= O_WRONLY;
- break;
+ case _LLIO_WRONLY:
+ open_mode |= O_WRONLY;
+ break;
- case _LLIO_RDWR:
- /* The file should be opened for both reads and writes. */
- open_mode |= O_RDWR;
- break;
+ case _LLIO_RDWR:
+ /* The file should be opened for both reads and writes. */
+ open_mode |= O_RDWR;
+ break;
- default:
- return _LLIO_ERROR;
- }
+ default:
+ return _LLIO_ERROR;
+ }
- handle = open(filename, open_mode, 0);
- if (handle < 0)
+ handle = open(filename, open_mode, 0);
+ if (handle < 0)
+ {
+ return _LLIO_ERROR;
+ }
+ return handle;
+#else
+ LOG_W(_WARNING_WITHOUT_FS);
return _LLIO_ERROR;
-
- return handle;
-#endif
+#endif /* DFS_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c
index e248211486..a276a3e401 100644
--- a/components/libc/compilers/dlib/syscall_read.c
+++ b/components/libc/compilers/dlib/syscall_read.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -9,35 +9,57 @@
*/
#include <rtthread.h>
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
-#include <yfuns.h>
+#include <LowLevelIOInterface.h>
+#include <unistd.h>
+#ifdef RT_USING_POSIX_STDIO
#include "libc.h"
+#endif /* RT_USING_POSIX_STDIO */
+#include <compiler_private.h>
+#define DBG_TAG "dlib.syscall.read"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
+/*
+ * The "__read" function reads a number of bytes, at most "size" into
+ * the memory area pointed to by "buffer". It returns the number of
+ * bytes read, 0 at the end of the file, or _LLIO_ERROR if failure
+ * occurs.
+ *
+ * The template implementation below assumes that the application
+ * provides the function "MyLowLevelGetchar". It should return a
+ * character value, or -1 on failure.
+ */
#pragma module_name = "?__read"
+
size_t __read(int handle, unsigned char *buf, size_t len)
{
-#ifdef RT_USING_DFS
+#ifdef DFS_USING_POSIX
int size;
-#endif
if (handle == _LLIO_STDIN)
{
-#ifdef RT_USING_POSIX
- return libc_stdio_read(buf, len);
+#ifdef RT_USING_POSIX_STDIO
+ if (libc_stdio_get_console() < 0)
+ {
+ LOG_W("Do not invoke standard input before initializing Compiler");
+ return 0; /* error, but keep going */
+ }
+ return read(STDIN_FILENO, buf, len); /* return the length of the data read */
#else
+ LOG_W(_WARNING_WITHOUT_STDIO);
return _LLIO_ERROR;
-#endif
+#endif /* RT_USING_POSIX_STDIO */
}
-
- if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
+ else if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
+ {
return _LLIO_ERROR;
+ }
-#ifndef RT_USING_DFS
- return _LLIO_ERROR;
-#else
size = read(handle, buf, len);
- return size;
-#endif
+ return size; /* return the length of the data read */
+#else
+ LOG_W(_WARNING_WITHOUT_FS);
+ return _LLIO_ERROR;
+#endif /* DFS_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_remove.c b/components/libc/compilers/dlib/syscall_remove.c
index e7f0268b1b..04230544da 100644
--- a/components/libc/compilers/dlib/syscall_remove.c
+++ b/components/libc/compilers/dlib/syscall_remove.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -7,18 +7,28 @@
* Date Author Notes
* 2015-01-28 Bernard first version
*/
+
#include <rtthread.h>
-#ifdef RT_USING_DFS
-#include <dfs_file.h>
-#endif
-#include <yfuns.h>
+#include <LowLevelIOInterface.h>
+#include <unistd.h>
+#include <compiler_private.h>
+#define DBG_TAG "dlib.syscall.remove"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
+/*
+ * The "remove" function should remove the file named "filename". It
+ * should return 0 on success and nonzero on failure.
+ */
#pragma module_name = "?remove"
-int remove(const char *val)
-{
-#ifdef RT_USING_DFS
- dfs_file_unlink(val);
-#endif
- return 0;
+int remove(const char *filename)
+{
+#ifdef DFS_USING_POSIX
+ return unlink(filename);
+#else
+ LOG_W(_WARNING_WITHOUT_FS);
+ return _LLIO_ERROR;
+#endif /* DFS_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c
index 85c0da22c3..4eead9aa38 100644
--- a/components/libc/compilers/dlib/syscall_write.c
+++ b/components/libc/compilers/dlib/syscall_write.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -9,46 +9,63 @@
*/
#include <rtthread.h>
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
-#include <yfuns.h>
-#include "libc.h"
+#include <LowLevelIOInterface.h>
+#include <unistd.h>
+#include <compiler_private.h>
+#define DBG_TAG "dlib.syscall.write"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
+/*
+ * The "__write" function should output "size" number of bytes from
+ * "buffer" in some application-specific way. It should return the
+ * number of characters written, or _LLIO_ERROR on failure.
+ *
+ * If "buffer" is zero then __write should perform flushing of
+ * internal buffers, if any. In this case "handle" can be -1 to
+ * indicate that all handles should be flushed.
+ *
+ * The template implementation below assumes that the application
+ * provides the function "MyLowLevelPutchar". It should return the
+ * character written, or -1 on failure.
+ */
#pragma module_name = "?__write"
size_t __write(int handle, const unsigned char *buf, size_t len)
{
-#ifdef RT_USING_DFS
+#ifdef DFS_USING_POSIX
int size;
-#endif
+#endif /* DFS_USING_POSIX */
if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
{
-#ifndef RT_USING_CONSOLE
- return _LLIO_ERROR;
-#else
-
-#ifdef RT_USING_POSIX
- return libc_stdio_write((void*)buf, len);
-#else
+#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
rt_device_t console_device;
console_device = rt_console_get_device();
- if (console_device != 0) rt_device_write(console_device, 0, buf, len);
+ if (console_device)
+ {
+ rt_device_write(console_device, 0, buf, len);
+ }
- return len;
-#endif
-#endif
+ return len; /* return the length of the data written */
+#else
+ return _LLIO_ERROR;
+#endif /* defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) */
}
-
- if (handle == _LLIO_STDIN) return _LLIO_ERROR;
-
-#ifndef RT_USING_DFS
- return _LLIO_ERROR;
+ else if (handle == _LLIO_STDIN)
+ {
+ return _LLIO_ERROR;
+ }
+ else
+ {
+#ifdef DFS_USING_POSIX
+ size = write(handle, buf, len);
+ return size; /* return the length of the data written */
#else
- size = write(handle, buf, len);
- return size;
-#endif
+ LOG_W(_WARNING_WITHOUT_FS);
+ return _LLIO_ERROR;
+#endif /* DFS_USING_POSIX */
+ }
}
-
diff --git a/components/libc/compilers/dlib/syscalls.c b/components/libc/compilers/dlib/syscalls.c
new file mode 100644
index 0000000000..391cbcac8a
--- /dev/null
+++ b/components/libc/compilers/dlib/syscalls.c
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-02-13 Meco Man implement exit() and abort()
+ */
+
+#include <rtthread.h>
+
+/* for exit() and abort() */
+void __exit (int status)
+{
+ extern void __rt_libc_exit(int status);
+ __rt_libc_exit(status);
+ while(1);
+}
diff --git a/components/libc/compilers/dlib/syscalls.h b/components/libc/compilers/dlib/syscalls.h
deleted file mode 100644
index 993962e8db..0000000000
--- a/components/libc/compilers/dlib/syscalls.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2015-01-28 Bernard first version
- */
-
diff --git a/components/libc/compilers/dlib/unistd.h b/components/libc/compilers/dlib/unistd.h
deleted file mode 100644
index a07d8409c2..0000000000
--- a/components/libc/compilers/dlib/unistd.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef _UNISTD_H_
-#define _UNISTD_H_
-
-# include "sys/unistd.h"
-
-#endif /* _UNISTD_H_ */
diff --git a/components/libc/compilers/minilibc/SConscript b/components/libc/compilers/minilibc/SConscript
deleted file mode 100644
index dec657028f..0000000000
--- a/components/libc/compilers/minilibc/SConscript
+++ /dev/null
@@ -1,15 +0,0 @@
-from building import *
-Import('rtconfig')
-
-src = Glob('*.c') + Glob('*.cpp')
-cwd = GetCurrentDir()
-group = []
-
-CPPPATH = [cwd]
-CPPDEFINES = ['RT_USING_MINILIBC']
-
-if rtconfig.PLATFORM == 'gcc' and rtconfig.ARCH != 'sim' and not GetDepend('RT_USING_LIBC') and GetDepend('RT_USING_MINILIBC'):
- group = DefineGroup('libc', src, depend = [''],
- CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
-
-Return('group')
diff --git a/components/libc/compilers/minilibc/ctype.c b/components/libc/compilers/minilibc/ctype.c
deleted file mode 100644
index b94ff2dae8..0000000000
--- a/components/libc/compilers/minilibc/ctype.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2008-08-14 Bernard the first version
- */
-
-#include <rtthread.h>
-#include <sys/types.h>
-
-#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
-#include "ctype.h"
-
-int isprint (int ch)
-{
- ch&=0x7f;
- return (ch>=32 && ch<127);
-}
-
-int isalpha(int ch)
-{
- return (unsigned int)((ch | 0x20) - 'a') < 26u;
-}
-
-int isdigit (int ch)
-{
- return (unsigned int)(ch - '0') < 10u;
-}
-
-int isspace(int ch)
-{
- switch(ch)
- {
- case ' ':
- case '\n':
- case '\f':
- case '\r':
- case '\t':
- case '\v':
- return 1;
- default:
- return 0;
- }
-}
-
-#endif
diff --git a/components/libc/compilers/minilibc/ctype.h b/components/libc/compilers/minilibc/ctype.h
deleted file mode 100644
index 5f41376ed8..0000000000
--- a/components/libc/compilers/minilibc/ctype.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2008-08-14 Bernard the first version
- */
-#ifndef __CTYPE_H__
-#define __CTYPE_H__
-
-int isprint(int c) __attribute__ ((__const__));
-int isalpha (int c) __attribute__ ((__const__));
-int isdigit (int ch) __attribute__ ((__const__));
-int isspace(int ch) __attribute__ ((__const__));
-
-#endif
diff --git a/components/libc/compilers/minilibc/errno.h b/components/libc/compilers/minilibc/errno.h
deleted file mode 100644
index a7ee380594..0000000000
--- a/components/libc/compilers/minilibc/errno.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __ERRNO_H__
-#define __ERRNO_H__
-
-#include "libc/libc_errno.h"
-/* Others defined in libc/libc_errno.h */
-#define ENSRNOTFOUND 163 /* Domain name not found */
-
-#endif
diff --git a/components/libc/compilers/minilibc/inttypes.h b/components/libc/compilers/minilibc/inttypes.h
deleted file mode 100644
index 8bab743655..0000000000
--- a/components/libc/compilers/minilibc/inttypes.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __INTTYPES_H__
-#define __INTTYPES_H__
-
-#include "stdint.h"
-
-#endif
diff --git a/components/libc/compilers/minilibc/math.c b/components/libc/compilers/minilibc/math.c
deleted file mode 100644
index cd5770178e..0000000000
--- a/components/libc/compilers/minilibc/math.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#include <math.h>
-
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS CRT
- * FILE: lib/crt/math/cos.c
- * PURPOSE: Generic C Implementation of cos
- * PROGRAMMER: Timo Kreuzer ([email protected])
- */
-
-#define PRECISION 9
-
-static double cos_off_tbl[] = {0.0, -M_PI/2., 0, -M_PI/2.};
-static double cos_sign_tbl[] = {1,-1,-1,1};
-
-static double sin_off_tbl[] = {0.0, -M_PI/2., 0, -M_PI/2.};
-static double sin_sign_tbl[] = {1,-1,-1,1};
-
-double sin(double x)
-{
- int quadrant;
- double x2, result;
-
- /* Calculate the quadrant */
- quadrant = x * (2./M_PI);
-
- /* Get offset inside quadrant */
- x = x - quadrant * (M_PI/2.);
-
- /* Normalize quadrant to [0..3] */
- quadrant = (quadrant - 1) & 0x3;
-
- /* Fixup value for the generic function */
- x += sin_off_tbl[quadrant];
-
- /* Calculate the negative of the square of x */
- x2 = - (x * x);
-
- /* This is an unrolled taylor series using <PRECISION> iterations
- * Example with 4 iterations:
- * result = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8!
- * To save multiplications and to keep the precision high, it's performed
- * like this:
- * result = 1 - x^2 * (1/2! - x^2 * (1/4! - x^2 * (1/6! - x^2 * (1/8!))))
- */
-
- /* Start with 0, compiler will optimize this away */
- result = 0;
-
-#if (PRECISION >= 10)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20);
- result *= x2;
-#endif
-#if (PRECISION >= 9)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18);
- result *= x2;
-#endif
-#if (PRECISION >= 8)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16);
- result *= x2;
-#endif
-#if (PRECISION >= 7)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14);
- result *= x2;
-#endif
-#if (PRECISION >= 6)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12);
- result *= x2;
-#endif
-#if (PRECISION >= 5)
- result += 1./(1.*2*3*4*5*6*7*8*9*10);
- result *= x2;
-#endif
- result += 1./(1.*2*3*4*5*6*7*8);
- result *= x2;
-
- result += 1./(1.*2*3*4*5*6);
- result *= x2;
-
- result += 1./(1.*2*3*4);
- result *= x2;
-
- result += 1./(1.*2);
- result *= x2;
-
- result += 1;
-
- /* Apply correct sign */
- result *= sin_sign_tbl[quadrant];
-
- return result;
-}
-
-double cos(double x)
-{
- int quadrant;
- double x2, result;
-
- /* Calculate the quadrant */
- quadrant = x * (2./M_PI);
-
- /* Get offset inside quadrant */
- x = x - quadrant * (M_PI/2.);
-
- /* Normalize quadrant to [0..3] */
- quadrant = quadrant & 0x3;
-
- /* Fixup value for the generic function */
- x += cos_off_tbl[quadrant];
-
- /* Calculate the negative of the square of x */
- x2 = - (x * x);
-
- /* This is an unrolled taylor series using <PRECISION> iterations
- * Example with 4 iterations:
- * result = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8!
- * To save multiplications and to keep the precision high, it's performed
- * like this:
- * result = 1 - x^2 * (1/2! - x^2 * (1/4! - x^2 * (1/6! - x^2 * (1/8!))))
- */
-
- /* Start with 0, compiler will optimize this away */
- result = 0;
-
-#if (PRECISION >= 10)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20);
- result *= x2;
-#endif
-#if (PRECISION >= 9)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18);
- result *= x2;
-#endif
-#if (PRECISION >= 8)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16);
- result *= x2;
-#endif
-#if (PRECISION >= 7)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14);
- result *= x2;
-#endif
-#if (PRECISION >= 6)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12);
- result *= x2;
-#endif
-#if (PRECISION >= 5)
- result += 1./(1.*2*3*4*5*6*7*8*9*10);
- result *= x2;
-#endif
- result += 1./(1.*2*3*4*5*6*7*8);
- result *= x2;
-
- result += 1./(1.*2*3*4*5*6);
- result *= x2;
-
- result += 1./(1.*2*3*4);
- result *= x2;
-
- result += 1./(1.*2);
- result *= x2;
-
- result += 1;
-
- /* Apply correct sign */
- result *= cos_sign_tbl[quadrant];
-
- return result;
-}
-
diff --git a/components/libc/compilers/minilibc/math.h b/components/libc/compilers/minilibc/math.h
deleted file mode 100644
index 49b80d8219..0000000000
--- a/components/libc/compilers/minilibc/math.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __MATH_H__
-#define __MATH_H__
-
-#define M_PI 3.141592653589793238462643
-
-double sin(double x);
-double cos(double x);
-
-typedef float float_t;
-typedef double double_t;
-
-#endif
diff --git a/components/libc/compilers/minilibc/qsort.c b/components/libc/compilers/minilibc/qsort.c
deleted file mode 100644
index 2b97ce763c..0000000000
--- a/components/libc/compilers/minilibc/qsort.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#include <sys/types.h>
-#include <stdlib.h>
-
-static void exch(char* base,size_t size,size_t a,size_t b) {
- char* x=base+a*size;
- char* y=base+b*size;
- while (size) {
- char z=*x;
- *x=*y;
- *y=z;
- --size; ++x; ++y;
- }
-}
-
-/* Quicksort with 3-way partitioning, ala Sedgewick */
-/* Blame him for the scary variable names */
-/* http://www.cs.princeton.edu/~rs/talks/QuicksortIsOptimal.pdf */
-static void quicksort(char* base,size_t size,ssize_t l,ssize_t r,
- int (*compar)(const void*,const void*)) {
- ssize_t i=l-1, j=r, p=l-1, q=r, k;
- char* v=base+r*size;
- if (r<=l) return;
- for (;;) {
- while (++i != r && compar(base+i*size,v)<0) ;
- while (compar(v,base+(--j)*size)<0) if (j == l) break;
- if (i >= j) break;
- exch(base,size,i,j);
- if (compar(base+i*size,v)==0) exch(base,size,++p,i);
- if (compar(v,base+j*size)==0) exch(base,size,j,--q);
- }
- exch(base,size,i,r); j = i-1; ++i;
- for (k=l; k<p; k++, j--) exch(base,size,k,j);
- for (k=r-1; k>q; k--, i++) exch(base,size,i,k);
- quicksort(base,size,l,j,compar);
- quicksort(base,size,i,r,compar);
-}
-
-void qsort(void* base,size_t nmemb,size_t size,int (*compar)(const void*,const void*)) {
- /* check for integer overflows */
- if (nmemb >= (((size_t)-1)>>1) ||
- size >= (((size_t)-1)>>1)) return;
- if (nmemb>1)
- quicksort(base,size,0,nmemb-1,compar);
-}
diff --git a/components/libc/compilers/minilibc/rand.c b/components/libc/compilers/minilibc/rand.c
deleted file mode 100644
index 88603dc808..0000000000
--- a/components/libc/compilers/minilibc/rand.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#include <stdlib.h>
-#include <stdint.h>
-#include <sys/types.h>
-
-static unsigned int _seed=1;
-
-/* Knuth's TAOCP section 3.6 */
-#define M ((1U<<31) -1)
-#define A 48271
-#define Q 44488 // M/A
-#define R 3399 // M%A; R < Q !!!
-
-int rand_r(unsigned int* seed)
-{ int32_t X;
-
- X = *seed;
- X = A*(X%Q) - R * (int32_t) (X/Q);
- if (X < 0)
- X += M;
-
- *seed = X;
- return X;
-}
-
-int rand(void) {
- return rand_r(&_seed);
-}
-
-void srand(unsigned int i)
-{
- _seed=i;
-}
-
-int random(void) __attribute__((alias("rand")));
-void srandom(unsigned int i) __attribute__((alias("srand")));
diff --git a/components/libc/compilers/minilibc/signal.h b/components/libc/compilers/minilibc/signal.h
deleted file mode 100644
index f52f1e1009..0000000000
--- a/components/libc/compilers/minilibc/signal.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017-09-12 Bernard The first version
- */
-
-#ifndef SIGNAL_H__
-#define SIGNAL_H__
-
-#include <libc/libc_signal.h>
-
-#define SIG_DFL ((_sig_func_ptr)0) /* Default action */
-#define SIG_IGN ((_sig_func_ptr)1) /* Ignore action */
-#define SIG_ERR ((_sig_func_ptr)-1) /* Error return */
-
-#endif
diff --git a/components/libc/compilers/minilibc/stddef.h b/components/libc/compilers/minilibc/stddef.h
deleted file mode 100644
index 7353a157cb..0000000000
--- a/components/libc/compilers/minilibc/stddef.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __STDDEF_H__
-#define __STDDEF_H__
-
-#include <sys/types.h>
-typedef signed long ptrdiff_t;
-
-#endif
diff --git a/components/libc/compilers/minilibc/stdint.h b/components/libc/compilers/minilibc/stdint.h
deleted file mode 100644
index bd5fdc83f5..0000000000
--- a/components/libc/compilers/minilibc/stdint.h
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-/*
- * ISO C Standard: 7.18 Integer types <stdint.h>
- */
-
-#ifndef __STDINT_H__
-#define __STDINT_H__
-
-/* 7.8.1.1 Exact-width integer types */
-
-#ifdef __INT8_TYPE__
-typedef __INT8_TYPE__ int8_t;
-#endif
-#ifdef __INT16_TYPE__
-typedef __INT16_TYPE__ int16_t;
-#endif
-#ifdef __INT32_TYPE__
-typedef __INT32_TYPE__ int32_t;
-#endif
-#ifdef __INT64_TYPE__
-typedef __INT64_TYPE__ int64_t;
-#endif
-#ifdef __UINT8_TYPE__
-typedef __UINT8_TYPE__ uint8_t;
-#endif
-#ifdef __UINT16_TYPE__
-typedef __UINT16_TYPE__ uint16_t;
-#endif
-#ifdef __UINT32_TYPE__
-typedef __UINT32_TYPE__ uint32_t;
-#endif
-#ifdef __UINT64_TYPE__
-typedef __UINT64_TYPE__ uint64_t;
-#endif
-
-/* 7.8.1.2 Minimum-width integer types */
-
-typedef __INT_LEAST8_TYPE__ int_least8_t;
-typedef __INT_LEAST16_TYPE__ int_least16_t;
-typedef __INT_LEAST32_TYPE__ int_least32_t;
-typedef __INT_LEAST64_TYPE__ int_least64_t;
-typedef __UINT_LEAST8_TYPE__ uint_least8_t;
-typedef __UINT_LEAST16_TYPE__ uint_least16_t;
-typedef __UINT_LEAST32_TYPE__ uint_least32_t;
-typedef __UINT_LEAST64_TYPE__ uint_least64_t;
-
-/* 7.8.1.3 Fastest minimum-width integer types */
-
-typedef __INT_FAST8_TYPE__ int_fast8_t;
-typedef __INT_FAST16_TYPE__ int_fast16_t;
-typedef __INT_FAST32_TYPE__ int_fast32_t;
-typedef __INT_FAST64_TYPE__ int_fast64_t;
-typedef __UINT_FAST8_TYPE__ uint_fast8_t;
-typedef __UINT_FAST16_TYPE__ uint_fast16_t;
-typedef __UINT_FAST32_TYPE__ uint_fast32_t;
-typedef __UINT_FAST64_TYPE__ uint_fast64_t;
-
-/* 7.8.1.4 Integer types capable of holding object pointers */
-
-#ifdef __INTPTR_TYPE__
-typedef __INTPTR_TYPE__ intptr_t;
-#endif
-#ifdef __UINTPTR_TYPE__
-typedef __UINTPTR_TYPE__ uintptr_t;
-#endif
-
-/* 7.8.1.5 Greatest-width integer types */
-
-typedef __INTMAX_TYPE__ intmax_t;
-typedef __UINTMAX_TYPE__ uintmax_t;
-
-#if (!defined __cplusplus || __cplusplus >= 201103L \
- || defined __STDC_LIMIT_MACROS)
-
-/*
- * 7.18.2 Limits of specified-width integer types.
- *
- * The following object-like macros specify the minimum and maximum limits
- * of integer types corresponding to the typedef names defined above.
- */
-
-/* 7.18.2.1 Limits of exact-width integer types */
-
-#ifdef __INT8_MAX__
-# undef INT8_MAX
-# define INT8_MAX __INT8_MAX__
-# undef INT8_MIN
-# define INT8_MIN (-INT8_MAX - 1)
-#endif
-#ifdef __UINT8_MAX__
-# undef UINT8_MAX
-# define UINT8_MAX __UINT8_MAX__
-#endif
-#ifdef __INT16_MAX__
-# undef INT16_MAX
-# define INT16_MAX __INT16_MAX__
-# undef INT16_MIN
-# define INT16_MIN (-INT16_MAX - 1)
-#endif
-#ifdef __UINT16_MAX__
-# undef UINT16_MAX
-# define UINT16_MAX __UINT16_MAX__
-#endif
-#ifdef __INT32_MAX__
-# undef INT32_MAX
-# define INT32_MAX __INT32_MAX__
-# undef INT32_MIN
-# define INT32_MIN (-INT32_MAX - 1)
-#endif
-#ifdef __UINT32_MAX__
-# undef UINT32_MAX
-# define UINT32_MAX __UINT32_MAX__
-#endif
-#ifdef __INT64_MAX__
-# undef INT64_MAX
-# define INT64_MAX __INT64_MAX__
-# undef INT64_MIN
-# define INT64_MIN (-INT64_MAX - 1)
-#endif
-#ifdef __UINT64_MAX__
-# undef UINT64_MAX
-# define UINT64_MAX __UINT64_MAX__
-#endif
-
-#undef INT_LEAST8_MAX
-#define INT_LEAST8_MAX __INT_LEAST8_MAX__
-#undef INT_LEAST8_MIN
-#define INT_LEAST8_MIN (-INT_LEAST8_MAX - 1)
-#undef UINT_LEAST8_MAX
-#define UINT_LEAST8_MAX __UINT_LEAST8_MAX__
-#undef INT_LEAST16_MAX
-#define INT_LEAST16_MAX __INT_LEAST16_MAX__
-#undef INT_LEAST16_MIN
-#define INT_LEAST16_MIN (-INT_LEAST16_MAX - 1)
-#undef UINT_LEAST16_MAX
-#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
-#undef INT_LEAST32_MAX
-#define INT_LEAST32_MAX __INT_LEAST32_MAX__
-#undef INT_LEAST32_MIN
-#define INT_LEAST32_MIN (-INT_LEAST32_MAX - 1)
-#undef UINT_LEAST32_MAX
-#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
-#undef INT_LEAST64_MAX
-#define INT_LEAST64_MAX __INT_LEAST64_MAX__
-#undef INT_LEAST64_MIN
-#define INT_LEAST64_MIN (-INT_LEAST64_MAX - 1)
-#undef UINT_LEAST64_MAX
-#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__
-
-#undef INT_FAST8_MAX
-#define INT_FAST8_MAX __INT_FAST8_MAX__
-#undef INT_FAST8_MIN
-#define INT_FAST8_MIN (-INT_FAST8_MAX - 1)
-#undef UINT_FAST8_MAX
-#define UINT_FAST8_MAX __UINT_FAST8_MAX__
-#undef INT_FAST16_MAX
-#define INT_FAST16_MAX __INT_FAST16_MAX__
-#undef INT_FAST16_MIN
-#define INT_FAST16_MIN (-INT_FAST16_MAX - 1)
-#undef UINT_FAST16_MAX
-#define UINT_FAST16_MAX __UINT_FAST16_MAX__
-#undef INT_FAST32_MAX
-#define INT_FAST32_MAX __INT_FAST32_MAX__
-#undef INT_FAST32_MIN
-#define INT_FAST32_MIN (-INT_FAST32_MAX - 1)
-#undef UINT_FAST32_MAX
-#define UINT_FAST32_MAX __UINT_FAST32_MAX__
-#undef INT_FAST64_MAX
-#define INT_FAST64_MAX __INT_FAST64_MAX__
-#undef INT_FAST64_MIN
-#define INT_FAST64_MIN (-INT_FAST64_MAX - 1)
-#undef UINT_FAST64_MAX
-#define UINT_FAST64_MAX __UINT_FAST64_MAX__
-
-#ifdef __INTPTR_MAX__
-# undef INTPTR_MAX
-# define INTPTR_MAX __INTPTR_MAX__
-# undef INTPTR_MIN
-# define INTPTR_MIN (-INTPTR_MAX - 1)
-#endif
-#ifdef __UINTPTR_MAX__
-# undef UINTPTR_MAX
-# define UINTPTR_MAX __UINTPTR_MAX__
-#endif
-
-#undef INTMAX_MAX
-#define INTMAX_MAX __INTMAX_MAX__
-#undef INTMAX_MIN
-#define INTMAX_MIN (-INTMAX_MAX - 1)
-#undef UINTMAX_MAX
-#define UINTMAX_MAX __UINTMAX_MAX__
-
-/* 7.18.3 Limits of other integer types */
-
-#undef PTRDIFF_MAX
-#define PTRDIFF_MAX __PTRDIFF_MAX__
-#undef PTRDIFF_MIN
-#define PTRDIFF_MIN (-PTRDIFF_MAX - 1)
-
-#undef SIG_ATOMIC_MAX
-#define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__
-#undef SIG_ATOMIC_MIN
-#define SIG_ATOMIC_MIN __SIG_ATOMIC_MIN__
-
-#undef SIZE_MAX
-#define SIZE_MAX __SIZE_MAX__
-
-#undef WCHAR_MAX
-#define WCHAR_MAX __WCHAR_MAX__
-#undef WCHAR_MIN
-#define WCHAR_MIN __WCHAR_MIN__
-
-#undef WINT_MAX
-#define WINT_MAX __WINT_MAX__
-#undef WINT_MIN
-#define WINT_MIN __WINT_MIN__
-
-#endif /* (!defined __cplusplus || __cplusplus >= 201103L
- || defined __STDC_LIMIT_MACROS) */
-
-#if (!defined __cplusplus || __cplusplus >= 201103L \
- || defined __STDC_CONSTANT_MACROS)
-
-#undef INT8_C
-#define INT8_C(c) __INT8_C(c)
-#undef INT16_C
-#define INT16_C(c) __INT16_C(c)
-#undef INT32_C
-#define INT32_C(c) __INT32_C(c)
-#undef INT64_C
-#define INT64_C(c) __INT64_C(c)
-#undef UINT8_C
-#define UINT8_C(c) __UINT8_C(c)
-#undef UINT16_C
-#define UINT16_C(c) __UINT16_C(c)
-#undef UINT32_C
-#define UINT32_C(c) __UINT32_C(c)
-#undef UINT64_C
-#define UINT64_C(c) __UINT64_C(c)
-#undef INTMAX_C
-#define INTMAX_C(c) __INTMAX_C(c)
-#undef UINTMAX_C
-#define UINTMAX_C(c) __UINTMAX_C(c)
-
-#endif /* (!defined __cplusplus || __cplusplus >= 201103L
- || defined __STDC_CONSTANT_MACROS) */
-
-#ifndef __INT_MAX__
-#define __INT_MAX__ 2147483647
-#endif
-#define INT_MIN (-1 - INT_MAX)
-#define INT_MAX (__INT_MAX__)
-#define UINT_MAX (INT_MAX * 2U + 1U)
-
-#define LONG_MAX ((long)(~0UL>>1))
-#define LONG_MIN (-LONG_MAX - 1)
-#define ULONG_MAX (~0UL)
-
-#endif
diff --git a/components/libc/compilers/minilibc/stdio.h b/components/libc/compilers/minilibc/stdio.h
deleted file mode 100644
index 678682cf5e..0000000000
--- a/components/libc/compilers/minilibc/stdio.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __STDIO_H__
-#define __STDIO_H__
-
-#define BUFSIZ 128
-#define EOF (-1)
-
-#ifndef SEEK_SET
-#define SEEK_SET 0 /* set file offset to offset */
-#endif
-#ifndef SEEK_CUR
-#define SEEK_CUR 1 /* set file offset to current plus offset */
-#endif
-#ifndef SEEK_END
-#define SEEK_END 2 /* set file offset to EOF plus offset */
-#endif
-
-#endif
-
diff --git a/components/libc/compilers/minilibc/stdlib.c b/components/libc/compilers/minilibc/stdlib.c
deleted file mode 100644
index 8154ec5b8b..0000000000
--- a/components/libc/compilers/minilibc/stdlib.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2008-08-14 Bernard the first version
- */
-
-#include <rtthread.h>
-
-#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
-#include "stdlib.h"
-
-int atoi(const char* s)
-{
- long int v=0;
- int sign=1;
- while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) s++;
- switch (*s)
- {
- case '-':
- sign=-1;
- case '+':
- ++s;
- }
- while ((unsigned int) (*s - '0') < 10u)
- {
- v=v*10+*s-'0';
- ++s;
- }
- return sign==-1?-v:v;
-}
-
-long int atol(const char* s)
-{
- long int v=0;
- int sign=0;
- while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) ++s;
- switch (*s)
- {
- case '-': sign=-1;
- case '+': ++s;
- }
- while ((unsigned int) (*s - '0') < 10u)
- {
- v=v*10+*s-'0'; ++s;
- }
- return sign?-v:v;
-}
-
-#ifdef RT_USING_HEAP
-void *malloc(size_t size)
-{
- return rt_malloc(size);
-}
-
-void free(void *ptr)
-{
- rt_free(ptr);
-}
-
-void *realloc(void *ptr, size_t size)
-{
- return rt_realloc(ptr, size);
-}
-
-void *calloc(size_t nelem, size_t elsize)
-{
- return rt_calloc(nelem, elsize);
-}
-#endif
-
-#endif
diff --git a/components/libc/compilers/minilibc/stdlib.h b/components/libc/compilers/minilibc/stdlib.h
deleted file mode 100644
index d57d95b64d..0000000000
--- a/components/libc/compilers/minilibc/stdlib.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2008-08-14 Bernard the first version
- */
-
-#ifndef __STDLIB_H__
-#define __STDLIB_H__
-
-#include <sys/types.h>
-
-#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
-int atoi(const char *nptr);
-long int atol(const char *nptr);
-
-int rand(void);
-int rand_r(unsigned int *seed);
-void srand(unsigned int seed);
-
-void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
-
-void *malloc(size_t size);
-void free(void *ptr);
-void *realloc(void *ptr, size_t size);
-void *calloc(size_t nelem, size_t elsize);
-void abort(void);
-#endif
-
-#endif
diff --git a/components/libc/compilers/minilibc/string.c b/components/libc/compilers/minilibc/string.c
deleted file mode 100644
index 1ab7c0509f..0000000000
--- a/components/libc/compilers/minilibc/string.c
+++ /dev/null
@@ -1,630 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2008-08-14 Bernard the first version
- * 2010-02-15 Gary Lee add strlcpy
- * 2010-03-17 Bernard add strlcpy implementation to this file.
- * fix strlcpy declaration
- * 2010-03-24 Bernard add strchr and strtok implementation.
- */
-
-#include <rtthread.h>
-#include <stdint.h>
-
-#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
-#include "string.h"
-
-/* there is no strcpy and strcmp implementation in RT-Thread */
-char *strcpy(char *dest, const char *src)
-{
- return (char *)rt_strncpy(dest, src, rt_strlen(src) + 1);
-}
-
-char *strncpy(char *dest, const char *src, size_t siz)
-{
- return (char *)rt_strncpy(dest, src, siz);
-}
-
-size_t strlcpy(char *dst, const char *src, size_t siz)
-{
- register char *d = dst;
- register const char *s = src;
- register size_t n = siz;
-
- /* Copy as many bytes as will fit */
- if (n != 0 && --n != 0)
- {
- do
- {
- if ((*d++ = *s++) == 0) break;
- } while (--n != 0);
- }
-
- /* Not enough room in dst, add NUL and traverse rest of src */
- if (n == 0)
- {
- if (siz != 0) *d = '\0'; /* NUL-terminate dst */
- while (*s++) ;
- }
-
- return(s - src - 1); /* count does not include NUL */
-}
-
-int strcmp (const char *s1, const char *s2)
-{
- while (*s1 && *s1 == *s2)
- s1++, s2++;
- return (*s1 - *s2);
-}
-
-/**
- * strncmp - Compare two length-limited strings
- * @cs: One string
- * @ct: Another string
- * @count: The maximum number of bytes to compare
- */
-int strncmp(const char *cs,const char *ct, size_t count)
-{
- register signed char __res = 0;
-
- while (count) {
- if ((__res = *cs - *ct++) != 0 || !*cs++)
- break;
- count--;
- }
-
- return __res;
-}
-
-char *strcat(char * dest, const char * src)
-{
- char *tmp = dest;
-
- while (*dest)
- dest++;
- while ((*dest++ = *src++) != '\0')
- ;
-
- return tmp;
-}
-
-char *strncat(char *dest, const char *src, size_t count)
-{
- char *tmp = dest;
-
- if (count) {
- while (*dest)
- dest++;
- while ((*dest++ = *src++)) {
- if (--count == 0) {
- *dest = '\0';
- break;
- }
- }
- }
-
- return tmp;
-}
-
-char *strrchr(const char *t, int c)
-{
- register char ch;
- register const char *l=0;
-
- ch = c;
- for (;;)
- {
- if (*t == ch) l=t;
- if (!*t) return (char*)l;
- ++t;
- }
-
- return (char*)l;
-}
-
-
-int strncasecmp ( const char* s1, const char* s2, size_t len )
-{
- register unsigned int x2;
- register unsigned int x1;
- register const char* end = s1 + len;
-
- while (1)
- {
- if ((s1 >= end) )
- return 0;
-
- x2 = *s2 - 'A'; if ((x2 < 26u)) x2 += 32;
- x1 = *s1 - 'A'; if ((x1 < 26u)) x1 += 32;
- s1++; s2++;
-
- if (x2 != x1)
- break;
-
- if (x1 == (unsigned int)-'A')
- break;
- }
-
- return x1 - x2;
-}
-
-/* private function */
-#define isdigit(c) ((unsigned)((c) - '0') < 10)
-
-rt_inline int divide(int *n, int base)
-{
- rt_int32_t res;
-
- /* optimized for processor which does not support divide instructions. */
- if (base == 10)
- {
- res = ((int)*n) % 10U;
- *n = ((int)*n) / 10U;
- }
- else
- {
- res = ((int)*n) % 16U;
- *n = ((int)*n) / 16U;
- }
-
- return res;
-}
-
-rt_inline int skip_atoi(const char **s)
-{
- register int i=0;
- while (isdigit(**s)) i = i*10 + *((*s)++) - '0';
-
- return i;
-}
-
-unsigned char _ctype[] = {
-_C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */
-_C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */
-_C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */
-_C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */
-_S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */
-_P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */
-_D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */
-_D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */
-_P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */
-_U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */
-_U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */
-_U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */
-_P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */
-_L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */
-_L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */
-_L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */
-_S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 160-175 */
-_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 176-191 */
-_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U, /* 192-207 */
-_U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L, /* 208-223 */
-_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */
-_L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */
-
-#define __ismask(x) (_ctype[(int)(unsigned char)(x)])
-
-#define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0)
-#define isalpha(c) ((__ismask(c)&(_U|_L)) != 0)
-#define iscntrl(c) ((__ismask(c)&(_C)) != 0)
-#define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0)
-#define islower(c) ((__ismask(c)&(_L)) != 0)
-#define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
-#define ispunct(c) ((__ismask(c)&(_P)) != 0)
-#define isspace(c) ((__ismask(c)&(_S)) != 0)
-#define isupper(c) ((__ismask(c)&(_U)) != 0)
-#define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0)
-
-#define isascii(c) (((unsigned char)(c))<=0x7f)
-#define toascii(c) (((unsigned char)(c))&0x7f)
-
-static inline unsigned char __tolower(unsigned char c)
-{
- if (isupper(c))
- c -= 'A'-'a';
- return c;
-}
-
-static inline unsigned char __toupper(unsigned char c)
-{
- if (islower(c))
- c -= 'a'-'A';
- return c;
-}
-
-int tolower(int c)
-{
- return __tolower(c);
-}
-
-int toupper(int c)
-{
- return __toupper(c);
-}
-
-/**
- * simple_strtoul - convert a string to an unsigned long
- * @cp: The start of the string
- * @endp: A pointer to the end of the parsed string will be placed here
- * @base: The number base to use
- */
-unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base)
-{
- unsigned long result = 0,value;
-
- if (!base) {
- base = 10;
- if (*cp == '0') {
- base = 8;
- cp++;
- if ((toupper(*cp) == 'X') && isxdigit(cp[1])) {
- cp++;
- base = 16;
- }
- }
- } else if (base == 16) {
- if (cp[0] == '0' && toupper(cp[1]) == 'X')
- cp += 2;
- }
- while (isxdigit(*cp) &&
- (value = isdigit(*cp) ? *cp-'0' : toupper(*cp)-'A'+10) < base) {
- result = result*base + value;
- cp++;
- }
- if (endp)
- *endp = (char *)cp;
- return result;
-}
-
-/**
- * simple_strtol - convert a string to a signed long
- * @cp: The start of the string
- * @endp: A pointer to the end of the parsed string will be placed here
- * @base: The number base to use
- */
-long simple_strtol(const char *cp,char **endp,unsigned int base)
-{
- if(*cp=='-')
- return -simple_strtoul(cp+1,endp,base);
- return simple_strtoul(cp,endp,base);
-}
-
-/**
- * simple_strtoull - convert a string to an unsigned long long
- * @cp: The start of the string
- * @endp: A pointer to the end of the parsed string will be placed here
- * @base: The number base to use
- */
-unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base)
-{
- unsigned long long result = 0, value;
-
- if (*cp == '0') {
- cp++;
- if ((toupper(*cp) == 'X') && isxdigit (cp[1])) {
- base = 16;
- cp++;
- }
- if (!base) {
- base = 8;
- }
- }
- if (!base) {
- base = 10;
- }
- while (isxdigit (*cp) && (value = isdigit (*cp)
- ? *cp - '0'
- : (islower (*cp) ? toupper (*cp) : *cp) - 'A' + 10) < base) {
- result = result * base + value;
- cp++;
- }
- if (endp)
- *endp = (char *) cp;
- return result;
-}
-
-/**
- * simple_strtoll - convert a string to a signed long long
- * @cp: The start of the string
- * @endp: A pointer to the end of the parsed string will be placed here
- * @base: The number base to use
- */
-long long simple_strtoll(const char *cp,char **endp,unsigned int base)
-{
- if(*cp=='-')
- return -simple_strtoull(cp+1,endp,base);
- return simple_strtoull(cp,endp,base);
-}
-
-/**
- * vsscanf - Unformat a buffer into a list of arguments
- * @buf: input buffer
- * @fmt: format of buffer
- * @args: arguments
- */
-int vsscanf(const char * buf, const char * fmt, va_list args)
-{
- const char *str = buf;
- char *next;
- int num = 0;
- int qualifier;
- int base;
- int field_width = -1;
- int is_sign = 0;
-
- while(*fmt && *str) {
- /* skip any white space in format */
- /* white space in format matchs any amount of
- * white space, including none, in the input.
- */
- if (isspace(*fmt)) {
- while (isspace(*fmt))
- ++fmt;
- while (isspace(*str))
- ++str;
- }
-
- /* anything that is not a conversion must match exactly */
- if (*fmt != '%' && *fmt) {
- if (*fmt++ != *str++)
- break;
- continue;
- }
-
- if (!*fmt)
- break;
- ++fmt;
-
- /* skip this conversion.
- * advance both strings to next white space
- */
- if (*fmt == '*') {
- while (!isspace(*fmt) && *fmt)
- fmt++;
- while (!isspace(*str) && *str)
- str++;
- continue;
- }
-
- /* get field width */
- if (isdigit(*fmt))
- field_width = skip_atoi(&fmt);
-
- /* get conversion qualifier */
- qualifier = -1;
- if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt == 'Z') {
- qualifier = *fmt;
- fmt++;
- }
- base = 10;
- is_sign = 0;
-
- if (!*fmt || !*str)
- break;
-
- switch(*fmt++) {
- case 'c':
- {
- char *s = (char *) va_arg(args,char*);
- if (field_width == -1)
- field_width = 1;
- do {
- *s++ = *str++;
- } while(field_width-- > 0 && *str);
- num++;
- }
- continue;
- case 's':
- {
- char *s = (char *) va_arg(args, char *);
- if(field_width == -1)
- field_width = INT_MAX;
- /* first, skip leading white space in buffer */
- while (isspace(*str))
- str++;
-
- /* now copy until next white space */
- while (*str && !isspace(*str) && field_width--) {
- *s++ = *str++;
- }
- *s = '\0';
- num++;
- }
- continue;
- case 'n':
- /* return number of characters read so far */
- {
- int *i = (int *)va_arg(args,int*);
- *i = str - buf;
- }
- continue;
- case 'o':
- base = 8;
- break;
- case 'x':
- case 'X':
- base = 16;
- break;
- case 'd':
- case 'i':
- is_sign = 1;
- case 'u':
- break;
- case '%':
- /* looking for '%' in str */
- if (*str++ != '%')
- return num;
- continue;
- default:
- /* invalid format; stop here */
- return num;
- }
-
- /* have some sort of integer conversion.
- * first, skip white space in buffer.
- */
- while (isspace(*str))
- str++;
-
- if (!*str || !isdigit(*str))
- break;
-
- switch(qualifier) {
- case 'h':
- if (is_sign) {
- short *s = (short *) va_arg(args,short *);
- *s = (short) simple_strtol(str,&next,base);
- } else {
- unsigned short *s = (unsigned short *) va_arg(args, unsigned short *);
- *s = (unsigned short) simple_strtoul(str, &next, base);
- }
- break;
- case 'l':
- if (is_sign) {
- long *l = (long *) va_arg(args,long *);
- *l = simple_strtol(str,&next,base);
- } else {
- unsigned long *l = (unsigned long*) va_arg(args,unsigned long*);
- *l = simple_strtoul(str,&next,base);
- }
- break;
- case 'L':
- if (is_sign) {
- long long *l = (long long*) va_arg(args,long long *);
- *l = simple_strtoll(str,&next,base);
- } else {
- unsigned long long *l = (unsigned long long*) va_arg(args,unsigned long long*);
- *l = simple_strtoull(str,&next,base);
- }
- break;
- case 'Z':
- {
- unsigned long *s = (unsigned long*) va_arg(args,unsigned long*);
- *s = (unsigned long) simple_strtoul(str,&next,base);
- }
- break;
- default:
- if (is_sign) {
- int *i = (int *) va_arg(args, int*);
- *i = (int) simple_strtol(str,&next,base);
- } else {
- unsigned int *i = (unsigned int*) va_arg(args, unsigned int*);
- *i = (unsigned int) simple_strtoul(str,&next,base);
- }
- break;
- }
- num++;
-
- if (!next)
- break;
- str = next;
- }
- return num;
-}
-
-/**
- * sscanf - Unformat a buffer into a list of arguments
- * @buf: input buffer
- * @fmt: formatting of buffer
- * @...: resulting arguments
- */
-int sscanf(const char * buf, const char * fmt, ...)
-{
- va_list args;
- int i;
-
- va_start(args,fmt);
- i = vsscanf(buf,fmt,args);
- va_end(args);
-
- return i;
-}
-
-size_t strspn(const char *s, const char *accept)
-{
- size_t l=0;
- int a=1,i, al=strlen(accept);
-
- while((a)&&(*s))
- {
- for(a=i=0;(!a)&&(i<al);i++)
- if (*s==accept[i]) a=1;
- if (a) l++;
- s++;
- }
- return l;
-}
-
-size_t strcspn(const char *s, const char *reject)
-{
- size_t l=0;
- int a=1,i,al=strlen(reject);
-
- while((a)&&(*s))
- {
- for(i=0;(a)&&(i<al);i++)
- if (*s==reject[i]) a=0;
- if (a) l++;
- s++;
- }
- return l;
-}
-
-char*strtok_r(char*s,const char*delim,char**ptrptr)
-{
- char*tmp=0;
-
- if (s==0) s=*ptrptr;
- s += strspn(s,delim); /* overread leading delimiter */
- if (*s)
- {
- tmp=s;
- s+=strcspn(s,delim);
-
- if (*s) *s++=0; /* not the end ? => terminate it */
- }
- *ptrptr=s;
- return tmp;
-}
-
-char *strtok(char *s, const char *delim)
-{
- static char *strtok_pos;
- return strtok_r(s,delim,&strtok_pos);
-}
-
-char *strchr(const char *s1, int i)
-{
- const unsigned char *s = (const unsigned char *)s1;
- unsigned char c = (unsigned int)i;
-
- while (*s && *s != c)
- {
- s++;
- }
-
- if (*s != c)
- {
- s = NULL;
- }
-
- return (char *) s;
-}
-
-long strtol(const char *str, char **endptr, int base)
-{
- return simple_strtol(str, endptr, base);
-}
-
-long long strtoll(const char *str, char **endptr, int base)
-{
- return simple_strtoll(str, endptr, base);
-}
-
-#endif
diff --git a/components/libc/compilers/minilibc/string.h b/components/libc/compilers/minilibc/string.h
deleted file mode 100644
index 45524c7764..0000000000
--- a/components/libc/compilers/minilibc/string.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2008-08-14 Bernard the first version
- */
-#ifndef __STRING_H__
-#define __STRING_H__
-
-#include <rtthread.h>
-#include <sys/types.h>
-
-/* replace for standard string library */
-#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
-
-#define ZEROPAD (1 << 0) /* pad with zero */
-#define SIGN (1 << 1) /* unsigned/signed long */
-#define PLUS (1 << 2) /* show plus */
-#define SPACE (1 << 3) /* space if plus */
-#define LEFT (1 << 4) /* left justified */
-#define SPECIAL (1 << 5) /* 0x */
-#define LARGE (1 << 6) /* use 'ABCDEF' instead of 'abcdef' */
-
-#define _U 0x01 /* upper */
-#define _L 0x02 /* lower */
-#define _D 0x04 /* digit */
-#define _C 0x08 /* cntrl */
-#define _P 0x10 /* punct */
-#define _S 0x20 /* white space (space/lf/tab) */
-#define _X 0x40 /* hex digit */
-#define _SP 0x80 /* hard space (0x20) */
-
-void* memset(void *s, int c, size_t n);
-void* memcpy(void *dest, const void *src, size_t n);
-void* memmove(void *dest, const void *src, size_t n);
-int memcmp(const void *s1, const void *s2, size_t n);
-
-int tolower(int c);
-int toupper(int c);
-
-int strcmp (const char *s1, const char *s2);
-int strncmp(const char *cs,const char *ct, size_t count);
-int strcasecmp(const char *a, const char *b);
-int strncasecmp(const char *cs, const char *ct, size_t count);
-int sscanf(const char * buf, const char * fmt, ...);
-size_t strlen(const char *s);
-char *strstr(const char * s1,const char * s2);
-char *strcpy(char *dest, const char *src);
-char *strncpy(char *dest, const char *src, size_t n);
-size_t strlcpy(char *dst, const char *src, size_t siz);
-char *strncat(char *dest, const char *src, size_t count);
-char *strcat(char * dest, const char * src);
-char *strchr(const char *s1, int i);
-char *strrchr(const char *t, int c);
-char *strdup(const char *s);
-char *strtok(char *s, const char *delim);
-char*strtok_r(char*s, const char*delim, char**ptrptr);
-
-size_t strcspn(const char *s, const char *reject);
-size_t strspn (const char *s, const char *accept);
-
-long strtol(const char *str, char **endptr, int base);
-long long strtoll(const char *str, char **endptr, int base);
-#endif
-
-#endif
diff --git a/components/libc/compilers/minilibc/sys/mman.h b/components/libc/compilers/minilibc/sys/mman.h
deleted file mode 100644
index 8c61b32b7c..0000000000
--- a/components/libc/compilers/minilibc/sys/mman.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/11/30 Bernard The first version.
- */
-
-#ifndef _SYS_MMAN_H
-#define _SYS_MMAN_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MAP_FAILED ((void *) -1)
-
-#define MAP_SHARED 0x01
-#define MAP_PRIVATE 0x02
-#define MAP_TYPE 0x0f
-#define MAP_FIXED 0x10
-#define MAP_ANON 0x20
-#define MAP_ANONYMOUS MAP_ANON
-#define MAP_NORESERVE 0x4000
-#define MAP_GROWSDOWN 0x0100
-#define MAP_DENYWRITE 0x0800
-#define MAP_EXECUTABLE 0x1000
-#define MAP_LOCKED 0x2000
-#define MAP_POPULATE 0x8000
-#define MAP_NONBLOCK 0x10000
-#define MAP_STACK 0x20000
-#define MAP_HUGETLB 0x40000
-#define MAP_FILE 0
-
-#define PROT_NONE 0
-#define PROT_READ 1
-#define PROT_WRITE 2
-#define PROT_EXEC 4
-#define PROT_GROWSDOWN 0x01000000
-#define PROT_GROWSUP 0x02000000
-
-#define MS_ASYNC 1
-#define MS_INVALIDATE 2
-#define MS_SYNC 4
-
-#define MCL_CURRENT 1
-#define MCL_FUTURE 2
-#define MCL_ONFAULT 4
-
-void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off);
-int munmap (void *start, size_t len);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/components/libc/compilers/minilibc/sys/stat.h b/components/libc/compilers/minilibc/sys/stat.h
deleted file mode 100644
index 65db477a4a..0000000000
--- a/components/libc/compilers/minilibc/sys/stat.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __STAT_H__
-#define __STAT_H__
-
-#include <rtthread.h>
-
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#else
-#define _FREAD 0x0001 /* read enabled */
-#define _FWRITE 0x0002 /* write enabled */
-#define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */
-#define _FMARK 0x0010 /* internal; mark during gc() */
-#define _FDEFER 0x0020 /* internal; defer for next gc pass */
-#define _FASYNC 0x0040 /* signal pgrp when data ready */
-#define _FSHLOCK 0x0080 /* BSD flock() shared lock present */
-#define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */
-#define _FCREAT 0x0200 /* open with file create */
-#define _FTRUNC 0x0400 /* open with truncation */
-#define _FEXCL 0x0800 /* error on open if file exists */
-#define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */
-#define _FSYNC 0x2000 /* do all writes synchronously */
-#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */
-#define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */
-#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */
-
-#define O_RDONLY 0 /* +1 == FREAD */
-#define O_WRONLY 1 /* +1 == FWRITE */
-#define O_RDWR 2 /* +1 == FREAD|FWRITE */
-#define O_APPEND _FAPPEND
-#define O_CREAT _FCREAT
-#define O_TRUNC _FTRUNC
-#define O_EXCL _FEXCL
-#define O_SYNC _FSYNC
-#endif
-
-#endif
diff --git a/components/libc/compilers/minilibc/sys/time.h b/components/libc/compilers/minilibc/sys/time.h
deleted file mode 100644
index 22a93f5c9d..0000000000
--- a/components/libc/compilers/minilibc/sys/time.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef _SYS_TIME_H_
-#define _SYS_TIME_H_
-
-#include <sys/types.h>
-typedef long time_t;
-
-/*
- * Structure returned by gettimeofday(2) system call,
- * and used in other calls.
- */
-struct timeval {
- long tv_sec; /* seconds */
- long tv_usec; /* and microseconds */
-};
-
-/*
- * Structure defined by POSIX.1b to be like a timeval.
- */
-struct timespec {
- time_t tv_sec; /* seconds */
- long tv_nsec; /* and nanoseconds */
-};
-
-struct timezone {
- int tz_minuteswest; /* minutes west of Greenwich */
- int tz_dsttime; /* type of dst correction */
-};
-
-struct tm {
- int tm_sec; /* Seconds. [0-60] (1 leap second) */
- int tm_min; /* Minutes. [0-59] */
- int tm_hour; /* Hours. [0-23] */
- int tm_mday; /* Day. [1-31] */
- int tm_mon; /* Month. [0-11] */
- int tm_year; /* Year - 1900. */
- int tm_wday; /* Day of week. [0-6] */
- int tm_yday; /* Days in year.[0-365] */
- int tm_isdst; /* DST. [-1/0/1]*/
-
- long int tm_gmtoff; /* Seconds east of UTC. */
- const char *tm_zone; /* Timezone abbreviation. */
-};
-
-int gettimeofday(struct timeval *tp, void *ignore);
-
-#endif
diff --git a/components/libc/compilers/minilibc/sys/types.h b/components/libc/compilers/minilibc/sys/types.h
deleted file mode 100644
index 746235273c..0000000000
--- a/components/libc/compilers/minilibc/sys/types.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __TYPES_H__
-#define __TYPES_H__
-#include <rtconfig.h>
-
-typedef long off_t;
-
-#ifndef ARCH_CPU_64BIT
-typedef unsigned int size_t;
-typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */
-#else
-typedef long unsigned int size_t;
-typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */
-#endif
-
-typedef unsigned char u_char;
-typedef unsigned short u_short;
-typedef unsigned int u_int;
-typedef unsigned long u_long;
-
-typedef unsigned long clockid_t;
-typedef int pid_t;
-
-typedef int gid_t;
-typedef int uid_t;
-typedef int dev_t;
-typedef int ino_t;
-typedef int mode_t;
-typedef int caddr_t;
-
-typedef unsigned int wint_t;
-typedef unsigned long useconds_t;
-
-typedef unsigned long clock_t; /* clock() */
-
-#ifndef NULL
-#define NULL (0)
-#endif
-
-#define __u_char_defined
-
-#endif
-
diff --git a/components/libc/compilers/minilibc/time.c b/components/libc/compilers/minilibc/time.c
deleted file mode 100644
index 25e8f0e310..0000000000
--- a/components/libc/compilers/minilibc/time.c
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#include <time.h>
-#include <rtthread.h>
-
-/* days per month -- nonleap! */
-const short __spm[13] =
-{ 0,
- (31),
- (31 + 28),
- (31 + 28 + 31),
- (31 + 28 + 31 + 30),
- (31 + 28 + 31 + 30 + 31),
- (31 + 28 + 31 + 30 + 31 + 30),
- (31 + 28 + 31 + 30 + 31 + 30 + 31),
- (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31),
- (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30),
- (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31),
- (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30),
- (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31),
-};
-static long int timezone;
-static const char days[] = "Sun Mon Tue Wed Thu Fri Sat ";
-static const char months[] = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
-
-/* seconds per day */
-#define SPD 24*60*60
-
-int __isleap(int year)
-{
- /* every fourth year is a leap year except for century years that are
- * not divisible by 400. */
- /* return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); */
- return (!(year % 4) && ((year % 100) || !(year % 400)));
-}
-
-struct tm *gmtime_r(const time_t *timep, struct tm *r)
-{
- time_t i;
- register time_t work = *timep % (SPD);
- r->tm_sec = work % 60;
- work /= 60;
- r->tm_min = work % 60;
- r->tm_hour = work / 60;
- work = *timep / (SPD);
- r->tm_wday = (4 + work) % 7;
- for (i = 1970;; ++i)
- {
- register time_t k = __isleap(i) ? 366 : 365;
- if (work >= k)
- work -= k;
- else
- break;
- }
- r->tm_year = i - 1900;
- r->tm_yday = work;
-
- r->tm_mday = 1;
- if (__isleap(i) && (work > 58))
- {
- if (work == 59)
- r->tm_mday = 2; /* 29.2. */
- work -= 1;
- }
-
- for (i = 11; i && (__spm[i] > work); --i)
- ;
- r->tm_mon = i;
- r->tm_mday += work - __spm[i];
- return r;
-}
-
-struct tm* localtime_r(const time_t* t, struct tm* r)
-{
- time_t tmp;
- struct timezone tz = {0};
- gettimeofday(0, &tz);
- timezone = tz.tz_minuteswest * 60L;
- tmp = *t + timezone;
- return gmtime_r(&tmp, r);
-}
-
-struct tm* localtime(const time_t* t)
-{
- static struct tm tmp;
- return localtime_r(t, &tmp);
-}
-
-time_t mktime(struct tm * const t)
-{
- register time_t day;
- register time_t i;
- register time_t years = t->tm_year - 70;
-
- if (t->tm_sec > 60)
- {
- t->tm_min += t->tm_sec / 60;
- t->tm_sec %= 60;
- }
- if (t->tm_min > 60)
- {
- t->tm_hour += t->tm_min / 60;
- t->tm_min %= 60;
- }
- if (t->tm_hour > 24)
- {
- t->tm_mday += t->tm_hour / 24;
- t->tm_hour %= 24;
- }
- if (t->tm_mon > 12)
- {
- t->tm_year += t->tm_mon / 12;
- t->tm_mon %= 12;
- }
- while (t->tm_mday > __spm[1 + t->tm_mon])
- {
- if (t->tm_mon == 1 && __isleap(t->tm_year + 1900))
- {
- --t->tm_mday;
- }
- t->tm_mday -= __spm[t->tm_mon];
- ++t->tm_mon;
- if (t->tm_mon > 11)
- {
- t->tm_mon = 0;
- ++t->tm_year;
- }
- }
-
- if (t->tm_year < 70)
- return (time_t) - 1;
-
- /* Days since 1970 is 365 * number of years + number of leap years since 1970 */
- day = years * 365 + (years + 1) / 4;
-
- /* After 2100 we have to substract 3 leap years for every 400 years
- This is not intuitive. Most mktime implementations do not support
- dates after 2059, anyway, so we might leave this out for it's
- bloat. */
- if (years >= 131)
- {
- years -= 131;
- years /= 100;
- day -= (years >> 2) * 3 + 1;
- if ((years &= 3) == 3)
- years--;
- day -= years;
- }
-
- day += t->tm_yday = __spm[t->tm_mon] + t->tm_mday - 1 +
- (__isleap(t->tm_year + 1900) & (t->tm_mon > 1));
-
- /* day is now the number of days since 'Jan 1 1970' */
- i = 7;
- t->tm_wday = (day + 4) % i; /* Sunday=0, Monday=1, ..., Saturday=6 */
-
- i = 24;
- day *= i;
- i = 60;
- return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec;
-}
-
-static void num2str(char *c, int i)
-{
- c[0] = i / 10 + '0';
- c[1] = i % 10 + '0';
-}
-
-char *asctime_r(const struct tm *t, char *buf)
-{
- /* "Wed Jun 30 21:49:08 1993\n" */
- *(int*) buf = *(int*) (days + (t->tm_wday << 2));
- *(int*) (buf + 4) = *(int*) (months + (t->tm_mon << 2));
- num2str(buf + 8, t->tm_mday);
- if (buf[8] == '0')
- buf[8] = ' ';
- buf[10] = ' ';
- num2str(buf + 11, t->tm_hour);
- buf[13] = ':';
- num2str(buf + 14, t->tm_min);
- buf[16] = ':';
- num2str(buf + 17, t->tm_sec);
- buf[19] = ' ';
- num2str(buf + 20, (t->tm_year + 1900) / 100);
- num2str(buf + 22, (t->tm_year + 1900) % 100);
- buf[24] = '\n';
- return buf;
-}
-
-char *asctime(const struct tm *timeptr)
-{
- static char buf[25];
- return asctime_r(timeptr, buf);
-}
-
-char *ctime(const time_t *timep)
-{
- return asctime(localtime(timep));
-}
-
-#ifdef RT_USING_DEVICE
-int gettimeofday(struct timeval *tp, void *ignore)
-{
- time_t time;
- rt_device_t device;
-
- device = rt_device_find("rtc");
- RT_ASSERT(device != RT_NULL);
-
- rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time);
- if (tp != RT_NULL)
- {
- tp->tv_sec = time;
- tp->tv_usec = 0;
- }
-
- return time;
-}
-#endif
-
-#ifndef _gettimeofday
-/* Dummy function when hardware do not have RTC */
-int _gettimeofday( struct timeval *tv, void *ignore)
-{
- tv->tv_sec = 0; // convert to seconds
- tv->tv_usec = 0; // get remaining microseconds
- return 0; // return non-zero for error
-}
-#endif
-
-/**
- * Returns the current time.
- *
- * @param time_t * t the timestamp pointer, if not used, keep NULL.
- *
- * @return time_t return timestamp current.
- *
- */
-/* for IAR 6.2 later Compiler */
-#if defined (__IAR_SYSTEMS_ICC__) && (__VER__) >= 6020000
-#pragma module_name = "?time"
-time_t (__time32)(time_t *t) /* Only supports 32-bit timestamp */
-#else
-time_t time(time_t *t)
-#endif
-{
- time_t time_now = 0;
-
-#ifdef RT_USING_RTC
- static rt_device_t device = RT_NULL;
-
- /* optimization: find rtc device only first. */
- if (device == RT_NULL)
- {
- device = rt_device_find("rtc");
- }
-
- /* read timestamp from RTC device. */
- if (device != RT_NULL)
- {
- if (rt_device_open(device, 0) == RT_EOK)
- {
- rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now);
- rt_device_close(device);
- }
- }
-#endif /* RT_USING_RTC */
-
- /* if t is not NULL, write timestamp to *t */
- if (t != RT_NULL)
- {
- *t = time_now;
- }
-
- return time_now;
-}
-
-RT_WEAK clock_t clock(void)
-{
- return rt_tick_get();
-}
diff --git a/components/libc/compilers/minilibc/time.h b/components/libc/compilers/minilibc/time.h
deleted file mode 100644
index 09fc7d2e67..0000000000
--- a/components/libc/compilers/minilibc/time.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __TIME_H__
-#define __TIME_H__
-
-#include <sys/time.h>
-
-time_t mktime(struct tm * const t);
-
-char *asctime(const struct tm *timeptr);
-char *ctime(const time_t *timep);
-struct tm* localtime(const time_t* t);
-
-char *asctime_r(const struct tm *t, char *buf);
-struct tm *gmtime_r(const time_t *timep, struct tm *r);
-struct tm* localtime_r(const time_t* t, struct tm* r);
-
-#endif
diff --git a/components/libc/compilers/newlib/README.md b/components/libc/compilers/newlib/README.md
index 385f329a4f..4614375b45 100644
--- a/components/libc/compilers/newlib/README.md
+++ b/components/libc/compilers/newlib/README.md
@@ -1,9 +1,4 @@
# NEWLIB (GCC) porting for RT-Thread
-Please define RT_USING_LIBC and compile RT-Thread with GCC compiler.
+https://sourceware.org/newlib/libc.html#Reentrancy
-
-
-## More Information
-
-https://sourceware.org/newlib/libc.html#Reentrancy \ No newline at end of file
diff --git a/components/libc/compilers/newlib/SConscript b/components/libc/compilers/newlib/SConscript
index d0868bbdea..8076a73727 100644
--- a/components/libc/compilers/newlib/SConscript
+++ b/components/libc/compilers/newlib/SConscript
@@ -1,21 +1,31 @@
+import os
from building import *
+from gcc import *
Import('rtconfig')
-src = Glob('*.c')
+src = []
cwd = GetCurrentDir()
group = []
-
+LIBS = ['m'] # link libm
CPPPATH = [cwd]
-CPPDEFINES = ['RT_USING_NEWLIB']
-
-# link with libc and libm:
-# libm is a frequently used lib. Newlib is compiled with -ffunction-sections in
-# recent GCC tool chains. The linker would just link in the functions that have
-# been referenced. So setting this won't result in bigger text size.
-LIBS = ['c', 'm']
if rtconfig.PLATFORM == 'gcc':
- group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'],
- CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
+ LIBS += ['c'] # link libc
+ src += Glob('*.c')
+
+ #report newlib version
+ print('Newlib version:' + GetNewLibVersion(rtconfig))
+
+ # identify this is Newlib, and only enable POSIX.1-1990
+ CPPDEFINES = ['RT_USING_NEWLIB', '_POSIX_C_SOURCE=1']
+
+ group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
+
+
+list = os.listdir(cwd)
+for d in list:
+ path = os.path.join(cwd, d)
+ if os.path.isfile(os.path.join(path, 'SConscript')):
+ group = group + SConscript(os.path.join(d, 'SConscript'))
Return('group')
diff --git a/components/libc/compilers/newlib/fcntl.h b/components/libc/compilers/newlib/fcntl.h
new file mode 100644
index 0000000000..847ae3d35b
--- /dev/null
+++ b/components/libc/compilers/newlib/fcntl.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-09-02 Meco Man First version
+ */
+
+#ifndef __FCNTL_H__
+#define __FCNTL_H__
+
+#include <sys/_default_fcntl.h>
+
+#ifndef O_DIRECTORY
+#define O_DIRECTORY 0x200000
+#endif
+
+#ifndef O_BINARY
+#define O_BINARY 0x10000
+#endif
+
+#endif
diff --git a/components/libc/compilers/newlib/legacy/SConscript b/components/libc/compilers/newlib/legacy/SConscript
new file mode 100644
index 0000000000..4c815c49b8
--- /dev/null
+++ b/components/libc/compilers/newlib/legacy/SConscript
@@ -0,0 +1,15 @@
+# RT-Thread building script for bridge
+
+import os
+from building import *
+
+cwd = GetCurrentDir()
+objs = []
+list = os.listdir(cwd)
+
+for d in list:
+ path = os.path.join(cwd, d)
+ if os.path.isfile(os.path.join(path, 'SConscript')):
+ objs = objs + SConscript(os.path.join(d, 'SConscript'))
+
+Return('objs')
diff --git a/components/libc/compilers/newlib/legacy/_select/SConscript b/components/libc/compilers/newlib/legacy/_select/SConscript
new file mode 100644
index 0000000000..b7bd86a36c
--- /dev/null
+++ b/components/libc/compilers/newlib/legacy/_select/SConscript
@@ -0,0 +1,20 @@
+from shutil import copy
+from building import *
+from gcc import *
+Import('rtconfig')
+
+src = []
+cwd = GetCurrentDir()
+CPPPATH = [cwd]
+group = []
+
+# sys/select.h does not exist in newlib 2.1.0 or lower version
+if rtconfig.PLATFORM == 'gcc' and (CheckHeader(rtconfig, 'sys/select.h') == False):
+ try:
+ copy("../../../../common/nogcc/sys/select.h", "./sys/select.h") # copy from 'nogcc/sys/select.h'
+ except:
+ pass
+
+ group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/components/libc/compilers/newlib/legacy/_select/readme.md b/components/libc/compilers/newlib/legacy/_select/readme.md
new file mode 100644
index 0000000000..4ad9f21923
--- /dev/null
+++ b/components/libc/compilers/newlib/legacy/_select/readme.md
@@ -0,0 +1,2 @@
+Newlib 2.2.0 or lower version does not provide `sys/select.h`, and `fd_set` is defined in `sys/types.h`. It will be generated by scons automatically, and **DO NOT** change it.
+
diff --git a/components/libc/compilers/newlib/legacy/_select/sys/select.h b/components/libc/compilers/newlib/legacy/_select/sys/select.h
new file mode 100644
index 0000000000..02fb77dd89
--- /dev/null
+++ b/components/libc/compilers/newlib/legacy/_select/sys/select.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-07-21 Meco Man The first version
+ */
+
+#ifndef __SYS_SELECT_H__
+#define __SYS_SELECT_H__
+
+#include <rtconfig.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#ifdef _WIN32
+#include <winsock.h>
+#endif
+
+#ifndef FD_SETSIZE
+#define FD_SETSIZE 32
+#endif
+
+#ifdef SAL_USING_POSIX
+#ifdef FD_SETSIZE
+#undef FD_SETSIZE
+#endif
+#define FD_SETSIZE DFS_FD_MAX
+#endif /* SAL_USING_POSIX */
+
+typedef long fd_mask;
+
+#ifndef _WIN32
+#ifndef _SYS_TYPES_FD_SET /* MIPS */
+
+#define NBBY 8 /* number of bits in a byte */
+#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
+#ifndef howmany
+#define howmany(x,y) (((x)+((y)-1))/(y))
+#endif
+
+typedef struct _types_fd_set {
+ fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
+} _types_fd_set;
+#define fd_set _types_fd_set
+
+#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
+#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
+#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
+#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
+#endif /* _SYS_TYPES_FD_SET */
+
+int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
+#endif /* _WIN32 */
+
+#endif /* __SYS_SELECT_H__ */
diff --git a/components/libc/compilers/newlib/libc.c b/components/libc/compilers/newlib/libc.c
deleted file mode 100644
index 2234c36f98..0000000000
--- a/components/libc/compilers/newlib/libc.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/10/15 bernard the first version
- */
-#include <rtthread.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <sys/time.h>
-
-#include "libc.h"
-
-#ifdef RT_USING_PTHREADS
-#include <pthread.h>
-#endif
-
-int _EXFUN(putenv,(char *__string));
-
-int libc_system_init(void)
-{
-#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS) & defined(RT_USING_CONSOLE)
- rt_device_t dev_console;
-
- dev_console = rt_console_get_device();
- if (dev_console)
- {
- #if defined(RT_USING_POSIX)
- libc_stdio_set_console(dev_console->parent.name, O_RDWR);
- #else
- libc_stdio_set_console(dev_console->parent.name, O_WRONLY);
- #endif
- }
-
- /* set PATH and HOME */
- putenv("PATH=/bin");
- putenv("HOME=/home");
-#endif
-
-#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT
- pthread_system_init();
-#endif
-
- return 0;
-}
-INIT_COMPONENT_EXPORT(libc_system_init);
diff --git a/components/libc/compilers/newlib/libc.h b/components/libc/compilers/newlib/libc.h
deleted file mode 100644
index fdf2ab4f60..0000000000
--- a/components/libc/compilers/newlib/libc.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/10/15 bernard the first version
- */
-#ifndef __RTT_LIBC_H__
-#define __RTT_LIBC_H__
-
-#include <stdio.h>
-#include <stdint.h>
-#include <string.h>
-#include <sys/time.h>
-
-#ifndef _EXFUN
-#define _EXFUN(name, proto) name proto
-#endif
-
-#define MILLISECOND_PER_SECOND 1000UL
-#define MICROSECOND_PER_SECOND 1000000UL
-#define NANOSECOND_PER_SECOND 1000000000UL
-
-#define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / RT_TICK_PER_SECOND)
-#define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND)
-#define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND)
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-int libc_system_init(void);
-int libc_stdio_set_console(const char* device_name, int mode);
-int libc_stdio_get_console(void);
-
-/* some time related function */
-int libc_set_time(const struct timespec* time);
-int libc_get_time(struct timespec* time);
-int libc_time_to_tick(const struct timespec* time);
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/components/libc/compilers/newlib/machine/time.h b/components/libc/compilers/newlib/machine/time.h
new file mode 100644
index 0000000000..805b061aea
--- /dev/null
+++ b/components/libc/compilers/newlib/machine/time.h
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-02-16 Meco Man The first version
+ */
+
+#ifndef _MACHTIME_H_
+#define _MACHTIME_H_
+
+#include <rtconfig.h>
+#define _CLOCKS_PER_SEC_ RT_TICK_PER_SECOND
+
+#endif /* _MACHTIME_H_ */
diff --git a/components/libc/compilers/newlib/stdio.c b/components/libc/compilers/newlib/stdio.c
deleted file mode 100644
index 233a447396..0000000000
--- a/components/libc/compilers/newlib/stdio.c
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/10/15 bernard the first version
- */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <rtthread.h>
-#include "libc.h"
-
-#define STDIO_DEVICE_NAME_MAX 32
-
-int _EXFUN(fileno, (FILE *));
-
-static FILE* std_console = NULL;
-
-int libc_stdio_set_console(const char* device_name, int mode)
-{
- FILE *fp;
- char name[STDIO_DEVICE_NAME_MAX];
- char *file_mode;
-
- snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
- name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
-
- if (mode == O_RDWR) file_mode = "r+";
- else if (mode == O_WRONLY) file_mode = "wb";
- else file_mode = "rb";
-
- fp = fopen(name, file_mode);
- if (fp)
- {
- setvbuf(fp, NULL, _IONBF, 0);
-
- if (std_console)
- {
- fclose(std_console);
- std_console = NULL;
- }
- std_console = fp;
-
- if (mode == O_RDWR)
- {
- _GLOBAL_REENT->_stdin = std_console;
- }
- else
- {
- _GLOBAL_REENT->_stdin = NULL;
- }
-
- if (mode == O_RDONLY)
- {
- _GLOBAL_REENT->_stdout = NULL;
- _GLOBAL_REENT->_stderr = NULL;
- }
- else
- {
- _GLOBAL_REENT->_stdout = std_console;
- _GLOBAL_REENT->_stderr = std_console;
- }
-
- _GLOBAL_REENT->__sdidinit = 1;
- }
-
- if (std_console) return fileno(std_console);
-
- return -1;
-}
-
-int libc_stdio_get_console(void) {
- if (std_console)
- return fileno(std_console);
- else
- return -1;
-}
diff --git a/components/libc/compilers/newlib/sys/dirent.h b/components/libc/compilers/newlib/sys/dirent.h
deleted file mode 100644
index db8c0655a1..0000000000
--- a/components/libc/compilers/newlib/sys/dirent.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __RTT_DIRENT_H__
-#define __RTT_DIRENT_H__
-
-#include <rtthread.h>
-
-/*
-* dirent.h - format of directory entries
- * Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html
- */
-
-/* File types */
-#define FT_REGULAR 0 /* regular file */
-#define FT_SOCKET 1 /* socket file */
-#define FT_DIRECTORY 2 /* directory */
-#define FT_USER 3 /* user defined */
-
-#define DT_UNKNOWN 0x00
-#define DT_REG 0x01
-#define DT_DIR 0x02
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef HAVE_DIR_STRUCTURE
-typedef struct
-{
- int fd; /* directory file */
- char buf[512];
- int num;
- int cur;
-} DIR;
-#endif
-
-#ifndef HAVE_DIRENT_STRUCTURE
-struct dirent
-{
- rt_uint8_t d_type; /* The type of the file */
- rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */
- rt_uint16_t d_reclen; /* length of this record */
- char d_name[256]; /* The null-terminated file name */
-};
-#endif
-
-int closedir(DIR *);
-DIR *opendir(const char *);
-struct dirent *readdir(DIR *);
-int readdir_r(DIR *, struct dirent *, struct dirent **);
-void rewinddir(DIR *);
-void seekdir(DIR *, long int);
-long telldir(DIR *);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/components/libc/compilers/newlib/sys/mman.h b/components/libc/compilers/newlib/sys/mman.h
deleted file mode 100644
index 8c61b32b7c..0000000000
--- a/components/libc/compilers/newlib/sys/mman.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/11/30 Bernard The first version.
- */
-
-#ifndef _SYS_MMAN_H
-#define _SYS_MMAN_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MAP_FAILED ((void *) -1)
-
-#define MAP_SHARED 0x01
-#define MAP_PRIVATE 0x02
-#define MAP_TYPE 0x0f
-#define MAP_FIXED 0x10
-#define MAP_ANON 0x20
-#define MAP_ANONYMOUS MAP_ANON
-#define MAP_NORESERVE 0x4000
-#define MAP_GROWSDOWN 0x0100
-#define MAP_DENYWRITE 0x0800
-#define MAP_EXECUTABLE 0x1000
-#define MAP_LOCKED 0x2000
-#define MAP_POPULATE 0x8000
-#define MAP_NONBLOCK 0x10000
-#define MAP_STACK 0x20000
-#define MAP_HUGETLB 0x40000
-#define MAP_FILE 0
-
-#define PROT_NONE 0
-#define PROT_READ 1
-#define PROT_WRITE 2
-#define PROT_EXEC 4
-#define PROT_GROWSDOWN 0x01000000
-#define PROT_GROWSUP 0x02000000
-
-#define MS_ASYNC 1
-#define MS_INVALIDATE 2
-#define MS_SYNC 4
-
-#define MCL_CURRENT 1
-#define MCL_FUTURE 2
-#define MCL_ONFAULT 4
-
-void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off);
-int munmap (void *start, size_t len);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/components/libc/compilers/newlib/sys/statfs.h b/components/libc/compilers/newlib/sys/statfs.h
deleted file mode 100644
index 3c923a21f9..0000000000
--- a/components/libc/compilers/newlib/sys/statfs.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __RTT_STATFS_H__
-#define __RTT_STATFS_H__
-
-#include <rtthread.h>
-
-struct statfs
-{
- rt_size_t f_bsize; /* block size */
- rt_size_t f_blocks; /* total data blocks in file system */
- rt_size_t f_bfree; /* free blocks in file system */
-};
-
-#endif
diff --git a/components/libc/compilers/newlib/sys/termios.h b/components/libc/compilers/newlib/sys/termios.h
deleted file mode 100644
index ce95230e88..0000000000
--- a/components/libc/compilers/newlib/sys/termios.h
+++ /dev/null
@@ -1,8 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c
index 228fa0d140..dcf26ccfb7 100644
--- a/components/libc/compilers/newlib/syscalls.c
+++ b/components/libc/compilers/newlib/syscalls.c
@@ -1,455 +1,339 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
+ * 2021-02-11 Meco Man remove _gettimeofday_r() and _times_r()
+ * 2020-02-13 Meco Man re-implement exit() and abort()
+ * 2020-02-21 Meco Man improve and beautify syscalls
+ * 2020-02-24 Meco Man fix bug of _isatty_r()
*/
+
#include <reent.h>
-#include <sys/errno.h>
-#include <sys/time.h>
+#include <rtthread.h>
#include <stdio.h>
+#include <string.h>
+#include <stddef.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/errno.h>
+#include <sys/stat.h>
+#ifdef RT_USING_POSIX_STDIO
+#include "libc.h"
+#endif /* RT_USING_POSIX_STDIO */
+#ifdef RT_USING_MODULE
+#include <dlmodule.h>
+#endif /* RT_USING_MODULE */
+#include <compiler_private.h>
+#define DBG_TAG "newlib.syscalls"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
-#include <rtthread.h>
+#ifdef RT_USING_HEAP /* Memory routine */
+void *_malloc_r (struct _reent *ptr, size_t size)
+{
+ void* result;
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
+ result = (void*)rt_malloc (size);
+ if (result == RT_NULL)
+ {
+ ptr->_errno = ENOMEM;
+ }
-#ifdef RT_USING_MODULE
-#include <dlmodule.h>
-#endif
+ return result;
+}
-/* Reentrant versions of system calls. */
+void *_realloc_r (struct _reent *ptr, void *old, size_t newlen)
+{
+ void* result;
+
+ result = (void*)rt_realloc (old, newlen);
+ if (result == RT_NULL)
+ {
+ ptr->_errno = ENOMEM;
+ }
+
+ return result;
+}
+
+void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
+{
+ void* result;
+ result = (void*)rt_calloc (size, len);
+ if (result == RT_NULL)
+ {
+ ptr->_errno = ENOMEM;
+ }
+
+ return result;
+}
+
+void _free_r (struct _reent *ptr, void *addr)
+{
+ rt_free (addr);
+}
+
+#else
+void *
+_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
+{
+ LOG_E("Please enable RT_USING_HEAP");
+ RT_ASSERT(0);
+ return RT_NULL;
+}
+#endif /*RT_USING_HEAP*/
+
+void __libc_init_array(void)
+{
+ /* we not use __libc init_aray to initialize C++ objects */
+ /* __libc_init_array is ARM code, not Thumb; it will cause a hardfault. */
+}
+
+/* Reentrant versions of system calls. */
#ifndef _REENT_ONLY
-int *
-__errno ()
+int *__errno ()
{
return _rt_errno();
}
#endif
-int
-_close_r(struct _reent *ptr, int fd)
+int _getpid_r(struct _reent *ptr)
{
-#ifndef RT_USING_DFS
return 0;
-#else
- return close(fd);
-#endif
}
-int
-_execve_r(struct _reent *ptr, const char * name, char *const *argv, char *const *env)
+int _close_r(struct _reent *ptr, int fd)
{
- /* return "not supported" */
+#ifdef DFS_USING_POSIX
+ return close(fd);
+#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
ptr->_errno = ENOTSUP;
return -1;
+#endif /* DFS_USING_POSIX */
}
-int
-_fcntl_r(struct _reent *ptr, int fd, int cmd, int arg)
+int _execve_r(struct _reent *ptr, const char * name, char *const *argv, char *const *env)
{
- /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
}
-int
-_fork_r(struct _reent *ptr)
+int _fcntl_r(struct _reent *ptr, int fd, int cmd, int arg)
{
- /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
}
-int
-_fstat_r(struct _reent *ptr, int fd, struct stat *pstat)
+int _fork_r(struct _reent *ptr)
{
- /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
}
-int
-_getpid_r(struct _reent *ptr)
+int _fstat_r(struct _reent *ptr, int fd, struct stat *pstat)
{
- return 0;
+ ptr->_errno = ENOTSUP;
+ return -1;
}
-int
-_isatty_r(struct _reent *ptr, int fd)
+int _isatty_r(struct _reent *ptr, int fd)
{
- if (fd >=0 && fd < 3) return 1;
+ if (fd >=0 && fd < 3)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
- /* return "not supported" */
+int _kill_r(struct _reent *ptr, int pid, int sig)
+{
ptr->_errno = ENOTSUP;
return -1;
}
-int
-_kill_r(struct _reent *ptr, int pid, int sig)
+int _link_r(struct _reent *ptr, const char *old, const char *new)
{
- /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
}
-int
-_link_r(struct _reent *ptr, const char *old, const char *new)
+int _wait_r(struct _reent *ptr, int *status)
{
- /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
}
-_off_t
-_lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
+mode_t umask(mode_t mask)
{
-#ifndef RT_USING_DFS
- return 0;
-#else
- _off_t rc;
-
- rc = lseek(fd, pos, whence);
- return rc;
-#endif
+ return 022;
}
-int
-_mkdir_r(struct _reent *ptr, const char *name, int mode)
+int flock(int fd, int operation)
{
-#ifndef RT_USING_DFS
return 0;
-#else
- int rc;
-
- rc = mkdir(name, mode);
- return rc;
-#endif
}
-int
-_open_r(struct _reent *ptr, const char *file, int flags, int mode)
+_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
{
-#ifndef RT_USING_DFS
- return 0;
-#else
- int rc;
-
- rc = open(file, flags, mode);
+#ifdef DFS_USING_POSIX
+ _off_t rc;
+ rc = lseek(fd, pos, whence);
return rc;
-#endif
-}
-
-_ssize_t
-_read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
-{
-#ifndef RT_USING_DFS
- return 0;
#else
- _ssize_t rc;
-
- rc = read(fd, buf, nbytes);
- return rc;
-#endif
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
+ ptr->_errno = ENOTSUP;
+ return -1;
+#endif /* DFS_USING_POSIX */
}
-int
-_rename_r(struct _reent *ptr, const char *old, const char *new)
+int _mkdir_r(struct _reent *ptr, const char *name, int mode)
{
-#ifndef RT_USING_DFS
- return 0;
-#else
+#ifdef DFS_USING_POSIX
int rc;
-
- rc = rename(old, new);
+ rc = mkdir(name, mode);
return rc;
-#endif
-}
-
-void *
-_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
-{
- /* no use this routine to get memory */
- return RT_NULL;
-}
-
-int
-_stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
-{
-#ifndef RT_USING_DFS
- return 0;
#else
- int rc;
-
- rc = stat(file, pstat);
- return rc;
-#endif
-}
-
-_CLOCK_T_
-_times_r(struct _reent *ptr, struct tms *ptms)
-{
- /* return "not supported" */
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
ptr->_errno = ENOTSUP;
return -1;
+#endif /* DFS_USING_POSIX */
}
-int
-_unlink_r(struct _reent *ptr, const char *file)
+int _open_r(struct _reent *ptr, const char *file, int flags, int mode)
{
-#ifndef RT_USING_DFS
- return 0;
-#else
+#ifdef DFS_USING_POSIX
int rc;
-
- rc = unlink(file);
+ rc = open(file, flags, mode);
return rc;
-#endif
-}
-
-int
-_wait_r(struct _reent *ptr, int *status)
-{
- /* return "not supported" */
+#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
ptr->_errno = ENOTSUP;
return -1;
+#endif /* DFS_USING_POSIX */
}
-#ifdef RT_USING_DEVICE
-_ssize_t
-_write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
+_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
{
-#ifndef RT_USING_DFS
- if (fileno(stdout) == fd)
- {
- rt_device_t console;
-
- console = rt_console_get_device();
- if (console) return rt_device_write(console, -1, buf, nbytes);
- }
-
- return 0;
-
-#else
+#ifdef DFS_USING_POSIX
_ssize_t rc;
-
- rc = write(fd, buf, nbytes);
- return rc;
-#endif
-}
-#endif
-
-#ifdef RT_USING_PTHREADS
-
-#include <clock_time.h>
-/* POSIX timer provides clock_gettime function */
-#include <time.h>
-int
-_gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp)
-{
- struct timespec tp;
-
- if (clock_gettime(CLOCK_REALTIME, &tp) == 0)
+ if (fd == STDIN_FILENO)
{
- if (__tp != RT_NULL)
+#ifdef RT_USING_POSIX_STDIO
+ if (libc_stdio_get_console() < 0)
{
- __tp->tv_sec = tp.tv_sec;
- __tp->tv_usec = tp.tv_nsec / 1000UL;
+ LOG_W("Do not invoke standard input before initializing Compiler");
+ return 0;
}
-
- return tp.tv_sec;
- }
-
- /* return "not supported" */
- ptr->_errno = ENOTSUP;
- return -1;
-}
-
#else
-
-#define MILLISECOND_PER_SECOND 1000UL
-#define MICROSECOND_PER_SECOND 1000000UL
-#define NANOSECOND_PER_SECOND 1000000000UL
-
-#define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / RT_TICK_PER_SECOND)
-#define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND)
-#define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND)
-
-struct timeval _timevalue = {0};
-#ifdef RT_USING_DEVICE
-static void libc_system_time_init(void)
-{
- time_t time;
- rt_tick_t tick;
- rt_device_t device;
-
- time = 0;
- device = rt_device_find("rtc");
- if (device != RT_NULL)
- {
- /* get realtime seconds */
- rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time);
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_STDIO);
+ ptr->_errno = ENOTSUP;
+ return -1;
+#endif /* RT_USING_POSIX_STDIO */
}
-
- /* get tick */
- tick = rt_tick_get();
-
- _timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK;
- _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1;
-}
-#endif
-
-int libc_get_time(struct timespec *time)
-{
- rt_tick_t tick;
- static rt_bool_t inited = 0;
-
- RT_ASSERT(time != RT_NULL);
-
- /* initialize system time */
- if (inited == 0)
+ else if (fd == STDOUT_FILENO || fd == STDERR_FILENO)
{
- libc_system_time_init();
- inited = 1;
+ ptr->_errno = ENOTSUP;
+ return -1;
}
- /* get tick */
- tick = rt_tick_get();
-
- time->tv_sec = _timevalue.tv_sec + tick / RT_TICK_PER_SECOND;
- time->tv_nsec = (_timevalue.tv_usec + (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK) * 1000;
-
- return 0;
+ rc = read(fd, buf, nbytes);
+ return rc;
+#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
+ ptr->_errno = ENOTSUP;
+ return -1;
+#endif /* DFS_USING_POSIX */
}
-int
-_gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp)
+int _rename_r(struct _reent *ptr, const char *old, const char *new)
{
- struct timespec tp;
-
- if (libc_get_time(&tp) == 0)
- {
- if (__tp != RT_NULL)
- {
- __tp->tv_sec = tp.tv_sec;
- __tp->tv_usec = tp.tv_nsec / 1000UL;
- }
-
- return tp.tv_sec;
- }
-
- /* return "not supported" */
+#ifdef DFS_USING_POSIX
+ int rc;
+ rc = rename(old, new);
+ return rc;
+#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
ptr->_errno = ENOTSUP;
return -1;
+#endif /* DFS_USING_POSIX */
}
-#endif
-/* Memory routine */
-void *
-_malloc_r (struct _reent *ptr, size_t size)
+int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
{
- void* result;
-
- result = (void*)rt_malloc (size);
- if (result == RT_NULL)
- {
- ptr->_errno = ENOMEM;
- }
-
- return result;
+#ifdef DFS_USING_POSIX
+ int rc;
+ rc = stat(file, pstat);
+ return rc;
+#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
+ ptr->_errno = ENOTSUP;
+ return -1;
+#endif /* DFS_USING_POSIX */
}
-void *
-_realloc_r (struct _reent *ptr, void *old, size_t newlen)
+int _unlink_r(struct _reent *ptr, const char *file)
{
- void* result;
-
- result = (void*)rt_realloc (old, newlen);
- if (result == RT_NULL)
- {
- ptr->_errno = ENOMEM;
- }
-
- return result;
+#ifdef DFS_USING_POSIX
+ return unlink(file);
+#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
+ ptr->_errno = ENOTSUP;
+ return -1;
+#endif /* DFS_USING_POSIX */
}
-void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
+_ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
{
- void* result;
+#ifdef DFS_USING_POSIX
+ _ssize_t rc;
+#endif /* DFS_USING_POSIX */
- result = (void*)rt_calloc (size, len);
- if (result == RT_NULL)
+ if (fd == STDOUT_FILENO || fd == STDERR_FILENO)
{
- ptr->_errno = ENOMEM;
- }
-
- return result;
-}
-
-void
-_free_r (struct _reent *ptr, void *addr)
-{
- rt_free (addr);
-}
+#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
+ rt_device_t console;
-void
-exit (int status)
-{
-#ifdef RT_USING_MODULE
- if (dlmodule_self())
- {
- dlmodule_exit(status);
+ console = rt_console_get_device();
+ if (console)
+ return rt_device_write(console, -1, buf, nbytes);
+#else
+ ptr->_errno = ENOTSUP;
+ return -1;
+#endif /* defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) */
}
-#endif
-
- rt_kprintf("thread:%s exit with %d\n", rt_thread_self()->name, status);
- RT_ASSERT(0);
-
- while (1);
-}
-
-void
-_system(const char *s)
-{
- /* not support this call */
- return;
-}
-
-void __libc_init_array(void)
-{
- /* we not use __libc init_aray to initialize C++ objects */
-}
-
-void abort(void)
-{
- if (rt_thread_self())
+ else if (fd == STDIN_FILENO)
{
- rt_thread_t self = rt_thread_self();
-
- rt_kprintf("thread:%-8.*s abort!\n", RT_NAME_MAX, self->name);
- rt_thread_suspend(self);
-
- rt_schedule();
+ ptr->_errno = ENOTSUP;
+ return -1;
}
- while (1);
-}
-
-uid_t getuid(void)
-{
- return 0;
+#ifdef DFS_USING_POSIX
+ rc = write(fd, buf, nbytes);
+ return rc;
+#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
+ ptr->_errno = ENOTSUP;
+ return -1;
+#endif /* DFS_USING_POSIX */
}
-mode_t umask(mode_t mask)
+/* for exit() and abort() */
+__attribute__ ((noreturn)) void _exit (int status)
{
- return 022;
+ extern void __rt_libc_exit(int status);
+ __rt_libc_exit(status);
+ while(1);
}
-int flock(int fd, int operation)
-{
- return 0;
-}
+/*
+These functions are implemented and replaced by the 'common/time.c' file
+int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp);
+_CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms);
+*/
diff --git a/components/libc/compilers/readme.md b/components/libc/compilers/readme.md
new file mode 100644
index 0000000000..e376cc704f
--- /dev/null
+++ b/components/libc/compilers/readme.md
@@ -0,0 +1 @@
+This folder provides uniformed header files crossing different compiler platforms, and supports basic standard C library functions, such as memory management and time management, etc. \ No newline at end of file
diff --git a/components/libc/getline/README.md b/components/libc/getline/README.md
deleted file mode 100644
index 0b279755d3..0000000000
--- a/components/libc/getline/README.md
+++ /dev/null
@@ -1,30 +0,0 @@
-# getline/getdelim for RT-Thread POSIX(IEEE Std 1003.1-2008)
-
-[![Build Status](https://travis-ci.org/ivanrad/getline.svg?branch=master)](https://travis-ci.org/ivanrad/getline)
-
-https://github.com/ivanrad/getline
-
-Read a delimited record from stream.
-
-Yet another (hopefully portable C) implementation of getline/getdelim.
-These are ersatz functions, a drop-in replacement, to be used on those occasions when your C library does not already support them.
-
-For more details, see [Open Group Base Specification for getdelim/getline][opengroup-spec].
-
-
-
-## License
-
-This code is unlicensed -- free and released into the public domain. See `UNLICENSE` file for more information.
-
-[opengroup-spec]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getline.html
-
-
-
-
-## 联系&维护
-Meco Man
-
-
-https://github.com/mysterywolf/getline
diff --git a/components/libc/getline/SConscript b/components/libc/getline/SConscript
deleted file mode 100644
index fa4c8618c1..0000000000
--- a/components/libc/getline/SConscript
+++ /dev/null
@@ -1,13 +0,0 @@
-# RT-Thread building script for component
-
-from building import *
-
-cwd = GetCurrentDir()
-src = Glob('*.c') + Glob('*.cpp')
-CPPPATH = [cwd]
-
-group = DefineGroup('libc', src,
- depend = ['RT_USING_LIBC', 'RT_USING_POSIX','RT_USING_POSIX_GETLINE'],
- CPPPATH = CPPPATH)
-
-Return('group')
diff --git a/components/libc/getline/UNLICENSE b/components/libc/getline/UNLICENSE
deleted file mode 100644
index 68a49daad8..0000000000
--- a/components/libc/getline/UNLICENSE
+++ /dev/null
@@ -1,24 +0,0 @@
-This is free and unencumbered software released into the public domain.
-
-Anyone is free to copy, modify, publish, use, compile, sell, or
-distribute this software, either in source code form or as a compiled
-binary, for any purpose, commercial or non-commercial, and by any
-means.
-
-In jurisdictions that recognize copyright laws, the author or authors
-of this software dedicate any and all copyright interest in the
-software to the public domain. We make this dedication for the benefit
-of the public at large and to the detriment of our heirs and
-successors. We intend this dedication to be an overt act of
-relinquishment in perpetuity of all present and future rights to this
-software under copyright law.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-For more information, please refer to <http://unlicense.org/>
diff --git a/components/libc/getline/posix_getline.c b/components/libc/getline/posix_getline.c
deleted file mode 100644
index e2ac278242..0000000000
--- a/components/libc/getline/posix_getline.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/* posix_getline.c
- * RT-Thread POSIX
- * getdelim(), getline() - read a delimited record from stream, ersatz implementation
- * This code is unlicensed -- free and released into the public domain.
- * https://man7.org/linux/man-pages/man3/getline.3.html
- * Authors:
- * https://github.com/ivanrad/getline
- * https://github.com/mysterywolf/getline/
- *
- * Meco Man 2020-09-03 First Version
- */
-
-#include "posix_getline.h"
-#include <stdlib.h>
-#include <errno.h>
-#include <rtlibc.h>
-
-ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream) {
- char *cur_pos, *new_lineptr;
- size_t new_lineptr_len;
- int c;
-
- if (lineptr == NULL || n == NULL || stream == NULL) {
- errno = EINVAL;
- return -1;
- }
-
- if (*lineptr == NULL) {
- *n = 128; /* init len */
- if ((*lineptr = (char *)malloc(*n)) == NULL) {
- errno = ENOMEM;
- return -1;
- }
- }
-
- cur_pos = *lineptr;
- for (;;) {
- c = getc(stream);
-
- if (ferror(stream) || (c == EOF && cur_pos == *lineptr))
- return -1;
-
- if (c == EOF)
- break;
-
- if ((*lineptr + *n - cur_pos) < 2) {
- if (SSIZE_MAX / 2 < *n) {
-#ifdef EOVERFLOW
- errno = EOVERFLOW;
-#else
- errno = ERANGE; /* no EOVERFLOW defined */
-#endif
- return -1;
- }
- new_lineptr_len = *n * 2;
-
- if ((new_lineptr = (char *)realloc(*lineptr, new_lineptr_len)) == NULL) {
- errno = ENOMEM;
- return -1;
- }
- cur_pos = new_lineptr + (cur_pos - *lineptr);
- *lineptr = new_lineptr;
- *n = new_lineptr_len;
- }
-
- *cur_pos++ = (char)c;
-
- if (c == delim)
- break;
- }
-
- *cur_pos = '\0';
- return (ssize_t)(cur_pos - *lineptr);
-}
-
-ssize_t getline(char **lineptr, size_t *n, FILE *stream) {
- return getdelim(lineptr, n, '\n', stream);
-}
-
diff --git a/components/libc/getline/posix_getline.h b/components/libc/getline/posix_getline.h
deleted file mode 100644
index c7d6021af3..0000000000
--- a/components/libc/getline/posix_getline.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* posix_getline.h
- * RT-Thread POSIX
- * getdelim(), getline() - read a delimited record from stream, ersatz implementation
- * This code is unlicensed -- free and released into the public domain.
- * https://man7.org/linux/man-pages/man3/getline.3.html
- * Authors:
- * https://github.com/ivanrad/getline
- * https://github.com/mysterywolf/getline/
- *
- * Meco Man 2020-09-03 First Version
- */
-
-
-#ifndef POSIX_GETLINE_H
-#define POSIX_GETLINE_H
-
-#include <stdio.h>
-#include <sys/types.h>
-
-ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
-ssize_t getline(char **lineptr, size_t *n, FILE *stream);
-
-#endif /* POSIX_GETLINE_H */
-
diff --git a/components/libc/libdl/SConscript b/components/libc/libdl/SConscript
deleted file mode 100644
index 93636e4b7a..0000000000
--- a/components/libc/libdl/SConscript
+++ /dev/null
@@ -1,14 +0,0 @@
-from building import *
-Import('rtconfig')
-
-src = Glob('*.c') + Glob('*.cpp') + Glob('arch/*.c')
-cwd = GetCurrentDir()
-group = []
-CPPPATH = [cwd]
-
-if rtconfig.PLATFORM == 'gcc':
- group = DefineGroup('libc', src,
- depend = ['RT_USING_MODULE'],
- CPPPATH = CPPPATH)
-
-Return('group')
diff --git a/components/libc/posix-info.txt b/components/libc/posix-info.txt
new file mode 100644
index 0000000000..5b779b1564
--- /dev/null
+++ b/components/libc/posix-info.txt
@@ -0,0 +1,324 @@
+### The list of function support for POSIX 51 standard in the RT-Thread
+
+<ctype.h>
++ isalnum()
++ isalpha()
++ isblank()
++ iscntrl()
++ isdigit()
++ isgraph()
++ islower()
++ isprint()
++ ispunct()
++ isspace()
++ isupper()
++ isxdigit()
++ tolower()
++ toupper()
+
+<errno.h> -> Suggesting to use <sys/errno.h> instead of <errno.h> to be compatible with three compilation platforms of IAR Keil GCC at the same time.
++ errno
+
+<fcntl.h>
++ open()
+
+<fenv.h> ;the 'env' should combined with non-volatile devices
++ feclearexcept()
++ fegetenv()
++ fegetexceptflag()
++ fegetround()
++ feholdexcept()
++ feraiseexcept()
++ fesetenv()
++ fesetexceptflag()
++ fesetround()
++ fetestexcept()
++ feupdateenv()
+
+<inttypes.h>
++ imaxabs()
++ imaxdiv()
++ strtoimax()
++ strtoumax()
+
+<locale.h>
++ localeconv()
++ setlocale()
+
+<pthread.h>
++ pthread_atfork()
++ pthread_attr_destroy()
++ pthread_attr_getdetachstate()
++ pthread_attr_getguardsize()
++ pthread_attr_getinheritsched()
++ pthread_attr_getschedparam()
++ pthread_attr_getschedpolicy()
++ pthread_attr_getscope()
++ pthread_attr_getstack()
++ pthread_attr_getstackaddr()
++ pthread_attr_getstacksize()
++ pthread_attr_init()
++ pthread_attr_setdetachstate()
++ pthread_attr_setguardsize()
++ pthread_attr_setinheritsched()
++ pthread_attr_setschedparam()
++ pthread_attr_setschedpolicy()
++ pthread_attr_setscope()
++ pthread_attr_setstack()
++ pthread_attr_setstackaddr()
++ pthread_attr_setstacksize()
++ pthread_cancel()
++ pthread_cleanup_pop()
++ pthread_cleanup_push()
++ pthread_cond_broadcast()
++ pthread_cond_destroy()
++ pthread_cond_init()
++ pthread_cond_signal()
++ pthread_cond_timedwait()
++ pthread_cond_wait()
++ pthread_condattr_destroy()
++ pthread_condattr_getclock()
++ pthread_condattr_init()
++ pthread_condattr_setclock()
++ pthread_create()
++ pthread_detach()
++ pthread_equal()
++ pthread_exit()
++ pthread_getcpuclockid()
++ pthread_getconcurrency()
++ pthread_getschedparam()
++ pthread_getspecific()
++ pthread_join()
++ pthread_key_create()
++ pthread_key_delete()
++ pthread_mutex_destroy()
++ pthread_mutex_getprioceiling()
++ pthread_mutex_init()
++ pthread_mutex_lock()
++ pthread_mutex_setprioceiling()
++ pthread_mutex_trylock()
++ pthread_mutex_unlock()
++ pthread_mutexattr_destroy()
++ pthread_mutexattr_getprioceiling()
++ pthread_mutexattr_getprotocol()
++ pthread_mutexattr_gettype()
++ pthread_mutexattr_init()
++ pthread_mutexattr_setprioceiling()
++ pthread_mutexattr_setprotocol()
++ pthread_mutexattr_settype()
++ pthread_once()
++ pthread_self()
++ pthread_setcancelstate()
++ pthread_setcanceltype()
++ pthread_setconcurrency()
++ pthread_setschedparam()
++ pthread_setschedprio()
++ pthread_setspecific()
++ pthread_testcancel()
+
+<sched.h>
++ sched_get_priority_max()
++ sched_get_priority_min()
++ sched_rr_get_interval()
+
+<samaphore.h>
++ sem_close()
++ sem_destroy()
++ sem_getvalue()
++ sem_init()
++ sem_open()
++ sem_post()
++ sem_timedwait()
++ sem_trywait()
++ sem_unlink()
++ sem_wait()
+
+<setjmp.h>
++ longjmp()
++ setjmp()
+
+<signal.h> -> Suggesting to use <sys/signal.h> instead of <signal.h> to be compatible with three compilation platforms of IAR Keil GCC at the same time.
++ kill()
++ pthread_kill()
++ pthread_sigmask()
++ raise()
++ sigaction()
++ sigaddset()
++ sigdelset()
++ sigemptyset()
++ sigfillset()
++ sigismember()
++ signal()
++ sigpending()
++ sigprocmask()
+- sigqueue()
++ sigsuspend()
++ sigtimedwait()
++ sigwait()
++ sigwaitinfo()
+
+<stdarg.h>
++ va_arg()
++ va_copy()
++ va_end()
++ va_start()
+
+<stdio.h>
++ clearerr()
++ fclose()
+- fdopen()
++ feof()
++ ferror()
++ fflush()
++ fgetc()
++ fgets()
++ fileno() ; GCC and IAR support, but Keil doesn't support
+- flockfile()
++ fopen()
++ fprintf()
++ fputc()
++ fputs()
++ fread()
++ freopen()
++ fscanf()
+- ftrylockfile()
+- funlockfile()
++ fwrite()
++ getc()
+% getc_unlocked() ; thread safe in the default
++ getchar()
++ getchar_unlocked()
++ gets()
++ perror()
++ printf()
++ putc()
+% putc_unlocked() ; thread safe in the default
++ putchar()
+% putchar_unlocked() ; thread safe in the default
++ puts()
++ scanf()
++ setbuf()
++ setvbuf()
++ snprintf()
++ sprintf()
++ sscanf()
++ stderr
++ stdin
++ stdout
++ ungetc()
++ vfprintf()
++ vfscanf()
++ vprintf()
++ vscanf()
++ vsnprintf()
++ vsprintf()
++ vsscanf()
+
+<stdlib.h>
++ abort()
++ abs()
++ atof()
++ atoi()
++ atol()
++ atoll()
++ bsearch()
++ calloc()
++ div()
++ free()
++ getenv()
++ labs()
++ ldiv()
++ llabs()
++ lldiv()
++ malloc()
++ qsort()
++ rand()
+% rand_r() ; thread safe in the default
++ realloc()
+- setenv() ;the 'env' should combined with non-volatile devices
++ srand()
++ strtod()
++ strtof()
++ strtol()
++ strtold()
++ strtoll()
++ strtoul()
++ strtoull()
+- unsetenv() ;the 'env' should combined with non-volatile devices
+
+<string.h>
++ memchr()
++ memcmp()
++ memcpy()
++ memmove()
++ memset()
++ strcat()
++ strchr()
++ strcmp()
++ strcoll()
++ strcpy()
++ strcspn()
++ strerror()
+% strerror_r() ; thread safe in the default
++ strlen()
++ strncat()
++ strncmp()
++ strncpy()
++ strpbrk()
++ strrchr()
++ strspn()
++ strstr()
++ strtok()
+% strtok_r() ; thread safe in the default
++ strxfrm()
+
+<sys/mman.h>
+- mlockall()
++ mmap()
+- munlock()
++ munmap()
+- shm_open()
+- shm_unlink()
+
+<sys/utsname.h>
++ uname()
+
+<time.h> -> Suggesting to use <sys/time.h> instead of <time.h> to be compatible with three compilation platforms of IAR Keil GCC at the same time.
++ asctime()
++ asctime_r()
++ clock_getres()
++ clock_gettime()
++ clock_nanosleep()
++ clock_settime()
++ ctime()
++ ctime_r()
++ difftime()
++ gmtime()
++ gmtime_r()
++ localtime()
++ localtime_r()
++ mktime()
++ nanosleep()
++ strftime()
++ time()
++ timer_create()
++ timer_delete()
++ timer_getoverrun()
++ timer_gettime()
++ timer_settime()
+- tzname ; you should better use 'tz_xxx' in the rt-thread.
+- tzset() ; you should better use 'tz_xxx' in the rt-thread.
+
+<unistd.h>
++ alarm()
++ close()
++ environ
+% fdatasync() ;smaller ranther than <fsync>, in the rt-thread, it is universal
++ fsync()
++ pause()
++ read()
++ sysconf()
++ write()
+- confstr()
+
+
diff --git a/components/libc/posix/Kconfig b/components/libc/posix/Kconfig
new file mode 100644
index 0000000000..5c766d9509
--- /dev/null
+++ b/components/libc/posix/Kconfig
@@ -0,0 +1,80 @@
+menu "POSIX (Portable Operating System Interface) layer"
+
+config RT_USING_POSIX_FS
+ bool "Enable POSIX file system and I/O"
+ select RT_USING_DFS
+ select DFS_USING_POSIX
+ default n
+
+if RT_USING_POSIX_FS
+ config RT_USING_POSIX_DEVIO
+ bool "Enable devices as file descriptors"
+ select RT_USING_DFS_DEVFS
+ default n
+
+ config RT_USING_POSIX_STDIO
+ bool "Enable standard I/O devices, e.g. STDOUT_FILENO"
+ select RT_USING_POSIX_DEVIO
+ default n
+
+ config RT_USING_POSIX_POLL
+ bool "Enable I/O Multiplexing poll() <poll.h>"
+ default n
+
+ config RT_USING_POSIX_SELECT
+ bool "Enable I/O Multiplexing select() <sys/select.h>"
+ select RT_USING_POSIX_POLL
+ default n
+
+ config RT_USING_POSIX_TERMIOS
+ bool "Enable Terminal I/O <termios.h>"
+ select RT_USING_POSIX_STDIO
+ default n
+
+ config RT_USING_POSIX_AIO
+ bool "Enable Asynchronous I/O <aio.h>"
+ default n
+
+ config RT_USING_POSIX_MMAN
+ bool "Enable Memory-Mapped I/O <sys/mman.h>"
+ default n
+endif
+
+config RT_USING_POSIX_DELAY
+ bool "Enable delay APIs, sleep()/usleep()/msleep() etc"
+ default n
+
+config RT_USING_POSIX_CLOCK
+ bool "Enable clock/time functions, clock_gettime()/clock_settime()/clock_getres() etc"
+ select RT_USING_POSIX_DELAY
+ default n
+
+config RT_USING_POSIX_TIMER
+ select RT_USING_TIMER_SOFT
+ bool "Enable posix time functions, timer_create()/timer_gettime()/timer_settime() etc"
+ default n
+
+config RT_USING_PTHREADS
+ bool "Enable pthreads APIs"
+ select RT_USING_POSIX_CLOCK
+ default n
+
+if RT_USING_PTHREADS
+ config PTHREAD_NUM_MAX
+ int "Maximum number of pthreads"
+ default 8
+endif
+
+config RT_USING_MODULE
+ bool "Enable dynamic module with dlopen/dlsym/dlclose feature"
+ default n
+
+if RT_USING_MODULE
+ config RT_USING_CUSTOM_DLMODULE
+ bool "Enable load dynamic module by custom"
+ default n
+endif
+
+source "$RTT_DIR/components/libc/posix/ipc/Kconfig"
+
+endmenu
diff --git a/components/libc/posix/SConscript b/components/libc/posix/SConscript
new file mode 100644
index 0000000000..4c815c49b8
--- /dev/null
+++ b/components/libc/posix/SConscript
@@ -0,0 +1,15 @@
+# RT-Thread building script for bridge
+
+import os
+from building import *
+
+cwd = GetCurrentDir()
+objs = []
+list = os.listdir(cwd)
+
+for d in list:
+ path = os.path.join(cwd, d)
+ if os.path.isfile(os.path.join(path, 'SConscript')):
+ objs = objs + SConscript(os.path.join(d, 'SConscript'))
+
+Return('objs')
diff --git a/components/libc/time/SConscript b/components/libc/posix/delay/SConscript
index f7e6f7e8e9..f587f2dd64 100644
--- a/components/libc/time/SConscript
+++ b/components/libc/posix/delay/SConscript
@@ -3,10 +3,9 @@
from building import *
cwd = GetCurrentDir()
-src = Glob('*.c') + Glob('*.cpp')
+src = Glob('*.c')
CPPPATH = [cwd]
-group = DefineGroup('libc', src,
- depend = ['RT_USING_PTHREADS'], CPPPATH = CPPPATH)
+group = DefineGroup('POSIX', src, depend = ['RT_USING_POSIX_DELAY'], CPPPATH = CPPPATH)
Return('group')
diff --git a/components/libc/posix/delay/delay.c b/components/libc/posix/delay/delay.c
new file mode 100644
index 0000000000..753ca48526
--- /dev/null
+++ b/components/libc/posix/delay/delay.c
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-05-07 Meco Man first Version
+ */
+
+#include <sys/types.h>
+#include <rtthread.h>
+#include <rthw.h>
+#define DBG_TAG "POSIX.delay"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
+RT_WEAK void rt_hw_us_delay(rt_uint32_t us)
+{
+ (void) us;
+ LOG_W("Please consider implementing rt_hw_us_delay() in another file.");
+}
+
+void msleep(unsigned int msecs)
+{
+ rt_thread_mdelay(msecs);
+}
+RTM_EXPORT(msleep);
+
+void ssleep(unsigned int seconds)
+{
+ msleep(seconds * 1000);
+}
+RTM_EXPORT(ssleep);
+
+void mdelay(unsigned long msecs)
+{
+ rt_hw_us_delay(msecs * 1000);
+}
+RTM_EXPORT(mdelay);
+
+void udelay(unsigned long usecs)
+{
+ rt_hw_us_delay(usecs);
+}
+RTM_EXPORT(udelay);
+
+void ndelay(unsigned long nsecs)
+{
+ rt_hw_us_delay(1);
+}
+RTM_EXPORT(ndelay);
+
+unsigned int sleep(unsigned int seconds)
+{
+ if (rt_thread_self() != RT_NULL)
+ {
+ ssleep(seconds);
+ }
+ else /* scheduler has not run yet */
+ {
+ while(seconds > 0)
+ {
+ udelay(1000000u);
+ seconds --;
+ }
+ }
+
+ return 0;
+}
+RTM_EXPORT(sleep);
+
+int usleep(useconds_t usec)
+{
+ if (rt_thread_self() != RT_NULL)
+ {
+ msleep(usec / 1000u);
+ }
+ else /* scheduler has not run yet */
+ {
+ udelay(usec / 1000u);
+ }
+ udelay(usec % 1000u);
+
+ return 0;
+}
+RTM_EXPORT(usleep);
diff --git a/components/libc/posix/delay/delay.h b/components/libc/posix/delay/delay.h
new file mode 100644
index 0000000000..eb0332e0cd
--- /dev/null
+++ b/components/libc/posix/delay/delay.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-05-07 Meco Man first Version
+ */
+
+#ifndef __DELAY_H__
+#define __DELAY_H__
+
+unsigned int sleep(unsigned int seconds);
+void msleep(unsigned int msecs);
+void ssleep(unsigned int seconds);
+void mdelay(unsigned long msecs);
+void udelay(unsigned long usecs);
+void ndelay(unsigned long nsecs);
+
+#endif
diff --git a/components/libc/posix/io/README.md b/components/libc/posix/io/README.md
new file mode 100644
index 0000000000..54f5c0a02d
--- /dev/null
+++ b/components/libc/posix/io/README.md
@@ -0,0 +1,10 @@
+This folder contains:
+
+| sub-folders | description |
+| ----------- | ------------------------- |
+| aio | Asynchronous I/O |
+| mman | Memory-Mapped I/O |
+| poll | Nonblocking I/O |
+| stdio | Standard Input/Output I/O |
+| termios | Terminal I/O |
+
diff --git a/components/libc/posix/io/SConscript b/components/libc/posix/io/SConscript
new file mode 100644
index 0000000000..e016836a9d
--- /dev/null
+++ b/components/libc/posix/io/SConscript
@@ -0,0 +1,15 @@
+# RT-Thread building script for component
+
+import os
+from building import *
+
+cwd = GetCurrentDir()
+group = []
+
+list = os.listdir(cwd)
+for d in list:
+ path = os.path.join(cwd, d)
+ if os.path.isfile(os.path.join(path, 'SConscript')):
+ group = group + SConscript(os.path.join(d, 'SConscript'))
+
+Return('group')
diff --git a/components/libc/posix/io/aio/SConscript b/components/libc/posix/io/aio/SConscript
new file mode 100644
index 0000000000..6d4014311c
--- /dev/null
+++ b/components/libc/posix/io/aio/SConscript
@@ -0,0 +1,11 @@
+# RT-Thread building script for component
+
+from building import *
+
+cwd = GetCurrentDir()
+src = ['aio.c']
+CPPPATH = [cwd]
+
+group = DefineGroup('POSIX', src, depend = ['RT_USING_POSIX_AIO'], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/components/libc/aio/posix_aio.c b/components/libc/posix/io/aio/aio.c
index 3eb7634495..e12a7047c8 100644
--- a/components/libc/aio/posix_aio.c
+++ b/components/libc/posix/io/aio/aio.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -8,39 +8,36 @@
* 2017/12/30 Bernard The first version.
*/
-#include <stdint.h>
-#include <stdio.h>
-
-#include <rthw.h>
-#include <rtdevice.h>
#include <rtthread.h>
-
-#include <dfs_posix.h>
-
-#include "posix_aio.h"
+#include <rthw.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/errno.h>
+#include "aio.h"
struct rt_workqueue* aio_queue = NULL;
/**
- * The aio_cancel() function shall attempt to cancel one or more asynchronous I/O
- * requests currently outstanding against file descriptor fildes. The aiocbp
- * argument points to the asynchronous I/O control block for a particular request
- * to be canceled. If aiocbp is NULL, then all outstanding cancelable asynchronous
+ * The aio_cancel() function shall attempt to cancel one or more asynchronous I/O
+ * requests currently outstanding against file descriptor fildes. The aiocbp
+ * argument points to the asynchronous I/O control block for a particular request
+ * to be canceled. If aiocbp is NULL, then all outstanding cancelable asynchronous
* I/O requests against fildes shall be canceled.
- *
- * Normal asynchronous notification shall occur for asynchronous I/O operations
- * that are successfully canceled. If there are requests that cannot be canceled,
- * then the normal asynchronous completion process shall take place for those
+ *
+ * Normal asynchronous notification shall occur for asynchronous I/O operations
+ * that are successfully canceled. If there are requests that cannot be canceled,
+ * then the normal asynchronous completion process shall take place for those
* requests when they are completed.
- *
- * For requested operations that are successfully canceled, the associated error
- * status shall be set to [ECANCELED] and the return status shall be -1. For
- * requested operations that are not successfully canceled, the aiocbp shall not
+ *
+ * For requested operations that are successfully canceled, the associated error
+ * status shall be set to [ECANCELED] and the return status shall be -1. For
+ * requested operations that are not successfully canceled, the aiocbp shall not
* be modified by aio_cancel().
- *
- * If aiocbp is not NULL, then if fildes does not have the same value as the file
+ *
+ * If aiocbp is not NULL, then if fildes does not have the same value as the file
* descriptor with which the asynchronous operation was initiated, unspecified results occur.
- *
+ *
* Which operations are cancelable is implementation-defined.
*/
int aio_cancel(int fd, struct aiocb *cb)
@@ -61,9 +58,9 @@ int aio_cancel(int fd, struct aiocb *cb)
}
/**
- * The aio_error() function shall return the error status associated with the
- * aiocb structure referenced by the aiocbp argument. The error status for an
- * asynchronous I/O operation is the errno value that would be set by the corresponding
+ * The aio_error() function shall return the error status associated with the
+ * aiocb structure referenced by the aiocbp argument. The error status for an
+ * asynchronous I/O operation is the errno value that would be set by the corresponding
* read(), write(),
*/
int aio_error (const struct aiocb *cb)
@@ -77,44 +74,44 @@ int aio_error (const struct aiocb *cb)
}
/**
- * The aio_fsync() function shall asynchronously perform a file synchronization
- * operation, as specified by the op argument, for I/O operations associated with
- * the file indicated by the file descriptor aio_fildes member of the aiocb
- * structure referenced by the aiocbp argument and queued at the time of the
- * call to aio_fsync(). The function call shall return when the synchronization
- * request has been initiated or queued to the file or device (even when the data
+ * The aio_fsync() function shall asynchronously perform a file synchronization
+ * operation, as specified by the op argument, for I/O operations associated with
+ * the file indicated by the file descriptor aio_fildes member of the aiocb
+ * structure referenced by the aiocbp argument and queued at the time of the
+ * call to aio_fsync(). The function call shall return when the synchronization
+ * request has been initiated or queued to the file or device (even when the data
* cannot be synchronized immediately).
- *
- * option: If op is O_DSYNC, all currently queued I/O operations shall be completed
- * as if by a call to fdatasync(); that is, as defined for synchronized I/O data
+ *
+ * option: If op is O_DSYNC, all currently queued I/O operations shall be completed
+ * as if by a call to fdatasync(); that is, as defined for synchronized I/O data
* integrity completion.
- *
- * option: If op is O_SYNC, all currently queued I/O operations shall be completed
- * as if by a call to fsync(); that is, as defined for synchronized I/O file integrity
- * completion. If the aio_fsync() function fails, or if the operation queued by
- * aio_fsync() fails, then outstanding I/O operations are not guaranteed to have
+ *
+ * option: If op is O_SYNC, all currently queued I/O operations shall be completed
+ * as if by a call to fsync(); that is, as defined for synchronized I/O file integrity
+ * completion. If the aio_fsync() function fails, or if the operation queued by
+ * aio_fsync() fails, then outstanding I/O operations are not guaranteed to have
* been completed.
- *
- * If aio_fsync() succeeds, then it is only the I/O that was queued at the time
- * of the call to aio_fsync() that is guaranteed to be forced to the relevant
+ *
+ * If aio_fsync() succeeds, then it is only the I/O that was queued at the time
+ * of the call to aio_fsync() that is guaranteed to be forced to the relevant
* completion state. The completion of subsequent I/O on the file descriptor is
* not guaranteed to be completed in a synchronized fashion.
- *
- * The aiocbp argument refers to an asynchronous I/O control block. The aiocbp
- * value may be used as an argument to aio_error() and aio_return() in order to
- * determine the error status and return status, respectively, of the asynchronous
- * operation while it is proceeding. When the request is queued, the error status
- * for the operation is [EINPROGRESS]. When all data has been successfully transferred,
- * the error status shall be reset to reflect the success or failure of the operation.
- * If the operation does not complete successfully, the error status for the
- * operation shall be set to indicate the error. The aio_sigevent member determines
- * the asynchronous notification to occur as specified in Signal Generation and
- * Delivery when all operations have achieved synchronized I/O completion. All
- * other members of the structure referenced by aiocbp are ignored. If the control
- * block referenced by aiocbp becomes an illegal address prior to asynchronous
+ *
+ * The aiocbp argument refers to an asynchronous I/O control block. The aiocbp
+ * value may be used as an argument to aio_error() and aio_return() in order to
+ * determine the error status and return status, respectively, of the asynchronous
+ * operation while it is proceeding. When the request is queued, the error status
+ * for the operation is [EINPROGRESS]. When all data has been successfully transferred,
+ * the error status shall be reset to reflect the success or failure of the operation.
+ * If the operation does not complete successfully, the error status for the
+ * operation shall be set to indicate the error. The aio_sigevent member determines
+ * the asynchronous notification to occur as specified in Signal Generation and
+ * Delivery when all operations have achieved synchronized I/O completion. All
+ * other members of the structure referenced by aiocbp are ignored. If the control
+ * block referenced by aiocbp becomes an illegal address prior to asynchronous
* I/O completion, then the behavior is undefined.
- *
- * If the aio_fsync() function fails or aiocbp indicates an error condition,
+ *
+ * If the aio_fsync() function fails or aiocbp indicates an error condition,
* data is not guaranteed to have been successfully transferred.
*/
static void aio_fync_work(struct rt_work* work, void* work_data)
@@ -169,7 +166,7 @@ static void aio_read_work(struct rt_work* work, void* work_data)
level = rt_hw_interrupt_disable();
if (len <= 0)
cb->aio_result = errno;
- else
+ else
cb->aio_result = len;
rt_hw_interrupt_enable(level);
@@ -177,51 +174,51 @@ static void aio_read_work(struct rt_work* work, void* work_data)
}
/**
- * The aio_read() function shall read aiocbp->aio_nbytes from the file associated
- * with aiocbp->aio_fildes into the buffer pointed to by aiocbp->aio_buf. The
- * function call shall return when the read request has been initiated or queued
+ * The aio_read() function shall read aiocbp->aio_nbytes from the file associated
+ * with aiocbp->aio_fildes into the buffer pointed to by aiocbp->aio_buf. The
+ * function call shall return when the read request has been initiated or queued
* to the file or device (even when the data cannot be delivered immediately).
- *
- * If prioritized I/O is supported for this file, then the asynchronous operation
- * shall be submitted at a priority equal to a base scheduling priority minus
- * aiocbp->aio_reqprio. If Thread Execution Scheduling is not supported, then
+ *
+ * If prioritized I/O is supported for this file, then the asynchronous operation
+ * shall be submitted at a priority equal to a base scheduling priority minus
+ * aiocbp->aio_reqprio. If Thread Execution Scheduling is not supported, then
* the base scheduling priority is that of the calling process;
- *
- * otherwise, the base scheduling priority is that of the calling thread.
- *
- * The aiocbp value may be used as an argument to aio_error() and aio_return()
- * in order to determine the error status and return status, respectively, of
- * the asynchronous operation while it is proceeding. If an error condition is
- * encountered during queuing, the function call shall return without having
- * initiated or queued the request. The requested operation takes place at the
- * absolute position in the file as given by aio_offset, as if lseek() were called
- * immediately prior to the operation with an offset equal to aio_offset and a
- * whence equal to SEEK_SET. After a successful call to enqueue an asynchronous
+ *
+ * otherwise, the base scheduling priority is that of the calling thread.
+ *
+ * The aiocbp value may be used as an argument to aio_error() and aio_return()
+ * in order to determine the error status and return status, respectively, of
+ * the asynchronous operation while it is proceeding. If an error condition is
+ * encountered during queuing, the function call shall return without having
+ * initiated or queued the request. The requested operation takes place at the
+ * absolute position in the file as given by aio_offset, as if lseek() were called
+ * immediately prior to the operation with an offset equal to aio_offset and a
+ * whence equal to SEEK_SET. After a successful call to enqueue an asynchronous
* I/O operation, the value of the file offset for the file is unspecified.
*
- * The aio_sigevent member specifies the notification which occurs when the
+ * The aio_sigevent member specifies the notification which occurs when the
* request is completed.
*
* The aiocbp->aio_lio_opcode field shall be ignored by aio_read().
- *
- * The aiocbp argument points to an aiocb structure. If the buffer pointed to by
- * aiocbp->aio_buf or the control block pointed to by aiocbp becomes an illegal
+ *
+ * The aiocbp argument points to an aiocb structure. If the buffer pointed to by
+ * aiocbp->aio_buf or the control block pointed to by aiocbp becomes an illegal
* address prior to asynchronous I/O completion, then the behavior is undefined.
- *
- * Simultaneous asynchronous operations using the same aiocbp produce undefined
+ *
+ * Simultaneous asynchronous operations using the same aiocbp produce undefined
* results.
- *
+ *
* If synchronized I/O is enabled on the file associated with aiocbp->aio_fildes,
- * the behavior of this function shall be according to the definitions of synchronized
- * I/O data integrity completion and synchronized I/O file integrity completion.
- *
- * For any system action that changes the process memory space while an asynchronous
- * I/O is outstanding to the address range being changed, the result of that action
+ * the behavior of this function shall be according to the definitions of synchronized
+ * I/O data integrity completion and synchronized I/O file integrity completion.
+ *
+ * For any system action that changes the process memory space while an asynchronous
+ * I/O is outstanding to the address range being changed, the result of that action
* is undefined.
- *
- * For regular files, no data transfer shall occur past the offset maximum
+ *
+ * For regular files, no data transfer shall occur past the offset maximum
* established in the open file description associated with aiocbp->aio_fildes.
- *
+ *
*/
int aio_read(struct aiocb *cb)
{
@@ -242,16 +239,16 @@ int aio_read(struct aiocb *cb)
}
/**
- * The aio_return() function shall return the return status associated with the
- * aiocb structure referenced by the aiocbp argument. The return status for an
- * asynchronous I/O operation is the value that would be returned by the corresponding
- * read(), write(), or fsync() function call. If the error status for the operation
- * is equal to [EINPROGRESS], then the return status for the operation is undefined.
- * The aio_return() function may be called exactly once to retrieve the return
- * status of a given asynchronous operation; thereafter, if the same aiocb structure
- * is used in a call to aio_return() or aio_error(), an error may be returned.
- * When the aiocb structure referred to by aiocbp is used to submit another asynchronous
- * operation, then aio_return() may be successfully used to retrieve the return
+ * The aio_return() function shall return the return status associated with the
+ * aiocb structure referenced by the aiocbp argument. The return status for an
+ * asynchronous I/O operation is the value that would be returned by the corresponding
+ * read(), write(), or fsync() function call. If the error status for the operation
+ * is equal to [EINPROGRESS], then the return status for the operation is undefined.
+ * The aio_return() function may be called exactly once to retrieve the return
+ * status of a given asynchronous operation; thereafter, if the same aiocb structure
+ * is used in a call to aio_return() or aio_error(), an error may be returned.
+ * When the aiocb structure referred to by aiocbp is used to submit another asynchronous
+ * operation, then aio_return() may be successfully used to retrieve the return
* status of that operation.
*/
ssize_t aio_return(struct aiocb *cb)
@@ -268,23 +265,23 @@ ssize_t aio_return(struct aiocb *cb)
}
/**
- * The aio_suspend() function shall suspend the calling thread until at least
- * one of the asynchronous I/O operations referenced by the list argument has
- * completed, until a signal interrupts the function, or, if timeout is not NULL,
- * until the time interval specified by timeout has passed. If any of the aiocb
- * structures in the list correspond to completed asynchronous I/O operations
- * (that is, the error status for the operation is not equal to [EINPROGRESS])
- * at the time of the call, the function shall return without suspending the
- * calling thread. The list argument is an array of pointers to asynchronous I/O
- * control blocks. The nent argument indicates the number of elements in the
- * array. Each aiocb structure pointed to has been used in initiating an asynchronous
- * I/O request via aio_read(), aio_write(), or lio_listio(). This array may
- * contain null pointers, which are ignored. If this array contains pointers
- * that refer to aiocb structures that have not been used in submitting asynchronous
+ * The aio_suspend() function shall suspend the calling thread until at least
+ * one of the asynchronous I/O operations referenced by the list argument has
+ * completed, until a signal interrupts the function, or, if timeout is not NULL,
+ * until the time interval specified by timeout has passed. If any of the aiocb
+ * structures in the list correspond to completed asynchronous I/O operations
+ * (that is, the error status for the operation is not equal to [EINPROGRESS])
+ * at the time of the call, the function shall return without suspending the
+ * calling thread. The list argument is an array of pointers to asynchronous I/O
+ * control blocks. The nent argument indicates the number of elements in the
+ * array. Each aiocb structure pointed to has been used in initiating an asynchronous
+ * I/O request via aio_read(), aio_write(), or lio_listio(). This array may
+ * contain null pointers, which are ignored. If this array contains pointers
+ * that refer to aiocb structures that have not been used in submitting asynchronous
* I/O, the effect is undefined.
- *
- * If the time interval indicated in the timespec structure pointed to by timeout
- * passes before any of the I/O operations referenced by list are completed, then
+ *
+ * If the time interval indicated in the timespec structure pointed to by timeout
+ * passes before any of the I/O operations referenced by list are completed, then
* aio_suspend() shall return with an error.
*/
int aio_suspend(const struct aiocb *const list[], int nent,
@@ -315,7 +312,7 @@ static void aio_write_work(struct rt_work* work, void* work_data)
level = rt_hw_interrupt_disable();
if (len <= 0)
cb->aio_result = errno;
- else
+ else
cb->aio_result = len;
rt_hw_interrupt_enable(level);
@@ -323,42 +320,42 @@ static void aio_write_work(struct rt_work* work, void* work_data)
}
/**
- * The aio_write() function shall write aiocbp->aio_nbytes to the file associated
- * with aiocbp->aio_fildes from the buffer pointed to by aiocbp->aio_buf. The
- * function shall return when the write request has been initiated or, at a minimum,
+ * The aio_write() function shall write aiocbp->aio_nbytes to the file associated
+ * with aiocbp->aio_fildes from the buffer pointed to by aiocbp->aio_buf. The
+ * function shall return when the write request has been initiated or, at a minimum,
* queued to the file or device.
- *
- * The aiocbp argument may be used as an argument to aio_error() and aio_return()
- * in order to determine the error status and return status, respectively, of the
+ *
+ * The aiocbp argument may be used as an argument to aio_error() and aio_return()
+ * in order to determine the error status and return status, respectively, of the
* asynchronous operation while it is proceeding.
- *
- * The aiocbp argument points to an aiocb structure. If the buffer pointed to by
- * aiocbp->aio_buf or the control block pointed to by aiocbp becomes an illegal
+ *
+ * The aiocbp argument points to an aiocb structure. If the buffer pointed to by
+ * aiocbp->aio_buf or the control block pointed to by aiocbp becomes an illegal
* address prior to asynchronous I/O completion, then the behavior is undefined.
- *
- * If O_APPEND is not set for the file descriptor aio_fildes, then the requested
- * operation shall take place at the absolute position in the file as given by
- * aio_offset, as if lseek() were called immediately prior to the operation with
- * an offset equal to aio_offset and a whence equal to SEEK_SET. If O_APPEND is
- * set for the file descriptor, or if aio_fildes is associated with a device that
- * is incapable of seeking, write operations append to the file in the same order
- * as the calls were made, except under circumstances described in Asynchronous
- * I/O. After a successful call to enqueue an asynchronous I/O operation, the value
+ *
+ * If O_APPEND is not set for the file descriptor aio_fildes, then the requested
+ * operation shall take place at the absolute position in the file as given by
+ * aio_offset, as if lseek() were called immediately prior to the operation with
+ * an offset equal to aio_offset and a whence equal to SEEK_SET. If O_APPEND is
+ * set for the file descriptor, or if aio_fildes is associated with a device that
+ * is incapable of seeking, write operations append to the file in the same order
+ * as the calls were made, except under circumstances described in Asynchronous
+ * I/O. After a successful call to enqueue an asynchronous I/O operation, the value
* of the file offset for the file is unspecified.
- *
- * The aio_sigevent member specifies the notification which occurs when the request
+ *
+ * The aio_sigevent member specifies the notification which occurs when the request
* is completed.
- *
+ *
* The aiocbp->aio_lio_opcode field shall be ignored by aio_write().
- *
- * Simultaneous asynchronous operations using the same aiocbp produce undefined
+ *
+ * Simultaneous asynchronous operations using the same aiocbp produce undefined
* results.
- *
- * If synchronized I/O is enabled on the file associated with aiocbp->aio_fildes,
- * the behavior of this function shall be according to the definitions of synchronized
+ *
+ * If synchronized I/O is enabled on the file associated with aiocbp->aio_fildes,
+ * the behavior of this function shall be according to the definitions of synchronized
* I/O data integrity completion, and synchronized I/O file integrity completion.
- *
- * For regular files, no data transfer shall occur past the offset maximum established
+ *
+ * For regular files, no data transfer shall occur past the offset maximum established
* in the open file description associated with aiocbp->aio_fildes.
*/
int aio_write(struct aiocb *cb)
@@ -385,69 +382,69 @@ int aio_write(struct aiocb *cb)
}
/**
- * The lio_listio() function shall initiate a list of I/O requests with a single
+ * The lio_listio() function shall initiate a list of I/O requests with a single
* function call.
- *
- * The mode argument takes one of the values LIO_WAIT or LIO_NOWAIT declared in
- * <aio.h> and determines whether the function returns when the I/O operations
- * have been completed, or as soon as the operations have been queued. If the
- * mode argument is LIO_WAIT, the function shall wait until all I/O is complete
+ *
+ * The mode argument takes one of the values LIO_WAIT or LIO_NOWAIT declared in
+ * <aio.h> and determines whether the function returns when the I/O operations
+ * have been completed, or as soon as the operations have been queued. If the
+ * mode argument is LIO_WAIT, the function shall wait until all I/O is complete
* and the sig argument shall be ignored.
- *
- * If the mode argument is LIO_NOWAIT, the function shall return immediately, and
- * asynchronous notification shall occur, according to the sig argument, when all
- * the I/O operations complete. If sig is NULL, then no asynchronous notification
- * shall occur. If sig is not NULL, asynchronous notification occurs as specified
+ *
+ * If the mode argument is LIO_NOWAIT, the function shall return immediately, and
+ * asynchronous notification shall occur, according to the sig argument, when all
+ * the I/O operations complete. If sig is NULL, then no asynchronous notification
+ * shall occur. If sig is not NULL, asynchronous notification occurs as specified
* in Signal Generation and Delivery when all the requests in list have completed.
- *
+ *
* The I/O requests enumerated by list are submitted in an unspecified order.
- *
- * The list argument is an array of pointers to aiocb structures. The array contains
+ *
+ * The list argument is an array of pointers to aiocb structures. The array contains
* nent elements. The array may contain NULL elements, which shall be ignored.
- *
- * If the buffer pointed to by list or the aiocb structures pointed to by the
- * elements of the array list become illegal addresses before all asynchronous I/O
- * completed and, if necessary, the notification is sent, then the behavior is
- * undefined. If the buffers pointed to by the aio_buf member of the aiocb structure
- * pointed to by the elements of the array list become illegal addresses prior to
- * the asynchronous I/O associated with that aiocb structure being completed, the
+ *
+ * If the buffer pointed to by list or the aiocb structures pointed to by the
+ * elements of the array list become illegal addresses before all asynchronous I/O
+ * completed and, if necessary, the notification is sent, then the behavior is
+ * undefined. If the buffers pointed to by the aio_buf member of the aiocb structure
+ * pointed to by the elements of the array list become illegal addresses prior to
+ * the asynchronous I/O associated with that aiocb structure being completed, the
* behavior is undefined.
- *
- * The aio_lio_opcode field of each aiocb structure specifies the operation to be
- * performed. The supported operations are LIO_READ, LIO_WRITE, and LIO_NOP; these
- * symbols are defined in <aio.h>. The LIO_NOP operation causes the list entry to
- * be ignored. If the aio_lio_opcode element is equal to LIO_READ, then an I/O operation
- * is submitted as if by a call to aio_read() with the aiocbp equal to the address
- * of the aiocb structure. If the aio_lio_opcode element is equal to LIO_WRITE, then
- * an I/O operation is submitted as if by a call to aio_write() with the aiocbp equal
+ *
+ * The aio_lio_opcode field of each aiocb structure specifies the operation to be
+ * performed. The supported operations are LIO_READ, LIO_WRITE, and LIO_NOP; these
+ * symbols are defined in <aio.h>. The LIO_NOP operation causes the list entry to
+ * be ignored. If the aio_lio_opcode element is equal to LIO_READ, then an I/O operation
+ * is submitted as if by a call to aio_read() with the aiocbp equal to the address
+ * of the aiocb structure. If the aio_lio_opcode element is equal to LIO_WRITE, then
+ * an I/O operation is submitted as if by a call to aio_write() with the aiocbp equal
* to the address of the aiocb structure.
- *
- * The aio_fildes member specifies the file descriptor on which the operation is to
+ *
+ * The aio_fildes member specifies the file descriptor on which the operation is to
* be performed.
- *
- * The aio_buf member specifies the address of the buffer to or from which the data
+ *
+ * The aio_buf member specifies the address of the buffer to or from which the data
* is transferred.
- *
+ *
* The aio_nbytes member specifies the number of bytes of data to be transferred.
- *
- * The members of the aiocb structure further describe the I/O operation to be
- * performed, in a manner identical to that of the corresponding aiocb structure
+ *
+ * The members of the aiocb structure further describe the I/O operation to be
+ * performed, in a manner identical to that of the corresponding aiocb structure
* when used by the aio_read() and aio_write() functions.
- *
- * The nent argument specifies how many elements are members of the list; that is,
+ *
+ * The nent argument specifies how many elements are members of the list; that is,
* the length of the array.
- *
- * The behavior of this function is altered according to the definitions of synchronized
- * I/O data integrity completion and synchronized I/O file integrity completion if
+ *
+ * The behavior of this function is altered according to the definitions of synchronized
+ * I/O data integrity completion and synchronized I/O file integrity completion if
* synchronized I/O is enabled on the file associated with aio_fildes.
- *
- * For regular files, no data transfer shall occur past the offset maximum established
+ *
+ * For regular files, no data transfer shall occur past the offset maximum established
* in the open file description associated with aiocbp->aio_fildes.
- *
- * If sig->sigev_notify is SIGEV_THREAD and sig->sigev_notify_attributes is a
- * non-null pointer and the block pointed to by this pointer becomes an illegal
- * address prior to all asynchronous I/O being completed, then the behavior is
- * undefined.
+ *
+ * If sig->sigev_notify is SIGEV_THREAD and sig->sigev_notify_attributes is a
+ * non-null pointer and the block pointed to by this pointer becomes an illegal
+ * address prior to all asynchronous I/O being completed, then the behavior is
+ * undefined.
*/
int lio_listio(int mode, struct aiocb * const list[], int nent,
struct sigevent *sig)
diff --git a/components/libc/aio/posix_aio.h b/components/libc/posix/io/aio/aio.h
index f20ed48cb3..35a5c194db 100644
--- a/components/libc/aio/posix_aio.h
+++ b/components/libc/posix/io/aio/aio.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -8,8 +8,12 @@
* 2017/12/30 Bernard The first version.
*/
-#ifndef POSIX_AIO_H__
-#define POSIX_AIO_H__
+#ifndef __AIO_H__
+#define __AIO_H__
+
+#include <stdio.h>
+#include <sys/signal.h>
+#include <rtdevice.h>
struct aiocb
{
diff --git a/components/libc/posix/io/mman/SConscript b/components/libc/posix/io/mman/SConscript
new file mode 100644
index 0000000000..7dd096c998
--- /dev/null
+++ b/components/libc/posix/io/mman/SConscript
@@ -0,0 +1,11 @@
+# RT-Thread building script for component
+
+from building import *
+
+cwd = GetCurrentDir()
+src = ['mman.c']
+CPPPATH = [cwd]
+
+group = DefineGroup('POSIX', src, depend = ['RT_USING_POSIX_MMAN'], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/components/libc/mmap/posix_mmap.c b/components/libc/posix/io/mman/mman.c
index a16ace8306..d484b3ed7b 100644
--- a/components/libc/mmap/posix_mmap.c
+++ b/components/libc/posix/io/mman/mman.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -12,9 +12,11 @@
#include <stdio.h>
#include <rtthread.h>
-#include <dfs_posix.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/statfs.h>
-#include <sys/mman.h>
+#include "sys/mman.h"
void *mmap(void *addr, size_t length, int prot, int flags,
int fd, off_t offset)
diff --git a/components/libc/compilers/dlib/sys/mman.h b/components/libc/posix/io/mman/sys/mman.h
index 8c61b32b7c..a730f33b6b 100644
--- a/components/libc/compilers/dlib/sys/mman.h
+++ b/components/libc/posix/io/mman/sys/mman.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -8,13 +8,15 @@
* 2017/11/30 Bernard The first version.
*/
-#ifndef _SYS_MMAN_H
-#define _SYS_MMAN_H
+#ifndef __SYS_MMAN_H__
+#define __SYS_MMAN_H__
#ifdef __cplusplus
extern "C" {
#endif
+#include <sys/types.h>
+
#define MAP_FAILED ((void *) -1)
#define MAP_SHARED 0x01
diff --git a/components/libc/posix/io/poll/SConscript b/components/libc/posix/io/poll/SConscript
new file mode 100644
index 0000000000..7e7c0f55f7
--- /dev/null
+++ b/components/libc/posix/io/poll/SConscript
@@ -0,0 +1,17 @@
+# RT-Thread building script for component
+
+from building import *
+
+cwd = GetCurrentDir()
+src = []
+CPPPATH = [cwd]
+
+if GetDepend('RT_USING_POSIX_POLL'):
+ src += ['poll.c']
+
+if GetDepend('RT_USING_POSIX_SELECT'):
+ src += ['select.c']
+
+group = DefineGroup('POSIX', src, depend = [''], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/components/libc/posix/io/poll/poll.c b/components/libc/posix/io/poll/poll.c
new file mode 100644
index 0000000000..3c5940b8d3
--- /dev/null
+++ b/components/libc/posix/io/poll/poll.c
@@ -0,0 +1,227 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2016-12-28 Bernard first version
+ * 2018-03-09 Bernard Add protection for pt->triggered.
+ */
+
+#include <stdint.h>
+#include <rthw.h>
+#include <rtthread.h>
+#include <dfs_file.h>
+#include "poll.h"
+
+struct rt_poll_node;
+
+struct rt_poll_table
+{
+ rt_pollreq_t req;
+ rt_uint32_t triggered; /* the waited thread whether triggered */
+ rt_thread_t polling_thread;
+ struct rt_poll_node *nodes;
+};
+
+struct rt_poll_node
+{
+ struct rt_wqueue_node wqn;
+ struct rt_poll_table *pt;
+ struct rt_poll_node *next;
+};
+
+static int __wqueue_pollwake(struct rt_wqueue_node *wait, void *key)
+{
+ struct rt_poll_node *pn;
+
+ if (key && !((rt_ubase_t)key & wait->key))
+ return -1;
+
+ pn = rt_container_of(wait, struct rt_poll_node, wqn);
+ pn->pt->triggered = 1;
+
+ return __wqueue_default_wake(wait, key);
+}
+
+static void _poll_add(rt_wqueue_t *wq, rt_pollreq_t *req)
+{
+ struct rt_poll_table *pt;
+ struct rt_poll_node *node;
+
+ node = (struct rt_poll_node *)rt_malloc(sizeof(struct rt_poll_node));
+ if (node == RT_NULL)
+ return;
+
+ pt = rt_container_of(req, struct rt_poll_table, req);
+
+ node->wqn.key = req->_key;
+ rt_list_init(&(node->wqn.list));
+ node->wqn.polling_thread = pt->polling_thread;
+ node->wqn.wakeup = __wqueue_pollwake;
+ node->next = pt->nodes;
+ node->pt = pt;
+ pt->nodes = node;
+ rt_wqueue_add(wq, &node->wqn);
+}
+
+static void poll_table_init(struct rt_poll_table *pt)
+{
+ pt->req._proc = _poll_add;
+ pt->triggered = 0;
+ pt->nodes = RT_NULL;
+ pt->polling_thread = rt_thread_self();
+}
+
+static int poll_wait_timeout(struct rt_poll_table *pt, int msec)
+{
+ rt_int32_t timeout;
+ int ret = 0;
+ struct rt_thread *thread;
+ rt_base_t level;
+
+ thread = pt->polling_thread;
+
+ timeout = rt_tick_from_millisecond(msec);
+
+ level = rt_hw_interrupt_disable();
+
+ if (timeout != 0 && !pt->triggered)
+ {
+ rt_thread_suspend(thread);
+ if (timeout > 0)
+ {
+ rt_timer_control(&(thread->thread_timer),
+ RT_TIMER_CTRL_SET_TIME,
+ &timeout);
+ rt_timer_start(&(thread->thread_timer));
+ }
+
+ rt_hw_interrupt_enable(level);
+
+ rt_schedule();
+
+ level = rt_hw_interrupt_disable();
+ }
+
+ ret = !pt->triggered;
+ rt_hw_interrupt_enable(level);
+
+ return ret;
+}
+
+static int do_pollfd(struct pollfd *pollfd, rt_pollreq_t *req)
+{
+ int mask = 0;
+ int fd;
+
+ fd = pollfd->fd;
+
+ if (fd >= 0)
+ {
+ struct dfs_fd *f = fd_get(fd);
+ mask = POLLNVAL;
+
+ if (f)
+ {
+ mask = POLLMASK_DEFAULT;
+ if (f->fops->poll)
+ {
+ req->_key = pollfd->events | POLLERR | POLLHUP;
+
+ mask = f->fops->poll(f, req);
+
+ /* dealwith the device return error -1*/
+ if (mask < 0)
+ {
+ fd_put(f);
+ pollfd->revents = 0;
+ return mask;
+ }
+ }
+ /* Mask out unneeded events. */
+ mask &= pollfd->events | POLLERR | POLLHUP;
+ fd_put(f);
+ }
+ }
+ pollfd->revents = mask;
+
+ return mask;
+}
+
+static int poll_do(struct pollfd *fds, nfds_t nfds, struct rt_poll_table *pt, int msec)
+{
+ int num;
+ int istimeout = 0;
+ int n;
+ struct pollfd *pf;
+ int ret = 0;
+
+ if (msec == 0)
+ {
+ pt->req._proc = RT_NULL;
+ istimeout = 1;
+ }
+
+ while (1)
+ {
+ pf = fds;
+ num = 0;
+
+ for (n = 0; n < nfds; n ++)
+ {
+ ret = do_pollfd(pf, &pt->req);
+ if(ret < 0)
+ {
+ /*dealwith the device return error -1 */
+ pt->req._proc = RT_NULL;
+ return ret;
+ }
+ else if(ret > 0)
+ {
+ num ++;
+ pt->req._proc = RT_NULL;
+ }
+ pf ++;
+ }
+
+ pt->req._proc = RT_NULL;
+
+ if (num || istimeout)
+ break;
+
+ if (poll_wait_timeout(pt, msec))
+ istimeout = 1;
+ }
+
+ return num;
+}
+
+static void poll_teardown(struct rt_poll_table *pt)
+{
+ struct rt_poll_node *node, *next;
+
+ next = pt->nodes;
+ while (next)
+ {
+ node = next;
+ rt_wqueue_remove(&node->wqn);
+ next = node->next;
+ rt_free(node);
+ }
+}
+
+int poll(struct pollfd *fds, nfds_t nfds, int timeout)
+{
+ int num;
+ struct rt_poll_table table;
+
+ poll_table_init(&table);
+
+ num = poll_do(fds, nfds, &table, timeout);
+
+ poll_teardown(&table);
+
+ return num;
+}
diff --git a/components/libc/posix/io/poll/poll.h b/components/libc/posix/io/poll/poll.h
new file mode 100644
index 0000000000..0fccd48b0d
--- /dev/null
+++ b/components/libc/posix/io/poll/poll.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-09-11 Meco Man First version
+ */
+
+#ifndef __POLL_H__
+#define __POLL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if !defined(POLLIN) && !defined(POLLOUT)
+#define POLLIN (0x01)
+#define POLLRDNORM (0x01)
+#define POLLRDBAND (0x01)
+#define POLLPRI (0x01)
+
+#define POLLOUT (0x02)
+#define POLLWRNORM (0x02)
+#define POLLWRBAND (0x02)
+
+#define POLLERR (0x04)
+#define POLLHUP (0x08)
+#define POLLNVAL (0x10)
+
+typedef unsigned int nfds_t;
+
+struct pollfd
+{
+ int fd;
+ short events;
+ short revents;
+};
+#endif /* !defined(POLLIN) && !defined(POLLOUT) */
+
+#define POLLMASK_DEFAULT (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
+
+int poll(struct pollfd *fds, nfds_t nfds, int timeout);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __POLL_H__ */
diff --git a/components/libc/posix/io/poll/select.c b/components/libc/posix/io/poll/select.c
new file mode 100644
index 0000000000..bac63258a5
--- /dev/null
+++ b/components/libc/posix/io/poll/select.c
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2016-12-28 Bernard first version
+ */
+
+#include <rtthread.h>
+#include <poll.h>
+#include <sys/select.h>
+
+static void fdszero(fd_set *set, int nfds)
+{
+ fd_mask *m;
+ int n;
+
+ /*
+ The 'sizeof(fd_set)' of the system space may differ from user space,
+ so the actual size of the 'fd_set' is determined here with the parameter 'nfds'
+ */
+ m = (fd_mask *)set;
+ for (n = 0; n < nfds; n += (sizeof(fd_mask) * 8))
+ {
+ rt_memset(m, 0, sizeof(fd_mask));
+ m ++;
+ }
+}
+
+int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
+{
+ int fd;
+ int npfds;
+ int msec;
+ int ndx;
+ int ret;
+ struct pollfd *pollset = RT_NULL;
+
+ /* How many pollfd structures do we need to allocate? */
+ for (fd = 0, npfds = 0; fd < nfds; fd++)
+ {
+ /* Check if any monitor operation is requested on this fd */
+ if ((readfds && FD_ISSET(fd, readfds)) ||
+ (writefds && FD_ISSET(fd, writefds)) ||
+ (exceptfds && FD_ISSET(fd, exceptfds)))
+ {
+ npfds++;
+ }
+ }
+
+ /* Allocate the descriptor list for poll() */
+ if (npfds > 0)
+ {
+ pollset = (struct pollfd *)rt_calloc(npfds, sizeof(struct pollfd));
+ if (!pollset)
+ {
+ return -1;
+ }
+ }
+
+ /* Initialize the descriptor list for poll() */
+ for (fd = 0, ndx = 0; fd < nfds; fd++)
+ {
+ int incr = 0;
+
+ /* The readfs set holds the set of FDs that the caller can be assured
+ * of reading from without blocking. Note that POLLHUP is included as
+ * a read-able condition. POLLHUP will be reported at the end-of-file
+ * or when a connection is lost. In either case, the read() can then
+ * be performed without blocking.
+ */
+
+ if (readfds && FD_ISSET(fd, readfds))
+ {
+ pollset[ndx].fd = fd;
+ pollset[ndx].events |= POLLIN;
+ incr = 1;
+ }
+
+ if (writefds && FD_ISSET(fd, writefds))
+ {
+ pollset[ndx].fd = fd;
+ pollset[ndx].events |= POLLOUT;
+ incr = 1;
+ }
+
+ if (exceptfds && FD_ISSET(fd, exceptfds))
+ {
+ pollset[ndx].fd = fd;
+ incr = 1;
+ }
+
+ ndx += incr;
+ }
+
+ RT_ASSERT(ndx == npfds);
+
+ /* Convert the timeout to milliseconds */
+ if (timeout)
+ {
+ msec = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
+ }
+ else
+ {
+ msec = -1;
+ }
+
+ /* Then let poll do all of the real work. */
+
+ ret = poll(pollset, npfds, msec);
+
+ /* Now set up the return values */
+ if (readfds)
+ {
+ fdszero(readfds, nfds);
+ }
+
+ if (writefds)
+ {
+ fdszero(writefds, nfds);
+ }
+
+ if (exceptfds)
+ {
+ fdszero(exceptfds, nfds);
+ }
+
+ /* Convert the poll descriptor list back into selects 3 bitsets */
+
+ if (ret > 0)
+ {
+ ret = 0;
+ for (ndx = 0; ndx < npfds; ndx++)
+ {
+ /* Check for read conditions. Note that POLLHUP is included as a
+ * read condition. POLLHUP will be reported when no more data will
+ * be available (such as when a connection is lost). In either
+ * case, the read() can then be performed without blocking.
+ */
+
+ if (readfds)
+ {
+ if (pollset[ndx].revents & (POLLIN | POLLHUP))
+ {
+ FD_SET(pollset[ndx].fd, readfds);
+ ret++;
+ }
+ }
+
+ /* Check for write conditions */
+ if (writefds)
+ {
+ if (pollset[ndx].revents & POLLOUT)
+ {
+ FD_SET(pollset[ndx].fd, writefds);
+ ret++;
+ }
+ }
+
+ /* Check for exceptions */
+ if (exceptfds)
+ {
+ if (pollset[ndx].revents & POLLERR)
+ {
+ FD_SET(pollset[ndx].fd, exceptfds);
+ ret++;
+ }
+ }
+ }
+ }
+
+ if (pollset) rt_free(pollset);
+
+ return ret;
+}
diff --git a/components/libc/posix/io/stdio/SConscript b/components/libc/posix/io/stdio/SConscript
new file mode 100644
index 0000000000..d33809ce42
--- /dev/null
+++ b/components/libc/posix/io/stdio/SConscript
@@ -0,0 +1,22 @@
+# RT-Thread building script for component
+
+import os
+from building import *
+
+src = []
+cwd = GetCurrentDir()
+CPPPATH = [cwd]
+group = []
+
+if GetDepend('RT_USING_POSIX_STDIO'):
+ src += ['libc.c']
+
+group = DefineGroup('POSIX', src, depend = [''], CPPPATH = CPPPATH)
+
+list = os.listdir(cwd)
+for d in list:
+ path = os.path.join(cwd, d)
+ if os.path.isfile(os.path.join(path, 'SConscript')):
+ group = group + SConscript(os.path.join(d, 'SConscript'))
+
+Return('group')
diff --git a/components/libc/posix/io/stdio/libc.c b/components/libc/posix/io/stdio/libc.c
new file mode 100644
index 0000000000..ebdc3a537b
--- /dev/null
+++ b/components/libc/posix/io/stdio/libc.c
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2017/10/15 bernard the first version
+ */
+
+#include <rtthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <sys/errno.h>
+#include "libc.h"
+
+int libc_system_init(void)
+{
+#ifdef RT_USING_POSIX_STDIO
+ rt_device_t dev_console;
+
+ dev_console = rt_console_get_device();
+ if (dev_console)
+ {
+ libc_stdio_set_console(dev_console->parent.name, O_RDWR);
+ }
+#endif /* RT_USING_POSIX_STDIO */
+ return 0;
+}
+INIT_COMPONENT_EXPORT(libc_system_init);
+
+#if defined(RT_USING_POSIX_STDIO) && defined(RT_USING_NEWLIB)
+#define STDIO_DEVICE_NAME_MAX 32
+static FILE* std_console = NULL;
+int libc_stdio_set_console(const char* device_name, int mode)
+{
+ FILE *fp;
+ char name[STDIO_DEVICE_NAME_MAX];
+ char *file_mode;
+
+ snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
+ name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
+
+ if (mode == O_RDWR)
+ {
+ file_mode = "r+";
+ }
+ else if (mode == O_WRONLY)
+ {
+ file_mode = "wb";
+ }
+ else
+ {
+ file_mode = "rb";
+ }
+
+ fp = fopen(name, file_mode);
+ if (fp)
+ {
+ setvbuf(fp, NULL, _IONBF, 0);
+
+ if (std_console)
+ {
+ fclose(std_console);
+ std_console = NULL;
+ }
+ std_console = fp;
+
+ if (mode == O_RDWR)
+ {
+ _GLOBAL_REENT->_stdin = std_console;
+ }
+ else
+ {
+ _GLOBAL_REENT->_stdin = NULL;
+ }
+
+ if (mode == O_RDONLY)
+ {
+ _GLOBAL_REENT->_stdout = NULL;
+ _GLOBAL_REENT->_stderr = NULL;
+ }
+ else
+ {
+ _GLOBAL_REENT->_stdout = std_console;
+ _GLOBAL_REENT->_stderr = std_console;
+ }
+
+ _GLOBAL_REENT->__sdidinit = 1;
+ }
+
+ if (std_console)
+ return fileno(std_console);
+
+ return -1;
+}
+
+int libc_stdio_get_console(void)
+{
+ if (std_console)
+ return fileno(std_console);
+ else
+ return -1;
+}
+
+#elif defined(RT_USING_POSIX_STDIO)
+#define STDIO_DEVICE_NAME_MAX 32
+static int std_fd = -1;
+int libc_stdio_set_console(const char* device_name, int mode)
+{
+ int fd;
+ char name[STDIO_DEVICE_NAME_MAX];
+
+ snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
+ name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
+
+ fd = open(name, mode, 0);
+ if (fd >= 0)
+ {
+ if (std_fd >= 0)
+ {
+ close(std_fd);
+ }
+ std_fd = fd;
+ }
+
+ return std_fd;
+}
+
+int libc_stdio_get_console(void) {
+ return std_fd;
+}
+#endif /* defined(RT_USING_POSIX_STDIO) && defined(RT_USING_NEWLIB) */
+
+int isatty(int fd)
+{
+#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
+ if(fd == STDOUT_FILENO || fd == STDERR_FILENO)
+ {
+ return 1;
+ }
+#endif
+
+#ifdef RT_USING_POSIX_STDIO
+ if(fd == STDIN_FILENO)
+ {
+ return 1;
+ }
+#endif
+
+ rt_set_errno(ENOTTY);
+ return 0;
+}
+RTM_EXPORT(isatty);
diff --git a/components/libc/compilers/dlib/libc.h b/components/libc/posix/io/stdio/libc.h
index 5b46bee0c8..6b5dfd1fcc 100644
--- a/components/libc/compilers/dlib/libc.h
+++ b/components/libc/posix/io/stdio/libc.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -11,17 +11,18 @@
#ifndef __RTT_LIBC_H__
#define __RTT_LIBC_H__
-#include <stddef.h>
+#include <rtconfig.h>
#ifdef __cplusplus
extern "C" {
#endif
-int libc_system_init(void);
-int libc_stdio_set_console(const char* device_name, int mode);
+int libc_system_init(void);
+#ifdef RT_USING_POSIX_STDIO
int libc_stdio_get_console(void);
-int libc_stdio_read(void* buffer, size_t size);
-int libc_stdio_write(const void* buffer, size_t size);
+int libc_stdio_set_console(const char* device_name, int mode);
+#endif /* RT_USING_POSIX_STDIO */
+
#ifdef __cplusplus
}
#endif
diff --git a/components/libc/posix/io/termios/SConscript b/components/libc/posix/io/termios/SConscript
new file mode 100644
index 0000000000..68bd9d81c9
--- /dev/null
+++ b/components/libc/posix/io/termios/SConscript
@@ -0,0 +1,11 @@
+# RT-Thread building script for component
+
+from building import *
+
+cwd = GetCurrentDir()
+src = ['termios.c']
+CPPPATH = [cwd]
+
+group = DefineGroup('POSIX', src, depend = ['RT_USING_POSIX_TERMIOS'], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/components/libc/termios/posix_termios.c b/components/libc/posix/io/termios/termios.c
index 9c736c3184..8333b594bf 100644
--- a/components/libc/termios/posix_termios.c
+++ b/components/libc/posix/io/termios/termios.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -7,12 +7,12 @@
* Date Author Notes
* 2017/08/30 Bernard The first version
*/
+
#include <stdlib.h>
#include <string.h>
-#include <rtthread.h>
-#include <dfs_posix.h>
-
-#include <termios.h>
+#include <unistd.h>
+#include <sys/errno.h>
+#include "termios.h"
int tcgetattr(int fd, struct termios *tio)
{
@@ -128,4 +128,3 @@ int cfsetspeed(struct termios *tio, speed_t speed)
return cfsetospeed(tio, speed);
}
#endif
-
diff --git a/components/libc/termios/posix_termios.h b/components/libc/posix/io/termios/termios.h
index c61191b7dc..27f2db85b0 100644
--- a/components/libc/termios/posix_termios.h
+++ b/components/libc/posix/io/termios/termios.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -7,11 +7,12 @@
* Date Author Notes
* 2017/08/30 Bernard The first version
*/
-#ifndef TERMIOS_H__
-#define TERMIOS_H__
-#include <rtthread.h>
+#ifndef __TERMIOS_H__
+#define __TERMIOS_H__
+
#include <sys/types.h>
+#include <sys/ioctl.h>
#ifdef __cplusplus
extern "C" {
diff --git a/components/libc/posix/ipc/Kconfig b/components/libc/posix/ipc/Kconfig
new file mode 100644
index 0000000000..a1e4fc1632
--- /dev/null
+++ b/components/libc/posix/ipc/Kconfig
@@ -0,0 +1,36 @@
+menu "Interprocess Communication (IPC)"
+
+config RT_USING_POSIX_PIPE
+ bool "Enable pipe and FIFO"
+ select RT_USING_POSIX_FS
+ select RT_USING_POSIX_DEVIO
+ select RT_USING_POSIX_POLL
+ default n
+
+config RT_USING_POSIX_PIPE_SIZE
+ int "Set pipe buffer size"
+ depends on RT_USING_POSIX_PIPE
+ default 512
+
+# We have't implement of 'systemv ipc', so hide it firstly.
+#
+# config RT_USING_POSIX_IPC_SYSTEM_V
+# bool "Enable System V IPC"
+# default n
+# help
+# System V supplies an alternative form of interprocess communication consisting of thress
+# features: shared memory, message, and semaphores.
+
+config RT_USING_POSIX_MESSAGE_QUEUE
+ bool "Enable posix message queue <mqueue.h>"
+ select RT_USING_POSIX_CLOCK
+ default n
+
+config RT_USING_POSIX_MESSAGE_SEMAPHORE
+ bool "Enable posix semaphore <semaphore.h>"
+ select RT_USING_POSIX_CLOCK
+ default n
+
+comment "Socket is in the 'Network' category"
+
+endmenu
diff --git a/components/libc/posix/ipc/SConscript b/components/libc/posix/ipc/SConscript
new file mode 100644
index 0000000000..5ea9dea355
--- /dev/null
+++ b/components/libc/posix/ipc/SConscript
@@ -0,0 +1,20 @@
+from building import *
+
+cwd = GetCurrentDir()
+src = []
+inc = [cwd]
+
+# We have't implement of 'systemv ipc', so hide it firstly.
+# if GetDepend('RT_USING_POSIX_IPC_SYSTEM_V'):
+# src += Glob('system-v/*.c')
+# inc += [cwd + '/system-v']
+
+if GetDepend('RT_USING_POSIX_MESSAGE_QUEUE'):
+ src += ['mqueue.c']
+
+if GetDepend('RT_USING_POSIX_MESSAGE_SEMAPHORE'):
+ src += ['semaphore.c']
+
+group = DefineGroup('POSIX', src, depend = [''], CPPPATH = inc)
+
+Return('group')
diff --git a/components/libc/pthreads/mqueue.c b/components/libc/posix/ipc/mqueue.c
index 003b49b9a0..4bc1c39955 100644
--- a/components/libc/pthreads/mqueue.c
+++ b/components/libc/posix/ipc/mqueue.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -8,15 +8,23 @@
*/
#include <string.h>
+#include <fcntl.h>
+#include <sys/signal.h>
+#include <sys/time.h>
+#include <sys/errno.h>
+#include <rtthread.h>
#include "mqueue.h"
-#include "pthread_internal.h"
static mqd_t posix_mq_list = RT_NULL;
static struct rt_semaphore posix_mq_lock;
-void posix_mq_system_init()
+
+/* initialize posix mqueue */
+static int posix_mq_system_init(void)
{
rt_sem_init(&posix_mq_lock, "pmq", 1, RT_IPC_FLAG_FIFO);
+ return 0;
}
+INIT_COMPONENT_EXPORT(posix_mq_system_init);
rt_inline void posix_mq_insert(mqd_t pmq)
{
@@ -243,7 +251,7 @@ ssize_t mq_timedreceive(mqd_t mqdes,
return -1;
}
- tick = clock_time_to_tick(abs_timeout);
+ tick = rt_timespec_to_tick(abs_timeout);
result = rt_mq_recv(mqdes->mq, msg_ptr, msg_len, tick);
if (result == RT_EOK)
diff --git a/components/libc/pthreads/mqueue.h b/components/libc/posix/ipc/mqueue.h
index 5cadde3ae8..4872dc238d 100644
--- a/components/libc/pthreads/mqueue.h
+++ b/components/libc/posix/ipc/mqueue.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -10,8 +10,9 @@
#ifndef __MQUEUE_H__
#define __MQUEUE_H__
-#include <rtthread.h>
-#include <pthread.h>
+#include <sys/signal.h>
+#include <sys/time.h>
+#include <rtdef.h>
struct mqdes
{
diff --git a/components/libc/pthreads/semaphore.c b/components/libc/posix/ipc/semaphore.c
index 2ed93e99b6..d5b1a70279 100644
--- a/components/libc/pthreads/semaphore.c
+++ b/components/libc/posix/ipc/semaphore.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -10,15 +10,20 @@
#include <rtthread.h>
#include <string.h>
+#include <fcntl.h>
+#include <sys/errno.h>
#include "semaphore.h"
-#include "pthread_internal.h"
static sem_t *posix_sem_list = RT_NULL;
static struct rt_semaphore posix_sem_lock;
-void posix_sem_system_init()
+
+/* initialize posix semaphore */
+static int posix_sem_system_init(void)
{
rt_sem_init(&posix_sem_lock, "psem", 1, RT_IPC_FLAG_FIFO);
+ return 0;
}
+INIT_COMPONENT_EXPORT(posix_sem_system_init);
rt_inline void posix_sem_insert(sem_t *psem)
{
@@ -186,7 +191,7 @@ int sem_init(sem_t *sem, int pshared, unsigned int value)
rt_snprintf(name, sizeof(name), "psem%02d", psem_number++);
sem->sem = rt_sem_create(name, value, RT_IPC_FLAG_FIFO);
- if (sem == RT_NULL)
+ if (sem->sem == RT_NULL)
{
rt_set_errno(ENOMEM);
@@ -319,7 +324,7 @@ int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout)
return EINVAL;
/* calculate os tick */
- tick = clock_time_to_tick(abs_timeout);
+ tick = rt_timespec_to_tick(abs_timeout);
result = rt_sem_take(sem->sem, tick);
if (result == -RT_ETIMEOUT)
diff --git a/components/libc/pthreads/semaphore.h b/components/libc/posix/ipc/semaphore.h
index d135ae9261..a0882552a5 100644
--- a/components/libc/pthreads/semaphore.h
+++ b/components/libc/posix/ipc/semaphore.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -11,8 +11,8 @@
#ifndef __POSIX_SEMAPHORE_H__
#define __POSIX_SEMAPHORE_H__
-#include <rtthread.h>
-#include <pthread.h>
+#include <rtdef.h>
+#include <sys/time.h>
struct posix_sem
{
diff --git a/components/libc/posix/ipc/system-v/sys/ipc.h b/components/libc/posix/ipc/system-v/sys/ipc.h
new file mode 100644
index 0000000000..f4ac50a1e9
--- /dev/null
+++ b/components/libc/posix/ipc/system-v/sys/ipc.h
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-12-07 Meco Man First version
+ */
+
+#ifndef __SYS_IPC_H__
+#define __SYS_IPC_H__
+
+
+
+#endif
diff --git a/components/libc/posix/ipc/system-v/sys/msg.h b/components/libc/posix/ipc/system-v/sys/msg.h
new file mode 100644
index 0000000000..1489586a32
--- /dev/null
+++ b/components/libc/posix/ipc/system-v/sys/msg.h
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-12-07 Meco Man First version
+ */
+
+#ifndef __SYS_MSG_H__
+#define __SYS_MSG_H__
+
+
+
+#endif
diff --git a/components/libc/posix/ipc/system-v/sys/sem.h b/components/libc/posix/ipc/system-v/sys/sem.h
new file mode 100644
index 0000000000..4a32c91204
--- /dev/null
+++ b/components/libc/posix/ipc/system-v/sys/sem.h
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-12-07 Meco Man First version
+ */
+
+#ifndef __SYS_SEM_H__
+#define __SYS_SEM_H__
+
+#endif
diff --git a/components/libc/posix/ipc/system-v/sys/shm.h b/components/libc/posix/ipc/system-v/sys/shm.h
new file mode 100644
index 0000000000..5b536067fc
--- /dev/null
+++ b/components/libc/posix/ipc/system-v/sys/shm.h
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-12-07 Meco Man First version
+ */
+
+#ifndef __SYS_SHM_H__
+#define __SYS_SHM_H__
+
+
+
+#endif
diff --git a/components/libc/posix/libdl/SConscript b/components/libc/posix/libdl/SConscript
new file mode 100644
index 0000000000..7c5f9b8085
--- /dev/null
+++ b/components/libc/posix/libdl/SConscript
@@ -0,0 +1,12 @@
+from building import *
+Import('rtconfig')
+
+src = Glob('*.c') + Glob('arch/*.c')
+cwd = GetCurrentDir()
+group = []
+CPPPATH = [cwd]
+
+if rtconfig.PLATFORM == 'gcc':
+ group = DefineGroup('POSIX', src, depend = ['RT_USING_MODULE'], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/components/libc/libdl/arch/arm.c b/components/libc/posix/libdl/arch/arm.c
index a53c04f0bc..6a884bdb54 100644
--- a/components/libc/libdl/arch/arm.c
+++ b/components/libc/posix/libdl/arch/arm.c
@@ -1,8 +1,8 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
- *
+ *
* Change Logs:
* Date Author Notes
* 2018/08/29 Bernard first version
diff --git a/components/libc/posix/libdl/arch/riscv.c b/components/libc/posix/libdl/arch/riscv.c
new file mode 100644
index 0000000000..c7c454e168
--- /dev/null
+++ b/components/libc/posix/libdl/arch/riscv.c
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021/04/23 chunyexixiaoyu first version
+
+ */
+
+#include "../dlmodule.h"
+#include "../dlelf.h"
+
+#if (__riscv_xlen == 64)
+#define R_RISCV_NONE 0
+#define R_RISCV_32 1
+#define R_RISCV_64 2
+#define R_RISCV_RELATIVE 3
+#define R_RISCV_COPY 4
+#define R_RISCV_JUMP_SLOT 5
+#define R_RISCV_TLS_DTPMOD32 6
+#define R_RISCV_TLS_DTPMOD64 7
+#define R_RISCV_TLS_DTPREL32 8
+#define R_RISCV_TLS_DTPREL64 9
+#define R_RISCV_TLS_TPREL32 10
+#define R_RISCV_TLS_TPREL64 11
+
+int dlmodule_relocate(struct rt_dlmodule *module, Elf_Rel *rel, Elf_Addr sym_val)
+{
+ Elf64_Addr *where, tmp;
+ Elf64_Sword addend, offset;
+ rt_uint64_t upper, lower, sign, j1, j2;
+
+ where = (Elf64_Addr *)((rt_uint8_t *)module->mem_space
+ + rel->r_offset
+ - module->vstart_addr);
+ switch (ELF64_R_TYPE(rel->r_info))
+ {
+ case R_RISCV_NONE:
+ break;
+ case R_RISCV_64:
+ *where = (Elf64_Addr)(sym_val + rel->r_addend);
+ RT_DEBUG_LOG(RT_DEBUG_MODULE, ("R_RISCV_64: %x -> %x\n",where, *where));
+ break;
+ case R_RISCV_RELATIVE:
+ *where = (Elf64_Addr)((rt_uint8_t *)module->mem_space - module->vstart_addr + rel->r_addend);
+ RT_DEBUG_LOG(RT_DEBUG_MODULE, ("R_RISCV_RELATIVE: %x -> %x\n",where, *where));
+ break;
+ case R_RISCV_JUMP_SLOT:
+ *where = (Elf64_Addr)sym_val;
+ RT_DEBUG_LOG(RT_DEBUG_MODULE, ("R_RISCV_JUMP_SLOT: %x -> %x\n",where, *where));
+ break;
+ default:
+ RT_DEBUG_LOG(RT_DEBUG_MODULE, ("__riscv__ELF: invalid relocate TYPE %d\n", ELF64_R_TYPE(rel->r_info)));
+ return -1;
+ }
+ return 0;
+}
+#endif
diff --git a/components/libc/libdl/arch/x86.c b/components/libc/posix/libdl/arch/x86.c
index 16f2322fb4..e7ad714a03 100644
--- a/components/libc/libdl/arch/x86.c
+++ b/components/libc/posix/libdl/arch/x86.c
@@ -1,8 +1,8 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
- *
+ *
* Change Logs:
* Date Author Notes
* 2018/09/15 parai first version
@@ -13,9 +13,9 @@
#ifdef __i386__
-#define R_X86_64_GLOB_DAT 6 /* Create GOT entry */
-#define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */
-#define R_X86_64_RELATIVE 8 /* Adjust by program base */
+#define R_X86_64_GLOB_DAT 6 /* Create GOT entry */
+#define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */
+#define R_X86_64_RELATIVE 8 /* Adjust by program base */
int dlmodule_relocate(struct rt_dlmodule *module, Elf32_Rel *rel, Elf32_Addr sym_val)
{
Elf32_Addr *where, tmp;
diff --git a/components/libc/libdl/dlclose.c b/components/libc/posix/libdl/dlclose.c
index 1202e13f2c..876a1576c8 100644
--- a/components/libc/libdl/dlclose.c
+++ b/components/libc/posix/libdl/dlclose.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/libdl/dlelf.c b/components/libc/posix/libdl/dlelf.c
index 55ef0d8951..418ad7539a 100644
--- a/components/libc/libdl/dlelf.c
+++ b/components/libc/posix/libdl/dlelf.c
@@ -1,11 +1,12 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018/08/29 Bernard first version
+ * 2021/04/23 chunyexixiaoyu distinguish 32-bit and 64-bit
*/
#include "dlmodule.h"
@@ -18,8 +19,8 @@
rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_ptr)
{
rt_bool_t linked = RT_FALSE;
- rt_uint32_t index, module_size = 0;
- Elf32_Addr vstart_addr, vend_addr;
+ rt_ubase_t index, module_size = 0;
+ Elf_Addr vstart_addr, vend_addr;
rt_bool_t has_vstart;
RT_ASSERT(module_ptr != RT_NULL);
@@ -53,7 +54,7 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
has_vstart = RT_TRUE;
if (vend_addr < vstart_addr)
{
- rt_kprintf("invalid elf: segment %d: p_vaddr: %d, p_memsz: %d\n",
+ LOG_E("invalid elf: segment %d: p_vaddr: %d, p_memsz: %d\n",
index, phdr[index].p_vaddr, phdr[index].p_memsz);
return RT_NULL;
}
@@ -62,7 +63,7 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
{
if (phdr[index].p_vaddr < vend_addr)
{
- rt_kprintf("invalid elf: segment should be sorted and not overlapped\n");
+ LOG_E("invalid elf: segment should be sorted and not overlapped\n");
return RT_NULL;
}
if (phdr[index].p_vaddr > vend_addr + 16)
@@ -74,7 +75,7 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
vend_addr = phdr[index].p_vaddr + phdr[index].p_memsz;
if (vend_addr < phdr[index].p_vaddr)
{
- rt_kprintf("invalid elf: "
+ LOG_E("invalid elf: "
"segment %d address overflow\n", index);
return RT_NULL;
}
@@ -85,7 +86,7 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
LOG_D("module size: %d, vstart_addr: 0x%p", module_size, vstart_addr);
if (module_size == 0)
{
- rt_kprintf("Module: size error\n");
+ LOG_E("Module: size error\n");
return -RT_ERROR;
}
@@ -96,7 +97,7 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
module->mem_space = rt_malloc(module_size);
if (module->mem_space == RT_NULL)
{
- rt_kprintf("Module: allocate space failed.\n");
+ LOG_E("Module: allocate space failed.\n");
return -RT_ERROR;
}
module->mem_size = module_size;
@@ -119,42 +120,49 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
/* handle relocation section */
for (index = 0; index < elf_module->e_shnum; index ++)
{
- rt_uint32_t i, nr_reloc;
- Elf32_Sym *symtab;
- Elf32_Rel *rel;
+ rt_ubase_t i, nr_reloc;
+ Elf_Sym *symtab;
+ Elf_Rel *rel;
rt_uint8_t *strtab;
static rt_bool_t unsolved = RT_FALSE;
-
+ #if (defined(__arm__) || defined(__i386__) || (__riscv_xlen == 32))
if (!IS_REL(shdr[index]))
continue;
+ #elif (defined(__aarch64__) || defined(__x86_64__) || (__riscv_xlen == 64))
+ if (!IS_RELA(shdr[index]))
+ continue;
+ #endif
/* get relocate item */
- rel = (Elf32_Rel *)((rt_uint8_t *)module_ptr + shdr[index].sh_offset);
+ rel = (Elf_Rel *)((rt_uint8_t *)module_ptr + shdr[index].sh_offset);
/* locate .rel.plt and .rel.dyn section */
- symtab = (Elf32_Sym *)((rt_uint8_t *)module_ptr +
+ symtab = (Elf_Sym *)((rt_uint8_t *)module_ptr +
shdr[shdr[index].sh_link].sh_offset);
strtab = (rt_uint8_t *)module_ptr +
shdr[shdr[shdr[index].sh_link].sh_link].sh_offset;
- nr_reloc = (rt_uint32_t)(shdr[index].sh_size / sizeof(Elf32_Rel));
+ nr_reloc = (rt_ubase_t)(shdr[index].sh_size / sizeof(Elf_Rel));
/* relocate every items */
for (i = 0; i < nr_reloc; i ++)
{
- Elf32_Sym *sym = &symtab[ELF32_R_SYM(rel->r_info)];
-
+ #if (defined(__arm__) || defined(__i386__) || (__riscv_xlen == 32))
+ Elf_Sym *sym = &symtab[ELF32_R_SYM(rel->r_info)];
+ #elif (defined(__aarch64__) || defined(__x86_64__) || (__riscv_xlen == 64))
+ Elf_Sym *sym = &symtab[ELF64_R_SYM(rel->r_info)];
+ #endif
LOG_D("relocate symbol %s shndx %d", strtab + sym->st_name, sym->st_shndx);
if ((sym->st_shndx != SHT_NULL) ||(ELF_ST_BIND(sym->st_info) == STB_LOCAL))
{
- Elf32_Addr addr;
+ Elf_Addr addr;
- addr = (Elf32_Addr)(module->mem_space + sym->st_value - vstart_addr);
+ addr = (Elf_Addr)(module->mem_space + sym->st_value - vstart_addr);
dlmodule_relocate(module, rel, addr);
}
else if (!linked)
{
- Elf32_Addr addr;
+ Elf_Addr addr;
LOG_D("relocate symbol: %s", strtab + sym->st_name);
/* need to resolve symbol in kernel symbol table */
@@ -172,7 +180,7 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
rel ++;
}
- if (unsolved)
+ if (unsolved)
return -RT_ERROR;
}
@@ -191,13 +199,13 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
if (index != elf_module->e_shnum)
{
int i, count = 0;
- Elf32_Sym *symtab = RT_NULL;
+ Elf_Sym *symtab = RT_NULL;
rt_uint8_t *strtab = RT_NULL;
- symtab = (Elf32_Sym *)((rt_uint8_t *)module_ptr + shdr[index].sh_offset);
+ symtab = (Elf_Sym *)((rt_uint8_t *)module_ptr + shdr[index].sh_offset);
strtab = (rt_uint8_t *)module_ptr + shdr[shdr[index].sh_link].sh_offset;
- for (i = 0; i < shdr[index].sh_size / sizeof(Elf32_Sym); i++)
+ for (i = 0; i < shdr[index].sh_size / sizeof(Elf_Sym); i++)
{
if ((ELF_ST_BIND(symtab[i].st_info) == STB_GLOBAL) &&
(ELF_ST_TYPE(symtab[i].st_info) == STT_FUNC))
@@ -207,7 +215,7 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
module->symtab = (struct rt_module_symtab *)rt_malloc
(count * sizeof(struct rt_module_symtab));
module->nsym = count;
- for (i = 0, count = 0; i < shdr[index].sh_size / sizeof(Elf32_Sym); i++)
+ for (i = 0, count = 0; i < shdr[index].sh_size / sizeof(Elf_Sym); i++)
{
rt_size_t length;
@@ -231,7 +239,7 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
rt_uint32_t flag = 0;
rt_uint16_t priority;
rt_uint32_t stacksize;
- for (i = 0; i < shdr[index].sh_size / sizeof(Elf32_Sym); i++)
+ for (i = 0; i < shdr[index].sh_size / sizeof(Elf_Sym); i++)
{
if (((flag & 0x01) == 0) &&
(rt_strcmp((const char *)(strtab + symtab[i].st_name), "dlmodule_thread_priority") == 0))
@@ -267,8 +275,8 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module_ptr)
{
- rt_uint32_t index, rodata_addr = 0, bss_addr = 0, data_addr = 0;
- rt_uint32_t module_addr = 0, module_size = 0;
+ rt_ubase_t index, rodata_addr = 0, bss_addr = 0, data_addr = 0;
+ rt_ubase_t module_addr = 0, module_size = 0;
rt_uint8_t *ptr, *strtab, *shstrab;
/* get the ELF image size */
@@ -306,7 +314,7 @@ rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module
module->mem_space = rt_malloc(module_size);
if (module->mem_space == RT_NULL)
{
- rt_kprintf("Module: allocate space failed.\n");
+ LOG_E("Module: allocate space failed.\n");
return -RT_ERROR;
}
module->mem_size = module_size;
@@ -335,7 +343,7 @@ rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module
(rt_uint8_t *)elf_module + shdr[index].sh_offset,
shdr[index].sh_size);
rodata_addr = (rt_uint32_t)ptr;
- LOG_D("load rodata 0x%x, size %d, rodata 0x%x", ptr,
+ LOG_D("load rodata 0x%x, size %d, rodata 0x%x", ptr,
shdr[index].sh_size, *(rt_uint32_t *)data_addr);
ptr += shdr[index].sh_size;
}
@@ -347,7 +355,7 @@ rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module
(rt_uint8_t *)elf_module + shdr[index].sh_offset,
shdr[index].sh_size);
data_addr = (rt_uint32_t)ptr;
- LOG_D("load data 0x%x, size %d, data 0x%x", ptr,
+ LOG_D("load data 0x%x, size %d, data 0x%x", ptr,
shdr[index].sh_size, *(rt_uint32_t *)data_addr);
ptr += shdr[index].sh_size;
}
@@ -367,36 +375,46 @@ rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module
/* handle relocation section */
for (index = 0; index < elf_module->e_shnum; index ++)
{
- rt_uint32_t i, nr_reloc;
- Elf32_Sym *symtab;
- Elf32_Rel *rel;
+ rt_ubase_t i, nr_reloc;
+ Elf_Sym *symtab;
+ Elf_Rel *rel;
+ #if (defined(__arm__) || defined(__i386__) || (__riscv_xlen == 32))
if (!IS_REL(shdr[index]))
continue;
+ #elif (defined(__aarch64__) || defined(__x86_64__) || (__riscv_xlen == 64))
+ if (!IS_RELA(shdr[index]))
+ continue;
+ #endif
+
/* get relocate item */
- rel = (Elf32_Rel *)((rt_uint8_t *)module_ptr + shdr[index].sh_offset);
+ rel = (Elf_Rel *)((rt_uint8_t *)module_ptr + shdr[index].sh_offset);
/* locate .dynsym and .dynstr */
- symtab = (Elf32_Sym *)((rt_uint8_t *)module_ptr +
+ symtab = (Elf_Sym *)((rt_uint8_t *)module_ptr +
shdr[shdr[index].sh_link].sh_offset);
strtab = (rt_uint8_t *)module_ptr +
shdr[shdr[shdr[index].sh_link].sh_link].sh_offset;
shstrab = (rt_uint8_t *)module_ptr +
shdr[elf_module->e_shstrndx].sh_offset;
- nr_reloc = (rt_uint32_t)(shdr[index].sh_size / sizeof(Elf32_Rel));
+ nr_reloc = (rt_uint32_t)(shdr[index].sh_size / sizeof(Elf_Rel));
/* relocate every items */
for (i = 0; i < nr_reloc; i ++)
{
- Elf32_Sym *sym = &symtab[ELF32_R_SYM(rel->r_info)];
+ #if (defined(__arm__) || defined(__i386__) || (__riscv_xlen == 32))
+ Elf_Sym *sym = &symtab[ELF32_R_SYM(rel->r_info)];
+ #elif (defined(__aarch64__) || defined(__x86_64__) || (__riscv_xlen == 64))
+ Elf_Sym *sym = &symtab[ELF64_R_SYM(rel->r_info)];
+ #endif
LOG_D("relocate symbol: %s", strtab + sym->st_name);
if (sym->st_shndx != STN_UNDEF)
{
- Elf32_Addr addr = 0;
-
+ Elf_Addr addr = 0;
+
if ((ELF_ST_TYPE(sym->st_info) == STT_SECTION) ||
(ELF_ST_TYPE(sym->st_info) == STT_OBJECT))
{
@@ -405,28 +423,28 @@ rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module
{
/* relocate rodata section */
LOG_D("rodata");
- addr = (Elf32_Addr)(rodata_addr + sym->st_value);
+ addr = (Elf_Addr)(rodata_addr + sym->st_value);
}
else if (rt_strncmp((const char *)
(shstrab + shdr[sym->st_shndx].sh_name), ELF_BSS, 5) == 0)
{
/* relocate bss section */
LOG_D("bss");
- addr = (Elf32_Addr)bss_addr + sym->st_value;
+ addr = (Elf_Addr)bss_addr + sym->st_value;
}
else if (rt_strncmp((const char *)(shstrab + shdr[sym->st_shndx].sh_name),
ELF_DATA, 6) == 0)
{
/* relocate data section */
LOG_D("data");
- addr = (Elf32_Addr)data_addr + sym->st_value;
+ addr = (Elf_Addr)data_addr + sym->st_value;
}
if (addr != 0) dlmodule_relocate(module, rel, addr);
}
else if (ELF_ST_TYPE(sym->st_info) == STT_FUNC)
{
- addr = (Elf32_Addr)((rt_uint8_t *) module->mem_space - module_addr + sym->st_value);
+ addr = (Elf_Addr)((rt_uint8_t *) module->mem_space - module_addr + sym->st_value);
/* relocate function */
dlmodule_relocate(module, rel, addr);
@@ -436,14 +454,14 @@ rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module
{
/* relocate function */
dlmodule_relocate(module, rel,
- (Elf32_Addr)((rt_uint8_t *)
+ (Elf_Addr)((rt_uint8_t *)
module->mem_space
- module_addr
+ sym->st_value));
}
else
{
- Elf32_Addr addr;
+ Elf_Addr addr;
if (ELF32_R_TYPE(rel->r_info) != R_ARM_V4BX)
{
@@ -451,7 +469,7 @@ rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module
/* need to resolve symbol in kernel symbol table */
addr = dlmodule_symbol_find((const char *)(strtab + sym->st_name));
- if (addr != (Elf32_Addr)RT_NULL)
+ if (addr != (Elf_Addr)RT_NULL)
{
dlmodule_relocate(module, rel, addr);
LOG_D("symbol addr 0x%x", addr);
@@ -462,7 +480,7 @@ rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module
}
else
{
- addr = (Elf32_Addr)((rt_uint8_t *) module->mem_space - module_addr + sym->st_value);
+ addr = (Elf_Addr)((rt_uint8_t *) module->mem_space - module_addr + sym->st_value);
dlmodule_relocate(module, rel, addr);
}
}
diff --git a/components/libc/libdl/dlelf.h b/components/libc/posix/libdl/dlelf.h
index 014ebe85c8..339e172bb4 100644
--- a/components/libc/libdl/dlelf.h
+++ b/components/libc/posix/libdl/dlelf.h
@@ -1,11 +1,12 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
- *
+ *
* Change Logs:
- * Date Author Notes
- * 2018/08/29 Bernard first version
+ * Date Author Notes
+ * 2018/08/29 Bernard first version
+ * 2021/04/23 chunyexixiaoyu distinguish 32-bit and 64-bit
*/
#ifndef DL_ELF_H__
@@ -19,6 +20,16 @@ typedef rt_int32_t Elf32_Sword; /* Signed large integer */
typedef rt_uint32_t Elf32_Word; /* Unsigned large integer */
typedef rt_uint16_t Elf32_Half; /* Unsigned medium integer */
+typedef rt_uint64_t Elf64_Addr;
+typedef rt_uint16_t Elf64_Half;
+typedef rt_int16_t Elf64_SHalf;
+typedef rt_uint64_t Elf64_Off;
+typedef rt_int32_t Elf64_Sword;
+typedef rt_uint32_t Elf64_Word;
+typedef rt_uint64_t Elf64_Xword;
+typedef rt_int64_t Elf64_Sxword;
+typedef rt_uint16_t Elf64_Section;
+
/* e_ident[] magic number */
#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
#define ELFMAG1 'E' /* e_ident[EI_MAG1] */
@@ -75,6 +86,25 @@ typedef struct elfhdr
header string table" entry offset */
} Elf32_Ehdr;
+typedef struct elf64_hdr
+{
+ unsigned char e_ident[EI_NIDENT]; /* ELF Identification */
+ Elf64_Half e_type; /* object file type */
+ Elf64_Half e_machine; /* machine */
+ Elf64_Word e_version; /* object file version */
+ Elf64_Addr e_entry; /* virtual entry point */
+ Elf64_Off e_phoff; /* program header table offset */
+ Elf64_Off e_shoff; /* section header table offset */
+ Elf64_Word e_flags; /* processor-specific flags */
+ Elf64_Half e_ehsize; /* ELF header size */
+ Elf64_Half e_phentsize; /* program header entry size */
+ Elf64_Half e_phnum; /* number of program header entries */
+ Elf64_Half e_shentsize; /* section header entry size */
+ Elf64_Half e_shnum; /* number of section header entries */
+ Elf64_Half e_shstrndx; /* section header table's "section
+ header string table" entry offset */
+} Elf64_Ehdr;
+
/* Section Header */
typedef struct
{
@@ -91,6 +121,20 @@ typedef struct
Elf32_Word sh_entsize; /* section entry size */
} Elf32_Shdr;
+typedef struct
+{
+ Elf64_Word sh_name; /* Section name (string tbl index) */
+ Elf64_Word sh_type; /* Section type */
+ Elf64_Xword sh_flags; /* Section flags */
+ Elf64_Addr sh_addr; /* Section virtual addr at execution */
+ Elf64_Off sh_offset; /* Section file offset */
+ Elf64_Xword sh_size; /* Section size in bytes */
+ Elf64_Word sh_link; /* Link to another section */
+ Elf64_Word sh_info; /* Additional section information */
+ Elf64_Xword sh_addralign; /* Section alignment */
+ Elf64_Xword sh_entsize; /* Entry size if section holds table */
+} Elf64_Shdr;
+
/* Section names */
#define ELF_BSS ".bss" /* uninitialized data */
#define ELF_DATA ".data" /* initialized data */
@@ -126,6 +170,16 @@ typedef struct elf32_sym
Elf32_Half st_shndx; /* section header index */
} Elf32_Sym;
+typedef struct
+{
+ Elf64_Word st_name; /* Symbol name (string tbl index) */
+ unsigned char st_info; /* Symbol type and binding */
+ unsigned char st_other; /* Symbol visibility */
+ Elf64_Section st_shndx; /* Section index */
+ Elf64_Addr st_value; /* Symbol value */
+ Elf64_Xword st_size; /* Symbol size */
+} Elf64_Sym;
+
#define STB_LOCAL 0 /* BIND */
#define STB_GLOBAL 1
#define STB_WEAK 2
@@ -160,6 +214,12 @@ typedef struct
Elf32_Word r_info; /* symbol table index and type */
} Elf32_Rel;
+typedef struct
+{
+ Elf64_Addr r_offset; /* Address */
+ Elf64_Xword r_info; /* Relocation type and symbol index */
+} Elf64_Rel;
+
/* Relocation entry with explicit addend */
typedef struct
{
@@ -168,11 +228,22 @@ typedef struct
Elf32_Sword r_addend;
} Elf32_Rela;
+typedef struct
+{
+ Elf64_Addr r_offset; /* Address */
+ Elf64_Xword r_info; /* Relocation type and symbol index */
+ Elf64_Sxword r_addend; /* Addend */
+} Elf64_Rela;
+
/* Extract relocation info - r_info */
#define ELF32_R_SYM(i) ((i) >> 8)
#define ELF32_R_TYPE(i) ((unsigned char) (i))
#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))
+#define ELF64_R_SYM(i) ((i) >> 32)
+#define ELF64_R_TYPE(i) ((i) & 0xffffffff)
+#define ELF64_R_INFO(sym,type) ((((Elf64_Xword) (sym)) << 32) + (type))
+
/*
* Relocation type for arm
*/
@@ -219,6 +290,18 @@ typedef struct
Elf32_Word p_align; /* memory alignment */
} Elf32_Phdr;
+typedef struct
+{
+ Elf64_Word p_type; /* Segment type */
+ Elf64_Word p_flags; /* Segment flags */
+ Elf64_Off p_offset; /* Segment file offset */
+ Elf64_Addr p_vaddr; /* Segment virtual address */
+ Elf64_Addr p_paddr; /* Segment physical address */
+ Elf64_Xword p_filesz; /* Segment size in file */
+ Elf64_Xword p_memsz; /* Segment size in memory */
+ Elf64_Xword p_align; /* Segment alignment */
+} Elf64_Phdr;
+
/* p_type */
#define PT_NULL 0
#define PT_LOAD 1
@@ -273,13 +356,26 @@ typedef struct
#define IS_AX(s) ((s.sh_flags & SHF_ALLOC) && (s.sh_flags & SHF_EXECINSTR))
#define IS_AW(s) ((s.sh_flags & SHF_ALLOC) && (s.sh_flags & SHF_WRITE))
+#if (defined(__arm__) || defined(__i386__) || (__riscv_xlen == 32))
#define elf_module ((Elf32_Ehdr *)module_ptr)
#define shdr ((Elf32_Shdr *)((rt_uint8_t *)module_ptr + elf_module->e_shoff))
#define phdr ((Elf32_Phdr *)((rt_uint8_t *)module_ptr + elf_module->e_phoff))
-rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_ptr);
-rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module_ptr);
+typedef Elf32_Sym Elf_Sym;
+typedef Elf32_Rel Elf_Rel;
+typedef Elf32_Addr Elf_Addr;
+#elif (defined(__aarch64__) || defined(__x86_64__) || (__riscv_xlen == 64))
+#define elf_module ((Elf64_Ehdr *)module_ptr)
+#define shdr ((Elf64_Shdr *)((rt_uint8_t *)module_ptr + elf_module->e_shoff))
+#define phdr ((Elf64_Phdr *)((rt_uint8_t *)module_ptr + elf_module->e_phoff))
+
+typedef Elf64_Sym Elf_Sym;
+typedef Elf64_Rela Elf_Rel;
+typedef Elf64_Addr Elf_Addr;
+#endif
-int dlmodule_relocate(struct rt_dlmodule *module, Elf32_Rel *rel, Elf32_Addr sym_val);
+int dlmodule_relocate(struct rt_dlmodule *module, Elf_Rel *rel, Elf_Addr sym_val);
+rt_err_t dlmodule_load_shared_object(struct rt_dlmodule *module, void *module_ptr);
+rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule *module, void *module_ptr);
#endif
diff --git a/components/libc/libdl/dlerror.c b/components/libc/posix/libdl/dlerror.c
index ad9b630e4c..de948eb16b 100644
--- a/components/libc/libdl/dlerror.c
+++ b/components/libc/posix/libdl/dlerror.c
@@ -1,8 +1,8 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
- *
+ *
* Change Logs:
* Date Author Notes
* 2010-11-17 yi.qiu first version
@@ -13,6 +13,6 @@
const char *dlerror(void)
{
- return "TODO";
+ return "TODO";
}
RTM_EXPORT(dlerror)
diff --git a/components/libc/libdl/dlfcn.h b/components/libc/posix/libdl/dlfcn.h
index 55273a41eb..f5c9063f2f 100644
--- a/components/libc/libdl/dlfcn.h
+++ b/components/libc/posix/libdl/dlfcn.h
@@ -1,8 +1,8 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
- *
+ *
* Change Logs:
* Date Author Notes
* 2010-11-17 yi.qiu first version
diff --git a/components/libc/libdl/dlmodule.c b/components/libc/posix/libdl/dlmodule.c
index 314cf52709..ffa23de82d 100644
--- a/components/libc/libdl/dlmodule.c
+++ b/components/libc/posix/libdl/dlmodule.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -14,8 +14,10 @@
#include "dlmodule.h"
#include "dlelf.h"
-#if defined(RT_USING_POSIX)
-#include <dfs_posix.h>
+#ifdef RT_USING_POSIX_FS
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/statfs.h>
#endif
#define DBG_TAG "DLMD"
@@ -421,14 +423,14 @@ struct rt_dlmodule *rt_module_self(void)
struct rt_dlmodule* dlmodule_load(const char* filename)
{
-#if defined(RT_USING_POSIX)
+#ifdef RT_USING_POSIX_FS
int fd = -1, length = 0;
#endif
rt_err_t ret = RT_EOK;
rt_uint8_t *module_ptr = RT_NULL;
struct rt_dlmodule *module = RT_NULL;
-#if defined(RT_USING_POSIX)
+#ifdef RT_USING_POSIX_FS
fd = open(filename, O_RDONLY, 0);
if (fd >= 0)
{
@@ -464,7 +466,7 @@ struct rt_dlmodule* dlmodule_load(const char* filename)
}
/* check ELF class */
- if (elf_module->e_ident[EI_CLASS] != ELFCLASS32)
+ if ((elf_module->e_ident[EI_CLASS] != ELFCLASS32)&&(elf_module->e_ident[EI_CLASS] != ELFCLASS64))
{
rt_kprintf("Module: ELF class error\n");
goto __exit;
@@ -520,7 +522,7 @@ struct rt_dlmodule* dlmodule_load(const char* filename)
return module;
__exit:
-#if defined(RT_USING_POSIX)
+#ifdef RT_USING_POSIX_FS
if (fd >= 0) close(fd);
#endif
if (module_ptr) rt_free(module_ptr);
@@ -547,7 +549,7 @@ struct rt_dlmodule* dlmodule_exec(const char* pgname, const char* cmd, int cmd_s
if (module->priority > RT_THREAD_PRIORITY_MAX) module->priority = RT_THREAD_PRIORITY_MAX - 1;
if (module->stack_size < 2048 || module->stack_size > (1024 * 32)) module->stack_size = 2048;
- tid = rt_thread_create(module->parent.name, _dlmodule_thread_entry, (void*)module,
+ tid = rt_thread_create(module->parent.name, _dlmodule_thread_entry, (void*)module,
module->stack_size, module->priority, 10);
if (tid)
{
@@ -571,7 +573,7 @@ struct rt_dlmodule* dlmodule_exec(const char* pgname, const char* cmd, int cmd_s
#if defined(RT_USING_CUSTOM_DLMODULE)
struct rt_dlmodule* dlmodule_load_custom(const char* filename, struct rt_dlmodule_ops* ops)
{
-#if defined(RT_USING_POSIX)
+#ifdef RT_USING_POSIX_FS
int fd = -1, length = 0;
#endif
rt_err_t ret = RT_EOK;
@@ -584,7 +586,7 @@ struct rt_dlmodule* dlmodule_load_custom(const char* filename, struct rt_dlmodul
RT_ASSERT(ops->unload);
module_ptr = ops->load(filename);
}
-#if defined(RT_USING_POSIX)
+#ifdef RT_USING_POSIX_FS
else
{
fd = open(filename, O_RDONLY, 0);
@@ -686,7 +688,7 @@ struct rt_dlmodule* dlmodule_load_custom(const char* filename, struct rt_dlmodul
return module;
__exit:
-#if defined(RT_USING_POSIX)
+#ifdef RT_USING_POSIX_FS
if (fd >= 0) close(fd);
#endif
if (module_ptr)
@@ -724,7 +726,7 @@ struct rt_dlmodule* dlmodule_exec_custom(const char* pgname, const char* cmd, in
if (module->priority > RT_THREAD_PRIORITY_MAX) module->priority = RT_THREAD_PRIORITY_MAX - 1;
if (module->stack_size < 2048 || module->stack_size > (1024 * 32)) module->stack_size = 2048;
- tid = rt_thread_create(module->parent.name, _dlmodule_thread_entry, (void*)module,
+ tid = rt_thread_create(module->parent.name, _dlmodule_thread_entry, (void*)module,
module->stack_size, module->priority, 10);
if (tid)
{
@@ -758,7 +760,7 @@ void dlmodule_exit(int ret_code)
rt_enter_critical();
/* module is not running */
- if (module->stat != RT_DLMODULE_STAT_RUNNING)
+ if (module->stat != RT_DLMODULE_STAT_RUNNING)
{
/* restore scheduling */
rt_exit_critical();
diff --git a/components/libc/libdl/dlmodule.h b/components/libc/posix/libdl/dlmodule.h
index b366c7603e..183faca159 100644
--- a/components/libc/libdl/dlmodule.h
+++ b/components/libc/posix/libdl/dlmodule.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/libdl/dlopen.c b/components/libc/posix/libdl/dlopen.c
index a8202ec607..bcb57d78f0 100644
--- a/components/libc/libdl/dlopen.c
+++ b/components/libc/posix/libdl/dlopen.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -43,12 +43,12 @@ void* dlopen(const char *filename, int flags)
/* find in module list */
module = dlmodule_find(fullpath);
- if(module != RT_NULL)
+ if(module != RT_NULL)
{
rt_exit_critical();
module->nref++;
}
- else
+ else
{
rt_exit_critical();
module = dlmodule_load(fullpath);
diff --git a/components/libc/libdl/dlsym.c b/components/libc/posix/libdl/dlsym.c
index ed0f183d83..f7c1c901fd 100644
--- a/components/libc/libdl/dlsym.c
+++ b/components/libc/posix/libdl/dlsym.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -17,7 +17,7 @@ void* dlsym(void *handle, const char* symbol)
{
int i;
struct rt_dlmodule *module;
-
+
RT_ASSERT(handle != RT_NULL);
module = (struct rt_dlmodule *)handle;
diff --git a/components/libc/compilers/newlib/libc_syms.c b/components/libc/posix/libdl/dlsyms.c
index b150c10fd6..e6ca23b393 100644
--- a/components/libc/compilers/newlib/libc_syms.c
+++ b/components/libc/posix/libdl/dlsyms.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -7,6 +7,7 @@
* Date Author Notes
* 2017/10/15 bernard the first version
*/
+
#include <rtthread.h>
#include <rtm.h>
@@ -39,10 +40,6 @@ RTM_EXPORT(snprintf);
RTM_EXPORT(fwrite);
-#include <time.h>
-RTM_EXPORT(localtime);
-RTM_EXPORT(time);
-
#include <setjmp.h>
RTM_EXPORT(longjmp);
RTM_EXPORT(setjmp);
diff --git a/components/libc/posix/pthreads/SConscript b/components/libc/posix/pthreads/SConscript
new file mode 100644
index 0000000000..adcd07ee49
--- /dev/null
+++ b/components/libc/posix/pthreads/SConscript
@@ -0,0 +1,9 @@
+from building import *
+
+cwd = GetCurrentDir()
+src = Glob('*.c')
+CPPPATH = [cwd]
+
+group = DefineGroup('POSIX', src, depend = ['RT_USING_PTHREADS'], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/components/libc/pthreads/posix_types.h b/components/libc/posix/pthreads/posix_types.h
index ca20464bb5..e6da941956 100644
--- a/components/libc/pthreads/posix_types.h
+++ b/components/libc/posix/pthreads/posix_types.h
@@ -1,11 +1,11 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
- * 2013-12-23 Bernard Add the checking for ESHUTDOWN
+ * 2013-12-23 Bernard Add the checking for ESHUTDOWN
*/
#ifndef __POSIX_TYPES_H__
@@ -19,16 +19,8 @@
#include <sys/types.h>
#include <sys/time.h>
-
-/* errno for Keil MDK */
-#if defined(__CC_ARM) || defined(__IAR_SYSTEMS_ICC__)
-#include <sys/errno.h>
-#include <sys/unistd.h>
-#else
#include <unistd.h>
-#include <errno.h>
+#include <sys/errno.h>
#include <fcntl.h>
-#endif
#endif
-
diff --git a/components/libc/pthreads/pthread.c b/components/libc/posix/pthreads/pthread.c
index 19a511b45b..33f29b62ed 100644
--- a/components/libc/pthreads/pthread.c
+++ b/components/libc/posix/pthreads/pthread.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -13,10 +13,12 @@
#include <rthw.h>
#include <pthread.h>
#include <sched.h>
+#include <sys/time.h>
#include "pthread_internal.h"
RT_DEFINE_SPINLOCK(pth_lock);
_pthread_data_t *pth_table[PTHREAD_NUM_MAX] = {NULL};
+static int concurrency_level;
_pthread_data_t *_pthread_get_data(pthread_t thread)
{
@@ -89,9 +91,30 @@ void _pthread_data_destroy(pthread_t pth)
{
RT_DECLARE_SPINLOCK(pth_lock);
+ extern _pthread_key_data_t _thread_keys[PTHREAD_KEY_MAX];
_pthread_data_t *ptd = _pthread_get_data(pth);
if (ptd)
{
+ /* destruct thread local key */
+ if (ptd->tls != RT_NULL)
+ {
+ void *data;
+ rt_uint32_t index;
+ for (index = 0; index < PTHREAD_KEY_MAX; index ++)
+ {
+ if (_thread_keys[index].is_used)
+ {
+ data = ptd->tls[index];
+ if (data && _thread_keys[index].destructor)
+ _thread_keys[index].destructor(data);
+ }
+ }
+
+ /* release tls area */
+ rt_free(ptd->tls);
+ ptd->tls = RT_NULL;
+ }
+
/* remove from pthread table */
rt_hw_spin_lock(&pth_lock);
pth_table[pth] = NULL;
@@ -102,13 +125,17 @@ void _pthread_data_destroy(pthread_t pth)
rt_sem_delete(ptd->joinable_sem);
/* release thread resource */
- if (ptd->attr.stackaddr == RT_NULL && ptd->tid->stack_addr != RT_NULL)
+ if (ptd->attr.stackaddr == RT_NULL)
{
/* release thread allocated stack */
- rt_free(ptd->tid->stack_addr);
+ if (ptd->tid)
+ {
+ rt_free(ptd->tid->stack_addr);
+ }
}
/* clean stack addr pointer */
- ptd->tid->stack_addr = RT_NULL;
+ if (ptd->tid)
+ ptd->tid->stack_addr = RT_NULL;
/*
* if this thread create the local thread data,
@@ -125,19 +152,6 @@ void _pthread_data_destroy(pthread_t pth)
}
}
-int pthread_system_init(void)
-{
- /* initialize key area */
- pthread_key_system_init();
- /* initialize posix mqueue */
- posix_mq_system_init();
- /* initialize posix semaphore */
- posix_sem_system_init();
-
- return 0;
-}
-INIT_COMPONENT_EXPORT(pthread_system_init);
-
static void _pthread_destroy(_pthread_data_t *ptd)
{
pthread_t pth = _pthread_data_get_pth(ptd);
@@ -200,7 +214,7 @@ int pthread_create(pthread_t *pid,
/* allocate posix thread data */
pth_id = _pthread_data_create();
- if (pth_id == PTHREAD_NUM_MAX)
+ if (pth_id == PTHREAD_NUM_MAX)
{
ret = ENOMEM;
goto __exit;
@@ -208,6 +222,8 @@ int pthread_create(pthread_t *pid,
/* get pthread data */
ptd = _pthread_get_data(pth_id);
+ RT_ASSERT(ptd != RT_NULL);
+
if (attr != RT_NULL)
{
ptd->attr = *attr;
@@ -218,6 +234,12 @@ int pthread_create(pthread_t *pid,
pthread_attr_init(&ptd->attr);
}
+ if (ptd->attr.stacksize == 0)
+ {
+ ret = EINVAL;
+ goto __exit;
+ }
+
rt_snprintf(name, sizeof(name), "pth%02d", pthread_number ++);
/* pthread is a static thread object */
@@ -266,7 +288,7 @@ int pthread_create(pthread_t *pid,
/* initial this pthread to system */
if (rt_thread_init(ptd->tid, name, pthread_entry_stub, ptd,
stack, ptd->attr.stacksize,
- ptd->attr.schedparam.sched_priority, 5) != RT_EOK)
+ ptd->attr.schedparam.sched_priority, 20) != RT_EOK)
{
ret = EINVAL;
goto __exit;
@@ -298,6 +320,12 @@ int pthread_detach(pthread_t thread)
{
int ret = 0;
_pthread_data_t *ptd = _pthread_get_data(thread);
+ if (ptd == RT_NULL)
+ {
+ /* invalid pthread id */
+ ret = EINVAL;
+ goto __exit;
+ }
rt_enter_critical();
if (ptd->attr.detachstate == PTHREAD_CREATE_DETACHED)
@@ -359,6 +387,12 @@ int pthread_join(pthread_t thread, void **value_ptr)
rt_err_t result;
ptd = _pthread_get_data(thread);
+
+ if (ptd == RT_NULL)
+ {
+ return EINVAL; /* invalid pthread id */
+ }
+
if (ptd && ptd->tid == rt_thread_self())
{
/* join self */
@@ -366,7 +400,9 @@ int pthread_join(pthread_t thread, void **value_ptr)
}
if (ptd->attr.detachstate == PTHREAD_CREATE_DETACHED)
+ {
return EINVAL; /* join on a detached pthread */
+ }
result = rt_sem_take(ptd->joinable_sem, RT_WAITING_FOREVER);
if (result == RT_EOK)
@@ -403,6 +439,70 @@ pthread_t pthread_self (void)
}
RTM_EXPORT(pthread_self);
+int pthread_getcpuclockid(pthread_t thread, clockid_t *clock_id)
+{
+ if(_pthread_get_data(thread) == NULL)
+ {
+ return EINVAL;
+ }
+
+ *clock_id = (clockid_t)rt_tick_get();
+
+ return 0;
+}
+RTM_EXPORT(pthread_getcpuclockid);
+
+int pthread_getconcurrency(void)
+{
+ return concurrency_level;
+}
+RTM_EXPORT(pthread_getconcurrency);
+
+int pthread_setconcurrency(int new_level)
+{
+ concurrency_level = new_level;
+
+ return 0;
+}
+RTM_EXPORT(pthread_setconcurrency);
+
+int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param)
+{
+ _pthread_data_t *ptd;
+
+ ptd = _pthread_get_data(thread);
+ pthread_attr_getschedpolicy(&ptd->attr, policy);
+ pthread_attr_getschedparam(&ptd->attr, param);
+
+ return 0;
+}
+RTM_EXPORT(pthread_getschedparam);
+
+int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param)
+{
+ _pthread_data_t *ptd;
+
+ ptd = _pthread_get_data(thread);
+ pthread_attr_setschedpolicy(&ptd->attr, policy);
+ pthread_attr_setschedparam(&ptd->attr, param);
+
+ return 0;
+}
+RTM_EXPORT(pthread_setschedparam);
+
+int pthread_setschedprio(pthread_t thread, int prio)
+{
+ _pthread_data_t *ptd;
+ struct sched_param param;
+
+ ptd = _pthread_get_data(thread);
+ param.sched_priority = prio;
+ pthread_attr_setschedparam(&ptd->attr, &param);
+
+ return 0;
+}
+RTM_EXPORT(pthread_setschedprio);
+
void pthread_exit(void *value)
{
_pthread_data_t *ptd;
@@ -443,7 +543,7 @@ void pthread_exit(void *value)
if (_thread_keys[index].is_used)
{
data = ptd->tls[index];
- if (data)
+ if (data && _thread_keys[index].destructor)
_thread_keys[index].destructor(data);
}
}
@@ -490,14 +590,21 @@ int pthread_kill(pthread_t thread, int sig)
{
#ifdef RT_USING_SIGNALS
_pthread_data_t *ptd;
+ int ret;
ptd = _pthread_get_data(thread);
if (ptd)
{
- return rt_thread_kill(ptd->tid, sig);
+ ret = rt_thread_kill(ptd->tid, sig);
+ if (ret == -RT_EINVAL)
+ {
+ return EINVAL;
+ }
+
+ return ret;
}
- return EINVAL;
+ return ESRCH;
#else
return ENOSYS;
#endif
@@ -661,7 +768,10 @@ int pthread_cancel(pthread_t thread)
/* get posix thread data */
ptd = _pthread_get_data(thread);
- RT_ASSERT(ptd != RT_NULL);
+ if (ptd == RT_NULL)
+ {
+ return EINVAL;
+ }
/* cancel self */
if (ptd->tid == rt_thread_self())
diff --git a/components/libc/pthreads/pthread.h b/components/libc/posix/pthreads/pthread.h
index 7bb72b726c..c170ec49fd 100644
--- a/components/libc/pthreads/pthread.h
+++ b/components/libc/posix/pthreads/pthread.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -158,10 +158,11 @@ int pthread_attr_getstack(pthread_attr_t const *attr,
size_t *stack_size);
int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guard_size);
int pthread_attr_getguardsize(pthread_attr_t const *attr, size_t *guard_size);
+int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched);
+int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritsched);
int pthread_attr_setscope(pthread_attr_t *attr, int scope);
-int pthread_attr_getscope(pthread_attr_t const *attr);
-int pthread_system_init(void);
-int pthread_create (pthread_t *tid, const pthread_attr_t *attr,
+int pthread_attr_getscope(pthread_attr_t const *attr, int *scope);
+int pthread_create (pthread_t *tid, const pthread_attr_t *attr,
void *(*start) (void *), void *arg);
int pthread_detach (pthread_t thread);
@@ -174,9 +175,20 @@ rt_inline int pthread_equal (pthread_t t1, pthread_t t2)
pthread_t pthread_self (void);
+int pthread_getcpuclockid(pthread_t thread, clockid_t *clock_id);
+int pthread_getconcurrency(void);
+int pthread_setconcurrency(int new_level);
+int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param);
+int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param);
+int pthread_setschedprio(pthread_t thread, int prio);
+
void pthread_exit (void *value_ptr);
int pthread_once(pthread_once_t * once_control, void (*init_routine) (void));
+#ifdef RT_USING_SIGNALS
+int pthread_sigmask(int how, const sigset_t *set, sigset_t *oset);
+#endif
+
/* pthread cleanup */
void pthread_cleanup_pop(int execute);
void pthread_cleanup_push(void (*routine)(void*), void *arg);
@@ -196,6 +208,8 @@ int pthread_mutex_destroy(pthread_mutex_t *mutex);
int pthread_mutex_lock(pthread_mutex_t *mutex);
int pthread_mutex_unlock(pthread_mutex_t *mutex);
int pthread_mutex_trylock(pthread_mutex_t *mutex);
+int pthread_mutex_getprioceiling(const pthread_mutex_t *mutex, int *prioceiling);
+int pthread_mutex_setprioceiling(pthread_mutex_t *mutex, int prioceiling, int *old_ceiling);
int pthread_mutexattr_init(pthread_mutexattr_t *attr);
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
@@ -203,6 +217,11 @@ int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type);
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared);
int pthread_mutexattr_getpshared(pthread_mutexattr_t *attr, int *pshared);
+int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *attr, int *prioceiling);
+int pthread_mutexattr_setprioceiling(const pthread_mutexattr_t *attr, int prioceiling);
+int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, int *protocol);
+int pthread_mutexattr_setprotocol(const pthread_mutexattr_t *attr, int protocol);
+
/* pthread condition interface */
int pthread_condattr_destroy(pthread_condattr_t *attr);
@@ -265,6 +284,11 @@ int pthread_barrier_init(pthread_barrier_t *barrier,
int pthread_barrier_wait(pthread_barrier_t *barrier);
+int pthread_setspecific(pthread_key_t key, const void *value);
+void *pthread_getspecific(pthread_key_t key);
+int pthread_key_create(pthread_key_t *key, void (*destructor)(void *));
+int pthread_key_delete(pthread_key_t key);
+
#ifdef __cplusplus
}
#endif
diff --git a/components/libc/pthreads/pthread_attr.c b/components/libc/posix/pthreads/pthread_attr.c
index 2294599bf3..047e06e21d 100644
--- a/components/libc/pthreads/pthread_attr.c
+++ b/components/libc/posix/pthreads/pthread_attr.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -16,7 +16,7 @@
#define DEFAULT_STACK_SIZE 2048
#define DEFAULT_PRIORITY (RT_THREAD_PRIORITY_MAX/2 + RT_THREAD_PRIORITY_MAX/4)
-const pthread_attr_t pthread_default_attr =
+const pthread_attr_t pthread_default_attr =
{
0, /* stack base */
DEFAULT_STACK_SIZE, /* stack size */
@@ -189,6 +189,26 @@ int pthread_attr_getguardsize(pthread_attr_t const *attr, size_t *guard_size)
}
RTM_EXPORT(pthread_attr_getguardsize);
+int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched)
+{
+ RT_ASSERT(attr != RT_NULL);
+
+ attr->inheritsched = inheritsched;
+
+ return 0;
+}
+RTM_EXPORT(pthread_attr_setinheritsched);
+
+int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritsched)
+{
+ RT_ASSERT(attr != RT_NULL);
+
+ *inheritsched = attr->inheritsched;
+
+ return 0;
+}
+RTM_EXPORT(pthread_attr_getinheritsched);
+
int pthread_attr_setscope(pthread_attr_t *attr, int scope)
{
if (scope == PTHREAD_SCOPE_SYSTEM)
@@ -200,7 +220,7 @@ int pthread_attr_setscope(pthread_attr_t *attr, int scope)
}
RTM_EXPORT(pthread_attr_setscope);
-int pthread_attr_getscope(pthread_attr_t const *attr)
+int pthread_attr_getscope(pthread_attr_t const *attr, int *scope)
{
return PTHREAD_SCOPE_SYSTEM;
}
diff --git a/components/libc/pthreads/pthread_barrier.c b/components/libc/posix/pthreads/pthread_barrier.c
index d76fe7f13f..1a5b7fa3f9 100644
--- a/components/libc/pthreads/pthread_barrier.c
+++ b/components/libc/posix/pthreads/pthread_barrier.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/pthreads/pthread_cond.c b/components/libc/posix/pthreads/pthread_cond.c
index 38dc697469..9bf49704ed 100644
--- a/components/libc/pthreads/pthread_cond.c
+++ b/components/libc/posix/pthreads/pthread_cond.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -84,10 +84,10 @@ int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
rt_snprintf(cond_name, sizeof(cond_name), "cond%02d", cond_num++);
- if (attr == RT_NULL) /* use default value */
- cond->attr = PTHREAD_PROCESS_PRIVATE;
- else
- cond->attr = *attr;
+ if (attr == RT_NULL) /* use default value */
+ cond->attr = PTHREAD_PROCESS_PRIVATE;
+ else
+ cond->attr = *attr;
result = rt_sem_init(&cond->sem, cond_name, 0, RT_IPC_FLAG_FIFO);
if (result != RT_EOK)
@@ -222,7 +222,7 @@ int pthread_cond_timedwait(pthread_cond_t *cond,
int timeout;
rt_err_t result;
- timeout = clock_time_to_tick(abstime);
+ timeout = rt_timespec_to_tick(abstime);
result = _pthread_cond_timedwait(cond, mutex, timeout);
if (result == RT_EOK)
return 0;
diff --git a/components/libc/pthreads/pthread_internal.h b/components/libc/posix/pthreads/pthread_internal.h
index a6706ca091..03db46acb6 100644
--- a/components/libc/pthreads/pthread_internal.h
+++ b/components/libc/posix/pthreads/pthread_internal.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -13,6 +13,7 @@
#include <rtthread.h>
#include <pthread.h>
+#include <sys/time.h>
struct _pthread_cleanup
{
@@ -62,10 +63,4 @@ typedef struct _pthread_data _pthread_data_t;
_pthread_data_t *_pthread_get_data(pthread_t thread);
-int clock_time_to_tick(const struct timespec *time);
-
-void posix_mq_system_init(void);
-void posix_sem_system_init(void);
-void pthread_key_system_init(void);
-
#endif
diff --git a/components/libc/pthreads/pthread_mutex.c b/components/libc/posix/pthreads/pthread_mutex.c
index 8f96531782..1010c06959 100644
--- a/components/libc/pthreads/pthread_mutex.c
+++ b/components/libc/posix/pthreads/pthread_mutex.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -121,7 +121,7 @@ int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
mutex->attr = *attr;
/* init mutex lock */
- result = rt_mutex_init(&(mutex->lock), name, RT_IPC_FLAG_FIFO);
+ result = rt_mutex_init(&(mutex->lock), name, RT_IPC_FLAG_PRIO);
if (result != RT_EOK)
return EINVAL;
@@ -211,7 +211,7 @@ int pthread_mutex_unlock(pthread_mutex_t *mutex)
result = rt_mutex_release(&(mutex->lock));
if (result == RT_EOK)
return 0;
-
+
return EINVAL;
}
RTM_EXPORT(pthread_mutex_unlock);
@@ -246,3 +246,45 @@ int pthread_mutex_trylock(pthread_mutex_t *mutex)
return EBUSY;
}
RTM_EXPORT(pthread_mutex_trylock);
+
+int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *attr, int *prioceiling)
+{
+ return EINVAL;
+}
+RTM_EXPORT(pthread_mutexattr_getprioceiling);
+
+int pthread_mutexattr_setprioceiling(const pthread_mutexattr_t *attr, int prioceiling)
+{
+ return EINVAL;
+}
+RTM_EXPORT(pthread_mutexattr_setprioceiling);
+
+int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, int *protocol)
+{
+ return EINVAL;
+}
+RTM_EXPORT(pthread_mutexattr_getprotocol);
+
+int pthread_mutexattr_setprotocol(const pthread_mutexattr_t *attr, int protocol)
+{
+ return EINVAL;
+}
+RTM_EXPORT(pthread_mutexattr_setprotocol);
+
+int pthread_mutex_getprioceiling(const pthread_mutex_t *mutex, int *prioceiling)
+{
+ return pthread_mutexattr_getprioceiling(&mutex->attr, prioceiling);
+}
+RTM_EXPORT(pthread_mutex_getprioceiling);
+
+int pthread_mutex_setprioceiling(pthread_mutex_t *mutex, int prioceiling, int *old_ceiling)
+{
+ *old_ceiling = pthread_mutexattr_getprioceiling(&mutex->attr, old_ceiling);
+ if(*old_ceiling != 0)
+ {
+ return EINVAL;
+ }
+
+ return pthread_mutexattr_setprioceiling(&mutex->attr, prioceiling);
+}
+RTM_EXPORT(pthread_mutex_setprioceiling);
diff --git a/components/libc/pthreads/pthread_rwlock.c b/components/libc/posix/pthreads/pthread_rwlock.c
index 64a0e221b4..1c2fe19f5f 100644
--- a/components/libc/pthreads/pthread_rwlock.c
+++ b/components/libc/posix/pthreads/pthread_rwlock.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -60,7 +60,7 @@ int pthread_rwlock_init(pthread_rwlock_t *rwlock,
pthread_mutex_init(&(rwlock->rw_mutex), NULL);
pthread_cond_init(&(rwlock->rw_condreaders), NULL);
pthread_cond_init(&(rwlock->rw_condwriters), NULL);
-
+
rwlock->rw_nwaitwriters = 0;
rwlock->rw_nwaitreaders = 0;
rwlock->rw_refcount = 0;
@@ -117,7 +117,7 @@ int pthread_rwlock_destroy (pthread_rwlock_t *rwlock)
pthread_mutex_unlock(&rwlock->rw_mutex);
if (result == 0)
pthread_mutex_destroy(&rwlock->rw_mutex);
-
+
return result;
}
RTM_EXPORT(pthread_rwlock_destroy);
@@ -234,7 +234,7 @@ int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock,
result = pthread_cond_timedwait(&rwlock->rw_condwriters, &rwlock->rw_mutex, abstime);
/* rw_mutex should have been taken again when returned from waiting */
rwlock->rw_nwaitwriters--;
-
+
if (result != 0)
break;
}
@@ -324,7 +324,7 @@ int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
result = pthread_cond_wait(&rwlock->rw_condwriters, &rwlock->rw_mutex);
/* rw_mutex should have been taken again when returned from waiting */
rwlock->rw_nwaitwriters--;
-
+
if (result != 0)
break;
}
diff --git a/components/libc/pthreads/pthread_spin.c b/components/libc/posix/pthreads/pthread_spin.c
index b31f4f6393..3f3dc1593c 100644
--- a/components/libc/pthreads/pthread_spin.c
+++ b/components/libc/posix/pthreads/pthread_spin.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/pthreads/pthread_tls.c b/components/libc/posix/pthreads/pthread_tls.c
index 4b97d796d9..041318666c 100644
--- a/components/libc/pthreads/pthread_tls.c
+++ b/components/libc/posix/pthreads/pthread_tls.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -13,10 +13,13 @@
_pthread_key_data_t _thread_keys[PTHREAD_KEY_MAX];
-void pthread_key_system_init()
+/* initialize key area */
+static int pthread_key_system_init(void)
{
rt_memset(&_thread_keys[0], 0, sizeof(_thread_keys));
+ return 0;
}
+INIT_COMPONENT_EXPORT(pthread_key_system_init);
void *pthread_getspecific(pthread_key_t key)
{
diff --git a/components/libc/pthreads/sched.c b/components/libc/posix/pthreads/sched.c
index a1bf50985e..833d70e8f0 100644
--- a/components/libc/pthreads/sched.c
+++ b/components/libc/posix/pthreads/sched.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -40,3 +40,18 @@ int sched_setscheduler(pid_t pid, int policy)
return EOPNOTSUPP;
}
RTM_EXPORT(sched_setscheduler);
+
+int sched_rr_get_interval(pid_t pid, struct timespec *tp)
+{
+ if(pid != 0)
+ {
+ return EINVAL;
+ }
+
+ rt_set_errno(-EINVAL);
+
+ /* course model, don't support */
+ // TODO
+ return -1;
+}
+RTM_EXPORT(sched_rr_get_interval);
diff --git a/components/libc/pthreads/sched.h b/components/libc/posix/pthreads/sched.h
index dbaf66edc2..a343eaddad 100644
--- a/components/libc/pthreads/sched.h
+++ b/components/libc/posix/pthreads/sched.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -31,6 +31,7 @@ extern "C"
int sched_yield(void);
int sched_get_priority_min(int policy);
int sched_get_priority_max(int policy);
+int sched_rr_get_interval(pid_t pid, struct timespec *tp);
int sched_setscheduler(pid_t pid, int policy);
#ifdef __cplusplus
diff --git a/components/libc/posix/readme.md b/components/libc/posix/readme.md
new file mode 100644
index 0000000000..9683a02a6a
--- /dev/null
+++ b/components/libc/posix/readme.md
@@ -0,0 +1,11 @@
+This folder provides functions that are not part of the standard C library but are part of the POSIX.1 (IEEE Standard 1003.1) standard.
+
+
+
+## NOTE
+
+1. For consistency of compilation results across the different of platforms(gcc, keil, iar) , use:
+ - `#include <sys/time.h>` to instead of `#include <time.h>`
+ - `#include <sys/errno.h>` to instead of `#include <errno.h>`
+ - `#include <sys/signal.h>` to instead of `#include <signal.h>`
+
diff --git a/components/libc/mmap/SConscript b/components/libc/posix/signal/SConscript
index 1a36a15710..9c712fa694 100644
--- a/components/libc/mmap/SConscript
+++ b/components/libc/posix/signal/SConscript
@@ -6,8 +6,8 @@ cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp')
CPPPATH = [cwd]
-group = DefineGroup('libc', src,
- depend = ['RT_USING_DFS', 'RT_USING_POSIX_MMAP'],
+group = DefineGroup('POSIX', src,
+ depend = ['RT_USING_SIGNALS', 'RT_USING_PTHREADS'],
CPPPATH = CPPPATH)
Return('group')
diff --git a/components/libc/signal/posix_signal.c b/components/libc/posix/signal/posix_signal.c
index c0dd90e637..c87bc6104f 100644
--- a/components/libc/signal/posix_signal.c
+++ b/components/libc/posix/signal/posix_signal.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -7,12 +7,15 @@
* Date Author Notes
* 2017/10/1 Bernard The first version
*/
+
#include <rthw.h>
#include <rtthread.h>
-#include <time.h>
+#include <sys/time.h>
+#include <sys/errno.h>
#include "posix_signal.h"
+
#define sig_valid(sig_no) (sig_no >= 0 && sig_no < RT_SIG_MAX)
void (*signal(int sig, void (*func)(int))) (int)
@@ -52,6 +55,35 @@ int sigprocmask (int how, const sigset_t *set, sigset_t *oset)
return 0;
}
+int sigpending (sigset_t *set)
+{
+ sigprocmask(SIG_SETMASK, RT_NULL, set);
+ return 0;
+}
+
+int sigsuspend (const sigset_t *set)
+{
+ int ret = 0;
+ sigset_t origin_set;
+ sigset_t suspend_set;
+ siginfo_t info; /* unless paremeter */
+
+ /* get the origin signal information */
+ sigpending(&origin_set);
+
+ /* set the new signal information */
+ sigprocmask(SIG_BLOCK, set, RT_NULL);
+ sigpending(&suspend_set);
+
+ ret = rt_signal_wait(&suspend_set, &info, RT_WAITING_FOREVER);
+
+ /* restore the original sigprocmask */
+ sigprocmask(SIG_UNBLOCK, (sigset_t *)0xffffUL, RT_NULL);
+ sigprocmask(SIG_BLOCK, &origin_set, RT_NULL);
+
+ return ret;
+}
+
int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
{
rt_sighandler_t old = RT_NULL;
@@ -72,19 +104,15 @@ int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
return 0;
}
-int sigtimedwait(const sigset_t *set, siginfo_t *info,
- const struct timespec *timeout)
+int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout)
{
int ret = 0;
int tick = RT_WAITING_FOREVER;
-#ifdef RT_USING_PTHREADS
if (timeout)
{
- extern int clock_time_to_tick(const struct timespec *time);
- tick = clock_time_to_tick(timeout);
+ tick = rt_timespec_to_tick(timeout);
}
-#endif
ret = rt_signal_wait(set, info, tick);
if (ret == 0) return 0;
@@ -114,3 +142,11 @@ int raise(int sig)
return 0;
}
+#include <sys/types.h>
+int sigqueue (pid_t pid, int signo, const union sigval value)
+{
+ /* no support, signal queue */
+
+ return -1;
+}
+
diff --git a/components/libc/signal/posix_signal.h b/components/libc/posix/signal/posix_signal.h
index 896d6b6da4..f04b54c5f8 100644
--- a/components/libc/signal/posix_signal.h
+++ b/components/libc/posix/signal/posix_signal.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -15,7 +15,6 @@
extern "C" {
#endif
-#include <rtthread.h>
#include <sys/signal.h>
enum rt_signal_value{
diff --git a/components/libc/pthreads/SConscript b/components/libc/pthreads/SConscript
deleted file mode 100644
index 767b406d4c..0000000000
--- a/components/libc/pthreads/SConscript
+++ /dev/null
@@ -1,22 +0,0 @@
-from building import *
-from utils import VersionCmp
-
-cwd = GetCurrentDir()
-src = Glob('*.c')
-CPPPATH = [cwd]
-CPPDEFINES = []
-
-# only enable POSIX.1b-1993 Real-time extensions
-libc_ver = GetDepend('LIBC_VERSION')
-try:
- ver = libc_ver.split(' ')
- ver = ver[1]
- if VersionCmp(ver, "2.5.0") == 1:
- CPPDEFINES = ['_POSIX_C_SOURCE=199309L']
-except :
- pass
-
-group = DefineGroup('libc', src,
- depend = ['RT_USING_PTHREADS', 'RT_USING_LIBC'], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
-
-Return('group')
diff --git a/components/libc/signal/SConscript b/components/libc/signal/SConscript
deleted file mode 100644
index f07ff58f6e..0000000000
--- a/components/libc/signal/SConscript
+++ /dev/null
@@ -1,13 +0,0 @@
-# RT-Thread building script for component
-
-from building import *
-
-cwd = GetCurrentDir()
-src = Glob('*.c') + Glob('*.cpp')
-CPPPATH = [cwd]
-
-group = DefineGroup('libc', src,
- depend = ['RT_USING_SIGNALS', 'RT_USING_PTHREADS', 'RT_USING_LIBC'],
- CPPPATH = CPPPATH)
-
-Return('group')
diff --git a/components/libc/termios/SConscript b/components/libc/termios/SConscript
deleted file mode 100644
index 381eb5ad8b..0000000000
--- a/components/libc/termios/SConscript
+++ /dev/null
@@ -1,13 +0,0 @@
-# RT-Thread building script for component
-
-from building import *
-
-cwd = GetCurrentDir()
-src = Glob('*.c') + Glob('*.cpp')
-CPPPATH = [cwd]
-
-group = DefineGroup('libc', src,
- depend = ['RT_USING_LIBC', 'RT_USING_POSIX', 'RT_USING_POSIX_TERMIOS'],
- CPPPATH = CPPPATH)
-
-Return('group')
diff --git a/components/libc/time/clock_time.c b/components/libc/time/clock_time.c
deleted file mode 100644
index 83b3b916ca..0000000000
--- a/components/libc/time/clock_time.c
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2012-12-08 Bernard fix the issue of _timevalue.tv_usec initialization,
- * which found by Rob <[email protected]>
- */
-
-#include <rtthread.h>
-#include <pthread.h>
-
-#include "clock_time.h"
-
-static struct timeval _timevalue;
-int clock_time_system_init()
-{
- time_t time;
- rt_tick_t tick;
- rt_device_t device;
-
- time = 0;
- device = rt_device_find("rtc");
- if (device != RT_NULL)
- {
- /* get realtime seconds */
- rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time);
- }
-
- /* get tick */
- tick = rt_tick_get();
-
- _timevalue.tv_usec = (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK;
- _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1;
-
- return 0;
-}
-INIT_COMPONENT_EXPORT(clock_time_system_init);
-
-int clock_time_to_tick(const struct timespec *time)
-{
- int tick;
- int nsecond, second;
- struct timespec tp;
-
- RT_ASSERT(time != RT_NULL);
-
- tick = RT_WAITING_FOREVER;
- if (time != NULL)
- {
- /* get current tp */
- clock_gettime(CLOCK_REALTIME, &tp);
-
- if ((time->tv_nsec - tp.tv_nsec) < 0)
- {
- nsecond = NANOSECOND_PER_SECOND - (tp.tv_nsec - time->tv_nsec);
- second = time->tv_sec - tp.tv_sec - 1;
- }
- else
- {
- nsecond = time->tv_nsec - tp.tv_nsec;
- second = time->tv_sec - tp.tv_sec;
- }
-
- tick = second * RT_TICK_PER_SECOND + nsecond * RT_TICK_PER_SECOND / NANOSECOND_PER_SECOND;
- if (tick < 0) tick = 0;
- }
-
- return tick;
-}
-RTM_EXPORT(clock_time_to_tick);
-
-int clock_getres(clockid_t clockid, struct timespec *res)
-{
- int ret = 0;
-
- if (res == RT_NULL)
- {
- rt_set_errno(EINVAL);
- return -1;
- }
-
- switch (clockid)
- {
- case CLOCK_REALTIME:
- res->tv_sec = 0;
- res->tv_nsec = NANOSECOND_PER_SECOND/RT_TICK_PER_SECOND;
- break;
-
-#ifdef RT_USING_CPUTIME
- case CLOCK_CPUTIME_ID:
- res->tv_sec = 0;
- res->tv_nsec = clock_cpu_getres();
- break;
-#endif
-
- default:
- ret = -1;
- rt_set_errno(EINVAL);
- break;
- }
-
- return ret;
-}
-RTM_EXPORT(clock_getres);
-
-int clock_gettime(clockid_t clockid, struct timespec *tp)
-{
- int ret = 0;
-
- if (tp == RT_NULL)
- {
- rt_set_errno(EINVAL);
- return -1;
- }
-
- switch (clockid)
- {
- case CLOCK_REALTIME:
- {
- /* get tick */
- int tick = rt_tick_get();
-
- tp->tv_sec = _timevalue.tv_sec + tick / RT_TICK_PER_SECOND;
- tp->tv_nsec = (_timevalue.tv_usec + (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK) * 1000;
- }
- break;
-
-#ifdef RT_USING_CPUTIME
- case CLOCK_CPUTIME_ID:
- {
- float unit = 0;
- long long cpu_tick;
-
- unit = clock_cpu_getres();
- cpu_tick = clock_cpu_gettime();
-
- tp->tv_sec = ((int)(cpu_tick * unit)) / NANOSECOND_PER_SECOND;
- tp->tv_nsec = ((int)(cpu_tick * unit)) % NANOSECOND_PER_SECOND;
- }
- break;
-#endif
- default:
- rt_set_errno(EINVAL);
- ret = -1;
- }
-
- return ret;
-}
-RTM_EXPORT(clock_gettime);
-
-int clock_settime(clockid_t clockid, const struct timespec *tp)
-{
- int second;
- rt_tick_t tick;
- rt_device_t device;
-
- if ((clockid != CLOCK_REALTIME) || (tp == RT_NULL))
- {
- rt_set_errno(EINVAL);
-
- return -1;
- }
-
- /* get second */
- second = tp->tv_sec;
- /* get tick */
- tick = rt_tick_get();
-
- /* update timevalue */
- _timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK;
- _timevalue.tv_sec = second - tick/RT_TICK_PER_SECOND - 1;
-
- /* update for RTC device */
- device = rt_device_find("rtc");
- if (device != RT_NULL)
- {
- /* set realtime seconds */
- rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second);
- }
- else
- return -1;
-
- return 0;
-}
-RTM_EXPORT(clock_settime);
diff --git a/components/libc/time/clock_time.h b/components/libc/time/clock_time.h
deleted file mode 100644
index 16b2306f4b..0000000000
--- a/components/libc/time/clock_time.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017-12-31 Bernard the first version
- */
-
-#ifndef CLOCK_TIME_H__
-#define CLOCK_TIME_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* posix clock and timer */
-#define MILLISECOND_PER_SECOND 1000UL
-#define MICROSECOND_PER_SECOND 1000000UL
-#define NANOSECOND_PER_SECOND 1000000000UL
-
-#define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / RT_TICK_PER_SECOND)
-#define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND)
-#define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND)
-
-#ifndef CLOCK_REALTIME
-#define CLOCK_REALTIME 1
-#endif
-
-#define CLOCK_CPUTIME_ID 2
-
-#ifndef CLOCK_PROCESS_CPUTIME_ID
-#define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID
-#endif
-#ifndef CLOCK_THREAD_CPUTIME_ID
-#define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID
-#endif
-
-#ifndef CLOCK_MONOTONIC
-#define CLOCK_MONOTONIC 4
-#endif
-
-int clock_getres (clockid_t clockid, struct timespec *res);
-int clock_gettime (clockid_t clockid, struct timespec *tp);
-int clock_settime (clockid_t clockid, const struct timespec *tp);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/components/libc/time/posix_sleep.c b/components/libc/time/posix_sleep.c
deleted file mode 100644
index e50bda7d4a..0000000000
--- a/components/libc/time/posix_sleep.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2020-12-16 Meco Man add usleep
- */
-#include <rtthread.h>
-#include <rthw.h>
-#include <unistd.h>
-
-unsigned int sleep(unsigned int seconds)
-{
- rt_tick_t delta_tick;
-
- delta_tick = rt_tick_get();
- rt_thread_delay(seconds * RT_TICK_PER_SECOND);
- delta_tick = rt_tick_get() - delta_tick;
-
- return seconds - delta_tick/RT_TICK_PER_SECOND;
-}
-
-int usleep(useconds_t usec)
-{
- rt_thread_mdelay(usec / 1000u);
- rt_hw_us_delay(usec % 1000u);
- return 0;
-}