1. 30 7月, 2019 15 次提交
  2. 29 7月, 2019 11 次提交
    • R
      timer_gettime: add time64 syscall support, decouple 32-bit time_t · a02bd528
      Rich Felker 提交于
      the time64 syscall has to be used if time_t is 64-bit, since there's
      no way of knowing before making a syscall whether the result will fit
      in 32 bits, and the 32-bit syscalls do not report overflow as an
      error.
      
      on 64-bit archs, there is no change to the code after preprocessing.
      on current 32-bit archs, the result is now read from the kernel
      through long[4] array, then copied into the timespec, to remove the
      assumption that time_t is the same as long.
      a02bd528
    • R
      remove x32 syscall timespec fixup hacks · 4c307bed
      Rich Felker 提交于
      the x32 syscall interfaces treat timespec's tv_nsec member as 64-bit
      despite the API type being long and long being 32-bit in the ABI. this
      is no problem for syscalls that store timespecs to userspace as
      results, but caused uninitialized padding to be misinterpreted as the
      high bits in syscalls that take timespecs as input.
      
      since the beginning of the port, we've dealt with this situation with
      hacks in syscall_arch.h, and injected between __syscall_cp_c and
      __syscall_cp_asm, to special-case the syscall numbers that involve
      timespecs as inputs and copy them to a form suitable to pass to the
      kernel.
      
      commit 40aa18d5 set the stage for
      removal of these hacks by letting us treat the "normal" x32 syscalls
      dealing with timespec as if they're x32's "time64" syscalls,
      effectively making x32 ax "time64-only 32-bit arch" like riscv32 will
      be when it's added. since then, all users of syscalls that x32's
      syscall_arch.h had hacks for have been updated to use time64 syscalls,
      so the hacks can be removed.
      
      there are still at least a few other timespec-related syscalls broken
      on x32, which were overlooked when the x32 hacks were done or added
      later. these include at least recvmmsg, adjtimex/clock_adjtime, and
      timerfd_settime, and they will be fixed independently later on.
      4c307bed
    • R
      utimensat: add time64 syscall support, decouple 32-bit time_t · 01f3480d
      Rich Felker 提交于
      time64 syscall is used only if it's the only one defined for the arch,
      or if either of the requested times does not fit in 32 bits. care is
      taken to normalize the inputs to account for UTIME_NOW or UTIME_OMIT
      in tv_nsec, in which case tv_sec should be ignored. this is needed not
      only to avoid spurious time64 syscalls that might waste time failing
      with ENOSYS, but also to accurately decide whether fallback is
      possible.
      
      if the requested time cannot be represented, the function fails with
      ENOTSUP, defined in general as "The implementation does not support
      the requested feature or value". neither the time64 syscall, nor this
      error, can happen on current 32-bit archs where time_t is a 32-bit
      type, and both are statically unreachable.
      
      on 64-bit archs, there are only superficial changes to the
      SYS_futimesat fallback path, which has been modified to pass long[4]
      instead of struct timeval[2] to the kernel, making it suitable for use
      on 32-bit archs even once time_t is changed to 64-bit. for 32-bit
      archs, the call to SYS_utimensat has also been changed to copy the
      timespecs through an array of long[4] rather than passing the
      timespec[2] in-place.
      01f3480d
    • R
      clock_settime: add time64 syscall support, decouple 32-bit time_t · 7aeecf3e
      Rich Felker 提交于
      time64 syscall is used only if it's the only one defined for the arch,
      or if the requested time does not fit in 32 bits. on current 32-bit
      archs where time_t is a 32-bit type, this makes it statically
      unreachable.
      
      if the time64 syscall is needed because the requested time does not
      fit in 32 bits, we define this as an error ENOTSUP, for "The
      implementation does not support the requested feature or value".
      
      on 64-bit archs, there is no change to the code after preprocessing.
      on current 32-bit archs, the time is moved through an intermediate
      copy to remove the assumption that time_t is a 32-bit type.
      7aeecf3e
    • R
      timer_settime: add support for time64 syscall, decouple 32-bit time_t · e1501091
      Rich Felker 提交于
      time64 syscall is used only if it's the only one defined for the arch,
      if either component of the itimerspec does not fit in 32 bits, or if
      time_t is 64-bit and the caller requested the old value, in which case
      there's a possibility that the old value might not fit in 32 bits. on
      current 32-bit archs where time_t is a 32-bit type, this makes it
      statically unreachable.
      
      on 64-bit archs, there is no change to the code after preprocessing.
      on current 32-bit archs, the time is moved through an intermediate
      copy to remove the assumption that time_t is a 32-bit type.
      e1501091
    • R
      pselect, ppoll: add time64 syscall support, decouple 32-bit time_t · 22276671
      Rich Felker 提交于
      time64 syscall is used only if it's the only one defined for the arch,
      or if the requested timeout length does not fit in 32 bits. on current
      32-bit archs where time_t is a 32-bit type, this makes it statically
      unreachable.
      
      on 64-bit archs, there are only superficial changes to the code after
      preprocessing. both before and after these changes, these functions
      copied their timeout arguments to avoid letting the kernel clobber the
      caller's copies. now, the copying also serves to change the type from
      userspace timespec to a pair of longs, which makes a difference only
      in the 32-bit fallback case, not on 64-bit.
      22276671
    • R
      futex wait operations: add time64 syscall support, decouple 32-bit time_t · 1492bdf5
      Rich Felker 提交于
      thanks to the original factorization using the __timedwait function,
      there are no FUTEX_WAIT calls anywhere else, giving us a single point
      of change to make nearly all the timed thread primitives time64-ready.
      the one exception is the FUTEX_LOCK_PI command for PI mutex timedlock.
      I haven't tried to make these two points share code, since they have
      different fallbacks (no non-private fallback needed for PI since PI
      was added later) and FUTEX_LOCK_PI isn't a cancellation point (thus
      allowing the whole code path to inline into pthread_mutex_timedlock).
      
      as for other changes in this series, the time64 syscall is used only
      if it's the only one defined for the arch, or if the requested timeout
      does not fit in 32 bits. on current 32-bit archs where time_t is a
      32-bit type, this makes it statically unreachable.
      
      on 64-bit archs, there are only superficial changes to the code after
      preprocessing. on current 32-bit archs, the time is passed via an
      intermediate copy to remove the assumption that time_t is a 32-bit
      type.
      1492bdf5
    • R
      semtimedop: add time64 syscall support, decouple 32-bit time_t · eb2e298c
      Rich Felker 提交于
      time64 syscall is used only if it's the only one defined for the arch,
      or if the requested timeout does not fit in 32 bits. on current 32-bit
      archs where time_t is a 32-bit type, this makes it statically
      unreachable.
      
      on 64-bit archs, there is no change to the code after preprocessing.
      on current 32-bit archs, the time is passed via an intermediate copy
      to remove the assumption that time_t is a 32-bit type.
      
      to avoid duplicating SYS_ipc/SYS_semtimedop choice logic, the code for
      32-bit archs "falls through" after updating the timeout argument ts to
      point to a [compound literal] array of longs. in preparation for
      "time64-only" 32-bit archs, an extra case is added for neither SYS_ipc
      nor the non-time64 SYS_semtimedop existing; the ENOSYS failure path
      here should never be reachable, and is added just in case a compiler
      can't see that it's not reachable, to avoid spurious static analysis
      complaints.
      eb2e298c
    • R
      sigtimedwait: add time64 syscall support, decouple 32-bit time_t · 68c98391
      Rich Felker 提交于
      time64 syscall is used only if it's the only one defined for the arch,
      or if the requested timeout length does not fit in 32 bits. on current
      32-bit archs where time_t is a 32-bit type, this makes it statically
      unreachable.
      
      on 64-bit archs, there are only superficial changes to the code after
      preprocessing. on current 32-bit archs, the timeout is passed via an
      intermediate copy to remove the assumption that time_t is a 32-bit
      type.
      68c98391
    • R
      mq_timedsend, mq_timedreceive: add time64, decouple 32-bit time_t · 2ab90de7
      Rich Felker 提交于
      time64 syscall is used only if it's the only one defined for the arch,
      or if the requested absolute timeout does not fit in 32 bits. on
      current 32-bit archs where time_t is a 32-bit type, this makes it
      statically unreachable.
      
      on 64-bit archs, there is no change to the code after preprocessing.
      on current 32-bit archs, the timeout is passed via an intermediate
      copy to remove the assumption that time_t is a 32-bit type.
      2ab90de7
    • R
      clock_nanosleep: add time64 syscall support, decouple 32-bit time_t · 1334e366
      Rich Felker 提交于
      time64 syscall is used only if it's the only one defined for the arch,
      or if the requested time does not fit in 32 bits. on current 32-bit
      archs where time_t is a 32-bit type, this makes it statically
      unreachable.
      
      on 64-bit archs, there is no change to the code after preprocessing.
      on current 32-bit archs, the time is moved through an intermediate
      copy to remove the assumption that time_t is a 32-bit type.
      1334e366
  3. 28 7月, 2019 5 次提交
    • R
      implement settimeofday in terms of clock_settime, not old syscall · 2c2c3605
      Rich Felker 提交于
      this is yet another place where special handling of time syscalls can
      and should be avoided by implementing legacy functions in terms of
      their modern replacements. in theory a fallback to SYS_settimeofday
      could be added to clock_settime, but SYS_clock_settime has been
      available since Linux 2.6.0 or earlier, i.e. all the way back to the
      minimum supported version.
      2c2c3605
    • R
      internally, define plain syscalls, if missing, as their time64 variants · 4bbd7bae
      Rich Felker 提交于
      this commit has no effect whatsoever right now, but is in preparation
      for a future riscv32 port and other future 32-bit archs that will be
      "time64-only" from the start on the kernel side.
      
      together with the previous x32 changes, this commit ensures that
      syscall call points that don't care about time (passing null timeouts,
      etc.) can continue to do so without having to special-case time64-only
      archs, and allows code using the time64 syscalls to uniformly test for
      the need to fallback with SYS_foo != SYS_foo_time64, rather than
      needing to check defined(SYS_foo) && SYS_foo != SYS_foo_time64.
      4bbd7bae
    • R
      internally, define time64 syscalls on x32 as the existing syscalls · 40aa18d5
      Rich Felker 提交于
      x32 is odd in that it's the only ILP32 arch/ABI we have where time_t
      is 64-bit rather than (32-bit) long, and this has always been
      problematic in that it results in struct timespec having unused
      padding space, since tv_nsec has type long, which the kernel insists
      be zero- or sign-extended (due to negative tv_nsec being invalid, it
      doesn't matter which) to match the x86_64 type.
      
      up til now, we've had really ugly hacks in x32/syscall_arch.h to patch
      up the timespecs passed to the kernel. but the same requirement to
      zero- or sign-extend tv_nsec also applies to all the new time64
      syscalls on true 32-bit archs. so let's take advantage of this to
      clean things up.
      
      this patch defines all of the time64 syscalls for x32 as aliases for
      the existing syscalls by the same name. this establishes the following
      invariants:
      
      - if the time64 form is defined, it takes time arguments as 64-bit
        objects, and tv_nsec inputs must be zero-/sign-extended to 64-bit.
      
      - if the time64 form is not defined, or if the time64 form is defined
        and is not equal to the "plain" form, the plain form takes time
        arguments as longs.
      
      this will avoid the need for protocols for archs to define appropriate
      types for each family of syscalls, and for the reader of the code to
      have to be aware of such type definitions.
      
      in some sense it might be simpler if the plain syscall form were
      undefined for x32, so that it would always take longs if defined.
      however, a number of these syscalls are used in contexts with a null
      time argument, or (e.g. futex) for commands that don't involve time at
      all, and having to introduce time64-specific logic to all those call
      points does not make sense. thus, while the "plain" forms are kept now
      just because they're needed until the affected code is converted over,
      they'll also almost surely be kept in the future as well.
      40aa18d5
    • R
      don't use futimesat syscall as utimensat fallback on x32 · b93183e3
      Rich Felker 提交于
      kernel support for x32 was added long after the utimensat syscall was
      already available, so having a fallback is just wasted code size.
      
      also, for changes related to time64 support on 32-bit archs, I want to
      be able to assume the old futimesat syscall always works with longs,
      which is true except for x32. by ensuring that it's not used on x32,
      the needed invariant is established.
      b93183e3
    • R
      fix and simplify futimesat fallback in utimensat · cb856a61
      Rich Felker 提交于
      previously the fallback wrongly failed with EINVAL rather than ENOSYS
      when UTIME_NOW was used with one component but not both. commit
      dd5f50da introduced this behavior when
      initially adding the fallback support.
      
      instead, detect the case where both are UTIME_NOW early and replace
      with a null times pointer; this may improve performance slightly (less
      copy from user), and removes the complex logic from the fallback case.
      it also makes things slightly simpler for adding time64 code paths.
      cb856a61
  4. 27 7月, 2019 1 次提交
    • R
      refactor thrd_sleep and nanosleep in terms of clock_nanosleep · 331993e3
      Rich Felker 提交于
      for namespace-safety with thrd_sleep, this requires an alias, which is
      also added. this eliminates all but one direct call point for
      nanosleep syscalls, and arranges that 64-bit time_t conversion logic
      will only need to exist in one file rather than three.
      
      as a bonus, clock_nanosleep with CLOCK_REALTIME and empty flags is now
      implemented as SYS_nanosleep, thereby working on older kernels that
      may lack POSIX clocks functionality.
      331993e3
  5. 21 7月, 2019 3 次提交
    • S
      use the correct stat structure in the fstat path · 0ce49d0a
      Samuel Holland 提交于
      commit 01ae3fc6 modified fstatat to
      translate the kernel's struct stat ("kstat") into the libc struct stat.
      To do this, it created a local kstat object, and copied its contents
      into the user-provided object.
      
      However, the commit neglected to update the fstat compatibility path and
      its fallbacks. They continued to pass the user-supplied object to the
      kernel, later overwiting it with the uninitialized memory in the local
      temporary.
      0ce49d0a
    • R
      refactor adjtime function using adjtimex function instead of syscall · e53a91da
      Rich Felker 提交于
      this removes the assumption that userspace struct timex matches the
      syscall type and sets the stage for 64-bit time_t on 32-bit archs.
      e53a91da
    • R
      refactor adjtimex in terms of clock_adjtime · 107d68ad
      Rich Felker 提交于
      this sets the stage for having the conversion logic for 64-bit time_t
      all in one file, and as a bonus makes clock_adjtime for CLOCK_REALTIME
      work even on kernels too old to have the clock_adjtime syscall.
      107d68ad
  6. 19 7月, 2019 5 次提交