~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/bpf_iter_ksym.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /* Copyright (c) 2022, Oracle and/or its affiliates. */
  3 #include "bpf_iter.h"
  4 #include <bpf/bpf_helpers.h>
  5 
  6 char _license[] SEC("license") = "GPL";
  7 
  8 unsigned long last_sym_value = 0;
  9 
 10 static inline char to_lower(char c)
 11 {
 12         if (c >= 'A' && c <= 'Z')
 13                 c += ('a' - 'A');
 14         return c;
 15 }
 16 
 17 static inline char to_upper(char c)
 18 {
 19         if (c >= 'a' && c <= 'z')
 20                 c -= ('a' - 'A');
 21         return c;
 22 }
 23 
 24 /* Dump symbols with max size; the latter is calculated by caching symbol N value
 25  * and when iterating on symbol N+1, we can print max size of symbol N via
 26  * address of N+1 - address of N.
 27  */
 28 SEC("iter/ksym")
 29 int dump_ksym(struct bpf_iter__ksym *ctx)
 30 {
 31         struct seq_file *seq = ctx->meta->seq;
 32         struct kallsym_iter *iter = ctx->ksym;
 33         __u32 seq_num = ctx->meta->seq_num;
 34         unsigned long value;
 35         char type;
 36 
 37         if (!iter)
 38                 return 0;
 39 
 40         if (seq_num == 0) {
 41                 BPF_SEQ_PRINTF(seq, "ADDR TYPE NAME MODULE_NAME KIND MAX_SIZE\n");
 42                 return 0;
 43         }
 44         if (last_sym_value)
 45                 BPF_SEQ_PRINTF(seq, "0x%x\n", iter->value - last_sym_value);
 46         else
 47                 BPF_SEQ_PRINTF(seq, "\n");
 48 
 49         value = iter->show_value ? iter->value : 0;
 50 
 51         last_sym_value = value;
 52 
 53         type = iter->type;
 54 
 55         if (iter->module_name[0]) {
 56                 type = iter->exported ? to_upper(type) : to_lower(type);
 57                 BPF_SEQ_PRINTF(seq, "0x%llx %c %s [ %s ] ",
 58                                value, type, iter->name, iter->module_name);
 59         } else {
 60                 BPF_SEQ_PRINTF(seq, "0x%llx %c %s ", value, type, iter->name);
 61         }
 62         if (!iter->pos_mod_end || iter->pos_mod_end > iter->pos)
 63                 BPF_SEQ_PRINTF(seq, "MOD ");
 64         else if (!iter->pos_ftrace_mod_end || iter->pos_ftrace_mod_end > iter->pos)
 65                 BPF_SEQ_PRINTF(seq, "FTRACE_MOD ");
 66         else if (!iter->pos_bpf_end || iter->pos_bpf_end > iter->pos)
 67                 BPF_SEQ_PRINTF(seq, "BPF ");
 68         else
 69                 BPF_SEQ_PRINTF(seq, "KPROBE ");
 70         return 0;
 71 }
 72 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php