mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 13:55:58 +00:00
fix: validate the CASP pair on a mismatch in the LSE emulator
This commit is contained in:
1 parent
ffac895afc
commit
0db9865045
6 files changed
+54
-18
No files matched your search
@@ -1,9 +1,10 @@
|
||||
# LSE-Emu
|
||||
|
||||
`lse_emu.c` is a copy of [SildurFX/LSE-Emu](https://github.com/SildurFX/LSE-Emu) at commit
|
||||
`8bc9548ac6fd24a8d506b266b17ba8d0e71a9b01` (GPL-3.0-or-later) with one fix: the patched stub
|
||||
for `LDSMAX`/`LDSMIN`/`LDUMAX`/`LDUMIN` saves and restores NZCV around its `cmp`/`csel`, since
|
||||
the real instructions leave the flags alone. Carry that fix forward until upstream has it.
|
||||
`8bc9548ac6fd24a8d506b266b17ba8d0e71a9b01` (GPL-3.0-or-later) with two fixes, listed in
|
||||
`docs/arm-v8.0-steam-client.md` under "Fixes over upstream": NZCV kept across the min/max
|
||||
stubs, and a store-back on `CASP` mismatches so the returned pair is atomic. Carry them forward
|
||||
until upstream has them.
|
||||
|
||||
It is an `LD_PRELOAD` library that emulates the ARMv8.1 LSE atomic instructions (and `LDAPR`)
|
||||
on ARMv8.0 CPUs. A SIGILL handler performs each trapped instruction with an LL/SC loop. With
|
||||
|
||||
@@ -90,7 +90,10 @@ static void casp128(void *p, uint64_t *o0, uint64_t *o1,
|
||||
" cbnz %2, 2f\n"
|
||||
" stlxp %w2, %9, %10, [%6]\n"
|
||||
" cbnz %w2, 1b\n"
|
||||
"2: clrex\n"
|
||||
" b 3f\n"
|
||||
"2: stlxp %w2, %0, %1, [%6]\n" // a 128-bit ldxp is only single-copy atomic once a stxp succeeds
|
||||
" cbnz %w2, 1b\n"
|
||||
"3:\n"
|
||||
: "=&r"(a), "=&r"(b), "=&r"(t), "=&r"(s)
|
||||
: "0"(0), "1"(0), "r"(p), "r"(e0), "r"(e1), "r"(d0), "r"(d1)
|
||||
: "memory", "cc");
|
||||
@@ -180,7 +183,7 @@ static uint32_t alu(unsigned op, unsigned d, unsigned n, unsigned m) {
|
||||
return base[op] | (m << 16) | (n << 5) | d; // add, bic, eor, orr
|
||||
}
|
||||
|
||||
// CASP{A}{L} Xs,Xs+1,Xt,Xt+1,[Xn] (64-bit pair): ldxp/ldaxp + compare + stxp/stlxp. Four scratch registers, no flag changes, 15 words.
|
||||
// CASP{A}{L} Xs,Xs+1,Xt,Xt+1,[Xn] (64-bit pair): ldxp/ldaxp + compare + stxp/stlxp. Four scratch registers, no flag changes, 16 words.
|
||||
static int gen_casp(uint32_t *w, uintptr_t stub, uintptr_t ret, unsigned sz,
|
||||
unsigned rs, unsigned rt, unsigned rn, unsigned acq, unsigned rel) {
|
||||
// sz 1: 64-bit pair (LDXP x), sz 0: 32-bit pair (LDXP w, 8-byte aligned)
|
||||
@@ -198,10 +201,11 @@ static int gen_casp(uint32_t *w, uintptr_t stub, uintptr_t ret, unsigned sz,
|
||||
W(EOR | (rs << 16) | (t0 << 5) | t2); // eor t2,t0,rs
|
||||
W(EOR | ((rs + 1) << 16) | (t1 << 5) | t3); // eor t3,t1,rs+1
|
||||
W(ORR | (t3 << 16) | (t2 << 5) | t2); // orr t2,t2,t3
|
||||
W(0xB5000000u | (3u << 5) | t2); // cbnz t2, clrex (+3)
|
||||
W(STXP | (t2 << 16) | (rel << 15) | ((rt + 1) << 10) | (rn << 5) | rt); // stxp/stlxp w(t2),rt,rt+1,[rn]
|
||||
W(0x35000000u | (((unsigned)(loop - n) & 0x7FFFF) << 5) | t2); // cbnz w(t2), loop
|
||||
W(0xD5033F5Fu); // clrex
|
||||
W(0xB4000000u | (3u << 5) | t2); // cbz t2, match (+3)
|
||||
W(STXP | (t2 << 16) | (rel << 15) | (t1 << 10) | (rn << 5) | t0); // mismatch: store the loaded pair back, which validates it
|
||||
W(0x14000002u); // b check (+2)
|
||||
W(STXP | (t2 << 16) | (rel << 15) | ((rt + 1) << 10) | (rn << 5) | rt); // match: stxp/stlxp w(t2),rt,rt+1,[rn]
|
||||
W(0x35000000u | (((unsigned)(loop - n) & 0x7FFFF) << 5) | t2); // check: cbnz w(t2), loop
|
||||
W(MOVX(rs, t0));
|
||||
W(MOVX(rs + 1, t1));
|
||||
W(0xA9410000u | (t3 << 10) | (31u << 5) | t2); // ldp t2,t3,[sp,#16]
|
||||
|
||||
@@ -12,7 +12,7 @@ if [ "${BL_RAISE_NOFILE:-0}" = 1 ] && [ -z "${BL_INSIDE:-}" ]; then
|
||||
fi
|
||||
export HOME=${HOME:-/root}
|
||||
if grep -qs '/liblse_emu\.so$' /etc/ld.so.preload; then
|
||||
export LSE_EMU=1 LSE_EMU_PATCH=1
|
||||
export LSE_EMU=1 LSE_EMU_PATCH=${LSE_EMU_PATCH:-1}
|
||||
[ -n "${BL_DEBUG_DIR:-}" ] && export LSE_EMU_LOG=${LSE_EMU_LOG:-$BL_DEBUG_DIR/lse_emu.log}
|
||||
fi
|
||||
mode=${1:-desktop}
|
||||
|
||||
Reference in new issue
Block a user