name: 'Kernel Fixes' description: 'Applies compatibility fixes based on android/kernel/sublevel' inputs: version: required: true type: string android_version: required: true type: string kernel_version: required: true type: string sublevel: required: true type: string os_patch_level: required: true type: string runs: using: composite steps: - name: 'Apply Makefile and parse-options.c fixes for GLIBC >= 2.38' working-directory: ${{ github.workspace }}/kernel/common shell: bash run: | set -euo pipefail GLIBC_VERSION="$(ldd --version 2>/dev/null | head -n 1 | awk '{print $NF}')" echo "[INFO] Detected GLIBC version: $GLIBC_VERSION" if [ "$(printf '%s\n' "2.38" "$GLIBC_VERSION" | sort -V | head -n 1)" = "2.38" ]; then echo "[INFO] GLIBC >= 2.38, attempting Makefile fix." # Check if the pattern that needs fixing actually exists if grep -q '\$(Q)\$(MAKE) -C \$(SUBCMD_SRC) OUTPUT=\$(abspath \$(dir \$@))\/ \$(abspath \$@)' tools/bpf/resolve_btfids/Makefile; then echo "[INFO] Found pattern to fix, applying sed." sed -i '/\$(Q)\$(MAKE) -C \$(SUBCMD_SRC) OUTPUT=\$(abspath \$(dir \$@))\/ \$(abspath \$@)/s//$(Q)$(MAKE) -C $(SUBCMD_SRC) EXTRA_CFLAGS="$(CFLAGS)" OUTPUT=$(abspath $(dir $@))\/ $(abspath $@)/' tools/bpf/resolve_btfids/Makefile MAKEFILE_FIXED="true" elif grep -q 'EXTRA_CFLAGS' tools/bpf/resolve_btfids/Makefile; then echo "[INFO] EXTRA_CFLAGS already present, no fix needed." MAKEFILE_FIXED="already_fixed" else echo "[WARN] Neither pattern found in Makefile." MAKEFILE_FIXED="false" fi echo "MAKEFILE_FIXED=$MAKEFILE_FIXED" >> $GITHUB_ENV if [[ "${{ inputs.version }}" == "android13-5.10" && "${{ inputs.sublevel }}" -le 186 ]] || \ [[ "${{ inputs.version }}" == "android13-5.15" && "${{ inputs.sublevel }}" -le 119 ]] || \ [[ "${{ inputs.version }}" == "android14-5.15" && "${{ inputs.sublevel }}" -le 110 ]]; then echo "[INFO] Applying parse-options.c fixes." sed -i '/char \*buf = NULL;/a int i;' tools/lib/subcmd/parse-options.c 2>/dev/null || true sed -i 's/for (int i = 0; subcommands\[i\]; i++) {/for (i = 0; subcommands[i]; i++) {/' tools/lib/subcmd/parse-options.c 2>/dev/null || true sed -i '/if (subcommands) {/a int i;' tools/lib/subcmd/parse-options.c 2>/dev/null || true sed -i 's/for (int i = 0; subcommands\[i\]; i++)/for (i = 0; subcommands[i]; i++)/' tools/lib/subcmd/parse-options.c 2>/dev/null || true echo "PARSE_OPTIONS_FIXED=true" >> $GITHUB_ENV else echo "PARSE_OPTIONS_FIXED=false" >> $GITHUB_ENV fi else echo "[SKIP] GLIBC version < 2.38, skipping Makefile fix." fi - name: 'Apply mmap.c fix for specific versions' shell: bash if: ${{ inputs.version == 'android15-6.6' && inputs.sublevel <= '58' }} working-directory: ${{ github.workspace }}/kernel/common run: | echo "[INFO] Checking for android15 + kernel 6.6 include fix..." if [[ "${{ inputs.android_version }}" == "android15" && "${{ inputs.kernel_version }}" == "6.6" ]]; then echo "[MATCH] android15 + 6.6, checking for fs.h include." cd "${{ github.workspace }}/kernel/common" if ! grep -qxF '#include ' ./fs/namespace.c; then echo "[INFO] Adding missing #include to fs/namespace.c." sed -i '/#include /a #include ' ./fs/namespace.c echo "MMAP_NAMESPACE_FIX=true" >> "$GITHUB_ENV" else echo "[INFO] #include already present." echo "MMAP_NAMESPACE_FIX=already_present" >> "$GITHUB_ENV" fi fi - name: 'Apply mmap.c fix for specific versions' shell: bash if: ${{ (inputs.version == 'android12-5.10' && inputs.sublevel == 226) || (inputs.version == 'android13-5.10' && inputs.sublevel == 223) || (inputs.version == 'android13-5.15' && inputs.sublevel == 167) || (inputs.version == 'android14-5.15' && inputs.sublevel == 167) }} working-directory: ${{ github.workspace }}/kernel/common run: | echo "[INFO] Applying mmap.c fix for specific version combo." sed -i 's/\s*vm_flags_clear(new_vma, VM_PAD_MASK);/ new_vma->vm_flags \&= ~VM_PAD_MASK;/' mm/mmap.c echo "MMAP_VM_FLAGS_FIX=true" >> "$GITHUB_ENV" - name: 'Final Kernel Fixes Summary' shell: bash run: | echo "## Final Kernel Fixes Summary" >> "$GITHUB_STEP_SUMMARY" echo "" >> "$GITHUB_STEP_SUMMARY" echo "**Kernel Version:** ${{ inputs.android_version }} + ${{ inputs.kernel_version }} (sublevel ${{ inputs.sublevel }})" >> "$GITHUB_STEP_SUMMARY" echo "" >> "$GITHUB_STEP_SUMMARY" echo "### Fix Status" >> "$GITHUB_STEP_SUMMARY" GLIBC_VERSION="$(ldd --version 2>/dev/null | head -n 1 | awk '{print $NF}')" if [ "$(printf '%s\n' "2.38" "$GLIBC_VERSION" | sort -V | head -n 1)" = "2.38" ]; then if [ "${MAKEFILE_FIXED:-false}" = "true" ]; then echo "- Makefile EXTRA_CFLAGS fix: applied" >> "$GITHUB_STEP_SUMMARY" elif [ "${MAKEFILE_FIXED:-false}" = "already_fixed" ]; then echo "- Makefile EXTRA_CFLAGS fix: already present" >> "$GITHUB_STEP_SUMMARY" else echo "- Makefile EXTRA_CFLAGS fix: pattern not found" >> "$GITHUB_STEP_SUMMARY" fi if [ "${PARSE_OPTIONS_FIXED:-false}" = "true" ]; then echo "- parse-options.c fix: applied" >> "$GITHUB_STEP_SUMMARY" else echo "- parse-options.c fix: not applicable" >> "$GITHUB_STEP_SUMMARY" fi else echo "- Makefile EXTRA_CFLAGS fix: skipped because GLIBC < 2.38" >> "$GITHUB_STEP_SUMMARY" echo "- parse-options.c fix: skipped because GLIBC < 2.38" >> "$GITHUB_STEP_SUMMARY" fi if [ "${MMAP_NAMESPACE_FIX:-not_applicable}" = "true" ]; then echo "- fs/namespace.c include fix: applied" >> "$GITHUB_STEP_SUMMARY" elif [ "${MMAP_NAMESPACE_FIX:-not_applicable}" = "already_present" ]; then echo "- fs/namespace.c include fix: already present" >> "$GITHUB_STEP_SUMMARY" else echo "- fs/namespace.c include fix: not applicable" >> "$GITHUB_STEP_SUMMARY" fi if [ "${MMAP_VM_FLAGS_FIX:-not_applicable}" = "true" ]; then echo "- mm/mmap.c VM_PAD_MASK fix: applied" >> "$GITHUB_STEP_SUMMARY" else echo "- mm/mmap.c VM_PAD_MASK fix: not applicable" >> "$GITHUB_STEP_SUMMARY" fi