Module Name: src Committed By: hannken Date: Wed Jun 5 16:25:43 UTC 2019
Modified Files: src/common/include/rpc: types.h src/common/lib/libc/rpc: xdr.c xdr_array.c xdr_mem.c Log Message: Make XDR usable from kernel or module. No user visible changes intended. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/common/include/rpc/types.h cvs rdiff -u -r1.1 -r1.2 src/common/lib/libc/rpc/xdr.c \ src/common/lib/libc/rpc/xdr_array.c src/common/lib/libc/rpc/xdr_mem.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/common/include/rpc/types.h diff -u src/common/include/rpc/types.h:1.1 src/common/include/rpc/types.h:1.2 --- src/common/include/rpc/types.h:1.1 Tue Jun 4 15:07:55 2019 +++ src/common/include/rpc/types.h Wed Jun 5 16:25:43 2019 @@ -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 @@ typedef int32_t rpc_inline_t; # 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 @@ struct __rpc_sockinfo { int si_alen; }; +#endif /* _KERNEL || _STANDALONE */ + #endif /* !_RPC_TYPES_H_ */ Index: src/common/lib/libc/rpc/xdr.c diff -u src/common/lib/libc/rpc/xdr.c:1.1 src/common/lib/libc/rpc/xdr.c:1.2 --- src/common/lib/libc/rpc/xdr.c:1.1 Tue Jun 4 15:07:55 2019 +++ src/common/lib/libc/rpc/xdr.c Wed Jun 5 16:25:43 2019 @@ -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 @@ __RCSID("$NetBSD: xdr.c,v 1.1 2019/06/04 * 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_void,_xdr_void) __weak_alias(xdr_wrapstring,_xdr_wrapstring) #endif +#endif /* _KERNEL || _STANDALONE */ + /* * constants specific to the xdr "protocol" */ @@ -633,7 +643,7 @@ xdr_bytes(XDR *xdrs, char **cpp, u_int * 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 @@ xdr_string(XDR *xdrs, char **cpp, u_int 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 @@ xdr_string(XDR *xdrs, char **cpp, u_int 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 @@ xdr_wrapstring(XDR *xdrs, char **cpp) 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' Index: src/common/lib/libc/rpc/xdr_array.c diff -u src/common/lib/libc/rpc/xdr_array.c:1.1 src/common/lib/libc/rpc/xdr_array.c:1.2 --- src/common/lib/libc/rpc/xdr_array.c:1.1 Tue Jun 4 15:07:55 2019 +++ src/common/lib/libc/rpc/xdr_array.c Wed Jun 5 16:25:43 2019 @@ -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 @@ __RCSID("$NetBSD: xdr_array.c,v 1.1 2019 * 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_array,_xdr_array) __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. Index: src/common/lib/libc/rpc/xdr_mem.c diff -u src/common/lib/libc/rpc/xdr_mem.c:1.1 src/common/lib/libc/rpc/xdr_mem.c:1.2 --- src/common/lib/libc/rpc/xdr_mem.c:1.1 Tue Jun 4 15:07:55 2019 +++ src/common/lib/libc/rpc/xdr_mem.c Wed Jun 5 16:25:43 2019 @@ -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 @@ __RCSID("$NetBSD: xdr_mem.c,v 1.1 2019/0 * */ +#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 @@ __RCSID("$NetBSD: xdr_mem.c,v 1.1 2019/0 __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 *);