From 0c2903e839596de0ecf0e47be319040b72155dac Mon Sep 17 00:00:00 2001 From: yunwei37 <1067852565@qq.com> Date: Wed, 15 Feb 2023 16:14:11 +0800 Subject: [PATCH] fix export bpf api --- include/bpf-api.h | 3 ++- src/main.cpp | 2 +- src/wasm-bpf.cpp | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/bpf-api.h b/include/bpf-api.h index 3bffa31..f4f53a0 100644 --- a/include/bpf-api.h +++ b/include/bpf-api.h @@ -27,6 +27,7 @@ void bpf_buffer__free(struct bpf_buffer *); void bpf_object__close(struct bpf_object *object); int bpf_link__destroy(bpf_link *link); } + /// @brief init libbpf callbacks void init_libbpf(void); struct wasm_bpf_program { @@ -60,6 +61,6 @@ enum bpf_map_cmd { int bpf_map_operate(int fd, int cmd, void *key, void *value, void *next_key, uint64_t flags); /// The main entry, argc and argv will be passed to the wasm module. -int wasm_main(std::vector wasm_module, int argc, char *argv[]); +int wasm_main(unsigned char *buf, unsigned int size, int argc, char *argv[]); #endif diff --git a/src/main.cpp b/src/main.cpp index e8ada6a..0a737f7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,5 +16,5 @@ int main(int argc, char *argv[]) { std::ifstream file(argv[1]); std::vector wasm_module((std::istreambuf_iterator(file)), std::istreambuf_iterator()); - return wasm_main(wasm_module, argc - 1, argv + 1); + return wasm_main(wasm_module.data(), wasm_module.size(), argc - 1, argv + 1); } diff --git a/src/wasm-bpf.cpp b/src/wasm-bpf.cpp index 5c60430..5b20ef9 100644 --- a/src/wasm-bpf.cpp +++ b/src/wasm-bpf.cpp @@ -269,7 +269,7 @@ int wasm_bpf_map_operate(wasm_exec_env_t exec_env, int fd, int cmd, void *key, } } -int wasm_main(std::vector wasm_module, int argc, char *argv[]) { +int wasm_main(unsigned char *buf, unsigned int size, int argc, char *argv[]) { char error_buf[128]; int exit_code = 0; char *wasm_path = NULL; @@ -301,7 +301,7 @@ int wasm_main(std::vector wasm_module, int argc, char *argv[]) { printf("Init runtime environment failed.\n"); return -1; } - module = wasm_runtime_load(wasm_module.data(), (uint32_t)wasm_module.size(), + module = wasm_runtime_load(buf, size, error_buf, sizeof(error_buf)); if (!module) { printf("Load wasm module failed. error: %s\n", error_buf);