]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/kern_ntptime.c
xnu-7195.81.3.tar.gz
[apple/xnu.git] / bsd / kern / kern_ntptime.c
index 589ff9d97e0a1e2d05b03d018789ea98d24975be..0ae62258f0b304f77de3cd36c3a07953c6c4c588 100644 (file)
@@ -278,11 +278,11 @@ ntp_gettime(struct proc *p, struct ntp_gettime_args *uap, __unused int32_t *retv
                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));
        }
@@ -309,14 +309,14 @@ ntp_adjtime(struct proc *p, struct ntp_adjtime_args *uap, int32_t *retval)
                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.status = user_ntv.status;
-               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));
@@ -334,7 +334,7 @@ ntp_adjtime(struct proc *p, struct ntp_adjtime_args *uap, int32_t *retval)
                return error;
        }
 
-#if DEVELOPEMNT || DEBUG
+#if DEVELOPMENT || DEBUG
        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);
@@ -438,7 +438,7 @@ ntp_adjtime(struct proc *p, struct ntp_adjtime_args *uap, int32_t *retval)
 
        ret = ntp_is_time_error(time_status) ? TIME_ERROR : time_state;
 
-#if DEVELOPEMNT || DEBUG
+#if DEVELOPMENT || DEBUG
        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);
@@ -458,7 +458,11 @@ ntp_adjtime(struct proc *p, struct ntp_adjtime_args *uap, int32_t *retval)
                } else {
                        user_ntv.offset = L_GINT(time_offset) / 1000;
                }
-               user_ntv.freq = L_GINT((time_freq / 1000LL) << 16);
+               if (time_freq > 0) {
+                       user_ntv.freq = L_GINT(((int64_t)(time_freq / 1000LL)) << 16);
+               } else {
+                       user_ntv.freq = -L_GINT(((int64_t)(-(time_freq) / 1000LL)) << 16);
+               }
                user_ntv.maxerror = time_maxerror;
                user_ntv.esterror = time_esterror;
                user_ntv.status = time_status;
@@ -483,15 +487,19 @@ ntp_adjtime(struct proc *p, struct ntp_adjtime_args *uap, int32_t *retval)
                } else {
                        user_ntv.offset = L_GINT(time_offset) / 1000;
                }
-               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.status = time_status;
-               user_ntv.constant = time_constant;
+               user_ntv.constant = (user32_long_t)time_constant;
                if (time_status & STA_NANO) {
-                       user_ntv.precision = time_precision;
+                       user_ntv.precision = (user32_long_t)time_precision;
                } else {
-                       user_ntv.precision = time_precision / 1000;
+                       user_ntv.precision = (user32_long_t)(time_precision / 1000);
                }
                user_ntv.tolerance = MAXFREQ * SCALE_PPM;
 
@@ -559,7 +567,7 @@ ntp_update_second(int64_t *adjustment, clock_sec_t secs)
                } else if (time_adjtime < -500) {
                        tickrate = -500;
                } else {
-                       tickrate = time_adjtime;
+                       tickrate = (int)time_adjtime;
                }
                time_adjtime -= tickrate;
                L_LINT(ftemp, tickrate * 1000);
@@ -572,7 +580,7 @@ ntp_update_second(int64_t *adjustment, clock_sec_t secs)
                updated = 0;
        }
 
-#if DEVELOPEMNT || DEBUG
+#if DEVELOPMENT || DEBUG
        if (g_should_log_clock_adjustments) {
                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));
@@ -675,7 +683,7 @@ kern_adjtime(struct timeval *delta)
        NTP_LOCK(enable);
        ltr = time_adjtime;
        time_adjtime = ltw;
-#if DEVELOPEMNT || DEBUG
+#if DEVELOPMENT || DEBUG
        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);
@@ -683,7 +691,7 @@ kern_adjtime(struct timeval *delta)
 #endif
        NTP_UNLOCK(enable);
 
-       atv.tv_sec = ltr / (int64_t)USEC_PER_SEC;
+       atv.tv_sec = (__darwin_time_t)(ltr / (int64_t)USEC_PER_SEC);
        atv.tv_usec = ltr % (int64_t)USEC_PER_SEC;
        if (atv.tv_usec < 0) {
                atv.tv_usec += (suseconds_t)USEC_PER_SEC;
@@ -719,7 +727,7 @@ adjtime(struct proc *p, struct adjtime_args *uap, __unused int32_t *retval)
        if (IS_64BIT_PROCESS(p)) {
                struct user64_timeval user_atv;
                error = copyin(uap->delta, &user_atv, sizeof(user_atv));
-               atv.tv_sec = user_atv.tv_sec;
+               atv.tv_sec = (__darwin_time_t)user_atv.tv_sec;
                atv.tv_usec = user_atv.tv_usec;
        } else {
                struct user32_timeval user_atv;
@@ -741,7 +749,7 @@ adjtime(struct proc *p, struct adjtime_args *uap, __unused int32_t *retval)
                        error = copyout(&user_atv, uap->olddelta, sizeof(user_atv));
                } else {
                        struct user32_timeval user_atv = {};
-                       user_atv.tv_sec = atv.tv_sec;
+                       user_atv.tv_sec = (user32_time_t)atv.tv_sec;
                        user_atv.tv_usec = atv.tv_usec;
                        error = copyout(&user_atv, uap->olddelta, sizeof(user_atv));
                }