]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
2 years agolinux(4): Handle 64-bit SO_TIMESTAMP for 32-bit binaries
Dmitry Chagin [Sat, 28 May 2022 20:45:39 +0000 (23:45 +0300)]
linux(4): Handle 64-bit SO_TIMESTAMP for 32-bit binaries

To solve y2k38 problem in the recvmsg syscall the new SO_TIMESTAMP
constant were added on v5.1 Linux kernel. So, old 32-bit binaries
that knows only 32-bit time_t uses the old value of the constant,
and binaries that knows 64-bit time_t uses the new constant.

To determine what size of time_t type is expected by the user-space,
store requested value (SO_TIMESTAMP) in the process emuldata structure.

MFC after: 2 weeks

(cherry picked from commit 0e26e54bdfa2859908150011a4a165e9dd3de9ac)

2 years agolinux(4): For future use replace malloc type for l_sockaddr by M_LINUX
Dmitry Chagin [Sat, 28 May 2022 20:44:48 +0000 (23:44 +0300)]
linux(4): For future use replace malloc type for l_sockaddr by M_LINUX

MFC after: 2 weeks

(cherry picked from commit 6335583990d8691ab01cd4fa92390f82f07e3d75)

2 years agolinux(4): Improve recvmsg() readability
Dmitry Chagin [Sat, 28 May 2022 20:44:02 +0000 (23:44 +0300)]
linux(4): Improve recvmsg() readability

To improve recvmsg() readability SCM_ handlers moved to a separate
functions.

MFC after: 2 weeks

(cherry picked from commit b408788d6b7edf91a6c4b9e2e8d1b34fe5d41525)

2 years agolinux(4): For future use move SCM definitions below socket options
Dmitry Chagin [Sat, 28 May 2022 20:42:23 +0000 (23:42 +0300)]
linux(4): For future use move SCM definitions below socket options

MFC after: 2 weeks

(cherry picked from commit f409a7c5386a30edccf2b26a5612cab99fdff045)

2 years agolinux(4): Avoid EISCONN if addr is specified for sendto()
Dmitry Chagin [Sat, 28 May 2022 20:42:09 +0000 (23:42 +0300)]
linux(4): Avoid EISCONN if addr is specified for sendto()

If the socket is in a connected state, the target address should be
ignored.

MFC after: 2 weeks

(cherry picked from commit db48fa8319825b4428795fcef9fb5458ac34c1a9)

2 years agolinux(4): Fix SO_LINGER l_onoff value
Dmitry Chagin [Sat, 28 May 2022 20:31:06 +0000 (23:31 +0300)]
linux(4): Fix SO_LINGER l_onoff value

On Linux l_onoff should be 1 when linger is used.

MFC after: 2 weeks

(cherry picked from commit e8d9d8082be339d046826e543e8e835c61e2d4b0)

2 years agolinux(4): Add a helper to copyout getsockopt value
Dmitry Chagin [Sat, 28 May 2022 20:30:22 +0000 (23:30 +0300)]
linux(4): Add a helper to copyout getsockopt value

For getsockopt(), optlen is a value-result argument, which is modified
on return to indicate the actual size of the value returned.
For some cases this was missed, fixed.

MFC after: 2 weeks

(cherry picked from commit e92b9a9eaa646bc1037af2a838270c43ea607d55)

2 years agolinux(4): Check the socket before any others sanity checks
Dmitry Chagin [Sat, 28 May 2022 20:29:12 +0000 (23:29 +0300)]
linux(4): Check the socket before any others sanity checks

Strictly speaking, this check is performed by the kern_recvit(), but in
the Linux emulation layer before calling the kernel we do other sanity
checks and conversions from Linux types to the native types. This changes
an order of the error returning that is critical for some buggy Linux
applications.

For recvmmsg() syscall this fixes a panic in case when the user-supplied
vlen value is 0, then error is not initialized and garbage passed to the
bsd_to_linux_errno().

MFC after: 2 weeks

(cherry picked from commit 3a99aac66f8d12386e8382aaf29d2e82e6b5353b)

2 years agoFinish cpuset_getaffinity() after f35093f8
Dmitry Chagin [Sat, 28 May 2022 17:53:08 +0000 (20:53 +0300)]
Finish cpuset_getaffinity() after f35093f8

Split cpuset_getaffinity() into a two counterparts, where the
user_cpuset_getaffinity() is intended to operate on the cpuset_t from
user va, while kern_cpuset_getaffinity() expects the cpuset from kernel
va.
Accordingly, the code that clears the high bits is moved to the
user_cpuset_getaffinity(). Linux sched_getaffinity() syscall returns
the size of set copied to the user-space and then glibc wrapper clears
the high bits.

MFC after: 2 weeks

(cherry picked from commit d46174cd8838b86b9fe956b80c82bd238c302b2e)

2 years agosysent: Get rid of bogus sys/sysent.h include.
Dmitry Chagin [Sat, 28 May 2022 17:52:17 +0000 (20:52 +0300)]
sysent: Get rid of bogus sys/sysent.h include.

Where appropriate hide sysent.h under proper condition.

MFC after: 2 weeks

(cherry picked from commit 31d1b816fe139f46083f8609c34b7d129a6e2ee0)

