Skip to content

Commit

Permalink
refactor: remove ABI encoding from inspect state
Browse files Browse the repository at this point in the history
also change cmt_io_get_rx to limit end of buffer to what was reported
in fromhost after yield
  • Loading branch information
diegonehab committed Mar 19, 2024
1 parent d4f6f73 commit 4072ee0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
2 changes: 2 additions & 0 deletions sys-utils/libcmt/include/libcmt/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ enum {
typedef struct {
cmt_buf_t tx[1];
cmt_buf_t rx[1];
uint32_t rx_max_length;
uint32_t rx_fromhost_length;
int fd;
} cmt_io_driver_ioctl_t;

Expand Down
18 changes: 15 additions & 3 deletions sys-utils/libcmt/src/ioctl/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ int cmt_io_init(cmt_io_driver_t *_me) {
goto do_unmap;
}

me->rx_max_length = setup.rx.length;
me->rx_fromhost_length = 0;

cmt_buf_init(me->tx, setup.tx.length, tx);
cmt_buf_init(me->rx, setup.rx.length, rx);
return 0;
Expand All @@ -69,17 +72,23 @@ void cmt_io_fini(cmt_io_driver_t *_me) {
}

cmt_buf_t cmt_io_get_tx(cmt_io_driver_t *me) {
cmt_buf_t empty = {NULL, NULL};
static const cmt_buf_t empty = {NULL, NULL};
if (!me)
return empty;
return *me->ioctl.tx;
}

static uint32_t min(uint32_t a, uint32_t b) {
return a < b? a: b;
}

cmt_buf_t cmt_io_get_rx(cmt_io_driver_t *me) {
cmt_buf_t empty = {NULL, NULL};
static const cmt_buf_t empty = {NULL, NULL};
if (!me)
return empty;
return *me->ioctl.rx;
cmt_buf_t rx = *me->ioctl.rx;
rx.end = rx.begin + min(me->ioctl.rx_max_length, me->ioctl.rx_fromhost_length);
return rx;
}

static uint64_t pack(struct cmt_io_yield *rr) {
Expand Down Expand Up @@ -125,6 +134,9 @@ int cmt_io_yield(cmt_io_driver_t *_me, struct cmt_io_yield *rr) {
if (ioctl(me->fd, IOCTL_CMIO_YIELD, &req))
return -errno;
*rr = unpack(req);

me->rx_fromhost_length = rr->data;

if (enabled) {
fprintf(stderr,
"fromhost {\n"
Expand Down
13 changes: 3 additions & 10 deletions sys-utils/libcmt/src/rollup.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,9 @@ int cmt_rollup_read_inspect_state(cmt_rollup_t *me, cmt_rollup_inspect_t *inspec
return -EINVAL;
if (!inspect)
return -EINVAL;

cmt_buf_t rd[1] = {cmt_io_get_rx(me->io)};
cmt_buf_t st[1] = {{rd->begin + 4, rd->end}}; // EVM offsets are from after funsel
cmt_buf_t of[1];

size_t length = 0;
if (DBG(cmt_abi_check_funsel(rd, EVM_INSPECT)) || DBG(cmt_abi_get_bytes_s(rd, of)) ||
DBG(cmt_abi_get_bytes_d(st, of, &length, &inspect->data)))
return -ENOBUFS;
inspect->length = length;
cmt_buf_t rx[1] = {cmt_io_get_rx(me->io)};
inspect->length = cmt_buf_length(rx);
inspect->data = rx->begin;
return 0;
}

Expand Down

0 comments on commit 4072ee0

Please sign in to comment.