spintest_user.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <linux/bpf.h>
  4. #include <string.h>
  5. #include <assert.h>
  6. #include <sys/resource.h>
  7. #include "libbpf.h"
  8. #include "bpf_load.h"
  9. int main(int ac, char **argv)
  10. {
  11. struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
  12. long key, next_key, value;
  13. char filename[256];
  14. struct ksym *sym;
  15. int i;
  16. snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
  17. setrlimit(RLIMIT_MEMLOCK, &r);
  18. if (load_kallsyms()) {
  19. printf("failed to process /proc/kallsyms\n");
  20. return 2;
  21. }
  22. if (load_bpf_file(filename)) {
  23. printf("%s", bpf_log_buf);
  24. return 1;
  25. }
  26. for (i = 0; i < 5; i++) {
  27. key = 0;
  28. printf("kprobing funcs:");
  29. while (bpf_get_next_key(map_fd[0], &key, &next_key) == 0) {
  30. bpf_lookup_elem(map_fd[0], &next_key, &value);
  31. assert(next_key == value);
  32. sym = ksym_search(value);
  33. printf(" %s", sym->name);
  34. key = next_key;
  35. }
  36. if (key)
  37. printf("\n");
  38. key = 0;
  39. while (bpf_get_next_key(map_fd[0], &key, &next_key) == 0)
  40. bpf_delete_elem(map_fd[0], &next_key);
  41. sleep(1);
  42. }
  43. return 0;
  44. }