2 years agolinux(4): Fix unlinkat() after a125ed50
Dmitry Chagin [Mon, 23 May 2022 10:19:34 +0000 (13:19 +0300)]
linux(4): Fix unlinkat() after a125ed50

MFC after: 2 weeks

(cherry picked from commit 1bb3faed29cf1f451bcdc396eaa4f8cc476f9159)

2 years agolinux(4); Move vdso_selector_x86.c to the linux_common module
Dmitry Chagin [Mon, 23 May 2022 10:19:07 +0000 (13:19 +0300)]
linux(4); Move vdso_selector_x86.c to the linux_common module

MFC after: 2 weeks

(cherry picked from commit 2b378d59a98a4eb1dab173c4db3b48f385c47728)

2 years agolinux(4): Deduplicate execve
Dmitry Chagin [Fri, 17 Jun 2022 19:35:30 +0000 (22:35 +0300)]
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 26700ac0c4d0466c00f944bde9613d18625d1f91)

2 years agolinux(4): Fix unlink() after a125ed50
Dmitry Chagin [Mon, 23 May 2022 10:18:07 +0000 (13:18 +0300)]
linux(4): Fix unlink() after a125ed50

MFC after: 2 weeks

(cherry picked from commit e0aef0d62d2b14e754f25ef4f3582ae5faf8579c)

2 years agolinux(4): Fix execve() on amd64/linux32 after a125ed50
Dmitry Chagin [Mon, 23 May 2022 10:17:39 +0000 (13:17 +0300)]
linux(4): Fix execve() on amd64/linux32 after a125ed50

MFC after: 2 weeks

(cherry picked from commit 53726a1f1ed75a6788f5235833597e78781fffba)

2 years agolinux(4): Deduplicate bsd_to_linux_trapcode()
Dmitry Chagin [Mon, 23 May 2022 10:16:58 +0000 (13:16 +0300)]
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 9016ec056ae3896522798ead39bb2f3ff4f68809)

2 years agolinux(4): Deduplicate translate_traps()
Dmitry Chagin [Mon, 23 May 2022 10:16:26 +0000 (13:16 +0300)]
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 2434137f690dabc35586ab45fc4c4ecc5b71184f)

2 years agoRetire sv_transtrap
Dmitry Chagin [Fri, 20 May 2022 11:54:03 +0000 (14:54 +0300)]
Retire sv_transtrap

Call translate_traps directly from sendsig().

MFC after: 2 weeks

(cherry picked from commit eca368ecb6e00e9db7e1c090e98a29439d255895)

2 years agolinux(4): Retire unneeded translate_traps from arm64
Dmitry Chagin [Fri, 20 May 2022 11:19:51 +0000 (14:19 +0300)]
linux(4): Retire unneeded translate_traps from arm64

MFC after: 2 weeks

(cherry picked from commit f34a9180ae881dc77ea42ab38e992828b1567a5d)

2 years agolinux(4): To improve readability use FUTEX_UNOWNED instead of 0
Dmitry Chagin [Thu, 19 May 2022 18:42:38 +0000 (21:42 +0300)]
linux(4): To improve readability use FUTEX_UNOWNED instead of 0

MFC after: 2 weeks

(cherry picked from commit b04f5d18b5faad004a10f054d9c9072fcf31c29b)

2 years agolinux(4): Convert the native kernel signal codes into the Linux codes
Dmitry Chagin [Thu, 19 May 2022 16:56:50 +0000 (19:56 +0300)]
linux(4): Convert the native kernel signal codes into the Linux codes

MFC after: 2 weeks

(cherry picked from commit a6f85b12bbe8e50243350c77b0c5879d9e72f85b)

2 years agolinux(4): Add kernel signal code definitions
Dmitry Chagin [Thu, 19 May 2022 16:55:56 +0000 (19:55 +0300)]
linux(4): Add kernel signal code definitions

In the next commit I'll convert the native signal codes into the Linux codes,
since they are not 1:1 mapped.

MFC after: 2 weeks

(cherry picked from commit 30301975637f85172fe18b73c863dabd8ad28296)

2 years agolinux(4): Move signal codes definitions to the appropriate header
Dmitry Chagin [Thu, 19 May 2022 16:55:20 +0000 (19:55 +0300)]
linux(4): Move signal codes definitions to the appropriate header

In the Linux the struct siginfo related bits are placed into the siginfo.h
header.

MFC after: 2 weeks

(cherry picked from commit 9386e18b395dd62f6d0cccad67af51e3ad1d2429)

2 years agoarm64: Enable the floating-point exception traps
Dmitry Chagin [Thu, 19 May 2022 16:53:56 +0000 (19:53 +0300)]
arm64: Enable the floating-point exception traps

To enable it user-space needs to call feenableexcept().

FPE_FLTIDO has been added as the IDF bit can't be mapped to any existing
FPE code.

Reviewed by: andrew@
Differential revision: https://reviews.freebsd.org/D35247
MFC after: 2 weeks

(cherry picked from commit 6e2caba7a1297eeda4f43e6377667d2e049f24f9)

