mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 09:58:34 +00:00
Compare commits
10 Commits
testing-fr
...
v0.1.9
| Author | SHA1 | Date | |
|---|---|---|---|
| 5311a16c21 | |||
| 8c5069f424 | |||
| 5a9c77f016 | |||
| d0f7a9dcec | |||
| 0dea1836df | |||
| 7cdb9cb2f5 | |||
| 0482aa2be9 | |||
| d4f1b5a9b4 | |||
| c2de7dad96 | |||
| d1bb0191c9 |
2
Makefile
2
Makefile
@ -7,7 +7,7 @@ clean:
|
|||||||
rm -rf htmlcov .coverage
|
rm -rf htmlcov .coverage
|
||||||
|
|
||||||
test:
|
test:
|
||||||
pytest tests/ -v --tb=short -m "not verifier"
|
pytest tests/ -W ignore::DeprecationWarning -v --tb=short -m "not verifier"
|
||||||
|
|
||||||
test-cov:
|
test-cov:
|
||||||
pytest tests/ -v --tb=short -m "not verifier" \
|
pytest tests/ -v --tb=short -m "not verifier" \
|
||||||
|
|||||||
@ -15,8 +15,8 @@ sys.path.insert(0, os.path.abspath(".."))
|
|||||||
project = "PythonBPF"
|
project = "PythonBPF"
|
||||||
copyright = "2026, Pragyansh Chaturvedi, Varun Mallya"
|
copyright = "2026, Pragyansh Chaturvedi, Varun Mallya"
|
||||||
author = "Pragyansh Chaturvedi, Varun Mallya"
|
author = "Pragyansh Chaturvedi, Varun Mallya"
|
||||||
release = "0.1.8"
|
release = "0.1.9"
|
||||||
version = "0.1.8"
|
version = "0.1.9"
|
||||||
|
|
||||||
# -- General configuration ---------------------------------------------------
|
# -- General configuration ---------------------------------------------------
|
||||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
||||||
|
|||||||
@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "pythonbpf"
|
name = "pythonbpf"
|
||||||
version = "0.1.8"
|
version = "0.1.9"
|
||||||
description = "Reduced Python frontend for eBPF"
|
description = "Reduced Python frontend for eBPF"
|
||||||
authors = [
|
authors = [
|
||||||
{ name = "r41k0u", email="pragyanshchaturvedi18@gmail.com" },
|
{ name = "r41k0u", email="pragyanshchaturvedi18@gmail.com" },
|
||||||
|
|||||||
@ -26,7 +26,7 @@ import re
|
|||||||
|
|
||||||
logger: Logger = logging.getLogger(__name__)
|
logger: Logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
VERSION = "v0.1.8"
|
VERSION = "v0.1.9"
|
||||||
|
|
||||||
|
|
||||||
def finalize_module(original_str):
|
def finalize_module(original_str):
|
||||||
|
|||||||
@ -11,7 +11,7 @@ def deref_to_depth(func, builder, val, target_depth):
|
|||||||
cur_type = val.type
|
cur_type = val.type
|
||||||
|
|
||||||
for depth in range(target_depth):
|
for depth in range(target_depth):
|
||||||
if not isinstance(val.type, ir.PointerType):
|
if not isinstance(cur_type, ir.PointerType):
|
||||||
logger.error("Cannot dereference further, non-pointer type")
|
logger.error("Cannot dereference further, non-pointer type")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@ -113,7 +113,12 @@ def bpf_map_lookup_elem_emitter(
|
|||||||
f"Map lookup expects exactly one argument (key), got {len(call.args)}"
|
f"Map lookup expects exactly one argument (key), got {len(call.args)}"
|
||||||
)
|
)
|
||||||
key_ptr = get_or_create_ptr_from_arg(
|
key_ptr = get_or_create_ptr_from_arg(
|
||||||
func, compilation_context, call.args[0], builder, local_sym_tab
|
func,
|
||||||
|
compilation_context,
|
||||||
|
call.args[0],
|
||||||
|
builder,
|
||||||
|
local_sym_tab,
|
||||||
|
expected_type=ir.IntType(64),
|
||||||
)
|
)
|
||||||
map_void_ptr = builder.bitcast(map_ptr, ir.PointerType())
|
map_void_ptr = builder.bitcast(map_ptr, ir.PointerType())
|
||||||
|
|
||||||
@ -215,10 +220,20 @@ def bpf_map_update_elem_emitter(
|
|||||||
flags_arg = call.args[2] if len(call.args) > 2 else None
|
flags_arg = call.args[2] if len(call.args) > 2 else None
|
||||||
|
|
||||||
key_ptr = get_or_create_ptr_from_arg(
|
key_ptr = get_or_create_ptr_from_arg(
|
||||||
func, compilation_context, key_arg, builder, local_sym_tab
|
func,
|
||||||
|
compilation_context,
|
||||||
|
key_arg,
|
||||||
|
builder,
|
||||||
|
local_sym_tab,
|
||||||
|
expected_type=ir.IntType(64),
|
||||||
)
|
)
|
||||||
value_ptr = get_or_create_ptr_from_arg(
|
value_ptr = get_or_create_ptr_from_arg(
|
||||||
func, compilation_context, value_arg, builder, local_sym_tab
|
func,
|
||||||
|
compilation_context,
|
||||||
|
value_arg,
|
||||||
|
builder,
|
||||||
|
local_sym_tab,
|
||||||
|
expected_type=ir.IntType(64),
|
||||||
)
|
)
|
||||||
flags_val = get_flags_val(flags_arg, builder, local_sym_tab)
|
flags_val = get_flags_val(flags_arg, builder, local_sym_tab)
|
||||||
|
|
||||||
@ -267,7 +282,12 @@ def bpf_map_delete_elem_emitter(
|
|||||||
f"Map delete expects exactly one argument (key), got {len(call.args)}"
|
f"Map delete expects exactly one argument (key), got {len(call.args)}"
|
||||||
)
|
)
|
||||||
key_ptr = get_or_create_ptr_from_arg(
|
key_ptr = get_or_create_ptr_from_arg(
|
||||||
func, compilation_context, call.args[0], builder, local_sym_tab
|
func,
|
||||||
|
compilation_context,
|
||||||
|
call.args[0],
|
||||||
|
builder,
|
||||||
|
local_sym_tab,
|
||||||
|
expected_type=ir.IntType(64),
|
||||||
)
|
)
|
||||||
map_void_ptr = builder.bitcast(map_ptr, ir.PointerType())
|
map_void_ptr = builder.bitcast(map_ptr, ir.PointerType())
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,8 @@ from pythonbpf.expr import (
|
|||||||
eval_expr,
|
eval_expr,
|
||||||
access_struct_field,
|
access_struct_field,
|
||||||
)
|
)
|
||||||
|
from pythonbpf.expr.ir_ops import deref_to_depth
|
||||||
|
from pythonbpf.expr.type_normalization import get_base_type_and_depth
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -104,6 +106,18 @@ def get_or_create_ptr_from_arg(
|
|||||||
if val is None:
|
if val is None:
|
||||||
raise ValueError("Failed to evaluate expression for helper arg.")
|
raise ValueError("Failed to evaluate expression for helper arg.")
|
||||||
|
|
||||||
|
if expected_type and isinstance(val.type, ir.PointerType):
|
||||||
|
_, val_depth = get_base_type_and_depth(val.type)
|
||||||
|
_, expected_depth = get_base_type_and_depth(expected_type)
|
||||||
|
if val_depth > expected_depth:
|
||||||
|
val = deref_to_depth(func, builder, val, val_depth - expected_depth)
|
||||||
|
if val is None:
|
||||||
|
raise ValueError("Failed to dereference pointer to expected depth")
|
||||||
|
else:
|
||||||
|
logger.debug(
|
||||||
|
"Expected Type not known / Not a pointer, skipping dereference"
|
||||||
|
)
|
||||||
|
|
||||||
ptr, temp_name = compilation_context.scratch_pool.get_next_temp(
|
ptr, temp_name = compilation_context.scratch_pool.get_next_temp(
|
||||||
local_sym_tab, expected_type
|
local_sym_tab, expected_type
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user