1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
/*
* Mach Operating System
* Copyright (c) 1993-1989 Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*/
/*
* HISTORY
* 26-Feb-94 Johannes Helander (jvh) at Helsinki University of Technology
* Added mach_put_reply_port. mig_dealloc_reply_port now takes the
* port as an argument.
*
* $Log: mig_support.c,v $
* Revision 2.8 93/01/24 13:27:14 danner
* Corrrected include of mach/mach.h to mach.h
* [93/01/16 mrt]
*
* Revision 2.7 93/01/14 18:05:37 danner
* Converted file to ANSI C.
* Made argument to mig_init a void * for compatibility with
* mig_init in libmach.
* [92/12/18 pds]
*
* Revision 2.6 91/05/14 17:57:41 mrt
* Correcting copyright
*
* Revision 2.5 91/02/14 14:20:30 mrt
* Added new Mach copyright
* [91/02/13 12:41:26 mrt]
*
* Revision 2.4 90/08/07 14:31:41 rpd
* Removed RCS keyword nonsense.
*
* Revision 2.3 90/08/07 14:27:48 rpd
* When we recycle the global reply port by giving it to the first
* cthread, clear the global reply port. This will take care of
* someone accidently calling this twice.
* [90/08/07 rwd]
*
* Revision 2.2 90/06/02 15:14:04 rpd
* Converted to new IPC.
* [90/03/20 20:56:50 rpd]
*
* Revision 2.1 89/08/03 17:09:50 rwd
* Created.
*
* 18-Jan-89 David Golub (dbg) at Carnegie-Mellon University
* Replaced task_data() by thread_reply().
*
*
* 27-Aug-87 Eric Cooper (ecc) at Carnegie Mellon University
* Changed mig_support.c to avoid deadlock that can occur
* if tracing is turned on during calls to mig_get_reply_port().
*
* 10-Aug-87 Eric Cooper (ecc) at Carnegie Mellon University
* Changed mig_support.c to use MACH_CALL.
* Changed "is_init" to "multithreaded" and reversed its sense.
*
* 30-Jul-87 Mary Thompson (mrt) at Carnegie Mellon University
* Created.
*/
/*
* File: mig_support.c
* Author: Mary R. Thompson, Carnegie Mellon University
* Date: July, 1987
*
* Routines to set and deallocate the mig reply port for the current thread.
* Called from mig-generated interfaces.
*
*/
#include <mach.h>
#include <mach/mig_support.h>
#include <mach/mach_traps.h>
#include <cthreads.h>
#include "cthread_internals.h"
private boolean_t multithreaded = FALSE;
/* use a global reply port before becoming multi-threaded */
private mach_port_t mig_reply_port = MACH_PORT_NULL;
/*
* Called by mach_init with 0 before cthread_init is
* called and again with initial cproc at end of cthread_init.
*/
void
mig_init(register void *initial)
{
if (initial == NO_CPROC) {
/* called from mach_init before cthread_init,
possibly after a fork. clear global reply port. */
multithreaded = FALSE;
mig_reply_port = MACH_PORT_NULL;
} else {
/* recycle global reply port as this cthread's reply port */
multithreaded = TRUE;
((cproc_t) initial)->reply_port = mig_reply_port;
mig_reply_port = MACH_PORT_NULL;
}
}
/*
* Called by mig interface code whenever a reply port is needed.
*/
mach_port_t
mig_get_reply_port(void)
{
register mach_port_t reply_port;
if (multithreaded) {
register cproc_t self;
self = cproc_self();
ASSERT(self != NO_CPROC);
if ((reply_port = self->reply_port) == MACH_PORT_NULL)
self->reply_port = reply_port = mach_reply_port();
} else {
if ((reply_port = mig_reply_port) == MACH_PORT_NULL)
mig_reply_port = reply_port = mach_reply_port();
}
return reply_port;
}
/*
* Called by mig interface code after a timeout on the reply port.
* May also be called by user.
*/
/*ARGSUSED*/
void
mig_dealloc_reply_port(mach_port_t p)
{
register mach_port_t reply_port;
if (multithreaded) {
register cproc_t self;
self = cproc_self();
ASSERT(self != NO_CPROC);
reply_port = self->reply_port;
self->reply_port = MACH_PORT_NULL;
} else {
reply_port = mig_reply_port;
mig_reply_port = MACH_PORT_NULL;
}
(void) mach_port_mod_refs(mach_task_self(), reply_port,
MACH_PORT_RIGHT_RECEIVE, -1);
}
/*
* Called by mig interfaces when done with a port.
* Used to provide the same interface as needed when a custom
* allocator is used.
*/
/*ARGSUSED*/
void
mig_put_reply_port(mach_port_t port)
{
/* Do nothing */
}
void
__mig_init(register void *initial)
{
mig_init (initial);
}
mach_port_t
__mig_get_reply_port(void)
{
return mig_get_reply_port();
}
void
__mig_dealloc_reply_port(mach_port_t p)
{
mig_dealloc_reply_port(p);
}
void
__mig_put_reply_port(mach_port_t port)
{
mig_put_reply_port(port);
}
void
__mig_dealloc_reply_port (void)
{
mig_dealloc_reply_port ();
}
/* XXX shouldn't need these */
/* Called by MiG to allocate space. */
void
__mig_allocate (vm_address_t *addr,
vm_size_t size)
{
if (__vm_allocate (__mach_task_self (), addr, size, 1) != KERN_SUCCESS)
*addr = 0;
}
/* Called by MiG to deallocate space. */
void
__mig_deallocate (vm_address_t addr,
vm_size_t size)
{
(void) __vm_deallocate (__mach_task_self (), addr, size);
}
|