Rx: Permit MakeDebugCall() be be compiled when RXDEBUG is undefined
[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 #include <afsconfig.h>
15 #ifdef  KERNEL
16 #include "afs/param.h"
17 #else
18 #include <afs/param.h>
19 #endif
20
21
22 #ifdef KERNEL
23 # include "afs/sysincludes.h"
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_OSF_ENV
36 #   undef kmem_alloc
37 #   undef kmem_free
38 #   undef mem_alloc
39 #   undef mem_free
40 #  endif /* AFS_OSF_ENV */
41 #  ifdef AFS_LINUX22_ENV
42 #   ifndef quad_t
43 #    define quad_t __quad_t
44 #    define u_quad_t __u_quad_t
45 #   endif
46 #  endif
47 #  include "rx/xdr.h"
48 #  include "netinet/in.h"
49 # endif /* !UKERNEL */
50 # include "rx/xdr.h"
51 # include "rx/rx.h"
52
53 #else /* KERNEL */
54 # include <sys/types.h>
55 # include <stdio.h>
56 # ifndef AFS_NT40_ENV
57 #  include <netinet/in.h>
58 # endif
59 # include "rx.h"
60 # include "xdr.h"
61 #endif /* KERNEL */
62
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 */
68
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,
72                              u_int len);
73 static bool_t xdrrx_putbytes(XDR *axdrs, caddr_t addr,
74                              u_int len);
75 static afs_int32 *xdrrx_inline(XDR *axdrs, u_int len);
76
77
78 /*
79  * Ops vector for stdio type XDR
80  */
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 */
86 #endif
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 */
91 #endif
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 */
102 #endif
103 #else
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)
117     .x_control = NULL,
118 #endif
119 #endif
120 };
121
122 /*
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.
125  */
126 void
127 xdrrx_create(XDR * xdrs, struct rx_call *call,
128              enum xdr_op op)
129 {
130     xdrs->x_op = op;
131     xdrs->x_ops = &xdrrx_ops;
132     xdrs->x_private = (caddr_t) call;
133 }
134
135 #if     defined(KERNEL) && defined(AFS_AIX32_ENV)
136 #define STACK_TO_PIN    2*PAGESIZE      /* 8K */
137 int rx_pin_failed = 0;
138 #endif
139
140 #ifdef AFS_XDR_64BITOPS
141 static bool_t
142 xdrrx_getint64(XDR *axdrs, long *lp)
143 {
144     XDR * xdrs = (XDR *)axdrs;
145     struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
146     afs_int32 i;
147
148     if (rx_Read32(call, &i) == sizeof(i)) {
149         *lp = ntohl(i);
150         return TRUE;
151     }
152     return FALSE;
153 }
154
155 static bool_t
156 xdrrx_putint64(XDR *axdrs, long *lp)
157 {
158     XDR * xdrs = (XDR *)axdrs;
159     afs_int32 code, i = htonl(*lp);
160     struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
161
162     code = (rx_Write32(call, &i) == sizeof(i));
163     return code;
164 }
165 #endif /* AFS_XDR_64BITOPS */
166
167 static bool_t
168 xdrrx_getint32(XDR *axdrs, afs_int32 * lp)
169 {
170     afs_int32 l;
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;
176     /*
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.
184      */
185     if (pin(saddr, STACK_TO_PIN)) {
186         /* XXX There's little we can do by continue XXX */
187         saddr = NULL;
188         rx_pin_failed++;
189     }
190 #endif
191     if (rx_Read32(call, &l) == sizeof(l)) {
192         *lp = ntohl(l);
193 #if     defined(KERNEL) && defined(AFS_AIX32_ENV)
194         if (saddr)
195             unpin(saddr, STACK_TO_PIN);
196 #endif
197         return TRUE;
198     }
199 #if     defined(KERNEL) && defined(AFS_AIX32_ENV)
200     if (saddr)
201         unpin(saddr, STACK_TO_PIN);
202 #endif
203     return FALSE;
204 }
205
206 static bool_t
207 xdrrx_putint32(XDR *axdrs, afs_int32 * lp)
208 {
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;
215     /*
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.
223      */
224     if (pin(saddr, STACK_TO_PIN)) {
225         saddr = NULL;
226         rx_pin_failed++;
227     }
228 #endif
229     code = (rx_Write32(call, &l) == sizeof(l));
230 #if     defined(KERNEL) && defined(AFS_AIX32_ENV)
231     if (saddr)
232         unpin(saddr, STACK_TO_PIN);
233 #endif
234     return code;
235 }
236
237 static bool_t
238 xdrrx_getbytes(XDR *axdrs, caddr_t addr, u_int len)
239 {
240     afs_int32 code;
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;
246     /*
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.
254      */
255     if (pin(saddr, STACK_TO_PIN)) {
256         /* XXX There's little we can do by continue XXX */
257         saddr = NULL;
258         rx_pin_failed++;
259     }
260 #endif
261     code = (rx_Read(call, addr, len) == len);
262 #if     defined(KERNEL) && defined(AFS_AIX32_ENV)
263     if (saddr)
264         unpin(saddr, STACK_TO_PIN);
265 #endif
266     return code;
267 }
268
269 static bool_t
270 xdrrx_putbytes(XDR *axdrs, caddr_t addr, u_int len)
271 {
272     afs_int32 code;
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;
278     /*
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.
286      */
287     if (pin(saddr, STACK_TO_PIN)) {
288         /* XXX There's little we can do by continue XXX */
289         saddr = NULL;
290         rx_pin_failed++;
291     }
292 #endif
293     code = (rx_Write(call, addr, len) == len);
294 #if     defined(KERNEL) && defined(AFS_AIX32_ENV)
295     if (saddr)
296         unpin(saddr, STACK_TO_PIN);
297 #endif
298     return code;
299 }
300
301 #ifdef undef                    /* not used */
302 static u_int
303 xdrrx_getpos(XDR * xdrs)
304 {
305     /* Not supported.  What error code should we return? (It doesn't matter:  it will never be called, anyway!) */
306     return -1;
307 }
308
309 static bool_t
310 xdrrx_setpos(XDR * xdrs, u_int pos)
311 {
312     /* Not supported */
313     return FALSE;
314 }
315 #endif
316
317 static afs_int32 *
318 xdrrx_inline(XDR *axdrs, u_int len)
319 {
320     /* I don't know what this routine is supposed to do, but the stdio module returns null, so we will, too */
321     return (0);
322 }