mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Fix imports and type issues for bpf_probe_read
This commit is contained in:
@ -1,7 +1,17 @@
|
||||
from .helper_registry import HelperHandlerRegistry
|
||||
from .helper_utils import reset_scratch_pool
|
||||
from .bpf_helper_handler import handle_helper_call, emit_probe_read_kernel_str_call
|
||||
from .helpers import ktime, pid, deref, comm, probe_read_str, random, XDP_DROP, XDP_PASS
|
||||
from .helpers import (
|
||||
ktime,
|
||||
pid,
|
||||
deref,
|
||||
comm,
|
||||
probe_read_str,
|
||||
random,
|
||||
probe_read,
|
||||
XDP_DROP,
|
||||
XDP_PASS,
|
||||
)
|
||||
|
||||
|
||||
# Register the helper handler with expr module
|
||||
@ -66,6 +76,7 @@ __all__ = [
|
||||
"comm",
|
||||
"probe_read_str",
|
||||
"random",
|
||||
"probe_read",
|
||||
"XDP_DROP",
|
||||
"XDP_PASS",
|
||||
]
|
||||
|
||||
@ -476,23 +476,20 @@ def bpf_probe_read_emitter(
|
||||
if len(call.args) != 3:
|
||||
logger.warn("Expected 3 args for probe_read helper")
|
||||
return
|
||||
dst_ptr, _ = get_ptr_from_arg(
|
||||
call.args[0], func, module, builder, local_sym_tab, map_sym_tab, struct_sym_tab
|
||||
dst_ptr = get_or_create_ptr_from_arg(
|
||||
func, module, call.args[0], builder, local_sym_tab, map_sym_tab, struct_sym_tab
|
||||
)
|
||||
size_val = (
|
||||
get_int_value_from_arg(
|
||||
call.args[1],
|
||||
func,
|
||||
module,
|
||||
builder,
|
||||
local_sym_tab,
|
||||
map_sym_tab,
|
||||
struct_sym_tab,
|
||||
)
|
||||
& 0xFFFFFFFF
|
||||
size_val = get_int_value_from_arg(
|
||||
call.args[1],
|
||||
func,
|
||||
module,
|
||||
builder,
|
||||
local_sym_tab,
|
||||
map_sym_tab,
|
||||
struct_sym_tab,
|
||||
)
|
||||
src_ptr, _ = get_ptr_from_arg(
|
||||
call.args[2], func, module, builder, local_sym_tab, map_sym_tab, struct_sym_tab
|
||||
src_ptr = get_or_create_ptr_from_arg(
|
||||
func, module, call.args[2], builder, local_sym_tab, map_sym_tab, struct_sym_tab
|
||||
)
|
||||
fn_type = ir.FunctionType(
|
||||
ir.IntType(64),
|
||||
@ -507,7 +504,7 @@ def bpf_probe_read_emitter(
|
||||
fn_ptr,
|
||||
[
|
||||
builder.bitcast(dst_ptr, ir.PointerType()),
|
||||
ir.Constant(ir.IntType(32), size_val),
|
||||
builder.trunc(size_val, ir.IntType(32)),
|
||||
builder.bitcast(src_ptr, ir.PointerType()),
|
||||
],
|
||||
tail=False,
|
||||
|
||||
@ -32,6 +32,11 @@ def random():
|
||||
return ctypes.c_int32(0)
|
||||
|
||||
|
||||
def probe_read(dst, size, src):
|
||||
"""Safely read data from kernel memory"""
|
||||
return ctypes.c_int64(0)
|
||||
|
||||
|
||||
XDP_ABORTED = ctypes.c_int64(0)
|
||||
XDP_DROP = ctypes.c_int64(1)
|
||||
XDP_PASS = ctypes.c_int64(2)
|
||||
|
||||
Reference in New Issue
Block a user