Skip to content

Commit 1f99fb1

Browse files
unlock monotonic clock for clock_res_get
1 parent 6b7dc6f commit 1f99fb1

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/features/clock.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,21 @@ import { WASIOptions } from "../options";
77
export function useClock(options: WASIOptions, abi: WASIAbi, memoryView: () => DataView): WebAssembly.ModuleImports {
88
return {
99
clock_res_get: (clockId: number, resolution: number) => {
10-
// There is no standard way to guarantee monotonicity in JavaScript,
11-
if (clockId !== WASIAbi.WASI_CLOCK_REALTIME) {
12-
return WASIAbi.WASI_ENOSYS;
10+
let resolutionValue: number;
11+
switch (clockId) {
12+
case WASIAbi.WASI_CLOCK_MONOTONIC: {
13+
resolutionValue = 1;
14+
break;
15+
}
16+
case WASIAbi.WASI_CLOCK_REALTIME: {
17+
resolutionValue = 1000;
18+
break;
19+
}
20+
default: return WASIAbi.WASI_ENOSYS;
1321
}
1422
const view = memoryView();
15-
view.setBigUint64(resolution, BigInt(1000), true);
23+
// 64-bit integer, but only the lower 32 bits are used.
24+
view.setUint32(resolution, resolutionValue, true);
1625
return WASIAbi.WASI_ESUCCESS;
1726
},
1827
clock_time_get: (clockId: number, precision: number, time: number) => {

test/wasi-test-suite/core.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ describe("wasi-test-suite-core", () => {
66
const suiteDir = pathJoin(__dirname, "../../third_party/wasi-test-suite/core");
77
const entries = readdirSync(suiteDir);
88
const UNSUPPORTED = [
9-
"clock_get_res-monotonic.wasm",
109
"fd_stat_get-stderr.wasm",
1110
"fd_stat_get-stdin.wasm",
1211
"fd_stat_get-stdout.wasm",

test/wasi-test-suite/libc.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ describe("wasi-test-suite-libc", () => {
66
const suiteDir = pathJoin(__dirname, "../../third_party/wasi-test-suite/libc");
77
const entries = readdirSync(suiteDir);
88
const UNSUPPORTED = [
9-
"clock_getres-monotonic.wasm",
109
"clock_gettime-monotonic.wasm",
1110
"ftruncate.wasm",
1211
]

0 commit comments

Comments
 (0)