orangeC23 added the bug label to Issue #7419.
orangeC23 opened issue #7419:
Steps to Reproduce
(1) The cfile is :
#define _POSIX_C_SOURCE 199309L #include <stdio.h> #include <stdlib.h> #include <time.h> int clock_time_get(clockid_t clock_id) { struct timespec tp; if (clock_gettime(clock_id, &tp) == 0) { printf("Successfully get the clock time.\n"); printf("seconds: %ld\n", tp.tv_sec); printf("nano seconds: %ld\n", tp.tv_nsec); } else { perror("Failed to get the clock time.\n"); return 1; } return 0; } int clock_time_geto2Ei6c4mXI (){ clockid_t clock_id = CLOCK_MONOTONIC; return clock_time_get(clock_id); } int main() { clock_time_geto2Ei6c4mXI (); }
(2)compile the c file into wasm: ./wasi-sdk-16.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-16.0/share/wasi-sysroot clock.c -o clock.wasm
(3)exeute clock.wasm
wasmtime run clock.wasmExpected Results
Using gcc clock.c -o clock and ./clock to execute get the following result:
Successfully get the clock time.
seconds: 17709947
nano seconds: 519650825And wamr, wasmedge,wasmer also print the above message.
Actual Results
wasmtime prints:
Successfully get the clock time.
seconds: 0
nano seconds: 1053984wasmtime print the seconds is zero ? I'm not sure whether this is a bug.
Sorry for bothering you. Thanks a lot !Versions and Environment
wasmtime 13.0.0
Operating system: Ubuntu 20.04Architecture: x86_64
bjorn3 commented on issue #7419:
https://github.com/bytecodealliance/wasmtime/blob/2f83f97c9f4f7f98750eb2be19a336339da931e2/crates/wasi-common/src/snapshots/preview_1.rs#L97-L100 It is supposed to work at least. Not sure what the issue is here.
alexcrichton closed issue #7419:
Steps to Reproduce
(1) The cfile is :
#define _POSIX_C_SOURCE 199309L #include <stdio.h> #include <stdlib.h> #include <time.h> int clock_time_get(clockid_t clock_id) { struct timespec tp; if (clock_gettime(clock_id, &tp) == 0) { printf("Successfully get the clock time.\n"); printf("seconds: %ld\n", tp.tv_sec); printf("nano seconds: %ld\n", tp.tv_nsec); } else { perror("Failed to get the clock time.\n"); return 1; } return 0; } int clock_time_geto2Ei6c4mXI (){ clockid_t clock_id = CLOCK_MONOTONIC; return clock_time_get(clock_id); } int main() { clock_time_geto2Ei6c4mXI (); }
(2)compile the c file into wasm: ./wasi-sdk-16.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-16.0/share/wasi-sysroot clock.c -o clock.wasm
(3)exeute clock.wasm
wasmtime run clock.wasmExpected Results
Using gcc clock.c -o clock and ./clock to execute get the following result:
Successfully get the clock time.
seconds: 17709947
nano seconds: 519650825And wamr, wasmedge,wasmer also print the above message.
Actual Results
wasmtime prints:
Successfully get the clock time.
seconds: 0
nano seconds: 1053984wasmtime print the seconds is zero ? I'm not sure whether this is a bug.
Sorry for bothering you. Thanks a lot !Versions and Environment
wasmtime 13.0.0
Operating system: Ubuntu 20.04Architecture: x86_64
alexcrichton commented on issue #7419:
The monotonic clock is relative to an arbitrary point in time, and Wasmtime's arbitrary point is the start of the instance itself, so what's happening here is the time is being measured shortly after the instance starts. This is to avoid leaking information about the host's own clocks to the guest which doesn't need to know that information by default.
alexcrichton commented on issue #7419:
@orangeC23 is there perhaps something we can help you out with at a higher level? You've opened a number of issues here which appear to be mostly poking at WASI behavior. Is there a way we could perhaps help out with that and/or help steer? I'm curious how these programs are coming into existence for example and if it might be good to file issues for clarifications/etc on the WASI specifications themselves for example.
Last updated: Dec 23 2024 at 12:05 UTC