Commit Graph

22 Commits

Author SHA1 Message Date
Dan Gohman
f2e779e5f1 AT_FDCWD support.
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.
2021-02-05 06:41:53 -08:00
Dan Gohman
cab0ec601e Remove __wasilibc_unmodified_upstream markers from libc-bottom-half.
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.
2021-02-04 21:22:15 -08:00
Dan Gohman
614d783e92
New-style command support. (#203)
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>
2020-10-03 14:18:39 -07: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
753cc4344d
Merge the basics component into libc-bottom-half. (#199)
We no longer have a need to maintain basics as a separate component.
Folding it into libc-bottom-half eliminates a fair amount of redundancy.
2020-06-01 16:44:05 -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
Pat Hickey
3de8c71d06 libc: change to flattened event struct 2020-02-24 11:36:05 -08:00
Pat Hickey
c2ae180dee cloudlibc & libpreopen: changes for tagged unions
we decided to abandon the upstream code guarded by
 #ifdef __wasilibc_unmodified_upstream // non-anonymous unions
because these changes are sprawling and those guards are of diminishing
importance
2020-02-24 11:36:05 -08:00
Dan Gohman
870a25121b
Remove unused cloudlibc headers. (#170) 2020-02-21 11:40:23 -08:00
Dan Gohman
446cb3f1aa
Wasi snapshot preview1 (#140)
* Make __wasi_linkcount_t a uint64_t (#134)

Refs: https://github.com/WebAssembly/WASI/pull/127

* Generate the WASI interface from witx.

This replaces the hand-maintained <wasi/core.h> header with a
<wasi/api.h> generated from witx.

Most of the churn here is caused by upstream WASI renamings; hopefully
in the future ABI updates will be less noisy.
2019-11-21 20:06:00 -08:00
Dan Gohman
deb8eae418
Don't pre-check capabilities in openat. (#130)
Rely on the WASI implementation to check capabilities flags, rather
than also checking them in the userspace `openat` implementation.

This code is admittedly getting fairly dense with `#ifdef`s, so it
may soon make sense to move this file out of the `cloudlibc`
directory and removing the upstream change markers.
2019-11-10 06:39:00 -08:00
Dan Gohman
a94d2d04e7
Avoid varargs conventions when calling open (#126)
* Add an entrypoint for calling open that bypasses the varargs.

* Add an entrypoint for calling openat that bypasses the varargs.
2019-11-04 16:37:45 -08:00
Dan Gohman
afbf94c39e
Call populate_args only if we actually need command-line arguments (#112)
* Link `populate_args` only if we actually need command-line arguments.

This avoids linking in the argv/argc initialization code,
and the __wasi_args_sizes_get and __wasi_args_get imports, in
programs that don't use command-line arguments. The way this works is,
if the user writes `int main(int argc, char *argv[])`, the argument
initialization code is loaded, and if they write `int main(void)`,
it's not loaded.

This promotes the `__original_main` mechanism into an effective contract
between the compiler and libc, which wasn't its original purpose,
however it seems to fit this purpose quite well.

* Document that `__original_main` may be the user's zero-arg `main`.
2019-10-24 17:30:46 -07:00
Dan Gohman
b59b83cbc2
Miscellaneous cleanups (#113)
* Tidy up some #include names.

* Move non-cloudlibc sources out of the cloudlibc directory.
2019-10-18 13:53:13 -07:00
Dan Gohman
1db93d1169 Switch from the cloudlibc inet_pton etc. to the musl versions.
These functions aren't specific to the underlying system call interface,
so they don't need to be in the "bottom half".

This also fixes src/functional/inet_pton.c and
src/regression/inet_pton-empty-last-field.c in musl's libc-test.
2019-05-09 09:10:57 -07:00
Dan Gohman
382b944a2e Rename __wasilibc_rmfileat to __wasilibc_unlinkat.
The POSIX terminology is that directories are "removed" while files
are "unlinked".
2019-05-07 15:04:17 -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
1cbedc6d7e Implement FD_SET, FD_CLR, etc.
Previously, FD_SET and friends were missing their actual definitions.
This provides definitions, entirely within the system headers in a
way that doesn't need instantiated out-of-line definitions.
2019-04-23 15:01:23 -07:00
Dan Gohman
538937e2c8 Remove capsicum.h; WASI libc doesn't support that API, even internally. 2019-04-23 15:01:05 -07:00
Dan Gohman
1cc98f27f5 Update to cloudlibc 8835639f27fc42d32096d59d294a0bbb857dc368.
There's no functional change here; the only change is the patch I
submitted upstream, so we can remove some local changes.
2019-04-15 09:49:02 -07:00
Dan Gohman
7ba6adfc61 Fix miscellaneous lint warnings. 2019-04-15 09:47:16 -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