From fcbbe87ddea0cc3d84360dc03850e48027a1a252 Mon Sep 17 00:00:00 2001 From: The412Banner Date: Sat, 26 Sep 2026 17:30:30 -0400 Subject: [PATCH] shadPS4: tolerate guard holes in FEX mapping checks; cache CI builds Need for Speed Hot Pursuit Remastered stopped when a game thread's destructors ran: the FEX engine's pre-flight check read /proc/self/maps and required every page of the thread's writable range to be host- writable, but the game keeps a PROT_NONE guard hole inside it ("host_permissions=---p", "pthread thread dtors failed at stage 1: 13"). Skip such holes; read-only or W+X pages still fail the check. The build now compiles through ccache and keeps apt's downloads, both in the workspace and carried between runs with actions/cache, so a rebuild with the same pin recompiles only what a patch touched. --- .github/workflows/build-shadps4.yml | 14 ++++++++++++++ tools/shadps4/build-in-debian.sh | 17 ++++++++++++++++- .../0004-fex-mapping-allow-guard-holes.patch | 16 ++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tools/shadps4/patches/0004-fex-mapping-allow-guard-holes.patch diff --git a/.github/workflows/build-shadps4.yml b/.github/workflows/build-shadps4.yml index e74132e7e8..7fb598e2db 100644 --- a/.github/workflows/build-shadps4.yml +++ b/.github/workflows/build-shadps4.yml @@ -25,6 +25,20 @@ jobs: timeout-minutes: 150 steps: - uses: actions/checkout@v4 + # Compiler and package caches carried between runs; a run with the same pin and patches + # recompiles only what changed. + - uses: actions/cache@v4 + with: + path: .ccache + key: shadps4-ccache-${{ hashFiles('tools/shadps4/source.env') }}-${{ github.run_id }} + restore-keys: | + shadps4-ccache-${{ hashFiles('tools/shadps4/source.env') }}- + shadps4-ccache- + - uses: actions/cache@v4 + with: + path: .apt-cache + key: shadps4-apt-${{ hashFiles('tools/shadps4/build-in-debian.sh') }} + restore-keys: shadps4-apt- - name: Build in Debian trixie run: | set -euo pipefail diff --git a/tools/shadps4/build-in-debian.sh b/tools/shadps4/build-in-debian.sh index 5388bbeebf..c90edf96c3 100755 --- a/tools/shadps4/build-in-debian.sh +++ b/tools/shadps4/build-in-debian.sh @@ -10,13 +10,21 @@ cd "$WORK" . tools/shadps4/source.env export DEBIAN_FRONTEND=noninteractive +# Downloaded packages are kept in the workspace (.apt-cache), which the workflow caches between +# runs; the image's docker-clean hook would otherwise delete them after every install. +rm -f /etc/apt/apt.conf.d/docker-clean +mkdir -p "$WORK/.apt-cache/archives/partial" +cat > /etc/apt/apt.conf.d/99droiddeck-cache <<'APT' +Dir::Cache::archives "/work/.apt-cache/archives"; +Binary::apt::APT::Keep-Downloaded-Packages "true"; +APT dpkg --add-architecture arm64 apt-get update # The Bachata runtime's cross set, plus PulseAudio and ALSA headers so SDL3 builds its audio # drivers (it loads them at run time; the runtime plays through PulseAudio), and the Wayland, EGL # and xkbcommon headers with the host's wayland-scanner so it builds its Wayland video driver. apt-get install -y --no-install-recommends \ - ca-certificates git curl xz-utils zstd file pkg-config dpkg-dev squashfs-tools \ + ca-certificates git curl xz-utils zstd file pkg-config dpkg-dev squashfs-tools ccache \ cmake ninja-build clang llvm lld gcc g++ make \ gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu \ python3 nodejs \ @@ -45,7 +53,14 @@ done # only through it, and without it builds ALSA alone. export PKG_CONFIG_LIBDIR=/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig pkg-config --modversion libpulse +# Every CMake project the build configures (FEXCore, shadPS4 and its externals) compiles through +# ccache; the cache lives in the workspace (.ccache) and the workflow keeps it between runs. +export CCACHE_DIR=$WORK/.ccache CCACHE_BASEDIR=$WORK CCACHE_NOHASHDIR=1 \ + CCACHE_COMPILERCHECK=content CCACHE_MAXSIZE=4G \ + CMAKE_C_COMPILER_LAUNCHER=ccache CMAKE_CXX_COMPILER_LAUNCHER=ccache +ccache -z bash "$SRC/runtime/scripts/build-shadps4-arm64.sh" +ccache -s BIN=$SRC/runtime/build/shadps4-arm64-stage/bin/shadps4-arm64 test -x "$BIN" cat "$SRC/runtime/build/shadps4-arm64-stage/needed.txt" diff --git a/tools/shadps4/patches/0004-fex-mapping-allow-guard-holes.patch b/tools/shadps4/patches/0004-fex-mapping-allow-guard-holes.patch new file mode 100644 index 0000000000..268ebc67f3 --- /dev/null +++ b/tools/shadps4/patches/0004-fex-mapping-allow-guard-holes.patch @@ -0,0 +1,16 @@ +diff --git a/src/core/fex/fex_guest_engine.cpp b/src/core/fex/fex_guest_engine.cpp +index 2271f97..71ddc6d 100644 +--- a/src/core/fex/fex_guest_engine.cpp ++++ b/src/core/fex/fex_guest_engine.cpp +@@ -182,7 +182,10 @@ EngineResult ValidateHostMapping(const GuestExecutionRange& range) { + static_cast(begin), static_cast(end), permissions); + return Failure(EngineStage::Mapping, EACCES); + } +- if (range.Writable && (permissions[1] != 'w' || permissions[2] == 'x')) { ++ // A guard hole the guest protected itself (PROT_NONE, "---p") inside a writable range is ++ // the game's own doing, like a stack guard page; FEX never writes there on its behalf. ++ const bool guardHole = permissions[0] == '-' && permissions[1] == '-' && permissions[2] == '-'; ++ if (range.Writable && !guardHole && (permissions[1] != 'w' || permissions[2] == 'x')) { + std::fprintf(stderr, + "BACHATA_FEX_MAPPING_FAIL reason=host_write_permission error=%d begin=%#lx " + "size=%#lx executable=%d writable=%d host_begin=%#lx host_end=%#lx "