Commit graph

309 commits

Author SHA1 Message Date
Dmitry Chagin
c272720e2a linux(4): Properly build argument list for the signal handler
Provide arguments 2 and 3 if signal handler installed with SA_SIGINFO.

MFC after:		2 weeks

(cherry picked from commit 109fd18ad9)
2022-06-17 22:35:38 +03:00
Dmitry Chagin
fa6d9e24f4 linux(4): Microoptimize rt_sendsig(), convert signal mask once
On amd64 Linux saves the thread signal mask in both contexts, in the machine
dependent and in the machine independent. Both contexts are user accessible.
Convert the mask once, then copy it.

MFC after:		2 weeks

(cherry picked from commit c30a767c6f)
2022-06-17 22:35:38 +03:00
Dmitry Chagin
0f23fc29f9 linux(4): Avoid direct manipulation of td_sigmask
Use kern_sigprocmask() instead of direct manipulation of td_sigmask
to reschedule newly blocked signals.

MFC after:		2 weeks

(cherry picked from commit 2ab9b59faa)
2022-06-17 22:35:37 +03:00
Dmitry Chagin
601c19df36 linux(4): Reduce duplication between MD parts of the Linuxulator
Move sigprocmask actions defines under compat/linux,
they are identical across all Linux architectures.

MFC after:		2 weeks

(cherry picked from commit 2ca34847e7)
2022-06-17 22:35:37 +03:00
Dmitry Chagin
959d0bdc24 linux(4): Deduplicate execve
As linux_execve is common across archs, except amd64 32-bit Linuxulator,
move it under compat/linux.

Noted by:               andrew@
MFC after:              2 weeks

(cherry picked from commit 26700ac0c4)
2022-06-17 22:35:30 +03:00
Dmitry Chagin
06f6414a64 linux(4): Deduplicate bsd_to_linux_trapcode()
As bsd_to_linux_trapcode() is common for x86 Linuxulators,
move it under x86/linux.

MFC after:		2 weeks

(cherry picked from commit 9016ec056a)
2022-06-17 22:35:28 +03:00
Dmitry Chagin
f327f595cb linux(4): Deduplicate translate_traps()
As translate_traps() is common for x86 Linuxulators,
move it under x86/linux.

MFC after:		2 weeks

(cherry picked from commit 2434137f69)
2022-06-17 22:35:28 +03:00
Dmitry Chagin
3cf95e49cb Retire sv_transtrap
Call translate_traps directly from sendsig().

MFC after:		2 weeks

(cherry picked from commit eca368ecb6)
2022-06-17 22:35:27 +03:00
Dmitry Chagin
68384ee5e4 linux(4): Retire handmade DWARF annotations from signal trampolines
The Linux exports __kernel_sigreturn and __kernel_rt_sigreturn from the
vdso. Modern glibc's sigaction sets the sa_restorer field of sigaction
to the corresponding vdso __sigreturn, and sets the SA_RESTORER.
Our signal trampolines uses the FreeBSD-way to call a signal handler,
so does not use the sigaction's sa_restorer.

However, as glibc's runtime linker depends on the existment of the vdso
__sigreturn symbols, for all Linuxulators was added separate trampolines
named __sigcode with DWARF anotations and left separate __sigreturn
methods, which are exported.

MFC after:              2 weeks

(cherry picked from commit 8f9635dc99)
2022-06-17 22:35:21 +03:00
Dmitry Chagin
c2704d3780 linux(4): Better naming for ucontext field of struct rt_sigframe
To reduce sendsig code difference and to avoid confusing me,
rename sf_sc to sf_uc to match the content.

MFC after:		2 weeks

(cherry picked from commit 6e826d27c3)
2022-06-17 22:35:21 +03:00
Dmitry Chagin
43dbc72cc5 linux(4): Rework the definition of struct siginfo to match Linux actual one
Rework the defintion of struct siginfo so that the array padding
struct siginfo to SI_MAX_SIZE can be placed in a union along side of the
rest of the struct siginfo members.  The result is that we no longer need
the __ARCH_SI_PREAMBLE_SIZE or SI_PAD_SIZE definitions.

Move struct siginfo definition under /compat/linux to reduce MD part.
To avoid headers polution include linux_siginfo.h in the MD linux.h

MFC after:		2 weeks

(cherry picked from commit af557e649c)
2022-06-17 22:35:20 +03:00
Dmitry Chagin
3f3bfb8266 linux(4): Move sigframe definitions to separate headers
The signal trampoine-related definitions are used only in the MD part
of code, wherefore moved from everywhere used linux.h to separate MD
headers.

