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

Partly revert commit 6514d561587fd1527fe6a26cb43e6b5742c8c779 in
"freebsd/sys/kern/sys_generic.c".  The goal is to use USB, network, PCI, and
NVMe support without the VFS to reduce the memory and runtime overhead
introduced by VFS.

Avoid the VFS by providing a weak bwillwrite() implementation.

Update #4475.
---
 freebsd/sys/kern/sys_generic.c                | 111 +++++++++++++++++-
 freebsd/sys/sys/sysproto.h                    |   4 +-
 .../machine/rtems-bsd-kernel-namespace.h      |   3 -
 rtemsbsd/rtems/rtems-bsd-syscall-api.c        |  86 --------------
 4 files changed, 108 insertions(+), 96 deletions(-)

diff --git a/freebsd/sys/kern/sys_generic.c b/freebsd/sys/kern/sys_generic.c
index 1e5351a7..1c3bb714 100644
--- a/freebsd/sys/kern/sys_generic.c
+++ b/freebsd/sys/kern/sys_generic.c
@@ -77,6 +77,19 @@ __FBSDID("$FreeBSD$");
 #endif
 
 #include <security/audit/audit.h>
+#ifdef __rtems__
+#include <machine/rtems-bsd-syscall-api.h>
+
+static int kern_select(struct thread *, int, fd_set *, fd_set *,
+    fd_set *, struct timeval *, int);
+
+__weak_symbol void
+bwillwrite(void)
+{
+
+       /* Do not pull in the VFS support only through this translation unit */
+}
+#endif /* __rtems__ */
 
 /*
  * The following macro defines how many bytes will be allocated from
@@ -259,7 +272,6 @@ freebsd6_pread(struct thread *td, struct 
freebsd6_pread_args *uap)
        return (kern_pread(td, uap->fd, uap->buf, uap->nbyte, uap->offset));
 }
 #endif
-#endif /* __rtems__ */
 
 /*
  * Scatter read system call.
@@ -284,6 +296,7 @@ sys_readv(struct thread *td, struct readv_args *uap)
        free(auio, M_IOV);
        return (error);
 }
+#endif /* __rtems__ */
 
 int
 kern_readv(struct thread *td, int fd, struct uio *auio)
@@ -465,7 +478,6 @@ freebsd6_pwrite(struct thread *td, struct 
freebsd6_pwrite_args *uap)
        return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte, uap->offset));
 }
 #endif
-#endif /* __rtems__ */
 
 /*
  * Gather write system call.
@@ -490,6 +502,7 @@ sys_writev(struct thread *td, struct writev_args *uap)
        free(auio, M_IOV);
        return (error);
 }
+#endif /* __rtems__ */
 
 int
 kern_writev(struct thread *td, int fd, struct uio *auio)
@@ -865,6 +878,7 @@ poll_no_poll(int events)
        return (events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
 }
 
+#ifndef __rtems__
 int
 sys_pselect(struct thread *td, struct pselect_args *uap)
 {
@@ -898,7 +912,6 @@ kern_pselect(struct thread *td, int nd, fd_set *in, fd_set 
*ou, fd_set *ex,
 {
        int error;
 
-#ifndef __rtems__
        if (uset != NULL) {
                error = kern_sigprocmask(td, SIG_SETMASK, uset,
                    &td->td_oldsigmask, 0);
@@ -914,7 +927,6 @@ kern_pselect(struct thread *td, int nd, fd_set *in, fd_set 
*ou, fd_set *ex,
                td->td_flags |= TDF_ASTPENDING;
                thread_unlock(td);
        }
-#endif /* __rtems__ */
        error = kern_select(td, nd, in, ou, ex, tvp, abi_nfdbits);
        return (error);
 }
@@ -943,6 +955,7 @@ sys_select(struct thread *td, struct select_args *uap)
        return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
            NFDBITS));
 }
