Commit Graph

1005 Commits

Author SHA1 Message Date
Szabolcs Nagy
f35b99b387 sys/prctl.h: add PR_SET_SYSCALL_USER_DISPATCH from linux v5.11
see

  linux commit 1446e1df9eb183fdf81c3f0715402f1d7595d4cb
  kernel: Implement selective syscall userspace redirection

  linux commit 36a6c843fd0d8e02506681577e96dabd203dd8e8
  entry: Use different define for selector variable in SUD

redirect syscalls to a userspace handler via SIGSYS, except for a specific
range of code. can be toggled via a memory write to a selector variable.
mainly for wine.
2022-03-08 17:19:38 -05:00
Érico Nogueira
cbacd638e3 add SEEK_DATA and SEEK_HOLE to unistd.h
these are linux specific constants. glibc exposes them behind
_GNU_SOURCE, but, since SEEK_* is reserved for the implementation, we
can simply define them. furthermore, since they can't be used with
fseek() and other functions that deal with FILE, we don't add them to
stdio.h.
2022-01-09 00:31:05 -05:00
Ismael Luceno
98e688a9da define NULL as nullptr when used in C++11 or later
This should be safer for casting and more compatible with existing code
bases that wrongly assume it must be defined as a pointer.
2021-11-29 17:45:21 -05:00
Érico Nogueira
b76f37fd56 add qsort_r and make qsort a wrapper around it
we make qsort a wrapper by providing a wrapper_cmp function that uses
the extra argument as a function pointer. should be optimized to a tail
call on most architectures, as long as it's built with
-fomit-frame-pointer, so the performance impact should be minimal.

to keep the git history clean, for now qsort_r is implemented in qsort.c
and qsort is implemented in qsort_nr.c.  qsort.c also received a few
trivial cleanups, including replacing (*cmp)() calls with cmp().
qsort_nr.c contains only wrapper_cmp and qsort as a qsort_r wrapper
itself.
2021-09-23 20:09:22 -04:00
Érico Rolim
bd3b9c4ca5 add pthread_getname_np function
based on the pthread_setname_np implementation
2021-04-20 15:34:30 -04:00
Érico Nogueira
9a40e842df define __STDC_UTF_{16,32}__ macros
these macros are used to indicate that the implementation uses,
respectively, utf-16 and utf-32 encoding for char16_t and char32_t.
2021-04-19 09:49:20 -04:00
Érico Rolim
e48e99c112 suppress isascii() macro for C++
analogous to commit a60457c84a.
2021-02-25 16:35:54 -05:00
Rich Felker
b129cd8690 guard against compilers failing to handle setjmp specially by default
since 4.1, gcc has had the __returns_twice__ attribute and has
required functions which return twice to carry it; however it's always
applied it automatically to known setjmp-like function names. clang
however does not do this reliably, at least not with -ffreestanding
and possibly under other conditions, resulting in silent emission of
wrong code.

since the symbol name setjmp is in no way special (setjmp is specified
as a macro that could expand to use any implementation-specific symbol
name or names), a compiler is justified not to do anything special
without further hints, and it's reasonable to do what we can to
provide such hints.

gcc 4.0.x and earlier do not recognize the attribute, so make use
conditional on __GNUC__ macros. clang and other gcc-like compilers
report (and have always reported) a later "GNUC" version so the
preprocessor conditional should function as desired for them as too.

undefine the internal macro after use so that nothing abuses it as a
public feature.
2021-02-22 15:52:21 -05:00
Szabolcs Nagy
87b8f14811 signal.h: add MTE specific SIGSEGV codes from linux v5.10
add synchronouse and asynchronous tag check failure codes, see

  linux commit 74f1082487feb90bbf880af14beb8e29c3030c9f
  arm64: mte: Add specific SIGSEGV codes
2021-02-15 09:16:06 -05:00
Szabolcs Nagy
19239cde94 sys/prctl.h: add MTE related constants from linux v5.10
these are for the aarch64 MTE (memory tagging extension), see

  linux commit 1c101da8b971a36695319dce7a24711dc567a0dd
  arm64: mte: Allow user control of the tag check mode via prctl()

  linux commit af5ce95282dc99d08a27a407a02c763dde1c5558
  arm64: mte: Allow user control of the generated random tags via prctl()
2021-02-15 09:16:06 -05:00
Szabolcs Nagy
8b29f02370 elf.h: add NT_ARM_TAGGED_ADDR_CTRL from linux v5.10
see

  linux commit 2200aa7154cb7ef76bac93e98326883ba64bfa2e
  arm64: mte: ptrace: Add NT_ARM_TAGGED_ADDR_CTRL regset
2021-02-15 09:16:06 -05:00
Szabolcs Nagy
d7210f0c12 sys/mman.h: add MAP_HUGE_16KB from linux v5.10
see

  linux commit e47168f3d1b14af5281cf50c59561d59d28201f9
  powerpc/8xx: Support 16k hugepages with 4k pages
2021-02-15 09:16:06 -05:00
Szabolcs Nagy
a7456524d7 sys/mount.h: add MS_NOSYMFOLLOW from linux v5.10
path resolution does not follow symlinks on nosymfollow mounts (but
readlink still does), see

  linux commit dab741e0e02bd3c4f5e2e97be74b39df2523fc6e
  Add a "nosymfollow" mount option.
2021-02-15 09:16:06 -05:00
Szabolcs Nagy
54ca1cc7f1 sys/membarrier.h: add new constants from linux v5.10
can cause rseq restart on another cpu to synchronize with global
memory access from rseq critical sections, see

  linux commit 2a36ab717e8fe678d98f81c14a0b124712719840
  rseq/membarrier: Add MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ
