Add a `__wasilibc_deinit_environ` function which clears the current
environment variable state to the state where next time the environment
variable functions are called, they'll reinitialize the environment.
And add a `__wasilibc_maybe_reinitialize_environ_eagerly` function to
reinitialize the environment variable state if `environ` or `_environ`
are needed.
These functions are needed by wizer to be able to suspend and resume
a program and have it read new environment variables from the host
environment; see bytecodealliance/wizer#8 for background.
Upcoming WASI snapshots omit the `PROCESS_CPUTIME` clock, since WASI has
no inherent concept of processes, and since implementations which don't
use a process for each instance don't have a way to implement it
efficiently.
However, `clock`, `times`, and `getrusage` are useful functions, so
provide optional emulated version of them, using the `MONOTONIC` clock.
This means these implementations will measure not just the program's
own CPU time, but also time spent suspended while other programs are
running.
Due to this difference in behavior, put these implementations behind
a flag. Users must pass `-D_WASI_EMULATED_PROCESS_CLOCK` and link with
`-lwasi-emulated-process-clocks` to enable them.
* Update to the next version of the `witx` crate
* Generate adapter functions instead of simply a header file to have a
place where adapter code can go.
* Implement adapters in terms of the instructions that the `witx` crate
tells us about.
* Update the interface of functions to what `witx` expects, notably
string arguments are now only taken as `char*` and `strlen` happens in
the adapter function.
* Update defined/predefined/undefined symbol lists for types that have
been updated.
Some precise generated code has changed but the actual APIs should all
be the same except for the change to not take the length of the string
in the raw WASI call, since idiomatically C doesn't pass the length of
strings around.
Eventually it's expected that the shim functions, while sometimes not
necessary today, will implement more checks and more conversions as
necessary for new APIs.
* Actually update witx submodule
* Comment how to regenerate files
* Tweak name of actual function imports
Make it a bit clearer that they're the ones that we're importing and
calling.
* Update submodule to point to WebAssembly
AT_FDCWD is a special constant in POSIX that can be passed to *at
functions to indicate the current working directory. Since the
current working directory is emulated in wasi libc, add emulated
AT_FDCWD support as well.
Fixes#42.
We've already started removing this; this just removes all remaining
ones under the libc-bottom-half directory.
These markers were originally intended to help track upstream changes,
however in practice they created a lot of clutter and weren't that
helpful. And now, upstream cloudlibc is no longer active.
CFLAGS now get initialized with the provided value for WASM_CFLAGS, or
its default.
This seems to be the intended use case of having `WASM_CFLAGS ?=` at the
top of the Makefile. Otherwise, if WASM_CFLAGS is set on the command
line, it overrides all CFLAGS and for example `--sysroot` is not added,
rendering the build invalid unless it is supplied on the make command
line.
In the musl 1.2.1 update, I made a change to disable the new code in
sinh for handling directed rounding modes, but I only incompletely
disabled it. This led to `sinh(-inf)` computing `inf` instead of `-inf`,
detected in [wasi-libc-test]. This patch fixes it.
[wasi-libc-test]: https://github.com/CraneStation/wasi-libc-test/tree/master/libc-test
See the WHATSNEW file for details. WASI libc currently uses a separate
malloc, so the new mallocng is not currently used.
This includes a few new custom changes to disable code for handling
directed rounding modes. Wasm doesn't have directed rounding modes,
so disabling this code size saves code size, something the WASI libc
project cares about!
* Add basic emulation of getcwd/chdir
This commit adds basic emulation of a current working directory to
wasi-libc. The `getcwd` and `chdir` symbols are now implemented and
available for use. The `getcwd` implementation is pretty simple in that
it just copies out of a new global, `__wasilibc_cwd`, which defaults to
`"/"`. The `chdir` implementation is much more involved and has more
ramification, however.
A new function, `make_absolute`, was added to the preopens object. Paths
stored in the preopen table are now always stored as absolute paths
instead of relative paths, and initial relative paths are interpreted as
being relative to `/`. Looking up a path to preopen now always turns it
into an absolute path, relative to the current working directory, and an
appropriate path is then returned.
The signature of `__wasilibc_find_relpath` has changed as well. It now
returns two path components, one for the absolute part and one for the
relative part. Additionally the relative part is always dynamically
allocated since it may no longer be a substring of the original input
path.
This has been tested lightly against the Rust standard library so far,
but I'm not a regular C developer so there's likely a few things to
improve!
* Amortize mallocs made in syscalls
* Avoid size bloat on programs that don't use `chdir`
* Add threading compat
* Collect `link`/`renameat` second path lookup
* Update comments about chdir.c in makefile
* Move definition of `__wasilibc_find_relpath_alloc` to header
* Expand comments
* Document the format of strings a bit more
* Fixup a few issues in path logic
* Fix GitHub Actions
This adds a new crt1-command.c startup file, which uses
[new-style command support]. Instead of calling `__wasm_call_ctors`
and `__wasm_call_dtors` directly, this lets wasm-ld automatically call
them.
This preserves the existing crt1.c, so that the same wasi-libc build
can support old-style and new-style commands, for compatibility during
the transition.
[new-style command support]: https://reviews.llvm.org/D81689
Co-authored-by: Dan Gohman <sunfish@mozilla.com>
Normally bits like this would be considered implementation details, but
in this case, `X_OK`, `W_OK`, and `R_OK` line up with `S_IXOTH`,
`S_IWOTH`, and `S_IROTH` on other systems, and those bits do have
well-known values.
This comments out a use of "protected" visibility, since
[WebAssembly doesn't support it].
[WebAssembly doesn't support it]: https://reviews.llvm.org/D81688
This emphasizes the relationship with `__wasm_call_ctors`. Note however
that while `__wasm_call_ctors` is synthesized by the linker,
`__wasm_call_dtors` is still defined by libc.
Static constructors are registered statically, but static destructors
need to be registered dynamically so that they only run if their
corresponding static constructors have run, and so that they're
ordered with respect to interleaved `atexit` calls.
* Avoid calling `poll_oneoff` with zero subscriptions.
With https://github.com/WebAssembly/WASI/pull/193 merged, WASI is moving
to make `poll_oneoff` with no arguments an error. Even though that's in
ephemeral and not yet in a snapshot, we can start to anticipate it in
libc:
- Remove the `pause` function, since WASI has no signals and thus no
way to ever wake it up short of having the host terminate it.
- Make `poll` and `pselect` return `ENOTSUP` in the case of having no
events to wait for.
* Remove `pause` from the defined-symbols.txt list.
* Fix __wasilibc_unmodified_upstream markers.
* Check for zero subscriptions, rather than zero events.
Make `poll` and `pselect` return `ENOTSUP` when asked to poll on zero
subscriptions, rather than when the systerm returns zero events.
While here, drop the `__wasilibc_unmodified_upstream` markers, which
were already pretty noisy here, and would be significantly worse with
this change.
* Add comments about the subtle relationship between nfds and nsubscriptions.
* Rewrite the comment.
* Fix code quotes.
* Rewrite the preopen functionality.
Rewrite the preopen functionality to be simpler, better organized,
and better integrated into WASI libc. Preopen support has diverged so
much from libpreopen that it no longer makes sense to track libpreopen
as an explicit upstream. And add more documentation.
* Fix missing #include.
* Fix a compilation error.
* Add support for the Reactor model.
* Mark _activate and _start as wasm exports.
* Rename _activate to _initialize.
* Don't define `_fini`.
* Rename reactor-crt1.c to crt1-reactor.c.
Before this commit, he header of a mapped area, `struct map`, was
defined as follows:
struct map {
int prot;
int flags;
off_t offset;
size_t length;
char body[];
};
Because the size and alignment of an `off_t` is 8 bytes, the entire
structure was padded to 24 bytes. However, the offset of `body` into
`struct map` was only 20 bytes. Therefore the code in mmap() and
munmap() did not agree on the offset from header to body.
This commit changes mmap() to skip the entire header, which is what
munmap() expects and what the size calculation uses.
* CI: use llvm 10.0.0 release
* ci: download mac over https, add -L flag to curl
* llvm 10 is shipping for ubuntu 18.04, which is reasonable
* llvm releases are now served from github! 🎉
* oops
* one of these days ill get it right
* love too program in yml
* missed the other spot to convert to 18.04
* mac ci: fix clang_dir
* Added utime.h
* Changes after code review
* Auto-generated expected files instead of manually editing
* Fix libpreopoen stat and utime not following symlinks correctly