]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
2 years agolinux(4): Regen for rseq syscall.
Dmitry Chagin [Fri, 17 Jun 2022 19:34:03 +0000 (22:34 +0300)]
linux(4): Regen for rseq syscall.

(cherry picked from commit 75e409495f67a39114e09224b8915cb0ecc481c4)

2 years agolinux(4): Change rseq syscall definition to match Linux actual one.
Dmitry Chagin [Tue, 26 Apr 2022 16:35:54 +0000 (19:35 +0300)]
linux(4): Change rseq syscall definition to match Linux actual one.

MFC after: 2 weeks

(cherry picked from commit f202f35db00cb9908b143a5a67f58ee95310f419)

2 years agoFix build after 128b9bf9
Dmitry Chagin [Mon, 25 Apr 2022 11:45:05 +0000 (14:45 +0300)]
Fix build after 128b9bf9

MFC after: 2 weeks

(cherry picked from commit 0ced2aef06760bfc57248482045c997be718b207)

2 years agoAdd tests for sigwait family syscalls.
Dmitry Chagin [Fri, 17 Jun 2022 19:33:56 +0000 (22:33 +0300)]
Add tests for sigwait family syscalls.

MFC after:              2 weeks

(cherry picked from commit 128b9bf96cae36c33b45a4d418ff502497bbb834)

2 years agosigtimedwait: Prevent timeout math overflows.
Dmitry Chagin [Mon, 25 Apr 2022 07:23:15 +0000 (10:23 +0300)]
sigtimedwait: Prevent timeout math overflows.

Our kern_sigtimedwait() calculates absolute sleep timo value as 'uptime+timeout'.
So, when the user specifies a big timeout value (LONG_MAX), the calculated
timo can be less the the current uptime value.
In that case kern_sigtimedwait() returns EAGAIN instead of EINTR, if
unblocked signal was caught.

While here switch to a high-precision sleep method.

Reviewed by: mav, kib
In collaboration with: mav
Differential revision: https://reviews.freebsd.org/D34981
MFC after: 2 weeks

(cherry picked from commit 4a700f3c329a48f3a20fd576900820e293c8cad7)

2 years agolinux(4): Refactor signal send methods.
Dmitry Chagin [Mon, 25 Apr 2022 07:22:51 +0000 (10:22 +0300)]
linux(4): Refactor signal send methods.

Created a couple of helpers to send signals to the specific thread or to
the whole process. Use helpers in the corresponding syscalls.
This fixes the confusion where a signal destined for a whole process
was sent to a specific thread and vice versa.
There is an exclusion for the linux_kill() syscall that takes a pid
argument and should send a signal to the whole process, but I know
at least one example where kill() takes tid.

MFC after: 2 weeks

(cherry picked from commit 6201a50d0d6d98633dba3db12dea2dfe95295e0e)

2 years agolinux(4): Check that the thread tid in the thread group pid in linux_tdfind().
Dmitry Chagin [Mon, 25 Apr 2022 07:21:51 +0000 (10:21 +0300)]
linux(4): Check that the thread tid in the thread group pid in linux_tdfind().

MFC after: 2 weeks

(cherry picked from commit fe894a370556e5b173a8893cdcde6323ff79cc57)

2 years agolinux(4): Microoptimize bsd_to_linux_sockaddr().
Dmitry Chagin [Mon, 25 Apr 2022 07:21:20 +0000 (10:21 +0300)]
linux(4): Microoptimize bsd_to_linux_sockaddr().

Differential Revision: https://reviews.freebsd.org/D34725
MFC after: 2 weeks

(cherry picked from commit bbddd5881d1826a366d09d1e156ec6b64d3715e5)

2 years agoAdd timespecvalid_interval macro and use it.
Dmitry Chagin [Mon, 25 Apr 2022 07:20:54 +0000 (10:20 +0300)]
Add timespecvalid_interval macro and use it.

Reviewed by: jhb, imp (early rev)
Differential revision: https://reviews.freebsd.org/D34848
MFC after: 2 weeks

(cherry picked from commit 91e7bdcdcf10684098e213e311cdafcd7a0ac983)

2 years agoFix sigtimedwait manpage.
Dmitry Chagin [Thu, 21 Apr 2022 07:52:29 +0000 (10:52 +0300)]
Fix sigtimedwait manpage.

Historically, sigtimedwait() blocks indefinitely if timeout is NULL.

Reviewed by: jilles, imp
Differential Revision: https://reviews.freebsd.org/D34985
MFC after: 2 weeks

(cherry picked from commit 89ecdff2c32c4e8975f8652c5cb913eba8642204)

2 years agoBump Dd in getdirentries.2 after c6487446.
Dmitry Chagin [Wed, 20 Apr 2022 14:55:32 +0000 (17:55 +0300)]
Bump Dd in getdirentries.2 after c6487446.

MFC after: 1 week

(cherry picked from commit 45a4c442996edafbe49caecb33a6e1226ab51a8e)

2 years agolinux(4): Copyout actual size of addr to the user space in accept().
Dmitry Chagin [Mon, 11 Apr 2022 20:33:27 +0000 (23:33 +0300)]
linux(4): Copyout actual size of addr to the user space in accept().

Differential Revision: https://reviews.freebsd.org/D34727

(cherry picked from commit 673bce11cedde3cc33c154d2b8e2d41139dcef72)

2 years agolinux(4): Limit user-supplied sockaddr length in recvfrom().
Dmitry Chagin [Mon, 11 Apr 2022 20:32:28 +0000 (23:32 +0300)]
linux(4): Limit user-supplied sockaddr length in recvfrom().

