@@ -67,25 +67,20 @@ pub fn perf_attach_bpf(target: fd_t, prog: fd_t) !void {
67
67
}
68
68
}
69
69
70
- pub fn perf_open_uprobe (uprobe_type : u32 , uprobe_path : []const u8 , uprobe_offset : u64 ) ! fd_t {
71
- // TODO: .size should be the default (stage2 bug)
70
+ pub fn perf_open_probe (probe_type : u32 , config1 : u64 , config2 : u64 ) ! fd_t {
72
71
var attr = linux.perf_event_attr {};
73
72
74
73
// TODO: use /sys/devices/system/cpu/online
75
74
// but not needed for uprobe/kprobe???
76
75
77
76
// the type value is dynamic and might be outside the defined values of
78
77
// PERF.TYPE. praxis or zig std correctness issue
79
- attr .type = @intToEnum (PERF .TYPE , uprobe_type );
78
+ attr .type = @intToEnum (PERF .TYPE , probe_type );
80
79
attr .sample_period_or_freq = 1 ;
81
80
attr .wakeup_events_or_watermark = 1 ;
82
- var path_buf : [512 ]u8 = undefined ;
83
- if (uprobe_path .len > 511 ) return error .InvalidProgram ;
84
- mem .copy (u8 , & path_buf , uprobe_path );
85
- path_buf [uprobe_path .len ] = 0 ;
86
81
87
- attr .config1 = @ptrToInt ( & path_buf ) ;
88
- attr .config2 = uprobe_offset ;
82
+ attr .config1 = config1 ;
83
+ attr .config2 = config2 ;
89
84
90
85
const rc = linux .perf_event_open (& attr , -1 , 0 , -1 , 0 );
91
86
return switch (errno (rc )) {
@@ -98,8 +93,18 @@ pub fn perf_open_uprobe(uprobe_type: u32, uprobe_path: []const u8, uprobe_offset
98
93
};
99
94
}
100
95
101
- pub fn getUprobeType () ! u32 {
102
- const fil = try std .fs .openFileAbsolute ("/sys/bus/event_source/devices/uprobe/type" , .{});
96
+ // makes a null-terminated copy of config1, maximum size: 511 bytes (+ added nul byte)
97
+ pub fn perf_open_probe_cstr (uprobe_type : u32 , config1 : []const u8 , config2 : u64 ) ! fd_t {
98
+ var config1_buf : [512 ]u8 = undefined ;
99
+ if (config1 .len > 511 ) return error .InvalidProgram ;
100
+ mem .copy (u8 , & config1_buf , config1 );
101
+ config1_buf [config1 .len ] = 0 ;
102
+
103
+ return perf_open_probe (uprobe_type , @ptrToInt (& config1_buf ), config2 );
104
+ }
105
+
106
+ pub fn getProbeTypeFromPath (path : []const u8 ) ! u32 {
107
+ const fil = try std .fs .openFileAbsolute (path , .{});
103
108
defer fil .close ();
104
109
105
110
const reader = fil .reader ();
@@ -108,6 +113,14 @@ pub fn getUprobeType() !u32 {
108
113
return std .fmt .parseInt (u32 , line , 10 );
109
114
}
110
115
116
+ pub fn getKprobeType () ! u32 {
117
+ return getProbeTypeFromPath ("/sys/bus/event_source/devices/kprobe/type" );
118
+ }
119
+
120
+ pub fn getUprobeType () ! u32 {
121
+ return getProbeTypeFromPath ("/sys/bus/event_source/devices/uprobe/type" );
122
+ }
123
+
111
124
pub const pt_regs_amd64 = enum (u8 ) {
112
125
r15 ,
113
126
r14 ,
0 commit comments