Commit Graph

25 Commits

Author SHA1 Message Date
Dan Gohman
dd010beea5
Avoid using cast expressions in WASI API constants. (#148)
Cast expressions aren't valid to use in some preprocessor constants, so
change the constants to use `UINT32_C` etc. instead of casts.

Fixes #146.
2019-12-16 13:29:06 -08:00
Sam Clegg
f645f498df Update signal macros after upgrade to snapshot1 (#144)
This should probably have been part of #140 but we don't actually
support signals so this doesn't get much testing I imagine.

The old names like `__WASI_SIGBUS` no longer exist and the new names
look like `__WASI_SIGNAL_BUS`.
2019-12-03 09:23:40 -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
Pat Hickey
fe130532ae
c header generation updated for reorganized witx ast (#139) 2019-11-22 13:06:12 -05:00
Dan Gohman
cd74e1d988
Correct the version of #136 on master (#141)
* Add the WASI repo as a submodule.

Also, add the witx filenames to the generated output, and just have
`cargo run` auto-generate the api.h header, rather than using clap.

* Switch witx to a path dependency.

* Add a test.

* Add a test that the generated file is in sync with the generator.

* Enable CI testing with Github Actions.

* Fix the name of the wasi-headers directory.

* Enable submodules.

* Add a diff mechanism to help explain failures.

* Sort the inputs for display.

* More debugging.

* More debugging.

* Add a .gitattributes file forcing text files to be eol=lf.

Most editors these days can deal with eof=lf files, even on Windows, and
this avoids trouble with headers and other generated files differing in
line endings.
2019-11-21 20:55:26 -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
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
bdfbb54520
Call populate_environ only if we actually need environment variables. (#109)
* Link `populate_environ` only if we actually need environment variables.

This avoids linking in the environment variable initialization code,
and the __wasi_environ_sizes_get and __wasi_environ_get imports, in
programs that don't use environment variables.

This also removes the "___environ" (three underscores) alias symbol,
which is only in musl for backwards compatibility.

* Switch to //-style comments.

* If malloc fails, don't leave `__environ` pointing to an uninitialized buffer.

* Fix a memory leak if one malloc succeeds and the other fails.

* Use calloc to handle multiplication overflow.

This also handles the NULL terminator.

* Don't initialize __environ until everything has succeeded.

* Avoid leaking in case __wasi_environ_get fails.

* Handle overflow in the add too.

* Add #include <stdlib.h> for malloc etc.

* If the environment is empty, don't allocate any memory.
2019-10-22 06:02:44 -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
b7ae2fe33b WASI libc's dirent does have t_type, so define _DIRENT_HAVE_D_TYPE.
Also update predefined-macros.txt.
2019-08-29 10:22:03 -07:00
Dan Gohman
256081f628 Move the mode_t macros into their own header.
This allows them to be defined by <fcntl.h> as well, as specified by
POSIX.

This fixes a part of src/api/fcntl.c.
2019-05-10 12:37:49 -07:00
Dan Gohman
861f0d2ec8 Define O_TTY_INIT.
Define it to 0, as several popular operating systems ignore this flag.

This fixes a part of src/api/fcntl.c.
2019-05-10 12:37:31 -07:00
Dan Gohman
60cba39d11 Move the SEEK_* macros into their own header and use it from fcntl.h.
POSIX requires fcntl.h to define the SEEK_* macros, so this satisfies
that requirement. Also, this allows <stdio.h> to avoid including as much
unnecessary content.

This fixes one issue with src/api/fcntl.c.
2019-05-09 09:11:43 -07:00
Dan Gohman
46ce01276f Don't declare dup in unistd.h.
Dup isn't defined in libc.a, so don't declare it.
2019-05-09 09:07: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
124f6a4d0a Add __restrict qualifiers to the fstatat declaration.
This makes it consistent with its definition.
2019-05-07 15:03:26 -07:00
Dan Gohman
51969495ee Define TIME_UTC to be 1.
TIME_UTC is the only time base defined by the relevant standards. This
change doesn't preclude adding other time bases in the future.
2019-05-01 12:52:28 -07:00
Dan Gohman
1bdb356bef Define CLOCKS_PER_SEC to have type clock_t.
The C standard requires CLOCKS_PER_SEC to have type clock_t.
2019-05-01 12:52:28 -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
49f1a57cb8 Declare getrusage.
It's defined publicly in libc, so publicly declare it too.
2019-04-22 11:41:40 -07:00
Dan Gohman
7ba6adfc61 Fix miscellaneous lint warnings. 2019-04-15 09:47:16 -07:00
Dan Gohman
685d014446
Provide a public interface to preopened directory lookups. (#10)
* Provide a public interface to preopened directory lookups.

For users of especially non-C compilers, provide an API for looking up
preopened directories. This is used internally in WASI libc to translate
from eg. `open` to `openat`, but it can now also be used by user code.
2019-04-05 06:30:30 -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