Differential Revision: https://reviews.freebsd.org/D34726

(cherry picked from commit bb0f644cd680d20b3112f6c14dc853171f497a88)

2 years agolinux(4): Remove unnecessary PTRIN().
Dmitry Chagin [Mon, 11 Apr 2022 20:32:02 +0000 (23:32 +0300)]
linux(4): Remove unnecessary PTRIN().

(cherry picked from commit 68bfaefb3d93781730ebc63956538154173b77c8)

2 years agolinux(4): Handle SO_DOMAIN in getsockopt syscall.
Dmitry Chagin [Mon, 11 Apr 2022 20:31:28 +0000 (23:31 +0300)]
linux(4): Handle SO_DOMAIN in getsockopt syscall.

Differential revision: https://reviews.freebsd.org/D34714

(cherry picked from commit cf312f799a867b4b1beef0536a162062659659a6)

2 years agogetdirentries: return ENOENT for unlinked but still open directory.
Dmitry Chagin [Fri, 17 Jun 2022 19:33:51 +0000 (22:33 +0300)]
getdirentries: return ENOENT for unlinked but still open directory.

To be more compatible to IEEE Std 1003.1-2008 (“POSIX.1”).

Reviewed by:            mjg, Pau Amma (doc)
Differential revision:  https://reviews.freebsd.org/D34680
MFC after:              2 weeks

(cherry picked from commit c6487446d7e99537551d2e51a2f6c6569fcb89fc)

2 years agolinux(4): Prevent an attempt to copy an uninitialized source address.
Dmitry Chagin [Mon, 11 Apr 2022 20:29:45 +0000 (23:29 +0300)]
linux(4): Prevent an attempt to copy an uninitialized source address.

PR: 259380
MFC after: 3 days

(cherry picked from commit bb46e9b5107fd8763742f7e55b66ea2e574f5815)

2 years ago[linprocfs] add sys/kernel/random/boot_id
Fernando Apesteguía [Tue, 8 Mar 2022 14:19:53 +0000 (15:19 +0100)]
[linprocfs] add sys/kernel/random/boot_id

This file holds a UUID that is invariant for every boot. In our case, it is
invariant per mount.

PR: 262369
Reported by: sodynet1@gmail.com
Approved by: dchagin@
Differential Revision: https://reviews.freebsd.org/D34860

(cherry picked from commit 0f2041a5b03259a8a7b20ffc98e34884cc5590b3)

2 years agoi386 linux: Remove unused variables.
John Baldwin [Sat, 9 Apr 2022 00:25:14 +0000 (17:25 -0700)]
i386 linux: Remove unused variables.

(cherry picked from commit 9e70163017ff929a36926ddbc5bd6e8b6b19cfeb)

2 years agolinux(4): Fix a typo in itimerspec conversion routine.
Dmitry Chagin [Wed, 6 Apr 2022 14:40:00 +0000 (17:40 +0300)]
linux(4): Fix a typo in itimerspec conversion routine.

MFC after: 3 days

(cherry picked from commit 0938d04a2c513122127c4a1552542ab617f567a8)

2 years agolinsysfs: plug set-but-not-used vars.
Dmitry Chagin [Thu, 31 Mar 2022 20:49:26 +0000 (23:49 +0300)]
linsysfs: plug set-but-not-used vars.

MFC after: 2 weeks

(cherry picked from commit bafe3b8804ca1450584191ae8689c1c0abeea68d)

2 years agolinux(4): Cleanup empty lines.
Dmitry Chagin [Thu, 31 Mar 2022 18:23:12 +0000 (21:23 +0300)]
linux(4): Cleanup empty lines.

MFC after: 2 weeks

(cherry picked from commit 09d60bfae58f10a24c8fc7c06bd3d90b86d40e07)

2 years agolinux(4): Fix KASSERT message.
Dmitry Chagin [Thu, 31 Mar 2022 18:22:31 +0000 (21:22 +0300)]
linux(4): Fix KASSERT message.

MFC after: 2 weeks

(cherry picked from commit 4e1e83461bdc9b8c3ab96dc82e7342d4ea1e69b9)

2 years agolinux(4): readlink should fail if bufzis <= 0.
Dmitry Chagin [Thu, 31 Mar 2022 18:21:41 +0000 (21:21 +0300)]
linux(4): readlink should fail if bufzis <= 0.

MFC after: 2 weeks

(cherry picked from commit d6ccce0aa267db8ee57736e944520e2967896340)

2 years agolinprocfs: Add /proc/self/oom_score_adj.
Dmitry Chagin [Thu, 31 Mar 2022 18:04:44 +0000 (21:04 +0300)]
linprocfs: Add /proc/self/oom_score_adj.

To avoid annoyng messages from LTP test suites add the simple
implementation of /proc/self/oom_score_adj which is do nothing.

Reviewed by: emaste
Differential revision:  https://reviews.freebsd.org/D34710
MFC after: 2 weeks

(cherry picked from commit b7df7b987e8fac05006aa5f132c424e2b2bcf156)

2 years agolinux(4): Add compat.linux32.emulate_i386 knob.
Dmitry Chagin [Thu, 31 Mar 2022 18:01:09 +0000 (21:01 +0300)]
linux(4): Add compat.linux32.emulate_i386 knob.

Historically 32-bit Linuxulator under amd64 emulated the real i386
behavior. Since 3d8dd983 the old i386 Linux world can't be used under
amd64 Linuxulator as it don't know anything about amd64 machine (which
is returned now by newuname() syscall). So, add a knob to allow to swith
the behavior and use i386 Linux binaries on amd64.
Set knob to the new behavior as I think this is common to the modern
Linux distros.

