+ clock_get_calendar_absolute_and_microtime_locked(&oldsecs, &oldmicrosecs, &absolutesys);
+
+#if DEVELOPMENT || DEBUG
+ if (g_should_log_clock_adjustments) {
+ os_log(OS_LOG_DEFAULT, "%s wall %lu s %d u computed with %llu abs\n",
+ __func__, (unsigned long)oldsecs, oldmicrosecs, absolutesys);
+ os_log(OS_LOG_DEFAULT, "%s requested %lu s %d u\n",
+ __func__, (unsigned long)secs, microsecs );
+ }
+#endif
+
+ if (oldsecs < secs || (oldsecs == secs && oldmicrosecs < microsecs)) {
+ // moving forwards
+ deltasecs = secs;
+ deltamicrosecs = microsecs;
+
+ TIME_SUB(deltasecs, oldsecs, deltamicrosecs, oldmicrosecs, USEC_PER_SEC);
+
+#if DEVELOPMENT || DEBUG
+ if (g_should_log_clock_adjustments) {
+ os_log(OS_LOG_DEFAULT, "%s delta requested %lu s %d u\n",
+ __func__, (unsigned long)deltasecs, deltamicrosecs);
+ }
+#endif
+
+ TIME_ADD(clock_boottime, deltasecs, clock_boottime_usec, deltamicrosecs, USEC_PER_SEC);
+ clock2bintime(&deltasecs, &deltamicrosecs, &bt);
+ bintime_add(&clock_calend.boottime, &bt);
+ update_basesleep(bt, TRUE);
+ } else {
+ // moving backwards
+ deltasecs = oldsecs;
+ deltamicrosecs = oldmicrosecs;
+
+ TIME_SUB(deltasecs, secs, deltamicrosecs, microsecs, USEC_PER_SEC);
+#if DEVELOPMENT || DEBUG
+ if (g_should_log_clock_adjustments) {
+ os_log(OS_LOG_DEFAULT, "%s negative delta requested %lu s %d u\n",
+ __func__, (unsigned long)deltasecs, deltamicrosecs);
+ }
+#endif
+
+ TIME_SUB(clock_boottime, deltasecs, clock_boottime_usec, deltamicrosecs, USEC_PER_SEC);
+ clock2bintime(&deltasecs, &deltamicrosecs, &bt);
+ bintime_sub(&clock_calend.boottime, &bt);
+ update_basesleep(bt, FALSE);
+ }
+
+ clock_calend.bintime = clock_calend.boottime;
+ bintime_add(&clock_calend.bintime, &clock_calend.offset);
+
+ clock2bintime((clock_sec_t *) &secs, (clock_usec_t *) µsecs, &bt);
+
+ clock_gettimeofday_set_commpage(absolutesys, bt.sec, bt.frac, clock_calend.tick_scale_x, ticks_per_sec);
+
+#if DEVELOPMENT || DEBUG
+ struct clock_calend clock_calend_cp1 = clock_calend;
+#endif
+
+ commpage_value = clock_boottime * USEC_PER_SEC + clock_boottime_usec;
+
+ clock_unlock();
+ splx(s);