1. 19 4月, 2011 1 次提交
  2. 18 4月, 2011 9 次提交
    • R
      fix typo in x86_64 cancellable syscall asm · 1bc44a47
      Rich Felker 提交于
      1bc44a47
    • R
      pthread_exit is not supposed to affect cancellability · 2afed79f
      Rich Felker 提交于
      if the exit was caused by cancellation, __cancel has already set these
      flags anyway.
      2afed79f
    • R
      fix pthread_exit from cancellation handler · 1ebde9c3
      Rich Felker 提交于
      cancellation frames were not correctly popped, so this usage would not
      only loop, but also reuse discarded and invalid parts of the stack.
      1ebde9c3
    • R
      clean up handling of thread/nothread mode, locking · 9080cc15
      Rich Felker 提交于
      9080cc15
    • R
      debloat: use __syscall instead of syscall where possible · eb0e8fa0
      Rich Felker 提交于
      don't waste time (and significant code size due to function call
      overhead!) setting errno when the result of a syscall does not matter
      or when it can't fail.
      eb0e8fa0
    • R
      fix bugs in cancellable syscall asm · 09dae2b7
      Rich Felker 提交于
      x86_64 was just plain wrong in the cancel-flag-already-set path, and
      crashing.
      
      the more subtle error was not clearing the saved stack pointer before
      returning to c code. this could result in the signal handler
      misidentifying c code as the pre-syscall part of the asm, and acting
      on cancellation at the wrong time, and thus resource leak race
      conditions.
      
      also, now __cancel (in the c code) is responsible for clearing the
      saved sp in the already-cancelled branch. this means we have to use
      call rather than jmp to ensure the stack pointer in the c will never
      match what the asm saved.
      09dae2b7
    • R
      optimize cancellation enable/disable code · ebf82447
      Rich Felker 提交于
      the goal is to be able to use pthread_setcancelstate internally in
      the implementation, whenever a function might want to use functions
      which are cancellation points but avoid becoming a cancellation point
      itself. i could have just used a separate internal function for
      temporarily inhibiting cancellation, but the solution in this commit
      is better because (1) it's one less implementation-specific detail in
      functions that need to use it, and (2) application code can also get
      the same benefit.
      
      previously, pthread_setcancelstate dependend on pthread_self, which
      would pull in unwanted thread setup overhead for non-threaded
      programs. now, it temporarily stores the state in the global libc
      struct if threads have not been initialized, and later moves it if
      needed. this way we can instead use __pthread_self, which has no
      dependencies and assumes that the thread register is already valid.
      ebf82447
    • R
      02eff258
    • R
      fix some minor issues in cancellation handling patch · e7466401
      Rich Felker 提交于
      signals were wrongly left masked, and cancellability state was not
      switched to disabled, during the execution of cleanup handlers.
      e7466401
  3. 17 4月, 2011 1 次提交
    • R
      overhaul pthread cancellation · feee9890
      Rich Felker 提交于
      this patch improves the correctness, simplicity, and size of
      cancellation-related code. modulo any small errors, it should now be
      completely conformant, safe, and resource-leak free.
      
      the notion of entering and exiting cancellation-point context has been
      completely eliminated and replaced with alternative syscall assembly
      code for cancellable syscalls. the assembly is responsible for setting
      up execution context information (stack pointer and address of the
      syscall instruction) which the cancellation signal handler can use to
      determine whether the interrupted code was in a cancellable state.
      
      these changes eliminate race conditions in the previous generation of
      cancellation handling code (whereby a cancellation request received
      just prior to the syscall would not be processed, leaving the syscall
      to block, potentially indefinitely), and remedy an issue where
      non-cancellable syscalls made from signal handlers became cancellable
      if the signal handler interrupted a cancellation point.
      
      x86_64 asm is untested and may need a second try to get it right.
      feee9890
  4. 15 4月, 2011 3 次提交
  5. 14 4月, 2011 1 次提交
    • R
      simplify cancellation point handling · 9beb6330
      Rich Felker 提交于
      we take advantage of the fact that unless self->cancelpt is 1,
      cancellation cannot happen. so just increment it by 2 to temporarily
      block cancellation. this drops pthread_create.o well under 1k.
      9beb6330
  6. 07 4月, 2011 6 次提交
  7. 06 4月, 2011 1 次提交
    • R
      new framework to inhibit thread cancellation when needed · 729cb49f
      Rich Felker 提交于
      with these small changes, libc functions which need to call functions
      which are cancellation points, but which themselves must not be
      cancellation points, can use the CANCELPT_INHIBIT and CANCELPT_RESUME
      macros to temporarily inhibit all cancellation.
      729cb49f
  8. 04 4月, 2011 5 次提交
    • R
      pthread_create need not set errno · 7fd39952
      Rich Felker 提交于
      7fd39952
    • R
      block all signals during rsyscall · 66def4e7
      Rich Felker 提交于
      otherwise a signal handler could see an inconsistent and nonconformant
      program state where different threads have different uids/gids.
      66def4e7
    • R
      fix race condition in rsyscall handler · 1ad049b7
      Rich Felker 提交于
      the problem: there is a (single-instruction) race condition window
      between a thread flagging itself dead and decrementing itself from the
      thread count. if it receives the rsyscall signal at this exact moment,
      the rsyscall caller will never succeed in signalling enough flags to
      succeed, and will deadlock forever. in previous versions of musl, the
      about-to-terminate thread masked all signals prior to decrementing
      the thread count, but this cost a whole syscall just to account for
      extremely rare races.
      
      the solution is a huge hack: rather than blocking in the signal
      handler if the thread is dead, modify the signal mask of the saved
      context and return in order to prevent further signal handling by the
      dead thread. this allows the dead thread to continue decrementing the
      thread count (if it had not yet done so) and exiting, even while the
      live part of the program blocks for rsyscall.
      1ad049b7
    • R
      don't trust siginfo in rsyscall handler · c9b2d801
      Rich Felker 提交于
      for some inexplicable reason, linux allows the sender of realtime
      signals to spoof its identity. permission checks for sending signals
      should limit the impact to same-user processes, but just to be safe,
      we avoid trusting the siginfo structure and instead simply examine the
      program state to see if we're in the middle of a legitimate rsyscall.
      c9b2d801
    • R
      simplify calling of timer signal handler · f01d3518
      Rich Felker 提交于
      f01d3518
  9. 03 4月, 2011 2 次提交
  10. 02 4月, 2011 4 次提交
  11. 01 4月, 2011 2 次提交
  12. 30 3月, 2011 5 次提交
    • R
      avoid crash on stupid but allowable usage of pthread_mutex_unlock · a1eb8cb5
      Rich Felker 提交于
      unlocking an unlocked mutex is not UB for robust or error-checking
      mutexes, so we must avoid calling __pthread_self (which might crash
      due to lack of thread-register initialization) until after checking
      that the mutex is locked.
      a1eb8cb5
    • R
      streamline mutex unlock to remove a useless branch, use a_store to unlock · 02084109
      Rich Felker 提交于
      this roughly halves the cost of pthread_mutex_unlock, at least for
      non-robust, normal-type mutexes.
      
      the a_store change is in preparation for future support of archs which
      require a memory barrier or special atomic store operation, and also
      should prevent the possibility of the compiler misordering writes.
      02084109
    • R
      cheap special-case optimization for normal mutexes · 124b4ebc
      Rich Felker 提交于
      cycle-level benchmark on atom cpu showed typical pthread_mutex_lock
      call dropping from ~120 cycles to ~90 cycles with this change. benefit
      may vary with compiler options and version, but this optimization is
      very cheap to make and should always help some.
      124b4ebc
    • R
      8524d653
    • R
      major improvements to cancellation handling · bf619d82
      Rich Felker 提交于
      - there is no longer any risk of spoofing cancellation requests, since
        the cancel flag is set in pthread_cancel rather than in the signal
        handler.
      
      - cancellation signal is no longer unblocked when running the
        cancellation handlers. instead, pthread_create will cause any new
        threads created from a cancellation handler to unblock their own
        cancellation signal.
      
      - various tweaks in preparation for POSIX timer support.
      bf619d82