]> git.ipfire.org Git - thirdparty/glibc.git/blame - mach/msg-destroy.c
Convert 703 function definitions to prototype style.
[thirdparty/glibc.git] / mach / msg-destroy.c
CommitLineData
5107cf1d 1/*
28f540f4
RM
2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
4 * All Rights Reserved.
5107cf1d 5 *
28f540f4
RM
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
5107cf1d 11 *
28f540f4
RM
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
5107cf1d 15 *
28f540f4 16 * Carnegie Mellon requests users of this software to return to
5107cf1d 17 *
28f540f4
RM
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
5107cf1d 22 *
28f540f4
RM
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26/*
eff75b8d 27 * (pre-GNU) HISTORY
28f540f4
RM
28 *
29 * Revision 2.4 91/05/14 17:53:15 mrt
30 * Correcting copyright
5107cf1d 31 *
28f540f4
RM
32 * Revision 2.3 91/02/14 14:17:43 mrt
33 * Added new Mach copyright
34 * [91/02/13 12:44:15 mrt]
5107cf1d 35 *
28f540f4
RM
36 * Revision 2.2 90/08/06 17:24:22 rpd
37 * Created.
5107cf1d 38 *
28f540f4
RM
39 */
40
41#if 1
42#include <mach.h>
43#else
44/* This is what CMU did, but that fails to declare some used functions. */
45#include <mach/port.h>
46#include <mach/message.h>
47#include <mach_init.h>
48#endif
49
ebe3b3eb
TBB
50static void mach_msg_destroy_port(mach_port_t, mach_msg_type_name_t);
51static void mach_msg_destroy_memory(vm_offset_t, vm_size_t);
28f540f4
RM
52
53/*
54 * Routine: mach_msg_destroy
55 * Purpose:
56 * Deallocates all port rights and out-of-line memory
57 * found in a received message.
58 */
59
60void
9d46370c 61__mach_msg_destroy (mach_msg_header_t *msg)
28f540f4
RM
62{
63 mach_msg_bits_t mbits = msg->msgh_bits;
64
65 /*
66 * The msgh_local_port field doesn't hold a port right.
67 * The receive operation consumes the destination port right.
68 */
69
70 mach_msg_destroy_port(msg->msgh_remote_port, MACH_MSGH_BITS_REMOTE(mbits));
71
72 if (mbits & MACH_MSGH_BITS_COMPLEX) {
61c83c3f
RM
73#ifdef MACH_MSG_PORT_DESCRIPTOR
74 mach_msg_body_t *body;
75 mach_msg_descriptor_t *saddr, *eaddr;
76
350635a5
OB
77 body = (mach_msg_body_t *) (msg + 1);
78 saddr = (mach_msg_descriptor_t *)
61c83c3f 79 ((mach_msg_base_t *) msg + 1);
350635a5 80 eaddr = saddr + body->msgh_descriptor_count;
61c83c3f
RM
81
82 for ( ; saddr < eaddr; saddr++) {
83 switch (saddr->type.type) {
84
85 case MACH_MSG_PORT_DESCRIPTOR: {
86 mach_msg_port_descriptor_t *dsc;
87
88 /*
89 * Destroy port rights carried in the message
90 */
91 dsc = &saddr->port;
92 mach_msg_destroy_port(dsc->name, dsc->disposition);
93 break;
94 }
95
96 case MACH_MSG_OOL_DESCRIPTOR : {
97 mach_msg_ool_descriptor_t *dsc;
98
99 /*
100 * Destroy memory carried in the message
101 */
102 dsc = &saddr->out_of_line;
103 if (dsc->deallocate) {
104 mach_msg_destroy_memory((vm_offset_t)dsc->address,
105 dsc->size);
106 }
107 break;
108 }
109
110 case MACH_MSG_OOL_PORTS_DESCRIPTOR : {
111 mach_port_t *ports;
112 mach_msg_ool_ports_descriptor_t *dsc;
113 mach_msg_type_number_t j;
114
115 /*
116 * Destroy port rights carried in the message
117 */
118 dsc = &saddr->ool_ports;
119 ports = (mach_port_t *) dsc->address;
120 for (j = 0; j < dsc->count; j++, ports++) {
121 mach_msg_destroy_port(*ports, dsc->disposition);
122 }
123
124 /*
125 * Destroy memory carried in the message
126 */
127 if (dsc->deallocate) {
128 mach_msg_destroy_memory((vm_offset_t)dsc->address,
129 dsc->count * sizeof(mach_port_t));
130 }
131 break;
132 }
133 }
134 }
135#else
28f540f4
RM
136 vm_offset_t saddr;
137 vm_offset_t eaddr;
138
139 saddr = (vm_offset_t) (msg + 1);
140 eaddr = (vm_offset_t) msg + msg->msgh_size;
141
142 while (saddr < eaddr) {
143 mach_msg_type_long_t *type;
144 mach_msg_type_name_t name;
145 mach_msg_type_size_t size;
146 mach_msg_type_number_t number;
147 boolean_t is_inline;
148 vm_size_t length;
149 vm_offset_t addr;
150
151 type = (mach_msg_type_long_t *) saddr;
152 is_inline = type->msgtl_header.msgt_inline;
153 if (type->msgtl_header.msgt_longform) {
154 name = type->msgtl_name;
155 size = type->msgtl_size;
156 number = type->msgtl_number;
157 saddr += sizeof(mach_msg_type_long_t);
158 } else {
159 name = type->msgtl_header.msgt_name;
160 size = type->msgtl_header.msgt_size;
161 number = type->msgtl_header.msgt_number;
162 saddr += sizeof(mach_msg_type_t);
163 }
164
165 /* calculate length of data in bytes, rounding up */
5107cf1d
UD
166 length = (((((number * size) + 7) >> 3) + sizeof (int) - 1)
167 &~ (sizeof (int) - 1));
28f540f4
RM
168
169 addr = is_inline ? saddr : * (vm_offset_t *) saddr;
170
171 if (MACH_MSG_TYPE_PORT_ANY(name)) {
172 mach_port_t *ports = (mach_port_t *) addr;
173 mach_msg_type_number_t i;
174
175 for (i = 0; i < number; i++)
176 mach_msg_destroy_port(*ports++, name);
177 }
178
179 if (is_inline) {
180 /* inline data sizes round up to int boundaries */
181 saddr += length;
182 } else {
183 mach_msg_destroy_memory(addr, length);
184 saddr += sizeof(vm_offset_t);
185 }
186 }
61c83c3f 187#endif
28f540f4
RM
188 }
189}
190
191weak_alias (__mach_msg_destroy, mach_msg_destroy)
192
193static void
9d46370c 194mach_msg_destroy_port (mach_port_t port, mach_msg_type_name_t type)
28f540f4
RM
195{
196 if (MACH_PORT_VALID(port)) switch (type) {
61c83c3f
RM
197 case MACH_MSG_TYPE_MOVE_SEND:
198 case MACH_MSG_TYPE_MOVE_SEND_ONCE:
199 /* destroy the send/send-once right */
200 (void) __mach_port_deallocate(mach_task_self(), port);
28f540f4
RM
201 break;
202
61c83c3f
RM
203 case MACH_MSG_TYPE_MOVE_RECEIVE:
204 /* destroy the receive right */
205 (void) __mach_port_mod_refs(mach_task_self(), port,
28f540f4
RM
206 MACH_PORT_RIGHT_RECEIVE, -1);
207 break;
61c83c3f
RM
208
209 case MACH_MSG_TYPE_MAKE_SEND:
210 /* create a send right and then destroy it */
211 (void) __mach_port_insert_right(mach_task_self(), port,
212 port, MACH_MSG_TYPE_MAKE_SEND);
213 (void) __mach_port_deallocate(mach_task_self(), port);
214 break;
215
216 case MACH_MSG_TYPE_MAKE_SEND_ONCE:
217 /* create a send-once right and then destroy it */
218 (void) __mach_port_extract_right(mach_task_self(), port,
219 MACH_MSG_TYPE_MAKE_SEND_ONCE,
220 &port, &type);
221 (void) __mach_port_deallocate(mach_task_self(), port);
222 break;
28f540f4
RM
223 }
224}
225
226static void
9d46370c 227mach_msg_destroy_memory (vm_offset_t addr, vm_size_t size)
28f540f4
RM
228{
229 if (size > 0)
230 (void) __vm_deallocate(__mach_task_self(), addr, size);
231}