-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunc-bpf-buffer-poll.cpp
More file actions
50 lines (45 loc) · 1.86 KB
/
Copy pathfunc-bpf-buffer-poll.cpp
File metadata and controls
50 lines (45 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2019-2024 Second State INC
#include "func-bpf-buffer-poll.h"
#include "wasmedge/wasmedge.h"
#include <shared_mutex>
namespace WasmEdge {
namespace Host {
// Helper functions of context conversions.
inline const auto *toCallFrameCxt(const Runtime::CallingFrame *Cxt) noexcept {
return reinterpret_cast<const WasmEdge_CallingFrameContext *>(Cxt);
}
Expect<int32_t> BpfBufferPoll::body(const Runtime::CallingFrame &Frame,
handle_t program, int32_t fd,
int32_t sample_func, uint32_t ctx,
uint32_t data, uint32_t max_size,
int32_t timeout_ms) {
auto c_ctx = toCallFrameCxt(&Frame);
auto c_module = WasmEdge_CallingFrameGetModuleInstance(c_ctx);
auto c_executor = WasmEdge_CallingFrameGetExecutor(c_ctx);
if (unlikely(!c_ctx || !c_module || !c_executor)) {
return Unexpect(ErrCode::Value::HostFuncError);
}
auto *memory = Frame.getMemoryByIndex(0);
if (unlikely(!memory)) {
return Unexpect(ErrCode::Value::HostFuncError);
}
auto module_instance = Frame.getModule();
if (unlikely(!module_instance)) {
return Unexpect(ErrCode::Value::HostFuncError);
}
std::shared_lock lock(state->lock);
auto program_ptr = state->handles.find(program);
if (program_ptr == state->handles.end()) {
return Unexpect(ErrCode::Value::HostFuncError);
}
auto data_buf = memory->getSpan<char>(data, max_size);
if (data_buf.size() != max_size) {
return Unexpect(ErrCode::Value::HostFuncError);
}
return program_ptr->second->bpf_buffer_poll(c_executor, c_module, fd,
sample_func, ctx, data_buf.data(),
max_size, timeout_ms, data);
}
} // namespace Host
} // namespace WasmEdge