2 years agolinux(4): Handle cas failure on ll/sc operations
Dmitry Chagin [Thu, 19 May 2022 16:52:18 +0000 (19:52 +0300)]
linux(4): Handle cas failure on ll/sc operations

Follow the 11a6ecd4. Check and handle the case when the ll/sc casu fails
even when the compare succeeds.

For more details PR/263825, https://reviews.freebsd.org/D35150.

Obtained from: Andrew@
MFC after: 2 weeks

(cherry picked from commit 2cd662064a0cd8d179cbb5a06378fce0ec458747)

2 years agokqueue: Trim trailing whitespace
Dmitry Chagin [Thu, 19 May 2022 16:52:02 +0000 (19:52 +0300)]
kqueue: Trim trailing whitespace

MFC after: 1 week

(cherry picked from commit 2479e381cd5fe21c1f1c516ee42dfdd1fcc9abfc)

2 years agoPrevent running sigwait tests in parallel
Dmitry Chagin [Fri, 17 Jun 2022 19:35:24 +0000 (22:35 +0300)]
Prevent running sigwait tests in parallel

test_sig_discard_ign_* could not run at the same time.

Approved by:    dchagin
Sponsored by:   Netflix
Differential Revision:  https://reviews.freebsd.org/D35236

(cherry picked from commit c678572e7675c8de6d19fa925284a50f58358f35)

2 years agolinux(4): Fix arm64 syscalls.master layout
Dmitry Chagin [Mon, 16 May 2022 19:53:38 +0000 (22:53 +0300)]
linux(4): Fix arm64 syscalls.master layout

MFC after: 2 weeks

(cherry picked from commit 3020bfe1b8f53d70aa110b72227fa64f678e7307)

2 years agolibsysdecode: Fix decoding of SCHED_ flags
Dmitry Chagin [Mon, 16 May 2022 18:57:48 +0000 (21:57 +0300)]
libsysdecode: Fix decoding of SCHED_ flags

Use sys/sched.h where SCHED_ flags are defined.

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

(cherry picked from commit 41068268ec480e58811a86787b60914709375b3f)

2 years agolinux(4): Add AT_MINSIGSTKSZ to arm64 port
Dmitry Chagin [Sun, 15 May 2022 18:12:03 +0000 (21:12 +0300)]
linux(4): Add AT_MINSIGSTKSZ to arm64 port

MFC after: 2 weeks

(cherry picked from commit 390c9ea029fdd3fb2ce61fc6b48617f0f7cd8754)

2 years agolinux(4): Implement signal trampoline for arm64 in a FreeBSD-way
Dmitry Chagin [Sun, 15 May 2022 18:10:50 +0000 (21:10 +0300)]
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 c56480a832354aff995f9d0bc5da4ccf27dfe78a)

2 years agolinux(4): Retire unused include
Dmitry Chagin [Sun, 15 May 2022 18:08:45 +0000 (21:08 +0300)]
linux(4): Retire unused include

MFC after: 2 weeks

(cherry picked from commit 08e201a3b4624d84f67f4587ab21b4b4abf61e76)

2 years agolinux(4): Retire handmade DWARF annotations from signal trampolines
Dmitry Chagin [Fri, 17 Jun 2022 19:35:21 +0000 (22:35 +0300)]
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 8f9635dc99f571a0ae4e613b9a0439e68da7b160)

2 years agolinux(4): Better naming for ucontext field of struct rt_sigframe
Dmitry Chagin [Sun, 15 May 2022 18:06:47 +0000 (21:06 +0300)]
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 6e826d27c340fa29e166d06e5d8553f6c63c409e)

2 years agolinux(4): Rework the definition of struct siginfo to match Linux actual one
Dmitry Chagin [Sun, 15 May 2022 18:05:01 +0000 (21:05 +0300)]
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 af557e649cf229e45a83767c3c4a7daeb92f0b01)

2 years agolinux(4): Move sigframe definitions to separate headers
Dmitry Chagin [Sun, 15 May 2022 18:03:01 +0000 (21:03 +0300)]
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 21f246174184742ba8952aeb1dadbf58d48d54b4)

2 years agolinux(4): Cleanup signal trampolines
Dmitry Chagin [Sun, 15 May 2022 18:00:05 +0000 (21:00 +0300)]
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 ba279bcd6d75aa236bcb9ccf11aeb6f51a2f8514)

2 years agolinux(4): Retire unneeded initialization
Dmitry Chagin [Sun, 15 May 2022 17:58:47 +0000 (20:58 +0300)]
linux(4): Retire unneeded initialization

Both uc_flags and uc_link are zeroed above. On amd64 and i386 the
uc_link field is not used at all. The UC_FP_XSTATE bit should be set
in the uc_flags if OS xsave knob is turned on (and xsave is implemented).

MFC after: 2 weeks

(cherry picked from commit 0b5d5dc3767fcf2f0198f0f9549cb23983e0ee3e)

2 years agolinux(4): Implement futex_op for arm64.
Dmitry Chagin [Sun, 15 May 2022 17:49:42 +0000 (20:49 +0300)]
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 3bae1cd68a2ac3e2c37d54cf550e01257dfb1a04)

