mirror of https://github.com/aya-rs/aya
feat(aya-obj): Support loading programs with ksyms
By default, BTF of extern functions has `extern` linkage. However, verifier is not accepting functions with other linkages than `global` and `static`. Fixup of sizes and offsets of ksyms can't be retrieved from ELF. Instead, the size of an unsigned integer is used for all types which were found in the ksyms section. Based on similar fixups which are done in libbpf.[0] [0] https://github.com/torvalds/linux/commit/5bd022ec01f06 Fixes #1245pull/1265/head
parent
583709f6a0
commit
44f777bd5b
@ -0,0 +1,30 @@
|
||||
// clang-format off
|
||||
#include <vmlinux.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_core_read.h>
|
||||
#include <bpf/bpf_tracing.h>
|
||||
// clang-format on
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
||||
struct {
|
||||
__uint(type, BPF_MAP_TYPE_TASK_STORAGE);
|
||||
__uint(map_flags, BPF_F_NO_PREALLOC);
|
||||
__type(key, int);
|
||||
__type(value, __u32);
|
||||
} task_storage SEC(".maps");
|
||||
|
||||
extern void bpf_rcu_read_lock(void) __ksym;
|
||||
extern void bpf_rcu_read_unlock(void) __ksym;
|
||||
|
||||
SEC("tp_btf/sys_enter")
|
||||
int BPF_PROG(sys_enter, struct pt_regs *regs, long id) {
|
||||
__u32 value = 1;
|
||||
struct task_struct *task = bpf_get_current_task_btf();
|
||||
bpf_rcu_read_lock();
|
||||
struct task_struct *group_leader = task->group_leader;
|
||||
bpf_task_storage_get(&task_storage, group_leader, &value,
|
||||
BPF_LOCAL_STORAGE_GET_F_CREATE);
|
||||
bpf_rcu_read_unlock();
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
use aya::{Btf, Ebpf, programs::BtfTracePoint};
|
||||
use test_log::test;
|
||||
|
||||
#[test]
|
||||
fn test_ksym() {
|
||||
let mut ebpf = Ebpf::load(crate::KSYM).unwrap();
|
||||
|
||||
let prog: &mut BtfTracePoint = ebpf.program_mut("sys_enter").unwrap().try_into().unwrap();
|
||||
let btf = Btf::from_sys_fs().unwrap();
|
||||
prog.load("sys_enter", &btf).unwrap();
|
||||
prog.attach().unwrap();
|
||||
}
|
Loading…
Reference in New Issue