From c755f88f8c6862ef1497375df2d09454c99a0632 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Fri, 13 Dec 2024 17:36:53 -0500 Subject: Gather macros into libmisc/macro.h --- cmd/sbc_harness/main.c | 6 +- cmd/sbc_harness/usb_keyboard.c | 9 +- cmd/srv9p/main.c | 5 +- lib9p/9p.generated.c | 282 +++++++++++++++++++------------------- lib9p/idl.gen | 38 ++--- lib9p/internal.h | 27 ++-- lib9p/map.h | 14 +- lib9p_util/static.c | 10 +- libcr/coroutine.c | 65 ++++----- libhw/host_alarmclock.c | 4 +- libhw/host_net.c | 5 +- libhw/rp2040_hwtimer.c | 2 +- libhw/w5500.c | 9 +- libmisc/CMakeLists.txt | 1 + libmisc/include/libmisc/log.h | 14 +- libmisc/include/libmisc/macro.h | 55 ++++++++ libmisc/include/libmisc/private.h | 29 +--- libmisc/tests/test_assert.c | 14 +- 18 files changed, 297 insertions(+), 292 deletions(-) create mode 100644 libmisc/include/libmisc/macro.h diff --git a/cmd/sbc_harness/main.c b/cmd/sbc_harness/main.c index bbefe92..00f1c4a 100644 --- a/cmd/sbc_harness/main.c +++ b/cmd/sbc_harness/main.c @@ -25,8 +25,6 @@ #include "config.h" -#define ARRAY_LEN(arr) (sizeof(arr)/sizeof((arr)[0])) - static COROUTINE hello_world_cr(void *_chan) { const char *msg = "Hello world!\n"; usb_keyboard_rpc_t *chan = _chan; @@ -106,8 +104,8 @@ COROUTINE init_cr(void *) { flash_id24[0], flash_id24[1], flash_id24[2], }})); - static_assert(sizeof(flash_id64)*2 == ARRAY_LEN(globals.usb_serial)); - for (size_t i = 0; i < ARRAY_LEN(globals.usb_serial); i++) + static_assert(sizeof(flash_id64)*2 == LM_ARRAY_LEN(globals.usb_serial)); + for (size_t i = 0; i < LM_ARRAY_LEN(globals.usb_serial); i++) globals.usb_serial[i] = hexdig[(flash_id64 >> ((sizeof(flash_id64)*8)-((i+1)*4))) & 0xF]; usb_common_earlyinit(globals.usb_serial, sizeof(globals.usb_serial)); usb_keyboard_init(); diff --git a/cmd/sbc_harness/usb_keyboard.c b/cmd/sbc_harness/usb_keyboard.c index f4816c1..b781d4d 100644 --- a/cmd/sbc_harness/usb_keyboard.c +++ b/cmd/sbc_harness/usb_keyboard.c @@ -8,11 +8,10 @@ #include /* for TUD_ENDPOINT_IN */ #include +#include #include "usb_keyboard.h" -#define UNUSED(name) - /** * A USB-HID "Report Descriptor" (see USB-HID 1.11 ยง6.2.2 "Report * Descriptor") describing a keyboard. @@ -108,7 +107,11 @@ 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 UNUSED(instance), uint8_t UNUSED(report_id), hid_report_type_t UNUSED(report_type), uint8_t const *UNUSED(buffer), uint16_t UNUSED(bufsize)) +void tud_hid_set_report_cb(uint8_t LM_UNUSED(instance), + uint8_t LM_UNUSED(report_id), + hid_report_type_t LM_UNUSED(report_type), + uint8_t const *LM_UNUSED(buffer), + uint16_t LM_UNUSED(bufsize)) { // TODO not implemented } diff --git a/cmd/srv9p/main.c b/cmd/srv9p/main.c index 394bf84..b5cb122 100644 --- a/cmd/srv9p/main.c +++ b/cmd/srv9p/main.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "static.h" @@ -25,8 +26,6 @@ /* implementation *************************************************************/ -#define UNUSED(name) - /* file tree ******************************************************************/ #define FILE_COMMON(NAME) { \ @@ -79,7 +78,7 @@ static struct util9p_static_dir root = { }, }; -static implements_lib9p_srv_file *get_root(struct lib9p_srv_ctx *UNUSED(ctx), char *UNUSED(treename)) { +static implements_lib9p_srv_file *get_root(struct lib9p_srv_ctx *LM_UNUSED(ctx), char *LM_UNUSED(treename)) { return &root; } diff --git a/lib9p/9p.generated.c b/lib9p/9p.generated.c index badeb95..d3dc36a 100644 --- a/lib9p/9p.generated.c +++ b/lib9p/9p.generated.c @@ -36,7 +36,7 @@ const char *lib9p_version_str(enum lib9p_version ver) { /* validate_* *****************************************************************/ -ALWAYS_INLINE static bool _validate_size_net(struct _validate_ctx *ctx, uint32_t n) { +LM_ALWAYS_INLINE static bool _validate_size_net(struct _validate_ctx *ctx, uint32_t n) { if (__builtin_add_overflow(ctx->net_offset, n, &ctx->net_offset)) /* If needed-net-size overflowed uint32_t, then * there's no way that actual-net-size will live up to @@ -47,7 +47,7 @@ ALWAYS_INLINE static bool _validate_size_net(struct _validate_ctx *ctx, uint32_t return false; } -ALWAYS_INLINE static bool _validate_size_host(struct _validate_ctx *ctx, size_t n) { +LM_ALWAYS_INLINE static bool _validate_size_host(struct _validate_ctx *ctx, size_t n) { if (__builtin_add_overflow(ctx->host_extra, n, &ctx->host_extra)) /* If needed-host-size overflowed size_t, then there's * no way that actual-net-size will live up to @@ -56,7 +56,7 @@ ALWAYS_INLINE static bool _validate_size_host(struct _validate_ctx *ctx, size_t return false; } -ALWAYS_INLINE static bool _validate_list(struct _validate_ctx *ctx, +LM_ALWAYS_INLINE static bool _validate_list(struct _validate_ctx *ctx, size_t cnt, _validate_fn_t item_fn, size_t item_host_size) { for (size_t i = 0; i < cnt; i++) @@ -71,15 +71,15 @@ ALWAYS_INLINE static bool _validate_list(struct _validate_ctx *ctx, #define validate_8(ctx) _validate_size_net(ctx, 8) #if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u -ALWAYS_INLINE static bool validate_tag(struct _validate_ctx *ctx) { +LM_ALWAYS_INLINE static bool validate_tag(struct _validate_ctx *ctx) { return validate_2(ctx); } -ALWAYS_INLINE static bool validate_fid(struct _validate_ctx *ctx) { +LM_ALWAYS_INLINE static bool validate_fid(struct _validate_ctx *ctx) { return validate_4(ctx); } -ALWAYS_INLINE static bool validate_d(struct _validate_ctx *ctx) { +LM_ALWAYS_INLINE static bool validate_d(struct _validate_ctx *ctx) { uint32_t base_offset = ctx->net_offset; if (validate_4(ctx)) return true; @@ -87,7 +87,7 @@ ALWAYS_INLINE static bool validate_d(struct _validate_ctx *ctx) { return _validate_size_net(ctx, len) || _validate_size_host(ctx, len); } -ALWAYS_INLINE static bool validate_s(struct _validate_ctx *ctx) { +LM_ALWAYS_INLINE static bool validate_s(struct _validate_ctx *ctx) { uint32_t base_offset = ctx->net_offset; if (validate_2(ctx)) return true; @@ -110,7 +110,7 @@ static const lib9p_dm_t dm_masks[LIB9P_VER_NUM] = { [LIB9P_VER_9P2000_u] = 0b11101100101111000000000111111111, #endif /* CONFIG_9P_ENABLE_9P2000_u */ }; -ALWAYS_INLINE static bool validate_dm(struct _validate_ctx *ctx) { +LM_ALWAYS_INLINE static bool validate_dm(struct _validate_ctx *ctx) { if (validate_4(ctx)) return true; lib9p_dm_t mask = dm_masks[ctx->ctx->version]; @@ -131,7 +131,7 @@ static const lib9p_qt_t qt_masks[LIB9P_VER_NUM] = { [LIB9P_VER_9P2000_u] = 0b11101110, #endif /* CONFIG_9P_ENABLE_9P2000_u */ }; -ALWAYS_INLINE static bool validate_qt(struct _validate_ctx *ctx) { +LM_ALWAYS_INLINE static bool validate_qt(struct _validate_ctx *ctx) { if (validate_1(ctx)) return true; lib9p_qt_t mask = qt_masks[ctx->ctx->version]; @@ -141,7 +141,7 @@ ALWAYS_INLINE static bool validate_qt(struct _validate_ctx *ctx) { return false; } -ALWAYS_INLINE static bool validate_qid(struct _validate_ctx *ctx) { +LM_ALWAYS_INLINE static bool validate_qid(struct _validate_ctx *ctx) { return false || validate_qt(ctx) || validate_4(ctx) @@ -149,7 +149,7 @@ ALWAYS_INLINE static bool validate_qid(struct _validate_ctx *ctx) { ; } -ALWAYS_INLINE static bool validate_stat(struct _validate_ctx *ctx) { +LM_ALWAYS_INLINE static bool validate_stat(struct _validate_ctx *ctx) { uint16_t stat_size; uint32_t _kern_type_offset; return false @@ -187,7 +187,7 @@ static const lib9p_o_t o_masks[LIB9P_VER_NUM] = { [LIB9P_VER_9P2000_u] = 0b01010011, #endif /* CONFIG_9P_ENABLE_9P2000_u */ }; -ALWAYS_INLINE static bool validate_o(struct _validate_ctx *ctx) { +LM_ALWAYS_INLINE static bool validate_o(struct _validate_ctx *ctx) { if (validate_1(ctx)) return true; lib9p_o_t mask = o_masks[ctx->ctx->version]; @@ -197,7 +197,7 @@ ALWAYS_INLINE static bool validate_o(struct _validate_ctx *ctx) { return false; } -FLATTEN static bool validate_Tversion(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Tversion(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -214,7 +214,7 @@ FLATTEN static bool validate_Tversion(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Rversion(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Rversion(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -231,7 +231,7 @@ FLATTEN static bool validate_Rversion(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Tauth(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Tauth(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -252,7 +252,7 @@ FLATTEN static bool validate_Tauth(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Rauth(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Rauth(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -268,7 +268,7 @@ FLATTEN static bool validate_Rauth(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Tattach(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Tattach(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -290,7 +290,7 @@ FLATTEN static bool validate_Tattach(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Rattach(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Rattach(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -306,7 +306,7 @@ FLATTEN static bool validate_Rattach(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Rerror(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Rerror(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -325,7 +325,7 @@ FLATTEN static bool validate_Rerror(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Tflush(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Tflush(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -341,7 +341,7 @@ FLATTEN static bool validate_Tflush(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Rflush(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Rflush(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -356,7 +356,7 @@ FLATTEN static bool validate_Rflush(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Twalk(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Twalk(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint16_t nwname; @@ -378,7 +378,7 @@ FLATTEN static bool validate_Twalk(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Rwalk(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Rwalk(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint16_t nwqid; @@ -398,7 +398,7 @@ FLATTEN static bool validate_Rwalk(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Topen(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Topen(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -415,7 +415,7 @@ FLATTEN static bool validate_Topen(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Ropen(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Ropen(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -432,7 +432,7 @@ FLATTEN static bool validate_Ropen(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Tcreate(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Tcreate(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -451,7 +451,7 @@ FLATTEN static bool validate_Tcreate(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Rcreate(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Rcreate(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -468,7 +468,7 @@ FLATTEN static bool validate_Rcreate(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Tread(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Tread(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -486,7 +486,7 @@ FLATTEN static bool validate_Tread(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Rread(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Rread(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -502,7 +502,7 @@ FLATTEN static bool validate_Rread(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Twrite(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Twrite(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -520,7 +520,7 @@ FLATTEN static bool validate_Twrite(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Rwrite(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Rwrite(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -536,7 +536,7 @@ FLATTEN static bool validate_Rwrite(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Tclunk(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Tclunk(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -552,7 +552,7 @@ FLATTEN static bool validate_Tclunk(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Rclunk(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Rclunk(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -567,7 +567,7 @@ FLATTEN static bool validate_Rclunk(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Tremove(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Tremove(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -583,7 +583,7 @@ FLATTEN static bool validate_Tremove(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Rremove(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Rremove(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -598,7 +598,7 @@ FLATTEN static bool validate_Rremove(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Tstat(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Tstat(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -614,7 +614,7 @@ FLATTEN static bool validate_Tstat(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Rstat(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Rstat(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint16_t nstat; @@ -635,7 +635,7 @@ FLATTEN static bool validate_Rstat(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Twstat(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Twstat(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint16_t nstat; @@ -657,7 +657,7 @@ FLATTEN static bool validate_Twstat(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Rwstat(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Rwstat(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -674,7 +674,7 @@ FLATTEN static bool validate_Rwstat(struct _validate_ctx *ctx) { #endif /* CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u */ #if CONFIG_9P_ENABLE_9P2000_e -FLATTEN static bool validate_Tsession(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Tsession(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -690,7 +690,7 @@ FLATTEN static bool validate_Tsession(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Rsession(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Rsession(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -705,7 +705,7 @@ FLATTEN static bool validate_Rsession(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Tsread(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Tsread(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -723,7 +723,7 @@ FLATTEN static bool validate_Tsread(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Rsread(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Rsread(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -739,7 +739,7 @@ FLATTEN static bool validate_Rsread(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Tswrite(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Tswrite(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -758,7 +758,7 @@ FLATTEN static bool validate_Tswrite(struct _validate_ctx *ctx) { ; } -FLATTEN static bool validate_Rswrite(struct _validate_ctx *ctx) { +LM_FLATTEN static bool validate_Rswrite(struct _validate_ctx *ctx) { uint32_t size; uint8_t typ; uint32_t _size_offset; @@ -777,36 +777,36 @@ FLATTEN static bool validate_Rswrite(struct _validate_ctx *ctx) { /* unmarshal_* ****************************************************************/ -ALWAYS_INLINE static void unmarshal_1(struct _unmarshal_ctx *ctx, uint8_t *out) { +LM_ALWAYS_INLINE static void unmarshal_1(struct _unmarshal_ctx *ctx, uint8_t *out) { *out = decode_u8le(&ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 1; } -ALWAYS_INLINE static void unmarshal_2(struct _unmarshal_ctx *ctx, uint16_t *out) { +LM_ALWAYS_INLINE static void unmarshal_2(struct _unmarshal_ctx *ctx, uint16_t *out) { *out = decode_u16le(&ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 2; } -ALWAYS_INLINE static void unmarshal_4(struct _unmarshal_ctx *ctx, uint32_t *out) { +LM_ALWAYS_INLINE static void unmarshal_4(struct _unmarshal_ctx *ctx, uint32_t *out) { *out = decode_u32le(&ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 4; } -ALWAYS_INLINE static void unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out) { +LM_ALWAYS_INLINE static void unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out) { *out = decode_u64le(&ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 8; } #if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u -ALWAYS_INLINE static void unmarshal_tag(struct _unmarshal_ctx *ctx, lib9p_tag_t *out) { +LM_ALWAYS_INLINE static void unmarshal_tag(struct _unmarshal_ctx *ctx, lib9p_tag_t *out) { unmarshal_2(ctx, (uint16_t *)out); } -ALWAYS_INLINE static void unmarshal_fid(struct _unmarshal_ctx *ctx, lib9p_fid_t *out) { +LM_ALWAYS_INLINE static void unmarshal_fid(struct _unmarshal_ctx *ctx, lib9p_fid_t *out) { unmarshal_4(ctx, (uint32_t *)out); } -ALWAYS_INLINE static void unmarshal_d(struct _unmarshal_ctx *ctx, struct lib9p_d *out) { +LM_ALWAYS_INLINE static void unmarshal_d(struct _unmarshal_ctx *ctx, struct lib9p_d *out) { memset(out, 0, sizeof(*out)); unmarshal_4(ctx, &out->len); out->dat = ctx->extra; @@ -815,7 +815,7 @@ ALWAYS_INLINE static void unmarshal_d(struct _unmarshal_ctx *ctx, struct lib9p_d unmarshal_1(ctx, (uint8_t *)&out->dat[i]); } -ALWAYS_INLINE static void unmarshal_s(struct _unmarshal_ctx *ctx, struct lib9p_s *out) { +LM_ALWAYS_INLINE static void unmarshal_s(struct _unmarshal_ctx *ctx, struct lib9p_s *out) { memset(out, 0, sizeof(*out)); unmarshal_2(ctx, &out->len); out->utf8 = ctx->extra; @@ -826,22 +826,22 @@ ALWAYS_INLINE static void unmarshal_s(struct _unmarshal_ctx *ctx, struct lib9p_s out->utf8[out->len] = '\0'; } -ALWAYS_INLINE static void unmarshal_dm(struct _unmarshal_ctx *ctx, lib9p_dm_t *out) { +LM_ALWAYS_INLINE static void unmarshal_dm(struct _unmarshal_ctx *ctx, lib9p_dm_t *out) { unmarshal_4(ctx, (uint32_t *)out); } -ALWAYS_INLINE static void unmarshal_qt(struct _unmarshal_ctx *ctx, lib9p_qt_t *out) { +LM_ALWAYS_INLINE static void unmarshal_qt(struct _unmarshal_ctx *ctx, lib9p_qt_t *out) { unmarshal_1(ctx, (uint8_t *)out); } -ALWAYS_INLINE static void unmarshal_qid(struct _unmarshal_ctx *ctx, struct lib9p_qid *out) { +LM_ALWAYS_INLINE static void unmarshal_qid(struct _unmarshal_ctx *ctx, struct lib9p_qid *out) { memset(out, 0, sizeof(*out)); unmarshal_qt(ctx, &out->type); unmarshal_4(ctx, &out->vers); unmarshal_8(ctx, &out->path); } -ALWAYS_INLINE static void unmarshal_stat(struct _unmarshal_ctx *ctx, struct lib9p_stat *out) { +LM_ALWAYS_INLINE static void unmarshal_stat(struct _unmarshal_ctx *ctx, struct lib9p_stat *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 2; unmarshal_2(ctx, &out->kern_type); @@ -863,11 +863,11 @@ ALWAYS_INLINE static void unmarshal_stat(struct _unmarshal_ctx *ctx, struct lib9 #endif /* CONFIG_9P_ENABLE_9P2000_u */ } -ALWAYS_INLINE static void unmarshal_o(struct _unmarshal_ctx *ctx, lib9p_o_t *out) { +LM_ALWAYS_INLINE static void unmarshal_o(struct _unmarshal_ctx *ctx, lib9p_o_t *out) { unmarshal_1(ctx, (uint8_t *)out); } -FLATTEN static void unmarshal_Tversion(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tversion *out) { +LM_FLATTEN static void unmarshal_Tversion(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tversion *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -876,7 +876,7 @@ FLATTEN static void unmarshal_Tversion(struct _unmarshal_ctx *ctx, struct lib9p_ unmarshal_s(ctx, &out->version); } -FLATTEN static void unmarshal_Rversion(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rversion *out) { +LM_FLATTEN static void unmarshal_Rversion(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rversion *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -885,7 +885,7 @@ FLATTEN static void unmarshal_Rversion(struct _unmarshal_ctx *ctx, struct lib9p_ unmarshal_s(ctx, &out->version); } -FLATTEN static void unmarshal_Tauth(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tauth *out) { +LM_FLATTEN static void unmarshal_Tauth(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tauth *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -898,7 +898,7 @@ FLATTEN static void unmarshal_Tauth(struct _unmarshal_ctx *ctx, struct lib9p_msg #endif /* CONFIG_9P_ENABLE_9P2000_u */ } -FLATTEN static void unmarshal_Rauth(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rauth *out) { +LM_FLATTEN static void unmarshal_Rauth(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rauth *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -906,7 +906,7 @@ FLATTEN static void unmarshal_Rauth(struct _unmarshal_ctx *ctx, struct lib9p_msg unmarshal_qid(ctx, &out->aqid); } -FLATTEN static void unmarshal_Tattach(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tattach *out) { +LM_FLATTEN static void unmarshal_Tattach(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tattach *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -920,7 +920,7 @@ FLATTEN static void unmarshal_Tattach(struct _unmarshal_ctx *ctx, struct lib9p_m #endif /* CONFIG_9P_ENABLE_9P2000_u */ } -FLATTEN static void unmarshal_Rattach(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rattach *out) { +LM_FLATTEN static void unmarshal_Rattach(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rattach *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -928,7 +928,7 @@ FLATTEN static void unmarshal_Rattach(struct _unmarshal_ctx *ctx, struct lib9p_m unmarshal_qid(ctx, &out->qid); } -FLATTEN static void unmarshal_Rerror(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rerror *out) { +LM_FLATTEN static void unmarshal_Rerror(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rerror *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -939,7 +939,7 @@ FLATTEN static void unmarshal_Rerror(struct _unmarshal_ctx *ctx, struct lib9p_ms #endif /* CONFIG_9P_ENABLE_9P2000_u */ } -FLATTEN static void unmarshal_Tflush(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tflush *out) { +LM_FLATTEN static void unmarshal_Tflush(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tflush *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -947,14 +947,14 @@ FLATTEN static void unmarshal_Tflush(struct _unmarshal_ctx *ctx, struct lib9p_ms unmarshal_2(ctx, &out->oldtag); } -FLATTEN static void unmarshal_Rflush(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rflush *out) { +LM_FLATTEN static void unmarshal_Rflush(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rflush *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; unmarshal_tag(ctx, &out->tag); } -FLATTEN static void unmarshal_Twalk(struct _unmarshal_ctx *ctx, struct lib9p_msg_Twalk *out) { +LM_FLATTEN static void unmarshal_Twalk(struct _unmarshal_ctx *ctx, struct lib9p_msg_Twalk *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -968,7 +968,7 @@ FLATTEN static void unmarshal_Twalk(struct _unmarshal_ctx *ctx, struct lib9p_msg unmarshal_s(ctx, &out->wname[i]); } -FLATTEN static void unmarshal_Rwalk(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rwalk *out) { +LM_FLATTEN static void unmarshal_Rwalk(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rwalk *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -980,7 +980,7 @@ FLATTEN static void unmarshal_Rwalk(struct _unmarshal_ctx *ctx, struct lib9p_msg unmarshal_qid(ctx, &out->wqid[i]); } -FLATTEN static void unmarshal_Topen(struct _unmarshal_ctx *ctx, struct lib9p_msg_Topen *out) { +LM_FLATTEN static void unmarshal_Topen(struct _unmarshal_ctx *ctx, struct lib9p_msg_Topen *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -989,7 +989,7 @@ FLATTEN static void unmarshal_Topen(struct _unmarshal_ctx *ctx, struct lib9p_msg unmarshal_o(ctx, &out->mode); } -FLATTEN static void unmarshal_Ropen(struct _unmarshal_ctx *ctx, struct lib9p_msg_Ropen *out) { +LM_FLATTEN static void unmarshal_Ropen(struct _unmarshal_ctx *ctx, struct lib9p_msg_Ropen *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -998,7 +998,7 @@ FLATTEN static void unmarshal_Ropen(struct _unmarshal_ctx *ctx, struct lib9p_msg unmarshal_4(ctx, &out->iounit); } -FLATTEN static void unmarshal_Tcreate(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tcreate *out) { +LM_FLATTEN static void unmarshal_Tcreate(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tcreate *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -1009,7 +1009,7 @@ FLATTEN static void unmarshal_Tcreate(struct _unmarshal_ctx *ctx, struct lib9p_m unmarshal_o(ctx, &out->mode); } -FLATTEN static void unmarshal_Rcreate(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rcreate *out) { +LM_FLATTEN static void unmarshal_Rcreate(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rcreate *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -1018,7 +1018,7 @@ FLATTEN static void unmarshal_Rcreate(struct _unmarshal_ctx *ctx, struct lib9p_m unmarshal_4(ctx, &out->iounit); } -FLATTEN static void unmarshal_Tread(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tread *out) { +LM_FLATTEN static void unmarshal_Tread(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tread *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -1028,7 +1028,7 @@ FLATTEN static void unmarshal_Tread(struct _unmarshal_ctx *ctx, struct lib9p_msg unmarshal_4(ctx, &out->count); } -FLATTEN static void unmarshal_Rread(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rread *out) { +LM_FLATTEN static void unmarshal_Rread(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rread *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -1036,7 +1036,7 @@ FLATTEN static void unmarshal_Rread(struct _unmarshal_ctx *ctx, struct lib9p_msg unmarshal_d(ctx, &out->data); } -FLATTEN static void unmarshal_Twrite(struct _unmarshal_ctx *ctx, struct lib9p_msg_Twrite *out) { +LM_FLATTEN static void unmarshal_Twrite(struct _unmarshal_ctx *ctx, struct lib9p_msg_Twrite *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -1046,7 +1046,7 @@ FLATTEN static void unmarshal_Twrite(struct _unmarshal_ctx *ctx, struct lib9p_ms unmarshal_d(ctx, &out->data); } -FLATTEN static void unmarshal_Rwrite(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rwrite *out) { +LM_FLATTEN static void unmarshal_Rwrite(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rwrite *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -1054,7 +1054,7 @@ FLATTEN static void unmarshal_Rwrite(struct _unmarshal_ctx *ctx, struct lib9p_ms unmarshal_4(ctx, &out->count); } -FLATTEN static void unmarshal_Tclunk(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tclunk *out) { +LM_FLATTEN static void unmarshal_Tclunk(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tclunk *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -1062,14 +1062,14 @@ FLATTEN static void unmarshal_Tclunk(struct _unmarshal_ctx *ctx, struct lib9p_ms unmarshal_fid(ctx, &out->fid); } -FLATTEN static void unmarshal_Rclunk(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rclunk *out) { +LM_FLATTEN static void unmarshal_Rclunk(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rclunk *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; unmarshal_tag(ctx, &out->tag); } -FLATTEN static void unmarshal_Tremove(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tremove *out) { +LM_FLATTEN static void unmarshal_Tremove(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tremove *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -1077,14 +1077,14 @@ FLATTEN static void unmarshal_Tremove(struct _unmarshal_ctx *ctx, struct lib9p_m unmarshal_fid(ctx, &out->fid); } -FLATTEN static void unmarshal_Rremove(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rremove *out) { +LM_FLATTEN static void unmarshal_Rremove(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rremove *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; unmarshal_tag(ctx, &out->tag); } -FLATTEN static void unmarshal_Tstat(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tstat *out) { +LM_FLATTEN static void unmarshal_Tstat(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tstat *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -1092,7 +1092,7 @@ FLATTEN static void unmarshal_Tstat(struct _unmarshal_ctx *ctx, struct lib9p_msg unmarshal_fid(ctx, &out->fid); } -FLATTEN static void unmarshal_Rstat(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rstat *out) { +LM_FLATTEN static void unmarshal_Rstat(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rstat *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -1101,7 +1101,7 @@ FLATTEN static void unmarshal_Rstat(struct _unmarshal_ctx *ctx, struct lib9p_msg unmarshal_stat(ctx, &out->stat); } -FLATTEN static void unmarshal_Twstat(struct _unmarshal_ctx *ctx, struct lib9p_msg_Twstat *out) { +LM_FLATTEN static void unmarshal_Twstat(struct _unmarshal_ctx *ctx, struct lib9p_msg_Twstat *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -1111,7 +1111,7 @@ FLATTEN static void unmarshal_Twstat(struct _unmarshal_ctx *ctx, struct lib9p_ms unmarshal_stat(ctx, &out->stat); } -FLATTEN static void unmarshal_Rwstat(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rwstat *out) { +LM_FLATTEN static void unmarshal_Rwstat(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rwstat *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -1120,7 +1120,7 @@ FLATTEN static void unmarshal_Rwstat(struct _unmarshal_ctx *ctx, struct lib9p_ms #endif /* CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u */ #if CONFIG_9P_ENABLE_9P2000_e -FLATTEN static void unmarshal_Tsession(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tsession *out) { +LM_FLATTEN static void unmarshal_Tsession(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tsession *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -1128,14 +1128,14 @@ FLATTEN static void unmarshal_Tsession(struct _unmarshal_ctx *ctx, struct lib9p_ unmarshal_8(ctx, &out->key); } -FLATTEN static void unmarshal_Rsession(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rsession *out) { +LM_FLATTEN static void unmarshal_Rsession(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rsession *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; unmarshal_tag(ctx, &out->tag); } -FLATTEN static void unmarshal_Tsread(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tsread *out) { +LM_FLATTEN static void unmarshal_Tsread(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tsread *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -1148,7 +1148,7 @@ FLATTEN static void unmarshal_Tsread(struct _unmarshal_ctx *ctx, struct lib9p_ms unmarshal_s(ctx, &out->wname[i]); } -FLATTEN static void unmarshal_Rsread(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rsread *out) { +LM_FLATTEN static void unmarshal_Rsread(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rsread *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -1156,7 +1156,7 @@ FLATTEN static void unmarshal_Rsread(struct _unmarshal_ctx *ctx, struct lib9p_ms unmarshal_d(ctx, &out->data); } -FLATTEN static void unmarshal_Tswrite(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tswrite *out) { +LM_FLATTEN static void unmarshal_Tswrite(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tswrite *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -1170,7 +1170,7 @@ FLATTEN static void unmarshal_Tswrite(struct _unmarshal_ctx *ctx, struct lib9p_m unmarshal_d(ctx, &out->data); } -FLATTEN static void unmarshal_Rswrite(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rswrite *out) { +LM_FLATTEN static void unmarshal_Rswrite(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rswrite *out) { memset(out, 0, sizeof(*out)); ctx->net_offset += 4; ctx->net_offset += 1; @@ -1181,7 +1181,7 @@ FLATTEN static void unmarshal_Rswrite(struct _unmarshal_ctx *ctx, struct lib9p_m /* marshal_* ******************************************************************/ -ALWAYS_INLINE static bool _marshal_too_large(struct _marshal_ctx *ctx) { +LM_ALWAYS_INLINE static bool _marshal_too_large(struct _marshal_ctx *ctx) { lib9p_errorf(ctx->ctx, LINUX_ERANGE, "%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"), @@ -1189,7 +1189,7 @@ ALWAYS_INLINE static bool _marshal_too_large(struct _marshal_ctx *ctx) { return true; } -ALWAYS_INLINE static bool marshal_1(struct _marshal_ctx *ctx, uint8_t *val) { +LM_ALWAYS_INLINE static bool marshal_1(struct _marshal_ctx *ctx, uint8_t *val) { if (ctx->net_offset + 1 > ctx->ctx->max_msg_size) return _marshal_too_large(ctx); ctx->net_bytes[ctx->net_offset] = *val; @@ -1197,7 +1197,7 @@ ALWAYS_INLINE static bool marshal_1(struct _marshal_ctx *ctx, uint8_t *val) { return false; } -ALWAYS_INLINE static bool marshal_2(struct _marshal_ctx *ctx, uint16_t *val) { +LM_ALWAYS_INLINE static bool marshal_2(struct _marshal_ctx *ctx, uint16_t *val) { if (ctx->net_offset + 2 > ctx->ctx->max_msg_size) return _marshal_too_large(ctx); encode_u16le(*val, &ctx->net_bytes[ctx->net_offset]); @@ -1205,7 +1205,7 @@ ALWAYS_INLINE static bool marshal_2(struct _marshal_ctx *ctx, uint16_t *val) { return false; } -ALWAYS_INLINE static bool marshal_4(struct _marshal_ctx *ctx, uint32_t *val) { +LM_ALWAYS_INLINE static bool marshal_4(struct _marshal_ctx *ctx, uint32_t *val) { if (ctx->net_offset + 4 > ctx->ctx->max_msg_size) return true; encode_u32le(*val, &ctx->net_bytes[ctx->net_offset]); @@ -1213,7 +1213,7 @@ ALWAYS_INLINE static bool marshal_4(struct _marshal_ctx *ctx, uint32_t *val) { return false; } -ALWAYS_INLINE static bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) { +LM_ALWAYS_INLINE static bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) { if (ctx->net_offset + 8 > ctx->ctx->max_msg_size) return true; encode_u64le(*val, &ctx->net_bytes[ctx->net_offset]); @@ -1222,15 +1222,15 @@ ALWAYS_INLINE static bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) { } #if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u -ALWAYS_INLINE static bool marshal_tag(struct _marshal_ctx *ctx, lib9p_tag_t *val) { +LM_ALWAYS_INLINE static bool marshal_tag(struct _marshal_ctx *ctx, lib9p_tag_t *val) { return marshal_2(ctx, (uint16_t *)val); } -ALWAYS_INLINE static bool marshal_fid(struct _marshal_ctx *ctx, lib9p_fid_t *val) { +LM_ALWAYS_INLINE static bool marshal_fid(struct _marshal_ctx *ctx, lib9p_fid_t *val) { return marshal_4(ctx, (uint32_t *)val); } -ALWAYS_INLINE static bool marshal_d(struct _marshal_ctx *ctx, struct lib9p_d *val) { +LM_ALWAYS_INLINE static bool marshal_d(struct _marshal_ctx *ctx, struct lib9p_d *val) { return false || marshal_4(ctx, &val->len) || ({ bool err = false; @@ -1240,7 +1240,7 @@ ALWAYS_INLINE static bool marshal_d(struct _marshal_ctx *ctx, struct lib9p_d *va ; } -ALWAYS_INLINE static bool marshal_s(struct _marshal_ctx *ctx, struct lib9p_s *val) { +LM_ALWAYS_INLINE static bool marshal_s(struct _marshal_ctx *ctx, struct lib9p_s *val) { return false || marshal_2(ctx, &val->len) || ({ bool err = false; @@ -1250,17 +1250,17 @@ ALWAYS_INLINE static bool marshal_s(struct _marshal_ctx *ctx, struct lib9p_s *va ; } -ALWAYS_INLINE static bool marshal_dm(struct _marshal_ctx *ctx, lib9p_dm_t *val) { +LM_ALWAYS_INLINE static bool marshal_dm(struct _marshal_ctx *ctx, lib9p_dm_t *val) { lib9p_dm_t masked_val = *val & dm_masks[ctx->ctx->version]; return marshal_4(ctx, (uint32_t *)&masked_val); } -ALWAYS_INLINE static bool marshal_qt(struct _marshal_ctx *ctx, lib9p_qt_t *val) { +LM_ALWAYS_INLINE static bool marshal_qt(struct _marshal_ctx *ctx, lib9p_qt_t *val) { lib9p_qt_t masked_val = *val & qt_masks[ctx->ctx->version]; return marshal_1(ctx, (uint8_t *)&masked_val); } -ALWAYS_INLINE static bool marshal_qid(struct _marshal_ctx *ctx, struct lib9p_qid *val) { +LM_ALWAYS_INLINE static bool marshal_qid(struct _marshal_ctx *ctx, struct lib9p_qid *val) { return false || marshal_qt(ctx, &val->type) || marshal_4(ctx, &val->vers) @@ -1268,7 +1268,7 @@ ALWAYS_INLINE static bool marshal_qid(struct _marshal_ctx *ctx, struct lib9p_qid ; } -ALWAYS_INLINE static bool marshal_stat(struct _marshal_ctx *ctx, struct lib9p_stat *val) { +LM_ALWAYS_INLINE static bool marshal_stat(struct _marshal_ctx *ctx, struct lib9p_stat *val) { uint32_t _stat_size_offset; uint32_t _kern_type_offset; return false @@ -1294,12 +1294,12 @@ ALWAYS_INLINE static bool marshal_stat(struct _marshal_ctx *ctx, struct lib9p_st ; } -ALWAYS_INLINE static bool marshal_o(struct _marshal_ctx *ctx, lib9p_o_t *val) { +LM_ALWAYS_INLINE static bool marshal_o(struct _marshal_ctx *ctx, lib9p_o_t *val) { lib9p_o_t masked_val = *val & o_masks[ctx->ctx->version]; return marshal_1(ctx, (uint8_t *)&masked_val); } -FLATTEN static bool marshal_Tversion(struct _marshal_ctx *ctx, struct lib9p_msg_Tversion *val) { +LM_FLATTEN static bool marshal_Tversion(struct _marshal_ctx *ctx, struct lib9p_msg_Tversion *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1313,7 +1313,7 @@ FLATTEN static bool marshal_Tversion(struct _marshal_ctx *ctx, struct lib9p_msg_ ; } -FLATTEN static bool marshal_Rversion(struct _marshal_ctx *ctx, struct lib9p_msg_Rversion *val) { +LM_FLATTEN static bool marshal_Rversion(struct _marshal_ctx *ctx, struct lib9p_msg_Rversion *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1327,7 +1327,7 @@ FLATTEN static bool marshal_Rversion(struct _marshal_ctx *ctx, struct lib9p_msg_ ; } -FLATTEN static bool marshal_Tauth(struct _marshal_ctx *ctx, struct lib9p_msg_Tauth *val) { +LM_FLATTEN static bool marshal_Tauth(struct _marshal_ctx *ctx, struct lib9p_msg_Tauth *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1345,7 +1345,7 @@ FLATTEN static bool marshal_Tauth(struct _marshal_ctx *ctx, struct lib9p_msg_Tau ; } -FLATTEN static bool marshal_Rauth(struct _marshal_ctx *ctx, struct lib9p_msg_Rauth *val) { +LM_FLATTEN static bool marshal_Rauth(struct _marshal_ctx *ctx, struct lib9p_msg_Rauth *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1358,7 +1358,7 @@ FLATTEN static bool marshal_Rauth(struct _marshal_ctx *ctx, struct lib9p_msg_Rau ; } -FLATTEN static bool marshal_Tattach(struct _marshal_ctx *ctx, struct lib9p_msg_Tattach *val) { +LM_FLATTEN static bool marshal_Tattach(struct _marshal_ctx *ctx, struct lib9p_msg_Tattach *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1377,7 +1377,7 @@ FLATTEN static bool marshal_Tattach(struct _marshal_ctx *ctx, struct lib9p_msg_T ; } -FLATTEN static bool marshal_Rattach(struct _marshal_ctx *ctx, struct lib9p_msg_Rattach *val) { +LM_FLATTEN static bool marshal_Rattach(struct _marshal_ctx *ctx, struct lib9p_msg_Rattach *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1390,7 +1390,7 @@ FLATTEN static bool marshal_Rattach(struct _marshal_ctx *ctx, struct lib9p_msg_R ; } -FLATTEN static bool marshal_Rerror(struct _marshal_ctx *ctx, struct lib9p_msg_Rerror *val) { +LM_FLATTEN static bool marshal_Rerror(struct _marshal_ctx *ctx, struct lib9p_msg_Rerror *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1406,7 +1406,7 @@ FLATTEN static bool marshal_Rerror(struct _marshal_ctx *ctx, struct lib9p_msg_Re ; } -FLATTEN static bool marshal_Tflush(struct _marshal_ctx *ctx, struct lib9p_msg_Tflush *val) { +LM_FLATTEN static bool marshal_Tflush(struct _marshal_ctx *ctx, struct lib9p_msg_Tflush *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1419,7 +1419,7 @@ FLATTEN static bool marshal_Tflush(struct _marshal_ctx *ctx, struct lib9p_msg_Tf ; } -FLATTEN static bool marshal_Rflush(struct _marshal_ctx *ctx, struct lib9p_msg_Rflush *val) { +LM_FLATTEN static bool marshal_Rflush(struct _marshal_ctx *ctx, struct lib9p_msg_Rflush *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1431,7 +1431,7 @@ FLATTEN static bool marshal_Rflush(struct _marshal_ctx *ctx, struct lib9p_msg_Rf ; } -FLATTEN static bool marshal_Twalk(struct _marshal_ctx *ctx, struct lib9p_msg_Twalk *val) { +LM_FLATTEN static bool marshal_Twalk(struct _marshal_ctx *ctx, struct lib9p_msg_Twalk *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1450,7 +1450,7 @@ FLATTEN static bool marshal_Twalk(struct _marshal_ctx *ctx, struct lib9p_msg_Twa ; } -FLATTEN static bool marshal_Rwalk(struct _marshal_ctx *ctx, struct lib9p_msg_Rwalk *val) { +LM_FLATTEN static bool marshal_Rwalk(struct _marshal_ctx *ctx, struct lib9p_msg_Rwalk *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1467,7 +1467,7 @@ FLATTEN static bool marshal_Rwalk(struct _marshal_ctx *ctx, struct lib9p_msg_Rwa ; } -FLATTEN static bool marshal_Topen(struct _marshal_ctx *ctx, struct lib9p_msg_Topen *val) { +LM_FLATTEN static bool marshal_Topen(struct _marshal_ctx *ctx, struct lib9p_msg_Topen *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1481,7 +1481,7 @@ FLATTEN static bool marshal_Topen(struct _marshal_ctx *ctx, struct lib9p_msg_Top ; } -FLATTEN static bool marshal_Ropen(struct _marshal_ctx *ctx, struct lib9p_msg_Ropen *val) { +LM_FLATTEN static bool marshal_Ropen(struct _marshal_ctx *ctx, struct lib9p_msg_Ropen *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1495,7 +1495,7 @@ FLATTEN static bool marshal_Ropen(struct _marshal_ctx *ctx, struct lib9p_msg_Rop ; } -FLATTEN static bool marshal_Tcreate(struct _marshal_ctx *ctx, struct lib9p_msg_Tcreate *val) { +LM_FLATTEN static bool marshal_Tcreate(struct _marshal_ctx *ctx, struct lib9p_msg_Tcreate *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1511,7 +1511,7 @@ FLATTEN static bool marshal_Tcreate(struct _marshal_ctx *ctx, struct lib9p_msg_T ; } -FLATTEN static bool marshal_Rcreate(struct _marshal_ctx *ctx, struct lib9p_msg_Rcreate *val) { +LM_FLATTEN static bool marshal_Rcreate(struct _marshal_ctx *ctx, struct lib9p_msg_Rcreate *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1525,7 +1525,7 @@ FLATTEN static bool marshal_Rcreate(struct _marshal_ctx *ctx, struct lib9p_msg_R ; } -FLATTEN static bool marshal_Tread(struct _marshal_ctx *ctx, struct lib9p_msg_Tread *val) { +LM_FLATTEN static bool marshal_Tread(struct _marshal_ctx *ctx, struct lib9p_msg_Tread *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1540,7 +1540,7 @@ FLATTEN static bool marshal_Tread(struct _marshal_ctx *ctx, struct lib9p_msg_Tre ; } -FLATTEN static bool marshal_Rread(struct _marshal_ctx *ctx, struct lib9p_msg_Rread *val) { +LM_FLATTEN static bool marshal_Rread(struct _marshal_ctx *ctx, struct lib9p_msg_Rread *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1553,7 +1553,7 @@ FLATTEN static bool marshal_Rread(struct _marshal_ctx *ctx, struct lib9p_msg_Rre ; } -FLATTEN static bool marshal_Twrite(struct _marshal_ctx *ctx, struct lib9p_msg_Twrite *val) { +LM_FLATTEN static bool marshal_Twrite(struct _marshal_ctx *ctx, struct lib9p_msg_Twrite *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1568,7 +1568,7 @@ FLATTEN static bool marshal_Twrite(struct _marshal_ctx *ctx, struct lib9p_msg_Tw ; } -FLATTEN static bool marshal_Rwrite(struct _marshal_ctx *ctx, struct lib9p_msg_Rwrite *val) { +LM_FLATTEN static bool marshal_Rwrite(struct _marshal_ctx *ctx, struct lib9p_msg_Rwrite *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1581,7 +1581,7 @@ FLATTEN static bool marshal_Rwrite(struct _marshal_ctx *ctx, struct lib9p_msg_Rw ; } -FLATTEN static bool marshal_Tclunk(struct _marshal_ctx *ctx, struct lib9p_msg_Tclunk *val) { +LM_FLATTEN static bool marshal_Tclunk(struct _marshal_ctx *ctx, struct lib9p_msg_Tclunk *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1594,7 +1594,7 @@ FLATTEN static bool marshal_Tclunk(struct _marshal_ctx *ctx, struct lib9p_msg_Tc ; } -FLATTEN static bool marshal_Rclunk(struct _marshal_ctx *ctx, struct lib9p_msg_Rclunk *val) { +LM_FLATTEN static bool marshal_Rclunk(struct _marshal_ctx *ctx, struct lib9p_msg_Rclunk *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1606,7 +1606,7 @@ FLATTEN static bool marshal_Rclunk(struct _marshal_ctx *ctx, struct lib9p_msg_Rc ; } -FLATTEN static bool marshal_Tremove(struct _marshal_ctx *ctx, struct lib9p_msg_Tremove *val) { +LM_FLATTEN static bool marshal_Tremove(struct _marshal_ctx *ctx, struct lib9p_msg_Tremove *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1619,7 +1619,7 @@ FLATTEN static bool marshal_Tremove(struct _marshal_ctx *ctx, struct lib9p_msg_T ; } -FLATTEN static bool marshal_Rremove(struct _marshal_ctx *ctx, struct lib9p_msg_Rremove *val) { +LM_FLATTEN static bool marshal_Rremove(struct _marshal_ctx *ctx, struct lib9p_msg_Rremove *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1631,7 +1631,7 @@ FLATTEN static bool marshal_Rremove(struct _marshal_ctx *ctx, struct lib9p_msg_R ; } -FLATTEN static bool marshal_Tstat(struct _marshal_ctx *ctx, struct lib9p_msg_Tstat *val) { +LM_FLATTEN static bool marshal_Tstat(struct _marshal_ctx *ctx, struct lib9p_msg_Tstat *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1644,7 +1644,7 @@ FLATTEN static bool marshal_Tstat(struct _marshal_ctx *ctx, struct lib9p_msg_Tst ; } -FLATTEN static bool marshal_Rstat(struct _marshal_ctx *ctx, struct lib9p_msg_Rstat *val) { +LM_FLATTEN static bool marshal_Rstat(struct _marshal_ctx *ctx, struct lib9p_msg_Rstat *val) { uint32_t _size_offset; uint32_t _typ_offset; uint32_t _nstat_offset; @@ -1661,7 +1661,7 @@ FLATTEN static bool marshal_Rstat(struct _marshal_ctx *ctx, struct lib9p_msg_Rst ; } -FLATTEN static bool marshal_Twstat(struct _marshal_ctx *ctx, struct lib9p_msg_Twstat *val) { +LM_FLATTEN static bool marshal_Twstat(struct _marshal_ctx *ctx, struct lib9p_msg_Twstat *val) { uint32_t _size_offset; uint32_t _typ_offset; uint32_t _nstat_offset; @@ -1679,7 +1679,7 @@ FLATTEN static bool marshal_Twstat(struct _marshal_ctx *ctx, struct lib9p_msg_Tw ; } -FLATTEN static bool marshal_Rwstat(struct _marshal_ctx *ctx, struct lib9p_msg_Rwstat *val) { +LM_FLATTEN static bool marshal_Rwstat(struct _marshal_ctx *ctx, struct lib9p_msg_Rwstat *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1693,7 +1693,7 @@ FLATTEN static bool marshal_Rwstat(struct _marshal_ctx *ctx, struct lib9p_msg_Rw #endif /* CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u */ #if CONFIG_9P_ENABLE_9P2000_e -FLATTEN static bool marshal_Tsession(struct _marshal_ctx *ctx, struct lib9p_msg_Tsession *val) { +LM_FLATTEN static bool marshal_Tsession(struct _marshal_ctx *ctx, struct lib9p_msg_Tsession *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1706,7 +1706,7 @@ FLATTEN static bool marshal_Tsession(struct _marshal_ctx *ctx, struct lib9p_msg_ ; } -FLATTEN static bool marshal_Rsession(struct _marshal_ctx *ctx, struct lib9p_msg_Rsession *val) { +LM_FLATTEN static bool marshal_Rsession(struct _marshal_ctx *ctx, struct lib9p_msg_Rsession *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1718,7 +1718,7 @@ FLATTEN static bool marshal_Rsession(struct _marshal_ctx *ctx, struct lib9p_msg_ ; } -FLATTEN static bool marshal_Tsread(struct _marshal_ctx *ctx, struct lib9p_msg_Tsread *val) { +LM_FLATTEN static bool marshal_Tsread(struct _marshal_ctx *ctx, struct lib9p_msg_Tsread *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1736,7 +1736,7 @@ FLATTEN static bool marshal_Tsread(struct _marshal_ctx *ctx, struct lib9p_msg_Ts ; } -FLATTEN static bool marshal_Rsread(struct _marshal_ctx *ctx, struct lib9p_msg_Rsread *val) { +LM_FLATTEN static bool marshal_Rsread(struct _marshal_ctx *ctx, struct lib9p_msg_Rsread *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1749,7 +1749,7 @@ FLATTEN static bool marshal_Rsread(struct _marshal_ctx *ctx, struct lib9p_msg_Rs ; } -FLATTEN static bool marshal_Tswrite(struct _marshal_ctx *ctx, struct lib9p_msg_Tswrite *val) { +LM_FLATTEN static bool marshal_Tswrite(struct _marshal_ctx *ctx, struct lib9p_msg_Tswrite *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -1768,7 +1768,7 @@ FLATTEN static bool marshal_Tswrite(struct _marshal_ctx *ctx, struct lib9p_msg_T ; } -FLATTEN static bool marshal_Rswrite(struct _marshal_ctx *ctx, struct lib9p_msg_Rswrite *val) { +LM_FLATTEN static bool marshal_Rswrite(struct _marshal_ctx *ctx, struct lib9p_msg_Rswrite *val) { uint32_t _size_offset; uint32_t _typ_offset; return false @@ -2836,12 +2836,12 @@ struct _table_version _lib9p_versions[LIB9P_VER_NUM] = { #endif /* CONFIG_9P_ENABLE_9P2000_u */ }; -FLATTEN bool _lib9p_validate_stat(struct _validate_ctx *ctx) { +LM_FLATTEN bool _lib9p_validate_stat(struct _validate_ctx *ctx) { return validate_stat(ctx); } -FLATTEN void _lib9p_unmarshal_stat(struct _unmarshal_ctx *ctx, struct lib9p_stat *out) { +LM_FLATTEN void _lib9p_unmarshal_stat(struct _unmarshal_ctx *ctx, struct lib9p_stat *out) { unmarshal_stat(ctx, out); } -FLATTEN bool _lib9p_marshal_stat(struct _marshal_ctx *ctx, struct lib9p_stat *val) { +LM_FLATTEN bool _lib9p_marshal_stat(struct _marshal_ctx *ctx, struct lib9p_stat *val) { return marshal_stat(ctx, val); } diff --git a/lib9p/idl.gen b/lib9p/idl.gen index cca83da..ae7f1a5 100755 --- a/lib9p/idl.gen +++ b/lib9p/idl.gen @@ -708,7 +708,7 @@ def gen_c(versions: set[str], typs: list[Type]) -> str: return arg def unused(arg: str) -> str: - return f"UNUSED({arg})" + return f"LM_UNUSED({arg})" # strings ################################################################## ret += f""" @@ -736,7 +736,7 @@ const char *{idprefix}version_str(enum {idprefix}version ver) {{ ret += """ /* validate_* *****************************************************************/ -ALWAYS_INLINE static bool _validate_size_net(struct _validate_ctx *ctx, uint32_t n) { +LM_ALWAYS_INLINE static bool _validate_size_net(struct _validate_ctx *ctx, uint32_t n) { if (__builtin_add_overflow(ctx->net_offset, n, &ctx->net_offset)) /* If needed-net-size overflowed uint32_t, then * there's no way that actual-net-size will live up to @@ -747,7 +747,7 @@ ALWAYS_INLINE static bool _validate_size_net(struct _validate_ctx *ctx, uint32_t return false; } -ALWAYS_INLINE static bool _validate_size_host(struct _validate_ctx *ctx, size_t n) { +LM_ALWAYS_INLINE static bool _validate_size_host(struct _validate_ctx *ctx, size_t n) { if (__builtin_add_overflow(ctx->host_extra, n, &ctx->host_extra)) /* If needed-host-size overflowed size_t, then there's * no way that actual-net-size will live up to @@ -756,7 +756,7 @@ ALWAYS_INLINE static bool _validate_size_host(struct _validate_ctx *ctx, size_t return false; } -ALWAYS_INLINE static bool _validate_list(struct _validate_ctx *ctx, +LM_ALWAYS_INLINE static bool _validate_list(struct _validate_ctx *ctx, size_t cnt, _validate_fn_t item_fn, size_t item_host_size) { for (size_t i = 0; i < cnt; i++) @@ -771,7 +771,7 @@ ALWAYS_INLINE static bool _validate_list(struct _validate_ctx *ctx, #define validate_8(ctx) _validate_size_net(ctx, 8) """ for typ in typs: - inline = "FLATTEN" if isinstance(typ, Message) else "ALWAYS_INLINE" + inline = "LM_FLATTEN" if isinstance(typ, Message) else "LM_ALWAYS_INLINE" argfn = unused if (isinstance(typ, Struct) and not typ.members) else used ret += "\n" ret += ifdef_push(1, c_ver_ifdef(typ.in_versions)) @@ -903,28 +903,28 @@ ALWAYS_INLINE static bool _validate_list(struct _validate_ctx *ctx, ret += """ /* unmarshal_* ****************************************************************/ -ALWAYS_INLINE static void unmarshal_1(struct _unmarshal_ctx *ctx, uint8_t *out) { +LM_ALWAYS_INLINE static void unmarshal_1(struct _unmarshal_ctx *ctx, uint8_t *out) { *out = decode_u8le(&ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 1; } -ALWAYS_INLINE static void unmarshal_2(struct _unmarshal_ctx *ctx, uint16_t *out) { +LM_ALWAYS_INLINE static void unmarshal_2(struct _unmarshal_ctx *ctx, uint16_t *out) { *out = decode_u16le(&ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 2; } -ALWAYS_INLINE static void unmarshal_4(struct _unmarshal_ctx *ctx, uint32_t *out) { +LM_ALWAYS_INLINE static void unmarshal_4(struct _unmarshal_ctx *ctx, uint32_t *out) { *out = decode_u32le(&ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 4; } -ALWAYS_INLINE static void unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out) { +LM_ALWAYS_INLINE static void unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out) { *out = decode_u64le(&ctx->net_bytes[ctx->net_offset]); ctx->net_offset += 8; } """ for typ in typs: - inline = "FLATTEN" if isinstance(typ, Message) else "ALWAYS_INLINE" + inline = "LM_FLATTEN" if isinstance(typ, Message) else "LM_ALWAYS_INLINE" argfn = unused if (isinstance(typ, Struct) and not typ.members) else used ret += "\n" ret += ifdef_push(1, c_ver_ifdef(typ.in_versions)) @@ -976,7 +976,7 @@ ALWAYS_INLINE static void unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out) ret += """ /* marshal_* ******************************************************************/ -ALWAYS_INLINE static bool _marshal_too_large(struct _marshal_ctx *ctx) { +LM_ALWAYS_INLINE static bool _marshal_too_large(struct _marshal_ctx *ctx) { lib9p_errorf(ctx->ctx, LINUX_ERANGE, "%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"), @@ -984,7 +984,7 @@ ALWAYS_INLINE static bool _marshal_too_large(struct _marshal_ctx *ctx) { return true; } -ALWAYS_INLINE static bool marshal_1(struct _marshal_ctx *ctx, uint8_t *val) { +LM_ALWAYS_INLINE static bool marshal_1(struct _marshal_ctx *ctx, uint8_t *val) { if (ctx->net_offset + 1 > ctx->ctx->max_msg_size) return _marshal_too_large(ctx); ctx->net_bytes[ctx->net_offset] = *val; @@ -992,7 +992,7 @@ ALWAYS_INLINE static bool marshal_1(struct _marshal_ctx *ctx, uint8_t *val) { return false; } -ALWAYS_INLINE static bool marshal_2(struct _marshal_ctx *ctx, uint16_t *val) { +LM_ALWAYS_INLINE static bool marshal_2(struct _marshal_ctx *ctx, uint16_t *val) { if (ctx->net_offset + 2 > ctx->ctx->max_msg_size) return _marshal_too_large(ctx); encode_u16le(*val, &ctx->net_bytes[ctx->net_offset]); @@ -1000,7 +1000,7 @@ ALWAYS_INLINE static bool marshal_2(struct _marshal_ctx *ctx, uint16_t *val) { return false; } -ALWAYS_INLINE static bool marshal_4(struct _marshal_ctx *ctx, uint32_t *val) { +LM_ALWAYS_INLINE static bool marshal_4(struct _marshal_ctx *ctx, uint32_t *val) { if (ctx->net_offset + 4 > ctx->ctx->max_msg_size) return true; encode_u32le(*val, &ctx->net_bytes[ctx->net_offset]); @@ -1008,7 +1008,7 @@ ALWAYS_INLINE static bool marshal_4(struct _marshal_ctx *ctx, uint32_t *val) { return false; } -ALWAYS_INLINE static bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) { +LM_ALWAYS_INLINE static bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) { if (ctx->net_offset + 8 > ctx->ctx->max_msg_size) return true; encode_u64le(*val, &ctx->net_bytes[ctx->net_offset]); @@ -1017,7 +1017,7 @@ ALWAYS_INLINE static bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) { } """ for typ in typs: - inline = "FLATTEN" if isinstance(typ, Message) else "ALWAYS_INLINE" + inline = "LM_FLATTEN" if isinstance(typ, Message) else "LM_ALWAYS_INLINE" argfn = unused if (isinstance(typ, Struct) and not typ.members) else used ret += "\n" ret += ifdef_push(1, c_ver_ifdef(typ.in_versions)) @@ -1136,13 +1136,13 @@ struct _table_version _{idprefix}versions[{c_ver_enum('NUM')}] = {{ ret += "};\n" ret += f""" -FLATTEN bool _{idprefix}validate_stat(struct _validate_ctx *ctx) {{ +LM_FLATTEN bool _{idprefix}validate_stat(struct _validate_ctx *ctx) {{ return validate_stat(ctx); }} -FLATTEN void _{idprefix}unmarshal_stat(struct _unmarshal_ctx *ctx, struct lib9p_stat *out) {{ +LM_FLATTEN void _{idprefix}unmarshal_stat(struct _unmarshal_ctx *ctx, struct lib9p_stat *out) {{ unmarshal_stat(ctx, out); }} -FLATTEN bool _{idprefix}marshal_stat(struct _marshal_ctx *ctx, struct lib9p_stat *val) {{ +LM_FLATTEN bool _{idprefix}marshal_stat(struct _marshal_ctx *ctx, struct lib9p_stat *val) {{ return marshal_stat(ctx, val); }} """ diff --git a/lib9p/internal.h b/lib9p/internal.h index 07bb9d6..b1a367d 100644 --- a/lib9p/internal.h +++ b/lib9p/internal.h @@ -13,6 +13,8 @@ #define SSIZE_MAX (SIZE_MAX >> 1) #endif +#include + #include /* configuration **************************************************************/ @@ -39,15 +41,6 @@ static_assert(CONFIG_9P_MAX_ERR_SIZE <= UINT16_MAX); static_assert(CONFIG_9P_MAX_MSG_SIZE <= CONFIG_9P_MAX_HOSTMSG_SIZE); static_assert(CONFIG_9P_MAX_HOSTMSG_SIZE <= SSIZE_MAX); -/* C language *****************************************************************/ - -#define UNUSED(name) -#define ALWAYS_INLINE [[gnu::always_inline]] inline -#define FLATTEN [[gnu::flatten]] -#define ARRAY_LEN(arr) (sizeof(arr)/sizeof((arr)[0])) -#define CAT2(a, b) a##b -#define CAT3(a, b, c) a##b##c - /* specialized contexts *******************************************************/ struct _validate_ctx { @@ -102,22 +95,22 @@ bool _lib9p_marshal_stat(struct _marshal_ctx *ctx, struct lib9p_stat *val); /* unmarshal utilities ********************************************************/ -ALWAYS_INLINE static uint8_t decode_u8le(uint8_t *in) { +LM_ALWAYS_INLINE static uint8_t decode_u8le(uint8_t *in) { return in[0]; } -ALWAYS_INLINE static uint16_t decode_u16le(uint8_t *in) { +LM_ALWAYS_INLINE static uint16_t decode_u16le(uint8_t *in) { return (((uint16_t)(in[0])) << 0) | (((uint16_t)(in[1])) << 8) ; } -ALWAYS_INLINE static uint32_t decode_u32le(uint8_t *in) { +LM_ALWAYS_INLINE static uint32_t decode_u32le(uint8_t *in) { return (((uint32_t)(in[0])) << 0) | (((uint32_t)(in[1])) << 8) | (((uint32_t)(in[2])) << 16) | (((uint32_t)(in[3])) << 24) ; } -ALWAYS_INLINE static uint64_t decode_u64le(uint8_t *in) { +LM_ALWAYS_INLINE static uint64_t decode_u64le(uint8_t *in) { return (((uint64_t)(in[0])) << 0) | (((uint64_t)(in[1])) << 8) | (((uint64_t)(in[2])) << 16) @@ -155,20 +148,20 @@ static inline bool _is_valid_utf8(uint8_t *str, size_t len, bool forbid_nul) { /* marshal utilities **********************************************************/ -ALWAYS_INLINE static void encode_u8le(uint8_t in, uint8_t *out) { +LM_ALWAYS_INLINE static void encode_u8le(uint8_t in, uint8_t *out) { out[0] = in; } -ALWAYS_INLINE static void encode_u16le(uint16_t in, uint8_t *out) { +LM_ALWAYS_INLINE static void encode_u16le(uint16_t in, uint8_t *out) { out[0] = (uint8_t)((in >> 0) & 0xFF); out[1] = (uint8_t)((in >> 8) & 0xFF); } -ALWAYS_INLINE static void encode_u32le(uint32_t in, uint8_t *out) { +LM_ALWAYS_INLINE static void encode_u32le(uint32_t in, uint8_t *out) { out[0] = (uint8_t)((in >> 0) & 0xFF); out[1] = (uint8_t)((in >> 8) & 0xFF); out[2] = (uint8_t)((in >> 16) & 0xFF); out[3] = (uint8_t)((in >> 24) & 0xFF); } -ALWAYS_INLINE static void encode_u64le(uint64_t in, uint8_t *out) { +LM_ALWAYS_INLINE static void encode_u64le(uint64_t in, uint8_t *out) { out[0] = (uint8_t)((in >> 0) & 0xFF); out[1] = (uint8_t)((in >> 8) & 0xFF); out[2] = (uint8_t)((in >> 16) & 0xFF); diff --git a/lib9p/map.h b/lib9p/map.h index f42bb2c..b59c83d 100644 --- a/lib9p/map.h +++ b/lib9p/map.h @@ -25,10 +25,10 @@ #endif #ifndef MAP_KEY -#define MAP_KV(TNAME) CAT3(_,TNAME,_kv) -#define MAP_METHOD(TNAME, MNAME) CAT3(TNAME,_,MNAME) +#define MAP_KV(TNAME) LM_CAT3(_,TNAME,_kv) +#define MAP_METHOD(TNAME, MNAME) LM_CAT3(TNAME,_,MNAME) #define MAP_FOREACH(m, k, v) \ - for (size_t i = 0; i < ARRAY_LEN((m)->items); i++) \ + for (size_t i = 0; i < LM_ARRAY_LEN((m)->items); i++) \ if ( ({ k = (m)->items[i].key; v = &(m)->items[i].val; (m)->items[i].set; }) ) #endif @@ -58,7 +58,7 @@ struct NAME { static VAL_T *MAP_METHOD(NAME,load)(struct NAME *m, KEY_T k) { if (!m->len) return NULL; - for (size_t i = 0; i < ARRAY_LEN(m->items); i++) + for (size_t i = 0; i < LM_ARRAY_LEN(m->items); i++) if (m->items[i].set && m->items[i].key == k) return &(m->items[i].val); return NULL; @@ -74,9 +74,9 @@ static VAL_T *MAP_METHOD(NAME,store)(struct NAME *m, KEY_T k, VAL_T v) { *old = v; return old; } - if (m->len == ARRAY_LEN(m->items)) + if (m->len == LM_ARRAY_LEN(m->items)) return NULL; - for (size_t i = 0; i < ARRAY_LEN(m->items); i++) + for (size_t i = 0; i < LM_ARRAY_LEN(m->items); i++) if (!m->items[i].set) { m->len++; m->items[i].set = true; @@ -94,7 +94,7 @@ static VAL_T *MAP_METHOD(NAME,store)(struct NAME *m, KEY_T k, VAL_T v) { static bool MAP_METHOD(NAME,del)(struct NAME *m, KEY_T k) { if (!m->len) return NULL; - for (size_t i = 0; i < ARRAY_LEN(m->items); i++) + for (size_t i = 0; i < LM_ARRAY_LEN(m->items); i++) if (m->items[i].set && m->items[i].key == k) { m->items[i].set = false; m->len--; diff --git a/lib9p_util/static.c b/lib9p_util/static.c index fd6f154..454b57e 100644 --- a/lib9p_util/static.c +++ b/lib9p_util/static.c @@ -5,11 +5,11 @@ */ #include +#include #include #include -#define UNUSED(name) #define p9_str(cstr) ((struct lib9p_s){ .len = strlen(cstr), .utf8 = cstr }) #define p9_nulstr ((struct lib9p_s){ .len = 0, .utf8 = NULL }) @@ -31,7 +31,7 @@ static void util9p_static_common_free(implements_lib9p_srv_file *_self, struct l /* do nothing */ } -static uint32_t util9p_static_common_io(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx, lib9p_o_t UNUSED(flags)) { +static uint32_t util9p_static_common_io(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx, lib9p_o_t LM_UNUSED(flags)) { _util9p_static_common *self = VCALL_SELF(_util9p_static_common, implements_lib9p_srv_file, _self); assert(self); assert(ctx); @@ -40,7 +40,7 @@ static uint32_t util9p_static_common_io(implements_lib9p_srv_file *_self, struct } static void util9p_static_common_wstat(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx, - struct lib9p_stat UNUSED(new)) { + struct lib9p_stat LM_UNUSED(new)) { _util9p_static_common *self = VCALL_SELF(_util9p_static_common, implements_lib9p_srv_file, _self); assert(self); assert(ctx); @@ -107,8 +107,8 @@ static implements_lib9p_srv_file *util9p_static_dir_dopen(implements_lib9p_srv_f } static implements_lib9p_srv_file *util9p_static_dir_dcreate(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx, - char *UNUSED(childname), - lib9p_dm_t UNUSED(perm), lib9p_o_t UNUSED(flags)) { + char *LM_UNUSED(childname), + lib9p_dm_t LM_UNUSED(perm), lib9p_o_t LM_UNUSED(flags)) { struct util9p_static_dir *self = VCALL_SELF(struct util9p_static_dir, implements_lib9p_srv_file, _self); assert(self); assert(ctx); diff --git a/libcr/coroutine.c b/libcr/coroutine.c index aa23d58..7278225 100644 --- a/libcr/coroutine.c +++ b/libcr/coroutine.c @@ -9,6 +9,7 @@ #include /* for strncpy(), memset() */ #include +#include #define LOG_NAME COROUTINE #include @@ -128,18 +129,6 @@ * no longer exists. */ -/* preprocessor macros ********************************************************/ - -/** Return `n` rounded up to the nearest multiple of `d` */ -#define ROUND_UP(n, d) ( ( ((n)+(d)-1) / (d) ) * (d) ) -#define ARRAY_LEN(arr) (sizeof(arr)/sizeof((arr)[0])) -#define NEXT_POWER_OF_2(x) ((1ULL)<<((sizeof(unsigned long long)*8)-__builtin_clzll(x))) - -#define UNUSED(name) - -#define ALWAYS_INLINE [[gnu::always_inline]] inline -#define NEVER_INLINE [[gnu::noinline]] - /* platform support ***********************************************************/ /* As part of sbc-harness, this only really needs to support ARM-32, but being @@ -211,7 +200,7 @@ sigprocmask(SIG_SETMASK, &zero, NULL); } #if CONFIG_COROUTINE_GDB - static void _cr_gdb_intrhandler(int UNUSED(sig)) {} + static void _cr_gdb_intrhandler(int LM_UNUSED(sig)) {} #endif static void cr_plat_init(void) { #if CONFIG_COROUTINE_GDB @@ -231,7 +220,7 @@ ); return isr_number != 0; } - ALWAYS_INLINE static bool _cr_plat_are_interrupts_enabled(void) { + LM_ALWAYS_INLINE static bool _cr_plat_are_interrupts_enabled(void) { assert(!cr_plat_is_in_intrhandler()); uint32_t primask; asm volatile ("mrs %0, PRIMASK" @@ -240,7 +229,7 @@ return primask == 0; } - ALWAYS_INLINE static void cr_plat_wait_for_interrupt(void) { + LM_ALWAYS_INLINE static void cr_plat_wait_for_interrupt(void) { assert(!cr_plat_is_in_intrhandler()); assert(!_cr_plat_are_interrupts_enabled()); asm volatile ("wfi\n" @@ -271,7 +260,7 @@ #define CR_PLAT_STACK_GROWS_DOWNWARD 1 #if CONFIG_COROUTINE_MEASURE_STACK - ALWAYS_INLINE static uintptr_t cr_plat_get_sp(void) { + LM_ALWAYS_INLINE static uintptr_t cr_plat_get_sp(void) { uintptr_t sp; asm volatile ("mov %0, sp":"=r"(sp)); return sp; @@ -303,7 +292,7 @@ #define CR_PLAT_STACK_GROWS_DOWNWARD 1 #if CONFIG_COROUTINE_MEASURE_STACK - ALWAYS_INLINE static uintptr_t cr_plat_get_sp(void) { + LM_ALWAYS_INLINE static uintptr_t cr_plat_get_sp(void) { uintptr_t sp; asm volatile ("movq %%rsp, %0":"=r"(sp)); return sp; @@ -419,10 +408,10 @@ static const uint8_t stack_pattern[] = { }; #endif #if CONFIG_COROUTINE_PROTECT_STACK - #define STACK_GUARD_SIZE \ - ROUND_UP(sizeof(stack_pattern), CR_PLAT_STACK_ALIGNMENT) + #define CR_STACK_GUARD_SIZE \ + LM_ROUND_UP(sizeof(stack_pattern), CR_PLAT_STACK_ALIGNMENT) #else - #define STACK_GUARD_SIZE 0 + #define CR_STACK_GUARD_SIZE 0 #endif /* global variables ***********************************************************/ @@ -463,7 +452,7 @@ static struct { * compiler will optimize `%array_len` to &(array_len-1)`, (b) * we don't have to worry about funny wrap-around behavior * when head or tail overflow. */ - cid_t buf[NEXT_POWER_OF_2(CONFIG_COROUTINE_NUM)]; + cid_t buf[LM_NEXT_POWER_OF_2(CONFIG_COROUTINE_NUM)]; } coroutine_ringbuf = {0}; static cid_t coroutine_running = 0; static size_t coroutine_cnt = 0; @@ -471,28 +460,28 @@ static size_t coroutine_cnt = 0; /* utility functions **********************************************************/ static inline const char* coroutine_state_str(enum coroutine_state state) { - assert(state < ARRAY_LEN(coroutine_state_strs)); + assert(state < LM_ARRAY_LEN(coroutine_state_strs)); return coroutine_state_strs[state]; } static inline void coroutine_ringbuf_push(cid_t val) { - coroutine_ringbuf.buf[coroutine_ringbuf.head++ % ARRAY_LEN(coroutine_ringbuf.buf)] = val; - assert((coroutine_ringbuf.head % ARRAY_LEN(coroutine_ringbuf.buf)) != - (coroutine_ringbuf.tail % ARRAY_LEN(coroutine_ringbuf.buf))); + coroutine_ringbuf.buf[coroutine_ringbuf.head++ % LM_ARRAY_LEN(coroutine_ringbuf.buf)] = val; + assert((coroutine_ringbuf.head % LM_ARRAY_LEN(coroutine_ringbuf.buf)) != + (coroutine_ringbuf.tail % LM_ARRAY_LEN(coroutine_ringbuf.buf))); } static inline cid_t coroutine_ringbuf_pop(void) { if (coroutine_ringbuf.tail == coroutine_ringbuf.head) return 0; - return coroutine_ringbuf.buf[coroutine_ringbuf.tail++ % ARRAY_LEN(coroutine_ringbuf.buf)]; + return coroutine_ringbuf.buf[coroutine_ringbuf.tail++ % LM_ARRAY_LEN(coroutine_ringbuf.buf)]; } #if CONFIG_COROUTINE_GDB -NEVER_INLINE void cr_gdb_breakpoint(void) { +LM_NEVER_INLINE void cr_gdb_breakpoint(void) { /* Prevent the call from being optimized away. */ asm (""); } -NEVER_INLINE void cr_gdb_readjmp(cr_plat_jmp_buf *env) { +LM_NEVER_INLINE void cr_gdb_readjmp(cr_plat_jmp_buf *env) { if (!cr_plat_setjmp(&coroutine_gdb_env)) cr_plat_longjmp(env, 2); } @@ -516,7 +505,7 @@ static inline void assert_cid(cid_t cid) { assert(coroutine_table[cid-1].stack_size); uint8_t *stack = coroutine_table[cid-1].stack; assert(stack); - for (size_t i = 0; i < STACK_GUARD_SIZE; i++) { + for (size_t i = 0; i < CR_STACK_GUARD_SIZE; i++) { size_t j = coroutine_table[cid-1].stack_size - (i+1); assert(stack[i] == stack_pattern[i%sizeof(stack_pattern)]); assert(stack[j] == stack_pattern[j%sizeof(stack_pattern)]); @@ -583,8 +572,8 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, #endif #if CONFIG_COROUTINE_VALGRIND coroutine_table[child-1].stack_id = VALGRIND_STACK_REGISTER( - coroutine_table[child-1].stack + STACK_GUARD_SIZE, - coroutine_table[child-1].stack + stack_size - STACK_GUARD_SIZE); + coroutine_table[child-1].stack + CR_STACK_GUARD_SIZE, + coroutine_table[child-1].stack + stack_size - CR_STACK_GUARD_SIZE); #endif coroutine_running = child; @@ -594,9 +583,9 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, void *stack_base = coroutine_table[child-1].stack #if CR_PLAT_STACK_GROWS_DOWNWARD + stack_size - - STACK_GUARD_SIZE + - CR_STACK_GUARD_SIZE #else - + STACK_GUARD_SIZE + + CR_STACK_GUARD_SIZE #endif ; debugf("...stack =%p", coroutine_table[child-1].stack); @@ -782,7 +771,7 @@ void cr_cid_info(cid_t cid, struct cr_cid_info *ret) { assert(ret); /* stack_cap */ - ret->stack_cap = coroutine_table[cid-1].stack_size - 2*STACK_GUARD_SIZE; + ret->stack_cap = coroutine_table[cid-1].stack_size - 2*CR_STACK_GUARD_SIZE; /* stack_max */ ret->stack_max = ret->stack_cap; @@ -790,9 +779,9 @@ void cr_cid_info(cid_t cid, struct cr_cid_info *ret) { for (;;) { size_t i = #if CR_PLAT_STACK_GROWS_DOWNWARD - STACK_GUARD_SIZE + ret->stack_cap - ret->stack_max + CR_STACK_GUARD_SIZE + ret->stack_cap - ret->stack_max #else - ret->stack_max - 1 - STACK_GUARD_SIZE + ret->stack_max - 1 - CR_STACK_GUARD_SIZE #endif ; if (ret->stack_max == 0 || @@ -812,9 +801,9 @@ void cr_cid_info(cid_t cid, struct cr_cid_info *ret) { assert(sp); uintptr_t sb = (uintptr_t)coroutine_table[cid-1].stack; #if CR_PLAT_STACK_GROWS_DOWNWARD - ret->stack_cur = (sb - STACK_GUARD_SIZE) - sp; + ret->stack_cur = (sb - CR_STACK_GUARD_SIZE) - sp; #else - ret->stack_cur = sp - (sb + STACK_GUARD_SIZE); + ret->stack_cur = sp - (sb + CR_STACK_GUARD_SIZE); #endif } diff --git a/libhw/host_alarmclock.c b/libhw/host_alarmclock.c index 8b9bdcf..5f7e494 100644 --- a/libhw/host_alarmclock.c +++ b/libhw/host_alarmclock.c @@ -54,8 +54,6 @@ implements_alarmclock *bootclock = &clock_monotonic; /* Main implementation ********************************************************/ -#define UNUSED(name) - static uint64_t hostclock_get_time_ns(implements_alarmclock *_alarmclock) { struct hostclock *alarmclock = VCALL_SELF(struct hostclock, implements_alarmclock, _alarmclock); @@ -69,7 +67,7 @@ static uint64_t hostclock_get_time_ns(implements_alarmclock *_alarmclock) { return ns_from_host_ns_time(ts); } -static void hostclock_handle_sig_alarm(int UNUSED(sig), siginfo_t *info, void *UNUSED(ucontext)) { +static void hostclock_handle_sig_alarm(int LM_UNUSED(sig), siginfo_t *info, void *LM_UNUSED(ucontext)) { struct hostclock *alarmclock = info->si_value.sival_ptr; assert(alarmclock); diff --git a/libhw/host_net.c b/libhw/host_net.c index 2ba8b23..917e764 100644 --- a/libhw/host_net.c +++ b/libhw/host_net.c @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -31,11 +32,9 @@ /* common *********************************************************************/ -#define UNUSED(name) - static int hostnet_sig_io = 0; -static void hostnet_handle_sig_io(int UNUSED(sig), siginfo_t *info, void *UNUSED(ucontext)) { +static void hostnet_handle_sig_io(int LM_UNUSED(sig), siginfo_t *info, void *LM_UNUSED(ucontext)) { cr_unpause_from_intrhandler((cid_t)info->si_value.sival_int); } diff --git a/libhw/rp2040_hwtimer.c b/libhw/rp2040_hwtimer.c index 4499642..c8c281e 100644 --- a/libhw/rp2040_hwtimer.c +++ b/libhw/rp2040_hwtimer.c @@ -68,7 +68,7 @@ static uint64_t rp2040_hwtimer_get_time_ns(implements_alarmclock *) { return timer_time_us_64(timer_hw) * (NS_PER_S/US_PER_S); } -#define NS_TO_US_ROUNDUP(x) ( ( (x) + (NS_PER_S/US_PER_S)-1) / (NS_PER_S/US_PER_S) ) +#define NS_TO_US_ROUNDUP(x) LM_CEILDIV(x, NS_PER_S/US_PER_S) static void rp2040_hwtimer_intrhandler(void) { uint irq_num = __get_current_exception() - VTABLE_FIRST_IRQ; diff --git a/libhw/w5500.c b/libhw/w5500.c index f36b9cf..cebcf8e 100644 --- a/libhw/w5500.c +++ b/libhw/w5500.c @@ -105,9 +105,6 @@ /* C language *****************************************************************/ -#define UNUSED(name) -#define ARRAY_LEN(ary) (sizeof(ary)/sizeof((ary)[0])) - static const char *w5500_state_str(uint8_t state) { switch (state) { case STATE_CLOSED: return "STATE_CLOSED"; @@ -328,9 +325,9 @@ static inline void w5500_socket_close(struct _w5500_socket *socket) { static struct w5500 *w5500_chips[CONFIG_W5500_NUM] = {0}; -static void w5500_intrhandler(uint gpio, uint32_t UNUSED(event_mask)) { +static void w5500_intrhandler(uint gpio, uint32_t LM_UNUSED(event_mask)) { debugf("w5500_intrhandler(): interrupt on pin %u", gpio); - for (size_t i = 0; i < ARRAY_LEN(w5500_chips); i++) + for (size_t i = 0; i < LM_ARRAY_LEN(w5500_chips); i++) if (w5500_chips[i] && w5500_chips[i]->pin_intr == gpio) cr_sema_signal_from_intrhandler(&w5500_chips[i]->intr); } @@ -374,7 +371,7 @@ void _w5500_init(struct w5500 *chip, /* Finally, wire in the interrupt handler. */ bool saved = cr_save_and_disable_interrupts(); - for (size_t i = 0; i < ARRAY_LEN(w5500_chips); i++) { + for (size_t i = 0; i < LM_ARRAY_LEN(w5500_chips); i++) { if (w5500_chips[i] == NULL) { w5500_chips[i] = chip; break; diff --git a/libmisc/CMakeLists.txt b/libmisc/CMakeLists.txt index 02b19d5..18053dc 100644 --- a/libmisc/CMakeLists.txt +++ b/libmisc/CMakeLists.txt @@ -15,6 +15,7 @@ add_lib_test(libmisc test_assert) add_lib_test(libmisc test_endian) add_lib_test(libmisc test_hash) add_lib_test(libmisc test_log) +#add_lib_test(libmisc test_macro) # TODO add_lib_test(libmisc test_private) add_lib_test(libmisc test_rand) add_lib_test(libmisc test_vcall) diff --git a/libmisc/include/libmisc/log.h b/libmisc/include/libmisc/log.h index b4f5461..8c6d6be 100644 --- a/libmisc/include/libmisc/log.h +++ b/libmisc/include/libmisc/log.h @@ -9,6 +9,8 @@ #include /* for uint8_t */ +#include + #ifndef LOG_NAME #error "each compilation unit that includes must define LOG_NAME" #endif @@ -18,17 +20,13 @@ #else #define _LOG_NDEBUG 0 #endif -#define __LOG_STR(x) #x -#define _LOG_STR(x) __LOG_STR(x) -#define __LOG_CAT3(a, b, c) a ## b ## c -#define _LOG_CAT3(a, b, c) __LOG_CAT3(a, b, c) [[format(printf, 1, 2)]] int _log_printf(const char *format, ...); -#define n_errorf(nam, fmt, ...) do { _log_printf("error: " _LOG_STR(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) -#define n_infof(nam, fmt, ...) do { _log_printf("info : " _LOG_STR(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) -#define n_debugf(nam, fmt, ...) do { if (_LOG_CAT3(CONFIG_, nam, _DEBUG) && !_LOG_NDEBUG) \ - _log_printf("debug: " _LOG_STR(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) +#define n_errorf(nam, fmt, ...) do { _log_printf("error: " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) +#define n_infof(nam, fmt, ...) do { _log_printf("info : " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) +#define n_debugf(nam, fmt, ...) do { if (LM_CAT3_(CONFIG_, nam, _DEBUG) && !_LOG_NDEBUG) \ + _log_printf("debug: " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) #define errorf(fmt, ...) n_errorf(LOG_NAME, fmt, __VA_ARGS__) #define infof(fmt, ...) n_infof(LOG_NAME, fmt, __VA_ARGS__) diff --git a/libmisc/include/libmisc/macro.h b/libmisc/include/libmisc/macro.h new file mode 100644 index 0000000..9bb068f --- /dev/null +++ b/libmisc/include/libmisc/macro.h @@ -0,0 +1,55 @@ +/* libmisc/macro.h - Useful C preprocessor macros + * + * Copyright (C) 2024 Luke T. Shumaker + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#ifndef _LIBMISC_MACRO_H_ +#define _LIBMISC_MACRO_H_ + +/* for function definitions */ + +#define LM_UNUSED(argname) +#define LM_ALWAYS_INLINE [[gnu::always_inline]] inline +#define LM_NEVER_INLINE [[gnu::noinline]] +#define LM_FLATTEN [[gnu::flatten]] + +/* numeric */ + +#define LM_ARRAY_LEN(ary) (sizeof(ary)/sizeof((ary)[0])) +#define LM_CEILDIV(n, d) ( ((n)+(d)-1) / (d) ) +#define LM_ROUND_UP(n, d) ( LM_CEILDIV(n, d) * (d) ) /** Return `n` rounded up to the nearest multiple of `d` */ +#define LM_NEXT_POWER_OF_2(x) ((1ULL)<<((sizeof(unsigned long long)*8)-__builtin_clzll(x))) + +/* strings */ + +#define LM_STR(x) #x +#define LM_STR_(x) LM_STR(x) + +/* token pasting */ + +#define LM_CAT2(a, b) a ## b +#define LM_CAT3(a, b, c) a ## b ## c + +#define LM_CAT2_(a, b) LM_CAT2(a, b) +#define LM_CAT3_(a, b, c) LM_CAT3(a, b, c) + +/* macro arguments */ + +#define LM_SECOND(a, b, ...) b +#define LM_EAT(...) +#define LM_EXPAND(...) __VA_ARGS__ + +/* conditionals */ + +#define LM_T xxTxx +#define LM_F xxFxx + +#define LM_SENTINEL() bogus, LM_T /* a magic sentinel value */ +#define LM_IS_SENTINEL(...) LM_SECOND(__VA_ARGS__, LM_F) + +#define LM_IF(cond) LM_CAT2(_LM_IF__, cond) /* LM_IF(cond)(then)(else) */ +#define _LM_IF__xxTxx(...) __VA_ARGS__ LM_EAT +#define _LM_IF__xxFxx(...) LM_EXPAND + +#endif /* _LIBMISC_MACRO_H_ */ diff --git a/libmisc/include/libmisc/private.h b/libmisc/include/libmisc/private.h index bc5e7ad..1db7915 100644 --- a/libmisc/include/libmisc/private.h +++ b/libmisc/include/libmisc/private.h @@ -7,31 +7,10 @@ #ifndef _LIBMISC_PRIVATE_H_ #define _LIBMISC_PRIVATE_H_ -/* primitive utilities */ +#include -#define _SECOND(a, b, ...) b - -#define _CAT(a, b) a ## b -#define _CAT2(a, b) _CAT(a, b) -#define _EAT(...) -#define _EXPAND(...) __VA_ARGS__ - -/* conditionals */ - -#define _T xxTxx -#define _F xxFxx - -#define _SENTINEL() bogus, _T /* a magic sentinel value */ -#define _IS_SENTINEL(...) _SECOND(__VA_ARGS__, _F) - -#define _IF(cond) _CAT(_IF__, cond) /* _IF(cond)(then)(else) */ -#define _IF__xxTxx(...) __VA_ARGS__ _EAT -#define _IF__xxFxx(...) _EXPAND - -/* high-level functionality */ - -#define YES _SENTINEL() -#define BEGIN_PRIVATE(name) _IF(_IS_SENTINEL(IMPLEMENTATION_FOR_##name))()(struct {) -#define END_PRIVATE(name) _IF(_IS_SENTINEL(IMPLEMENTATION_FOR_##name))()(} _CAT2(_HIDDEN_, __COUNTER__);) +#define YES LM_SENTINEL() +#define BEGIN_PRIVATE(name) LM_IF(LM_IS_SENTINEL(IMPLEMENTATION_FOR_##name))()(struct {) +#define END_PRIVATE(name) LM_IF(LM_IS_SENTINEL(IMPLEMENTATION_FOR_##name))()(} LM_CAT2_(_HIDDEN_, __COUNTER__);) #endif /* _LIBMISC_PRIVATE_H_ */ diff --git a/libmisc/tests/test_assert.c b/libmisc/tests/test_assert.c index 5b28561..189f6de 100644 --- a/libmisc/tests/test_assert.c +++ b/libmisc/tests/test_assert.c @@ -9,12 +9,11 @@ #include #include +#include #include #include "test.h" -#define UNUSED(name) - /* Intercept failures and logging *********************************************/ bool global_failed; @@ -64,23 +63,20 @@ int vprintf(const char *format, va_list ap) { } \ } while (0) -#define _STR(x) #x -#define STR(x) _STR(x) - /* Actual tests ***************************************************************/ static_assert(sizeof(char) == 1); int main() { test_should_succeed(assert(true)); - test_should_fail(assert(false), "error: ASSERT: "__FILE__":"STR(__LINE__)":main(): assertion \"false\" failed\n"); + test_should_fail(assert(false), "error: ASSERT: "__FILE__":"LM_STR_(__LINE__)":main(): assertion \"false\" failed\n"); test_should_succeed(assert_msg(true, "foo")); - test_should_fail(assert_msg(false, "foo"), "error: ASSERT: "__FILE__":"STR(__LINE__)":main(): assertion \"false\" failed: foo\n"); + test_should_fail(assert_msg(false, "foo"), "error: ASSERT: "__FILE__":"LM_STR_(__LINE__)":main(): assertion \"false\" failed: foo\n"); test_should_succeed(assert_msg(true, NULL)); - test_should_fail(assert_msg(false, NULL), "error: ASSERT: "__FILE__":"STR(__LINE__)":main(): assertion \"false\" failed\n"); + test_should_fail(assert_msg(false, NULL), "error: ASSERT: "__FILE__":"LM_STR_(__LINE__)":main(): assertion \"false\" failed\n"); - test_should_fail(assert_notreached("xxx"), "error: ASSERT: "__FILE__":"STR(__LINE__)":main(): assertion \"notreached\" failed: xxx\n"); + test_should_fail(assert_notreached("xxx"), "error: ASSERT: "__FILE__":"LM_STR_(__LINE__)":main(): assertion \"notreached\" failed: xxx\n"); if (global_log) { free(global_log); -- cgit v1.2.3-2-g168b