2 years agokqueue: Fix kqueue(2) man page.
Dmitry Chagin [Fri, 17 Jun 2022 19:35:18 +0000 (22:35 +0300)]
kqueue: Fix kqueue(2) man page.

Remove bogus BUGS note about timeout limit to 24 hours, that's not true
since callouting project import.

Reviewed by:            mav
Differential revision:  https://reviews.freebsd.org/D35206
MFC after:              2 weeks

(cherry picked from commit 14c99b43ef69beafa01a1574641c4cf19ecf2b9d)

2 years agosysvsem: Fix a typo
Dmitry Chagin [Sat, 14 May 2022 11:07:20 +0000 (14:07 +0300)]
sysvsem: Fix a typo

Per jamie@ rpr can be NULL if the jail is created with sysvsem=disable.
But at least it doesn't appear to be fatal, since rpr is never dereferenced
but is only compared to other prison pointers.

Reviewed by: jamie
Differential revision: https://reviews.freebsd.org/D35198
MFC after: 2 weeks

(cherry picked from commit cb2ae6163174b90e999326ecec3699ee093a5d43)

2 years agosysvsem: Style(9)
Dmitry Chagin [Sat, 14 May 2022 11:06:58 +0000 (14:06 +0300)]
sysvsem: Style(9)

MFC after: 2 weeks

(cherry picked from commit b6c8f461f09ea48d0369dba513e411e8a93e261a)

2 years agosysvsem: Trim traiing whitespace
Dmitry Chagin [Sat, 14 May 2022 11:06:40 +0000 (14:06 +0300)]
sysvsem: Trim traiing whitespace

MFC after: 2 weeks

(cherry picked from commit f0b0fdf15efee38ee6989ec2b1668f065704c7df)

2 years agofusefs tests: Remove an unused variable.
Dmitry Chagin [Fri, 13 May 2022 17:52:14 +0000 (20:52 +0300)]
fusefs tests: Remove an unused variable.

Reviewed by: asomers
Differential revision: https://reviews.freebsd.org/D35185
MFC after: 2 weeks

(cherry picked from commit d966efcc08071380cf89c46a167d5193043b6752)

2 years agotests: Get rid of invalid since 3e11d3f6 testcase
Dmitry Chagin [Thu, 12 May 2022 19:14:41 +0000 (22:14 +0300)]
tests: Get rid of invalid since 3e11d3f6 testcase

MFC after: 2 weeks

(cherry picked from commit e4a257058c95beca39aecebc70604ec5d8e37938)

2 years agoFixed the value returned by sched_getaffinity().
Dmitry Chagin [Thu, 12 May 2022 17:06:13 +0000 (20:06 +0300)]
Fixed the value returned by sched_getaffinity().

On success gnu libc sched_getaffinity() should return 0, unlike underlying
Linux syscall which returns the size of CPU mask copied to user.

PR: 263939
MFC after: 2 weeks

(cherry picked from commit 3e11d3f61ae2b2b8a8ffeff4ef32067d95c065a1)

2 years agolinux(4): Revert c7ef7c3 as it's wrong at all.
Dmitry Chagin [Wed, 11 May 2022 18:00:54 +0000 (21:00 +0300)]
linux(4): Revert c7ef7c3 as it's wrong at all.

Reported by: trasz

(cherry picked from commit 5326ebfd05c57b9432cb1ea7268f789559ba1e25)

2 years agokdump: Decode cpuset_t.
Dmitry Chagin [Wed, 11 May 2022 07:40:39 +0000 (10:40 +0300)]
kdump: Decode cpuset_t.

Reviewed by: jhb
Differential revision: https://reviews.freebsd.org/D34982
MFC after: 2 weeks

(cherry picked from commit 586ed321068b883e33df0e41ca913c074e6ea53d)

2 years agoAdd tests for affinity syscalls.
Dmitry Chagin [Wed, 11 May 2022 07:39:18 +0000 (10:39 +0300)]
Add tests for affinity syscalls.

MFC after: 2 weeks

(cherry picked from commit c8b5c478f66d155a092b8d0c6fd689546736dae7)

2 years agocpuset: Byte swap cpuset for compat32 on big endian architectures
Dmitry Chagin [Fri, 17 Jun 2022 19:35:14 +0000 (22:35 +0300)]
cpuset: Byte swap cpuset for compat32 on big endian architectures

Summary:
BITSET uses long as its basic underlying type, which is dependent on the
compile type, meaning on 32-bit builds the basic type is 32 bits, but on
64-bit builds it's 64 bits.  On little endian architectures this doesn't
matter, because the LSB is always at the low bit, so the words get
effectively concatenated moving between 32-bit and 64-bit, but on
big-endian architectures it throws a wrench in, as setting bit 0 in
32-bit mode is equivalent to setting bit 32 in 64-bit mode.  To
demonstrate:

32-bit mode:

BIT_SET(foo, 0):        0x00000001

64-bit sees: 0x0000000100000000

cpuset is the only system interface that uses bitsets, so solve this
by swapping the integer sub-components at the copyin/copyout points.

Reviewed by:    kib
Sponsored by:   Juniper Networks, Inc.
Differential Revision:  https://reviews.freebsd.org/D35225

(cherry picked from commit 47a57144af25a7bd768b29272d50a36fdf2874ba)

