Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_time.c
Show First 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | |||||
static int | static int | ||||
settime(struct thread *td, struct timeval *tv) | settime(struct thread *td, struct timeval *tv) | ||||
{ | { | ||||
struct timeval delta, tv1, tv2; | struct timeval delta, tv1, tv2; | ||||
static struct timeval maxtime, laststep; | static struct timeval maxtime, laststep; | ||||
struct timespec ts; | struct timespec ts; | ||||
int s; | |||||
s = splclock(); | |||||
microtime(&tv1); | microtime(&tv1); | ||||
delta = *tv; | delta = *tv; | ||||
timevalsub(&delta, &tv1); | timevalsub(&delta, &tv1); | ||||
/* | /* | ||||
* If the system is secure, we do not allow the time to be | * If the system is secure, we do not allow the time to be | ||||
* set to a value earlier than 1 second less than the highest | * set to a value earlier than 1 second less than the highest | ||||
* time we have yet seen. The worst a miscreant can do in | * time we have yet seen. The worst a miscreant can do in | ||||
Show All 13 Lines | if (delta.tv_sec < 0 || delta.tv_usec < 0) { | ||||
maxtime = tv1; | maxtime = tv1; | ||||
tv2 = *tv; | tv2 = *tv; | ||||
timevalsub(&tv2, &maxtime); | timevalsub(&tv2, &maxtime); | ||||
if (tv2.tv_sec < -1) { | if (tv2.tv_sec < -1) { | ||||
tv->tv_sec = maxtime.tv_sec - 1; | tv->tv_sec = maxtime.tv_sec - 1; | ||||
printf("Time adjustment clamped to -1 second\n"); | printf("Time adjustment clamped to -1 second\n"); | ||||
} | } | ||||
} else { | } else { | ||||
if (tv1.tv_sec == laststep.tv_sec) { | if (tv1.tv_sec == laststep.tv_sec) | ||||
splx(s); | |||||
return (EPERM); | return (EPERM); | ||||
} | |||||
if (delta.tv_sec > 1) { | if (delta.tv_sec > 1) { | ||||
tv->tv_sec = tv1.tv_sec + 1; | tv->tv_sec = tv1.tv_sec + 1; | ||||
printf("Time adjustment clamped to +1 second\n"); | printf("Time adjustment clamped to +1 second\n"); | ||||
} | } | ||||
laststep = *tv; | laststep = *tv; | ||||
} | } | ||||
} | } | ||||
ts.tv_sec = tv->tv_sec; | ts.tv_sec = tv->tv_sec; | ||||
ts.tv_nsec = tv->tv_usec * 1000; | ts.tv_nsec = tv->tv_usec * 1000; | ||||
mtx_lock(&Giant); | |||||
tc_setclock(&ts); | tc_setclock(&ts); | ||||
resettodr(); | resettodr(); | ||||
mtx_unlock(&Giant); | |||||
return (0); | return (0); | ||||
} | } | ||||
#ifndef _SYS_SYSPROTO_H_ | #ifndef _SYS_SYSPROTO_H_ | ||||
struct clock_getcpuclockid2_args { | struct clock_getcpuclockid2_args { | ||||
id_t id; | id_t id; | ||||
int which, | int which, | ||||
clockid_t *clock_id; | clockid_t *clock_id; | ||||
▲ Show 20 Lines • Show All 1,499 Lines • Show Last 20 Lines |