Reviewed by: Pau Amma (doc), emaste
Differential revision: https://reviews.freebsd.org/D34708
MFC after: 2 weeks

(cherry picked from commit d5dc757e84d8dc1db987f3a17052e32621d6ea87)

2 years agolinux(4): Fixup miscalculation of d_off of struct dirent in getdents() syscalls.
Dmitry Chagin [Thu, 31 Mar 2022 17:50:09 +0000 (20:50 +0300)]
linux(4): Fixup miscalculation of d_off of struct dirent in getdents() syscalls.

Avoid calculating d_off value as it is specific to the underlying filesystem
and can be used by others API, like lseek(), seekdir() as input offset.

Differential revision:  https://reviews.freebsd.org/D31551
MFC after: 2 weeks

(cherry picked from commit 099fa2feb36fe6a68a87dfdb0f290b882139a88d)

2 years agolinux(4): wait4() returns ESRCH if pid is INT_MIN.
Dmitry Chagin [Thu, 31 Mar 2022 17:49:39 +0000 (20:49 +0300)]
linux(4): wait4() returns ESRCH if pid is INT_MIN.

Weird and undocumented patch was added to the Linux kernel in 2017,
fixes wait403 LTP test.

MFC after: 2 weeks

(cherry picked from commit 9103c5582a2d271fa8f4df136ae511da572c660f)

2 years agolinux(4): Rid unused defines from linux_mib.
Dmitry Chagin [Thu, 31 Mar 2022 17:45:12 +0000 (20:45 +0300)]
linux(4): Rid unused defines from linux_mib.

Reviewed by: trasz
Differential revision:  https://reviews.freebsd.org/D31591
MFC after: 2 weeks

(cherry picked from commit 5bcf0f7cd7441a1f88383545fec6c370b934f1a1)

2 years agolinux(4): Fixup waitid handling P_PGID idtype.
Dmitry Chagin [Thu, 31 Mar 2022 17:44:00 +0000 (20:44 +0300)]
linux(4): Fixup waitid handling P_PGID idtype.

Since Linux 5.4, if id is zero, then wait for any child that is in the same
process grop as the caller's process group.

Differential revision:  https://reviews.freebsd.org/D31567
MFC after: 2 weeks

(cherry picked from commit 4e3aefb923ac1bd8e2a707b00239f171eab1231b)

2 years agolinux(4): Return ENOSYS for unsupported P_PIDFD waitid idtype.
Dmitry Chagin [Thu, 31 Mar 2022 17:42:42 +0000 (20:42 +0300)]
linux(4): Return ENOSYS for unsupported P_PIDFD waitid idtype.

Reviewed by: emaste
Differential revision:  https://reviews.freebsd.org/D31559
MFC after: 2 weeks

(cherry picked from commit be1e4a0bdf45da4bbdce996d2146eba3e32b3766)

2 years agolinux(4): Add support for __WALL wait option bit.
Dmitry Chagin [Thu, 31 Mar 2022 17:42:03 +0000 (20:42 +0300)]
linux(4): Add support for __WALL wait option bit.

As FreeBSD does not have __WALL option bit analogue explicitly set all
possible option bits to emulate Linux __WALL wait option bit.

Reviewed by: emaste
Differential revision:  https://reviews.freebsd.org/D31555
MFC after: 2 weeks

(cherry picked from commit c7ef7c3facaf663c3da2d91916bcb2f162fc300e)

2 years agolinux(4): Fixup options value validation in linux_waitid().
Dmitry Chagin [Thu, 31 Mar 2022 17:41:19 +0000 (20:41 +0300)]
linux(4): Fixup options value validation in linux_waitid().

Reviewed by: emaste
Differential revision:  https://reviews.freebsd.org/D31554
MFC after: 2 weeks

(cherry picked from commit d7e1e138ec66e410f525413b0caed089139f3cc0)

2 years agolinux(4): Eliminate bogus options value check validation.
Dmitry Chagin [Thu, 31 Mar 2022 17:41:02 +0000 (20:41 +0300)]
linux(4): Eliminate bogus options value check validation.

The kernel do it for us.

Reviewed by: emaste
Differential revision:  https://reviews.freebsd.org/D31553
MFC after: 2 weeks

(cherry picked from commit 2fd480b3182f52ebf23abdcacab04520224e90b7)

2 years agolinux(4): Consolidate wait* facility into linux_common_wait().
Dmitry Chagin [Thu, 31 Mar 2022 17:40:22 +0000 (20:40 +0300)]
linux(4): Consolidate wait* facility into linux_common_wait().

Also fix bug in waitid() implementation, use wru_self not wru_children.

Differential revision:  https://reviews.freebsd.org/D31552
MFC after: 2 weeks

(cherry picked from commit 0c6b1ff7de56ccaef9bb22bacfd69b07ab4aeb8a)

2 years agolinux: plug set-but-not-unused vars
Mateusz Guzik [Wed, 24 Nov 2021 21:16:03 +0000 (21:16 +0000)]
linux: plug set-but-not-unused vars

Sponsored by: Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 74a0e24f07974b4d51c57afa7525b5f88574ad31)

2 years agolinux(4): Add AT_NO_AUTOMOUNT to statx.
Dmitry Chagin [Fri, 25 Mar 2022 14:54:23 +0000 (17:54 +0300)]
linux(4): Add AT_NO_AUTOMOUNT to statx.

Specific to Linux AT_NO_AUTOMOUNT flag tells the kernel to not automount the
terminal component of pathname if it is a directory that is an automount point.
As it is the default for FreeBSD silencly ignore this flag.

