mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Implement bpf_get_stack handler
This commit is contained in:
@ -12,6 +12,7 @@ from .helpers import (
|
|||||||
smp_processor_id,
|
smp_processor_id,
|
||||||
uid,
|
uid,
|
||||||
skb_store_bytes,
|
skb_store_bytes,
|
||||||
|
get_stack,
|
||||||
XDP_DROP,
|
XDP_DROP,
|
||||||
XDP_PASS,
|
XDP_PASS,
|
||||||
)
|
)
|
||||||
@ -83,6 +84,7 @@ __all__ = [
|
|||||||
"smp_processor_id",
|
"smp_processor_id",
|
||||||
"uid",
|
"uid",
|
||||||
"skb_store_bytes",
|
"skb_store_bytes",
|
||||||
|
"get_stack",
|
||||||
"XDP_DROP",
|
"XDP_DROP",
|
||||||
"XDP_PASS",
|
"XDP_PASS",
|
||||||
]
|
]
|
||||||
|
|||||||
@ -956,8 +956,37 @@ def bpf_get_stack_emitter(
|
|||||||
struct_sym_tab=None,
|
struct_sym_tab=None,
|
||||||
map_sym_tab=None,
|
map_sym_tab=None,
|
||||||
):
|
):
|
||||||
# TODO: Implement bpf_get_stack emitter
|
if len(call.args) not in (1, 2):
|
||||||
pass
|
raise ValueError(
|
||||||
|
f"get_stack expects atmost two arguments (buf, flags), got {len(call.args)}"
|
||||||
|
)
|
||||||
|
ctx_ptr = func.args[0] # First argument to the function is ctx
|
||||||
|
buf_arg = call.args[0]
|
||||||
|
flags_arg = call.args[1] if len(call.args) == 2 else 0
|
||||||
|
buf_ptr, buf_size = get_buffer_ptr_and_size(
|
||||||
|
buf_arg, builder, local_sym_tab, struct_sym_tab
|
||||||
|
)
|
||||||
|
flags_val = get_flags_val(flags_arg, builder, local_sym_tab)
|
||||||
|
buf_void_ptr = builder.bitcast(buf_ptr, ir.PointerType())
|
||||||
|
fn_type = ir.FunctionType(
|
||||||
|
ir.IntType(64),
|
||||||
|
[
|
||||||
|
ir.PointerType(ir.IntType(8)),
|
||||||
|
ir.PointerType(),
|
||||||
|
ir.IntType(64),
|
||||||
|
ir.IntType(64),
|
||||||
|
],
|
||||||
|
var_arg=False,
|
||||||
|
)
|
||||||
|
fn_ptr_type = ir.PointerType(fn_type)
|
||||||
|
fn_addr = ir.Constant(ir.IntType(64), BPFHelperID.BPF_GET_STACK.value)
|
||||||
|
fn_ptr = builder.inttoptr(fn_addr, fn_ptr_type)
|
||||||
|
result = builder.call(
|
||||||
|
fn_ptr,
|
||||||
|
[ctx_ptr, buf_void_ptr, ir.Constant(ir.IntType(64), buf_size), flags_val],
|
||||||
|
tail=False,
|
||||||
|
)
|
||||||
|
return result, ir.IntType(64)
|
||||||
|
|
||||||
|
|
||||||
def handle_helper_call(
|
def handle_helper_call(
|
||||||
|
|||||||
@ -52,6 +52,11 @@ def skb_store_bytes(offset, from_buf, size, flags=0):
|
|||||||
return ctypes.c_int64(0)
|
return ctypes.c_int64(0)
|
||||||
|
|
||||||
|
|
||||||
|
def get_stack(buf, flags=0):
|
||||||
|
"""get the current stack trace"""
|
||||||
|
return ctypes.c_int64(0)
|
||||||
|
|
||||||
|
|
||||||
XDP_ABORTED = ctypes.c_int64(0)
|
XDP_ABORTED = ctypes.c_int64(0)
|
||||||
XDP_DROP = ctypes.c_int64(1)
|
XDP_DROP = ctypes.c_int64(1)
|
||||||
XDP_PASS = ctypes.c_int64(2)
|
XDP_PASS = ctypes.c_int64(2)
|
||||||
|
|||||||
Reference in New Issue
Block a user