Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/common Make XDR usable from kernel or module.



details:   https://anonhg.NetBSD.org/src/rev/29a99a93b1ae
branches:  trunk
changeset: 841875:29a99a93b1ae
user:      hannken <hannken%NetBSD.org@localhost>
date:      Wed Jun 05 16:25:43 2019 +0000

description:
Make XDR usable from kernel or module.

No user visible changes intended.

diffstat:

 common/include/rpc/types.h      |  17 ++++++++++++++++-
 common/lib/libc/rpc/xdr.c       |  22 ++++++++++++++++++----
 common/lib/libc/rpc/xdr_array.c |  15 +++++++++++++--
 common/lib/libc/rpc/xdr_mem.c   |  14 ++++++++++++--
 4 files changed, 59 insertions(+), 9 deletions(-)

diffs (199 lines):

diff -r 5cbcc097437c -r 29a99a93b1ae common/include/rpc/types.h
--- a/common/include/rpc/types.h        Wed Jun 05 07:22:49 2019 +0000
+++ b/common/include/rpc/types.h        Wed Jun 05 16:25:43 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: types.h,v 1.1 2019/06/04 15:07:55 hannken Exp $        */
+/*     $NetBSD: types.h,v 1.2 2019/06/05 16:25:43 hannken Exp $        */
 
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@@ -62,6 +62,19 @@
 #      define NULL     0
 #endif
 
+#if defined(_KERNEL) || defined(_STANDALONE)
+
+#define warn(msg,...) /**/
+
+typedef __caddr_t caddr_t;
+
+#include <sys/kmem.h>
+
+#define mem_alloc(bsize)       kmem_alloc(bsize, KM_SLEEP)
+#define mem_free(ptr, bsize)   kmem_free(ptr, bsize)
+
+#else /* _KERNEL || _STANDALONE */
+
 #define mem_alloc(bsize)       calloc((size_t)1, bsize)
 #define mem_free(ptr, bsize)   free(ptr)
 
@@ -104,4 +117,6 @@
        int si_alen;
 };
 
+#endif /* _KERNEL || _STANDALONE */
+
 #endif /* !_RPC_TYPES_H_ */
diff -r 5cbcc097437c -r 29a99a93b1ae common/lib/libc/rpc/xdr.c
--- a/common/lib/libc/rpc/xdr.c Wed Jun 05 07:22:49 2019 +0000
+++ b/common/lib/libc/rpc/xdr.c Wed Jun 05 16:25:43 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xdr.c,v 1.1 2019/06/04 15:07:55 hannken Exp $  */
+/*     $NetBSD: xdr.c,v 1.2 2019/06/05 16:25:43 hannken Exp $  */
 
 /*
  * Copyright (c) 2010, Oracle America, Inc.
@@ -37,7 +37,7 @@
 static char *sccsid = "@(#)xdr.c 1.35 87/08/12";
 static char *sccsid = "@(#)xdr.c       2.1 88/07/29 4.0 RPCSRC";
 #else
-__RCSID("$NetBSD: xdr.c,v 1.1 2019/06/04 15:07:55 hannken Exp $");
+__RCSID("$NetBSD: xdr.c,v 1.2 2019/06/05 16:25:43 hannken Exp $");
 #endif
 #endif
 
@@ -51,6 +51,14 @@
  * xdr.
  */
 
+#if defined(_KERNEL) || defined(_STANDALONE)
+
+#include <lib/libkern/libkern.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+
+#else /* _KERNEL || _STANDALONE */
+
 #include "namespace.h"
 
 #include <assert.h>
@@ -95,6 +103,8 @@
 __weak_alias(xdr_wrapstring,_xdr_wrapstring)
 #endif
 
+#endif /* _KERNEL || _STANDALONE */
+
 /*
  * constants specific to the xdr "protocol"
  */
@@ -633,7 +643,7 @@
                ret = xdr_opaque(xdrs, sp, nodesize);
                if ((xdrs->x_op == XDR_DECODE) && (ret == FALSE)) {
                        if (allocated == TRUE) {
-                               free(sp);
+                               mem_free(sp, nodesize);
                                *cpp = NULL;
                        }
                }
@@ -793,7 +803,7 @@
                ret = xdr_opaque(xdrs, sp, size);
                if ((xdrs->x_op == XDR_DECODE) && (ret == FALSE)) {
                        if (allocated == TRUE) {
-                               free(sp);
+                               mem_free(sp, nodesize);
                                *cpp = NULL;
                        }
                }
