mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
add ringbuf reserve function
This commit is contained in:
@ -28,22 +28,22 @@ int trace_execve(void *ctx)
|
||||
|
||||
// Reserve space in the ringbuffer
|
||||
e = bpf_ringbuf_reserve(&events, sizeof(*e), 0);
|
||||
if (!e)
|
||||
return 0;
|
||||
|
||||
// Fill the struct with data
|
||||
pid_tgid = bpf_get_current_pid_tgid();
|
||||
e->pid = pid_tgid >> 32;
|
||||
|
||||
uid_gid = bpf_get_current_uid_gid();
|
||||
e->uid = uid_gid & 0xFFFFFFFF;
|
||||
|
||||
e->timestamp = bpf_ktime_get_ns();
|
||||
|
||||
bpf_get_current_comm(&e->comm, sizeof(e->comm));
|
||||
|
||||
// Submit the event to ringbuffer
|
||||
bpf_ringbuf_submit(e, 0);
|
||||
// if (!e)
|
||||
// return 0;
|
||||
//
|
||||
// // Fill the struct with data
|
||||
// pid_tgid = bpf_get_current_pid_tgid();
|
||||
// e->pid = pid_tgid >> 32;
|
||||
//
|
||||
// uid_gid = bpf_get_current_uid_gid();
|
||||
// e->uid = uid_gid & 0xFFFFFFFF;
|
||||
//
|
||||
// e->timestamp = bpf_ktime_get_ns();
|
||||
//
|
||||
// bpf_get_current_comm(&e->comm, sizeof(e->comm));
|
||||
//
|
||||
// // Submit the event to ringbuffer
|
||||
// bpf_ringbuf_submit(e, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from pythonbpf import bpf, BPF, map, bpfglobal, section, compile, compile_to_ir
|
||||
from pythonbpf.maps import RingBuf, HashMap
|
||||
from pythonbpf import bpf, map, bpfglobal, section, compile, compile_to_ir
|
||||
from pythonbpf.maps import RingBuf
|
||||
from ctypes import c_int32, c_void_p
|
||||
|
||||
|
||||
@ -9,17 +9,11 @@ from ctypes import c_int32, c_void_p
|
||||
def mymap() -> RingBuf:
|
||||
return RingBuf(max_entries=(1024))
|
||||
|
||||
|
||||
@bpf
|
||||
@map
|
||||
def mymap2() -> HashMap:
|
||||
return HashMap(key=c_int32, value=c_int32, max_entries=1024)
|
||||
|
||||
|
||||
@bpf
|
||||
@section("tracepoint/syscalls/sys_enter_clone")
|
||||
def random_section(ctx: c_void_p) -> c_int32:
|
||||
print("Hello")
|
||||
e = mymap().reserve(16)
|
||||
return c_int32(0)
|
||||
|
||||
|
||||
@ -31,5 +25,3 @@ def LICENSE() -> str:
|
||||
|
||||
compile_to_ir("ringbuf.py", "ringbuf.ll")
|
||||
compile()
|
||||
b = BPF()
|
||||
b.load_and_attach()
|
||||
|
||||
Reference in New Issue
Block a user