Skip to content

Commit b9cb593

Browse files
fix(ci): patch ksud for legacy uapi zero
1 parent 6793676 commit b9cb593

4 files changed

Lines changed: 80 additions & 0 deletions

File tree

.github/actions/prepare-abk-app-inputs/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ runs:
5858
[ -f .github/workflows/build-abk-app.yml ] && sha256sum .github/workflows/build-abk-app.yml
5959
[ -f .github/workflows/build-abk-app-dev.yml ] && sha256sum .github/workflows/build-abk-app-dev.yml
6060
[ -f .github/actions/prepare-abk-app-inputs/action.yml ] && sha256sum .github/actions/prepare-abk-app-inputs/action.yml
61+
[ -f .github/scripts/patch-ksud-uapi-compat.py ] && sha256sum .github/scripts/patch-ksud-uapi-compat.py
6162
} | sha256sum | awk '{print $1}'
6263
)"
6364
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python3
2+
from __future__ import annotations
3+
4+
import pathlib
5+
import sys
6+
7+
8+
MARKER = "ABK legacy uapi=0 compatibility"
9+
10+
ORIGINAL = """pub fn ensure_uapi_version_matched() -> anyhow::Result<()> {
11+
let kernel_uapi = get_info().uapi_version;
12+
let userspace_uapi = uapi_version();
13+
if kernel_uapi != userspace_uapi {
14+
bail!(
15+
"UAPI version mismatch: kernel={kernel_uapi}, ksud={userspace_uapi}. Please update KernelSU!"
16+
);
17+
}
18+
Ok(())
19+
}
20+
"""
21+
22+
PATCHED = f"""pub fn ensure_uapi_version_matched() -> anyhow::Result<()> {{
23+
let kernel_uapi = get_info().uapi_version;
24+
let userspace_uapi = uapi_version();
25+
if kernel_uapi == 0 {{
26+
eprintln!(
27+
"[ABK] {MARKER}: kernel reports legacy uapi=0, continue with userspace uapi={{userspace_uapi}}"
28+
);
29+
return Ok(());
30+
}}
31+
if kernel_uapi != userspace_uapi {{
32+
bail!(
33+
"UAPI version mismatch: kernel={{kernel_uapi}}, ksud={{userspace_uapi}}. Please update KernelSU!"
34+
);
35+
}}
36+
Ok(())
37+
}}
38+
"""
39+
40+
41+
def main() -> int:
42+
if len(sys.argv) != 2:
43+
print("usage: patch-ksud-uapi-compat.py <sukisu-source-dir>", file=sys.stderr)
44+
return 2
45+
46+
source_dir = pathlib.Path(sys.argv[1]).resolve()
47+
target = source_dir / "userspace" / "ksud" / "src" / "ksucalls.rs"
48+
if not target.is_file():
49+
print(f"::error::{target} not found", file=sys.stderr)
50+
return 1
51+
52+
text = target.read_text(encoding="utf-8")
53+
if MARKER in text:
54+
print(f"ksud uapi compat patch already present: {target}")
55+
return 0
56+
57+
if ORIGINAL not in text:
58+
print(f"::error::expected ensure_uapi_version_matched block not found in {target}", file=sys.stderr)
59+
return 1
60+
61+
target.write_text(text.replace(ORIGINAL, PATCHED), encoding="utf-8")
62+
print(f"patched ksud legacy uapi compatibility: {target}")
63+
return 0
64+
65+
66+
if __name__ == "__main__":
67+
raise SystemExit(main())

.github/workflows/build-abk-app-dev.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
- "gradle/**"
1212
- ".github/workflows/build-abk-app-dev.yml"
1313
- ".github/actions/prepare-abk-app-inputs/**"
14+
- ".github/scripts/patch-ksud-uapi-compat.py"
1415
pull_request:
1516
paths:
1617
- "app/**"
@@ -20,6 +21,7 @@ on:
2021
- "gradle/**"
2122
- ".github/workflows/build-abk-app-dev.yml"
2223
- ".github/actions/prepare-abk-app-inputs/**"
24+
- ".github/scripts/patch-ksud-uapi-compat.py"
2325