@@ -808,6 +818,8 @@
        return (FALSE);
 }
 
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+
 /* 
  * Wrapper for xdr_string that can be called directly from 
  * routines like clnt_call
@@ -822,6 +834,8 @@
        return xdr_string(xdrs, cpp, RPC_MAXDATASIZE);
 }
 
+#endif /* !_KERNEL && !_STANDALONE */
+
 /*
  * NOTE: xdr_hyper(), xdr_u_hyper(), xdr_longlong_t(), and xdr_u_longlong_t()
  * are in the "non-portable" section because they require that a `long long'
diff -r 5cbcc097437c -r 29a99a93b1ae common/lib/libc/rpc/xdr_array.c
--- a/common/lib/libc/rpc/xdr_array.c   Wed Jun 05 07:22:49 2019 +0000
+++ b/common/lib/libc/rpc/xdr_array.c   Wed Jun 05 16:25:43 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xdr_array.c,v 1.1 2019/06/04 15:07:55 hannken Exp $    */
+/*     $NetBSD: xdr_array.c,v 1.2 2019/06/05 16:25:43 hannken Exp $    */
 
 /*
  * Copyright (c) 2010, Oracle America, Inc.
@@ -37,7 +37,7 @@
 static char *sccsid = "@(#)xdr_array.c 1.10 87/08/11 Copyr 1984 Sun Micro";
 static char *sccsid = "@(#)xdr_array.c 2.1 88/07/29 4.0 RPCSRC";
 #else
-__RCSID("$NetBSD: xdr_array.c,v 1.1 2019/06/04 15:07:55 hannken Exp $");
+__RCSID("$NetBSD: xdr_array.c,v 1.2 2019/06/05 16:25:43 hannken Exp $");
 #endif
 #endif
 
@@ -50,6 +50,15 @@
  * arrays.  See xdr.h for more info on the interface to xdr.
  */
 
+#if defined(_KERNEL) || defined(_STANDALONE)
+
+#include <sys/param.h>
+#include <lib/libkern/libkern.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+
+#else /* _KERNEL || _STANDALONE */
+
 #include "namespace.h"
 
 #include <err.h>
@@ -66,6 +75,8 @@
 __weak_alias(xdr_vector,_xdr_vector)
 #endif
 
+#endif /* _KERNEL || _STANDALONE */
+
 /*
  * XDR an array of arbitrary elements
  * *addrp is a pointer to the array, *sizep is the number of elements.
diff -r 5cbcc097437c -r 29a99a93b1ae common/lib/libc/rpc/xdr_mem.c
--- a/common/lib/libc/rpc/xdr_mem.c     Wed Jun 05 07:22:49 2019 +0000
+++ b/common/lib/libc/rpc/xdr_mem.c     Wed Jun 05 16:25:43 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xdr_mem.c,v 1.1 2019/06/04 15:07:55 hannken Exp $      */
+/*     $NetBSD: xdr_mem.c,v 1.2 2019/06/05 16:25:43 hannken Exp $      */
 
 /*
  * Copyright (c) 2010, Oracle America, Inc.
@@ -37,7 +37,7 @@
 static char *sccsid = "@(#)xdr_mem.c 1.19 87/08/11 Copyr 1984 Sun Micro";
 static char *sccsid = "@(#)xdr_mem.c   2.1 88/07/29 4.0 RPCSRC";
 #else
-__RCSID("$NetBSD: xdr_mem.c,v 1.1 2019/06/04 15:07:55 hannken Exp $");
+__RCSID("$NetBSD: xdr_mem.c,v 1.2 2019/06/05 16:25:43 hannken Exp $");
 #endif
 #endif
 
@@ -52,6 +52,14 @@
  *
  */
 
+#if defined(_KERNEL) || defined(_STANDALONE)
+
+#include <lib/libkern/libkern.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+
+#else /* _KERNEL || _STANDALONE */
+
 #include "namespace.h"
 
 #include <sys/types.h>
@@ -67,6 +75,8 @@
 __weak_alias(xdrmem_create,_xdrmem_create)
 #endif
 
+#endif /* _KERNEL || _STANDALONE */
+
 static void xdrmem_destroy(XDR *);
 static bool_t xdrmem_getlong_aligned(XDR *, long *);
 static bool_t xdrmem_putlong_aligned(XDR *, const long *);



Home | Main Index | Thread Index | Old Index