glibc-2.34 uses this flag in the stat64 system calls which is used by i386.

Reviewed by: trasz
Differential revision:  https://reviews.freebsd.org/D31524
MFC after: 2 weeks

(cherry picked from commit ff39d74aa99a49749d1de26dc1f6b1e1bfebceb0)

2 years agolinprocfs: Eliminate bogus comment (KSE).
Dmitry Chagin [Fri, 25 Mar 2022 14:53:08 +0000 (17:53 +0300)]
linprocfs: Eliminate bogus comment (KSE).

Reviewed by: trasz, emaste
Differential revision: https://reviews.freebsd.org/D31525
MFC after: 2 weeks

(cherry picked from commit aae8ae5ea5a67feb83a30e7c09553ab416d6830a)

2 years agolinux_copyout_strings: Use PROC_PS_STRINGS().
John Baldwin [Fri, 4 Feb 2022 23:57:57 +0000 (15:57 -0800)]
linux_copyout_strings: Use PROC_PS_STRINGS().

Reviewed by: markj
Obtained from: CheriBSD
Differential Revision: https://reviews.freebsd.org/D34173

(cherry picked from commit 6bea696af25c606452515bc812c23b9f2614344a)

2 years agolinprocfs: plug set-but-not-unused vars
Mateusz Guzik [Wed, 24 Nov 2021 21:18:36 +0000 (21:18 +0000)]
linprocfs: plug set-but-not-unused vars

Sponsored by: Rubicon Communications, LLC ("Netgate")

(cherry picked from commit ae3d955404dac5c22fdbbc9bd1a3583b4c7d8637)

2 years agopseudofs: Destroy vncache hashtbl on pseudofs module unload.
Dmitry Chagin [Thu, 9 Dec 2021 21:41:08 +0000 (21:41 +0000)]
pseudofs: Destroy vncache hashtbl on pseudofs module unload.

Reviewed by: mjg, kib
Differential Revision: https://reviews.freebsd.org/D31605
MFC after: 2 weeks

(cherry picked from commit 0f74021fb6a5c3fb6e031892cc159b1e7e325bd6)

2 years agolinux(4): Improve comment.
Dmitry Chagin [Fri, 13 Aug 2021 08:36:42 +0000 (11:36 +0300)]
linux(4): Improve comment.

Reported by: pfg
MFC after: 2 weeks

(cherry picked from commit d4da692862f195b8e98cbaeadbd97eb003cda92a)

2 years agolinux(4): Reduce diffs between linux_rt_sendsig() and sendsig()
Edward Tomasz Napierala [Tue, 4 Jan 2022 14:13:03 +0000 (14:13 +0000)]
linux(4): Reduce diffs between linux_rt_sendsig() and sendsig()

No functional changes (except for the uprintf).

Discussed With: kib
Sponsored By: EPSRC

(cherry picked from commit f7b04c53de46b18785a153d9812e64ca1a9a8c8d)

2 years agolinux: Provide dummy seccomp(2)
Edward Tomasz Napierala [Fri, 28 Jan 2022 10:55:11 +0000 (10:55 +0000)]
linux: Provide dummy seccomp(2)

Don't emit messages; this isn't any different from a Linux kernel
built without OPTIONS_SECCOMP, so the userspace already needs to know
how to deal with it.  This is also similar with how we handle seccomp
in linux_prctl().

Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D33808

(cherry picked from commit 99454d3e98ff205881aa7abef39234c9afc7600c)

2 years agolinux(4): Remove unused arm64 SDT declarations
Edward Tomasz Napierala [Tue, 21 Dec 2021 06:07:15 +0000 (06:07 +0000)]
linux(4): Remove unused arm64 SDT declarations

Those tracepoints have been removed somewhere in the past.

Sponsored By: EPSRC

(cherry picked from commit a15c591899663c30f2cbe13a4b350ad508b5e4bb)

2 years agolinux: plug set-but-not-used vars
Mateusz Guzik [Sat, 18 Dec 2021 13:12:15 +0000 (13:12 +0000)]
linux: plug set-but-not-used vars

Sponsored by: Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 0c8d7eebfdce5045bf3b8669ce954ca2cf553d9a)

2 years agolinux: remove the always curthread argument from lconvpath
Mateusz Guzik [Thu, 25 Nov 2021 21:42:13 +0000 (21:42 +0000)]
linux: remove the always curthread argument from lconvpath

(cherry picked from commit af4051d25055fee086c0f78421e68fec20640f17)

2 years agolinux_name_to_handle_at: Support AT_EMPTY_PATH.
John Baldwin [Wed, 17 Nov 2021 23:51:18 +0000 (15:51 -0800)]
linux_name_to_handle_at: Support AT_EMPTY_PATH.

Reviewed by: kib
Sponsored by: The University of Cambridge, Google Inc.
Differential Revision: https://reviews.freebsd.org/D33050

(cherry picked from commit 8b2ce7a3bbd0a754d31ff3943d918b4c84c831a3)

2 years agolinux_linkat: Don't invert AT_* flags.
John Baldwin [Wed, 17 Nov 2021 23:51:06 +0000 (15:51 -0800)]
linux_linkat: Don't invert AT_* flags.

Reviewed by: kib
Sponsored by: The University of Cambridge, Google Inc.
Differential Revision: https://reviews.freebsd.org/D33048

(cherry picked from commit a8d885296a9dc517e731723081c83d97d2aa598f)

2 years agolinux(4): Fix "set but not used" warnings
Edward Tomasz Napierala [Mon, 29 Nov 2021 16:44:40 +0000 (16:44 +0000)]
linux(4): Fix "set but not used" warnings

