Skip to content

Latest commit

 

History

History
51 lines (33 loc) · 2.44 KB

bpf_get_attach_cookie.md

File metadata and controls

51 lines (33 loc) · 2.44 KB
title description
Helper Function 'bpf_get_attach_cookie'
This page documents the 'bpf_get_attach_cookie' eBPF helper function, including its defintion, usage, program types that can use it, and examples.

Helper function bpf_get_attach_cookie

:octicons-tag-24: v5.15

Definition

Copyright (c) 2015 The Libbpf Authors. All rights reserved.

Get bpf_cookie value provided (optionally) during the program attachment. It might be different for each individual attachment, even if BPF program itself is the same. Expects BPF program context ctx as a first argument.

Supported for the following program types:

    - kprobe/uprobe;  - tracepoint;  - perf_event.

Returns

Value specified by user at BPF link creation/attachment time or 0, if it was not specified.

#!c static __u64 (* const bpf_get_attach_cookie)(void *ctx) = (void *) 174;

Usage

This is useful for cases when the same BPF program is used for attaching and processing invocation of different tracepoints/kprobes/uprobes in a generic fashion, but such that each invocation is distinguished from each other (e.g., BPF program can look up additional information associated with a specific kernel function without having to rely on function IP lookups). This enables new use cases to be implemented simply and efficiently that previously were possible only through code generation (and thus multiple instances of almost identical BPF program) or compilation at runtime (BCC-style) on target hosts (even more expensive resource-wise). For uprobes it is not even possible in some cases to know function IP before hand (e.g., when attaching to shared library without PID filtering, in which case base load address is not known for a library).

Program types

This helper call can be used in the following program types:

Example

!!! example "Docs could be improved" This part of the docs is incomplete, contributions are very welcome