Commit Graph
2981 Commits
Author SHA1 Message Date
maxjivi05 88f11c3fd0 fex: leave aio rejections, keys and unwritable event buffers to the kernel
A copied control block whose key slot is read-only is now passed to the
kernel as the guest's own block at the end of the list, so the kernel reports
its native fd, eventfd or key error. After io_submit, guest keys follow the
private copies through the first rejected position, and they are stored
through a fresh translation of the guest address, skipped when it no longer
maps. io_getevents and io_pgetevents probe the guest event buffer and reap at
most its writable prefix, handing an unwritable buffer to the kernel so
completions are not consumed.
2026-12-04 21:34:58 -05:00
maxjivi05 54bf8268a9 fex: keep aio keys, cancels and reaped events native for copied control blocks
Guest aio_key is no longer cleared before dispatch: the slot is probed with a
same-value write and only the first n accepted copies get key 0 after the host
io_submit returns n. io_cancel redirects to a copy only when the guest block is
readable and its key is 0, so unreadable blocks fault in the kernel as before.
io_getevents and io_pgetevents reap into emulator storage, translate and
release copies there, then copy the events out, returning -EFAULT if that
fails. A successful io_setup clears the ring header magic so userspace ring
reapers fall back to io_getevents, where copies are translated and released.
2026-12-04 21:08:05 -05:00
maxjivi05 027f9d5827 FEX: submit aio control blocks through private host copies
Stop editing guest IOCBs in place when aio_buf needs translation. io_submit
now hands the kernel a host copy of each such control block, maps
io_event.obj back to the guest pointer when the completion is reaped,
redirects io_cancel by guest pointer and context to the copy, and frees
copies on reap, on io_destroy, or when the kernel did not accept them.
The guest control block is never patched and its protection is never
touched, so the pending restore records, the protection windows and the
restore hooks in mmap, munmap, mremap and mprotect are removed with their
tests.
2026-12-04 20:04:52 -05:00
maxjivi05 25d0a3df8d FEX: restore stranded aio words before readable protection, report failures
Restore every pending aio word in the range before a readable guest
protection is applied, on both the high and low paths, and fail the guest
mprotect with the old protection kept when a word cannot be restored or its
window cannot be closed. Ignore user-sent SIGSEGV/SIGBUS after deferral,
read the cleared syscall info when resuming with guest GPRs and on restore,
and check exclusive acquisition from a separate thread in the harness.
2026-12-04 19:19:28 -05:00
maxjivi05 6f3b66af49 Rebase the FEX patch series onto FEX-2612 2026-12-04 18:49:17 -05:00
maxjivi05 6d69e52151 Defer user signals while guest high memory mappings are held
Only the trampoline breakpoint completes a replay, user-sent SIGSEGV,
SIGBUS and SIGTRAP raised while the mapping lock is held are requeued
after it is released, and stranded control block words are restored
when their page turns readable again. The harness now runs under a
timeout.
2026-12-04 18:35:28 -05:00
maxjivi05 b0727d8e2f Keep high-memory traps ordered, fault-exact and locked against unmap
Protect, Map and low mmap/munmap/mremap/mprotect reconcile pending aio
restores at once, and io_submit reconciles them even when no high region
is mapped. Ordered loads and stores split across backings are emulated
between full fences instead of being byte-copied through the trampoline;
atomics and exclusives are still refused. Gather and scatter use
fault-safe copies, and a failing piece is re-faulted at the guest
instruction through a probe load, with SIGBUS redelivered the same way.
The VMA lock is held from planning until the scatter finishes, so unmap
and protect cannot race a resumed access. Sign-extending loads are no
longer classified as writes.
2026-12-04 18:03:30 -05:00
maxjivi05 3ac630f006 Replay high-memory faults over the whole access and reconcile aio restores on unmap 2026-12-04 17:07:07 -05:00
maxjivi05 dc3578b8f6 Send only the first message of a batch when the socket cannot be pinned 2026-12-04 16:15:39 -05:00
maxjivi05 0f54bc6f45 Stop message batches at unreadable vectors, send singly without a spare descriptor and reserve aio restore slots
A message whose iovec snapshot cannot be taken ends the prepared batch
instead of being sent with an unknown length; when it is the first
message the kernel handles the original array natively. When the
batch socket cannot be duplicated, messages still go one at a time on
the original descriptor with each length written before the next send.
Pending aio restore slots are reserved under the pending mutex before
the first guest edit and released or handed to the pending record, so
concurrent submissions cannot exceed the bound. Tests use a real
socket pair, injected descriptor exhaustion and concurrent
reservations.
2026-12-04 14:41:00 -05:00
maxjivi05 7a396aac61 Pin batch sockets, fall back to whole batches and reconcile pending aio restores
Follow-up message sends and the first dispatch share one duplicated
socket. When it cannot be duplicated, the whole translated batch goes
to the kernel in one call and lengths are written back up to the first
one that cannot be stored. Short sends compare against the iovec
lengths given to the kernel. Unrestorable aio_buf edits, including
unreadable control blocks, keep their storage in a bounded list that
later submissions reconcile.
2026-12-04 12:19:06 -05:00
maxjivi05 a828192cae Harden high-memory aio, capability and message batch write-backs
Restore patched aio buffers through /proc/self/mem when the control block
became read-only and keep the scratch vectors alive if that fails too,
fault capability calls whose header write-back fails, stop send batches
after a short message, and pin the batch socket with a private dup.
2026-12-04 11:46:50 -05:00
maxjivi05 0965c46359 Send translated message batches one message at a time
Submit sendmmsg batches that need scratch headers one message per call,
storing each length before the next message goes out, so a length that
cannot be stored stops the batch where Linux would. Skip the name length
when no name was given and store flags before the control length. Check
the whole fixed file-handle header even when its size is invalid. Hand
capget and capset a private header so the checked data size matches the
version the kernel reads, and return a rewritten version to the guest.
Patch and restore AIO control blocks under the mapping lock and restore
only the block that was patched.
2026-12-04 08:56:22 -05:00
maxjivi05 c3de54593c Size high-memory syscall spans by kernel widths and embedded sizes
Read counts with the width the kernel uses for each argument, so int
and unsigned int counts ignore the upper register bits and negative
counts reach the handler. Size capability data by its header version,
perf and scheduler attributes, file handles and mount requests by their
own size fields, and landlock rules by rule type. Keep the translated
prefix of a message batch, read headers that span separate backings one
by one, write results back through the current guest mapping, and stop
counting messages whose length cannot be stored. Revisit an entry moved
into an earlier slot while merging regions. Give newer syscalls
fallback numbers in the test harness.
2026-12-04 08:32:56 -05:00
maxjivi05 9116ad8e84 Translate fixed-size, string and in-array guest pointers in high memory
Give every syscall pointer without a length a fixed x86-64 size, a
length read through another argument, or a terminator scan for strings,
so spans crossing separately backed regions are refused before the
kernel sees them. Size message queue buffers as the type word plus
msgsz. Translate io_submit control blocks and their buffers, including
vectored reads and writes, through bounded host copies, restore the
guest words afterwards, and report guest iocb addresses back from
io_getevents. Translate move_pages page lists for the calling process
and futex_waitv addresses. Merge new mappings with matching neighbours.
2026-12-04 07:48:38 -05:00
maxjivi05 91957ca9b0 Merge high regions after protection changes and translate message batches
Protect now merges neighbouring high regions whose guest and host
ranges touch and whose protection and code state match, so toggling
page protections no longer fills the region table.