No functional changes.

Sponsored By: EPSRC

(cherry picked from commit a089c17d320684e6eb36556fa131a8286e6a821d)

2 years agolinux: Drop some unnecessary includes
Dmitry Chagin [Fri, 17 Jun 2022 19:33:38 +0000 (22:33 +0300)]
linux: Drop some unnecessary includes

Drop some unnecessary includes from Linuxulator ptrace
and coredump code.  No functional changes.

Sponsored By:   EPSRC
Differential Revision:  https://reviews.freebsd.org/D32925

(cherry picked from commit 06d5ef0aad20f703c15350663ce2600bae2fe189)

2 years agolinux: Replace ifdefs in ptrace with per-architecture callbacks
Edward Tomasz Napierala [Tue, 9 Nov 2021 11:54:06 +0000 (11:54 +0000)]
linux: Replace ifdefs in ptrace with per-architecture callbacks

It's a cleanup; no (intended) functional changes.

Sponsored By: EPSRC
Reviewed By: kib
Differential Revision: https://reviews.freebsd.org/D32888

(cherry picked from commit 0bf8d5d5f43426321940e351939b0b712f28b08f)

2 years agolinux: Add ptrace(2) support on arm64
Edward Tomasz Napierala [Sun, 7 Nov 2021 08:22:41 +0000 (08:22 +0000)]
linux: Add ptrace(2) support on arm64

This moves linux_ptrace.c from sys/amd64/linux/ to sys/compat/linux/,
making it possible to use it on architectures other than amd64.
It also enables Linux ptrace(2) on arm64.

Relnotes: yes
Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D32868

(cherry picked from commit a90ff3c4bc901947a040717f39d5b3b8778047fe)

2 years agolinux: Implement linux_to_bsd_regset() on arm64
Edward Tomasz Napierala [Sat, 6 Nov 2021 08:35:04 +0000 (08:35 +0000)]
linux: Implement linux_to_bsd_regset() on arm64

This will be used by ptrace.

Sponsored By: EPSRC

(cherry picked from commit 6f397bc0fbe378664bbbc7c2296043e3b9673e2a)

2 years agolinux: Fix another amd64-specific piece of linux_ptrace.c
Edward Tomasz Napierala [Sat, 6 Nov 2021 07:56:51 +0000 (07:56 +0000)]
linux: Fix another amd64-specific piece of linux_ptrace.c

This was missed in c91d0e59be1.  No functional changes.

Sponsored By: EPSRC

(cherry picked from commit 3be6e606d7870a79baa7a4c5947dffd333defa79)

2 years agolinux: Make linux_ptrace.c portable
Edward Tomasz Napierala [Wed, 3 Nov 2021 08:54:30 +0000 (08:54 +0000)]
linux: Make linux_ptrace.c portable

Make sys/amd64/linux/linux_ptrace.c machine-independent,
in preparation for moving it into sys/compat/linux/.
No functional changes.

Reviewed By: kib
Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D32756

(cherry picked from commit c91d0e59be10f9412cbce467b8b038f006bb6f18)

2 years agolinux: mv sys/i386/linux/linux_ptrace{,_machdep}.c
Edward Tomasz Napierala [Wed, 3 Nov 2021 08:49:41 +0000 (08:49 +0000)]
linux: mv sys/i386/linux/linux_ptrace{,_machdep}.c

In preparation for machine-independent sys/compat/linux/linux_ptrace.c,
rename the i386-specific Linux ptrace(2) implementation.  No functional
changes.

Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D32757

(cherry picked from commit 4dfd612286ec2ecc7a05f3d4fd65a58f4b05f74c)

2 years agolinux: make PTRACE_SETREGS use a correct struct
Edward Tomasz Napierala [Sat, 30 Oct 2021 09:13:32 +0000 (10:13 +0100)]
linux: make PTRACE_SETREGS use a correct struct

Note that this is largely untested at this point, as was
the previous version; I'm committing this mostly to get
rid of `struct linux_pt_reg`.

Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D32735

(cherry picked from commit f0d9a6a781f331440baf9a846e773e44a297d59c)

2 years agolinux: make PTRACE_GETREGS return correct struct
Edward Tomasz Napierala [Fri, 29 Oct 2021 15:18:13 +0000 (16:18 +0100)]
linux: make PTRACE_GETREGS return correct struct

Previously it returned a shorter struct.  I can't find any
modern software that uses it, but tests/ptrace from strace(1)
repo complained.

Differential Revision: https://reviews.freebsd.org/D32601

(cherry picked from commit ad0379660d0c77aaf0ca6ec19472b7bb173c5794)

2 years agolinux: Constify bsd_to_linux_regset()
Edward Tomasz Napierala [Sat, 23 Oct 2021 07:33:48 +0000 (08:33 +0100)]
linux: Constify bsd_to_linux_regset()

No functional changes.

Reviewed By: emaste
Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D32599

(cherry picked from commit 3417c29851b6fce32b4c459b4c0a197b2e33018b)

2 years agolinux(4): Remove clone3 and faccessat2 from dummy.
Dmitry Chagin [Thu, 12 Aug 2021 13:07:21 +0000 (16:07 +0300)]
linux(4): Remove clone3 and faccessat2 from dummy.

MFC after: 2 weeks

(cherry picked from commit aecd31a8a3b09af874120bc7b4aa6fa51db98f94)

2 years agolinux(4): Remove the unnecessary spaces.
Dmitry Chagin [Thu, 12 Aug 2021 08:58:33 +0000 (11:58 +0300)]
linux(4): Remove the unnecessary spaces.

MFC after: 2 weeks

