Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/qemu_fwcfg.c
Show First 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | qemu_fwcfg_data_port_handler(struct vmctx *const ctx __unused, const int in, | ||||
/* return item data */ | /* return item data */ | ||||
*eax = item->data[fwcfg_sc.data_offset]; | *eax = item->data[fwcfg_sc.data_offset]; | ||||
fwcfg_sc.data_offset++; | fwcfg_sc.data_offset++; | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
qemu_fwcfg_add_item(const uint16_t architecture, const uint16_t index, | |||||
const uint32_t size, void *const data) | |||||
{ | |||||
/* truncate architecture and index to their desired size */ | |||||
const uint16_t arch = architecture & QEMU_FWCFG_ARCHITECTURE_MASK; | |||||
const uint16_t idx = index & QEMU_FWCFG_INDEX_MASK; | |||||
/* get pointer to item specified by selector */ | |||||
struct qemu_fwcfg_item *const fwcfg_item = &fwcfg_sc.items[arch][idx]; | |||||
markj: Should we validate the indices, if only with `assert()`? | |||||
Not Done Inline ActionsI'm not sure about this. items is defined as struct qemu_fwcfg_item items[QEMU_FWCFG_MAX_ARCHS][QEMU_FWCFG_MAX_ENTRIES];. The value of idx is masked. So, it's impossible for idx to be too large. corvink: I'm not sure about this. `items` is defined as `struct qemu_fwcfg_item items… | |||||
/* check if item is already used */ | |||||
if (fwcfg_item->data != NULL) { | |||||
warnx("%s: qemu fwcfg item exists (architecture %s index 0x%x)", | |||||
__func__, arch ? "specific" : "generic", idx); | |||||
return (-1); | |||||
} | |||||
/* save data of the item */ | |||||
fwcfg_item->size = size; | |||||
fwcfg_item->data = data; | |||||
return (0); | |||||
} | |||||
static int | |||||
qemu_fwcfg_register_port(const char *const name, const int port, const int size, | qemu_fwcfg_register_port(const char *const name, const int port, const int size, | ||||
const int flags, const inout_func_t handler) | const int flags, const inout_func_t handler) | ||||
{ | { | ||||
struct inout_port iop; | struct inout_port iop; | ||||
bzero(&iop, sizeof(iop)); | bzero(&iop, sizeof(iop)); | ||||
iop.name = name; | iop.name = name; | ||||
iop.port = port; | iop.port = port; | ||||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |
Should we validate the indices, if only with assert()?