[libbsd 16/22] Move socket system calls, avoid VFS

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Jun 24 06:33:44 UTC 2022


Collecting all system calls in a single translation unit is not good due to the
library initialization through linker sets.

Revert commit 6514d561587fd1527fe6a26cb43e6b5742c8c779 in the socket API
implementation files.  The goal is to use USB, network, PCI, and NVMe support
without the VFS to reduce the memory and runtime overhead introduced by VFS.

Update #4475.
---
 freebsd/sys/kern/sys_socket.c          | 271 ++++++++++++-
 freebsd/sys/kern/uipc_socket.c         |  27 +-
 freebsd/sys/kern/uipc_syscalls.c       | 516 +++++++++++++++++++++++--
 freebsd/sys/kern/uipc_usrreq.c         |  16 +-
 freebsd/sys/sys/socketvar.h            |  14 +-
 freebsd/sys/sys/sysproto.h             |  10 +-
 rtemsbsd/rtems/rtems-bsd-syscall-api.c | 366 ------------------
 testsuite/syscalls01/test_main.c       |   6 +-
 8 files changed, 774 insertions(+), 452 deletions(-)

diff --git a/freebsd/sys/kern/sys_socket.c b/freebsd/sys/kern/sys_socket.c
index 2fde0dd1..587a9806 100644
--- a/freebsd/sys/kern/sys_socket.c
+++ b/freebsd/sys/kern/sys_socket.c
@@ -33,6 +33,9 @@
  *	@(#)sys_socket.c	8.1 (Berkeley) 6/10/93
  */
 
+#ifdef __rtems__
+#include <rtems/bsd/sys/file.h>
+#endif /* __rtems__ */
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
@@ -79,7 +82,6 @@ __FBSDID("$FreeBSD$");
 #include <vm/pmap.h>
 #include <vm/vm_extern.h>
 #include <vm/vm_map.h>
-#endif /* __rtems__ */
 
 static SYSCTL_NODE(_kern_ipc, OID_AUTO, aio, CTLFLAG_RD, NULL,
     "socket AIO stats");
@@ -96,7 +98,9 @@ static fo_rdwr_t soo_read;
 static fo_rdwr_t soo_write;
 static fo_ioctl_t soo_ioctl;
 static fo_poll_t soo_poll;
+#endif /* __rtems__ */
 extern fo_kqfilter_t soo_kqfilter;
+#ifndef __rtems__
 static fo_stat_t soo_stat;
 static fo_close_t soo_close;
 static fo_fill_kinfo_t soo_fill_kinfo;
@@ -120,8 +124,13 @@ struct fileops	socketops = {
 	.fo_aio_queue = soo_aio_queue,
 	.fo_flags = DFLAG_PASSABLE
 };
+#endif /* __rtems__ */
 
+#ifdef __rtems__
+int
+#else /* __rtems__ */
 static int
+#endif /* __rtems__ */
 soo_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
     int flags, struct thread *td)
 {
@@ -136,8 +145,74 @@ soo_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
 	error = soreceive(so, 0, uio, 0, 0, 0);
 	return (error);
 }
+#ifdef __rtems__
+static ssize_t
+rtems_bsd_soo_read(rtems_libio_t *iop, void *buffer, size_t count)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct iovec iov = {
+		.iov_base = buffer,
+		.iov_len = count
+	};
+	struct uio auio = {
+		.uio_iov = &iov,
+		.uio_iovcnt = 1,
+		.uio_offset = 0,
+		.uio_resid = count,
+		.uio_segflg = UIO_USERSPACE,
+		.uio_rw = UIO_READ,
+		.uio_td = td
+	};
+	int error;
+
+	if (td != NULL) {
+		error = soo_read(iop, &auio, NULL, 0, NULL);
+	} else {
+		error = ENOMEM;
+	}
 
+	if (error == 0) {
+		return (count - auio.uio_resid);
+	} else {
+		rtems_set_errno_and_return_minus_one(error);
+	}
+}
+
+static ssize_t
+rtems_bsd_soo_readv(rtems_libio_t *iop, const struct iovec *iov,
+    int iovcnt, ssize_t total)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct uio auio = {
+		.uio_iov = __DECONST(struct iovec *, iov),
+		.uio_iovcnt = iovcnt,
+		.uio_offset = 0,
+		.uio_resid = total,
+		.uio_segflg = UIO_USERSPACE,
+		.uio_rw = UIO_READ,
+		.uio_td = td
+	};
+	int error;
+
+	if (td != NULL) {
+		error = soo_read(iop, &auio, NULL, 0, NULL);
+	} else {
+		error = ENOMEM;
+	}
+
+	if (error == 0) {
+		return (total - auio.uio_resid);
+	} else {
+		rtems_set_errno_and_return_minus_one(error);
+	}
+}
+#endif /* __rtems__ */
+
+#ifdef __rtems__
+int
+#else /* __rtems__ */
 static int
+#endif /* __rtems__ */
 soo_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
     int flags, struct thread *td)
 {
@@ -161,8 +236,74 @@ soo_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
 	}
 	return (error);
 }
+#ifdef __rtems__
+static ssize_t
+rtems_bsd_soo_write(rtems_libio_t *iop, const void *buffer, size_t count)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct iovec iov = {
+		.iov_base = __DECONST(void *, buffer),
+		.iov_len = count
+	};
+	struct uio auio = {
+		.uio_iov = &iov,
+		.uio_iovcnt = 1,
+		.uio_offset = 0,
+		.uio_resid = count,
+		.uio_segflg = UIO_USERSPACE,
+		.uio_rw = UIO_WRITE,
+		.uio_td = td
+	};
+	int error;
+
+	if (td != NULL) {
+		error = soo_write(iop, &auio, NULL, 0, NULL);
+	} else {
+		error = ENOMEM;
+	}
+
+	if (error == 0) {
+		return (count - auio.uio_resid);
+	} else {
+		rtems_set_errno_and_return_minus_one(error);
+	}
+}
+
+static ssize_t
+rtems_bsd_soo_writev(rtems_libio_t *iop, const struct iovec *iov,
+    int iovcnt, ssize_t total)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct uio auio = {
+		.uio_iov = __DECONST(struct iovec *, iov),
+		.uio_iovcnt = iovcnt,
+		.uio_offset = 0,
+		.uio_resid = total,
+		.uio_segflg = UIO_USERSPACE,
+		.uio_rw = UIO_WRITE,
+		.uio_td = td
+	};
+	int error;
 
+	if (td != NULL) {
+		error = soo_write(iop, &auio, NULL, 0, NULL);
+	} else {
+		error = ENOMEM;
+	}
+
+	if (error == 0) {
+		return (total - auio.uio_resid);
+	} else {
+		rtems_set_errno_and_return_minus_one(error);
+	}
+}
+#endif /* __rtems__ */
+
+#ifdef __rtems__
+int
+#else /* __rtems__ */
 static int
+#endif /* __rtems__ */
 soo_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *active_cred,
     struct thread *td)
 {
@@ -274,8 +415,28 @@ soo_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *active_cred,
 	}
 	return (error);
 }
+#ifdef __rtems__
+static int
+rtems_bsd_soo_ioctl(rtems_libio_t *iop, ioctl_command_t request, void *buffer)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	int error;
 
+	if (td != NULL) {
+		error = soo_ioctl(iop, request, buffer, NULL, td);
+	} else {
+		error = ENOMEM;
+	}
+
+	return rtems_bsd_error_to_status_and_errno(error);
+}
+#endif /* __rtems__ */
+
+#ifdef __rtems__
+int
+#else /* __rtems__ */
 static int