+#endif /* __rtems__ */
 
 /*
  * In the unlikely case when user specified n greater then the last
@@ -1171,6 +1184,65 @@ done:
 
        return (error);
 }
+#ifdef __rtems__
+int
+select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds,
+    struct timeval *timeout)
+{
+       struct thread *td = rtems_bsd_get_curthread_or_null();
+       int error;
+
+       if (td != NULL) {
+               error = kern_select(td, nfds, readfds, writefds, errorfds,
+                   timeout, NFDBITS);
+       } else {
+               error = ENOMEM;
+       }
+
+       if (error == 0) {
+               return td->td_retval[0];
+       } else {
+               rtems_set_errno_and_return_minus_one(error);
+       }
+}
+
+int
+pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds,
+    const struct timespec *timeout, const sigset_t *set)
+{
+       struct thread *td;
+       int error;
+
+       if (set != NULL) {
+               rtems_set_errno_and_return_minus_one(ENOSYS);
+       }
+
+       td = rtems_bsd_get_curthread_or_null();
+
+       if (td != NULL) {
+               struct timeval tv;
+               struct timeval *tvp;
+
+               if (timeout != NULL) {
+                       TIMESPEC_TO_TIMEVAL(&tv, timeout);
+                       tvp = &tv;
+               } else {
+                       tvp = NULL;
+               }
+
+               error = kern_select(td, nfds, readfds, writefds, errorfds,
+                   tvp, NFDBITS);
+       } else {
+               error = ENOMEM;
+       }
+
+       if (error == 0) {
+               return td->td_retval[0];
+       } else {
+               rtems_set_errno_and_return_minus_one(error);
+       }
+}
+#endif /* __rtems__ */
 
 /* 
  * Convert a select bit set to poll flags.
@@ -1404,6 +1476,12 @@ selscan(struct thread *td, fd_mask **ibits, fd_mask 
**obits, int nfd)
        return (0);
 }
 
+#ifdef __rtems__
+static int kern_poll(struct thread *td, struct pollfd *fds, u_int nfds,
+    struct timespec *tsp, sigset_t *uset);
+
+static
+#endif /* __rtems__ */
 int
 sys_poll(struct thread *td, struct poll_args *uap)
 {
@@ -1522,6 +1600,31 @@ out:
                free(bits, M_TEMP);
        return (error);
 }
