From fe778ac0277fd3f165ff70dfd269a6ed44dbdc99 Mon Sep 17 00:00:00 2001
From: Chris Johns <chrisj@rtems.org>
Date: Thu, 29 Jul 2021 13:24:49 +1000
Subject: [PATCH rtems-libbsd v4 17/19] kern/sys: Add the kernel RPC and XDR
 support

Updates #4475
---
 buildset/default.ini                          |   1 +
 freebsd/sys/rpc/auth_none.c                   |   2 +
 freebsd/sys/rpc/auth_unix.c                   |   2 +
 freebsd/sys/rpc/authunix_prot.c               |  21 +++
 freebsd/sys/rpc/clnt_bck.c                    |   2 +
 freebsd/sys/rpc/clnt_dg.c                     |   2 +
 freebsd/sys/rpc/clnt_rc.c                     |   2 +
 freebsd/sys/rpc/clnt_vc.c                     |   2 +
 freebsd/sys/rpc/getnetconfig.c                |   4 +-
 freebsd/sys/rpc/replay.c                      |   2 +
 freebsd/sys/rpc/rpc_callmsg.c                 |   2 +
 freebsd/sys/rpc/rpc_com.h                     |   5 +
 freebsd/sys/rpc/rpc_generic.c                 |   4 +-
 freebsd/sys/rpc/rpc_prot.c                    |   2 +
 freebsd/sys/rpc/rpcb_clnt.c                   |   4 +-
 freebsd/sys/rpc/rpcb_prot.c                   |   2 +
 freebsd/sys/rpc/svc.c                         |  17 +++
 freebsd/sys/rpc/svc_auth.c                    |   5 +-
 freebsd/sys/rpc/svc_auth_unix.c               |   2 +
 freebsd/sys/rpc/svc_dg.c                      |   2 +
 freebsd/sys/rpc/svc_generic.c                 |   4 +-
 freebsd/sys/rpc/svc_vc.c                      |   2 +
 freebsd/sys/xdr/xdr.c                         |   2 +
 freebsd/sys/xdr/xdr_array.c                   |   2 +
 freebsd/sys/xdr/xdr_mbuf.c                    |   2 +
 freebsd/sys/xdr/xdr_mem.c                     |   2 +
 freebsd/sys/xdr/xdr_reference.c               |   2 +
 freebsd/sys/xdr/xdr_sizeof.c                  |   2 +
 libbsd.py                                     |  67 +++++++++
 .../machine/rtems-bsd-kernel-namespace.h      | 133 ++++++++++++++++++
 30 files changed, 298 insertions(+), 5 deletions(-)

diff --git a/buildset/default.ini b/buildset/default.ini
index 9c0d1bf8..5848a459 100644
--- a/buildset/default.ini
+++ b/buildset/default.ini
@@ -51,6 +51,7 @@ netinet = on
 netinet6 = on
 netipsec = off
 nfsv2 = on
+rpc = on
 nvme = on
 opencrypto = on
 pci = on
diff --git a/freebsd/sys/rpc/auth_none.c b/freebsd/sys/rpc/auth_none.c
index 236b4aa1..cafd8948 100644
--- a/freebsd/sys/rpc/auth_none.c
+++ b/freebsd/sys/rpc/auth_none.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: auth_none.c,v 1.13 2000/01/22 22:19:17 mycroft Exp $	*/
 
 /*-
diff --git a/freebsd/sys/rpc/auth_unix.c b/freebsd/sys/rpc/auth_unix.c
index 4a3df5f7..3b344059 100644
--- a/freebsd/sys/rpc/auth_unix.c
+++ b/freebsd/sys/rpc/auth_unix.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: auth_unix.c,v 1.18 2000/07/06 03:03:30 christos Exp $	*/
 
 /*-
diff --git a/freebsd/sys/rpc/authunix_prot.c b/freebsd/sys/rpc/authunix_prot.c
index b6cde0fb..06dfe863 100644
--- a/freebsd/sys/rpc/authunix_prot.c
+++ b/freebsd/sys/rpc/authunix_prot.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: authunix_prot.c,v 1.12 2000/01/22 22:19:17 mycroft Exp $	*/
 
 /*-
@@ -74,7 +76,11 @@ xdr_authunix_parms(XDR *xdrs, uint32_t *time, struct xucred *cred)
 		/*
 		 * Restrict name length to 255 according to RFC 1057.
 		 */
+#ifndef __rtems__
 		getcredhostname(NULL, hostbuf, sizeof(hostbuf));
+#else /* __rtems__ */
+		gethostname(hostbuf, sizeof(hostbuf));
+#endif /* __rtems__ */
 		namelen = strlen(hostbuf);
 		if (namelen > 255)
 			namelen = 255;
@@ -97,9 +103,19 @@ xdr_authunix_parms(XDR *xdrs, uint32_t *time, struct xucred *cred)
 		xdr_setpos(xdrs, xdr_getpos(xdrs) + RNDUP(namelen));
 	}
 
