Skip to content

Commit

Permalink
runtime: fix compile error and docker image error (eunomia-bpf#46)
Browse files Browse the repository at this point in the history
* runtime: fix compile errors

* deps: updat libbpf version and fix compile

---------

Co-authored-by: Littlefisher619 <i@littlefisher.me>
  • Loading branch information
yunwei37 and Littlefisher619 committed Oct 19, 2023
1 parent 549c4da commit b7c223f
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ build: ## build the package
cd tools/cli-rs && cargo build

release: ## build the package
cmake -Bbuild -DBPFTIME_ENABLE_UNIT_TESTING=0 -DCMAKE_BUILD_TYPE:STRING=Release && cmake --build build --config Release -j --target install
cmake -Bbuild -DBPFTIME_ENABLE_UNIT_TESTING=0 -DCMAKE_BUILD_TYPE:STRING=Release && cmake --build build --config Release --target install

build-vm: ## build only the core library
make -C vm build
Expand Down
7 changes: 1 addition & 6 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
add_executable(simple-benchmark-with-embed-ebpf-calling test_embed.c)

add_ebpf_program_target(uprobe_prog ${CMAKE_CURRENT_SOURCE_DIR}/uprobe/uprobe.bpf.c ${CMAKE_CURRENT_BINARY_DIR}/uprobe_prog.bpf.o)
add_ebpf_program_target(uretprobe_prog ${CMAKE_CURRENT_SOURCE_DIR}/uretprobe/uretprobe.bpf.c ${CMAKE_CURRENT_BINARY_DIR}/uretprobe_prog.bpf.o)

add_dependencies(simple-benchmark-with-embed-ebpf-calling vm-bpf uprobe_prog uretprobe_prog libbpf)
add_dependencies(simple-benchmark-with-embed-ebpf-calling vm-bpf libbpf)
target_compile_definitions(simple-benchmark-with-embed-ebpf-calling
PRIVATE
UPROBE_PROG=${CMAKE_CURRENT_BINARY_DIR}/uprobe_prog.bpf.o
URETPROBE_PROG=${CMAKE_CURRENT_BINARY_DIR}/uretprobe_prog.bpf.o
)
target_link_libraries(simple-benchmark-with-embed-ebpf-calling vm-bpf ${LIBBPF_LIBRARIES} elf z)
target_include_directories(simple-benchmark-with-embed-ebpf-calling
Expand Down
12 changes: 8 additions & 4 deletions benchmark/test_embed.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ struct pt_regs {

struct ebpf_vm *begin_vm = NULL;
struct ebpf_vm *end_vm = NULL;
// ebpf_jit_fn begin_fn = NULL, end_fn = NULL;
const char *uprobe_prog = TOSTRING(UPROBE_PROG);
const char *uretprobe_prog = TOSTRING(URETPROBE_PROG);

bool enable_ebpf = false;

// The timespec struct holds seconds and nanoseconds
Expand Down Expand Up @@ -172,8 +170,14 @@ struct ebpf_vm *create_vm_from_elf(const char *elf_file,
return vm;
}

int main()
int main(int argc, char **argv)
{
if (argc < 3) {
printf("Usage: %s <uprobe elf> <uretprobe elf>\n", argv[0]);
return 0;
}
const char *uprobe_prog = argv[1];
const char *uretprobe_prog = argv[2];
printf("uprobe elf: %s\nuretprobe elf:%s\n", uprobe_prog,
uretprobe_prog);
enable_ebpf = true;
Expand Down
1 change: 0 additions & 1 deletion cmake/libbpf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ function(add_ebpf_program_target target_name source_file output_file)
| sed 's/riscv64/riscv/' \
| sed 's/loongarch64/loongarch/'"
OUTPUT_VARIABLE UNAME_ARCH
COMMAND_ERROR_IS_FATAL ANY
)
string(STRIP ${UNAME_ARCH} UNAME_ARCH_STRIPPED)
add_custom_command(
Expand Down
2 changes: 1 addition & 1 deletion documents/build-and-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Install the required packages:
```bash
sudo apt install -y --no-install-recommends \
libelf1 libelf-dev zlib1g-dev make git libboost1.74-all-dev \
binutils-dev libyaml-cpp-dev
binutils-dev libyaml-cpp-dev llvm
git submodule update --init --recursive
```
---
Expand Down
2 changes: 2 additions & 0 deletions runtime/src/attach/attach_manager/frida_attach_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <memory>
#include <stdexcept>
#include <utility>
#include <unistd.h>

GType uprobe_listener_get_type();

static std::string get_executable_path()
Expand Down
4 changes: 1 addition & 3 deletions runtime/src/attach/bpf_attach_ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,8 @@ int bpf_attach_ctx::create_tracepoint(int tracepoint_id, int perf_fd,
const auto &[id_table, _] = get_global_syscall_id_table();
if (auto itr = tp_table.find(tracepoint_id); itr != tp_table.end()) {
spdlog::info("Creating tracepoint for tp name {}", itr->second);
// I'm lazy. So I just lookup the corresponding bpf progs by
// Lookup the corresponding bpf progs by
// brute force

#warning Inefficient algorithm here. Remeber to rewrite it in the future
std::vector<const bpftime_prog *> progs;

for (std::size_t i = 0; i < manager->size(); i++) {
Expand Down
8 changes: 7 additions & 1 deletion runtime/src/bpf_map/ringbuf_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
#include <boost/interprocess/sync/interprocess_sharable_mutex.hpp>
#include <boost/interprocess/sync/sharable_lock.hpp>
#include <bpf_map/ringbuf_map.hpp>
#include <linux/bpf.h>
#include <spdlog/spdlog.h>

enum {
BPF_RINGBUF_BUSY_BIT = 2147483648,
BPF_RINGBUF_DISCARD_BIT = 1073741824,
BPF_RINGBUF_HDR_SZ = 8,
};

#define READ_ONCE_UL(x) (*(volatile unsigned long *)&x)
#define WRITE_ONCE_UL(x, v) (*(volatile unsigned long *)&x) = (v)
#define READ_ONCE_I(x) (*(volatile int *)&x)
Expand Down

0 comments on commit b7c223f

Please sign in to comment.