Fix the build after 47a57144

(cherry picked from commit 89737eb8290a10d96b77afac1b68e4740b43353b)

cpuset: Fix the KASAN and KMSAN builds

Rename the "copyin" and "copyout" fields of struct cpuset_copy_cb to
something less generic, since sanitizers define interceptors for
copyin() and copyout() using #define.

Reported by:    syzbot+2db5d644097fc698fb6f@syzkaller.appspotmail.com
Fixes: 47a57144af25 ("cpuset: Byte swap cpuset for compat32 on big endian architectures")
Sponsored by:   The FreeBSD Foundation

(cherry picked from commit 4a3e51335e86cee02569c04b9f1e95ca9abcb170)

Use Linux semantics for the thread affinity syscalls.

Linux has more tolerant checks of the user supplied cpuset_t's.

Minimum cpuset_t size that the Linux kernel permits in case of
getaffinity() is the maximum CPU id, present in the system / NBBY,
the maximum size is not limited.
For setaffinity(), Linux does not limit the size of the user-provided
cpuset_t, internally using only the meaningful part of the set, where
the upper bound is the maximum CPU id, present in the system, no larger
than the size of the kernel cpuset_t.
Unlike FreeBSD, Linux ignores high bits if set in the setaffinity(),
so clear it in the sched_setaffinity() and Linuxulator itself.

Reviewed by:            Pau Amma (man pages)
In collaboration with:  jhb
Differential revision:  https://reviews.freebsd.org/D34849
MFC after:              2 weeks

(cherry picked from commit f35093f8d6d8155ab2e56c11ee03d474688b16a2)

2 years agolinux(4): Regen for prctl fix.
Dmitry Chagin [Fri, 17 Jun 2022 19:35:11 +0000 (22:35 +0300)]
linux(4): Regen for prctl fix.

MFC after:              2 weeks

(cherry picked from commit 7b76c79b0b3aa2b769e4c6b058243ec65278f361)

2 years agolinux(4): Fix 039e98e6.
Dmitry Chagin [Mon, 9 May 2022 18:45:51 +0000 (21:45 +0300)]
linux(4): Fix 039e98e6.

The patch was about an year in my local queue and I still screwed up...

MFC after: 2 weeks

(cherry picked from commit bfae7fbaa2af43800589b666ac45897d513f4482)

2 years agolinux(4); Style.
Dmitry Chagin [Mon, 9 May 2022 18:16:48 +0000 (21:16 +0300)]
linux(4); Style.

MFC after: 2 weeks

(cherry picked from commit 109c2bd212574a12a472eed7f6e11196ce456e53)

2 years agolinux(4): Return native error from futex_atomic_op to avoid conversion by the caller.
Dmitry Chagin [Mon, 9 May 2022 18:16:31 +0000 (21:16 +0300)]
linux(4): Return native error from futex_atomic_op to avoid conversion by the caller.

MFC after: 2 weeks

(cherry picked from commit 07d108932ab5b5bc25221be4916ebf8874cd256f)

2 years agolinux(4): Fixed offset miscalculation in the preadv/pwritev syscalls.
Dmitry Chagin [Mon, 9 May 2022 18:11:37 +0000 (21:11 +0300)]
linux(4): Fixed offset miscalculation in the preadv/pwritev syscalls.

MFC after: 2 weeks

(cherry picked from commit b17446281d21311cc4f9d522c5d18337a9f786bc)

2 years agolinux(4): Regen for prctl syscall.
Dmitry Chagin [Fri, 17 Jun 2022 19:35:05 +0000 (22:35 +0300)]
linux(4): Regen for prctl syscall.

MFC after:              2 weeks

(cherry picked from commit e76857671873f0c9037dcc9c546b490714096c73)

2 years agolinux(4): Change prctl syscall definition to match Linux actual one.
Dmitry Chagin [Mon, 9 May 2022 18:09:39 +0000 (21:09 +0300)]
linux(4): Change prctl syscall definition to match Linux actual one.

Otherwise argX conversion leads to an unexpected behaviour.

MFC after: 2 weeks

(cherry picked from commit 039e98e60cb193fb0f8a86f23a26c049c46c27bd)

2 years agolinux(4): The futex_wait operation should restart.
Dmitry Chagin [Mon, 9 May 2022 18:08:59 +0000 (21:08 +0300)]
linux(4): The futex_wait operation should restart.

It's ok from the futex_wait perspective as umtxq_sleep method uses
absolute sleep timeout.

MFC after: 2 weeks

(cherry picked from commit 5eec19c8eb0e1afafd7290325c61611c9a13b621)

2 years agolinux(4): Use the right function to get the bit index in vdso binuptime.
Dmitry Chagin [Sun, 8 May 2022 14:20:52 +0000 (17:20 +0300)]
linux(4): Use the right function to get the bit index in vdso binuptime.

This is modeled after a1f93266 (by kib@).

MFC after: 2 weeks

(cherry picked from commit c6df21760381c3e48bcd412705de6f0ded9e4aae)

2 years agolinux(4): Implement vdso getcpu for x86.
Dmitry Chagin [Sun, 8 May 2022 14:20:52 +0000 (17:20 +0300)]
linux(4): Implement vdso getcpu for x86.

