Commit Graph

14 Commits

Author SHA1 Message Date
Yuta Saito
2f088a99d8
Update _POSIX_THREAD_XX macro definitions (#494)
This is a follow-up to https://github.com/WebAssembly/wasi-libc/pull/356
2024-05-06 16:56:34 -07:00
Dan Gohman
7250bd4165
Don't define _POSIX_THREADS unless threads are enabled. (#356)
* Don't define `_POSIX_THREADS` unless threads are enabled.

Fixes #355.

* Remove `_POSIX_THREADS` from predefined-macros.txt.
2022-12-07 13:54:19 -08:00
Dan Gohman
e066a8b9d9
Add a getpagesize function. (#300)
* Add a `getpagesize` function.

This adds a `getpagesize` function. This interface is deprecated in POSIX,
but it's sufficiently widely used and not problematic in practice.

* Use musl's `getpagesize`.

* Enable the `getpagesize` declaration in unistd.h.
2022-07-11 08:27:39 -07:00
Dan Gohman
5d8a1409aa
Update to musl 1.2.3.
* Update to musl 1.2.3.

See the WHATSNEW file for details.
2022-05-24 19:31:23 -07:00
Dan Gohman
659ff41456 Implement emulated support for getpid.
Add a simple `getpid` emulation function which just returns a fixed
value, for applications that just use it for logging.
2021-04-05 16:58:36 -07:00
Dan Gohman
322bd4ff9e Update to musl 1.2.2.
See the WHATSNEW file for details.
2021-03-18 11:18:41 -07:00
Alex Crichton
5b148b6131
Add basic emulation of getcwd/chdir (#214)
* 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
2020-11-30 12:40:41 -08:00
Dan Gohman
5a7ba74c19
Avoid calling poll_oneoff with zero subscriptions. (#162)
* 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.
2020-06-01 19:00:30 -07:00
Dan Gohman
79a9b40837 Update to musl 1.1.24.
See the WHATSNEW file for details; this doesn't have any major changes
for wasi-libc; in particular, the new catgets and GLOB_TILDE features
are disabled.
2020-02-26 10:23:05 -08:00
Dan Gohman
7d2354e7d1 Disable the lseek optimization in C++.
The lseek optimization turns lseek calls into __wasilibc_tell calls when
possible, using macros and __builtin_constant_p. However, this isn't
safe in C++ code in the presence of namespaces and `using` declarations,
to just disable it in C++ for now.
2019-08-29 07:03:29 -07:00
Dan Gohman
cf366c06d1 Optimize lseek in the tell case.
`lseek(x, 0, SEEK_CUR)` has no effect other than to return the current
file offset. The patch here uses a macro with `__builtin_constant_p` to
recognize this case and rewrite it to a library call that uses `fd_tell`
rather than `fd_seek`, so that programs that don't need actual seeking
don't end up importing `fd_seek`.

This is also the first usage of `__wasi_fd_tell` in WASI libc, so this
adds it to undefined-symbols.txt.
2019-04-30 16:19:05 -07:00
Dan Gohman
9f0d8e85e3 Define _ALL_SOURCE when generating predefined-macros.txt.
And clean up various stale declarations and macros that this turned up.
In particular:
 - Don't install pthread.h or aio.h in THREAD_MODEL=single mode.
 - Don't define mkstemp and friends, since WASI currently has no support for
   temporary directories.
2019-04-15 04:05:20 -07:00
Dan Gohman
e5f14be383 Add comments explaining changes to upstream source files.
Add at least a one-line comment on every
`#ifdef __wasilibc_unmodified_upstream` briefly indicating what its
purpose is.

While here, reenable some of the code that was previously disabled when
getenv wasn't supported, as getenv is now supported.
2019-04-05 06:39:09 -07:00
Dan Gohman
320054e84f WASI libc prototype implementation.
This incoporates pieces from musl-libc, cloudlibc, cloudabi, libpreopen,
and dlmalloc, as well as a significant amount of new code.
2019-03-27 07:59:55 -07:00