2021-02-15 09:16:06 -05:00
Ariadne Conill
821083ac7b implement reallocarray
reallocarray is an extension introduced by OpenBSD, which introduces
calloc overflow checking to realloc.

glibc 2.28 introduced support for this function behind _GNU_SOURCE,
while glibc 2.29 allows its usage in _DEFAULT_SOURCE.
2020-11-30 16:49:58 -05:00
Szabolcs Nagy
67f774625e netinet/in.h: add IP_RECVERR_4884 from linux v5.9
see

  linux commit eba75c587e811d3249c8bd50d22bb2266ccd3c0f
  icmp: support rfc 4884
2020-11-29 00:54:41 -05:00
Szabolcs Nagy
d078f83657 sys/fanotify.h: add new FAN_* macros from linux v5.9
Update fanotify.h, see

  linux commit 929943b38daf817f2e6d303ea04401651fc3bc05
  fanotify: add support for FAN_REPORT_NAME

  linux commit 83b7a59896dd24015a34b7f00027f0ff3747972f
  fanotify: add basic support for FAN_REPORT_DIR_FID

  linux commit 08b95c338e0c5a96e47f4ca314ea1e7580ecb5d7
  fanotify: remove event FAN_DIR_MODIFY

FAN_DIR_MODIFY that was new in v5.7 is now removed from linux uapi,
but kept in musl, so we don't break api, linux cannot reuse the
value anyway.
2020-11-29 00:54:36 -05:00
William Woodruff
badc5bb211 add missing personality values
Adds two missing personality(2) personas: UNAME26 and FDPIC_FUNCPTRS.

FDPIC_FUNCPTRS was also missing its corresponding PER_LINUX_FDPIC
value.
2020-11-29 00:52:36 -05:00
James Y Knight
7c71792e87 add support for SIGEV_THREAD_ID timers
This is like SIGEV_SIGNAL, but targeted to a particular thread's
tid, rather than the process.
2020-10-28 23:00:08 -04:00
Rich Felker
bd153422f2 implement _Fork and refactor fork using it
the _Fork interface is defined for future issue of POSIX as the
outcome of Austin Group issue 62, which drops the AS-safety
requirement for fork, and provides an AS-safe replacement that does
not run the registered atfork handlers.
2020-10-14 20:27:12 -04:00
Szabolcs Nagy
f035c7b1e6 netinet/if_ether.h: add ETH_P_MRP from linux v5.8
Ethernet protocol number for media redundancy protocol, see

  linux commit 4714d13791f831d253852c8b5d657270becb8b2a
  bridge: uapi: mrp: Add mrp attributes.
2020-09-09 17:22:04 -04:00
Szabolcs Nagy
6b1741aaf5 elf.h: add .note.gnu.property related definitions
On x86 and aarch64 GNU properties may be used to mark ELF objects.
2020-09-09 17:22:02 -04:00
Szabolcs Nagy
616a8bf660 netinet/tcp.h: update to linux v5.7
add TCP_NLA_BYTES_NOTSENT and new tcp_zerocopy_receive fields, see

  linux commit c8856c051454909e5059df4e81c77b9c366c5515
  tcp-zerocopy: Return inq along with tcp receive zerocopy.

  linux commit 33946518d493cdf10aedb4a483f1aa41948a3dab
  tcp-zerocopy: Return sk_err (if set) along with tcp receive zerocopy.

  linux commit e08ab0b377a1489760533424437c5f4be7f484a4
  tcp: add bytes not sent to SCM_TIMESTAMPING_OPT_STATS
2020-09-09 17:20:57 -04:00
Szabolcs Nagy
a6c302bec1 sys/mman.h: add MREMAP_DONTUNMAP from linux v5.7
it remaps anon mappings without unmapping the original. chromeos plans
to use it with userfaultfd, see:

  linux commit e346b3813067d4b17383f975f197a9aa28a3b077
  mm/mremap: add MREMAP_DONTUNMAP to mremap()
2020-09-09 17:20:54 -04:00
Szabolcs Nagy
8adf42f7c1 sys/fanotify.h: update to linux v5.7
see

  linux commit 9e2ba2c34f1922ca1e0c7d31b30ace5842c2e7d1
  fanotify: send FAN_DIR_MODIFY event flavor with dir inode and name

  linux commit 44d705b0370b1d581f46ff23e5d33e8b5ff8ec58
  fanotify: report name info for FAN_DIR_MODIFY event
2020-09-09 17:20:49 -04:00
Szabolcs Nagy
43b640c2ff sched.h: add CLONE_NEWTIME from linux v5.6
reuses a bit from CSIGNAL so it can only be used with unshare
and clone3, added in

  linux commit 769071ac9f20b6a447410c7eaa55d1a5233ef40c
  ns: Introduce Time Namespace
2020-09-09 17:20:34 -04:00
Szabolcs Nagy
3da18e6951 sys/random.h: add GRND_INSECURE from linux v5.6
added in

  linux commit 75551dbf112c992bc6c99a972990b3f272247e23
  random: add GRND_INSECURE to return best-effort non-cryptographic bytes
2020-09-09 17:20:27 -04:00
Szabolcs Nagy
8f4aa78a0c sys/prctl.h: add PR_{SET,GET}_IO_FLUSHER from linux v5.6
needed for storage drivers with userspace component that may
run in the IO path, see

  linux commit 8d19f1c8e1937baf74e1962aae9f90fa3aeab463
  prctl: PR_{G,S}ET_IO_FLUSHER to support controlling memory reclaim
