mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
add global support with broken generation function
This commit is contained in:
@ -0,0 +1,27 @@
|
||||
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
|
||||
#include <linux/bpf.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_tracing.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
struct test_struct {
|
||||
__u64 a;
|
||||
__u64 b;
|
||||
};
|
||||
|
||||
struct test_struct w = {};
|
||||
volatile __u64 prev_time = 0;
|
||||
|
||||
SEC("tracepoint/syscalls/sys_enter_execve")
|
||||
int trace_execve(void *ctx)
|
||||
{
|
||||
bpf_printk("previous %ul now %ul", w.b, w.a);
|
||||
__u64 ts = bpf_ktime_get_ns();
|
||||
bpf_printk("prev %ul now %ul", prev_time, ts);
|
||||
w.a = ts;
|
||||
w.b = prev_time;
|
||||
prev_time = ts;
|
||||
return 0;
|
||||
}
|
||||
|
||||
char LICENSE[] SEC("license") = "GPL";
|
||||
|
||||
@ -0,0 +1,23 @@
|
||||
import logging
|
||||
|
||||
from pythonbpf import compile, bpf, section, bpfglobal, compile_to_ir
|
||||
from ctypes import c_void_p, c_int64
|
||||
|
||||
@bpf
|
||||
@bpfglobal
|
||||
def somevalue() -> c_int64:
|
||||
return c_int64(0)
|
||||
|
||||
@bpf
|
||||
@section("sometag1")
|
||||
def sometag(ctx: c_void_p) -> c_int64:
|
||||
return c_int64(0)
|
||||
|
||||
@bpf
|
||||
@bpfglobal
|
||||
def LICENSE() -> str:
|
||||
return "GPL"
|
||||
|
||||
|
||||
compile_to_ir("globals.py", "globals.ll", loglevel=logging.INFO)
|
||||
compile()
|
||||
|
||||
Reference in New Issue
Block a user