From 38a2ffe0c733bf0d1d272ed39f54cb6821707c4d Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Tue, 28 Oct 2025 14:13:10 -0700 Subject: [PATCH] Add stacktrace kernelcompat Signed-off-by: Zach Brown --- kmod/src/Makefile.kernelcompat | 8 ++++++++ kmod/src/kernelcompat.h | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/kmod/src/Makefile.kernelcompat b/kmod/src/Makefile.kernelcompat index 3bf3ccdb..47aaf813 100644 --- a/kmod/src/Makefile.kernelcompat +++ b/kmod/src/Makefile.kernelcompat @@ -462,3 +462,11 @@ ifneq (,$(shell grep 'struct list_lru_one \*list, spinlock_t \*lock, void \*cb_a ccflags-y += -DKC_LIST_LRU_WALK_CB_LIST_LOCK endif +# +# v5.1-rc4-273-ge9b98e162aa5 +# +# introduce stack trace helpers +# +ifneq (,$(shell grep '^unsigned int stack_trace_save' include/linux/stacktrace.h)) +ccflags-y += -DKC_STACK_TRACE_SAVE +endif diff --git a/kmod/src/kernelcompat.h b/kmod/src/kernelcompat.h index 7fb566b5..43e8c91c 100644 --- a/kmod/src/kernelcompat.h +++ b/kmod/src/kernelcompat.h @@ -457,4 +457,30 @@ static inline void list_lru_isolate_move(struct list_lru_one *list, struct list_ } #endif +#ifndef KC_STACK_TRACE_SAVE +#include +static inline unsigned int stack_trace_save(unsigned long *store, unsigned int size, + unsigned int skipnr) +{ + struct stack_trace trace = { + .entries = store, + .max_entries = size, + .skip = skipnr, + }; + + save_stack_trace(&trace); + return trace.nr_entries; +} + +static inline void stack_trace_print(unsigned long *entries, unsigned int nr_entries, int spaces) +{ + struct stack_trace trace = { + .entries = entries, + .nr_entries = nr_entries, + }; + + print_stack_trace(&trace, spaces); +} +#endif + #endif