1 /* Copyright (c) 2017 Facebook
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
12 #include <linux/bpf.h>
14 #include <linux/perf_event.h>
18 #include <sys/resource.h>
22 /* This program verifies bpf attachment to tracepoint sys_enter_* and sys_exit_*.
23 * This requires kernel CONFIG_FTRACE_SYSCALLS to be set.
26 static void verify_map(int map_id)
31 if (bpf_map_lookup_elem(map_id, &key, &val) != 0) {
32 fprintf(stderr, "map_lookup failed: %s\n", strerror(errno));
36 fprintf(stderr, "failed: map #%d returns value 0\n", map_id);
39 int main(int argc, char **argv)
41 struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
45 setrlimit(RLIMIT_MEMLOCK, &r);
46 snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
48 if (load_bpf_file(filename)) {
49 fprintf(stderr, "%s", bpf_log_buf);
53 /* current load_bpf_file has perf_event_open default pid = -1
54 * and cpu = 0, which permits attached bpf execution on
55 * all cpus for all pid's. bpf program execution ignores
58 /* trigger some "open" operations */
59 fd = open(filename, O_RDONLY);
61 fprintf(stderr, "open failed: %s\n", strerror(errno));
67 verify_map(map_fd[0]);
68 verify_map(map_fd[1]);