From 9afc86bfb51e1b8cf73f3758bc2ef11568027d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E5=BE=AE?= <1067852565@qq.com> Date: Fri, 17 Nov 2023 20:14:25 -0500 Subject: [PATCH] CI: add build benchmark and License identifier (#87) * add license * add build benchmark ci * add more license identifier * add more license * add license * add more license header * fix redis patch * ci: fix compile * fix ci --- .github/workflows/build-benchmarks.yml | 28 ++++ .github/workflows/test-runtime.yml | 12 +- README.md | 1 + benchmark/Makefile | 10 ++ benchmark/bpf-syscall/bpf-syscall-bench.c | 115 ----------------- benchmark/ssl-nginx/.gitignore | 3 +- benchmark/ssl-nginx/Makefile | 1 + benchmark/tools/.gitignore | 1 + benchmark/tools/Makefile | 2 + daemon/bpf_tracer_event.h | 6 +- daemon/kernel/bpf_defs.h | 5 + daemon/kernel/bpf_event_ringbuf.h | 5 + daemon/kernel/bpf_kernel_config.h | 5 + daemon/kernel/bpf_obj_id_fd_map.h | 5 + daemon/kernel/bpf_pid_fd_map.h | 5 + daemon/kernel/bpf_tracer.bpf.c | 8 +- daemon/test/common_def.hpp | 5 + daemon/test/test_daemon.cpp | 5 + daemon/test/test_daemon_driver.cpp | 5 + daemon/user/bpf_tracer.cpp | 6 +- daemon/user/bpftime_driver.cpp | 5 + daemon/user/bpftime_driver.hpp | 5 + daemon/user/daemon.hpp | 5 + daemon/user/daemon_config.hpp | 5 + daemon/user/handle_bpf_event.cpp | 5 + daemon/user/handle_bpf_event.hpp | 5 + daemon/user/main.cpp | 6 +- .../hot_patch/redis}/.gitignore | 4 +- .../hot_patch/redis}/Makefile | 51 +++++++- example/hot_patch/redis/README.md | 120 +++++++++--------- example/hot_patch/redis/ffi.bpf.h | 97 ++++++++++++++ .../redis/{redis.bpf.c => redis-patch.bpf.c} | 0 example/hot_patch/redis/redis-patch.c | 73 +++++++++++ runtime/include/bpftime_prog.hpp | 5 + runtime/include/bpftime_shm.hpp | 6 +- runtime/src/attach/attach_internal.hpp | 5 + .../attach_manager/base_attach_manager.cpp | 5 + .../attach_manager/base_attach_manager.hpp | 5 + .../attach_manager/frida_attach_manager.cpp | 5 + .../attach_manager/frida_attach_manager.hpp | 5 + runtime/src/attach/bpf_attach_ctx.cpp | 13 +- runtime/src/bpf_helper.cpp | 5 + runtime/src/bpf_map/map_common_def.hpp | 5 + .../bpf_map/shared/array_map_kernel_user.cpp | 5 + .../bpf_map/shared/array_map_kernel_user.hpp | 5 + .../bpf_map/shared/hash_map_kernel_user.cpp | 5 + .../bpf_map/shared/hash_map_kernel_user.hpp | 5 + .../shared/percpu_array_map_kernel_user.cpp | 5 + .../shared/percpu_array_map_kernel_user.hpp | 5 + .../shared/perf_event_array_kernel_user.cpp | 5 + .../shared/perf_event_array_kernel_user.hpp | 6 + runtime/src/bpf_map/userspace/array_map.cpp | 6 + runtime/src/bpf_map/userspace/array_map.hpp | 6 + runtime/src/bpf_map/userspace/hash_map.cpp | 6 + runtime/src/bpf_map/userspace/hash_map.hpp | 6 + .../bpf_map/userspace/per_cpu_array_map.cpp | 6 + .../bpf_map/userspace/per_cpu_array_map.hpp | 5 + .../bpf_map/userspace/per_cpu_hash_map.cpp | 6 + .../bpf_map/userspace/per_cpu_hash_map.hpp | 5 + .../userspace/perf_event_array_map.cpp | 6 + .../userspace/perf_event_array_map.hpp | 6 + runtime/src/bpf_map/userspace/ringbuf_map.cpp | 5 + runtime/src/bpf_map/userspace/ringbuf_map.hpp | 6 + runtime/src/bpftime_handler.hpp | 5 + runtime/src/bpftime_internal.h | 5 + runtime/src/bpftime_prog.cpp | 5 + runtime/src/bpftime_shm.cpp | 5 + runtime/src/bpftime_shm_internal.cpp | 5 + runtime/src/bpftime_shm_internal.hpp | 5 + runtime/src/bpftime_shm_json.cpp | 5 + runtime/src/bpftime_shm_json.hpp | 5 + runtime/src/ffi.cpp | 5 + runtime/src/handler/btf_handler.hpp | 5 + runtime/src/handler/epoll_handler.cpp | 5 + runtime/src/handler/epoll_handler.hpp | 5 + runtime/src/handler/handler_manager.cpp | 5 + runtime/src/handler/handler_manager.hpp | 5 + runtime/src/handler/link_handler.hpp | 5 + runtime/src/handler/map_handler.cpp | 5 + runtime/src/handler/map_handler.hpp | 5 + runtime/src/handler/perf_event_handler.cpp | 5 + runtime/src/handler/perf_event_handler.hpp | 5 + runtime/src/handler/prog_handler.cpp | 5 + runtime/src/syscall_table.cpp | 5 + runtime/syscall-server/syscall_context.cpp | 7 +- runtime/syscall-server/syscall_context.hpp | 5 + .../syscall-server/syscall_server_main.cpp | 5 + .../syscall-server/syscall_server_utils.cpp | 5 + .../syscall-server/syscall_server_utils.hpp | 5 + runtime/test/bpf/btf-relo.bpf.c | 5 + runtime/test/bpf/ffi-btf.bpf.c | 5 + runtime/test/bpf/ffi.bpf.c | 5 + runtime/test/bpf/ffi.bpf.h | 5 + runtime/test/bpf/global.bpf.c | 5 + runtime/test/bpf/hash-map-test.bpf.c | 7 +- runtime/test/bpf/helpers.bpf.c | 5 + runtime/test/bpf/map.bpf.c | 5 + runtime/test/bpf/patch.bpf.c | 6 +- runtime/test/bpf/replace.bpf.c | 5 + runtime/test/include/test_bpf_progs.h | 6 +- runtime/test/include/test_defs.h | 5 + .../test/include/test_minimal_bpf_host_ffi.h | 5 + runtime/test/src/test_attach_replace.cpp | 5 + runtime/test/src/test_ffi.cpp | 5 + runtime/test/src/test_ffi_register.cpp | 5 + runtime/test/src/test_hash_map.c | 5 + runtime/test/src/test_helpers.cpp | 5 + runtime/test/src/test_shm_client.cpp | 5 + runtime/test/src/test_shm_hash_maps.cpp | 5 + runtime/test/src/test_shm_progs_attach.cpp | 7 +- runtime/test/src/test_shm_server.cpp | 5 + tools/bpftimetool/main.cpp | 16 +-- tools/cli-rs/src/main.rs | 1 + vm/llvm-jit/src/bpf_jit.cpp | 5 + vm/llvm-jit/src/bpf_jit_compile_module.cpp | 5 + vm/llvm-jit/src/bpf_jit_helpers.h | 5 + 116 files changed, 847 insertions(+), 216 deletions(-) create mode 100644 .github/workflows/build-benchmarks.yml delete mode 100644 benchmark/bpf-syscall/bpf-syscall-bench.c create mode 100644 benchmark/ssl-nginx/Makefile create mode 100644 benchmark/tools/.gitignore create mode 100644 benchmark/tools/Makefile rename {benchmark/bpf-syscall => example/hot_patch/redis}/.gitignore (74%) rename {benchmark/bpf-syscall => example/hot_patch/redis}/Makefile (59%) create mode 100644 example/hot_patch/redis/ffi.bpf.h rename example/hot_patch/redis/{redis.bpf.c => redis-patch.bpf.c} (100%) create mode 100644 example/hot_patch/redis/redis-patch.c diff --git a/.github/workflows/build-benchmarks.yml b/.github/workflows/build-benchmarks.yml new file mode 100644 index 00000000..aa3d6735 --- /dev/null +++ b/.github/workflows/build-benchmarks.yml @@ -0,0 +1,28 @@ +name: Build benchmarks + +on: + push: + branches: "master" + pull_request: + branches: "master" + +jobs: + build: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + + - name: install deps + run: | + sudo apt install -y --no-install-recommends \ + libelf1 libelf-dev zlib1g-dev make git libboost1.74-all-dev \ + binutils-dev libyaml-cpp-dev gcc-12 g++-12 llvm + + - name: build runtime + run: CC=gcc-12 CXX=g++-12 make release -j + + - name: build benchmarks + run: make -C benchmark diff --git a/.github/workflows/test-runtime.yml b/.github/workflows/test-runtime.yml index 11212482..d075d6e9 100644 --- a/.github/workflows/test-runtime.yml +++ b/.github/workflows/test-runtime.yml @@ -29,10 +29,10 @@ jobs: - name: build runtime with mpk enable run: | - make clean - cmake -Bbuild -DBPFTIME_ENABLE_UNIT_TESTING=0 \ - -DCMAKE_BUILD_TYPE:STRING=Release \ - -DBPFTIME_ENABLE_LTO=0 -DBPFTIME_ENABLE_MPK=1 - cmake --build build --config Release + make clean + cmake -Bbuild -DBPFTIME_ENABLE_UNIT_TESTING=1 -DBPFTIME_ENABLE_MPK=1 + cmake --build build --config Debug -DBPFTIME_ENABLE_MPK=1 + cmake --build build + - name: test runtime with mpk - run: make unit-test \ No newline at end of file + run: make unit-test diff --git a/README.md b/README.md index 4b09e2bb..c90c874b 100644 --- a/README.md +++ b/README.md @@ -189,6 +189,7 @@ see [documents/build-and-test.md](https://github.com/eunomia-bpf/bpftime/tree/ma - [ ] More examples and usecases: - [ ] Network on userspace eBPF - [ ] Hotpatch userspace application + - [ ] Error injection and filter syscall - [ ] etc... - [ ] More map types and distribution maps support. - [ ] More program types support. diff --git a/benchmark/Makefile b/benchmark/Makefile index 9a657b97..359bafe7 100644 --- a/benchmark/Makefile +++ b/benchmark/Makefile @@ -1,2 +1,12 @@ +all: benchmark test test: test.c gcc test.c -o test + +# test with the files in bpf-loader +TEST_CASES_DIRS=$(filter-out $(SKIP_TESTS),$(shell ls -l $(./) | grep ^d | awk '{print $$9}')) +benchmark: $(TEST_CASES_DIRS) + +.PHONY:$(TEST_CASES_DIRS) +# build the test cases +$(TEST_CASES_DIRS): + make -C $(TEST_EXAMPLE_DIR)$@/ diff --git a/benchmark/bpf-syscall/bpf-syscall-bench.c b/benchmark/bpf-syscall/bpf-syscall-bench.c deleted file mode 100644 index 4fc6a426..00000000 --- a/benchmark/bpf-syscall/bpf-syscall-bench.c +++ /dev/null @@ -1,115 +0,0 @@ -// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) -/* Copyright (c) 2020 Facebook */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "linux/filter.h" - -int prog_fd; - -// The timespec struct holds seconds and nanoseconds -struct timespec start_time, end_time; - -void start_timer() -{ - clock_gettime(CLOCK_MONOTONIC_RAW, &start_time); -} - -void end_timer() -{ - clock_gettime(CLOCK_MONOTONIC_RAW, &end_time); -} - -__attribute_noinline__ uint64_t __benchmark_test_function1(const char *a, int b, - uint64_t c) -{ - return bpf_prog_test_run_opts(prog_fd, NULL); -} - -typedef uint64_t (*benchmark_test_function_t)(const char *, int, uint64_t); - -static double get_elapsed_time() -{ - long seconds = end_time.tv_sec - start_time.tv_sec; - long nanoseconds = end_time.tv_nsec - start_time.tv_nsec; - if (start_time.tv_nsec > end_time.tv_nsec) { // clock underflow - --seconds; - nanoseconds += 1000000000; - } - printf("Elapsed time: %ld.%09ld seconds\n", seconds, nanoseconds); - return seconds * 1.0 + nanoseconds / 1000000000.0; -} - -static double get_function_time(benchmark_test_function_t func, int iter) -{ - start_timer(); - // test base line - for (int i = 0; i < iter; i++) { - func("hello", i % 4, i); - } - end_timer(); - double time = get_elapsed_time(); - return time; -} - -void do_benchmark_userspace(benchmark_test_function_t func, int iter) -{ - double base_line_time; - - printf("a[b] + c for %d times\n", iter); - base_line_time = get_function_time(func, iter); - printf("Average time usage %lf ns\n\n", - (base_line_time) / iter * 1000000000.0); -} - -#define do_benchmark_func(func, iter) \ - do { \ - printf("Benchmarking %s\n", #func); \ - do_benchmark_userspace(func ,iter); \ - } while (0) - -int test_run_time() -{ - puts(""); - struct bpf_insn trival_prog_insns[] = { - BPF_MOV64_IMM(BPF_REG_0, 0), - BPF_EXIT_INSN(), - }; - int prog_fd = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, NULL, "GPL", - trival_prog_insns, 2, NULL); - if (prog_fd < 0) { - printf("Failed to load BPF program: %s\n", strerror(prog_fd)); - exit(1); - } - int iter = 100 * 1000; - do_benchmark_func(__benchmark_test_function1, iter); - return 0; -} - -#define warn(...) fprintf(stderr, __VA_ARGS__) - -static int libbpf_print_fn(enum libbpf_print_level level, const char *format, - va_list args) -{ - return vfprintf(stderr, format, args); -} - -int main(int argc, char **argv) -{ - /* Set up libbpf errors and debug info callback */ - libbpf_set_print(libbpf_print_fn); - - test_run_time(); - - return 0; -} diff --git a/benchmark/ssl-nginx/.gitignore b/benchmark/ssl-nginx/.gitignore index 38edc3b7..46299f60 100644 --- a/benchmark/ssl-nginx/.gitignore +++ b/benchmark/ssl-nginx/.gitignore @@ -1,4 +1,5 @@ access.log nginx.pid nginx-error.txt -sslsniff \ No newline at end of file +sslsniff +wrk diff --git a/benchmark/ssl-nginx/Makefile b/benchmark/ssl-nginx/Makefile new file mode 100644 index 00000000..c5941149 --- /dev/null +++ b/benchmark/ssl-nginx/Makefile @@ -0,0 +1 @@ +index.html: index.html \ No newline at end of file diff --git a/benchmark/tools/.gitignore b/benchmark/tools/.gitignore new file mode 100644 index 00000000..b66ea85e --- /dev/null +++ b/benchmark/tools/.gitignore @@ -0,0 +1 @@ +readlink diff --git a/benchmark/tools/Makefile b/benchmark/tools/Makefile new file mode 100644 index 00000000..3c81d575 --- /dev/null +++ b/benchmark/tools/Makefile @@ -0,0 +1,2 @@ +readlink: readlink.cpp + g++ readlink.cpp -o readlink diff --git a/daemon/bpf_tracer_event.h b/daemon/bpf_tracer_event.h index 1869f70a..267187ae 100644 --- a/daemon/bpf_tracer_event.h +++ b/daemon/bpf_tracer_event.h @@ -1,4 +1,8 @@ -/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef __SYSCALL_TRACER_H #define __SYSCALL_TRACER_H diff --git a/daemon/kernel/bpf_defs.h b/daemon/kernel/bpf_defs.h index 7f62d598..c27f98c7 100644 --- a/daemon/kernel/bpf_defs.h +++ b/daemon/kernel/bpf_defs.h @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef BPFTIME_BPF_DEFS_H #define BPFTIME_BPF_DEFS_H diff --git a/daemon/kernel/bpf_event_ringbuf.h b/daemon/kernel/bpf_event_ringbuf.h index 654e7bf2..0291a0fc 100644 --- a/daemon/kernel/bpf_event_ringbuf.h +++ b/daemon/kernel/bpf_event_ringbuf.h @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef BPF_UTILS_H #define BPF_UTILS_H diff --git a/daemon/kernel/bpf_kernel_config.h b/daemon/kernel/bpf_kernel_config.h index 91a77d74..a0907822 100644 --- a/daemon/kernel/bpf_kernel_config.h +++ b/daemon/kernel/bpf_kernel_config.h @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef BPFTIME_KERNEL_CONFIG_H #define BPFTIME_KERNEL_CONFIG_H diff --git a/daemon/kernel/bpf_obj_id_fd_map.h b/daemon/kernel/bpf_obj_id_fd_map.h index d142d7d4..c6e4ac64 100644 --- a/daemon/kernel/bpf_obj_id_fd_map.h +++ b/daemon/kernel/bpf_obj_id_fd_map.h @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef BPFTIME_BPF_MAPS_ID_FD_MAP #define BPFTIME_BPF_MAPS_ID_FD_MAP diff --git a/daemon/kernel/bpf_pid_fd_map.h b/daemon/kernel/bpf_pid_fd_map.h index deb486fa..b9b6e888 100644 --- a/daemon/kernel/bpf_pid_fd_map.h +++ b/daemon/kernel/bpf_pid_fd_map.h @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef BPFTIME_BPF_PID_FD_MAP #define BPFTIME_BPF_PID_FD_MAP diff --git a/daemon/kernel/bpf_tracer.bpf.c b/daemon/kernel/bpf_tracer.bpf.c index 6577a03c..11dda8c3 100644 --- a/daemon/kernel/bpf_tracer.bpf.c +++ b/daemon/kernel/bpf_tracer.bpf.c @@ -1,6 +1,8 @@ -// SPDX-License-Identifier: GPL-2.0 -// Copyright (c) 2019 Facebook -// Copyright (c) 2020 Netflix +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include #include #include diff --git a/daemon/test/common_def.hpp b/daemon/test/common_def.hpp index 302b0049..63691eb0 100644 --- a/daemon/test/common_def.hpp +++ b/daemon/test/common_def.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _COMMON_DEF_HPP #define _COMMON_DEF_HPP #include diff --git a/daemon/test/test_daemon.cpp b/daemon/test/test_daemon.cpp index 001267ca..5883de04 100644 --- a/daemon/test/test_daemon.cpp +++ b/daemon/test/test_daemon.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include #include #include diff --git a/daemon/test/test_daemon_driver.cpp b/daemon/test/test_daemon_driver.cpp index 79c79d1c..8285a038 100644 --- a/daemon/test/test_daemon_driver.cpp +++ b/daemon/test/test_daemon_driver.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include #include #include diff --git a/daemon/user/bpf_tracer.cpp b/daemon/user/bpf_tracer.cpp index 1bab1c28..7883adeb 100644 --- a/daemon/user/bpf_tracer.cpp +++ b/daemon/user/bpf_tracer.cpp @@ -1,4 +1,8 @@ -// Description: bpf_tracer daemon +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "spdlog/common.h" #include #include diff --git a/daemon/user/bpftime_driver.cpp b/daemon/user/bpftime_driver.cpp index df7145fc..ece22f4a 100644 --- a/daemon/user/bpftime_driver.cpp +++ b/daemon/user/bpftime_driver.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "bpftime_driver.hpp" #include #include diff --git a/daemon/user/bpftime_driver.hpp b/daemon/user/bpftime_driver.hpp index fa56a299..e339b782 100644 --- a/daemon/user/bpftime_driver.hpp +++ b/daemon/user/bpftime_driver.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef BPFTIME_DRIVER_HPP #define BPFTIME_DRIVER_HPP diff --git a/daemon/user/daemon.hpp b/daemon/user/daemon.hpp index b1dce4f0..9a4883ef 100644 --- a/daemon/user/daemon.hpp +++ b/daemon/user/daemon.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef BPFTIME_DAEMON_HPP #define BPFTIME_DAEMON_HPP diff --git a/daemon/user/daemon_config.hpp b/daemon/user/daemon_config.hpp index 7731b415..d9aa3eef 100644 --- a/daemon/user/daemon_config.hpp +++ b/daemon/user/daemon_config.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef BPFTIME_DAEMON_CONFIG_HPP #define BPFTIME_DAEMON_CONFIG_HPP diff --git a/daemon/user/handle_bpf_event.cpp b/daemon/user/handle_bpf_event.cpp index bf2ce03c..605c2016 100644 --- a/daemon/user/handle_bpf_event.cpp +++ b/daemon/user/handle_bpf_event.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include #include #include diff --git a/daemon/user/handle_bpf_event.hpp b/daemon/user/handle_bpf_event.hpp index f16d7dcc..578d377a 100644 --- a/daemon/user/handle_bpf_event.hpp +++ b/daemon/user/handle_bpf_event.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef BPFTIME_HANDLE_EVENT_HPP #define BPFTIME_HANDLE_EVENT_HPP diff --git a/daemon/user/main.cpp b/daemon/user/main.cpp index 2025b1ed..207c742d 100644 --- a/daemon/user/main.cpp +++ b/daemon/user/main.cpp @@ -1,4 +1,8 @@ -// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include #include #include diff --git a/benchmark/bpf-syscall/.gitignore b/example/hot_patch/redis/.gitignore similarity index 74% rename from benchmark/bpf-syscall/.gitignore rename to example/hot_patch/redis/.gitignore index e606ec01..26379aae 100644 --- a/benchmark/bpf-syscall/.gitignore +++ b/example/hot_patch/redis/.gitignore @@ -5,7 +5,7 @@ package.json *.skel.yaml package.yaml ecli +redis-patch .output test -uretprobe -bpf-syscall-bench +victim diff --git a/benchmark/bpf-syscall/Makefile b/example/hot_patch/redis/Makefile similarity index 59% rename from benchmark/bpf-syscall/Makefile rename to example/hot_patch/redis/Makefile index 5ead5370..2175edf2 100644 --- a/benchmark/bpf-syscall/Makefile +++ b/example/hot_patch/redis/Makefile @@ -1,8 +1,8 @@ # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) OUTPUT := .output CLANG ?= clang -LIBBPF_SRC := $(abspath ../../third_party/libbpf/src) -BPFTOOL_SRC := $(abspath ../../third_party/bpftool/src) +LIBBPF_SRC := $(abspath ../../../third_party/libbpf/src) +BPFTOOL_SRC := $(abspath ../../../third_party/bpftool/src) LIBBPF_OBJ := $(abspath $(OUTPUT)/libbpf.a) BPFTOOL_OUTPUT ?= $(abspath $(OUTPUT)/bpftool) BPFTOOL ?= $(BPFTOOL_OUTPUT)/bootstrap/bpftool @@ -13,15 +13,15 @@ ARCH ?= $(shell uname -m | sed 's/x86_64/x86/' \ | sed 's/mips.*/mips/' \ | sed 's/riscv64/riscv/' \ | sed 's/loongarch64/loongarch/') -VMLINUX := ../../third_party/vmlinux/$(ARCH)/vmlinux.h +VMLINUX := ../../../third_party/vmlinux/$(ARCH)/vmlinux.h # Use our own libbpf API headers and Linux UAPI headers distributed with # libbpf to avoid dependency on system-wide headers, which could be missing or # outdated -INCLUDES := -I$(OUTPUT) -I../../third_party/libbpf/include -I../../third_party/libbpf/include/uapi -I$(dir $(VMLINUX)) +INCLUDES := -I$(OUTPUT) -I../../../third_party/libbpf/include/uapi -I../../../third_party/libbpf/include/ -I$(dir $(VMLINUX)) CFLAGS := -g -Wall ALL_LDFLAGS := $(LDFLAGS) $(EXTRA_LDFLAGS) -APPS = bpf-syscall-bench # minimal minimal_legacy kprobe fentry usdt sockfilter tc ksyscall +APPS = redis-patch # redis-patch redis-patch_legacy uprobe kprobe fentry usdt sockfilter tc ksyscall CARGO ?= $(shell which cargo) ifeq ($(strip $(CARGO)),) @@ -85,9 +85,46 @@ $(LIBBPF_OBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPU INCLUDEDIR= LIBDIR= UAPIDIR= \ install -.output/bpf-syscall-bench.o: bpf-syscall-bench.c $(OUTPUT) +# Build bpftool +$(BPFTOOL): | $(BPFTOOL_OUTPUT) + $(call msg,BPFTOOL,$@) + $(Q)$(MAKE) ARCH= CROSS_COMPILE= OUTPUT=$(BPFTOOL_OUTPUT)/ -C $(BPFTOOL_SRC) bootstrap + + +$(LIBBLAZESYM_SRC)/target/release/libblazesym.a:: + $(Q)cd $(LIBBLAZESYM_SRC) && $(CARGO) build --features=cheader,dont-generate-test-files --release + +$(LIBBLAZESYM_OBJ): $(LIBBLAZESYM_SRC)/target/release/libblazesym.a | $(OUTPUT) + $(call msg,LIB, $@) + $(Q)cp $(LIBBLAZESYM_SRC)/target/release/libblazesym.a $@ + +$(LIBBLAZESYM_HEADER): $(LIBBLAZESYM_SRC)/target/release/libblazesym.a | $(OUTPUT) + $(call msg,LIB,$@) + $(Q)cp $(LIBBLAZESYM_SRC)/target/release/blazesym.h $@ + +# Build BPF code +$(OUTPUT)/%.bpf.o: %.bpf.c $(LIBBPF_OBJ) $(wildcard %.h) $(VMLINUX) | $(OUTPUT) $(BPFTOOL) + $(call msg,BPF,$@) + $(Q)$(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(ARCH) \ + $(INCLUDES) $(CLANG_BPF_SYS_INCLUDES) \ + -c $(filter %.c,$^) -o $(patsubst %.bpf.o,%.tmp.bpf.o,$@) + $(Q)$(BPFTOOL) gen object $@ $(patsubst %.bpf.o,%.tmp.bpf.o,$@) + +# Generate BPF skeletons +$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(OUTPUT) $(BPFTOOL) + $(call msg,GEN-SKEL,$@) + $(Q)$(BPFTOOL) gen skeleton $< > $@ + +# Build user-space code +$(patsubst %,$(OUTPUT)/%.o,$(APPS)): %.o: %.skel.h + +$(OUTPUT)/%.o: %.c $(wildcard %.h) | $(OUTPUT) $(call msg,CC,$@) - $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ + $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@ + +$(patsubst %,$(OUTPUT)/%.o,$(BZS_APPS)): $(LIBBLAZESYM_HEADER) + +$(BZS_APPS): $(LIBBLAZESYM_OBJ) # Build application binary $(APPS): %: $(OUTPUT)/%.o $(LIBBPF_OBJ) | $(OUTPUT) diff --git a/example/hot_patch/redis/README.md b/example/hot_patch/redis/README.md index 1b33398d..52817e96 100644 --- a/example/hot_patch/redis/README.md +++ b/example/hot_patch/redis/README.md @@ -6,83 +6,83 @@ you can compile one in `redis-5.0-rc1`. 1. find function -```console -$ nm ./redis-server | grep xgroupCommand -00000000000b7c80 T xgroupCommand -00000000000280b9 t xgroupCommand.cold -``` + ```console + $ nm ./redis-server | grep xgroupCommand + 00000000000b7c80 T xgroupCommand + 00000000000280b9 t xgroupCommand.cold + ``` 2. generate btf (optional) -```sh -pahole --btf_encode_detached redis-server.btf ./redis-server -``` + ```sh + pahole --btf_encode_detached redis-server.btf ./redis-server + ``` 3. generate header -```sh -bpftool btf dump file redis-server.btf format c > redis-server.btf.h -``` + ```sh + bpftool btf dump file redis-server.btf format c > redis-server.btf.h + ``` 4. trigger the POC(before the patch): -PoC: + PoC: -```console -$ ./redis-server + ```console + $ ./redis-server -# on another bash -$ ./redis-cli -p 6379 -127.0.0.1:1234> set a 123 -OK -127.0.0.1:1234> xgroup create a b $ -Error: Connection reset by peer <— segfault'ed -127.0.0.1:1234> + # on another bash + $ ./redis-cli -p 6379 + 127.0.0.1:1234> set a 123 + OK + 127.0.0.1:1234> xgroup create a b $ + Error: Connection reset by peer <— segfault'ed + 127.0.0.1:1234> -The bug also could be triggered via netcat -$ nc 127.0.0.1 1234 -set a 123 -+OK -xgroup create a b $ <— segfault’ed after this line -``` + The bug also could be triggered via netcat + $ nc 127.0.0.1 1234 + set a 123 + +OK + xgroup create a b $ <— segfault’ed after this line + ``` 5. prepare patch: -This is fixed by commit: + This is fixed by commit: -``` -@@ -1576,7 +1576,7 @@ NULL - /* Lookup the key now, this is common for all the subcommands but HELP. */ - if (c->argc >= 4) { -robj *o = lookupKeyWriteOrReply(c,c->argv[2],shared.nokeyerr); -- if (o == NULL) return; -+ if (o == NULL || checkType(c,o,OBJ_STREAM)) return; - s = o->ptr; - grpname = c->argv[3]->ptr; -``` + ```c + @@ -1576,7 +1576,7 @@ NULL + /* Lookup the key now, this is common for all the subcommands but HELP. */ + if (c->argc >= 4) { + robj *o = lookupKeyWriteOrReply(c,c->argv[2],shared.nokeyerr); + - if (o == NULL) return; + + if (o == NULL || checkType(c,o,OBJ_STREAM)) return; + s = o->ptr; + grpname = c->argv[3]->ptr; + ``` -see poc.bpf.c and poc.json. + see poc.bpf.c and poc.json. 6. after patch, run the command to install: -```console -$ sudo build/tools/cli/bpftime-cli workloads/ebpf-patch-dev/poc4-redis/poc.json -Successfully injected. ID: 1 -``` - -results in: - -```console -find and load program: xgroupCommand -load insn cnt: 79 -attach replace 0x562b4fcf7c80 -Successfully attached -xgroupCommand: 0x562b50b15c98 -c->argc >= 4lookupKeyWriteOrReply: 0x562b50b15c98 0x562b50b23ed8 (nil) -find func lookupKeyWrite at 545 -----------------------op code: 0 ret: 0 -xgroupCommand: 0x562b50b15c98 -c->argc >= 4lookupKeyWriteOrReply: 0x562b50b15c98 0x562b50b220d8 (nil) -find func lookupKeyWrite at 545 -----------------------op code: 0 ret: 0 -``` + ```console + $ sudo build/tools/cli/bpftime-cli workloads/ebpf-patch-dev/poc4-redis/poc.json + Successfully injected. ID: 1 + ``` + + results in: + + ```console + find and load program: xgroupCommand + load insn cnt: 79 + attach replace 0x562b4fcf7c80 + Successfully attached + xgroupCommand: 0x562b50b15c98 + c->argc >= 4lookupKeyWriteOrReply: 0x562b50b15c98 0x562b50b23ed8 (nil) + find func lookupKeyWrite at 545 + ----------------------op code: 0 ret: 0 + xgroupCommand: 0x562b50b15c98 + c->argc >= 4lookupKeyWriteOrReply: 0x562b50b15c98 0x562b50b220d8 (nil) + find func lookupKeyWrite at 545 + ----------------------op code: 0 ret: 0 + ``` diff --git a/example/hot_patch/redis/ffi.bpf.h b/example/hot_patch/redis/ffi.bpf.h new file mode 100644 index 00000000..19a8e4e5 --- /dev/null +++ b/example/hot_patch/redis/ffi.bpf.h @@ -0,0 +1,97 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ +#ifndef FFI_HELPER_H +#define FFI_HELPER_H + +typedef unsigned long long uint64_t; +typedef long long int64_t; +typedef int int32_t; +// global context not support +// uint64_t context; + +union arg_val { + uint64_t uint64; + int64_t int64; + int32_t int32; + double double_val; + void *ptr; +}; + +struct arg_list { + uint64_t args[6]; +}; + +#define FFI_HELPER_ID_DISPATCHER 1000 +#define FFI_HELPER_ID_FIND_ID 1001 + +static const uint64_t (*ffi_call)(uint64_t id, uint64_t arg_list) = (void *)FFI_HELPER_ID_DISPATCHER; +static const uint64_t (*ffi_find_func_id)(const char* func_name) = (void *)FFI_HELPER_ID_FIND_ID; + +// func: function id +#define FFI_CALL_0(func) \ + ({ \ + struct arg_list argn = {0}; \ + ffi_call(func, (uint64_t)&argn); \ + }) + +// func: function id +#define FFI_CALL_1(func, arg1) \ + ({ \ + struct arg_list argn = {0}; \ + argn.args[0] = (uint64_t)arg1; \ + ffi_call(func, (uint64_t)&argn); \ + }) + +// func: function id +#define FFI_CALL_2(func, arg1, arg2) \ + ({ \ + struct arg_list argn = {0}; \ + argn.args[0] = (uint64_t)arg1; \ + argn.args[1] = (uint64_t)arg2; \ + ffi_call(func, (uint64_t)&argn); \ + }) + +// func: function id +#define FFI_CALL_3(func, arg1, arg2, arg3) \ + ({ \ + struct arg_list argn = {0}; \ + argn.args[0] = (uint64_t)arg1; \ + argn.args[1] = (uint64_t)arg2; \ + argn.args[2] = (uint64_t)arg3; \ + ffi_call(func, (uint64_t)&argn); \ + }) + +// func: function name +#define FFI_CALL_NAME_0(func_name) \ + ({ \ + char funcname[] = func_name; \ + uint64_t func_id = ffi_find_func_id(funcname); \ + FFI_CALL_0(func_id);\ + }) + + +#define FFI_CALL_NAME_1(func_name, arg1) \ + ({ \ + char funcname[] = func_name; \ + uint64_t func_id = ffi_find_func_id(funcname); \ + FFI_CALL_1(func_id, arg1);\ + }) + +#define FFI_CALL_NAME_2(func_name, arg1, arg2) \ + ({ \ + char funcname[] = func_name; \ + uint64_t func_id = ffi_find_func_id(funcname); \ + FFI_CALL_2(func_id, arg1, arg2); \ + }) + +#define FFI_CALL_NAME_3(func_name, arg1, arg2, arg3) \ + ({ \ + char funcname[] = func_name; \ + uint64_t func_id = ffi_find_func_id(funcname); \ + FFI_CALL_3(func_id, arg1, arg2, arg3); \ + }) + +#endif \ No newline at end of file diff --git a/example/hot_patch/redis/redis.bpf.c b/example/hot_patch/redis/redis-patch.bpf.c similarity index 100% rename from example/hot_patch/redis/redis.bpf.c rename to example/hot_patch/redis/redis-patch.bpf.c diff --git a/example/hot_patch/redis/redis-patch.c b/example/hot_patch/redis/redis-patch.c new file mode 100644 index 00000000..0a8a80b8 --- /dev/null +++ b/example/hot_patch/redis/redis-patch.c @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +/* Copyright (c) 2020 Facebook */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "redis-patch.skel.h" +#include + +#define warn(...) fprintf(stderr, __VA_ARGS__) + +static int libbpf_print_fn(enum libbpf_print_level level, const char *format, + va_list args) +{ + return vfprintf(stderr, format, args); +} + +static volatile bool exiting = false; + +static void sig_handler(int sig) +{ + exiting = true; +} + +int main(int argc, char **argv) +{ + struct redis_patch_bpf *skel; + int err; + + /* Set up libbpf errors and debug info callback */ + libbpf_set_print(libbpf_print_fn); + + /* Cleaner handling of Ctrl-C */ + signal(SIGINT, sig_handler); + signal(SIGTERM, sig_handler); + + /* Load and verify BPF application */ + skel = redis_patch_bpf__open(); + if (!skel) { + fprintf(stderr, "Failed to open and load BPF skeleton\n"); + return 1; + } + + /* Load & verify BPF programs */ + err = redis_patch_bpf__load(skel); + if (err) { + fprintf(stderr, "Failed to load and verify BPF skeleton\n"); + goto cleanup; + } + // LIBBPF_OPTS(bpf_uprobe_opts, attach_opts, .func_name = "target_func", + // .retprobe = false, .attach_mode = PROBE_ATTACH_MODE_PERF); + // struct bpf_link *attach = bpf_program__attach_uprobe_opts( + // skel->progs.do_uprobe_trace, -1, "example/redis-patch/victim", 0, + // &attach_opts); + // if (!attach) { + // fprintf(stderr, "Failed to attach BPF skeleton\n"); + // err = -1; + // goto cleanup; + // } + while (!exiting) { + sleep(1); + } +cleanup: + /* Clean up */ + redis_patch_bpf__destroy(skel); + + return err < 0 ? -err : 0; +} diff --git a/runtime/include/bpftime_prog.hpp b/runtime/include/bpftime_prog.hpp index 57eeffb8..cab7dd95 100644 --- a/runtime/include/bpftime_prog.hpp +++ b/runtime/include/bpftime_prog.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _BPFTIME_PROG_HPP #define _BPFTIME_PROG_HPP diff --git a/runtime/include/bpftime_shm.hpp b/runtime/include/bpftime_shm.hpp index 50f1ed47..151bb929 100644 --- a/runtime/include/bpftime_shm.hpp +++ b/runtime/include/bpftime_shm.hpp @@ -43,8 +43,10 @@ enum class bpf_event_type { // custom types BPF_TYPE_UPROBE = 6, BPF_TYPE_URETPROBE = 7, - BPF_TYPE_FILTER = 8, - BPF_TYPE_REPLACE = 9, + BPF_TYPE_UFILTER = 8, + BPF_TYPE_UREPLACE = 9, + + BPF_TYPE_SYSCALL_FILTER = 10, }; #define KERNEL_USER_MAP_OFFSET 1000 diff --git a/runtime/src/attach/attach_internal.hpp b/runtime/src/attach/attach_internal.hpp index 3cce6cb2..d5829bee 100644 --- a/runtime/src/attach/attach_internal.hpp +++ b/runtime/src/attach/attach_internal.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _ATTACH_INTERNAL_HPP #define _ATTACH_INTERNAL_HPP #include diff --git a/runtime/src/attach/attach_manager/base_attach_manager.cpp b/runtime/src/attach/attach_manager/base_attach_manager.cpp index 6414785b..253aac51 100644 --- a/runtime/src/attach/attach_manager/base_attach_manager.cpp +++ b/runtime/src/attach/attach_manager/base_attach_manager.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "spdlog/spdlog.h" #include #include diff --git a/runtime/src/attach/attach_manager/base_attach_manager.hpp b/runtime/src/attach/attach_manager/base_attach_manager.hpp index 251b917b..58600cfd 100644 --- a/runtime/src/attach/attach_manager/base_attach_manager.hpp +++ b/runtime/src/attach/attach_manager/base_attach_manager.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _BPFTIME_ATTACH_MANAGER_HPP #define _BPFTIME_ATTACH_MANAGER_HPP #include diff --git a/runtime/src/attach/attach_manager/frida_attach_manager.cpp b/runtime/src/attach/attach_manager/frida_attach_manager.cpp index c079c2cf..4596e136 100644 --- a/runtime/src/attach/attach_manager/frida_attach_manager.cpp +++ b/runtime/src/attach/attach_manager/frida_attach_manager.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "attach/attach_manager/base_attach_manager.hpp" #include "frida-gum.h" #include "spdlog/spdlog.h" diff --git a/runtime/src/attach/attach_manager/frida_attach_manager.hpp b/runtime/src/attach/attach_manager/frida_attach_manager.hpp index 3e35d76b..89897693 100644 --- a/runtime/src/attach/attach_manager/frida_attach_manager.hpp +++ b/runtime/src/attach/attach_manager/frida_attach_manager.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _BPFTIME_FRIDA_ATTACH_MANAGER_HPP #define _BPFTIME_FRIDA_ATTACH_MANAGER_HPP diff --git a/runtime/src/attach/bpf_attach_ctx.cpp b/runtime/src/attach/bpf_attach_ctx.cpp index eb246322..fc9e9460 100644 --- a/runtime/src/attach/bpf_attach_ctx.cpp +++ b/runtime/src/attach/bpf_attach_ctx.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "attach/attach_manager/frida_attach_manager.hpp" #include "bpftime.hpp" #include "handler/epoll_handler.hpp" @@ -247,8 +252,8 @@ int bpf_attach_ctx::init_attach_ctx_from_handlers( std::get(handler); void *func_addr = nullptr; switch (event_handler.type) { - case bpf_event_type::BPF_TYPE_FILTER: - case bpf_event_type::BPF_TYPE_REPLACE: + case bpf_event_type::BPF_TYPE_UFILTER: + case bpf_event_type::BPF_TYPE_UREPLACE: case bpf_event_type::BPF_TYPE_UPROBE: case bpf_event_type::BPF_TYPE_URETPROBE: func_addr = @@ -264,7 +269,7 @@ int bpf_attach_ctx::init_attach_ctx_from_handlers( } // attach base on events switch (event_handler.type) { - case bpf_event_type::BPF_TYPE_FILTER: { + case bpf_event_type::BPF_TYPE_UFILTER: { spdlog::debug( "Creating filter for perf event fd {}", i); @@ -297,7 +302,7 @@ int bpf_attach_ctx::init_attach_ctx_from_handlers( i, err); break; } - case bpf_event_type::BPF_TYPE_REPLACE: { + case bpf_event_type::BPF_TYPE_UREPLACE: { spdlog::debug( "Creating replace for perf event fd {}", i); diff --git a/runtime/src/bpf_helper.cpp b/runtime/src/bpf_helper.cpp index 539098f4..8c9a6ef3 100644 --- a/runtime/src/bpf_helper.cpp +++ b/runtime/src/bpf_helper.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "bpftime_helper_group.hpp" #include #include diff --git a/runtime/src/bpf_map/map_common_def.hpp b/runtime/src/bpf_map/map_common_def.hpp index 8b0a4d97..b93c2495 100644 --- a/runtime/src/bpf_map/map_common_def.hpp +++ b/runtime/src/bpf_map/map_common_def.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _MAP_COMMON_DEF_HPP #define _MAP_COMMON_DEF_HPP #include "spdlog/spdlog.h" diff --git a/runtime/src/bpf_map/shared/array_map_kernel_user.cpp b/runtime/src/bpf_map/shared/array_map_kernel_user.cpp index 9b714903..af69f3b5 100644 --- a/runtime/src/bpf_map/shared/array_map_kernel_user.cpp +++ b/runtime/src/bpf_map/shared/array_map_kernel_user.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "spdlog/spdlog.h" #include #include diff --git a/runtime/src/bpf_map/shared/array_map_kernel_user.hpp b/runtime/src/bpf_map/shared/array_map_kernel_user.hpp index 1bde0c2d..86fa932a 100644 --- a/runtime/src/bpf_map/shared/array_map_kernel_user.hpp +++ b/runtime/src/bpf_map/shared/array_map_kernel_user.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _BPFTIME_KERNEL_ARRAY_MAP_HPP #define _BPFTIME_KERNEL_ARRAY_MAP_HPP #include diff --git a/runtime/src/bpf_map/shared/hash_map_kernel_user.cpp b/runtime/src/bpf_map/shared/hash_map_kernel_user.cpp index 23e0668b..e4dd404d 100644 --- a/runtime/src/bpf_map/shared/hash_map_kernel_user.cpp +++ b/runtime/src/bpf_map/shared/hash_map_kernel_user.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "spdlog/spdlog.h" #include #include diff --git a/runtime/src/bpf_map/shared/hash_map_kernel_user.hpp b/runtime/src/bpf_map/shared/hash_map_kernel_user.hpp index d894279c..92826b1a 100644 --- a/runtime/src/bpf_map/shared/hash_map_kernel_user.hpp +++ b/runtime/src/bpf_map/shared/hash_map_kernel_user.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _BPFTIME_KERNEL_HASH_MAP_HPP #define _BPFTIME_KERNEL_HASH_MAP_HPP #include diff --git a/runtime/src/bpf_map/shared/percpu_array_map_kernel_user.cpp b/runtime/src/bpf_map/shared/percpu_array_map_kernel_user.cpp index edbcb15f..1af861dd 100644 --- a/runtime/src/bpf_map/shared/percpu_array_map_kernel_user.cpp +++ b/runtime/src/bpf_map/shared/percpu_array_map_kernel_user.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "bpf/bpf.h" #include "spdlog/spdlog.h" #include diff --git a/runtime/src/bpf_map/shared/percpu_array_map_kernel_user.hpp b/runtime/src/bpf_map/shared/percpu_array_map_kernel_user.hpp index 85be25eb..599273b4 100644 --- a/runtime/src/bpf_map/shared/percpu_array_map_kernel_user.hpp +++ b/runtime/src/bpf_map/shared/percpu_array_map_kernel_user.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _BPFTIME_PERCPU_ARRAY_MAP_KERNEL_USER_HPP #define _BPFTIME_PERCPU_ARRAY_MAP_KERNEL_USER_HPP #include diff --git a/runtime/src/bpf_map/shared/perf_event_array_kernel_user.cpp b/runtime/src/bpf_map/shared/perf_event_array_kernel_user.cpp index 44ee40f3..97a47375 100644 --- a/runtime/src/bpf_map/shared/perf_event_array_kernel_user.cpp +++ b/runtime/src/bpf_map/shared/perf_event_array_kernel_user.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "bpf/bpf.h" #include "bpf/libbpf_common.h" #include "bpftool/libbpf/include/uapi/linux/bpf.h" diff --git a/runtime/src/bpf_map/shared/perf_event_array_kernel_user.hpp b/runtime/src/bpf_map/shared/perf_event_array_kernel_user.hpp index 332c6f89..1886e956 100644 --- a/runtime/src/bpf_map/shared/perf_event_array_kernel_user.hpp +++ b/runtime/src/bpf_map/shared/perf_event_array_kernel_user.hpp @@ -1,9 +1,15 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _BPFTIME_PERF_EVENT_ARRAY_KERNEL_USER #define _BPFTIME_PERF_EVENT_ARRAY_KERNEL_USER #include #include #include #include + namespace bpftime { diff --git a/runtime/src/bpf_map/userspace/array_map.cpp b/runtime/src/bpf_map/userspace/array_map.cpp index 8129567a..abfd4896 100644 --- a/runtime/src/bpf_map/userspace/array_map.cpp +++ b/runtime/src/bpf_map/userspace/array_map.cpp @@ -1,5 +1,11 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include #include + namespace bpftime { diff --git a/runtime/src/bpf_map/userspace/array_map.hpp b/runtime/src/bpf_map/userspace/array_map.hpp index a72a2de3..fdd6350c 100644 --- a/runtime/src/bpf_map/userspace/array_map.hpp +++ b/runtime/src/bpf_map/userspace/array_map.hpp @@ -1,6 +1,12 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _ARRAY_MAP_HPP #define _ARRAY_MAP_HPP #include + namespace bpftime { diff --git a/runtime/src/bpf_map/userspace/hash_map.cpp b/runtime/src/bpf_map/userspace/hash_map.cpp index 2c1bcc3f..446c71ba 100644 --- a/runtime/src/bpf_map/userspace/hash_map.cpp +++ b/runtime/src/bpf_map/userspace/hash_map.cpp @@ -1,8 +1,14 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "spdlog/spdlog.h" #include #include #include #include + namespace bpftime { hash_map_impl::hash_map_impl(managed_shared_memory &memory, uint32_t key_size, diff --git a/runtime/src/bpf_map/userspace/hash_map.hpp b/runtime/src/bpf_map/userspace/hash_map.hpp index 56e05a30..8a7ce9eb 100644 --- a/runtime/src/bpf_map/userspace/hash_map.hpp +++ b/runtime/src/bpf_map/userspace/hash_map.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _HASHMAP_HPP #define _HASHMAP_HPP #include @@ -7,6 +12,7 @@ #include #include #include + namespace bpftime { diff --git a/runtime/src/bpf_map/userspace/per_cpu_array_map.cpp b/runtime/src/bpf_map/userspace/per_cpu_array_map.cpp index 82bc264f..b13aeae1 100644 --- a/runtime/src/bpf_map/userspace/per_cpu_array_map.cpp +++ b/runtime/src/bpf_map/userspace/per_cpu_array_map.cpp @@ -1,9 +1,15 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "bpf_map/map_common_def.hpp" #include "spdlog/spdlog.h" #include #include #include #include + namespace bpftime { diff --git a/runtime/src/bpf_map/userspace/per_cpu_array_map.hpp b/runtime/src/bpf_map/userspace/per_cpu_array_map.hpp index 724c018d..931f8c6f 100644 --- a/runtime/src/bpf_map/userspace/per_cpu_array_map.hpp +++ b/runtime/src/bpf_map/userspace/per_cpu_array_map.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _BPFTIME_PER_CPU_ARRAY_MAP_HPP #define _BPFTIME_PER_CPU_ARRAY_MAP_HPP #include "bpf_map/map_common_def.hpp" diff --git a/runtime/src/bpf_map/userspace/per_cpu_hash_map.cpp b/runtime/src/bpf_map/userspace/per_cpu_hash_map.cpp index db215c84..5a665436 100644 --- a/runtime/src/bpf_map/userspace/per_cpu_hash_map.cpp +++ b/runtime/src/bpf_map/userspace/per_cpu_hash_map.cpp @@ -1,9 +1,15 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "bpf_map/map_common_def.hpp" #include "spdlog/fmt/bin_to_hex.h" #include "spdlog/spdlog.h" #include #include #include + namespace bpftime { per_cpu_hash_map_impl::per_cpu_hash_map_impl( diff --git a/runtime/src/bpf_map/userspace/per_cpu_hash_map.hpp b/runtime/src/bpf_map/userspace/per_cpu_hash_map.hpp index b66d16ae..5bbcdcc7 100644 --- a/runtime/src/bpf_map/userspace/per_cpu_hash_map.hpp +++ b/runtime/src/bpf_map/userspace/per_cpu_hash_map.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _BPFTIME_PER_CPU_HASH_MAP_HPP #define _BPFTIME_PER_CPU_HASH_MAP_HPP #include diff --git a/runtime/src/bpf_map/userspace/perf_event_array_map.cpp b/runtime/src/bpf_map/userspace/perf_event_array_map.cpp index 3176464b..2c18fcdf 100644 --- a/runtime/src/bpf_map/userspace/perf_event_array_map.cpp +++ b/runtime/src/bpf_map/userspace/perf_event_array_map.cpp @@ -1,8 +1,14 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "spdlog/spdlog.h" #include #include #include #include + namespace bpftime { perf_event_array_map_impl::perf_event_array_map_impl( diff --git a/runtime/src/bpf_map/userspace/perf_event_array_map.hpp b/runtime/src/bpf_map/userspace/perf_event_array_map.hpp index 8e5dca53..c78892b5 100644 --- a/runtime/src/bpf_map/userspace/perf_event_array_map.hpp +++ b/runtime/src/bpf_map/userspace/perf_event_array_map.hpp @@ -1,8 +1,14 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _PERF_EVENT_ARRAY_HPP #define _PERF_EVENT_ARRAY_HPP #include #include #include + namespace bpftime { diff --git a/runtime/src/bpf_map/userspace/ringbuf_map.cpp b/runtime/src/bpf_map/userspace/ringbuf_map.cpp index 58f63995..0159f35e 100644 --- a/runtime/src/bpf_map/userspace/ringbuf_map.cpp +++ b/runtime/src/bpf_map/userspace/ringbuf_map.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include #include #include diff --git a/runtime/src/bpf_map/userspace/ringbuf_map.hpp b/runtime/src/bpf_map/userspace/ringbuf_map.hpp index 73b7aff9..2138ac34 100644 --- a/runtime/src/bpf_map/userspace/ringbuf_map.hpp +++ b/runtime/src/bpf_map/userspace/ringbuf_map.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _RINGBUF_MAP_HPP #define _RINGBUF_MAP_HPP #include @@ -10,6 +15,7 @@ #include #include #include + namespace bpftime { using sharable_mutex_ptr = boost::interprocess::managed_unique_ptr< diff --git a/runtime/src/bpftime_handler.hpp b/runtime/src/bpftime_handler.hpp index 8b32118b..6dd1a015 100644 --- a/runtime/src/bpftime_handler.hpp +++ b/runtime/src/bpftime_handler.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _BPFTIME_HANDLER_HPP #define _BPFTIME_HANDLER_HPP diff --git a/runtime/src/bpftime_internal.h b/runtime/src/bpftime_internal.h index 26616a53..a32f2c1b 100644 --- a/runtime/src/bpftime_internal.h +++ b/runtime/src/bpftime_internal.h @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef EBPF_RUNTIME_INTERNEL_H_ #define EBPF_RUNTIME_INTERNEL_H_ diff --git a/runtime/src/bpftime_prog.cpp b/runtime/src/bpftime_prog.cpp index 4386668e..92b31ef4 100644 --- a/runtime/src/bpftime_prog.cpp +++ b/runtime/src/bpftime_prog.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "bpftime.hpp" #include "bpftime_helper_group.hpp" #include "bpftime_internal.h" diff --git a/runtime/src/bpftime_shm.cpp b/runtime/src/bpftime_shm.cpp index 346a8750..263d2098 100644 --- a/runtime/src/bpftime_shm.cpp +++ b/runtime/src/bpftime_shm.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "handler/epoll_handler.hpp" #include "handler/map_handler.hpp" #include "handler/perf_event_handler.hpp" diff --git a/runtime/src/bpftime_shm_internal.cpp b/runtime/src/bpftime_shm_internal.cpp index 4823335c..4480c4a3 100644 --- a/runtime/src/bpftime_shm_internal.cpp +++ b/runtime/src/bpftime_shm_internal.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "bpftime_shm.hpp" #include "handler/epoll_handler.hpp" #include "handler/perf_event_handler.hpp" diff --git a/runtime/src/bpftime_shm_internal.hpp b/runtime/src/bpftime_shm_internal.hpp index 9515b25d..c9afa367 100644 --- a/runtime/src/bpftime_shm_internal.hpp +++ b/runtime/src/bpftime_shm_internal.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _BPFTIME_SHM_INTERNAL #define _BPFTIME_SHM_INTERNAL #include "bpf_map/userspace/array_map.hpp" diff --git a/runtime/src/bpftime_shm_json.cpp b/runtime/src/bpftime_shm_json.cpp index a45e1e2b..520b7dfb 100644 --- a/runtime/src/bpftime_shm_json.cpp +++ b/runtime/src/bpftime_shm_json.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "bpftime_shm.hpp" #include "handler/epoll_handler.hpp" #include "handler/perf_event_handler.hpp" diff --git a/runtime/src/bpftime_shm_json.hpp b/runtime/src/bpftime_shm_json.hpp index a1040a18..a95f2787 100644 --- a/runtime/src/bpftime_shm_json.hpp +++ b/runtime/src/bpftime_shm_json.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef BPFTIME_JSON_EXPORTER_HPP #define BPFTIME_JSON_EXPORTER_HPP diff --git a/runtime/src/ffi.cpp b/runtime/src/ffi.cpp index a29f191e..c66956c1 100644 --- a/runtime/src/ffi.cpp +++ b/runtime/src/ffi.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include #include #include "bpftime_internal.h" diff --git a/runtime/src/handler/btf_handler.hpp b/runtime/src/handler/btf_handler.hpp index 6f634989..644b6302 100644 --- a/runtime/src/handler/btf_handler.hpp +++ b/runtime/src/handler/btf_handler.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _BPFTIME_BTF_HANDLER_HPP #define _BPFTIME_BTF_HANDLER_HPP #include diff --git a/runtime/src/handler/epoll_handler.cpp b/runtime/src/handler/epoll_handler.cpp index 5ea05f7c..bf5bc7a8 100644 --- a/runtime/src/handler/epoll_handler.cpp +++ b/runtime/src/handler/epoll_handler.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include #include namespace bpftime diff --git a/runtime/src/handler/epoll_handler.hpp b/runtime/src/handler/epoll_handler.hpp index aedbb303..ce9287b7 100644 --- a/runtime/src/handler/epoll_handler.hpp +++ b/runtime/src/handler/epoll_handler.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _EPOLL_HANDLER_HPP #define _EPOLL_HANDLER_HPP #include "handler/perf_event_handler.hpp" diff --git a/runtime/src/handler/handler_manager.cpp b/runtime/src/handler/handler_manager.cpp index ec5e3121..cf570a77 100644 --- a/runtime/src/handler/handler_manager.cpp +++ b/runtime/src/handler/handler_manager.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "handler/perf_event_handler.hpp" #include "handler/prog_handler.hpp" #include "spdlog/spdlog.h" diff --git a/runtime/src/handler/handler_manager.hpp b/runtime/src/handler/handler_manager.hpp index bd0e53b2..e419b85a 100644 --- a/runtime/src/handler/handler_manager.hpp +++ b/runtime/src/handler/handler_manager.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _HANDLER_MANAGER_HPP #define _HANDLER_MANAGER_HPP #include "bpftime_config.hpp" diff --git a/runtime/src/handler/link_handler.hpp b/runtime/src/handler/link_handler.hpp index 1f590858..cf60ee5e 100644 --- a/runtime/src/handler/link_handler.hpp +++ b/runtime/src/handler/link_handler.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _LINK_HANDLER_HPP #define _LINK_HANDLER_HPP #include diff --git a/runtime/src/handler/map_handler.cpp b/runtime/src/handler/map_handler.cpp index 3161aaa1..31612c87 100644 --- a/runtime/src/handler/map_handler.cpp +++ b/runtime/src/handler/map_handler.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "bpf_map/userspace/per_cpu_array_map.hpp" #include "bpf_map/userspace/per_cpu_hash_map.hpp" #include diff --git a/runtime/src/handler/map_handler.hpp b/runtime/src/handler/map_handler.hpp index 9865b801..f81eac87 100644 --- a/runtime/src/handler/map_handler.hpp +++ b/runtime/src/handler/map_handler.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _MAP_HANDLER #define _MAP_HANDLER #include "bpf_map/userspace/array_map.hpp" diff --git a/runtime/src/handler/perf_event_handler.cpp b/runtime/src/handler/perf_event_handler.cpp index 363dad1d..8c5f0753 100644 --- a/runtime/src/handler/perf_event_handler.cpp +++ b/runtime/src/handler/perf_event_handler.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "linux/perf_event.h" #include "spdlog/spdlog.h" #include diff --git a/runtime/src/handler/perf_event_handler.hpp b/runtime/src/handler/perf_event_handler.hpp index be9463be..5e4cd433 100644 --- a/runtime/src/handler/perf_event_handler.hpp +++ b/runtime/src/handler/perf_event_handler.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _PERF_EVENT_HANDLER #define _PERF_EVENT_HANDLER #include "spdlog/spdlog.h" diff --git a/runtime/src/handler/prog_handler.cpp b/runtime/src/handler/prog_handler.cpp index 06f2f013..780845e5 100644 --- a/runtime/src/handler/prog_handler.cpp +++ b/runtime/src/handler/prog_handler.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include namespace bpftime { diff --git a/runtime/src/syscall_table.cpp b/runtime/src/syscall_table.cpp index ae4b62da..1506400f 100644 --- a/runtime/src/syscall_table.cpp +++ b/runtime/src/syscall_table.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "syscall_table.hpp" #include "spdlog/spdlog.h" #include diff --git a/runtime/syscall-server/syscall_context.cpp b/runtime/syscall-server/syscall_context.cpp index 75efcb77..eef94def 100644 --- a/runtime/syscall-server/syscall_context.cpp +++ b/runtime/syscall-server/syscall_context.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "syscall_context.hpp" #include "bpftime_shm.hpp" #include "handler/perf_event_handler.hpp" @@ -253,7 +258,7 @@ int syscall_context::handle_perfevent(perf_event_attr *attr, pid_t pid, int cpu, spdlog::debug("Created software perf event with fd {}", fd); return fd; } - spdlog::warn("Calling original perf event open"); + spdlog::info("Calling original perf event open"); return orig_syscall_fn(__NR_perf_event_open, (uint64_t)(uintptr_t)attr, (uint64_t)pid, (uint64_t)cpu, (uint64_t)group_fd, (uint64_t)flags); diff --git a/runtime/syscall-server/syscall_context.hpp b/runtime/syscall-server/syscall_context.hpp index 3bef28f4..dc30f750 100644 --- a/runtime/syscall-server/syscall_context.hpp +++ b/runtime/syscall-server/syscall_context.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _SYSCALL_CONTEXT_HPP #define _SYSCALL_CONTEXT_HPP #include "linux/perf_event.h" diff --git a/runtime/syscall-server/syscall_server_main.cpp b/runtime/syscall-server/syscall_server_main.cpp index 6ca2de95..f9930aae 100644 --- a/runtime/syscall-server/syscall_server_main.cpp +++ b/runtime/syscall-server/syscall_server_main.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "syscall_context.hpp" #include "bpftime_shm.hpp" #include "linux/bpf.h" diff --git a/runtime/syscall-server/syscall_server_utils.cpp b/runtime/syscall-server/syscall_server_utils.cpp index 4f27118f..d99b4097 100644 --- a/runtime/syscall-server/syscall_server_utils.cpp +++ b/runtime/syscall-server/syscall_server_utils.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "bpftime_shm_internal.hpp" #include #include diff --git a/runtime/syscall-server/syscall_server_utils.hpp b/runtime/syscall-server/syscall_server_utils.hpp index 9a4da9b3..f2af1cf8 100644 --- a/runtime/syscall-server/syscall_server_utils.hpp +++ b/runtime/syscall-server/syscall_server_utils.hpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _SYSCALL_SERVER_UTILS_HPP #define _SYSCALL_SERVER_UTILS_HPP diff --git a/runtime/test/bpf/btf-relo.bpf.c b/runtime/test/bpf/btf-relo.bpf.c index f4bdac23..e5771ba2 100644 --- a/runtime/test/bpf/btf-relo.bpf.c +++ b/runtime/test/bpf/btf-relo.bpf.c @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #define USE_NEW_VERSION #ifndef BPF_NO_PRESERVE_ACCESS_INDEX diff --git a/runtime/test/bpf/ffi-btf.bpf.c b/runtime/test/bpf/ffi-btf.bpf.c index 286b49e4..3477fb69 100644 --- a/runtime/test/bpf/ffi-btf.bpf.c +++ b/runtime/test/bpf/ffi-btf.bpf.c @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "ffi.bpf.h" struct data { diff --git a/runtime/test/bpf/ffi.bpf.c b/runtime/test/bpf/ffi.bpf.c index 330f7a93..c7da266a 100644 --- a/runtime/test/bpf/ffi.bpf.c +++ b/runtime/test/bpf/ffi.bpf.c @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "ffi.bpf.h" struct data { diff --git a/runtime/test/bpf/ffi.bpf.h b/runtime/test/bpf/ffi.bpf.h index 644d29ce..19a8e4e5 100644 --- a/runtime/test/bpf/ffi.bpf.h +++ b/runtime/test/bpf/ffi.bpf.h @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef FFI_HELPER_H #define FFI_HELPER_H diff --git a/runtime/test/bpf/global.bpf.c b/runtime/test/bpf/global.bpf.c index 806d470e..ab486034 100644 --- a/runtime/test/bpf/global.bpf.c +++ b/runtime/test/bpf/global.bpf.c @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ const int i = 0; static int j = 1; int k = 1; diff --git a/runtime/test/bpf/hash-map-test.bpf.c b/runtime/test/bpf/hash-map-test.bpf.c index 25bb805e..606ccdf8 100644 --- a/runtime/test/bpf/hash-map-test.bpf.c +++ b/runtime/test/bpf/hash-map-test.bpf.c @@ -1,9 +1,14 @@ - +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ static void *(*bpf_map_lookup_elem)(void *map, const void *key) = (void *)1; static long (*bpf_map_update_elem)(void *map, const void *key, const void *value, unsigned long flags) = (void *)2; static long (*bpf_map_delete_elem)(void *map, const void *key) = (void *)3; + int bpf_main() { void *MAP_ID = (void *)0; diff --git a/runtime/test/bpf/helpers.bpf.c b/runtime/test/bpf/helpers.bpf.c index 22ef7fef..3427691e 100644 --- a/runtime/test/bpf/helpers.bpf.c +++ b/runtime/test/bpf/helpers.bpf.c @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #define BPF_NO_GLOBAL_DATA #include "vmlinux.h" #include "bpf/bpf_tracing.h" diff --git a/runtime/test/bpf/map.bpf.c b/runtime/test/bpf/map.bpf.c index 1a9e4b52..0483675a 100644 --- a/runtime/test/bpf/map.bpf.c +++ b/runtime/test/bpf/map.bpf.c @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ struct data { int key_size; diff --git a/runtime/test/bpf/patch.bpf.c b/runtime/test/bpf/patch.bpf.c index 8a2725d1..cce016ab 100644 --- a/runtime/test/bpf/patch.bpf.c +++ b/runtime/test/bpf/patch.bpf.c @@ -1,4 +1,8 @@ - +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ typedef unsigned long long uint64_t; enum PatchOp { diff --git a/runtime/test/bpf/replace.bpf.c b/runtime/test/bpf/replace.bpf.c index 306956cb..06adf3fb 100644 --- a/runtime/test/bpf/replace.bpf.c +++ b/runtime/test/bpf/replace.bpf.c @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "vmlinux.h" #include "bpf/bpf_tracing.h" #include "bpf/bpf_helpers.h" diff --git a/runtime/test/include/test_bpf_progs.h b/runtime/test/include/test_bpf_progs.h index 641d4ba9..6dc05d22 100644 --- a/runtime/test/include/test_bpf_progs.h +++ b/runtime/test/include/test_bpf_progs.h @@ -1,4 +1,8 @@ - +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef EBPF_TEST_CODE_H_ #define EBPF_TEST_CODE_H_ diff --git a/runtime/test/include/test_defs.h b/runtime/test/include/test_defs.h index 6b7153d4..51cac6d2 100644 --- a/runtime/test/include/test_defs.h +++ b/runtime/test/include/test_defs.h @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef TEST_DEF_BPFTIME_H #define TEST_DEF_BPFTIME_H diff --git a/runtime/test/include/test_minimal_bpf_host_ffi.h b/runtime/test/include/test_minimal_bpf_host_ffi.h index c2215dae..6e733c32 100644 --- a/runtime/test/include/test_minimal_bpf_host_ffi.h +++ b/runtime/test/include/test_minimal_bpf_host_ffi.h @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef BPF_MINIMAL_TEST_FFI_DEFS_H #define BPF_MINIMAL_TEST_FFI_DEFS_H diff --git a/runtime/test/src/test_attach_replace.cpp b/runtime/test/src/test_attach_replace.cpp index db2596a9..3832bcb0 100644 --- a/runtime/test/src/test_attach_replace.cpp +++ b/runtime/test/src/test_attach_replace.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include #include #include diff --git a/runtime/test/src/test_ffi.cpp b/runtime/test/src/test_ffi.cpp index f928b137..ee66fd5c 100644 --- a/runtime/test/src/test_ffi.cpp +++ b/runtime/test/src/test_ffi.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ // test find function address, register all functions from btf and call it from // ebpf #include "test_defs.h" diff --git a/runtime/test/src/test_ffi_register.cpp b/runtime/test/src/test_ffi_register.cpp index 685b75e5..195f7f3a 100644 --- a/runtime/test/src/test_ffi_register.cpp +++ b/runtime/test/src/test_ffi_register.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ // test register raw function and call it from ffi #include "test_defs.h" #include "bpftime.hpp" diff --git a/runtime/test/src/test_hash_map.c b/runtime/test/src/test_hash_map.c index 83438994..94f386e3 100644 --- a/runtime/test/src/test_hash_map.c +++ b/runtime/test/src/test_hash_map.c @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ // Test map operating helpers #include "bpftime.hpp" #include "map/map_common.h" diff --git a/runtime/test/src/test_helpers.cpp b/runtime/test/src/test_helpers.cpp index 5bae0eec..21572fbb 100644 --- a/runtime/test/src/test_helpers.cpp +++ b/runtime/test/src/test_helpers.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ // test register raw function and call it from ffi #include "bpftime_helper_group.hpp" #include "test_defs.h" diff --git a/runtime/test/src/test_shm_client.cpp b/runtime/test/src/test_shm_client.cpp index 48ba7a03..0787363a 100644 --- a/runtime/test/src/test_shm_client.cpp +++ b/runtime/test/src/test_shm_client.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include #include #include diff --git a/runtime/test/src/test_shm_hash_maps.cpp b/runtime/test/src/test_shm_hash_maps.cpp index c4f8494b..48090fb6 100644 --- a/runtime/test/src/test_shm_hash_maps.cpp +++ b/runtime/test/src/test_shm_hash_maps.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include #include "bpftime_handler.hpp" #include diff --git a/runtime/test/src/test_shm_progs_attach.cpp b/runtime/test/src/test_shm_progs_attach.cpp index 9ecc802f..b878f220 100644 --- a/runtime/test/src/test_shm_progs_attach.cpp +++ b/runtime/test/src/test_shm_progs_attach.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "bpf_attach_ctx.hpp" #include "bpftime_ffi.hpp" #include "bpftime_shm.hpp" @@ -102,7 +107,7 @@ void attach_replace(bpftime::handler_manager &manager_ref, // attach replace manager_ref.set_handler( 3, - bpf_perf_event_handler(bpf_event_type::BPF_TYPE_REPLACE, offset, + bpf_perf_event_handler(bpf_event_type::BPF_TYPE_UREPLACE, offset, -1, "", segment, true), segment); } diff --git a/runtime/test/src/test_shm_server.cpp b/runtime/test/src/test_shm_server.cpp index b80ba589..dd2f27d2 100644 --- a/runtime/test/src/test_shm_server.cpp +++ b/runtime/test/src/test_shm_server.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include #include #include diff --git a/tools/bpftimetool/main.cpp b/tools/bpftimetool/main.cpp index b468ce21..aeffee58 100644 --- a/tools/bpftimetool/main.cpp +++ b/tools/bpftimetool/main.cpp @@ -17,8 +17,8 @@ using namespace bpftime; int main(int argc, char *argv[]) { if (argc == 1) { - cerr << "Usage: " << argv[0] << " [load|import|export|remove] ..." - << endl + cerr << "Usage: " << argv[0] + << " [load|import|export|remove] ..." << endl << "Command-line tool to inspect and manage userspace eBPF objects" << endl; return 1; @@ -35,7 +35,8 @@ int main(int argc, char *argv[]) << endl; return 1; } - bpftime_initialize_global_shm(shm_open_type::SHM_CREATE_OR_OPEN); + bpftime_initialize_global_shm( + shm_open_type::SHM_CREATE_OR_OPEN); int fd = atoi(argv[2]); auto json_str = std::string(argv[3]); return bpftime_import_shm_handler_from_json(fd, @@ -59,21 +60,20 @@ int main(int argc, char *argv[]) << endl; return 1; } - bpftime_initialize_global_shm(shm_open_type::SHM_CREATE_OR_OPEN); + bpftime_initialize_global_shm( + shm_open_type::SHM_CREATE_OR_OPEN); auto filename = std::string(argv[2]); return bpftime_import_global_shm_from_json(filename.c_str()); } else if (cmd == "remove") { if (argc != 2) { - cerr << "Usage: " << argv[0] << " remove" - << endl + cerr << "Usage: " << argv[0] << " remove" << endl << "Remove the global shared memory system wide" << endl; return 1; } bpftime_remove_global_shm(); return 0; - } - else { + } else { cerr << "Invalid subcommand " << cmd << endl; return 1; } diff --git a/tools/cli-rs/src/main.rs b/tools/cli-rs/src/main.rs index 76a23869..3b6126b4 100644 --- a/tools/cli-rs/src/main.rs +++ b/tools/cli-rs/src/main.rs @@ -124,6 +124,7 @@ fn load_ebpf_object_into_kernel(path: impl AsRef) -> anyhow::Result<()> { } Ok(()) } + #[allow(non_upper_case_globals)] static subprocess_pid: AtomicU32 = AtomicU32::new(0); diff --git a/vm/llvm-jit/src/bpf_jit.cpp b/vm/llvm-jit/src/bpf_jit.cpp index a67afac2..a30cff26 100644 --- a/vm/llvm-jit/src/bpf_jit.cpp +++ b/vm/llvm-jit/src/bpf_jit.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "ebpf_inst.h" #include "llvm_bpf_jit.h" #include "llvm_jit_context.h" diff --git a/vm/llvm-jit/src/bpf_jit_compile_module.cpp b/vm/llvm-jit/src/bpf_jit_compile_module.cpp index 476c0953..f95c1110 100644 --- a/vm/llvm-jit/src/bpf_jit_compile_module.cpp +++ b/vm/llvm-jit/src/bpf_jit_compile_module.cpp @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #include "llvm_bpf_jit.h" #include "llvm_jit_context.h" #include "ebpf_inst.h" diff --git a/vm/llvm-jit/src/bpf_jit_helpers.h b/vm/llvm-jit/src/bpf_jit_helpers.h index 57d1b58a..a58f5031 100644 --- a/vm/llvm-jit/src/bpf_jit_helpers.h +++ b/vm/llvm-jit/src/bpf_jit_helpers.h @@ -1,3 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (c) 2022, eunomia-bpf org + * All rights reserved. + */ #ifndef _BPF_JIT_HELPER #define _BPF_JIT_HELPER