Commit Graph

978 Commits

Author SHA1 Message Date
Rich Felker
bc695a5ac1 fix incorrect unit for CPU_SETSIZE macro
this macro is supposed to reflect the number of members (bits) in
cpu_set_t, not the storage size (bytes).
2023-02-23 10:10:44 -05:00
Rich Felker
ea3b40a321 fix integer overflow in WIFSTOPPED macro
the result of the 0xffff mask with the exit status could have bit 15
set, in which case multiplying by 0x10001 overflows 32-bit signed int.
making the multiply unsigned avoids the overflow. it also changes the
sign extension behavior of the subsequent >> operation, but the
affected bits are all unwanted anyway and all discarded by the cast to
short.
2023-02-08 16:42:28 -05:00
Rich Felker
a4b0a665b8 expose memmem under baseline POSIX feature profile
memmem has been adopted for the next issue of POSIX (outcome of
tracker item 1061). since mem* is in the reserved namespace for
string.h it's already fully conforming to expose it by default, so
just do so.
2023-01-06 06:33:19 -05:00
Fangrui Song
c5f4b2dfea elf.h: add ELFCOMPRESS_ZSTD 2022-12-14 09:34:32 -05:00
Rich Felker
25e6fee27f remove LFS64 programming interfaces (macro-only) from _GNU_SOURCE
these badly pollute the namespace with macros whenever _GNU_SOURCE is
defined, which is always the case with g++, and especially tends to
interfere with C++ constructs.

as our implementation of these was macro-only, their removal cannot
affect any existing binaries. at the source level, portable software
should be prepared for them not to exist.

for now, they are left in place with explicit _LARGEFILE64_SOURCE.
this provides an easy temporary path for integrators/distributions to
get packages building again right away if they break while working on
a proper, upstreamable fix. the intent is that this be a very
short-term measure and that the macros be removed entirely in the next
release cycle.
2022-10-19 14:01:31 -04:00
Rich Felker
759bf785a8 arpa/nameser.h: update RR types list
our RR type list in arpa/nameser.h was badly outdated, and missing
important types for DNSSEC and DANE use, among other things.
2022-09-22 18:44:44 -04:00
Rich Felker
85050ac5a2 getaddrinfo: add EAI_NODATA error code to distinguish NODATA vs NxDomain
this was apparently omitted long ago out of a lack of understanding of
its importance and the fact that POSIX doesn't specify it. despite not
being officially standardized, however, it turns out that at least
AIX, glibc, NetBSD, OpenBSD, QNX, and Solaris document and support it.

in certain usage cases, such as implementing a DNS gateway on top of
the stub resolver interfaces, it's necessary to distinguish the case
where a name does not exit (NxDomain) from one where it exists but has
no addresses (or other records) of the requested type (NODATA). in
fact, even the legacy gethostbyname API had this distinction, which we
were previously unable to support correctly because the backend lacked
it.

apart from fixing an important functionality gap, adding this
distinction helps clarify to users how search domain fallback works
(falling back in cases corresponding to EAI_NONAME, not in ones
corresponding to EAI_NODATA), a topic that has been a source of
ongoing confusion and frustration.

as a result of this change, EAI_NONAME is no longer a valid universal
error code for getaddrinfo in the case where AI_ADDRCONFIG has
suppressed use of all address families. in order to return an accurate
result in this case, getaddrinfo is modified to still perform at least
one lookup. this will almost surely fail (with a network error, since
there is no v4 or v6 network to query DNS over) unless a result comes
from the hosts file or from ip literal parsing, but in case it does
succeed, the result is replaced by EAI_NODATA.

glibc has a related error code, EAI_ADDRFAMILY, that could be used for
the AI_ADDRCONFIG case and certain NODATA cases, but distinguishing
them properly in full generality seems to require additional DNS
queries that are otherwise not useful. on glibc, it is only used for
ip literals with mismatching family, not for DNS or hosts file results
where the name has addresses only in the opposite family. since this
seems misleading and inconsistent, and since EAI_NODATA already covers
the semantic case where the "name" exists but doesn't have any
addresses in the requested family, we do not adopt EAI_ADDRFAMILY at
this time. this could be changed at some point if desired, but the
logic for getting all the corner cases with AI_ADDRCONFIG right is
slightly nontrivial.
2022-09-20 18:09:42 -04:00
Rich Felker
25340a9337 add sysconf keys/values for signal stack size
as a result of ISA extensions exploding register file sizes on some
archs, using a constant for minimum signal stack size no longer seems
viably future-proof. add sysconf keys allowing the kernel to provide a
machine-dependent minimum applications can query to ensure they
allocate sufficient space for stacks. the key names and indices align
with the same functionality in glibc.

see commit d5a5045382 for previous
action on this subject.

ultimately, the macros MINSIGSTKSZ and SIGSTKSZ probably need to be
deprecated, but that is standards-amendment work outside the scope of
a single implementation.
2022-08-26 10:20:46 -04:00
Fangrui Song
d32dadd60e ldso: support DT_RELR relative relocation format
this resolves DT_RELR relocations in non-ldso, dynamic-linked objects.
2022-08-02 17:27:45 -04:00
Michael Pratt
46d1c7801b fix strings.h feature test macro usage due to missing features.h 2022-08-01 13:57:11 -04:00
Rich Felker
55b727d7ad add missing POSIX confstr keys for pthread CFLAGS/LDFLAGS
_CS_POSIX_V7_THREADS_CFLAGS and _CS_POSIX_V7_THREADS_LDFLAGS have been
missing for a long time, which is a conformance defect. we were
waiting on glibc to add them or at least agree on the numeric values
they will have so as to keep the numbering aligned. it looks like they
will be added to glibc with these numbers, and in any case, this list
does not have any significant churn that would result in the numbers
getting taken.
2022-04-20 09:06:54 -04:00
Szabolcs Nagy
bdb5454065 sys/ptrace.h: add PTRACE_GET_RSEQ_CONFIGURATION from linux v5.13
see

  linux commit 90f093fa8ea48e5d991332cee160b761423d55c1
  rseq, ptrace: Add PTRACE_GET_RSEQ_CONFIGURATION request