+#endif /* __rtems__ */
 soo_poll(struct file *fp, int events, struct ucred *active_cred,
     struct thread *td)
 {
@@ -287,19 +448,47 @@ soo_poll(struct file *fp, int events, struct ucred *active_cred,
 	if (error)
 		return (error);
 #endif
+#ifndef __rtems__
 	return (sopoll(so, events, fp->f_cred, td));
+#else /* __rtems__ */
+	return (sopoll(so, events, NULL, td));
+#endif /* __rtems__ */
 }
+#ifdef __rtems__
+static int
+rtems_bsd_soo_poll(rtems_libio_t *iop, int events)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	int error;
+
+	if (td != NULL) {
+		error = soo_poll(iop, events, NULL, td);
+	} else {
+		error = ENOMEM;
+	}
 
+	return (error);
+}
+#endif /* __rtems__ */
+
+#ifndef __rtems__
 int
 soo_stat(struct file *fp, struct stat *ub, struct ucred *active_cred,
     struct thread *td)
 {
 	struct socket *so = fp->f_data;
+#else /* __rtems__ */
+static int
+soo_stat(struct socket *so, struct stat *ub)
+{
+#endif /* __rtems__ */
 #ifdef MAC
 	int error;
 #endif
 
+#ifndef __rtems__
 	bzero((caddr_t)ub, sizeof (*ub));
+#endif /* __rtems__ */
 	ub->st_mode = S_IFSOCK;
 #ifdef MAC
 	error = mac_socket_check_stat(active_cred, so);
@@ -335,6 +524,19 @@ soo_stat(struct file *fp, struct stat *ub, struct ucred *active_cred,
 #endif /* __rtems__ */
 	return (*so->so_proto->pr_usrreqs->pru_sense)(so, ub);
 }
+#ifdef __rtems__
+static int
+rtems_bsd_soo_stat(
+	const rtems_filesystem_location_info_t *loc,
+	struct stat *buf
+)
+{
+	struct socket *so = rtems_bsd_loc_to_f_data(loc);
+	int error = soo_stat(so, buf);
+
+	return rtems_bsd_error_to_status_and_errno(error);
+}
+#endif /* __rtems__ */
 
 /*
  * API socket close on file pointer.  We call soclose() to close the socket
@@ -342,15 +544,27 @@ soo_stat(struct file *fp, struct stat *ub, struct ucred *active_cred,
  * file reference but the actual socket will not go away until the socket's
  * ref count hits 0.
  */
+#ifdef __rtems__
+int
+#else /* __rtems__ */
 static int
+#endif /* __rtems__ */
 soo_close(struct file *fp, struct thread *td)
 {
 	int error = 0;
 	struct socket *so;
 
+#ifdef __rtems__
+	/* FIXME: Move this to the RTEMS close() function */
+	knote_fdclose(td, rtems_libio_iop_to_descriptor(fp));
+#endif /* __rtems__ */
 
 	so = fp->f_data;
+#ifndef __rtems__
 	fp->f_ops = &badfileops;
+#else /* __rtems__ */
+	fp->pathinfo.handlers = &rtems_filesystem_handlers_default;
+#endif /* __rtems__ */
 	fp->f_data = NULL;
 
 	if (so)
@@ -358,6 +572,7 @@ soo_close(struct file *fp, struct thread *td)
 	return (error);
 }
 
+#ifndef __rtems__
 static int
 soo_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp)
 {
@@ -426,7 +641,6 @@ soo_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp)
 	return (0);	
 }
 
-#ifndef __rtems__
 /*
  * Use the 'backend3' field in AIO jobs to store the amount of data
  * completed by the AIO job so far.
@@ -799,12 +1013,10 @@ soo_aio_cancel(struct kaiocb *job)
 	else
 		aio_cancel(job);
 }
-#endif /* __rtems__ */
 
 static int
 soo_aio_queue(struct file *fp, struct kaiocb *job)
 {
-#ifndef __rtems__
 	struct socket *so;
 	struct sockbuf *sb;
 	int error;
@@ -837,7 +1049,54 @@ soo_aio_queue(struct file *fp, struct kaiocb *job)
 	}
 	SOCKBUF_UNLOCK(sb);
 	return (0);
-#else /* __rtems__ */
-	return (EIO);
+}
 #endif /* __rtems__ */
+#ifdef __rtems__
+static int
+rtems_bsd_soo_open(rtems_libio_t *iop, const char *path, int oflag,
+    mode_t mode)
+{
+	return rtems_bsd_error_to_status_and_errno(ENXIO);
+}
+
+static int
+rtems_bsd_soo_close(rtems_libio_t *iop)
+{
+	int error = soo_close(iop, NULL);
+
+	return rtems_bsd_error_to_status_and_errno(error);
 }
+
+static int
+rtems_bsd_soo_fcntl(rtems_libio_t *iop, int cmd)
+{
+	int error = 0;
+
+	if (cmd == F_SETFL) {
+		int nbio = iop->flags & LIBIO_FLAGS_NO_DELAY;
+
+		error = soo_ioctl(iop, FIONBIO, &nbio, NULL, NULL);
+	}
+
+	return rtems_bsd_error_to_status_and_errno(error);
+}
+
+const rtems_filesystem_file_handlers_r socketops = {
+	.open_h = rtems_bsd_soo_open,
+	.close_h = rtems_bsd_soo_close,
+	.read_h = rtems_bsd_soo_read,
+	.write_h = rtems_bsd_soo_write,
+	.ioctl_h = rtems_bsd_soo_ioctl,
+	.lseek_h = rtems_filesystem_default_lseek,
+	.fstat_h = rtems_bsd_soo_stat,
+	.ftruncate_h = rtems_filesystem_default_ftruncate,
+	.fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
+	.fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
+	.fcntl_h = rtems_bsd_soo_fcntl,
+	.poll_h = rtems_bsd_soo_poll,
+	.kqfilter_h = soo_kqfilter,
+	.readv_h = rtems_bsd_soo_readv,
+	.writev_h = rtems_bsd_soo_writev,
+	.mmap_h = rtems_filesystem_default_mmap
+};
+#endif /* __rtems__ */
diff --git a/freebsd/sys/kern/uipc_socket.c b/freebsd/sys/kern/uipc_socket.c
index 9c05a228..ddc3c6c1 100644
--- a/freebsd/sys/kern/uipc_socket.c
+++ b/freebsd/sys/kern/uipc_socket.c
@@ -104,6 +104,9 @@
  * sopoll() currently does not need a VNET context to be set.
  */
 
