Refactoring Kconfig and Makefile to optimize KernelSU configuration logic and simplify kernel type determination

This commit is contained in:
ShirkNeko
2025-04-19 16:02:18 +08:00
parent 1a563bb3e1
commit 970e7651a5
2 changed files with 32 additions and 33 deletions

View File

@@ -2,7 +2,6 @@ menu "KernelSU"
config KSU config KSU
tristate "KernelSU function support" tristate "KernelSU function support"
depends on OVERLAY_FS
default y default y
help help
Enable kernel-level root privileges on Android System. Enable kernel-level root privileges on Android System.
@@ -17,27 +16,27 @@ config KSU_DEBUG
Enable KernelSU debug mode. Enable KernelSU debug mode.
config KSU_MANUAL_HOOK config KSU_MANUAL_HOOK
bool "Manual hooking GKI kernels without kprobes" bool "Manual hooking GKI kernels without kprobes"
depends on KSU && KSU != m depends on KSU && KSU != m
default n default n
help help
Keep KPROBES enabled but do not use KPROBES to implement Using manual hooks instead of KSU KPROBES hooks.
the hooks required by KernelSU, but instead hook them manually. By default the GKI kernel should use the KSU KPROBES hook.
This function is automatically enabled for GKI kernels. Non-GKI kernels should prioritize the use of manual hooks.
config KSU_GKI_KERNEL config KSU_GKI_KERNEL
bool bool
default y if (VERSION >= 5 && PATCHLEVEL >= 10) default y if VERSION >= 5 && PATCHLEVEL >= 10 || \
help VERSION >= 6
Internal flag to indicate whether the kernel is GKI. help
Internal flag for GKI kernel detection.
config KSU_HOOK_KPROBES config KSU_HOOK_KPROBES
bool bool
depends on KPROBES depends on KSU && KPROBES && KSU_GKI_KERNEL
depends on KSU_GKI_KERNEL default y if !KSU_MANUAL_HOOK
default y if !KSU_MANUAL_HOOK help
help Internal flags for hooks based on KSU kprobes.
Internal flag to indicate whether KPROBES should be used for hooking.
config KSU_ALLOWLIST_WORKAROUND config KSU_ALLOWLIST_WORKAROUND
bool "KernelSU Session Keyring Init workaround" bool "KernelSU Session Keyring Init workaround"

View File

@@ -51,18 +51,6 @@ endif
$(info -- SukiSU Manager signature size: $(KSU_EXPECTED_SIZE)) $(info -- SukiSU Manager signature size: $(KSU_EXPECTED_SIZE))
$(info -- SukiSU Manager signature hash: $(KSU_EXPECTED_HASH)) $(info -- SukiSU Manager signature hash: $(KSU_EXPECTED_HASH))
$(info -- Supported Unofficial Manager: 5ec1cff (GKI) rsuntk (Non-GKI) ShirkNeko udochina (GKI and non-GKI and KPM)) $(info -- Supported Unofficial Manager: 5ec1cff (GKI) rsuntk (Non-GKI) ShirkNeko udochina (GKI and non-GKI and KPM))
KERNEL_VERSION := $(VERSION).$(PATCHLEVEL)
ifeq ($(shell test $(VERSION) -ge 5 -a $(PATCHLEVEL) -ge 10; echo $$?),0)
KERNEL_TYPE := GKI 2.0
else ifeq ($(shell test $(VERSION) -ge 6; echo $$?),0)
KERNEL_TYPE := GKI 2.0
else ifeq ($(shell test $(VERSION) -eq 5 -a $(PATCHLEVEL) -eq 4; echo $$?),0)
KERNEL_TYPE := GKI 1.0
else
KERNEL_TYPE := Non-GKI
endif
$(info -- KERNEL_VERSION: $(KERNEL_VERSION))
$(info -- KERNEL_TYPE$(KERNEL_TYPE))
ifeq ($(strip $(CONFIG_KSU_HOOK_KPROBES)),y) ifeq ($(strip $(CONFIG_KSU_HOOK_KPROBES)),y)
$(info -- SukiSU: KPROBES hooking enabled!) $(info -- SukiSU: KPROBES hooking enabled!)
@@ -73,6 +61,20 @@ $(error CONFIG_KSU_MANUAL_HOOK cannot be enabled when compiling SukiSU as LKM!)
endif endif
endif endif
KERNEL_VERSION := $(VERSION).$(PATCHLEVEL)
KERNEL_TYPE := Non-GKI
# Check for GKI 2.0 (5.10+ or 6.x+)
ifneq ($(shell test \( $(VERSION) -ge 5 -a $(PATCHLEVEL) -ge 10 \) -o $(VERSION) -ge 6; echo $$?),0)
# Check for GKI 1.0 (5.4)
ifeq ($(shell test $(VERSION)-$(PATCHLEVEL) = 5-4; echo $$?),0)
KERNEL_TYPE := GKI 1.0
endif
else
KERNEL_TYPE := GKI 2.0
endif
$(info -- KERNEL_VERSION: $(KERNEL_VERSION))
$(info -- KERNEL_TYPE: $(KERNEL_TYPE))
# Check if KPM is enabled # Check if KPM is enabled
ifeq ($(CONFIG_KPM),y) ifeq ($(CONFIG_KPM),y)
$(info -- KPM is enabled) $(info -- KPM is enabled)
@@ -88,8 +90,6 @@ ATOMIC_INC_FUNC = atomic_long_inc_not_zero
else else
$(info -- SukiSU compat: Neither atomic_inc_not_zero nor atomic_long_inc_not_zero found in kernel/cred.c) $(info -- SukiSU compat: Neither atomic_inc_not_zero nor atomic_long_inc_not_zero found in kernel/cred.c)
endif endif
# Inform which function is being patched
$(info -- SukiSU compat: Using $(ATOMIC_INC_FUNC) in get_cred_rcu patch.) $(info -- SukiSU compat: Using $(ATOMIC_INC_FUNC) in get_cred_rcu patch.)
# 写入签名 # 写入签名