From 627ee9265afa3e3c22fa01591ae439fd51797d5b Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Mon, 8 Sep 2025 20:06:21 +0530 Subject: [PATCH] fix: Hashmap type check --- examples/c-form/ex2.bpf.c | 8 ++++++++ examples/execve2.py | 3 ++- pythonbpf/functions_pass.py | 3 --- pythonbpf/maps.py | 8 ++++++++ 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 pythonbpf/maps.py diff --git a/examples/c-form/ex2.bpf.c b/examples/c-form/ex2.bpf.c index 8cc9a97..f708248 100644 --- a/examples/c-form/ex2.bpf.c +++ b/examples/c-form/ex2.bpf.c @@ -1,5 +1,13 @@ #include #include +#define u64 unsigned long long + +struct { + __uint(type, BPF_MAP_TYPE_HASH); + __uint(max_entries, 1); + __type(key, u64); + __type(value, u64); +} last SEC(".maps"); SEC("tracepoint/syscalls/sys_enter_execve") int hello(struct pt_regs *ctx) { diff --git a/examples/execve2.py b/examples/execve2.py index 67191f0..73e71ec 100644 --- a/examples/execve2.py +++ b/examples/execve2.py @@ -1,6 +1,7 @@ from pythonbpf.decorators import bpf, bpfglobal, section -from ctypes import c_void_p, c_int64, c_int32 +from ctypes import c_void_p, c_int64, c_int32, c_uint64 from pythonbpf.helpers import bpf_ktime_get_ns +from pythonbpf.maps import HashMap @bpf diff --git a/pythonbpf/functions_pass.py b/pythonbpf/functions_pass.py index b8baa49..f339b84 100644 --- a/pythonbpf/functions_pass.py +++ b/pythonbpf/functions_pass.py @@ -56,9 +56,6 @@ def process_bpf_chunk(func_node, module, return_type): func_name = func_node.name - # TODO: The function actual arg retgurn type is parsed, - # but the actual output is not. It's still very wrong. Try uncommenting the - # code in execve2.py once ret_type = return_type # TODO: parse parameters diff --git a/pythonbpf/maps.py b/pythonbpf/maps.py new file mode 100644 index 0000000..585d9c8 --- /dev/null +++ b/pythonbpf/maps.py @@ -0,0 +1,8 @@ +class HashMap: + def __init__(self, key_type, value_type, max_entries): + self.key_type = key_type + self.value_type = value_type + self.max_entries = max_entries + self.entries = {} + + # add other supported map functions here