+#ifdef __rtems__
+#include <rtems/bsd/sys/file.h>
+#endif /* __rtems__ */
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
@@ -3384,11 +3387,7 @@ sopoll_generic(struct socket *so, int events, struct ucred *active_cred,
 int
 soo_kqfilter(struct file *fp, struct knote *kn)
 {
-#ifndef __rtems__
 	struct socket *so = kn->kn_fp->f_data;
-#else /* __rtems__ */
-	struct socket *so = rtems_bsd_knote_to_file(kn)->f_data;
-#endif /* __rtems__ */
 	struct sockbuf *sb;
 	struct knlist *knl;
 
@@ -3598,11 +3597,7 @@ pru_sopoll_notsupp(struct socket *so, int events, struct ucred *cred,
 static void
 filt_sordetach(struct knote *kn)
 {
-#ifndef __rtems__
 	struct socket *so = kn->kn_fp->f_data;
-#else /* __rtems__ */
-	struct socket *so = rtems_bsd_knote_to_file(kn)->f_data;
-#endif /* __rtems__ */
 
 	so_rdknl_lock(so);
 	knlist_remove(&so->so_rdsel.si_note, kn, 1);
@@ -3617,11 +3612,7 @@ filt_soread(struct knote *kn, long hint)
 {
 	struct socket *so;
 
-#ifndef __rtems__
 	so = kn->kn_fp->f_data;
-#else /* __rtems__ */
-	so = rtems_bsd_knote_to_file(kn)->f_data;
-#endif /* __rtems__ */
 
 	if (SOLISTENING(so)) {
 		SOCK_LOCK_ASSERT(so);
@@ -3657,11 +3648,7 @@ filt_soread(struct knote *kn, long hint)
 static void
 filt_sowdetach(struct knote *kn)
 {
-#ifndef __rtems__
 	struct socket *so = kn->kn_fp->f_data;
-#else /* __rtems__ */
-	struct socket *so = rtems_bsd_knote_to_file(kn)->f_data;
-#endif /* __rtems__ */
 
 	so_wrknl_lock(so);
 	knlist_remove(&so->so_wrsel.si_note, kn, 1);
@@ -3676,11 +3663,7 @@ filt_sowrite(struct knote *kn, long hint)
 {
 	struct socket *so;
 
-#ifndef __rtems__
 	so = kn->kn_fp->f_data;
-#else /* __rtems__ */
-	so = rtems_bsd_knote_to_file(kn)->f_data;
-#endif /* __rtems__ */
 
 	if (SOLISTENING(so))
 		return (0);
@@ -3710,11 +3693,7 @@ filt_soempty(struct knote *kn, long hint)
 {
 	struct socket *so;
 
-#ifndef __rtems__
 	so = kn->kn_fp->f_data;
-#else /* __rtems__ */
-	so = rtems_bsd_knote_to_file(kn)->f_data;
-#endif /* __rtems__ */
 
 	if (SOLISTENING(so))
 		return (1);
diff --git a/freebsd/sys/kern/uipc_syscalls.c b/freebsd/sys/kern/uipc_syscalls.c
index 50413091..69beefb7 100644
--- a/freebsd/sys/kern/uipc_syscalls.c
+++ b/freebsd/sys/kern/uipc_syscalls.c
@@ -33,6 +33,9 @@
  *	@(#)uipc_syscalls.c	8.4 (Berkeley) 2/21/94
  */
 
+#ifdef __rtems__
+#include <rtems/bsd/sys/file.h>
+#endif /* __rtems__ */
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
@@ -78,9 +81,9 @@ __FBSDID("$FreeBSD$");
 static int sendit(struct thread *td, int s, struct msghdr *mp, int flags);
 static int recvit(struct thread *td, int s, struct msghdr *mp, void *namelenp);
 
+#ifndef __rtems__
 static int accept1(struct thread *td, int s, struct sockaddr *uname,
 		   socklen_t *anamelen, int flags);
-#ifndef __rtems__
 static int getsockname1(struct thread *td, struct getsockname_args *uap,
 			int compat);
 static int getpeername1(struct thread *td, struct getpeername_args *uap,
@@ -90,26 +93,15 @@ struct getsockaddr_sockaddr {
 	struct sockaddr	header;
 	char		data[SOCK_MAXADDRLEN - sizeof(struct sockaddr)];
 } __aligned(sizeof(long));
-/*
- * The getsockaddr is used else where with an allocation. Having a version
- * local that does not alloc is a nice optimisation but we need to maintain
- * the exported version. See nfs_mount in nfs_clvfsops.c.
- */
-static int
-getsockaddr_noalloc(struct sockaddr **namp, const struct sockaddr *uaddr, size_t len)
-{
-	struct sockaddr *sa;
 
-	if (len > SOCK_MAXADDRLEN)
-		return (ENAMETOOLONG);
-	if (len < offsetof(struct sockaddr, sa_data[0]))
-		return (EINVAL);
-	sa = memcpy(*namp, uaddr, len);
-	sa->sa_len = len;
-	return (0);
-}
-#define getsockaddr_hold getsockadd
-#define getsockaddr getsockaddr_noalloc
+static int kern_getsockname(struct thread *, int, struct sockaddr **,
+    socklen_t *);
+static int kern_listen(struct thread *, int, int);
+static int kern_setsockopt(struct thread *, int, int, int, const void *,
+    enum uio_seg, socklen_t);
+static int kern_shutdown(struct thread *, int, int);
+static int kern_socket(struct thread *, int, int, int);
+static int kern_socketpair(struct thread *, int, int, int, int *);
 #endif /* __rtems__ */
 static int sockargs(struct mbuf **, char *, socklen_t, int);
 
@@ -141,6 +133,46 @@ getsock_cap(struct thread *td, int fd, cap_rights_t *rightsp,
 	*fpp = fp;
 	return (0);
 }
+#else /* __rtems__ */
+static int
+rtems_bsd_getsock(int fd, struct file **fpp, u_int *fflagp)
+{
+	struct file *fp;
+	int error;
+
+	if ((uint32_t) fd < rtems_libio_number_iops) {
+		unsigned int flags;
+
+		fp = rtems_libio_iop(fd);
+		flags = rtems_libio_iop_hold(fp);
+		if ((flags & LIBIO_FLAGS_OPEN) == 0) {
+			rtems_libio_iop_drop(fp);
+			fp = NULL;
+			error = EBADF;
+		} else if (fp->pathinfo.handlers != &socketops) {
+			rtems_libio_iop_drop(fp);
+			fp = NULL;
+			error = ENOTSOCK;
+		} else {
+			if (fflagp != NULL) {
+				*fflagp = rtems_bsd_libio_flags_to_fflag(
+				    fp->flags);
+			}
+
+			error = 0;
+		}
+	} else {
+		fp = NULL;
+		error = EBADF;
+	}
+
+	*fpp = fp;
+
+	return (error);
+}
+
+#define	getsock_cap(td, fd, rights, fpp, fflagp, havecapsp) \
+    rtems_bsd_getsock(fd, fpp, fflagp)
 #endif /* __rtems__ */
 
 /*
@@ -150,6 +182,9 @@ getsock_cap(struct thread *td, int fd, cap_rights_t *rightsp,
 #define COMPAT_OLDSOCK
 #endif
 
+#ifdef __rtems__
+static
+#endif /* __rtems__ */
 int
 sys_socket(struct thread *td, struct socket_args *uap)
 {
@@ -200,7 +235,38 @@ kern_socket(struct thread *td, int domain, int type, int protocol)
 #endif /* __rtems__ */
 	return (error);
 }
+#ifdef __rtems__
+int
+socket(int domain, int type, int protocol)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct socket_args ua = {
+		.domain = domain,
+		.type = type,
+		.protocol = protocol
+	};
+	int error;
+
+	if (td != NULL) {
+		error = sys_socket(td, &ua);
+	} else {
+		error = ENOMEM;
+	}
+
+	if (error == 0) {
+		return td->td_retval[0];
+	} else {
+		rtems_set_errno_and_return_minus_one(error);
+	}
+}
+#endif /* __rtems__ */
+
+#ifdef __rtems__
+static int kern_bindat(struct thread *td, int dirfd, int fd,
+    struct sockaddr *sa);
 
+static
+#endif /* __rtems__ */
 int
 sys_bind(struct thread *td, struct bind_args *uap)
 {
@@ -220,6 +286,27 @@ sys_bind(struct thread *td, struct bind_args *uap)
 	}
 	return (error);
 }
+#ifdef __rtems__
+int
+bind(int socket, const struct sockaddr *address, socklen_t address_len)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct bind_args ua = {
+		.s = socket,
+		.name = address,
+		.namelen = address_len
+	};
+	int error;
+
+	if (td != NULL) {
+		error = sys_bind(td, &ua);
+	} else {
+		error = ENOMEM;
+	}
+
+	return rtems_bsd_error_to_status_and_errno(error);
+}
+#endif /* __rtems__ */
 
 int
 kern_bindat(struct thread *td, int dirfd, int fd, struct sockaddr *sa)
@@ -282,6 +369,9 @@ sys_bindat(struct thread *td, struct bindat_args *uap)
 }
 #endif /* __rtems__ */
 
+#ifdef __rtems__
+static
+#endif /* __rtems__ */
 int
 sys_listen(struct thread *td, struct listen_args *uap)
 {
@@ -310,7 +400,31 @@ kern_listen(struct thread *td, int s, int backlog)
 	}
 	return (error);
 }
+#ifdef __rtems__
+int
+listen(int socket, int backlog)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct listen_args ua = {
+		.s = socket,
+		.backlog = backlog
+	};
+	int error;
+
+	if (td != NULL) {
+		error = sys_listen(td, &ua);
+	} else {
+		error = ENOMEM;
+	}
+
+	return rtems_bsd_error_to_status_and_errno(error);
+}
+#endif /* __rtems__ */
 
+#ifdef __rtems__
+static int kern_accept4(struct thread *td, int s, struct sockaddr **name,
+    socklen_t *namelen, int flags, struct file **fp);
+#endif /* __rtems__ */
 /*
  * accept1()
  */
@@ -359,13 +473,37 @@ accept1(td, s, uname, anamelen, flags)
 	free(name, M_SONAME);
 	return (error);
 }
+#ifdef __rtems__
+int
+accept(int socket, struct sockaddr *__restrict address,
+    socklen_t *__restrict address_len)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	int error;
+
+	if (td != NULL) {
+		error = accept1(td, socket, address, address_len,
+		    ACCEPT4_INHERIT);
+	} else {
+		error = ENOMEM;
+	}
+
+	if (error == 0) {
+		return td->td_retval[0];
+	} else {
+		rtems_set_errno_and_return_minus_one(error);
+	}
+}
+#endif /* __rtems__ */
 
+#ifndef __rtems__
 int
 kern_accept(struct thread *td, int s, struct sockaddr **name,
     socklen_t *namelen, struct file **fp)
 {
 	return (kern_accept4(td, s, name, namelen, ACCEPT4_INHERIT, fp));
 }
+#endif /* __rtems__ */
 
 int
 kern_accept4(struct thread *td, int s, struct sockaddr **name,
@@ -374,7 +512,9 @@ kern_accept4(struct thread *td, int s, struct sockaddr **name,
 	struct file *headfp, *nfp = NULL;
 	struct sockaddr *sa = NULL;
 	struct socket *head, *so;
+#ifndef __rtems__
 	struct filecaps fcaps;
+#endif /* __rtems__ */
 	u_int fflag;
 	pid_t pgid;
 	int error, fd, tmp;
@@ -486,6 +626,7 @@ done:
 	return (error);
 }
 
+#ifndef __rtems__
 int
 sys_accept(td, uap)
 	struct thread *td;
@@ -518,7 +659,14 @@ oaccept(td, uap)
 	    ACCEPT4_INHERIT | ACCEPT4_COMPAT));
 }
 #endif /* COMPAT_OLDSOCK */
+#endif /* __rtems__ */
+
+#ifdef __rtems__
+static int kern_connectat(struct thread *td, int dirfd, int fd,
+    struct sockaddr *sa);
 
+static
+#endif /* __rtems__ */
 int
 sys_connect(struct thread *td, struct connect_args *uap)
 {
@@ -538,6 +686,27 @@ sys_connect(struct thread *td, struct connect_args *uap)
 	}
 	return (error);
 }
