-#define L_ADD(v, u) ((v) += (u))
-#define L_SUB(v, u) ((v) -= (u))
-#define L_ADDHI(v, a) ((v) += (int64_t)(a) << 32)
-#define L_NEG(v) ((v) = -(v))
+#define L_ADD(v, u) ((v) += (u))
+#define L_SUB(v, u) ((v) -= (u))
+#define L_ADDHI(v, a) ((v) += (int64_t)(a) << 32)
+#define L_NEG(v) ((v) = -(v))
-#define L_MPY(v, a) ((v) *= (a))
-#define L_CLR(v) ((v) = 0)
-#define L_ISNEG(v) ((v) < 0)
+#define L_MPY(v, a) ((v) *= (a))
+#define L_CLR(v) ((v) = 0)
+#define L_ISNEG(v) ((v) < 0)
static lck_spin_t * ntp_lock;
static lck_grp_t * ntp_lock_grp;
static lck_attr_t * ntp_lock_attr;
static lck_spin_t * ntp_lock;
static lck_grp_t * ntp_lock_grp;
static lck_attr_t * ntp_lock_attr;
-#define NTP_LOCK(enable) \
- enable = ml_set_interrupts_enabled(FALSE); \
- lck_spin_lock(ntp_lock);
+#define NTP_LOCK(enable) \
+ enable = ml_set_interrupts_enabled(FALSE); \
+ lck_spin_lock(ntp_lock);
-#define NTP_UNLOCK(enable) \
- lck_spin_unlock(ntp_lock);\
- ml_set_interrupts_enabled(enable);
+#define NTP_UNLOCK(enable) \
+ lck_spin_unlock(ntp_lock);\
+ ml_set_interrupts_enabled(enable);
ntvp->time.tv_sec = atv.tv_sec;
ntvp->time.tv_nsec = atv.tv_nsec;
if ((unsigned long)atv.tv_sec > last_time_maxerror_update) {
ntvp->time.tv_sec = atv.tv_sec;
ntvp->time.tv_nsec = atv.tv_nsec;
if ((unsigned long)atv.tv_sec > last_time_maxerror_update) {
ntv.constant = user_ntv.constant;
ntv.precision = user_ntv.precision;
ntv.tolerance = user_ntv.tolerance;
ntv.constant = user_ntv.constant;
ntv.precision = user_ntv.precision;
ntv.tolerance = user_ntv.tolerance;
} else {
struct user32_timex user_ntv;
error = copyin(uap->tp, &user_ntv, sizeof(user_ntv));
} else {
struct user32_timex user_ntv;
error = copyin(uap->tp, &user_ntv, sizeof(user_ntv));
if (g_should_log_clock_adjustments) {
os_log(OS_LOG_DEFAULT, "%s: BEFORE modes %u offset %ld freq %ld status %d constant %ld time_adjtime %lld\n",
if (g_should_log_clock_adjustments) {
os_log(OS_LOG_DEFAULT, "%s: BEFORE modes %u offset %ld freq %ld status %d constant %ld time_adjtime %lld\n",
- __func__, ntv.modes, ntv.offset, ntv.freq, ntv.status, ntv.constant, time_adjtime);
+ __func__, ntv.modes, ntv.offset, ntv.freq, ntv.status, ntv.constant, time_adjtime);
if (!IOTaskHasEntitlement(current_task(), SETTIME_ENTITLEMENT)) {
#if CONFIG_MACF
error = mac_system_check_settime(kauth_cred_get());
if (!IOTaskHasEntitlement(current_task(), SETTIME_ENTITLEMENT)) {
#if CONFIG_MACF
error = mac_system_check_settime(kauth_cred_get());
if (g_should_log_clock_adjustments) {
os_log(OS_LOG_DEFAULT, "%s: AFTER modes %u offset %lld freq %lld status %d constant %ld time_adjtime %lld\n",
if (g_should_log_clock_adjustments) {
os_log(OS_LOG_DEFAULT, "%s: AFTER modes %u offset %lld freq %lld status %d constant %ld time_adjtime %lld\n",
- __func__, modes, time_offset, time_freq, time_status, time_constant, time_adjtime);
+ __func__, modes, time_offset, time_freq, time_status, time_constant, time_adjtime);
user_ntv.freq = L_GINT((time_freq / 1000LL) << 16);
user_ntv.maxerror = time_maxerror;
user_ntv.esterror = time_esterror;
user_ntv.status = time_status;
user_ntv.constant = time_constant;
user_ntv.freq = L_GINT((time_freq / 1000LL) << 16);
user_ntv.maxerror = time_maxerror;
user_ntv.esterror = time_esterror;
user_ntv.status = time_status;
user_ntv.constant = time_constant;
user_ntv.tolerance = MAXFREQ * SCALE_PPM;
/* unlock before copyout */
NTP_UNLOCK(enable);
error = copyout(&user_ntv, uap->tp, sizeof(user_ntv));
user_ntv.tolerance = MAXFREQ * SCALE_PPM;
/* unlock before copyout */
NTP_UNLOCK(enable);
error = copyout(&user_ntv, uap->tp, sizeof(user_ntv));
user_ntv.freq = L_GINT((time_freq / 1000LL) << 16);
user_ntv.maxerror = time_maxerror;
user_ntv.esterror = time_esterror;
user_ntv.status = time_status;
user_ntv.constant = time_constant;
user_ntv.freq = L_GINT((time_freq / 1000LL) << 16);
user_ntv.maxerror = time_maxerror;
user_ntv.esterror = time_esterror;
user_ntv.status = time_status;
user_ntv.constant = time_constant;
time_adjtime -= tickrate;
L_LINT(ftemp, tickrate * 1000);
L_ADD(time_adj, ftemp);
time_adjtime -= tickrate;
L_LINT(ftemp, tickrate * 1000);
L_ADD(time_adj, ftemp);
- int64_t nano = (time_adj > 0)? time_adj >> 32 : -((-time_adj) >> 32);
- int64_t frac = (time_adj > 0)? ((uint32_t) time_adj) : -((uint32_t) (-time_adj));
+ int64_t nano = (time_adj > 0)? time_adj >> 32 : -((-time_adj) >> 32);
+ int64_t frac = (time_adj > 0)? ((uint32_t) time_adj) : -((uint32_t) (-time_adj));
- "constant %ld time_adjtime %lld nano %lld frac %lld adj %lld\n",
- __func__, time_offset, (time_offset > 0)? time_offset >> 32 : -((-time_offset) >> 32),
- time_freq, time_status, time_constant, time_adjtime, nano, frac, time_adj);
+ "constant %ld time_adjtime %lld nano %lld frac %lld adj %lld\n",
+ __func__, time_offset, (time_offset > 0)? time_offset >> 32 : -((-time_offset) >> 32),
+ time_freq, time_status, time_constant, time_adjtime, nano, frac, time_adj);
L_LINT(time_offset, time_monitor);
clock_get_calendar_uptime(&time_uptime);
L_LINT(time_offset, time_monitor);
clock_get_calendar_uptime(&time_uptime);
if (g_should_log_clock_adjustments) {
os_log(OS_LOG_DEFAULT, "%s:AFTER offset %lld freq %lld status %d constant %ld time_adjtime %lld\n",
if (g_should_log_clock_adjustments) {
os_log(OS_LOG_DEFAULT, "%s:AFTER offset %lld freq %lld status %d constant %ld time_adjtime %lld\n",
- __func__, time_offset, time_freq, time_status, time_constant, time_adjtime);
+ __func__, time_offset, time_freq, time_status, time_constant, time_adjtime);
struct timeval atv;
int error;
/* Check that this task is entitled to set the time or it is root */
if (!IOTaskHasEntitlement(current_task(), SETTIME_ENTITLEMENT)) {
struct timeval atv;
int error;
/* Check that this task is entitled to set the time or it is root */
if (!IOTaskHasEntitlement(current_task(), SETTIME_ENTITLEMENT)) {
ntp_loop_deadline = mach_absolute_time() + ntp_loop_period;
if (!timer_call_enter(&ntp_loop_update, ntp_loop_deadline, TIMER_CALL_SYS_CRITICAL)) {
ntp_loop_deadline = mach_absolute_time() + ntp_loop_period;
if (!timer_call_enter(&ntp_loop_update, ntp_loop_deadline, TIMER_CALL_SYS_CRITICAL)) {