Skip to content

Commit 054a834

Browse files
committed
Add failing assign test retype.py, with explanation
1 parent d7bfe86 commit 054a834

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from pythonbpf import bpf, map, section, bpfglobal, compile
2+
from ctypes import c_void_p, c_int64, c_uint64
3+
from pythonbpf.maps import HashMap
4+
5+
6+
# NOTE: This example tries to reinterpret the variable `x` to a different type.
7+
# We do not allow this for now, as stack allocations are typed and have to be
8+
# done in the first basic block. Allowing re-interpretation would require
9+
# re-allocation of stack space (possibly in a new basic block), which is not
10+
# supported in eBPF yet.
11+
# We can allow bitcasts in cases where the width of the types is the same in
12+
# the future. But for now, we do not allow any re-interpretation of variables.
13+
14+
@bpf
15+
@map
16+
def last() -> HashMap:
17+
return HashMap(key=c_uint64, value=c_uint64, max_entries=3)
18+
19+
20+
@bpf
21+
@section("tracepoint/syscalls/sys_enter_execve")
22+
def hello_world(ctx: c_void_p) -> c_int64:
23+
last.update(0, 1)
24+
x = last.lookup(0)
25+
x = 20
26+
if x == 2:
27+
print("Hello, World!")
28+
else:
29+
print("Goodbye, World!")
30+
return
31+
32+
33+
@bpf
34+
@bpfglobal
35+
def LICENSE() -> str:
36+
return "GPL"
37+
38+
39+
compile()

0 commit comments

Comments
 (0)