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"
40 # endif /* AFS_OSF_ENV */
41 # ifdef AFS_LINUX22_ENV
43 # define quad_t __quad_t
44 # define u_quad_t __u_quad_t
48 # include "netinet/in.h"
49 # endif /* !UKERNEL */
54 # include <sys/types.h>
57 # include <netinet/in.h>
63 /* Static prototypes */
64 #ifdef AFS_XDR_64BITOPS
65 static bool_t xdrrx_getint64(XDR *axdrs, long *lp);
66 static bool_t xdrrx_putint64(XDR *axdrs, long *lp);
67 #endif /* AFS_XDR_64BITOPS */
69 static bool_t xdrrx_getint32(XDR *axdrs, afs_int32 * lp);
70 static bool_t xdrrx_putint32(XDR *axdrs, afs_int32 * lp);
71 static bool_t xdrrx_getbytes(XDR *axdrs, caddr_t addr,
73 static bool_t xdrrx_putbytes(XDR *axdrs, caddr_t addr,
75 static afs_int32 *xdrrx_inline(XDR *axdrs, u_int len);
79 * Ops vector for stdio type XDR
81 static struct xdr_ops xdrrx_ops = {
82 #ifndef HAVE_STRUCT_LABEL_SUPPORT
83 #ifdef AFS_XDR_64BITOPS
84 xdrrx_getint64, /* deserialize an afs_int64 */
85 xdrrx_putint64, /* serialize an afs_int64 */
87 /* Windows does not support labeled assigments */
88 #if !(defined(KERNEL) && defined(AFS_SUN57_ENV))
89 xdrrx_getint32, /* deserialize an afs_int32 */
90 xdrrx_putint32, /* serialize an afs_int32 */
92 xdrrx_getbytes, /* deserialize counted bytes */
93 xdrrx_putbytes, /* serialize counted bytes */
94 NULL, /* get offset in the stream: not supported. */
95 NULL, /* set offset in the stream: not supported. */
96 xdrrx_inline, /* prime stream for inline macros */
97 NULL, /* destroy stream */
98 #if (defined(KERNEL) && defined(AFS_SUN57_ENV))
99 NULL, /* control - not implemented */
100 xdrrx_getint32, /* not supported */
101 xdrrx_putint32, /* serialize an afs_int32 */
104 #ifdef AFS_XDR_64BITOPS
105 .x_getint64 = xdrrx_getint64,
106 .x_putint64 = xdrrx_putint64,
107 #endif /* AFS_XDR_64BITOPS */
108 .x_getint32 = xdrrx_getint32, /* deserialize an afs_int32 */
109 .x_putint32 = xdrrx_putint32, /* serialize an afs_int32 */
110 .x_getbytes = xdrrx_getbytes, /* deserialize counted bytes */
111 .x_putbytes = xdrrx_putbytes, /* serialize counted bytes */
112 .x_getpostn = NULL, /* get offset in the stream: not supported. */
113 .x_setpostn = NULL, /* set offset in the stream: not supported. */
114 .x_inline = xdrrx_inline, /* prime stream for inline macros */
115 .x_destroy = NULL, /* destroy stream */
116 #if defined(KERNEL) && defined(AFS_SUN57_ENV)
123 * Initialize an rx xdr handle, for a given rx call. op must be XDR_ENCODE or XDR_DECODE.
124 * Call must have been returned by rx_MakeCall or rx_GetCall.
127 xdrrx_create(XDR * xdrs, struct rx_call *call,
131 xdrs->x_ops = &xdrrx_ops;
132 xdrs->x_private = (caddr_t) call;
135 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
136 #define STACK_TO_PIN 2*PAGESIZE /* 8K */
137 int rx_pin_failed = 0;
140 #ifdef AFS_XDR_64BITOPS
142 xdrrx_getint64(XDR *axdrs, long *lp)
144 XDR * xdrs = (XDR *)axdrs;
145 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
148 if (rx_Read32(call, &i) == sizeof(i)) {
156 xdrrx_putint64(XDR *axdrs, long *lp)
158 XDR * xdrs = (XDR *)axdrs;
159 afs_int32 code, i = htonl(*lp);
160 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
162 code = (rx_Write32(call, &i) == sizeof(i));
165 #endif /* AFS_XDR_64BITOPS */
168 xdrrx_getint32(XDR *axdrs, afs_int32 * lp)
171 XDR * xdrs = (XDR *)axdrs;
172 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)
195 unpin(saddr, STACK_TO_PIN);
199 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
201 unpin(saddr, STACK_TO_PIN);
207 xdrrx_putint32(XDR *axdrs, afs_int32 * lp)
209 afs_int32 code, l = htonl(*lp);
210 XDR * xdrs = (XDR *)axdrs;
211 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
212 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
213 char *saddr = (char *)&code;
214 saddr -= STACK_TO_PIN;
216 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
217 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
218 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
219 * 2K stack we could try to bring the next few stack pages in here before we call the rx
220 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
221 * out between here and calling splnet. So we now pin (and unpin) them instead to
222 * guarantee that they remain there.
224 if (pin(saddr, STACK_TO_PIN)) {
229 code = (rx_Write32(call, &l) == sizeof(l));
230 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
232 unpin(saddr, STACK_TO_PIN);
238 xdrrx_getbytes(XDR *axdrs, caddr_t addr, u_int len)
241 XDR * xdrs = (XDR *)axdrs;
242 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
243 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
244 char *saddr = (char *)&code;
245 saddr -= STACK_TO_PIN;
247 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
248 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
249 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
250 * 2K stack we could try to bring the next few stack pages in here before we call the rx
251 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
252 * out between here and calling splnet. So we now pin (and unpin) them instead to
253 * guarantee that they remain there.
255 if (pin(saddr, STACK_TO_PIN)) {
256 /* XXX There's little we can do by continue XXX */
261 code = (rx_Read(call, addr, len) == len);
262 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
264 unpin(saddr, STACK_TO_PIN);
270 xdrrx_putbytes(XDR *axdrs, caddr_t addr, u_int len)
273 XDR * xdrs = (XDR *)axdrs;
274 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
275 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
276 char *saddr = (char *)&code;
277 saddr -= STACK_TO_PIN;
279 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
280 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
281 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
282 * 2K stack we could try to bring the next few stack pages in here before we call the rx
283 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
284 * out between here and calling splnet. So we now pin (and unpin) them instead to
285 * guarantee that they remain there.
287 if (pin(saddr, STACK_TO_PIN)) {
288 /* XXX There's little we can do by continue XXX */
293 code = (rx_Write(call, addr, len) == len);
294 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
296 unpin(saddr, STACK_TO_PIN);
301 #ifdef undef /* not used */
303 xdrrx_getpos(XDR * xdrs)
305 /* Not supported. What error code should we return? (It doesn't matter: it will never be called, anyway!) */
310 xdrrx_setpos(XDR * xdrs, u_int pos)
318 xdrrx_inline(XDR *axdrs, u_int len)
320 /* I don't know what this routine is supposed to do, but the stdio module returns null, so we will, too */