summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-01-25 22:46:25 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-01-27 21:34:09 -0700
commit90254ad6e0477ff67e488958f0f297c5f85a4c56 (patch)
tree31f6968ae18ead2760abf3536ef25e0398cc3c8f
parentc5c170bac070c1bbc0e008e05783109c2e49afab (diff)
lib9p: idl: Refactor how I handle data-lengths being signed
-rw-r--r--lib9p/9p.generated.c344
-rwxr-xr-xlib9p/idl.gen10
-rw-r--r--lib9p/idl/2002-9P2000.9p9
-rw-r--r--lib9p/idl/2010-9P2000.L.9p4
-rw-r--r--lib9p/idl/2012-9P2000.e.9p7
-rw-r--r--lib9p/include/lib9p/9p.generated.h75
6 files changed, 217 insertions, 232 deletions
diff --git a/lib9p/9p.generated.c b/lib9p/9p.generated.c
index af16084..ab39102 100644
--- a/lib9p/9p.generated.c
+++ b/lib9p/9p.generated.c
@@ -375,6 +375,14 @@ LM_ALWAYS_INLINE static bool validate_d(struct _validate_ctx *ctx) {
return _validate_size_net(ctx, len) || _validate_size_host(ctx, len);
}
+LM_ALWAYS_INLINE static bool validate_d_signed(struct _validate_ctx *ctx) {
+ uint32_t base_offset = ctx->net_offset;
+ if (validate_4(ctx))
+ return true;
+ uint32_t len = uint32le_decode(&ctx->net_bytes[base_offset]);
+ return _validate_size_net(ctx, len) || _validate_size_host(ctx, len);
+}
+
LM_ALWAYS_INLINE static bool validate_s(struct _validate_ctx *ctx) {
uint32_t base_offset = ctx->net_offset;
if (validate_2(ctx))
@@ -470,15 +478,6 @@ LM_ALWAYS_INLINE static bool validate_lock_status(struct _validate_ctx *ctx) {
}
#endif /* CONFIG_9P_ENABLE_9P2000_L */
-#if CONFIG_9P_ENABLE_9P2000_e
-LM_ALWAYS_INLINE static bool validate_d_e(struct _validate_ctx *ctx) {
- return false
- || validate_4(ctx)
- || _validate_list(ctx, uint32le_decode(&ctx->net_bytes[ctx->net_offset-4]), validate_1, sizeof(uint8_t))
- ;
-}
-
-#endif /* CONFIG_9P_ENABLE_9P2000_e */
#if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_L || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u
LM_FLATTEN static bool validate_Tflush(struct _validate_ctx *ctx) {
uint32_t size;
@@ -677,23 +676,6 @@ LM_FLATTEN static bool validate_Rxattrcreate(struct _validate_ctx *ctx) {
;
}
-LM_FLATTEN static bool validate_Rreaddir(struct _validate_ctx *ctx) {
- uint32_t size;
- uint8_t typ;
- uint32_t _size_offset;
- return false
- || (({ _size_offset = ctx->net_offset; validate_4(ctx); }) || ({ size = uint32le_decode(&ctx->net_bytes[ctx->net_offset-4]); false; }))
- || (validate_1(ctx) || ({ typ = ctx->net_bytes[ctx->net_offset-1]; false; }))
- || validate_tag(ctx)
- || validate_4(ctx)
- || _validate_list(ctx, uint32le_decode(&ctx->net_bytes[ctx->net_offset-4]), validate_1, sizeof(uint8_t))
- || ({ uint32_t exp = ctx->net_offset - _size_offset; (((uint32_t)size) != exp) &&
- lib9p_errorf(ctx->ctx, LINUX_EBADMSG, "size value is wrong (actual:%"PRIu32" != correct:%"PRIu32")", (uint32_t)size, exp); })
- || ({ uint8_t exp = 41; (((uint8_t)typ) != exp) &&
- lib9p_errorf(ctx->ctx, LINUX_EBADMSG, "typ value is wrong (actual:%"PRIu8" != correct:%"PRIu8")", (uint8_t)typ, exp); })
- ;
-}
-
LM_FLATTEN static bool validate_Rfsync(struct _validate_ctx *ctx) {
uint32_t size;
uint8_t typ;
@@ -965,7 +947,41 @@ LM_FLATTEN static bool validate_Tfsync(struct _validate_ctx *ctx) {
;
}
+LM_FLATTEN static bool validate_Rreaddir(struct _validate_ctx *ctx) {
+ uint32_t size;
+ uint8_t typ;
+ uint32_t _size_offset;
+ return false
+ || (({ _size_offset = ctx->net_offset; validate_4(ctx); }) || ({ size = uint32le_decode(&ctx->net_bytes[ctx->net_offset-4]); false; }))
+ || (validate_1(ctx) || ({ typ = ctx->net_bytes[ctx->net_offset-1]; false; }))
+ || validate_tag(ctx)
+ || validate_d(ctx)
+ || ({ uint32_t exp = ctx->net_offset - _size_offset; (((uint32_t)size) != exp) &&
+ lib9p_errorf(ctx->ctx, LINUX_EBADMSG, "size value is wrong (actual:%"PRIu32" != correct:%"PRIu32")", (uint32_t)size, exp); })
+ || ({ uint8_t exp = 41; (((uint8_t)typ) != exp) &&
+ lib9p_errorf(ctx->ctx, LINUX_EBADMSG, "typ value is wrong (actual:%"PRIu8" != correct:%"PRIu8")", (uint8_t)typ, exp); })
+ ;
+}
+
#endif /* CONFIG_9P_ENABLE_9P2000_L */
+#if CONFIG_9P_ENABLE_9P2000_e
+LM_FLATTEN static bool validate_Rsread(struct _validate_ctx *ctx) {
+ uint32_t size;
+ uint8_t typ;
+ uint32_t _size_offset;
+ return false
+ || (({ _size_offset = ctx->net_offset; validate_4(ctx); }) || ({ size = uint32le_decode(&ctx->net_bytes[ctx->net_offset-4]); false; }))
+ || (validate_1(ctx) || ({ typ = ctx->net_bytes[ctx->net_offset-1]; false; }))
+ || validate_tag(ctx)
+ || validate_d(ctx)
+ || ({ uint32_t exp = ctx->net_offset - _size_offset; (((uint32_t)size) != exp) &&
+ lib9p_errorf(ctx->ctx, LINUX_EBADMSG, "size value is wrong (actual:%"PRIu32" != correct:%"PRIu32")", (uint32_t)size, exp); })
+ || ({ uint8_t exp = 153; (((uint8_t)typ) != exp) &&
+ lib9p_errorf(ctx->ctx, LINUX_EBADMSG, "typ value is wrong (actual:%"PRIu8" != correct:%"PRIu8")", (uint8_t)typ, exp); })
+ ;
+}
+
+#endif /* CONFIG_9P_ENABLE_9P2000_e */
#if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_L || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u
LM_FLATTEN static bool validate_Rread(struct _validate_ctx *ctx) {
uint32_t size;
@@ -975,7 +991,7 @@ LM_FLATTEN static bool validate_Rread(struct _validate_ctx *ctx) {
|| (({ _size_offset = ctx->net_offset; validate_4(ctx); }) || ({ size = uint32le_decode(&ctx->net_bytes[ctx->net_offset-4]); false; }))
|| (validate_1(ctx) || ({ typ = ctx->net_bytes[ctx->net_offset-1]; false; }))
|| validate_tag(ctx)
- || validate_d(ctx)
+ || validate_d_signed(ctx)
|| ({ uint32_t exp = ctx->net_offset - _size_offset; (((uint32_t)size) != exp) &&
lib9p_errorf(ctx->ctx, LINUX_EBADMSG, "size value is wrong (actual:%"PRIu32" != correct:%"PRIu32")", (uint32_t)size, exp); })
|| ({ uint8_t exp = 117; (((uint8_t)typ) != exp) &&
@@ -994,7 +1010,7 @@ LM_FLATTEN static bool validate_Twrite(struct _validate_ctx *ctx) {
|| validate_tag(ctx)
|| validate_fid(ctx)
|| (validate_8(ctx) || ({ offset = uint64le_decode(&ctx->net_bytes[ctx->net_offset-8]); false; }))
- || validate_d(ctx)
+ || validate_d_signed(ctx)
|| ({ uint32_t exp = ctx->net_offset - _size_offset; (((uint32_t)size) != exp) &&
lib9p_errorf(ctx->ctx, LINUX_EBADMSG, "size value is wrong (actual:%"PRIu32" != correct:%"PRIu32")", (uint32_t)size, exp); })
|| ({ uint8_t exp = 118; (((uint8_t)typ) != exp) &&
@@ -1268,6 +1284,25 @@ LM_FLATTEN static bool validate_Tsread(struct _validate_ctx *ctx) {
;
}
+LM_FLATTEN static bool validate_Tswrite(struct _validate_ctx *ctx) {
+ uint32_t size;
+ uint8_t typ;
+ uint32_t _size_offset;
+ return false
+ || (({ _size_offset = ctx->net_offset; validate_4(ctx); }) || ({ size = uint32le_decode(&ctx->net_bytes[ctx->net_offset-4]); false; }))
+ || (validate_1(ctx) || ({ typ = ctx->net_bytes[ctx->net_offset-1]; false; }))
+ || validate_tag(ctx)
+ || validate_4(ctx)
+ || validate_2(ctx)
+ || _validate_list(ctx, uint16le_decode(&ctx->net_bytes[ctx->net_offset-2]), validate_s, sizeof(struct lib9p_s))
+ || validate_d(ctx)
+ || ({ uint32_t exp = ctx->net_offset - _size_offset; (((uint32_t)size) != exp) &&
+ lib9p_errorf(ctx->ctx, LINUX_EBADMSG, "size value is wrong (actual:%"PRIu32" != correct:%"PRIu32")", (uint32_t)size, exp); })
+ || ({ uint8_t exp = 154; (((uint8_t)typ) != exp) &&
+ lib9p_errorf(ctx->ctx, LINUX_EBADMSG, "typ value is wrong (actual:%"PRIu8" != correct:%"PRIu8")", (uint8_t)typ, exp); })
+ ;
+}
+
#endif /* CONFIG_9P_ENABLE_9P2000_e */
#if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_L || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u
LM_ALWAYS_INLINE static bool validate_qid(struct _validate_ctx *ctx) {
@@ -1504,43 +1539,6 @@ LM_FLATTEN static bool validate_Rlock(struct _validate_ctx *ctx) {
}
#endif /* CONFIG_9P_ENABLE_9P2000_L */
-#if CONFIG_9P_ENABLE_9P2000_e
-LM_FLATTEN static bool validate_Rsread(struct _validate_ctx *ctx) {
- uint32_t size;
- uint8_t typ;
- uint32_t _size_offset;
- return false
- || (({ _size_offset = ctx->net_offset; validate_4(ctx); }) || ({ size = uint32le_decode(&ctx->net_bytes[ctx->net_offset-4]); false; }))
- || (validate_1(ctx) || ({ typ = ctx->net_bytes[ctx->net_offset-1]; false; }))
- || validate_tag(ctx)
- || validate_d_e(ctx)
- || ({ uint32_t exp = ctx->net_offset - _size_offset; (((uint32_t)size) != exp) &&
- lib9p_errorf(ctx->ctx, LINUX_EBADMSG, "size value is wrong (actual:%"PRIu32" != correct:%"PRIu32")", (uint32_t)size, exp); })
- || ({ uint8_t exp = 153; (((uint8_t)typ) != exp) &&
- lib9p_errorf(ctx->ctx, LINUX_EBADMSG, "typ value is wrong (actual:%"PRIu8" != correct:%"PRIu8")", (uint8_t)typ, exp); })
- ;
-}
-
-LM_FLATTEN static bool validate_Tswrite(struct _validate_ctx *ctx) {
- uint32_t size;
- uint8_t typ;
- uint32_t _size_offset;
- return false
- || (({ _size_offset = ctx->net_offset; validate_4(ctx); }) || ({ size = uint32le_decode(&ctx->net_bytes[ctx->net_offset-4]); false; }))
- || (validate_1(ctx) || ({ typ = ctx->net_bytes[ctx->net_offset-1]; false; }))
- || validate_tag(ctx)
- || validate_4(ctx)
- || validate_2(ctx)
- || _validate_list(ctx, uint16le_decode(&ctx->net_bytes[ctx->net_offset-2]), validate_s, sizeof(struct lib9p_s))
- || validate_d_e(ctx)
- || ({ uint32_t exp = ctx->net_offset - _size_offset; (((uint32_t)size) != exp) &&
- lib9p_errorf(ctx->ctx, LINUX_EBADMSG, "size value is wrong (actual:%"PRIu32" != correct:%"PRIu32")", (uint32_t)size, exp); })
- || ({ uint8_t exp = 154; (((uint8_t)typ) != exp) &&
- lib9p_errorf(ctx->ctx, LINUX_EBADMSG, "typ value is wrong (actual:%"PRIu8" != correct:%"PRIu8")", (uint8_t)typ, exp); })
- ;
-}
-
-#endif /* CONFIG_9P_ENABLE_9P2000_e */
#if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u
LM_ALWAYS_INLINE static bool validate_stat(struct _validate_ctx *ctx) {
uint16_t stat_size;
@@ -1864,6 +1862,15 @@ LM_ALWAYS_INLINE static void unmarshal_d(struct _unmarshal_ctx *ctx, struct lib9
unmarshal_1(ctx, (uint8_t *)&out->dat[i]);
}
+LM_ALWAYS_INLINE static void unmarshal_d_signed(struct _unmarshal_ctx *ctx, struct lib9p_d_signed *out) {
+ memset(out, 0, sizeof(*out));
+ unmarshal_4(ctx, &out->len);
+ out->dat = ctx->extra;
+ ctx->extra += sizeof(out->dat[0]) * out->len;
+ for (typeof(out->len) i = 0; i < out->len; i++)
+ unmarshal_1(ctx, (uint8_t *)&out->dat[i]);
+}
+
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);
@@ -1920,17 +1927,6 @@ LM_ALWAYS_INLINE static void unmarshal_lock_status(struct _unmarshal_ctx *ctx, l
}
#endif /* CONFIG_9P_ENABLE_9P2000_L */
-#if CONFIG_9P_ENABLE_9P2000_e
-LM_ALWAYS_INLINE static void unmarshal_d_e(struct _unmarshal_ctx *ctx, struct lib9p_d_e *out) {
- memset(out, 0, sizeof(*out));
- unmarshal_4(ctx, &out->len);
- out->dat = ctx->extra;
- ctx->extra += sizeof(out->dat[0]) * out->len;
- for (typeof(out->len) i = 0; i < out->len; i++)
- unmarshal_1(ctx, &out->dat[i]);
-}
-
-#endif /* CONFIG_9P_ENABLE_9P2000_e */
#if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_L || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u
LM_FLATTEN static void unmarshal_Tflush(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tflush *out) {
memset(out, 0, sizeof(*out));
@@ -2033,18 +2029,6 @@ LM_FLATTEN static void unmarshal_Rxattrcreate(struct _unmarshal_ctx *ctx, struct
unmarshal_tag(ctx, &out->tag);
}
-LM_FLATTEN static void unmarshal_Rreaddir(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rreaddir *out) {
- memset(out, 0, sizeof(*out));
- ctx->net_offset += 4;
- ctx->net_offset += 1;
- unmarshal_tag(ctx, &out->tag);
- unmarshal_4(ctx, &out->count);
- out->data = ctx->extra;
- ctx->extra += sizeof(out->data[0]) * out->count;
- for (typeof(out->count) i = 0; i < out->count; i++)
- unmarshal_1(ctx, &out->data[i]);
-}
-
LM_FLATTEN static void unmarshal_Rfsync(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rfsync *out) {
memset(out, 0, sizeof(*out));
ctx->net_offset += 4;
@@ -2182,14 +2166,32 @@ LM_FLATTEN static void unmarshal_Tfsync(struct _unmarshal_ctx *ctx, struct lib9p
unmarshal_4(ctx, &out->datasync);
}
+LM_FLATTEN static void unmarshal_Rreaddir(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rreaddir *out) {
+ memset(out, 0, sizeof(*out));
+ ctx->net_offset += 4;
+ ctx->net_offset += 1;
+ unmarshal_tag(ctx, &out->tag);
+ unmarshal_d(ctx, &out->data);
+}
+
#endif /* CONFIG_9P_ENABLE_9P2000_L */
+#if CONFIG_9P_ENABLE_9P2000_e
+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;
+ unmarshal_tag(ctx, &out->tag);
+ unmarshal_d(ctx, &out->data);
+}
+
+#endif /* CONFIG_9P_ENABLE_9P2000_e */
#if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_L || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u
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;
unmarshal_tag(ctx, &out->tag);
- unmarshal_d(ctx, &out->data);
+ unmarshal_d_signed(ctx, &out->data);
}
LM_FLATTEN static void unmarshal_Twrite(struct _unmarshal_ctx *ctx, struct lib9p_msg_Twrite *out) {
@@ -2199,7 +2201,7 @@ LM_FLATTEN static void unmarshal_Twrite(struct _unmarshal_ctx *ctx, struct lib9p
unmarshal_tag(ctx, &out->tag);
unmarshal_fid(ctx, &out->fid);
unmarshal_8(ctx, &out->offset);
- unmarshal_d(ctx, &out->data);
+ unmarshal_d_signed(ctx, &out->data);
}
LM_FLATTEN static void unmarshal_Tversion(struct _unmarshal_ctx *ctx, struct lib9p_msg_Tversion *out) {
@@ -2357,6 +2359,20 @@ LM_FLATTEN static void unmarshal_Tsread(struct _unmarshal_ctx *ctx, struct lib9p
unmarshal_s(ctx, &out->wname[i]);
}
+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;
+ unmarshal_tag(ctx, &out->tag);
+ unmarshal_4(ctx, &out->fid);
+ unmarshal_2(ctx, &out->nwname);
+ out->wname = ctx->extra;
+ ctx->extra += sizeof(out->wname[0]) * out->nwname;
+ for (typeof(out->nwname) i = 0; i < out->nwname; i++)
+ unmarshal_s(ctx, &out->wname[i]);
+ unmarshal_d(ctx, &out->data);
+}
+
#endif /* CONFIG_9P_ENABLE_9P2000_e */
#if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_L || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u
LM_ALWAYS_INLINE static void unmarshal_qid(struct _unmarshal_ctx *ctx, struct lib9p_qid *out) {
@@ -2504,30 +2520,6 @@ LM_FLATTEN static void unmarshal_Rlock(struct _unmarshal_ctx *ctx, struct lib9p_
}
#endif /* CONFIG_9P_ENABLE_9P2000_L */
-#if CONFIG_9P_ENABLE_9P2000_e
-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;
- unmarshal_tag(ctx, &out->tag);
- unmarshal_d_e(ctx, &out->data);
-}
-
-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;
- unmarshal_tag(ctx, &out->tag);
- unmarshal_4(ctx, &out->fid);
- unmarshal_2(ctx, &out->nwname);
- out->wname = ctx->extra;
- ctx->extra += sizeof(out->wname[0]) * out->nwname;
- for (typeof(out->nwname) i = 0; i < out->nwname; i++)
- unmarshal_s(ctx, &out->wname[i]);
- unmarshal_d_e(ctx, &out->data);
-}
-
-#endif /* CONFIG_9P_ENABLE_9P2000_e */
#if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u
LM_ALWAYS_INLINE static void unmarshal_stat(struct _unmarshal_ctx *ctx, struct lib9p_stat *out) {
memset(out, 0, sizeof(*out));
@@ -2755,6 +2747,16 @@ LM_ALWAYS_INLINE static bool marshal_d(struct _marshal_ctx *ctx, struct lib9p_d
;
}
+LM_ALWAYS_INLINE static bool marshal_d_signed(struct _marshal_ctx *ctx, struct lib9p_d_signed *val) {
+ return false
+ || marshal_4(ctx, &val->len)
+ || ({ bool err = false;
+ for (typeof(val->len) i = 0; i < val->len && !err; i++)
+ err = marshal_1(ctx, (uint8_t *)&val->dat[i]);
+ err; })
+ ;
+}
+
LM_ALWAYS_INLINE static bool marshal_s(struct _marshal_ctx *ctx, struct lib9p_s *val) {
return false
|| marshal_2(ctx, &val->len)
@@ -2818,18 +2820,6 @@ LM_ALWAYS_INLINE static bool marshal_lock_status(struct _marshal_ctx *ctx, lib9p
}
#endif /* CONFIG_9P_ENABLE_9P2000_L */
-#if CONFIG_9P_ENABLE_9P2000_e
-LM_ALWAYS_INLINE static bool marshal_d_e(struct _marshal_ctx *ctx, struct lib9p_d_e *val) {
- return false
- || marshal_4(ctx, &val->len)
- || ({ bool err = false;
- for (typeof(val->len) i = 0; i < val->len && !err; i++)
- err = marshal_1(ctx, &val->dat[i]);
- err; })
- ;
-}
-
-#endif /* CONFIG_9P_ENABLE_9P2000_e */
#if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_L || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u
LM_FLATTEN static bool marshal_Tflush(struct _marshal_ctx *ctx, struct lib9p_msg_Tflush *val) {
uint32_t _size_offset;
@@ -2992,23 +2982,6 @@ LM_FLATTEN static bool marshal_Rxattrcreate(struct _marshal_ctx *ctx, struct lib
;
}
-LM_FLATTEN static bool marshal_Rreaddir(struct _marshal_ctx *ctx, struct lib9p_msg_Rreaddir *val) {
- uint32_t _size_offset;
- uint32_t _typ_offset;
- return false
- || ({ _size_offset = ctx->net_offset; ({ ctx->net_offset += 4; false; }); })
- || ({ _typ_offset = ctx->net_offset; ({ ctx->net_offset += 1; false; }); })
- || marshal_tag(ctx, &val->tag)
- || marshal_4(ctx, &val->count)
- || ({ bool err = false;
- for (typeof(val->count) i = 0; i < val->count && !err; i++)
- err = marshal_1(ctx, &val->data[i]);
- err; })
- || ({ uint32le_encode(&ctx->net_bytes[_size_offset], ctx->net_offset - _size_offset); false; })
- || ({ ctx->net_bytes[_typ_offset] = 41; false; })
- ;
-}
-
LM_FLATTEN static bool marshal_Rfsync(struct _marshal_ctx *ctx, struct lib9p_msg_Rfsync *val) {
uint32_t _size_offset;
uint32_t _typ_offset;
@@ -3226,7 +3199,35 @@ LM_FLATTEN static bool marshal_Tfsync(struct _marshal_ctx *ctx, struct lib9p_msg
;
}
+LM_FLATTEN static bool marshal_Rreaddir(struct _marshal_ctx *ctx, struct lib9p_msg_Rreaddir *val) {
+ uint32_t _size_offset;
+ uint32_t _typ_offset;
+ return false
+ || ({ _size_offset = ctx->net_offset; ({ ctx->net_offset += 4; false; }); })
+ || ({ _typ_offset = ctx->net_offset; ({ ctx->net_offset += 1; false; }); })
+ || marshal_tag(ctx, &val->tag)
+ || marshal_d(ctx, &val->data)
+ || ({ uint32le_encode(&ctx->net_bytes[_size_offset], ctx->net_offset - _size_offset); false; })
+ || ({ ctx->net_bytes[_typ_offset] = 41; false; })
+ ;
+}
+
#endif /* CONFIG_9P_ENABLE_9P2000_L */
+#if CONFIG_9P_ENABLE_9P2000_e
+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
+ || ({ _size_offset = ctx->net_offset; ({ ctx->net_offset += 4; false; }); })
+ || ({ _typ_offset = ctx->net_offset; ({ ctx->net_offset += 1; false; }); })
+ || marshal_tag(ctx, &val->tag)
+ || marshal_d(ctx, &val->data)
+ || ({ uint32le_encode(&ctx->net_bytes[_size_offset], ctx->net_offset - _size_offset); false; })
+ || ({ ctx->net_bytes[_typ_offset] = 153; false; })
+ ;
+}
+
+#endif /* CONFIG_9P_ENABLE_9P2000_e */
#if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_L || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u
LM_FLATTEN static bool marshal_Rread(struct _marshal_ctx *ctx, struct lib9p_msg_Rread *val) {
uint32_t _size_offset;
@@ -3235,7 +3236,7 @@ LM_FLATTEN static bool marshal_Rread(struct _marshal_ctx *ctx, struct lib9p_msg_
|| ({ _size_offset = ctx->net_offset; ({ ctx->net_offset += 4; false; }); })
|| ({ _typ_offset = ctx->net_offset; ({ ctx->net_offset += 1; false; }); })
|| marshal_tag(ctx, &val->tag)
- || marshal_d(ctx, &val->data)
+ || marshal_d_signed(ctx, &val->data)
|| ({ uint32le_encode(&ctx->net_bytes[_size_offset], ctx->net_offset - _size_offset); false; })
|| ({ ctx->net_bytes[_typ_offset] = 117; false; })
;
@@ -3250,7 +3251,7 @@ LM_FLATTEN static bool marshal_Twrite(struct _marshal_ctx *ctx, struct lib9p_msg
|| marshal_tag(ctx, &val->tag)
|| marshal_fid(ctx, &val->fid)
|| marshal_8(ctx, &val->offset)
- || marshal_d(ctx, &val->data)
+ || marshal_d_signed(ctx, &val->data)
|| ({ uint32le_encode(&ctx->net_bytes[_size_offset], ctx->net_offset - _size_offset); false; })
|| ({ ctx->net_bytes[_typ_offset] = 118; false; })
;
@@ -3481,6 +3482,25 @@ LM_FLATTEN static bool marshal_Tsread(struct _marshal_ctx *ctx, struct lib9p_msg
;
}
+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
+ || ({ _size_offset = ctx->net_offset; ({ ctx->net_offset += 4; false; }); })
+ || ({ _typ_offset = ctx->net_offset; ({ ctx->net_offset += 1; false; }); })
+ || marshal_tag(ctx, &val->tag)
+ || marshal_4(ctx, &val->fid)
+ || marshal_2(ctx, &val->nwname)
+ || ({ bool err = false;
+ for (typeof(val->nwname) i = 0; i < val->nwname && !err; i++)
+ err = marshal_s(ctx, &val->wname[i]);
+ err; })
+ || marshal_d(ctx, &val->data)
+ || ({ uint32le_encode(&ctx->net_bytes[_size_offset], ctx->net_offset - _size_offset); false; })
+ || ({ ctx->net_bytes[_typ_offset] = 154; false; })
+ ;
+}
+
#endif /* CONFIG_9P_ENABLE_9P2000_e */
#if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_L || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u
LM_ALWAYS_INLINE static bool marshal_qid(struct _marshal_ctx *ctx, struct lib9p_qid *val) {
@@ -3684,40 +3704,6 @@ LM_FLATTEN static bool marshal_Rlock(struct _marshal_ctx *ctx, struct lib9p_msg_
}
#endif /* CONFIG_9P_ENABLE_9P2000_L */
-#if CONFIG_9P_ENABLE_9P2000_e
-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
- || ({ _size_offset = ctx->net_offset; ({ ctx->net_offset += 4; false; }); })
- || ({ _typ_offset = ctx->net_offset; ({ ctx->net_offset += 1; false; }); })
- || marshal_tag(ctx, &val->tag)
- || marshal_d_e(ctx, &val->data)
- || ({ uint32le_encode(&ctx->net_bytes[_size_offset], ctx->net_offset - _size_offset); false; })
- || ({ ctx->net_bytes[_typ_offset] = 153; false; })
- ;
-}
-
-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
- || ({ _size_offset = ctx->net_offset; ({ ctx->net_offset += 4; false; }); })
- || ({ _typ_offset = ctx->net_offset; ({ ctx->net_offset += 1; false; }); })
- || marshal_tag(ctx, &val->tag)
- || marshal_4(ctx, &val->fid)
- || marshal_2(ctx, &val->nwname)
- || ({ bool err = false;
- for (typeof(val->nwname) i = 0; i < val->nwname && !err; i++)
- err = marshal_s(ctx, &val->wname[i]);
- err; })
- || marshal_d_e(ctx, &val->data)
- || ({ uint32le_encode(&ctx->net_bytes[_size_offset], ctx->net_offset - _size_offset); false; })
- || ({ ctx->net_bytes[_typ_offset] = 154; false; })
- ;
-}
-
-#endif /* CONFIG_9P_ENABLE_9P2000_e */
#if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u
LM_ALWAYS_INLINE static bool marshal_stat(struct _marshal_ctx *ctx, struct lib9p_stat *val) {
uint32_t _stat_size_offset;
diff --git a/lib9p/idl.gen b/lib9p/idl.gen
index f154cb1..b179415 100755
--- a/lib9p/idl.gen
+++ b/lib9p/idl.gen
@@ -73,7 +73,9 @@ def c_ver_cond(versions: set[str]) -> str:
def c_typename(typ: idl.Type, parent: idl.Type | None = None) -> str:
match typ:
case idl.Primitive():
- if typ.value == 1 and parent and parent.name in ["d", "s"]: # SPECIAL
+ if (
+ typ.value == 1 and parent and parent.name in ["d", "d_signed", "s"]
+ ): # SPECIAL
return "[[gnu::nonstring]] char"
return f"uint{typ.value*8}_t"
case idl.Number():
@@ -499,7 +501,7 @@ LM_ALWAYS_INLINE static bool _validate_list(struct _validate_ctx *ctx,
ret += ifdef_push(1, c_ver_ifdef(typ.in_versions))
ret += f"{inline} static bool validate_{typ.name}(struct _validate_ctx *{argfn('ctx')}) {{\n"
- if typ.name == "d": # SPECIAL
+ if typ.name == "d" or typ.name == "d_signed": # SPECIAL
# Optimize... maybe the compiler could figure out to do
# this, but let's make it obvious.
ret += "\tuint32_t base_offset = ctx->net_offset;\n"
@@ -672,7 +674,7 @@ LM_ALWAYS_INLINE static void unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *o
ret += f"out->{member.name} = ctx->extra;\n"
ret += f"{prefix}ctx->extra += sizeof(out->{member.name}[0]) * out->{member.cnt.name};\n"
ret += f"{prefix}for (typeof(out->{member.cnt.name}) i = 0; i < out->{member.cnt.name}; i++)\n"
- if typ.name in ["d", "s"]: # SPECIAL
+ if typ.name in ["d", "d_signed", "s"]: # SPECIAL
# Special-case is that we cast from `char` to `uint8_t`.
ret += f"{prefix}\tunmarshal_{member.typ.name}(ctx, (uint8_t *)&out->{member.name}[i]);\n"
else:
@@ -775,7 +777,7 @@ LM_ALWAYS_INLINE static bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val)
ret += "({ bool err = false;\n"
ret += f"\t for (typeof(val->{member.cnt.name}) i = 0; i < val->{member.cnt.name} && !err; i++)\n"
ret += "\t \terr = "
- if typ.name in ["d", "s"]: # SPECIAL
+ if typ.name in ["d", "d_signed", "s"]: # SPECIAL
# Special-case is that we cast from `char` to `uint8_t`.
ret += f"marshal_{member.typ.name}(ctx, (uint8_t *)&val->{member.name}[i]);\n"
else:
diff --git a/lib9p/idl/2002-9P2000.9p b/lib9p/idl/2002-9P2000.9p
index c1cd74b..f0df7d1 100644
--- a/lib9p/idl/2002-9P2000.9p
+++ b/lib9p/idl/2002-9P2000.9p
@@ -27,8 +27,11 @@ num tag = 2
num fid = 4
"NOFID = ~0"
+# data - u32le `n`, then `n` bytes of data
+struct d = "len[4] len*(dat[1])"
+
# data - s32le `n`, then `n` bytes of data
-struct d = "len[4,max=s32_max] len*(dat[1])"
+struct d_signed = "len[4,max=s32_max] len*(dat[1])"
# string - u16le `n`, then `n` bytes of UTF-8, without any nul-bytes
struct s = "len[2] len*(utf8[1])"
@@ -142,8 +145,8 @@ msg Ropen = "size[4,val=end-&size] typ[1,val=113] tag[tag] qid[qid] iounit[4]
msg Tcreate = "size[4,val=end-&size] typ[1,val=114] tag[tag] fid[fid] name[s] perm[dm] mode[o]"
msg Rcreate = "size[4,val=end-&size] typ[1,val=115] tag[tag] qid[qid] iounit[4]"
msg Tread = "size[4,val=end-&size] typ[1,val=116] tag[tag] fid[fid] offset[8,max=s64_max] count[4,max=s32_max]"
-msg Rread = "size[4,val=end-&size] typ[1,val=117] tag[tag] data[d]" # for directories `data` is the sequence "cnt*(entries[stat])"
-msg Twrite = "size[4,val=end-&size] typ[1,val=118] tag[tag] fid[fid] offset[8,max=s64_max] data[d]"
+msg Rread = "size[4,val=end-&size] typ[1,val=117] tag[tag] data[d_signed]" # for directories `data` is the sequence "cnt*(entries[stat])"
+msg Twrite = "size[4,val=end-&size] typ[1,val=118] tag[tag] fid[fid] offset[8,max=s64_max] data[d_signed]"
msg Rwrite = "size[4,val=end-&size] typ[1,val=119] tag[tag] count[4]"
msg Tclunk = "size[4,val=end-&size] typ[1,val=120] tag[tag] fid[fid]"
msg Rclunk = "size[4,val=end-&size] typ[1,val=121] tag[tag]"
diff --git a/lib9p/idl/2010-9P2000.L.9p b/lib9p/idl/2010-9P2000.L.9p
index 8edf18d..3e5db69 100644
--- a/lib9p/idl/2010-9P2000.L.9p
+++ b/lib9p/idl/2010-9P2000.L.9p
@@ -7,7 +7,7 @@
# https://github.com/chaos/diod/blob/master/protocol.md
version "9P2000.L"
-from ./2002-9P2000.9p import tag, fid, s, d, qt, qid
+from ./2002-9P2000.9p import tag, fid, s, d, d_signed, qt, qid
from ./2002-9P2000.9p import Rerror
from ./2002-9P2000.9p import Tversion, Rversion, Tflush, Rflush, Twalk, Rwalk, Tread, Rread, Twrite, Rwrite, Tclunk, Rclunk, Tremove, Rremove
from ./2005-9P2000.u.9p import nuid, Tauth, Rauth, Tattach, Rattach
@@ -89,7 +89,7 @@ msg Txattrcreate = "size[4,val=end-&size] typ[1,val=32] tag[tag] fid[fid] name[s
msg Rxattrcreate = "size[4,val=end-&size] typ[1,val=33] tag[tag]"
#...
msg Treaddir = "size[4,val=end-&size] typ[1,val=40] tag[tag] fid[fid] offset[8] count[4]"
-msg Rreaddir = "size[4,val=end-&size] typ[1,val=41] tag[tag] count[4] count*(data[1])" # data is "qid[qid] offset[8] type[1] name[s]"
+msg Rreaddir = "size[4,val=end-&size] typ[1,val=41] tag[tag] data[d]" # data is "qid[qid] offset[8] type[1] name[s]"
#...
msg Tfsync = "size[4,val=end-&size] typ[1,val=50] tag[tag] fid[fid] datasync[4]"
msg Rfsync = "size[4,val=end-&size] typ[1,val=51] tag[tag]"
diff --git a/lib9p/idl/2012-9P2000.e.9p b/lib9p/idl/2012-9P2000.e.9p
index aba4e66..ef80796 100644
--- a/lib9p/idl/2012-9P2000.e.9p
+++ b/lib9p/idl/2012-9P2000.e.9p
@@ -10,12 +10,9 @@ version "9P2000.e"
from ./2002-9P2000.9p import *
-# like 9P2000 `d`, but without the s32_max limit
-struct d_e = "len[4] len*(dat[1])"
-
msg Tsession = "size[4,val=end-&size] typ[1,val=150] tag[tag] key[8]"
msg Rsession = "size[4,val=end-&size] typ[1,val=151] tag[tag]"
msg Tsread = "size[4,val=end-&size] typ[1,val=152] tag[tag] fid[4] nwname[2] nwname*(wname[s])"
-msg Rsread = "size[4,val=end-&size] typ[1,val=153] tag[tag] data[d_e]"
-msg Tswrite = "size[4,val=end-&size] typ[1,val=154] tag[tag] fid[4] nwname[2] nwname*(wname[s]) data[d_e]"
+msg Rsread = "size[4,val=end-&size] typ[1,val=153] tag[tag] data[d]"
+msg Tswrite = "size[4,val=end-&size] typ[1,val=154] tag[tag] fid[4] nwname[2] nwname*(wname[s]) data[d]"
msg Rswrite = "size[4,val=end-&size] typ[1,val=155] tag[tag] count[4]"
diff --git a/lib9p/include/lib9p/9p.generated.h b/lib9p/include/lib9p/9p.generated.h
index c33ab26..105cafc 100644
--- a/lib9p/include/lib9p/9p.generated.h
+++ b/lib9p/include/lib9p/9p.generated.h
@@ -144,12 +144,18 @@ typedef uint16_t lib9p_tag_t;
typedef uint32_t lib9p_fid_t;
#define LIB9P_FID_NOFID ((lib9p_fid_t)UINT32_C(~0))
-/* min_size = 4 ; max_size = 2,147,483,651 */
+/* min_size = 4 ; max_size = 4,294,967,299 (warning: >UINT32_MAX) */
struct lib9p_d {
uint32_t len;
[[gnu::nonstring]] char *dat;
};
+/* min_size = 4 ; max_size = 2,147,483,651 */
+struct lib9p_d_signed {
+ uint32_t len;
+ [[gnu::nonstring]] char *dat;
+};
+
/* min_size = 2 ; max_size = 65,537 */
struct lib9p_s {
uint16_t len;
@@ -406,14 +412,6 @@ typedef uint8_t lib9p_lock_status_t;
#define LIB9P_LOCK_STATUS_GRACE ((lib9p_lock_status_t)UINT8_C(3))
#endif /* CONFIG_9P_ENABLE_9P2000_L */
-#if CONFIG_9P_ENABLE_9P2000_e
-/* min_size = 4 ; max_size = 4,294,967,299 (warning: >UINT32_MAX) */
-struct lib9p_d_e {
- uint32_t len;
- uint8_t *dat;
-};
-
-#endif /* CONFIG_9P_ENABLE_9P2000_e */
#if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_L || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u
/* size = 9 */
struct lib9p_msg_Tflush {
@@ -492,13 +490,6 @@ struct lib9p_msg_Rxattrcreate {
lib9p_tag_t tag;
};
-/* min_size = 11 ; max_size = 4,294,967,306 (warning: >UINT32_MAX) */
-struct lib9p_msg_Rreaddir {
- lib9p_tag_t tag;
- uint32_t count;
- uint8_t *data;
-};
-
/* size = 7 */
struct lib9p_msg_Rfsync {
lib9p_tag_t tag;
@@ -604,20 +595,34 @@ struct lib9p_msg_Tfsync {
uint32_t datasync;
};
+/* min_size = 11 ; max_size = 4,294,967,306 (warning: >UINT32_MAX) */
+struct lib9p_msg_Rreaddir {
+ lib9p_tag_t tag;
+ struct lib9p_d data;
+};
+
#endif /* CONFIG_9P_ENABLE_9P2000_L */
+#if CONFIG_9P_ENABLE_9P2000_e
+/* min_size = 11 ; max_size = 4,294,967,306 (warning: >UINT32_MAX) */
+struct lib9p_msg_Rsread {
+ lib9p_tag_t tag;
+ struct lib9p_d data;
+};
+
+#endif /* CONFIG_9P_ENABLE_9P2000_e */
#if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_L || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u
/* min_size = 11 ; max_size = 2,147,483,658 */
struct lib9p_msg_Rread {
- lib9p_tag_t tag;
- struct lib9p_d data;
+ lib9p_tag_t tag;
+ struct lib9p_d_signed data;
};
/* min_size = 23 ; max_size = 2,147,483,670 */
struct lib9p_msg_Twrite {
- lib9p_tag_t tag;
- lib9p_fid_t fid;
- uint64_t offset;
- struct lib9p_d data;
+ lib9p_tag_t tag;
+ lib9p_fid_t fid;
+ uint64_t offset;
+ struct lib9p_d_signed data;
};
/* min_size = 13 ; max_size = 65,548 */
@@ -744,6 +749,15 @@ struct lib9p_msg_Tsread {
struct lib9p_s *wname;
};
+/* min_size = 17 ; max_size = 8,589,934,607 (warning: >UINT32_MAX) */
+struct lib9p_msg_Tswrite {
+ lib9p_tag_t tag;
+ uint32_t fid;
+ uint16_t nwname;
+ struct lib9p_s *wname;
+ struct lib9p_d data;
+};
+
#endif /* CONFIG_9P_ENABLE_9P2000_e */
#if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_L || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u
/* size = 13 */
@@ -875,23 +889,6 @@ struct lib9p_msg_Rlock {
};
#endif /* CONFIG_9P_ENABLE_9P2000_L */
-#if CONFIG_9P_ENABLE_9P2000_e
-/* min_size = 11 ; max_size = 4,294,967,306 (warning: >UINT32_MAX) */
-struct lib9p_msg_Rsread {
- lib9p_tag_t tag;
- struct lib9p_d_e data;
-};
-
-/* min_size = 17 ; max_size = 8,589,934,607 (warning: >UINT32_MAX) */
-struct lib9p_msg_Tswrite {
- lib9p_tag_t tag;
- uint32_t fid;
- uint16_t nwname;
- struct lib9p_s *wname;
- struct lib9p_d_e data;
-};
-
-#endif /* CONFIG_9P_ENABLE_9P2000_e */
#if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u
/* LIB9P_VER_9P2000 : min_size = 49 ; max_size = 262,189 */
/* LIB9P_VER_9P2000_e: min_size = 49 ; max_size = 262,189 */