afsconfig-and-rcsid-all-around-20010705
[openafs.git] / src / rx / xdr_rx.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 /*
11  * xdr_rx.c.  XDR using RX. 
12  */
13
14 #ifdef  KERNEL
15 #include "../afs/param.h"
16 #else
17 #include <afs/param.h>
18 #endif
19 #include <afsconfig.h>
20
21 RCSID("$Header$");
22
23 #ifdef KERNEL
24 #ifndef UKERNEL
25 #include "../h/types.h"
26 #include "../h/uio.h"
27 #ifdef  AFS_OSF_ENV
28 #include <net/net_globals.h>
29 #endif  /* AFS_OSF_ENV */
30 #ifdef AFS_LINUX20_ENV
31 #include "../h/socket.h"
32 #else
33 #include "../rpc/types.h"
34 #endif
35 #ifdef  AFS_ALPHA_ENV
36 #undef kmem_alloc
37 #undef kmem_free
38 #undef mem_alloc
39 #undef mem_free
40 #undef register
41 #endif  /* AFS_ALPHA_ENV */
42 #ifdef AFS_LINUX22_ENV
43 #ifndef quad_t
44 #define quad_t __quad_t
45 #define u_quad_t __u_quad_t
46 #endif
47 #endif
48 #include "../rpc/xdr.h"
49 #include "../netinet/in.h"
50 #else /* !UKERNEL */
51 #include "../afs/sysincludes.h"
52 #include "../rpc/types.h"
53 #include "../rpc/xdr.h"
54 #endif /* !UKERNEL */
55 #include "../rx/rx.h"
56
57 #include "../afs/longc_procs.h"
58
59 #else /* KERNEL */
60 #include <sys/types.h>
61 #include <stdio.h>
62 #ifndef AFS_NT40_ENV
63 #include <netinet/in.h>
64 #endif
65 #include "xdr.h"
66 #include "rx.h"
67 #endif /* KERNEL */
68
69 /*
70  * This section should really go in the param.*.h files.
71  */
72 #if defined(KERNEL)
73 /*
74  * kernel version needs to agree with <rpc/xdr.h>
75  */
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
80 # else
81 #  define AFS_RPC_INLINE_T long
82 # endif
83 #else   /* KERNEL */
84 /*
85  * user version needs to agree with "xdr.h", i.e. <rx/xdr.h>
86  */
87 #  define AFS_RPC_INLINE_T afs_int32
88 #endif  /* KERNEL */
89
90 #if (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV)
91 static bool_t   xdrrx_getint64();
92 static bool_t   xdrrx_putint64();
93 #endif /* defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT) || defined(AFS_HPUX_64BIT_ENV) */
94 static bool_t   xdrrx_getint32();
95 static bool_t   xdrrx_putint32();
96 static bool_t   xdrrx_getbytes();
97 static bool_t   xdrrx_putbytes();
98 static AFS_RPC_INLINE_T *       xdrrx_inline();
99 void            xdrrx_destroy();
100
101 /*
102  * Ops vector for stdio type XDR
103  */
104 static struct xdr_ops   xdrrx_ops = {
105 #if (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV)
106         xdrrx_getint64,
107         xdrrx_putint64,
108 #endif /* (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV) */
109 #if !(defined(KERNEL) && defined(AFS_SUN57_ENV)) && !defined(AFS_HPUX_64BIT_ENV)
110         xdrrx_getint32, /* deserialize an afs_int32 */
111         xdrrx_putint32, /* serialize an afs_int32 */
112 #endif
113         xdrrx_getbytes, /* deserialize counted bytes */
114         xdrrx_putbytes, /* serialize counted bytes */
115         0,              /* get offset in the stream: not supported. */
116         0,              /* set offset in the stream: not supported. */
117         xdrrx_inline,   /* prime stream for inline macros */
118         0,              /* destroy stream */
119 #if defined(KERNEL) && defined(AFS_SUN57_ENV)
120         0,
121         xdrrx_getint32, /* deserialize an afs_int32 */
122         xdrrx_putint32, /* serialize an afs_int32 */
123 #endif
124 };
125
126 /*
127  * Initialize an rx xdr handle, for a given rx call.  op must be XDR_ENCODE or XDR_DECODE.
128  * Call must have been returned by rx_MakeCall or rx_GetCall.  Stream should be a pointer to a local rx_stream structure.
129  */
130 void
131 xdrrx_create(xdrs, call, op)
132         register XDR *xdrs;
133         register struct rx_call *call;
134         register enum xdr_op op;
135 {
136         xdrs->x_op = op;
137         xdrs->x_ops = &xdrrx_ops;
138         xdrs->x_private = (caddr_t) call;
139 }
140
141 #if     defined(KERNEL) && defined(AFS_AIX32_ENV)
142 #define STACK_TO_PIN    2*PAGESIZE              /* 8K */
143 int  rx_pin_failed = 0;
144 #endif
145
146 #if (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV)
147 static bool_t
148 xdrrx_getint64(XDR *xdrs, long *lp)
149 {
150         register struct rx_call *call = ((struct rx_call *) (xdrs)->x_private);
151         afs_int32 i;
152         
153         if (rx_Read32(call, &i) == sizeof(i)) {
154                 *lp = ntohl(i);
155                 return TRUE;
156         }
157         return FALSE;
158 }
159
160 static bool_t
161 xdrrx_putint64(XDR *xdrs, long *lp)
162 {
163         afs_int32 code, i = htonl(*lp);
164         register struct rx_call *call = ((struct rx_call *) (xdrs)->x_private);
165
166         code =  (rx_Write32(call, &i) == sizeof(i));
167         return code;
168 }
169 #endif /* (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV) */
170
171 static bool_t
172 xdrrx_getint32(xdrs, lp)
173         register XDR *xdrs;
174         register afs_int32 *lp;
175 {
176         afs_int32 l;
177         register struct rx_call *call = ((struct rx_call *) (xdrs)->x_private);
178 #if     defined(KERNEL) && defined(AFS_AIX32_ENV)
179         char *saddr = (char *)&l;
180         saddr -= STACK_TO_PIN;
181         /*
182          * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under 
183          * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
184          * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
185          * 2K stack we could try to bring the next few stack pages in here before we call the rx
186          * layer. Of course this doesn't guarantee that those stack pages won't be swapped
187          * out between here and calling splnet. So we now pin (and unpin) them instead to
188          * guarantee that they remain there.
189          */
190         if (pin(saddr, STACK_TO_PIN)) { 
191             /* XXX There's little we can do by continue XXX */
192             saddr = (char *)0;
193             rx_pin_failed++;
194         }
195 #endif
196         if (rx_Read32(call, &l) == sizeof(l)) {
197             *lp = ntohl(l);
198 #if     defined(KERNEL) && defined(AFS_AIX32_ENV)
199             if (saddr) unpin(saddr, STACK_TO_PIN);
200 #endif
201             return TRUE;
202         }
203 #if     defined(KERNEL) && defined(AFS_AIX32_ENV)
204         if (saddr) unpin(saddr, STACK_TO_PIN);
205 #endif
206         return FALSE;
207 }
208
209 static bool_t
210 xdrrx_putint32(xdrs, lp)
211         register XDR *xdrs;
212         register afs_int32 *lp;
213 {
214         afs_int32 code, l = htonl(*lp);
215         register struct rx_call *call = ((struct rx_call *) (xdrs)->x_private);
216 #if     defined(KERNEL) && defined(AFS_AIX32_ENV)
217         char *saddr = (char *)&code;
218         saddr -= STACK_TO_PIN;
219         /*
220          * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under 
221          * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
222          * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
223          * 2K stack we could try to bring the next few stack pages in here before we call the rx
224          * layer. Of course this doesn't guarantee that those stack pages won't be swapped
225          * out between here and calling splnet. So we now pin (and unpin) them instead to
226          * guarantee that they remain there.
227          */
228         if (pin(saddr, STACK_TO_PIN)) {
229             saddr = (char *)0;
230             rx_pin_failed++;
231         }
232 #endif
233         code =  (rx_Write32(call, &l) == sizeof(l));
234 #if     defined(KERNEL) && defined(AFS_AIX32_ENV)
235         if (saddr) unpin(saddr, STACK_TO_PIN);
236 #endif
237         return code;
238 }
239
240 static bool_t
241 xdrrx_getbytes(xdrs, addr, len)
242         register XDR *xdrs;
243         register caddr_t addr;
244         register u_int len;
245 {
246         afs_int32 code;
247         register struct rx_call *call = ((struct rx_call *) (xdrs)->x_private);
248 #if     defined(KERNEL) && defined(AFS_AIX32_ENV)
249         char *saddr = (char *)&code;
250         saddr -= STACK_TO_PIN;
251         /*
252          * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under 
253          * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
254          * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
255          * 2K stack we could try to bring the next few stack pages in here before we call the rx
256          * layer. Of course this doesn't guarantee that those stack pages won't be swapped
257          * out between here and calling splnet. So we now pin (and unpin) them instead to
258          * guarantee that they remain there.
259          */
260         if (pin(saddr, STACK_TO_PIN)) { 
261             /* XXX There's little we can do by continue XXX */
262             saddr = (char *)0;
263             rx_pin_failed++;
264         }
265 #endif
266         code = (rx_Read(call, addr, len) == len);
267 #if     defined(KERNEL) && defined(AFS_AIX32_ENV)
268         if (saddr) unpin(saddr, STACK_TO_PIN);
269 #endif
270         return code;
271 }
272
273 static bool_t
274 xdrrx_putbytes(xdrs, addr, len)
275         register XDR *xdrs;
276         register caddr_t addr;
277         register u_int len;
278 {
279         afs_int32 code;
280         register struct rx_call *call = ((struct rx_call *) (xdrs)->x_private);
281 #if     defined(KERNEL) && defined(AFS_AIX32_ENV)
282         char *saddr = (char *)&code;
283         saddr -= STACK_TO_PIN;
284         /*
285          * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under 
286          * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
287          * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
288          * 2K stack we could try to bring the next few stack pages in here before we call the rx
289          * layer. Of course this doesn't guarantee that those stack pages won't be swapped
290          * out between here and calling splnet. So we now pin (and unpin) them instead to
291          * guarantee that they remain there.
292          */
293         if (pin(saddr, STACK_TO_PIN)) { 
294             /* XXX There's little we can do by continue XXX */
295             saddr = (char *)0;
296             rx_pin_failed++;
297         }
298 #endif
299         code =  (rx_Write(call, addr, len) == len);
300 #if     defined(KERNEL) && defined(AFS_AIX32_ENV)
301         if (saddr) unpin(saddr, STACK_TO_PIN);
302 #endif
303         return code;
304 }
305
306 #ifdef undef /* not used */
307 static u_int
308 xdrrx_getpos(xdrs)
309         register XDR *xdrs;
310 {
311         /* Not supported.  What error code should we return? (It doesn't matter:  it will never be called, anyway!) */
312         return -1;
313 }
314
315 static bool_t
316 xdrrx_setpos(xdrs, pos) 
317         register XDR *xdrs;
318         u_int pos;
319
320         /* Not supported */
321         return FALSE;
322 }
323 #endif
324
325 static AFS_RPC_INLINE_T *
326 xdrrx_inline(xdrs, len)
327         register XDR *xdrs;
328         register u_int len;
329 {
330         /* I don't know what this routine is supposed to do, but the stdio module returns null, so we will, too */
331         return (0);
332 }
333