2004-01-02 01:48:54 +03:00
|
|
|
/* $NetBSD: mach_notify.c,v 1.15 2004/01/01 22:48:54 manu Exp $ */
|
2003-03-29 14:04:08 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Emmanuel Dreyfus
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2004-01-02 01:48:54 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: mach_notify.c,v 1.15 2004/01/01 22:48:54 manu Exp $");
|
2003-04-05 23:27:51 +04:00
|
|
|
|
|
|
|
#include "opt_ktrace.h"
|
2003-03-29 14:04:08 +03:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/signal.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
|
|
|
#include <compat/mach/mach_types.h>
|
|
|
|
#include <compat/mach/mach_exec.h>
|
First work on Mach exceptions. Things that can turn into signals on UNIX
may turn into exceptions on Mach: a small message sent by the kernel to
the task that requested the exception.
On Darwin, when an exception is sent, no signal can be delivered.
TODO: more exceptions: arithmetic, bad instructions, emulation, s
software, and syscalls (plain and Mach). There is also RPC alert, but
I have no idea about what it is.
While we are there, remove some user ktrace in notification code, and add
a NODEF qualifier in mach_services.master: it will be used for notifications
and exceptions, where the kernel is always client and never server: we
don't want the message to be displayed as "unimplemented xxx" in kdump (thus
UNIMPL is not good), but we don't want to generate the server prototype
(therefore, STD is not good either). NODEF will declare it normally in the
name tables without creating the prototype.
2003-11-17 04:52:14 +03:00
|
|
|
#include <compat/mach/mach_thread.h>
|
2003-03-29 14:04:08 +03:00
|
|
|
#include <compat/mach/mach_notify.h>
|
2003-11-18 04:40:18 +03:00
|
|
|
#include <compat/mach/mach_message.h>
|
|
|
|
#include <compat/mach/mach_services.h>
|
2003-03-29 14:04:08 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
mach_notify_port_destroyed(l, mr)
|
|
|
|
struct lwp *l;
|
|
|
|
struct mach_right *mr;
|
|
|
|
{
|
|
|
|
struct mach_port *mp;
|
|
|
|
mach_notify_port_destroyed_request_t *req;
|
|
|
|
|
|
|
|
if (mr->mr_notify_destroyed == NULL)
|
|
|
|
return;
|
2004-01-02 01:48:54 +03:00
|
|
|
|
2003-03-29 14:04:08 +03:00
|
|
|
mp = mr->mr_notify_destroyed->mr_port;
|
|
|
|
|
2003-12-03 21:40:07 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if ((mp == NULL) || (mp->mp_recv == NULL)) {
|
|
|
|
printf("mach_notify_port_destroyed: bad port or receiver\n");
|
2003-03-29 14:04:08 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-01-02 01:48:54 +03:00
|
|
|
MACH_PORT_REF(mp);
|
|
|
|
|
2003-03-29 14:04:08 +03:00
|
|
|
req = malloc(sizeof(*req), M_EMULDATA, M_WAITOK | M_ZERO);
|
|
|
|
|
|
|
|
req->req_msgh.msgh_bits =
|
|
|
|
MACH_MSGH_REPLY_LOCAL_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE);
|
2003-04-05 23:27:51 +04:00
|
|
|
req->req_msgh.msgh_size = sizeof(*req) - sizeof(req->req_trailer);
|
2003-03-29 14:04:08 +03:00
|
|
|
req->req_msgh.msgh_local_port = mr->mr_notify_destroyed->mr_name;
|
First work on Mach exceptions. Things that can turn into signals on UNIX
may turn into exceptions on Mach: a small message sent by the kernel to
the task that requested the exception.
On Darwin, when an exception is sent, no signal can be delivered.
TODO: more exceptions: arithmetic, bad instructions, emulation, s
software, and syscalls (plain and Mach). There is also RPC alert, but
I have no idea about what it is.
While we are there, remove some user ktrace in notification code, and add
a NODEF qualifier in mach_services.master: it will be used for notifications
and exceptions, where the kernel is always client and never server: we
don't want the message to be displayed as "unimplemented xxx" in kdump (thus
UNIMPL is not good), but we don't want to generate the server prototype
(therefore, STD is not good either). NODEF will declare it normally in the
name tables without creating the prototype.
2003-11-17 04:52:14 +03:00
|
|
|
req->req_msgh.msgh_id = MACH_NOTIFY_DESTROYED_MSGID;
|
2003-03-29 14:04:08 +03:00
|
|
|
req->req_body.msgh_descriptor_count = 1;
|
|
|
|
req->req_rights.name = mr->mr_name;
|
2003-12-09 14:29:01 +03:00
|
|
|
|
|
|
|
mach_set_trailer(req, sizeof(*req));
|
2003-03-29 14:04:08 +03:00
|
|
|
|
|
|
|
(void)mach_message_get((mach_msg_header_t *)req, sizeof(*req), mp, l);
|
2003-04-05 23:27:51 +04:00
|
|
|
#ifdef DEBUG_MACH_MSG
|
|
|
|
printf("pid %d: message queued on port %p (%d) [%p]\n",
|
|
|
|
l->l_proc->p_pid, mp, req->req_msgh.msgh_id,
|
|
|
|
mp->mp_recv->mr_sethead);
|
|
|
|
#endif
|
2003-03-29 14:04:08 +03:00
|
|
|
wakeup(mp->mp_recv->mr_sethead);
|
|
|
|
|
2004-01-02 01:48:54 +03:00
|
|
|
MACH_PORT_UNREF(mp);
|
|
|
|
|
2003-03-29 14:04:08 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mach_notify_port_no_senders(l, mr)
|
|
|
|
struct lwp *l;
|
|
|
|
struct mach_right *mr;
|
|
|
|
{
|
|
|
|
struct mach_port *mp;
|
|
|
|
mach_notify_port_no_senders_request_t *req;
|
|
|
|
|
|
|
|
if ((mr->mr_notify_no_senders == NULL) ||
|
|
|
|
(mr->mr_notify_no_senders->mr_port == NULL))
|
|
|
|
return;
|
|
|
|
mp = mr->mr_notify_no_senders->mr_port;
|
|
|
|
|
2003-12-03 21:40:07 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if ((mp == NULL) ||
|
|
|
|
(mp->mp_recv == NULL) ||
|
|
|
|
(mp->mp_datatype != MACH_MP_NOTIFY_SYNC)) {
|
|
|
|
printf("mach_notify_port_no_senders: bad port or reciever\n");
|
2003-03-29 14:04:08 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2004-01-02 01:48:54 +03:00
|
|
|
MACH_PORT_REF(mp);
|
2003-03-29 14:04:08 +03:00
|
|
|
if ((int)mp->mp_data >= mr->mr_refcount)
|
2004-01-02 01:48:54 +03:00
|
|
|
goto out;
|
2003-03-29 14:04:08 +03:00
|
|
|
|
|
|
|
req = malloc(sizeof(*req), M_EMULDATA, M_WAITOK | M_ZERO);
|
|
|
|
|
|
|
|
req->req_msgh.msgh_bits =
|
|
|
|
MACH_MSGH_REPLY_LOCAL_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE);
|
2003-04-05 23:27:51 +04:00
|
|
|
req->req_msgh.msgh_size = sizeof(*req) - sizeof(req->req_trailer);
|
2003-03-29 14:04:08 +03:00
|
|
|
req->req_msgh.msgh_local_port = mr->mr_notify_no_senders->mr_name;
|
First work on Mach exceptions. Things that can turn into signals on UNIX
may turn into exceptions on Mach: a small message sent by the kernel to
the task that requested the exception.
On Darwin, when an exception is sent, no signal can be delivered.
TODO: more exceptions: arithmetic, bad instructions, emulation, s
software, and syscalls (plain and Mach). There is also RPC alert, but
I have no idea about what it is.
While we are there, remove some user ktrace in notification code, and add
a NODEF qualifier in mach_services.master: it will be used for notifications
and exceptions, where the kernel is always client and never server: we
don't want the message to be displayed as "unimplemented xxx" in kdump (thus
UNIMPL is not good), but we don't want to generate the server prototype
(therefore, STD is not good either). NODEF will declare it normally in the
name tables without creating the prototype.
2003-11-17 04:52:14 +03:00
|
|
|
req->req_msgh.msgh_id = MACH_NOTIFY_NO_SENDERS_MSGID;
|
2003-03-29 14:04:08 +03:00
|
|
|
req->req_mscount = mr->mr_refcount;
|
2003-12-09 14:29:01 +03:00
|
|
|
|
|
|
|
mach_set_trailer(req, sizeof(*req));
|
2003-03-29 14:04:08 +03:00
|
|
|
|
|
|
|
(void)mach_message_get((mach_msg_header_t *)req, sizeof(*req), mp, l);
|
2003-04-05 23:27:51 +04:00
|
|
|
#ifdef DEBUG_MACH_MSG
|
|
|
|
printf("pid %d: message queued on port %p (%d) [%p]\n",
|
|
|
|
l->l_proc->p_pid, mp, req->req_msgh.msgh_id,
|
|
|
|
mp->mp_recv->mr_sethead);
|
|
|
|
#endif
|
2003-03-29 14:04:08 +03:00
|
|
|
wakeup(mp->mp_recv->mr_sethead);
|
|
|
|
|
2004-01-02 01:48:54 +03:00
|
|
|
out:
|
|
|
|
MACH_PORT_UNREF(mp);
|
2003-03-29 14:04:08 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mach_notify_port_dead_name(l, mr)
|
|
|
|
struct lwp *l;
|
|
|
|
struct mach_right *mr;
|
|
|
|
{
|
|
|
|
struct mach_port *mp;
|
|
|
|
mach_notify_port_dead_name_request_t *req;
|
|
|
|
|
|
|
|
if ((mr->mr_notify_dead_name == NULL) ||
|
|
|
|
(mr->mr_notify_dead_name->mr_port == NULL))
|
|
|
|
return;
|
2004-01-02 01:48:54 +03:00
|
|
|
mp = mr->mr_notify_dead_name->mr_port;
|
2003-03-29 14:04:08 +03:00
|
|
|
|
2003-12-03 21:40:07 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if ((mp == NULL) || (mp->mp_recv)) {
|
|
|
|
printf("mach_notify_port_dead_name: bad port or reciever\n");
|
2003-03-29 14:04:08 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2004-01-02 01:48:54 +03:00
|
|
|
MACH_PORT_REF(mp);
|
2003-03-29 14:04:08 +03:00
|
|
|
|
|
|
|
req = malloc(sizeof(*req), M_EMULDATA, M_WAITOK | M_ZERO);
|
|
|
|
|
|
|
|
req->req_msgh.msgh_bits =
|
|
|
|
MACH_MSGH_REPLY_LOCAL_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE);
|
2003-04-05 23:27:51 +04:00
|
|
|
req->req_msgh.msgh_size = sizeof(*req) - sizeof(req->req_trailer);
|
2003-03-29 14:04:08 +03:00
|
|
|
req->req_msgh.msgh_local_port = mr->mr_notify_dead_name->mr_name;
|
First work on Mach exceptions. Things that can turn into signals on UNIX
may turn into exceptions on Mach: a small message sent by the kernel to
the task that requested the exception.
On Darwin, when an exception is sent, no signal can be delivered.
TODO: more exceptions: arithmetic, bad instructions, emulation, s
software, and syscalls (plain and Mach). There is also RPC alert, but
I have no idea about what it is.
While we are there, remove some user ktrace in notification code, and add
a NODEF qualifier in mach_services.master: it will be used for notifications
and exceptions, where the kernel is always client and never server: we
don't want the message to be displayed as "unimplemented xxx" in kdump (thus
UNIMPL is not good), but we don't want to generate the server prototype
(therefore, STD is not good either). NODEF will declare it normally in the
name tables without creating the prototype.
2003-11-17 04:52:14 +03:00
|
|
|
req->req_msgh.msgh_id = MACH_NOTIFY_DEAD_NAME_MSGID;
|
2003-03-29 14:04:08 +03:00
|
|
|
req->req_name = mr->mr_name;
|
2003-12-09 14:29:01 +03:00
|
|
|
|
|
|
|
mach_set_trailer(req, sizeof(*req));
|
2003-03-29 14:04:08 +03:00
|
|
|
|
|
|
|
mr->mr_refcount++;
|
|
|
|
|
|
|
|
(void)mach_message_get((mach_msg_header_t *)req, sizeof(*req), mp, l);
|
2003-04-05 23:27:51 +04:00
|
|
|
#ifdef DEBUG_MACH_MSG
|
|
|
|
printf("pid %d: message queued on port %p (%d) [%p]\n",
|
|
|
|
l->l_proc->p_pid, mp, req->req_msgh.msgh_id,
|
|
|
|
mp->mp_recv->mr_sethead);
|
|
|
|
#endif
|
2003-03-29 14:04:08 +03:00
|
|
|
wakeup(mp->mp_recv->mr_sethead);
|
2004-01-02 01:48:54 +03:00
|
|
|
MACH_PORT_UNREF(mp);
|
2003-03-29 14:04:08 +03:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|