1 /* $NetBSD: mach_notify.c,v 1.19 2007/12/08 18:36:15 dsl Exp $ */
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: mach_notify.c,v 1.19 2007/12/08 18:36:15 dsl Exp $");
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <sys/signal.h>
39 #include <sys/malloc.h>
41 #include <compat/mach/mach_types.h>
42 #include <compat/mach/mach_exec.h>
43 #include <compat/mach/mach_thread.h>
44 #include <compat/mach/mach_notify.h>
45 #include <compat/mach/mach_message.h>
46 #include <compat/mach/mach_services.h>
49 mach_notify_port_destroyed(struct lwp
*l
, struct mach_right
*mr
)
52 mach_notify_port_destroyed_request_t
*req
;
54 if (mr
->mr_notify_destroyed
== NULL
)
57 mp
= mr
->mr_notify_destroyed
->mr_port
;
60 if ((mp
== NULL
) || (mp
->mp_recv
== NULL
)) {
61 printf("mach_notify_port_destroyed: bad port or receiver\n");
68 req
= malloc(sizeof(*req
), M_EMULDATA
, M_WAITOK
| M_ZERO
);
70 req
->req_msgh
.msgh_bits
=
71 MACH_MSGH_REPLY_LOCAL_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE
);
72 req
->req_msgh
.msgh_size
= sizeof(*req
) - sizeof(req
->req_trailer
);
73 req
->req_msgh
.msgh_local_port
= mr
->mr_notify_destroyed
->mr_name
;
74 req
->req_msgh
.msgh_id
= MACH_NOTIFY_DESTROYED_MSGID
;
75 req
->req_body
.msgh_descriptor_count
= 1;
76 req
->req_rights
.name
= mr
->mr_name
;
78 mach_set_trailer(req
, sizeof(*req
));
80 (void)mach_message_get((mach_msg_header_t
*)req
, sizeof(*req
), mp
, l
);
82 printf("pid %d: message queued on port %p (%d) [%p]\n",
83 l
->l_proc
->p_pid
, mp
, req
->req_msgh
.msgh_id
,
84 mp
->mp_recv
->mr_sethead
);
86 wakeup(mp
->mp_recv
->mr_sethead
);
94 mach_notify_port_no_senders(struct lwp
*l
, struct mach_right
*mr
)
97 mach_notify_port_no_senders_request_t
*req
;
99 if ((mr
->mr_notify_no_senders
== NULL
) ||
100 (mr
->mr_notify_no_senders
->mr_port
== NULL
))
102 mp
= mr
->mr_notify_no_senders
->mr_port
;
106 (mp
->mp_recv
== NULL
) ||
107 (mp
->mp_datatype
!= MACH_MP_NOTIFY_SYNC
)) {
108 printf("mach_notify_port_no_senders: bad port or reciever\n");
113 if ((int)mp
->mp_data
>= mr
->mr_refcount
)
116 req
= malloc(sizeof(*req
), M_EMULDATA
, M_WAITOK
| M_ZERO
);
118 req
->req_msgh
.msgh_bits
=
119 MACH_MSGH_REPLY_LOCAL_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE
);
120 req
->req_msgh
.msgh_size
= sizeof(*req
) - sizeof(req
->req_trailer
);
121 req
->req_msgh
.msgh_local_port
= mr
->mr_notify_no_senders
->mr_name
;
122 req
->req_msgh
.msgh_id
= MACH_NOTIFY_NO_SENDERS_MSGID
;
123 req
->req_mscount
= mr
->mr_refcount
;
125 mach_set_trailer(req
, sizeof(*req
));
127 (void)mach_message_get((mach_msg_header_t
*)req
, sizeof(*req
), mp
, l
);
128 #ifdef DEBUG_MACH_MSG
129 printf("pid %d: message queued on port %p (%d) [%p]\n",
130 l
->l_proc
->p_pid
, mp
, req
->req_msgh
.msgh_id
,
131 mp
->mp_recv
->mr_sethead
);
133 wakeup(mp
->mp_recv
->mr_sethead
);
141 mach_notify_port_dead_name(struct lwp
*l
, struct mach_right
*mr
)
143 struct mach_port
*mp
;
144 mach_notify_port_dead_name_request_t
*req
;
146 if ((mr
->mr_notify_dead_name
== NULL
) ||
147 (mr
->mr_notify_dead_name
->mr_port
== NULL
))
149 mp
= mr
->mr_notify_dead_name
->mr_port
;
152 if ((mp
== NULL
) || (mp
->mp_recv
)) {
153 printf("mach_notify_port_dead_name: bad port or reciever\n");
159 req
= malloc(sizeof(*req
), M_EMULDATA
, M_WAITOK
| M_ZERO
);
161 req
->req_msgh
.msgh_bits
=
162 MACH_MSGH_REPLY_LOCAL_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE
);
163 req
->req_msgh
.msgh_size
= sizeof(*req
) - sizeof(req
->req_trailer
);
164 req
->req_msgh
.msgh_local_port
= mr
->mr_notify_dead_name
->mr_name
;
165 req
->req_msgh
.msgh_id
= MACH_NOTIFY_DEAD_NAME_MSGID
;
166 req
->req_name
= mr
->mr_name
;
168 mach_set_trailer(req
, sizeof(*req
));
172 (void)mach_message_get((mach_msg_header_t
*)req
, sizeof(*req
), mp
, l
);
173 #ifdef DEBUG_MACH_MSG
174 printf("pid %d: message queued on port %p (%d) [%p]\n",
175 l
->l_proc
->p_pid
, mp
, req
->req_msgh
.msgh_id
,
176 mp
->mp_recv
->mr_sethead
);
178 wakeup(mp
->mp_recv
->mr_sethead
);