|
@@ -108,9 +108,9 @@ static inline sub_object *table_fetch_object(zend_object *obj) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void EbpfExtension::_trace_autoload() {
|
|
void EbpfExtension::_trace_autoload() {
|
|
|
- size_t num_funcs = bpf.get_num_functions();
|
|
|
|
|
|
|
+ size_t num_funcs = bpf_num_functions(mod);
|
|
|
for (size_t i = 0; i < num_funcs; i++) {
|
|
for (size_t i = 0; i < num_funcs; i++) {
|
|
|
- const char *func_name = bpf.get_function_name(i);
|
|
|
|
|
|
|
+ const char *func_name = bpf_function_name(mod, i);
|
|
|
std::string fn_name(func_name);
|
|
std::string fn_name(func_name);
|
|
|
if (fn_name.rfind("kprobe__", 0) == 0) {
|
|
if (fn_name.rfind("kprobe__", 0) == 0) {
|
|
|
std::string kernel_func = fix_syscall_fnname(fn_name.substr(8));
|
|
std::string kernel_func = fix_syscall_fnname(fn_name.substr(8));
|
|
@@ -374,6 +374,7 @@ zval EbpfExtension::get_table_cls(const char *table_name, int from_attr) {
|
|
|
Z_ADDREF(retval);
|
|
Z_ADDREF(retval);
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
+#ifdef BPF_MAP_TYPE_RINGBUF
|
|
|
case BPF_MAP_TYPE_RINGBUF: {
|
|
case BPF_MAP_TYPE_RINGBUF: {
|
|
|
if (!ring_buf_table_ce) {
|
|
if (!ring_buf_table_ce) {
|
|
|
zend_throw_error(NULL, "RingBufTable class not found");
|
|
zend_throw_error(NULL, "RingBufTable class not found");
|
|
@@ -386,6 +387,7 @@ zval EbpfExtension::get_table_cls(const char *table_name, int from_attr) {
|
|
|
Z_ADDREF(retval);
|
|
Z_ADDREF(retval);
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
+#endif
|
|
|
default:
|
|
default:
|
|
|
if (from_attr) {
|
|
if (from_attr) {
|
|
|
ZVAL_LONG(&retval, ttype);
|
|
ZVAL_LONG(&retval, ttype);
|
|
@@ -495,6 +497,7 @@ std::unordered_set<std::string> EbpfExtension::get_kprobe_functions(const std::s
|
|
|
return fns;
|
|
return fns;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#ifdef BPF_PROG_TYPE_TRACING
|
|
|
ebpf::StatusTuple EbpfExtension::attach_kfunc(const std::string &kfn) {
|
|
ebpf::StatusTuple EbpfExtension::attach_kfunc(const std::string &kfn) {
|
|
|
int probe_fd;
|
|
int probe_fd;
|
|
|
auto fn = bpf.load_func(kfn, BPF_PROG_TYPE_TRACING, probe_fd);
|
|
auto fn = bpf.load_func(kfn, BPF_PROG_TYPE_TRACING, probe_fd);
|
|
@@ -503,11 +506,20 @@ ebpf::StatusTuple EbpfExtension::attach_kfunc(const std::string &kfn) {
|
|
|
if (res_fd < 0) {
|
|
if (res_fd < 0) {
|
|
|
TRY2(bpf.unload_func(kfn));
|
|
TRY2(bpf.unload_func(kfn));
|
|
|
return ebpf::StatusTuple(-1, "Unable to attach kfunc using %s",
|
|
return ebpf::StatusTuple(-1, "Unable to attach kfunc using %s",
|
|
|
- kfn.c_str());
|
|
|
|
|
|
|
+ kfn.c_str());
|
|
|
}
|
|
}
|
|
|
return ebpf::StatusTuple::OK();
|
|
return ebpf::StatusTuple::OK();
|
|
|
}
|
|
}
|
|
|
|
|
+#else
|
|
|
|
|
|
|
|
|
|
+ebpf::StatusTuple EbpfExtension::attach_kfunc(const std::string &kfn) {
|
|
|
|
|
+ return ebpf::StatusTuple(-1,
|
|
|
|
|
+ "kfunc attachment requires BPF_PROG_TYPE_TRACING, which is not available on this kernel");
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+#ifdef BPF_PROG_TYPE_LSM
|
|
|
ebpf::StatusTuple EbpfExtension::attach_lsm(const std::string &lsm) {
|
|
ebpf::StatusTuple EbpfExtension::attach_lsm(const std::string &lsm) {
|
|
|
int probe_fd;
|
|
int probe_fd;
|
|
|
auto fn = bpf.load_func(lsm, BPF_PROG_TYPE_LSM, probe_fd);
|
|
auto fn = bpf.load_func(lsm, BPF_PROG_TYPE_LSM, probe_fd);
|
|
@@ -516,10 +528,17 @@ ebpf::StatusTuple EbpfExtension::attach_lsm(const std::string &lsm) {
|
|
|
if (res_fd < 0) {
|
|
if (res_fd < 0) {
|
|
|
TRY2(bpf.unload_func(lsm));
|
|
TRY2(bpf.unload_func(lsm));
|
|
|
return ebpf::StatusTuple(-1, "Unable to attach lsm using %s",
|
|
return ebpf::StatusTuple(-1, "Unable to attach lsm using %s",
|
|
|
- lsm.c_str());
|
|
|
|
|
|
|
+ lsm.c_str());
|
|
|
}
|
|
}
|
|
|
return ebpf::StatusTuple::OK();
|
|
return ebpf::StatusTuple::OK();
|
|
|
}
|
|
}
|
|
|
|
|
+#else
|
|
|
|
|
+
|
|
|
|
|
+ebpf::StatusTuple EbpfExtension::attach_lsm(const std::string &lsm) {
|
|
|
|
|
+ return ebpf::StatusTuple(-1, "BPF_PROG_TYPE_LSM is not supported by this kernel.");
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
zend_object *bpf_create_object(zend_class_entry *ce) {
|
|
zend_object *bpf_create_object(zend_class_entry *ce) {
|
|
@@ -592,7 +611,7 @@ PHP_METHOD (Bpf, __construct) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
auto res = obj->ebpf_cpp_cls->init(source);
|
|
auto res = obj->ebpf_cpp_cls->init(source);
|
|
|
- if (!res.ok()) {
|
|
|
|
|
|
|
+ if (res.code() != 0) {
|
|
|
zend_throw_error(NULL, "BPF init failed: %s", res.msg().c_str());
|
|
zend_throw_error(NULL, "BPF init failed: %s", res.msg().c_str());
|
|
|
RETURN_FALSE;
|
|
RETURN_FALSE;
|
|
|
}
|
|
}
|
|
@@ -664,7 +683,7 @@ PHP_METHOD (Bpf, attach_kprobe) {
|
|
|
std::string(probe_func, probe_func_len)
|
|
std::string(probe_func, probe_func_len)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- if (!attach_res.ok()) {
|
|
|
|
|
|
|
+ if (attach_res.code() != 0) {
|
|
|
zend_throw_error(NULL, "attach error: %s", attach_res.msg().c_str());
|
|
zend_throw_error(NULL, "attach error: %s", attach_res.msg().c_str());
|
|
|
RETURN_NULL();
|
|
RETURN_NULL();
|
|
|
}
|
|
}
|
|
@@ -692,7 +711,7 @@ PHP_METHOD (Bpf, attach_tracepoint) {
|
|
|
std::string(probe_func, probe_func_len)
|
|
std::string(probe_func, probe_func_len)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- if (!attach_res.ok()) {
|
|
|
|
|
|
|
+ if (attach_res.code() != 0) {
|
|
|
zend_throw_error(NULL, "attach error: %s", attach_res.msg().c_str());
|
|
zend_throw_error(NULL, "attach error: %s", attach_res.msg().c_str());
|
|
|
RETURN_NULL();
|
|
RETURN_NULL();
|
|
|
}
|
|
}
|
|
@@ -744,7 +763,7 @@ PHP_METHOD (Bpf, attach_kfunc) {
|
|
|
|
|
|
|
|
auto attach_res = obj->ebpf_cpp_cls->attach_kfunc(std::string(kfunc, kfunc_len));
|
|
auto attach_res = obj->ebpf_cpp_cls->attach_kfunc(std::string(kfunc, kfunc_len));
|
|
|
|
|
|
|
|
- if (!attach_res.ok()) {
|
|
|
|
|
|
|
+ if (attach_res.code() != 0) {
|
|
|
zend_throw_error(NULL, "attach error: %s", attach_res.msg().c_str());
|
|
zend_throw_error(NULL, "attach error: %s", attach_res.msg().c_str());
|
|
|
RETURN_NULL();
|
|
RETURN_NULL();
|
|
|
}
|
|
}
|
|
@@ -768,7 +787,7 @@ PHP_METHOD (Bpf, attach_lsm) {
|
|
|
|
|
|
|
|
auto attach_res = obj->ebpf_cpp_cls->attach_lsm(std::string(lsm, lsm_len));
|
|
auto attach_res = obj->ebpf_cpp_cls->attach_lsm(std::string(lsm, lsm_len));
|
|
|
|
|
|
|
|
- if (!attach_res.ok()) {
|
|
|
|
|
|
|
+ if (attach_res.code() != 0) {
|
|
|
zend_throw_error(NULL, "attach error: %s", attach_res.msg().c_str());
|
|
zend_throw_error(NULL, "attach error: %s", attach_res.msg().c_str());
|
|
|
RETURN_NULL();
|
|
RETURN_NULL();
|
|
|
}
|
|
}
|
|
@@ -856,7 +875,7 @@ PHP_METHOD (Bpf, detach_kprobe) {
|
|
|
|
|
|
|
|
auto detach_res = obj->ebpf_cpp_cls->bpf.detach_kprobe(std::string(fn, fn_len));
|
|
auto detach_res = obj->ebpf_cpp_cls->bpf.detach_kprobe(std::string(fn, fn_len));
|
|
|
|
|
|
|
|
- if (!detach_res.ok()) {
|
|
|
|
|
|
|
+ if (detach_res.code() != 0) {
|
|
|
zend_throw_error(NULL, "detach_kprobe error: %s", detach_res.msg().c_str());
|
|
zend_throw_error(NULL, "detach_kprobe error: %s", detach_res.msg().c_str());
|
|
|
RETURN_NULL();
|
|
RETURN_NULL();
|
|
|
}
|
|
}
|
|
@@ -913,7 +932,7 @@ PHP_METHOD (Bpf, detach_uprobe) {
|
|
|
symbol_offset
|
|
symbol_offset
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- if (!detach_res.ok()) {
|
|
|
|
|
|
|
+ if (detach_res.code() != 0) {
|
|
|
zend_throw_error(NULL, "detach_uprobe error: %s", detach_res.msg().c_str());
|
|
zend_throw_error(NULL, "detach_uprobe error: %s", detach_res.msg().c_str());
|
|
|
RETURN_NULL();
|
|
RETURN_NULL();
|
|
|
}
|
|
}
|
|
@@ -1116,7 +1135,7 @@ PHP_METHOD (Bpf, load_func) {
|
|
|
probe_fd
|
|
probe_fd
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- if (!res.ok()) {
|
|
|
|
|
|
|
+ if (res.code() != 0) {
|
|
|
zend_throw_error(NULL, "Failed to load function: %s", res.msg().c_str());
|
|
zend_throw_error(NULL, "Failed to load function: %s", res.msg().c_str());
|
|
|
RETURN_NULL();
|
|
RETURN_NULL();
|
|
|
}
|
|
}
|
|
@@ -1209,7 +1228,7 @@ PHP_METHOD (PerfEventArrayTable, open_perf_buffer) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
auto res = obj->bpf->open_perf_buffer(name, callbackfn);
|
|
auto res = obj->bpf->open_perf_buffer(name, callbackfn);
|
|
|
- if (!res.ok()) {
|
|
|
|
|
|
|
+ if (res.code() != 0) {
|
|
|
zend_throw_error(NULL, "open_perf_buffer error: %s", res.msg().c_str());
|
|
zend_throw_error(NULL, "open_perf_buffer error: %s", res.msg().c_str());
|
|
|
RETURN_NULL();
|
|
RETURN_NULL();
|
|
|
}
|
|
}
|
|
@@ -1278,20 +1297,20 @@ PHP_METHOD (HashTable, clear) {
|
|
|
|
|
|
|
|
if (!name_zv || Z_TYPE_P(name_zv) != IS_STRING) {
|
|
if (!name_zv || Z_TYPE_P(name_zv) != IS_STRING) {
|
|
|
zend_throw_error(NULL, "Invalid or missing name property");
|
|
zend_throw_error(NULL, "Invalid or missing name property");
|
|
|
- RETURN_NULL();
|
|
|
|
|
|
|
+ RETURN_NULL()
|
|
|
}
|
|
}
|
|
|
sub_object *obj = table_fetch_object(Z_OBJ_P(getThis()));
|
|
sub_object *obj = table_fetch_object(Z_OBJ_P(getThis()));
|
|
|
if (!obj || !obj->bpf) {
|
|
if (!obj || !obj->bpf) {
|
|
|
zend_throw_error(NULL, "Invalid object state");
|
|
zend_throw_error(NULL, "Invalid object state");
|
|
|
- RETURN_NULL();
|
|
|
|
|
|
|
+ RETURN_NULL()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
auto table = obj->bpf->get_table(Z_STRVAL_P(name_zv));
|
|
auto table = obj->bpf->get_table(Z_STRVAL_P(name_zv));
|
|
|
auto res = table.clear_table_non_atomic();
|
|
auto res = table.clear_table_non_atomic();
|
|
|
|
|
|
|
|
- if (!res.ok()) {
|
|
|
|
|
|
|
+ if (res.code() != 0) {
|
|
|
zend_throw_error(NULL, "Failed to clear table: %s", res.msg().c_str());
|
|
zend_throw_error(NULL, "Failed to clear table: %s", res.msg().c_str());
|
|
|
- RETURN_NULL();
|
|
|
|
|
|
|
+ RETURN_NULL()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
RETURN_TRUE;
|
|
@@ -1330,7 +1349,7 @@ PHP_METHOD (ArrayTable, get_value) {
|
|
|
auto table = obj->bpf->get_array_table<uint64_t>(Z_STRVAL_P(name_zv));
|
|
auto table = obj->bpf->get_array_table<uint64_t>(Z_STRVAL_P(name_zv));
|
|
|
uint64_t val;
|
|
uint64_t val;
|
|
|
auto res = table.get_value(index, val);
|
|
auto res = table.get_value(index, val);
|
|
|
- if (!res.ok()) {
|
|
|
|
|
|
|
+ if (res.code() != 0) {
|
|
|
zend_throw_error(NULL, "Get value error in %s", Z_STRVAL_P(name_zv));
|
|
zend_throw_error(NULL, "Get value error in %s", Z_STRVAL_P(name_zv));
|
|
|
RETURN_NULL();
|
|
RETURN_NULL();
|
|
|
}
|
|
}
|
|
@@ -1540,7 +1559,7 @@ PHP_METHOD (PerCpuArrayTable, sum_value) {
|
|
|
try {
|
|
try {
|
|
|
auto table = obj->bpf->get_percpu_array_table<uint64_t>(Z_STRVAL_P(name_zv));
|
|
auto table = obj->bpf->get_percpu_array_table<uint64_t>(Z_STRVAL_P(name_zv));
|
|
|
auto res = table.get_value(index, val);
|
|
auto res = table.get_value(index, val);
|
|
|
- if (!res.ok()) {
|
|
|
|
|
|
|
+ if (res.code() != 0) {
|
|
|
zend_throw_error(NULL, "Get value error in %s", Z_STRVAL_P(name_zv));
|
|
zend_throw_error(NULL, "Get value error in %s", Z_STRVAL_P(name_zv));
|
|
|
RETURN_NULL();
|
|
RETURN_NULL();
|
|
|
}
|
|
}
|