mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 01:48:35 +00:00
One IR-shape case per fix: u32 >>= / //= / %= emit lshr/udiv/urem; ktime() >> 1 and pid() // 3 emit lshr/udiv; p >> 63 on a c_uint64 map value is lshr; ctx.data - c_int32 is a u32 subtraction with the trunc/zext pair rather than a 64-bit one. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
25 lines
588 B
Python
25 lines
588 B
Python
# Augmented assignment picks its operator from the promoted type like a
|
|
# binary operation does: on a c_uint32, >>= is a logical shift and //= and
|
|
# %= are unsigned division and remainder.
|
|
from pythonbpf import bpf, section, bpfglobal, compile
|
|
from ctypes import c_void_p, c_int64, c_uint32
|
|
|
|
|
|
@bpf
|
|
@section("tracepoint/raw_syscalls/sys_enter")
|
|
def prog(ctx: c_void_p) -> c_int64:
|
|
u = c_uint32(0xF0000000)
|
|
u >>= 4 # lshr: 0x0F000000, not sign-filled
|
|
u //= 3 # udiv
|
|
u %= 7 # urem
|
|
return c_int64(u)
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def LICENSE() -> str:
|
|
return "GPL"
|
|
|
|
|
|
compile()
|