diff --git a/src/sim_client.c b/src/sim_client.c index ca76aed2..15312a06 100644 --- a/src/sim_client.c +++ b/src/sim_client.c @@ -6,8 +6,6 @@ #define CHANNEL_LOOKUP_BUCKETS 4096 /* Offset in bytes from start of store struct to start of clients array (assume adjacently allocated) */ - -/* FIXME: Incorrect since buckets are also allocated */ #define STORE_CLIENTS_OFFSET (sizeof(struct sim_client_store) + (sizeof(struct sim_client_store) % alignof(struct sim_client))) @@ -22,11 +20,17 @@ READONLY struct sim_client_store _g_sim_client_store_nil = { .valid = false }; struct sim_client_store *client_store_alloc(void) { struct arena arena = arena_alloc(GIGABYTE(64)); + u64 num_channel_lookup_buckets = CHANNEL_LOOKUP_BUCKETS; + u64 channel_lookup_buckets = arena_push_array_zero(&arena, struct channel_lookup_bucket, num_channel_lookup_buckets); + struct sim_client_store *store = arena_push_zero(&arena, struct sim_client_store); - store->arena = arena; - store->num_channel_lookup_buckets = CHANNEL_LOOKUP_BUCKETS; - store->channel_lookup_buckets = arena_push_array_zero(&arena, struct channel_lookup_bucket, store->num_channel_lookup_buckets); store->clients = arena_dry_push(&arena, struct sim_client); + ASSERT((u8 *)store->clients - (u8 *)store == STORE_CLIENTS_OFFSET); /* Offset must be correct */ + + store->arena = arena; + store->num_channel_lookup_buckets = num_channel_lookup_buckets; + store->channel_lookup_buckets = channel_lookup_buckets; + return store; } diff --git a/src/sim_ent.c b/src/sim_ent.c index 53678044..706d1a39 100644 --- a/src/sim_ent.c +++ b/src/sim_ent.c @@ -44,7 +44,7 @@ struct sim_ent_store *sim_ent_store_alloc(void) store->valid = true; store->arena = arena; store->entities = arena_dry_push(&arena, struct sim_ent); - ASSERT((u64)store->entities - (u64)store == STORE_ENTITIES_OFFSET); /* Offset must be correct */ + ASSERT((u8 *)store->entities - (u8 *)store == STORE_ENTITIES_OFFSET); /* Offset must be correct */ store_make_root(store); return store; }