[rt-smart] Fix return value in syscall (#7045)
* [timer] fix sys return value to avoid outdated errno * [rtdef] add wrap to stringify * [syscall] return value in rt errno should be recycle immediately after call to posix layer * [syscall] return type of syscall should be long errno should be recycle immediately after call to rt posix layer to avoid outdated value * [format] move prototype to header file * [fix] futex definition conflict
This commit is contained in:
parent
34bf77b8e3
commit
fcc01a617d
|
@ -374,7 +374,7 @@ void fd_release(int fd)
|
|||
fdt_fd_release(fdt, fd);
|
||||
}
|
||||
|
||||
int sys_dup(int oldfd)
|
||||
rt_err_t sys_dup(int oldfd)
|
||||
{
|
||||
int newfd = -1;
|
||||
struct dfs_fdtable *fdt = NULL;
|
||||
|
@ -466,7 +466,7 @@ int fd_is_open(const char *pathname)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int sys_dup2(int oldfd, int newfd)
|
||||
rt_err_t sys_dup2(int oldfd, int newfd)
|
||||
{
|
||||
struct dfs_fdtable *fdt = NULL;
|
||||
int ret = 0;
|
||||
|
|
|
@ -174,7 +174,9 @@ void futex_wake(struct rt_futex *futex, int number)
|
|||
rt_schedule();
|
||||
}
|
||||
|
||||
int sys_futex(int *uaddr, int op, int val, const struct timespec *timeout,
|
||||
#include <syscall_generic.h>
|
||||
|
||||
sysret_t sys_futex(int *uaddr, int op, int val, const struct timespec *timeout,
|
||||
int *uaddr2, int val3)
|
||||
{
|
||||
struct rt_lwp *lwp = RT_NULL;
|
||||
|
|
|
@ -418,7 +418,9 @@ static int _pthread_mutex_destroy(void *umutex)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int sys_pmutex(void *umutex, int op, void *arg)
|
||||
#include <syscall_generic.h>
|
||||
|
||||
sysret_t sys_pmutex(void *umutex, int op, void *arg)
|
||||
{
|
||||
int ret = -EINVAL;
|
||||
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-03-13 RT-Thread Export as header
|
||||
*/
|
||||
#ifndef __LWP_SYS_SOCKET_H__
|
||||
#define __LWP_SYS_SOCKET_H__
|
||||
|
||||
/* socket levels */
|
||||
#define INTF_SOL_SOCKET 1
|
||||
#define IMPL_SOL_SOCKET 0xFFF
|
||||
|
||||
#define INTF_IPPROTO_IP 0
|
||||
#define IMPL_IPPROTO_IP 0
|
||||
|
||||
#define INTF_IPPROTO_TCP 6
|
||||
#define IMPL_IPPROTO_TCP 6
|
||||
|
||||
#define INTF_IPPROTO_IPV6 41
|
||||
#define IMPL_IPPROTO_IPV6 41
|
||||
|
||||
/* SOL_SOCKET option names */
|
||||
#define INTF_SO_BROADCAST 6
|
||||
#define INTF_SO_KEEPALIVE 9
|
||||
#define INTF_SO_REUSEADDR 2
|
||||
#define INTF_SO_TYPE 3
|
||||
#define INTF_SO_ERROR 4
|
||||
#define INTF_SO_SNDTIMEO 21
|
||||
#define INTF_SO_RCVTIMEO 20
|
||||
#define INTF_SO_RCVBUF 8
|
||||
#define INTF_SO_LINGER 13
|
||||
#define INTF_SO_NO_CHECK 11
|
||||
#define INTF_SO_ACCEPTCONN 30
|
||||
#define INTF_SO_DONTROUTE 5
|
||||
#define INTF_SO_OOBINLINE 10
|
||||
#define INTF_SO_REUSEPORT 15
|
||||
#define INTF_SO_SNDBUF 7
|
||||
#define INTF_SO_SNDLOWAT 19
|
||||
#define INTF_SO_RCVLOWAT 18
|
||||
|
||||
#define IMPL_SO_BROADCAST 0x0020
|
||||
#define IMPL_SO_KEEPALIVE 0x0008
|
||||
#define IMPL_SO_REUSEADDR 0x0004
|
||||
#define IMPL_SO_TYPE 0x1008
|
||||
#define IMPL_SO_ERROR 0x1007
|
||||
#define IMPL_SO_SNDTIMEO 0x1005
|
||||
#define IMPL_SO_RCVTIMEO 0x1006
|
||||
#define IMPL_SO_RCVBUF 0x1002
|
||||
#define IMPL_SO_LINGER 0x0080
|
||||
#define IMPL_SO_NO_CHECK 0x100a
|
||||
#define IMPL_SO_ACCEPTCONN 0x0002
|
||||
#define IMPL_SO_DONTROUTE 0x0010
|
||||
#define IMPL_SO_OOBINLINE 0x0100
|
||||
#define IMPL_SO_REUSEPORT 0x0200
|
||||
#define IMPL_SO_SNDBUF 0x1001
|
||||
#define IMPL_SO_SNDLOWAT 0x1003
|
||||
#define IMPL_SO_RCVLOWAT 0x1004
|
||||
|
||||
/* IPPROTO_IP option names */
|
||||
#define INTF_IP_TTL 2
|
||||
#define INTF_IP_TOS 1
|
||||
#define INTF_IP_MULTICAST_TTL 33
|
||||
#define INTF_IP_MULTICAST_IF 32
|
||||
#define INTF_IP_MULTICAST_LOOP 34
|
||||
#define INTF_IP_ADD_MEMBERSHIP 35
|
||||
#define INTF_IP_DROP_MEMBERSHIP 36
|
||||
|
||||
#define IMPL_IP_TTL 2
|
||||
#define IMPL_IP_TOS 1
|
||||
#define IMPL_IP_MULTICAST_TTL 5
|
||||
#define IMPL_IP_MULTICAST_IF 6
|
||||
#define IMPL_IP_MULTICAST_LOOP 7
|
||||
#define IMPL_IP_ADD_MEMBERSHIP 3
|
||||
#define IMPL_IP_DROP_MEMBERSHIP 4
|
||||
|
||||
/* IPPROTO_TCP option names */
|
||||
#define INTF_TCP_NODELAY 1
|
||||
#define INTF_TCP_KEEPALIVE 9
|
||||
#define INTF_TCP_KEEPIDLE 4
|
||||
#define INTF_TCP_KEEPINTVL 5
|
||||
#define INTF_TCP_KEEPCNT 6
|
||||
|
||||
#define IMPL_TCP_NODELAY 0x01
|
||||
#define IMPL_TCP_KEEPALIVE 0x02
|
||||
#define IMPL_TCP_KEEPIDLE 0x03
|
||||
#define IMPL_TCP_KEEPINTVL 0x04
|
||||
#define IMPL_TCP_KEEPCNT 0x05
|
||||
|
||||
/* IPPROTO_IPV6 option names */
|
||||
#define INTF_IPV6_V6ONLY 26
|
||||
#define IMPL_IPV6_V6ONLY 27
|
||||
|
||||
#endif /* __LWP_SYS_SOCKET_H__ */
|
|
@ -10,6 +10,7 @@
|
|||
* 2021-02-06 lizhirui fix some bugs
|
||||
* 2021-02-12 lizhirui add 64-bit support for sys_brk
|
||||
* 2021-02-20 lizhirui fix some warnings
|
||||
* 2023-03-13 WangXiaoyao Format & fix syscall return value
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
/* RT-Thread System call */
|
||||
|
@ -20,6 +21,12 @@
|
|||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define DBG_TAG "SYSCALL"
|
||||
#define DBG_LVL DBG_INFO
|
||||
#include <rtdbg.h>
|
||||
|
||||
#include "syscall_generic.h"
|
||||
|
||||
#include <lwp.h>
|
||||
#ifdef ARCH_MM_MMU
|
||||
#include <lwp_user_mm.h>
|
||||
|
@ -38,27 +45,8 @@
|
|||
#include <sys/statfs.h> /* statfs() */
|
||||
#endif
|
||||
|
||||
#include "syscall_data.h"
|
||||
#include "mqueue.h"
|
||||
|
||||
#if (defined(RT_USING_SAL) && defined(SAL_USING_POSIX))
|
||||
#include <sys/socket.h>
|
||||
|
||||
#define SYSCALL_NET(f) f
|
||||
#else
|
||||
#define SYSCALL_NET(f) SYSCALL_SIGN(sys_notimpl)
|
||||
#endif
|
||||
|
||||
#if defined(RT_USING_DFS) && defined(ARCH_MM_MMU)
|
||||
#define SYSCALL_USPACE(f) f
|
||||
#else
|
||||
#define SYSCALL_USPACE(f) SYSCALL_SIGN(sys_notimpl)
|
||||
#endif
|
||||
|
||||
#define DBG_TAG "SYSCALL"
|
||||
#define DBG_LVL DBG_INFO
|
||||
#include <rtdbg.h>
|
||||
|
||||
#ifdef RT_USING_SAL
|
||||
#include <netdev_ipaddr.h>
|
||||
#include <netdev.h>
|
||||
|
@ -66,11 +54,27 @@
|
|||
#include <sal_netdb.h>
|
||||
#include <sal_socket.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#endif /* RT_USING_SAL */
|
||||
|
||||
#if (defined(RT_USING_SAL) && defined(SAL_USING_POSIX))
|
||||
#include <sys/socket.h>
|
||||
|
||||
#define SYSCALL_NET(f) f
|
||||
#else
|
||||
#define SYSCALL_NET(f) SYSCALL_SIGN(sys_notimpl)
|
||||
#endif /* (defined(RT_USING_SAL) && defined(SAL_USING_POSIX)) */
|
||||
|
||||
#if defined(RT_USING_DFS) && defined(ARCH_MM_MMU)
|
||||
#define SYSCALL_USPACE(f) f
|
||||
#else
|
||||
#define SYSCALL_USPACE(f) SYSCALL_SIGN(sys_notimpl)
|
||||
#endif /* defined(RT_USING_DFS) && defined(ARCH_MM_MMU) */
|
||||
|
||||
#include <tty.h>
|
||||
#include "lwp_ipc_internal.h"
|
||||
#include <sched.h>
|
||||
|
||||
#ifndef GRND_NONBLOCK
|
||||
#define GRND_NONBLOCK 0x0001
|
||||
#endif /* GRND_NONBLOCK */
|
||||
|
@ -81,29 +85,23 @@
|
|||
|
||||
#ifndef RT_USING_POSIX_TIMER
|
||||
#error "No definition RT_USING_POSIX_TIMER"
|
||||
#endif
|
||||
#endif /* RT_USING_POSIX_TIMER */
|
||||
|
||||
#ifndef RT_USING_POSIX_CLOCK
|
||||
#error "No definition RT_USING_POSIX_CLOCK"
|
||||
#endif
|
||||
#endif /* RT_USING_POSIX_CLOCK */
|
||||
|
||||
#define SET_ERRNO(no) rt_set_errno(-(no))
|
||||
#define GET_ERRNO() ((rt_get_errno() > 0) ? (-rt_get_errno()) : rt_get_errno())
|
||||
struct musl_sockaddr
|
||||
{
|
||||
uint16_t sa_family;
|
||||
char sa_data[14];
|
||||
};
|
||||
|
||||
int sys_dup(int oldfd);
|
||||
int sys_dup2(int oldfd, int new);
|
||||
void lwp_cleanup(struct rt_thread *tid);
|
||||
|
||||
#ifdef ARCH_MM_MMU
|
||||
#define ALLOC_KERNEL_STACK_SIZE 5120
|
||||
|
||||
int sys_futex(int *uaddr, int op, int val, void *timeout, void *uaddr2, int val3);
|
||||
int sys_pmutex(void *umutex, int op, void *arg);
|
||||
int sys_cacheflush(void *addr, int len, int cache);
|
||||
static void *kmem_get(size_t size)
|
||||
{
|
||||
return rt_malloc(size);
|
||||
|
@ -113,7 +111,7 @@ static void kmem_put(void *kptr)
|
|||
{
|
||||
rt_free(kptr);
|
||||
}
|
||||
#else
|
||||
#else /* ARCH_MM_MMU */
|
||||
#define ALLOC_KERNEL_STACK_SIZE 1536
|
||||
#define ALLOC_KERNEL_STACK_SIZE_MIN 1024
|
||||
#define ALLOC_KERNEL_STACK_SIZE_MAX 4096
|
||||
|
@ -121,94 +119,11 @@ static void kmem_put(void *kptr)
|
|||
extern void set_user_context(void *stack);
|
||||
#endif /* ARCH_MM_MMU */
|
||||
|
||||
#ifdef RT_USING_SAL
|
||||
/* The same socket option is defined differently in the user interfaces and the
|
||||
* implementation. The options should be converted in the kernel. */
|
||||
#include "lwp_sys_socket.h"
|
||||
|
||||
/* socket levels */
|
||||
#define INTF_SOL_SOCKET 1
|
||||
#define IMPL_SOL_SOCKET 0xFFF
|
||||
|
||||
#define INTF_IPPROTO_IP 0
|
||||
#define IMPL_IPPROTO_IP 0
|
||||
|
||||
#define INTF_IPPROTO_TCP 6
|
||||
#define IMPL_IPPROTO_TCP 6
|
||||
|
||||
#define INTF_IPPROTO_IPV6 41
|
||||
#define IMPL_IPPROTO_IPV6 41
|
||||
|
||||
/* SOL_SOCKET option names */
|
||||
#define INTF_SO_BROADCAST 6
|
||||
#define INTF_SO_KEEPALIVE 9
|
||||
#define INTF_SO_REUSEADDR 2
|
||||
#define INTF_SO_TYPE 3
|
||||
#define INTF_SO_ERROR 4
|
||||
#define INTF_SO_SNDTIMEO 21
|
||||
#define INTF_SO_RCVTIMEO 20
|
||||
#define INTF_SO_RCVBUF 8
|
||||
#define INTF_SO_LINGER 13
|
||||
#define INTF_SO_NO_CHECK 11
|
||||
#define INTF_SO_ACCEPTCONN 30
|
||||
#define INTF_SO_DONTROUTE 5
|
||||
#define INTF_SO_OOBINLINE 10
|
||||
#define INTF_SO_REUSEPORT 15
|
||||
#define INTF_SO_SNDBUF 7
|
||||
#define INTF_SO_SNDLOWAT 19
|
||||
#define INTF_SO_RCVLOWAT 18
|
||||
|
||||
#define IMPL_SO_BROADCAST 0x0020
|
||||
#define IMPL_SO_KEEPALIVE 0x0008
|
||||
#define IMPL_SO_REUSEADDR 0x0004
|
||||
#define IMPL_SO_TYPE 0x1008
|
||||
#define IMPL_SO_ERROR 0x1007
|
||||
#define IMPL_SO_SNDTIMEO 0x1005
|
||||
#define IMPL_SO_RCVTIMEO 0x1006
|
||||
#define IMPL_SO_RCVBUF 0x1002
|
||||
#define IMPL_SO_LINGER 0x0080
|
||||
#define IMPL_SO_NO_CHECK 0x100a
|
||||
#define IMPL_SO_ACCEPTCONN 0x0002
|
||||
#define IMPL_SO_DONTROUTE 0x0010
|
||||
#define IMPL_SO_OOBINLINE 0x0100
|
||||
#define IMPL_SO_REUSEPORT 0x0200
|
||||
#define IMPL_SO_SNDBUF 0x1001
|
||||
#define IMPL_SO_SNDLOWAT 0x1003
|
||||
#define IMPL_SO_RCVLOWAT 0x1004
|
||||
|
||||
/* IPPROTO_IP option names */
|
||||
#define INTF_IP_TTL 2
|
||||
#define INTF_IP_TOS 1
|
||||
#define INTF_IP_MULTICAST_TTL 33
|
||||
#define INTF_IP_MULTICAST_IF 32
|
||||
#define INTF_IP_MULTICAST_LOOP 34
|
||||
#define INTF_IP_ADD_MEMBERSHIP 35
|
||||
#define INTF_IP_DROP_MEMBERSHIP 36
|
||||
|
||||
#define IMPL_IP_TTL 2
|
||||
#define IMPL_IP_TOS 1
|
||||
#define IMPL_IP_MULTICAST_TTL 5
|
||||
#define IMPL_IP_MULTICAST_IF 6
|
||||
#define IMPL_IP_MULTICAST_LOOP 7
|
||||
#define IMPL_IP_ADD_MEMBERSHIP 3
|
||||
#define IMPL_IP_DROP_MEMBERSHIP 4
|
||||
|
||||
/* IPPROTO_TCP option names */
|
||||
#define INTF_TCP_NODELAY 1
|
||||
#define INTF_TCP_KEEPALIVE 9
|
||||
#define INTF_TCP_KEEPIDLE 4
|
||||
#define INTF_TCP_KEEPINTVL 5
|
||||
#define INTF_TCP_KEEPCNT 6
|
||||
|
||||
#define IMPL_TCP_NODELAY 0x01
|
||||
#define IMPL_TCP_KEEPALIVE 0x02
|
||||
#define IMPL_TCP_KEEPIDLE 0x03
|
||||
#define IMPL_TCP_KEEPINTVL 0x04
|
||||
#define IMPL_TCP_KEEPCNT 0x05
|
||||
|
||||
/* IPPROTO_IPV6 option names */
|
||||
#define INTF_IPV6_V6ONLY 26
|
||||
#define IMPL_IPV6_V6ONLY 27
|
||||
|
||||
#ifdef RT_USING_SAL
|
||||
static void convert_sockopt(int *level, int *optname)
|
||||
{
|
||||
if (*level == INTF_SOL_SOCKET)
|
||||
|
@ -558,7 +473,7 @@ off_t sys_lseek(int fd, off_t offset, int whence)
|
|||
}
|
||||
|
||||
/* syscall: "open" ret: "int" args: "const char *" "int" "..." */
|
||||
int sys_open(const char *name, int flag, ...)
|
||||
sysret_t sys_open(const char *name, int flag, ...)
|
||||
{
|
||||
#ifdef ARCH_MM_MMU
|
||||
int ret = -1;
|
||||
|
@ -603,20 +518,20 @@ int sys_open(const char *name, int flag, ...)
|
|||
}
|
||||
|
||||
/* syscall: "close" ret: "int" args: "int" */
|
||||
int sys_close(int fd)
|
||||
sysret_t sys_close(int fd)
|
||||
{
|
||||
int ret = close(fd);
|
||||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
}
|
||||
|
||||
/* syscall: "ioctl" ret: "int" args: "int" "u_long" "..." */
|
||||
int sys_ioctl(int fd, unsigned long cmd, void* data)
|
||||
sysret_t sys_ioctl(int fd, unsigned long cmd, void* data)
|
||||
{
|
||||
int ret = ioctl(fd, cmd, data);
|
||||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
}
|
||||
|
||||
int sys_fstat(int file, struct stat *buf)
|
||||
sysret_t sys_fstat(int file, struct stat *buf)
|
||||
{
|
||||
#ifdef ARCH_MM_MMU
|
||||
int ret = -1;
|
||||
|
@ -743,7 +658,7 @@ static void dfs2musl_events(short *events)
|
|||
*events = result_e;
|
||||
}
|
||||
|
||||
int sys_poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
||||
sysret_t sys_poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
||||
{
|
||||
int ret = -1;
|
||||
int i = 0;
|
||||
|
@ -804,7 +719,7 @@ int sys_poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
|||
#endif /* ARCH_MM_MMU */
|
||||
}
|
||||
|
||||
int sys_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
|
||||
sysret_t sys_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
|
||||
{
|
||||
#ifdef ARCH_MM_MMU
|
||||
int ret = -1;
|
||||
|
@ -908,7 +823,7 @@ quit:
|
|||
#endif
|
||||
}
|
||||
|
||||
int sys_unlink(const char *pathname)
|
||||
sysret_t sys_unlink(const char *pathname)
|
||||
{
|
||||
#ifdef ARCH_MM_MMU
|
||||
int ret = -1;
|
||||
|
@ -951,7 +866,7 @@ int sys_unlink(const char *pathname)
|
|||
}
|
||||
|
||||
/* syscall: "nanosleep" ret: "int" args: "const struct timespec *" "struct timespec *" */
|
||||
int sys_nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
|
||||
sysret_t sys_nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
|
||||
{
|
||||
int ret = 0;
|
||||
dbg_log(DBG_LOG, "sys_nanosleep\n");
|
||||
|
@ -982,7 +897,7 @@ int sys_nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
|
|||
}
|
||||
|
||||
/* syscall: "gettimeofday" ret: "int" args: "struct timeval *" "struct timezone *" */
|
||||
int sys_gettimeofday(struct timeval *tp, struct timezone *tzp)
|
||||
sysret_t sys_gettimeofday(struct timeval *tp, struct timezone *tzp)
|
||||
{
|
||||
#ifdef ARCH_MM_MMU
|
||||
struct timeval t_k;
|
||||
|
@ -1014,30 +929,30 @@ int sys_gettimeofday(struct timeval *tp, struct timezone *tzp)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int sys_settimeofday(const struct timeval *tv, const struct timezone *tzp)
|
||||
sysret_t sys_settimeofday(const struct timeval *tv, const struct timezone *tzp)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sys_exec(char *filename, int argc, char **argv, char **envp)
|
||||
sysret_t sys_exec(char *filename, int argc, char **argv, char **envp)
|
||||
{
|
||||
return lwp_execve(filename, 0, argc, argv, envp);
|
||||
}
|
||||
|
||||
int sys_kill(int pid, int sig)
|
||||
sysret_t sys_kill(int pid, int sig)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = lwp_kill(pid, sig);
|
||||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
}
|
||||
|
||||
int sys_getpid(void)
|
||||
sysret_t sys_getpid(void)
|
||||
{
|
||||
return lwp_getpid();
|
||||
}
|
||||
|
||||
/* syscall: "getpriority" ret: "int" args: "int" "id_t" */
|
||||
int sys_getpriority(int which, id_t who)
|
||||
sysret_t sys_getpriority(int which, id_t who)
|
||||
{
|
||||
if (which == PRIO_PROCESS)
|
||||
{
|
||||
|
@ -1054,7 +969,7 @@ int sys_getpriority(int which, id_t who)
|
|||
}
|
||||
|
||||
/* syscall: "setpriority" ret: "int" args: "int" "id_t" "int" */
|
||||
int sys_setpriority(int which, id_t who, int prio)
|
||||
sysret_t sys_setpriority(int which, id_t who, int prio)
|
||||
{
|
||||
if (which == PRIO_PROCESS)
|
||||
{
|
||||
|
@ -1136,7 +1051,7 @@ void *sys_mmap2(void *addr, size_t length, int prot,
|
|||
return lwp_mmap2(addr, length, prot, flags, fd, pgoffset);
|
||||
}
|
||||
|
||||
int sys_munmap(void *addr, size_t length)
|
||||
sysret_t sys_munmap(void *addr, size_t length)
|
||||
{
|
||||
return lwp_munmap(addr);
|
||||
}
|
||||
|
@ -1147,7 +1062,7 @@ void *sys_mremap(void *old_address, size_t old_size,
|
|||
return (void *)-1;
|
||||
}
|
||||
|
||||
int sys_madvise(void *addr, size_t len, int behav)
|
||||
sysret_t sys_madvise(void *addr, size_t len, int behav)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
@ -1343,27 +1258,31 @@ rt_err_t sys_timer_create(clockid_t clockid, struct sigevent *restrict sevp, tim
|
|||
memset(&sevp_k, 0, sizeof(sevp_k));
|
||||
|
||||
/* musl passes `struct ksigevent` to kernel, we shoule only get size of that bytes */
|
||||
lwp_get_from_user(&sevp_k, (void *)sevp, sizeof(struct ksigevent));
|
||||
if (!lwp_get_from_user(&sevp_k, (void *)sevp, sizeof(struct ksigevent)))
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
lwp_get_from_user(&timerid_k, (void *)timerid, sizeof(timerid_k));
|
||||
|
||||
/* to protect unsafe implementation in current rt-smart toolchain */
|
||||
RT_ASSERT(((struct ksigevent *)sevp)->sigev_tid == *(int *)(&sevp_k.sigev_notify_function));
|
||||
|
||||
ret = timer_create(clockid, &sevp_k, &timerid_k);
|
||||
ret = _SYS_WRAP(timer_create(clockid, &sevp_k, &timerid_k));
|
||||
|
||||
/* ID should not extend 32-bits size for libc */
|
||||
RT_ASSERT((rt_ubase_t)timerid_k < UINT32_MAX);
|
||||
utimer = (rt_ubase_t)timerid_k;
|
||||
|
||||
if (ret != -RT_ERROR){
|
||||
lwp_put_to_user(sevp, (void *)&sevp_k, sizeof(struct ksigevent));
|
||||
lwp_put_to_user(timerid, (void *)&utimer, sizeof(utimer));
|
||||
if (ret != -RT_ERROR)
|
||||
{
|
||||
if (!lwp_put_to_user(sevp, (void *)&sevp_k, sizeof(struct ksigevent)) ||
|
||||
!lwp_put_to_user(timerid, (void *)&utimer, sizeof(utimer)))
|
||||
ret = -EINVAL;
|
||||
}
|
||||
#else
|
||||
ret = timer_create(clockid, sevp, timerid);
|
||||
ret = _SYS_WRAP(timer_create(clockid, sevp, timerid));
|
||||
#endif
|
||||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
rt_err_t sys_timer_delete(timer_t timerid)
|
||||
|
@ -1739,7 +1658,7 @@ static int lwp_copy_files(struct rt_lwp *dst, struct rt_lwp *src)
|
|||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
int _sys_fork(void)
|
||||
sysret_t _sys_fork(void)
|
||||
{
|
||||
rt_base_t level;
|
||||
int tid = 0;
|
||||
|
@ -1906,12 +1825,12 @@ size_t lwp_user_strlen(const char *s, int *err)
|
|||
|
||||
/* arm needs to wrap fork/clone call to preserved lr & caller saved regs */
|
||||
|
||||
rt_weak int sys_fork(void)
|
||||
rt_weak sysret_t sys_fork(void)
|
||||
{
|
||||
return _sys_fork();
|
||||
}
|
||||
|
||||
rt_weak int sys_vfork(void)
|
||||
rt_weak sysret_t sys_vfork(void)
|
||||
{
|
||||
return sys_fork();
|
||||
}
|
||||
|
@ -2232,7 +2151,7 @@ quit:
|
|||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
}
|
||||
|
||||
int sys_execve(const char *path, char *const argv[], char *const envp[])
|
||||
sysret_t sys_execve(const char *path, char *const argv[], char *const envp[])
|
||||
{
|
||||
int ret = -1;
|
||||
int argc = 0;
|
||||
|
@ -2531,7 +2450,7 @@ rt_thread_t sys_thread_self(void)
|
|||
|
||||
/* sys channel */
|
||||
|
||||
int sys_channel_open(const char *name, int flags)
|
||||
sysret_t sys_channel_open(const char *name, int flags)
|
||||
{
|
||||
return lwp_channel_open(FDT_TYPE_LWP, name, flags);
|
||||
}
|
||||
|
@ -2598,7 +2517,7 @@ static int sys_log_enable(int argc, char** argv)
|
|||
}
|
||||
MSH_CMD_EXPORT_ALIAS(sys_log_enable, sys_log, sys_log 1(enable)/0(disable));
|
||||
|
||||
int sys_log(const char* log, int size)
|
||||
sysret_t sys_log(const char* log, int size)
|
||||
{
|
||||
rt_device_t console = rt_console_get_device();
|
||||
|
||||
|
@ -2610,7 +2529,7 @@ int sys_log(const char* log, int size)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int sys_stat(const char *file, struct stat *buf)
|
||||
sysret_t sys_stat(const char *file, struct stat *buf)
|
||||
{
|
||||
int ret = 0;
|
||||
int err;
|
||||
|
@ -2644,7 +2563,7 @@ int sys_stat(const char *file, struct stat *buf)
|
|||
}
|
||||
copy_path[copy_len] = '\0';
|
||||
|
||||
ret = stat(copy_path, &statbuff);
|
||||
ret = _SYS_WRAP(stat(copy_path, &statbuff));
|
||||
rt_free(copy_path);
|
||||
|
||||
if (ret == 0)
|
||||
|
@ -2652,10 +2571,10 @@ int sys_stat(const char *file, struct stat *buf)
|
|||
lwp_put_to_user(buf, &statbuff, sizeof statbuff);
|
||||
}
|
||||
|
||||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sys_notimpl(void)
|
||||
sysret_t sys_notimpl(void)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
@ -2671,12 +2590,12 @@ void sys_hw_interrupt_enable(uint32_t level)
|
|||
}
|
||||
|
||||
#ifdef ARCH_MM_MMU
|
||||
int sys_shmget(size_t key, size_t size, int create)
|
||||
sysret_t sys_shmget(size_t key, size_t size, int create)
|
||||
{
|
||||
return lwp_shmget(key, size, create);
|
||||
}
|
||||
|
||||
int sys_shmrm(int id)
|
||||
sysret_t sys_shmrm(int id)
|
||||
{
|
||||
return lwp_shmrm(id);
|
||||
}
|
||||
|
@ -2686,7 +2605,7 @@ void* sys_shmat(int id, void* shm_vaddr)
|
|||
return lwp_shmat(id, shm_vaddr);
|
||||
}
|
||||
|
||||
int sys_shmdt(void* shm_vaddr)
|
||||
sysret_t sys_shmdt(void* shm_vaddr)
|
||||
{
|
||||
return lwp_shmdt(shm_vaddr);
|
||||
}
|
||||
|
@ -2709,7 +2628,7 @@ void *sys_shm_retain(void *mem)
|
|||
return lwp_shm_retain(mem);
|
||||
}
|
||||
|
||||
int sys_shm_free(void *mem)
|
||||
sysret_t sys_shm_free(void *mem)
|
||||
{
|
||||
if (!lwp_user_accessable(mem, sizeof (void *)))
|
||||
{
|
||||
|
@ -2763,7 +2682,7 @@ rt_ssize_t sys_device_write(rt_device_t dev, rt_off_t pos, const void *buffer, r
|
|||
|
||||
#ifdef RT_USING_SAL
|
||||
/* network interfaces */
|
||||
int sys_accept(int socket, struct musl_sockaddr *addr, socklen_t *addrlen)
|
||||
sysret_t sys_accept(int socket, struct musl_sockaddr *addr, socklen_t *addrlen)
|
||||
{
|
||||
int ret = -1;
|
||||
struct sockaddr ksa;
|
||||
|
@ -2807,7 +2726,7 @@ int sys_accept(int socket, struct musl_sockaddr *addr, socklen_t *addrlen)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int sys_bind(int socket, const struct musl_sockaddr *name, socklen_t namelen)
|
||||
sysret_t sys_bind(int socket, const struct musl_sockaddr *name, socklen_t namelen)
|
||||
{
|
||||
struct sockaddr sa;
|
||||
struct musl_sockaddr kname;
|
||||
|
@ -2831,12 +2750,12 @@ int sys_bind(int socket, const struct musl_sockaddr *name, socklen_t namelen)
|
|||
return bind(socket, &sa, namelen);
|
||||
}
|
||||
|
||||
int sys_shutdown(int socket, int how)
|
||||
sysret_t sys_shutdown(int socket, int how)
|
||||
{
|
||||
return shutdown(socket, how);
|
||||
}
|
||||
|
||||
int sys_getpeername (int socket, struct musl_sockaddr *name, socklen_t *namelen)
|
||||
sysret_t sys_getpeername(int socket, struct musl_sockaddr *name, socklen_t *namelen)
|
||||
{
|
||||
int ret = -1;
|
||||
struct sockaddr sa;
|
||||
|
@ -2880,7 +2799,7 @@ int sys_getpeername (int socket, struct musl_sockaddr *name, socklen_t *namelen)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int sys_getsockname (int socket, struct musl_sockaddr *name, socklen_t *namelen)
|
||||
sysret_t sys_getsockname(int socket, struct musl_sockaddr *name, socklen_t *namelen)
|
||||
{
|
||||
int ret = -1;
|
||||
struct sockaddr sa;
|
||||
|
@ -2922,7 +2841,7 @@ int sys_getsockname (int socket, struct musl_sockaddr *name, socklen_t *namelen)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int sys_getsockopt(int socket, int level, int optname, void *optval, socklen_t *optlen)
|
||||
sysret_t sys_getsockopt(int socket, int level, int optname, void *optval, socklen_t *optlen)
|
||||
{
|
||||
int ret;
|
||||
convert_sockopt(&level, &optname);
|
||||
|
@ -2931,7 +2850,7 @@ int sys_getsockopt(int socket, int level, int optname, void *optval, socklen_t *
|
|||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
}
|
||||
|
||||
int sys_setsockopt(int socket, int level, int optname, const void *optval, socklen_t optlen)
|
||||
sysret_t sys_setsockopt(int socket, int level, int optname, const void *optval, socklen_t optlen)
|
||||
{
|
||||
int ret;
|
||||
convert_sockopt(&level, &optname);
|
||||
|
@ -2939,7 +2858,7 @@ int sys_setsockopt(int socket, int level, int optname, const void *optval, sockl
|
|||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
}
|
||||
|
||||
int sys_connect(int socket, const struct musl_sockaddr *name, socklen_t namelen)
|
||||
sysret_t sys_connect(int socket, const struct musl_sockaddr *name, socklen_t namelen)
|
||||
{
|
||||
int ret;
|
||||
struct sockaddr sa;
|
||||
|
@ -2965,7 +2884,7 @@ int sys_connect(int socket, const struct musl_sockaddr *name, socklen_t namelen)
|
|||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
}
|
||||
|
||||
int sys_listen(int socket, int backlog)
|
||||
sysret_t sys_listen(int socket, int backlog)
|
||||
{
|
||||
return listen(socket, backlog);
|
||||
}
|
||||
|
@ -3003,7 +2922,7 @@ static int netflags_muslc_2_lwip(int flags)
|
|||
return flgs;
|
||||
}
|
||||
|
||||
int sys_recvfrom(int socket, void *mem, size_t len, int flags,
|
||||
sysret_t sys_recvfrom(int socket, void *mem, size_t len, int flags,
|
||||
struct musl_sockaddr *from, socklen_t *fromlen)
|
||||
{
|
||||
int flgs = 0;
|
||||
|
@ -3077,7 +2996,7 @@ int sys_recvfrom(int socket, void *mem, size_t len, int flags,
|
|||
#endif
|
||||
}
|
||||
|
||||
int sys_recv(int socket, void *mem, size_t len, int flags)
|
||||
sysret_t sys_recv(int socket, void *mem, size_t len, int flags)
|
||||
{
|
||||
int flgs = 0;
|
||||
int ret;
|
||||
|
@ -3087,7 +3006,7 @@ int sys_recv(int socket, void *mem, size_t len, int flags)
|
|||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
}
|
||||
|
||||
int sys_sendto(int socket, const void *dataptr, size_t size, int flags,
|
||||
sysret_t sys_sendto(int socket, const void *dataptr, size_t size, int flags,
|
||||
const struct musl_sockaddr *to, socklen_t tolen)
|
||||
{
|
||||
int flgs = 0;
|
||||
|
@ -3153,7 +3072,7 @@ int sys_sendto(int socket, const void *dataptr, size_t size, int flags,
|
|||
#endif
|
||||
}
|
||||
|
||||
int sys_send(int socket, const void *dataptr, size_t size, int flags)
|
||||
sysret_t sys_send(int socket, const void *dataptr, size_t size, int flags)
|
||||
{
|
||||
int ret;
|
||||
int flgs = 0;
|
||||
|
@ -3163,7 +3082,7 @@ int sys_send(int socket, const void *dataptr, size_t size, int flags)
|
|||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
}
|
||||
|
||||
int sys_socket(int domain, int type, int protocol)
|
||||
sysret_t sys_socket(int domain, int type, int protocol)
|
||||
{
|
||||
int fd = -1;
|
||||
int nonblock = 0;
|
||||
|
@ -3192,7 +3111,7 @@ out:
|
|||
return (fd < 0 ? GET_ERRNO() : fd);
|
||||
}
|
||||
|
||||
int sys_closesocket(int socket)
|
||||
sysret_t sys_closesocket(int socket)
|
||||
{
|
||||
return closesocket(socket);
|
||||
}
|
||||
|
@ -3221,7 +3140,7 @@ struct k_sigaction {
|
|||
unsigned mask[2];
|
||||
};
|
||||
|
||||
int sys_sigaction(int sig, const struct k_sigaction *act,
|
||||
sysret_t sys_sigaction(int sig, const struct k_sigaction *act,
|
||||
struct k_sigaction *oact, size_t sigsetsize)
|
||||
{
|
||||
int ret = -RT_EINVAL;
|
||||
|
@ -3279,7 +3198,7 @@ out:
|
|||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
}
|
||||
|
||||
int sys_sigprocmask(int how, const sigset_t *sigset, sigset_t *oset, size_t size)
|
||||
sysret_t sys_sigprocmask(int how, const sigset_t *sigset, sigset_t *oset, size_t size)
|
||||
{
|
||||
int ret = -1;
|
||||
lwp_sigset_t *pnewset = RT_NULL, *poldset = RT_NULL;
|
||||
|
@ -3346,7 +3265,7 @@ int sys_sigprocmask(int how, const sigset_t *sigset, sigset_t *oset, size_t size
|
|||
return (ret < 0 ? -EFAULT: ret);
|
||||
}
|
||||
|
||||
int sys_tkill(int tid, int sig)
|
||||
sysret_t sys_tkill(int tid, int sig)
|
||||
{
|
||||
#ifdef ARCH_MM_MMU
|
||||
rt_base_t level;
|
||||
|
@ -3363,7 +3282,7 @@ int sys_tkill(int tid, int sig)
|
|||
#endif
|
||||
}
|
||||
|
||||
int sys_thread_sigprocmask(int how, const lwp_sigset_t *sigset, lwp_sigset_t *oset, size_t size)
|
||||
sysret_t sys_thread_sigprocmask(int how, const lwp_sigset_t *sigset, lwp_sigset_t *oset, size_t size)
|
||||
{
|
||||
int ret = -1;
|
||||
lwp_sigset_t *pnewset = RT_NULL, *poldset = RT_NULL;
|
||||
|
@ -3431,7 +3350,7 @@ int sys_thread_sigprocmask(int how, const lwp_sigset_t *sigset, lwp_sigset_t *os
|
|||
}
|
||||
|
||||
#ifndef ARCH_MM_MMU
|
||||
int sys_lwp_sighandler_set(int sig, lwp_sighandler_t func)
|
||||
sysret_t sys_lwp_sighandler_set(int sig, lwp_sighandler_t func)
|
||||
{
|
||||
if (!lwp_user_accessable((void *)func, sizeof(lwp_sighandler_t)))
|
||||
{
|
||||
|
@ -3442,7 +3361,7 @@ int sys_lwp_sighandler_set(int sig, lwp_sighandler_t func)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int sys_thread_sighandler_set(int sig, lwp_sighandler_t func)
|
||||
sysret_t sys_thread_sighandler_set(int sig, lwp_sighandler_t func)
|
||||
{
|
||||
if (!lwp_user_accessable((void *)func, sizeof(lwp_sighandler_t)))
|
||||
{
|
||||
|
@ -3454,7 +3373,7 @@ int sys_thread_sighandler_set(int sig, lwp_sighandler_t func)
|
|||
}
|
||||
#endif /* not defined ARCH_MM_MMU */
|
||||
|
||||
int32_t sys_waitpid(int32_t pid, int *status, int options)
|
||||
sysret_t sys_waitpid(int32_t pid, int *status, int options)
|
||||
{
|
||||
int ret = -1;
|
||||
#ifdef ARCH_MM_MMU
|
||||
|
@ -3491,7 +3410,7 @@ struct musl_addrinfo
|
|||
struct musl_addrinfo *ai_next;
|
||||
};
|
||||
|
||||
int sys_getaddrinfo(const char *nodename,
|
||||
sysret_t sys_getaddrinfo(const char *nodename,
|
||||
const char *servname,
|
||||
const struct musl_addrinfo *hints,
|
||||
struct musl_addrinfo *res)
|
||||
|
@ -3617,7 +3536,7 @@ exit:
|
|||
}
|
||||
|
||||
#define HOSTENT_BUFSZ 512
|
||||
int sys_gethostbyname2_r(const char *name, int af, struct hostent *ret,
|
||||
sysret_t sys_gethostbyname2_r(const char *name, int af, struct hostent *ret,
|
||||
char *buf, size_t buflen,
|
||||
struct hostent **result, int *err)
|
||||
{
|
||||
|
@ -3741,7 +3660,7 @@ char *sys_getcwd(char *buf, size_t size)
|
|||
return (char *)strlen(buf);
|
||||
}
|
||||
|
||||
int sys_chdir(const char *path)
|
||||
sysret_t sys_chdir(const char *path)
|
||||
{
|
||||
#ifdef ARCH_MM_MMU
|
||||
int err = 0;
|
||||
|
@ -3759,7 +3678,7 @@ int sys_chdir(const char *path)
|
|||
#endif
|
||||
}
|
||||
|
||||
int sys_mkdir(const char *path, mode_t mode)
|
||||
sysret_t sys_mkdir(const char *path, mode_t mode)
|
||||
{
|
||||
#ifdef ARCH_MM_MMU
|
||||
int err = 0;
|
||||
|
@ -3777,7 +3696,7 @@ int sys_mkdir(const char *path, mode_t mode)
|
|||
#endif
|
||||
}
|
||||
|
||||
int sys_rmdir(const char *path)
|
||||
sysret_t sys_rmdir(const char *path)
|
||||
{
|
||||
#ifdef ARCH_MM_MMU
|
||||
int err = 0;
|
||||
|
@ -3798,6 +3717,7 @@ int sys_rmdir(const char *path)
|
|||
#ifdef RT_USING_MUSL
|
||||
typedef uint64_t ino_t;
|
||||
#endif
|
||||
|
||||
struct libc_dirent {
|
||||
ino_t d_ino;
|
||||
off_t d_off;
|
||||
|
@ -3805,7 +3725,8 @@ struct libc_dirent {
|
|||
unsigned char d_type;
|
||||
char d_name[256];
|
||||
};
|
||||
int sys_getdents(int fd, struct libc_dirent *dirp, size_t nbytes)
|
||||
|
||||
sysret_t sys_getdents(int fd, struct libc_dirent *dirp, size_t nbytes)
|
||||
{
|
||||
int ret = -1;
|
||||
struct dfs_fd *dfs_fd;
|
||||
|
@ -3861,8 +3782,9 @@ rt_err_t sys_get_errno(void)
|
|||
{
|
||||
return rt_get_errno();
|
||||
}
|
||||
|
||||
#ifdef ARCH_MM_MMU
|
||||
int sys_set_thread_area(void *p)
|
||||
sysret_t sys_set_thread_area(void *p)
|
||||
{
|
||||
rt_thread_t thread;
|
||||
|
||||
|
@ -3873,7 +3795,7 @@ int sys_set_thread_area(void *p)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int sys_set_tid_address(int *tidptr)
|
||||
sysret_t sys_set_tid_address(int *tidptr)
|
||||
{
|
||||
rt_thread_t thread;
|
||||
|
||||
|
@ -3889,12 +3811,12 @@ int sys_set_tid_address(int *tidptr)
|
|||
}
|
||||
#endif /* ARCH_MM_MMU */
|
||||
|
||||
int sys_gettid(void)
|
||||
sysret_t sys_gettid(void)
|
||||
{
|
||||
return rt_thread_self()->tid;
|
||||
}
|
||||
|
||||
int sys_access(const char *filename, int mode)
|
||||
sysret_t sys_access(const char *filename, int mode)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifdef ARCH_MM_MMU
|
||||
|
@ -3935,7 +3857,7 @@ int sys_access(const char *filename, int mode)
|
|||
#endif
|
||||
}
|
||||
|
||||
int sys_pipe(int fd[2])
|
||||
sysret_t sys_pipe(int fd[2])
|
||||
{
|
||||
int ret;
|
||||
if (!lwp_user_accessable((void *)fd, sizeof(int[2])))
|
||||
|
@ -3946,7 +3868,7 @@ int sys_pipe(int fd[2])
|
|||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
}
|
||||
|
||||
int sys_clock_settime(clockid_t clk, const struct timespec *ts)
|
||||
sysret_t sys_clock_settime(clockid_t clk, const struct timespec *ts)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifdef ARCH_MM_MMU
|
||||
|
@ -3984,7 +3906,7 @@ int sys_clock_settime(clockid_t clk, const struct timespec *ts)
|
|||
#endif
|
||||
}
|
||||
|
||||
int sys_clock_gettime(clockid_t clk, struct timespec *ts)
|
||||
sysret_t sys_clock_gettime(clockid_t clk, struct timespec *ts)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifdef ARCH_MM_MMU
|
||||
|
@ -4024,7 +3946,7 @@ int sys_clock_gettime(clockid_t clk, struct timespec *ts)
|
|||
#endif
|
||||
}
|
||||
|
||||
int sys_clock_nanosleep(clockid_t clk, int flags, const struct timespec *rqtp, struct timespec *rmtp)
|
||||
sysret_t sys_clock_nanosleep(clockid_t clk, int flags, const struct timespec *rqtp, struct timespec *rmtp)
|
||||
{
|
||||
int ret = 0;
|
||||
dbg_log(DBG_LOG, "sys_nanosleep\n");
|
||||
|
@ -4054,7 +3976,7 @@ int sys_clock_nanosleep(clockid_t clk, int flags, const struct timespec *rqtp, s
|
|||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
}
|
||||
|
||||
int sys_clock_getres(clockid_t clk, struct timespec *ts)
|
||||
sysret_t sys_clock_getres(clockid_t clk, struct timespec *ts)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifdef ARCH_MM_MMU
|
||||
|
@ -4080,7 +4002,7 @@ int sys_clock_getres(clockid_t clk, struct timespec *ts)
|
|||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
}
|
||||
|
||||
int sys_rename(const char *oldpath, const char *newpath)
|
||||
sysret_t sys_rename(const char *oldpath, const char *newpath)
|
||||
{
|
||||
int ret = -1;
|
||||
#ifdef ARCH_MM_MMU
|
||||
|
@ -4120,7 +4042,7 @@ struct rlimit {
|
|||
#define RLIMIT_MEMLOCK 8
|
||||
#define RLIMIT_AS 9
|
||||
|
||||
int sys_prlimit64(pid_t pid,
|
||||
sysret_t sys_prlimit64(pid_t pid,
|
||||
unsigned int resource,
|
||||
const struct rlimit *new_rlim,
|
||||
struct rlimit *old_rlim)
|
||||
|
@ -4128,7 +4050,7 @@ int sys_prlimit64(pid_t pid,
|
|||
return -ENOSYS;
|
||||
}
|
||||
|
||||
int sys_getrlimit(unsigned int resource, unsigned long rlim[2])
|
||||
sysret_t sys_getrlimit(unsigned int resource, unsigned long rlim[2])
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
|
@ -4156,19 +4078,19 @@ int sys_getrlimit(unsigned int resource, unsigned long rlim[2])
|
|||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
}
|
||||
|
||||
int sys_setrlimit(unsigned int resource, struct rlimit *rlim)
|
||||
sysret_t sys_setrlimit(unsigned int resource, struct rlimit *rlim)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
int sys_setsid(void)
|
||||
sysret_t sys_setsid(void)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = setsid();
|
||||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
}
|
||||
|
||||
int sys_getrandom(void *buf, size_t buflen, unsigned int flags)
|
||||
sysret_t sys_getrandom(void *buf, size_t buflen, unsigned int flags)
|
||||
{
|
||||
int ret = -1;
|
||||
int count = 0;
|
||||
|
@ -4294,7 +4216,7 @@ ssize_t sys_readlink(char* path, char *buf, size_t bufsz)
|
|||
return bufsz;
|
||||
}
|
||||
|
||||
int sys_setaffinity(pid_t pid, size_t size, void *set)
|
||||
sysret_t sys_setaffinity(pid_t pid, size_t size, void *set)
|
||||
{
|
||||
if (!lwp_user_accessable(set, sizeof(cpu_set_t)))
|
||||
{
|
||||
|
@ -4310,7 +4232,7 @@ int sys_setaffinity(pid_t pid, size_t size, void *set)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int sys_sched_setparam(pid_t pid, void *param)
|
||||
sysret_t sys_sched_setparam(pid_t pid, void *param)
|
||||
{
|
||||
struct sched_param *sched_param = (struct sched_param *)param;
|
||||
struct rt_lwp *lwp = NULL;
|
||||
|
@ -4336,7 +4258,7 @@ int sys_sched_setparam(pid_t pid, void *param)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int sys_sched_getparam(pid_t pid, void *param)
|
||||
sysret_t sys_sched_getparam(pid_t pid, void *param)
|
||||
{
|
||||
struct sched_param *sched_param = (struct sched_param *)param;
|
||||
struct rt_lwp *lwp = NULL;
|
||||
|
@ -4363,27 +4285,27 @@ int sys_sched_getparam(pid_t pid, void *param)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int sys_sched_get_priority_max(int policy)
|
||||
sysret_t sys_sched_get_priority_max(int policy)
|
||||
{
|
||||
if(policy < 0)
|
||||
{
|
||||
rt_set_errno(EINVAL);
|
||||
SET_ERRNO(EINVAL);
|
||||
return -rt_get_errno();
|
||||
}
|
||||
return RT_THREAD_PRIORITY_MAX;
|
||||
}
|
||||
|
||||
int sys_sched_get_priority_min(int policy)
|
||||
sysret_t sys_sched_get_priority_min(int policy)
|
||||
{
|
||||
if(policy < 0)
|
||||
{
|
||||
rt_set_errno(EINVAL);
|
||||
SET_ERRNO(EINVAL);
|
||||
return -rt_get_errno();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sys_sched_setscheduler(int tid, int policy, void *param)
|
||||
sysret_t sys_sched_setscheduler(int tid, int policy, void *param)
|
||||
{
|
||||
struct sched_param *sched_param = (struct sched_param *)param;
|
||||
rt_thread_t thread = lwp_tid_get_thread(tid);
|
||||
|
@ -4396,7 +4318,7 @@ int sys_sched_setscheduler(int tid, int policy, void *param)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int sys_sched_getscheduler(int tid, int *policy, void *param)
|
||||
sysret_t sys_sched_getscheduler(int tid, int *policy, void *param)
|
||||
{
|
||||
struct sched_param *sched_param = (struct sched_param *)param;
|
||||
rt_thread_t thread = lwp_tid_get_thread(tid);
|
||||
|
@ -4409,7 +4331,7 @@ int sys_sched_getscheduler(int tid, int *policy, void *param)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int sys_fsync(int fd)
|
||||
sysret_t sys_fsync(int fd)
|
||||
{
|
||||
int res = fsync(fd);
|
||||
if (res < 0)
|
||||
|
@ -4455,7 +4377,7 @@ mqd_t sys_mq_open(const char *name, int flags, mode_t mode, struct mq_attr *attr
|
|||
return mqdes;
|
||||
}
|
||||
|
||||
int sys_mq_unlink(const char *name)
|
||||
sysret_t sys_mq_unlink(const char *name)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifdef ARCH_MM_MMU
|
||||
|
@ -4487,7 +4409,7 @@ int sys_mq_unlink(const char *name)
|
|||
#endif
|
||||
}
|
||||
|
||||
int sys_mq_timedsend(mqd_t mqd, const char *msg, size_t len, unsigned prio, const struct timespec *at)
|
||||
sysret_t sys_mq_timedsend(mqd_t mqd, const char *msg, size_t len, unsigned prio, const struct timespec *at)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifdef ARCH_MM_MMU
|
||||
|
@ -4519,7 +4441,7 @@ int sys_mq_timedsend(mqd_t mqd, const char *msg, size_t len, unsigned prio, cons
|
|||
#endif
|
||||
}
|
||||
|
||||
int sys_mq_timedreceive(mqd_t mqd, char *restrict msg, size_t len, unsigned *restrict prio, const struct timespec *restrict at)
|
||||
sysret_t sys_mq_timedreceive(mqd_t mqd, char *restrict msg, size_t len, unsigned *restrict prio, const struct timespec *restrict at)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifdef ARCH_MM_MMU
|
||||
|
@ -4555,7 +4477,7 @@ int sys_mq_timedreceive(mqd_t mqd, char *restrict msg, size_t len, unsigned *res
|
|||
#endif
|
||||
}
|
||||
|
||||
int sys_mq_notify(mqd_t mqd, const struct sigevent *sev)
|
||||
sysret_t sys_mq_notify(mqd_t mqd, const struct sigevent *sev)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifdef ARCH_MM_MMU
|
||||
|
@ -4568,7 +4490,7 @@ int sys_mq_notify(mqd_t mqd, const struct sigevent *sev)
|
|||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
}
|
||||
|
||||
int sys_mq_getsetattr(mqd_t mqd, const struct mq_attr *restrict new, struct mq_attr *restrict old)
|
||||
sysret_t sys_mq_getsetattr(mqd_t mqd, const struct mq_attr *restrict new, struct mq_attr *restrict old)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifdef ARCH_MM_MMU
|
||||
|
@ -4613,7 +4535,7 @@ int sys_mq_getsetattr(mqd_t mqd, const struct mq_attr *restrict new, struct mq_a
|
|||
#endif
|
||||
}
|
||||
|
||||
int sys_mq_close(mqd_t mqd)
|
||||
sysret_t sys_mq_close(mqd_t mqd)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifdef ARCH_MM_MMU
|
||||
|
@ -4624,7 +4546,7 @@ int sys_mq_close(mqd_t mqd)
|
|||
return (ret < 0 ? GET_ERRNO() : ret);
|
||||
}
|
||||
|
||||
const static void* func_table[] =
|
||||
const static struct rt_syscall_def func_table[] =
|
||||
{
|
||||
SYSCALL_SIGN(sys_exit), /* 01 */
|
||||
SYSCALL_SIGN(sys_read),
|
||||
|
@ -4846,9 +4768,9 @@ const void *lwp_get_sys_api(rt_uint32_t number)
|
|||
else
|
||||
{
|
||||
number -= 1;
|
||||
if (number < sizeof(func_table) / sizeof(func_table[0]) / 2)
|
||||
if (number < sizeof(func_table) / sizeof(func_table[0]))
|
||||
{
|
||||
func = func_table[number << 1];
|
||||
func = func_table[number].func;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4866,12 +4788,12 @@ const char *lwp_get_syscall_name(rt_uint32_t number)
|
|||
else
|
||||
{
|
||||
number -= 1;
|
||||
if (number < sizeof(func_table) / sizeof(func_table[0]) / 2)
|
||||
if (number < sizeof(func_table) / sizeof(func_table[0]))
|
||||
{
|
||||
name = (char*)func_table[(number << 1) + 1];
|
||||
name = (char*)func_table[number].name;
|
||||
}
|
||||
}
|
||||
|
||||
// skip sys_
|
||||
return name + 4;
|
||||
return name;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
#ifndef __LWP_SYSCALL_H__
|
||||
#define __LWP_SYSCALL_H__
|
||||
|
||||
#include <syscall_generic.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <rtthread.h>
|
||||
#include <dfs_file.h>
|
||||
|
@ -46,55 +48,64 @@ void sys_exit(int value);
|
|||
ssize_t sys_read(int fd, void *buf, size_t nbyte);
|
||||
ssize_t sys_write(int fd, const void *buf, size_t nbyte);
|
||||
off_t sys_lseek(int fd, off_t offset, int whence);
|
||||
int sys_open(const char *name, int mode, ...);
|
||||
int sys_close(int fd);
|
||||
int sys_ioctl(int fd, unsigned long cmd, void* data);
|
||||
int sys_fstat(int file, struct stat *buf);
|
||||
int sys_poll(struct pollfd *fds, nfds_t nfds, int timeout);
|
||||
int sys_nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
|
||||
int sys_gettimeofday(struct timeval *tp, struct timezone *tzp);
|
||||
int sys_settimeofday(const struct timeval *tv, const struct timezone *tzp);
|
||||
int sys_exec(char *filename, int argc, char **argv, char **envp);
|
||||
int sys_kill(int pid, int sig);
|
||||
int sys_getpid(void);
|
||||
int sys_getpriority(int which, id_t who);
|
||||
int sys_setpriority(int which, id_t who, int prio);
|
||||
sysret_t sys_open(const char *name, int mode, ...);
|
||||
sysret_t sys_close(int fd);
|
||||
sysret_t sys_ioctl(int fd, unsigned long cmd, void* data);
|
||||
sysret_t sys_fstat(int file, struct stat *buf);
|
||||
sysret_t sys_poll(struct pollfd *fds, nfds_t nfds, int timeout);
|
||||
sysret_t sys_nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
|
||||
sysret_t sys_gettimeofday(struct timeval *tp, struct timezone *tzp);
|
||||
sysret_t sys_settimeofday(const struct timeval *tv, const struct timezone *tzp);
|
||||
sysret_t sys_exec(char *filename, int argc, char **argv, char **envp);
|
||||
sysret_t sys_kill(int pid, int sig);
|
||||
sysret_t sys_getpid(void);
|
||||
sysret_t sys_getpriority(int which, id_t who);
|
||||
sysret_t sys_setpriority(int which, id_t who, int prio);
|
||||
rt_sem_t sys_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag);
|
||||
rt_err_t sys_sem_delete(rt_sem_t sem);
|
||||
rt_err_t sys_sem_take(rt_sem_t sem, rt_int32_t time);
|
||||
rt_err_t sys_sem_release(rt_sem_t sem);
|
||||
sysret_t sys_sem_delete(rt_sem_t sem);
|
||||
sysret_t sys_sem_take(rt_sem_t sem, rt_int32_t time);
|
||||
sysret_t sys_sem_release(rt_sem_t sem);
|
||||
rt_mutex_t sys_mutex_create(const char *name, rt_uint8_t flag);
|
||||
rt_err_t sys_mutex_delete(rt_mutex_t mutex);
|
||||
rt_err_t sys_mutex_take(rt_mutex_t mutex, rt_int32_t time);
|
||||
rt_err_t sys_mutex_release(rt_mutex_t mutex);
|
||||
sysret_t sys_mutex_delete(rt_mutex_t mutex);
|
||||
sysret_t sys_mutex_take(rt_mutex_t mutex, rt_int32_t time);
|
||||
sysret_t sys_mutex_release(rt_mutex_t mutex);
|
||||
rt_event_t sys_event_create(const char *name, rt_uint8_t flag);
|
||||
rt_err_t sys_event_delete(rt_event_t event);
|
||||
rt_err_t sys_event_send(rt_event_t event, rt_uint32_t set);
|
||||
rt_err_t sys_event_recv(rt_event_t event, rt_uint32_t set, rt_uint8_t opt, rt_int32_t timeout, rt_uint32_t *recved);
|
||||
sysret_t sys_event_delete(rt_event_t event);
|
||||
sysret_t sys_event_send(rt_event_t event, rt_uint32_t set);
|
||||
sysret_t sys_event_recv(rt_event_t event, rt_uint32_t set, rt_uint8_t opt, rt_int32_t timeout, rt_uint32_t *recved);
|
||||
rt_mailbox_t sys_mb_create(const char *name, rt_size_t size, rt_uint8_t flag);
|
||||
rt_err_t sys_mb_delete(rt_mailbox_t mb);
|
||||
rt_err_t sys_mb_send(rt_mailbox_t mb, rt_ubase_t value);
|
||||
rt_err_t sys_mb_send_wait(rt_mailbox_t mb, rt_ubase_t value, rt_int32_t timeout);
|
||||
rt_err_t sys_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout);
|
||||
sysret_t sys_mb_delete(rt_mailbox_t mb);
|
||||
sysret_t sys_mb_send(rt_mailbox_t mb, rt_ubase_t value);
|
||||
sysret_t sys_mb_send_wait(rt_mailbox_t mb, rt_ubase_t value, rt_int32_t timeout);
|
||||
sysret_t sys_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout);
|
||||
rt_mq_t sys_mq_create(const char *name, rt_size_t msg_size, rt_size_t max_msgs, rt_uint8_t flag);
|
||||
rt_err_t sys_mq_delete(rt_mq_t mq);
|
||||
rt_err_t sys_mq_send(rt_mq_t mq, void *buffer, rt_size_t size);
|
||||
rt_err_t sys_mq_urgent(rt_mq_t mq, void *buffer, rt_size_t size);
|
||||
rt_err_t sys_mq_recv(rt_mq_t mq, void *buffer, rt_size_t size, rt_int32_t timeout);
|
||||
sysret_t sys_mq_delete(rt_mq_t mq);
|
||||
sysret_t sys_mq_send(rt_mq_t mq, void *buffer, rt_size_t size);
|
||||
sysret_t sys_mq_urgent(rt_mq_t mq, void *buffer, rt_size_t size);
|
||||
sysret_t sys_mq_recv(rt_mq_t mq, void *buffer, rt_size_t size, rt_int32_t timeout);
|
||||
rt_thread_t sys_thread_create(void *arg[]);
|
||||
rt_err_t sys_thread_delete(rt_thread_t thread);
|
||||
rt_err_t sys_thread_startup(rt_thread_t thread);
|
||||
sysret_t sys_thread_delete(rt_thread_t thread);
|
||||
sysret_t sys_thread_startup(rt_thread_t thread);
|
||||
rt_thread_t sys_thread_self(void);
|
||||
int sys_channel_open(const char *name, int flags);
|
||||
rt_err_t sys_channel_close(int fd);
|
||||
rt_err_t sys_channel_send(int fd, rt_channel_msg_t data);
|
||||
rt_err_t sys_channel_send_recv(int fd, rt_channel_msg_t data, rt_channel_msg_t data_ret);
|
||||
rt_err_t sys_channel_reply(int fd, rt_channel_msg_t data);
|
||||
rt_err_t sys_channel_recv(int fd, rt_channel_msg_t data);
|
||||
sysret_t sys_channel_open(const char *name, int flags);
|
||||
sysret_t sys_channel_close(int fd);
|
||||
sysret_t sys_channel_send(int fd, rt_channel_msg_t data);
|
||||
sysret_t sys_channel_send_recv(int fd, rt_channel_msg_t data, rt_channel_msg_t data_ret);
|
||||
sysret_t sys_channel_reply(int fd, rt_channel_msg_t data);
|
||||
sysret_t sys_channel_recv(int fd, rt_channel_msg_t data);
|
||||
void sys_enter_critical(void);
|
||||
void sys_exit_critical(void);
|
||||
|
||||
int sys_log(const char* log, int size);
|
||||
sysret_t sys_dup(int oldfd);
|
||||
sysret_t sys_dup2(int oldfd, int new);
|
||||
|
||||
sysret_t sys_log(const char* log, int size);
|
||||
|
||||
#ifdef ARCH_MM_MMU
|
||||
sysret_t sys_futex(int *uaddr, int op, int val, const struct timespec *timeout, int *uaddr2, int val3);
|
||||
sysret_t sys_pmutex(void *umutex, int op, void *arg);
|
||||
sysret_t sys_cacheflush(void *addr, int len, int cache);
|
||||
#endif /* ARCH_MM_MMU */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -6,12 +6,21 @@
|
|||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-11-10 RT-Thread The first version
|
||||
* 2023-03-13 WangXiaoyao syscall metadata as structure
|
||||
*/
|
||||
#ifndef __SYSCALL_DATA_H__
|
||||
#define __SYSCALL_DATA_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
typedef long sysret_t;
|
||||
|
||||
struct rt_syscall_def
|
||||
{
|
||||
void *func;
|
||||
char *name;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief signature for syscall, used to locate syscall metadata.
|
||||
*
|
||||
|
@ -20,13 +29,15 @@
|
|||
* which increases system booting time. We signature a pointer
|
||||
* just below each syscall entry in syscall table to make it
|
||||
* easy to locate every syscall's metadata by using syscall id.
|
||||
*
|
||||
* TODO Currently this adds a dummy pointer to syscall name.
|
||||
* After adding metadata of every syscalls in front of their definition,
|
||||
* this should be replaced by a pointer to that structure
|
||||
*/
|
||||
#define SYSCALL_SIGN(func) \
|
||||
(void *)func, \
|
||||
RT_STRINGIFY(func)
|
||||
#define SYSCALL_SIGN(func) { \
|
||||
(void *)(func), \
|
||||
&RT_STRINGIFY(func)[4], \
|
||||
}
|
||||
|
||||
#define SET_ERRNO(no) rt_set_errno(-(no))
|
||||
#define GET_ERRNO() ({int _errno = rt_get_errno(); _errno > 0 ? -_errno : _errno;})
|
||||
|
||||
#define _SYS_WRAP(func) ({int _ret = func; _ret < 0 ? GET_ERRNO() : _ret;})
|
||||
|
||||
#endif /* __SYSCALL_DATA_H__ */
|
|
@ -188,7 +188,7 @@ typedef __gnuc_va_list va_list;
|
|||
#define va_end(v) __builtin_va_end(v)
|
||||
#define va_arg(v,l) __builtin_va_arg(v,l)
|
||||
#endif /* RT_USING_LIBC */
|
||||
#define __RT_STRINGIFY(x...) #x
|
||||
#define __RT_STRINGIFY(x...) (#x)
|
||||
#define RT_STRINGIFY(x...) __RT_STRINGIFY(x)
|
||||
#define rt_section(x) __attribute__((section(x)))
|
||||
#define rt_used __attribute__((used))
|
||||
|
|
Loading…
Reference in New Issue