This is modeled after f2395455 (by kib@).

MFC after: 2 weeks

(cherry picked from commit 5a6a4fb284b1a9c4b4105fd6ab8143356f3ef3f7)

2 years agolinux(4): Refactor vdso_gettc_x86 includes.
Dmitry Chagin [Sun, 8 May 2022 14:20:51 +0000 (17:20 +0300)]
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 332eca05b557f4f9d108480688d9c0933f6ed06b)

2 years agolinux(4): Add a helper intended for copying timespec's from the userspace.
Dmitry Chagin [Sun, 8 May 2022 13:16:47 +0000 (16:16 +0300)]
linux(4): Add a helper intended for copying timespec's from the userspace.

There are many places where we copyin Linux timespec from the userspace
and then convert it to the kernel timespec. To avoid code duplication
add a tiny halper for doing this.

MFC after: 2 weeks

(cherry picked from commit 707e567a4061669b7643ddbe8a1ad9c4e6545a75)

2 years agolinux(4): Prevent time_t overflows on i386.
Dmitry Chagin [Sun, 8 May 2022 12:39:09 +0000 (15:39 +0300)]
linux(4): Prevent time_t overflows on i386.

As native i386 time_t is still 32-bit, check that the user-provided 64-bit
tv_sec value fits to the kernel time_t, return EOVERFLOW if not.

MFC after: 2 weeks

(cherry picked from commit 3dc2a06752b593acd1a76e784b169f3d60e81d00)

2 years agolinux(4): Zero out high order bits of nanoseconds in the compat mode.
Dmitry Chagin [Sun, 8 May 2022 12:38:19 +0000 (15:38 +0300)]
linux(4): Zero out high order bits of nanoseconds in the compat mode.

Assuming the kernel would use random data, the 64-bit Linux kernel ignores
upper 32 bits of tv_nsec of struct timespec64 for 32-bit binaries.

MFC after: 2 weeks

(cherry picked from commit 1579b320f1a4d555250b82fa74a391d963e7ae13)

2 years agolinux(4): Add a helper intended for copying timespec's to the userspace.
Dmitry Chagin [Sun, 8 May 2022 12:37:27 +0000 (15:37 +0300)]
linux(4): Add a helper intended for copying timespec's to the userspace.

There are many places where we convert natvie timespec and copyout it to
the userspace. To avoid code duplication add a tiny halper for doing this.

MFC after: 2 weeks

(cherry picked from commit 9a9482f87490bcbb054ba1799d69fdab7cdb6dc9)

2 years agolinux(4): Regen for ppoll_time64 syscall.
Dmitry Chagin [Fri, 17 Jun 2022 19:34:58 +0000 (22:34 +0300)]
linux(4): Regen for ppoll_time64 syscall.

MFC after:              2 weeks

(cherry picked from commit 61f45f6733d7536c442d14b30b435cfa6cd2f7cc)

2 years agolinux(4): Fix ppoll_time64 syscall definition.
Dmitry Chagin [Sun, 8 May 2022 10:37:48 +0000 (13:37 +0300)]
linux(4): Fix ppoll_time64 syscall definition.

Fixed my typo in ed61e0ce1d. Here tsp is a pointer to the 64-bit timespec.

MFC after: 2 weeks

(cherry picked from commit 94f5f150ef59d8e985bd529b0a6dea52ae8a7def)

2 years agolinux(4): Implement semtimedop syscalls.
Dmitry Chagin [Fri, 6 May 2022 17:02:59 +0000 (20:02 +0300)]
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 3245a2ecea21ace3d97cec1266fbe29c88ba1a59)

2 years agolinux(4): Regen for semtimedop syscalls.
Dmitry Chagin [Fri, 17 Jun 2022 19:34:53 +0000 (22:34 +0300)]
linux(4): Regen for semtimedop syscalls.

MFC after:              2 weeks

(cherry picked from commit 430460d7178285a26087d294177627e6c88ad369)

2 years agolinux(4): Change semtimedop syscall definition to match Linux actual one.
Dmitry Chagin [Fri, 6 May 2022 17:01:43 +0000 (20:01 +0300)]
linux(4): Change semtimedop syscall definition to match Linux actual one.

MFC after: 2 weeks

(cherry picked from commit f19c4e23413d9e2661d09120bb5434c54593bb8e)

2 years agolinux(4): Retire linux_semop implementation.
Dmitry Chagin [Fri, 6 May 2022 17:00:13 +0000 (20:00 +0300)]
linux(4): Retire linux_semop implementation.

In i386 Linux semop called via ipc() multiplexor, so use kern_semop
directly from multiplexor.

MFC after: 2 weeks

(cherry picked from commit f48a68874bf4503a18c0c55887a028dab0a4600f)

2 years agolinux(4): Regen for semop syscall.
Dmitry Chagin [Fri, 17 Jun 2022 19:34:47 +0000 (22:34 +0300)]
linux(4): Regen for semop syscall.

MFC after:              2 weeks

(cherry picked from commit cd875998dc236eb531753bba7296a834de57d99d)