Exclusive loads on high memory accept write-only pages and exclusive
stores need only PROT_WRITE, matching x86-64 where writable pages are
readable.

sendmmsg and recvmmsg translate the name, control and io vectors of
every message in the batch, return msg_len for each processed message
and the received header fields for recvmmsg.

Counted arrays passed to getgroups, setgroups, semop, semtimedop,
io_submit, io_getevents, io_pgetevents, move_pages, futex_waitv and
listmount are now checked to stay within one host range. The unused
ToHost helper is removed.
2026-12-04 07:22:48 -05:00
maxjivi05 8090c6ed04 Allow syscalls for a forwarded prctl while dispatch blocks
The prctl wrapper issues its syscall from the preload's own text, so a
thread whose selector blocks got SIGSYS where the plain libc call would
have been dispatched the same way by the caller's own rules. Allow
syscalls for the forwarded call and restore the selector afterwards.

The dispatch test now waits until the selector blocks before it sends
the trim request, and checks a prctl call made while it blocks.
2026-12-04 05:54:40 -05:00
maxjivi05 e42ab05872 Serve memory trim requests while syscall user dispatch blocks
A thread that runs with syscall user dispatch on and its selector set to
block (as x86-64 Wine does while in Windows code) took the trim signal
with the selector still blocking. Every raw syscall the handler made was
then dispatched to the program's SIGSYS handler, which either deadlocked
the thread or killed the process when SIGSYS was blocked, so the session
saw it as a deaf process and the game stalled during loading.