MFC after:		2 weeks

(cherry picked from commit 21f2461741)
2022-06-17 22:35:20 +03:00
Dmitry Chagin
0fae97fd1c linux(4): Cleanup signal trampolines
This is the first stage of a signal trampolines refactoring.

From trampolines retired emulation of the 'call' instruction, which is
replaced by direct call of a signal handler. The signal handler address
is in the register.

The previous trampoline implemenatation used semi-Linux-way to call
a signal handler via the 'jmp' instruction. Wherefore the trampoline
emulated a 'call' instruction to into the stack the return address for
signal handler's 'ret' instruction.  Wherefore handmade DWARD annotations
was used.

While here rephrased and removed excessive comments.

MFC after:		2 weeks

(cherry picked from commit ba279bcd6d)
2022-06-17 22:35:19 +03:00
Dmitry Chagin
d9c17939f0 linux(4): Return native error from futex_atomic_op to avoid conversion by the caller.
MFC after:		2 weeks

(cherry picked from commit 07d108932a)
2022-06-17 22:35:06 +03:00
Dmitry Chagin
e7a07ad1db linux(4): Implement vdso getcpu for x86.
This is modeled after f2395455 (by kib@).

MFC after:		2 weeks

(cherry picked from commit 5a6a4fb284)
2022-06-17 22:35:00 +03:00
Dmitry Chagin
f360bdf68d linux(4): Refactor vdso_gettc_x86 includes.
Factor out includes from common vdso_gettc_x86 file to the corresponding
MD files.

MFC after:		2 weeks

(cherry picked from commit 332eca05b5)
2022-06-17 22:34:59 +03:00
Dmitry Chagin
9fd86dde83 linux(4): Implement semtimedop syscalls.
On i386 are two semtimedop. The old one is called via multiplexor and
uses 32-bit timespec, and new semtimedop_tim64, which is uses 64-bit
timespec.

MFC after:		2 weeks

(cherry picked from commit 3245a2ecea)
2022-06-17 22:34:53 +03:00
Dmitry Chagin
639c685d25 linux(4): Regen for semtimedop syscalls.
MFC after:              2 weeks

(cherry picked from commit 430460d717)
2022-06-17 22:34:53 +03:00
Dmitry Chagin
6fe321e3ac linux(4): Change semtimedop syscall definition to match Linux actual one.
MFC after:		2 weeks

(cherry picked from commit f19c4e2341)
2022-06-17 22:34:47 +03:00
Dmitry Chagin
2f5e4f652a linux(4): Regen for semop syscall.
MFC after:              2 weeks

(cherry picked from commit cd875998dc)
2022-06-17 22:34:47 +03:00
Dmitry Chagin
219681b57b linux(4): Call semop directly.
As the Linux semop syscall is not defined in i386, and as it is equal
to the native semop syscall, call it directly.
Fix semop definition to match Linux actual one - nsops is size_t type.

MFC after:		2 weeks

(cherry picked from commit f686092664)
2022-06-17 22:34:43 +03:00
Dmitry Chagin
4b4dac6ce8 linux(4): Regen for epoll_pwait2 syscall.
(cherry picked from commit df377f1fb8)
2022-06-17 22:34:09 +03:00
Dmitry Chagin
7a865d8861 linux(4): Change epoll_pwait2 syscall definition to match Linux actual one.
MFC after:	2 weeks

(cherry picked from commit 81b0b7dc0c)
2022-06-17 22:34:05 +03:00
Dmitry Chagin
b203abf47a linux(4): Regen for rseq syscall.
(cherry picked from commit 75e409495f)
2022-06-17 22:34:03 +03:00
Dmitry Chagin
24c5e6eb7b linux(4): Change rseq syscall definition to match Linux actual one.
MFC after:	2 weeks

(cherry picked from commit f202f35db0)
2022-06-17 22:33:57 +03:00
Edward Tomasz Napierala
feb67d438b 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 f7b04c53de)
2022-06-17 22:33:41 +03:00
Mateusz Guzik
753605353d linux: remove the always curthread argument from lconvpath
(cherry picked from commit af4051d250)
2022-06-17 22:33:39 +03:00
Edward Tomasz Napierala
ca5426f938 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 0bf8d5d5f4)
2022-06-17 22:33:37 +03:00
Edward Tomasz Napierala
99950e8beb 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 a90ff3c4bc)
2022-06-17 22:33:37 +03:00
Edward Tomasz Napierala
dadf3312b4 linux: Fix another amd64-specific piece of linux_ptrace.c
This was missed in c91d0e59be.  No functional changes.

