1. 13 8月, 2021 1 次提交
    • Z
      fix: 进程退出静态问题 · d7deb3fb
      zhushengle 提交于
      问题描述:
          进程在退出过程中,拿到了init_fini_lock锁后被信号打断,
      收到退出信号,再次调用exit函数进入进程退出流程,造成死锁
      
      解决方案:
          在libc中添加exit字段,在进程退出时将该字段表示进程已经在退出,
      若再次进入退出流程,则直接退出,由第一个执行退出流程的线程继续执行
      退出流程。并且在退出时屏蔽信号,避免退出流程被频繁打断。
      Close #I43V23
      Signed-off-by: Nzhushengle <zhushengle@huawei.com>
      
      Change-Id: I57b60391267d50c8eb89fc115a26229461bb4ed4
      d7deb3fb
  2. 11 6月, 2021 1 次提交
  3. 11 3月, 2021 1 次提交
  4. 09 9月, 2020 1 次提交
  5. 17 8月, 2020 1 次提交
  6. 01 7月, 2019 1 次提交
    • S
      fix deadlock in synccall after threaded fork · 84ebec6c
      Samuel Holland 提交于
      synccall may be called by AS-safe functions such as setuid/setgid after
      fork. although fork() resets libc.threads_minus_one, causing synccall to
      take the single-threaded path, synccall still takes the thread list
      lock. This lock may be held by another thread if for example fork()
      races with pthread_create(). After fork(), the value of the lock is
      meaningless, so clear it.
      
      maintainer's note: commit 8f11e612 and
      e4235d70 introduced this regression.
      the state protected by this lock is the linked list, which is entirely
      replaced in the child path of fork (next=prev=self), so resetting it
      is semantically sound.
      84ebec6c
  7. 16 2月, 2019 1 次提交
    • R
      track all live threads in an AS-safe, fully-consistent linked list · 8f11e612
      Rich Felker 提交于
      the hard problem here is unlinking threads from a list when they exit
      without creating a window of inconsistency where the kernel task for a
      thread still exists and is still executing instructions in userspace,
      but is not reflected in the list. the magic solution here is getting
      rid of per-thread exit futex addresses (set_tid_address), and instead
      using the exit futex to unlock the global thread list.
      
      since pthread_join can no longer see the thread enter a detach_state
      of EXITED (which depended on the exit futex address pointing to the
      detach_state), it must now observe the unlocking of the thread list
      lock before it can unmap the joined thread and return. it doesn't
      actually have to take the lock. for this, a __tl_sync primitive is
      offered, with a signature that will allow it to be enhanced for quick
      return even under contention on the lock, if needed. for now, the
      exiting thread always performs a futex wake on its detach_state. a
      future change could optimize this out except when there is already a
      joiner waiting.
      
      initial/dynamic variants of detached state no longer need to be
      tracked separately, since the futex address is always set to the
      global list lock, not a thread-local address that could become invalid
      on detached thread exit. all detached threads, however, must perform a
      second sigprocmask syscall to block implementation-internal signals,
      since locking the thread list with them already blocked is not
      permissible.
      
      the arch-independent C version of __unmapself no longer needs to take
      a lock or setup its own futex address to release the lock, since it
      must necessarily be called with the thread list lock already held,
      guaranteeing exclusive access to the temporary stack.
      
      changes to libc.threads_minus_1 no longer need to be atomic, since
      they are guarded by the thread list lock. it is largely vestigial at
      this point, and can be replaced with a cheaper boolean indicating
      whether the process is multithreaded at some point in the future.
      8f11e612
  8. 11 11月, 2017 1 次提交
  9. 14 4月, 2015 1 次提交
    • R
      remove remnants of support for running in no-thread-pointer mode · 19a1fe67
      Rich Felker 提交于
      since 1.1.0, musl has nominally required a thread pointer to be setup.
      most of the remaining code that was checking for its availability was
      doing so for the sake of being usable by the dynamic linker. as of
      commit 71f099cb, this is no longer
      necessary; the thread pointer is now valid before any libc code
      (outside of dynamic linker bootstrap functions) runs.
      
      this commit essentially concludes "phase 3" of the "transition path
      for removing lazy init of thread pointer" project that began during
      the 1.1.0 release cycle.
      19a1fe67
  10. 10 4月, 2015 1 次提交
    • R
      optimize out setting up robust list with kernel when not needed · 4e98cce1
      Rich Felker 提交于
      as a result of commit 12e1e324, kernel
      processing of the robust list is only needed for process-shared
      mutexes. previously the first attempt to lock any owner-tracked mutex
      resulted in robust list initialization and a set_robust_list syscall.
      this is no longer necessary, and since the kernel's record of the
      robust list must now be cleared at thread exit time for detached
      threads, optimizing it out is more worthwhile than before too.
      4e98cce1
  11. 06 7月, 2014 1 次提交
    • R
      eliminate use of cached pid from thread structure · 83dc6eb0
      Rich Felker 提交于
      the main motivation for this change is to remove the assumption that
      the tid of the main thread is also the pid of the process. (the value
      returned by the set_tid_address syscall was used to fill both fields
      despite it semantically being the tid.) this is historically and
      presently true on linux and unlikely to change, but it conceivably
      could be false on other systems that otherwise reproduce the linux
      syscall api/abi.
      
      only a few parts of the code were actually still using the cached pid.
      in a couple places (aio and synccall) it was a minor optimization to
      avoid a syscall. caching could be reintroduced, but lazily as part of
      the public getpid function rather than at program startup, if it's
      deemed important for performance later. in other places (cancellation
      and pthread_kill) the pid was completely unnecessary; the tkill
      syscall can be used instead of tgkill. this is actually a rather
      subtle issue, since tgkill is supposedly a solution to race conditions
      that can affect use of tkill. however, as documented in the commit
      message for commit 7779dbd2, tgkill
      does not actually solve this race; it just limits it to happening
      within one process rather than between processes. we use a lock that
      avoids the race in pthread_kill, and the use in the cancellation
      signal handler is self-targeted and thus not subject to tid reuse
      races, so both are safe regardless of which syscall (tgkill or tkill)
      is used.
      83dc6eb0
  12. 30 5月, 2014 1 次提交
    • R
      support linux kernel apis (new archs) with old syscalls removed · dd5f50da
      Rich Felker 提交于
      such archs are expected to omit definitions of the SYS_* macros for
      syscalls their kernels lack from arch/$ARCH/bits/syscall.h. the
      preprocessor is then able to select the an appropriate implementation
      for affected functions. two basic strategies are used on a
      case-by-case basis:
      
      where the old syscalls correspond to deprecated library-level
      functions, the deprecated functions have been converted to wrappers
      for the modern function, and the modern function has fallback code
      (omitted at the preprocessor level on new archs) to make use of the
      old syscalls if the new syscall fails with ENOSYS. this also improves
      functionality on older kernels and eliminates the incentive to program
      with deprecated library-level functions for the sake of compatibility
      with older kernels.
      
      in other situations where the old syscalls correspond to library-level
      functions which are not deprecated but merely lack some new features,
      such as the *at functions, the old syscalls are still used on archs
      which support them. this may change at some point in the future if or
      when fallback code is added to the new functions to make them usable
      (possibly with reduced functionality) on old kernels.
      dd5f50da
  13. 25 3月, 2014 1 次提交
    • R
      always initialize thread pointer at program start · dab441ae
      Rich Felker 提交于
      this is the first step in an overhaul aimed at greatly simplifying and
      optimizing everything dealing with thread-local state.
      
      previously, the thread pointer was initialized lazily on first access,
      or at program startup if stack protector was in use, or at certain
      random places where inconsistent state could be reached if it were not
      initialized early. while believed to be fully correct, the logic was
      fragile and non-obvious.
      
      in the first phase of the thread pointer overhaul, support is retained
      (and in some cases improved) for systems/situation where loading the
      thread pointer fails, e.g. old kernels.
      
      some notes on specific changes:
      
      - the confusing use of libc.main_thread as an indicator that the
        thread pointer is initialized is eliminated in favor of an explicit
        has_thread_pointer predicate.
      
      - sigaction no longer needs to ensure that the thread pointer is
        initialized before installing a signal handler (this was needed to
        prevent a situation where the signal handler caused the thread
        pointer to be initialized and the subsequent sigreturn cleared it
        again) but it still needs to ensure that implementation-internal
        thread-related signals are not blocked.
      
      - pthread tsd initialization for the main thread is deferred in a new
        manner to minimize bloat in the static-linked __init_tp code.
      
      - pthread_setcancelstate no longer needs special handling for the
        situation before the thread pointer is initialized. it simply fails
        on systems that cannot support a thread pointer, which are
        non-conforming anyway.
      
      - pthread_cleanup_push/pop now check for missing thread pointer and
        nop themselves out in this case, so stdio no longer needs to avoid
        the cancellable path when the thread pointer is not available.
      
      a number of cases remain where certain interfaces may crash if the
      system does not support a thread pointer. at this point, these should
      be limited to pthread interfaces, and the number of such cases should
      be fewer than before.
      dab441ae
  14. 09 8月, 2013 1 次提交
    • R
      block signals during fork · d4d6d6f3
      Rich Felker 提交于
      there are several reasons for this. some of them are related to race
      conditions that arise since fork is required to be async-signal-safe:
      if fork or pthread_create is called from a signal handler after the
      fork syscall has returned but before the subsequent userspace code has
      finished, inconsistent state could result. also, there seem to be
      kernel and/or strace bugs related to arrival of signals during fork,
      at least on some versions, and simply blocking signals eliminates the
      possibility of such bugs.
      d4d6d6f3
  15. 09 11月, 2012 1 次提交
    • R
      clean up sloppy nested inclusion from pthread_impl.h · efd4d87a
      Rich Felker 提交于
      this mirrors the stdio_impl.h cleanup. one header which is not
      strictly needed, errno.h, is left in pthread_impl.h, because since
      pthread functions return their error codes rather than using errno,
      nearly every single pthread function needs the errno constants.
      
      in a few places, rather than bringing in string.h to use memset, the
      memset was replaced by direct assignment. this seems to generate much
      better code anyway, and makes many functions which were previously
      non-leaf functions into leaf functions (possibly eliminating a great
      deal of bloat on some platforms where non-leaf functions require ugly
      prologue and/or epilogue).
      efd4d87a
  16. 07 8月, 2011 1 次提交
  17. 17 7月, 2011 1 次提交
  18. 21 4月, 2011 1 次提交
    • R
      fix minor bugs due to incorrect threaded-predicate semantics · 870cc679
      Rich Felker 提交于
      some functions that should have been testing whether pthread_self()
      had been called and initialized the thread pointer were instead
      testing whether pthread_create() had been called and actually made the
      program "threaded". while it's unlikely any mismatch would occur in
      real-world problems, this could have introduced subtle bugs. now, we
      store the address of the main thread's thread descriptor in the libc
      structure and use its presence as a flag that the thread register is
      initialized. note that after fork, the calling thread (not necessarily
      the original main thread) is the new main thread.
      870cc679
  19. 18 4月, 2011 1 次提交
  20. 13 4月, 2011 1 次提交
    • R
      speed up threaded fork · e2915eee
      Rich Felker 提交于
      after fork, we have a new process and the pid is equal to the tid of
      the new main thread. there is no need to make two separate syscalls to
      obtain the same number.
      e2915eee
  21. 20 3月, 2011 1 次提交
  22. 10 3月, 2011 1 次提交
  23. 19 2月, 2011 1 次提交
    • R
      add pthread_atfork interface · e9417fff
      Rich Felker 提交于
      note that this presently does not handle consistency of the libc's own
      global state during forking. as per POSIX 2008, if the parent process
      was threaded, the child process may only call async-signal-safe
      functions until one of the exec-family functions is called, so the
      current behavior is believed to be conformant even if non-ideal. it
      may be improved at some later time.
      e9417fff
  24. 12 2月, 2011 1 次提交