summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/sbc_harness/config/config.h1
-rwxr-xr-xlib9p/9p.gen11
-rw-r--r--lib9p/9p.generated.c14
-rw-r--r--lib9p/map.h1
-rw-r--r--lib9p/srv.c7
-rw-r--r--libcr/coroutine.c18
6 files changed, 40 insertions, 12 deletions
diff --git a/cmd/sbc_harness/config/config.h b/cmd/sbc_harness/config/config.h
index 1d9d441..c5ba6d8 100644
--- a/cmd/sbc_harness/config/config.h
+++ b/cmd/sbc_harness/config/config.h
@@ -55,6 +55,7 @@
# define CONFIG_COROUTINE_MEASURE_STACK 1 /* bool */
# define CONFIG_COROUTINE_PROTECT_STACK 1 /* bool */
# define CONFIG_COROUTINE_DEBUG 0 /* bool */
+# define CONFIG_COROUTINE_VALGRIND 1 /* bool */
# define CONFIG_COROUTINE_NUM (1 /* usb_common */ +\
1 /* usb_keyboard */ +\
CONFIG_NETIO_NUM_CONNS /* accept+read */ +\
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
diff --git a/libcr/coroutine.c b/libcr/coroutine.c
index df9cad3..176590a 100644
--- a/libcr/coroutine.c
+++ b/libcr/coroutine.c
@@ -32,6 +32,13 @@
#ifndef CONFIG_COROUTINE_DEBUG
# error config.h must define CONFIG_COROUTINE_DEBUG
#endif
+#ifndef CONFIG_COROUTINE_VALGRIND
+# error config.h must define CONFIG_COROUTINE_VALGRIND
+#endif
+
+#if CONFIG_COROUTINE_VALGRIND
+# include <valgrind/valgrind.h>
+#endif
/* Implementation *************************************************************/
@@ -271,6 +278,9 @@ struct coroutine {
#endif
size_t stack_size;
void *stack;
+#if CONFIG_COROUTINE_VALGRIND
+ unsigned stack_id;
+#endif
};
/* constants ******************************************************************/
@@ -433,6 +443,11 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, cr_fn_t fn, void *args) {
((uint8_t *)coroutine_table[child-1].stack)[i] =
stack_pattern[i%sizeof(stack_pattern)];
#endif
+#if CONFIG_COROUTINE_VALGRIND
+ coroutine_table[child-1].stack_id = VALGRIND_STACK_REGISTER(
+ coroutine_table[child-1].stack + STACK_GUARD_SIZE,
+ coroutine_table[child-1].stack + stack_size - STACK_GUARD_SIZE);
+#endif
coroutine_running = child;
coroutine_table[child-1].state = CR_INITIALIZING;
@@ -488,6 +503,9 @@ void coroutine_main(void) {
/* This is where we jump to from cr_exit(), and from
* nowhere else. */
assert_cid_state(coroutine_running, state == CR_NONE);
+#if CONFIG_COROUTINE_VALGRIND
+ VALGRIND_STACK_DEREGISTER(coroutine_table[coroutine_running-1].stack_id);
+#endif
free(coroutine_table[coroutine_running-1].stack);
coroutine_table[coroutine_running-1] = (struct coroutine){0};
}