Open Noc0r opened 1 year ago
@Noc0r WASIX has a wasmer_wasix::Runtime
trait which acts as an abstraction of the "Operating System", and WASIX syscalls are implemented in terms of that abstraction.
To make syscalls deterministic, we would need to add methods for getting the time and populating a buffer with random bytes and make sure syscalls go through that rather than directly calling the equivalent functions on the host.
It should be quite possible to do, however the core Wasmer team probably won't have spare capacity to make those changes in the foreseeable time. We are happy to guide PRs to implement this feature, though.
@Michael-F-Bryan I implemented logic for deterministic, can i somehow create PR for this?
@Michael-F-Bryan May be you know what can be the issue:
I'm using this quickjs engine: https://wasmer.io/saghul/quickjs
And when i'm trying to get new Date()
, then it works fine. But Math.random()
still returns random data.
I checked code of quickjs and looks like it uses syscall to gettimeofday
host function.
static void js_random_init(JSContext *ctx)
{
struct timeval tv;
gettimeofday(&tv, NULL);
ctx->random_state = ((int64_t)tv.tv_sec * 1000000) + tv.tv_usec;
/* the state must be non zero */
if (ctx->random_state == 0)
ctx->random_state = 1;
}
Summary
Can i somehow override syscalls from
wasmer-wasix
crate? I want to achieve next behavior:should return predefined values instead of real random value and real date. As i understood on logs it calls
clock_time_get
: