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.
14 #include <afsconfig.h>
16 #include "afs/param.h"
18 #include <afs/param.h>
25 #include "afs/sysincludes.h"
30 #include <net/net_globals.h>
31 #endif /* AFS_OSF_ENV */
32 #ifdef AFS_LINUX20_ENV
35 #include "rpc/types.h"
43 #endif /* AFS_OSF_ENV */
44 #ifdef AFS_LINUX22_ENV
46 #define quad_t __quad_t
47 #define u_quad_t __u_quad_t
51 #include "netinet/in.h"
53 #include "rpc/types.h"
56 #include "rx/rx_internal.h"
60 #include <sys/types.h>
63 #include <netinet/in.h>
65 #include "rx_internal.h"
71 * This section should really go in the param.*.h files.
75 * kernel version needs to agree with <rpc/xdr.h>
76 * except on Linux which does XDR differently from everyone else
78 # if defined(AFS_LINUX20_ENV) && !defined(UKERNEL)
79 # define AFS_XDRS_T void *
81 # define AFS_XDRS_T XDR *
83 # if defined(AFS_SUN57_ENV)
84 # define AFS_RPC_INLINE_T rpc_inline_t
85 # elif defined(AFS_DUX40_ENV)
86 # define AFS_RPC_INLINE_T int
87 # elif defined(AFS_LINUX20_ENV) && !defined(UKERNEL)
88 # define AFS_RPC_INLINE_T afs_int32
89 # elif defined(AFS_LINUX20_ENV)
90 # define AFS_RPC_INLINE_T int32_t *
92 # define AFS_RPC_INLINE_T long
96 * user version needs to agree with "xdr.h", i.e. <rx/xdr.h>
98 # define AFS_XDRS_T void *
99 # define AFS_RPC_INLINE_T afs_int32
102 /* Static prototypes */
103 #if (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV)
104 static bool_t xdrrx_getint64(AFS_XDRS_T axdrs, long *lp);
105 static bool_t xdrrx_putint64(AFS_XDRS_T axdrs, long *lp);
106 #endif /* (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV) */
108 static bool_t xdrrx_getint32(AFS_XDRS_T axdrs, afs_int32 * lp);
109 static bool_t xdrrx_putint32(AFS_XDRS_T axdrs, afs_int32 * lp);
110 static bool_t xdrrx_getbytes(AFS_XDRS_T axdrs, caddr_t addr,
112 static bool_t xdrrx_putbytes(AFS_XDRS_T axdrs, caddr_t addr,
114 static AFS_RPC_INLINE_T *xdrrx_inline(AFS_XDRS_T axdrs, u_int len);
118 * Ops vector for stdio type XDR
120 static struct xdr_ops xdrrx_ops = {
121 #if defined(KERNEL) && ((defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV))
124 #endif /* defined(KERNEL) && ((defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV)) */
125 #if !(defined(KERNEL) && defined(AFS_SUN57_ENV))
126 xdrrx_getint32, /* deserialize an afs_int32 */
127 xdrrx_putint32, /* serialize an afs_int32 */
129 xdrrx_getbytes, /* deserialize counted bytes */
130 xdrrx_putbytes, /* serialize counted bytes */
131 0, /* get offset in the stream: not supported. */
132 0, /* set offset in the stream: not supported. */
133 xdrrx_inline, /* prime stream for inline macros */
134 0, /* destroy stream */
135 #if defined(KERNEL) && defined(AFS_SUN57_ENV)
137 xdrrx_getint32, /* deserialize an afs_int32 */
138 xdrrx_putint32, /* serialize an afs_int32 */
143 * Initialize an rx xdr handle, for a given rx call. op must be XDR_ENCODE or XDR_DECODE.
144 * Call must have been returned by rx_MakeCall or rx_GetCall.
147 xdrrx_create(XDR * xdrs, struct rx_call *call,
151 xdrs->x_ops = &xdrrx_ops;
152 xdrs->x_private = (caddr_t) call;
155 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
156 #define STACK_TO_PIN 2*PAGESIZE /* 8K */
157 int rx_pin_failed = 0;
160 #if (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV)
162 xdrrx_getint64(AFS_XDRS_T axdrs, long *lp)
164 XDR * xdrs = (XDR *)axdrs;
165 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
168 if (rx_Read32(call, &i) == sizeof(i)) {
176 xdrrx_putint64(AFS_XDRS_T axdrs, long *lp)
178 XDR * xdrs = (XDR *)axdrs;
179 afs_int32 code, i = htonl(*lp);
180 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
182 code = (rx_Write32(call, &i) == sizeof(i));
185 #endif /* (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV) */
188 xdrrx_getint32(AFS_XDRS_T axdrs, afs_int32 * lp)
191 XDR * xdrs = (XDR *)axdrs;
192 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
193 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
194 char *saddr = (char *)&l;
195 saddr -= STACK_TO_PIN;
197 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
198 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
199 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
200 * 2K stack we could try to bring the next few stack pages in here before we call the rx
201 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
202 * out between here and calling splnet. So we now pin (and unpin) them instead to
203 * guarantee that they remain there.
205 if (pin(saddr, STACK_TO_PIN)) {
206 /* XXX There's little we can do by continue XXX */
211 if (rx_Read32(call, &l) == sizeof(l)) {
213 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
215 unpin(saddr, STACK_TO_PIN);
219 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
221 unpin(saddr, STACK_TO_PIN);
227 xdrrx_putint32(AFS_XDRS_T axdrs, afs_int32 * lp)
229 afs_int32 code, l = htonl(*lp);
230 XDR * xdrs = (XDR *)axdrs;
231 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
232 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
233 char *saddr = (char *)&code;
234 saddr -= STACK_TO_PIN;
236 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
237 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
238 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
239 * 2K stack we could try to bring the next few stack pages in here before we call the rx
240 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
241 * out between here and calling splnet. So we now pin (and unpin) them instead to
242 * guarantee that they remain there.
244 if (pin(saddr, STACK_TO_PIN)) {
249 code = (rx_Write32(call, &l) == sizeof(l));
250 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
252 unpin(saddr, STACK_TO_PIN);
258 xdrrx_getbytes(AFS_XDRS_T axdrs, caddr_t addr, u_int len)
261 XDR * xdrs = (XDR *)axdrs;
262 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
263 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
264 char *saddr = (char *)&code;
265 saddr -= STACK_TO_PIN;
267 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
268 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
269 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
270 * 2K stack we could try to bring the next few stack pages in here before we call the rx
271 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
272 * out between here and calling splnet. So we now pin (and unpin) them instead to
273 * guarantee that they remain there.
275 if (pin(saddr, STACK_TO_PIN)) {
276 /* XXX There's little we can do by continue XXX */
281 code = (rx_Read(call, addr, len) == len);
282 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
284 unpin(saddr, STACK_TO_PIN);
290 xdrrx_putbytes(AFS_XDRS_T axdrs, caddr_t addr, u_int len)
293 XDR * xdrs = (XDR *)axdrs;
294 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
295 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
296 char *saddr = (char *)&code;
297 saddr -= STACK_TO_PIN;
299 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
300 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
301 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
302 * 2K stack we could try to bring the next few stack pages in here before we call the rx
303 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
304 * out between here and calling splnet. So we now pin (and unpin) them instead to
305 * guarantee that they remain there.
307 if (pin(saddr, STACK_TO_PIN)) {
308 /* XXX There's little we can do by continue XXX */
313 code = (rx_Write(call, addr, len) == len);
314 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
316 unpin(saddr, STACK_TO_PIN);
321 #ifdef undef /* not used */
323 xdrrx_getpos(XDR * xdrs)
325 /* Not supported. What error code should we return? (It doesn't matter: it will never be called, anyway!) */
330 xdrrx_setpos(XDR * xdrs, u_int pos)
337 static AFS_RPC_INLINE_T *
338 xdrrx_inline(AFS_XDRS_T axdrs, u_int len)
340 /* I don't know what this routine is supposed to do, but the stdio module returns null, so we will, too */