+#ifdef __rtems__
+int
+connect(int socket, const struct sockaddr *address, socklen_t address_len)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct connect_args ua = {
+		.s = socket,
+		.name = address,
+		.namelen = address_len
+	};
+	int error;
+
+	if (td != NULL) {
+		error = sys_connect(td, &ua);
+	} else {
+		error = ENOMEM;
+	}
+
+	return rtems_bsd_error_to_status_and_errno(error);
+}
+#endif /* __rtems__ */
 
 int
 kern_connectat(struct thread *td, int dirfd, int fd, struct sockaddr *sa)
@@ -724,6 +893,9 @@ free1:
 	return (error);
 }
 
+#ifdef __rtems__
+static
+#endif /* __rtems__ */
 int
 sys_socketpair(struct thread *td, struct socketpair_args *uap)
 {
@@ -747,7 +919,34 @@ sys_socketpair(struct thread *td, struct socketpair_args *uap)
 #endif /* __rtems__ */
 	return (error);
 }
+#ifdef __rtems__
+int
+socketpair(int domain, int type, int protocol, int *socket_vector)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct socketpair_args ua = {
+		.domain = domain,
+		.type = type,
+		.protocol = protocol,
+		.rsv = socket_vector
+	};
+	int error;
+
+	if (td != NULL) {
+		error = sys_socketpair(td, &ua);
+	} else {
+		error = ENOMEM;
+	}
+
+	return rtems_bsd_error_to_status_and_errno(error);
+}
+#endif /* __rtems__ */
 
+#ifdef __rtems__
+static int
+kern_sendit( struct thread *td, int s, struct msghdr *mp, int flags,
+    struct mbuf *control, enum uio_seg segflg);
+#endif /* __rtems__ */
 static int
 sendit(struct thread *td, int s, struct msghdr *mp, int flags)
 {
@@ -822,7 +1021,9 @@ kern_sendit(struct thread *td, int s, struct msghdr *mp, int flags,
 	struct uio auio;
 	struct iovec *iov;
 	struct socket *so;
+#ifndef __rtems__
 	cap_rights_t *rights;
+#endif /* __rtems__ */
 #ifdef KTRACE
 	struct uio *ktruio = NULL;
 #endif
@@ -837,8 +1038,6 @@ kern_sendit(struct thread *td, int s, struct msghdr *mp, int flags,
 		AUDIT_ARG_SOCKADDR(td, AT_FDCWD, mp->msg_name);
 		rights = &cap_send_connect_rights;
 	}
-#else /* __rtems__ */
-	rights = NULL;
 #endif /* __rtems__ */
 	error = getsock_cap(td, s, rights, &fp, NULL, NULL);
 	if (error != 0) {
@@ -917,6 +1116,9 @@ bad:
 	return (error);
 }
 
+#ifdef __rtems__
+static
+#endif /* __rtems__ */
 int
 sys_sendto(struct thread *td, struct sendto_args *uap)
 {
@@ -941,6 +1143,34 @@ sys_sendto(struct thread *td, struct sendto_args *uap)
 	return (sendit(td, uap->s, &msg, uap->flags));
 }
 #ifdef __rtems__
+ssize_t
+sendto(int socket, const void *message, size_t length, int flags,
+    const struct sockaddr *dest_addr, socklen_t dest_len)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct sendto_args ua = {
+		.s = socket,
+		.buf = (caddr_t) message,
+		.len = length,
+		.flags = flags,
+		.to = dest_addr,
+		.tolen = dest_len
+	};
+	int error;
+
+	if (td != NULL) {
+		error = sys_sendto(td, &ua);
+	} else {
+		error = ENOMEM;
+	}
+
+	if (error == 0) {
+		return td->td_retval[0];
+	} else {
+		rtems_set_errno_and_return_minus_one(error);
+	}
+}
+
 int
 rtems_bsd_sendto(int socket, struct mbuf *m, int flags,
     const struct sockaddr *dest_addr)
@@ -1007,6 +1237,9 @@ osendmsg(struct thread *td, struct osendmsg_args *uap)
 #endif
 #endif /* __rtems__ */
 
+#ifdef __rtems__
+static
+#endif /* __rtems__ */
 int
 sys_sendmsg(struct thread *td, struct sendmsg_args *uap)
 {
@@ -1029,7 +1262,35 @@ sys_sendmsg(struct thread *td, struct sendmsg_args *uap)
 	free(iov, M_IOV);
 	return (error);
 }
+#ifdef __rtems__
+ssize_t
+sendmsg(int socket, const struct msghdr *message, int flags)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct sendmsg_args ua = {
+		.s = socket,
+		.msg = message,
+		.flags = flags
+	};
+	int error;
+
+	if (td != NULL) {
+		error = sys_sendmsg(td, &ua);
+	} else {
+		error = ENOMEM;
+	}
+
+	if (error == 0) {
+		return td->td_retval[0];
+	} else {
+		rtems_set_errno_and_return_minus_one(error);
+	}
+}
+#endif /* __rtems__ */
 
+#ifdef __rtems__
+static
+#endif /* __rtems__ */
 int
 kern_recvit(struct thread *td, int s, struct msghdr *mp, enum uio_seg fromseg,
     struct mbuf **controlp)
