Commit graph

154 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
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
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
5781e205b0 linux(4): Retire unneeded translate_traps from arm64
MFC after:	2 weeks

(cherry picked from commit f34a9180ae)
2022-06-17 22:35:27 +03:00
Dmitry Chagin
f92747cd4c linux(4): Fix arm64 syscalls.master layout
MFC after:		2 weeks

(cherry picked from commit 3020bfe1b8)
2022-06-17 22:35:23 +03:00
Dmitry Chagin
d30b87879b linux(4): Add AT_MINSIGSTKSZ to arm64 port
MFC after:	2 weeks

(cherry picked from commit 390c9ea029)
2022-06-17 22:35:23 +03:00
Dmitry Chagin
98b737c9f1 linux(4): Implement signal trampoline for arm64 in a FreeBSD-way
The implemenation differs from others Linuxulators.
For unwinders Linux ucontext_t is stored, however native machine context
is used to store/restore process state to avoid code duplication.

As DWARF Aarch64 does not define a register number for PC and provides no
direct way to encode the PC of the previous frame, CFI cannot describe a
signal trampoline frame. So, modified the vdso linker script to discard
unused sections.

Extensions are not implemented.

MFC after:		2 weeks

(cherry picked from commit c56480a832)
2022-06-17 22:35:22 +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
30c8127e3c linux(4): Implement futex_op for arm64.
It's mostly modeled like the Linux does.

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

(cherry picked from commit 3bae1cd68a)
2022-06-17 22:35:19 +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
7fdc5559bd linux(4): Remove unused arm64 SDT declarations
Those tracepoints have been removed somewhere in the past.

Sponsored By:	EPSRC

(cherry picked from commit a15c591899)
2022-06-17 22:33:40 +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
5bce15eb9e linux(4): Fix "set but not used" warnings
No functional changes.

Sponsored By:	EPSRC

(cherry picked from commit a089c17d32)
2022-06-17 22:33:38 +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
b04e157ce9 linux: Implement linux_to_bsd_regset() on arm64
This will be used by ptrace.

Sponsored By:	EPSRC

(cherry picked from commit 6f397bc0fb)
2022-06-17 22:33:36 +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
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
5eb6549994 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 fc37be2460)
2022-06-17 22:33:27 +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
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
Edward Tomasz Napierala
0b82c544de linux: implement signal delivery on arm64
Note that this still uses FreeBSD-style sigframe;
this will be addressed later.

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

(cherry picked from commit ccc510b463)
2022-06-17 22:33:09 +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
a340b5b4bd linux(4); Almost complete the vDSO.
The vDSO (virtual dynamic shared object) is a small shared library that the
kernel maps R/O into the address space of all Linux processes on image
activation. The vDSO is a fully formed ELF image, shared by all processes
with the same ABI, has no process private data.

The primary purpose of the vDSO:
- non-executable stack, signal trampolines not copied to the stack;
- signal trampolines unwind, mandatory for the NPTL;
- to avoid contex-switch overhead frequently used system calls can be
  implemented in the vDSO: for now gettimeofday, clock_gettime.

The first two have been implemented, so add the implementation of system
calls.

System calls implemenation based on a native timekeeping code with some
limitations:
- ifunc can't be used, as vDSO r/o mapped to the process VA and rtld
  can't relocate symbols;
- reading HPET memory is not implemented for now (TODO).

In case on any error vDSO system calls fallback to the kernel system
calls. For unimplemented vDSO system calls added prototypes which call
corresponding kernel system call.

Relnotes:		yes
Tested by:              trasz (arm64)
Differential revision:  https://reviews.freebsd.org/D30900
MFC after:              2 weeks

(cherry picked from commit 9931033bbf)
2022-06-17 22:33:07 +03:00
Dmitry Chagin
54689a282a linux(4): Modify sv_onexec hook to return an error.
Temporary add stubs to the Linux emulation layer which calls the existing hook.

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

(cherry picked from commit 5fd9cd53d2)
2022-06-17 22:33:05 +03:00
Dmitry Chagin
f652f0b5d8 linux(4): Remove function prototypes from the vDSO.
In preparation for vDSO code revision get rid of incomplete vDSO methods
from locore, but leave .note.Linux section commented out.
.note.Linux section is used by glibc rtld to get the kernel version, that
saves one system call call. I'll try to implement it later, if figure out
how to use it with jails.

MFC after:      2 weeks

(cherry picked from commit 815165be20)
2022-06-17 22:33:03 +03:00
Edward Tomasz Napierala
9240bf3e1f linux(4): implement coredumps on arm64
Previously they only worked on amd64.

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

(cherry picked from commit 45d99014ca)
2022-06-17 22:33:02 +03:00
Edward Tomasz Napierala
ab3423fdb7 linux(4): revert arm64 part of 447636e43c
The arm64 part of the patch was incomplete and prevented
linux64.ko from loading due to missing symbol.

Sponsored By:	EPSRC

(cherry picked from commit 93c3453f11)
2022-06-17 22:33:02 +03:00
Edward Tomasz Napierala
1b196c07b8 linux(4): implement coredump support
Implement dumping core for Linux binaries on amd64, for both
32- and 64-bit executables.  Some bits are still missing.

This is based on a prototype by chuck@.

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

(cherry picked from commit 447636e43c)
2022-06-17 22:33:02 +03:00
Dmitry Chagin
0cd177a3d3 linux(4): Retire linux_kplatform.
Assuming we can't run on i486, i586 class cpu, retire linux_kplatform var
and use hardcoded 'machine' value in linux_newuname().

I have added linux_kplatform for consistency with linux_platform which is
placed in to vdso to avoid excess copyout it on stack for AT_PLATFORM at
exec time.

This is the first stage of Linuxulator's vdso revision.

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

(cherry picked from commit c1da89fec2)
2022-06-17 22:30:23 +03:00
Dmitry Chagin
92b1cf8572 linux(4): Regen for futex system call.
MFC after:	2 weeks

(cherry picked from commit ee64d98204)
2022-06-17 22:30:14 +03:00
Dmitry Chagin
f348d6732b linux(4): Change Linux futex syscall definition to match Linux actual one.
MFC after:	2 weeks

(cherry picked from commit 3c1de151e3)
2022-06-17 22:30:14 +03:00