mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
multiple map elements support
This commit is contained in:
@ -8,7 +8,7 @@ struct {
|
|||||||
__uint(type, BPF_MAP_TYPE_HASH);
|
__uint(type, BPF_MAP_TYPE_HASH);
|
||||||
__type(key, u64);
|
__type(key, u64);
|
||||||
__type(value, u64);
|
__type(value, u64);
|
||||||
__uint(max_entries, 1);
|
__uint(max_entries, 4);
|
||||||
} last SEC(".maps");
|
} last SEC(".maps");
|
||||||
|
|
||||||
// Handler for syscall entry
|
// Handler for syscall entry
|
||||||
|
|||||||
@ -8,7 +8,7 @@ from ctypes import c_void_p, c_int64, c_int32, c_uint64
|
|||||||
@bpf
|
@bpf
|
||||||
@map
|
@map
|
||||||
def last() -> HashMap:
|
def last() -> HashMap:
|
||||||
return HashMap(key_type=c_uint64, value_type=c_uint64, max_entries=1)
|
return HashMap(key_type=c_uint64, value_type=c_uint64, max_entries=3)
|
||||||
|
|
||||||
|
|
||||||
@bpf
|
@bpf
|
||||||
@ -37,7 +37,13 @@ def hello_again(ctx: c_void_p) -> c_int64:
|
|||||||
if x:
|
if x:
|
||||||
print("we did not prevail")
|
print("we did not prevail")
|
||||||
ts = ktime()
|
ts = ktime()
|
||||||
last().update(key, ts, 0)
|
last().update(key, ts)
|
||||||
|
keys = 2
|
||||||
|
last().update(keys, ts)
|
||||||
|
key = 4
|
||||||
|
last().update(key, ts)
|
||||||
|
key = 5
|
||||||
|
last().update(key, ts)
|
||||||
return c_int64(0)
|
return c_int64(0)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -74,6 +74,14 @@ def create_map_debug_info(module, map_global, map_name, map_params):
|
|||||||
"size": 32,
|
"size": 32,
|
||||||
"elements": [array_subrange]
|
"elements": [array_subrange]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
array_subrange_max_entries = module.add_debug_info("DISubrange", {"count": map_params["max_entries"]})
|
||||||
|
array_type_max_entries = module.add_debug_info("DICompositeType", {
|
||||||
|
"tag": dc.DW_TAG_array_type,
|
||||||
|
"baseType": uint_type,
|
||||||
|
"size": 32,
|
||||||
|
"elements": [array_subrange_max_entries]
|
||||||
|
})
|
||||||
|
|
||||||
# Create pointer types
|
# Create pointer types
|
||||||
type_ptr = module.add_debug_info("DIDerivedType", {
|
type_ptr = module.add_debug_info("DIDerivedType", {
|
||||||
@ -84,7 +92,7 @@ def create_map_debug_info(module, map_global, map_name, map_params):
|
|||||||
|
|
||||||
max_entries_ptr = module.add_debug_info("DIDerivedType", {
|
max_entries_ptr = module.add_debug_info("DIDerivedType", {
|
||||||
"tag": dc.DW_TAG_pointer_type,
|
"tag": dc.DW_TAG_pointer_type,
|
||||||
"baseType": array_type,
|
"baseType": array_type_max_entries,
|
||||||
"size": 64
|
"size": 64
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user