summaryrefslogtreecommitdiff
path: root/lib9p
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-05 21:50:49 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-05 21:50:49 -0600
commit7ca16c45a2ecfbf415fffd384eb5efd32180c5da (patch)
treeeed9c8a9f56e45cfb14d7b4a574b432a01ae2491 /lib9p
parentcb108cfecb78c01ae8a2957ca5a32b58f9ddc4aa (diff)
fixes, valgrind
Diffstat (limited to 'lib9p')
-rwxr-xr-xlib9p/9p.gen11
-rw-r--r--lib9p/9p.generated.c14
-rw-r--r--lib9p/map.h1
-rw-r--r--lib9p/srv.c7
4 files changed, 21 insertions, 12 deletions
diff --git a/lib9p/9p.gen b/lib9p/9p.gen
index 2b7745e..4a8e4d1 100755
--- a/lib9p/9p.gen
+++ b/lib9p/9p.gen
@@ -750,11 +750,11 @@ static ALWAYS_INLINE void unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out)
prefix = "\t\t"
if member.cnt:
if member.ver != struct_versions:
- ret += "{\n"
- ret += f"{prefix}out->{member.name} = ctx->extra;\n"
+ ret += f"{{\n{prefix}"
+ ret += f"out->{member.name} = ctx->extra;\n"
ret += f"{prefix}ctx->extra += sizeof(out->{member.name}[0]) * out->{member.cnt};\n"
ret += f"{prefix}for (typeof(out->{member.cnt}) i = 0; i < out->{member.cnt}; i++)\n"
- if typ.name in ['d', 's']: # SPECIAL
+ if typ.name in ["d", "s"]: # SPECIAL
ret += f"{prefix}\tunmarshal_{member.typ.name}(ctx, (uint8_t *)&out->{member.name}[i]);\n"
else:
ret += f"{prefix}\tunmarshal_{member.typ.name}(ctx, &out->{member.name}[i]);\n"
@@ -764,6 +764,9 @@ static ALWAYS_INLINE void unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out)
ret += (
f"unmarshal_{member.typ.name}(ctx, &out->{member.name});\n"
)
+ if typ.name == "s": # SPECIAL
+ ret += "\tctx->extra++;\n"
+ ret += "\tout->utf8[out->len] = '\\0';\n"
ret += "}\n"
# marshal_* ################################################################
@@ -853,7 +856,7 @@ static ALWAYS_INLINE bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) {
ret += "({"
ret += f"\n{prefix2}\tbool err = false;"
ret += f"\n{prefix2}\tfor (typeof(val->{member.cnt}) i = 0; i < val->{member.cnt} && !err; i++)"
- if typ.name in ['d', 's']: # SPECIAL
+ if typ.name in ["d", "s"]: # SPECIAL
ret += f"\n{prefix2}\t\terr = marshal_{member.typ.name}(ctx, (uint8_t *)&val->{member.name}[i]);"
else:
ret += f"\n{prefix2}\t\terr = marshal_{member.typ.name}(ctx, &val->{member.name}[i]);"
diff --git a/lib9p/9p.generated.c b/lib9p/9p.generated.c
index 54e7613..1fef571 100644
--- a/lib9p/9p.generated.c
+++ b/lib9p/9p.generated.c
@@ -611,7 +611,7 @@ static ALWAYS_INLINE void unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out)
static ALWAYS_INLINE 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;
+ 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]);
@@ -620,10 +620,12 @@ static ALWAYS_INLINE void unmarshal_d(struct _unmarshal_ctx *ctx, struct lib9p_d
static ALWAYS_INLINE 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;
+ out->utf8 = ctx->extra;
ctx->extra += sizeof(out->utf8[0]) * out->len;
for (typeof(out->len) i = 0; i < out->len; i++)
unmarshal_1(ctx, (uint8_t *)&out->utf8[i]);
+ ctx->extra++;
+ out->utf8[out->len] = '\0';
}
static ALWAYS_INLINE void unmarshal_dm(struct _unmarshal_ctx *ctx, lib9p_dm_t *out) {
@@ -724,7 +726,7 @@ static FLATTEN void unmarshal_Twalk(struct _unmarshal_ctx *ctx, struct lib9p_msg
unmarshal_4(ctx, &out->fid);
unmarshal_4(ctx, &out->newfid);
unmarshal_2(ctx, &out->nwname);
- out->wname = ctx->extra;
+ 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]);
@@ -733,7 +735,7 @@ static FLATTEN void unmarshal_Twalk(struct _unmarshal_ctx *ctx, struct lib9p_msg
static FLATTEN void unmarshal_Rwalk(struct _unmarshal_ctx *ctx, struct lib9p_msg_Rwalk *out) {
memset(out, 0, sizeof(*out));
unmarshal_2(ctx, &out->nwqid);
- out->wqid = ctx->extra;
+ out->wqid = ctx->extra;
ctx->extra += sizeof(out->wqid[0]) * out->nwqid;
for (typeof(out->nwqid) i = 0; i < out->nwqid; i++)
unmarshal_qid(ctx, &out->wqid[i]);
@@ -840,7 +842,7 @@ static FLATTEN void unmarshal_Tsread(struct _unmarshal_ctx *ctx, struct lib9p_ms
memset(out, 0, sizeof(*out));
unmarshal_4(ctx, &out->fid);
unmarshal_2(ctx, &out->nwname);
- out->wname = ctx->extra;
+ 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]);
@@ -855,7 +857,7 @@ static FLATTEN void unmarshal_Tswrite(struct _unmarshal_ctx *ctx, struct lib9p_m
memset(out, 0, sizeof(*out));
unmarshal_4(ctx, &out->fid);
unmarshal_2(ctx, &out->nwname);
- out->wname = ctx->extra;
+ 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]);
diff --git a/lib9p/map.h b/lib9p/map.h
index 833f4f5..dcb6ecd 100644
--- a/lib9p/map.h
+++ b/lib9p/map.h
@@ -78,6 +78,7 @@ static VAL_T *MAP_METHOD(NAME,store)(struct NAME *m, KEY_T k, VAL_T v) {
return NULL;
for (size_t i = 0; i < ARRAY_LEN(m->items); i++)
if (!m->items[i].set) {
+ m->len++;
m->items[i].set = true;
m->items[i].key = k;
m->items[i].val = v;
diff --git a/lib9p/srv.c b/lib9p/srv.c
index 077db83..ee28b38 100644
--- a/lib9p/srv.c
+++ b/lib9p/srv.c
@@ -182,6 +182,7 @@ COROUTINE lib9p_srv_read_cr(void *_srv) {
.initialized = false,
};
for (;;) {
+ nextmsg:
/* Read the message. */
size_t done = 0;
if (read_at_least(conn.fd, buf, 4, &done))
@@ -211,7 +212,7 @@ COROUTINE lib9p_srv_read_cr(void *_srv) {
goal,
sess.max_msg_size);
respond_error(&req);
- continue;
+ goto nextmsg;
}
if (read_at_least(conn.fd, buf, goal, &done))
goto close;
@@ -225,7 +226,7 @@ COROUTINE lib9p_srv_read_cr(void *_srv) {
sess.closing = true;
cr_pause_and_yield();
assert(sess.reqs.len == 0);
- netio_close(conn.fd, false, true);
+ netio_close(conn.fd, true, true);
}
}
@@ -384,6 +385,7 @@ static void handle_Tversion(struct _lib9p_srv_req *ctx,
return;
}
+ /*
if (ctx->parent_sess->reqs.len) {
ctx->parent_sess->closing = true;
// TODO: send flush events
@@ -398,6 +400,7 @@ static void handle_Tversion(struct _lib9p_srv_req *ctx,
fidmap_del(&ctx->parent_sess->fids, fid);
}
}
+ */
// TODO: replace session with a new one?
#pragma GCC diagnostic push