Skip to content

Commit aea032f

Browse files
committed
process: static_assert timeval/rusage layout too — closes the remaining unguarded extern struct claims. rusage was the riskiest in the tree (14 hand-counted i64 pad fields to reach 144B, never verified). asserts confirm sizeof(timeval)==16 and sizeof(rusage)==144, which also proves the alignment-padding rule fs.milo's Stat relies on for its rdev->atimespec gap. wmsg/wchannel need no guard (milo-only, no c counterpart). cpuusage/hrtime smoke green
1 parent 5c28a8f commit aea032f

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/milo/runtime/entry.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ _Static_assert(offsetof(struct timespec, tv_nsec) == 8, "Timespec.tv_nsec drifte
4242
// fs.milo stats into a fixed [u8; 256] scratch buffer — it must hold a whole struct stat.
4343
_Static_assert(sizeof(struct stat) <= 256, "struct stat outgrew fs.milo's 256-byte statBuf");
4444

45+
// Same guards for process.milo's `extern struct Timeval` / `extern struct Rusage`.
46+
// Rusage is the riskiest claim in the tree: milo spells it as ru_utime/ru_stime followed
47+
// by 14 hand-counted i64 padding fields to reach 144 bytes. Note tv_usec is 4 bytes but
48+
// Timeval is 16 — the trailing 4 are alignment padding the compiler inserts, which is the
49+
// rule fs.milo's Stat relies on for its st_rdev->st_atimespec gap. Assert it, don't assume.
50+
#include <sys/resource.h>
51+
#include <sys/time.h>
52+
_Static_assert(offsetof(struct timeval, tv_sec) == 0, "Timeval.tv_sec drifted vs process.milo");
53+
_Static_assert(offsetof(struct timeval, tv_usec) == 8, "Timeval.tv_usec drifted vs process.milo");
54+
_Static_assert(sizeof(struct timeval) == 16, "Timeval is not 16B — process.milo's Rusage padding is wrong");
55+
_Static_assert(offsetof(struct rusage, ru_utime) == 0, "Rusage.ru_utime drifted vs process.milo");
56+
_Static_assert(offsetof(struct rusage, ru_stime) == 16, "Rusage.ru_stime drifted vs process.milo");
57+
_Static_assert(sizeof(struct rusage) == 144, "struct rusage is not 144B — process.milo's _p0.._pD padding is wrong");
58+
4559
extern int milo_node_main(int argc, char** argv);
4660
extern char **environ;
4761

0 commit comments

Comments
 (0)