Commit Graph

270 Commits

Author SHA1 Message Date
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
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
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 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
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 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 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 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 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 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 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 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
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 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
Szabolcs Nagy db8b53f207 sys/mman.h: add new hugetlb mmap flags from linux v4.19
aarch64 supports 32MB and 512MB hugetlb page sizes too.
added in linux commit 20916d4636a9b3c1bf562b305f91d126771edaf9
2019-03-13 12:32:14 -04:00
Szabolcs Nagy df4b017bcd sys/inotify.h: add IN_MASK_CREATE from linux v4.19
inotify_add_watch flag to prevent modifying existing watch descriptors,
when used on an already watched inode it fails with EEXIST.
added in linux commit 4d97f7d53da7dc830dbf416a3d2a6778d267ae68
2019-03-13 12:29:27 -04:00
Szabolcs Nagy 31b3efbf3e sys/socket.h: add SO_TXTIME from linux v4.19
added in linux commit 80b14dee2bea128928537d61c333f24cb8cbb62f
2019-03-13 12:29:23 -04:00
Rich Felker ba18c1ecc6 add membarrier syscall wrapper, refactor dynamic tls install to use it
the motivation for this change is twofold. first, it gets the fallback
logic out of the dynamic linker, improving code readability and
organization. second, it provides application code that wants to use
the membarrier syscall, which depends on preregistration of intent
before the process becomes multithreaded unless unbounded latency is
acceptable, with a symbol that, when linked, ensures that this
registration happens.
2019-02-22 03:25:39 -05:00
Bobby Bingham 1dd915c370 update line discipline constants 2019-02-07 12:43:22 -05:00
Bobby Bingham 3517d74a5e move arch-invariant definitions out of bits/ioctl.h 2019-02-07 12:43:19 -05:00
Szabolcs Nagy a71276e258 add SIGSYS support to sys/signalfd.h from linux v4.18
new in linux commit 76b7f670730e87974f71df9f6129811e2769666e

