mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 18:08:36 +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>
24 lines
563 B
Python
24 lines
563 B
Python
# A helper's value carries the sign its registry entry declares: ktime()
|
|
# and pid() are unsigned, so a right shift is logical and a division is
|
|
# unsigned, the same as for a c_uint64 local.
|
|
from pythonbpf import bpf, section, bpfglobal, compile
|
|
from pythonbpf.helper import ktime, pid
|
|
from ctypes import c_void_p, c_int64
|
|
|
|
|
|
@bpf
|
|
@section("tracepoint/raw_syscalls/sys_enter")
|
|
def prog(ctx: c_void_p) -> c_int64:
|
|
t = ktime() >> 1 # lshr
|
|
q = pid() // 3 # udiv
|
|
return c_int64(t + q)
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def LICENSE() -> str:
|
|
return "GPL"
|
|
|
|
|
|
compile()
|