@@ -1204,6 +1465,9 @@ recvit(struct thread *td, int s, struct msghdr *mp, void *namelenp)
 	return (error);
 }
 
+#ifdef __rtems__
+static
+#endif /* __rtems__ */
 int
 sys_recvfrom(struct thread *td, struct recvfrom_args *uap)
 {
@@ -1230,6 +1494,35 @@ sys_recvfrom(struct thread *td, struct recvfrom_args *uap)
 done2:
 	return (error);
 }
+#ifdef __rtems__
+ssize_t
+recvfrom(int socket, void *__restrict buffer, size_t length, int flags,
+    struct sockaddr *__restrict address, socklen_t *__restrict address_len)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct recvfrom_args ua = {
+		.s = socket,
+		.buf = buffer,
+		.len = length,
+		.flags = flags,
+		.from = address,
+		.fromlenaddr = address_len
+	};
+	int error;
+
+	if (td != NULL) {
+		error = sys_recvfrom(td, &ua);
+	} else {
+		error = ENOMEM;
+	}
+
+	if (error == 0) {
+		return td->td_retval[0];
+	} else {
+		rtems_set_errno_and_return_minus_one(error);
+	}
+}
+#endif /* __rtems__ */
 
 #ifndef __rtems__
 #ifdef COMPAT_OLDSOCK
@@ -1290,6 +1583,9 @@ orecvmsg(struct thread *td, struct orecvmsg_args *uap)
 #endif
 #endif /* __rtems__ */
 
+#ifdef __rtems__
+static
+#endif /* __rtems__ */
 int
 sys_recvmsg(struct thread *td, struct recvmsg_args *uap)
 {
@@ -1318,7 +1614,35 @@ sys_recvmsg(struct thread *td, struct recvmsg_args *uap)
 	free(iov, M_IOV);
 	return (error);
 }
+#ifdef __rtems__
+ssize_t
+recvmsg(int socket, struct msghdr *message, int flags)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct recvmsg_args ua = {
+		.s = socket,
+		.msg = message,
+		.flags = flags
+	};
+	int error;
+
+	if (td != NULL) {
+		error = sys_recvmsg(td, &ua);
+	} else {
+		error = ENOMEM;
+	}
+
+	if (error == 0) {
+		return td->td_retval[0];
+	} else {
+		rtems_set_errno_and_return_minus_one(error);
+	}
+}
+#endif /* __rtems__ */
 
+#ifdef __rtems__
+static
+#endif /* __rtems__ */
 int
 sys_shutdown(struct thread *td, struct shutdown_args *uap)
 {
@@ -1354,7 +1678,23 @@ kern_shutdown(struct thread *td, int s, int how)
 	}
 	return (error);
 }
+#ifdef __rtems__
+int
+shutdown(int socket, int how)
+{
+	struct shutdown_args ua = {
+		.s = socket,
+		.how = how
+	};
+	int error = sys_shutdown(NULL, &ua);
+
+	return rtems_bsd_error_to_status_and_errno(error);
+}
+#endif /* __rtems__ */
 
+#ifdef __rtems__
+static
+#endif /* __rtems__ */
 int
 sys_setsockopt(struct thread *td, struct setsockopt_args *uap)
 {
@@ -1362,10 +1702,39 @@ sys_setsockopt(struct thread *td, struct setsockopt_args *uap)
 	return (kern_setsockopt(td, uap->s, uap->level, uap->name,
 	    uap->val, UIO_USERSPACE, uap->valsize));
 }
+#ifdef __rtems__
+int
+setsockopt(int socket, int level, int option_name, const void *option_value,
+    socklen_t option_len)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct setsockopt_args ua = {
+		.s = socket,
+		.level = level,
+		.name = option_name,
+		.val = __DECONST(void *, option_value),
+		.valsize = option_len
+	};
+	int error;
+
+	if (td != NULL) {
+		error = sys_setsockopt(td, &ua);
+	} else {
+		error = ENOMEM;
+	}
+
+	return rtems_bsd_error_to_status_and_errno(error);
+}
+#endif /* __rtems__ */
 
 int
+#ifndef __rtems__
 kern_setsockopt(struct thread *td, int s, int level, int name, void *val,
     enum uio_seg valseg, socklen_t valsize)
+#else /* __rtems__ */
+kern_setsockopt(struct thread *td, int s, int level, int name, const void *val,
+    enum uio_seg valseg, socklen_t valsize)
+#endif /* __rtems__ */
 {
 	struct socket *so;
 	struct file *fp;
@@ -1380,7 +1749,11 @@ kern_setsockopt(struct thread *td, int s, int level, int name, void *val,
 	sopt.sopt_dir = SOPT_SET;
 	sopt.sopt_level = level;
 	sopt.sopt_name = name;
+#ifndef __rtems__
 	sopt.sopt_val = val;
+#else /* __rtems__ */
+	sopt.sopt_val = __DECONST(void *, val);
+#endif /* __rtems__ */
 	sopt.sopt_valsize = valsize;
 	switch (valseg) {
 	case UIO_USERSPACE:
@@ -1404,6 +1777,12 @@ kern_setsockopt(struct thread *td, int s, int level, int name, void *val,
 	return(error);
 }
 
+#ifdef __rtems__
+static int kern_getsockopt( struct thread *td, int s, int level, int name,
+    void *val, enum uio_seg valseg, socklen_t *valsize);
+
+static
+#endif /* __rtems__ */
 int
 sys_getsockopt(struct thread *td, struct getsockopt_args *uap)
 {
@@ -1423,6 +1802,30 @@ sys_getsockopt(struct thread *td, struct getsockopt_args *uap)
 		error = copyout(&valsize, uap->avalsize, sizeof (valsize));
 	return (error);
 }
+#ifdef __rtems__
+int
+getsockopt(int socket, int level, int option_name, void *__restrict
+    option_value, socklen_t *__restrict option_len)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct getsockopt_args ua = {
+		.s = socket,
+		.level = level,
+		.name = option_name,
+		.val = (caddr_t) option_value,
+		.avalsize = option_len
+	};
+	int error;
+
+	if (td != NULL) {
+		error = sys_getsockopt(td, &ua);
+	} else {
+		error = ENOMEM;
+	}
+
+	return rtems_bsd_error_to_status_and_errno(error);
+}
+#endif /* __rtems__ */
 
 /*
  * Kernel version of getsockopt.
@@ -1500,6 +1903,28 @@ getsockname1(struct thread *td, struct getsockname_args *uap, int compat)
 		error = copyout(&len, uap->alen, sizeof(len));
 	return (error);
 }
+#ifdef __rtems__
+int
+getsockname(int socket, struct sockaddr *__restrict address,
+    socklen_t *__restrict address_len)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct getsockname_args ua = {
+		.fdes = socket,
+		.asa = address,
+		.alen = address_len
+	};
+	int error;
+
+	if (td != NULL) {
+		error = getsockname1(td, &ua, 0);
+	} else {
+		error = ENOMEM;
+	}
+
+	return rtems_bsd_error_to_status_and_errno(error);
+}
+#endif /* __rtems__ */
 
 int
 kern_getsockname(struct thread *td, int fd, struct sockaddr **sa,
@@ -1540,6 +1965,7 @@ bad:
 	return (error);
 }
 
+#ifndef __rtems__
 int
 sys_getsockname(struct thread *td, struct getsockname_args *uap)
 {
@@ -1555,7 +1981,13 @@ ogetsockname(struct thread *td, struct getsockname_args *uap)
 	return (getsockname1(td, uap, 1));
 }
 #endif /* COMPAT_OLDSOCK */
+#endif /* __rtems__ */
 
+#ifdef __rtems__
+static int
+kern_getpeername(struct thread *td, int fd, struct sockaddr **sa,
+    socklen_t *alen);
+#endif /* __rtems__ */
 /*
  * getpeername1() - Get name of peer for connected socket.
  */
@@ -1586,6 +2018,28 @@ getpeername1(struct thread *td, struct getpeername_args *uap, int compat)
 		error = copyout(&len, uap->alen, sizeof(len));
 	return (error);
 }
+#ifdef __rtems__
+int
+getpeername(int socket, struct sockaddr *__restrict address,
+    socklen_t *__restrict address_len)
+{
+	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct getpeername_args ua = {
+		.fdes = socket,
+		.asa = address,
+		.alen = address_len
+	};
+	int error;
+
+	if (td != NULL) {
+		error = getpeername1(td, &ua, 0);
+	} else {
+		error = ENOMEM;
+	}
+
+	return rtems_bsd_error_to_status_and_errno(error);
+}
+#endif /* __rtems__ */
 
 int
 kern_getpeername(struct thread *td, int fd, struct sockaddr **sa,
@@ -1631,6 +2085,7 @@ done:
 	return (error);
 }
 
+#ifndef __rtems__
 int
 sys_getpeername(struct thread *td, struct getpeername_args *uap)
 {
@@ -1647,6 +2102,7 @@ ogetpeername(struct thread *td, struct ogetpeername_args *uap)
 	return (getpeername1(td, (struct getpeername_args *)uap, 1));
 }
 #endif /* COMPAT_OLDSOCK */
+#endif /* __rtems__ */
 
 static int
 sockargs(struct mbuf **mp, char *buf, socklen_t buflen, int type)
@@ -1686,22 +2142,23 @@ sockargs(struct mbuf **mp, char *buf, socklen_t buflen, int type)
 	return (error);
 }
 
