1 /* $NetBSD: mach_notify.c,v 1.18 2006/03/07 03:32:06 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Emmanuel Dreyfus
9 *
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.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: mach_notify.c,v 1.18 2006/03/07 03:32:06 thorpej Exp $");
41
42 #include <sys/types.h>
43 #include <sys/param.h>
44 #include <sys/signal.h>
45 #include <sys/proc.h>
46 #include <sys/malloc.h>
47
48 #include <compat/mach/mach_types.h>
49 #include <compat/mach/mach_exec.h>
50 #include <compat/mach/mach_thread.h>
51 #include <compat/mach/mach_notify.h>
52 #include <compat/mach/mach_message.h>
53 #include <compat/mach/mach_services.h>
54
55 void
56 mach_notify_port_destroyed(l, mr)
57 struct lwp *l;
58 struct mach_right *mr;
59 {
60 struct mach_port *mp;
61 mach_notify_port_destroyed_request_t *req;
62
63 if (mr->mr_notify_destroyed == NULL)
64 return;
65
66 mp = mr->mr_notify_destroyed->mr_port;
67
68 #ifdef DIAGNOSTIC
69 if ((mp == NULL) || (mp->mp_recv == NULL)) {
70 printf("mach_notify_port_destroyed: bad port or receiver\n");
71 return;
72 }
73 #endif
74
75 MACH_PORT_REF(mp);
76
77 req = malloc(sizeof(*req), M_EMULDATA, M_WAITOK | M_ZERO);
78
79 req->req_msgh.msgh_bits =
80 MACH_MSGH_REPLY_LOCAL_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE);
81 req->req_msgh.msgh_size = sizeof(*req) - sizeof(req->req_trailer);
82 req->req_msgh.msgh_local_port = mr->mr_notify_destroyed->mr_name;
83 req->req_msgh.msgh_id = MACH_NOTIFY_DESTROYED_MSGID;
84 req->req_body.msgh_descriptor_count = 1;
85 req->req_rights.name = mr->mr_name;
86
87 mach_set_trailer(req, sizeof(*req));
88
89 (void)mach_message_get((mach_msg_header_t *)req, sizeof(*req), mp, l);
90 #ifdef DEBUG_MACH_MSG
91 printf("pid %d: message queued on port %p (%d) [%p]\n",
92 l->l_proc->p_pid, mp, req->req_msgh.msgh_id,
93 mp->mp_recv->mr_sethead);
94 #endif
95 wakeup(mp->mp_recv->mr_sethead);
96
97 MACH_PORT_UNREF(mp);
98
99 return;
100 }
101
102 void
103 mach_notify_port_no_senders(l, mr)
104 struct lwp *l;
105 struct mach_right *mr;
106 {
107 struct mach_port *mp;
108 mach_notify_port_no_senders_request_t *req;
109
110 if ((mr->mr_notify_no_senders == NULL) ||
111 (mr->mr_notify_no_senders->mr_port == NULL))
112 return;
113 mp = mr->mr_notify_no_senders->mr_port;
114
115 #ifdef DIAGNOSTIC
116 if ((mp == NULL) ||
117 (mp->mp_recv == NULL) ||
118 (mp->mp_datatype != MACH_MP_NOTIFY_SYNC)) {
119 printf("mach_notify_port_no_senders: bad port or reciever\n");
120 return;
121 }
122 #endif
123 MACH_PORT_REF(mp);
124 if ((int)mp->mp_data >= mr->mr_refcount)
125 goto out;
126
127 req = malloc(sizeof(*req), M_EMULDATA, M_WAITOK | M_ZERO);
128
129 req->req_msgh.msgh_bits =
130 MACH_MSGH_REPLY_LOCAL_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE);
131 req->req_msgh.msgh_size = sizeof(*req) - sizeof(req->req_trailer);
132 req->req_msgh.msgh_local_port = mr->mr_notify_no_senders->mr_name;
133 req->req_msgh.msgh_id = MACH_NOTIFY_NO_SENDERS_MSGID;
134 req->req_mscount = mr->mr_refcount;
135
136 mach_set_trailer(req, sizeof(*req));
137
138 (void)mach_message_get((mach_msg_header_t *)req, sizeof(*req), mp, l);
139 #ifdef DEBUG_MACH_MSG
140 printf("pid %d: message queued on port %p (%d) [%p]\n",
141 l->l_proc->p_pid, mp, req->req_msgh.msgh_id,
142 mp->mp_recv->mr_sethead);
143 #endif
144 wakeup(mp->mp_recv->mr_sethead);
145
146 out:
147 MACH_PORT_UNREF(mp);
148 return;
149 }
150
151 void
152 mach_notify_port_dead_name(l, mr)
153 struct lwp *l;
154 struct mach_right *mr;
155 {
156 struct mach_port *mp;
157 mach_notify_port_dead_name_request_t *req;
158
159 if ((mr->mr_notify_dead_name == NULL) ||
160 (mr->mr_notify_dead_name->mr_port == NULL))
161 return;
162 mp = mr->mr_notify_dead_name->mr_port;
163
164 #ifdef DIAGNOSTIC
165 if ((mp == NULL) || (mp->mp_recv)) {
166 printf("mach_notify_port_dead_name: bad port or reciever\n");
167 return;
168 }
169 #endif
170 MACH_PORT_REF(mp);
171
172 req = malloc(sizeof(*req), M_EMULDATA, M_WAITOK | M_ZERO);
173
174 req->req_msgh.msgh_bits =
175 MACH_MSGH_REPLY_LOCAL_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE);
176 req->req_msgh.msgh_size = sizeof(*req) - sizeof(req->req_trailer);
177 req->req_msgh.msgh_local_port = mr->mr_notify_dead_name->mr_name;
178 req->req_msgh.msgh_id = MACH_NOTIFY_DEAD_NAME_MSGID;
179 req->req_name = mr->mr_name;
180
181 mach_set_trailer(req, sizeof(*req));
182
183 mr->mr_refcount++;
184
185 (void)mach_message_get((mach_msg_header_t *)req, sizeof(*req), mp, l);
186 #ifdef DEBUG_MACH_MSG
187 printf("pid %d: message queued on port %p (%d) [%p]\n",
188 l->l_proc->p_pid, mp, req->req_msgh.msgh_id,
189 mp->mp_recv->mr_sethead);
190 #endif
191 wakeup(mp->mp_recv->mr_sethead);
192 MACH_PORT_UNREF(mp);
193
194 return;
195 }
Cache object: cff83a61f67ee719e0e5653da66cc9f1
|