File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed
tools/testing/selftests/bpf Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -190,10 +190,52 @@ static void regs_common(void)
190190 test_uprobe__destroy (skel );
191191}
192192
193+ static noinline unsigned long uprobe_regs_change_ip_1 (void )
194+ {
195+ return 0xc0ffee ;
196+ }
197+
198+ static noinline unsigned long uprobe_regs_change_ip_2 (void )
199+ {
200+ return 0xdeadbeef ;
201+ }
202+
203+ static void regs_ip (void )
204+ {
205+ LIBBPF_OPTS (bpf_uprobe_opts , uprobe_opts );
206+ struct test_uprobe * skel ;
207+ unsigned long ret ;
208+
209+ skel = test_uprobe__open_and_load ();
210+ if (!ASSERT_OK_PTR (skel , "skel_open" ))
211+ return ;
212+
213+ skel -> bss -> my_pid = getpid ();
214+ skel -> bss -> ip = (unsigned long ) uprobe_regs_change_ip_2 ;
215+
216+ uprobe_opts .func_name = "uprobe_regs_change_ip_1" ;
217+ skel -> links .test_regs_change_ip = bpf_program__attach_uprobe_opts (
218+ skel -> progs .test_regs_change_ip ,
219+ -1 ,
220+ "/proc/self/exe" ,
221+ 0 /* offset */ ,
222+ & uprobe_opts );
223+ if (!ASSERT_OK_PTR (skel -> links .test_regs_change_ip , "bpf_program__attach_uprobe_opts" ))
224+ goto cleanup ;
225+
226+ ret = uprobe_regs_change_ip_1 ();
227+ ASSERT_EQ (ret , 0xdeadbeef , "ret" );
228+
229+ cleanup :
230+ test_uprobe__destroy (skel );
231+ }
232+
193233static void test_uprobe_regs_change (void )
194234{
195235 if (test__start_subtest ("regs_change_common" ))
196236 regs_common ();
237+ if (test__start_subtest ("regs_change_ip" ))
238+ regs_ip ();
197239}
198240#else
199241static void test_uprobe_regs_change (void ) { }
Original file line number Diff line number Diff line change @@ -82,4 +82,18 @@ int BPF_UPROBE(test_regs_change)
8282 ctx -> si = regs .si ;
8383 return 0 ;
8484}
85+
86+ unsigned long ip ;
87+
88+ SEC ("uprobe" )
89+ int BPF_UPROBE (test_regs_change_ip )
90+ {
91+ pid_t pid = bpf_get_current_pid_tgid () >> 32 ;
92+
93+ if (pid != my_pid )
94+ return 0 ;
95+
96+ ctx -> ip = ip ;
97+ return 0 ;
98+ }
8599#endif
You can’t perform that action at this time.
0 commit comments