1. 03 4月, 2014 4 次提交
    • R
      add __sigsetjmp ABI-compat alias for sigsetjmp · b9b2db2f
      Rich Felker 提交于
      b9b2db2f
    • S
      remove struct elem entirely from hsearch.c · 141d3b5c
      sin 提交于
      There are two changes here, both of which make sense to be done in a
      single patch:
      
      - Remove hash from struct elem and compute it at runtime wherever
        necessary.
      - Eliminate struct elem and use ENTRY directly.
      
      As a result we cut down on the memory usage as each element in the
      hash table now contains only an ENTRY not an ENTRY + size_t for the
      hash. The downside is that the hash needs to be computed at runtime.
      141d3b5c
    • S
      implement hcreate_r, hdestroy_r and hsearch_r · fe1ba7db
      sin 提交于
      the size and alignment of struct hsearch_data are matched to the glibc
      definition for binary compatibility. the members of the structure do
      not match, which should not be a problem as long as applications
      correctly treat the structure as opaque.
      
      unlike the glibc implementation, this version of hcreate_r does not
      require the caller to zero-fill the structure before use.
      fe1ba7db
    • R
      avoid malloc failure for small requests when brk can't be extended · 54463033
      Rich Felker 提交于
      this issue mainly affects PIE binaries and execution of programs via
      direct invocation of the dynamic linker binary: depending on kernel
      behavior, in these cases the initial brk may be placed at at location
      where it cannot be extended, due to conflicting adjacent maps.
      
      when brk fails, mmap is used instead to expand the heap. in order to
      avoid expensive bookkeeping for managing fragmentation by merging
      these new heap regions, the minimum size for new heap regions
      increases exponentially in the number of regions. this limits the
      number of regions, and thereby the number of fixed fragmentation
      points, to a quantity which is logarithmic with respect to the size of
      virtual address space and thus negligible. the exponential growth is
      tuned so as to avoid expanding the heap by more than approximately 50%
      of its current total size.
      54463033
  2. 26 3月, 2014 5 次提交
  3. 25 3月, 2014 3 次提交
    • R
      fix pointer type mismatch and misplacement of const · 689e0e6b
      Rich Felker 提交于
      689e0e6b
    • T
      fix confstr return value · 0a8d9828
      Timo Teräs 提交于
      per the specification, the terminating null byte is counted.
      0a8d9828
    • 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
  4. 24 3月, 2014 2 次提交
    • R
      reduce static linking overhead from TLS support by inlining mmap syscall · 98221c36
      Rich Felker 提交于
      the external mmap function is heavy because it has to handle error
      reporting that the kernel cannot do, and has to do some locking for
      arcane race-condition-avoidance purposes. for allocating initial TLS,
      we do not need any of that; the raw syscall suffices.
      
      on i386, this change shaves off 13% of the size of .text for the empty
      program.
      98221c36
    • R
      include header that declares __syscall_ret where it's defined · 30c1205a
      Rich Felker 提交于
      in general, we aim to always include the header that's declaring a
      function before defining it so that the compiler can check that
      prototypes match.
      
      additionally, the internal syscall.h declares __syscall_ret with a
      visibility attribute to improve code generation for shared libc (to
      prevent gratuitous GOT-register loads). this declaration should be
      visible at the point where __syscall_ret is defined, too, or the
      inconsistency could theoretically lead to problems at link-time.
      30c1205a
  5. 19 3月, 2014 2 次提交
  6. 17 3月, 2014 1 次提交
    • R
      fix negated error codes from ptsname_r · 66193171
      Rich Felker 提交于
      the incorrect error codes also made their way into errno when
      __ptsname_r was called by plain ptsname, which reports errors via
      errno rather than a return value.
      66193171
  7. 14 3月, 2014 1 次提交
    • R
      semctl: fix UB causing crashes on powerpc · 2b47a7af
      rofl0r 提交于
      it's UB to fetch variadic args when none are passed, and this caused
      real crashes on ppc due to its calling convention, which defines that
      for variadic functions aggregate types be passed as pointers.
      the assignment caused that pointer to get dereferenced, resulting in
      a crash.
      2b47a7af
  8. 09 3月, 2014 2 次提交
    • R
      fix incorrect rounding in printf floating point corner cases · 9743a399
      Rich Felker 提交于
      the printf floating point formatting code contains an optimization to
      avoid computing digits that will be thrown away by rounding at the
      specified (or default) precision. while it was correctly retaining all
      places up to the last decimal place to be printed, it was not
      retaining enough precision to see the next nonzero decimal place in
      all cases. this could cause incorrect rounding down in round-to-even
      (default) rounding mode, for example, when printing 0.5+DBL_EPSILON
      with "%.0f".
      
      in the fix, LDBL_MANT_DIG/3 is a lazy (non-sharp) upper bound on the
      number of zeros between any two nonzero decimal digits.
      9743a399
    • R
      fix buffer overflow in printf formatting of denormals with low bit set · ba231cf9
      Rich Felker 提交于
      empirically the overflow was an off-by-one, and it did not seem to be
      overwriting meaningful data. rather than simply increasing the buffer
      size by one, however, I have attempted to make the size obviously
      correct in terms of bounds on the number of iterations for the loops
      that fill the buffer. this still results in no more than a negligible
      size increase of the buffer on the stack (6-7 32-bit slots) and is a
      "safer" fix unless/until somebody wants to do the proof that a smaller
      buffer would suffice.
      ba231cf9
  9. 08 3月, 2014 1 次提交
    • R
      in fcntl, use unsigned long instead of long for variadic argument type · b576766d
      Rich Felker 提交于
      neither is correct; different commands take different argument types,
      and some take no arguments at all. I have a much larger overhaul of
      fcntl prepared to address this, but it's not appropriate to commit
      during freeze.
      
      the immediate problem being addressed affects forward-compatibility on
      x32: if new commands are added and they take pointers, but the
      libc-level fcntl function is not aware of them, using long would
      sign-extend the pointer to 64 bits and give the kernel an invalid
      pointer. on the kernel side, the argument to fcntl is always treated
      as unsigned long, so no harm is done by treating possibly-signed
      integer arguments as unsigned. for every command that takes an integer
      argument except for F_SETOWN, large integer arguments and negative
      arguments are handled identically anyway. in the case of F_SETOWN, the
      kernel is responsible for converting the argument which it received as
      unsigned long to int, so the sign of negative arguments is recovered.
      
      the other problem that will be addressed later is that the type passed
      to va_arg does not match the type in the caller of fcntl. an advanced
      compiler doing cross-translation-unit analysis could potentially see
      this mismatch and issue warnings or otherwise make trouble.
      
      on i386, this patch was confirmed not to alter the code generated by
      gcc 4.7.3. in principle the generated code should not be affected on
      any arch except x32.
      b576766d
  10. 06 3月, 2014 2 次提交
    • R
      x32: fix sysinfo() · dae8ca73
      rofl0r 提交于
      the kernel uses long longs in the struct, but the documentation
      says they're long. so we need to fixup the mismatch between the
      userspace and kernelspace structs.
      since the struct offers a mem_unit member, we can avoid truncation
      by adjusting that value.
      dae8ca73
    • R
      fix strerror on mips: one error code is out of the 8-bit table range · abdd2e48
      Rich Felker 提交于
      if we ever encounter other targets where error codes don't fit in the
      8-bit range, the table should probably just be bumped to 16-bit, but
      for now I don't want to increase the table size on all archs just
      because of a bug in the mips abi.
      abdd2e48
  11. 28 2月, 2014 2 次提交
  12. 26 2月, 2014 1 次提交
    • R
      fix readdir not to set ENOENT when directory is removed while reading · b9f7f2e8
      Rich Felker 提交于
      per POSIX, ENOENT is reserved for invalid stream position; it is an
      optional error and would only happen if the application performs
      invalid seeks on the underlying file descriptor. however, linux's
      getdents syscall also returns ENOENT if the directory was removed
      between the time it was opened and the time of the read. we need to
      catch this case and remap it to simple end-of-file condition (null
      pointer return value like an error, but no change to errno). this
      issue reportedly affects GNU make in certain corner cases.
      
      rather than backing up and restoring errno, I've just changed the
      syscall to be made in a way that doesn't affect errno (via an inline
      syscall rather than a call to the __getdents function). the latter
      still exists for the purpose of providing the public getdents alias
      which sets errno.
      b9f7f2e8
  13. 25 2月, 2014 2 次提交
    • R
      add missing sub files for mipsel-sf to use softfloat code · e7837ec7
      Rich Felker 提交于
      the build system has no automatic way to know this code applies to
      both big (default) and little endian variants, so explicit .sub files
      are needed.
      e7837ec7
    • S
      mips: add mips-sf subarch support (soft-float) · e5bb165b
      Szabolcs Nagy 提交于
      Userspace emulated floating-point (gcc -msoft-float) is not compatible
      with the default mips abi (assumes an FPU or in kernel emulation of it).
      Soft vs hard float abi should not be mixed, __mips_soft_float is checked
      in musl's configure script and there is no runtime check. The -sf subarch
      does not save/restore floating-point registers in setjmp/longjmp and only
      provides dummy fenv implementation.
      e5bb165b
  14. 24 2月, 2014 1 次提交
  15. 23 2月, 2014 3 次提交
  16. 22 2月, 2014 4 次提交
    • R
      3b168ce1
    • R
      internal/syscall.h: add syscall_arg_t macro · 5cc1d920
      rofl0r 提交于
      some 32-on-64 archs require that the actual syscall args be long long.
      in that case syscall_arch.h can define syscall_arg_t to whatever it needs
      and syscall.h picks it up.
      all other archs just use long as usual.
      5cc1d920
    • R
      internal/syscall.h: use a macro for the syscall args casts · bf84967c
      rofl0r 提交于
      this allows syscall_arch.h to define the macro __scc if special
      casting is needed, as is the case for x32, where the actual syscall
      arguments are 64bit, but, in case of pointers, would get sign-extended
      and thus become invalid.
      bf84967c
    • R
      add fallback emulation for accept4 on old kernels · dc01e2cb
      Rich Felker 提交于
      the other atomic FD_CLOEXEC interfaces (dup3, pipe2, socket) already
      had such emulation in place. the justification for doing the emulation
      here is the same as for the other functions: it allows applications to
      simply use accept4 rather than having to have their own fallback code
      for ENOSYS/EINVAL (which one you get is arch-specific!) and there is
      no reasonable way an application could benefit from knowing the
      operation is emulated/non-atomic since there is no workaround at the
      application level for non-atomicity (that is the whole reason these
      interfaces were added).
      dc01e2cb
  17. 14 2月, 2014 2 次提交
  18. 12 2月, 2014 1 次提交
  19. 10 2月, 2014 1 次提交
    • B
      clone: make clone a wrapper around __clone · fdf5f1b1
      Bobby Bingham 提交于
      The architecture-specific assembly versions of clone did not set errno on
      failure, which is inconsistent with glibc.  __clone still returns the error
      via its return value, and clone is now a wrapper that sets errno as needed.
      The public clone has also been moved to src/linux, as it's not directly
      related to the pthreads API.
      
      __clone is called by pthread_create, which does not report errors via
      errno.  Though not strictly necessary, it's nice to avoid clobbering errno
      here.
      fdf5f1b1