diff --git a/usr.sbin/bhyve/basl.h b/usr.sbin/bhyve/basl.h --- a/usr.sbin/bhyve/basl.h +++ b/usr.sbin/bhyve/basl.h @@ -32,5 +32,6 @@ int basl_init(void); int basl_table_append_bytes(struct basl_table *table, const void *bytes, uint32_t len); +int basl_table_append_int(struct basl_table *table, uint64_t val, uint8_t size); int basl_table_create(struct basl_table **table, struct vmctx *ctx, const uint8_t *name, uint32_t alignment, uint32_t off); diff --git a/usr.sbin/bhyve/basl.c b/usr.sbin/bhyve/basl.c --- a/usr.sbin/bhyve/basl.c +++ b/usr.sbin/bhyve/basl.c @@ -33,6 +33,17 @@ static STAILQ_HEAD(basl_table_list, basl_table) basl_tables = STAILQ_HEAD_INITIALIZER( basl_tables); +static __inline void +basl_le_enc(void *pp, uint64_t val, size_t len) +{ + char buf[8]; + + assert(len <= 8); + + le64enc(buf, val); + memcpy(pp, buf, len); +} + static int basl_dump_table(const struct basl_table *const table, const bool mem) { @@ -145,6 +156,18 @@ return (0); } +int +basl_table_append_int(struct basl_table *const table, const uint64_t val, + const uint8_t size) +{ + char buf[8]; + + assert(size <= sizeof(val)); + + basl_le_enc(buf, val, size); + return (basl_table_append_bytes(table, buf, size)); +} + int basl_table_create(struct basl_table **const table, struct vmctx *ctx, const uint8_t *const name, const uint32_t alignment,