From 36742cc17ea071e95f8b653084ab5fc737e1cb3a Mon Sep 17 00:00:00 2001 From: JackAltman <82563979+JackA1ltman@users.noreply.github.com> Date: Sat, 20 Sep 2025 13:28:05 +0800 Subject: [PATCH] feat: detect proc_ops support via header parsing instead of version check. (#411) Some kernels (e.g. 5.4 with backports) include proc_ops despite being older than 5.6.0. Replace hardcoded version check with runtime header detection to handle these cases. - Check for "struct proc_ops" in include/linux/proc_fs.h - Use KSU_COMPAT_HAS_PROC_OPS macro for conditional compilation - Fixes build failures on kernels with backported proc_ops Signed-off-by: JackAltman --- kernel/Makefile | 5 +++++ kernel/throne_comm.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index 4804fd51..c50e9355 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -126,6 +126,11 @@ $(info -- KernelSU/compat: new vfs_getattr() found) ccflags-y += -DKSU_HAS_NEW_VFS_GETATTR endif +# Function proc_ops check +ifeq ($(shell grep -q "struct proc_ops " $(srctree)/include/linux/proc_fs.h; echo $$?),0) +ccflags-y += -DKSU_COMPAT_HAS_PROC_OPS +endif + # Custom Signs ifdef KSU_EXPECTED_SIZE ccflags-y += -DEXPECTED_SIZE=$(KSU_EXPECTED_SIZE) diff --git a/kernel/throne_comm.c b/kernel/throne_comm.c index 7e4fcf2b..10342347 100644 --- a/kernel/throne_comm.c +++ b/kernel/throne_comm.c @@ -78,7 +78,7 @@ static ssize_t uid_scanner_write(struct file *file, const char __user *buffer, return count; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0) +#ifdef KSU_COMPAT_HAS_PROC_OPS static const struct proc_ops uid_scanner_proc_ops = { .proc_open = uid_scanner_open, .proc_read = seq_read, @@ -133,4 +133,4 @@ void ksu_throne_comm_exit(void) } pr_info("throne communication cleaned up\n"); -} \ No newline at end of file +}