The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/compat/mach/mach_notify.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: mach_notify.c,v 1.20 2008/04/28 20:23:44 martin 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  *
   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.
   30  */
   31 
   32 #include <sys/cdefs.h>
   33 __KERNEL_RCSID(0, "$NetBSD: mach_notify.c,v 1.20 2008/04/28 20:23:44 martin Exp $");
   34 
   35 #include <sys/types.h>
   36 #include <sys/param.h>
   37 #include <sys/signal.h>
   38 #include <sys/proc.h>
   39 #include <sys/malloc.h>
   40 
   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>
   47 
   48 void
   49 mach_notify_port_destroyed(struct lwp *l, struct mach_right *mr)
   50 {
   51         struct mach_port *mp;
   52         mach_notify_port_destroyed_request_t *req;
   53 
   54         if (mr->mr_notify_destroyed == NULL)
   55                 return;
   56 
   57         mp = mr->mr_notify_destroyed->mr_port;
   58 
   59 #ifdef DIAGNOSTIC
   60         if ((mp == NULL) || (mp->mp_recv == NULL)) {
   61                 printf("mach_notify_port_destroyed: bad port or receiver\n");
   62                 return;
   63         }
   64 #endif
   65 
   66         MACH_PORT_REF(mp);
   67 
   68         req = malloc(sizeof(*req), M_EMULDATA, M_WAITOK | M_ZERO);
   69 
   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;
   77 
   78         mach_set_trailer(req, sizeof(*req));
   79 
   80         (void)mach_message_get((mach_msg_header_t *)req, sizeof(*req), mp, l);
   81 #ifdef DEBUG_MACH_MSG
   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);
   85 #endif
   86         wakeup(mp->mp_recv->mr_sethead);
   87 
   88         MACH_PORT_UNREF(mp);
   89 
   90         return;
   91 }
   92 
   93 void
   94 mach_notify_port_no_senders(struct lwp *l, struct mach_right *mr)
   95 {
   96         struct mach_port *mp;
   97         mach_notify_port_no_senders_request_t *req;
   98 
   99         if ((mr->mr_notify_no_senders == NULL) ||
  100             (mr->mr_notify_no_senders->mr_port == NULL))
  101                 return;
  102         mp = mr->mr_notify_no_senders->mr_port;
  103 
  104 #ifdef DIAGNOSTIC
  105         if ((mp == NULL) ||
  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");
  109                 return;
  110         }
  111 #endif
  112         MACH_PORT_REF(mp);
  113         if ((int)mp->mp_data >= mr->mr_refcount)
  114                 goto out;
  115 
  116         req = malloc(sizeof(*req), M_EMULDATA, M_WAITOK | M_ZERO);
  117 
  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;
  124 
  125         mach_set_trailer(req, sizeof(*req));
  126 
  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);
  132 #endif
  133         wakeup(mp->mp_recv->mr_sethead);
  134 
  135 out:
  136         MACH_PORT_UNREF(mp);
  137         return;
  138 }
  139 
  140 void
  141 mach_notify_port_dead_name(struct lwp *l, struct mach_right *mr)
  142 {
  143         struct mach_port *mp;
  144         mach_notify_port_dead_name_request_t *req;
  145 
  146         if ((mr->mr_notify_dead_name == NULL) ||
  147             (mr->mr_notify_dead_name->mr_port == NULL))
  148                 return;
  149         mp = mr->mr_notify_dead_name->mr_port;
  150 
  151 #ifdef DIAGNOSTIC
  152         if ((mp == NULL) || (mp->mp_recv)) {
  153                 printf("mach_notify_port_dead_name: bad port or reciever\n");
  154                 return;
  155         }
  156 #endif
  157         MACH_PORT_REF(mp);
  158 
  159         req = malloc(sizeof(*req), M_EMULDATA, M_WAITOK | M_ZERO);
  160 
  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;
  167 
  168         mach_set_trailer(req, sizeof(*req));
  169 
  170         mr->mr_refcount++;
  171 
  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);
  177 #endif
  178         wakeup(mp->mp_recv->mr_sethead);
  179         MACH_PORT_UNREF(mp);
  180 
  181         return;
  182 }

Cache object: 537e6ed13133b2e6d373b2f838843ba6


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.