summaryrefslogtreecommitdiff
path: root/lib9p/idl.gen
diff options
context:
space:
mode:
Diffstat (limited to 'lib9p/idl.gen')
-rwxr-xr-xlib9p/idl.gen43
1 files changed, 27 insertions, 16 deletions
diff --git a/lib9p/idl.gen b/lib9p/idl.gen
index f9db2d5..7c79a28 100755
--- a/lib9p/idl.gen
+++ b/lib9p/idl.gen
@@ -498,7 +498,7 @@ LM_ALWAYS_INLINE static bool _validate_list(struct _validate_ctx *ctx,
ret += "\tuint32_t base_offset = ctx->net_offset;\n"
ret += "\tif (validate_4(ctx))\n"
ret += "\t\treturn true;\n"
- ret += "\tuint32_t len = decode_u32le(&ctx->net_bytes[base_offset]);\n"
+ ret += "\tuint32_t len = uint32le_decode(&ctx->net_bytes[base_offset]);\n"
ret += "\treturn _validate_size_net(ctx, len) || _validate_size_host(ctx, len);\n"
ret += "}\n"
continue
@@ -508,7 +508,7 @@ LM_ALWAYS_INLINE static bool _validate_list(struct _validate_ctx *ctx,
ret += "\tuint32_t base_offset = ctx->net_offset;\n"
ret += "\tif (validate_2(ctx))\n"
ret += "\t\treturn true;\n"
- ret += "\tuint16_t len = decode_u16le(&ctx->net_bytes[base_offset]);\n"
+ ret += "\tuint16_t len = uint16le_decode(&ctx->net_bytes[base_offset]);\n"
ret += "\tif (_validate_size_net(ctx, len) || _validate_size_host(ctx, ((size_t)len)))\n"
ret += "\t\treturn true;\n"
ret += "\tif (!is_valid_utf8_without_nul(&ctx->net_bytes[base_offset+2], len))\n"
@@ -526,7 +526,10 @@ LM_ALWAYS_INLINE static bool _validate_list(struct _validate_ctx *ctx,
ret += (
f"\t{c_typename(typ)} mask = {typ.name}_masks[ctx->ctx->version];\n"
)
- ret += f"\t{c_typename(typ)} val = decode_u{typ.static_size*8}le(&ctx->net_bytes[ctx->net_offset-{typ.static_size}]);\n"
+ if typ.static_size == 1:
+ ret += f"\t{c_typename(typ)} val = ctx->net_bytes[ctx->net_offset-1];\n"
+ else:
+ ret += f"\t{c_typename(typ)} val = uint{typ.static_size*8}le_decode(&ctx->net_bytes[ctx->net_offset-{typ.static_size}]);\n"
ret += f"\tif (val & ~mask)\n"
ret += f'\t\treturn lib9p_errorf(ctx->ctx, LINUX_EBADMSG, "unknown bits in {typ.name} bitfield: %#0{typ.static_size}"PRIx{typ.static_size*8}, val & ~mask);\n'
ret += "\treturn false;\n"
@@ -562,7 +565,10 @@ LM_ALWAYS_INLINE static bool _validate_list(struct _validate_ctx *ctx,
ret += "( " + c_ver_cond(member.in_versions) + " && "
if member.cnt is not None:
assert prev_size
- ret += f"_validate_list(ctx, decode_u{prev_size*8}le(&ctx->net_bytes[ctx->net_offset-{prev_size}]), validate_{member.typ.name}, sizeof({c_typename(member.typ)}))"
+ if prev_size == 1:
+ ret += f"_validate_list(ctx, ctx->net_bytes[ctx->net_offset-1], validate_{member.typ.name}, sizeof({c_typename(member.typ)}))"
+ else:
+ ret += f"_validate_list(ctx, uint{prev_size*8}le_decode(&ctx->net_bytes[ctx->net_offset-{prev_size}]), validate_{member.typ.name}, sizeof({c_typename(member.typ)}))"
else:
if member.max or member.val:
ret += "("
@@ -572,10 +578,12 @@ LM_ALWAYS_INLINE static bool _validate_list(struct _validate_ctx *ctx,
if member.name in mark_offset:
ret += "; })"
if member.max or member.val:
- bytes = member.static_size
- assert bytes
- bits = bytes * 8
- ret += f" || ({{ {member.name} = decode_u{bits}le(&ctx->net_bytes[ctx->net_offset-{bytes}]); false; }}))"
+ nbytes = member.static_size
+ assert nbytes
+ if nbytes == 1:
+ ret += f" || ({{ {member.name} = ctx->net_bytes[ctx->net_offset-1]; false; }}))"
+ else:
+ ret += f" || ({{ {member.name} = uint{nbytes*8}le_decode(&ctx->net_bytes[ctx->net_offset-{nbytes}]); false; }}))"
if member.in_versions != typ.in_versions:
ret += " )"
ret += "\n"
@@ -606,22 +614,22 @@ LM_ALWAYS_INLINE static bool _validate_list(struct _validate_ctx *ctx,
/* unmarshal_* ****************************************************************/
LM_ALWAYS_INLINE static void unmarshal_1(struct _unmarshal_ctx *ctx, uint8_t *out) {
-\t*out = decode_u8le(&ctx->net_bytes[ctx->net_offset]);
+\t*out = ctx->net_bytes[ctx->net_offset];
\tctx->net_offset += 1;
}
LM_ALWAYS_INLINE static void unmarshal_2(struct _unmarshal_ctx *ctx, uint16_t *out) {
-\t*out = decode_u16le(&ctx->net_bytes[ctx->net_offset]);
+\t*out = uint16le_decode(&ctx->net_bytes[ctx->net_offset]);
\tctx->net_offset += 2;
}
LM_ALWAYS_INLINE static void unmarshal_4(struct _unmarshal_ctx *ctx, uint32_t *out) {
-\t*out = decode_u32le(&ctx->net_bytes[ctx->net_offset]);
+\t*out = uint32le_decode(&ctx->net_bytes[ctx->net_offset]);
\tctx->net_offset += 4;
}
LM_ALWAYS_INLINE static void unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out) {
-\t*out = decode_u64le(&ctx->net_bytes[ctx->net_offset]);
+\t*out = uint64le_decode(&ctx->net_bytes[ctx->net_offset]);
\tctx->net_offset += 8;
}
"""
@@ -695,7 +703,7 @@ LM_ALWAYS_INLINE static bool marshal_1(struct _marshal_ctx *ctx, uint8_t *val) {
LM_ALWAYS_INLINE static bool marshal_2(struct _marshal_ctx *ctx, uint16_t *val) {
\tif (ctx->net_offset + 2 > ctx->ctx->max_msg_size)
\t\treturn _marshal_too_large(ctx);
-\tencode_u16le(*val, &ctx->net_bytes[ctx->net_offset]);
+\tuint16le_encode(&ctx->net_bytes[ctx->net_offset], *val);
\tctx->net_offset += 2;
\treturn false;
}
@@ -703,7 +711,7 @@ LM_ALWAYS_INLINE static bool marshal_2(struct _marshal_ctx *ctx, uint16_t *val)
LM_ALWAYS_INLINE static bool marshal_4(struct _marshal_ctx *ctx, uint32_t *val) {
\tif (ctx->net_offset + 4 > ctx->ctx->max_msg_size)
\t\treturn true;
-\tencode_u32le(*val, &ctx->net_bytes[ctx->net_offset]);
+\tuint32le_encode(&ctx->net_bytes[ctx->net_offset], *val);
\tctx->net_offset += 4;
\treturn false;
}
@@ -711,7 +719,7 @@ LM_ALWAYS_INLINE static bool marshal_4(struct _marshal_ctx *ctx, uint32_t *val)
LM_ALWAYS_INLINE static bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) {
\tif (ctx->net_offset + 8 > ctx->ctx->max_msg_size)
\t\treturn true;
-\tencode_u64le(*val, &ctx->net_bytes[ctx->net_offset]);
+\tuint64le_encode(&ctx->net_bytes[ctx->net_offset], *val);
\tctx->net_offset += 8;
\treturn false;
}
@@ -785,7 +793,10 @@ LM_ALWAYS_INLINE static bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val)
if member.val:
assert member.static_size
ret += ifdef_push(2, c_ver_ifdef(member.in_versions))
- ret += f"\t || ({{ encode_u{member.static_size*8}le({c_expr(member.val)}, &ctx->net_bytes[_{member.name}_offset]); false; }})\n"
+ if member.static_size == 1:
+ ret += f"\t || ({{ ctx->net_bytes[_{member.name}_offset] = {c_expr(member.val)}; false; }})\n"
+ else:
+ ret += f"\t || ({{ uint{member.static_size*8}le_encode(&ctx->net_bytes[_{member.name}_offset], {c_expr(member.val)}); false; }})\n"
ret += ifdef_pop(1)
ret += "\t ;\n"