* sysdeps/m68k/fpu/bits/mathinline.h: Don't define log2 as inline.
[glibc.git] / mach / msg-destroy.c
blob1e618df0bfb549f8bce5f33dcb25314bdd07d87c
1 /*
2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
4 * All Rights Reserved.
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.5 1997/06/21 01:40:07 drepper
30 * More 64bit changes.
32 * Revision 1.4 1996/11/15 19:44:43 thomas
33 * Tue Nov 12 16:58:41 1996 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu>
35 * * mach/mach.h (__mach_msg_destroy, mach_msg_destroy, __mach_msg):
36 * Provide prototypes.
38 * * mach/msg-destroy.c (mach_msg_destroy_port,
39 * mach_msg_destroy_memory): Use prototype syntax.
40 * * hurd/hurdmalloc.c (more_memory, malloc_fork_prepare,
41 * malloc_fork_parent, malloc_fork_child): Likewise.
43 * Revision 1.3 1995/01/23 22:16:52 roland
44 * (mach_msg_destroy): Define as weak alias for __mach_msg_destroy.
46 * Revision 1.2 1993/08/03 06:13:18 roland
47 * entered into RCS
49 * Revision 2.4 91/05/14 17:53:15 mrt
50 * Correcting copyright
52 * Revision 2.3 91/02/14 14:17:43 mrt
53 * Added new Mach copyright
54 * [91/02/13 12:44:15 mrt]
56 * Revision 2.2 90/08/06 17:24:22 rpd
57 * Created.
61 #if 1
62 #include <mach.h>
63 #else
64 /* This is what CMU did, but that fails to declare some used functions. */
65 #include <mach/port.h>
66 #include <mach/message.h>
67 #include <mach_init.h>
68 #endif
70 static void mach_msg_destroy_port(mach_port_t, mach_msg_type_name_t);
71 static void mach_msg_destroy_memory(vm_offset_t, vm_size_t);
74 * Routine: mach_msg_destroy
75 * Purpose:
76 * Deallocates all port rights and out-of-line memory
77 * found in a received message.
80 void
81 __mach_msg_destroy(msg)
82 mach_msg_header_t *msg;
84 mach_msg_bits_t mbits = msg->msgh_bits;
87 * The msgh_local_port field doesn't hold a port right.
88 * The receive operation consumes the destination port right.
91 mach_msg_destroy_port(msg->msgh_remote_port, MACH_MSGH_BITS_REMOTE(mbits));
93 if (mbits & MACH_MSGH_BITS_COMPLEX) {
94 vm_offset_t saddr;
95 vm_offset_t eaddr;
97 saddr = (vm_offset_t) (msg + 1);
98 eaddr = (vm_offset_t) msg + msg->msgh_size;
100 while (saddr < eaddr) {
101 mach_msg_type_long_t *type;
102 mach_msg_type_name_t name;
103 mach_msg_type_size_t size;
104 mach_msg_type_number_t number;
105 boolean_t is_inline;
106 vm_size_t length;
107 vm_offset_t addr;
109 type = (mach_msg_type_long_t *) saddr;
110 is_inline = type->msgtl_header.msgt_inline;
111 if (type->msgtl_header.msgt_longform) {
112 name = type->msgtl_name;
113 size = type->msgtl_size;
114 number = type->msgtl_number;
115 saddr += sizeof(mach_msg_type_long_t);
116 } else {
117 name = type->msgtl_header.msgt_name;
118 size = type->msgtl_header.msgt_size;
119 number = type->msgtl_header.msgt_number;
120 saddr += sizeof(mach_msg_type_t);
123 /* calculate length of data in bytes, rounding up */
124 length = (((((number * size) + 7) >> 3) + sizeof (int) - 1)
125 &~ (sizeof (int) - 1));
127 addr = is_inline ? saddr : * (vm_offset_t *) saddr;
129 if (MACH_MSG_TYPE_PORT_ANY(name)) {
130 mach_port_t *ports = (mach_port_t *) addr;
131 mach_msg_type_number_t i;
133 for (i = 0; i < number; i++)
134 mach_msg_destroy_port(*ports++, name);
137 if (is_inline) {
138 /* inline data sizes round up to int boundaries */
139 saddr += length;
140 } else {
141 mach_msg_destroy_memory(addr, length);
142 saddr += sizeof(vm_offset_t);
148 weak_alias (__mach_msg_destroy, mach_msg_destroy)
150 static void
151 mach_msg_destroy_port(port, type)
152 mach_port_t port;
153 mach_msg_type_name_t type;
155 if (MACH_PORT_VALID(port)) switch (type) {
156 case MACH_MSG_TYPE_PORT_SEND:
157 case MACH_MSG_TYPE_PORT_SEND_ONCE:
158 (void) __mach_port_deallocate(__mach_task_self(), port);
159 break;
161 case MACH_MSG_TYPE_PORT_RECEIVE:
162 (void) __mach_port_mod_refs(__mach_task_self(), port,
163 MACH_PORT_RIGHT_RECEIVE, -1);
164 break;
168 static void
169 mach_msg_destroy_memory(addr, size)
170 vm_offset_t addr;
171 vm_size_t size;
173 if (size > 0)
174 (void) __vm_deallocate(__mach_task_self(), addr, size);