allow casting

This commit is contained in:
2025-11-21 20:11:35 +05:30
parent fde8eab775
commit 25394059a6
5 changed files with 91 additions and 13 deletions

View File

@ -1,15 +1,18 @@
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_core_read.h>
char LICENSE[] SEC("license") = "GPL";
SEC("kprobe/blk_mq_start_request")
int example(struct pt_regs *ctx)
{
u64 a = ctx->r15;
struct request *req = (struct request *)(ctx->di);
u32 data_len = req->__data_len;
bpf_printk("data length %u\n", data_len);
unsigned int something_ns = BPF_CORE_READ(req, timeout);
unsigned int data_len = BPF_CORE_READ(req, __data_len);
bpf_printk("data length %lld %ld %ld\n", data_len, something_ns, a);
return 0;
}

View File

@ -1,5 +1,5 @@
from vmlinux import struct_request, struct_pt_regs
from pythonbpf import bpf, section, bpfglobal, compile_to_ir
from pythonbpf import bpf, section, bpfglobal, compile_to_ir, compile
import logging
from ctypes import c_int64
@ -7,9 +7,11 @@ from ctypes import c_int64
@bpf
@section("kprobe/blk_mq_start_request")
def example(ctx: struct_pt_regs) -> c_int64:
a = ctx.r15
req = struct_request(ctx.di)
c = req.__data_len
print(f"data length {c}")
d = req.__data_len
c = req.timeout
print(f"data length {d} and {c} and {a}")
return c_int64(0)
@ -20,3 +22,4 @@ def LICENSE() -> str:
compile_to_ir("requests.py", "requests.ll", loglevel=logging.INFO)
compile()