2020-09-09 17:20:22 -04:00
Szabolcs Nagy
1ab341e89b netinet/udp.h: add TCP_ENCAP_ESPINTCP from linux v5.6
The use of TCP_ in udp.h is not known, fortunately udp.h is not
specified by posix so there are no strict namespace rules, added in

  linux commit e27cca96cd68fa2c6814c90f9a1cfd36bb68c593
  xfrm: add espintcp (RFC 8229)
2020-09-09 17:20:19 -04:00
Szabolcs Nagy
c6321616b8 netinet/tcp.h: update for linux v5.6
TCP_NLA_TIMEOUT_REHASH queries timeout-triggered rehash attempts,
tcpm_ifindex limits the scope of TCP_MD5SIG* sockopt to a device.

see

  linux commit 32efcc06d2a15fa87585614d12d6c2308cc2d3f3
  tcp: export count for rehash attempts

  linux commit 6b102db50cdde3ba2f78631ed21222edf3a5fb51
  net: Add device index to tcp_md5sig
2020-09-09 17:20:18 -04:00
Szabolcs Nagy
8fca0ea4e9 netinet/in.h: add IPPROTO_ macros from linux v5.6
add IPPROTO_ETHERNET and IPPROTO_MPTCP, see

  linux commit 2677625387056136e256c743e3285b4fe3da87bb
  seg6: fix SRv6 L2 tunnels to use IANA-assigned protocol number

  linux commit faf391c3826cd29feae02078ca2022d2f912f7cc
  tcp: Define IPPROTO_MPTCP
2020-09-09 17:20:15 -04:00
Szabolcs Nagy
d4f298149c netinet/tcp.h: update tcp_info for linux v5.5
see

  linux commit 480274787d7e3458bc5a7cfbbbe07033984ad711
  tcp: add TCP_INFO status for failed client TFO
2020-09-09 17:19:50 -04:00
Rich Felker
1ccc804e13 fix regression with applications that expect struct winsize in ioctl.h
putting the (simple) definition in alltypes.h seems like the best
solution here. making sys/ioctl.h implicitly include termios.h is
probably excess namespace pollution.
2020-08-30 16:47:40 -04:00
Rich Felker
4d5786544b add tcgetwinsize and tcsetwinsize functions, move struct winsize
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.
2020-08-24 21:31:18 -04:00
Rich Felker
d49cf07541 add gettid function
this is a prerequisite for addition of other interfaces that use
kernel tids, including futex and SIGEV_THREAD_ID.

there is some ambiguity as to whether the semantic return type should
be int or pid_t. either way, futex API imposes a contract that the
values fit in int (excluding some upper reserved bits). glibc used
pid_t, so in the interest of not having gratuitous mismatch (the
underlying types are the same anyway), pid_t is used here as well.

while conceptually this is a syscall, the copy stored in the thread
structure is always valid in all contexts where it's valid to call
libc functions, so it's used to avoid the syscall.
2020-08-17 20:12:53 -04:00
Rich Felker
2f2348c958 remove duplicate definitions of INET[6]_ADDRSTRLEN
these were leftover from early beginnings when arpa/inet.h was not
including netinet/in.h.
2020-03-04 12:33:35 -05:00
Rich Felker
4e0796dfc7 add PTHREAD_NULL
this is added for POSIX-future as the outcome of Austin Group issue
599. since it's in the reserved namespace for pthread.h, there are no
namespace considerations for adding it early.
2020-02-26 10:09:32 -05:00
Rich Felker
e6093b5a87 fix misleading use of _POSIX_VDISABLE in sys/ttydefaults.h
_POSIX_VDISABLE is only visible if unistd.h has already been included,
so conditional use of it here makes no sense. the value is always 0
anyway; it does not vary.
2020-01-29 10:47:48 -05:00
Rich Felker
a0217a2ff7 fix unprotected macro argument in sys/ttydefaults.h 2020-01-29 10:47:19 -05:00
Rich Felker
614c9e7b1e move struct dirent to bits header, allow NAME_MAX to vary
this is not necessary for linux but is a simple, inexpensive change to
make that facilitates ports to systems where NAME_MAX needs to be
longer.
2020-01-25 23:08:55 -05:00
Leah Neukirchen
2507e7f531 define RLIMIT_RTTIME, bump RLIMIT_NLIMITS
This macro exists since Linux 2.6.25 and is defined in glibc since 2011.
2020-01-11 21:10:41 -05:00
Michael Forney
a56ec7e8e2 unconditonally define alloca as __builtin_alloca
This enables alternative compilers, which may not define __GNUC__,
to implement alloca, which is still fairly widely used.

This is similar to how stdarg.h already works in musl; compilers must
implement __builtin_va_arg, there is no fallback definition.
2020-01-01 15:07:11 -05:00
Rich Felker
ac89e2ccf5 remove gratuitous aligned attribute from __ptrace_syscall_info
this change was discussed on the mailing list thread for the linux
uapi v5.3 patches, and submitted as a v2 patch, but overlooked when I
applied the patches much later.

revert commit f291c09ec9 and apply the
v2 as submitted; the net change is just padding.

notes by Szabolcs Nagy follow:

compared to the linux uapi (and glibc) a padding is used instead of
aligned attribute for keeping the layout the same across targets, this
means the alignment of the struct may be different on some targets
(e.g. m68k where uint64_t is 2 byte aligned) but that should not affect
syscalls and this way the abi does not depend on nonstandard extensions.
2020-01-01 11:16:56 -05:00
Szabolcs Nagy
f296be74d5 sys/wait.h: add P_PIDFD from linux v5.4
allows waiting on a pidfd, in the future it might allow retrieving the
exit status by a non-parent process, see

  linux commit 3695eae5fee0605f316fbaad0b9e3de791d7dfaf
  pidfd: add P_PIDFD to waitid()
