Fix syntax of value type of sysconf, pathconf.
[glibc/history.git] / mach / msg-destroy.c
blob3bbf88d61cfcf287fe0b1e4b2b940a5568eff5ae
1 /*
2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
4 * All Rights Reserved.
5 *
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.
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.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
27 * HISTORY
28 * $Log$
29 * Revision 1.1 1991/10/23 12:49:45 roland
30 * Initial revision
32 * Revision 2.4 91/05/14 17:53:15 mrt
33 * Correcting copyright
35 * Revision 2.3 91/02/14 14:17:43 mrt
36 * Added new Mach copyright
37 * [91/02/13 12:44:15 mrt]
39 * Revision 2.2 90/08/06 17:24:22 rpd
40 * Created.
44 #include <mach/port.h>
45 #include <mach/message.h>
46 #include <mach_init.h>
48 static void mach_msg_destroy_port();
49 static void mach_msg_destroy_memory();
52 * Routine: mach_msg_destroy
53 * Purpose:
54 * Deallocates all port rights and out-of-line memory
55 * found in a received message.
58 void
59 __mach_msg_destroy(msg)
60 mach_msg_header_t *msg;
62 mach_msg_bits_t mbits = msg->msgh_bits;
65 * The msgh_local_port field doesn't hold a port right.
66 * The receive operation consumes the destination port right.
69 mach_msg_destroy_port(msg->msgh_remote_port, MACH_MSGH_BITS_REMOTE(mbits));
71 if (mbits & MACH_MSGH_BITS_COMPLEX) {
72 vm_offset_t saddr;
73 vm_offset_t eaddr;
75 saddr = (vm_offset_t) (msg + 1);
76 eaddr = (vm_offset_t) msg + msg->msgh_size;
78 while (saddr < eaddr) {
79 mach_msg_type_long_t *type;
80 mach_msg_type_name_t name;
81 mach_msg_type_size_t size;
82 mach_msg_type_number_t number;
83 boolean_t is_inline;
84 vm_size_t length;
85 vm_offset_t addr;
87 type = (mach_msg_type_long_t *) saddr;
88 is_inline = type->msgtl_header.msgt_inline;
89 if (type->msgtl_header.msgt_longform) {
90 name = type->msgtl_name;
91 size = type->msgtl_size;
92 number = type->msgtl_number;
93 saddr += sizeof(mach_msg_type_long_t);
94 } else {
95 name = type->msgtl_header.msgt_name;
96 size = type->msgtl_header.msgt_size;
97 number = type->msgtl_header.msgt_number;
98 saddr += sizeof(mach_msg_type_t);
101 /* calculate length of data in bytes, rounding up */
102 length = ((((number * size) + 7) >> 3) + 3) &~ 3;
104 addr = is_inline ? saddr : * (vm_offset_t *) saddr;
106 if (MACH_MSG_TYPE_PORT_ANY(name)) {
107 mach_port_t *ports = (mach_port_t *) addr;
108 mach_msg_type_number_t i;
110 for (i = 0; i < number; i++)
111 mach_msg_destroy_port(*ports++, name);
114 if (is_inline) {
115 /* inline data sizes round up to int boundaries */
116 saddr += length;
117 } else {
118 mach_msg_destroy_memory(addr, length);
119 saddr += sizeof(vm_offset_t);
125 static void
126 mach_msg_destroy_port(port, type)
127 mach_port_t port;
128 mach_msg_type_name_t type;
130 if (MACH_PORT_VALID(port)) switch (type) {
131 case MACH_MSG_TYPE_PORT_SEND:
132 case MACH_MSG_TYPE_PORT_SEND_ONCE:
133 (void) __mach_port_deallocate(__mach_task_self(), port);
134 break;
136 case MACH_MSG_TYPE_PORT_RECEIVE:
137 (void) __mach_port_mod_refs(__mach_task_self(), port,
138 MACH_PORT_RIGHT_RECEIVE, -1);
139 break;
143 static void
144 mach_msg_destroy_memory(addr, size)
145 vm_offset_t addr;
146 vm_size_t size;
148 if (size > 0)
149 (void) __vm_deallocate(__mach_task_self(), addr, size);