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