mirror of
https://github.com/netdata/libbpf.git
synced 2026-03-23 17:59:06 +08:00
sync: auto-generate latest BPF helpers
Latest changes to BPF helper definitions.
This commit is contained in:
committed by
Andrii Nakryiko
parent
df45cf7a3e
commit
67ab4c0f82
@@ -68,12 +68,15 @@ static int (*bpf_map_delete_elem)(void *map, const void *key) = (void *) 3;
|
||||
* bpf_probe_read
|
||||
*
|
||||
* For tracing programs, safely attempt to read *size* bytes from
|
||||
* address *src* and store the data in *dst*.
|
||||
* kernel space address *unsafe_ptr* and store the data in *dst*.
|
||||
*
|
||||
* Generally, use bpf_probe_read_user() or bpf_probe_read_kernel()
|
||||
* instead.
|
||||
*
|
||||
* Returns
|
||||
* 0 on success, or a negative error in case of failure.
|
||||
*/
|
||||
static int (*bpf_probe_read)(void *dst, __u32 size, const void *src) = (void *) 4;
|
||||
static int (*bpf_probe_read)(void *dst, __u32 size, const void *unsafe_ptr) = (void *) 4;
|
||||
|
||||
/*
|
||||
* bpf_ktime_get_ns
|
||||
@@ -1099,50 +1102,19 @@ static int (*bpf_xdp_adjust_head)(struct xdp_md *xdp_md, int delta) = (void *) 4
|
||||
/*
|
||||
* bpf_probe_read_str
|
||||
*
|
||||
* Copy a NUL terminated string from an unsafe address
|
||||
* *unsafe_ptr* to *dst*. The *size* should include the
|
||||
* terminating NUL byte. In case the string length is smaller than
|
||||
* *size*, the target is not padded with further NUL bytes. If the
|
||||
* string length is larger than *size*, just *size*-1 bytes are
|
||||
* copied and the last byte is set to NUL.
|
||||
* Copy a NUL terminated string from an unsafe kernel address
|
||||
* *unsafe_ptr* to *dst*. See bpf_probe_read_kernel_str() for
|
||||
* more details.
|
||||
*
|
||||
* On success, the length of the copied string is returned. This
|
||||
* makes this helper useful in tracing programs for reading
|
||||
* strings, and more importantly to get its length at runtime. See
|
||||
* the following snippet:
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* SEC("kprobe/sys_open")
|
||||
* void bpf_sys_open(struct pt_regs *ctx)
|
||||
* {
|
||||
* char buf[PATHLEN]; // PATHLEN is defined to 256
|
||||
* int res = bpf_probe_read_str(buf, sizeof(buf),
|
||||
* ctx->di);
|
||||
*
|
||||
* // Consume buf, for example push it to
|
||||
* // userspace via bpf_perf_event_output(); we
|
||||
* // can use res (the string length) as event
|
||||
* // size, after checking its boundaries.
|
||||
* }
|
||||
*
|
||||
* In comparison, using **bpf_probe_read()** helper here instead
|
||||
* to read the string would require to estimate the length at
|
||||
* compile time, and would often result in copying more memory
|
||||
* than necessary.
|
||||
*
|
||||
* Another useful use case is when parsing individual process
|
||||
* arguments or individual environment variables navigating
|
||||
* *current*\ **->mm->arg_start** and *current*\
|
||||
* **->mm->env_start**: using this helper and the return value,
|
||||
* one can quickly iterate at the right offset of the memory area.
|
||||
* Generally, use bpf_probe_read_user_str() or bpf_probe_read_kernel_str()
|
||||
* instead.
|
||||
*
|
||||
* Returns
|
||||
* On success, the strictly positive length of the string,
|
||||
* including the trailing NUL character. On error, a negative
|
||||
* value.
|
||||
*/
|
||||
static int (*bpf_probe_read_str)(void *dst, int size, const void *unsafe_ptr) = (void *) 45;
|
||||
static int (*bpf_probe_read_str)(void *dst, __u32 size, const void *unsafe_ptr) = (void *) 45;
|
||||
|
||||
/*
|
||||
* bpf_get_socket_cookie
|
||||
@@ -2702,4 +2674,86 @@ static __s64 (*bpf_tcp_gen_syncookie)(struct bpf_sock *sk, void *iph, __u32 iph_
|
||||
*/
|
||||
static int (*bpf_skb_output)(void *ctx, void *map, __u64 flags, void *data, __u64 size) = (void *) 111;
|
||||
|
||||
/*
|
||||
* bpf_probe_read_user
|
||||
*
|
||||
* Safely attempt to read *size* bytes from user space address
|
||||
* *unsafe_ptr* and store the data in *dst*.
|
||||
*
|
||||
* Returns
|
||||
* 0 on success, or a negative error in case of failure.
|
||||
*/
|
||||
static int (*bpf_probe_read_user)(void *dst, __u32 size, const void *unsafe_ptr) = (void *) 112;
|
||||
|
||||
/*
|
||||
* bpf_probe_read_kernel
|
||||
*
|
||||
* Safely attempt to read *size* bytes from kernel space address
|
||||
* *unsafe_ptr* and store the data in *dst*.
|
||||
*
|
||||
* Returns
|
||||
* 0 on success, or a negative error in case of failure.
|
||||
*/
|
||||
static int (*bpf_probe_read_kernel)(void *dst, __u32 size, const void *unsafe_ptr) = (void *) 113;
|
||||
|
||||
/*
|
||||
* bpf_probe_read_user_str
|
||||
*
|
||||
* Copy a NUL terminated string from an unsafe user address
|
||||
* *unsafe_ptr* to *dst*. The *size* should include the
|
||||
* terminating NUL byte. In case the string length is smaller than
|
||||
* *size*, the target is not padded with further NUL bytes. If the
|
||||
* string length is larger than *size*, just *size*-1 bytes are
|
||||
* copied and the last byte is set to NUL.
|
||||
*
|
||||
* On success, the length of the copied string is returned. This
|
||||
* makes this helper useful in tracing programs for reading
|
||||
* strings, and more importantly to get its length at runtime. See
|
||||
* the following snippet:
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* SEC("kprobe/sys_open")
|
||||
* void bpf_sys_open(struct pt_regs *ctx)
|
||||
* {
|
||||
* char buf[PATHLEN]; // PATHLEN is defined to 256
|
||||
* int res = bpf_probe_read_user_str(buf, sizeof(buf),
|
||||
* ctx->di);
|
||||
*
|
||||
* // Consume buf, for example push it to
|
||||
* // userspace via bpf_perf_event_output(); we
|
||||
* // can use res (the string length) as event
|
||||
* // size, after checking its boundaries.
|
||||
* }
|
||||
*
|
||||
* In comparison, using **bpf_probe_read_user()** helper here
|
||||
* instead to read the string would require to estimate the length
|
||||
* at compile time, and would often result in copying more memory
|
||||
* than necessary.
|
||||
*
|
||||
* Another useful use case is when parsing individual process
|
||||
* arguments or individual environment variables navigating
|
||||
* *current*\ **->mm->arg_start** and *current*\
|
||||
* **->mm->env_start**: using this helper and the return value,
|
||||
* one can quickly iterate at the right offset of the memory area.
|
||||
*
|
||||
* Returns
|
||||
* On success, the strictly positive length of the string,
|
||||
* including the trailing NUL character. On error, a negative
|
||||
* value.
|
||||
*/
|
||||
static int (*bpf_probe_read_user_str)(void *dst, __u32 size, const void *unsafe_ptr) = (void *) 114;
|
||||
|
||||
/*
|
||||
* bpf_probe_read_kernel_str
|
||||
*
|
||||
* Copy a NUL terminated string from an unsafe kernel address *unsafe_ptr*
|
||||
* to *dst*. Same semantics as with bpf_probe_read_user_str() apply.
|
||||
*
|
||||
* Returns
|
||||
* On success, the strictly positive length of the string, including
|
||||
* the trailing NUL character. On error, a negative value.
|
||||
*/
|
||||
static int (*bpf_probe_read_kernel_str)(void *dst, __u32 size, const void *unsafe_ptr) = (void *) 115;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user