Changeset 85206 in vbox for trunk/include
- Timestamp:
- Jul 10, 2020 9:02:45 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/time.h
r85205 r85206 358 358 359 359 /* PORTME: Add struct timeval guard macro here. */ 360 /* 361 * Starting with Linux kernel version 5.6-rc3, the struct timeval is no longer 362 * available to kernel code and must not be used in kernel code. 363 * Only 64-bit time-interfaces are allowed into the kernel. 364 */ 365 #if defined(RT_OS_LINUX) && defined(_LINUX_TIME64_H) 366 #define RTTIME_NO_TIMEVAL 367 #endif 368 #if !defined(RTTIME_NO_TIMEVAL) \ 369 && (defined(RTTIME_INCL_TIMEVAL) || defined(_STRUCT_TIMEVAL) || defined(_SYS__TIMEVAL_H_) \ 370 || defined(_SYS_TIME_H) || defined(_TIMEVAL) || defined(_LINUX_TIME_H) \ 371 || (defined(RT_OS_NETBSD) && defined(_SYS_TIME_H_))) 360 #if defined(RTTIME_INCL_TIMEVAL) \ 361 || defined(_SYS__TIMEVAL_H_) \ 362 || defined(_SYS_TIME_H) \ 363 || defined(_TIMEVAL) \ 364 || defined(_STRUCT_TIMEVAL) \ 365 || ( defined(RT_OS_LINUX) \ 366 && defined(_LINUX_TIME_H) \ 367 && (!defined(__KERNEL__) /* || < 5.6-rc3 - but we don't need this in ring-0. @bugref{9757} */)) \ 368 || (defined(RT_OS_NETBSD) && defined(_SYS_TIME_H_)) 369 372 370 /** 373 371 * Gets the time as POSIX timeval. … … 403 401 return RTTimeSpecAddMicro(RTTimeSpecSetSeconds(pTime, pTimeval->tv_sec), pTimeval->tv_usec); 404 402 } 403 405 404 #endif /* various ways of detecting struct timeval */ 406 405 407 406 408 407 /* PORTME: Add struct timespec guard macro here. */ 409 /* 410 * Starting with Linux kernel version 5.6-rc3, the _STRUCT_TIMESPEC is only defined 411 * under !__KERNEL__ guard and _LINUX_TIME64_H does not define a corresponding 412 * _STRUCT_TIMESPEC64. Only 64-bit time-interfaces are now allowed into the kernel. 413 * We have to keep it for __KERNEL__ though to support older guest kernels (2.6.X) 414 * without _LINUX_TIME64_H. 415 */ 416 #if defined(RT_OS_LINUX) && defined(_LINUX_TIME64_H) 417 #define RTTIME_NO_TIMESPEC 418 #endif 419 #if !defined(RTTIME_NO_TIMESPEC) \ 420 && (defined(RTTIME_INCL_TIMESPEC) || defined(_STRUCT_TIMESPEC) || defined(_SYS__TIMESPEC_H_) \ 421 || defined(TIMEVAL_TO_TIMESPEC) || defined(_TIMESPEC) \ 422 || (defined(RT_OS_NETBSD) && defined(_SYS_TIME_H_))) 408 #if defined(RTTIME_INCL_TIMESPEC) \ 409 || defined(_SYS__TIMESPEC_H_) \ 410 || defined(TIMEVAL_TO_TIMESPEC) \ 411 || defined(_TIMESPEC) \ 412 || ( defined(_STRUCT_TIMESPEC) \ 413 && (!defined(RT_OS_LINUX) || !defined(__KERNEL__) /* || < 5.6-rc3 - but we don't need this in ring-0. @bugref{9757} */) ) \ 414 || (defined(RT_OS_NETBSD) && defined(_SYS_TIME_H_)) 415 423 416 /** 424 417 * Gets the time as POSIX timespec. 425 418 * 426 * @returns pTime .419 * @returns pTimespec. 427 420 * @param pTime The time spec to interpret. 428 421 * @param pTimespec Where to store the time as POSIX timespec. … … 454 447 return RTTimeSpecAddNano(RTTimeSpecSetSeconds(pTime, pTimespec->tv_sec), pTimespec->tv_nsec); 455 448 } 449 456 450 #endif /* various ways of detecting struct timespec */ 457 451 458 #if defined(RTTIME_NO_TIMESPEC) 459 DECLINLINE(PRTTIMESPEC) RTTimeSpecSetTimespec64(PRTTIMESPEC pTime, const struct timespec64 *pTimeval) 460 { 461 return RTTimeSpecAddNano(RTTimeSpecSetSeconds(pTime, pTimeval->tv_sec), pTimeval->tv_nsec); 462 } 452 453 #if defined(RT_OS_LINUX) && defined(_LINUX_TIME64_H) /* since linux 3.17 */ 454 455 /** 456 * Gets the time a linux 64-bit timespec structure. 457 * @returns pTimespec. 458 * @param pTime The time spec to modify. 459 * @param pTimespec Where to store the time as linux 64-bit timespec. 460 */ 461 DECLINLINE(struct timespec64 *) RTTimeSpecSetTimespec64(PCRTTIMESPEC pTime, struct timespec64 *pTimespec) 462 { 463 int64_t i64 = RTTimeSpecGetNano(pTime); 464 int32_t i32Nano = (int32_t)(i64 % RT_NS_1SEC); 465 i64 /= RT_NS_1SEC; 466 if (i32Nano < 0) 467 { 468 i32Nano += RT_NS_1SEC; 469 i64--; 470 } 471 pTimespec->tv_sec = i64; 472 pTimespec->tv_nsec = i32Nano; 473 return pTimespec; 474 } 475 476 /** 477 * Sets the time from a linux 64-bit timespec structure. 478 * @returns pTime. 479 * @param pTime The time spec to modify. 480 * @param pTimespec Pointer to the linux 64-bit timespec struct with the new time. 481 */ 482 DECLINLINE(PRTTIMESPEC) RTTimeSpecSetTimespec64(PRTTIMESPEC pTime, const struct timespec64 *pTimespec) 483 { 484 return RTTimeSpecAddNano(RTTimeSpecSetSeconds(pTime, pTimespec->tv_sec), pTimespec->tv_nsec); 485 } 486 463 487 #endif /* RT_OS_LINUX && _LINUX_TIME64_H */ 464 465 488 466 489 … … 499 522 500 523 #ifdef _FILETIME_ 524 501 525 /** 502 526 * Gets the time as NT file time. … … 523 547 return RTTimeSpecSetNtTime(pTime, *(const uint64_t *)pFileTime); 524 548 } 525 #endif 549 550 #endif /* _FILETIME_ */ 526 551 527 552
Note:
See TracChangeset
for help on using the changeset viewer.