Commit dcc1b4fd15
Changed files (1107)
lib
libc
wasi
libc-bottom-half
libc-top-half
musl
arch
wasm32
include
src
dirent
errno
fenv
internal
ipc
ldso
m68k
microblaze
mips
mips64
mipsn32
or1k
powerpc
powerpc64
riscv64
s390x
sh
x32
legacy
linux
x32
malloc
math
aarch64
i386
m68k
powerpc64
s390x
x32
x86_64
misc
mman
mq
network
passwd
process
arm
i386
s390x
sh
x32
x86_64
sched
setjmp
signal
aarch64
m68k
microblaze
mips64
mipsn32
or1k
powerpc
powerpc64
riscv64
s390x
x86_64
stat
stdio
string
termios
thread
time
unistd
mips
mips64
sh
x32
lib/libc/wasi/libc-bottom-half/crt/crt1-reactor.c
@@ -1,7 +1,27 @@
+#if defined(_REENTRANT)
+#include <stdatomic.h>
+extern void __wasi_init_tp(void);
+#endif
extern void __wasm_call_ctors(void);
__attribute__((export_name("_initialize")))
void _initialize(void) {
+#if defined(_REENTRANT)
+ static volatile atomic_int initialized = 0;
+ int expected = 0;
+ if (!atomic_compare_exchange_strong(&initialized, &expected, 1)) {
+ __builtin_trap();
+ }
+
+ __wasi_init_tp();
+#else
+ static volatile int initialized = 0;
+ if (initialized != 0) {
+ __builtin_trap();
+ }
+ initialized = 1;
+#endif
+
// The linker synthesizes this to call constructors.
__wasm_call_ctors();
}
lib/libc/wasi/libc-bottom-half/sources/__errno_location.c
@@ -0,0 +1,5 @@
+#include <errno.h>
+
+int *__errno_location(void) {
+ return &errno;
+}
lib/libc/wasi/libc-bottom-half/sources/__wasilibc_real.c
@@ -662,7 +662,7 @@ __wasi_errno_t __wasi_sock_shutdown(
#ifdef _REENTRANT
int32_t __imported_wasi_thread_spawn(int32_t arg0) __attribute__((
__import_module__("wasi"),
- __import_name__("thread_spawn")
+ __import_name__("thread-spawn")
));
int32_t __wasi_thread_spawn(void* start_arg) {
lib/libc/wasi/libc-top-half/musl/arch/wasm32/atomic_arch.h
@@ -1,4 +1,3 @@
-#define a_barrier() (__sync_synchronize())
#define a_cas(p, t, s) (__sync_val_compare_and_swap((p), (t), (s)))
#define a_crash() (__builtin_trap())
#define a_clz_32 __builtin_clz
lib/libc/wasi/libc-top-half/musl/include/pthread.h
@@ -55,15 +55,9 @@ extern "C" {
#define PTHREAD_PROCESS_SHARED 1
-#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
#define PTHREAD_MUTEX_INITIALIZER {{{0}}}
#define PTHREAD_RWLOCK_INITIALIZER {{{0}}}
#define PTHREAD_COND_INITIALIZER {{{0}}}
-#else
-#define PTHREAD_MUTEX_INITIALIZER 0
-#define PTHREAD_RWLOCK_INITIALIZER 0
-#define PTHREAD_COND_INITIALIZER 0
-#endif
#define PTHREAD_ONCE_INIT 0
lib/libc/wasi/libc-top-half/musl/src/aio/aio.c
@@ -1,418 +0,0 @@
-#include <aio.h>
-#include <pthread.h>
-#include <semaphore.h>
-#include <limits.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/auxv.h>
-#include "syscall.h"
-#include "atomic.h"
-#include "pthread_impl.h"
-#include "aio_impl.h"
-
-#define malloc __libc_malloc
-#define calloc __libc_calloc
-#define realloc __libc_realloc
-#define free __libc_free
-
-/* The following is a threads-based implementation of AIO with minimal
- * dependence on implementation details. Most synchronization is
- * performed with pthread primitives, but atomics and futex operations
- * are used for notification in a couple places where the pthread
- * primitives would be inefficient or impractical.
- *
- * For each fd with outstanding aio operations, an aio_queue structure
- * is maintained. These are reference-counted and destroyed by the last
- * aio worker thread to exit. Accessing any member of the aio_queue
- * structure requires a lock on the aio_queue. Adding and removing aio
- * queues themselves requires a write lock on the global map object,
- * a 4-level table mapping file descriptor numbers to aio queues. A
- * read lock on the map is used to obtain locks on existing queues by
- * excluding destruction of the queue by a different thread while it is
- * being locked.
- *
- * Each aio queue has a list of active threads/operations. Presently there
- * is a one to one relationship between threads and operations. The only
- * members of the aio_thread structure which are accessed by other threads
- * are the linked list pointers, op (which is immutable), running (which
- * is updated atomically), and err (which is synchronized via running),
- * so no locking is necessary. Most of the other other members are used
- * for sharing data between the main flow of execution and cancellation
- * cleanup handler.
- *
- * Taking any aio locks requires having all signals blocked. This is
- * necessary because aio_cancel is needed by close, and close is required
- * to be async-signal safe. All aio worker threads run with all signals
- * blocked permanently.
- */
-
-struct aio_thread {
- pthread_t td;
- struct aiocb *cb;
- struct aio_thread *next, *prev;
- struct aio_queue *q;
- volatile int running;
- int err, op;
- ssize_t ret;
-};
-
-struct aio_queue {
- int fd, seekable, append, ref, init;
- pthread_mutex_t lock;
- pthread_cond_t cond;
- struct aio_thread *head;
-};
-
-struct aio_args {
- struct aiocb *cb;
- struct aio_queue *q;
- int op;
- sem_t sem;
-};
-
-static pthread_rwlock_t maplock = PTHREAD_RWLOCK_INITIALIZER;
-static struct aio_queue *****map;
-static volatile int aio_fd_cnt;
-volatile int __aio_fut;
-
-static size_t io_thread_stack_size;
-
-#define MAX(a,b) ((a)>(b) ? (a) : (b))
-
-static struct aio_queue *__aio_get_queue(int fd, int need)
-{
- if (fd < 0) {
- errno = EBADF;
- return 0;
- }
- int a=fd>>24;
- unsigned char b=fd>>16, c=fd>>8, d=fd;
- struct aio_queue *q = 0;
- pthread_rwlock_rdlock(&maplock);
- if ((!map || !map[a] || !map[a][b] || !map[a][b][c] || !(q=map[a][b][c][d])) && need) {
- pthread_rwlock_unlock(&maplock);
- if (fcntl(fd, F_GETFD) < 0) return 0;
- pthread_rwlock_wrlock(&maplock);
- if (!io_thread_stack_size) {
- unsigned long val = __getauxval(AT_MINSIGSTKSZ);
- io_thread_stack_size = MAX(MINSIGSTKSZ+2048, val+512);
- }
- if (!map) map = calloc(sizeof *map, (-1U/2+1)>>24);
- if (!map) goto out;
- if (!map[a]) map[a] = calloc(sizeof **map, 256);
- if (!map[a]) goto out;
- if (!map[a][b]) map[a][b] = calloc(sizeof ***map, 256);
- if (!map[a][b]) goto out;
- if (!map[a][b][c]) map[a][b][c] = calloc(sizeof ****map, 256);
- if (!map[a][b][c]) goto out;
- if (!(q = map[a][b][c][d])) {
- map[a][b][c][d] = q = calloc(sizeof *****map, 1);
- if (q) {
- q->fd = fd;
- pthread_mutex_init(&q->lock, 0);
- pthread_cond_init(&q->cond, 0);
- a_inc(&aio_fd_cnt);
- }
- }
- }
- if (q) pthread_mutex_lock(&q->lock);
-out:
- pthread_rwlock_unlock(&maplock);
- return q;
-}
-
-static void __aio_unref_queue(struct aio_queue *q)
-{
- if (q->ref > 1) {
- q->ref--;
- pthread_mutex_unlock(&q->lock);
- return;
- }
-
- /* This is potentially the last reference, but a new reference
- * may arrive since we cannot free the queue object without first
- * taking the maplock, which requires releasing the queue lock. */
- pthread_mutex_unlock(&q->lock);
- pthread_rwlock_wrlock(&maplock);
- pthread_mutex_lock(&q->lock);
- if (q->ref == 1) {
- int fd=q->fd;
- int a=fd>>24;
- unsigned char b=fd>>16, c=fd>>8, d=fd;
- map[a][b][c][d] = 0;
- a_dec(&aio_fd_cnt);
- pthread_rwlock_unlock(&maplock);
- pthread_mutex_unlock(&q->lock);
- free(q);
- } else {
- q->ref--;
- pthread_rwlock_unlock(&maplock);
- pthread_mutex_unlock(&q->lock);
- }
-}
-
-static void cleanup(void *ctx)
-{
- struct aio_thread *at = ctx;
- struct aio_queue *q = at->q;
- struct aiocb *cb = at->cb;
- struct sigevent sev = cb->aio_sigevent;
-
- /* There are four potential types of waiters we could need to wake:
- * 1. Callers of aio_cancel/close.
- * 2. Callers of aio_suspend with a single aiocb.
- * 3. Callers of aio_suspend with a list.
- * 4. AIO worker threads waiting for sequenced operations.
- * Types 1-3 are notified via atomics/futexes, mainly for AS-safety
- * considerations. Type 4 is notified later via a cond var. */
-
- cb->__ret = at->ret;
- if (a_swap(&at->running, 0) < 0)
- __wake(&at->running, -1, 1);
- if (a_swap(&cb->__err, at->err) != EINPROGRESS)
- __wake(&cb->__err, -1, 1);
- if (a_swap(&__aio_fut, 0))
- __wake(&__aio_fut, -1, 1);
-
- pthread_mutex_lock(&q->lock);
-
- if (at->next) at->next->prev = at->prev;
- if (at->prev) at->prev->next = at->next;
- else q->head = at->next;
-
- /* Signal aio worker threads waiting for sequenced operations. */
- pthread_cond_broadcast(&q->cond);
-
- __aio_unref_queue(q);
-
- if (sev.sigev_notify == SIGEV_SIGNAL) {
- siginfo_t si = {
- .si_signo = sev.sigev_signo,
- .si_value = sev.sigev_value,
- .si_code = SI_ASYNCIO,
- .si_pid = getpid(),
- .si_uid = getuid()
- };
- __syscall(SYS_rt_sigqueueinfo, si.si_pid, si.si_signo, &si);
- }
- if (sev.sigev_notify == SIGEV_THREAD) {
- a_store(&__pthread_self()->cancel, 0);
- sev.sigev_notify_function(sev.sigev_value);
- }
-}
-
-static void *io_thread_func(void *ctx)
-{
- struct aio_thread at, *p;
-
- struct aio_args *args = ctx;
- struct aiocb *cb = args->cb;
- int fd = cb->aio_fildes;
- int op = args->op;
- void *buf = (void *)cb->aio_buf;
- size_t len = cb->aio_nbytes;
- off_t off = cb->aio_offset;
-
- struct aio_queue *q = args->q;
- ssize_t ret;
-
- pthread_mutex_lock(&q->lock);
- sem_post(&args->sem);
-
- at.op = op;
- at.running = 1;
- at.ret = -1;
- at.err = ECANCELED;
- at.q = q;
- at.td = __pthread_self();
- at.cb = cb;
- at.prev = 0;
- if ((at.next = q->head)) at.next->prev = &at;
- q->head = &at;
-
- if (!q->init) {
- int seekable = lseek(fd, 0, SEEK_CUR) >= 0;
- q->seekable = seekable;
- q->append = !seekable || (fcntl(fd, F_GETFL) & O_APPEND);
- q->init = 1;
- }
-
- pthread_cleanup_push(cleanup, &at);
-
- /* Wait for sequenced operations. */
- if (op!=LIO_READ && (op!=LIO_WRITE || q->append)) {
- for (;;) {
- for (p=at.next; p && p->op!=LIO_WRITE; p=p->next);
- if (!p) break;
- pthread_cond_wait(&q->cond, &q->lock);
- }
- }
-
- pthread_mutex_unlock(&q->lock);
-
- switch (op) {
- case LIO_WRITE:
- ret = q->append ? write(fd, buf, len) : pwrite(fd, buf, len, off);
- break;
- case LIO_READ:
- ret = !q->seekable ? read(fd, buf, len) : pread(fd, buf, len, off);
- break;
- case O_SYNC:
- ret = fsync(fd);
- break;
- case O_DSYNC:
- ret = fdatasync(fd);
- break;
- }
- at.ret = ret;
- at.err = ret<0 ? errno : 0;
-
- pthread_cleanup_pop(1);
-
- return 0;
-}
-
-static int submit(struct aiocb *cb, int op)
-{
- int ret = 0;
- pthread_attr_t a;
- sigset_t allmask, origmask;
- pthread_t td;
- struct aio_queue *q = __aio_get_queue(cb->aio_fildes, 1);
- struct aio_args args = { .cb = cb, .op = op, .q = q };
- sem_init(&args.sem, 0, 0);
-
- if (!q) {
- if (errno != EBADF) errno = EAGAIN;
- cb->__ret = -1;
- cb->__err = errno;
- return -1;
- }
- q->ref++;
- pthread_mutex_unlock(&q->lock);
-
- if (cb->aio_sigevent.sigev_notify == SIGEV_THREAD) {
- if (cb->aio_sigevent.sigev_notify_attributes)
- a = *cb->aio_sigevent.sigev_notify_attributes;
- else
- pthread_attr_init(&a);
- } else {
- pthread_attr_init(&a);
- pthread_attr_setstacksize(&a, io_thread_stack_size);
- pthread_attr_setguardsize(&a, 0);
- }
- pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
- sigfillset(&allmask);
- pthread_sigmask(SIG_BLOCK, &allmask, &origmask);
- cb->__err = EINPROGRESS;
- if (pthread_create(&td, &a, io_thread_func, &args)) {
- pthread_mutex_lock(&q->lock);
- __aio_unref_queue(q);
- cb->__err = errno = EAGAIN;
- cb->__ret = ret = -1;
- }
- pthread_sigmask(SIG_SETMASK, &origmask, 0);
-
- if (!ret) {
- while (sem_wait(&args.sem));
- }
-
- return ret;
-}
-
-int aio_read(struct aiocb *cb)
-{
- return submit(cb, LIO_READ);
-}
-
-int aio_write(struct aiocb *cb)
-{
- return submit(cb, LIO_WRITE);
-}
-
-int aio_fsync(int op, struct aiocb *cb)
-{
- if (op != O_SYNC && op != O_DSYNC) {
- errno = EINVAL;
- return -1;
- }
- return submit(cb, op);
-}
-
-ssize_t aio_return(struct aiocb *cb)
-{
- return cb->__ret;
-}
-
-int aio_error(const struct aiocb *cb)
-{
- a_barrier();
- return cb->__err & 0x7fffffff;
-}
-
-int aio_cancel(int fd, struct aiocb *cb)
-{
- sigset_t allmask, origmask;
- int ret = AIO_ALLDONE;
- struct aio_thread *p;
- struct aio_queue *q;
-
- /* Unspecified behavior case. Report an error. */
- if (cb && fd != cb->aio_fildes) {
- errno = EINVAL;
- return -1;
- }
-
- sigfillset(&allmask);
- pthread_sigmask(SIG_BLOCK, &allmask, &origmask);
-
- errno = ENOENT;
- if (!(q = __aio_get_queue(fd, 0))) {
- if (errno == EBADF) ret = -1;
- goto done;
- }
-
- for (p = q->head; p; p = p->next) {
- if (cb && cb != p->cb) continue;
- /* Transition target from running to running-with-waiters */
- if (a_cas(&p->running, 1, -1)) {
- pthread_cancel(p->td);
- __wait(&p->running, 0, -1, 1);
- if (p->err == ECANCELED) ret = AIO_CANCELED;
- }
- }
-
- pthread_mutex_unlock(&q->lock);
-done:
- pthread_sigmask(SIG_SETMASK, &origmask, 0);
- return ret;
-}
-
-int __aio_close(int fd)
-{
- a_barrier();
- if (aio_fd_cnt) aio_cancel(fd, 0);
- return fd;
-}
-
-void __aio_atfork(int who)
-{
- if (who<0) {
- pthread_rwlock_rdlock(&maplock);
- return;
- }
- if (who>0 && map) for (int a=0; a<(-1U/2+1)>>24; a++)
- if (map[a]) for (int b=0; b<256; b++)
- if (map[a][b]) for (int c=0; c<256; c++)
- if (map[a][b][c]) for (int d=0; d<256; d++)
- map[a][b][c][d] = 0;
- pthread_rwlock_unlock(&maplock);
-}
-
-weak_alias(aio_cancel, aio_cancel64);
-weak_alias(aio_error, aio_error64);
-weak_alias(aio_fsync, aio_fsync64);
-weak_alias(aio_read, aio_read64);
-weak_alias(aio_write, aio_write64);
-weak_alias(aio_return, aio_return64);
lib/libc/wasi/libc-top-half/musl/src/aio/aio_suspend.c
@@ -1,79 +0,0 @@
-#include <aio.h>
-#include <errno.h>
-#include <time.h>
-#include "atomic.h"
-#include "pthread_impl.h"
-#include "aio_impl.h"
-
-int aio_suspend(const struct aiocb *const cbs[], int cnt, const struct timespec *ts)
-{
- int i, tid = 0, ret, expect = 0;
- struct timespec at;
- volatile int dummy_fut, *pfut;
- int nzcnt = 0;
- const struct aiocb *cb = 0;
-
- pthread_testcancel();
-
- if (cnt<0) {
- errno = EINVAL;
- return -1;
- }
-
- for (i=0; i<cnt; i++) if (cbs[i]) {
- if (aio_error(cbs[i]) != EINPROGRESS) return 0;
- nzcnt++;
- cb = cbs[i];
- }
-
- if (ts) {
- clock_gettime(CLOCK_MONOTONIC, &at);
- at.tv_sec += ts->tv_sec;
- if ((at.tv_nsec += ts->tv_nsec) >= 1000000000) {
- at.tv_nsec -= 1000000000;
- at.tv_sec++;
- }
- }
-
- for (;;) {
- for (i=0; i<cnt; i++)
- if (cbs[i] && aio_error(cbs[i]) != EINPROGRESS)
- return 0;
-
- switch (nzcnt) {
- case 0:
- pfut = &dummy_fut;
- break;
- case 1:
- pfut = (void *)&cb->__err;
- expect = EINPROGRESS | 0x80000000;
- a_cas(pfut, EINPROGRESS, expect);
- break;
- default:
- pfut = &__aio_fut;
- if (!tid) tid = __pthread_self()->tid;
- expect = a_cas(pfut, 0, tid);
- if (!expect) expect = tid;
- /* Need to recheck the predicate before waiting. */
- for (i=0; i<cnt; i++)
- if (cbs[i] && aio_error(cbs[i]) != EINPROGRESS)
- return 0;
- break;
- }
-
- ret = __timedwait_cp(pfut, expect, CLOCK_MONOTONIC, ts?&at:0, 1);
-
- switch (ret) {
- case ETIMEDOUT:
- ret = EAGAIN;
- case ECANCELED:
- case EINTR:
- errno = ret;
- return -1;
- }
- }
-}
-
-#if !_REDIR_TIME64
-weak_alias(aio_suspend, aio_suspend64);
-#endif
lib/libc/wasi/libc-top-half/musl/src/aio/lio_listio.c
@@ -1,143 +0,0 @@
-#include <aio.h>
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
-#include "pthread_impl.h"
-
-struct lio_state {
- struct sigevent *sev;
- int cnt;
- struct aiocb *cbs[];
-};
-
-static int lio_wait(struct lio_state *st)
-{
- int i, err, got_err = 0;
- int cnt = st->cnt;
- struct aiocb **cbs = st->cbs;
-
- for (;;) {
- for (i=0; i<cnt; i++) {
- if (!cbs[i]) continue;
- err = aio_error(cbs[i]);
- if (err==EINPROGRESS)
- break;
- if (err) got_err=1;
- cbs[i] = 0;
- }
- if (i==cnt) {
- if (got_err) {
- errno = EIO;
- return -1;
- }
- return 0;
- }
- if (aio_suspend((void *)cbs, cnt, 0))
- return -1;
- }
-}
-
-static void notify_signal(struct sigevent *sev)
-{
- siginfo_t si = {
- .si_signo = sev->sigev_signo,
- .si_value = sev->sigev_value,
- .si_code = SI_ASYNCIO,
- .si_pid = getpid(),
- .si_uid = getuid()
- };
- __syscall(SYS_rt_sigqueueinfo, si.si_pid, si.si_signo, &si);
-}
-
-static void *wait_thread(void *p)
-{
- struct lio_state *st = p;
- struct sigevent *sev = st->sev;
- lio_wait(st);
- free(st);
- switch (sev->sigev_notify) {
- case SIGEV_SIGNAL:
- notify_signal(sev);
- break;
- case SIGEV_THREAD:
- sev->sigev_notify_function(sev->sigev_value);
- break;
- }
- return 0;
-}
-
-int lio_listio(int mode, struct aiocb *restrict const *restrict cbs, int cnt, struct sigevent *restrict sev)
-{
- int i, ret;
- struct lio_state *st=0;
-
- if (cnt < 0) {
- errno = EINVAL;
- return -1;
- }
-
- if (mode == LIO_WAIT || (sev && sev->sigev_notify != SIGEV_NONE)) {
- if (!(st = malloc(sizeof *st + cnt*sizeof *cbs))) {
- errno = EAGAIN;
- return -1;
- }
- st->cnt = cnt;
- st->sev = sev;
- memcpy(st->cbs, (void*) cbs, cnt*sizeof *cbs);
- }
-
- for (i=0; i<cnt; i++) {
- if (!cbs[i]) continue;
- switch (cbs[i]->aio_lio_opcode) {
- case LIO_READ:
- ret = aio_read(cbs[i]);
- break;
- case LIO_WRITE:
- ret = aio_write(cbs[i]);
- break;
- default:
- continue;
- }
- if (ret) {
- free(st);
- errno = EAGAIN;
- return -1;
- }
- }
-
- if (mode == LIO_WAIT) {
- ret = lio_wait(st);
- free(st);
- return ret;
- }
-
- if (st) {
- pthread_attr_t a;
- sigset_t set, set_old;
- pthread_t td;
-
- if (sev->sigev_notify == SIGEV_THREAD) {
- if (sev->sigev_notify_attributes)
- a = *sev->sigev_notify_attributes;
- else
- pthread_attr_init(&a);
- } else {
- pthread_attr_init(&a);
- pthread_attr_setstacksize(&a, PAGE_SIZE);
- pthread_attr_setguardsize(&a, 0);
- }
- pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
- sigfillset(&set);
- pthread_sigmask(SIG_BLOCK, &set, &set_old);
- if (pthread_create(&td, &a, wait_thread, st)) {
- free(st);
- errno = EAGAIN;
- return -1;
- }
- pthread_sigmask(SIG_SETMASK, &set_old, 0);
- }
-
- return 0;
-}
-
-weak_alias(lio_listio, lio_listio64);
lib/libc/wasi/libc-top-half/musl/src/complex/cimag.c
@@ -1,6 +0,0 @@
-#include "complex_impl.h"
-
-double (cimag)(double complex z)
-{
- return cimag(z);
-}
lib/libc/wasi/libc-top-half/musl/src/complex/cimagf.c
@@ -1,6 +0,0 @@
-#include "complex_impl.h"
-
-float (cimagf)(float complex z)
-{
- return cimagf(z);
-}
lib/libc/wasi/libc-top-half/musl/src/complex/cimagl.c
@@ -1,6 +0,0 @@
-#include "complex_impl.h"
-
-long double (cimagl)(long double complex z)
-{
- return cimagl(z);
-}
lib/libc/wasi/libc-top-half/musl/src/complex/creal.c
@@ -1,6 +0,0 @@
-#include <complex.h>
-
-double (creal)(double complex z)
-{
- return creal(z);
-}
lib/libc/wasi/libc-top-half/musl/src/complex/crealf.c
@@ -1,6 +0,0 @@
-#include <complex.h>
-
-float (crealf)(float complex z)
-{
- return crealf(z);
-}
lib/libc/wasi/libc-top-half/musl/src/complex/creall.c
@@ -1,6 +0,0 @@
-#include <complex.h>
-
-long double (creall)(long double complex z)
-{
- return creall(z);
-}
lib/libc/wasi/libc-top-half/musl/src/dirent/closedir.c
@@ -1,11 +0,0 @@
-#include <dirent.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include "__dirent.h"
-
-int closedir(DIR *dir)
-{
- int ret = close(dir->fd);
- free(dir);
- return ret;
-}
lib/libc/wasi/libc-top-half/musl/src/dirent/dirfd.c
@@ -1,7 +0,0 @@
-#include <dirent.h>
-#include "__dirent.h"
-
-int dirfd(DIR *d)
-{
- return d->fd;
-}
lib/libc/wasi/libc-top-half/musl/src/dirent/fdopendir.c
@@ -1,31 +0,0 @@
-#include <dirent.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <stdlib.h>
-#include "__dirent.h"
-
-DIR *fdopendir(int fd)
-{
- DIR *dir;
- struct stat st;
-
- if (fstat(fd, &st) < 0) {
- return 0;
- }
- if (fcntl(fd, F_GETFL) & O_PATH) {
- errno = EBADF;
- return 0;
- }
- if (!S_ISDIR(st.st_mode)) {
- errno = ENOTDIR;
- return 0;
- }
- if (!(dir = calloc(1, sizeof *dir))) {
- return 0;
- }
-
- fcntl(fd, F_SETFD, FD_CLOEXEC);
- dir->fd = fd;
- return dir;
-}
lib/libc/wasi/libc-top-half/musl/src/dirent/opendir.c
@@ -1,21 +0,0 @@
-#define _GNU_SOURCE
-#include <dirent.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include "__dirent.h"
-#include "syscall.h"
-
-DIR *opendir(const char *name)
-{
- int fd;
- DIR *dir;
-
- if ((fd = open(name, O_RDONLY|O_DIRECTORY|O_CLOEXEC)) < 0)
- return 0;
- if (!(dir = calloc(1, sizeof *dir))) {
- __syscall(SYS_close, fd);
- return 0;
- }
- dir->fd = fd;
- return dir;
-}
lib/libc/wasi/libc-top-half/musl/src/dirent/readdir.c
@@ -1,29 +0,0 @@
-#include <dirent.h>
-#include <errno.h>
-#include <stddef.h>
-#include "__dirent.h"
-#include "syscall.h"
-
-typedef char dirstream_buf_alignment_check[1-2*(int)(
- offsetof(struct __dirstream, buf) % sizeof(off_t))];
-
-struct dirent *readdir(DIR *dir)
-{
- struct dirent *de;
-
- if (dir->buf_pos >= dir->buf_end) {
- int len = __syscall(SYS_getdents, dir->fd, dir->buf, sizeof dir->buf);
- if (len <= 0) {
- if (len < 0 && len != -ENOENT) errno = -len;
- return 0;
- }
- dir->buf_end = len;
- dir->buf_pos = 0;
- }
- de = (void *)(dir->buf + dir->buf_pos);
- dir->buf_pos += de->d_reclen;
- dir->tell = de->d_off;
- return de;
-}
-
-weak_alias(readdir, readdir64);
lib/libc/wasi/libc-top-half/musl/src/dirent/readdir_r.c
@@ -1,29 +0,0 @@
-#include <dirent.h>
-#include <errno.h>
-#include <string.h>
-#include "__dirent.h"
-#include "lock.h"
-
-int readdir_r(DIR *restrict dir, struct dirent *restrict buf, struct dirent **restrict result)
-{
- struct dirent *de;
- int errno_save = errno;
- int ret;
-
- LOCK(dir->lock);
- errno = 0;
- de = readdir(dir);
- if ((ret = errno)) {
- UNLOCK(dir->lock);
- return ret;
- }
- errno = errno_save;
- if (de) memcpy(buf, de, de->d_reclen);
- else buf = NULL;
-
- UNLOCK(dir->lock);
- *result = buf;
- return 0;
-}
-
-weak_alias(readdir_r, readdir64_r);
lib/libc/wasi/libc-top-half/musl/src/dirent/rewinddir.c
@@ -1,13 +0,0 @@
-#include <dirent.h>
-#include <unistd.h>
-#include "__dirent.h"
-#include "lock.h"
-
-void rewinddir(DIR *dir)
-{
- LOCK(dir->lock);
- lseek(dir->fd, 0, SEEK_SET);
- dir->buf_pos = dir->buf_end = 0;
- dir->tell = 0;
- UNLOCK(dir->lock);
-}
lib/libc/wasi/libc-top-half/musl/src/dirent/scandir.c
@@ -1,47 +0,0 @@
-#include <dirent.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <errno.h>
-#include <stddef.h>
-
-int scandir(const char *path, struct dirent ***res,
- int (*sel)(const struct dirent *),
- int (*cmp)(const struct dirent **, const struct dirent **))
-{
- DIR *d = opendir(path);
- struct dirent *de, **names=0, **tmp;
- size_t cnt=0, len=0;
- int old_errno = errno;
-
- if (!d) return -1;
-
- while ((errno=0), (de = readdir(d))) {
- if (sel && !sel(de)) continue;
- if (cnt >= len) {
- len = 2*len+1;
- if (len > SIZE_MAX/sizeof *names) break;
- tmp = realloc(names, len * sizeof *names);
- if (!tmp) break;
- names = tmp;
- }
- names[cnt] = malloc(de->d_reclen);
- if (!names[cnt]) break;
- memcpy(names[cnt++], de, de->d_reclen);
- }
-
- closedir(d);
-
- if (errno) {
- if (names) while (cnt-->0) free(names[cnt]);
- free(names);
- return -1;
- }
- errno = old_errno;
-
- if (cmp) qsort(names, cnt, sizeof *names, (int (*)(const void *, const void *))cmp);
- *res = names;
- return cnt;
-}
-
-weak_alias(scandir, scandir64);
lib/libc/wasi/libc-top-half/musl/src/dirent/seekdir.c
@@ -1,12 +0,0 @@
-#include <dirent.h>
-#include <unistd.h>
-#include "__dirent.h"
-#include "lock.h"
-
-void seekdir(DIR *dir, long off)
-{
- LOCK(dir->lock);
- dir->tell = lseek(dir->fd, off, SEEK_SET);
- dir->buf_pos = dir->buf_end = 0;
- UNLOCK(dir->lock);
-}
lib/libc/wasi/libc-top-half/musl/src/dirent/telldir.c
@@ -1,7 +0,0 @@
-#include <dirent.h>
-#include "__dirent.h"
-
-long telldir(DIR *dir)
-{
- return dir->tell;
-}
lib/libc/wasi/libc-top-half/musl/src/env/__environ.c
@@ -1,6 +0,0 @@
-#include <unistd.h>
-
-char **__environ = 0;
-weak_alias(__environ, ___environ);
-weak_alias(__environ, _environ);
-weak_alias(__environ, environ);
lib/libc/wasi/libc-top-half/musl/src/env/__init_tls.c
@@ -1,237 +0,0 @@
-#ifdef __wasilibc_unmodified_upstream
-#define SYSCALL_NO_TLS 1
-#include <elf.h>
-#endif
-#include <limits.h>
-#ifdef __wasilibc_unmodified_upstream
-#include <sys/mman.h>
-#endif
-#include <string.h>
-#include <stddef.h>
-#include "pthread_impl.h"
-#include "libc.h"
-#include "atomic.h"
-#include "syscall.h"
-
-volatile int __thread_list_lock;
-
-#ifndef __wasilibc_unmodified_upstream
-
-/* These symbols are generated by wasm-ld. __stack_high/__stack_low
- * symbols are only available in LLVM v16 and higher, therefore they're
- * defined as weak symbols and if not available, __heap_base/__data_end
- * is used instead.
- *
- * TODO: remove usage of __heap_base/__data_end for stack size calculation
- * once we drop support for LLVM v15 and older.
- */
-extern unsigned char __heap_base;
-extern unsigned char __data_end;
-extern unsigned char __global_base;
-extern weak unsigned char __stack_high;
-extern weak unsigned char __stack_low;
-
-static inline void setup_default_stack_size()
-{
- ptrdiff_t stack_size;
-
- if (&__stack_high)
- stack_size = &__stack_high - &__stack_low;
- else {
- unsigned char *sp;
- __asm__(
- ".globaltype __stack_pointer, i32\n"
- "global.get __stack_pointer\n"
- "local.set %0\n"
- : "=r"(sp));
- stack_size = sp > &__global_base ? &__heap_base - &__data_end : (ptrdiff_t)&__global_base;
- }
-
- if (stack_size > __default_stacksize)
- __default_stacksize =
- stack_size < DEFAULT_STACK_MAX ?
- stack_size : DEFAULT_STACK_MAX;
-}
-
-void __wasi_init_tp() {
- __init_tp((void *)__get_tp());
-}
-#endif
-
-int __init_tp(void *p)
-{
- pthread_t td = p;
- td->self = td;
-#ifdef __wasilibc_unmodified_upstream
- int r = __set_thread_area(TP_ADJ(p));
- if (r < 0) return -1;
- if (!r) libc.can_do_threads = 1;
- td->detach_state = DT_JOINABLE;
- td->tid = __syscall(SYS_set_tid_address, &__thread_list_lock);
-#else
- setup_default_stack_size();
- td->detach_state = DT_JOINABLE;
- /*
- * Initialize the TID to a value which doesn't conflict with
- * host-allocated TIDs, so that TID-based locks can work.
- *
- * Note:
- * - Host-allocated TIDs range from 1 to 0x1fffffff. (inclusive)
- * - __tl_lock and __lockfile uses TID 0 as "unlocked".
- * - __lockfile relies on the fact the most significant two bits
- * of TIDs are 0.
- */
- td->tid = 0x3fffffff;
-#endif
- td->locale = &libc.global_locale;
- td->robust_list.head = &td->robust_list.head;
- td->sysinfo = __sysinfo;
- td->next = td->prev = td;
- return 0;
-}
-
-#ifdef __wasilibc_unmodified_upstream
-
-static struct builtin_tls {
- char c;
- struct pthread pt;
- void *space[16];
-} builtin_tls[1];
-#define MIN_TLS_ALIGN offsetof(struct builtin_tls, pt)
-
-static struct tls_module main_tls;
-#endif
-
-#ifndef __wasilibc_unmodified_upstream
-extern void __wasm_init_tls(void*);
-#endif
-
-void *__copy_tls(unsigned char *mem)
-{
-#ifdef __wasilibc_unmodified_upstream
- pthread_t td;
- struct tls_module *p;
- size_t i;
- uintptr_t *dtv;
-
-#ifdef TLS_ABOVE_TP
- dtv = (uintptr_t*)(mem + libc.tls_size) - (libc.tls_cnt + 1);
-
- mem += -((uintptr_t)mem + sizeof(struct pthread)) & (libc.tls_align-1);
- td = (pthread_t)mem;
- mem += sizeof(struct pthread);
-
- for (i=1, p=libc.tls_head; p; i++, p=p->next) {
- dtv[i] = (uintptr_t)(mem + p->offset) + DTP_OFFSET;
- memcpy(mem + p->offset, p->image, p->len);
- }
-#else
- dtv = (uintptr_t *)mem;
-
- mem += libc.tls_size - sizeof(struct pthread);
- mem -= (uintptr_t)mem & (libc.tls_align-1);
- td = (pthread_t)mem;
-
- for (i=1, p=libc.tls_head; p; i++, p=p->next) {
- dtv[i] = (uintptr_t)(mem - p->offset) + DTP_OFFSET;
- memcpy(mem - p->offset, p->image, p->len);
- }
-#endif
- dtv[0] = libc.tls_cnt;
- td->dtv = dtv;
- return td;
-#else
- size_t tls_align = __builtin_wasm_tls_align();
- volatile void* tls_base = __builtin_wasm_tls_base();
- mem += tls_align;
- mem -= (uintptr_t)mem & (tls_align-1);
- __wasm_init_tls(mem);
- __asm__("local.get %0\n"
- "global.set __tls_base\n"
- :: "r"(tls_base));
- return mem;
-#endif
-}
-
-#ifdef __wasilibc_unmodified_upstream
-#if ULONG_MAX == 0xffffffff
-typedef Elf32_Phdr Phdr;
-#else
-typedef Elf64_Phdr Phdr;
-#endif
-
-extern weak hidden const size_t _DYNAMIC[];
-
-static void static_init_tls(size_t *aux)
-{
- unsigned char *p;
- size_t n;
- Phdr *phdr, *tls_phdr=0;
- size_t base = 0;
- void *mem;
-
- for (p=(void *)aux[AT_PHDR],n=aux[AT_PHNUM]; n; n--,p+=aux[AT_PHENT]) {
- phdr = (void *)p;
- if (phdr->p_type == PT_PHDR)
- base = aux[AT_PHDR] - phdr->p_vaddr;
- if (phdr->p_type == PT_DYNAMIC && _DYNAMIC)
- base = (size_t)_DYNAMIC - phdr->p_vaddr;
- if (phdr->p_type == PT_TLS)
- tls_phdr = phdr;
- if (phdr->p_type == PT_GNU_STACK &&
- phdr->p_memsz > __default_stacksize)
- __default_stacksize =
- phdr->p_memsz < DEFAULT_STACK_MAX ?
- phdr->p_memsz : DEFAULT_STACK_MAX;
- }
-
- if (tls_phdr) {
- main_tls.image = (void *)(base + tls_phdr->p_vaddr);
- main_tls.len = tls_phdr->p_filesz;
- main_tls.size = tls_phdr->p_memsz;
- main_tls.align = tls_phdr->p_align;
- libc.tls_cnt = 1;
- libc.tls_head = &main_tls;
- }
-
- main_tls.size += (-main_tls.size - (uintptr_t)main_tls.image)
- & (main_tls.align-1);
-#ifdef TLS_ABOVE_TP
- main_tls.offset = GAP_ABOVE_TP;
- main_tls.offset += (-GAP_ABOVE_TP + (uintptr_t)main_tls.image)
- & (main_tls.align-1);
-#else
- main_tls.offset = main_tls.size;
-#endif
- if (main_tls.align < MIN_TLS_ALIGN) main_tls.align = MIN_TLS_ALIGN;
-
- libc.tls_align = main_tls.align;
- libc.tls_size = 2*sizeof(void *) + sizeof(struct pthread)
-#ifdef TLS_ABOVE_TP
- + main_tls.offset
-#endif
- + main_tls.size + main_tls.align
- + MIN_TLS_ALIGN-1 & -MIN_TLS_ALIGN;
-
- if (libc.tls_size > sizeof builtin_tls) {
-#ifndef SYS_mmap2
-#define SYS_mmap2 SYS_mmap
-#endif
- mem = (void *)__syscall(
- SYS_mmap2,
- 0, libc.tls_size, PROT_READ|PROT_WRITE,
- MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
- /* -4095...-1 cast to void * will crash on dereference anyway,
- * so don't bloat the init code checking for error codes and
- * explicitly calling a_crash(). */
- } else {
- mem = builtin_tls;
- }
-
- /* Failure to initialize thread pointer is always fatal. */
- if (__init_tp(__copy_tls(mem)) < 0)
- a_crash();
-}
-
-weak_alias(static_init_tls, __init_tls);
-#endif
lib/libc/wasi/libc-top-half/musl/src/env/__libc_start_main.c
@@ -1,97 +0,0 @@
-#include <elf.h>
-#include <poll.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <unistd.h>
-#include "syscall.h"
-#include "atomic.h"
-#include "libc.h"
-
-static void dummy(void) {}
-weak_alias(dummy, _init);
-
-extern weak hidden void (*const __init_array_start)(void), (*const __init_array_end)(void);
-
-static void dummy1(void *p) {}
-weak_alias(dummy1, __init_ssp);
-
-#define AUX_CNT 38
-
-#ifdef __GNUC__
-__attribute__((__noinline__))
-#endif
-void __init_libc(char **envp, char *pn)
-{
- size_t i, *auxv, aux[AUX_CNT] = { 0 };
- __environ = envp;
- for (i=0; envp[i]; i++);
- libc.auxv = auxv = (void *)(envp+i+1);
- for (i=0; auxv[i]; i+=2) if (auxv[i]<AUX_CNT) aux[auxv[i]] = auxv[i+1];
- __hwcap = aux[AT_HWCAP];
- if (aux[AT_SYSINFO]) __sysinfo = aux[AT_SYSINFO];
- libc.page_size = aux[AT_PAGESZ];
-
- if (!pn) pn = (void*)aux[AT_EXECFN];
- if (!pn) pn = "";
- __progname = __progname_full = pn;
- for (i=0; pn[i]; i++) if (pn[i]=='/') __progname = pn+i+1;
-
- __init_tls(aux);
- __init_ssp((void *)aux[AT_RANDOM]);
-
- if (aux[AT_UID]==aux[AT_EUID] && aux[AT_GID]==aux[AT_EGID]
- && !aux[AT_SECURE]) return;
-
- struct pollfd pfd[3] = { {.fd=0}, {.fd=1}, {.fd=2} };
- int r =
-#ifdef SYS_poll
- __syscall(SYS_poll, pfd, 3, 0);
-#else
- __syscall(SYS_ppoll, pfd, 3, &(struct timespec){0}, 0, _NSIG/8);
-#endif
- if (r<0) a_crash();
- for (i=0; i<3; i++) if (pfd[i].revents&POLLNVAL)
- if (__sys_open("/dev/null", O_RDWR)<0)
- a_crash();
- libc.secure = 1;
-}
-
-static void libc_start_init(void)
-{
- _init();
- uintptr_t a = (uintptr_t)&__init_array_start;
- for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)()))
- (*(void (**)(void))a)();
-}
-
-weak_alias(libc_start_init, __libc_start_init);
-
-typedef int lsm2_fn(int (*)(int,char **,char **), int, char **);
-static lsm2_fn libc_start_main_stage2;
-
-int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv,
- void (*init_dummy)(), void(*fini_dummy)(), void(*ldso_dummy)())
-{
- char **envp = argv+argc+1;
-
- /* External linkage, and explicit noinline attribute if available,
- * are used to prevent the stack frame used during init from
- * persisting for the entire process lifetime. */
- __init_libc(envp, argv[0]);
-
- /* Barrier against hoisting application code or anything using ssp
- * or thread pointer prior to its initialization above. */
- lsm2_fn *stage2 = libc_start_main_stage2;
- __asm__ ( "" : "+r"(stage2) : : "memory" );
- return stage2(main, argc, argv);
-}
-
-static int libc_start_main_stage2(int (*main)(int,char **,char **), int argc, char **argv)
-{
- char **envp = argv+argc+1;
- __libc_start_init();
-
- /* Pass control to the application */
- exit(main(argc, argv, envp));
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/env/__reset_tls.c
@@ -1,15 +0,0 @@
-#include <string.h>
-#include "pthread_impl.h"
-#include "libc.h"
-
-void __reset_tls()
-{
- pthread_t self = __pthread_self();
- struct tls_module *p;
- size_t i, n = self->dtv[0];
- if (n) for (p=libc.tls_head, i=1; i<=n; i++, p=p->next) {
- char *mem = (char *)(self->dtv[i] - DTP_OFFSET);
- memcpy(mem, p->image, p->len);
- memset(mem+p->len, 0, p->size - p->len);
- }
-}
lib/libc/wasi/libc-top-half/musl/src/env/secure_getenv.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <stdlib.h>
-#include "libc.h"
-
-char *secure_getenv(const char *name)
-{
- return libc.secure ? NULL : getenv(name);
-}
lib/libc/wasi/libc-top-half/musl/src/errno/__errno_location.c
@@ -1,9 +0,0 @@
-#include <errno.h>
-#include "pthread_impl.h"
-
-int *__errno_location(void)
-{
- return &__pthread_self()->errno_val;
-}
-
-weak_alias(__errno_location, ___errno_location);
lib/libc/wasi/libc-top-half/musl/src/exit/arm/__aeabi_atexit.c
@@ -1,6 +0,0 @@
-int __cxa_atexit(void (*func)(void *), void *arg, void *dso);
-
-int __aeabi_atexit (void *obj, void (*func) (void *), void *d)
-{
- return __cxa_atexit (func, obj, d);
-}
lib/libc/wasi/libc-top-half/musl/src/exit/_Exit.c
@@ -1,8 +0,0 @@
-#include <stdlib.h>
-#include "syscall.h"
-
-_Noreturn void _Exit(int ec)
-{
- __syscall(SYS_exit_group, ec);
- for (;;) __syscall(SYS_exit, ec);
-}
lib/libc/wasi/libc-top-half/musl/src/exit/abort.c
@@ -1,30 +0,0 @@
-#include <stdlib.h>
-#include <signal.h>
-#include "syscall.h"
-#include "pthread_impl.h"
-#include "atomic.h"
-#include "lock.h"
-#include "ksigaction.h"
-
-_Noreturn void abort(void)
-{
- raise(SIGABRT);
-
- /* If there was a SIGABRT handler installed and it returned, or if
- * SIGABRT was blocked or ignored, take an AS-safe lock to prevent
- * sigaction from installing a new SIGABRT handler, uninstall any
- * handler that may be present, and re-raise the signal to generate
- * the default action of abnormal termination. */
- __block_all_sigs(0);
- LOCK(__abort_lock);
- __syscall(SYS_rt_sigaction, SIGABRT,
- &(struct k_sigaction){.handler = SIG_DFL}, 0, _NSIG/8);
- __syscall(SYS_tkill, __pthread_self()->tid, SIGABRT);
- __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK,
- &(long[_NSIG/(8*sizeof(long))]){1UL<<(SIGABRT-1)}, 0, _NSIG/8);
-
- /* Beyond this point should be unreachable. */
- a_crash();
- raise(SIGKILL);
- _Exit(127);
-}
lib/libc/wasi/libc-top-half/musl/src/exit/abort_lock.c
@@ -1,3 +0,0 @@
-#include "pthread_impl.h"
-
-volatile int __abort_lock[1];
lib/libc/wasi/libc-top-half/musl/src/fcntl/fcntl.c
@@ -1,48 +0,0 @@
-#define _GNU_SOURCE
-#include <fcntl.h>
-#include <stdarg.h>
-#include <errno.h>
-#include "syscall.h"
-
-int fcntl(int fd, int cmd, ...)
-{
- unsigned long arg;
- va_list ap;
- va_start(ap, cmd);
- arg = va_arg(ap, unsigned long);
- va_end(ap);
- if (cmd == F_SETFL) arg |= O_LARGEFILE;
- if (cmd == F_SETLKW) return syscall_cp(SYS_fcntl, fd, cmd, (void *)arg);
- if (cmd == F_GETOWN) {
- struct f_owner_ex ex;
- int ret = __syscall(SYS_fcntl, fd, F_GETOWN_EX, &ex);
- if (ret == -EINVAL) return __syscall(SYS_fcntl, fd, cmd, (void *)arg);
- if (ret) return __syscall_ret(ret);
- return ex.type == F_OWNER_PGRP ? -ex.pid : ex.pid;
- }
- if (cmd == F_DUPFD_CLOEXEC) {
- int ret = __syscall(SYS_fcntl, fd, F_DUPFD_CLOEXEC, arg);
- if (ret != -EINVAL) {
- if (ret >= 0)
- __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC);
- return __syscall_ret(ret);
- }
- ret = __syscall(SYS_fcntl, fd, F_DUPFD_CLOEXEC, 0);
- if (ret != -EINVAL) {
- if (ret >= 0) __syscall(SYS_close, ret);
- return __syscall_ret(-EINVAL);
- }
- ret = __syscall(SYS_fcntl, fd, F_DUPFD, arg);
- if (ret >= 0) __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC);
- return __syscall_ret(ret);
- }
- switch (cmd) {
- case F_SETLK:
- case F_GETLK:
- case F_GETOWN_EX:
- case F_SETOWN_EX:
- return syscall(SYS_fcntl, fd, cmd, (void *)arg);
- default:
- return syscall(SYS_fcntl, fd, cmd, arg);
- }
-}
lib/libc/wasi/libc-top-half/musl/src/fcntl/open.c
@@ -1,23 +0,0 @@
-#include <fcntl.h>
-#include <stdarg.h>
-#include "syscall.h"
-
-int open(const char *filename, int flags, ...)
-{
- mode_t mode = 0;
-
- if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) {
- va_list ap;
- va_start(ap, flags);
- mode = va_arg(ap, mode_t);
- va_end(ap);
- }
-
- int fd = __sys_open_cp(filename, flags, mode);
- if (fd>=0 && (flags & O_CLOEXEC))
- __syscall(SYS_fcntl, fd, F_SETFD, FD_CLOEXEC);
-
- return __syscall_ret(fd);
-}
-
-weak_alias(open, open64);
lib/libc/wasi/libc-top-half/musl/src/fcntl/openat.c
@@ -1,19 +0,0 @@
-#include <fcntl.h>
-#include <stdarg.h>
-#include "syscall.h"
-
-int openat(int fd, const char *filename, int flags, ...)
-{
- mode_t mode = 0;
-
- if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) {
- va_list ap;
- va_start(ap, flags);
- mode = va_arg(ap, mode_t);
- va_end(ap);
- }
-
- return syscall_cp(SYS_openat, fd, filename, flags|O_LARGEFILE, mode);
-}
-
-weak_alias(openat, openat64);
lib/libc/wasi/libc-top-half/musl/src/fcntl/posix_fadvise.c
@@ -1,18 +0,0 @@
-#include <fcntl.h>
-#include "syscall.h"
-
-int posix_fadvise(int fd, off_t base, off_t len, int advice)
-{
-#if defined(SYSCALL_FADVISE_6_ARG)
- /* Some archs, at least arm and powerpc, have the syscall
- * arguments reordered to avoid needing 7 argument registers
- * due to 64-bit argument alignment. */
- return -__syscall(SYS_fadvise, fd, advice,
- __SYSCALL_LL_E(base), __SYSCALL_LL_E(len));
-#else
- return -__syscall(SYS_fadvise, fd, __SYSCALL_LL_O(base),
- __SYSCALL_LL_E(len), advice);
-#endif
-}
-
-weak_alias(posix_fadvise, posix_fadvise64);
lib/libc/wasi/libc-top-half/musl/src/fcntl/posix_fallocate.c
@@ -1,10 +0,0 @@
-#include <fcntl.h>
-#include "syscall.h"
-
-int posix_fallocate(int fd, off_t base, off_t len)
-{
- return -__syscall(SYS_fallocate, fd, 0, __SYSCALL_LL_E(base),
- __SYSCALL_LL_E(len));
-}
-
-weak_alias(posix_fallocate, posix_fallocate64);
lib/libc/wasi/libc-top-half/musl/src/fenv/aarch64/fenv.s
@@ -1,68 +0,0 @@
-.global fegetround
-.type fegetround,%function
-fegetround:
- mrs x0, fpcr
- and w0, w0, #0xc00000
- ret
-
-.global __fesetround
-.hidden __fesetround
-.type __fesetround,%function
-__fesetround:
- mrs x1, fpcr
- bic w1, w1, #0xc00000
- orr w1, w1, w0
- msr fpcr, x1
- mov w0, #0
- ret
-
-.global fetestexcept
-.type fetestexcept,%function
-fetestexcept:
- and w0, w0, #0x1f
- mrs x1, fpsr
- and w0, w0, w1
- ret
-
-.global feclearexcept
-.type feclearexcept,%function
-feclearexcept:
- and w0, w0, #0x1f
- mrs x1, fpsr
- bic w1, w1, w0
- msr fpsr, x1
- mov w0, #0
- ret
-
-.global feraiseexcept
-.type feraiseexcept,%function
-feraiseexcept:
- and w0, w0, #0x1f
- mrs x1, fpsr
- orr w1, w1, w0
- msr fpsr, x1
- mov w0, #0
- ret
-
-.global fegetenv
-.type fegetenv,%function
-fegetenv:
- mrs x1, fpcr
- mrs x2, fpsr
- stp w1, w2, [x0]
- mov w0, #0
- ret
-
-// TODO preserve some bits
-.global fesetenv
-.type fesetenv,%function
-fesetenv:
- mov x1, #0
- mov x2, #0
- cmn x0, #1
- b.eq 1f
- ldp w1, w2, [x0]
-1: msr fpcr, x1
- msr fpsr, x2
- mov w0, #0
- ret
lib/libc/wasi/libc-top-half/musl/src/fenv/arm/fenv.c
@@ -1,3 +0,0 @@
-#if !__ARM_PCS_VFP
-#include "../fenv.c"
-#endif
lib/libc/wasi/libc-top-half/musl/src/fenv/i386/fenv.s
@@ -1,164 +0,0 @@
-.hidden __hwcap
-
-.global feclearexcept
-.type feclearexcept,@function
-feclearexcept:
- mov 4(%esp),%ecx
- and $0x3f,%ecx
- fnstsw %ax
- # consider sse fenv as well if the cpu has XMM capability
- call 1f
-1: addl $__hwcap-1b,(%esp)
- pop %edx
- testl $0x02000000,(%edx)
- jz 2f
- # maintain exceptions in the sse mxcsr, clear x87 exceptions
- test %eax,%ecx
- jz 1f
- fnclex
-1: push %edx
- stmxcsr (%esp)
- pop %edx
- and $0x3f,%eax
- or %eax,%edx
- test %edx,%ecx
- jz 1f
- not %ecx
- and %ecx,%edx
- push %edx
- ldmxcsr (%esp)
- pop %edx
-1: xor %eax,%eax
- ret
- # only do the expensive x87 fenv load/store when needed
-2: test %eax,%ecx
- jz 1b
- not %ecx
- and %ecx,%eax
- test $0x3f,%eax
- jz 1f
- fnclex
- jmp 1b
-1: sub $32,%esp
- fnstenv (%esp)
- mov %al,4(%esp)
- fldenv (%esp)
- add $32,%esp
- xor %eax,%eax
- ret
-
-.global feraiseexcept
-.type feraiseexcept,@function
-feraiseexcept:
- mov 4(%esp),%eax
- and $0x3f,%eax
- sub $32,%esp
- fnstenv (%esp)
- or %al,4(%esp)
- fldenv (%esp)
- add $32,%esp
- xor %eax,%eax
- ret
-
-.global __fesetround
-.hidden __fesetround
-.type __fesetround,@function
-__fesetround:
- mov 4(%esp),%ecx
- push %eax
- xor %eax,%eax
- fnstcw (%esp)
- andb $0xf3,1(%esp)
- or %ch,1(%esp)
- fldcw (%esp)
- # consider sse fenv as well if the cpu has XMM capability
- call 1f
-1: addl $__hwcap-1b,(%esp)
- pop %edx
- testl $0x02000000,(%edx)
- jz 1f
- stmxcsr (%esp)
- shl $3,%ch
- andb $0x9f,1(%esp)
- or %ch,1(%esp)
- ldmxcsr (%esp)
-1: pop %ecx
- ret
-
-.global fegetround
-.type fegetround,@function
-fegetround:
- push %eax
- fnstcw (%esp)
- pop %eax
- and $0xc00,%eax
- ret
-
-.global fegetenv
-.type fegetenv,@function
-fegetenv:
- mov 4(%esp),%ecx
- xor %eax,%eax
- fnstenv (%ecx)
- # consider sse fenv as well if the cpu has XMM capability
- call 1f
-1: addl $__hwcap-1b,(%esp)
- pop %edx
- testl $0x02000000,(%edx)
- jz 1f
- push %eax
- stmxcsr (%esp)
- pop %edx
- and $0x3f,%edx
- or %edx,4(%ecx)
-1: ret
-
-.global fesetenv
-.type fesetenv,@function
-fesetenv:
- mov 4(%esp),%ecx
- xor %eax,%eax
- inc %ecx
- jz 1f
- fldenv -1(%ecx)
- movl -1(%ecx),%ecx
- jmp 2f
-1: push %eax
- push %eax
- push %eax
- push %eax
- pushl $0xffff
- push %eax
- pushl $0x37f
- fldenv (%esp)
- add $28,%esp
- # consider sse fenv as well if the cpu has XMM capability
-2: call 1f
-1: addl $__hwcap-1b,(%esp)
- pop %edx
- testl $0x02000000,(%edx)
- jz 1f
- # mxcsr := same rounding mode, cleared exceptions, default mask
- and $0xc00,%ecx
- shl $3,%ecx
- or $0x1f80,%ecx
- mov %ecx,4(%esp)
- ldmxcsr 4(%esp)
-1: ret
-
-.global fetestexcept
-.type fetestexcept,@function
-fetestexcept:
- mov 4(%esp),%ecx
- and $0x3f,%ecx
- fnstsw %ax
- # consider sse fenv as well if the cpu has XMM capability
- call 1f
-1: addl $__hwcap-1b,(%esp)
- pop %edx
- testl $0x02000000,(%edx)
- jz 1f
- stmxcsr 4(%esp)
- or 4(%esp),%eax
-1: and %ecx,%eax
- ret
lib/libc/wasi/libc-top-half/musl/src/fenv/m68k/fenv.c
@@ -1,85 +0,0 @@
-#include <fenv.h>
-#include <features.h>
-
-#if __HAVE_68881__ || __mcffpu__
-
-static unsigned getsr()
-{
- unsigned v;
- __asm__ __volatile__ ("fmove.l %%fpsr,%0" : "=dm"(v));
- return v;
-}
-
-static void setsr(unsigned v)
-{
- __asm__ __volatile__ ("fmove.l %0,%%fpsr" : : "dm"(v));
-}
-
-static unsigned getcr()
-{
- unsigned v;
- __asm__ __volatile__ ("fmove.l %%fpcr,%0" : "=dm"(v));
- return v;
-}
-
-static void setcr(unsigned v)
-{
- __asm__ __volatile__ ("fmove.l %0,%%fpcr" : : "dm"(v));
-}
-
-int feclearexcept(int mask)
-{
- if (mask & ~FE_ALL_EXCEPT) return -1;
- setsr(getsr() & ~mask);
- return 0;
-}
-
-int feraiseexcept(int mask)
-{
- if (mask & ~FE_ALL_EXCEPT) return -1;
- setsr(getsr() | mask);
- return 0;
-}
-
-int fetestexcept(int mask)
-{
- return getsr() & mask;
-}
-
-int fegetround(void)
-{
- return getcr() & FE_UPWARD;
-}
-
-hidden int __fesetround(int r)
-{
- setcr((getcr() & ~FE_UPWARD) | r);
- return 0;
-}
-
-int fegetenv(fenv_t *envp)
-{
- envp->__control_register = getcr();
- envp->__status_register = getsr();
- __asm__ __volatile__ ("fmove.l %%fpiar,%0"
- : "=dm"(envp->__instruction_address));
- return 0;
-}
-
-int fesetenv(const fenv_t *envp)
-{
- static const fenv_t default_env = { 0 };
- if (envp == FE_DFL_ENV)
- envp = &default_env;
- setcr(envp->__control_register);
- setsr(envp->__status_register);
- __asm__ __volatile__ ("fmove.l %0,%%fpiar"
- : : "dm"(envp->__instruction_address));
- return 0;
-}
-
-#else
-
-#include "../fenv.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/fenv/mips/fenv-sf.c
@@ -1,3 +0,0 @@
-#ifdef __mips_soft_float
-#include "../fenv.c"
-#endif
lib/libc/wasi/libc-top-half/musl/src/fenv/mips64/fenv-sf.c
@@ -1,3 +0,0 @@
-#ifdef __mips_soft_float
-#include "../fenv.c"
-#endif
lib/libc/wasi/libc-top-half/musl/src/fenv/mipsn32/fenv-sf.c
@@ -1,3 +0,0 @@
-#ifdef __mips_soft_float
-#include "../fenv.c"
-#endif
lib/libc/wasi/libc-top-half/musl/src/fenv/powerpc/fenv-sf.c
@@ -1,3 +0,0 @@
-#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
-#include "../fenv.c"
-#endif
lib/libc/wasi/libc-top-half/musl/src/fenv/powerpc64/fenv.c
@@ -1,69 +0,0 @@
-#define _GNU_SOURCE
-#include <fenv.h>
-#include <features.h>
-
-static inline double get_fpscr_f(void)
-{
- double d;
- __asm__ __volatile__("mffs %0" : "=d"(d));
- return d;
-}
-
-static inline long get_fpscr(void)
-{
- return (union {double f; long i;}) {get_fpscr_f()}.i;
-}
-
-static inline void set_fpscr_f(double fpscr)
-{
- __asm__ __volatile__("mtfsf 255, %0" : : "d"(fpscr));
-}
-
-static void set_fpscr(long fpscr)
-{
- set_fpscr_f((union {long i; double f;}) {fpscr}.f);
-}
-
-int feclearexcept(int mask)
-{
- mask &= FE_ALL_EXCEPT;
- if (mask & FE_INVALID) mask |= FE_ALL_INVALID;
- set_fpscr(get_fpscr() & ~mask);
- return 0;
-}
-
-int feraiseexcept(int mask)
-{
- mask &= FE_ALL_EXCEPT;
- if (mask & FE_INVALID) mask |= FE_INVALID_SOFTWARE;
- set_fpscr(get_fpscr() | mask);
- return 0;
-}
-
-int fetestexcept(int mask)
-{
- return get_fpscr() & mask & FE_ALL_EXCEPT;
-}
-
-int fegetround(void)
-{
- return get_fpscr() & 3;
-}
-
-hidden int __fesetround(int r)
-{
- set_fpscr(get_fpscr() & ~3L | r);
- return 0;
-}
-
-int fegetenv(fenv_t *envp)
-{
- *envp = get_fpscr_f();
- return 0;
-}
-
-int fesetenv(const fenv_t *envp)
-{
- set_fpscr_f(envp != FE_DFL_ENV ? *envp : 0);
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/fenv/riscv64/fenv-sf.c
@@ -1,3 +0,0 @@
-#ifndef __riscv_flen
-#include "../fenv.c"
-#endif
lib/libc/wasi/libc-top-half/musl/src/fenv/s390x/fenv.c
@@ -1,56 +0,0 @@
-#include <fenv.h>
-#include <features.h>
-
-static inline unsigned get_fpc(void)
-{
- unsigned fpc;
- __asm__ __volatile__("efpc %0" : "=r"(fpc));
- return fpc;
-}
-
-static inline void set_fpc(unsigned fpc)
-{
- __asm__ __volatile__("sfpc %0" :: "r"(fpc));
-}
-
-int feclearexcept(int mask)
-{
- mask &= FE_ALL_EXCEPT;
- set_fpc(get_fpc() & ~mask);
- return 0;
-}
-
-int feraiseexcept(int mask)
-{
- mask &= FE_ALL_EXCEPT;
- set_fpc(get_fpc() | mask);
- return 0;
-}
-
-int fetestexcept(int mask)
-{
- return get_fpc() & mask & FE_ALL_EXCEPT;
-}
-
-int fegetround(void)
-{
- return get_fpc() & 3;
-}
-
-hidden int __fesetround(int r)
-{
- set_fpc(get_fpc() & ~3L | r);
- return 0;
-}
-
-int fegetenv(fenv_t *envp)
-{
- *envp = get_fpc();
- return 0;
-}
-
-int fesetenv(const fenv_t *envp)
-{
- set_fpc(envp != FE_DFL_ENV ? *envp : 0);
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/fenv/sh/fenv-nofpu.c
@@ -1,3 +0,0 @@
-#if !__SH_FPU_ANY__ && !__SH4__
-#include "../fenv.c"
-#endif
lib/libc/wasi/libc-top-half/musl/src/fenv/x32/fenv.s
@@ -1,98 +0,0 @@
-.global feclearexcept
-.type feclearexcept,@function
-feclearexcept:
- # maintain exceptions in the sse mxcsr, clear x87 exceptions
- mov %edi,%ecx
- and $0x3f,%ecx
- fnstsw %ax
- test %eax,%ecx
- jz 1f
- fnclex
-1: stmxcsr -8(%esp)
- and $0x3f,%eax
- or %eax,-8(%esp)
- test %ecx,-8(%esp)
- jz 1f
- not %ecx
- and %ecx,-8(%esp)
- ldmxcsr -8(%esp)
-1: xor %eax,%eax
- ret
-
-.global feraiseexcept
-.type feraiseexcept,@function
-feraiseexcept:
- and $0x3f,%edi
- stmxcsr -8(%esp)
- or %edi,-8(%esp)
- ldmxcsr -8(%esp)
- xor %eax,%eax
- ret
-
-.global __fesetround
-.hidden __fesetround
-.type __fesetround,@function
-__fesetround:
- push %rax
- xor %eax,%eax
- mov %edi,%ecx
- fnstcw (%esp)
- andb $0xf3,1(%esp)
- or %ch,1(%esp)
- fldcw (%esp)
- stmxcsr (%esp)
- shl $3,%ch
- andb $0x9f,1(%esp)
- or %ch,1(%esp)
- ldmxcsr (%esp)
- pop %rcx
- ret
-
-.global fegetround
-.type fegetround,@function
-fegetround:
- push %rax
- stmxcsr (%esp)
- pop %rax
- shr $3,%eax
- and $0xc00,%eax
- ret
-
-.global fegetenv
-.type fegetenv,@function
-fegetenv:
- xor %eax,%eax
- fnstenv (%edi)
- stmxcsr 28(%edi)
- ret
-
-.global fesetenv
-.type fesetenv,@function
-fesetenv:
- xor %eax,%eax
- inc %edi
- jz 1f
- fldenv -1(%edi)
- ldmxcsr 27(%edi)
- ret
-1: push %rax
- push %rax
- pushq $0xffff
- pushq $0x37f
- fldenv (%esp)
- pushq $0x1f80
- ldmxcsr (%esp)
- add $40,%esp
- ret
-
-.global fetestexcept
-.type fetestexcept,@function
-fetestexcept:
- and $0x3f,%edi
- push %rax
- stmxcsr (%esp)
- pop %rsi
- fnstsw %ax
- or %esi,%eax
- and %edi,%eax
- ret
lib/libc/wasi/libc-top-half/musl/src/fenv/x86_64/fenv.s
@@ -1,98 +0,0 @@
-.global feclearexcept
-.type feclearexcept,@function
-feclearexcept:
- # maintain exceptions in the sse mxcsr, clear x87 exceptions
- mov %edi,%ecx
- and $0x3f,%ecx
- fnstsw %ax
- test %eax,%ecx
- jz 1f
- fnclex
-1: stmxcsr -8(%rsp)
- and $0x3f,%eax
- or %eax,-8(%rsp)
- test %ecx,-8(%rsp)
- jz 1f
- not %ecx
- and %ecx,-8(%rsp)
- ldmxcsr -8(%rsp)
-1: xor %eax,%eax
- ret
-
-.global feraiseexcept
-.type feraiseexcept,@function
-feraiseexcept:
- and $0x3f,%edi
- stmxcsr -8(%rsp)
- or %edi,-8(%rsp)
- ldmxcsr -8(%rsp)
- xor %eax,%eax
- ret
-
-.global __fesetround
-.hidden __fesetround
-.type __fesetround,@function
-__fesetround:
- push %rax
- xor %eax,%eax
- mov %edi,%ecx
- fnstcw (%rsp)
- andb $0xf3,1(%rsp)
- or %ch,1(%rsp)
- fldcw (%rsp)
- stmxcsr (%rsp)
- shl $3,%ch
- andb $0x9f,1(%rsp)
- or %ch,1(%rsp)
- ldmxcsr (%rsp)
- pop %rcx
- ret
-
-.global fegetround
-.type fegetround,@function
-fegetround:
- push %rax
- stmxcsr (%rsp)
- pop %rax
- shr $3,%eax
- and $0xc00,%eax
- ret
-
-.global fegetenv
-.type fegetenv,@function
-fegetenv:
- xor %eax,%eax
- fnstenv (%rdi)
- stmxcsr 28(%rdi)
- ret
-
-.global fesetenv
-.type fesetenv,@function
-fesetenv:
- xor %eax,%eax
- inc %rdi
- jz 1f
- fldenv -1(%rdi)
- ldmxcsr 27(%rdi)
- ret
-1: push %rax
- push %rax
- pushq $0xffff
- pushq $0x37f
- fldenv (%rsp)
- pushq $0x1f80
- ldmxcsr (%rsp)
- add $40,%rsp
- ret
-
-.global fetestexcept
-.type fetestexcept,@function
-fetestexcept:
- and $0x3f,%edi
- push %rax
- stmxcsr (%rsp)
- pop %rsi
- fnstsw %ax
- or %esi,%eax
- and %edi,%eax
- ret
lib/libc/wasi/libc-top-half/musl/src/fenv/__flt_rounds.c
@@ -1,19 +0,0 @@
-#include <float.h>
-#include <fenv.h>
-
-int __flt_rounds()
-{
- switch (fegetround()) {
-#ifdef FE_TOWARDZERO
- case FE_TOWARDZERO: return 0;
-#endif
- case FE_TONEAREST: return 1;
-#ifdef FE_UPWARD
- case FE_UPWARD: return 2;
-#endif
-#ifdef FE_DOWNWARD
- case FE_DOWNWARD: return 3;
-#endif
- }
- return -1;
-}
lib/libc/wasi/libc-top-half/musl/src/internal/i386/defsysinfo.s
@@ -1,9 +0,0 @@
-1: int $128
- ret
-
-.data
-.align 4
-.hidden __sysinfo
-.global __sysinfo
-__sysinfo:
- .long 1b
lib/libc/wasi/libc-top-half/musl/src/internal/sh/__shcall.c
@@ -1,6 +0,0 @@
-#include <features.h>
-
-hidden int __shcall(void *arg, int (*func)(void *))
-{
- return func(arg);
-}
lib/libc/wasi/libc-top-half/musl/src/internal/procfdname.c
@@ -1,15 +0,0 @@
-#include "syscall.h"
-
-void __procfdname(char *buf, unsigned fd)
-{
- unsigned i, j;
- for (i=0; (buf[i] = "/proc/self/fd/"[i]); i++);
- if (!fd) {
- buf[i] = '0';
- buf[i+1] = 0;
- return;
- }
- for (j=fd; j; j/=10, i++);
- buf[i] = 0;
- for (; fd; fd/=10) buf[--i] = '0' + fd%10;
-}
lib/libc/wasi/libc-top-half/musl/src/internal/syscall_ret.c
@@ -1,11 +0,0 @@
-#include <errno.h>
-#include "syscall.h"
-
-long __syscall_ret(unsigned long r)
-{
- if (r > -4096UL) {
- errno = -r;
- return -1;
- }
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/internal/vdso.c
@@ -1,93 +0,0 @@
-#include <elf.h>
-#include <link.h>
-#include <limits.h>
-#include <stdint.h>
-#include <string.h>
-#include "libc.h"
-#include "syscall.h"
-
-#ifdef VDSO_USEFUL
-
-#if ULONG_MAX == 0xffffffff
-typedef Elf32_Ehdr Ehdr;
-typedef Elf32_Phdr Phdr;
-typedef Elf32_Sym Sym;
-typedef Elf32_Verdef Verdef;
-typedef Elf32_Verdaux Verdaux;
-#else
-typedef Elf64_Ehdr Ehdr;
-typedef Elf64_Phdr Phdr;
-typedef Elf64_Sym Sym;
-typedef Elf64_Verdef Verdef;
-typedef Elf64_Verdaux Verdaux;
-#endif
-
-static int checkver(Verdef *def, int vsym, const char *vername, char *strings)
-{
- vsym &= 0x7fff;
- for (;;) {
- if (!(def->vd_flags & VER_FLG_BASE)
- && (def->vd_ndx & 0x7fff) == vsym)
- break;
- if (def->vd_next == 0)
- return 0;
- def = (Verdef *)((char *)def + def->vd_next);
- }
- Verdaux *aux = (Verdaux *)((char *)def + def->vd_aux);
- return !strcmp(vername, strings + aux->vda_name);
-}
-
-#define OK_TYPES (1<<STT_NOTYPE | 1<<STT_OBJECT | 1<<STT_FUNC | 1<<STT_COMMON)
-#define OK_BINDS (1<<STB_GLOBAL | 1<<STB_WEAK | 1<<STB_GNU_UNIQUE)
-
-void *__vdsosym(const char *vername, const char *name)
-{
- size_t i;
- for (i=0; libc.auxv[i] != AT_SYSINFO_EHDR; i+=2)
- if (!libc.auxv[i]) return 0;
- if (!libc.auxv[i+1]) return 0;
- Ehdr *eh = (void *)libc.auxv[i+1];
- Phdr *ph = (void *)((char *)eh + eh->e_phoff);
- size_t *dynv=0, base=-1;
- for (i=0; i<eh->e_phnum; i++, ph=(void *)((char *)ph+eh->e_phentsize)) {
- if (ph->p_type == PT_LOAD)
- base = (size_t)eh + ph->p_offset - ph->p_vaddr;
- else if (ph->p_type == PT_DYNAMIC)
- dynv = (void *)((char *)eh + ph->p_offset);
- }
- if (!dynv || base==(size_t)-1) return 0;
-
- char *strings = 0;
- Sym *syms = 0;
- Elf_Symndx *hashtab = 0;
- uint16_t *versym = 0;
- Verdef *verdef = 0;
-
- for (i=0; dynv[i]; i+=2) {
- void *p = (void *)(base + dynv[i+1]);
- switch(dynv[i]) {
- case DT_STRTAB: strings = p; break;
- case DT_SYMTAB: syms = p; break;
- case DT_HASH: hashtab = p; break;
- case DT_VERSYM: versym = p; break;
- case DT_VERDEF: verdef = p; break;
- }
- }
-
- if (!strings || !syms || !hashtab) return 0;
- if (!verdef) versym = 0;
-
- for (i=0; i<hashtab[1]; i++) {
- if (!(1<<(syms[i].st_info&0xf) & OK_TYPES)) continue;
- if (!(1<<(syms[i].st_info>>4) & OK_BINDS)) continue;
- if (!syms[i].st_shndx) continue;
- if (strcmp(name, strings+syms[i].st_name)) continue;
- if (versym && !checkver(verdef, versym[i], vername, strings))
- continue;
- return (void *)(base + syms[i].st_value);
- }
-
- return 0;
-}
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/internal/version.c
@@ -1,4 +0,0 @@
-#include "version.h"
-#include "libc.h"
-
-const char __libc_version[] = VERSION;
lib/libc/wasi/libc-top-half/musl/src/ipc/ftok.c
@@ -1,10 +0,0 @@
-#include <sys/ipc.h>
-#include <sys/stat.h>
-
-key_t ftok(const char *path, int id)
-{
- struct stat st;
- if (stat(path, &st) < 0) return -1;
-
- return ((st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16) | ((id & 0xffu) << 24));
-}
lib/libc/wasi/libc-top-half/musl/src/ipc/msgctl.c
@@ -1,51 +0,0 @@
-#include <sys/msg.h>
-#include <endian.h>
-#include "syscall.h"
-#include "ipc.h"
-
-#if __BYTE_ORDER != __BIG_ENDIAN
-#undef SYSCALL_IPC_BROKEN_MODE
-#endif
-
-int msgctl(int q, int cmd, struct msqid_ds *buf)
-{
-#if IPC_TIME64
- struct msqid_ds out, *orig;
- if (cmd&IPC_TIME64) {
- out = (struct msqid_ds){0};
- orig = buf;
- buf = &out;
- }
-#endif
-#ifdef SYSCALL_IPC_BROKEN_MODE
- struct msqid_ds tmp;
- if (cmd == IPC_SET) {
- tmp = *buf;
- tmp.msg_perm.mode *= 0x10000U;
- buf = &tmp;
- }
-#endif
-#ifndef SYS_ipc
- int r = __syscall(SYS_msgctl, q, IPC_CMD(cmd), buf);
-#else
- int r = __syscall(SYS_ipc, IPCOP_msgctl, q, IPC_CMD(cmd), 0, buf, 0);
-#endif
-#ifdef SYSCALL_IPC_BROKEN_MODE
- if (r >= 0) switch (cmd | IPC_TIME64) {
- case IPC_STAT:
- case MSG_STAT:
- case MSG_STAT_ANY:
- buf->msg_perm.mode >>= 16;
- }
-#endif
-#if IPC_TIME64
- if (r >= 0 && (cmd&IPC_TIME64)) {
- buf = orig;
- *buf = out;
- IPC_HILO(buf, msg_stime);
- IPC_HILO(buf, msg_rtime);
- IPC_HILO(buf, msg_ctime);
- }
-#endif
- return __syscall_ret(r);
-}
lib/libc/wasi/libc-top-half/musl/src/ipc/msgget.c
@@ -1,12 +0,0 @@
-#include <sys/msg.h>
-#include "syscall.h"
-#include "ipc.h"
-
-int msgget(key_t k, int flag)
-{
-#ifndef SYS_ipc
- return syscall(SYS_msgget, k, flag);
-#else
- return syscall(SYS_ipc, IPCOP_msgget, k, flag);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/ipc/msgrcv.c
@@ -1,12 +0,0 @@
-#include <sys/msg.h>
-#include "syscall.h"
-#include "ipc.h"
-
-ssize_t msgrcv(int q, void *m, size_t len, long type, int flag)
-{
-#ifndef SYS_ipc
- return syscall_cp(SYS_msgrcv, q, m, len, type, flag);
-#else
- return syscall_cp(SYS_ipc, IPCOP_msgrcv, q, len, flag, ((long[]){ (long)m, type }));
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/ipc/msgsnd.c
@@ -1,12 +0,0 @@
-#include <sys/msg.h>
-#include "syscall.h"
-#include "ipc.h"
-
-int msgsnd(int q, const void *m, size_t len, int flag)
-{
-#ifndef SYS_ipc
- return syscall_cp(SYS_msgsnd, q, m, len, flag);
-#else
- return syscall_cp(SYS_ipc, IPCOP_msgsnd, q, len, flag, m);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/ipc/semctl.c
@@ -1,69 +0,0 @@
-#include <sys/sem.h>
-#include <stdarg.h>
-#include <endian.h>
-#include "syscall.h"
-#include "ipc.h"
-
-#if __BYTE_ORDER != __BIG_ENDIAN
-#undef SYSCALL_IPC_BROKEN_MODE
-#endif
-
-union semun {
- int val;
- struct semid_ds *buf;
- unsigned short *array;
-};
-
-int semctl(int id, int num, int cmd, ...)
-{
- union semun arg = {0};
- va_list ap;
- switch (cmd & ~IPC_TIME64) {
- case SETVAL: case GETALL: case SETALL: case IPC_SET:
- case IPC_INFO: case SEM_INFO:
- case IPC_STAT & ~IPC_TIME64:
- case SEM_STAT & ~IPC_TIME64:
- case SEM_STAT_ANY & ~IPC_TIME64:
- va_start(ap, cmd);
- arg = va_arg(ap, union semun);
- va_end(ap);
- }
-#if IPC_TIME64
- struct semid_ds out, *orig;
- if (cmd&IPC_TIME64) {
- out = (struct semid_ds){0};
- orig = arg.buf;
- arg.buf = &out;
- }
-#endif
-#ifdef SYSCALL_IPC_BROKEN_MODE
- struct semid_ds tmp;
- if (cmd == IPC_SET) {
- tmp = *arg.buf;
- tmp.sem_perm.mode *= 0x10000U;
- arg.buf = &tmp;
- }
-#endif
-#ifndef SYS_ipc
- int r = __syscall(SYS_semctl, id, num, IPC_CMD(cmd), arg.buf);
-#else
- int r = __syscall(SYS_ipc, IPCOP_semctl, id, num, IPC_CMD(cmd), &arg.buf);
-#endif
-#ifdef SYSCALL_IPC_BROKEN_MODE
- if (r >= 0) switch (cmd | IPC_TIME64) {
- case IPC_STAT:
- case SEM_STAT:
- case SEM_STAT_ANY:
- arg.buf->sem_perm.mode >>= 16;
- }
-#endif
-#if IPC_TIME64
- if (r >= 0 && (cmd&IPC_TIME64)) {
- arg.buf = orig;
- *arg.buf = out;
- IPC_HILO(arg.buf, sem_otime);
- IPC_HILO(arg.buf, sem_ctime);
- }
-#endif
- return __syscall_ret(r);
-}
lib/libc/wasi/libc-top-half/musl/src/ipc/semget.c
@@ -1,19 +0,0 @@
-#include <sys/sem.h>
-#include <limits.h>
-#include <errno.h>
-#include "syscall.h"
-#include "ipc.h"
-
-int semget(key_t key, int n, int fl)
-{
- /* The kernel uses the wrong type for the sem_nsems member
- * of struct semid_ds, and thus might not check that the
- * n fits in the correct (per POSIX) userspace type, so
- * we have to check here. */
- if (n > USHRT_MAX) return __syscall_ret(-EINVAL);
-#ifndef SYS_ipc
- return syscall(SYS_semget, key, n, fl);
-#else
- return syscall(SYS_ipc, IPCOP_semget, key, n, fl);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/ipc/semop.c
@@ -1,12 +0,0 @@
-#include <sys/sem.h>
-#include "syscall.h"
-#include "ipc.h"
-
-int semop(int id, struct sembuf *buf, size_t n)
-{
-#ifndef SYS_ipc
- return syscall(SYS_semop, id, buf, n);
-#else
- return syscall(SYS_ipc, IPCOP_semop, id, n, 0, buf);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/ipc/semtimedop.c
@@ -1,35 +0,0 @@
-#define _GNU_SOURCE
-#include <sys/sem.h>
-#include <errno.h>
-#include "syscall.h"
-#include "ipc.h"
-
-#define IS32BIT(x) !((x)+0x80000000ULL>>32)
-#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
-
-#if !defined(SYS_semtimedop) && !defined(SYS_ipc)
-#define NO_TIME32 1
-#else
-#define NO_TIME32 0
-#endif
-
-int semtimedop(int id, struct sembuf *buf, size_t n, const struct timespec *ts)
-{
-#ifdef SYS_semtimedop_time64
- time_t s = ts ? ts->tv_sec : 0;
- long ns = ts ? ts->tv_nsec : 0;
- int r = -ENOSYS;
- if (NO_TIME32 || !IS32BIT(s))
- r = __syscall(SYS_semtimedop_time64, id, buf, n,
- ts ? ((long long[]){s, ns}) : 0);
- if (NO_TIME32 || r!=-ENOSYS) return __syscall_ret(r);
- ts = ts ? (void *)(long[]){CLAMP(s), ns} : 0;
-#endif
-#if defined(SYS_ipc)
- return syscall(SYS_ipc, IPCOP_semtimedop, id, n, 0, buf, ts);
-#elif defined(SYS_semtimedop)
- return syscall(SYS_semtimedop, id, buf, n, ts);
-#else
- return __syscall_ret(-ENOSYS);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/ipc/shmat.c
@@ -1,17 +0,0 @@
-#include <sys/shm.h>
-#include "syscall.h"
-#include "ipc.h"
-
-#ifndef SYS_ipc
-void *shmat(int id, const void *addr, int flag)
-{
- return (void *)syscall(SYS_shmat, id, addr, flag);
-}
-#else
-void *shmat(int id, const void *addr, int flag)
-{
- unsigned long ret;
- ret = syscall(SYS_ipc, IPCOP_shmat, id, flag, &addr, addr);
- return (ret > -(unsigned long)SHMLBA) ? (void *)ret : (void *)addr;
-}
-#endif
lib/libc/wasi/libc-top-half/musl/src/ipc/shmctl.c
@@ -1,51 +0,0 @@
-#include <sys/shm.h>
-#include <endian.h>
-#include "syscall.h"
-#include "ipc.h"
-
-#if __BYTE_ORDER != __BIG_ENDIAN
-#undef SYSCALL_IPC_BROKEN_MODE
-#endif
-
-int shmctl(int id, int cmd, struct shmid_ds *buf)
-{
-#if IPC_TIME64
- struct shmid_ds out, *orig;
- if (cmd&IPC_TIME64) {
- out = (struct shmid_ds){0};
- orig = buf;
- buf = &out;
- }
-#endif
-#ifdef SYSCALL_IPC_BROKEN_MODE
- struct shmid_ds tmp;
- if (cmd == IPC_SET) {
- tmp = *buf;
- tmp.shm_perm.mode *= 0x10000U;
- buf = &tmp;
- }
-#endif
-#ifndef SYS_ipc
- int r = __syscall(SYS_shmctl, id, IPC_CMD(cmd), buf);
-#else
- int r = __syscall(SYS_ipc, IPCOP_shmctl, id, IPC_CMD(cmd), 0, buf, 0);
-#endif
-#ifdef SYSCALL_IPC_BROKEN_MODE
- if (r >= 0) switch (cmd | IPC_TIME64) {
- case IPC_STAT:
- case SHM_STAT:
- case SHM_STAT_ANY:
- buf->shm_perm.mode >>= 16;
- }
-#endif
-#if IPC_TIME64
- if (r >= 0 && (cmd&IPC_TIME64)) {
- buf = orig;
- *buf = out;
- IPC_HILO(buf, shm_atime);
- IPC_HILO(buf, shm_dtime);
- IPC_HILO(buf, shm_ctime);
- }
-#endif
- return __syscall_ret(r);
-}
lib/libc/wasi/libc-top-half/musl/src/ipc/shmdt.c
@@ -1,12 +0,0 @@
-#include <sys/shm.h>
-#include "syscall.h"
-#include "ipc.h"
-
-int shmdt(const void *addr)
-{
-#ifndef SYS_ipc
- return syscall(SYS_shmdt, addr);
-#else
- return syscall(SYS_ipc, IPCOP_shmdt, 0, 0, 0, addr);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/ipc/shmget.c
@@ -1,14 +0,0 @@
-#include <sys/shm.h>
-#include <stdint.h>
-#include "syscall.h"
-#include "ipc.h"
-
-int shmget(key_t key, size_t size, int flag)
-{
- if (size > PTRDIFF_MAX) size = SIZE_MAX;
-#ifndef SYS_ipc
- return syscall(SYS_shmget, key, size, flag);
-#else
- return syscall(SYS_ipc, IPCOP_shmget, key, size, flag);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/ldso/aarch64/dlsym.s
@@ -1,6 +0,0 @@
-.global dlsym
-.hidden __dlsym
-.type dlsym,%function
-dlsym:
- mov x2,x30
- b __dlsym
lib/libc/wasi/libc-top-half/musl/src/ldso/aarch64/tlsdesc.s
@@ -1,31 +0,0 @@
-// size_t __tlsdesc_static(size_t *a)
-// {
-// return a[1];
-// }
-.global __tlsdesc_static
-.hidden __tlsdesc_static
-.type __tlsdesc_static,@function
-__tlsdesc_static:
- ldr x0,[x0,#8]
- ret
-
-// size_t __tlsdesc_dynamic(size_t *a)
-// {
-// struct {size_t modidx,off;} *p = (void*)a[1];
-// size_t *dtv = *(size_t**)(tp - 8);
-// return dtv[p->modidx] + p->off - tp;
-// }
-.global __tlsdesc_dynamic
-.hidden __tlsdesc_dynamic
-.type __tlsdesc_dynamic,@function
-__tlsdesc_dynamic:
- stp x1,x2,[sp,#-16]!
- mrs x1,tpidr_el0 // tp
- ldr x0,[x0,#8] // p
- ldp x0,x2,[x0] // p->modidx, p->off
- sub x2,x2,x1 // p->off - tp
- ldr x1,[x1,#-8] // dtv
- ldr x1,[x1,x0,lsl #3] // dtv[p->modidx]
- add x0,x1,x2 // dtv[p->modidx] + p->off - tp
- ldp x1,x2,[sp],#16
- ret
lib/libc/wasi/libc-top-half/musl/src/ldso/arm/dlsym.s
@@ -1,8 +0,0 @@
-.syntax unified
-.text
-.global dlsym
-.hidden __dlsym
-.type dlsym,%function
-dlsym:
- mov r2,lr
- b __dlsym
lib/libc/wasi/libc-top-half/musl/src/ldso/arm/find_exidx.c
@@ -1,42 +0,0 @@
-#define _GNU_SOURCE
-#include <link.h>
-#include <stdint.h>
-
-struct find_exidx_data {
- uintptr_t pc, exidx_start;
- int exidx_len;
-};
-
-static int find_exidx(struct dl_phdr_info *info, size_t size, void *ptr)
-{
- struct find_exidx_data *data = ptr;
- const ElfW(Phdr) *phdr = info->dlpi_phdr;
- uintptr_t addr, exidx_start = 0;
- int i, match = 0, exidx_len = 0;
-
- for (i = info->dlpi_phnum; i > 0; i--, phdr++) {
- addr = info->dlpi_addr + phdr->p_vaddr;
- switch (phdr->p_type) {
- case PT_LOAD:
- match |= data->pc >= addr && data->pc < addr + phdr->p_memsz;
- break;
- case PT_ARM_EXIDX:
- exidx_start = addr;
- exidx_len = phdr->p_memsz;
- break;
- }
- }
- data->exidx_start = exidx_start;
- data->exidx_len = exidx_len;
- return match;
-}
-
-uintptr_t __gnu_Unwind_Find_exidx(uintptr_t pc, int *pcount)
-{
- struct find_exidx_data data;
- data.pc = pc;
- if (dl_iterate_phdr(find_exidx, &data) <= 0)
- return 0;
- *pcount = data.exidx_len / 8;
- return data.exidx_start;
-}
lib/libc/wasi/libc-top-half/musl/src/ldso/i386/dlsym.s
@@ -1,11 +0,0 @@
-.text
-.global dlsym
-.hidden __dlsym
-.type dlsym,@function
-dlsym:
- push (%esp)
- push 12(%esp)
- push 12(%esp)
- call __dlsym
- add $12,%esp
- ret
lib/libc/wasi/libc-top-half/musl/src/ldso/i386/tlsdesc.s
@@ -1,23 +0,0 @@
-.text
-.global __tlsdesc_static
-.hidden __tlsdesc_static
-.type __tlsdesc_static,@function
-__tlsdesc_static:
- mov 4(%eax),%eax
- ret
-
-.global __tlsdesc_dynamic
-.hidden __tlsdesc_dynamic
-.type __tlsdesc_dynamic,@function
-__tlsdesc_dynamic:
- mov 4(%eax),%eax
- push %edx
- mov %gs:4,%edx
- push %ecx
- mov (%eax),%ecx
- mov 4(%eax),%eax
- add (%edx,%ecx,4),%eax
- pop %ecx
- sub %gs:0,%eax
- pop %edx
- ret
lib/libc/wasi/libc-top-half/musl/src/ldso/m68k/dlsym.s
@@ -1,12 +0,0 @@
-.text
-.global dlsym
-.hidden __dlsym
-.type dlsym,@function
-dlsym:
- move.l (%sp),-(%sp)
- move.l 12(%sp),-(%sp)
- move.l 12(%sp),-(%sp)
- lea __dlsym-.-8,%a1
- jsr (%pc,%a1)
- add.l #12,%sp
- rts
lib/libc/wasi/libc-top-half/musl/src/ldso/microblaze/dlsym.s
@@ -1,6 +0,0 @@
-.global dlsym
-.hidden __dlsym
-.type dlsym,@function
-dlsym:
- brid __dlsym
- add r7, r15, r0
lib/libc/wasi/libc-top-half/musl/src/ldso/mips/dlsym.s
@@ -1,17 +0,0 @@
-.set noreorder
-.global dlsym
-.hidden __dlsym
-.type dlsym,@function
-dlsym:
- lui $gp, %hi(_gp_disp)
- addiu $gp, %lo(_gp_disp)
- addu $gp, $gp, $25
- move $6, $ra
- lw $25, %call16(__dlsym)($gp)
- addiu $sp, $sp, -16
- sw $ra, 12($sp)
- jalr $25
- nop
- lw $ra, 12($sp)
- jr $ra
- addiu $sp, $sp, 16
lib/libc/wasi/libc-top-half/musl/src/ldso/mips64/dlsym.s
@@ -1,17 +0,0 @@
-.set noreorder
-.global dlsym
-.hidden __dlsym
-.type dlsym,@function
-dlsym:
- lui $3, %hi(%neg(%gp_rel(dlsym)))
- daddiu $3, $3, %lo(%neg(%gp_rel(dlsym)))
- daddu $3, $3, $25
- move $6, $ra
- ld $25, %got_disp(__dlsym)($3)
- daddiu $sp, $sp, -32
- sd $ra, 24($sp)
- jalr $25
- nop
- ld $ra, 24($sp)
- jr $ra
- daddiu $sp, $sp, 32
lib/libc/wasi/libc-top-half/musl/src/ldso/mipsn32/dlsym.s
@@ -1,17 +0,0 @@
-.set noreorder
-.global dlsym
-.hidden __dlsym
-.type dlsym,@function
-dlsym:
- lui $3, %hi(%neg(%gp_rel(dlsym)))
- addiu $3, $3, %lo(%neg(%gp_rel(dlsym)))
- addu $3, $3, $25
- move $6, $ra
- lw $25, %got_disp(__dlsym)($3)
- addiu $sp, $sp, -32
- sd $ra, 16($sp)
- jalr $25
- nop
- ld $ra, 16($sp)
- jr $ra
- addiu $sp, $sp, 32
lib/libc/wasi/libc-top-half/musl/src/ldso/or1k/dlsym.s
@@ -1,6 +0,0 @@
-.global dlsym
-.hidden __dlsym
-.type dlsym,@function
-dlsym:
- l.j __dlsym
- l.ori r5, r9, 0
lib/libc/wasi/libc-top-half/musl/src/ldso/powerpc/dlsym.s
@@ -1,8 +0,0 @@
- .text
- .global dlsym
- .hidden __dlsym
- .type dlsym,@function
-dlsym:
- mflr 5 # The return address is arg3.
- b __dlsym
- .size dlsym, .-dlsym
lib/libc/wasi/libc-top-half/musl/src/ldso/powerpc64/dlsym.s
@@ -1,11 +0,0 @@
- .text
- .global dlsym
- .hidden __dlsym
- .type dlsym,@function
-dlsym:
- addis 2, 12, .TOC.-dlsym@ha
- addi 2, 2, .TOC.-dlsym@l
- .localentry dlsym,.-dlsym
- mflr 5 # The return address is arg3.
- b __dlsym
- .size dlsym, .-dlsym
lib/libc/wasi/libc-top-half/musl/src/ldso/riscv64/dlsym.s
@@ -1,6 +0,0 @@
-.global dlsym
-.hidden __dlsym
-.type dlsym, %function
-dlsym:
- mv a2, ra
- tail __dlsym
lib/libc/wasi/libc-top-half/musl/src/ldso/s390x/dlsym.s
@@ -1,6 +0,0 @@
- .global dlsym
- .hidden __dlsym
- .type dlsym,@function
-dlsym:
- lgr %r4, %r14
- jg __dlsym
lib/libc/wasi/libc-top-half/musl/src/ldso/sh/dlsym.s
@@ -1,11 +0,0 @@
-.text
-.global dlsym
-.hidden __dlsym
-.type dlsym, @function
-dlsym:
- mov.l L1, r0
-1: braf r0
- mov.l @r15, r6
-
-.align 2
-L1: .long __dlsym@PLT-(1b+4-.)
lib/libc/wasi/libc-top-half/musl/src/ldso/x32/dlsym.s
@@ -1,7 +0,0 @@
-.text
-.global dlsym
-.hidden __dlsym
-.type dlsym,@function
-dlsym:
- mov (%rsp),%rdx
- jmp __dlsym
lib/libc/wasi/libc-top-half/musl/src/ldso/x86_64/dlsym.s
@@ -1,7 +0,0 @@
-.text
-.global dlsym
-.hidden __dlsym
-.type dlsym,@function
-dlsym:
- mov (%rsp),%rdx
- jmp __dlsym
lib/libc/wasi/libc-top-half/musl/src/ldso/x86_64/tlsdesc.s
@@ -1,23 +0,0 @@
-.text
-.global __tlsdesc_static
-.hidden __tlsdesc_static
-.type __tlsdesc_static,@function
-__tlsdesc_static:
- mov 8(%rax),%rax
- ret
-
-.global __tlsdesc_dynamic
-.hidden __tlsdesc_dynamic
-.type __tlsdesc_dynamic,@function
-__tlsdesc_dynamic:
- mov 8(%rax),%rax
- push %rdx
- mov %fs:8,%rdx
- push %rcx
- mov (%rax),%rcx
- mov 8(%rax),%rax
- add (%rdx,%rcx,8),%rax
- pop %rcx
- sub %fs:0,%rax
- pop %rdx
- ret
lib/libc/wasi/libc-top-half/musl/src/ldso/__dlsym.c
@@ -1,14 +0,0 @@
-#include <dlfcn.h>
-#include "dynlink.h"
-
-static void *stub_dlsym(void *restrict p, const char *restrict s, void *restrict ra)
-{
- __dl_seterr("Symbol not found: %s", s);
- return 0;
-}
-
-weak_alias(stub_dlsym, __dlsym);
-
-#if _REDIR_TIME64
-weak_alias(stub_dlsym, __dlsym_redir_time64);
-#endif
lib/libc/wasi/libc-top-half/musl/src/ldso/dl_iterate_phdr.c
@@ -1,47 +0,0 @@
-#include <elf.h>
-#include <link.h>
-#include "pthread_impl.h"
-#include "libc.h"
-
-#define AUX_CNT 38
-
-extern weak hidden const size_t _DYNAMIC[];
-
-static int static_dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data)
-{
- unsigned char *p;
- ElfW(Phdr) *phdr, *tls_phdr=0;
- size_t base = 0;
- size_t n;
- struct dl_phdr_info info;
- size_t i, aux[AUX_CNT] = {0};
-
- for (i=0; libc.auxv[i]; i+=2)
- if (libc.auxv[i]<AUX_CNT) aux[libc.auxv[i]] = libc.auxv[i+1];
-
- for (p=(void *)aux[AT_PHDR],n=aux[AT_PHNUM]; n; n--,p+=aux[AT_PHENT]) {
- phdr = (void *)p;
- if (phdr->p_type == PT_PHDR)
- base = aux[AT_PHDR] - phdr->p_vaddr;
- if (phdr->p_type == PT_DYNAMIC && _DYNAMIC)
- base = (size_t)_DYNAMIC - phdr->p_vaddr;
- if (phdr->p_type == PT_TLS)
- tls_phdr = phdr;
- }
- info.dlpi_addr = base;
- info.dlpi_name = "/proc/self/exe";
- info.dlpi_phdr = (void *)aux[AT_PHDR];
- info.dlpi_phnum = aux[AT_PHNUM];
- info.dlpi_adds = 0;
- info.dlpi_subs = 0;
- if (tls_phdr) {
- info.dlpi_tls_modid = 1;
- info.dlpi_tls_data = __tls_get_addr((tls_mod_off_t[]){1,0});
- } else {
- info.dlpi_tls_modid = 0;
- info.dlpi_tls_data = 0;
- }
- return (callback)(&info, sizeof (info), data);
-}
-
-weak_alias(static_dl_iterate_phdr, dl_iterate_phdr);
lib/libc/wasi/libc-top-half/musl/src/ldso/dladdr.c
@@ -1,9 +0,0 @@
-#define _GNU_SOURCE
-#include <dlfcn.h>
-
-static int stub_dladdr(const void *addr, Dl_info *info)
-{
- return 0;
-}
-
-weak_alias(stub_dladdr, dladdr);
lib/libc/wasi/libc-top-half/musl/src/ldso/dlclose.c
@@ -1,7 +0,0 @@
-#include <dlfcn.h>
-#include "dynlink.h"
-
-int dlclose(void *p)
-{
- return __dl_invalid_handle(p);
-}
lib/libc/wasi/libc-top-half/musl/src/ldso/dlerror.c
@@ -1,87 +0,0 @@
-#include <dlfcn.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include "pthread_impl.h"
-#include "dynlink.h"
-#include "lock.h"
-#include "fork_impl.h"
-
-#define malloc __libc_malloc
-#define calloc __libc_calloc
-#define realloc __libc_realloc
-#define free __libc_free
-
-char *dlerror()
-{
- pthread_t self = __pthread_self();
- if (!self->dlerror_flag) return 0;
- self->dlerror_flag = 0;
- char *s = self->dlerror_buf;
- if (s == (void *)-1)
- return "Dynamic linker failed to allocate memory for error message";
- else
- return s;
-}
-
-static volatile int freebuf_queue_lock[1];
-static void **freebuf_queue;
-volatile int *const __dlerror_lockptr = freebuf_queue_lock;
-
-void __dl_thread_cleanup(void)
-{
- pthread_t self = __pthread_self();
- if (self->dlerror_buf && self->dlerror_buf != (void *)-1) {
- LOCK(freebuf_queue_lock);
- void **p = (void **)self->dlerror_buf;
- *p = freebuf_queue;
- freebuf_queue = p;
- UNLOCK(freebuf_queue_lock);
- }
-}
-
-hidden void __dl_vseterr(const char *fmt, va_list ap)
-{
- LOCK(freebuf_queue_lock);
- void **q = freebuf_queue;
- freebuf_queue = 0;
- UNLOCK(freebuf_queue_lock);
-
- while (q) {
- void **p = *q;
- free(q);
- q = p;
- }
-
- va_list ap2;
- va_copy(ap2, ap);
- pthread_t self = __pthread_self();
- if (self->dlerror_buf != (void *)-1)
- free(self->dlerror_buf);
- size_t len = vsnprintf(0, 0, fmt, ap2);
- if (len < sizeof(void *)) len = sizeof(void *);
- va_end(ap2);
- char *buf = malloc(len+1);
- if (buf) {
- vsnprintf(buf, len+1, fmt, ap);
- } else {
- buf = (void *)-1;
- }
- self->dlerror_buf = buf;
- self->dlerror_flag = 1;
-}
-
-hidden void __dl_seterr(const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- __dl_vseterr(fmt, ap);
- va_end(ap);
-}
-
-static int stub_invalid_handle(void *h)
-{
- __dl_seterr("Invalid library handle %p", (void *)h);
- return 1;
-}
-
-weak_alias(stub_invalid_handle, __dl_invalid_handle);
lib/libc/wasi/libc-top-half/musl/src/ldso/dlinfo.c
@@ -1,14 +0,0 @@
-#define _GNU_SOURCE
-#include <dlfcn.h>
-#include "dynlink.h"
-
-int dlinfo(void *dso, int req, void *res)
-{
- if (__dl_invalid_handle(dso)) return -1;
- if (req != RTLD_DI_LINKMAP) {
- __dl_seterr("Unsupported request %d", req);
- return -1;
- }
- *(struct link_map **)res = dso;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/ldso/dlopen.c
@@ -1,10 +0,0 @@
-#include <dlfcn.h>
-#include "dynlink.h"
-
-static void *stub_dlopen(const char *file, int mode)
-{
- __dl_seterr("Dynamic loading not supported");
- return 0;
-}
-
-weak_alias(stub_dlopen, dlopen);
lib/libc/wasi/libc-top-half/musl/src/ldso/dlsym.c
@@ -1,7 +0,0 @@
-#include <dlfcn.h>
-#include "dynlink.h"
-
-void *dlsym(void *restrict p, const char *restrict s)
-{
- return __dlsym(p, s, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/ldso/tlsdesc.c
@@ -1,9 +0,0 @@
-#include <stddef.h>
-#include <dynlink.h>
-
-ptrdiff_t __tlsdesc_static()
-{
- return 0;
-}
-
-weak_alias(__tlsdesc_static, __tlsdesc_dynamic);
lib/libc/wasi/libc-top-half/musl/src/legacy/cuserid.c
@@ -1,22 +0,0 @@
-#define _GNU_SOURCE
-#include <pwd.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-
-char *cuserid(char *buf)
-{
- static char usridbuf[L_cuserid];
- struct passwd pw, *ppw;
- long pwb[256];
- if (buf) *buf = 0;
- getpwuid_r(geteuid(), &pw, (void *)pwb, sizeof pwb, &ppw);
- if (!ppw)
- return buf;
- size_t len = strnlen(pw.pw_name, L_cuserid);
- if (len == L_cuserid)
- return buf;
- if (!buf) buf = usridbuf;
- memcpy(buf, pw.pw_name, len+1);
- return buf;
-}
lib/libc/wasi/libc-top-half/musl/src/legacy/daemon.c
@@ -1,33 +0,0 @@
-#define _GNU_SOURCE
-#include <fcntl.h>
-#include <unistd.h>
-
-int daemon(int nochdir, int noclose)
-{
- if (!nochdir && chdir("/"))
- return -1;
- if (!noclose) {
- int fd, failed = 0;
- if ((fd = open("/dev/null", O_RDWR)) < 0) return -1;
- if (dup2(fd, 0) < 0 || dup2(fd, 1) < 0 || dup2(fd, 2) < 0)
- failed++;
- if (fd > 2) close(fd);
- if (failed) return -1;
- }
-
- switch(fork()) {
- case 0: break;
- case -1: return -1;
- default: _exit(0);
- }
-
- if (setsid() < 0) return -1;
-
- switch(fork()) {
- case 0: break;
- case -1: return -1;
- default: _exit(0);
- }
-
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/legacy/err.c
@@ -1,67 +0,0 @@
-#include <err.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
-
-extern char *__progname;
-
-void vwarn(const char *fmt, va_list ap)
-{
- fprintf (stderr, "%s: ", __progname);
- if (fmt) {
- vfprintf(stderr, fmt, ap);
- fputs (": ", stderr);
- }
- perror(0);
-}
-
-void vwarnx(const char *fmt, va_list ap)
-{
- fprintf (stderr, "%s: ", __progname);
- if (fmt) vfprintf(stderr, fmt, ap);
- putc('\n', stderr);
-}
-
-_Noreturn void verr(int status, const char *fmt, va_list ap)
-{
- vwarn(fmt, ap);
- exit(status);
-}
-
-_Noreturn void verrx(int status, const char *fmt, va_list ap)
-{
- vwarnx(fmt, ap);
- exit(status);
-}
-
-void warn(const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- vwarn(fmt, ap);
- va_end(ap);
-}
-
-void warnx(const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- vwarnx(fmt, ap);
- va_end(ap);
-}
-
-_Noreturn void err(int status, const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- verr(status, fmt, ap);
- va_end(ap);
-}
-
-_Noreturn void errx(int status, const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- verrx(status, fmt, ap);
- va_end(ap);
-}
lib/libc/wasi/libc-top-half/musl/src/legacy/euidaccess.c
@@ -1,10 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include <fcntl.h>
-
-int euidaccess(const char *filename, int amode)
-{
- return faccessat(AT_FDCWD, filename, amode, AT_EACCESS);
-}
-
-weak_alias(euidaccess, eaccess);
lib/libc/wasi/libc-top-half/musl/src/legacy/ftw.c
@@ -1,11 +0,0 @@
-#include <ftw.h>
-
-int ftw(const char *path, int (*fn)(const char *, const struct stat *, int), int fd_limit)
-{
- /* The following cast assumes that calling a function with one
- * argument more than it needs behaves as expected. This is
- * actually undefined, but works on all real-world machines. */
- return nftw(path, (int (*)())fn, fd_limit, FTW_PHYS);
-}
-
-weak_alias(ftw, ftw64);
lib/libc/wasi/libc-top-half/musl/src/legacy/futimes.c
@@ -1,14 +0,0 @@
-#define _GNU_SOURCE
-#include <sys/stat.h>
-#include <sys/time.h>
-
-int futimes(int fd, const struct timeval tv[2])
-{
- struct timespec times[2];
- if (!tv) return futimens(fd, 0);
- times[0].tv_sec = tv[0].tv_sec;
- times[0].tv_nsec = tv[0].tv_usec * 1000;
- times[1].tv_sec = tv[1].tv_sec;
- times[1].tv_nsec = tv[1].tv_usec * 1000;
- return futimens(fd, times);
-}
lib/libc/wasi/libc-top-half/musl/src/legacy/getdtablesize.c
@@ -1,11 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include <limits.h>
-#include <sys/resource.h>
-
-int getdtablesize(void)
-{
- struct rlimit rl;
- getrlimit(RLIMIT_NOFILE, &rl);
- return rl.rlim_cur < INT_MAX ? rl.rlim_cur : INT_MAX;
-}
lib/libc/wasi/libc-top-half/musl/src/legacy/getloadavg.c
@@ -1,14 +0,0 @@
-#define _GNU_SOURCE
-#include <stdlib.h>
-#include <sys/sysinfo.h>
-
-int getloadavg(double *a, int n)
-{
- struct sysinfo si;
- if (n <= 0) return n ? -1 : 0;
- sysinfo(&si);
- if (n > 3) n = 3;
- for (int i=0; i<n; i++)
- a[i] = 1.0/(1<<SI_LOAD_SHIFT) * si.loads[i];
- return n;
-}
lib/libc/wasi/libc-top-half/musl/src/legacy/getpass.c
@@ -1,40 +0,0 @@
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <termios.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-
-char *getpass(const char *prompt)
-{
- int fd;
- struct termios s, t;
- ssize_t l;
- static char password[128];
-
- if ((fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_CLOEXEC)) < 0) return 0;
-
- tcgetattr(fd, &t);
- s = t;
- t.c_lflag &= ~(ECHO|ISIG);
- t.c_lflag |= ICANON;
- t.c_iflag &= ~(INLCR|IGNCR);
- t.c_iflag |= ICRNL;
- tcsetattr(fd, TCSAFLUSH, &t);
- tcdrain(fd);
-
- dprintf(fd, "%s", prompt);
-
- l = read(fd, password, sizeof password);
- if (l >= 0) {
- if (l > 0 && password[l-1] == '\n' || l==sizeof password) l--;
- password[l] = 0;
- }
-
- tcsetattr(fd, TCSAFLUSH, &s);
-
- dprintf(fd, "\n");
- close(fd);
-
- return l<0 ? 0 : password;
-}
lib/libc/wasi/libc-top-half/musl/src/legacy/getusershell.c
@@ -1,32 +0,0 @@
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <unistd.h>
-
-static const char defshells[] = "/bin/sh\n/bin/csh\n";
-
-static char *line;
-static size_t linesize;
-static FILE *f;
-
-void endusershell(void)
-{
- if (f) fclose(f);
- f = 0;
-}
-
-void setusershell(void)
-{
- if (!f) f = fopen("/etc/shells", "rbe");
- if (!f) f = fmemopen((void *)defshells, sizeof defshells - 1, "rb");
-}
-
-char *getusershell(void)
-{
- ssize_t l;
- if (!f) setusershell();
- if (!f) return 0;
- l = getline(&line, &linesize, f);
- if (l <= 0) return 0;
- if (line[l-1]=='\n') line[l-1]=0;
- return line;
-}
lib/libc/wasi/libc-top-half/musl/src/legacy/isastream.c
@@ -1,7 +0,0 @@
-#include <stropts.h>
-#include <fcntl.h>
-
-int isastream(int fd)
-{
- return fcntl(fd, F_GETFD) < 0 ? -1 : 0;
-}
lib/libc/wasi/libc-top-half/musl/src/legacy/lutimes.c
@@ -1,16 +0,0 @@
-#define _GNU_SOURCE
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <fcntl.h>
-
-int lutimes(const char *filename, const struct timeval tv[2])
-{
- struct timespec times[2];
- if (tv) {
- times[0].tv_sec = tv[0].tv_sec;
- times[0].tv_nsec = tv[0].tv_usec * 1000;
- times[1].tv_sec = tv[1].tv_sec;
- times[1].tv_nsec = tv[1].tv_usec * 1000;
- }
- return utimensat(AT_FDCWD, filename, tv ? times : 0, AT_SYMLINK_NOFOLLOW);
-}
lib/libc/wasi/libc-top-half/musl/src/legacy/ulimit.c
@@ -1,19 +0,0 @@
-#include <sys/resource.h>
-#include <ulimit.h>
-#include <stdarg.h>
-
-long ulimit(int cmd, ...)
-{
- struct rlimit rl;
- getrlimit(RLIMIT_FSIZE, &rl);
- if (cmd == UL_SETFSIZE) {
- long val;
- va_list ap;
- va_start(ap, cmd);
- val = va_arg(ap, long);
- va_end(ap);
- rl.rlim_cur = 512ULL * val;
- if (setrlimit(RLIMIT_FSIZE, &rl)) return -1;
- }
- return rl.rlim_cur / 512;
-}
lib/libc/wasi/libc-top-half/musl/src/legacy/utmpx.c
@@ -1,52 +0,0 @@
-#define _GNU_SOURCE
-#include <utmpx.h>
-#include <stddef.h>
-#include <errno.h>
-
-void endutxent(void)
-{
-}
-
-void setutxent(void)
-{
-}
-
-struct utmpx *getutxent(void)
-{
- return NULL;
-}
-
-struct utmpx *getutxid(const struct utmpx *ut)
-{
- return NULL;
-}
-
-struct utmpx *getutxline(const struct utmpx *ut)
-{
- return NULL;
-}
-
-struct utmpx *pututxline(const struct utmpx *ut)
-{
- return NULL;
-}
-
-void updwtmpx(const char *f, const struct utmpx *u)
-{
-}
-
-static int __utmpxname(const char *f)
-{
- errno = ENOTSUP;
- return -1;
-}
-
-weak_alias(endutxent, endutent);
-weak_alias(setutxent, setutent);
-weak_alias(getutxent, getutent);
-weak_alias(getutxid, getutid);
-weak_alias(getutxline, getutline);
-weak_alias(pututxline, pututline);
-weak_alias(updwtmpx, updwtmp);
-weak_alias(__utmpxname, utmpname);
-weak_alias(__utmpxname, utmpxname);
lib/libc/wasi/libc-top-half/musl/src/legacy/valloc.c
@@ -1,8 +0,0 @@
-#define _BSD_SOURCE
-#include <stdlib.h>
-#include "libc.h"
-
-void *valloc(size_t size)
-{
- return memalign(PAGE_SIZE, size);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/x32/sysinfo.c
@@ -1,49 +0,0 @@
-#include <sys/sysinfo.h>
-#include "syscall.h"
-
-#define klong long long
-#define kulong unsigned long long
-
-struct kernel_sysinfo {
- klong uptime;
- kulong loads[3];
- kulong totalram;
- kulong freeram;
- kulong sharedram;
- kulong bufferram;
- kulong totalswap;
- kulong freeswap;
- short procs;
- short pad;
- kulong totalhigh;
- kulong freehigh;
- unsigned mem_unit;
-};
-
-int __lsysinfo(struct sysinfo *info)
-{
- struct kernel_sysinfo tmp;
- int ret = syscall(SYS_sysinfo, &tmp);
- if(ret == -1) return ret;
- info->uptime = tmp.uptime;
- info->loads[0] = tmp.loads[0];
- info->loads[1] = tmp.loads[1];
- info->loads[2] = tmp.loads[2];
- kulong shifts;
- kulong max = tmp.totalram | tmp.totalswap;
- __asm__("bsr %1,%0" : "=r"(shifts) : "r"(max));
- shifts = shifts >= 32 ? shifts - 31 : 0;
- info->totalram = tmp.totalram >> shifts;
- info->freeram = tmp.freeram >> shifts;
- info->sharedram = tmp.sharedram >> shifts;
- info->bufferram = tmp.bufferram >> shifts;
- info->totalswap = tmp.totalswap >> shifts;
- info->freeswap = tmp.freeswap >> shifts;
- info->procs = tmp.procs ;
- info->totalhigh = tmp.totalhigh >> shifts;
- info->freehigh = tmp.freehigh >> shifts;
- info->mem_unit = (tmp.mem_unit ? tmp.mem_unit : 1) << shifts;
- return ret;
-}
-
-weak_alias(__lsysinfo, sysinfo);
lib/libc/wasi/libc-top-half/musl/src/linux/adjtime.c
@@ -1,27 +0,0 @@
-#define _GNU_SOURCE
-#include <sys/time.h>
-#include <sys/timex.h>
-#include <errno.h>
-#include "syscall.h"
-
-int adjtime(const struct timeval *in, struct timeval *out)
-{
- struct timex tx = { 0 };
- if (in) {
- if (in->tv_sec > 1000 || in->tv_usec > 1000000000) {
- errno = EINVAL;
- return -1;
- }
- tx.offset = in->tv_sec*1000000 + in->tv_usec;
- tx.modes = ADJ_OFFSET_SINGLESHOT;
- }
- if (adjtimex(&tx) < 0) return -1;
- if (out) {
- out->tv_sec = tx.offset / 1000000;
- if ((out->tv_usec = tx.offset % 1000000) < 0) {
- out->tv_sec--;
- out->tv_usec += 1000000;
- }
- }
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/linux/adjtimex.c
@@ -1,7 +0,0 @@
-#include <sys/timex.h>
-#include <time.h>
-
-int adjtimex(struct timex *tx)
-{
- return clock_adjtime(CLOCK_REALTIME, tx);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/arch_prctl.c
@@ -1,7 +0,0 @@
-#include "syscall.h"
-#ifdef SYS_arch_prctl
-int arch_prctl(int code, unsigned long addr)
-{
- return syscall(SYS_arch_prctl, code, addr);
-}
-#endif
lib/libc/wasi/libc-top-half/musl/src/linux/brk.c
@@ -1,9 +0,0 @@
-#define _BSD_SOURCE
-#include <unistd.h>
-#include <errno.h>
-#include "syscall.h"
-
-int brk(void *end)
-{
- return __syscall_ret(-ENOMEM);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/cache.c
@@ -1,50 +0,0 @@
-#include <errno.h>
-#include "syscall.h"
-#include "atomic.h"
-
-#ifdef SYS_cacheflush
-int _flush_cache(void *addr, int len, int op)
-{
- return syscall(SYS_cacheflush, addr, len, op);
-}
-weak_alias(_flush_cache, cacheflush);
-#endif
-
-#ifdef SYS_cachectl
-int __cachectl(void *addr, int len, int op)
-{
- return syscall(SYS_cachectl, addr, len, op);
-}
-weak_alias(__cachectl, cachectl);
-#endif
-
-#ifdef SYS_riscv_flush_icache
-
-#define VDSO_FLUSH_ICACHE_SYM "__vdso_flush_icache"
-#define VDSO_FLUSH_ICACHE_VER "LINUX_4.5"
-
-static void *volatile vdso_func;
-
-static int flush_icache_init(void *start, void *end, unsigned long int flags)
-{
- void *p = __vdsosym(VDSO_FLUSH_ICACHE_VER, VDSO_FLUSH_ICACHE_SYM);
- int (*f)(void *, void *, unsigned long int) =
- (int (*)(void *, void *, unsigned long int))p;
- a_cas_p(&vdso_func, (void *)flush_icache_init, p);
- return f ? f(start, end, flags) : -ENOSYS;
-}
-
-static void *volatile vdso_func = (void *)flush_icache_init;
-
-int __riscv_flush_icache(void *start, void *end, unsigned long int flags)
-{
- int (*f)(void *, void *, unsigned long int) =
- (int (*)(void *, void *, unsigned long int))vdso_func;
- if (f) {
- int r = f(start, end, flags);
- if (!r) return r;
- if (r != -ENOSYS) return __syscall_ret(r);
- }
-}
-weak_alias(__riscv_flush_icache, riscv_flush_icache);
-#endif
lib/libc/wasi/libc-top-half/musl/src/linux/cap.c
@@ -1,11 +0,0 @@
-#include "syscall.h"
-
-int capset(void *a, void *b)
-{
- return syscall(SYS_capset, a, b);
-}
-
-int capget(void *a, void *b)
-{
- return syscall(SYS_capget, a, b);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/chroot.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include "syscall.h"
-
-int chroot(const char *path)
-{
- return syscall(SYS_chroot, path);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/clock_adjtime.c
@@ -1,151 +0,0 @@
-#include <sys/timex.h>
-#include <time.h>
-#include <errno.h>
-#include "syscall.h"
-
-#define IS32BIT(x) !((x)+0x80000000ULL>>32)
-
-struct ktimex64 {
- unsigned modes;
- int :32;
- long long offset, freq, maxerror, esterror;
- int status;
- int :32;
- long long constant, precision, tolerance;
- long long time_sec, time_usec;
- long long tick, ppsfreq, jitter;
- int shift;
- int :32;
- long long stabil, jitcnt, calcnt, errcnt, stbcnt;
- int tai;
- int __padding[11];
-};
-
-struct ktimex {
- unsigned modes;
- long offset, freq, maxerror, esterror;
- int status;
- long constant, precision, tolerance;
- long time_sec, time_usec;
- long tick, ppsfreq, jitter;
- int shift;
- long stabil, jitcnt, calcnt, errcnt, stbcnt;
- int tai;
- int __padding[11];
-};
-
-int clock_adjtime (clockid_t clock_id, struct timex *utx)
-{
- int r = -ENOSYS;
-#ifdef SYS_clock_adjtime64
- struct ktimex64 ktx = {
- .modes = utx->modes,
- .offset = utx->offset,
- .freq = utx->freq,
- .maxerror = utx->maxerror,
- .esterror = utx->esterror,
- .status = utx->status,
- .constant = utx->constant,
- .precision = utx->precision,
- .tolerance = utx->tolerance,
- .time_sec = utx->time.tv_sec,
- .time_usec = utx->time.tv_usec,
- .tick = utx->tick,
- .ppsfreq = utx->ppsfreq,
- .jitter = utx->jitter,
- .shift = utx->shift,
- .stabil = utx->stabil,
- .jitcnt = utx->jitcnt,
- .calcnt = utx->calcnt,
- .errcnt = utx->errcnt,
- .stbcnt = utx->stbcnt,
- .tai = utx->tai,
- };
- r = __syscall(SYS_clock_adjtime64, clock_id, &ktx);
- if (r>=0) {
- utx->modes = ktx.modes;
- utx->offset = ktx.offset;
- utx->freq = ktx.freq;
- utx->maxerror = ktx.maxerror;
- utx->esterror = ktx.esterror;
- utx->status = ktx.status;
- utx->constant = ktx.constant;
- utx->precision = ktx.precision;
- utx->tolerance = ktx.tolerance;
- utx->time.tv_sec = ktx.time_sec;
- utx->time.tv_usec = ktx.time_usec;
- utx->tick = ktx.tick;
- utx->ppsfreq = ktx.ppsfreq;
- utx->jitter = ktx.jitter;
- utx->shift = ktx.shift;
- utx->stabil = ktx.stabil;
- utx->jitcnt = ktx.jitcnt;
- utx->calcnt = ktx.calcnt;
- utx->errcnt = ktx.errcnt;
- utx->stbcnt = ktx.stbcnt;
- utx->tai = ktx.tai;
- }
- if (SYS_clock_adjtime == SYS_clock_adjtime64 || r!=-ENOSYS)
- return __syscall_ret(r);
- if ((utx->modes & ADJ_SETOFFSET) && !IS32BIT(utx->time.tv_sec))
- return __syscall_ret(-ENOTSUP);
-#endif
- if (sizeof(time_t) > sizeof(long)) {
- struct ktimex ktx = {
- .modes = utx->modes,
- .offset = utx->offset,
- .freq = utx->freq,
- .maxerror = utx->maxerror,
- .esterror = utx->esterror,
- .status = utx->status,
- .constant = utx->constant,
- .precision = utx->precision,
- .tolerance = utx->tolerance,
- .time_sec = utx->time.tv_sec,
- .time_usec = utx->time.tv_usec,
- .tick = utx->tick,
- .ppsfreq = utx->ppsfreq,
- .jitter = utx->jitter,
- .shift = utx->shift,
- .stabil = utx->stabil,
- .jitcnt = utx->jitcnt,
- .calcnt = utx->calcnt,
- .errcnt = utx->errcnt,
- .stbcnt = utx->stbcnt,
- .tai = utx->tai,
- };
-#ifdef SYS_adjtimex
- if (clock_id==CLOCK_REALTIME) r = __syscall(SYS_adjtimex, &ktx);
- else
-#endif
- r = __syscall(SYS_clock_adjtime, clock_id, &ktx);
- if (r>=0) {
- utx->modes = ktx.modes;
- utx->offset = ktx.offset;
- utx->freq = ktx.freq;
- utx->maxerror = ktx.maxerror;
- utx->esterror = ktx.esterror;
- utx->status = ktx.status;
- utx->constant = ktx.constant;
- utx->precision = ktx.precision;
- utx->tolerance = ktx.tolerance;
- utx->time.tv_sec = ktx.time_sec;
- utx->time.tv_usec = ktx.time_usec;
- utx->tick = ktx.tick;
- utx->ppsfreq = ktx.ppsfreq;
- utx->jitter = ktx.jitter;
- utx->shift = ktx.shift;
- utx->stabil = ktx.stabil;
- utx->jitcnt = ktx.jitcnt;
- utx->calcnt = ktx.calcnt;
- utx->errcnt = ktx.errcnt;
- utx->stbcnt = ktx.stbcnt;
- utx->tai = ktx.tai;
- }
- return __syscall_ret(r);
- }
-#ifdef SYS_adjtimex
- if (clock_id==CLOCK_REALTIME) return syscall(SYS_adjtimex, utx);
-#endif
- return syscall(SYS_clock_adjtime, clock_id, utx);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/clone.c
@@ -1,21 +0,0 @@
-#define _GNU_SOURCE
-#include <stdarg.h>
-#include <unistd.h>
-#include <sched.h>
-#include "pthread_impl.h"
-#include "syscall.h"
-
-int clone(int (*func)(void *), void *stack, int flags, void *arg, ...)
-{
- va_list ap;
- pid_t *ptid, *ctid;
- void *tls;
-
- va_start(ap, arg);
- ptid = va_arg(ap, pid_t *);
- tls = va_arg(ap, void *);
- ctid = va_arg(ap, pid_t *);
- va_end(ap);
-
- return __syscall_ret(__clone(func, stack, flags, arg, ptid, tls, ctid));
-}
lib/libc/wasi/libc-top-half/musl/src/linux/copy_file_range.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include "syscall.h"
-
-ssize_t copy_file_range(int fd_in, off_t *off_in, int fd_out, off_t *off_out, size_t len, unsigned flags)
-{
- return syscall(SYS_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/epoll.c
@@ -1,37 +0,0 @@
-#include <sys/epoll.h>
-#include <signal.h>
-#include <errno.h>
-#include "syscall.h"
-
-int epoll_create(int size)
-{
- return epoll_create1(0);
-}
-
-int epoll_create1(int flags)
-{
- int r = __syscall(SYS_epoll_create1, flags);
-#ifdef SYS_epoll_create
- if (r==-ENOSYS && !flags) r = __syscall(SYS_epoll_create, 1);
-#endif
- return __syscall_ret(r);
-}
-
-int epoll_ctl(int fd, int op, int fd2, struct epoll_event *ev)
-{
- return syscall(SYS_epoll_ctl, fd, op, fd2, ev);
-}
-
-int epoll_pwait(int fd, struct epoll_event *ev, int cnt, int to, const sigset_t *sigs)
-{
- int r = __syscall_cp(SYS_epoll_pwait, fd, ev, cnt, to, sigs, _NSIG/8);
-#ifdef SYS_epoll_wait
- if (r==-ENOSYS && !sigs) r = __syscall_cp(SYS_epoll_wait, fd, ev, cnt, to);
-#endif
- return __syscall_ret(r);
-}
-
-int epoll_wait(int fd, struct epoll_event *ev, int cnt, int to)
-{
- return epoll_pwait(fd, ev, cnt, to, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/eventfd.c
@@ -1,23 +0,0 @@
-#include <sys/eventfd.h>
-#include <unistd.h>
-#include <errno.h>
-#include "syscall.h"
-
-int eventfd(unsigned int count, int flags)
-{
- int r = __syscall(SYS_eventfd2, count, flags);
-#ifdef SYS_eventfd
- if (r==-ENOSYS && !flags) r = __syscall(SYS_eventfd, count);
-#endif
- return __syscall_ret(r);
-}
-
-int eventfd_read(int fd, eventfd_t *value)
-{
- return (sizeof(*value) == read(fd, value, sizeof(*value))) ? 0 : -1;
-}
-
-int eventfd_write(int fd, eventfd_t value)
-{
- return (sizeof(value) == write(fd, &value, sizeof(value))) ? 0 : -1;
-}
lib/libc/wasi/libc-top-half/musl/src/linux/fallocate.c
@@ -1,12 +0,0 @@
-#define _GNU_SOURCE
-#include <fcntl.h>
-#include "syscall.h"
-
-int fallocate(int fd, int mode, off_t base, off_t len)
-{
- return syscall(SYS_fallocate, fd, mode, __SYSCALL_LL_E(base),
- __SYSCALL_LL_E(len));
-}
-
-#undef fallocate64
-weak_alias(fallocate, fallocate64);
lib/libc/wasi/libc-top-half/musl/src/linux/fanotify.c
@@ -1,14 +0,0 @@
-#include "syscall.h"
-#include <sys/fanotify.h>
-
-int fanotify_init(unsigned flags, unsigned event_f_flags)
-{
- return syscall(SYS_fanotify_init, flags, event_f_flags);
-}
-
-int fanotify_mark(int fanotify_fd, unsigned flags, unsigned long long mask,
- int dfd, const char *pathname)
-{
- return syscall(SYS_fanotify_mark, fanotify_fd, flags, __SYSCALL_LL_E(mask), dfd, pathname);
-}
-
lib/libc/wasi/libc-top-half/musl/src/linux/flock.c
@@ -1,7 +0,0 @@
-#include <sys/file.h>
-#include "syscall.h"
-
-int flock(int fd, int op)
-{
- return syscall(SYS_flock, fd, op);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/getdents.c
@@ -1,12 +0,0 @@
-#define _BSD_SOURCE
-#include <dirent.h>
-#include <limits.h>
-#include "syscall.h"
-
-int getdents(int fd, struct dirent *buf, size_t len)
-{
- if (len>INT_MAX) len = INT_MAX;
- return syscall(SYS_getdents, fd, buf, len);
-}
-
-weak_alias(getdents, getdents64);
lib/libc/wasi/libc-top-half/musl/src/linux/getrandom.c
@@ -1,7 +0,0 @@
-#include <sys/random.h>
-#include "syscall.h"
-
-ssize_t getrandom(void *buf, size_t buflen, unsigned flags)
-{
- return syscall_cp(SYS_getrandom, buf, buflen, flags);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/gettid.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include "pthread_impl.h"
-
-pid_t gettid(void)
-{
- return __pthread_self()->tid;
-}
lib/libc/wasi/libc-top-half/musl/src/linux/inotify.c
@@ -1,26 +0,0 @@
-#include <sys/inotify.h>
-#include <errno.h>
-#include "syscall.h"
-
-int inotify_init()
-{
- return inotify_init1(0);
-}
-int inotify_init1(int flags)
-{
- int r = __syscall(SYS_inotify_init1, flags);
-#ifdef SYS_inotify_init
- if (r==-ENOSYS && !flags) r = __syscall(SYS_inotify_init);
-#endif
- return __syscall_ret(r);
-}
-
-int inotify_add_watch(int fd, const char *pathname, uint32_t mask)
-{
- return syscall(SYS_inotify_add_watch, fd, pathname, mask);
-}
-
-int inotify_rm_watch(int fd, int wd)
-{
- return syscall(SYS_inotify_rm_watch, fd, wd);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/ioperm.c
@@ -1,10 +0,0 @@
-#include "syscall.h"
-
-#ifdef SYS_ioperm
-#include <sys/io.h>
-
-int ioperm(unsigned long from, unsigned long num, int turn_on)
-{
- return syscall(SYS_ioperm, from, num, turn_on);
-}
-#endif
lib/libc/wasi/libc-top-half/musl/src/linux/iopl.c
@@ -1,10 +0,0 @@
-#include "syscall.h"
-
-#ifdef SYS_iopl
-#include <sys/io.h>
-
-int iopl(int level)
-{
- return syscall(SYS_iopl, level);
-}
-#endif
lib/libc/wasi/libc-top-half/musl/src/linux/klogctl.c
@@ -1,7 +0,0 @@
-#include <sys/klog.h>
-#include "syscall.h"
-
-int klogctl (int type, char *buf, int len)
-{
- return syscall(SYS_syslog, type, buf, len);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/membarrier.c
@@ -1,72 +0,0 @@
-#include <sys/membarrier.h>
-#include <semaphore.h>
-#include <signal.h>
-#include <string.h>
-#include "pthread_impl.h"
-#include "syscall.h"
-
-static void dummy_0(void)
-{
-}
-
-weak_alias(dummy_0, __tl_lock);
-weak_alias(dummy_0, __tl_unlock);
-
-static sem_t barrier_sem;
-
-static void bcast_barrier(int s)
-{
- sem_post(&barrier_sem);
-}
-
-int __membarrier(int cmd, int flags)
-{
- int r = __syscall(SYS_membarrier, cmd, flags);
- /* Emulate the private expedited command, which is needed by the
- * dynamic linker for installation of dynamic TLS, for older
- * kernels that lack the syscall. Unlike the syscall, this only
- * synchronizes with threads of the process, not other processes
- * sharing the VM, but such sharing is not a supported usage
- * anyway. */
- if (r && cmd == MEMBARRIER_CMD_PRIVATE_EXPEDITED && !flags) {
- pthread_t self=__pthread_self(), td;
- sigset_t set;
- __block_app_sigs(&set);
- __tl_lock();
- sem_init(&barrier_sem, 0, 0);
- struct sigaction sa = {
- .sa_flags = SA_RESTART,
- .sa_handler = bcast_barrier
- };
- memset(&sa.sa_mask, -1, sizeof sa.sa_mask);
- if (!__libc_sigaction(SIGSYNCCALL, &sa, 0)) {
- for (td=self->next; td!=self; td=td->next)
- __syscall(SYS_tkill, td->tid, SIGSYNCCALL);
- for (td=self->next; td!=self; td=td->next)
- sem_wait(&barrier_sem);
- r = 0;
- sa.sa_handler = SIG_IGN;
- __libc_sigaction(SIGSYNCCALL, &sa, 0);
- }
- sem_destroy(&barrier_sem);
- __tl_unlock();
- __restore_sigs(&set);
- }
- return __syscall_ret(r);
-}
-
-void __membarrier_init(void)
-{
- /* If membarrier is linked, attempt to pre-register to be able to use
- * the private expedited command before the process becomes multi-
- * threaded, since registering later has bad, potentially unbounded
- * latency. This syscall should be essentially free, and it's arguably
- * a mistake in the API design that registration was even required.
- * For other commands, registration may impose some cost, so it's left
- * to the application to do so if desired. Unfortunately this means
- * library code initialized after the process becomes multi-threaded
- * cannot use these features without accepting registration latency. */
- __syscall(SYS_membarrier, MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED, 0);
-}
-
-weak_alias(__membarrier, membarrier);
lib/libc/wasi/libc-top-half/musl/src/linux/memfd_create.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE 1
-#include <sys/mman.h>
-#include "syscall.h"
-
-int memfd_create(const char *name, unsigned flags)
-{
- return syscall(SYS_memfd_create, name, flags);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/mlock2.c
@@ -1,10 +0,0 @@
-#define _GNU_SOURCE 1
-#include <sys/mman.h>
-#include "syscall.h"
-
-int mlock2(const void *addr, size_t len, unsigned flags)
-{
- if (flags == 0)
- return mlock(addr, len);
- return syscall(SYS_mlock2, addr, len, flags);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/module.c
@@ -1,11 +0,0 @@
-#include "syscall.h"
-
-int init_module(void *a, unsigned long b, const char *c)
-{
- return syscall(SYS_init_module, a, b, c);
-}
-
-int delete_module(const char *a, unsigned b)
-{
- return syscall(SYS_delete_module, a, b);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/mount.c
@@ -1,17 +0,0 @@
-#include <sys/mount.h>
-#include "syscall.h"
-
-int mount(const char *special, const char *dir, const char *fstype, unsigned long flags, const void *data)
-{
- return syscall(SYS_mount, special, dir, fstype, flags, data);
-}
-
-int umount(const char *special)
-{
- return syscall(SYS_umount2, special, 0);
-}
-
-int umount2(const char *special, int flags)
-{
- return syscall(SYS_umount2, special, flags);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/name_to_handle_at.c
@@ -1,10 +0,0 @@
-#define _GNU_SOURCE
-#include <fcntl.h>
-#include "syscall.h"
-
-int name_to_handle_at(int dirfd, const char *pathname,
- struct file_handle *handle, int *mount_id, int flags)
-{
- return syscall(SYS_name_to_handle_at, dirfd,
- pathname, handle, mount_id, flags);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/open_by_handle_at.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <fcntl.h>
-#include "syscall.h"
-
-int open_by_handle_at(int mount_fd, struct file_handle *handle, int flags)
-{
- return syscall(SYS_open_by_handle_at, mount_fd, handle, flags);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/personality.c
@@ -1,8 +0,0 @@
-#include <sys/personality.h>
-#include "syscall.h"
-#ifdef SYS_personality
-int personality(unsigned long persona)
-{
- return syscall(SYS_personality, persona);
-}
-#endif
lib/libc/wasi/libc-top-half/musl/src/linux/pivot_root.c
@@ -1,6 +0,0 @@
-#include "syscall.h"
-
-int pivot_root(const char *new, const char *old)
-{
- return syscall(SYS_pivot_root, new, old);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/ppoll.c
@@ -1,26 +0,0 @@
-#define _GNU_SOURCE
-#include <poll.h>
-#include <signal.h>
-#include <errno.h>
-#include "syscall.h"
-
-#define IS32BIT(x) !((x)+0x80000000ULL>>32)
-#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
-
-int ppoll(struct pollfd *fds, nfds_t n, const struct timespec *to, const sigset_t *mask)
-{
- time_t s = to ? to->tv_sec : 0;
- long ns = to ? to->tv_nsec : 0;
-#ifdef SYS_ppoll_time64
- int r = -ENOSYS;
- if (SYS_ppoll == SYS_ppoll_time64 || !IS32BIT(s))
- r = __syscall_cp(SYS_ppoll_time64, fds, n,
- to ? ((long long[]){s, ns}) : 0,
- mask, _NSIG/8);
- if (SYS_ppoll == SYS_ppoll_time64 || r != -ENOSYS)
- return __syscall_ret(r);
- s = CLAMP(s);
-#endif
- return syscall_cp(SYS_ppoll, fds, n,
- to ? ((long[]){s, ns}) : 0, mask, _NSIG/8);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/prctl.c
@@ -1,14 +0,0 @@
-#include <sys/prctl.h>
-#include <stdarg.h>
-#include "syscall.h"
-
-int prctl(int op, ...)
-{
- unsigned long x[4];
- int i;
- va_list ap;
- va_start(ap, op);
- for (i=0; i<4; i++) x[i] = va_arg(ap, unsigned long);
- va_end(ap);
- return syscall(SYS_prctl, op, x[0], x[1], x[2], x[3]);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/prlimit.c
@@ -1,26 +0,0 @@
-#define _GNU_SOURCE
-#include <sys/resource.h>
-#include "syscall.h"
-
-#define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0)
-
-int prlimit(pid_t pid, int resource, const struct rlimit *new_limit, struct rlimit *old_limit)
-{
- struct rlimit tmp;
- int r;
- if (new_limit && SYSCALL_RLIM_INFINITY != RLIM_INFINITY) {
- tmp = *new_limit;
- FIX(tmp.rlim_cur);
- FIX(tmp.rlim_max);
- new_limit = &tmp;
- }
- r = syscall(SYS_prlimit64, pid, resource, new_limit, old_limit);
- if (!r && old_limit && SYSCALL_RLIM_INFINITY != RLIM_INFINITY) {
- FIX(old_limit->rlim_cur);
- FIX(old_limit->rlim_max);
- }
- return r;
-}
-
-#undef prlimit64
-weak_alias(prlimit, prlimit64);
lib/libc/wasi/libc-top-half/musl/src/linux/process_vm.c
@@ -1,13 +0,0 @@
-#define _GNU_SOURCE
-#include <sys/uio.h>
-#include "syscall.h"
-
-ssize_t process_vm_writev(pid_t pid, const struct iovec *lvec, unsigned long liovcnt, const struct iovec *rvec, unsigned long riovcnt, unsigned long flags)
-{
- return syscall(SYS_process_vm_writev, pid, lvec, liovcnt, rvec, riovcnt, flags);
-}
-
-ssize_t process_vm_readv(pid_t pid, const struct iovec *lvec, unsigned long liovcnt, const struct iovec *rvec, unsigned long riovcnt, unsigned long flags)
-{
- return syscall(SYS_process_vm_readv, pid, lvec, liovcnt, rvec, riovcnt, flags);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/ptrace.c
@@ -1,29 +0,0 @@
-#include <sys/ptrace.h>
-#include <stdarg.h>
-#include <unistd.h>
-#include "syscall.h"
-
-long ptrace(int req, ...)
-{
- va_list ap;
- pid_t pid;
- void *addr, *data, *addr2 = 0;
- long ret, result;
-
- va_start(ap, req);
- pid = va_arg(ap, pid_t);
- addr = va_arg(ap, void *);
- data = va_arg(ap, void *);
- /* PTRACE_{READ,WRITE}{DATA,TEXT} (16...19) are specific to SPARC. */
-#ifdef PTRACE_READDATA
- if ((unsigned)req - PTRACE_READDATA < 4)
- addr2 = va_arg(ap, void *);
-#endif
- va_end(ap);
-
- if (req-1U < 3) data = &result;
- ret = syscall(SYS_ptrace, req, pid, addr, data, addr2);
-
- if (ret < 0 || req-1U >= 3) return ret;
- return result;
-}
lib/libc/wasi/libc-top-half/musl/src/linux/quotactl.c
@@ -1,7 +0,0 @@
-#include <sys/quota.h>
-#include "syscall.h"
-
-int quotactl(int cmd, const char *special, int id, char *addr)
-{
- return syscall(SYS_quotactl, cmd, special, id, addr);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/readahead.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <fcntl.h>
-#include "syscall.h"
-
-ssize_t readahead(int fd, off_t pos, size_t len)
-{
- return syscall(SYS_readahead, fd, __SYSCALL_LL_O(pos), len);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/reboot.c
@@ -1,7 +0,0 @@
-#include <sys/reboot.h>
-#include "syscall.h"
-
-int reboot(int type)
-{
- return syscall(SYS_reboot, 0xfee1dead, 672274793, type);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/remap_file_pages.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <sys/mman.h>
-#include "syscall.h"
-
-int remap_file_pages(void *addr, size_t size, int prot, size_t pgoff, int flags)
-{
- return syscall(SYS_remap_file_pages, addr, size, prot, pgoff, flags);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/sbrk.c
@@ -1,11 +0,0 @@
-#define _BSD_SOURCE
-#include <unistd.h>
-#include <stdint.h>
-#include <errno.h>
-#include "syscall.h"
-
-void *sbrk(intptr_t inc)
-{
- if (inc) return (void *)__syscall_ret(-ENOMEM);
- return (void *)__syscall(SYS_brk, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/sendfile.c
@@ -1,9 +0,0 @@
-#include <sys/sendfile.h>
-#include "syscall.h"
-
-ssize_t sendfile(int out_fd, int in_fd, off_t *ofs, size_t count)
-{
- return syscall(SYS_sendfile, out_fd, in_fd, ofs, count);
-}
-
-weak_alias(sendfile, sendfile64);
lib/libc/wasi/libc-top-half/musl/src/linux/setfsgid.c
@@ -1,7 +0,0 @@
-#include <sys/fsuid.h>
-#include "syscall.h"
-
-int setfsgid(gid_t gid)
-{
- return syscall(SYS_setfsgid, gid);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/setfsuid.c
@@ -1,7 +0,0 @@
-#include <sys/fsuid.h>
-#include "syscall.h"
-
-int setfsuid(uid_t uid)
-{
- return syscall(SYS_setfsuid, uid);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/setgroups.c
@@ -1,36 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include <signal.h>
-#include "syscall.h"
-#include "libc.h"
-
-struct ctx {
- size_t count;
- const gid_t *list;
- int ret;
-};
-
-static void do_setgroups(void *p)
-{
- struct ctx *c = p;
- if (c->ret<0) return;
- int ret = __syscall(SYS_setgroups, c->count, c->list);
- if (ret && !c->ret) {
- /* If one thread fails to set groups after another has already
- * succeeded, forcibly killing the process is the only safe
- * thing to do. State is inconsistent and dangerous. Use
- * SIGKILL because it is uncatchable. */
- __block_all_sigs(0);
- __syscall(SYS_kill, __syscall(SYS_getpid), SIGKILL);
- }
- c->ret = ret;
-}
-
-int setgroups(size_t count, const gid_t list[])
-{
- /* ret is initially nonzero so that failure of the first thread does not
- * trigger the safety kill above. */
- struct ctx c = { .count = count, .list = list, .ret = 1 };
- __synccall(do_setgroups, &c);
- return __syscall_ret(c.ret);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/sethostname.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include "syscall.h"
-
-int sethostname(const char *name, size_t len)
-{
- return syscall(SYS_sethostname, name, len);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/setns.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <sched.h>
-#include "syscall.h"
-
-int setns(int fd, int nstype)
-{
- return syscall(SYS_setns, fd, nstype);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/settimeofday.c
@@ -1,13 +0,0 @@
-#define _BSD_SOURCE
-#include <sys/time.h>
-#include <time.h>
-#include <errno.h>
-#include "syscall.h"
-
-int settimeofday(const struct timeval *tv, const struct timezone *tz)
-{
- if (!tv) return 0;
- if (tv->tv_usec >= 1000000ULL) return __syscall_ret(-EINVAL);
- return clock_settime(CLOCK_REALTIME, &((struct timespec){
- .tv_sec = tv->tv_sec, .tv_nsec = tv->tv_usec * 1000}));
-}
lib/libc/wasi/libc-top-half/musl/src/linux/signalfd.c
@@ -1,21 +0,0 @@
-#include <sys/signalfd.h>
-#include <signal.h>
-#include <errno.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int signalfd(int fd, const sigset_t *sigs, int flags)
-{
- int ret = __syscall(SYS_signalfd4, fd, sigs, _NSIG/8, flags);
-#ifdef SYS_signalfd
- if (ret != -ENOSYS) return __syscall_ret(ret);
- ret = __syscall(SYS_signalfd, fd, sigs, _NSIG/8);
- if (ret >= 0) {
- if (flags & SFD_CLOEXEC)
- __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC);
- if (flags & SFD_NONBLOCK)
- __syscall(SYS_fcntl, ret, F_SETFL, O_NONBLOCK);
- }
-#endif
- return __syscall_ret(ret);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/splice.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <fcntl.h>
-#include "syscall.h"
-
-ssize_t splice(int fd_in, off_t *off_in, int fd_out, off_t *off_out, size_t len, unsigned flags)
-{
- return syscall(SYS_splice, fd_in, off_in, fd_out, off_out, len, flags);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/stime.c
@@ -1,9 +0,0 @@
-#define _GNU_SOURCE
-#include <time.h>
-#include <sys/time.h>
-
-int stime(const time_t *t)
-{
- struct timeval tv = { .tv_sec = *t, .tv_usec = 0 };
- return settimeofday(&tv, (void *)0);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/swap.c
@@ -1,12 +0,0 @@
-#include <sys/swap.h>
-#include "syscall.h"
-
-int swapon(const char *path, int flags)
-{
- return syscall(SYS_swapon, path, flags);
-}
-
-int swapoff(const char *path)
-{
- return syscall(SYS_swapoff, path);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/sync_file_range.c
@@ -1,17 +0,0 @@
-#define _GNU_SOURCE
-#include <fcntl.h>
-#include <errno.h>
-#include "syscall.h"
-
-int sync_file_range(int fd, off_t pos, off_t len, unsigned flags)
-{
-#if defined(SYS_sync_file_range2)
- return syscall(SYS_sync_file_range2, fd, flags,
- __SYSCALL_LL_E(pos), __SYSCALL_LL_E(len));
-#elif defined(SYS_sync_file_range)
- return syscall(SYS_sync_file_range, fd,
- __SYSCALL_LL_O(pos), __SYSCALL_LL_E(len), flags);
-#else
- return __syscall_ret(-ENOSYS);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/linux/syncfs.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include "syscall.h"
-
-int syncfs(int fd)
-{
- return syscall(SYS_syncfs, fd);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/sysinfo.c
@@ -1,9 +0,0 @@
-#include <sys/sysinfo.h>
-#include "syscall.h"
-
-int __lsysinfo(struct sysinfo *info)
-{
- return syscall(SYS_sysinfo, info);
-}
-
-weak_alias(__lsysinfo, sysinfo);
lib/libc/wasi/libc-top-half/musl/src/linux/tee.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <fcntl.h>
-#include "syscall.h"
-
-ssize_t tee(int src, int dest, size_t len, unsigned flags)
-{
- return syscall(SYS_tee, src, dest, len, flags);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/timerfd.c
@@ -1,59 +0,0 @@
-#include <sys/timerfd.h>
-#include <errno.h>
-#include "syscall.h"
-
-#define IS32BIT(x) !((x)+0x80000000ULL>>32)
-
-int timerfd_create(int clockid, int flags)
-{
- return syscall(SYS_timerfd_create, clockid, flags);
-}
-
-int timerfd_settime(int fd, int flags, const struct itimerspec *new, struct itimerspec *old)
-{
-#ifdef SYS_timerfd_settime64
- time_t is = new->it_interval.tv_sec, vs = new->it_value.tv_sec;
- long ins = new->it_interval.tv_nsec, vns = new->it_value.tv_nsec;
- int r = -ENOSYS;
- if (SYS_timerfd_settime == SYS_timerfd_settime64
- || !IS32BIT(is) || !IS32BIT(vs) || (sizeof(time_t)>4 && old))
- r = __syscall(SYS_timerfd_settime64, fd, flags,
- ((long long[]){is, ins, vs, vns}), old);
- if (SYS_timerfd_settime == SYS_timerfd_settime64 || r!=-ENOSYS)
- return __syscall_ret(r);
- if (!IS32BIT(is) || !IS32BIT(vs))
- return __syscall_ret(-ENOTSUP);
- long old32[4];
- r = __syscall(SYS_timerfd_settime, fd, flags,
- ((long[]){is, ins, vs, vns}), old32);
- if (!r && old) {
- old->it_interval.tv_sec = old32[0];
- old->it_interval.tv_nsec = old32[1];
- old->it_value.tv_sec = old32[2];
- old->it_value.tv_nsec = old32[3];
- }
- return __syscall_ret(r);
-#endif
- return syscall(SYS_timerfd_settime, fd, flags, new, old);
-}
-
-int timerfd_gettime(int fd, struct itimerspec *cur)
-{
-#ifdef SYS_timerfd_gettime64
- int r = -ENOSYS;
- if (sizeof(time_t) > 4)
- r = __syscall(SYS_timerfd_gettime64, fd, cur);
- if (SYS_timerfd_gettime == SYS_timerfd_gettime64 || r!=-ENOSYS)
- return __syscall_ret(r);
- long cur32[4];
- r = __syscall(SYS_timerfd_gettime, fd, cur32);
- if (!r) {
- cur->it_interval.tv_sec = cur32[0];
- cur->it_interval.tv_nsec = cur32[1];
- cur->it_value.tv_sec = cur32[2];
- cur->it_value.tv_nsec = cur32[3];
- }
- return __syscall_ret(r);
-#endif
- return syscall(SYS_timerfd_gettime, fd, cur);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/utimes.c
@@ -1,8 +0,0 @@
-#include <sys/time.h>
-#include "fcntl.h"
-#include "syscall.h"
-
-int utimes(const char *path, const struct timeval times[2])
-{
- return __futimesat(AT_FDCWD, path, times);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/vhangup.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include "syscall.h"
-
-int vhangup(void)
-{
- return syscall(SYS_vhangup);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/vmsplice.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <fcntl.h>
-#include "syscall.h"
-
-ssize_t vmsplice(int fd, const struct iovec *iov, size_t cnt, unsigned flags)
-{
- return syscall(SYS_vmsplice, fd, iov, cnt, flags);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/wait3.c
@@ -1,9 +0,0 @@
-#define _GNU_SOURCE
-#include <sys/wait.h>
-#include <sys/resource.h>
-#include "syscall.h"
-
-pid_t wait3(int *status, int options, struct rusage *usage)
-{
- return wait4(-1, status, options, usage);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/wait4.c
@@ -1,39 +0,0 @@
-#define _GNU_SOURCE
-#include <sys/wait.h>
-#include <sys/resource.h>
-#include <string.h>
-#include <errno.h>
-#include "syscall.h"
-
-pid_t wait4(pid_t pid, int *status, int options, struct rusage *ru)
-{
- int r;
-#ifdef SYS_wait4_time64
- if (ru) {
- long long kru64[18];
- r = __syscall(SYS_wait4_time64, pid, status, options, kru64);
- if (!r) {
- ru->ru_utime = (struct timeval)
- { .tv_sec = kru64[0], .tv_usec = kru64[1] };
- ru->ru_stime = (struct timeval)
- { .tv_sec = kru64[2], .tv_usec = kru64[3] };
- char *slots = (char *)&ru->ru_maxrss;
- for (int i=0; i<14; i++)
- *(long *)(slots + i*sizeof(long)) = kru64[4+i];
- }
- if (SYS_wait4_time64 == SYS_wait4 || r != -ENOSYS)
- return __syscall_ret(r);
- }
-#endif
- char *dest = ru ? (char *)&ru->ru_maxrss - 4*sizeof(long) : 0;
- r = __syscall(SYS_wait4, pid, status, options, dest);
- if (r>0 && ru && sizeof(time_t) > sizeof(long)) {
- long kru[4];
- memcpy(kru, dest, 4*sizeof(long));
- ru->ru_utime = (struct timeval)
- { .tv_sec = kru[0], .tv_usec = kru[1] };
- ru->ru_stime = (struct timeval)
- { .tv_sec = kru[2], .tv_usec = kru[3] };
- }
- return __syscall_ret(r);
-}
lib/libc/wasi/libc-top-half/musl/src/linux/xattr.c
@@ -1,62 +0,0 @@
-#include <sys/xattr.h>
-#include "syscall.h"
-
-ssize_t getxattr(const char *path, const char *name, void *value, size_t size)
-{
- return syscall(SYS_getxattr, path, name, value, size);
-}
-
-ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size)
-{
- return syscall(SYS_lgetxattr, path, name, value, size);
-}
-
-ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size)
-{
- return syscall(SYS_fgetxattr, filedes, name, value, size);
-}
-
-ssize_t listxattr(const char *path, char *list, size_t size)
-{
- return syscall(SYS_listxattr, path, list, size);
-}
-
-ssize_t llistxattr(const char *path, char *list, size_t size)
-{
- return syscall(SYS_llistxattr, path, list, size);
-}
-
-ssize_t flistxattr(int filedes, char *list, size_t size)
-{
- return syscall(SYS_flistxattr, filedes, list, size);
-}
-
-int setxattr(const char *path, const char *name, const void *value, size_t size, int flags)
-{
- return syscall(SYS_setxattr, path, name, value, size, flags);
-}
-
-int lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
-{
- return syscall(SYS_lsetxattr, path, name, value, size, flags);
-}
-
-int fsetxattr(int filedes, const char *name, const void *value, size_t size, int flags)
-{
- return syscall(SYS_fsetxattr, filedes, name, value, size, flags);
-}
-
-int removexattr(const char *path, const char *name)
-{
- return syscall(SYS_removexattr, path, name);
-}
-
-int lremovexattr(const char *path, const char *name)
-{
- return syscall(SYS_lremovexattr, path, name);
-}
-
-int fremovexattr(int fd, const char *name)
-{
- return syscall(SYS_fremovexattr, fd, name);
-}
lib/libc/wasi/libc-top-half/musl/src/locale/bind_textdomain_codeset.c
@@ -1,11 +0,0 @@
-#include <libintl.h>
-#include <string.h>
-#include <strings.h>
-#include <errno.h>
-
-char *bind_textdomain_codeset(const char *domainname, const char *codeset)
-{
- if (codeset && strcasecmp(codeset, "UTF-8"))
- errno = EINVAL;
- return NULL;
-}
lib/libc/wasi/libc-top-half/musl/src/locale/dcngettext.c
@@ -1,283 +0,0 @@
-#include <libintl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <limits.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <ctype.h>
-#include "locale_impl.h"
-#include "atomic.h"
-#include "pleval.h"
-#include "lock.h"
-#include "fork_impl.h"
-
-#define malloc __libc_malloc
-#define calloc __libc_calloc
-#define realloc undef
-#define free undef
-
-struct binding {
- struct binding *next;
- int dirlen;
- volatile int active;
- char *domainname;
- char *dirname;
- char buf[];
-};
-
-static void *volatile bindings;
-
-static char *gettextdir(const char *domainname, size_t *dirlen)
-{
- struct binding *p;
- for (p=bindings; p; p=p->next) {
- if (!strcmp(p->domainname, domainname) && p->active) {
- *dirlen = p->dirlen;
- return (char *)p->dirname;
- }
- }
- return 0;
-}
-
-static volatile int lock[1];
-volatile int *const __gettext_lockptr = lock;
-
-char *bindtextdomain(const char *domainname, const char *dirname)
-{
- struct binding *p, *q;
-
- if (!domainname) return 0;
- if (!dirname) return gettextdir(domainname, &(size_t){0});
-
- size_t domlen = strnlen(domainname, NAME_MAX+1);
- size_t dirlen = strnlen(dirname, PATH_MAX);
- if (domlen > NAME_MAX || dirlen >= PATH_MAX) {
- errno = EINVAL;
- return 0;
- }
-
- LOCK(lock);
-
- for (p=bindings; p; p=p->next) {
- if (!strcmp(p->domainname, domainname) &&
- !strcmp(p->dirname, dirname)) {
- break;
- }
- }
-
- if (!p) {
- p = calloc(sizeof *p + domlen + dirlen + 2, 1);
- if (!p) {
- UNLOCK(lock);
- return 0;
- }
- p->next = bindings;
- p->dirlen = dirlen;
- p->domainname = p->buf;
- p->dirname = p->buf + domlen + 1;
- memcpy(p->domainname, domainname, domlen+1);
- memcpy(p->dirname, dirname, dirlen+1);
- a_cas_p(&bindings, bindings, p);
- }
-
- a_store(&p->active, 1);
-
- for (q=bindings; q; q=q->next) {
- if (!strcmp(q->domainname, domainname) && q != p)
- a_store(&q->active, 0);
- }
-
- UNLOCK(lock);
-
- return (char *)p->dirname;
-}
-
-static const char catnames[][12] = {
- "LC_CTYPE",
- "LC_NUMERIC",
- "LC_TIME",
- "LC_COLLATE",
- "LC_MONETARY",
- "LC_MESSAGES",
-};
-
-static const char catlens[] = { 8, 10, 7, 10, 11, 11 };
-
-struct msgcat {
- struct msgcat *next;
- const void *map;
- size_t map_size;
- const char *plural_rule;
- int nplurals;
- struct binding *binding;
- const struct __locale_map *lm;
- int cat;
-};
-
-static char *dummy_gettextdomain()
-{
- return "messages";
-}
-
-weak_alias(dummy_gettextdomain, __gettextdomain);
-
-char *dcngettext(const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n, int category)
-{
- static struct msgcat *volatile cats;
- struct msgcat *p;
- struct __locale_struct *loc = CURRENT_LOCALE;
- const struct __locale_map *lm;
- size_t domlen;
- struct binding *q;
- int old_errno = errno;
-
- /* match gnu gettext behaviour */
- if (!msgid1) goto notrans;
-
- if ((unsigned)category >= LC_ALL) goto notrans;
-
- if (!domainname) domainname = __gettextdomain();
-
- domlen = strnlen(domainname, NAME_MAX+1);
- if (domlen > NAME_MAX) goto notrans;
-
- for (q=bindings; q; q=q->next)
- if (!strcmp(q->domainname, domainname) && q->active)
- break;
- if (!q) goto notrans;
-
- lm = loc->cat[category];
- if (!lm) {
-notrans:
- errno = old_errno;
- return (char *) ((n == 1) ? msgid1 : msgid2);
- }
-
- for (p=cats; p; p=p->next)
- if (p->binding == q && p->lm == lm && p->cat == category)
- break;
-
- if (!p) {
- const char *dirname, *locname, *catname, *modname, *locp;
- size_t dirlen, loclen, catlen, modlen, alt_modlen;
- void *old_cats;
- size_t map_size;
-
- dirname = q->dirname;
- locname = lm->name;
- catname = catnames[category];
-
- dirlen = q->dirlen;
- loclen = strlen(locname);
- catlen = catlens[category];
-
- /* Logically split @mod suffix from locale name. */
- modname = memchr(locname, '@', loclen);
- if (!modname) modname = locname + loclen;
- alt_modlen = modlen = loclen - (modname-locname);
- loclen = modname-locname;
-
- /* Drop .charset identifier; it is not used. */
- const char *csp = memchr(locname, '.', loclen);
- if (csp) loclen = csp-locname;
-
- char name[dirlen+1 + loclen+modlen+1 + catlen+1 + domlen+3 + 1];
- const void *map;
-
- for (;;) {
- snprintf(name, sizeof name, "%s/%.*s%.*s/%s/%s.mo\0",
- dirname, (int)loclen, locname,
- (int)alt_modlen, modname, catname, domainname);
- if (map = __map_file(name, &map_size)) break;
-
- /* Try dropping @mod, _YY, then both. */
- if (alt_modlen) {
- alt_modlen = 0;
- } else if ((locp = memchr(locname, '_', loclen))) {
- loclen = locp-locname;
- alt_modlen = modlen;
- } else {
- break;
- }
- }
- if (!map) goto notrans;
-
- p = calloc(sizeof *p, 1);
- if (!p) {
- __munmap((void *)map, map_size);
- goto notrans;
- }
- p->cat = category;
- p->binding = q;
- p->lm = lm;
- p->map = map;
- p->map_size = map_size;
-
- const char *rule = "n!=1;";
- unsigned long np = 2;
- const char *r = __mo_lookup(p->map, p->map_size, "");
- char *z;
- while (r && strncmp(r, "Plural-Forms:", 13)) {
- z = strchr(r, '\n');
- r = z ? z+1 : 0;
- }
- if (r) {
- r += 13;
- while (isspace(*r)) r++;
- if (!strncmp(r, "nplurals=", 9)) {
- np = strtoul(r+9, &z, 10);
- r = z;
- }
- while (*r && *r != ';') r++;
- if (*r) {
- r++;
- while (isspace(*r)) r++;
- if (!strncmp(r, "plural=", 7))
- rule = r+7;
- }
- }
- p->nplurals = np;
- p->plural_rule = rule;
-
- do {
- old_cats = cats;
- p->next = old_cats;
- } while (a_cas_p(&cats, old_cats, p) != old_cats);
- }
-
- const char *trans = __mo_lookup(p->map, p->map_size, msgid1);
- if (!trans) goto notrans;
-
- /* Non-plural-processing gettext forms pass a null pointer as
- * msgid2 to request that dcngettext suppress plural processing. */
-
- if (msgid2 && p->nplurals) {
- unsigned long plural = __pleval(p->plural_rule, n);
- if (plural > p->nplurals) goto notrans;
- while (plural--) {
- size_t rem = p->map_size - (trans - (char *)p->map);
- size_t l = strnlen(trans, rem);
- if (l+1 >= rem)
- goto notrans;
- trans += l+1;
- }
- }
- errno = old_errno;
- return (char *)trans;
-}
-
-char *dcgettext(const char *domainname, const char *msgid, int category)
-{
- return dcngettext(domainname, msgid, 0, 1, category);
-}
-
-char *dngettext(const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n)
-{
- return dcngettext(domainname, msgid1, msgid2, n, LC_MESSAGES);
-}
-
-char *dgettext(const char *domainname, const char *msgid)
-{
- return dcngettext(domainname, msgid, 0, 1, LC_MESSAGES);
-}
lib/libc/wasi/libc-top-half/musl/src/locale/textdomain.c
@@ -1,42 +0,0 @@
-#include <libintl.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <limits.h>
-
-static char *current_domain;
-
-char *__gettextdomain()
-{
- return current_domain ? current_domain : "messages";
-}
-
-char *textdomain(const char *domainname)
-{
- if (!domainname) return __gettextdomain();
-
- size_t domlen = strlen(domainname);
- if (domlen > NAME_MAX) {
- errno = EINVAL;
- return 0;
- }
-
- if (!current_domain) {
- current_domain = malloc(NAME_MAX+1);
- if (!current_domain) return 0;
- }
-
- memcpy(current_domain, domainname, domlen+1);
-
- return current_domain;
-}
-
-char *gettext(const char *msgid)
-{
- return dgettext(0, msgid);
-}
-
-char *ngettext(const char *msgid1, const char *msgid2, unsigned long int n)
-{
- return dngettext(0, msgid1, msgid2, n);
-}
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/aligned_alloc.c
@@ -1,60 +0,0 @@
-#include <stdlib.h>
-#include <errno.h>
-#include "meta.h"
-
-void *aligned_alloc(size_t align, size_t len)
-{
- if ((align & -align) != align) {
- errno = EINVAL;
- return 0;
- }
-
- if (len > SIZE_MAX - align || align >= (1ULL<<31)*UNIT) {
- errno = ENOMEM;
- return 0;
- }
-
- if (DISABLE_ALIGNED_ALLOC) {
- errno = ENOMEM;
- return 0;
- }
-
- if (align <= UNIT) align = UNIT;
-
- unsigned char *p = malloc(len + align - UNIT);
- if (!p)
- return 0;
-
- struct meta *g = get_meta(p);
- int idx = get_slot_index(p);
- size_t stride = get_stride(g);
- unsigned char *start = g->mem->storage + stride*idx;
- unsigned char *end = g->mem->storage + stride*(idx+1) - IB;
- size_t adj = -(uintptr_t)p & (align-1);
-
- if (!adj) {
- set_size(p, end, len);
- return p;
- }
- p += adj;
- uint32_t offset = (size_t)(p-g->mem->storage)/UNIT;
- if (offset <= 0xffff) {
- *(uint16_t *)(p-2) = offset;
- p[-4] = 0;
- } else {
- // use a 32-bit offset if 16-bit doesn't fit. for this,
- // 16-bit field must be zero, [-4] byte nonzero.
- *(uint16_t *)(p-2) = 0;
- *(uint32_t *)(p-8) = offset;
- p[-4] = 1;
- }
- p[-3] = idx;
- set_size(p, end, len);
- // store offset to aligned enframing. this facilitates cycling
- // offset and also iteration of heap for debugging/measurement.
- // for extreme overalignment it won't fit but these are classless
- // allocations anyway.
- *(uint16_t *)(start - 2) = (size_t)(p-start)/UNIT;
- start[-3] = 7<<5;
- return p;
-}
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/donate.c
@@ -1,39 +0,0 @@
-#include <stdlib.h>
-#include <stdint.h>
-#include <limits.h>
-#include <string.h>
-#include <sys/mman.h>
-#include <errno.h>
-
-#include "meta.h"
-
-static void donate(unsigned char *base, size_t len)
-{
- uintptr_t a = (uintptr_t)base;
- uintptr_t b = a + len;
- a += -a & (UNIT-1);
- b -= b & (UNIT-1);
- memset(base, 0, len);
- for (int sc=47; sc>0 && b>a; sc-=4) {
- if (b-a < (size_classes[sc]+1)*UNIT) continue;
- struct meta *m = alloc_meta();
- m->avail_mask = 0;
- m->freed_mask = 1;
- m->mem = (void *)a;
- m->mem->meta = m;
- m->last_idx = 0;
- m->freeable = 0;
- m->sizeclass = sc;
- m->maplen = 0;
- *((unsigned char *)m->mem+UNIT-4) = 0;
- *((unsigned char *)m->mem+UNIT-3) = 255;
- m->mem->storage[size_classes[sc]*UNIT-4] = 0;
- queue(&ctx.active[sc], m);
- a += (size_classes[sc]+1)*UNIT;
- }
-}
-
-void __malloc_donate(char *start, char *end)
-{
- donate((void *)start, end-start);
-}
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/free.c
@@ -1,151 +0,0 @@
-#define _BSD_SOURCE
-#include <stdlib.h>
-#include <sys/mman.h>
-
-#include "meta.h"
-
-struct mapinfo {
- void *base;
- size_t len;
-};
-
-static struct mapinfo nontrivial_free(struct meta *, int);
-
-static struct mapinfo free_group(struct meta *g)
-{
- struct mapinfo mi = { 0 };
- int sc = g->sizeclass;
- if (sc < 48) {
- ctx.usage_by_class[sc] -= g->last_idx+1;
- }
- if (g->maplen) {
- step_seq();
- record_seq(sc);
- mi.base = g->mem;
- mi.len = g->maplen*4096UL;
- } else {
- void *p = g->mem;
- struct meta *m = get_meta(p);
- int idx = get_slot_index(p);
- g->mem->meta = 0;
- // not checking size/reserved here; it's intentionally invalid
- mi = nontrivial_free(m, idx);
- }
- free_meta(g);
- return mi;
-}
-
-static int okay_to_free(struct meta *g)
-{
- int sc = g->sizeclass;
-
- if (!g->freeable) return 0;
-
- // always free individual mmaps not suitable for reuse
- if (sc >= 48 || get_stride(g) < UNIT*size_classes[sc])
- return 1;
-
- // always free groups allocated inside another group's slot
- // since recreating them should not be expensive and they
- // might be blocking freeing of a much larger group.
- if (!g->maplen) return 1;
-
- // if there is another non-full group, free this one to
- // consolidate future allocations, reduce fragmentation.
- if (g->next != g) return 1;
-
- // free any group in a size class that's not bouncing
- if (!is_bouncing(sc)) return 1;
-
- size_t cnt = g->last_idx+1;
- size_t usage = ctx.usage_by_class[sc];
-
- // if usage is high enough that a larger count should be
- // used, free the low-count group so a new one will be made.
- if (9*cnt <= usage && cnt < 20)
- return 1;
-
- // otherwise, keep the last group in a bouncing class.
- return 0;
-}
-
-static struct mapinfo nontrivial_free(struct meta *g, int i)
-{
- uint32_t self = 1u<<i;
- int sc = g->sizeclass;
- uint32_t mask = g->freed_mask | g->avail_mask;
-
- if (mask+self == (2u<<g->last_idx)-1 && okay_to_free(g)) {
- // any multi-slot group is necessarily on an active list
- // here, but single-slot groups might or might not be.
- if (g->next) {
- assert(sc < 48);
- int activate_new = (ctx.active[sc]==g);
- dequeue(&ctx.active[sc], g);
- if (activate_new && ctx.active[sc])
- activate_group(ctx.active[sc]);
- }
- return free_group(g);
- } else if (!mask) {
- assert(sc < 48);
- // might still be active if there were no allocations
- // after last available slot was taken.
- if (ctx.active[sc] != g) {
- queue(&ctx.active[sc], g);
- }
- }
- a_or(&g->freed_mask, self);
- return (struct mapinfo){ 0 };
-}
-
-void free(void *p)
-{
- if (!p) return;
-
- struct meta *g = get_meta(p);
- int idx = get_slot_index(p);
- size_t stride = get_stride(g);
- unsigned char *start = g->mem->storage + stride*idx;
- unsigned char *end = start + stride - IB;
- get_nominal_size(p, end);
- uint32_t self = 1u<<idx, all = (2u<<g->last_idx)-1;
- ((unsigned char *)p)[-3] = 255;
- // invalidate offset to group header, and cycle offset of
- // used region within slot if current offset is zero.
- *(uint16_t *)((char *)p-2) = 0;
-
- // release any whole pages contained in the slot to be freed
- // unless it's a single-slot group that will be unmapped.
- if (((uintptr_t)(start-1) ^ (uintptr_t)end) >= 2*PGSZ && g->last_idx) {
- unsigned char *base = start + (-(uintptr_t)start & (PGSZ-1));
- size_t len = (end-base) & -PGSZ;
- if (len) {
- int e = errno;
- madvise(base, len, MADV_FREE);
- errno = e;
- }
- }
-
- // atomic free without locking if this is neither first or last slot
- for (;;) {
- uint32_t freed = g->freed_mask;
- uint32_t avail = g->avail_mask;
- uint32_t mask = freed | avail;
- assert(!(mask&self));
- if (!freed || mask+self==all) break;
- if (!MT)
- g->freed_mask = freed+self;
- else if (a_cas(&g->freed_mask, freed, freed+self)!=freed)
- continue;
- return;
- }
-
- wrlock();
- struct mapinfo mi = nontrivial_free(g, idx);
- unlock();
- if (mi.len) {
- int e = errno;
- munmap(mi.base, mi.len);
- errno = e;
- }
-}
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/malloc.c
@@ -1,387 +0,0 @@
-#include <stdlib.h>
-#include <stdint.h>
-#include <limits.h>
-#include <string.h>
-#include <sys/mman.h>
-#include <errno.h>
-
-#include "meta.h"
-
-LOCK_OBJ_DEF;
-
-const uint16_t size_classes[] = {
- 1, 2, 3, 4, 5, 6, 7, 8,
- 9, 10, 12, 15,
- 18, 20, 25, 31,
- 36, 42, 50, 63,
- 72, 84, 102, 127,
- 146, 170, 204, 255,
- 292, 340, 409, 511,
- 584, 682, 818, 1023,
- 1169, 1364, 1637, 2047,
- 2340, 2730, 3276, 4095,
- 4680, 5460, 6552, 8191,
-};
-
-static const uint8_t small_cnt_tab[][3] = {
- { 30, 30, 30 },
- { 31, 15, 15 },
- { 20, 10, 10 },
- { 31, 15, 7 },
- { 25, 12, 6 },
- { 21, 10, 5 },
- { 18, 8, 4 },
- { 31, 15, 7 },
- { 28, 14, 6 },
-};
-
-static const uint8_t med_cnt_tab[4] = { 28, 24, 20, 32 };
-
-struct malloc_context ctx = { 0 };
-
-struct meta *alloc_meta(void)
-{
- struct meta *m;
- unsigned char *p;
- if (!ctx.init_done) {
-#ifndef PAGESIZE
- ctx.pagesize = get_page_size();
-#endif
- ctx.secret = get_random_secret();
- ctx.init_done = 1;
- }
- size_t pagesize = PGSZ;
- if (pagesize < 4096) pagesize = 4096;
- if ((m = dequeue_head(&ctx.free_meta_head))) return m;
- if (!ctx.avail_meta_count) {
- int need_unprotect = 1;
- if (!ctx.avail_meta_area_count && ctx.brk!=-1) {
- uintptr_t new = ctx.brk + pagesize;
- int need_guard = 0;
- if (!ctx.brk) {
- need_guard = 1;
- ctx.brk = brk(0);
- // some ancient kernels returned _ebss
- // instead of next page as initial brk.
- ctx.brk += -ctx.brk & (pagesize-1);
- new = ctx.brk + 2*pagesize;
- }
- if (brk(new) != new) {
- ctx.brk = -1;
- } else {
- if (need_guard) mmap((void *)ctx.brk, pagesize,
- PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0);
- ctx.brk = new;
- ctx.avail_meta_areas = (void *)(new - pagesize);
- ctx.avail_meta_area_count = pagesize>>12;
- need_unprotect = 0;
- }
- }
- if (!ctx.avail_meta_area_count) {
- size_t n = 2UL << ctx.meta_alloc_shift;
- p = mmap(0, n*pagesize, PROT_NONE,
- MAP_PRIVATE|MAP_ANON, -1, 0);
- if (p==MAP_FAILED) return 0;
- ctx.avail_meta_areas = p + pagesize;
- ctx.avail_meta_area_count = (n-1)*(pagesize>>12);
- ctx.meta_alloc_shift++;
- }
- p = ctx.avail_meta_areas;
- if ((uintptr_t)p & (pagesize-1)) need_unprotect = 0;
- if (need_unprotect)
- if (mprotect(p, pagesize, PROT_READ|PROT_WRITE)
- && errno != ENOSYS)
- return 0;
- ctx.avail_meta_area_count--;
- ctx.avail_meta_areas = p + 4096;
- if (ctx.meta_area_tail) {
- ctx.meta_area_tail->next = (void *)p;
- } else {
- ctx.meta_area_head = (void *)p;
- }
- ctx.meta_area_tail = (void *)p;
- ctx.meta_area_tail->check = ctx.secret;
- ctx.avail_meta_count = ctx.meta_area_tail->nslots
- = (4096-sizeof(struct meta_area))/sizeof *m;
- ctx.avail_meta = ctx.meta_area_tail->slots;
- }
- ctx.avail_meta_count--;
- m = ctx.avail_meta++;
- m->prev = m->next = 0;
- return m;
-}
-
-static uint32_t try_avail(struct meta **pm)
-{
- struct meta *m = *pm;
- uint32_t first;
- if (!m) return 0;
- uint32_t mask = m->avail_mask;
- if (!mask) {
- if (!m) return 0;
- if (!m->freed_mask) {
- dequeue(pm, m);
- m = *pm;
- if (!m) return 0;
- } else {
- m = m->next;
- *pm = m;
- }
-
- mask = m->freed_mask;
-
- // skip fully-free group unless it's the only one
- // or it's a permanently non-freeable group
- if (mask == (2u<<m->last_idx)-1 && m->freeable) {
- m = m->next;
- *pm = m;
- mask = m->freed_mask;
- }
-
- // activate more slots in a not-fully-active group
- // if needed, but only as a last resort. prefer using
- // any other group with free slots. this avoids
- // touching & dirtying as-yet-unused pages.
- if (!(mask & ((2u<<m->mem->active_idx)-1))) {
- if (m->next != m) {
- m = m->next;
- *pm = m;
- } else {
- int cnt = m->mem->active_idx + 2;
- int size = size_classes[m->sizeclass]*UNIT;
- int span = UNIT + size*cnt;
- // activate up to next 4k boundary
- while ((span^(span+size-1)) < 4096) {
- cnt++;
- span += size;
- }
- if (cnt > m->last_idx+1)
- cnt = m->last_idx+1;
- m->mem->active_idx = cnt-1;
- }
- }
- mask = activate_group(m);
- assert(mask);
- decay_bounces(m->sizeclass);
- }
- first = mask&-mask;
- m->avail_mask = mask-first;
- return first;
-}
-
-static int alloc_slot(int, size_t);
-
-static struct meta *alloc_group(int sc, size_t req)
-{
- size_t size = UNIT*size_classes[sc];
- int i = 0, cnt;
- unsigned char *p;
- struct meta *m = alloc_meta();
- if (!m) return 0;
- size_t usage = ctx.usage_by_class[sc];
- size_t pagesize = PGSZ;
- int active_idx;
- if (sc < 9) {
- while (i<2 && 4*small_cnt_tab[sc][i] > usage)
- i++;
- cnt = small_cnt_tab[sc][i];
- } else {
- // lookup max number of slots fitting in power-of-two size
- // from a table, along with number of factors of two we
- // can divide out without a remainder or reaching 1.
- cnt = med_cnt_tab[sc&3];
-
- // reduce cnt to avoid excessive eagar allocation.
- while (!(cnt&1) && 4*cnt > usage)
- cnt >>= 1;
-
- // data structures don't support groups whose slot offsets
- // in units don't fit in 16 bits.
- while (size*cnt >= 65536*UNIT)
- cnt >>= 1;
- }
-
- // If we selected a count of 1 above but it's not sufficient to use
- // mmap, increase to 2. Then it might be; if not it will nest.
- if (cnt==1 && size*cnt+UNIT <= pagesize/2) cnt = 2;
-
- // All choices of size*cnt are "just below" a power of two, so anything
- // larger than half the page size should be allocated as whole pages.
- if (size*cnt+UNIT > pagesize/2) {
- // check/update bounce counter to start/increase retention
- // of freed maps, and inhibit use of low-count, odd-size
- // small mappings and single-slot groups if activated.
- int nosmall = is_bouncing(sc);
- account_bounce(sc);
- step_seq();
-
- // since the following count reduction opportunities have
- // an absolute memory usage cost, don't overdo them. count
- // coarse usage as part of usage.
- if (!(sc&1) && sc<32) usage += ctx.usage_by_class[sc+1];
-
- // try to drop to a lower count if the one found above
- // increases usage by more than 25%. these reduced counts
- // roughly fill an integral number of pages, just not a
- // power of two, limiting amount of unusable space.
- if (4*cnt > usage && !nosmall) {
- if (0);
- else if ((sc&3)==1 && size*cnt>8*pagesize) cnt = 2;
- else if ((sc&3)==2 && size*cnt>4*pagesize) cnt = 3;
- else if ((sc&3)==0 && size*cnt>8*pagesize) cnt = 3;
- else if ((sc&3)==0 && size*cnt>2*pagesize) cnt = 5;
- }
- size_t needed = size*cnt + UNIT;
- needed += -needed & (pagesize-1);
-
- // produce an individually-mmapped allocation if usage is low,
- // bounce counter hasn't triggered, and either it saves memory
- // or it avoids eagar slot allocation without wasting too much.
- if (!nosmall && cnt<=7) {
- req += IB + UNIT;
- req += -req & (pagesize-1);
- if (req<size+UNIT || (req>=4*pagesize && 2*cnt>usage)) {
- cnt = 1;
- needed = req;
- }
- }
-
- p = mmap(0, needed, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
- if (p==MAP_FAILED) {
- free_meta(m);
- return 0;
- }
- m->maplen = needed>>12;
- ctx.mmap_counter++;
- active_idx = (4096-UNIT)/size-1;
- if (active_idx > cnt-1) active_idx = cnt-1;
- if (active_idx < 0) active_idx = 0;
- } else {
- int j = size_to_class(UNIT+cnt*size-IB);
- int idx = alloc_slot(j, UNIT+cnt*size-IB);
- if (idx < 0) {
- free_meta(m);
- return 0;
- }
- struct meta *g = ctx.active[j];
- p = enframe(g, idx, UNIT*size_classes[j]-IB, ctx.mmap_counter);
- m->maplen = 0;
- p[-3] = (p[-3]&31) | (6<<5);
- for (int i=0; i<=cnt; i++)
- p[UNIT+i*size-4] = 0;
- active_idx = cnt-1;
- }
- ctx.usage_by_class[sc] += cnt;
- m->avail_mask = (2u<<active_idx)-1;
- m->freed_mask = (2u<<(cnt-1))-1 - m->avail_mask;
- m->mem = (void *)p;
- m->mem->meta = m;
- m->mem->active_idx = active_idx;
- m->last_idx = cnt-1;
- m->freeable = 1;
- m->sizeclass = sc;
- return m;
-}
-
-static int alloc_slot(int sc, size_t req)
-{
- uint32_t first = try_avail(&ctx.active[sc]);
- if (first) return a_ctz_32(first);
-
- struct meta *g = alloc_group(sc, req);
- if (!g) return -1;
-
- g->avail_mask--;
- queue(&ctx.active[sc], g);
- return 0;
-}
-
-void *malloc(size_t n)
-{
- if (size_overflows(n)) return 0;
- struct meta *g;
- uint32_t mask, first;
- int sc;
- int idx;
- int ctr;
-
- if (n >= MMAP_THRESHOLD) {
- size_t needed = n + IB + UNIT;
- void *p = mmap(0, needed, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_ANON, -1, 0);
- if (p==MAP_FAILED) return 0;
- wrlock();
- step_seq();
- g = alloc_meta();
- if (!g) {
- unlock();
- munmap(p, needed);
- return 0;
- }
- g->mem = p;
- g->mem->meta = g;
- g->last_idx = 0;
- g->freeable = 1;
- g->sizeclass = 63;
- g->maplen = (needed+4095)/4096;
- g->avail_mask = g->freed_mask = 0;
- // use a global counter to cycle offset in
- // individually-mmapped allocations.
- ctx.mmap_counter++;
- idx = 0;
- goto success;
- }
-
- sc = size_to_class(n);
-
- rdlock();
- g = ctx.active[sc];
-
- // use coarse size classes initially when there are not yet
- // any groups of desired size. this allows counts of 2 or 3
- // to be allocated at first rather than having to start with
- // 7 or 5, the min counts for even size classes.
- if (!g && sc>=4 && sc<32 && sc!=6 && !(sc&1) && !ctx.usage_by_class[sc]) {
- size_t usage = ctx.usage_by_class[sc|1];
- // if a new group may be allocated, count it toward
- // usage in deciding if we can use coarse class.
- if (!ctx.active[sc|1] || (!ctx.active[sc|1]->avail_mask
- && !ctx.active[sc|1]->freed_mask))
- usage += 3;
- if (usage <= 12)
- sc |= 1;
- g = ctx.active[sc];
- }
-
- for (;;) {
- mask = g ? g->avail_mask : 0;
- first = mask&-mask;
- if (!first) break;
- if (RDLOCK_IS_EXCLUSIVE || !MT)
- g->avail_mask = mask-first;
- else if (a_cas(&g->avail_mask, mask, mask-first)!=mask)
- continue;
- idx = a_ctz_32(first);
- goto success;
- }
- upgradelock();
-
- idx = alloc_slot(sc, n);
- if (idx < 0) {
- unlock();
- return 0;
- }
- g = ctx.active[sc];
-
-success:
- ctr = ctx.mmap_counter;
- unlock();
- return enframe(g, idx, n, ctr);
-}
-
-int is_allzero(void *p)
-{
- struct meta *g = get_meta(p);
- return g->sizeclass >= 48 ||
- get_stride(g) < UNIT*size_classes[g->sizeclass];
-}
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/malloc_usable_size.c
@@ -1,13 +0,0 @@
-#include <stdlib.h>
-#include "meta.h"
-
-size_t malloc_usable_size(void *p)
-{
- if (!p) return 0;
- struct meta *g = get_meta(p);
- int idx = get_slot_index(p);
- size_t stride = get_stride(g);
- unsigned char *start = g->mem->storage + stride*idx;
- unsigned char *end = start + stride - IB;
- return get_nominal_size(p, end);
-}
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/realloc.c
@@ -1,51 +0,0 @@
-#define _GNU_SOURCE
-#include <stdlib.h>
-#include <sys/mman.h>
-#include <string.h>
-#include "meta.h"
-
-void *realloc(void *p, size_t n)
-{
- if (!p) return malloc(n);
- if (size_overflows(n)) return 0;
-
- struct meta *g = get_meta(p);
- int idx = get_slot_index(p);
- size_t stride = get_stride(g);
- unsigned char *start = g->mem->storage + stride*idx;
- unsigned char *end = start + stride - IB;
- size_t old_size = get_nominal_size(p, end);
- size_t avail_size = end-(unsigned char *)p;
- void *new;
-
- // only resize in-place if size class matches
- if (n <= avail_size && n<MMAP_THRESHOLD
- && size_to_class(n)+1 >= g->sizeclass) {
- set_size(p, end, n);
- return p;
- }
-
- // use mremap if old and new size are both mmap-worthy
- if (g->sizeclass>=48 && n>=MMAP_THRESHOLD) {
- assert(g->sizeclass==63);
- size_t base = (unsigned char *)p-start;
- size_t needed = (n + base + UNIT + IB + 4095) & -4096;
- new = g->maplen*4096UL == needed ? g->mem :
- mremap(g->mem, g->maplen*4096UL, needed, MREMAP_MAYMOVE);
- if (new!=MAP_FAILED) {
- g->mem = new;
- g->maplen = needed/4096;
- p = g->mem->storage + base;
- end = g->mem->storage + (needed - UNIT) - IB;
- *end = 0;
- set_size(p, end, n);
- return p;
- }
- }
-
- new = malloc(n);
- if (!new) return 0;
- memcpy(new, p, n < old_size ? n : old_size);
- free(p);
- return new;
-}
lib/libc/wasi/libc-top-half/musl/src/malloc/oldmalloc/aligned_alloc.c
@@ -1,53 +0,0 @@
-#include <stdlib.h>
-#include <stdint.h>
-#include <errno.h>
-#include "malloc_impl.h"
-
-void *aligned_alloc(size_t align, size_t len)
-{
- unsigned char *mem, *new;
-
- if ((align & -align) != align) {
- errno = EINVAL;
- return 0;
- }
-
- if (len > SIZE_MAX - align ||
- (__malloc_replaced && !__aligned_alloc_replaced)) {
- errno = ENOMEM;
- return 0;
- }
-
- if (align <= SIZE_ALIGN)
- return malloc(len);
-
- if (!(mem = malloc(len + align-1)))
- return 0;
-
- new = (void *)((uintptr_t)mem + align-1 & -align);
- if (new == mem) return mem;
-
- struct chunk *c = MEM_TO_CHUNK(mem);
- struct chunk *n = MEM_TO_CHUNK(new);
-
- if (IS_MMAPPED(c)) {
- /* Apply difference between aligned and original
- * address to the "extra" field of mmapped chunk. */
- n->psize = c->psize + (new-mem);
- n->csize = c->csize - (new-mem);
- return new;
- }
-
- struct chunk *t = NEXT_CHUNK(c);
-
- /* Split the allocated chunk into two chunks. The aligned part
- * that will be used has the size in its footer reduced by the
- * difference between the aligned and original addresses, and
- * the resulting size copied to its header. A new header and
- * footer are written for the split-off part to be freed. */
- n->psize = c->csize = C_INUSE | (new-mem);
- n->csize = t->psize -= new-mem;
-
- __bin_chunk(c);
- return new;
-}
lib/libc/wasi/libc-top-half/musl/src/malloc/oldmalloc/malloc.c
@@ -1,556 +0,0 @@
-#define _GNU_SOURCE
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <stdint.h>
-#include <errno.h>
-#include <sys/mman.h>
-#include "libc.h"
-#include "atomic.h"
-#include "pthread_impl.h"
-#include "malloc_impl.h"
-#include "fork_impl.h"
-
-#define malloc __libc_malloc_impl
-#define realloc __libc_realloc
-#define free __libc_free
-
-#if defined(__GNUC__) && defined(__PIC__)
-#define inline inline __attribute__((always_inline))
-#endif
-
-static struct {
- volatile uint64_t binmap;
- struct bin bins[64];
- volatile int split_merge_lock[2];
-} mal;
-
-/* Synchronization tools */
-
-static inline void lock(volatile int *lk)
-{
- int need_locks = libc.need_locks;
- if (need_locks) {
- while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1);
- if (need_locks < 0) libc.need_locks = 0;
- }
-}
-
-static inline void unlock(volatile int *lk)
-{
- if (lk[0]) {
- a_store(lk, 0);
- if (lk[1]) __wake(lk, 1, 1);
- }
-}
-
-static inline void lock_bin(int i)
-{
- lock(mal.bins[i].lock);
- if (!mal.bins[i].head)
- mal.bins[i].head = mal.bins[i].tail = BIN_TO_CHUNK(i);
-}
-
-static inline void unlock_bin(int i)
-{
- unlock(mal.bins[i].lock);
-}
-
-static int first_set(uint64_t x)
-{
-#if 1
- return a_ctz_64(x);
-#else
- static const char debruijn64[64] = {
- 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,
- 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,
- 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,
- 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12
- };
- static const char debruijn32[32] = {
- 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
- 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
- };
- if (sizeof(long) < 8) {
- uint32_t y = x;
- if (!y) {
- y = x>>32;
- return 32 + debruijn32[(y&-y)*0x076be629 >> 27];
- }
- return debruijn32[(y&-y)*0x076be629 >> 27];
- }
- return debruijn64[(x&-x)*0x022fdd63cc95386dull >> 58];
-#endif
-}
-
-static const unsigned char bin_tab[60] = {
- 32,33,34,35,36,36,37,37,38,38,39,39,
- 40,40,40,40,41,41,41,41,42,42,42,42,43,43,43,43,
- 44,44,44,44,44,44,44,44,45,45,45,45,45,45,45,45,
- 46,46,46,46,46,46,46,46,47,47,47,47,47,47,47,47,
-};
-
-static int bin_index(size_t x)
-{
- x = x / SIZE_ALIGN - 1;
- if (x <= 32) return x;
- if (x < 512) return bin_tab[x/8-4];
- if (x > 0x1c00) return 63;
- return bin_tab[x/128-4] + 16;
-}
-
-static int bin_index_up(size_t x)
-{
- x = x / SIZE_ALIGN - 1;
- if (x <= 32) return x;
- x--;
- if (x < 512) return bin_tab[x/8-4] + 1;
- return bin_tab[x/128-4] + 17;
-}
-
-#if 0
-void __dump_heap(int x)
-{
- struct chunk *c;
- int i;
- for (c = (void *)mal.heap; CHUNK_SIZE(c); c = NEXT_CHUNK(c))
- fprintf(stderr, "base %p size %zu (%d) flags %d/%d\n",
- c, CHUNK_SIZE(c), bin_index(CHUNK_SIZE(c)),
- c->csize & 15,
- NEXT_CHUNK(c)->psize & 15);
- for (i=0; i<64; i++) {
- if (mal.bins[i].head != BIN_TO_CHUNK(i) && mal.bins[i].head) {
- fprintf(stderr, "bin %d: %p\n", i, mal.bins[i].head);
- if (!(mal.binmap & 1ULL<<i))
- fprintf(stderr, "missing from binmap!\n");
- } else if (mal.binmap & 1ULL<<i)
- fprintf(stderr, "binmap wrongly contains %d!\n", i);
- }
-}
-#endif
-
-/* This function returns true if the interval [old,new]
- * intersects the 'len'-sized interval below &libc.auxv
- * (interpreted as the main-thread stack) or below &b
- * (the current stack). It is used to defend against
- * buggy brk implementations that can cross the stack. */
-
-static int traverses_stack_p(uintptr_t old, uintptr_t new)
-{
- const uintptr_t len = 8<<20;
- uintptr_t a, b;
-
- b = (uintptr_t)libc.auxv;
- a = b > len ? b-len : 0;
- if (new>a && old<b) return 1;
-
- b = (uintptr_t)&b;
- a = b > len ? b-len : 0;
- if (new>a && old<b) return 1;
-
- return 0;
-}
-
-/* Expand the heap in-place if brk can be used, or otherwise via mmap,
- * using an exponential lower bound on growth by mmap to make
- * fragmentation asymptotically irrelevant. The size argument is both
- * an input and an output, since the caller needs to know the size
- * allocated, which will be larger than requested due to page alignment
- * and mmap minimum size rules. The caller is responsible for locking
- * to prevent concurrent calls. */
-
-static void *__expand_heap(size_t *pn)
-{
- static uintptr_t brk;
- static unsigned mmap_step;
- size_t n = *pn;
-
- if (n > SIZE_MAX/2 - PAGE_SIZE) {
- errno = ENOMEM;
- return 0;
- }
- n += -n & PAGE_SIZE-1;
-
- if (!brk) {
- brk = __syscall(SYS_brk, 0);
- brk += -brk & PAGE_SIZE-1;
- }
-
- if (n < SIZE_MAX-brk && !traverses_stack_p(brk, brk+n)
- && __syscall(SYS_brk, brk+n)==brk+n) {
- *pn = n;
- brk += n;
- return (void *)(brk-n);
- }
-
- size_t min = (size_t)PAGE_SIZE << mmap_step/2;
- if (n < min) n = min;
- void *area = __mmap(0, n, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
- if (area == MAP_FAILED) return 0;
- *pn = n;
- mmap_step++;
- return area;
-}
-
-static struct chunk *expand_heap(size_t n)
-{
- static void *end;
- void *p;
- struct chunk *w;
-
- /* The argument n already accounts for the caller's chunk
- * overhead needs, but if the heap can't be extended in-place,
- * we need room for an extra zero-sized sentinel chunk. */
- n += SIZE_ALIGN;
-
- p = __expand_heap(&n);
- if (!p) return 0;
-
- /* If not just expanding existing space, we need to make a
- * new sentinel chunk below the allocated space. */
- if (p != end) {
- /* Valid/safe because of the prologue increment. */
- n -= SIZE_ALIGN;
- p = (char *)p + SIZE_ALIGN;
- w = MEM_TO_CHUNK(p);
- w->psize = 0 | C_INUSE;
- }
-
- /* Record new heap end and fill in footer. */
- end = (char *)p + n;
- w = MEM_TO_CHUNK(end);
- w->psize = n | C_INUSE;
- w->csize = 0 | C_INUSE;
-
- /* Fill in header, which may be new or may be replacing a
- * zero-size sentinel header at the old end-of-heap. */
- w = MEM_TO_CHUNK(p);
- w->csize = n | C_INUSE;
-
- return w;
-}
-
-static int adjust_size(size_t *n)
-{
- /* Result of pointer difference must fit in ptrdiff_t. */
- if (*n-1 > PTRDIFF_MAX - SIZE_ALIGN - PAGE_SIZE) {
- if (*n) {
- errno = ENOMEM;
- return -1;
- } else {
- *n = SIZE_ALIGN;
- return 0;
- }
- }
- *n = (*n + OVERHEAD + SIZE_ALIGN - 1) & SIZE_MASK;
- return 0;
-}
-
-static void unbin(struct chunk *c, int i)
-{
- if (c->prev == c->next)
- a_and_64(&mal.binmap, ~(1ULL<<i));
- c->prev->next = c->next;
- c->next->prev = c->prev;
- c->csize |= C_INUSE;
- NEXT_CHUNK(c)->psize |= C_INUSE;
-}
-
-static void bin_chunk(struct chunk *self, int i)
-{
- self->next = BIN_TO_CHUNK(i);
- self->prev = mal.bins[i].tail;
- self->next->prev = self;
- self->prev->next = self;
- if (self->prev == BIN_TO_CHUNK(i))
- a_or_64(&mal.binmap, 1ULL<<i);
-}
-
-static void trim(struct chunk *self, size_t n)
-{
- size_t n1 = CHUNK_SIZE(self);
- struct chunk *next, *split;
-
- if (n >= n1 - DONTCARE) return;
-
- next = NEXT_CHUNK(self);
- split = (void *)((char *)self + n);
-
- split->psize = n | C_INUSE;
- split->csize = n1-n;
- next->psize = n1-n;
- self->csize = n | C_INUSE;
-
- int i = bin_index(n1-n);
- lock_bin(i);
-
- bin_chunk(split, i);
-
- unlock_bin(i);
-}
-
-void *malloc(size_t n)
-{
- struct chunk *c;
- int i, j;
- uint64_t mask;
-
- if (adjust_size(&n) < 0) return 0;
-
- if (n > MMAP_THRESHOLD) {
- size_t len = n + OVERHEAD + PAGE_SIZE - 1 & -PAGE_SIZE;
- char *base = __mmap(0, len, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
- if (base == (void *)-1) return 0;
- c = (void *)(base + SIZE_ALIGN - OVERHEAD);
- c->csize = len - (SIZE_ALIGN - OVERHEAD);
- c->psize = SIZE_ALIGN - OVERHEAD;
- return CHUNK_TO_MEM(c);
- }
-
- i = bin_index_up(n);
- if (i<63 && (mal.binmap & (1ULL<<i))) {
- lock_bin(i);
- c = mal.bins[i].head;
- if (c != BIN_TO_CHUNK(i) && CHUNK_SIZE(c)-n <= DONTCARE) {
- unbin(c, i);
- unlock_bin(i);
- return CHUNK_TO_MEM(c);
- }
- unlock_bin(i);
- }
- lock(mal.split_merge_lock);
- for (mask = mal.binmap & -(1ULL<<i); mask; mask -= (mask&-mask)) {
- j = first_set(mask);
- lock_bin(j);
- c = mal.bins[j].head;
- if (c != BIN_TO_CHUNK(j)) {
- unbin(c, j);
- unlock_bin(j);
- break;
- }
- unlock_bin(j);
- }
- if (!mask) {
- c = expand_heap(n);
- if (!c) {
- unlock(mal.split_merge_lock);
- return 0;
- }
- }
- trim(c, n);
- unlock(mal.split_merge_lock);
- return CHUNK_TO_MEM(c);
-}
-
-int __malloc_allzerop(void *p)
-{
- return IS_MMAPPED(MEM_TO_CHUNK(p));
-}
-
-void *realloc(void *p, size_t n)
-{
- struct chunk *self, *next;
- size_t n0, n1;
- void *new;
-
- if (!p) return malloc(n);
-
- if (adjust_size(&n) < 0) return 0;
-
- self = MEM_TO_CHUNK(p);
- n1 = n0 = CHUNK_SIZE(self);
-
- if (n<=n0 && n0-n<=DONTCARE) return p;
-
- if (IS_MMAPPED(self)) {
- size_t extra = self->psize;
- char *base = (char *)self - extra;
- size_t oldlen = n0 + extra;
- size_t newlen = n + extra;
- /* Crash on realloc of freed chunk */
- if (extra & 1) a_crash();
- if (newlen < PAGE_SIZE && (new = malloc(n-OVERHEAD))) {
- n0 = n;
- goto copy_free_ret;
- }
- newlen = (newlen + PAGE_SIZE-1) & -PAGE_SIZE;
- if (oldlen == newlen) return p;
- base = __mremap(base, oldlen, newlen, MREMAP_MAYMOVE);
- if (base == (void *)-1)
- goto copy_realloc;
- self = (void *)(base + extra);
- self->csize = newlen - extra;
- return CHUNK_TO_MEM(self);
- }
-
- next = NEXT_CHUNK(self);
-
- /* Crash on corrupted footer (likely from buffer overflow) */
- if (next->psize != self->csize) a_crash();
-
- if (n < n0) {
- int i = bin_index_up(n);
- int j = bin_index(n0);
- if (i<j && (mal.binmap & (1ULL << i)))
- goto copy_realloc;
- struct chunk *split = (void *)((char *)self + n);
- self->csize = split->psize = n | C_INUSE;
- split->csize = next->psize = n0-n | C_INUSE;
- __bin_chunk(split);
- return CHUNK_TO_MEM(self);
- }
-
- lock(mal.split_merge_lock);
-
- size_t nsize = next->csize & C_INUSE ? 0 : CHUNK_SIZE(next);
- if (n0+nsize >= n) {
- int i = bin_index(nsize);
- lock_bin(i);
- if (!(next->csize & C_INUSE)) {
- unbin(next, i);
- unlock_bin(i);
- next = NEXT_CHUNK(next);
- self->csize = next->psize = n0+nsize | C_INUSE;
- trim(self, n);
- unlock(mal.split_merge_lock);
- return CHUNK_TO_MEM(self);
- }
- unlock_bin(i);
- }
- unlock(mal.split_merge_lock);
-
-copy_realloc:
- /* As a last resort, allocate a new chunk and copy to it. */
- new = malloc(n-OVERHEAD);
- if (!new) return 0;
-copy_free_ret:
- memcpy(new, p, (n<n0 ? n : n0) - OVERHEAD);
- free(CHUNK_TO_MEM(self));
- return new;
-}
-
-void __bin_chunk(struct chunk *self)
-{
- struct chunk *next = NEXT_CHUNK(self);
-
- /* Crash on corrupted footer (likely from buffer overflow) */
- if (next->psize != self->csize) a_crash();
-
- lock(mal.split_merge_lock);
-
- size_t osize = CHUNK_SIZE(self), size = osize;
-
- /* Since we hold split_merge_lock, only transition from free to
- * in-use can race; in-use to free is impossible */
- size_t psize = self->psize & C_INUSE ? 0 : CHUNK_PSIZE(self);
- size_t nsize = next->csize & C_INUSE ? 0 : CHUNK_SIZE(next);
-
- if (psize) {
- int i = bin_index(psize);
- lock_bin(i);
- if (!(self->psize & C_INUSE)) {
- struct chunk *prev = PREV_CHUNK(self);
- unbin(prev, i);
- self = prev;
- size += psize;
- }
- unlock_bin(i);
- }
- if (nsize) {
- int i = bin_index(nsize);
- lock_bin(i);
- if (!(next->csize & C_INUSE)) {
- unbin(next, i);
- next = NEXT_CHUNK(next);
- size += nsize;
- }
- unlock_bin(i);
- }
-
- int i = bin_index(size);
- lock_bin(i);
-
- self->csize = size;
- next->psize = size;
- bin_chunk(self, i);
- unlock(mal.split_merge_lock);
-
- /* Replace middle of large chunks with fresh zero pages */
- if (size > RECLAIM && (size^(size-osize)) > size-osize) {
- uintptr_t a = (uintptr_t)self + SIZE_ALIGN+PAGE_SIZE-1 & -PAGE_SIZE;
- uintptr_t b = (uintptr_t)next - SIZE_ALIGN & -PAGE_SIZE;
- int e = errno;
-#if 1
- __madvise((void *)a, b-a, MADV_DONTNEED);
-#else
- __mmap((void *)a, b-a, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0);
-#endif
- errno = e;
- }
-
- unlock_bin(i);
-}
-
-static void unmap_chunk(struct chunk *self)
-{
- size_t extra = self->psize;
- char *base = (char *)self - extra;
- size_t len = CHUNK_SIZE(self) + extra;
- /* Crash on double free */
- if (extra & 1) a_crash();
- int e = errno;
- __munmap(base, len);
- errno = e;
-}
-
-void free(void *p)
-{
- if (!p) return;
-
- struct chunk *self = MEM_TO_CHUNK(p);
-
- if (IS_MMAPPED(self))
- unmap_chunk(self);
- else
- __bin_chunk(self);
-}
-
-void __malloc_donate(char *start, char *end)
-{
- size_t align_start_up = (SIZE_ALIGN-1) & (-(uintptr_t)start - OVERHEAD);
- size_t align_end_down = (SIZE_ALIGN-1) & (uintptr_t)end;
-
- /* Getting past this condition ensures that the padding for alignment
- * and header overhead will not overflow and will leave a nonzero
- * multiple of SIZE_ALIGN bytes between start and end. */
- if (end - start <= OVERHEAD + align_start_up + align_end_down)
- return;
- start += align_start_up + OVERHEAD;
- end -= align_end_down;
-
- struct chunk *c = MEM_TO_CHUNK(start), *n = MEM_TO_CHUNK(end);
- c->psize = n->csize = C_INUSE;
- c->csize = n->psize = C_INUSE | (end-start);
- __bin_chunk(c);
-}
-
-void __malloc_atfork(int who)
-{
- if (who<0) {
- lock(mal.split_merge_lock);
- for (int i=0; i<64; i++)
- lock(mal.bins[i].lock);
- } else if (!who) {
- for (int i=0; i<64; i++)
- unlock(mal.bins[i].lock);
- unlock(mal.split_merge_lock);
- } else {
- for (int i=0; i<64; i++)
- mal.bins[i].lock[0] = mal.bins[i].lock[1] = 0;
- mal.split_merge_lock[1] = 0;
- mal.split_merge_lock[0] = 0;
- }
-}
lib/libc/wasi/libc-top-half/musl/src/malloc/oldmalloc/malloc_usable_size.c
@@ -1,9 +0,0 @@
-#include <malloc.h>
-#include "malloc_impl.h"
-
-hidden void *(*const __realloc_dep)(void *, size_t) = realloc;
-
-size_t malloc_usable_size(void *p)
-{
- return p ? CHUNK_SIZE(MEM_TO_CHUNK(p)) - OVERHEAD : 0;
-}
lib/libc/wasi/libc-top-half/musl/src/malloc/calloc.c
@@ -1,45 +0,0 @@
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <errno.h>
-#include "dynlink.h"
-
-static size_t mal0_clear(char *p, size_t n)
-{
- const size_t pagesz = 4096; /* arbitrary */
- if (n < pagesz) return n;
-#ifdef __GNUC__
- typedef uint64_t __attribute__((__may_alias__)) T;
-#else
- typedef unsigned char T;
-#endif
- char *pp = p + n;
- size_t i = (uintptr_t)pp & (pagesz - 1);
- for (;;) {
- pp = memset(pp - i, 0, i);
- if (pp - p < pagesz) return pp - p;
- for (i = pagesz; i; i -= 2*sizeof(T), pp -= 2*sizeof(T))
- if (((T *)pp)[-1] | ((T *)pp)[-2])
- break;
- }
-}
-
-static int allzerop(void *p)
-{
- return 0;
-}
-weak_alias(allzerop, __malloc_allzerop);
-
-void *calloc(size_t m, size_t n)
-{
- if (n && m > (size_t)-1/n) {
- errno = ENOMEM;
- return 0;
- }
- n *= m;
- void *p = malloc(n);
- if (!p || (!__malloc_replaced && __malloc_allzerop(p)))
- return p;
- n = mal0_clear(p, n);
- return memset(p, 0, n);
-}
lib/libc/wasi/libc-top-half/musl/src/malloc/free.c
@@ -1,6 +0,0 @@
-#include <stdlib.h>
-
-void free(void *p)
-{
- __libc_free(p);
-}
lib/libc/wasi/libc-top-half/musl/src/malloc/libc_calloc.c
@@ -1,4 +0,0 @@
-#define calloc __libc_calloc
-#define malloc __libc_malloc
-
-#include "calloc.c"
lib/libc/wasi/libc-top-half/musl/src/malloc/lite_malloc.c
@@ -1,118 +0,0 @@
-#include <stdlib.h>
-#include <stdint.h>
-#include <limits.h>
-#include <errno.h>
-#include <sys/mman.h>
-#include "libc.h"
-#include "lock.h"
-#include "syscall.h"
-#include "fork_impl.h"
-
-#define ALIGN 16
-
-/* This function returns true if the interval [old,new]
- * intersects the 'len'-sized interval below &libc.auxv
- * (interpreted as the main-thread stack) or below &b
- * (the current stack). It is used to defend against
- * buggy brk implementations that can cross the stack. */
-
-static int traverses_stack_p(uintptr_t old, uintptr_t new)
-{
- const uintptr_t len = 8<<20;
- uintptr_t a, b;
-
- b = (uintptr_t)libc.auxv;
- a = b > len ? b-len : 0;
- if (new>a && old<b) return 1;
-
- b = (uintptr_t)&b;
- a = b > len ? b-len : 0;
- if (new>a && old<b) return 1;
-
- return 0;
-}
-
-static volatile int lock[1];
-volatile int *const __bump_lockptr = lock;
-
-static void *__simple_malloc(size_t n)
-{
- static uintptr_t brk, cur, end;
- static unsigned mmap_step;
- size_t align=1;
- void *p;
-
- if (n > SIZE_MAX/2) {
- errno = ENOMEM;
- return 0;
- }
-
- if (!n) n++;
- while (align<n && align<ALIGN)
- align += align;
-
- LOCK(lock);
-
- cur += -cur & align-1;
-
- if (n > end-cur) {
- size_t req = n - (end-cur) + PAGE_SIZE-1 & -PAGE_SIZE;
-
- if (!cur) {
- brk = __syscall(SYS_brk, 0);
- brk += -brk & PAGE_SIZE-1;
- cur = end = brk;
- }
-
- if (brk == end && req < SIZE_MAX-brk
- && !traverses_stack_p(brk, brk+req)
- && __syscall(SYS_brk, brk+req)==brk+req) {
- brk = end += req;
- } else {
- int new_area = 0;
- req = n + PAGE_SIZE-1 & -PAGE_SIZE;
- /* Only make a new area rather than individual mmap
- * if wasted space would be over 1/8 of the map. */
- if (req-n > req/8) {
- /* Geometric area size growth up to 64 pages,
- * bounding waste by 1/8 of the area. */
- size_t min = PAGE_SIZE<<(mmap_step/2);
- if (min-n > end-cur) {
- if (req < min) {
- req = min;
- if (mmap_step < 12)
- mmap_step++;
- }
- new_area = 1;
- }
- }
- void *mem = __mmap(0, req, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
- if (mem == MAP_FAILED || !new_area) {
- UNLOCK(lock);
- return mem==MAP_FAILED ? 0 : mem;
- }
- cur = (uintptr_t)mem;
- end = cur + req;
- }
- }
-
- p = (void *)cur;
- cur += n;
- UNLOCK(lock);
- return p;
-}
-
-weak_alias(__simple_malloc, __libc_malloc_impl);
-
-void *__libc_malloc(size_t n)
-{
- return __libc_malloc_impl(n);
-}
-
-static void *default_malloc(size_t n)
-{
- return __libc_malloc_impl(n);
-}
-
-weak_alias(default_malloc, malloc);
lib/libc/wasi/libc-top-half/musl/src/malloc/memalign.c
@@ -1,7 +0,0 @@
-#define _BSD_SOURCE
-#include <stdlib.h>
-
-void *memalign(size_t align, size_t len)
-{
- return aligned_alloc(align, len);
-}
lib/libc/wasi/libc-top-half/musl/src/malloc/posix_memalign.c
@@ -1,11 +0,0 @@
-#include <stdlib.h>
-#include <errno.h>
-
-int posix_memalign(void **res, size_t align, size_t len)
-{
- if (align < sizeof(void *)) return EINVAL;
- void *mem = aligned_alloc(align, len);
- if (!mem) return errno;
- *res = mem;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/malloc/realloc.c
@@ -1,6 +0,0 @@
-#include <stdlib.h>
-
-void *realloc(void *p, size_t n)
-{
- return __libc_realloc(p, n);
-}
lib/libc/wasi/libc-top-half/musl/src/malloc/reallocarray.c
@@ -1,13 +0,0 @@
-#define _BSD_SOURCE
-#include <errno.h>
-#include <stdlib.h>
-
-void *reallocarray(void *ptr, size_t m, size_t n)
-{
- if (n && m > -1 / n) {
- errno = ENOMEM;
- return 0;
- }
-
- return realloc(ptr, m * n);
-}
lib/libc/wasi/libc-top-half/musl/src/malloc/replaced.c
@@ -1,4 +0,0 @@
-#include "dynlink.h"
-
-int __malloc_replaced;
-int __aligned_alloc_replaced;
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/ceil.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double ceil(double x)
-{
- __asm__ ("frintp %d0, %d1" : "=w"(x) : "w"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/ceilf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float ceilf(float x)
-{
- __asm__ ("frintp %s0, %s1" : "=w"(x) : "w"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fabs.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double fabs(double x)
-{
- __asm__ ("fabs %d0, %d1" : "=w"(x) : "w"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fabsf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float fabsf(float x)
-{
- __asm__ ("fabs %s0, %s1" : "=w"(x) : "w"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/floor.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double floor(double x)
-{
- __asm__ ("frintm %d0, %d1" : "=w"(x) : "w"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/floorf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float floorf(float x)
-{
- __asm__ ("frintm %s0, %s1" : "=w"(x) : "w"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fma.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double fma(double x, double y, double z)
-{
- __asm__ ("fmadd %d0, %d1, %d2, %d3" : "=w"(x) : "w"(x), "w"(y), "w"(z));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fmaf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float fmaf(float x, float y, float z)
-{
- __asm__ ("fmadd %s0, %s1, %s2, %s3" : "=w"(x) : "w"(x), "w"(y), "w"(z));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fmax.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double fmax(double x, double y)
-{
- __asm__ ("fmaxnm %d0, %d1, %d2" : "=w"(x) : "w"(x), "w"(y));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fmaxf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float fmaxf(float x, float y)
-{
- __asm__ ("fmaxnm %s0, %s1, %s2" : "=w"(x) : "w"(x), "w"(y));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fmin.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double fmin(double x, double y)
-{
- __asm__ ("fminnm %d0, %d1, %d2" : "=w"(x) : "w"(x), "w"(y));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fminf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float fminf(float x, float y)
-{
- __asm__ ("fminnm %s0, %s1, %s2" : "=w"(x) : "w"(x), "w"(y));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/llrint.c
@@ -1,10 +0,0 @@
-#include <math.h>
-
-long long llrint(double x)
-{
- long long n;
- __asm__ (
- "frintx %d1, %d1\n"
- "fcvtzs %x0, %d1\n" : "=r"(n), "+w"(x));
- return n;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/llrintf.c
@@ -1,10 +0,0 @@
-#include <math.h>
-
-long long llrintf(float x)
-{
- long long n;
- __asm__ (
- "frintx %s1, %s1\n"
- "fcvtzs %x0, %s1\n" : "=r"(n), "+w"(x));
- return n;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/llround.c
@@ -1,8 +0,0 @@
-#include <math.h>
-
-long long llround(double x)
-{
- long long n;
- __asm__ ("fcvtas %x0, %d1" : "=r"(n) : "w"(x));
- return n;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/llroundf.c
@@ -1,8 +0,0 @@
-#include <math.h>
-
-long long llroundf(float x)
-{
- long long n;
- __asm__ ("fcvtas %x0, %s1" : "=r"(n) : "w"(x));
- return n;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/lrint.c
@@ -1,10 +0,0 @@
-#include <math.h>
-
-long lrint(double x)
-{
- long n;
- __asm__ (
- "frintx %d1, %d1\n"
- "fcvtzs %x0, %d1\n" : "=r"(n), "+w"(x));
- return n;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/lrintf.c
@@ -1,10 +0,0 @@
-#include <math.h>
-
-long lrintf(float x)
-{
- long n;
- __asm__ (
- "frintx %s1, %s1\n"
- "fcvtzs %x0, %s1\n" : "=r"(n), "+w"(x));
- return n;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/lround.c
@@ -1,8 +0,0 @@
-#include <math.h>
-
-long lround(double x)
-{
- long n;
- __asm__ ("fcvtas %x0, %d1" : "=r"(n) : "w"(x));
- return n;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/lroundf.c
@@ -1,8 +0,0 @@
-#include <math.h>
-
-long lroundf(float x)
-{
- long n;
- __asm__ ("fcvtas %x0, %s1" : "=r"(n) : "w"(x));
- return n;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/nearbyint.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double nearbyint(double x)
-{
- __asm__ ("frinti %d0, %d1" : "=w"(x) : "w"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/nearbyintf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float nearbyintf(float x)
-{
- __asm__ ("frinti %s0, %s1" : "=w"(x) : "w"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/rint.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double rint(double x)
-{
- __asm__ ("frintx %d0, %d1" : "=w"(x) : "w"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/rintf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float rintf(float x)
-{
- __asm__ ("frintx %s0, %s1" : "=w"(x) : "w"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/round.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double round(double x)
-{
- __asm__ ("frinta %d0, %d1" : "=w"(x) : "w"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/roundf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float roundf(float x)
-{
- __asm__ ("frinta %s0, %s1" : "=w"(x) : "w"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/sqrt.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double sqrt(double x)
-{
- __asm__ ("fsqrt %d0, %d1" : "=w"(x) : "w"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/sqrtf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float sqrtf(float x)
-{
- __asm__ ("fsqrt %s0, %s1" : "=w"(x) : "w"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/trunc.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double trunc(double x)
-{
- __asm__ ("frintz %d0, %d1" : "=w"(x) : "w"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/truncf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float truncf(float x)
-{
- __asm__ ("frintz %s0, %s1" : "=w"(x) : "w"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/arm/fabs.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if __ARM_PCS_VFP && __ARM_FP&8
-
-double fabs(double x)
-{
- __asm__ ("vabs.f64 %P0, %P1" : "=w"(x) : "w"(x));
- return x;
-}
-
-#else
-
-#include "../fabs.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/arm/fabsf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if __ARM_PCS_VFP && !BROKEN_VFP_ASM
-
-float fabsf(float x)
-{
- __asm__ ("vabs.f32 %0, %1" : "=t"(x) : "t"(x));
- return x;
-}
-
-#else
-
-#include "../fabsf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/arm/fma.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if __ARM_FEATURE_FMA && __ARM_FP&8 && !__SOFTFP__
-
-double fma(double x, double y, double z)
-{
- __asm__ ("vfma.f64 %P0, %P1, %P2" : "+w"(z) : "w"(x), "w"(y));
- return z;
-}
-
-#else
-
-#include "../fma.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/arm/fmaf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if __ARM_FEATURE_FMA && __ARM_FP&4 && !__SOFTFP__ && !BROKEN_VFP_ASM
-
-float fmaf(float x, float y, float z)
-{
- __asm__ ("vfma.f32 %0, %1, %2" : "+t"(z) : "t"(x), "t"(y));
- return z;
-}
-
-#else
-
-#include "../fmaf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/arm/sqrt.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if (__ARM_PCS_VFP || (__VFP_FP__ && !__SOFTFP__)) && (__ARM_FP&8)
-
-double sqrt(double x)
-{
- __asm__ ("vsqrt.f64 %P0, %P1" : "=w"(x) : "w"(x));
- return x;
-}
-
-#else
-
-#include "../sqrt.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/arm/sqrtf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if (__ARM_PCS_VFP || (__VFP_FP__ && !__SOFTFP__)) && !BROKEN_VFP_ASM
-
-float sqrtf(float x)
-{
- __asm__ ("vsqrt.f32 %0, %1" : "=t"(x) : "t"(x));
- return x;
-}
-
-#else
-
-#include "../sqrtf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/i386/__invtrigl.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/acos.s
@@ -1,18 +0,0 @@
-# use acos(x) = atan2(fabs(sqrt((1-x)*(1+x))), x)
-
-.global acos
-.type acos,@function
-acos:
- fldl 4(%esp)
- fld %st(0)
- fld1
- fsub %st(0),%st(1)
- fadd %st(2)
- fmulp
- fsqrt
- fabs # fix sign of zero (matters in downward rounding mode)
- fxch %st(1)
- fpatan
- fstpl 4(%esp)
- fldl 4(%esp)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/acosf.s
@@ -1,16 +0,0 @@
-.global acosf
-.type acosf,@function
-acosf:
- flds 4(%esp)
- fld %st(0)
- fld1
- fsub %st(0),%st(1)
- fadd %st(2)
- fmulp
- fsqrt
- fabs # fix sign of zero (matters in downward rounding mode)
- fxch %st(1)
- fpatan
- fstps 4(%esp)
- flds 4(%esp)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/acosl.s
@@ -1,14 +0,0 @@
-.global acosl
-.type acosl,@function
-acosl:
- fldt 4(%esp)
- fld %st(0)
- fld1
- fsub %st(0),%st(1)
- fadd %st(2)
- fmulp
- fsqrt
- fabs # fix sign of zero (matters in downward rounding mode)
- fxch %st(1)
- fpatan
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/asin.s
@@ -1,21 +0,0 @@
-.global asin
-.type asin,@function
-asin:
- fldl 4(%esp)
- mov 8(%esp),%eax
- add %eax,%eax
- cmp $0x00200000,%eax
- jb 1f
- fld %st(0)
- fld1
- fsub %st(0),%st(1)
- fadd %st(2)
- fmulp
- fsqrt
- fpatan
- fstpl 4(%esp)
- fldl 4(%esp)
- ret
- # subnormal x, return x with underflow
-1: fsts 4(%esp)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/asinf.s
@@ -1,23 +0,0 @@
-.global asinf
-.type asinf,@function
-asinf:
- flds 4(%esp)
- mov 4(%esp),%eax
- add %eax,%eax
- cmp $0x01000000,%eax
- jb 1f
- fld %st(0)
- fld1
- fsub %st(0),%st(1)
- fadd %st(2)
- fmulp
- fsqrt
- fpatan
- fstps 4(%esp)
- flds 4(%esp)
- ret
- # subnormal x, return x with underflow
-1: fld %st(0)
- fmul %st(1)
- fstps 4(%esp)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/asinl.s
@@ -1,12 +0,0 @@
-.global asinl
-.type asinl,@function
-asinl:
- fldt 4(%esp)
- fld %st(0)
- fld1
- fsub %st(0),%st(1)
- fadd %st(2)
- fmulp
- fsqrt
- fpatan
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/atan.s
@@ -1,16 +0,0 @@
-.global atan
-.type atan,@function
-atan:
- fldl 4(%esp)
- mov 8(%esp),%eax
- add %eax,%eax
- cmp $0x00200000,%eax
- jb 1f
- fld1
- fpatan
- fstpl 4(%esp)
- fldl 4(%esp)
- ret
- # subnormal x, return x with underflow
-1: fsts 4(%esp)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/atan2.s
@@ -1,15 +0,0 @@
-.global atan2
-.type atan2,@function
-atan2:
- fldl 4(%esp)
- fldl 12(%esp)
- fpatan
- fstpl 4(%esp)
- fldl 4(%esp)
- mov 8(%esp),%eax
- add %eax,%eax
- cmp $0x00200000,%eax
- jae 1f
- # subnormal x, return x with underflow
- fsts 4(%esp)
-1: ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/atan2f.s
@@ -1,17 +0,0 @@
-.global atan2f
-.type atan2f,@function
-atan2f:
- flds 4(%esp)
- flds 8(%esp)
- fpatan
- fstps 4(%esp)
- flds 4(%esp)
- mov 4(%esp),%eax
- add %eax,%eax
- cmp $0x01000000,%eax
- jae 1f
- # subnormal x, return x with underflow
- fld %st(0)
- fmul %st(1)
- fstps 4(%esp)
-1: ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/atan2l.s
@@ -1,7 +0,0 @@
-.global atan2l
-.type atan2l,@function
-atan2l:
- fldt 4(%esp)
- fldt 16(%esp)
- fpatan
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/atanf.s
@@ -1,18 +0,0 @@
-.global atanf
-.type atanf,@function
-atanf:
- flds 4(%esp)
- mov 4(%esp),%eax
- add %eax,%eax
- cmp $0x01000000,%eax
- jb 1f
- fld1
- fpatan
- fstps 4(%esp)
- flds 4(%esp)
- ret
- # subnormal x, return x with underflow
-1: fld %st(0)
- fmul %st(1)
- fstps 4(%esp)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/atanl.s
@@ -1,7 +0,0 @@
-.global atanl
-.type atanl,@function
-atanl:
- fldt 4(%esp)
- fld1
- fpatan
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/ceil.s
@@ -1,1 +0,0 @@
-# see floor.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/ceilf.s
@@ -1,1 +0,0 @@
-# see floor.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/ceill.s
@@ -1,1 +0,0 @@
-# see floor.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/exp2l.s
@@ -1,1 +0,0 @@
-# see exp_ld.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/exp_ld.s
@@ -1,93 +0,0 @@
-.global expm1l
-.type expm1l,@function
-expm1l:
- fldt 4(%esp)
- fldl2e
- fmulp
- mov $0xc2820000,%eax
- push %eax
- flds (%esp)
- pop %eax
- fucomp %st(1)
- fnstsw %ax
- sahf
- fld1
- jb 1f
- # x*log2e < -65, return -1 without underflow
- fstp %st(1)
- fchs
- ret
-1: fld %st(1)
- fabs
- fucom %st(1)
- fnstsw %ax
- fstp %st(0)
- fstp %st(0)
- sahf
- ja 1f
- f2xm1
- ret
-1: call 1f
- fld1
- fsubrp
- ret
-
-.global exp2l
-.global __exp2l
-.hidden __exp2l
-.type exp2l,@function
-exp2l:
-__exp2l:
- fldt 4(%esp)
-1: sub $12,%esp
- fld %st(0)
- fstpt (%esp)
- mov 8(%esp),%ax
- and $0x7fff,%ax
- cmp $0x3fff+13,%ax
- jb 4f # |x| < 8192
- cmp $0x3fff+15,%ax
- jae 3f # |x| >= 32768
- fsts (%esp)
- cmpl $0xc67ff800,(%esp)
- jb 2f # x > -16382
- movl $0x5f000000,(%esp)
- flds (%esp) # 0x1p63
- fld %st(1)
- fsub %st(1)
- faddp
- fucomp %st(1)
- fnstsw
- sahf
- je 2f # x - 0x1p63 + 0x1p63 == x
- movl $1,(%esp)
- flds (%esp) # 0x1p-149
- fdiv %st(1)
- fstps (%esp) # raise underflow
-2: fld1
- fld %st(1)
- frndint
- fxch %st(2)
- fsub %st(2) # st(0)=x-rint(x), st(1)=1, st(2)=rint(x)
- f2xm1
- faddp # 2^(x-rint(x))
-1: fscale
- fstp %st(1)
- add $12,%esp
- ret
-3: xor %eax,%eax
-4: cmp $0x3fff-64,%ax
- fld1
- jb 1b # |x| < 0x1p-64
- fstpt (%esp)
- fistl 8(%esp)
- fildl 8(%esp)
- fsubrp %st(1)
- addl $0x3fff,8(%esp)
- f2xm1
- fld1
- faddp # 2^(x-rint(x))
- fldt (%esp) # 2^rint(x)
- fmulp
- add $12,%esp
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/expl.s
@@ -1,101 +0,0 @@
-# exp(x) = 2^hi + 2^hi (2^lo - 1)
-# where hi+lo = log2e*x with 128bit precision
-# exact log2e*x calculation depends on nearest rounding mode
-# using the exact multiplication method of Dekker and Veltkamp
-
-.global expl
-.type expl,@function
-expl:
- fldt 4(%esp)
-
- # interesting case: 0x1p-32 <= |x| < 16384
- # check if (exponent|0x8000) is in [0xbfff-32, 0xbfff+13]
- mov 12(%esp), %ax
- or $0x8000, %ax
- sub $0xbfdf, %ax
- cmp $45, %ax
- jbe 2f
- test %ax, %ax
- fld1
- js 1f
- # if |x|>=0x1p14 or nan return 2^trunc(x)
- fscale
- fstp %st(1)
- ret
- # if |x|<0x1p-32 return 1+x
-1: faddp
- ret
-
- # should be 0x1.71547652b82fe178p0L == 0x3fff b8aa3b29 5c17f0bc
- # it will be wrong on non-nearest rounding mode
-2: fldl2e
- subl $44, %esp
- # hi = log2e_hi*x
- # 2^hi = exp2l(hi)
- fmul %st(1),%st
- fld %st(0)
- fstpt (%esp)
- fstpt 16(%esp)
- fstpt 32(%esp)
-.hidden __exp2l
- call __exp2l
- # if 2^hi == inf return 2^hi
- fld %st(0)
- fstpt (%esp)
- cmpw $0x7fff, 8(%esp)
- je 1f
- fldt 32(%esp)
- fldt 16(%esp)
- # fpu stack: 2^hi x hi
- # exact mult: x*log2e
- fld %st(1)
- # c = 0x1p32+1
- pushl $0x41f00000
- pushl $0x00100000
- fldl (%esp)
- # xh = x - c*x + c*x
- # xl = x - xh
- fmulp
- fld %st(2)
- fsub %st(1), %st
- faddp
- fld %st(2)
- fsub %st(1), %st
- # yh = log2e_hi - c*log2e_hi + c*log2e_hi
- pushl $0x3ff71547
- pushl $0x65200000
- fldl (%esp)
- # fpu stack: 2^hi x hi xh xl yh
- # lo = hi - xh*yh + xl*yh
- fld %st(2)
- fmul %st(1), %st
- fsubp %st, %st(4)
- fmul %st(1), %st
- faddp %st, %st(3)
- # yl = log2e_hi - yh
- pushl $0x3de705fc
- pushl $0x2f000000
- fldl (%esp)
- # fpu stack: 2^hi x lo xh xl yl
- # lo += xh*yl + xl*yl
- fmul %st, %st(2)
- fmulp %st, %st(1)
- fxch %st(2)
- faddp
- faddp
- # log2e_lo
- pushl $0xbfbe
- pushl $0x82f0025f
- pushl $0x2dc582ee
- fldt (%esp)
- addl $36,%esp
- # fpu stack: 2^hi x lo log2e_lo
- # lo += log2e_lo*x
- # return 2^hi + 2^hi (2^lo - 1)
- fmulp %st, %st(2)
- faddp
- f2xm1
- fmul %st(1), %st
- faddp
-1: addl $44, %esp
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/expm1l.s
@@ -1,1 +0,0 @@
-# see exp_ld.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/fabs.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double fabs(double x)
-{
- __asm__ ("fabs" : "+t"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/fabsf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float fabsf(float x)
-{
- __asm__ ("fabs" : "+t"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/fabsl.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-long double fabsl(long double x)
-{
- __asm__ ("fabs" : "+t"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/floor.s
@@ -1,67 +0,0 @@
-.global floorf
-.type floorf,@function
-floorf:
- flds 4(%esp)
- jmp 1f
-
-.global floorl
-.type floorl,@function
-floorl:
- fldt 4(%esp)
- jmp 1f
-
-.global floor
-.type floor,@function
-floor:
- fldl 4(%esp)
-1: mov $0x7,%al
-1: fstcw 4(%esp)
- mov 5(%esp),%ah
- mov %al,5(%esp)
- fldcw 4(%esp)
- frndint
- mov %ah,5(%esp)
- fldcw 4(%esp)
- ret
-
-.global ceil
-.type ceil,@function
-ceil:
- fldl 4(%esp)
- mov $0xb,%al
- jmp 1b
-
-.global ceilf
-.type ceilf,@function
-ceilf:
- flds 4(%esp)
- mov $0xb,%al
- jmp 1b
-
-.global ceill
-.type ceill,@function
-ceill:
- fldt 4(%esp)
- mov $0xb,%al
- jmp 1b
-
-.global trunc
-.type trunc,@function
-trunc:
- fldl 4(%esp)
- mov $0xf,%al
- jmp 1b
-
-.global truncf
-.type truncf,@function
-truncf:
- flds 4(%esp)
- mov $0xf,%al
- jmp 1b
-
-.global truncl
-.type truncl,@function
-truncl:
- fldt 4(%esp)
- mov $0xf,%al
- jmp 1b
lib/libc/wasi/libc-top-half/musl/src/math/i386/floorf.s
@@ -1,1 +0,0 @@
-# see floor.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/floorl.s
@@ -1,1 +0,0 @@
-# see floor.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/fmod.c
@@ -1,10 +0,0 @@
-#include <math.h>
-
-double fmod(double x, double y)
-{
- unsigned short fpsr;
- // fprem does not introduce excess precision into x
- do __asm__ ("fprem; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y));
- while (fpsr & 0x400);
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/fmodf.c
@@ -1,10 +0,0 @@
-#include <math.h>
-
-float fmodf(float x, float y)
-{
- unsigned short fpsr;
- // fprem does not introduce excess precision into x
- do __asm__ ("fprem; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y));
- while (fpsr & 0x400);
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/fmodl.c
@@ -1,9 +0,0 @@
-#include <math.h>
-
-long double fmodl(long double x, long double y)
-{
- unsigned short fpsr;
- do __asm__ ("fprem; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y));
- while (fpsr & 0x400);
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/hypot.s
@@ -1,45 +0,0 @@
-.global hypot
-.type hypot,@function
-hypot:
- mov 8(%esp),%eax
- mov 16(%esp),%ecx
- add %eax,%eax
- add %ecx,%ecx
- and %eax,%ecx
- cmp $0xffe00000,%ecx
- jae 2f
- or 4(%esp),%eax
- jnz 1f
- fldl 12(%esp)
- fabs
- ret
-1: mov 16(%esp),%eax
- add %eax,%eax
- or 12(%esp),%eax
- jnz 1f
- fldl 4(%esp)
- fabs
- ret
-1: fldl 4(%esp)
- fld %st(0)
- fmulp
- fldl 12(%esp)
- fld %st(0)
- fmulp
- faddp
- fsqrt
- ret
-2: sub $0xffe00000,%eax
- or 4(%esp),%eax
- jnz 1f
- fldl 4(%esp)
- fabs
- ret
-1: mov 16(%esp),%eax
- add %eax,%eax
- sub $0xffe00000,%eax
- or 12(%esp),%eax
- fldl 12(%esp)
- jnz 1f
- fabs
-1: ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/hypotf.s
@@ -1,42 +0,0 @@
-.global hypotf
-.type hypotf,@function
-hypotf:
- mov 4(%esp),%eax
- mov 8(%esp),%ecx
- add %eax,%eax
- add %ecx,%ecx
- and %eax,%ecx
- cmp $0xff000000,%ecx
- jae 2f
- test %eax,%eax
- jnz 1f
- flds 8(%esp)
- fabs
- ret
-1: mov 8(%esp),%eax
- add %eax,%eax
- jnz 1f
- flds 4(%esp)
- fabs
- ret
-1: flds 4(%esp)
- fld %st(0)
- fmulp
- flds 8(%esp)
- fld %st(0)
- fmulp
- faddp
- fsqrt
- ret
-2: cmp $0xff000000,%eax
- jnz 1f
- flds 4(%esp)
- fabs
- ret
-1: mov 8(%esp),%eax
- add %eax,%eax
- cmp $0xff000000,%eax
- flds 8(%esp)
- jnz 1f
- fabs
-1: ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/ldexp.s
@@ -1,1 +0,0 @@
-# see scalbn.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/ldexpf.s
@@ -1,1 +0,0 @@
-# see scalbnf.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/ldexpl.s
@@ -1,1 +0,0 @@
-# see scalbnl.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/llrint.c
@@ -1,8 +0,0 @@
-#include <math.h>
-
-long long llrint(double x)
-{
- long long r;
- __asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st");
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/llrintf.c
@@ -1,8 +0,0 @@
-#include <math.h>
-
-long long llrintf(float x)
-{
- long long r;
- __asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st");
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/llrintl.c
@@ -1,8 +0,0 @@
-#include <math.h>
-
-long long llrintl(long double x)
-{
- long long r;
- __asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st");
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/log.s
@@ -1,9 +0,0 @@
-.global log
-.type log,@function
-log:
- fldln2
- fldl 4(%esp)
- fyl2x
- fstpl 4(%esp)
- fldl 4(%esp)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/log10.s
@@ -1,9 +0,0 @@
-.global log10
-.type log10,@function
-log10:
- fldlg2
- fldl 4(%esp)
- fyl2x
- fstpl 4(%esp)
- fldl 4(%esp)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/log10f.s
@@ -1,9 +0,0 @@
-.global log10f
-.type log10f,@function
-log10f:
- fldlg2
- flds 4(%esp)
- fyl2x
- fstps 4(%esp)
- flds 4(%esp)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/log10l.s
@@ -1,7 +0,0 @@
-.global log10l
-.type log10l,@function
-log10l:
- fldlg2
- fldt 4(%esp)
- fyl2x
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/log1p.s
@@ -1,25 +0,0 @@
-.global log1p
-.type log1p,@function
-log1p:
- mov 8(%esp),%eax
- fldln2
- and $0x7fffffff,%eax
- fldl 4(%esp)
- cmp $0x3fd28f00,%eax
- ja 1f
- cmp $0x00100000,%eax
- jb 2f
- fyl2xp1
- fstpl 4(%esp)
- fldl 4(%esp)
- ret
-1: fld1
- faddp
- fyl2x
- fstpl 4(%esp)
- fldl 4(%esp)
- ret
- # subnormal x, return x with underflow
-2: fsts 4(%esp)
- fstp %st(1)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/log1pf.s
@@ -1,26 +0,0 @@
-.global log1pf
-.type log1pf,@function
-log1pf:
- mov 4(%esp),%eax
- fldln2
- and $0x7fffffff,%eax
- flds 4(%esp)
- cmp $0x3e940000,%eax
- ja 1f
- cmp $0x00800000,%eax
- jb 2f
- fyl2xp1
- fstps 4(%esp)
- flds 4(%esp)
- ret
-1: fld1
- faddp
- fyl2x
- fstps 4(%esp)
- flds 4(%esp)
- ret
- # subnormal x, return x with underflow
-2: fxch
- fmul %st(1)
- fstps 4(%esp)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/log1pl.s
@@ -1,15 +0,0 @@
-.global log1pl
-.type log1pl,@function
-log1pl:
- mov 10(%esp),%eax
- fldln2
- and $0x7fffffff,%eax
- fldt 4(%esp)
- cmp $0x3ffd9400,%eax
- ja 1f
- fyl2xp1
- ret
-1: fld1
- faddp
- fyl2x
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/log2.s
@@ -1,9 +0,0 @@
-.global log2
-.type log2,@function
-log2:
- fld1
- fldl 4(%esp)
- fyl2x
- fstpl 4(%esp)
- fldl 4(%esp)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/log2f.s
@@ -1,9 +0,0 @@
-.global log2f
-.type log2f,@function
-log2f:
- fld1
- flds 4(%esp)
- fyl2x
- fstps 4(%esp)
- flds 4(%esp)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/log2l.s
@@ -1,7 +0,0 @@
-.global log2l
-.type log2l,@function
-log2l:
- fld1
- fldt 4(%esp)
- fyl2x
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/logf.s
@@ -1,9 +0,0 @@
-.global logf
-.type logf,@function
-logf:
- fldln2
- flds 4(%esp)
- fyl2x
- fstps 4(%esp)
- flds 4(%esp)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/logl.s
@@ -1,7 +0,0 @@
-.global logl
-.type logl,@function
-logl:
- fldln2
- fldt 4(%esp)
- fyl2x
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/lrint.c
@@ -1,8 +0,0 @@
-#include <math.h>
-
-long lrint(double x)
-{
- long r;
- __asm__ ("fistpl %0" : "=m"(r) : "t"(x) : "st");
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/lrintf.c
@@ -1,8 +0,0 @@
-#include <math.h>
-
-long lrintf(float x)
-{
- long r;
- __asm__ ("fistpl %0" : "=m"(r) : "t"(x) : "st");
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/lrintl.c
@@ -1,8 +0,0 @@
-#include <math.h>
-
-long lrintl(long double x)
-{
- long r;
- __asm__ ("fistpl %0" : "=m"(r) : "t"(x) : "st");
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/remainder.c
@@ -1,12 +0,0 @@
-#include <math.h>
-
-double remainder(double x, double y)
-{
- unsigned short fpsr;
- // fprem1 does not introduce excess precision into x
- do __asm__ ("fprem1; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y));
- while (fpsr & 0x400);
- return x;
-}
-
-weak_alias(remainder, drem);
lib/libc/wasi/libc-top-half/musl/src/math/i386/remainderf.c
@@ -1,12 +0,0 @@
-#include <math.h>
-
-float remainderf(float x, float y)
-{
- unsigned short fpsr;
- // fprem1 does not introduce excess precision into x
- do __asm__ ("fprem1; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y));
- while (fpsr & 0x400);
- return x;
-}
-
-weak_alias(remainderf, dremf);
lib/libc/wasi/libc-top-half/musl/src/math/i386/remainderl.c
@@ -1,9 +0,0 @@
-#include <math.h>
-
-long double remainderl(long double x, long double y)
-{
- unsigned short fpsr;
- do __asm__ ("fprem1; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y));
- while (fpsr & 0x400);
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/remquo.s
@@ -1,50 +0,0 @@
-.global remquof
-.type remquof,@function
-remquof:
- mov 12(%esp),%ecx
- flds 8(%esp)
- flds 4(%esp)
- mov 11(%esp),%dh
- xor 7(%esp),%dh
- jmp 1f
-
-.global remquol
-.type remquol,@function
-remquol:
- mov 28(%esp),%ecx
- fldt 16(%esp)
- fldt 4(%esp)
- mov 25(%esp),%dh
- xor 13(%esp),%dh
- jmp 1f
-
-.global remquo
-.type remquo,@function
-remquo:
- mov 20(%esp),%ecx
- fldl 12(%esp)
- fldl 4(%esp)
- mov 19(%esp),%dh
- xor 11(%esp),%dh
-1: fprem1
- fnstsw %ax
- sahf
- jp 1b
- fstp %st(1)
- mov %ah,%dl
- shr %dl
- and $1,%dl
- mov %ah,%al
- shr $5,%al
- and $2,%al
- or %al,%dl
- mov %ah,%al
- shl $2,%al
- and $4,%al
- or %al,%dl
- test %dh,%dh
- jns 1f
- neg %dl
-1: movsbl %dl,%edx
- mov %edx,(%ecx)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/remquof.s
@@ -1,1 +0,0 @@
-# see remquo.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/remquol.s
@@ -1,1 +0,0 @@
-# see remquo.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/rint.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double rint(double x)
-{
- __asm__ ("frndint" : "+t"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/rintf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float rintf(float x)
-{
- __asm__ ("frndint" : "+t"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/rintl.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-long double rintl(long double x)
-{
- __asm__ ("frndint" : "+t"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/scalbln.s
@@ -1,1 +0,0 @@
-# see scalbn.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/scalblnf.s
@@ -1,1 +0,0 @@
-# see scalbnf.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/scalblnl.s
@@ -1,1 +0,0 @@
-# see scalbnl.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/scalbn.s
@@ -1,33 +0,0 @@
-.global ldexp
-.type ldexp,@function
-ldexp:
- nop
-
-.global scalbln
-.type scalbln,@function
-scalbln:
- nop
-
-.global scalbn
-.type scalbn,@function
-scalbn:
- mov 12(%esp),%eax
- add $0x3ffe,%eax
- cmp $0x7ffd,%eax
- jb 1f
- sub $0x3ffe,%eax
- sar $31,%eax
- xor $0xfff,%eax
- add $0x3ffe,%eax
-1: inc %eax
- fldl 4(%esp)
- mov %eax,12(%esp)
- mov $0x80000000,%eax
- mov %eax,8(%esp)
- xor %eax,%eax
- mov %eax,4(%esp)
- fldt 4(%esp)
- fmulp
- fstpl 4(%esp)
- fldl 4(%esp)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/scalbnf.s
@@ -1,32 +0,0 @@
-.global ldexpf
-.type ldexpf,@function
-ldexpf:
- nop
-
-.global scalblnf
-.type scalblnf,@function
-scalblnf:
- nop
-
-.global scalbnf
-.type scalbnf,@function
-scalbnf:
- mov 8(%esp),%eax
- add $0x3fe,%eax
- cmp $0x7fd,%eax
- jb 1f
- sub $0x3fe,%eax
- sar $31,%eax
- xor $0x1ff,%eax
- add $0x3fe,%eax
-1: inc %eax
- shl $20,%eax
- flds 4(%esp)
- mov %eax,8(%esp)
- xor %eax,%eax
- mov %eax,4(%esp)
- fldl 4(%esp)
- fmulp
- fstps 4(%esp)
- flds 4(%esp)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/scalbnl.s
@@ -1,32 +0,0 @@
-.global ldexpl
-.type ldexpl,@function
-ldexpl:
- nop
-
-.global scalblnl
-.type scalblnl,@function
-scalblnl:
- nop
-
-.global scalbnl
-.type scalbnl,@function
-scalbnl:
- mov 16(%esp),%eax
- add $0x3ffe,%eax
- cmp $0x7ffd,%eax
- jae 1f
- inc %eax
- fldt 4(%esp)
- mov %eax,12(%esp)
- mov $0x80000000,%eax
- mov %eax,8(%esp)
- xor %eax,%eax
- mov %eax,4(%esp)
- fldt 4(%esp)
- fmulp
- ret
-1: fildl 16(%esp)
- fldt 4(%esp)
- fscale
- fstp %st(1)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/sqrt.c
@@ -1,15 +0,0 @@
-#include "libm.h"
-
-double sqrt(double x)
-{
- union ldshape ux;
- unsigned fpsr;
- __asm__ ("fsqrt; fnstsw %%ax": "=t"(ux.f), "=a"(fpsr) : "0"(x));
- if ((ux.i.m & 0x7ff) != 0x400)
- return (double)ux.f;
- /* Rounding to double would have encountered an exact halfway case.
- Adjust mantissa downwards if fsqrt rounded up, else upwards.
- (result of fsqrt could not have been exact) */
- ux.i.m ^= (fpsr & 0x200) + 0x300;
- return (double)ux.f;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/sqrtf.c
@@ -1,12 +0,0 @@
-#include <math.h>
-
-float sqrtf(float x)
-{
- long double t;
- /* The long double result has sufficient precision so that
- * second rounding to float still keeps the returned value
- * correctly rounded, see Pierre Roux, "Innocuous Double
- * Rounding of Basic Arithmetic Operations". */
- __asm__ ("fsqrt" : "=t"(t) : "0"(x));
- return (float)t;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/sqrtl.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-long double sqrtl(long double x)
-{
- __asm__ ("fsqrt" : "+t"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/i386/trunc.s
@@ -1,1 +0,0 @@
-# see floor.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/truncf.s
@@ -1,1 +0,0 @@
-# see floor.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/truncl.s
@@ -1,1 +0,0 @@
-# see floor.s
lib/libc/wasi/libc-top-half/musl/src/math/m68k/sqrtl.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if __HAVE_68881__
-
-long double sqrtl(long double x)
-{
- __asm__ ("fsqrt.x %1,%0" : "=f"(x) : "fm"(x));
- return x;
-}
-
-#else
-
-#include "../sqrtl.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/mips/fabs.c
@@ -1,16 +0,0 @@
-#if !defined(__mips_soft_float) && defined(__mips_abs2008)
-
-#include <math.h>
-
-double fabs(double x)
-{
- double r;
- __asm__("abs.d %0,%1" : "=f"(r) : "f"(x));
- return r;
-}
-
-#else
-
-#include "../fabs.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/mips/fabsf.c
@@ -1,16 +0,0 @@
-#if !defined(__mips_soft_float) && defined(__mips_abs2008)
-
-#include <math.h>
-
-float fabsf(float x)
-{
- float r;
- __asm__("abs.s %0,%1" : "=f"(r) : "f"(x));
- return r;
-}
-
-#else
-
-#include "../fabsf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/mips/sqrt.c
@@ -1,16 +0,0 @@
-#if !defined(__mips_soft_float) && __mips >= 3
-
-#include <math.h>
-
-double sqrt(double x)
-{
- double r;
- __asm__("sqrt.d %0,%1" : "=f"(r) : "f"(x));
- return r;
-}
-
-#else
-
-#include "../sqrt.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/mips/sqrtf.c
@@ -1,16 +0,0 @@
-#if !defined(__mips_soft_float) && __mips >= 2
-
-#include <math.h>
-
-float sqrtf(float x)
-{
- float r;
- __asm__("sqrt.s %0,%1" : "=f"(r) : "f"(x));
- return r;
-}
-
-#else
-
-#include "../sqrtf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/fabs.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__) || defined(BROKEN_PPC_D_ASM)
-
-#include "../fabs.c"
-
-#else
-
-double fabs(double x)
-{
- __asm__ ("fabs %0, %1" : "=d"(x) : "d"(x));
- return x;
-}
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/fabsf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
-
-#include "../fabsf.c"
-
-#else
-
-float fabsf(float x)
-{
- __asm__ ("fabs %0, %1" : "=f"(x) : "f"(x));
- return x;
-}
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/fma.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__) || defined(BROKEN_PPC_D_ASM)
-
-#include "../fma.c"
-
-#else
-
-double fma(double x, double y, double z)
-{
- __asm__("fmadd %0, %1, %2, %3" : "=d"(x) : "d"(x), "d"(y), "d"(z));
- return x;
-}
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/fmaf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
-
-#include "../fmaf.c"
-
-#else
-
-float fmaf(float x, float y, float z)
-{
- __asm__("fmadds %0, %1, %2, %3" : "=f"(x) : "f"(x), "f"(y), "f"(z));
- return x;
-}
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/sqrt.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if !defined _SOFT_FLOAT && defined _ARCH_PPCSQ
-
-double sqrt(double x)
-{
- __asm__ ("fsqrt %0, %1\n" : "=d" (x) : "d" (x));
- return x;
-}
-
-#else
-
-#include "../sqrt.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/sqrtf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if !defined _SOFT_FLOAT && defined _ARCH_PPCSQ
-
-float sqrtf(float x)
-{
- __asm__ ("fsqrts %0, %1\n" : "=f" (x) : "f" (x));
- return x;
-}
-
-#else
-
-#include "../sqrtf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/ceil.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#ifdef _ARCH_PWR5X
-
-double ceil(double x)
-{
- __asm__ ("frip %0, %1" : "=d"(x) : "d"(x));
- return x;
-}
-
-#else
-
-#include "../ceil.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/ceilf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#ifdef _ARCH_PWR5X
-
-float ceilf(float x)
-{
- __asm__ ("frip %0, %1" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../ceilf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fabs.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double fabs(double x)
-{
- __asm__ ("fabs %0, %1" : "=d"(x) : "d"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fabsf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float fabsf(float x)
-{
- __asm__ ("fabs %0, %1" : "=f"(x) : "f"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/floor.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#ifdef _ARCH_PWR5X
-
-double floor(double x)
-{
- __asm__ ("frim %0, %1" : "=d"(x) : "d"(x));
- return x;
-}
-
-#else
-
-#include "../floor.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/floorf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#ifdef _ARCH_PWR5X
-
-float floorf(float x)
-{
- __asm__ ("frim %0, %1" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../floorf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fma.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double fma(double x, double y, double z)
-{
- __asm__ ("fmadd %0, %1, %2, %3" : "=d"(x) : "d"(x), "d"(y), "d"(z));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fmaf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float fmaf(float x, float y, float z)
-{
- __asm__ ("fmadds %0, %1, %2, %3" : "=f"(x) : "f"(x), "f"(y), "f"(z));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fmax.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#ifdef __VSX__
-
-double fmax(double x, double y)
-{
- __asm__ ("xsmaxdp %x0, %x1, %x2" : "=ws"(x) : "ws"(x), "ws"(y));
- return x;
-}
-
-#else
-
-#include "../fmax.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fmaxf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#ifdef __VSX__
-
-float fmaxf(float x, float y)
-{
- __asm__ ("xsmaxdp %x0, %x1, %x2" : "=ww"(x) : "ww"(x), "ww"(y));
- return x;
-}
-
-#else
-
-#include "../fmaxf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fmin.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#ifdef __VSX__
-
-double fmin(double x, double y)
-{
- __asm__ ("xsmindp %x0, %x1, %x2" : "=ws"(x) : "ws"(x), "ws"(y));
- return x;
-}
-
-#else
-
-#include "../fmin.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fminf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#ifdef __VSX__
-
-float fminf(float x, float y)
-{
- __asm__ ("xsmindp %x0, %x1, %x2" : "=ww"(x) : "ww"(x), "ww"(y));
- return x;
-}
-
-#else
-
-#include "../fminf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/lrint.c
@@ -1,16 +0,0 @@
-#include <math.h>
-
-#ifdef _ARCH_PWR5X
-
-long lrint(double x)
-{
- long n;
- __asm__ ("fctid %0, %1" : "=d"(n) : "d"(x));
- return n;
-}
-
-#else
-
-#include "../lrint.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/lrintf.c
@@ -1,16 +0,0 @@
-#include <math.h>
-
-#ifdef _ARCH_PWR5X
-
-long lrintf(float x)
-{
- long n;
- __asm__ ("fctid %0, %1" : "=d"(n) : "f"(x));
- return n;
-}
-
-#else
-
-#include "../lrintf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/lround.c
@@ -1,18 +0,0 @@
-#include <math.h>
-
-#ifdef __VSX__
-
-long lround(double x)
-{
- long n;
- __asm__ (
- "xsrdpi %1, %1\n"
- "fctid %0, %1\n" : "=d"(n), "+d"(x));
- return n;
-}
-
-#else
-
-#include "../lround.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/lroundf.c
@@ -1,18 +0,0 @@
-#include <math.h>
-
-#ifdef __VSX__
-
-long lroundf(float x)
-{
- long n;
- __asm__ (
- "xsrdpi %1, %1\n"
- "fctid %0, %1\n" : "=d"(n), "+f"(x));
- return n;
-}
-
-#else
-
-#include "../lroundf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/round.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#ifdef _ARCH_PWR5X
-
-double round(double x)
-{
- __asm__ ("frin %0, %1" : "=d"(x) : "d"(x));
- return x;
-}
-
-#else
-
-#include "../round.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/roundf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#ifdef _ARCH_PWR5X
-
-float roundf(float x)
-{
- __asm__ ("frin %0, %1" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../roundf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/sqrt.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double sqrt(double x)
-{
- __asm__ ("fsqrt %0, %1" : "=d"(x) : "d"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/sqrtf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float sqrtf(float x)
-{
- __asm__ ("fsqrts %0, %1" : "=f"(x) : "f"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/trunc.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#ifdef _ARCH_PWR5X
-
-double trunc(double x)
-{
- __asm__ ("friz %0, %1" : "=d"(x) : "d"(x));
- return x;
-}
-
-#else
-
-#include "../trunc.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/truncf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#ifdef _ARCH_PWR5X
-
-float truncf(float x)
-{
- __asm__ ("friz %0, %1" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../truncf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/copysign.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if __riscv_flen >= 64
-
-double copysign(double x, double y)
-{
- __asm__ ("fsgnj.d %0, %1, %2" : "=f"(x) : "f"(x), "f"(y));
- return x;
-}
-
-#else
-
-#include "../copysign.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/copysignf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if __riscv_flen >= 32
-
-float copysignf(float x, float y)
-{
- __asm__ ("fsgnj.s %0, %1, %2" : "=f"(x) : "f"(x), "f"(y));
- return x;
-}
-
-#else
-
-#include "../copysignf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fabs.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if __riscv_flen >= 64
-
-double fabs(double x)
-{
- __asm__ ("fabs.d %0, %1" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../fabs.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fabsf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if __riscv_flen >= 32
-
-float fabsf(float x)
-{
- __asm__ ("fabs.s %0, %1" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../fabsf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fma.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if __riscv_flen >= 64
-
-double fma(double x, double y, double z)
-{
- __asm__ ("fmadd.d %0, %1, %2, %3" : "=f"(x) : "f"(x), "f"(y), "f"(z));
- return x;
-}
-
-#else
-
-#include "../fma.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fmaf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if __riscv_flen >= 32
-
-float fmaf(float x, float y, float z)
-{
- __asm__ ("fmadd.s %0, %1, %2, %3" : "=f"(x) : "f"(x), "f"(y), "f"(z));
- return x;
-}
-
-#else
-
-#include "../fmaf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fmax.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if __riscv_flen >= 64
-
-double fmax(double x, double y)
-{
- __asm__ ("fmax.d %0, %1, %2" : "=f"(x) : "f"(x), "f"(y));
- return x;
-}
-
-#else
-
-#include "../fmax.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fmaxf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if __riscv_flen >= 32
-
-float fmaxf(float x, float y)
-{
- __asm__ ("fmax.s %0, %1, %2" : "=f"(x) : "f"(x), "f"(y));
- return x;
-}
-
-#else
-
-#include "../fmaxf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fmin.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if __riscv_flen >= 64
-
-double fmin(double x, double y)
-{
- __asm__ ("fmin.d %0, %1, %2" : "=f"(x) : "f"(x), "f"(y));
- return x;
-}
-
-#else
-
-#include "../fmin.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fminf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if __riscv_flen >= 32
-
-float fminf(float x, float y)
-{
- __asm__ ("fmin.s %0, %1, %2" : "=f"(x) : "f"(x), "f"(y));
- return x;
-}
-
-#else
-
-#include "../fminf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/sqrt.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if __riscv_flen >= 64
-
-double sqrt(double x)
-{
- __asm__ ("fsqrt.d %0, %1" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../sqrt.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/sqrtf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if __riscv_flen >= 32
-
-float sqrtf(float x)
-{
- __asm__ ("fsqrt.s %0, %1" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../sqrtf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/ceil.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-double ceil(double x)
-{
- __asm__ ("fidbra %0, 6, %1, 4" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../ceil.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/ceilf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-float ceilf(float x)
-{
- __asm__ ("fiebra %0, 6, %1, 4" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../ceilf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/ceill.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-long double ceill(long double x)
-{
- __asm__ ("fixbra %0, 6, %1, 4" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../ceill.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/fabs.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-double fabs(double x)
-{
- __asm__ ("lpdbr %0, %1" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../fabs.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/fabsf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-float fabsf(float x)
-{
- __asm__ ("lpebr %0, %1" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../fabsf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/fabsl.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-long double fabsl(long double x)
-{
- __asm__ ("lpxbr %0, %1" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../fabsl.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/floor.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-double floor(double x)
-{
- __asm__ ("fidbra %0, 7, %1, 4" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../floor.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/floorf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-float floorf(float x)
-{
- __asm__ ("fiebra %0, 7, %1, 4" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../floorf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/floorl.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-long double floorl(long double x)
-{
- __asm__ ("fixbra %0, 7, %1, 4" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../floorl.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/fma.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double fma(double x, double y, double z)
-{
- __asm__ ("madbr %0, %1, %2" : "+f"(z) : "f"(x), "f"(y));
- return z;
-}
lib/libc/wasi/libc-top-half/musl/src/math/s390x/fmaf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float fmaf(float x, float y, float z)
-{
- __asm__ ("maebr %0, %1, %2" : "+f"(z) : "f"(x), "f"(y));
- return z;
-}
lib/libc/wasi/libc-top-half/musl/src/math/s390x/nearbyint.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-double nearbyint(double x)
-{
- __asm__ ("fidbra %0, 0, %1, 4" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../nearbyint.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/nearbyintf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-float nearbyintf(float x)
-{
- __asm__ ("fiebra %0, 0, %1, 4" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../nearbyintf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/nearbyintl.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-long double nearbyintl(long double x)
-{
- __asm__ ("fixbra %0, 0, %1, 4" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../nearbyintl.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/rint.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-double rint(double x)
-{
- __asm__ ("fidbr %0, 0, %1" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../rint.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/rintf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-float rintf(float x)
-{
- __asm__ ("fiebr %0, 0, %1" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../rintf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/rintl.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-long double rintl(long double x)
-{
- __asm__ ("fixbr %0, 0, %1" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../rintl.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/round.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-double round(double x)
-{
- __asm__ ("fidbra %0, 1, %1, 4" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../round.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/roundf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-float roundf(float x)
-{
- __asm__ ("fiebra %0, 1, %1, 4" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../roundf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/roundl.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-long double roundl(long double x)
-{
- __asm__ ("fixbra %0, 1, %1, 4" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../roundl.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/sqrt.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-double sqrt(double x)
-{
- __asm__ ("sqdbr %0, %1" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../sqrt.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/sqrtf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-float sqrtf(float x)
-{
- __asm__ ("sqebr %0, %1" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../sqrtf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/sqrtl.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-long double sqrtl(long double x)
-{
- __asm__ ("sqxbr %0, %1" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../sqrtl.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/trunc.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-double trunc(double x)
-{
- __asm__ ("fidbra %0, 5, %1, 4" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../trunc.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/truncf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-float truncf(float x)
-{
- __asm__ ("fiebra %0, 5, %1, 4" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../truncf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/truncl.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-long double truncl(long double x)
-{
- __asm__ ("fixbra %0, 5, %1, 4" : "=f"(x) : "f"(x));
- return x;
-}
-
-#else
-
-#include "../truncl.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/x32/__invtrigl.s
lib/libc/wasi/libc-top-half/musl/src/math/x32/acosl.s
@@ -1,16 +0,0 @@
-# see ../i386/acos.s
-
-.global acosl
-.type acosl,@function
-acosl:
- fldt 8(%esp)
-1: fld %st(0)
- fld1
- fsub %st(0),%st(1)
- fadd %st(2)
- fmulp
- fsqrt
- fabs
- fxch %st(1)
- fpatan
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/asinl.s
@@ -1,12 +0,0 @@
-.global asinl
-.type asinl,@function
-asinl:
- fldt 8(%esp)
-1: fld %st(0)
- fld1
- fsub %st(0),%st(1)
- fadd %st(2)
- fmulp
- fsqrt
- fpatan
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/atan2l.s
@@ -1,7 +0,0 @@
-.global atan2l
-.type atan2l,@function
-atan2l:
- fldt 8(%esp)
- fldt 24(%esp)
- fpatan
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/atanl.s
@@ -1,7 +0,0 @@
-.global atanl
-.type atanl,@function
-atanl:
- fldt 8(%esp)
- fld1
- fpatan
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/ceill.s
@@ -1,1 +0,0 @@
-# see floorl.s
lib/libc/wasi/libc-top-half/musl/src/math/x32/exp2l.s
@@ -1,83 +0,0 @@
-.global expm1l
-.type expm1l,@function
-expm1l:
- fldt 8(%esp)
- fldl2e
- fmulp
- movl $0xc2820000,-4(%esp)
- flds -4(%esp)
- fucomip %st(1),%st
- fld1
- jb 1f
- # x*log2e <= -65, return -1 without underflow
- fstp %st(1)
- fchs
- ret
-1: fld %st(1)
- fabs
- fucomip %st(1),%st
- fstp %st(0)
- ja 1f
- f2xm1
- ret
-1: push %rax
- call 1f
- pop %rax
- fld1
- fsubrp
- ret
-
-.global exp2l
-.type exp2l,@function
-exp2l:
- fldt 8(%esp)
-1: fld %st(0)
- sub $16,%esp
- fstpt (%esp)
- mov 8(%esp),%ax
- and $0x7fff,%ax
- cmp $0x3fff+13,%ax
- jb 4f # |x| < 8192
- cmp $0x3fff+15,%ax
- jae 3f # |x| >= 32768
- fsts (%esp)
- cmpl $0xc67ff800,(%esp)
- jb 2f # x > -16382
- movl $0x5f000000,(%esp)
- flds (%esp) # 0x1p63
- fld %st(1)
- fsub %st(1)
- faddp
- fucomip %st(1),%st
- je 2f # x - 0x1p63 + 0x1p63 == x
- movl $1,(%esp)
- flds (%esp) # 0x1p-149
- fdiv %st(1)
- fstps (%esp) # raise underflow
-2: fld1
- fld %st(1)
- frndint
- fxch %st(2)
- fsub %st(2) # st(0)=x-rint(x), st(1)=1, st(2)=rint(x)
- f2xm1
- faddp # 2^(x-rint(x))
-1: fscale
- fstp %st(1)
- add $16,%esp
- ret
-3: xor %eax,%eax
-4: cmp $0x3fff-64,%ax
- fld1
- jb 1b # |x| < 0x1p-64
- fstpt (%esp)
- fistl 8(%esp)
- fildl 8(%esp)
- fsubrp %st(1)
- addl $0x3fff,8(%esp)
- f2xm1
- fld1
- faddp # 2^(x-rint(x))
- fldt (%esp) # 2^rint(x)
- fmulp
- add $16,%esp
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/expl.s
@@ -1,101 +0,0 @@
-# exp(x) = 2^hi + 2^hi (2^lo - 1)
-# where hi+lo = log2e*x with 128bit precision
-# exact log2e*x calculation depends on nearest rounding mode
-# using the exact multiplication method of Dekker and Veltkamp
-
-.global expl
-.type expl,@function
-expl:
- fldt 8(%esp)
-
- # interesting case: 0x1p-32 <= |x| < 16384
- # check if (exponent|0x8000) is in [0xbfff-32, 0xbfff+13]
- mov 16(%esp), %ax
- or $0x8000, %ax
- sub $0xbfdf, %ax
- cmp $45, %ax
- jbe 2f
- test %ax, %ax
- fld1
- js 1f
- # if |x|>=0x1p14 or nan return 2^trunc(x)
- fscale
- fstp %st(1)
- ret
- # if |x|<0x1p-32 return 1+x
-1: faddp
- ret
-
- # should be 0x1.71547652b82fe178p0L == 0x3fff b8aa3b29 5c17f0bc
- # it will be wrong on non-nearest rounding mode
-2: fldl2e
- sub $48, %esp
- # hi = log2e_hi*x
- # 2^hi = exp2l(hi)
- fmul %st(1),%st
- fld %st(0)
- fstpt (%esp)
- fstpt 16(%esp)
- fstpt 32(%esp)
- call exp2l@PLT
- # if 2^hi == inf return 2^hi
- fld %st(0)
- fstpt (%esp)
- cmpw $0x7fff, 8(%esp)
- je 1f
- fldt 32(%esp)
- fldt 16(%esp)
- # fpu stack: 2^hi x hi
- # exact mult: x*log2e
- fld %st(1)
- # c = 0x1p32+1
- movq $0x41f0000000100000,%rax
- pushq %rax
- fldl (%esp)
- # xh = x - c*x + c*x
- # xl = x - xh
- fmulp
- fld %st(2)
- fsub %st(1), %st
- faddp
- fld %st(2)
- fsub %st(1), %st
- # yh = log2e_hi - c*log2e_hi + c*log2e_hi
- movq $0x3ff7154765200000,%rax
- pushq %rax
- fldl (%esp)
- # fpu stack: 2^hi x hi xh xl yh
- # lo = hi - xh*yh + xl*yh
- fld %st(2)
- fmul %st(1), %st
- fsubp %st, %st(4)
- fmul %st(1), %st
- faddp %st, %st(3)
- # yl = log2e_hi - yh
- movq $0x3de705fc2f000000,%rax
- pushq %rax
- fldl (%esp)
- # fpu stack: 2^hi x lo xh xl yl
- # lo += xh*yl + xl*yl
- fmul %st, %st(2)
- fmulp %st, %st(1)
- fxch %st(2)
- faddp
- faddp
- # log2e_lo
- movq $0xbfbe,%rax
- pushq %rax
- movq $0x82f0025f2dc582ee,%rax
- pushq %rax
- fldt (%esp)
- add $40,%esp
- # fpu stack: 2^hi x lo log2e_lo
- # lo += log2e_lo*x
- # return 2^hi + 2^hi (2^lo - 1)
- fmulp %st, %st(2)
- faddp
- f2xm1
- fmul %st(1), %st
- faddp
-1: add $48, %esp
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/expm1l.s
@@ -1,1 +0,0 @@
-# see exp2l.s
lib/libc/wasi/libc-top-half/musl/src/math/x32/fabs.s
@@ -1,9 +0,0 @@
-.global fabs
-.type fabs,@function
-fabs:
- xor %eax,%eax
- dec %rax
- shr %rax
- movq %rax,%xmm1
- andpd %xmm1,%xmm0
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/fabsf.s
@@ -1,7 +0,0 @@
-.global fabsf
-.type fabsf,@function
-fabsf:
- mov $0x7fffffff,%eax
- movq %rax,%xmm1
- andps %xmm1,%xmm0
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/fabsl.s
@@ -1,6 +0,0 @@
-.global fabsl
-.type fabsl,@function
-fabsl:
- fldt 8(%esp)
- fabs
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/floorl.s
@@ -1,27 +0,0 @@
-.global floorl
-.type floorl,@function
-floorl:
- fldt 8(%esp)
-1: mov $0x7,%al
-1: fstcw 8(%esp)
- mov 9(%esp),%ah
- mov %al,9(%esp)
- fldcw 8(%esp)
- frndint
- mov %ah,9(%esp)
- fldcw 8(%esp)
- ret
-
-.global ceill
-.type ceill,@function
-ceill:
- fldt 8(%esp)
- mov $0xb,%al
- jmp 1b
-
-.global truncl
-.type truncl,@function
-truncl:
- fldt 8(%esp)
- mov $0xf,%al
- jmp 1b
lib/libc/wasi/libc-top-half/musl/src/math/x32/fma.c
@@ -1,23 +0,0 @@
-#include <math.h>
-
-#if __FMA__
-
-double fma(double x, double y, double z)
-{
- __asm__ ("vfmadd132sd %1, %2, %0" : "+x" (x) : "x" (y), "x" (z));
- return x;
-}
-
-#elif __FMA4__
-
-double fma(double x, double y, double z)
-{
- __asm__ ("vfmaddsd %3, %2, %1, %0" : "=x" (x) : "x" (x), "x" (y), "x" (z));
- return x;
-}
-
-#else
-
-#include "../fma.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/x32/fmaf.c
@@ -1,23 +0,0 @@
-#include <math.h>
-
-#if __FMA__
-
-float fmaf(float x, float y, float z)
-{
- __asm__ ("vfmadd132ss %1, %2, %0" : "+x" (x) : "x" (y), "x" (z));
- return x;
-}
-
-#elif __FMA4__
-
-float fmaf(float x, float y, float z)
-{
- __asm__ ("vfmaddss %3, %2, %1, %0" : "=x" (x) : "x" (x), "x" (y), "x" (z));
- return x;
-}
-
-#else
-
-#include "../fmaf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/x32/fmodl.s
@@ -1,11 +0,0 @@
-.global fmodl
-.type fmodl,@function
-fmodl:
- fldt 24(%esp)
- fldt 8(%esp)
-1: fprem
- fnstsw %ax
- testb $4,%ah
- jnz 1b
- fstp %st(1)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/llrint.s
@@ -1,5 +0,0 @@
-.global llrint
-.type llrint,@function
-llrint:
- cvtsd2si %xmm0,%rax
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/llrintf.s
@@ -1,5 +0,0 @@
-.global llrintf
-.type llrintf,@function
-llrintf:
- cvtss2si %xmm0,%rax
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/llrintl.s
@@ -1,7 +0,0 @@
-.global llrintl
-.type llrintl,@function
-llrintl:
- fldt 8(%esp)
- fistpll 8(%esp)
- mov 8(%esp),%rax
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/log10l.s
@@ -1,7 +0,0 @@
-.global log10l
-.type log10l,@function
-log10l:
- fldlg2
- fldt 8(%esp)
- fyl2x
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/log1pl.s
@@ -1,15 +0,0 @@
-.global log1pl
-.type log1pl,@function
-log1pl:
- mov 14(%esp),%eax
- fldln2
- and $0x7fffffff,%eax
- fldt 8(%esp)
- cmp $0x3ffd9400,%eax
- ja 1f
- fyl2xp1
- ret
-1: fld1
- faddp
- fyl2x
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/log2l.s
@@ -1,7 +0,0 @@
-.global log2l
-.type log2l,@function
-log2l:
- fld1
- fldt 8(%esp)
- fyl2x
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/logl.s
@@ -1,7 +0,0 @@
-.global logl
-.type logl,@function
-logl:
- fldln2
- fldt 8(%esp)
- fyl2x
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/lrint.s
@@ -1,5 +0,0 @@
-.global lrint
-.type lrint,@function
-lrint:
- cvtsd2si %xmm0,%rax
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/lrintf.s
@@ -1,5 +0,0 @@
-.global lrintf
-.type lrintf,@function
-lrintf:
- cvtss2si %xmm0,%rax
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/lrintl.s
@@ -1,7 +0,0 @@
-.global lrintl
-.type lrintl,@function
-lrintl:
- fldt 8(%esp)
- fistpl 8(%esp)
- movl 8(%esp),%eax
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/remainderl.s
@@ -1,11 +0,0 @@
-.global remainderl
-.type remainderl,@function
-remainderl:
- fldt 24(%esp)
- fldt 8(%esp)
-1: fprem1
- fnstsw %ax
- testb $4,%ah
- jnz 1b
- fstp %st(1)
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/rintl.s
@@ -1,6 +0,0 @@
-.global rintl
-.type rintl,@function
-rintl:
- fldt 8(%esp)
- frndint
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/sqrt.s
@@ -1,4 +0,0 @@
-.global sqrt
-.type sqrt,@function
-sqrt: sqrtsd %xmm0, %xmm0
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/sqrtf.s
@@ -1,4 +0,0 @@
-.global sqrtf
-.type sqrtf,@function
-sqrtf: sqrtss %xmm0, %xmm0
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/sqrtl.s
@@ -1,5 +0,0 @@
-.global sqrtl
-.type sqrtl,@function
-sqrtl: fldt 8(%esp)
- fsqrt
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/truncl.s
@@ -1,1 +0,0 @@
-# see floorl.s
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/__invtrigl.s
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/acosl.s
@@ -1,16 +0,0 @@
-# see ../i386/acos.s
-
-.global acosl
-.type acosl,@function
-acosl:
- fldt 8(%rsp)
-1: fld %st(0)
- fld1
- fsub %st(0),%st(1)
- fadd %st(2)
- fmulp
- fsqrt
- fabs
- fxch %st(1)
- fpatan
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/asinl.s
@@ -1,12 +0,0 @@
-.global asinl
-.type asinl,@function
-asinl:
- fldt 8(%rsp)
-1: fld %st(0)
- fld1
- fsub %st(0),%st(1)
- fadd %st(2)
- fmulp
- fsqrt
- fpatan
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/atan2l.s
@@ -1,7 +0,0 @@
-.global atan2l
-.type atan2l,@function
-atan2l:
- fldt 8(%rsp)
- fldt 24(%rsp)
- fpatan
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/atanl.s
@@ -1,7 +0,0 @@
-.global atanl
-.type atanl,@function
-atanl:
- fldt 8(%rsp)
- fld1
- fpatan
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/ceill.s
@@ -1,1 +0,0 @@
-# see floorl.s
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/exp2l.s
@@ -1,83 +0,0 @@
-.global expm1l
-.type expm1l,@function
-expm1l:
- fldt 8(%rsp)
- fldl2e
- fmulp
- movl $0xc2820000,-4(%rsp)
- flds -4(%rsp)
- fucomip %st(1),%st
- fld1
- jb 1f
- # x*log2e <= -65, return -1 without underflow
- fstp %st(1)
- fchs
- ret
-1: fld %st(1)
- fabs
- fucomip %st(1),%st
- fstp %st(0)
- ja 1f
- f2xm1
- ret
-1: push %rax
- call 1f
- pop %rax
- fld1
- fsubrp
- ret
-
-.global exp2l
-.type exp2l,@function
-exp2l:
- fldt 8(%rsp)
-1: fld %st(0)
- sub $16,%rsp
- fstpt (%rsp)
- mov 8(%rsp),%ax
- and $0x7fff,%ax
- cmp $0x3fff+13,%ax
- jb 4f # |x| < 8192
- cmp $0x3fff+15,%ax
- jae 3f # |x| >= 32768
- fsts (%rsp)
- cmpl $0xc67ff800,(%rsp)
- jb 2f # x > -16382
- movl $0x5f000000,(%rsp)
- flds (%rsp) # 0x1p63
- fld %st(1)
- fsub %st(1)
- faddp
- fucomip %st(1),%st
- je 2f # x - 0x1p63 + 0x1p63 == x
- movl $1,(%rsp)
- flds (%rsp) # 0x1p-149
- fdiv %st(1)
- fstps (%rsp) # raise underflow
-2: fld1
- fld %st(1)
- frndint
- fxch %st(2)
- fsub %st(2) # st(0)=x-rint(x), st(1)=1, st(2)=rint(x)
- f2xm1
- faddp # 2^(x-rint(x))
-1: fscale
- fstp %st(1)
- add $16,%rsp
- ret
-3: xor %eax,%eax
-4: cmp $0x3fff-64,%ax
- fld1
- jb 1b # |x| < 0x1p-64
- fstpt (%rsp)
- fistl 8(%rsp)
- fildl 8(%rsp)
- fsubrp %st(1)
- addl $0x3fff,8(%rsp)
- f2xm1
- fld1
- faddp # 2^(x-rint(x))
- fldt (%rsp) # 2^rint(x)
- fmulp
- add $16,%rsp
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/expl.s
@@ -1,101 +0,0 @@
-# exp(x) = 2^hi + 2^hi (2^lo - 1)
-# where hi+lo = log2e*x with 128bit precision
-# exact log2e*x calculation depends on nearest rounding mode
-# using the exact multiplication method of Dekker and Veltkamp
-
-.global expl
-.type expl,@function
-expl:
- fldt 8(%rsp)
-
- # interesting case: 0x1p-32 <= |x| < 16384
- # check if (exponent|0x8000) is in [0xbfff-32, 0xbfff+13]
- mov 16(%rsp), %ax
- or $0x8000, %ax
- sub $0xbfdf, %ax
- cmp $45, %ax
- jbe 2f
- test %ax, %ax
- fld1
- js 1f
- # if |x|>=0x1p14 or nan return 2^trunc(x)
- fscale
- fstp %st(1)
- ret
- # if |x|<0x1p-32 return 1+x
-1: faddp
- ret
-
- # should be 0x1.71547652b82fe178p0L == 0x3fff b8aa3b29 5c17f0bc
- # it will be wrong on non-nearest rounding mode
-2: fldl2e
- subq $48, %rsp
- # hi = log2e_hi*x
- # 2^hi = exp2l(hi)
- fmul %st(1),%st
- fld %st(0)
- fstpt (%rsp)
- fstpt 16(%rsp)
- fstpt 32(%rsp)
- call exp2l@PLT
- # if 2^hi == inf return 2^hi
- fld %st(0)
- fstpt (%rsp)
- cmpw $0x7fff, 8(%rsp)
- je 1f
- fldt 32(%rsp)
- fldt 16(%rsp)
- # fpu stack: 2^hi x hi
- # exact mult: x*log2e
- fld %st(1)
- # c = 0x1p32+1
- movq $0x41f0000000100000,%rax
- pushq %rax
- fldl (%rsp)
- # xh = x - c*x + c*x
- # xl = x - xh
- fmulp
- fld %st(2)
- fsub %st(1), %st
- faddp
- fld %st(2)
- fsub %st(1), %st
- # yh = log2e_hi - c*log2e_hi + c*log2e_hi
- movq $0x3ff7154765200000,%rax
- pushq %rax
- fldl (%rsp)
- # fpu stack: 2^hi x hi xh xl yh
- # lo = hi - xh*yh + xl*yh
- fld %st(2)
- fmul %st(1), %st
- fsubp %st, %st(4)
- fmul %st(1), %st
- faddp %st, %st(3)
- # yl = log2e_hi - yh
- movq $0x3de705fc2f000000,%rax
- pushq %rax
- fldl (%rsp)
- # fpu stack: 2^hi x lo xh xl yl
- # lo += xh*yl + xl*yl
- fmul %st, %st(2)
- fmulp %st, %st(1)
- fxch %st(2)
- faddp
- faddp
- # log2e_lo
- movq $0xbfbe,%rax
- pushq %rax
- movq $0x82f0025f2dc582ee,%rax
- pushq %rax
- fldt (%rsp)
- addq $40,%rsp
- # fpu stack: 2^hi x lo log2e_lo
- # lo += log2e_lo*x
- # return 2^hi + 2^hi (2^lo - 1)
- fmulp %st, %st(2)
- faddp
- f2xm1
- fmul %st(1), %st
- faddp
-1: addq $48, %rsp
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/expm1l.s
@@ -1,1 +0,0 @@
-# see exp2l.s
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/fabs.c
@@ -1,10 +0,0 @@
-#include <math.h>
-
-double fabs(double x)
-{
- double t;
- __asm__ ("pcmpeqd %0, %0" : "=x"(t)); // t = ~0
- __asm__ ("psrlq $1, %0" : "+x"(t)); // t >>= 1
- __asm__ ("andps %1, %0" : "+x"(x) : "x"(t)); // x &= t
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/fabsf.c
@@ -1,10 +0,0 @@
-#include <math.h>
-
-float fabsf(float x)
-{
- float t;
- __asm__ ("pcmpeqd %0, %0" : "=x"(t)); // t = ~0
- __asm__ ("psrld $1, %0" : "+x"(t)); // t >>= 1
- __asm__ ("andps %1, %0" : "+x"(x) : "x"(t)); // x &= t
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/fabsl.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-long double fabsl(long double x)
-{
- __asm__ ("fabs" : "+t"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/floorl.s
@@ -1,27 +0,0 @@
-.global floorl
-.type floorl,@function
-floorl:
- fldt 8(%rsp)
-1: mov $0x7,%al
-1: fstcw 8(%rsp)
- mov 9(%rsp),%ah
- mov %al,9(%rsp)
- fldcw 8(%rsp)
- frndint
- mov %ah,9(%rsp)
- fldcw 8(%rsp)
- ret
-
-.global ceill
-.type ceill,@function
-ceill:
- fldt 8(%rsp)
- mov $0xb,%al
- jmp 1b
-
-.global truncl
-.type truncl,@function
-truncl:
- fldt 8(%rsp)
- mov $0xf,%al
- jmp 1b
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/fma.c
@@ -1,23 +0,0 @@
-#include <math.h>
-
-#if __FMA__
-
-double fma(double x, double y, double z)
-{
- __asm__ ("vfmadd132sd %1, %2, %0" : "+x" (x) : "x" (y), "x" (z));
- return x;
-}
-
-#elif __FMA4__
-
-double fma(double x, double y, double z)
-{
- __asm__ ("vfmaddsd %3, %2, %1, %0" : "=x" (x) : "x" (x), "x" (y), "x" (z));
- return x;
-}
-
-#else
-
-#include "../fma.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/fmaf.c
@@ -1,23 +0,0 @@
-#include <math.h>
-
-#if __FMA__
-
-float fmaf(float x, float y, float z)
-{
- __asm__ ("vfmadd132ss %1, %2, %0" : "+x" (x) : "x" (y), "x" (z));
- return x;
-}
-
-#elif __FMA4__
-
-float fmaf(float x, float y, float z)
-{
- __asm__ ("vfmaddss %3, %2, %1, %0" : "=x" (x) : "x" (x), "x" (y), "x" (z));
- return x;
-}
-
-#else
-
-#include "../fmaf.c"
-
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/fmodl.c
@@ -1,9 +0,0 @@
-#include <math.h>
-
-long double fmodl(long double x, long double y)
-{
- unsigned short fpsr;
- do __asm__ ("fprem; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y));
- while (fpsr & 0x400);
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/llrint.c
@@ -1,8 +0,0 @@
-#include <math.h>
-
-long long llrint(double x)
-{
- long long r;
- __asm__ ("cvtsd2si %1, %0" : "=r"(r) : "x"(x));
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/llrintf.c
@@ -1,8 +0,0 @@
-#include <math.h>
-
-long long llrintf(float x)
-{
- long long r;
- __asm__ ("cvtss2si %1, %0" : "=r"(r) : "x"(x));
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/llrintl.c
@@ -1,8 +0,0 @@
-#include <math.h>
-
-long long llrintl(long double x)
-{
- long long r;
- __asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st");
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/log10l.s
@@ -1,7 +0,0 @@
-.global log10l
-.type log10l,@function
-log10l:
- fldlg2
- fldt 8(%rsp)
- fyl2x
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/log1pl.s
@@ -1,15 +0,0 @@
-.global log1pl
-.type log1pl,@function
-log1pl:
- mov 14(%rsp),%eax
- fldln2
- and $0x7fffffff,%eax
- fldt 8(%rsp)
- cmp $0x3ffd9400,%eax
- ja 1f
- fyl2xp1
- ret
-1: fld1
- faddp
- fyl2x
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/log2l.s
@@ -1,7 +0,0 @@
-.global log2l
-.type log2l,@function
-log2l:
- fld1
- fldt 8(%rsp)
- fyl2x
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/logl.s
@@ -1,7 +0,0 @@
-.global logl
-.type logl,@function
-logl:
- fldln2
- fldt 8(%rsp)
- fyl2x
- ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/lrint.c
@@ -1,8 +0,0 @@
-#include <math.h>
-
-long lrint(double x)
-{
- long r;
- __asm__ ("cvtsd2si %1, %0" : "=r"(r) : "x"(x));
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/lrintf.c
@@ -1,8 +0,0 @@
-#include <math.h>
-
-long lrintf(float x)
-{
- long r;
- __asm__ ("cvtss2si %1, %0" : "=r"(r) : "x"(x));
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/lrintl.c
@@ -1,8 +0,0 @@
-#include <math.h>
-
-long lrintl(long double x)
-{
- long r;
- __asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st");
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/remainderl.c
@@ -1,9 +0,0 @@
-#include <math.h>
-
-long double remainderl(long double x, long double y)
-{
- unsigned short fpsr;
- do __asm__ ("fprem1; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y));
- while (fpsr & 0x400);
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/remquol.c
@@ -1,32 +0,0 @@
-#include <math.h>
-
-long double remquol(long double x, long double y, int *quo)
-{
- signed char *cx = (void *)&x, *cy = (void *)&y;
- /* By ensuring that addresses of x and y cannot be discarded,
- * this empty asm guides GCC into representing extraction of
- * their sign bits as memory loads rather than making x and y
- * not-address-taken internally and using bitfield operations,
- * which in the end wouldn't work out, as extraction from FPU
- * registers needs to go through memory anyway. This way GCC
- * should manage to use incoming stack slots without spills. */
- __asm__ ("" :: "X"(cx), "X"(cy));
-
- long double t = x;
- unsigned fpsr;
- do __asm__ ("fprem1; fnstsw %%ax" : "+t"(t), "=a"(fpsr) : "u"(y));
- while (fpsr & 0x400);
- /* C0, C1, C3 flags in x87 status word carry low bits of quotient:
- * 15 14 13 12 11 10 9 8
- * . C3 . . . C2 C1 C0
- * . b1 . . . 0 b0 b2 */
- unsigned char i = fpsr >> 8;
- i = i>>4 | i<<4;
- /* i[5:2] is now {b0 b2 ? b1}. Retrieve {0 b2 b1 b0} via
- * in-register table lookup. */
- unsigned qbits = 0x7575313164642020 >> (i & 60);
- qbits &= 7;
-
- *quo = (cx[9]^cy[9]) < 0 ? -qbits : qbits;
- return t;
-}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/rintl.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-long double rintl(long double x)
-{
- __asm__ ("frndint" : "+t"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/sqrt.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double sqrt(double x)
-{
- __asm__ ("sqrtsd %1, %0" : "=x"(x) : "x"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/sqrtf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float sqrtf(float x)
-{
- __asm__ ("sqrtss %1, %0" : "=x"(x) : "x"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/sqrtl.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-long double sqrtl(long double x)
-{
- __asm__ ("fsqrt" : "+t"(x));
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/truncl.s
@@ -1,1 +0,0 @@
-# see floorl.s
lib/libc/wasi/libc-top-half/musl/src/math/__fpclassify.c
@@ -1,11 +0,0 @@
-#include <math.h>
-#include <stdint.h>
-
-int __fpclassify(double x)
-{
- union {double f; uint64_t i;} u = {x};
- int e = u.i>>52 & 0x7ff;
- if (!e) return u.i<<1 ? FP_SUBNORMAL : FP_ZERO;
- if (e==0x7ff) return u.i<<12 ? FP_NAN : FP_INFINITE;
- return FP_NORMAL;
-}
lib/libc/wasi/libc-top-half/musl/src/math/__fpclassifyf.c
@@ -1,11 +0,0 @@
-#include <math.h>
-#include <stdint.h>
-
-int __fpclassifyf(float x)
-{
- union {float f; uint32_t i;} u = {x};
- int e = u.i>>23 & 0xff;
- if (!e) return u.i<<1 ? FP_SUBNORMAL : FP_ZERO;
- if (e==0xff) return u.i<<9 ? FP_NAN : FP_INFINITE;
- return FP_NORMAL;
-}
lib/libc/wasi/libc-top-half/musl/src/math/__fpclassifyl.c
@@ -1,42 +0,0 @@
-#include "libm.h"
-
-#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
-int __fpclassifyl(long double x)
-{
- return __fpclassify(x);
-}
-#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
-int __fpclassifyl(long double x)
-{
- union ldshape u = {x};
- int e = u.i.se & 0x7fff;
- int msb = u.i.m>>63;
- if (!e && !msb)
- return u.i.m ? FP_SUBNORMAL : FP_ZERO;
- if (e == 0x7fff) {
- /* The x86 variant of 80-bit extended precision only admits
- * one representation of each infinity, with the mantissa msb
- * necessarily set. The version with it clear is invalid/nan.
- * The m68k variant, however, allows either, and tooling uses
- * the version with it clear. */
- if (__BYTE_ORDER == __LITTLE_ENDIAN && !msb)
- return FP_NAN;
- return u.i.m << 1 ? FP_NAN : FP_INFINITE;
- }
- if (!msb)
- return FP_NAN;
- return FP_NORMAL;
-}
-#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
-int __fpclassifyl(long double x)
-{
- union ldshape u = {x};
- int e = u.i.se & 0x7fff;
- u.i.se = 0;
- if (!e)
- return u.i2.lo | u.i2.hi ? FP_SUBNORMAL : FP_ZERO;
- if (e == 0x7fff)
- return u.i2.lo | u.i2.hi ? FP_NAN : FP_INFINITE;
- return FP_NORMAL;
-}
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/__signbit.c
@@ -1,13 +0,0 @@
-#include "libm.h"
-
-// FIXME: macro in math.h
-int __signbit(double x)
-{
- union {
- double d;
- uint64_t i;
- } y = { x };
- return y.i>>63;
-}
-
-
lib/libc/wasi/libc-top-half/musl/src/math/__signbitf.c
@@ -1,11 +0,0 @@
-#include "libm.h"
-
-// FIXME: macro in math.h
-int __signbitf(float x)
-{
- union {
- float f;
- uint32_t i;
- } y = { x };
- return y.i>>31;
-}
lib/libc/wasi/libc-top-half/musl/src/math/__signbitl.c
@@ -1,14 +0,0 @@
-#include "libm.h"
-
-#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
-int __signbitl(long double x)
-{
- union ldshape u = {x};
- return u.i.se >> 15;
-}
-#elif LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
-int __signbitl(long double x)
-{
- return __signbit(x);
-}
-#endif
lib/libc/wasi/libc-top-half/musl/src/math/ceil.c
@@ -1,31 +0,0 @@
-#include "libm.h"
-
-#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
-#define EPS DBL_EPSILON
-#elif FLT_EVAL_METHOD==2
-#define EPS LDBL_EPSILON
-#endif
-static const double_t toint = 1/EPS;
-
-double ceil(double x)
-{
- union {double f; uint64_t i;} u = {x};
- int e = u.i >> 52 & 0x7ff;
- double_t y;
-
- if (e >= 0x3ff+52 || x == 0)
- return x;
- /* y = int(x) - x, where int(x) is an integer neighbor of x */
- if (u.i >> 63)
- y = x - toint + toint - x;
- else
- y = x + toint - toint - x;
- /* special case because of non-nearest rounding modes */
- if (e <= 0x3ff-1) {
- FORCE_EVAL(y);
- return u.i >> 63 ? -0.0 : 1;
- }
- if (y < 0)
- return x + y + 1;
- return x + y;
-}
lib/libc/wasi/libc-top-half/musl/src/math/ceilf.c
@@ -1,27 +0,0 @@
-#include "libm.h"
-
-float ceilf(float x)
-{
- union {float f; uint32_t i;} u = {x};
- int e = (int)(u.i >> 23 & 0xff) - 0x7f;
- uint32_t m;
-
- if (e >= 23)
- return x;
- if (e >= 0) {
- m = 0x007fffff >> e;
- if ((u.i & m) == 0)
- return x;
- FORCE_EVAL(x + 0x1p120f);
- if (u.i >> 31 == 0)
- u.i += m;
- u.i &= ~m;
- } else {
- FORCE_EVAL(x + 0x1p120f);
- if (u.i >> 31)
- u.f = -0.0;
- else if (u.i << 1)
- u.f = 1.0;
- }
- return u.f;
-}
lib/libc/wasi/libc-top-half/musl/src/math/copysign.c
@@ -1,8 +0,0 @@
-#include "libm.h"
-
-double copysign(double x, double y) {
- union {double f; uint64_t i;} ux={x}, uy={y};
- ux.i &= -1ULL/2;
- ux.i |= uy.i & 1ULL<<63;
- return ux.f;
-}
lib/libc/wasi/libc-top-half/musl/src/math/copysignf.c
@@ -1,10 +0,0 @@
-#include <math.h>
-#include <stdint.h>
-
-float copysignf(float x, float y)
-{
- union {float f; uint32_t i;} ux={x}, uy={y};
- ux.i &= 0x7fffffff;
- ux.i |= uy.i & 0x80000000;
- return ux.f;
-}
lib/libc/wasi/libc-top-half/musl/src/math/fabs.c
@@ -1,9 +0,0 @@
-#include <math.h>
-#include <stdint.h>
-
-double fabs(double x)
-{
- union {double f; uint64_t i;} u = {x};
- u.i &= -1ULL/2;
- return u.f;
-}
lib/libc/wasi/libc-top-half/musl/src/math/fabsf.c
@@ -1,9 +0,0 @@
-#include <math.h>
-#include <stdint.h>
-
-float fabsf(float x)
-{
- union {float f; uint32_t i;} u = {x};
- u.i &= 0x7fffffff;
- return u.f;
-}
lib/libc/wasi/libc-top-half/musl/src/math/floor.c
@@ -1,31 +0,0 @@
-#include "libm.h"
-
-#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
-#define EPS DBL_EPSILON
-#elif FLT_EVAL_METHOD==2
-#define EPS LDBL_EPSILON
-#endif
-static const double_t toint = 1/EPS;
-
-double floor(double x)
-{
- union {double f; uint64_t i;} u = {x};
- int e = u.i >> 52 & 0x7ff;
- double_t y;
-
- if (e >= 0x3ff+52 || x == 0)
- return x;
- /* y = int(x) - x, where int(x) is an integer neighbor of x */
- if (u.i >> 63)
- y = x - toint + toint - x;
- else
- y = x + toint - toint - x;
- /* special case because of non-nearest rounding modes */
- if (e <= 0x3ff-1) {
- FORCE_EVAL(y);
- return u.i >> 63 ? -1 : 0;
- }
- if (y > 0)
- return x + y - 1;
- return x + y;
-}
lib/libc/wasi/libc-top-half/musl/src/math/floorf.c
@@ -1,27 +0,0 @@
-#include "libm.h"
-
-float floorf(float x)
-{
- union {float f; uint32_t i;} u = {x};
- int e = (int)(u.i >> 23 & 0xff) - 0x7f;
- uint32_t m;
-
- if (e >= 23)
- return x;
- if (e >= 0) {
- m = 0x007fffff >> e;
- if ((u.i & m) == 0)
- return x;
- FORCE_EVAL(x + 0x1p120f);
- if (u.i >> 31)
- u.i += m;
- u.i &= ~m;
- } else {
- FORCE_EVAL(x + 0x1p120f);
- if (u.i >> 31 == 0)
- u.i = 0;
- else if (u.i << 1)
- u.f = -1.0;
- }
- return u.f;
-}
lib/libc/wasi/libc-top-half/musl/src/math/fmax.c
@@ -1,13 +0,0 @@
-#include <math.h>
-
-double fmax(double x, double y)
-{
- if (isnan(x))
- return y;
- if (isnan(y))
- return x;
- /* handle signed zeros, see C99 Annex F.9.9.2 */
- if (signbit(x) != signbit(y))
- return signbit(x) ? y : x;
- return x < y ? y : x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/fmaxf.c
@@ -1,13 +0,0 @@
-#include <math.h>
-
-float fmaxf(float x, float y)
-{
- if (isnan(x))
- return y;
- if (isnan(y))
- return x;
- /* handle signed zeroes, see C99 Annex F.9.9.2 */
- if (signbit(x) != signbit(y))
- return signbit(x) ? y : x;
- return x < y ? y : x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/fmin.c
@@ -1,13 +0,0 @@
-#include <math.h>
-
-double fmin(double x, double y)
-{
- if (isnan(x))
- return y;
- if (isnan(y))
- return x;
- /* handle signed zeros, see C99 Annex F.9.9.2 */
- if (signbit(x) != signbit(y))
- return signbit(x) ? x : y;
- return x < y ? x : y;
-}
lib/libc/wasi/libc-top-half/musl/src/math/fminf.c
@@ -1,13 +0,0 @@
-#include <math.h>
-
-float fminf(float x, float y)
-{
- if (isnan(x))
- return y;
- if (isnan(y))
- return x;
- /* handle signed zeros, see C99 Annex F.9.9.2 */
- if (signbit(x) != signbit(y))
- return signbit(x) ? x : y;
- return x < y ? x : y;
-}
lib/libc/wasi/libc-top-half/musl/src/math/nearbyint.c
@@ -1,20 +0,0 @@
-#include <fenv.h>
-#include <math.h>
-
-/* nearbyint is the same as rint, but it must not raise the inexact exception */
-
-double nearbyint(double x)
-{
-#ifdef FE_INEXACT
- #pragma STDC FENV_ACCESS ON
- int e;
-
- e = fetestexcept(FE_INEXACT);
-#endif
- x = rint(x);
-#ifdef FE_INEXACT
- if (!e)
- feclearexcept(FE_INEXACT);
-#endif
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/nearbyintf.c
@@ -1,18 +0,0 @@
-#include <fenv.h>
-#include <math.h>
-
-float nearbyintf(float x)
-{
-#ifdef FE_INEXACT
- #pragma STDC FENV_ACCESS ON
- int e;
-
- e = fetestexcept(FE_INEXACT);
-#endif
- x = rintf(x);
-#ifdef FE_INEXACT
- if (!e)
- feclearexcept(FE_INEXACT);
-#endif
- return x;
-}
lib/libc/wasi/libc-top-half/musl/src/math/rint.c
@@ -1,28 +0,0 @@
-#include <float.h>
-#include <math.h>
-#include <stdint.h>
-
-#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
-#define EPS DBL_EPSILON
-#elif FLT_EVAL_METHOD==2
-#define EPS LDBL_EPSILON
-#endif
-static const double_t toint = 1/EPS;
-
-double rint(double x)
-{
- union {double f; uint64_t i;} u = {x};
- int e = u.i>>52 & 0x7ff;
- int s = u.i>>63;
- double_t y;
-
- if (e >= 0x3ff+52)
- return x;
- if (s)
- y = x - toint + toint;
- else
- y = x + toint - toint;
- if (y == 0)
- return s ? -0.0 : 0;
- return y;
-}
lib/libc/wasi/libc-top-half/musl/src/math/rintf.c
@@ -1,30 +0,0 @@
-#include <float.h>
-#include <math.h>
-#include <stdint.h>
-
-#if FLT_EVAL_METHOD==0
-#define EPS FLT_EPSILON
-#elif FLT_EVAL_METHOD==1
-#define EPS DBL_EPSILON
-#elif FLT_EVAL_METHOD==2
-#define EPS LDBL_EPSILON
-#endif
-static const float_t toint = 1/EPS;
-
-float rintf(float x)
-{
- union {float f; uint32_t i;} u = {x};
- int e = u.i>>23 & 0xff;
- int s = u.i>>31;
- float_t y;
-
- if (e >= 0x7f+23)
- return x;
- if (s)
- y = x - toint + toint;
- else
- y = x + toint - toint;
- if (y == 0)
- return s ? -0.0f : 0.0f;
- return y;
-}
lib/libc/wasi/libc-top-half/musl/src/math/sqrt.c
@@ -1,158 +0,0 @@
-#include <stdint.h>
-#include <math.h>
-#include "libm.h"
-#include "sqrt_data.h"
-
-#define FENV_SUPPORT 1
-
-/* returns a*b*2^-32 - e, with error 0 <= e < 1. */
-static inline uint32_t mul32(uint32_t a, uint32_t b)
-{
- return (uint64_t)a*b >> 32;
-}
-
-/* returns a*b*2^-64 - e, with error 0 <= e < 3. */
-static inline uint64_t mul64(uint64_t a, uint64_t b)
-{
- uint64_t ahi = a>>32;
- uint64_t alo = a&0xffffffff;
- uint64_t bhi = b>>32;
- uint64_t blo = b&0xffffffff;
- return ahi*bhi + (ahi*blo >> 32) + (alo*bhi >> 32);
-}
-
-double sqrt(double x)
-{
- uint64_t ix, top, m;
-
- /* special case handling. */
- ix = asuint64(x);
- top = ix >> 52;
- if (predict_false(top - 0x001 >= 0x7ff - 0x001)) {
- /* x < 0x1p-1022 or inf or nan. */
- if (ix * 2 == 0)
- return x;
- if (ix == 0x7ff0000000000000)
- return x;
- if (ix > 0x7ff0000000000000)
- return __math_invalid(x);
- /* x is subnormal, normalize it. */
- ix = asuint64(x * 0x1p52);
- top = ix >> 52;
- top -= 52;
- }
-
- /* argument reduction:
- x = 4^e m; with integer e, and m in [1, 4)
- m: fixed point representation [2.62]
- 2^e is the exponent part of the result. */
- int even = top & 1;
- m = (ix << 11) | 0x8000000000000000;
- if (even) m >>= 1;
- top = (top + 0x3ff) >> 1;
-
- /* approximate r ~ 1/sqrt(m) and s ~ sqrt(m) when m in [1,4)
-
- initial estimate:
- 7bit table lookup (1bit exponent and 6bit significand).
-
- iterative approximation:
- using 2 goldschmidt iterations with 32bit int arithmetics
- and a final iteration with 64bit int arithmetics.
-
- details:
-
- the relative error (e = r0 sqrt(m)-1) of a linear estimate
- (r0 = a m + b) is |e| < 0.085955 ~ 0x1.6p-4 at best,
- a table lookup is faster and needs one less iteration
- 6 bit lookup table (128b) gives |e| < 0x1.f9p-8
- 7 bit lookup table (256b) gives |e| < 0x1.fdp-9
- for single and double prec 6bit is enough but for quad
- prec 7bit is needed (or modified iterations). to avoid
- one more iteration >=13bit table would be needed (16k).
-
- a newton-raphson iteration for r is
- w = r*r
- u = 3 - m*w
- r = r*u/2
- can use a goldschmidt iteration for s at the end or
- s = m*r
-
- first goldschmidt iteration is
- s = m*r
- u = 3 - s*r
- r = r*u/2
- s = s*u/2
- next goldschmidt iteration is
- u = 3 - s*r
- r = r*u/2
- s = s*u/2
- and at the end r is not computed only s.
-
- they use the same amount of operations and converge at the
- same quadratic rate, i.e. if
- r1 sqrt(m) - 1 = e, then
- r2 sqrt(m) - 1 = -3/2 e^2 - 1/2 e^3
- the advantage of goldschmidt is that the mul for s and r
- are independent (computed in parallel), however it is not
- "self synchronizing": it only uses the input m in the
- first iteration so rounding errors accumulate. at the end
- or when switching to larger precision arithmetics rounding
- errors dominate so the first iteration should be used.
-
- the fixed point representations are
- m: 2.30 r: 0.32, s: 2.30, d: 2.30, u: 2.30, three: 2.30
- and after switching to 64 bit
- m: 2.62 r: 0.64, s: 2.62, d: 2.62, u: 2.62, three: 2.62 */
-
- static const uint64_t three = 0xc0000000;
- uint64_t r, s, d, u, i;
-
- i = (ix >> 46) % 128;
- r = (uint32_t)__rsqrt_tab[i] << 16;
- /* |r sqrt(m) - 1| < 0x1.fdp-9 */
- s = mul32(m>>32, r);
- /* |s/sqrt(m) - 1| < 0x1.fdp-9 */
- d = mul32(s, r);
- u = three - d;
- r = mul32(r, u) << 1;
- /* |r sqrt(m) - 1| < 0x1.7bp-16 */
- s = mul32(s, u) << 1;
- /* |s/sqrt(m) - 1| < 0x1.7bp-16 */
- d = mul32(s, r);
- u = three - d;
- r = mul32(r, u) << 1;
- /* |r sqrt(m) - 1| < 0x1.3704p-29 (measured worst-case) */
- r = r << 32;
- s = mul64(m, r);
- d = mul64(s, r);
- u = (three<<32) - d;
- s = mul64(s, u); /* repr: 3.61 */
- /* -0x1p-57 < s - sqrt(m) < 0x1.8001p-61 */
- s = (s - 2) >> 9; /* repr: 12.52 */
- /* -0x1.09p-52 < s - sqrt(m) < -0x1.fffcp-63 */
-
- /* s < sqrt(m) < s + 0x1.09p-52,
- compute nearest rounded result:
- the nearest result to 52 bits is either s or s+0x1p-52,
- we can decide by comparing (2^52 s + 0.5)^2 to 2^104 m. */
- uint64_t d0, d1, d2;
- double y, t;
- d0 = (m << 42) - s*s;
- d1 = s - d0;
- d2 = d1 + s + 1;
- s += d1 >> 63;
- s &= 0x000fffffffffffff;
- s |= top << 52;
- y = asdouble(s);
- if (FENV_SUPPORT) {
- /* handle rounding modes and inexact exception:
- only (s+1)^2 == 2^42 m case is exact otherwise
- add a tiny value to cause the fenv effects. */
- uint64_t tiny = predict_false(d2==0) ? 0 : 0x0010000000000000;
- tiny |= (d1^d2) & 0x8000000000000000;
- t = asdouble(tiny);
- y = eval_as_double(y + t);
- }
- return y;
-}
lib/libc/wasi/libc-top-half/musl/src/math/sqrtf.c
@@ -1,83 +0,0 @@
-#include <stdint.h>
-#include <math.h>
-#include "libm.h"
-#include "sqrt_data.h"
-
-#define FENV_SUPPORT 1
-
-static inline uint32_t mul32(uint32_t a, uint32_t b)
-{
- return (uint64_t)a*b >> 32;
-}
-
-/* see sqrt.c for more detailed comments. */
-
-float sqrtf(float x)
-{
- uint32_t ix, m, m1, m0, even, ey;
-
- ix = asuint(x);
- if (predict_false(ix - 0x00800000 >= 0x7f800000 - 0x00800000)) {
- /* x < 0x1p-126 or inf or nan. */
- if (ix * 2 == 0)
- return x;
- if (ix == 0x7f800000)
- return x;
- if (ix > 0x7f800000)
- return __math_invalidf(x);
- /* x is subnormal, normalize it. */
- ix = asuint(x * 0x1p23f);
- ix -= 23 << 23;
- }
-
- /* x = 4^e m; with int e and m in [1, 4). */
- even = ix & 0x00800000;
- m1 = (ix << 8) | 0x80000000;
- m0 = (ix << 7) & 0x7fffffff;
- m = even ? m0 : m1;
-
- /* 2^e is the exponent part of the return value. */
- ey = ix >> 1;
- ey += 0x3f800000 >> 1;
- ey &= 0x7f800000;
-
- /* compute r ~ 1/sqrt(m), s ~ sqrt(m) with 2 goldschmidt iterations. */
- static const uint32_t three = 0xc0000000;
- uint32_t r, s, d, u, i;
- i = (ix >> 17) % 128;
- r = (uint32_t)__rsqrt_tab[i] << 16;
- /* |r*sqrt(m) - 1| < 0x1p-8 */
- s = mul32(m, r);
- /* |s/sqrt(m) - 1| < 0x1p-8 */
- d = mul32(s, r);
- u = three - d;
- r = mul32(r, u) << 1;
- /* |r*sqrt(m) - 1| < 0x1.7bp-16 */
- s = mul32(s, u) << 1;
- /* |s/sqrt(m) - 1| < 0x1.7bp-16 */
- d = mul32(s, r);
- u = three - d;
- s = mul32(s, u);
- /* -0x1.03p-28 < s/sqrt(m) - 1 < 0x1.fp-31 */
- s = (s - 1)>>6;
- /* s < sqrt(m) < s + 0x1.08p-23 */
-
- /* compute nearest rounded result. */
- uint32_t d0, d1, d2;
- float y, t;
- d0 = (m << 16) - s*s;
- d1 = s - d0;
- d2 = d1 + s + 1;
- s += d1 >> 31;
- s &= 0x007fffff;
- s |= ey;
- y = asfloat(s);
- if (FENV_SUPPORT) {
- /* handle rounding and inexact exception. */
- uint32_t tiny = predict_false(d2==0) ? 0 : 0x01000000;
- tiny |= (d1^d2) & 0x80000000;
- t = asfloat(tiny);
- y = eval_as_float(y + t);
- }
- return y;
-}
lib/libc/wasi/libc-top-half/musl/src/math/trunc.c
@@ -1,19 +0,0 @@
-#include "libm.h"
-
-double trunc(double x)
-{
- union {double f; uint64_t i;} u = {x};
- int e = (int)(u.i >> 52 & 0x7ff) - 0x3ff + 12;
- uint64_t m;
-
- if (e >= 52 + 12)
- return x;
- if (e < 12)
- e = 1;
- m = -1ULL >> e;
- if ((u.i & m) == 0)
- return x;
- FORCE_EVAL(x + 0x1p120f);
- u.i &= ~m;
- return u.f;
-}
lib/libc/wasi/libc-top-half/musl/src/math/truncf.c
@@ -1,19 +0,0 @@
-#include "libm.h"
-
-float truncf(float x)
-{
- union {float f; uint32_t i;} u = {x};
- int e = (int)(u.i >> 23 & 0xff) - 0x7f + 9;
- uint32_t m;
-
- if (e >= 23 + 9)
- return x;
- if (e < 9)
- e = 1;
- m = -1U >> e;
- if ((u.i & m) == 0)
- return x;
- FORCE_EVAL(x + 0x1p120f);
- u.i &= ~m;
- return u.f;
-}
lib/libc/wasi/libc-top-half/musl/src/misc/forkpty.c
@@ -1,57 +0,0 @@
-#include <pty.h>
-#include <utmp.h>
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/wait.h>
-#include <pthread.h>
-
-int forkpty(int *pm, char *name, const struct termios *tio, const struct winsize *ws)
-{
- int m, s, ec=0, p[2], cs;
- pid_t pid=-1;
- sigset_t set, oldset;
-
- if (openpty(&m, &s, name, tio, ws) < 0) return -1;
-
- sigfillset(&set);
- pthread_sigmask(SIG_BLOCK, &set, &oldset);
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
-
- if (pipe2(p, O_CLOEXEC)) {
- close(s);
- goto out;
- }
-
- pid = fork();
- if (!pid) {
- close(m);
- close(p[0]);
- if (login_tty(s)) {
- write(p[1], &errno, sizeof errno);
- _exit(127);
- }
- close(p[1]);
- pthread_setcancelstate(cs, 0);
- pthread_sigmask(SIG_SETMASK, &oldset, 0);
- return 0;
- }
- close(s);
- close(p[1]);
- if (read(p[0], &ec, sizeof ec) > 0) {
- int status;
- waitpid(pid, &status, 0);
- pid = -1;
- errno = ec;
- }
- close(p[0]);
-
-out:
- if (pid > 0) *pm = m;
- else close(m);
-
- pthread_setcancelstate(cs, 0);
- pthread_sigmask(SIG_SETMASK, &oldset, 0);
-
- return pid;
-}
lib/libc/wasi/libc-top-half/musl/src/misc/get_current_dir_name.c
@@ -1,15 +0,0 @@
-#define _GNU_SOURCE
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <unistd.h>
-#include <sys/stat.h>
-
-char *get_current_dir_name(void) {
- struct stat a, b;
- char *res = getenv("PWD");
- if (res && *res && !stat(res, &a) && !stat(".", &b)
- && (a.st_dev == b.st_dev) && (a.st_ino == b.st_ino))
- return strdup(res);
- return getcwd(0, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/misc/getauxval.c
@@ -1,15 +0,0 @@
-#include <sys/auxv.h>
-#include <errno.h>
-#include "libc.h"
-
-unsigned long __getauxval(unsigned long item)
-{
- size_t *auxv = libc.auxv;
- if (item == AT_SECURE) return libc.secure;
- for (; *auxv; auxv+=2)
- if (*auxv==item) return auxv[1];
- errno = ENOENT;
- return 0;
-}
-
-weak_alias(__getauxval, getauxval);
lib/libc/wasi/libc-top-half/musl/src/misc/getentropy.c
@@ -1,33 +0,0 @@
-#define _BSD_SOURCE
-#include <unistd.h>
-#include <sys/random.h>
-#include <pthread.h>
-#include <errno.h>
-
-int getentropy(void *buffer, size_t len)
-{
- int cs, ret = 0;
- char *pos = buffer;
-
- if (len > 256) {
- errno = EIO;
- return -1;
- }
-
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
-
- while (len) {
- ret = getrandom(pos, len, 0);
- if (ret < 0) {
- if (errno == EINTR) continue;
- else break;
- }
- pos += ret;
- len -= ret;
- ret = 0;
- }
-
- pthread_setcancelstate(cs, 0);
-
- return ret;
-}
lib/libc/wasi/libc-top-half/musl/src/misc/getpriority.c
@@ -1,9 +0,0 @@
-#include <sys/resource.h>
-#include "syscall.h"
-
-int getpriority(int which, id_t who)
-{
- int ret = syscall(SYS_getpriority, which, who);
- if (ret < 0) return ret;
- return 20-ret;
-}
lib/libc/wasi/libc-top-half/musl/src/misc/getresgid.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include "syscall.h"
-
-int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid)
-{
- return syscall(SYS_getresgid, rgid, egid, sgid);
-}
lib/libc/wasi/libc-top-half/musl/src/misc/getresuid.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include "syscall.h"
-
-int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid)
-{
- return syscall(SYS_getresuid, ruid, euid, suid);
-}
lib/libc/wasi/libc-top-half/musl/src/misc/getrlimit.c
@@ -1,26 +0,0 @@
-#include <sys/resource.h>
-#include <errno.h>
-#include "syscall.h"
-
-#define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0)
-
-int getrlimit(int resource, struct rlimit *rlim)
-{
- unsigned long k_rlim[2];
- int ret = syscall(SYS_prlimit64, 0, resource, 0, rlim);
- if (!ret) {
- FIX(rlim->rlim_cur);
- FIX(rlim->rlim_max);
- }
- if (!ret || errno != ENOSYS)
- return ret;
- if (syscall(SYS_getrlimit, resource, k_rlim) < 0)
- return -1;
- rlim->rlim_cur = k_rlim[0] == -1UL ? RLIM_INFINITY : k_rlim[0];
- rlim->rlim_max = k_rlim[1] == -1UL ? RLIM_INFINITY : k_rlim[1];
- FIX(rlim->rlim_cur);
- FIX(rlim->rlim_max);
- return 0;
-}
-
-weak_alias(getrlimit, getrlimit64);
lib/libc/wasi/libc-top-half/musl/src/misc/getrusage.c
@@ -1,35 +0,0 @@
-#include <sys/resource.h>
-#include <string.h>
-#include <errno.h>
-#include "syscall.h"
-
-int getrusage(int who, struct rusage *ru)
-{
- int r;
-#ifdef SYS_getrusage_time64
- long long kru64[18];
- r = __syscall(SYS_getrusage_time64, who, kru64);
- if (!r) {
- ru->ru_utime = (struct timeval)
- { .tv_sec = kru64[0], .tv_usec = kru64[1] };
- ru->ru_stime = (struct timeval)
- { .tv_sec = kru64[2], .tv_usec = kru64[3] };
- char *slots = (char *)&ru->ru_maxrss;
- for (int i=0; i<14; i++)
- *(long *)(slots + i*sizeof(long)) = kru64[4+i];
- }
- if (SYS_getrusage_time64 == SYS_getrusage || r != -ENOSYS)
- return __syscall_ret(r);
-#endif
- char *dest = (char *)&ru->ru_maxrss - 4*sizeof(long);
- r = __syscall(SYS_getrusage, who, dest);
- if (!r && sizeof(time_t) > sizeof(long)) {
- long kru[4];
- memcpy(kru, dest, 4*sizeof(long));
- ru->ru_utime = (struct timeval)
- { .tv_sec = kru[0], .tv_usec = kru[1] };
- ru->ru_stime = (struct timeval)
- { .tv_sec = kru[2], .tv_usec = kru[3] };
- }
- return __syscall_ret(r);
-}
lib/libc/wasi/libc-top-half/musl/src/misc/initgroups.c
@@ -1,11 +0,0 @@
-#define _GNU_SOURCE
-#include <grp.h>
-#include <limits.h>
-
-int initgroups(const char *user, gid_t gid)
-{
- gid_t groups[NGROUPS_MAX];
- int count = NGROUPS_MAX;
- if (getgrouplist(user, gid, groups, &count) < 0) return -1;
- return setgroups(count, groups);
-}
lib/libc/wasi/libc-top-half/musl/src/misc/ioctl.c
@@ -1,151 +0,0 @@
-#include <sys/ioctl.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <time.h>
-#include <sys/time.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <string.h>
-#include <endian.h>
-#include "syscall.h"
-
-#define alignof(t) offsetof(struct { char c; t x; }, x)
-
-#define W 1
-#define R 2
-#define WR 3
-
-struct ioctl_compat_map {
- int new_req, old_req;
- unsigned char old_size, dir, force_align, noffs;
- unsigned char offsets[8];
-};
-
-#define NINTH(a,b,c,d,e,f,g,h,i,...) i
-#define COUNT(...) NINTH(__VA_ARGS__,8,7,6,5,4,3,2,1,0)
-#define OFFS(...) COUNT(__VA_ARGS__), { __VA_ARGS__ }
-
-/* yields a type for a struct with original size n, with a misaligned
- * timeval/timespec expanded from 32- to 64-bit. for use with ioctl
- * number producing macros; only size of result is meaningful. */
-#define new_misaligned(n) struct { int i; time_t t; char c[(n)-4]; }
-
-struct v4l2_event {
- uint32_t a;
- uint64_t b[8];
- uint32_t c[2], ts[2], d[9];
-};
-
-static const struct ioctl_compat_map compat_map[] = {
- { SIOCGSTAMP, SIOCGSTAMP_OLD, 8, R, 0, OFFS(0, 4) },
- { SIOCGSTAMPNS, SIOCGSTAMPNS_OLD, 8, R, 0, OFFS(0, 4) },
-
- /* SNDRV_TIMER_IOCTL_STATUS */
- { _IOR('T', 0x14, char[96]), _IOR('T', 0x14, 88), 88, R, 0, OFFS(0,4) },
-
- /* SNDRV_PCM_IOCTL_STATUS[_EXT] */
- { _IOR('A', 0x20, char[128]), _IOR('A', 0x20, char[108]), 108, R, 1, OFFS(4,8,12,16,52,56,60,64) },
- { _IOWR('A', 0x24, char[128]), _IOWR('A', 0x24, char[108]), 108, WR, 1, OFFS(4,8,12,16,52,56,60,64) },
-
- /* SNDRV_RAWMIDI_IOCTL_STATUS */
- { _IOWR('W', 0x20, char[48]), _IOWR('W', 0x20, char[36]), 36, WR, 1, OFFS(4,8) },
-
- /* SNDRV_PCM_IOCTL_SYNC_PTR - with 3 subtables */
- { _IOWR('A', 0x23, char[136]), _IOWR('A', 0x23, char[132]), 0, WR, 1, 0 },
- { 0, 0, 4, WR, 1, 0 }, /* snd_pcm_sync_ptr (flags only) */
- { 0, 0, 32, WR, 1, OFFS(8,12,16,24,28) }, /* snd_pcm_mmap_status */
- { 0, 0, 4, WR, 1, 0 }, /* snd_pcm_mmap_control (each member) */
-
- /* VIDIOC_QUERYBUF, VIDIOC_QBUF, VIDIOC_DQBUF, VIDIOC_PREPARE_BUF */
- { _IOWR('V', 9, new_misaligned(68)), _IOWR('V', 9, char[68]), 68, WR, 1, OFFS(20, 24) },
- { _IOWR('V', 15, new_misaligned(68)), _IOWR('V', 15, char[68]), 68, WR, 1, OFFS(20, 24) },
- { _IOWR('V', 17, new_misaligned(68)), _IOWR('V', 17, char[68]), 68, WR, 1, OFFS(20, 24) },
- { _IOWR('V', 93, new_misaligned(68)), _IOWR('V', 93, char[68]), 68, WR, 1, OFFS(20, 24) },
-
- /* VIDIOC_DQEVENT */
- { _IOR('V', 89, new_misaligned(120)), _IOR('V', 89, struct v4l2_event), sizeof(struct v4l2_event),
- R, 0, OFFS(offsetof(struct v4l2_event, ts[0]), offsetof(struct v4l2_event, ts[1])) },
-
- /* VIDIOC_OMAP3ISP_STAT_REQ */
- { _IOWR('V', 192+6, char[32]), _IOWR('V', 192+6, char[24]), 22, WR, 0, OFFS(0,4) },
-
- /* PPPIOCGIDLE */
- { _IOR('t', 63, char[16]), _IOR('t', 63, char[8]), 8, R, 0, OFFS(0,4) },
-
- /* PPGETTIME, PPSETTIME */
- { _IOR('p', 0x95, char[16]), _IOR('p', 0x95, char[8]), 8, R, 0, OFFS(0,4) },
- { _IOW('p', 0x96, char[16]), _IOW('p', 0x96, char[8]), 8, W, 0, OFFS(0,4) },
-
- /* LPSETTIMEOUT */
- { _IOW(0x6, 0xf, char[16]), 0x060f, 8, W, 0, OFFS(0,4) },
-};
-
-static void convert_ioctl_struct(const struct ioctl_compat_map *map, char *old, char *new, int dir)
-{
- int new_offset = 0;
- int old_offset = 0;
- int old_size = map->old_size;
- if (!(dir & map->dir)) return;
- if (!map->old_size) {
- /* offsets hard-coded for SNDRV_PCM_IOCTL_SYNC_PTR;
- * if another exception appears this needs changing. */
- convert_ioctl_struct(map+1, old, new, dir);
- convert_ioctl_struct(map+2, old+4, new+8, dir);
- /* snd_pcm_mmap_control, special-cased due to kernel
- * type definition having been botched. */
- int adj = BYTE_ORDER==BIG_ENDIAN ? 4 : 0;
- convert_ioctl_struct(map+3, old+68, new+72+adj, dir);
- convert_ioctl_struct(map+3, old+72, new+76+3*adj, dir);
- return;
- }
- for (int i=0; i < map->noffs; i++) {
- int ts_offset = map->offsets[i];
- int len = ts_offset-old_offset;
- if (dir==W) memcpy(old+old_offset, new+new_offset, len);
- else memcpy(new+new_offset, old+old_offset, len);
- new_offset += len;
- old_offset += len;
- long long new_ts;
- long old_ts;
- int align = map->force_align ? sizeof(time_t) : alignof(time_t);
- new_offset += (align-1) & -new_offset;
- if (dir==W) {
- memcpy(&new_ts, new+new_offset, sizeof new_ts);
- old_ts = new_ts;
- memcpy(old+old_offset, &old_ts, sizeof old_ts);
- } else {
- memcpy(&old_ts, old+old_offset, sizeof old_ts);
- new_ts = old_ts;
- memcpy(new+new_offset, &new_ts, sizeof new_ts);
- }
- new_offset += sizeof new_ts;
- old_offset += sizeof old_ts;
- }
- if (dir==W) memcpy(old+old_offset, new+new_offset, old_size-old_offset);
- else memcpy(new+new_offset, old+old_offset, old_size-old_offset);
-}
-
-int ioctl(int fd, int req, ...)
-{
- void *arg;
- va_list ap;
- va_start(ap, req);
- arg = va_arg(ap, void *);
- va_end(ap);
- int r = __syscall(SYS_ioctl, fd, req, arg);
- if (SIOCGSTAMP != SIOCGSTAMP_OLD && req && r==-ENOTTY) {
- for (int i=0; i<sizeof compat_map/sizeof *compat_map; i++) {
- if (compat_map[i].new_req != req) continue;
- union {
- long long align;
- char buf[256];
- } u;
- convert_ioctl_struct(&compat_map[i], u.buf, arg, W);
- r = __syscall(SYS_ioctl, fd, compat_map[i].old_req, u.buf);
- if (r<0) break;
- convert_ioctl_struct(&compat_map[i], u.buf, arg, R);
- break;
- }
- }
- return __syscall_ret(r);
-}
lib/libc/wasi/libc-top-half/musl/src/misc/issetugid.c
@@ -1,8 +0,0 @@
-#define _BSD_SOURCE
-#include <unistd.h>
-#include "libc.h"
-
-int issetugid(void)
-{
- return libc.secure;
-}
lib/libc/wasi/libc-top-half/musl/src/misc/lockf.c
@@ -1,32 +0,0 @@
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-
-int lockf(int fd, int op, off_t size)
-{
- struct flock l = {
- .l_type = F_WRLCK,
- .l_whence = SEEK_CUR,
- .l_len = size,
- };
- switch (op) {
- case F_TEST:
- l.l_type = F_RDLCK;
- if (fcntl(fd, F_GETLK, &l) < 0)
- return -1;
- if (l.l_type == F_UNLCK || l.l_pid == getpid())
- return 0;
- errno = EACCES;
- return -1;
- case F_ULOCK:
- l.l_type = F_UNLCK;
- case F_TLOCK:
- return fcntl(fd, F_SETLK, &l);
- case F_LOCK:
- return fcntl(fd, F_SETLKW, &l);
- }
- errno = EINVAL;
- return -1;
-}
-
-weak_alias(lockf, lockf64);
lib/libc/wasi/libc-top-half/musl/src/misc/login_tty.c
@@ -1,14 +0,0 @@
-#include <utmp.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
-
-int login_tty(int fd)
-{
- setsid();
- if (ioctl(fd, TIOCSCTTY, (char *)0)) return -1;
- dup2(fd, 0);
- dup2(fd, 1);
- dup2(fd, 2);
- if (fd>2) close(fd);
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/misc/mntent.c
@@ -1,77 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <mntent.h>
-#include <errno.h>
-
-static char *internal_buf;
-static size_t internal_bufsize;
-
-#define SENTINEL (char *)&internal_buf
-
-FILE *setmntent(const char *name, const char *mode)
-{
- return fopen(name, mode);
-}
-
-int endmntent(FILE *f)
-{
- if (f) fclose(f);
- return 1;
-}
-
-struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int buflen)
-{
- int cnt, n[8], use_internal = (linebuf == SENTINEL);
-
- mnt->mnt_freq = 0;
- mnt->mnt_passno = 0;
-
- do {
- if (use_internal) {
- getline(&internal_buf, &internal_bufsize, f);
- linebuf = internal_buf;
- } else {
- fgets(linebuf, buflen, f);
- }
- if (feof(f) || ferror(f)) return 0;
- if (!strchr(linebuf, '\n')) {
- fscanf(f, "%*[^\n]%*[\n]");
- errno = ERANGE;
- return 0;
- }
- cnt = sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d",
- n, n+1, n+2, n+3, n+4, n+5, n+6, n+7,
- &mnt->mnt_freq, &mnt->mnt_passno);
- } while (cnt < 2 || linebuf[n[0]] == '#');
-
- linebuf[n[1]] = 0;
- linebuf[n[3]] = 0;
- linebuf[n[5]] = 0;
- linebuf[n[7]] = 0;
-
- mnt->mnt_fsname = linebuf+n[0];
- mnt->mnt_dir = linebuf+n[2];
- mnt->mnt_type = linebuf+n[4];
- mnt->mnt_opts = linebuf+n[6];
-
- return mnt;
-}
-
-struct mntent *getmntent(FILE *f)
-{
- static struct mntent mnt;
- return getmntent_r(f, &mnt, SENTINEL, 0);
-}
-
-int addmntent(FILE *f, const struct mntent *mnt)
-{
- if (fseek(f, 0, SEEK_END)) return 1;
- return fprintf(f, "%s\t%s\t%s\t%s\t%d\t%d\n",
- mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type, mnt->mnt_opts,
- mnt->mnt_freq, mnt->mnt_passno) < 0;
-}
-
-char *hasmntopt(const struct mntent *mnt, const char *opt)
-{
- return strstr(mnt->mnt_opts, opt);
-}
lib/libc/wasi/libc-top-half/musl/src/misc/openpty.c
@@ -1,40 +0,0 @@
-#include <stdlib.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <pty.h>
-#include <stdio.h>
-#include <pthread.h>
-
-/* Nonstandard, but vastly superior to the standard functions */
-
-int openpty(int *pm, int *ps, char *name, const struct termios *tio, const struct winsize *ws)
-{
- int m, s, n=0, cs;
- char buf[20];
-
- m = open("/dev/ptmx", O_RDWR|O_NOCTTY);
- if (m < 0) return -1;
-
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
-
- if (ioctl(m, TIOCSPTLCK, &n) || ioctl (m, TIOCGPTN, &n))
- goto fail;
-
- if (!name) name = buf;
- snprintf(name, sizeof buf, "/dev/pts/%d", n);
- if ((s = open(name, O_RDWR|O_NOCTTY)) < 0)
- goto fail;
-
- if (tio) tcsetattr(s, TCSANOW, tio);
- if (ws) ioctl(s, TIOCSWINSZ, ws);
-
- *pm = m;
- *ps = s;
-
- pthread_setcancelstate(cs, 0);
- return 0;
-fail:
- close(m);
- pthread_setcancelstate(cs, 0);
- return -1;
-}
lib/libc/wasi/libc-top-half/musl/src/misc/ptsname.c
@@ -1,13 +0,0 @@
-#include <stdlib.h>
-#include <errno.h>
-
-char *ptsname(int fd)
-{
- static char buf[9 + sizeof(int)*3 + 1];
- int err = __ptsname_r(fd, buf, sizeof buf);
- if (err) {
- errno = err;
- return 0;
- }
- return buf;
-}
lib/libc/wasi/libc-top-half/musl/src/misc/pty.c
@@ -1,35 +0,0 @@
-#include <stdlib.h>
-#include <sys/ioctl.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <errno.h>
-#include "syscall.h"
-
-int posix_openpt(int flags)
-{
- int r = open("/dev/ptmx", flags);
- if (r < 0 && errno == ENOSPC) errno = EAGAIN;
- return r;
-}
-
-int grantpt(int fd)
-{
- return 0;
-}
-
-int unlockpt(int fd)
-{
- int unlock = 0;
- return ioctl(fd, TIOCSPTLCK, &unlock);
-}
-
-int __ptsname_r(int fd, char *buf, size_t len)
-{
- int pty, err;
- if (!buf) len = 0;
- if ((err = __syscall(SYS_ioctl, fd, TIOCGPTN, &pty))) return -err;
- if (snprintf(buf, len, "/dev/pts/%d", pty) >= len) return ERANGE;
- return 0;
-}
-
-weak_alias(__ptsname_r, ptsname_r);
lib/libc/wasi/libc-top-half/musl/src/misc/realpath.c
@@ -1,156 +0,0 @@
-#include <stdlib.h>
-#include <limits.h>
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
-
-static size_t slash_len(const char *s)
-{
- const char *s0 = s;
- while (*s == '/') s++;
- return s-s0;
-}
-
-char *realpath(const char *restrict filename, char *restrict resolved)
-{
- char stack[PATH_MAX+1];
- char output[PATH_MAX];
- size_t p, q, l, l0, cnt=0, nup=0;
- int check_dir=0;
-
- if (!filename) {
- errno = EINVAL;
- return 0;
- }
- l = strnlen(filename, sizeof stack);
- if (!l) {
- errno = ENOENT;
- return 0;
- }
- if (l >= PATH_MAX) goto toolong;
- p = sizeof stack - l - 1;
- q = 0;
- memcpy(stack+p, filename, l+1);
-
- /* Main loop. Each iteration pops the next part from stack of
- * remaining path components and consumes any slashes that follow.
- * If not a link, it's moved to output; if a link, contents are
- * pushed to the stack. */
-restart:
- for (; ; p+=slash_len(stack+p)) {
- /* If stack starts with /, the whole component is / or //
- * and the output state must be reset. */
- if (stack[p] == '/') {
- check_dir=0;
- nup=0;
- q=0;
- output[q++] = '/';
- p++;
- /* Initial // is special. */
- if (stack[p] == '/' && stack[p+1] != '/')
- output[q++] = '/';
- continue;
- }
-
- char *z = __strchrnul(stack+p, '/');
- l0 = l = z-(stack+p);
-
- if (!l && !check_dir) break;
-
- /* Skip any . component but preserve check_dir status. */
- if (l==1 && stack[p]=='.') {
- p += l;
- continue;
- }
-
- /* Copy next component onto output at least temporarily, to
- * call readlink, but wait to advance output position until
- * determining it's not a link. */
- if (q && output[q-1] != '/') {
- if (!p) goto toolong;
- stack[--p] = '/';
- l++;
- }
- if (q+l >= PATH_MAX) goto toolong;
- memcpy(output+q, stack+p, l);
- output[q+l] = 0;
- p += l;
-
- int up = 0;
- if (l0==2 && stack[p-2]=='.' && stack[p-1]=='.') {
- up = 1;
- /* Any non-.. path components we could cancel start
- * after nup repetitions of the 3-byte string "../";
- * if there are none, accumulate .. components to
- * later apply to cwd, if needed. */
- if (q <= 3*nup) {
- nup++;
- q += l;
- continue;
- }
- /* When previous components are already known to be
- * directories, processing .. can skip readlink. */
- if (!check_dir) goto skip_readlink;
- }
- ssize_t k = readlink(output, stack, p);
- if (k==p) goto toolong;
- if (!k) {
- errno = ENOENT;
- return 0;
- }
- if (k<0) {
- if (errno != EINVAL) return 0;
-skip_readlink:
- check_dir = 0;
- if (up) {
- while(q && output[q-1]!='/') q--;
- if (q>1 && (q>2 || output[0]!='/')) q--;
- continue;
- }
- if (l0) q += l;
- check_dir = stack[p];
- continue;
- }
- if (++cnt == SYMLOOP_MAX) {
- errno = ELOOP;
- return 0;
- }
-
- /* If link contents end in /, strip any slashes already on
- * stack to avoid /->// or //->/// or spurious toolong. */
- if (stack[k-1]=='/') while (stack[p]=='/') p++;
- p -= k;
- memmove(stack+p, stack, k);
-
- /* Skip the stack advancement in case we have a new
- * absolute base path. */
- goto restart;
- }
-
- output[q] = 0;
-
- if (output[0] != '/') {
- if (!getcwd(stack, sizeof stack)) return 0;
- l = strlen(stack);
- /* Cancel any initial .. components. */
- p = 0;
- while (nup--) {
- while(l>1 && stack[l-1]!='/') l--;
- if (l>1) l--;
- p += 2;
- if (p<q) p++;
- }
- if (q-p && stack[l-1]!='/') stack[l++] = '/';
- if (l + (q-p) + 1 >= PATH_MAX) goto toolong;
- memmove(output + l, output + p, q - p + 1);
- memcpy(output, stack, l);
- q = l + q-p;
- }
-
- if (resolved) return memcpy(resolved, output, q+1);
- else return strdup(output);
-
-toolong:
- errno = ENAMETOOLONG;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/misc/setdomainname.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include "syscall.h"
-
-int setdomainname(const char *name, size_t len)
-{
- return syscall(SYS_setdomainname, name, len);
-}
lib/libc/wasi/libc-top-half/musl/src/misc/setpriority.c
@@ -1,7 +0,0 @@
-#include <sys/resource.h>
-#include "syscall.h"
-
-int setpriority(int which, id_t who, int prio)
-{
- return syscall(SYS_setpriority, which, who, prio);
-}
lib/libc/wasi/libc-top-half/musl/src/misc/setrlimit.c
@@ -1,47 +0,0 @@
-#include <sys/resource.h>
-#include <errno.h>
-#include "syscall.h"
-#include "libc.h"
-
-#define MIN(a, b) ((a)<(b) ? (a) : (b))
-#define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0)
-
-struct ctx {
- unsigned long lim[2];
- int res;
- int err;
-};
-
-static void do_setrlimit(void *p)
-{
- struct ctx *c = p;
- if (c->err>0) return;
- c->err = -__syscall(SYS_setrlimit, c->res, c->lim);
-}
-
-int setrlimit(int resource, const struct rlimit *rlim)
-{
- struct rlimit tmp;
- if (SYSCALL_RLIM_INFINITY != RLIM_INFINITY) {
- tmp = *rlim;
- FIX(tmp.rlim_cur);
- FIX(tmp.rlim_max);
- rlim = &tmp;
- }
- int ret = __syscall(SYS_prlimit64, 0, resource, rlim, 0);
- if (ret != -ENOSYS) return __syscall_ret(ret);
-
- struct ctx c = {
- .lim[0] = MIN(rlim->rlim_cur, MIN(-1UL, SYSCALL_RLIM_INFINITY)),
- .lim[1] = MIN(rlim->rlim_max, MIN(-1UL, SYSCALL_RLIM_INFINITY)),
- .res = resource, .err = -1
- };
- __synccall(do_setrlimit, &c);
- if (c.err) {
- if (c.err>0) errno = c.err;
- return -1;
- }
- return 0;
-}
-
-weak_alias(setrlimit, setrlimit64);
lib/libc/wasi/libc-top-half/musl/src/misc/syscall.c
@@ -1,21 +0,0 @@
-#define _BSD_SOURCE
-#include <unistd.h>
-#include "syscall.h"
-#include <stdarg.h>
-
-#undef syscall
-
-long syscall(long n, ...)
-{
- va_list ap;
- syscall_arg_t a,b,c,d,e,f;
- va_start(ap, n);
- a=va_arg(ap, syscall_arg_t);
- b=va_arg(ap, syscall_arg_t);
- c=va_arg(ap, syscall_arg_t);
- d=va_arg(ap, syscall_arg_t);
- e=va_arg(ap, syscall_arg_t);
- f=va_arg(ap, syscall_arg_t);
- va_end(ap);
- return __syscall_ret(__syscall(n,a,b,c,d,e,f));
-}
lib/libc/wasi/libc-top-half/musl/src/misc/syslog.c
@@ -1,162 +0,0 @@
-#include <stdarg.h>
-#include <sys/socket.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <time.h>
-#include <signal.h>
-#include <string.h>
-#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
-#include <pthread.h>
-#endif
-#include <errno.h>
-#include <fcntl.h>
-#include "lock.h"
-#include "fork_impl.h"
-
-static volatile int lock[1];
-static char log_ident[32];
-static int log_opt;
-static int log_facility = LOG_USER;
-static int log_mask = 0xff;
-static int log_fd = -1;
-volatile int *const __syslog_lockptr = lock;
-
-int setlogmask(int maskpri)
-{
- LOCK(lock);
- int ret = log_mask;
- if (maskpri) log_mask = maskpri;
- UNLOCK(lock);
- return ret;
-}
-
-static const struct {
- short sun_family;
- char sun_path[9];
-} log_addr = {
- AF_UNIX,
- "/dev/log"
-};
-
-void closelog(void)
-{
-#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
- int cs;
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
-#endif
- LOCK(lock);
- close(log_fd);
- log_fd = -1;
- UNLOCK(lock);
-#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
- pthread_setcancelstate(cs, 0);
-#endif
-}
-
-static void __openlog()
-{
- log_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
- if (log_fd >= 0) connect(log_fd, (void *)&log_addr, sizeof log_addr);
-}
-
-void openlog(const char *ident, int opt, int facility)
-{
-#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
- int cs;
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
-#endif
- LOCK(lock);
-
- if (ident) {
- size_t n = strnlen(ident, sizeof log_ident - 1);
- memcpy(log_ident, ident, n);
- log_ident[n] = 0;
- } else {
- log_ident[0] = 0;
- }
- log_opt = opt;
- log_facility = facility;
-
- if ((opt & LOG_NDELAY) && log_fd<0) __openlog();
-
- UNLOCK(lock);
-#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
- pthread_setcancelstate(cs, 0);
-#endif
-}
-
-static int is_lost_conn(int e)
-{
- return e==ECONNREFUSED || e==ECONNRESET || e==ENOTCONN || e==EPIPE;
-}
-
-static void _vsyslog(int priority, const char *message, va_list ap)
-{
- char timebuf[16];
- time_t now;
- struct tm tm;
- char buf[1024];
- int errno_save = errno;
- int pid;
- int l, l2;
- int hlen;
- int fd;
-
- if (log_fd < 0) __openlog();
-
- if (!(priority & LOG_FACMASK)) priority |= log_facility;
-
- now = time(NULL);
- gmtime_r(&now, &tm);
- strftime(timebuf, sizeof timebuf, "%b %e %T", &tm);
-
- pid = (log_opt & LOG_PID) ? getpid() : 0;
- l = snprintf(buf, sizeof buf, "<%d>%s %n%s%s%.0d%s: ",
- priority, timebuf, &hlen, log_ident, "["+!pid, pid, "]"+!pid);
- errno = errno_save;
- l2 = vsnprintf(buf+l, sizeof buf - l, message, ap);
- if (l2 >= 0) {
- if (l2 >= sizeof buf - l) l = sizeof buf - 1;
- else l += l2;
- if (buf[l-1] != '\n') buf[l++] = '\n';
- if (send(log_fd, buf, l, 0) < 0 && (!is_lost_conn(errno)
- || connect(log_fd, (void *)&log_addr, sizeof log_addr) < 0
- || send(log_fd, buf, l, 0) < 0)
- && (log_opt & LOG_CONS)) {
- fd = open("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
- if (fd >= 0) {
- dprintf(fd, "%.*s", l-hlen, buf+hlen);
- close(fd);
- }
- }
- if (log_opt & LOG_PERROR) dprintf(2, "%.*s", l-hlen, buf+hlen);
- }
-}
-
-static void __vsyslog(int priority, const char *message, va_list ap)
-{
-#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
- int cs;
-#endif
- if (!(log_mask & LOG_MASK(priority&7)) || (priority&~0x3ff)) return;
-#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
-#endif
- LOCK(lock);
- _vsyslog(priority, message, ap);
- UNLOCK(lock);
-#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
- pthread_setcancelstate(cs, 0);
-#endif
-}
-
-void syslog(int priority, const char *message, ...)
-{
- va_list ap;
- va_start(ap, message);
- __vsyslog(priority, message, ap);
- va_end(ap);
-}
-
-weak_alias(__vsyslog, vsyslog);
lib/libc/wasi/libc-top-half/musl/src/misc/wordexp.c
@@ -1,187 +0,0 @@
-#include <wordexp.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <limits.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <sys/wait.h>
-#include <signal.h>
-#include <errno.h>
-#include <fcntl.h>
-#include "pthread_impl.h"
-
-static void reap(pid_t pid)
-{
- int status;
- while (waitpid(pid, &status, 0) < 0 && errno == EINTR);
-}
-
-static char *getword(FILE *f)
-{
- char *s = 0;
- return getdelim(&s, (size_t [1]){0}, 0, f) < 0 ? 0 : s;
-}
-
-static int do_wordexp(const char *s, wordexp_t *we, int flags)
-{
- size_t i, l;
- int sq=0, dq=0;
- size_t np=0;
- char *w, **tmp;
- char *redir = (flags & WRDE_SHOWERR) ? "" : "2>/dev/null";
- int err = 0;
- FILE *f;
- size_t wc = 0;
- char **wv = 0;
- int p[2];
- pid_t pid;
- sigset_t set;
-
- if (flags & WRDE_REUSE) wordfree(we);
-
- if (flags & WRDE_NOCMD) for (i=0; s[i]; i++) switch (s[i]) {
- case '\\':
- if (!sq && !s[++i]) return WRDE_SYNTAX;
- break;
- case '\'':
- if (!dq) sq^=1;
- break;
- case '"':
- if (!sq) dq^=1;
- break;
- case '(':
- if (np) {
- np++;
- break;
- }
- case ')':
- if (np) {
- np--;
- break;
- }
- case '\n':
- case '|':
- case '&':
- case ';':
- case '<':
- case '>':
- case '{':
- case '}':
- if (!(sq|dq|np)) return WRDE_BADCHAR;
- break;
- case '$':
- if (sq) break;
- if (s[i+1]=='(' && s[i+2]=='(') {
- i += 2;
- np += 2;
- break;
- } else if (s[i+1] != '(') break;
- case '`':
- if (sq) break;
- return WRDE_CMDSUB;
- }
-
- if (flags & WRDE_APPEND) {
- wc = we->we_wordc;
- wv = we->we_wordv;
- }
-
- i = wc;
- if (flags & WRDE_DOOFFS) {
- if (we->we_offs > SIZE_MAX/sizeof(void *)/4)
- goto nospace;
- i += we->we_offs;
- } else {
- we->we_offs = 0;
- }
-
- if (pipe2(p, O_CLOEXEC) < 0) goto nospace;
- __block_all_sigs(&set);
- pid = fork();
- __restore_sigs(&set);
- if (pid < 0) {
- close(p[0]);
- close(p[1]);
- goto nospace;
- }
- if (!pid) {
- if (p[1] == 1) fcntl(1, F_SETFD, 0);
- else dup2(p[1], 1);
- execl("/bin/sh", "sh", "-c",
- "eval \"printf %s\\\\\\\\0 x $1 $2\"",
- "sh", s, redir, (char *)0);
- _exit(1);
- }
- close(p[1]);
-
- f = fdopen(p[0], "r");
- if (!f) {
- close(p[0]);
- kill(pid, SIGKILL);
- reap(pid);
- goto nospace;
- }
-
- l = wv ? i+1 : 0;
-
- free(getword(f));
- if (feof(f)) {
- fclose(f);
- reap(pid);
- return WRDE_SYNTAX;
- }
-
- while ((w = getword(f))) {
- if (i+1 >= l) {
- l += l/2+10;
- tmp = realloc(wv, l*sizeof(char *));
- if (!tmp) break;
- wv = tmp;
- }
- wv[i++] = w;
- wv[i] = 0;
- }
- if (!feof(f)) err = WRDE_NOSPACE;
-
- fclose(f);
- reap(pid);
-
- if (!wv) wv = calloc(i+1, sizeof *wv);
-
- we->we_wordv = wv;
- we->we_wordc = i;
-
- if (flags & WRDE_DOOFFS) {
- if (wv) for (i=we->we_offs; i; i--)
- we->we_wordv[i-1] = 0;
- we->we_wordc -= we->we_offs;
- }
- return err;
-
-nospace:
- if (!(flags & WRDE_APPEND)) {
- we->we_wordc = 0;
- we->we_wordv = 0;
- }
- return WRDE_NOSPACE;
-}
-
-int wordexp(const char *restrict s, wordexp_t *restrict we, int flags)
-{
- int r, cs;
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
- r = do_wordexp(s, we, flags);
- pthread_setcancelstate(cs, 0);
- return r;
-}
-
-void wordfree(wordexp_t *we)
-{
- size_t i;
- if (!we->we_wordv) return;
- for (i=0; i<we->we_wordc; i++) free(we->we_wordv[we->we_offs+i]);
- free(we->we_wordv);
- we->we_wordv = 0;
- we->we_wordc = 0;
-}
lib/libc/wasi/libc-top-half/musl/src/mman/madvise.c
@@ -1,9 +0,0 @@
-#include <sys/mman.h>
-#include "syscall.h"
-
-int __madvise(void *addr, size_t len, int advice)
-{
- return syscall(SYS_madvise, addr, len, advice);
-}
-
-weak_alias(__madvise, madvise);
lib/libc/wasi/libc-top-half/musl/src/mman/mincore.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <sys/mman.h>
-#include "syscall.h"
-
-int mincore (void *addr, size_t len, unsigned char *vec)
-{
- return syscall(SYS_mincore, addr, len, vec);
-}
lib/libc/wasi/libc-top-half/musl/src/mman/mlock.c
@@ -1,11 +0,0 @@
-#include <sys/mman.h>
-#include "syscall.h"
-
-int mlock(const void *addr, size_t len)
-{
-#ifdef SYS_mlock
- return syscall(SYS_mlock, addr, len);
-#else
- return syscall(SYS_mlock2, addr, len, 0);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/mman/mlockall.c
@@ -1,7 +0,0 @@
-#include <sys/mman.h>
-#include "syscall.h"
-
-int mlockall(int flags)
-{
- return syscall(SYS_mlockall, flags);
-}
lib/libc/wasi/libc-top-half/musl/src/mman/mmap.c
@@ -1,41 +0,0 @@
-#include <unistd.h>
-#include <sys/mman.h>
-#include <errno.h>
-#include <stdint.h>
-#include <limits.h>
-#include "syscall.h"
-
-static void dummy(void) { }
-weak_alias(dummy, __vm_wait);
-
-#define UNIT SYSCALL_MMAP2_UNIT
-#define OFF_MASK ((-0x2000ULL << (8*sizeof(syscall_arg_t)-1)) | (UNIT-1))
-
-void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off)
-{
- long ret;
- if (off & OFF_MASK) {
- errno = EINVAL;
- return MAP_FAILED;
- }
- if (len >= PTRDIFF_MAX) {
- errno = ENOMEM;
- return MAP_FAILED;
- }
- if (flags & MAP_FIXED) {
- __vm_wait();
- }
-#ifdef SYS_mmap2
- ret = __syscall(SYS_mmap2, start, len, prot, flags, fd, off/UNIT);
-#else
- ret = __syscall(SYS_mmap, start, len, prot, flags, fd, off);
-#endif
- /* Fixup incorrect EPERM from kernel. */
- if (ret == -EPERM && !start && (flags&MAP_ANON) && !(flags&MAP_FIXED))
- ret = -ENOMEM;
- return (void *)__syscall_ret(ret);
-}
-
-weak_alias(__mmap, mmap);
-
-weak_alias(mmap, mmap64);
lib/libc/wasi/libc-top-half/musl/src/mman/mprotect.c
@@ -1,13 +0,0 @@
-#include <sys/mman.h>
-#include "libc.h"
-#include "syscall.h"
-
-int __mprotect(void *addr, size_t len, int prot)
-{
- size_t start, end;
- start = (size_t)addr & -PAGE_SIZE;
- end = (size_t)((char *)addr + len + PAGE_SIZE-1) & -PAGE_SIZE;
- return syscall(SYS_mprotect, start, end-start, prot);
-}
-
-weak_alias(__mprotect, mprotect);
lib/libc/wasi/libc-top-half/musl/src/mman/mremap.c
@@ -1,32 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include <sys/mman.h>
-#include <errno.h>
-#include <stdint.h>
-#include <stdarg.h>
-#include "syscall.h"
-
-static void dummy(void) { }
-weak_alias(dummy, __vm_wait);
-
-void *__mremap(void *old_addr, size_t old_len, size_t new_len, int flags, ...)
-{
- va_list ap;
- void *new_addr = 0;
-
- if (new_len >= PTRDIFF_MAX) {
- errno = ENOMEM;
- return MAP_FAILED;
- }
-
- if (flags & MREMAP_FIXED) {
- __vm_wait();
- va_start(ap, flags);
- new_addr = va_arg(ap, void *);
- va_end(ap);
- }
-
- return (void *)syscall(SYS_mremap, old_addr, old_len, new_len, flags, new_addr);
-}
-
-weak_alias(__mremap, mremap);
lib/libc/wasi/libc-top-half/musl/src/mman/msync.c
@@ -1,7 +0,0 @@
-#include <sys/mman.h>
-#include "syscall.h"
-
-int msync(void *start, size_t len, int flags)
-{
- return syscall_cp(SYS_msync, start, len, flags);
-}
lib/libc/wasi/libc-top-half/musl/src/mman/munlock.c
@@ -1,7 +0,0 @@
-#include <sys/mman.h>
-#include "syscall.h"
-
-int munlock(const void *addr, size_t len)
-{
- return syscall(SYS_munlock, addr, len);
-}
lib/libc/wasi/libc-top-half/musl/src/mman/munlockall.c
@@ -1,7 +0,0 @@
-#include <sys/mman.h>
-#include "syscall.h"
-
-int munlockall(void)
-{
- return syscall(SYS_munlockall);
-}
lib/libc/wasi/libc-top-half/musl/src/mman/munmap.c
@@ -1,13 +0,0 @@
-#include <sys/mman.h>
-#include "syscall.h"
-
-static void dummy(void) { }
-weak_alias(dummy, __vm_wait);
-
-int __munmap(void *start, size_t len)
-{
- __vm_wait();
- return syscall(SYS_munmap, start, len);
-}
-
-weak_alias(__munmap, munmap);
lib/libc/wasi/libc-top-half/musl/src/mman/posix_madvise.c
@@ -1,9 +0,0 @@
-#define _GNU_SOURCE
-#include <sys/mman.h>
-#include "syscall.h"
-
-int posix_madvise(void *addr, size_t len, int advice)
-{
- if (advice == MADV_DONTNEED) return 0;
- return -__syscall(SYS_madvise, addr, len, advice);
-}
lib/libc/wasi/libc-top-half/musl/src/mman/shm_open.c
@@ -1,43 +0,0 @@
-#include <sys/mman.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
-#include <limits.h>
-#include <pthread.h>
-
-char *__shm_mapname(const char *name, char *buf)
-{
- char *p;
- while (*name == '/') name++;
- if (*(p = __strchrnul(name, '/')) || p==name ||
- (p-name <= 2 && name[0]=='.' && p[-1]=='.')) {
- errno = EINVAL;
- return 0;
- }
- if (p-name > NAME_MAX) {
- errno = ENAMETOOLONG;
- return 0;
- }
- memcpy(buf, "/dev/shm/", 9);
- memcpy(buf+9, name, p-name+1);
- return buf;
-}
-
-int shm_open(const char *name, int flag, mode_t mode)
-{
- int cs;
- char buf[NAME_MAX+10];
- if (!(name = __shm_mapname(name, buf))) return -1;
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
- int fd = open(name, flag|O_NOFOLLOW|O_CLOEXEC|O_NONBLOCK, mode);
- pthread_setcancelstate(cs, 0);
- return fd;
-}
-
-int shm_unlink(const char *name)
-{
- char buf[NAME_MAX+10];
- if (!(name = __shm_mapname(name, buf))) return -1;
- return unlink(name);
-}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_close.c
@@ -1,7 +0,0 @@
-#include <mqueue.h>
-#include "syscall.h"
-
-int mq_close(mqd_t mqd)
-{
- return syscall(SYS_close, mqd);
-}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_getattr.c
@@ -1,7 +0,0 @@
-#include <mqueue.h>
-#include "syscall.h"
-
-int mq_getattr(mqd_t mqd, struct mq_attr *attr)
-{
- return mq_setattr(mqd, 0, attr);
-}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_notify.c
@@ -1,73 +0,0 @@
-#include <mqueue.h>
-#include <pthread.h>
-#include <errno.h>
-#include <sys/socket.h>
-#include <signal.h>
-#include <unistd.h>
-#include "syscall.h"
-
-struct args {
- pthread_barrier_t barrier;
- int sock;
- const struct sigevent *sev;
-};
-
-static void *start(void *p)
-{
- struct args *args = p;
- char buf[32];
- ssize_t n;
- int s = args->sock;
- void (*func)(union sigval) = args->sev->sigev_notify_function;
- union sigval val = args->sev->sigev_value;
-
- pthread_barrier_wait(&args->barrier);
- n = recv(s, buf, sizeof(buf), MSG_NOSIGNAL|MSG_WAITALL);
- close(s);
- if (n==sizeof buf && buf[sizeof buf - 1] == 1)
- func(val);
- return 0;
-}
-
-int mq_notify(mqd_t mqd, const struct sigevent *sev)
-{
- struct args args = { .sev = sev };
- pthread_attr_t attr;
- pthread_t td;
- int s;
- struct sigevent sev2;
- static const char zeros[32];
-
- if (!sev || sev->sigev_notify != SIGEV_THREAD)
- return syscall(SYS_mq_notify, mqd, sev);
-
- s = socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, 0);
- if (s < 0) return -1;
- args.sock = s;
-
- if (sev->sigev_notify_attributes) attr = *sev->sigev_notify_attributes;
- else pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- pthread_barrier_init(&args.barrier, 0, 2);
-
- if (pthread_create(&td, &attr, start, &args)) {
- __syscall(SYS_close, s);
- errno = EAGAIN;
- return -1;
- }
-
- pthread_barrier_wait(&args.barrier);
- pthread_barrier_destroy(&args.barrier);
-
- sev2.sigev_notify = SIGEV_THREAD;
- sev2.sigev_signo = s;
- sev2.sigev_value.sival_ptr = (void *)&zeros;
-
- if (syscall(SYS_mq_notify, mqd, &sev2) < 0) {
- pthread_cancel(td);
- __syscall(SYS_close, s);
- return -1;
- }
-
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_open.c
@@ -1,19 +0,0 @@
-#include <mqueue.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#include "syscall.h"
-
-mqd_t mq_open(const char *name, int flags, ...)
-{
- mode_t mode = 0;
- struct mq_attr *attr = 0;
- if (*name == '/') name++;
- if (flags & O_CREAT) {
- va_list ap;
- va_start(ap, flags);
- mode = va_arg(ap, mode_t);
- attr = va_arg(ap, struct mq_attr *);
- va_end(ap);
- }
- return syscall(SYS_mq_open, name, flags, mode, attr);
-}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_receive.c
@@ -1,6 +0,0 @@
-#include <mqueue.h>
-
-ssize_t mq_receive(mqd_t mqd, char *msg, size_t len, unsigned *prio)
-{
- return mq_timedreceive(mqd, msg, len, prio, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_send.c
@@ -1,6 +0,0 @@
-#include <mqueue.h>
-
-int mq_send(mqd_t mqd, const char *msg, size_t len, unsigned prio)
-{
- return mq_timedsend(mqd, msg, len, prio, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_setattr.c
@@ -1,7 +0,0 @@
-#include <mqueue.h>
-#include "syscall.h"
-
-int mq_setattr(mqd_t mqd, const struct mq_attr *restrict new, struct mq_attr *restrict old)
-{
- return syscall(SYS_mq_getsetattr, mqd, new, old);
-}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_timedreceive.c
@@ -1,24 +0,0 @@
-#include <mqueue.h>
-#include <errno.h>
-#include "syscall.h"
-
-#define IS32BIT(x) !((x)+0x80000000ULL>>32)
-#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
-
-ssize_t mq_timedreceive(mqd_t mqd, char *restrict msg, size_t len, unsigned *restrict prio, const struct timespec *restrict at)
-{
-#ifdef SYS_mq_timedreceive_time64
- time_t s = at ? at->tv_sec : 0;
- long ns = at ? at->tv_nsec : 0;
- long r = -ENOSYS;
- if (SYS_mq_timedreceive == SYS_mq_timedreceive_time64 || !IS32BIT(s))
- r = __syscall_cp(SYS_mq_timedreceive_time64, mqd, msg, len, prio,
- at ? ((long long []){at->tv_sec, at->tv_nsec}) : 0);
- if (SYS_mq_timedreceive == SYS_mq_timedreceive_time64 || r != -ENOSYS)
- return __syscall_ret(r);
- return syscall_cp(SYS_mq_timedreceive, mqd, msg, len, prio,
- at ? ((long[]){CLAMP(s), ns}) : 0);
-#else
- return syscall_cp(SYS_mq_timedreceive, mqd, msg, len, prio, at);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_timedsend.c
@@ -1,24 +0,0 @@
-#include <mqueue.h>
-#include <errno.h>
-#include "syscall.h"
-
-#define IS32BIT(x) !((x)+0x80000000ULL>>32)
-#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
-
-int mq_timedsend(mqd_t mqd, const char *msg, size_t len, unsigned prio, const struct timespec *at)
-{
-#ifdef SYS_mq_timedsend_time64
- time_t s = at ? at->tv_sec : 0;
- long ns = at ? at->tv_nsec : 0;
- long r = -ENOSYS;
- if (SYS_mq_timedsend == SYS_mq_timedsend_time64 || !IS32BIT(s))
- r = __syscall_cp(SYS_mq_timedsend_time64, mqd, msg, len, prio,
- at ? ((long long []){at->tv_sec, at->tv_nsec}) : 0);
- if (SYS_mq_timedsend == SYS_mq_timedsend_time64 || r != -ENOSYS)
- return __syscall_ret(r);
- return syscall_cp(SYS_mq_timedsend, mqd, msg, len, prio,
- at ? ((long[]){CLAMP(s), ns}) : 0);
-#else
- return syscall_cp(SYS_mq_timedsend, mqd, msg, len, prio, at);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_unlink.c
@@ -1,16 +0,0 @@
-#include <mqueue.h>
-#include <errno.h>
-#include "syscall.h"
-
-int mq_unlink(const char *name)
-{
- int ret;
- if (*name == '/') name++;
- ret = __syscall(SYS_mq_unlink, name);
- if (ret < 0) {
- if (ret == -EPERM) ret = -EACCES;
- errno = -ret;
- return -1;
- }
- return ret;
-}
lib/libc/wasi/libc-top-half/musl/src/network/accept.c
@@ -1,7 +0,0 @@
-#include <sys/socket.h>
-#include "syscall.h"
-
-int accept(int fd, struct sockaddr *restrict addr, socklen_t *restrict len)
-{
- return socketcall_cp(accept, fd, addr, len, 0, 0, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/network/accept4.c
@@ -1,19 +0,0 @@
-#define _GNU_SOURCE
-#include <sys/socket.h>
-#include <errno.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int accept4(int fd, struct sockaddr *restrict addr, socklen_t *restrict len, int flg)
-{
- if (!flg) return accept(fd, addr, len);
- int ret = socketcall_cp(accept4, fd, addr, len, flg, 0, 0);
- if (ret>=0 || (errno != ENOSYS && errno != EINVAL)) return ret;
- ret = accept(fd, addr, len);
- if (ret<0) return ret;
- if (flg & SOCK_CLOEXEC)
- __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC);
- if (flg & SOCK_NONBLOCK)
- __syscall(SYS_fcntl, ret, F_SETFL, O_NONBLOCK);
- return ret;
-}
lib/libc/wasi/libc-top-half/musl/src/network/bind.c
@@ -1,7 +0,0 @@
-#include <sys/socket.h>
-#include "syscall.h"
-
-int bind(int fd, const struct sockaddr *addr, socklen_t len)
-{
- return socketcall(bind, fd, addr, len, 0, 0, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/network/connect.c
@@ -1,7 +0,0 @@
-#include <sys/socket.h>
-#include "syscall.h"
-
-int connect(int fd, const struct sockaddr *addr, socklen_t len)
-{
- return socketcall_cp(connect, fd, addr, len, 0, 0, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/network/dn_comp.c
@@ -1,107 +0,0 @@
-#include <string.h>
-#include <resolv.h>
-
-/* RFC 1035 message compression */
-
-/* label start offsets of a compressed domain name s */
-static int getoffs(short *offs, const unsigned char *base, const unsigned char *s)
-{
- int i=0;
- for (;;) {
- while (*s & 0xc0) {
- if ((*s & 0xc0) != 0xc0) return 0;
- s = base + ((s[0]&0x3f)<<8 | s[1]);
- }
- if (!*s) return i;
- if (s-base >= 0x4000) return 0;
- offs[i++] = s-base;
- s += *s + 1;
- }
-}
-
-/* label lengths of an ascii domain name s */
-static int getlens(unsigned char *lens, const char *s, int l)
-{
- int i=0,j=0,k=0;
- for (;;) {
- for (; j<l && s[j]!='.'; j++);
- if (j-k-1u > 62) return 0;
- lens[i++] = j-k;
- if (j==l) return i;
- k = ++j;
- }
-}
-
-/* longest suffix match of an ascii domain with a compressed domain name dn */
-static int match(int *offset, const unsigned char *base, const unsigned char *dn,
- const char *end, const unsigned char *lens, int nlen)
-{
- int l, o, m=0;
- short offs[128];
- int noff = getoffs(offs, base, dn);
- if (!noff) return 0;
- for (;;) {
- l = lens[--nlen];
- o = offs[--noff];
- end -= l;
- if (l != base[o] || memcmp(base+o+1, end, l))
- return m;
- *offset = o;
- m += l;
- if (nlen) m++;
- if (!nlen || !noff) return m;
- end--;
- }
-}
-
-int dn_comp(const char *src, unsigned char *dst, int space, unsigned char **dnptrs, unsigned char **lastdnptr)
-{
- int i, j, n, m=0, offset, bestlen=0, bestoff;
- unsigned char lens[127];
- unsigned char **p;
- const char *end;
- size_t l = strnlen(src, 255);
- if (l && src[l-1] == '.') l--;
- if (l>253 || space<=0) return -1;
- if (!l) {
- *dst = 0;
- return 1;
- }
- end = src+l;
- n = getlens(lens, src, l);
- if (!n) return -1;
-
- p = dnptrs;
- if (p && *p) for (p++; *p; p++) {
- m = match(&offset, *dnptrs, *p, end, lens, n);
- if (m > bestlen) {
- bestlen = m;
- bestoff = offset;
- if (m == l)
- break;
- }
- }
-
- /* encode unmatched part */
- if (space < l-bestlen+2+(bestlen-1 < l-1)) return -1;
- memcpy(dst+1, src, l-bestlen);
- for (i=j=0; i<l-bestlen; i+=lens[j++]+1)
- dst[i] = lens[j];
-
- /* add tail */
- if (bestlen) {
- dst[i++] = 0xc0 | bestoff>>8;
- dst[i++] = bestoff;
- } else
- dst[i++] = 0;
-
- /* save dst pointer */
- if (i>2 && lastdnptr && dnptrs && *dnptrs) {
- while (*p) p++;
- if (p+1 < lastdnptr) {
- *p++ = dst;
- *p=0;
- }
- }
- return i;
-}
lib/libc/wasi/libc-top-half/musl/src/network/dn_expand.c
@@ -1,33 +0,0 @@
-#include <resolv.h>
-
-int __dn_expand(const unsigned char *base, const unsigned char *end, const unsigned char *src, char *dest, int space)
-{
- const unsigned char *p = src;
- char *dend, *dbegin = dest;
- int len = -1, i, j;
- if (p==end || space <= 0) return -1;
- dend = dest + (space > 254 ? 254 : space);
- /* detect reference loop using an iteration counter */
- for (i=0; i < end-base; i+=2) {
- /* loop invariants: p<end, dest<dend */
- if (*p & 0xc0) {
- if (p+1==end) return -1;
- j = ((p[0] & 0x3f) << 8) | p[1];
- if (len < 0) len = p+2-src;
- if (j >= end-base) return -1;
- p = base+j;
- } else if (*p) {
- if (dest != dbegin) *dest++ = '.';
- j = *p++;
- if (j >= end-p || j >= dend-dest) return -1;
- while (j--) *dest++ = *p++;
- } else {
- *dest = 0;
- if (len < 0) len = p+1-src;
- return len;
- }
- }
- return -1;
-}
-
-weak_alias(__dn_expand, dn_expand);
lib/libc/wasi/libc-top-half/musl/src/network/dn_skipname.c
@@ -1,15 +0,0 @@
-#include <resolv.h>
-
-int dn_skipname(const unsigned char *s, const unsigned char *end)
-{
- const unsigned char *p = s;
- while (p < end)
- if (!*p) return p-s+1;
- else if (*p>=192)
- if (p+1<end) return p-s+2;
- else break;
- else
- if (end-p<*p+1) break;
- else p += *p + 1;
- return -1;
-}
lib/libc/wasi/libc-top-half/musl/src/network/dns_parse.c
@@ -1,33 +0,0 @@
-#include <string.h>
-#include "lookup.h"
-
-int __dns_parse(const unsigned char *r, int rlen, int (*callback)(void *, int, const void *, int, const void *), void *ctx)
-{
- int qdcount, ancount;
- const unsigned char *p;
- int len;
-
- if (rlen<12) return -1;
- if ((r[3]&15)) return 0;
- p = r+12;
- qdcount = r[4]*256 + r[5];
- ancount = r[6]*256 + r[7];
- if (qdcount+ancount > 64) return -1;
- while (qdcount--) {
- while (p-r < rlen && *p-1U < 127) p++;
- if (*p>193 || (*p==193 && p[1]>254) || p>r+rlen-6)
- return -1;
- p += 5 + !!*p;
- }
- while (ancount--) {
- while (p-r < rlen && *p-1U < 127) p++;
- if (*p>193 || (*p==193 && p[1]>254) || p>r+rlen-6)
- return -1;
- p += 1 + !!*p;
- len = p[8]*256 + p[9];
- if (p+len > r+rlen) return -1;
- if (callback(ctx, p[1], p+10, len, r) < 0) return -1;
- p += 10 + len;
- }
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/network/ent.c
@@ -1,22 +0,0 @@
-#include <netdb.h>
-
-void sethostent(int x)
-{
-}
-
-struct hostent *gethostent()
-{
- return 0;
-}
-
-struct netent *getnetent()
-{
- return 0;
-}
-
-void endhostent(void)
-{
-}
-
-weak_alias(sethostent, setnetent);
-weak_alias(endhostent, endnetent);
lib/libc/wasi/libc-top-half/musl/src/network/ether.c
@@ -1,58 +0,0 @@
-#include <stdlib.h>
-#include <netinet/ether.h>
-#include <stdio.h>
-
-struct ether_addr *ether_aton_r (const char *x, struct ether_addr *p_a)
-{
- struct ether_addr a;
- char *y;
- for (int ii = 0; ii < 6; ii++) {
- unsigned long int n;
- if (ii != 0) {
- if (x[0] != ':') return 0; /* bad format */
- else x++;
- }
- n = strtoul (x, &y, 16);
- x = y;
- if (n > 0xFF) return 0; /* bad byte */
- a.ether_addr_octet[ii] = n;
- }
- if (x[0] != 0) return 0; /* bad format */
- *p_a = a;
- return p_a;
-}
-
-struct ether_addr *ether_aton (const char *x)
-{
- static struct ether_addr a;
- return ether_aton_r (x, &a);
-}
-
-char *ether_ntoa_r (const struct ether_addr *p_a, char *x) {
- char *y;
- y = x;
- for (int ii = 0; ii < 6; ii++) {
- x += sprintf (x, ii == 0 ? "%.2X" : ":%.2X", p_a->ether_addr_octet[ii]);
- }
- return y;
-}
-
-char *ether_ntoa (const struct ether_addr *p_a) {
- static char x[18];
- return ether_ntoa_r (p_a, x);
-}
-
-int ether_line(const char *l, struct ether_addr *e, char *hostname)
-{
- return -1;
-}
-
-int ether_ntohost(char *hostname, const struct ether_addr *e)
-{
- return -1;
-}
-
-int ether_hostton(const char *hostname, struct ether_addr *e)
-{
- return -1;
-}
lib/libc/wasi/libc-top-half/musl/src/network/freeaddrinfo.c
@@ -1,16 +0,0 @@
-#include <stdlib.h>
-#include <stddef.h>
-#include <netdb.h>
-#include "lookup.h"
-#include "lock.h"
-
-void freeaddrinfo(struct addrinfo *p)
-{
- size_t cnt;
- for (cnt=1; p->ai_next; cnt++, p=p->ai_next);
- struct aibuf *b = (void *)((char *)p - offsetof(struct aibuf, ai));
- b -= b->slot;
- LOCK(b->lock);
- if (!(b->ref -= cnt)) free(b);
- else UNLOCK(b->lock);
-}
lib/libc/wasi/libc-top-half/musl/src/network/gai_strerror.c
@@ -1,25 +0,0 @@
-#include <netdb.h>
-#include "locale_impl.h"
-
-static const char msgs[] =
- "Invalid flags\0"
- "Name does not resolve\0"
- "Try again\0"
- "Non-recoverable error\0"
- "Unknown error\0"
- "Unrecognized address family or invalid length\0"
- "Unrecognized socket type\0"
- "Unrecognized service\0"
- "Unknown error\0"
- "Out of memory\0"
- "System error\0"
- "Overflow\0"
- "\0Unknown error";
-
-const char *gai_strerror(int ecode)
-{
- const char *s;
- for (s=msgs, ecode++; ecode && *s; ecode++, s++) for (; *s; s++);
- if (!*s) s++;
- return LCTRANS_CUR(s);
-}
lib/libc/wasi/libc-top-half/musl/src/network/getaddrinfo.c
@@ -1,135 +0,0 @@
-#include <stdlib.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <string.h>
-#include <pthread.h>
-#include <unistd.h>
-#include <endian.h>
-#include <errno.h>
-#include "lookup.h"
-
-int getaddrinfo(const char *restrict host, const char *restrict serv, const struct addrinfo *restrict hint, struct addrinfo **restrict res)
-{
- struct service ports[MAXSERVS];
- struct address addrs[MAXADDRS];
- char canon[256], *outcanon;
- int nservs, naddrs, nais, canon_len, i, j, k;
- int family = AF_UNSPEC, flags = 0, proto = 0, socktype = 0;
- struct aibuf *out;
-
- if (!host && !serv) return EAI_NONAME;
-
- if (hint) {
- family = hint->ai_family;
- flags = hint->ai_flags;
- proto = hint->ai_protocol;
- socktype = hint->ai_socktype;
-
- const int mask = AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST |
- AI_V4MAPPED | AI_ALL | AI_ADDRCONFIG | AI_NUMERICSERV;
- if ((flags & mask) != flags)
- return EAI_BADFLAGS;
-
- switch (family) {
- case AF_INET:
- case AF_INET6:
- case AF_UNSPEC:
- break;
- default:
- return EAI_FAMILY;
- }
- }
-
- if (flags & AI_ADDRCONFIG) {
- /* Define the "an address is configured" condition for address
- * families via ability to create a socket for the family plus
- * routability of the loopback address for the family. */
- static const struct sockaddr_in lo4 = {
- .sin_family = AF_INET, .sin_port = 65535,
- .sin_addr.s_addr = __BYTE_ORDER == __BIG_ENDIAN
- ? 0x7f000001 : 0x0100007f
- };
- static const struct sockaddr_in6 lo6 = {
- .sin6_family = AF_INET6, .sin6_port = 65535,
- .sin6_addr = IN6ADDR_LOOPBACK_INIT
- };
- int tf[2] = { AF_INET, AF_INET6 };
- const void *ta[2] = { &lo4, &lo6 };
- socklen_t tl[2] = { sizeof lo4, sizeof lo6 };
- for (i=0; i<2; i++) {
- if (family==tf[1-i]) continue;
- int s = socket(tf[i], SOCK_CLOEXEC|SOCK_DGRAM,
- IPPROTO_UDP);
- if (s>=0) {
- int cs;
- pthread_setcancelstate(
- PTHREAD_CANCEL_DISABLE, &cs);
- int r = connect(s, ta[i], tl[i]);
- pthread_setcancelstate(cs, 0);
- close(s);
- if (!r) continue;
- }
- switch (errno) {
- case EADDRNOTAVAIL:
- case EAFNOSUPPORT:
- case EHOSTUNREACH:
- case ENETDOWN:
- case ENETUNREACH:
- break;
- default:
- return EAI_SYSTEM;
- }
- if (family == tf[i]) return EAI_NONAME;
- family = tf[1-i];
- }
- }
-
- nservs = __lookup_serv(ports, serv, proto, socktype, flags);
- if (nservs < 0) return nservs;
-
- naddrs = __lookup_name(addrs, canon, host, family, flags);
- if (naddrs < 0) return naddrs;
-
- nais = nservs * naddrs;
- canon_len = strlen(canon);
- out = calloc(1, nais * sizeof(*out) + canon_len + 1);
- if (!out) return EAI_MEMORY;
-
- if (canon_len) {
- outcanon = (void *)&out[nais];
- memcpy(outcanon, canon, canon_len+1);
- } else {
- outcanon = 0;
- }
-
- for (k=i=0; i<naddrs; i++) for (j=0; j<nservs; j++, k++) {
- out[k].slot = k;
- out[k].ai = (struct addrinfo){
- .ai_family = addrs[i].family,
- .ai_socktype = ports[j].socktype,
- .ai_protocol = ports[j].proto,
- .ai_addrlen = addrs[i].family == AF_INET
- ? sizeof(struct sockaddr_in)
- : sizeof(struct sockaddr_in6),
- .ai_addr = (void *)&out[k].sa,
- .ai_canonname = outcanon };
- if (k) out[k-1].ai.ai_next = &out[k].ai;
- switch (addrs[i].family) {
- case AF_INET:
- out[k].sa.sin.sin_family = AF_INET;
- out[k].sa.sin.sin_port = htons(ports[j].port);
- memcpy(&out[k].sa.sin.sin_addr, &addrs[i].addr, 4);
- break;
- case AF_INET6:
- out[k].sa.sin6.sin6_family = AF_INET6;
- out[k].sa.sin6.sin6_port = htons(ports[j].port);
- out[k].sa.sin6.sin6_scope_id = addrs[i].scopeid;
- memcpy(&out[k].sa.sin6.sin6_addr, &addrs[i].addr, 16);
- break;
- }
- }
- out[0].ref = nais;
- *res = &out->ai;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/network/gethostbyaddr.c
@@ -1,24 +0,0 @@
-#define _GNU_SOURCE
-
-#include <netdb.h>
-#include <errno.h>
-#include <stdlib.h>
-
-struct hostent *gethostbyaddr(const void *a, socklen_t l, int af)
-{
- static struct hostent *h;
- size_t size = 63;
- struct hostent *res;
- int err;
- do {
- free(h);
- h = malloc(size+=size+1);
- if (!h) {
- h_errno = NO_RECOVERY;
- return 0;
- }
- err = gethostbyaddr_r(a, l, af, h,
- (void *)(h+1), size-sizeof *h, &res, &h_errno);
- } while (err == ERANGE);
- return err ? 0 : h;
-}
lib/libc/wasi/libc-top-half/musl/src/network/gethostbyaddr_r.c
@@ -1,71 +0,0 @@
-#define _GNU_SOURCE
-
-#include <sys/socket.h>
-#include <netdb.h>
-#include <string.h>
-#include <netinet/in.h>
-#include <errno.h>
-#include <inttypes.h>
-
-int gethostbyaddr_r(const void *a, socklen_t l, int af,
- struct hostent *h, char *buf, size_t buflen,
- struct hostent **res, int *err)
-{
- union {
- struct sockaddr_in sin;
- struct sockaddr_in6 sin6;
- } sa = { .sin.sin_family = af };
- socklen_t sl = af==AF_INET6 ? sizeof sa.sin6 : sizeof sa.sin;
- int i;
-
- *res = 0;
-
- /* Load address argument into sockaddr structure */
- if (af==AF_INET6 && l==16) memcpy(&sa.sin6.sin6_addr, a, 16);
- else if (af==AF_INET && l==4) memcpy(&sa.sin.sin_addr, a, 4);
- else {
- *err = NO_RECOVERY;
- return EINVAL;
- }
-
- /* Align buffer and check for space for pointers and ip address */
- i = (uintptr_t)buf & sizeof(char *)-1;
- if (!i) i = sizeof(char *);
- if (buflen <= 5*sizeof(char *)-i + l) return ERANGE;
- buf += sizeof(char *)-i;
- buflen -= 5*sizeof(char *)-i + l;
-
- h->h_addr_list = (void *)buf;
- buf += 2*sizeof(char *);
- h->h_aliases = (void *)buf;
- buf += 2*sizeof(char *);
-
- h->h_addr_list[0] = buf;
- memcpy(h->h_addr_list[0], a, l);
- buf += l;
- h->h_addr_list[1] = 0;
- h->h_aliases[0] = buf;
- h->h_aliases[1] = 0;
-
- switch (getnameinfo((void *)&sa, sl, buf, buflen, 0, 0, 0)) {
- case EAI_AGAIN:
- *err = TRY_AGAIN;
- return EAGAIN;
- case EAI_OVERFLOW:
- return ERANGE;
- default:
- case EAI_MEMORY:
- case EAI_SYSTEM:
- case EAI_FAIL:
- *err = NO_RECOVERY;
- return errno;
- case 0:
- break;
- }
-
- h->h_addrtype = af;
- h->h_length = l;
- h->h_name = h->h_aliases[0];
- *res = h;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/network/gethostbyname.c
@@ -1,11 +0,0 @@
-#define _GNU_SOURCE
-
-#include <sys/socket.h>
-#include <netdb.h>
-#include <string.h>
-#include <netinet/in.h>
-
-struct hostent *gethostbyname(const char *name)
-{
- return gethostbyname2(name, AF_INET);
-}
lib/libc/wasi/libc-top-half/musl/src/network/gethostbyname2.c
@@ -1,25 +0,0 @@
-#define _GNU_SOURCE
-
-#include <sys/socket.h>
-#include <netdb.h>
-#include <errno.h>
-#include <stdlib.h>
-
-struct hostent *gethostbyname2(const char *name, int af)
-{
- static struct hostent *h;
- size_t size = 63;
- struct hostent *res;
- int err;
- do {
- free(h);
- h = malloc(size+=size+1);
- if (!h) {
- h_errno = NO_RECOVERY;
- return 0;
- }
- err = gethostbyname2_r(name, af, h,
- (void *)(h+1), size-sizeof *h, &res, &h_errno);
- } while (err == ERANGE);
- return err ? 0 : h;
-}
lib/libc/wasi/libc-top-half/musl/src/network/gethostbyname2_r.c
@@ -1,80 +0,0 @@
-#define _GNU_SOURCE
-
-#include <sys/socket.h>
-#include <netdb.h>
-#include <string.h>
-#include <netinet/in.h>
-#include <errno.h>
-#include <stdint.h>
-#include "lookup.h"
-
-int gethostbyname2_r(const char *name, int af,
- struct hostent *h, char *buf, size_t buflen,
- struct hostent **res, int *err)
-{
- struct address addrs[MAXADDRS];
- char canon[256];
- int i, cnt;
- size_t align, need;
-
- *res = 0;
- cnt = __lookup_name(addrs, canon, name, af, AI_CANONNAME);
- if (cnt<0) switch (cnt) {
- case EAI_NONAME:
- *err = HOST_NOT_FOUND;
- return ENOENT;
- case EAI_AGAIN:
- *err = TRY_AGAIN;
- return EAGAIN;
- default:
- case EAI_FAIL:
- *err = NO_RECOVERY;
- return EBADMSG;
- case EAI_MEMORY:
- case EAI_SYSTEM:
- *err = NO_RECOVERY;
- return errno;
- }
-
- h->h_addrtype = af;
- h->h_length = af==AF_INET6 ? 16 : 4;
-
- /* Align buffer */
- align = -(uintptr_t)buf & sizeof(char *)-1;
-
- need = 4*sizeof(char *);
- need += (cnt + 1) * (sizeof(char *) + h->h_length);
- need += strlen(name)+1;
- need += strlen(canon)+1;
- need += align;
-
- if (need > buflen) return ERANGE;
-
- buf += align;
- h->h_aliases = (void *)buf;
- buf += 3*sizeof(char *);
- h->h_addr_list = (void *)buf;
- buf += (cnt+1)*sizeof(char *);
-
- for (i=0; i<cnt; i++) {
- h->h_addr_list[i] = (void *)buf;
- buf += h->h_length;
- memcpy(h->h_addr_list[i], addrs[i].addr, h->h_length);
- }
- h->h_addr_list[i] = 0;
-
- h->h_name = h->h_aliases[0] = buf;
- strcpy(h->h_name, canon);
- buf += strlen(h->h_name)+1;
-
- if (strcmp(h->h_name, name)) {
- h->h_aliases[1] = buf;
- strcpy(h->h_aliases[1], name);
- buf += strlen(h->h_aliases[1])+1;
- } else h->h_aliases[1] = 0;
-
- h->h_aliases[2] = 0;
-
- *res = h;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/network/gethostbyname_r.c
@@ -1,11 +0,0 @@
-#define _GNU_SOURCE
-
-#include <sys/socket.h>
-#include <netdb.h>
-
-int gethostbyname_r(const char *name,
- struct hostent *h, char *buf, size_t buflen,
- struct hostent **res, int *err)
-{
- return gethostbyname2_r(name, AF_INET, h, buf, buflen, res, err);
-}
lib/libc/wasi/libc-top-half/musl/src/network/getifaddrs.c
@@ -1,216 +0,0 @@
-#define _GNU_SOURCE
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <ifaddrs.h>
-#include <syscall.h>
-#include <net/if.h>
-#include <netinet/in.h>
-#include "netlink.h"
-
-#define IFADDRS_HASH_SIZE 64
-
-/* getifaddrs() reports hardware addresses with PF_PACKET that implies
- * struct sockaddr_ll. But e.g. Infiniband socket address length is
- * longer than sockaddr_ll.ssl_addr[8] can hold. Use this hack struct
- * to extend ssl_addr - callers should be able to still use it. */
-struct sockaddr_ll_hack {
- unsigned short sll_family, sll_protocol;
- int sll_ifindex;
- unsigned short sll_hatype;
- unsigned char sll_pkttype, sll_halen;
- unsigned char sll_addr[24];
-};
-
-union sockany {
- struct sockaddr sa;
- struct sockaddr_ll_hack ll;
- struct sockaddr_in v4;
- struct sockaddr_in6 v6;
-};
-
-struct ifaddrs_storage {
- struct ifaddrs ifa;
- struct ifaddrs_storage *hash_next;
- union sockany addr, netmask, ifu;
- unsigned int index;
- char name[IFNAMSIZ+1];
-};
-
-struct ifaddrs_ctx {
- struct ifaddrs_storage *first;
- struct ifaddrs_storage *last;
- struct ifaddrs_storage *hash[IFADDRS_HASH_SIZE];
-};
-
-void freeifaddrs(struct ifaddrs *ifp)
-{
- struct ifaddrs *n;
- while (ifp) {
- n = ifp->ifa_next;
- free(ifp);
- ifp = n;
- }
-}
-
-static void copy_addr(struct sockaddr **r, int af, union sockany *sa, void *addr, size_t addrlen, int ifindex)
-{
- uint8_t *dst;
- int len;
-
- switch (af) {
- case AF_INET:
- dst = (uint8_t*) &sa->v4.sin_addr;
- len = 4;
- break;
- case AF_INET6:
- dst = (uint8_t*) &sa->v6.sin6_addr;
- len = 16;
- if (IN6_IS_ADDR_LINKLOCAL(addr) || IN6_IS_ADDR_MC_LINKLOCAL(addr))
- sa->v6.sin6_scope_id = ifindex;
- break;
- default:
- return;
- }
- if (addrlen < len) return;
- sa->sa.sa_family = af;
- memcpy(dst, addr, len);
- *r = &sa->sa;
-}
-
-static void gen_netmask(struct sockaddr **r, int af, union sockany *sa, int prefixlen)
-{
- uint8_t addr[16] = {0};
- int i;
-
- if (prefixlen > 8*sizeof(addr)) prefixlen = 8*sizeof(addr);
- i = prefixlen / 8;
- memset(addr, 0xff, i);
- if (i < sizeof(addr)) addr[i++] = 0xff << (8 - (prefixlen % 8));
- copy_addr(r, af, sa, addr, sizeof(addr), 0);
-}
-
-static void copy_lladdr(struct sockaddr **r, union sockany *sa, void *addr, size_t addrlen, int ifindex, unsigned short hatype)
-{
- if (addrlen > sizeof(sa->ll.sll_addr)) return;
- sa->ll.sll_family = AF_PACKET;
- sa->ll.sll_ifindex = ifindex;
- sa->ll.sll_hatype = hatype;
- sa->ll.sll_halen = addrlen;
- memcpy(sa->ll.sll_addr, addr, addrlen);
- *r = &sa->sa;
-}
-
-static int netlink_msg_to_ifaddr(void *pctx, struct nlmsghdr *h)
-{
- struct ifaddrs_ctx *ctx = pctx;
- struct ifaddrs_storage *ifs, *ifs0;
- struct ifinfomsg *ifi = NLMSG_DATA(h);
- struct ifaddrmsg *ifa = NLMSG_DATA(h);
- struct rtattr *rta;
- int stats_len = 0;
-
- if (h->nlmsg_type == RTM_NEWLINK) {
- for (rta = NLMSG_RTA(h, sizeof(*ifi)); NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) {
- if (rta->rta_type != IFLA_STATS) continue;
- stats_len = RTA_DATALEN(rta);
- break;
- }
- } else {
- for (ifs0 = ctx->hash[ifa->ifa_index % IFADDRS_HASH_SIZE]; ifs0; ifs0 = ifs0->hash_next)
- if (ifs0->index == ifa->ifa_index)
- break;
- if (!ifs0) return 0;
- }
-
- ifs = calloc(1, sizeof(struct ifaddrs_storage) + stats_len);
- if (ifs == 0) return -1;
-
- if (h->nlmsg_type == RTM_NEWLINK) {
- ifs->index = ifi->ifi_index;
- ifs->ifa.ifa_flags = ifi->ifi_flags;
-
- for (rta = NLMSG_RTA(h, sizeof(*ifi)); NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) {
- switch (rta->rta_type) {
- case IFLA_IFNAME:
- if (RTA_DATALEN(rta) < sizeof(ifs->name)) {
- memcpy(ifs->name, RTA_DATA(rta), RTA_DATALEN(rta));
- ifs->ifa.ifa_name = ifs->name;
- }
- break;
- case IFLA_ADDRESS:
- copy_lladdr(&ifs->ifa.ifa_addr, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifi->ifi_index, ifi->ifi_type);
- break;
- case IFLA_BROADCAST:
- copy_lladdr(&ifs->ifa.ifa_broadaddr, &ifs->ifu, RTA_DATA(rta), RTA_DATALEN(rta), ifi->ifi_index, ifi->ifi_type);
- break;
- case IFLA_STATS:
- ifs->ifa.ifa_data = (void*)(ifs+1);
- memcpy(ifs->ifa.ifa_data, RTA_DATA(rta), RTA_DATALEN(rta));
- break;
- }
- }
- if (ifs->ifa.ifa_name) {
- unsigned int bucket = ifs->index % IFADDRS_HASH_SIZE;
- ifs->hash_next = ctx->hash[bucket];
- ctx->hash[bucket] = ifs;
- }
- } else {
- ifs->ifa.ifa_name = ifs0->ifa.ifa_name;
- ifs->ifa.ifa_flags = ifs0->ifa.ifa_flags;
- for (rta = NLMSG_RTA(h, sizeof(*ifa)); NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) {
- switch (rta->rta_type) {
- case IFA_ADDRESS:
- /* If ifa_addr is already set we, received an IFA_LOCAL before
- * so treat this as destination address */
- if (ifs->ifa.ifa_addr)
- copy_addr(&ifs->ifa.ifa_dstaddr, ifa->ifa_family, &ifs->ifu, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
- else
- copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
- break;
- case IFA_BROADCAST:
- copy_addr(&ifs->ifa.ifa_broadaddr, ifa->ifa_family, &ifs->ifu, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
- break;
- case IFA_LOCAL:
- /* If ifa_addr is set and we get IFA_LOCAL, assume we have
- * a point-to-point network. Move address to correct field. */
- if (ifs->ifa.ifa_addr) {
- ifs->ifu = ifs->addr;
- ifs->ifa.ifa_dstaddr = &ifs->ifu.sa;
- memset(&ifs->addr, 0, sizeof(ifs->addr));
- }
- copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
- break;
- case IFA_LABEL:
- if (RTA_DATALEN(rta) < sizeof(ifs->name)) {
- memcpy(ifs->name, RTA_DATA(rta), RTA_DATALEN(rta));
- ifs->ifa.ifa_name = ifs->name;
- }
- break;
- }
- }
- if (ifs->ifa.ifa_addr)
- gen_netmask(&ifs->ifa.ifa_netmask, ifa->ifa_family, &ifs->netmask, ifa->ifa_prefixlen);
- }
-
- if (ifs->ifa.ifa_name) {
- if (!ctx->first) ctx->first = ifs;
- if (ctx->last) ctx->last->ifa.ifa_next = &ifs->ifa;
- ctx->last = ifs;
- } else {
- free(ifs);
- }
- return 0;
-}
-
-int getifaddrs(struct ifaddrs **ifap)
-{
- struct ifaddrs_ctx _ctx, *ctx = &_ctx;
- int r;
- memset(ctx, 0, sizeof *ctx);
- r = __rtnetlink_enumerate(AF_UNSPEC, AF_UNSPEC, netlink_msg_to_ifaddr, ctx);
- if (r == 0) *ifap = &ctx->first->ifa;
- else freeifaddrs(&ctx->first->ifa);
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/network/getnameinfo.c
@@ -1,200 +0,0 @@
-#include <netdb.h>
-#include <limits.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <net/if.h>
-#include <ctype.h>
-#include <resolv.h>
-#include "lookup.h"
-#include "stdio_impl.h"
-
-#define PTR_MAX (64 + sizeof ".in-addr.arpa")
-#define RR_PTR 12
-
-static char *itoa(char *p, unsigned x) {
- p += 3*sizeof(int);
- *--p = 0;
- do {
- *--p = '0' + x % 10;
- x /= 10;
- } while (x);
- return p;
-}
-
-static void mkptr4(char *s, const unsigned char *ip)
-{
- sprintf(s, "%d.%d.%d.%d.in-addr.arpa",
- ip[3], ip[2], ip[1], ip[0]);
-}
-
-static void mkptr6(char *s, const unsigned char *ip)
-{
- static const char xdigits[] = "0123456789abcdef";
- int i;
- for (i=15; i>=0; i--) {
- *s++ = xdigits[ip[i]&15]; *s++ = '.';
- *s++ = xdigits[ip[i]>>4]; *s++ = '.';
- }
- strcpy(s, "ip6.arpa");
-}
-
-static void reverse_hosts(char *buf, const unsigned char *a, unsigned scopeid, int family)
-{
- char line[512], *p, *z;
- unsigned char _buf[1032], atmp[16];
- struct address iplit;
- FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf);
- if (!f) return;
- if (family == AF_INET) {
- memcpy(atmp+12, a, 4);
- memcpy(atmp, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
- a = atmp;
- }
- while (fgets(line, sizeof line, f)) {
- if ((p=strchr(line, '#'))) *p++='\n', *p=0;
-
- for (p=line; *p && !isspace(*p); p++);
- *p++ = 0;
- if (__lookup_ipliteral(&iplit, line, AF_UNSPEC)<=0)
- continue;
-
- if (iplit.family == AF_INET) {
- memcpy(iplit.addr+12, iplit.addr, 4);
- memcpy(iplit.addr, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
- iplit.scopeid = 0;
- }
-
- if (memcmp(a, iplit.addr, 16) || iplit.scopeid != scopeid)
- continue;
-
- for (; *p && isspace(*p); p++);
- for (z=p; *z && !isspace(*z); z++);
- *z = 0;
- if (z-p < 256) {
- memcpy(buf, p, z-p+1);
- break;
- }
- }
- __fclose_ca(f);
-}
-
-static void reverse_services(char *buf, int port, int dgram)
-{
- unsigned long svport;
- char line[128], *p, *z;
- unsigned char _buf[1032];
- FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf);
- if (!f) return;
- while (fgets(line, sizeof line, f)) {
- if ((p=strchr(line, '#'))) *p++='\n', *p=0;
-
- for (p=line; *p && !isspace(*p); p++);
- if (!*p) continue;
- *p++ = 0;
- svport = strtoul(p, &z, 10);
-
- if (svport != port || z==p) continue;
- if (dgram && strncmp(z, "/udp", 4)) continue;
- if (!dgram && strncmp(z, "/tcp", 4)) continue;
- if (p-line > 32) continue;
-
- memcpy(buf, line, p-line);
- break;
- }
- __fclose_ca(f);
-}
-
-static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet)
-{
- if (rr != RR_PTR) return 0;
- if (__dn_expand(packet, (const unsigned char *)packet + 512,
- data, c, 256) <= 0)
- *(char *)c = 0;
- return 0;
-
-}
-
-int getnameinfo(const struct sockaddr *restrict sa, socklen_t sl,
- char *restrict node, socklen_t nodelen,
- char *restrict serv, socklen_t servlen,
- int flags)
-{
- char ptr[PTR_MAX];
- char buf[256], num[3*sizeof(int)+1];
- int af = sa->sa_family;
- unsigned char *a;
- unsigned scopeid;
-
- switch (af) {
- case AF_INET:
- a = (void *)&((struct sockaddr_in *)sa)->sin_addr;
- if (sl < sizeof(struct sockaddr_in)) return EAI_FAMILY;
- mkptr4(ptr, a);
- scopeid = 0;
- break;
- case AF_INET6:
- a = (void *)&((struct sockaddr_in6 *)sa)->sin6_addr;
- if (sl < sizeof(struct sockaddr_in6)) return EAI_FAMILY;
- if (memcmp(a, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12))
- mkptr6(ptr, a);
- else
- mkptr4(ptr, a+12);
- scopeid = ((struct sockaddr_in6 *)sa)->sin6_scope_id;
- break;
- default:
- return EAI_FAMILY;
- }
-
- if (node && nodelen) {
- buf[0] = 0;
- if (!(flags & NI_NUMERICHOST)) {
- reverse_hosts(buf, a, scopeid, af);
- }
- if (!*buf && !(flags & NI_NUMERICHOST)) {
- unsigned char query[18+PTR_MAX], reply[512];
- int qlen = __res_mkquery(0, ptr, 1, RR_PTR,
- 0, 0, 0, query, sizeof query);
- query[3] = 0; /* don't need AD flag */
- int rlen = __res_send(query, qlen, reply, sizeof reply);
- buf[0] = 0;
- if (rlen > 0)
- __dns_parse(reply, rlen, dns_parse_callback, buf);
- }
- if (!*buf) {
- if (flags & NI_NAMEREQD) return EAI_NONAME;
- inet_ntop(af, a, buf, sizeof buf);
- if (scopeid) {
- char *p = 0, tmp[IF_NAMESIZE+1];
- if (!(flags & NI_NUMERICSCOPE) &&
- (IN6_IS_ADDR_LINKLOCAL(a) ||
- IN6_IS_ADDR_MC_LINKLOCAL(a)))
- p = if_indextoname(scopeid, tmp+1);
- if (!p)
- p = itoa(num, scopeid);
- *--p = '%';
- strcat(buf, p);
- }
- }
- if (strlen(buf) >= nodelen) return EAI_OVERFLOW;
- strcpy(node, buf);
- }
-
- if (serv && servlen) {
- char *p = buf;
- int port = ntohs(((struct sockaddr_in *)sa)->sin_port);
- buf[0] = 0;
- if (!(flags & NI_NUMERICSERV))
- reverse_services(buf, port, flags & NI_DGRAM);
- if (!*p)
- p = itoa(num, port);
- if (strlen(p) >= servlen)
- return EAI_OVERFLOW;
- strcpy(serv, p);
- }
-
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/network/getpeername.c
@@ -1,7 +0,0 @@
-#include <sys/socket.h>
-#include "syscall.h"
-
-int getpeername(int fd, struct sockaddr *restrict addr, socklen_t *restrict len)
-{
- return socketcall(getpeername, fd, addr, len, 0, 0, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/network/getservbyname.c
@@ -1,12 +0,0 @@
-#define _GNU_SOURCE
-#include <netdb.h>
-
-struct servent *getservbyname(const char *name, const char *prots)
-{
- static struct servent se;
- static char *buf[2];
- struct servent *res;
- if (getservbyname_r(name, prots, &se, (void *)buf, sizeof buf, &res))
- return 0;
- return &se;
-}
lib/libc/wasi/libc-top-half/musl/src/network/getservbyname_r.c
@@ -1,55 +0,0 @@
-#define _GNU_SOURCE
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <inttypes.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "lookup.h"
-
-#define ALIGN (sizeof(struct { char a; char *b; }) - sizeof(char *))
-
-int getservbyname_r(const char *name, const char *prots,
- struct servent *se, char *buf, size_t buflen, struct servent **res)
-{
- struct service servs[MAXSERVS];
- int cnt, proto, align;
-
- *res = 0;
-
- /* Don't treat numeric port number strings as service records. */
- char *end = "";
- strtoul(name, &end, 10);
- if (!*end) return ENOENT;
-
- /* Align buffer */
- align = -(uintptr_t)buf & ALIGN-1;
- if (buflen < 2*sizeof(char *)+align)
- return ERANGE;
- buf += align;
-
- if (!prots) proto = 0;
- else if (!strcmp(prots, "tcp")) proto = IPPROTO_TCP;
- else if (!strcmp(prots, "udp")) proto = IPPROTO_UDP;
- else return EINVAL;
-
- cnt = __lookup_serv(servs, name, proto, 0, 0);
- if (cnt<0) switch (cnt) {
- case EAI_MEMORY:
- case EAI_SYSTEM:
- return ENOMEM;
- default:
- return ENOENT;
- }
-
- se->s_name = (char *)name;
- se->s_aliases = (void *)buf;
- se->s_aliases[0] = se->s_name;
- se->s_aliases[1] = 0;
- se->s_port = htons(servs[0].port);
- se->s_proto = servs[0].proto == IPPROTO_TCP ? "tcp" : "udp";
-
- *res = se;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/network/getservbyport.c
@@ -1,12 +0,0 @@
-#define _GNU_SOURCE
-#include <netdb.h>
-
-struct servent *getservbyport(int port, const char *prots)
-{
- static struct servent se;
- static long buf[32/sizeof(long)];
- struct servent *res;
- if (getservbyport_r(port, prots, &se, (void *)buf, sizeof buf, &res))
- return 0;
- return &se;
-}
lib/libc/wasi/libc-top-half/musl/src/network/getservbyport_r.c
@@ -1,60 +0,0 @@
-#define _GNU_SOURCE
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <inttypes.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-
-int getservbyport_r(int port, const char *prots,
- struct servent *se, char *buf, size_t buflen, struct servent **res)
-{
- int i;
- struct sockaddr_in sin = {
- .sin_family = AF_INET,
- .sin_port = port,
- };
-
- if (!prots) {
- int r = getservbyport_r(port, "tcp", se, buf, buflen, res);
- if (r) r = getservbyport_r(port, "udp", se, buf, buflen, res);
- return r;
- }
- *res = 0;
-
- /* Align buffer */
- i = (uintptr_t)buf & sizeof(char *)-1;
- if (!i) i = sizeof(char *);
- if (buflen < 3*sizeof(char *)-i)
- return ERANGE;
- buf += sizeof(char *)-i;
- buflen -= sizeof(char *)-i;
-
- if (strcmp(prots, "tcp") && strcmp(prots, "udp")) return EINVAL;
-
- se->s_port = port;
- se->s_proto = (char *)prots;
- se->s_aliases = (void *)buf;
- buf += 2*sizeof(char *);
- buflen -= 2*sizeof(char *);
- se->s_aliases[1] = 0;
- se->s_aliases[0] = se->s_name = buf;
-
- switch (getnameinfo((void *)&sin, sizeof sin, 0, 0, buf, buflen,
- strcmp(prots, "udp") ? 0 : NI_DGRAM)) {
- case EAI_MEMORY:
- case EAI_SYSTEM:
- return ENOMEM;
- default:
- return ENOENT;
- case 0:
- break;
- }
-
- /* A numeric port string is not a service record. */
- if (strtol(buf, 0, 10)==ntohs(port)) return ENOENT;
-
- *res = se;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/network/getsockname.c
@@ -1,7 +0,0 @@
-#include <sys/socket.h>
-#include "syscall.h"
-
-int getsockname(int fd, struct sockaddr *restrict addr, socklen_t *restrict len)
-{
- return socketcall(getsockname, fd, addr, len, 0, 0, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/network/getsockopt.c
@@ -1,41 +0,0 @@
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <errno.h>
-#include "syscall.h"
-
-int getsockopt(int fd, int level, int optname, void *restrict optval, socklen_t *restrict optlen)
-{
- long tv32[2];
- struct timeval *tv;
-
- int r = __socketcall(getsockopt, fd, level, optname, optval, optlen, 0);
-
- if (r==-ENOPROTOOPT) switch (level) {
- case SOL_SOCKET:
- switch (optname) {
- case SO_RCVTIMEO:
- case SO_SNDTIMEO:
- if (SO_RCVTIMEO == SO_RCVTIMEO_OLD) break;
- if (*optlen < sizeof *tv) return __syscall_ret(-EINVAL);
- if (optname==SO_RCVTIMEO) optname=SO_RCVTIMEO_OLD;
- if (optname==SO_SNDTIMEO) optname=SO_SNDTIMEO_OLD;
- r = __socketcall(getsockopt, fd, level, optname,
- tv32, (socklen_t[]){sizeof tv32}, 0);
- if (r<0) break;
- tv = optval;
- tv->tv_sec = tv32[0];
- tv->tv_usec = tv32[1];
- *optlen = sizeof *tv;
- break;
- case SO_TIMESTAMP:
- case SO_TIMESTAMPNS:
- if (SO_TIMESTAMP == SO_TIMESTAMP_OLD) break;
- if (optname==SO_TIMESTAMP) optname=SO_TIMESTAMP_OLD;
- if (optname==SO_TIMESTAMPNS) optname=SO_TIMESTAMPNS_OLD;
- r = __socketcall(getsockopt, fd, level,
- optname, optval, optlen, 0);
- break;
- }
- }
- return __syscall_ret(r);
-}
lib/libc/wasi/libc-top-half/musl/src/network/h_errno.c
@@ -1,11 +0,0 @@
-#include <netdb.h>
-#include "pthread_impl.h"
-
-#undef h_errno
-int h_errno;
-
-int *__h_errno_location(void)
-{
- if (!__pthread_self()->stack) return &h_errno;
- return &__pthread_self()->h_errno_val;
-}
lib/libc/wasi/libc-top-half/musl/src/network/herror.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <netdb.h>
-
-void herror(const char *msg)
-{
- fprintf(stderr, "%s%s%s\n", msg?msg:"", msg?": ":"", hstrerror(h_errno));
-}
lib/libc/wasi/libc-top-half/musl/src/network/hstrerror.c
@@ -1,18 +0,0 @@
-#define _GNU_SOURCE
-#include <netdb.h>
-#include "locale_impl.h"
-
-static const char msgs[] =
- "Host not found\0"
- "Try again\0"
- "Non-recoverable error\0"
- "Address not available\0"
- "\0Unknown error";
-
-const char *hstrerror(int ecode)
-{
- const char *s;
- for (s=msgs, ecode--; ecode && *s; ecode--, s++) for (; *s; s++);
- if (!*s) s++;
- return LCTRANS_CUR(s);
-}
lib/libc/wasi/libc-top-half/musl/src/network/if_freenameindex.c
@@ -1,7 +0,0 @@
-#include <net/if.h>
-#include <stdlib.h>
-
-void if_freenameindex(struct if_nameindex *idx)
-{
- free(idx);
-}
lib/libc/wasi/libc-top-half/musl/src/network/if_indextoname.c
@@ -1,23 +0,0 @@
-#define _GNU_SOURCE
-#include <net/if.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <string.h>
-#include <errno.h>
-#include "syscall.h"
-
-char *if_indextoname(unsigned index, char *name)
-{
- struct ifreq ifr;
- int fd, r;
-
- if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 0;
- ifr.ifr_ifindex = index;
- r = ioctl(fd, SIOCGIFNAME, &ifr);
- __syscall(SYS_close, fd);
- if (r < 0) {
- if (errno == ENODEV) errno = ENXIO;
- return 0;
- }
- return strncpy(name, ifr.ifr_name, IF_NAMESIZE);
-}
lib/libc/wasi/libc-top-half/musl/src/network/if_nameindex.c
@@ -1,114 +0,0 @@
-#define _GNU_SOURCE
-#include <net/if.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <pthread.h>
-#include "netlink.h"
-
-#define IFADDRS_HASH_SIZE 64
-
-struct ifnamemap {
- unsigned int hash_next;
- unsigned int index;
- unsigned char namelen;
- char name[IFNAMSIZ];
-};
-
-struct ifnameindexctx {
- unsigned int num, allocated, str_bytes;
- struct ifnamemap *list;
- unsigned int hash[IFADDRS_HASH_SIZE];
-};
-
-static int netlink_msg_to_nameindex(void *pctx, struct nlmsghdr *h)
-{
- struct ifnameindexctx *ctx = pctx;
- struct ifnamemap *map;
- struct rtattr *rta;
- unsigned int i;
- int index, type, namelen, bucket;
-
- if (h->nlmsg_type == RTM_NEWLINK) {
- struct ifinfomsg *ifi = NLMSG_DATA(h);
- index = ifi->ifi_index;
- type = IFLA_IFNAME;
- rta = NLMSG_RTA(h, sizeof(*ifi));
- } else {
- struct ifaddrmsg *ifa = NLMSG_DATA(h);
- index = ifa->ifa_index;
- type = IFA_LABEL;
- rta = NLMSG_RTA(h, sizeof(*ifa));
- }
- for (; NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) {
- if (rta->rta_type != type) continue;
-
- namelen = RTA_DATALEN(rta) - 1;
- if (namelen > IFNAMSIZ) return 0;
-
- /* suppress duplicates */
- bucket = index % IFADDRS_HASH_SIZE;
- i = ctx->hash[bucket];
- while (i) {
- map = &ctx->list[i-1];
- if (map->index == index &&
- map->namelen == namelen &&
- memcmp(map->name, RTA_DATA(rta), namelen) == 0)
- return 0;
- i = map->hash_next;
- }
-
- if (ctx->num >= ctx->allocated) {
- size_t a = ctx->allocated ? ctx->allocated * 2 + 1 : 8;
- if (a > SIZE_MAX/sizeof *map) return -1;
- map = realloc(ctx->list, a * sizeof *map);
- if (!map) return -1;
- ctx->list = map;
- ctx->allocated = a;
- }
- map = &ctx->list[ctx->num];
- map->index = index;
- map->namelen = namelen;
- memcpy(map->name, RTA_DATA(rta), namelen);
- ctx->str_bytes += namelen + 1;
- ctx->num++;
- map->hash_next = ctx->hash[bucket];
- ctx->hash[bucket] = ctx->num;
- return 0;
- }
- return 0;
-}
-
-struct if_nameindex *if_nameindex()
-{
- struct ifnameindexctx _ctx, *ctx = &_ctx;
- struct if_nameindex *ifs = 0, *d;
- struct ifnamemap *s;
- char *p;
- int i;
- int cs;
-
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
- memset(ctx, 0, sizeof(*ctx));
- if (__rtnetlink_enumerate(AF_UNSPEC, AF_INET, netlink_msg_to_nameindex, ctx) < 0) goto err;
-
- ifs = malloc(sizeof(struct if_nameindex[ctx->num+1]) + ctx->str_bytes);
- if (!ifs) goto err;
-
- p = (char*)(ifs + ctx->num + 1);
- for (i = ctx->num, d = ifs, s = ctx->list; i; i--, s++, d++) {
- d->if_index = s->index;
- d->if_name = p;
- memcpy(p, s->name, s->namelen);
- p += s->namelen;
- *p++ = 0;
- }
- d->if_index = 0;
- d->if_name = 0;
-err:
- pthread_setcancelstate(cs, 0);
- free(ctx->list);
- errno = ENOBUFS;
- return ifs;
-}
lib/libc/wasi/libc-top-half/musl/src/network/if_nametoindex.c
@@ -1,18 +0,0 @@
-#define _GNU_SOURCE
-#include <net/if.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <string.h>
-#include "syscall.h"
-
-unsigned if_nametoindex(const char *name)
-{
- struct ifreq ifr;
- int fd, r;
-
- if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 0;
- strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
- r = ioctl(fd, SIOCGIFINDEX, &ifr);
- __syscall(SYS_close, fd);
- return r < 0 ? 0 : ifr.ifr_ifindex;
-}
lib/libc/wasi/libc-top-half/musl/src/network/inet_addr.c
@@ -1,10 +0,0 @@
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-in_addr_t inet_addr(const char *p)
-{
- struct in_addr a;
- if (!__inet_aton(p, &a)) return -1;
- return a.s_addr;
-}
lib/libc/wasi/libc-top-half/musl/src/network/inet_legacy.c
@@ -1,32 +0,0 @@
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-in_addr_t inet_network(const char *p)
-{
- return ntohl(inet_addr(p));
-}
-
-struct in_addr inet_makeaddr(in_addr_t n, in_addr_t h)
-{
- if (n < 256) h |= n<<24;
- else if (n < 65536) h |= n<<16;
- else h |= n<<8;
- return (struct in_addr){ h };
-}
-
-in_addr_t inet_lnaof(struct in_addr in)
-{
- uint32_t h = in.s_addr;
- if (h>>24 < 128) return h & 0xffffff;
- if (h>>24 < 192) return h & 0xffff;
- return h & 0xff;
-}
-
-in_addr_t inet_netof(struct in_addr in)
-{
- uint32_t h = in.s_addr;
- if (h>>24 < 128) return h >> 24;
- if (h>>24 < 192) return h >> 16;
- return h >> 8;
-}
lib/libc/wasi/libc-top-half/musl/src/network/inet_ntoa.c
@@ -1,10 +0,0 @@
-#include <arpa/inet.h>
-#include <stdio.h>
-
-char *inet_ntoa(struct in_addr in)
-{
- static char buf[16];
- unsigned char *a = (void *)∈
- snprintf(buf, sizeof buf, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
- return buf;
-}
lib/libc/wasi/libc-top-half/musl/src/network/listen.c
@@ -1,7 +0,0 @@
-#include <sys/socket.h>
-#include "syscall.h"
-
-int listen(int fd, int backlog)
-{
- return socketcall(listen, fd, backlog, 0, 0, 0, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/network/lookup_ipliteral.c
@@ -1,55 +0,0 @@
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <net/if.h>
-#include <arpa/inet.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include "lookup.h"
-
-int __lookup_ipliteral(struct address buf[static 1], const char *name, int family)
-{
- struct in_addr a4;
- struct in6_addr a6;
- if (__inet_aton(name, &a4) > 0) {
- if (family == AF_INET6) /* wrong family */
- return EAI_NONAME;
- memcpy(&buf[0].addr, &a4, sizeof a4);
- buf[0].family = AF_INET;
- buf[0].scopeid = 0;
- return 1;
- }
-
- char tmp[64];
- char *p = strchr(name, '%'), *z;
- unsigned long long scopeid = 0;
- if (p && p-name < 64) {
- memcpy(tmp, name, p-name);
- tmp[p-name] = 0;
- name = tmp;
- }
-
- if (inet_pton(AF_INET6, name, &a6) <= 0)
- return 0;
- if (family == AF_INET) /* wrong family */
- return EAI_NONAME;
-
- memcpy(&buf[0].addr, &a6, sizeof a6);
- buf[0].family = AF_INET6;
- if (p) {
- if (isdigit(*++p)) scopeid = strtoull(p, &z, 10);
- else z = p-1;
- if (*z) {
- if (!IN6_IS_ADDR_LINKLOCAL(&a6) &&
- !IN6_IS_ADDR_MC_LINKLOCAL(&a6))
- return EAI_NONAME;
- scopeid = if_nametoindex(p);
- if (!scopeid) return EAI_NONAME;
- }
- if (scopeid > UINT_MAX) return EAI_NONAME;
- }
- buf[0].scopeid = scopeid;
- return 1;
-}
lib/libc/wasi/libc-top-half/musl/src/network/lookup_name.c
@@ -1,425 +0,0 @@
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <net/if.h>
-#include <arpa/inet.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <pthread.h>
-#include <errno.h>
-#include <resolv.h>
-#include "lookup.h"
-#include "stdio_impl.h"
-#include "syscall.h"
-
-static int is_valid_hostname(const char *host)
-{
- const unsigned char *s;
- if (strnlen(host, 255)-1 >= 254 || mbstowcs(0, host, 0) == -1) return 0;
- for (s=(void *)host; *s>=0x80 || *s=='.' || *s=='-' || isalnum(*s); s++);
- return !*s;
-}
-
-static int name_from_null(struct address buf[static 2], const char *name, int family, int flags)
-{
- int cnt = 0;
- if (name) return 0;
- if (flags & AI_PASSIVE) {
- if (family != AF_INET6)
- buf[cnt++] = (struct address){ .family = AF_INET };
- if (family != AF_INET)
- buf[cnt++] = (struct address){ .family = AF_INET6 };
- } else {
- if (family != AF_INET6)
- buf[cnt++] = (struct address){ .family = AF_INET, .addr = { 127,0,0,1 } };
- if (family != AF_INET)
- buf[cnt++] = (struct address){ .family = AF_INET6, .addr = { [15] = 1 } };
- }
- return cnt;
-}
-
-static int name_from_numeric(struct address buf[static 1], const char *name, int family)
-{
- return __lookup_ipliteral(buf, name, family);
-}
-
-static int name_from_hosts(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family)
-{
- char line[512];
- size_t l = strlen(name);
- int cnt = 0, badfam = 0, have_canon = 0;
- unsigned char _buf[1032];
- FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf);
- if (!f) switch (errno) {
- case ENOENT:
- case ENOTDIR:
- case EACCES:
- return 0;
- default:
- return EAI_SYSTEM;
- }
- while (fgets(line, sizeof line, f) && cnt < MAXADDRS) {
- char *p, *z;
-
- if ((p=strchr(line, '#'))) *p++='\n', *p=0;
- for(p=line+1; (p=strstr(p, name)) &&
- (!isspace(p[-1]) || !isspace(p[l])); p++);
- if (!p) continue;
-
- /* Isolate IP address to parse */
- for (p=line; *p && !isspace(*p); p++);
- *p++ = 0;
- switch (name_from_numeric(buf+cnt, line, family)) {
- case 1:
- cnt++;
- break;
- case 0:
- continue;
- default:
- badfam = EAI_NONAME;
- break;
- }
-
- if (have_canon) continue;
-
- /* Extract first name as canonical name */
- for (; *p && isspace(*p); p++);
- for (z=p; *z && !isspace(*z); z++);
- *z = 0;
- if (is_valid_hostname(p)) {
- have_canon = 1;
- memcpy(canon, p, z-p+1);
- }
- }
- __fclose_ca(f);
- return cnt ? cnt : badfam;
-}
-
-struct dpc_ctx {
- struct address *addrs;
- char *canon;
- int cnt;
-};
-
-#define RR_A 1
-#define RR_CNAME 5
-#define RR_AAAA 28
-
-static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet)
-{
- char tmp[256];
- struct dpc_ctx *ctx = c;
- if (ctx->cnt >= MAXADDRS) return -1;
- switch (rr) {
- case RR_A:
- if (len != 4) return -1;
- ctx->addrs[ctx->cnt].family = AF_INET;
- ctx->addrs[ctx->cnt].scopeid = 0;
- memcpy(ctx->addrs[ctx->cnt++].addr, data, 4);
- break;
- case RR_AAAA:
- if (len != 16) return -1;
- ctx->addrs[ctx->cnt].family = AF_INET6;
- ctx->addrs[ctx->cnt].scopeid = 0;
- memcpy(ctx->addrs[ctx->cnt++].addr, data, 16);
- break;
- case RR_CNAME:
- if (__dn_expand(packet, (const unsigned char *)packet + 512,
- data, tmp, sizeof tmp) > 0 && is_valid_hostname(tmp))
- strcpy(ctx->canon, tmp);
- break;
- }
- return 0;
-}
-
-static int name_from_dns(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, const struct resolvconf *conf)
-{
- unsigned char qbuf[2][280], abuf[2][512];
- const unsigned char *qp[2] = { qbuf[0], qbuf[1] };
- unsigned char *ap[2] = { abuf[0], abuf[1] };
- int qlens[2], alens[2];
- int i, nq = 0;
- struct dpc_ctx ctx = { .addrs = buf, .canon = canon };
- static const struct { int af; int rr; } afrr[2] = {
- { .af = AF_INET6, .rr = RR_A },
- { .af = AF_INET, .rr = RR_AAAA },
- };
-
- for (i=0; i<2; i++) {
- if (family != afrr[i].af) {
- qlens[nq] = __res_mkquery(0, name, 1, afrr[i].rr,
- 0, 0, 0, qbuf[nq], sizeof *qbuf);
- if (qlens[nq] == -1)
- return EAI_NONAME;
- qbuf[nq][3] = 0; /* don't need AD flag */
- nq++;
- }
- }
-
- if (__res_msend_rc(nq, qp, qlens, ap, alens, sizeof *abuf, conf) < 0)
- return EAI_SYSTEM;
-
- for (i=0; i<nq; i++) {
- if (alens[i] < 4 || (abuf[i][3] & 15) == 2) return EAI_AGAIN;
- if ((abuf[i][3] & 15) == 3) return 0;
- if ((abuf[i][3] & 15) != 0) return EAI_FAIL;
- }
-
- for (i=0; i<nq; i++)
- __dns_parse(abuf[i], alens[i], dns_parse_callback, &ctx);
-
- if (ctx.cnt) return ctx.cnt;
- return EAI_NONAME;
-}
-
-static int name_from_dns_search(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family)
-{
- char search[256];
- struct resolvconf conf;
- size_t l, dots;
- char *p, *z;
-
- if (__get_resolv_conf(&conf, search, sizeof search) < 0) return -1;
-
- /* Count dots, suppress search when >=ndots or name ends in
- * a dot, which is an explicit request for global scope. */
- for (dots=l=0; name[l]; l++) if (name[l]=='.') dots++;
- if (dots >= conf.ndots || name[l-1]=='.') *search = 0;
-
- /* Strip final dot for canon, fail if multiple trailing dots. */
- if (name[l-1]=='.') l--;
- if (!l || name[l-1]=='.') return EAI_NONAME;
-
- /* This can never happen; the caller already checked length. */
- if (l >= 256) return EAI_NONAME;
-
- /* Name with search domain appended is setup in canon[]. This both
- * provides the desired default canonical name (if the requested
- * name is not a CNAME record) and serves as a buffer for passing
- * the full requested name to name_from_dns. */
- memcpy(canon, name, l);
- canon[l] = '.';
-
- for (p=search; *p; p=z) {
- for (; isspace(*p); p++);
- for (z=p; *z && !isspace(*z); z++);
- if (z==p) break;
- if (z-p < 256 - l - 1) {
- memcpy(canon+l+1, p, z-p);
- canon[z-p+1+l] = 0;
- int cnt = name_from_dns(buf, canon, canon, family, &conf);
- if (cnt) return cnt;
- }
- }
-
- canon[l] = 0;
- return name_from_dns(buf, canon, name, family, &conf);
-}
-
-static const struct policy {
- unsigned char addr[16];
- unsigned char len, mask;
- unsigned char prec, label;
-} defpolicy[] = {
- { "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1", 15, 0xff, 50, 0 },
- { "\0\0\0\0\0\0\0\0\0\0\xff\xff", 11, 0xff, 35, 4 },
- { "\x20\2", 1, 0xff, 30, 2 },
- { "\x20\1", 3, 0xff, 5, 5 },
- { "\xfc", 0, 0xfe, 3, 13 },
-#if 0
- /* These are deprecated and/or returned to the address
- * pool, so despite the RFC, treating them as special
- * is probably wrong. */
- { "", 11, 0xff, 1, 3 },
- { "\xfe\xc0", 1, 0xc0, 1, 11 },
- { "\x3f\xfe", 1, 0xff, 1, 12 },
-#endif
- /* Last rule must match all addresses to stop loop. */
- { "", 0, 0, 40, 1 },
-};
-
-static const struct policy *policyof(const struct in6_addr *a)
-{
- int i;
- for (i=0; ; i++) {
- if (memcmp(a->s6_addr, defpolicy[i].addr, defpolicy[i].len))
- continue;
- if ((a->s6_addr[defpolicy[i].len] & defpolicy[i].mask)
- != defpolicy[i].addr[defpolicy[i].len])
- continue;
- return defpolicy+i;
- }
-}
-
-static int labelof(const struct in6_addr *a)
-{
- return policyof(a)->label;
-}
-
-static int scopeof(const struct in6_addr *a)
-{
- if (IN6_IS_ADDR_MULTICAST(a)) return a->s6_addr[1] & 15;
- if (IN6_IS_ADDR_LINKLOCAL(a)) return 2;
- if (IN6_IS_ADDR_LOOPBACK(a)) return 2;
- if (IN6_IS_ADDR_SITELOCAL(a)) return 5;
- return 14;
-}
-
-static int prefixmatch(const struct in6_addr *s, const struct in6_addr *d)
-{
- /* FIXME: The common prefix length should be limited to no greater
- * than the nominal length of the prefix portion of the source
- * address. However the definition of the source prefix length is
- * not clear and thus this limiting is not yet implemented. */
- unsigned i;
- for (i=0; i<128 && !((s->s6_addr[i/8]^d->s6_addr[i/8])&(128>>(i%8))); i++);
- return i;
-}
-
-#define DAS_USABLE 0x40000000
-#define DAS_MATCHINGSCOPE 0x20000000
-#define DAS_MATCHINGLABEL 0x10000000
-#define DAS_PREC_SHIFT 20
-#define DAS_SCOPE_SHIFT 16
-#define DAS_PREFIX_SHIFT 8
-#define DAS_ORDER_SHIFT 0
-
-static int addrcmp(const void *_a, const void *_b)
-{
- const struct address *a = _a, *b = _b;
- return b->sortkey - a->sortkey;
-}
-
-int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags)
-{
- int cnt = 0, i, j;
-
- *canon = 0;
- if (name) {
- /* reject empty name and check len so it fits into temp bufs */
- size_t l = strnlen(name, 255);
- if (l-1 >= 254)
- return EAI_NONAME;
- memcpy(canon, name, l+1);
- }
-
- /* Procedurally, a request for v6 addresses with the v4-mapped
- * flag set is like a request for unspecified family, followed
- * by filtering of the results. */
- if (flags & AI_V4MAPPED) {
- if (family == AF_INET6) family = AF_UNSPEC;
- else flags -= AI_V4MAPPED;
- }
-
- /* Try each backend until there's at least one result. */
- cnt = name_from_null(buf, name, family, flags);
- if (!cnt) cnt = name_from_numeric(buf, name, family);
- if (!cnt && !(flags & AI_NUMERICHOST)) {
- cnt = name_from_hosts(buf, canon, name, family);
- if (!cnt) cnt = name_from_dns_search(buf, canon, name, family);
- }
- if (cnt<=0) return cnt ? cnt : EAI_NONAME;
-
- /* Filter/transform results for v4-mapped lookup, if requested. */
- if (flags & AI_V4MAPPED) {
- if (!(flags & AI_ALL)) {
- /* If any v6 results exist, remove v4 results. */
- for (i=0; i<cnt && buf[i].family != AF_INET6; i++);
- if (i<cnt) {
- for (j=0; i<cnt; i++) {
- if (buf[i].family == AF_INET6)
- buf[j++] = buf[i];
- }
- cnt = i = j;
- }
- }
- /* Translate any remaining v4 results to v6 */
- for (i=0; i<cnt; i++) {
- if (buf[i].family != AF_INET) continue;
- memcpy(buf[i].addr+12, buf[i].addr, 4);
- memcpy(buf[i].addr, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
- buf[i].family = AF_INET6;
- }
- }
-
- /* No further processing is needed if there are fewer than 2
- * results or if there are only IPv4 results. */
- if (cnt<2 || family==AF_INET) return cnt;
- for (i=0; i<cnt; i++) if (buf[i].family != AF_INET) break;
- if (i==cnt) return cnt;
-
- int cs;
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
-
- /* The following implements a subset of RFC 3484/6724 destination
- * address selection by generating a single 31-bit sort key for
- * each address. Rules 3, 4, and 7 are omitted for having
- * excessive runtime and code size cost and dubious benefit.
- * So far the label/precedence table cannot be customized. */
- for (i=0; i<cnt; i++) {
- int family = buf[i].family;
- int key = 0;
- struct sockaddr_in6 sa6 = { 0 }, da6 = {
- .sin6_family = AF_INET6,
- .sin6_scope_id = buf[i].scopeid,
- .sin6_port = 65535
- };
- struct sockaddr_in sa4 = { 0 }, da4 = {
- .sin_family = AF_INET,
- .sin_port = 65535
- };
- void *sa, *da;
- socklen_t salen, dalen;
- if (family == AF_INET6) {
- memcpy(da6.sin6_addr.s6_addr, buf[i].addr, 16);
- da = &da6; dalen = sizeof da6;
- sa = &sa6; salen = sizeof sa6;
- } else {
- memcpy(sa6.sin6_addr.s6_addr,
- "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
- memcpy(da6.sin6_addr.s6_addr+12, buf[i].addr, 4);
- memcpy(da6.sin6_addr.s6_addr,
- "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
- memcpy(da6.sin6_addr.s6_addr+12, buf[i].addr, 4);
- memcpy(&da4.sin_addr, buf[i].addr, 4);
- da = &da4; dalen = sizeof da4;
- sa = &sa4; salen = sizeof sa4;
- }
- const struct policy *dpolicy = policyof(&da6.sin6_addr);
- int dscope = scopeof(&da6.sin6_addr);
- int dlabel = dpolicy->label;
- int dprec = dpolicy->prec;
- int prefixlen = 0;
- int fd = socket(family, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_UDP);
- if (fd >= 0) {
- if (!connect(fd, da, dalen)) {
- key |= DAS_USABLE;
- if (!getsockname(fd, sa, &salen)) {
- if (family == AF_INET) memcpy(
- sa6.sin6_addr.s6_addr+12,
- &sa4.sin_addr, 4);
- if (dscope == scopeof(&sa6.sin6_addr))
- key |= DAS_MATCHINGSCOPE;
- if (dlabel == labelof(&sa6.sin6_addr))
- key |= DAS_MATCHINGLABEL;
- prefixlen = prefixmatch(&sa6.sin6_addr,
- &da6.sin6_addr);
- }
- }
- close(fd);
- }
- key |= dprec << DAS_PREC_SHIFT;
- key |= (15-dscope) << DAS_SCOPE_SHIFT;
- key |= prefixlen << DAS_PREFIX_SHIFT;
- key |= (MAXADDRS-i) << DAS_ORDER_SHIFT;
- buf[i].sortkey = key;
- }
- qsort(buf, cnt, sizeof *buf, addrcmp);
-
- pthread_setcancelstate(cs, 0);
-
- return cnt;
-}
lib/libc/wasi/libc-top-half/musl/src/network/lookup_serv.c
@@ -1,114 +0,0 @@
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <ctype.h>
-#include <string.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <errno.h>
-#include "lookup.h"
-#include "stdio_impl.h"
-
-int __lookup_serv(struct service buf[static MAXSERVS], const char *name, int proto, int socktype, int flags)
-{
- char line[128];
- int cnt = 0;
- char *p, *z = "";
- unsigned long port = 0;
-
- switch (socktype) {
- case SOCK_STREAM:
- switch (proto) {
- case 0:
- proto = IPPROTO_TCP;
- case IPPROTO_TCP:
- break;
- default:
- return EAI_SERVICE;
- }
- break;
- case SOCK_DGRAM:
- switch (proto) {
- case 0:
- proto = IPPROTO_UDP;
- case IPPROTO_UDP:
- break;
- default:
- return EAI_SERVICE;
- }
- case 0:
- break;
- default:
- if (name) return EAI_SERVICE;
- buf[0].port = 0;
- buf[0].proto = proto;
- buf[0].socktype = socktype;
- return 1;
- }
-
- if (name) {
- if (!*name) return EAI_SERVICE;
- port = strtoul(name, &z, 10);
- }
- if (!*z) {
- if (port > 65535) return EAI_SERVICE;
- if (proto != IPPROTO_UDP) {
- buf[cnt].port = port;
- buf[cnt].socktype = SOCK_STREAM;
- buf[cnt++].proto = IPPROTO_TCP;
- }
- if (proto != IPPROTO_TCP) {
- buf[cnt].port = port;
- buf[cnt].socktype = SOCK_DGRAM;
- buf[cnt++].proto = IPPROTO_UDP;
- }
- return cnt;
- }
-
- if (flags & AI_NUMERICSERV) return EAI_NONAME;
-
- size_t l = strlen(name);
-
- unsigned char _buf[1032];
- FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf);
- if (!f) switch (errno) {
- case ENOENT:
- case ENOTDIR:
- case EACCES:
- return EAI_SERVICE;
- default:
- return EAI_SYSTEM;
- }
-
- while (fgets(line, sizeof line, f) && cnt < MAXSERVS) {
- if ((p=strchr(line, '#'))) *p++='\n', *p=0;
-
- /* Find service name */
- for(p=line; (p=strstr(p, name)); p++) {
- if (p>line && !isspace(p[-1])) continue;
- if (p[l] && !isspace(p[l])) continue;
- break;
- }
- if (!p) continue;
-
- /* Skip past canonical name at beginning of line */
- for (p=line; *p && !isspace(*p); p++);
-
- port = strtoul(p, &z, 10);
- if (port > 65535 || z==p) continue;
- if (!strncmp(z, "/udp", 4)) {
- if (proto == IPPROTO_TCP) continue;
- buf[cnt].port = port;
- buf[cnt].socktype = SOCK_DGRAM;
- buf[cnt++].proto = IPPROTO_UDP;
- }
- if (!strncmp(z, "/tcp", 4)) {
- if (proto == IPPROTO_UDP) continue;
- buf[cnt].port = port;
- buf[cnt].socktype = SOCK_STREAM;
- buf[cnt++].proto = IPPROTO_TCP;
- }
- }
- __fclose_ca(f);
- return cnt > 0 ? cnt : EAI_SERVICE;
-}
lib/libc/wasi/libc-top-half/musl/src/network/netlink.c
@@ -1,52 +0,0 @@
-#include <errno.h>
-#include <string.h>
-#include <syscall.h>
-#include <sys/socket.h>
-#include "netlink.h"
-
-static int __netlink_enumerate(int fd, unsigned int seq, int type, int af,
- int (*cb)(void *ctx, struct nlmsghdr *h), void *ctx)
-{
- struct nlmsghdr *h;
- union {
- uint8_t buf[8192];
- struct {
- struct nlmsghdr nlh;
- struct rtgenmsg g;
- } req;
- struct nlmsghdr reply;
- } u;
- int r, ret;
-
- memset(&u.req, 0, sizeof(u.req));
- u.req.nlh.nlmsg_len = sizeof(u.req);
- u.req.nlh.nlmsg_type = type;
- u.req.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST;
- u.req.nlh.nlmsg_seq = seq;
- u.req.g.rtgen_family = af;
- r = send(fd, &u.req, sizeof(u.req), 0);
- if (r < 0) return r;
-
- while (1) {
- r = recv(fd, u.buf, sizeof(u.buf), MSG_DONTWAIT);
- if (r <= 0) return -1;
- for (h = &u.reply; NLMSG_OK(h, (void*)&u.buf[r]); h = NLMSG_NEXT(h)) {
- if (h->nlmsg_type == NLMSG_DONE) return 0;
- if (h->nlmsg_type == NLMSG_ERROR) return -1;
- ret = cb(ctx, h);
- if (ret) return ret;
- }
- }
-}
-
-int __rtnetlink_enumerate(int link_af, int addr_af, int (*cb)(void *ctx, struct nlmsghdr *h), void *ctx)
-{
- int fd, r;
-
- fd = socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, NETLINK_ROUTE);
- if (fd < 0) return -1;
- r = __netlink_enumerate(fd, 1, RTM_GETLINK, link_af, cb, ctx);
- if (!r) r = __netlink_enumerate(fd, 2, RTM_GETADDR, addr_af, cb, ctx);
- __syscall(SYS_close,fd);
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/network/netname.c
@@ -1,12 +0,0 @@
-#include <netdb.h>
-
-struct netent *getnetbyaddr(uint32_t net, int type)
-{
- return 0;
-}
-
-struct netent *getnetbyname(const char *name)
-{
- return 0;
-}
-
lib/libc/wasi/libc-top-half/musl/src/network/ns_parse.c
@@ -1,171 +0,0 @@
-#define _BSD_SOURCE
-#include <errno.h>
-#include <stddef.h>
-#include <resolv.h>
-#include <arpa/nameser.h>
-
-const struct _ns_flagdata _ns_flagdata[16] = {
- { 0x8000, 15 },
- { 0x7800, 11 },
- { 0x0400, 10 },
- { 0x0200, 9 },
- { 0x0100, 8 },
- { 0x0080, 7 },
- { 0x0040, 6 },
- { 0x0020, 5 },
- { 0x0010, 4 },
- { 0x000f, 0 },
- { 0x0000, 0 },
- { 0x0000, 0 },
- { 0x0000, 0 },
- { 0x0000, 0 },
- { 0x0000, 0 },
- { 0x0000, 0 },
-};
-
-unsigned ns_get16(const unsigned char *cp)
-{
- return cp[0]<<8 | cp[1];
-}
-
-unsigned long ns_get32(const unsigned char *cp)
-{
- return (unsigned)cp[0]<<24 | cp[1]<<16 | cp[2]<<8 | cp[3];
-}
-
-void ns_put16(unsigned s, unsigned char *cp)
-{
- *cp++ = s>>8;
- *cp++ = s;
-}
-
-void ns_put32(unsigned long l, unsigned char *cp)
-{
- *cp++ = l>>24;
- *cp++ = l>>16;
- *cp++ = l>>8;
- *cp++ = l;
-}
-
-int ns_initparse(const unsigned char *msg, int msglen, ns_msg *handle)
-{
- int i, r;
-
- handle->_msg = msg;
- handle->_eom = msg + msglen;
- if (msglen < (2 + ns_s_max) * NS_INT16SZ) goto bad;
- NS_GET16(handle->_id, msg);
- NS_GET16(handle->_flags, msg);
- for (i = 0; i < ns_s_max; i++) NS_GET16(handle->_counts[i], msg);
- for (i = 0; i < ns_s_max; i++) {
- if (handle->_counts[i]) {
- handle->_sections[i] = msg;
- r = ns_skiprr(msg, handle->_eom, i, handle->_counts[i]);
- if (r < 0) return -1;
- msg += r;
- } else {
- handle->_sections[i] = NULL;
- }
- }
- if (msg != handle->_eom) goto bad;
- handle->_sect = ns_s_max;
- handle->_rrnum = -1;
- handle->_msg_ptr = NULL;
- return 0;
-bad:
- errno = EMSGSIZE;
- return -1;
-}
-
-int ns_skiprr(const unsigned char *ptr, const unsigned char *eom, ns_sect section, int count)
-{
- const unsigned char *p = ptr;
- int r;
-
- while (count--) {
- r = dn_skipname(p, eom);
- if (r < 0) goto bad;
- if (r + 2 * NS_INT16SZ > eom - p) goto bad;
- p += r + 2 * NS_INT16SZ;
- if (section != ns_s_qd) {
- if (NS_INT32SZ + NS_INT16SZ > eom - p) goto bad;
- p += NS_INT32SZ;
- NS_GET16(r, p);
- if (r > eom - p) goto bad;
- p += r;
- }
- }
- return p - ptr;
-bad:
- errno = EMSGSIZE;
- return -1;
-}
-
-int ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr)
-{
- int r;
-
- if (section < 0 || section >= ns_s_max) goto bad;
- if (section != handle->_sect) {
- handle->_sect = section;
- handle->_rrnum = 0;
- handle->_msg_ptr = handle->_sections[section];
- }
- if (rrnum == -1) rrnum = handle->_rrnum;
- if (rrnum < 0 || rrnum >= handle->_counts[section]) goto bad;
- if (rrnum < handle->_rrnum) {
- handle->_rrnum = 0;
- handle->_msg_ptr = handle->_sections[section];
- }
- if (rrnum > handle->_rrnum) {
- r = ns_skiprr(handle->_msg_ptr, handle->_eom, section, rrnum - handle->_rrnum);
- if (r < 0) return -1;
- handle->_msg_ptr += r;
- handle->_rrnum = rrnum;
- }
- r = ns_name_uncompress(handle->_msg, handle->_eom, handle->_msg_ptr, rr->name, NS_MAXDNAME);
- if (r < 0) return -1;
- handle->_msg_ptr += r;
- if (2 * NS_INT16SZ > handle->_eom - handle->_msg_ptr) goto size;
- NS_GET16(rr->type, handle->_msg_ptr);
- NS_GET16(rr->rr_class, handle->_msg_ptr);
- if (section != ns_s_qd) {
- if (NS_INT32SZ + NS_INT16SZ > handle->_eom - handle->_msg_ptr) goto size;
- NS_GET32(rr->ttl, handle->_msg_ptr);
- NS_GET16(rr->rdlength, handle->_msg_ptr);
- if (rr->rdlength > handle->_eom - handle->_msg_ptr) goto size;
- rr->rdata = handle->_msg_ptr;
- handle->_msg_ptr += rr->rdlength;
- } else {
- rr->ttl = 0;
- rr->rdlength = 0;
- rr->rdata = NULL;
- }
- handle->_rrnum++;
- if (handle->_rrnum > handle->_counts[section]) {
- handle->_sect = section + 1;
- if (handle->_sect == ns_s_max) {
- handle->_rrnum = -1;
- handle->_msg_ptr = NULL;
- } else {
- handle->_rrnum = 0;
- }
- }
- return 0;
-bad:
- errno = ENODEV;
- return -1;
-size:
- errno = EMSGSIZE;
- return -1;
-}
-
-int ns_name_uncompress(const unsigned char *msg, const unsigned char *eom,
- const unsigned char *src, char *dst, size_t dstsiz)
-{
- int r;
- r = dn_expand(msg, eom, src, dst, dstsiz);
- if (r < 0) errno = EMSGSIZE;
- return r;
-}
-
lib/libc/wasi/libc-top-half/musl/src/network/proto.c
@@ -1,84 +0,0 @@
-#include <netdb.h>
-#include <string.h>
-
-/* do we really need all these?? */
-
-static int idx;
-static const unsigned char protos[] = {
- "\000ip\0"
- "\001icmp\0"
- "\002igmp\0"
- "\003ggp\0"
- "\004ipencap\0"
- "\005st\0"
- "\006tcp\0"
- "\010egp\0"
- "\014pup\0"
- "\021udp\0"
- "\024hmp\0"
- "\026xns-idp\0"
- "\033rdp\0"
- "\035iso-tp4\0"
- "\044xtp\0"
- "\045ddp\0"
- "\046idpr-cmtp\0"
- "\051ipv6\0"
- "\053ipv6-route\0"
- "\054ipv6-frag\0"
- "\055idrp\0"
- "\056rsvp\0"
- "\057gre\0"
- "\062esp\0"
- "\063ah\0"
- "\071skip\0"
- "\072ipv6-icmp\0"
- "\073ipv6-nonxt\0"
- "\074ipv6-opts\0"
- "\111rspf\0"
- "\121vmtp\0"
- "\131ospf\0"
- "\136ipip\0"
- "\142encap\0"
- "\147pim\0"
- "\377raw"
-};
-
-void endprotoent(void)
-{
- idx = 0;
-}
-
-void setprotoent(int stayopen)
-{
- idx = 0;
-}
-
-struct protoent *getprotoent(void)
-{
- static struct protoent p;
- static const char *aliases;
- if (idx >= sizeof protos) return NULL;
- p.p_proto = protos[idx];
- p.p_name = (char *)&protos[idx+1];
- p.p_aliases = (char **)&aliases;
- idx += strlen(p.p_name) + 2;
- return &p;
-}
-
-struct protoent *getprotobyname(const char *name)
-{
- struct protoent *p;
- endprotoent();
- do p = getprotoent();
- while (p && strcmp(name, p->p_name));
- return p;
-}
-
-struct protoent *getprotobynumber(int num)
-{
- struct protoent *p;
- endprotoent();
- do p = getprotoent();
- while (p && p->p_proto != num);
- return p;
-}
lib/libc/wasi/libc-top-half/musl/src/network/recv.c
@@ -1,6 +0,0 @@
-#include <sys/socket.h>
-
-ssize_t recv(int fd, void *buf, size_t len, int flags)
-{
- return recvfrom(fd, buf, len, flags, 0, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/network/recvfrom.c
@@ -1,7 +0,0 @@
-#include <sys/socket.h>
-#include "syscall.h"
-
-ssize_t recvfrom(int fd, void *restrict buf, size_t len, int flags, struct sockaddr *restrict addr, socklen_t *restrict alen)
-{
- return socketcall_cp(recvfrom, fd, buf, len, flags, addr, alen);
-}
lib/libc/wasi/libc-top-half/musl/src/network/recvmmsg.c
@@ -1,39 +0,0 @@
-#define _GNU_SOURCE
-#include <sys/socket.h>
-#include <limits.h>
-#include <errno.h>
-#include <time.h>
-#include "syscall.h"
-
-#define IS32BIT(x) !((x)+0x80000000ULL>>32)
-#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
-
-hidden void __convert_scm_timestamps(struct msghdr *, socklen_t);
-
-int recvmmsg(int fd, struct mmsghdr *msgvec, unsigned int vlen, unsigned int flags, struct timespec *timeout)
-{
-#if LONG_MAX > INT_MAX
- struct mmsghdr *mh = msgvec;
- unsigned int i;
- for (i = vlen; i; i--, mh++)
- mh->msg_hdr.__pad1 = mh->msg_hdr.__pad2 = 0;
-#endif
-#ifdef SYS_recvmmsg_time64
- time_t s = timeout ? timeout->tv_sec : 0;
- long ns = timeout ? timeout->tv_nsec : 0;
- int r = __syscall_cp(SYS_recvmmsg_time64, fd, msgvec, vlen, flags,
- timeout ? ((long long[]){s, ns}) : 0);
- if (SYS_recvmmsg == SYS_recvmmsg_time64 || r!=-ENOSYS)
- return __syscall_ret(r);
- if (vlen > IOV_MAX) vlen = IOV_MAX;
- socklen_t csize[vlen];
- for (int i=0; i<vlen; i++) csize[i] = msgvec[i].msg_hdr.msg_controllen;
- r = __syscall_cp(SYS_recvmmsg, fd, msgvec, vlen, flags,
- timeout ? ((long[]){CLAMP(s), ns}) : 0);
- for (int i=0; i<r; i++)
- __convert_scm_timestamps(&msgvec[i].msg_hdr, csize[i]);
- return __syscall_ret(r);
-#else
- return syscall_cp(SYS_recvmmsg, fd, msgvec, vlen, flags, timeout);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/network/recvmsg.c
@@ -1,68 +0,0 @@
-#include <sys/socket.h>
-#include <limits.h>
-#include <time.h>
-#include <sys/time.h>
-#include <string.h>
-#include "syscall.h"
-
-hidden void __convert_scm_timestamps(struct msghdr *, socklen_t);
-
-void __convert_scm_timestamps(struct msghdr *msg, socklen_t csize)
-{
- if (SCM_TIMESTAMP == SCM_TIMESTAMP_OLD) return;
- if (!msg->msg_control || !msg->msg_controllen) return;
-
- struct cmsghdr *cmsg, *last=0;
- long tmp;
- long long tvts[2];
- int type = 0;
-
- for (cmsg=CMSG_FIRSTHDR(msg); cmsg; cmsg=CMSG_NXTHDR(msg, cmsg)) {
- if (cmsg->cmsg_level==SOL_SOCKET) switch (cmsg->cmsg_type) {
- case SCM_TIMESTAMP_OLD:
- if (type) break;
- type = SCM_TIMESTAMP;
- goto common;
- case SCM_TIMESTAMPNS_OLD:
- type = SCM_TIMESTAMPNS;
- common:
- memcpy(&tmp, CMSG_DATA(cmsg), sizeof tmp);
- tvts[0] = tmp;
- memcpy(&tmp, CMSG_DATA(cmsg) + sizeof tmp, sizeof tmp);
- tvts[1] = tmp;
- break;
- }
- last = cmsg;
- }
- if (!last || !type) return;
- if (CMSG_SPACE(sizeof tvts) > csize-msg->msg_controllen) {
- msg->msg_flags |= MSG_CTRUNC;
- return;
- }
- msg->msg_controllen += CMSG_SPACE(sizeof tvts);
- cmsg = CMSG_NXTHDR(msg, last);
- cmsg->cmsg_level = SOL_SOCKET;
- cmsg->cmsg_type = type;
- cmsg->cmsg_len = CMSG_LEN(sizeof tvts);
- memcpy(CMSG_DATA(cmsg), &tvts, sizeof tvts);
-}
-
-ssize_t recvmsg(int fd, struct msghdr *msg, int flags)
-{
- ssize_t r;
- socklen_t orig_controllen = msg->msg_controllen;
-#if LONG_MAX > INT_MAX
- struct msghdr h, *orig = msg;
- if (msg) {
- h = *msg;
- h.__pad1 = h.__pad2 = 0;
- msg = &h;
- }
-#endif
- r = socketcall_cp(recvmsg, fd, msg, flags, 0, 0, 0);
- if (r >= 0) __convert_scm_timestamps(msg, orig_controllen);
-#if LONG_MAX > INT_MAX
- if (orig) *orig = h;
-#endif
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/network/res_init.c
@@ -1,6 +0,0 @@
-#include <resolv.h>
-
-int res_init()
-{
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/network/res_mkquery.c
@@ -1,44 +0,0 @@
-#include <resolv.h>
-#include <string.h>
-#include <time.h>
-
-int __res_mkquery(int op, const char *dname, int class, int type,
- const unsigned char *data, int datalen,
- const unsigned char *newrr, unsigned char *buf, int buflen)
-{
- int id, i, j;
- unsigned char q[280];
- struct timespec ts;
- size_t l = strnlen(dname, 255);
- int n;
-
- if (l && dname[l-1]=='.') l--;
- n = 17+l+!!l;
- if (l>253 || buflen<n || op>15u || class>255u || type>255u)
- return -1;
-
- /* Construct query template - ID will be filled later */
- memset(q, 0, n);
- q[2] = op*8 + 1;
- q[3] = 32; /* AD */
- q[5] = 1;
- memcpy((char *)q+13, dname, l);
- for (i=13; q[i]; i=j+1) {
- for (j=i; q[j] && q[j] != '.'; j++);
- if (j-i-1u > 62u) return -1;
- q[i-1] = j-i;
- }
- q[i+1] = type;
- q[i+3] = class;
-
- /* Make a reasonably unpredictable id */
- clock_gettime(CLOCK_REALTIME, &ts);
- id = ts.tv_nsec + ts.tv_nsec/65536UL & 0xffff;
- q[0] = id/256;
- q[1] = id;
-
- memcpy(buf, q, n);
- return n;
-}
-
-weak_alias(__res_mkquery, res_mkquery);
lib/libc/wasi/libc-top-half/musl/src/network/res_msend.c
@@ -1,188 +0,0 @@
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <arpa/inet.h>
-#include <stdint.h>
-#include <string.h>
-#include <poll.h>
-#include <time.h>
-#include <ctype.h>
-#include <unistd.h>
-#include <errno.h>
-#include <pthread.h>
-#include "stdio_impl.h"
-#include "syscall.h"
-#include "lookup.h"
-
-static void cleanup(void *p)
-{
- __syscall(SYS_close, (intptr_t)p);
-}
-
-static unsigned long mtime()
-{
- struct timespec ts;
- clock_gettime(CLOCK_REALTIME, &ts);
- return (unsigned long)ts.tv_sec * 1000
- + ts.tv_nsec / 1000000;
-}
-
-int __res_msend_rc(int nqueries, const unsigned char *const *queries,
- const int *qlens, unsigned char *const *answers, int *alens, int asize,
- const struct resolvconf *conf)
-{
- int fd;
- int timeout, attempts, retry_interval, servfail_retry;
- union {
- struct sockaddr_in sin;
- struct sockaddr_in6 sin6;
- } sa = {0}, ns[MAXNS] = {{0}};
- socklen_t sl = sizeof sa.sin;
- int nns = 0;
- int family = AF_INET;
- int rlen;
- int next;
- int i, j;
- int cs;
- struct pollfd pfd;
- unsigned long t0, t1, t2;
-
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
-
- timeout = 1000*conf->timeout;
- attempts = conf->attempts;
-
- for (nns=0; nns<conf->nns; nns++) {
- const struct address *iplit = &conf->ns[nns];
- if (iplit->family == AF_INET) {
- memcpy(&ns[nns].sin.sin_addr, iplit->addr, 4);
- ns[nns].sin.sin_port = htons(53);
- ns[nns].sin.sin_family = AF_INET;
- } else {
- sl = sizeof sa.sin6;
- memcpy(&ns[nns].sin6.sin6_addr, iplit->addr, 16);
- ns[nns].sin6.sin6_port = htons(53);
- ns[nns].sin6.sin6_scope_id = iplit->scopeid;
- ns[nns].sin6.sin6_family = family = AF_INET6;
- }
- }
-
- /* Get local address and open/bind a socket */
- sa.sin.sin_family = family;
- fd = socket(family, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
-
- /* Handle case where system lacks IPv6 support */
- if (fd < 0 && family == AF_INET6 && errno == EAFNOSUPPORT) {
- fd = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
- family = AF_INET;
- }
- if (fd < 0 || bind(fd, (void *)&sa, sl) < 0) {
- if (fd >= 0) close(fd);
- pthread_setcancelstate(cs, 0);
- return -1;
- }
-
- /* Past this point, there are no errors. Each individual query will
- * yield either no reply (indicated by zero length) or an answer
- * packet which is up to the caller to interpret. */
-
- pthread_cleanup_push(cleanup, (void *)(intptr_t)fd);
- pthread_setcancelstate(cs, 0);
-
- /* Convert any IPv4 addresses in a mixed environment to v4-mapped */
- if (family == AF_INET6) {
- setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &(int){0}, sizeof 0);
- for (i=0; i<nns; i++) {
- if (ns[i].sin.sin_family != AF_INET) continue;
- memcpy(ns[i].sin6.sin6_addr.s6_addr+12,
- &ns[i].sin.sin_addr, 4);
- memcpy(ns[i].sin6.sin6_addr.s6_addr,
- "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
- ns[i].sin6.sin6_family = AF_INET6;
- ns[i].sin6.sin6_flowinfo = 0;
- ns[i].sin6.sin6_scope_id = 0;
- }
- }
-
- memset(alens, 0, sizeof *alens * nqueries);
-
- pfd.fd = fd;
- pfd.events = POLLIN;
- retry_interval = timeout / attempts;
- next = 0;
- t0 = t2 = mtime();
- t1 = t2 - retry_interval;
-
- for (; t2-t0 < timeout; t2=mtime()) {
- if (t2-t1 >= retry_interval) {
- /* Query all configured namservers in parallel */
- for (i=0; i<nqueries; i++)
- if (!alens[i])
- for (j=0; j<nns; j++)
- sendto(fd, queries[i],
- qlens[i], MSG_NOSIGNAL,
- (void *)&ns[j], sl);
- t1 = t2;
- servfail_retry = 2 * nqueries;
- }
-
- /* Wait for a response, or until time to retry */
- if (poll(&pfd, 1, t1+retry_interval-t2) <= 0) continue;
-
- while ((rlen = recvfrom(fd, answers[next], asize, 0,
- (void *)&sa, (socklen_t[1]){sl})) >= 0) {
-
- /* Ignore non-identifiable packets */
- if (rlen < 4) continue;
-
- /* Ignore replies from addresses we didn't send to */
- for (j=0; j<nns && memcmp(ns+j, &sa, sl); j++);
- if (j==nns) continue;
-
- /* Find which query this answer goes with, if any */
- for (i=next; i<nqueries && (
- answers[next][0] != queries[i][0] ||
- answers[next][1] != queries[i][1] ); i++);
- if (i==nqueries) continue;
- if (alens[i]) continue;
-
- /* Only accept positive or negative responses;
- * retry immediately on server failure, and ignore
- * all other codes such as refusal. */
- switch (answers[next][3] & 15) {
- case 0:
- case 3:
- break;
- case 2:
- if (servfail_retry && servfail_retry--)
- sendto(fd, queries[i],
- qlens[i], MSG_NOSIGNAL,
- (void *)&ns[j], sl);
- default:
- continue;
- }
-
- /* Store answer in the right slot, or update next
- * available temp slot if it's already in place. */
- alens[i] = rlen;
- if (i == next)
- for (; next<nqueries && alens[next]; next++);
- else
- memcpy(answers[i], answers[next], rlen);
-
- if (next == nqueries) goto out;
- }
- }
-out:
- pthread_cleanup_pop(1);
-
- return 0;
-}
-
-int __res_msend(int nqueries, const unsigned char *const *queries,
- const int *qlens, unsigned char *const *answers, int *alens, int asize)
-{
- struct resolvconf conf;
- if (__get_resolv_conf(&conf, 0, 0) < 0) return -1;
- return __res_msend_rc(nqueries, queries, qlens, answers, alens, asize, &conf);
-}
lib/libc/wasi/libc-top-half/musl/src/network/res_query.c
@@ -1,26 +0,0 @@
-#define _BSD_SOURCE
-#include <resolv.h>
-#include <netdb.h>
-
-int res_query(const char *name, int class, int type, unsigned char *dest, int len)
-{
- unsigned char q[280];
- int ql = __res_mkquery(0, name, class, type, 0, 0, 0, q, sizeof q);
- if (ql < 0) return ql;
- int r = __res_send(q, ql, dest, len);
- if (r<12) {
- h_errno = TRY_AGAIN;
- return -1;
- }
- if ((dest[3] & 15) == 3) {
- h_errno = HOST_NOT_FOUND;
- return -1;
- }
- if ((dest[3] & 15) == 0 && !dest[6] && !dest[7]) {
- h_errno = NO_DATA;
- return -1;
- }
- return r;
-}
-
-weak_alias(res_query, res_search);
lib/libc/wasi/libc-top-half/musl/src/network/res_querydomain.c
@@ -1,14 +0,0 @@
-#include <resolv.h>
-#include <string.h>
-
-int res_querydomain(const char *name, const char *domain, int class, int type, unsigned char *dest, int len)
-{
- char tmp[255];
- size_t nl = strnlen(name, 255);
- size_t dl = strnlen(domain, 255);
- if (nl+dl+1 > 254) return -1;
- memcpy(tmp, name, nl);
- tmp[nl] = '.';
- memcpy(tmp+nl+1, domain, dl+1);
- return res_query(tmp, class, type, dest, len);
-}
lib/libc/wasi/libc-top-half/musl/src/network/res_send.c
@@ -1,9 +0,0 @@
-#include <resolv.h>
-
-int __res_send(const unsigned char *msg, int msglen, unsigned char *answer, int anslen)
-{
- int r = __res_msend(1, &msg, &msglen, &answer, &anslen, anslen);
- return r<0 || !anslen ? -1 : anslen;
-}
-
-weak_alias(__res_send, res_send);
lib/libc/wasi/libc-top-half/musl/src/network/res_state.c
@@ -1,9 +0,0 @@
-#include <resolv.h>
-
-/* This is completely unused, and exists purely to satisfy broken apps. */
-
-struct __res_state *__res_state()
-{
- static struct __res_state res;
- return &res;
-}
lib/libc/wasi/libc-top-half/musl/src/network/resolvconf.c
@@ -1,94 +0,0 @@
-#include "lookup.h"
-#include "stdio_impl.h"
-#include <ctype.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <netinet/in.h>
-
-int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
-{
- char line[256];
- unsigned char _buf[256];
- FILE *f, _f;
- int nns = 0;
-
- conf->ndots = 1;
- conf->timeout = 5;
- conf->attempts = 2;
- if (search) *search = 0;
-
- f = __fopen_rb_ca("/etc/resolv.conf", &_f, _buf, sizeof _buf);
- if (!f) switch (errno) {
- case ENOENT:
- case ENOTDIR:
- case EACCES:
- goto no_resolv_conf;
- default:
- return -1;
- }
-
- while (fgets(line, sizeof line, f)) {
- char *p, *z;
- if (!strchr(line, '\n') && !feof(f)) {
- /* Ignore lines that get truncated rather than
- * potentially misinterpreting them. */
- int c;
- do c = getc(f);
- while (c != '\n' && c != EOF);
- continue;
- }
- if (!strncmp(line, "options", 7) && isspace(line[7])) {
- p = strstr(line, "ndots:");
- if (p && isdigit(p[6])) {
- p += 6;
- unsigned long x = strtoul(p, &z, 10);
- if (z != p) conf->ndots = x > 15 ? 15 : x;
- }
- p = strstr(line, "attempts:");
- if (p && isdigit(p[9])) {
- p += 9;
- unsigned long x = strtoul(p, &z, 10);
- if (z != p) conf->attempts = x > 10 ? 10 : x;
- }
- p = strstr(line, "timeout:");
- if (p && (isdigit(p[8]) || p[8]=='.')) {
- p += 8;
- unsigned long x = strtoul(p, &z, 10);
- if (z != p) conf->timeout = x > 60 ? 60 : x;
- }
- continue;
- }
- if (!strncmp(line, "nameserver", 10) && isspace(line[10])) {
- if (nns >= MAXNS) continue;
- for (p=line+11; isspace(*p); p++);
- for (z=p; *z && !isspace(*z); z++);
- *z=0;
- if (__lookup_ipliteral(conf->ns+nns, p, AF_UNSPEC) > 0)
- nns++;
- continue;
- }
-
- if (!search) continue;
- if ((strncmp(line, "domain", 6) && strncmp(line, "search", 6))
- || !isspace(line[6]))
- continue;
- for (p=line+7; isspace(*p); p++);
- size_t l = strlen(p);
- /* This can never happen anyway with chosen buffer sizes. */
- if (l >= search_sz) continue;
- memcpy(search, p, l+1);
- }
-
- __fclose_ca(f);
-
-no_resolv_conf:
- if (!nns) {
- __lookup_ipliteral(conf->ns, "127.0.0.1", AF_UNSPEC);
- nns = 1;
- }
-
- conf->nns = nns;
-
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/network/send.c
@@ -1,6 +0,0 @@
-#include <sys/socket.h>
-
-ssize_t send(int fd, const void *buf, size_t len, int flags)
-{
- return sendto(fd, buf, len, flags, 0, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/network/sendmmsg.c
@@ -1,30 +0,0 @@
-#define _GNU_SOURCE
-#include <sys/socket.h>
-#include <limits.h>
-#include <errno.h>
-#include "syscall.h"
-
-int sendmmsg(int fd, struct mmsghdr *msgvec, unsigned int vlen, unsigned int flags)
-{
-#if LONG_MAX > INT_MAX
- /* Can't use the syscall directly because the kernel has the wrong
- * idea for the types of msg_iovlen, msg_controllen, and cmsg_len,
- * and the cmsg blocks cannot be modified in-place. */
- int i;
- if (vlen > IOV_MAX) vlen = IOV_MAX; /* This matches the kernel. */
- if (!vlen) return 0;
- for (i=0; i<vlen; i++) {
- /* As an unfortunate inconsistency, the sendmmsg API uses
- * unsigned int for the resulting msg_len, despite sendmsg
- * returning ssize_t. However Linux limits the total bytes
- * sent by sendmsg to INT_MAX, so the assignment is safe. */
- ssize_t r = sendmsg(fd, &msgvec[i].msg_hdr, flags);
- if (r < 0) goto error;
- msgvec[i].msg_len = r;
- }
-error:
- return i ? i : -1;
-#else
- return syscall_cp(SYS_sendmmsg, fd, msgvec, vlen, flags);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/network/sendmsg.c
@@ -1,29 +0,0 @@
-#include <sys/socket.h>
-#include <limits.h>
-#include <string.h>
-#include <errno.h>
-#include "syscall.h"
-
-ssize_t sendmsg(int fd, const struct msghdr *msg, int flags)
-{
-#if LONG_MAX > INT_MAX
- struct msghdr h;
- struct cmsghdr chbuf[1024/sizeof(struct cmsghdr)+1], *c;
- if (msg) {
- h = *msg;
- h.__pad1 = h.__pad2 = 0;
- msg = &h;
- if (h.msg_controllen) {
- if (h.msg_controllen > 1024) {
- errno = ENOMEM;
- return -1;
- }
- memcpy(chbuf, h.msg_control, h.msg_controllen);
- h.msg_control = chbuf;
- for (c=CMSG_FIRSTHDR(&h); c; c=CMSG_NXTHDR(&h,c))
- c->__pad1 = 0;
- }
- }
-#endif
- return socketcall_cp(sendmsg, fd, msg, flags, 0, 0, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/network/sendto.c
@@ -1,7 +0,0 @@
-#include <sys/socket.h>
-#include "syscall.h"
-
-ssize_t sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen)
-{
- return socketcall_cp(sendto, fd, buf, len, flags, addr, alen);
-}
lib/libc/wasi/libc-top-half/musl/src/network/serv.c
@@ -1,14 +0,0 @@
-#include <netdb.h>
-
-void endservent(void)
-{
-}
-
-void setservent(int stayopen)
-{
-}
-
-struct servent *getservent(void)
-{
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/network/setsockopt.c
@@ -1,46 +0,0 @@
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <errno.h>
-#include "syscall.h"
-
-#define IS32BIT(x) !((x)+0x80000000ULL>>32)
-#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
-
-int setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
-{
- const struct timeval *tv;
- time_t s;
- suseconds_t us;
-
- int r = __socketcall(setsockopt, fd, level, optname, optval, optlen, 0);
-
- if (r==-ENOPROTOOPT) switch (level) {
- case SOL_SOCKET:
- switch (optname) {
- case SO_RCVTIMEO:
- case SO_SNDTIMEO:
- if (SO_RCVTIMEO == SO_RCVTIMEO_OLD) break;
- if (optlen < sizeof *tv) return __syscall_ret(-EINVAL);
- tv = optval;
- s = tv->tv_sec;
- us = tv->tv_usec;
- if (!IS32BIT(s)) return __syscall_ret(-ENOTSUP);
-
- if (optname==SO_RCVTIMEO) optname=SO_RCVTIMEO_OLD;
- if (optname==SO_SNDTIMEO) optname=SO_SNDTIMEO_OLD;
-
- r = __socketcall(setsockopt, fd, level, optname,
- ((long[]){s, CLAMP(us)}), 2*sizeof(long), 0);
- break;
- case SO_TIMESTAMP:
- case SO_TIMESTAMPNS:
- if (SO_TIMESTAMP == SO_TIMESTAMP_OLD) break;
- if (optname==SO_TIMESTAMP) optname=SO_TIMESTAMP_OLD;
- if (optname==SO_TIMESTAMPNS) optname=SO_TIMESTAMPNS_OLD;
- r = __socketcall(setsockopt, fd, level,
- optname, optval, optlen, 0);
- break;
- }
- }
- return __syscall_ret(r);
-}
lib/libc/wasi/libc-top-half/musl/src/network/shutdown.c
@@ -1,7 +0,0 @@
-#include <sys/socket.h>
-#include "syscall.h"
-
-int shutdown(int fd, int how)
-{
- return socketcall(shutdown, fd, how, 0, 0, 0, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/network/sockatmark.c
@@ -1,10 +0,0 @@
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-
-int sockatmark(int s)
-{
- int ret;
- if (ioctl(s, SIOCATMARK, &ret) < 0)
- return -1;
- return ret;
-}
lib/libc/wasi/libc-top-half/musl/src/network/socket.c
@@ -1,21 +0,0 @@
-#include <sys/socket.h>
-#include <fcntl.h>
-#include <errno.h>
-#include "syscall.h"
-
-int socket(int domain, int type, int protocol)
-{
- int s = __socketcall(socket, domain, type, protocol, 0, 0, 0);
- if ((s==-EINVAL || s==-EPROTONOSUPPORT)
- && (type&(SOCK_CLOEXEC|SOCK_NONBLOCK))) {
- s = __socketcall(socket, domain,
- type & ~(SOCK_CLOEXEC|SOCK_NONBLOCK),
- protocol, 0, 0, 0);
- if (s < 0) return __syscall_ret(s);
- if (type & SOCK_CLOEXEC)
- __syscall(SYS_fcntl, s, F_SETFD, FD_CLOEXEC);
- if (type & SOCK_NONBLOCK)
- __syscall(SYS_fcntl, s, F_SETFL, O_NONBLOCK);
- }
- return __syscall_ret(s);
-}
lib/libc/wasi/libc-top-half/musl/src/network/socketpair.c
@@ -1,25 +0,0 @@
-#include <sys/socket.h>
-#include <fcntl.h>
-#include <errno.h>
-#include "syscall.h"
-
-int socketpair(int domain, int type, int protocol, int fd[2])
-{
- int r = socketcall(socketpair, domain, type, protocol, fd, 0, 0);
- if (r<0 && (errno==EINVAL || errno==EPROTONOSUPPORT)
- && (type&(SOCK_CLOEXEC|SOCK_NONBLOCK))) {
- r = socketcall(socketpair, domain,
- type & ~(SOCK_CLOEXEC|SOCK_NONBLOCK),
- protocol, fd, 0, 0);
- if (r < 0) return r;
- if (type & SOCK_CLOEXEC) {
- __syscall(SYS_fcntl, fd[0], F_SETFD, FD_CLOEXEC);
- __syscall(SYS_fcntl, fd[1], F_SETFD, FD_CLOEXEC);
- }
- if (type & SOCK_NONBLOCK) {
- __syscall(SYS_fcntl, fd[0], F_SETFL, O_NONBLOCK);
- __syscall(SYS_fcntl, fd[1], F_SETFL, O_NONBLOCK);
- }
- }
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/fgetgrent.c
@@ -1,12 +0,0 @@
-#define _GNU_SOURCE
-#include "pwf.h"
-
-struct group *fgetgrent(FILE *f)
-{
- static char *line, **mem;
- static struct group gr;
- struct group *res;
- size_t size=0, nmem=0;
- __getgrent_a(f, &gr, &line, &size, &mem, &nmem, &res);
- return res;
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/fgetpwent.c
@@ -1,12 +0,0 @@
-#define _GNU_SOURCE
-#include "pwf.h"
-
-struct passwd *fgetpwent(FILE *f)
-{
- static char *line;
- static struct passwd pw;
- size_t size=0;
- struct passwd *res;
- __getpwent_a(f, &pw, &line, &size, &res);
- return res;
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/fgetspent.c
@@ -1,15 +0,0 @@
-#include "pwf.h"
-#include <pthread.h>
-
-struct spwd *fgetspent(FILE *f)
-{
- static char *line;
- static struct spwd sp;
- size_t size = 0;
- struct spwd *res = 0;
- int cs;
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
- if (getline(&line, &size, f) >= 0 && __parsespent(line, &sp) >= 0) res = &sp;
- pthread_setcancelstate(cs, 0);
- return res;
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/getgr_a.c
@@ -1,169 +0,0 @@
-#include <pthread.h>
-#include <byteswap.h>
-#include <string.h>
-#include <unistd.h>
-#include "pwf.h"
-#include "nscd.h"
-
-static char *itoa(char *p, uint32_t x)
-{
- // number of digits in a uint32_t + NUL
- p += 11;
- *--p = 0;
- do {
- *--p = '0' + x % 10;
- x /= 10;
- } while (x);
- return p;
-}
-
-int __getgr_a(const char *name, gid_t gid, struct group *gr, char **buf, size_t *size, char ***mem, size_t *nmem, struct group **res)
-{
- FILE *f;
- int rv = 0;
- int cs;
-
- *res = 0;
-
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
- f = fopen("/etc/group", "rbe");
- if (!f) {
- rv = errno;
- goto done;
- }
-
- while (!(rv = __getgrent_a(f, gr, buf, size, mem, nmem, res)) && *res) {
- if (name && !strcmp(name, (*res)->gr_name)
- || !name && (*res)->gr_gid == gid) {
- break;
- }
- }
- fclose(f);
-
- if (!*res && (rv == 0 || rv == ENOENT || rv == ENOTDIR)) {
- int32_t req = name ? GETGRBYNAME : GETGRBYGID;
- int32_t i;
- const char *key;
- int32_t groupbuf[GR_LEN] = {0};
- size_t len = 0;
- size_t grlist_len = 0;
- char gidbuf[11] = {0};
- int swap = 0;
- char *ptr;
-
- if (name) {
- key = name;
- } else {
- if (gid < 0 || gid > UINT32_MAX) {
- rv = 0;
- goto done;
- }
- key = itoa(gidbuf, gid);
- }
-
- f = __nscd_query(req, key, groupbuf, sizeof groupbuf, &swap);
- if (!f) { rv = errno; goto done; }
-
- if (!groupbuf[GRFOUND]) { rv = 0; goto cleanup_f; }
-
- if (!groupbuf[GRNAMELEN] || !groupbuf[GRPASSWDLEN]) {
- rv = EIO;
- goto cleanup_f;
- }
-
- if (groupbuf[GRNAMELEN] > SIZE_MAX - groupbuf[GRPASSWDLEN]) {
- rv = ENOMEM;
- goto cleanup_f;
- }
- len = groupbuf[GRNAMELEN] + groupbuf[GRPASSWDLEN];
-
- for (i = 0; i < groupbuf[GRMEMCNT]; i++) {
- uint32_t name_len;
- if (fread(&name_len, sizeof name_len, 1, f) < 1) {
- rv = ferror(f) ? errno : EIO;
- goto cleanup_f;
- }
- if (swap) {
- name_len = bswap_32(name_len);
- }
- if (name_len > SIZE_MAX - grlist_len
- || name_len > SIZE_MAX - len) {
- rv = ENOMEM;
- goto cleanup_f;
- }
- len += name_len;
- grlist_len += name_len;
- }
-
- if (len > *size || !*buf) {
- char *tmp = realloc(*buf, len);
- if (!tmp) {
- rv = errno;
- goto cleanup_f;
- }
- *buf = tmp;
- *size = len;
- }
-
- if (!fread(*buf, len, 1, f)) {
- rv = ferror(f) ? errno : EIO;
- goto cleanup_f;
- }
-
- if (groupbuf[GRMEMCNT] + 1 > *nmem) {
- if (groupbuf[GRMEMCNT] + 1 > SIZE_MAX/sizeof(char*)) {
- rv = ENOMEM;
- goto cleanup_f;
- }
- char **tmp = realloc(*mem, (groupbuf[GRMEMCNT]+1)*sizeof(char*));
- if (!tmp) {
- rv = errno;
- goto cleanup_f;
- }
- *mem = tmp;
- *nmem = groupbuf[GRMEMCNT] + 1;
- }
-
- if (groupbuf[GRMEMCNT]) {
- mem[0][0] = *buf + groupbuf[GRNAMELEN] + groupbuf[GRPASSWDLEN];
- for (ptr = mem[0][0], i = 0; ptr != mem[0][0]+grlist_len; ptr++)
- if (!*ptr) mem[0][++i] = ptr+1;
- mem[0][i] = 0;
-
- if (i != groupbuf[GRMEMCNT]) {
- rv = EIO;
- goto cleanup_f;
- }
- } else {
- mem[0][0] = 0;
- }
-
- gr->gr_name = *buf;
- gr->gr_passwd = gr->gr_name + groupbuf[GRNAMELEN];
- gr->gr_gid = groupbuf[GRGID];
- gr->gr_mem = *mem;
-
- if (gr->gr_passwd[-1]
- || gr->gr_passwd[groupbuf[GRPASSWDLEN]-1]) {
- rv = EIO;
- goto cleanup_f;
- }
-
- if (name && strcmp(name, gr->gr_name)
- || !name && gid != gr->gr_gid) {
- rv = EIO;
- goto cleanup_f;
- }
-
- *res = gr;
-
-cleanup_f:
- fclose(f);
- goto done;
- }
-
-done:
- pthread_setcancelstate(cs, 0);
- if (rv) errno = rv;
- return rv;
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/getgr_r.c
@@ -1,49 +0,0 @@
-#include "pwf.h"
-#include <pthread.h>
-
-#define FIX(x) (gr->gr_##x = gr->gr_##x-line+buf)
-
-static int getgr_r(const char *name, gid_t gid, struct group *gr, char *buf, size_t size, struct group **res)
-{
- char *line = 0;
- size_t len = 0;
- char **mem = 0;
- size_t nmem = 0;
- int rv = 0;
- size_t i;
- int cs;
-
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
-
- rv = __getgr_a(name, gid, gr, &line, &len, &mem, &nmem, res);
- if (*res && size < len + (nmem+1)*sizeof(char *) + 32) {
- *res = 0;
- rv = ERANGE;
- }
- if (*res) {
- buf += (16-(uintptr_t)buf)%16;
- gr->gr_mem = (void *)buf;
- buf += (nmem+1)*sizeof(char *);
- memcpy(buf, line, len);
- FIX(name);
- FIX(passwd);
- for (i=0; mem[i]; i++)
- gr->gr_mem[i] = mem[i]-line+buf;
- gr->gr_mem[i] = 0;
- }
- free(mem);
- free(line);
- pthread_setcancelstate(cs, 0);
- if (rv) errno = rv;
- return rv;
-}
-
-int getgrnam_r(const char *name, struct group *gr, char *buf, size_t size, struct group **res)
-{
- return getgr_r(name, 0, gr, buf, size, res);
-}
-
-int getgrgid_r(gid_t gid, struct group *gr, char *buf, size_t size, struct group **res)
-{
- return getgr_r(0, gid, gr, buf, size, res);
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/getgrent.c
@@ -1,39 +0,0 @@
-#include "pwf.h"
-
-static FILE *f;
-static char *line, **mem;
-static struct group gr;
-
-void setgrent()
-{
- if (f) fclose(f);
- f = 0;
-}
-
-weak_alias(setgrent, endgrent);
-
-struct group *getgrent()
-{
- struct group *res;
- size_t size=0, nmem=0;
- if (!f) f = fopen("/etc/group", "rbe");
- if (!f) return 0;
- __getgrent_a(f, &gr, &line, &size, &mem, &nmem, &res);
- return res;
-}
-
-struct group *getgrgid(gid_t gid)
-{
- struct group *res;
- size_t size=0, nmem=0;
- __getgr_a(0, gid, &gr, &line, &size, &mem, &nmem, &res);
- return res;
-}
-
-struct group *getgrnam(const char *name)
-{
- struct group *res;
- size_t size=0, nmem=0;
- __getgr_a(name, 0, &gr, &line, &size, &mem, &nmem, &res);
- return res;
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/getgrent_a.c
@@ -1,68 +0,0 @@
-#include "pwf.h"
-#include <pthread.h>
-
-static unsigned atou(char **s)
-{
- unsigned x;
- for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0');
- return x;
-}
-
-int __getgrent_a(FILE *f, struct group *gr, char **line, size_t *size, char ***mem, size_t *nmem, struct group **res)
-{
- ssize_t l;
- char *s, *mems;
- size_t i;
- int rv = 0;
- int cs;
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
- for (;;) {
- if ((l=getline(line, size, f)) < 0) {
- rv = ferror(f) ? errno : 0;
- free(*line);
- *line = 0;
- gr = 0;
- goto end;
- }
- line[0][l-1] = 0;
-
- s = line[0];
- gr->gr_name = s++;
- if (!(s = strchr(s, ':'))) continue;
-
- *s++ = 0; gr->gr_passwd = s;
- if (!(s = strchr(s, ':'))) continue;
-
- *s++ = 0; gr->gr_gid = atou(&s);
- if (*s != ':') continue;
-
- *s++ = 0; mems = s;
- break;
- }
-
- for (*nmem=!!*s; *s; s++)
- if (*s==',') ++*nmem;
- free(*mem);
- *mem = calloc(sizeof(char *), *nmem+1);
- if (!*mem) {
- rv = errno;
- free(*line);
- *line = 0;
- gr = 0;
- goto end;
- }
- if (*mems) {
- mem[0][0] = mems;
- for (s=mems, i=0; *s; s++)
- if (*s==',') *s++ = 0, mem[0][++i] = s;
- mem[0][++i] = 0;
- } else {
- mem[0][0] = 0;
- }
- gr->gr_mem = *mem;
-end:
- pthread_setcancelstate(cs, 0);
- *res = gr;
- if(rv) errno = rv;
- return rv;
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/getgrouplist.c
@@ -1,81 +0,0 @@
-#define _GNU_SOURCE
-#include "pwf.h"
-#include <grp.h>
-#include <string.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <byteswap.h>
-#include <errno.h>
-#include "nscd.h"
-
-int getgrouplist(const char *user, gid_t gid, gid_t *groups, int *ngroups)
-{
- int rv, nlim, ret = -1;
- ssize_t i, n = 1;
- struct group gr;
- struct group *res;
- FILE *f;
- int swap = 0;
- int32_t resp[INITGR_LEN];
- uint32_t *nscdbuf = 0;
- char *buf = 0;
- char **mem = 0;
- size_t nmem = 0;
- size_t size;
- nlim = *ngroups;
- if (nlim >= 1) *groups++ = gid;
-
- f = __nscd_query(GETINITGR, user, resp, sizeof resp, &swap);
- if (!f) goto cleanup;
- if (resp[INITGRFOUND]) {
- nscdbuf = calloc(resp[INITGRNGRPS], sizeof(uint32_t));
- if (!nscdbuf) goto cleanup;
- size_t nbytes = sizeof(*nscdbuf)*resp[INITGRNGRPS];
- if (nbytes && !fread(nscdbuf, nbytes, 1, f)) {
- if (!ferror(f)) errno = EIO;
- goto cleanup;
- }
- if (swap) {
- for (i = 0; i < resp[INITGRNGRPS]; i++)
- nscdbuf[i] = bswap_32(nscdbuf[i]);
- }
- }
- fclose(f);
-
- f = fopen("/etc/group", "rbe");
- if (!f && errno != ENOENT && errno != ENOTDIR)
- goto cleanup;
-
- if (f) {
- while (!(rv = __getgrent_a(f, &gr, &buf, &size, &mem, &nmem, &res)) && res) {
- if (nscdbuf)
- for (i=0; i < resp[INITGRNGRPS]; i++) {
- if (nscdbuf[i] == gr.gr_gid) nscdbuf[i] = gid;
- }
- for (i=0; gr.gr_mem[i] && strcmp(user, gr.gr_mem[i]); i++);
- if (!gr.gr_mem[i]) continue;
- if (++n <= nlim) *groups++ = gr.gr_gid;
- }
- if (rv) {
- errno = rv;
- goto cleanup;
- }
- }
- if (nscdbuf) {
- for(i=0; i < resp[INITGRNGRPS]; i++) {
- if (nscdbuf[i] != gid)
- if(++n <= nlim) *groups++ = nscdbuf[i];
- }
- }
-
- ret = n > nlim ? -1 : n;
- *ngroups = n;
-
-cleanup:
- if (f) fclose(f);
- free(nscdbuf);
- free(buf);
- free(mem);
- return ret;
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/getpw_a.c
@@ -1,142 +0,0 @@
-#include <pthread.h>
-#include <byteswap.h>
-#include <string.h>
-#include <unistd.h>
-#include "pwf.h"
-#include "nscd.h"
-
-static char *itoa(char *p, uint32_t x)
-{
- // number of digits in a uint32_t + NUL
- p += 11;
- *--p = 0;
- do {
- *--p = '0' + x % 10;
- x /= 10;
- } while (x);
- return p;
-}
-
-int __getpw_a(const char *name, uid_t uid, struct passwd *pw, char **buf, size_t *size, struct passwd **res)
-{
- FILE *f;
- int cs;
- int rv = 0;
-
- *res = 0;
-
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
-
- f = fopen("/etc/passwd", "rbe");
- if (!f) {
- rv = errno;
- goto done;
- }
-
- while (!(rv = __getpwent_a(f, pw, buf, size, res)) && *res) {
- if (name && !strcmp(name, (*res)->pw_name)
- || !name && (*res)->pw_uid == uid)
- break;
- }
- fclose(f);
-
- if (!*res && (rv == 0 || rv == ENOENT || rv == ENOTDIR)) {
- int32_t req = name ? GETPWBYNAME : GETPWBYUID;
- const char *key;
- int32_t passwdbuf[PW_LEN] = {0};
- size_t len = 0;
- char uidbuf[11] = {0};
-
- if (name) {
- key = name;
- } else {
- /* uid outside of this range can't be queried with the
- * nscd interface, but might happen if uid_t ever
- * happens to be a larger type (this is not true as of
- * now)
- */
- if(uid < 0 || uid > UINT32_MAX) {
- rv = 0;
- goto done;
- }
- key = itoa(uidbuf, uid);
- }
-
- f = __nscd_query(req, key, passwdbuf, sizeof passwdbuf, (int[]){0});
- if (!f) { rv = errno; goto done; }
-
- if(!passwdbuf[PWFOUND]) { rv = 0; goto cleanup_f; }
-
- /* A zero length response from nscd is invalid. We ignore
- * invalid responses and just report an error, rather than
- * trying to do something with them.
- */
- if (!passwdbuf[PWNAMELEN] || !passwdbuf[PWPASSWDLEN]
- || !passwdbuf[PWGECOSLEN] || !passwdbuf[PWDIRLEN]
- || !passwdbuf[PWSHELLLEN]) {
- rv = EIO;
- goto cleanup_f;
- }
-
- if ((passwdbuf[PWNAMELEN]|passwdbuf[PWPASSWDLEN]
- |passwdbuf[PWGECOSLEN]|passwdbuf[PWDIRLEN]
- |passwdbuf[PWSHELLLEN]) >= SIZE_MAX/8) {
- rv = ENOMEM;
- goto cleanup_f;
- }
-
- len = passwdbuf[PWNAMELEN] + passwdbuf[PWPASSWDLEN]
- + passwdbuf[PWGECOSLEN] + passwdbuf[PWDIRLEN]
- + passwdbuf[PWSHELLLEN];
-
- if (len > *size || !*buf) {
- char *tmp = realloc(*buf, len);
- if (!tmp) {
- rv = errno;
- goto cleanup_f;
- }
- *buf = tmp;
- *size = len;
- }
-
- if (!fread(*buf, len, 1, f)) {
- rv = ferror(f) ? errno : EIO;
- goto cleanup_f;
- }
-
- pw->pw_name = *buf;
- pw->pw_passwd = pw->pw_name + passwdbuf[PWNAMELEN];
- pw->pw_gecos = pw->pw_passwd + passwdbuf[PWPASSWDLEN];
- pw->pw_dir = pw->pw_gecos + passwdbuf[PWGECOSLEN];
- pw->pw_shell = pw->pw_dir + passwdbuf[PWDIRLEN];
- pw->pw_uid = passwdbuf[PWUID];
- pw->pw_gid = passwdbuf[PWGID];
-
- /* Don't assume that nscd made sure to null terminate strings.
- * It's supposed to, but malicious nscd should be ignored
- * rather than causing a crash.
- */
- if (pw->pw_passwd[-1] || pw->pw_gecos[-1] || pw->pw_dir[-1]
- || pw->pw_shell[passwdbuf[PWSHELLLEN]-1]) {
- rv = EIO;
- goto cleanup_f;
- }
-
- if (name && strcmp(name, pw->pw_name)
- || !name && uid != pw->pw_uid) {
- rv = EIO;
- goto cleanup_f;
- }
-
-
- *res = pw;
-cleanup_f:
- fclose(f);
- goto done;
- }
-
-done:
- pthread_setcancelstate(cs, 0);
- if (rv) errno = rv;
- return rv;
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/getpw_r.c
@@ -1,42 +0,0 @@
-#include "pwf.h"
-#include <pthread.h>
-
-#define FIX(x) (pw->pw_##x = pw->pw_##x-line+buf)
-
-static int getpw_r(const char *name, uid_t uid, struct passwd *pw, char *buf, size_t size, struct passwd **res)
-{
- char *line = 0;
- size_t len = 0;
- int rv = 0;
- int cs;
-
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
-
- rv = __getpw_a(name, uid, pw, &line, &len, res);
- if (*res && size < len) {
- *res = 0;
- rv = ERANGE;
- }
- if (*res) {
- memcpy(buf, line, len);
- FIX(name);
- FIX(passwd);
- FIX(gecos);
- FIX(dir);
- FIX(shell);
- }
- free(line);
- pthread_setcancelstate(cs, 0);
- if (rv) errno = rv;
- return rv;
-}
-
-int getpwnam_r(const char *name, struct passwd *pw, char *buf, size_t size, struct passwd **res)
-{
- return getpw_r(name, 0, pw, buf, size, res);
-}
-
-int getpwuid_r(uid_t uid, struct passwd *pw, char *buf, size_t size, struct passwd **res)
-{
- return getpw_r(0, uid, pw, buf, size, res);
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/getpwent.c
@@ -1,37 +0,0 @@
-#include "pwf.h"
-
-static FILE *f;
-static char *line;
-static struct passwd pw;
-static size_t size;
-
-void setpwent()
-{
- if (f) fclose(f);
- f = 0;
-}
-
-weak_alias(setpwent, endpwent);
-
-struct passwd *getpwent()
-{
- struct passwd *res;
- if (!f) f = fopen("/etc/passwd", "rbe");
- if (!f) return 0;
- __getpwent_a(f, &pw, &line, &size, &res);
- return res;
-}
-
-struct passwd *getpwuid(uid_t uid)
-{
- struct passwd *res;
- __getpw_a(0, uid, &pw, &line, &size, &res);
- return res;
-}
-
-struct passwd *getpwnam(const char *name)
-{
- struct passwd *res;
- __getpw_a(name, 0, &pw, &line, &size, &res);
- return res;
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/getpwent_a.c
@@ -1,54 +0,0 @@
-#include "pwf.h"
-#include <pthread.h>
-
-static unsigned atou(char **s)
-{
- unsigned x;
- for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0');
- return x;
-}
-
-int __getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *size, struct passwd **res)
-{
- ssize_t l;
- char *s;
- int rv = 0;
- int cs;
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
- for (;;) {
- if ((l=getline(line, size, f)) < 0) {
- rv = ferror(f) ? errno : 0;
- free(*line);
- *line = 0;
- pw = 0;
- break;
- }
- line[0][l-1] = 0;
-
- s = line[0];
- pw->pw_name = s++;
- if (!(s = strchr(s, ':'))) continue;
-
- *s++ = 0; pw->pw_passwd = s;
- if (!(s = strchr(s, ':'))) continue;
-
- *s++ = 0; pw->pw_uid = atou(&s);
- if (*s != ':') continue;
-
- *s++ = 0; pw->pw_gid = atou(&s);
- if (*s != ':') continue;
-
- *s++ = 0; pw->pw_gecos = s;
- if (!(s = strchr(s, ':'))) continue;
-
- *s++ = 0; pw->pw_dir = s;
- if (!(s = strchr(s, ':'))) continue;
-
- *s++ = 0; pw->pw_shell = s;
- break;
- }
- pthread_setcancelstate(cs, 0);
- *res = pw;
- if (rv) errno = rv;
- return rv;
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/getspent.c
@@ -1,14 +0,0 @@
-#include "pwf.h"
-
-void setspent()
-{
-}
-
-void endspent()
-{
-}
-
-struct spwd *getspent()
-{
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/getspnam.c
@@ -1,18 +0,0 @@
-#include "pwf.h"
-
-#define LINE_LIM 256
-
-struct spwd *getspnam(const char *name)
-{
- static struct spwd sp;
- static char *line;
- struct spwd *res;
- int e;
- int orig_errno = errno;
-
- if (!line) line = malloc(LINE_LIM);
- if (!line) return 0;
- e = getspnam_r(name, &sp, line, LINE_LIM, &res);
- errno = e ? e : orig_errno;
- return res;
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/getspnam_r.c
@@ -1,125 +0,0 @@
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <ctype.h>
-#include <pthread.h>
-#include "pwf.h"
-
-/* This implementation support Openwall-style TCB passwords in place of
- * traditional shadow, if the appropriate directories and files exist.
- * Thus, it is careful to avoid following symlinks or blocking on fifos
- * which a malicious user might create in place of his or her TCB shadow
- * file. It also avoids any allocation to prevent memory-exhaustion
- * attacks via huge TCB shadow files. */
-
-static long xatol(char **s)
-{
- long x;
- if (**s == ':' || **s == '\n') return -1;
- for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0');
- return x;
-}
-
-int __parsespent(char *s, struct spwd *sp)
-{
- sp->sp_namp = s;
- if (!(s = strchr(s, ':'))) return -1;
- *s = 0;
-
- sp->sp_pwdp = ++s;
- if (!(s = strchr(s, ':'))) return -1;
- *s = 0;
-
- s++; sp->sp_lstchg = xatol(&s);
- if (*s != ':') return -1;
-
- s++; sp->sp_min = xatol(&s);
- if (*s != ':') return -1;
-
- s++; sp->sp_max = xatol(&s);
- if (*s != ':') return -1;
-
- s++; sp->sp_warn = xatol(&s);
- if (*s != ':') return -1;
-
- s++; sp->sp_inact = xatol(&s);
- if (*s != ':') return -1;
-
- s++; sp->sp_expire = xatol(&s);
- if (*s != ':') return -1;
-
- s++; sp->sp_flag = xatol(&s);
- if (*s != '\n') return -1;
- return 0;
-}
-
-static void cleanup(void *p)
-{
- fclose(p);
-}
-
-int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t size, struct spwd **res)
-{
- char path[20+NAME_MAX];
- FILE *f = 0;
- int rv = 0;
- int fd;
- size_t k, l = strlen(name);
- int skip = 0;
- int cs;
- int orig_errno = errno;
-
- *res = 0;
-
- /* Disallow potentially-malicious user names */
- if (*name=='.' || strchr(name, '/') || !l)
- return errno = EINVAL;
-
- /* Buffer size must at least be able to hold name, plus some.. */
- if (size < l+100)
- return errno = ERANGE;
-
- /* Protect against truncation */
- if (snprintf(path, sizeof path, "/etc/tcb/%s/shadow", name) >= sizeof path)
- return errno = EINVAL;
-
- fd = open(path, O_RDONLY|O_NOFOLLOW|O_NONBLOCK|O_CLOEXEC);
- if (fd >= 0) {
- struct stat st = { 0 };
- errno = EINVAL;
- if (fstat(fd, &st) || !S_ISREG(st.st_mode) || !(f = fdopen(fd, "rb"))) {
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
- close(fd);
- pthread_setcancelstate(cs, 0);
- return errno;
- }
- } else {
- if (errno != ENOENT && errno != ENOTDIR)
- return errno;
- f = fopen("/etc/shadow", "rbe");
- if (!f) {
- if (errno != ENOENT && errno != ENOTDIR)
- return errno;
- return 0;
- }
- }
-
- pthread_cleanup_push(cleanup, f);
- while (fgets(buf, size, f) && (k=strlen(buf))>0) {
- if (skip || strncmp(name, buf, l) || buf[l]!=':') {
- skip = buf[k-1] != '\n';
- continue;
- }
- if (buf[k-1] != '\n') {
- rv = ERANGE;
- break;
- }
-
- if (__parsespent(buf, sp) < 0) continue;
- *res = sp;
- break;
- }
- pthread_cleanup_pop(1);
- errno = rv ? rv : orig_errno;
- return rv;
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/lckpwdf.c
@@ -1,11 +0,0 @@
-#include <shadow.h>
-
-int lckpwdf()
-{
- return 0;
-}
-
-int ulckpwdf()
-{
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/nscd_query.c
@@ -1,115 +0,0 @@
-#include <sys/socket.h>
-#include <byteswap.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <limits.h>
-#include "nscd.h"
-
-static const struct {
- short sun_family;
- char sun_path[21];
-} addr = {
- AF_UNIX,
- "/var/run/nscd/socket"
-};
-
-FILE *__nscd_query(int32_t req, const char *key, int32_t *buf, size_t len, int *swap)
-{
- size_t i;
- int fd;
- FILE *f = 0;
- int32_t req_buf[REQ_LEN] = {
- NSCDVERSION,
- req,
- strnlen(key,LOGIN_NAME_MAX)+1
- };
- struct msghdr msg = {
- .msg_iov = (struct iovec[]){
- {&req_buf, sizeof(req_buf)},
- {(char*)key, strlen(key)+1}
- },
- .msg_iovlen = 2
- };
- int errno_save = errno;
-
- *swap = 0;
-retry:
- memset(buf, 0, len);
- buf[0] = NSCDVERSION;
-
- fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
- if (fd < 0) {
- if (errno == EAFNOSUPPORT) {
- f = fopen("/dev/null", "re");
- if (f)
- errno = errno_save;
- return f;
- }
- return 0;
- }
-
- if(!(f = fdopen(fd, "r"))) {
- close(fd);
- return 0;
- }
-
- if (req_buf[2] > LOGIN_NAME_MAX)
- return f;
-
- if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
- /* If there isn't a running nscd we simulate a "not found"
- * result and the caller is responsible for calling
- * fclose on the (unconnected) socket. The value of
- * errno must be left unchanged in this case. */
- if (errno == EACCES || errno == ECONNREFUSED || errno == ENOENT) {
- errno = errno_save;
- return f;
- }
- goto error;
- }
-
- if (sendmsg(fd, &msg, MSG_NOSIGNAL) < 0)
- goto error;
-
- if (!fread(buf, len, 1, f)) {
- /* If the VERSION entry mismatches nscd will disconnect. The
- * most likely cause is that the endianness mismatched. So, we
- * byteswap and try once more. (if we already swapped, just
- * fail out)
- */
- if (ferror(f)) goto error;
- if (!*swap) {
- fclose(f);
- for (i = 0; i < sizeof(req_buf)/sizeof(req_buf[0]); i++) {
- req_buf[i] = bswap_32(req_buf[i]);
- }
- *swap = 1;
- goto retry;
- } else {
- errno = EIO;
- goto error;
- }
- }
-
- if (*swap) {
- for (i = 0; i < len/sizeof(buf[0]); i++) {
- buf[i] = bswap_32(buf[i]);
- }
- }
-
- /* The first entry in every nscd response is the version number. This
- * really shouldn't happen, and is evidence of some form of malformed
- * response.
- */
- if(buf[0] != NSCDVERSION) {
- errno = EIO;
- goto error;
- }
-
- return f;
-error:
- fclose(f);
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/putgrent.c
@@ -1,17 +0,0 @@
-#define _GNU_SOURCE
-#include <grp.h>
-#include <stdio.h>
-
-int putgrent(const struct group *gr, FILE *f)
-{
- int r;
- size_t i;
- flockfile(f);
- if ((r = fprintf(f, "%s:%s:%u:", gr->gr_name, gr->gr_passwd, gr->gr_gid))<0) goto done;
- if (gr->gr_mem) for (i=0; gr->gr_mem[i]; i++)
- if ((r = fprintf(f, "%s%s", i?",":"", gr->gr_mem[i]))<0) goto done;
- r = fputc('\n', f);
-done:
- funlockfile(f);
- return r<0 ? -1 : 0;
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/putpwent.c
@@ -1,10 +0,0 @@
-#define _GNU_SOURCE
-#include <pwd.h>
-#include <stdio.h>
-
-int putpwent(const struct passwd *pw, FILE *f)
-{
- return fprintf(f, "%s:%s:%u:%u:%s:%s:%s\n",
- pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid,
- pw->pw_gecos, pw->pw_dir, pw->pw_shell)<0 ? -1 : 0;
-}
lib/libc/wasi/libc-top-half/musl/src/passwd/putspent.c
@@ -1,13 +0,0 @@
-#include <shadow.h>
-#include <stdio.h>
-
-#define NUM(n) ((n) == -1 ? 0 : -1), ((n) == -1 ? 0 : (n))
-#define STR(s) ((s) ? (s) : "")
-
-int putspent(const struct spwd *sp, FILE *f)
-{
- return fprintf(f, "%s:%s:%.*ld:%.*ld:%.*ld:%.*ld:%.*ld:%.*ld:%.*lu\n",
- STR(sp->sp_namp), STR(sp->sp_pwdp), NUM(sp->sp_lstchg),
- NUM(sp->sp_min), NUM(sp->sp_max), NUM(sp->sp_warn),
- NUM(sp->sp_inact), NUM(sp->sp_expire), NUM(sp->sp_flag)) < 0 ? -1 : 0;
-}
lib/libc/wasi/libc-top-half/musl/src/process/arm/vfork.s
@@ -1,10 +0,0 @@
-.syntax unified
-.global vfork
-.type vfork,%function
-vfork:
- mov ip, r7
- mov r7, 190
- svc 0
- mov r7, ip
- .hidden __syscall_ret
- b __syscall_ret
lib/libc/wasi/libc-top-half/musl/src/process/i386/vfork.s
@@ -1,12 +0,0 @@
-.global vfork
-.type vfork,@function
-vfork:
- pop %edx
- mov $190,%eax
- int $128
- push %edx
- push %eax
- .hidden __syscall_ret
- call __syscall_ret
- pop %edx
- ret
lib/libc/wasi/libc-top-half/musl/src/process/s390x/vfork.s
@@ -1,6 +0,0 @@
- .global vfork
- .type vfork,%function
-vfork:
- svc 190
- .hidden __syscall_ret
- jg __syscall_ret
lib/libc/wasi/libc-top-half/musl/src/process/sh/vfork.s
@@ -1,20 +0,0 @@
-.global vfork
-.type vfork,@function
-vfork:
- mov #95, r3
- add r3, r3
-
- trapa #31
- or r0, r0
- or r0, r0
- or r0, r0
- or r0, r0
- or r0, r0
-
- mov r0, r4
- mov.l 1f, r0
-2: braf r0
- nop
- .align 2
- .hidden __syscall_ret
-1: .long __syscall_ret@PLT-(2b+4-.)
lib/libc/wasi/libc-top-half/musl/src/process/x32/vfork.s
@@ -1,10 +0,0 @@
-.global vfork
-.type vfork,@function
-vfork:
- pop %rdx
- mov $0x4000003a,%eax /* SYS_vfork */
- syscall
- push %rdx
- mov %rax,%rdi
- .hidden __syscall_ret
- jmp __syscall_ret
lib/libc/wasi/libc-top-half/musl/src/process/x86_64/vfork.s
@@ -1,10 +0,0 @@
-.global vfork
-.type vfork,@function
-vfork:
- pop %rdx
- mov $58,%eax
- syscall
- push %rdx
- mov %rax,%rdi
- .hidden __syscall_ret
- jmp __syscall_ret
lib/libc/wasi/libc-top-half/musl/src/process/_Fork.c
@@ -1,38 +0,0 @@
-#include <unistd.h>
-#include <signal.h>
-#include "syscall.h"
-#include "libc.h"
-#include "lock.h"
-#include "pthread_impl.h"
-#include "aio_impl.h"
-
-static void dummy(int x) { }
-weak_alias(dummy, __aio_atfork);
-
-pid_t _Fork(void)
-{
- pid_t ret;
- sigset_t set;
- __block_all_sigs(&set);
- __aio_atfork(-1);
- LOCK(__abort_lock);
-#ifdef SYS_fork
- ret = __syscall(SYS_fork);
-#else
- ret = __syscall(SYS_clone, SIGCHLD, 0);
-#endif
- if (!ret) {
- pthread_t self = __pthread_self();
- self->tid = __syscall(SYS_gettid);
- self->robust_list.off = 0;
- self->robust_list.pending = 0;
- self->next = self->prev = self;
- __thread_list_lock = 0;
- libc.threads_minus_1 = 0;
- if (libc.need_locks) libc.need_locks = -1;
- }
- UNLOCK(__abort_lock);
- __aio_atfork(!ret);
- __restore_sigs(&set);
- return __syscall_ret(ret);
-}
lib/libc/wasi/libc-top-half/musl/src/process/execl.c
@@ -1,22 +0,0 @@
-#include <unistd.h>
-#include <stdarg.h>
-
-int execl(const char *path, const char *argv0, ...)
-{
- int argc;
- va_list ap;
- va_start(ap, argv0);
- for (argc=1; va_arg(ap, const char *); argc++);
- va_end(ap);
- {
- int i;
- char *argv[argc+1];
- va_start(ap, argv0);
- argv[0] = (char *)argv0;
- for (i=1; i<argc; i++)
- argv[i] = va_arg(ap, char *);
- argv[i] = NULL;
- va_end(ap);
- return execv(path, argv);
- }
-}
lib/libc/wasi/libc-top-half/musl/src/process/execle.c
@@ -1,23 +0,0 @@
-#include <unistd.h>
-#include <stdarg.h>
-
-int execle(const char *path, const char *argv0, ...)
-{
- int argc;
- va_list ap;
- va_start(ap, argv0);
- for (argc=1; va_arg(ap, const char *); argc++);
- va_end(ap);
- {
- int i;
- char *argv[argc+1];
- char **envp;
- va_start(ap, argv0);
- argv[0] = (char *)argv0;
- for (i=1; i<=argc; i++)
- argv[i] = va_arg(ap, char *);
- envp = va_arg(ap, char **);
- va_end(ap);
- return execve(path, argv, envp);
- }
-}
lib/libc/wasi/libc-top-half/musl/src/process/execlp.c
@@ -1,22 +0,0 @@
-#include <unistd.h>
-#include <stdarg.h>
-
-int execlp(const char *file, const char *argv0, ...)
-{
- int argc;
- va_list ap;
- va_start(ap, argv0);
- for (argc=1; va_arg(ap, const char *); argc++);
- va_end(ap);
- {
- int i;
- char *argv[argc+1];
- va_start(ap, argv0);
- argv[0] = (char *)argv0;
- for (i=1; i<argc; i++)
- argv[i] = va_arg(ap, char *);
- argv[i] = NULL;
- va_end(ap);
- return execvp(file, argv);
- }
-}
lib/libc/wasi/libc-top-half/musl/src/process/execv.c
@@ -1,8 +0,0 @@
-#include <unistd.h>
-
-extern char **__environ;
-
-int execv(const char *path, char *const argv[])
-{
- return execve(path, argv, __environ);
-}
lib/libc/wasi/libc-top-half/musl/src/process/execve.c
@@ -1,8 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-int execve(const char *path, char *const argv[], char *const envp[])
-{
- /* do we need to use environ if envp is null? */
- return syscall(SYS_execve, path, argv, envp);
-}
lib/libc/wasi/libc-top-half/musl/src/process/execvp.c
@@ -1,60 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <limits.h>
-
-extern char **__environ;
-
-int __execvpe(const char *file, char *const argv[], char *const envp[])
-{
- const char *p, *z, *path = getenv("PATH");
- size_t l, k;
- int seen_eacces = 0;
-
- errno = ENOENT;
- if (!*file) return -1;
-
- if (strchr(file, '/'))
- return execve(file, argv, envp);
-
- if (!path) path = "/usr/local/bin:/bin:/usr/bin";
- k = strnlen(file, NAME_MAX+1);
- if (k > NAME_MAX) {
- errno = ENAMETOOLONG;
- return -1;
- }
- l = strnlen(path, PATH_MAX-1)+1;
-
- for(p=path; ; p=z) {
- char b[l+k+1];
- z = __strchrnul(p, ':');
- if (z-p >= l) {
- if (!*z++) break;
- continue;
- }
- memcpy(b, p, z-p);
- b[z-p] = '/';
- memcpy(b+(z-p)+(z>p), file, k+1);
- execve(b, argv, envp);
- switch (errno) {
- case EACCES:
- seen_eacces = 1;
- case ENOENT:
- case ENOTDIR:
- break;
- default:
- return -1;
- }
- if (!*z++) break;
- }
- if (seen_eacces) errno = EACCES;
- return -1;
-}
-
-int execvp(const char *file, char *const argv[])
-{
- return __execvpe(file, argv, __environ);
-}
-
-weak_alias(__execvpe, execvpe);
lib/libc/wasi/libc-top-half/musl/src/process/fexecve.c
@@ -1,16 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int fexecve(int fd, char *const argv[], char *const envp[])
-{
- int r = __syscall(SYS_execveat, fd, "", argv, envp, AT_EMPTY_PATH);
- if (r != -ENOSYS) return __syscall_ret(r);
- char buf[15 + 3*sizeof(int)];
- __procfdname(buf, fd);
- execve(buf, argv, envp);
- if (errno == ENOENT) errno = EBADF;
- return -1;
-}
lib/libc/wasi/libc-top-half/musl/src/process/fork.c
@@ -1,86 +0,0 @@
-#include <unistd.h>
-#include <errno.h>
-#include "libc.h"
-#include "lock.h"
-#include "pthread_impl.h"
-#include "fork_impl.h"
-
-static volatile int *const dummy_lockptr = 0;
-
-weak_alias(dummy_lockptr, __at_quick_exit_lockptr);
-weak_alias(dummy_lockptr, __atexit_lockptr);
-weak_alias(dummy_lockptr, __dlerror_lockptr);
-weak_alias(dummy_lockptr, __gettext_lockptr);
-weak_alias(dummy_lockptr, __locale_lockptr);
-weak_alias(dummy_lockptr, __random_lockptr);
-weak_alias(dummy_lockptr, __sem_open_lockptr);
-weak_alias(dummy_lockptr, __stdio_ofl_lockptr);
-weak_alias(dummy_lockptr, __syslog_lockptr);
-weak_alias(dummy_lockptr, __timezone_lockptr);
-weak_alias(dummy_lockptr, __bump_lockptr);
-
-weak_alias(dummy_lockptr, __vmlock_lockptr);
-
-static volatile int *const *const atfork_locks[] = {
- &__at_quick_exit_lockptr,
- &__atexit_lockptr,
- &__dlerror_lockptr,
- &__gettext_lockptr,
- &__locale_lockptr,
- &__random_lockptr,
- &__sem_open_lockptr,
- &__stdio_ofl_lockptr,
- &__syslog_lockptr,
- &__timezone_lockptr,
- &__bump_lockptr,
-};
-
-static void dummy(int x) { }
-weak_alias(dummy, __fork_handler);
-weak_alias(dummy, __malloc_atfork);
-weak_alias(dummy, __ldso_atfork);
-
-static void dummy_0(void) { }
-weak_alias(dummy_0, __tl_lock);
-weak_alias(dummy_0, __tl_unlock);
-
-pid_t fork(void)
-{
- sigset_t set;
- __fork_handler(-1);
- __block_app_sigs(&set);
- int need_locks = libc.need_locks > 0;
- if (need_locks) {
- __ldso_atfork(-1);
- __inhibit_ptc();
- for (int i=0; i<sizeof atfork_locks/sizeof *atfork_locks; i++)
- if (*atfork_locks[i]) LOCK(*atfork_locks[i]);
- __malloc_atfork(-1);
- __tl_lock();
- }
- pthread_t self=__pthread_self(), next=self->next;
- pid_t ret = _Fork();
- int errno_save = errno;
- if (need_locks) {
- if (!ret) {
- for (pthread_t td=next; td!=self; td=td->next)
- td->tid = -1;
- if (__vmlock_lockptr) {
- __vmlock_lockptr[0] = 0;
- __vmlock_lockptr[1] = 0;
- }
- }
- __tl_unlock();
- __malloc_atfork(!ret);
- for (int i=0; i<sizeof atfork_locks/sizeof *atfork_locks; i++)
- if (*atfork_locks[i])
- if (ret) UNLOCK(*atfork_locks[i]);
- else **atfork_locks[i] = 0;
- __release_ptc();
- __ldso_atfork(!ret);
- }
- __restore_sigs(&set);
- __fork_handler(!ret);
- if (ret<0) errno = errno_save;
- return ret;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn.c
@@ -1,214 +0,0 @@
-#define _GNU_SOURCE
-#include <spawn.h>
-#include <sched.h>
-#include <unistd.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <sys/wait.h>
-#include "syscall.h"
-#include "lock.h"
-#include "pthread_impl.h"
-#include "fdop.h"
-
-struct args {
- int p[2];
- sigset_t oldmask;
- const char *path;
- const posix_spawn_file_actions_t *fa;
- const posix_spawnattr_t *restrict attr;
- char *const *argv, *const *envp;
-};
-
-static int __sys_dup2(int old, int new)
-{
-#ifdef SYS_dup2
- return __syscall(SYS_dup2, old, new);
-#else
- return __syscall(SYS_dup3, old, new, 0);
-#endif
-}
-
-static int child(void *args_vp)
-{
- int i, ret;
- struct sigaction sa = {0};
- struct args *args = args_vp;
- int p = args->p[1];
- const posix_spawn_file_actions_t *fa = args->fa;
- const posix_spawnattr_t *restrict attr = args->attr;
- sigset_t hset;
-
- close(args->p[0]);
-
- /* All signal dispositions must be either SIG_DFL or SIG_IGN
- * before signals are unblocked. Otherwise a signal handler
- * from the parent might get run in the child while sharing
- * memory, with unpredictable and dangerous results. To
- * reduce overhead, sigaction has tracked for us which signals
- * potentially have a signal handler. */
- __get_handler_set(&hset);
- for (i=1; i<_NSIG; i++) {
- if ((attr->__flags & POSIX_SPAWN_SETSIGDEF)
- && sigismember(&attr->__def, i)) {
- sa.sa_handler = SIG_DFL;
- } else if (sigismember(&hset, i)) {
- if (i-32<3U) {
- sa.sa_handler = SIG_IGN;
- } else {
- __libc_sigaction(i, 0, &sa);
- if (sa.sa_handler==SIG_IGN) continue;
- sa.sa_handler = SIG_DFL;
- }
- } else {
- continue;
- }
- __libc_sigaction(i, &sa, 0);
- }
-
- if (attr->__flags & POSIX_SPAWN_SETSID)
- if ((ret=__syscall(SYS_setsid)) < 0)
- goto fail;
-
- if (attr->__flags & POSIX_SPAWN_SETPGROUP)
- if ((ret=__syscall(SYS_setpgid, 0, attr->__pgrp)))
- goto fail;
-
- /* Use syscalls directly because the library functions attempt
- * to do a multi-threaded synchronized id-change, which would
- * trash the parent's state. */
- if (attr->__flags & POSIX_SPAWN_RESETIDS)
- if ((ret=__syscall(SYS_setgid, __syscall(SYS_getgid))) ||
- (ret=__syscall(SYS_setuid, __syscall(SYS_getuid))) )
- goto fail;
-
- if (fa && fa->__actions) {
- struct fdop *op;
- int fd;
- for (op = fa->__actions; op->next; op = op->next);
- for (; op; op = op->prev) {
- /* It's possible that a file operation would clobber
- * the pipe fd used for synchronizing with the
- * parent. To avoid that, we dup the pipe onto
- * an unoccupied fd. */
- if (op->fd == p) {
- ret = __syscall(SYS_dup, p);
- if (ret < 0) goto fail;
- __syscall(SYS_close, p);
- p = ret;
- }
- switch(op->cmd) {
- case FDOP_CLOSE:
- __syscall(SYS_close, op->fd);
- break;
- case FDOP_DUP2:
- fd = op->srcfd;
- if (fd == p) {
- ret = -EBADF;
- goto fail;
- }
- if (fd != op->fd) {
- if ((ret=__sys_dup2(fd, op->fd))<0)
- goto fail;
- } else {
- ret = __syscall(SYS_fcntl, fd, F_GETFD);
- ret = __syscall(SYS_fcntl, fd, F_SETFD,
- ret & ~FD_CLOEXEC);
- if (ret<0)
- goto fail;
- }
- break;
- case FDOP_OPEN:
- fd = __sys_open(op->path, op->oflag, op->mode);
- if ((ret=fd) < 0) goto fail;
- if (fd != op->fd) {
- if ((ret=__sys_dup2(fd, op->fd))<0)
- goto fail;
- __syscall(SYS_close, fd);
- }
- break;
- case FDOP_CHDIR:
- ret = __syscall(SYS_chdir, op->path);
- if (ret<0) goto fail;
- break;
- case FDOP_FCHDIR:
- ret = __syscall(SYS_fchdir, op->fd);
- if (ret<0) goto fail;
- break;
- }
- }
- }
-
- /* Close-on-exec flag may have been lost if we moved the pipe
- * to a different fd. We don't use F_DUPFD_CLOEXEC above because
- * it would fail on older kernels and atomicity is not needed --
- * in this process there are no threads or signal handlers. */
- __syscall(SYS_fcntl, p, F_SETFD, FD_CLOEXEC);
-
- pthread_sigmask(SIG_SETMASK, (attr->__flags & POSIX_SPAWN_SETSIGMASK)
- ? &attr->__mask : &args->oldmask, 0);
-
- int (*exec)(const char *, char *const *, char *const *) =
- attr->__fn ? (int (*)())attr->__fn : execve;
-
- exec(args->path, args->argv, args->envp);
- ret = -errno;
-
-fail:
- /* Since sizeof errno < PIPE_BUF, the write is atomic. */
- ret = -ret;
- if (ret) while (__syscall(SYS_write, p, &ret, sizeof ret) < 0);
- _exit(127);
-}
-
-
-int posix_spawn(pid_t *restrict res, const char *restrict path,
- const posix_spawn_file_actions_t *fa,
- const posix_spawnattr_t *restrict attr,
- char *const argv[restrict], char *const envp[restrict])
-{
- pid_t pid;
- char stack[1024+PATH_MAX];
- int ec=0, cs;
- struct args args;
-
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
-
- args.path = path;
- args.fa = fa;
- args.attr = attr ? attr : &(const posix_spawnattr_t){0};
- args.argv = argv;
- args.envp = envp;
- pthread_sigmask(SIG_BLOCK, SIGALL_SET, &args.oldmask);
-
- /* The lock guards both against seeing a SIGABRT disposition change
- * by abort and against leaking the pipe fd to fork-without-exec. */
- LOCK(__abort_lock);
-
- if (pipe2(args.p, O_CLOEXEC)) {
- UNLOCK(__abort_lock);
- ec = errno;
- goto fail;
- }
-
- pid = __clone(child, stack+sizeof stack,
- CLONE_VM|CLONE_VFORK|SIGCHLD, &args);
- close(args.p[1]);
- UNLOCK(__abort_lock);
-
- if (pid > 0) {
- if (read(args.p[0], &ec, sizeof ec) != sizeof ec) ec = 0;
- else waitpid(pid, &(int){0}, 0);
- } else {
- ec = -pid;
- }
-
- close(args.p[0]);
-
- if (!ec && res) *res = pid;
-
-fail:
- pthread_sigmask(SIG_SETMASK, &args.oldmask, 0);
- pthread_setcancelstate(cs, 0);
-
- return ec;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_addchdir.c
@@ -1,18 +0,0 @@
-#include <spawn.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include "fdop.h"
-
-int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *restrict fa, const char *restrict path)
-{
- struct fdop *op = malloc(sizeof *op + strlen(path) + 1);
- if (!op) return ENOMEM;
- op->cmd = FDOP_CHDIR;
- op->fd = -1;
- strcpy(op->path, path);
- if ((op->next = fa->__actions)) op->next->prev = op;
- op->prev = 0;
- fa->__actions = op;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_addclose.c
@@ -1,17 +0,0 @@
-#include <spawn.h>
-#include <stdlib.h>
-#include <errno.h>
-#include "fdop.h"
-
-int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *fa, int fd)
-{
- if (fd < 0) return EBADF;
- struct fdop *op = malloc(sizeof *op);
- if (!op) return ENOMEM;
- op->cmd = FDOP_CLOSE;
- op->fd = fd;
- if ((op->next = fa->__actions)) op->next->prev = op;
- op->prev = 0;
- fa->__actions = op;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_adddup2.c
@@ -1,18 +0,0 @@
-#include <spawn.h>
-#include <stdlib.h>
-#include <errno.h>
-#include "fdop.h"
-
-int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *fa, int srcfd, int fd)
-{
- if (srcfd < 0 || fd < 0) return EBADF;
- struct fdop *op = malloc(sizeof *op);
- if (!op) return ENOMEM;
- op->cmd = FDOP_DUP2;
- op->srcfd = srcfd;
- op->fd = fd;
- if ((op->next = fa->__actions)) op->next->prev = op;
- op->prev = 0;
- fa->__actions = op;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_addfchdir.c
@@ -1,18 +0,0 @@
-#include <spawn.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include "fdop.h"
-
-int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *fa, int fd)
-{
- if (fd < 0) return EBADF;
- struct fdop *op = malloc(sizeof *op);
- if (!op) return ENOMEM;
- op->cmd = FDOP_FCHDIR;
- op->fd = fd;
- if ((op->next = fa->__actions)) op->next->prev = op;
- op->prev = 0;
- fa->__actions = op;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_addopen.c
@@ -1,21 +0,0 @@
-#include <spawn.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include "fdop.h"
-
-int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *restrict fa, int fd, const char *restrict path, int flags, mode_t mode)
-{
- if (fd < 0) return EBADF;
- struct fdop *op = malloc(sizeof *op + strlen(path) + 1);
- if (!op) return ENOMEM;
- op->cmd = FDOP_OPEN;
- op->fd = fd;
- op->oflag = flags;
- op->mode = mode;
- strcpy(op->path, path);
- if ((op->next = fa->__actions)) op->next->prev = op;
- op->prev = 0;
- fa->__actions = op;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_destroy.c
@@ -1,14 +0,0 @@
-#include <spawn.h>
-#include <stdlib.h>
-#include "fdop.h"
-
-int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *fa)
-{
- struct fdop *op = fa->__actions, *next;
- while (op) {
- next = op->next;
- free(op);
- op = next;
- }
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_init.c
@@ -1,7 +0,0 @@
-#include <spawn.h>
-
-int posix_spawn_file_actions_init(posix_spawn_file_actions_t *fa)
-{
- fa->__actions = 0;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_destroy.c
@@ -1,6 +0,0 @@
-#include <spawn.h>
-
-int posix_spawnattr_destroy(posix_spawnattr_t *attr)
-{
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_getflags.c
@@ -1,7 +0,0 @@
-#include <spawn.h>
-
-int posix_spawnattr_getflags(const posix_spawnattr_t *restrict attr, short *restrict flags)
-{
- *flags = attr->__flags;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_getpgroup.c
@@ -1,7 +0,0 @@
-#include <spawn.h>
-
-int posix_spawnattr_getpgroup(const posix_spawnattr_t *restrict attr, pid_t *restrict pgrp)
-{
- *pgrp = attr->__pgrp;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_getsigdefault.c
@@ -1,7 +0,0 @@
-#include <spawn.h>
-
-int posix_spawnattr_getsigdefault(const posix_spawnattr_t *restrict attr, sigset_t *restrict def)
-{
- *def = attr->__def;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_getsigmask.c
@@ -1,7 +0,0 @@
-#include <spawn.h>
-
-int posix_spawnattr_getsigmask(const posix_spawnattr_t *restrict attr, sigset_t *restrict mask)
-{
- *mask = attr->__mask;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_init.c
@@ -1,7 +0,0 @@
-#include <spawn.h>
-
-int posix_spawnattr_init(posix_spawnattr_t *attr)
-{
- *attr = (posix_spawnattr_t){ 0 };
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_sched.c
@@ -1,25 +0,0 @@
-#include <spawn.h>
-#include <sched.h>
-#include <errno.h>
-
-int posix_spawnattr_getschedparam(const posix_spawnattr_t *restrict attr,
- struct sched_param *restrict schedparam)
-{
- return ENOSYS;
-}
-
-int posix_spawnattr_setschedparam(posix_spawnattr_t *restrict attr,
- const struct sched_param *restrict schedparam)
-{
- return ENOSYS;
-}
-
-int posix_spawnattr_getschedpolicy(const posix_spawnattr_t *restrict attr, int *restrict policy)
-{
- return ENOSYS;
-}
-
-int posix_spawnattr_setschedpolicy(posix_spawnattr_t *attr, int policy)
-{
- return ENOSYS;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_setflags.c
@@ -1,18 +0,0 @@
-#include <spawn.h>
-#include <errno.h>
-
-int posix_spawnattr_setflags(posix_spawnattr_t *attr, short flags)
-{
- const unsigned all_flags =
- POSIX_SPAWN_RESETIDS |
- POSIX_SPAWN_SETPGROUP |
- POSIX_SPAWN_SETSIGDEF |
- POSIX_SPAWN_SETSIGMASK |
- POSIX_SPAWN_SETSCHEDPARAM |
- POSIX_SPAWN_SETSCHEDULER |
- POSIX_SPAWN_USEVFORK |
- POSIX_SPAWN_SETSID;
- if (flags & ~all_flags) return EINVAL;
- attr->__flags = flags;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_setpgroup.c
@@ -1,7 +0,0 @@
-#include <spawn.h>
-
-int posix_spawnattr_setpgroup(posix_spawnattr_t *attr, pid_t pgrp)
-{
- attr->__pgrp = pgrp;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_setsigdefault.c
@@ -1,7 +0,0 @@
-#include <spawn.h>
-
-int posix_spawnattr_setsigdefault(posix_spawnattr_t *restrict attr, const sigset_t *restrict def)
-{
- attr->__def = *def;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_setsigmask.c
@@ -1,7 +0,0 @@
-#include <spawn.h>
-
-int posix_spawnattr_setsigmask(posix_spawnattr_t *restrict attr, const sigset_t *restrict mask)
-{
- attr->__mask = *mask;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnp.c
@@ -1,13 +0,0 @@
-#include <spawn.h>
-#include <unistd.h>
-
-int posix_spawnp(pid_t *restrict res, const char *restrict file,
- const posix_spawn_file_actions_t *fa,
- const posix_spawnattr_t *restrict attr,
- char *const argv[restrict], char *const envp[restrict])
-{
- posix_spawnattr_t spawnp_attr = { 0 };
- if (attr) spawnp_attr = *attr;
- spawnp_attr.__fn = (void *)__execvpe;
- return posix_spawn(res, file, fa, &spawnp_attr, argv, envp);
-}
lib/libc/wasi/libc-top-half/musl/src/process/system.c
@@ -1,46 +0,0 @@
-#include <unistd.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <sys/wait.h>
-#include <spawn.h>
-#include <errno.h>
-#include "pthread_impl.h"
-
-extern char **__environ;
-
-int system(const char *cmd)
-{
- pid_t pid;
- sigset_t old, reset;
- struct sigaction sa = { .sa_handler = SIG_IGN }, oldint, oldquit;
- int status = -1, ret;
- posix_spawnattr_t attr;
-
- pthread_testcancel();
-
- if (!cmd) return 1;
-
- sigaction(SIGINT, &sa, &oldint);
- sigaction(SIGQUIT, &sa, &oldquit);
- sigaddset(&sa.sa_mask, SIGCHLD);
- sigprocmask(SIG_BLOCK, &sa.sa_mask, &old);
-
- sigemptyset(&reset);
- if (oldint.sa_handler != SIG_IGN) sigaddset(&reset, SIGINT);
- if (oldquit.sa_handler != SIG_IGN) sigaddset(&reset, SIGQUIT);
- posix_spawnattr_init(&attr);
- posix_spawnattr_setsigmask(&attr, &old);
- posix_spawnattr_setsigdefault(&attr, &reset);
- posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGDEF|POSIX_SPAWN_SETSIGMASK);
- ret = posix_spawn(&pid, "/bin/sh", 0, &attr,
- (char *[]){"sh", "-c", (char *)cmd, 0}, __environ);
- posix_spawnattr_destroy(&attr);
-
- if (!ret) while (waitpid(pid, &status, 0)<0 && errno == EINTR);
- sigaction(SIGINT, &oldint, NULL);
- sigaction(SIGQUIT, &oldquit, NULL);
- sigprocmask(SIG_SETMASK, &old, NULL);
-
- if (ret) errno = ret;
- return status;
-}
lib/libc/wasi/libc-top-half/musl/src/process/vfork.c
@@ -1,14 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include <signal.h>
-#include "syscall.h"
-
-pid_t vfork(void)
-{
- /* vfork syscall cannot be made from C code */
-#ifdef SYS_fork
- return syscall(SYS_fork);
-#else
- return syscall(SYS_clone, SIGCHLD, 0);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/process/wait.c
@@ -1,6 +0,0 @@
-#include <sys/wait.h>
-
-pid_t wait(int *status)
-{
- return waitpid((pid_t)-1, status, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/process/waitid.c
@@ -1,7 +0,0 @@
-#include <sys/wait.h>
-#include "syscall.h"
-
-int waitid(idtype_t type, id_t id, siginfo_t *info, int options)
-{
- return syscall_cp(SYS_waitid, type, id, info, options, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/process/waitpid.c
@@ -1,7 +0,0 @@
-#include <sys/wait.h>
-#include "syscall.h"
-
-pid_t waitpid(pid_t pid, int *status, int options)
-{
- return syscall_cp(SYS_wait4, pid, status, options, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/sched/affinity.c
@@ -1,33 +0,0 @@
-#define _GNU_SOURCE
-#include <sched.h>
-#include <string.h>
-#include "pthread_impl.h"
-#include "syscall.h"
-
-int sched_setaffinity(pid_t tid, size_t size, const cpu_set_t *set)
-{
- return syscall(SYS_sched_setaffinity, tid, size, set);
-}
-
-int pthread_setaffinity_np(pthread_t td, size_t size, const cpu_set_t *set)
-{
- return -__syscall(SYS_sched_setaffinity, td->tid, size, set);
-}
-
-static int do_getaffinity(pid_t tid, size_t size, cpu_set_t *set)
-{
- long ret = __syscall(SYS_sched_getaffinity, tid, size, set);
- if (ret < 0) return ret;
- if (ret < size) memset((char *)set+ret, 0, size-ret);
- return 0;
-}
-
-int sched_getaffinity(pid_t tid, size_t size, cpu_set_t *set)
-{
- return __syscall_ret(do_getaffinity(tid, size, set));
-}
-
-int pthread_getaffinity_np(pthread_t td, size_t size, cpu_set_t *set)
-{
- return -do_getaffinity(td->tid, size, set);
-}
lib/libc/wasi/libc-top-half/musl/src/sched/sched_cpucount.c
@@ -1,11 +0,0 @@
-#define _GNU_SOURCE
-#include <sched.h>
-
-int __sched_cpucount(size_t size, const cpu_set_t *set)
-{
- size_t i, j, cnt=0;
- const unsigned char *p = (const void *)set;
- for (i=0; i<size; i++) for (j=0; j<8; j++)
- if (p[i] & (1<<j)) cnt++;
- return cnt;
-}
lib/libc/wasi/libc-top-half/musl/src/sched/sched_get_priority_max.c
@@ -1,12 +0,0 @@
-#include <sched.h>
-#include "syscall.h"
-
-int sched_get_priority_max(int policy)
-{
- return syscall(SYS_sched_get_priority_max, policy);
-}
-
-int sched_get_priority_min(int policy)
-{
- return syscall(SYS_sched_get_priority_min, policy);
-}
lib/libc/wasi/libc-top-half/musl/src/sched/sched_getcpu.c
@@ -1,42 +0,0 @@
-#define _GNU_SOURCE
-#include <errno.h>
-#include <sched.h>
-#include "syscall.h"
-#include "atomic.h"
-
-#ifdef VDSO_GETCPU_SYM
-
-static void *volatile vdso_func;
-
-typedef long (*getcpu_f)(unsigned *, unsigned *, void *);
-
-static long getcpu_init(unsigned *cpu, unsigned *node, void *unused)
-{
- void *p = __vdsosym(VDSO_GETCPU_VER, VDSO_GETCPU_SYM);
- getcpu_f f = (getcpu_f)p;
- a_cas_p(&vdso_func, (void *)getcpu_init, p);
- return f ? f(cpu, node, unused) : -ENOSYS;
-}
-
-static void *volatile vdso_func = (void *)getcpu_init;
-
-#endif
-
-int sched_getcpu(void)
-{
- int r;
- unsigned cpu;
-
-#ifdef VDSO_GETCPU_SYM
- getcpu_f f = (getcpu_f)vdso_func;
- if (f) {
- r = f(&cpu, 0, 0);
- if (!r) return cpu;
- if (r != -ENOSYS) return __syscall_ret(r);
- }
-#endif
-
- r = __syscall(SYS_getcpu, &cpu, 0, 0);
- if (!r) return cpu;
- return __syscall_ret(r);
-}
lib/libc/wasi/libc-top-half/musl/src/sched/sched_getparam.c
@@ -1,8 +0,0 @@
-#include <sched.h>
-#include <errno.h>
-#include "syscall.h"
-
-int sched_getparam(pid_t pid, struct sched_param *param)
-{
- return __syscall_ret(-ENOSYS);
-}
lib/libc/wasi/libc-top-half/musl/src/sched/sched_getscheduler.c
@@ -1,8 +0,0 @@
-#include <sched.h>
-#include <errno.h>
-#include "syscall.h"
-
-int sched_getscheduler(pid_t pid)
-{
- return __syscall_ret(-ENOSYS);
-}
lib/libc/wasi/libc-top-half/musl/src/sched/sched_rr_get_interval.c
@@ -1,21 +0,0 @@
-#include <sched.h>
-#include "syscall.h"
-
-int sched_rr_get_interval(pid_t pid, struct timespec *ts)
-{
-#ifdef SYS_sched_rr_get_interval_time64
- /* On a 32-bit arch, use the old syscall if it exists. */
- if (SYS_sched_rr_get_interval != SYS_sched_rr_get_interval_time64) {
- long ts32[2];
- int r = __syscall(SYS_sched_rr_get_interval, pid, ts32);
- if (!r) {
- ts->tv_sec = ts32[0];
- ts->tv_nsec = ts32[1];
- }
- return __syscall_ret(r);
- }
-#endif
- /* If reaching this point, it's a 64-bit arch or time64-only
- * 32-bit arch and we can get result directly into timespec. */
- return syscall(SYS_sched_rr_get_interval, pid, ts);
-}
lib/libc/wasi/libc-top-half/musl/src/sched/sched_setparam.c
@@ -1,8 +0,0 @@
-#include <sched.h>
-#include <errno.h>
-#include "syscall.h"
-
-int sched_setparam(pid_t pid, const struct sched_param *param)
-{
- return __syscall_ret(-ENOSYS);
-}
lib/libc/wasi/libc-top-half/musl/src/sched/sched_setscheduler.c
@@ -1,8 +0,0 @@
-#include <sched.h>
-#include <errno.h>
-#include "syscall.h"
-
-int sched_setscheduler(pid_t pid, int sched, const struct sched_param *param)
-{
- return __syscall_ret(-ENOSYS);
-}
lib/libc/wasi/libc-top-half/musl/src/sched/sched_yield.c
@@ -1,7 +0,0 @@
-#include <sched.h>
-#include "syscall.h"
-
-int sched_yield()
-{
- return syscall(SYS_sched_yield);
-}
lib/libc/wasi/libc-top-half/musl/src/select/poll.c
@@ -1,15 +0,0 @@
-#include <poll.h>
-#include <time.h>
-#include <signal.h>
-#include "syscall.h"
-
-int poll(struct pollfd *fds, nfds_t n, int timeout)
-{
-#ifdef SYS_poll
- return syscall_cp(SYS_poll, fds, n, timeout);
-#else
- return syscall_cp(SYS_ppoll, fds, n, timeout>=0 ?
- &((struct timespec){ .tv_sec = timeout/1000,
- .tv_nsec = timeout%1000*1000000 }) : 0, 0, _NSIG/8);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/select/pselect.c
@@ -1,26 +0,0 @@
-#include <sys/select.h>
-#include <signal.h>
-#include <stdint.h>
-#include <errno.h>
-#include "syscall.h"
-
-#define IS32BIT(x) !((x)+0x80000000ULL>>32)
-#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
-
-int pselect(int n, fd_set *restrict rfds, fd_set *restrict wfds, fd_set *restrict efds, const struct timespec *restrict ts, const sigset_t *restrict mask)
-{
- syscall_arg_t data[2] = { (uintptr_t)mask, _NSIG/8 };
- time_t s = ts ? ts->tv_sec : 0;
- long ns = ts ? ts->tv_nsec : 0;
-#ifdef SYS_pselect6_time64
- int r = -ENOSYS;
- if (SYS_pselect6 == SYS_pselect6_time64 || !IS32BIT(s))
- r = __syscall_cp(SYS_pselect6_time64, n, rfds, wfds, efds,
- ts ? ((long long[]){s, ns}) : 0, data);
- if (SYS_pselect6 == SYS_pselect6_time64 || r!=-ENOSYS)
- return __syscall_ret(r);
- s = CLAMP(s);
-#endif
- return syscall_cp(SYS_pselect6, n, rfds, wfds, efds,
- ts ? ((long[]){s, ns}) : 0, data);
-}
lib/libc/wasi/libc-top-half/musl/src/select/select.c
@@ -1,44 +0,0 @@
-#include <sys/select.h>
-#include <signal.h>
-#include <stdint.h>
-#include <errno.h>
-#include "syscall.h"
-
-#define IS32BIT(x) !((x)+0x80000000ULL>>32)
-#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
-
-int select(int n, fd_set *restrict rfds, fd_set *restrict wfds, fd_set *restrict efds, struct timeval *restrict tv)
-{
- time_t s = tv ? tv->tv_sec : 0;
- suseconds_t us = tv ? tv->tv_usec : 0;
- long ns;
- const time_t max_time = (1ULL<<8*sizeof(time_t)-1)-1;
-
- if (s<0 || us<0) return __syscall_ret(-EINVAL);
- if (us/1000000 > max_time - s) {
- s = max_time;
- us = 999999;
- ns = 999999999;
- } else {
- s += us/1000000;
- us %= 1000000;
- ns = us*1000;
- }
-
-#ifdef SYS_pselect6_time64
- int r = -ENOSYS;
- if (SYS_pselect6 == SYS_pselect6_time64 || !IS32BIT(s))
- r = __syscall_cp(SYS_pselect6_time64, n, rfds, wfds, efds,
- tv ? ((long long[]){s, ns}) : 0,
- ((syscall_arg_t[]){ 0, _NSIG/8 }));
- if (SYS_pselect6 == SYS_pselect6_time64 || r!=-ENOSYS)
- return __syscall_ret(r);
-#endif
-#ifdef SYS_select
- return syscall_cp(SYS_select, n, rfds, wfds, efds,
- tv ? ((long[]){s, us}) : 0);
-#else
- return syscall_cp(SYS_pselect6, n, rfds, wfds, efds,
- tv ? ((long[]){s, ns}) : 0, ((syscall_arg_t[]){ 0, _NSIG/8 }));
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/setjmp/aarch64/longjmp.s
@@ -1,23 +0,0 @@
-.global _longjmp
-.global longjmp
-.type _longjmp,%function
-.type longjmp,%function
-_longjmp:
-longjmp:
- // IHI0055B_aapcs64.pdf 5.1.1, 5.1.2 callee saved registers
- ldp x19, x20, [x0,#0]
- ldp x21, x22, [x0,#16]
- ldp x23, x24, [x0,#32]
- ldp x25, x26, [x0,#48]
- ldp x27, x28, [x0,#64]
- ldp x29, x30, [x0,#80]
- ldr x2, [x0,#104]
- mov sp, x2
- ldp d8 , d9, [x0,#112]
- ldp d10, d11, [x0,#128]
- ldp d12, d13, [x0,#144]
- ldp d14, d15, [x0,#160]
-
- cmp w1, 0
- csinc w0, w1, wzr, ne
- br x30
lib/libc/wasi/libc-top-half/musl/src/setjmp/aarch64/setjmp.s
@@ -1,24 +0,0 @@
-.global __setjmp
-.global _setjmp
-.global setjmp
-.type __setjmp,@function
-.type _setjmp,@function
-.type setjmp,@function
-__setjmp:
-_setjmp:
-setjmp:
- // IHI0055B_aapcs64.pdf 5.1.1, 5.1.2 callee saved registers
- stp x19, x20, [x0,#0]
- stp x21, x22, [x0,#16]
- stp x23, x24, [x0,#32]
- stp x25, x26, [x0,#48]
- stp x27, x28, [x0,#64]
- stp x29, x30, [x0,#80]
- mov x2, sp
- str x2, [x0,#104]
- stp d8, d9, [x0,#112]
- stp d10, d11, [x0,#128]
- stp d12, d13, [x0,#144]
- stp d14, d15, [x0,#160]
- mov x0, #0
- ret
lib/libc/wasi/libc-top-half/musl/src/setjmp/i386/longjmp.s
@@ -1,16 +0,0 @@
-.global _longjmp
-.global longjmp
-.type _longjmp,@function
-.type longjmp,@function
-_longjmp:
-longjmp:
- mov 4(%esp),%edx
- mov 8(%esp),%eax
- cmp $1,%eax
- adc $0, %al
- mov (%edx),%ebx
- mov 4(%edx),%esi
- mov 8(%edx),%edi
- mov 12(%edx),%ebp
- mov 16(%edx),%esp
- jmp *20(%edx)
lib/libc/wasi/libc-top-half/musl/src/setjmp/i386/setjmp.s
@@ -1,23 +0,0 @@
-.global ___setjmp
-.hidden ___setjmp
-.global __setjmp
-.global _setjmp
-.global setjmp
-.type __setjmp,@function
-.type _setjmp,@function
-.type setjmp,@function
-___setjmp:
-__setjmp:
-_setjmp:
-setjmp:
- mov 4(%esp), %eax
- mov %ebx, (%eax)
- mov %esi, 4(%eax)
- mov %edi, 8(%eax)
- mov %ebp, 12(%eax)
- lea 4(%esp), %ecx
- mov %ecx, 16(%eax)
- mov (%esp), %ecx
- mov %ecx, 20(%eax)
- xor %eax, %eax
- ret
lib/libc/wasi/libc-top-half/musl/src/setjmp/m68k/longjmp.s
@@ -1,14 +0,0 @@
-.global _longjmp
-.global longjmp
-.type _longjmp,@function
-.type longjmp,@function
-_longjmp:
-longjmp:
- movea.l 4(%sp),%a0
- move.l 8(%sp),%d0
- bne 1f
- move.l #1,%d0
-1: movem.l (%a0),%d2-%d7/%a2-%a7
- fmovem.x 52(%a0),%fp2-%fp7
- move.l 48(%a0),(%sp)
- rts
lib/libc/wasi/libc-top-half/musl/src/setjmp/m68k/setjmp.s
@@ -1,18 +0,0 @@
-.global ___setjmp
-.hidden ___setjmp
-.global __setjmp
-.global _setjmp
-.global setjmp
-.type __setjmp,@function
-.type _setjmp,@function
-.type setjmp,@function
-___setjmp:
-__setjmp:
-_setjmp:
-setjmp:
- movea.l 4(%sp),%a0
- movem.l %d2-%d7/%a2-%a7,(%a0)
- move.l (%sp),48(%a0)
- fmovem.x %fp2-%fp7,52(%a0)
- clr.l %d0
- rts
lib/libc/wasi/libc-top-half/musl/src/setjmp/microblaze/longjmp.s
@@ -1,29 +0,0 @@
-.global _longjmp
-.global longjmp
-.type _longjmp,@function
-.type longjmp,@function
-_longjmp:
-longjmp:
- addi r3, r6, 0
- bnei r3, 1f
- addi r3, r3, 1
-1: lwi r1, r5, 0
- lwi r15, r5, 4
- lwi r2, r5, 8
- lwi r13, r5, 12
- lwi r18, r5, 16
- lwi r19, r5, 20
- lwi r20, r5, 24
- lwi r21, r5, 28
- lwi r22, r5, 32
- lwi r23, r5, 36
- lwi r24, r5, 40
- lwi r25, r5, 44
- lwi r26, r5, 48
- lwi r27, r5, 52
- lwi r28, r5, 56
- lwi r29, r5, 60
- lwi r30, r5, 64
- lwi r31, r5, 68
- rtsd r15, 8
- nop
lib/libc/wasi/libc-top-half/musl/src/setjmp/microblaze/setjmp.s
@@ -1,32 +0,0 @@
-.global ___setjmp
-.hidden ___setjmp
-.global __setjmp
-.global _setjmp
-.global setjmp
-.type __setjmp,@function
-.type _setjmp,@function
-.type setjmp,@function
-___setjmp:
-__setjmp:
-_setjmp:
-setjmp:
- swi r1, r5, 0
- swi r15, r5, 4
- swi r2, r5, 8
- swi r13, r5, 12
- swi r18, r5, 16
- swi r19, r5, 20
- swi r20, r5, 24
- swi r21, r5, 28
- swi r22, r5, 32
- swi r23, r5, 36
- swi r24, r5, 40
- swi r25, r5, 44
- swi r26, r5, 48
- swi r27, r5, 52
- swi r28, r5, 56
- swi r29, r5, 60
- swi r30, r5, 64
- swi r31, r5, 68
- rtsd r15, 8
- ori r3, r0, 0
lib/libc/wasi/libc-top-half/musl/src/setjmp/or1k/longjmp.s
@@ -1,25 +0,0 @@
-.global _longjmp
-.global longjmp
-.type _longjmp,@function
-.type longjmp,@function
-_longjmp:
-longjmp:
- l.sfeqi r4, 0
- l.bnf 1f
- l.addi r11, r4,0
- l.ori r11, r0, 1
-1: l.lwz r1, 0(r3)
- l.lwz r2, 4(r3)
- l.lwz r9, 8(r3)
- l.lwz r10, 12(r3)
- l.lwz r14, 16(r3)
- l.lwz r16, 20(r3)
- l.lwz r18, 24(r3)
- l.lwz r20, 28(r3)
- l.lwz r22, 32(r3)
- l.lwz r24, 36(r3)
- l.lwz r26, 40(r3)
- l.lwz r28, 44(r3)
- l.lwz r30, 48(r3)
- l.jr r9
- l.nop
lib/libc/wasi/libc-top-half/musl/src/setjmp/or1k/setjmp.s
@@ -1,27 +0,0 @@
-.global ___setjmp
-.hidden ___setjmp
-.global __setjmp
-.global _setjmp
-.global setjmp
-.type __setjmp,@function
-.type _setjmp,@function
-.type setjmp,@function
-___setjmp:
-__setjmp:
-_setjmp:
-setjmp:
- l.sw 0(r3), r1
- l.sw 4(r3), r2
- l.sw 8(r3), r9
- l.sw 12(r3), r10
- l.sw 16(r3), r14
- l.sw 20(r3), r16
- l.sw 24(r3), r18
- l.sw 28(r3), r20
- l.sw 32(r3), r22
- l.sw 36(r3), r24
- l.sw 40(r3), r26
- l.sw 44(r3), r28
- l.sw 48(r3), r30
- l.jr r9
- l.ori r11,r0,0
lib/libc/wasi/libc-top-half/musl/src/setjmp/powerpc64/longjmp.s
@@ -1,81 +0,0 @@
- .global _longjmp
- .global longjmp
- .type _longjmp,@function
- .type longjmp,@function
-_longjmp:
-longjmp:
- # 0) move old return address into the link register
- ld 0, 0*8(3)
- mtlr 0
- # 1) restore cr
- ld 0, 1*8(3)
- mtcr 0
- # 2) restore SP
- ld 1, 2*8(3)
- # 3) restore TOC into both r2 and the caller's stack.
- # Which location is required depends on whether setjmp was called
- # locally or non-locally, but it's always safe to restore to both.
- ld 2, 3*8(3)
- std 2, 24(1)
- # 4) restore r14-r31
- ld 14, 4*8(3)
- ld 15, 5*8(3)
- ld 16, 6*8(3)
- ld 17, 7*8(3)
- ld 18, 8*8(3)
- ld 19, 9*8(3)
- ld 20, 10*8(3)
- ld 21, 11*8(3)
- ld 22, 12*8(3)
- ld 23, 13*8(3)
- ld 24, 14*8(3)
- ld 25, 15*8(3)
- ld 26, 16*8(3)
- ld 27, 17*8(3)
- ld 28, 18*8(3)
- ld 29, 19*8(3)
- ld 30, 20*8(3)
- ld 31, 21*8(3)
- # 5) restore floating point registers f14-f31
- lfd 14, 22*8(3)
- lfd 15, 23*8(3)
- lfd 16, 24*8(3)
- lfd 17, 25*8(3)
- lfd 18, 26*8(3)
- lfd 19, 27*8(3)
- lfd 20, 28*8(3)
- lfd 21, 29*8(3)
- lfd 22, 30*8(3)
- lfd 23, 31*8(3)
- lfd 24, 32*8(3)
- lfd 25, 33*8(3)
- lfd 26, 34*8(3)
- lfd 27, 35*8(3)
- lfd 28, 36*8(3)
- lfd 29, 37*8(3)
- lfd 30, 38*8(3)
- lfd 31, 39*8(3)
-
- # 6) restore vector registers v20-v31
- addi 3, 3, 40*8
- lvx 20, 0, 3 ; addi 3, 3, 16
- lvx 21, 0, 3 ; addi 3, 3, 16
- lvx 22, 0, 3 ; addi 3, 3, 16
- lvx 23, 0, 3 ; addi 3, 3, 16
- lvx 24, 0, 3 ; addi 3, 3, 16
- lvx 25, 0, 3 ; addi 3, 3, 16
- lvx 26, 0, 3 ; addi 3, 3, 16
- lvx 27, 0, 3 ; addi 3, 3, 16
- lvx 28, 0, 3 ; addi 3, 3, 16
- lvx 29, 0, 3 ; addi 3, 3, 16
- lvx 30, 0, 3 ; addi 3, 3, 16
- lvx 31, 0, 3
-
- # 7) return r4 ? r4 : 1
- mr 3, 4
- cmpwi cr7, 4, 0
- bne cr7, 1f
- li 3, 1
-1:
- blr
-
lib/libc/wasi/libc-top-half/musl/src/setjmp/powerpc64/setjmp.s
@@ -1,89 +0,0 @@
- .global __setjmp
- .global _setjmp
- .global setjmp
- .type __setjmp,@function
- .type _setjmp,@function
- .type setjmp,@function
-__setjmp:
-_setjmp:
-setjmp:
- ld 5, 24(1) # load from the TOC slot in the caller's stack frame
- b __setjmp_toc
-
- .localentry __setjmp,.-__setjmp
- .localentry _setjmp,.-_setjmp
- .localentry setjmp,.-setjmp
- mr 5, 2
-
- .global __setjmp_toc
- .hidden __setjmp_toc
- # same as normal setjmp, except TOC pointer to save is provided in r5.
- # r4 would normally be the 2nd parameter, but we're using r5 to simplify calling from sigsetjmp.
- # solves the problem of knowing whether to save the TOC pointer from r2 or the caller's stack frame.
-__setjmp_toc:
- # 0) store IP into 0, then into the jmpbuf pointed to by r3 (first arg)
- mflr 0
- std 0, 0*8(3)
- # 1) store cr
- mfcr 0
- std 0, 1*8(3)
- # 2) store SP and TOC
- std 1, 2*8(3)
- std 5, 3*8(3)
- # 3) store r14-31
- std 14, 4*8(3)
- std 15, 5*8(3)
- std 16, 6*8(3)
- std 17, 7*8(3)
- std 18, 8*8(3)
- std 19, 9*8(3)
- std 20, 10*8(3)
- std 21, 11*8(3)
- std 22, 12*8(3)
- std 23, 13*8(3)
- std 24, 14*8(3)
- std 25, 15*8(3)
- std 26, 16*8(3)
- std 27, 17*8(3)
- std 28, 18*8(3)
- std 29, 19*8(3)
- std 30, 20*8(3)
- std 31, 21*8(3)
- # 4) store floating point registers f14-f31
- stfd 14, 22*8(3)
- stfd 15, 23*8(3)
- stfd 16, 24*8(3)
- stfd 17, 25*8(3)
- stfd 18, 26*8(3)
- stfd 19, 27*8(3)
- stfd 20, 28*8(3)
- stfd 21, 29*8(3)
- stfd 22, 30*8(3)
- stfd 23, 31*8(3)
- stfd 24, 32*8(3)
- stfd 25, 33*8(3)
- stfd 26, 34*8(3)
- stfd 27, 35*8(3)
- stfd 28, 36*8(3)
- stfd 29, 37*8(3)
- stfd 30, 38*8(3)
- stfd 31, 39*8(3)
-
- # 5) store vector registers v20-v31
- addi 3, 3, 40*8
- stvx 20, 0, 3 ; addi 3, 3, 16
- stvx 21, 0, 3 ; addi 3, 3, 16
- stvx 22, 0, 3 ; addi 3, 3, 16
- stvx 23, 0, 3 ; addi 3, 3, 16
- stvx 24, 0, 3 ; addi 3, 3, 16
- stvx 25, 0, 3 ; addi 3, 3, 16
- stvx 26, 0, 3 ; addi 3, 3, 16
- stvx 27, 0, 3 ; addi 3, 3, 16
- stvx 28, 0, 3 ; addi 3, 3, 16
- stvx 29, 0, 3 ; addi 3, 3, 16
- stvx 30, 0, 3 ; addi 3, 3, 16
- stvx 31, 0, 3
-
- # 6) return 0
- li 3, 0
- blr
lib/libc/wasi/libc-top-half/musl/src/setjmp/s390x/longjmp.s
@@ -1,23 +0,0 @@
- .global _longjmp
- .global longjmp
- .type _longjmp,@function
- .type longjmp,@function
-_longjmp:
-longjmp:
-
-1:
- lmg %r6, %r15, 0(%r2)
-
- ld %f8, 10*8(%r2)
- ld %f9, 11*8(%r2)
- ld %f10, 12*8(%r2)
- ld %f11, 13*8(%r2)
- ld %f12, 14*8(%r2)
- ld %f13, 15*8(%r2)
- ld %f14, 16*8(%r2)
- ld %f15, 17*8(%r2)
-
- ltgr %r2, %r3
- bnzr %r14
- lhi %r2, 1
- br %r14
lib/libc/wasi/libc-top-half/musl/src/setjmp/s390x/setjmp.s
@@ -1,25 +0,0 @@
- .global ___setjmp
- .hidden ___setjmp
- .global __setjmp
- .global _setjmp
- .global setjmp
- .type __setjmp,@function
- .type _setjmp,@function
- .type setjmp,@function
-___setjmp:
-__setjmp:
-_setjmp:
-setjmp:
- stmg %r6, %r15, 0(%r2)
-
- std %f8, 10*8(%r2)
- std %f9, 11*8(%r2)
- std %f10, 12*8(%r2)
- std %f11, 13*8(%r2)
- std %f12, 14*8(%r2)
- std %f13, 15*8(%r2)
- std %f14, 16*8(%r2)
- std %f15, 17*8(%r2)
-
- lghi %r2, 0
- br %r14
lib/libc/wasi/libc-top-half/musl/src/setjmp/x32/longjmp.s
@@ -1,18 +0,0 @@
-/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
-.global _longjmp
-.global longjmp
-.type _longjmp,@function
-.type longjmp,@function
-_longjmp:
-longjmp:
- xor %eax,%eax
- cmp $1,%esi /* CF = val ? 0 : 1 */
- adc %esi,%eax /* eax = val + !val */
- mov (%rdi),%rbx /* rdi is the jmp_buf, restore regs from it */
- mov 8(%rdi),%rbp
- mov 16(%rdi),%r12
- mov 24(%rdi),%r13
- mov 32(%rdi),%r14
- mov 40(%rdi),%r15
- mov 48(%rdi),%rsp
- jmp *56(%rdi) /* goto saved address without altering rsp */
lib/libc/wasi/libc-top-half/musl/src/setjmp/x32/setjmp.s
@@ -1,22 +0,0 @@
-/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
-.global __setjmp
-.global _setjmp
-.global setjmp
-.type __setjmp,@function
-.type _setjmp,@function
-.type setjmp,@function
-__setjmp:
-_setjmp:
-setjmp:
- mov %rbx,(%rdi) /* rdi is jmp_buf, move registers onto it */
- mov %rbp,8(%rdi)
- mov %r12,16(%rdi)
- mov %r13,24(%rdi)
- mov %r14,32(%rdi)
- mov %r15,40(%rdi)
- lea 8(%rsp),%rdx /* this is our rsp WITHOUT current ret addr */
- mov %rdx,48(%rdi)
- mov (%rsp),%rdx /* save return addr ptr for new rip */
- mov %rdx,56(%rdi)
- xor %eax,%eax /* always return 0 */
- ret
lib/libc/wasi/libc-top-half/musl/src/setjmp/x86_64/longjmp.s
@@ -1,18 +0,0 @@
-/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
-.global _longjmp
-.global longjmp
-.type _longjmp,@function
-.type longjmp,@function
-_longjmp:
-longjmp:
- xor %eax,%eax
- cmp $1,%esi /* CF = val ? 0 : 1 */
- adc %esi,%eax /* eax = val + !val */
- mov (%rdi),%rbx /* rdi is the jmp_buf, restore regs from it */
- mov 8(%rdi),%rbp
- mov 16(%rdi),%r12
- mov 24(%rdi),%r13
- mov 32(%rdi),%r14
- mov 40(%rdi),%r15
- mov 48(%rdi),%rsp
- jmp *56(%rdi) /* goto saved address without altering rsp */
lib/libc/wasi/libc-top-half/musl/src/setjmp/x86_64/setjmp.s
@@ -1,22 +0,0 @@
-/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
-.global __setjmp
-.global _setjmp
-.global setjmp
-.type __setjmp,@function
-.type _setjmp,@function
-.type setjmp,@function
-__setjmp:
-_setjmp:
-setjmp:
- mov %rbx,(%rdi) /* rdi is jmp_buf, move registers onto it */
- mov %rbp,8(%rdi)
- mov %r12,16(%rdi)
- mov %r13,24(%rdi)
- mov %r14,32(%rdi)
- mov %r15,40(%rdi)
- lea 8(%rsp),%rdx /* this is our rsp WITHOUT current ret addr */
- mov %rdx,48(%rdi)
- mov (%rsp),%rdx /* save return addr ptr for new rip */
- mov %rdx,56(%rdi)
- xor %eax,%eax /* always return 0 */
- ret
lib/libc/wasi/libc-top-half/musl/src/setjmp/longjmp.c
lib/libc/wasi/libc-top-half/musl/src/setjmp/setjmp.c
lib/libc/wasi/libc-top-half/musl/src/signal/aarch64/restore.s
@@ -1,10 +0,0 @@
-.global __restore
-.hidden __restore
-.type __restore,%function
-__restore:
-.global __restore_rt
-.hidden __restore_rt
-.type __restore_rt,%function
-__restore_rt:
- mov x8,#139 // SYS_rt_sigreturn
- svc 0
lib/libc/wasi/libc-top-half/musl/src/signal/aarch64/sigsetjmp.s
@@ -1,21 +0,0 @@
-.global sigsetjmp
-.global __sigsetjmp
-.type sigsetjmp,%function
-.type __sigsetjmp,%function
-sigsetjmp:
-__sigsetjmp:
- cbz x1,setjmp
-
- str x30,[x0,#176]
- str x19,[x0,#176+8+8]
- mov x19,x0
-
- bl setjmp
-
- mov w1,w0
- mov x0,x19
- ldr x30,[x0,#176]
- ldr x19,[x0,#176+8+8]
-
-.hidden __sigsetjmp_tail
- b __sigsetjmp_tail
lib/libc/wasi/libc-top-half/musl/src/signal/arm/restore.s
@@ -1,15 +0,0 @@
-.syntax unified
-
-.global __restore
-.hidden __restore
-.type __restore,%function
-__restore:
- mov r7,#119
- swi 0x0
-
-.global __restore_rt
-.hidden __restore_rt
-.type __restore_rt,%function
-__restore_rt:
- mov r7,#173
- swi 0x0
lib/libc/wasi/libc-top-half/musl/src/signal/arm/sigsetjmp.s
@@ -1,24 +0,0 @@
-.syntax unified
-.global sigsetjmp
-.global __sigsetjmp
-.type sigsetjmp,%function
-.type __sigsetjmp,%function
-sigsetjmp:
-__sigsetjmp:
- tst r1,r1
- bne 1f
- b setjmp
-
-1: str lr,[r0,#256]
- str r4,[r0,#260+8]
- mov r4,r0
-
- bl setjmp
-
- mov r1,r0
- mov r0,r4
- ldr lr,[r0,#256]
- ldr r4,[r0,#260+8]
-
-.hidden __sigsetjmp_tail
- b __sigsetjmp_tail
lib/libc/wasi/libc-top-half/musl/src/signal/i386/restore.s
@@ -1,14 +0,0 @@
-.global __restore
-.hidden __restore
-.type __restore,@function
-__restore:
- popl %eax
- movl $119, %eax
- int $0x80
-
-.global __restore_rt
-.hidden __restore_rt
-.type __restore_rt,@function
-__restore_rt:
- movl $173, %eax
- int $0x80
lib/libc/wasi/libc-top-half/musl/src/signal/i386/sigsetjmp.s
@@ -1,26 +0,0 @@
-.global sigsetjmp
-.global __sigsetjmp
-.type sigsetjmp,@function
-.type __sigsetjmp,@function
-sigsetjmp:
-__sigsetjmp:
- mov 8(%esp),%ecx
- jecxz 1f
-
- mov 4(%esp),%eax
- popl 24(%eax)
- mov %ebx,28+8(%eax)
- mov %eax,%ebx
-
-.hidden ___setjmp
- call ___setjmp
-
- pushl 24(%ebx)
- mov %ebx,4(%esp)
- mov %eax,8(%esp)
- mov 28+8(%ebx),%ebx
-
-.hidden __sigsetjmp_tail
- jmp __sigsetjmp_tail
-
-1: jmp ___setjmp
lib/libc/wasi/libc-top-half/musl/src/signal/m68k/sigsetjmp.s
@@ -1,29 +0,0 @@
-.global sigsetjmp
-.global __sigsetjmp
-.type sigsetjmp,@function
-.type __sigsetjmp,@function
-sigsetjmp:
-__sigsetjmp:
- move.l 8(%sp),%d0
- beq 1f
-
- movea.l 4(%sp),%a1
- move.l (%sp)+,156(%a1)
- move.l %a2,156+4+8(%a1)
- movea.l %a1,%a2
-
-.hidden ___setjmp
- lea ___setjmp-.-8,%a1
- jsr (%pc,%a1)
-
- move.l 156(%a2),-(%sp)
- move.l %a2,4(%sp)
- move.l %d0,8(%sp)
- movea.l 156+4+8(%a2),%a2
-
-.hidden __sigsetjmp_tail
- lea __sigsetjmp_tail-.-8,%a1
- jmp (%pc,%a1)
-
-1: lea ___setjmp-.-8,%a1
- jmp (%pc,%a1)
lib/libc/wasi/libc-top-half/musl/src/signal/microblaze/restore.s
@@ -1,13 +0,0 @@
-.global __restore
-.hidden __restore
-.type __restore,@function
-__restore:
- ori r12, r0, 119
- brki r14, 0x8
-
-.global __restore_rt
-.hidden __restore_rt
-.type __restore_rt,@function
-__restore_rt:
- ori r12, r0, 173
- brki r14, 0x8
lib/libc/wasi/libc-top-half/musl/src/signal/microblaze/sigsetjmp.s
@@ -1,22 +0,0 @@
-.global sigsetjmp
-.global __sigsetjmp
-.type sigsetjmp,@function
-.type __sigsetjmp,@function
-sigsetjmp:
-__sigsetjmp:
-.hidden ___setjmp
- beqi r6, ___setjmp
-
- swi r15,r5,72
- swi r19,r5,72+4+8
-
- brlid r15,___setjmp
- ori r19,r5,0
-
- ori r6,r3,0
- ori r5,r19,0
- lwi r15,r5,72
- lwi r19,r5,72+4+8
-
-.hidden __sigsetjmp_tail
- bri __sigsetjmp_tail
lib/libc/wasi/libc-top-half/musl/src/signal/mips/restore.s
@@ -1,15 +0,0 @@
-.set noreorder
-
-.global __restore_rt
-.hidden __restore_rt
-.type __restore_rt,@function
-__restore_rt:
- li $2, 4193
- syscall
-
-.global __restore
-.hidden __restore
-.type __restore,@function
-__restore:
- li $2, 4119
- syscall
lib/libc/wasi/libc-top-half/musl/src/signal/mips/sigsetjmp.s
@@ -1,33 +0,0 @@
-.set noreorder
-
-.global sigsetjmp
-.global __sigsetjmp
-.type sigsetjmp,@function
-.type __sigsetjmp,@function
-sigsetjmp:
-__sigsetjmp:
- lui $gp, %hi(_gp_disp)
- addiu $gp, %lo(_gp_disp)
- beq $5, $0, 1f
- addu $gp, $gp, $25
-
- sw $ra, 104($4)
- sw $16, 104+4+16($4)
-
- lw $25, %call16(setjmp)($gp)
- jalr $25
- move $16, $4
-
- move $5,$2
- move $4,$16
- lw $ra, 104($4)
- lw $16, 104+4+16($4)
-
-.hidden __sigsetjmp_tail
- lw $25, %call16(__sigsetjmp_tail)($gp)
- jr $25
- nop
-
-1: lw $25, %call16(setjmp)($gp)
- jr $25
- nop
lib/libc/wasi/libc-top-half/musl/src/signal/mips64/restore.s
@@ -1,11 +0,0 @@
-.set noreorder
-.global __restore_rt
-.global __restore
-.hidden __restore_rt
-.hidden __restore
-.type __restore_rt,@function
-.type __restore,@function
-__restore_rt:
-__restore:
- li $2,5211
- syscall
lib/libc/wasi/libc-top-half/musl/src/signal/mips64/sigsetjmp.s
@@ -1,38 +0,0 @@
-.set noreorder
-.global sigsetjmp
-.global __sigsetjmp
-.type sigsetjmp,@function
-.type __sigsetjmp,@function
-sigsetjmp:
-__sigsetjmp:
- lui $3, %hi(%neg(%gp_rel(sigsetjmp)))
- daddiu $3, $3, %lo(%neg(%gp_rel(sigsetjmp)))
-
- # comparing save mask with 0, if equals to 0 then
- # sigsetjmp is equal to setjmp.
- beq $5, $0, 1f
- daddu $3, $3, $25
- sd $ra, 160($4)
- sd $16, 168($4)
-
- # save base of got so that we can use it later
- # once we return from 'longjmp'
- sd $3, 176($4)
- ld $25, %got_disp(setjmp)($3)
- jalr $25
- move $16, $4
-
- move $5, $2 # Return from 'setjmp' or 'longjmp'
- move $4, $16 # Restore the pointer-to-sigjmp_buf
- ld $ra, 160($4) # Restore ra of sigsetjmp
- ld $16, 168($4) # Restore $16 of sigsetjmp
- ld $3, 176($4) # Restore base of got
-
-.hidden __sigsetjmp_tail
- ld $25, %got_disp(__sigsetjmp_tail)($3)
- jr $25
- nop
-1:
- ld $25, %got_disp(setjmp)($3)
- jr $25
- nop
lib/libc/wasi/libc-top-half/musl/src/signal/mipsn32/restore.s
@@ -1,11 +0,0 @@
-.set noreorder
-.global __restore_rt
-.global __restore
-.hidden __restore_rt
-.hidden __restore
-.type __restore_rt,@function
-.type __restore,@function
-__restore_rt:
-__restore:
- li $2,6211
- syscall
lib/libc/wasi/libc-top-half/musl/src/signal/mipsn32/sigsetjmp.s
@@ -1,38 +0,0 @@
-.set noreorder
-.global sigsetjmp
-.global __sigsetjmp
-.type sigsetjmp,@function
-.type __sigsetjmp,@function
-sigsetjmp:
-__sigsetjmp:
- lui $3, %hi(%neg(%gp_rel(sigsetjmp)))
- addiu $3, $3, %lo(%neg(%gp_rel(sigsetjmp)))
-
- # comparing save mask with 0, if equals to 0 then
- # sigsetjmp is equal to setjmp.
- beq $5, $0, 1f
- addu $3, $3, $25
- sd $ra, 160($4)
- sd $16, 168($4)
-
- # save base of got so that we can use it later
- # once we return from 'longjmp'
- sd $3, 176($4)
- lw $25, %got_disp(setjmp)($3)
- jalr $25
- move $16, $4
-
- move $5, $2 # Return from 'setjmp' or 'longjmp'
- move $4, $16 # Restore the pointer-to-sigjmp_buf
- ld $ra, 160($4) # Restore ra of sigsetjmp
- ld $16, 168($4) # Restore $16 of sigsetjmp
- ld $3, 176($4) # Restore base of got
-
-.hidden __sigsetjmp_tail
- lw $25, %got_disp(__sigsetjmp_tail)($3)
- jr $25
- nop
-1:
- lw $25, %got_disp(setjmp)($3)
- jr $25
- nop
lib/libc/wasi/libc-top-half/musl/src/signal/or1k/sigsetjmp.s
@@ -1,24 +0,0 @@
-.global sigsetjmp
-.global __sigsetjmp
-.type sigsetjmp,@function
-.type __sigsetjmp,@function
-sigsetjmp:
-__sigsetjmp:
- l.sfeq r4, r0
-.hidden ___setjmp
- l.bf ___setjmp
-
- l.sw 52(r3), r9
- l.sw 52+4+8(r3), r20
-
- l.jal ___setjmp
- l.ori r20, r3, 0
-
- l.ori r4, r11, 0
- l.ori r3, r20, 0
-
- l.lwz r9, 52(r3)
-
-.hidden __sigsetjmp_tail
- l.j __sigsetjmp_tail
- l.lwz r20, 52+4+8(r3)
lib/libc/wasi/libc-top-half/musl/src/signal/powerpc/restore.s
@@ -1,13 +0,0 @@
- .global __restore
- .hidden __restore
- .type __restore,%function
-__restore:
- li 0, 119 #__NR_sigreturn
- sc
-
- .global __restore_rt
- .hidden __restore_rt
- .type __restore_rt,%function
-__restore_rt:
- li 0, 172 # __NR_rt_sigreturn
- sc
lib/libc/wasi/libc-top-half/musl/src/signal/powerpc/sigsetjmp.s
@@ -1,27 +0,0 @@
- .global sigsetjmp
- .global __sigsetjmp
- .type sigsetjmp,%function
- .type __sigsetjmp,%function
-sigsetjmp:
-__sigsetjmp:
- cmpwi cr7, 4, 0
- beq- cr7, 1f
-
- mflr 5
- stw 5, 448(3)
- stw 16, 448+4+8(3)
- mr 16, 3
-
-.hidden ___setjmp
- bl ___setjmp
-
- mr 4, 3
- mr 3, 16
- lwz 5, 448(3)
- mtlr 5
- lwz 16, 448+4+8(3)
-
-.hidden __sigsetjmp_tail
- b __sigsetjmp_tail
-
-1: b ___setjmp
lib/libc/wasi/libc-top-half/musl/src/signal/powerpc64/restore.s
@@ -1,13 +0,0 @@
- .global __restore
- .hidden __restore
- .type __restore,%function
-__restore:
- li 0, 119 #__NR_sigreturn
- sc
-
- .global __restore_rt
- .hidden __restore_rt
- .type __restore_rt,%function
-__restore_rt:
- li 0, 172 # __NR_rt_sigreturn
- sc
lib/libc/wasi/libc-top-half/musl/src/signal/powerpc64/sigsetjmp.s
@@ -1,37 +0,0 @@
- .global sigsetjmp
- .global __sigsetjmp
- .type sigsetjmp,%function
- .type __sigsetjmp,%function
- .hidden __setjmp_toc
-sigsetjmp:
-__sigsetjmp:
- addis 2, 12, .TOC.-__sigsetjmp@ha
- addi 2, 2, .TOC.-__sigsetjmp@l
- ld 5, 24(1) # load from the TOC slot in the caller's stack frame
- b 1f
-
- .localentry sigsetjmp,.-sigsetjmp
- .localentry __sigsetjmp,.-__sigsetjmp
- mr 5, 2
-
-1:
- cmpwi cr7, 4, 0
- beq- cr7, __setjmp_toc
-
- mflr 6
- std 6, 512(3)
- std 2, 512+16(3)
- std 16, 512+24(3)
- mr 16, 3
-
- bl __setjmp_toc
-
- mr 4, 3
- mr 3, 16
- ld 5, 512(3)
- mtlr 5
- ld 2, 512+16(3)
- ld 16, 512+24(3)
-
-.hidden __sigsetjmp_tail
- b __sigsetjmp_tail
lib/libc/wasi/libc-top-half/musl/src/signal/riscv64/restore.s
@@ -1,8 +0,0 @@
-.global __restore
-.type __restore, %function
-__restore:
-.global __restore_rt
-.type __restore_rt, %function
-__restore_rt:
- li a7, 139 # SYS_rt_sigreturn
- ecall
lib/libc/wasi/libc-top-half/musl/src/signal/riscv64/sigsetjmp.s
@@ -1,23 +0,0 @@
-.global sigsetjmp
-.global __sigsetjmp
-.type sigsetjmp, %function
-.type __sigsetjmp, %function
-sigsetjmp:
-__sigsetjmp:
- bnez a1, 1f
- tail setjmp
-1:
-
- sd ra, 208(a0)
- sd s0, 224(a0)
- mv s0, a0
-
- call setjmp
-
- mv a1, a0
- mv a0, s0
- ld s0, 224(a0)
- ld ra, 208(a0)
-
-.hidden __sigsetjmp_tail
- tail __sigsetjmp_tail
lib/libc/wasi/libc-top-half/musl/src/signal/s390x/restore.s
@@ -1,11 +0,0 @@
- .global __restore
- .hidden __restore
- .type __restore,%function
-__restore:
- svc 119 #__NR_sigreturn
-
- .global __restore_rt
- .hidden __restore_rt
- .type __restore_rt,%function
-__restore_rt:
- svc 173 # __NR_rt_sigreturn
lib/libc/wasi/libc-top-half/musl/src/signal/s390x/sigsetjmp.s
@@ -1,23 +0,0 @@
- .global sigsetjmp
- .global __sigsetjmp
- .type sigsetjmp,%function
- .type __sigsetjmp,%function
- .hidden ___setjmp
-sigsetjmp:
-__sigsetjmp:
- ltgr %r3, %r3
- jz ___setjmp
-
- stg %r14, 18*8(%r2)
- stg %r6, 20*8(%r2)
- lgr %r6, %r2
-
- brasl %r14, ___setjmp
-
- lgr %r3, %r2
- lgr %r2, %r6
- lg %r14, 18*8(%r2)
- lg %r6, 20*8(%r2)
-
-.hidden __sigsetjmp_tail
- jg __sigsetjmp_tail
lib/libc/wasi/libc-top-half/musl/src/signal/sh/restore.s
@@ -1,24 +0,0 @@
-.global __restore
-.hidden __restore
-__restore:
- mov #119, r3 !__NR_sigreturn
- trapa #31
-
- or r0, r0
- or r0, r0
- or r0, r0
- or r0, r0
- or r0, r0
-
-.global __restore_rt
-.hidden __restore_rt
-__restore_rt:
- mov #100, r3 !__NR_rt_sigreturn
- add #73, r3
- trapa #31
-
- or r0, r0
- or r0, r0
- or r0, r0
- or r0, r0
- or r0, r0
lib/libc/wasi/libc-top-half/musl/src/signal/sh/sigsetjmp.s
@@ -1,41 +0,0 @@
-.global sigsetjmp
-.global __sigsetjmp
-.type sigsetjmp,@function
-.type __sigsetjmp,@function
-sigsetjmp:
-__sigsetjmp:
- tst r5, r5
- bt 9f
-
- mov r4, r6
- add #60, r6
- sts pr, r0
- mov.l r0, @r6
- mov.l r8, @(4+8,r6)
-
- mov.l 1f, r0
-2: bsrf r0
- mov r4, r8
-
- mov r0, r5
- mov r8, r4
- mov r4, r6
- add #60, r6
-
- mov.l @r6, r0
- lds r0, pr
-
- mov.l 3f, r0
-4: braf r0
- mov.l @(4+8,r4), r8
-
-9: mov.l 5f, r0
-6: braf r0
- nop
-
-.align 2
-.hidden ___setjmp
-1: .long ___setjmp@PLT-(2b+4-.)
-.hidden __sigsetjmp_tail
-3: .long __sigsetjmp_tail@PLT-(4b+4-.)
-5: .long ___setjmp@PLT-(6b+4-.)
lib/libc/wasi/libc-top-half/musl/src/signal/x32/getitimer.c
@@ -1,7 +0,0 @@
-#include <sys/time.h>
-#include "syscall.h"
-
-int getitimer(int which, struct itimerval *old)
-{
- return syscall(SYS_getitimer, which, old);
-}
lib/libc/wasi/libc-top-half/musl/src/signal/x32/restore.s
@@ -1,8 +0,0 @@
- nop
-.global __restore_rt
-.hidden __restore_rt
-.type __restore_rt,@function
-__restore_rt:
- mov $0x40000201, %rax /* SYS_rt_sigreturn */
- syscall
-.size __restore_rt,.-__restore_rt
lib/libc/wasi/libc-top-half/musl/src/signal/x32/setitimer.c
@@ -1,7 +0,0 @@
-#include <sys/time.h>
-#include "syscall.h"
-
-int setitimer(int which, const struct itimerval *restrict new, struct itimerval *restrict old)
-{
- return syscall(SYS_setitimer, which, new, old);
-}
lib/libc/wasi/libc-top-half/musl/src/signal/x32/sigsetjmp.s
@@ -1,25 +0,0 @@
-.global sigsetjmp
-.global __sigsetjmp
-.type sigsetjmp,@function
-.type __sigsetjmp,@function
-sigsetjmp:
-__sigsetjmp:
- test %esi,%esi
- jz 1f
-
- popq 64(%rdi)
- mov %rbx,72+8(%rdi)
- mov %rdi,%rbx
-
- call setjmp@PLT
-
- pushq 64(%rbx)
- movl $0, 4(%rsp)
- mov %rbx,%rdi
- mov %eax,%esi
- mov 72+8(%rbx),%rbx
-
-.hidden __sigsetjmp_tail
- jmp __sigsetjmp_tail
-
-1: jmp setjmp@PLT
lib/libc/wasi/libc-top-half/musl/src/signal/x86_64/restore.s
@@ -1,8 +0,0 @@
- nop
-.global __restore_rt
-.hidden __restore_rt
-.type __restore_rt,@function
-__restore_rt:
- mov $15, %rax
- syscall
-.size __restore_rt,.-__restore_rt
lib/libc/wasi/libc-top-half/musl/src/signal/x86_64/sigsetjmp.s
@@ -1,24 +0,0 @@
-.global sigsetjmp
-.global __sigsetjmp
-.type sigsetjmp,@function
-.type __sigsetjmp,@function
-sigsetjmp:
-__sigsetjmp:
- test %esi,%esi
- jz 1f
-
- popq 64(%rdi)
- mov %rbx,72+8(%rdi)
- mov %rdi,%rbx
-
- call setjmp@PLT
-
- pushq 64(%rbx)
- mov %rbx,%rdi
- mov %eax,%esi
- mov 72+8(%rbx),%rbx
-
-.hidden __sigsetjmp_tail
- jmp __sigsetjmp_tail
-
-1: jmp setjmp@PLT
lib/libc/wasi/libc-top-half/musl/src/signal/block.c
@@ -1,44 +0,0 @@
-#include "pthread_impl.h"
-#include "syscall.h"
-#include <signal.h>
-
-static const unsigned long all_mask[] = {
-#if ULONG_MAX == 0xffffffff && _NSIG > 65
- -1UL, -1UL, -1UL, -1UL
-#elif ULONG_MAX == 0xffffffff || _NSIG > 65
- -1UL, -1UL
-#else
- -1UL
-#endif
-};
-
-static const unsigned long app_mask[] = {
-#if ULONG_MAX == 0xffffffff
-#if _NSIG == 65
- 0x7fffffff, 0xfffffffc
-#else
- 0x7fffffff, 0xfffffffc, -1UL, -1UL
-#endif
-#else
-#if _NSIG == 65
- 0xfffffffc7fffffff
-#else
- 0xfffffffc7fffffff, -1UL
-#endif
-#endif
-};
-
-void __block_all_sigs(void *set)
-{
- __syscall(SYS_rt_sigprocmask, SIG_BLOCK, &all_mask, set, _NSIG/8);
-}
-
-void __block_app_sigs(void *set)
-{
- __syscall(SYS_rt_sigprocmask, SIG_BLOCK, &app_mask, set, _NSIG/8);
-}
-
-void __restore_sigs(void *set)
-{
- __syscall(SYS_rt_sigprocmask, SIG_SETMASK, set, 0, _NSIG/8);
-}
lib/libc/wasi/libc-top-half/musl/src/signal/getitimer.c
@@ -1,18 +0,0 @@
-#include <sys/time.h>
-#include "syscall.h"
-
-int getitimer(int which, struct itimerval *old)
-{
- if (sizeof(time_t) > sizeof(long)) {
- long old32[4];
- int r = __syscall(SYS_getitimer, which, old32);
- if (!r) {
- old->it_interval.tv_sec = old32[0];
- old->it_interval.tv_usec = old32[1];
- old->it_value.tv_sec = old32[2];
- old->it_value.tv_usec = old32[3];
- }
- return __syscall_ret(r);
- }
- return syscall(SYS_getitimer, which, old);
-}
lib/libc/wasi/libc-top-half/musl/src/signal/kill.c
@@ -1,7 +0,0 @@
-#include <signal.h>
-#include "syscall.h"
-
-int kill(pid_t pid, int sig)
-{
- return syscall(SYS_kill, pid, sig);
-}
lib/libc/wasi/libc-top-half/musl/src/signal/killpg.c
@@ -1,11 +0,0 @@
-#include <signal.h>
-#include <errno.h>
-
-int killpg(pid_t pgid, int sig)
-{
- if (pgid < 0) {
- errno = EINVAL;
- return -1;
- }
- return kill(-pgid, sig);
-}
lib/libc/wasi/libc-top-half/musl/src/signal/psiginfo.c
@@ -1,6 +0,0 @@
-#include <signal.h>
-
-void psiginfo(const siginfo_t *si, const char *msg)
-{
- psignal(si->si_signo, msg);
-}
lib/libc/wasi/libc-top-half/musl/src/signal/raise.c
@@ -1,13 +0,0 @@
-#include <signal.h>
-#include <stdint.h>
-#include "syscall.h"
-#include "pthread_impl.h"
-
-int raise(int sig)
-{
- sigset_t set;
- __block_app_sigs(&set);
- int ret = syscall(SYS_tkill, __pthread_self()->tid, sig);
- __restore_sigs(&set);
- return ret;
-}
lib/libc/wasi/libc-top-half/musl/src/signal/restore.c
@@ -1,12 +0,0 @@
-#include <features.h>
-
-/* These functions will not work, but suffice for targets where the
- * kernel sigaction structure does not actually use sa_restorer. */
-
-hidden void __restore()
-{
-}
-
-hidden void __restore_rt()
-{
-}
lib/libc/wasi/libc-top-half/musl/src/signal/setitimer.c
@@ -1,26 +0,0 @@
-#include <sys/time.h>
-#include <errno.h>
-#include "syscall.h"
-
-#define IS32BIT(x) !((x)+0x80000000ULL>>32)
-
-int setitimer(int which, const struct itimerval *restrict new, struct itimerval *restrict old)
-{
- if (sizeof(time_t) > sizeof(long)) {
- time_t is = new->it_interval.tv_sec, vs = new->it_value.tv_sec;
- long ius = new->it_interval.tv_usec, vus = new->it_value.tv_usec;
- if (!IS32BIT(is) || !IS32BIT(vs))
- return __syscall_ret(-ENOTSUP);
- long old32[4];
- int r = __syscall(SYS_setitimer, which,
- ((long[]){is, ius, vs, vus}), old32);
- if (!r && old) {
- old->it_interval.tv_sec = old32[0];
- old->it_interval.tv_usec = old32[1];
- old->it_value.tv_sec = old32[2];
- old->it_value.tv_usec = old32[3];
- }
- return __syscall_ret(r);
- }
- return syscall(SYS_setitimer, which, new, old);
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigaction.c
@@ -1,84 +0,0 @@
-#include <signal.h>
-#include <errno.h>
-#include <string.h>
-#include "syscall.h"
-#include "pthread_impl.h"
-#include "libc.h"
-#include "lock.h"
-#include "ksigaction.h"
-
-static int unmask_done;
-static unsigned long handler_set[_NSIG/(8*sizeof(long))];
-
-void __get_handler_set(sigset_t *set)
-{
- memcpy(set, handler_set, sizeof handler_set);
-}
-
-volatile int __eintr_valid_flag;
-
-int __libc_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
-{
- struct k_sigaction ksa, ksa_old;
- if (sa) {
- if ((uintptr_t)sa->sa_handler > 1UL) {
- a_or_l(handler_set+(sig-1)/(8*sizeof(long)),
- 1UL<<(sig-1)%(8*sizeof(long)));
-
- /* If pthread_create has not yet been called,
- * implementation-internal signals might not
- * yet have been unblocked. They must be
- * unblocked before any signal handler is
- * installed, so that an application cannot
- * receive an illegal sigset_t (with them
- * blocked) as part of the ucontext_t passed
- * to the signal handler. */
- if (!libc.threaded && !unmask_done) {
- __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK,
- SIGPT_SET, 0, _NSIG/8);
- unmask_done = 1;
- }
-
- if (!(sa->sa_flags & SA_RESTART)) {
- a_store(&__eintr_valid_flag, 1);
- }
- }
- ksa.handler = sa->sa_handler;
- ksa.flags = sa->sa_flags | SA_RESTORER;
- ksa.restorer = (sa->sa_flags & SA_SIGINFO) ? __restore_rt : __restore;
- memcpy(&ksa.mask, &sa->sa_mask, _NSIG/8);
- }
- int r = __syscall(SYS_rt_sigaction, sig, sa?&ksa:0, old?&ksa_old:0, _NSIG/8);
- if (old && !r) {
- old->sa_handler = ksa_old.handler;
- old->sa_flags = ksa_old.flags;
- memcpy(&old->sa_mask, &ksa_old.mask, _NSIG/8);
- }
- return __syscall_ret(r);
-}
-
-int __sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
-{
- unsigned long set[_NSIG/(8*sizeof(long))];
-
- if (sig-32U < 3 || sig-1U >= _NSIG-1) {
- errno = EINVAL;
- return -1;
- }
-
- /* Doing anything with the disposition of SIGABRT requires a lock,
- * so that it cannot be changed while abort is terminating the
- * process and so any change made by abort can't be observed. */
- if (sig == SIGABRT) {
- __block_all_sigs(&set);
- LOCK(__abort_lock);
- }
- int r = __libc_sigaction(sig, sa, old);
- if (sig == SIGABRT) {
- UNLOCK(__abort_lock);
- __restore_sigs(&set);
- }
- return r;
-}
-
-weak_alias(__sigaction, sigaction);
lib/libc/wasi/libc-top-half/musl/src/signal/sigaddset.c
@@ -1,13 +0,0 @@
-#include <signal.h>
-#include <errno.h>
-
-int sigaddset(sigset_t *set, int sig)
-{
- unsigned s = sig-1;
- if (s >= _NSIG-1 || sig-32U < 3) {
- errno = EINVAL;
- return -1;
- }
- set->__bits[s/8/sizeof *set->__bits] |= 1UL<<(s&8*sizeof *set->__bits-1);
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigaltstack.c
@@ -1,18 +0,0 @@
-#include <signal.h>
-#include <errno.h>
-#include "syscall.h"
-
-int sigaltstack(const stack_t *restrict ss, stack_t *restrict old)
-{
- if (ss) {
- if (!(ss->ss_flags & SS_DISABLE) && ss->ss_size < MINSIGSTKSZ) {
- errno = ENOMEM;
- return -1;
- }
- if (ss->ss_flags & SS_ONSTACK) {
- errno = EINVAL;
- return -1;
- }
- }
- return syscall(SYS_sigaltstack, ss, old);
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigandset.c
@@ -1,12 +0,0 @@
-#define _GNU_SOURCE
-#include <signal.h>
-
-#define SST_SIZE (_NSIG/8/sizeof(long))
-
-int sigandset(sigset_t *dest, const sigset_t *left, const sigset_t *right)
-{
- unsigned long i = 0, *d = (void*) dest, *l = (void*) left, *r = (void*) right;
- for(; i < SST_SIZE; i++) d[i] = l[i] & r[i];
- return 0;
-}
-
lib/libc/wasi/libc-top-half/musl/src/signal/sigdelset.c
@@ -1,13 +0,0 @@
-#include <signal.h>
-#include <errno.h>
-
-int sigdelset(sigset_t *set, int sig)
-{
- unsigned s = sig-1;
- if (s >= _NSIG-1 || sig-32U < 3) {
- errno = EINVAL;
- return -1;
- }
- set->__bits[s/8/sizeof *set->__bits] &=~(1UL<<(s&8*sizeof *set->__bits-1));
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigemptyset.c
@@ -1,13 +0,0 @@
-#include <signal.h>
-#include <string.h>
-
-int sigemptyset(sigset_t *set)
-{
- set->__bits[0] = 0;
- if (sizeof(long)==4 || _NSIG > 65) set->__bits[1] = 0;
- if (sizeof(long)==4 && _NSIG > 65) {
- set->__bits[2] = 0;
- set->__bits[3] = 0;
- }
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigfillset.c
@@ -1,18 +0,0 @@
-#include <signal.h>
-#include <limits.h>
-
-int sigfillset(sigset_t *set)
-{
-#if ULONG_MAX == 0xffffffff
- set->__bits[0] = 0x7ffffffful;
- set->__bits[1] = 0xfffffffcul;
- if (_NSIG > 65) {
- set->__bits[2] = 0xfffffffful;
- set->__bits[3] = 0xfffffffful;
- }
-#else
- set->__bits[0] = 0xfffffffc7ffffffful;
- if (_NSIG > 65) set->__bits[1] = 0xfffffffffffffffful;
-#endif
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sighold.c
@@ -1,10 +0,0 @@
-#include <signal.h>
-
-int sighold(int sig)
-{
- sigset_t mask;
-
- sigemptyset(&mask);
- if (sigaddset(&mask, sig) < 0) return -1;
- return sigprocmask(SIG_BLOCK, &mask, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigignore.c
@@ -1,11 +0,0 @@
-#include <signal.h>
-
-int sigignore(int sig)
-{
- struct sigaction sa;
-
- sigemptyset(&sa.sa_mask);
- sa.sa_handler = SIG_IGN;
- sa.sa_flags = 0;
- return sigaction(sig, &sa, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/signal/siginterrupt.c
@@ -1,12 +0,0 @@
-#include <signal.h>
-
-int siginterrupt(int sig, int flag)
-{
- struct sigaction sa;
-
- sigaction(sig, 0, &sa);
- if (flag) sa.sa_flags &= ~SA_RESTART;
- else sa.sa_flags |= SA_RESTART;
-
- return sigaction(sig, &sa, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigisemptyset.c
@@ -1,10 +0,0 @@
-#define _GNU_SOURCE
-#include <signal.h>
-#include <string.h>
-
-int sigisemptyset(const sigset_t *set)
-{
- for (size_t i=0; i<_NSIG/8/sizeof *set->__bits; i++)
- if (set->__bits[i]) return 0;
- return 1;
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigismember.c
@@ -1,8 +0,0 @@
-#include <signal.h>
-
-int sigismember(const sigset_t *set, int sig)
-{
- unsigned s = sig-1;
- if (s >= _NSIG-1) return 0;
- return !!(set->__bits[s/8/sizeof *set->__bits] & 1UL<<(s&8*sizeof *set->__bits-1));
-}
lib/libc/wasi/libc-top-half/musl/src/signal/siglongjmp.c
@@ -1,9 +0,0 @@
-#include <setjmp.h>
-#include <signal.h>
-#include "syscall.h"
-#include "pthread_impl.h"
-
-_Noreturn void siglongjmp(sigjmp_buf buf, int ret)
-{
- longjmp(buf, ret);
-}
lib/libc/wasi/libc-top-half/musl/src/signal/signal.c
@@ -1,13 +0,0 @@
-#include <signal.h>
-#include "syscall.h"
-
-void (*signal(int sig, void (*func)(int)))(int)
-{
- struct sigaction sa_old, sa = { .sa_handler = func, .sa_flags = SA_RESTART };
- if (__sigaction(sig, &sa, &sa_old) < 0)
- return SIG_ERR;
- return sa_old.sa_handler;
-}
-
-weak_alias(signal, bsd_signal);
-weak_alias(signal, __sysv_signal);
lib/libc/wasi/libc-top-half/musl/src/signal/sigorset.c
@@ -1,12 +0,0 @@
-#define _GNU_SOURCE
-#include <signal.h>
-
-#define SST_SIZE (_NSIG/8/sizeof(long))
-
-int sigorset(sigset_t *dest, const sigset_t *left, const sigset_t *right)
-{
- unsigned long i = 0, *d = (void*) dest, *l = (void*) left, *r = (void*) right;
- for(; i < SST_SIZE; i++) d[i] = l[i] | r[i];
- return 0;
-}
-
lib/libc/wasi/libc-top-half/musl/src/signal/sigpause.c
@@ -1,9 +0,0 @@
-#include <signal.h>
-
-int sigpause(int sig)
-{
- sigset_t mask;
- sigprocmask(0, 0, &mask);
- sigdelset(&mask, sig);
- return sigsuspend(&mask);
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigpending.c
@@ -1,7 +0,0 @@
-#include <signal.h>
-#include "syscall.h"
-
-int sigpending(sigset_t *set)
-{
- return syscall(SYS_rt_sigpending, set, _NSIG/8);
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigprocmask.c
@@ -1,10 +0,0 @@
-#include <signal.h>
-#include <errno.h>
-
-int sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old)
-{
- int r = pthread_sigmask(how, set, old);
- if (!r) return r;
- errno = r;
- return -1;
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigqueue.c
@@ -1,22 +0,0 @@
-#include <signal.h>
-#include <string.h>
-#include <unistd.h>
-#include "syscall.h"
-#include "pthread_impl.h"
-
-int sigqueue(pid_t pid, int sig, const union sigval value)
-{
- siginfo_t si;
- sigset_t set;
- int r;
- memset(&si, 0, sizeof si);
- si.si_signo = sig;
- si.si_code = SI_QUEUE;
- si.si_value = value;
- si.si_uid = getuid();
- __block_app_sigs(&set);
- si.si_pid = getpid();
- r = syscall(SYS_rt_sigqueueinfo, pid, sig, &si);
- __restore_sigs(&set);
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigrelse.c
@@ -1,10 +0,0 @@
-#include <signal.h>
-
-int sigrelse(int sig)
-{
- sigset_t mask;
-
- sigemptyset(&mask);
- if (sigaddset(&mask, sig) < 0) return -1;
- return sigprocmask(SIG_UNBLOCK, &mask, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigrtmax.c
@@ -1,6 +0,0 @@
-#include <signal.h>
-
-int __libc_current_sigrtmax()
-{
- return _NSIG-1;
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigrtmin.c
@@ -1,6 +0,0 @@
-#include <signal.h>
-
-int __libc_current_sigrtmin()
-{
- return 35;
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigset.c
@@ -1,27 +0,0 @@
-#include <signal.h>
-
-void (*sigset(int sig, void (*handler)(int)))(int)
-{
- struct sigaction sa, sa_old;
- sigset_t mask, mask_old;
-
- sigemptyset(&mask);
- if (sigaddset(&mask, sig) < 0)
- return SIG_ERR;
-
- if (handler == SIG_HOLD) {
- if (sigaction(sig, 0, &sa_old) < 0)
- return SIG_ERR;
- if (sigprocmask(SIG_BLOCK, &mask, &mask_old) < 0)
- return SIG_ERR;
- } else {
- sa.sa_handler = handler;
- sa.sa_flags = 0;
- sigemptyset(&sa.sa_mask);
- if (sigaction(sig, &sa, &sa_old) < 0)
- return SIG_ERR;
- if (sigprocmask(SIG_UNBLOCK, &mask, &mask_old) < 0)
- return SIG_ERR;
- }
- return sigismember(&mask_old, sig) ? SIG_HOLD : sa_old.sa_handler;
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigsetjmp.c
lib/libc/wasi/libc-top-half/musl/src/signal/sigsetjmp_tail.c
@@ -1,10 +0,0 @@
-#include <setjmp.h>
-#include <signal.h>
-#include "syscall.h"
-
-hidden int __sigsetjmp_tail(sigjmp_buf jb, int ret)
-{
- void *p = jb->__ss;
- __syscall(SYS_rt_sigprocmask, SIG_SETMASK, ret?p:0, ret?0:p, _NSIG/8);
- return ret;
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigsuspend.c
@@ -1,7 +0,0 @@
-#include <signal.h>
-#include "syscall.h"
-
-int sigsuspend(const sigset_t *mask)
-{
- return syscall_cp(SYS_rt_sigsuspend, mask, _NSIG/8);
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigtimedwait.c
@@ -1,32 +0,0 @@
-#include <signal.h>
-#include <errno.h>
-#include "syscall.h"
-
-#define IS32BIT(x) !((x)+0x80000000ULL>>32)
-#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
-
-static int do_sigtimedwait(const sigset_t *restrict mask, siginfo_t *restrict si, const struct timespec *restrict ts)
-{
-#ifdef SYS_rt_sigtimedwait_time64
- time_t s = ts ? ts->tv_sec : 0;
- long ns = ts ? ts->tv_nsec : 0;
- int r = -ENOSYS;
- if (SYS_rt_sigtimedwait == SYS_rt_sigtimedwait_time64 || !IS32BIT(s))
- r = __syscall_cp(SYS_rt_sigtimedwait_time64, mask, si,
- ts ? ((long long[]){s, ns}) : 0, _NSIG/8);
- if (SYS_rt_sigtimedwait == SYS_rt_sigtimedwait_time64 || r!=-ENOSYS)
- return r;
- return __syscall_cp(SYS_rt_sigtimedwait, mask, si,
- ts ? ((long[]){CLAMP(s), ns}) : 0, _NSIG/8);;
-#else
- return __syscall_cp(SYS_rt_sigtimedwait, mask, si, ts, _NSIG/8);
-#endif
-}
-
-int sigtimedwait(const sigset_t *restrict mask, siginfo_t *restrict si, const struct timespec *restrict timeout)
-{
- int ret;
- do ret = do_sigtimedwait(mask, si, timeout);
- while (ret==-EINTR);
- return __syscall_ret(ret);
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigwait.c
@@ -1,10 +0,0 @@
-#include <signal.h>
-
-int sigwait(const sigset_t *restrict mask, int *restrict sig)
-{
- siginfo_t si;
- if (sigtimedwait(mask, &si, 0) < 0)
- return -1;
- *sig = si.si_signo;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/signal/sigwaitinfo.c
@@ -1,6 +0,0 @@
-#include <signal.h>
-
-int sigwaitinfo(const sigset_t *restrict mask, siginfo_t *restrict si)
-{
- return sigtimedwait(mask, si, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/stat/__xstat.c
@@ -1,40 +0,0 @@
-#include <sys/stat.h>
-
-#if !_REDIR_TIME64
-
-int __fxstat(int ver, int fd, struct stat *buf)
-{
- return fstat(fd, buf);
-}
-
-int __fxstatat(int ver, int fd, const char *path, struct stat *buf, int flag)
-{
- return fstatat(fd, path, buf, flag);
-}
-
-int __lxstat(int ver, const char *path, struct stat *buf)
-{
- return lstat(path, buf);
-}
-
-int __xstat(int ver, const char *path, struct stat *buf)
-{
- return stat(path, buf);
-}
-
-weak_alias(__fxstat, __fxstat64);
-weak_alias(__fxstatat, __fxstatat64);
-weak_alias(__lxstat, __lxstat64);
-weak_alias(__xstat, __xstat64);
-
-#endif
-
-int __xmknod(int ver, const char *path, mode_t mode, dev_t *dev)
-{
- return mknod(path, mode, *dev);
-}
-
-int __xmknodat(int ver, int fd, const char *path, mode_t mode, dev_t *dev)
-{
- return mknodat(fd, path, mode, *dev);
-}
lib/libc/wasi/libc-top-half/musl/src/stat/chmod.c
@@ -1,12 +0,0 @@
-#include <sys/stat.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int chmod(const char *path, mode_t mode)
-{
-#ifdef SYS_chmod
- return syscall(SYS_chmod, path, mode);
-#else
- return syscall(SYS_fchmodat, AT_FDCWD, path, mode);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/stat/fchmod.c
@@ -1,19 +0,0 @@
-#include <sys/stat.h>
-#include <errno.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int fchmod(int fd, mode_t mode)
-{
- int ret = __syscall(SYS_fchmod, fd, mode);
- if (ret != -EBADF || __syscall(SYS_fcntl, fd, F_GETFD) < 0)
- return __syscall_ret(ret);
-
- char buf[15+3*sizeof(int)];
- __procfdname(buf, fd);
-#ifdef SYS_chmod
- return syscall(SYS_chmod, buf, mode);
-#else
- return syscall(SYS_fchmodat, AT_FDCWD, buf, mode);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/stat/fchmodat.c
@@ -1,38 +0,0 @@
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include "syscall.h"
-#include "kstat.h"
-
-int fchmodat(int fd, const char *path, mode_t mode, int flag)
-{
- if (!flag) return syscall(SYS_fchmodat, fd, path, mode, flag);
-
- if (flag != AT_SYMLINK_NOFOLLOW)
- return __syscall_ret(-EINVAL);
-
- struct kstat st;
- int ret, fd2;
- char proc[15+3*sizeof(int)];
-
- if ((ret = __syscall(SYS_fstatat, fd, path, &st, flag)))
- return __syscall_ret(ret);
- if (S_ISLNK(st.st_mode))
- return __syscall_ret(-EOPNOTSUPP);
-
- if ((fd2 = __syscall(SYS_openat, fd, path, O_RDONLY|O_PATH|O_NOFOLLOW|O_NOCTTY|O_CLOEXEC)) < 0) {
- if (fd2 == -ELOOP)
- return __syscall_ret(-EOPNOTSUPP);
- return __syscall_ret(fd2);
- }
-
- __procfdname(proc, fd2);
- ret = __syscall(SYS_fstatat, AT_FDCWD, proc, &st, 0);
- if (!ret) {
- if (S_ISLNK(st.st_mode)) ret = -EOPNOTSUPP;
- else ret = __syscall(SYS_fchmodat, AT_FDCWD, proc, mode);
- }
-
- __syscall(SYS_close, fd2);
- return __syscall_ret(ret);
-}
lib/libc/wasi/libc-top-half/musl/src/stat/fstat.c
@@ -1,15 +0,0 @@
-#define _BSD_SOURCE
-#include <sys/stat.h>
-#include <errno.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int fstat(int fd, struct stat *st)
-{
- if (fd<0) return __syscall_ret(-EBADF);
- return fstatat(fd, "", st, AT_EMPTY_PATH);
-}
-
-#if !_REDIR_TIME64
-weak_alias(fstat, fstat64);
-#endif
lib/libc/wasi/libc-top-half/musl/src/stat/fstatat.c
@@ -1,147 +0,0 @@
-#define _BSD_SOURCE
-#include <sys/stat.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdint.h>
-#include <sys/sysmacros.h>
-#include "syscall.h"
-#include "kstat.h"
-
-struct statx {
- uint32_t stx_mask;
- uint32_t stx_blksize;
- uint64_t stx_attributes;
- uint32_t stx_nlink;
- uint32_t stx_uid;
- uint32_t stx_gid;
- uint16_t stx_mode;
- uint16_t pad1;
- uint64_t stx_ino;
- uint64_t stx_size;
- uint64_t stx_blocks;
- uint64_t stx_attributes_mask;
- struct {
- int64_t tv_sec;
- uint32_t tv_nsec;
- int32_t pad;
- } stx_atime, stx_btime, stx_ctime, stx_mtime;
- uint32_t stx_rdev_major;
- uint32_t stx_rdev_minor;
- uint32_t stx_dev_major;
- uint32_t stx_dev_minor;
- uint64_t spare[14];
-};
-
-static int fstatat_statx(int fd, const char *restrict path, struct stat *restrict st, int flag)
-{
- struct statx stx;
-
- int ret = __syscall(SYS_statx, fd, path, flag, 0x7ff, &stx);
- if (ret) return ret;
-
- *st = (struct stat){
- .st_dev = makedev(stx.stx_dev_major, stx.stx_dev_minor),
- .st_ino = stx.stx_ino,
- .st_mode = stx.stx_mode,
- .st_nlink = stx.stx_nlink,
- .st_uid = stx.stx_uid,
- .st_gid = stx.stx_gid,
- .st_rdev = makedev(stx.stx_rdev_major, stx.stx_rdev_minor),
- .st_size = stx.stx_size,
- .st_blksize = stx.stx_blksize,
- .st_blocks = stx.stx_blocks,
- .st_atim.tv_sec = stx.stx_atime.tv_sec,
- .st_atim.tv_nsec = stx.stx_atime.tv_nsec,
- .st_mtim.tv_sec = stx.stx_mtime.tv_sec,
- .st_mtim.tv_nsec = stx.stx_mtime.tv_nsec,
- .st_ctim.tv_sec = stx.stx_ctime.tv_sec,
- .st_ctim.tv_nsec = stx.stx_ctime.tv_nsec,
-#if _REDIR_TIME64
- .__st_atim32.tv_sec = stx.stx_atime.tv_sec,
- .__st_atim32.tv_nsec = stx.stx_atime.tv_nsec,
- .__st_mtim32.tv_sec = stx.stx_mtime.tv_sec,
- .__st_mtim32.tv_nsec = stx.stx_mtime.tv_nsec,
- .__st_ctim32.tv_sec = stx.stx_ctime.tv_sec,
- .__st_ctim32.tv_nsec = stx.stx_ctime.tv_nsec,
-#endif
- };
- return 0;
-}
-
-static int fstatat_kstat(int fd, const char *restrict path, struct stat *restrict st, int flag)
-{
- int ret;
- struct kstat kst;
-
- if (flag==AT_EMPTY_PATH && fd>=0 && !*path) {
- ret = __syscall(SYS_fstat, fd, &kst);
- if (ret==-EBADF && __syscall(SYS_fcntl, fd, F_GETFD)>=0) {
- ret = __syscall(SYS_fstatat, fd, path, &kst, flag);
- if (ret==-EINVAL) {
- char buf[15+3*sizeof(int)];
- __procfdname(buf, fd);
-#ifdef SYS_stat
- ret = __syscall(SYS_stat, buf, &kst);
-#else
- ret = __syscall(SYS_fstatat, AT_FDCWD, buf, &kst, 0);
-#endif
- }
- }
- }
-#ifdef SYS_lstat
- else if ((fd == AT_FDCWD || *path=='/') && flag==AT_SYMLINK_NOFOLLOW)
- ret = __syscall(SYS_lstat, path, &kst);
-#endif
-#ifdef SYS_stat
- else if ((fd == AT_FDCWD || *path=='/') && !flag)
- ret = __syscall(SYS_stat, path, &kst);
-#endif
- else ret = __syscall(SYS_fstatat, fd, path, &kst, flag);
-
- if (ret) return ret;
-
- *st = (struct stat){
- .st_dev = kst.st_dev,
- .st_ino = kst.st_ino,
- .st_mode = kst.st_mode,
- .st_nlink = kst.st_nlink,
- .st_uid = kst.st_uid,
- .st_gid = kst.st_gid,
- .st_rdev = kst.st_rdev,
- .st_size = kst.st_size,
- .st_blksize = kst.st_blksize,
- .st_blocks = kst.st_blocks,
- .st_atim.tv_sec = kst.st_atime_sec,
- .st_atim.tv_nsec = kst.st_atime_nsec,
- .st_mtim.tv_sec = kst.st_mtime_sec,
- .st_mtim.tv_nsec = kst.st_mtime_nsec,
- .st_ctim.tv_sec = kst.st_ctime_sec,
- .st_ctim.tv_nsec = kst.st_ctime_nsec,
-#if _REDIR_TIME64
- .__st_atim32.tv_sec = kst.st_atime_sec,
- .__st_atim32.tv_nsec = kst.st_atime_nsec,
- .__st_mtim32.tv_sec = kst.st_mtime_sec,
- .__st_mtim32.tv_nsec = kst.st_mtime_nsec,
- .__st_ctim32.tv_sec = kst.st_ctime_sec,
- .__st_ctim32.tv_nsec = kst.st_ctime_nsec,
-#endif
- };
-
- return 0;
-}
-
-int fstatat(int fd, const char *restrict path, struct stat *restrict st, int flag)
-{
- int ret;
- if (sizeof((struct kstat){0}.st_atime_sec) < sizeof(time_t)) {
- ret = fstatat_statx(fd, path, st, flag);
- if (ret!=-ENOSYS) return __syscall_ret(ret);
- }
- ret = fstatat_kstat(fd, path, st, flag);
- return __syscall_ret(ret);
-}
-
-#if !_REDIR_TIME64
-weak_alias(fstatat, fstatat64);
-#endif
lib/libc/wasi/libc-top-half/musl/src/stat/futimens.c
@@ -1,6 +0,0 @@
-#include <sys/stat.h>
-
-int futimens(int fd, const struct timespec times[2])
-{
- return utimensat(fd, 0, times, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/stat/lchmod.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <sys/stat.h>
-#include <fcntl.h>
-
-int lchmod(const char *path, mode_t mode)
-{
- return fchmodat(AT_FDCWD, path, mode, AT_SYMLINK_NOFOLLOW);
-}
lib/libc/wasi/libc-top-half/musl/src/stat/lstat.c
@@ -1,11 +0,0 @@
-#include <sys/stat.h>
-#include <fcntl.h>
-
-int lstat(const char *restrict path, struct stat *restrict buf)
-{
- return fstatat(AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW);
-}
-
-#if !_REDIR_TIME64
-weak_alias(lstat, lstat64);
-#endif
lib/libc/wasi/libc-top-half/musl/src/stat/mkdir.c
@@ -1,12 +0,0 @@
-#include <sys/stat.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int mkdir(const char *path, mode_t mode)
-{
-#ifdef SYS_mkdir
- return syscall(SYS_mkdir, path, mode);
-#else
- return syscall(SYS_mkdirat, AT_FDCWD, path, mode);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/stat/mkdirat.c
@@ -1,7 +0,0 @@
-#include <sys/stat.h>
-#include "syscall.h"
-
-int mkdirat(int fd, const char *path, mode_t mode)
-{
- return syscall(SYS_mkdirat, fd, path, mode);
-}
lib/libc/wasi/libc-top-half/musl/src/stat/mkfifo.c
@@ -1,6 +0,0 @@
-#include <sys/stat.h>
-
-int mkfifo(const char *path, mode_t mode)
-{
- return mknod(path, mode | S_IFIFO, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/stat/mkfifoat.c
@@ -1,6 +0,0 @@
-#include <sys/stat.h>
-
-int mkfifoat(int fd, const char *path, mode_t mode)
-{
- return mknodat(fd, path, mode | S_IFIFO, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/stat/mknod.c
@@ -1,12 +0,0 @@
-#include <sys/stat.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int mknod(const char *path, mode_t mode, dev_t dev)
-{
-#ifdef SYS_mknod
- return syscall(SYS_mknod, path, mode, dev);
-#else
- return syscall(SYS_mknodat, AT_FDCWD, path, mode, dev);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/stat/mknodat.c
@@ -1,7 +0,0 @@
-#include <sys/stat.h>
-#include "syscall.h"
-
-int mknodat(int fd, const char *path, mode_t mode, dev_t dev)
-{
- return syscall(SYS_mknodat, fd, path, mode, dev);
-}
lib/libc/wasi/libc-top-half/musl/src/stat/stat.c
@@ -1,11 +0,0 @@
-#include <sys/stat.h>
-#include <fcntl.h>
-
-int stat(const char *restrict path, struct stat *restrict buf)
-{
- return fstatat(AT_FDCWD, path, buf, 0);
-}
-
-#if !_REDIR_TIME64
-weak_alias(stat, stat64);
-#endif
lib/libc/wasi/libc-top-half/musl/src/stat/statvfs.c
@@ -1,63 +0,0 @@
-#include <sys/statvfs.h>
-#include <sys/statfs.h>
-#include "syscall.h"
-
-static int __statfs(const char *path, struct statfs *buf)
-{
- *buf = (struct statfs){0};
-#ifdef SYS_statfs64
- return syscall(SYS_statfs64, path, sizeof *buf, buf);
-#else
- return syscall(SYS_statfs, path, buf);
-#endif
-}
-
-static int __fstatfs(int fd, struct statfs *buf)
-{
- *buf = (struct statfs){0};
-#ifdef SYS_fstatfs64
- return syscall(SYS_fstatfs64, fd, sizeof *buf, buf);
-#else
- return syscall(SYS_fstatfs, fd, buf);
-#endif
-}
-
-weak_alias(__statfs, statfs);
-weak_alias(__fstatfs, fstatfs);
-
-static void fixup(struct statvfs *out, const struct statfs *in)
-{
- *out = (struct statvfs){0};
- out->f_bsize = in->f_bsize;
- out->f_frsize = in->f_frsize ? in->f_frsize : in->f_bsize;
- out->f_blocks = in->f_blocks;
- out->f_bfree = in->f_bfree;
- out->f_bavail = in->f_bavail;
- out->f_files = in->f_files;
- out->f_ffree = in->f_ffree;
- out->f_favail = in->f_ffree;
- out->f_fsid = in->f_fsid.__val[0];
- out->f_flag = in->f_flags;
- out->f_namemax = in->f_namelen;
-}
-
-int statvfs(const char *restrict path, struct statvfs *restrict buf)
-{
- struct statfs kbuf;
- if (__statfs(path, &kbuf)<0) return -1;
- fixup(buf, &kbuf);
- return 0;
-}
-
-int fstatvfs(int fd, struct statvfs *buf)
-{
- struct statfs kbuf;
- if (__fstatfs(fd, &kbuf)<0) return -1;
- fixup(buf, &kbuf);
- return 0;
-}
-
-weak_alias(statvfs, statvfs64);
-weak_alias(statfs, statfs64);
-weak_alias(fstatvfs, fstatvfs64);
-weak_alias(fstatfs, fstatfs64);
lib/libc/wasi/libc-top-half/musl/src/stat/umask.c
@@ -1,7 +0,0 @@
-#include <sys/stat.h>
-#include "syscall.h"
-
-mode_t umask(mode_t mode)
-{
- return syscall(SYS_umask, mode);
-}
lib/libc/wasi/libc-top-half/musl/src/stat/utimensat.c
@@ -1,60 +0,0 @@
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <fcntl.h>
-#include <errno.h>
-#include "syscall.h"
-
-#define IS32BIT(x) !((x)+0x80000000ULL>>32)
-#define NS_SPECIAL(ns) ((ns)==UTIME_NOW || (ns)==UTIME_OMIT)
-
-int utimensat(int fd, const char *path, const struct timespec times[2], int flags)
-{
- int r;
- if (times && times[0].tv_nsec==UTIME_NOW && times[1].tv_nsec==UTIME_NOW)
- times = 0;
-#ifdef SYS_utimensat_time64
- r = -ENOSYS;
- time_t s0=0, s1=0;
- long ns0=0, ns1=0;
- if (times) {
- ns0 = times[0].tv_nsec;
- ns1 = times[1].tv_nsec;
- if (!NS_SPECIAL(ns0)) s0 = times[0].tv_sec;
- if (!NS_SPECIAL(ns1)) s1 = times[1].tv_sec;
- }
- if (SYS_utimensat == SYS_utimensat_time64 || !IS32BIT(s0) || !IS32BIT(s1))
- r = __syscall(SYS_utimensat_time64, fd, path, times ?
- ((long long[]){s0, ns0, s1, ns1}) : 0, flags);
- if (SYS_utimensat == SYS_utimensat_time64 || r!=-ENOSYS)
- return __syscall_ret(r);
- if (!IS32BIT(s0) || !IS32BIT(s1))
- return __syscall_ret(-ENOTSUP);
- r = __syscall(SYS_utimensat, fd, path,
- times ? ((long[]){s0, ns0, s1, ns1}) : 0, flags);
-#else
- r = __syscall(SYS_utimensat, fd, path, times, flags);
-#endif
-
-#ifdef SYS_futimesat
- if (r != -ENOSYS || flags) return __syscall_ret(r);
- long *tv=0, tmp[4];
- if (times) {
- int i;
- tv = tmp;
- for (i=0; i<2; i++) {
- if (times[i].tv_nsec >= 1000000000ULL) {
- if (NS_SPECIAL(times[i].tv_nsec))
- return __syscall_ret(-ENOSYS);
- return __syscall_ret(-EINVAL);
- }
- tmp[2*i+0] = times[i].tv_sec;
- tmp[2*i+1] = times[i].tv_nsec / 1000;
- }
- }
-
- r = __syscall(SYS_futimesat, fd, path, tv);
- if (r != -ENOSYS || fd != AT_FDCWD) return __syscall_ret(r);
- r = __syscall(SYS_utimes, path, tv);
-#endif
- return __syscall_ret(r);
-}
lib/libc/wasi/libc-top-half/musl/src/stdio/__lockfile.c
@@ -1,23 +0,0 @@
-#include "stdio_impl.h"
-#include "pthread_impl.h"
-
-int __lockfile(FILE *f)
-{
- int owner = f->lock, tid = __pthread_self()->tid;
- if ((owner & ~MAYBE_WAITERS) == tid)
- return 0;
- owner = a_cas(&f->lock, 0, tid);
- if (!owner) return 1;
- while ((owner = a_cas(&f->lock, 0, tid|MAYBE_WAITERS))) {
- if ((owner & MAYBE_WAITERS) ||
- a_cas(&f->lock, owner, owner|MAYBE_WAITERS)==owner)
- __futexwait(&f->lock, owner|MAYBE_WAITERS, 1);
- }
- return 1;
-}
-
-void __unlockfile(FILE *f)
-{
- if (a_swap(&f->lock, 0) & MAYBE_WAITERS)
- __wake(&f->lock, 1, 1);
-}
lib/libc/wasi/libc-top-half/musl/src/stdio/flockfile.c
@@ -1,9 +0,0 @@
-#include "stdio_impl.h"
-#include "pthread_impl.h"
-
-void flockfile(FILE *f)
-{
- if (!ftrylockfile(f)) return;
- __lockfile(f);
- __register_locked_file(f, __pthread_self());
-}
lib/libc/wasi/libc-top-half/musl/src/stdio/ftrylockfile.c
@@ -1,46 +0,0 @@
-#include "stdio_impl.h"
-#include "pthread_impl.h"
-#include <limits.h>
-
-void __do_orphaned_stdio_locks()
-{
- FILE *f;
- for (f=__pthread_self()->stdio_locks; f; f=f->next_locked)
- a_store(&f->lock, 0x40000000);
-}
-
-void __unlist_locked_file(FILE *f)
-{
- if (f->lockcount) {
- if (f->next_locked) f->next_locked->prev_locked = f->prev_locked;
- if (f->prev_locked) f->prev_locked->next_locked = f->next_locked;
- else __pthread_self()->stdio_locks = f->next_locked;
- }
-}
-
-void __register_locked_file(FILE *f, pthread_t self)
-{
- f->lockcount = 1;
- f->prev_locked = 0;
- f->next_locked = self->stdio_locks;
- if (f->next_locked) f->next_locked->prev_locked = f;
- self->stdio_locks = f;
-}
-
-int ftrylockfile(FILE *f)
-{
- pthread_t self = __pthread_self();
- int tid = self->tid;
- int owner = f->lock;
- if ((owner & ~MAYBE_WAITERS) == tid) {
- if (f->lockcount == LONG_MAX)
- return -1;
- f->lockcount++;
- return 0;
- }
- if (owner < 0) f->lock = owner = 0;
- if (owner || a_cas(&f->lock, 0, tid))
- return -1;
- __register_locked_file(f, self);
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/stdio/funlockfile.c
@@ -1,13 +0,0 @@
-#include "stdio_impl.h"
-#include "pthread_impl.h"
-
-void funlockfile(FILE *f)
-{
- if (f->lockcount == 1) {
- __unlist_locked_file(f);
- f->lockcount = 0;
- __unlockfile(f);
- } else {
- f->lockcount--;
- }
-}
lib/libc/wasi/libc-top-half/musl/src/stdio/gets.c
@@ -1,15 +0,0 @@
-#include "stdio_impl.h"
-#include <limits.h>
-#include <string.h>
-
-char *gets(char *s)
-{
- size_t i=0;
- int c;
- FLOCK(stdin);
- while ((c=getc_unlocked(stdin)) != EOF && c != '\n') s[i++] = c;
- s[i] = 0;
- if (c != '\n' && (!feof(stdin) || !i)) s = 0;
- FUNLOCK(stdin);
- return s;
-}
lib/libc/wasi/libc-top-half/musl/src/stdio/pclose.c
@@ -1,13 +0,0 @@
-#include "stdio_impl.h"
-#include <errno.h>
-#include <unistd.h>
-
-int pclose(FILE *f)
-{
- int status, r;
- pid_t pid = f->pipe_pid;
- fclose(f);
- while ((r=__syscall(SYS_wait4, pid, &status, 0, 0)) == -EINTR);
- if (r<0) return __syscall_ret(r);
- return status;
-}
lib/libc/wasi/libc-top-half/musl/src/stdio/popen.c
@@ -1,61 +0,0 @@
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <spawn.h>
-#include "stdio_impl.h"
-#include "syscall.h"
-
-extern char **__environ;
-
-FILE *popen(const char *cmd, const char *mode)
-{
- int p[2], op, e;
- pid_t pid;
- FILE *f;
- posix_spawn_file_actions_t fa;
-
- if (*mode == 'r') {
- op = 0;
- } else if (*mode == 'w') {
- op = 1;
- } else {
- errno = EINVAL;
- return 0;
- }
-
- if (pipe2(p, O_CLOEXEC)) return NULL;
- f = fdopen(p[op], mode);
- if (!f) {
- __syscall(SYS_close, p[0]);
- __syscall(SYS_close, p[1]);
- return NULL;
- }
-
- e = ENOMEM;
- if (!posix_spawn_file_actions_init(&fa)) {
- for (FILE *l = *__ofl_lock(); l; l=l->next)
- if (l->pipe_pid && posix_spawn_file_actions_addclose(&fa, l->fd))
- goto fail;
- if (!posix_spawn_file_actions_adddup2(&fa, p[1-op], 1-op)) {
- if (!(e = posix_spawn(&pid, "/bin/sh", &fa, 0,
- (char *[]){ "sh", "-c", (char *)cmd, 0 }, __environ))) {
- posix_spawn_file_actions_destroy(&fa);
- f->pipe_pid = pid;
- if (!strchr(mode, 'e'))
- fcntl(p[op], F_SETFD, 0);
- __syscall(SYS_close, p[1-op]);
- __ofl_unlock();
- return f;
- }
- }
-fail:
- __ofl_unlock();
- posix_spawn_file_actions_destroy(&fa);
- }
- fclose(f);
- __syscall(SYS_close, p[1-op]);
-
- errno = e;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/stdio/remove.c
@@ -1,19 +0,0 @@
-#include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int remove(const char *path)
-{
-#ifdef SYS_unlink
- int r = __syscall(SYS_unlink, path);
-#else
- int r = __syscall(SYS_unlinkat, AT_FDCWD, path, 0);
-#endif
-#ifdef SYS_rmdir
- if (r==-EISDIR) r = __syscall(SYS_rmdir, path);
-#else
- if (r==-EISDIR) r = __syscall(SYS_unlinkat, AT_FDCWD, path, AT_REMOVEDIR);
-#endif
- return __syscall_ret(r);
-}
lib/libc/wasi/libc-top-half/musl/src/stdio/rename.c
@@ -1,14 +0,0 @@
-#include <stdio.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int rename(const char *old, const char *new)
-{
-#if defined(SYS_rename)
- return syscall(SYS_rename, old, new);
-#elif defined(SYS_renameat)
- return syscall(SYS_renameat, AT_FDCWD, old, AT_FDCWD, new);
-#else
- return syscall(SYS_renameat2, AT_FDCWD, old, AT_FDCWD, new, 0);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/stdio/tempnam.c
@@ -1,49 +0,0 @@
-#include <stdio.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <limits.h>
-#include <string.h>
-#include <stdlib.h>
-#include "syscall.h"
-#include "kstat.h"
-
-#define MAXTRIES 100
-
-char *tempnam(const char *dir, const char *pfx)
-{
- char s[PATH_MAX];
- size_t l, dl, pl;
- int try;
- int r;
-
- if (!dir) dir = P_tmpdir;
- if (!pfx) pfx = "temp";
-
- dl = strlen(dir);
- pl = strlen(pfx);
- l = dl + 1 + pl + 1 + 6;
-
- if (l >= PATH_MAX) {
- errno = ENAMETOOLONG;
- return 0;
- }
-
- memcpy(s, dir, dl);
- s[dl] = '/';
- memcpy(s+dl+1, pfx, pl);
- s[dl+1+pl] = '_';
- s[l] = 0;
-
- for (try=0; try<MAXTRIES; try++) {
- __randname(s+l-6);
-#ifdef SYS_lstat
- r = __syscall(SYS_lstat, s, &(struct kstat){0});
-#else
- r = __syscall(SYS_fstatat, AT_FDCWD, s,
- &(struct kstat){0}, AT_SYMLINK_NOFOLLOW);
-#endif
- if (r == -ENOENT) return strdup(s);
- }
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/stdio/tmpfile.c
@@ -1,31 +0,0 @@
-#include <stdio.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include "stdio_impl.h"
-
-#define MAXTRIES 100
-
-FILE *tmpfile(void)
-{
- char s[] = "/tmp/tmpfile_XXXXXX";
- int fd;
- FILE *f;
- int try;
- for (try=0; try<MAXTRIES; try++) {
- __randname(s+13);
- fd = sys_open(s, O_RDWR|O_CREAT|O_EXCL, 0600);
- if (fd >= 0) {
-#ifdef SYS_unlink
- __syscall(SYS_unlink, s);
-#else
- __syscall(SYS_unlinkat, AT_FDCWD, s, 0);
-#endif
- f = __fdopen(fd, "w+");
- if (!f) __syscall(SYS_close, fd);
- return f;
- }
- }
- return 0;
-}
-
-weak_alias(tmpfile, tmpfile64);
lib/libc/wasi/libc-top-half/musl/src/stdio/tmpnam.c
@@ -1,29 +0,0 @@
-#include <stdio.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <stdlib.h>
-#include "syscall.h"
-#include "kstat.h"
-
-#define MAXTRIES 100
-
-char *tmpnam(char *buf)
-{
- static char internal[L_tmpnam];
- char s[] = "/tmp/tmpnam_XXXXXX";
- int try;
- int r;
- for (try=0; try<MAXTRIES; try++) {
- __randname(s+12);
-#ifdef SYS_lstat
- r = __syscall(SYS_lstat, s, &(struct kstat){0});
-#else
- r = __syscall(SYS_fstatat, AT_FDCWD, s,
- &(struct kstat){0}, AT_SYMLINK_NOFOLLOW);
-#endif
- if (r == -ENOENT) return strcpy(buf ? buf : internal, s);
- }
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/string/arm/__aeabi_memcpy.s
@@ -1,45 +0,0 @@
-.syntax unified
-
-.global __aeabi_memcpy8
-.global __aeabi_memcpy4
-.global __aeabi_memcpy
-.global __aeabi_memmove8
-.global __aeabi_memmove4
-.global __aeabi_memmove
-
-.type __aeabi_memcpy8,%function
-.type __aeabi_memcpy4,%function
-.type __aeabi_memcpy,%function
-.type __aeabi_memmove8,%function
-.type __aeabi_memmove4,%function
-.type __aeabi_memmove,%function
-
-__aeabi_memmove8:
-__aeabi_memmove4:
-__aeabi_memmove:
- cmp r0, r1
- bls 3f
- cmp r2, #0
- beq 2f
- adds r0, r0, r2
- adds r2, r1, r2
-1: subs r2, r2, #1
- ldrb r3, [r2]
- subs r0, r0, #1
- strb r3, [r0]
- cmp r1, r2
- bne 1b
-2: bx lr
-__aeabi_memcpy8:
-__aeabi_memcpy4:
-__aeabi_memcpy:
-3: cmp r2, #0
- beq 2f
- adds r2, r1, r2
-1: ldrb r3, [r1]
- adds r1, r1, #1
- strb r3, [r0]
- adds r0, r0, #1
- cmp r1, r2
- bne 1b
-2: bx lr
lib/libc/wasi/libc-top-half/musl/src/string/arm/__aeabi_memset.s
@@ -1,31 +0,0 @@
-.syntax unified
-
-.global __aeabi_memclr8
-.global __aeabi_memclr4
-.global __aeabi_memclr
-.global __aeabi_memset8
-.global __aeabi_memset4
-.global __aeabi_memset
-
-.type __aeabi_memclr8,%function
-.type __aeabi_memclr4,%function
-.type __aeabi_memclr,%function
-.type __aeabi_memset8,%function
-.type __aeabi_memset4,%function
-.type __aeabi_memset,%function
-
-__aeabi_memclr8:
-__aeabi_memclr4:
-__aeabi_memclr:
- movs r2, #0
-__aeabi_memset8:
-__aeabi_memset4:
-__aeabi_memset:
- cmp r1, #0
- beq 2f
- adds r1, r0, r1
-1: strb r2, [r0]
- adds r0, r0, #1
- cmp r1, r0
- bne 1b
-2: bx lr
lib/libc/wasi/libc-top-half/musl/src/string/i386/memcpy.s
@@ -1,32 +0,0 @@
-.global memcpy
-.global __memcpy_fwd
-.hidden __memcpy_fwd
-.type memcpy,@function
-memcpy:
-__memcpy_fwd:
- push %esi
- push %edi
- mov 12(%esp),%edi
- mov 16(%esp),%esi
- mov 20(%esp),%ecx
- mov %edi,%eax
- cmp $4,%ecx
- jc 1f
- test $3,%edi
- jz 1f
-2: movsb
- dec %ecx
- test $3,%edi
- jnz 2b
-1: mov %ecx,%edx
- shr $2,%ecx
- rep
- movsl
- and $3,%edx
- jz 1f
-2: movsb
- dec %edx
- jnz 2b
-1: pop %edi
- pop %esi
- ret
lib/libc/wasi/libc-top-half/musl/src/string/i386/memmove.s
@@ -1,22 +0,0 @@
-.global memmove
-.type memmove,@function
-memmove:
- mov 4(%esp),%eax
- sub 8(%esp),%eax
- cmp 12(%esp),%eax
-.hidden __memcpy_fwd
- jae __memcpy_fwd
- push %esi
- push %edi
- mov 12(%esp),%edi
- mov 16(%esp),%esi
- mov 20(%esp),%ecx
- lea -1(%edi,%ecx),%edi
- lea -1(%esi,%ecx),%esi
- std
- rep movsb
- cld
- lea 1(%edi),%eax
- pop %edi
- pop %esi
- ret
lib/libc/wasi/libc-top-half/musl/src/string/i386/memset.s
@@ -1,76 +0,0 @@
-.global memset
-.type memset,@function
-memset:
- mov 12(%esp),%ecx
- cmp $62,%ecx
- ja 2f
-
- mov 8(%esp),%dl
- mov 4(%esp),%eax
- test %ecx,%ecx
- jz 1f
-
- mov %dl,%dh
-
- mov %dl,(%eax)
- mov %dl,-1(%eax,%ecx)
- cmp $2,%ecx
- jbe 1f
-
- mov %dx,1(%eax)
- mov %dx,(-1-2)(%eax,%ecx)
- cmp $6,%ecx
- jbe 1f
-
- shl $16,%edx
- mov 8(%esp),%dl
- mov 8(%esp),%dh
-
- mov %edx,(1+2)(%eax)
- mov %edx,(-1-2-4)(%eax,%ecx)
- cmp $14,%ecx
- jbe 1f
-
- mov %edx,(1+2+4)(%eax)
- mov %edx,(1+2+4+4)(%eax)
- mov %edx,(-1-2-4-8)(%eax,%ecx)
- mov %edx,(-1-2-4-4)(%eax,%ecx)
- cmp $30,%ecx
- jbe 1f
-
- mov %edx,(1+2+4+8)(%eax)
- mov %edx,(1+2+4+8+4)(%eax)
- mov %edx,(1+2+4+8+8)(%eax)
- mov %edx,(1+2+4+8+12)(%eax)
- mov %edx,(-1-2-4-8-16)(%eax,%ecx)
- mov %edx,(-1-2-4-8-12)(%eax,%ecx)
- mov %edx,(-1-2-4-8-8)(%eax,%ecx)
- mov %edx,(-1-2-4-8-4)(%eax,%ecx)
-
-1: ret
-
-2: movzbl 8(%esp),%eax
- mov %edi,12(%esp)
- imul $0x1010101,%eax
- mov 4(%esp),%edi
- test $15,%edi
- mov %eax,-4(%edi,%ecx)
- jnz 2f
-
-1: shr $2, %ecx
- rep
- stosl
- mov 4(%esp),%eax
- mov 12(%esp),%edi
- ret
-
-2: xor %edx,%edx
- sub %edi,%edx
- and $15,%edx
- mov %eax,(%edi)
- mov %eax,4(%edi)
- mov %eax,8(%edi)
- mov %eax,12(%edi)
- sub %edx,%ecx
- add %edx,%edi
- jmp 1b
lib/libc/wasi/libc-top-half/musl/src/string/x86_64/memcpy.s
@@ -1,25 +0,0 @@
-.global memcpy
-.global __memcpy_fwd
-.hidden __memcpy_fwd
-.type memcpy,@function
-memcpy:
-__memcpy_fwd:
- mov %rdi,%rax
- cmp $8,%rdx
- jc 1f
- test $7,%edi
- jz 1f
-2: movsb
- dec %rdx
- test $7,%edi
- jnz 2b
-1: mov %rdx,%rcx
- shr $3,%rcx
- rep
- movsq
- and $7,%edx
- jz 1f
-2: movsb
- dec %edx
- jnz 2b
-1: ret
lib/libc/wasi/libc-top-half/musl/src/string/x86_64/memmove.s
@@ -1,16 +0,0 @@
-.global memmove
-.type memmove,@function
-memmove:
- mov %rdi,%rax
- sub %rsi,%rax
- cmp %rdx,%rax
-.hidden __memcpy_fwd
- jae __memcpy_fwd
- mov %rdx,%rcx
- lea -1(%rdi,%rdx),%rdi
- lea -1(%rsi,%rdx),%rsi
- std
- rep movsb
- cld
- lea 1(%rdi),%rax
- ret
lib/libc/wasi/libc-top-half/musl/src/string/x86_64/memset.s
@@ -1,72 +0,0 @@
-.global memset
-.type memset,@function
-memset:
- movzbq %sil,%rax
- mov $0x101010101010101,%r8
- imul %r8,%rax
-
- cmp $126,%rdx
- ja 2f
-
- test %edx,%edx
- jz 1f
-
- mov %sil,(%rdi)
- mov %sil,-1(%rdi,%rdx)
- cmp $2,%edx
- jbe 1f
-
- mov %ax,1(%rdi)
- mov %ax,(-1-2)(%rdi,%rdx)
- cmp $6,%edx
- jbe 1f
-
- mov %eax,(1+2)(%rdi)
- mov %eax,(-1-2-4)(%rdi,%rdx)
- cmp $14,%edx
- jbe 1f
-
- mov %rax,(1+2+4)(%rdi)
- mov %rax,(-1-2-4-8)(%rdi,%rdx)
- cmp $30,%edx
- jbe 1f
-
- mov %rax,(1+2+4+8)(%rdi)
- mov %rax,(1+2+4+8+8)(%rdi)
- mov %rax,(-1-2-4-8-16)(%rdi,%rdx)
- mov %rax,(-1-2-4-8-8)(%rdi,%rdx)
- cmp $62,%edx
- jbe 1f
-
- mov %rax,(1+2+4+8+16)(%rdi)
- mov %rax,(1+2+4+8+16+8)(%rdi)
- mov %rax,(1+2+4+8+16+16)(%rdi)
- mov %rax,(1+2+4+8+16+24)(%rdi)
- mov %rax,(-1-2-4-8-16-32)(%rdi,%rdx)
- mov %rax,(-1-2-4-8-16-24)(%rdi,%rdx)
- mov %rax,(-1-2-4-8-16-16)(%rdi,%rdx)
- mov %rax,(-1-2-4-8-16-8)(%rdi,%rdx)
-
-1: mov %rdi,%rax
- ret
-
-2: test $15,%edi
- mov %rdi,%r8
- mov %rax,-8(%rdi,%rdx)
- mov %rdx,%rcx
- jnz 2f
-
-1: shr $3,%rcx
- rep
- stosq
- mov %r8,%rax
- ret
-
-2: xor %edx,%edx
- sub %edi,%edx
- and $15,%edx
- mov %rax,(%rdi)
- mov %rax,8(%rdi)
- sub %rdx,%rcx
- add %rdx,%rdi
- jmp 1b
lib/libc/wasi/libc-top-half/musl/src/temp/__randname.c
@@ -1,18 +0,0 @@
-#include <time.h>
-#include <stdint.h>
-
-/* This assumes that a check for the
- template size has already been made */
-char *__randname(char *template)
-{
- int i;
- struct timespec ts;
- unsigned long r;
-
- __clock_gettime(CLOCK_REALTIME, &ts);
- r = ts.tv_nsec*65537 ^ (uintptr_t)&ts / 16 + (uintptr_t)template;
- for (i=0; i<6; i++, r>>=5)
- template[i] = 'A'+(r&15)+(r&16)*2;
-
- return template;
-}
lib/libc/wasi/libc-top-half/musl/src/temp/mkdtemp.c
@@ -1,23 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/stat.h>
-
-char *mkdtemp(char *template)
-{
- size_t l = strlen(template);
- int retries = 100;
-
- if (l<6 || memcmp(template+l-6, "XXXXXX", 6)) {
- errno = EINVAL;
- return 0;
- }
-
- do {
- __randname(template+l-6);
- if (!mkdir(template, 0700)) return template;
- } while (--retries && errno == EEXIST);
-
- memcpy(template+l-6, "XXXXXX", 6);
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/temp/mkostemp.c
@@ -1,9 +0,0 @@
-#define _BSD_SOURCE
-#include <stdlib.h>
-
-int mkostemp(char *template, int flags)
-{
- return __mkostemps(template, 0, flags);
-}
-
-weak_alias(mkostemp, mkostemp64);
lib/libc/wasi/libc-top-half/musl/src/temp/mkostemps.c
@@ -1,29 +0,0 @@
-#define _BSD_SOURCE
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-
-int __mkostemps(char *template, int len, int flags)
-{
- size_t l = strlen(template);
- if (l<6 || len>l-6 || memcmp(template+l-len-6, "XXXXXX", 6)) {
- errno = EINVAL;
- return -1;
- }
-
- flags -= flags & O_ACCMODE;
- int fd, retries = 100;
- do {
- __randname(template+l-len-6);
- if ((fd = open(template, flags | O_RDWR | O_CREAT | O_EXCL, 0600))>=0)
- return fd;
- } while (--retries && errno == EEXIST);
-
- memcpy(template+l-len-6, "XXXXXX", 6);
- return -1;
-}
-
-weak_alias(__mkostemps, mkostemps);
-weak_alias(__mkostemps, mkostemps64);
lib/libc/wasi/libc-top-half/musl/src/temp/mkstemp.c
@@ -1,8 +0,0 @@
-#include <stdlib.h>
-
-int mkstemp(char *template)
-{
- return __mkostemps(template, 0, 0);
-}
-
-weak_alias(mkstemp, mkstemp64);
lib/libc/wasi/libc-top-half/musl/src/temp/mkstemps.c
@@ -1,9 +0,0 @@
-#define _BSD_SOURCE
-#include <stdlib.h>
-
-int mkstemps(char *template, int len)
-{
- return __mkostemps(template, len, 0);
-}
-
-weak_alias(mkstemps, mkstemps64);
lib/libc/wasi/libc-top-half/musl/src/temp/mktemp.c
@@ -1,30 +0,0 @@
-#define _GNU_SOURCE
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/stat.h>
-
-char *mktemp(char *template)
-{
- size_t l = strlen(template);
- int retries = 100;
- struct stat st;
-
- if (l < 6 || memcmp(template+l-6, "XXXXXX", 6)) {
- errno = EINVAL;
- *template = 0;
- return template;
- }
-
- do {
- __randname(template+l-6);
- if (stat(template, &st)) {
- if (errno != ENOENT) *template = 0;
- return template;
- }
- } while (--retries);
-
- *template = 0;
- errno = EEXIST;
- return template;
-}
lib/libc/wasi/libc-top-half/musl/src/termios/cfgetospeed.c
@@ -1,13 +0,0 @@
-#define _BSD_SOURCE
-#include <termios.h>
-#include <sys/ioctl.h>
-
-speed_t cfgetospeed(const struct termios *tio)
-{
- return tio->c_cflag & CBAUD;
-}
-
-speed_t cfgetispeed(const struct termios *tio)
-{
- return cfgetospeed(tio);
-}
lib/libc/wasi/libc-top-half/musl/src/termios/cfmakeraw.c
@@ -1,13 +0,0 @@
-#define _GNU_SOURCE
-#include <termios.h>
-
-void cfmakeraw(struct termios *t)
-{
- t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
- t->c_oflag &= ~OPOST;
- t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
- t->c_cflag &= ~(CSIZE|PARENB);
- t->c_cflag |= CS8;
- t->c_cc[VMIN] = 1;
- t->c_cc[VTIME] = 0;
-}
lib/libc/wasi/libc-top-half/musl/src/termios/cfsetospeed.c
@@ -1,22 +0,0 @@
-#define _BSD_SOURCE
-#include <termios.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-
-int cfsetospeed(struct termios *tio, speed_t speed)
-{
- if (speed & ~CBAUD) {
- errno = EINVAL;
- return -1;
- }
- tio->c_cflag &= ~CBAUD;
- tio->c_cflag |= speed;
- return 0;
-}
-
-int cfsetispeed(struct termios *tio, speed_t speed)
-{
- return speed ? cfsetospeed(tio, speed) : 0;
-}
-
-weak_alias(cfsetospeed, cfsetspeed);
lib/libc/wasi/libc-top-half/musl/src/termios/tcdrain.c
@@ -1,8 +0,0 @@
-#include <termios.h>
-#include <sys/ioctl.h>
-#include "syscall.h"
-
-int tcdrain(int fd)
-{
- return syscall_cp(SYS_ioctl, fd, TCSBRK, 1);
-}
lib/libc/wasi/libc-top-half/musl/src/termios/tcflow.c
@@ -1,7 +0,0 @@
-#include <termios.h>
-#include <sys/ioctl.h>
-
-int tcflow(int fd, int action)
-{
- return ioctl(fd, TCXONC, action);
-}
lib/libc/wasi/libc-top-half/musl/src/termios/tcflush.c
@@ -1,7 +0,0 @@
-#include <termios.h>
-#include <sys/ioctl.h>
-
-int tcflush(int fd, int queue)
-{
- return ioctl(fd, TCFLSH, queue);
-}
lib/libc/wasi/libc-top-half/musl/src/termios/tcgetattr.c
@@ -1,9 +0,0 @@
-#include <termios.h>
-#include <sys/ioctl.h>
-
-int tcgetattr(int fd, struct termios *tio)
-{
- if (ioctl(fd, TCGETS, tio))
- return -1;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/termios/tcgetsid.c
@@ -1,10 +0,0 @@
-#include <termios.h>
-#include <sys/ioctl.h>
-
-pid_t tcgetsid(int fd)
-{
- int sid;
- if (ioctl(fd, TIOCGSID, &sid) < 0)
- return -1;
- return sid;
-}
lib/libc/wasi/libc-top-half/musl/src/termios/tcgetwinsize.c
@@ -1,8 +0,0 @@
-#include <termios.h>
-#include <sys/ioctl.h>
-#include "syscall.h"
-
-int tcgetwinsize(int fd, struct winsize *wsz)
-{
- return syscall(SYS_ioctl, fd, TIOCGWINSZ, wsz);
-}
lib/libc/wasi/libc-top-half/musl/src/termios/tcsendbreak.c
@@ -1,8 +0,0 @@
-#include <termios.h>
-#include <sys/ioctl.h>
-
-int tcsendbreak(int fd, int dur)
-{
- /* nonzero duration is implementation-defined, so ignore it */
- return ioctl(fd, TCSBRK, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/termios/tcsetattr.c
@@ -1,12 +0,0 @@
-#include <termios.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-
-int tcsetattr(int fd, int act, const struct termios *tio)
-{
- if (act < 0 || act > 2) {
- errno = EINVAL;
- return -1;
- }
- return ioctl(fd, TCSETS+act, tio);
-}
lib/libc/wasi/libc-top-half/musl/src/termios/tcsetwinsize.c
@@ -1,8 +0,0 @@
-#include <termios.h>
-#include <sys/ioctl.h>
-#include "syscall.h"
-
-int tcsetwinsize(int fd, const struct winsize *wsz)
-{
- return syscall(SYS_ioctl, fd, TIOCSWINSZ, wsz);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/aarch64/__set_thread_area.s
@@ -1,7 +0,0 @@
-.global __set_thread_area
-.hidden __set_thread_area
-.type __set_thread_area,@function
-__set_thread_area:
- msr tpidr_el0,x0
- mov w0,#0
- ret
lib/libc/wasi/libc-top-half/musl/src/thread/aarch64/__unmapself.s
@@ -1,7 +0,0 @@
-.global __unmapself
-.type __unmapself,%function
-__unmapself:
- mov x8,#215 // SYS_munmap
- svc 0
- mov x8,#93 // SYS_exit
- svc 0
lib/libc/wasi/libc-top-half/musl/src/thread/aarch64/clone.s
@@ -1,30 +0,0 @@
-// __clone(func, stack, flags, arg, ptid, tls, ctid)
-// x0, x1, w2, x3, x4, x5, x6
-
-// syscall(SYS_clone, flags, stack, ptid, tls, ctid)
-// x8, x0, x1, x2, x3, x4
-
-.global __clone
-.hidden __clone
-.type __clone,%function
-__clone:
- // align stack and save func,arg
- and x1,x1,#-16
- stp x0,x3,[x1,#-16]!
-
- // syscall
- uxtw x0,w2
- mov x2,x4
- mov x3,x5
- mov x4,x6
- mov x8,#220 // SYS_clone
- svc #0
-
- cbz x0,1f
- // parent
- ret
- // child
-1: ldp x1,x0,[sp],#16
- blr x1
- mov x8,#93 // SYS_exit
- svc #0
lib/libc/wasi/libc-top-half/musl/src/thread/aarch64/syscall_cp.s
@@ -1,32 +0,0 @@
-// __syscall_cp_asm(&self->cancel, nr, u, v, w, x, y, z)
-// x0 x1 x2 x3 x4 x5 x6 x7
-
-// syscall(nr, u, v, w, x, y, z)
-// x8 x0 x1 x2 x3 x4 x5
-
-.global __cp_begin
-.hidden __cp_begin
-.global __cp_end
-.hidden __cp_end
-.global __cp_cancel
-.hidden __cp_cancel
-.hidden __cancel
-.global __syscall_cp_asm
-.hidden __syscall_cp_asm
-.type __syscall_cp_asm,%function
-__syscall_cp_asm:
-__cp_begin:
- ldr w0,[x0]
- cbnz w0,__cp_cancel
- mov x8,x1
- mov x0,x2
- mov x1,x3
- mov x2,x4
- mov x3,x5
- mov x4,x6
- mov x5,x7
- svc 0
-__cp_end:
- ret
-__cp_cancel:
- b __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/arm/__aeabi_read_tp.s
@@ -1,10 +0,0 @@
-.syntax unified
-.global __aeabi_read_tp
-.type __aeabi_read_tp,%function
-__aeabi_read_tp:
- ldr r0,1f
- add r0,r0,pc
- ldr r0,[r0]
-2: bx r0
- .align 2
-1: .word __a_gettp_ptr - 2b
lib/libc/wasi/libc-top-half/musl/src/thread/arm/__set_thread_area.c
@@ -1,52 +0,0 @@
-#include <stdint.h>
-#include <elf.h>
-#include "pthread_impl.h"
-#include "libc.h"
-
-#define HWCAP_TLS (1 << 15)
-
-extern hidden const unsigned char
- __a_barrier_oldkuser[], __a_barrier_v6[], __a_barrier_v7[],
- __a_cas_v6[], __a_cas_v7[],
- __a_gettp_cp15[];
-
-#define __a_barrier_kuser 0xffff0fa0
-#define __a_barrier_oldkuser (uintptr_t)__a_barrier_oldkuser
-#define __a_barrier_v6 (uintptr_t)__a_barrier_v6
-#define __a_barrier_v7 (uintptr_t)__a_barrier_v7
-
-#define __a_cas_kuser 0xffff0fc0
-#define __a_cas_v6 (uintptr_t)__a_cas_v6
-#define __a_cas_v7 (uintptr_t)__a_cas_v7
-
-#define __a_gettp_kuser 0xffff0fe0
-#define __a_gettp_cp15 (uintptr_t)__a_gettp_cp15
-
-extern hidden uintptr_t __a_barrier_ptr, __a_cas_ptr, __a_gettp_ptr;
-
-int __set_thread_area(void *p)
-{
-#if !__ARM_ARCH_7A__ && !__ARM_ARCH_7R__ && __ARM_ARCH < 7
- if (__hwcap & HWCAP_TLS) {
- size_t *aux;
- __a_cas_ptr = __a_cas_v7;
- __a_barrier_ptr = __a_barrier_v7;
- for (aux=libc.auxv; *aux; aux+=2) {
- if (*aux != AT_PLATFORM) continue;
- const char *s = (void *)aux[1];
- if (s[0]!='v' || s[1]!='6' || s[2]-'0'<10u) break;
- __a_cas_ptr = __a_cas_v6;
- __a_barrier_ptr = __a_barrier_v6;
- break;
- }
- } else {
- int ver = *(int *)0xffff0ffc;
- __a_gettp_ptr = __a_gettp_kuser;
- __a_cas_ptr = __a_cas_kuser;
- __a_barrier_ptr = __a_barrier_kuser;
- if (ver < 2) a_crash();
- if (ver < 3) __a_barrier_ptr = __a_barrier_oldkuser;
- }
-#endif
- return __syscall(0xf0005, p);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/arm/__unmapself.s
@@ -1,9 +0,0 @@
-.syntax unified
-.text
-.global __unmapself
-.type __unmapself,%function
-__unmapself:
- mov r7,#91
- svc 0
- mov r7,#1
- svc 0
lib/libc/wasi/libc-top-half/musl/src/thread/arm/atomics.s
@@ -1,106 +0,0 @@
-.syntax unified
-.text
-
-.global __a_barrier_dummy
-.hidden __a_barrier_dummy
-.type __a_barrier_dummy,%function
-__a_barrier_dummy:
- bx lr
-
-.global __a_barrier_oldkuser
-.hidden __a_barrier_oldkuser
-.type __a_barrier_oldkuser,%function
-__a_barrier_oldkuser:
- push {r0,r1,r2,r3,ip,lr}
- mov r1,r0
- mov r2,sp
- ldr ip,=0xffff0fc0
- bl 1f
- pop {r0,r1,r2,r3,ip,lr}
- bx lr
-1: bx ip
-
-.global __a_barrier_v6
-.hidden __a_barrier_v6
-.type __a_barrier_v6,%function
-__a_barrier_v6:
- .arch armv6t2
- mcr p15,0,r0,c7,c10,5
- bx lr
-
-.global __a_barrier_v7
-.hidden __a_barrier_v7
-.type __a_barrier_v7,%function
-__a_barrier_v7:
- .arch armv7-a
- dmb ish
- bx lr
-
-.global __a_cas_dummy
-.hidden __a_cas_dummy
-.type __a_cas_dummy,%function
-__a_cas_dummy:
- mov r3,r0
- ldr r0,[r2]
- subs r0,r3,r0
- streq r1,[r2]
- bx lr
-
-.global __a_cas_v6
-.hidden __a_cas_v6
-.type __a_cas_v6,%function
-__a_cas_v6:
- .arch armv6t2
- mov r3,r0
- mcr p15,0,r0,c7,c10,5
-1: ldrex r0,[r2]
- subs r0,r3,r0
- strexeq r0,r1,[r2]
- teqeq r0,#1
- beq 1b
- mcr p15,0,r0,c7,c10,5
- bx lr
-
-.global __a_cas_v7
-.hidden __a_cas_v7
-.type __a_cas_v7,%function
-__a_cas_v7:
- .arch armv7-a
- mov r3,r0
- dmb ish
-1: ldrex r0,[r2]
- subs r0,r3,r0
- strexeq r0,r1,[r2]
- teqeq r0,#1
- beq 1b
- dmb ish
- bx lr
-
-.global __a_gettp_cp15
-.hidden __a_gettp_cp15
-.type __a_gettp_cp15,%function
-__a_gettp_cp15:
- mrc p15,0,r0,c13,c0,3
- bx lr
-
-/* Tag this file with minimum ISA level so as not to affect linking. */
-.object_arch armv4t
-.eabi_attribute 6,2
-
-.data
-.align 2
-
-.global __a_barrier_ptr
-.hidden __a_barrier_ptr
-__a_barrier_ptr:
- .word __a_barrier_dummy
-
-.global __a_cas_ptr
-.hidden __a_cas_ptr
-__a_cas_ptr:
- .word __a_cas_dummy
-
-.global __a_gettp_ptr
-.hidden __a_gettp_ptr
-__a_gettp_ptr:
- .word __a_gettp_cp15
lib/libc/wasi/libc-top-half/musl/src/thread/arm/clone.s
@@ -1,28 +0,0 @@
-.syntax unified
-.text
-.global __clone
-.hidden __clone
-.type __clone,%function
-__clone:
- stmfd sp!,{r4,r5,r6,r7}
- mov r7,#120
- mov r6,r3
- mov r5,r0
- mov r0,r2
- and r1,r1,#-16
- ldr r2,[sp,#16]
- ldr r3,[sp,#20]
- ldr r4,[sp,#24]
- svc 0
- tst r0,r0
- beq 1f
- ldmfd sp!,{r4,r5,r6,r7}
- bx lr
-
-1: mov r0,r6
- bl 3f
-2: mov r7,#1
- svc 0
- b 2b
-
-3: bx r5
lib/libc/wasi/libc-top-half/musl/src/thread/arm/syscall_cp.s
@@ -1,29 +0,0 @@
-.syntax unified
-.global __cp_begin
-.hidden __cp_begin
-.global __cp_end
-.hidden __cp_end
-.global __cp_cancel
-.hidden __cp_cancel
-.hidden __cancel
-.global __syscall_cp_asm
-.hidden __syscall_cp_asm
-.type __syscall_cp_asm,%function
-__syscall_cp_asm:
- mov ip,sp
- stmfd sp!,{r4,r5,r6,r7}
-__cp_begin:
- ldr r0,[r0]
- cmp r0,#0
- bne __cp_cancel
- mov r7,r1
- mov r0,r2
- mov r1,r3
- ldmfd ip,{r2,r3,r4,r5,r6}
- svc 0
-__cp_end:
- ldmfd sp!,{r4,r5,r6,r7}
- bx lr
-__cp_cancel:
- ldmfd sp!,{r4,r5,r6,r7}
- b __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/i386/__set_thread_area.s
@@ -1,47 +0,0 @@
-.text
-.global __set_thread_area
-.hidden __set_thread_area
-.type __set_thread_area,@function
-__set_thread_area:
- push %ebx
- push $0x51
- push $0xfffff
- push 16(%esp)
- call 1f
-1: addl $4f-1b,(%esp)
- pop %ecx
- mov (%ecx),%edx
- push %edx
- mov %esp,%ebx
- xor %eax,%eax
- mov $243,%al
- int $128
- testl %eax,%eax
- jnz 2f
- movl (%esp),%edx
- movl %edx,(%ecx)
- leal 3(,%edx,8),%edx
-3: movw %dx,%gs
-1:
- addl $16,%esp
- popl %ebx
- ret
-2:
- mov %ebx,%ecx
- xor %eax,%eax
- xor %ebx,%ebx
- xor %edx,%edx
- mov %ebx,(%esp)
- mov $1,%bl
- mov $16,%dl
- mov $123,%al
- int $128
- testl %eax,%eax
- jnz 1b
- mov $7,%dl
- inc %al
- jmp 3b
-
-.data
- .align 4
-4: .long -1
lib/libc/wasi/libc-top-half/musl/src/thread/i386/__unmapself.s
@@ -1,11 +0,0 @@
-.text
-.global __unmapself
-.type __unmapself,@function
-__unmapself:
- movl $91,%eax
- movl 4(%esp),%ebx
- movl 8(%esp),%ecx
- int $128
- xorl %ebx,%ebx
- movl $1,%eax
- int $128
lib/libc/wasi/libc-top-half/musl/src/thread/i386/clone.s
@@ -1,49 +0,0 @@
-.text
-.global __clone
-.hidden __clone
-.type __clone,@function
-__clone:
- push %ebp
- mov %esp,%ebp
- push %ebx
- push %esi
- push %edi
-
- xor %eax,%eax
- push $0x51
- mov %gs,%ax
- push $0xfffff
- shr $3,%eax
- push 28(%ebp)
- push %eax
- mov $120,%al
-
- mov 12(%ebp),%ecx
- mov 16(%ebp),%ebx
- and $-16,%ecx
- sub $16,%ecx
- mov 20(%ebp),%edi
- mov %edi,(%ecx)
- mov 24(%ebp),%edx
- mov %esp,%esi
- mov 32(%ebp),%edi
- mov 8(%ebp),%ebp
- int $128
- test %eax,%eax
- jnz 1f
-
- mov %ebp,%eax
- xor %ebp,%ebp
- call *%eax
- mov %eax,%ebx
- xor %eax,%eax
- inc %eax
- int $128
- hlt
-
-1: add $16,%esp
- pop %edi
- pop %esi
- pop %ebx
- pop %ebp
- ret
lib/libc/wasi/libc-top-half/musl/src/thread/i386/syscall_cp.s
@@ -1,41 +0,0 @@
-.text
-.global __cp_begin
-.hidden __cp_begin
-.global __cp_end
-.hidden __cp_end
-.global __cp_cancel
-.hidden __cp_cancel
-.hidden __cancel
-.global __syscall_cp_asm
-.hidden __syscall_cp_asm
-.type __syscall_cp_asm,@function
-__syscall_cp_asm:
- mov 4(%esp),%ecx
- pushl %ebx
- pushl %esi
- pushl %edi
- pushl %ebp
-__cp_begin:
- movl (%ecx),%eax
- testl %eax,%eax
- jnz __cp_cancel
- movl 24(%esp),%eax
- movl 28(%esp),%ebx
- movl 32(%esp),%ecx
- movl 36(%esp),%edx
- movl 40(%esp),%esi
- movl 44(%esp),%edi
- movl 48(%esp),%ebp
- int $128
-__cp_end:
- popl %ebp
- popl %edi
- popl %esi
- popl %ebx
- ret
-__cp_cancel:
- popl %ebp
- popl %edi
- popl %esi
- popl %ebx
- jmp __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/i386/tls.s
@@ -1,9 +0,0 @@
-.text
-.global ___tls_get_addr
-.type ___tls_get_addr,@function
-___tls_get_addr:
- mov %gs:4,%edx
- mov (%eax),%ecx
- mov 4(%eax),%eax
- add (%edx,%ecx,4),%eax
- ret
lib/libc/wasi/libc-top-half/musl/src/thread/m68k/__m68k_read_tp.s
@@ -1,8 +0,0 @@
-.text
-.global __m68k_read_tp
-.type __m68k_read_tp,@function
-__m68k_read_tp:
- move.l #333,%d0
- trap #0
- move.l %d0,%a0
- rts
lib/libc/wasi/libc-top-half/musl/src/thread/m68k/clone.s
@@ -1,25 +0,0 @@
-.text
-.global __clone
-.hidden __clone
-.type __clone,@function
-__clone:
- movem.l %d2-%d5,-(%sp)
- move.l #120,%d0
- move.l 28(%sp),%d1
- move.l 24(%sp),%d2
- and.l #-16,%d2
- move.l 36(%sp),%d3
- move.l 44(%sp),%d4
- move.l 40(%sp),%d5
- move.l 20(%sp),%a0
- move.l 32(%sp),%a1
- trap #0
- tst.l %d0
- beq 1f
- movem.l (%sp)+,%d2-%d5
- rts
-1: move.l %a1,-(%sp)
- jsr (%a0)
- move.l #1,%d0
- trap #0
- clr.b 0
lib/libc/wasi/libc-top-half/musl/src/thread/m68k/syscall_cp.s
@@ -1,26 +0,0 @@
-.text
-.global __cp_begin
-.hidden __cp_begin
-.global __cp_end
-.hidden __cp_end
-.global __cp_cancel
-.hidden __cp_cancel
-.hidden __cancel
-.global __syscall_cp_asm
-.hidden __syscall_cp_asm
-.type __syscall_cp_asm,@function
-__syscall_cp_asm:
- movem.l %d2-%d5,-(%sp)
- movea.l 20(%sp),%a0
-__cp_begin:
- move.l (%a0),%d0
- bne __cp_cancel
- movem.l 24(%sp),%d0-%d5/%a0
- trap #0
-__cp_end:
- movem.l (%sp)+,%d2-%d5
- rts
-__cp_cancel:
- movem.l (%sp)+,%d2-%d5
- move.l __cancel-.-8,%a1
- jmp (%pc,%a1)
lib/libc/wasi/libc-top-half/musl/src/thread/microblaze/__set_thread_area.s
@@ -1,7 +0,0 @@
-.global __set_thread_area
-.hidden __set_thread_area
-.type __set_thread_area,@function
-__set_thread_area:
- ori r21, r5, 0
- rtsd r15, 8
- ori r3, r0, 0
lib/libc/wasi/libc-top-half/musl/src/thread/microblaze/__unmapself.s
@@ -1,8 +0,0 @@
-.global __unmapself
-.type __unmapself,@function
-__unmapself:
- ori r12, r0, 91
- brki r14, 0x8
- ori r12, r0, 1
- brki r14, 0x8
- nop
lib/libc/wasi/libc-top-half/musl/src/thread/microblaze/clone.s
@@ -1,30 +0,0 @@
-.global __clone
-.hidden __clone
-.type __clone,@function
-
-# r5, r6, r7, r8, r9, r10, stack
-# fn, st, fl, ar, pt, tl, ct
-# fl, st, __, pt, ct, tl
-
-__clone:
- andi r6, r6, -16
- addi r6, r6, -16
- swi r5, r6, 0
- swi r8, r6, 4
-
- ori r5, r7, 0
- ori r8, r9, 0
- lwi r9, r1, 28
- ori r12, r0, 120
-
- brki r14, 8
- beqi r3, 1f
- rtsd r15, 8
- nop
-
-1: lwi r3, r1, 0
- lwi r5, r1, 4
- brald r15, r3
- nop
- ori r12, r0, 1
- brki r14, 8
lib/libc/wasi/libc-top-half/musl/src/thread/microblaze/syscall_cp.s
@@ -1,27 +0,0 @@
-.global __cp_begin
-.hidden __cp_begin
-.global __cp_end
-.hidden __cp_end
-.global __cp_cancel
-.hidden __cp_cancel
-.hidden __cancel
-.global __syscall_cp_asm
-.hidden __syscall_cp_asm
-.type __syscall_cp_asm,@function
-__syscall_cp_asm:
-__cp_begin:
- lwi r5, r5, 0
- bnei r5, __cp_cancel
- addi r12, r6, 0
- add r5, r7, r0
- add r6, r8, r0
- add r7, r9, r0
- add r8, r10, r0
- lwi r9, r1, 28
- lwi r10, r1, 32
- brki r14, 0x8
-__cp_end:
- rtsd r15, 8
- nop
-__cp_cancel:
- bri __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/mips/__unmapself.s
@@ -1,10 +0,0 @@
-.set noreorder
-.global __unmapself
-.type __unmapself,@function
-__unmapself:
- move $sp, $25
- li $2, 4091
- syscall
- li $4, 0
- li $2, 4001
- syscall
lib/libc/wasi/libc-top-half/musl/src/thread/mips/clone.s
@@ -1,36 +0,0 @@
-.set noreorder
-.global __clone
-.hidden __clone
-.type __clone,@function
-__clone:
- # Save function pointer and argument pointer on new thread stack
- and $5, $5, -8
- subu $5, $5, 16
- sw $4, 0($5)
- sw $7, 4($5)
- # Shuffle (fn,sp,fl,arg,ptid,tls,ctid) to (fl,sp,ptid,tls,ctid)
- move $4, $6
- lw $6, 16($sp)
- lw $7, 20($sp)
- lw $9, 24($sp)
- subu $sp, $sp, 16
- sw $9, 16($sp)
- li $2, 4120
- syscall
- beq $7, $0, 1f
- nop
- addu $sp, $sp, 16
- jr $ra
- subu $2, $0, $2
-1: beq $2, $0, 1f
- nop
- addu $sp, $sp, 16
- jr $ra
- nop
-1: lw $25, 0($sp)
- lw $4, 4($sp)
- jalr $25
- nop
- move $4, $2
- li $2, 4001
- syscall
lib/libc/wasi/libc-top-half/musl/src/thread/mips/syscall_cp.s
@@ -1,53 +0,0 @@
-.set noreorder
-
-.global __cp_begin
-.hidden __cp_begin
-.type __cp_begin,@function
-.global __cp_end
-.hidden __cp_end
-.type __cp_end,@function
-.global __cp_cancel
-.hidden __cp_cancel
-.type __cp_cancel,@function
-.hidden __cancel
-.global __syscall_cp_asm
-.hidden __syscall_cp_asm
-.type __syscall_cp_asm,@function
-__syscall_cp_asm:
- subu $sp, $sp, 32
-__cp_begin:
- lw $4, 0($4)
- bne $4, $0, __cp_cancel
- move $2, $5
- move $4, $6
- move $5, $7
- lw $6, 48($sp)
- lw $7, 52($sp)
- lw $8, 56($sp)
- lw $9, 60($sp)
- lw $10,64($sp)
- sw $8, 16($sp)
- sw $9, 20($sp)
- sw $10,24($sp)
- sw $2, 28($sp)
- lw $2, 28($sp)
- syscall
-__cp_end:
- beq $7, $0, 1f
- addu $sp, $sp, 32
- subu $2, $0, $2
-1: jr $ra
- nop
-
-__cp_cancel:
- move $2, $ra
- bal 1f
- addu $sp, $sp, 32
- .gpword .
- .gpword __cancel
-1: lw $3, ($ra)
- subu $3, $ra, $3
- lw $25, 4($ra)
- addu $25, $25, $3
- jr $25
- move $ra, $2
lib/libc/wasi/libc-top-half/musl/src/thread/mips64/__unmapself.s
@@ -1,9 +0,0 @@
-.set noreorder
-.global __unmapself
-.type __unmapself, @function
-__unmapself:
- li $2, 5011
- syscall
- li $4, 0
- li $2, 5058
- syscall
lib/libc/wasi/libc-top-half/musl/src/thread/mips64/clone.s
@@ -1,34 +0,0 @@
-.set noreorder
-.global __clone
-.hidden __clone
-.type __clone,@function
-__clone:
- # Save function pointer and argument pointer on new thread stack
- and $5, $5, -16 # aligning stack to double word
- dsubu $5, $5, 16
- sd $4, 0($5) # save function pointer
- sd $7, 8($5) # save argument pointer
-
- # Shuffle (fn,sp,fl,arg,ptid,tls,ctid) to (fl,sp,ptid,tls,ctid)
- # sys_clone(u64 flags, u64 ustack_base, u64 parent_tidptr, u64 child_tidptr, u64 tls)
- move $4, $6
- move $6, $8
- move $7, $9
- move $8, $10
- li $2, 5055
- syscall
- beq $7, $0, 1f
- nop
- jr $ra
- dsubu $2, $0, $2
-1: beq $2, $0, 1f
- nop
- jr $ra
- nop
-1: ld $25, 0($sp) # function pointer
- ld $4, 8($sp) # argument pointer
- jalr $25 # call the user's function
- nop
- move $4, $2
- li $2, 5058
- syscall
lib/libc/wasi/libc-top-half/musl/src/thread/mips64/syscall_cp.s
@@ -1,52 +0,0 @@
-.set noreorder
-.global __cp_begin
-.hidden __cp_begin
-.type __cp_begin,@function
-.global __cp_end
-.hidden __cp_end
-.type __cp_end,@function
-.global __cp_cancel
-.hidden __cp_cancel
-.type __cp_cancel,@function
-.global __cp_cancel_data
-.hidden __cp_cancel_data
-.type __cp_cancel_data,@function
-.hidden __cancel
-.global __syscall_cp_asm
-.hidden __syscall_cp_asm
-.type __syscall_cp_asm,@function
-__syscall_cp_asm:
-__cp_begin:
- lw $4, 0($4)
- bne $4, $0, __cp_cancel
- move $2, $5
- move $4, $6
- move $5, $7
- move $6, $8
- move $7, $9
- move $8, $10
- move $9, $11
- ld $10, 0($sp)
- syscall
-__cp_end:
- beq $7, $0, 1f
- nop
- dsubu $2, $0, $2
-1: jr $ra
- nop
-
- # if cancellation flag is 1 then call __cancel
-__cp_cancel:
- move $2, $ra
-.align 8
- bal 1f
- nop
-__cp_cancel_data:
- .gpdword __cp_cancel_data
- .gpdword __cancel
-1: ld $3, ($ra)
- dsubu $3, $ra, $3
- ld $25, 8($ra)
- daddu $25, $25, $3
- jr $25
- move $ra, $2
lib/libc/wasi/libc-top-half/musl/src/thread/mipsn32/__unmapself.s
@@ -1,9 +0,0 @@
-.set noreorder
-.global __unmapself
-.type __unmapself,@function
-__unmapself:
- li $2, 6011
- syscall
- li $4, 0
- li $2, 6058
- syscall
lib/libc/wasi/libc-top-half/musl/src/thread/mipsn32/clone.s
@@ -1,34 +0,0 @@
-.set noreorder
-.global __clone
-.hidden __clone
-.type __clone,@function
-__clone:
- # Save function pointer and argument pointer on new thread stack
- and $5, $5, -16 # aligning stack to double word
- subu $5, $5, 16
- sw $4, 0($5) # save function pointer
- sw $7, 4($5) # save argument pointer
-
- # Shuffle (fn,sp,fl,arg,ptid,tls,ctid) to (fl,sp,ptid,tls,ctid)
- # sys_clone(u64 flags, u64 ustack_base, u64 parent_tidptr, u64 child_tidptr, u64 tls)
- move $4, $6
- move $6, $8
- move $7, $9
- move $8, $10
- li $2, 6055
- syscall
- beq $7, $0, 1f
- nop
- jr $ra
- subu $2, $0, $2
-1: beq $2, $0, 1f
- nop
- jr $ra
- nop
-1: lw $25, 0($sp) # function pointer
- lw $4, 4($sp) # argument pointer
- jalr $25 # call the user's function
- nop
- move $4, $2
- li $2, 6058
- syscall
lib/libc/wasi/libc-top-half/musl/src/thread/mipsn32/syscall_cp.s
@@ -1,51 +0,0 @@
-.set noreorder
-.global __cp_begin
-.hidden __cp_begin
-.type __cp_begin,@function
-.global __cp_end
-.hidden __cp_end
-.type __cp_end,@function
-.global __cp_cancel
-.hidden __cp_cancel
-.type __cp_cancel,@function
-.global __cp_cancel_data
-.hidden __cp_cancel_data
-.type __cp_cancel_data,@function
-.hidden __cancel
-.global __syscall_cp_asm
-.hidden __syscall_cp_asm
-.type __syscall_cp_asm,@function
-__syscall_cp_asm:
-__cp_begin:
- lw $4, 0($4)
- bne $4, $0, __cp_cancel
- move $2, $5
- move $4, $6
- move $5, $7
- move $6, $8
- move $7, $9
- move $8, $10
- move $9, $11
- lw $10, 0($sp)
- syscall
-__cp_end:
- beq $7, $0, 1f
- nop
- subu $2, $0, $2
-1: jr $ra
- nop
-
- # if cancellation flag is 1 then call __cancel
-__cp_cancel:
- move $2, $ra
- bal 1f
- nop
-__cp_cancel_data:
- .gpword __cp_cancel_data
- .gpword __cancel
-1: lw $3, 0($ra)
- subu $3, $ra, $3
- lw $25, 4($ra)
- addu $25, $25, $3
- jr $25
- move $ra, $2
lib/libc/wasi/libc-top-half/musl/src/thread/or1k/__set_thread_area.s
@@ -1,7 +0,0 @@
-.global __set_thread_area
-.hidden __set_thread_area
-.type __set_thread_area,@function
-__set_thread_area:
- l.ori r10, r3, 0
- l.jr r9
- l.ori r11, r0, 0
lib/libc/wasi/libc-top-half/musl/src/thread/or1k/__unmapself.s
@@ -1,8 +0,0 @@
-.global __unmapself
-.type __unmapself,@function
-__unmapself:
- l.ori r11, r0, 215 /* __NR_munmap */
- l.sys 1
- l.ori r3, r0, 0
- l.ori r11, r0, 93 /* __NR_exit */
- l.sys 1
lib/libc/wasi/libc-top-half/musl/src/thread/or1k/clone.s
@@ -1,31 +0,0 @@
-/* int clone(fn, stack, flags, arg, ptid, tls, ctid)
- * r3 r4 r5 r6 sp+0 sp+4 sp+8
- * sys_clone(flags, stack, ptid, ctid, tls)
- */
-.global __clone
-.hidden __clone
-.type __clone,@function
-__clone:
- l.addi r4, r4, -8
- l.sw 0(r4), r3
- l.sw 4(r4), r6
- /* (fn, st, fl, ar, pt, tl, ct) => (fl, st, pt, ct, tl) */
- l.ori r3, r5, 0
- l.lwz r5, 0(r1)
- l.lwz r6, 8(r1)
- l.lwz r7, 4(r1)
- l.ori r11, r0, 220 /* __NR_clone */
- l.sys 1
-
- l.sfeqi r11, 0
- l.bf 1f
- l.nop
- l.jr r9
- l.nop
-
-1: l.lwz r11, 0(r1)
- l.jalr r11
- l.lwz r3, 4(r1)
-
- l.ori r11, r0, 93 /* __NR_exit */
- l.sys 1
lib/libc/wasi/libc-top-half/musl/src/thread/or1k/syscall_cp.s
@@ -1,29 +0,0 @@
-.global __cp_begin
-.hidden __cp_begin
-.global __cp_end
-.hidden __cp_end
-.global __cp_cancel
-.hidden __cp_cancel
-.hidden __cancel
-.global __syscall_cp_asm
-.hidden __syscall_cp_asm
-.type __syscall_cp_asm,@function
-__syscall_cp_asm:
-__cp_begin:
- l.lwz r3, 0(r3)
- l.sfeqi r3, 0
- l.bnf __cp_cancel
- l.ori r11, r4, 0
- l.ori r3, r5, 0
- l.ori r4, r6, 0
- l.ori r5, r7, 0
- l.ori r6, r8, 0
- l.lwz r7, 0(r1)
- l.lwz r8, 4(r1)
- l.sys 1
-__cp_end:
- l.jr r9
- l.nop
-__cp_cancel:
- l.j __cancel
- l.nop
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc/__set_thread_area.s
@@ -1,12 +0,0 @@
-.text
-.global __set_thread_area
-.hidden __set_thread_area
-.type __set_thread_area, %function
-__set_thread_area:
- # mov pointer in reg3 into r2
- mr 2, 3
- # put 0 into return reg
- li 3, 0
- # return
- blr
-
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc/__unmapself.s
@@ -1,9 +0,0 @@
- .text
- .global __unmapself
- .type __unmapself,%function
-__unmapself:
- li 0, 91 # __NR_munmap
- sc
- li 0, 1 #__NR_exit
- sc
- blr
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc/clone.s
@@ -1,73 +0,0 @@
-.text
-.global __clone
-.hidden __clone
-.type __clone, %function
-__clone:
-# int clone(fn, stack, flags, arg, ptid, tls, ctid)
-# a b c d e f g
-# 3 4 5 6 7 8 9
-# pseudo C code:
-# tid = syscall(SYS_clone,c,b,e,f,g);
-# if (!tid) syscall(SYS_exit, a(d));
-# return tid;
-
-# SYS_clone = 120
-# SYS_exit = 1
-
-# store non-volatile regs r30, r31 on stack in order to put our
-# start func and its arg there
-stwu 30, -16(1)
-stw 31, 4(1)
-
-# save r3 (func) into r30, and r6(arg) into r31
-mr 30, 3
-mr 31, 6
-
-# create initial stack frame for new thread
-clrrwi 4, 4, 4
-li 0, 0
-stwu 0, -16(4)
-
-#move c into first arg
-mr 3, 5
-#mr 4, 4
-mr 5, 7
-mr 6, 8
-mr 7, 9
-
-# move syscall number into r0
-li 0, 120
-
-sc
-
-# check for syscall error
-bns+ 1f # jump to label 1 if no summary overflow.
-#else
-neg 3, 3 #negate the result (errno)
-1:
-# compare sc result with 0
-cmpwi cr7, 3, 0
-
-# if not 0, jump to end
-bne cr7, 2f
-
-#else: we're the child
-#call funcptr: move arg (d) into r3
-mr 3, 31
-#move r30 (funcptr) into CTR reg
-mtctr 30
-# call CTR reg
-bctrl
-# mov SYS_exit into r0 (the exit param is already in r3)
-li 0, 1
-sc
-
-2:
-
-# restore stack
-lwz 30, 0(1)
-lwz 31, 4(1)
-addi 1, 1, 16
-
-blr
-
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc/syscall_cp.s
@@ -1,59 +0,0 @@
-.global __cp_begin
-.hidden __cp_begin
-.global __cp_end
-.hidden __cp_end
-.global __cp_cancel
-.hidden __cp_cancel
-.hidden __cancel
-.global __syscall_cp_asm
-.hidden __syscall_cp_asm
-
-#r0: volatile. may be modified during linkage.
-#r1: stack frame: 16 byte alignment.
-#r2: tls/thread pointer on pp32
-#r3,r4: return values, first args
-#r5-r10: args
-#r11-r12: volatile. may be modified during linkage
-#r13: "small data area" pointer
-#r14 - r30: local vars
-#r31: local or environment pointer
-
-#r1, r14-31: belong to the caller, must be saved and restored
-#r0, r3-r12, ctr, xer: volatile, not preserved
-#r0,r11,r12: may be altered by cross-module call,
-#"a func cannot depend on that these regs have the values placed by the caller"
-
-#the fields CR2,CR2,CR4 of the cond reg must be preserved
-#LR (link reg) shall contain the funcs return address
- .text
- .type __syscall_cp_asm,%function
-__syscall_cp_asm:
- # at enter: r3 = pointer to self->cancel, r4: syscall no, r5: first arg, r6: 2nd, r7: 3rd, r8: 4th, r9: 5th, r10: 6th
-__cp_begin:
- # r3 holds first argument, its a pointer to self->cancel.
- # we must compare the dereferenced value with 0 and jump to __cancel if its not
-
- lwz 0, 0(3) #deref pointer into r0
-
- cmpwi cr7, 0, 0 #compare r0 with 0, store result in cr7.
- beq+ cr7, 1f #jump to label 1 if r0 was 0
-
- b __cp_cancel #else call cancel
-1:
- #ok, the cancel flag was not set
- # syscall: number goes to r0, the rest 3-8
- mr 0, 4 # put the system call number into r0
- mr 3, 5 # Shift the arguments: arg1
- mr 4, 6 # arg2
- mr 5, 7 # arg3
- mr 6, 8 # arg4
- mr 7, 9 # arg5
- mr 8, 10 # arg6
- sc
-__cp_end:
- bnslr+ # return if no summary overflow.
- #else negate result.
- neg 3, 3
- blr
-__cp_cancel:
- b __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc64/__set_thread_area.s
@@ -1,9 +0,0 @@
-.text
-.global __set_thread_area
-.hidden __set_thread_area
-.type __set_thread_area, %function
-__set_thread_area:
- mr 13, 3
- li 3, 0
- blr
-
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc64/__unmapself.s
@@ -1,9 +0,0 @@
- .text
- .global __unmapself
- .type __unmapself,%function
-__unmapself:
- li 0, 91 # __NR_munmap
- sc
- li 0, 1 #__NR_exit
- sc
- blr
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc64/clone.s
@@ -1,48 +0,0 @@
-.text
-.global __clone
-.hidden __clone
-.type __clone, %function
-__clone:
- # int clone(fn, stack, flags, arg, ptid, tls, ctid)
- # a b c d e f g
- # 3 4 5 6 7 8 9
- # pseudo C code:
- # tid = syscall(SYS_clone,c,b,e,f,g);
- # if (!tid) syscall(SYS_exit, a(d));
- # return tid;
-
- # create initial stack frame for new thread
- clrrdi 4, 4, 4
- li 0, 0
- stdu 0,-32(4)
-
- # save fn and arg to child stack
- std 3, 8(4)
- std 6, 16(4)
-
- # shuffle args into correct registers and call SYS_clone
- mr 3, 5
- #mr 4, 4
- mr 5, 7
- mr 6, 8
- mr 7, 9
- li 0, 120 # SYS_clone = 120
- sc
-
- # if error, negate return (errno)
- bns+ 1f
- neg 3, 3
-
-1: # if we're the parent, return
- cmpwi cr7, 3, 0
- bnelr cr7
-
- # we're the child. call fn(arg)
- ld 3, 16(1)
- ld 12, 8(1)
- mtctr 12
- bctrl
-
- # call SYS_exit. exit code is already in r3 from fn return value
- li 0, 1 # SYS_exit = 1
- sc
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc64/syscall_cp.s
@@ -1,44 +0,0 @@
- .global __cp_begin
- .hidden __cp_begin
- .global __cp_end
- .hidden __cp_end
- .global __cp_cancel
- .hidden __cp_cancel
- .hidden __cancel
- .global __syscall_cp_asm
- .hidden __syscall_cp_asm
- .text
- .type __syscall_cp_asm,%function
-__syscall_cp_asm:
- # at enter: r3 = pointer to self->cancel, r4: syscall no, r5: first arg, r6: 2nd, r7: 3rd, r8: 4th, r9: 5th, r10: 6th
-__cp_begin:
- # if (self->cancel) goto __cp_cancel
- lwz 0, 0(3)
- cmpwi cr7, 0, 0
- bne- cr7, __cp_cancel
-
- # make syscall
- mr 0, 4
- mr 3, 5
- mr 4, 6
- mr 5, 7
- mr 6, 8
- mr 7, 9
- mr 8, 10
- sc
-
-__cp_end:
- # return error ? -r3 : r3
- bnslr+
- neg 3, 3
- blr
-
-__cp_cancel:
- mflr 0
- bl 1f
- .long .TOC.-.
-1: mflr 3
- lwa 2, 0(3)
- add 2, 2, 3
- mtlr 0
- b __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/riscv64/__set_thread_area.s
@@ -1,6 +0,0 @@
-.global __set_thread_area
-.type __set_thread_area, %function
-__set_thread_area:
- mv tp, a0
- li a0, 0
- ret
lib/libc/wasi/libc-top-half/musl/src/thread/riscv64/__unmapself.s
@@ -1,7 +0,0 @@
-.global __unmapself
-.type __unmapself, %function
-__unmapself:
- li a7, 215 # SYS_munmap
- ecall
- li a7, 93 # SYS_exit
- ecall
lib/libc/wasi/libc-top-half/musl/src/thread/riscv64/clone.s
@@ -1,34 +0,0 @@
-# __clone(func, stack, flags, arg, ptid, tls, ctid)
-# a0, a1, a2, a3, a4, a5, a6
-
-# syscall(SYS_clone, flags, stack, ptid, tls, ctid)
-# a7 a0, a1, a2, a3, a4
-
-.global __clone
-.type __clone, %function
-__clone:
- # Save func and arg to stack
- addi a1, a1, -16
- sd a0, 0(a1)
- sd a3, 8(a1)
-
- # Call SYS_clone
- mv a0, a2
- mv a2, a4
- mv a3, a5
- mv a4, a6
- li a7, 220 # SYS_clone
- ecall
-
- beqz a0, 1f
- # Parent
- ret
-
- # Child
-1: ld a1, 0(sp)
- ld a0, 8(sp)
- jalr a1
-
- # Exit
- li a7, 93 # SYS_exit
- ecall
lib/libc/wasi/libc-top-half/musl/src/thread/riscv64/syscall_cp.s
@@ -1,29 +0,0 @@
-.global __cp_begin
-.hidden __cp_begin
-.global __cp_end
-.hidden __cp_end
-.global __cp_cancel
-.hidden __cp_cancel
-.hidden __cancel
-.global __syscall_cp_asm
-.hidden __syscall_cp_asm
-.type __syscall_cp_asm, %function
-__syscall_cp_asm:
-__cp_begin:
- lw t0, 0(a0)
- bnez t0, __cp_cancel
-
- mv t0, a1
- mv a0, a2
- mv a1, a3
- mv a2, a4
- mv a3, a5
- mv a4, a6
- mv a5, a7
- ld a6, 0(sp)
- mv a7, t0
- ecall
-__cp_end:
- ret
-__cp_cancel:
- tail __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/s390x/__set_thread_area.s
@@ -1,10 +0,0 @@
-.text
-.global __set_thread_area
-.hidden __set_thread_area
-.type __set_thread_area, %function
-__set_thread_area:
- sar %a1, %r2
- srlg %r2, %r2, 32
- sar %a0, %r2
- lghi %r2, 0
- br %r14
lib/libc/wasi/libc-top-half/musl/src/thread/s390x/__tls_get_offset.s
@@ -1,17 +0,0 @@
- .global __tls_get_offset
- .type __tls_get_offset,%function
-__tls_get_offset:
- stmg %r14, %r15, 112(%r15)
- aghi %r15, -160
-
- la %r2, 0(%r2, %r12)
- brasl %r14, __tls_get_addr
-
- ear %r1, %a0
- sllg %r1, %r1, 32
- ear %r1, %a1
-
- sgr %r2, %r1
-
- lmg %r14, %r15, 272(%r15)
- br %r14
lib/libc/wasi/libc-top-half/musl/src/thread/s390x/__unmapself.s
@@ -1,6 +0,0 @@
-.text
-.global __unmapself
-.type __unmapself, @function
-__unmapself:
- svc 91 # SYS_munmap
- svc 1 # SYS_exit
lib/libc/wasi/libc-top-half/musl/src/thread/s390x/clone.s
@@ -1,54 +0,0 @@
-.text
-.global __clone
-.hidden __clone
-.type __clone, %function
-__clone:
- # int clone(
- # fn, a = r2
- # stack, b = r3
- # flags, c = r4
- # arg, d = r5
- # ptid, e = r6
- # tls, f = *(r15+160)
- # ctid) g = *(r15+168)
- #
- # pseudo C code:
- # tid = syscall(SYS_clone,b,c,e,g,f);
- # if (!tid) syscall(SYS_exit, a(d));
- # return tid;
-
- # preserve call-saved register used as syscall arg
- stg %r6, 48(%r15)
-
- # create initial stack frame for new thread
- nill %r3, 0xfff8
- aghi %r3, -160
- lghi %r0, 0
- stg %r0, 0(%r3)
-
- # save fn and arg to child stack
- stg %r2, 8(%r3)
- stg %r5, 16(%r3)
-
- # shuffle args into correct registers and call SYS_clone
- lgr %r2, %r3
- lgr %r3, %r4
- lgr %r4, %r6
- lg %r5, 168(%r15)
- lg %r6, 160(%r15)
- svc 120
-
- # restore call-saved register
- lg %r6, 48(%r15)
-
- # if error or if we're the parent, return
- ltgr %r2, %r2
- bnzr %r14
-
- # we're the child. call fn(arg)
- lg %r1, 8(%r15)
- lg %r2, 16(%r15)
- basr %r14, %r1
-
- # call SYS_exit. exit code is already in r2 from fn return value
- svc 1
lib/libc/wasi/libc-top-half/musl/src/thread/s390x/syscall_cp.s
@@ -1,34 +0,0 @@
- .global __cp_begin
- .hidden __cp_begin
- .global __cp_end
- .hidden __cp_end
- .global __cp_cancel
- .hidden __cp_cancel
- .hidden __cancel
- .global __syscall_cp_asm
- .hidden __syscall_cp_asm
- .text
- .type __syscall_cp_asm,%function
-__syscall_cp_asm:
-__cp_begin:
- icm %r2, 15, 0(%r2)
- jne __cp_cancel
-
- stg %r6, 48(%r15)
- stg %r7, 56(%r15)
- lgr %r1, %r3
- lgr %r2, %r4
- lgr %r3, %r5
- lgr %r4, %r6
- lg %r5, 160(%r15)
- lg %r6, 168(%r15)
- lg %r7, 176(%r15)
- svc 0
-
-__cp_end:
- lg %r7, 56(%r15)
- lg %r6, 48(%r15)
- br %r14
-
-__cp_cancel:
- jg __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/sh/__set_thread_area.c
@@ -1,37 +0,0 @@
-#include "pthread_impl.h"
-#include "libc.h"
-#include <elf.h>
-
-/* Also perform sh-specific init */
-
-#define CPU_HAS_LLSC 0x0040
-#define CPU_HAS_CAS_L 0x0400
-
-extern hidden const char __sh_cas_gusa[], __sh_cas_llsc[], __sh_cas_imask[], __sh_cas_cas_l[];
-
-hidden const void *__sh_cas_ptr;
-
-hidden unsigned __sh_nommu;
-
-int __set_thread_area(void *p)
-{
- size_t *aux;
- __asm__ __volatile__ ( "ldc %0, gbr" : : "r"(p) : "memory" );
-#ifndef __SH4A__
- __sh_cas_ptr = __sh_cas_gusa;
-#if !defined(__SH3__) && !defined(__SH4__)
- for (aux=libc.auxv; *aux; aux+=2) {
- if (*aux != AT_PLATFORM) continue;
- const char *s = (void *)aux[1];
- if (s[0]!='s' || s[1]!='h' || s[2]!='2' || s[3]-'0'<10u) break;
- __sh_cas_ptr = __sh_cas_imask;
- __sh_nommu = 1;
- }
-#endif
- if (__hwcap & CPU_HAS_CAS_L)
- __sh_cas_ptr = __sh_cas_cas_l;
- else if (__hwcap & CPU_HAS_LLSC)
- __sh_cas_ptr = __sh_cas_llsc;
-#endif
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/sh/__unmapself.c
@@ -1,24 +0,0 @@
-#include "pthread_impl.h"
-
-hidden void __unmapself_sh_mmu(void *, size_t);
-hidden void __unmapself_sh_nommu(void *, size_t);
-
-#if !defined(__SH3__) && !defined(__SH4__)
-#define __unmapself __unmapself_sh_nommu
-#include "dynlink.h"
-#undef CRTJMP
-#define CRTJMP(pc,sp) __asm__ __volatile__( \
- "mov.l @%0+,r0 ; mov.l @%0,r12 ; jmp @r0 ; mov %1,r15" \
- : : "r"(pc), "r"(sp) : "r0", "memory" )
-#include "../__unmapself.c"
-#undef __unmapself
-extern hidden unsigned __sh_nommu;
-#else
-#define __sh_nommu 0
-#endif
-
-void __unmapself(void *base, size_t size)
-{
- if (__sh_nommu) __unmapself_sh_nommu(base, size);
- else __unmapself_sh_mmu(base, size);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/sh/__unmapself_mmu.s
@@ -1,23 +0,0 @@
-.text
-.global __unmapself_sh_mmu
-.hidden __unmapself_sh_mmu
-.type __unmapself_sh_mmu, @function
-__unmapself_sh_mmu:
- mov #91, r3 ! SYS_munmap
- trapa #31
-
- or r0, r0
- or r0, r0
- or r0, r0
- or r0, r0
- or r0, r0
-
- mov #1, r3 ! SYS_exit
- mov #0, r4
- trapa #31
-
- or r0, r0
- or r0, r0
- or r0, r0
- or r0, r0
- or r0, r0
lib/libc/wasi/libc-top-half/musl/src/thread/sh/atomics.s
@@ -1,65 +0,0 @@
-/* Contract for all versions is same as cas.l r2,r3,@r0
- * pr and r1 are also clobbered (by jsr & r1 as temp).
- * r0,r2,r4-r15 must be preserved.
- * r3 contains result (==r2 iff cas succeeded). */
-
- .align 2
-.global __sh_cas_gusa
-.hidden __sh_cas_gusa
-__sh_cas_gusa:
- mov.l r5,@-r15
- mov.l r4,@-r15
- mov r0,r4
- mova 1f,r0
- mov r15,r1
- mov #(0f-1f),r15
-0: mov.l @r4,r5
- cmp/eq r5,r2
- bf 1f
- mov.l r3,@r4
-1: mov r1,r15
- mov r5,r3
- mov r4,r0
- mov.l @r15+,r4
- rts
- mov.l @r15+,r5
-
-.global __sh_cas_llsc
-.hidden __sh_cas_llsc
-__sh_cas_llsc:
- mov r0,r1
- .word 0x00ab /* synco */
-0: .word 0x0163 /* movli.l @r1,r0 */
- cmp/eq r0,r2
- bf 1f
- mov r3,r0
- .word 0x0173 /* movco.l r0,@r1 */
- bf 0b
- mov r2,r0
-1: .word 0x00ab /* synco */
- mov r0,r3
- rts
- mov r1,r0
-
-.global __sh_cas_imask
-.hidden __sh_cas_imask
-__sh_cas_imask:
- mov r0,r1
- stc sr,r0
- mov.l r0,@-r15
- or #0xf0,r0
- ldc r0,sr
- mov.l @r1,r0
- cmp/eq r0,r2
- bf 1f
- mov.l r3,@r1
-1: ldc.l @r15+,sr
- mov r0,r3
- rts
- mov r1,r0
-
-.global __sh_cas_cas_l
-.hidden __sh_cas_cas_l
-__sh_cas_cas_l:
- rts
- .word 0x2323 /* cas.l r2,r3,@r0 */
lib/libc/wasi/libc-top-half/musl/src/thread/sh/clone.s
@@ -1,54 +0,0 @@
-.text
-.global __clone
-.hidden __clone
-.type __clone, @function
-__clone:
-! incoming: fn stack flags arg ptid tls ctid
-! r4 r5 r6 r7 @r15 @(4,r15) @(8,r15)
-
- mov #-16, r0
- and r0, r5
-
- mov r4, r1 ! r1 = fn
- mov r7, r2 ! r2 = arg
-
- mov #120, r3 ! r3 = __NR_clone
- mov r6, r4 ! r4 = flags
- !mov r5, r5 ! r5 = stack
- mov.l @r15, r6 ! r6 = ptid
- mov.l @(8,r15), r7 ! r7 = ctid
- mov.l @(4,r15), r0 ! r0 = tls
- trapa #31
-
- or r0, r0
- or r0, r0
- or r0, r0
- or r0, r0
- or r0, r0
-
- cmp/eq #0, r0
- bt 1f
-
- ! we are the parent, return
- rts
- nop
-
-1: ! we are the child, call fn(arg)
- mov.l 1f, r0
- mov r1, r5
- bsrf r0
- mov r2, r4
-
-2: mov #1, r3 ! __NR_exit
- mov r0, r4
- trapa #31
-
- or r0, r0
- or r0, r0
- or r0, r0
- or r0, r0
- or r0, r0
-
-.align 2
-.hidden __shcall
-1: .long __shcall@PCREL+(.-2b)
lib/libc/wasi/libc-top-half/musl/src/thread/sh/syscall_cp.s
@@ -1,45 +0,0 @@
-.text
-.global __cp_begin
-.hidden __cp_begin
-.global __cp_end
-.hidden __cp_end
-.global __cp_cancel
-.hidden __cp_cancel
-.hidden __cancel
-.global __syscall_cp_asm
-.hidden __syscall_cp_asm
-.type __syscall_cp_asm, @function
-__syscall_cp_asm:
-
-__cp_begin:
- mov.l @r4, r4
- tst r4, r4
- bf __cp_cancel
- mov r5, r3
- mov r6, r4
- mov r7, r5
- mov.l @r15, r6
- mov.l @(4,r15), r7
- mov.l @(8,r15), r0
- mov.l @(12,r15), r1
- trapa #31
-
-__cp_end:
- ! work around hardware bug
- or r0, r0
- or r0, r0
- or r0, r0
- or r0, r0
- or r0, r0
-
- rts
- nop
-
-__cp_cancel:
- mov.l 2f, r0
- braf r0
- nop
-1:
-
-.align 2
-2: .long __cancel@PCREL-(1b-.)
lib/libc/wasi/libc-top-half/musl/src/thread/x32/__set_thread_area.s
@@ -1,11 +0,0 @@
-/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
-.text
-.global __set_thread_area
-.hidden __set_thread_area
-.type __set_thread_area,@function
-__set_thread_area:
- mov %edi,%esi /* shift for syscall */
- movl $0x1002,%edi /* SET_FS register */
- movl $0x4000009e,%eax /* set fs segment to */
- syscall /* arch_prctl(SET_FS, arg)*/
- ret
lib/libc/wasi/libc-top-half/musl/src/thread/x32/__unmapself.s
@@ -1,10 +0,0 @@
-/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
-.text
-.global __unmapself
-.type __unmapself,@function
-__unmapself:
- movl $0x4000000b,%eax /* SYS_munmap */
- syscall /* munmap(arg2,arg3) */
- xor %rdi,%rdi /* exit() args: always return success */
- movl $0x4000003c,%eax /* SYS_exit */
- syscall /* exit(0) */
lib/libc/wasi/libc-top-half/musl/src/thread/x32/clone.s
@@ -1,26 +0,0 @@
-.text
-.global __clone
-.hidden __clone
-.type __clone,@function
-__clone:
- movl $0x40000038,%eax /* SYS_clone */
- mov %rdi,%r11
- mov %rdx,%rdi
- mov %r8,%rdx
- mov %r9,%r8
- mov 8(%rsp),%r10
- mov %r11,%r9
- and $-16,%rsi
- sub $8,%rsi
- mov %rcx,(%rsi)
- syscall
- test %eax,%eax
- jnz 1f
- xor %ebp,%ebp
- pop %rdi
- call *%r9
- mov %eax,%edi
- movl $0x4000003c,%eax /* SYS_exit */
- syscall
- hlt
-1: ret
lib/libc/wasi/libc-top-half/musl/src/thread/x32/syscall_cp.s
@@ -1,31 +0,0 @@
-.text
-.global __cp_begin
-.hidden __cp_begin
-.global __cp_end
-.hidden __cp_end
-.global __cp_cancel
-.hidden __cp_cancel
-.hidden __cancel
-.global __syscall_cp_asm
-.hidden __syscall_cp_asm
-.type __syscall_cp_asm,@function
-__syscall_cp_asm:
-
-__cp_begin:
- mov (%rdi),%eax
- test %eax,%eax
- jnz __cp_cancel
- mov %rdi,%r11
- mov %rsi,%rax
- mov %rdx,%rdi
- mov %rcx,%rsi
- mov %r8,%rdx
- mov %r9,%r10
- mov 8(%rsp),%r8
- mov 16(%rsp),%r9
- mov %r11,8(%rsp)
- syscall
-__cp_end:
- ret
-__cp_cancel:
- jmp __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/x86_64/__set_thread_area.s
@@ -1,11 +0,0 @@
-/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
-.text
-.global __set_thread_area
-.hidden __set_thread_area
-.type __set_thread_area,@function
-__set_thread_area:
- mov %rdi,%rsi /* shift for syscall */
- movl $0x1002,%edi /* SET_FS register */
- movl $158,%eax /* set fs segment to */
- syscall /* arch_prctl(SET_FS, arg)*/
- ret
lib/libc/wasi/libc-top-half/musl/src/thread/x86_64/__unmapself.s
@@ -1,10 +0,0 @@
-/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
-.text
-.global __unmapself
-.type __unmapself,@function
-__unmapself:
- movl $11,%eax /* SYS_munmap */
- syscall /* munmap(arg2,arg3) */
- xor %rdi,%rdi /* exit() args: always return success */
- movl $60,%eax /* SYS_exit */
- syscall /* exit(0) */
lib/libc/wasi/libc-top-half/musl/src/thread/x86_64/clone.s
@@ -1,28 +0,0 @@
-.text
-.global __clone
-.hidden __clone
-.type __clone,@function
-__clone:
- xor %eax,%eax
- mov $56,%al
- mov %rdi,%r11
- mov %rdx,%rdi
- mov %r8,%rdx
- mov %r9,%r8
- mov 8(%rsp),%r10
- mov %r11,%r9
- and $-16,%rsi
- sub $8,%rsi
- mov %rcx,(%rsi)
- syscall
- test %eax,%eax
- jnz 1f
- xor %ebp,%ebp
- pop %rdi
- call *%r9
- mov %eax,%edi
- xor %eax,%eax
- mov $60,%al
- syscall
- hlt
-1: ret
lib/libc/wasi/libc-top-half/musl/src/thread/x86_64/syscall_cp.s
@@ -1,31 +0,0 @@
-.text
-.global __cp_begin
-.hidden __cp_begin
-.global __cp_end
-.hidden __cp_end
-.global __cp_cancel
-.hidden __cp_cancel
-.hidden __cancel
-.global __syscall_cp_asm
-.hidden __syscall_cp_asm
-.type __syscall_cp_asm,@function
-__syscall_cp_asm:
-
-__cp_begin:
- mov (%rdi),%eax
- test %eax,%eax
- jnz __cp_cancel
- mov %rdi,%r11
- mov %rsi,%rax
- mov %rdx,%rdi
- mov %rcx,%rsi
- mov %r8,%rdx
- mov %r9,%r10
- mov 8(%rsp),%r8
- mov 16(%rsp),%r9
- mov %r11,8(%rsp)
- syscall
-__cp_end:
- ret
-__cp_cancel:
- jmp __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/__lock.c
@@ -1,62 +0,0 @@
-#include "pthread_impl.h"
-
-/* This lock primitive combines a flag (in the sign bit) and a
- * congestion count (= threads inside the critical section, CS) in a
- * single int that is accessed through atomic operations. The states
- * of the int for value x are:
- *
- * x == 0: unlocked and no thread inside the critical section
- *
- * x < 0: locked with a congestion of x-INT_MIN, including the thread
- * that holds the lock
- *
- * x > 0: unlocked with a congestion of x
- *
- * or in an equivalent formulation x is the congestion count or'ed
- * with INT_MIN as a lock flag.
- */
-
-void __lock(volatile int *l)
-{
- int need_locks = libc.need_locks;
- if (!need_locks) return;
- /* fast path: INT_MIN for the lock, +1 for the congestion */
- int current = a_cas(l, 0, INT_MIN + 1);
- if (need_locks < 0) libc.need_locks = 0;
- if (!current) return;
- /* A first spin loop, for medium congestion. */
- for (unsigned i = 0; i < 10; ++i) {
- if (current < 0) current -= INT_MIN + 1;
- // assertion: current >= 0
- int val = a_cas(l, current, INT_MIN + (current + 1));
- if (val == current) return;
- current = val;
- }
- // Spinning failed, so mark ourselves as being inside the CS.
- current = a_fetch_add(l, 1) + 1;
- /* The main lock acquisition loop for heavy congestion. The only
- * change to the value performed inside that loop is a successful
- * lock via the CAS that acquires the lock. */
- for (;;) {
- /* We can only go into wait, if we know that somebody holds the
- * lock and will eventually wake us up, again. */
- if (current < 0) {
- __futexwait(l, current, 1);
- current -= INT_MIN + 1;
- }
- /* assertion: current > 0, the count includes us already. */
- int val = a_cas(l, current, INT_MIN + current);
- if (val == current) return;
- current = val;
- }
-}
-
-void __unlock(volatile int *l)
-{
- /* Check l[0] to see if we are multi-threaded. */
- if (l[0] < 0) {
- if (a_fetch_add(l, -(INT_MIN + 1)) != (INT_MIN + 1)) {
- __wake(l, 1, 1);
- }
- }
-}
lib/libc/wasi/libc-top-half/musl/src/thread/__set_thread_area.c
@@ -1,10 +0,0 @@
-#include "pthread_impl.h"
-
-int __set_thread_area(void *p)
-{
-#ifdef SYS_set_thread_area
- return __syscall(SYS_set_thread_area, p);
-#else
- return -ENOSYS;
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/thread/__syscall_cp.c
@@ -1,20 +0,0 @@
-#include "pthread_impl.h"
-#include "syscall.h"
-
-hidden long __syscall_cp_c();
-
-static long sccp(syscall_arg_t nr,
- syscall_arg_t u, syscall_arg_t v, syscall_arg_t w,
- syscall_arg_t x, syscall_arg_t y, syscall_arg_t z)
-{
- return __syscall(nr, u, v, w, x, y, z);
-}
-
-weak_alias(sccp, __syscall_cp_c);
-
-long (__syscall_cp)(syscall_arg_t nr,
- syscall_arg_t u, syscall_arg_t v, syscall_arg_t w,
- syscall_arg_t x, syscall_arg_t y, syscall_arg_t z)
-{
- return __syscall_cp_c(nr, u, v, w, x, y, z);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/__timedwait.c
@@ -1,84 +0,0 @@
-#include <pthread.h>
-#include <time.h>
-#include <errno.h>
-#include "futex.h"
-#include "syscall.h"
-#include "pthread_impl.h"
-
-#ifdef __wasilibc_unmodified_upstream
-#define IS32BIT(x) !((x)+0x80000000ULL>>32)
-#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
-
-static int __futex4_cp(volatile void *addr, int op, int val, const struct timespec *to)
-{
- int r;
-#ifdef SYS_futex_time64
- time_t s = to ? to->tv_sec : 0;
- long ns = to ? to->tv_nsec : 0;
- r = -ENOSYS;
- if (SYS_futex == SYS_futex_time64 || !IS32BIT(s))
- r = __syscall_cp(SYS_futex_time64, addr, op, val,
- to ? ((long long[]){s, ns}) : 0);
- if (SYS_futex == SYS_futex_time64 || r!=-ENOSYS) return r;
- to = to ? (void *)(long[]){CLAMP(s), ns} : 0;
-#endif
- r = __syscall_cp(SYS_futex, addr, op, val, to);
- if (r != -ENOSYS) return r;
- return __syscall_cp(SYS_futex, addr, op & ~FUTEX_PRIVATE, val, to);
-}
-
-static volatile int dummy = 0;
-weak_alias(dummy, __eintr_valid_flag);
-#else
-static int __futex4_cp(volatile void *addr, int op, int val, const struct timespec *to)
-{
- int64_t max_wait_ns = -1;
- if (to) {
- max_wait_ns = (int64_t)(to->tv_sec * 1000000000 + to->tv_nsec);
- }
- return __wasilibc_futex_wait(addr, op, val, max_wait_ns);
-}
-#endif
-
-int __timedwait_cp(volatile int *addr, int val,
- clockid_t clk, const struct timespec *at, int priv)
-{
- int r;
- struct timespec to, *top=0;
-
- if (priv) priv = FUTEX_PRIVATE;
-
- if (at) {
- if (at->tv_nsec >= 1000000000UL) return EINVAL;
- if (__clock_gettime(clk, &to)) return EINVAL;
- to.tv_sec = at->tv_sec - to.tv_sec;
- if ((to.tv_nsec = at->tv_nsec - to.tv_nsec) < 0) {
- to.tv_sec--;
- to.tv_nsec += 1000000000;
- }
- if (to.tv_sec < 0) return ETIMEDOUT;
- top = &to;
- }
-
- r = -__futex4_cp(addr, FUTEX_WAIT|priv, val, top);
- if (r != EINTR && r != ETIMEDOUT && r != ECANCELED) r = 0;
-#ifdef __wasilibc_unmodified_upstream
- /* Mitigate bug in old kernels wrongly reporting EINTR for non-
- * interrupting (SA_RESTART) signal handlers. This is only practical
- * when NO interrupting signal handlers have been installed, and
- * works by sigaction tracking whether that's the case. */
- if (r == EINTR && !__eintr_valid_flag) r = 0;
-#endif
-
- return r;
-}
-
-int __timedwait(volatile int *addr, int val,
- clockid_t clk, const struct timespec *at, int priv)
-{
- int cs, r;
- __pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
- r = __timedwait_cp(addr, val, clk, at, priv);
- __pthread_setcancelstate(cs, 0);
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/__tls_get_addr.c
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-void *__tls_get_addr(tls_mod_off_t *v)
-{
- pthread_t self = __pthread_self();
- return (void *)(self->dtv[v[0]] + v[1]);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/__unmapself.c
@@ -1,24 +0,0 @@
-#include "pthread_impl.h"
-#include "atomic.h"
-#include "syscall.h"
-/* cheat and reuse CRTJMP macro from dynlink code */
-#include "dynlink.h"
-
-static void *unmap_base;
-static size_t unmap_size;
-static char shared_stack[256];
-
-static void do_unmap()
-{
- __syscall(SYS_munmap, unmap_base, unmap_size);
- __syscall(SYS_exit);
-}
-
-void __unmapself(void *base, size_t size)
-{
- char *stack = shared_stack + sizeof shared_stack;
- stack -= (uintptr_t)stack % 16;
- unmap_base = base;
- unmap_size = size;
- CRTJMP(do_unmap, stack);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/__wait.c
@@ -1,55 +0,0 @@
-#include "pthread_impl.h"
-#ifndef __wasilibc_unmodified_upstream
-#include "assert.h"
-#endif
-
-#ifndef __wasilibc_unmodified_upstream
-// Use WebAssembly's `wait` instruction to implement a futex. Note that `op` is
-// unused but retained as a parameter to match the original signature of the
-// syscall and that, for `max_wait_ns`, -1 (or any negative number) means wait
-// indefinitely.
-//
-// Adapted from Emscripten: see
-// https://github.com/emscripten-core/emscripten/blob/058a9fff/system/lib/pthread/emscripten_futex_wait.c#L111-L150.
-int __wasilibc_futex_wait(volatile void *addr, int op, int val, int64_t max_wait_ns)
-{
- if ((((intptr_t)addr) & 3) != 0) {
- return -EINVAL;
- }
-
- int ret = __builtin_wasm_memory_atomic_wait32((int *)addr, val, max_wait_ns);
-
- // memory.atomic.wait32 returns:
- // 0 => "ok", woken by another agent.
- // 1 => "not-equal", loaded value != expected value
- // 2 => "timed-out", the timeout expired
- if (ret == 1) {
- return -EWOULDBLOCK;
- }
- if (ret == 2) {
- return -ETIMEDOUT;
- }
- assert(ret == 0);
- return 0;
-}
-#endif
-
-void __wait(volatile int *addr, volatile int *waiters, int val, int priv)
-{
- int spins=100;
- if (priv) priv = FUTEX_PRIVATE;
- while (spins-- && (!waiters || !*waiters)) {
- if (*addr==val) a_spin();
- else return;
- }
- if (waiters) a_inc(waiters);
- while (*addr==val) {
-#ifdef __wasilibc_unmodified_upstream
- __syscall(SYS_futex, addr, FUTEX_WAIT|priv, val, 0) != -ENOSYS
- || __syscall(SYS_futex, addr, FUTEX_WAIT, val, 0);
-#else
- __wasilibc_futex_wait(addr, FUTEX_WAIT, val, -1);
-#endif
- }
- if (waiters) a_dec(waiters);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/call_once.c
@@ -1,7 +0,0 @@
-#include <threads.h>
-#include <pthread.h>
-
-void call_once(once_flag *flag, void (*func)(void))
-{
- __pthread_once(flag, func);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/clone.c
@@ -1,7 +0,0 @@
-#include <errno.h>
-#include "pthread_impl.h"
-
-int __clone(int (*func)(void *), void *stack, int flags, void *arg, ...)
-{
- return -ENOSYS;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/cnd_broadcast.c
@@ -1,9 +0,0 @@
-#include <threads.h>
-#include <pthread.h>
-
-int cnd_broadcast(cnd_t *c)
-{
- /* This internal function never fails, and always returns zero,
- * which matches the value thrd_success is defined with. */
- return __private_cond_signal((pthread_cond_t *)c, -1);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/cnd_destroy.c
@@ -1,6 +0,0 @@
-#include <threads.h>
-
-void cnd_destroy(cnd_t *c)
-{
- /* For private cv this is a no-op */
-}
lib/libc/wasi/libc-top-half/musl/src/thread/cnd_init.c
@@ -1,7 +0,0 @@
-#include <threads.h>
-
-int cnd_init(cnd_t *c)
-{
- *c = (cnd_t){ 0 };
- return thrd_success;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/cnd_signal.c
@@ -1,9 +0,0 @@
-#include <threads.h>
-#include <pthread.h>
-
-int cnd_signal(cnd_t *c)
-{
- /* This internal function never fails, and always returns zero,
- * which matches the value thrd_success is defined with. */
- return __private_cond_signal((pthread_cond_t *)c, 1);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/cnd_timedwait.c
@@ -1,14 +0,0 @@
-#include <threads.h>
-#include <pthread.h>
-#include <errno.h>
-
-int cnd_timedwait(cnd_t *restrict c, mtx_t *restrict m, const struct timespec *restrict ts)
-{
- int ret = __pthread_cond_timedwait((pthread_cond_t *)c, (pthread_mutex_t *)m, ts);
- switch (ret) {
- /* May also return EINVAL or EPERM. */
- default: return thrd_error;
- case 0: return thrd_success;
- case ETIMEDOUT: return thrd_timedout;
- }
-}
lib/libc/wasi/libc-top-half/musl/src/thread/cnd_wait.c
@@ -1,9 +0,0 @@
-#include <threads.h>
-
-int cnd_wait(cnd_t *c, mtx_t *m)
-{
- /* Calling cnd_timedwait with a null pointer is an extension.
- * It is convenient here to avoid duplication of the logic
- * for return values. */
- return cnd_timedwait(c, m, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/default_attr.c
@@ -1,4 +0,0 @@
-#include "pthread_impl.h"
-
-unsigned __default_stacksize = DEFAULT_STACK_SIZE;
-unsigned __default_guardsize = DEFAULT_GUARD_SIZE;
lib/libc/wasi/libc-top-half/musl/src/thread/lock_ptc.c
@@ -1,18 +0,0 @@
-#include <pthread.h>
-
-static pthread_rwlock_t lock = PTHREAD_RWLOCK_INITIALIZER;
-
-void __inhibit_ptc()
-{
- pthread_rwlock_wrlock(&lock);
-}
-
-void __acquire_ptc()
-{
- pthread_rwlock_rdlock(&lock);
-}
-
-void __release_ptc()
-{
- pthread_rwlock_unlock(&lock);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/mtx_destroy.c
@@ -1,5 +0,0 @@
-#include <threads.h>
-
-void mtx_destroy(mtx_t *mtx)
-{
-}
lib/libc/wasi/libc-top-half/musl/src/thread/mtx_init.c
@@ -1,10 +0,0 @@
-#include "pthread_impl.h"
-#include <threads.h>
-
-int mtx_init(mtx_t *m, int type)
-{
- *m = (mtx_t){
- ._m_type = ((type&mtx_recursive) ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL),
- };
- return thrd_success;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/mtx_lock.c
@@ -1,12 +0,0 @@
-#include "pthread_impl.h"
-#include <threads.h>
-
-int mtx_lock(mtx_t *m)
-{
- if (m->_m_type == PTHREAD_MUTEX_NORMAL && !a_cas(&m->_m_lock, 0, EBUSY))
- return thrd_success;
- /* Calling mtx_timedlock with a null pointer is an extension.
- * It is convenient, here to avoid duplication of the logic
- * for return values. */
- return mtx_timedlock(m, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/mtx_timedlock.c
@@ -1,13 +0,0 @@
-#include <threads.h>
-#include <pthread.h>
-#include <errno.h>
-
-int mtx_timedlock(mtx_t *restrict m, const struct timespec *restrict ts)
-{
- int ret = __pthread_mutex_timedlock((pthread_mutex_t *)m, ts);
- switch (ret) {
- default: return thrd_error;
- case 0: return thrd_success;
- case ETIMEDOUT: return thrd_timedout;
- }
-}
lib/libc/wasi/libc-top-half/musl/src/thread/mtx_trylock.c
@@ -1,15 +0,0 @@
-#include "pthread_impl.h"
-#include <threads.h>
-
-int mtx_trylock(mtx_t *m)
-{
- if (m->_m_type == PTHREAD_MUTEX_NORMAL)
- return (a_cas(&m->_m_lock, 0, EBUSY) & EBUSY) ? thrd_busy : thrd_success;
-
- int ret = __pthread_mutex_trylock((pthread_mutex_t *)m);
- switch (ret) {
- default: return thrd_error;
- case 0: return thrd_success;
- case EBUSY: return thrd_busy;
- }
-}
lib/libc/wasi/libc-top-half/musl/src/thread/mtx_unlock.c
@@ -1,10 +0,0 @@
-#include <threads.h>
-#include <pthread.h>
-
-int mtx_unlock(mtx_t *mtx)
-{
- /* The only cases where pthread_mutex_unlock can return an
- * error are undefined behavior for C11 mtx_unlock, so we can
- * assume it does not return an error and simply tail call. */
- return __pthread_mutex_unlock((pthread_mutex_t *)mtx);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_atfork.c
@@ -1,49 +0,0 @@
-#include <pthread.h>
-#include "libc.h"
-#include "lock.h"
-
-static struct atfork_funcs {
- void (*prepare)(void);
- void (*parent)(void);
- void (*child)(void);
- struct atfork_funcs *prev, *next;
-} *funcs;
-
-static volatile int lock[1];
-
-void __fork_handler(int who)
-{
- struct atfork_funcs *p;
- if (!funcs) return;
- if (who < 0) {
- LOCK(lock);
- for (p=funcs; p; p = p->next) {
- if (p->prepare) p->prepare();
- funcs = p;
- }
- } else {
- for (p=funcs; p; p = p->prev) {
- if (!who && p->parent) p->parent();
- else if (who && p->child) p->child();
- funcs = p;
- }
- UNLOCK(lock);
- }
-}
-
-int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))
-{
- struct atfork_funcs *new = malloc(sizeof *new);
- if (!new) return -1;
-
- LOCK(lock);
- new->next = funcs;
- new->prev = 0;
- new->prepare = prepare;
- new->parent = parent;
- new->child = child;
- if (funcs) funcs->prev = new;
- funcs = new;
- UNLOCK(lock);
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_destroy.c
@@ -1,6 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_attr_destroy(pthread_attr_t *a)
-{
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_get.c
@@ -1,102 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_attr_getdetachstate(const pthread_attr_t *a, int *state)
-{
- *state = a->_a_detach;
- return 0;
-}
-int pthread_attr_getguardsize(const pthread_attr_t *restrict a, size_t *restrict size)
-{
- *size = a->_a_guardsize;
- return 0;
-}
-
-int pthread_attr_getinheritsched(const pthread_attr_t *restrict a, int *restrict inherit)
-{
- *inherit = a->_a_sched;
- return 0;
-}
-
-#ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */
-int pthread_attr_getschedparam(const pthread_attr_t *restrict a, struct sched_param *restrict param)
-{
- param->sched_priority = a->_a_prio;
- return 0;
-}
-
-int pthread_attr_getschedpolicy(const pthread_attr_t *restrict a, int *restrict policy)
-{
- *policy = a->_a_policy;
- return 0;
-}
-#endif
-
-int pthread_attr_getscope(const pthread_attr_t *restrict a, int *restrict scope)
-{
- *scope = PTHREAD_SCOPE_SYSTEM;
- return 0;
-}
-
-int pthread_attr_getstack(const pthread_attr_t *restrict a, void **restrict addr, size_t *restrict size)
-{
- if (!a->_a_stackaddr)
- return EINVAL;
- *size = a->_a_stacksize;
- *addr = (void *)(a->_a_stackaddr - *size);
- return 0;
-}
-
-int pthread_attr_getstacksize(const pthread_attr_t *restrict a, size_t *restrict size)
-{
- *size = a->_a_stacksize;
- return 0;
-}
-
-int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict a, int *restrict pshared)
-{
- *pshared = !!a->__attr;
- return 0;
-}
-
-#ifdef __wasilibc_unmodified_upstream /* Forward declaration of WASI's `__clockid` type. */
-int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk)
-{
- *clk = a->__attr & 0x7fffffff;
- return 0;
-}
-#endif
-
-int pthread_condattr_getpshared(const pthread_condattr_t *restrict a, int *restrict pshared)
-{
- *pshared = a->__attr>>31;
- return 0;
-}
-
-int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *restrict a, int *restrict protocol)
-{
- *protocol = a->__attr / 8U % 2;
- return 0;
-}
-int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict a, int *restrict pshared)
-{
- *pshared = a->__attr / 128U % 2;
- return 0;
-}
-
-int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict a, int *restrict robust)
-{
- *robust = a->__attr / 4U % 2;
- return 0;
-}
-
-int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict a, int *restrict type)
-{
- *type = a->__attr & 3;
- return 0;
-}
-
-int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *restrict a, int *restrict pshared)
-{
- *pshared = a->__attr[0];
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_init.c
@@ -1,11 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_attr_init(pthread_attr_t *a)
-{
- *a = (pthread_attr_t){0};
- __acquire_ptc();
- a->_a_stacksize = __default_stacksize;
- a->_a_guardsize = __default_guardsize;
- __release_ptc();
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setdetachstate.c
@@ -1,8 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_attr_setdetachstate(pthread_attr_t *a, int state)
-{
- if (state > 1U) return EINVAL;
- a->_a_detach = state;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setguardsize.c
@@ -1,8 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_attr_setguardsize(pthread_attr_t *a, size_t size)
-{
- if (size > SIZE_MAX/8) return EINVAL;
- a->_a_guardsize = size;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setinheritsched.c
@@ -1,9 +0,0 @@
-#include "pthread_impl.h"
-#include "syscall.h"
-
-int pthread_attr_setinheritsched(pthread_attr_t *a, int inherit)
-{
- if (inherit > 1U) return EINVAL;
- a->_a_sched = inherit;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setschedparam.c
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_attr_setschedparam(pthread_attr_t *restrict a, const struct sched_param *restrict param)
-{
- a->_a_prio = param->sched_priority;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setschedpolicy.c
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_attr_setschedpolicy(pthread_attr_t *a, int policy)
-{
- a->_a_policy = policy;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setscope.c
@@ -1,13 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_attr_setscope(pthread_attr_t *a, int scope)
-{
- switch (scope) {
- case PTHREAD_SCOPE_SYSTEM:
- return 0;
- case PTHREAD_SCOPE_PROCESS:
- return ENOTSUP;
- default:
- return EINVAL;
- }
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setstack.c
@@ -1,9 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_attr_setstack(pthread_attr_t *a, void *addr, size_t size)
-{
- if (size-PTHREAD_STACK_MIN > SIZE_MAX/4) return EINVAL;
- a->_a_stackaddr = (size_t)addr + size;
- a->_a_stacksize = size;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setstacksize.c
@@ -1,9 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_attr_setstacksize(pthread_attr_t *a, size_t size)
-{
- if (size-PTHREAD_STACK_MIN > SIZE_MAX/4) return EINVAL;
- a->_a_stackaddr = 0;
- a->_a_stacksize = size;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_barrier_destroy.c
@@ -1,17 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_barrier_destroy(pthread_barrier_t *b)
-{
- if (b->_b_limit < 0) {
- if (b->_b_lock) {
- int v;
- a_or(&b->_b_lock, INT_MIN);
- while ((v = b->_b_lock) & INT_MAX)
- __wait(&b->_b_lock, 0, v, 0);
- }
-#ifdef __wasilibc_unmodified_upstream /* WASI does not understand processes or locking between them. */
- __vm_wait();
-#endif
- }
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_barrier_init.c
@@ -1,8 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_barrier_init(pthread_barrier_t *restrict b, const pthread_barrierattr_t *restrict a, unsigned count)
-{
- if (count-1 > INT_MAX-1) return EINVAL;
- *b = (pthread_barrier_t){ ._b_limit = count-1 | (a?a->__attr:0) };
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_barrier_wait.c
@@ -1,119 +0,0 @@
-#include "pthread_impl.h"
-
-static int pshared_barrier_wait(pthread_barrier_t *b)
-{
- int limit = (b->_b_limit & INT_MAX) + 1;
- int ret = 0;
- int v, w;
-
- if (limit==1) return PTHREAD_BARRIER_SERIAL_THREAD;
-
- while ((v=a_cas(&b->_b_lock, 0, limit)))
- __wait(&b->_b_lock, &b->_b_waiters, v, 0);
-
- /* Wait for <limit> threads to get to the barrier */
- if (++b->_b_count == limit) {
- a_store(&b->_b_count, 0);
- ret = PTHREAD_BARRIER_SERIAL_THREAD;
- if (b->_b_waiters2) __wake(&b->_b_count, -1, 0);
- } else {
- a_store(&b->_b_lock, 0);
- if (b->_b_waiters) __wake(&b->_b_lock, 1, 0);
- while ((v=b->_b_count)>0)
- __wait(&b->_b_count, &b->_b_waiters2, v, 0);
- }
-
-#ifdef __wasilibc_unmodified_upstream /* WASI does not understand processes or locking between them. */
- __vm_lock();
-#endif
-
- /* Ensure all threads have a vm lock before proceeding */
- if (a_fetch_add(&b->_b_count, -1)==1-limit) {
- a_store(&b->_b_count, 0);
- if (b->_b_waiters2) __wake(&b->_b_count, -1, 0);
- } else {
- while ((v=b->_b_count))
- __wait(&b->_b_count, &b->_b_waiters2, v, 0);
- }
-
- /* Perform a recursive unlock suitable for self-sync'd destruction */
- do {
- v = b->_b_lock;
- w = b->_b_waiters;
- } while (a_cas(&b->_b_lock, v, v==INT_MIN+1 ? 0 : v-1) != v);
-
- /* Wake a thread waiting to reuse or destroy the barrier */
- if (v==INT_MIN+1 || (v==1 && w))
- __wake(&b->_b_lock, 1, 0);
-
-#ifdef __wasilibc_unmodified_upstream /* WASI does not understand processes or locking between them. */
- __vm_unlock();
-#endif
-
- return ret;
-}
-
-struct instance
-{
- volatile int count;
- volatile int last;
- volatile int waiters;
- volatile int finished;
-};
-
-int pthread_barrier_wait(pthread_barrier_t *b)
-{
- int limit = b->_b_limit;
- struct instance *inst;
-
- /* Trivial case: count was set at 1 */
- if (!limit) return PTHREAD_BARRIER_SERIAL_THREAD;
-
- /* Process-shared barriers require a separate, inefficient wait */
- if (limit < 0) return pshared_barrier_wait(b);
-
- /* Otherwise we need a lock on the barrier object */
- while (a_swap(&b->_b_lock, 1))
- __wait(&b->_b_lock, &b->_b_waiters, 1, 1);
- inst = b->_b_inst;
-
- /* First thread to enter the barrier becomes the "instance owner" */
- if (!inst) {
- struct instance new_inst = { 0 };
- int spins = 200;
- b->_b_inst = inst = &new_inst;
- a_store(&b->_b_lock, 0);
- if (b->_b_waiters) __wake(&b->_b_lock, 1, 1);
- while (spins-- && !inst->finished)
- a_spin();
- a_inc(&inst->finished);
- while (inst->finished == 1)
-#ifdef __wasilibc_unmodified_upstream
- __syscall(SYS_futex,&inst->finished,FUTEX_WAIT|FUTEX_PRIVATE,1,0) != -ENOSYS
- || __syscall(SYS_futex,&inst->finished,FUTEX_WAIT,1,0);
-#else
- __futexwait(&inst->finished, 1, 0);
-#endif
- return PTHREAD_BARRIER_SERIAL_THREAD;
- }
-
- /* Last thread to enter the barrier wakes all non-instance-owners */
- if (++inst->count == limit) {
- b->_b_inst = 0;
- a_store(&b->_b_lock, 0);
- if (b->_b_waiters) __wake(&b->_b_lock, 1, 1);
- a_store(&inst->last, 1);
- if (inst->waiters)
- __wake(&inst->last, -1, 1);
- } else {
- a_store(&b->_b_lock, 0);
- if (b->_b_waiters) __wake(&b->_b_lock, 1, 1);
- __wait(&inst->last, &inst->waiters, 0, 1);
- }
-
- /* Last thread to exit the barrier wakes the instance owner */
- if (a_fetch_add(&inst->count,-1)==1 && a_fetch_add(&inst->finished,1))
- __wake(&inst->finished, 1, 1);
-
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_barrierattr_destroy.c
@@ -1,6 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_barrierattr_destroy(pthread_barrierattr_t *a)
-{
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_barrierattr_init.c
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_barrierattr_init(pthread_barrierattr_t *a)
-{
- *a = (pthread_barrierattr_t){0};
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cancel.c
@@ -1,101 +0,0 @@
-#define _GNU_SOURCE
-#include <string.h>
-#include "pthread_impl.h"
-#include "syscall.h"
-
-hidden long __cancel(), __syscall_cp_asm(), __syscall_cp_c();
-
-long __cancel()
-{
- pthread_t self = __pthread_self();
- if (self->canceldisable == PTHREAD_CANCEL_ENABLE || self->cancelasync)
- pthread_exit(PTHREAD_CANCELED);
- self->canceldisable = PTHREAD_CANCEL_DISABLE;
- return -ECANCELED;
-}
-
-long __syscall_cp_asm(volatile void *, syscall_arg_t,
- syscall_arg_t, syscall_arg_t, syscall_arg_t,
- syscall_arg_t, syscall_arg_t, syscall_arg_t);
-
-long __syscall_cp_c(syscall_arg_t nr,
- syscall_arg_t u, syscall_arg_t v, syscall_arg_t w,
- syscall_arg_t x, syscall_arg_t y, syscall_arg_t z)
-{
- pthread_t self;
- long r;
- int st;
-
- if ((st=(self=__pthread_self())->canceldisable)
- && (st==PTHREAD_CANCEL_DISABLE || nr==SYS_close))
- return __syscall(nr, u, v, w, x, y, z);
-
- r = __syscall_cp_asm(&self->cancel, nr, u, v, w, x, y, z);
- if (r==-EINTR && nr!=SYS_close && self->cancel &&
- self->canceldisable != PTHREAD_CANCEL_DISABLE)
- r = __cancel();
- return r;
-}
-
-static void _sigaddset(sigset_t *set, int sig)
-{
- unsigned s = sig-1;
- set->__bits[s/8/sizeof *set->__bits] |= 1UL<<(s&8*sizeof *set->__bits-1);
-}
-
-extern hidden const char __cp_begin[1], __cp_end[1], __cp_cancel[1];
-
-static void cancel_handler(int sig, siginfo_t *si, void *ctx)
-{
- pthread_t self = __pthread_self();
- ucontext_t *uc = ctx;
- uintptr_t pc = uc->uc_mcontext.MC_PC;
-
- a_barrier();
- if (!self->cancel || self->canceldisable == PTHREAD_CANCEL_DISABLE) return;
-
- _sigaddset(&uc->uc_sigmask, SIGCANCEL);
-
- if (self->cancelasync || pc >= (uintptr_t)__cp_begin && pc < (uintptr_t)__cp_end) {
- uc->uc_mcontext.MC_PC = (uintptr_t)__cp_cancel;
-#ifdef CANCEL_GOT
- uc->uc_mcontext.MC_GOT = CANCEL_GOT;
-#endif
- return;
- }
-
- __syscall(SYS_tkill, self->tid, SIGCANCEL);
-}
-
-void __testcancel()
-{
- pthread_t self = __pthread_self();
- if (self->cancel && !self->canceldisable)
- __cancel();
-}
-
-static void init_cancellation()
-{
- struct sigaction sa = {
- .sa_flags = SA_SIGINFO | SA_RESTART,
- .sa_sigaction = cancel_handler
- };
- memset(&sa.sa_mask, -1, _NSIG/8);
- __libc_sigaction(SIGCANCEL, &sa, 0);
-}
-
-int pthread_cancel(pthread_t t)
-{
- static int init;
- if (!init) {
- init_cancellation();
- init = 1;
- }
- a_store(&t->cancel, 1);
- if (t == pthread_self()) {
- if (t->canceldisable == PTHREAD_CANCEL_ENABLE && t->cancelasync)
- pthread_exit(PTHREAD_CANCELED);
- return 0;
- }
- return pthread_kill(t, SIGCANCEL);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cleanup_push.c
@@ -1,20 +0,0 @@
-#include "pthread_impl.h"
-
-static void dummy(struct __ptcb *cb)
-{
-}
-weak_alias(dummy, __do_cleanup_push);
-weak_alias(dummy, __do_cleanup_pop);
-
-void _pthread_cleanup_push(struct __ptcb *cb, void (*f)(void *), void *x)
-{
- cb->__f = f;
- cb->__x = x;
- __do_cleanup_push(cb);
-}
-
-void _pthread_cleanup_pop(struct __ptcb *cb, int run)
-{
- __do_cleanup_pop(cb);
- if (run) cb->__f(cb->__x);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cond_broadcast.c
@@ -1,10 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_cond_broadcast(pthread_cond_t *c)
-{
- if (!c->_c_shared) return __private_cond_signal(c, -1);
- if (!c->_c_waiters) return 0;
- a_inc(&c->_c_seq);
- __wake(&c->_c_seq, -1, 0);
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cond_destroy.c
@@ -1,14 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_cond_destroy(pthread_cond_t *c)
-{
- if (c->_c_shared && c->_c_waiters) {
- int cnt;
- a_or(&c->_c_waiters, 0x80000000);
- a_inc(&c->_c_seq);
- __wake(&c->_c_seq, -1, 0);
- while ((cnt = c->_c_waiters) & 0x7fffffff)
- __wait(&c->_c_waiters, 0, cnt, 0);
- }
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cond_init.c
@@ -1,11 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_cond_init(pthread_cond_t *restrict c, const pthread_condattr_t *restrict a)
-{
- *c = (pthread_cond_t){0};
- if (a) {
- c->_c_clock = a->__attr & 0x7fffffff;
- if (a->__attr>>31) c->_c_shared = (void *)-1;
- }
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cond_signal.c
@@ -1,10 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_cond_signal(pthread_cond_t *c)
-{
- if (!c->_c_shared) return __private_cond_signal(c, 1);
- if (!c->_c_waiters) return 0;
- a_inc(&c->_c_seq);
- __wake(&c->_c_seq, 1, 0);
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cond_timedwait.c
@@ -1,230 +0,0 @@
-#include "pthread_impl.h"
-
-#ifndef __wasilibc_unmodified_upstream
-#include <common/clock.h>
-#endif
-
-/*
- * struct waiter
- *
- * Waiter objects have automatic storage on the waiting thread, and
- * are used in building a linked list representing waiters currently
- * waiting on the condition variable or a group of waiters woken
- * together by a broadcast or signal; in the case of signal, this is a
- * degenerate list of one member.
- *
- * Waiter lists attached to the condition variable itself are
- * protected by the lock on the cv. Detached waiter lists are never
- * modified again, but can only be traversed in reverse order, and are
- * protected by the "barrier" locks in each node, which are unlocked
- * in turn to control wake order.
- *
- * Since process-shared cond var semantics do not necessarily allow
- * one thread to see another's automatic storage (they may be in
- * different processes), the waiter list is not used for the
- * process-shared case, but the structure is still used to store data
- * needed by the cancellation cleanup handler.
- */
-
-struct waiter {
- struct waiter *prev, *next;
- volatile int state, barrier;
- volatile int *notify;
-};
-
-/* Self-synchronized-destruction-safe lock functions */
-
-static inline void lock(volatile int *l)
-{
- if (a_cas(l, 0, 1)) {
- a_cas(l, 1, 2);
- do __wait(l, 0, 2, 1);
- while (a_cas(l, 0, 2));
- }
-}
-
-static inline void unlock(volatile int *l)
-{
- if (a_swap(l, 0)==2)
- __wake(l, 1, 1);
-}
-
-static inline void unlock_requeue(volatile int *l, volatile int *r, int w)
-{
- a_store(l, 0);
-#ifdef __wasilibc_unmodified_upstream
- if (w) __wake(l, 1, 1);
- else __syscall(SYS_futex, l, FUTEX_REQUEUE|FUTEX_PRIVATE, 0, 1, r) != -ENOSYS
- || __syscall(SYS_futex, l, FUTEX_REQUEUE, 0, 1, r);
-#else
- // Always wake due to lack of requeue system call in WASI
- // This can impact the performance, so we might need to re-visit that decision
- __wake(l, 1, 1);
-#endif
-}
-
-enum {
- WAITING,
- SIGNALED,
- LEAVING,
-};
-
-int __pthread_cond_timedwait(pthread_cond_t *restrict c, pthread_mutex_t *restrict m, const struct timespec *restrict ts)
-{
- struct waiter node = { 0 };
- int e, seq, clock = c->_c_clock, cs, shared=0, oldstate, tmp;
-#ifndef __wasilibc_unmodified_upstream
- struct __clockid clock_id = { .id = clock };
-#endif
- volatile int *fut;
-
- if ((m->_m_type&15) && (m->_m_lock&INT_MAX) != __pthread_self()->tid)
- return EPERM;
-
- if (ts && ts->tv_nsec >= 1000000000UL)
- return EINVAL;
-
- __pthread_testcancel();
-
- if (c->_c_shared) {
- shared = 1;
- fut = &c->_c_seq;
- seq = c->_c_seq;
- a_inc(&c->_c_waiters);
- } else {
- lock(&c->_c_lock);
-
- seq = node.barrier = 2;
- fut = &node.barrier;
- node.state = WAITING;
- node.next = c->_c_head;
- c->_c_head = &node;
- if (!c->_c_tail) c->_c_tail = &node;
- else node.next->prev = &node;
-
- unlock(&c->_c_lock);
- }
-
- __pthread_mutex_unlock(m);
-
- __pthread_setcancelstate(PTHREAD_CANCEL_MASKED, &cs);
- if (cs == PTHREAD_CANCEL_DISABLE) __pthread_setcancelstate(cs, 0);
-
-#ifdef __wasilibc_unmodified_upstream
- do e = __timedwait_cp(fut, seq, clock, ts, !shared);
-#else
- do e = __timedwait_cp(fut, seq, &clock_id, ts, !shared);
-#endif
- while (*fut==seq && (!e || e==EINTR));
- if (e == EINTR) e = 0;
-
- if (shared) {
- /* Suppress cancellation if a signal was potentially
- * consumed; this is a legitimate form of spurious
- * wake even if not. */
- if (e == ECANCELED && c->_c_seq != seq) e = 0;
- if (a_fetch_add(&c->_c_waiters, -1) == -0x7fffffff)
- __wake(&c->_c_waiters, 1, 0);
- oldstate = WAITING;
- goto relock;
- }
-
- oldstate = a_cas(&node.state, WAITING, LEAVING);
-
- if (oldstate == WAITING) {
- /* Access to cv object is valid because this waiter was not
- * yet signaled and a new signal/broadcast cannot return
- * after seeing a LEAVING waiter without getting notified
- * via the futex notify below. */
-
- lock(&c->_c_lock);
-
- if (c->_c_head == &node) c->_c_head = node.next;
- else if (node.prev) node.prev->next = node.next;
- if (c->_c_tail == &node) c->_c_tail = node.prev;
- else if (node.next) node.next->prev = node.prev;
-
- unlock(&c->_c_lock);
-
- if (node.notify) {
- if (a_fetch_add(node.notify, -1)==1)
- __wake(node.notify, 1, 1);
- }
- } else {
- /* Lock barrier first to control wake order. */
- lock(&node.barrier);
- }
-
-relock:
- /* Errors locking the mutex override any existing error or
- * cancellation, since the caller must see them to know the
- * state of the mutex. */
- if ((tmp = pthread_mutex_lock(m))) e = tmp;
-
- if (oldstate == WAITING) goto done;
-
- if (!node.next && !(m->_m_type & 8))
- a_inc(&m->_m_waiters);
-
- /* Unlock the barrier that's holding back the next waiter, and
- * either wake it or requeue it to the mutex. */
- if (node.prev) {
- int val = m->_m_lock;
- if (val>0) a_cas(&m->_m_lock, val, val|0x80000000);
- unlock_requeue(&node.prev->barrier, &m->_m_lock, m->_m_type & (8|128));
- } else if (!(m->_m_type & 8)) {
- a_dec(&m->_m_waiters);
- }
-
- /* Since a signal was consumed, cancellation is not permitted. */
- if (e == ECANCELED) e = 0;
-
-done:
- __pthread_setcancelstate(cs, 0);
-
- if (e == ECANCELED) {
- __pthread_testcancel();
- __pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0);
- }
-
- return e;
-}
-
-int __private_cond_signal(pthread_cond_t *c, int n)
-{
- struct waiter *p, *first=0;
- volatile int ref = 0;
- int cur;
-
- lock(&c->_c_lock);
- for (p=c->_c_tail; n && p; p=p->prev) {
- if (a_cas(&p->state, WAITING, SIGNALED) != WAITING) {
- ref++;
- p->notify = &ref;
- } else {
- n--;
- if (!first) first=p;
- }
- }
- /* Split the list, leaving any remainder on the cv. */
- if (p) {
- if (p->next) p->next->prev = 0;
- p->next = 0;
- } else {
- c->_c_head = 0;
- }
- c->_c_tail = p;
- unlock(&c->_c_lock);
-
- /* Wait for any waiters in the LEAVING state to remove
- * themselves from the list before returning or allowing
- * signaled threads to proceed. */
- while ((cur = ref)) __wait(&ref, 0, cur, 1);
-
- /* Allow first signaled waiter, if any, to proceed. */
- if (first) unlock(&first->barrier);
-
- return 0;
-}
-
-weak_alias(__pthread_cond_timedwait, pthread_cond_timedwait);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cond_wait.c
@@ -1,6 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_cond_wait(pthread_cond_t *restrict c, pthread_mutex_t *restrict m)
-{
- return pthread_cond_timedwait(c, m, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_condattr_destroy.c
@@ -1,6 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_condattr_destroy(pthread_condattr_t *a)
-{
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_condattr_init.c
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_condattr_init(pthread_condattr_t *a)
-{
- *a = (pthread_condattr_t){0};
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_condattr_setclock.c
@@ -1,21 +0,0 @@
-#include "pthread_impl.h"
-
-#ifndef __wasilibc_unmodified_upstream
-#include <common/clock.h>
-#endif
-
-int pthread_condattr_setclock(pthread_condattr_t *a, clockid_t clk)
-{
-#ifdef __wasilibc_unmodified_upstream
- if (clk < 0 || clk-2U < 2) return EINVAL;
-#else
- if (clk->id < 0 || clk->id-2U < 2) return EINVAL;
-#endif
- a->__attr &= 0x80000000;
-#ifdef __wasilibc_unmodified_upstream
- a->__attr |= clk;
-#else
- a->__attr |= clk->id;
-#endif
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_create.c
@@ -1,585 +0,0 @@
-#define _GNU_SOURCE
-#include "pthread_impl.h"
-#include "stdio_impl.h"
-#include "libc.h"
-#include "lock.h"
-#ifdef __wasilibc_unmodified_upstream
-#include <sys/mman.h>
-#endif
-#include <string.h>
-#include <stddef.h>
-#ifndef __wasilibc_unmodified_upstream
-#include <stdatomic.h>
-#endif
-
-#include <stdalign.h>
-
-static void dummy_0()
-{
-}
-weak_alias(dummy_0, __acquire_ptc);
-weak_alias(dummy_0, __release_ptc);
-weak_alias(dummy_0, __pthread_tsd_run_dtors);
-weak_alias(dummy_0, __do_orphaned_stdio_locks);
-#ifdef __wasilibc_unmodified_upstream
-weak_alias(dummy_0, __dl_thread_cleanup);
-weak_alias(dummy_0, __membarrier_init);
-#endif
-
-static int tl_lock_count;
-static int tl_lock_waiters;
-
-void __tl_lock(void)
-{
- int tid = __pthread_self()->tid;
- int val = __thread_list_lock;
- if (val == tid) {
- tl_lock_count++;
- return;
- }
- while ((val = a_cas(&__thread_list_lock, 0, tid)))
- __wait(&__thread_list_lock, &tl_lock_waiters, val, 0);
-}
-
-void __tl_unlock(void)
-{
- if (tl_lock_count) {
- tl_lock_count--;
- return;
- }
- a_store(&__thread_list_lock, 0);
- if (tl_lock_waiters) __wake(&__thread_list_lock, 1, 0);
-}
-
-void __tl_sync(pthread_t td)
-{
- a_barrier();
- int val = __thread_list_lock;
- if (!val) return;
- __wait(&__thread_list_lock, &tl_lock_waiters, val, 0);
- if (tl_lock_waiters) __wake(&__thread_list_lock, 1, 0);
-}
-
-#ifdef __wasilibc_unmodified_upstream
-_Noreturn void __pthread_exit(void *result)
-#else
-static void __pthread_exit(void *result)
-#endif
-{
- pthread_t self = __pthread_self();
- sigset_t set;
-
- self->canceldisable = 1;
- self->cancelasync = 0;
- self->result = result;
-
- while (self->cancelbuf) {
- void (*f)(void *) = self->cancelbuf->__f;
- void *x = self->cancelbuf->__x;
- self->cancelbuf = self->cancelbuf->__next;
- f(x);
- }
-
- __pthread_tsd_run_dtors();
-
-#ifdef __wasilibc_unmodified_upstream
- __block_app_sigs(&set);
-#endif
-
- /* This atomic potentially competes with a concurrent pthread_detach
- * call; the loser is responsible for freeing thread resources. */
- int state = a_cas(&self->detach_state, DT_JOINABLE, DT_EXITING);
-
- if (state==DT_DETACHED && self->map_base) {
- /* Since __unmapself bypasses the normal munmap code path,
- * explicitly wait for vmlock holders first. This must be
- * done before any locks are taken, to avoid lock ordering
- * issues that could lead to deadlock. */
-#ifdef __wasilibc_unmodified_upstream
- __vm_wait();
-#endif
- }
-
- /* Access to target the exiting thread with syscalls that use
- * its kernel tid is controlled by killlock. For detached threads,
- * any use past this point would have undefined behavior, but for
- * joinable threads it's a valid usage that must be handled.
- * Signals must be blocked since pthread_kill must be AS-safe. */
- LOCK(self->killlock);
-
- /* The thread list lock must be AS-safe, and thus depends on
- * application signals being blocked above. */
- __tl_lock();
-
- /* If this is the only thread in the list, don't proceed with
- * termination of the thread, but restore the previous lock and
- * signal state to prepare for exit to call atexit handlers. */
- if (self->next == self) {
- __tl_unlock();
- UNLOCK(self->killlock);
- self->detach_state = state;
-#ifdef __wasilibc_unmodified_upstream
- __restore_sigs(&set);
-#endif
- exit(0);
- }
-
- /* At this point we are committed to thread termination. */
-
-#ifdef __wasilibc_unmodified_upstream
- /* Process robust list in userspace to handle non-pshared mutexes
- * and the detached thread case where the robust list head will
- * be invalid when the kernel would process it. */
- __vm_lock();
-#endif
- volatile void *volatile *rp;
- while ((rp=self->robust_list.head) && rp != &self->robust_list.head) {
- pthread_mutex_t *m = (void *)((char *)rp
- - offsetof(pthread_mutex_t, _m_next));
- int waiters = m->_m_waiters;
- int priv = (m->_m_type & 128) ^ 128;
- self->robust_list.pending = rp;
- self->robust_list.head = *rp;
- int cont = a_swap(&m->_m_lock, 0x40000000);
- self->robust_list.pending = 0;
- if (cont < 0 || waiters)
- __wake(&m->_m_lock, 1, priv);
- }
-#ifdef __wasilibc_unmodified_upstream
- __vm_unlock();
-#endif
-
- __do_orphaned_stdio_locks();
-#ifdef __wasilibc_unmodified_upstream
- __dl_thread_cleanup();
-#endif
-
- /* Last, unlink thread from the list. This change will not be visible
- * until the lock is released, which only happens after SYS_exit
- * has been called, via the exit futex address pointing at the lock.
- * This needs to happen after any possible calls to LOCK() that might
- * skip locking if process appears single-threaded. */
- if (!--libc.threads_minus_1) libc.need_locks = -1;
- self->next->prev = self->prev;
- self->prev->next = self->next;
- self->prev = self->next = self;
-
-#ifndef __wasilibc_unmodified_upstream
- /* On Linux, the thread is created with CLONE_CHILD_CLEARTID,
- * and this lock will unlock by kernel when this thread terminates.
- * So we should unlock it here in WebAssembly.
- * See also set_tid_address(2) */
- __tl_unlock();
-#endif
-
-#ifdef __wasilibc_unmodified_upstream
- if (state==DT_DETACHED && self->map_base) {
- /* Detached threads must block even implementation-internal
- * signals, since they will not have a stack in their last
- * moments of existence. */
- __block_all_sigs(&set);
-
- /* Robust list will no longer be valid, and was already
- * processed above, so unregister it with the kernel. */
- if (self->robust_list.off)
- __syscall(SYS_set_robust_list, 0, 3*sizeof(long));
-
- /* The following call unmaps the thread's stack mapping
- * and then exits without touching the stack. */
- __unmapself(self->map_base, self->map_size);
- }
-#else
- if (state==DT_DETACHED && self->map_base) {
- // __syscall(SYS_exit) would unlock the thread, list
- // do it manually here
- __tl_unlock();
- free(self->map_base);
- // Can't use `exit()` here, because it is too high level
- return;
- }
-#endif
-
- /* Wake any joiner. */
- a_store(&self->detach_state, DT_EXITED);
- __wake(&self->detach_state, 1, 1);
-
- /* After the kernel thread exits, its tid may be reused. Clear it
- * to prevent inadvertent use and inform functions that would use
- * it that it's no longer available. */
- self->tid = 0;
- UNLOCK(self->killlock);
-
-#ifdef __wasilibc_unmodified_upstream
- for (;;) __syscall(SYS_exit, 0);
-#else
- // __syscall(SYS_exit) would unlock the thread, list
- // do it manually here
- __tl_unlock();
- // Can't use `exit()` here, because it is too high level
-#endif
-}
-
-void __do_cleanup_push(struct __ptcb *cb)
-{
- struct pthread *self = __pthread_self();
- cb->__next = self->cancelbuf;
- self->cancelbuf = cb;
-}
-
-void __do_cleanup_pop(struct __ptcb *cb)
-{
- __pthread_self()->cancelbuf = cb->__next;
-}
-
-struct start_args {
-#ifdef __wasilibc_unmodified_upstream
- void *(*start_func)(void *);
- void *start_arg;
- volatile int control;
- unsigned long sig_mask[_NSIG/8/sizeof(long)];
-#else
- /*
- * Note: the offset of the "stack" and "tls_base" members
- * in this structure is hardcoded in wasi_thread_start.
- */
- void *stack;
- void *tls_base;
- void *(*start_func)(void *);
- void *start_arg;
-#endif
-};
-
-#ifdef __wasilibc_unmodified_upstream
-static int start(void *p)
-{
- struct start_args *args = p;
- int state = args->control;
- if (state) {
- if (a_cas(&args->control, 1, 2)==1)
- __wait(&args->control, 0, 2, 1);
- if (args->control) {
-#ifdef __wasilibc_unmodified_upstream
- __syscall(SYS_set_tid_address, &args->control);
- for (;;) __syscall(SYS_exit, 0);
-#endif
- }
- }
-#ifdef __wasilibc_unmodified_upstream
- __syscall(SYS_rt_sigprocmask, SIG_SETMASK, &args->sig_mask, 0, _NSIG/8);
-#endif
- __pthread_exit(args->start_func(args->start_arg));
- return 0;
-}
-
-static int start_c11(void *p)
-{
- struct start_args *args = p;
- int (*start)(void*) = (int(*)(void*)) args->start_func;
- __pthread_exit((void *)(uintptr_t)start(args->start_arg));
- return 0;
-}
-#else
-
-/*
- * We want to ensure wasi_thread_start is linked whenever
- * pthread_create is used. The following reference is to ensure that.
- * Otherwise, the linker doesn't notice the dependency because
- * wasi_thread_start is used indirectly via a wasm export.
- */
-void wasi_thread_start(int tid, void *p);
-hidden void *__dummy_reference = wasi_thread_start;
-
-hidden void __wasi_thread_start_C(int tid, void *p)
-{
- struct start_args *args = p;
- pthread_t self = __pthread_self();
- // Set the thread ID (TID) on the pthread structure. The TID is stored
- // atomically since it is also stored by the parent thread; this way,
- // whichever thread (parent or child) reaches this point first can proceed
- // without waiting.
- atomic_store((atomic_int *) &(self->tid), tid);
- // Execute the user's start function.
- __pthread_exit(args->start_func(args->start_arg));
-}
-#endif
-
-#ifdef __wasilibc_unmodified_upstream
-#define ROUND(x) (((x)+PAGE_SIZE-1)&-PAGE_SIZE)
-#else
-/*
- * As we allocate stack with malloc() instead of mmap/mprotect,
- * there is no point to round it up to PAGE_SIZE.
- * Instead, round up to a sane alignment.
- * Note: PAGE_SIZE is rather big on WASM. (65536)
- */
-#define ROUND(x) (((x)+16-1)&-16)
-#endif
-
-/* pthread_key_create.c overrides this */
-static volatile size_t dummy = 0;
-weak_alias(dummy, __pthread_tsd_size);
-static void *dummy_tsd[1] = { 0 };
-weak_alias(dummy_tsd, __pthread_tsd_main);
-
-static FILE *volatile dummy_file = 0;
-weak_alias(dummy_file, __stdin_used);
-weak_alias(dummy_file, __stdout_used);
-weak_alias(dummy_file, __stderr_used);
-
-static void init_file_lock(FILE *f)
-{
- if (f && f->lock<0) f->lock = 0;
-}
-
-int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp, void *(*entry)(void *), void *restrict arg)
-{
- int ret, c11 = (attrp == __ATTRP_C11_THREAD);
- size_t size, guard;
- struct pthread *self, *new;
- unsigned char *map = 0, *stack = 0, *tsd = 0, *stack_limit;
-#ifdef __wasilibc_unmodified_upstream
- unsigned flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND
- | CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS
- | CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID | CLONE_DETACHED;
-#endif
- pthread_attr_t attr = { 0 };
- sigset_t set;
-#ifndef __wasilibc_unmodified_upstream
- size_t tls_size = __builtin_wasm_tls_size();
- size_t tls_align = __builtin_wasm_tls_align();
- void* tls_base = __builtin_wasm_tls_base();
- void* new_tls_base;
- size_t tls_offset;
- tls_size += tls_align;
-#endif
-
-#ifdef __wasilibc_unmodified_upstream
- if (!libc.can_do_threads) return ENOSYS;
-#endif
- self = __pthread_self();
- if (!libc.threaded) {
- for (FILE *f=*__ofl_lock(); f; f=f->next)
- init_file_lock(f);
- __ofl_unlock();
- init_file_lock(__stdin_used);
- init_file_lock(__stdout_used);
- init_file_lock(__stderr_used);
-#ifdef __wasilibc_unmodified_upstream
- __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, SIGPT_SET, 0, _NSIG/8);
-#endif
- self->tsd = (void **)__pthread_tsd_main;
-#ifdef __wasilibc_unmodified_upstream
- __membarrier_init();
-#endif
- libc.threaded = 1;
- }
- if (attrp && !c11) attr = *attrp;
-
- __acquire_ptc();
- if (!attrp || c11) {
- attr._a_stacksize = __default_stacksize;
- attr._a_guardsize = __default_guardsize;
- }
-
- if (attr._a_stackaddr) {
-#ifdef __wasilibc_unmodified_upstream
- size_t need = libc.tls_size + __pthread_tsd_size;
-#else
- size_t need = tls_size + __pthread_tsd_size;
-#endif
- size = attr._a_stacksize;
- stack = (void *)(attr._a_stackaddr & -16);
- stack_limit = (void *)(attr._a_stackaddr - size);
- /* Use application-provided stack for TLS only when
- * it does not take more than ~12% or 2k of the
- * application's stack space. */
- if (need < size/8 && need < 2048) {
- tsd = stack - __pthread_tsd_size;
-#ifdef __wasilibc_unmodified_upstream
- stack = tsd - libc.tls_size;
-#else
- stack = tsd - tls_size;
-#endif
- memset(stack, 0, need);
- } else {
- size = ROUND(need);
- }
- guard = 0;
- } else {
- guard = ROUND(attr._a_guardsize);
- size = guard + ROUND(attr._a_stacksize
-#ifdef __wasilibc_unmodified_upstream
- + libc.tls_size + __pthread_tsd_size);
-#else
- + tls_size + __pthread_tsd_size);
-#endif
- }
-
- if (!tsd) {
-#ifdef __wasilibc_unmodified_upstream
- if (guard) {
- map = __mmap(0, size, PROT_NONE, MAP_PRIVATE|MAP_ANON, -1, 0);
- if (map == MAP_FAILED) goto fail;
- if (__mprotect(map+guard, size-guard, PROT_READ|PROT_WRITE)
- && errno != ENOSYS) {
- __munmap(map, size);
- goto fail;
- }
- } else {
- map = __mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
- if (map == MAP_FAILED) goto fail;
- }
-#else
- map = malloc(size);
- if (!map) goto fail;
-#endif
- tsd = map + size - __pthread_tsd_size;
- if (!stack) {
-#ifdef __wasilibc_unmodified_upstream
- stack = tsd - libc.tls_size;
-#else
- stack = tsd - tls_size;
-#endif
- stack_limit = map + guard;
- }
- }
-
-#ifdef __wasilibc_unmodified_upstream
- new = __copy_tls(tsd - libc.tls_size);
-#else
- new_tls_base = __copy_tls(tsd - tls_size);
- tls_offset = new_tls_base - tls_base;
- new = (void*)((uintptr_t)self + tls_offset);
-#endif
- new->map_base = map;
- new->map_size = size;
- new->stack = stack;
- new->stack_size = stack - stack_limit;
- new->guard_size = guard;
- new->self = new;
- new->tsd = (void *)tsd;
- new->locale = &libc.global_locale;
- if (attr._a_detach) {
- new->detach_state = DT_DETACHED;
- } else {
- new->detach_state = DT_JOINABLE;
- }
- new->robust_list.head = &new->robust_list.head;
- new->canary = self->canary;
- new->sysinfo = self->sysinfo;
-
- /* Setup argument structure for the new thread on its stack.
- * It's safe to access from the caller only until the thread
- * list is unlocked. */
-#ifdef __wasilibc_unmodified_upstream
- stack -= (uintptr_t)stack % sizeof(uintptr_t);
- stack -= sizeof(struct start_args);
- struct start_args *args = (void *)stack;
- args->start_func = entry;
- args->start_arg = arg;
- args->control = attr._a_sched ? 1 : 0;
-
- /* Application signals (but not the synccall signal) must be
- * blocked before the thread list lock can be taken, to ensure
- * that the lock is AS-safe. */
- __block_app_sigs(&set);
-
- /* Ensure SIGCANCEL is unblocked in new thread. This requires
- * working with a copy of the set so we can restore the
- * original mask in the calling thread. */
- memcpy(&args->sig_mask, &set, sizeof args->sig_mask);
- args->sig_mask[(SIGCANCEL-1)/8/sizeof(long)] &=
- ~(1UL<<((SIGCANCEL-1)%(8*sizeof(long))));
-#else
- /* Align the stack to struct start_args */
- stack -= sizeof(struct start_args);
- stack -= (uintptr_t)stack % alignof(struct start_args);
- struct start_args *args = (void *)stack;
-
- /* Align the stack to 16 and store it */
- new->stack = (void *)((uintptr_t) stack & -16);
- /* Correct the stack size */
- new->stack_size = stack - stack_limit;
-
- args->stack = new->stack; /* just for convenience of asm trampoline */
- args->start_func = entry;
- args->start_arg = arg;
- args->tls_base = (void*)new_tls_base;
-#endif
-
- __tl_lock();
- if (!libc.threads_minus_1++) libc.need_locks = 1;
-#ifdef __wasilibc_unmodified_upstream
- ret = __clone((c11 ? start_c11 : start), stack, flags, args, &new->tid, TP_ADJ(new), &__thread_list_lock);
-#else
- /* Instead of `__clone`, WASI uses a host API to instantiate a new version
- * of the current module and start executing the entry function. The
- * wasi-threads specification requires the module to export a
- * `wasi_thread_start` function, which is invoked with `args`. */
- ret = __wasi_thread_spawn((void *) args);
-#endif
-
-#ifdef __wasilibc_unmodified_upstream
- /* All clone failures translate to EAGAIN. If explicit scheduling
- * was requested, attempt it before unlocking the thread list so
- * that the failed thread is never exposed and so that we can
- * clean up all transient resource usage before returning. */
- if (ret < 0) {
- ret = -EAGAIN;
- } else if (attr._a_sched) {
- ret = __syscall(SYS_sched_setscheduler,
- new->tid, attr._a_policy, &attr._a_prio);
- if (a_swap(&args->control, ret ? 3 : 0)==2)
- __wake(&args->control, 1, 1);
- if (ret)
- __wait(&args->control, 0, 3, 0);
- }
-#else
- /* `wasi_thread_spawn` will either return a host-provided thread ID (TID)
- * (`>= 0`) or an error code (`< 0`). As in the unmodified version, all
- * spawn failures translate to EAGAIN; unlike the modified version, there is
- * no need to "start up" the child thread--the host does this. If the spawn
- * did succeed, then we store the TID atomically, since this parent thread
- * is racing with the child thread to set this field; this way, whichever
- * thread reaches this point first can continue without waiting. */
- if (ret < 0) {
- ret = -EAGAIN;
- } else {
- atomic_store((atomic_int *) &(new->tid), ret);
- }
-#endif
-
- if (ret >= 0) {
- new->next = self->next;
- new->prev = self;
- new->next->prev = new;
- new->prev->next = new;
- } else {
- if (!--libc.threads_minus_1) libc.need_locks = 0;
- }
- __tl_unlock();
-#ifdef __wasilibc_unmodified_upstream
- __restore_sigs(&set);
-#endif
- __release_ptc();
-
- if (ret < 0) {
-#ifdef __wasilibc_unmodified_upstream
- if (map) __munmap(map, size);
-#else
- free(map);
-#endif
- return -ret;
- }
-
- *res = new;
- return 0;
-fail:
- __release_ptc();
- return EAGAIN;
-}
-
-#ifdef __wasilibc_unmodified_upstream
-weak_alias(__pthread_exit, pthread_exit);
-#endif
-weak_alias(__pthread_create, pthread_create);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_detach.c
@@ -1,14 +0,0 @@
-#include "pthread_impl.h"
-#include <threads.h>
-
-static int __pthread_detach(pthread_t t)
-{
- /* If the cas fails, detach state is either already-detached
- * or exiting/exited, and pthread_join will trap or cleanup. */
- if (a_cas(&t->detach_state, DT_JOINABLE, DT_DETACHED) != DT_JOINABLE)
- return __pthread_join(t, 0);
- return 0;
-}
-
-weak_alias(__pthread_detach, pthread_detach);
-weak_alias(__pthread_detach, thrd_detach);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_equal.c
@@ -1,10 +0,0 @@
-#include <pthread.h>
-#include <threads.h>
-
-static int __pthread_equal(pthread_t a, pthread_t b)
-{
- return a==b;
-}
-
-weak_alias(__pthread_equal, pthread_equal);
-weak_alias(__pthread_equal, thrd_equal);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_getattr_np.c
@@ -1,24 +0,0 @@
-#define _GNU_SOURCE
-#include "pthread_impl.h"
-#include "libc.h"
-#include <sys/mman.h>
-
-int pthread_getattr_np(pthread_t t, pthread_attr_t *a)
-{
- *a = (pthread_attr_t){0};
- a->_a_detach = t->detach_state>=DT_DETACHED;
- a->_a_guardsize = t->guard_size;
- if (t->stack) {
- a->_a_stackaddr = (uintptr_t)t->stack;
- a->_a_stacksize = t->stack_size;
- } else {
- char *p = (void *)libc.auxv;
- size_t l = PAGE_SIZE;
- p += -(uintptr_t)p & PAGE_SIZE-1;
- a->_a_stackaddr = (uintptr_t)p;
- while (mremap(p-l-PAGE_SIZE, PAGE_SIZE, 2*PAGE_SIZE, 0)==MAP_FAILED && errno==ENOMEM)
- l += PAGE_SIZE;
- a->_a_stacksize = l;
- }
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_getconcurrency.c
@@ -1,6 +0,0 @@
-#include <pthread.h>
-
-int pthread_getconcurrency()
-{
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_getcpuclockid.c
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_getcpuclockid(pthread_t t, clockid_t *clockid)
-{
- *clockid = (-t->tid-1)*8U + 6;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_getname_np.c
@@ -1,25 +0,0 @@
-#define _GNU_SOURCE
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/prctl.h>
-
-#include "pthread_impl.h"
-
-int pthread_getname_np(pthread_t thread, char *name, size_t len)
-{
- int fd, cs, status = 0;
- char f[sizeof "/proc/self/task//comm" + 3*sizeof(int)];
-
- if (len < 16) return ERANGE;
-
- if (thread == pthread_self())
- return prctl(PR_GET_NAME, (unsigned long)name, 0UL, 0UL, 0UL) ? errno : 0;
-
- snprintf(f, sizeof f, "/proc/self/task/%d/comm", thread->tid);
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
- if ((fd = open(f, O_RDONLY|O_CLOEXEC)) < 0 || (len = read(fd, name, len)) == -1) status = errno;
- else name[len-1] = 0; /* remove trailing new line only if successful */
- if (fd >= 0) close(fd);
- pthread_setcancelstate(cs, 0);
- return status;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_getschedparam.c
@@ -1,21 +0,0 @@
-#include "pthread_impl.h"
-#include "lock.h"
-
-int pthread_getschedparam(pthread_t t, int *restrict policy, struct sched_param *restrict param)
-{
- int r;
- sigset_t set;
- __block_app_sigs(&set);
- LOCK(t->killlock);
- if (!t->tid) {
- r = ESRCH;
- } else {
- r = -__syscall(SYS_sched_getparam, t->tid, param);
- if (!r) {
- *policy = __syscall(SYS_sched_getscheduler, t->tid);
- }
- }
- UNLOCK(t->killlock);
- __restore_sigs(&set);
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_getspecific.c
@@ -1,11 +0,0 @@
-#include "pthread_impl.h"
-#include <threads.h>
-
-static void *__pthread_getspecific(pthread_key_t k)
-{
- struct pthread *self = __pthread_self();
- return self->tsd[k];
-}
-
-weak_alias(__pthread_getspecific, pthread_getspecific);
-weak_alias(__pthread_getspecific, tss_get);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_join.c
@@ -1,46 +0,0 @@
-#define _GNU_SOURCE
-#include "pthread_impl.h"
-#ifdef __wasilibc_unmodified_upstream
-#include <sys/mman.h>
-#endif
-
-static void dummy1(pthread_t t)
-{
-}
-weak_alias(dummy1, __tl_sync);
-
-static int __pthread_timedjoin_np(pthread_t t, void **res, const struct timespec *at)
-{
- int state, cs, r = 0;
- __pthread_testcancel();
- __pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
- if (cs == PTHREAD_CANCEL_ENABLE) __pthread_setcancelstate(cs, 0);
- while ((state = t->detach_state) && r != ETIMEDOUT && r != EINVAL) {
- if (state >= DT_DETACHED) a_crash();
- r = __timedwait_cp(&t->detach_state, state, CLOCK_REALTIME, at, 1);
- }
- __pthread_setcancelstate(cs, 0);
- if (r == ETIMEDOUT || r == EINVAL) return r;
- __tl_sync(t);
- if (res) *res = t->result;
-#ifdef __wasilibc_unmodified_upstream
- if (t->map_base) __munmap(t->map_base, t->map_size);
-#else
- if (t->map_base) free(t->map_base);
-#endif
- return 0;
-}
-
-int __pthread_join(pthread_t t, void **res)
-{
- return __pthread_timedjoin_np(t, res, 0);
-}
-
-static int __pthread_tryjoin_np(pthread_t t, void **res)
-{
- return t->detach_state==DT_JOINABLE ? EBUSY : __pthread_join(t, res);
-}
-
-weak_alias(__pthread_tryjoin_np, pthread_tryjoin_np);
-weak_alias(__pthread_timedjoin_np, pthread_timedjoin_np);
-weak_alias(__pthread_join, pthread_join);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_key_create.c
@@ -1,95 +0,0 @@
-#include "pthread_impl.h"
-
-volatile size_t __pthread_tsd_size = sizeof(void *) * PTHREAD_KEYS_MAX;
-void *__pthread_tsd_main[PTHREAD_KEYS_MAX] = { 0 };
-
-static void (*keys[PTHREAD_KEYS_MAX])(void *);
-
-static pthread_rwlock_t key_lock = PTHREAD_RWLOCK_INITIALIZER;
-
-static pthread_key_t next_key;
-
-static void nodtor(void *dummy)
-{
-}
-
-static void dummy_0(void)
-{
-}
-
-weak_alias(dummy_0, __tl_lock);
-weak_alias(dummy_0, __tl_unlock);
-
-int __pthread_key_create(pthread_key_t *k, void (*dtor)(void *))
-{
- pthread_t self = __pthread_self();
-
- /* This can only happen in the main thread before
- * pthread_create has been called. */
- if (!self->tsd) self->tsd = __pthread_tsd_main;
-
- /* Purely a sentinel value since null means slot is free. */
- if (!dtor) dtor = nodtor;
-
- __pthread_rwlock_wrlock(&key_lock);
- pthread_key_t j = next_key;
- do {
- if (!keys[j]) {
- keys[next_key = *k = j] = dtor;
- __pthread_rwlock_unlock(&key_lock);
- return 0;
- }
- } while ((j=(j+1)%PTHREAD_KEYS_MAX) != next_key);
-
- __pthread_rwlock_unlock(&key_lock);
- return EAGAIN;
-}
-
-int __pthread_key_delete(pthread_key_t k)
-{
- sigset_t set;
- pthread_t self = __pthread_self(), td=self;
-
-#ifdef __wasilibc_unmodified_upstream
- __block_app_sigs(&set);
-#endif
- __pthread_rwlock_wrlock(&key_lock);
-
- __tl_lock();
- do td->tsd[k] = 0;
- while ((td=td->next)!=self);
- __tl_unlock();
-
- keys[k] = 0;
-
- __pthread_rwlock_unlock(&key_lock);
-#ifdef __wasilibc_unmodified_upstream
- __restore_sigs(&set);
-#endif
-
- return 0;
-}
-
-void __pthread_tsd_run_dtors()
-{
- pthread_t self = __pthread_self();
- int i, j;
- for (j=0; self->tsd_used && j<PTHREAD_DESTRUCTOR_ITERATIONS; j++) {
- __pthread_rwlock_rdlock(&key_lock);
- self->tsd_used = 0;
- for (i=0; i<PTHREAD_KEYS_MAX; i++) {
- void *val = self->tsd[i];
- void (*dtor)(void *) = keys[i];
- self->tsd[i] = 0;
- if (val && dtor && dtor != nodtor) {
- __pthread_rwlock_unlock(&key_lock);
- dtor(val);
- __pthread_rwlock_rdlock(&key_lock);
- }
- }
- __pthread_rwlock_unlock(&key_lock);
- }
-}
-
-weak_alias(__pthread_key_create, pthread_key_create);
-weak_alias(__pthread_key_delete, pthread_key_delete);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_kill.c
@@ -1,18 +0,0 @@
-#include "pthread_impl.h"
-#include "lock.h"
-
-int pthread_kill(pthread_t t, int sig)
-{
- int r;
- sigset_t set;
- /* Block not just app signals, but internal ones too, since
- * pthread_kill is used to implement pthread_cancel, which
- * must be async-cancel-safe. */
- __block_all_sigs(&set);
- LOCK(t->killlock);
- r = t->tid ? -__syscall(SYS_tkill, t->tid, sig)
- : (sig+0U >= _NSIG ? EINVAL : 0);
- UNLOCK(t->killlock);
- __restore_sigs(&set);
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_consistent.c
@@ -1,14 +0,0 @@
-#include "pthread_impl.h"
-#include "atomic.h"
-
-int pthread_mutex_consistent(pthread_mutex_t *m)
-{
- int old = m->_m_lock;
- int own = old & 0x3fffffff;
- if (!(m->_m_type & 4) || !own || !(old & 0x40000000))
- return EINVAL;
- if (own != __pthread_self()->tid)
- return EPERM;
- a_and(&m->_m_lock, ~0x40000000);
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_destroy.c
@@ -1,18 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_mutex_destroy(pthread_mutex_t *mutex)
-{
-#ifdef __wasilibc_unmodified_upstream
- /* If the mutex being destroyed is process-shared and has nontrivial
- * type (tracking ownership), it might be in the pending slot of a
- * robust_list; wait for quiescence. */
- if (mutex->_m_type > 128) __vm_wait();
-#else
- /* For now, wasi-libc chooses to avoid implementing robust mutex support
- * though this could be added later. The error code indicates that the
- * mutex was an invalid type, but it would be more accurate as
- * "unimplemented". */
- if (mutex->_m_type > 128) return EINVAL;
-#endif
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_getprioceiling.c
@@ -1,6 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_mutex_getprioceiling(const pthread_mutex_t *restrict m, int *restrict ceiling)
-{
- return EINVAL;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_init.c
@@ -1,8 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_mutex_init(pthread_mutex_t *restrict m, const pthread_mutexattr_t *restrict a)
-{
- *m = (pthread_mutex_t){0};
- if (a) m->_m_type = a->__attr;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_lock.c
@@ -1,12 +0,0 @@
-#include "pthread_impl.h"
-
-int __pthread_mutex_lock(pthread_mutex_t *m)
-{
- if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL
- && !a_cas(&m->_m_lock, 0, EBUSY))
- return 0;
-
- return __pthread_mutex_timedlock(m, 0);
-}
-
-weak_alias(__pthread_mutex_lock, pthread_mutex_lock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_setprioceiling.c
@@ -1,6 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_mutex_setprioceiling(pthread_mutex_t *restrict m, int ceiling, int *restrict old)
-{
- return EINVAL;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_timedlock.c
@@ -1,96 +0,0 @@
-#include "pthread_impl.h"
-
-#ifdef __wasilibc_unmodified_upstream
-#define IS32BIT(x) !((x)+0x80000000ULL>>32)
-#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
-
-static int __futex4(volatile void *addr, int op, int val, const struct timespec *to)
-{
-#ifdef SYS_futex_time64
- time_t s = to ? to->tv_sec : 0;
- long ns = to ? to->tv_nsec : 0;
- int r = -ENOSYS;
- if (SYS_futex == SYS_futex_time64 || !IS32BIT(s))
- r = __syscall(SYS_futex_time64, addr, op, val,
- to ? ((long long[]){s, ns}) : 0);
- if (SYS_futex == SYS_futex_time64 || r!=-ENOSYS) return r;
- to = to ? (void *)(long[]){CLAMP(s), ns} : 0;
-#endif
- return __syscall(SYS_futex, addr, op, val, to);
-}
-
-static int pthread_mutex_timedlock_pi(pthread_mutex_t *restrict m, const struct timespec *restrict at)
-{
- int type = m->_m_type;
- int priv = (type & 128) ^ 128;
- pthread_t self = __pthread_self();
- int e;
-
- if (!priv) self->robust_list.pending = &m->_m_next;
-
- do e = -__futex4(&m->_m_lock, FUTEX_LOCK_PI|priv, 0, at);
- while (e==EINTR);
- if (e) self->robust_list.pending = 0;
-
- switch (e) {
- case 0:
- /* Catch spurious success for non-robust mutexes. */
- if (!(type&4) && ((m->_m_lock & 0x40000000) || m->_m_waiters)) {
- a_store(&m->_m_waiters, -1);
- __syscall(SYS_futex, &m->_m_lock, FUTEX_UNLOCK_PI|priv);
- self->robust_list.pending = 0;
- break;
- }
- /* Signal to trylock that we already have the lock. */
- m->_m_count = -1;
- return __pthread_mutex_trylock(m);
- case ETIMEDOUT:
- return e;
- case EDEADLK:
- if ((type&3) == PTHREAD_MUTEX_ERRORCHECK) return e;
- }
- do e = __timedwait(&(int){0}, 0, CLOCK_REALTIME, at, 1);
- while (e != ETIMEDOUT);
- return e;
-}
-#endif
-
-int __pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec *restrict at)
-{
- if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL
- && !a_cas(&m->_m_lock, 0, EBUSY))
- return 0;
-
- int type = m->_m_type;
- int r, t, priv = (type & 128) ^ 128;
-
- r = __pthread_mutex_trylock(m);
- if (r != EBUSY) return r;
-
-#ifdef __wasilibc_unmodified_upstream
- if (type&8) return pthread_mutex_timedlock_pi(m, at);
-#endif
-
- int spins = 100;
- while (spins-- && m->_m_lock && !m->_m_waiters) a_spin();
-
- while ((r=__pthread_mutex_trylock(m)) == EBUSY) {
- r = m->_m_lock;
- int own = r & 0x3fffffff;
- if (!own && (!r || (type&4)))
- continue;
- if ((type&3) == PTHREAD_MUTEX_ERRORCHECK
- && own == __pthread_self()->tid)
- return EDEADLK;
-
- a_inc(&m->_m_waiters);
- t = r | 0x80000000;
- a_cas(&m->_m_lock, r, t);
- r = __timedwait(&m->_m_lock, t, CLOCK_REALTIME, at, priv);
- a_dec(&m->_m_waiters);
- if (r && r != EINTR) break;
- }
- return r;
-}
-
-weak_alias(__pthread_mutex_timedlock, pthread_mutex_timedlock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_trylock.c
@@ -1,78 +0,0 @@
-#include "pthread_impl.h"
-
-int __pthread_mutex_trylock_owner(pthread_mutex_t *m)
-{
- int old, own;
- int type = m->_m_type;
- pthread_t self = __pthread_self();
- int tid = self->tid;
-
- old = m->_m_lock;
- own = old & 0x3fffffff;
- if (own == tid) {
- if ((type&8) && m->_m_count<0) {
- old &= 0x40000000;
- m->_m_count = 0;
- goto success;
- }
- if ((type&3) == PTHREAD_MUTEX_RECURSIVE) {
- if ((unsigned)m->_m_count >= INT_MAX) return EAGAIN;
- m->_m_count++;
- return 0;
- }
- }
- if (own == 0x3fffffff) return ENOTRECOVERABLE;
- if (own || (old && !(type & 4))) return EBUSY;
-
- if (type & 128) {
- if (!self->robust_list.off) {
- self->robust_list.off = (char*)&m->_m_lock-(char *)&m->_m_next;
-#ifdef __wasilibc_unmodified_upstream
- __syscall(SYS_set_robust_list, &self->robust_list, 3*sizeof(long));
-#endif
- }
- if (m->_m_waiters) tid |= 0x80000000;
- self->robust_list.pending = &m->_m_next;
- }
- tid |= old & 0x40000000;
-
- if (a_cas(&m->_m_lock, old, tid) != old) {
- self->robust_list.pending = 0;
- if ((type&12)==12 && m->_m_waiters) return ENOTRECOVERABLE;
- return EBUSY;
- }
-
-success:
- if ((type&8) && m->_m_waiters) {
- int priv = (type & 128) ^ 128;
-#ifdef __wasilibc_unmodified_upstream
- __syscall(SYS_futex, &m->_m_lock, FUTEX_UNLOCK_PI|priv);
-#endif
- self->robust_list.pending = 0;
- return (type&4) ? ENOTRECOVERABLE : EBUSY;
- }
-
- volatile void *next = self->robust_list.head;
- m->_m_next = next;
- m->_m_prev = &self->robust_list.head;
- if (next != &self->robust_list.head) *(volatile void *volatile *)
- ((char *)next - sizeof(void *)) = &m->_m_next;
- self->robust_list.head = &m->_m_next;
- self->robust_list.pending = 0;
-
- if (old) {
- m->_m_count = 0;
- return EOWNERDEAD;
- }
-
- return 0;
-}
-
-int __pthread_mutex_trylock(pthread_mutex_t *m)
-{
- if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL)
- return a_cas(&m->_m_lock, 0, EBUSY) & EBUSY;
- return __pthread_mutex_trylock_owner(m);
-}
-
-weak_alias(__pthread_mutex_trylock, pthread_mutex_trylock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_unlock.c
@@ -1,60 +0,0 @@
-#include "pthread_impl.h"
-
-int __pthread_mutex_unlock(pthread_mutex_t *m)
-{
- pthread_t self;
- int waiters = m->_m_waiters;
- int cont;
- int type = m->_m_type & 15;
- int priv = (m->_m_type & 128) ^ 128;
- int new = 0;
- int old;
-
- if (type != PTHREAD_MUTEX_NORMAL) {
- self = __pthread_self();
- old = m->_m_lock;
- int own = old & 0x3fffffff;
- if (own != self->tid)
- return EPERM;
- if ((type&3) == PTHREAD_MUTEX_RECURSIVE && m->_m_count)
- return m->_m_count--, 0;
- if ((type&4) && (old&0x40000000))
- new = 0x7fffffff;
- if (!priv) {
- self->robust_list.pending = &m->_m_next;
-#ifdef __wasilibc_unmodified_upstream
- __vm_lock();
-#endif
- }
- volatile void *prev = m->_m_prev;
- volatile void *next = m->_m_next;
- *(volatile void *volatile *)prev = next;
- if (next != &self->robust_list.head) *(volatile void *volatile *)
- ((char *)next - sizeof(void *)) = prev;
- }
-#ifdef __wasilibc_unmodified_upstream
- if (type&8) {
- if (old<0 || a_cas(&m->_m_lock, old, new)!=old) {
- if (new) a_store(&m->_m_waiters, -1);
- __syscall(SYS_futex, &m->_m_lock, FUTEX_UNLOCK_PI|priv);
- }
- cont = 0;
- waiters = 0;
- } else {
- cont = a_swap(&m->_m_lock, new);
- }
-#else
- cont = a_swap(&m->_m_lock, new);
-#endif
- if (type != PTHREAD_MUTEX_NORMAL && !priv) {
- self->robust_list.pending = 0;
-#ifdef __wasilibc_unmodified_upstream
- __vm_unlock();
-#endif
- }
- if (waiters || cont<0)
- __wake(&m->_m_lock, 1, priv);
- return 0;
-}
-
-weak_alias(__pthread_mutex_unlock, pthread_mutex_unlock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_destroy.c
@@ -1,6 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_mutexattr_destroy(pthread_mutexattr_t *a)
-{
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_init.c
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_mutexattr_init(pthread_mutexattr_t *a)
-{
- *a = (pthread_mutexattr_t){0};
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setprotocol.c
@@ -1,32 +0,0 @@
-#include "pthread_impl.h"
-#include "syscall.h"
-
-static volatile int check_pi_result = -1;
-
-int pthread_mutexattr_setprotocol(pthread_mutexattr_t *a, int protocol)
-{
- int r;
- switch (protocol) {
- case PTHREAD_PRIO_NONE:
- a->__attr &= ~8;
- return 0;
- case PTHREAD_PRIO_INHERIT:
-#ifdef __wasilibc_unmodified_upstream
- r = check_pi_result;
- if (r < 0) {
- volatile int lk = 0;
- r = -__syscall(SYS_futex, &lk, FUTEX_LOCK_PI, 0, 0);
- a_store(&check_pi_result, r);
- }
- if (r) return r;
- a->__attr |= 8;
- return 0;
-#else
- return ENOTSUP;
-#endif
- case PTHREAD_PRIO_PROTECT:
- return ENOTSUP;
- default:
- return EINVAL;
- }
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setrobust.c
@@ -1,27 +0,0 @@
-#include "pthread_impl.h"
-#include "syscall.h"
-
-static volatile int check_robust_result = -1;
-
-int pthread_mutexattr_setrobust(pthread_mutexattr_t *a, int robust)
-{
-#ifdef __wasilibc_unmodified_upstream
- if (robust > 1U) return EINVAL;
- if (robust) {
- int r = check_robust_result;
- if (r < 0) {
- void *p;
- size_t l;
- r = -__syscall(SYS_get_robust_list, 0, &p, &l);
- a_store(&check_robust_result, r);
- }
- if (r) return r;
- a->__attr |= 4;
- return 0;
- }
- a->__attr &= ~4;
- return 0;
-#else
- return EINVAL;
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_settype.c
@@ -1,8 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_mutexattr_settype(pthread_mutexattr_t *a, int type)
-{
- if ((unsigned)type > 2) return EINVAL;
- a->__attr = (a->__attr & ~3) | type;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_once.c
@@ -1,50 +0,0 @@
-#include "pthread_impl.h"
-
-static void undo(void *control)
-{
- /* Wake all waiters, since the waiter status is lost when
- * resetting control to the initial state. */
- if (a_swap(control, 0) == 3)
- __wake(control, -1, 1);
-}
-
-hidden int __pthread_once_full(pthread_once_t *control, void (*init)(void))
-{
- /* Try to enter initializing state. Four possibilities:
- * 0 - we're the first or the other cancelled; run init
- * 1 - another thread is running init; wait
- * 2 - another thread finished running init; just return
- * 3 - another thread is running init, waiters present; wait */
-
- for (;;) switch (a_cas(control, 0, 1)) {
- case 0:
- pthread_cleanup_push(undo, control);
- init();
- pthread_cleanup_pop(0);
-
- if (a_swap(control, 2) == 3)
- __wake(control, -1, 1);
- return 0;
- case 1:
- /* If this fails, so will __wait. */
- a_cas(control, 1, 3);
- case 3:
- __wait(control, 0, 3, 1);
- continue;
- case 2:
- return 0;
- }
-}
-
-int __pthread_once(pthread_once_t *control, void (*init)(void))
-{
- /* Return immediately if init finished before, but ensure that
- * effects of the init routine are visible to the caller. */
- if (*(volatile int *)control == 2) {
- a_barrier();
- return 0;
- }
- return __pthread_once_full(control, init);
-}
-
-weak_alias(__pthread_once, pthread_once);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_destroy.c
@@ -1,6 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_rwlock_destroy(pthread_rwlock_t *rw)
-{
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_init.c
@@ -1,8 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_rwlock_init(pthread_rwlock_t *restrict rw, const pthread_rwlockattr_t *restrict a)
-{
- *rw = (pthread_rwlock_t){0};
- if (a) rw->_rw_shared = a->__attr[0]*128;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_rdlock.c
@@ -1,8 +0,0 @@
-#include "pthread_impl.h"
-
-int __pthread_rwlock_rdlock(pthread_rwlock_t *rw)
-{
- return __pthread_rwlock_timedrdlock(rw, 0);
-}
-
-weak_alias(__pthread_rwlock_rdlock, pthread_rwlock_rdlock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_timedrdlock.c
@@ -1,25 +0,0 @@
-#include "pthread_impl.h"
-
-int __pthread_rwlock_timedrdlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at)
-{
- int r, t;
-
- r = pthread_rwlock_tryrdlock(rw);
- if (r != EBUSY) return r;
-
- int spins = 100;
- while (spins-- && rw->_rw_lock && !rw->_rw_waiters) a_spin();
-
- while ((r=__pthread_rwlock_tryrdlock(rw))==EBUSY) {
- if (!(r=rw->_rw_lock) || (r&0x7fffffff)!=0x7fffffff) continue;
- t = r | 0x80000000;
- a_inc(&rw->_rw_waiters);
- a_cas(&rw->_rw_lock, r, t);
- r = __timedwait(&rw->_rw_lock, t, CLOCK_REALTIME, at, rw->_rw_shared^128);
- a_dec(&rw->_rw_waiters);
- if (r && r != EINTR) return r;
- }
- return r;
-}
-
-weak_alias(__pthread_rwlock_timedrdlock, pthread_rwlock_timedrdlock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_timedwrlock.c
@@ -1,25 +0,0 @@
-#include "pthread_impl.h"
-
-int __pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at)
-{
- int r, t;
-
- r = pthread_rwlock_trywrlock(rw);
- if (r != EBUSY) return r;
-
- int spins = 100;
- while (spins-- && rw->_rw_lock && !rw->_rw_waiters) a_spin();
-
- while ((r=__pthread_rwlock_trywrlock(rw))==EBUSY) {
- if (!(r=rw->_rw_lock)) continue;
- t = r | 0x80000000;
- a_inc(&rw->_rw_waiters);
- a_cas(&rw->_rw_lock, r, t);
- r = __timedwait(&rw->_rw_lock, t, CLOCK_REALTIME, at, rw->_rw_shared^128);
- a_dec(&rw->_rw_waiters);
- if (r && r != EINTR) return r;
- }
- return r;
-}
-
-weak_alias(__pthread_rwlock_timedwrlock, pthread_rwlock_timedwrlock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_tryrdlock.c
@@ -1,15 +0,0 @@
-#include "pthread_impl.h"
-
-int __pthread_rwlock_tryrdlock(pthread_rwlock_t *rw)
-{
- int val, cnt;
- do {
- val = rw->_rw_lock;
- cnt = val & 0x7fffffff;
- if (cnt == 0x7fffffff) return EBUSY;
- if (cnt == 0x7ffffffe) return EAGAIN;
- } while (a_cas(&rw->_rw_lock, val, val+1) != val);
- return 0;
-}
-
-weak_alias(__pthread_rwlock_tryrdlock, pthread_rwlock_tryrdlock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_trywrlock.c
@@ -1,9 +0,0 @@
-#include "pthread_impl.h"
-
-int __pthread_rwlock_trywrlock(pthread_rwlock_t *rw)
-{
- if (a_cas(&rw->_rw_lock, 0, 0x7fffffff)) return EBUSY;
- return 0;
-}
-
-weak_alias(__pthread_rwlock_trywrlock, pthread_rwlock_trywrlock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_unlock.c
@@ -1,20 +0,0 @@
-#include "pthread_impl.h"
-
-int __pthread_rwlock_unlock(pthread_rwlock_t *rw)
-{
- int val, cnt, waiters, new, priv = rw->_rw_shared^128;
-
- do {
- val = rw->_rw_lock;
- cnt = val & 0x7fffffff;
- waiters = rw->_rw_waiters;
- new = (cnt == 0x7fffffff || cnt == 1) ? 0 : val-1;
- } while (a_cas(&rw->_rw_lock, val, new) != val);
-
- if (!new && (waiters || val<0))
- __wake(&rw->_rw_lock, cnt, priv);
-
- return 0;
-}
-
-weak_alias(__pthread_rwlock_unlock, pthread_rwlock_unlock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_wrlock.c
@@ -1,8 +0,0 @@
-#include "pthread_impl.h"
-
-int __pthread_rwlock_wrlock(pthread_rwlock_t *rw)
-{
- return __pthread_rwlock_timedwrlock(rw, 0);
-}
-
-weak_alias(__pthread_rwlock_wrlock, pthread_rwlock_wrlock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlockattr_destroy.c
@@ -1,6 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_rwlockattr_destroy(pthread_rwlockattr_t *a)
-{
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlockattr_init.c
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_rwlockattr_init(pthread_rwlockattr_t *a)
-{
- *a = (pthread_rwlockattr_t){0};
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_self.c
@@ -1,15 +0,0 @@
-#include "pthread_impl.h"
-#include <threads.h>
-
-#if !defined(__wasilibc_unmodified_upstream) && defined(__wasm__) && \
- defined(_REENTRANT)
-_Thread_local struct pthread __wasilibc_pthread_self;
-#endif
-
-static pthread_t __pthread_self_internal()
-{
- return __pthread_self();
-}
-
-weak_alias(__pthread_self_internal, pthread_self);
-weak_alias(__pthread_self_internal, thrd_current);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setattr_default_np.c
@@ -1,37 +0,0 @@
-#define _GNU_SOURCE
-#include "pthread_impl.h"
-#include <string.h>
-
-#define MIN(a,b) ((a)<(b) ? (a) : (b))
-#define MAX(a,b) ((a)>(b) ? (a) : (b))
-
-int pthread_setattr_default_np(const pthread_attr_t *attrp)
-{
- /* Reject anything in the attr object other than stack/guard size. */
- pthread_attr_t tmp = *attrp, zero = { 0 };
- tmp._a_stacksize = 0;
- tmp._a_guardsize = 0;
- if (memcmp(&tmp, &zero, sizeof tmp))
- return EINVAL;
-
- unsigned stack = MIN(attrp->_a_stacksize, DEFAULT_STACK_MAX);
- unsigned guard = MIN(attrp->_a_guardsize, DEFAULT_GUARD_MAX);
-
- __inhibit_ptc();
- __default_stacksize = MAX(__default_stacksize, stack);
- __default_guardsize = MAX(__default_guardsize, guard);
- __release_ptc();
-
- return 0;
-}
-
-int pthread_getattr_default_np(pthread_attr_t *attrp)
-{
- __acquire_ptc();
- *attrp = (pthread_attr_t) {
- ._a_stacksize = __default_stacksize,
- ._a_guardsize = __default_guardsize,
- };
- __release_ptc();
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setcancelstate.c
@@ -1,14 +0,0 @@
-#include "pthread_impl.h"
-
-int __pthread_setcancelstate(int new, int *old)
-{
-#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
- if (new > 2U) return EINVAL;
- struct pthread *self = __pthread_self();
- if (old) *old = self->canceldisable;
- self->canceldisable = new;
-#endif
- return 0;
-}
-
-weak_alias(__pthread_setcancelstate, pthread_setcancelstate);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setcanceltype.c
@@ -1,11 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_setcanceltype(int new, int *old)
-{
- struct pthread *self = __pthread_self();
- if (new > 1U) return EINVAL;
- if (old) *old = self->cancelasync;
- self->cancelasync = new;
- if (new) pthread_testcancel();
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setconcurrency.c
@@ -1,9 +0,0 @@
-#include <pthread.h>
-#include <errno.h>
-
-int pthread_setconcurrency(int val)
-{
- if (val < 0) return EINVAL;
- if (val > 0) return EAGAIN;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setname_np.c
@@ -1,26 +0,0 @@
-#define _GNU_SOURCE
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/prctl.h>
-
-#include "pthread_impl.h"
-
-int pthread_setname_np(pthread_t thread, const char *name)
-{
- int fd, cs, status = 0;
- char f[sizeof "/proc/self/task//comm" + 3*sizeof(int)];
- size_t len;
-
- if ((len = strnlen(name, 16)) > 15) return ERANGE;
-
- if (thread == pthread_self())
- return prctl(PR_SET_NAME, (unsigned long)name, 0UL, 0UL, 0UL) ? errno : 0;
-
- snprintf(f, sizeof f, "/proc/self/task/%d/comm", thread->tid);
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
- if ((fd = open(f, O_WRONLY|O_CLOEXEC)) < 0 || write(fd, name, len) < 0) status = errno;
- if (fd >= 0) close(fd);
- pthread_setcancelstate(cs, 0);
- return status;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setschedparam.c
@@ -1,14 +0,0 @@
-#include "pthread_impl.h"
-#include "lock.h"
-
-int pthread_setschedparam(pthread_t t, int policy, const struct sched_param *param)
-{
- int r;
- sigset_t set;
- __block_app_sigs(&set);
- LOCK(t->killlock);
- r = !t->tid ? ESRCH : -__syscall(SYS_sched_setscheduler, t->tid, policy, param);
- UNLOCK(t->killlock);
- __restore_sigs(&set);
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setschedprio.c
@@ -1,14 +0,0 @@
-#include "pthread_impl.h"
-#include "lock.h"
-
-int pthread_setschedprio(pthread_t t, int prio)
-{
- int r;
- sigset_t set;
- __block_app_sigs(&set);
- LOCK(t->killlock);
- r = !t->tid ? ESRCH : -__syscall(SYS_sched_setparam, t->tid, &prio);
- UNLOCK(t->killlock);
- __restore_sigs(&set);
- return r;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setspecific.c
@@ -1,12 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_setspecific(pthread_key_t k, const void *x)
-{
- struct pthread *self = __pthread_self();
- /* Avoid unnecessary COW */
- if (self->tsd[k] != x) {
- self->tsd[k] = (void *)x;
- self->tsd_used = 1;
- }
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_sigmask.c
@@ -1,19 +0,0 @@
-#include <signal.h>
-#include <errno.h>
-#include "syscall.h"
-
-int pthread_sigmask(int how, const sigset_t *restrict set, sigset_t *restrict old)
-{
- int ret;
- if (set && (unsigned)how - SIG_BLOCK > 2U) return EINVAL;
- ret = -__syscall(SYS_rt_sigprocmask, how, set, old, _NSIG/8);
- if (!ret && old) {
- if (sizeof old->__bits[0] == 8) {
- old->__bits[0] &= ~0x380000000ULL;
- } else {
- old->__bits[0] &= ~0x80000000UL;
- old->__bits[1] &= ~0x3UL;
- }
- }
- return ret;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_spin_destroy.c
@@ -1,6 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_spin_destroy(pthread_spinlock_t *s)
-{
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_spin_init.c
@@ -1,6 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_spin_init(pthread_spinlock_t *s, int shared)
-{
- return *s = 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_spin_lock.c
@@ -1,8 +0,0 @@
-#include "pthread_impl.h"
-#include <errno.h>
-
-int pthread_spin_lock(pthread_spinlock_t *s)
-{
- while (*(volatile int *)s || a_cas(s, 0, EBUSY)) a_spin();
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_spin_trylock.c
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-#include <errno.h>
-
-int pthread_spin_trylock(pthread_spinlock_t *s)
-{
- return a_cas(s, 0, EBUSY);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_spin_unlock.c
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_spin_unlock(pthread_spinlock_t *s)
-{
- a_store(s, 0);
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_testcancel.c
@@ -1,14 +0,0 @@
-#include "pthread_impl.h"
-
-static void dummy()
-{
-}
-
-weak_alias(dummy, __testcancel);
-
-void __pthread_testcancel()
-{
- __testcancel();
-}
-
-weak_alias(__pthread_testcancel, pthread_testcancel);
lib/libc/wasi/libc-top-half/musl/src/thread/sem_destroy.c
@@ -1,6 +0,0 @@
-#include <semaphore.h>
-
-int sem_destroy(sem_t *sem)
-{
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/sem_getvalue.c
@@ -1,8 +0,0 @@
-#include <semaphore.h>
-
-int sem_getvalue(sem_t *restrict sem, int *restrict valp)
-{
- int val = sem->__val[0];
- *valp = val < 0 ? 0 : val;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/sem_init.c
@@ -1,15 +0,0 @@
-#include <semaphore.h>
-#include <limits.h>
-#include <errno.h>
-
-int sem_init(sem_t *sem, int pshared, unsigned value)
-{
- if (value > SEM_VALUE_MAX) {
- errno = EINVAL;
- return -1;
- }
- sem->__val[0] = value;
- sem->__val[1] = 0;
- sem->__val[2] = pshared ? 0 : 128;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/sem_open.c
@@ -1,182 +0,0 @@
-#include <semaphore.h>
-#include <sys/mman.h>
-#include <limits.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <time.h>
-#include <stdio.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <pthread.h>
-#include "lock.h"
-#include "fork_impl.h"
-
-#define malloc __libc_malloc
-#define calloc __libc_calloc
-#define realloc undef
-#define free undef
-
-static struct {
- ino_t ino;
- sem_t *sem;
- int refcnt;
-} *semtab;
-static volatile int lock[1];
-volatile int *const __sem_open_lockptr = lock;
-
-#define FLAGS (O_RDWR|O_NOFOLLOW|O_CLOEXEC|O_NONBLOCK)
-
-sem_t *sem_open(const char *name, int flags, ...)
-{
- va_list ap;
- mode_t mode;
- unsigned value;
- int fd, i, e, slot, first=1, cnt, cs;
- sem_t newsem;
- void *map;
- char tmp[64];
- struct timespec ts;
- struct stat st;
- char buf[NAME_MAX+10];
-
- if (!(name = __shm_mapname(name, buf)))
- return SEM_FAILED;
-
- LOCK(lock);
- /* Allocate table if we don't have one yet */
- if (!semtab && !(semtab = calloc(sizeof *semtab, SEM_NSEMS_MAX))) {
- UNLOCK(lock);
- return SEM_FAILED;
- }
-
- /* Reserve a slot in case this semaphore is not mapped yet;
- * this is necessary because there is no way to handle
- * failures after creation of the file. */
- slot = -1;
- for (cnt=i=0; i<SEM_NSEMS_MAX; i++) {
- cnt += semtab[i].refcnt;
- if (!semtab[i].sem && slot < 0) slot = i;
- }
- /* Avoid possibility of overflow later */
- if (cnt == INT_MAX || slot < 0) {
- errno = EMFILE;
- UNLOCK(lock);
- return SEM_FAILED;
- }
- /* Dummy pointer to make a reservation */
- semtab[slot].sem = (sem_t *)-1;
- UNLOCK(lock);
-
- flags &= (O_CREAT|O_EXCL);
-
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
-
- /* Early failure check for exclusive open; otherwise the case
- * where the semaphore already exists is expensive. */
- if (flags == (O_CREAT|O_EXCL) && access(name, F_OK) == 0) {
- errno = EEXIST;
- goto fail;
- }
-
- for (;;) {
- /* If exclusive mode is not requested, try opening an
- * existing file first and fall back to creation. */
- if (flags != (O_CREAT|O_EXCL)) {
- fd = open(name, FLAGS);
- if (fd >= 0) {
- if (fstat(fd, &st) < 0 ||
- (map = mmap(0, sizeof(sem_t), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) {
- close(fd);
- goto fail;
- }
- close(fd);
- break;
- }
- if (errno != ENOENT)
- goto fail;
- }
- if (!(flags & O_CREAT))
- goto fail;
- if (first) {
- first = 0;
- va_start(ap, flags);
- mode = va_arg(ap, mode_t) & 0666;
- value = va_arg(ap, unsigned);
- va_end(ap);
- if (value > SEM_VALUE_MAX) {
- errno = EINVAL;
- goto fail;
- }
- sem_init(&newsem, 1, value);
- }
- /* Create a temp file with the new semaphore contents
- * and attempt to atomically link it as the new name */
- clock_gettime(CLOCK_REALTIME, &ts);
- snprintf(tmp, sizeof(tmp), "/dev/shm/tmp-%d", (int)ts.tv_nsec);
- fd = open(tmp, O_CREAT|O_EXCL|FLAGS, mode);
- if (fd < 0) {
- if (errno == EEXIST) continue;
- goto fail;
- }
- if (write(fd, &newsem, sizeof newsem) != sizeof newsem || fstat(fd, &st) < 0 ||
- (map = mmap(0, sizeof(sem_t), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) {
- close(fd);
- unlink(tmp);
- goto fail;
- }
- close(fd);
- e = link(tmp, name) ? errno : 0;
- unlink(tmp);
- if (!e) break;
- munmap(map, sizeof(sem_t));
- /* Failure is only fatal when doing an exclusive open;
- * otherwise, next iteration will try to open the
- * existing file. */
- if (e != EEXIST || flags == (O_CREAT|O_EXCL))
- goto fail;
- }
-
- /* See if the newly mapped semaphore is already mapped. If
- * so, unmap the new mapping and use the existing one. Otherwise,
- * add it to the table of mapped semaphores. */
- LOCK(lock);
- for (i=0; i<SEM_NSEMS_MAX && semtab[i].ino != st.st_ino; i++);
- if (i<SEM_NSEMS_MAX) {
- munmap(map, sizeof(sem_t));
- semtab[slot].sem = 0;
- slot = i;
- map = semtab[i].sem;
- }
- semtab[slot].refcnt++;
- semtab[slot].sem = map;
- semtab[slot].ino = st.st_ino;
- UNLOCK(lock);
- pthread_setcancelstate(cs, 0);
- return map;
-
-fail:
- pthread_setcancelstate(cs, 0);
- LOCK(lock);
- semtab[slot].sem = 0;
- UNLOCK(lock);
- return SEM_FAILED;
-}
-
-int sem_close(sem_t *sem)
-{
- int i;
- LOCK(lock);
- for (i=0; i<SEM_NSEMS_MAX && semtab[i].sem != sem; i++);
- if (--semtab[i].refcnt) {
- UNLOCK(lock);
- return 0;
- }
- semtab[i].sem = 0;
- semtab[i].ino = 0;
- UNLOCK(lock);
- munmap(sem, sizeof *sem);
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/sem_post.c
@@ -1,17 +0,0 @@
-#include <semaphore.h>
-#include "pthread_impl.h"
-
-int sem_post(sem_t *sem)
-{
- int val, waiters, priv = sem->__val[2];
- do {
- val = sem->__val[0];
- waiters = sem->__val[1];
- if (val == SEM_VALUE_MAX) {
- errno = EOVERFLOW;
- return -1;
- }
- } while (a_cas(sem->__val, val, val+1+(val<0)) != val);
- if (val<0 || waiters) __wake(sem->__val, 1, priv);
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/sem_timedwait.c
@@ -1,31 +0,0 @@
-#include <semaphore.h>
-#include "pthread_impl.h"
-
-static void cleanup(void *p)
-{
- a_dec(p);
-}
-
-int sem_timedwait(sem_t *restrict sem, const struct timespec *restrict at)
-{
- pthread_testcancel();
-
- if (!sem_trywait(sem)) return 0;
-
- int spins = 100;
- while (spins-- && sem->__val[0] <= 0 && !sem->__val[1]) a_spin();
-
- while (sem_trywait(sem)) {
- int r;
- a_inc(sem->__val+1);
- a_cas(sem->__val, 0, -1);
- pthread_cleanup_push(cleanup, (void *)(sem->__val+1));
- r = __timedwait_cp(sem->__val, -1, CLOCK_REALTIME, at, sem->__val[2]);
- pthread_cleanup_pop(1);
- if (r) {
- errno = r;
- return -1;
- }
- }
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/sem_trywait.c
@@ -1,13 +0,0 @@
-#include <semaphore.h>
-#include "pthread_impl.h"
-
-int sem_trywait(sem_t *sem)
-{
- int val;
- while ((val=sem->__val[0]) > 0) {
- int new = val-1-(val==1 && sem->__val[1]);
- if (a_cas(sem->__val, val, new)==val) return 0;
- }
- errno = EAGAIN;
- return -1;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/sem_unlink.c
@@ -1,7 +0,0 @@
-#include <semaphore.h>
-#include <sys/mman.h>
-
-int sem_unlink(const char *name)
-{
- return shm_unlink(name);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/sem_wait.c
@@ -1,6 +0,0 @@
-#include <semaphore.h>
-
-int sem_wait(sem_t *sem)
-{
- return sem_timedwait(sem, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/synccall.c
@@ -1,120 +0,0 @@
-#include "pthread_impl.h"
-#include <semaphore.h>
-#include <string.h>
-
-static void dummy_0(void)
-{
-}
-
-weak_alias(dummy_0, __tl_lock);
-weak_alias(dummy_0, __tl_unlock);
-
-static int target_tid;
-static void (*callback)(void *), *context;
-static sem_t target_sem, caller_sem;
-
-static void dummy(void *p)
-{
-}
-
-static void handler(int sig)
-{
- if (__pthread_self()->tid != target_tid) return;
-
- int old_errno = errno;
-
- /* Inform caller we have received signal and wait for
- * the caller to let us make the callback. */
- sem_post(&caller_sem);
- sem_wait(&target_sem);
-
- callback(context);
-
- /* Inform caller we've complered the callback and wait
- * for the caller to release us to return. */
- sem_post(&caller_sem);
- sem_wait(&target_sem);
-
- /* Inform caller we are returning and state is destroyable. */
- sem_post(&caller_sem);
-
- errno = old_errno;
-}
-
-void __synccall(void (*func)(void *), void *ctx)
-{
- sigset_t oldmask;
- int cs, i, r;
- struct sigaction sa = { .sa_flags = SA_RESTART, .sa_handler = handler };
- pthread_t self = __pthread_self(), td;
- int count = 0;
-
- /* Blocking signals in two steps, first only app-level signals
- * before taking the lock, then all signals after taking the lock,
- * is necessary to achieve AS-safety. Blocking them all first would
- * deadlock if multiple threads called __synccall. Waiting to block
- * any until after the lock would allow re-entry in the same thread
- * with the lock already held. */
- __block_app_sigs(&oldmask);
- __tl_lock();
- __block_all_sigs(0);
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
-
- sem_init(&target_sem, 0, 0);
- sem_init(&caller_sem, 0, 0);
-
- if (!libc.threads_minus_1 || __syscall(SYS_gettid) != self->tid)
- goto single_threaded;
-
- callback = func;
- context = ctx;
-
- /* Block even implementation-internal signals, so that nothing
- * interrupts the SIGSYNCCALL handlers. The main possible source
- * of trouble is asynchronous cancellation. */
- memset(&sa.sa_mask, -1, sizeof sa.sa_mask);
- __libc_sigaction(SIGSYNCCALL, &sa, 0);
-
-
- for (td=self->next; td!=self; td=td->next) {
- target_tid = td->tid;
- while ((r = -__syscall(SYS_tkill, td->tid, SIGSYNCCALL)) == EAGAIN);
- if (r) {
- /* If we failed to signal any thread, nop out the
- * callback to abort the synccall and just release
- * any threads already caught. */
- callback = func = dummy;
- break;
- }
- sem_wait(&caller_sem);
- count++;
- }
- target_tid = 0;
-
- /* Serialize execution of callback in caught threads, or just
- * release them all if synccall is being aborted. */
- for (i=0; i<count; i++) {
- sem_post(&target_sem);
- sem_wait(&caller_sem);
- }
-
- sa.sa_handler = SIG_IGN;
- __libc_sigaction(SIGSYNCCALL, &sa, 0);
-
-single_threaded:
- func(ctx);
-
- /* Only release the caught threads once all threads, including the
- * caller, have returned from the callback function. */
- for (i=0; i<count; i++)
- sem_post(&target_sem);
- for (i=0; i<count; i++)
- sem_wait(&caller_sem);
-
- sem_destroy(&caller_sem);
- sem_destroy(&target_sem);
-
- pthread_setcancelstate(cs, 0);
- __tl_unlock();
- __restore_sigs(&oldmask);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/syscall_cp.c
lib/libc/wasi/libc-top-half/musl/src/thread/thrd_create.c
@@ -1,12 +0,0 @@
-#include "pthread_impl.h"
-#include <threads.h>
-
-int thrd_create(thrd_t *thr, thrd_start_t func, void *arg)
-{
- int ret = __pthread_create(thr, __ATTRP_C11_THREAD, (void *(*)(void *))func, arg);
- switch (ret) {
- case 0: return thrd_success;
- case EAGAIN: return thrd_nomem;
- default: return thrd_error;
- }
-}
lib/libc/wasi/libc-top-half/musl/src/thread/thrd_exit.c
@@ -1,8 +0,0 @@
-#include <threads.h>
-#include <pthread.h>
-#include <stdint.h>
-
-_Noreturn void thrd_exit(int result)
-{
- __pthread_exit((void*)(intptr_t)result);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/thrd_join.c
@@ -1,11 +0,0 @@
-#include <stdint.h>
-#include <threads.h>
-#include <pthread.h>
-
-int thrd_join(thrd_t t, int *res)
-{
- void *pthread_res;
- __pthread_join(t, &pthread_res);
- if (res) *res = (int)(intptr_t)pthread_res;
- return thrd_success;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/thrd_yield.c
@@ -1,7 +0,0 @@
-#include <threads.h>
-#include "syscall.h"
-
-void thrd_yield()
-{
- __syscall(SYS_sched_yield);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/tls.c
lib/libc/wasi/libc-top-half/musl/src/thread/tss_create.c
@@ -1,10 +0,0 @@
-#include <threads.h>
-#include <pthread.h>
-
-int tss_create(tss_t *tss, tss_dtor_t dtor)
-{
- /* Different error returns are possible. C glues them together into
- * just failure notification. Can't be optimized to a tail call,
- * unless thrd_error equals EAGAIN. */
- return __pthread_key_create(tss, dtor) ? thrd_error : thrd_success;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/tss_delete.c
@@ -1,7 +0,0 @@
-#include <threads.h>
-#include <pthread.h>
-
-void tss_delete(tss_t key)
-{
- __pthread_key_delete(key);
-}
lib/libc/wasi/libc-top-half/musl/src/thread/tss_set.c
@@ -1,13 +0,0 @@
-#include "pthread_impl.h"
-#include <threads.h>
-
-int tss_set(tss_t k, void *x)
-{
- struct pthread *self = __pthread_self();
- /* Avoid unnecessary COW */
- if (self->tsd[k] != x) {
- self->tsd[k] = x;
- self->tsd_used = 1;
- }
- return thrd_success;
-}
lib/libc/wasi/libc-top-half/musl/src/thread/vmlock.c
@@ -1,23 +0,0 @@
-#include "pthread_impl.h"
-#include "fork_impl.h"
-
-static volatile int vmlock[2];
-volatile int *const __vmlock_lockptr = vmlock;
-
-void __vm_wait()
-{
- int tmp;
- while ((tmp=vmlock[0]))
- __wait(vmlock, vmlock+1, tmp, 1);
-}
-
-void __vm_lock()
-{
- a_inc(vmlock);
-}
-
-void __vm_unlock()
-{
- if (a_fetch_add(vmlock, -1)==1 && vmlock[1])
- __wake(vmlock, -1, 1);
-}
lib/libc/wasi/libc-top-half/musl/src/time/__map_file.c
@@ -1,19 +0,0 @@
-#include <sys/mman.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include "syscall.h"
-#include "kstat.h"
-
-const char unsigned *__map_file(const char *pathname, size_t *size)
-{
- struct kstat st;
- const unsigned char *map = MAP_FAILED;
- int fd = sys_open(pathname, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
- if (fd < 0) return 0;
- if (!syscall(SYS_fstat, fd, &st)) {
- map = __mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
- *size = st.st_size;
- }
- __syscall(SYS_close, fd);
- return map == MAP_FAILED ? 0 : map;
-}
lib/libc/wasi/libc-top-half/musl/src/time/clock.c
@@ -1,16 +0,0 @@
-#include <time.h>
-#include <limits.h>
-
-clock_t clock()
-{
- struct timespec ts;
-
- if (__clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts))
- return -1;
-
- if (ts.tv_sec > LONG_MAX/1000000
- || ts.tv_nsec/1000 > LONG_MAX-1000000*ts.tv_sec)
- return -1;
-
- return ts.tv_sec*1000000 + ts.tv_nsec/1000;
-}
lib/libc/wasi/libc-top-half/musl/src/time/clock_getcpuclockid.c
@@ -1,14 +0,0 @@
-#include <time.h>
-#include <errno.h>
-#include <unistd.h>
-#include "syscall.h"
-
-int clock_getcpuclockid(pid_t pid, clockid_t *clk)
-{
- struct timespec ts;
- clockid_t id = (-pid-1)*8U + 2;
- int ret = __syscall(SYS_clock_getres, id, &ts);
- if (ret) return -ret;
- *clk = id;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/time/clock_getres.c
@@ -1,21 +0,0 @@
-#include <time.h>
-#include "syscall.h"
-
-int clock_getres(clockid_t clk, struct timespec *ts)
-{
-#ifdef SYS_clock_getres_time64
- /* On a 32-bit arch, use the old syscall if it exists. */
- if (SYS_clock_getres != SYS_clock_getres_time64) {
- long ts32[2];
- int r = __syscall(SYS_clock_getres, clk, ts32);
- if (!r && ts) {
- ts->tv_sec = ts32[0];
- ts->tv_nsec = ts32[1];
- }
- return __syscall_ret(r);
- }
-#endif
- /* If reaching this point, it's a 64-bit arch or time64-only
- * 32-bit arch and we can get result directly into timespec. */
- return syscall(SYS_clock_getres, clk, ts);
-}
lib/libc/wasi/libc-top-half/musl/src/time/clock_gettime.c
@@ -1,107 +0,0 @@
-#include <time.h>
-#include <errno.h>
-#include <stdint.h>
-#include "syscall.h"
-#include "atomic.h"
-
-#ifdef VDSO_CGT_SYM
-
-static void *volatile vdso_func;
-
-#ifdef VDSO_CGT32_SYM
-static void *volatile vdso_func_32;
-static int cgt_time32_wrap(clockid_t clk, struct timespec *ts)
-{
- long ts32[2];
- int (*f)(clockid_t, long[2]) =
- (int (*)(clockid_t, long[2]))vdso_func_32;
- int r = f(clk, ts32);
- if (!r) {
- /* Fallback to syscalls if time32 overflowed. Maybe
- * we lucked out and somehow migrated to a kernel with
- * time64 syscalls available. */
- if (ts32[0] < 0) {
- a_cas_p(&vdso_func, (void *)cgt_time32_wrap, 0);
- return -ENOSYS;
- }
- ts->tv_sec = ts32[0];
- ts->tv_nsec = ts32[1];
- }
- return r;
-}
-#endif
-
-static int cgt_init(clockid_t clk, struct timespec *ts)
-{
- void *p = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM);
-#ifdef VDSO_CGT32_SYM
- if (!p) {
- void *q = __vdsosym(VDSO_CGT32_VER, VDSO_CGT32_SYM);
- if (q) {
- a_cas_p(&vdso_func_32, 0, q);
- p = cgt_time32_wrap;
- }
- }
-#endif
- int (*f)(clockid_t, struct timespec *) =
- (int (*)(clockid_t, struct timespec *))p;
- a_cas_p(&vdso_func, (void *)cgt_init, p);
- return f ? f(clk, ts) : -ENOSYS;
-}
-
-static void *volatile vdso_func = (void *)cgt_init;
-
-#endif
-
-int __clock_gettime(clockid_t clk, struct timespec *ts)
-{
- int r;
-
-#ifdef VDSO_CGT_SYM
- int (*f)(clockid_t, struct timespec *) =
- (int (*)(clockid_t, struct timespec *))vdso_func;
- if (f) {
- r = f(clk, ts);
- if (!r) return r;
- if (r == -EINVAL) return __syscall_ret(r);
- /* Fall through on errors other than EINVAL. Some buggy
- * vdso implementations return ENOSYS for clocks they
- * can't handle, rather than making the syscall. This
- * also handles the case where cgt_init fails to find
- * a vdso function to use. */
- }
-#endif
-
-#ifdef SYS_clock_gettime64
- r = -ENOSYS;
- if (sizeof(time_t) > 4)
- r = __syscall(SYS_clock_gettime64, clk, ts);
- if (SYS_clock_gettime == SYS_clock_gettime64 || r!=-ENOSYS)
- return __syscall_ret(r);
- long ts32[2];
- r = __syscall(SYS_clock_gettime, clk, ts32);
- if (r==-ENOSYS && clk==CLOCK_REALTIME) {
- r = __syscall(SYS_gettimeofday, ts32, 0);
- ts32[1] *= 1000;
- }
- if (!r) {
- ts->tv_sec = ts32[0];
- ts->tv_nsec = ts32[1];
- return r;
- }
- return __syscall_ret(r);
-#else
- r = __syscall(SYS_clock_gettime, clk, ts);
- if (r == -ENOSYS) {
- if (clk == CLOCK_REALTIME) {
- __syscall(SYS_gettimeofday, ts, 0);
- ts->tv_nsec = (int)ts->tv_nsec * 1000;
- return 0;
- }
- r = -EINVAL;
- }
- return __syscall_ret(r);
-#endif
-}
-
-weak_alias(__clock_gettime, clock_gettime);
lib/libc/wasi/libc-top-half/musl/src/time/clock_nanosleep.c
@@ -1,38 +0,0 @@
-#include <time.h>
-#include <errno.h>
-#include "syscall.h"
-
-#define IS32BIT(x) !((x)+0x80000000ULL>>32)
-#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
-
-int __clock_nanosleep(clockid_t clk, int flags, const struct timespec *req, struct timespec *rem)
-{
- if (clk == CLOCK_THREAD_CPUTIME_ID) return EINVAL;
-#ifdef SYS_clock_nanosleep_time64
- time_t s = req->tv_sec;
- long ns = req->tv_nsec;
- int r = -ENOSYS;
- if (SYS_clock_nanosleep == SYS_clock_nanosleep_time64 || !IS32BIT(s))
- r = __syscall_cp(SYS_clock_nanosleep_time64, clk, flags,
- ((long long[]){s, ns}), rem);
- if (SYS_clock_nanosleep == SYS_clock_nanosleep_time64 || r!=-ENOSYS)
- return -r;
- long long extra = s - CLAMP(s);
- long ts32[2] = { CLAMP(s), ns };
- if (clk == CLOCK_REALTIME && !flags)
- r = __syscall_cp(SYS_nanosleep, &ts32, &ts32);
- else
- r = __syscall_cp(SYS_clock_nanosleep, clk, flags, &ts32, &ts32);
- if (r==-EINTR && rem && !(flags & TIMER_ABSTIME)) {
- rem->tv_sec = ts32[0] + extra;
- rem->tv_nsec = ts32[1];
- }
- return -r;
-#else
- if (clk == CLOCK_REALTIME && !flags)
- return -__syscall_cp(SYS_nanosleep, req, rem);
- return -__syscall_cp(SYS_clock_nanosleep, clk, flags, req, rem);
-#endif
-}
-
-weak_alias(__clock_nanosleep, clock_nanosleep);
lib/libc/wasi/libc-top-half/musl/src/time/clock_settime.c
@@ -1,24 +0,0 @@
-#include <time.h>
-#include <errno.h>
-#include "syscall.h"
-
-#define IS32BIT(x) !((x)+0x80000000ULL>>32)
-
-int clock_settime(clockid_t clk, const struct timespec *ts)
-{
-#ifdef SYS_clock_settime64
- time_t s = ts->tv_sec;
- long ns = ts->tv_nsec;
- int r = -ENOSYS;
- if (SYS_clock_settime == SYS_clock_settime64 || !IS32BIT(s))
- r = __syscall(SYS_clock_settime64, clk,
- ((long long[]){s, ns}));
- if (SYS_clock_settime == SYS_clock_settime64 || r!=-ENOSYS)
- return __syscall_ret(r);
- if (!IS32BIT(s))
- return __syscall_ret(-ENOTSUP);
- return syscall(SYS_clock_settime, clk, ((long[]){s, ns}));
-#else
- return syscall(SYS_clock_settime, clk, ts);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/time/gettimeofday.c
@@ -1,13 +0,0 @@
-#include <time.h>
-#include <sys/time.h>
-#include "syscall.h"
-
-int gettimeofday(struct timeval *restrict tv, void *restrict tz)
-{
- struct timespec ts;
- if (!tv) return 0;
- clock_gettime(CLOCK_REALTIME, &ts);
- tv->tv_sec = ts.tv_sec;
- tv->tv_usec = (int)ts.tv_nsec / 1000;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/time/nanosleep.c
@@ -1,7 +0,0 @@
-#include <time.h>
-#include "syscall.h"
-
-int nanosleep(const struct timespec *req, struct timespec *rem)
-{
- return __syscall_ret(-__clock_nanosleep(CLOCK_REALTIME, 0, req, rem));
-}
lib/libc/wasi/libc-top-half/musl/src/time/time.c
@@ -1,10 +0,0 @@
-#include <time.h>
-#include "syscall.h"
-
-time_t time(time_t *t)
-{
- struct timespec ts;
- __clock_gettime(CLOCK_REALTIME, &ts);
- if (t) *t = ts.tv_sec;
- return ts.tv_sec;
-}
lib/libc/wasi/libc-top-half/musl/src/time/timer_create.c
@@ -1,129 +0,0 @@
-#include <time.h>
-#include <setjmp.h>
-#include <limits.h>
-#include "pthread_impl.h"
-#include "atomic.h"
-
-struct ksigevent {
- union sigval sigev_value;
- int sigev_signo;
- int sigev_notify;
- int sigev_tid;
-};
-
-struct start_args {
- pthread_barrier_t b;
- struct sigevent *sev;
-};
-
-static void dummy_0()
-{
-}
-weak_alias(dummy_0, __pthread_tsd_run_dtors);
-
-static void cleanup_fromsig(void *p)
-{
- pthread_t self = __pthread_self();
- __pthread_tsd_run_dtors();
- self->cancel = 0;
- self->cancelbuf = 0;
- self->canceldisable = 0;
- self->cancelasync = 0;
- __reset_tls();
- longjmp(p, 1);
-}
-
-static void *start(void *arg)
-{
- pthread_t self = __pthread_self();
- struct start_args *args = arg;
- jmp_buf jb;
-
- void (*notify)(union sigval) = args->sev->sigev_notify_function;
- union sigval val = args->sev->sigev_value;
-
- pthread_barrier_wait(&args->b);
- for (;;) {
- siginfo_t si;
- while (sigwaitinfo(SIGTIMER_SET, &si) < 0);
- if (si.si_code == SI_TIMER && !setjmp(jb)) {
- pthread_cleanup_push(cleanup_fromsig, jb);
- notify(val);
- pthread_cleanup_pop(1);
- }
- if (self->timer_id < 0) break;
- }
- __syscall(SYS_timer_delete, self->timer_id & INT_MAX);
- return 0;
-}
-
-int timer_create(clockid_t clk, struct sigevent *restrict evp, timer_t *restrict res)
-{
- volatile static int init = 0;
- pthread_t td;
- pthread_attr_t attr;
- int r;
- struct start_args args;
- struct ksigevent ksev, *ksevp=0;
- int timerid;
- sigset_t set;
-
- switch (evp ? evp->sigev_notify : SIGEV_SIGNAL) {
- case SIGEV_NONE:
- case SIGEV_SIGNAL:
- case SIGEV_THREAD_ID:
- if (evp) {
- ksev.sigev_value = evp->sigev_value;
- ksev.sigev_signo = evp->sigev_signo;
- ksev.sigev_notify = evp->sigev_notify;
- if (evp->sigev_notify == SIGEV_THREAD_ID)
- ksev.sigev_tid = evp->sigev_notify_thread_id;
- else
- ksev.sigev_tid = 0;
- ksevp = &ksev;
- }
- if (syscall(SYS_timer_create, clk, ksevp, &timerid) < 0)
- return -1;
- *res = (void *)(intptr_t)timerid;
- break;
- case SIGEV_THREAD:
- if (!init) {
- struct sigaction sa = { .sa_handler = SIG_DFL };
- __libc_sigaction(SIGTIMER, &sa, 0);
- a_store(&init, 1);
- }
- if (evp->sigev_notify_attributes)
- attr = *evp->sigev_notify_attributes;
- else
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- pthread_barrier_init(&args.b, 0, 2);
- args.sev = evp;
-
- __block_app_sigs(&set);
- __syscall(SYS_rt_sigprocmask, SIG_BLOCK, SIGTIMER_SET, 0, _NSIG/8);
- r = pthread_create(&td, &attr, start, &args);
- __restore_sigs(&set);
- if (r) {
- errno = r;
- return -1;
- }
-
- ksev.sigev_value.sival_ptr = 0;
- ksev.sigev_signo = SIGTIMER;
- ksev.sigev_notify = SIGEV_THREAD_ID;
- ksev.sigev_tid = td->tid;
- if (syscall(SYS_timer_create, clk, &ksev, &timerid) < 0)
- timerid = -1;
- td->timer_id = timerid;
- pthread_barrier_wait(&args.b);
- if (timerid < 0) return -1;
- *res = (void *)(INTPTR_MIN | (uintptr_t)td>>1);
- break;
- default:
- errno = EINVAL;
- return -1;
- }
-
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/time/timer_delete.c
@@ -1,14 +0,0 @@
-#include <time.h>
-#include <limits.h>
-#include "pthread_impl.h"
-
-int timer_delete(timer_t t)
-{
- if ((intptr_t)t < 0) {
- pthread_t td = (void *)((uintptr_t)t << 1);
- a_store(&td->timer_id, td->timer_id | INT_MIN);
- __syscall(SYS_tkill, td->tid, SIGTIMER);
- return 0;
- }
- return __syscall(SYS_timer_delete, t);
-}
lib/libc/wasi/libc-top-half/musl/src/time/timer_getoverrun.c
@@ -1,12 +0,0 @@
-#include <time.h>
-#include <limits.h>
-#include "pthread_impl.h"
-
-int timer_getoverrun(timer_t t)
-{
- if ((intptr_t)t < 0) {
- pthread_t td = (void *)((uintptr_t)t << 1);
- t = (void *)(uintptr_t)(td->timer_id & INT_MAX);
- }
- return syscall(SYS_timer_getoverrun, t);
-}
lib/libc/wasi/libc-top-half/musl/src/time/timer_gettime.c
@@ -1,28 +0,0 @@
-#include <time.h>
-#include <limits.h>
-#include "pthread_impl.h"
-
-int timer_gettime(timer_t t, struct itimerspec *val)
-{
- if ((intptr_t)t < 0) {
- pthread_t td = (void *)((uintptr_t)t << 1);
- t = (void *)(uintptr_t)(td->timer_id & INT_MAX);
- }
-#ifdef SYS_timer_gettime64
- int r = -ENOSYS;
- if (sizeof(time_t) > 4)
- r = __syscall(SYS_timer_gettime64, t, val);
- if (SYS_timer_gettime == SYS_timer_gettime64 || r!=-ENOSYS)
- return __syscall_ret(r);
- long val32[4];
- r = __syscall(SYS_timer_gettime, t, val32);
- if (!r) {
- val->it_interval.tv_sec = val32[0];
- val->it_interval.tv_nsec = val32[1];
- val->it_value.tv_sec = val32[2];
- val->it_value.tv_nsec = val32[3];
- }
- return __syscall_ret(r);
-#endif
- return syscall(SYS_timer_gettime, t, val);
-}
lib/libc/wasi/libc-top-half/musl/src/time/timer_settime.c
@@ -1,37 +0,0 @@
-#include <time.h>
-#include <limits.h>
-#include "pthread_impl.h"
-
-#define IS32BIT(x) !((x)+0x80000000ULL>>32)
-
-int timer_settime(timer_t t, int flags, const struct itimerspec *restrict val, struct itimerspec *restrict old)
-{
- if ((intptr_t)t < 0) {
- pthread_t td = (void *)((uintptr_t)t << 1);
- t = (void *)(uintptr_t)(td->timer_id & INT_MAX);
- }
-#ifdef SYS_timer_settime64
- time_t is = val->it_interval.tv_sec, vs = val->it_value.tv_sec;
- long ins = val->it_interval.tv_nsec, vns = val->it_value.tv_nsec;
- int r = -ENOSYS;
- if (SYS_timer_settime == SYS_timer_settime64
- || !IS32BIT(is) || !IS32BIT(vs) || (sizeof(time_t)>4 && old))
- r = __syscall(SYS_timer_settime64, t, flags,
- ((long long[]){is, ins, vs, vns}), old);
- if (SYS_timer_settime == SYS_timer_settime64 || r!=-ENOSYS)
- return __syscall_ret(r);
- if (!IS32BIT(is) || !IS32BIT(vs))
- return __syscall_ret(-ENOTSUP);
- long old32[4];
- r = __syscall(SYS_timer_settime, t, flags,
- ((long[]){is, ins, vs, vns}), old32);
- if (!r && old) {
- old->it_interval.tv_sec = old32[0];
- old->it_interval.tv_nsec = old32[1];
- old->it_value.tv_sec = old32[2];
- old->it_value.tv_nsec = old32[3];
- }
- return __syscall_ret(r);
-#endif
- return syscall(SYS_timer_settime, t, flags, val, old);
-}
lib/libc/wasi/libc-top-half/musl/src/time/times.c
@@ -1,7 +0,0 @@
-#include <sys/times.h>
-#include "syscall.h"
-
-clock_t times(struct tms *tms)
-{
- return __syscall(SYS_times, tms);
-}
lib/libc/wasi/libc-top-half/musl/src/time/utime.c
@@ -1,11 +0,0 @@
-#include <utime.h>
-#include <sys/stat.h>
-#include <time.h>
-#include <fcntl.h>
-
-int utime(const char *path, const struct utimbuf *times)
-{
- return utimensat(AT_FDCWD, path, times ? ((struct timespec [2]){
- { .tv_sec = times->actime }, { .tv_sec = times->modtime }})
- : 0, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/mips/pipe.s
@@ -1,20 +0,0 @@
-.set noreorder
-
-.global pipe
-.type pipe,@function
-pipe:
- lui $gp, %hi(_gp_disp)
- addiu $gp, %lo(_gp_disp)
- addu $gp, $gp, $25
- li $2, 4042
- syscall
- beq $7, $0, 1f
- nop
- lw $25, %call16(__syscall_ret)($gp)
- jr $25
- subu $4, $0, $2
-1: sw $2, 0($4)
- sw $3, 4($4)
- move $2, $0
- jr $ra
- nop
lib/libc/wasi/libc-top-half/musl/src/unistd/mips64/pipe.s
@@ -1,19 +0,0 @@
-.set noreorder
-.global pipe
-.type pipe,@function
-pipe:
- lui $3, %hi(%neg(%gp_rel(pipe)))
- daddiu $3, $3, %lo(%neg(%gp_rel(pipe)))
- daddu $3, $3, $25
- li $2, 5021
- syscall
- beq $7, $0, 1f
- nop
- ld $25, %got_disp(__syscall_ret)($3)
- jr $25
- dsubu $4, $0, $2
-1: sw $2, 0($4)
- sw $3, 4($4)
- move $2, $0
- jr $ra
- nop
lib/libc/wasi/libc-top-half/musl/src/unistd/mipsn32/lseek.c
@@ -1,20 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-off_t __lseek(int fd, off_t offset, int whence)
-{
- register long long r4 __asm__("$4") = fd;
- register long long r5 __asm__("$5") = offset;
- register long long r6 __asm__("$6") = whence;
- register long long r7 __asm__("$7");
- register long long r2 __asm__("$2") = SYS_lseek;
- __asm__ __volatile__ (
- "syscall"
- : "+&r"(r2), "=r"(r7)
- : "r"(r4), "r"(r5), "r"(r6)
- : SYSCALL_CLOBBERLIST);
- return r7 ? __syscall_ret(-r2) : r2;
-}
-
-weak_alias(__lseek, lseek);
-weak_alias(__lseek, lseek64);
lib/libc/wasi/libc-top-half/musl/src/unistd/mipsn32/pipe.s
@@ -1,19 +0,0 @@
-.set noreorder
-.global pipe
-.type pipe,@function
-pipe:
- lui $3, %hi(%neg(%gp_rel(pipe)))
- addiu $3, $3, %lo(%neg(%gp_rel(pipe)))
- addu $3, $3, $25
- li $2, 6021
- syscall
- beq $7, $0, 1f
- nop
- lw $25, %got_disp(__syscall_ret)($3)
- jr $25
- subu $4, $0, $2
-1: sw $2, 0($4)
- sw $3, 4($4)
- move $2, $0
- jr $ra
- nop
lib/libc/wasi/libc-top-half/musl/src/unistd/sh/pipe.s
@@ -1,27 +0,0 @@
-.global pipe
-.type pipe, @function
-pipe:
- mov #42, r3
- trapa #31
-
- ! work around hardware bug
- or r0, r0
- or r0, r0
- or r0, r0
- or r0, r0
- or r0, r0
-
- cmp/pz r0
- bt 1f
-
- mov.l L1, r1
- braf r1
- mov r0, r4
-
-1: mov.l r0, @(0,r4)
- mov.l r1, @(4,r4)
- rts
- mov #0, r0
-
-.align 2
-L1: .long __syscall_ret@PLT-(1b-.)
lib/libc/wasi/libc-top-half/musl/src/unistd/x32/lseek.c
@@ -1,15 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-off_t __lseek(int fd, off_t offset, int whence)
-{
- off_t ret;
- __asm__ __volatile__ ("syscall"
- : "=a"(ret)
- : "a"(SYS_lseek), "D"(fd), "S"(offset), "d"(whence)
- : "rcx", "r11", "memory");
- return ret < 0 ? __syscall_ret(ret) : ret;
-}
-
-weak_alias(__lseek, lseek);
-weak_alias(__lseek, lseek64);
lib/libc/wasi/libc-top-half/musl/src/unistd/_exit.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include <stdlib.h>
-
-_Noreturn void _exit(int status)
-{
- _Exit(status);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/access.c
@@ -1,12 +0,0 @@
-#include <unistd.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int access(const char *filename, int amode)
-{
-#ifdef SYS_access
- return syscall(SYS_access, filename, amode);
-#else
- return syscall(SYS_faccessat, AT_FDCWD, filename, amode, 0);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/acct.c
@@ -1,8 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include "syscall.h"
-
-int acct(const char *filename)
-{
- return syscall(SYS_acct, filename);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/alarm.c
@@ -1,10 +0,0 @@
-#include <unistd.h>
-#include <sys/time.h>
-#include "syscall.h"
-
-unsigned alarm(unsigned seconds)
-{
- struct itimerval it = { .it_value.tv_sec = seconds }, old = { 0 };
- setitimer(ITIMER_REAL, &it, &old);
- return old.it_value.tv_sec + !!old.it_value.tv_usec;
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/chdir.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-int chdir(const char *path)
-{
- return syscall(SYS_chdir, path);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/chown.c
@@ -1,12 +0,0 @@
-#include <unistd.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int chown(const char *path, uid_t uid, gid_t gid)
-{
-#ifdef SYS_chown
- return syscall(SYS_chown, path, uid, gid);
-#else
- return syscall(SYS_fchownat, AT_FDCWD, path, uid, gid, 0);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/close.c
@@ -1,19 +0,0 @@
-#include <unistd.h>
-#include <errno.h>
-#include "aio_impl.h"
-#include "syscall.h"
-
-static int dummy(int fd)
-{
- return fd;
-}
-
-weak_alias(dummy, __aio_close);
-
-int close(int fd)
-{
- fd = __aio_close(fd);
- int r = __syscall_cp(SYS_close, fd);
- if (r == -EINTR) r = 0;
- return __syscall_ret(r);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/ctermid.c
@@ -1,7 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-
-char *ctermid(char *s)
-{
- return s ? strcpy(s, "/dev/tty") : "/dev/tty";
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/dup.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-int dup(int fd)
-{
- return syscall(SYS_dup, fd);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/dup2.c
@@ -1,20 +0,0 @@
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int dup2(int old, int new)
-{
- int r;
-#ifdef SYS_dup2
- while ((r=__syscall(SYS_dup2, old, new))==-EBUSY);
-#else
- if (old==new) {
- r = __syscall(SYS_fcntl, old, F_GETFD);
- if (r >= 0) return old;
- } else {
- while ((r=__syscall(SYS_dup3, old, new, 0))==-EBUSY);
- }
-#endif
- return __syscall_ret(r);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/dup3.c
@@ -1,24 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int __dup3(int old, int new, int flags)
-{
- int r;
-#ifdef SYS_dup2
- if (old==new) return __syscall_ret(-EINVAL);
- if (flags & O_CLOEXEC) {
- while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY);
- if (r!=-ENOSYS) return __syscall_ret(r);
- }
- while ((r=__syscall(SYS_dup2, old, new))==-EBUSY);
- if (flags & O_CLOEXEC) __syscall(SYS_fcntl, new, F_SETFD, FD_CLOEXEC);
-#else
- while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY);
-#endif
- return __syscall_ret(r);
-}
-
-weak_alias(__dup3, dup3);
lib/libc/wasi/libc-top-half/musl/src/unistd/faccessat.c
@@ -1,61 +0,0 @@
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/wait.h>
-#include "syscall.h"
-#include "pthread_impl.h"
-
-struct ctx {
- int fd;
- const char *filename;
- int amode;
- int p;
-};
-
-static int checker(void *p)
-{
- struct ctx *c = p;
- int ret;
- if (__syscall(SYS_setregid, __syscall(SYS_getegid), -1)
- || __syscall(SYS_setreuid, __syscall(SYS_geteuid), -1))
- __syscall(SYS_exit, 1);
- ret = __syscall(SYS_faccessat, c->fd, c->filename, c->amode, 0);
- __syscall(SYS_write, c->p, &ret, sizeof ret);
- return 0;
-}
-
-int faccessat(int fd, const char *filename, int amode, int flag)
-{
- if (flag) {
- int ret = __syscall(SYS_faccessat2, fd, filename, amode, flag);
- if (ret != -ENOSYS) return __syscall_ret(ret);
- }
-
- if (flag & ~AT_EACCESS)
- return __syscall_ret(-EINVAL);
-
- if (!flag || (getuid()==geteuid() && getgid()==getegid()))
- return syscall(SYS_faccessat, fd, filename, amode);
-
- char stack[1024];
- sigset_t set;
- pid_t pid;
- int status;
- int ret, p[2];
-
- if (pipe2(p, O_CLOEXEC)) return __syscall_ret(-EBUSY);
- struct ctx c = { .fd = fd, .filename = filename, .amode = amode, .p = p[1] };
-
- __block_all_sigs(&set);
-
- pid = __clone(checker, stack+sizeof stack, 0, &c);
- __syscall(SYS_close, p[1]);
-
- if (pid<0 || __syscall(SYS_read, p[0], &ret, sizeof ret) != sizeof(ret))
- ret = -EBUSY;
- __syscall(SYS_close, p[0]);
- __syscall(SYS_wait4, pid, &status, __WCLONE, 0);
-
- __restore_sigs(&set);
-
- return __syscall_ret(ret);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/fchdir.c
@@ -1,15 +0,0 @@
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int fchdir(int fd)
-{
- int ret = __syscall(SYS_fchdir, fd);
- if (ret != -EBADF || __syscall(SYS_fcntl, fd, F_GETFD) < 0)
- return __syscall_ret(ret);
-
- char buf[15+3*sizeof(int)];
- __procfdname(buf, fd);
- return syscall(SYS_chdir, buf);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/fchown.c
@@ -1,20 +0,0 @@
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int fchown(int fd, uid_t uid, gid_t gid)
-{
- int ret = __syscall(SYS_fchown, fd, uid, gid);
- if (ret != -EBADF || __syscall(SYS_fcntl, fd, F_GETFD) < 0)
- return __syscall_ret(ret);
-
- char buf[15+3*sizeof(int)];
- __procfdname(buf, fd);
-#ifdef SYS_chown
- return syscall(SYS_chown, buf, uid, gid);
-#else
- return syscall(SYS_fchownat, AT_FDCWD, buf, uid, gid, 0);
-#endif
-
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/fchownat.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-int fchownat(int fd, const char *path, uid_t uid, gid_t gid, int flag)
-{
- return syscall(SYS_fchownat, fd, path, uid, gid, flag);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/fdatasync.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-int fdatasync(int fd)
-{
- return syscall_cp(SYS_fdatasync, fd);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/fsync.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-int fsync(int fd)
-{
- return syscall_cp(SYS_fsync, fd);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/ftruncate.c
@@ -1,9 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-int ftruncate(int fd, off_t length)
-{
- return syscall(SYS_ftruncate, fd, __SYSCALL_LL_O(length));
-}
-
-weak_alias(ftruncate, ftruncate64);
lib/libc/wasi/libc-top-half/musl/src/unistd/getcwd.c
@@ -1,25 +0,0 @@
-#include <unistd.h>
-#include <errno.h>
-#include <limits.h>
-#include <string.h>
-#include "syscall.h"
-
-char *getcwd(char *buf, size_t size)
-{
- char tmp[buf ? 1 : PATH_MAX];
- if (!buf) {
- buf = tmp;
- size = sizeof tmp;
- } else if (!size) {
- errno = EINVAL;
- return 0;
- }
- long ret = syscall(SYS_getcwd, buf, size);
- if (ret < 0)
- return 0;
- if (ret == 0 || buf[0] != '/') {
- errno = ENOENT;
- return 0;
- }
- return buf == tmp ? strdup(buf) : buf;
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/getegid.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-gid_t getegid(void)
-{
- return __syscall(SYS_getegid);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/geteuid.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-uid_t geteuid(void)
-{
- return __syscall(SYS_geteuid);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/getgid.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-gid_t getgid(void)
-{
- return __syscall(SYS_getgid);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/getgroups.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-int getgroups(int count, gid_t list[])
-{
- return syscall(SYS_getgroups, count, list);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/gethostname.c
@@ -1,13 +0,0 @@
-#include <unistd.h>
-#include <sys/utsname.h>
-
-int gethostname(char *name, size_t len)
-{
- size_t i;
- struct utsname uts;
- if (uname(&uts)) return -1;
- if (len > sizeof uts.nodename) len = sizeof uts.nodename;
- for (i=0; i<len && (name[i] = uts.nodename[i]); i++);
- if (i && i==len) name[i-1] = 0;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/getlogin.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include <stdlib.h>
-
-char *getlogin(void)
-{
- return getenv("LOGNAME");
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/getlogin_r.c
@@ -1,12 +0,0 @@
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-
-int getlogin_r(char *name, size_t size)
-{
- char *logname = getlogin();
- if (!logname) return ENXIO; /* or...? */
- if (strlen(logname) >= size) return ERANGE;
- strcpy(name, logname);
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/getpgid.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-pid_t getpgid(pid_t pid)
-{
- return syscall(SYS_getpgid, pid);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/getpgrp.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-pid_t getpgrp(void)
-{
- return __syscall(SYS_getpgid, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/getpid.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-pid_t getpid(void)
-{
- return __syscall(SYS_getpid);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/getppid.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-pid_t getppid(void)
-{
- return __syscall(SYS_getppid);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/getsid.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-pid_t getsid(pid_t pid)
-{
- return syscall(SYS_getsid, pid);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/getuid.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-uid_t getuid(void)
-{
- return __syscall(SYS_getuid);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/isatty.c
@@ -1,13 +0,0 @@
-#include <unistd.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include "syscall.h"
-
-int isatty(int fd)
-{
- struct winsize wsz;
- unsigned long r = syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz);
- if (r == 0) return 1;
- if (errno != EBADF) errno = ENOTTY;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/lchown.c
@@ -1,12 +0,0 @@
-#include <unistd.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int lchown(const char *path, uid_t uid, gid_t gid)
-{
-#ifdef SYS_lchown
- return syscall(SYS_lchown, path, uid, gid);
-#else
- return syscall(SYS_fchownat, AT_FDCWD, path, uid, gid, AT_SYMLINK_NOFOLLOW);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/link.c
@@ -1,12 +0,0 @@
-#include <unistd.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int link(const char *existing, const char *new)
-{
-#ifdef SYS_link
- return syscall(SYS_link, existing, new);
-#else
- return syscall(SYS_linkat, AT_FDCWD, existing, AT_FDCWD, new, 0);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/linkat.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-int linkat(int fd1, const char *existing, int fd2, const char *new, int flag)
-{
- return syscall(SYS_linkat, fd1, existing, fd2, new, flag);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/lseek.c
@@ -1,23 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-off_t __lseek(int fd, off_t offset, int whence)
-{
-#ifdef SYS__llseek
- off_t result;
-#ifdef __wasilibc_unmodified_upstream // WASI has no syscall
- return syscall(SYS__llseek, fd, offset>>32, offset, &result, whence) ? -1 : result;
-#else
- return llseek(fd, offset>>32, offset, &result, whence) ? -1 : result;
-#endif
-#else
-#ifdef __wasilibc_unmodified_upstream // WASI has no syscall
- return syscall(SYS_lseek, fd, offset, whence);
-#else
- return lseek(fd, offset, whence);
-#endif
-#endif
-}
-
-weak_alias(__lseek, lseek);
-weak_alias(__lseek, lseek64);
lib/libc/wasi/libc-top-half/musl/src/unistd/nice.c
@@ -1,23 +0,0 @@
-#include <unistd.h>
-#include <errno.h>
-#include <sys/resource.h>
-#include <limits.h>
-#include "syscall.h"
-
-int nice(int inc)
-{
- int prio = inc;
- // Only query old priority if it can affect the result.
- // This also avoids issues with integer overflow.
- if (inc > -2*NZERO && inc < 2*NZERO)
- prio += getpriority(PRIO_PROCESS, 0);
- if (prio > NZERO-1) prio = NZERO-1;
- if (prio < -NZERO) prio = -NZERO;
- if (setpriority(PRIO_PROCESS, 0, prio)) {
- if (errno == EACCES)
- errno = EPERM;
- return -1;
- } else {
- return prio;
- }
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/pause.c
@@ -1,11 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-int pause(void)
-{
-#ifdef SYS_pause
- return syscall_cp(SYS_pause);
-#else
- return syscall_cp(SYS_ppoll, 0, 0, 0, 0);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/pipe.c
@@ -1,11 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-int pipe(int fd[2])
-{
-#ifdef SYS_pipe
- return syscall(SYS_pipe, fd);
-#else
- return syscall(SYS_pipe2, fd, 0);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/pipe2.c
@@ -1,22 +0,0 @@
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int pipe2(int fd[2], int flag)
-{
- if (!flag) return pipe(fd);
- int ret = __syscall(SYS_pipe2, fd, flag);
- if (ret != -ENOSYS) return __syscall_ret(ret);
- ret = pipe(fd);
- if (ret) return ret;
- if (flag & O_CLOEXEC) {
- __syscall(SYS_fcntl, fd[0], F_SETFD, FD_CLOEXEC);
- __syscall(SYS_fcntl, fd[1], F_SETFD, FD_CLOEXEC);
- }
- if (flag & O_NONBLOCK) {
- __syscall(SYS_fcntl, fd[0], F_SETFL, O_NONBLOCK);
- __syscall(SYS_fcntl, fd[1], F_SETFL, O_NONBLOCK);
- }
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/pread.c
@@ -1,9 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-ssize_t pread(int fd, void *buf, size_t size, off_t ofs)
-{
- return syscall_cp(SYS_pread, fd, buf, size, __SYSCALL_LL_PRW(ofs));
-}
-
-weak_alias(pread, pread64);
lib/libc/wasi/libc-top-half/musl/src/unistd/preadv.c
@@ -1,12 +0,0 @@
-#define _BSD_SOURCE
-#include <sys/uio.h>
-#include <unistd.h>
-#include "syscall.h"
-
-ssize_t preadv(int fd, const struct iovec *iov, int count, off_t ofs)
-{
- return syscall_cp(SYS_preadv, fd, iov, count,
- (long)(ofs), (long)(ofs>>32));
-}
-
-weak_alias(preadv, preadv64);
lib/libc/wasi/libc-top-half/musl/src/unistd/pwrite.c
@@ -1,9 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs)
-{
- return syscall_cp(SYS_pwrite, fd, buf, size, __SYSCALL_LL_PRW(ofs));
-}
-
-weak_alias(pwrite, pwrite64);
lib/libc/wasi/libc-top-half/musl/src/unistd/pwritev.c
@@ -1,12 +0,0 @@
-#define _BSD_SOURCE
-#include <sys/uio.h>
-#include <unistd.h>
-#include "syscall.h"
-
-ssize_t pwritev(int fd, const struct iovec *iov, int count, off_t ofs)
-{
- return syscall_cp(SYS_pwritev, fd, iov, count,
- (long)(ofs), (long)(ofs>>32));
-}
-
-weak_alias(pwritev, pwritev64);
lib/libc/wasi/libc-top-half/musl/src/unistd/read.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-ssize_t read(int fd, void *buf, size_t count)
-{
- return syscall_cp(SYS_read, fd, buf, count);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/readlink.c
@@ -1,19 +0,0 @@
-#include <unistd.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize)
-{
- char dummy[1];
- if (!bufsize) {
- buf = dummy;
- bufsize = 1;
- }
-#ifdef SYS_readlink
- int r = __syscall(SYS_readlink, path, buf, bufsize);
-#else
- int r = __syscall(SYS_readlinkat, AT_FDCWD, path, buf, bufsize);
-#endif
- if (buf == dummy && r > 0) r = 0;
- return __syscall_ret(r);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/readlinkat.c
@@ -1,14 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize)
-{
- char dummy[1];
- if (!bufsize) {
- buf = dummy;
- bufsize = 1;
- }
- int r = __syscall(SYS_readlinkat, fd, path, buf, bufsize);
- if (buf == dummy && r > 0) r = 0;
- return __syscall_ret(r);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/readv.c
@@ -1,7 +0,0 @@
-#include <sys/uio.h>
-#include "syscall.h"
-
-ssize_t readv(int fd, const struct iovec *iov, int count)
-{
- return syscall_cp(SYS_readv, fd, iov, count);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/renameat.c
@@ -1,11 +0,0 @@
-#include <stdio.h>
-#include "syscall.h"
-
-int renameat(int oldfd, const char *old, int newfd, const char *new)
-{
-#ifdef SYS_renameat
- return syscall(SYS_renameat, oldfd, old, newfd, new);
-#else
- return syscall(SYS_renameat2, oldfd, old, newfd, new, 0);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/rmdir.c
@@ -1,12 +0,0 @@
-#include <unistd.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int rmdir(const char *path)
-{
-#ifdef SYS_rmdir
- return syscall(SYS_rmdir, path);
-#else
- return syscall(SYS_unlinkat, AT_FDCWD, path, AT_REMOVEDIR);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/setegid.c
@@ -1,8 +0,0 @@
-#include <unistd.h>
-#include "libc.h"
-#include "syscall.h"
-
-int setegid(gid_t egid)
-{
- return __setxid(SYS_setresgid, -1, egid, -1);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/seteuid.c
@@ -1,8 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-#include "libc.h"
-
-int seteuid(uid_t euid)
-{
- return __setxid(SYS_setresuid, -1, euid, -1);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/setgid.c
@@ -1,8 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-#include "libc.h"
-
-int setgid(gid_t gid)
-{
- return __setxid(SYS_setgid, gid, 0, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/setpgid.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-int setpgid(pid_t pid, pid_t pgid)
-{
- return syscall(SYS_setpgid, pid, pgid);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/setpgrp.c
@@ -1,6 +0,0 @@
-#include <unistd.h>
-
-pid_t setpgrp(void)
-{
- return setpgid(0, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/setregid.c
@@ -1,8 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-#include "libc.h"
-
-int setregid(gid_t rgid, gid_t egid)
-{
- return __setxid(SYS_setregid, rgid, egid, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/setresgid.c
@@ -1,9 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include "syscall.h"
-#include "libc.h"
-
-int setresgid(gid_t rgid, gid_t egid, gid_t sgid)
-{
- return __setxid(SYS_setresgid, rgid, egid, sgid);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/setresuid.c
@@ -1,9 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include "syscall.h"
-#include "libc.h"
-
-int setresuid(uid_t ruid, uid_t euid, uid_t suid)
-{
- return __setxid(SYS_setresuid, ruid, euid, suid);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/setreuid.c
@@ -1,8 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-#include "libc.h"
-
-int setreuid(uid_t ruid, uid_t euid)
-{
- return __setxid(SYS_setreuid, ruid, euid, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/setsid.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-pid_t setsid(void)
-{
- return syscall(SYS_setsid);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/setuid.c
@@ -1,8 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-#include "libc.h"
-
-int setuid(uid_t uid)
-{
- return __setxid(SYS_setuid, uid, 0, 0);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/setxid.c
@@ -1,34 +0,0 @@
-#include <unistd.h>
-#include <signal.h>
-#include "syscall.h"
-#include "libc.h"
-
-struct ctx {
- int id, eid, sid;
- int nr, ret;
-};
-
-static void do_setxid(void *p)
-{
- struct ctx *c = p;
- if (c->ret<0) return;
- int ret = __syscall(c->nr, c->id, c->eid, c->sid);
- if (ret && !c->ret) {
- /* If one thread fails to set ids after another has already
- * succeeded, forcibly killing the process is the only safe
- * thing to do. State is inconsistent and dangerous. Use
- * SIGKILL because it is uncatchable. */
- __block_all_sigs(0);
- __syscall(SYS_kill, __syscall(SYS_getpid), SIGKILL);
- }
- c->ret = ret;
-}
-
-int __setxid(int nr, int id, int eid, int sid)
-{
- /* ret is initially nonzero so that failure of the first thread does not
- * trigger the safety kill above. */
- struct ctx c = { .nr = nr, .id = id, .eid = eid, .sid = sid, .ret = 1 };
- __synccall(do_setxid, &c);
- return __syscall_ret(c.ret);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/sleep.c
@@ -1,10 +0,0 @@
-#include <unistd.h>
-#include <time.h>
-
-unsigned sleep(unsigned seconds)
-{
- struct timespec tv = { .tv_sec = seconds, .tv_nsec = 0 };
- if (nanosleep(&tv, &tv))
- return tv.tv_sec;
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/symlink.c
@@ -1,12 +0,0 @@
-#include <unistd.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int symlink(const char *existing, const char *new)
-{
-#ifdef SYS_symlink
- return syscall(SYS_symlink, existing, new);
-#else
- return syscall(SYS_symlinkat, existing, AT_FDCWD, new);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/symlinkat.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-int symlinkat(const char *existing, int fd, const char *new)
-{
- return syscall(SYS_symlinkat, existing, fd, new);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/sync.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-void sync(void)
-{
- __syscall(SYS_sync);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/tcgetpgrp.c
@@ -1,11 +0,0 @@
-#include <unistd.h>
-#include <termios.h>
-#include <sys/ioctl.h>
-
-pid_t tcgetpgrp(int fd)
-{
- int pgrp;
- if (ioctl(fd, TIOCGPGRP, &pgrp) < 0)
- return -1;
- return pgrp;
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/tcsetpgrp.c
@@ -1,9 +0,0 @@
-#include <unistd.h>
-#include <termios.h>
-#include <sys/ioctl.h>
-
-int tcsetpgrp(int fd, pid_t pgrp)
-{
- int pgrp_int = pgrp;
- return ioctl(fd, TIOCSPGRP, &pgrp_int);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/truncate.c
@@ -1,9 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-int truncate(const char *path, off_t length)
-{
- return syscall(SYS_truncate, path, __SYSCALL_LL_O(length));
-}
-
-weak_alias(truncate, truncate64);
lib/libc/wasi/libc-top-half/musl/src/unistd/ttyname.c
@@ -1,14 +0,0 @@
-#include <unistd.h>
-#include <errno.h>
-#include <limits.h>
-
-char *ttyname(int fd)
-{
- static char buf[TTY_NAME_MAX];
- int result;
- if ((result = ttyname_r(fd, buf, sizeof buf))) {
- errno = result;
- return NULL;
- }
- return buf;
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/ttyname_r.c
@@ -1,28 +0,0 @@
-#include <unistd.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include "syscall.h"
-
-int ttyname_r(int fd, char *name, size_t size)
-{
- struct stat st1, st2;
- char procname[sizeof "/proc/self/fd/" + 3*sizeof(int) + 2];
- ssize_t l;
-
- if (!isatty(fd)) return errno;
-
- __procfdname(procname, fd);
- l = readlink(procname, name, size);
-
- if (l < 0) return errno;
- else if (l == size) return ERANGE;
-
- name[l] = 0;
-
- if (stat(name, &st1) || fstat(fd, &st2))
- return errno;
- if (st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino)
- return ENODEV;
-
- return 0;
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/ualarm.c
@@ -1,13 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include <sys/time.h>
-
-unsigned ualarm(unsigned value, unsigned interval)
-{
- struct itimerval it = {
- .it_interval.tv_usec = interval,
- .it_value.tv_usec = value
- }, it_old;
- setitimer(ITIMER_REAL, &it, &it_old);
- return it_old.it_value.tv_sec*1000000 + it_old.it_value.tv_usec;
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/unlink.c
@@ -1,12 +0,0 @@
-#include <unistd.h>
-#include <fcntl.h>
-#include "syscall.h"
-
-int unlink(const char *path)
-{
-#ifdef SYS_unlink
- return syscall(SYS_unlink, path);
-#else
- return syscall(SYS_unlinkat, AT_FDCWD, path, 0);
-#endif
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/unlinkat.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-int unlinkat(int fd, const char *path, int flag)
-{
- return syscall(SYS_unlinkat, fd, path, flag);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/usleep.c
@@ -1,12 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include <time.h>
-
-int usleep(unsigned useconds)
-{
- struct timespec tv = {
- .tv_sec = useconds/1000000,
- .tv_nsec = (useconds%1000000)*1000
- };
- return nanosleep(&tv, &tv);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/write.c
@@ -1,7 +0,0 @@
-#include <unistd.h>
-#include "syscall.h"
-
-ssize_t write(int fd, const void *buf, size_t count)
-{
- return syscall_cp(SYS_write, fd, buf, count);
-}
lib/libc/wasi/libc-top-half/musl/src/unistd/writev.c
@@ -1,7 +0,0 @@
-#include <sys/uio.h>
-#include "syscall.h"
-
-ssize_t writev(int fd, const struct iovec *iov, int count)
-{
- return syscall_cp(SYS_writev, fd, iov, count);
-}
src/wasi_libc.zig
@@ -459,6 +459,7 @@ const libc_bottom_half_src_files = [_][]const u8{
"wasi/libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c",
"wasi/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c",
"wasi/libc-bottom-half/cloudlibc/src/libc/unistd/write.c",
+ "wasi/libc-bottom-half/sources/__errno_location.c",
"wasi/libc-bottom-half/sources/__main_void.c",
"wasi/libc-bottom-half/sources/__wasilibc_dt.c",
"wasi/libc-bottom-half/sources/__wasilibc_environ.c",