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_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS | EFD_SEMAPHORE)
#define ULLONG_MAX (~0ULL)
#define EFD_ULLONG_MAX (~0ULL)
#define EVENTFD_MUTEX_NAME "eventfd"
@ -84,10 +84,10 @@ static int eventfd_poll(struct dfs_file *file, struct rt_pollreq *req)
if (count > 0)
events |= POLLIN;
if (count == ULLONG_MAX)
if (count == EFD_ULLONG_MAX)
events |= POLLERR;
if ((ULLONG_MAX - 1) > count)
if ((EFD_ULLONG_MAX - 1) > count)
events |= POLLOUT;
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;
if (counter_num == ULLONG_MAX)
if (counter_num == EFD_ULLONG_MAX)
return -EINVAL;
ret = -EAGAIN;
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);
}
@ -176,7 +176,7 @@ static ssize_t eventfd_write(struct dfs_file *file, const void *buf, size_t coun
{
for (;;)
{
if ((ULLONG_MAX - ctx->count) >= counter_num)
if ((EFD_ULLONG_MAX - ctx->count) >= counter_num)
{
ret = sizeof(counter_num);
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;
struct sockaddr sa;
struct musl_sockaddr kname;
struct sockaddr_un addr_un;
rt_uint16_t family = 0;
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);
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;
}
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
{

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

@ -48,17 +48,17 @@ typedef uint16_t in_port_t;
#define SO_KEEPALIVE 0x0008 /* keep connections alive */
#define SO_BROADCAST 0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
#define SO_PASSCRED 16
#define SO_PEERCRED 17
#define SO_PASSCRED 16
#define SO_PEERCRED 17
#define SO_BINDTODEVICE 25
#define SO_ATTACH_FILTER 26
#define SO_DETACH_FILTER 27
#define SO_SNDBUFFORCE 32
#define SO_RCVBUFFORCE 33
#define SO_PROTOCOL 38
#define SO_DOMAIN 39
#define SO_SNDBUFFORCE 32
#define SO_RCVBUFFORCE 33
#define SO_PROTOCOL 38
#define SO_DOMAIN 39
/* Additional options, not kept in so_options */
#define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info recording */
@ -81,7 +81,7 @@ typedef uint16_t in_port_t;
#define SO_NO_CHECK 0x100a /* don't create UDP checksum */
/* Level number for (get/set)sockopt() to apply to socket itself */
#define SOL_SOCKET 0xfff /* options for socket level */
#define SOL_SOCKET 0xfff /* options for socket level */
#define SOL_NETLINK 270
#define AF_UNSPEC 0
@ -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_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */
#define MSG_MORE 0x10 /* Sender will send more */
/* LWIPPTP_SWREQ_0036 */
#define MSG_ERRQUEUE 0x2000 /* Fetch message from error queue */
#define MSG_CONFIRM 0x0800 /* Confirm path validity */
@ -169,8 +169,8 @@ typedef struct ip_mreq
#define IPTOS_PREC_ROUTINE 0x00
#define SCM_RIGHTS 0x01 /* rw: access rights (array of int) */
#define SCM_CREDENTIALS 0x02 /* rw: struct ucred */
#define SCM_SECURITY 0x03 /* rw: security label */
#define SCM_CREDENTIALS 0x02 /* rw: struct ucred */
#define SCM_SECURITY 0x03 /* rw: security label */
/* Options for shatdown type */
#ifndef SHUT_RD
@ -229,6 +229,16 @@ struct sockaddr_storage
#endif /* NETDEV_IPV6 */
};
#ifdef RT_USING_MUSLLIBC
#ifndef __DEFINED_struct_iovec
struct iovec
{
void *iov_base;
size_t iov_len;
};
#endif
#endif
struct msghdr
{
void *msg_name;

View File

@ -168,7 +168,6 @@ int recv(int s, void *mem, size_t len, int flags)
}
RTM_EXPORT(recv);
/* LWIPPTP_SWREQ_0036 */
int sendmsg(int s, const struct msghdr *message, int flags)
{
int socket = dfs_net_getsocket(s);
@ -177,7 +176,6 @@ int sendmsg(int s, const struct msghdr *message, int flags)
}
RTM_EXPORT(sendmsg);
/* LWIPPTP_SWREQ_0036 */
int recvmsg(int s, struct msghdr *message, int flags)
{
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
*
@ -34,10 +34,6 @@
#include <lwp_sys_socket.h>
#endif
#if defined(RT_USING_DFS_V2) && defined(SAL_USING_AF_UNIX)
#include <af_unix.h>
#endif
/* check system workqueue stack size */
#if defined(SAL_INTERNET_CHECK) && RT_SYSTEM_WORKQUEUE_STACKSIZE < 1536
#error "The system workqueue stack size must more than 1536 bytes"
@ -65,7 +61,7 @@ struct sal_netdev_res_table
struct ifconf
{
int ifc_len; /* Size of buffer. */
int ifc_len; /* Size of buffer. */
union
{
char* ifcu_buf;
@ -1158,7 +1154,7 @@ int sal_closesocket(int socket)
#define ARPHRD_ETHER 1 /* Ethernet 10/100Mbps. */
#define ARPHRD_LOOPBACK 772 /* Loopback device. */
#define IFF_UP 0x1
#define IFF_UP 0x1
#define IFF_RUNNING 0x40
#define IFF_NOARP 0x80