Skip to content

find user pt_regs from task_struct #13

@dvc94ch

Description

@dvc94ch

not so hard in C but tricky in rust. needed for flamegraphing kprobe's and tracepoint and adding the kernel part to profile.

iovisor/bcc#2073

struct task_struct* __current = (struct task_struct*)bpf_get_current_task();
void* __current_stack_page = __current->stack;
void* __ptr = __current_stack_page + THREAD_SIZE - TOP_OF_KERNEL_STACK_PADDING;
struct pt_regs* _tctx = ((struct pt_regs *)__ptr) - 1;

THREAD_SIZE should be 2 * PAGE_SIZE and PAGE_SIZE 4096
TOP_OF_KERNEL_STACK_PADDING should be 0 on x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions