-#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) {
error = copyout(&user_ntv, uap->ntvp, sizeof(user_ntv));
} else {
struct user32_ntptimeval user_ntv = {};
error = copyout(&user_ntv, uap->ntvp, sizeof(user_ntv));
} else {
struct user32_ntptimeval user_ntv = {};
- user_ntv.time.tv_sec = ntv.time.tv_sec;
- user_ntv.time.tv_nsec = ntv.time.tv_nsec;
- user_ntv.maxerror = ntv.maxerror;
- user_ntv.esterror = ntv.esterror;
- user_ntv.tai = ntv.tai;
+ user_ntv.time.tv_sec = (user32_long_t)ntv.time.tv_sec;
+ user_ntv.time.tv_nsec = (user32_long_t)ntv.time.tv_nsec;
+ user_ntv.maxerror = (user32_long_t)ntv.maxerror;
+ user_ntv.esterror = (user32_long_t)ntv.esterror;
+ user_ntv.tai = (user32_long_t)ntv.tai;
user_ntv.time_state = ntv.time_state;
error = copyout(&user_ntv, uap->ntvp, sizeof(user_ntv));
}
user_ntv.time_state = ntv.time_state;
error = copyout(&user_ntv, uap->ntvp, sizeof(user_ntv));
}
struct user64_timex user_ntv;
error = copyin(uap->tp, &user_ntv, sizeof(user_ntv));
ntv.modes = user_ntv.modes;
struct user64_timex user_ntv;
error = copyin(uap->tp, &user_ntv, sizeof(user_ntv));
ntv.modes = user_ntv.modes;
- ntv.offset = user_ntv.offset;
- ntv.freq = user_ntv.freq;
- ntv.maxerror = user_ntv.maxerror;
- ntv.esterror = user_ntv.esterror;
+ ntv.offset = (long)user_ntv.offset;
+ ntv.freq = (long)user_ntv.freq;
+ ntv.maxerror = (long)user_ntv.maxerror;
+ ntv.esterror = (long)user_ntv.esterror;
- ntv.constant = user_ntv.constant;
- ntv.precision = user_ntv.precision;
- ntv.tolerance = user_ntv.tolerance;
-
+ ntv.constant = (long)user_ntv.constant;
+ ntv.precision = (long)user_ntv.precision;
+ ntv.tolerance = (long)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.maxerror = time_maxerror;
user_ntv.esterror = time_esterror;
user_ntv.status = time_status;
user_ntv.constant = time_constant;
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;
+ }
+ if (time_freq > 0) {
+ user_ntv.freq = L_GINT((time_freq / 1000LL) << 16);
+ } else {
+ user_ntv.freq = -L_GINT((-(time_freq) / 1000LL) << 16);
+ }
+ user_ntv.maxerror = (user32_long_t)time_maxerror;
+ user_ntv.esterror = (user32_long_t)time_esterror;
- user_ntv.constant = time_constant;
- if (time_status & STA_NANO)
- user_ntv.precision = time_precision;
- else
- user_ntv.precision = time_precision / 1000;
+ user_ntv.constant = (user32_long_t)time_constant;
+ if (time_status & STA_NANO) {
+ user_ntv.precision = (user32_long_t)time_precision;
+ } else {
+ user_ntv.precision = (user32_long_t)(time_precision / 1000);
+ }
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)) {
}
if (IS_64BIT_PROCESS(p)) {
struct user64_timeval user_atv;
error = copyin(uap->delta, &user_atv, sizeof(user_atv));
}
if (IS_64BIT_PROCESS(p)) {
struct user64_timeval user_atv;
error = copyin(uap->delta, &user_atv, sizeof(user_atv));
error = copyout(&user_atv, uap->olddelta, sizeof(user_atv));
} else {
struct user32_timeval user_atv = {};
error = copyout(&user_atv, uap->olddelta, sizeof(user_atv));
} else {
struct user32_timeval user_atv = {};
user_atv.tv_usec = atv.tv_usec;
error = copyout(&user_atv, uap->olddelta, sizeof(user_atv));
}
}
user_atv.tv_usec = atv.tv_usec;
error = copyout(&user_atv, uap->olddelta, sizeof(user_atv));
}
}
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)) {