/* * Limits for settimeofday(): * * To prevent setting the time close to the wraparound point time setting * is limited so a reasonable uptime can be accomodated. Uptime of 30 years * should be really sufficient, which means the cutoff is 2232. At that * point the cutoff is just a small part of the larger problem.
*/ #define TIME_UPTIME_SEC_MAX (30LL * 365 * 24 *3600) #define TIME_SETTOD_SEC_MAX (KTIME_SEC_MAX - TIME_UPTIME_SEC_MAX)
/* * Returns true if the timespec64 is norm, false if denorm:
*/ staticinlinebool timespec64_valid(conststruct timespec64 *ts)
{ /* Dates before 1970 are bogus */ if (ts->tv_sec < 0) returnfalse; /* Can't have more nanoseconds then a second */ if ((unsignedlong)ts->tv_nsec >= NSEC_PER_SEC) returnfalse; returntrue;
}
staticinlinebool timespec64_valid_strict(conststruct timespec64 *ts)
{ if (!timespec64_valid(ts)) returnfalse; /* Disallow values that could overflow ktime_t */ if ((unsignedlonglong)ts->tv_sec >= KTIME_SEC_MAX) returnfalse; returntrue;
}
staticinlinebool timespec64_valid_settod(conststruct timespec64 *ts)
{ if (!timespec64_valid(ts)) returnfalse; /* Disallow values which cause overflow issues vs. CLOCK_REALTIME */ if ((unsignedlonglong)ts->tv_sec >= TIME_SETTOD_SEC_MAX) returnfalse; returntrue;
}
/** * timespec64_to_ns - Convert timespec64 to nanoseconds * @ts: pointer to the timespec64 variable to be converted * * Returns the scalar nanosecond representation of the timespec64 * parameter.
*/ staticinline s64 timespec64_to_ns(conststruct timespec64 *ts)
{ /* Prevent multiplication overflow / underflow */ if (ts->tv_sec >= KTIME_SEC_MAX) return KTIME_MAX;
if (ts->tv_sec <= KTIME_SEC_MIN) return KTIME_MIN;
/** * ns_to_timespec64 - Convert nanoseconds to timespec64 * @nsec: the nanoseconds value to be converted * * Returns the timespec64 representation of the nsec parameter.
*/ externstruct timespec64 ns_to_timespec64(s64 nsec);
/** * timespec64_add_ns - Adds nanoseconds to a timespec64 * @a: pointer to timespec64 to be incremented * @ns: unsigned nanoseconds value to be added * * This must always be inlined because its used from the x86-64 vdso, * which cannot call other kernel functions.
*/ static __always_inline void timespec64_add_ns(struct timespec64 *a, u64 ns)
{
a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
a->tv_nsec = ns;
}
/* * timespec64_add_safe assumes both values are positive and checks for * overflow. It will return TIME64_MAX in case of overflow.
*/ externstruct timespec64 timespec64_add_safe(conststruct timespec64 lhs, conststruct timespec64 rhs);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.