From c863ff6f4981e1d507f375f53349f6a057a39ec3 Mon Sep 17 00:00:00 2001 From: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> Date: Tue, 4 Nov 2025 19:28:13 +0800 Subject: [PATCH] ci: Attempting once more to build the LKM using the DDK --- .github/workflows/build-gki-image.yml | 37 ++++++ .github/workflows/build-kernel-a12.yml | 112 +++++++++++++++++ .github/workflows/build-kernel-a13.yml | 147 +++++++++++++++++++++++ .github/workflows/build-kernel-a14.yml | 159 +++++++++++++++++++++++++ .github/workflows/build-kernel-a15.yml | 132 ++++++++++++++++++++ .github/workflows/build-kernel-a16.yml | 105 ++++++++++++++++ .github/workflows/build-lkm.yml | 79 ++---------- .github/workflows/build-manager.yml | 78 +----------- .github/workflows/clippy.yml | 2 +- .github/workflows/ddk-lkm.yml | 53 +++++++++ .github/workflows/deploy-website.yml | 67 +++++++++++ .github/workflows/gki-kernel-mock.yml | 79 ------------ .github/workflows/gki-kernel.yml | 8 +- .github/workflows/ksud.yml | 27 +---- .github/workflows/shellcheck.yml | 2 +- .gitignore | 1 - .vscode/settings.json | 5 + kernel/.vscode/c_cpp_properties.json | 11 ++ kernel/.vscode/generate_compdb.py | 92 ++++++++++++++ kernel/.vscode/settings.json | 35 ++++++ kernel/.vscode/tasks.json | 16 +++ kernel/Kconfig | 3 - kernel/Makefile | 19 ++- kernel/core_hook.c | 2 +- kernel/kernel_compat.h | 8 ++ kernel/ksu.c | 5 +- kernel/ksud.c | 18 +-- kernel/sucompat.c | 18 +-- 28 files changed, 1046 insertions(+), 274 deletions(-) create mode 100644 .github/workflows/build-gki-image.yml create mode 100644 .github/workflows/build-kernel-a12.yml create mode 100644 .github/workflows/build-kernel-a13.yml create mode 100644 .github/workflows/build-kernel-a14.yml create mode 100644 .github/workflows/build-kernel-a15.yml create mode 100644 .github/workflows/build-kernel-a16.yml create mode 100644 .github/workflows/ddk-lkm.yml create mode 100644 .github/workflows/deploy-website.yml delete mode 100644 .github/workflows/gki-kernel-mock.yml create mode 100644 .vscode/settings.json create mode 100644 kernel/.vscode/c_cpp_properties.json create mode 100644 kernel/.vscode/generate_compdb.py create mode 100644 kernel/.vscode/settings.json create mode 100644 kernel/.vscode/tasks.json diff --git a/.github/workflows/build-gki-image.yml b/.github/workflows/build-gki-image.yml new file mode 100644 index 00000000..065022cb --- /dev/null +++ b/.github/workflows/build-gki-image.yml @@ -0,0 +1,37 @@ +name: Build Android GKI Image +on: + workflow_call: + workflow_dispatch: + inputs: + debug: + description: 'Build debug kernel' + required: false + type: boolean + default: false + +jobs: + build-a12-kernel: + uses: ./.github/workflows/build-kernel-a12.yml + secrets: inherit + with: + debug: ${{ github.event.inputs.debug || false }} + build-a13-kernel: + uses: ./.github/workflows/build-kernel-a13.yml + secrets: inherit + with: + debug: ${{ github.event.inputs.debug || false }} + build-a14-kernel: + uses: ./.github/workflows/build-kernel-a14.yml + secrets: inherit + with: + debug: ${{ github.event.inputs.debug || false }} + build-a15-kernel: + uses: ./.github/workflows/build-kernel-a15.yml + secrets: inherit + with: + debug: ${{ github.event.inputs.debug || false }} + build-a16-kernel: + uses: ./.github/workflows/build-kernel-a16.yml + secrets: inherit + with: + debug: ${{ github.event.inputs.debug || false }} diff --git a/.github/workflows/build-kernel-a12.yml b/.github/workflows/build-kernel-a12.yml new file mode 100644 index 00000000..7dc6c00e --- /dev/null +++ b/.github/workflows/build-kernel-a12.yml @@ -0,0 +1,112 @@ +name: Build Kernel - Android 12 +on: + # push: + # branches: ["main", "ci", "checkci"] + # paths: + # - ".github/workflows/deps/gki/build-kernel-a12.yml" + # - ".github/workflows/deps/gki/gki-kernel.yml" + # - ".github/scripts/build_a12.sh" + # - "kernel/**" + workflow_call: + inputs: + debug: + description: 'Build debug kernel' + required: false + type: boolean + default: false +jobs: + build-kernel: + if: github.event_name != 'pull_request' && github.ref != 'refs/heads/checkci' + strategy: + matrix: + include: + - sub_level: 209 + os_patch_level: 2024-05 + - sub_level: 218 + os_patch_level: 2024-08 + - sub_level: 226 + os_patch_level: 2024-11 + - sub_level: 233 + os_patch_level: 2025-02 + - sub_level: 236 + os_patch_level: 2025-05 + uses: ./.github/workflows/gki-kernel.yml + secrets: inherit + with: + version: android12-5.10 + version_name: android12-5.10.${{ matrix.sub_level }} + tag: android12-5.10-${{ matrix.os_patch_level }} + os_patch_level: ${{ matrix.os_patch_level }} + patch_path: "5.10" + debug: ${{ inputs.debug || false }} + + upload-artifacts: + needs: build-kernel + runs-on: ubuntu-latest + if: ${{ ( github.event_name != 'pull_request' && github.ref == 'refs/heads/main' ) || github.ref_type == 'tag' || github.ref == 'refs/heads/ci' }} + env: + CHAT_ID: ${{ secrets.CHAT_ID }} + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + MESSAGE_THREAD_ID: ${{ secrets.MESSAGE_THREAD_ID }} + COMMIT_MESSAGE: ${{ github.event.head_commit.message }} + COMMIT_URL: ${{ github.event.head_commit.url }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + + - uses: actions/checkout@v4 + with: + path: KernelSU + fetch-depth: 0 + + - name: List artifacts + run: | + tree + + - name: Download prebuilt toolchain + run: | + AOSP_MIRROR=https://android.googlesource.com + BRANCH=main-kernel-build-2024 + git clone $AOSP_MIRROR/platform/prebuilts/build-tools -b $BRANCH --depth 1 build-tools + git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools + git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 + pip3 install telethon + + - name: Set boot sign key + env: + BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }} + run: | + if [ ! -z "$BOOT_SIGN_KEY" ]; then + echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem + fi + + - name: Bot session cache + id: bot_session_cache + uses: actions/cache@v4 + if: false + with: + path: scripts/ksubot.session + key: ${{ runner.os }}-bot-session + + - name: Build boot images + run: | + export AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool + export GZIP=$GITHUB_WORKSPACE/build-tools/path/linux-x86/gzip + export LZ4=$GITHUB_WORKSPACE/build-tools/path/linux-x86/lz4 + export MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py + export UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py + cd $GITHUB_WORKSPACE/KernelSU + export VERSION=$(($(git rev-list --count HEAD) + 10200)) + echo "VERSION: $VERSION" + cd - + bash $GITHUB_WORKSPACE/KernelSU/.github/scripts/build_a12.sh + + - name: Display structure of boot files + run: ls -R + + - name: Upload images artifact + uses: actions/upload-artifact@v4 + with: + name: boot-images-android12 + path: Image-android12*/*.img.gz diff --git a/.github/workflows/build-kernel-a13.yml b/.github/workflows/build-kernel-a13.yml new file mode 100644 index 00000000..4a4ab1ac --- /dev/null +++ b/.github/workflows/build-kernel-a13.yml @@ -0,0 +1,147 @@ +name: Build Kernel - Android 13 +on: + # push: + # branches: ["main", "ci", "checkci"] + # paths: + # - ".github/workflows/deps/gki/build-kernel-a13.yml" + # - ".github/workflows/deps/gki/gki-kernel.yml" + # - ".github/scripts/build_a13.sh" + # - "kernel/**" + workflow_call: + inputs: + debug: + description: 'Build debug kernel' + required: false + type: boolean + default: false +jobs: + build-kernel: + if: github.event_name != 'pull_request' && github.ref != 'refs/heads/checkci' + strategy: + matrix: + include: + - version: "5.10" + sub_level: 209 + os_patch_level: 2024-05 + - version: "5.10" + sub_level: 210 + os_patch_level: 2024-06 + - version: "5.10" + sub_level: 214 + os_patch_level: 2024-07 + - version: "5.10" + sub_level: 218 + os_patch_level: 2024-08 + - version: "5.10" + sub_level: 223 + os_patch_level: 2024-11 + - version: "5.10" + sub_level: 228 + os_patch_level: 2025-01 + - version: "5.10" + sub_level: 234 + os_patch_level: 2025-03 + - version: "5.15" + sub_level: 148 + os_patch_level: 2024-05 + - version: "5.15" + sub_level: 149 + os_patch_level: 2024-07 + - version: "5.15" + sub_level: 151 + os_patch_level: 2024-08 + - version: "5.15" + sub_level: 153 + os_patch_level: 2024-09 + - version: "5.15" + sub_level: 167 + os_patch_level: 2024-11 + - version: "5.15" + sub_level: 178 + os_patch_level: 2024-11 + - version: "5.15" + sub_level: 170 + os_patch_level: 2025-01 + - version: "5.15" + sub_level: 178 + os_patch_level: 2025-03 + uses: ./.github/workflows/gki-kernel.yml + secrets: inherit + with: + version: android13-${{ matrix.version }} + version_name: android13-${{ matrix.version }}.${{ matrix.sub_level }} + tag: android13-${{ matrix.version }}-${{ matrix.os_patch_level }} + os_patch_level: ${{ matrix.os_patch_level }} + patch_path: ${{ matrix.version }} + debug: ${{ inputs.debug || false }} + + upload-artifacts: + needs: build-kernel + runs-on: ubuntu-latest + if: ${{ ( github.event_name != 'pull_request' && github.ref == 'refs/heads/main' ) || github.ref_type == 'tag' || github.ref == 'refs/heads/ci' }} + env: + CHAT_ID: ${{ secrets.CHAT_ID }} + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + MESSAGE_THREAD_ID: ${{ secrets.MESSAGE_THREAD_ID }} + COMMIT_MESSAGE: ${{ github.event.head_commit.message }} + COMMIT_URL: ${{ github.event.head_commit.url }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + + - uses: actions/checkout@v4 + with: + path: KernelSU + fetch-depth: 0 + + - name: List artifacts + run: | + tree + + - name: Download prebuilt toolchain + run: | + AOSP_MIRROR=https://android.googlesource.com + BRANCH=main-kernel-build-2024 + git clone $AOSP_MIRROR/platform/prebuilts/build-tools -b $BRANCH --depth 1 build-tools + git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools + git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 + pip3 install telethon + + - name: Set boot sign key + env: + BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }} + run: | + if [ ! -z "$BOOT_SIGN_KEY" ]; then + echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem + fi + + - name: Bot session cache + id: bot_session_cache + uses: actions/cache@v4 + if: false + with: + path: scripts/ksubot.session + key: ${{ runner.os }}-bot-session + + - name: Build boot images + run: | + export AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool + export GZIP=$GITHUB_WORKSPACE/build-tools/path/linux-x86/gzip + export LZ4=$GITHUB_WORKSPACE/build-tools/path/linux-x86/lz4 + export MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py + export UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py + cd $GITHUB_WORKSPACE/KernelSU + export VERSION=$(($(git rev-list --count HEAD) + 10200)) + echo "VERSION: $VERSION" + cd - + bash $GITHUB_WORKSPACE/KernelSU/.github/scripts/build_a13.sh + + - name: Display structure of boot files + run: ls -R + + - name: Upload images artifact + uses: actions/upload-artifact@v4 + with: + name: boot-images-android13 + path: Image-android13*/*.img.gz diff --git a/.github/workflows/build-kernel-a14.yml b/.github/workflows/build-kernel-a14.yml new file mode 100644 index 00000000..0c71b390 --- /dev/null +++ b/.github/workflows/build-kernel-a14.yml @@ -0,0 +1,159 @@ +name: Build Kernel - Android 14 +on: + # push: + # branches: ["main", "ci", "checkci"] + # paths: + # - ".github/workflows/deps/gki/build-kernel-a14.yml" + # - ".github/workflows/deps/gki/gki-kernel.yml" + # - ".github/scripts/build_a13.sh" + # - "kernel/**" + workflow_call: + inputs: + debug: + description: 'Build debug kernel' + required: false + type: boolean + default: false +jobs: + build-kernel: + if: github.event_name != 'pull_request' && github.ref != 'refs/heads/checkci' + strategy: + matrix: + include: + - version: "5.15" + sub_level: 148 + os_patch_level: 2024-05 + - version: "5.15" + sub_level: 149 + os_patch_level: 2024-06 + - version: "5.15" + sub_level: 153 + os_patch_level: 2024-07 + - version: "5.15" + sub_level: 158 + os_patch_level: 2024-08 + - version: "5.15" + sub_level: 164 + os_patch_level: 2024-09 + - version: "5.15" + sub_level: 167 + os_patch_level: 2024-11 + - version: "5.15" + sub_level: 170 + os_patch_level: 2025-01 + - version: "5.15" + sub_level: 178 + os_patch_level: 2025-03 + - version: "6.1" + sub_level: 75 + os_patch_level: 2024-05 + - version: "6.1" + sub_level: 78 + os_patch_level: 2024-06 + - version: "6.1" + sub_level: 84 + os_patch_level: 2024-07 + - version: "6.1" + sub_level: 90 + os_patch_level: 2024-08 + - version: "6.1" + sub_level: 93 + os_patch_level: 2024-09 + - version: "6.1" + sub_level: 99 + os_patch_level: 2024-10 + - version: "6.1" + sub_level: 112 + os_patch_level: 2024-11 + - version: "6.1" + sub_level: 115 + os_patch_level: 2024-12 + - version: "6.1" + sub_level: 118 + os_patch_level: 2025-01 + - version: "6.1" + sub_level: 128 + os_patch_level: 2025-03 + - version: "6.1" + sub_level: 134 + os_patch_level: 2025-05 + uses: ./.github/workflows/gki-kernel.yml + secrets: inherit + with: + version: android14-${{ matrix.version }} + version_name: android14-${{ matrix.version }}.${{ matrix.sub_level }} + tag: android14-${{ matrix.version }}-${{ matrix.os_patch_level }} + os_patch_level: ${{ matrix.os_patch_level }} + patch_path: ${{ matrix.version }} + debug: ${{ inputs.debug || false }} + + upload-artifacts: + needs: build-kernel + runs-on: ubuntu-latest + if: ${{ ( github.event_name != 'pull_request' && github.ref == 'refs/heads/main' ) || github.ref_type == 'tag' || github.ref == 'refs/heads/ci' }} + env: + CHAT_ID: ${{ secrets.CHAT_ID }} + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + MESSAGE_THREAD_ID: ${{ secrets.MESSAGE_THREAD_ID }} + COMMIT_MESSAGE: ${{ github.event.head_commit.message }} + COMMIT_URL: ${{ github.event.head_commit.url }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + + - uses: actions/checkout@v4 + with: + path: KernelSU + fetch-depth: 0 + + - name: List artifacts + run: | + tree + + - name: Download prebuilt toolchain + run: | + AOSP_MIRROR=https://android.googlesource.com + BRANCH=main-kernel-build-2024 + git clone $AOSP_MIRROR/platform/prebuilts/build-tools -b $BRANCH --depth 1 build-tools + git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools + git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 + pip3 install telethon + + - name: Set boot sign key + env: + BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }} + run: | + if [ ! -z "$BOOT_SIGN_KEY" ]; then + echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem + fi + + - name: Bot session cache + id: bot_session_cache + uses: actions/cache@v4 + if: false + with: + path: scripts/ksubot.session + key: ${{ runner.os }}-bot-session + + - name: Build boot images + run: | + export AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool + export GZIP=$GITHUB_WORKSPACE/build-tools/path/linux-x86/gzip + export LZ4=$GITHUB_WORKSPACE/build-tools/path/linux-x86/lz4 + export MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py + export UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py + cd $GITHUB_WORKSPACE/KernelSU + export VERSION=$(($(git rev-list --count HEAD) + 10200)) + echo "VERSION: $VERSION" + cd - + bash $GITHUB_WORKSPACE/KernelSU/.github/scripts/build_a13.sh + + - name: Display structure of boot files + run: ls -R + + - name: Upload images artifact + uses: actions/upload-artifact@v4 + with: + name: boot-images-android14 + path: Image-android14*/*.img.gz diff --git a/.github/workflows/build-kernel-a15.yml b/.github/workflows/build-kernel-a15.yml new file mode 100644 index 00000000..7f113e35 --- /dev/null +++ b/.github/workflows/build-kernel-a15.yml @@ -0,0 +1,132 @@ +name: Build Kernel - Android 15 +on: + # push: + # branches: ["main", "ci", "checkci"] + # paths: + # - ".github/workflows/deps/gki/build-kernel-a15.yml" + # - ".github/workflows/deps/gki/gki-kernel.yml" + # - ".github/scripts/build_a13.sh" + # - "kernel/**" + workflow_call: + inputs: + debug: + description: 'Build debug kernel' + required: false + type: boolean + default: false +jobs: + build-kernel: + if: github.event_name != 'pull_request' && github.ref != 'refs/heads/checkci' + strategy: + matrix: + include: + - version: "6.6" + sub_level: 30 + os_patch_level: 2024-08 + - version: "6.6" + sub_level: 46 + os_patch_level: 2024-09 + - version: "6.6" + sub_level: 50 + os_patch_level: 2024-10 + - version: "6.6" + sub_level: 56 + os_patch_level: 2024-11 + - version: "6.6" + sub_level: 57 + os_patch_level: 2024-12 + - version: "6.6" + sub_level: 58 + os_patch_level: 2025-01 + - version: "6.6" + sub_level: 66 + os_patch_level: 2025-02 + - version: "6.6" + sub_level: 77 + os_patch_level: 2025-03 + - version: "6.6" + sub_level: 82 + os_patch_level: 2025-04 + - version: "6.6" + sub_level: 87 + os_patch_level: 2025-05 + uses: ./.github/workflows/gki-kernel.yml + secrets: inherit + with: + version: android15-${{ matrix.version }} + version_name: android15-${{ matrix.version }}.${{ matrix.sub_level }} + tag: android15-${{ matrix.version }}-${{ matrix.os_patch_level }} + os_patch_level: ${{ matrix.os_patch_level }} + patch_path: ${{ matrix.version }} + debug: ${{ inputs.debug || false }} + + upload-artifacts: + needs: build-kernel + runs-on: ubuntu-latest + if: ${{ ( github.event_name != 'pull_request' && github.ref == 'refs/heads/main' ) || github.ref_type == 'tag' || github.ref == 'refs/heads/ci' }} + env: + CHAT_ID: ${{ secrets.CHAT_ID }} + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + MESSAGE_THREAD_ID: ${{ secrets.MESSAGE_THREAD_ID }} + COMMIT_MESSAGE: ${{ github.event.head_commit.message }} + COMMIT_URL: ${{ github.event.head_commit.url }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + + - uses: actions/checkout@v4 + with: + path: KernelSU + fetch-depth: 0 + + - name: List artifacts + run: | + tree + + - name: Download prebuilt toolchain + run: | + AOSP_MIRROR=https://android.googlesource.com + BRANCH=main-kernel-build-2024 + git clone $AOSP_MIRROR/platform/prebuilts/build-tools -b $BRANCH --depth 1 build-tools + git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools + git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 + pip3 install telethon + + - name: Set boot sign key + env: + BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }} + run: | + if [ ! -z "$BOOT_SIGN_KEY" ]; then + echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem + fi + + - name: Bot session cache + id: bot_session_cache + uses: actions/cache@v4 + if: false + with: + path: scripts/ksubot.session + key: ${{ runner.os }}-bot-session + + - name: Build boot images + run: | + export AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool + export GZIP=$GITHUB_WORKSPACE/build-tools/path/linux-x86/gzip + export LZ4=$GITHUB_WORKSPACE/build-tools/path/linux-x86/lz4 + export MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py + export UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py + cd $GITHUB_WORKSPACE/KernelSU + export VERSION=$(($(git rev-list --count HEAD) + 10200)) + echo "VERSION: $VERSION" + cd - + bash $GITHUB_WORKSPACE/KernelSU/.github/scripts/build_a13.sh + + - name: Display structure of boot files + run: ls -R + + - name: Upload images artifact + uses: actions/upload-artifact@v4 + with: + name: boot-images-android15 + path: Image-android15*/*.img.gz diff --git a/.github/workflows/build-kernel-a16.yml b/.github/workflows/build-kernel-a16.yml new file mode 100644 index 00000000..3f2d0bdd --- /dev/null +++ b/.github/workflows/build-kernel-a16.yml @@ -0,0 +1,105 @@ +name: Build Kernel - Android 16 +on: + # push: + # branches: ["main", "ci", "checkci"] + # paths: + # - ".github/workflows/deps/gki/build-kernel-a16.yml" + # - ".github/workflows/deps/gki/gki-kernel.yml" + # - ".github/scripts/build_a13.sh" + # - "kernel/**" + workflow_call: + inputs: + debug: + description: 'Build debug kernel' + required: false + type: boolean + default: false +jobs: + build-kernel: + if: github.event_name != 'pull_request' && github.ref != 'refs/heads/checkci' + strategy: + matrix: + include: + - version: "6.12" + sub_level: 38 + os_patch_level: 2025-08 + uses: ./.github/workflows/gki-kernel.yml + secrets: inherit + with: + version: android16-${{ matrix.version }} + version_name: android16-${{ matrix.version }}.${{ matrix.sub_level }} + tag: android16-${{ matrix.version }}-${{ matrix.os_patch_level }} + os_patch_level: ${{ matrix.os_patch_level }} + patch_path: ${{ matrix.version }} + debug: ${{ inputs.debug || false }} + + upload-artifacts: + needs: build-kernel + runs-on: ubuntu-latest + if: ${{ ( github.event_name != 'pull_request' && github.ref == 'refs/heads/main' ) || github.ref_type == 'tag' || github.ref == 'refs/heads/ci' }} + env: + CHAT_ID: ${{ secrets.CHAT_ID }} + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + MESSAGE_THREAD_ID: ${{ secrets.MESSAGE_THREAD_ID }} + COMMIT_MESSAGE: ${{ github.event.head_commit.message }} + COMMIT_URL: ${{ github.event.head_commit.url }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + steps: + - name: Download artifacts + uses: actions/download-artifact@v6 + + - uses: actions/checkout@v5 + with: + path: KernelSU + fetch-depth: 0 + + - name: List artifacts + run: | + tree + + - name: Download prebuilt toolchain + run: | + AOSP_MIRROR=https://android.googlesource.com + BRANCH=main-kernel-build-2024 + git clone $AOSP_MIRROR/platform/prebuilts/build-tools -b $BRANCH --depth 1 build-tools + git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools + git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 + pip3 install telethon + + - name: Set boot sign key + env: + BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }} + run: | + if [ ! -z "$BOOT_SIGN_KEY" ]; then + echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem + fi + + - name: Bot session cache + id: bot_session_cache + uses: actions/cache@v4 + if: false + with: + path: scripts/ksubot.session + key: ${{ runner.os }}-bot-session + + - name: Build boot images + run: | + export AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool + export GZIP=$GITHUB_WORKSPACE/build-tools/path/linux-x86/gzip + export LZ4=$GITHUB_WORKSPACE/build-tools/path/linux-x86/lz4 + export MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py + export UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py + cd $GITHUB_WORKSPACE/KernelSU + export VERSION=$(($(git rev-list --count HEAD) + 10200)) + echo "VERSION: $VERSION" + cd - + bash $GITHUB_WORKSPACE/KernelSU/.github/scripts/build_a13.sh + + - name: Display structure of boot files + run: ls -R + + - name: Upload images artifact + uses: actions/upload-artifact@v5 + with: + name: boot-images-android16 + path: Image-android16*/*.img.gz diff --git a/.github/workflows/build-lkm.yml b/.github/workflows/build-lkm.yml index 2218dd47..2da532cc 100644 --- a/.github/workflows/build-lkm.yml +++ b/.github/workflows/build-lkm.yml @@ -1,77 +1,20 @@ name: Build LKM for KernelSU on: workflow_call: - inputs: - upload: - required: true - type: boolean - default: true - description: "Whether to upload to branch" - secrets: - # username:github_pat - TOKEN: - required: true workflow_dispatch: - inputs: - upload: - required: true - type: boolean - default: true - description: "Whether to upload to branch" jobs: build-lkm: strategy: matrix: - include: - - version: "android12-5.10" - sub_level: 240 - os_patch_level: 2025-09 - - version: "android13-5.10" - sub_level: 238 - os_patch_level: 2025-07 - - version: "android13-5.15" - sub_level: 189 - os_patch_level: 2025-09 - - version: "android14-5.15" - sub_level: 185 - os_patch_level: 2025-07 - - version: "android14-6.1" - sub_level: 145 - os_patch_level: 2025-09 - - version: "android15-6.6" - sub_level: 98 - os_patch_level: 2025-09 - #- version: "android16-6.12" - # sub_level: 38 - # os_patch_level: 2025-09 - # uses: ./.github/workflows/gki-kernel-mock.yml when debugging - uses: ./.github/workflows/gki-kernel.yml + kmi: + - android12-5.10 + - android13-5.10 + - android13-5.15 + - android14-5.15 + - android14-6.1 + - android15-6.6 + - android16-6.12 + uses: ./.github/workflows/ddk-lkm.yml with: - version: ${{ matrix.version }} - version_name: ${{ matrix.version }}.${{ matrix.sub_level }} - tag: ${{ matrix.version }}-${{ matrix.os_patch_level }} - os_patch_level: ${{ matrix.os_patch_level }} - build_lkm: true - - push-to-branch: - needs: [build-lkm] - runs-on: ubuntu-latest - if: ${{ inputs.upload }} - steps: - - name: Download all workflow run artifacts - uses: actions/download-artifact@v4 - with: - path: bin/ - merge-multiple: true - - name: Push to branch LKM - run: | - cd bin - git config --global init.defaultBranch lkm - git init - git remote add origin https://${{ secrets.TOKEN }}@github.com/${{ github.repository }} - git config --local user.name "github-actions[bot]" - git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" - find . -type f - git add . - git commit -m "Upload LKM from ${{ github.sha }}" -m "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" - git push --force --set-upstream origin lkm + kmi: ${{ matrix.kmi }} + ddk_release: '20251104' diff --git a/.github/workflows/build-manager.yml b/.github/workflows/build-manager.yml index 70205c09..a5accfbf 100644 --- a/.github/workflows/build-manager.yml +++ b/.github/workflows/build-manager.yml @@ -5,6 +5,7 @@ on: branches: [ "main", "ci" ] paths: - '.github/workflows/build-manager.yml' + - '.github/workflows/build-lkm.yml' - 'manager/**' - 'kernel/**' - 'userspace/ksud/**' @@ -15,77 +16,13 @@ on: paths: - 'manager/**' workflow_call: - workflow_dispatch: - inputs: - build_lkm: - required: true - type: choice - default: "auto" - options: - - "true" - - "false" - - "auto" - description: "Whether to build lkm" - upload_lkm: - required: true - type: boolean - default: true - description: "Whether to upload lkm" -jobs: - check-build-lkm: - runs-on: ubuntu-latest - outputs: - build_lkm: ${{ steps.check-build.outputs.build_lkm }} - upload_lkm: ${{ steps.check-build.outputs.upload_lkm }} - steps: - - name: check build - id: check-build - run: | - if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ "${{ inputs.build_lkm }}" != "auto" ]; then - kernel_changed="${{ inputs.build_lkm }}" - else - kernel_changed=true - mkdir tmp - cd tmp - git config --global init.defaultBranch bot - git config --global user.name 'Bot' - git config --global user.email 'bot@github.shirkneko.io' - git init . - git remote add origin https://github.com/${{ github.repository }} - CURRENT_COMMIT="${{ github.event.head_commit.id }}" - git fetch origin $CURRENT_COMMIT --depth=1 - git fetch origin lkm --depth=1 - LKM_COMMIT="$(git log --format=%B -n 1 origin/lkm | head -n 1)" - LKM_COMMIT="${LKM_COMMIT#Upload LKM from }" - LKM_COMMIT=$(echo "$LKM_COMMIT" | tr -d '[:space:]') - echo "LKM_COMMIT=$LKM_COMMIT" - git fetch origin "$LKM_COMMIT" --depth=1 - git diff --quiet "$LKM_COMMIT" "$CURRENT_COMMIT" -- kernel :!kernel/setup.sh .github/workflows/build-lkm.yml .github/workflows/build-kernel-*.yml && kernel_changed=false - cd .. - rm -rf tmp - fi - if [ "${{ github.event_name }}" == "push" ] && [ "${{ github.ref }}" == 'refs/heads/main' ]; then - need_upload=true - elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then - need_upload="${{ inputs.upload_lkm }}" - else - need_upload=false - fi - echo "kernel changed: $kernel_changed" - echo "need upload: $need_upload" - echo "build_lkm=$kernel_changed" >> "$GITHUB_OUTPUT" - echo "upload_lkm=$need_upload" >> "$GITHUB_OUTPUT" +jobs: build-lkm: - needs: check-build-lkm uses: ./.github/workflows/build-lkm.yml - if: ${{ needs.check-build-lkm.outputs.build_lkm == 'true' }} - with: - upload: ${{ needs.check-build-lkm.outputs.upload_lkm == 'true' }} secrets: inherit build-susfs: - if: ${{ always() }} - needs: [ check-build-lkm, build-lkm ] + needs: build-lkm strategy: matrix: include: @@ -97,8 +34,7 @@ jobs: os: ${{ matrix.os }} build-user_scanner: - if: ${{ always() }} - needs: [ check-build-lkm, build-lkm ] + needs: build-lkm strategy: matrix: include: @@ -110,8 +46,7 @@ jobs: os: ${{ matrix.os }} build-ksud: - if: ${{ always() }} - needs: [ check-build-lkm, build-lkm ] + needs: build-lkm strategy: matrix: include: @@ -125,11 +60,8 @@ jobs: with: target: ${{ matrix.target }} os: ${{ matrix.os }} - pack_lkm: true - pull_lkm: ${{ needs.check-build-lkm.outputs.build_lkm != 'true' }} build-manager: - if: ${{ always() }} needs: build-ksud runs-on: ubuntu-latest defaults: diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index bafb41a1..a59d1d1d 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -34,4 +34,4 @@ jobs: - name: Run clippy run: | cross clippy --manifest-path userspace/ksud/Cargo.toml --target aarch64-linux-android --release - cross clippy --manifest-path userspace/ksud/Cargo.toml --target x86_64-linux-android --release + cross clippy --manifest-path userspace/ksud/Cargo.toml --target x86_64-linux-android --release \ No newline at end of file diff --git a/.github/workflows/ddk-lkm.yml b/.github/workflows/ddk-lkm.yml new file mode 100644 index 00000000..34b613cc --- /dev/null +++ b/.github/workflows/ddk-lkm.yml @@ -0,0 +1,53 @@ +name: Build KernelSU Kernel Module + +on: + workflow_call: + inputs: + kmi: + description: 'KMI version' + required: true + type: string + ddk_release: + description: 'DDK release version' + required: false + default: '20251104' + type: string + +jobs: + build-kernelsu-ko: + name: Build kernelsu.ko for ${{ inputs.kmi }} + runs-on: ubuntu-latest + container: + image: ghcr.io/shirkneko/ddk:${{ inputs.kmi }}-${{ inputs.ddk_release }} + options: --privileged + + steps: + - name: Checkout source code + uses: actions/checkout@v4 + + - name: Build kernelsu.ko + run: | + git config --global --add safe.directory /__w/SukiSU-Ultra/SukiSU-Ultra + cd kernel + + echo "=== Building kernelsu.ko for KMI: ${{ inputs.kmi }} ===" + CONFIG_KSU=m make + + echo "=== Build completed ===" + # Create output directory in GitHub workspace + mkdir -p /github/workspace/out + # Copy with KMI-specific naming + OUTPUT_NAME="${{ inputs.kmi }}_kernelsu.ko" + cp kernelsu.ko "/github/workspace/out/$OUTPUT_NAME" + + echo "Copied to: /github/workspace/out/$OUTPUT_NAME" + ls -la "/github/workspace/out/$OUTPUT_NAME" + echo "Size: $(du -h "/github/workspace/out/$OUTPUT_NAME" | cut -f1)" + llvm-strip -d "/github/workspace/out/$OUTPUT_NAME" + echo "Size after stripping: $(du -h "/github/workspace/out/$OUTPUT_NAME" | cut -f1)" + + - name: Upload kernelsu.ko artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ inputs.kmi }}-lkm + path: /github/workspace/out/${{ inputs.kmi }}_kernelsu.ko \ No newline at end of file diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml new file mode 100644 index 00000000..4174daf6 --- /dev/null +++ b/.github/workflows/deploy-website.yml @@ -0,0 +1,67 @@ +name: Deploy Website + +on: + push: + branches: + - main + - website + paths: + - '.github/workflows/deploy-website.yml' + - 'website/**' + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: pages + cancel-in-progress: false + +jobs: + # Build job + build: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./website + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Not needed if lastUpdated is not enabled + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: latest + cache: yarn # or pnpm / yarn + cache-dependency-path: website/yarn.lock + - name: Setup Pages + uses: actions/configure-pages@v5 + - name: Install dependencies + run: yarn install --frozen-lockfile + - name: Build with VitePress + run: | + yarn docs:build + touch docs/.vitepress/dist/.nojekyll + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: website/docs/.vitepress/dist + + # Deployment job + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + needs: build + runs-on: ubuntu-latest + name: Deploy + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 \ No newline at end of file diff --git a/.github/workflows/gki-kernel-mock.yml b/.github/workflows/gki-kernel-mock.yml deleted file mode 100644 index 205d1d0e..00000000 --- a/.github/workflows/gki-kernel-mock.yml +++ /dev/null @@ -1,79 +0,0 @@ -name: GKI Kernel Build - -on: - workflow_call: - inputs: - version: - required: true - type: string - description: > - Output directory of gki, - for example: android12-5.10 - version_name: - required: true - type: string - description: > - With SUBLEVEL of kernel, - for example: android12-5.10.66 - tag: - required: true - type: string - description: > - Part of branch name of common kernel manifest, - for example: android12-5.10-2021-11 - os_patch_level: - required: false - type: string - description: > - Patch level of common kernel manifest, - for example: 2021-11 - default: 2022-05 - patch_path: - required: false - type: string - description: > - Directory name of .github/patches/ - for example: 5.10 - use_cache: - required: false - type: boolean - default: true - embed_ksud: - required: false - type: string - default: ksud-aarch64-linux-android - description: > - Artifact name of prebuilt ksud to be embedded - for example: ksud-aarch64-linux-android - debug: - required: false - type: boolean - default: false - build_lkm: - required: false - type: boolean - default: false - secrets: - BOOT_SIGN_KEY: - required: false - CHAT_ID: - required: false - BOT_TOKEN: - required: false - MESSAGE_THREAD_ID: - required: false - -jobs: - mock_build: - name: Mock build ${{ inputs.version_name }} - runs-on: ubuntu-latest - steps: - - name: Create mocking ko - run: | - echo "${{ inputs.version }}_kernelsu.ko" > ${{ inputs.version }}_kernelsu.ko - - name: Upload LKM - uses: actions/upload-artifact@v4 - if: ${{ inputs.build_lkm == true }} - with: - name: ${{ inputs.version }}-lkm - path: ./*_kernelsu.ko diff --git a/.github/workflows/gki-kernel.yml b/.github/workflows/gki-kernel.yml index 21bb6346..8a89393b 100644 --- a/.github/workflows/gki-kernel.yml +++ b/.github/workflows/gki-kernel.yml @@ -103,7 +103,7 @@ jobs: cd $GITHUB_WORKSPACE sudo apt-get install repo -y mkdir android-kernel && cd android-kernel - repo init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${{ inputs.tag }} --repo-rev=v2.35 + repo init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${{ inputs.tag }} --repo-rev=v2.16 REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${{ inputs.tag }}) DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml if grep -q deprecated <<< $REMOTE_BRANCH; then @@ -198,9 +198,11 @@ jobs: - name: Make working directory clean to avoid dirty working-directory: android-kernel run: | - if [ -e common/BUILD.bazel ]; then - sed -i '/^[[:space:]]*"protected_exports_list"[[:space:]]*:[[:space:]]*"android\/abi_gki_protected_exports_aarch64",$/d' common/BUILD.bazel + # Fix bazel build error + if [ -f common/BUILD.bazel ]; then + [ -f android/abi_gki_protected_exports_aarch64 ] || sed -i '/^[[:space:]]*"protected_exports_list"[[:space:]]*:[[:space:]]*"android\/abi_gki_protected_exports_aarch64",$/d' common/BUILD.bazel fi + rm common/android/abi_gki_protected_exports_* || echo "No protected exports!" git config --global user.email "bot@kernelsu.org" git config --global user.name "KernelSUBot" diff --git a/.github/workflows/ksud.yml b/.github/workflows/ksud.yml index 7d1ea16c..44d2967f 100644 --- a/.github/workflows/ksud.yml +++ b/.github/workflows/ksud.yml @@ -9,10 +9,6 @@ on: required: false type: string default: ubuntu-latest - pull_lkm: - required: false - type: boolean - default: true pack_lkm: required: false type: boolean @@ -29,27 +25,14 @@ jobs: with: fetch-depth: 0 - - name: Pull lkms from branch - if: ${{ inputs.pack_lkm && inputs.pull_lkm }} - uses: actions/checkout@v4 - with: - ref: lkm - path: lkm - - - name: Download lkms from artifacts - if: ${{ inputs.pack_lkm && !inputs.pull_lkm }} + - name: Download artifacts uses: actions/download-artifact@v4 - - - name: Prepare LKM files - if: ${{ inputs.pack_lkm && inputs.pull_lkm }} - run: | - cp lkm/*_kernelsu.ko ./userspace/ksud/bin/aarch64/ - - - name: Prepare LKM files - if: ${{ inputs.pack_lkm && !inputs.pull_lkm }} + + - name: Prepare LKM fies + if: ${{ inputs.pack_lkm }} run: | cp android*-lkm/*_kernelsu.ko ./userspace/ksud/bin/aarch64/ - + - name: Setup rustup run: | rustup update stable diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml index e4287380..f864e05f 100644 --- a/.github/workflows/shellcheck.yml +++ b/.github/workflows/shellcheck.yml @@ -16,7 +16,7 @@ on: jobs: shellcheck: - runs-on: self-hosted + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.gitignore b/.gitignore index b6ce1a41..54963dbb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ .idea -.vscode CLAUDE.md .DS_Store diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..db55e624 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "selinux.h": "c" + } +} \ No newline at end of file diff --git a/kernel/.vscode/c_cpp_properties.json b/kernel/.vscode/c_cpp_properties.json new file mode 100644 index 00000000..f6613702 --- /dev/null +++ b/kernel/.vscode/c_cpp_properties.json @@ -0,0 +1,11 @@ +{ + "configurations": [ + { + "name": "Linux", + "cStandard": "c11", + "intelliSenseMode": "gcc-arm64", + "compileCommands": "${workspaceFolder}/compile_commands.json" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/kernel/.vscode/generate_compdb.py b/kernel/.vscode/generate_compdb.py new file mode 100644 index 00000000..88669138 --- /dev/null +++ b/kernel/.vscode/generate_compdb.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 + +from __future__ import print_function, division + +import argparse +import fnmatch +import functools +import json +import math +import multiprocessing +import os +import re +import sys + + +CMD_VAR_RE = re.compile(r'^\s*(?:saved)?cmd_(\S+)\s*:=\s*(.+)\s*$', re.MULTILINE) +SOURCE_VAR_RE = re.compile(r'^\s*source_(\S+)\s*:=\s*(.+)\s*$', re.MULTILINE) + + +def print_progress_bar(progress): + progress_bar = '[' + '|' * int(50 * progress) + '-' * int(50 * (1.0 - progress)) + ']' + print('\r', progress_bar, "{0:.1%}".format(progress), end='\r', file=sys.stderr) + + +def parse_cmd_file(out_dir, cmdfile_path): + with open(cmdfile_path, 'r') as cmdfile: + cmdfile_content = cmdfile.read() + + commands = { match.group(1): match.group(2) for match in CMD_VAR_RE.finditer(cmdfile_content) } + sources = { match.group(1): match.group(2) for match in SOURCE_VAR_RE.finditer(cmdfile_content) } + + return [{ + 'directory': out_dir, + 'command': commands[o_file_name], + 'file': source, + 'output': o_file_name + } for o_file_name, source in sources.items()] + + +def gen_compile_commands(cmd_file_search_path, out_dir): + print("Building *.o.cmd file list...", file=sys.stderr) + + out_dir = os.path.abspath(out_dir) + + if not cmd_file_search_path: + cmd_file_search_path = [out_dir] + + cmd_files = [] + for search_path in cmd_file_search_path: + if (os.path.isdir(search_path)): + for cur_dir, subdir, files in os.walk(search_path): + cmd_files.extend(os.path.join(cur_dir, cmdfile_name) for cmdfile_name in fnmatch.filter(files, '*.o.cmd')) + else: + cmd_files.extend(search_path) + + if not cmd_files: + print("No *.o.cmd files found in", ", ".join(cmd_file_search_path), file=sys.stderr) + return + + print("Parsing *.o.cmd files...", file=sys.stderr) + + n_processed = 0 + print_progress_bar(0) + + compdb = [] + pool = multiprocessing.Pool() + try: + for compdb_chunk in pool.imap_unordered(functools.partial(parse_cmd_file, out_dir), cmd_files, chunksize=int(math.sqrt(len(cmd_files)))): + compdb.extend(compdb_chunk) + n_processed += 1 + print_progress_bar(n_processed / len(cmd_files)) + + finally: + pool.terminate() + pool.join() + + print(file=sys.stderr) + print("Writing compile_commands.json...", file=sys.stderr) + + with open('compile_commands.json', 'w') as compdb_file: + json.dump(compdb, compdb_file, indent=1) + + +def main(): + cmd_parser = argparse.ArgumentParser() + cmd_parser.add_argument('-O', '--out-dir', type=str, default=os.getcwd(), help="Build output directory") + cmd_parser.add_argument('cmd_file_search_path', nargs='*', help="*.cmd file search path") + gen_compile_commands(**vars(cmd_parser.parse_args())) + + +if __name__ == '__main__': + main() diff --git a/kernel/.vscode/settings.json b/kernel/.vscode/settings.json new file mode 100644 index 00000000..6f8776a1 --- /dev/null +++ b/kernel/.vscode/settings.json @@ -0,0 +1,35 @@ +{ + "files.exclude": { + "**/*.o.cmd": true, + "**/*.ko.cmd": true, + "**/*.mod.cmd": true, + "**/*.cmd": true, + "**/*.order": true, + "**/*.symvers": true, + "**/*.o": true, + "**/*.mod": true, + "**/android-wuwa.mod.c": true, + "**/android-wuwa.lds": true, + "**/.*.*.cmd": true, + "**/.*.d": true, + "**/.*.S": true + }, + "[c]": { + "editor.detectIndentation": false, + "editor.tabSize": 4, + "editor.insertSpaces": true, + "editor.rulers": [80,100] + }, + "files.associations": { + "*.h": "c", + "ratio": "c", + "array": "c", + "string_view": "c", + "initializer_list": "c", + "random": "cpp" + }, + "editor.indentSize": 4, + "editor.insertSpaces": true, + "editor.detectIndentation": false, + "clangd.path": "/opt/ddk/clang/clang-r450784e/bin/clangd" +} diff --git a/kernel/.vscode/tasks.json b/kernel/.vscode/tasks.json new file mode 100644 index 00000000..4ed9adba --- /dev/null +++ b/kernel/.vscode/tasks.json @@ -0,0 +1,16 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Generate compile_commands.json", + "type": "process", + "command": "python", + "args": [ + "${workspaceRoot}/.vscode/generate_compdb.py" + ], + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/kernel/Kconfig b/kernel/Kconfig index 47117816..d197f65c 100644 --- a/kernel/Kconfig +++ b/kernel/Kconfig @@ -2,7 +2,6 @@ menu "KernelSU" config KSU tristate "KernelSU function support" - depends on OVERLAY_FS default y help Enable kernel-level root privileges on Android System. @@ -38,8 +37,6 @@ choice prompt "KernelSU hook type" depends on KSU default KSU_KPROBES_HOOK - help - Hook type for KernelSU config KSU_KPROBES_HOOK bool "Hook KernelSU with Kprobes" diff --git a/kernel/Makefile b/kernel/Makefile index 249c9dbd..e258ff3f 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -45,6 +45,12 @@ KSU_VERSION_API := 3.2.0 GIT_BIN := /usr/bin/env PATH="$$PATH":/usr/bin:/usr/local/bin git CURL_BIN := /usr/bin/env PATH="$$PATH":/usr/bin:/usr/local/bin curl +KDIR := $(KDIR) +MDIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))) + +$(info -- KDIR: $(KDIR)) +$(info -- MDIR: $(MDIR)) + KSU_GITHUB_VERSION := $(shell $(CURL_BIN) -s "https://api.github.com/repos/$(REPO_OWNER)/$(REPO_NAME)/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/') KSU_GITHUB_VERSION_COMMIT := $(shell $(CURL_BIN) -sI "https://api.github.com/repos/$(REPO_OWNER)/$(REPO_NAME)/commits?sha=$(REPO_BRANCH)&per_page=1" | grep -i "link:" | sed -n 's/.*page=\([0-9]*\)>; rel="last".*/\1/p') @@ -54,6 +60,10 @@ else KSU_SRC := $(srctree)/$(src) endif +ifneq ($(shell test -e $(KSU_SRC)/../.git && echo "in-tree"),in-tree) + KSU_SRC := $(MDIR) +endif + LOCAL_GIT_EXISTS := $(shell test -e $(KSU_SRC)/../.git && echo 1 || echo 0) define get_ksu_version_full @@ -110,8 +120,6 @@ ccflags-y += -DKSU_MANAGER_PACKAGE=\"$(KSU_MANAGER_PACKAGE)\" $(info -- SukiSU Manager package name: $(KSU_MANAGER_PACKAGE)) endif -$(info -- Supported Unofficial Manager: 5ec1cff (GKI) ShirkNeko udochina (GKI and KPM)) - ifeq ($(CONFIG_KSU_KPROBES_HOOK), y) $(info -- SukiSU: CONFIG_KSU_KPROBES_HOOK) else ifeq ($(CONFIG_KSU_TRACEPOINT_HOOK), y) @@ -154,4 +162,11 @@ endif ccflags-y += -Wno-implicit-function-declaration -Wno-strict-prototypes -Wno-int-conversion -Wno-gcc-compat ccflags-y += -Wno-declaration-after-statement -Wno-unused-function +all: + make -C $(KDIR) M=$(MDIR) modules +compdb: + python3 $(MDIR)/.vscode/generate_compdb.py -O $(KDIR) $(MDIR) +clean: + make -C $(KDIR) M=$(MDIR) clean + # Keep a new line here!! Because someone may append config diff --git a/kernel/core_hook.c b/kernel/core_hook.c index b6c985ba..dbd1bfb0 100644 --- a/kernel/core_hook.c +++ b/kernel/core_hook.c @@ -887,4 +887,4 @@ void ksu_core_exit(void) flush_workqueue(ksu_workqueue); destroy_workqueue(ksu_workqueue); } -} +} \ No newline at end of file diff --git a/kernel/kernel_compat.h b/kernel/kernel_compat.h index 23848571..39a0643f 100644 --- a/kernel/kernel_compat.h +++ b/kernel/kernel_compat.h @@ -6,6 +6,14 @@ #include "ss/policydb.h" #include "linux/key.h" +#if defined(CONFIG_KPROBES) && !(defined(CONFIG_KSU_TRACEPOINT_HOOK) || defined(CONFIG_KSU_MANUAL_HOOK)) +#define __KPROBES_HOOK 1 +#elif (defined(CONFIG_KSU_TRACEPOINT_HOOK) || defined(CONFIG_KSU_MANUAL_HOOK)) && !defined(CONFIG_KSU_KPROBES_HOOK) +#define __KPROBES_HOOK 0 +#elif defined(CONFIG_KSU_KPROBES_HOOK) +#define __KPROBES_HOOK 1 +#endif + #if defined(CONFIG_ARM) || defined(CONFIG_ARM64) // arch/arm64/include/asm/barrier.h, adding dsb probably unneeded diff --git a/kernel/ksu.c b/kernel/ksu.c index 1675c84d..5f11ceac 100644 --- a/kernel/ksu.c +++ b/kernel/ksu.c @@ -7,6 +7,7 @@ #include "allowlist.h" #include "arch.h" +#include "kernel_compat.h" #include "core_hook.h" #include "feature.h" #include "klog.h" // IWYU pragma: keep @@ -56,7 +57,7 @@ int __init kernelsu_init(void) ksu_allowlist_init(); ksu_throne_tracker_init(); -#ifdef CONFIG_KSU_KPROBES_HOOK +#ifdef __KPROBES_HOOK ksu_sucompat_init(); ksu_ksud_init(); #else @@ -85,7 +86,7 @@ void kernelsu_exit(void) destroy_workqueue(ksu_workqueue); -#ifdef CONFIG_KSU_KPROBES_HOOK +#ifdef __KPROBES_HOOK ksu_ksud_exit(); ksu_sucompat_exit(); #endif diff --git a/kernel/ksud.c b/kernel/ksud.c index fe153900..d488494b 100644 --- a/kernel/ksud.c +++ b/kernel/ksud.c @@ -49,7 +49,7 @@ static void stop_vfs_read_hook(); static void stop_execve_hook(); static void stop_input_hook(); -#ifdef CONFIG_KSU_KPROBES_HOOK +#ifdef __KPROBES_HOOK static struct work_struct stop_vfs_read_work; static struct work_struct stop_execve_hook_work; static struct work_struct stop_input_hook_work; @@ -268,7 +268,7 @@ static ssize_t read_iter_proxy(struct kiocb *iocb, struct iov_iter *to) int ksu_handle_vfs_read(struct file **file_ptr, char __user **buf_ptr, size_t *count_ptr, loff_t **pos) { -#ifndef CONFIG_KSU_KPROBES_HOOK +#ifndef __KPROBES_HOOK if (!ksu_vfs_read_hook) { return 0; } @@ -381,7 +381,7 @@ static bool is_volumedown_enough(unsigned int count) int ksu_handle_input_handle_event(unsigned int *type, unsigned int *code, int *value) { -#ifndef CONFIG_KSU_KPROBES_HOOK +#ifndef __KPROBES_HOOK if (!ksu_input_hook) { return 0; } @@ -423,7 +423,7 @@ bool ksu_is_safe_mode() return false; } -#ifdef CONFIG_KSU_KPROBES_HOOK +#ifdef __KPROBES_HOOK static int sys_execve_handler_pre(struct kprobe *p, struct pt_regs *regs) { /* @@ -596,7 +596,7 @@ static void do_stop_input_hook(struct work_struct *work) static void stop_vfs_read_hook() { -#ifdef CONFIG_KSU_KPROBES_HOOK +#ifdef __KPROBES_HOOK bool ret = schedule_work(&stop_vfs_read_work); pr_info("unregister vfs_read kprobe: %d!\n", ret); #else @@ -607,7 +607,7 @@ static void stop_vfs_read_hook() static void stop_execve_hook() { -#ifdef CONFIG_KSU_KPROBES_HOOK +#ifdef __KPROBES_HOOK bool ret = schedule_work(&stop_execve_hook_work); pr_info("unregister execve kprobe: %d!\n", ret); #else @@ -623,7 +623,7 @@ static void stop_input_hook() return; } input_hook_stopped = true; -#ifdef CONFIG_KSU_KPROBES_HOOK +#ifdef __KPROBES_HOOK bool ret = schedule_work(&stop_input_hook_work); pr_info("unregister input kprobe: %d!\n", ret); #else @@ -635,7 +635,7 @@ static void stop_input_hook() // ksud: module support void ksu_ksud_init() { -#ifdef CONFIG_KSU_KPROBES_HOOK +#ifdef __KPROBES_HOOK int ret; ret = register_kprobe(&execve_kp); @@ -655,7 +655,7 @@ void ksu_ksud_init() void ksu_ksud_exit() { -#ifdef CONFIG_KSU_KPROBES_HOOK +#ifdef __KPROBES_HOOK unregister_kprobe(&execve_kp); // this should be done before unregister vfs_read_kp // unregister_kprobe(&vfs_read_kp); diff --git a/kernel/sucompat.c b/kernel/sucompat.c index b710df6c..91c6d825 100644 --- a/kernel/sucompat.c +++ b/kernel/sucompat.c @@ -62,7 +62,7 @@ static const struct ksu_feature_handler su_compat_handler = { .set_handler = su_compat_feature_set, }; -#ifndef CONFIG_KSU_KPROBES_HOOK +#ifndef __KPROBES_HOOK static bool ksu_sucompat_hook_state __read_mostly = true; #endif @@ -94,7 +94,7 @@ int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode, { const char su[] = SU_PATH; -#ifndef CONFIG_KSU_KPROBES_HOOK +#ifndef __KPROBES_HOOK if (!ksu_sucompat_hook_state) { return 0; } @@ -124,7 +124,7 @@ int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags) // const char sh[] = SH_PATH; const char su[] = SU_PATH; -#ifndef CONFIG_KSU_KPROBES_HOOK +#ifndef __KPROBES_HOOK if (!ksu_sucompat_hook_state) { return 0; } @@ -182,7 +182,7 @@ int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr, const char sh[] = KSUD_PATH; const char su[] = SU_PATH; -#ifndef CONFIG_KSU_KPROBES_HOOK +#ifndef __KPROBES_HOOK if (!ksu_sucompat_hook_state) { return 0; } @@ -228,7 +228,7 @@ int ksu_handle_execve_sucompat(int *fd, const char __user **filename_user, const char su[] = SU_PATH; char path[sizeof(su) + 1]; -#ifndef CONFIG_KSU_KPROBES_HOOK +#ifndef __KPROBES_HOOK if (!ksu_sucompat_hook_state){ return 0; } @@ -273,7 +273,7 @@ int ksu_handle_devpts(struct inode *inode) int __ksu_handle_devpts(struct inode *inode) { -#ifndef CONFIG_KSU_KPROBES_HOOK +#ifndef __KPROBES_HOOK if (!ksu_sucompat_hook_state) return 0; #endif @@ -299,7 +299,7 @@ int __ksu_handle_devpts(struct inode *inode) return 0; } -#ifdef CONFIG_KSU_KPROBES_HOOK +#ifdef __KPROBES_HOOK static int faccessat_handler_pre(struct kprobe *p, struct pt_regs *regs) { struct pt_regs *real_regs = PT_REAL_REGS(regs); @@ -381,7 +381,7 @@ static void destroy_kprobe(struct kprobe **kp_ptr) // sucompat: permited process can execute 'su' to gain root access. void ksu_sucompat_enable() { -#ifdef CONFIG_KSU_KPROBES_HOOK +#ifdef __KPROBES_HOOK su_kps[0] = init_kprobe(SYS_EXECVE_SYMBOL, execve_handler_pre); su_kps[1] = init_kprobe(SYS_FACCESSAT_SYMBOL, faccessat_handler_pre); su_kps[2] = init_kprobe(SYS_NEWFSTATAT_SYMBOL, newfstatat_handler_pre); @@ -394,7 +394,7 @@ void ksu_sucompat_enable() void ksu_sucompat_disable() { -#ifdef CONFIG_KSU_KPROBES_HOOK +#ifdef __KPROBES_HOOK int i; for (i = 0; i < ARRAY_SIZE(su_kps); i++) { destroy_kprobe(&su_kps[i]);