diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2020-02-08 04:03:48 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2020-02-08 04:03:48 +0000 |
commit | 06e40383787a1ff6bd9c9006e2f057feae0fe3f3 (patch) | |
tree | 63caa3a3f61bdfffe3a6e54b3bd4c0295f0e11ed | |
parent | 8fbf85ef4d040a1158ecf40b41ee0b068a985e83 (diff) | |
parent | 41065cda77e818716bab177ea578da7ea6419a0a (diff) | |
download | bcc-android-platform-11.0.0_r28.tar.gz |
Snap for 6191568 from 41065cda77e818716bab177ea578da7ea6419a0a to rvc-releaseandroid-vts-11.0_r9android-vts-11.0_r8android-vts-11.0_r7android-vts-11.0_r6android-vts-11.0_r5android-vts-11.0_r4android-vts-11.0_r3android-vts-11.0_r2android-vts-11.0_r16android-vts-11.0_r15android-vts-11.0_r14android-vts-11.0_r13android-vts-11.0_r12android-vts-11.0_r11android-vts-11.0_r10android-vts-11.0_r1android-security-11.0.0_r76android-security-11.0.0_r75android-security-11.0.0_r74android-security-11.0.0_r73android-security-11.0.0_r72android-security-11.0.0_r71android-security-11.0.0_r70android-security-11.0.0_r69android-security-11.0.0_r68android-security-11.0.0_r67android-security-11.0.0_r66android-security-11.0.0_r65android-security-11.0.0_r64android-security-11.0.0_r63android-security-11.0.0_r62android-security-11.0.0_r61android-security-11.0.0_r60android-security-11.0.0_r59android-security-11.0.0_r58android-security-11.0.0_r57android-security-11.0.0_r56android-security-11.0.0_r55android-security-11.0.0_r54android-security-11.0.0_r53android-security-11.0.0_r52android-security-11.0.0_r51android-security-11.0.0_r50android-security-11.0.0_r49android-security-11.0.0_r1android-platform-11.0.0_r9android-platform-11.0.0_r8android-platform-11.0.0_r7android-platform-11.0.0_r6android-platform-11.0.0_r5android-platform-11.0.0_r40android-platform-11.0.0_r4android-platform-11.0.0_r39android-platform-11.0.0_r38android-platform-11.0.0_r37android-platform-11.0.0_r36android-platform-11.0.0_r35android-platform-11.0.0_r34android-platform-11.0.0_r33android-platform-11.0.0_r32android-platform-11.0.0_r31android-platform-11.0.0_r30android-platform-11.0.0_r3android-platform-11.0.0_r29android-platform-11.0.0_r28android-platform-11.0.0_r27android-platform-11.0.0_r26android-platform-11.0.0_r25android-platform-11.0.0_r24android-platform-11.0.0_r23android-platform-11.0.0_r22android-platform-11.0.0_r21android-platform-11.0.0_r20android-platform-11.0.0_r2android-platform-11.0.0_r19android-platform-11.0.0_r18android-platform-11.0.0_r17android-platform-11.0.0_r16android-platform-11.0.0_r15android-platform-11.0.0_r14android-platform-11.0.0_r13android-platform-11.0.0_r12android-platform-11.0.0_r11android-platform-11.0.0_r10android-platform-11.0.0_r1android-cts-11.0_r9android-cts-11.0_r8android-cts-11.0_r7android-cts-11.0_r6android-cts-11.0_r5android-cts-11.0_r4android-cts-11.0_r3android-cts-11.0_r2android-cts-11.0_r16android-cts-11.0_r15android-cts-11.0_r14android-cts-11.0_r13android-cts-11.0_r12android-cts-11.0_r11android-cts-11.0_r10android-cts-11.0_r1android-11.0.0_r6android-11.0.0_r5android-11.0.0_r4android-11.0.0_r3android-11.0.0_r25android-11.0.0_r2android-11.0.0_r17android-11.0.0_r1android11-tests-releaseandroid11-security-releaseandroid11-s1-releaseandroid11-releaseandroid11-platform-releaseandroid11-gsi
Change-Id: I86bb2433eb07ef7699152319ee47eba704702167
-rw-r--r-- | src/cc/libbpf.c | 66 |
1 files changed, 52 insertions, 14 deletions
diff --git a/src/cc/libbpf.c b/src/cc/libbpf.c index 90ae2fd8..6b295fea 100644 --- a/src/cc/libbpf.c +++ b/src/cc/libbpf.c @@ -843,6 +843,7 @@ int bpf_attach_kprobe(int progfd, enum bpf_probe_attach_type attach_type, char buf[256]; char event_alias[128]; static char *event_type = "kprobe"; + bool use_debugfs = false; // Try create the kprobe Perf Event with perf_event_open API. pfd = bpf_try_perf_event_open_with_probe(fn_name, fn_offset, -1, event_type, @@ -850,11 +851,17 @@ int bpf_attach_kprobe(int progfd, enum bpf_probe_attach_type attach_type, // If failed, most likely Kernel doesn't support the new perf_event_open API // yet. Try create the event using debugfs. if (pfd < 0) { - snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/%s_events", event_type); + snprintf(buf, sizeof(buf), "/sys/kernel/tracing/%s_events", event_type); kfd = open(buf, O_WRONLY | O_APPEND | O_CLOEXEC, 0); if (kfd < 0) { - fprintf(stderr, "open(%s): %s\n", buf, strerror(errno)); - goto error; + use_debugfs = true; + snprintf(buf, sizeof(buf), + "/sys/kernel/debug/tracing/%s_events", event_type); + kfd = open(buf, O_WRONLY | O_APPEND | O_CLOEXEC, 0); + if (kfd < 0) { + fprintf(stderr, "open(%s): %s\n", buf, strerror(errno)); + goto error; + } } snprintf(event_alias, sizeof(event_alias), "%s_bcc_%d", ev_name, getpid()); @@ -876,7 +883,13 @@ int bpf_attach_kprobe(int progfd, enum bpf_probe_attach_type attach_type, goto error; } close(kfd); - snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/events/%ss/%s", event_type, event_alias); + if (use_debugfs) { + snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/events/%ss/%s", event_type, + event_alias); + } else { + snprintf(buf, sizeof(buf), "/sys/kernel/tracing/events/%ss/%s", event_type, + event_alias); + } } // If perf_event_open succeeded, bpf_attach_tracing_event will use the created // Perf Event FD directly and buf would be empty and unused. @@ -960,17 +973,23 @@ int bpf_attach_uprobe(int progfd, enum bpf_probe_attach_type attach_type, char event_alias[PATH_MAX]; static char *event_type = "uprobe"; int res, kfd = -1, pfd = -1, ns_fd = -1; + bool use_debugfs = false; // Try create the uprobe Perf Event with perf_event_open API. pfd = bpf_try_perf_event_open_with_probe(binary_path, offset, pid, event_type, attach_type != BPF_PROBE_ENTRY); // If failed, most likely Kernel doesn't support the new perf_event_open API // yet. Try create the event using debugfs. if (pfd < 0) { - snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/%s_events", event_type); + snprintf(buf, sizeof(buf), "/sys/kernel/tracing/%s_events", event_type); kfd = open(buf, O_WRONLY | O_APPEND | O_CLOEXEC, 0); if (kfd < 0) { - fprintf(stderr, "open(%s): %s\n", buf, strerror(errno)); - goto error; + use_debugfs = true; + snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/%s_events", event_type); + kfd = open(buf, O_WRONLY | O_APPEND | O_CLOEXEC, 0); + if (kfd < 0) { + fprintf(stderr, "open(%s): %s\n", buf, strerror(errno)); + goto error; + } } res = snprintf(event_alias, sizeof(event_alias), "%s_bcc_%d", ev_name, getpid()); @@ -995,8 +1014,12 @@ int bpf_attach_uprobe(int progfd, enum bpf_probe_attach_type attach_type, kfd = -1; exit_mount_ns(ns_fd); ns_fd = -1; - - snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/events/%ss/%s", event_type, event_alias); + if (use_debugfs) { + snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/events/%ss/%s", event_type, + event_alias); + } else { + snprintf(buf, sizeof(buf), "/sys/kernel/tracing/events/%ss/%s", event_type, event_alias); + } } // If perf_event_open succeeded, bpf_attach_tracing_event will use the created // Perf Event FD directly and buf would be empty and unused. @@ -1021,6 +1044,7 @@ static int bpf_detach_probe(const char *ev_name, const char *event_type) size_t bufsize = 0; char *cptr = NULL; FILE *fp; + bool use_debugfs = false; /* * For [k,u]probe created with perf_event_open (on newer kernel), it is @@ -1028,11 +1052,16 @@ static int bpf_detach_probe(const char *ev_name, const char *event_type) * the %s_bcc_%d line in [k,u]probe_events. If the event is not found, * it is safe to skip the cleaning up process (write -:... to the file). */ - snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/%s_events", event_type); + snprintf(buf, sizeof(buf), "/sys/kernel/tracing/%s_events", event_type); fp = fopen(buf, "re"); if (!fp) { - fprintf(stderr, "open(%s): %s\n", buf, strerror(errno)); - goto error; + use_debugfs = true; + snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/%s_events", event_type); + fp = fopen(buf, "re"); + if (!fp) { + fprintf(stderr, "open(%s): %s\n", buf, strerror(errno)); + goto error; + } } res = snprintf(buf, sizeof(buf), "%ss/%s_bcc_%d", event_type, ev_name, getpid()); @@ -1052,8 +1081,11 @@ static int bpf_detach_probe(const char *ev_name, const char *event_type) if (!found_event) return 0; - - snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/%s_events", event_type); + if (use_debugfs) { + snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/%s_events", event_type); + } else { + snprintf(buf, sizeof(buf), "/sys/kernel/tracing/%s_events", event_type); + } kfd = open(buf, O_WRONLY | O_APPEND | O_CLOEXEC, 0); if (kfd < 0) { fprintf(stderr, "open(%s): %s\n", buf, strerror(errno)); @@ -1098,6 +1130,12 @@ int bpf_attach_tracepoint(int progfd, const char *tp_category, char buf[256]; int pfd = -1; + snprintf(buf, sizeof(buf), "/sys/kernel/tracing/events/%s/%s", + tp_category, tp_name); + if (bpf_attach_tracing_event(progfd, buf, -1 /* PID */, &pfd) == 0) + return pfd; + + // try debugfs next snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/events/%s/%s", tp_category, tp_name); if (bpf_attach_tracing_event(progfd, buf, -1 /* PID */, &pfd) == 0) |