(cherry picked from commit bed2ac27a14d39df713f004ea46cbe77fa853f86)

2 years agofork: Remove the unnecessary spaces.
Dmitry Chagin [Thu, 12 Aug 2021 08:58:17 +0000 (11:58 +0300)]
fork: Remove the unnecessary spaces.

MFC after: 2 weeks

(cherry picked from commit 71854d9b2b0953b624ffcb268f41b84c9370981b)

2 years agolinux(4): Move ff variable initialization from declaration.
Dmitry Chagin [Thu, 12 Aug 2021 08:57:16 +0000 (11:57 +0300)]
linux(4): Move ff variable initialization from declaration.

Modern style(9) allows variables initialization where they are declared,
but in this case initialization obfuscate the code.

MFC after: 2 weeks

(cherry picked from commit 1af0780b5f20aaa2603bba221ff78ca22dd44bd2)

2 years agolinux(4): Verify that higher 32bits of exit_signal in clone3 are unset.
Dmitry Chagin [Thu, 12 Aug 2021 08:56:51 +0000 (11:56 +0300)]
linux(4): Verify that higher 32bits of exit_signal in clone3 are unset.

MFC after: 2 weeks

(cherry picked from commit c2cc5345b88e98efb85ebc7318b8f92a8455345e)

2 years agolinux(4): Return ENOSYS for unsupported clone3 option bits.
Dmitry Chagin [Thu, 12 Aug 2021 08:56:36 +0000 (11:56 +0300)]
linux(4): Return ENOSYS for unsupported clone3 option bits.

Differential Revision: https://reviews.freebsd.org/D31483
MFC after: 2 weeks

(cherry picked from commit 4385147547d9f2f8b93f08012c0a18aa6d895403)

2 years agolinux(4): Add LINUX_RATELIMIT_MSG macro for future use.
Dmitry Chagin [Thu, 12 Aug 2021 08:55:55 +0000 (11:55 +0300)]
linux(4): Add LINUX_RATELIMIT_MSG macro for future use.

Differential Revision: https://reviews.freebsd.org/D31488
MFC after: 2 weeks

(cherry picked from commit 0d77f6c0c350ae41acc0653a236a76d981773021)

2 years agolinux(4): Implement CLONE_CLEAR_SIGHAND option bit.
Dmitry Chagin [Thu, 12 Aug 2021 08:55:35 +0000 (11:55 +0300)]
linux(4): Implement CLONE_CLEAR_SIGHAND option bit.

CLONE_CLEAR_SIGHAND is designed to reset all signal handlers of the child
not set to SIG_IGN to SIG_DFL.

Reviewed by: kib
Differential revision: https://reviews.freebsd.org/D31481
MFC after: 2 weeks

(cherry picked from commit c5fc9fe7f36a742e567173b2e3d65252140013d1)

2 years agolinux(4): Add CLONE_PIDFD option bit.
Dmitry Chagin [Thu, 12 Aug 2021 08:55:24 +0000 (11:55 +0300)]
linux(4): Add CLONE_PIDFD option bit.

Differential revision: https://reviews.freebsd.org/D31478
MFC after: 2 weeks

(cherry picked from commit a796845d6de083971eef2d2a33ccc74fcd609ec7)

2 years agolinux(4): Regen for clone3 system call.
Dmitry Chagin [Thu, 12 Aug 2021 08:50:22 +0000 (11:50 +0300)]
linux(4): Regen for clone3 system call.

MFC after: 2 weeks

(cherry picked from commit b356030e670686df1300edf851e146c5d274e4f8)

2 years agolinux(4): Implement clone3 system call.
Dmitry Chagin [Thu, 12 Aug 2021 08:49:36 +0000 (11:49 +0300)]
linux(4): Implement clone3 system call.

clone3 system call is used by glibc-2.34.

Differential revision: https://reviews.freebsd.org/D31475
MFC after: 2 weeks

(cherry picked from commit 17913b0b6b707568d63559255820f3212cd31cdf)

2 years agolinux(4): Add struct clone_args for future clone3 system call.
Dmitry Chagin [Thu, 12 Aug 2021 08:49:01 +0000 (11:49 +0300)]
linux(4): Add struct clone_args for future clone3 system call.

In preparation for clone3 system call add struct clone_args and use it in
clone implementation.
Move all of clone related bits to the newly created linux_fork.h header.

Differential revision: https://reviews.freebsd.org/D31474
MFC after: 2 weeks

(cherry picked from commit 0a4b664ae8582b7596858317b53d84eb4f8bbf9a)

2 years agolinux(4): Regen for clone syscall.
Dmitry Chagin [Thu, 12 Aug 2021 08:47:31 +0000 (11:47 +0300)]
linux(4): Regen for clone syscall.

MFC after: 2 weeks

(cherry picked from commit 0c08f34f4ddff9847bd57f262270687ea1220a6a)

2 years agolinux(4): Change clone syscall definition to match Linux actual one.
Dmitry Chagin [Thu, 12 Aug 2021 08:46:36 +0000 (11:46 +0300)]
linux(4): Change clone syscall definition to match Linux actual one.

Differential revision: https://reviews.freebsd.org/D31473
MFC after: 2 weeks

(cherry picked from commit f1c450492f81cda4bddd46dc71ea4c92907567ac)

2 years agofork: Allow ABI to specify fork return values for child.
Dmitry Chagin [Fri, 17 Jun 2022 19:33:28 +0000 (22:33 +0300)]
fork: Allow ABI to specify fork return values for child.

At least Linux x86 ABI's does not use carry bit and expects that the dx register
is preserved. For this add a new sv_set_fork_retval hook and call it from cpu_fork().

