diff --git a/components/libc/compilers/common/include/sys/signal.h b/components/libc/compilers/common/include/sys/signal.h index b6990e1b55a..59839d8fc98 100644 --- a/components/libc/compilers/common/include/sys/signal.h +++ b/components/libc/compilers/common/include/sys/signal.h @@ -28,6 +28,9 @@ extern "C" { #include #endif +#elif defined(RT_USING_MLIBC) +#include + #else #include diff --git a/components/libc/compilers/mlibc/SConscript b/components/libc/compilers/mlibc/SConscript new file mode 100644 index 00000000000..66b11b96ff6 --- /dev/null +++ b/components/libc/compilers/mlibc/SConscript @@ -0,0 +1,37 @@ +import os +from building import * +Import('rtconfig') + +group = [] + +if rtconfig.PLATFORM == 'gcc': + from gcc import * +else: + Return('group') + +mlibc_version = "0.0.1" + +if mlibc_version and GetDepend('RT_USING_EXTERNAL_LIBC'): + print('mlibc version: ' + mlibc_version) + + cwd = GetCurrentDir() + src = Glob('*.c') + + CPPPATH = [cwd] + if GetDepend("RT_USING_SMART"): + CPPPATH += [cwd + '/smart'] + CPPPATH += [cwd + '/smart/sys'] + print(CPPPATH) + CPPDEFINES = ['RT_USING_MLIBC', 'RT_USING_LIBC'] # identify this is Newlib, and only enable POSIX.1-1990 + # LIBS = ['c', 'm'] # link libc and libm + AddDepend(['RT_USING_PICOLIBC', 'RT_USING_LIBC']) + + group = 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/mlibc/alltypes.h b/components/libc/compilers/mlibc/alltypes.h new file mode 100644 index 00000000000..5a535a3475c --- /dev/null +++ b/components/libc/compilers/mlibc/alltypes.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) mlibc & plct lab + * + * SPDX-License-Identifier: MIT + * + * Change Logs: + * Date Author Notes + * 2023/06/16 bernard the first verison + */ + +#ifndef MLIBC_ALLTYPES_H__ +#define MLIBC_ALLTYPES_H__ + +#include + +typedef uint64_t fsblkcnt_t; +typedef uint64_t fsfilcnt_t; + +#define INT_FAST16_MIN INT32_MIN +#define INT_FAST32_MIN INT32_MIN + +#define INT_FAST16_MAX INT32_MAX +#define INT_FAST32_MAX INT32_MAX + +#define UINT_FAST16_MAX UINT32_MAX +#define UINT_FAST32_MAX UINT32_MAX + +#if (defined(__GNUC__) && (__SIZEOF_POINTER__ == 8)) +#define __LONG_MAX INT64_MAX +#else +#define __LONG_MAX INT32_MAX +#endif /* __GNUC__ */ + +#endif diff --git a/components/libc/compilers/mlibc/smart/sched.h b/components/libc/compilers/mlibc/smart/sched.h new file mode 100644 index 00000000000..eb35064b30b --- /dev/null +++ b/components/libc/compilers/mlibc/smart/sched.h @@ -0,0 +1,141 @@ +/* + * Copyright (c) mlibc & plct lab + * + * SPDX-License-Identifier: MIT + * + * Change Logs: + * Date Author Notes + * 2024/8/8 0Bitbiscuits the first version + */ +#ifndef MLIBC_SCHED_H__ +#define MLIBC_SCHED_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +/* Defined a set of scheduling policies and a scheduling flag */ +#define SCHED_OTHER 0 +#define SCHED_FIFO 1 +#define SCHED_RR 2 +#define SCHED_BATCH 3 +#define SCHED_IDLE 5 +#define SCHED_DEADLINE 6 +#define SCHED_RESET_ON_FORK 0x40000000 + +/* Defined a set of flags for the clone system call, +** which control how the new process (or thread) +** inherits and shares the parent process's resources. +**/ +#ifdef __GNUC__ +#define CSIGNAL 0x000000ff +#define CLONE_NEWTIME 0x00000080 +#define CLONE_VM 0x00000100 +#define CLONE_FS 0x00000200 +#define CLONE_FILES 0x00000400 +#define CLONE_SIGHAND 0x00000800 +#define CLONE_PIDFD 0x00001000 +#define CLONE_PTRACE 0x00002000 +#define CLONE_VFORK 0x00004000 +#define CLONE_PARENT 0x00008000 +#define CLONE_THREAD 0x00010000 +#define CLONE_NEWNS 0x00020000 +#define CLONE_SYSVSEM 0x00040000 +#define CLONE_SETTLS 0x00080000 +#define CLONE_PARENT_SETTID 0x00100000 +#define CLONE_CHILD_CLEARTID 0x00200000 +#define CLONE_DETACHED 0x00400000 +#define CLONE_UNTRACED 0x00800000 +#define CLONE_CHILD_SETTID 0x01000000 +#define CLONE_NEWCGROUP 0x02000000 +#define CLONE_NEWUTS 0x04000000 +#define CLONE_NEWIPC 0x08000000 +#define CLONE_NEWUSER 0x10000000 +#define CLONE_NEWPID 0x20000000 +#define CLONE_NEWNET 0x40000000 +#define CLONE_IO 0x80000000 +#endif /* __GNUC__ */ + +struct sched_param { + int sched_priority; + int __reserved1; + struct { + time_t __reserved1; + long __reserved2; + } __reserved2[2]; + int __reserved3; +}; + +int sched_get_priority_max(int); +int sched_get_priority_min(int); +int sched_getparam(pid_t, struct sched_param *); +int sched_getscheduler(pid_t); +int sched_rr_get_interval(pid_t, struct timespec *); +int sched_setparam(pid_t, const struct sched_param *); +int sched_setscheduler(pid_t, int, const struct sched_param *); +int sched_yield(void); + +int clone (int (*)(void *), void *, int, void *, ...); +int unshare(int); +int setns(int, int); + +typedef struct cpu_set_t { unsigned long __bits[128/sizeof(long)]; } cpu_set_t; +int __sched_cpucount(size_t, const cpu_set_t *); +int sched_getcpu(void); +int sched_getaffinity(pid_t, size_t, cpu_set_t *); +int sched_setaffinity(pid_t, size_t, const cpu_set_t *); + +#define __CPU_op_S(i, size, set, op) ( (i)/8U >= (size) ? 0 : \ + (((unsigned long *)(set))[(i)/8/sizeof(long)] op (1UL<<((i)%(8*sizeof(long))))) ) + +#define CPU_SET_S(i, size, set) __CPU_op_S(i, size, set, |=) +#define CPU_CLR_S(i, size, set) __CPU_op_S(i, size, set, &=~) +#define CPU_ISSET_S(i, size, set) __CPU_op_S(i, size, set, &) + +#define __CPU_op_func_S(func, op) \ +static __inline void __CPU_##func##_S(size_t __size, cpu_set_t *__dest, \ + const cpu_set_t *__src1, const cpu_set_t *__src2) \ +{ \ + size_t __i; \ + for (__i=0; __i<__size/sizeof(long); __i++) \ + ((unsigned long *)__dest)[__i] = ((unsigned long *)__src1)[__i] \ + op ((unsigned long *)__src2)[__i] ; \ +} + +__CPU_op_func_S(AND, &) +__CPU_op_func_S(OR, |) +__CPU_op_func_S(XOR, ^) + +#define CPU_AND_S(a,b,c,d) __CPU_AND_S(a,b,c,d) +#define CPU_OR_S(a,b,c,d) __CPU_OR_S(a,b,c,d) +#define CPU_XOR_S(a,b,c,d) __CPU_XOR_S(a,b,c,d) + +#define CPU_COUNT_S(size,set) __sched_cpucount(size,set) +#define CPU_ZERO_S(size,set) memset(set,0,size) +#define CPU_EQUAL_S(size,set1,set2) (!memcmp(set1,set2,size)) + +#define CPU_ALLOC_SIZE(n) (sizeof(long) * ( (n)/(8*sizeof(long)) \ + + ((n)%(8*sizeof(long)) + 8*sizeof(long)-1)/(8*sizeof(long)) ) ) +#define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n))) +#define CPU_FREE(set) free(set) + +#define CPU_SETSIZE 1024 + +#define CPU_SET(i, set) CPU_SET_S(i,sizeof(cpu_set_t),set) +#define CPU_CLR(i, set) CPU_CLR_S(i,sizeof(cpu_set_t),set) +#define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set) +#define CPU_AND(d,s1,s2) CPU_AND_S(sizeof(cpu_set_t),d,s1,s2) +#define CPU_OR(d,s1,s2) CPU_OR_S(sizeof(cpu_set_t),d,s1,s2) +#define CPU_XOR(d,s1,s2) CPU_XOR_S(sizeof(cpu_set_t),d,s1,s2) +#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set) +#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set) +#define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/libc/compilers/mlibc/smart/sys/epoll.h b/components/libc/compilers/mlibc/smart/sys/epoll.h new file mode 100644 index 00000000000..970a5dd9fa2 --- /dev/null +++ b/components/libc/compilers/mlibc/smart/sys/epoll.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) mlibc & plct lab + * + * SPDX-License-Identifier: MIT + * + * Change Logs: + * Date Author Notes + * 2024/8/8 0Bitbiscuits the first version + */ +#ifndef MLIBC_EPOLL_H__ +#define MLIBC_EPOLL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#include + +/* The flag of file descriptor */ +#define EPOLL_CLOEXEC O_CLOEXEC +#define EPOLL_NONBLOCK O_NONBLOCK + +/* The event of file descriptor */ +enum EPOLL_EVENTS { __EPOLL_DUMMY }; +#define EPOLLIN 0x001 +#define EPOLLPRI 0x002 +#define EPOLLOUT 0x004 +#define EPOLLRDNORM 0x040 +#define EPOLLNVAL 0x020 +#define EPOLLRDBAND 0x080 +#define EPOLLWRNORM 0x100 +#define EPOLLWRBAND 0x200 +#define EPOLLMSG 0x400 +#define EPOLLERR 0x008 +#define EPOLLHUP 0x010 +#define EPOLLRDHUP 0x2000 +#define EPOLLEXCLUSIVE (1U<<28) +#define EPOLLWAKEUP (1U<<29) +#define EPOLLONESHOT (1U<<30) +#define EPOLLET (1U<<31) + +/* The control type of file descriptor */ +#define EPOLL_CTL_ADD 1 +#define EPOLL_CTL_DEL 2 +#define EPOLL_CTL_MOD 3 + +typedef union epoll_data { + void *ptr; + int fd; + uint32_t u32; + uint64_t u64; +} epoll_data_t; + +struct epoll_event { + uint32_t events; + epoll_data_t data; +}; + +int epoll_create(int); +int epoll_create1(int); +int epoll_ctl(int, int, int, struct epoll_event *); +int epoll_wait(int, struct epoll_event *, int, int); +int epoll_pwait(int, struct epoll_event *, int, int, const sigset_t *); + +#ifdef __cplusplus +} +#endif + +#endif /* MLIBC_SYS_EPOLL_H__ */ \ No newline at end of file diff --git a/components/libc/compilers/mlibc/smart/sys/eventfd.h b/components/libc/compilers/mlibc/smart/sys/eventfd.h new file mode 100644 index 00000000000..705de2d4f40 --- /dev/null +++ b/components/libc/compilers/mlibc/smart/sys/eventfd.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) mlibc & plct lab + * + * SPDX-License-Identifier: MIT + * + * Change Logs: + * Date Author Notes + * 2024/8/8 0Bitbiscuits the first version + */ +#ifndef MLIBC_SYS_EVENTFD_H__ +#define MLIBC_SYS_EVENTFD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +typedef uint64_t eventfd_t; + +/* The type of file descriptor */ +#define EFD_SEMAPHORE 1 +#define EFD_CLOEXEC O_CLOEXEC +#define EFD_NONBLOCK O_NONBLOCK + +int eventfd(unsigned int, int); +int eventfd_read(int, eventfd_t *); +int eventfd_write(int, eventfd_t); + +#ifdef __cplusplus +} +#endif + +#endif /* sys/eventfd.h */ diff --git a/components/libc/compilers/mlibc/smart/sys/ioctl.h b/components/libc/compilers/mlibc/smart/sys/ioctl.h new file mode 100644 index 00000000000..13890d9609d --- /dev/null +++ b/components/libc/compilers/mlibc/smart/sys/ioctl.h @@ -0,0 +1,263 @@ +/* + * Copyright (c) mlibc & plct lab + * + * SPDX-License-Identifier: MIT + * + * Change Logs: + * Date Author Notes + * 2024/8/8 0Bitbiscuits the first version + */ +#ifndef MLIBC_SYS_IOCTL_H__ +#define MLIBC_SYS_IOCTL_H__ +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define _IOC(a, b, c, d) (((a) << 29) | ((b) << 8) | (c) | ((d) << 16)) +#define _IOC_NONE 1U +#define _IOC_READ 2U +#define _IOC_WRITE 4U + +#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)) + +/* Line Discipline Definitions */ +#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 N_GIGASET_M101 16 +#define N_SLCAN 17 +#define N_PPS 18 +#define N_V253 19 +#define N_CAIF 20 +#define N_GSM0710 21 +#define N_TI_WL 22 +#define N_TRACESINK 23 +#define N_TRACEROUTER 24 +#define N_NCI 25 +#define N_SPEAKUP 26 +#define N_NULL 27 + +/* Definitions for pseudo-terminal (PTY) packet mode flags */ +#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 + +/* Used to check if the transmit FIFO +** buffer of the serial port is empty +*/ +#define TIOCSER_TEMT 1 + +#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 + +#ifndef FIONWRITE +#define FIONWRITE _IOR('f', 121, int) /* get # bytes outstanding in send queue */ +#endif + +/* Terminal control commands.*/ +#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 FIONREAD 0x541B +#define TIOCINQ FIONREAD +#define TIOCLINUX 0x541C +#define TIOCCONS 0x541D +#define TIOCGSERIAL 0x541E +#define TIOCSSERIAL 0x541F +#define TIOCPKT 0x5420 +#define FIONBIO 0x5421 +#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 TIOCGPTPEER 0x5441 +#define TIOCGISO7816 0x80285442 +#define TIOCSISO7816 0xc0285443 + +/* File descriptor control commands */ +#define FIONCLEX 0x5450 +#define FIOCLEX 0x5451 +#define FIOASYNC 0x5452 +#define FIOQSIZE 0x5460 + +/* Uart control command */ +#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 + +/* Modem control lines */ +#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 + +/* Socket control commands */ +#define FIOSETOWN 0x8901 +#define SIOCSPGRP 0x8902 +#define FIOGETOWN 0x8903 +#define SIOCGPGRP 0x8904 +#define SIOCATMARK 0x8905 +#if __LONG_MAX == 0x7fffffff +#define SIOCGSTAMP _IOR(0x89, 6, char[16]) +#define SIOCGSTAMPNS _IOR(0x89, 7, char[16]) +#else +#define SIOCGSTAMP 0x8906 +#define SIOCGSTAMPNS 0x8907 +#endif + +struct winsize +{ + unsigned short ws_row; + unsigned short ws_col; + unsigned short ws_xpixel; + unsigned short ws_ypixel; +}; + +int ioctl (int, int, ...); + +#ifdef __cplusplus +} +#endif + +#endif /* MLIBC_SYS_IOCTL_H__ */ diff --git a/components/libc/compilers/mlibc/smart/sys/mman.h b/components/libc/compilers/mlibc/smart/sys/mman.h new file mode 100644 index 00000000000..c2d0298035b --- /dev/null +++ b/components/libc/compilers/mlibc/smart/sys/mman.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) mlibc & plct lab + * + * SPDX-License-Identifier: MIT + * + * Change Logs: + * Date Author Notes + * 2024/8/8 0Bitbiscuits the first version + */ +#ifndef MLIBC_SYS_MMAN_H__ +#define MLIBC_SYS_MMAN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define MAP_FAILED ((void *) -1) + +/* mmap flags */ +#define MAP_SHARED 0x01 /**< Share the mapping with other processes. */ +#define MAP_PRIVATE 0x02 /**< Create a private copy-on-write mapping. */ +#define MAP_TYPE 0x0f /**< Mask for type of mapping. */ +#define MAP_FIXED 0x10 /**< Interpret addr exactly. */ +#define MAP_ANON 0x20 /**< Anonymous mapping. */ +#define MAP_ANONYMOUS MAP_ANON /**< Synonym for MAP_ANON. */ +#define MAP_NORESERVE 0x4000 /**< Don't reserve swap space for this mapping. */ +#define MAP_GROWSDOWN 0x0100 /**< Stack-like segment. */ +#define MAP_DENYWRITE 0x0800 /**< ETXTBSY. */ +#define MAP_EXECUTABLE 0x1000 /**< Mark it as an executable. */ +#define MAP_LOCKED 0x2000 /**< Lock the mapping's pages. */ +#define MAP_POPULATE 0x8000 /**< Populate (prefault) pagetables. */ +#define MAP_NONBLOCK 0x10000 /**< Do not block on IO. */ +#define MAP_STACK 0x20000 /**< Allocation is a stack segment. */ +#define MAP_HUGETLB 0x40000 /**< Create a huge page mapping. */ +#define MAP_FILE 0 /**< Compatibility */ + +/* mmap protections */ +#define PROT_NONE 0 /**< No access. */ +#define PROT_READ 1 /**< Page can be read. */ +#define PROT_WRITE 2 /**< Page can be written. */ +#define PROT_EXEC 4 /**< Page can be executed. */ +#define PROT_GROWSDOWN 0x01000000/**< Extend change to start of growsdown vma (mprotect only). */ +#define PROT_GROWSUP 0x02000000/**< Extend change to start of growsup vma (mprotect only). */ + +/* msync flags */ +#define MS_ASYNC 1 /**< Perform asynchronous writes. */ +#define MS_INVALIDATE 2 /**< Invalidate mappings after writing. */ +#define MS_SYNC 4 /**< Perform synchronous writes. */ + +/* mlockall flags */ +#define MCL_CURRENT 1 /**< Lock all pages which are currently mapped into the address space of the process. */ +#define MCL_FUTURE 2 /**< Lock all pages which will become mapped into the address space of the process in the future. */ +#define MCL_ONFAULT 4 /**< Lock all pages which are currently mapped into the address space of the process on access. */ + +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 /* MLIBC_SYS_MMAN_H__ */ diff --git a/components/libc/compilers/mlibc/smart/sys/reboot.h b/components/libc/compilers/mlibc/smart/sys/reboot.h new file mode 100644 index 00000000000..3f273c48d5e --- /dev/null +++ b/components/libc/compilers/mlibc/smart/sys/reboot.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) mlibc & plct lab + * + * SPDX-License-Identifier: MIT + * + * Change Logs: + * Date Author Notes + * 2024/8/8 0Bitbiscuits the first version + */ +#ifndef MLIBC_SYS_REBOOT_H__ +#define MLIBC_SYS_REBOOT_H__ +#ifdef __cplusplus +extern "C" { +#endif + +#define RB_AUTOBOOT 0x01234567 +#define RB_HALT_SYSTEM 0xcdef0123 +#define RB_ENABLE_CAD 0x89abcdef +#define RB_DISABLE_CAD 0 +#define RB_POWER_OFF 0x4321fedc +#define RB_SW_SUSPEND 0xd000fce2 +#define RB_KEXEC 0x45584543 + +int reboot(int); + +#ifdef __cplusplus +} +#endif + +#endif /* MLIBC_SYS_REBOOT_H__ */ diff --git a/components/libc/compilers/mlibc/smart/sys/signalfd.h b/components/libc/compilers/mlibc/smart/sys/signalfd.h new file mode 100644 index 00000000000..572879944bf --- /dev/null +++ b/components/libc/compilers/mlibc/smart/sys/signalfd.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) mlibc & plct lab + * + * SPDX-License-Identifier: MIT + * + * Change Logs: + * Date Author Notes + * 2024/8/8 0Bitbiscuits the first version + */ +#ifndef MLIBC_SYS_SIGNALFD_H__ +#define MLIBC_SYS_SIGNALFD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +/* Signal file descriptor state */ +#define SFD_CLOEXEC O_CLOEXEC +#define SFD_NONBLOCK O_NONBLOCK + +struct signalfd_siginfo { + uint32_t ssi_signo; + int32_t ssi_errno; + int32_t ssi_code; + uint32_t ssi_pid; + uint32_t ssi_uid; + int32_t ssi_fd; + uint32_t ssi_tid; + uint32_t ssi_band; + uint32_t ssi_overrun; + uint32_t ssi_trapno; + int32_t ssi_status; + int32_t ssi_int; + uint64_t ssi_ptr; + uint64_t ssi_utime; + uint64_t ssi_stime; + uint64_t ssi_addr; + uint16_t ssi_addr_lsb; + uint16_t __pad2; + int32_t ssi_syscall; + uint64_t ssi_call_addr; + uint32_t ssi_arch; + uint8_t __pad[128-14*4-5*8-2*2]; +}; + +int signalfd(int, const sigset_t *, int); + +#ifdef __cplusplus +} +#endif + +#endif /* MLIBC_SYS_SIGNALFD_H__ */ diff --git a/components/libc/compilers/mlibc/smart/sys/sysinfo.h b/components/libc/compilers/mlibc/smart/sys/sysinfo.h new file mode 100644 index 00000000000..c754e9e7d7a --- /dev/null +++ b/components/libc/compilers/mlibc/smart/sys/sysinfo.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) mlibc & plct lab + * + * SPDX-License-Identifier: MIT + * + * Change Logs: + * Date Author Notes + * 2024/8/8 0Bitbiscuits the first version + */ +#ifndef MLIBC_SYS_SYSINFO_H__ +#define MLIBC_SYS_SYSINFO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define SI_LOAD_SHIFT 16 + +struct sysinfo { + unsigned long uptime; + unsigned long loads[3]; + unsigned long totalram; + unsigned long freeram; + unsigned long sharedram; + unsigned long bufferram; + unsigned long totalswap; + unsigned long freeswap; + unsigned short procs, pad; + unsigned long totalhigh; + unsigned long freehigh; + unsigned mem_unit; + char __reserved[256]; +}; + +int sysinfo (struct sysinfo *); +int get_nprocs_conf (void); +int get_nprocs (void); +long get_phys_pages (void); +long get_avphys_pages (void); + +#ifdef __cplusplus +} +#endif + +#endif /* MLIBC_SYS_SYSINFO_H__ */ diff --git a/components/libc/compilers/mlibc/smart/sys/timerfd.h b/components/libc/compilers/mlibc/smart/sys/timerfd.h new file mode 100644 index 00000000000..d1a15cc58f2 --- /dev/null +++ b/components/libc/compilers/mlibc/smart/sys/timerfd.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) mlibc & plct lab + * + * SPDX-License-Identifier: MIT + * + * Change Logs: + * Date Author Notes + * 2024/8/8 0Bitbiscuits the first version + */ +#ifndef MLIBC_SYS_TIMERFD_H__ +#define MLIBC_SYS_TIMERFD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define TFD_NONBLOCK O_NONBLOCK +#define TFD_CLOEXEC O_CLOEXEC + +#define TFD_TIMER_ABSTIME 1 +#define TFD_TIMER_CANCEL_ON_SET (1 << 1) + +int timerfd_create(int, int); +int timerfd_settime(int, int, const struct itimerspec *, struct itimerspec *); +int timerfd_gettime(int, struct itimerspec *); + +#ifdef __cplusplus +} +#endif + +#endif /* MLIBC_SYS_TIMERFD_H__ */ diff --git a/components/libc/compilers/mlibc/syscalls.c b/components/libc/compilers/mlibc/syscalls.c new file mode 100644 index 00000000000..30e0122e507 --- /dev/null +++ b/components/libc/compilers/mlibc/syscalls.c @@ -0,0 +1,83 @@ +#include +#include + +struct __lock +{ + rt_mutex_t sys_mutex; +}; +typedef struct __lock* _LOCK_T; + +int __retarget_lock_init(_LOCK_T *lock) +{ + static int mutex_counter = 0; + char mutex_name[20]; + + (*lock) = rt_malloc(sizeof(struct __lock)); + + (*lock)->sys_mutex = NULL; + + snprintf(mutex_name, 20, "libc_mutex%d", mutex_counter++); + (*lock)->sys_mutex = rt_mutex_create(mutex_name, 0); + if(!((*lock)->sys_mutex)) + { + rt_free((*lock)); + return -RT_ERROR; + } + + return RT_EOK; +} + +int __retarget_lock_init_recursive(_LOCK_T *lock) +{ + return __retarget_lock_init(lock); +} + +int __retarget_lock_deinit(_LOCK_T lock) +{ + int ret = 0; + + if(lock) + { + ret = rt_mutex_delete((rt_mutex_t)lock->sys_mutex); + rt_free(lock); + return ret; + } + + return -RT_ERROR; +} + +int __retarget_lock_deinit_recursive(_LOCK_T lock) +{ + return __retarget_lock_deinit(lock); +} + +int __retarget_lock_take(_LOCK_T lock) +{ + if(lock) + return rt_mutex_take(lock->sys_mutex, 0); + + return -RT_ERROR; +} + +int __retarget_lock_take_recursive(_LOCK_T lock) +{ + return __retarget_lock_take(lock); +} + +int __retarget_lock_release(_LOCK_T lock) +{ + if(lock) + return rt_mutex_release(lock->sys_mutex); + + return -RT_ERROR; +} + +int __retarget_lock_release_recursive(_LOCK_T lock) +{ + return __retarget_lock_release(lock); +} + +int *__errno_location(void) +{ + return _rt_errno(); +}