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(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 xdrrx_getint32, /* deserialize an afs_int32 */
90 xdrrx_putint32, /* serialize an afs_int32 */
91 xdrrx_getbytes, /* deserialize counted bytes */
92 xdrrx_putbytes, /* serialize counted bytes */
93 NULL, /* get offset in the stream: not supported. */
94 NULL, /* set offset in the stream: not supported. */
95 xdrrx_inline, /* prime stream for inline macros */
96 NULL /* destroy stream */
98 #ifdef AFS_XDR_64BITOPS
99 .x_getint64 = xdrrx_getint64,
100 .x_putint64 = xdrrx_putint64,
101 #endif /* AFS_XDR_64BITOPS */
102 .x_getint32 = xdrrx_getint32, /* deserialize an afs_int32 */
103 .x_putint32 = xdrrx_putint32, /* serialize an afs_int32 */
104 .x_getbytes = xdrrx_getbytes, /* deserialize counted bytes */
105 .x_putbytes = xdrrx_putbytes, /* serialize counted bytes */
106 .x_getpostn = NULL, /* get offset in the stream: not supported. */
107 .x_setpostn = NULL, /* set offset in the stream: not supported. */
108 .x_inline = xdrrx_inline, /* prime stream for inline macros */
109 .x_destroy = NULL, /* destroy stream */
110 #if defined(KERNEL) && defined(AFS_SUN57_ENV)
117 * Initialize an rx xdr handle, for a given rx call. op must be XDR_ENCODE or XDR_DECODE.
118 * Call must have been returned by rx_MakeCall or rx_GetCall.
121 xdrrx_create(XDR * xdrs, struct rx_call *call,
125 xdrs->x_ops = &xdrrx_ops;
126 xdrs->x_private = (caddr_t) call;
129 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
130 #define STACK_TO_PIN 2*PAGESIZE /* 8K */
131 int rx_pin_failed = 0;
134 #ifdef AFS_XDR_64BITOPS
136 xdrrx_getint64(XDR *axdrs, long *lp)
138 XDR * xdrs = (XDR *)axdrs;
139 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
142 if (rx_Read32(call, &i) == sizeof(i)) {
150 xdrrx_putint64(XDR *axdrs, long *lp)
152 XDR * xdrs = (XDR *)axdrs;
153 afs_int32 code, i = htonl(*lp);
154 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
156 code = (rx_Write32(call, &i) == sizeof(i));
159 #endif /* AFS_XDR_64BITOPS */
162 xdrrx_getint32(XDR *axdrs, afs_int32 * lp)
165 XDR * xdrs = (XDR *)axdrs;
166 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
167 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
168 char *saddr = (char *)&l;
169 saddr -= STACK_TO_PIN;
171 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
172 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
173 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
174 * 2K stack we could try to bring the next few stack pages in here before we call the rx
175 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
176 * out between here and calling splnet. So we now pin (and unpin) them instead to
177 * guarantee that they remain there.
179 if (pin(saddr, STACK_TO_PIN)) {
180 /* XXX There's little we can do by continue XXX */
185 if (rx_Read32(call, &l) == sizeof(l)) {
187 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
189 unpin(saddr, STACK_TO_PIN);
193 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
195 unpin(saddr, STACK_TO_PIN);
201 xdrrx_putint32(XDR *axdrs, afs_int32 * lp)
203 afs_int32 code, l = htonl(*lp);
204 XDR * xdrs = (XDR *)axdrs;
205 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
206 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
207 char *saddr = (char *)&code;
208 saddr -= STACK_TO_PIN;
210 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
211 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
212 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
213 * 2K stack we could try to bring the next few stack pages in here before we call the rx
214 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
215 * out between here and calling splnet. So we now pin (and unpin) them instead to
216 * guarantee that they remain there.
218 if (pin(saddr, STACK_TO_PIN)) {
223 code = (rx_Write32(call, &l) == sizeof(l));
224 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
226 unpin(saddr, STACK_TO_PIN);
232 xdrrx_getbytes(XDR *axdrs, caddr_t addr, u_int len)
235 XDR * xdrs = (XDR *)axdrs;
236 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)
258 unpin(saddr, STACK_TO_PIN);
264 xdrrx_putbytes(XDR *axdrs, caddr_t addr, u_int len)
267 XDR * xdrs = (XDR *)axdrs;
268 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
269 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
270 char *saddr = (char *)&code;
271 saddr -= STACK_TO_PIN;
273 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
274 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
275 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
276 * 2K stack we could try to bring the next few stack pages in here before we call the rx
277 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
278 * out between here and calling splnet. So we now pin (and unpin) them instead to
279 * guarantee that they remain there.
281 if (pin(saddr, STACK_TO_PIN)) {
282 /* XXX There's little we can do by continue XXX */
287 code = (rx_Write(call, addr, len) == len);
288 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
290 unpin(saddr, STACK_TO_PIN);
295 #ifdef undef /* not used */
297 xdrrx_getpos(XDR * xdrs)
299 /* Not supported. What error code should we return? (It doesn't matter: it will never be called, anyway!) */
304 xdrrx_setpos(XDR * xdrs, u_int pos)
312 xdrrx_inline(XDR *axdrs, u_int len)
314 /* I don't know what this routine is supposed to do, but the stdio module returns null, so we will, too */