Commit Graph

11 Commits

Author SHA1 Message Date
Dan Gohman
9efc2f4283
Lazy-initialize the environment variables. (#184)
* Lazy-initialize the environment variables.

This is the first in a series of PRs to make it easier to use WASI libc
in Wasm modules that don't have a `main` function. By initializing the
environment on demand, we avoid depending on having `__wasm_call_ctors`
run.

This uses weak symbols strategically to ensure that if `environ` is
used, it is initialized eagerly, but if only `getenv` and friends
are used, the environment is initialized lazily.

Eventually, I expect we'll have a convention for wasm modules without
main functions which will allow the `__wasm_call_ctors` function to be
called automatically, but this helps in simple cases for now.

Fixes #180.

* Add comments explaining the libc-environ-compat.h header usage.
2020-03-19 09:32:41 -07: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
2c2fc9a2fd
Don't call free on paths which are about to call _Exit. (#161)
This is a minor code-size optimization.
2020-02-14 14:02:59 -08:00
Dan Gohman
410c66070a
Use constructor functions for optional init routines. (#142)
* Use constructor functions for optional init routines.

Instead of using weak symbols, use constructor function attributes for the
environment and preopen initialization routines. This is simpler, uses
less code, and is more LTO-friendly.

* Change the constructor priorities to start at 50.

We don't currently have specific plans for other levels in the reserved
range (0-100), so leave room for both lower and higher priorities.
2019-11-25 14:04:45 -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
54102f06a9
Ignore rights in libpreopen. (#129)
Don't ignore paths which don't have the required rights. This means
that if the lookup finds a path that doesn't have the required
rights, it'll just proceed to the actual operation which will fail
with `ENOTCAPABLE`.

Intuitively, use cases which would depend on having multiple
overlapping matching paths for a given lookup and intelligently
picking the one with the required rights seems like they should
be uncommon.

This is simpler overall, and requires less code.
2019-11-21 15:49:51 -08:00
Dan Gohman
951cc3eceb
Fix unintended recursion in __wasilibc_register_preopened_fd. (#133) 2019-11-08 11:44:18 -08:00
Dan Gohman
5216983ad7
Avoid a strdup call in __wasilibc_populate_libpreopen. (#128)
* Avoid a `strdup` call in `__wasilibc_populate_libpreopen`.

Optimize `__wasilibc_populate_libpreopen` to avoid calling `strdup` in
the common case where it's called from `__wasilibc_populate_libpreopen`.

* Convert an if into a ?:.
2019-11-08 11:31:44 -08:00
Dan Gohman
70099d4d1c
Don't link in libpreopen initialization code when it isn't needed. (#127)
* Avoid linking in `populate_libpreopen` when it isn't needed.

* Merge adjacent `if`s using `&&`.
2019-11-08 11:08:22 -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
7fcc4f29df
Revamp and simplify the libpreopen code. (#110)
wasi-libc's copy of libpreopen has evolved so many local changes that
it's no longer worth keeping the upstream code structure and marking
changes with __wasilibc_unmodified_upstream.

This PR merges the source files into a single file, removes all
__wasilibc_unmodified_upstream code, eliminates the ability to
allocate multiple preopen lists, eliminates the need for
__wasilibc_init_preopen, eliminates the non-standard eaccess, and
makes several other cleanups. It also enables NDEBUG so that internal
assertions are disabled in release builds.
2019-11-04 14:56:35 -08:00