Add a short comment about touching dx in x86_set_fork_retval(), for more details
see phab comments from kib@ and imp@.

Reviewed by:            kib
Differential revision:  https://reviews.freebsd.org/D31472
MFC after:              2 weeks

(cherry picked from commit de8374df28cc23ce0d893fd96d1ad0a861414154)

2 years agolinux(4): Plug in aarch64 fcntl flags.
Dmitry Chagin [Thu, 12 Aug 2021 08:42:50 +0000 (11:42 +0300)]
linux(4): Plug in aarch64 fcntl flags.

Fixes opendir() libc function.

Differential Revision: https://reviews.freebsd.org/D31357
MFC after: 2 weeks

(cherry picked from commit fc37be246021ee9b7110c9f506141c2bf0bc9fb0)

2 years agolinux(4): Regen for faccessat2 system call.
Dmitry Chagin [Thu, 12 Aug 2021 08:41:35 +0000 (11:41 +0300)]
linux(4): Regen for faccessat2 system call.

MFC after: 2 weeks

(cherry picked from commit bee191e46fc261b64fcaf440952d74a94cf4a273)

2 years agolinux(4): Implement faccessat2 system call.
Dmitry Chagin [Thu, 12 Aug 2021 08:40:42 +0000 (11:40 +0300)]
linux(4): Implement faccessat2 system call.

It's used by bash on arm64 with glibc-2.32.

Reviewed by: trasz
Differential Revision: https://reviews.freebsd.org/D31345
MFC after: 2 weeks

(cherry picked from commit 13d79be9950dd820628906dcad4f4f1365b307b9)

2 years agolinux(4): Fix futex copyrights.
Dmitry Chagin [Thu, 12 Aug 2021 08:36:24 +0000 (11:36 +0300)]
linux(4): Fix futex copyrights.

As no more NetBSD code in futexes exists replace NetBSD copyrights by
standard FreeBSD 2 clause license.
Add Roman Divacky's copyrights as an author of the robust futexes.

Differential revision: https://reviews.freebsd.org/D31347
MFC after: 2 weeks

(cherry picked from commit 6e31bed646c2f67cbcfd4bb2ce38aadd15868dcc)

2 years agolinux(4): Eliminate a now unused includes after futexes refactoring.
Dmitry Chagin [Thu, 29 Jul 2021 09:56:39 +0000 (12:56 +0300)]
linux(4): Eliminate a now unused includes after futexes refactoring.

MFC after: 2 weeks

(cherry picked from commit 2411ac0b89f3a33aca93c62b53bd48deee123766)

2 years agolinux(4): Add a comment about wait/requeue pi operations.
Dmitry Chagin [Thu, 29 Jul 2021 09:55:59 +0000 (12:55 +0300)]
linux(4): Add a comment about wait/requeue pi operations.

MFC after: 2 weeks

(cherry picked from commit d90df8ac1324d731f8423b5501158ee870fbd5ba)

2 years agolinux(4): Handle incorrect FUTEX_CLOCK_REALTIME option bit.
Dmitry Chagin [Thu, 29 Jul 2021 09:55:33 +0000 (12:55 +0300)]
linux(4): Handle incorrect FUTEX_CLOCK_REALTIME option bit.

Return ENOSYS if the FUTEX_CLOCK_REALTIME option bit is specified for an
inappropriate futex operation.

MFC after: 2 weeks

(cherry picked from commit 626cbd4648141929502b953111dc8a71d550c7e8)

2 years agolinux(4): Handle FUTEX_LOCK_PI2 oeration.
Dmitry Chagin [Thu, 29 Jul 2021 09:55:02 +0000 (12:55 +0300)]
linux(4): Handle FUTEX_LOCK_PI2 oeration.

FUTEX_LOCK_PI2 was added to support clock selection as FUTEX_LOCK_PI uses a
CLOCK_REALTIME based absolute value since it was implemented, but it does not
require that the FUTEX_CLOCK_REALTIME bit is set, because that was introduced
later.

MFC after: 2 weeks

(cherry picked from commit a9bb1b1c188339ed7658103ff5843c161df08799)

2 years agolinux(4): Use variable name not type for sizeof() to calculate storage size.
Dmitry Chagin [Thu, 29 Jul 2021 09:54:32 +0000 (12:54 +0300)]
linux(4): Use variable name not type for sizeof() to calculate storage size.

MFC after: 2 weeks

(cherry picked from commit bd25bf092ae92f5a46eed51a3152c9af4cb0f7b3)

2 years agolinux(4): Move len variable initialization to the appropriate place.
Dmitry Chagin [Thu, 29 Jul 2021 09:54:16 +0000 (12:54 +0300)]
linux(4): Move len variable initialization to the appropriate place.

MFC after: 2 weeks

(cherry picked from commit 49a5c0409bf15fc00bbe363fe7090d7b7c601985)

2 years agolinux(4): Use linux_tdfind() in get_robust_list.
Dmitry Chagin [Thu, 29 Jul 2021 09:53:59 +0000 (12:53 +0300)]
linux(4): Use linux_tdfind() in get_robust_list.

In the Linux emulation layer linux_tdfind() has a special purpose to
handle glibc specific TID mangling and we should use it instead of tdfind().

MFC after: 2 weeks

(cherry picked from commit c8e9d2b7eb6ef55e1386150458c58e6554762166)

2 years agolinux(4): Eliminate unnecessary error initialization.
Dmitry Chagin [Thu, 29 Jul 2021 09:53:41 +0000 (12:53 +0300)]
linux(4): Eliminate unnecessary error initialization.

MFC after: 2 weeks