+#ifndef __rtems__
 	if (!xdr_uint32_t(xdrs, &cred->cr_uid))
+#else /* __rtems__ */
+	junk = cred->cr_uid;
+	if (!xdr_uint32_t(xdrs, &junk))
+#endif /* __rtems__ */
 		return (FALSE);
+#ifndef __rtems__
 	if (!xdr_uint32_t(xdrs, &cred->cr_groups[0]))
+#else /* __rtems__ */
+	junk = cred->cr_groups[0];
+	if (!xdr_uint32_t(xdrs, &junk))
+#endif /* __rtems__ */
 		return (FALSE);
 
 	if (xdrs->x_op == XDR_ENCODE) {
@@ -112,7 +128,12 @@ xdr_authunix_parms(XDR *xdrs, uint32_t *time, struct xucred *cred)
 		return (FALSE);
 	for (i = 0; i < ngroups; i++) {
 		if (i + 1 < ngroups_max + 1) {
+#ifndef __rtems__
 			if (!xdr_uint32_t(xdrs, &cred->cr_groups[i + 1]))
+#else /* __rtems__ */
+			junk = cred->cr_uid;
+			if (!xdr_uint32_t(xdrs, &junk))
+#endif /* __rtems__ */
 				return (FALSE);
 		} else {
 			if (!xdr_uint32_t(xdrs, &junk))
diff --git a/freebsd/sys/rpc/clnt_bck.c b/freebsd/sys/rpc/clnt_bck.c
index 66f3c308..aeb7087c 100644
--- a/freebsd/sys/rpc/clnt_bck.c
+++ b/freebsd/sys/rpc/clnt_bck.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: clnt_vc.c,v 1.4 2000/07/14 08:40:42 fvdl Exp $	*/
 
 /*-
diff --git a/freebsd/sys/rpc/clnt_dg.c b/freebsd/sys/rpc/clnt_dg.c
index 4c40a494..217ff5a0 100644
--- a/freebsd/sys/rpc/clnt_dg.c
+++ b/freebsd/sys/rpc/clnt_dg.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: clnt_dg.c,v 1.4 2000/07/14 08:40:41 fvdl Exp $	*/
 
 /*-
diff --git a/freebsd/sys/rpc/clnt_rc.c b/freebsd/sys/rpc/clnt_rc.c
index 5254f4c8..6f74a2cc 100644
--- a/freebsd/sys/rpc/clnt_rc.c
+++ b/freebsd/sys/rpc/clnt_rc.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
diff --git a/freebsd/sys/rpc/clnt_vc.c b/freebsd/sys/rpc/clnt_vc.c
index 0231c303..b3fb5d81 100644
--- a/freebsd/sys/rpc/clnt_vc.c
+++ b/freebsd/sys/rpc/clnt_vc.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: clnt_vc.c,v 1.4 2000/07/14 08:40:42 fvdl Exp $	*/
 
 /*-
diff --git a/freebsd/sys/rpc/getnetconfig.c b/freebsd/sys/rpc/getnetconfig.c
index 05b30dfe..1ae0129d 100644
--- a/freebsd/sys/rpc/getnetconfig.c
+++ b/freebsd/sys/rpc/getnetconfig.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
@@ -27,7 +29,7 @@
  * SUCH DAMAGE.
  */
 
-#include "opt_inet6.h"
+#include <rtems/bsd/local/opt_inet6.h>
 
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
diff --git a/freebsd/sys/rpc/replay.c b/freebsd/sys/rpc/replay.c
index 8e161f72..2e9686e4 100644
--- a/freebsd/sys/rpc/replay.c
+++ b/freebsd/sys/rpc/replay.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
diff --git a/freebsd/sys/rpc/rpc_callmsg.c b/freebsd/sys/rpc/rpc_callmsg.c
index ab0848d7..a01f3f06 100644
--- a/freebsd/sys/rpc/rpc_callmsg.c
+++ b/freebsd/sys/rpc/rpc_callmsg.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: rpc_callmsg.c,v 1.16 2000/07/14 08:40:42 fvdl Exp $	*/
 
 /*-
diff --git a/freebsd/sys/rpc/rpc_com.h b/freebsd/sys/rpc/rpc_com.h
index 70d4214f..7c6224bd 100644
--- a/freebsd/sys/rpc/rpc_com.h
+++ b/freebsd/sys/rpc/rpc_com.h
@@ -57,6 +57,10 @@
 #define	RPC_MAXDATASIZE 9000
 #define	RPC_MAXADDRSIZE 1024
 
+#ifdef __rtems__
+#define __RPC_GETXID(now) ((uint32_t)_Thread_Get_executing() ^ (uint32_t)(now)->tv_sec ^ \
+    (uint32_t)(now)->tv_usec)
+#else /* __rtems__ */
 #ifdef _KERNEL
 
 #define __RPC_GETXID(now) ((uint32_t)curproc->p_pid ^ (uint32_t)(now)->tv_sec ^ \
@@ -68,6 +72,7 @@
     (uint32_t)(now)->tv_usec)
 
 #endif
+#endif /* __rtems__ */
 
 __BEGIN_DECLS
 #ifndef _KERNEL
diff --git a/freebsd/sys/rpc/rpc_generic.c b/freebsd/sys/rpc/rpc_generic.c
index a4d6298b..e3eb8526 100644
--- a/freebsd/sys/rpc/rpc_generic.c
+++ b/freebsd/sys/rpc/rpc_generic.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: rpc_generic.c,v 1.4 2000/09/28 09:07:04 kleink Exp $	*/
 
 /*-
@@ -42,7 +44,7 @@ __FBSDID("$FreeBSD$");
  *
  */
 
-#include "opt_inet6.h"
+#include <rtems/bsd/local/opt_inet6.h>
 
 #include <sys/param.h>
 #include <sys/kernel.h>
diff --git a/freebsd/sys/rpc/rpc_prot.c b/freebsd/sys/rpc/rpc_prot.c
index 70a543d3..7ae4c9f1 100644
--- a/freebsd/sys/rpc/rpc_prot.c
+++ b/freebsd/sys/rpc/rpc_prot.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: rpc_prot.c,v 1.16 2000/06/02 23:11:13 fvdl Exp $	*/
 
 /*-
diff --git a/freebsd/sys/rpc/rpcb_clnt.c b/freebsd/sys/rpc/rpcb_clnt.c
index 8a95999b..4316bc6b 100644
--- a/freebsd/sys/rpc/rpcb_clnt.c
+++ b/freebsd/sys/rpc/rpcb_clnt.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: rpcb_clnt.c,v 1.6 2000/07/16 06:41:43 itojun Exp $	*/
 
 /*-
@@ -49,7 +51,7 @@ __FBSDID("$FreeBSD$");
  * Copyright (C) 1988, Sun Microsystems, Inc.
  */
 
-#include "opt_inet6.h"
+#include <rtems/bsd/local/opt_inet6.h>
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff --git a/freebsd/sys/rpc/rpcb_prot.c b/freebsd/sys/rpc/rpcb_prot.c
index a59dc501..8de849d1 100644
--- a/freebsd/sys/rpc/rpcb_prot.c
+++ b/freebsd/sys/rpc/rpcb_prot.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: rpcb_prot.c,v 1.3 2000/07/14 08:40:42 fvdl Exp $	*/
 
 /*-
diff --git a/freebsd/sys/rpc/svc.c b/freebsd/sys/rpc/svc.c
index cd44b8fd..1f32ad30 100644
--- a/freebsd/sys/rpc/svc.c
+++ b/freebsd/sys/rpc/svc.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: svc.c,v 1.21 2000/07/06 03:10:35 christos Exp $	*/
 
 /*-
@@ -1226,6 +1228,11 @@ svc_run_internal(SVCGROUP *grp, bool_t ismaster)
 			} else if (error != 0) {
 				KASSERT(error == EINTR || error == ERESTART,
 				    ("non-signal error %d", error));
+#ifdef __rtems__
+				mtx_unlock(&grp->sg_lock);
+				svc_exit(pool);
+				mtx_lock(&grp->sg_lock);
+#else /* __rtems__ */
 				mtx_unlock(&grp->sg_lock);
 				p = curproc;
 				PROC_LOCK(p);
@@ -1240,6 +1247,7 @@ svc_run_internal(SVCGROUP *grp, bool_t ismaster)
 					mtx_lock(&grp->sg_lock);
 					break;
 				}
+#endif /* __rtems__ */
 			}
 			continue;
 		}
