diff --git a/include/L1/stack_switch.h b/include/L1/stack_switch.h index f85da21..70625b9 100644 --- a/include/L1/stack_switch.h +++ b/include/L1/stack_switch.h @@ -7,14 +7,12 @@ // These must be used as a pair #define SYM_ON_KERN_STACK() \ - sym_elevate(); \ uint64_t user_stack; \ SYM_PRESERVE_USER_STACK(user_stack); \ SYM_SWITCH_TO_KERN_STACK(); #define SYM_ON_USER_STACK() \ - SYM_RESTORE_USER_STACK(user_stack); \ - sym_lower(); + SYM_RESTORE_USER_STACK(user_stack); // Combine the two above so we don't have to remember to call both // but put all of user code inbetween diff --git a/src/LIDK/idk.c b/src/LIDK/idk.c index 037093a..d902172 100644 --- a/src/LIDK/idk.c +++ b/src/LIDK/idk.c @@ -54,16 +54,22 @@ void* sym_get_fn_address(char *symbol) { parse_system_map(); } + long already_elevated = sym_check_elevate(); + // Elevate to be able to call kallsyms_lookup_name - sym_elevate(); + if (!already_elevated) + sym_elevate(); + // TODO: clean this up uint64_t user_stack; SYM_PRESERVE_USER_STACK(user_stack); SYM_SWITCH_TO_KERN_STACK(); void* result = (void*)kallsyms_lookup_name(symbol); SYM_RESTORE_USER_STACK(user_stack); - // Don't forget to lower - sym_lower(); + + // Don't forget to lower + if (!already_elevated) + sym_lower(); return (void*)result; }