diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-09-27 22:27:01 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-09-27 22:27:01 -0600 |
commit | 7ec97df3ee8edfd102fe573eaa61cf4e5c6284cb (patch) | |
tree | e696f30da5645cdd3cb09971d9544622e9943bcf | |
parent | fa357459f88bb8f0170d1a68df66e7d068d59996 (diff) |
wip fixes
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | cmd/sbc_harness/usb_keyboard.c | 5 | ||||
-rw-r--r-- | cmd/srv9p/main.c | 17 | ||||
-rw-r--r-- | lib9p/9p.c | 72 | ||||
-rw-r--r-- | lib9p/include/lib9p/9p.h | 14 | ||||
-rw-r--r-- | lib9p/include/lib9p/_types.h | 2 | ||||
-rw-r--r-- | lib9p/include/lib9p/srv.h | 5 | ||||
-rw-r--r-- | lib9p/internal.h | 13 | ||||
-rw-r--r-- | lib9p/srv.c | 69 | ||||
-rw-r--r-- | lib9p/types.c | 811 | ||||
-rwxr-xr-x | lib9p/types.gen | 71 | ||||
-rw-r--r-- | libcr/coroutine.c | 15 | ||||
-rw-r--r-- | libcr/include/libcr/coroutine.h | 2 | ||||
-rw-r--r-- | libcr_ipc/sema.c | 3 | ||||
-rw-r--r-- | libnetio/include/libnetio/netio.h (renamed from libnetio/netio.h) | 6 | ||||
-rw-r--r-- | libnetio/netio_posix.c | 2 | ||||
-rw-r--r-- | libusb/usb_common.c | 1 | ||||
-rw-r--r-- | notes.md | 50 |
18 files changed, 632 insertions, 528 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index f33b81b..ae76e60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,8 @@ endif() project(sbc_harness) +add_compile_options(-Wall -Wextra -Werror) + add_subdirectory(libcr) add_subdirectory(libcr_ipc) add_subdirectory(libusb) diff --git a/cmd/sbc_harness/usb_keyboard.c b/cmd/sbc_harness/usb_keyboard.c index 3cf0bb3..5482fdc 100644 --- a/cmd/sbc_harness/usb_keyboard.c +++ b/cmd/sbc_harness/usb_keyboard.c @@ -11,6 +11,8 @@ #include "usb_keyboard.h" +#define UNUSED(name) /* name __attribute__ ((unused)) */ + /** * A USB-HID "Report Descriptor" (see USB-HID 1.11 ยง6.2.2 "Report * Descriptor") describing a keyboard. @@ -107,8 +109,7 @@ uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_t // Invoked when received SET_REPORT control request or // received data on OUT endpoint ( Report ID = 0, Type = 0 ) -void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) +void tud_hid_set_report_cb(uint8_t UNUSED(instance), uint8_t UNUSED(report_id), hid_report_type_t UNUSED(report_type), uint8_t const *UNUSED(buffer), uint16_t UNUSED(bufsize)) { // TODO not implemented - (void) report_id; } diff --git a/cmd/srv9p/main.c b/cmd/srv9p/main.c index d63c5fb..2c403df 100644 --- a/cmd/srv9p/main.c +++ b/cmd/srv9p/main.c @@ -2,16 +2,27 @@ #include <stdio.h> #include <libcr/coroutine.h> +#include <libnetio/netio.h> #include <lib9p/srv.h> +#define USE_CONFIG_COROUTINE +#include "config.h" + int main() { int sock = netio_listen(9000); if (sock < 0) error(1, -sock, "netio_listen"); - for (int i = 0; i < 8; i++) - if (!coroutine_add(net9p_cr, &sock)) - error(1, 0, "coroutine_add(net9p_cr, NULL)"); + struct lib9p_srv srv = { + .sockfd = sock, + }; + + for (int i = 0; i < CONFIG_NETIO_NUM_CONNS; i++) + if (!coroutine_add(lib9p_srv_read_cr, &srv)) + error(1, 0, "coroutine_add(lib9p_srv_read_cr, &srv)"); + for (int i = 0; i < 2*CONFIG_NETIO_NUM_CONNS; i++) + if (!coroutine_add(lib9p_srv_write_cr, &srv)) + error(1, 0, "coroutine_add(lib9p_srv_write_cr, &srv)"); coroutine_main(); return 1; @@ -13,12 +13,12 @@ #include "internal.h" -enum lib9p_version lib9p_ctx_version(lib9p_ctx *ctx) { +enum lib9p_version lib9p_ctx_version(struct lib9p_ctx *ctx) { assert(ctx); return ctx->version; } -uint32_t lib9p_ctx_max_msg_size(lib9p_ctx *ctx) { +uint32_t lib9p_ctx_max_msg_size(struct lib9p_ctx *ctx) { assert(ctx); return ctx->max_msg_size; } @@ -45,50 +45,66 @@ int lib9p_errorf(struct lib9p_ctx *ctx, uint32_t linux_errno, char const *fmt, . return -1; } -size_t lib9p_unmarshal_size(struct lib9p_ctx *ctx, uint8_t *net_bytes) { +ssize_t lib9p_unmarshal_size(struct lib9p_ctx *ctx, uint8_t *net_bytes) { /* Header */ - uint32_t net_len = decode_u32le(net_bytes); - if (net_len < 7) + struct _checksize_ctx subctx = { + .ctx = ctx, + .net_size = decode_u32le(net_bytes), + .net_bytes = net_bytes, + + .net_offset = 7, + .host_extra = 0, + }; + if (subctx.net_size < subctx.net_offset) return lib9p_error(ctx, LINUX_EBADMSG, "message is too short"); uint8_t typ = net_bytes[4]; - uint32_t net_offset = 7; /* Body */ - if (!versions[ctx->version]->msgs[typ].unmarshal_extrasize) + struct _vtable_msg vtable = _lib9p_vtables[ctx->version].msgs[typ]; + if (!vtable.unmarshal_extrasize) return lib9p_errorf(ctx, LINUX_EOPNOTSUPP, "unknown message type %"PRIu8, typ); - size_t host_size = versions[ctx->version]->msgs[typ].unmarshal_basesize; - if (versions[ctx->version]->msgs[typ].unmarshal_extrasize(net_len, net_bytes, &net_offset, &host_size)) - return lib9p_error(ctx, LINUX_EBADMSG, "message is too short for content"); + if (vtable.unmarshal_extrasize(&subctx)) + return -1; - return host_size; + return (ssize_t)(vtable.unmarshal_basesize + subctx.host_extra); } -uint8_t lib9p_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, uint16_t *out_tag, void *out_body) { +void lib9p_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, + enum lib9p_msg_type *ret_typ, uint16_t *ret_tag, void *ret_body) { /* Header */ - uint8_t typ = net_bytes[4]; - *out_tag = decode_u16le(&net_bytes[5]); - uint32_t net_offset = 7; + struct _unmarshal_ctx subctx = { + .ctx = ctx, + .net_bytes = net_bytes, - /* Body */ - void *host_extra = out_body + versions[ctx->version]->msgs[typ].unmarshal_basesize; - if (versions[ctx->version]->msgs[typ].unmarshal(net_bytes, &net_offset, &host_extra, out_body)) - return lib9p_error(ctx, LINUX_EBADMSG, "message contains invalid UTF-8"); + .net_offset = 7, + }; + *ret_typ = net_bytes[4]; + *ret_tag = decode_u16le(&net_bytes[5]); - return typ; + /* Body */ + struct _vtable_msg vtable = _lib9p_vtables[ctx->version].msgs[*ret_typ]; + subctx.extra = ret_body + vtable.unmarshal_basesize; + vtable.unmarshal(&subctx, ret_body); } -uint32_t lib9p_marshal(struct lib9p_ctx *ctx, uint8_t typ, uint16_t msgid, void *body, uint8_t *out_bytes) { +bool lib9p_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, uint16_t tag, void *body, + uint8_t *ret_bytes) { /* Header */ - out_bytes[4] = typ; - encode_u16le(msgid, &out_bytes[5]); - uint32_t net_offset = 7; + struct _marshal_ctx subctx = { + .ctx = ctx, + .net_bytes = ret_bytes, + .net_offset = 7, + }; + ret_bytes[4] = typ; + encode_u16le(tag, &ret_bytes[5]); /* Body */ - if (versions[ctx->version]->msgs[typ].marshal(ctx, body, out_bytes, &net_offset)) - return 0; + struct _vtable_msg vtable = _lib9p_vtables[ctx->version].msgs[typ]; + if (vtable.marshal(&subctx, body)) + return true; /* Header, again */ - encode_u32le(net_offset, out_bytes); + encode_u32le(subctx.net_offset, ret_bytes); - return net_offset; + return false; } diff --git a/lib9p/include/lib9p/9p.h b/lib9p/include/lib9p/9p.h index a55f08f..954498e 100644 --- a/lib9p/include/lib9p/9p.h +++ b/lib9p/include/lib9p/9p.h @@ -7,6 +7,9 @@ #ifndef _LIB9P_9P_H_ #define _LIB9P_9P_H_ +#include <stdbool.h> +#include <sys/types.h> /* for ssize_t */ + #include <lib9p/linux-errno.h> #include <lib9p/_types.h> @@ -14,8 +17,8 @@ #define LIB9P_NOFID ((uint32_t)~0U) struct lib9p_ctx; -enum lib9p_version lib9p_ctx_version(lib9p_ctx *); -uint32_t lib9p_ctx_max_msg_size(lib9p_ctx *); +enum lib9p_version lib9p_ctx_version(struct lib9p_ctx *); +uint32_t lib9p_ctx_max_msg_size(struct lib9p_ctx *); /** Write an static error into ctx, return -1. */ int lib9p_error(struct lib9p_ctx *ctx, uint32_t linux_errno, char const *msg); @@ -50,10 +53,9 @@ ssize_t lib9p_unmarshal_size(struct lib9p_ctx *ctx, uint8_t *net_bytes); * @return ret_typ : the mesage type * @return ret_tag : the message-ID tag * @return ret_body : the message body, must be at least lib9p_unmarshal_size() bytes - * @return the message type, or -1 on error */ -bool lib9p_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, - enum lib9p_msg_typ *ret_typ, uint16_t *ret_tag, void *ret_body); +void lib9p_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, + enum lib9p_msg_type *ret_typ, uint16_t *ret_tag, void *ret_body); /** * Marshal a `struct lib9p_msg_{typ}` structure into a byte-array. @@ -66,7 +68,7 @@ bool lib9p_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, * @return ret_bytes : the buffer to encode to, must be at be at least lib9p_ctx_max_msg_size(ctx) bytes * @return whether there was an error (false=success, true=error) */ -bool lib9p_marshal(struct lib9p_ctx *ctx, uint8_t typ, uint16_t tag, void *body, +bool lib9p_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, uint16_t tag, void *body, uint8_t *ret_bytes); #endif _LIB9P_9P_H_ diff --git a/lib9p/include/lib9p/_types.h b/lib9p/include/lib9p/_types.h index 7dcd8e2..7f320a5 100644 --- a/lib9p/include/lib9p/_types.h +++ b/lib9p/include/lib9p/_types.h @@ -3,7 +3,7 @@ #ifndef _LIB9P__TYPES_H_ #define _LIB9P__TYPES_H_ -#include <stdint.h> +#include <stdint.h> /* for uint{n}_t types */ /* versions *******************************************************************/ diff --git a/lib9p/include/lib9p/srv.h b/lib9p/include/lib9p/srv.h index 3b8b21e..a8bd9c7 100644 --- a/lib9p/include/lib9p/srv.h +++ b/lib9p/include/lib9p/srv.h @@ -2,12 +2,13 @@ #define _LIB9P_SRV_H_ #include <libcr/coroutine.h> +#include <libcr_ipc/chan.h> struct lib9p_srvreq; struct lib9p_srv { - int sockfd; - cr_chan_t(lib9p_srvreq *) reqch; + int sockfd; + cr_chan_t(struct lib9p_srvreq *) reqch; }; COROUTINE lib9p_srv_read_cr(void *_srv); diff --git a/lib9p/internal.h b/lib9p/internal.h index ebdc3f3..a5175af 100644 --- a/lib9p/internal.h +++ b/lib9p/internal.h @@ -8,13 +8,15 @@ #define _LIB9P_INTERNAL_H_ #include <assert.h> -#include <stdbool.h> +#include <stddef.h> /* for size_t */ +#include <limits.h> /* for SSIZE_MAX */ #include <lib9p/9p.h> -#define USE_CONFIG_LIB9P +#define USE_CONFIG_9P #include "config.h" -static_assert(CONFIG_LIB9P_MAX_ERR_SIZE <= UINT16_MAX); +static_assert(CONFIG_9P_MAX_ERR_SIZE <= UINT16_MAX); +static_assert(CONFIG_9P_MAX_MSG_SIZE <= SSIZE_MAX); /* C language *****************************************************************/ @@ -34,7 +36,7 @@ struct lib9p_ctx { /* state */ uint32_t err_num; - char err_msg[CONFIG_LIB9P_MAX_ERR_SIZE]; + char err_msg[CONFIG_9P_MAX_ERR_SIZE]; }; /* vtables ********************************************************************/ @@ -42,7 +44,7 @@ struct lib9p_ctx { struct _checksize_ctx { struct lib9p_ctx *ctx; uint32_t net_size; - uint8_t net_bytes; + uint8_t *net_bytes; uint32_t net_offset; /* Increment `host_extra` to pre-allocate space that is @@ -52,6 +54,7 @@ struct _checksize_ctx { struct _unmarshal_ctx { struct lib9p_ctx *ctx; + uint8_t *net_bytes; uint32_t net_offset; /* `extra` points to the beginning of unallocated space. */ diff --git a/lib9p/srv.c b/lib9p/srv.c index c6558d6..9a68a2b 100644 --- a/lib9p/srv.c +++ b/lib9p/srv.c @@ -1,47 +1,50 @@ #include <assert.h> +#include <stdio.h> /* for fprintf(), stderr */ +#include <string.h> /* for strerror() */ #include <libcr/coroutine.h> #include <libcr_ipc/chan.h> #include <libnetio/netio.h> #include <lib9p/9p.h> +#include <lib9p/srv.h> #include "internal.h" -struct p9_srvconn { +struct lib9p_srvconn { /* immutable */ - p9_srv *srv; - cid_t reader; - int fd; + struct lib9p_srv *srv; + cid_t reader; + int fd; /* mutable */ - uint32_t max_msg_size; - enum p9_version version; - unsigned int refcount; + uint32_t max_msg_size; + enum lib9p_version version; + unsigned int refcount; }; -struct p9_srvreq { - p9_srvconn *conn; - uint8_t *msg; +struct lib9p_srvreq { + struct lib9p_srvconn *conn; + uint8_t *msg; }; -COROUTINE p9_srv_read_cr(void *_srv) { +COROUTINE lib9p_srv_read_cr(void *_srv) { uint8_t buf[CONFIG_9P_MAX_MSG_SIZE]; - p9_srv *srv = _srv; + struct lib9p_srv *srv = _srv; assert(srv); cr_begin(); for (;;) { - struct p9_srvconn conn = { + struct lib9p_srvconn conn = { .srv = srv, - .reader = cr_getcid(); + .reader = cr_getcid(), - .max_msg_size = CONFIG_9P_MAX_MSG_SIZE; - .version = P9_VER_UNINITIALIZED; + .max_msg_size = CONFIG_9P_MAX_MSG_SIZE, + .version = LIB9P_VER_UNINITIALIZED, .refcount = 1, }; conn.fd = netio_accept(srv->sockfd); if (conn.fd < 0) { - fprintf(stderr, "error: accept: %m", -conn.fd); + fprintf(stderr, "error: accept: %s", strerror(-conn.fd)); continue; } @@ -67,14 +70,14 @@ COROUTINE p9_srv_read_cr(void *_srv) { goto close; } if (goal > conn.max_msg_size) { - struct p9_ctx ctx = { + struct lib9p_ctx ctx = { .version = conn.version, .max_msg_size = conn.max_msg_size, }; if (initialized) - p9_errorf(&ctx, LINUX_EMSGSIZE, "T-message larger than negotiated limit (%zu > %zu)", goal, conn.max_msg_size); + lib9p_errorf(&ctx, LINUX_EMSGSIZE, "T-message larger than negotiated limit (%zu > %zu)", goal, conn.max_msg_size); else - p9_errorf(&ctx, LINUX_EMSGSIZE, "T-message larger than server limit (%zu > %zu)", goal, conn.max_msg_size); + lib9p_errorf(&ctx, LINUX_EMSGSIZE, "T-message larger than server limit (%zu > %zu)", goal, conn.max_msg_size); marshal_error(&ctx, buf); netio_write(conn.fd, buf, decode_u32le(buf)); continue; @@ -93,7 +96,7 @@ COROUTINE p9_srv_read_cr(void *_srv) { } /* Handle the message... */ - if (conn.version == P9_VER_UNINITIALIZED) { + if (conn.version == LIB9P_VER_UNINITIALIZED) { /* ...synchronously if we haven't negotiated the protocol yet, ... */ handle_message(&conn, buf); } else { @@ -114,15 +117,15 @@ COROUTINE p9_srv_read_cr(void *_srv) { cr_end(); } -COROUTINE p9_srv_write_cr(void *_srv) { +COROUTINE lib9p_srv_write_cr(void *_srv) { uint8_t net[CONFIG_9P_MAX_MSG_SIZE]; - p9_srv *srv = _srv; + lib9p_srv *srv = _srv; assert(srv); cr_begin(); for (;;) { - struct p9_srvreq req; + struct lib9p_srvreq req; cr_chan_recv(&srv->reqch, &req); memcpy(net, req.msg, decode_u32le(req.msg)); req.conn->refcount++; @@ -137,28 +140,28 @@ COROUTINE p9_srv_write_cr(void *_srv) { cr_end(); } -void handle_message(p9_srvconn *conn, uint8_t *net) { +void handle_message(lib9p_srvconn *conn, uint8_t *net) { uint8_t host[CONFIG_9P_MAX_MSG_SIZE]; - struct p9_ctx ctx = { + struct lib9p_ctx ctx = { .version = req.conn->version, .max_msg_size = req.conn->max_msg_size, }; - size_t host_size = p9_unmarshal_size(&ctx, net); + size_t host_size = lib9p_unmarshal_size(&ctx, net); if (host_size == (size_t)-1) goto write; if (host_size > sizeof(host)) { - p9_errorf(&ctx, LINUX_EMSGSIZE, "unmarshalled payload larger than server limit (%zu > %zu)", host_size, sizeof(host)); + lib9p_errorf(&ctx, LINUX_EMSGSIZE, "unmarshalled payload larger than server limit (%zu > %zu)", host_size, sizeof(host)); goto write; } uint16_t tag; - uint8_t typ = p9_unmarshal(&ctx, net, &tag, host); + uint8_t typ = lib9p_unmarshal(&ctx, net, &tag, host); if (typ == (uint8_t)-1) goto write; if (typ % 2 != 0) { - p9_errorf(&ctx, LINUX_EOPNOTSUPP, "expected a T-message but got an R-message"); + lib9p_errorf(&ctx, LINUX_EOPNOTSUPP, "expected a T-message but got an R-message"); goto write; } @@ -179,8 +182,8 @@ static inline uint16_t min_u16(uint16_t a, b) { /* We have special code for marshaling Rerror because we don't ever * want to produce an error because the err_msg is too long for the * `ctx->max_msg_size`! */ -void marshal_error(struct p9_ctx *ctx, uint16_t tag, uint8_t *net) { - struct p9_msg_Rerror host = { +void marshal_error(struct lib9p_ctx *ctx, uint16_t tag, uint8_t *net) { + struct lib9p_msg_Rerror host = { .ename = { .len = strnlen(ctx->err_msg, CONFIG_9P_MAX_ERR_SIZE), .utf8 = ctx->err_msg, @@ -188,7 +191,7 @@ void marshal_error(struct p9_ctx *ctx, uint16_t tag, uint8_t *net) { }; if (host.ename.len + ctx->Rerror_overhead > ctx->max_msg_size) host.ename.len = ctx->max_msg_size - overhead; - p9_marshal(ctx, tag, host, net); + lib9p_marshal(ctx, tag, host, net); } ERANGE for reply too large diff --git a/lib9p/types.c b/lib9p/types.c index deceb4e..5b6d0a0 100644 --- a/lib9p/types.c +++ b/lib9p/types.c @@ -1,6 +1,9 @@ /* Generated by `./lib9p/types.gen lib9p/9P2000.txt lib9p/9P2000.u.txt lib9p/9P2000.e.txt`. DO NOT EDIT! */ #include <stdbool.h> +#include <stddef.h> /* for size_t */ +#include <inttypes.h> /* for PRI* macros */ +#include <string.h> /* for memset() */ #include <lib9p/9p.h> @@ -43,18 +46,18 @@ static inline bool _checksize_list(struct _checksize_ctx *ctx, static inline bool checksize_d(struct _checksize_ctx *ctx) { uint32_t base_offset = ctx->net_offset; - if (_checksize_4(ctx)) + if (checksize_4(ctx)) return true; uint32_t len = decode_u32le(&ctx->net_bytes[base_offset]); - return checksize_net(ctx, len) || checksize_host(ctx, len); + return _checksize_net(ctx, len) || _checksize_host(ctx, len); } static inline bool checksize_s(struct _checksize_ctx *ctx) { uint32_t base_offset = ctx->net_offset; - if (_checksize_2(ctx)) + if (checksize_2(ctx)) return true; uint16_t len = decode_u16le(&ctx->net_bytes[base_offset]); - if (checksize_net(ctx, len) || checksize_host(ctx, ((size_t)len)+1)) + if (_checksize_net(ctx, len) || _checksize_host(ctx, ((size_t)len)+1)) return true; if (!is_valid_utf8_without_nul(&ctx->net_bytes[base_offset+2], len)) return lib9p_error(ctx->ctx, LINUX_EBADMSG, "message contains invalid UTF-8"); @@ -249,22 +252,22 @@ static bool checksize_Rswrite(struct _checksize_ctx *ctx) { /* unmarshal_* ****************************************************************/ -static inline vold unmarshal_1(struct _unmarshal_ctx *ctx, uint8_t *out) { +static inline void unmarshal_1(struct _unmarshal_ctx *ctx, uint8_t *out) { *out = decode_u8le(&ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 1; } -static inline vold unmarshal_2(struct _unmarshal_ctx *ctx, uint16_t *out) { +static inline void unmarshal_2(struct _unmarshal_ctx *ctx, uint16_t *out) { *out = decode_u16le(&ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 2; } -static inline vold unmarshal_4(struct _unmarshal_ctx *ctx, uint32_t *out) { +static inline void unmarshal_4(struct _unmarshal_ctx *ctx, uint32_t *out) { *out = decode_u32le(&ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 4; } -static inline vold unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out) { +static inline void unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out) { *out = decode_u64le(&ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 8; } @@ -272,8 +275,8 @@ static inline vold unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out) { static inline void unmarshal_d(struct _unmarshal_ctx *ctx, struct lib9p_d *out) { memset(out, 0, sizeof(*out)); unmarshal_4(ctx, &out->len); - out->dat = ctx->host_extra; - ctx->host_extra += sizeof(out->dat[0]) * out->len; + out->dat = ctx->extra; + ctx->extra += sizeof(out->dat[0]) * out->len; for (typeof(out->len) i = 0; i < out->len; i++) unmarshal_1(ctx, &out->dat[i]); } @@ -281,8 +284,8 @@ static inline void unmarshal_d(struct _unmarshal_ctx *ctx, struct lib9p_d *out) static inline void unmarshal_s(struct _unmarshal_ctx *ctx, struct lib9p_s *out) { memset(out, 0, sizeof(*out)); unmarshal_2(ctx, &out->len); - out->utf8 = ctx->host_extra; - ctx->host_extra += sizeof(out->utf8[0]) * out->len; + out->utf8 = ctx->extra; + ctx->extra += sizeof(out->utf8[0]) * out->len; for (typeof(out->len) i = 0; i < out->len; i++) unmarshal_1(ctx, &out->utf8[i]); } @@ -363,7 +366,7 @@ static void unmarshal_Tflush(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tflush unmarshal_2(ctx, &out->oldtag); } -static void unmarshal_Rflush(struct _unmarshal_ctx *UNUSED(ctx), struct lib9p_msg_Rflush *UNUSED(out)) { +static void unmarshal_Rflush(struct _unmarshal_ctx *UNUSED(ctx), struct lib9p_msg_Rflush *out) { memset(out, 0, sizeof(*out)); } @@ -372,8 +375,8 @@ static void unmarshal_Twalk(struct _unmarshal_ctx *ctx, struct lib9p_msg_Twalk * unmarshal_4(ctx, &out->fid); unmarshal_4(ctx, &out->newfid); unmarshal_2(ctx, &out->nwname); - out->wname = ctx->host_extra; - ctx->host_extra += sizeof(out->wname[0]) * out->nwname; + out->wname = ctx->extra; + ctx->extra += sizeof(out->wname[0]) * out->nwname; for (typeof(out->nwname) i = 0; i < out->nwname; i++) unmarshal_s(ctx, &out->wname[i]); } @@ -381,8 +384,8 @@ static void unmarshal_Twalk(struct _unmarshal_ctx *ctx, struct lib9p_msg_Twalk * static void unmarshal_Rwalk(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rwalk *out) { memset(out, 0, sizeof(*out)); unmarshal_2(ctx, &out->nwqid); - out->wqid = ctx->host_extra; - ctx->host_extra += sizeof(out->wqid[0]) * out->nwqid; + out->wqid = ctx->extra; + ctx->extra += sizeof(out->wqid[0]) * out->nwqid; for (typeof(out->nwqid) i = 0; i < out->nwqid; i++) unmarshal_qid(ctx, &out->wqid[i]); } @@ -442,7 +445,7 @@ static void unmarshal_Tclunk(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tclunk unmarshal_4(ctx, &out->fid); } -static void unmarshal_Rclunk(struct _unmarshal_ctx *UNUSED(ctx), struct lib9p_msg_Rclunk *UNUSED(out)) { +static void unmarshal_Rclunk(struct _unmarshal_ctx *UNUSED(ctx), struct lib9p_msg_Rclunk *out) { memset(out, 0, sizeof(*out)); } @@ -451,7 +454,7 @@ static void unmarshal_Tremove(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tremo unmarshal_4(ctx, &out->fid); } -static void unmarshal_Rremove(struct _unmarshal_ctx *UNUSED(ctx), struct lib9p_msg_Rremove *UNUSED(out)) { +static void unmarshal_Rremove(struct _unmarshal_ctx *UNUSED(ctx), struct lib9p_msg_Rremove *out) { memset(out, 0, sizeof(*out)); } @@ -471,7 +474,7 @@ static void unmarshal_Twstat(struct _unmarshal_ctx *ctx, struct lib9p_msg_Twstat unmarshal_stat(ctx, &out->stat); } -static void unmarshal_Rwstat(struct _unmarshal_ctx *UNUSED(ctx), struct lib9p_msg_Rwstat *UNUSED(out)) { +static void unmarshal_Rwstat(struct _unmarshal_ctx *UNUSED(ctx), struct lib9p_msg_Rwstat *out) { memset(out, 0, sizeof(*out)); } @@ -480,7 +483,7 @@ static void unmarshal_Tsession(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tses unmarshal_8(ctx, &out->key); } -static void unmarshal_Rsession(struct _unmarshal_ctx *UNUSED(ctx), struct lib9p_msg_Rsession *UNUSED(out)) { +static void unmarshal_Rsession(struct _unmarshal_ctx *UNUSED(ctx), struct lib9p_msg_Rsession *out) { memset(out, 0, sizeof(*out)); } @@ -488,8 +491,8 @@ static void unmarshal_Tsread(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tsread memset(out, 0, sizeof(*out)); unmarshal_4(ctx, &out->fid); unmarshal_2(ctx, &out->nwname); - out->wname = ctx->host_extra; - ctx->host_extra += sizeof(out->wname[0]) * out->nwname; + out->wname = ctx->extra; + ctx->extra += sizeof(out->wname[0]) * out->nwname; for (typeof(out->nwname) i = 0; i < out->nwname; i++) unmarshal_s(ctx, &out->wname[i]); } @@ -503,8 +506,8 @@ static void unmarshal_Tswrite(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tswri memset(out, 0, sizeof(*out)); unmarshal_4(ctx, &out->fid); unmarshal_2(ctx, &out->nwname); - out->wname = ctx->host_extra; - ctx->host_extra += sizeof(out->wname[0]) * out->nwname; + out->wname = ctx->extra; + ctx->extra += sizeof(out->wname[0]) * out->nwname; for (typeof(out->nwname) i = 0; i < out->nwname; i++) unmarshal_s(ctx, &out->wname[i]); unmarshal_d(ctx, &out->data); @@ -518,43 +521,43 @@ static void unmarshal_Rswrite(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rswri /* marshal_* ******************************************************************/ static inline bool _marshal_too_large(struct _marshal_ctx *ctx) { - lib9p_errorf(ctx->ctx, "%s too large to marshal into %s limit (limit=%"PRIu32")", + lib9p_errorf(ctx->ctx, LINUX_EMSGSIZE, "%s too large to marshal into %s limit (limit=%"PRIu32")", (ctx->net_bytes[4] % 2 == 0) ? "T-message" : "R-message", ctx->ctx->version ? "negotiated" : ((ctx->net_bytes[4] % 2 == 0) ? "client" : "server"), - ctx->ctx->max_msg_size)); - return true; + ctx->ctx->max_msg_size); + return true; } static inline bool marshal_1(struct _marshal_ctx *ctx, uint8_t *val) { - if (ctx->net_offset + 1 > ctx->max_msg_size) - return _marshal_too_large(ctx); - out_net_bytes[ctx->net_offset] = *val; + if (ctx->net_offset + 1 > ctx->ctx->max_msg_size) + return _marshal_too_large(ctx); + ctx->net_bytes[ctx->net_offset] = *val; ctx->net_offset += 1; - return false; + return false; } static inline bool marshal_2(struct _marshal_ctx *ctx, uint16_t *val) { - if (ctx->net_offset + 2 > ctx->max_msg_size) - return _marshal_too_large(ctx); - encode_u16le(*val, &out_net_bytes[ctx->net_offset]); + if (ctx->net_offset + 2 > ctx->ctx->max_msg_size) + return _marshal_too_large(ctx); + encode_u16le(*val, &ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 2; - return false; + return false; } static inline bool marshal_4(struct _marshal_ctx *ctx, uint32_t *val) { - if (ctx->net_offset + 4 > ctx->max_msg_size) + if (ctx->net_offset + 4 > ctx->ctx->max_msg_size) return true; - encode_u32le(*val, &out_net_bytes[ctx->net_offset]); + encode_u32le(*val, &ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 4; - return false; + return false; } static inline bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) { - if (ctx->net_offset + 8 > ctx->max_msg_size) + if (ctx->net_offset + 8 > ctx->ctx->max_msg_size) return true; - encode_u64le(*val, &out_net_bytes[ctx->net_offset]); + encode_u64le(*val, &ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 8; - return false; + return false; } static inline bool marshal_d(struct _marshal_ctx *ctx, struct lib9p_d *val) { @@ -562,7 +565,7 @@ static inline bool marshal_d(struct _marshal_ctx *ctx, struct lib9p_d *val) { || ({ bool err = false; for (typeof(val->len) i = 0; i < val->len && !err; i++) - err = marshal_1(ctx, &val->dat[i])); + err = marshal_1(ctx, &val->dat[i]); err; }); } @@ -572,7 +575,7 @@ static inline bool marshal_s(struct _marshal_ctx *ctx, struct lib9p_s *val) { || ({ bool err = false; for (typeof(val->len) i = 0; i < val->len && !err; i++) - err = marshal_1(ctx, &val->utf8[i])); + err = marshal_1(ctx, &val->utf8[i]); err; }); } @@ -654,7 +657,7 @@ static bool marshal_Twalk(struct _marshal_ctx *ctx, struct lib9p_msg_Twalk *val) || ({ bool err = false; for (typeof(val->nwname) i = 0; i < val->nwname && !err; i++) - err = marshal_s(ctx, &val->wname[i])); + err = marshal_s(ctx, &val->wname[i]); err; }); } @@ -664,7 +667,7 @@ static bool marshal_Rwalk(struct _marshal_ctx *ctx, struct lib9p_msg_Rwalk *val) || ({ bool err = false; for (typeof(val->nwqid) i = 0; i < val->nwqid && !err; i++) - err = marshal_qid(ctx, &val->wqid[i])); + err = marshal_qid(ctx, &val->wqid[i]); err; }); } @@ -758,7 +761,7 @@ static bool marshal_Tsread(struct _marshal_ctx *ctx, struct lib9p_msg_Tsread *va || ({ bool err = false; for (typeof(val->nwname) i = 0; i < val->nwname && !err; i++) - err = marshal_s(ctx, &val->wname[i])); + err = marshal_s(ctx, &val->wname[i]); err; }); } @@ -773,7 +776,7 @@ static bool marshal_Tswrite(struct _marshal_ctx *ctx, struct lib9p_msg_Tswrite * || ({ bool err = false; for (typeof(val->nwname) i = 0; i < val->nwname && !err; i++) - err = marshal_s(ctx, &val->wname[i])); + err = marshal_s(ctx, &val->wname[i]); err; }) || marshal_d(ctx, &val->data); @@ -788,544 +791,544 @@ static bool marshal_Rswrite(struct _marshal_ctx *ctx, struct lib9p_msg_Rswrite * struct _vtable_version _lib9p_vtables[LIB9P_VER_NUM] = { [LIB9P_VER_UNINITIALIZED] = { .msgs = { [LIB9P_TYP_Tversion] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tversion), - r.unmarshal_extrasize = checksize_Tversion, - r.unmarshal = unmarshal_Tversion, - r.marshal = (_marshal_fn_t)marshal_Tversion, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tversion), + .unmarshal_extrasize = checksize_Tversion, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tversion, + .marshal = (_marshal_fn_t)marshal_Tversion, }, [LIB9P_TYP_Rversion] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rversion), - r.unmarshal_extrasize = checksize_Rversion, - r.unmarshal = unmarshal_Rversion, - r.marshal = (_marshal_fn_t)marshal_Rversion, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rversion), + .unmarshal_extrasize = checksize_Rversion, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rversion, + .marshal = (_marshal_fn_t)marshal_Rversion, }, }}, [LIB9P_VER_9P2000] = { .msgs = { [LIB9P_TYP_Tversion] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tversion), - r.unmarshal_extrasize = checksize_Tversion, - r.unmarshal = unmarshal_Tversion, - r.marshal = (_marshal_fn_t)marshal_Tversion, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tversion), + .unmarshal_extrasize = checksize_Tversion, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tversion, + .marshal = (_marshal_fn_t)marshal_Tversion, }, [LIB9P_TYP_Rversion] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rversion), - r.unmarshal_extrasize = checksize_Rversion, - r.unmarshal = unmarshal_Rversion, - r.marshal = (_marshal_fn_t)marshal_Rversion, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rversion), + .unmarshal_extrasize = checksize_Rversion, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rversion, + .marshal = (_marshal_fn_t)marshal_Rversion, }, [LIB9P_TYP_Tauth] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tauth), - r.unmarshal_extrasize = checksize_Tauth, - r.unmarshal = unmarshal_Tauth, - r.marshal = (_marshal_fn_t)marshal_Tauth, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tauth), + .unmarshal_extrasize = checksize_Tauth, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tauth, + .marshal = (_marshal_fn_t)marshal_Tauth, }, [LIB9P_TYP_Rauth] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rauth), - r.unmarshal_extrasize = checksize_Rauth, - r.unmarshal = unmarshal_Rauth, - r.marshal = (_marshal_fn_t)marshal_Rauth, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rauth), + .unmarshal_extrasize = checksize_Rauth, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rauth, + .marshal = (_marshal_fn_t)marshal_Rauth, }, [LIB9P_TYP_Tattach] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tattach), - r.unmarshal_extrasize = checksize_Tattach, - r.unmarshal = unmarshal_Tattach, - r.marshal = (_marshal_fn_t)marshal_Tattach, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tattach), + .unmarshal_extrasize = checksize_Tattach, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tattach, + .marshal = (_marshal_fn_t)marshal_Tattach, }, [LIB9P_TYP_Rattach] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rattach), - r.unmarshal_extrasize = checksize_Rattach, - r.unmarshal = unmarshal_Rattach, - r.marshal = (_marshal_fn_t)marshal_Rattach, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rattach), + .unmarshal_extrasize = checksize_Rattach, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rattach, + .marshal = (_marshal_fn_t)marshal_Rattach, }, [LIB9P_TYP_Rerror] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rerror), - r.unmarshal_extrasize = checksize_Rerror, - r.unmarshal = unmarshal_Rerror, - r.marshal = (_marshal_fn_t)marshal_Rerror, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rerror), + .unmarshal_extrasize = checksize_Rerror, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rerror, + .marshal = (_marshal_fn_t)marshal_Rerror, }, [LIB9P_TYP_Tflush] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tflush), - r.unmarshal_extrasize = checksize_Tflush, - r.unmarshal = unmarshal_Tflush, - r.marshal = (_marshal_fn_t)marshal_Tflush, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tflush), + .unmarshal_extrasize = checksize_Tflush, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tflush, + .marshal = (_marshal_fn_t)marshal_Tflush, }, [LIB9P_TYP_Rflush] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rflush), - r.unmarshal_extrasize = checksize_Rflush, - r.unmarshal = unmarshal_Rflush, - r.marshal = (_marshal_fn_t)marshal_Rflush, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rflush), + .unmarshal_extrasize = checksize_Rflush, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rflush, + .marshal = (_marshal_fn_t)marshal_Rflush, }, [LIB9P_TYP_Twalk] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Twalk), - r.unmarshal_extrasize = checksize_Twalk, - r.unmarshal = unmarshal_Twalk, - r.marshal = (_marshal_fn_t)marshal_Twalk, + .unmarshal_basesize = sizeof(struct lib9p_msg_Twalk), + .unmarshal_extrasize = checksize_Twalk, + .unmarshal = (_unmarshal_fn_t)unmarshal_Twalk, + .marshal = (_marshal_fn_t)marshal_Twalk, }, [LIB9P_TYP_Rwalk] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rwalk), - r.unmarshal_extrasize = checksize_Rwalk, - r.unmarshal = unmarshal_Rwalk, - r.marshal = (_marshal_fn_t)marshal_Rwalk, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rwalk), + .unmarshal_extrasize = checksize_Rwalk, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rwalk, + .marshal = (_marshal_fn_t)marshal_Rwalk, }, [LIB9P_TYP_Topen] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Topen), - r.unmarshal_extrasize = checksize_Topen, - r.unmarshal = unmarshal_Topen, - r.marshal = (_marshal_fn_t)marshal_Topen, + .unmarshal_basesize = sizeof(struct lib9p_msg_Topen), + .unmarshal_extrasize = checksize_Topen, + .unmarshal = (_unmarshal_fn_t)unmarshal_Topen, + .marshal = (_marshal_fn_t)marshal_Topen, }, [LIB9P_TYP_Ropen] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Ropen), - r.unmarshal_extrasize = checksize_Ropen, - r.unmarshal = unmarshal_Ropen, - r.marshal = (_marshal_fn_t)marshal_Ropen, + .unmarshal_basesize = sizeof(struct lib9p_msg_Ropen), + .unmarshal_extrasize = checksize_Ropen, + .unmarshal = (_unmarshal_fn_t)unmarshal_Ropen, + .marshal = (_marshal_fn_t)marshal_Ropen, }, [LIB9P_TYP_Tcreate] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tcreate), - r.unmarshal_extrasize = checksize_Tcreate, - r.unmarshal = unmarshal_Tcreate, - r.marshal = (_marshal_fn_t)marshal_Tcreate, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tcreate), + .unmarshal_extrasize = checksize_Tcreate, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tcreate, + .marshal = (_marshal_fn_t)marshal_Tcreate, }, [LIB9P_TYP_Rcreate] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rcreate), - r.unmarshal_extrasize = checksize_Rcreate, - r.unmarshal = unmarshal_Rcreate, - r.marshal = (_marshal_fn_t)marshal_Rcreate, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rcreate), + .unmarshal_extrasize = checksize_Rcreate, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rcreate, + .marshal = (_marshal_fn_t)marshal_Rcreate, }, [LIB9P_TYP_Tread] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tread), - r.unmarshal_extrasize = checksize_Tread, - r.unmarshal = unmarshal_Tread, - r.marshal = (_marshal_fn_t)marshal_Tread, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tread), + .unmarshal_extrasize = checksize_Tread, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tread, + .marshal = (_marshal_fn_t)marshal_Tread, }, [LIB9P_TYP_Rread] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rread), - r.unmarshal_extrasize = checksize_Rread, - r.unmarshal = unmarshal_Rread, - r.marshal = (_marshal_fn_t)marshal_Rread, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rread), + .unmarshal_extrasize = checksize_Rread, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rread, + .marshal = (_marshal_fn_t)marshal_Rread, }, [LIB9P_TYP_Twrite] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Twrite), - r.unmarshal_extrasize = checksize_Twrite, - r.unmarshal = unmarshal_Twrite, - r.marshal = (_marshal_fn_t)marshal_Twrite, + .unmarshal_basesize = sizeof(struct lib9p_msg_Twrite), + .unmarshal_extrasize = checksize_Twrite, + .unmarshal = (_unmarshal_fn_t)unmarshal_Twrite, + .marshal = (_marshal_fn_t)marshal_Twrite, }, [LIB9P_TYP_Rwrite] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rwrite), - r.unmarshal_extrasize = checksize_Rwrite, - r.unmarshal = unmarshal_Rwrite, - r.marshal = (_marshal_fn_t)marshal_Rwrite, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rwrite), + .unmarshal_extrasize = checksize_Rwrite, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rwrite, + .marshal = (_marshal_fn_t)marshal_Rwrite, }, [LIB9P_TYP_Tclunk] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tclunk), - r.unmarshal_extrasize = checksize_Tclunk, - r.unmarshal = unmarshal_Tclunk, - r.marshal = (_marshal_fn_t)marshal_Tclunk, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tclunk), + .unmarshal_extrasize = checksize_Tclunk, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tclunk, + .marshal = (_marshal_fn_t)marshal_Tclunk, }, [LIB9P_TYP_Rclunk] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rclunk), - r.unmarshal_extrasize = checksize_Rclunk, - r.unmarshal = unmarshal_Rclunk, - r.marshal = (_marshal_fn_t)marshal_Rclunk, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rclunk), + .unmarshal_extrasize = checksize_Rclunk, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rclunk, + .marshal = (_marshal_fn_t)marshal_Rclunk, }, [LIB9P_TYP_Tremove] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tremove), - r.unmarshal_extrasize = checksize_Tremove, - r.unmarshal = unmarshal_Tremove, - r.marshal = (_marshal_fn_t)marshal_Tremove, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tremove), + .unmarshal_extrasize = checksize_Tremove, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tremove, + .marshal = (_marshal_fn_t)marshal_Tremove, }, [LIB9P_TYP_Rremove] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rremove), - r.unmarshal_extrasize = checksize_Rremove, - r.unmarshal = unmarshal_Rremove, - r.marshal = (_marshal_fn_t)marshal_Rremove, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rremove), + .unmarshal_extrasize = checksize_Rremove, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rremove, + .marshal = (_marshal_fn_t)marshal_Rremove, }, [LIB9P_TYP_Tstat] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tstat), - r.unmarshal_extrasize = checksize_Tstat, - r.unmarshal = unmarshal_Tstat, - r.marshal = (_marshal_fn_t)marshal_Tstat, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tstat), + .unmarshal_extrasize = checksize_Tstat, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tstat, + .marshal = (_marshal_fn_t)marshal_Tstat, }, [LIB9P_TYP_Rstat] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rstat), - r.unmarshal_extrasize = checksize_Rstat, - r.unmarshal = unmarshal_Rstat, - r.marshal = (_marshal_fn_t)marshal_Rstat, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rstat), + .unmarshal_extrasize = checksize_Rstat, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rstat, + .marshal = (_marshal_fn_t)marshal_Rstat, }, [LIB9P_TYP_Twstat] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Twstat), - r.unmarshal_extrasize = checksize_Twstat, - r.unmarshal = unmarshal_Twstat, - r.marshal = (_marshal_fn_t)marshal_Twstat, + .unmarshal_basesize = sizeof(struct lib9p_msg_Twstat), + .unmarshal_extrasize = checksize_Twstat, + .unmarshal = (_unmarshal_fn_t)unmarshal_Twstat, + .marshal = (_marshal_fn_t)marshal_Twstat, }, [LIB9P_TYP_Rwstat] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rwstat), - r.unmarshal_extrasize = checksize_Rwstat, - r.unmarshal = unmarshal_Rwstat, - r.marshal = (_marshal_fn_t)marshal_Rwstat, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rwstat), + .unmarshal_extrasize = checksize_Rwstat, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rwstat, + .marshal = (_marshal_fn_t)marshal_Rwstat, }, }}, [LIB9P_VER_9P2000_e] = { .msgs = { [LIB9P_TYP_Tversion] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tversion), - r.unmarshal_extrasize = checksize_Tversion, - r.unmarshal = unmarshal_Tversion, - r.marshal = (_marshal_fn_t)marshal_Tversion, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tversion), + .unmarshal_extrasize = checksize_Tversion, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tversion, + .marshal = (_marshal_fn_t)marshal_Tversion, }, [LIB9P_TYP_Rversion] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rversion), - r.unmarshal_extrasize = checksize_Rversion, - r.unmarshal = unmarshal_Rversion, - r.marshal = (_marshal_fn_t)marshal_Rversion, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rversion), + .unmarshal_extrasize = checksize_Rversion, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rversion, + .marshal = (_marshal_fn_t)marshal_Rversion, }, [LIB9P_TYP_Tauth] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tauth), - r.unmarshal_extrasize = checksize_Tauth, - r.unmarshal = unmarshal_Tauth, - r.marshal = (_marshal_fn_t)marshal_Tauth, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tauth), + .unmarshal_extrasize = checksize_Tauth, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tauth, + .marshal = (_marshal_fn_t)marshal_Tauth, }, [LIB9P_TYP_Rauth] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rauth), - r.unmarshal_extrasize = checksize_Rauth, - r.unmarshal = unmarshal_Rauth, - r.marshal = (_marshal_fn_t)marshal_Rauth, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rauth), + .unmarshal_extrasize = checksize_Rauth, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rauth, + .marshal = (_marshal_fn_t)marshal_Rauth, }, [LIB9P_TYP_Tattach] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tattach), - r.unmarshal_extrasize = checksize_Tattach, - r.unmarshal = unmarshal_Tattach, - r.marshal = (_marshal_fn_t)marshal_Tattach, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tattach), + .unmarshal_extrasize = checksize_Tattach, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tattach, + .marshal = (_marshal_fn_t)marshal_Tattach, }, [LIB9P_TYP_Rattach] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rattach), - r.unmarshal_extrasize = checksize_Rattach, - r.unmarshal = unmarshal_Rattach, - r.marshal = (_marshal_fn_t)marshal_Rattach, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rattach), + .unmarshal_extrasize = checksize_Rattach, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rattach, + .marshal = (_marshal_fn_t)marshal_Rattach, }, [LIB9P_TYP_Rerror] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rerror), - r.unmarshal_extrasize = checksize_Rerror, - r.unmarshal = unmarshal_Rerror, - r.marshal = (_marshal_fn_t)marshal_Rerror, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rerror), + .unmarshal_extrasize = checksize_Rerror, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rerror, + .marshal = (_marshal_fn_t)marshal_Rerror, }, [LIB9P_TYP_Tflush] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tflush), - r.unmarshal_extrasize = checksize_Tflush, - r.unmarshal = unmarshal_Tflush, - r.marshal = (_marshal_fn_t)marshal_Tflush, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tflush), + .unmarshal_extrasize = checksize_Tflush, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tflush, + .marshal = (_marshal_fn_t)marshal_Tflush, }, [LIB9P_TYP_Rflush] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rflush), - r.unmarshal_extrasize = checksize_Rflush, - r.unmarshal = unmarshal_Rflush, - r.marshal = (_marshal_fn_t)marshal_Rflush, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rflush), + .unmarshal_extrasize = checksize_Rflush, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rflush, + .marshal = (_marshal_fn_t)marshal_Rflush, }, [LIB9P_TYP_Twalk] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Twalk), - r.unmarshal_extrasize = checksize_Twalk, - r.unmarshal = unmarshal_Twalk, - r.marshal = (_marshal_fn_t)marshal_Twalk, + .unmarshal_basesize = sizeof(struct lib9p_msg_Twalk), + .unmarshal_extrasize = checksize_Twalk, + .unmarshal = (_unmarshal_fn_t)unmarshal_Twalk, + .marshal = (_marshal_fn_t)marshal_Twalk, }, [LIB9P_TYP_Rwalk] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rwalk), - r.unmarshal_extrasize = checksize_Rwalk, - r.unmarshal = unmarshal_Rwalk, - r.marshal = (_marshal_fn_t)marshal_Rwalk, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rwalk), + .unmarshal_extrasize = checksize_Rwalk, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rwalk, + .marshal = (_marshal_fn_t)marshal_Rwalk, }, [LIB9P_TYP_Topen] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Topen), - r.unmarshal_extrasize = checksize_Topen, - r.unmarshal = unmarshal_Topen, - r.marshal = (_marshal_fn_t)marshal_Topen, + .unmarshal_basesize = sizeof(struct lib9p_msg_Topen), + .unmarshal_extrasize = checksize_Topen, + .unmarshal = (_unmarshal_fn_t)unmarshal_Topen, + .marshal = (_marshal_fn_t)marshal_Topen, }, [LIB9P_TYP_Ropen] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Ropen), - r.unmarshal_extrasize = checksize_Ropen, - r.unmarshal = unmarshal_Ropen, - r.marshal = (_marshal_fn_t)marshal_Ropen, + .unmarshal_basesize = sizeof(struct lib9p_msg_Ropen), + .unmarshal_extrasize = checksize_Ropen, + .unmarshal = (_unmarshal_fn_t)unmarshal_Ropen, + .marshal = (_marshal_fn_t)marshal_Ropen, }, [LIB9P_TYP_Tcreate] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tcreate), - r.unmarshal_extrasize = checksize_Tcreate, - r.unmarshal = unmarshal_Tcreate, - r.marshal = (_marshal_fn_t)marshal_Tcreate, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tcreate), + .unmarshal_extrasize = checksize_Tcreate, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tcreate, + .marshal = (_marshal_fn_t)marshal_Tcreate, }, [LIB9P_TYP_Rcreate] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rcreate), - r.unmarshal_extrasize = checksize_Rcreate, - r.unmarshal = unmarshal_Rcreate, - r.marshal = (_marshal_fn_t)marshal_Rcreate, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rcreate), + .unmarshal_extrasize = checksize_Rcreate, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rcreate, + .marshal = (_marshal_fn_t)marshal_Rcreate, }, [LIB9P_TYP_Tread] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tread), - r.unmarshal_extrasize = checksize_Tread, - r.unmarshal = unmarshal_Tread, - r.marshal = (_marshal_fn_t)marshal_Tread, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tread), + .unmarshal_extrasize = checksize_Tread, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tread, + .marshal = (_marshal_fn_t)marshal_Tread, }, [LIB9P_TYP_Rread] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rread), - r.unmarshal_extrasize = checksize_Rread, - r.unmarshal = unmarshal_Rread, - r.marshal = (_marshal_fn_t)marshal_Rread, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rread), + .unmarshal_extrasize = checksize_Rread, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rread, + .marshal = (_marshal_fn_t)marshal_Rread, }, [LIB9P_TYP_Twrite] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Twrite), - r.unmarshal_extrasize = checksize_Twrite, - r.unmarshal = unmarshal_Twrite, - r.marshal = (_marshal_fn_t)marshal_Twrite, + .unmarshal_basesize = sizeof(struct lib9p_msg_Twrite), + .unmarshal_extrasize = checksize_Twrite, + .unmarshal = (_unmarshal_fn_t)unmarshal_Twrite, + .marshal = (_marshal_fn_t)marshal_Twrite, }, [LIB9P_TYP_Rwrite] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rwrite), - r.unmarshal_extrasize = checksize_Rwrite, - r.unmarshal = unmarshal_Rwrite, - r.marshal = (_marshal_fn_t)marshal_Rwrite, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rwrite), + .unmarshal_extrasize = checksize_Rwrite, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rwrite, + .marshal = (_marshal_fn_t)marshal_Rwrite, }, [LIB9P_TYP_Tclunk] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tclunk), - r.unmarshal_extrasize = checksize_Tclunk, - r.unmarshal = unmarshal_Tclunk, - r.marshal = (_marshal_fn_t)marshal_Tclunk, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tclunk), + .unmarshal_extrasize = checksize_Tclunk, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tclunk, + .marshal = (_marshal_fn_t)marshal_Tclunk, }, [LIB9P_TYP_Rclunk] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rclunk), - r.unmarshal_extrasize = checksize_Rclunk, - r.unmarshal = unmarshal_Rclunk, - r.marshal = (_marshal_fn_t)marshal_Rclunk, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rclunk), + .unmarshal_extrasize = checksize_Rclunk, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rclunk, + .marshal = (_marshal_fn_t)marshal_Rclunk, }, [LIB9P_TYP_Tremove] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tremove), - r.unmarshal_extrasize = checksize_Tremove, - r.unmarshal = unmarshal_Tremove, - r.marshal = (_marshal_fn_t)marshal_Tremove, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tremove), + .unmarshal_extrasize = checksize_Tremove, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tremove, + .marshal = (_marshal_fn_t)marshal_Tremove, }, [LIB9P_TYP_Rremove] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rremove), - r.unmarshal_extrasize = checksize_Rremove, - r.unmarshal = unmarshal_Rremove, - r.marshal = (_marshal_fn_t)marshal_Rremove, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rremove), + .unmarshal_extrasize = checksize_Rremove, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rremove, + .marshal = (_marshal_fn_t)marshal_Rremove, }, [LIB9P_TYP_Tstat] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tstat), - r.unmarshal_extrasize = checksize_Tstat, - r.unmarshal = unmarshal_Tstat, - r.marshal = (_marshal_fn_t)marshal_Tstat, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tstat), + .unmarshal_extrasize = checksize_Tstat, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tstat, + .marshal = (_marshal_fn_t)marshal_Tstat, }, [LIB9P_TYP_Rstat] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rstat), - r.unmarshal_extrasize = checksize_Rstat, - r.unmarshal = unmarshal_Rstat, - r.marshal = (_marshal_fn_t)marshal_Rstat, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rstat), + .unmarshal_extrasize = checksize_Rstat, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rstat, + .marshal = (_marshal_fn_t)marshal_Rstat, }, [LIB9P_TYP_Twstat] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Twstat), - r.unmarshal_extrasize = checksize_Twstat, - r.unmarshal = unmarshal_Twstat, - r.marshal = (_marshal_fn_t)marshal_Twstat, + .unmarshal_basesize = sizeof(struct lib9p_msg_Twstat), + .unmarshal_extrasize = checksize_Twstat, + .unmarshal = (_unmarshal_fn_t)unmarshal_Twstat, + .marshal = (_marshal_fn_t)marshal_Twstat, }, [LIB9P_TYP_Rwstat] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rwstat), - r.unmarshal_extrasize = checksize_Rwstat, - r.unmarshal = unmarshal_Rwstat, - r.marshal = (_marshal_fn_t)marshal_Rwstat, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rwstat), + .unmarshal_extrasize = checksize_Rwstat, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rwstat, + .marshal = (_marshal_fn_t)marshal_Rwstat, }, [LIB9P_TYP_Tsession] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tsession), - r.unmarshal_extrasize = checksize_Tsession, - r.unmarshal = unmarshal_Tsession, - r.marshal = (_marshal_fn_t)marshal_Tsession, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tsession), + .unmarshal_extrasize = checksize_Tsession, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tsession, + .marshal = (_marshal_fn_t)marshal_Tsession, }, [LIB9P_TYP_Rsession] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rsession), - r.unmarshal_extrasize = checksize_Rsession, - r.unmarshal = unmarshal_Rsession, - r.marshal = (_marshal_fn_t)marshal_Rsession, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rsession), + .unmarshal_extrasize = checksize_Rsession, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rsession, + .marshal = (_marshal_fn_t)marshal_Rsession, }, [LIB9P_TYP_Tsread] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tsread), - r.unmarshal_extrasize = checksize_Tsread, - r.unmarshal = unmarshal_Tsread, - r.marshal = (_marshal_fn_t)marshal_Tsread, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tsread), + .unmarshal_extrasize = checksize_Tsread, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tsread, + .marshal = (_marshal_fn_t)marshal_Tsread, }, [LIB9P_TYP_Rsread] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rsread), - r.unmarshal_extrasize = checksize_Rsread, - r.unmarshal = unmarshal_Rsread, - r.marshal = (_marshal_fn_t)marshal_Rsread, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rsread), + .unmarshal_extrasize = checksize_Rsread, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rsread, + .marshal = (_marshal_fn_t)marshal_Rsread, }, [LIB9P_TYP_Tswrite] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tswrite), - r.unmarshal_extrasize = checksize_Tswrite, - r.unmarshal = unmarshal_Tswrite, - r.marshal = (_marshal_fn_t)marshal_Tswrite, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tswrite), + .unmarshal_extrasize = checksize_Tswrite, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tswrite, + .marshal = (_marshal_fn_t)marshal_Tswrite, }, [LIB9P_TYP_Rswrite] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rswrite), - r.unmarshal_extrasize = checksize_Rswrite, - r.unmarshal = unmarshal_Rswrite, - r.marshal = (_marshal_fn_t)marshal_Rswrite, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rswrite), + .unmarshal_extrasize = checksize_Rswrite, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rswrite, + .marshal = (_marshal_fn_t)marshal_Rswrite, }, }}, [LIB9P_VER_9P2000_u] = { .msgs = { [LIB9P_TYP_Tversion] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tversion), - r.unmarshal_extrasize = checksize_Tversion, - r.unmarshal = unmarshal_Tversion, - r.marshal = (_marshal_fn_t)marshal_Tversion, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tversion), + .unmarshal_extrasize = checksize_Tversion, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tversion, + .marshal = (_marshal_fn_t)marshal_Tversion, }, [LIB9P_TYP_Rversion] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rversion), - r.unmarshal_extrasize = checksize_Rversion, - r.unmarshal = unmarshal_Rversion, - r.marshal = (_marshal_fn_t)marshal_Rversion, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rversion), + .unmarshal_extrasize = checksize_Rversion, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rversion, + .marshal = (_marshal_fn_t)marshal_Rversion, }, [LIB9P_TYP_Tauth] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tauth), - r.unmarshal_extrasize = checksize_Tauth, - r.unmarshal = unmarshal_Tauth, - r.marshal = (_marshal_fn_t)marshal_Tauth, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tauth), + .unmarshal_extrasize = checksize_Tauth, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tauth, + .marshal = (_marshal_fn_t)marshal_Tauth, }, [LIB9P_TYP_Rauth] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rauth), - r.unmarshal_extrasize = checksize_Rauth, - r.unmarshal = unmarshal_Rauth, - r.marshal = (_marshal_fn_t)marshal_Rauth, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rauth), + .unmarshal_extrasize = checksize_Rauth, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rauth, + .marshal = (_marshal_fn_t)marshal_Rauth, }, [LIB9P_TYP_Tattach] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tattach), - r.unmarshal_extrasize = checksize_Tattach, - r.unmarshal = unmarshal_Tattach, - r.marshal = (_marshal_fn_t)marshal_Tattach, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tattach), + .unmarshal_extrasize = checksize_Tattach, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tattach, + .marshal = (_marshal_fn_t)marshal_Tattach, }, [LIB9P_TYP_Rattach] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rattach), - r.unmarshal_extrasize = checksize_Rattach, - r.unmarshal = unmarshal_Rattach, - r.marshal = (_marshal_fn_t)marshal_Rattach, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rattach), + .unmarshal_extrasize = checksize_Rattach, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rattach, + .marshal = (_marshal_fn_t)marshal_Rattach, }, [LIB9P_TYP_Rerror] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rerror), - r.unmarshal_extrasize = checksize_Rerror, - r.unmarshal = unmarshal_Rerror, - r.marshal = (_marshal_fn_t)marshal_Rerror, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rerror), + .unmarshal_extrasize = checksize_Rerror, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rerror, + .marshal = (_marshal_fn_t)marshal_Rerror, }, [LIB9P_TYP_Tflush] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tflush), - r.unmarshal_extrasize = checksize_Tflush, - r.unmarshal = unmarshal_Tflush, - r.marshal = (_marshal_fn_t)marshal_Tflush, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tflush), + .unmarshal_extrasize = checksize_Tflush, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tflush, + .marshal = (_marshal_fn_t)marshal_Tflush, }, [LIB9P_TYP_Rflush] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rflush), - r.unmarshal_extrasize = checksize_Rflush, - r.unmarshal = unmarshal_Rflush, - r.marshal = (_marshal_fn_t)marshal_Rflush, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rflush), + .unmarshal_extrasize = checksize_Rflush, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rflush, + .marshal = (_marshal_fn_t)marshal_Rflush, }, [LIB9P_TYP_Twalk] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Twalk), - r.unmarshal_extrasize = checksize_Twalk, - r.unmarshal = unmarshal_Twalk, - r.marshal = (_marshal_fn_t)marshal_Twalk, + .unmarshal_basesize = sizeof(struct lib9p_msg_Twalk), + .unmarshal_extrasize = checksize_Twalk, + .unmarshal = (_unmarshal_fn_t)unmarshal_Twalk, + .marshal = (_marshal_fn_t)marshal_Twalk, }, [LIB9P_TYP_Rwalk] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rwalk), - r.unmarshal_extrasize = checksize_Rwalk, - r.unmarshal = unmarshal_Rwalk, - r.marshal = (_marshal_fn_t)marshal_Rwalk, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rwalk), + .unmarshal_extrasize = checksize_Rwalk, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rwalk, + .marshal = (_marshal_fn_t)marshal_Rwalk, }, [LIB9P_TYP_Topen] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Topen), - r.unmarshal_extrasize = checksize_Topen, - r.unmarshal = unmarshal_Topen, - r.marshal = (_marshal_fn_t)marshal_Topen, + .unmarshal_basesize = sizeof(struct lib9p_msg_Topen), + .unmarshal_extrasize = checksize_Topen, + .unmarshal = (_unmarshal_fn_t)unmarshal_Topen, + .marshal = (_marshal_fn_t)marshal_Topen, }, [LIB9P_TYP_Ropen] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Ropen), - r.unmarshal_extrasize = checksize_Ropen, - r.unmarshal = unmarshal_Ropen, - r.marshal = (_marshal_fn_t)marshal_Ropen, + .unmarshal_basesize = sizeof(struct lib9p_msg_Ropen), + .unmarshal_extrasize = checksize_Ropen, + .unmarshal = (_unmarshal_fn_t)unmarshal_Ropen, + .marshal = (_marshal_fn_t)marshal_Ropen, }, [LIB9P_TYP_Tcreate] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tcreate), - r.unmarshal_extrasize = checksize_Tcreate, - r.unmarshal = unmarshal_Tcreate, - r.marshal = (_marshal_fn_t)marshal_Tcreate, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tcreate), + .unmarshal_extrasize = checksize_Tcreate, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tcreate, + .marshal = (_marshal_fn_t)marshal_Tcreate, }, [LIB9P_TYP_Rcreate] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rcreate), - r.unmarshal_extrasize = checksize_Rcreate, - r.unmarshal = unmarshal_Rcreate, - r.marshal = (_marshal_fn_t)marshal_Rcreate, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rcreate), + .unmarshal_extrasize = checksize_Rcreate, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rcreate, + .marshal = (_marshal_fn_t)marshal_Rcreate, }, [LIB9P_TYP_Tread] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tread), - r.unmarshal_extrasize = checksize_Tread, - r.unmarshal = unmarshal_Tread, - r.marshal = (_marshal_fn_t)marshal_Tread, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tread), + .unmarshal_extrasize = checksize_Tread, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tread, + .marshal = (_marshal_fn_t)marshal_Tread, }, [LIB9P_TYP_Rread] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rread), - r.unmarshal_extrasize = checksize_Rread, - r.unmarshal = unmarshal_Rread, - r.marshal = (_marshal_fn_t)marshal_Rread, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rread), + .unmarshal_extrasize = checksize_Rread, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rread, + .marshal = (_marshal_fn_t)marshal_Rread, }, [LIB9P_TYP_Twrite] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Twrite), - r.unmarshal_extrasize = checksize_Twrite, - r.unmarshal = unmarshal_Twrite, - r.marshal = (_marshal_fn_t)marshal_Twrite, + .unmarshal_basesize = sizeof(struct lib9p_msg_Twrite), + .unmarshal_extrasize = checksize_Twrite, + .unmarshal = (_unmarshal_fn_t)unmarshal_Twrite, + .marshal = (_marshal_fn_t)marshal_Twrite, }, [LIB9P_TYP_Rwrite] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rwrite), - r.unmarshal_extrasize = checksize_Rwrite, - r.unmarshal = unmarshal_Rwrite, - r.marshal = (_marshal_fn_t)marshal_Rwrite, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rwrite), + .unmarshal_extrasize = checksize_Rwrite, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rwrite, + .marshal = (_marshal_fn_t)marshal_Rwrite, }, [LIB9P_TYP_Tclunk] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tclunk), - r.unmarshal_extrasize = checksize_Tclunk, - r.unmarshal = unmarshal_Tclunk, - r.marshal = (_marshal_fn_t)marshal_Tclunk, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tclunk), + .unmarshal_extrasize = checksize_Tclunk, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tclunk, + .marshal = (_marshal_fn_t)marshal_Tclunk, }, [LIB9P_TYP_Rclunk] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rclunk), - r.unmarshal_extrasize = checksize_Rclunk, - r.unmarshal = unmarshal_Rclunk, - r.marshal = (_marshal_fn_t)marshal_Rclunk, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rclunk), + .unmarshal_extrasize = checksize_Rclunk, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rclunk, + .marshal = (_marshal_fn_t)marshal_Rclunk, }, [LIB9P_TYP_Tremove] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tremove), - r.unmarshal_extrasize = checksize_Tremove, - r.unmarshal = unmarshal_Tremove, - r.marshal = (_marshal_fn_t)marshal_Tremove, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tremove), + .unmarshal_extrasize = checksize_Tremove, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tremove, + .marshal = (_marshal_fn_t)marshal_Tremove, }, [LIB9P_TYP_Rremove] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rremove), - r.unmarshal_extrasize = checksize_Rremove, - r.unmarshal = unmarshal_Rremove, - r.marshal = (_marshal_fn_t)marshal_Rremove, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rremove), + .unmarshal_extrasize = checksize_Rremove, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rremove, + .marshal = (_marshal_fn_t)marshal_Rremove, }, [LIB9P_TYP_Tstat] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Tstat), - r.unmarshal_extrasize = checksize_Tstat, - r.unmarshal = unmarshal_Tstat, - r.marshal = (_marshal_fn_t)marshal_Tstat, + .unmarshal_basesize = sizeof(struct lib9p_msg_Tstat), + .unmarshal_extrasize = checksize_Tstat, + .unmarshal = (_unmarshal_fn_t)unmarshal_Tstat, + .marshal = (_marshal_fn_t)marshal_Tstat, }, [LIB9P_TYP_Rstat] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rstat), - r.unmarshal_extrasize = checksize_Rstat, - r.unmarshal = unmarshal_Rstat, - r.marshal = (_marshal_fn_t)marshal_Rstat, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rstat), + .unmarshal_extrasize = checksize_Rstat, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rstat, + .marshal = (_marshal_fn_t)marshal_Rstat, }, [LIB9P_TYP_Twstat] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Twstat), - r.unmarshal_extrasize = checksize_Twstat, - r.unmarshal = unmarshal_Twstat, - r.marshal = (_marshal_fn_t)marshal_Twstat, + .unmarshal_basesize = sizeof(struct lib9p_msg_Twstat), + .unmarshal_extrasize = checksize_Twstat, + .unmarshal = (_unmarshal_fn_t)unmarshal_Twstat, + .marshal = (_marshal_fn_t)marshal_Twstat, }, [LIB9P_TYP_Rwstat] = { - r.unmarshal_basesize = sizeof(struct lib9p_msg_Rwstat), - r.unmarshal_extrasize = checksize_Rwstat, - r.unmarshal = unmarshal_Rwstat, - r.marshal = (_marshal_fn_t)marshal_Rwstat, + .unmarshal_basesize = sizeof(struct lib9p_msg_Rwstat), + .unmarshal_extrasize = checksize_Rwstat, + .unmarshal = (_unmarshal_fn_t)unmarshal_Rwstat, + .marshal = (_marshal_fn_t)marshal_Rwstat, }, }}, }; diff --git a/lib9p/types.gen b/lib9p/types.gen index 0de5068..48f8107 100755 --- a/lib9p/types.gen +++ b/lib9p/types.gen @@ -222,7 +222,7 @@ def gen_h(idprefix: str, versions: set[str], structs: list[Struct]) -> str: #ifndef {guard} #define {guard} -#include <stdint.h> +#include <stdint.h> /* for uint{{n}}_t types */ """ ret += f""" @@ -322,6 +322,9 @@ def gen_c(idprefix: str, versions: set[str], structs: list[Struct]) -> str: ret = f"""/* Generated by `{' '.join(sys.argv)}`. DO NOT EDIT! */ #include <stdbool.h> +#include <stddef.h> /* for size_t */ +#include <inttypes.h> /* for PRI* macros */ +#include <string.h> /* for memset() */ #include <lib9p/9p.h> @@ -390,20 +393,20 @@ static inline bool _checksize_list(struct _checksize_ctx *ctx, # this, but let's make it obvious. ret += "\n" ret += "\tuint32_t base_offset = ctx->net_offset;\n" - ret += "\tif (_checksize_4(ctx))\n" + ret += "\tif (checksize_4(ctx))\n" ret += "\t\treturn true;\n" ret += "\tuint32_t len = decode_u32le(&ctx->net_bytes[base_offset]);\n" - ret += "\treturn checksize_net(ctx, len) || checksize_host(ctx, len);\n" + ret += "\treturn _checksize_net(ctx, len) || _checksize_host(ctx, len);\n" ret += "}\n" case "s": # Add an extra nul-byte on the host, and validate # UTF-8 (also, similar optimization to "d"). ret += "\n" ret += "\tuint32_t base_offset = ctx->net_offset;\n" - ret += "\tif (_checksize_2(ctx))\n" + ret += "\tif (checksize_2(ctx))\n" ret += "\t\treturn true;\n" ret += "\tuint16_t len = decode_u16le(&ctx->net_bytes[base_offset]);\n" - ret += "\tif (checksize_net(ctx, len) || checksize_host(ctx, ((size_t)len)+1))\n" + ret += "\tif (_checksize_net(ctx, len) || _checksize_host(ctx, ((size_t)len)+1))\n" ret += "\t\treturn true;\n" ret += "\tif (!is_valid_utf8_without_nul(&ctx->net_bytes[base_offset+2], len))\n" ret += '\t\treturn lib9p_error(ctx->ctx, LINUX_EBADMSG, "message contains invalid UTF-8");\n' @@ -442,22 +445,22 @@ static inline bool _checksize_list(struct _checksize_ctx *ctx, ret += """ /* unmarshal_* ****************************************************************/ -static inline vold unmarshal_1(struct _unmarshal_ctx *ctx, uint8_t *out) { +static inline void unmarshal_1(struct _unmarshal_ctx *ctx, uint8_t *out) { *out = decode_u8le(&ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 1; } -static inline vold unmarshal_2(struct _unmarshal_ctx *ctx, uint16_t *out) { +static inline void unmarshal_2(struct _unmarshal_ctx *ctx, uint16_t *out) { *out = decode_u16le(&ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 2; } -static inline vold unmarshal_4(struct _unmarshal_ctx *ctx, uint32_t *out) { +static inline void unmarshal_4(struct _unmarshal_ctx *ctx, uint32_t *out) { *out = decode_u32le(&ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 4; } -static inline vold unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out) { +static inline void unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out) { *out = decode_u64le(&ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 8; } @@ -466,7 +469,7 @@ static inline vold unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out) { inline = " inline" if struct.msgid is None else "" argfn = used if struct.members else unused ret += "\n" - ret += f"static{inline} void unmarshal_{struct.name}(struct _unmarshal_ctx *{argfn('ctx')}, {c_typename(idprefix, struct)} *{argfn('out')}) {{\n" + ret += f"static{inline} void unmarshal_{struct.name}(struct _unmarshal_ctx *{argfn('ctx')}, {c_typename(idprefix, struct)} *out) {{\n" ret += "\tmemset(out, 0, sizeof(*out));\n" if struct.members: @@ -489,8 +492,8 @@ static inline vold unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out) { if member.cnt: if member.ver != struct_versions: ret += "{\n" - ret += f"{prefix}out->{member.name} = ctx->host_extra;\n" - ret += f"{prefix}ctx->host_extra += sizeof(out->{member.name}[0]) * out->{member.cnt};\n" + ret += f"{prefix}out->{member.name} = ctx->extra;\n" + ret += f"{prefix}ctx->extra += sizeof(out->{member.name}[0]) * out->{member.cnt};\n" ret += f"{prefix}for (typeof(out->{member.cnt}) i = 0; i < out->{member.cnt}; i++)\n" ret += f"{prefix}\tunmarshal_{member.typ.name}(ctx, &out->{member.name}[i]);\n" if member.ver != struct_versions: @@ -504,43 +507,43 @@ static inline vold unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out) { /* marshal_* ******************************************************************/ static inline bool _marshal_too_large(struct _marshal_ctx *ctx) { - lib9p_errorf(ctx->ctx, "%s too large to marshal into %s limit (limit=%"PRIu32")", + lib9p_errorf(ctx->ctx, LINUX_EMSGSIZE, "%s too large to marshal into %s limit (limit=%"PRIu32")", (ctx->net_bytes[4] % 2 == 0) ? "T-message" : "R-message", ctx->ctx->version ? "negotiated" : ((ctx->net_bytes[4] % 2 == 0) ? "client" : "server"), - ctx->ctx->max_msg_size)); - return true; + ctx->ctx->max_msg_size); + return true; } static inline bool marshal_1(struct _marshal_ctx *ctx, uint8_t *val) { - if (ctx->net_offset + 1 > ctx->max_msg_size) - return _marshal_too_large(ctx); - out_net_bytes[ctx->net_offset] = *val; + if (ctx->net_offset + 1 > ctx->ctx->max_msg_size) + return _marshal_too_large(ctx); + ctx->net_bytes[ctx->net_offset] = *val; ctx->net_offset += 1; - return false; + return false; } static inline bool marshal_2(struct _marshal_ctx *ctx, uint16_t *val) { - if (ctx->net_offset + 2 > ctx->max_msg_size) - return _marshal_too_large(ctx); - encode_u16le(*val, &out_net_bytes[ctx->net_offset]); + if (ctx->net_offset + 2 > ctx->ctx->max_msg_size) + return _marshal_too_large(ctx); + encode_u16le(*val, &ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 2; - return false; + return false; } static inline bool marshal_4(struct _marshal_ctx *ctx, uint32_t *val) { - if (ctx->net_offset + 4 > ctx->max_msg_size) + if (ctx->net_offset + 4 > ctx->ctx->max_msg_size) return true; - encode_u32le(*val, &out_net_bytes[ctx->net_offset]); + encode_u32le(*val, &ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 4; - return false; + return false; } static inline bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) { - if (ctx->net_offset + 8 > ctx->max_msg_size) + if (ctx->net_offset + 8 > ctx->ctx->max_msg_size) return true; - encode_u64le(*val, &out_net_bytes[ctx->net_offset]); + encode_u64le(*val, &ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 8; - return false; + return false; } """ for struct in structs: @@ -563,7 +566,7 @@ static inline bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) { ret += f"\n{prefix }({{" ret += f"\n{prefix2}\tbool err = false;" ret += f"\n{prefix2}\tfor (typeof(val->{member.cnt}) i = 0; i < val->{member.cnt} && !err; i++)" - ret += f"\n{prefix2}\t\terr = marshal_{member.typ.name}(ctx, &val->{member.name}[i]));" + ret += f"\n{prefix2}\t\terr = marshal_{member.typ.name}(ctx, &val->{member.name}[i]);" ret += f"\n{prefix2}\terr;" ret += f"\n{prefix2}}})" else: @@ -575,10 +578,10 @@ static inline bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) { def msg_entry(msg: Struct) -> str: ret = "" ret += f"\t\t[{idprefix.upper()}TYP_{msg.name}] = {{\n" - ret += f"\t\t\tr.unmarshal_basesize = sizeof({c_typename(idprefix, msg)}),\n" - ret += f"\t\t\tr.unmarshal_extrasize = checksize_{msg.name},\n" - ret += f"\t\t\tr.unmarshal = unmarshal_{msg.name},\n" - ret += f"\t\t\tr.marshal = (_marshal_fn_t)marshal_{msg.name},\n" + ret += f"\t\t\t.unmarshal_basesize = sizeof({c_typename(idprefix, msg)}),\n" + ret += f"\t\t\t.unmarshal_extrasize = checksize_{msg.name},\n" + ret += f"\t\t\t.unmarshal = (_unmarshal_fn_t)unmarshal_{msg.name},\n" + ret += f"\t\t\t.marshal = (_marshal_fn_t)marshal_{msg.name},\n" ret += "\t\t}" return ret diff --git a/libcr/coroutine.c b/libcr/coroutine.c index 0920f23..fd44acc 100644 --- a/libcr/coroutine.c +++ b/libcr/coroutine.c @@ -214,7 +214,7 @@ static void call_with_stack(void *stack, cr_fn_t fn, void *args) { static const uint8_t stack_pattern[] = {0x1e, 0x15, 0x16, 0x0a, 0xcc, 0x52, 0x7e, 0xb7}; #endif -static void inline assert_cid(cid_t cid) { +static inline void assert_cid(cid_t cid) { assert(cid > 0); assert(cid <= CONFIG_COROUTINE_NUM); #if CONFIG_COROUTINE_PROTECT_STACK @@ -233,13 +233,14 @@ static void inline assert_cid(cid_t cid) { assert(coroutine_table[(cid)-1].state opstate); \ } while (0) +cid_t coroutine_add(cr_fn_t fn, void *args) { + return coroutine_add_with_stack_size(CONFIG_COROUTINE_DEFAULT_STACK_SIZE, fn, args); +} + cid_t coroutine_add_with_stack_size(size_t stack_size, cr_fn_t fn, void *args) { static cid_t last_created = 0; cid_t parent = coroutine_running; - if (!stack_size) - stack_size = CONFIG_COROUTINE_DEFAULT_STACK_SIZE; - if (parent) assert_cid_state(parent, == CR_RUNNING); assert(stack_size); @@ -295,19 +296,19 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, cr_fn_t fn, void *args) { void coroutine_main(void) { debugf("coroutine_main()\n"); - bool ran; + bool ran = false; for (coroutine_running = 1;; coroutine_running = (coroutine_running%CONFIG_COROUTINE_NUM)+1) { if (coroutine_running == 1) ran = false; struct coroutine *cr = &coroutine_table[coroutine_running-1]; if (cr->state == CR_RUNNABLE) { debugf("running cid=%zu...\n", coroutine_running); - ran = true; cr->state = CR_RUNNING; if (!setjmp(coroutine_main_env)) { /* point=b */ longjmp(cr->env, 1); /* jump to point=c */ assert(false); /* should cr_exit() instead of returning */ } + ran = true; assert_cid_state(coroutine_running, != CR_RUNNING); if (cr->state == CR_NONE) { #if CONFIG_COROUTINE_MEASURE_STACK @@ -386,8 +387,10 @@ void cr_unpause_from_sighandler(cid_t cid) { switch (coroutine_table[cid-1].state) { case CR_RUNNING: coroutine_table[cid-1].sig_unpause = true; + break; case CR_PAUSED: coroutine_table[cid-1].state = CR_RUNNABLE; + break; default: assert(false); } diff --git a/libcr/include/libcr/coroutine.h b/libcr/include/libcr/coroutine.h index 5c2d608..47467bd 100644 --- a/libcr/include/libcr/coroutine.h +++ b/libcr/include/libcr/coroutine.h @@ -90,7 +90,7 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, cr_fn_t fn, void *args); * Like coroutine_add_with_stack_size(), but uses a default stack size so * you don't need to think about it. */ -#define coroutine_add(fn, args) coroutine_add_with_stack_size(0, fn, args) +cid_t coroutine_add(cr_fn_t fn, void *args); /** * The main scheduler loop. diff --git a/libcr_ipc/sema.c b/libcr_ipc/sema.c index 5f489aa..a3b2ca0 100644 --- a/libcr_ipc/sema.c +++ b/libcr_ipc/sema.c @@ -36,7 +36,10 @@ static inline bool drain(cr_sema_t *sema) { cr_unpause(sema->head->val); sema->head = sema->head->next; if (!sema->head) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers" sema->tail = &sema->head; +#pragma GCC diagnostic pop } } sema->locked = false; diff --git a/libnetio/netio.h b/libnetio/include/libnetio/netio.h index 8497330..9383c54 100644 --- a/libnetio/netio.h +++ b/libnetio/include/libnetio/netio.h @@ -1,8 +1,10 @@ #ifndef _NETIO_H_ #define _NETIO_H_ -#include <stdbool.h> /* for bool */ -#include <stdint.h> /* for size_t, ssize_t, uint16_t */ +#include <stdbool.h> /* for bool */ +#include <stdint.h> /* for uint16_t */ +#include <stddef.h> /* for size_t */ +#include <sys/types.h> /* for ssize_t */ /** Return socket-fd on success, -errno on error. */ int netio_listen(uint16_t port); diff --git a/libnetio/netio_posix.c b/libnetio/netio_posix.c index 133b226..2cc6be4 100644 --- a/libnetio/netio_posix.c +++ b/libnetio/netio_posix.c @@ -134,7 +134,7 @@ int netio_accept(int sock) { * while waiting for us to accept(). */ for (;;) { #if CONFIG_NETIO_ISLINUX - cr_sema_wait(&sock->accept_waiters); + cr_sema_wait(&socket_table[sock].accept_waiters); #endif int conn = accept(socket_table[sock].fd, NULL, NULL); if (conn < 0) { diff --git a/libusb/usb_common.c b/libusb/usb_common.c index 5485d71..7effcec 100644 --- a/libusb/usb_common.c +++ b/libusb/usb_common.c @@ -5,6 +5,7 @@ */ #include <stdint.h> /* for uint{n}_t types */ +#include <stddef.h> /* for size_t */ #include <string.h> /* memcpy(newlib) */ #include <assert.h> /* for assert(newlib) */ #include <stdlib.h> /* for malloc(pico_malloc), realloc(pico_malloc), reallocarray(pico_malloc) */ diff --git a/notes.md b/notes.md new file mode 100644 index 0000000..344b1fa --- /dev/null +++ b/notes.md @@ -0,0 +1,50 @@ + +Which file to include: + +> The <stdint.h> header is a subset of the <inttypes.h> header + +|----------------------------------------|-----------------------------------|--------------------------------| +| C INTS | | | +| `{CHAR,SHRT,INT,LONG,LLONG}_{MIN,MAX}` | `<limits.h>` | | +| `U{CHAR,SHRT,INT,LONG,LLONG}_MAX` | `<limits.h>` | | +|----------------------------------------|-----------------------------------|--------------------------------| +| C SIZED INTS | | | +| `(C u)int{n}_t` (and `_{MIN,MAX}`) | `<stdint.h>` | exact | +| `(u)int_least{n}_t` (and `_{MIN,MAX}`) | `<stdint.h>` | type may be more than `n` bits | +| `(u)int_fast{n}_t` (and `_{MIN,MAX}`) | `<stdint.h>` | type may be more than `n` bits | +| `(u)intptr_t` (and `_{MIN,MAX}`) | `<stdint.h>` | | +| `(u)intmax_t` (and `_{MIN,MAX}`) | `<stdint.h>` | | +| `PRI*` | `<inttypes.h>` | | +| `SCN*` | `<inttypes.h>` | | +|----------------------------------------|-----------------------------------|--------------------------------| +| C ADDRESS INTS | | | +| `ptrdiff_t` | `<stddef.h>` | | +| `PTRDIFF_{MIN,MAX}` | `<stdint.h>` | | +| `size_t` | `<stddef.h>` (or `<sys/types.h>`) | | +| `SIZE_MAX` | `<stdint.h>` | | +|----------------------------------------|-----------------------------------|--------------------------------| +| C WCHAR INTS | | | +| `wchar_t` | `<stddef.h>` | | +| `WCHAR_{MIN,MAX}` | `<stdint.h>` | | +| `wint_t` | `<wchar.h>` | | +| `WINT_{MIN,MAX}` | `<stdint.h>` | | +|----------------------------------------|-----------------------------------|--------------------------------| +| POSIX INTS | | | +| `sig_atomic_t` | `<signal.h>` | | +| `SIG_ATOMIC_{MIN,MAX}` | `<stdint.h>` | | +| `mode_t` | `<sys/types.h>` | unsigned | +| `dev_t` | `<sys/types.h>` | unsigned | +| `nlink_t` | `<sys/types.h>` | unsigned | +| `{u,g,}id_t` | `<sys/types.h>` | unsigned | +| `blkcnt_t` | `<sys/types.h>` | signed | +| `off_t` | `<sys/types.h>` | signed | +| `fsblkcnt_t` | `<sys/types.h>` | unsigned | +| `fsfilecnt_t` | `<sys/types.h>` | unsigned | +| `ino_t` | `<sys/types.h>` | unsigned | +| `blksize_t` | `<sys/types.h>` | signed | +| `pid_t` | `<sys/types.h>` | signed | +| `ssize_t` | `<sys/types.h>` | signed | +| `SSIZE_MAX` | `<limits.h>` | | +| `suseconds_t` | `<sys/types.h>` | signed | +| `clock_t` | `<sys/types.h>` | could be float | +| `time_t` | `<sys/types.h>` | signed | |