2426
jobs:
2527
build:
@@ -137,6 +139,8 @@ jobs:
137139
rm -rf "$source_dir" "$target_dir" "$jni_target_dir"
138140
git clone --depth 1 --branch "$SUKISU_ULTRA_REF" "$SUKISU_ULTRA_REPO" "$source_dir"
139141
commit="$(git -C "$source_dir" rev-parse HEAD)"
142+
python3 .github/scripts/patch-ksud-uapi-compat.py "$source_dir"
143+
grep -q "ABK legacy uapi=0 compatibility" "$source_dir/userspace/ksud/src/ksucalls.rs"
140144
mkdir -p "$target_dir" "$jni_target_dir"
141145
142146
setup_rust_build() {
@@ -237,6 +241,7 @@ jobs:
237241
echo "ref=$SUKISU_ULTRA_REF"
238242
echo "commit=$commit"
239243
echo "abis=$SUKISU_KSUD_ABIS"
244+
echo "patches=legacy_uapi_zero_compat"
240245
echo "built_by=.github/workflows/build-abk-app-dev.yml"
241246
} > "$target_dir/source.properties"
242247
@@ -310,6 +315,7 @@ jobs:
310315
echo "- ABIs: $SUKISU_KSUD_ABIS"
311316
echo "- Embedded ksuinit: aarch64-unknown-linux-musl, x86_64-unknown-linux-musl"
312317
echo "- magiskboot: removed upstream (ksud uses bootimg crate)"
318+
echo "- Patch: allow legacy kernel uapi=0 for bundled ksud"
313319
} >> "$GITHUB_STEP_SUMMARY"
314320
315321
- name: Cache LKM assets

.github/workflows/build-abk-app.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
- "gradle/**"
1212
- ".github/workflows/build-abk-app.yml"
1313
- ".github/actions/prepare-abk-app-inputs/**"
14+
- ".github/scripts/patch-ksud-uapi-compat.py"
1415
pull_request:
1516
paths:
1617
- "app/**"
@@ -20,6 +21,7 @@ on:
2021
- "gradle/**"
2122
- ".github/workflows/build-abk-app.yml"
2223
- ".github/actions/prepare-abk-app-inputs/**"
24+
- ".github/scripts/patch-ksud-uapi-compat.py"
2325

2426
jobs:
2527
build:
@@ -137,6 +139,8 @@ jobs:
137139
rm -rf "$source_dir" "$target_dir" "$jni_target_dir"
138140
git clone --depth 1 --branch "$SUKISU_ULTRA_REF" "$SUKISU_ULTRA_REPO" "$source_dir"
139141
commit="$(git -C "$source_dir" rev-parse HEAD)"
142+
python3 .github/scripts/patch-ksud-uapi-compat.py "$source_dir"
143+
grep -q "ABK legacy uapi=0 compatibility" "$source_dir/userspace/ksud/src/ksucalls.rs"
140144
mkdir -p "$target_dir" "$jni_target_dir"
141145
142146
setup_rust_build() {
@@ -237,6 +241,7 @@ jobs:
237241
echo "ref=$SUKISU_ULTRA_REF"
238242
echo "commit=$commit"
239243
echo "abis=$SUKISU_KSUD_ABIS"
244+
echo "patches=legacy_uapi_zero_compat"
240245
echo "built_by=.github/workflows/build-abk-app.yml"
241246
} > "$target_dir/source.properties"
242247
@@ -310,6 +315,7 @@ jobs:
310315
echo "- ABIs: $SUKISU_KSUD_ABIS"
311316
echo "- Embedded ksuinit: aarch64-unknown-linux-musl, x86_64-unknown-linux-musl"
312317
echo "- magiskboot: removed upstream (ksud uses bootimg crate)"
318+
echo "- Patch: allow legacy kernel uapi=0 for bundled ksud"
313319
} >> "$GITHUB_STEP_SUMMARY"
314320
315321
- name: Cache LKM assets

0 commit comments

Comments
 (0)