2019-12-30 18:14:08 -05:00
Szabolcs Nagy
5e0c9f246c netinet/tcp.h: add new tcp_info fields from linux v5.4
tcpi_rcv_ooopack for tracking connection quality:

  linux commit f9af2dbbfe01def62765a58af7fbc488351893c3
  tcp: Add TCP_INFO counter for packets received out-of-order

tcpi_snd_wnd peer window size for diagnosing tcp performance problems:

  linux commit 8f7baad7f03543451af27f5380fc816b008aa1f2
  tcp: Add snd_wnd to TCP_INFO
2019-12-30 18:14:08 -05:00
Szabolcs Nagy
5675aaa559 sys/prctl.h: add PR_*_TAGGED_ADDR_* from linux v5.4
per thread prctl commands to relax the syscall abi such that top bits
of user pointers are ignored in the kernel. this allows the use of
those bits by hwasan or by mte to color pointers and memory on aarch64:

  linux commit 63f0c60379650d82250f22e4cf4137ef3dc4f43d
  arm64: Introduce prctl() options to control the tagged user addresses ABI
2019-12-30 18:14:08 -05:00
Szabolcs Nagy
d95ead261e sys/mman.h: add MADV_COLD and MADV_PAGEOUT from linux v5.4
These were mainly introduced so android can optimize the memory usage
of unused apps.

MADV_COLD hints that the memory range is currently not needed (unlike
with MADV_FREE the content is not garbage, it needs to be swapped):

  linux commit 9c276cc65a58faf98be8e56962745ec99ab87636
  mm: introduce MADV_COLD

MADV_PAGEOUT hints that the memory range is not needed for a long time
so it can be reclaimed immediately independently of memory pressure
(unlike with MADV_DONTNEED the content is not garbage):

  linux commit 1a4e58cce84ee88129d5d49c064bd2852b481357
  mm: introduce MADV_PAGEOUT
2019-12-30 18:14:08 -05:00
Szabolcs Nagy
f291c09ec9 sys/ptrace.h: add PTRACE_GET_SYSCALL_INFO from linux v5.3
ptrace API to get details of the syscall the tracee is blocked in, see

  linux commit 201766a20e30f982ccfe36bebfad9602c3ff574a
  ptrace: add PTRACE_GET_SYSCALL_INFO request

the align attribute was used to keep the layout the same across targets
e.g. on m68k uint32_t is 2 byte aligned, this helps with compat ptrace.
2019-12-30 18:12:49 -05:00
Szabolcs Nagy
06636c5542 sys/socket.h: add SO_DETACH_REUSEPORT_BPF from linux v5.3
see

  linux commit 99f3a064bc2e4bd5fe50218646c5be342f2ad18c
  bpf: net: Add SO_DETACH_REUSEPORT_BPF
2019-12-30 18:12:46 -05:00
Szabolcs Nagy
167cbf1316 netinet/if_ether.h: add ETH_P_LLDP from linux v5.3
see

  linux commit c54c2c72b2b90a3ba61b8cad032a578ce2bf5b35
  net: Add a define for LLDP ethertype
2019-12-30 18:12:42 -05:00
Szabolcs Nagy
af2576e61d netinet/tcp.h: add TCP_TX_DELAY from linux v5.3
see

  linux commit a842fe1425cb20f457abd3f8ef98b468f83ca98b
  tcp: add optional per socket transmit delay
2019-12-30 18:12:40 -05:00
A. Wilcox
0738e6c19f add uapi guards for new netinet/ip.h conflict with struct iphdr
This ensures that the musl definition of 'struct iphdr' does not conflict
with the Linux kernel UAPI definition of it.

Some software, i.e. net-tools, will not compile against 5.4 kernel headers
without this patch and the corresponding Linux kernel patch.
2019-12-22 12:45:48 -05:00
Rich Felker
1e7f0fcd7f adjust utmpx struct layout for time64, 32-/64-bit arch compat
since time64 switchover has changed the size and layout of the struct
anyway, take the opportunity to fix it up so that it can be shared
between 32- and 64-bit ABIs on the same system as long as byte order
matches.

the ut_type member is explicitly padded to make up for m68k having
only 2-byte alignment; explicit padding has no effect on other archs.

ut_session is changed from long to int, with endian-matched padding.
this affects 64-bit archs as well, but brings the type into alignment
with glibc's x86_64 struct, so it should not break software, and does
not break on-disk format. the semantic type is int (pid-like) anyway.
the padding produces correct alignment for the ut_tv member on 32-bit
archs that don't naturally align it, so that ABI matches 64-bit.

this type is presently not used anywhere in the ABI between libc and
libc consumers; it's only used between pairs of consumers if a
third-party utmp library using the system utmpx.h is in use.
2019-12-22 12:37:16 -05:00
Rich Felker
3f959f6f76 fix elf_prstatus regression on time64, existing wrong definition on x32
the elf_prstatus structure is used in core dumps, and the timeval
structures in it are longs matching the elf class, *not* the kernel
"old timeval" for the arch. this means using timeval here for x32 was
always wrong, despite kernel uapi headers and glibc also exposing it
this way, and of course it's wrong for any arch with 64-bit time_t.

