Repository navigation
Description
Problem
The WASI clock provider rejects a successful u64 nanosecond timestamp above i64::MAX before dividing it into seconds and nanoseconds. These timestamps are representable in TimeSpec; the early check unnecessarily loses half of the host range.
Starting points: std/sys/wasm/time.wave.
Reproduction
Tested at 6257ba3eb4b9f1ab6c247a920c6e0c4b5d699331 on Linux amd64 with LLVM 21.1.8 and a compiler built from that checkout. Build it with LLVM_SYS_211_PREFIX=/usr/lib64/llvm21 cargo build --locked --jobs 2. Node.js 22.22.1 and wasm-ld were used. This is an executed Wave WASI module with controlled host imports, not an assertion about how frequently a production host returns these values.
For a self-contained test against this checkout's std, create a temporary alias (leaving installed std unchanged):
python3 - <<'PYSETUP'
from pathlib import Path
import shutil
p = Path('/tmp/wave-issue-std')
shutil.copytree('std', p, dirs_exist_ok=True)
for f in p.rglob('*.wave'):
f.write_text(f.read_text().replace('"std::', '"checkout_std::'))
PYSETUPSave as repro.wave:
import("checkout_std::sys::time")::{TimeSpec, clock_gettime};
pub fun audit() -> i64 { var value: TimeSpec; return clock_gettime(0, &value); }
fun main() -> i32 { return 0; }
target/debug/wavec build repro.wave --dep checkout_std=/tmp/wave-issue-std --target wasm32-wasip1 -O0 --emit=obj --out-dir /tmp/wave-issue-wasi
wasm-ld --no-entry --export=audit --export-memory /tmp/wave-issue-wasi/repro.o -o /tmp/wave-issue-wasi/test.wasmSave as repro.cjs and run node repro.cjs:
const fs = require('fs');
(async () => {
const module = await WebAssembly.compile(fs.readFileSync('/tmp/wave-issue-wasi/test.wasm'));
const imports = {}; let instance; let calls = 0;
for (const i of WebAssembly.Module.imports(module)) {
imports[i.module] ??= {};
imports[i.module][i.name] = () => 0;
}
imports.wasi_snapshot_preview1.clock_time_get = (clock, precision, output) => {
new DataView(instance.exports.memory.buffer).setBigUint64(output, 9223372036854775808n, true);
return 0;
};
instance = await WebAssembly.instantiate(module, imports);
console.log(String(instance.exports.audit()), 'read calls:', calls);
})().catch(e => { console.error(e); process.exit(1); });Observed: -75 read calls: 0, despite a successful host clock result that fits TimeSpec. Repeat compilation with -O2; the same behavior was observed.
The official WASI Preview 1 header defines EINTR as 27 and timestamps as u64 nanoseconds.
Scope
Split the unsigned timestamp before conversion and validate the actual destination fields. Preserve host failures and pointer validation.
Difficulty: easy.
Completion criteria
- Check 0, i64::MAX, i64::MAX+1 and u64::MAX timestamps.
- For 2^63 ns, return seconds=9223372036 and nanoseconds=854775808 successfully.
- Keep nanoseconds normalized and test null output/host error handling at O0/O2.
Activity