File tree 3 files changed +32
-0
lines changed 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -565,6 +565,36 @@ void btf__free(struct btf *btf)
565
565
free (btf );
566
566
}
567
567
568
+ struct btf * btf__new_empty (void )
569
+ {
570
+ struct btf * btf ;
571
+
572
+ btf = calloc (1 , sizeof (* btf ));
573
+ if (!btf )
574
+ return ERR_PTR (- ENOMEM );
575
+ btf -> fd = -1 ;
576
+ btf -> ptr_sz = sizeof (void * );
577
+
578
+ /* +1 for empty string at offset 0 */
579
+ btf -> raw_size = sizeof (struct btf_header ) + 1 ;
580
+ btf -> raw_data = calloc (1 , btf -> raw_size );
581
+ if (!btf -> raw_data ) {
582
+ free (btf );
583
+ return ERR_PTR (- ENOMEM );
584
+ }
585
+
586
+ btf -> hdr = btf -> raw_data ;
587
+ btf -> hdr -> hdr_len = sizeof (struct btf_header );
588
+ btf -> hdr -> magic = BTF_MAGIC ;
589
+ btf -> hdr -> version = BTF_VERSION ;
590
+
591
+ btf -> types_data = btf -> raw_data + btf -> hdr -> hdr_len ;
592
+ btf -> strs_data = btf -> raw_data + btf -> hdr -> hdr_len ;
593
+ btf -> hdr -> str_len = 1 ; /* empty string at offset 0 */
594
+
595
+ return btf ;
596
+ }
597
+
568
598
struct btf * btf__new (const void * data , __u32 size )
569
599
{
570
600
struct btf * btf ;
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ struct bpf_object;
27
27
28
28
LIBBPF_API void btf__free (struct btf * btf );
29
29
LIBBPF_API struct btf * btf__new (const void * data , __u32 size );
30
+ LIBBPF_API struct btf * btf__new_empty (void );
30
31
LIBBPF_API struct btf * btf__parse (const char * path , struct btf_ext * * btf_ext );
31
32
LIBBPF_API struct btf * btf__parse_elf (const char * path , struct btf_ext * * btf_ext );
32
33
LIBBPF_API struct btf * btf__parse_raw (const char * path );
Original file line number Diff line number Diff line change @@ -307,6 +307,7 @@ LIBBPF_0.2.0 {
307
307
bpf_program__section_name;
308
308
btf__add_str;
309
309
btf__find_str;
310
+ btf__new_empty;
310
311
perf_buffer__buffer_cnt;
311
312
perf_buffer__buffer_fd;
312
313
perf_buffer__epoll_fd;
You can’t perform that action at this time.
0 commit comments