@@ -3,8 +3,8 @@ mod raw_tracepoint;
3
3
mod tracepoint;
4
4
mod uprobe;
5
5
6
+ use anyhow:: { self , bail, Result } ;
6
7
use bcc_sys:: bccapi:: * ;
7
- use failure:: * ;
8
8
9
9
use self :: kprobe:: Kprobe ;
10
10
use self :: raw_tracepoint:: RawTracepoint ;
@@ -59,7 +59,7 @@ impl BPF {
59
59
feature = "v0_7_0" ,
60
60
feature = "v0_8_0" ,
61
61
) ) ]
62
- pub fn new ( code : & str ) -> Result < BPF , Error > {
62
+ pub fn new ( code : & str ) -> Result < BPF > {
63
63
let cs = CString :: new ( code) ?;
64
64
let ptr = unsafe { bpf_module_create_c_from_string ( cs. as_ptr ( ) , 2 , ptr:: null_mut ( ) , 0 ) } ;
65
65
if ptr. is_null ( ) {
@@ -79,7 +79,7 @@ impl BPF {
79
79
80
80
// 0.9.0 changes the API for bpf_module_create_c_from_string()
81
81
#[ cfg( any( feature = "v0_9_0" , feature = "v0_10_0" , ) ) ]
82
- pub fn new ( code : & str ) -> Result < BPF , Error > {
82
+ pub fn new ( code : & str ) -> Result < BPF > {
83
83
let cs = CString :: new ( code) ?;
84
84
let ptr =
85
85
unsafe { bpf_module_create_c_from_string ( cs. as_ptr ( ) , 2 , ptr:: null_mut ( ) , 0 , true ) } ;
@@ -105,7 +105,7 @@ impl BPF {
105
105
feature = "v0_13_0" ,
106
106
not( feature = "specific" ) ,
107
107
) ) ]
108
- pub fn new ( code : & str ) -> Result < BPF , Error > {
108
+ pub fn new ( code : & str ) -> Result < BPF > {
109
109
let cs = CString :: new ( code) ?;
110
110
let ptr = unsafe {
111
111
bpf_module_create_c_from_string (
@@ -118,7 +118,7 @@ impl BPF {
118
118
)
119
119
} ;
120
120
if ptr. is_null ( ) {
121
- return Err ( format_err ! ( "couldn't create BPF program" ) ) ;
121
+ bail ! ( anyhow :: anyhow !( "couldn't create BPF program" ) ) ;
122
122
}
123
123
124
124
Ok ( BPF {
@@ -143,20 +143,20 @@ impl BPF {
143
143
Table :: new ( id, self . ptr ( ) )
144
144
}
145
145
146
- pub fn load_net ( & mut self , name : & str ) -> Result < File , Error > {
146
+ pub fn load_net ( & mut self , name : & str ) -> Result < File > {
147
147
self . load ( name, bpf_prog_type_BPF_PROG_TYPE_SCHED_ACT, 0 , 0 )
148
148
}
149
149
150
- pub fn load_kprobe ( & mut self , name : & str ) -> Result < File , Error > {
150
+ pub fn load_kprobe ( & mut self , name : & str ) -> Result < File > {
151
151
self . load ( name, bpf_prog_type_BPF_PROG_TYPE_KPROBE, 0 , 0 )
152
152
}
153
153
154
- pub fn load_uprobe ( & mut self , name : & str ) -> Result < File , Error > {
154
+ pub fn load_uprobe ( & mut self , name : & str ) -> Result < File > {
155
155
// it's BPF_PROG_TYPE_KPROBE even though it's a uprobe, it's weird
156
156
self . load ( name, bpf_prog_type_BPF_PROG_TYPE_KPROBE, 0 , 0 )
157
157
}
158
158
159
- pub fn load_tracepoint ( & mut self , name : & str ) -> Result < File , Error > {
159
+ pub fn load_tracepoint ( & mut self , name : & str ) -> Result < File > {
160
160
self . load ( name, bpf_prog_type_BPF_PROG_TYPE_TRACEPOINT, 0 , 0 )
161
161
}
162
162
@@ -172,7 +172,7 @@ impl BPF {
172
172
feature = "v0_13_0" ,
173
173
not( feature = "specific" ) ,
174
174
) ) ]
175
- pub fn load_raw_tracepoint ( & mut self , name : & str ) -> Result < File , Error > {
175
+ pub fn load_raw_tracepoint ( & mut self , name : & str ) -> Result < File > {
176
176
self . load ( name, bpf_prog_type_BPF_PROG_TYPE_RAW_TRACEPOINT, 0 , 0 )
177
177
}
178
178
@@ -183,7 +183,7 @@ impl BPF {
183
183
prog_type : u32 ,
184
184
_log_level : i32 ,
185
185
log_size : u32 ,
186
- ) -> Result < File , Error > {
186
+ ) -> Result < File > {
187
187
let cname = CString :: new ( name) . unwrap ( ) ;
188
188
unsafe {
189
189
let start: * mut bpf_insn =
@@ -227,7 +227,7 @@ impl BPF {
227
227
prog_type : u32 ,
228
228
log_level : i32 ,
229
229
log_size : u32 ,
230
- ) -> Result < File , Error > {
230
+ ) -> Result < File > {
231
231
let cname = CString :: new ( name) . unwrap ( ) ;
232
232
unsafe {
233
233
let start: * mut bpf_insn =
@@ -236,7 +236,7 @@ impl BPF {
236
236
let license = bpf_module_license ( self . ptr ( ) ) ;
237
237
let version = bpf_module_kern_version ( self . ptr ( ) ) ;
238
238
if start. is_null ( ) {
239
- return Err ( format_err ! ( "Error in bpf_function_start for {}" , name) ) ;
239
+ bail ! ( anyhow :: anyhow !( "Error in bpf_function_start for {}" , name) ) ;
240
240
}
241
241
let mut log_buf: Vec < u8 > = Vec :: with_capacity ( log_size as usize ) ;
242
242
// TODO: we're ignoring any changes bpf_prog_load made to log_buf right now
@@ -274,7 +274,7 @@ impl BPF {
274
274
prog_type : u32 ,
275
275
log_level : i32 ,
276
276
log_size : u32 ,
277
- ) -> Result < File , Error > {
277
+ ) -> Result < File > {
278
278
let cname = CString :: new ( name) . unwrap ( ) ;
279
279
unsafe {
280
280
let start: * mut bpf_insn =
@@ -283,7 +283,7 @@ impl BPF {
283
283
let license = bpf_module_license ( self . ptr ( ) ) ;
284
284
let version = bpf_module_kern_version ( self . ptr ( ) ) ;
285
285
if start. is_null ( ) {
286
- return Err ( format_err ! ( "Error in bpf_function_start for {}" , name) ) ;
286
+ bail ! ( anyhow :: anyhow !( "Error in bpf_function_start for {}" , name) ) ;
287
287
}
288
288
let mut log_buf: Vec < u8 > = Vec :: with_capacity ( log_size as usize ) ;
289
289
// TODO: we're ignoring any changes bpf_prog_load made to log_buf right now
@@ -301,7 +301,7 @@ impl BPF {
301
301
log_buf. capacity ( ) as u32 ,
302
302
) ;
303
303
if fd < 0 {
304
- return Err ( format_err ! ( "error loading BPF program: {}" , name) ) ;
304
+ bail ! ( anyhow :: anyhow !( "error loading BPF program: {}" , name) ) ;
305
305
}
306
306
Ok ( File :: from_raw_fd ( fd) )
307
307
}
@@ -313,25 +313,25 @@ impl BPF {
313
313
symbol : & str ,
314
314
file : File ,
315
315
pid : pid_t ,
316
- ) -> Result < ( ) , Error > {
316
+ ) -> Result < ( ) > {
317
317
let uprobe = Uprobe :: attach_uretprobe ( binary_path, symbol, file, pid) ?;
318
318
self . uprobes . insert ( uprobe) ;
319
319
Ok ( ( ) )
320
320
}
321
321
322
- pub fn attach_kprobe ( & mut self , function : & str , file : File ) -> Result < ( ) , Error > {
322
+ pub fn attach_kprobe ( & mut self , function : & str , file : File ) -> Result < ( ) > {
323
323
let kprobe = Kprobe :: attach_kprobe ( function, file) ?;
324
324
self . kprobes . insert ( kprobe) ;
325
325
Ok ( ( ) )
326
326
}
327
327
328
- pub fn attach_kretprobe ( & mut self , function : & str , file : File ) -> Result < ( ) , Error > {
328
+ pub fn attach_kretprobe ( & mut self , function : & str , file : File ) -> Result < ( ) > {
329
329
let kretprobe = Kprobe :: attach_kretprobe ( function, file) ?;
330
330
self . kprobes . insert ( kretprobe) ;
331
331
Ok ( ( ) )
332
332
}
333
333
334
- pub fn get_kprobe_functions ( & mut self , event_re : & str ) -> Result < Vec < String > , Error > {
334
+ pub fn get_kprobe_functions ( & mut self , event_re : & str ) -> Result < Vec < String > > {
335
335
Kprobe :: get_kprobe_functions ( event_re)
336
336
}
337
337
@@ -341,13 +341,13 @@ impl BPF {
341
341
symbol : & str ,
342
342
file : File ,
343
343
pid : pid_t ,
344
- ) -> Result < ( ) , Error > {
344
+ ) -> Result < ( ) > {
345
345
let uprobe = Uprobe :: attach_uprobe ( binary_path, symbol, file, pid) ?;
346
346
self . uprobes . insert ( uprobe) ;
347
347
Ok ( ( ) )
348
348
}
349
349
350
- pub fn attach_tracepoint ( & mut self , subsys : & str , name : & str , file : File ) -> Result < ( ) , Error > {
350
+ pub fn attach_tracepoint ( & mut self , subsys : & str , name : & str , file : File ) -> Result < ( ) > {
351
351
let tracepoint = Tracepoint :: attach_tracepoint ( subsys, name, file) ?;
352
352
self . tracepoints . insert ( tracepoint) ;
353
353
Ok ( ( ) )
@@ -365,13 +365,13 @@ impl BPF {
365
365
feature = "v0_13_0" ,
366
366
not( feature = "specific" ) ,
367
367
) ) ]
368
- pub fn attach_raw_tracepoint ( & mut self , name : & str , file : File ) -> Result < ( ) , Error > {
368
+ pub fn attach_raw_tracepoint ( & mut self , name : & str , file : File ) -> Result < ( ) > {
369
369
let raw_tracepoint = RawTracepoint :: attach_raw_tracepoint ( name, file) ?;
370
370
self . raw_tracepoints . insert ( raw_tracepoint) ;
371
371
Ok ( ( ) )
372
372
}
373
373
374
- pub fn ksymname ( & mut self , name : & str ) -> Result < u64 , Error > {
374
+ pub fn ksymname ( & mut self , name : & str ) -> Result < u64 > {
375
375
self . sym_caches
376
376
. entry ( -1 )
377
377
. or_insert_with ( || SymbolCache :: new ( -1 ) ) ;
@@ -396,7 +396,7 @@ impl BPF {
396
396
|| self . ksymname ( "bpf_get_raw_tracepoint" ) . is_ok ( )
397
397
}
398
398
399
- pub fn init_perf_map < F > ( & mut self , table : Table , cb : F ) -> Result < ( ) , Error >
399
+ pub fn init_perf_map < F > ( & mut self , table : Table , cb : F ) -> Result < ( ) >
400
400
where
401
401
F : Fn ( ) -> Box < dyn FnMut ( & [ u8 ] ) + Send > ,
402
402
{
0 commit comments