]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/mk_timer.c
xnu-2050.7.9.tar.gz
[apple/xnu.git] / osfmk / kern / mk_timer.c
index df1d3fa700656026dfb1b3fdb1a4269182aa94c2..f0dd81cc9aa304022bde55e367e83be4d12933ed 100644 (file)
@@ -1,16 +1,19 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_LICENSE_HEADER_START@
- * 
- * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
+ * @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
@@ -20,7 +23,7 @@
  * Please see the License for the specific language governing rights and
  * limitations under the License.
  * 
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 /*
  * Copyright (c) 2000 Apple Computer, Inc.  All rights reserved.
@@ -32,6 +35,7 @@
  */
 
 #include <mach/mach_types.h>
+#include <mach/mach_traps.h>
 #include <mach/mach_port_server.h>
 
 #include <mach/mk_timer.h>
@@ -52,7 +56,8 @@ static void   mk_timer_expire(
                                void                    *p1);
 
 mach_port_name_t
-mk_timer_create(void)
+mk_timer_create_trap(
+       __unused struct mk_timer_create_trap_args *args)
 {
        mk_timer_t                      timer;
        ipc_space_t                     myspace = current_space();
@@ -70,13 +75,13 @@ mk_timer_create(void)
                result = ipc_port_translate_receive(myspace, name, &port);
 
        if (result != KERN_SUCCESS) {
-               zfree(mk_timer_zone, (vm_offset_t)timer);
+               zfree(mk_timer_zone, timer);
 
                return (MACH_PORT_NULL);
        }
 
-       simple_lock_init(&timer->lock, ETAP_MISC_TIMER);
-       call_entry_setup(&timer->call_entry, mk_timer_expire, timer);
+       simple_lock_init(&timer->lock, 0);
+       thread_call_setup(&timer->call_entry, mk_timer_expire, timer);
        timer->is_armed = timer->is_dead = FALSE;
        timer->active = 0;
 
@@ -114,7 +119,7 @@ mk_timer_port_destroy(
                timer->is_dead = TRUE;
                if (timer->active == 0) {
                        simple_unlock(&timer->lock);
-                       zfree(mk_timer_zone, (vm_offset_t)timer);
+                       zfree(mk_timer_zone, timer);
 
                        ipc_port_release_send(port);
                        return;
@@ -132,12 +137,14 @@ mk_timer_init(void)
        assert(!(mk_timer_zone != NULL));
 
        mk_timer_zone = zinit(s, (4096 * s), (16 * s), "mk_timer");
+
+       zone_change(mk_timer_zone, Z_NOENCRYPT, TRUE);
 }
 
 static void
 mk_timer_expire(
        void                    *p0,
-       void                    *p1)
+       __unused void           *p1)
 {
        mk_timer_t                      timer = p0;
        ipc_port_t                      port;
@@ -167,14 +174,14 @@ mk_timer_expire(
 
                msg.unused[0] = msg.unused[1] = msg.unused[2] = 0;
 
-               (void) mach_msg_send_from_kernel(&msg.header, sizeof (msg));
+               (void) mach_msg_send_from_kernel_proper(&msg.header, sizeof (msg));
 
                simple_lock(&timer->lock);
        }
 
        if (--timer->active == 0 && timer->is_dead) {
                simple_unlock(&timer->lock);
-               zfree(mk_timer_zone, (vm_offset_t)timer);
+               zfree(mk_timer_zone, timer);
 
                ipc_port_release_send(port);
                return;
@@ -183,10 +190,23 @@ mk_timer_expire(
        simple_unlock(&timer->lock);
 }
 
+/*
+ * mk_timer_destroy_trap: Destroy the Mach port associated with a timer
+ *
+ * Parameters:  args                     User argument descriptor (see below)
+ *
+ * Indirect:     args->name               Mach port name
+ *
+ *
+ * Returns:        0                      Success
+ *                !0                      Not success           
+ *
+ */
 kern_return_t
-mk_timer_destroy(
-       mach_port_name_t        name)
+mk_timer_destroy_trap(
+       struct mk_timer_destroy_trap_args *args)
 {
+       mach_port_name_t        name = args->name;
        ipc_space_t                     myspace = current_space();
        ipc_port_t                      port;
        kern_return_t           result;
@@ -207,19 +227,30 @@ mk_timer_destroy(
        return (result);
 }
 
+/*
+ * mk_timer_arm_trap: Start (arm) a timer
+ *
+ * Parameters:  args                     User argument descriptor (see below)
+ *
+ * Indirect:     args->name               Mach port name
+ *               args->expire_time        Time when timer expires
+ *
+ *
+ * Returns:        0                      Success
+ *                !0                      Not success           
+ *
+ */
 kern_return_t
-mk_timer_arm(
-       mach_port_name_t        name,
-       uint64_t                        expire_time)
+mk_timer_arm_trap(
+       struct mk_timer_arm_trap_args *args)
 {
-       uint64_t                        time_of_arming;
+       mach_port_name_t        name = args->name;
+       uint64_t                        expire_time = args->expire_time;
        mk_timer_t                      timer;
        ipc_space_t                     myspace = current_space();
        ipc_port_t                      port;
        kern_return_t           result;
 
-       clock_get_uptime(&time_of_arming);
-
        result = ipc_port_translate_receive(myspace, name, &port);
        if (result != KERN_SUCCESS)
                return (result);
@@ -232,7 +263,6 @@ mk_timer_arm(
                ip_unlock(port);
 
                if (!timer->is_dead) {
-                       timer->time_of_arming = time_of_arming;
                        timer->is_armed = TRUE;
 
                        if (!thread_call_enter_delayed(&timer->call_entry, expire_time))
@@ -249,11 +279,25 @@ mk_timer_arm(
        return (result);
 }
 
+/*
+ * mk_timer_cancel_trap: Cancel a timer
+ *
+ * Parameters:  args                     User argument descriptor (see below)
+ *
+ * Indirect:     args->name               Mach port name
+ *               args->result_time        The armed time of the cancelled timer (return value)
+ *
+ *
+ * Returns:        0                      Success
+ *                !0                      Not success           
+ *
+ */
 kern_return_t
-mk_timer_cancel(
-       mach_port_name_t        name,
-       uint64_t                        *result_time)
+mk_timer_cancel_trap(
+       struct mk_timer_cancel_trap_args *args)
 {
+       mach_port_name_t        name = args->name;
+       mach_vm_address_t       result_time_addr = args->result_time; 
        uint64_t                        armed_time = 0;
        mk_timer_t                      timer;
        ipc_space_t                     myspace = current_space();
@@ -272,7 +316,7 @@ mk_timer_cancel(
                ip_unlock(port);
 
                if (timer->is_armed) {
-                       armed_time = timer->call_entry.deadline;
+                       armed_time = timer->call_entry.tc_call.deadline;
                        if (thread_call_cancel(&timer->call_entry))
                                timer->active--;
                        timer->is_armed = FALSE;
@@ -286,8 +330,8 @@ mk_timer_cancel(
        }
 
        if (result == KERN_SUCCESS)
-               if (    result_time     != NULL                                                                         &&
-                               copyout((void *)&armed_time, (void *)result_time,
+               if (    result_time_addr != 0                                                                           &&
+                               copyout((void *)&armed_time, result_time_addr,
                                                                sizeof (armed_time)) != 0                                       )
                        result = KERN_FAILURE;