Track the selector each thread registers through prctl, allow syscalls
for the length of the handler and restore the selector before returning.
2026-12-04 04:30:37 -05:00
maxjivi05 7e662ddedf Refuse a high unmap when failed host unmaps could not all be retained
UnmapLocked counts the overlapping regions before it changes anything and returns ENOMEM when the retired list could not hold all of them, so a host range is never dropped from tracking while still mapped.
2026-12-04 02:05:27 -05:00
maxjivi05 95810c4c88 Size counted guest buffers by element and keep exclusive access within guest protection
poll, ppoll, epoll waits, mmsg calls and select bitmaps now translate the whole array their count describes, so a buffer that crosses into an unrelated host range fails with EFAULT and oversized counts cannot wrap. High regions remember their protection through mprotect, splitting at the range edges, and exclusive stores to read-only pages or loads from inaccessible pages reach the guest as a fault instead of being emulated.
2026-12-04 02:04:28 -05:00
maxjivi05 7217dcc99a Emulate exclusive pairs on high guest memory and release failed host unmaps later 2026-12-03 22:09:12 -05:00
maxjivi05 46e36d95a3 Add an end-to-end probe for guest memory above the host address limit 2026-12-03 21:28:02 -05:00
maxjivi05 15b5d46f70 Reject wrapping lengths and drop stale code on discarded high memory
A nonzero length that wraps when page-aligned now fails madvise with
EINVAL and mprotect with ENOMEM, as on Linux. Discarding advice on
high memory invalidates translated code for the range whenever advice
reached any region.
2026-12-03 21:04:10 -05:00
maxjivi05 7ce0b702bb Claim high guest memory only with LSE atomics and invalidate every code alias
High guest mappings are claimed only when the JIT emits LSE atomics, and
exclusive load/store instructions are never single-stepped, so an atomic
on high memory cannot spin. A store into high code invalidates every
mirror of the written page through the tracked mapping. madvise and
mprotect on high memory apply to each region at its own host address.
2026-12-03 20:46:45 -05:00
maxjivi05 078bd56dd0 Translate only pointer syscall arguments into high guest memory
Pointer arguments are now picked from a per-syscall layout table, so
scalar values such as a truncate length are never rewritten. Sized
buffers must map to one contiguous host range or the call fails with
EFAULT, and new host backings are placed next to their guest
neighbours so adjacent mappings stay contiguous. readv, writev and the
preadv/pwritev family, sendmsg and recvmsg get a host-side copy of
their iovec and msghdr with translated bases, leaving the guest copies
untouched. Code invalidation for kernel writes maps the host buffer
back to its guest address, and an unmap checks the table before it
changes any host mapping.
2026-12-03 20:27:36 -05:00
maxjivi05 1ff0ce1421 Leave MAP_FIXED_NOREPLACE above the host limit to the host
Wine finds the top of the address space with MAP_FIXED_NOREPLACE probes.
Claiming those probes above a 39-bit host limit made Wine place its stacks
in relocated memory, and every wineserver request then failed with EFAULT
because the iovec buffers it passes to writev are nested pointers that are
not translated. Only MAP_FIXED requests are relocated again, so the probes
see the real host limit while fixed mappings above it keep working.
2026-12-03 19:55:32 -05:00
maxjivi05 25ac3830f2 Update FEX before deciding anti-cheat routing
A device on an older FEX build never went through droiddeck-fex on the
ARM64 path, so the catalog FEX was never installed and the gate kept
anti-cheat games on ARM64 forever. dd_anticheat now runs the new
droiddeck-fex update action first, which installs the catalog build
under the same lock and retry window as other FEX launches.
2026-12-03 18:00:49 -05:00
maxjivi05 d3349f848f Route anti-cheat games to x86-64 Proton only on a capable FEX
The FEX build now lists its patches in share/fex-emu/.droiddeck-patches.
Anti-cheat routing needs the fixed guest memory patch in that list and
otherwise keeps the launch on ARM64, as an older FEX cannot map the
anti-cheat helper buffer above the host address limit. Installing a FEX
build without the list removes a list left by an earlier build.
2026-12-03 17:10:14 -05:00
maxjivi05 274a9c0d2d Keep a requested x86-64 default and accept linked anti-cheat runtimes
A request for the current automatic x86-64 default now marks it as the
app's choice, so the next settle no longer moves it back to ARM64.
Anti-cheat runtime discovery follows a symlinked runtime directory.
2026-12-03 17:08:21 -05:00
maxjivi05 f1641f2ffe Keep high guest mappings intact when a fixed map or unmap fails
Check room in the region table, splits included, before a fixed map or
unmap removes anything, return the host munmap error without touching
the table entry, and keep write-protecting low shared aliases of
executable ranges that sit above the host address limit.
2026-12-03 17:07:16 -05:00
maxjivi05 cc8bb7b0a8 Keep x86-64 Proton builds out of the automatic default tool 2026-12-03 16:17:30 -05:00
maxjivi05 17c0af445e Check the driver query is answered before each wrapper's call sites 2026-12-03 15:29:10 -05:00
maxjivi05 19b4844998 Check anti-cheat runtime bridges, apply component choices under FEX and honour MAP_FIXED_NOREPLACE above the host limit 2026-12-03 14:22:49 -05:00
maxjivi05 b1fe206215 test(game-env): build the adopted-tool wrapper through extra_wrapper_sh 2026-12-03 14:02:14 -05:00
maxjivi05 19613e6842 Keep anti-cheat games on a tool the user chose instead of moving them to x86-64 2026-12-03 13:01:38 -05:00
maxjivi05 0756e93b8e README: match the StonkGuy credit to the renumbered FEX patches 2026-12-03 13:01:38 -05:00
maxjivi05 98df621d9c Docs: describe the anti-cheat signal mask fix and the container procfs view 2026-12-03 13:01:38 -05:00
maxjivi05 ee432f444d Test the container procfs view of FEX's emulated mount tables 2026-12-03 13:01:38 -05:00
maxjivi05 58fe8bb197 FEX: order the anti-cheat series after the guest stack patch from main 2026-12-03 13:01:38 -05:00
maxjivi05 20e3e9a802 FEX: describe the container's procfs in emulated mount tables 2026-12-03 13:01:38 -05:00
maxjivi05 7648b9ae8f FEX: show the guest command line when the argument area cannot be remapped 2026-12-03 13:01:38 -05:00
maxjivi05 e16a77facb droiddeck-fex: take the runtime from an adopted tool's original manifest 2026-12-03 13:01:38 -05:00
maxjivi05 f802206917 Keep x86-64 DroidDeck-Proton builds out of the ARM64 tool list 2026-12-03 13:01:38 -05:00
maxjivi05 b11bac2539 Run games with anti-cheat files on an x86-64 DroidDeck-Proton under FEX
The Proton launchers look for Easy Anti-Cheat or BattlEye bridge files in
the game folder and, when an x86-64 DroidDeck-Proton and the matching Proton
runtime are installed, hand the launch to that Proton under FEX with the
game's own prefix. Picking the x86-64 tool directly also runs it under FEX.
DROIDDECK_ANTICHEAT=off keeps a game on ARM64.
2026-12-03 13:01:38 -05:00
maxjivi05 6a3cee3ee0 FEX: serve decoder reads from fixed guest memory above the host limit 2026-12-03 13:01:38 -05:00
maxjivi05andStonkGuy c113948dd3 FEX: map fixed guest memory above a small host address space
Co-authored-by: StonkGuy <StonkGuy@users.noreply.github.com>
2026-12-03 13:01:38 -05:00
maxjivi05 a7f3c69987 FEX: serve emulated proc files by the requested path when the host returns a memfd 2026-12-03 13:01:38 -05:00
maxjivi05 b399683502 FEX: open guest paths with the raw openat system call so host preloads cannot replace the file 2026-12-03 13:01:38 -05:00
maxjivi05andStonkGuy 57a6224fcf Credit StonkGuy in the FEX anti-cheat patches and README
Co-authored-by: StonkGuy <68372320+StonkGuy@users.noreply.github.com>
2026-12-03 13:01:38 -05:00
maxjivi05 8bdc6485c8 FEX: hand a traced program's ptrace state across exec 2026-12-03 13:01:38 -05:00