1 /* $NetBSD: pmap_prot2.c,v 1.17 2013/03/11 20:19:29 tron Exp $ */
4 * Copyright (c) 2010, Oracle America, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
16 * * Neither the name of the "Oracle America, 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
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/cdefs.h>
35 #if defined(LIBC_SCCS) && !defined(lint)
37 static char *sccsid
= "@(#)pmap_prot2.c 1.3 87/08/11 Copyr 1984 Sun Micro";
38 static char *sccsid
= "@(#)pmap_prot2.c 2.1 88/07/29 4.0 RPCSRC";
40 __RCSID("$NetBSD: pmap_prot2.c,v 1.17 2013/03/11 20:19:29 tron Exp $");
46 * Protocol for the local binder service, or pmap.
48 * Copyright (C) 1984, Sun Microsystems, Inc.
51 #include "namespace.h"
55 #include <rpc/types.h>
57 #include <rpc/pmap_prot.h>
60 __weak_alias(xdr_pmaplist
,_xdr_pmaplist
)
64 * What is going on with linked lists? (!)
65 * First recall the link list declaration from pmap_prot.h:
68 * struct pmap pml_map;
69 * struct pmaplist *pml_map;
72 * Compare that declaration with a corresponding xdr declaration that
73 * is (a) pointer-less, and (b) recursive:
75 * typedef union switch (bool_t) {
82 * case FALSE: struct {};
85 * Notice that the xdr declaration has no nxt pointer while
86 * the C declaration has no bool_t variable. The bool_t can be
87 * interpreted as ``more data follows me''; if FALSE then nothing
88 * follows this bool_t; if TRUE then the bool_t is followed by
89 * an actual struct pmap, and then (recursively) by the
90 * xdr union, pamplist_t.
92 * This could be implemented via the xdr_union primitive, though this
93 * would cause a one recursive call per element in the list. Rather than do
94 * that we can ``unwind'' the recursion
95 * into a while loop and do the union arms in-place.
97 * The head of the list is what the C programmer wishes to past around
98 * the net, yet is the data that the pointer points to which is interesting;
99 * this sounds like a job for xdr_reference!
102 xdr_pmaplist(XDR
*xdrs
, struct pmaplist
**rp
)
105 * more_elements is pre-computed in case the direction is
106 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
107 * xdr_bool when the direction is XDR_DECODE.
109 bool_t more_elements
;
111 struct pmaplist
**next
= NULL
; /* pacify gcc */
113 _DIAGASSERT(xdrs
!= NULL
);
114 _DIAGASSERT(rp
!= NULL
);
116 freeing
= (xdrs
->x_op
== XDR_FREE
);
119 more_elements
= (bool_t
)(*rp
!= NULL
);
120 if (! xdr_bool(xdrs
, &more_elements
))
123 return (TRUE
); /* we are done */
125 * the unfortunate side effect of non-recursion is that in
126 * the case of freeing we must remember the next object
127 * before we free the current object ...
130 next
= &((*rp
)->pml_next
);
131 if (! xdr_reference(xdrs
, (caddr_t
*)rp
,
132 (u_int
)sizeof(struct pmaplist
), (xdrproc_t
)xdr_pmap
))
134 rp
= (freeing
) ? next
: &((*rp
)->pml_next
);
140 * xdr_pmaplist_ptr() is specified to take a PMAPLIST *, but is identical in
141 * functionality to xdr_pmaplist().
144 xdr_pmaplist_ptr(XDR
*xdrs
, struct pmaplist
*rp
)
147 _DIAGASSERT(xdrs
!= NULL
);
148 _DIAGASSERT(rp
!= NULL
);
150 return xdr_pmaplist(xdrs
, (struct pmaplist
**)(void *)rp
);