in struct signalfd_siginfo the pad member is changed to __pad to keep
the namespace clean, it's not part of the public api.
2018-12-09 22:25:21 -05:00
Szabolcs Nagy 0a9a5c20c7 add AF_XDP to sys/socket.h from linux v4.18
new address family and related macros were added in linux commit
68e8b849b221b37a78a110a0307717d45e3593a0
2018-12-09 22:24:12 -05:00
midipix f2c6dbe244 move inclusion of linux headers for kd.h, soundcard.h, vt.h to bits
maintainer's note: while musl does not use the linux kernel headers,
it does provide these three sys/* headers which do nothing but include
the corresponding linux/* headers, since the sys/* versions are the
ones documented for application use (and they arguably provide
interfaces that are not linux-specific but common to other unices).
these headers should probably not be provided by libc (rather by a
separate package), but as long as they are, use the bits header
framework as an aid to out-of-tree ports of musl for non-linux systems
that want to implement them in some other way.
2018-07-20 01:06:41 -04:00
midipix 2fab90a71a remove inclusion guard hacks for sys/kd.h
maintainer's note: at some point, probably long before linux separated
the uapi headers, it was the case, or at least I believed it was the
case, that linux/types.h was unsafe to include from userspace. thus,
the inclusion guard macro _LINUX_TYPES_H was defined in sys/kd.h to
prevent linux/kd.h from including linux/types.h (which it spuriously
includes but does not use). as far as I can tell, whatever problem
this was meant to solve does not seem to have been present for a long
time, and the hack was not done correctly anyway, so removing it is
the right thing to do.
2018-07-20 01:06:03 -04:00
Szabolcs Nagy df6d9450ea add support for arch-specific ptrace command macros
sys/ptrace.h is target specific, use bits/ptrace.h to add target
specific macro definitions.

these macros are kept in the generic sys/ptrace.h even though some
targets don't support them:

PTRACE_GETREGS
PTRACE_SETREGS
PTRACE_GETFPREGS
PTRACE_SETFPREGS
PTRACE_GETFPXREGS
PTRACE_SETFPXREGS

so no macro definition got removed in this patch on any target. only
s390x has a numerically conflicting macro definition (PTRACE_SINGLEBLOCK).

the PT_ aliases follow glibc headers, otherwise the definitions come
from linux uapi headers except ones that are skipped in glibc and
there is no real kernel support (s390x PTRACE_*_AREA) or need special
type definitions (mips PTRACE_*_WATCH_*) or only relevant for linux
2.4 compatibility (PTRACE_OLDSETOPTIONS).
2018-07-17 22:25:08 -04:00
Szabolcs Nagy 7ea32a8282 sys/ptrace.h: add missing PTRACE_EVENT_STOP
new in linux v3.1 commit 3544d72a0e10d0aa1c1bd59ed77a53a59cdc12f7
changed in linux v3.4 commit 5cdf389aee90109e2e3d88085dea4dd5508a3be7

A tracer recieves this event in the waitpid status of a PTRACED_SEIZED
process.
2018-07-17 22:24:15 -04:00
Rich Felker 062015204a add ST_RELATIME to statvfs.h 2018-07-12 20:41:30 -04:00
Rich Felker 587f5a53bc fix value of SO_PEERSEC on mips archs
adapted from patch by Matthias Schiffer.
2018-06-26 15:55:29 -04:00
Szabolcs Nagy 38f2fa3d02 add memfd_create syscall wrapper
memfd_create was added in linux v3.17 and glibc has api for it.
2018-06-20 21:36:04 -04:00
Szabolcs Nagy b64d66d0b0 add mlock2 linux syscall wrapper
mlock2 syscall was added in linux v4.4 and glibc has api for it.
It falls back to mlock in case of flags==0, so that case works
even on older kernels.

MLOCK_ONFAULT is moved under _GNU_SOURCE following glibc.
2018-06-20 21:35:45 -04:00
Szabolcs Nagy da9f2b2ac8 add speculation control prctls from linux v4.17
PR_{SET,GET}_SPECULATION_CTRL controls speculation related vulnerability
mitigations, new in commits
b617cfc858161140d69cc0b5cc211996b557a1c7
356e4bfff2c5489e016fdb925adbf12a1e3950ee
2018-06-19 13:27:08 -04:00
Szabolcs Nagy af55070eae add {MSG,SEM,SHM}_STAT_ANY from linux v4.17
introduced to stat ipc objects without permission checks since the
info is available in /proc/sysvipc anyway, new in linux commits
23c8cec8cf679b10997a512abb1e86f0cedc42ba
a280d6dc77eb6002f269d58cd47c7c7e69b617b6
c21a6970ae727839a2f300cd8dd957de0d0238c3
2018-06-19 13:26:24 -04:00
Szabolcs Nagy 156a3bedb2 add MAP_FIXED_NOREPLACE from linux v4.17
to map at a fixed address without unmapping underlying mappings
(fails with EEXIST unlike MAP_FIXED), new in linux commits
4ed28639519c7bad5f518e70b3284c6e0763e650 and
a4ff8e8620d3f4f50ac4b41e8067b7d395056843.
2018-06-19 13:26:00 -04:00
Szabolcs Nagy 0f7aa600f7 sys/ptrace.h: add PTRACE_SECCOMP_GET_METADATA from linux v4.16
to get seccomp state for checkpoint restore.
added in linux commit 26500475ac1b499d8636ff281311d633909f5d20

struct tag follows the glibc api and ptrace_peeksiginfo_args
got changed too accordingly.
2018-06-19 13:25:33 -04:00
Szabolcs Nagy 29f3202b73 sys/epoll.h: add EPOLLNVAL from linux v4.16
added to uapi in commit 65aaf87b3aa2d049c6b9fd85221858a895df3393
used since commit a9a08845e9acbd224e4ee466f5c1275ed50054e8,
which renamed POLL* to EPOLL* in the kernel.
2018-06-19 13:25:16 -04:00
Hauke Mehrtens e206582091 add getrandom syscall wrapper
This syscall is available since Linux 3.17 and was also implemented in
glibc in version 2.25 using the same interfaces.
2018-02-22 19:34:58 -05:00
Szabolcs Nagy 121d18d2f2 sys/prctl.h: add new PR_SVE_* macros from linux v4.15
PR_SVE_SET_VL and PR_SVE_GET_VL controls are new in linux commit
2d2123bc7c7f843aa9db87720de159a049839862
related PR_SVE_* macros were added in
7582e22038a266444eb87bc07c372592ad647439
2018-02-22 18:49:34 -05:00
Szabolcs Nagy 9b57db3f95 add MAP_SYNC and MAP_SHARED_VALIDATE from linux v4.15
for synchronous page faults, new in linux commit
1c9725974074a047f6080eecc62c50a8e840d050 and
b6fb293f2497a9841d94f6b57bd2bb2cd222da43
note that only targets that use asm-generic/mman.h have this new
flag defined, so undef it on other targets (mips*, powerpc*).
2018-02-22 18:48:58 -05:00
Szabolcs Nagy abdaba8616 sys/{mman,shm}.h: add {MAP,SHM}_HUGE_ macros from linux uapi
*_HUGE_SHIFT, *_HUGE_2MB, *_HUGE_1GB are documented in the man page,
so add all of the *_HUGE_* macros from linux uapi.

if MAP_HUGETLB is set, top bits of the mmap flags encode the page size.
see the linux commit aafd4562dfee81a40ba21b5ea3cf5e06664bc7f6

if SHM_HUGETLB is set, top bits of the shmget flags encode the page size.
see the linux commit 4da243ac1cf6aeb30b7c555d56208982d66d6d33

*_HUGE_16GB is defined unsigned to avoid signed left shift ub.
2018-02-22 18:48:12 -05:00
Szabolcs Nagy 5431c20040 sys/mman.h: add MADV_WIPEONFORK from linux v4.14
allows zeroing anonymous private pages inherited by a child process.
new in linux commit d2cd9ede6e193dd7d88b6d27399e96229a551b19
2018-02-22 18:45:31 -05:00