2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * xdr_rx.c. XDR using RX.
15 #include "afs/param.h"
17 #include <afs/param.h>
19 #include <afsconfig.h>
28 #include <net/net_globals.h>
29 #endif /* AFS_OSF_ENV */
30 #ifdef AFS_LINUX20_ENV
33 #include "rpc/types.h"
41 #endif /* AFS_ALPHA_ENV */
42 #ifdef AFS_LINUX22_ENV
44 #define quad_t __quad_t
45 #define u_quad_t __u_quad_t
49 #include "netinet/in.h"
51 #include "afs/sysincludes.h"
52 #include "rpc/types.h"
57 #include "afs/longc_procs.h"
60 #include <sys/types.h>
63 #include <netinet/in.h>
70 * This section should really go in the param.*.h files.
74 * kernel version needs to agree with <rpc/xdr.h>
76 # if defined(AFS_SUN57_ENV)
77 # define AFS_RPC_INLINE_T rpc_inline_t
78 # elif defined(AFS_DUX40_ENV)
79 # define AFS_RPC_INLINE_T int
81 # define AFS_RPC_INLINE_T long
85 * user version needs to agree with "xdr.h", i.e. <rx/xdr.h>
87 # define AFS_RPC_INLINE_T afs_int32
90 /* Static prototypes */
91 #if (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV)
92 static bool_t xdrrx_getint64(XDR *xdrs, long *lp);
93 static bool_t xdrrx_putint64(XDR *xdrs, long *lp);
94 #endif /* (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV) */
96 static bool_t xdrrx_getint32(XDR *xdrs, afs_int32 *lp);
97 static bool_t xdrrx_putint32(register XDR *xdrs, register afs_int32 *lp);
98 static bool_t xdrrx_getbytes(register XDR *xdrs,
99 register caddr_t addr, register u_int len);
100 static bool_t xdrrx_putbytes(register XDR *xdrs,
101 register caddr_t addr, register u_int len);
102 static AFS_RPC_INLINE_T *xdrrx_inline(register XDR *xdrs, register u_int len);
106 * Ops vector for stdio type XDR
108 static struct xdr_ops xdrrx_ops = {
109 #if defined(KERNEL) && ((defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV))
112 #endif /* defined(KERNEL) && ((defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV)) */
113 #if !(defined(KERNEL) && defined(AFS_SUN57_ENV))
114 xdrrx_getint32, /* deserialize an afs_int32 */
115 xdrrx_putint32, /* serialize an afs_int32 */
117 xdrrx_getbytes, /* deserialize counted bytes */
118 xdrrx_putbytes, /* serialize counted bytes */
119 0, /* get offset in the stream: not supported. */
120 0, /* set offset in the stream: not supported. */
121 xdrrx_inline, /* prime stream for inline macros */
122 0, /* destroy stream */
123 #if defined(KERNEL) && defined(AFS_SUN57_ENV)
125 xdrrx_getint32, /* deserialize an afs_int32 */
126 xdrrx_putint32, /* serialize an afs_int32 */
131 * Initialize an rx xdr handle, for a given rx call. op must be XDR_ENCODE or XDR_DECODE.
132 * Call must have been returned by rx_MakeCall or rx_GetCall. Stream should be a pointer to a local rx_stream structure.
134 void xdrrx_create(register XDR *xdrs, register struct rx_call *call, register enum xdr_op op)
137 xdrs->x_ops = &xdrrx_ops;
138 xdrs->x_private = (caddr_t) call;
141 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
142 #define STACK_TO_PIN 2*PAGESIZE /* 8K */
143 int rx_pin_failed = 0;
146 #if (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV)
147 static bool_t xdrrx_getint64(XDR *xdrs, long *lp)
149 register struct rx_call *call = ((struct rx_call *) (xdrs)->x_private);
152 if (rx_Read32(call, &i) == sizeof(i)) {
159 static bool_t xdrrx_putint64(XDR *xdrs, long *lp)
161 afs_int32 code, i = htonl(*lp);
162 register struct rx_call *call = ((struct rx_call *) (xdrs)->x_private);
164 code = (rx_Write32(call, &i) == sizeof(i));
167 #endif /* (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV) */
169 static bool_t xdrrx_getint32(XDR *xdrs, afs_int32 *lp)
172 register struct rx_call *call = ((struct rx_call *) (xdrs)->x_private);
173 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
174 char *saddr = (char *)&l;
175 saddr -= STACK_TO_PIN;
177 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
178 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
179 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
180 * 2K stack we could try to bring the next few stack pages in here before we call the rx
181 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
182 * out between here and calling splnet. So we now pin (and unpin) them instead to
183 * guarantee that they remain there.
185 if (pin(saddr, STACK_TO_PIN)) {
186 /* XXX There's little we can do by continue XXX */
191 if (rx_Read32(call, &l) == sizeof(l)) {
193 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
194 if (saddr) unpin(saddr, STACK_TO_PIN);
198 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
199 if (saddr) unpin(saddr, STACK_TO_PIN);
204 static bool_t xdrrx_putint32(register XDR *xdrs, register afs_int32 *lp)
206 afs_int32 code, l = htonl(*lp);
207 register struct rx_call *call = ((struct rx_call *) (xdrs)->x_private);
208 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
209 char *saddr = (char *)&code;
210 saddr -= STACK_TO_PIN;
212 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
213 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
214 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
215 * 2K stack we could try to bring the next few stack pages in here before we call the rx
216 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
217 * out between here and calling splnet. So we now pin (and unpin) them instead to
218 * guarantee that they remain there.
220 if (pin(saddr, STACK_TO_PIN)) {
225 code = (rx_Write32(call, &l) == sizeof(l));
226 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
227 if (saddr) unpin(saddr, STACK_TO_PIN);
232 static bool_t xdrrx_getbytes(register XDR *xdrs,
233 register caddr_t addr, register u_int len)
236 register struct rx_call *call = ((struct rx_call *) (xdrs)->x_private);
237 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
238 char *saddr = (char *)&code;
239 saddr -= STACK_TO_PIN;
241 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
242 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
243 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
244 * 2K stack we could try to bring the next few stack pages in here before we call the rx
245 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
246 * out between here and calling splnet. So we now pin (and unpin) them instead to
247 * guarantee that they remain there.
249 if (pin(saddr, STACK_TO_PIN)) {
250 /* XXX There's little we can do by continue XXX */
255 code = (rx_Read(call, addr, len) == len);
256 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
257 if (saddr) unpin(saddr, STACK_TO_PIN);
262 static bool_t xdrrx_putbytes(register XDR *xdrs,
263 register caddr_t addr, register u_int len)
266 register struct rx_call *call = ((struct rx_call *) (xdrs)->x_private);
267 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
268 char *saddr = (char *)&code;
269 saddr -= STACK_TO_PIN;
271 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
272 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
273 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
274 * 2K stack we could try to bring the next few stack pages in here before we call the rx
275 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
276 * out between here and calling splnet. So we now pin (and unpin) them instead to
277 * guarantee that they remain there.
279 if (pin(saddr, STACK_TO_PIN)) {
280 /* XXX There's little we can do by continue XXX */
285 code = (rx_Write(call, addr, len) == len);
286 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
287 if (saddr) unpin(saddr, STACK_TO_PIN);
292 #ifdef undef /* not used */
293 static u_int xdrrx_getpos(register XDR *xdrs)
295 /* Not supported. What error code should we return? (It doesn't matter: it will never be called, anyway!) */
299 static bool_t xdrrx_setpos(register XDR *xdrs, u_int pos)
306 static AFS_RPC_INLINE_T *xdrrx_inline(register XDR *xdrs, register u_int len)
308 /* I don't know what this routine is supposed to do, but the stdio module returns null, so we will, too */