rather than just changing the type on affected archs, use a tagless
struct containing long tv_sec and tv_usec members in place of the
timevals. this intentionally breaks use of them as timevals (e.g.
assignment, passing address, etc.) on 64-bit archs as well so that any
usage unsafe for 32-bit archs is caught even in software that only
gets tested on 64-bit archs. from what I could gather, there is not
any software using these members anyway. the only reason they need to
be fixed to begin with is that the only members which are commonly
used, the saved registers, follow the time members and have the wrong
offset if the time members are sized incorrectly.
2019-12-22 11:20:44 -05:00
Rich Felker
b329095650 fix regression in ioctl definitions provided by arch/generic bits
commit b60fdf133c broke the
SIOCGSTAMP[NS] ioctl fallbacks introduced in commit
2e554617e5, as well as use of these
ioctls, by creating a situation where bits/ioctl.h could be included
without __LONG_MAX being visible.
2019-12-18 18:03:43 -05:00
Rich Felker
f12bd8e05c signal to kernel headers that time_t is 64-bit
linux/input.h and perhaps others use this macro to determine whether
the userspace time_t is 64-bit when potentially defining types in
terms of time_t and derived structures. the name __USE_TIME_BITS64 is
unfortunate; it really should have been in the __UAPI namespace. but
this is what was chosen back in v4.16 when first preparing input.h for
time64 userspace, presumably based on expectations about what the
glibc-internal features.h macro for time64 would be, and changing it
now would just put a new minimum version requirement on kernel
headers.

the __USE_TIME_BITS64 macro is not intended as a public interface. it
is purely an internal contract between libc and Linux uapi headers.
2019-12-17 18:19:05 -05:00
Rich Felker
d6dcfe4d0c move time_t and suseconds_t definitions to common alltypes.h.in
now that all 32-bit archs have 64-bit time_t (and suseconds_t), the
arch-provided _Int64 macro (long or long long, as appropriate) can be
used to define them, and arch-specific definitions are no longer
needed.
2019-11-02 18:30:56 -04:00
Rich Felker
c71dbb24c9 move time64 socket options from arch bits to top-level sys/socket.h
now that all 32-bit archs have 64-bit time types, the values for the
time-related socket option macros can be treated as universal for
32-bit archs. the sys/socket.h mechanism for this predates
arch/generic and is instead in the top-level header.

x32, which does not use the new time64 values of the macros, already
has its own overrides, so this commit does not affect it.
2019-11-02 18:30:56 -04:00
Rich Felker
a0252bc75b move msghdr and cmsghdr out of bits/socket.h
these structures can now be defined generically in terms of endianness
and long size. previously, the 32-bit archs all shared a common
definition from the generic bits header, and each 64-bit arch had to
repeat the 64-bit version, with endian conditionals if the arch had
variants of each endianness.

I would prefer getting rid of the preprocessor conditionals for
padding and instead using unnamed bitfield members, like commit
9b2921bea1 did for struct timespec.
however, at present sendmsg, recvmsg, and recvmmsg need access to the
padding members by name to zero them. this could perhaps be cleaned up
in the future.
2019-11-02 18:30:56 -04:00
Rich Felker
0bbc04c981 make time-related socket options overridable by arch bits files
SO_RCVTIMEO and SO_SNDTIMEO already were, but only in aggregate with
SO_DEBUG and all of the other low/traditional options that varied per
arch. SO_TIMESTAMP* are newly overridable. the two groups have to be
done separately since mips64 and powerpc64 will override the former
but not the latter.

at some point this should be cleaned up to use bits headers more
idiomatically.
2019-11-02 18:30:56 -04:00
Rich Felker
22daaea39f add time64 redirect for, and redirecting implementation of, dlsym
if symbols are being redirected to provide the new time64 ABI, dlsym
must perform matching redirections; otherwise, it would poke a hole in
the magic and return pointers to functions that are not safe to call
from a caller using time64 types.

rather than duplicating a table of redirections, use the time64
symbols present in libc's symbol table to derive the decision for
whether a particular symbol needs to be redirected.
2019-11-02 18:30:56 -04:00
Rich Felker
2d69fcf5ef prepare struct sched_param for change in time_t definition
the time_t members in struct sched_param are just reserved space to
preserve size and alignment. when time_t changes to 64-bit on 32-bit
archs, this structure should not change.

make definition conditional on _REDIR_TIME64 to match the size of the
old time_t, which can be assumed to be long if _REDIR_TIME64 is
defined.
2019-10-28 19:26:52 -04:00
Rich Felker
1febd21d3f add time64 symbol name redirects to public headers, under arch control
a _REDIR_TIME64 macro is introduced, which the arch's alltypes.h is
expected to define, to control redirection of symbol names for
interfaces that involve time_t and derived types. this ensures that
object files will only be linked to libc interfaces matching the ABI
whose headers they were compiled against.

along with time32 compat shims, which will be introduced separately,
the redirection also makes it possible for a single libc (static or
shared) to be used with object files produced with either the old
(32-bit time_t) headers or the new ones after 64-bit time_t switchover
takes place. mixing of such object files (or shared libraries) in the
same program will also be possible, but must be done with care; ABI
between libc and a consumer of the libc interfaces is guaranteed to
match by the the symbol name redirection, but pairwise ABI between
consumers of libc that define interfaces between each other in terms
of time_t is not guaranteed to match.