@@ -1352,16 +1360,25 @@ void
 svc_run(SVCPOOL *pool)
 {
 	int g, i;
+#ifndef __rtems__
 	struct proc *p;
 	struct thread *td;
+#endif /* __rtems__ */
 	SVCGROUP *grp;
 
+#ifndef __rtems__
 	p = curproc;
 	td = curthread;
 	snprintf(td->td_name, sizeof(td->td_name),
 	    "%s: master", pool->sp_name);
+#endif /* __rtems__ */
+
 	pool->sp_state = SVCPOOL_ACTIVE;
+#ifndef __rtems__
 	pool->sp_proc = p;
+#else /* __rtems__ */
+	pool->sp_proc = NULL;
+#endif /* __rtems__ */
 
 	/* Choose group count based on number of threads and CPUs. */
 	pool->sp_groupcount = max(1, min(SVC_MAXGROUPS,
diff --git a/freebsd/sys/rpc/svc_auth.c b/freebsd/sys/rpc/svc_auth.c
index 5dbc64b7..77d767ca 100644
--- a/freebsd/sys/rpc/svc_auth.c
+++ b/freebsd/sys/rpc/svc_auth.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: svc_auth.c,v 1.12 2000/07/06 03:10:35 christos Exp $	*/
 
 /*-
@@ -181,8 +183,10 @@ svc_getcred(struct svc_req *rqst, struct ucred **crp, int *flavorp)
 		cr->cr_uid = cr->cr_ruid = cr->cr_svuid = xcr->cr_uid;
 		crsetgroups(cr, xcr->cr_ngroups, xcr->cr_groups);
 		cr->cr_rgid = cr->cr_svgid = cr->cr_groups[0];
+#ifndef __rtems__
 		cr->cr_prison = &prison0;
 		prison_hold(cr->cr_prison);
+#endif /* __rtems__ */
 		*crp = cr;
 		return (TRUE);
 
@@ -195,4 +199,3 @@ svc_getcred(struct svc_req *rqst, struct ucred **crp, int *flavorp)
 		return (FALSE);
 	}
 }
-
diff --git a/freebsd/sys/rpc/svc_auth_unix.c b/freebsd/sys/rpc/svc_auth_unix.c
index de46bf43..4471d8c1 100644
--- a/freebsd/sys/rpc/svc_auth_unix.c
+++ b/freebsd/sys/rpc/svc_auth_unix.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*-
  * SPDX-License-Identifier: BSD-3-Clause
  *
diff --git a/freebsd/sys/rpc/svc_dg.c b/freebsd/sys/rpc/svc_dg.c
index 2bdd0700..5d051dc8 100644
--- a/freebsd/sys/rpc/svc_dg.c
+++ b/freebsd/sys/rpc/svc_dg.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: svc_dg.c,v 1.4 2000/07/06 03:10:35 christos Exp $	*/
 
 /*-
diff --git a/freebsd/sys/rpc/svc_generic.c b/freebsd/sys/rpc/svc_generic.c
index 54e9cd0b..404ce3f8 100644
--- a/freebsd/sys/rpc/svc_generic.c
+++ b/freebsd/sys/rpc/svc_generic.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: svc_generic.c,v 1.3 2000/07/06 03:10:35 christos Exp $	*/
 
 /*-
@@ -46,7 +48,7 @@ __FBSDID("$FreeBSD$");
  *
  */
 
-#include "opt_inet6.h"
+#include <rtems/bsd/local/opt_inet6.h>
 
 #include <sys/param.h>
 #include <sys/lock.h>
diff --git a/freebsd/sys/rpc/svc_vc.c b/freebsd/sys/rpc/svc_vc.c
index dd6b801f..719fc87a 100644
--- a/freebsd/sys/rpc/svc_vc.c
+++ b/freebsd/sys/rpc/svc_vc.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: svc_vc.c,v 1.7 2000/08/03 00:01:53 fvdl Exp $	*/
 
 /*-
diff --git a/freebsd/sys/xdr/xdr.c b/freebsd/sys/xdr/xdr.c
index 915d27bc..b26a1018 100644
--- a/freebsd/sys/xdr/xdr.c
+++ b/freebsd/sys/xdr/xdr.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: xdr.c,v 1.22 2000/07/06 03:10:35 christos Exp $	*/
 
 /*
diff --git a/freebsd/sys/xdr/xdr_array.c b/freebsd/sys/xdr/xdr_array.c
index 31fe9343..38616084 100644
--- a/freebsd/sys/xdr/xdr_array.c
+++ b/freebsd/sys/xdr/xdr_array.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: xdr_array.c,v 1.12 2000/01/22 22:19:18 mycroft Exp $	*/
 
 /*
diff --git a/freebsd/sys/xdr/xdr_mbuf.c b/freebsd/sys/xdr/xdr_mbuf.c
index 571dfec7..489351cc 100644
--- a/freebsd/sys/xdr/xdr_mbuf.c
+++ b/freebsd/sys/xdr/xdr_mbuf.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
diff --git a/freebsd/sys/xdr/xdr_mem.c b/freebsd/sys/xdr/xdr_mem.c
index 8a14f17e..3e0bd006 100644
--- a/freebsd/sys/xdr/xdr_mem.c
+++ b/freebsd/sys/xdr/xdr_mem.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: xdr_mem.c,v 1.15 2000/01/22 22:19:18 mycroft Exp $	*/
 
 /*
diff --git a/freebsd/sys/xdr/xdr_reference.c b/freebsd/sys/xdr/xdr_reference.c
index 16ff8482..c630ea36 100644
--- a/freebsd/sys/xdr/xdr_reference.c
+++ b/freebsd/sys/xdr/xdr_reference.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*	$NetBSD: xdr_reference.c,v 1.13 2000/01/22 22:19:18 mycroft Exp	$ */
 
 /*
diff --git a/freebsd/sys/xdr/xdr_sizeof.c b/freebsd/sys/xdr/xdr_sizeof.c
index 5452834d..9d5bf4c0 100644
--- a/freebsd/sys/xdr/xdr_sizeof.c
+++ b/freebsd/sys/xdr/xdr_sizeof.c
@@ -1,3 +1,5 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
diff --git a/libbsd.py b/libbsd.py
index c5f601ed..bd0e6de9 100644
--- a/libbsd.py
+++ b/libbsd.py
@@ -2817,6 +2817,71 @@ class nfsv2(builder.Module):
             mm.generator['source']()
         )
 
+#
+# RPC
+#
+class rpc(builder.Module):
+
+    def __init__(self, manager):
+        super(rpc, self).__init__(manager, type(self).__name__)
+
+    def generate(self):
+        mm = self.manager
+        self.addKernelSpaceHeaderFiles(
+            [
+                'sys/kgssapi/gssapi.h',
+                'sys/rpc/auth.h',
+                'sys/rpc/clnt.h',
+                'sys/rpc/clnt_stat.h',
+                'sys/rpc/krpc.h',
+                'sys/rpc/netconfig.h',
+                'sys/rpc/nettype.h',
+                'sys/rpc/pmap_prot.h',
+                'sys/rpc/replay.h',
+                'sys/rpc/rpc.h',
+                'sys/rpc/rpc_com.h',
+                'sys/rpc/rpc_msg.h',
+                'sys/rpc/rpcb_clnt.h',
+                'sys/rpc/rpcb_prot.h',
+                'sys/rpc/rpcm_subs.h',
+                'sys/rpc/rpcsec_gss.h',
+                'sys/rpc/svc.h',
+                'sys/rpc/svc_auth.h',
+                'sys/rpc/types.h',
+                'sys/rpc/xdr.h',
+            ]
+        )
+        self.addKernelSpaceSourceFiles(
+            [
+                'sys/rpc/auth_none.c',
+                'sys/rpc/auth_unix.c',
+                'sys/rpc/authunix_prot.c',
+                'sys/rpc/clnt_bck.c',
+                'sys/rpc/clnt_dg.c',
+                'sys/rpc/clnt_rc.c',
+                'sys/rpc/clnt_vc.c',
+                'sys/rpc/getnetconfig.c',
+                'sys/rpc/replay.c',
+                'sys/rpc/rpc_callmsg.c',
+                'sys/rpc/rpc_generic.c',
+                'sys/rpc/rpc_prot.c',
+                'sys/rpc/rpcb_clnt.c',
+                'sys/rpc/rpcb_prot.c',
+                'sys/rpc/svc.c',
+                'sys/rpc/svc_auth.c',
+                'sys/rpc/svc_auth_unix.c',
+                'sys/rpc/svc_dg.c',
+                'sys/rpc/svc_generic.c',
+                'sys/rpc/svc_vc.c',
+                'sys/xdr/xdr.c',
+                'sys/xdr/xdr_array.c',
+                'sys/xdr/xdr_mbuf.c',
+                'sys/xdr/xdr_mem.c',
+                'sys/xdr/xdr_reference.c',
+                'sys/xdr/xdr_sizeof.c',
+            ],
+            mm.generator['source']()
+        )
 
 #
 # PCI
@@ -5380,6 +5445,8 @@ def load(mm):
     mm.addModule(rpc_user(mm))
     mm.addModule(nfsv2(mm))
 
+    mm.addModule(rpc(mm))
+
     # Add PCI
     mm.addModule(pci(mm))
 
diff --git a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
index 9d3472d6..9e91feac 100644
--- a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
+++ b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
@@ -139,6 +139,7 @@
 #define	M_PCB _bsd_M_PCB
 #define	M_PFHASH _bsd_M_PFHASH
 #define	M_REGULATOR _bsd_M_REGULATOR
+#define	M_RPC _bsd_M_RPC
 #define	M_RTABLE _bsd_M_RTABLE
 #define	M_RTWN_PRIV _bsd_M_RTWN_PRIV
 #define	M_SONAME _bsd_M_SONAME
@@ -304,7 +305,22 @@
 #define	__mnt_vnode_markerfree_all _bsd___mnt_vnode_markerfree_all
 #define	__mnt_vnode_next_active _bsd___mnt_vnode_next_active
 #define	__mnt_vnode_next_all _bsd___mnt_vnode_next_all
+#define	__rpc_endconf _bsd___rpc_endconf
+#define	__rpc_get_a_size _bsd___rpc_get_a_size
+#define	__rpc_get_t_size _bsd___rpc_get_t_size
+#define	__rpc_getconf _bsd___rpc_getconf
+#define	__rpc_getconfip _bsd___rpc_getconfip
+#define	__rpc_nconf2socket _bsd___rpc_nconf2socket
+#define	__rpc_nconf2sockinfo _bsd___rpc_nconf2sockinfo
+#define	__rpc_seman2socktype _bsd___rpc_seman2socktype
+#define	__rpc_setconf _bsd___rpc_setconf
+#define	__rpc_socket2sockinfo _bsd___rpc_socket2sockinfo
+#define	__rpc_sockisbound _bsd___rpc_sockisbound
+#define	__rpc_socktype2seman _bsd___rpc_socktype2seman
+#define	__rpc_taddr2uaddr_af _bsd___rpc_taddr2uaddr_af
+#define	__rpc_uaddr2taddr_af _bsd___rpc_uaddr2taddr_af
 #define	__vfs_statfs _bsd___vfs_statfs
+#define	_authenticate _bsd__authenticate
 #define	_callout_init_lock _bsd__callout_init_lock
 #define	_callout_stop_safe _bsd__callout_stop_safe
 #define	_ck_epoch_addref _bsd__ck_epoch_addref
@@ -342,6 +358,7 @@
 #define	_mtx_assert _bsd__mtx_assert
 #define	_mtx_lock_flags _bsd__mtx_lock_flags
 #define	_mtx_unlock_flags _bsd__mtx_unlock_flags
+#define	_null_auth _bsd__null_auth
 #define	_rw_assert _bsd__rw_assert
 #define	_rw_downgrade _bsd__rw_downgrade
 #define	_rw_rlock _bsd__rw_rlock
@@ -351,6 +368,7 @@
 #define	_rw_try_wlock _bsd__rw_try_wlock
 #define	_rw_wlock _bsd__rw_wlock
 #define	_rw_wunlock _bsd__rw_wunlock
+#define	_seterr_reply _bsd__seterr_reply
 #define	_sleep _bsd__sleep
 #define	_start_set_crypto_set _bsd__start_set_crypto_set
 #define	_start_set_ieee80211_ioctl_getset _bsd__start_set_ieee80211_ioctl_getset
@@ -372,6 +390,9 @@
 #define	_stop_set_scanner_set _bsd__stop_set_scanner_set
 #define	_stop_set_sysctl_set _bsd__stop_set_sysctl_set
 #define	_stop_set_sysinit_set _bsd__stop_set_sysinit_set
+#define	_svcauth_null _bsd__svcauth_null
+#define	_svcauth_short _bsd__svcauth_short
+#define	_svcauth_unix _bsd__svcauth_unix
 #define	_sx_assert _bsd__sx_assert
 #define	_sx_slock_int _bsd__sx_slock_int
 #define	_sx_sunlock_int _bsd__sx_sunlock_int
@@ -462,6 +483,8 @@
 #define	auth_hash_sha2_256 _bsd_auth_hash_sha2_256
 #define	auth_hash_sha2_384 _bsd_auth_hash_sha2_384
 #define	auth_hash_sha2_512 _bsd_auth_hash_sha2_512
+#define	authnone_create _bsd_authnone_create
+#define	authunix_create _bsd_authunix_create
 #define	babarrierwrite _bsd_babarrierwrite
 #define	badfileops _bsd_badfileops
 #define	badport_bandlim _bsd_badport_bandlim
@@ -707,6 +730,7 @@
 #define	be_uuid_enc _bsd_be_uuid_enc
 #define	bgetvp _bsd_bgetvp
 #define	bin2bcd_data _bsd_bin2bcd_data
+#define	bindresvport _bsd_bindresvport
 #define	bio_transient_maxcnt _bsd_bio_transient_maxcnt
 #define	biodone _bsd_biodone
 #define	biofinish _bsd_biofinish
@@ -1030,6 +1054,13 @@
 #define	clean_unrhdrl _bsd_clean_unrhdrl
 #define	clear_unrhdr _bsd_clear_unrhdr
 #define	clk_intr_event _bsd_clk_intr_event
+#define	clnt_bck_call _bsd_clnt_bck_call
+#define	clnt_bck_create _bsd_clnt_bck_create
+#define	clnt_bck_svccall _bsd_clnt_bck_svccall
+#define	clnt_call_private _bsd_clnt_call_private
+#define	clnt_dg_create _bsd_clnt_dg_create
+#define	clnt_reconnect_create _bsd_clnt_reconnect_create
+#define	clnt_vc_create _bsd_clnt_vc_create
 #define	closef _bsd_closef
 #define	comp_algo_deflate _bsd_comp_algo_deflate
 #define	comp_algorithm_lookup _bsd_comp_algorithm_lookup
@@ -1606,6 +1637,7 @@
 #define	enc_xform_skipjack _bsd_enc_xform_skipjack
 #define	encap4_input _bsd_encap4_input
 #define	encap6_input _bsd_encap6_input
+#define	endnetconfig _bsd_endnetconfig
 #define	eopnotsupp _bsd_eopnotsupp
 #define	epoch_call _bsd_epoch_call
 #define	epoch_drain_callbacks _bsd_epoch_drain_callbacks
@@ -1791,6 +1823,7 @@
 #define	frag6_set_bucketsize _bsd_frag6_set_bucketsize
 #define	frag6_slowtimo _bsd_frag6_slowtimo
 #define	free_unr _bsd_free_unr
+#define	freenetconfigent _bsd_freenetconfigent
 #define	fs_filtops _bsd_fs_filtops
 #define	gbincore _bsd_gbincore
 #define	genkbd_commonioctl _bsd_genkbd_commonioctl
@@ -1803,6 +1836,8 @@
 #define	getblkx _bsd_getblkx
 #define	getcredhostuuid _bsd_getcredhostuuid
 #define	geteblk _bsd_geteblk
+#define	getnetconfig _bsd_getnetconfig
+#define	getnetconfigent _bsd_getnetconfigent
 #define	getnewvnode _bsd_getnewvnode
 #define	getnewvnode_drop_reserve _bsd_getnewvnode_drop_reserve
 #define	getnewvnode_reserve _bsd_getnewvnode_reserve
@@ -4496,6 +4531,11 @@
 #define	regulator_stop _bsd_regulator_stop
 #define	relookup _bsd_relookup
 #define	relpbuf _bsd_relpbuf
+#define	replay_find _bsd_replay_find
+#define	replay_freecache _bsd_replay_freecache
+#define	replay_newcache _bsd_replay_newcache
+#define	replay_setreply _bsd_replay_setreply
+#define	replay_setsize _bsd_replay_setsize
 #define	resource_disabled _bsd_resource_disabled
 #define	resource_find_match _bsd_resource_find_match
 #define	resource_int_value _bsd_resource_int_value
@@ -4601,6 +4641,10 @@
 #define	root_bus_configure _bsd_root_bus_configure
 #define	root_devclass _bsd_root_devclass
 #define	route6_input _bsd_route6_input
+#define	rpc_createerr _bsd_rpc_createerr
+#define	rpc_gss_entries _bsd_rpc_gss_entries
+#define	rpcb_set _bsd_rpcb_set
+#define	rpcb_unset _bsd_rpcb_unset
 #define	rsvp_input _bsd_rsvp_input
 #define	rsvp_input_p _bsd_rsvp_input_p
 #define	rsvp_on _bsd_rsvp_on
@@ -5203,6 +5247,7 @@
 #define	send_sendso_input_hook _bsd_send_sendso_input_hook
 #define	setfmode _bsd_setfmode
 #define	setfown _bsd_setfown
+#define	setnetconfig _bsd_setnetconfig
 #define	sha1_init _bsd_sha1_init
 #define	sha1_loop _bsd_sha1_loop
 #define	sha1_pad _bsd_sha1_pad
@@ -5342,6 +5387,37 @@
 #define	sprintf _bsd_sprintf
 #define	statfs_scale_blocks _bsd_statfs_scale_blocks
 #define	subkey_table_gen _bsd_subkey_table_gen
+#define	svc_auth_reg _bsd_svc_auth_reg
+#define	svc_create _bsd_svc_create
+#define	svc_dg_create _bsd_svc_dg_create
+#define	svc_exit _bsd_svc_exit
+#define	svc_freeargs _bsd_svc_freeargs
+#define	svc_freereq _bsd_svc_freereq
+#define	svc_getargs _bsd_svc_getargs
+#define	svc_getcred _bsd_svc_getcred
+#define	svc_loss_reg _bsd_svc_loss_reg
+#define	svc_loss_unreg _bsd_svc_loss_unreg
+#define	svc_reg _bsd_svc_reg
+#define	svc_run _bsd_svc_run
+#define	svc_sendreply _bsd_svc_sendreply
+#define	svc_sendreply_mbuf _bsd_svc_sendreply_mbuf
+#define	svc_tli_create _bsd_svc_tli_create
+#define	svc_tp_create _bsd_svc_tp_create
+#define	svc_unreg _bsd_svc_unreg
+#define	svc_vc_create _bsd_svc_vc_create
+#define	svc_vc_create_backchannel _bsd_svc_vc_create_backchannel
+#define	svc_xprt_alloc _bsd_svc_xprt_alloc
+#define	svc_xprt_free _bsd_svc_xprt_free
+#define	svcerr_auth _bsd_svcerr_auth
+#define	svcerr_decode _bsd_svcerr_decode
+#define	svcerr_noproc _bsd_svcerr_noproc
+#define	svcerr_noprog _bsd_svcerr_noprog
+#define	svcerr_progvers _bsd_svcerr_progvers
+#define	svcerr_systemerr _bsd_svcerr_systemerr
+#define	svcerr_weakauth _bsd_svcerr_weakauth
+#define	svcpool_close _bsd_svcpool_close
+#define	svcpool_create _bsd_svcpool_create
+#define	svcpool_destroy _bsd_svcpool_destroy
 #define	swi_add _bsd_swi_add
 #define	swi_sched _bsd_swi_sched
 #define	sx_destroy _bsd_sx_destroy
@@ -5570,6 +5646,7 @@
 #define	system_base_info _bsd_system_base_info
 #define	t_functions _bsd_t_functions
 #define	t_functions_inited _bsd_t_functions_inited
+#define	taddr2uaddr _bsd_taddr2uaddr
 #define	taskqgroup_adjust _bsd_taskqgroup_adjust
 #define	taskqgroup_attach _bsd_taskqgroup_attach
 #define	taskqgroup_attach_cpu _bsd_taskqgroup_attach_cpu
@@ -5854,6 +5931,7 @@
 #define	ttyoutq_write _bsd_ttyoutq_write
 #define	ttyoutq_write_nofrag _bsd_ttyoutq_write_nofrag
 #define	tvtohz _bsd_tvtohz
+#define	uaddr2taddr _bsd_uaddr2taddr
 #define	ucom_attach _bsd_ucom_attach
 #define	ucom_cfg_is_gone _bsd_ucom_cfg_is_gone
 #define	ucom_cnops _bsd_ucom_cnops
@@ -6501,10 +6579,65 @@
 #define	window_deflate _bsd_window_deflate
 #define	window_inflate _bsd_window_inflate
 #define	write_dsfield _bsd_write_dsfield
+#define	xdr_accepted_reply _bsd_xdr_accepted_reply
+#define	xdr_array _bsd_xdr_array
+#define	xdr_authunix_parms _bsd_xdr_authunix_parms
+#define	xdr_bool _bsd_xdr_bool
+#define	xdr_bytes _bsd_xdr_bytes
+#define	xdr_callhdr _bsd_xdr_callhdr
+#define	xdr_callmsg _bsd_xdr_callmsg
+#define	xdr_char _bsd_xdr_char
+#define	xdr_enum _bsd_xdr_enum
+#define	xdr_free _bsd_xdr_free
+#define	xdr_hyper _bsd_xdr_hyper
+#define	xdr_int _bsd_xdr_int
+#define	xdr_int16_t _bsd_xdr_int16_t
+#define	xdr_int32_t _bsd_xdr_int32_t
+#define	xdr_int64_t _bsd_xdr_int64_t
+#define	xdr_long _bsd_xdr_long
+#define	xdr_longlong_t _bsd_xdr_longlong_t
+#define	xdr_netobj _bsd_xdr_netobj
+#define	xdr_opaque _bsd_xdr_opaque
+#define	xdr_opaque_auth _bsd_xdr_opaque_auth
+#define	xdr_pointer _bsd_xdr_pointer
+#define	xdr_portmap _bsd_xdr_portmap
+#define	xdr_reference _bsd_xdr_reference
+#define	xdr_rejected_reply _bsd_xdr_rejected_reply
+#define	xdr_replymsg _bsd_xdr_replymsg
+#define	xdr_rpcb _bsd_xdr_rpcb
+#define	xdr_rpcb_entry _bsd_xdr_rpcb_entry
+#define	xdr_rpcb_entry_list_ptr _bsd_xdr_rpcb_entry_list_ptr
+#define	xdr_rpcblist_ptr _bsd_xdr_rpcblist_ptr
+#define	xdr_short _bsd_xdr_short
+#define	xdr_sizeof _bsd_xdr_sizeof
+#define	xdr_string _bsd_xdr_string
+#define	xdr_u_char _bsd_xdr_u_char
+#define	xdr_u_hyper _bsd_xdr_u_hyper
+#define	xdr_u_int _bsd_xdr_u_int
+#define	xdr_u_long _bsd_xdr_u_long
+#define	xdr_u_longlong_t _bsd_xdr_u_longlong_t
+#define	xdr_u_short _bsd_xdr_u_short
+#define	xdr_uint16_t _bsd_xdr_uint16_t
+#define	xdr_uint32_t _bsd_xdr_uint32_t
+#define	xdr_uint64_t _bsd_xdr_uint64_t
+#define	xdr_union _bsd_xdr_union
+#define	xdr_vector _bsd_xdr_vector
+#define	xdr_void _bsd_xdr_void
+#define	xdr_wrapstring _bsd_xdr_wrapstring
+#define	xdrmbuf_append _bsd_xdrmbuf_append
+#define	xdrmbuf_create _bsd_xdrmbuf_create
+#define	xdrmbuf_getall _bsd_xdrmbuf_getall
+#define	xdrmem_create _bsd_xdrmem_create
 #define	xform_ah_authsize _bsd_xform_ah_authsize
 #define	xform_attach _bsd_xform_attach
 #define	xform_detach _bsd_xform_detach
 #define	xform_init _bsd_xform_init
+#define	xprt_active _bsd_xprt_active
+#define	xprt_inactive _bsd_xprt_inactive
+#define	xprt_inactive_locked _bsd_xprt_inactive_locked
+#define	xprt_inactive_self _bsd_xprt_inactive_self
+#define	xprt_register _bsd_xprt_register
+#define	xprt_unregister _bsd_xprt_unregister
 #define	xpt_bus_deregister _bsd_xpt_bus_deregister
 #define	xpt_bus_register _bsd_xpt_bus_register
 #define	xpt_done _bsd_xpt_done
-- 
2.24.1

