diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 4146f174..529aa2e6 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -237,10 +237,7 @@ message(DEBUG "Successfully added all dependencies and linked against them.") set(BPFTIME_RUNTIME_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/src) -if(UNIX AND NOT APPLE) add_subdirectory(object) -endif() - add_subdirectory(agent) add_subdirectory(syscall-server) # diff --git a/runtime/include/bpftime_epoll.h b/runtime/include/bpftime_epoll.h index 3989576e..e25fde6c 100644 --- a/runtime/include/bpftime_epoll.h +++ b/runtime/include/bpftime_epoll.h @@ -23,6 +23,12 @@ #define __NR_bpf 515 // This is a placeholder value. Linux assigns syscall numbers dynamically. #endif +#if __GNUC__ >= 4 +#define LIBBPF_API __attribute__((visibility("default"))) +#else +#define LIBBPF_API +#endif + #ifndef __NR_perf_event_open #define __NR_perf_event_open 516 // This is a placeholder value. Linux assigns syscall numbers dynamically. #endif @@ -770,6 +776,7 @@ struct perf_event_attr { __u64 config3; /* extension of config2 */ }; + namespace bpftime_epoll{ struct bpf_map_info { __u32 type; @@ -1241,6 +1248,35 @@ static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr, // No-op stub return 0; } + +// from libbpf/btf +void btf__free(struct btf *btf); +// from libbpf +void +bpf_object__close(struct bpf_object* object); + +LIBBPF_API struct bpf_program * +bpf_object__next_program(const struct bpf_object *obj, struct bpf_program *prog); + +#define bpf_object__for_each_program(pos, obj) \ + for ((pos) = bpf_object__next_program((obj), NULL); \ + (pos) != NULL; \ + (pos) = bpf_object__next_program((obj), (pos))) + +struct bpf_program; + +LIBBPF_API const struct bpf_insn *bpf_program__insns(const struct bpf_program *prog); +LIBBPF_API size_t bpf_program__insn_cnt(const struct bpf_program *prog); +LIBBPF_API const char *bpf_program__name(const struct bpf_program *prog); +LIBBPF_API const char *bpf_program__section_name(const struct bpf_program *prog); +LIBBPF_API struct bpf_object *bpf_object__open(const char *path); + +enum libbpf_print_level { + LIBBPF_WARN, + LIBBPF_INFO, + LIBBPF_DEBUG, +}; + // https://github.com/torvalds/linux/blob/2ef5971ff345d3c000873725db555085e0131961/tools/lib/bpf/bpf.h#L503 inline int bpf_obj_get_info_by_fd(int bpf_fd, void *info, __u32 *info_len) { diff --git a/runtime/object/bpf_object.cpp b/runtime/object/bpf_object.cpp index 6de463a3..7357fa6f 100644 --- a/runtime/object/bpf_object.cpp +++ b/runtime/object/bpf_object.cpp @@ -1,5 +1,7 @@ #if __linux__ #include +#elif __APPLE__ +#include "bpftime_epoll.h" #endif #include #include @@ -9,6 +11,9 @@ #include using namespace std; using namespace bpftime; +#if __APPLE__ +using namespace bpftime_epoll; +#endif #ifdef USE_LIBBPF extern "C" {