1. 02 4月, 2019 1 次提交
  2. 01 4月, 2019 1 次提交
    • R
      implement priority inheritance mutexes · 54ca6779
      Rich Felker 提交于
      priority inheritance is a feature to mitigate priority inversion
      situations, where a execution of a medium-priority thread can
      unboundedly block forward progress of a high-priority thread when a
      lock it needs is held by a low-priority thread.
      
      the natural way to do priority inheritance would be with a simple
      futex flag to donate the calling thread's priority to a target thread
      while it waits on the futex. unfortunately, linux does not offer such
      an interface, but instead insists on implementing the whole locking
      protocol in kernelspace with special futex commands that exist solely
      for the purpose of doing PI mutexes. this would require the entire
      "trylock" logic to be duplicated in the timedlock code path for PI
      mutexes, since, once the previous lock holder releases the lock and
      the futex call returns, the lock is already held by the caller.
      obviously such code duplication is undesirable.
      
      instead, I've made the PI timedlock success path set the mutex lock
      count to -1, which can be thought of as "not yet complete", since a
      lock count of 0 is "locked, with no recursive references". a simple
      branch in a non-hot path of pthread_mutex_trylock can then see and act
      on this state, skipping past the code that would check and take the
      lock to the same code path that runs after the lock is obtained for a
      non-PI mutex.
      
      because we're forced to let the kernel perform the actual lock and
      unlock operations whenever the mutex is contended, we have to patch
      things up when it does the wrong thing:
      
      1. the lock operation is not aware of whether the mutex is
         error-checking, so it will always fail with EDEADLK rather than
         deadlocking.
      
      2. the lock operation is not aware of whether the mutex is robust, so
         it will successfully obtain mutexes in the owner-died state even if
         they're non-robust, whereas this operation should deadlock.
      
      3. the unlock operation always sets the lock value to zero, whereas
         for robust mutexes, we want to set it to a special value indicating
         that the mutex obtained after its owner died was unlocked without
         marking it consistent, so that future operations all fail with
         ENOTRECOVERABLE.
      
      the first of these is easy to solve, just by performing a futex wait
      on a dummy futex address to simulate deadlock or ETIMEDOUT as
      appropriate. but problems 2 and 3 interact in a nasty way. to solve
      problem 2, we need to back out the spurious success. but if waiters
      are present -- which we can't just ignore, because even if we don't
      want to wake them, the calling thread is incorrectly inheriting their
      priorities -- this requires using the kernel's unlock operation, which
      will zero the lock value, thereby losing the "owner died with lock
      held" state.
      
      to solve these problems, we overload the mutex's waiters field, which
      is unused for PI mutexes since they don't call the normal futex wait
      functions, as an indicator that the PI mutex is permanently
      non-lockable. originally I wanted to use the count field, but there is
      one code path that needs to access this flag without synchronization:
      trylock's CAS failure path needs to be able to decide whether to fail
      with EBUSY or ENOTRECOVERABLE, the waiters field is already treated as
      a relaxed-order atomic in our memory model, so this works out nicely.
      54ca6779
  3. 30 3月, 2019 1 次提交
    • R
      clean up access to mutex type in pthread_mutex_trylock · 2142cafd
      Rich Felker 提交于
      there was no point in masking off the pshared bit when first loading
      the type, since every subsequent access involves a mask anyway. not
      masking it may avoid a subsequent load to check the pshared flag, and
      it's just simpler.
      2142cafd
  4. 22 3月, 2019 3 次提交
  5. 15 3月, 2019 1 次提交
    • R
      fix crash/out-of-bound read in sscanf · 8f12c4e1
      Rich Felker 提交于
      commit d6c855ca caused this
      "regression", though the behavior was undefined before, overlooking
      that f->shend=0 was being used as a sentinel for "EOF" status (actual
      EOF or hitting the scanf field width) of the stream helper (shgetc)
      functions.
      
      obviously the shgetc macro could be adjusted to check for a null
      pointer in addition to the != comparison, but it's the hot path, and
      adding extra code/branches to it begins to defeat the purpose.
      
      so instead of setting shend to a null pointer to block further reads,
      which no longer works, set it to the current position (rpos). this
      makes the shgetc macro work with no change, but it breaks shunget,
      which can no longer look at the value of shend to determine whether to
      back up. Szabolcs Nagy suggested a solution which I'm using here:
      setting shlim to a negative value is inexpensive to test at shunget
      time, and automatically re-trips the cnt>=shlim stop condition in
      __shgetc no matter what the original limit was.
      8f12c4e1
  6. 14 3月, 2019 22 次提交
  7. 13 3月, 2019 5 次提交
    • R
      handle labels with 8-bit byte values in dn_skipname · 2a0ff45b
      Ryan Fairfax 提交于
      The original logic considered each byte until it either found a 0
      value or a value >= 192. This means if a string segment contained any
      byte >= 192 it was interepretted as a compressed segment marker even
      if it wasn't in a position where it should be interpretted as such.
      
      The fix is to adjust dn_skipname to increment by each segments size
      rather than look at each character. This avoids misinterpretting
      string segment characters by not considering those bytes.
      2a0ff45b
    • J
      fix POSIX_FADV_DONTNEED/_NOREUSE on s390x · 4b125dd4
      Jonathan Neuschäfer 提交于
      On s390x, POSIX_FADV_DONTNEED and POSIX_FADV_NOREUSE have different
      values than on all other architectures that Linux supports.
      
      Handle this difference by wrapping their definitions in
      include/fcntl.h in #ifdef, so that arch/s390x/bits/fcntl.h can
      override them.
      4b125dd4
    • R
      expose TSVTX unconditionally in tar.h · 81221e13
      Rich Felker 提交于
      as noted in Austin Group issue #1236, the XSI shading for TSVTX is
      misplaced in the html version of the standard; it was only supposed to
      be on the description text. the intent was that the definition always
      be visible, which is reflected in the pdf version of the standard.
      
      this reverts commits d93c0740 and
      729fef0a.
      81221e13
    • A
      setvbuf: return failure if mode is invalid · 00d3d577
      A. Wilcox 提交于
      POSIX requires setvbuf to return non-zero if `mode` is not one of _IONBF,
      _IOLBF, or _IOFBF.
      00d3d577
    • R
      make FILE a complete type for pre-C11 standard profiles · f368d9fd
      Rich Felker 提交于
      C11 removed the requirement that FILE be a complete type, which was
      deemed erroneous, as part of the changes introduced by N1439 regarding
      completeness of types (see footnote 6 for specific mention of FILE).
      however the current version of POSIX is still based on C99 and
      incorporates the old requirement that FILE be a complete type.
      
      expose an arbitrary, useless complete type definition because the
      actual object used to represent FILE streams cannot be public/ABI.
      
      thanks to commit 13d1afa4, we now have
      a framework for suppressing the public complete-type definition of FILE
      when stdio.h is included internally, so that a different internal
      definition can be provided. this is perfectly well-defined, since the
      same struct tag can refer to different types in different translation
      units. it would be a problem if the implementation were accessing the
      application's FILE objects or vice versa, but either would be
      undefined behavior.
      f368d9fd
  8. 11 3月, 2019 1 次提交
    • R
      fix invalid-/double-/use-after-free in new dlopen ctor execution · 50cd0238
      Rich Felker 提交于
      this affected the error path where dlopen successfully found and
      loaded the requested dso and all its dependencies, but failed to
      resolve one or more relocations, causing the operation to fail after
      storage for the ctor queue was allocated.
      
      commit 188759bb wrongly put the free
      for the ctor_queue array in the error path inside a loop over each
      loaded dso that needed to be backed-out, rather than just doing it
      once. in addition, the exit path also observed the ctor_queue pointer
      still being nonzero, and would attempt to call ctors on the backed-out
      dsos unless the double-free crashed the process first.
      50cd0238
  9. 06 3月, 2019 1 次提交
    • R
      don't reject unknown/future flags in sigaltstack, allow SS_AUTODISARM · 4918b7fb
      Rich Felker 提交于
      historically, and likely accidentally, sigaltstack was specified to
      fail with EINVAL if any flag bit other than SS_DISABLE was set. the
      resolution of Austin Group issue 1187 fixes this so that the
      requirement is only to fail for SS_ONSTACK (which cannot be set) or
      "invalid" flags.
      
      Linux fails on the kernel side for invalid flags, but historically
      accepts SS_ONSTACK as a no-op, so it needs to be rejected in userspace
      still.
      
      with this change, the Linux-specific SS_AUTODISARM, provided since
      commit 9680e1d0 but unusable due to
      rejection at runtime, is now usable.
      4918b7fb
  10. 04 3月, 2019 4 次提交
    • R
      avoid malloc of ctor queue for programs with no external deps · 43e7efb4
      Rich Felker 提交于
      together with the previous two commits, this completes restoration of
      the property that dynamic-linked apps with no external deps and no tls
      have no failure paths before entry.
      43e7efb4
    • R
      avoid malloc of deps arrays for ldso and vdso · f034f145
      Rich Felker 提交于
      neither has or can have any dependencies, but since commit
      40355569, gratuitous zero-length deps
      arrays were being allocated for them. use a dummy array instead.
      f034f145
    • R
      avoid malloc of deps array for programs with no external deps · e612d094
      Rich Felker 提交于
      traditionally, we've provided a guarantee that dynamic-linked
      applications with no external dependencies (nothing but libc) and no
      thread-local storage have no failure paths before the entry point.
      normally, thanks to reclaim_gaps, such a malloc will not require a
      syscall anyway, but if segment alignment is unlucky, it might. use a
      builtin array for this common special case.
      e612d094
    • R
      fix malloc misuse for startup ctor queue, breakage on fdpic archs · 2f1f51ae
      Rich Felker 提交于
      in the case where malloc is being replaced, it's not valid to call
      malloc between final relocations and main app's crt1 entry point; on
      fdpic archs the main app's entry point will not yet have performed the
      self-fixups necessary to call its code.
      
      to fix, reorder queue_ctors before final relocations. an alternative
      solution would be doing the allocation from __libc_start_init, after
      the entry point but before any ctors run. this is less desirable,
      since it would leave a call to malloc that might be provided by the
      application happening at startup when doing so can be easily avoided.
      2f1f51ae