]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/kern_time.c
xnu-792.17.14.tar.gz
[apple/xnu.git] / bsd / kern / kern_time.c
index 3f78ebfd110e1eedc3c0aea3b41c08dc166880ea..2948aff9867aab93dcf29416cbde280c8370258f 100644 (file)
@@ -1,31 +1,29 @@
 /*
- * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_LICENSE_OSREFERENCE_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.  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 
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
- * Please see the License for the specific language governing rights and 
+ * 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. 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
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
  * limitations under the License.
- *
- * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
+ * 
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
 /*
@@ -91,6 +89,14 @@ static void          setthetime(
 
 void time_zone_slock_init(void);
 
+int gettimeofday(struct proc *p,
+#ifdef __ppc__
+                        struct ppc_gettimeofday_args *uap, 
+#else                   
+                        struct gettimeofday_args *uap, 
+#endif
+                        register_t *retval);
+
 /* 
  * Time of day and interval timer support.
  *
@@ -99,29 +105,52 @@ void time_zone_slock_init(void);
  * here provide support for adding and subtracting timeval structures
  * and decrementing interval timers, optionally reloading the interval
  * timers when they expire.
+ *
+ * XXX Y2038 bug because of clock_get_calendar_microtime() first argument
  */
 /* ARGSUSED */
 int
-gettimeofday(
-__unused       struct proc     *p,
-                       struct gettimeofday_args *uap, 
-                       register_t *retval)
+gettimeofday(__unused struct proc *p,
+#ifdef __ppc__
+                        register struct ppc_gettimeofday_args *uap, 
+#else                   
+                        register struct gettimeofday_args *uap, 
+#endif
+                        __unused register_t *retval)
 {
+       struct timeval atv;
        int error = 0;
        struct timezone ltz; /* local copy */
 
-       if (uap->tp)
-               clock_gettimeofday(&retval[0], &retval[1]);
+/*  NOTE THIS implementation is for non ppc architectures only */
+
+       if (uap->tp) {
+               clock_get_calendar_microtime((uint32_t *)&atv.tv_sec, &atv.tv_usec);
+               if (IS_64BIT_PROCESS(p)) {
+                       struct user_timeval user_atv;
+                       user_atv.tv_sec = atv.tv_sec;
+                       user_atv.tv_usec = atv.tv_usec;
+                       /*
+                        * This cast is not necessary for PPC, but is
+                        * mostly harmless.
+                        */
+                       error = copyout(&user_atv, CAST_USER_ADDR_T(uap->tp), sizeof(struct user_timeval));
+               } else {
+                       error = copyout(&atv, CAST_USER_ADDR_T(uap->tp), sizeof(struct timeval));
+               }
+               if (error)
+                       return(error);
+       }
        
        if (uap->tzp) {
                lck_spin_lock(tz_slock);
                ltz = tz;
                lck_spin_unlock(tz_slock);
-
-               error = copyout((caddr_t)&ltz, CAST_USER_ADDR_T(uap->tzp), sizeof (tz));
+               error = copyout((caddr_t)&ltz, CAST_USER_ADDR_T(uap->tzp),
+                   sizeof (tz));
        }
 
-       return (error);
+       return(error);
 }
 
 /*
@@ -582,11 +611,13 @@ time_zone_slock_init(void)
 {
        /* allocate lock group attribute and group */
        tz_slock_grp_attr = lck_grp_attr_alloc_init();
+       lck_grp_attr_setstat(tz_slock_grp_attr);
 
        tz_slock_grp =  lck_grp_alloc_init("tzlock", tz_slock_grp_attr);
 
        /* Allocate lock attribute */
        tz_slock_attr = lck_attr_alloc_init();
+       //lck_attr_setdebug(tz_slock_attr);
 
        /* Allocate the spin lock */
        tz_slock = lck_spin_alloc_init(tz_slock_grp, tz_slock_attr);