this change adds a dependency on an additional "GNU C" feature to the
public headers for existing 32-bit archs, which is generally
undesirable; however, the feature is one which glibc has depended on
for a long time, and thus which any viable alternative compiler is
going to need to provide. 64-bit archs are not affected, nor will
future 32-bit archs be, regardless of whether they are "new" on the
kernel side (e.g. riscv32) or just newly-added (e.g. a new sparc or
xtensa port). the same applies to newly-added ABIs for existing
machine-level archs.
2019-10-28 19:26:52 -04:00
Rich Felker
9b2921bea1 adjust struct timespec definition to be time64-ready
for time64 support on 32-bit archs, the kernel interfaces use a
timespec layout padded to match the representation of a pair of 64-bit
values, which requires endian-specific padding.

use of an ordinary, non-bitfield, named member for the padding is
undesirable because, on big endian archs, it would alter the
interpretation of traditional (non-designated) initializers of the
form {s,ns}, initializing the padding instead of the tv_nsec member.
unnamed bitfield members solve this problem by not taking part in
initialization, and were the expected solution when the kernel
interfaces were designed. however, they also have further advantages
which we take advantage of here:

positioning of the padding could be controlled by having a
preprocessor conditional with separate definitions of struct timespec
for little and big endian, but whether padding should appear at all is
a function of whether time_t is larger than long. this condition is
not something the preprocessor can determine unless we were to define
a new macro specifically for that purpose.

by using unnamed bitfield members instead of ordinary named members,
we can arrange for the size of the padding to collapse to zero when it
should not be present, just by using sizeof(time_t) and sizeof(long)
in the bitfield width expression, which can be any integer constant
expression.
2019-10-20 03:27:58 -04:00
Rich Felker
2d3083e746 move pthread types out of per-arch alltypes.h
policy has long been that these definitions are purely a function of
whether long/pointer is 32- or 64-bit, and that they are not allowed
to vary per-arch. move the definition to the shared alltypes.h.in
fragment, using integer constant expressions in terms of sizeof to
vary the array dimensions appropriately. I'm not sure whether this is
more or less ugly than using preprocessor conditionals and two sets of
definitions here, but either way is a lot less ugly than repeating the
same thing for every arch.
2019-10-17 19:35:17 -04:00
Rich Felker
7cc79d10af define LONG_MAX via arch alltypes.h, strip down bits/limits.h
LLONG_MAX is uniform for all archs we support and plenty of header and
code level logic assumes it is, so it does not make sense for limits.h
bits mechanism to pretend it's variable.

LONG_BIT can be defined in terms of LONG_MAX; there's no reason to put
it in bits.

by moving LONG_MAX definition to __LONG_MAX in alltypes.h and moving
LLONG_MAX out of bits, there are now no plain-C limits that are
defined in the bits header, so the bits header only needs to be
included in the POSIX or extended profiles. this allows the feature
test macro logic to be removed from the bits header, facilitating a
long-term goal of getting such logic out of bits.

having __LONG_MAX in alltypes.h will allow further generalization of
headers.

archs without a constant PAGESIZE no longer need bits/limits.h at all.
2019-10-17 19:23:39 -04:00
Rich Felker
316730cdc7 make endian.h expose unprefixed macros, functions in standard profile
the resolution of Austin Group issue #162 adds endian.h as a standard
header for future versions of the standard, making it no longer
acceptable for some of the functionality to be hidden behind
_BSD_SOURCE or _GNU_SOURCE. the definitions of the [lb]etoh{16,32,64}
function-like macros are kept conditional since they are alternate
names which the standard did not adopt.
2019-10-17 16:26:22 -04:00
Rich Felker
71d23fbeac remove indirect use of endian.h from public headers
building on commit 97d35a552e,
__BYTE_ORDER is now available wherever alltypes.h is included.
endian.h should not be used since, in the future, it will expose
identifiers that are not in the reserved namespace for the headers
which were previously using it.
2019-10-17 16:03:42 -04:00
Rich Felker
97d35a552e move __BYTE_ORDER definition to alltypes.h
this change is motivated by the intersection of several factors.
presently, despite being a nonstandard header, endian.h is exposing
the unprefixed byte order macros and functions only if _BSD_SOURCE or
_GNU_SOURCE is defined. this is to accommodate use of endian.h from
other headers, including bits headers, which need to define structure
layout in terms of endianness. with time64 switch-over, even more
headers will need to do this.

at the same time, the resolution of Austin Group issue 162 makes
endian.h a standard header for POSIX-future, requiring that it expose
the unprefixed macros and the functions even in standards-conforming
profiles. changes to meet this new requirement would break existing
internal usage of endian.h by causing it to violate namespace where
it's used.

instead, have the arch's alltypes.h define __BYTE_ORDER, either as a
fixed constant or depending on the right arch-specific predefined
macros for determining endianness. explicit literals 1234 and 4321 are
used instead of __LITTLE_ENDIAN and __BIG_ENDIAN so that there's no
danger of getting the wrong result if a macro is undefined and
implicitly evaluates to 0 at the preprocessor level.

the powerpc (32-bit) bits/endian.h being removed had logic for varying
endianness, but our powerpc arch has never supported that and has
always been big-endian-only. this logic is not carried over to the new
__BYTE_ORDER definition in alltypes.h.
2019-10-17 15:55:15 -04:00
Rich Felker
00ec11d19e remove per-arch definitions for va_list
now that commit f7f1079796 removed the
legacy i386 conditional definition, va_list is in no way
arch-specific, and has no reason to be in the future. move it to the
shared part of alltypes.h.in
2019-10-17 15:27:00 -04:00
Szabolcs Nagy
81e795e1f1 fcntl.h: add AT_RECURSIVE from linux v5.2
apply open_tree with OPEN_TREE_CLONE call to the entire subtree, see

  linux commit a07b20004793d8926f78d63eb5980559f7813404
  vfs: syscall: Add open_tree(2) to reference or clone a mount