2 years agolinux(4): Call semop directly.
Dmitry Chagin [Fri, 6 May 2022 16:58:53 +0000 (19:58 +0300)]
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 f686092664ee6c2c287f77f716db4d72e451c780)

2 years agosysvsem: Add a timeout argument to the semop.
Dmitry Chagin [Fri, 6 May 2022 16:51:48 +0000 (19:51 +0300)]
sysvsem: Add a timeout argument to the semop.

For future use in the Linux emulation layer for the semtimedop syscall
split the sys_semop syscall into two counterparts and add
struct timespec *timeout argument to the last one.

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

(cherry picked from commit f04534f5c84e58009efbb7f378803da3f33585b9)

2 years agolinux(4): Implement recvmmsg_time64 syscall.
Dmitry Chagin [Wed, 4 May 2022 10:06:53 +0000 (13:06 +0300)]
linux(4): Implement recvmmsg_time64 syscall.

MFC after: 2 weeks

(cherry picked from commit 1744f14e26c99af704650922e19e6934aa9a1271)

2 years agolinux(4): Regen for recvmmsg_time64 syscall.
Dmitry Chagin [Fri, 17 Jun 2022 19:34:42 +0000 (22:34 +0300)]
linux(4): Regen for recvmmsg_time64 syscall.

MFC after:      2 weeks

(cherry picked from commit 79695e9585fafb4fd7240d8183839852f6c5d43a)

2 years agolinux(4): Change recvmmsg_time64 syscall definition to match Linux actual one.
Dmitry Chagin [Wed, 4 May 2022 10:06:52 +0000 (13:06 +0300)]
linux(4): Change recvmmsg_time64 syscall definition to match Linux actual one.

MFC after: 2 weeks

(cherry picked from commit 17ccda0039229d884b9f624815775893889d161e)

2 years agolinux(4): Implement timerfd_gettime64 syscall.
Dmitry Chagin [Wed, 4 May 2022 10:06:52 +0000 (13:06 +0300)]
linux(4): Implement timerfd_gettime64 syscall.

MFC after: 2 weeks

(cherry picked from commit ce9f8d6ab00c491f84a021b23a28a1484ef817d8)

2 years agolinux(4): Regen for timerfd_gettime64 syscall.
Dmitry Chagin [Fri, 17 Jun 2022 19:34:36 +0000 (22:34 +0300)]
linux(4): Regen for timerfd_gettime64 syscall.

MFC after:      2 weeks

(cherry picked from commit ac80ae931323411c8a034624b0369eb6c0fe0934)

2 years agolinux(4): Change timerfd_gettime64 syscall definition to match Linux actual one.
Dmitry Chagin [Wed, 4 May 2022 10:06:51 +0000 (13:06 +0300)]
linux(4): Change timerfd_gettime64 syscall definition to match Linux actual one.

MFC after: 2 weeks

(cherry picked from commit 16aefe5ba3923991088f1a46e9d493664421a0a2)

2 years agolinux(4): Implement timerfd_settime64 syscall.
Dmitry Chagin [Wed, 4 May 2022 10:06:50 +0000 (13:06 +0300)]
linux(4): Implement timerfd_settime64 syscall.

MFC after: 2weeks

(cherry picked from commit b1f0b08d932005a574411c829422e81223df14da)

2 years agolinux(4): Regen for timerfd_settime64 syscall.
Dmitry Chagin [Fri, 17 Jun 2022 19:34:31 +0000 (22:34 +0300)]
linux(4): Regen for timerfd_settime64 syscall.

MFC after:      2 weeks

(cherry picked from commit f4228fbb4eb85601e4e857446642372f7d74d6e9)

2 years agolinux(4): Change timerfd_settime64 syscall definition to match Linux actual one.
Dmitry Chagin [Wed, 4 May 2022 10:06:50 +0000 (13:06 +0300)]
linux(4): Change timerfd_settime64 syscall definition to match Linux actual one.

MFC after: 2 weeks

(cherry picked from commit 8545bcff313f39665fbb26dbc2a727fd481018b2)

2 years agolinux(4): Implement timer_settime64 syscall.
Dmitry Chagin [Wed, 4 May 2022 10:06:49 +0000 (13:06 +0300)]
linux(4): Implement timer_settime64 syscall.

MFC after: 2 weeks

(cherry picked from commit a1fd2911ddb06c1a2d23ebb636a46bc20ca498e7)

2 years agolinux(4): Regen for timer_settime64 syscall.
Dmitry Chagin [Fri, 17 Jun 2022 19:34:26 +0000 (22:34 +0300)]
linux(4): Regen for timer_settime64 syscall.

MFC after:      2 weeks

(cherry picked from commit 9038a0b74cf74c73cea635ae2fff51706cc9ab33)

2 years agolinux(4): Change timer_settime64 syscall definition to match Linux actual one.
Dmitry Chagin [Wed, 4 May 2022 10:06:48 +0000 (13:06 +0300)]
linux(4): Change timer_settime64 syscall definition to match Linux actual one.

MFC after: 2 weeks

(cherry picked from commit 1508b1b6a022592e214a2ed2ed52e6100e84de35)