(cherry picked from commit f88d3c522f743c0d948048de3c36f9bb9e0ca171)

2 years agolinux(4): Eliminate unnecessary head initialization.
Dmitry Chagin [Thu, 29 Jul 2021 09:53:25 +0000 (12:53 +0300)]
linux(4): Eliminate unnecessary head initialization.

MFC after: 2 weeks

(cherry picked from commit 6b68e8af1f8770bdc7aff66e1ae616efd9c9da46)

2 years agolinux(4): style, wrap too long line.
Dmitry Chagin [Thu, 29 Jul 2021 09:53:07 +0000 (12:53 +0300)]
linux(4): style, wrap too long line.

MFC after: 2 weeks

(cherry picked from commit 971b53fa04f96199889f6dd6a078d054772bc7c9)

2 years agolinux(4): Eliminating remnants of futex sdt.
Dmitry Chagin [Thu, 29 Jul 2021 09:52:36 +0000 (12:52 +0300)]
linux(4): Eliminating remnants of futex sdt.

MFC after: 2 weeks

(cherry picked from commit edd44176aa0e1acdb3a97746c6fe595d12be0c45)

2 years agolinux(4): Eliminating an accidental comment.
Dmitry Chagin [Thu, 29 Jul 2021 09:51:56 +0000 (12:51 +0300)]
linux(4): Eliminating an accidental comment.

MFC after: 2 weeks

(cherry picked from commit 741f80df531cb58a38a8ec98203c7e315b6f9bca)

2 years agolinux(4): Handle special case for regular futex in handle_futex_death().
Dmitry Chagin [Thu, 29 Jul 2021 09:51:39 +0000 (12:51 +0300)]
linux(4): Handle special case for regular futex in handle_futex_death().

Handle some races in handle_futex_death() which can prevents a wakeup of
potential waiters which can cause these waiters to block forever.

Differential Revision: https://reviews.freebsd.org/D31280
MFC after: 2 weeks

(cherry picked from commit b59cf25eac06c1feb2d35a5a3d8a089ae62fd0df)

2 years agolinux(4): Futex address must be 32-bit aligned.
Dmitry Chagin [Thu, 29 Jul 2021 09:50:58 +0000 (12:50 +0300)]
linux(4): Futex address must be 32-bit aligned.

Linux futex documentation explicitly states that EINVAL is returned if
the futex is not 4-byte aligned. Check futex alignment as a Linux do
and return EINVAL.

Differential Revision: https://reviews.freebsd.org/D31279
MFC after: 2 weeks

(cherry picked from commit dad107705667dfca89db796c1c075a782f4666d4)

2 years agolinux(4): Finish cf8d74e3fe63.
Dmitry Chagin [Thu, 29 Jul 2021 09:50:43 +0000 (12:50 +0300)]
linux(4): Finish cf8d74e3fe63.

Add forgotten val3_compare initialization in case of time64 futex.

MFC after: 2 weeks

(cherry picked from commit b33e4690271cb8084631db8ccb5ed8e2ecec48bd)

2 years agolinux(4): Replace casuword32 by casueword32.
Dmitry Chagin [Thu, 29 Jul 2021 09:50:11 +0000 (12:50 +0300)]
linux(4): Replace casuword32 by casueword32.

Follow the r349951 (30b3018d), add check to react to stops and requests
to terminate between retries.

Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D31254
MFC after: 2 weeks

(cherry picked from commit 4f34dc64536f7de8324ca1a494aee88e64c7de70)

2 years agolinux(4): Implement pi futexes using umtx.
Dmitry Chagin [Thu, 29 Jul 2021 09:49:42 +0000 (12:49 +0300)]
linux(4): Implement pi futexes using umtx.

Differential Revision: https://reviews.freebsd.org/D31240
MFC after: 2 weeks

(cherry picked from commit 7a718f293a1ec59d7f59e5637e098c212adfb23b)

2 years agolinux(4): Replace copyin() by fueword32() in handle_futex_death().
Dmitry Chagin [Thu, 29 Jul 2021 09:48:59 +0000 (12:48 +0300)]
linux(4): Replace copyin() by fueword32() in handle_futex_death().

According to fetch(9) fueword facility designed to fetch atomically
small amount of data from user space.

Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D31239
MFC after: 2 weeks

(cherry picked from commit cb01cc4a1020d7916bcf0f1e774156745c387409)

2 years agoumtx: Add new pi_futex type.
Dmitry Chagin [Thu, 29 Jul 2021 09:48:34 +0000 (12:48 +0300)]
umtx: Add new pi_futex type.

Differential Revision: https://reviews.freebsd.org/D31250
MFC after: 2 weeks

(cherry picked from commit 20979f38c18665efbd9dd17eb4d6ab43d253eca4)

2 years agoumtx: Split do_unlock_pi on two counterparts.
Dmitry Chagin [Thu, 29 Jul 2021 09:47:39 +0000 (12:47 +0300)]
umtx: Split do_unlock_pi on two counterparts.

The umtx_pi_frop() will be used by Linux emulation layer.

Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D31238
MFC after: 2 weeks

(cherry picked from commit 9e32efa79bf2dc95dab86d801c08cffcd6e171db)

2 years agoumtx: Expose some of the pi umtx structures and API to the rest of the kernel.
Dmitry Chagin [Thu, 29 Jul 2021 09:46:58 +0000 (12:46 +0300)]
umtx: Expose some of the pi umtx structures and API to the rest of the kernel.

Differential Revision: https://reviews.freebsd.org/D31237
MFC after: 2 weeks

(cherry picked from commit 09f55e60024662d7a9da248257ec72cd86767cea)