No empty .Rs/.Re
[netbsd-mini2440.git] / sys / compat / mach / mach_message.h
blob6c95fef86ae2b3e703509474a0a86d48d761bff2
1 /* $NetBSD: mach_message.h,v 1.29 2006/02/16 20:17:15 perry Exp $ */
3 /*-
4 * Copyright (c) 2001-2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas and Emmanuel Dreyfus.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #ifndef _MACH_MESSAGE_H_
33 #define _MACH_MESSAGE_H_
35 typedef unsigned int mach_msg_bits_t;
36 typedef unsigned int mach_msg_size_t;
37 typedef unsigned int mach_msg_id_t;
38 typedef unsigned int mach_msg_timeout_t;
39 typedef unsigned int mach_msg_option_t;
40 typedef unsigned int mach_msg_type_name_t;
41 typedef unsigned int mach_msg_type_number_t;
44 * Options
46 #define MACH_MSG_OPTION_NONE 0x00000000
47 #define MACH_SEND_MSG 0x00000001
48 #define MACH_RCV_MSG 0x00000002
49 #define MACH_RCV_LARGE 0x00000004
50 #define MACH_SEND_TIMEOUT 0x00000010
51 #define MACH_SEND_INTERRUPT 0x00000040
52 #define MACH_SEND_CANCEL 0x00000080
53 #define MACH_RCV_TIMEOUT 0x00000100
54 #define MACH_RCV_NOTIFY 0x00000200
55 #define MACH_RCV_INTERRUPT 0x00000400
56 #define MACH_RCV_OVERWRITE 0x00001000
57 #define MACH_SEND_ALWAYS 0x00010000
58 #define MACH_SEND_TRAILER 0x00020000
60 /* mach_msg error codes */
61 #define MACH_MSG_SUCCESS 0x00000000
62 #define MACH_MSG_MASK 0x00003e00
63 #define MACH_MSG_IPC_SPACE 0x00002000
64 #define MACH_MSG_VM_SPACE 0x00001000
65 #define MACH_MSG_IPC_KERNEL 0x00000800
66 #define MACH_MSG_VM_KERNEL 0x00000400
67 #define MACH_SEND_MSG 0x00000001
68 #define MACH_SEND_TIMEOUT 0x00000010
69 #define MACH_SEND_INTERRUPT 0x00000040
70 #define MACH_SEND_CANCEL 0x00000080
71 #define MACH_SEND_ALWAYS 0x00010000
72 #define MACH_SEND_TRAILER 0x00020000
73 #define MACH_SEND_IN_PROGRESS 0x10000001
74 #define MACH_SEND_INVALID_DATA 0x10000002
75 #define MACH_SEND_INVALID_DEST 0x10000003
76 #define MACH_SEND_TIMED_OUT 0x10000004
77 #define MACH_SEND_INTERRUPTED 0x10000007
78 #define MACH_SEND_MSG_TOO_SMALL 0x10000008
79 #define MACH_SEND_INVALID_REPLY 0x10000009
80 #define MACH_SEND_INVALID_RIGHT 0x1000000a
81 #define MACH_SEND_INVALID_NOTIFY 0x1000000b
82 #define MACH_SEND_INVALID_MEMORY 0x1000000c
83 #define MACH_SEND_NO_BUFFER 0x1000000d
84 #define MACH_SEND_TOO_LARGE 0x1000000e
85 #define MACH_SEND_INVALID_TYPE 0x1000000f
86 #define MACH_SEND_INVALID_HEADER 0x10000010
87 #define MACH_SEND_INVALID_TRAILER 0x10000011
88 #define MACH_SEND_INVALID_RT_OOL_SIZE 0x10000015
89 #define MACH_RCV_IN_PROGRESS 0x10004001
90 #define MACH_RCV_INVALID_NAME 0x10004002
91 #define MACH_RCV_TIMED_OUT 0x10004003
92 #define MACH_RCV_TOO_LARGE 0x10004004
93 #define MACH_RCV_INTERRUPTED 0x10004005
94 #define MACH_RCV_PORT_CHANGED 0x10004006
95 #define MACH_RCV_INVALID_NOTIFY 0x10004007
96 #define MACH_RCV_INVALID_DATA 0x10004008
97 #define MACH_RCV_PORT_DIED 0x10004009
98 #define MACH_RCV_IN_SET 0x1000400a
99 #define MACH_RCV_HEADER_ERROR 0x1000400b
100 #define MACH_RCV_BODY_ERROR 0x1000400c
101 #define MACH_RCV_INVALID_TYPE 0x1000400d
102 #define MACH_RCV_SCATTER_SMALL 0x1000400e
103 #define MACH_RCV_INVALID_TRAILER 0x1000400f
104 #define MACH_RCV_IN_PROGRESS_TIMED 0x10004011
106 #define MACH_MSG_OPTION_BITS "\177\20" \
107 "b\00send_msg\0b\01rcv_msg\0" \
108 "b\02rcv_large\0b\03invalid[0x8]\0" \
109 "b\04send_timeout\0b05invalid[0x20]\0" \
110 "b\06send_interrupt\0b\05send_cancel\0" \
111 "b\06rcv_timeout\0b\07rcv_notify\0" \
112 "b\10rcv_interrupt\0b\11invalid[0x800]\0" \
113 "b\12rcv_overwrite\0b\13invalid[0x2000]\0" \
114 "b\14invalid[0x4000]\0b\15invalid[0x8000]\0" \
115 "b\16send_always\0b\17send_trailer\0"
117 #define MACH_MSGH_BITS_REMOTE_MASK 0x000000ff
118 #define MACH_MSGH_BITS_LOCAL_MASK 0x0000ff00
119 #define MACH_MSGH_BITS_COMPLEX 0x80000000
120 #define MACH_MSGH_LOCAL_BITS(bits) (((bits) >> 8) & 0xff)
121 #define MACH_MSGH_REMOTE_BITS(bits) ((bits) & 0xff)
122 #define MACH_MSGH_REPLY_LOCAL_BITS(bits) (((bits) << 8) & 0xff00)
124 #define MACH_MSG_TYPE_MOVE_RECEIVE 16
125 #define MACH_MSG_TYPE_MOVE_SEND 17
126 #define MACH_MSG_TYPE_MOVE_SEND_ONCE 18
127 #define MACH_MSG_TYPE_COPY_SEND 19
128 #define MACH_MSG_TYPE_MAKE_SEND 20
129 #define MACH_MSG_TYPE_MAKE_SEND_ONCE 21
130 #define MACH_MSG_TYPE_COPY_RECEIVE 22
132 typedef unsigned int mach_msg_copy_options_t;
134 #define MACH_MSG_PHYSICAL_COPY 0
135 #define MACH_MSG_VIRTUAL_COPY 1
136 #define MACH_MSG_ALLOCATE 2
137 #define MACH_MSG_OVERWRITE 3
138 #define MACH_MSG_KALLOC_COPY_T 4
139 #define MACH_MSG_PAGE_LIST_COPY_T 5
141 typedef unsigned int mach_msg_descriptor_type_t;
143 #define MACH_MSG_PORT_DESCRIPTOR 0
144 #define MACH_MSG_OOL_DESCRIPTOR 1
145 #define MACH_MSG_OOL_PORTS_DESCRIPTOR 2
146 #define MACH_MSG_OOL_VOLATILE_DESCRIPTOR 3
148 #define MACH_MAX_MSG_LEN 65536
150 typedef struct {
151 mach_msg_bits_t msgh_bits;
152 mach_msg_size_t msgh_size;
153 mach_port_t msgh_remote_port;
154 mach_port_t msgh_local_port;
155 mach_msg_size_t msgh_reserved;
156 mach_msg_id_t msgh_id;
157 } mach_msg_header_t;
159 #define MACH_MSG_TRAILER_FORMAT_0 0
160 typedef u_int32_t mach_msg_trailer_type_t;
161 typedef u_int32_t mach_msg_trailer_size_t;
162 typedef struct {
163 mach_msg_trailer_type_t msgh_trailer_type;
164 mach_msg_trailer_size_t msgh_trailer_size;
165 } mach_msg_trailer_t;
167 typedef struct {
168 void* pad1;
169 mach_msg_size_t pad2;
170 unsigned int pad3 : 24;
171 mach_msg_descriptor_type_t type : 8;
172 } mach_msg_type_descriptor_t;
174 typedef struct {
175 mach_port_t name;
176 mach_msg_size_t pad1;
177 unsigned int pad2 : 16;
178 mach_msg_type_name_t disposition : 8;
179 mach_msg_descriptor_type_t type : 8;
180 } mach_msg_port_descriptor_t;
182 typedef struct {
183 void * address;
184 mach_msg_size_t count;
185 mach_boolean_t deallocate: 8;
186 mach_msg_copy_options_t copy: 8;
187 mach_msg_type_name_t disposition : 8;
188 mach_msg_descriptor_type_t type : 8;
189 } mach_msg_ool_ports_descriptor_t;
191 typedef struct {
192 void * address;
193 mach_msg_size_t size;
194 mach_boolean_t deallocate : 8;
195 mach_msg_copy_options_t copy : 8;
196 unsigned int pad1 : 8;
197 mach_msg_descriptor_type_t type : 8;
198 } mach_msg_ool_descriptor_t;
200 typedef struct {
201 mach_msg_size_t msgh_descriptor_count;
202 } mach_msg_body_t;
204 #define MACH_REQMSG_OVERFLOW(args, test) \
205 (((u_long)&test - (u_long)args->smsg) > args->ssize)
207 struct mach_short_reply {
208 mach_msg_header_t sr_header;
209 mach_msg_trailer_t sr_trailer;
212 struct mach_complex_msg {
213 mach_msg_header_t mcm_header;
214 mach_msg_body_t mcm_body;
215 union {
216 mach_msg_type_descriptor_t gen[1];
217 mach_msg_port_descriptor_t port[1];
218 mach_msg_ool_ports_descriptor_t ool_ports[1];
219 mach_msg_ool_descriptor_t ool[1];
220 } mcm_desc;
223 /* Kernel-private structures */
225 struct mach_trap_args {
226 struct lwp *l; /* Current task (doing the Mach system call) */
227 struct lwp *tl; /* Target task */
228 void *smsg; /* Sent message */
229 void *rmsg; /* Reply message */
230 size_t ssize; /* Sent message size */
231 size_t *rsize; /* Reply message maximum size, may be lowered */
234 struct mach_service {
235 int srv_id;
236 int (*srv_handler)(struct mach_trap_args *);
237 const char *srv_name;
238 size_t srv_reqlen; /* Minimum length of the request message */
239 size_t srv_replen; /* Maximum length of the reply message */
241 extern struct mach_service mach_services_table[];
244 /* In-kernel Mach messages description */
245 struct mach_message {
246 mach_msg_header_t *mm_msg; /* In-kernel copy of the message */
247 size_t mm_size; /* Message size */
248 TAILQ_ENTRY(mach_message) mm_list;
249 /* List of pending messages */
250 struct mach_port *mm_port; /* The port on which msg is queued */
251 struct lwp *mm_l; /* The thread that sent it */
254 /* Flags for mach_ool_copy{in|out} */
255 #define MACH_OOL_NONE 0x0
256 #define MACH_OOL_FREE 0x1 /* Free kernel buffer after copyout */
257 #define MACH_OOL_TRACE 0x2 /* ktrace OOL data */
259 __inline int mach_ool_copyin(struct lwp *, const void *, void **, size_t, int);
260 __inline int mach_ool_copyout(struct lwp *, const void *, void **, size_t, int);
261 __inline void mach_set_trailer(void *, size_t);
262 __inline void mach_set_header(void *, void *, size_t);
263 __inline void mach_add_port_desc(void *, mach_port_name_t);
264 __inline void mach_add_ool_ports_desc(void *, void *, int);
265 __inline void mach_add_ool_desc(void *, void *, size_t);
266 void mach_message_init(void);
267 struct mach_message *mach_message_get(mach_msg_header_t *,
268 size_t, struct mach_port *, struct lwp *);
269 void mach_message_put(struct mach_message *);
270 void mach_message_put_shlocked(struct mach_message *);
271 void mach_message_put_exclocked(struct mach_message *);
272 #ifdef DEBUG_MACH
273 void mach_debug_message(void);
274 #endif
276 #endif /* !_MACH_MESSAGE_H_ */