@@ -151,7 +151,7 @@ struct trace {
151
151
struct perf_tool tool ;
152
152
struct {
153
153
/** Sorted sycall numbers used by the trace. */
154
- struct syscall * table ;
154
+ struct syscall * * table ;
155
155
/** Size of table. */
156
156
size_t table_size ;
157
157
struct {
@@ -2473,24 +2473,41 @@ static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size,
2473
2473
return printed ;
2474
2474
}
2475
2475
2476
- static void syscall__init ( struct syscall * sc , int e_machine , int id )
2476
+ static struct syscall * syscall__new ( int e_machine , int id )
2477
2477
{
2478
- memset (sc , 0 , sizeof (* sc ));
2478
+ struct syscall * sc = zalloc (sizeof (* sc ));
2479
+
2480
+ if (!sc )
2481
+ return NULL ;
2482
+
2479
2483
sc -> e_machine = e_machine ;
2480
2484
sc -> id = id ;
2485
+ return sc ;
2481
2486
}
2482
2487
2483
- static void syscall__exit (struct syscall * sc )
2488
+ static void syscall__delete (struct syscall * sc )
2484
2489
{
2485
2490
if (!sc )
2486
2491
return ;
2487
2492
2488
- zfree (& sc -> arg_fmt );
2493
+ free (sc -> arg_fmt );
2494
+ free (sc );
2495
+ }
2496
+
2497
+ static int syscall__bsearch_cmp (const void * key , const void * entry )
2498
+ {
2499
+ const struct syscall * a = key , * b = * ((const struct syscall * * )entry );
2500
+
2501
+ if (a -> e_machine != b -> e_machine )
2502
+ return a -> e_machine - b -> e_machine ;
2503
+
2504
+ return a -> id - b -> id ;
2489
2505
}
2490
2506
2491
2507
static int syscall__cmp (const void * va , const void * vb )
2492
2508
{
2493
- const struct syscall * a = va , * b = vb ;
2509
+ const struct syscall * a = * ((const struct syscall * * )va );
2510
+ const struct syscall * b = * ((const struct syscall * * )vb );
2494
2511
2495
2512
if (a -> e_machine != b -> e_machine )
2496
2513
return a -> e_machine - b -> e_machine ;
@@ -2504,27 +2521,33 @@ static struct syscall *trace__find_syscall(struct trace *trace, int e_machine, i
2504
2521
.e_machine = e_machine ,
2505
2522
.id = id ,
2506
2523
};
2507
- struct syscall * sc , * tmp ;
2524
+ struct syscall * sc , * * tmp ;
2508
2525
2509
2526
if (trace -> syscalls .table ) {
2510
- sc = bsearch (& key , trace -> syscalls .table , trace -> syscalls .table_size ,
2511
- sizeof (struct syscall ), syscall__cmp );
2512
- if (sc )
2513
- return sc ;
2527
+ struct syscall * * sc_entry = bsearch (& key , trace -> syscalls .table ,
2528
+ trace -> syscalls .table_size ,
2529
+ sizeof (trace -> syscalls .table [0 ]),
2530
+ syscall__bsearch_cmp );
2531
+
2532
+ if (sc_entry )
2533
+ return * sc_entry ;
2514
2534
}
2515
2535
2536
+ sc = syscall__new (e_machine , id );
2537
+ if (!sc )
2538
+ return NULL ;
2539
+
2516
2540
tmp = reallocarray (trace -> syscalls .table , trace -> syscalls .table_size + 1 ,
2517
- sizeof (struct syscall ));
2518
- if (!tmp )
2541
+ sizeof (trace -> syscalls .table [0 ]));
2542
+ if (!tmp ) {
2543
+ syscall__delete (sc );
2519
2544
return NULL ;
2545
+ }
2520
2546
2521
2547
trace -> syscalls .table = tmp ;
2522
- sc = & trace -> syscalls .table [trace -> syscalls .table_size ++ ];
2523
- syscall__init (sc , e_machine , id );
2524
- qsort (trace -> syscalls .table , trace -> syscalls .table_size , sizeof (struct syscall ),
2548
+ trace -> syscalls .table [trace -> syscalls .table_size ++ ] = sc ;
2549
+ qsort (trace -> syscalls .table , trace -> syscalls .table_size , sizeof (trace -> syscalls .table [0 ]),
2525
2550
syscall__cmp );
2526
- sc = bsearch (& key , trace -> syscalls .table , trace -> syscalls .table_size ,
2527
- sizeof (struct syscall ), syscall__cmp );
2528
2551
return sc ;
2529
2552
}
2530
2553
@@ -3855,33 +3878,32 @@ static int trace__bpf_sys_enter_beauty_map(struct trace *trace, int e_machine, i
3855
3878
return -1 ;
3856
3879
}
3857
3880
3858
- static struct bpf_program * trace__find_usable_bpf_prog_entry (struct trace * trace , struct syscall * _sc )
3881
+ static struct bpf_program * trace__find_usable_bpf_prog_entry (struct trace * trace ,
3882
+ struct syscall * sc )
3859
3883
{
3860
- struct syscall sc = * _sc ; /* Copy as trace__syscall_info may invalidate pointer. */
3861
3884
struct tep_format_field * field , * candidate_field ;
3862
3885
/*
3863
3886
* We're only interested in syscalls that have a pointer:
3864
3887
*/
3865
- for (field = sc . args ; field ; field = field -> next ) {
3888
+ for (field = sc -> args ; field ; field = field -> next ) {
3866
3889
if (field -> flags & TEP_FIELD_IS_POINTER )
3867
3890
goto try_to_find_pair ;
3868
3891
}
3869
3892
3870
3893
return NULL ;
3871
3894
3872
3895
try_to_find_pair :
3873
- for (int i = 0 , num_idx = syscalltbl__num_idx (sc .e_machine ); i < num_idx ; ++ i ) {
3874
- int id = syscalltbl__id_at_idx (sc .e_machine , i );
3875
- /* calling trace__syscall_info() may invalidate '_sc' */
3876
- struct syscall * pair = trace__syscall_info (trace , NULL , sc .e_machine , id );
3896
+ for (int i = 0 , num_idx = syscalltbl__num_idx (sc -> e_machine ); i < num_idx ; ++ i ) {
3897
+ int id = syscalltbl__id_at_idx (sc -> e_machine , i );
3898
+ struct syscall * pair = trace__syscall_info (trace , NULL , sc -> e_machine , id );
3877
3899
struct bpf_program * pair_prog ;
3878
3900
bool is_candidate = false;
3879
3901
3880
- if (pair == NULL || pair -> id == sc . id ||
3902
+ if (pair == NULL || pair -> id == sc -> id ||
3881
3903
pair -> bpf_prog .sys_enter == trace -> skel -> progs .syscall_unaugmented )
3882
3904
continue ;
3883
3905
3884
- for (field = sc . args , candidate_field = pair -> args ;
3906
+ for (field = sc -> args , candidate_field = pair -> args ;
3885
3907
field && candidate_field ; field = field -> next , candidate_field = candidate_field -> next ) {
3886
3908
bool is_pointer = field -> flags & TEP_FIELD_IS_POINTER ,
3887
3909
candidate_is_pointer = candidate_field -> flags & TEP_FIELD_IS_POINTER ;
@@ -3948,7 +3970,8 @@ static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace
3948
3970
goto next_candidate ;
3949
3971
}
3950
3972
3951
- pr_debug ("Reusing \"%s\" BPF sys_enter augmenter for \"%s\"\n" , pair -> name , sc .name );
3973
+ pr_debug ("Reusing \"%s\" BPF sys_enter augmenter for \"%s\"\n" , pair -> name ,
3974
+ sc -> name );
3952
3975
return pair_prog ;
3953
3976
next_candidate :
3954
3977
continue ;
@@ -4044,11 +4067,7 @@ static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace, int e_m
4044
4067
pair_prog = trace__find_usable_bpf_prog_entry (trace , sc );
4045
4068
if (pair_prog == NULL )
4046
4069
continue ;
4047
- /*
4048
- * Get syscall info again as find usable entry above might
4049
- * modify the syscall table and shuffle it.
4050
- */
4051
- sc = trace__syscall_info (trace , NULL , e_machine , key );
4070
+
4052
4071
sc -> bpf_prog .sys_enter = pair_prog ;
4053
4072
4054
4073
/*
@@ -5316,7 +5335,7 @@ static void trace__exit(struct trace *trace)
5316
5335
zfree (& trace -> ev_qualifier_ids .entries );
5317
5336
if (trace -> syscalls .table ) {
5318
5337
for (size_t i = 0 ; i < trace -> syscalls .table_size ; i ++ )
5319
- syscall__exit ( & trace -> syscalls .table [i ]);
5338
+ syscall__delete ( trace -> syscalls .table [i ]);
5320
5339
zfree (& trace -> syscalls .table );
5321
5340
}
5322
5341
zfree (& trace -> perfconfig_events );
0 commit comments