wasmtime: Add `nix` support for missing host function calls.

At a quick glance, the following functions are not yet provided by nix, but would be useful to have in nix for use by wasi-common: mkdirat, unlinkat, renameat, linkat, clock_getres, clock_gettime, posix_fallocate, posix_fadvise.

Currently code in wasi-common and lucet-wasi is calling libc interfaces for these functions directly, which requires unsafe code. Having nix provide these will mean the unsafe code is shifted to nix instead. This may not seem like a win on a theoretical level, but the more we can push unsafe code into dedicated utilities that do simple unsafe things with safe, testable, interfaces, the easier it is to audit everything.

I’ve marked this as “help wanted” – this is not an urgent project, but it is a nicely scoped, straightforward, and subdividable project, and it’s a good chance to see some of the low-level parts of the software stack that wasi-common is built on. And mentoring is available 😃.

Additional resources:

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 23 (10 by maintainers)

Commits related to this issue

Most upvoted comments

I think unlinkat is close to merging. I will give linkat and symlinkat a go if no one else has started these.

memcpy should be able to be replaced with std::ptr::copy_nonoverlapping

Continuing to chip away at this, also did a bit of grepping here for direct references to libc functions. I ended up with:

I need to look more into whether or not nix::dir as it is can replace the directory reading/iterating calls listed here. I think that’s the case.

Any input @sunfishcode @kubkon ? I’ll keep track of things here to the best of knowledge.

@jlb6740 noted that on the list. Go ahead!

@kevinwern That list looks good! As a minor update, sched_yield is now in upstream nix here so we just need to update wasi-common to use it.

That’s a good catch. One caveat here though. It is currently quite unfortunate that sched_yield landed in sched module in nix crate which is compiled only for linux-like hosts. This precludes its use on macos for example. I have now submitted a PR to remedy this nix-rust/nix#1090, and I guess when it lands, we can safely move away from using libc::sched_yield directly.

Definitely up to help out however I can…I remember confirming that the list @sunfishcode had at the top of this issue covered everything but I will double-check that tomorrow. Regardless, I’ll try to pick off things bit by bit.

Hey, that’s awesome, thanks! It’d be great if we could get all missing host function calls added to nix and especially those that we rely on internally in wasi-common. Would you be willing to scan the repo, find any calls that rely directly on libc, and try adding them to nix? For example, we’re still missing posix_fadvise.

Feel free to ask any questions, and I’ll be happy to help out as much as I can, and @sunfishcode can mentor and straighten me out in case I’m saying something stupid 😉