2019-09-11 10:40:31 -04:00
Szabolcs Nagy
cc1a53515b fcntl.h: add AT_STATX_ statx sync flag definitions
see

  linux commit a528d35e8bfcc521d7cb70aaf03e1bd296c8493f
  statx: Add a system call to make enhanced file info available

these are linux specific and not reserved names for fcntl.h so they
are under _BSD_SOURCE|_GNU_SOURCE.
2019-09-11 10:40:11 -04:00
Szabolcs Nagy
1e22eb2e8f sched.h: add CLONE_PIDFD from linux v5.2
when set a pidfd is stored in parent_tidptr, see

  linux commit b3e5838252665ee4cfa76b82bdf1198dca81e5be
  clone: add CLONE_PIDFD
2019-09-11 10:40:04 -04:00
Szabolcs Nagy
b5134ccd4d netinet/if_ether.h: add ETH_P_DSA_8021Q from linux v5.2
ethertype for fake VLAN header for DSA, see

  linux commit bf5bc3ce8a8f32a0d45b6820ede8f9fc3e9c23df
  ether: Add dedicated Ethertype for pseudo-802.1Q DSA tagging
2019-09-11 10:39:58 -04:00
Rich Felker
a882841baf add public declaration for optreset under appropriate feature profiles
commit 030e526392 added optreset, a BSD
extension to getopt duplicating the functionality (also an extension)
of setting optind to 0, but failed to provide a public declaration for
it. according to the BSD documentation and headers, the application is
not supposed to need to provide its own declaration.
2019-08-30 17:48:47 -04:00
Rich Felker
74244e5b3e add posix_spawn [f]chdir file actions
these are presently extensions, thus named with _np to match glibc and
other implementations that provide them; however they are likely to be
standardized in the future without the _np suffix as a result of
Austin Group issue 1208. if so, both names will be kept as aliases.
2019-08-30 16:21:36 -04:00
Árni Dagur
f76e183111 add copy_file_range system call wrapper 2019-08-23 20:24:06 -04:00
Rich Felker
827aa8fbca remove sporadic server members from struct sched_param
these members are associated with an unsupported option group. with
time_t changing size on 32-bit archs, all interfaces taking struct
sched_param arguments would need redirection and compat shims in order
to be able to continue offering these members, for no benefit. just
convert them to reserved space instead.
2019-08-14 20:50:42 -04:00
Petr Vaněk
7844ecb590 add secure_getenv function
This function is a GNU extension introduced in glibc 2.17.
2019-08-08 11:33:18 -04:00
Ismael Luceno
49eacf29d2 glob: implement GLOB_TILDE and GLOB_TILDE_CHECK 2019-08-06 14:03:31 -04:00
Rich Felker
006a75a997 move IPC_STAT definition to a new bits/ipcstat.h file
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.
2019-08-02 00:08:23 -04:00
Rich Felker
3c02bacf0f allow archs to define IPC_STAT, propagate time64 bit to other macros
to make use of {sem,shm,msg}ctl IPC_STAT functionality to provide
64-bit time_t on 32-bit archs, IPC_STAT and related macros must be
defined with bit 8 (0x100) set. allow archs to define IPC_STAT in
bits/ipc.h, and define the other macros in terms of it so that they
all get the same value of the time64 bit.
2019-08-02 00:08:23 -04:00
Szabolcs Nagy
47bc7f0afe elf.h: add NT_ARM_PAC{A,G}_KEYS from linux v5.1
to request or change pointer auth keys for criu via ptrace, new in

  linux commit d0a060be573bfbf8753a15dca35497db5e968bb0
  arm64: add ptrace regsets for ptrauth key management
2019-07-01 14:16:49 -04:00
Szabolcs Nagy
eea841e653 netinet/in.h: add INADDR_ALLSNOOPERS_GROUP from linux v5.1
RFC 4286: "The IPv4 multicast address for All-Snoopers is 224.0.0.106."
from

  linux commit 4effd28c1245303dce7fd290c501ac2c11052114
  bridge: join all-snoopers multicast address
2019-07-01 14:16:41 -04:00
Szabolcs Nagy
5b2b682ddc sys/socket.h: add SO_BINDTOIFINDEX from linux v5.1
SO_BINDTOIFINDEX behaves similar to SO_BINDTODEVICE, but takes a
network interface index as argument, rather than the network
interface name. see

  linux commit f5dd3d0c9638a9d9a02b5964c4ad636f06cf7e2c
  net: introduce SO_BINDTOIFINDEX sockopt
2019-07-01 14:12:36 -04:00
Szabolcs Nagy
93b5f6c843 netinet/in.h: add IPV6_ROUTER_ALERT_ISOLATE from linux v5.1
restricts router alert packets received by the socket to the
socket's namespace only. see

  linux commit 9036b2fe092a107856edd1a3bad48b83f2b45000
  net: ipv6: add socket option IPV6_ROUTER_ALERT_ISOLATE
2019-07-01 14:12:14 -04:00
Szabolcs Nagy
c7081edcf8 sys/prctl.h: add PR_SPEC_DISABLE_NOEXEC from linux v5.1
allows specifying that the speculative store bypass disable bit should
be cleared on exec. see

  linux commit 71368af9027f18fe5d1c6f372cfdff7e4bde8b48
  x86/speculation: Add PR_SPEC_DISABLE_NOEXEC
