This commit is contained in:
yunwei37
2024-12-04 09:22:15 +00:00
parent e6c0489187
commit 080450c2ac
2 changed files with 14 additions and 13 deletions

View File

@@ -3,6 +3,7 @@ obj-m += hello.o # hello.o is the target
# Enable BTF generation # Enable BTF generation
KBUILD_CFLAGS += -g -O2 KBUILD_CFLAGS += -g -O2
ccflags-y += -DCONFIG_BPF_SYSCALL ccflags-y += -DCONFIG_BPF_SYSCALL
KBUILD_MODPOST_WARN=1
all: all:
# Compile the module with BTF information # Compile the module with BTF information
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

View File

@@ -17,19 +17,19 @@ __bpf_kfunc_start_defs();
__bpf_kfunc int bpf_strstr(const char *str, u32 str__sz, const char *substr, u32 substr__sz) __bpf_kfunc int bpf_strstr(const char *str, u32 str__sz, const char *substr, u32 substr__sz)
{ {
// const char *fmt = "strstr: str=%s, str__sz=%u, substr=%s\n"; const char *fmt = "strstr: str=%s, str__sz=%u, substr=%s\n";
// // bpf_trace_printk((u64)(void*)fmt, (u64)sizeof(fmt), (u64)(void*)str, (u64)str__sz, (u64)(void*)substr); // bpf_trace_printk((u64)(void*)fmt, (u64)sizeof(fmt), (u64)(void*)str, (u64)str__sz, (u64)(void*)substr);
// // Edge case: if substr is empty, return 0 (assuming empty string is found at the start) // Edge case: if substr is empty, return 0 (assuming empty string is found at the start)
// const struct bpf_func_proto *proto = bpf_base_func_proto(BPF_FUNC_trace_printk, NULL); const struct bpf_func_proto *proto = bpf_base_func_proto(BPF_FUNC_trace_printk, NULL);
// if (!proto) { if (!proto) {
// pr_err("bpf_trace_printk: Failed to get prototype\n"); pr_err("bpf_trace_printk: Failed to get prototype\n");
// return -1; return -1;
// } }
// if (proto->func) { if (proto->func) {
// proto->func((u64)(void*)fmt, (u64)sizeof(fmt), (u64)(void*)str, str__sz, (u64)(void*)substr); proto->func((u64)(void*)fmt, (u64)sizeof(fmt), (u64)(void*)str, str__sz, (u64)(void*)substr);
// } else { } else {
// pr_err("bpf_trace_printk: Failed to get function pointer\n"); pr_err("bpf_trace_printk: Failed to get function pointer\n");
// } }
if (substr__sz == 0) if (substr__sz == 0)
{ {
return 0; return 0;