Sponsored By:	EPSRC

(cherry picked from commit 3be6e606d7)
2022-06-17 22:33:36 +03:00
Edward Tomasz Napierala
ab52de4478 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 c91d0e59be)
2022-06-17 22:33:35 +03:00
Edward Tomasz Napierala
50ed51aa5b 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 f0d9a6a781)
2022-06-17 22:33:35 +03:00
Edward Tomasz Napierala
e5a000ff5a 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 ad0379660d)
2022-06-17 22:33:34 +03:00
Edward Tomasz Napierala
bf0ad7c979 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 3417c29851)
2022-06-17 22:33:34 +03:00
Dmitry Chagin
a1e6526440 linux(4): Remove the unnecessary spaces.
MFC after:		2 weeks

(cherry picked from commit bed2ac27a1)
2022-06-17 22:33:33 +03:00
Dmitry Chagin
8b54e105d5 linux(4): Regen for clone3 system call.
MFC after:		2 weeks

(cherry picked from commit b356030e67)
2022-06-17 22:33:30 +03:00
Dmitry Chagin
b27e302329 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 17913b0b6b)
2022-06-17 22:33:30 +03:00
Dmitry Chagin
8fb3f959dc 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 0a4b664ae8)
2022-06-17 22:33:30 +03:00
Dmitry Chagin
94ac0dac7f linux(4): Regen for clone syscall.
MFC after:		2 weeks

(cherry picked from commit 0c08f34f4d)
2022-06-17 22:33:29 +03:00
Dmitry Chagin
b2c247a0db 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 f1c450492f)
2022-06-17 22:33:29 +03:00
Dmitry Chagin
5a66ec2748 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 de8374df28)
2022-06-17 22:33:28 +03:00
Dmitry Chagin
282eae4d06 linux(4): Regen for faccessat2 system call.
MFC after:		2 weeks

(cherry picked from commit bee191e46f)
2022-06-17 22:33:26 +03:00
Dmitry Chagin
15e715fe7c 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 13d79be995)
2022-06-17 22:33:26 +03:00
Dmitry Chagin
85b2ff6496 linux(4): Fix gcc buld.
gcc failed as it didn't inlined the builtins and generates calls to
the libgcc, ld can't find libgcc as cross-toolchain libgcc is not installed.
To avoid this add internal vDSO ffs functions without optimized builtins.

Reported by:		jhb
MFC after:		2 weeks

(cherry picked from commit f337940144)
2022-06-17 22:33:14 +03:00
Dmitry Chagin
6698c1a28d linux(4): Allow musl brand to use FUTEX_REQUEUE op.
Initial patch from submitter was adapted by me to prevent unconditional
FUTEX_REQUEUE use.

PR:			255947
Submitted by:		Philippe Michaud-Boudreault
Differential Revision:	https://reviews.freebsd.org/D30332

(cherry picked from commit cf8d74e3fe)
2022-06-17 22:33:12 +03:00
Edward Tomasz Napierala
97382953f2 linux: implement sigaltstack(2) on arm64
... by making it machine-independent.

Reviewed By:	dchagin
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D31286

(cherry picked from commit 30c6d98219)
2022-06-17 22:33:10 +03:00
Dmitry Chagin
2e084b4b54 Drop "All rights reserved" from my copyright statements.
Add email and fixup years while here.

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

(cherry picked from commit 1ca6b15bbd)
2022-06-17 22:33:09 +03:00
Dmitry Chagin
896a4b7c79 linux(4): Add arch name to the some printfs.
Reviewed by:		emaste
Differential revision:	https://reviews.freebsd.org/D30904
MFC after:		2 weeks

(cherry picked from commit ae8330b448)
2022-06-17 22:33:08 +03:00
Dmitry Chagin
4e34c0445c linux(4): Fixup the vDSO initialization order.
The vDSO initialisation order should be as follows:
- native abi init via exec_sysvec_init();
- vDSO symbols queued to the linux_vdso_syms list;
- linux_vdso_install();
- linux_exec_sysvec_init();

As the exec_sysvec_init() called with SI_ORDER_ANY (last) at SI_SUB_EXEC
order, move linux_vdso_install() and linux_exec_sysvec_init() to the
SI_SUB_EXEC+1 order.

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

(cherry picked from commit 09cffde975)
2022-06-17 22:33:07 +03:00
Dmitry Chagin
b960dd4815 linux(4): Constify vdso install/deinstall.
In order to reduce diff between arches constify vdso install/deinstall
functions like arm64.

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

(cherry picked from commit a543556c81)
2022-06-17 22:33:07 +03:00