@@ -174,7 +174,7 @@ ebpf_program = attribute_list "fn" identifier "(" parameter_list ")" "->" return
174174
175175attribute_list = attribute { attribute }
176176attribute = "@" attribute_name [ "(" attribute_args ")" ]
177- attribute_name = "xdp" | "tc" | "kprobe " | "tracepoint" |
177+ attribute_name = "xdp" | "tc" | "probe " | "tracepoint" |
178178 "struct_ops" | "kfunc" | "private" | "helper" | "test"
179179attribute_args = string_literal | identifier
180180
@@ -185,44 +185,64 @@ return_type = type_annotation
185185
186186** Note:** eBPF programs are now simple attributed functions. All configuration is done through global named config blocks.
187187
188- #### 3.1.1 Advanced Kprobe Functions with BTF Signature Extraction
188+ #### 3.1.1 Advanced Probe Functions with BTF Signature Extraction and Intelligent Probe Type Selection
189189
190- KernelScript automatically extracts kernel function signatures from BTF (BPF Type Format) for kprobe functions, eliminating the need for ` KprobeContext ` and providing type-safe access to function parameters .
190+ KernelScript automatically extracts kernel function signatures from BTF (BPF Type Format) for probe functions and intelligently chooses between fprobe (function entrance) and kprobe (arbitrary address) based on the target specification .
191191
192192``` kernelscript
193- @kprobe("sys_read")
194- fn new_style(fd: u32, buf: *u8, count: usize) -> i32 {
193+ // Function entrance probe (uses fprobe)
194+ @probe("sys_read")
195+ fn function_entrance(fd: u32, buf: *u8, count: usize) -> i32 {
195196 // Direct access to function parameters with correct types
196197 // Compiler automatically extracts signature from BTF:
197198 // long sys_read(unsigned int fd, char __user *buf, size_t count)
199+ // Uses fprobe for better performance at function entrance
198200
199201 print("Reading %d bytes from fd %d", count, fd)
200202 return 0
201203}
204+
205+ // Arbitrary address probe (uses kprobe)
206+ @probe("vfs_read+109")
207+ fn arbitrary_address() -> i32 {
208+ // Probes specific instruction offset within vfs_read
209+ // Uses kprobe for arbitrary address probing
210+ // No direct parameters available at arbitrary addresses
211+
212+ print("Probing vfs_read at offset +109")
213+ return 0
214+ }
202215```
203216
204217** Key Benefits:**
205- - ** Type Safety** : Parameters have correct types extracted from kernel BTF information
206- - ** No Magic Numbers** : Direct parameter access instead of ` ctx.arg_*(index) `
207- - ** Self-Documenting** : Function signature matches the actual kernel function
218+ - ** Intelligent Probe Selection** : Automatically chooses fprobe for function entrance (better performance) or kprobe for arbitrary addresses
219+ - ** Type Safety** : Function entrance probes have correct types extracted from kernel BTF information
220+ - ** No Magic Numbers** : Direct parameter access for function entrance probes
221+ - ** Self-Documenting** : Function signature matches the actual kernel function for entrance probes
208222- ** Compile-Time Validation** : Invalid parameter access caught at compile time
209223
210- ** BTF Signature Mapping:**
224+ ** Probe Type Selection:**
225+ - ` @probe("function_name") ` → Uses ** fprobe** for function entrance with direct parameter access
226+ - ` @probe("function_name+offset") ` → Uses ** kprobe** for arbitrary address probing
227+
228+ ** BTF Signature Mapping for Function Entrance:**
211229``` kernelscript
212230// Kernel function: long sys_openat(int dfd, const char __user *filename, int flags, umode_t mode)
213- @kprobe ("sys_openat")
231+ @probe ("sys_openat")
214232fn trace_openat(dfd: i32, filename: *u8, flags: i32, mode: u16) -> i32 {
215- // Parameters automatically mapped to PT_REGS_PARM1, PT_REGS_PARM2, etc.
233+ // Direct parameter access with fprobe (no PT_REGS needed)
216234 print("Opening file with flags %d", flags)
217235 return 0
218236}
219237
220- // Kernel function: long sys_write(unsigned int fd, const char __user *buf, size_t count)
221- @kprobe("sys_write")
222- fn trace_write(fd: u32, buf: *u8, count: usize) -> i32 {
223- // Type-safe parameter access
224- if (count > 1024) {
225- print("Large write detected: %d bytes to fd %d", count, fd)
238+ // For arbitrary address probing:
239+ @probe("sys_write+50")
240+ fn trace_write_offset() -> i32 {
241+ // Uses kprobe for arbitrary offset - no direct parameters available
242+ print("Probing sys_write at offset +50")
243+ return 0
244+ }
245+
226246 }
227247 return 0
228248}
@@ -1940,7 +1960,7 @@ struct PersonInfo {
19401960}
19411961
19421962// Kernel space usage - kprobe with BTF-extracted function signature
1943- @kprobe ("sys_open")
1963+ @probe ("sys_open")
19441964fn user_monitor(dfd: i32, filename: *u8, flags: i32, mode: u16) -> i32 {
19451965 var process_name: ProcessName = get_current_process_name()
19461966 var file_path: FilePath = get_file_path_from_filename(filename)
@@ -2381,7 +2401,7 @@ fn security_analyzer(ctx: LsmContext) -> i32 {
23812401pin var global_counters : array<u32, GlobalCounter>(256)
23822402pin var event_stream : hash<u32, Event>(1024)
23832403
2384- @kprobe ("sys_read")
2404+ @probe ("sys_read")
23852405fn producer(fd: u32, buf: *u8, count: usize) -> i32 {
23862406 var pid = bpf_get_current_pid_tgid() as u32
23872407
@@ -2401,7 +2421,7 @@ fn producer(fd: u32, buf: *u8, count: usize) -> i32 {
24012421 return 0
24022422}
24032423
2404- @kprobe ("sys_write")
2424+ @probe ("sys_write")
24052425fn consumer(fd: u32, buf: *u8, count: usize) -> i32 {
24062426 var pid = bpf_get_current_pid_tgid() as u32
24072427
@@ -4335,7 +4355,7 @@ fn measure_write_time() -> u64 {
43354355 return bpf_ktime_get_ns()
43364356}
43374357
4338- @kprobe ("sys_read")
4358+ @probe ("sys_read")
43394359fn perf_monitor(fd: u32, buf: *u8, count: usize) -> i32 {
43404360 var pid = bpf_get_current_pid_tgid() as u32
43414361 var call_info = CallInfo {
@@ -4371,7 +4391,7 @@ fn perf_monitor_return(ret_value: isize) -> i32 {
43714391 return 0
43724392}
43734393
4374- @kprobe ("sys_write")
4394+ @probe ("sys_write")
43754395fn write_monitor(fd: u32, buf: *u8, count: usize) -> i32 {
43764396 var pid = bpf_get_current_pid_tgid() as u32
43774397 var duration = measure_write_time() // No context needed
0 commit comments