1 /* $NetBSD: pmap_prot2.c,v 1.14 2000/07/06 03:10:34 christos Exp $ */
4 * SPDX-License-Identifier: BSD-3-Clause
6 * Copyright (c) 2009, Sun Microsystems, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 * - Neither the name of Sun Microsystems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
33 #if defined(LIBC_SCCS) && !defined(lint)
34 static char *sccsid2 = "@(#)pmap_prot2.c 1.3 87/08/11 Copyr 1984 Sun Micro";
35 static char *sccsid = "@(#)pmap_prot2.c 2.1 88/07/29 4.0 RPCSRC";
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
42 * Protocol for the local binder service, or pmap.
44 * Copyright (C) 1984, Sun Microsystems, Inc.
47 #include "namespace.h"
50 #include <rpc/types.h>
52 #include <rpc/pmap_prot.h>
53 #include "un-namespace.h"
57 * What is going on with linked lists? (!)
58 * First recall the link list declaration from pmap_prot.h:
61 * struct pmap pml_map;
62 * struct pmaplist *pml_map;
65 * Compare that declaration with a corresponding xdr declaration that
66 * is (a) pointer-less, and (b) recursive:
68 * typedef union switch (bool_t) {
75 * case FALSE: struct {};
78 * Notice that the xdr declaration has no nxt pointer while
79 * the C declaration has no bool_t variable. The bool_t can be
80 * interpreted as ``more data follows me''; if FALSE then nothing
81 * follows this bool_t; if TRUE then the bool_t is followed by
82 * an actual struct pmap, and then (recursively) by the
83 * xdr union, pamplist_t.
85 * This could be implemented via the xdr_union primitive, though this
86 * would cause a one recursive call per element in the list. Rather than do
87 * that we can ``unwind'' the recursion
88 * into a while loop and do the union arms in-place.
90 * The head of the list is what the C programmer wishes to past around
91 * the net, yet is the data that the pointer points to which is interesting;
92 * this sounds like a job for xdr_reference!
95 xdr_pmaplist(XDR *xdrs, struct pmaplist **rp)
98 * more_elements is pre-computed in case the direction is
99 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
100 * xdr_bool when the direction is XDR_DECODE.
102 bool_t more_elements;
104 struct pmaplist **next = NULL; /* pacify gcc */
106 assert(xdrs != NULL);
109 freeing = (xdrs->x_op == XDR_FREE);
112 more_elements = (bool_t)(*rp != NULL);
113 if (! xdr_bool(xdrs, &more_elements))
116 return (TRUE); /* we are done */
118 * the unfortunate side effect of non-recursion is that in
119 * the case of freeing we must remember the next object
120 * before we free the current object ...
123 next = &((*rp)->pml_next);
124 if (! xdr_reference(xdrs, (caddr_t *)rp,
125 (u_int)sizeof(struct pmaplist), (xdrproc_t)xdr_pmap))
127 rp = (freeing) ? next : &((*rp)->pml_next);
133 * xdr_pmaplist_ptr() is specified to take a PMAPLIST *, but is identical in
134 * functionality to xdr_pmaplist().
137 xdr_pmaplist_ptr(XDR *xdrs, struct pmaplist *rp)
139 return xdr_pmaplist(xdrs, (struct pmaplist **)(void *)rp);