X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/ff6e181ae92fc6f1e89841290f461d1f2f9badd9..d9a64523371fa019c4575bb400cbbc3a50ac9903:/osfmk/kern/host_notify.c diff --git a/osfmk/kern/host_notify.c b/osfmk/kern/host_notify.c index 7d407e63c..a69f109b4 100644 --- a/osfmk/kern/host_notify.c +++ b/osfmk/kern/host_notify.c @@ -1,14 +1,19 @@ /* - * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2003-2009 Apple Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER @@ -18,15 +23,7 @@ * Please see the License for the specific language governing rights and * limitations under the License. * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. - * - * HISTORY - * - * 16 January 2003 (debo) - * Created. + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ #include @@ -40,13 +37,19 @@ #include "mach/host_notify_reply.h" +decl_lck_mtx_data(,host_notify_lock) + +lck_mtx_ext_t host_notify_lock_ext; +lck_grp_t host_notify_lock_grp; +lck_attr_t host_notify_lock_attr; +static lck_grp_attr_t host_notify_lock_grp_attr; static zone_t host_notify_zone; -decl_mutex_data(static,host_notify_lock) static queue_head_t host_notify_queue[HOST_NOTIFY_TYPE_MAX+1]; static mach_msg_id_t host_notify_replyid[HOST_NOTIFY_TYPE_MAX+1] = - { HOST_CALENDAR_CHANGED_REPLYID }; + { HOST_CALENDAR_CHANGED_REPLYID, + HOST_CALENDAR_SET_REPLYID }; struct host_notify_entry { queue_chain_t entries; @@ -63,7 +66,11 @@ host_notify_init(void) for (i = 0; i <= HOST_NOTIFY_TYPE_MAX; i++) queue_init(&host_notify_queue[i]); - mutex_init(&host_notify_lock, 0); + lck_grp_attr_setdefault(&host_notify_lock_grp_attr); + lck_grp_init(&host_notify_lock_grp, "host_notify", &host_notify_lock_grp_attr); + lck_attr_setdefault(&host_notify_lock_attr); + + lck_mtx_init_ext(&host_notify_lock, &host_notify_lock_ext, &host_notify_lock_grp, &host_notify_lock_attr); i = sizeof (struct host_notify_entry); host_notify_zone = @@ -91,13 +98,13 @@ host_request_notification( if (entry == NULL) return (KERN_RESOURCE_SHORTAGE); - mutex_lock(&host_notify_lock); + lck_mtx_lock(&host_notify_lock); ip_lock(port); - if (!ip_active(port) || ip_kotype(port) != IKOT_NONE) { + if (!ip_active(port) || port->ip_tempowner || ip_kotype(port) != IKOT_NONE) { ip_unlock(port); - mutex_unlock(&host_notify_lock); + lck_mtx_unlock(&host_notify_lock); zfree(host_notify_zone, entry); return (KERN_FAILURE); @@ -108,7 +115,7 @@ host_request_notification( ip_unlock(port); enqueue_tail(&host_notify_queue[notify_type], (queue_entry_t)entry); - mutex_unlock(&host_notify_lock); + lck_mtx_unlock(&host_notify_lock); return (KERN_SUCCESS); } @@ -119,7 +126,7 @@ host_notify_port_destroy( { host_notify_t entry; - mutex_lock(&host_notify_lock); + lck_mtx_lock(&host_notify_lock); ip_lock(port); if (ip_kotype(port) == IKOT_HOST_NOTIFY) { @@ -129,8 +136,8 @@ host_notify_port_destroy( ip_unlock(port); assert(entry->port == port); - remqueue(NULL, (queue_entry_t)entry); - mutex_unlock(&host_notify_lock); + remqueue((queue_entry_t)entry); + lck_mtx_unlock(&host_notify_lock); zfree(host_notify_zone, entry); ipc_port_release_sonce(port); @@ -138,7 +145,7 @@ host_notify_port_destroy( } ip_unlock(port); - mutex_unlock(&host_notify_lock); + lck_mtx_unlock(&host_notify_lock); } static void @@ -149,7 +156,7 @@ host_notify_all( { queue_t notify_queue = &host_notify_queue[notify_type]; - mutex_lock(&host_notify_lock); + lck_mtx_lock(&host_notify_lock); if (!queue_empty(notify_queue)) { queue_head_t send_queue; @@ -161,10 +168,11 @@ host_notify_all( send_queue.next->prev = &send_queue; send_queue.prev->next = &send_queue; - msg->msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE, 0); + msg->msgh_bits = + MACH_MSGH_BITS_SET(MACH_MSG_TYPE_MOVE_SEND_ONCE, 0, 0, 0); msg->msgh_local_port = MACH_PORT_NULL; + msg->msgh_voucher_port = MACH_PORT_NULL; msg->msgh_id = host_notify_replyid[notify_type]; - msg->msgh_reserved = 0; while ((entry = (host_notify_t)dequeue(&send_queue)) != NULL) { ipc_port_t port; @@ -178,18 +186,18 @@ host_notify_all( ipc_kobject_set_atomically(port, IKO_NULL, IKOT_NONE); ip_unlock(port); - mutex_unlock(&host_notify_lock); + lck_mtx_unlock(&host_notify_lock); zfree(host_notify_zone, entry); msg->msgh_remote_port = port; - (void) mach_msg_send_from_kernel(msg, msg_size); + (void) mach_msg_send_from_kernel_proper(msg, msg_size); - mutex_lock(&host_notify_lock); + lck_mtx_lock(&host_notify_lock); } } - mutex_unlock(&host_notify_lock); + lck_mtx_unlock(&host_notify_lock); } void @@ -199,3 +207,11 @@ host_notify_calendar_change(void) host_notify_all(HOST_NOTIFY_CALENDAR_CHANGE, &msg.Head, sizeof (msg)); } + +void +host_notify_calendar_set(void) +{ + __Request__host_calendar_set_t msg; + + host_notify_all(HOST_NOTIFY_CALENDAR_SET, &msg.Head, sizeof (msg)); +}