the struct type got __ prefix to follow existing practice.
2022-03-08 17:21:26 -05:00
Szabolcs Nagy
aa3bab6ce4 sys/prctl.h: add PR_PAC_{SET,GET}_ENABLED_KEYS from linux v5.13
see

  linux commit 201698626fbca1cf1a3b686ba14cf2a056500716
  arm64: Introduce prctl(PR_PAC_{SET,GET}_ENABLED_KEYS)
2022-03-08 17:21:26 -05:00
Szabolcs Nagy
a8300f5d2a elf.h: add NT_ARM_PAC_ENABLED_KEYS from linux v5.13
see

  linux commit 201698626fbca1cf1a3b686ba14cf2a056500716
  arm64: Introduce prctl(PR_PAC_{SET,GET}_ENABLED_KEYS)
2022-03-08 17:21:26 -05:00
Szabolcs Nagy
dda21f10a7 netinet/in.h: add INADDR_DUMMY from linux v5.13
see

  linux commit 321827477360934dc040e9d3c626bf1de6c3ab3c
  icmp: don't send out ICMP messages with a source address of 0.0.0.0

"RFC7600 reserves a dummy address to be used as a source for ICMP
messages (192.0.0.8/32), so let's teach the kernel to substitute that
address as a last resort if the regular source address selection procedure
fails."
2022-03-08 17:21:26 -05:00
Szabolcs Nagy
1ee8109ea0 netinet/tcp.h: add tcp_zerocopy_receive fields from linux v5.12
see

  linux commit 7eeba1706eba6def15f6cb2fc7b3c3b9a2651edc
  tcp: Add receive timestamp support for receive zerocopy.

  linux commit 3c5a2fd042d0bfac71a2dfb99515723d318df47b
  tcp: Sanitize CMSG flags and reserved args in tcp_zerocopy_receive.
2022-03-08 17:19:56 -05:00
Szabolcs Nagy
bc89c31112 netinet/tcp.h: add TCP_NLA_* values up to linux v5.12
TCP_NLA_EDT was new in v5.9, see

  linux commit 48040793fa6003d211f021c6ad273477bcd90d91
  tcp: add earliest departure time to SCM_TIMESTAMPING_OPT_STATS

TCP_NLA_TTL is new in v5.12, see

  linux commit e7ed11ee945438b737e2ae2370e35591e16ec371
  tcp: add TTL to SCM_TIMESTAMPING_OPT_STATS
2022-03-08 17:19:54 -05:00
Szabolcs Nagy
e99c425827 signal.h: add new sa_flags from linux v5.11
see

  linux commit a54f0dfda754c5cecc89a14dab68a3edc1e497b5
  signal: define the SA_UNSUPPORTED bit in sa_flags

  linux commit 6ac05e832a9e96f9b1c42a8917cdd317d7b6c8fa
  signal: define the SA_EXPOSE_TAGBITS bit in sa_flags

Note: SA_ is in the posix reserved namespace so these linux specific flags
can be exposed when compiling for posix.
2022-03-08 17:19:49 -05:00
Szabolcs Nagy
993cccce13 signal.h: add SYS_USER_DISPATCH si_code value from linux v5.11
see

  linux commit 1d7637d89cfce54a4f4a41c2325288c2f47470e8
  signal: Expose SYS_USER_DISPATCH si_code type
2022-03-08 17:19:48 -05:00
Szabolcs Nagy
3dcbd89690 signal.h: add si_code values for SIGSYS
unlike other si_code defines, SYS_ is not in the posix reserved namespace
which is likely the reason why SYS_SECCOMP was previously missing (was new
in linux v3.5).
2022-03-08 17:19:46 -05:00
Szabolcs Nagy
30c8a1456a netinet/tcp.h: add tcp zerocopy related changes from linux v5.11
see

  linux commit 18fb76ed53865c1b5d5f0157b1b825704590beb5
  net-zerocopy: Copy straggler unaligned data for TCP Rx. zerocopy.

  linux commit 94ab9eb9b234ddf23af04a4bc7e8db68e67b8778
  net-zerocopy: Defer vm zap unless actually needed.
2022-03-08 17:19:44 -05:00
Szabolcs Nagy
b54f481fbc netinet/if_ether.h: add ETH_P_CFM from linux v5.11
see

  linux commit fbaedb4129838252570410c65abb2036b5505cbd
  bridge: uapi: cfm: Added EtherType used by the CFM protocol.
2022-03-08 17:19:43 -05:00
Szabolcs Nagy
c5ecaca743 sys/socket.h: add new SO_ socket options from linux v5.11
see

  linux commit 7fd3253a7de6a317a0683f83739479fb880bffc8
  net: Introduce preferred busy-polling

  linux commit 7c951cafc0cb2e575f1d58677b95ac387ac0a5bd
  net: Add SO_BUSY_POLL_BUDGET socket option
2022-03-08 17:19:40 -05:00
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