diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-02 13:12:16 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-02 13:19:04 -0600 |
commit | fa7f6a5176a386f8847810f34538d5c0e56f0fb1 (patch) | |
tree | ebcab0fd2b7936a53c77ad7c6614f548b0436103 /lib9p/types.gen | |
parent | 50cfe77ace4caa424352a163f90bbf7a684b60d6 (diff) |
lib9p: Rename checksize to validate
Diffstat (limited to 'lib9p/types.gen')
-rwxr-xr-x | lib9p/types.gen | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/lib9p/types.gen b/lib9p/types.gen index 7d74558..a594e45 100755 --- a/lib9p/types.gen +++ b/lib9p/types.gen @@ -468,11 +468,11 @@ const char *{idprefix}msg_type_str(enum {idprefix}msg_type typ) {{ }} """ - # checksize_* ############################################################## + # validate_* ############################################################### ret += """ -/* checksize_* (internals of unmarshal_size()) ********************************/ +/* validate_* *****************************************************************/ -static ALWAYS_INLINE bool _checksize_net(struct _checksize_ctx *ctx, uint32_t n) { +static ALWAYS_INLINE 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 @@ -483,7 +483,7 @@ static ALWAYS_INLINE bool _checksize_net(struct _checksize_ctx *ctx, uint32_t n) return false; } -static ALWAYS_INLINE bool _checksize_host(struct _checksize_ctx *ctx, size_t n) { +static ALWAYS_INLINE 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 @@ -492,24 +492,24 @@ static ALWAYS_INLINE bool _checksize_host(struct _checksize_ctx *ctx, size_t n) return false; } -static ALWAYS_INLINE bool _checksize_list(struct _checksize_ctx *ctx, - size_t cnt, _checksize_fn_t item_fn, size_t item_host_size) { +static ALWAYS_INLINE 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++) - if (_checksize_host(ctx, item_host_size) || item_fn(ctx)) + if (_validate_size_host(ctx, item_host_size) || item_fn(ctx)) return true; return false; } -#define checksize_1(ctx) _checksize_net(ctx, 1) -#define checksize_2(ctx) _checksize_net(ctx, 2) -#define checksize_4(ctx) _checksize_net(ctx, 4) -#define checksize_8(ctx) _checksize_net(ctx, 8) +#define validate_1(ctx) _validate_size_net(ctx, 1) +#define validate_2(ctx) _validate_size_net(ctx, 2) +#define validate_4(ctx) _validate_size_net(ctx, 4) +#define validate_8(ctx) _validate_size_net(ctx, 8) """ for struct in just_structs_all(typs): inline = " ALWAYS_INLINE" if struct.msgid is None else " FLATTEN" argfn = used if struct.members else unused ret += "\n" - ret += f"static{inline} bool checksize_{struct.name}(struct _checksize_ctx *{argfn('ctx')}) {{" + ret += f"static{inline} bool validate_{struct.name}(struct _validate_ctx *{argfn('ctx')}) {{" if len(struct.members) == 0: ret += "\n\treturn false;\n" ret += "}\n" @@ -520,10 +520,10 @@ static ALWAYS_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 (validate_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 _validate_size_net(ctx, len) || _validate_size_host(ctx, len);\n" ret += "}\n" continue if struct.name == "s": # SPECIAL @@ -531,10 +531,10 @@ static ALWAYS_INLINE bool _checksize_list(struct _checksize_ctx *ctx, # (also, similar optimization to "d"). ret += "\n" ret += "\tuint32_t base_offset = ctx->net_offset;\n" - ret += "\tif (checksize_2(ctx))\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 += "\tif (_checksize_net(ctx, len) || _checksize_host(ctx, ((size_t)len)+1))\n" + ret += "\tif (_validate_size_net(ctx, len) || _validate_size_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' @@ -555,9 +555,9 @@ static ALWAYS_INLINE bool _checksize_list(struct _checksize_ctx *ctx, ret += "( " + c_vercond(idprefix, member.ver) + " && " if member.cnt is not None: assert prev_size - ret += f"_checksize_list(ctx, decode_u{prev_size*8}le(&ctx->net_bytes[ctx->net_offset-{prev_size}]), checksize_{member.typ.name}, sizeof({c_typename(idprefix, member.typ)}))" + 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(idprefix, member.typ)}))" else: - ret += f"checksize_{member.typ.name}(ctx)" + ret += f"validate_{member.typ.name}(ctx)" if member.ver != struct_versions: ret += " )" prefix = prefix1 @@ -698,11 +698,11 @@ static ALWAYS_INLINE bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) { ret += f""" /* vtables ********************************************************************/ -#define _MSG(typ) [{idprefix.upper()}TYP_##typ] = {{ \\ - .unmarshal_basesize = sizeof(struct {idprefix}msg_##typ), \\ - .unmarshal_extrasize = checksize_##typ, \\ - .unmarshal = (_unmarshal_fn_t)unmarshal_##typ, \\ - .marshal = (_marshal_fn_t)marshal_##typ, \\ +#define _MSG(typ) [{idprefix.upper()}TYP_##typ] = {{ \\ + .basesize = sizeof(struct {idprefix}msg_##typ), \\ + .validate = validate_##typ, \\ + .unmarshal = (_unmarshal_fn_t)unmarshal_##typ, \\ + .marshal = (_marshal_fn_t)marshal_##typ, \\ }} struct _vtable_version _{idprefix}vtables[{c_verenum(idprefix, 'NUM')}] = {{ |