[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);
|
fdt_fd_release(fdt, fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sys_dup(int oldfd)
|
rt_err_t sys_dup(int oldfd)
|
||||||
{
|
{
|
||||||
int newfd = -1;
|
int newfd = -1;
|
||||||
struct dfs_fdtable *fdt = NULL;
|
struct dfs_fdtable *fdt = NULL;
|
||||||
|
@ -466,7 +466,7 @@ int fd_is_open(const char *pathname)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sys_dup2(int oldfd, int newfd)
|
rt_err_t sys_dup2(int oldfd, int newfd)
|
||||||
{
|
{
|
||||||
struct dfs_fdtable *fdt = NULL;
|
struct dfs_fdtable *fdt = NULL;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
|
@ -174,7 +174,9 @@ void futex_wake(struct rt_futex *futex, int number)
|
||||||
rt_schedule();
|
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)
|
int *uaddr2, int val3)
|
||||||
{
|
{
|
||||||
struct rt_lwp *lwp = RT_NULL;
|
struct rt_lwp *lwp = RT_NULL;
|
||||||
|
|
|
@ -418,7 +418,9 @@ static int _pthread_mutex_destroy(void *umutex)
|
||||||
return 0;
|
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;
|
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__ */
|
File diff suppressed because it is too large
Load Diff
|
@ -11,6 +11,8 @@
|
||||||
#ifndef __LWP_SYSCALL_H__
|
#ifndef __LWP_SYSCALL_H__
|
||||||
#define __LWP_SYSCALL_H__
|
#define __LWP_SYSCALL_H__
|
||||||
|
|
||||||
|
#include <syscall_generic.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include <dfs_file.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_read(int fd, void *buf, size_t nbyte);
|
||||||
ssize_t sys_write(int fd, const 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);
|
off_t sys_lseek(int fd, off_t offset, int whence);
|
||||||
int sys_open(const char *name, int mode, ...);
|
sysret_t sys_open(const char *name, int mode, ...);
|
||||||
int sys_close(int fd);
|
sysret_t sys_close(int fd);
|
||||||
int sys_ioctl(int fd, unsigned long cmd, void* data);
|
sysret_t sys_ioctl(int fd, unsigned long cmd, void* data);
|
||||||
int sys_fstat(int file, struct stat *buf);
|
sysret_t sys_fstat(int file, struct stat *buf);
|
||||||
int sys_poll(struct pollfd *fds, nfds_t nfds, int timeout);
|
sysret_t sys_poll(struct pollfd *fds, nfds_t nfds, int timeout);
|
||||||
int sys_nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
|
sysret_t sys_nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
|
||||||
int sys_gettimeofday(struct timeval *tp, struct timezone *tzp);
|
sysret_t sys_gettimeofday(struct timeval *tp, struct timezone *tzp);
|
||||||
int sys_settimeofday(const struct timeval *tv, const struct timezone *tzp);
|
sysret_t sys_settimeofday(const struct timeval *tv, const struct timezone *tzp);
|
||||||
int sys_exec(char *filename, int argc, char **argv, char **envp);
|
sysret_t sys_exec(char *filename, int argc, char **argv, char **envp);
|
||||||
int sys_kill(int pid, int sig);
|
sysret_t sys_kill(int pid, int sig);
|
||||||
int sys_getpid(void);
|
sysret_t sys_getpid(void);
|
||||||
int sys_getpriority(int which, id_t who);
|
sysret_t sys_getpriority(int which, id_t who);
|
||||||
int sys_setpriority(int which, id_t who, int prio);
|
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_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);
|
sysret_t sys_sem_delete(rt_sem_t sem);
|
||||||
rt_err_t sys_sem_take(rt_sem_t sem, rt_int32_t time);
|
sysret_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_release(rt_sem_t sem);
|
||||||
rt_mutex_t sys_mutex_create(const char *name, rt_uint8_t flag);
|
rt_mutex_t sys_mutex_create(const char *name, rt_uint8_t flag);
|
||||||
rt_err_t sys_mutex_delete(rt_mutex_t mutex);
|
sysret_t sys_mutex_delete(rt_mutex_t mutex);
|
||||||
rt_err_t sys_mutex_take(rt_mutex_t mutex, rt_int32_t time);
|
sysret_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_release(rt_mutex_t mutex);
|
||||||
rt_event_t sys_event_create(const char *name, rt_uint8_t flag);
|
rt_event_t sys_event_create(const char *name, rt_uint8_t flag);
|
||||||
rt_err_t sys_event_delete(rt_event_t event);
|
sysret_t sys_event_delete(rt_event_t event);
|
||||||
rt_err_t sys_event_send(rt_event_t event, rt_uint32_t set);
|
sysret_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_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_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);
|
sysret_t sys_mb_delete(rt_mailbox_t mb);
|
||||||
rt_err_t sys_mb_send(rt_mailbox_t mb, rt_ubase_t value);
|
sysret_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);
|
sysret_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_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_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);
|
sysret_t sys_mq_delete(rt_mq_t mq);
|
||||||
rt_err_t sys_mq_send(rt_mq_t mq, void *buffer, rt_size_t size);
|
sysret_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);
|
sysret_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_recv(rt_mq_t mq, void *buffer, rt_size_t size, rt_int32_t timeout);
|
||||||
rt_thread_t sys_thread_create(void *arg[]);
|
rt_thread_t sys_thread_create(void *arg[]);
|
||||||
rt_err_t sys_thread_delete(rt_thread_t thread);
|
sysret_t sys_thread_delete(rt_thread_t thread);
|
||||||
rt_err_t sys_thread_startup(rt_thread_t thread);
|
sysret_t sys_thread_startup(rt_thread_t thread);
|
||||||
rt_thread_t sys_thread_self(void);
|
rt_thread_t sys_thread_self(void);
|
||||||
int sys_channel_open(const char *name, int flags);
|
sysret_t sys_channel_open(const char *name, int flags);
|
||||||
rt_err_t sys_channel_close(int fd);
|
sysret_t sys_channel_close(int fd);
|
||||||
rt_err_t sys_channel_send(int fd, rt_channel_msg_t data);
|
sysret_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);
|
sysret_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);
|
sysret_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_recv(int fd, rt_channel_msg_t data);
|
||||||
void sys_enter_critical(void);
|
void sys_enter_critical(void);
|
||||||
void sys_exit_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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,21 @@
|
||||||
* Change Logs:
|
* Change Logs:
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2022-11-10 RT-Thread The first version
|
* 2022-11-10 RT-Thread The first version
|
||||||
|
* 2023-03-13 WangXiaoyao syscall metadata as structure
|
||||||
*/
|
*/
|
||||||
#ifndef __SYSCALL_DATA_H__
|
#ifndef __SYSCALL_DATA_H__
|
||||||
#define __SYSCALL_DATA_H__
|
#define __SYSCALL_DATA_H__
|
||||||
|
|
||||||
#include <rtthread.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.
|
* @brief signature for syscall, used to locate syscall metadata.
|
||||||
*
|
*
|
||||||
|
@ -20,13 +29,15 @@
|
||||||
* which increases system booting time. We signature a pointer
|
* which increases system booting time. We signature a pointer
|
||||||
* just below each syscall entry in syscall table to make it
|
* just below each syscall entry in syscall table to make it
|
||||||
* easy to locate every syscall's metadata by using syscall id.
|
* 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) \
|
#define SYSCALL_SIGN(func) { \
|
||||||
(void *)func, \
|
(void *)(func), \
|
||||||
RT_STRINGIFY(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__ */
|
#endif /* __SYSCALL_DATA_H__ */
|
|
@ -188,7 +188,7 @@ typedef __gnuc_va_list va_list;
|
||||||
#define va_end(v) __builtin_va_end(v)
|
#define va_end(v) __builtin_va_end(v)
|
||||||
#define va_arg(v,l) __builtin_va_arg(v,l)
|
#define va_arg(v,l) __builtin_va_arg(v,l)
|
||||||
#endif /* RT_USING_LIBC */
|
#endif /* RT_USING_LIBC */
|
||||||
#define __RT_STRINGIFY(x...) #x
|
#define __RT_STRINGIFY(x...) (#x)
|
||||||
#define RT_STRINGIFY(x...) __RT_STRINGIFY(x)
|
#define RT_STRINGIFY(x...) __RT_STRINGIFY(x)
|
||||||
#define rt_section(x) __attribute__((section(x)))
|
#define rt_section(x) __attribute__((section(x)))
|
||||||
#define rt_used __attribute__((used))
|
#define rt_used __attribute__((used))
|
||||||
|
|
Loading…
Reference in New Issue