From a0f5064ed0f3ee42a0b303e111bd89641a926676 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Mon, 10 Feb 2025 10:16:52 -0700 Subject: lib9p: Add comments clarifying why I split the `subctx`s the way I did --- lib9p/9p.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'lib9p/9p.c') diff --git a/lib9p/9p.c b/lib9p/9p.c index 51ff2eb..c54dae7 100644 --- a/lib9p/9p.c +++ b/lib9p/9p.c @@ -124,10 +124,12 @@ ssize_t _lib9p_validate(uint8_t xxx_low_typ_bit, struct lib9p_ctx *ctx, uint8_t *net_bytes) { /* Inspect the first 5 bytes ourselves. */ struct _validate_ctx subctx = { + /* input */ .ctx = ctx, .net_size = uint32le_decode(net_bytes), .net_bytes = net_bytes, + /* output */ .net_offset = 0, .host_extra = 0, }; @@ -171,17 +173,19 @@ static void _lib9p_unmarshal(const struct _lib9p_recv_tentry xxx_table[LIB9P_VER_NUM][0x80], struct lib9p_ctx *ctx, uint8_t *net_bytes, enum lib9p_msg_type *ret_typ, void *ret_body) { + enum lib9p_msg_type typ = net_bytes[4]; + *ret_typ = typ; + struct _lib9p_recv_tentry tentry = xxx_table[ctx->version][typ/2]; + struct _unmarshal_ctx subctx = { + /* input */ .ctx = ctx, .net_bytes = net_bytes, + /* output */ .net_offset = 0, + .extra = ret_body + tentry.basesize, }; - - enum lib9p_msg_type typ = net_bytes[4]; - *ret_typ = typ; - struct _lib9p_recv_tentry tentry = xxx_table[ctx->version][typ/2]; - subctx.extra = ret_body + tentry.basesize; tentry.unmarshal(&subctx, ret_body); } @@ -202,7 +206,10 @@ bool _lib9p_marshal(const struct _lib9p_send_tentry xxx_table[LIB9P_VER_NUM][0x8 struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body, uint8_t *ret_bytes) { struct _marshal_ctx subctx = { + /* input */ .ctx = ctx, + + /* ouptut */ .net_bytes = ret_bytes, .net_offset = 0, }; @@ -228,10 +235,12 @@ bool lib9p_Rmsg_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *bo bool lib9p_stat_validate(struct lib9p_ctx *ctx, uint32_t net_size, uint8_t *net_bytes, uint32_t *ret_net_size, ssize_t *ret_host_size) { struct _validate_ctx subctx = { + /* input */ .ctx = ctx, .net_size = net_size, .net_bytes = net_bytes, + /* output */ .net_offset = 0, .host_extra = 0, }; @@ -248,11 +257,13 @@ bool lib9p_stat_validate(struct lib9p_ctx *ctx, uint32_t net_size, uint8_t *net_ uint32_t lib9p_stat_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, struct lib9p_stat *ret_obj, void *ret_extra) { struct _unmarshal_ctx subctx = { - .ctx = ctx, - .net_bytes = net_bytes, - .net_offset = 0, + /* input */ + .ctx = ctx, + .net_bytes = net_bytes, - .extra = ret_extra, + /* output */ + .net_offset = 0, + .extra = ret_extra, }; _lib9p_stat_unmarshal(&subctx, ret_obj); return subctx.net_offset; @@ -263,7 +274,10 @@ uint32_t lib9p_stat_marshal(struct lib9p_ctx *ctx, uint32_t max_net_size, struct struct lib9p_ctx _ctx = *ctx; _ctx.max_msg_size = max_net_size; struct _marshal_ctx subctx = { + /* input */ .ctx = &_ctx, + + /* output */ .net_bytes = ret_bytes, .net_offset = 0, }; -- cgit v1.2.3-2-g168b