-#ifdef __rtems__
-#undef getsockaddr
-int
-_bsd_getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len)
-#else /* __rtems__ */
 int
+#ifndef __rtems__
 getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len)
+#else /* __rtems__ */
+getsockaddr(struct sockaddr **namp, const struct sockaddr *uaddr, size_t len)
 #endif /* __rtems__ */
 {
 	struct sockaddr *sa;
+#ifndef __rtems__
 	int error;
+#endif /* __rtems__ */
 
 	if (len > SOCK_MAXADDRLEN)
 		return (ENAMETOOLONG);
 	if (len < offsetof(struct sockaddr, sa_data[0]))
 		return (EINVAL);
+#ifndef __rtems__
 	sa = malloc(len, M_SONAME, M_WAITOK);
 	error = copyin(uaddr, sa, len);
 	if (error != 0) {
@@ -1716,6 +2173,11 @@ getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len)
 		*namp = sa;
 	}
 	return (error);
+#else /* __rtems__ */
+	sa = memcpy(*namp, uaddr, len);
+	sa->sa_len = len;
+	return (0);
+#endif /* __rtems__ */
 }
 
 /*
diff --git a/freebsd/sys/kern/uipc_usrreq.c b/freebsd/sys/kern/uipc_usrreq.c
index db07ce8a..47cdcfbd 100644
--- a/freebsd/sys/kern/uipc_usrreq.c
+++ b/freebsd/sys/kern/uipc_usrreq.c
@@ -59,6 +59,9 @@
  *	need a proper out-of-band
  */
 
+#ifdef __rtems__
+#include <rtems/bsd/sys/file.h>
+#endif /* __rtems__ */
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
@@ -77,7 +80,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/mbuf.h>
 #include <sys/mount.h>
 #include <sys/mutex.h>
+#ifndef __rtems__
 #include <sys/namei.h>
+#endif /* __rtems__ */
 #include <sys/proc.h>
 #include <sys/protosw.h>
 #include <sys/queue.h>
@@ -608,8 +613,7 @@ rtems_uipc_imfs_destroy(IMFS_jnode_t *node)
 }
 
 static const IMFS_node_control rtems_uipc_imfs_control =
-	IMFS_GENERIC_INITIALIZER(&rtems_bsd_sysgen_imfsnodeops,
-		rtems_uipc_imfs_initialize,
+    IMFS_GENERIC_INITIALIZER(&socketops, rtems_uipc_imfs_initialize,
     rtems_uipc_imfs_destroy);
 
 static const IMFS_node_control rtems_uipc_imfs_zombi_control =
@@ -617,13 +621,13 @@ static const IMFS_node_control rtems_uipc_imfs_zombi_control =
     IMFS_node_destroy_default);
 
 static void
-VOP_UNP_DETACH_rtems(IMFS_generic_t *vp)
+vop_unp_detach(IMFS_generic_t *vp)
 {
+
 	vp->Node.control = &rtems_uipc_imfs_zombi_control;
 	vp->context = NULL;
 }
-#undef VOP_UNP_DETACH
-#define VOP_UNP_DETACH VOP_UNP_DETACH_rtems
+#define	VOP_UNP_DETACH vop_unp_detach
 #endif /* __rtems__ */
 static int
 uipc_bindat(int fd, struct socket *so, struct sockaddr *nam, struct thread *td)
@@ -1727,7 +1731,7 @@ unp_connectat(int fd, struct socket *so, struct sockaddr *nam,
 	    &ctx, &soun->sun_path[0], (size_t)len, eval_flags,
 	    &rtems_filesystem_root, &rtems_filesystem_current);
 
