Class: LibBPFRuby::Object
- Inherits:
-
Object
- Object
- LibBPFRuby::Object
- Defined in:
- ext/libbpf_ruby/libbpf_ruby.c
Instance Method Summary collapse
- #close ⇒ Object
- #initialize(path) ⇒ Object constructor
- #map_fd(name) ⇒ Object
- #program(name) ⇒ Object
- #program_fd(name) ⇒ Object
Constructor Details
#initialize(path) ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'ext/libbpf_ruby/libbpf_ruby.c', line 260
static VALUE rb_cObject_initialize(VALUE self, VALUE path) {
libbpf_ruby_object_t *libbpf_ruby_object;
TypedData_Get_Struct(self, libbpf_ruby_object_t, &libbpf_ruby_object_type, libbpf_ruby_object);
StringValueCStr(path);
VALUE frozen_path = rb_str_new_frozen(path);
nogvl_open_ctx_t open_ctx = { .path = RSTRING_PTR(frozen_path) };
rb_nogvl(nogvl_bpf_object__open_file, &open_ctx, NULL, NULL, 0);
long err = libbpf_get_error(open_ctx.bpf_object);
if (err) {
rb_raise(rb_eRuntimeError, "bpf_object__open_file failed: %s", strerror(-err));
}
nogvl_load_ctx_t load_ctx = { .bpf_object = open_ctx.bpf_object };
rb_nogvl(nogvl_bpf_object__load, &load_ctx, NULL, NULL, 0);
if (load_ctx.err) {
rb_nogvl(nogvl_bpf_object__close, open_ctx.bpf_object, NULL, NULL, 0);
rb_raise(rb_eRuntimeError, "bpf_object__load failed: %s", strerror(-load_ctx.err));
}
libbpf_ruby_object->bpf_object = open_ctx.bpf_object;
return self;
}
|
Instance Method Details
#close ⇒ Object
319 320 321 322 323 324 325 326 327 |
# File 'ext/libbpf_ruby/libbpf_ruby.c', line 319
static VALUE rb_cObject_close(VALUE self) {
libbpf_ruby_object_t *libbpf_ruby_object;
TypedData_Get_Struct(self, libbpf_ruby_object_t, &libbpf_ruby_object_type, libbpf_ruby_object);
if (libbpf_ruby_object->bpf_object) {
rb_nogvl(nogvl_bpf_object__close, libbpf_ruby_object->bpf_object, NULL, NULL, 0);
libbpf_ruby_object->bpf_object = NULL;
}
return Qnil;
}
|
#map_fd(name) ⇒ Object
307 308 309 310 311 312 313 314 315 316 317 |
# File 'ext/libbpf_ruby/libbpf_ruby.c', line 307
static VALUE rb_cObject_map_fd(VALUE self, VALUE name) {
libbpf_ruby_object_t *libbpf_ruby_object;
TypedData_Get_Struct(self, libbpf_ruby_object_t, &libbpf_ruby_object_type, libbpf_ruby_object);
const char *name_str = StringValueCStr(name);
int fd = bpf_object__find_map_fd_by_name(libbpf_ruby_object->bpf_object, name_str);
if (fd < 0) {
rb_raise(rb_eRuntimeError, "map %s not found", name_str);
}
return INT2NUM(fd);
}
|
#program(name) ⇒ Object
283 284 285 286 287 288 289 290 291 292 293 |
# File 'ext/libbpf_ruby/libbpf_ruby.c', line 283
static VALUE rb_cObject_program(VALUE self, VALUE name) {
libbpf_ruby_object_t *libbpf_ruby_object;
TypedData_Get_Struct(self, libbpf_ruby_object_t, &libbpf_ruby_object_type, libbpf_ruby_object);
const char *name_str = StringValueCStr(name);
struct bpf_program *program = bpf_object__find_program_by_name(libbpf_ruby_object->bpf_object, name_str);
if (!program) {
rb_raise(rb_eRuntimeError, "program %s not found", name_str);
}
return libbpf_ruby_program_wrap(self, program);
}
|
#program_fd(name) ⇒ Object
295 296 297 298 299 300 301 302 303 304 305 |
# File 'ext/libbpf_ruby/libbpf_ruby.c', line 295
static VALUE rb_cObject_program_fd(VALUE self, VALUE name) {
libbpf_ruby_object_t *libbpf_ruby_object;
TypedData_Get_Struct(self, libbpf_ruby_object_t, &libbpf_ruby_object_type, libbpf_ruby_object);
const char *name_str = StringValueCStr(name);
struct bpf_program *program = bpf_object__find_program_by_name(libbpf_ruby_object->bpf_object, name_str);
if (!program) {
rb_raise(rb_eRuntimeError, "program %s not found", name_str);
}
return INT2NUM(bpf_program__fd(program));
}
|