File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 44
55use std:: ffi:: c_void;
66use std:: ffi:: CStr ;
7+ use std:: ffi:: CString ;
78use std:: ffi:: OsStr ;
89use std:: marker:: PhantomData ;
910use std:: mem;
@@ -52,7 +53,7 @@ pub struct UprobeOpts {
5253 /// `func_name` and use `func_offset` argument to specify offset within the
5354 /// function. Shared library functions must specify the shared library
5455 /// binary_path.
55- pub func_name : String ,
56+ pub func_name : Option < String > ,
5657 #[ doc( hidden) ]
5758 pub _non_exhaustive : ( ) ,
5859}
@@ -817,13 +818,20 @@ impl<'obj> ProgramMut<'obj> {
817818 _non_exhaustive,
818819 } = opts;
819820
820- let func_name = util:: str_to_cstring ( & func_name) ?;
821+ let func_name: Option < CString > = if let Some ( func_name) = func_name {
822+ Some ( util:: str_to_cstring ( & func_name) ?)
823+ } else {
824+ None
825+ } ;
826+ let ptr = func_name
827+ . as_ref ( )
828+ . map_or ( ptr:: null ( ) , |func_name| func_name. as_ptr ( ) ) ;
821829 let opts = libbpf_sys:: bpf_uprobe_opts {
822830 sz : size_of :: < libbpf_sys:: bpf_uprobe_opts > ( ) as _ ,
823831 ref_ctr_offset : ref_ctr_offset as libbpf_sys:: size_t ,
824832 bpf_cookie : cookie,
825833 retprobe,
826- func_name : func_name . as_ptr ( ) ,
834+ func_name : ptr ,
827835 ..Default :: default ( )
828836 } ;
829837
Original file line number Diff line number Diff line change @@ -1684,7 +1684,7 @@ fn test_object_uprobe_with_opts() {
16841684 let path = current_exe ( ) . expect ( "failed to find executable name" ) ;
16851685 let func_offset = 0 ;
16861686 let opts = UprobeOpts {
1687- func_name : "uprobe_target" . to_string ( ) ,
1687+ func_name : Some ( "uprobe_target" . into ( ) ) ,
16881688 ..Default :: default ( )
16891689 } ;
16901690 let _link = prog
@@ -1713,7 +1713,7 @@ fn test_object_uprobe_with_cookie() {
17131713 let path = current_exe ( ) . expect ( "failed to find executable name" ) ;
17141714 let func_offset = 0 ;
17151715 let opts = UprobeOpts {
1716- func_name : "uprobe_target" . to_string ( ) ,
1716+ func_name : Some ( "uprobe_target" . into ( ) ) ,
17171717 cookie : cookie_val. into ( ) ,
17181718 ..Default :: default ( )
17191719 } ;
You can’t perform that action at this time.
0 commit comments