2 * QEMU eBPF binary declaration routine.
4 * Developed by Daynix Computing LTD (http://www.daynix.com)
7 * Andrew Melnychenko <andrew@daynix.com>
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "qemu/osdep.h"
13 #include "qemu/queue.h"
14 #include "qapi/error.h"
15 #include "qapi/qapi-commands-ebpf.h"
16 #include "ebpf/ebpf.h"
18 typedef struct ElfBinaryDataEntry
{
23 QSLIST_ENTRY(ElfBinaryDataEntry
) node
;
26 static QSLIST_HEAD(, ElfBinaryDataEntry
) ebpf_elf_obj_list
=
27 QSLIST_HEAD_INITIALIZER();
29 void ebpf_register_binary_data(int id
, const void *data
, size_t datalen
)
31 struct ElfBinaryDataEntry
*dataentry
= NULL
;
33 dataentry
= g_new0(struct ElfBinaryDataEntry
, 1);
34 dataentry
->data
= data
;
35 dataentry
->datalen
= datalen
;
38 QSLIST_INSERT_HEAD(&ebpf_elf_obj_list
, dataentry
, node
);
41 const void *ebpf_find_binary_by_id(int id
, size_t *sz
, Error
**errp
)
43 struct ElfBinaryDataEntry
*it
= NULL
;
44 QSLIST_FOREACH(it
, &ebpf_elf_obj_list
, node
) {
51 error_setg(errp
, "can't find eBPF object with id: %d", id
);
56 EbpfObject
*qmp_request_ebpf(EbpfProgramID id
, Error
**errp
)
58 EbpfObject
*ret
= NULL
;
60 const void *data
= ebpf_find_binary_by_id(id
, &size
, errp
);
65 ret
= g_new0(EbpfObject
, 1);
66 ret
->object
= g_base64_encode(data
, size
);