2 years agolinux(4): Implement timer_gettime64 syscall.
Dmitry Chagin [Wed, 4 May 2022 10:06:48 +0000 (13:06 +0300)]
linux(4): Implement timer_gettime64 syscall.

MFC after: 2 weeks

(cherry picked from commit 783c1bd8cb0cf02f2cfb95418b0a115ed975086a)

2 years agolinux(4): Regen for timer_gettime64 syscall.
Dmitry Chagin [Fri, 17 Jun 2022 19:34:20 +0000 (22:34 +0300)]
linux(4): Regen for timer_gettime64 syscall.

MFC after:      2 weeks

(cherry picked from commit 1cccef6dff13f4854ac75c243c36317ccd4defc1)

2 years agolinux(4): Change timer_gettime64 syscall definition to match Linux actual one.
Dmitry Chagin [Wed, 4 May 2022 10:06:47 +0000 (13:06 +0300)]
linux(4): Change timer_gettime64 syscall definition to match Linux actual one.

MFC after: 2 weeks

(cherry picked from commit ccec96033c5aa2f1dfd6c736daf3e493c2272af3)

2 years agolinux(4): Implement sched_rr_get_interval_time64 syscall.
Dmitry Chagin [Wed, 4 May 2022 10:06:47 +0000 (13:06 +0300)]
linux(4): Implement sched_rr_get_interval_time64 syscall.

MFC after: 2 weeks

(cherry picked from commit 8c84ca657bb343b73f315520ac3cabc43c5a67ec)

2 years agolinux(4): Regen for sched_rr_get_interval_time64 syscall.
Dmitry Chagin [Fri, 17 Jun 2022 19:34:15 +0000 (22:34 +0300)]
linux(4): Regen for sched_rr_get_interval_time64 syscall.

MFC after:      2 weeks

(cherry picked from commit cdddbb77c30b7f518f7ac78b113a823c3ca0cd11)

2 years agolinux(4): Change sched_rr_get_interval_time64 syscall definition to match Linux actua...
Dmitry Chagin [Wed, 4 May 2022 10:06:45 +0000 (13:06 +0300)]
linux(4): Change sched_rr_get_interval_time64 syscall definition to match Linux actual one.

MFC after: 2 weeks

(cherry picked from commit 7b520c0b3c50a1a0025ee6cdbd457a1b6e6c2a0c)

2 years agoRemove dead code.
Dmitry Chagin [Tue, 26 Apr 2022 16:40:59 +0000 (19:40 +0300)]
Remove dead code.

is_physical_memory() dead since 235a54de.

Reviewed by: markj
Differential revision: https://reviews.freebsd.org/D35056
MFC after: 2 weeks

(cherry picked from commit fe2c9f83a6dc1cc62da177a765ce8a265894b2cd)

2 years agolinux(4): Add epoll_pwai2 syscall.
Dmitry Chagin [Tue, 26 Apr 2022 16:35:59 +0000 (19:35 +0300)]
linux(4): Add epoll_pwai2 syscall.

MFC after: 2 weeks

(cherry picked from commit e00aad1042e7163865763b42d8d72137eeb9df63)

2 years agolinux(4): Regen for epoll_pwait2 syscall.
Dmitry Chagin [Fri, 17 Jun 2022 19:34:09 +0000 (22:34 +0300)]
linux(4): Regen for epoll_pwait2 syscall.

(cherry picked from commit df377f1fb8dd92a1839bc578aac46d2cdf1b5b84)

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

MFC after: 2 weeks

(cherry picked from commit 81b0b7dc0c624c2e086943822beda0b08a12e252)

2 years agolinux(4): Add copyin_sigset() helper.
Dmitry Chagin [Tue, 26 Apr 2022 16:35:57 +0000 (19:35 +0300)]
linux(4): Add copyin_sigset() helper.

MFC after: 2 weeks

(cherry picked from commit 3923e632094a7e4cc66cd8e68964b9cb495119e2)

2 years agolinux(4): Add linux_epoll_pwait_ts() helper for future use.
Dmitry Chagin [Tue, 26 Apr 2022 16:35:56 +0000 (19:35 +0300)]
linux(4): Add linux_epoll_pwait_ts() helper for future use.

MFC after: 2 weeks

(cherry picked from commit 27a25179c8356d58b5df6303d850050122f020c6)

2 years agolinux(4): Copyout pselect timeout.
Dmitry Chagin [Tue, 26 Apr 2022 16:35:56 +0000 (19:35 +0300)]
linux(4): Copyout pselect timeout.

According to pselect6 manual, on error timeout becomes undefined, by fact
Linux modifies the timeout and ignore EFAULT error if so.

MFC after: 2 weeks

(cherry picked from commit 5171ed79f6d1fc3948a7ebfb32b02d698224c29b)

2 years agolinux(4): Add a simple rseq syscall implementation.
Dmitry Chagin [Tue, 26 Apr 2022 16:35:56 +0000 (19:35 +0300)]
linux(4): Add a simple rseq syscall implementation.

To avoid annoyng messages from glibc-2.35 test suite add the simple
implementation of rseq syscall which is do nothing for now.

I plan to implement it if and when the API stabilizes.

MFC after: 2 weeks

(cherry picked from commit ee55d560e89ac8de37def993a13d2582638273b7)