File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,9 +55,32 @@ impl PerfFifo {
5555}
5656
5757pub fn setup_environment ( ) {
58+ // sysctl kernel.kptr_restrict=0
59+
60+ let sysctl_read = |name : & str | -> Option < u64 > {
61+ let output = std:: process:: Command :: new ( "sysctl" )
62+ . arg ( name)
63+ . output ( )
64+ . unwrap ( ) ;
65+ let output = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
66+ output
67+ . split ( " = " )
68+ . last ( )
69+ . unwrap ( )
70+ . trim ( )
71+ . parse :: < u64 > ( )
72+ . ok ( )
73+ } ;
74+
5875 // Allow access to kernel symbols
59- run_with_sudo ( & [ "sysctl" , "-w" , "kernel.kptr_restrict=0" ] ) . unwrap ( ) ;
76+ let kptr_restrict = sysctl_read ( "kernel.kptr_restrict" ) ;
77+ if kptr_restrict != Some ( 0 ) {
78+ run_with_sudo ( & [ "sysctl" , "-w" , "kernel.kptr_restrict=0" ] ) . unwrap ( ) ;
79+ }
6080
6181 // Allow non-root profiling
62- run_with_sudo ( & [ "sysctl" , "-w" , "kernel.perf_event_paranoid=1" ] ) . unwrap ( ) ;
82+ let perf_event_paranoid = sysctl_read ( "kernel.perf_event_paranoid" ) ;
83+ if perf_event_paranoid != Some ( 1 ) {
84+ run_with_sudo ( & [ "sysctl" , "-w" , "kernel.perf_event_paranoid=1" ] ) . unwrap ( ) ;
85+ }
6386}
You can’t perform that action at this time.
0 commit comments