1. 02 8月, 2019 1 次提交
    • R
      move IPC_STAT definition to a new bits/ipcstat.h file · 006a75a9
      Rich Felker 提交于
      otherwise, 32-bit archs that could otherwise share the generic
      bits/ipc.h would need to duplicate the struct ipc_perm definition,
      obscuring the fact that it's the same. sysvipc is not widely used and
      these headers are not commonly included, so there is no performance
      gain to be had by limiting the number of indirectly included files
      here.
      
      files with the existing time32 definition of IPC_STAT are added to all
      current 32-bit archs now, so that when it's changed the change will
      show up as a change rather than addition of a new file where it's less
      obvious that the value is changing vs the generic one that was used
      before.
      006a75a9
  2. 01 8月, 2019 2 次提交
    • R
      ioctl: add fallback for new time64 SIOCGSTAMP[NS] · 2e554617
      Rich Felker 提交于
      without this, the SIOCGSTAMP and SIOCGSTAMPNS ioctl commands, for
      obtaining timestamps, would stop working on pre-5.1 kernels after
      time_t is switched to 64-bit and their values are changed to the new
      time64 versions.
      
      new code is written such that it's statically unreachable on 64-bit
      archs, and on existing 32-bit archs until the macro values are changed
      to activate 64-bit time_t.
      2e554617
    • R
      get/setsockopt: add fallback for new time64 SO_RCVTIMEO/SO_SNDTIMEO · 51fd67fc
      Rich Felker 提交于
      without this, the SO_RCVTIMEO and SO_SNDTIMEO socket options would
      stop working on pre-5.1 kernels after time_t is switched to 64-bit and
      their values are changed to the new time64 versions.
      
      new code is written such that it's statically unreachable on 64-bit
      archs, and on existing 32-bit archs until the macro values are changed
      to activate 64-bit time_t.
      51fd67fc
  3. 31 7月, 2019 3 次提交
    • R
      remove gratuitously-different arch-specific bits/ipc.h files · 319b2d02
      Rich Felker 提交于
      these differ from generic only in using endian-matched padding with a
      short __ipc_perm_seq field in place of the int field in generic. this
      is not a documented public interface anyway, and the original intent
      was to use int here. some ports just inadvertently slipped in the
      kernel short+padding form.
      319b2d02
    • R
      remove arch-specific bits/ipc.h that are identical to generic · 2a0bb9e0
      Rich Felker 提交于
      previously these differed from generic because they needed their own
      definitions of IPC_64. now that it's no longer in public header,
      they're identical.
      2a0bb9e0
    • R
      move IPC_64 from public bits/ipc.h to syscall_arch.h · f56d57f8
      Rich Felker 提交于
      the definition of the IPC_64 macro controls the interface between libc
      and the kernel through syscalls; it's not a public API. the meaning is
      rather obscure. long ago, Linux's sysvipc *id_ds structures used
      16-bit uids/gids and wrong types for a few other fields. this was in
      the libc5 era, before glibc. the IPC_64 flag (64 is a misnomer; it's
      more like 32) tells the kernel to use the modern[-ish] versions of the
      structures.
      
      the definition of IPC_64 has nothing to do with whether the arch is
      32- or 64-bit. rather, due to either historical accident or
      intentional obnoxiousness, the kernel only accepts and masks off the
      0x100 IPC_64 flag conditional on CONFIG_ARCH_WANT_IPC_PARSE_VERSION,
      i.e. for archs that want to provide, or that accidentally provided,
      both. for archs which don't define this option, no masking is
      performed and commands with the 0x100 bit set will fail as invalid. so
      ultimately, the definition is just a matter of matching an arbitrary
      switch defined per-arch in the kernel.
      f56d57f8
  4. 30 7月, 2019 12 次提交
  5. 29 7月, 2019 1 次提交
    • R
      remove x32 syscall timespec fixup hacks · 4c307bed
      Rich Felker 提交于
      the x32 syscall interfaces treat timespec's tv_nsec member as 64-bit
      despite the API type being long and long being 32-bit in the ABI. this
      is no problem for syscalls that store timespecs to userspace as
      results, but caused uninitialized padding to be misinterpreted as the
      high bits in syscalls that take timespecs as input.
      
      since the beginning of the port, we've dealt with this situation with
      hacks in syscall_arch.h, and injected between __syscall_cp_c and
      __syscall_cp_asm, to special-case the syscall numbers that involve
      timespecs as inputs and copy them to a form suitable to pass to the
      kernel.
      
      commit 40aa18d5 set the stage for
      removal of these hacks by letting us treat the "normal" x32 syscalls
      dealing with timespec as if they're x32's "time64" syscalls,
      effectively making x32 ax "time64-only 32-bit arch" like riscv32 will
      be when it's added. since then, all users of syscalls that x32's
      syscall_arch.h had hacks for have been updated to use time64 syscalls,
      so the hacks can be removed.
      
      there are still at least a few other timespec-related syscalls broken
      on x32, which were overlooked when the x32 hacks were done or added
      later. these include at least recvmmsg, adjtimex/clock_adjtime, and
      timerfd_settime, and they will be fixed independently later on.
      4c307bed
  6. 28 7月, 2019 2 次提交
    • R
      internally, define time64 syscalls on x32 as the existing syscalls · 40aa18d5
      Rich Felker 提交于
      x32 is odd in that it's the only ILP32 arch/ABI we have where time_t
      is 64-bit rather than (32-bit) long, and this has always been
      problematic in that it results in struct timespec having unused
      padding space, since tv_nsec has type long, which the kernel insists
      be zero- or sign-extended (due to negative tv_nsec being invalid, it
      doesn't matter which) to match the x86_64 type.
      
      up til now, we've had really ugly hacks in x32/syscall_arch.h to patch
      up the timespecs passed to the kernel. but the same requirement to
      zero- or sign-extend tv_nsec also applies to all the new time64
      syscalls on true 32-bit archs. so let's take advantage of this to
      clean things up.
      
      this patch defines all of the time64 syscalls for x32 as aliases for
      the existing syscalls by the same name. this establishes the following
      invariants:
      
      - if the time64 form is defined, it takes time arguments as 64-bit
        objects, and tv_nsec inputs must be zero-/sign-extended to 64-bit.
      
      - if the time64 form is not defined, or if the time64 form is defined
        and is not equal to the "plain" form, the plain form takes time
        arguments as longs.
      
      this will avoid the need for protocols for archs to define appropriate
      types for each family of syscalls, and for the reader of the code to
      have to be aware of such type definitions.
      
      in some sense it might be simpler if the plain syscall form were
      undefined for x32, so that it would always take longs if defined.
      however, a number of these syscalls are used in contexts with a null
      time argument, or (e.g. futex) for commands that don't involve time at
      all, and having to introduce time64-specific logic to all those call
      points does not make sense. thus, while the "plain" forms are kept now
      just because they're needed until the affected code is converted over,
      they'll also almost surely be kept in the future as well.
      40aa18d5
    • R
      don't use futimesat syscall as utimensat fallback on x32 · b93183e3
      Rich Felker 提交于
      kernel support for x32 was added long after the utimensat syscall was
      already available, so having a fallback is just wasted code size.
      
      also, for changes related to time64 support on 32-bit archs, I want to
      be able to assume the old futimesat syscall always works with longs,
      which is true except for x32. by ensuring that it's not used on x32,
      the needed invariant is established.
      b93183e3
  7. 19 7月, 2019 3 次提交
    • R
      remove mips/n32/64 stat struct hacks from syscall machinery · fa7d4218
      Rich Felker 提交于
      now that we have a kstat structure decoupled from the public struct
      stat, we can just use the broken kernel structures directly and let
      the code in fstatat do the translation.
      fa7d4218
    • R
      decouple struct stat from kernel type · 01ae3fc6
      Rich Felker 提交于
      presently, all archs/ABIs have struct stat matching the kernel
      stat[64] type, except mips/mipsn32/mips64 which do conversion hacks in
      syscall_arch.h to work around bugs in the kernel type. this patch
      completely decouples them and adds a translation step to the success
      path of fstatat. at present, this is just a gratuitous copying, but it
      opens up multiple possibilities for future support for 64-bit time_t
      on 32-bit archs and for cleaned-up/unified ABIs.
      
      for clarity, the mips hacks are not yet removed in this commit, so the
      mips kstat structs still correspond to the output of the hacks in
      their syscall_arch.h files, not the raw kernel type. a subsequent
      commit will fix this.
      01ae3fc6
    • R
      remove utterly wrong includes from mips64/n32 bits/stat.h · 62a73d96
      Rich Felker 提交于
      these were overlooked during review. bits headers are not allowed to
      pull in additional headers (note: that rule is currently broken in
      other places but just for endian.h). string.h has no place here
      anyway, and including bits/alltypes.h without defining macros to
      request types from it is a nop.
      62a73d96
  8. 18 7月, 2019 3 次提交
    • R
      use register constraint instead of memory operand for riscv64 atomics · f0eb2e77
      Rich Felker 提交于
      the "A" constraint is simply for an address expression that's a single
      register, but it's not yet supported by clang, and has no advantage
      here over just using a register operand for the address. the latter is
      actually preferable in the a_cas_p case because it avoids aliasing an
      lvalue onto the memory.
      f0eb2e77
    • R
      fix riscv64 atomic asm constraints · 2dcbeabd
      Rich Felker 提交于
      most egregious problem was the lack of memory clobber and lack of
      volatile asm; this made the atomics memory barriers but not compiler
      barriers. use of "+r" rather than "=r" for a clobbered temp was also
      wrong, since the initial value is indeterminate.
      2dcbeabd
    • R
      fix riscv64 syscall asm constraint · 8eb49e04
      Rich Felker 提交于
      having "+r"(a0) is redundant with "0"(a0) in syscalls with at least 1
      arg, which is arguably a constraint violation (clang treats it as
      such), and an invalid input with indeterminate value in the 0-arg
      case. use the "=r"(a0) form instead.
      8eb49e04
  9. 17 7月, 2019 2 次提交
    • R
      clean up mips64/n32 syscall asm constraints · ddc7c4f9
      Rich Felker 提交于
      ever since inline syscalls were added for (o32) mips in commit
      328810d3, the asm has nonsensically
      loaded the syscall number, rather than taking $2 as an input
      constraint to let the compiler load it. commit
      cfc09b1e improved on this somewhat by
      allowing a constant syscall number to propagate into an immediate, but
      missed that the whole operation made no sense.
      
      now, only $4, $5, $6, $8, and $9 are potential input-only registers.
      $2 is always input and output, and $7 is both when it's an argument,
      otherwise output-only. previously, $7 was treated as an input (with a
      "1" constraint matching its output position) even when it was not an
      input, which was arguably undefined behavior (asm input from
      indeterminate value). this is corrected.
      ddc7c4f9
    • R
      deduplicate mips64/n32 syscall clobbered register lists · db2a148d
      Rich Felker 提交于
      this patch is not purely non-functional changes, since before, $8 and
      $9 were wrongly in the clobberlist for syscalls with fewer than 5 or 6
      arguments. of course it's impossible for syscalls to have different
      clobbers depending on their number of arguments. the clobberlist for
      the recently-added 5- and 6-argument forms was correct, and for the 0-
      to 4-argument forms was erroneously copied from the mips o32 ABI where
      the additional arguments had to be passed on the stack.
      
      in making this change, I reviewed the kernel sources, and $8 and $9
      are always saved for 64-bit kernels since they're part of the syscall
      argument list for n32 and n64 ABIs.
      db2a148d
  10. 16 7月, 2019 1 次提交
    • R
      fix build failure on arm building C code in thumb1 mode · 980f80f7
      Rich Felker 提交于
      a fully thumb1 build is not supported because some asm files are
      incompatible with thumb1, but apparently it works to compile the C
      code as thumb1
      
      commit 06fbefd1 caused this regression
      but introducing use of the clz instruction, which is not supported in
      arm mode prior to v5, and not supported in thumb prior to thumb2
      (v6t2). commit 1b9406b0 fixed the
      issue only for arm mode pre-v5 but left thumb1 broken.
      980f80f7
  11. 11 7月, 2019 1 次提交
  12. 05 7月, 2019 1 次提交
  13. 02 7月, 2019 3 次提交
    • S
      add new syscall numbers from linux v5.1 · f3f96f2d
      Szabolcs Nagy 提交于
      syscall numbers are now synced up across targets (starting from 403 the
      numbers are the same on all targets other than an arch specific offset)
      
      IPC syscalls sem*, shm*, msg* got added where they were missing (except
      for semop: only semtimedop got added), the new semctl, shmctl, msgctl
      imply IPC_64, see
      
        linux commit 0d6040d4681735dfc47565de288525de405a5c99
        arch: add split IPC system calls where needed
      
      new 64bit time_t syscall variants got added on 32bit targets, see
      
        linux commit 48166e6ea47d23984f0b481ca199250e1ce0730a
        y2038: add 64-bit time_t syscalls to all 32-bit architectures
      
      new async io syscalls got added, see
      
        linux commit 2b188cc1bb857a9d4701ae59aa7768b5124e262e
        Add io_uring IO interface
      
        linux commit edafccee56ff31678a091ddb7219aba9b28bc3cb
        io_uring: add support for pre-mapped user IO buffers
      
      a new syscall got added that uses the fd of /proc/<pid> as a stable
      handle for processes: allows sending signals without pid reuse issues,
      intended to eventually replace rt_sigqueueinfo, kill, tgkill and
      rt_tgsigqueueinfo, see
      
        linux commit 3eb39f47934f9d5a3027fe00d906a45fe3a15fad
        signal: add pidfd_send_signal() syscall
      
      on some targets (arm, m68k, s390x, sh) some previously missing syscall
      numbers got added as well.
      f3f96f2d
    • S
      mips64: fix syscall numbers of io_pgetevents and rseq · b574de5b
      Szabolcs Nagy 提交于
      the numbers added in
      
        commit d149e69c
        add io_pgetevents and rseq syscall numbers from linux v4.18
      
      were incorrect.
      b574de5b
    • S
      s390x: drop SO_ definitions from bits/socket.h · 45235051
      Szabolcs Nagy 提交于
      the s390x definitions matched the generic ones in sys/socket.h.
      45235051
  14. 15 6月, 2019 1 次提交
    • R
      add riscv64 architecture support · 0a48860c
      Rich Felker 提交于
      Author: Alex Suykov <alex.suykov@gmail.com>
      Author: Aric Belsito <lluixhi@gmail.com>
      Author: Drew DeVault <sir@cmpwn.com>
      Author: Michael Clark <mjc@sifive.com>
      Author: Michael Forney <mforney@mforney.org>
      Author: Stefan O'Rear <sorear2@gmail.com>
      
      This port has involved the work of many people over several years. I
      have tried to ensure that everyone with substantial contributions has
      been credited above; if any omissions are found they will be noted
      later in an update to the authors/contributors list in the COPYRIGHT
      file.
      
      The version committed here comes from the riscv/riscv-musl repo's
      commit 3fe7e2c75df78eef42dcdc352a55757729f451e2, with minor changes by
      me for issues found during final review:
      
      - a_ll/a_sc atomics are removed (according to the ISA spec, lr/sc
        are not safe to use in separate inline asm fragments)
      
      - a_cas[_p] is fixed to be a memory barrier
      
      - the call from the _start assembly into the C part of crt1/ldso is
        changed to allow for the possibility that the linker does not place
        them nearby each other.
      
      - DTP_OFFSET is defined correctly so that local-dynamic TLS works
      
      - reloc.h LDSO_ARCH logic is simplified and made explicit.
      
      - unused, non-functional crti/n asm files are removed.
      
      - an empty .sdata section is added to crt1 so that the
        __global_pointer reference is resolvable.
      
      - indentation style errors in some asm files are fixed.
      0a48860c
  15. 23 5月, 2019 2 次提交
    • R
      make powerpc64 vrregset_t logical layout match expected API · ac304227
      Rich Felker 提交于
      between v2 and v3 of the powerpc64 port patch, the change was made
      from a 32x4 array of 32-bit unsigned ints for vrregs[] to a 32-element
      array of __int128. this mismatches the API applications working with
      mcontext_t expect from glibc, and seems to have been motivated by a
      misinterpretation of a comment on how aarch64 did things as a
      suggestion to do the same on powerpc64.
      ac304227
    • R
      fix vrregset_t layout and member naming on powerpc64 · 3c59a868
      Rich Felker 提交于
      the mistaken layout seems to have been adapted from 32-bit powerpc,
      where vscr and vrsave are packed into the same 128-bit slot in a way
      that looks like it relies on non-overlapping-ness of the value bits in
      big endian.
      
      the powerpc64 port accounted for the fact that the 64-bit ABI puts
      each in its own 128-bit slot, but ordered them incorrectly (matching
      the bit order used on the 32-bit ABI), and failed to account for vscr
      being padded according to endianness so that it can be accessed via
      vector moves.
      
      in addition to ABI layout, our definition used different logical
      member layout/naming from glibc, where vscr is a structure to
      facilitate access as a 32-bit word or a 128-bit vector. the
      inconsistency here was unintentional, so fix it.
      3c59a868
  16. 12 5月, 2019 1 次提交
    • R
      improve i386 inline syscall asm on non-broken compilers · bdb08175
      Rich Felker 提交于
      we have to avoid using ebx unconditionally in asm constraints for
      i386, because gcc 3 and 4 and possibly other simplistic compilers
      (pcc?) implement PIC via making ebx a fixed-use register, and disallow
      its use for anything else. rather than hard-coding knowledge of which
      compilers work (at least gcc 5+ and clang), perform a configure test;
      this should give us the good codegen on any new compilers we don't yet
      know about.
      
      swapping ebx and edx is kept for 1- and 2-arg syscalls because it
      avoids having any spills/stack-frame at all in small functions. for
      6-arg, if ebx is directly usable, the complex shuffling introduced in
      commit c8798ef9 can be avoided, and
      ebp can be loaded the same way ebx is in 5-arg syscalls for compilers
      that don't support direct use of ebx.
      bdb08175
  17. 11 5月, 2019 1 次提交
    • R
      fix regression in i386 inline syscall asm producing invalid code · c8798ef9
      Rich Felker 提交于
      commit 22e5bbd0 inlined the i386
      syscall mechanism, but wrongly assumed memory operands to the 5- and
      6-argument syscall asm would be esp-based. however, nothing in the
      constraints prevented them from being ebx- or ebp-based, and in those
      cases, ebx and ebp could be clobbered before use of the memory operand
      was complete. in the 6-argument case, this prevented restoration of
      the original register values before the end of the asm block, breaking
      the asm contract since ebx and ebp are not marked as clobbered. (they
      can't be, because lots of compilers don't accept these registers in
      constraints or clobbers if PIC or frame pointer is enabled).
      
      doing this right is complicated by the fact that, after a single push,
      no operands which might be memory operands are usable. if they are
      esp-based, the value of esp has changed, rendering them invalid.
      
      introduce some new dances to load the registers. for the 5-arg case,
      push the operand that may be a memory operand first, and after that,
      it doesn't matter if the operand is invalid, since we'll just use the
      newly pushed value. for the 6-arg case, we need to put both operands
      in memory to begin with, like the old non-inline code prior to commit
      22e5bbd0 accepted, so that there's
      only one potentially memory-based operand to the asm. this can then be
      saved with a single push, and after that the values can be read off
      into the registers they're needed in.
      
      there's some size overhead, but still a lot less execution overhead
      than the old out-of-line code. doing it better depends on a modern
      compiler that lets you use ebx and ebp in asm constraints without
      restriction. the failure modes on compilers where this doesn't work
      are inconsistent and dangerous (on at least some gcc versions 4.x and
      earlier, wrong codegen!), so this is a delicate matter. it can be
      addressed later if needed.
      c8798ef9