Re: [PATCH v4 11/39] unwind_user: Add user space unwinding API

From: Steven Rostedt
Date: Fri Jan 24 2025 - 15:02:14 EST


On Tue, 21 Jan 2025 18:31:03 -0800
Josh Poimboeuf <jpoimboe@xxxxxxxxxx> wrote:

> +int unwind_user_next(struct unwind_user_state *state)
> +{
> + struct unwind_user_frame _frame;
> + struct unwind_user_frame *frame = &_frame;
> + unsigned long cfa = 0, fp, ra = 0;
> +
> + /* no implementation yet */
> + -EINVAL;
> +}
> +
> +int unwind_user_start(struct unwind_user_state *state)
> +{
> + struct pt_regs *regs = task_pt_regs(current);
> +
> + memset(state, 0, sizeof(*state));
> +
> + if (!current->mm || !user_mode(regs)) {
> + state->done = true;
> + return -EINVAL;
> + }
> +
> + state->type = UNWIND_USER_TYPE_NONE;
> +
> + state->ip = instruction_pointer(regs);
> + state->sp = user_stack_pointer(regs);
> + state->fp = frame_pointer(regs);
> +
> + return 0;
> +}
> +

I know this is just an introductory of the interface, but this should
really have kerneldoc attached to it, as I have no idea what these are
supposed to be doing. This patch is meaningless without it. The change log
is useless too.

-- Steve


> +int unwind_user(struct unwind_stacktrace *trace, unsigned int max_entries)
> +{
> + struct unwind_user_state state;
> +
> + trace->nr = 0;
> +
> + if (!max_entries)
> + return -EINVAL;
> +
> + if (!current->mm)
> + return 0;
> +
> + for_each_user_frame(&state) {
> + trace->entries[trace->nr++] = state.ip;
> + if (trace->nr >= max_entries)
> + break;
> + }
> +
> + return 0;
> +}