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>
23 # include "afs/sysincludes.h"
28 # include <net/net_globals.h>
29 # endif /* AFS_OSF_ENV */
30 # ifdef AFS_LINUX20_ENV
31 # include "h/socket.h"
33 # include "rpc/types.h"
41 # endif /* AFS_OSF_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"
50 # endif /* !UKERNEL */
55 # include <sys/types.h>
58 # include <netinet/in.h>
64 /* Static prototypes */
65 #ifdef AFS_XDR_64BITOPS
66 static bool_t xdrrx_getint64(XDR *axdrs, long *lp);
67 static bool_t xdrrx_putint64(XDR *axdrs, long *lp);
68 #endif /* AFS_XDR_64BITOPS */
70 static bool_t xdrrx_getint32(XDR *axdrs, afs_int32 * lp);
71 static bool_t xdrrx_putint32(XDR *axdrs, afs_int32 * lp);
72 static bool_t xdrrx_getbytes(XDR *axdrs, caddr_t addr,
74 static bool_t xdrrx_putbytes(XDR *axdrs, caddr_t addr,
76 static afs_int32 *xdrrx_inline(XDR *axdrs, u_int len);
80 * Ops vector for stdio type XDR
82 static struct xdr_ops xdrrx_ops = {
83 #if defined(AFS_NT40_ENV) || defined(__SUNPRO_C) || (defined(AFS_SGI_ENV) && !defined(__c99))
84 #ifdef AFS_XDR_64BITOPS
85 xdrrx_getint64, /* deserialize an afs_int64 */
86 xdrrx_putint64, /* serialize an afs_int64 */
88 /* Windows does not support labeled assigments */
89 #if !(defined(KERNEL) && defined(AFS_SUN57_ENV))
90 xdrrx_getint32, /* deserialize an afs_int32 */
91 xdrrx_putint32, /* serialize an afs_int32 */
93 xdrrx_getbytes, /* deserialize counted bytes */
94 xdrrx_putbytes, /* serialize counted bytes */
95 NULL, /* get offset in the stream: not supported. */
96 NULL, /* set offset in the stream: not supported. */
97 xdrrx_inline, /* prime stream for inline macros */
98 NULL, /* destroy stream */
99 #if (defined(KERNEL) && defined(AFS_SUN57_ENV))
100 NULL, /* control - not implemented */
101 xdrrx_getint32, /* not supported */
102 xdrrx_putint32, /* serialize an afs_int32 */
105 #ifdef AFS_XDR_64BITOPS
106 .x_getint64 = xdrrx_getint64,
107 .x_putint64 = xdrrx_putint64,
108 #endif /* AFS_XDR_64BITOPS */
109 .x_getint32 = xdrrx_getint32, /* deserialize an afs_int32 */
110 .x_putint32 = xdrrx_putint32, /* serialize an afs_int32 */
111 .x_getbytes = xdrrx_getbytes, /* deserialize counted bytes */
112 .x_putbytes = xdrrx_putbytes, /* serialize counted bytes */
113 .x_getpostn = NULL, /* get offset in the stream: not supported. */
114 .x_setpostn = NULL, /* set offset in the stream: not supported. */
115 .x_inline = xdrrx_inline, /* prime stream for inline macros */
116 .x_destroy = NULL, /* destroy stream */
117 #if defined(KERNEL) && defined(AFS_SUN57_ENV)
124 * Initialize an rx xdr handle, for a given rx call. op must be XDR_ENCODE or XDR_DECODE.
125 * Call must have been returned by rx_MakeCall or rx_GetCall.
128 xdrrx_create(XDR * xdrs, struct rx_call *call,
132 xdrs->x_ops = &xdrrx_ops;
133 xdrs->x_private = (caddr_t) call;
136 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
137 #define STACK_TO_PIN 2*PAGESIZE /* 8K */
138 int rx_pin_failed = 0;
141 #ifdef AFS_XDR_64BITOPS
143 xdrrx_getint64(XDR *axdrs, long *lp)
145 XDR * xdrs = (XDR *)axdrs;
146 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
149 if (rx_Read32(call, &i) == sizeof(i)) {
157 xdrrx_putint64(XDR *axdrs, long *lp)
159 XDR * xdrs = (XDR *)axdrs;
160 afs_int32 code, i = htonl(*lp);
161 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
163 code = (rx_Write32(call, &i) == sizeof(i));
166 #endif /* AFS_XDR_64BITOPS */
169 xdrrx_getint32(XDR *axdrs, afs_int32 * lp)
172 XDR * xdrs = (XDR *)axdrs;
173 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
174 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
175 char *saddr = (char *)&l;
176 saddr -= STACK_TO_PIN;
178 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
179 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
180 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
181 * 2K stack we could try to bring the next few stack pages in here before we call the rx
182 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
183 * out between here and calling splnet. So we now pin (and unpin) them instead to
184 * guarantee that they remain there.
186 if (pin(saddr, STACK_TO_PIN)) {
187 /* XXX There's little we can do by continue XXX */
192 if (rx_Read32(call, &l) == sizeof(l)) {
194 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
196 unpin(saddr, STACK_TO_PIN);
200 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
202 unpin(saddr, STACK_TO_PIN);
208 xdrrx_putint32(XDR *axdrs, afs_int32 * lp)
210 afs_int32 code, l = htonl(*lp);
211 XDR * xdrs = (XDR *)axdrs;
212 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
213 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
214 char *saddr = (char *)&code;
215 saddr -= STACK_TO_PIN;
217 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
218 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
219 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
220 * 2K stack we could try to bring the next few stack pages in here before we call the rx
221 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
222 * out between here and calling splnet. So we now pin (and unpin) them instead to
223 * guarantee that they remain there.
225 if (pin(saddr, STACK_TO_PIN)) {
230 code = (rx_Write32(call, &l) == sizeof(l));
231 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
233 unpin(saddr, STACK_TO_PIN);
239 xdrrx_getbytes(XDR *axdrs, caddr_t addr, u_int len)
242 XDR * xdrs = (XDR *)axdrs;
243 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
244 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
245 char *saddr = (char *)&code;
246 saddr -= STACK_TO_PIN;
248 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
249 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
250 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
251 * 2K stack we could try to bring the next few stack pages in here before we call the rx
252 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
253 * out between here and calling splnet. So we now pin (and unpin) them instead to
254 * guarantee that they remain there.
256 if (pin(saddr, STACK_TO_PIN)) {
257 /* XXX There's little we can do by continue XXX */
262 code = (rx_Read(call, addr, len) == len);
263 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
265 unpin(saddr, STACK_TO_PIN);
271 xdrrx_putbytes(XDR *axdrs, caddr_t addr, u_int len)
274 XDR * xdrs = (XDR *)axdrs;
275 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
276 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
277 char *saddr = (char *)&code;
278 saddr -= STACK_TO_PIN;
280 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
281 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
282 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
283 * 2K stack we could try to bring the next few stack pages in here before we call the rx
284 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
285 * out between here and calling splnet. So we now pin (and unpin) them instead to
286 * guarantee that they remain there.
288 if (pin(saddr, STACK_TO_PIN)) {
289 /* XXX There's little we can do by continue XXX */
294 code = (rx_Write(call, addr, len) == len);
295 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
297 unpin(saddr, STACK_TO_PIN);
302 #ifdef undef /* not used */
304 xdrrx_getpos(XDR * xdrs)
306 /* Not supported. What error code should we return? (It doesn't matter: it will never be called, anyway!) */
311 xdrrx_setpos(XDR * xdrs, u_int pos)
319 xdrrx_inline(XDR *axdrs, u_int len)
321 /* I don't know what this routine is supposed to do, but the stdio module returns null, so we will, too */