source: rtems/cpukit/librpc/include/rpc/svc.h @ 17fa7d6

4.10
Last change on this file since 17fa7d6 was 17fa7d6, checked in by Sebastian Huber <sebastian.huber@…>, on 04/23/12 at 12:42:58

librpc: PR2066: Fix for short enums

The XDR library has a problem on architectures with short enums like the
default ARM EABI. Short enums means that the size of the enum type is
variable and the smallest integer type to hold all enum values will be
selected. For many enums this is char. The XDR library uses int32_t
for enum_t. There are several evil casts from an enum type to enum_t
which leads to invalid memory accesses on short enum architectures. A
workaround is to add appropriate dummy enum values.

  • Property mode set to 100644
File size: 9.4 KB
Line 
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part.  Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
8 *
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
12 *
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
16 *
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
20 *
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
24 *
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California  94043
28 *
29 *      from: @(#)svc.h 1.35 88/12/17 SMI
30 *      from: @(#)svc.h      1.27    94/04/25 SMI
31 * $FreeBSD: src/include/rpc/svc.h,v 1.24 2003/06/15 10:32:01 mbr Exp $
32 */
33
34/*
35 * svc.h, Server-side remote procedure call interface.
36 *
37 * Copyright (C) 1986-1993 by Sun Microsystems, Inc.
38 */
39
40#ifndef _RPC_SVC_H
41#define _RPC_SVC_H
42#include <rtems/bsd/sys/cdefs.h>
43
44/*
45 * This interface must manage two items concerning remote procedure calling:
46 *
47 * 1) An arbitrary number of transport connections upon which rpc requests
48 * are received.  The two most notable transports are TCP and UDP;  they are
49 * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
50 * they in turn call xprt_register and xprt_unregister.
51 *
52 * 2) An arbitrary number of locally registered services.  Services are
53 * described by the following four data: program number, version number,
54 * "service dispatch" function, a transport handle, and a boolean that
55 * indicates whether or not the exported program should be registered with a
56 * local binder service;  if true the program's number and version and the
57 * port number from the transport handle are registered with the binder.
58 * These data are registered with the rpc svc system via svc_register.
59 *
60 * A service's dispatch function is called whenever an rpc request comes in
61 * on a transport.  The request's program and version numbers must match
62 * those of the registered service.  The dispatch function is passed two
63 * parameters, struct svc_req * and SVCXPRT *, defined below.
64 */
65
66enum xprt_stat {
67        XPRT_DIED,
68        XPRT_MOREREQS,
69        XPRT_IDLE,
70        _XPRT_STAT = 0xffffffff
71};
72
73struct rpc_msg;
74
75/*
76 * Server side transport handle
77 */
78typedef struct __rpc_svcxprt {
79        int             xp_sock;
80        u_short         xp_port;         /* associated port number */
81        struct xp_ops {
82            /* receive incoming requests */
83            bool_t      (*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *);
84            /* get transport status */
85            enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *);
86            /* get arguments */
87            bool_t      (*xp_getargs)(struct __rpc_svcxprt *, xdrproc_t,
88                                caddr_t args_ptr);
89            /* send reply */
90            bool_t      (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *);
91            /* free mem allocated for args */
92            bool_t      (*xp_freeargs)(struct __rpc_svcxprt *, xdrproc_t,
93                                caddr_t args_ptr);
94            /* destroy this struct */
95            void        (*xp_destroy)(struct __rpc_svcxprt *);
96        } *xp_ops;
97        socklen_t       xp_addrlen;      /* length of remote address */
98        struct sockaddr_in xp_raddr;     /* remote addr. (backward ABI compat) */
99        struct opaque_auth xp_verf;      /* raw response verifier */
100        void            *xp_p1;          /* private: for use by svc ops */
101        void            *xp_p2;          /* private: for use by svc ops */
102} SVCXPRT;
103
104/*
105 * Service request
106 */
107struct svc_req {
108        u_int32_t       rq_prog;        /* service program number */
109        u_int32_t       rq_vers;        /* service protocol version */
110        u_int32_t       rq_proc;        /* the desired procedure */
111        struct opaque_auth rq_cred;     /* raw creds from the wire */
112        caddr_t         rq_clntcred;    /* read only cooked cred */
113        SVCXPRT         *rq_xprt;       /* associated transport */
114};
115
116
117/*
118 * Operations defined on an SVCXPRT handle
119 *
120 * SVCXPRT              *xprt;
121 * struct rpc_msg       *msg;
122 * xdrproc_t             xargs;
123 * caddr_t               argsp;
124 */
125#define SVC_RECV(xprt, msg)                             \
126        (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
127#define svc_recv(xprt, msg)                             \
128        (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
129
130#define SVC_STAT(xprt)                                  \
131        (*(xprt)->xp_ops->xp_stat)(xprt)
132#define svc_stat(xprt)                                  \
133        (*(xprt)->xp_ops->xp_stat)(xprt)
134
135#define SVC_GETARGS(xprt, xargs, argsp)                 \
136        (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
137#define svc_getargs(xprt, xargs, argsp)                 \
138        (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
139
140#define SVC_REPLY(xprt, msg)                            \
141        (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
142#define svc_reply(xprt, msg)                            \
143        (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
144
145#define SVC_FREEARGS(xprt, xargs, argsp)                \
146        (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
147#define svc_freeargs(xprt, xargs, argsp)                \
148        (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
149
150#define SVC_DESTROY(xprt)                               \
151        (*(xprt)->xp_ops->xp_destroy)(xprt)
152#define svc_destroy(xprt)                               \
153        (*(xprt)->xp_ops->xp_destroy)(xprt)
154
155/*
156 * Transport registration.
157 *
158 * xprt_register(xprt)
159 *      SVCXPRT *xprt;
160 */
161__BEGIN_DECLS
162extern void     xprt_register(SVCXPRT *);
163__END_DECLS
164
165/*
166 * Transport un-register
167 *
168 * xprt_unregister(xprt)
169 *      SVCXPRT *xprt;
170 */
171__BEGIN_DECLS
172extern void     xprt_unregister(SVCXPRT *);
173__END_DECLS
174
175
176/*
177 * When the service routine is called, it must first check to see if it
178 * knows about the procedure;  if not, it should call svcerr_noproc
179 * and return.  If so, it should deserialize its arguments via
180 * SVC_GETARGS (defined above).  If the deserialization does not work,
181 * svcerr_decode should be called followed by a return.  Successful
182 * decoding of the arguments should be followed the execution of the
183 * procedure's code and a call to svc_sendreply.
184 *
185 * Also, if the service refuses to execute the procedure due to too-
186 * weak authentication parameters, svcerr_weakauth should be called.
187 * Note: do not confuse access-control failure with weak authentication!
188 *
189 * NB: In pure implementations of rpc, the caller always waits for a reply
190 * msg.  This message is sent when svc_sendreply is called.
191 * Therefore pure service implementations should always call
192 * svc_sendreply even if the function logically returns void;  use
193 * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
194 * for the abuse of pure rpc via batched calling or pipelining.  In the
195 * case of a batched call, svc_sendreply should NOT be called since
196 * this would send a return message, which is what batching tries to avoid.
197 * It is the service/protocol writer's responsibility to know which calls are
198 * batched and which are not.  Warning: responding to batch calls may
199 * deadlock the caller and server processes!
200 */
201
202__BEGIN_DECLS
203extern bool_t   svc_sendreply(SVCXPRT *, xdrproc_t, void *);
204extern void     svcerr_decode(SVCXPRT *);
205extern void     svcerr_weakauth(SVCXPRT *);
206extern void     svcerr_noproc(SVCXPRT *);
207extern void     svcerr_progvers(SVCXPRT *, rpcvers_t, rpcvers_t);
208extern void     svcerr_auth(SVCXPRT *, enum auth_stat);
209extern void     svcerr_noprog(SVCXPRT *);
210extern void     svcerr_systemerr(SVCXPRT *);
211__END_DECLS
212
213/*
214 * Lowest level dispatching -OR- who owns this process anyway.
215 * Somebody has to wait for incoming requests and then call the correct
216 * service routine.  The routine svc_run does infinite waiting; i.e.,
217 * svc_run never returns.
218 * Since another (co-existant) package may wish to selectively wait for
219 * incoming calls or other events outside of the rpc architecture, the
220 * routine svc_getreq is provided.  It must be passed readfds, the
221 * "in-place" results of a select system call (see select, section 2).
222 */
223
224/*
225 * Global keeper of rpc service descriptors in use
226 * dynamic; must be inspected before each call to select
227 */
228extern int svc_maxfd;
229extern fd_set svc_fdset;
230#define svc_fds svc_fdset.fds_bits[0]   /* compatibility */
231
232#ifndef _KERNEL
233/*
234 * a small program implemented by the svc_rpc implementation itself;
235 * also see clnt.h for protocol numbers.
236 */
237__BEGIN_DECLS
238extern void rpctest_service(void);
239__END_DECLS
240#endif
241
242__BEGIN_DECLS
243extern void     svc_getreq(int);
244extern void     svc_getreqset(fd_set *);
245extern void     svc_getreqset2(fd_set *, int); /* XXX: nonstd, undoc */
246extern void     svc_run(void);
247__END_DECLS
248
249/*
250 * Socket to use on svcxxx_create call to get default socket
251 */
252#define RPC_ANYSOCK     -1
253#define RPC_ANYFD       RPC_ANYSOCK
254
255/*
256 * These are the existing service side transport implementations
257 */
258
259__BEGIN_DECLS
260/*
261 * Transport independent svc_create routine.
262 */
263
264/*
265 * Connectionless and connectionful create routines
266 */
267
268extern SVCXPRT *svc_vc_create(const int, const u_int, const u_int);
269/*
270 *      const int fd;                           -- open connection end point
271 *      const u_int sendsize;                   -- max send size
272 *      const u_int recvsize;                   -- max recv size
273 */
274
275/*
276 * Added for compatibility to old rpc 4.0. Obsoleted by svc_vc_create().
277 */
278extern SVCXPRT *svcunix_create(int, u_int, u_int, char *);
279
280/*
281 * Added for compatibility to old rpc 4.0. Obsoleted by svc_fd_create().
282 */
283extern SVCXPRT *svcunixfd_create(int, u_int, u_int);
284__END_DECLS
285
286
287/* for backward compatibility */
288#include <rpc/svc_soc.h>
289
290#endif /* !_RPC_SVC_H */
Note: See TracBrowser for help on using the repository browser.