Skip to content

Commit b7c223f

Browse files
runtime: fix compile error and docker image error (#46)
* runtime: fix compile errors * deps: updat libbpf version and fix compile --------- Co-authored-by: Littlefisher619 <i@littlefisher.me>
1 parent 549c4da commit b7c223f

File tree

9 files changed

+22
-18
lines changed

9 files changed

+22
-18
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ build: ## build the package
4747
cd tools/cli-rs && cargo build
4848

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

5252
build-vm: ## build only the core library
5353
make -C vm build

benchmark/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
add_executable(simple-benchmark-with-embed-ebpf-calling test_embed.c)
22

3-
add_ebpf_program_target(uprobe_prog ${CMAKE_CURRENT_SOURCE_DIR}/uprobe/uprobe.bpf.c ${CMAKE_CURRENT_BINARY_DIR}/uprobe_prog.bpf.o)
4-
add_ebpf_program_target(uretprobe_prog ${CMAKE_CURRENT_SOURCE_DIR}/uretprobe/uretprobe.bpf.c ${CMAKE_CURRENT_BINARY_DIR}/uretprobe_prog.bpf.o)
5-
6-
add_dependencies(simple-benchmark-with-embed-ebpf-calling vm-bpf uprobe_prog uretprobe_prog libbpf)
3+
add_dependencies(simple-benchmark-with-embed-ebpf-calling vm-bpf libbpf)
74
target_compile_definitions(simple-benchmark-with-embed-ebpf-calling
85
PRIVATE
9-
UPROBE_PROG=${CMAKE_CURRENT_BINARY_DIR}/uprobe_prog.bpf.o
10-
URETPROBE_PROG=${CMAKE_CURRENT_BINARY_DIR}/uretprobe_prog.bpf.o
116
)
127
target_link_libraries(simple-benchmark-with-embed-ebpf-calling vm-bpf ${LIBBPF_LIBRARIES} elf z)
138
target_include_directories(simple-benchmark-with-embed-ebpf-calling

benchmark/test_embed.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ struct pt_regs {
4646

4747
struct ebpf_vm *begin_vm = NULL;
4848
struct ebpf_vm *end_vm = NULL;
49-
// ebpf_jit_fn begin_fn = NULL, end_fn = NULL;
50-
const char *uprobe_prog = TOSTRING(UPROBE_PROG);
51-
const char *uretprobe_prog = TOSTRING(URETPROBE_PROG);
49+
5250
bool enable_ebpf = false;
5351

5452
// The timespec struct holds seconds and nanoseconds
@@ -172,8 +170,14 @@ struct ebpf_vm *create_vm_from_elf(const char *elf_file,
172170
return vm;
173171
}
174172

175-
int main()
173+
int main(int argc, char **argv)
176174
{
175+
if (argc < 3) {
176+
printf("Usage: %s <uprobe elf> <uretprobe elf>\n", argv[0]);
177+
return 0;
178+
}
179+
const char *uprobe_prog = argv[1];
180+
const char *uretprobe_prog = argv[2];
177181
printf("uprobe elf: %s\nuretprobe elf:%s\n", uprobe_prog,
178182
uretprobe_prog);
179183
enable_ebpf = true;

cmake/libbpf.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ function(add_ebpf_program_target target_name source_file output_file)
101101
| sed 's/riscv64/riscv/' \
102102
| sed 's/loongarch64/loongarch/'"
103103
OUTPUT_VARIABLE UNAME_ARCH
104-
COMMAND_ERROR_IS_FATAL ANY
105104
)
106105
string(STRIP ${UNAME_ARCH} UNAME_ARCH_STRIPPED)
107106
add_custom_command(

documents/build-and-test.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Install the required packages:
77
```bash
88
sudo apt install -y --no-install-recommends \
99
libelf1 libelf-dev zlib1g-dev make git libboost1.74-all-dev \
10-
binutils-dev libyaml-cpp-dev
10+
binutils-dev libyaml-cpp-dev llvm
1111
git submodule update --init --recursive
1212
```
1313
---

runtime/src/attach/attach_manager/frida_attach_manager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <memory>
1010
#include <stdexcept>
1111
#include <utility>
12+
#include <unistd.h>
13+
1214
GType uprobe_listener_get_type();
1315

1416
static std::string get_executable_path()

runtime/src/attach/bpf_attach_ctx.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,8 @@ int bpf_attach_ctx::create_tracepoint(int tracepoint_id, int perf_fd,
396396
const auto &[id_table, _] = get_global_syscall_id_table();
397397
if (auto itr = tp_table.find(tracepoint_id); itr != tp_table.end()) {
398398
spdlog::info("Creating tracepoint for tp name {}", itr->second);
399-
// I'm lazy. So I just lookup the corresponding bpf progs by
399+
// Lookup the corresponding bpf progs by
400400
// brute force
401-
402-
#warning Inefficient algorithm here. Remeber to rewrite it in the future
403401
std::vector<const bpftime_prog *> progs;
404402

405403
for (std::size_t i = 0; i < manager->size(); i++) {

runtime/src/bpf_map/ringbuf_map.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
#include <boost/interprocess/sync/interprocess_sharable_mutex.hpp>
44
#include <boost/interprocess/sync/sharable_lock.hpp>
55
#include <bpf_map/ringbuf_map.hpp>
6-
#include <linux/bpf.h>
76
#include <spdlog/spdlog.h>
7+
8+
enum {
9+
BPF_RINGBUF_BUSY_BIT = 2147483648,
10+
BPF_RINGBUF_DISCARD_BIT = 1073741824,
11+
BPF_RINGBUF_HDR_SZ = 8,
12+
};
13+
814
#define READ_ONCE_UL(x) (*(volatile unsigned long *)&x)
915
#define WRITE_ONCE_UL(x, v) (*(volatile unsigned long *)&x) = (v)
1016
#define READ_ONCE_I(x) (*(volatile int *)&x)

0 commit comments

Comments
 (0)