Commit graph

138 commits

Author SHA1 Message Date
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
Dmitry Chagin
e58a9a565f Regen for ('0f8dab45404f347752470579feccc6d2739b9570') Linux
rt_sigtimedwait system call.

MFC after:	2 weeks

(cherry picked from commit e29ea22f70)
2022-06-17 22:27:59 +03:00
Dmitry Chagin
77935ceb59 linux(4): Fix timeout parameter of rt_sigtimedwait syscall, which is
timespec not a timeval.

MFC after:	2 weeks

(cherry picked from commit 0f8dab4540)
2022-06-17 22:27:59 +03:00
Dmitry Chagin
587982d0d9 linux(4); Retire unnecessary __packed attribute from some struct's
definition.

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

(cherry picked from commit 19593f775c)
2022-06-17 22:22:15 +03:00
Andrew Turner
e5e2c7ffa0 Create sys/reg.h for the common code previously in machine/reg.h
Move the common kernel function signatures from machine/reg.h to a new
sys/reg.h. This is in preperation for adding PT_GETREGSET to ptrace(2).

Reviewed by:	imp, markj
Sponsored by:	DARPA, AFRL (original work)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D19830

(cherry picked from commit b792434150)
2022-05-12 15:12:59 -07:00
Edward Tomasz Napierala
f707a6cf1a Add infrastructure required for Linux coredump support
This adds `sv_elf_core_osabi`, `sv_elf_core_abi_vendor`,
and `sv_elf_core_prepare_notes` fields to `struct sysentvec`,
and modifies imgact_elf.c to make use of them instead
of hardcoding FreeBSD-specific values.  It also updates all
of the ABI definitions to preserve current behaviour.

This makes it possible to implement non-native ELF coredump
support without unnecessary code duplication.  It will be used
for Linux coredumps.

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

(cherry picked from commit 435754a59e)
2022-05-12 15:12:59 -07:00
Edward Tomasz Napierala
15acd92e8f linux: implement rt_sigsuspend(2) on arm64
... by making it architecture-independent.

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

(cherry picked from commit 72f7ddb587)
2022-02-14 18:45:24 +00:00
Edward Tomasz Napierala
dfd9bcf077 Regen after 2561da0636.
(cherry picked from commit 8bc3dc0100)
2022-02-14 18:43:29 +00:00
Edward Tomasz Napierala
9a76e9f246 linux: Fix declaration of rt_sigreturn() on arm64
On Linux, this syscall doesn't take any arguments; instead
it assumes the context was put on the stack.

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

(cherry picked from commit 2561da0636)
2022-02-14 18:43:20 +00:00
Edward Tomasz Napierala
95f24ec842 linux(4): remove unfinished vsyscall bits on arm64
The vsyscall mechanism is obsolete.

Reviewed By:	dchagin, emaste
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D31091

(cherry picked from commit 84a3963d5d)
2022-02-14 00:09:05 +00:00
Edward Tomasz Napierala
552c230a57 linux: implement set_cloned_tls() on arm64
This fixes random segfaults on "git commit --amend".

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

(cherry picked from commit a397b55083)
2022-02-14 00:08:19 +00:00
Edward Tomasz Napierala
20daa209e4 linux: implement set_upcall on aarch64
This fixes "git diff" (git-1:2.25.1-1ubuntu3).

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

(cherry picked from commit e505c3066b)
2022-02-14 00:08:11 +00:00
Edward Tomasz Napierala
5d5616acec linux: export AT_HWCAP and AT_HWCAP2 on aarch64
The flag values seem to be the same between Linux and FreeBSD.
Comparing to a Linux VM on the same hardware, we're missing
HWCAP_EVTSTRM, HWCAP_CPUID, HWCAP_DCPOP, HWCAP_USCAT, HWCAP_PACA,
and HWCAP_PACG.

Reviewed By:	mhorne, emaste
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D30540

(cherry picked from commit b501b2ae52)
2022-02-13 23:21:35 +00:00
Edward Tomasz Napierala
b36eaf0f4c linux: fix architecture returned for uname on aarch64
Previously it would return "arm64", which was breaking build
for Linux kernel.  While here, reshuffle entries in the auxv
vector to match real Linux.

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

(cherry picked from commit aa462cab60)
2022-02-13 23:21:20 +00:00
Edward Tomasz Napierala
cbab32bdf1 linux: deduplicate DUMMY() entries
No functional changes.

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

(cherry picked from commit 83043a741d)
2022-02-13 22:22:11 +00:00
Edward Tomasz Napierala
56205425a9 linux: make linux64.ko loadable again on aarch64
This should probably get deduplicated; this is a quick fix
just to unbreak things.

Fixes:		6d926e850d
Sponsored By:	EPSRC

(cherry picked from commit 023ee5392c)
2022-02-13 21:31:07 +00:00
Edward Tomasz Napierala
64b1197cce Regen after 6d926e850d.
Sponsored By:	EPSRC

(cherry picked from commit c0f171736a)
2022-02-13 21:31:00 +00:00