mirror of https://github.com/WebAssembly/wasi-libc
Browse Source
* Fixes for the THREAD_MODEL=posix build * Fix expected symbols from previous commit * Enable `lock` in `random.c` when threads are enabled This uses the `_REENTRANT` definition to indicate when the `lock` should be available. * Disable `aio.h` when compiling for threads In talking to @sunfishcode about `aio.h`, this functionality is not yet a primary concern (it was already disabled in the default, single-threaded mode). Additionally, this change adds expectation lines for the new symbols/includes added and removed by `pthread.h`. This change was reached by running: ```console $ git diff --no-index expected/wasm32-wasi sysroot/share/wasm32-wasi > patch.diff # replace "sysroot/share" with "expected" in `patch.diff` $ git apply patch.diff --reject # manually fix any rejections ``` * Specify the TLS model until LLVM 15 is released The `-ftls-model` configuration can be removed once https://reviews.llvm.org/D130053 makes its way into an upstream release. * Rename `__wasi_libc_pthread_self` to `__wasilibc_pthread_self` The symbol is still undefined, though. * Add different sets of expected output based on THREAD_MODEL * Re-add trailing whitespace to `predefined-macros.txt` @sbc100 wanted to retain the whitespace trailing after certain predefined macro lines. This change restores that whitespace from upstream and re-generates the POSIX version using the following command: ```console $ git diff --no-index expected/wasm32-wasi/posix/predefined-macros.txt sysroot/share/wasm32-wasi/predefined-macros.txt | sed 's/sysroot\/share\/wasm32-wasi/expected\/wasm32-wasi\/posix/' | git apply ``` * Protect `preopens.c` against concurrent access * Only build thread-capable wasi-libc on latest version of Clang * Use `thrd_sleep` from MUSL instead of aliasing `nanosleep` * Define `pthread_setcancelstate` in `THREAD_MODEL=posix` builds There are other options here (e.g., always define the `pthread_*` symbols with stubs) but until we discuss that this is an intermediate working step. * Define a Wasm global to store `pthread_self` * Remove `g_needs_dynamic_alloc` global * Document the state of pthread support * review: de-duplicate symbols based on #314 * review: only define `__wasilibc_cwd_{un}lock` when needed * review: add #ifdefs to `__pthread_setcancelstate` * review: add additional #ifdefs to `pthread_self.c` * review: put lock definition behind #ifdef _REENTRANT * review: remove pthread_setcancelstate.c * review: re-fix indentation * review: alias __clock_nanosleep in bottom half * review: remove extra line Co-authored-by: Sam Clegg <sbc@chromium.org>pull/316/head
Andrew Brown
2 years ago
committed by
GitHub
26 changed files with 4973 additions and 46 deletions
File diff suppressed because it is too large
@ -0,0 +1,171 @@ |
|||
#include <__errno.h> |
|||
#include <__errno_values.h> |
|||
#include <__fd_set.h> |
|||
#include <__function___isatty.h> |
|||
#include <__functions_malloc.h> |
|||
#include <__functions_memcpy.h> |
|||
#include <__header_dirent.h> |
|||
#include <__header_fcntl.h> |
|||
#include <__header_inttypes.h> |
|||
#include <__header_netinet_in.h> |
|||
#include <__header_poll.h> |
|||
#include <__header_stdlib.h> |
|||
#include <__header_string.h> |
|||
#include <__header_sys_ioctl.h> |
|||
#include <__header_sys_resource.h> |
|||
#include <__header_sys_socket.h> |
|||
#include <__header_sys_stat.h> |
|||
#include <__header_time.h> |
|||
#include <__header_unistd.h> |
|||
#include <__macro_FD_SETSIZE.h> |
|||
#include <__macro_PAGESIZE.h> |
|||
#include <__mode_t.h> |
|||
#include <__seek.h> |
|||
#include <__struct_dirent.h> |
|||
#include <__struct_in6_addr.h> |
|||
#include <__struct_in_addr.h> |
|||
#include <__struct_iovec.h> |
|||
#include <__struct_msghdr.h> |
|||
#include <__struct_pollfd.h> |
|||
#include <__struct_rusage.h> |
|||
#include <__struct_sockaddr.h> |
|||
#include <__struct_sockaddr_in.h> |
|||
#include <__struct_sockaddr_in6.h> |
|||
#include <__struct_sockaddr_storage.h> |
|||
#include <__struct_sockaddr_un.h> |
|||
#include <__struct_stat.h> |
|||
#include <__struct_timespec.h> |
|||
#include <__struct_timeval.h> |
|||
#include <__struct_tm.h> |
|||
#include <__struct_tms.h> |
|||
#include <__typedef_DIR.h> |
|||
#include <__typedef_blkcnt_t.h> |
|||
#include <__typedef_blksize_t.h> |
|||
#include <__typedef_clock_t.h> |
|||
#include <__typedef_clockid_t.h> |
|||
#include <__typedef_dev_t.h> |
|||
#include <__typedef_fd_set.h> |
|||
#include <__typedef_gid_t.h> |
|||
#include <__typedef_in_addr_t.h> |
|||
#include <__typedef_in_port_t.h> |
|||
#include <__typedef_ino_t.h> |
|||
#include <__typedef_mode_t.h> |
|||
#include <__typedef_nfds_t.h> |
|||
#include <__typedef_nlink_t.h> |
|||
#include <__typedef_off_t.h> |
|||
#include <__typedef_sa_family_t.h> |
|||
#include <__typedef_sigset_t.h> |
|||
#include <__typedef_socklen_t.h> |
|||
#include <__typedef_ssize_t.h> |
|||
#include <__typedef_suseconds_t.h> |
|||
#include <__typedef_time_t.h> |
|||
#include <__typedef_uid_t.h> |
|||
#include <alloca.h> |
|||
#include <ar.h> |
|||
#include <arpa/ftp.h> |
|||
#include <arpa/inet.h> |
|||
#include <arpa/nameser.h> |
|||
#include <arpa/nameser_compat.h> |
|||
#include <arpa/telnet.h> |
|||
#include <arpa/tftp.h> |
|||
#include <assert.h> |
|||
#include <byteswap.h> |
|||
#include <complex.h> |
|||
#include <cpio.h> |
|||
#include <crypt.h> |
|||
#include <ctype.h> |
|||
#include <dirent.h> |
|||
#include <endian.h> |
|||
#include <err.h> |
|||
#include <errno.h> |
|||
#include <fcntl.h> |
|||
#include <features.h> |
|||
#include <fenv.h> |
|||
#include <float.h> |
|||
#include <fmtmsg.h> |
|||
#include <fnmatch.h> |
|||
#include <ftw.h> |
|||
#include <getopt.h> |
|||
#include <glob.h> |
|||
#include <iconv.h> |
|||
#include <ifaddrs.h> |
|||
#include <inttypes.h> |
|||
#include <iso646.h> |
|||
#include <langinfo.h> |
|||
#include <libgen.h> |
|||
#include <limits.h> |
|||
#include <locale.h> |
|||
#include <malloc.h> |
|||
#include <math.h> |
|||
#include <memory.h> |
|||
#include <monetary.h> |
|||
#include <mqueue.h> |
|||
#include <netinet/icmp6.h> |
|||
#include <netinet/igmp.h> |
|||
#include <netinet/in.h> |
|||
#include <netinet/in_systm.h> |
|||
#include <netinet/ip.h> |
|||
#include <netinet/ip6.h> |
|||
#include <netinet/ip_icmp.h> |
|||
#include <netinet/tcp.h> |
|||
#include <netinet/udp.h> |
|||
#include <netpacket/packet.h> |
|||
#include <nl_types.h> |
|||
#include <poll.h> |
|||
#include <pthread.h> |
|||
#include <regex.h> |
|||
#include <sched.h> |
|||
#include <search.h> |
|||
#include <semaphore.h> |
|||
#include <stdalign.h> |
|||
#include <stdbool.h> |
|||
#include <stdc-predef.h> |
|||
#include <stdint.h> |
|||
#include <stdio.h> |
|||
#include <stdio_ext.h> |
|||
#include <stdlib.h> |
|||
#include <stdnoreturn.h> |
|||
#include <string.h> |
|||
#include <strings.h> |
|||
#include <stropts.h> |
|||
#include <sys/dir.h> |
|||
#include <sys/errno.h> |
|||
#include <sys/eventfd.h> |
|||
#include <sys/fcntl.h> |
|||
#include <sys/file.h> |
|||
#include <sys/ioctl.h> |
|||
#include <sys/param.h> |
|||
#include <sys/poll.h> |
|||
#include <sys/random.h> |
|||
#include <sys/reg.h> |
|||
#include <sys/select.h> |
|||
#include <sys/socket.h> |
|||
#include <sys/stat.h> |
|||
#include <sys/stropts.h> |
|||
#include <sys/syscall.h> |
|||
#include <sys/sysinfo.h> |
|||
#include <sys/time.h> |
|||
#include <sys/timeb.h> |
|||
#include <sys/timex.h> |
|||
#include <sys/ttydefaults.h> |
|||
#include <sys/types.h> |
|||
#include <sys/uio.h> |
|||
#include <sys/un.h> |
|||
#include <sys/utsname.h> |
|||
#include <syscall.h> |
|||
#include <sysexits.h> |
|||
#include <tar.h> |
|||
#include <tgmath.h> |
|||
#include <threads.h> |
|||
#include <time.h> |
|||
#include <uchar.h> |
|||
#include <unistd.h> |
|||
#include <utime.h> |
|||
#include <values.h> |
|||
#include <wasi/api.h> |
|||
#include <wasi/libc-environ.h> |
|||
#include <wasi/libc-find-relpath.h> |
|||
#include <wasi/libc-nocwd.h> |
|||
#include <wasi/libc.h> |
|||
#include <wchar.h> |
|||
#include <wctype.h> |
File diff suppressed because it is too large
@ -0,0 +1,75 @@ |
|||
__addtf3 |
|||
__divtf3 |
|||
__eqtf2 |
|||
__extenddftf2 |
|||
__extendsftf2 |
|||
__fixtfdi |
|||
__fixtfsi |
|||
__fixunstfsi |
|||
__floatsitf |
|||
__floatunsitf |
|||
__getf2 |
|||
__gttf2 |
|||
__heap_base |
|||
__imported_wasi_snapshot_preview1_args_get |
|||
__imported_wasi_snapshot_preview1_args_sizes_get |
|||
__imported_wasi_snapshot_preview1_clock_res_get |
|||
__imported_wasi_snapshot_preview1_clock_time_get |
|||
__imported_wasi_snapshot_preview1_environ_get |
|||
__imported_wasi_snapshot_preview1_environ_sizes_get |
|||
__imported_wasi_snapshot_preview1_fd_advise |
|||
__imported_wasi_snapshot_preview1_fd_allocate |
|||
__imported_wasi_snapshot_preview1_fd_close |
|||
__imported_wasi_snapshot_preview1_fd_datasync |
|||
__imported_wasi_snapshot_preview1_fd_fdstat_get |
|||
__imported_wasi_snapshot_preview1_fd_fdstat_set_flags |
|||
__imported_wasi_snapshot_preview1_fd_fdstat_set_rights |
|||
__imported_wasi_snapshot_preview1_fd_filestat_get |
|||
__imported_wasi_snapshot_preview1_fd_filestat_set_size |
|||
__imported_wasi_snapshot_preview1_fd_filestat_set_times |
|||
__imported_wasi_snapshot_preview1_fd_pread |
|||
__imported_wasi_snapshot_preview1_fd_prestat_dir_name |
|||
__imported_wasi_snapshot_preview1_fd_prestat_get |
|||
__imported_wasi_snapshot_preview1_fd_pwrite |
|||
__imported_wasi_snapshot_preview1_fd_read |
|||
__imported_wasi_snapshot_preview1_fd_readdir |
|||
__imported_wasi_snapshot_preview1_fd_renumber |
|||
__imported_wasi_snapshot_preview1_fd_seek |
|||
__imported_wasi_snapshot_preview1_fd_sync |
|||
__imported_wasi_snapshot_preview1_fd_tell |
|||
__imported_wasi_snapshot_preview1_fd_write |
|||
__imported_wasi_snapshot_preview1_path_create_directory |
|||
__imported_wasi_snapshot_preview1_path_filestat_get |
|||
__imported_wasi_snapshot_preview1_path_filestat_set_times |
|||
__imported_wasi_snapshot_preview1_path_link |
|||
__imported_wasi_snapshot_preview1_path_open |
|||
__imported_wasi_snapshot_preview1_path_readlink |
|||
__imported_wasi_snapshot_preview1_path_remove_directory |
|||
__imported_wasi_snapshot_preview1_path_rename |
|||
__imported_wasi_snapshot_preview1_path_symlink |
|||
__imported_wasi_snapshot_preview1_path_unlink_file |
|||
__imported_wasi_snapshot_preview1_poll_oneoff |
|||
__imported_wasi_snapshot_preview1_proc_exit |
|||
__imported_wasi_snapshot_preview1_random_get |
|||
__imported_wasi_snapshot_preview1_sched_yield |
|||
__imported_wasi_snapshot_preview1_sock_accept |
|||
__imported_wasi_snapshot_preview1_sock_recv |
|||
__imported_wasi_snapshot_preview1_sock_send |
|||
__imported_wasi_snapshot_preview1_sock_shutdown |
|||
__letf2 |
|||
__lock |
|||
__lockfile |
|||
__lttf2 |
|||
__main_argc_argv |
|||
__netf2 |
|||
__stack_pointer |
|||
__subtf3 |
|||
__tls_base |
|||
__trunctfdf2 |
|||
__trunctfsf2 |
|||
__unlock |
|||
__unlockfile |
|||
__unordtf2 |
|||
__wasilibc_pthread_self |
|||
__wasm_call_ctors |
|||
pthread_setcancelstate |
@ -1,30 +1,39 @@ |
|||
#include <unistd.h> |
|||
#include <errno.h> |
|||
#include <string.h> |
|||
#include "lock.h" |
|||
|
|||
char *__wasilibc_cwd = "/"; |
|||
|
|||
// For threads this needs to synchronize with chdir
|
|||
#ifdef _REENTRANT |
|||
#error "getcwd doesn't yet support multiple threads" |
|||
static volatile int lock[1]; |
|||
void __wasilibc_cwd_lock(void) { LOCK(lock); } |
|||
void __wasilibc_cwd_unlock(void) { UNLOCK(lock); } |
|||
#else |
|||
#define __wasilibc_cwd_lock() (void)0 |
|||
#define __wasilibc_cwd_unlock() (void)0 |
|||
#endif |
|||
|
|||
char *__wasilibc_cwd = "/"; |
|||
|
|||
char *getcwd(char *buf, size_t size) |
|||
{ |
|||
__wasilibc_cwd_lock(); |
|||
if (!buf) { |
|||
buf = strdup(__wasilibc_cwd); |
|||
if (!buf) { |
|||
errno = ENOMEM; |
|||
__wasilibc_cwd_unlock(); |
|||
return NULL; |
|||
} |
|||
} else { |
|||
size_t len = strlen(__wasilibc_cwd); |
|||
if (size < len + 1) { |
|||
errno = ERANGE; |
|||
__wasilibc_cwd_unlock(); |
|||
return NULL; |
|||
} |
|||
strcpy(buf, __wasilibc_cwd); |
|||
} |
|||
__wasilibc_cwd_unlock(); |
|||
return buf; |
|||
} |
|||
|
|||
|
Loading…
Reference in new issue