summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-02 21:44:27 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-02 21:50:40 -0600
commitad2027ae26e5d83eb42c9edaa90f7b278f9b0d3d (patch)
tree696c1d8bca3c8a7b29aa89ec0763b2e2e5c850eb
parent06ab37743a3a657178a17d56252794073c00342b (diff)
lib9p: Exclude the MOUNT bit from masks, align masks
-rw-r--r--lib9p/9P2000.txt4
-rw-r--r--lib9p/include/lib9p/_types.h4
-rw-r--r--lib9p/types.c12
-rwxr-xr-xlib9p/types.gen36
4 files changed, 37 insertions, 19 deletions
diff --git a/lib9p/9P2000.txt b/lib9p/9P2000.txt
index 98ed952..5b5b942 100644
--- a/lib9p/9P2000.txt
+++ b/lib9p/9P2000.txt
@@ -103,8 +103,8 @@ stat = "stat_size[2]"
# "O"pen flags (flags to pass to Topen and Tcreate)
bitfield o 8
- 0/_rwx_0 # low bit of the 2-bit READ/WRITE/RDWR/EXEC enum
- 1/_rwx_1 # high bit of the 2-bit READ/WRITE/RDWR/EXEC enum
+ 0/rwx_0 # low bit of the 2-bit READ/WRITE/RDWR/EXEC enum
+ 1/rwx_1 # high bit of the 2-bit READ/WRITE/RDWR/EXEC enum
#2/unused
#3/unused
4/TRUNC
diff --git a/lib9p/include/lib9p/_types.h b/lib9p/include/lib9p/_types.h
index e22404c..576d481 100644
--- a/lib9p/include/lib9p/_types.h
+++ b/lib9p/include/lib9p/_types.h
@@ -71,8 +71,8 @@ typedef uint8_t lib9p_o_t;
#define LIB9P_O_TRUNC ((lib9p_o_t)(1<<4))
#define _LIB9P_O_UNUSED_3 ((lib9p_o_t)(1<<3))
#define _LIB9P_O_UNUSED_2 ((lib9p_o_t)(1<<2))
-#define _LIB9P_O_rwx_1 ((lib9p_o_t)(1<<1))
-#define _LIB9P_O_rwx_0 ((lib9p_o_t)(1<<0))
+#define LIB9P_O_rwx_1 ((lib9p_o_t)(1<<1))
+#define LIB9P_O_rwx_0 ((lib9p_o_t)(1<<0))
#define LIB9P_O_READ ((lib9p_o_t)(0))
#define LIB9P_O_WRITE ((lib9p_o_t)(1))
#define LIB9P_O_RDWR ((lib9p_o_t)(2))
diff --git a/lib9p/types.c b/lib9p/types.c
index 2d0bb1b..baddab3 100644
--- a/lib9p/types.c
+++ b/lib9p/types.c
@@ -347,9 +347,9 @@ static ALWAYS_INLINE bool validate_dm(struct _validate_ctx *ctx) {
if (validate_4(ctx))
return true;
static const lib9p_dm_t masks[LIB9P_VER_NUM] = {
- [LIB9P_VER_9P2000] = 0b11111100000000000000000111111111,
- [LIB9P_VER_9P2000_e] = 0b11111100000000000000000111111111,
- [LIB9P_VER_9P2000_u] = 0b11111100101111000000000111111111,
+ [LIB9P_VER_9P2000] = 0b11101100000000000000000111111111,
+ [LIB9P_VER_9P2000_e] = 0b11101100000000000000000111111111,
+ [LIB9P_VER_9P2000_u] = 0b11101100101111000000000111111111,
};
lib9p_dm_t mask = masks[ctx->ctx->version];
lib9p_dm_t val = decode_u32le(&ctx->net_bytes[ctx->net_offset-4]);
@@ -363,9 +363,9 @@ static ALWAYS_INLINE bool validate_qt(struct _validate_ctx *ctx) {
if (validate_1(ctx))
return true;
static const lib9p_qt_t masks[LIB9P_VER_NUM] = {
- [LIB9P_VER_9P2000] = 0b11111100,
- [LIB9P_VER_9P2000_e] = 0b11111100,
- [LIB9P_VER_9P2000_u] = 0b11111110,
+ [LIB9P_VER_9P2000] = 0b11101100,
+ [LIB9P_VER_9P2000_e] = 0b11101100,
+ [LIB9P_VER_9P2000_u] = 0b11101110,
};
lib9p_qt_t mask = masks[ctx->ctx->version];
lib9p_qt_t val = decode_u8le(&ctx->net_bytes[ctx->net_offset-1]);
diff --git a/lib9p/types.gen b/lib9p/types.gen
index 3e800e8..da99c36 100755
--- a/lib9p/types.gen
+++ b/lib9p/types.gen
@@ -50,6 +50,16 @@ class Bitfield:
def static_size(self) -> int:
return int((len(self.bits) + 7) / 8)
+ def bitname_is_valid(self, bitname: str, ver: str | None = None) -> bool:
+ assert bitname in self.bits
+ if not bitname:
+ return False
+ if bitname.startswith("_"):
+ return False
+ if ver and (ver not in self.names[bitname].ver):
+ return False
+ return True
+
# `msgid/structname = "member1 member2..."`
# `structname = "member1 member2..."`
@@ -137,7 +147,9 @@ re_structspec = (
re_structspec_cont = r'\s+"(?P<members>[^"]*)"'
re_bitfieldspec = r"bitfield\s+(?P<name>\S+)\s+(?P<size>[0-9]+)"
re_bitfieldspec_bit = r"(?:\s+|(?P<bitfield>\S+)\s*\+=\s*)(?P<bit>[0-9]+)/(?P<name>\S+)"
-re_bitfieldspec_alias = r"(?:\s+|(?P<bitfield>\S+)\s*\+=\s*)(?P<name>\S+)\s*=\s*(?P<val>.*)"
+re_bitfieldspec_alias = (
+ r"(?:\s+|(?P<bitfield>\S+)\s*\+=\s*)(?P<name>\S+)\s*=\s*(?P<val>.*)"
+)
def parse_file(
@@ -595,7 +607,11 @@ static ALWAYS_INLINE bool _validate_list(struct _validate_ctx *ctx,
val.ver == [*typ.names.values()][0].ver
for val in typ.names.values()
)
- if all_the_same and all(not bit for bit in typ.bits):
+ if (
+ all_the_same
+ and (len(typ.bits) == typ.static_size * 8)
+ and all(typ.bitname_is_valid(bitname) for bitname in typ.bits)
+ ):
ret += f"\treturn validate_{typ.static_size}(ctx));\n"
else:
ret += f"\t if (validate_{typ.static_size}(ctx))\n"
@@ -603,19 +619,21 @@ static ALWAYS_INLINE bool _validate_list(struct _validate_ctx *ctx,
if all_the_same:
ret += (
f"\tstatic const {c_typename(idprefix, typ)} mask = 0b"
- + ("".join("1" if b else "0" for b in reversed(typ.bits)))
+ + "".join(
+ "1" if typ.bitname_is_valid(bitname) else "0"
+ for bitname in reversed(typ.bits)
+ )
+ ";\n"
)
else:
ret += f"\tstatic const {c_typename(idprefix, typ)} masks[{c_verenum(idprefix, 'NUM')}] = {{\n"
+ verwidth = max(len(ver) for ver in versions)
for ver in sorted(versions):
ret += (
- f"\t\t[{c_verenum(idprefix, ver)}] = 0b"
- + (
- "".join(
- "1" if (b and ver in typ.names[b].ver) else "0"
- for b in reversed(typ.bits)
- )
+ f"\t\t[{c_verenum(idprefix, ver)}]{' '*(verwidth-len(ver))} = 0b"
+ + "".join(
+ "1" if typ.bitname_is_valid(bitname, ver) else "0"
+ for bitname in reversed(typ.bits)
)
+ ",\n"
)