-	if (currentloc->handlers == &rtems_bsd_sysgen_imfsnodeops) {
+	if (currentloc->handlers == &socketops) {
 		vp = currentloc->node_access;
 	} else {
 		vp = NULL;
diff --git a/freebsd/sys/sys/socketvar.h b/freebsd/sys/sys/socketvar.h
index ad57730a..db7227d8 100644
--- a/freebsd/sys/sys/socketvar.h
+++ b/freebsd/sys/sys/socketvar.h
@@ -384,18 +384,8 @@ int	getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len);
 int	getsock_cap(struct thread *td, int fd, cap_rights_t *rightsp,
 	    struct file **fpp, u_int *fflagp, struct filecaps *havecaps);
 #else /* __rtems__ */
-int rtems_bsd_getsock(int fd, struct file **fpp, u_int *fflagp);
-
-static inline int
-getsock_cap(struct thread *td, int fd, cap_rights_t *rightsp,
-    struct file **fpp, u_int *fflagp, struct filecaps *havecaps)
-{
-
-	(void)td;
-	(void)rightsp;
-	(void)havecaps;
-	return (rtems_bsd_getsock(fd, fpp, fflagp));
-}
+int	getsockaddr(struct sockaddr **namp, const struct sockaddr *uaddr,
+	    size_t len);
 #endif /* __rtems__ */
 void	soabort(struct socket *so);
 int	soaccept(struct socket *so, struct sockaddr **nam);
diff --git a/freebsd/sys/sys/sysproto.h b/freebsd/sys/sys/sysproto.h
index 8d72d52b..31c3e933 100644
--- a/freebsd/sys/sys/sysproto.h
+++ b/freebsd/sys/sys/sysproto.h
@@ -1922,13 +1922,13 @@ int	sys_setuid(struct thread *, struct setuid_args *);
 int	sys_getuid(struct thread *, struct getuid_args *);
 int	sys_geteuid(struct thread *, struct geteuid_args *);
 int	sys_ptrace(struct thread *, struct ptrace_args *);
-#endif /* __rtems__ */
 int	sys_recvmsg(struct thread *, struct recvmsg_args *);
 int	sys_sendmsg(struct thread *, struct sendmsg_args *);
 int	sys_recvfrom(struct thread *, struct recvfrom_args *);
 int	sys_accept(struct thread *, struct accept_args *);
 int	sys_getpeername(struct thread *, struct getpeername_args *);
 int	sys_getsockname(struct thread *, struct getsockname_args *);
+#endif /* __rtems__ */
 int	sys_access(struct thread *, struct access_args *);
 int	sys_chflags(struct thread *, struct chflags_args *);
 int	sys_fchflags(struct thread *, struct fchflags_args *);
@@ -1980,20 +1980,16 @@ int	sys_select(struct thread *, struct select_args *);
 int	sys_fsync(struct thread *, struct fsync_args *);
 #ifndef __rtems__
 int	sys_setpriority(struct thread *, struct setpriority_args *);
-#endif /* __rtems__ */
 int	sys_socket(struct thread *, struct socket_args *);
 int	sys_connect(struct thread *, struct connect_args *);
-#ifndef __rtems__
 int	sys_getpriority(struct thread *, struct getpriority_args *);
-#endif /* __rtems__ */
 int	sys_bind(struct thread *, struct bind_args *);
 int	sys_setsockopt(struct thread *, struct setsockopt_args *);
 int	sys_listen(struct thread *, struct listen_args *);
-#ifndef __rtems__
 int	sys_gettimeofday(struct thread *, struct gettimeofday_args *);
 int	sys_getrusage(struct thread *, struct getrusage_args *);
-#endif /* __rtems__ */
 int	sys_getsockopt(struct thread *, struct getsockopt_args *);
+#endif /* __rtems__ */
 int	sys_readv(struct thread *, struct readv_args *);
 int	sys_writev(struct thread *, struct writev_args *);
 #ifndef __rtems__
@@ -2007,10 +2003,10 @@ int	sys_setregid(struct thread *, struct setregid_args *);
 int	sys_rename(struct thread *, struct rename_args *);
 int	sys_flock(struct thread *, struct flock_args *);
 int	sys_mkfifo(struct thread *, struct mkfifo_args *);
-#endif /* __rtems__ */
 int	sys_sendto(struct thread *, struct sendto_args *);
 int	sys_shutdown(struct thread *, struct shutdown_args *);
 int	sys_socketpair(struct thread *, struct socketpair_args *);
+#endif /* __rtems__ */
 int	sys_mkdir(struct thread *, struct mkdir_args *);
 int	sys_rmdir(struct thread *, struct rmdir_args *);
 #ifndef __rtems__
diff --git a/rtemsbsd/rtems/rtems-bsd-syscall-api.c b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
index 0ab85bbf..7caeecf8 100644
--- a/rtemsbsd/rtems/rtems-bsd-syscall-api.c
+++ b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
@@ -165,52 +165,6 @@ const rtems_filesystem_file_handlers_r rtems_bsd_sysgen_imfsnodeops = {
 	.mmap_h = rtems_filesystem_default_mmap
 };
 
-int
-rtems_bsd_getsock(int fd, struct file **fpp, u_int *fflagp)
-{
-	int error;
-	rtems_libio_t *iop;
-	unsigned int actual_flags;
-	struct file *fp;
-
-	if ((uint32_t)fd >= rtems_libio_number_iops) {
-		error = EBADF;
-		goto bad;
-	}
-
-	iop = rtems_libio_iop(fd);
-	actual_flags = rtems_libio_iop_hold(iop);
-
-	if ((actual_flags & LIBIO_FLAGS_OPEN) != LIBIO_FLAGS_OPEN) {
-		error = EBADF;
-		goto drop;
-	}
-
-	if (iop->pathinfo.handlers->close_h != rtems_bsd_sysgen_close) {
-		error = ENOTSOCK;
-		goto drop;
-	}
-
-	fp = iop->data1;
-
-	if (fp->f_type != DTYPE_SOCKET) {
-		error = ENOTSOCK;
-		goto drop;
-	}
-
-	if (fflagp != NULL)
-		*fflagp = fp->f_flag;
-	*fpp = fp;
-	return (0);
-
-drop:
-	rtems_libio_iop_drop(iop);
-
-bad:
-	*fpp = NULL;
-	return (error);
-}
-
 struct file *
 rtems_bsd_iop_to_file(const rtems_libio_t *iop)
 {
@@ -257,326 +211,6 @@ rtems_bsd_fdclose(struct file *fp)
 	free(fp, M_TEMP);
 }
 
-int
-accept(int socket, struct sockaddr *__restrict address,
-    socklen_t *__restrict address_len)
-{
-	struct thread *td;
-	int error;
-	struct accept_args ua;
-	rtems_libio_t *iop;
-	int afd;
-	if (RTEMS_BSD_SYSCALL_TRACE) {
-		printf("bsd: sys: accept: %d\n", socket);
-	}
-	td = rtems_bsd_get_curthread_or_null();
-	if (td == NULL) {
-		return rtems_bsd_error_to_status_and_errno(ENOMEM);
-	}
-	ua.s = socket;
-	ua.name = address;
-	ua.anamelen = address_len;
-	error = sys_accept(td, &ua);
-	if (error != 0) {
-		return rtems_bsd_error_to_status_and_errno(error);
-	}
-	return (td->td_retval[0]);
-}
-
-int
-bind(int socket, const struct sockaddr *address, socklen_t address_len)
-{
-	struct thread *td = rtems_bsd_get_curthread_or_null();
-	struct bind_args ua;
-	int error;
-	if (RTEMS_BSD_SYSCALL_TRACE) {
-		printf("bsd: sys: bind: %d\n", socket);
-	}
-	if (td == NULL) {
-		return rtems_bsd_error_to_status_and_errno(ENOMEM);
-	}
-	ua.s = socket;
-	ua.name = address;
-	ua.namelen = address_len;
-	error = sys_bind(td, &ua);
-	return rtems_bsd_error_to_status_and_errno(error);
-}
-
-int
-connect(int socket, const struct sockaddr *address, socklen_t address_len)
-{
-	struct thread *td = rtems_bsd_get_curthread_or_null();
-	struct connect_args ua;
-	int error;
-	if (RTEMS_BSD_SYSCALL_TRACE) {
-		printf("bsd: sys: connect: %d\n", socket);
-	}
-	if (td == NULL) {
-		return rtems_bsd_error_to_status_and_errno(ENOMEM);
-	}
-	ua.s = socket;
-	ua.name = address;
-	ua.namelen = address_len;
-	error = sys_connect(td, &ua);
-	return rtems_bsd_error_to_status_and_errno(error);
-}
-
-int
-getpeername(int socket, struct sockaddr *__restrict address,
-    socklen_t *__restrict address_len)
-{
-	struct thread *td = rtems_bsd_get_curthread_or_null();
-	struct getpeername_args ua;
-	int error;
-	if (RTEMS_BSD_SYSCALL_TRACE) {
-		printf("bsd: sys: getpeername: %d\n", socket);
-	}
-	if (td == NULL) {
-		return rtems_bsd_error_to_status_and_errno(ENOMEM);
-	}
-	ua.fdes = socket;
-	ua.asa = address;
-	ua.alen = address_len;
-	error = sys_getpeername(td, &ua);
-	return rtems_bsd_error_to_status_and_errno(error);
-}
-
-int
-getsockname(int socket, struct sockaddr *__restrict address,
-    socklen_t *__restrict address_len)
-{
-	struct thread *td = rtems_bsd_get_curthread_or_null();
-	struct getsockname_args ua;
-	int error;
-	if (RTEMS_BSD_SYSCALL_TRACE) {
-		printf("bsd: sys: getsockname: %d\n", socket);
-	}
-	if (td == NULL) {
-		return rtems_bsd_error_to_status_and_errno(ENOMEM);
-	}
-	ua.fdes = socket;
-	ua.asa = address;
-	ua.alen = address_len;
-	error = sys_getsockname(td, &ua);
-	return rtems_bsd_error_to_status_and_errno(error);
-}
-
-int
-getsockopt(int socket, int level, int option_name,
-    void *__restrict option_value, socklen_t *__restrict option_len)
-{
-	struct thread *td = rtems_bsd_get_curthread_or_null();
-	struct getsockopt_args ua;
-	int error;
-	if (RTEMS_BSD_SYSCALL_TRACE) {
-		printf("bsd: sys: getsockopt: %d\n", socket);
-	}
-	if (td == NULL) {
-		return rtems_bsd_error_to_status_and_errno(ENOMEM);
-	}
-	ua.s = socket;
-	ua.level = level;
-	ua.name = option_name;
-	ua.val = (caddr_t)option_value;
-	ua.avalsize = option_len;
-	error = sys_getsockopt(td, &ua);
-	return rtems_bsd_error_to_status_and_errno(error);
-}
-
-int
-listen(int socket, int backlog)
-{
-	struct thread *td = rtems_bsd_get_curthread_or_null();
-	struct listen_args ua;
-	int error;
-	if (RTEMS_BSD_SYSCALL_TRACE) {
-		printf("bsd: sys: listen: %d\n", socket);
-	}
-	if (td == NULL) {
-		return rtems_bsd_error_to_status_and_errno(ENOMEM);
-	}
-	ua.s = socket;
-	ua.backlog = backlog;
-	error = sys_listen(td, &ua);
-	return rtems_bsd_error_to_status_and_errno(error);
-}
-
-ssize_t
-recvfrom(int socket, void *__restrict buffer, size_t length, int flags,
-    struct sockaddr *__restrict address, socklen_t *__restrict address_len)
-{
-	struct thread *td = rtems_bsd_get_curthread_or_null();
-	struct recvfrom_args ua;
-	int error;
-	if (RTEMS_BSD_SYSCALL_TRACE) {
-		printf("bsd: sys: recvfrom: %d\n", socket);
-	}
-	if (td == NULL) {
-		return rtems_bsd_error_to_status_and_errno(ENOMEM);
-	}
-	ua.s = socket;
-	ua.buf = buffer;
-	ua.len = length;
-	ua.flags = flags;
-	ua.from = address;
-	ua.fromlenaddr = address_len;
-	error = sys_recvfrom(td, &ua);
-	if (error != 0) {
-		return rtems_bsd_error_to_status_and_errno(error);
-	}
-	return td->td_retval[0];
-}
-
-ssize_t
-recvmsg(int socket, struct msghdr *message, int flags)
-{
-	struct thread *td = rtems_bsd_get_curthread_or_null();
-	struct recvmsg_args ua;
-	int error;
-	if (RTEMS_BSD_SYSCALL_TRACE) {
-		printf("bsd: sys: recvmsg: %d\n", socket);
-	}
-	if (td == NULL) {
-		return rtems_bsd_error_to_status_and_errno(ENOMEM);
-	}
-	ua.s = socket;
-	ua.msg = message;
-	ua.flags = flags;
-	error = sys_recvmsg(td, &ua);
-	if (error != 0) {
-		return rtems_bsd_error_to_status_and_errno(error);
-	}
-	return td->td_retval[0];
-}
-
-ssize_t
-sendto(int socket, const void *message, size_t length, int flags,
-    const struct sockaddr *dest_addr, socklen_t dest_len)
-{
-	struct thread *td = rtems_bsd_get_curthread_or_null();
-	struct sendto_args ua;
-	int error;
-	if (RTEMS_BSD_SYSCALL_TRACE) {
-		printf("bsd: sys: sendto: %d\n", socket);
-	}
-	if (td == NULL) {
-		return rtems_bsd_error_to_status_and_errno(ENOMEM);
-	}
-	ua.s = socket;
-	ua.buf = (caddr_t)message;
-	ua.len = length;
-	ua.flags = flags;
-	ua.to = dest_addr;
-	ua.tolen = dest_len;
-	error = sys_sendto(td, &ua);
-	if (error != 0) {
-		return rtems_bsd_error_to_status_and_errno(error);
-	}
-	return td->td_retval[0];
-}
-
-ssize_t
-sendmsg(int socket, const struct msghdr *message, int flags)
-{
-	struct thread *td = rtems_bsd_get_curthread_or_null();
-	struct sendmsg_args ua;
-	int error;
-	if (RTEMS_BSD_SYSCALL_TRACE) {
-		printf("bsd: sys: sendmsg: %d\n", socket);
-	}
-	if (td == NULL) {
-		return rtems_bsd_error_to_status_and_errno(ENOMEM);
-	}
-	ua.s = socket;
-	ua.msg = message;
-	ua.flags = flags;
-	error = sys_sendmsg(td, &ua);
-	return rtems_bsd_error_to_status_and_errno(error);
-}
-
-int
-setsockopt(int socket, int level, int option_name, const void *option_value,
-    socklen_t option_len)
-{
-	struct thread *td = rtems_bsd_get_curthread_or_null();
-	struct setsockopt_args ua;
-	int error;
-	if (RTEMS_BSD_SYSCALL_TRACE) {
-		printf("bsd: sys: setsockopt: %d\n", socket);
-	}
-	if (td == NULL) {
-		return rtems_bsd_error_to_status_and_errno(ENOMEM);
-	}
-	ua.s = socket;
-	ua.level = level;
-	ua.name = option_name;
-	ua.val = __DECONST(void *, option_value);
-	ua.valsize = option_len;
-	error = sys_setsockopt(td, &ua);
-	return rtems_bsd_error_to_status_and_errno(error);
-}
-
-int
-shutdown(int socket, int how)
-{
-	struct thread *td = rtems_bsd_get_curthread_or_null();
-	int error;
-	if (RTEMS_BSD_SYSCALL_TRACE) {
-		printf("bsd: sys: shutdown: %d\n", socket);
-	}
-	if (td == NULL) {
-		return rtems_bsd_error_to_status_and_errno(ENOMEM);
-	}
-	struct shutdown_args ua = { .s = socket, .how = how };
-	error = sys_shutdown(td, &ua);
-	return rtems_bsd_error_to_status_and_errno(error);
-}
-
-int
-socket(int domain, int type, int protocol)
-{
-	struct thread *td;
-	struct socket_args ua;
-	int error;
-	td = rtems_bsd_get_curthread_or_null();
-	if (td == NULL) {
-		return rtems_bsd_error_to_status_and_errno(ENOMEM);
-	}
-	ua.domain = domain;
-	ua.type = type;
-	ua.protocol = protocol;
-	error = sys_socket(td, &ua);
-	if (error != 0) {
-		return rtems_bsd_error_to_status_and_errno(error);
-	}
-	return (td->td_retval[0]);
-}
-
-int
-socketpair(int domain, int type, int protocol, int *socket_vector)
-{
-	struct thread *td;
-	struct socketpair_args ua;
-	int error;
-	if (RTEMS_BSD_SYSCALL_TRACE) {
-		printf("bsd: sys: socketpair:\n");
-	}
-	td = rtems_bsd_get_curthread_or_null();
-	if (td == NULL) {
-		return rtems_bsd_error_to_status_and_errno(ENOMEM);
-	}
-	ua.domain = domain;
-	ua.type = type;
-	ua.protocol = protocol;
-	ua.rsv = socket_vector;
-	error = sys_socketpair(td, &ua);
-	if (error != 0) {
-		return rtems_bsd_error_to_status_and_errno(error);
-	}
-	return (0);
-}
-
-
 static int
 rtems_bsd_sysgen_open_error(
     rtems_libio_t *iop, const char *path, int oflag, mode_t mode)
diff --git a/testsuite/syscalls01/test_main.c b/testsuite/syscalls01/test_main.c
index dd2caebc..bf4cad91 100644
--- a/testsuite/syscalls01/test_main.c
+++ b/testsuite/syscalls01/test_main.c
@@ -446,8 +446,7 @@ no_mem_socket_fstat(int fd)
 	int rv;
 
 	rv = fstat(fd, &st);
-	assert(rv == -1);
-	assert(errno == ENOMEM);
+	assert(rv == 0);
 }
 
 static void
@@ -456,8 +455,7 @@ no_mem_socket_shutdown(int fd)
 	int rv;
 
 	rv = shutdown(fd, SHUT_RDWR);
-	assert(rv == -1);
-	assert(errno == ENOMEM);
+	assert(rv == 0);
 }
 
 static void
-- 
2.35.3



More information about the devel mailing list