2019-07-01 14:12:06 -04:00
Szabolcs Nagy
9e8dd1c7f1 fcntl.h: add F_SEAL_FUTURE_WRITE from linux v5.1
needed for android so it can migrate from its ashmem to memfd.
allows making the memfd readonly for future users while keeping
a writable mmap of it. see

  linux commit ab3948f58ff841e51feb845720624665ef5b7ef3
  mm/memfd: add an F_SEAL_FUTURE_WRITE seal to memfd
2019-07-01 14:11:56 -04:00
Szabolcs Nagy
f67b3c1799 sys/fanotify.h: update for linux v5.1
includes changes from linux v5.1

  linux commit 235328d1fa4251c6dcb32351219bb553a58838d2
  fanotify: add support for create/attrib/move/delete events

  linux commit 5e469c830fdb5a1ebaa69b375b87f583326fd296
  fanotify: copy event fid info to user

  linux commit e9e0c8903009477b630e37a8b6364b26a00720da
  fanotify: encode file identifier for FAN_REPORT_FID

as well as earlier changes that were missed.

sys/statfs.h is included for fsid_t.
2019-07-01 14:11:42 -04:00
Rich Felker
a31a30a007 remove implicit include of sys/sysmacros.h from sys/types.h
this reverts commit f552c792c7, which
exposed the sysmacros.h macros (device major/minor calculations) for
BSD and GNU profiles to mimic an unintentional glibc behavior some
code depended on. glibc has deprecated and since removed them as the
resolution to bug #19239, so it makes no sense for us to keep this
behavior. affected code should all have been fixed by now, and if it's
not yet fixed it needs to be for use with modern glibc anyway.
2019-06-21 15:49:38 -04:00
Rich Felker
0a48860c27 add riscv64 architecture support
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.
2019-06-14 17:13:05 -04:00
Szabolcs Nagy
e980ca7a57 define FP_FAST_FMA* when fma* can be inlined
FP_FAST_FMA can be defined if "the fma function generally executes about
as fast as, or faster than, a multiply and an add of double operands",
which can only be true if the fma call is inlined as an instruction.

gcc sets __FP_FAST_FMA if __builtin_fma is inlined as an instruction,
but that does not mean an fma call will be inlined (e.g. it is defined
with -fno-builtin-fma), other compilers (clang) don't even have such
macro, but this is the closest we can get.

(even if the libc fma implementation is a single instruction, the extern
call overhead is already too big when the macro is used to decide between
x*y+z and fma(x,y,z) so it cannot be based on libc only, defining the
macro unconditionally on targets which have fma in the base isa is also
incorrect: the compiler might not inline fma anyway.)

this solution works with gcc unless fma inlining is explicitly turned off.
2019-04-17 13:02:47 -04:00
A. Wilcox
65c8be3804 fcntl.h: define O_TTY_INIT to 0
POSIX: "[If] either O_TTY_INIT is set in oflag or O_TTY_INIT has the
value zero, open() shall set any non-standard termios structure
terminal parameters to a state that provides conforming behavior."

The Linux kernel tty drivers always perform initialisation on their
devices to set known good termios values during the open(2) call.  This
means that setting O_TTY_INIT to zero is conforming.
2019-04-10 20:37:04 -04:00
Bobby Bingham
e8e780af98 fix signature of function accepted by makecontext
This parameter was incorrectly declared to be a pointer to a function
accepting zero parameters.  The intent of makecontext is that it is
possible to pass integer parameters to the function, so this should
have been a pointer to a function accepting an unspecified set of
parameters.
2019-04-05 17:29:00 -04:00
Szabolcs Nagy
cff993cf32 sys/prctl.h: add PR_PAC_RESET_KEYS from linux v5.0
aarch64 pointer authentication code related prctl that allows
reinitializing the key for the thread, added in linux commit
ba830885656414101b2f8ca88786524d4bb5e8c1
2019-03-13 12:34:56 -04:00
Szabolcs Nagy
843e453c11 elf.h: add NT_ definitions from linux v5.0
NT_MIPS_MSA for ptrace access to mips simd arch reg set, added in linux
commit 3cd640832894b85b5929d5bda74505452c800421
NT_ARM_PAC_MASK for ptrace access to pointer auth code mask, added in
commit ec6e822d1a22d0eef1d1fa260dff751dba9a4258
2019-03-13 12:34:08 -04:00
Szabolcs Nagy
02f769b20d elf.h: update with C-SKY definitions
C-SKY support was added to binutils 2.32 in commit
b8891f8d622a31306062065813fc278d8a94fe21
the elf.h change was added to glibc 2.29 in commit
4975f0c3d0131fdf697be0b1631c265e5fd39088
2019-03-13 12:34:03 -04:00
Szabolcs Nagy
9e06514e23 netinet/tcp.h: add TCP_NLA_SRTT from linux v5.0
smoothed RTT for SCM_TIMESTAMPING_OPT_STATS control messages.
added in linux commit e8bd8fca6773ef49390269bd467bf940a0841ccf
2019-03-13 12:33:54 -04:00
Szabolcs Nagy
292bda7ceb netinet/udp.h: add UDP_GRO from linux v5.0
sockopt to enable gro for udp.
added in linux commit e20cf8d3f1f763ad28a9cb3b41305b8a8a42653e
2019-03-13 12:33:51 -04:00
Szabolcs Nagy
13c73da72f sys/prctl.h: add PR_SPEC_INDIRECT_BRANCH from linux v4.20
prctls to allow per task control of indirect branch speculation on x86.

added in linux commit 9137bb27e60e554dab694eafa4cca241fa3a694f
2019-03-13 12:33:04 -04:00