1. 31 8月, 2020 1 次提交
  2. 25 8月, 2020 1 次提交
    • R
      add tcgetwinsize and tcsetwinsize functions, move struct winsize · 4d578654
      Rich Felker 提交于
      these have been adopted for future issue of POSIX as the outcome of
      Austin Group issue 1151, and are simply functions performing the roles
      of the historical ioctls. since struct winsize is being standardized
      along with them, its definition is moved to the appropriate header.
      
      there is some chance this will break source files that expect struct
      winsize to be defined by sys/ioctl.h without including termios.h. if
      this happens, further changes will be needed to have sys/ioctl.h
      expose it too.
      4d578654
  3. 06 8月, 2019 1 次提交
  4. 17 7月, 2019 3 次提交
    • R
      fix broken lseek on x32 (x86_64/ILP32) with offsets larger than LONG_MAX · 1a28c6ea
      Rich Felker 提交于
      this is analogous to commit 918c5fa0
      which fixed the corresponding issue for mips n32.
      1a28c6ea
    • R
      fix broken lseek on mipsn32 with offsets larger than LONG_MAX · 918c5fa0
      Rich Felker 提交于
      mips n32 has 32-bit long, and generally uses long syscall arguments
      and return values, but provides only SYS_lseek, not SYS_llseek. we
      have some framework (syscall_arg_t, added for x32) to make syscall
      arguments 64-bit in such a setting, but it's not clear whether this
      could match the sign-extension semantics needed for 32-bit args to all
      the other syscalls, and we don't have any existing mechanism to allow
      the return value of syscalls to be something other than long.
      
      instead, just provide a custom mipsn32 version of the lseek function
      doing its own syscall asm with 64-bit arguments. as a result of commit
      03919b26, stdio will also get the new
      code, fixing fseeko/ftello too.
      918c5fa0
    • R
      use namespace-safe __lseek for __stdio_seek instead of direct syscall · 03919b26
      Rich Felker 提交于
      this probably saves a few bytes, avoids duplicating the clunky
      lseek/_llseek syscall convention in two places, and sets the stage for
      fixing broken seeks on x32 and mipsn32.
      03919b26
  5. 11 7月, 2019 1 次提交
  6. 22 3月, 2019 1 次提交
  7. 15 9月, 2018 1 次提交
    • B
      improve error handling of ttyname_r and isatty · c8497199
      Benjamin Peterson 提交于
      POSIX allows ttyname(_r) and isatty to return EBADF if passed file
      descriptor is invalid.
      
      maintainer's note: these are optional ("may fail") errors, but it's
      non-conforming for ttyname_r to return ENOTTY when it failed for a
      different reason.
      c8497199
  8. 13 9月, 2018 3 次提交
    • R
      remove spurious inclusion of libc.h for LFS64 ABI aliases · 63a4c9ad
      Rich Felker 提交于
      the LFS64 macro was not self-documenting and barely saved any
      characters. simply use weak_alias directly so that it's clear what's
      being done, and doesn't depend on a header to provide a strange macro.
      63a4c9ad
    • R
      reduce spurious inclusion of libc.h · 5ce37379
      Rich Felker 提交于
      libc.h was intended to be a header for access to global libc state and
      related interfaces, but ended up included all over the place because
      it was the way to get the weak_alias macro. most of the inclusions
      removed here are places where weak_alias was needed. a few were
      recently introduced for hidden. some go all the way back to when
      libc.h defined CANCELPT_BEGIN and _END, and all (wrongly implemented)
      cancellation points had to include it.
      
      remaining spurious users are mostly callers of the LOCK/UNLOCK macros
      and files that use the LFS64 macro to define the awful *64 aliases.
      
      in a few places, new inclusion of libc.h is added because several
      internal headers no longer implicitly include libc.h.
      
      declarations for __lockfile and __unlockfile are moved from libc.h to
      stdio_impl.h so that the latter does not need libc.h. putting them in
      libc.h made no sense at all, since the macros in stdio_impl.h are
      needed to use them correctly anyway.
      5ce37379
    • R
      move and deduplicate declarations of __procfdname to make it checkable · 6fcd60dd
      Rich Felker 提交于
      syscall.h was chosen as the header to declare it, since its intended
      usage is alongside syscalls as a fallback for operations the direct
      syscall does not support.
      6fcd60dd
  9. 02 5月, 2018 1 次提交
    • R
      avoid excessive stack usage in getcwd · 375840c7
      Rich Felker 提交于
      to support the GNU extension of allocating a buffer for getcwd's
      result when a null pointer is passed without incurring a link
      dependency on free, we use a PATH_MAX-sized buffer on the stack and
      only duplicate it to allocated storage after the operation succeeds.
      unfortunately this imposed excessive stack usage on all callers,
      including those not making use of the GNU extension.
      
      instead, use a VLA to make stack allocation conditional.
      375840c7
  10. 19 4月, 2018 1 次提交
  11. 18 4月, 2018 1 次提交
    • R
      fix return value of nice function · 4bf0717e
      Rich Felker 提交于
      the Linux SYS_nice syscall is unusable because it does not return the
      newly set priority. always use SYS_setpriority. also avoid overflows
      in addition of inc by handling large inc values directly without
      examining the old nice value.
      4bf0717e
  12. 08 2月, 2018 1 次提交
    • D
      make getcwd fail if it cannot obtain an absolute path · 23ddab85
      Dmitry V. Levin 提交于
      Currently getcwd(3) can succeed without returning an absolute path
      because the underlying getcwd syscall, starting with linux commit
      v2.6.36-rc1~96^2~2, may succeed without returning an absolute path.
      
      This is a conformance issue because "The getcwd() function shall
      place an absolute pathname of the current working directory
      in the array pointed to by buf, and return buf".
      
      Fix this by checking the path returned by syscall and failing with
      ENOENT if the path is not absolute.  The error code is chosen for
      consistency with the case when the current directory is unlinked.
      
      Similar issue was fixed in glibc recently, see
      https://sourceware.org/bugzilla/show_bug.cgi?id=22679
      23ddab85
  13. 06 2月, 2018 1 次提交
    • R
      revert regression in faccessat AT_EACCESS robustness · cd0ae687
      Rich Felker 提交于
      commit f9fb20b4 switched from using a
      pipe for the result to conveying it via the child process exit status.
      Alexander Monakov pointed out that the latter could fail if the
      application is not expecting faccessat to produce a child and performs
      a wait operation with __WCLONE or __WALL, and that it is not clear
      whether it's guaranteed to work when SIGCHLD's disposition has been
      set to SIG_IGN.
      
      in addition, that commit introduced a bug that caused EACCES to be
      produced instead of EBUSY due to an exit path that was overlooked when
      the error channel was changed, and introduced a spurious retry loop
      around the wait operation.
      cd0ae687
  14. 28 5月, 2017 1 次提交
  15. 22 4月, 2017 1 次提交
    • R
      make ttyname[_r] return ENODEV rather than ENOENT · e1232f5b
      Rich Felker 提交于
      commit 0a950dcf added checking that
      the pathname a tty device was opened with actually matches the device,
      which can fail to hold when a container inherits a tty from outside
      the container. the error code added at the time was ENOENT; however,
      discussions between affected applications and glibc developers
      resulted in glibc adopting ENODEV as the error for this condition, and
      this has now been documented in the man pages project as well. adopt
      the same error code for consistency.
      
      patch by Christian Brauner.
      e1232f5b
  16. 31 8月, 2016 1 次提交
  17. 12 8月, 2016 1 次提交
    • R
      fix pread/pwrite syscall calling convention on sh · 7cc3a28e
      Rich Felker 提交于
      despite sh not generally using register-pair alignment for 64-bit
      syscall arguments, there are arch-specific versions of the syscall
      entry points for pread and pwrite which include a dummy argument for
      alignment before the 64-bit offset argument.
      7cc3a28e
  18. 18 4月, 2016 1 次提交
  19. 07 3月, 2016 1 次提交
    • R
      add mips64 port · 83933573
      Rich Felker 提交于
      patch by Mahesh Bodapati and Jaydeep Patil of Imagination
      Technologies.
      83933573
  20. 16 6月, 2015 1 次提交
    • R
      switch to using trap number 31 for syscalls on sh · 10d0268c
      Rich Felker 提交于
      nominally the low bits of the trap number on sh are the number of
      syscall arguments, but they have never been used by the kernel, and
      some code making syscalls does not even know the number of arguments
      and needs to pass an arbitrary high number anyway.
      
      sh3/sh4 traditionally used the trap range 16-31 for syscalls, but part
      of this range overlapped with hardware exceptions/interrupts on sh2
      hardware, so an incompatible range 32-47 was chosen for sh2.
      
      using trap number 31 everywhere, since it's in the existing sh3/sh4
      range and does not conflict with sh2 hardware, is a proposed
      unification of the kernel syscall convention that will allow binaries
      to be shared between sh2 and sh3/sh4. if this is not accepted into the
      kernel, we can refit the sh2 target with runtime selection mechanisms
      for the trap number, but doing so would be invasive and would entail
      non-trivial overhead.
      10d0268c
  21. 24 2月, 2015 1 次提交
    • R
      fix possible isatty false positives and unwanted device state changes · 2de85a98
      Rich Felker 提交于
      the equivalent checks for newly opened stdio output streams, used to
      determine buffering mode, are also fixed.
      
      on most archs, the TCGETS ioctl command shares a value with
      SNDCTL_TMR_TIMEBASE, part of the OSS sound API which was apparently
      used with certain MIDI and timer devices. for file descriptors
      referring to such a device, TCGETS will not fail with ENOTTY as
      expected; it may produce a different error, or may succeed, and if it
      succeeds it changes the mode of the device. while it's unlikely that
      such devices are in use, this is in principle very harmful behavior
      for an operation which is supposed to do nothing but query whether the
      fd refers to a tty.
      
      TIOCGWINSZ, used to query logical window size for a terminal, was
      chosen as an alternate ioctl to perform the isatty check. it does not
      share a value with any other ioctl commands, and it succeeds on any
      tty device.
      
      this change also cleans up strace output to be less ugly and
      misleading.
      2de85a98
  22. 21 2月, 2015 1 次提交
    • R
      map interruption of close by signal to success rather than EINPROGRESS · 6bea5dc6
      Rich Felker 提交于
      commit 82dc1e2e addressed the
      resolution of Austin Group issue 529, which requires close to leave
      the fd open when failing with EINTR, by returning the newly defined
      error code EINPROGRESS. this turns out to be a bad idea, though, since
      legacy applications not aware of the new specification are likely to
      interpret any error from close except EINTR as a hard failure.
      6bea5dc6
  23. 13 2月, 2015 1 次提交
    • R
      overhaul aio implementation for correctness · 4e8a3561
      Rich Felker 提交于
      previously, aio operations were not tracked by file descriptor; each
      operation was completely independent. this resulted in non-conforming
      behavior for non-seekable/append-mode writes (which are required to be
      ordered) and made it impossible to implement aio_cancel, which in turn
      made closing file descriptors with outstanding aio operations unsafe.
      
      the new implementation is significantly heavier (roughly twice the
      size, and seems to be slightly slower) and presently aims mainly at
      correctness, not performance.
      
      most of the public interfaces have been moved into a single file,
      aio.c, because there is little benefit to be had from splitting them.
      whenever any aio functions are used, aio_cancel and the internal
      queue lifetime management and fd-to-queue mapping code must be linked,
      and these functions make up the bulk of the code size.
      
      the close function's interaction with aio is implemented with weak
      alias magic, to avoid pulling in heavy aio cancellation code in
      programs that don't use aio, and the expensive cancellation path
      (which includes signal blocking) is optimized out when there are no
      active aio queues.
      4e8a3561
  24. 31 1月, 2015 1 次提交
  25. 15 1月, 2015 1 次提交
    • R
      for multithreaded set*id/setrlimit, handle case where callback does not run · 472e8b71
      Rich Felker 提交于
      in the current version of __synccall, the callback is always run, so
      failure to handle this case did not matter. however, the upcoming
      overhaul of __synccall will have failure cases, in which case the
      callback does not run and errno is already set. the changes being
      committed now are in preparation for that.
      472e8b71
  26. 13 1月, 2015 1 次提交
    • R
      remove rlimit hacks from multi-threaded set*id() code · 84b5c547
      Rich Felker 提交于
      the code being removed was introduced to work around "partial failure"
      of multi-threaded set*id() operations, where some threads would
      succeed in changing their ids but an RLIMIT_NPROC setting would
      prevent the rest from succeeding, leaving the process in an
      inconsistent and dangerous state. however, the workaround code did not
      handle important usage cases like swapping real and effective uids
      then restoring their original values, and the wrongful kernel
      enforcement of RLIMIT_NPROC at setuid time was removed in Linux 3.1,
      making the workaround obsolete.
      
      since the partial failure still is dangerous on old kernels, and could
      in principle happen on post-fix kernels as well if set*id() syscalls
      fail for another spurious reason such as resource-related failures,
      new code is added to detect and forcibly kill the process if/when such
      a situation arises. future documentation releases should be updated to
      reflect that setting RLIMIT_NPROC to RLIM_INFINITY is necessary to
      avoid this forced-kill on old kernels. ideally, at some point the
      kernel will get proper multi-threaded set*id() syscalls capable of
      performing their actions atomically, and all of the userspace code to
      emulate them can be treated as a fallback for outdated kernels.
      84b5c547
  27. 12 1月, 2015 1 次提交
    • R
      simplify ctermid · 9772eadb
      Rich Felker 提交于
      opening /dev/tty then using ttyname_r on it does not produce a
      canonical terminal name; it simply yields "/dev/tty".
      
      it would be possible to make ctermid determine the actual controlling
      terminal device via field 7 of /proc/self/stat, but doing so would
      introduce a buffer overflow into applications built with L_ctermid==9,
      which glibc defines, adversely affecting the quality of ABI compat.
      9772eadb
  28. 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
  29. 28 2月, 2014 1 次提交
    • R
      rename superh port to "sh" for consistency · aacd3486
      Rich Felker 提交于
      linux, gcc, etc. all use "sh" as the name for the superh arch. there
      was already some inconsistency internally in musl: the dynamic linker
      was searching for "ld-musl-sh.path" as its path file despite its own
      name being "ld-musl-superh.so.1". there was some sentiment in both
      directions as to how to resolve the inconsistency, but overall "sh"
      was favored.
      aacd3486
  30. 24 2月, 2014 1 次提交
  31. 20 12月, 2013 1 次提交
    • R
      fix failure of fchmod, fstat, fchdir, and fchown to produce EBADF · 65ea604c
      Rich Felker 提交于
      the workaround/fallback code for supporting O_PATH file descriptors
      when the kernel lacks support for performing these operations on them
      caused EBADF to get replaced by ENOENT (due to missing entry in
      /proc/self/fd). this is unlikely to affect real-world code (calls that
      might yield EBADF are generally unsafe, especially in library code)
      but it was breaking some test cases.
      
      the fix I've applied is something of a tradeoff: it adds one syscall
      to these operations on kernels where the workaround is needed. the
      alternative would be to catch ENOENT from the /proc lookup and
      translate it to EBADF, but I want to avoid doing that in the interest
      of not touching/depending on /proc at all in these functions as long
      as the kernel correctly supports the operations. this is following the
      general principle of isolating hacks to code paths that are taken on
      broken systems, and keeping the code for correct systems completely
      hack-free.
      65ea604c
  32. 12 12月, 2013 1 次提交
  33. 07 12月, 2013 1 次提交
  34. 02 11月, 2013 2 次提交
  35. 18 10月, 2013 1 次提交