Import Upstream version 1.8.5
[hcoop/debian/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 #include <afs/param.h>
16
17 #ifdef KERNEL
18 # include "afs/sysincludes.h"
19 # ifndef UKERNEL
20 # include "h/types.h"
21 # include "h/uio.h"
22 # ifdef AFS_LINUX20_ENV
23 # include "h/socket.h"
24 # endif
25 # ifdef AFS_LINUX22_ENV
26 # ifndef quad_t
27 # define quad_t __quad_t
28 # define u_quad_t __u_quad_t
29 # endif
30 # endif
31 # include "netinet/in.h"
32 # endif /* !UKERNEL */
33 #else /* KERNEL */
34 # include <roken.h>
35 #endif /* KERNEL */
36
37 #include "rx.h"
38 #include "xdr.h"
39
40 /* Static prototypes */
41 static bool_t xdrrx_getint32(XDR *axdrs, afs_int32 * lp);
42 static bool_t xdrrx_putint32(XDR *axdrs, afs_int32 * lp);
43 static bool_t xdrrx_getbytes(XDR *axdrs, caddr_t addr,
44 u_int len);
45 static bool_t xdrrx_putbytes(XDR *axdrs, caddr_t addr,
46 u_int len);
47 static afs_int32 *xdrrx_inline(XDR *axdrs, u_int len);
48
49
50 /*
51 * Ops vector for stdio type XDR
52 */
53 static struct xdr_ops xdrrx_ops = {
54 #ifndef HAVE_STRUCT_LABEL_SUPPORT
55 /* Windows does not support labeled assigments */
56 xdrrx_getint32, /* deserialize an afs_int32 */
57 xdrrx_putint32, /* serialize an afs_int32 */
58 xdrrx_getbytes, /* deserialize counted bytes */
59 xdrrx_putbytes, /* serialize counted bytes */
60 NULL, /* get offset in the stream: not supported. */
61 NULL, /* set offset in the stream: not supported. */
62 xdrrx_inline, /* prime stream for inline macros */
63 NULL, /* destroy stream */
64 #else
65 .x_getint32 = xdrrx_getint32, /* deserialize an afs_int32 */
66 .x_putint32 = xdrrx_putint32, /* serialize an afs_int32 */
67 .x_getbytes = xdrrx_getbytes, /* deserialize counted bytes */
68 .x_putbytes = xdrrx_putbytes, /* serialize counted bytes */
69 .x_getpostn = NULL, /* get offset in the stream: not supported. */
70 .x_setpostn = NULL, /* set offset in the stream: not supported. */
71 .x_inline = xdrrx_inline, /* prime stream for inline macros */
72 .x_destroy = NULL, /* destroy stream */
73 #endif
74 };
75
76 /*
77 * Initialize an rx xdr handle, for a given rx call. op must be XDR_ENCODE or XDR_DECODE.
78 * Call must have been returned by rx_MakeCall or rx_GetCall.
79 */
80 void
81 xdrrx_create(XDR * xdrs, struct rx_call *call,
82 enum xdr_op op)
83 {
84 xdrs->x_op = op;
85 xdrs->x_ops = &xdrrx_ops;
86 xdrs->x_private = (caddr_t) call;
87 }
88
89 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
90 #define STACK_TO_PIN 2*PAGESIZE /* 8K */
91 int rx_pin_failed = 0;
92 #endif
93
94 static bool_t
95 xdrrx_getint32(XDR *axdrs, afs_int32 * lp)
96 {
97 afs_int32 l;
98 XDR * xdrs = (XDR *)axdrs;
99 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
100 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
101 char *saddr = (char *)&l;
102 saddr -= STACK_TO_PIN;
103 /*
104 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
105 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
106 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
107 * 2K stack we could try to bring the next few stack pages in here before we call the rx
108 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
109 * out between here and calling splnet. So we now pin (and unpin) them instead to
110 * guarantee that they remain there.
111 */
112 if (pin(saddr, STACK_TO_PIN)) {
113 /* XXX There's little we can do by continue XXX */
114 saddr = NULL;
115 rx_pin_failed++;
116 }
117 #endif
118 if (rx_Read32(call, &l) == sizeof(l)) {
119 *lp = ntohl(l);
120 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
121 if (saddr)
122 unpin(saddr, STACK_TO_PIN);
123 #endif
124 return TRUE;
125 }
126 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
127 if (saddr)
128 unpin(saddr, STACK_TO_PIN);
129 #endif
130 return FALSE;
131 }
132
133 static bool_t
134 xdrrx_putint32(XDR *axdrs, afs_int32 * lp)
135 {
136 afs_int32 code, l = htonl(*lp);
137 XDR * xdrs = (XDR *)axdrs;
138 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
139 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
140 char *saddr = (char *)&code;
141 saddr -= STACK_TO_PIN;
142 /*
143 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
144 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
145 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
146 * 2K stack we could try to bring the next few stack pages in here before we call the rx
147 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
148 * out between here and calling splnet. So we now pin (and unpin) them instead to
149 * guarantee that they remain there.
150 */
151 if (pin(saddr, STACK_TO_PIN)) {
152 saddr = NULL;
153 rx_pin_failed++;
154 }
155 #endif
156 code = (rx_Write32(call, &l) == sizeof(l));
157 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
158 if (saddr)
159 unpin(saddr, STACK_TO_PIN);
160 #endif
161 return code;
162 }
163
164 static bool_t
165 xdrrx_getbytes(XDR *axdrs, caddr_t addr, u_int len)
166 {
167 afs_int32 code;
168 XDR * xdrs = (XDR *)axdrs;
169 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
170 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
171 char *saddr = (char *)&code;
172 saddr -= STACK_TO_PIN;
173 /*
174 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
175 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
176 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
177 * 2K stack we could try to bring the next few stack pages in here before we call the rx
178 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
179 * out between here and calling splnet. So we now pin (and unpin) them instead to
180 * guarantee that they remain there.
181 */
182 if (pin(saddr, STACK_TO_PIN)) {
183 /* XXX There's little we can do by continue XXX */
184 saddr = NULL;
185 rx_pin_failed++;
186 }
187 #endif
188 code = (rx_Read(call, addr, len) == len);
189 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
190 if (saddr)
191 unpin(saddr, STACK_TO_PIN);
192 #endif
193 return code;
194 }
195
196 static bool_t
197 xdrrx_putbytes(XDR *axdrs, caddr_t addr, u_int len)
198 {
199 afs_int32 code;
200 XDR * xdrs = (XDR *)axdrs;
201 struct rx_call *call = ((struct rx_call *)(xdrs)->x_private);
202 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
203 char *saddr = (char *)&code;
204 saddr -= STACK_TO_PIN;
205 /*
206 * Hack of hacks: Aix3.2 only guarantees that the next 2K of stack in pinned. Under
207 * splnet (disables interrupts), which is set throughout rx, we can't swap in stack
208 * pages if we need so we panic. Since sometimes, under splnet, we'll use more than
209 * 2K stack we could try to bring the next few stack pages in here before we call the rx
210 * layer. Of course this doesn't guarantee that those stack pages won't be swapped
211 * out between here and calling splnet. So we now pin (and unpin) them instead to
212 * guarantee that they remain there.
213 */
214 if (pin(saddr, STACK_TO_PIN)) {
215 /* XXX There's little we can do by continue XXX */
216 saddr = NULL;
217 rx_pin_failed++;
218 }
219 #endif
220 code = (rx_Write(call, addr, len) == len);
221 #if defined(KERNEL) && defined(AFS_AIX32_ENV)
222 if (saddr)
223 unpin(saddr, STACK_TO_PIN);
224 #endif
225 return code;
226 }
227
228 #ifdef undef /* not used */
229 static u_int
230 xdrrx_getpos(XDR * xdrs)
231 {
232 /* Not supported. What error code should we return? (It doesn't matter: it will never be called, anyway!) */
233 return -1;
234 }
235
236 static bool_t
237 xdrrx_setpos(XDR * xdrs, u_int pos)
238 {
239 /* Not supported */
240 return FALSE;
241 }
242 #endif
243
244 static afs_int32 *
245 xdrrx_inline(XDR *axdrs, u_int len)
246 {
247 /* I don't know what this routine is supposed to do, but the stdio module returns null, so we will, too */
248 return (0);
249 }