diff options
| author | Wayne Lin <[email protected]> | 2022-01-25 18:53:52 +0800 |
|---|---|---|
| committer | Wayne Lin <[email protected]> | 2022-01-25 18:53:52 +0800 |
| commit | c95c296e9915a38a666ae1a2575c2a4d0ba1d376 (patch) | |
| tree | c6e5a1ffe4ceb997e853ba0c3daffc9dc60c8b79 /components/libc | |
| parent | f7ba146a01fcf23a2b06a141d1b1a56cb27b878c (diff) | |
| parent | 32a5668593c578b85560338c29d76f3a252c8dbc (diff) | |
Merge branch 'master' of https://github.com/RT-Thread/rt-thread into nuvoton
# Conflicts:
# bsp/gd32/gd32107c-eval/rtconfig.h
Diffstat (limited to 'components/libc')
| -rw-r--r-- | components/libc/Kconfig | 10 | ||||
| -rw-r--r-- | components/libc/compilers/armlibc/libc_syms.c | 43 | ||||
| -rw-r--r-- | components/libc/compilers/common/extension/SConscript (renamed from components/libc/compilers/common/nogcc/SConscript) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/common/extension/fcntl.h (renamed from components/libc/compilers/common/nogcc/fcntl.h) | 4 | ||||
| -rw-r--r-- | components/libc/compilers/common/extension/readme.md | 4 | ||||
| -rw-r--r-- | components/libc/compilers/common/extension/sys/errno.h (renamed from components/libc/compilers/common/nogcc/sys/errno.h) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/common/extension/sys/select.h (renamed from components/libc/compilers/common/nogcc/sys/select.h) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/common/extension/sys/stat.h (renamed from components/libc/compilers/common/nogcc/sys/stat.h) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/common/extension/sys/types.h (renamed from components/libc/compilers/common/nogcc/sys/types.h) | 2 | ||||
| -rw-r--r-- | components/libc/compilers/common/extension/sys/unistd.h (renamed from components/libc/compilers/common/nogcc/sys/unistd.h) | 3 | ||||
| -rw-r--r-- | components/libc/compilers/common/extension/unistd.h (renamed from components/libc/compilers/common/nogcc/unistd.h) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/common/nogcc/readme.md | 3 | ||||
| -rw-r--r-- | components/libc/compilers/common/sys/ioctl.h | 77 | ||||
| -rw-r--r-- | components/libc/compilers/common/sys/signal.h | 38 | ||||
| -rw-r--r-- | components/libc/compilers/common/sys/time.h | 29 | ||||
| -rw-r--r-- | components/libc/compilers/common/time.c | 266 | ||||
| -rw-r--r-- | components/libc/compilers/gcc/newlib/legacy/SConscript | 15 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/README.md (renamed from components/libc/compilers/gcc/newlib/README.md) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/SConscript (renamed from components/libc/compilers/gcc/newlib/SConscript) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/fcntl.h (renamed from components/libc/compilers/gcc/newlib/fcntl.h) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/legacy/SConscript (renamed from components/libc/compilers/gcc/SConscript) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/legacy/_select/SConscript (renamed from components/libc/compilers/gcc/newlib/legacy/_select/SConscript) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/legacy/_select/readme.md (renamed from components/libc/compilers/gcc/newlib/legacy/_select/readme.md) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/legacy/_select/sys/select.h (renamed from components/libc/compilers/gcc/newlib/legacy/_select/sys/select.h) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/machine/time.h (renamed from components/libc/compilers/gcc/newlib/machine/time.h) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/syscalls.c (renamed from components/libc/compilers/gcc/newlib/syscalls.c) | 0 | ||||
| -rw-r--r-- | components/libc/libdl/SConscript | 14 | ||||
| -rw-r--r-- | components/libc/posix-info.txt | 324 | ||||
| -rw-r--r-- | components/libc/posix/Kconfig | 15 | ||||
| -rw-r--r-- | components/libc/posix/delay/delay.h | 1 | ||||
| -rw-r--r-- | components/libc/posix/io/README.md | 10 | ||||
| -rw-r--r-- | components/libc/posix/io/SConscript | 15 | ||||
| -rw-r--r-- | components/libc/posix/io/aio/aio.c | 7 | ||||
| -rw-r--r-- | components/libc/posix/io/mman/mman.c | 4 | ||||
| -rw-r--r-- | components/libc/posix/io/poll/SConscript | 5 | ||||
| -rw-r--r-- | components/libc/posix/io/poll/select.c (renamed from components/libc/posix/io/select.c) | 0 | ||||
| -rw-r--r-- | components/libc/posix/io/stdio/SConscript | 22 | ||||
| -rw-r--r-- | components/libc/posix/io/stdio/libc.c (renamed from components/libc/posix/io/libc.c) | 26 | ||||
| -rw-r--r-- | components/libc/posix/io/stdio/libc.h (renamed from components/libc/posix/io/libc.h) | 0 | ||||
| -rw-r--r-- | components/libc/posix/io/termios/termios.c | 2 | ||||
| -rw-r--r-- | components/libc/posix/libdl/SConscript | 12 | ||||
| -rw-r--r-- | components/libc/posix/libdl/arch/arm.c (renamed from components/libc/libdl/arch/arm.c) | 0 | ||||
| -rw-r--r-- | components/libc/posix/libdl/arch/riscv.c (renamed from components/libc/libdl/arch/riscv.c) | 0 | ||||
| -rw-r--r-- | components/libc/posix/libdl/arch/x86.c (renamed from components/libc/libdl/arch/x86.c) | 0 | ||||
| -rw-r--r-- | components/libc/posix/libdl/dlclose.c (renamed from components/libc/libdl/dlclose.c) | 0 | ||||
| -rw-r--r-- | components/libc/posix/libdl/dlelf.c (renamed from components/libc/libdl/dlelf.c) | 0 | ||||
| -rw-r--r-- | components/libc/posix/libdl/dlelf.h (renamed from components/libc/libdl/dlelf.h) | 0 | ||||
| -rw-r--r-- | components/libc/posix/libdl/dlerror.c (renamed from components/libc/libdl/dlerror.c) | 0 | ||||
| -rw-r--r-- | components/libc/posix/libdl/dlfcn.h (renamed from components/libc/libdl/dlfcn.h) | 0 | ||||
| -rw-r--r-- | components/libc/posix/libdl/dlmodule.c (renamed from components/libc/libdl/dlmodule.c) | 18 | ||||
| -rw-r--r-- | components/libc/posix/libdl/dlmodule.h (renamed from components/libc/libdl/dlmodule.h) | 0 | ||||
| -rw-r--r-- | components/libc/posix/libdl/dlopen.c (renamed from components/libc/libdl/dlopen.c) | 0 | ||||
| -rw-r--r-- | components/libc/posix/libdl/dlsym.c (renamed from components/libc/libdl/dlsym.c) | 0 | ||||
| -rw-r--r-- | components/libc/posix/libdl/dlsyms.c (renamed from components/libc/compilers/gcc/newlib/libc_syms.c) | 0 | ||||
| -rw-r--r-- | components/libc/posix/pthreads/pthread.h | 4 | ||||
| -rw-r--r-- | components/libc/posix/readme.md | 5 | ||||
| -rw-r--r-- | components/libc/posix/signal/posix_signal.c | 40 | ||||
| -rw-r--r-- | components/libc/posix/src/SConscript | 16 | ||||
| -rw-r--r-- | components/libc/posix/src/unistd.c | 41 |
59 files changed, 871 insertions, 204 deletions
diff --git a/components/libc/Kconfig b/components/libc/Kconfig index 0556cf6183..71547e7970 100644 --- a/components/libc/Kconfig +++ b/components/libc/Kconfig @@ -1,15 +1,5 @@ menu "POSIX layer and C standard library" -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 - config RT_LIBC_DEFAULT_TIMEZONE int "Set the default time zone (UTC+)" range -12 12 diff --git a/components/libc/compilers/armlibc/libc_syms.c b/components/libc/compilers/armlibc/libc_syms.c deleted file mode 100644 index 2b370a25a6..0000000000 --- a/components/libc/compilers/armlibc/libc_syms.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2006-2021, 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 <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); - -/* 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/common/nogcc/SConscript b/components/libc/compilers/common/extension/SConscript index dbc26ac177..dbc26ac177 100644 --- a/components/libc/compilers/common/nogcc/SConscript +++ b/components/libc/compilers/common/extension/SConscript diff --git a/components/libc/compilers/common/nogcc/fcntl.h b/components/libc/compilers/common/extension/fcntl.h index 83c3ec0b6b..ac642abcbb 100644 --- a/components/libc/compilers/common/nogcc/fcntl.h +++ b/components/libc/compilers/common/extension/fcntl.h @@ -11,7 +11,7 @@ #ifndef __FCNTL_H__ #define __FCNTL_H__ -#include <sys/types.h> +#include "sys/types.h" #define O_RDONLY 00 #define O_WRONLY 01 @@ -66,6 +66,6 @@ int open(const char *file, int flags, ...); int fcntl(int fildes, int cmd, ...); -int creat(const char *, mode_t); +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/nogcc/sys/errno.h b/components/libc/compilers/common/extension/sys/errno.h index d53ce4b386..d53ce4b386 100644 --- a/components/libc/compilers/common/nogcc/sys/errno.h +++ b/components/libc/compilers/common/extension/sys/errno.h diff --git a/components/libc/compilers/common/nogcc/sys/select.h b/components/libc/compilers/common/extension/sys/select.h index 44f9b4ed91..44f9b4ed91 100644 --- a/components/libc/compilers/common/nogcc/sys/select.h +++ b/components/libc/compilers/common/extension/sys/select.h diff --git a/components/libc/compilers/common/nogcc/sys/stat.h b/components/libc/compilers/common/extension/sys/stat.h index 107c15decf..107c15decf 100644 --- a/components/libc/compilers/common/nogcc/sys/stat.h +++ b/components/libc/compilers/common/extension/sys/stat.h diff --git a/components/libc/compilers/common/nogcc/sys/types.h b/components/libc/compilers/common/extension/sys/types.h index 32b2493c95..85cd4fea21 100644 --- a/components/libc/compilers/common/nogcc/sys/types.h +++ b/components/libc/compilers/common/extension/sys/types.h @@ -28,6 +28,8 @@ typedef signed int ssize_t; /* Used for a count of bytes or an error #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) */ diff --git a/components/libc/compilers/common/nogcc/sys/unistd.h b/components/libc/compilers/common/extension/sys/unistd.h index 650c87dc18..29ec3f70c4 100644 --- a/components/libc/compilers/common/nogcc/sys/unistd.h +++ b/components/libc/compilers/common/extension/sys/unistd.h @@ -19,10 +19,13 @@ #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); diff --git a/components/libc/compilers/common/nogcc/unistd.h b/components/libc/compilers/common/extension/unistd.h index 4dd71c842e..4dd71c842e 100644 --- a/components/libc/compilers/common/nogcc/unistd.h +++ b/components/libc/compilers/common/extension/unistd.h diff --git a/components/libc/compilers/common/nogcc/readme.md b/components/libc/compilers/common/nogcc/readme.md deleted file mode 100644 index b10940d003..0000000000 --- a/components/libc/compilers/common/nogcc/readme.md +++ /dev/null @@ -1,3 +0,0 @@ -## Attentions - -This folder is "common" for toolchains excluding gcc.
\ No newline at end of file diff --git a/components/libc/compilers/common/sys/ioctl.h b/components/libc/compilers/common/sys/ioctl.h index d93c79115a..0b1edca699 100644 --- a/components/libc/compilers/common/sys/ioctl.h +++ b/components/libc/compilers/common/sys/ioctl.h @@ -11,35 +11,79 @@ #ifndef __SYS_IOCTL_H__ #define __SYS_IOCTL_H__ -#include <rtconfig.h> -#include <dfs_posix.h> - #ifdef _WIN32 #include <winsock.h> #endif -struct winsize { +struct winsize +{ unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }; -#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) ) +/* + * 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 -#if !defined (_WIN32) && !defined (__TASKING__) -#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0) -#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c)) -#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c)) -#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c)) +#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 @@ -67,18 +111,12 @@ struct winsize { #define TIOCMSET 0x5418 #define TIOCGSOFTCAR 0x5419 #define TIOCSSOFTCAR 0x541A -#ifndef FIONREAD -#define FIONREAD 0x541B -#endif #define TIOCINQ FIONREAD #define TIOCLINUX 0x541C #define TIOCCONS 0x541D #define TIOCGSERIAL 0x541E #define TIOCSSERIAL 0x541F #define TIOCPKT 0x5420 -#ifndef FIONBIO -#define FIONBIO 0x5421 -#endif #define TIOCNOTTY 0x5422 #define TIOCSETD 0x5423 #define TIOCGETD 0x5424 @@ -104,10 +142,6 @@ struct winsize { #define FIONCLEX 0x5450 #define FIOCLEX 0x5451 -#ifndef _WIN32 -#define FIOASYNC 0x5452 -#endif - #define TIOCSERCONFIG 0x5453 #define TIOCSERGWILD 0x5454 #define TIOCSERSWILD 0x5455 @@ -169,9 +203,6 @@ struct winsize { #define SIOCSPGRP 0x8902 #define FIOGETOWN 0x8903 #define SIOCGPGRP 0x8904 -#ifndef SIOCATMARK -#define SIOCATMARK 0x8905 -#endif #define SIOCGSTAMP 0x8906 #define SIOCGSTAMPNS 0x8907 diff --git a/components/libc/compilers/common/sys/signal.h b/components/libc/compilers/common/sys/signal.h index 9787958a37..041dd765b7 100644 --- a/components/libc/compilers/common/sys/signal.h +++ b/components/libc/compilers/common/sys/signal.h @@ -17,6 +17,19 @@ 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 @@ -62,6 +75,16 @@ struct sigaction 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 */ @@ -73,6 +96,15 @@ struct sigaction #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 @@ -100,6 +132,9 @@ int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) #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 @@ -133,6 +168,9 @@ int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) #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 diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index 758333796d..a3af31b20b 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2021, RT-Thread Development Team + * Copyright (c) 2006-2022, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -60,6 +60,16 @@ struct timespec time_t tv_sec; /* seconds */ long tv_nsec; /* and nanoseconds */ }; + +/* + * 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 stime(const time_t *t); @@ -68,6 +78,9 @@ 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); @@ -84,7 +97,7 @@ time_t time(time_t* t); int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); #endif /* RT_USING_POSIX_DELAY */ -#ifdef RT_USING_POSIX_CLOCK +#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 @@ -110,7 +123,9 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); #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); @@ -118,6 +133,16 @@ int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, s 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); diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 46bb0c1355..71755b8bbb 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -25,6 +25,10 @@ #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 @@ -489,7 +493,6 @@ RTM_EXPORT(difftime); RTM_EXPORT(strftime); #ifdef RT_USING_POSIX_DELAY -#include <delay.h> int nanosleep(const struct timespec *rqtp, struct timespec *rmtp) { sleep(rqtp->tv_sec); @@ -715,6 +718,267 @@ 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); + } +} + +/** + * @brief Create a per-process timer. + * + * This API does not accept SIGEV_THREAD as valid signal event notification + * type. + * + * 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 + */ +int timer_delete(timer_t timerid) +{ + struct timer_obj *timer = (struct timer_obj *)timerid; + + if (timer == RT_NULL) + { + rt_set_errno(EINVAL); + return -RT_ERROR; + } + + if (timer->status == ACTIVE) + { + timer->status = NOT_ACTIVE; + rt_timer_stop(&timer->timer); + } + + 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) + { + 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_timer_stop(&timer->timer); + } + + timer->status = NOT_ACTIVE; + return RT_EOK; + } + + /* 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) + { + rt_timer_stop(&timer->timer); + } + + 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 */ + + /* timezone */ #ifndef RT_LIBC_DEFAULT_TIMEZONE #define RT_LIBC_DEFAULT_TIMEZONE 8 diff --git a/components/libc/compilers/gcc/newlib/legacy/SConscript b/components/libc/compilers/gcc/newlib/legacy/SConscript deleted file mode 100644 index 4c815c49b8..0000000000 --- a/components/libc/compilers/gcc/newlib/legacy/SConscript +++ /dev/null @@ -1,15 +0,0 @@ -# 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/gcc/newlib/README.md b/components/libc/compilers/newlib/README.md index 4614375b45..4614375b45 100644 --- a/components/libc/compilers/gcc/newlib/README.md +++ b/components/libc/compilers/newlib/README.md diff --git a/components/libc/compilers/gcc/newlib/SConscript b/components/libc/compilers/newlib/SConscript index 8076a73727..8076a73727 100644 --- a/components/libc/compilers/gcc/newlib/SConscript +++ b/components/libc/compilers/newlib/SConscript diff --git a/components/libc/compilers/gcc/newlib/fcntl.h b/components/libc/compilers/newlib/fcntl.h index 847ae3d35b..847ae3d35b 100644 --- a/components/libc/compilers/gcc/newlib/fcntl.h +++ b/components/libc/compilers/newlib/fcntl.h diff --git a/components/libc/compilers/gcc/SConscript b/components/libc/compilers/newlib/legacy/SConscript index 4c815c49b8..4c815c49b8 100644 --- a/components/libc/compilers/gcc/SConscript +++ b/components/libc/compilers/newlib/legacy/SConscript diff --git a/components/libc/compilers/gcc/newlib/legacy/_select/SConscript b/components/libc/compilers/newlib/legacy/_select/SConscript index b7bd86a36c..b7bd86a36c 100644 --- a/components/libc/compilers/gcc/newlib/legacy/_select/SConscript +++ b/components/libc/compilers/newlib/legacy/_select/SConscript diff --git a/components/libc/compilers/gcc/newlib/legacy/_select/readme.md b/components/libc/compilers/newlib/legacy/_select/readme.md index 4ad9f21923..4ad9f21923 100644 --- a/components/libc/compilers/gcc/newlib/legacy/_select/readme.md +++ b/components/libc/compilers/newlib/legacy/_select/readme.md diff --git a/components/libc/compilers/gcc/newlib/legacy/_select/sys/select.h b/components/libc/compilers/newlib/legacy/_select/sys/select.h index 02fb77dd89..02fb77dd89 100644 --- a/components/libc/compilers/gcc/newlib/legacy/_select/sys/select.h +++ b/components/libc/compilers/newlib/legacy/_select/sys/select.h diff --git a/components/libc/compilers/gcc/newlib/machine/time.h b/components/libc/compilers/newlib/machine/time.h index 805b061aea..805b061aea 100644 --- a/components/libc/compilers/gcc/newlib/machine/time.h +++ b/components/libc/compilers/newlib/machine/time.h diff --git a/components/libc/compilers/gcc/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c index dcf26ccfb7..dcf26ccfb7 100644 --- a/components/libc/compilers/gcc/newlib/syscalls.c +++ b/components/libc/compilers/newlib/syscalls.c 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 index 76dabc2734..5c766d9509 100644 --- a/components/libc/posix/Kconfig +++ b/components/libc/posix/Kconfig @@ -49,6 +49,11 @@ config RT_USING_POSIX_CLOCK 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 @@ -60,6 +65,16 @@ if RT_USING_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/delay/delay.h b/components/libc/posix/delay/delay.h index 19492bdb45..eb0332e0cd 100644 --- a/components/libc/posix/delay/delay.h +++ b/components/libc/posix/delay/delay.h @@ -11,6 +11,7 @@ #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); 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 index bb45211ec0..e016836a9d 100644 --- a/components/libc/posix/io/SConscript +++ b/components/libc/posix/io/SConscript @@ -3,24 +3,9 @@ import os from building import * -src = [] cwd = GetCurrentDir() -CPPPATH = [cwd] group = [] -flag = False - -if GetDepend('RT_USING_POSIX_STDIO'): - src += ['libc.c'] - flag = True - -if GetDepend('RT_USING_POSIX_SELECT'): - src += ['select.c'] - flag = True - -if flag == True: - group = DefineGroup('POSIX', src, depend = [''], CPPPATH = CPPPATH) - list = os.listdir(cwd) for d in list: path = os.path.join(cwd, d) diff --git a/components/libc/posix/io/aio/aio.c b/components/libc/posix/io/aio/aio.c index 08ef4c634a..e12a7047c8 100644 --- a/components/libc/posix/io/aio/aio.c +++ b/components/libc/posix/io/aio/aio.c @@ -8,9 +8,12 @@ * 2017/12/30 Bernard The first version. */ -#include <stdint.h> +#include <rtthread.h> #include <rthw.h> -#include <dfs_posix.h> +#include <stdint.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/errno.h> #include "aio.h" struct rt_workqueue* aio_queue = NULL; diff --git a/components/libc/posix/io/mman/mman.c b/components/libc/posix/io/mman/mman.c index 827f2cbb14..d484b3ed7b 100644 --- a/components/libc/posix/io/mman/mman.c +++ b/components/libc/posix/io/mman/mman.c @@ -12,7 +12,9 @@ #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" diff --git a/components/libc/posix/io/poll/SConscript b/components/libc/posix/io/poll/SConscript index 39b321b6c5..7e7c0f55f7 100644 --- a/components/libc/posix/io/poll/SConscript +++ b/components/libc/posix/io/poll/SConscript @@ -7,7 +7,10 @@ src = [] CPPPATH = [cwd] if GetDepend('RT_USING_POSIX_POLL'): - src += ['poll.c'] + src += ['poll.c'] + +if GetDepend('RT_USING_POSIX_SELECT'): + src += ['select.c'] group = DefineGroup('POSIX', src, depend = [''], CPPPATH = CPPPATH) diff --git a/components/libc/posix/io/select.c b/components/libc/posix/io/poll/select.c index bac63258a5..bac63258a5 100644 --- a/components/libc/posix/io/select.c +++ b/components/libc/posix/io/poll/select.c 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/libc.c b/components/libc/posix/io/stdio/libc.c index e57749f1da..ebdc3a537b 100644 --- a/components/libc/posix/io/libc.c +++ b/components/libc/posix/io/stdio/libc.c @@ -15,9 +15,8 @@ #include <unistd.h> #include <fcntl.h> #include <sys/time.h> +#include <sys/errno.h> #include "libc.h" -#include <stdio.h> -#include <stdlib.h> int libc_system_init(void) { @@ -108,7 +107,7 @@ int libc_stdio_get_console(void) return -1; } -#else +#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) @@ -136,3 +135,24 @@ 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/posix/io/libc.h b/components/libc/posix/io/stdio/libc.h index 6b5dfd1fcc..6b5dfd1fcc 100644 --- a/components/libc/posix/io/libc.h +++ b/components/libc/posix/io/stdio/libc.h diff --git a/components/libc/posix/io/termios/termios.c b/components/libc/posix/io/termios/termios.c index 44e0e80853..8333b594bf 100644 --- a/components/libc/posix/io/termios/termios.c +++ b/components/libc/posix/io/termios/termios.c @@ -10,7 +10,7 @@ #include <stdlib.h> #include <string.h> -#include <dfs_posix.h> +#include <unistd.h> #include <sys/errno.h> #include "termios.h" 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 6a884bdb54..6a884bdb54 100644 --- a/components/libc/libdl/arch/arm.c +++ b/components/libc/posix/libdl/arch/arm.c diff --git a/components/libc/libdl/arch/riscv.c b/components/libc/posix/libdl/arch/riscv.c index c7c454e168..c7c454e168 100644 --- a/components/libc/libdl/arch/riscv.c +++ b/components/libc/posix/libdl/arch/riscv.c diff --git a/components/libc/libdl/arch/x86.c b/components/libc/posix/libdl/arch/x86.c index e7ad714a03..e7ad714a03 100644 --- a/components/libc/libdl/arch/x86.c +++ b/components/libc/posix/libdl/arch/x86.c diff --git a/components/libc/libdl/dlclose.c b/components/libc/posix/libdl/dlclose.c index 876a1576c8..876a1576c8 100644 --- a/components/libc/libdl/dlclose.c +++ b/components/libc/posix/libdl/dlclose.c diff --git a/components/libc/libdl/dlelf.c b/components/libc/posix/libdl/dlelf.c index 418ad7539a..418ad7539a 100644 --- a/components/libc/libdl/dlelf.c +++ b/components/libc/posix/libdl/dlelf.c diff --git a/components/libc/libdl/dlelf.h b/components/libc/posix/libdl/dlelf.h index 339e172bb4..339e172bb4 100644 --- a/components/libc/libdl/dlelf.h +++ b/components/libc/posix/libdl/dlelf.h diff --git a/components/libc/libdl/dlerror.c b/components/libc/posix/libdl/dlerror.c index de948eb16b..de948eb16b 100644 --- a/components/libc/libdl/dlerror.c +++ b/components/libc/posix/libdl/dlerror.c diff --git a/components/libc/libdl/dlfcn.h b/components/libc/posix/libdl/dlfcn.h index f5c9063f2f..f5c9063f2f 100644 --- a/components/libc/libdl/dlfcn.h +++ b/components/libc/posix/libdl/dlfcn.h diff --git a/components/libc/libdl/dlmodule.c b/components/libc/posix/libdl/dlmodule.c index 044c05a994..ffa23de82d 100644 --- a/components/libc/libdl/dlmodule.c +++ b/components/libc/posix/libdl/dlmodule.c @@ -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) { @@ -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); @@ -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) diff --git a/components/libc/libdl/dlmodule.h b/components/libc/posix/libdl/dlmodule.h index 183faca159..183faca159 100644 --- a/components/libc/libdl/dlmodule.h +++ b/components/libc/posix/libdl/dlmodule.h diff --git a/components/libc/libdl/dlopen.c b/components/libc/posix/libdl/dlopen.c index bcb57d78f0..bcb57d78f0 100644 --- a/components/libc/libdl/dlopen.c +++ b/components/libc/posix/libdl/dlopen.c diff --git a/components/libc/libdl/dlsym.c b/components/libc/posix/libdl/dlsym.c index f7c1c901fd..f7c1c901fd 100644 --- a/components/libc/libdl/dlsym.c +++ b/components/libc/posix/libdl/dlsym.c diff --git a/components/libc/compilers/gcc/newlib/libc_syms.c b/components/libc/posix/libdl/dlsyms.c index e6ca23b393..e6ca23b393 100644 --- a/components/libc/compilers/gcc/newlib/libc_syms.c +++ b/components/libc/posix/libdl/dlsyms.c diff --git a/components/libc/posix/pthreads/pthread.h b/components/libc/posix/pthreads/pthread.h index ad3259d2dc..c170ec49fd 100644 --- a/components/libc/posix/pthreads/pthread.h +++ b/components/libc/posix/pthreads/pthread.h @@ -185,6 +185,10 @@ 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); diff --git a/components/libc/posix/readme.md b/components/libc/posix/readme.md index df01047d6b..9683a02a6a 100644 --- a/components/libc/posix/readme.md +++ b/components/libc/posix/readme.md @@ -4,5 +4,8 @@ This folder provides functions that are not part of the standard C library but a ## NOTE -1. For consistency of compilation results across the different of platforms(gcc, keil, iar) , you better use ``#include <sys/time.h>`` to instead of ``#include <time.h>``. +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/posix/signal/posix_signal.c b/components/libc/posix/signal/posix_signal.c index ac8d2b1eef..c87bc6104f 100644 --- a/components/libc/posix/signal/posix_signal.c +++ b/components/libc/posix/signal/posix_signal.c @@ -55,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; @@ -75,8 +104,7 @@ 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; @@ -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/posix/src/SConscript b/components/libc/posix/src/SConscript deleted file mode 100644 index 93bb93b0ad..0000000000 --- a/components/libc/posix/src/SConscript +++ /dev/null @@ -1,16 +0,0 @@ -# RT-Thread building script for component - -from building import * - -src = [] -cwd = GetCurrentDir() -CPPPATH = [cwd] -group = [] - -flag = False -src += ['unistd.c'] #TODO - -if flag == True: - group = DefineGroup('POSIX', src, depend = [''], CPPPATH = CPPPATH) - -Return('group') diff --git a/components/libc/posix/src/unistd.c b/components/libc/posix/src/unistd.c deleted file mode 100644 index cb18dd3499..0000000000 --- a/components/libc/posix/src/unistd.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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 - * 2021-02-12 Meco Man move all functions located in <pthread_sleep.c> to this file - */ - -#include <rtthread.h> -#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)*/ -} -#else -int isatty(int fd) -{ - if (fd >=0 && fd < 3) - { - return 1; - } - else - { - return 0; - } -} -#endif -RTM_EXPORT(isatty); - -char *ttyname(int fd) -{ - return "/dev/tty"; /* TODO: need to add more specific */ -} -RTM_EXPORT(ttyname); |