+#ifdef __rtems__
+int
+poll(struct pollfd fds[], nfds_t nfds, int timeout)
+{
+       struct thread *td = rtems_bsd_get_curthread_or_null();
+       struct poll_args ua = {
+               .fds = &fds[0],
+               .nfds = nfds,
+               .timeout = timeout
+       };
+       int error;
+
+       if (td != NULL) {
+               error = sys_poll(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__
 int
diff --git a/freebsd/sys/sys/sysproto.h b/freebsd/sys/sys/sysproto.h
index 8e915185..8d72d52b 100644
--- a/freebsd/sys/sys/sysproto.h
+++ b/freebsd/sys/sys/sysproto.h
@@ -1975,8 +1975,8 @@ int       sys_getitimer(struct thread *, struct 
getitimer_args *);
 int    sys_getdtablesize(struct thread *, struct getdtablesize_args *);
 int    sys_dup2(struct thread *, struct dup2_args *);
 int    sys_fcntl(struct thread *, struct fcntl_args *);
-#endif /* __rtems__ */
 int    sys_select(struct thread *, struct select_args *);
+#endif /* __rtems__ */
 int    sys_fsync(struct thread *, struct fsync_args *);
 #ifndef __rtems__
 int    sys_setpriority(struct thread *, struct setpriority_args *);
@@ -2042,9 +2042,7 @@ int       sys_munlock(struct thread *, struct 
munlock_args *);
 int    sys_undelete(struct thread *, struct undelete_args *);
 int    sys_futimes(struct thread *, struct futimes_args *);
 int    sys_getpgid(struct thread *, struct getpgid_args *);
-#endif /* __rtems__ */
 int    sys_poll(struct thread *, struct poll_args *);
-#ifndef __rtems__
 int    sys_semget(struct thread *, struct semget_args *);
 int    sys_semop(struct thread *, struct semop_args *);
 int    sys_msgget(struct thread *, struct msgget_args *);
diff --git a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h 
b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
index dc19c7c2..6f28fea4 100644
--- a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
+++ b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
@@ -5840,8 +5840,6 @@
 #define        sys_open _bsd_sys_open
 #define        sys_openat _bsd_sys_openat
 #define        sys_pipe2 _bsd_sys_pipe2
-#define        sys_poll _bsd_sys_poll
-#define        sys_pselect _bsd_sys_pselect
 #define        sys_read _bsd_sys_read
 #define        sys_readlink _bsd_sys_readlink
 #define        sys_readlinkat _bsd_sys_readlinkat
@@ -5851,7 +5849,6 @@
 #define        sys_rename _bsd_sys_rename
 #define        sys_renameat _bsd_sys_renameat
 #define        sys_rmdir _bsd_sys_rmdir
-#define        sys_select _bsd_sys_select
 #define        sys_sendmsg _bsd_sys_sendmsg
 #define        sys_sendto _bsd_sys_sendto
 #define        sys_setsockopt _bsd_sys_setsockopt
diff --git a/rtemsbsd/rtems/rtems-bsd-syscall-api.c 
b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
index 8a60afc1..0ab85bbf 100644
--- a/rtemsbsd/rtems/rtems-bsd-syscall-api.c
+++ b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
@@ -401,68 +401,6 @@ listen(int socket, int backlog)
        return rtems_bsd_error_to_status_and_errno(error);
 }
 
-int
-poll(struct pollfd fds[], nfds_t nfds, int timeout)
-{
-       struct thread *td = rtems_bsd_get_curthread_or_null();
-       struct poll_args ua;
-       int error;
-       if (RTEMS_BSD_SYSCALL_TRACE) {
-               printf("bsd: sys: poll: %d\n", nfds);
-       }
-       if (td == NULL) {
-               return rtems_bsd_error_to_status_and_errno(ENOMEM);
-       }
-       /*
-        * Pass libio descriptors through as libio and bsd descriptors
-        * can be in the list at the same time.
-        */
-       ua.fds = &fds[0];
-       ua.nfds = nfds;
-       ua.timeout = timeout;
-       error = sys_poll(td, &ua);
-       if (error != 0) {
-               return rtems_bsd_error_to_status_and_errno(error);
-       }
-       return td->td_retval[0];
-}
-
-int
-pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds,
-    const struct timespec *timeout, const sigset_t *set)
-{
-       struct thread *td;
-       struct timeval tv;
-       struct timeval *tvp;
-       int error;
-       if (RTEMS_BSD_SYSCALL_TRACE) {
-               printf("bsd: sys: pselect: %d\n", nfds);
-       }
-       if (set != NULL) {
-               return rtems_bsd_error_to_status_and_errno(ENOSYS);
-       }
-       td = rtems_bsd_get_curthread_or_null();
-       if (td == NULL) {
-               return rtems_bsd_error_to_status_and_errno(ENOMEM);
-       }
-       if (timeout != NULL) {
-               TIMESPEC_TO_TIMEVAL(&tv, timeout);
-               tvp = &tv;
-       } else {
-               tvp = NULL;
-       }
-       /*
-        * Pass libio descriptors through as libio and bsd descriptors
-        * can be in the list at the same time.
-        */
-       error = kern_select(
-           td, nfds, readfds, writefds, errorfds, tvp, NFDBITS);
-       if (error != 0) {
-               return rtems_bsd_error_to_status_and_errno(error);
-       }
-       return td->td_retval[0];
-}
-
 ssize_t
 recvfrom(int socket, void *__restrict buffer, size_t length, int flags,
     struct sockaddr *__restrict address, socklen_t *__restrict address_len)
@@ -511,30 +449,6 @@ recvmsg(int socket, struct msghdr *message, int flags)
        return td->td_retval[0];
 }
 
-int
-select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds,
-    struct timeval *timeout)
-{
-       struct thread *td = rtems_bsd_get_curthread_or_null();
-       int error;
-       if (RTEMS_BSD_SYSCALL_TRACE) {
-               printf("bsd: sys: select: %d\n", nfds);
-       }
-       if (td == NULL) {
-               return rtems_bsd_error_to_status_and_errno(ENOMEM);
-       }
-       /*
-        * Pass libio descriptors through as libio and bsd descriptors
-        * can be in the list at the same time.
-        */
-       error = kern_select(
-           td, nfds, readfds, writefds, errorfds, timeout, NFDBITS);
-       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)
-- 
2.35.3

_______________________________________________
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Reply via email to