Updated issues related to uds capacity and eventfd macro redefinition (#8329)

This commit is contained in:
zmq810150896 2023-12-06 13:51:13 +08:00 committed by GitHub
parent 1b0dae2bb0
commit 2790ce5357
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 107 additions and 30 deletions

View File

@ -25,7 +25,7 @@
#define EFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK) #define EFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)
#define EFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS | EFD_SEMAPHORE) #define EFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS | EFD_SEMAPHORE)
#define ULLONG_MAX (~0ULL) #define EFD_ULLONG_MAX (~0ULL)
#define EVENTFD_MUTEX_NAME "eventfd" #define EVENTFD_MUTEX_NAME "eventfd"
@ -84,10 +84,10 @@ static int eventfd_poll(struct dfs_file *file, struct rt_pollreq *req)
if (count > 0) if (count > 0)
events |= POLLIN; events |= POLLIN;
if (count == ULLONG_MAX) if (count == EFD_ULLONG_MAX)
events |= POLLERR; events |= POLLERR;
if ((ULLONG_MAX - 1) > count) if ((EFD_ULLONG_MAX - 1) > count)
events |= POLLOUT; events |= POLLOUT;
return events; return events;
@ -161,14 +161,14 @@ static ssize_t eventfd_write(struct dfs_file *file, const void *buf, size_t coun
counter_num = *(rt_uint64_t *)buf; counter_num = *(rt_uint64_t *)buf;
if (counter_num == ULLONG_MAX) if (counter_num == EFD_ULLONG_MAX)
return -EINVAL; return -EINVAL;
ret = -EAGAIN; ret = -EAGAIN;
rt_mutex_take(&ctx->lock, RT_WAITING_FOREVER); rt_mutex_take(&ctx->lock, RT_WAITING_FOREVER);
if ((ULLONG_MAX - ctx->count) > counter_num) if ((EFD_ULLONG_MAX - ctx->count) > counter_num)
{ {
ret = sizeof(counter_num); ret = sizeof(counter_num);
} }
@ -176,7 +176,7 @@ static ssize_t eventfd_write(struct dfs_file *file, const void *buf, size_t coun
{ {
for (;;) for (;;)
{ {
if ((ULLONG_MAX - ctx->count) >= counter_num) if ((EFD_ULLONG_MAX - ctx->count) >= counter_num)
{ {
ret = sizeof(counter_num); ret = sizeof(counter_num);
break; break;

View File

@ -3293,7 +3293,6 @@ sysret_t sys_bind(int socket, const struct musl_sockaddr *name, socklen_t namele
rt_err_t ret = 0; rt_err_t ret = 0;
struct sockaddr sa; struct sockaddr sa;
struct musl_sockaddr kname; struct musl_sockaddr kname;
struct sockaddr_un addr_un;
rt_uint16_t family = 0; rt_uint16_t family = 0;
if (!lwp_user_accessable((void *)name, namelen)) if (!lwp_user_accessable((void *)name, namelen))
@ -3302,16 +3301,16 @@ sysret_t sys_bind(int socket, const struct musl_sockaddr *name, socklen_t namele
} }
lwp_get_from_user(&family, (void *)name, 2); lwp_get_from_user(&family, (void *)name, 2);
if (family == AF_UNIX) if ((family == AF_UNIX) || (family == AF_NETLINK))
{ {
if (!lwp_user_accessable((void *)name, sizeof(struct sockaddr_un))) if (!lwp_user_accessable((void *)name, sizeof(struct sockaddr)))
{ {
return -EFAULT; return -EFAULT;
} }
lwp_get_from_user(&addr_un, (void *)name, sizeof(struct sockaddr_un)); lwp_get_from_user(&sa, (void *)name, sizeof(struct sockaddr));
ret = bind(socket, (struct sockaddr *)(&addr_un), namelen); ret = bind(socket, &sa, namelen);
} }
else else
{ {

View File

@ -0,0 +1,74 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-12-06 zmq810150896 The first version.
*/
#ifndef __SAL_MSG_H__
#define __SAL_MSG_H__
#include <rtthread.h>
/* message frame */
struct msg_buf
{
void *parm; /* Parameters for message detection */
void *buf; /* Data to be sent */
rt_size_t length; /* Data length */
void *control_data; /* Additional data to send the message */
rt_size_t data_len; /* Additional data length */
int msg_type; /* message type */
int data_type; /* Addittional data length */
int msg_level;
int *fd; /* Pass the array used by fd */
rt_slist_t msg_next; /* Next message */
rt_slist_t msg_node; /* sendmsg is used to send multiple messages at the same time */
};
/* Remaining message */
struct last_buf
{
void *buf; /* Data to be sent */
rt_size_t length; /* Data length */
rt_size_t offset; /* Data Offset */
struct msg_buf *msg;
};
/* sock */
struct unix_sock
{
rt_uint8_t len;
int flags;
uint8_t family; /* protocol */
char path[108]; /* file name */
struct unix_conn *conn; /* connecting processing */
rt_wqueue_t wq_head; /* Waiting queue head */
rt_atomic_t listen_num; /* Maximum listening quantity */
rt_atomic_t conn_counter; /* connected num */
struct rt_mutex sock_lock;
rt_slist_t wait_conn_head;
struct last_buf pbuf;
};
struct unix_conn
{
int state; /* connect state */
int type;
int proto;
rt_uint32_t send_timeout;
rt_uint32_t recv_timeout;
rt_wqueue_t wq_read_head;
rt_wqueue_t wq_confirm;
struct rt_mutex conn_lock;
rt_slist_t msg_head; /* message head */
rt_slist_t conn_node;
struct unix_sock *sock;
struct unix_sock *ser_sock;
struct unix_conn *correl_conn; /* Information about the other party */
int (* conn_callback)(struct unix_conn *conn); /* The callback function that establishes the connection */
};
#endif

View File

@ -118,7 +118,7 @@ typedef uint16_t in_port_t;
#define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */ #define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */
#define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */ #define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */
#define MSG_MORE 0x10 /* Sender will send more */ #define MSG_MORE 0x10 /* Sender will send more */
/* LWIPPTP_SWREQ_0036 */
#define MSG_ERRQUEUE 0x2000 /* Fetch message from error queue */ #define MSG_ERRQUEUE 0x2000 /* Fetch message from error queue */
#define MSG_CONFIRM 0x0800 /* Confirm path validity */ #define MSG_CONFIRM 0x0800 /* Confirm path validity */
@ -229,6 +229,16 @@ struct sockaddr_storage
#endif /* NETDEV_IPV6 */ #endif /* NETDEV_IPV6 */
}; };
#ifdef RT_USING_MUSLLIBC
#ifndef __DEFINED_struct_iovec
struct iovec
{
void *iov_base;
size_t iov_len;
};
#endif
#endif
struct msghdr struct msghdr
{ {
void *msg_name; void *msg_name;

View File

@ -168,7 +168,6 @@ int recv(int s, void *mem, size_t len, int flags)
} }
RTM_EXPORT(recv); RTM_EXPORT(recv);
/* LWIPPTP_SWREQ_0036 */
int sendmsg(int s, const struct msghdr *message, int flags) int sendmsg(int s, const struct msghdr *message, int flags)
{ {
int socket = dfs_net_getsocket(s); int socket = dfs_net_getsocket(s);
@ -177,7 +176,6 @@ int sendmsg(int s, const struct msghdr *message, int flags)
} }
RTM_EXPORT(sendmsg); RTM_EXPORT(sendmsg);
/* LWIPPTP_SWREQ_0036 */
int recvmsg(int s, struct msghdr *message, int flags) int recvmsg(int s, struct msghdr *message, int flags)
{ {
int socket = dfs_net_getsocket(s); int socket = dfs_net_getsocket(s);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2006-2022, RT-Thread Development Team * Copyright (c) 2006-2023, RT-Thread Development Team
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
* *
@ -34,10 +34,6 @@
#include <lwp_sys_socket.h> #include <lwp_sys_socket.h>
#endif #endif
#if defined(RT_USING_DFS_V2) && defined(SAL_USING_AF_UNIX)
#include <af_unix.h>
#endif
/* check system workqueue stack size */ /* check system workqueue stack size */
#if defined(SAL_INTERNET_CHECK) && RT_SYSTEM_WORKQUEUE_STACKSIZE < 1536 #if defined(SAL_INTERNET_CHECK) && RT_SYSTEM_WORKQUEUE_STACKSIZE < 1536
#error "The system workqueue stack size must more than 1536 bytes" #error "The system workqueue stack size must more than 1536 bytes"