authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2023-05-23 22:12:53+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-05-23 22:12:53+02:00
logdcc1b4fd1532ccfe028fe9f68c0d19fc28800191
tree29b6620e0d7c118bd7257129fced21c0371cd9c7
parent0000b34a2dcfc1f96d827d38d22894e4b341c402
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Update wasi-libc to 3189cd1ceec8771e8f27faab58ad05d4d6c369ef (#15817)

Also remove all the wasi-libc files we used to ship, but never compile. The latest wasi-libc HEAD has an extra commit (a6f871343313220b76009827ed0153586361c0d5), which makes preopen initialization lazy. Unfortunately, that breaks quite a lot of things on our end. Applications now need to explicitly call __wasilibc_populate_preopens() everywhere when the libc is linked. That can wait after 0.11.

1107 files changed, 27 insertions(+), 27261 deletions(-)

lib/libc/wasi/libc-bottom-half/crt/crt1-reactor.c+20
......@@ -1,7 +1,27 @@
1#if defined(_REENTRANT)
2#include <stdatomic.h>
3extern void __wasi_init_tp(void);
4#endif
15extern void __wasm_call_ctors(void);
26
37__attribute__((export_name("_initialize")))
48void _initialize(void) {
9#if defined(_REENTRANT)
10 static volatile atomic_int initialized = 0;
11 int expected = 0;
12 if (!atomic_compare_exchange_strong(&initialized, &expected, 1)) {
13 __builtin_trap();
14 }
15
16 __wasi_init_tp();
17#else
18 static volatile int initialized = 0;
19 if (initialized != 0) {
20 __builtin_trap();
21 }
22 initialized = 1;
23#endif
24
525 // The linker synthesizes this to call constructors.
626 __wasm_call_ctors();
727}
lib/libc/wasi/libc-bottom-half/sources/__errno_location.c created+5
......@@ -0,0 +1,5 @@
1#include <errno.h>
2
3int *__errno_location(void) {
4 return &errno;
5}
lib/libc/wasi/libc-bottom-half/sources/__wasilibc_real.c+1-1
......@@ -662,7 +662,7 @@ __wasi_errno_t __wasi_sock_shutdown(
662662#ifdef _REENTRANT
663663int32_t __imported_wasi_thread_spawn(int32_t arg0) __attribute__((
664664 __import_module__("wasi"),
665 __import_name__("thread_spawn")
665 __import_name__("thread-spawn")
666666));
667667
668668int32_t __wasi_thread_spawn(void* start_arg) {
lib/libc/wasi/libc-top-half/musl/arch/wasm32/atomic_arch.h-1
......@@ -1,4 +1,3 @@
1#define a_barrier() (__sync_synchronize())
21#define a_cas(p, t, s) (__sync_val_compare_and_swap((p), (t), (s)))
32#define a_crash() (__builtin_trap())
43#define a_clz_32 __builtin_clz
lib/libc/wasi/libc-top-half/musl/include/pthread.h-6
......@@ -55,15 +55,9 @@ extern "C" {
5555#define PTHREAD_PROCESS_SHARED 1
5656
5757
58#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
5958#define PTHREAD_MUTEX_INITIALIZER {{{0}}}
6059#define PTHREAD_RWLOCK_INITIALIZER {{{0}}}
6160#define PTHREAD_COND_INITIALIZER {{{0}}}
62#else
63#define PTHREAD_MUTEX_INITIALIZER 0
64#define PTHREAD_RWLOCK_INITIALIZER 0
65#define PTHREAD_COND_INITIALIZER 0
66#endif
6761#define PTHREAD_ONCE_INIT 0
6862
6963
lib/libc/wasi/libc-top-half/musl/src/aio/aio.c deleted-418
......@@ -1,418 +0,0 @@
1#include <aio.h>
2#include <pthread.h>
3#include <semaphore.h>
4#include <limits.h>
5#include <errno.h>
6#include <unistd.h>
7#include <stdlib.h>
8#include <sys/auxv.h>
9#include "syscall.h"
10#include "atomic.h"
11#include "pthread_impl.h"
12#include "aio_impl.h"
13
14#define malloc __libc_malloc
15#define calloc __libc_calloc
16#define realloc __libc_realloc
17#define free __libc_free
18
19/* The following is a threads-based implementation of AIO with minimal
20 * dependence on implementation details. Most synchronization is
21 * performed with pthread primitives, but atomics and futex operations
22 * are used for notification in a couple places where the pthread
23 * primitives would be inefficient or impractical.
24 *
25 * For each fd with outstanding aio operations, an aio_queue structure
26 * is maintained. These are reference-counted and destroyed by the last
27 * aio worker thread to exit. Accessing any member of the aio_queue
28 * structure requires a lock on the aio_queue. Adding and removing aio
29 * queues themselves requires a write lock on the global map object,
30 * a 4-level table mapping file descriptor numbers to aio queues. A
31 * read lock on the map is used to obtain locks on existing queues by
32 * excluding destruction of the queue by a different thread while it is
33 * being locked.
34 *
35 * Each aio queue has a list of active threads/operations. Presently there
36 * is a one to one relationship between threads and operations. The only
37 * members of the aio_thread structure which are accessed by other threads
38 * are the linked list pointers, op (which is immutable), running (which
39 * is updated atomically), and err (which is synchronized via running),
40 * so no locking is necessary. Most of the other other members are used
41 * for sharing data between the main flow of execution and cancellation
42 * cleanup handler.
43 *
44 * Taking any aio locks requires having all signals blocked. This is
45 * necessary because aio_cancel is needed by close, and close is required
46 * to be async-signal safe. All aio worker threads run with all signals
47 * blocked permanently.
48 */
49
50struct aio_thread {
51 pthread_t td;
52 struct aiocb *cb;
53 struct aio_thread *next, *prev;
54 struct aio_queue *q;
55 volatile int running;
56 int err, op;
57 ssize_t ret;
58};
59
60struct aio_queue {
61 int fd, seekable, append, ref, init;
62 pthread_mutex_t lock;
63 pthread_cond_t cond;
64 struct aio_thread *head;
65};
66
67struct aio_args {
68 struct aiocb *cb;
69 struct aio_queue *q;
70 int op;
71 sem_t sem;
72};
73
74static pthread_rwlock_t maplock = PTHREAD_RWLOCK_INITIALIZER;
75static struct aio_queue *****map;
76static volatile int aio_fd_cnt;
77volatile int __aio_fut;
78
79static size_t io_thread_stack_size;
80
81#define MAX(a,b) ((a)>(b) ? (a) : (b))
82
83static struct aio_queue *__aio_get_queue(int fd, int need)
84{
85 if (fd < 0) {
86 errno = EBADF;
87 return 0;
88 }
89 int a=fd>>24;
90 unsigned char b=fd>>16, c=fd>>8, d=fd;
91 struct aio_queue *q = 0;
92 pthread_rwlock_rdlock(&maplock);
93 if ((!map || !map[a] || !map[a][b] || !map[a][b][c] || !(q=map[a][b][c][d])) && need) {
94 pthread_rwlock_unlock(&maplock);
95 if (fcntl(fd, F_GETFD) < 0) return 0;
96 pthread_rwlock_wrlock(&maplock);
97 if (!io_thread_stack_size) {
98 unsigned long val = __getauxval(AT_MINSIGSTKSZ);
99 io_thread_stack_size = MAX(MINSIGSTKSZ+2048, val+512);
100 }
101 if (!map) map = calloc(sizeof *map, (-1U/2+1)>>24);
102 if (!map) goto out;
103 if (!map[a]) map[a] = calloc(sizeof **map, 256);
104 if (!map[a]) goto out;
105 if (!map[a][b]) map[a][b] = calloc(sizeof ***map, 256);
106 if (!map[a][b]) goto out;
107 if (!map[a][b][c]) map[a][b][c] = calloc(sizeof ****map, 256);
108 if (!map[a][b][c]) goto out;
109 if (!(q = map[a][b][c][d])) {
110 map[a][b][c][d] = q = calloc(sizeof *****map, 1);
111 if (q) {
112 q->fd = fd;
113 pthread_mutex_init(&q->lock, 0);
114 pthread_cond_init(&q->cond, 0);
115 a_inc(&aio_fd_cnt);
116 }
117 }
118 }
119 if (q) pthread_mutex_lock(&q->lock);
120out:
121 pthread_rwlock_unlock(&maplock);
122 return q;
123}
124
125static void __aio_unref_queue(struct aio_queue *q)
126{
127 if (q->ref > 1) {
128 q->ref--;
129 pthread_mutex_unlock(&q->lock);
130 return;
131 }
132
133 /* This is potentially the last reference, but a new reference
134 * may arrive since we cannot free the queue object without first
135 * taking the maplock, which requires releasing the queue lock. */
136 pthread_mutex_unlock(&q->lock);
137 pthread_rwlock_wrlock(&maplock);
138 pthread_mutex_lock(&q->lock);
139 if (q->ref == 1) {
140 int fd=q->fd;
141 int a=fd>>24;
142 unsigned char b=fd>>16, c=fd>>8, d=fd;
143 map[a][b][c][d] = 0;
144 a_dec(&aio_fd_cnt);
145 pthread_rwlock_unlock(&maplock);
146 pthread_mutex_unlock(&q->lock);
147 free(q);
148 } else {
149 q->ref--;
150 pthread_rwlock_unlock(&maplock);
151 pthread_mutex_unlock(&q->lock);
152 }
153}
154
155static void cleanup(void *ctx)
156{
157 struct aio_thread *at = ctx;
158 struct aio_queue *q = at->q;
159 struct aiocb *cb = at->cb;
160 struct sigevent sev = cb->aio_sigevent;
161
162 /* There are four potential types of waiters we could need to wake:
163 * 1. Callers of aio_cancel/close.
164 * 2. Callers of aio_suspend with a single aiocb.
165 * 3. Callers of aio_suspend with a list.
166 * 4. AIO worker threads waiting for sequenced operations.
167 * Types 1-3 are notified via atomics/futexes, mainly for AS-safety
168 * considerations. Type 4 is notified later via a cond var. */
169
170 cb->__ret = at->ret;
171 if (a_swap(&at->running, 0) < 0)
172 __wake(&at->running, -1, 1);
173 if (a_swap(&cb->__err, at->err) != EINPROGRESS)
174 __wake(&cb->__err, -1, 1);
175 if (a_swap(&__aio_fut, 0))
176 __wake(&__aio_fut, -1, 1);
177
178 pthread_mutex_lock(&q->lock);
179
180 if (at->next) at->next->prev = at->prev;
181 if (at->prev) at->prev->next = at->next;
182 else q->head = at->next;
183
184 /* Signal aio worker threads waiting for sequenced operations. */
185 pthread_cond_broadcast(&q->cond);
186
187 __aio_unref_queue(q);
188
189 if (sev.sigev_notify == SIGEV_SIGNAL) {
190 siginfo_t si = {
191 .si_signo = sev.sigev_signo,
192 .si_value = sev.sigev_value,
193 .si_code = SI_ASYNCIO,
194 .si_pid = getpid(),
195 .si_uid = getuid()
196 };
197 __syscall(SYS_rt_sigqueueinfo, si.si_pid, si.si_signo, &si);
198 }
199 if (sev.sigev_notify == SIGEV_THREAD) {
200 a_store(&__pthread_self()->cancel, 0);
201 sev.sigev_notify_function(sev.sigev_value);
202 }
203}
204
205static void *io_thread_func(void *ctx)
206{
207 struct aio_thread at, *p;
208
209 struct aio_args *args = ctx;
210 struct aiocb *cb = args->cb;
211 int fd = cb->aio_fildes;
212 int op = args->op;
213 void *buf = (void *)cb->aio_buf;
214 size_t len = cb->aio_nbytes;
215 off_t off = cb->aio_offset;
216
217 struct aio_queue *q = args->q;
218 ssize_t ret;
219
220 pthread_mutex_lock(&q->lock);
221 sem_post(&args->sem);
222
223 at.op = op;
224 at.running = 1;
225 at.ret = -1;
226 at.err = ECANCELED;
227 at.q = q;
228 at.td = __pthread_self();
229 at.cb = cb;
230 at.prev = 0;
231 if ((at.next = q->head)) at.next->prev = &at;
232 q->head = &at;
233
234 if (!q->init) {
235 int seekable = lseek(fd, 0, SEEK_CUR) >= 0;
236 q->seekable = seekable;
237 q->append = !seekable || (fcntl(fd, F_GETFL) & O_APPEND);
238 q->init = 1;
239 }
240
241 pthread_cleanup_push(cleanup, &at);
242
243 /* Wait for sequenced operations. */
244 if (op!=LIO_READ && (op!=LIO_WRITE || q->append)) {
245 for (;;) {
246 for (p=at.next; p && p->op!=LIO_WRITE; p=p->next);
247 if (!p) break;
248 pthread_cond_wait(&q->cond, &q->lock);
249 }
250 }
251
252 pthread_mutex_unlock(&q->lock);
253
254 switch (op) {
255 case LIO_WRITE:
256 ret = q->append ? write(fd, buf, len) : pwrite(fd, buf, len, off);
257 break;
258 case LIO_READ:
259 ret = !q->seekable ? read(fd, buf, len) : pread(fd, buf, len, off);
260 break;
261 case O_SYNC:
262 ret = fsync(fd);
263 break;
264 case O_DSYNC:
265 ret = fdatasync(fd);
266 break;
267 }
268 at.ret = ret;
269 at.err = ret<0 ? errno : 0;
270
271 pthread_cleanup_pop(1);
272
273 return 0;
274}
275
276static int submit(struct aiocb *cb, int op)
277{
278 int ret = 0;
279 pthread_attr_t a;
280 sigset_t allmask, origmask;
281 pthread_t td;
282 struct aio_queue *q = __aio_get_queue(cb->aio_fildes, 1);
283 struct aio_args args = { .cb = cb, .op = op, .q = q };
284 sem_init(&args.sem, 0, 0);
285
286 if (!q) {
287 if (errno != EBADF) errno = EAGAIN;
288 cb->__ret = -1;
289 cb->__err = errno;
290 return -1;
291 }
292 q->ref++;
293 pthread_mutex_unlock(&q->lock);
294
295 if (cb->aio_sigevent.sigev_notify == SIGEV_THREAD) {
296 if (cb->aio_sigevent.sigev_notify_attributes)
297 a = *cb->aio_sigevent.sigev_notify_attributes;
298 else
299 pthread_attr_init(&a);
300 } else {
301 pthread_attr_init(&a);
302 pthread_attr_setstacksize(&a, io_thread_stack_size);
303 pthread_attr_setguardsize(&a, 0);
304 }
305 pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
306 sigfillset(&allmask);
307 pthread_sigmask(SIG_BLOCK, &allmask, &origmask);
308 cb->__err = EINPROGRESS;
309 if (pthread_create(&td, &a, io_thread_func, &args)) {
310 pthread_mutex_lock(&q->lock);
311 __aio_unref_queue(q);
312 cb->__err = errno = EAGAIN;
313 cb->__ret = ret = -1;
314 }
315 pthread_sigmask(SIG_SETMASK, &origmask, 0);
316
317 if (!ret) {
318 while (sem_wait(&args.sem));
319 }
320
321 return ret;
322}
323
324int aio_read(struct aiocb *cb)
325{
326 return submit(cb, LIO_READ);
327}
328
329int aio_write(struct aiocb *cb)
330{
331 return submit(cb, LIO_WRITE);
332}
333
334int aio_fsync(int op, struct aiocb *cb)
335{
336 if (op != O_SYNC && op != O_DSYNC) {
337 errno = EINVAL;
338 return -1;
339 }
340 return submit(cb, op);
341}
342
343ssize_t aio_return(struct aiocb *cb)
344{
345 return cb->__ret;
346}
347
348int aio_error(const struct aiocb *cb)
349{
350 a_barrier();
351 return cb->__err & 0x7fffffff;
352}
353
354int aio_cancel(int fd, struct aiocb *cb)
355{
356 sigset_t allmask, origmask;
357 int ret = AIO_ALLDONE;
358 struct aio_thread *p;
359 struct aio_queue *q;
360
361 /* Unspecified behavior case. Report an error. */
362 if (cb && fd != cb->aio_fildes) {
363 errno = EINVAL;
364 return -1;
365 }
366
367 sigfillset(&allmask);
368 pthread_sigmask(SIG_BLOCK, &allmask, &origmask);
369
370 errno = ENOENT;
371 if (!(q = __aio_get_queue(fd, 0))) {
372 if (errno == EBADF) ret = -1;
373 goto done;
374 }
375
376 for (p = q->head; p; p = p->next) {
377 if (cb && cb != p->cb) continue;
378 /* Transition target from running to running-with-waiters */
379 if (a_cas(&p->running, 1, -1)) {
380 pthread_cancel(p->td);
381 __wait(&p->running, 0, -1, 1);
382 if (p->err == ECANCELED) ret = AIO_CANCELED;
383 }
384 }
385
386 pthread_mutex_unlock(&q->lock);
387done:
388 pthread_sigmask(SIG_SETMASK, &origmask, 0);
389 return ret;
390}
391
392int __aio_close(int fd)
393{
394 a_barrier();
395 if (aio_fd_cnt) aio_cancel(fd, 0);
396 return fd;
397}
398
399void __aio_atfork(int who)
400{
401 if (who<0) {
402 pthread_rwlock_rdlock(&maplock);
403 return;
404 }
405 if (who>0 && map) for (int a=0; a<(-1U/2+1)>>24; a++)
406 if (map[a]) for (int b=0; b<256; b++)
407 if (map[a][b]) for (int c=0; c<256; c++)
408 if (map[a][b][c]) for (int d=0; d<256; d++)
409 map[a][b][c][d] = 0;
410 pthread_rwlock_unlock(&maplock);
411}
412
413weak_alias(aio_cancel, aio_cancel64);
414weak_alias(aio_error, aio_error64);
415weak_alias(aio_fsync, aio_fsync64);
416weak_alias(aio_read, aio_read64);
417weak_alias(aio_write, aio_write64);
418weak_alias(aio_return, aio_return64);
lib/libc/wasi/libc-top-half/musl/src/aio/aio_suspend.c deleted-79
......@@ -1,79 +0,0 @@
1#include <aio.h>
2#include <errno.h>
3#include <time.h>
4#include "atomic.h"
5#include "pthread_impl.h"
6#include "aio_impl.h"
7
8int aio_suspend(const struct aiocb *const cbs[], int cnt, const struct timespec *ts)
9{
10 int i, tid = 0, ret, expect = 0;
11 struct timespec at;
12 volatile int dummy_fut, *pfut;
13 int nzcnt = 0;
14 const struct aiocb *cb = 0;
15
16 pthread_testcancel();
17
18 if (cnt<0) {
19 errno = EINVAL;
20 return -1;
21 }
22
23 for (i=0; i<cnt; i++) if (cbs[i]) {
24 if (aio_error(cbs[i]) != EINPROGRESS) return 0;
25 nzcnt++;
26 cb = cbs[i];
27 }
28
29 if (ts) {
30 clock_gettime(CLOCK_MONOTONIC, &at);
31 at.tv_sec += ts->tv_sec;
32 if ((at.tv_nsec += ts->tv_nsec) >= 1000000000) {
33 at.tv_nsec -= 1000000000;
34 at.tv_sec++;
35 }
36 }
37
38 for (;;) {
39 for (i=0; i<cnt; i++)
40 if (cbs[i] && aio_error(cbs[i]) != EINPROGRESS)
41 return 0;
42
43 switch (nzcnt) {
44 case 0:
45 pfut = &dummy_fut;
46 break;
47 case 1:
48 pfut = (void *)&cb->__err;
49 expect = EINPROGRESS | 0x80000000;
50 a_cas(pfut, EINPROGRESS, expect);
51 break;
52 default:
53 pfut = &__aio_fut;
54 if (!tid) tid = __pthread_self()->tid;
55 expect = a_cas(pfut, 0, tid);
56 if (!expect) expect = tid;
57 /* Need to recheck the predicate before waiting. */
58 for (i=0; i<cnt; i++)
59 if (cbs[i] && aio_error(cbs[i]) != EINPROGRESS)
60 return 0;
61 break;
62 }
63
64 ret = __timedwait_cp(pfut, expect, CLOCK_MONOTONIC, ts?&at:0, 1);
65
66 switch (ret) {
67 case ETIMEDOUT:
68 ret = EAGAIN;
69 case ECANCELED:
70 case EINTR:
71 errno = ret;
72 return -1;
73 }
74 }
75}
76
77#if !_REDIR_TIME64
78weak_alias(aio_suspend, aio_suspend64);
79#endif
lib/libc/wasi/libc-top-half/musl/src/aio/lio_listio.c deleted-143
......@@ -1,143 +0,0 @@
1#include <aio.h>
2#include <errno.h>
3#include <unistd.h>
4#include <string.h>
5#include "pthread_impl.h"
6
7struct lio_state {
8 struct sigevent *sev;
9 int cnt;
10 struct aiocb *cbs[];
11};
12
13static int lio_wait(struct lio_state *st)
14{
15 int i, err, got_err = 0;
16 int cnt = st->cnt;
17 struct aiocb **cbs = st->cbs;
18
19 for (;;) {
20 for (i=0; i<cnt; i++) {
21 if (!cbs[i]) continue;
22 err = aio_error(cbs[i]);
23 if (err==EINPROGRESS)
24 break;
25 if (err) got_err=1;
26 cbs[i] = 0;
27 }
28 if (i==cnt) {
29 if (got_err) {
30 errno = EIO;
31 return -1;
32 }
33 return 0;
34 }
35 if (aio_suspend((void *)cbs, cnt, 0))
36 return -1;
37 }
38}
39
40static void notify_signal(struct sigevent *sev)
41{
42 siginfo_t si = {
43 .si_signo = sev->sigev_signo,
44 .si_value = sev->sigev_value,
45 .si_code = SI_ASYNCIO,
46 .si_pid = getpid(),
47 .si_uid = getuid()
48 };
49 __syscall(SYS_rt_sigqueueinfo, si.si_pid, si.si_signo, &si);
50}
51
52static void *wait_thread(void *p)
53{
54 struct lio_state *st = p;
55 struct sigevent *sev = st->sev;
56 lio_wait(st);
57 free(st);
58 switch (sev->sigev_notify) {
59 case SIGEV_SIGNAL:
60 notify_signal(sev);
61 break;
62 case SIGEV_THREAD:
63 sev->sigev_notify_function(sev->sigev_value);
64 break;
65 }
66 return 0;
67}
68
69int lio_listio(int mode, struct aiocb *restrict const *restrict cbs, int cnt, struct sigevent *restrict sev)
70{
71 int i, ret;
72 struct lio_state *st=0;
73
74 if (cnt < 0) {
75 errno = EINVAL;
76 return -1;
77 }
78
79 if (mode == LIO_WAIT || (sev && sev->sigev_notify != SIGEV_NONE)) {
80 if (!(st = malloc(sizeof *st + cnt*sizeof *cbs))) {
81 errno = EAGAIN;
82 return -1;
83 }
84 st->cnt = cnt;
85 st->sev = sev;
86 memcpy(st->cbs, (void*) cbs, cnt*sizeof *cbs);
87 }
88
89 for (i=0; i<cnt; i++) {
90 if (!cbs[i]) continue;
91 switch (cbs[i]->aio_lio_opcode) {
92 case LIO_READ:
93 ret = aio_read(cbs[i]);
94 break;
95 case LIO_WRITE:
96 ret = aio_write(cbs[i]);
97 break;
98 default:
99 continue;
100 }
101 if (ret) {
102 free(st);
103 errno = EAGAIN;
104 return -1;
105 }
106 }
107
108 if (mode == LIO_WAIT) {
109 ret = lio_wait(st);
110 free(st);
111 return ret;
112 }
113
114 if (st) {
115 pthread_attr_t a;
116 sigset_t set, set_old;
117 pthread_t td;
118
119 if (sev->sigev_notify == SIGEV_THREAD) {
120 if (sev->sigev_notify_attributes)
121 a = *sev->sigev_notify_attributes;
122 else
123 pthread_attr_init(&a);
124 } else {
125 pthread_attr_init(&a);
126 pthread_attr_setstacksize(&a, PAGE_SIZE);
127 pthread_attr_setguardsize(&a, 0);
128 }
129 pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
130 sigfillset(&set);
131 pthread_sigmask(SIG_BLOCK, &set, &set_old);
132 if (pthread_create(&td, &a, wait_thread, st)) {
133 free(st);
134 errno = EAGAIN;
135 return -1;
136 }
137 pthread_sigmask(SIG_SETMASK, &set_old, 0);
138 }
139
140 return 0;
141}
142
143weak_alias(lio_listio, lio_listio64);
lib/libc/wasi/libc-top-half/musl/src/complex/cimag.c deleted-6
......@@ -1,6 +0,0 @@
1#include "complex_impl.h"
2
3double (cimag)(double complex z)
4{
5 return cimag(z);
6}
lib/libc/wasi/libc-top-half/musl/src/complex/cimagf.c deleted-6
......@@ -1,6 +0,0 @@
1#include "complex_impl.h"
2
3float (cimagf)(float complex z)
4{
5 return cimagf(z);
6}
lib/libc/wasi/libc-top-half/musl/src/complex/cimagl.c deleted-6
......@@ -1,6 +0,0 @@
1#include "complex_impl.h"
2
3long double (cimagl)(long double complex z)
4{
5 return cimagl(z);
6}
lib/libc/wasi/libc-top-half/musl/src/complex/creal.c deleted-6
......@@ -1,6 +0,0 @@
1#include <complex.h>
2
3double (creal)(double complex z)
4{
5 return creal(z);
6}
lib/libc/wasi/libc-top-half/musl/src/complex/crealf.c deleted-6
......@@ -1,6 +0,0 @@
1#include <complex.h>
2
3float (crealf)(float complex z)
4{
5 return crealf(z);
6}
lib/libc/wasi/libc-top-half/musl/src/complex/creall.c deleted-6
......@@ -1,6 +0,0 @@
1#include <complex.h>
2
3long double (creall)(long double complex z)
4{
5 return creall(z);
6}
lib/libc/wasi/libc-top-half/musl/src/dirent/closedir.c deleted-11
......@@ -1,11 +0,0 @@
1#include <dirent.h>
2#include <unistd.h>
3#include <stdlib.h>
4#include "__dirent.h"
5
6int closedir(DIR *dir)
7{
8 int ret = close(dir->fd);
9 free(dir);
10 return ret;
11}
lib/libc/wasi/libc-top-half/musl/src/dirent/dirfd.c deleted-7
......@@ -1,7 +0,0 @@
1#include <dirent.h>
2#include "__dirent.h"
3
4int dirfd(DIR *d)
5{
6 return d->fd;
7}
lib/libc/wasi/libc-top-half/musl/src/dirent/fdopendir.c deleted-31
......@@ -1,31 +0,0 @@
1#include <dirent.h>
2#include <fcntl.h>
3#include <sys/stat.h>
4#include <errno.h>
5#include <stdlib.h>
6#include "__dirent.h"
7
8DIR *fdopendir(int fd)
9{
10 DIR *dir;
11 struct stat st;
12
13 if (fstat(fd, &st) < 0) {
14 return 0;
15 }
16 if (fcntl(fd, F_GETFL) & O_PATH) {
17 errno = EBADF;
18 return 0;
19 }
20 if (!S_ISDIR(st.st_mode)) {
21 errno = ENOTDIR;
22 return 0;
23 }
24 if (!(dir = calloc(1, sizeof *dir))) {
25 return 0;
26 }
27
28 fcntl(fd, F_SETFD, FD_CLOEXEC);
29 dir->fd = fd;
30 return dir;
31}
lib/libc/wasi/libc-top-half/musl/src/dirent/opendir.c deleted-21
......@@ -1,21 +0,0 @@
1#define _GNU_SOURCE
2#include <dirent.h>
3#include <fcntl.h>
4#include <stdlib.h>
5#include "__dirent.h"
6#include "syscall.h"
7
8DIR *opendir(const char *name)
9{
10 int fd;
11 DIR *dir;
12
13 if ((fd = open(name, O_RDONLY|O_DIRECTORY|O_CLOEXEC)) < 0)
14 return 0;
15 if (!(dir = calloc(1, sizeof *dir))) {
16 __syscall(SYS_close, fd);
17 return 0;
18 }
19 dir->fd = fd;
20 return dir;
21}
lib/libc/wasi/libc-top-half/musl/src/dirent/readdir.c deleted-29
......@@ -1,29 +0,0 @@
1#include <dirent.h>
2#include <errno.h>
3#include <stddef.h>
4#include "__dirent.h"
5#include "syscall.h"
6
7typedef char dirstream_buf_alignment_check[1-2*(int)(
8 offsetof(struct __dirstream, buf) % sizeof(off_t))];
9
10struct dirent *readdir(DIR *dir)
11{
12 struct dirent *de;
13
14 if (dir->buf_pos >= dir->buf_end) {
15 int len = __syscall(SYS_getdents, dir->fd, dir->buf, sizeof dir->buf);
16 if (len <= 0) {
17 if (len < 0 && len != -ENOENT) errno = -len;
18 return 0;
19 }
20 dir->buf_end = len;
21 dir->buf_pos = 0;
22 }
23 de = (void *)(dir->buf + dir->buf_pos);
24 dir->buf_pos += de->d_reclen;
25 dir->tell = de->d_off;
26 return de;
27}
28
29weak_alias(readdir, readdir64);
lib/libc/wasi/libc-top-half/musl/src/dirent/readdir_r.c deleted-29
......@@ -1,29 +0,0 @@
1#include <dirent.h>
2#include <errno.h>
3#include <string.h>
4#include "__dirent.h"
5#include "lock.h"
6
7int readdir_r(DIR *restrict dir, struct dirent *restrict buf, struct dirent **restrict result)
8{
9 struct dirent *de;
10 int errno_save = errno;
11 int ret;
12
13 LOCK(dir->lock);
14 errno = 0;
15 de = readdir(dir);
16 if ((ret = errno)) {
17 UNLOCK(dir->lock);
18 return ret;
19 }
20 errno = errno_save;
21 if (de) memcpy(buf, de, de->d_reclen);
22 else buf = NULL;
23
24 UNLOCK(dir->lock);
25 *result = buf;
26 return 0;
27}
28
29weak_alias(readdir_r, readdir64_r);
lib/libc/wasi/libc-top-half/musl/src/dirent/rewinddir.c deleted-13
......@@ -1,13 +0,0 @@
1#include <dirent.h>
2#include <unistd.h>
3#include "__dirent.h"
4#include "lock.h"
5
6void rewinddir(DIR *dir)
7{
8 LOCK(dir->lock);
9 lseek(dir->fd, 0, SEEK_SET);
10 dir->buf_pos = dir->buf_end = 0;
11 dir->tell = 0;
12 UNLOCK(dir->lock);
13}
lib/libc/wasi/libc-top-half/musl/src/dirent/scandir.c deleted-47
......@@ -1,47 +0,0 @@
1#include <dirent.h>
2#include <string.h>
3#include <stdlib.h>
4#include <stdint.h>
5#include <errno.h>
6#include <stddef.h>
7
8int scandir(const char *path, struct dirent ***res,
9 int (*sel)(const struct dirent *),
10 int (*cmp)(const struct dirent **, const struct dirent **))
11{
12 DIR *d = opendir(path);
13 struct dirent *de, **names=0, **tmp;
14 size_t cnt=0, len=0;
15 int old_errno = errno;
16
17 if (!d) return -1;
18
19 while ((errno=0), (de = readdir(d))) {
20 if (sel && !sel(de)) continue;
21 if (cnt >= len) {
22 len = 2*len+1;
23 if (len > SIZE_MAX/sizeof *names) break;
24 tmp = realloc(names, len * sizeof *names);
25 if (!tmp) break;
26 names = tmp;
27 }
28 names[cnt] = malloc(de->d_reclen);
29 if (!names[cnt]) break;
30 memcpy(names[cnt++], de, de->d_reclen);
31 }
32
33 closedir(d);
34
35 if (errno) {
36 if (names) while (cnt-->0) free(names[cnt]);
37 free(names);
38 return -1;
39 }
40 errno = old_errno;
41
42 if (cmp) qsort(names, cnt, sizeof *names, (int (*)(const void *, const void *))cmp);
43 *res = names;
44 return cnt;
45}
46
47weak_alias(scandir, scandir64);
lib/libc/wasi/libc-top-half/musl/src/dirent/seekdir.c deleted-12
......@@ -1,12 +0,0 @@
1#include <dirent.h>
2#include <unistd.h>
3#include "__dirent.h"
4#include "lock.h"
5
6void seekdir(DIR *dir, long off)
7{
8 LOCK(dir->lock);
9 dir->tell = lseek(dir->fd, off, SEEK_SET);
10 dir->buf_pos = dir->buf_end = 0;
11 UNLOCK(dir->lock);
12}
lib/libc/wasi/libc-top-half/musl/src/dirent/telldir.c deleted-7
......@@ -1,7 +0,0 @@
1#include <dirent.h>
2#include "__dirent.h"
3
4long telldir(DIR *dir)
5{
6 return dir->tell;
7}
lib/libc/wasi/libc-top-half/musl/src/env/__environ.c deleted-6
......@@ -1,6 +0,0 @@
1#include <unistd.h>
2
3char **__environ = 0;
4weak_alias(__environ, ___environ);
5weak_alias(__environ, _environ);
6weak_alias(__environ, environ);
lib/libc/wasi/libc-top-half/musl/src/env/__init_tls.c deleted-237
......@@ -1,237 +0,0 @@
1#ifdef __wasilibc_unmodified_upstream
2#define SYSCALL_NO_TLS 1
3#include <elf.h>
4#endif
5#include <limits.h>
6#ifdef __wasilibc_unmodified_upstream
7#include <sys/mman.h>
8#endif
9#include <string.h>
10#include <stddef.h>
11#include "pthread_impl.h"
12#include "libc.h"
13#include "atomic.h"
14#include "syscall.h"
15
16volatile int __thread_list_lock;
17
18#ifndef __wasilibc_unmodified_upstream
19
20/* These symbols are generated by wasm-ld. __stack_high/__stack_low
21 * symbols are only available in LLVM v16 and higher, therefore they're
22 * defined as weak symbols and if not available, __heap_base/__data_end
23 * is used instead.
24 *
25 * TODO: remove usage of __heap_base/__data_end for stack size calculation
26 * once we drop support for LLVM v15 and older.
27 */
28extern unsigned char __heap_base;
29extern unsigned char __data_end;
30extern unsigned char __global_base;
31extern weak unsigned char __stack_high;
32extern weak unsigned char __stack_low;
33
34static inline void setup_default_stack_size()
35{
36 ptrdiff_t stack_size;
37
38 if (&__stack_high)
39 stack_size = &__stack_high - &__stack_low;
40 else {
41 unsigned char *sp;
42 __asm__(
43 ".globaltype __stack_pointer, i32\n"
44 "global.get __stack_pointer\n"
45 "local.set %0\n"
46 : "=r"(sp));
47 stack_size = sp > &__global_base ? &__heap_base - &__data_end : (ptrdiff_t)&__global_base;
48 }
49
50 if (stack_size > __default_stacksize)
51 __default_stacksize =
52 stack_size < DEFAULT_STACK_MAX ?
53 stack_size : DEFAULT_STACK_MAX;
54}
55
56void __wasi_init_tp() {
57 __init_tp((void *)__get_tp());
58}
59#endif
60
61int __init_tp(void *p)
62{
63 pthread_t td = p;
64 td->self = td;
65#ifdef __wasilibc_unmodified_upstream
66 int r = __set_thread_area(TP_ADJ(p));
67 if (r < 0) return -1;
68 if (!r) libc.can_do_threads = 1;
69 td->detach_state = DT_JOINABLE;
70 td->tid = __syscall(SYS_set_tid_address, &__thread_list_lock);
71#else
72 setup_default_stack_size();
73 td->detach_state = DT_JOINABLE;
74 /*
75 * Initialize the TID to a value which doesn't conflict with
76 * host-allocated TIDs, so that TID-based locks can work.
77 *
78 * Note:
79 * - Host-allocated TIDs range from 1 to 0x1fffffff. (inclusive)
80 * - __tl_lock and __lockfile uses TID 0 as "unlocked".
81 * - __lockfile relies on the fact the most significant two bits
82 * of TIDs are 0.
83 */
84 td->tid = 0x3fffffff;
85#endif
86 td->locale = &libc.global_locale;
87 td->robust_list.head = &td->robust_list.head;
88 td->sysinfo = __sysinfo;
89 td->next = td->prev = td;
90 return 0;
91}
92
93#ifdef __wasilibc_unmodified_upstream
94
95static struct builtin_tls {
96 char c;
97 struct pthread pt;
98 void *space[16];
99} builtin_tls[1];
100#define MIN_TLS_ALIGN offsetof(struct builtin_tls, pt)
101
102static struct tls_module main_tls;
103#endif
104
105#ifndef __wasilibc_unmodified_upstream
106extern void __wasm_init_tls(void*);
107#endif
108
109void *__copy_tls(unsigned char *mem)
110{
111#ifdef __wasilibc_unmodified_upstream
112 pthread_t td;
113 struct tls_module *p;
114 size_t i;
115 uintptr_t *dtv;
116
117#ifdef TLS_ABOVE_TP
118 dtv = (uintptr_t*)(mem + libc.tls_size) - (libc.tls_cnt + 1);
119
120 mem += -((uintptr_t)mem + sizeof(struct pthread)) & (libc.tls_align-1);
121 td = (pthread_t)mem;
122 mem += sizeof(struct pthread);
123
124 for (i=1, p=libc.tls_head; p; i++, p=p->next) {
125 dtv[i] = (uintptr_t)(mem + p->offset) + DTP_OFFSET;
126 memcpy(mem + p->offset, p->image, p->len);
127 }
128#else
129 dtv = (uintptr_t *)mem;
130
131 mem += libc.tls_size - sizeof(struct pthread);
132 mem -= (uintptr_t)mem & (libc.tls_align-1);
133 td = (pthread_t)mem;
134
135 for (i=1, p=libc.tls_head; p; i++, p=p->next) {
136 dtv[i] = (uintptr_t)(mem - p->offset) + DTP_OFFSET;
137 memcpy(mem - p->offset, p->image, p->len);
138 }
139#endif
140 dtv[0] = libc.tls_cnt;
141 td->dtv = dtv;
142 return td;
143#else
144 size_t tls_align = __builtin_wasm_tls_align();
145 volatile void* tls_base = __builtin_wasm_tls_base();
146 mem += tls_align;
147 mem -= (uintptr_t)mem & (tls_align-1);
148 __wasm_init_tls(mem);
149 __asm__("local.get %0\n"
150 "global.set __tls_base\n"
151 :: "r"(tls_base));
152 return mem;
153#endif
154}
155
156#ifdef __wasilibc_unmodified_upstream
157#if ULONG_MAX == 0xffffffff
158typedef Elf32_Phdr Phdr;
159#else
160typedef Elf64_Phdr Phdr;
161#endif
162
163extern weak hidden const size_t _DYNAMIC[];
164
165static void static_init_tls(size_t *aux)
166{
167 unsigned char *p;
168 size_t n;
169 Phdr *phdr, *tls_phdr=0;
170 size_t base = 0;
171 void *mem;
172
173 for (p=(void *)aux[AT_PHDR],n=aux[AT_PHNUM]; n; n--,p+=aux[AT_PHENT]) {
174 phdr = (void *)p;
175 if (phdr->p_type == PT_PHDR)
176 base = aux[AT_PHDR] - phdr->p_vaddr;
177 if (phdr->p_type == PT_DYNAMIC && _DYNAMIC)
178 base = (size_t)_DYNAMIC - phdr->p_vaddr;
179 if (phdr->p_type == PT_TLS)
180 tls_phdr = phdr;
181 if (phdr->p_type == PT_GNU_STACK &&
182 phdr->p_memsz > __default_stacksize)
183 __default_stacksize =
184 phdr->p_memsz < DEFAULT_STACK_MAX ?
185 phdr->p_memsz : DEFAULT_STACK_MAX;
186 }
187
188 if (tls_phdr) {
189 main_tls.image = (void *)(base + tls_phdr->p_vaddr);
190 main_tls.len = tls_phdr->p_filesz;
191 main_tls.size = tls_phdr->p_memsz;
192 main_tls.align = tls_phdr->p_align;
193 libc.tls_cnt = 1;
194 libc.tls_head = &main_tls;
195 }
196
197 main_tls.size += (-main_tls.size - (uintptr_t)main_tls.image)
198 & (main_tls.align-1);
199#ifdef TLS_ABOVE_TP
200 main_tls.offset = GAP_ABOVE_TP;
201 main_tls.offset += (-GAP_ABOVE_TP + (uintptr_t)main_tls.image)
202 & (main_tls.align-1);
203#else
204 main_tls.offset = main_tls.size;
205#endif
206 if (main_tls.align < MIN_TLS_ALIGN) main_tls.align = MIN_TLS_ALIGN;
207
208 libc.tls_align = main_tls.align;
209 libc.tls_size = 2*sizeof(void *) + sizeof(struct pthread)
210#ifdef TLS_ABOVE_TP
211 + main_tls.offset
212#endif
213 + main_tls.size + main_tls.align
214 + MIN_TLS_ALIGN-1 & -MIN_TLS_ALIGN;
215
216 if (libc.tls_size > sizeof builtin_tls) {
217#ifndef SYS_mmap2
218#define SYS_mmap2 SYS_mmap
219#endif
220 mem = (void *)__syscall(
221 SYS_mmap2,
222 0, libc.tls_size, PROT_READ|PROT_WRITE,
223 MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
224 /* -4095...-1 cast to void * will crash on dereference anyway,
225 * so don't bloat the init code checking for error codes and
226 * explicitly calling a_crash(). */
227 } else {
228 mem = builtin_tls;
229 }
230
231 /* Failure to initialize thread pointer is always fatal. */
232 if (__init_tp(__copy_tls(mem)) < 0)
233 a_crash();
234}
235
236weak_alias(static_init_tls, __init_tls);
237#endif
lib/libc/wasi/libc-top-half/musl/src/env/__libc_start_main.c deleted-97
......@@ -1,97 +0,0 @@
1#include <elf.h>
2#include <poll.h>
3#include <fcntl.h>
4#include <signal.h>
5#include <unistd.h>
6#include "syscall.h"
7#include "atomic.h"
8#include "libc.h"
9
10static void dummy(void) {}
11weak_alias(dummy, _init);
12
13extern weak hidden void (*const __init_array_start)(void), (*const __init_array_end)(void);
14
15static void dummy1(void *p) {}
16weak_alias(dummy1, __init_ssp);
17
18#define AUX_CNT 38
19
20#ifdef __GNUC__
21__attribute__((__noinline__))
22#endif
23void __init_libc(char **envp, char *pn)
24{
25 size_t i, *auxv, aux[AUX_CNT] = { 0 };
26 __environ = envp;
27 for (i=0; envp[i]; i++);
28 libc.auxv = auxv = (void *)(envp+i+1);
29 for (i=0; auxv[i]; i+=2) if (auxv[i]<AUX_CNT) aux[auxv[i]] = auxv[i+1];
30 __hwcap = aux[AT_HWCAP];
31 if (aux[AT_SYSINFO]) __sysinfo = aux[AT_SYSINFO];
32 libc.page_size = aux[AT_PAGESZ];
33
34 if (!pn) pn = (void*)aux[AT_EXECFN];
35 if (!pn) pn = "";
36 __progname = __progname_full = pn;
37 for (i=0; pn[i]; i++) if (pn[i]=='/') __progname = pn+i+1;
38
39 __init_tls(aux);
40 __init_ssp((void *)aux[AT_RANDOM]);
41
42 if (aux[AT_UID]==aux[AT_EUID] && aux[AT_GID]==aux[AT_EGID]
43 && !aux[AT_SECURE]) return;
44
45 struct pollfd pfd[3] = { {.fd=0}, {.fd=1}, {.fd=2} };
46 int r =
47#ifdef SYS_poll
48 __syscall(SYS_poll, pfd, 3, 0);
49#else
50 __syscall(SYS_ppoll, pfd, 3, &(struct timespec){0}, 0, _NSIG/8);
51#endif
52 if (r<0) a_crash();
53 for (i=0; i<3; i++) if (pfd[i].revents&POLLNVAL)
54 if (__sys_open("/dev/null", O_RDWR)<0)
55 a_crash();
56 libc.secure = 1;
57}
58
59static void libc_start_init(void)
60{
61 _init();
62 uintptr_t a = (uintptr_t)&__init_array_start;
63 for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)()))
64 (*(void (**)(void))a)();
65}
66
67weak_alias(libc_start_init, __libc_start_init);
68
69typedef int lsm2_fn(int (*)(int,char **,char **), int, char **);
70static lsm2_fn libc_start_main_stage2;
71
72int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv,
73 void (*init_dummy)(), void(*fini_dummy)(), void(*ldso_dummy)())
74{
75 char **envp = argv+argc+1;
76
77 /* External linkage, and explicit noinline attribute if available,
78 * are used to prevent the stack frame used during init from
79 * persisting for the entire process lifetime. */
80 __init_libc(envp, argv[0]);
81
82 /* Barrier against hoisting application code or anything using ssp
83 * or thread pointer prior to its initialization above. */
84 lsm2_fn *stage2 = libc_start_main_stage2;
85 __asm__ ( "" : "+r"(stage2) : : "memory" );
86 return stage2(main, argc, argv);
87}
88
89static int libc_start_main_stage2(int (*main)(int,char **,char **), int argc, char **argv)
90{
91 char **envp = argv+argc+1;
92 __libc_start_init();
93
94 /* Pass control to the application */
95 exit(main(argc, argv, envp));
96 return 0;
97}
lib/libc/wasi/libc-top-half/musl/src/env/__reset_tls.c deleted-15
......@@ -1,15 +0,0 @@
1#include <string.h>
2#include "pthread_impl.h"
3#include "libc.h"
4
5void __reset_tls()
6{
7 pthread_t self = __pthread_self();
8 struct tls_module *p;
9 size_t i, n = self->dtv[0];
10 if (n) for (p=libc.tls_head, i=1; i<=n; i++, p=p->next) {
11 char *mem = (char *)(self->dtv[i] - DTP_OFFSET);
12 memcpy(mem, p->image, p->len);
13 memset(mem+p->len, 0, p->size - p->len);
14 }
15}
lib/libc/wasi/libc-top-half/musl/src/env/secure_getenv.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <stdlib.h>
3#include "libc.h"
4
5char *secure_getenv(const char *name)
6{
7 return libc.secure ? NULL : getenv(name);
8}
lib/libc/wasi/libc-top-half/musl/src/errno/__errno_location.c deleted-9
......@@ -1,9 +0,0 @@
1#include <errno.h>
2#include "pthread_impl.h"
3
4int *__errno_location(void)
5{
6 return &__pthread_self()->errno_val;
7}
8
9weak_alias(__errno_location, ___errno_location);
lib/libc/wasi/libc-top-half/musl/src/exit/_Exit.c deleted-8
......@@ -1,8 +0,0 @@
1#include <stdlib.h>
2#include "syscall.h"
3
4_Noreturn void _Exit(int ec)
5{
6 __syscall(SYS_exit_group, ec);
7 for (;;) __syscall(SYS_exit, ec);
8}
lib/libc/wasi/libc-top-half/musl/src/exit/abort.c deleted-30
......@@ -1,30 +0,0 @@
1#include <stdlib.h>
2#include <signal.h>
3#include "syscall.h"
4#include "pthread_impl.h"
5#include "atomic.h"
6#include "lock.h"
7#include "ksigaction.h"
8
9_Noreturn void abort(void)
10{
11 raise(SIGABRT);
12
13 /* If there was a SIGABRT handler installed and it returned, or if
14 * SIGABRT was blocked or ignored, take an AS-safe lock to prevent
15 * sigaction from installing a new SIGABRT handler, uninstall any
16 * handler that may be present, and re-raise the signal to generate
17 * the default action of abnormal termination. */
18 __block_all_sigs(0);
19 LOCK(__abort_lock);
20 __syscall(SYS_rt_sigaction, SIGABRT,
21 &(struct k_sigaction){.handler = SIG_DFL}, 0, _NSIG/8);
22 __syscall(SYS_tkill, __pthread_self()->tid, SIGABRT);
23 __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK,
24 &(long[_NSIG/(8*sizeof(long))]){1UL<<(SIGABRT-1)}, 0, _NSIG/8);
25
26 /* Beyond this point should be unreachable. */
27 a_crash();
28 raise(SIGKILL);
29 _Exit(127);
30}
lib/libc/wasi/libc-top-half/musl/src/exit/abort_lock.c deleted-3
......@@ -1,3 +0,0 @@
1#include "pthread_impl.h"
2
3volatile int __abort_lock[1];
lib/libc/wasi/libc-top-half/musl/src/exit/arm/__aeabi_atexit.c deleted-6
......@@ -1,6 +0,0 @@
1int __cxa_atexit(void (*func)(void *), void *arg, void *dso);
2
3int __aeabi_atexit (void *obj, void (*func) (void *), void *d)
4{
5 return __cxa_atexit (func, obj, d);
6}
lib/libc/wasi/libc-top-half/musl/src/fcntl/fcntl.c deleted-48
......@@ -1,48 +0,0 @@
1#define _GNU_SOURCE
2#include <fcntl.h>
3#include <stdarg.h>
4#include <errno.h>
5#include "syscall.h"
6
7int fcntl(int fd, int cmd, ...)
8{
9 unsigned long arg;
10 va_list ap;
11 va_start(ap, cmd);
12 arg = va_arg(ap, unsigned long);
13 va_end(ap);
14 if (cmd == F_SETFL) arg |= O_LARGEFILE;
15 if (cmd == F_SETLKW) return syscall_cp(SYS_fcntl, fd, cmd, (void *)arg);
16 if (cmd == F_GETOWN) {
17 struct f_owner_ex ex;
18 int ret = __syscall(SYS_fcntl, fd, F_GETOWN_EX, &ex);
19 if (ret == -EINVAL) return __syscall(SYS_fcntl, fd, cmd, (void *)arg);
20 if (ret) return __syscall_ret(ret);
21 return ex.type == F_OWNER_PGRP ? -ex.pid : ex.pid;
22 }
23 if (cmd == F_DUPFD_CLOEXEC) {
24 int ret = __syscall(SYS_fcntl, fd, F_DUPFD_CLOEXEC, arg);
25 if (ret != -EINVAL) {
26 if (ret >= 0)
27 __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC);
28 return __syscall_ret(ret);
29 }
30 ret = __syscall(SYS_fcntl, fd, F_DUPFD_CLOEXEC, 0);
31 if (ret != -EINVAL) {
32 if (ret >= 0) __syscall(SYS_close, ret);
33 return __syscall_ret(-EINVAL);
34 }
35 ret = __syscall(SYS_fcntl, fd, F_DUPFD, arg);
36 if (ret >= 0) __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC);
37 return __syscall_ret(ret);
38 }
39 switch (cmd) {
40 case F_SETLK:
41 case F_GETLK:
42 case F_GETOWN_EX:
43 case F_SETOWN_EX:
44 return syscall(SYS_fcntl, fd, cmd, (void *)arg);
45 default:
46 return syscall(SYS_fcntl, fd, cmd, arg);
47 }
48}
lib/libc/wasi/libc-top-half/musl/src/fcntl/open.c deleted-23
......@@ -1,23 +0,0 @@
1#include <fcntl.h>
2#include <stdarg.h>
3#include "syscall.h"
4
5int open(const char *filename, int flags, ...)
6{
7 mode_t mode = 0;
8
9 if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) {
10 va_list ap;
11 va_start(ap, flags);
12 mode = va_arg(ap, mode_t);
13 va_end(ap);
14 }
15
16 int fd = __sys_open_cp(filename, flags, mode);
17 if (fd>=0 && (flags & O_CLOEXEC))
18 __syscall(SYS_fcntl, fd, F_SETFD, FD_CLOEXEC);
19
20 return __syscall_ret(fd);
21}
22
23weak_alias(open, open64);
lib/libc/wasi/libc-top-half/musl/src/fcntl/openat.c deleted-19
......@@ -1,19 +0,0 @@
1#include <fcntl.h>
2#include <stdarg.h>
3#include "syscall.h"
4
5int openat(int fd, const char *filename, int flags, ...)
6{
7 mode_t mode = 0;
8
9 if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) {
10 va_list ap;
11 va_start(ap, flags);
12 mode = va_arg(ap, mode_t);
13 va_end(ap);
14 }
15
16 return syscall_cp(SYS_openat, fd, filename, flags|O_LARGEFILE, mode);
17}
18
19weak_alias(openat, openat64);
lib/libc/wasi/libc-top-half/musl/src/fcntl/posix_fadvise.c deleted-18
......@@ -1,18 +0,0 @@
1#include <fcntl.h>
2#include "syscall.h"
3
4int posix_fadvise(int fd, off_t base, off_t len, int advice)
5{
6#if defined(SYSCALL_FADVISE_6_ARG)
7 /* Some archs, at least arm and powerpc, have the syscall
8 * arguments reordered to avoid needing 7 argument registers
9 * due to 64-bit argument alignment. */
10 return -__syscall(SYS_fadvise, fd, advice,
11 __SYSCALL_LL_E(base), __SYSCALL_LL_E(len));
12#else
13 return -__syscall(SYS_fadvise, fd, __SYSCALL_LL_O(base),
14 __SYSCALL_LL_E(len), advice);
15#endif
16}
17
18weak_alias(posix_fadvise, posix_fadvise64);
lib/libc/wasi/libc-top-half/musl/src/fcntl/posix_fallocate.c deleted-10
......@@ -1,10 +0,0 @@
1#include <fcntl.h>
2#include "syscall.h"
3
4int posix_fallocate(int fd, off_t base, off_t len)
5{
6 return -__syscall(SYS_fallocate, fd, 0, __SYSCALL_LL_E(base),
7 __SYSCALL_LL_E(len));
8}
9
10weak_alias(posix_fallocate, posix_fallocate64);
lib/libc/wasi/libc-top-half/musl/src/fenv/__flt_rounds.c deleted-19
......@@ -1,19 +0,0 @@
1#include <float.h>
2#include <fenv.h>
3
4int __flt_rounds()
5{
6 switch (fegetround()) {
7#ifdef FE_TOWARDZERO
8 case FE_TOWARDZERO: return 0;
9#endif
10 case FE_TONEAREST: return 1;
11#ifdef FE_UPWARD
12 case FE_UPWARD: return 2;
13#endif
14#ifdef FE_DOWNWARD
15 case FE_DOWNWARD: return 3;
16#endif
17 }
18 return -1;
19}
lib/libc/wasi/libc-top-half/musl/src/fenv/aarch64/fenv.s deleted-68
......@@ -1,68 +0,0 @@
1.global fegetround
2.type fegetround,%function
3fegetround:
4 mrs x0, fpcr
5 and w0, w0, #0xc00000
6 ret
7
8.global __fesetround
9.hidden __fesetround
10.type __fesetround,%function
11__fesetround:
12 mrs x1, fpcr
13 bic w1, w1, #0xc00000
14 orr w1, w1, w0
15 msr fpcr, x1
16 mov w0, #0
17 ret
18
19.global fetestexcept
20.type fetestexcept,%function
21fetestexcept:
22 and w0, w0, #0x1f
23 mrs x1, fpsr
24 and w0, w0, w1
25 ret
26
27.global feclearexcept
28.type feclearexcept,%function
29feclearexcept:
30 and w0, w0, #0x1f
31 mrs x1, fpsr
32 bic w1, w1, w0
33 msr fpsr, x1
34 mov w0, #0
35 ret
36
37.global feraiseexcept
38.type feraiseexcept,%function
39feraiseexcept:
40 and w0, w0, #0x1f
41 mrs x1, fpsr
42 orr w1, w1, w0
43 msr fpsr, x1
44 mov w0, #0
45 ret
46
47.global fegetenv
48.type fegetenv,%function
49fegetenv:
50 mrs x1, fpcr
51 mrs x2, fpsr
52 stp w1, w2, [x0]
53 mov w0, #0
54 ret
55
56// TODO preserve some bits
57.global fesetenv
58.type fesetenv,%function
59fesetenv:
60 mov x1, #0
61 mov x2, #0
62 cmn x0, #1
63 b.eq 1f
64 ldp w1, w2, [x0]
651: msr fpcr, x1
66 msr fpsr, x2
67 mov w0, #0
68 ret
lib/libc/wasi/libc-top-half/musl/src/fenv/arm/fenv.c deleted-3
......@@ -1,3 +0,0 @@
1#if !__ARM_PCS_VFP
2#include "../fenv.c"
3#endif
lib/libc/wasi/libc-top-half/musl/src/fenv/i386/fenv.s deleted-164
......@@ -1,164 +0,0 @@
1.hidden __hwcap
2
3.global feclearexcept
4.type feclearexcept,@function
5feclearexcept:
6 mov 4(%esp),%ecx
7 and $0x3f,%ecx
8 fnstsw %ax
9 # consider sse fenv as well if the cpu has XMM capability
10 call 1f
111: addl $__hwcap-1b,(%esp)
12 pop %edx
13 testl $0x02000000,(%edx)
14 jz 2f
15 # maintain exceptions in the sse mxcsr, clear x87 exceptions
16 test %eax,%ecx
17 jz 1f
18 fnclex
191: push %edx
20 stmxcsr (%esp)
21 pop %edx
22 and $0x3f,%eax
23 or %eax,%edx
24 test %edx,%ecx
25 jz 1f
26 not %ecx
27 and %ecx,%edx
28 push %edx
29 ldmxcsr (%esp)
30 pop %edx
311: xor %eax,%eax
32 ret
33 # only do the expensive x87 fenv load/store when needed
342: test %eax,%ecx
35 jz 1b
36 not %ecx
37 and %ecx,%eax
38 test $0x3f,%eax
39 jz 1f
40 fnclex
41 jmp 1b
421: sub $32,%esp
43 fnstenv (%esp)
44 mov %al,4(%esp)
45 fldenv (%esp)
46 add $32,%esp
47 xor %eax,%eax
48 ret
49
50.global feraiseexcept
51.type feraiseexcept,@function
52feraiseexcept:
53 mov 4(%esp),%eax
54 and $0x3f,%eax
55 sub $32,%esp
56 fnstenv (%esp)
57 or %al,4(%esp)
58 fldenv (%esp)
59 add $32,%esp
60 xor %eax,%eax
61 ret
62
63.global __fesetround
64.hidden __fesetround
65.type __fesetround,@function
66__fesetround:
67 mov 4(%esp),%ecx
68 push %eax
69 xor %eax,%eax
70 fnstcw (%esp)
71 andb $0xf3,1(%esp)
72 or %ch,1(%esp)
73 fldcw (%esp)
74 # consider sse fenv as well if the cpu has XMM capability
75 call 1f
761: addl $__hwcap-1b,(%esp)
77 pop %edx
78 testl $0x02000000,(%edx)
79 jz 1f
80 stmxcsr (%esp)
81 shl $3,%ch
82 andb $0x9f,1(%esp)
83 or %ch,1(%esp)
84 ldmxcsr (%esp)
851: pop %ecx
86 ret
87
88.global fegetround
89.type fegetround,@function
90fegetround:
91 push %eax
92 fnstcw (%esp)
93 pop %eax
94 and $0xc00,%eax
95 ret
96
97.global fegetenv
98.type fegetenv,@function
99fegetenv:
100 mov 4(%esp),%ecx
101 xor %eax,%eax
102 fnstenv (%ecx)
103 # consider sse fenv as well if the cpu has XMM capability
104 call 1f
1051: addl $__hwcap-1b,(%esp)
106 pop %edx
107 testl $0x02000000,(%edx)
108 jz 1f
109 push %eax
110 stmxcsr (%esp)
111 pop %edx
112 and $0x3f,%edx
113 or %edx,4(%ecx)
1141: ret
115
116.global fesetenv
117.type fesetenv,@function
118fesetenv:
119 mov 4(%esp),%ecx
120 xor %eax,%eax
121 inc %ecx
122 jz 1f
123 fldenv -1(%ecx)
124 movl -1(%ecx),%ecx
125 jmp 2f
1261: push %eax
127 push %eax
128 push %eax
129 push %eax
130 pushl $0xffff
131 push %eax
132 pushl $0x37f
133 fldenv (%esp)
134 add $28,%esp
135 # consider sse fenv as well if the cpu has XMM capability
1362: call 1f
1371: addl $__hwcap-1b,(%esp)
138 pop %edx
139 testl $0x02000000,(%edx)
140 jz 1f
141 # mxcsr := same rounding mode, cleared exceptions, default mask
142 and $0xc00,%ecx
143 shl $3,%ecx
144 or $0x1f80,%ecx
145 mov %ecx,4(%esp)
146 ldmxcsr 4(%esp)
1471: ret
148
149.global fetestexcept
150.type fetestexcept,@function
151fetestexcept:
152 mov 4(%esp),%ecx
153 and $0x3f,%ecx
154 fnstsw %ax
155 # consider sse fenv as well if the cpu has XMM capability
156 call 1f
1571: addl $__hwcap-1b,(%esp)
158 pop %edx
159 testl $0x02000000,(%edx)
160 jz 1f
161 stmxcsr 4(%esp)
162 or 4(%esp),%eax
1631: and %ecx,%eax
164 ret
lib/libc/wasi/libc-top-half/musl/src/fenv/m68k/fenv.c deleted-85
......@@ -1,85 +0,0 @@
1#include <fenv.h>
2#include <features.h>
3
4#if __HAVE_68881__ || __mcffpu__
5
6static unsigned getsr()
7{
8 unsigned v;
9 __asm__ __volatile__ ("fmove.l %%fpsr,%0" : "=dm"(v));
10 return v;
11}
12
13static void setsr(unsigned v)
14{
15 __asm__ __volatile__ ("fmove.l %0,%%fpsr" : : "dm"(v));
16}
17
18static unsigned getcr()
19{
20 unsigned v;
21 __asm__ __volatile__ ("fmove.l %%fpcr,%0" : "=dm"(v));
22 return v;
23}
24
25static void setcr(unsigned v)
26{
27 __asm__ __volatile__ ("fmove.l %0,%%fpcr" : : "dm"(v));
28}
29
30int feclearexcept(int mask)
31{
32 if (mask & ~FE_ALL_EXCEPT) return -1;
33 setsr(getsr() & ~mask);
34 return 0;
35}
36
37int feraiseexcept(int mask)
38{
39 if (mask & ~FE_ALL_EXCEPT) return -1;
40 setsr(getsr() | mask);
41 return 0;
42}
43
44int fetestexcept(int mask)
45{
46 return getsr() & mask;
47}
48
49int fegetround(void)
50{
51 return getcr() & FE_UPWARD;
52}
53
54hidden int __fesetround(int r)
55{
56 setcr((getcr() & ~FE_UPWARD) | r);
57 return 0;
58}
59
60int fegetenv(fenv_t *envp)
61{
62 envp->__control_register = getcr();
63 envp->__status_register = getsr();
64 __asm__ __volatile__ ("fmove.l %%fpiar,%0"
65 : "=dm"(envp->__instruction_address));
66 return 0;
67}
68
69int fesetenv(const fenv_t *envp)
70{
71 static const fenv_t default_env = { 0 };
72 if (envp == FE_DFL_ENV)
73 envp = &default_env;
74 setcr(envp->__control_register);
75 setsr(envp->__status_register);
76 __asm__ __volatile__ ("fmove.l %0,%%fpiar"
77 : : "dm"(envp->__instruction_address));
78 return 0;
79}
80
81#else
82
83#include "../fenv.c"
84
85#endif
lib/libc/wasi/libc-top-half/musl/src/fenv/mips/fenv-sf.c deleted-3
......@@ -1,3 +0,0 @@
1#ifdef __mips_soft_float
2#include "../fenv.c"
3#endif
lib/libc/wasi/libc-top-half/musl/src/fenv/mips64/fenv-sf.c deleted-3
......@@ -1,3 +0,0 @@
1#ifdef __mips_soft_float
2#include "../fenv.c"
3#endif
lib/libc/wasi/libc-top-half/musl/src/fenv/mipsn32/fenv-sf.c deleted-3
......@@ -1,3 +0,0 @@
1#ifdef __mips_soft_float
2#include "../fenv.c"
3#endif
lib/libc/wasi/libc-top-half/musl/src/fenv/powerpc/fenv-sf.c deleted-3
......@@ -1,3 +0,0 @@
1#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
2#include "../fenv.c"
3#endif
lib/libc/wasi/libc-top-half/musl/src/fenv/powerpc64/fenv.c deleted-69
......@@ -1,69 +0,0 @@
1#define _GNU_SOURCE
2#include <fenv.h>
3#include <features.h>
4
5static inline double get_fpscr_f(void)
6{
7 double d;
8 __asm__ __volatile__("mffs %0" : "=d"(d));
9 return d;
10}
11
12static inline long get_fpscr(void)
13{
14 return (union {double f; long i;}) {get_fpscr_f()}.i;
15}
16
17static inline void set_fpscr_f(double fpscr)
18{
19 __asm__ __volatile__("mtfsf 255, %0" : : "d"(fpscr));
20}
21
22static void set_fpscr(long fpscr)
23{
24 set_fpscr_f((union {long i; double f;}) {fpscr}.f);
25}
26
27int feclearexcept(int mask)
28{
29 mask &= FE_ALL_EXCEPT;
30 if (mask & FE_INVALID) mask |= FE_ALL_INVALID;
31 set_fpscr(get_fpscr() & ~mask);
32 return 0;
33}
34
35int feraiseexcept(int mask)
36{
37 mask &= FE_ALL_EXCEPT;
38 if (mask & FE_INVALID) mask |= FE_INVALID_SOFTWARE;
39 set_fpscr(get_fpscr() | mask);
40 return 0;
41}
42
43int fetestexcept(int mask)
44{
45 return get_fpscr() & mask & FE_ALL_EXCEPT;
46}
47
48int fegetround(void)
49{
50 return get_fpscr() & 3;
51}
52
53hidden int __fesetround(int r)
54{
55 set_fpscr(get_fpscr() & ~3L | r);
56 return 0;
57}
58
59int fegetenv(fenv_t *envp)
60{
61 *envp = get_fpscr_f();
62 return 0;
63}
64
65int fesetenv(const fenv_t *envp)
66{
67 set_fpscr_f(envp != FE_DFL_ENV ? *envp : 0);
68 return 0;
69}
lib/libc/wasi/libc-top-half/musl/src/fenv/riscv64/fenv-sf.c deleted-3
......@@ -1,3 +0,0 @@
1#ifndef __riscv_flen
2#include "../fenv.c"
3#endif
lib/libc/wasi/libc-top-half/musl/src/fenv/s390x/fenv.c deleted-56
......@@ -1,56 +0,0 @@
1#include <fenv.h>
2#include <features.h>
3
4static inline unsigned get_fpc(void)
5{
6 unsigned fpc;
7 __asm__ __volatile__("efpc %0" : "=r"(fpc));
8 return fpc;
9}
10
11static inline void set_fpc(unsigned fpc)
12{
13 __asm__ __volatile__("sfpc %0" :: "r"(fpc));
14}
15
16int feclearexcept(int mask)
17{
18 mask &= FE_ALL_EXCEPT;
19 set_fpc(get_fpc() & ~mask);
20 return 0;
21}
22
23int feraiseexcept(int mask)
24{
25 mask &= FE_ALL_EXCEPT;
26 set_fpc(get_fpc() | mask);
27 return 0;
28}
29
30int fetestexcept(int mask)
31{
32 return get_fpc() & mask & FE_ALL_EXCEPT;
33}
34
35int fegetround(void)
36{
37 return get_fpc() & 3;
38}
39
40hidden int __fesetround(int r)
41{
42 set_fpc(get_fpc() & ~3L | r);
43 return 0;
44}
45
46int fegetenv(fenv_t *envp)
47{
48 *envp = get_fpc();
49 return 0;
50}
51
52int fesetenv(const fenv_t *envp)
53{
54 set_fpc(envp != FE_DFL_ENV ? *envp : 0);
55 return 0;
56}
lib/libc/wasi/libc-top-half/musl/src/fenv/sh/fenv-nofpu.c deleted-3
......@@ -1,3 +0,0 @@
1#if !__SH_FPU_ANY__ && !__SH4__
2#include "../fenv.c"
3#endif
lib/libc/wasi/libc-top-half/musl/src/fenv/x32/fenv.s deleted-98
......@@ -1,98 +0,0 @@
1.global feclearexcept
2.type feclearexcept,@function
3feclearexcept:
4 # maintain exceptions in the sse mxcsr, clear x87 exceptions
5 mov %edi,%ecx
6 and $0x3f,%ecx
7 fnstsw %ax
8 test %eax,%ecx
9 jz 1f
10 fnclex
111: stmxcsr -8(%esp)
12 and $0x3f,%eax
13 or %eax,-8(%esp)
14 test %ecx,-8(%esp)
15 jz 1f
16 not %ecx
17 and %ecx,-8(%esp)
18 ldmxcsr -8(%esp)
191: xor %eax,%eax
20 ret
21
22.global feraiseexcept
23.type feraiseexcept,@function
24feraiseexcept:
25 and $0x3f,%edi
26 stmxcsr -8(%esp)
27 or %edi,-8(%esp)
28 ldmxcsr -8(%esp)
29 xor %eax,%eax
30 ret
31
32.global __fesetround
33.hidden __fesetround
34.type __fesetround,@function
35__fesetround:
36 push %rax
37 xor %eax,%eax
38 mov %edi,%ecx
39 fnstcw (%esp)
40 andb $0xf3,1(%esp)
41 or %ch,1(%esp)
42 fldcw (%esp)
43 stmxcsr (%esp)
44 shl $3,%ch
45 andb $0x9f,1(%esp)
46 or %ch,1(%esp)
47 ldmxcsr (%esp)
48 pop %rcx
49 ret
50
51.global fegetround
52.type fegetround,@function
53fegetround:
54 push %rax
55 stmxcsr (%esp)
56 pop %rax
57 shr $3,%eax
58 and $0xc00,%eax
59 ret
60
61.global fegetenv
62.type fegetenv,@function
63fegetenv:
64 xor %eax,%eax
65 fnstenv (%edi)
66 stmxcsr 28(%edi)
67 ret
68
69.global fesetenv
70.type fesetenv,@function
71fesetenv:
72 xor %eax,%eax
73 inc %edi
74 jz 1f
75 fldenv -1(%edi)
76 ldmxcsr 27(%edi)
77 ret
781: push %rax
79 push %rax
80 pushq $0xffff
81 pushq $0x37f
82 fldenv (%esp)
83 pushq $0x1f80
84 ldmxcsr (%esp)
85 add $40,%esp
86 ret
87
88.global fetestexcept
89.type fetestexcept,@function
90fetestexcept:
91 and $0x3f,%edi
92 push %rax
93 stmxcsr (%esp)
94 pop %rsi
95 fnstsw %ax
96 or %esi,%eax
97 and %edi,%eax
98 ret
lib/libc/wasi/libc-top-half/musl/src/fenv/x86_64/fenv.s deleted-98
......@@ -1,98 +0,0 @@
1.global feclearexcept
2.type feclearexcept,@function
3feclearexcept:
4 # maintain exceptions in the sse mxcsr, clear x87 exceptions
5 mov %edi,%ecx
6 and $0x3f,%ecx
7 fnstsw %ax
8 test %eax,%ecx
9 jz 1f
10 fnclex
111: stmxcsr -8(%rsp)
12 and $0x3f,%eax
13 or %eax,-8(%rsp)
14 test %ecx,-8(%rsp)
15 jz 1f
16 not %ecx
17 and %ecx,-8(%rsp)
18 ldmxcsr -8(%rsp)
191: xor %eax,%eax
20 ret
21
22.global feraiseexcept
23.type feraiseexcept,@function
24feraiseexcept:
25 and $0x3f,%edi
26 stmxcsr -8(%rsp)
27 or %edi,-8(%rsp)
28 ldmxcsr -8(%rsp)
29 xor %eax,%eax
30 ret
31
32.global __fesetround
33.hidden __fesetround
34.type __fesetround,@function
35__fesetround:
36 push %rax
37 xor %eax,%eax
38 mov %edi,%ecx
39 fnstcw (%rsp)
40 andb $0xf3,1(%rsp)
41 or %ch,1(%rsp)
42 fldcw (%rsp)
43 stmxcsr (%rsp)
44 shl $3,%ch
45 andb $0x9f,1(%rsp)
46 or %ch,1(%rsp)
47 ldmxcsr (%rsp)
48 pop %rcx
49 ret
50
51.global fegetround
52.type fegetround,@function
53fegetround:
54 push %rax
55 stmxcsr (%rsp)
56 pop %rax
57 shr $3,%eax
58 and $0xc00,%eax
59 ret
60
61.global fegetenv
62.type fegetenv,@function
63fegetenv:
64 xor %eax,%eax
65 fnstenv (%rdi)
66 stmxcsr 28(%rdi)
67 ret
68
69.global fesetenv
70.type fesetenv,@function
71fesetenv:
72 xor %eax,%eax
73 inc %rdi
74 jz 1f
75 fldenv -1(%rdi)
76 ldmxcsr 27(%rdi)
77 ret
781: push %rax
79 push %rax
80 pushq $0xffff
81 pushq $0x37f
82 fldenv (%rsp)
83 pushq $0x1f80
84 ldmxcsr (%rsp)
85 add $40,%rsp
86 ret
87
88.global fetestexcept
89.type fetestexcept,@function
90fetestexcept:
91 and $0x3f,%edi
92 push %rax
93 stmxcsr (%rsp)
94 pop %rsi
95 fnstsw %ax
96 or %esi,%eax
97 and %edi,%eax
98 ret
lib/libc/wasi/libc-top-half/musl/src/internal/i386/defsysinfo.s deleted-9
......@@ -1,9 +0,0 @@
11: int $128
2 ret
3
4.data
5.align 4
6.hidden __sysinfo
7.global __sysinfo
8__sysinfo:
9 .long 1b
lib/libc/wasi/libc-top-half/musl/src/internal/procfdname.c deleted-15
......@@ -1,15 +0,0 @@
1#include "syscall.h"
2
3void __procfdname(char *buf, unsigned fd)
4{
5 unsigned i, j;
6 for (i=0; (buf[i] = "/proc/self/fd/"[i]); i++);
7 if (!fd) {
8 buf[i] = '0';
9 buf[i+1] = 0;
10 return;
11 }
12 for (j=fd; j; j/=10, i++);
13 buf[i] = 0;
14 for (; fd; fd/=10) buf[--i] = '0' + fd%10;
15}
lib/libc/wasi/libc-top-half/musl/src/internal/sh/__shcall.c deleted-6
......@@ -1,6 +0,0 @@
1#include <features.h>
2
3hidden int __shcall(void *arg, int (*func)(void *))
4{
5 return func(arg);
6}
lib/libc/wasi/libc-top-half/musl/src/internal/syscall_ret.c deleted-11
......@@ -1,11 +0,0 @@
1#include <errno.h>
2#include "syscall.h"
3
4long __syscall_ret(unsigned long r)
5{
6 if (r > -4096UL) {
7 errno = -r;
8 return -1;
9 }
10 return r;
11}
lib/libc/wasi/libc-top-half/musl/src/internal/vdso.c deleted-93
......@@ -1,93 +0,0 @@
1#include <elf.h>
2#include <link.h>
3#include <limits.h>
4#include <stdint.h>
5#include <string.h>
6#include "libc.h"
7#include "syscall.h"
8
9#ifdef VDSO_USEFUL
10
11#if ULONG_MAX == 0xffffffff
12typedef Elf32_Ehdr Ehdr;
13typedef Elf32_Phdr Phdr;
14typedef Elf32_Sym Sym;
15typedef Elf32_Verdef Verdef;
16typedef Elf32_Verdaux Verdaux;
17#else
18typedef Elf64_Ehdr Ehdr;
19typedef Elf64_Phdr Phdr;
20typedef Elf64_Sym Sym;
21typedef Elf64_Verdef Verdef;
22typedef Elf64_Verdaux Verdaux;
23#endif
24
25static int checkver(Verdef *def, int vsym, const char *vername, char *strings)
26{
27 vsym &= 0x7fff;
28 for (;;) {
29 if (!(def->vd_flags & VER_FLG_BASE)
30 && (def->vd_ndx & 0x7fff) == vsym)
31 break;
32 if (def->vd_next == 0)
33 return 0;
34 def = (Verdef *)((char *)def + def->vd_next);
35 }
36 Verdaux *aux = (Verdaux *)((char *)def + def->vd_aux);
37 return !strcmp(vername, strings + aux->vda_name);
38}
39
40#define OK_TYPES (1<<STT_NOTYPE | 1<<STT_OBJECT | 1<<STT_FUNC | 1<<STT_COMMON)
41#define OK_BINDS (1<<STB_GLOBAL | 1<<STB_WEAK | 1<<STB_GNU_UNIQUE)
42
43void *__vdsosym(const char *vername, const char *name)
44{
45 size_t i;
46 for (i=0; libc.auxv[i] != AT_SYSINFO_EHDR; i+=2)
47 if (!libc.auxv[i]) return 0;
48 if (!libc.auxv[i+1]) return 0;
49 Ehdr *eh = (void *)libc.auxv[i+1];
50 Phdr *ph = (void *)((char *)eh + eh->e_phoff);
51 size_t *dynv=0, base=-1;
52 for (i=0; i<eh->e_phnum; i++, ph=(void *)((char *)ph+eh->e_phentsize)) {
53 if (ph->p_type == PT_LOAD)
54 base = (size_t)eh + ph->p_offset - ph->p_vaddr;
55 else if (ph->p_type == PT_DYNAMIC)
56 dynv = (void *)((char *)eh + ph->p_offset);
57 }
58 if (!dynv || base==(size_t)-1) return 0;
59
60 char *strings = 0;
61 Sym *syms = 0;
62 Elf_Symndx *hashtab = 0;
63 uint16_t *versym = 0;
64 Verdef *verdef = 0;
65
66 for (i=0; dynv[i]; i+=2) {
67 void *p = (void *)(base + dynv[i+1]);
68 switch(dynv[i]) {
69 case DT_STRTAB: strings = p; break;
70 case DT_SYMTAB: syms = p; break;
71 case DT_HASH: hashtab = p; break;
72 case DT_VERSYM: versym = p; break;
73 case DT_VERDEF: verdef = p; break;
74 }
75 }
76
77 if (!strings || !syms || !hashtab) return 0;
78 if (!verdef) versym = 0;
79
80 for (i=0; i<hashtab[1]; i++) {
81 if (!(1<<(syms[i].st_info&0xf) & OK_TYPES)) continue;
82 if (!(1<<(syms[i].st_info>>4) & OK_BINDS)) continue;
83 if (!syms[i].st_shndx) continue;
84 if (strcmp(name, strings+syms[i].st_name)) continue;
85 if (versym && !checkver(verdef, versym[i], vername, strings))
86 continue;
87 return (void *)(base + syms[i].st_value);
88 }
89
90 return 0;
91}
92
93#endif
lib/libc/wasi/libc-top-half/musl/src/internal/version.c deleted-4
......@@ -1,4 +0,0 @@
1#include "version.h"
2#include "libc.h"
3
4const char __libc_version[] = VERSION;
lib/libc/wasi/libc-top-half/musl/src/ipc/ftok.c deleted-10
......@@ -1,10 +0,0 @@
1#include <sys/ipc.h>
2#include <sys/stat.h>
3
4key_t ftok(const char *path, int id)
5{
6 struct stat st;
7 if (stat(path, &st) < 0) return -1;
8
9 return ((st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16) | ((id & 0xffu) << 24));
10}
lib/libc/wasi/libc-top-half/musl/src/ipc/msgctl.c deleted-51
......@@ -1,51 +0,0 @@
1#include <sys/msg.h>
2#include <endian.h>
3#include "syscall.h"
4#include "ipc.h"
5
6#if __BYTE_ORDER != __BIG_ENDIAN
7#undef SYSCALL_IPC_BROKEN_MODE
8#endif
9
10int msgctl(int q, int cmd, struct msqid_ds *buf)
11{
12#if IPC_TIME64
13 struct msqid_ds out, *orig;
14 if (cmd&IPC_TIME64) {
15 out = (struct msqid_ds){0};
16 orig = buf;
17 buf = &out;
18 }
19#endif
20#ifdef SYSCALL_IPC_BROKEN_MODE
21 struct msqid_ds tmp;
22 if (cmd == IPC_SET) {
23 tmp = *buf;
24 tmp.msg_perm.mode *= 0x10000U;
25 buf = &tmp;
26 }
27#endif
28#ifndef SYS_ipc
29 int r = __syscall(SYS_msgctl, q, IPC_CMD(cmd), buf);
30#else
31 int r = __syscall(SYS_ipc, IPCOP_msgctl, q, IPC_CMD(cmd), 0, buf, 0);
32#endif
33#ifdef SYSCALL_IPC_BROKEN_MODE
34 if (r >= 0) switch (cmd | IPC_TIME64) {
35 case IPC_STAT:
36 case MSG_STAT:
37 case MSG_STAT_ANY:
38 buf->msg_perm.mode >>= 16;
39 }
40#endif
41#if IPC_TIME64
42 if (r >= 0 && (cmd&IPC_TIME64)) {
43 buf = orig;
44 *buf = out;
45 IPC_HILO(buf, msg_stime);
46 IPC_HILO(buf, msg_rtime);
47 IPC_HILO(buf, msg_ctime);
48 }
49#endif
50 return __syscall_ret(r);
51}
lib/libc/wasi/libc-top-half/musl/src/ipc/msgget.c deleted-12
......@@ -1,12 +0,0 @@
1#include <sys/msg.h>
2#include "syscall.h"
3#include "ipc.h"
4
5int msgget(key_t k, int flag)
6{
7#ifndef SYS_ipc
8 return syscall(SYS_msgget, k, flag);
9#else
10 return syscall(SYS_ipc, IPCOP_msgget, k, flag);
11#endif
12}
lib/libc/wasi/libc-top-half/musl/src/ipc/msgrcv.c deleted-12
......@@ -1,12 +0,0 @@
1#include <sys/msg.h>
2#include "syscall.h"
3#include "ipc.h"
4
5ssize_t msgrcv(int q, void *m, size_t len, long type, int flag)
6{
7#ifndef SYS_ipc
8 return syscall_cp(SYS_msgrcv, q, m, len, type, flag);
9#else
10 return syscall_cp(SYS_ipc, IPCOP_msgrcv, q, len, flag, ((long[]){ (long)m, type }));
11#endif
12}
lib/libc/wasi/libc-top-half/musl/src/ipc/msgsnd.c deleted-12
......@@ -1,12 +0,0 @@
1#include <sys/msg.h>
2#include "syscall.h"
3#include "ipc.h"
4
5int msgsnd(int q, const void *m, size_t len, int flag)
6{
7#ifndef SYS_ipc
8 return syscall_cp(SYS_msgsnd, q, m, len, flag);
9#else
10 return syscall_cp(SYS_ipc, IPCOP_msgsnd, q, len, flag, m);
11#endif
12}
lib/libc/wasi/libc-top-half/musl/src/ipc/semctl.c deleted-69
......@@ -1,69 +0,0 @@
1#include <sys/sem.h>
2#include <stdarg.h>
3#include <endian.h>
4#include "syscall.h"
5#include "ipc.h"
6
7#if __BYTE_ORDER != __BIG_ENDIAN
8#undef SYSCALL_IPC_BROKEN_MODE
9#endif
10
11union semun {
12 int val;
13 struct semid_ds *buf;
14 unsigned short *array;
15};
16
17int semctl(int id, int num, int cmd, ...)
18{
19 union semun arg = {0};
20 va_list ap;
21 switch (cmd & ~IPC_TIME64) {
22 case SETVAL: case GETALL: case SETALL: case IPC_SET:
23 case IPC_INFO: case SEM_INFO:
24 case IPC_STAT & ~IPC_TIME64:
25 case SEM_STAT & ~IPC_TIME64:
26 case SEM_STAT_ANY & ~IPC_TIME64:
27 va_start(ap, cmd);
28 arg = va_arg(ap, union semun);
29 va_end(ap);
30 }
31#if IPC_TIME64
32 struct semid_ds out, *orig;
33 if (cmd&IPC_TIME64) {
34 out = (struct semid_ds){0};
35 orig = arg.buf;
36 arg.buf = &out;
37 }
38#endif
39#ifdef SYSCALL_IPC_BROKEN_MODE
40 struct semid_ds tmp;
41 if (cmd == IPC_SET) {
42 tmp = *arg.buf;
43 tmp.sem_perm.mode *= 0x10000U;
44 arg.buf = &tmp;
45 }
46#endif
47#ifndef SYS_ipc
48 int r = __syscall(SYS_semctl, id, num, IPC_CMD(cmd), arg.buf);
49#else
50 int r = __syscall(SYS_ipc, IPCOP_semctl, id, num, IPC_CMD(cmd), &arg.buf);
51#endif
52#ifdef SYSCALL_IPC_BROKEN_MODE
53 if (r >= 0) switch (cmd | IPC_TIME64) {
54 case IPC_STAT:
55 case SEM_STAT:
56 case SEM_STAT_ANY:
57 arg.buf->sem_perm.mode >>= 16;
58 }
59#endif
60#if IPC_TIME64
61 if (r >= 0 && (cmd&IPC_TIME64)) {
62 arg.buf = orig;
63 *arg.buf = out;
64 IPC_HILO(arg.buf, sem_otime);
65 IPC_HILO(arg.buf, sem_ctime);
66 }
67#endif
68 return __syscall_ret(r);
69}
lib/libc/wasi/libc-top-half/musl/src/ipc/semget.c deleted-19
......@@ -1,19 +0,0 @@
1#include <sys/sem.h>
2#include <limits.h>
3#include <errno.h>
4#include "syscall.h"
5#include "ipc.h"
6
7int semget(key_t key, int n, int fl)
8{
9 /* The kernel uses the wrong type for the sem_nsems member
10 * of struct semid_ds, and thus might not check that the
11 * n fits in the correct (per POSIX) userspace type, so
12 * we have to check here. */
13 if (n > USHRT_MAX) return __syscall_ret(-EINVAL);
14#ifndef SYS_ipc
15 return syscall(SYS_semget, key, n, fl);
16#else
17 return syscall(SYS_ipc, IPCOP_semget, key, n, fl);
18#endif
19}
lib/libc/wasi/libc-top-half/musl/src/ipc/semop.c deleted-12
......@@ -1,12 +0,0 @@
1#include <sys/sem.h>
2#include "syscall.h"
3#include "ipc.h"
4
5int semop(int id, struct sembuf *buf, size_t n)
6{
7#ifndef SYS_ipc
8 return syscall(SYS_semop, id, buf, n);
9#else
10 return syscall(SYS_ipc, IPCOP_semop, id, n, 0, buf);
11#endif
12}
lib/libc/wasi/libc-top-half/musl/src/ipc/semtimedop.c deleted-35
......@@ -1,35 +0,0 @@
1#define _GNU_SOURCE
2#include <sys/sem.h>
3#include <errno.h>
4#include "syscall.h"
5#include "ipc.h"
6
7#define IS32BIT(x) !((x)+0x80000000ULL>>32)
8#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
9
10#if !defined(SYS_semtimedop) && !defined(SYS_ipc)
11#define NO_TIME32 1
12#else
13#define NO_TIME32 0
14#endif
15
16int semtimedop(int id, struct sembuf *buf, size_t n, const struct timespec *ts)
17{
18#ifdef SYS_semtimedop_time64
19 time_t s = ts ? ts->tv_sec : 0;
20 long ns = ts ? ts->tv_nsec : 0;
21 int r = -ENOSYS;
22 if (NO_TIME32 || !IS32BIT(s))
23 r = __syscall(SYS_semtimedop_time64, id, buf, n,
24 ts ? ((long long[]){s, ns}) : 0);
25 if (NO_TIME32 || r!=-ENOSYS) return __syscall_ret(r);
26 ts = ts ? (void *)(long[]){CLAMP(s), ns} : 0;
27#endif
28#if defined(SYS_ipc)
29 return syscall(SYS_ipc, IPCOP_semtimedop, id, n, 0, buf, ts);
30#elif defined(SYS_semtimedop)
31 return syscall(SYS_semtimedop, id, buf, n, ts);
32#else
33 return __syscall_ret(-ENOSYS);
34#endif
35}
lib/libc/wasi/libc-top-half/musl/src/ipc/shmat.c deleted-17
......@@ -1,17 +0,0 @@
1#include <sys/shm.h>
2#include "syscall.h"
3#include "ipc.h"
4
5#ifndef SYS_ipc
6void *shmat(int id, const void *addr, int flag)
7{
8 return (void *)syscall(SYS_shmat, id, addr, flag);
9}
10#else
11void *shmat(int id, const void *addr, int flag)
12{
13 unsigned long ret;
14 ret = syscall(SYS_ipc, IPCOP_shmat, id, flag, &addr, addr);
15 return (ret > -(unsigned long)SHMLBA) ? (void *)ret : (void *)addr;
16}
17#endif
lib/libc/wasi/libc-top-half/musl/src/ipc/shmctl.c deleted-51
......@@ -1,51 +0,0 @@
1#include <sys/shm.h>
2#include <endian.h>
3#include "syscall.h"
4#include "ipc.h"
5
6#if __BYTE_ORDER != __BIG_ENDIAN
7#undef SYSCALL_IPC_BROKEN_MODE
8#endif
9
10int shmctl(int id, int cmd, struct shmid_ds *buf)
11{
12#if IPC_TIME64
13 struct shmid_ds out, *orig;
14 if (cmd&IPC_TIME64) {
15 out = (struct shmid_ds){0};
16 orig = buf;
17 buf = &out;
18 }
19#endif
20#ifdef SYSCALL_IPC_BROKEN_MODE
21 struct shmid_ds tmp;
22 if (cmd == IPC_SET) {
23 tmp = *buf;
24 tmp.shm_perm.mode *= 0x10000U;
25 buf = &tmp;
26 }
27#endif
28#ifndef SYS_ipc
29 int r = __syscall(SYS_shmctl, id, IPC_CMD(cmd), buf);
30#else
31 int r = __syscall(SYS_ipc, IPCOP_shmctl, id, IPC_CMD(cmd), 0, buf, 0);
32#endif
33#ifdef SYSCALL_IPC_BROKEN_MODE
34 if (r >= 0) switch (cmd | IPC_TIME64) {
35 case IPC_STAT:
36 case SHM_STAT:
37 case SHM_STAT_ANY:
38 buf->shm_perm.mode >>= 16;
39 }
40#endif
41#if IPC_TIME64
42 if (r >= 0 && (cmd&IPC_TIME64)) {
43 buf = orig;
44 *buf = out;
45 IPC_HILO(buf, shm_atime);
46 IPC_HILO(buf, shm_dtime);
47 IPC_HILO(buf, shm_ctime);
48 }
49#endif
50 return __syscall_ret(r);
51}
lib/libc/wasi/libc-top-half/musl/src/ipc/shmdt.c deleted-12
......@@ -1,12 +0,0 @@
1#include <sys/shm.h>
2#include "syscall.h"
3#include "ipc.h"
4
5int shmdt(const void *addr)
6{
7#ifndef SYS_ipc
8 return syscall(SYS_shmdt, addr);
9#else
10 return syscall(SYS_ipc, IPCOP_shmdt, 0, 0, 0, addr);
11#endif
12}
lib/libc/wasi/libc-top-half/musl/src/ipc/shmget.c deleted-14
......@@ -1,14 +0,0 @@
1#include <sys/shm.h>
2#include <stdint.h>
3#include "syscall.h"
4#include "ipc.h"
5
6int shmget(key_t key, size_t size, int flag)
7{
8 if (size > PTRDIFF_MAX) size = SIZE_MAX;
9#ifndef SYS_ipc
10 return syscall(SYS_shmget, key, size, flag);
11#else
12 return syscall(SYS_ipc, IPCOP_shmget, key, size, flag);
13#endif
14}
lib/libc/wasi/libc-top-half/musl/src/ldso/__dlsym.c deleted-14
......@@ -1,14 +0,0 @@
1#include <dlfcn.h>
2#include "dynlink.h"
3
4static void *stub_dlsym(void *restrict p, const char *restrict s, void *restrict ra)
5{
6 __dl_seterr("Symbol not found: %s", s);
7 return 0;
8}
9
10weak_alias(stub_dlsym, __dlsym);
11
12#if _REDIR_TIME64
13weak_alias(stub_dlsym, __dlsym_redir_time64);
14#endif
lib/libc/wasi/libc-top-half/musl/src/ldso/aarch64/dlsym.s deleted-6
......@@ -1,6 +0,0 @@
1.global dlsym
2.hidden __dlsym
3.type dlsym,%function
4dlsym:
5 mov x2,x30
6 b __dlsym
lib/libc/wasi/libc-top-half/musl/src/ldso/aarch64/tlsdesc.s deleted-31
......@@ -1,31 +0,0 @@
1// size_t __tlsdesc_static(size_t *a)
2// {
3// return a[1];
4// }
5.global __tlsdesc_static
6.hidden __tlsdesc_static
7.type __tlsdesc_static,@function
8__tlsdesc_static:
9 ldr x0,[x0,#8]
10 ret
11
12// size_t __tlsdesc_dynamic(size_t *a)
13// {
14// struct {size_t modidx,off;} *p = (void*)a[1];
15// size_t *dtv = *(size_t**)(tp - 8);
16// return dtv[p->modidx] + p->off - tp;
17// }
18.global __tlsdesc_dynamic
19.hidden __tlsdesc_dynamic
20.type __tlsdesc_dynamic,@function
21__tlsdesc_dynamic:
22 stp x1,x2,[sp,#-16]!
23 mrs x1,tpidr_el0 // tp
24 ldr x0,[x0,#8] // p
25 ldp x0,x2,[x0] // p->modidx, p->off
26 sub x2,x2,x1 // p->off - tp
27 ldr x1,[x1,#-8] // dtv
28 ldr x1,[x1,x0,lsl #3] // dtv[p->modidx]
29 add x0,x1,x2 // dtv[p->modidx] + p->off - tp
30 ldp x1,x2,[sp],#16
31 ret
lib/libc/wasi/libc-top-half/musl/src/ldso/arm/dlsym.s deleted-8
......@@ -1,8 +0,0 @@
1.syntax unified
2.text
3.global dlsym
4.hidden __dlsym
5.type dlsym,%function
6dlsym:
7 mov r2,lr
8 b __dlsym
lib/libc/wasi/libc-top-half/musl/src/ldso/arm/find_exidx.c deleted-42
......@@ -1,42 +0,0 @@
1#define _GNU_SOURCE
2#include <link.h>
3#include <stdint.h>
4
5struct find_exidx_data {
6 uintptr_t pc, exidx_start;
7 int exidx_len;
8};
9
10static int find_exidx(struct dl_phdr_info *info, size_t size, void *ptr)
11{
12 struct find_exidx_data *data = ptr;
13 const ElfW(Phdr) *phdr = info->dlpi_phdr;
14 uintptr_t addr, exidx_start = 0;
15 int i, match = 0, exidx_len = 0;
16
17 for (i = info->dlpi_phnum; i > 0; i--, phdr++) {
18 addr = info->dlpi_addr + phdr->p_vaddr;
19 switch (phdr->p_type) {
20 case PT_LOAD:
21 match |= data->pc >= addr && data->pc < addr + phdr->p_memsz;
22 break;
23 case PT_ARM_EXIDX:
24 exidx_start = addr;
25 exidx_len = phdr->p_memsz;
26 break;
27 }
28 }
29 data->exidx_start = exidx_start;
30 data->exidx_len = exidx_len;
31 return match;
32}
33
34uintptr_t __gnu_Unwind_Find_exidx(uintptr_t pc, int *pcount)
35{
36 struct find_exidx_data data;
37 data.pc = pc;
38 if (dl_iterate_phdr(find_exidx, &data) <= 0)
39 return 0;
40 *pcount = data.exidx_len / 8;
41 return data.exidx_start;
42}
lib/libc/wasi/libc-top-half/musl/src/ldso/dl_iterate_phdr.c deleted-47
......@@ -1,47 +0,0 @@
1#include <elf.h>
2#include <link.h>
3#include "pthread_impl.h"
4#include "libc.h"
5
6#define AUX_CNT 38
7
8extern weak hidden const size_t _DYNAMIC[];
9
10static int static_dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data)
11{
12 unsigned char *p;
13 ElfW(Phdr) *phdr, *tls_phdr=0;
14 size_t base = 0;
15 size_t n;
16 struct dl_phdr_info info;
17 size_t i, aux[AUX_CNT] = {0};
18
19 for (i=0; libc.auxv[i]; i+=2)
20 if (libc.auxv[i]<AUX_CNT) aux[libc.auxv[i]] = libc.auxv[i+1];
21
22 for (p=(void *)aux[AT_PHDR],n=aux[AT_PHNUM]; n; n--,p+=aux[AT_PHENT]) {
23 phdr = (void *)p;
24 if (phdr->p_type == PT_PHDR)
25 base = aux[AT_PHDR] - phdr->p_vaddr;
26 if (phdr->p_type == PT_DYNAMIC && _DYNAMIC)
27 base = (size_t)_DYNAMIC - phdr->p_vaddr;
28 if (phdr->p_type == PT_TLS)
29 tls_phdr = phdr;
30 }
31 info.dlpi_addr = base;
32 info.dlpi_name = "/proc/self/exe";
33 info.dlpi_phdr = (void *)aux[AT_PHDR];
34 info.dlpi_phnum = aux[AT_PHNUM];
35 info.dlpi_adds = 0;
36 info.dlpi_subs = 0;
37 if (tls_phdr) {
38 info.dlpi_tls_modid = 1;
39 info.dlpi_tls_data = __tls_get_addr((tls_mod_off_t[]){1,0});
40 } else {
41 info.dlpi_tls_modid = 0;
42 info.dlpi_tls_data = 0;
43 }
44 return (callback)(&info, sizeof (info), data);
45}
46
47weak_alias(static_dl_iterate_phdr, dl_iterate_phdr);
lib/libc/wasi/libc-top-half/musl/src/ldso/dladdr.c deleted-9
......@@ -1,9 +0,0 @@
1#define _GNU_SOURCE
2#include <dlfcn.h>
3
4static int stub_dladdr(const void *addr, Dl_info *info)
5{
6 return 0;
7}
8
9weak_alias(stub_dladdr, dladdr);
lib/libc/wasi/libc-top-half/musl/src/ldso/dlclose.c deleted-7
......@@ -1,7 +0,0 @@
1#include <dlfcn.h>
2#include "dynlink.h"
3
4int dlclose(void *p)
5{
6 return __dl_invalid_handle(p);
7}
lib/libc/wasi/libc-top-half/musl/src/ldso/dlerror.c deleted-87
......@@ -1,87 +0,0 @@
1#include <dlfcn.h>
2#include <stdlib.h>
3#include <stdarg.h>
4#include "pthread_impl.h"
5#include "dynlink.h"
6#include "lock.h"
7#include "fork_impl.h"
8
9#define malloc __libc_malloc
10#define calloc __libc_calloc
11#define realloc __libc_realloc
12#define free __libc_free
13
14char *dlerror()
15{
16 pthread_t self = __pthread_self();
17 if (!self->dlerror_flag) return 0;
18 self->dlerror_flag = 0;
19 char *s = self->dlerror_buf;
20 if (s == (void *)-1)
21 return "Dynamic linker failed to allocate memory for error message";
22 else
23 return s;
24}
25
26static volatile int freebuf_queue_lock[1];
27static void **freebuf_queue;
28volatile int *const __dlerror_lockptr = freebuf_queue_lock;
29
30void __dl_thread_cleanup(void)
31{
32 pthread_t self = __pthread_self();
33 if (self->dlerror_buf && self->dlerror_buf != (void *)-1) {
34 LOCK(freebuf_queue_lock);
35 void **p = (void **)self->dlerror_buf;
36 *p = freebuf_queue;
37 freebuf_queue = p;
38 UNLOCK(freebuf_queue_lock);
39 }
40}
41
42hidden void __dl_vseterr(const char *fmt, va_list ap)
43{
44 LOCK(freebuf_queue_lock);
45 void **q = freebuf_queue;
46 freebuf_queue = 0;
47 UNLOCK(freebuf_queue_lock);
48
49 while (q) {
50 void **p = *q;
51 free(q);
52 q = p;
53 }
54
55 va_list ap2;
56 va_copy(ap2, ap);
57 pthread_t self = __pthread_self();
58 if (self->dlerror_buf != (void *)-1)
59 free(self->dlerror_buf);
60 size_t len = vsnprintf(0, 0, fmt, ap2);
61 if (len < sizeof(void *)) len = sizeof(void *);
62 va_end(ap2);
63 char *buf = malloc(len+1);
64 if (buf) {
65 vsnprintf(buf, len+1, fmt, ap);
66 } else {
67 buf = (void *)-1;
68 }
69 self->dlerror_buf = buf;
70 self->dlerror_flag = 1;
71}
72
73hidden void __dl_seterr(const char *fmt, ...)
74{
75 va_list ap;
76 va_start(ap, fmt);
77 __dl_vseterr(fmt, ap);
78 va_end(ap);
79}
80
81static int stub_invalid_handle(void *h)
82{
83 __dl_seterr("Invalid library handle %p", (void *)h);
84 return 1;
85}
86
87weak_alias(stub_invalid_handle, __dl_invalid_handle);
lib/libc/wasi/libc-top-half/musl/src/ldso/dlinfo.c deleted-14
......@@ -1,14 +0,0 @@
1#define _GNU_SOURCE
2#include <dlfcn.h>
3#include "dynlink.h"
4
5int dlinfo(void *dso, int req, void *res)
6{
7 if (__dl_invalid_handle(dso)) return -1;
8 if (req != RTLD_DI_LINKMAP) {
9 __dl_seterr("Unsupported request %d", req);
10 return -1;
11 }
12 *(struct link_map **)res = dso;
13 return 0;
14}
lib/libc/wasi/libc-top-half/musl/src/ldso/dlopen.c deleted-10
......@@ -1,10 +0,0 @@
1#include <dlfcn.h>
2#include "dynlink.h"
3
4static void *stub_dlopen(const char *file, int mode)
5{
6 __dl_seterr("Dynamic loading not supported");
7 return 0;
8}
9
10weak_alias(stub_dlopen, dlopen);
lib/libc/wasi/libc-top-half/musl/src/ldso/dlsym.c deleted-7
......@@ -1,7 +0,0 @@
1#include <dlfcn.h>
2#include "dynlink.h"
3
4void *dlsym(void *restrict p, const char *restrict s)
5{
6 return __dlsym(p, s, 0);
7}
lib/libc/wasi/libc-top-half/musl/src/ldso/i386/dlsym.s deleted-11
......@@ -1,11 +0,0 @@
1.text
2.global dlsym
3.hidden __dlsym
4.type dlsym,@function
5dlsym:
6 push (%esp)
7 push 12(%esp)
8 push 12(%esp)
9 call __dlsym
10 add $12,%esp
11 ret
lib/libc/wasi/libc-top-half/musl/src/ldso/i386/tlsdesc.s deleted-23
......@@ -1,23 +0,0 @@
1.text
2.global __tlsdesc_static
3.hidden __tlsdesc_static
4.type __tlsdesc_static,@function
5__tlsdesc_static:
6 mov 4(%eax),%eax
7 ret
8
9.global __tlsdesc_dynamic
10.hidden __tlsdesc_dynamic
11.type __tlsdesc_dynamic,@function
12__tlsdesc_dynamic:
13 mov 4(%eax),%eax
14 push %edx
15 mov %gs:4,%edx
16 push %ecx
17 mov (%eax),%ecx
18 mov 4(%eax),%eax
19 add (%edx,%ecx,4),%eax
20 pop %ecx
21 sub %gs:0,%eax
22 pop %edx
23 ret
lib/libc/wasi/libc-top-half/musl/src/ldso/m68k/dlsym.s deleted-12
......@@ -1,12 +0,0 @@
1.text
2.global dlsym
3.hidden __dlsym
4.type dlsym,@function
5dlsym:
6 move.l (%sp),-(%sp)
7 move.l 12(%sp),-(%sp)
8 move.l 12(%sp),-(%sp)
9 lea __dlsym-.-8,%a1
10 jsr (%pc,%a1)
11 add.l #12,%sp
12 rts
lib/libc/wasi/libc-top-half/musl/src/ldso/microblaze/dlsym.s deleted-6
......@@ -1,6 +0,0 @@
1.global dlsym
2.hidden __dlsym
3.type dlsym,@function
4dlsym:
5 brid __dlsym
6 add r7, r15, r0
lib/libc/wasi/libc-top-half/musl/src/ldso/mips/dlsym.s deleted-17
......@@ -1,17 +0,0 @@
1.set noreorder
2.global dlsym
3.hidden __dlsym
4.type dlsym,@function
5dlsym:
6 lui $gp, %hi(_gp_disp)
7 addiu $gp, %lo(_gp_disp)
8 addu $gp, $gp, $25
9 move $6, $ra
10 lw $25, %call16(__dlsym)($gp)
11 addiu $sp, $sp, -16
12 sw $ra, 12($sp)
13 jalr $25
14 nop
15 lw $ra, 12($sp)
16 jr $ra
17 addiu $sp, $sp, 16
lib/libc/wasi/libc-top-half/musl/src/ldso/mips64/dlsym.s deleted-17
......@@ -1,17 +0,0 @@
1.set noreorder
2.global dlsym
3.hidden __dlsym
4.type dlsym,@function
5dlsym:
6 lui $3, %hi(%neg(%gp_rel(dlsym)))
7 daddiu $3, $3, %lo(%neg(%gp_rel(dlsym)))
8 daddu $3, $3, $25
9 move $6, $ra
10 ld $25, %got_disp(__dlsym)($3)
11 daddiu $sp, $sp, -32
12 sd $ra, 24($sp)
13 jalr $25
14 nop
15 ld $ra, 24($sp)
16 jr $ra
17 daddiu $sp, $sp, 32
lib/libc/wasi/libc-top-half/musl/src/ldso/mipsn32/dlsym.s deleted-17
......@@ -1,17 +0,0 @@
1.set noreorder
2.global dlsym
3.hidden __dlsym
4.type dlsym,@function
5dlsym:
6 lui $3, %hi(%neg(%gp_rel(dlsym)))
7 addiu $3, $3, %lo(%neg(%gp_rel(dlsym)))
8 addu $3, $3, $25
9 move $6, $ra
10 lw $25, %got_disp(__dlsym)($3)
11 addiu $sp, $sp, -32
12 sd $ra, 16($sp)
13 jalr $25
14 nop
15 ld $ra, 16($sp)
16 jr $ra
17 addiu $sp, $sp, 32
lib/libc/wasi/libc-top-half/musl/src/ldso/or1k/dlsym.s deleted-6
......@@ -1,6 +0,0 @@
1.global dlsym
2.hidden __dlsym
3.type dlsym,@function
4dlsym:
5 l.j __dlsym
6 l.ori r5, r9, 0
lib/libc/wasi/libc-top-half/musl/src/ldso/powerpc/dlsym.s deleted-8
......@@ -1,8 +0,0 @@
1 .text
2 .global dlsym
3 .hidden __dlsym
4 .type dlsym,@function
5dlsym:
6 mflr 5 # The return address is arg3.
7 b __dlsym
8 .size dlsym, .-dlsym
lib/libc/wasi/libc-top-half/musl/src/ldso/powerpc64/dlsym.s deleted-11
......@@ -1,11 +0,0 @@
1 .text
2 .global dlsym
3 .hidden __dlsym
4 .type dlsym,@function
5dlsym:
6 addis 2, 12, .TOC.-dlsym@ha
7 addi 2, 2, .TOC.-dlsym@l
8 .localentry dlsym,.-dlsym
9 mflr 5 # The return address is arg3.
10 b __dlsym
11 .size dlsym, .-dlsym
lib/libc/wasi/libc-top-half/musl/src/ldso/riscv64/dlsym.s deleted-6
......@@ -1,6 +0,0 @@
1.global dlsym
2.hidden __dlsym
3.type dlsym, %function
4dlsym:
5 mv a2, ra
6 tail __dlsym
lib/libc/wasi/libc-top-half/musl/src/ldso/s390x/dlsym.s deleted-6
......@@ -1,6 +0,0 @@
1 .global dlsym
2 .hidden __dlsym
3 .type dlsym,@function
4dlsym:
5 lgr %r4, %r14
6 jg __dlsym
lib/libc/wasi/libc-top-half/musl/src/ldso/sh/dlsym.s deleted-11
......@@ -1,11 +0,0 @@
1.text
2.global dlsym
3.hidden __dlsym
4.type dlsym, @function
5dlsym:
6 mov.l L1, r0
71: braf r0
8 mov.l @r15, r6
9
10.align 2
11L1: .long __dlsym@PLT-(1b+4-.)
lib/libc/wasi/libc-top-half/musl/src/ldso/tlsdesc.c deleted-9
......@@ -1,9 +0,0 @@
1#include <stddef.h>
2#include <dynlink.h>
3
4ptrdiff_t __tlsdesc_static()
5{
6 return 0;
7}
8
9weak_alias(__tlsdesc_static, __tlsdesc_dynamic);
lib/libc/wasi/libc-top-half/musl/src/ldso/x32/dlsym.s deleted-7
......@@ -1,7 +0,0 @@
1.text
2.global dlsym
3.hidden __dlsym
4.type dlsym,@function
5dlsym:
6 mov (%rsp),%rdx
7 jmp __dlsym
lib/libc/wasi/libc-top-half/musl/src/ldso/x86_64/dlsym.s deleted-7
......@@ -1,7 +0,0 @@
1.text
2.global dlsym
3.hidden __dlsym
4.type dlsym,@function
5dlsym:
6 mov (%rsp),%rdx
7 jmp __dlsym
lib/libc/wasi/libc-top-half/musl/src/ldso/x86_64/tlsdesc.s deleted-23
......@@ -1,23 +0,0 @@
1.text
2.global __tlsdesc_static
3.hidden __tlsdesc_static
4.type __tlsdesc_static,@function
5__tlsdesc_static:
6 mov 8(%rax),%rax
7 ret
8
9.global __tlsdesc_dynamic
10.hidden __tlsdesc_dynamic
11.type __tlsdesc_dynamic,@function
12__tlsdesc_dynamic:
13 mov 8(%rax),%rax
14 push %rdx
15 mov %fs:8,%rdx
16 push %rcx
17 mov (%rax),%rcx
18 mov 8(%rax),%rax
19 add (%rdx,%rcx,8),%rax
20 pop %rcx
21 sub %fs:0,%rax
22 pop %rdx
23 ret
lib/libc/wasi/libc-top-half/musl/src/legacy/cuserid.c deleted-22
......@@ -1,22 +0,0 @@
1#define _GNU_SOURCE
2#include <pwd.h>
3#include <stdio.h>
4#include <unistd.h>
5#include <string.h>
6
7char *cuserid(char *buf)
8{
9 static char usridbuf[L_cuserid];
10 struct passwd pw, *ppw;
11 long pwb[256];
12 if (buf) *buf = 0;
13 getpwuid_r(geteuid(), &pw, (void *)pwb, sizeof pwb, &ppw);
14 if (!ppw)
15 return buf;
16 size_t len = strnlen(pw.pw_name, L_cuserid);
17 if (len == L_cuserid)
18 return buf;
19 if (!buf) buf = usridbuf;
20 memcpy(buf, pw.pw_name, len+1);
21 return buf;
22}
lib/libc/wasi/libc-top-half/musl/src/legacy/daemon.c deleted-33
......@@ -1,33 +0,0 @@
1#define _GNU_SOURCE
2#include <fcntl.h>
3#include <unistd.h>
4
5int daemon(int nochdir, int noclose)
6{
7 if (!nochdir && chdir("/"))
8 return -1;
9 if (!noclose) {
10 int fd, failed = 0;
11 if ((fd = open("/dev/null", O_RDWR)) < 0) return -1;
12 if (dup2(fd, 0) < 0 || dup2(fd, 1) < 0 || dup2(fd, 2) < 0)
13 failed++;
14 if (fd > 2) close(fd);
15 if (failed) return -1;
16 }
17
18 switch(fork()) {
19 case 0: break;
20 case -1: return -1;
21 default: _exit(0);
22 }
23
24 if (setsid() < 0) return -1;
25
26 switch(fork()) {
27 case 0: break;
28 case -1: return -1;
29 default: _exit(0);
30 }
31
32 return 0;
33}
lib/libc/wasi/libc-top-half/musl/src/legacy/err.c deleted-67
......@@ -1,67 +0,0 @@
1#include <err.h>
2#include <stdio.h>
3#include <stdarg.h>
4#include <stdlib.h>
5
6extern char *__progname;
7
8void vwarn(const char *fmt, va_list ap)
9{
10 fprintf (stderr, "%s: ", __progname);
11 if (fmt) {
12 vfprintf(stderr, fmt, ap);
13 fputs (": ", stderr);
14 }
15 perror(0);
16}
17
18void vwarnx(const char *fmt, va_list ap)
19{
20 fprintf (stderr, "%s: ", __progname);
21 if (fmt) vfprintf(stderr, fmt, ap);
22 putc('\n', stderr);
23}
24
25_Noreturn void verr(int status, const char *fmt, va_list ap)
26{
27 vwarn(fmt, ap);
28 exit(status);
29}
30
31_Noreturn void verrx(int status, const char *fmt, va_list ap)
32{
33 vwarnx(fmt, ap);
34 exit(status);
35}
36
37void warn(const char *fmt, ...)
38{
39 va_list ap;
40 va_start(ap, fmt);
41 vwarn(fmt, ap);
42 va_end(ap);
43}
44
45void warnx(const char *fmt, ...)
46{
47 va_list ap;
48 va_start(ap, fmt);
49 vwarnx(fmt, ap);
50 va_end(ap);
51}
52
53_Noreturn void err(int status, const char *fmt, ...)
54{
55 va_list ap;
56 va_start(ap, fmt);
57 verr(status, fmt, ap);
58 va_end(ap);
59}
60
61_Noreturn void errx(int status, const char *fmt, ...)
62{
63 va_list ap;
64 va_start(ap, fmt);
65 verrx(status, fmt, ap);
66 va_end(ap);
67}
lib/libc/wasi/libc-top-half/musl/src/legacy/euidaccess.c deleted-10
......@@ -1,10 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include <fcntl.h>
4
5int euidaccess(const char *filename, int amode)
6{
7 return faccessat(AT_FDCWD, filename, amode, AT_EACCESS);
8}
9
10weak_alias(euidaccess, eaccess);
lib/libc/wasi/libc-top-half/musl/src/legacy/ftw.c deleted-11
......@@ -1,11 +0,0 @@
1#include <ftw.h>
2
3int ftw(const char *path, int (*fn)(const char *, const struct stat *, int), int fd_limit)
4{
5 /* The following cast assumes that calling a function with one
6 * argument more than it needs behaves as expected. This is
7 * actually undefined, but works on all real-world machines. */
8 return nftw(path, (int (*)())fn, fd_limit, FTW_PHYS);
9}
10
11weak_alias(ftw, ftw64);
lib/libc/wasi/libc-top-half/musl/src/legacy/futimes.c deleted-14
......@@ -1,14 +0,0 @@
1#define _GNU_SOURCE
2#include <sys/stat.h>
3#include <sys/time.h>
4
5int futimes(int fd, const struct timeval tv[2])
6{
7 struct timespec times[2];
8 if (!tv) return futimens(fd, 0);
9 times[0].tv_sec = tv[0].tv_sec;
10 times[0].tv_nsec = tv[0].tv_usec * 1000;
11 times[1].tv_sec = tv[1].tv_sec;
12 times[1].tv_nsec = tv[1].tv_usec * 1000;
13 return futimens(fd, times);
14}
lib/libc/wasi/libc-top-half/musl/src/legacy/getdtablesize.c deleted-11
......@@ -1,11 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include <limits.h>
4#include <sys/resource.h>
5
6int getdtablesize(void)
7{
8 struct rlimit rl;
9 getrlimit(RLIMIT_NOFILE, &rl);
10 return rl.rlim_cur < INT_MAX ? rl.rlim_cur : INT_MAX;
11}
lib/libc/wasi/libc-top-half/musl/src/legacy/getloadavg.c deleted-14
......@@ -1,14 +0,0 @@
1#define _GNU_SOURCE
2#include <stdlib.h>
3#include <sys/sysinfo.h>
4
5int getloadavg(double *a, int n)
6{
7 struct sysinfo si;
8 if (n <= 0) return n ? -1 : 0;
9 sysinfo(&si);
10 if (n > 3) n = 3;
11 for (int i=0; i<n; i++)
12 a[i] = 1.0/(1<<SI_LOAD_SHIFT) * si.loads[i];
13 return n;
14}
lib/libc/wasi/libc-top-half/musl/src/legacy/getpass.c deleted-40
......@@ -1,40 +0,0 @@
1#define _GNU_SOURCE
2#include <stdio.h>
3#include <termios.h>
4#include <unistd.h>
5#include <fcntl.h>
6#include <string.h>
7
8char *getpass(const char *prompt)
9{
10 int fd;
11 struct termios s, t;
12 ssize_t l;
13 static char password[128];
14
15 if ((fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_CLOEXEC)) < 0) return 0;
16
17 tcgetattr(fd, &t);
18 s = t;
19 t.c_lflag &= ~(ECHO|ISIG);
20 t.c_lflag |= ICANON;
21 t.c_iflag &= ~(INLCR|IGNCR);
22 t.c_iflag |= ICRNL;
23 tcsetattr(fd, TCSAFLUSH, &t);
24 tcdrain(fd);
25
26 dprintf(fd, "%s", prompt);
27
28 l = read(fd, password, sizeof password);
29 if (l >= 0) {
30 if (l > 0 && password[l-1] == '\n' || l==sizeof password) l--;
31 password[l] = 0;
32 }
33
34 tcsetattr(fd, TCSAFLUSH, &s);
35
36 dprintf(fd, "\n");
37 close(fd);
38
39 return l<0 ? 0 : password;
40}
lib/libc/wasi/libc-top-half/musl/src/legacy/getusershell.c deleted-32
......@@ -1,32 +0,0 @@
1#define _GNU_SOURCE
2#include <stdio.h>
3#include <unistd.h>
4
5static const char defshells[] = "/bin/sh\n/bin/csh\n";
6
7static char *line;
8static size_t linesize;
9static FILE *f;
10
11void endusershell(void)
12{
13 if (f) fclose(f);
14 f = 0;
15}
16
17void setusershell(void)
18{
19 if (!f) f = fopen("/etc/shells", "rbe");
20 if (!f) f = fmemopen((void *)defshells, sizeof defshells - 1, "rb");
21}
22
23char *getusershell(void)
24{
25 ssize_t l;
26 if (!f) setusershell();
27 if (!f) return 0;
28 l = getline(&line, &linesize, f);
29 if (l <= 0) return 0;
30 if (line[l-1]=='\n') line[l-1]=0;
31 return line;
32}
lib/libc/wasi/libc-top-half/musl/src/legacy/isastream.c deleted-7
......@@ -1,7 +0,0 @@
1#include <stropts.h>
2#include <fcntl.h>
3
4int isastream(int fd)
5{
6 return fcntl(fd, F_GETFD) < 0 ? -1 : 0;
7}
lib/libc/wasi/libc-top-half/musl/src/legacy/lutimes.c deleted-16
......@@ -1,16 +0,0 @@
1#define _GNU_SOURCE
2#include <sys/stat.h>
3#include <sys/time.h>
4#include <fcntl.h>
5
6int lutimes(const char *filename, const struct timeval tv[2])
7{
8 struct timespec times[2];
9 if (tv) {
10 times[0].tv_sec = tv[0].tv_sec;
11 times[0].tv_nsec = tv[0].tv_usec * 1000;
12 times[1].tv_sec = tv[1].tv_sec;
13 times[1].tv_nsec = tv[1].tv_usec * 1000;
14 }
15 return utimensat(AT_FDCWD, filename, tv ? times : 0, AT_SYMLINK_NOFOLLOW);
16}
lib/libc/wasi/libc-top-half/musl/src/legacy/ulimit.c deleted-19
......@@ -1,19 +0,0 @@
1#include <sys/resource.h>
2#include <ulimit.h>
3#include <stdarg.h>
4
5long ulimit(int cmd, ...)
6{
7 struct rlimit rl;
8 getrlimit(RLIMIT_FSIZE, &rl);
9 if (cmd == UL_SETFSIZE) {
10 long val;
11 va_list ap;
12 va_start(ap, cmd);
13 val = va_arg(ap, long);
14 va_end(ap);
15 rl.rlim_cur = 512ULL * val;
16 if (setrlimit(RLIMIT_FSIZE, &rl)) return -1;
17 }
18 return rl.rlim_cur / 512;
19}
lib/libc/wasi/libc-top-half/musl/src/legacy/utmpx.c deleted-52
......@@ -1,52 +0,0 @@
1#define _GNU_SOURCE
2#include <utmpx.h>
3#include <stddef.h>
4#include <errno.h>
5
6void endutxent(void)
7{
8}
9
10void setutxent(void)
11{
12}
13
14struct utmpx *getutxent(void)
15{
16 return NULL;
17}
18
19struct utmpx *getutxid(const struct utmpx *ut)
20{
21 return NULL;
22}
23
24struct utmpx *getutxline(const struct utmpx *ut)
25{
26 return NULL;
27}
28
29struct utmpx *pututxline(const struct utmpx *ut)
30{
31 return NULL;
32}
33
34void updwtmpx(const char *f, const struct utmpx *u)
35{
36}
37
38static int __utmpxname(const char *f)
39{
40 errno = ENOTSUP;
41 return -1;
42}
43
44weak_alias(endutxent, endutent);
45weak_alias(setutxent, setutent);
46weak_alias(getutxent, getutent);
47weak_alias(getutxid, getutid);
48weak_alias(getutxline, getutline);
49weak_alias(pututxline, pututline);
50weak_alias(updwtmpx, updwtmp);
51weak_alias(__utmpxname, utmpname);
52weak_alias(__utmpxname, utmpxname);
lib/libc/wasi/libc-top-half/musl/src/legacy/valloc.c deleted-8
......@@ -1,8 +0,0 @@
1#define _BSD_SOURCE
2#include <stdlib.h>
3#include "libc.h"
4
5void *valloc(size_t size)
6{
7 return memalign(PAGE_SIZE, size);
8}
lib/libc/wasi/libc-top-half/musl/src/linux/adjtime.c deleted-27
......@@ -1,27 +0,0 @@
1#define _GNU_SOURCE
2#include <sys/time.h>
3#include <sys/timex.h>
4#include <errno.h>
5#include "syscall.h"
6
7int adjtime(const struct timeval *in, struct timeval *out)
8{
9 struct timex tx = { 0 };
10 if (in) {
11 if (in->tv_sec > 1000 || in->tv_usec > 1000000000) {
12 errno = EINVAL;
13 return -1;
14 }
15 tx.offset = in->tv_sec*1000000 + in->tv_usec;
16 tx.modes = ADJ_OFFSET_SINGLESHOT;
17 }
18 if (adjtimex(&tx) < 0) return -1;
19 if (out) {
20 out->tv_sec = tx.offset / 1000000;
21 if ((out->tv_usec = tx.offset % 1000000) < 0) {
22 out->tv_sec--;
23 out->tv_usec += 1000000;
24 }
25 }
26 return 0;
27}
lib/libc/wasi/libc-top-half/musl/src/linux/adjtimex.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/timex.h>
2#include <time.h>
3
4int adjtimex(struct timex *tx)
5{
6 return clock_adjtime(CLOCK_REALTIME, tx);
7}
lib/libc/wasi/libc-top-half/musl/src/linux/arch_prctl.c deleted-7
......@@ -1,7 +0,0 @@
1#include "syscall.h"
2#ifdef SYS_arch_prctl
3int arch_prctl(int code, unsigned long addr)
4{
5 return syscall(SYS_arch_prctl, code, addr);
6}
7#endif
lib/libc/wasi/libc-top-half/musl/src/linux/brk.c deleted-9
......@@ -1,9 +0,0 @@
1#define _BSD_SOURCE
2#include <unistd.h>
3#include <errno.h>
4#include "syscall.h"
5
6int brk(void *end)
7{
8 return __syscall_ret(-ENOMEM);
9}
lib/libc/wasi/libc-top-half/musl/src/linux/cache.c deleted-50
......@@ -1,50 +0,0 @@
1#include <errno.h>
2#include "syscall.h"
3#include "atomic.h"
4
5#ifdef SYS_cacheflush
6int _flush_cache(void *addr, int len, int op)
7{
8 return syscall(SYS_cacheflush, addr, len, op);
9}
10weak_alias(_flush_cache, cacheflush);
11#endif
12
13#ifdef SYS_cachectl
14int __cachectl(void *addr, int len, int op)
15{
16 return syscall(SYS_cachectl, addr, len, op);
17}
18weak_alias(__cachectl, cachectl);
19#endif
20
21#ifdef SYS_riscv_flush_icache
22
23#define VDSO_FLUSH_ICACHE_SYM "__vdso_flush_icache"
24#define VDSO_FLUSH_ICACHE_VER "LINUX_4.5"
25
26static void *volatile vdso_func;
27
28static int flush_icache_init(void *start, void *end, unsigned long int flags)
29{
30 void *p = __vdsosym(VDSO_FLUSH_ICACHE_VER, VDSO_FLUSH_ICACHE_SYM);
31 int (*f)(void *, void *, unsigned long int) =
32 (int (*)(void *, void *, unsigned long int))p;
33 a_cas_p(&vdso_func, (void *)flush_icache_init, p);
34 return f ? f(start, end, flags) : -ENOSYS;
35}
36
37static void *volatile vdso_func = (void *)flush_icache_init;
38
39int __riscv_flush_icache(void *start, void *end, unsigned long int flags)
40{
41 int (*f)(void *, void *, unsigned long int) =
42 (int (*)(void *, void *, unsigned long int))vdso_func;
43 if (f) {
44 int r = f(start, end, flags);
45 if (!r) return r;
46 if (r != -ENOSYS) return __syscall_ret(r);
47 }
48}
49weak_alias(__riscv_flush_icache, riscv_flush_icache);
50#endif
lib/libc/wasi/libc-top-half/musl/src/linux/cap.c deleted-11
......@@ -1,11 +0,0 @@
1#include "syscall.h"
2
3int capset(void *a, void *b)
4{
5 return syscall(SYS_capset, a, b);
6}
7
8int capget(void *a, void *b)
9{
10 return syscall(SYS_capget, a, b);
11}
lib/libc/wasi/libc-top-half/musl/src/linux/chroot.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include "syscall.h"
4
5int chroot(const char *path)
6{
7 return syscall(SYS_chroot, path);
8}
lib/libc/wasi/libc-top-half/musl/src/linux/clock_adjtime.c deleted-151
......@@ -1,151 +0,0 @@
1#include <sys/timex.h>
2#include <time.h>
3#include <errno.h>
4#include "syscall.h"
5
6#define IS32BIT(x) !((x)+0x80000000ULL>>32)
7
8struct ktimex64 {
9 unsigned modes;
10 int :32;
11 long long offset, freq, maxerror, esterror;
12 int status;
13 int :32;
14 long long constant, precision, tolerance;
15 long long time_sec, time_usec;
16 long long tick, ppsfreq, jitter;
17 int shift;
18 int :32;
19 long long stabil, jitcnt, calcnt, errcnt, stbcnt;
20 int tai;
21 int __padding[11];
22};
23
24struct ktimex {
25 unsigned modes;
26 long offset, freq, maxerror, esterror;
27 int status;
28 long constant, precision, tolerance;
29 long time_sec, time_usec;
30 long tick, ppsfreq, jitter;
31 int shift;
32 long stabil, jitcnt, calcnt, errcnt, stbcnt;
33 int tai;
34 int __padding[11];
35};
36
37int clock_adjtime (clockid_t clock_id, struct timex *utx)
38{
39 int r = -ENOSYS;
40#ifdef SYS_clock_adjtime64
41 struct ktimex64 ktx = {
42 .modes = utx->modes,
43 .offset = utx->offset,
44 .freq = utx->freq,
45 .maxerror = utx->maxerror,
46 .esterror = utx->esterror,
47 .status = utx->status,
48 .constant = utx->constant,
49 .precision = utx->precision,
50 .tolerance = utx->tolerance,
51 .time_sec = utx->time.tv_sec,
52 .time_usec = utx->time.tv_usec,
53 .tick = utx->tick,
54 .ppsfreq = utx->ppsfreq,
55 .jitter = utx->jitter,
56 .shift = utx->shift,
57 .stabil = utx->stabil,
58 .jitcnt = utx->jitcnt,
59 .calcnt = utx->calcnt,
60 .errcnt = utx->errcnt,
61 .stbcnt = utx->stbcnt,
62 .tai = utx->tai,
63 };
64 r = __syscall(SYS_clock_adjtime64, clock_id, &ktx);
65 if (r>=0) {
66 utx->modes = ktx.modes;
67 utx->offset = ktx.offset;
68 utx->freq = ktx.freq;
69 utx->maxerror = ktx.maxerror;
70 utx->esterror = ktx.esterror;
71 utx->status = ktx.status;
72 utx->constant = ktx.constant;
73 utx->precision = ktx.precision;
74 utx->tolerance = ktx.tolerance;
75 utx->time.tv_sec = ktx.time_sec;
76 utx->time.tv_usec = ktx.time_usec;
77 utx->tick = ktx.tick;
78 utx->ppsfreq = ktx.ppsfreq;
79 utx->jitter = ktx.jitter;
80 utx->shift = ktx.shift;
81 utx->stabil = ktx.stabil;
82 utx->jitcnt = ktx.jitcnt;
83 utx->calcnt = ktx.calcnt;
84 utx->errcnt = ktx.errcnt;
85 utx->stbcnt = ktx.stbcnt;
86 utx->tai = ktx.tai;
87 }
88 if (SYS_clock_adjtime == SYS_clock_adjtime64 || r!=-ENOSYS)
89 return __syscall_ret(r);
90 if ((utx->modes & ADJ_SETOFFSET) && !IS32BIT(utx->time.tv_sec))
91 return __syscall_ret(-ENOTSUP);
92#endif
93 if (sizeof(time_t) > sizeof(long)) {
94 struct ktimex ktx = {
95 .modes = utx->modes,
96 .offset = utx->offset,
97 .freq = utx->freq,
98 .maxerror = utx->maxerror,
99 .esterror = utx->esterror,
100 .status = utx->status,
101 .constant = utx->constant,
102 .precision = utx->precision,
103 .tolerance = utx->tolerance,
104 .time_sec = utx->time.tv_sec,
105 .time_usec = utx->time.tv_usec,
106 .tick = utx->tick,
107 .ppsfreq = utx->ppsfreq,
108 .jitter = utx->jitter,
109 .shift = utx->shift,
110 .stabil = utx->stabil,
111 .jitcnt = utx->jitcnt,
112 .calcnt = utx->calcnt,
113 .errcnt = utx->errcnt,
114 .stbcnt = utx->stbcnt,
115 .tai = utx->tai,
116 };
117#ifdef SYS_adjtimex
118 if (clock_id==CLOCK_REALTIME) r = __syscall(SYS_adjtimex, &ktx);
119 else
120#endif
121 r = __syscall(SYS_clock_adjtime, clock_id, &ktx);
122 if (r>=0) {
123 utx->modes = ktx.modes;
124 utx->offset = ktx.offset;
125 utx->freq = ktx.freq;
126 utx->maxerror = ktx.maxerror;
127 utx->esterror = ktx.esterror;
128 utx->status = ktx.status;
129 utx->constant = ktx.constant;
130 utx->precision = ktx.precision;
131 utx->tolerance = ktx.tolerance;
132 utx->time.tv_sec = ktx.time_sec;
133 utx->time.tv_usec = ktx.time_usec;
134 utx->tick = ktx.tick;
135 utx->ppsfreq = ktx.ppsfreq;
136 utx->jitter = ktx.jitter;
137 utx->shift = ktx.shift;
138 utx->stabil = ktx.stabil;
139 utx->jitcnt = ktx.jitcnt;
140 utx->calcnt = ktx.calcnt;
141 utx->errcnt = ktx.errcnt;
142 utx->stbcnt = ktx.stbcnt;
143 utx->tai = ktx.tai;
144 }
145 return __syscall_ret(r);
146 }
147#ifdef SYS_adjtimex
148 if (clock_id==CLOCK_REALTIME) return syscall(SYS_adjtimex, utx);
149#endif
150 return syscall(SYS_clock_adjtime, clock_id, utx);
151}
lib/libc/wasi/libc-top-half/musl/src/linux/clone.c deleted-21
......@@ -1,21 +0,0 @@
1#define _GNU_SOURCE
2#include <stdarg.h>
3#include <unistd.h>
4#include <sched.h>
5#include "pthread_impl.h"
6#include "syscall.h"
7
8int clone(int (*func)(void *), void *stack, int flags, void *arg, ...)
9{
10 va_list ap;
11 pid_t *ptid, *ctid;
12 void *tls;
13
14 va_start(ap, arg);
15 ptid = va_arg(ap, pid_t *);
16 tls = va_arg(ap, void *);
17 ctid = va_arg(ap, pid_t *);
18 va_end(ap);
19
20 return __syscall_ret(__clone(func, stack, flags, arg, ptid, tls, ctid));
21}
lib/libc/wasi/libc-top-half/musl/src/linux/copy_file_range.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include "syscall.h"
4
5ssize_t copy_file_range(int fd_in, off_t *off_in, int fd_out, off_t *off_out, size_t len, unsigned flags)
6{
7 return syscall(SYS_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags);
8}
lib/libc/wasi/libc-top-half/musl/src/linux/epoll.c deleted-37
......@@ -1,37 +0,0 @@
1#include <sys/epoll.h>
2#include <signal.h>
3#include <errno.h>
4#include "syscall.h"
5
6int epoll_create(int size)
7{
8 return epoll_create1(0);
9}
10
11int epoll_create1(int flags)
12{
13 int r = __syscall(SYS_epoll_create1, flags);
14#ifdef SYS_epoll_create
15 if (r==-ENOSYS && !flags) r = __syscall(SYS_epoll_create, 1);
16#endif
17 return __syscall_ret(r);
18}
19
20int epoll_ctl(int fd, int op, int fd2, struct epoll_event *ev)
21{
22 return syscall(SYS_epoll_ctl, fd, op, fd2, ev);
23}
24
25int epoll_pwait(int fd, struct epoll_event *ev, int cnt, int to, const sigset_t *sigs)
26{
27 int r = __syscall_cp(SYS_epoll_pwait, fd, ev, cnt, to, sigs, _NSIG/8);
28#ifdef SYS_epoll_wait
29 if (r==-ENOSYS && !sigs) r = __syscall_cp(SYS_epoll_wait, fd, ev, cnt, to);
30#endif
31 return __syscall_ret(r);
32}
33
34int epoll_wait(int fd, struct epoll_event *ev, int cnt, int to)
35{
36 return epoll_pwait(fd, ev, cnt, to, 0);
37}
lib/libc/wasi/libc-top-half/musl/src/linux/eventfd.c deleted-23
......@@ -1,23 +0,0 @@
1#include <sys/eventfd.h>
2#include <unistd.h>
3#include <errno.h>
4#include "syscall.h"
5
6int eventfd(unsigned int count, int flags)
7{
8 int r = __syscall(SYS_eventfd2, count, flags);
9#ifdef SYS_eventfd
10 if (r==-ENOSYS && !flags) r = __syscall(SYS_eventfd, count);
11#endif
12 return __syscall_ret(r);
13}
14
15int eventfd_read(int fd, eventfd_t *value)
16{
17 return (sizeof(*value) == read(fd, value, sizeof(*value))) ? 0 : -1;
18}
19
20int eventfd_write(int fd, eventfd_t value)
21{
22 return (sizeof(value) == write(fd, &value, sizeof(value))) ? 0 : -1;
23}
lib/libc/wasi/libc-top-half/musl/src/linux/fallocate.c deleted-12
......@@ -1,12 +0,0 @@
1#define _GNU_SOURCE
2#include <fcntl.h>
3#include "syscall.h"
4
5int fallocate(int fd, int mode, off_t base, off_t len)
6{
7 return syscall(SYS_fallocate, fd, mode, __SYSCALL_LL_E(base),
8 __SYSCALL_LL_E(len));
9}
10
11#undef fallocate64
12weak_alias(fallocate, fallocate64);
lib/libc/wasi/libc-top-half/musl/src/linux/fanotify.c deleted-14
......@@ -1,14 +0,0 @@
1#include "syscall.h"
2#include <sys/fanotify.h>
3
4int fanotify_init(unsigned flags, unsigned event_f_flags)
5{
6 return syscall(SYS_fanotify_init, flags, event_f_flags);
7}
8
9int fanotify_mark(int fanotify_fd, unsigned flags, unsigned long long mask,
10 int dfd, const char *pathname)
11{
12 return syscall(SYS_fanotify_mark, fanotify_fd, flags, __SYSCALL_LL_E(mask), dfd, pathname);
13}
14
lib/libc/wasi/libc-top-half/musl/src/linux/flock.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/file.h>
2#include "syscall.h"
3
4int flock(int fd, int op)
5{
6 return syscall(SYS_flock, fd, op);
7}
lib/libc/wasi/libc-top-half/musl/src/linux/getdents.c deleted-12
......@@ -1,12 +0,0 @@
1#define _BSD_SOURCE
2#include <dirent.h>
3#include <limits.h>
4#include "syscall.h"
5
6int getdents(int fd, struct dirent *buf, size_t len)
7{
8 if (len>INT_MAX) len = INT_MAX;
9 return syscall(SYS_getdents, fd, buf, len);
10}
11
12weak_alias(getdents, getdents64);
lib/libc/wasi/libc-top-half/musl/src/linux/getrandom.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/random.h>
2#include "syscall.h"
3
4ssize_t getrandom(void *buf, size_t buflen, unsigned flags)
5{
6 return syscall_cp(SYS_getrandom, buf, buflen, flags);
7}
lib/libc/wasi/libc-top-half/musl/src/linux/gettid.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include "pthread_impl.h"
4
5pid_t gettid(void)
6{
7 return __pthread_self()->tid;
8}
lib/libc/wasi/libc-top-half/musl/src/linux/inotify.c deleted-26
......@@ -1,26 +0,0 @@
1#include <sys/inotify.h>
2#include <errno.h>
3#include "syscall.h"
4
5int inotify_init()
6{
7 return inotify_init1(0);
8}
9int inotify_init1(int flags)
10{
11 int r = __syscall(SYS_inotify_init1, flags);
12#ifdef SYS_inotify_init
13 if (r==-ENOSYS && !flags) r = __syscall(SYS_inotify_init);
14#endif
15 return __syscall_ret(r);
16}
17
18int inotify_add_watch(int fd, const char *pathname, uint32_t mask)
19{
20 return syscall(SYS_inotify_add_watch, fd, pathname, mask);
21}
22
23int inotify_rm_watch(int fd, int wd)
24{
25 return syscall(SYS_inotify_rm_watch, fd, wd);
26}
lib/libc/wasi/libc-top-half/musl/src/linux/ioperm.c deleted-10
......@@ -1,10 +0,0 @@
1#include "syscall.h"
2
3#ifdef SYS_ioperm
4#include <sys/io.h>
5
6int ioperm(unsigned long from, unsigned long num, int turn_on)
7{
8 return syscall(SYS_ioperm, from, num, turn_on);
9}
10#endif
lib/libc/wasi/libc-top-half/musl/src/linux/iopl.c deleted-10
......@@ -1,10 +0,0 @@
1#include "syscall.h"
2
3#ifdef SYS_iopl
4#include <sys/io.h>
5
6int iopl(int level)
7{
8 return syscall(SYS_iopl, level);
9}
10#endif
lib/libc/wasi/libc-top-half/musl/src/linux/klogctl.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/klog.h>
2#include "syscall.h"
3
4int klogctl (int type, char *buf, int len)
5{
6 return syscall(SYS_syslog, type, buf, len);
7}
lib/libc/wasi/libc-top-half/musl/src/linux/membarrier.c deleted-72
......@@ -1,72 +0,0 @@
1#include <sys/membarrier.h>
2#include <semaphore.h>
3#include <signal.h>
4#include <string.h>
5#include "pthread_impl.h"
6#include "syscall.h"
7
8static void dummy_0(void)
9{
10}
11
12weak_alias(dummy_0, __tl_lock);
13weak_alias(dummy_0, __tl_unlock);
14
15static sem_t barrier_sem;
16
17static void bcast_barrier(int s)
18{
19 sem_post(&barrier_sem);
20}
21
22int __membarrier(int cmd, int flags)
23{
24 int r = __syscall(SYS_membarrier, cmd, flags);
25 /* Emulate the private expedited command, which is needed by the
26 * dynamic linker for installation of dynamic TLS, for older
27 * kernels that lack the syscall. Unlike the syscall, this only
28 * synchronizes with threads of the process, not other processes
29 * sharing the VM, but such sharing is not a supported usage
30 * anyway. */
31 if (r && cmd == MEMBARRIER_CMD_PRIVATE_EXPEDITED && !flags) {
32 pthread_t self=__pthread_self(), td;
33 sigset_t set;
34 __block_app_sigs(&set);
35 __tl_lock();
36 sem_init(&barrier_sem, 0, 0);
37 struct sigaction sa = {
38 .sa_flags = SA_RESTART,
39 .sa_handler = bcast_barrier
40 };
41 memset(&sa.sa_mask, -1, sizeof sa.sa_mask);
42 if (!__libc_sigaction(SIGSYNCCALL, &sa, 0)) {
43 for (td=self->next; td!=self; td=td->next)
44 __syscall(SYS_tkill, td->tid, SIGSYNCCALL);
45 for (td=self->next; td!=self; td=td->next)
46 sem_wait(&barrier_sem);
47 r = 0;
48 sa.sa_handler = SIG_IGN;
49 __libc_sigaction(SIGSYNCCALL, &sa, 0);
50 }
51 sem_destroy(&barrier_sem);
52 __tl_unlock();
53 __restore_sigs(&set);
54 }
55 return __syscall_ret(r);
56}
57
58void __membarrier_init(void)
59{
60 /* If membarrier is linked, attempt to pre-register to be able to use
61 * the private expedited command before the process becomes multi-
62 * threaded, since registering later has bad, potentially unbounded
63 * latency. This syscall should be essentially free, and it's arguably
64 * a mistake in the API design that registration was even required.
65 * For other commands, registration may impose some cost, so it's left
66 * to the application to do so if desired. Unfortunately this means
67 * library code initialized after the process becomes multi-threaded
68 * cannot use these features without accepting registration latency. */
69 __syscall(SYS_membarrier, MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED, 0);
70}
71
72weak_alias(__membarrier, membarrier);
lib/libc/wasi/libc-top-half/musl/src/linux/memfd_create.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE 1
2#include <sys/mman.h>
3#include "syscall.h"
4
5int memfd_create(const char *name, unsigned flags)
6{
7 return syscall(SYS_memfd_create, name, flags);
8}
lib/libc/wasi/libc-top-half/musl/src/linux/mlock2.c deleted-10
......@@ -1,10 +0,0 @@
1#define _GNU_SOURCE 1
2#include <sys/mman.h>
3#include "syscall.h"
4
5int mlock2(const void *addr, size_t len, unsigned flags)
6{
7 if (flags == 0)
8 return mlock(addr, len);
9 return syscall(SYS_mlock2, addr, len, flags);
10}
lib/libc/wasi/libc-top-half/musl/src/linux/module.c deleted-11
......@@ -1,11 +0,0 @@
1#include "syscall.h"
2
3int init_module(void *a, unsigned long b, const char *c)
4{
5 return syscall(SYS_init_module, a, b, c);
6}
7
8int delete_module(const char *a, unsigned b)
9{
10 return syscall(SYS_delete_module, a, b);
11}
lib/libc/wasi/libc-top-half/musl/src/linux/mount.c deleted-17
......@@ -1,17 +0,0 @@
1#include <sys/mount.h>
2#include "syscall.h"
3
4int mount(const char *special, const char *dir, const char *fstype, unsigned long flags, const void *data)
5{
6 return syscall(SYS_mount, special, dir, fstype, flags, data);
7}
8
9int umount(const char *special)
10{
11 return syscall(SYS_umount2, special, 0);
12}
13
14int umount2(const char *special, int flags)
15{
16 return syscall(SYS_umount2, special, flags);
17}
lib/libc/wasi/libc-top-half/musl/src/linux/name_to_handle_at.c deleted-10
......@@ -1,10 +0,0 @@
1#define _GNU_SOURCE
2#include <fcntl.h>
3#include "syscall.h"
4
5int name_to_handle_at(int dirfd, const char *pathname,
6 struct file_handle *handle, int *mount_id, int flags)
7{
8 return syscall(SYS_name_to_handle_at, dirfd,
9 pathname, handle, mount_id, flags);
10}
lib/libc/wasi/libc-top-half/musl/src/linux/open_by_handle_at.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <fcntl.h>
3#include "syscall.h"
4
5int open_by_handle_at(int mount_fd, struct file_handle *handle, int flags)
6{
7 return syscall(SYS_open_by_handle_at, mount_fd, handle, flags);
8}
lib/libc/wasi/libc-top-half/musl/src/linux/personality.c deleted-8
......@@ -1,8 +0,0 @@
1#include <sys/personality.h>
2#include "syscall.h"
3#ifdef SYS_personality
4int personality(unsigned long persona)
5{
6 return syscall(SYS_personality, persona);
7}
8#endif
lib/libc/wasi/libc-top-half/musl/src/linux/pivot_root.c deleted-6
......@@ -1,6 +0,0 @@
1#include "syscall.h"
2
3int pivot_root(const char *new, const char *old)
4{
5 return syscall(SYS_pivot_root, new, old);
6}
lib/libc/wasi/libc-top-half/musl/src/linux/ppoll.c deleted-26
......@@ -1,26 +0,0 @@
1#define _GNU_SOURCE
2#include <poll.h>
3#include <signal.h>
4#include <errno.h>
5#include "syscall.h"
6
7#define IS32BIT(x) !((x)+0x80000000ULL>>32)
8#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
9
10int ppoll(struct pollfd *fds, nfds_t n, const struct timespec *to, const sigset_t *mask)
11{
12 time_t s = to ? to->tv_sec : 0;
13 long ns = to ? to->tv_nsec : 0;
14#ifdef SYS_ppoll_time64
15 int r = -ENOSYS;
16 if (SYS_ppoll == SYS_ppoll_time64 || !IS32BIT(s))
17 r = __syscall_cp(SYS_ppoll_time64, fds, n,
18 to ? ((long long[]){s, ns}) : 0,
19 mask, _NSIG/8);
20 if (SYS_ppoll == SYS_ppoll_time64 || r != -ENOSYS)
21 return __syscall_ret(r);
22 s = CLAMP(s);
23#endif
24 return syscall_cp(SYS_ppoll, fds, n,
25 to ? ((long[]){s, ns}) : 0, mask, _NSIG/8);
26}
lib/libc/wasi/libc-top-half/musl/src/linux/prctl.c deleted-14
......@@ -1,14 +0,0 @@
1#include <sys/prctl.h>
2#include <stdarg.h>
3#include "syscall.h"
4
5int prctl(int op, ...)
6{
7 unsigned long x[4];
8 int i;
9 va_list ap;
10 va_start(ap, op);
11 for (i=0; i<4; i++) x[i] = va_arg(ap, unsigned long);
12 va_end(ap);
13 return syscall(SYS_prctl, op, x[0], x[1], x[2], x[3]);
14}
lib/libc/wasi/libc-top-half/musl/src/linux/prlimit.c deleted-26
......@@ -1,26 +0,0 @@
1#define _GNU_SOURCE
2#include <sys/resource.h>
3#include "syscall.h"
4
5#define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0)
6
7int prlimit(pid_t pid, int resource, const struct rlimit *new_limit, struct rlimit *old_limit)
8{
9 struct rlimit tmp;
10 int r;
11 if (new_limit && SYSCALL_RLIM_INFINITY != RLIM_INFINITY) {
12 tmp = *new_limit;
13 FIX(tmp.rlim_cur);
14 FIX(tmp.rlim_max);
15 new_limit = &tmp;
16 }
17 r = syscall(SYS_prlimit64, pid, resource, new_limit, old_limit);
18 if (!r && old_limit && SYSCALL_RLIM_INFINITY != RLIM_INFINITY) {
19 FIX(old_limit->rlim_cur);
20 FIX(old_limit->rlim_max);
21 }
22 return r;
23}
24
25#undef prlimit64
26weak_alias(prlimit, prlimit64);
lib/libc/wasi/libc-top-half/musl/src/linux/process_vm.c deleted-13
......@@ -1,13 +0,0 @@
1#define _GNU_SOURCE
2#include <sys/uio.h>
3#include "syscall.h"
4
5ssize_t process_vm_writev(pid_t pid, const struct iovec *lvec, unsigned long liovcnt, const struct iovec *rvec, unsigned long riovcnt, unsigned long flags)
6{
7 return syscall(SYS_process_vm_writev, pid, lvec, liovcnt, rvec, riovcnt, flags);
8}
9
10ssize_t process_vm_readv(pid_t pid, const struct iovec *lvec, unsigned long liovcnt, const struct iovec *rvec, unsigned long riovcnt, unsigned long flags)
11{
12 return syscall(SYS_process_vm_readv, pid, lvec, liovcnt, rvec, riovcnt, flags);
13}
lib/libc/wasi/libc-top-half/musl/src/linux/ptrace.c deleted-29
......@@ -1,29 +0,0 @@
1#include <sys/ptrace.h>
2#include <stdarg.h>
3#include <unistd.h>
4#include "syscall.h"
5
6long ptrace(int req, ...)
7{
8 va_list ap;
9 pid_t pid;
10 void *addr, *data, *addr2 = 0;
11 long ret, result;
12
13 va_start(ap, req);
14 pid = va_arg(ap, pid_t);
15 addr = va_arg(ap, void *);
16 data = va_arg(ap, void *);
17 /* PTRACE_{READ,WRITE}{DATA,TEXT} (16...19) are specific to SPARC. */
18#ifdef PTRACE_READDATA
19 if ((unsigned)req - PTRACE_READDATA < 4)
20 addr2 = va_arg(ap, void *);
21#endif
22 va_end(ap);
23
24 if (req-1U < 3) data = &result;
25 ret = syscall(SYS_ptrace, req, pid, addr, data, addr2);
26
27 if (ret < 0 || req-1U >= 3) return ret;
28 return result;
29}
lib/libc/wasi/libc-top-half/musl/src/linux/quotactl.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/quota.h>
2#include "syscall.h"
3
4int quotactl(int cmd, const char *special, int id, char *addr)
5{
6 return syscall(SYS_quotactl, cmd, special, id, addr);
7}
lib/libc/wasi/libc-top-half/musl/src/linux/readahead.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <fcntl.h>
3#include "syscall.h"
4
5ssize_t readahead(int fd, off_t pos, size_t len)
6{
7 return syscall(SYS_readahead, fd, __SYSCALL_LL_O(pos), len);
8}
lib/libc/wasi/libc-top-half/musl/src/linux/reboot.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/reboot.h>
2#include "syscall.h"
3
4int reboot(int type)
5{
6 return syscall(SYS_reboot, 0xfee1dead, 672274793, type);
7}
lib/libc/wasi/libc-top-half/musl/src/linux/remap_file_pages.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <sys/mman.h>
3#include "syscall.h"
4
5int remap_file_pages(void *addr, size_t size, int prot, size_t pgoff, int flags)
6{
7 return syscall(SYS_remap_file_pages, addr, size, prot, pgoff, flags);
8}
lib/libc/wasi/libc-top-half/musl/src/linux/sbrk.c deleted-11
......@@ -1,11 +0,0 @@
1#define _BSD_SOURCE
2#include <unistd.h>
3#include <stdint.h>
4#include <errno.h>
5#include "syscall.h"
6
7void *sbrk(intptr_t inc)
8{
9 if (inc) return (void *)__syscall_ret(-ENOMEM);
10 return (void *)__syscall(SYS_brk, 0);
11}
lib/libc/wasi/libc-top-half/musl/src/linux/sendfile.c deleted-9
......@@ -1,9 +0,0 @@
1#include <sys/sendfile.h>
2#include "syscall.h"
3
4ssize_t sendfile(int out_fd, int in_fd, off_t *ofs, size_t count)
5{
6 return syscall(SYS_sendfile, out_fd, in_fd, ofs, count);
7}
8
9weak_alias(sendfile, sendfile64);
lib/libc/wasi/libc-top-half/musl/src/linux/setfsgid.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/fsuid.h>
2#include "syscall.h"
3
4int setfsgid(gid_t gid)
5{
6 return syscall(SYS_setfsgid, gid);
7}
lib/libc/wasi/libc-top-half/musl/src/linux/setfsuid.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/fsuid.h>
2#include "syscall.h"
3
4int setfsuid(uid_t uid)
5{
6 return syscall(SYS_setfsuid, uid);
7}
lib/libc/wasi/libc-top-half/musl/src/linux/setgroups.c deleted-36
......@@ -1,36 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include <signal.h>
4#include "syscall.h"
5#include "libc.h"
6
7struct ctx {
8 size_t count;
9 const gid_t *list;
10 int ret;
11};
12
13static void do_setgroups(void *p)
14{
15 struct ctx *c = p;
16 if (c->ret<0) return;
17 int ret = __syscall(SYS_setgroups, c->count, c->list);
18 if (ret && !c->ret) {
19 /* If one thread fails to set groups after another has already
20 * succeeded, forcibly killing the process is the only safe
21 * thing to do. State is inconsistent and dangerous. Use
22 * SIGKILL because it is uncatchable. */
23 __block_all_sigs(0);
24 __syscall(SYS_kill, __syscall(SYS_getpid), SIGKILL);
25 }
26 c->ret = ret;
27}
28
29int setgroups(size_t count, const gid_t list[])
30{
31 /* ret is initially nonzero so that failure of the first thread does not
32 * trigger the safety kill above. */
33 struct ctx c = { .count = count, .list = list, .ret = 1 };
34 __synccall(do_setgroups, &c);
35 return __syscall_ret(c.ret);
36}
lib/libc/wasi/libc-top-half/musl/src/linux/sethostname.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include "syscall.h"
4
5int sethostname(const char *name, size_t len)
6{
7 return syscall(SYS_sethostname, name, len);
8}
lib/libc/wasi/libc-top-half/musl/src/linux/setns.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <sched.h>
3#include "syscall.h"
4
5int setns(int fd, int nstype)
6{
7 return syscall(SYS_setns, fd, nstype);
8}
lib/libc/wasi/libc-top-half/musl/src/linux/settimeofday.c deleted-13
......@@ -1,13 +0,0 @@
1#define _BSD_SOURCE
2#include <sys/time.h>
3#include <time.h>
4#include <errno.h>
5#include "syscall.h"
6
7int settimeofday(const struct timeval *tv, const struct timezone *tz)
8{
9 if (!tv) return 0;
10 if (tv->tv_usec >= 1000000ULL) return __syscall_ret(-EINVAL);
11 return clock_settime(CLOCK_REALTIME, &((struct timespec){
12 .tv_sec = tv->tv_sec, .tv_nsec = tv->tv_usec * 1000}));
13}
lib/libc/wasi/libc-top-half/musl/src/linux/signalfd.c deleted-21
......@@ -1,21 +0,0 @@
1#include <sys/signalfd.h>
2#include <signal.h>
3#include <errno.h>
4#include <fcntl.h>
5#include "syscall.h"
6
7int signalfd(int fd, const sigset_t *sigs, int flags)
8{
9 int ret = __syscall(SYS_signalfd4, fd, sigs, _NSIG/8, flags);
10#ifdef SYS_signalfd
11 if (ret != -ENOSYS) return __syscall_ret(ret);
12 ret = __syscall(SYS_signalfd, fd, sigs, _NSIG/8);
13 if (ret >= 0) {
14 if (flags & SFD_CLOEXEC)
15 __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC);
16 if (flags & SFD_NONBLOCK)
17 __syscall(SYS_fcntl, ret, F_SETFL, O_NONBLOCK);
18 }
19#endif
20 return __syscall_ret(ret);
21}
lib/libc/wasi/libc-top-half/musl/src/linux/splice.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <fcntl.h>
3#include "syscall.h"
4
5ssize_t splice(int fd_in, off_t *off_in, int fd_out, off_t *off_out, size_t len, unsigned flags)
6{
7 return syscall(SYS_splice, fd_in, off_in, fd_out, off_out, len, flags);
8}
lib/libc/wasi/libc-top-half/musl/src/linux/stime.c deleted-9
......@@ -1,9 +0,0 @@
1#define _GNU_SOURCE
2#include <time.h>
3#include <sys/time.h>
4
5int stime(const time_t *t)
6{
7 struct timeval tv = { .tv_sec = *t, .tv_usec = 0 };
8 return settimeofday(&tv, (void *)0);
9}
lib/libc/wasi/libc-top-half/musl/src/linux/swap.c deleted-12
......@@ -1,12 +0,0 @@
1#include <sys/swap.h>
2#include "syscall.h"
3
4int swapon(const char *path, int flags)
5{
6 return syscall(SYS_swapon, path, flags);
7}
8
9int swapoff(const char *path)
10{
11 return syscall(SYS_swapoff, path);
12}
lib/libc/wasi/libc-top-half/musl/src/linux/sync_file_range.c deleted-17
......@@ -1,17 +0,0 @@
1#define _GNU_SOURCE
2#include <fcntl.h>
3#include <errno.h>
4#include "syscall.h"
5
6int sync_file_range(int fd, off_t pos, off_t len, unsigned flags)
7{
8#if defined(SYS_sync_file_range2)
9 return syscall(SYS_sync_file_range2, fd, flags,
10 __SYSCALL_LL_E(pos), __SYSCALL_LL_E(len));
11#elif defined(SYS_sync_file_range)
12 return syscall(SYS_sync_file_range, fd,
13 __SYSCALL_LL_O(pos), __SYSCALL_LL_E(len), flags);
14#else
15 return __syscall_ret(-ENOSYS);
16#endif
17}
lib/libc/wasi/libc-top-half/musl/src/linux/syncfs.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include "syscall.h"
4
5int syncfs(int fd)
6{
7 return syscall(SYS_syncfs, fd);
8}
lib/libc/wasi/libc-top-half/musl/src/linux/sysinfo.c deleted-9
......@@ -1,9 +0,0 @@
1#include <sys/sysinfo.h>
2#include "syscall.h"
3
4int __lsysinfo(struct sysinfo *info)
5{
6 return syscall(SYS_sysinfo, info);
7}
8
9weak_alias(__lsysinfo, sysinfo);
lib/libc/wasi/libc-top-half/musl/src/linux/tee.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <fcntl.h>
3#include "syscall.h"
4
5ssize_t tee(int src, int dest, size_t len, unsigned flags)
6{
7 return syscall(SYS_tee, src, dest, len, flags);
8}
lib/libc/wasi/libc-top-half/musl/src/linux/timerfd.c deleted-59
......@@ -1,59 +0,0 @@
1#include <sys/timerfd.h>
2#include <errno.h>
3#include "syscall.h"
4
5#define IS32BIT(x) !((x)+0x80000000ULL>>32)
6
7int timerfd_create(int clockid, int flags)
8{
9 return syscall(SYS_timerfd_create, clockid, flags);
10}
11
12int timerfd_settime(int fd, int flags, const struct itimerspec *new, struct itimerspec *old)
13{
14#ifdef SYS_timerfd_settime64
15 time_t is = new->it_interval.tv_sec, vs = new->it_value.tv_sec;
16 long ins = new->it_interval.tv_nsec, vns = new->it_value.tv_nsec;
17 int r = -ENOSYS;
18 if (SYS_timerfd_settime == SYS_timerfd_settime64
19 || !IS32BIT(is) || !IS32BIT(vs) || (sizeof(time_t)>4 && old))
20 r = __syscall(SYS_timerfd_settime64, fd, flags,
21 ((long long[]){is, ins, vs, vns}), old);
22 if (SYS_timerfd_settime == SYS_timerfd_settime64 || r!=-ENOSYS)
23 return __syscall_ret(r);
24 if (!IS32BIT(is) || !IS32BIT(vs))
25 return __syscall_ret(-ENOTSUP);
26 long old32[4];
27 r = __syscall(SYS_timerfd_settime, fd, flags,
28 ((long[]){is, ins, vs, vns}), old32);
29 if (!r && old) {
30 old->it_interval.tv_sec = old32[0];
31 old->it_interval.tv_nsec = old32[1];
32 old->it_value.tv_sec = old32[2];
33 old->it_value.tv_nsec = old32[3];
34 }
35 return __syscall_ret(r);
36#endif
37 return syscall(SYS_timerfd_settime, fd, flags, new, old);
38}
39
40int timerfd_gettime(int fd, struct itimerspec *cur)
41{
42#ifdef SYS_timerfd_gettime64
43 int r = -ENOSYS;
44 if (sizeof(time_t) > 4)
45 r = __syscall(SYS_timerfd_gettime64, fd, cur);
46 if (SYS_timerfd_gettime == SYS_timerfd_gettime64 || r!=-ENOSYS)
47 return __syscall_ret(r);
48 long cur32[4];
49 r = __syscall(SYS_timerfd_gettime, fd, cur32);
50 if (!r) {
51 cur->it_interval.tv_sec = cur32[0];
52 cur->it_interval.tv_nsec = cur32[1];
53 cur->it_value.tv_sec = cur32[2];
54 cur->it_value.tv_nsec = cur32[3];
55 }
56 return __syscall_ret(r);
57#endif
58 return syscall(SYS_timerfd_gettime, fd, cur);
59}
lib/libc/wasi/libc-top-half/musl/src/linux/unshare.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <sched.h>
3#include "syscall.h"
4
5int unshare(int flags)
6{
7 return syscall(SYS_unshare, flags);
8}
lib/libc/wasi/libc-top-half/musl/src/linux/utimes.c deleted-8
......@@ -1,8 +0,0 @@
1#include <sys/time.h>
2#include "fcntl.h"
3#include "syscall.h"
4
5int utimes(const char *path, const struct timeval times[2])
6{
7 return __futimesat(AT_FDCWD, path, times);
8}
lib/libc/wasi/libc-top-half/musl/src/linux/vhangup.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include "syscall.h"
4
5int vhangup(void)
6{
7 return syscall(SYS_vhangup);
8}
lib/libc/wasi/libc-top-half/musl/src/linux/vmsplice.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <fcntl.h>
3#include "syscall.h"
4
5ssize_t vmsplice(int fd, const struct iovec *iov, size_t cnt, unsigned flags)
6{
7 return syscall(SYS_vmsplice, fd, iov, cnt, flags);
8}
lib/libc/wasi/libc-top-half/musl/src/linux/wait3.c deleted-9
......@@ -1,9 +0,0 @@
1#define _GNU_SOURCE
2#include <sys/wait.h>
3#include <sys/resource.h>
4#include "syscall.h"
5
6pid_t wait3(int *status, int options, struct rusage *usage)
7{
8 return wait4(-1, status, options, usage);
9}
lib/libc/wasi/libc-top-half/musl/src/linux/wait4.c deleted-39
......@@ -1,39 +0,0 @@
1#define _GNU_SOURCE
2#include <sys/wait.h>
3#include <sys/resource.h>
4#include <string.h>
5#include <errno.h>
6#include "syscall.h"
7
8pid_t wait4(pid_t pid, int *status, int options, struct rusage *ru)
9{
10 int r;
11#ifdef SYS_wait4_time64
12 if (ru) {
13 long long kru64[18];
14 r = __syscall(SYS_wait4_time64, pid, status, options, kru64);
15 if (!r) {
16 ru->ru_utime = (struct timeval)
17 { .tv_sec = kru64[0], .tv_usec = kru64[1] };
18 ru->ru_stime = (struct timeval)
19 { .tv_sec = kru64[2], .tv_usec = kru64[3] };
20 char *slots = (char *)&ru->ru_maxrss;
21 for (int i=0; i<14; i++)
22 *(long *)(slots + i*sizeof(long)) = kru64[4+i];
23 }
24 if (SYS_wait4_time64 == SYS_wait4 || r != -ENOSYS)
25 return __syscall_ret(r);
26 }
27#endif
28 char *dest = ru ? (char *)&ru->ru_maxrss - 4*sizeof(long) : 0;
29 r = __syscall(SYS_wait4, pid, status, options, dest);
30 if (r>0 && ru && sizeof(time_t) > sizeof(long)) {
31 long kru[4];
32 memcpy(kru, dest, 4*sizeof(long));
33 ru->ru_utime = (struct timeval)
34 { .tv_sec = kru[0], .tv_usec = kru[1] };
35 ru->ru_stime = (struct timeval)
36 { .tv_sec = kru[2], .tv_usec = kru[3] };
37 }
38 return __syscall_ret(r);
39}
lib/libc/wasi/libc-top-half/musl/src/linux/x32/sysinfo.c deleted-49
......@@ -1,49 +0,0 @@
1#include <sys/sysinfo.h>
2#include "syscall.h"
3
4#define klong long long
5#define kulong unsigned long long
6
7struct kernel_sysinfo {
8 klong uptime;
9 kulong loads[3];
10 kulong totalram;
11 kulong freeram;
12 kulong sharedram;
13 kulong bufferram;
14 kulong totalswap;
15 kulong freeswap;
16 short procs;
17 short pad;
18 kulong totalhigh;
19 kulong freehigh;
20 unsigned mem_unit;
21};
22
23int __lsysinfo(struct sysinfo *info)
24{
25 struct kernel_sysinfo tmp;
26 int ret = syscall(SYS_sysinfo, &tmp);
27 if(ret == -1) return ret;
28 info->uptime = tmp.uptime;
29 info->loads[0] = tmp.loads[0];
30 info->loads[1] = tmp.loads[1];
31 info->loads[2] = tmp.loads[2];
32 kulong shifts;
33 kulong max = tmp.totalram | tmp.totalswap;
34 __asm__("bsr %1,%0" : "=r"(shifts) : "r"(max));
35 shifts = shifts >= 32 ? shifts - 31 : 0;
36 info->totalram = tmp.totalram >> shifts;
37 info->freeram = tmp.freeram >> shifts;
38 info->sharedram = tmp.sharedram >> shifts;
39 info->bufferram = tmp.bufferram >> shifts;
40 info->totalswap = tmp.totalswap >> shifts;
41 info->freeswap = tmp.freeswap >> shifts;
42 info->procs = tmp.procs ;
43 info->totalhigh = tmp.totalhigh >> shifts;
44 info->freehigh = tmp.freehigh >> shifts;
45 info->mem_unit = (tmp.mem_unit ? tmp.mem_unit : 1) << shifts;
46 return ret;
47}
48
49weak_alias(__lsysinfo, sysinfo);
lib/libc/wasi/libc-top-half/musl/src/linux/xattr.c deleted-62
......@@ -1,62 +0,0 @@
1#include <sys/xattr.h>
2#include "syscall.h"
3
4ssize_t getxattr(const char *path, const char *name, void *value, size_t size)
5{
6 return syscall(SYS_getxattr, path, name, value, size);
7}
8
9ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size)
10{
11 return syscall(SYS_lgetxattr, path, name, value, size);
12}
13
14ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size)
15{
16 return syscall(SYS_fgetxattr, filedes, name, value, size);
17}
18
19ssize_t listxattr(const char *path, char *list, size_t size)
20{
21 return syscall(SYS_listxattr, path, list, size);
22}
23
24ssize_t llistxattr(const char *path, char *list, size_t size)
25{
26 return syscall(SYS_llistxattr, path, list, size);
27}
28
29ssize_t flistxattr(int filedes, char *list, size_t size)
30{
31 return syscall(SYS_flistxattr, filedes, list, size);
32}
33
34int setxattr(const char *path, const char *name, const void *value, size_t size, int flags)
35{
36 return syscall(SYS_setxattr, path, name, value, size, flags);
37}
38
39int lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
40{
41 return syscall(SYS_lsetxattr, path, name, value, size, flags);
42}
43
44int fsetxattr(int filedes, const char *name, const void *value, size_t size, int flags)
45{
46 return syscall(SYS_fsetxattr, filedes, name, value, size, flags);
47}
48
49int removexattr(const char *path, const char *name)
50{
51 return syscall(SYS_removexattr, path, name);
52}
53
54int lremovexattr(const char *path, const char *name)
55{
56 return syscall(SYS_lremovexattr, path, name);
57}
58
59int fremovexattr(int fd, const char *name)
60{
61 return syscall(SYS_fremovexattr, fd, name);
62}
lib/libc/wasi/libc-top-half/musl/src/locale/bind_textdomain_codeset.c deleted-11
......@@ -1,11 +0,0 @@
1#include <libintl.h>
2#include <string.h>
3#include <strings.h>
4#include <errno.h>
5
6char *bind_textdomain_codeset(const char *domainname, const char *codeset)
7{
8 if (codeset && strcasecmp(codeset, "UTF-8"))
9 errno = EINVAL;
10 return NULL;
11}
lib/libc/wasi/libc-top-half/musl/src/locale/dcngettext.c deleted-283
......@@ -1,283 +0,0 @@
1#include <libintl.h>
2#include <stdlib.h>
3#include <string.h>
4#include <errno.h>
5#include <limits.h>
6#include <sys/stat.h>
7#include <sys/mman.h>
8#include <ctype.h>
9#include "locale_impl.h"
10#include "atomic.h"
11#include "pleval.h"
12#include "lock.h"
13#include "fork_impl.h"
14
15#define malloc __libc_malloc
16#define calloc __libc_calloc
17#define realloc undef
18#define free undef
19
20struct binding {
21 struct binding *next;
22 int dirlen;
23 volatile int active;
24 char *domainname;
25 char *dirname;
26 char buf[];
27};
28
29static void *volatile bindings;
30
31static char *gettextdir(const char *domainname, size_t *dirlen)
32{
33 struct binding *p;
34 for (p=bindings; p; p=p->next) {
35 if (!strcmp(p->domainname, domainname) && p->active) {
36 *dirlen = p->dirlen;
37 return (char *)p->dirname;
38 }
39 }
40 return 0;
41}
42
43static volatile int lock[1];
44volatile int *const __gettext_lockptr = lock;
45
46char *bindtextdomain(const char *domainname, const char *dirname)
47{
48 struct binding *p, *q;
49
50 if (!domainname) return 0;
51 if (!dirname) return gettextdir(domainname, &(size_t){0});
52
53 size_t domlen = strnlen(domainname, NAME_MAX+1);
54 size_t dirlen = strnlen(dirname, PATH_MAX);
55 if (domlen > NAME_MAX || dirlen >= PATH_MAX) {
56 errno = EINVAL;
57 return 0;
58 }
59
60 LOCK(lock);
61
62 for (p=bindings; p; p=p->next) {
63 if (!strcmp(p->domainname, domainname) &&
64 !strcmp(p->dirname, dirname)) {
65 break;
66 }
67 }
68
69 if (!p) {
70 p = calloc(sizeof *p + domlen + dirlen + 2, 1);
71 if (!p) {
72 UNLOCK(lock);
73 return 0;
74 }
75 p->next = bindings;
76 p->dirlen = dirlen;
77 p->domainname = p->buf;
78 p->dirname = p->buf + domlen + 1;
79 memcpy(p->domainname, domainname, domlen+1);
80 memcpy(p->dirname, dirname, dirlen+1);
81 a_cas_p(&bindings, bindings, p);
82 }
83
84 a_store(&p->active, 1);
85
86 for (q=bindings; q; q=q->next) {
87 if (!strcmp(q->domainname, domainname) && q != p)
88 a_store(&q->active, 0);
89 }
90
91 UNLOCK(lock);
92
93 return (char *)p->dirname;
94}
95
96static const char catnames[][12] = {
97 "LC_CTYPE",
98 "LC_NUMERIC",
99 "LC_TIME",
100 "LC_COLLATE",
101 "LC_MONETARY",
102 "LC_MESSAGES",
103};
104
105static const char catlens[] = { 8, 10, 7, 10, 11, 11 };
106
107struct msgcat {
108 struct msgcat *next;
109 const void *map;
110 size_t map_size;
111 const char *plural_rule;
112 int nplurals;
113 struct binding *binding;
114 const struct __locale_map *lm;
115 int cat;
116};
117
118static char *dummy_gettextdomain()
119{
120 return "messages";
121}
122
123weak_alias(dummy_gettextdomain, __gettextdomain);
124
125char *dcngettext(const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n, int category)
126{
127 static struct msgcat *volatile cats;
128 struct msgcat *p;
129 struct __locale_struct *loc = CURRENT_LOCALE;
130 const struct __locale_map *lm;
131 size_t domlen;
132 struct binding *q;
133 int old_errno = errno;
134
135 /* match gnu gettext behaviour */
136 if (!msgid1) goto notrans;
137
138 if ((unsigned)category >= LC_ALL) goto notrans;
139
140 if (!domainname) domainname = __gettextdomain();
141
142 domlen = strnlen(domainname, NAME_MAX+1);
143 if (domlen > NAME_MAX) goto notrans;
144
145 for (q=bindings; q; q=q->next)
146 if (!strcmp(q->domainname, domainname) && q->active)
147 break;
148 if (!q) goto notrans;
149
150 lm = loc->cat[category];
151 if (!lm) {
152notrans:
153 errno = old_errno;
154 return (char *) ((n == 1) ? msgid1 : msgid2);
155 }
156
157 for (p=cats; p; p=p->next)
158 if (p->binding == q && p->lm == lm && p->cat == category)
159 break;
160
161 if (!p) {
162 const char *dirname, *locname, *catname, *modname, *locp;
163 size_t dirlen, loclen, catlen, modlen, alt_modlen;
164 void *old_cats;
165 size_t map_size;
166
167 dirname = q->dirname;
168 locname = lm->name;
169 catname = catnames[category];
170
171 dirlen = q->dirlen;
172 loclen = strlen(locname);
173 catlen = catlens[category];
174
175 /* Logically split @mod suffix from locale name. */
176 modname = memchr(locname, '@', loclen);
177 if (!modname) modname = locname + loclen;
178 alt_modlen = modlen = loclen - (modname-locname);
179 loclen = modname-locname;
180
181 /* Drop .charset identifier; it is not used. */
182 const char *csp = memchr(locname, '.', loclen);
183 if (csp) loclen = csp-locname;
184
185 char name[dirlen+1 + loclen+modlen+1 + catlen+1 + domlen+3 + 1];
186 const void *map;
187
188 for (;;) {
189 snprintf(name, sizeof name, "%s/%.*s%.*s/%s/%s.mo\0",
190 dirname, (int)loclen, locname,
191 (int)alt_modlen, modname, catname, domainname);
192 if (map = __map_file(name, &map_size)) break;
193
194 /* Try dropping @mod, _YY, then both. */
195 if (alt_modlen) {
196 alt_modlen = 0;
197 } else if ((locp = memchr(locname, '_', loclen))) {
198 loclen = locp-locname;
199 alt_modlen = modlen;
200 } else {
201 break;
202 }
203 }
204 if (!map) goto notrans;
205
206 p = calloc(sizeof *p, 1);
207 if (!p) {
208 __munmap((void *)map, map_size);
209 goto notrans;
210 }
211 p->cat = category;
212 p->binding = q;
213 p->lm = lm;
214 p->map = map;
215 p->map_size = map_size;
216
217 const char *rule = "n!=1;";
218 unsigned long np = 2;
219 const char *r = __mo_lookup(p->map, p->map_size, "");
220 char *z;
221 while (r && strncmp(r, "Plural-Forms:", 13)) {
222 z = strchr(r, '\n');
223 r = z ? z+1 : 0;
224 }
225 if (r) {
226 r += 13;
227 while (isspace(*r)) r++;
228 if (!strncmp(r, "nplurals=", 9)) {
229 np = strtoul(r+9, &z, 10);
230 r = z;
231 }
232 while (*r && *r != ';') r++;
233 if (*r) {
234 r++;
235 while (isspace(*r)) r++;
236 if (!strncmp(r, "plural=", 7))
237 rule = r+7;
238 }
239 }
240 p->nplurals = np;
241 p->plural_rule = rule;
242
243 do {
244 old_cats = cats;
245 p->next = old_cats;
246 } while (a_cas_p(&cats, old_cats, p) != old_cats);
247 }
248
249 const char *trans = __mo_lookup(p->map, p->map_size, msgid1);
250 if (!trans) goto notrans;
251
252 /* Non-plural-processing gettext forms pass a null pointer as
253 * msgid2 to request that dcngettext suppress plural processing. */
254
255 if (msgid2 && p->nplurals) {
256 unsigned long plural = __pleval(p->plural_rule, n);
257 if (plural > p->nplurals) goto notrans;
258 while (plural--) {
259 size_t rem = p->map_size - (trans - (char *)p->map);
260 size_t l = strnlen(trans, rem);
261 if (l+1 >= rem)
262 goto notrans;
263 trans += l+1;
264 }
265 }
266 errno = old_errno;
267 return (char *)trans;
268}
269
270char *dcgettext(const char *domainname, const char *msgid, int category)
271{
272 return dcngettext(domainname, msgid, 0, 1, category);
273}
274
275char *dngettext(const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n)
276{
277 return dcngettext(domainname, msgid1, msgid2, n, LC_MESSAGES);
278}
279
280char *dgettext(const char *domainname, const char *msgid)
281{
282 return dcngettext(domainname, msgid, 0, 1, LC_MESSAGES);
283}
lib/libc/wasi/libc-top-half/musl/src/locale/textdomain.c deleted-42
......@@ -1,42 +0,0 @@
1#include <libintl.h>
2#include <string.h>
3#include <stdlib.h>
4#include <errno.h>
5#include <limits.h>
6
7static char *current_domain;
8
9char *__gettextdomain()
10{
11 return current_domain ? current_domain : "messages";
12}
13
14char *textdomain(const char *domainname)
15{
16 if (!domainname) return __gettextdomain();
17
18 size_t domlen = strlen(domainname);
19 if (domlen > NAME_MAX) {
20 errno = EINVAL;
21 return 0;
22 }
23
24 if (!current_domain) {
25 current_domain = malloc(NAME_MAX+1);
26 if (!current_domain) return 0;
27 }
28
29 memcpy(current_domain, domainname, domlen+1);
30
31 return current_domain;
32}
33
34char *gettext(const char *msgid)
35{
36 return dgettext(0, msgid);
37}
38
39char *ngettext(const char *msgid1, const char *msgid2, unsigned long int n)
40{
41 return dngettext(0, msgid1, msgid2, n);
42}
lib/libc/wasi/libc-top-half/musl/src/malloc/calloc.c deleted-45
......@@ -1,45 +0,0 @@
1#include <stdlib.h>
2#include <stdint.h>
3#include <string.h>
4#include <errno.h>
5#include "dynlink.h"
6
7static size_t mal0_clear(char *p, size_t n)
8{
9 const size_t pagesz = 4096; /* arbitrary */
10 if (n < pagesz) return n;
11#ifdef __GNUC__
12 typedef uint64_t __attribute__((__may_alias__)) T;
13#else
14 typedef unsigned char T;
15#endif
16 char *pp = p + n;
17 size_t i = (uintptr_t)pp & (pagesz - 1);
18 for (;;) {
19 pp = memset(pp - i, 0, i);
20 if (pp - p < pagesz) return pp - p;
21 for (i = pagesz; i; i -= 2*sizeof(T), pp -= 2*sizeof(T))
22 if (((T *)pp)[-1] | ((T *)pp)[-2])
23 break;
24 }
25}
26
27static int allzerop(void *p)
28{
29 return 0;
30}
31weak_alias(allzerop, __malloc_allzerop);
32
33void *calloc(size_t m, size_t n)
34{
35 if (n && m > (size_t)-1/n) {
36 errno = ENOMEM;
37 return 0;
38 }
39 n *= m;
40 void *p = malloc(n);
41 if (!p || (!__malloc_replaced && __malloc_allzerop(p)))
42 return p;
43 n = mal0_clear(p, n);
44 return memset(p, 0, n);
45}
lib/libc/wasi/libc-top-half/musl/src/malloc/free.c deleted-6
......@@ -1,6 +0,0 @@
1#include <stdlib.h>
2
3void free(void *p)
4{
5 __libc_free(p);
6}
lib/libc/wasi/libc-top-half/musl/src/malloc/libc_calloc.c deleted-4
......@@ -1,4 +0,0 @@
1#define calloc __libc_calloc
2#define malloc __libc_malloc
3
4#include "calloc.c"
lib/libc/wasi/libc-top-half/musl/src/malloc/lite_malloc.c deleted-118
......@@ -1,118 +0,0 @@
1#include <stdlib.h>
2#include <stdint.h>
3#include <limits.h>
4#include <errno.h>
5#include <sys/mman.h>
6#include "libc.h"
7#include "lock.h"
8#include "syscall.h"
9#include "fork_impl.h"
10
11#define ALIGN 16
12
13/* This function returns true if the interval [old,new]
14 * intersects the 'len'-sized interval below &libc.auxv
15 * (interpreted as the main-thread stack) or below &b
16 * (the current stack). It is used to defend against
17 * buggy brk implementations that can cross the stack. */
18
19static int traverses_stack_p(uintptr_t old, uintptr_t new)
20{
21 const uintptr_t len = 8<<20;
22 uintptr_t a, b;
23
24 b = (uintptr_t)libc.auxv;
25 a = b > len ? b-len : 0;
26 if (new>a && old<b) return 1;
27
28 b = (uintptr_t)&b;
29 a = b > len ? b-len : 0;
30 if (new>a && old<b) return 1;
31
32 return 0;
33}
34
35static volatile int lock[1];
36volatile int *const __bump_lockptr = lock;
37
38static void *__simple_malloc(size_t n)
39{
40 static uintptr_t brk, cur, end;
41 static unsigned mmap_step;
42 size_t align=1;
43 void *p;
44
45 if (n > SIZE_MAX/2) {
46 errno = ENOMEM;
47 return 0;
48 }
49
50 if (!n) n++;
51 while (align<n && align<ALIGN)
52 align += align;
53
54 LOCK(lock);
55
56 cur += -cur & align-1;
57
58 if (n > end-cur) {
59 size_t req = n - (end-cur) + PAGE_SIZE-1 & -PAGE_SIZE;
60
61 if (!cur) {
62 brk = __syscall(SYS_brk, 0);
63 brk += -brk & PAGE_SIZE-1;
64 cur = end = brk;
65 }
66
67 if (brk == end && req < SIZE_MAX-brk
68 && !traverses_stack_p(brk, brk+req)
69 && __syscall(SYS_brk, brk+req)==brk+req) {
70 brk = end += req;
71 } else {
72 int new_area = 0;
73 req = n + PAGE_SIZE-1 & -PAGE_SIZE;
74 /* Only make a new area rather than individual mmap
75 * if wasted space would be over 1/8 of the map. */
76 if (req-n > req/8) {
77 /* Geometric area size growth up to 64 pages,
78 * bounding waste by 1/8 of the area. */
79 size_t min = PAGE_SIZE<<(mmap_step/2);
80 if (min-n > end-cur) {
81 if (req < min) {
82 req = min;
83 if (mmap_step < 12)
84 mmap_step++;
85 }
86 new_area = 1;
87 }
88 }
89 void *mem = __mmap(0, req, PROT_READ|PROT_WRITE,
90 MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
91 if (mem == MAP_FAILED || !new_area) {
92 UNLOCK(lock);
93 return mem==MAP_FAILED ? 0 : mem;
94 }
95 cur = (uintptr_t)mem;
96 end = cur + req;
97 }
98 }
99
100 p = (void *)cur;
101 cur += n;
102 UNLOCK(lock);
103 return p;
104}
105
106weak_alias(__simple_malloc, __libc_malloc_impl);
107
108void *__libc_malloc(size_t n)
109{
110 return __libc_malloc_impl(n);
111}
112
113static void *default_malloc(size_t n)
114{
115 return __libc_malloc_impl(n);
116}
117
118weak_alias(default_malloc, malloc);
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/aligned_alloc.c deleted-60
......@@ -1,60 +0,0 @@
1#include <stdlib.h>
2#include <errno.h>
3#include "meta.h"
4
5void *aligned_alloc(size_t align, size_t len)
6{
7 if ((align & -align) != align) {
8 errno = EINVAL;
9 return 0;
10 }
11
12 if (len > SIZE_MAX - align || align >= (1ULL<<31)*UNIT) {
13 errno = ENOMEM;
14 return 0;
15 }
16
17 if (DISABLE_ALIGNED_ALLOC) {
18 errno = ENOMEM;
19 return 0;
20 }
21
22 if (align <= UNIT) align = UNIT;
23
24 unsigned char *p = malloc(len + align - UNIT);
25 if (!p)
26 return 0;
27
28 struct meta *g = get_meta(p);
29 int idx = get_slot_index(p);
30 size_t stride = get_stride(g);
31 unsigned char *start = g->mem->storage + stride*idx;
32 unsigned char *end = g->mem->storage + stride*(idx+1) - IB;
33 size_t adj = -(uintptr_t)p & (align-1);
34
35 if (!adj) {
36 set_size(p, end, len);
37 return p;
38 }
39 p += adj;
40 uint32_t offset = (size_t)(p-g->mem->storage)/UNIT;
41 if (offset <= 0xffff) {
42 *(uint16_t *)(p-2) = offset;
43 p[-4] = 0;
44 } else {
45 // use a 32-bit offset if 16-bit doesn't fit. for this,
46 // 16-bit field must be zero, [-4] byte nonzero.
47 *(uint16_t *)(p-2) = 0;
48 *(uint32_t *)(p-8) = offset;
49 p[-4] = 1;
50 }
51 p[-3] = idx;
52 set_size(p, end, len);
53 // store offset to aligned enframing. this facilitates cycling
54 // offset and also iteration of heap for debugging/measurement.
55 // for extreme overalignment it won't fit but these are classless
56 // allocations anyway.
57 *(uint16_t *)(start - 2) = (size_t)(p-start)/UNIT;
58 start[-3] = 7<<5;
59 return p;
60}
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/donate.c deleted-39
......@@ -1,39 +0,0 @@
1#include <stdlib.h>
2#include <stdint.h>
3#include <limits.h>
4#include <string.h>
5#include <sys/mman.h>
6#include <errno.h>
7
8#include "meta.h"
9
10static void donate(unsigned char *base, size_t len)
11{
12 uintptr_t a = (uintptr_t)base;
13 uintptr_t b = a + len;
14 a += -a & (UNIT-1);
15 b -= b & (UNIT-1);
16 memset(base, 0, len);
17 for (int sc=47; sc>0 && b>a; sc-=4) {
18 if (b-a < (size_classes[sc]+1)*UNIT) continue;
19 struct meta *m = alloc_meta();
20 m->avail_mask = 0;
21 m->freed_mask = 1;
22 m->mem = (void *)a;
23 m->mem->meta = m;
24 m->last_idx = 0;
25 m->freeable = 0;
26 m->sizeclass = sc;
27 m->maplen = 0;
28 *((unsigned char *)m->mem+UNIT-4) = 0;
29 *((unsigned char *)m->mem+UNIT-3) = 255;
30 m->mem->storage[size_classes[sc]*UNIT-4] = 0;
31 queue(&ctx.active[sc], m);
32 a += (size_classes[sc]+1)*UNIT;
33 }
34}
35
36void __malloc_donate(char *start, char *end)
37{
38 donate((void *)start, end-start);
39}
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/free.c deleted-151
......@@ -1,151 +0,0 @@
1#define _BSD_SOURCE
2#include <stdlib.h>
3#include <sys/mman.h>
4
5#include "meta.h"
6
7struct mapinfo {
8 void *base;
9 size_t len;
10};
11
12static struct mapinfo nontrivial_free(struct meta *, int);
13
14static struct mapinfo free_group(struct meta *g)
15{
16 struct mapinfo mi = { 0 };
17 int sc = g->sizeclass;
18 if (sc < 48) {
19 ctx.usage_by_class[sc] -= g->last_idx+1;
20 }
21 if (g->maplen) {
22 step_seq();
23 record_seq(sc);
24 mi.base = g->mem;
25 mi.len = g->maplen*4096UL;
26 } else {
27 void *p = g->mem;
28 struct meta *m = get_meta(p);
29 int idx = get_slot_index(p);
30 g->mem->meta = 0;
31 // not checking size/reserved here; it's intentionally invalid
32 mi = nontrivial_free(m, idx);
33 }
34 free_meta(g);
35 return mi;
36}
37
38static int okay_to_free(struct meta *g)
39{
40 int sc = g->sizeclass;
41
42 if (!g->freeable) return 0;
43
44 // always free individual mmaps not suitable for reuse
45 if (sc >= 48 || get_stride(g) < UNIT*size_classes[sc])
46 return 1;
47
48 // always free groups allocated inside another group's slot
49 // since recreating them should not be expensive and they
50 // might be blocking freeing of a much larger group.
51 if (!g->maplen) return 1;
52
53 // if there is another non-full group, free this one to
54 // consolidate future allocations, reduce fragmentation.
55 if (g->next != g) return 1;
56
57 // free any group in a size class that's not bouncing
58 if (!is_bouncing(sc)) return 1;
59
60 size_t cnt = g->last_idx+1;
61 size_t usage = ctx.usage_by_class[sc];
62
63 // if usage is high enough that a larger count should be
64 // used, free the low-count group so a new one will be made.
65 if (9*cnt <= usage && cnt < 20)
66 return 1;
67
68 // otherwise, keep the last group in a bouncing class.
69 return 0;
70}
71
72static struct mapinfo nontrivial_free(struct meta *g, int i)
73{
74 uint32_t self = 1u<<i;
75 int sc = g->sizeclass;
76 uint32_t mask = g->freed_mask | g->avail_mask;
77
78 if (mask+self == (2u<<g->last_idx)-1 && okay_to_free(g)) {
79 // any multi-slot group is necessarily on an active list
80 // here, but single-slot groups might or might not be.
81 if (g->next) {
82 assert(sc < 48);
83 int activate_new = (ctx.active[sc]==g);
84 dequeue(&ctx.active[sc], g);
85 if (activate_new && ctx.active[sc])
86 activate_group(ctx.active[sc]);
87 }
88 return free_group(g);
89 } else if (!mask) {
90 assert(sc < 48);
91 // might still be active if there were no allocations
92 // after last available slot was taken.
93 if (ctx.active[sc] != g) {
94 queue(&ctx.active[sc], g);
95 }
96 }
97 a_or(&g->freed_mask, self);
98 return (struct mapinfo){ 0 };
99}
100
101void free(void *p)
102{
103 if (!p) return;
104
105 struct meta *g = get_meta(p);
106 int idx = get_slot_index(p);
107 size_t stride = get_stride(g);
108 unsigned char *start = g->mem->storage + stride*idx;
109 unsigned char *end = start + stride - IB;
110 get_nominal_size(p, end);
111 uint32_t self = 1u<<idx, all = (2u<<g->last_idx)-1;
112 ((unsigned char *)p)[-3] = 255;
113 // invalidate offset to group header, and cycle offset of
114 // used region within slot if current offset is zero.
115 *(uint16_t *)((char *)p-2) = 0;
116
117 // release any whole pages contained in the slot to be freed
118 // unless it's a single-slot group that will be unmapped.
119 if (((uintptr_t)(start-1) ^ (uintptr_t)end) >= 2*PGSZ && g->last_idx) {
120 unsigned char *base = start + (-(uintptr_t)start & (PGSZ-1));
121 size_t len = (end-base) & -PGSZ;
122 if (len) {
123 int e = errno;
124 madvise(base, len, MADV_FREE);
125 errno = e;
126 }
127 }
128
129 // atomic free without locking if this is neither first or last slot
130 for (;;) {
131 uint32_t freed = g->freed_mask;
132 uint32_t avail = g->avail_mask;
133 uint32_t mask = freed | avail;
134 assert(!(mask&self));
135 if (!freed || mask+self==all) break;
136 if (!MT)
137 g->freed_mask = freed+self;
138 else if (a_cas(&g->freed_mask, freed, freed+self)!=freed)
139 continue;
140 return;
141 }
142
143 wrlock();
144 struct mapinfo mi = nontrivial_free(g, idx);
145 unlock();
146 if (mi.len) {
147 int e = errno;
148 munmap(mi.base, mi.len);
149 errno = e;
150 }
151}
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/malloc.c deleted-387
......@@ -1,387 +0,0 @@
1#include <stdlib.h>
2#include <stdint.h>
3#include <limits.h>
4#include <string.h>
5#include <sys/mman.h>
6#include <errno.h>
7
8#include "meta.h"
9
10LOCK_OBJ_DEF;
11
12const uint16_t size_classes[] = {
13 1, 2, 3, 4, 5, 6, 7, 8,
14 9, 10, 12, 15,
15 18, 20, 25, 31,
16 36, 42, 50, 63,
17 72, 84, 102, 127,
18 146, 170, 204, 255,
19 292, 340, 409, 511,
20 584, 682, 818, 1023,
21 1169, 1364, 1637, 2047,
22 2340, 2730, 3276, 4095,
23 4680, 5460, 6552, 8191,
24};
25
26static const uint8_t small_cnt_tab[][3] = {
27 { 30, 30, 30 },
28 { 31, 15, 15 },
29 { 20, 10, 10 },
30 { 31, 15, 7 },
31 { 25, 12, 6 },
32 { 21, 10, 5 },
33 { 18, 8, 4 },
34 { 31, 15, 7 },
35 { 28, 14, 6 },
36};
37
38static const uint8_t med_cnt_tab[4] = { 28, 24, 20, 32 };
39
40struct malloc_context ctx = { 0 };
41
42struct meta *alloc_meta(void)
43{
44 struct meta *m;
45 unsigned char *p;
46 if (!ctx.init_done) {
47#ifndef PAGESIZE
48 ctx.pagesize = get_page_size();
49#endif
50 ctx.secret = get_random_secret();
51 ctx.init_done = 1;
52 }
53 size_t pagesize = PGSZ;
54 if (pagesize < 4096) pagesize = 4096;
55 if ((m = dequeue_head(&ctx.free_meta_head))) return m;
56 if (!ctx.avail_meta_count) {
57 int need_unprotect = 1;
58 if (!ctx.avail_meta_area_count && ctx.brk!=-1) {
59 uintptr_t new = ctx.brk + pagesize;
60 int need_guard = 0;
61 if (!ctx.brk) {
62 need_guard = 1;
63 ctx.brk = brk(0);
64 // some ancient kernels returned _ebss
65 // instead of next page as initial brk.
66 ctx.brk += -ctx.brk & (pagesize-1);
67 new = ctx.brk + 2*pagesize;
68 }
69 if (brk(new) != new) {
70 ctx.brk = -1;
71 } else {
72 if (need_guard) mmap((void *)ctx.brk, pagesize,
73 PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0);
74 ctx.brk = new;
75 ctx.avail_meta_areas = (void *)(new - pagesize);
76 ctx.avail_meta_area_count = pagesize>>12;
77 need_unprotect = 0;
78 }
79 }
80 if (!ctx.avail_meta_area_count) {
81 size_t n = 2UL << ctx.meta_alloc_shift;
82 p = mmap(0, n*pagesize, PROT_NONE,
83 MAP_PRIVATE|MAP_ANON, -1, 0);
84 if (p==MAP_FAILED) return 0;
85 ctx.avail_meta_areas = p + pagesize;
86 ctx.avail_meta_area_count = (n-1)*(pagesize>>12);
87 ctx.meta_alloc_shift++;
88 }
89 p = ctx.avail_meta_areas;
90 if ((uintptr_t)p & (pagesize-1)) need_unprotect = 0;
91 if (need_unprotect)
92 if (mprotect(p, pagesize, PROT_READ|PROT_WRITE)
93 && errno != ENOSYS)
94 return 0;
95 ctx.avail_meta_area_count--;
96 ctx.avail_meta_areas = p + 4096;
97 if (ctx.meta_area_tail) {
98 ctx.meta_area_tail->next = (void *)p;
99 } else {
100 ctx.meta_area_head = (void *)p;
101 }
102 ctx.meta_area_tail = (void *)p;
103 ctx.meta_area_tail->check = ctx.secret;
104 ctx.avail_meta_count = ctx.meta_area_tail->nslots
105 = (4096-sizeof(struct meta_area))/sizeof *m;
106 ctx.avail_meta = ctx.meta_area_tail->slots;
107 }
108 ctx.avail_meta_count--;
109 m = ctx.avail_meta++;
110 m->prev = m->next = 0;
111 return m;
112}
113
114static uint32_t try_avail(struct meta **pm)
115{
116 struct meta *m = *pm;
117 uint32_t first;
118 if (!m) return 0;
119 uint32_t mask = m->avail_mask;
120 if (!mask) {
121 if (!m) return 0;
122 if (!m->freed_mask) {
123 dequeue(pm, m);
124 m = *pm;
125 if (!m) return 0;
126 } else {
127 m = m->next;
128 *pm = m;
129 }
130
131 mask = m->freed_mask;
132
133 // skip fully-free group unless it's the only one
134 // or it's a permanently non-freeable group
135 if (mask == (2u<<m->last_idx)-1 && m->freeable) {
136 m = m->next;
137 *pm = m;
138 mask = m->freed_mask;
139 }
140
141 // activate more slots in a not-fully-active group
142 // if needed, but only as a last resort. prefer using
143 // any other group with free slots. this avoids
144 // touching & dirtying as-yet-unused pages.
145 if (!(mask & ((2u<<m->mem->active_idx)-1))) {
146 if (m->next != m) {
147 m = m->next;
148 *pm = m;
149 } else {
150 int cnt = m->mem->active_idx + 2;
151 int size = size_classes[m->sizeclass]*UNIT;
152 int span = UNIT + size*cnt;
153 // activate up to next 4k boundary
154 while ((span^(span+size-1)) < 4096) {
155 cnt++;
156 span += size;
157 }
158 if (cnt > m->last_idx+1)
159 cnt = m->last_idx+1;
160 m->mem->active_idx = cnt-1;
161 }
162 }
163 mask = activate_group(m);
164 assert(mask);
165 decay_bounces(m->sizeclass);
166 }
167 first = mask&-mask;
168 m->avail_mask = mask-first;
169 return first;
170}
171
172static int alloc_slot(int, size_t);
173
174static struct meta *alloc_group(int sc, size_t req)
175{
176 size_t size = UNIT*size_classes[sc];
177 int i = 0, cnt;
178 unsigned char *p;
179 struct meta *m = alloc_meta();
180 if (!m) return 0;
181 size_t usage = ctx.usage_by_class[sc];
182 size_t pagesize = PGSZ;
183 int active_idx;
184 if (sc < 9) {
185 while (i<2 && 4*small_cnt_tab[sc][i] > usage)
186 i++;
187 cnt = small_cnt_tab[sc][i];
188 } else {
189 // lookup max number of slots fitting in power-of-two size
190 // from a table, along with number of factors of two we
191 // can divide out without a remainder or reaching 1.
192 cnt = med_cnt_tab[sc&3];
193
194 // reduce cnt to avoid excessive eagar allocation.
195 while (!(cnt&1) && 4*cnt > usage)
196 cnt >>= 1;
197
198 // data structures don't support groups whose slot offsets
199 // in units don't fit in 16 bits.
200 while (size*cnt >= 65536*UNIT)
201 cnt >>= 1;
202 }
203
204 // If we selected a count of 1 above but it's not sufficient to use
205 // mmap, increase to 2. Then it might be; if not it will nest.
206 if (cnt==1 && size*cnt+UNIT <= pagesize/2) cnt = 2;
207
208 // All choices of size*cnt are "just below" a power of two, so anything
209 // larger than half the page size should be allocated as whole pages.
210 if (size*cnt+UNIT > pagesize/2) {
211 // check/update bounce counter to start/increase retention
212 // of freed maps, and inhibit use of low-count, odd-size
213 // small mappings and single-slot groups if activated.
214 int nosmall = is_bouncing(sc);
215 account_bounce(sc);
216 step_seq();
217
218 // since the following count reduction opportunities have
219 // an absolute memory usage cost, don't overdo them. count
220 // coarse usage as part of usage.
221 if (!(sc&1) && sc<32) usage += ctx.usage_by_class[sc+1];
222
223 // try to drop to a lower count if the one found above
224 // increases usage by more than 25%. these reduced counts
225 // roughly fill an integral number of pages, just not a
226 // power of two, limiting amount of unusable space.
227 if (4*cnt > usage && !nosmall) {
228 if (0);
229 else if ((sc&3)==1 && size*cnt>8*pagesize) cnt = 2;
230 else if ((sc&3)==2 && size*cnt>4*pagesize) cnt = 3;
231 else if ((sc&3)==0 && size*cnt>8*pagesize) cnt = 3;
232 else if ((sc&3)==0 && size*cnt>2*pagesize) cnt = 5;
233 }
234 size_t needed = size*cnt + UNIT;
235 needed += -needed & (pagesize-1);
236
237 // produce an individually-mmapped allocation if usage is low,
238 // bounce counter hasn't triggered, and either it saves memory
239 // or it avoids eagar slot allocation without wasting too much.
240 if (!nosmall && cnt<=7) {
241 req += IB + UNIT;
242 req += -req & (pagesize-1);
243 if (req<size+UNIT || (req>=4*pagesize && 2*cnt>usage)) {
244 cnt = 1;
245 needed = req;
246 }
247 }
248
249 p = mmap(0, needed, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
250 if (p==MAP_FAILED) {
251 free_meta(m);
252 return 0;
253 }
254 m->maplen = needed>>12;
255 ctx.mmap_counter++;
256 active_idx = (4096-UNIT)/size-1;
257 if (active_idx > cnt-1) active_idx = cnt-1;
258 if (active_idx < 0) active_idx = 0;
259 } else {
260 int j = size_to_class(UNIT+cnt*size-IB);
261 int idx = alloc_slot(j, UNIT+cnt*size-IB);
262 if (idx < 0) {
263 free_meta(m);
264 return 0;
265 }
266 struct meta *g = ctx.active[j];
267 p = enframe(g, idx, UNIT*size_classes[j]-IB, ctx.mmap_counter);
268 m->maplen = 0;
269 p[-3] = (p[-3]&31) | (6<<5);
270 for (int i=0; i<=cnt; i++)
271 p[UNIT+i*size-4] = 0;
272 active_idx = cnt-1;
273 }
274 ctx.usage_by_class[sc] += cnt;
275 m->avail_mask = (2u<<active_idx)-1;
276 m->freed_mask = (2u<<(cnt-1))-1 - m->avail_mask;
277 m->mem = (void *)p;
278 m->mem->meta = m;
279 m->mem->active_idx = active_idx;
280 m->last_idx = cnt-1;
281 m->freeable = 1;
282 m->sizeclass = sc;
283 return m;
284}
285
286static int alloc_slot(int sc, size_t req)
287{
288 uint32_t first = try_avail(&ctx.active[sc]);
289 if (first) return a_ctz_32(first);
290
291 struct meta *g = alloc_group(sc, req);
292 if (!g) return -1;
293
294 g->avail_mask--;
295 queue(&ctx.active[sc], g);
296 return 0;
297}
298
299void *malloc(size_t n)
300{
301 if (size_overflows(n)) return 0;
302 struct meta *g;
303 uint32_t mask, first;
304 int sc;
305 int idx;
306 int ctr;
307
308 if (n >= MMAP_THRESHOLD) {
309 size_t needed = n + IB + UNIT;
310 void *p = mmap(0, needed, PROT_READ|PROT_WRITE,
311 MAP_PRIVATE|MAP_ANON, -1, 0);
312 if (p==MAP_FAILED) return 0;
313 wrlock();
314 step_seq();
315 g = alloc_meta();
316 if (!g) {
317 unlock();
318 munmap(p, needed);
319 return 0;
320 }
321 g->mem = p;
322 g->mem->meta = g;
323 g->last_idx = 0;
324 g->freeable = 1;
325 g->sizeclass = 63;
326 g->maplen = (needed+4095)/4096;
327 g->avail_mask = g->freed_mask = 0;
328 // use a global counter to cycle offset in
329 // individually-mmapped allocations.
330 ctx.mmap_counter++;
331 idx = 0;
332 goto success;
333 }
334
335 sc = size_to_class(n);
336
337 rdlock();
338 g = ctx.active[sc];
339
340 // use coarse size classes initially when there are not yet
341 // any groups of desired size. this allows counts of 2 or 3
342 // to be allocated at first rather than having to start with
343 // 7 or 5, the min counts for even size classes.
344 if (!g && sc>=4 && sc<32 && sc!=6 && !(sc&1) && !ctx.usage_by_class[sc]) {
345 size_t usage = ctx.usage_by_class[sc|1];
346 // if a new group may be allocated, count it toward
347 // usage in deciding if we can use coarse class.
348 if (!ctx.active[sc|1] || (!ctx.active[sc|1]->avail_mask
349 && !ctx.active[sc|1]->freed_mask))
350 usage += 3;
351 if (usage <= 12)
352 sc |= 1;
353 g = ctx.active[sc];
354 }
355
356 for (;;) {
357 mask = g ? g->avail_mask : 0;
358 first = mask&-mask;
359 if (!first) break;
360 if (RDLOCK_IS_EXCLUSIVE || !MT)
361 g->avail_mask = mask-first;
362 else if (a_cas(&g->avail_mask, mask, mask-first)!=mask)
363 continue;
364 idx = a_ctz_32(first);
365 goto success;
366 }
367 upgradelock();
368
369 idx = alloc_slot(sc, n);
370 if (idx < 0) {
371 unlock();
372 return 0;
373 }
374 g = ctx.active[sc];
375
376success:
377 ctr = ctx.mmap_counter;
378 unlock();
379 return enframe(g, idx, n, ctr);
380}
381
382int is_allzero(void *p)
383{
384 struct meta *g = get_meta(p);
385 return g->sizeclass >= 48 ||
386 get_stride(g) < UNIT*size_classes[g->sizeclass];
387}
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/malloc_usable_size.c deleted-13
......@@ -1,13 +0,0 @@
1#include <stdlib.h>
2#include "meta.h"
3
4size_t malloc_usable_size(void *p)
5{
6 if (!p) return 0;
7 struct meta *g = get_meta(p);
8 int idx = get_slot_index(p);
9 size_t stride = get_stride(g);
10 unsigned char *start = g->mem->storage + stride*idx;
11 unsigned char *end = start + stride - IB;
12 return get_nominal_size(p, end);
13}
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/realloc.c deleted-51
......@@ -1,51 +0,0 @@
1#define _GNU_SOURCE
2#include <stdlib.h>
3#include <sys/mman.h>
4#include <string.h>
5#include "meta.h"
6
7void *realloc(void *p, size_t n)
8{
9 if (!p) return malloc(n);
10 if (size_overflows(n)) return 0;
11
12 struct meta *g = get_meta(p);
13 int idx = get_slot_index(p);
14 size_t stride = get_stride(g);
15 unsigned char *start = g->mem->storage + stride*idx;
16 unsigned char *end = start + stride - IB;
17 size_t old_size = get_nominal_size(p, end);
18 size_t avail_size = end-(unsigned char *)p;
19 void *new;
20
21 // only resize in-place if size class matches
22 if (n <= avail_size && n<MMAP_THRESHOLD
23 && size_to_class(n)+1 >= g->sizeclass) {
24 set_size(p, end, n);
25 return p;
26 }
27
28 // use mremap if old and new size are both mmap-worthy
29 if (g->sizeclass>=48 && n>=MMAP_THRESHOLD) {
30 assert(g->sizeclass==63);
31 size_t base = (unsigned char *)p-start;
32 size_t needed = (n + base + UNIT + IB + 4095) & -4096;
33 new = g->maplen*4096UL == needed ? g->mem :
34 mremap(g->mem, g->maplen*4096UL, needed, MREMAP_MAYMOVE);
35 if (new!=MAP_FAILED) {
36 g->mem = new;
37 g->maplen = needed/4096;
38 p = g->mem->storage + base;
39 end = g->mem->storage + (needed - UNIT) - IB;
40 *end = 0;
41 set_size(p, end, n);
42 return p;
43 }
44 }
45
46 new = malloc(n);
47 if (!new) return 0;
48 memcpy(new, p, n < old_size ? n : old_size);
49 free(p);
50 return new;
51}
lib/libc/wasi/libc-top-half/musl/src/malloc/memalign.c deleted-7
......@@ -1,7 +0,0 @@
1#define _BSD_SOURCE
2#include <stdlib.h>
3
4void *memalign(size_t align, size_t len)
5{
6 return aligned_alloc(align, len);
7}
lib/libc/wasi/libc-top-half/musl/src/malloc/oldmalloc/aligned_alloc.c deleted-53
......@@ -1,53 +0,0 @@
1#include <stdlib.h>
2#include <stdint.h>
3#include <errno.h>
4#include "malloc_impl.h"
5
6void *aligned_alloc(size_t align, size_t len)
7{
8 unsigned char *mem, *new;
9
10 if ((align & -align) != align) {
11 errno = EINVAL;
12 return 0;
13 }
14
15 if (len > SIZE_MAX - align ||
16 (__malloc_replaced && !__aligned_alloc_replaced)) {
17 errno = ENOMEM;
18 return 0;
19 }
20
21 if (align <= SIZE_ALIGN)
22 return malloc(len);
23
24 if (!(mem = malloc(len + align-1)))
25 return 0;
26
27 new = (void *)((uintptr_t)mem + align-1 & -align);
28 if (new == mem) return mem;
29
30 struct chunk *c = MEM_TO_CHUNK(mem);
31 struct chunk *n = MEM_TO_CHUNK(new);
32
33 if (IS_MMAPPED(c)) {
34 /* Apply difference between aligned and original
35 * address to the "extra" field of mmapped chunk. */
36 n->psize = c->psize + (new-mem);
37 n->csize = c->csize - (new-mem);
38 return new;
39 }
40
41 struct chunk *t = NEXT_CHUNK(c);
42
43 /* Split the allocated chunk into two chunks. The aligned part
44 * that will be used has the size in its footer reduced by the
45 * difference between the aligned and original addresses, and
46 * the resulting size copied to its header. A new header and
47 * footer are written for the split-off part to be freed. */
48 n->psize = c->csize = C_INUSE | (new-mem);
49 n->csize = t->psize -= new-mem;
50
51 __bin_chunk(c);
52 return new;
53}
lib/libc/wasi/libc-top-half/musl/src/malloc/oldmalloc/malloc.c deleted-556
......@@ -1,556 +0,0 @@
1#define _GNU_SOURCE
2#include <stdlib.h>
3#include <string.h>
4#include <limits.h>
5#include <stdint.h>
6#include <errno.h>
7#include <sys/mman.h>
8#include "libc.h"
9#include "atomic.h"
10#include "pthread_impl.h"
11#include "malloc_impl.h"
12#include "fork_impl.h"
13
14#define malloc __libc_malloc_impl
15#define realloc __libc_realloc
16#define free __libc_free
17
18#if defined(__GNUC__) && defined(__PIC__)
19#define inline inline __attribute__((always_inline))
20#endif
21
22static struct {
23 volatile uint64_t binmap;
24 struct bin bins[64];
25 volatile int split_merge_lock[2];
26} mal;
27
28/* Synchronization tools */
29
30static inline void lock(volatile int *lk)
31{
32 int need_locks = libc.need_locks;
33 if (need_locks) {
34 while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1);
35 if (need_locks < 0) libc.need_locks = 0;
36 }
37}
38
39static inline void unlock(volatile int *lk)
40{
41 if (lk[0]) {
42 a_store(lk, 0);
43 if (lk[1]) __wake(lk, 1, 1);
44 }
45}
46
47static inline void lock_bin(int i)
48{
49 lock(mal.bins[i].lock);
50 if (!mal.bins[i].head)
51 mal.bins[i].head = mal.bins[i].tail = BIN_TO_CHUNK(i);
52}
53
54static inline void unlock_bin(int i)
55{
56 unlock(mal.bins[i].lock);
57}
58
59static int first_set(uint64_t x)
60{
61#if 1
62 return a_ctz_64(x);
63#else
64 static const char debruijn64[64] = {
65 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,
66 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,
67 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,
68 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12
69 };
70 static const char debruijn32[32] = {
71 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
72 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
73 };
74 if (sizeof(long) < 8) {
75 uint32_t y = x;
76 if (!y) {
77 y = x>>32;
78 return 32 + debruijn32[(y&-y)*0x076be629 >> 27];
79 }
80 return debruijn32[(y&-y)*0x076be629 >> 27];
81 }
82 return debruijn64[(x&-x)*0x022fdd63cc95386dull >> 58];
83#endif
84}
85
86static const unsigned char bin_tab[60] = {
87 32,33,34,35,36,36,37,37,38,38,39,39,
88 40,40,40,40,41,41,41,41,42,42,42,42,43,43,43,43,
89 44,44,44,44,44,44,44,44,45,45,45,45,45,45,45,45,
90 46,46,46,46,46,46,46,46,47,47,47,47,47,47,47,47,
91};
92
93static int bin_index(size_t x)
94{
95 x = x / SIZE_ALIGN - 1;
96 if (x <= 32) return x;
97 if (x < 512) return bin_tab[x/8-4];
98 if (x > 0x1c00) return 63;
99 return bin_tab[x/128-4] + 16;
100}
101
102static int bin_index_up(size_t x)
103{
104 x = x / SIZE_ALIGN - 1;
105 if (x <= 32) return x;
106 x--;
107 if (x < 512) return bin_tab[x/8-4] + 1;
108 return bin_tab[x/128-4] + 17;
109}
110
111#if 0
112void __dump_heap(int x)
113{
114 struct chunk *c;
115 int i;
116 for (c = (void *)mal.heap; CHUNK_SIZE(c); c = NEXT_CHUNK(c))
117 fprintf(stderr, "base %p size %zu (%d) flags %d/%d\n",
118 c, CHUNK_SIZE(c), bin_index(CHUNK_SIZE(c)),
119 c->csize & 15,
120 NEXT_CHUNK(c)->psize & 15);
121 for (i=0; i<64; i++) {
122 if (mal.bins[i].head != BIN_TO_CHUNK(i) && mal.bins[i].head) {
123 fprintf(stderr, "bin %d: %p\n", i, mal.bins[i].head);
124 if (!(mal.binmap & 1ULL<<i))
125 fprintf(stderr, "missing from binmap!\n");
126 } else if (mal.binmap & 1ULL<<i)
127 fprintf(stderr, "binmap wrongly contains %d!\n", i);
128 }
129}
130#endif
131
132/* This function returns true if the interval [old,new]
133 * intersects the 'len'-sized interval below &libc.auxv
134 * (interpreted as the main-thread stack) or below &b
135 * (the current stack). It is used to defend against
136 * buggy brk implementations that can cross the stack. */
137
138static int traverses_stack_p(uintptr_t old, uintptr_t new)
139{
140 const uintptr_t len = 8<<20;
141 uintptr_t a, b;
142
143 b = (uintptr_t)libc.auxv;
144 a = b > len ? b-len : 0;
145 if (new>a && old<b) return 1;
146
147 b = (uintptr_t)&b;
148 a = b > len ? b-len : 0;
149 if (new>a && old<b) return 1;
150
151 return 0;
152}
153
154/* Expand the heap in-place if brk can be used, or otherwise via mmap,
155 * using an exponential lower bound on growth by mmap to make
156 * fragmentation asymptotically irrelevant. The size argument is both
157 * an input and an output, since the caller needs to know the size
158 * allocated, which will be larger than requested due to page alignment
159 * and mmap minimum size rules. The caller is responsible for locking
160 * to prevent concurrent calls. */
161
162static void *__expand_heap(size_t *pn)
163{
164 static uintptr_t brk;
165 static unsigned mmap_step;
166 size_t n = *pn;
167
168 if (n > SIZE_MAX/2 - PAGE_SIZE) {
169 errno = ENOMEM;
170 return 0;
171 }
172 n += -n & PAGE_SIZE-1;
173
174 if (!brk) {
175 brk = __syscall(SYS_brk, 0);
176 brk += -brk & PAGE_SIZE-1;
177 }
178
179 if (n < SIZE_MAX-brk && !traverses_stack_p(brk, brk+n)
180 && __syscall(SYS_brk, brk+n)==brk+n) {
181 *pn = n;
182 brk += n;
183 return (void *)(brk-n);
184 }
185
186 size_t min = (size_t)PAGE_SIZE << mmap_step/2;
187 if (n < min) n = min;
188 void *area = __mmap(0, n, PROT_READ|PROT_WRITE,
189 MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
190 if (area == MAP_FAILED) return 0;
191 *pn = n;
192 mmap_step++;
193 return area;
194}
195
196static struct chunk *expand_heap(size_t n)
197{
198 static void *end;
199 void *p;
200 struct chunk *w;
201
202 /* The argument n already accounts for the caller's chunk
203 * overhead needs, but if the heap can't be extended in-place,
204 * we need room for an extra zero-sized sentinel chunk. */
205 n += SIZE_ALIGN;
206
207 p = __expand_heap(&n);
208 if (!p) return 0;
209
210 /* If not just expanding existing space, we need to make a
211 * new sentinel chunk below the allocated space. */
212 if (p != end) {
213 /* Valid/safe because of the prologue increment. */
214 n -= SIZE_ALIGN;
215 p = (char *)p + SIZE_ALIGN;
216 w = MEM_TO_CHUNK(p);
217 w->psize = 0 | C_INUSE;
218 }
219
220 /* Record new heap end and fill in footer. */
221 end = (char *)p + n;
222 w = MEM_TO_CHUNK(end);
223 w->psize = n | C_INUSE;
224 w->csize = 0 | C_INUSE;
225
226 /* Fill in header, which may be new or may be replacing a
227 * zero-size sentinel header at the old end-of-heap. */
228 w = MEM_TO_CHUNK(p);
229 w->csize = n | C_INUSE;
230
231 return w;
232}
233
234static int adjust_size(size_t *n)
235{
236 /* Result of pointer difference must fit in ptrdiff_t. */
237 if (*n-1 > PTRDIFF_MAX - SIZE_ALIGN - PAGE_SIZE) {
238 if (*n) {
239 errno = ENOMEM;
240 return -1;
241 } else {
242 *n = SIZE_ALIGN;
243 return 0;
244 }
245 }
246 *n = (*n + OVERHEAD + SIZE_ALIGN - 1) & SIZE_MASK;
247 return 0;
248}
249
250static void unbin(struct chunk *c, int i)
251{
252 if (c->prev == c->next)
253 a_and_64(&mal.binmap, ~(1ULL<<i));
254 c->prev->next = c->next;
255 c->next->prev = c->prev;
256 c->csize |= C_INUSE;
257 NEXT_CHUNK(c)->psize |= C_INUSE;
258}
259
260static void bin_chunk(struct chunk *self, int i)
261{
262 self->next = BIN_TO_CHUNK(i);
263 self->prev = mal.bins[i].tail;
264 self->next->prev = self;
265 self->prev->next = self;
266 if (self->prev == BIN_TO_CHUNK(i))
267 a_or_64(&mal.binmap, 1ULL<<i);
268}
269
270static void trim(struct chunk *self, size_t n)
271{
272 size_t n1 = CHUNK_SIZE(self);
273 struct chunk *next, *split;
274
275 if (n >= n1 - DONTCARE) return;
276
277 next = NEXT_CHUNK(self);
278 split = (void *)((char *)self + n);
279
280 split->psize = n | C_INUSE;
281 split->csize = n1-n;
282 next->psize = n1-n;
283 self->csize = n | C_INUSE;
284
285 int i = bin_index(n1-n);
286 lock_bin(i);
287
288 bin_chunk(split, i);
289
290 unlock_bin(i);
291}
292
293void *malloc(size_t n)
294{
295 struct chunk *c;
296 int i, j;
297 uint64_t mask;
298
299 if (adjust_size(&n) < 0) return 0;
300
301 if (n > MMAP_THRESHOLD) {
302 size_t len = n + OVERHEAD + PAGE_SIZE - 1 & -PAGE_SIZE;
303 char *base = __mmap(0, len, PROT_READ|PROT_WRITE,
304 MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
305 if (base == (void *)-1) return 0;
306 c = (void *)(base + SIZE_ALIGN - OVERHEAD);
307 c->csize = len - (SIZE_ALIGN - OVERHEAD);
308 c->psize = SIZE_ALIGN - OVERHEAD;
309 return CHUNK_TO_MEM(c);
310 }
311
312 i = bin_index_up(n);
313 if (i<63 && (mal.binmap & (1ULL<<i))) {
314 lock_bin(i);
315 c = mal.bins[i].head;
316 if (c != BIN_TO_CHUNK(i) && CHUNK_SIZE(c)-n <= DONTCARE) {
317 unbin(c, i);
318 unlock_bin(i);
319 return CHUNK_TO_MEM(c);
320 }
321 unlock_bin(i);
322 }
323 lock(mal.split_merge_lock);
324 for (mask = mal.binmap & -(1ULL<<i); mask; mask -= (mask&-mask)) {
325 j = first_set(mask);
326 lock_bin(j);
327 c = mal.bins[j].head;
328 if (c != BIN_TO_CHUNK(j)) {
329 unbin(c, j);
330 unlock_bin(j);
331 break;
332 }
333 unlock_bin(j);
334 }
335 if (!mask) {
336 c = expand_heap(n);
337 if (!c) {
338 unlock(mal.split_merge_lock);
339 return 0;
340 }
341 }
342 trim(c, n);
343 unlock(mal.split_merge_lock);
344 return CHUNK_TO_MEM(c);
345}
346
347int __malloc_allzerop(void *p)
348{
349 return IS_MMAPPED(MEM_TO_CHUNK(p));
350}
351
352void *realloc(void *p, size_t n)
353{
354 struct chunk *self, *next;
355 size_t n0, n1;
356 void *new;
357
358 if (!p) return malloc(n);
359
360 if (adjust_size(&n) < 0) return 0;
361
362 self = MEM_TO_CHUNK(p);
363 n1 = n0 = CHUNK_SIZE(self);
364
365 if (n<=n0 && n0-n<=DONTCARE) return p;
366
367 if (IS_MMAPPED(self)) {
368 size_t extra = self->psize;
369 char *base = (char *)self - extra;
370 size_t oldlen = n0 + extra;
371 size_t newlen = n + extra;
372 /* Crash on realloc of freed chunk */
373 if (extra & 1) a_crash();
374 if (newlen < PAGE_SIZE && (new = malloc(n-OVERHEAD))) {
375 n0 = n;
376 goto copy_free_ret;
377 }
378 newlen = (newlen + PAGE_SIZE-1) & -PAGE_SIZE;
379 if (oldlen == newlen) return p;
380 base = __mremap(base, oldlen, newlen, MREMAP_MAYMOVE);
381 if (base == (void *)-1)
382 goto copy_realloc;
383 self = (void *)(base + extra);
384 self->csize = newlen - extra;
385 return CHUNK_TO_MEM(self);
386 }
387
388 next = NEXT_CHUNK(self);
389
390 /* Crash on corrupted footer (likely from buffer overflow) */
391 if (next->psize != self->csize) a_crash();
392
393 if (n < n0) {
394 int i = bin_index_up(n);
395 int j = bin_index(n0);
396 if (i<j && (mal.binmap & (1ULL << i)))
397 goto copy_realloc;
398 struct chunk *split = (void *)((char *)self + n);
399 self->csize = split->psize = n | C_INUSE;
400 split->csize = next->psize = n0-n | C_INUSE;
401 __bin_chunk(split);
402 return CHUNK_TO_MEM(self);
403 }
404
405 lock(mal.split_merge_lock);
406
407 size_t nsize = next->csize & C_INUSE ? 0 : CHUNK_SIZE(next);
408 if (n0+nsize >= n) {
409 int i = bin_index(nsize);
410 lock_bin(i);
411 if (!(next->csize & C_INUSE)) {
412 unbin(next, i);
413 unlock_bin(i);
414 next = NEXT_CHUNK(next);
415 self->csize = next->psize = n0+nsize | C_INUSE;
416 trim(self, n);
417 unlock(mal.split_merge_lock);
418 return CHUNK_TO_MEM(self);
419 }
420 unlock_bin(i);
421 }
422 unlock(mal.split_merge_lock);
423
424copy_realloc:
425 /* As a last resort, allocate a new chunk and copy to it. */
426 new = malloc(n-OVERHEAD);
427 if (!new) return 0;
428copy_free_ret:
429 memcpy(new, p, (n<n0 ? n : n0) - OVERHEAD);
430 free(CHUNK_TO_MEM(self));
431 return new;
432}
433
434void __bin_chunk(struct chunk *self)
435{
436 struct chunk *next = NEXT_CHUNK(self);
437
438 /* Crash on corrupted footer (likely from buffer overflow) */
439 if (next->psize != self->csize) a_crash();
440
441 lock(mal.split_merge_lock);
442
443 size_t osize = CHUNK_SIZE(self), size = osize;
444
445 /* Since we hold split_merge_lock, only transition from free to
446 * in-use can race; in-use to free is impossible */
447 size_t psize = self->psize & C_INUSE ? 0 : CHUNK_PSIZE(self);
448 size_t nsize = next->csize & C_INUSE ? 0 : CHUNK_SIZE(next);
449
450 if (psize) {
451 int i = bin_index(psize);
452 lock_bin(i);
453 if (!(self->psize & C_INUSE)) {
454 struct chunk *prev = PREV_CHUNK(self);
455 unbin(prev, i);
456 self = prev;
457 size += psize;
458 }
459 unlock_bin(i);
460 }
461 if (nsize) {
462 int i = bin_index(nsize);
463 lock_bin(i);
464 if (!(next->csize & C_INUSE)) {
465 unbin(next, i);
466 next = NEXT_CHUNK(next);
467 size += nsize;
468 }
469 unlock_bin(i);
470 }
471
472 int i = bin_index(size);
473 lock_bin(i);
474
475 self->csize = size;
476 next->psize = size;
477 bin_chunk(self, i);
478 unlock(mal.split_merge_lock);
479
480 /* Replace middle of large chunks with fresh zero pages */
481 if (size > RECLAIM && (size^(size-osize)) > size-osize) {
482 uintptr_t a = (uintptr_t)self + SIZE_ALIGN+PAGE_SIZE-1 & -PAGE_SIZE;
483 uintptr_t b = (uintptr_t)next - SIZE_ALIGN & -PAGE_SIZE;
484 int e = errno;
485#if 1
486 __madvise((void *)a, b-a, MADV_DONTNEED);
487#else
488 __mmap((void *)a, b-a, PROT_READ|PROT_WRITE,
489 MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0);
490#endif
491 errno = e;
492 }
493
494 unlock_bin(i);
495}
496
497static void unmap_chunk(struct chunk *self)
498{
499 size_t extra = self->psize;
500 char *base = (char *)self - extra;
501 size_t len = CHUNK_SIZE(self) + extra;
502 /* Crash on double free */
503 if (extra & 1) a_crash();
504 int e = errno;
505 __munmap(base, len);
506 errno = e;
507}
508
509void free(void *p)
510{
511 if (!p) return;
512
513 struct chunk *self = MEM_TO_CHUNK(p);
514
515 if (IS_MMAPPED(self))
516 unmap_chunk(self);
517 else
518 __bin_chunk(self);
519}
520
521void __malloc_donate(char *start, char *end)
522{
523 size_t align_start_up = (SIZE_ALIGN-1) & (-(uintptr_t)start - OVERHEAD);
524 size_t align_end_down = (SIZE_ALIGN-1) & (uintptr_t)end;
525
526 /* Getting past this condition ensures that the padding for alignment
527 * and header overhead will not overflow and will leave a nonzero
528 * multiple of SIZE_ALIGN bytes between start and end. */
529 if (end - start <= OVERHEAD + align_start_up + align_end_down)
530 return;
531 start += align_start_up + OVERHEAD;
532 end -= align_end_down;
533
534 struct chunk *c = MEM_TO_CHUNK(start), *n = MEM_TO_CHUNK(end);
535 c->psize = n->csize = C_INUSE;
536 c->csize = n->psize = C_INUSE | (end-start);
537 __bin_chunk(c);
538}
539
540void __malloc_atfork(int who)
541{
542 if (who<0) {
543 lock(mal.split_merge_lock);
544 for (int i=0; i<64; i++)
545 lock(mal.bins[i].lock);
546 } else if (!who) {
547 for (int i=0; i<64; i++)
548 unlock(mal.bins[i].lock);
549 unlock(mal.split_merge_lock);
550 } else {
551 for (int i=0; i<64; i++)
552 mal.bins[i].lock[0] = mal.bins[i].lock[1] = 0;
553 mal.split_merge_lock[1] = 0;
554 mal.split_merge_lock[0] = 0;
555 }
556}
lib/libc/wasi/libc-top-half/musl/src/malloc/oldmalloc/malloc_usable_size.c deleted-9
......@@ -1,9 +0,0 @@
1#include <malloc.h>
2#include "malloc_impl.h"
3
4hidden void *(*const __realloc_dep)(void *, size_t) = realloc;
5
6size_t malloc_usable_size(void *p)
7{
8 return p ? CHUNK_SIZE(MEM_TO_CHUNK(p)) - OVERHEAD : 0;
9}
lib/libc/wasi/libc-top-half/musl/src/malloc/posix_memalign.c deleted-11
......@@ -1,11 +0,0 @@
1#include <stdlib.h>
2#include <errno.h>
3
4int posix_memalign(void **res, size_t align, size_t len)
5{
6 if (align < sizeof(void *)) return EINVAL;
7 void *mem = aligned_alloc(align, len);
8 if (!mem) return errno;
9 *res = mem;
10 return 0;
11}
lib/libc/wasi/libc-top-half/musl/src/malloc/realloc.c deleted-6
......@@ -1,6 +0,0 @@
1#include <stdlib.h>
2
3void *realloc(void *p, size_t n)
4{
5 return __libc_realloc(p, n);
6}
lib/libc/wasi/libc-top-half/musl/src/malloc/reallocarray.c deleted-13
......@@ -1,13 +0,0 @@
1#define _BSD_SOURCE
2#include <errno.h>
3#include <stdlib.h>
4
5void *reallocarray(void *ptr, size_t m, size_t n)
6{
7 if (n && m > -1 / n) {
8 errno = ENOMEM;
9 return 0;
10 }
11
12 return realloc(ptr, m * n);
13}
lib/libc/wasi/libc-top-half/musl/src/malloc/replaced.c deleted-4
......@@ -1,4 +0,0 @@
1#include "dynlink.h"
2
3int __malloc_replaced;
4int __aligned_alloc_replaced;
lib/libc/wasi/libc-top-half/musl/src/math/__fpclassify.c deleted-11
......@@ -1,11 +0,0 @@
1#include <math.h>
2#include <stdint.h>
3
4int __fpclassify(double x)
5{
6 union {double f; uint64_t i;} u = {x};
7 int e = u.i>>52 & 0x7ff;
8 if (!e) return u.i<<1 ? FP_SUBNORMAL : FP_ZERO;
9 if (e==0x7ff) return u.i<<12 ? FP_NAN : FP_INFINITE;
10 return FP_NORMAL;
11}
lib/libc/wasi/libc-top-half/musl/src/math/__fpclassifyf.c deleted-11
......@@ -1,11 +0,0 @@
1#include <math.h>
2#include <stdint.h>
3
4int __fpclassifyf(float x)
5{
6 union {float f; uint32_t i;} u = {x};
7 int e = u.i>>23 & 0xff;
8 if (!e) return u.i<<1 ? FP_SUBNORMAL : FP_ZERO;
9 if (e==0xff) return u.i<<9 ? FP_NAN : FP_INFINITE;
10 return FP_NORMAL;
11}
lib/libc/wasi/libc-top-half/musl/src/math/__fpclassifyl.c deleted-42
......@@ -1,42 +0,0 @@
1#include "libm.h"
2
3#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
4int __fpclassifyl(long double x)
5{
6 return __fpclassify(x);
7}
8#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
9int __fpclassifyl(long double x)
10{
11 union ldshape u = {x};
12 int e = u.i.se & 0x7fff;
13 int msb = u.i.m>>63;
14 if (!e && !msb)
15 return u.i.m ? FP_SUBNORMAL : FP_ZERO;
16 if (e == 0x7fff) {
17 /* The x86 variant of 80-bit extended precision only admits
18 * one representation of each infinity, with the mantissa msb
19 * necessarily set. The version with it clear is invalid/nan.
20 * The m68k variant, however, allows either, and tooling uses
21 * the version with it clear. */
22 if (__BYTE_ORDER == __LITTLE_ENDIAN && !msb)
23 return FP_NAN;
24 return u.i.m << 1 ? FP_NAN : FP_INFINITE;
25 }
26 if (!msb)
27 return FP_NAN;
28 return FP_NORMAL;
29}
30#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
31int __fpclassifyl(long double x)
32{
33 union ldshape u = {x};
34 int e = u.i.se & 0x7fff;
35 u.i.se = 0;
36 if (!e)
37 return u.i2.lo | u.i2.hi ? FP_SUBNORMAL : FP_ZERO;
38 if (e == 0x7fff)
39 return u.i2.lo | u.i2.hi ? FP_NAN : FP_INFINITE;
40 return FP_NORMAL;
41}
42#endif
lib/libc/wasi/libc-top-half/musl/src/math/__signbit.c deleted-13
......@@ -1,13 +0,0 @@
1#include "libm.h"
2
3// FIXME: macro in math.h
4int __signbit(double x)
5{
6 union {
7 double d;
8 uint64_t i;
9 } y = { x };
10 return y.i>>63;
11}
12
13
lib/libc/wasi/libc-top-half/musl/src/math/__signbitf.c deleted-11
......@@ -1,11 +0,0 @@
1#include "libm.h"
2
3// FIXME: macro in math.h
4int __signbitf(float x)
5{
6 union {
7 float f;
8 uint32_t i;
9 } y = { x };
10 return y.i>>31;
11}
lib/libc/wasi/libc-top-half/musl/src/math/__signbitl.c deleted-14
......@@ -1,14 +0,0 @@
1#include "libm.h"
2
3#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
4int __signbitl(long double x)
5{
6 union ldshape u = {x};
7 return u.i.se >> 15;
8}
9#elif LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
10int __signbitl(long double x)
11{
12 return __signbit(x);
13}
14#endif
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/ceil.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double ceil(double x)
4{
5 __asm__ ("frintp %d0, %d1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/ceilf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float ceilf(float x)
4{
5 __asm__ ("frintp %s0, %s1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fabs.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double fabs(double x)
4{
5 __asm__ ("fabs %d0, %d1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fabsf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float fabsf(float x)
4{
5 __asm__ ("fabs %s0, %s1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/floor.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double floor(double x)
4{
5 __asm__ ("frintm %d0, %d1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/floorf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float floorf(float x)
4{
5 __asm__ ("frintm %s0, %s1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fma.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double fma(double x, double y, double z)
4{
5 __asm__ ("fmadd %d0, %d1, %d2, %d3" : "=w"(x) : "w"(x), "w"(y), "w"(z));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fmaf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float fmaf(float x, float y, float z)
4{
5 __asm__ ("fmadd %s0, %s1, %s2, %s3" : "=w"(x) : "w"(x), "w"(y), "w"(z));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fmax.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double fmax(double x, double y)
4{
5 __asm__ ("fmaxnm %d0, %d1, %d2" : "=w"(x) : "w"(x), "w"(y));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fmaxf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float fmaxf(float x, float y)
4{
5 __asm__ ("fmaxnm %s0, %s1, %s2" : "=w"(x) : "w"(x), "w"(y));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fmin.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double fmin(double x, double y)
4{
5 __asm__ ("fminnm %d0, %d1, %d2" : "=w"(x) : "w"(x), "w"(y));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fminf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float fminf(float x, float y)
4{
5 __asm__ ("fminnm %s0, %s1, %s2" : "=w"(x) : "w"(x), "w"(y));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/llrint.c deleted-10
......@@ -1,10 +0,0 @@
1#include <math.h>
2
3long long llrint(double x)
4{
5 long long n;
6 __asm__ (
7 "frintx %d1, %d1\n"
8 "fcvtzs %x0, %d1\n" : "=r"(n), "+w"(x));
9 return n;
10}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/llrintf.c deleted-10
......@@ -1,10 +0,0 @@
1#include <math.h>
2
3long long llrintf(float x)
4{
5 long long n;
6 __asm__ (
7 "frintx %s1, %s1\n"
8 "fcvtzs %x0, %s1\n" : "=r"(n), "+w"(x));
9 return n;
10}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/llround.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long long llround(double x)
4{
5 long long n;
6 __asm__ ("fcvtas %x0, %d1" : "=r"(n) : "w"(x));
7 return n;
8}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/llroundf.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long long llroundf(float x)
4{
5 long long n;
6 __asm__ ("fcvtas %x0, %s1" : "=r"(n) : "w"(x));
7 return n;
8}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/lrint.c deleted-10
......@@ -1,10 +0,0 @@
1#include <math.h>
2
3long lrint(double x)
4{
5 long n;
6 __asm__ (
7 "frintx %d1, %d1\n"
8 "fcvtzs %x0, %d1\n" : "=r"(n), "+w"(x));
9 return n;
10}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/lrintf.c deleted-10
......@@ -1,10 +0,0 @@
1#include <math.h>
2
3long lrintf(float x)
4{
5 long n;
6 __asm__ (
7 "frintx %s1, %s1\n"
8 "fcvtzs %x0, %s1\n" : "=r"(n), "+w"(x));
9 return n;
10}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/lround.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long lround(double x)
4{
5 long n;
6 __asm__ ("fcvtas %x0, %d1" : "=r"(n) : "w"(x));
7 return n;
8}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/lroundf.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long lroundf(float x)
4{
5 long n;
6 __asm__ ("fcvtas %x0, %s1" : "=r"(n) : "w"(x));
7 return n;
8}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/nearbyint.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double nearbyint(double x)
4{
5 __asm__ ("frinti %d0, %d1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/nearbyintf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float nearbyintf(float x)
4{
5 __asm__ ("frinti %s0, %s1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/rint.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double rint(double x)
4{
5 __asm__ ("frintx %d0, %d1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/rintf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float rintf(float x)
4{
5 __asm__ ("frintx %s0, %s1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/round.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double round(double x)
4{
5 __asm__ ("frinta %d0, %d1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/roundf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float roundf(float x)
4{
5 __asm__ ("frinta %s0, %s1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/sqrt.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double sqrt(double x)
4{
5 __asm__ ("fsqrt %d0, %d1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/sqrtf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float sqrtf(float x)
4{
5 __asm__ ("fsqrt %s0, %s1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/trunc.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double trunc(double x)
4{
5 __asm__ ("frintz %d0, %d1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/truncf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float truncf(float x)
4{
5 __asm__ ("frintz %s0, %s1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/arm/fabs.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if __ARM_PCS_VFP && __ARM_FP&8
4
5double fabs(double x)
6{
7 __asm__ ("vabs.f64 %P0, %P1" : "=w"(x) : "w"(x));
8 return x;
9}
10
11#else
12
13#include "../fabs.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/arm/fabsf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if __ARM_PCS_VFP && !BROKEN_VFP_ASM
4
5float fabsf(float x)
6{
7 __asm__ ("vabs.f32 %0, %1" : "=t"(x) : "t"(x));
8 return x;
9}
10
11#else
12
13#include "../fabsf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/arm/fma.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if __ARM_FEATURE_FMA && __ARM_FP&8 && !__SOFTFP__
4
5double fma(double x, double y, double z)
6{
7 __asm__ ("vfma.f64 %P0, %P1, %P2" : "+w"(z) : "w"(x), "w"(y));
8 return z;
9}
10
11#else
12
13#include "../fma.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/arm/fmaf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if __ARM_FEATURE_FMA && __ARM_FP&4 && !__SOFTFP__ && !BROKEN_VFP_ASM
4
5float fmaf(float x, float y, float z)
6{
7 __asm__ ("vfma.f32 %0, %1, %2" : "+t"(z) : "t"(x), "t"(y));
8 return z;
9}
10
11#else
12
13#include "../fmaf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/arm/sqrt.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if (__ARM_PCS_VFP || (__VFP_FP__ && !__SOFTFP__)) && (__ARM_FP&8)
4
5double sqrt(double x)
6{
7 __asm__ ("vsqrt.f64 %P0, %P1" : "=w"(x) : "w"(x));
8 return x;
9}
10
11#else
12
13#include "../sqrt.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/arm/sqrtf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if (__ARM_PCS_VFP || (__VFP_FP__ && !__SOFTFP__)) && !BROKEN_VFP_ASM
4
5float sqrtf(float x)
6{
7 __asm__ ("vsqrt.f32 %0, %1" : "=t"(x) : "t"(x));
8 return x;
9}
10
11#else
12
13#include "../sqrtf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/ceil.c deleted-31
......@@ -1,31 +0,0 @@
1#include "libm.h"
2
3#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
4#define EPS DBL_EPSILON
5#elif FLT_EVAL_METHOD==2
6#define EPS LDBL_EPSILON
7#endif
8static const double_t toint = 1/EPS;
9
10double ceil(double x)
11{
12 union {double f; uint64_t i;} u = {x};
13 int e = u.i >> 52 & 0x7ff;
14 double_t y;
15
16 if (e >= 0x3ff+52 || x == 0)
17 return x;
18 /* y = int(x) - x, where int(x) is an integer neighbor of x */
19 if (u.i >> 63)
20 y = x - toint + toint - x;
21 else
22 y = x + toint - toint - x;
23 /* special case because of non-nearest rounding modes */
24 if (e <= 0x3ff-1) {
25 FORCE_EVAL(y);
26 return u.i >> 63 ? -0.0 : 1;
27 }
28 if (y < 0)
29 return x + y + 1;
30 return x + y;
31}
lib/libc/wasi/libc-top-half/musl/src/math/ceilf.c deleted-27
......@@ -1,27 +0,0 @@
1#include "libm.h"
2
3float ceilf(float x)
4{
5 union {float f; uint32_t i;} u = {x};
6 int e = (int)(u.i >> 23 & 0xff) - 0x7f;
7 uint32_t m;
8
9 if (e >= 23)
10 return x;
11 if (e >= 0) {
12 m = 0x007fffff >> e;
13 if ((u.i & m) == 0)
14 return x;
15 FORCE_EVAL(x + 0x1p120f);
16 if (u.i >> 31 == 0)
17 u.i += m;
18 u.i &= ~m;
19 } else {
20 FORCE_EVAL(x + 0x1p120f);
21 if (u.i >> 31)
22 u.f = -0.0;
23 else if (u.i << 1)
24 u.f = 1.0;
25 }
26 return u.f;
27}
lib/libc/wasi/libc-top-half/musl/src/math/copysign.c deleted-8
......@@ -1,8 +0,0 @@
1#include "libm.h"
2
3double copysign(double x, double y) {
4 union {double f; uint64_t i;} ux={x}, uy={y};
5 ux.i &= -1ULL/2;
6 ux.i |= uy.i & 1ULL<<63;
7 return ux.f;
8}
lib/libc/wasi/libc-top-half/musl/src/math/copysignf.c deleted-10
......@@ -1,10 +0,0 @@
1#include <math.h>
2#include <stdint.h>
3
4float copysignf(float x, float y)
5{
6 union {float f; uint32_t i;} ux={x}, uy={y};
7 ux.i &= 0x7fffffff;
8 ux.i |= uy.i & 0x80000000;
9 return ux.f;
10}
lib/libc/wasi/libc-top-half/musl/src/math/fabs.c deleted-9
......@@ -1,9 +0,0 @@
1#include <math.h>
2#include <stdint.h>
3
4double fabs(double x)
5{
6 union {double f; uint64_t i;} u = {x};
7 u.i &= -1ULL/2;
8 return u.f;
9}
lib/libc/wasi/libc-top-half/musl/src/math/fabsf.c deleted-9
......@@ -1,9 +0,0 @@
1#include <math.h>
2#include <stdint.h>
3
4float fabsf(float x)
5{
6 union {float f; uint32_t i;} u = {x};
7 u.i &= 0x7fffffff;
8 return u.f;
9}
lib/libc/wasi/libc-top-half/musl/src/math/floor.c deleted-31
......@@ -1,31 +0,0 @@
1#include "libm.h"
2
3#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
4#define EPS DBL_EPSILON
5#elif FLT_EVAL_METHOD==2
6#define EPS LDBL_EPSILON
7#endif
8static const double_t toint = 1/EPS;
9
10double floor(double x)
11{
12 union {double f; uint64_t i;} u = {x};
13 int e = u.i >> 52 & 0x7ff;
14 double_t y;
15
16 if (e >= 0x3ff+52 || x == 0)
17 return x;
18 /* y = int(x) - x, where int(x) is an integer neighbor of x */
19 if (u.i >> 63)
20 y = x - toint + toint - x;
21 else
22 y = x + toint - toint - x;
23 /* special case because of non-nearest rounding modes */
24 if (e <= 0x3ff-1) {
25 FORCE_EVAL(y);
26 return u.i >> 63 ? -1 : 0;
27 }
28 if (y > 0)
29 return x + y - 1;
30 return x + y;
31}
lib/libc/wasi/libc-top-half/musl/src/math/floorf.c deleted-27
......@@ -1,27 +0,0 @@
1#include "libm.h"
2
3float floorf(float x)
4{
5 union {float f; uint32_t i;} u = {x};
6 int e = (int)(u.i >> 23 & 0xff) - 0x7f;
7 uint32_t m;
8
9 if (e >= 23)
10 return x;
11 if (e >= 0) {
12 m = 0x007fffff >> e;
13 if ((u.i & m) == 0)
14 return x;
15 FORCE_EVAL(x + 0x1p120f);
16 if (u.i >> 31)
17 u.i += m;
18 u.i &= ~m;
19 } else {
20 FORCE_EVAL(x + 0x1p120f);
21 if (u.i >> 31 == 0)
22 u.i = 0;
23 else if (u.i << 1)
24 u.f = -1.0;
25 }
26 return u.f;
27}
lib/libc/wasi/libc-top-half/musl/src/math/fmax.c deleted-13
......@@ -1,13 +0,0 @@
1#include <math.h>
2
3double fmax(double x, double y)
4{
5 if (isnan(x))
6 return y;
7 if (isnan(y))
8 return x;
9 /* handle signed zeros, see C99 Annex F.9.9.2 */
10 if (signbit(x) != signbit(y))
11 return signbit(x) ? y : x;
12 return x < y ? y : x;
13}
lib/libc/wasi/libc-top-half/musl/src/math/fmaxf.c deleted-13
......@@ -1,13 +0,0 @@
1#include <math.h>
2
3float fmaxf(float x, float y)
4{
5 if (isnan(x))
6 return y;
7 if (isnan(y))
8 return x;
9 /* handle signed zeroes, see C99 Annex F.9.9.2 */
10 if (signbit(x) != signbit(y))
11 return signbit(x) ? y : x;
12 return x < y ? y : x;
13}
lib/libc/wasi/libc-top-half/musl/src/math/fmin.c deleted-13
......@@ -1,13 +0,0 @@
1#include <math.h>
2
3double fmin(double x, double y)
4{
5 if (isnan(x))
6 return y;
7 if (isnan(y))
8 return x;
9 /* handle signed zeros, see C99 Annex F.9.9.2 */
10 if (signbit(x) != signbit(y))
11 return signbit(x) ? x : y;
12 return x < y ? x : y;
13}
lib/libc/wasi/libc-top-half/musl/src/math/fminf.c deleted-13
......@@ -1,13 +0,0 @@
1#include <math.h>
2
3float fminf(float x, float y)
4{
5 if (isnan(x))
6 return y;
7 if (isnan(y))
8 return x;
9 /* handle signed zeros, see C99 Annex F.9.9.2 */
10 if (signbit(x) != signbit(y))
11 return signbit(x) ? x : y;
12 return x < y ? x : y;
13}
lib/libc/wasi/libc-top-half/musl/src/math/i386/__invtrigl.s deleted
lib/libc/wasi/libc-top-half/musl/src/math/i386/acos.s deleted-18
......@@ -1,18 +0,0 @@
1# use acos(x) = atan2(fabs(sqrt((1-x)*(1+x))), x)
2
3.global acos
4.type acos,@function
5acos:
6 fldl 4(%esp)
7 fld %st(0)
8 fld1
9 fsub %st(0),%st(1)
10 fadd %st(2)
11 fmulp
12 fsqrt
13 fabs # fix sign of zero (matters in downward rounding mode)
14 fxch %st(1)
15 fpatan
16 fstpl 4(%esp)
17 fldl 4(%esp)
18 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/acosf.s deleted-16
......@@ -1,16 +0,0 @@
1.global acosf
2.type acosf,@function
3acosf:
4 flds 4(%esp)
5 fld %st(0)
6 fld1
7 fsub %st(0),%st(1)
8 fadd %st(2)
9 fmulp
10 fsqrt
11 fabs # fix sign of zero (matters in downward rounding mode)
12 fxch %st(1)
13 fpatan
14 fstps 4(%esp)
15 flds 4(%esp)
16 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/acosl.s deleted-14
......@@ -1,14 +0,0 @@
1.global acosl
2.type acosl,@function
3acosl:
4 fldt 4(%esp)
5 fld %st(0)
6 fld1
7 fsub %st(0),%st(1)
8 fadd %st(2)
9 fmulp
10 fsqrt
11 fabs # fix sign of zero (matters in downward rounding mode)
12 fxch %st(1)
13 fpatan
14 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/asin.s deleted-21
......@@ -1,21 +0,0 @@
1.global asin
2.type asin,@function
3asin:
4 fldl 4(%esp)
5 mov 8(%esp),%eax
6 add %eax,%eax
7 cmp $0x00200000,%eax
8 jb 1f
9 fld %st(0)
10 fld1
11 fsub %st(0),%st(1)
12 fadd %st(2)
13 fmulp
14 fsqrt
15 fpatan
16 fstpl 4(%esp)
17 fldl 4(%esp)
18 ret
19 # subnormal x, return x with underflow
201: fsts 4(%esp)
21 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/asinf.s deleted-23
......@@ -1,23 +0,0 @@
1.global asinf
2.type asinf,@function
3asinf:
4 flds 4(%esp)
5 mov 4(%esp),%eax
6 add %eax,%eax
7 cmp $0x01000000,%eax
8 jb 1f
9 fld %st(0)
10 fld1
11 fsub %st(0),%st(1)
12 fadd %st(2)
13 fmulp
14 fsqrt
15 fpatan
16 fstps 4(%esp)
17 flds 4(%esp)
18 ret
19 # subnormal x, return x with underflow
201: fld %st(0)
21 fmul %st(1)
22 fstps 4(%esp)
23 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/asinl.s deleted-12
......@@ -1,12 +0,0 @@
1.global asinl
2.type asinl,@function
3asinl:
4 fldt 4(%esp)
5 fld %st(0)
6 fld1
7 fsub %st(0),%st(1)
8 fadd %st(2)
9 fmulp
10 fsqrt
11 fpatan
12 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/atan.s deleted-16
......@@ -1,16 +0,0 @@
1.global atan
2.type atan,@function
3atan:
4 fldl 4(%esp)
5 mov 8(%esp),%eax
6 add %eax,%eax
7 cmp $0x00200000,%eax
8 jb 1f
9 fld1
10 fpatan
11 fstpl 4(%esp)
12 fldl 4(%esp)
13 ret
14 # subnormal x, return x with underflow
151: fsts 4(%esp)
16 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/atan2.s deleted-15
......@@ -1,15 +0,0 @@
1.global atan2
2.type atan2,@function
3atan2:
4 fldl 4(%esp)
5 fldl 12(%esp)
6 fpatan
7 fstpl 4(%esp)
8 fldl 4(%esp)
9 mov 8(%esp),%eax
10 add %eax,%eax
11 cmp $0x00200000,%eax
12 jae 1f
13 # subnormal x, return x with underflow
14 fsts 4(%esp)
151: ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/atan2f.s deleted-17
......@@ -1,17 +0,0 @@
1.global atan2f
2.type atan2f,@function
3atan2f:
4 flds 4(%esp)
5 flds 8(%esp)
6 fpatan
7 fstps 4(%esp)
8 flds 4(%esp)
9 mov 4(%esp),%eax
10 add %eax,%eax
11 cmp $0x01000000,%eax
12 jae 1f
13 # subnormal x, return x with underflow
14 fld %st(0)
15 fmul %st(1)
16 fstps 4(%esp)
171: ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/atan2l.s deleted-7
......@@ -1,7 +0,0 @@
1.global atan2l
2.type atan2l,@function
3atan2l:
4 fldt 4(%esp)
5 fldt 16(%esp)
6 fpatan
7 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/atanf.s deleted-18
......@@ -1,18 +0,0 @@
1.global atanf
2.type atanf,@function
3atanf:
4 flds 4(%esp)
5 mov 4(%esp),%eax
6 add %eax,%eax
7 cmp $0x01000000,%eax
8 jb 1f
9 fld1
10 fpatan
11 fstps 4(%esp)
12 flds 4(%esp)
13 ret
14 # subnormal x, return x with underflow
151: fld %st(0)
16 fmul %st(1)
17 fstps 4(%esp)
18 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/atanl.s deleted-7
......@@ -1,7 +0,0 @@
1.global atanl
2.type atanl,@function
3atanl:
4 fldt 4(%esp)
5 fld1
6 fpatan
7 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/ceil.s deleted-1
......@@ -1 +0,0 @@
1# see floor.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/ceilf.s deleted-1
......@@ -1 +0,0 @@
1# see floor.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/ceill.s deleted-1
......@@ -1 +0,0 @@
1# see floor.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/exp2l.s deleted-1
......@@ -1 +0,0 @@
1# see exp_ld.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/exp_ld.s deleted-93
......@@ -1,93 +0,0 @@
1.global expm1l
2.type expm1l,@function
3expm1l:
4 fldt 4(%esp)
5 fldl2e
6 fmulp
7 mov $0xc2820000,%eax
8 push %eax
9 flds (%esp)
10 pop %eax
11 fucomp %st(1)
12 fnstsw %ax
13 sahf
14 fld1
15 jb 1f
16 # x*log2e < -65, return -1 without underflow
17 fstp %st(1)
18 fchs
19 ret
201: fld %st(1)
21 fabs
22 fucom %st(1)
23 fnstsw %ax
24 fstp %st(0)
25 fstp %st(0)
26 sahf
27 ja 1f
28 f2xm1
29 ret
301: call 1f
31 fld1
32 fsubrp
33 ret
34
35.global exp2l
36.global __exp2l
37.hidden __exp2l
38.type exp2l,@function
39exp2l:
40__exp2l:
41 fldt 4(%esp)
421: sub $12,%esp
43 fld %st(0)
44 fstpt (%esp)
45 mov 8(%esp),%ax
46 and $0x7fff,%ax
47 cmp $0x3fff+13,%ax
48 jb 4f # |x| < 8192
49 cmp $0x3fff+15,%ax
50 jae 3f # |x| >= 32768
51 fsts (%esp)
52 cmpl $0xc67ff800,(%esp)
53 jb 2f # x > -16382
54 movl $0x5f000000,(%esp)
55 flds (%esp) # 0x1p63
56 fld %st(1)
57 fsub %st(1)
58 faddp
59 fucomp %st(1)
60 fnstsw
61 sahf
62 je 2f # x - 0x1p63 + 0x1p63 == x
63 movl $1,(%esp)
64 flds (%esp) # 0x1p-149
65 fdiv %st(1)
66 fstps (%esp) # raise underflow
672: fld1
68 fld %st(1)
69 frndint
70 fxch %st(2)
71 fsub %st(2) # st(0)=x-rint(x), st(1)=1, st(2)=rint(x)
72 f2xm1
73 faddp # 2^(x-rint(x))
741: fscale
75 fstp %st(1)
76 add $12,%esp
77 ret
783: xor %eax,%eax
794: cmp $0x3fff-64,%ax
80 fld1
81 jb 1b # |x| < 0x1p-64
82 fstpt (%esp)
83 fistl 8(%esp)
84 fildl 8(%esp)
85 fsubrp %st(1)
86 addl $0x3fff,8(%esp)
87 f2xm1
88 fld1
89 faddp # 2^(x-rint(x))
90 fldt (%esp) # 2^rint(x)
91 fmulp
92 add $12,%esp
93 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/expl.s deleted-101
......@@ -1,101 +0,0 @@
1# exp(x) = 2^hi + 2^hi (2^lo - 1)
2# where hi+lo = log2e*x with 128bit precision
3# exact log2e*x calculation depends on nearest rounding mode
4# using the exact multiplication method of Dekker and Veltkamp
5
6.global expl
7.type expl,@function
8expl:
9 fldt 4(%esp)
10
11 # interesting case: 0x1p-32 <= |x| < 16384
12 # check if (exponent|0x8000) is in [0xbfff-32, 0xbfff+13]
13 mov 12(%esp), %ax
14 or $0x8000, %ax
15 sub $0xbfdf, %ax
16 cmp $45, %ax
17 jbe 2f
18 test %ax, %ax
19 fld1
20 js 1f
21 # if |x|>=0x1p14 or nan return 2^trunc(x)
22 fscale
23 fstp %st(1)
24 ret
25 # if |x|<0x1p-32 return 1+x
261: faddp
27 ret
28
29 # should be 0x1.71547652b82fe178p0L == 0x3fff b8aa3b29 5c17f0bc
30 # it will be wrong on non-nearest rounding mode
312: fldl2e
32 subl $44, %esp
33 # hi = log2e_hi*x
34 # 2^hi = exp2l(hi)
35 fmul %st(1),%st
36 fld %st(0)
37 fstpt (%esp)
38 fstpt 16(%esp)
39 fstpt 32(%esp)
40.hidden __exp2l
41 call __exp2l
42 # if 2^hi == inf return 2^hi
43 fld %st(0)
44 fstpt (%esp)
45 cmpw $0x7fff, 8(%esp)
46 je 1f
47 fldt 32(%esp)
48 fldt 16(%esp)
49 # fpu stack: 2^hi x hi
50 # exact mult: x*log2e
51 fld %st(1)
52 # c = 0x1p32+1
53 pushl $0x41f00000
54 pushl $0x00100000
55 fldl (%esp)
56 # xh = x - c*x + c*x
57 # xl = x - xh
58 fmulp
59 fld %st(2)
60 fsub %st(1), %st
61 faddp
62 fld %st(2)
63 fsub %st(1), %st
64 # yh = log2e_hi - c*log2e_hi + c*log2e_hi
65 pushl $0x3ff71547
66 pushl $0x65200000
67 fldl (%esp)
68 # fpu stack: 2^hi x hi xh xl yh
69 # lo = hi - xh*yh + xl*yh
70 fld %st(2)
71 fmul %st(1), %st
72 fsubp %st, %st(4)
73 fmul %st(1), %st
74 faddp %st, %st(3)
75 # yl = log2e_hi - yh
76 pushl $0x3de705fc
77 pushl $0x2f000000
78 fldl (%esp)
79 # fpu stack: 2^hi x lo xh xl yl
80 # lo += xh*yl + xl*yl
81 fmul %st, %st(2)
82 fmulp %st, %st(1)
83 fxch %st(2)
84 faddp
85 faddp
86 # log2e_lo
87 pushl $0xbfbe
88 pushl $0x82f0025f
89 pushl $0x2dc582ee
90 fldt (%esp)
91 addl $36,%esp
92 # fpu stack: 2^hi x lo log2e_lo
93 # lo += log2e_lo*x
94 # return 2^hi + 2^hi (2^lo - 1)
95 fmulp %st, %st(2)
96 faddp
97 f2xm1
98 fmul %st(1), %st
99 faddp
1001: addl $44, %esp
101 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/expm1l.s deleted-1
......@@ -1 +0,0 @@
1# see exp_ld.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/fabs.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double fabs(double x)
4{
5 __asm__ ("fabs" : "+t"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/i386/fabsf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float fabsf(float x)
4{
5 __asm__ ("fabs" : "+t"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/i386/fabsl.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3long double fabsl(long double x)
4{
5 __asm__ ("fabs" : "+t"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/i386/floor.s deleted-67
......@@ -1,67 +0,0 @@
1.global floorf
2.type floorf,@function
3floorf:
4 flds 4(%esp)
5 jmp 1f
6
7.global floorl
8.type floorl,@function
9floorl:
10 fldt 4(%esp)
11 jmp 1f
12
13.global floor
14.type floor,@function
15floor:
16 fldl 4(%esp)
171: mov $0x7,%al
181: fstcw 4(%esp)
19 mov 5(%esp),%ah
20 mov %al,5(%esp)
21 fldcw 4(%esp)
22 frndint
23 mov %ah,5(%esp)
24 fldcw 4(%esp)
25 ret
26
27.global ceil
28.type ceil,@function
29ceil:
30 fldl 4(%esp)
31 mov $0xb,%al
32 jmp 1b
33
34.global ceilf
35.type ceilf,@function
36ceilf:
37 flds 4(%esp)
38 mov $0xb,%al
39 jmp 1b
40
41.global ceill
42.type ceill,@function
43ceill:
44 fldt 4(%esp)
45 mov $0xb,%al
46 jmp 1b
47
48.global trunc
49.type trunc,@function
50trunc:
51 fldl 4(%esp)
52 mov $0xf,%al
53 jmp 1b
54
55.global truncf
56.type truncf,@function
57truncf:
58 flds 4(%esp)
59 mov $0xf,%al
60 jmp 1b
61
62.global truncl
63.type truncl,@function
64truncl:
65 fldt 4(%esp)
66 mov $0xf,%al
67 jmp 1b
lib/libc/wasi/libc-top-half/musl/src/math/i386/floorf.s deleted-1
......@@ -1 +0,0 @@
1# see floor.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/floorl.s deleted-1
......@@ -1 +0,0 @@
1# see floor.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/fmod.c deleted-10
......@@ -1,10 +0,0 @@
1#include <math.h>
2
3double fmod(double x, double y)
4{
5 unsigned short fpsr;
6 // fprem does not introduce excess precision into x
7 do __asm__ ("fprem; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y));
8 while (fpsr & 0x400);
9 return x;
10}
lib/libc/wasi/libc-top-half/musl/src/math/i386/fmodf.c deleted-10
......@@ -1,10 +0,0 @@
1#include <math.h>
2
3float fmodf(float x, float y)
4{
5 unsigned short fpsr;
6 // fprem does not introduce excess precision into x
7 do __asm__ ("fprem; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y));
8 while (fpsr & 0x400);
9 return x;
10}
lib/libc/wasi/libc-top-half/musl/src/math/i386/fmodl.c deleted-9
......@@ -1,9 +0,0 @@
1#include <math.h>
2
3long double fmodl(long double x, long double y)
4{
5 unsigned short fpsr;
6 do __asm__ ("fprem; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y));
7 while (fpsr & 0x400);
8 return x;
9}
lib/libc/wasi/libc-top-half/musl/src/math/i386/hypot.s deleted-45
......@@ -1,45 +0,0 @@
1.global hypot
2.type hypot,@function
3hypot:
4 mov 8(%esp),%eax
5 mov 16(%esp),%ecx
6 add %eax,%eax
7 add %ecx,%ecx
8 and %eax,%ecx
9 cmp $0xffe00000,%ecx
10 jae 2f
11 or 4(%esp),%eax
12 jnz 1f
13 fldl 12(%esp)
14 fabs
15 ret
161: mov 16(%esp),%eax
17 add %eax,%eax
18 or 12(%esp),%eax
19 jnz 1f
20 fldl 4(%esp)
21 fabs
22 ret
231: fldl 4(%esp)
24 fld %st(0)
25 fmulp
26 fldl 12(%esp)
27 fld %st(0)
28 fmulp
29 faddp
30 fsqrt
31 ret
322: sub $0xffe00000,%eax
33 or 4(%esp),%eax
34 jnz 1f
35 fldl 4(%esp)
36 fabs
37 ret
381: mov 16(%esp),%eax
39 add %eax,%eax
40 sub $0xffe00000,%eax
41 or 12(%esp),%eax
42 fldl 12(%esp)
43 jnz 1f
44 fabs
451: ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/hypotf.s deleted-42
......@@ -1,42 +0,0 @@
1.global hypotf
2.type hypotf,@function
3hypotf:
4 mov 4(%esp),%eax
5 mov 8(%esp),%ecx
6 add %eax,%eax
7 add %ecx,%ecx
8 and %eax,%ecx
9 cmp $0xff000000,%ecx
10 jae 2f
11 test %eax,%eax
12 jnz 1f
13 flds 8(%esp)
14 fabs
15 ret
161: mov 8(%esp),%eax
17 add %eax,%eax
18 jnz 1f
19 flds 4(%esp)
20 fabs
21 ret
221: flds 4(%esp)
23 fld %st(0)
24 fmulp
25 flds 8(%esp)
26 fld %st(0)
27 fmulp
28 faddp
29 fsqrt
30 ret
312: cmp $0xff000000,%eax
32 jnz 1f
33 flds 4(%esp)
34 fabs
35 ret
361: mov 8(%esp),%eax
37 add %eax,%eax
38 cmp $0xff000000,%eax
39 flds 8(%esp)
40 jnz 1f
41 fabs
421: ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/ldexp.s deleted-1
......@@ -1 +0,0 @@
1# see scalbn.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/ldexpf.s deleted-1
......@@ -1 +0,0 @@
1# see scalbnf.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/ldexpl.s deleted-1
......@@ -1 +0,0 @@
1# see scalbnl.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/llrint.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long long llrint(double x)
4{
5 long long r;
6 __asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st");
7 return r;
8}
lib/libc/wasi/libc-top-half/musl/src/math/i386/llrintf.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long long llrintf(float x)
4{
5 long long r;
6 __asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st");
7 return r;
8}
lib/libc/wasi/libc-top-half/musl/src/math/i386/llrintl.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long long llrintl(long double x)
4{
5 long long r;
6 __asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st");
7 return r;
8}
lib/libc/wasi/libc-top-half/musl/src/math/i386/log.s deleted-9
......@@ -1,9 +0,0 @@
1.global log
2.type log,@function
3log:
4 fldln2
5 fldl 4(%esp)
6 fyl2x
7 fstpl 4(%esp)
8 fldl 4(%esp)
9 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/log10.s deleted-9
......@@ -1,9 +0,0 @@
1.global log10
2.type log10,@function
3log10:
4 fldlg2
5 fldl 4(%esp)
6 fyl2x
7 fstpl 4(%esp)
8 fldl 4(%esp)
9 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/log10f.s deleted-9
......@@ -1,9 +0,0 @@
1.global log10f
2.type log10f,@function
3log10f:
4 fldlg2
5 flds 4(%esp)
6 fyl2x
7 fstps 4(%esp)
8 flds 4(%esp)
9 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/log10l.s deleted-7
......@@ -1,7 +0,0 @@
1.global log10l
2.type log10l,@function
3log10l:
4 fldlg2
5 fldt 4(%esp)
6 fyl2x
7 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/log1p.s deleted-25
......@@ -1,25 +0,0 @@
1.global log1p
2.type log1p,@function
3log1p:
4 mov 8(%esp),%eax
5 fldln2
6 and $0x7fffffff,%eax
7 fldl 4(%esp)
8 cmp $0x3fd28f00,%eax
9 ja 1f
10 cmp $0x00100000,%eax
11 jb 2f
12 fyl2xp1
13 fstpl 4(%esp)
14 fldl 4(%esp)
15 ret
161: fld1
17 faddp
18 fyl2x
19 fstpl 4(%esp)
20 fldl 4(%esp)
21 ret
22 # subnormal x, return x with underflow
232: fsts 4(%esp)
24 fstp %st(1)
25 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/log1pf.s deleted-26
......@@ -1,26 +0,0 @@
1.global log1pf
2.type log1pf,@function
3log1pf:
4 mov 4(%esp),%eax
5 fldln2
6 and $0x7fffffff,%eax
7 flds 4(%esp)
8 cmp $0x3e940000,%eax
9 ja 1f
10 cmp $0x00800000,%eax
11 jb 2f
12 fyl2xp1
13 fstps 4(%esp)
14 flds 4(%esp)
15 ret
161: fld1
17 faddp
18 fyl2x
19 fstps 4(%esp)
20 flds 4(%esp)
21 ret
22 # subnormal x, return x with underflow
232: fxch
24 fmul %st(1)
25 fstps 4(%esp)
26 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/log1pl.s deleted-15
......@@ -1,15 +0,0 @@
1.global log1pl
2.type log1pl,@function
3log1pl:
4 mov 10(%esp),%eax
5 fldln2
6 and $0x7fffffff,%eax
7 fldt 4(%esp)
8 cmp $0x3ffd9400,%eax
9 ja 1f
10 fyl2xp1
11 ret
121: fld1
13 faddp
14 fyl2x
15 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/log2.s deleted-9
......@@ -1,9 +0,0 @@
1.global log2
2.type log2,@function
3log2:
4 fld1
5 fldl 4(%esp)
6 fyl2x
7 fstpl 4(%esp)
8 fldl 4(%esp)
9 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/log2f.s deleted-9
......@@ -1,9 +0,0 @@
1.global log2f
2.type log2f,@function
3log2f:
4 fld1
5 flds 4(%esp)
6 fyl2x
7 fstps 4(%esp)
8 flds 4(%esp)
9 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/log2l.s deleted-7
......@@ -1,7 +0,0 @@
1.global log2l
2.type log2l,@function
3log2l:
4 fld1
5 fldt 4(%esp)
6 fyl2x
7 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/logf.s deleted-9
......@@ -1,9 +0,0 @@
1.global logf
2.type logf,@function
3logf:
4 fldln2
5 flds 4(%esp)
6 fyl2x
7 fstps 4(%esp)
8 flds 4(%esp)
9 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/logl.s deleted-7
......@@ -1,7 +0,0 @@
1.global logl
2.type logl,@function
3logl:
4 fldln2
5 fldt 4(%esp)
6 fyl2x
7 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/lrint.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long lrint(double x)
4{
5 long r;
6 __asm__ ("fistpl %0" : "=m"(r) : "t"(x) : "st");
7 return r;
8}
lib/libc/wasi/libc-top-half/musl/src/math/i386/lrintf.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long lrintf(float x)
4{
5 long r;
6 __asm__ ("fistpl %0" : "=m"(r) : "t"(x) : "st");
7 return r;
8}
lib/libc/wasi/libc-top-half/musl/src/math/i386/lrintl.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long lrintl(long double x)
4{
5 long r;
6 __asm__ ("fistpl %0" : "=m"(r) : "t"(x) : "st");
7 return r;
8}
lib/libc/wasi/libc-top-half/musl/src/math/i386/remainder.c deleted-12
......@@ -1,12 +0,0 @@
1#include <math.h>
2
3double remainder(double x, double y)
4{
5 unsigned short fpsr;
6 // fprem1 does not introduce excess precision into x
7 do __asm__ ("fprem1; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y));
8 while (fpsr & 0x400);
9 return x;
10}
11
12weak_alias(remainder, drem);
lib/libc/wasi/libc-top-half/musl/src/math/i386/remainderf.c deleted-12
......@@ -1,12 +0,0 @@
1#include <math.h>
2
3float remainderf(float x, float y)
4{
5 unsigned short fpsr;
6 // fprem1 does not introduce excess precision into x
7 do __asm__ ("fprem1; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y));
8 while (fpsr & 0x400);
9 return x;
10}
11
12weak_alias(remainderf, dremf);
lib/libc/wasi/libc-top-half/musl/src/math/i386/remainderl.c deleted-9
......@@ -1,9 +0,0 @@
1#include <math.h>
2
3long double remainderl(long double x, long double y)
4{
5 unsigned short fpsr;
6 do __asm__ ("fprem1; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y));
7 while (fpsr & 0x400);
8 return x;
9}
lib/libc/wasi/libc-top-half/musl/src/math/i386/remquo.s deleted-50
......@@ -1,50 +0,0 @@
1.global remquof
2.type remquof,@function
3remquof:
4 mov 12(%esp),%ecx
5 flds 8(%esp)
6 flds 4(%esp)
7 mov 11(%esp),%dh
8 xor 7(%esp),%dh
9 jmp 1f
10
11.global remquol
12.type remquol,@function
13remquol:
14 mov 28(%esp),%ecx
15 fldt 16(%esp)
16 fldt 4(%esp)
17 mov 25(%esp),%dh
18 xor 13(%esp),%dh
19 jmp 1f
20
21.global remquo
22.type remquo,@function
23remquo:
24 mov 20(%esp),%ecx
25 fldl 12(%esp)
26 fldl 4(%esp)
27 mov 19(%esp),%dh
28 xor 11(%esp),%dh
291: fprem1
30 fnstsw %ax
31 sahf
32 jp 1b
33 fstp %st(1)
34 mov %ah,%dl
35 shr %dl
36 and $1,%dl
37 mov %ah,%al
38 shr $5,%al
39 and $2,%al
40 or %al,%dl
41 mov %ah,%al
42 shl $2,%al
43 and $4,%al
44 or %al,%dl
45 test %dh,%dh
46 jns 1f
47 neg %dl
481: movsbl %dl,%edx
49 mov %edx,(%ecx)
50 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/remquof.s deleted-1
......@@ -1 +0,0 @@
1# see remquo.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/remquol.s deleted-1
......@@ -1 +0,0 @@
1# see remquo.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/rint.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double rint(double x)
4{
5 __asm__ ("frndint" : "+t"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/i386/rintf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float rintf(float x)
4{
5 __asm__ ("frndint" : "+t"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/i386/rintl.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3long double rintl(long double x)
4{
5 __asm__ ("frndint" : "+t"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/i386/scalbln.s deleted-1
......@@ -1 +0,0 @@
1# see scalbn.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/scalblnf.s deleted-1
......@@ -1 +0,0 @@
1# see scalbnf.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/scalblnl.s deleted-1
......@@ -1 +0,0 @@
1# see scalbnl.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/scalbn.s deleted-33
......@@ -1,33 +0,0 @@
1.global ldexp
2.type ldexp,@function
3ldexp:
4 nop
5
6.global scalbln
7.type scalbln,@function
8scalbln:
9 nop
10
11.global scalbn
12.type scalbn,@function
13scalbn:
14 mov 12(%esp),%eax
15 add $0x3ffe,%eax
16 cmp $0x7ffd,%eax
17 jb 1f
18 sub $0x3ffe,%eax
19 sar $31,%eax
20 xor $0xfff,%eax
21 add $0x3ffe,%eax
221: inc %eax
23 fldl 4(%esp)
24 mov %eax,12(%esp)
25 mov $0x80000000,%eax
26 mov %eax,8(%esp)
27 xor %eax,%eax
28 mov %eax,4(%esp)
29 fldt 4(%esp)
30 fmulp
31 fstpl 4(%esp)
32 fldl 4(%esp)
33 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/scalbnf.s deleted-32
......@@ -1,32 +0,0 @@
1.global ldexpf
2.type ldexpf,@function
3ldexpf:
4 nop
5
6.global scalblnf
7.type scalblnf,@function
8scalblnf:
9 nop
10
11.global scalbnf
12.type scalbnf,@function
13scalbnf:
14 mov 8(%esp),%eax
15 add $0x3fe,%eax
16 cmp $0x7fd,%eax
17 jb 1f
18 sub $0x3fe,%eax
19 sar $31,%eax
20 xor $0x1ff,%eax
21 add $0x3fe,%eax
221: inc %eax
23 shl $20,%eax
24 flds 4(%esp)
25 mov %eax,8(%esp)
26 xor %eax,%eax
27 mov %eax,4(%esp)
28 fldl 4(%esp)
29 fmulp
30 fstps 4(%esp)
31 flds 4(%esp)
32 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/scalbnl.s deleted-32
......@@ -1,32 +0,0 @@
1.global ldexpl
2.type ldexpl,@function
3ldexpl:
4 nop
5
6.global scalblnl
7.type scalblnl,@function
8scalblnl:
9 nop
10
11.global scalbnl
12.type scalbnl,@function
13scalbnl:
14 mov 16(%esp),%eax
15 add $0x3ffe,%eax
16 cmp $0x7ffd,%eax
17 jae 1f
18 inc %eax
19 fldt 4(%esp)
20 mov %eax,12(%esp)
21 mov $0x80000000,%eax
22 mov %eax,8(%esp)
23 xor %eax,%eax
24 mov %eax,4(%esp)
25 fldt 4(%esp)
26 fmulp
27 ret
281: fildl 16(%esp)
29 fldt 4(%esp)
30 fscale
31 fstp %st(1)
32 ret
lib/libc/wasi/libc-top-half/musl/src/math/i386/sqrt.c deleted-15
......@@ -1,15 +0,0 @@
1#include "libm.h"
2
3double sqrt(double x)
4{
5 union ldshape ux;
6 unsigned fpsr;
7 __asm__ ("fsqrt; fnstsw %%ax": "=t"(ux.f), "=a"(fpsr) : "0"(x));
8 if ((ux.i.m & 0x7ff) != 0x400)
9 return (double)ux.f;
10 /* Rounding to double would have encountered an exact halfway case.
11 Adjust mantissa downwards if fsqrt rounded up, else upwards.
12 (result of fsqrt could not have been exact) */
13 ux.i.m ^= (fpsr & 0x200) + 0x300;
14 return (double)ux.f;
15}
lib/libc/wasi/libc-top-half/musl/src/math/i386/sqrtf.c deleted-12
......@@ -1,12 +0,0 @@
1#include <math.h>
2
3float sqrtf(float x)
4{
5 long double t;
6 /* The long double result has sufficient precision so that
7 * second rounding to float still keeps the returned value
8 * correctly rounded, see Pierre Roux, "Innocuous Double
9 * Rounding of Basic Arithmetic Operations". */
10 __asm__ ("fsqrt" : "=t"(t) : "0"(x));
11 return (float)t;
12}
lib/libc/wasi/libc-top-half/musl/src/math/i386/sqrtl.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3long double sqrtl(long double x)
4{
5 __asm__ ("fsqrt" : "+t"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/i386/trunc.s deleted-1
......@@ -1 +0,0 @@
1# see floor.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/truncf.s deleted-1
......@@ -1 +0,0 @@
1# see floor.s
lib/libc/wasi/libc-top-half/musl/src/math/i386/truncl.s deleted-1
......@@ -1 +0,0 @@
1# see floor.s
lib/libc/wasi/libc-top-half/musl/src/math/m68k/sqrtl.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if __HAVE_68881__
4
5long double sqrtl(long double x)
6{
7 __asm__ ("fsqrt.x %1,%0" : "=f"(x) : "fm"(x));
8 return x;
9}
10
11#else
12
13#include "../sqrtl.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/mips/fabs.c deleted-16
......@@ -1,16 +0,0 @@
1#if !defined(__mips_soft_float) && defined(__mips_abs2008)
2
3#include <math.h>
4
5double fabs(double x)
6{
7 double r;
8 __asm__("abs.d %0,%1" : "=f"(r) : "f"(x));
9 return r;
10}
11
12#else
13
14#include "../fabs.c"
15
16#endif
lib/libc/wasi/libc-top-half/musl/src/math/mips/fabsf.c deleted-16
......@@ -1,16 +0,0 @@
1#if !defined(__mips_soft_float) && defined(__mips_abs2008)
2
3#include <math.h>
4
5float fabsf(float x)
6{
7 float r;
8 __asm__("abs.s %0,%1" : "=f"(r) : "f"(x));
9 return r;
10}
11
12#else
13
14#include "../fabsf.c"
15
16#endif
lib/libc/wasi/libc-top-half/musl/src/math/mips/sqrt.c deleted-16
......@@ -1,16 +0,0 @@
1#if !defined(__mips_soft_float) && __mips >= 3
2
3#include <math.h>
4
5double sqrt(double x)
6{
7 double r;
8 __asm__("sqrt.d %0,%1" : "=f"(r) : "f"(x));
9 return r;
10}
11
12#else
13
14#include "../sqrt.c"
15
16#endif
lib/libc/wasi/libc-top-half/musl/src/math/mips/sqrtf.c deleted-16
......@@ -1,16 +0,0 @@
1#if !defined(__mips_soft_float) && __mips >= 2
2
3#include <math.h>
4
5float sqrtf(float x)
6{
7 float r;
8 __asm__("sqrt.s %0,%1" : "=f"(r) : "f"(x));
9 return r;
10}
11
12#else
13
14#include "../sqrtf.c"
15
16#endif
lib/libc/wasi/libc-top-half/musl/src/math/nearbyint.c deleted-20
......@@ -1,20 +0,0 @@
1#include <fenv.h>
2#include <math.h>
3
4/* nearbyint is the same as rint, but it must not raise the inexact exception */
5
6double nearbyint(double x)
7{
8#ifdef FE_INEXACT
9 #pragma STDC FENV_ACCESS ON
10 int e;
11
12 e = fetestexcept(FE_INEXACT);
13#endif
14 x = rint(x);
15#ifdef FE_INEXACT
16 if (!e)
17 feclearexcept(FE_INEXACT);
18#endif
19 return x;
20}
lib/libc/wasi/libc-top-half/musl/src/math/nearbyintf.c deleted-18
......@@ -1,18 +0,0 @@
1#include <fenv.h>
2#include <math.h>
3
4float nearbyintf(float x)
5{
6#ifdef FE_INEXACT
7 #pragma STDC FENV_ACCESS ON
8 int e;
9
10 e = fetestexcept(FE_INEXACT);
11#endif
12 x = rintf(x);
13#ifdef FE_INEXACT
14 if (!e)
15 feclearexcept(FE_INEXACT);
16#endif
17 return x;
18}
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/fabs.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__) || defined(BROKEN_PPC_D_ASM)
4
5#include "../fabs.c"
6
7#else
8
9double fabs(double x)
10{
11 __asm__ ("fabs %0, %1" : "=d"(x) : "d"(x));
12 return x;
13}
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/fabsf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
4
5#include "../fabsf.c"
6
7#else
8
9float fabsf(float x)
10{
11 __asm__ ("fabs %0, %1" : "=f"(x) : "f"(x));
12 return x;
13}
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/fma.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__) || defined(BROKEN_PPC_D_ASM)
4
5#include "../fma.c"
6
7#else
8
9double fma(double x, double y, double z)
10{
11 __asm__("fmadd %0, %1, %2, %3" : "=d"(x) : "d"(x), "d"(y), "d"(z));
12 return x;
13}
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/fmaf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
4
5#include "../fmaf.c"
6
7#else
8
9float fmaf(float x, float y, float z)
10{
11 __asm__("fmadds %0, %1, %2, %3" : "=f"(x) : "f"(x), "f"(y), "f"(z));
12 return x;
13}
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/sqrt.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if !defined _SOFT_FLOAT && defined _ARCH_PPCSQ
4
5double sqrt(double x)
6{
7 __asm__ ("fsqrt %0, %1\n" : "=d" (x) : "d" (x));
8 return x;
9}
10
11#else
12
13#include "../sqrt.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/sqrtf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if !defined _SOFT_FLOAT && defined _ARCH_PPCSQ
4
5float sqrtf(float x)
6{
7 __asm__ ("fsqrts %0, %1\n" : "=f" (x) : "f" (x));
8 return x;
9}
10
11#else
12
13#include "../sqrtf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/ceil.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#ifdef _ARCH_PWR5X
4
5double ceil(double x)
6{
7 __asm__ ("frip %0, %1" : "=d"(x) : "d"(x));
8 return x;
9}
10
11#else
12
13#include "../ceil.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/ceilf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#ifdef _ARCH_PWR5X
4
5float ceilf(float x)
6{
7 __asm__ ("frip %0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../ceilf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fabs.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double fabs(double x)
4{
5 __asm__ ("fabs %0, %1" : "=d"(x) : "d"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fabsf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float fabsf(float x)
4{
5 __asm__ ("fabs %0, %1" : "=f"(x) : "f"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/floor.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#ifdef _ARCH_PWR5X
4
5double floor(double x)
6{
7 __asm__ ("frim %0, %1" : "=d"(x) : "d"(x));
8 return x;
9}
10
11#else
12
13#include "../floor.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/floorf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#ifdef _ARCH_PWR5X
4
5float floorf(float x)
6{
7 __asm__ ("frim %0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../floorf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fma.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double fma(double x, double y, double z)
4{
5 __asm__ ("fmadd %0, %1, %2, %3" : "=d"(x) : "d"(x), "d"(y), "d"(z));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fmaf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float fmaf(float x, float y, float z)
4{
5 __asm__ ("fmadds %0, %1, %2, %3" : "=f"(x) : "f"(x), "f"(y), "f"(z));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fmax.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#ifdef __VSX__
4
5double fmax(double x, double y)
6{
7 __asm__ ("xsmaxdp %x0, %x1, %x2" : "=ws"(x) : "ws"(x), "ws"(y));
8 return x;
9}
10
11#else
12
13#include "../fmax.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fmaxf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#ifdef __VSX__
4
5float fmaxf(float x, float y)
6{
7 __asm__ ("xsmaxdp %x0, %x1, %x2" : "=ww"(x) : "ww"(x), "ww"(y));
8 return x;
9}
10
11#else
12
13#include "../fmaxf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fmin.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#ifdef __VSX__
4
5double fmin(double x, double y)
6{
7 __asm__ ("xsmindp %x0, %x1, %x2" : "=ws"(x) : "ws"(x), "ws"(y));
8 return x;
9}
10
11#else
12
13#include "../fmin.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fminf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#ifdef __VSX__
4
5float fminf(float x, float y)
6{
7 __asm__ ("xsmindp %x0, %x1, %x2" : "=ww"(x) : "ww"(x), "ww"(y));
8 return x;
9}
10
11#else
12
13#include "../fminf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/lrint.c deleted-16
......@@ -1,16 +0,0 @@
1#include <math.h>
2
3#ifdef _ARCH_PWR5X
4
5long lrint(double x)
6{
7 long n;
8 __asm__ ("fctid %0, %1" : "=d"(n) : "d"(x));
9 return n;
10}
11
12#else
13
14#include "../lrint.c"
15
16#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/lrintf.c deleted-16
......@@ -1,16 +0,0 @@
1#include <math.h>
2
3#ifdef _ARCH_PWR5X
4
5long lrintf(float x)
6{
7 long n;
8 __asm__ ("fctid %0, %1" : "=d"(n) : "f"(x));
9 return n;
10}
11
12#else
13
14#include "../lrintf.c"
15
16#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/lround.c deleted-18
......@@ -1,18 +0,0 @@
1#include <math.h>
2
3#ifdef __VSX__
4
5long lround(double x)
6{
7 long n;
8 __asm__ (
9 "xsrdpi %1, %1\n"
10 "fctid %0, %1\n" : "=d"(n), "+d"(x));
11 return n;
12}
13
14#else
15
16#include "../lround.c"
17
18#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/lroundf.c deleted-18
......@@ -1,18 +0,0 @@
1#include <math.h>
2
3#ifdef __VSX__
4
5long lroundf(float x)
6{
7 long n;
8 __asm__ (
9 "xsrdpi %1, %1\n"
10 "fctid %0, %1\n" : "=d"(n), "+f"(x));
11 return n;
12}
13
14#else
15
16#include "../lroundf.c"
17
18#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/round.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#ifdef _ARCH_PWR5X
4
5double round(double x)
6{
7 __asm__ ("frin %0, %1" : "=d"(x) : "d"(x));
8 return x;
9}
10
11#else
12
13#include "../round.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/roundf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#ifdef _ARCH_PWR5X
4
5float roundf(float x)
6{
7 __asm__ ("frin %0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../roundf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/sqrt.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double sqrt(double x)
4{
5 __asm__ ("fsqrt %0, %1" : "=d"(x) : "d"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/sqrtf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float sqrtf(float x)
4{
5 __asm__ ("fsqrts %0, %1" : "=f"(x) : "f"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/trunc.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#ifdef _ARCH_PWR5X
4
5double trunc(double x)
6{
7 __asm__ ("friz %0, %1" : "=d"(x) : "d"(x));
8 return x;
9}
10
11#else
12
13#include "../trunc.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/truncf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#ifdef _ARCH_PWR5X
4
5float truncf(float x)
6{
7 __asm__ ("friz %0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../truncf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/rint.c deleted-28
......@@ -1,28 +0,0 @@
1#include <float.h>
2#include <math.h>
3#include <stdint.h>
4
5#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
6#define EPS DBL_EPSILON
7#elif FLT_EVAL_METHOD==2
8#define EPS LDBL_EPSILON
9#endif
10static const double_t toint = 1/EPS;
11
12double rint(double x)
13{
14 union {double f; uint64_t i;} u = {x};
15 int e = u.i>>52 & 0x7ff;
16 int s = u.i>>63;
17 double_t y;
18
19 if (e >= 0x3ff+52)
20 return x;
21 if (s)
22 y = x - toint + toint;
23 else
24 y = x + toint - toint;
25 if (y == 0)
26 return s ? -0.0 : 0;
27 return y;
28}
lib/libc/wasi/libc-top-half/musl/src/math/rintf.c deleted-30
......@@ -1,30 +0,0 @@
1#include <float.h>
2#include <math.h>
3#include <stdint.h>
4
5#if FLT_EVAL_METHOD==0
6#define EPS FLT_EPSILON
7#elif FLT_EVAL_METHOD==1
8#define EPS DBL_EPSILON
9#elif FLT_EVAL_METHOD==2
10#define EPS LDBL_EPSILON
11#endif
12static const float_t toint = 1/EPS;
13
14float rintf(float x)
15{
16 union {float f; uint32_t i;} u = {x};
17 int e = u.i>>23 & 0xff;
18 int s = u.i>>31;
19 float_t y;
20
21 if (e >= 0x7f+23)
22 return x;
23 if (s)
24 y = x - toint + toint;
25 else
26 y = x + toint - toint;
27 if (y == 0)
28 return s ? -0.0f : 0.0f;
29 return y;
30}
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/copysign.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if __riscv_flen >= 64
4
5double copysign(double x, double y)
6{
7 __asm__ ("fsgnj.d %0, %1, %2" : "=f"(x) : "f"(x), "f"(y));
8 return x;
9}
10
11#else
12
13#include "../copysign.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/copysignf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if __riscv_flen >= 32
4
5float copysignf(float x, float y)
6{
7 __asm__ ("fsgnj.s %0, %1, %2" : "=f"(x) : "f"(x), "f"(y));
8 return x;
9}
10
11#else
12
13#include "../copysignf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fabs.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if __riscv_flen >= 64
4
5double fabs(double x)
6{
7 __asm__ ("fabs.d %0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../fabs.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fabsf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if __riscv_flen >= 32
4
5float fabsf(float x)
6{
7 __asm__ ("fabs.s %0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../fabsf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fma.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if __riscv_flen >= 64
4
5double fma(double x, double y, double z)
6{
7 __asm__ ("fmadd.d %0, %1, %2, %3" : "=f"(x) : "f"(x), "f"(y), "f"(z));
8 return x;
9}
10
11#else
12
13#include "../fma.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fmaf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if __riscv_flen >= 32
4
5float fmaf(float x, float y, float z)
6{
7 __asm__ ("fmadd.s %0, %1, %2, %3" : "=f"(x) : "f"(x), "f"(y), "f"(z));
8 return x;
9}
10
11#else
12
13#include "../fmaf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fmax.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if __riscv_flen >= 64
4
5double fmax(double x, double y)
6{
7 __asm__ ("fmax.d %0, %1, %2" : "=f"(x) : "f"(x), "f"(y));
8 return x;
9}
10
11#else
12
13#include "../fmax.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fmaxf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if __riscv_flen >= 32
4
5float fmaxf(float x, float y)
6{
7 __asm__ ("fmax.s %0, %1, %2" : "=f"(x) : "f"(x), "f"(y));
8 return x;
9}
10
11#else
12
13#include "../fmaxf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fmin.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if __riscv_flen >= 64
4
5double fmin(double x, double y)
6{
7 __asm__ ("fmin.d %0, %1, %2" : "=f"(x) : "f"(x), "f"(y));
8 return x;
9}
10
11#else
12
13#include "../fmin.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fminf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if __riscv_flen >= 32
4
5float fminf(float x, float y)
6{
7 __asm__ ("fmin.s %0, %1, %2" : "=f"(x) : "f"(x), "f"(y));
8 return x;
9}
10
11#else
12
13#include "../fminf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/sqrt.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if __riscv_flen >= 64
4
5double sqrt(double x)
6{
7 __asm__ ("fsqrt.d %0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../sqrt.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/sqrtf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if __riscv_flen >= 32
4
5float sqrtf(float x)
6{
7 __asm__ ("fsqrt.s %0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../sqrtf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/ceil.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5double ceil(double x)
6{
7 __asm__ ("fidbra %0, 6, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../ceil.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/ceilf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5float ceilf(float x)
6{
7 __asm__ ("fiebra %0, 6, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../ceilf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/ceill.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5long double ceill(long double x)
6{
7 __asm__ ("fixbra %0, 6, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../ceill.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/fabs.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5double fabs(double x)
6{
7 __asm__ ("lpdbr %0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../fabs.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/fabsf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5float fabsf(float x)
6{
7 __asm__ ("lpebr %0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../fabsf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/fabsl.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5long double fabsl(long double x)
6{
7 __asm__ ("lpxbr %0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../fabsl.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/floor.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5double floor(double x)
6{
7 __asm__ ("fidbra %0, 7, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../floor.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/floorf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5float floorf(float x)
6{
7 __asm__ ("fiebra %0, 7, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../floorf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/floorl.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5long double floorl(long double x)
6{
7 __asm__ ("fixbra %0, 7, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../floorl.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/fma.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double fma(double x, double y, double z)
4{
5 __asm__ ("madbr %0, %1, %2" : "+f"(z) : "f"(x), "f"(y));
6 return z;
7}
lib/libc/wasi/libc-top-half/musl/src/math/s390x/fmaf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float fmaf(float x, float y, float z)
4{
5 __asm__ ("maebr %0, %1, %2" : "+f"(z) : "f"(x), "f"(y));
6 return z;
7}
lib/libc/wasi/libc-top-half/musl/src/math/s390x/nearbyint.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5double nearbyint(double x)
6{
7 __asm__ ("fidbra %0, 0, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../nearbyint.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/nearbyintf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5float nearbyintf(float x)
6{
7 __asm__ ("fiebra %0, 0, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../nearbyintf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/nearbyintl.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5long double nearbyintl(long double x)
6{
7 __asm__ ("fixbra %0, 0, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../nearbyintl.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/rint.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5double rint(double x)
6{
7 __asm__ ("fidbr %0, 0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../rint.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/rintf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5float rintf(float x)
6{
7 __asm__ ("fiebr %0, 0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../rintf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/rintl.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5long double rintl(long double x)
6{
7 __asm__ ("fixbr %0, 0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../rintl.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/round.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5double round(double x)
6{
7 __asm__ ("fidbra %0, 1, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../round.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/roundf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5float roundf(float x)
6{
7 __asm__ ("fiebra %0, 1, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../roundf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/roundl.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5long double roundl(long double x)
6{
7 __asm__ ("fixbra %0, 1, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../roundl.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/sqrt.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5double sqrt(double x)
6{
7 __asm__ ("sqdbr %0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../sqrt.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/sqrtf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5float sqrtf(float x)
6{
7 __asm__ ("sqebr %0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../sqrtf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/sqrtl.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5long double sqrtl(long double x)
6{
7 __asm__ ("sqxbr %0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../sqrtl.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/trunc.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5double trunc(double x)
6{
7 __asm__ ("fidbra %0, 5, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../trunc.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/truncf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5float truncf(float x)
6{
7 __asm__ ("fiebra %0, 5, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../truncf.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/s390x/truncl.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5long double truncl(long double x)
6{
7 __asm__ ("fixbra %0, 5, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../truncl.c"
14
15#endif
lib/libc/wasi/libc-top-half/musl/src/math/sqrt.c deleted-158
......@@ -1,158 +0,0 @@
1#include <stdint.h>
2#include <math.h>
3#include "libm.h"
4#include "sqrt_data.h"
5
6#define FENV_SUPPORT 1
7
8/* returns a*b*2^-32 - e, with error 0 <= e < 1. */
9static inline uint32_t mul32(uint32_t a, uint32_t b)
10{
11 return (uint64_t)a*b >> 32;
12}
13
14/* returns a*b*2^-64 - e, with error 0 <= e < 3. */
15static inline uint64_t mul64(uint64_t a, uint64_t b)
16{
17 uint64_t ahi = a>>32;
18 uint64_t alo = a&0xffffffff;
19 uint64_t bhi = b>>32;
20 uint64_t blo = b&0xffffffff;
21 return ahi*bhi + (ahi*blo >> 32) + (alo*bhi >> 32);
22}
23
24double sqrt(double x)
25{
26 uint64_t ix, top, m;
27
28 /* special case handling. */
29 ix = asuint64(x);
30 top = ix >> 52;
31 if (predict_false(top - 0x001 >= 0x7ff - 0x001)) {
32 /* x < 0x1p-1022 or inf or nan. */
33 if (ix * 2 == 0)
34 return x;
35 if (ix == 0x7ff0000000000000)
36 return x;
37 if (ix > 0x7ff0000000000000)
38 return __math_invalid(x);
39 /* x is subnormal, normalize it. */
40 ix = asuint64(x * 0x1p52);
41 top = ix >> 52;
42 top -= 52;
43 }
44
45 /* argument reduction:
46 x = 4^e m; with integer e, and m in [1, 4)
47 m: fixed point representation [2.62]
48 2^e is the exponent part of the result. */
49 int even = top & 1;
50 m = (ix << 11) | 0x8000000000000000;
51 if (even) m >>= 1;
52 top = (top + 0x3ff) >> 1;
53
54 /* approximate r ~ 1/sqrt(m) and s ~ sqrt(m) when m in [1,4)
55
56 initial estimate:
57 7bit table lookup (1bit exponent and 6bit significand).
58
59 iterative approximation:
60 using 2 goldschmidt iterations with 32bit int arithmetics
61 and a final iteration with 64bit int arithmetics.
62
63 details:
64
65 the relative error (e = r0 sqrt(m)-1) of a linear estimate
66 (r0 = a m + b) is |e| < 0.085955 ~ 0x1.6p-4 at best,
67 a table lookup is faster and needs one less iteration
68 6 bit lookup table (128b) gives |e| < 0x1.f9p-8
69 7 bit lookup table (256b) gives |e| < 0x1.fdp-9
70 for single and double prec 6bit is enough but for quad
71 prec 7bit is needed (or modified iterations). to avoid
72 one more iteration >=13bit table would be needed (16k).
73
74 a newton-raphson iteration for r is
75 w = r*r
76 u = 3 - m*w
77 r = r*u/2
78 can use a goldschmidt iteration for s at the end or
79 s = m*r
80
81 first goldschmidt iteration is
82 s = m*r
83 u = 3 - s*r
84 r = r*u/2
85 s = s*u/2
86 next goldschmidt iteration is
87 u = 3 - s*r
88 r = r*u/2
89 s = s*u/2
90 and at the end r is not computed only s.
91
92 they use the same amount of operations and converge at the
93 same quadratic rate, i.e. if
94 r1 sqrt(m) - 1 = e, then
95 r2 sqrt(m) - 1 = -3/2 e^2 - 1/2 e^3
96 the advantage of goldschmidt is that the mul for s and r
97 are independent (computed in parallel), however it is not
98 "self synchronizing": it only uses the input m in the
99 first iteration so rounding errors accumulate. at the end
100 or when switching to larger precision arithmetics rounding
101 errors dominate so the first iteration should be used.
102
103 the fixed point representations are
104 m: 2.30 r: 0.32, s: 2.30, d: 2.30, u: 2.30, three: 2.30
105 and after switching to 64 bit
106 m: 2.62 r: 0.64, s: 2.62, d: 2.62, u: 2.62, three: 2.62 */
107
108 static const uint64_t three = 0xc0000000;
109 uint64_t r, s, d, u, i;
110
111 i = (ix >> 46) % 128;
112 r = (uint32_t)__rsqrt_tab[i] << 16;
113 /* |r sqrt(m) - 1| < 0x1.fdp-9 */
114 s = mul32(m>>32, r);
115 /* |s/sqrt(m) - 1| < 0x1.fdp-9 */
116 d = mul32(s, r);
117 u = three - d;
118 r = mul32(r, u) << 1;
119 /* |r sqrt(m) - 1| < 0x1.7bp-16 */
120 s = mul32(s, u) << 1;
121 /* |s/sqrt(m) - 1| < 0x1.7bp-16 */
122 d = mul32(s, r);
123 u = three - d;
124 r = mul32(r, u) << 1;
125 /* |r sqrt(m) - 1| < 0x1.3704p-29 (measured worst-case) */
126 r = r << 32;
127 s = mul64(m, r);
128 d = mul64(s, r);
129 u = (three<<32) - d;
130 s = mul64(s, u); /* repr: 3.61 */
131 /* -0x1p-57 < s - sqrt(m) < 0x1.8001p-61 */
132 s = (s - 2) >> 9; /* repr: 12.52 */
133 /* -0x1.09p-52 < s - sqrt(m) < -0x1.fffcp-63 */
134
135 /* s < sqrt(m) < s + 0x1.09p-52,
136 compute nearest rounded result:
137 the nearest result to 52 bits is either s or s+0x1p-52,
138 we can decide by comparing (2^52 s + 0.5)^2 to 2^104 m. */
139 uint64_t d0, d1, d2;
140 double y, t;
141 d0 = (m << 42) - s*s;
142 d1 = s - d0;
143 d2 = d1 + s + 1;
144 s += d1 >> 63;
145 s &= 0x000fffffffffffff;
146 s |= top << 52;
147 y = asdouble(s);
148 if (FENV_SUPPORT) {
149 /* handle rounding modes and inexact exception:
150 only (s+1)^2 == 2^42 m case is exact otherwise
151 add a tiny value to cause the fenv effects. */
152 uint64_t tiny = predict_false(d2==0) ? 0 : 0x0010000000000000;
153 tiny |= (d1^d2) & 0x8000000000000000;
154 t = asdouble(tiny);
155 y = eval_as_double(y + t);
156 }
157 return y;
158}
lib/libc/wasi/libc-top-half/musl/src/math/sqrtf.c deleted-83
......@@ -1,83 +0,0 @@
1#include <stdint.h>
2#include <math.h>
3#include "libm.h"
4#include "sqrt_data.h"
5
6#define FENV_SUPPORT 1
7
8static inline uint32_t mul32(uint32_t a, uint32_t b)
9{
10 return (uint64_t)a*b >> 32;
11}
12
13/* see sqrt.c for more detailed comments. */
14
15float sqrtf(float x)
16{
17 uint32_t ix, m, m1, m0, even, ey;
18
19 ix = asuint(x);
20 if (predict_false(ix - 0x00800000 >= 0x7f800000 - 0x00800000)) {
21 /* x < 0x1p-126 or inf or nan. */
22 if (ix * 2 == 0)
23 return x;
24 if (ix == 0x7f800000)
25 return x;
26 if (ix > 0x7f800000)
27 return __math_invalidf(x);
28 /* x is subnormal, normalize it. */
29 ix = asuint(x * 0x1p23f);
30 ix -= 23 << 23;
31 }
32
33 /* x = 4^e m; with int e and m in [1, 4). */
34 even = ix & 0x00800000;
35 m1 = (ix << 8) | 0x80000000;
36 m0 = (ix << 7) & 0x7fffffff;
37 m = even ? m0 : m1;
38
39 /* 2^e is the exponent part of the return value. */
40 ey = ix >> 1;
41 ey += 0x3f800000 >> 1;
42 ey &= 0x7f800000;
43
44 /* compute r ~ 1/sqrt(m), s ~ sqrt(m) with 2 goldschmidt iterations. */
45 static const uint32_t three = 0xc0000000;
46 uint32_t r, s, d, u, i;
47 i = (ix >> 17) % 128;
48 r = (uint32_t)__rsqrt_tab[i] << 16;
49 /* |r*sqrt(m) - 1| < 0x1p-8 */
50 s = mul32(m, r);
51 /* |s/sqrt(m) - 1| < 0x1p-8 */
52 d = mul32(s, r);
53 u = three - d;
54 r = mul32(r, u) << 1;
55 /* |r*sqrt(m) - 1| < 0x1.7bp-16 */
56 s = mul32(s, u) << 1;
57 /* |s/sqrt(m) - 1| < 0x1.7bp-16 */
58 d = mul32(s, r);
59 u = three - d;
60 s = mul32(s, u);
61 /* -0x1.03p-28 < s/sqrt(m) - 1 < 0x1.fp-31 */
62 s = (s - 1)>>6;
63 /* s < sqrt(m) < s + 0x1.08p-23 */
64
65 /* compute nearest rounded result. */
66 uint32_t d0, d1, d2;
67 float y, t;
68 d0 = (m << 16) - s*s;
69 d1 = s - d0;
70 d2 = d1 + s + 1;
71 s += d1 >> 31;
72 s &= 0x007fffff;
73 s |= ey;
74 y = asfloat(s);
75 if (FENV_SUPPORT) {
76 /* handle rounding and inexact exception. */
77 uint32_t tiny = predict_false(d2==0) ? 0 : 0x01000000;
78 tiny |= (d1^d2) & 0x80000000;
79 t = asfloat(tiny);
80 y = eval_as_float(y + t);
81 }
82 return y;
83}
lib/libc/wasi/libc-top-half/musl/src/math/trunc.c deleted-19
......@@ -1,19 +0,0 @@
1#include "libm.h"
2
3double trunc(double x)
4{
5 union {double f; uint64_t i;} u = {x};
6 int e = (int)(u.i >> 52 & 0x7ff) - 0x3ff + 12;
7 uint64_t m;
8
9 if (e >= 52 + 12)
10 return x;
11 if (e < 12)
12 e = 1;
13 m = -1ULL >> e;
14 if ((u.i & m) == 0)
15 return x;
16 FORCE_EVAL(x + 0x1p120f);
17 u.i &= ~m;
18 return u.f;
19}
lib/libc/wasi/libc-top-half/musl/src/math/truncf.c deleted-19
......@@ -1,19 +0,0 @@
1#include "libm.h"
2
3float truncf(float x)
4{
5 union {float f; uint32_t i;} u = {x};
6 int e = (int)(u.i >> 23 & 0xff) - 0x7f + 9;
7 uint32_t m;
8
9 if (e >= 23 + 9)
10 return x;
11 if (e < 9)
12 e = 1;
13 m = -1U >> e;
14 if ((u.i & m) == 0)
15 return x;
16 FORCE_EVAL(x + 0x1p120f);
17 u.i &= ~m;
18 return u.f;
19}
lib/libc/wasi/libc-top-half/musl/src/math/x32/__invtrigl.s deleted
lib/libc/wasi/libc-top-half/musl/src/math/x32/acosl.s deleted-16
......@@ -1,16 +0,0 @@
1# see ../i386/acos.s
2
3.global acosl
4.type acosl,@function
5acosl:
6 fldt 8(%esp)
71: fld %st(0)
8 fld1
9 fsub %st(0),%st(1)
10 fadd %st(2)
11 fmulp
12 fsqrt
13 fabs
14 fxch %st(1)
15 fpatan
16 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/asinl.s deleted-12
......@@ -1,12 +0,0 @@
1.global asinl
2.type asinl,@function
3asinl:
4 fldt 8(%esp)
51: fld %st(0)
6 fld1
7 fsub %st(0),%st(1)
8 fadd %st(2)
9 fmulp
10 fsqrt
11 fpatan
12 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/atan2l.s deleted-7
......@@ -1,7 +0,0 @@
1.global atan2l
2.type atan2l,@function
3atan2l:
4 fldt 8(%esp)
5 fldt 24(%esp)
6 fpatan
7 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/atanl.s deleted-7
......@@ -1,7 +0,0 @@
1.global atanl
2.type atanl,@function
3atanl:
4 fldt 8(%esp)
5 fld1
6 fpatan
7 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/ceill.s deleted-1
......@@ -1 +0,0 @@
1# see floorl.s
lib/libc/wasi/libc-top-half/musl/src/math/x32/exp2l.s deleted-83
......@@ -1,83 +0,0 @@
1.global expm1l
2.type expm1l,@function
3expm1l:
4 fldt 8(%esp)
5 fldl2e
6 fmulp
7 movl $0xc2820000,-4(%esp)
8 flds -4(%esp)
9 fucomip %st(1),%st
10 fld1
11 jb 1f
12 # x*log2e <= -65, return -1 without underflow
13 fstp %st(1)
14 fchs
15 ret
161: fld %st(1)
17 fabs
18 fucomip %st(1),%st
19 fstp %st(0)
20 ja 1f
21 f2xm1
22 ret
231: push %rax
24 call 1f
25 pop %rax
26 fld1
27 fsubrp
28 ret
29
30.global exp2l
31.type exp2l,@function
32exp2l:
33 fldt 8(%esp)
341: fld %st(0)
35 sub $16,%esp
36 fstpt (%esp)
37 mov 8(%esp),%ax
38 and $0x7fff,%ax
39 cmp $0x3fff+13,%ax
40 jb 4f # |x| < 8192
41 cmp $0x3fff+15,%ax
42 jae 3f # |x| >= 32768
43 fsts (%esp)
44 cmpl $0xc67ff800,(%esp)
45 jb 2f # x > -16382
46 movl $0x5f000000,(%esp)
47 flds (%esp) # 0x1p63
48 fld %st(1)
49 fsub %st(1)
50 faddp
51 fucomip %st(1),%st
52 je 2f # x - 0x1p63 + 0x1p63 == x
53 movl $1,(%esp)
54 flds (%esp) # 0x1p-149
55 fdiv %st(1)
56 fstps (%esp) # raise underflow
572: fld1
58 fld %st(1)
59 frndint
60 fxch %st(2)
61 fsub %st(2) # st(0)=x-rint(x), st(1)=1, st(2)=rint(x)
62 f2xm1
63 faddp # 2^(x-rint(x))
641: fscale
65 fstp %st(1)
66 add $16,%esp
67 ret
683: xor %eax,%eax
694: cmp $0x3fff-64,%ax
70 fld1
71 jb 1b # |x| < 0x1p-64
72 fstpt (%esp)
73 fistl 8(%esp)
74 fildl 8(%esp)
75 fsubrp %st(1)
76 addl $0x3fff,8(%esp)
77 f2xm1
78 fld1
79 faddp # 2^(x-rint(x))
80 fldt (%esp) # 2^rint(x)
81 fmulp
82 add $16,%esp
83 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/expl.s deleted-101
......@@ -1,101 +0,0 @@
1# exp(x) = 2^hi + 2^hi (2^lo - 1)
2# where hi+lo = log2e*x with 128bit precision
3# exact log2e*x calculation depends on nearest rounding mode
4# using the exact multiplication method of Dekker and Veltkamp
5
6.global expl
7.type expl,@function
8expl:
9 fldt 8(%esp)
10
11 # interesting case: 0x1p-32 <= |x| < 16384
12 # check if (exponent|0x8000) is in [0xbfff-32, 0xbfff+13]
13 mov 16(%esp), %ax
14 or $0x8000, %ax
15 sub $0xbfdf, %ax
16 cmp $45, %ax
17 jbe 2f
18 test %ax, %ax
19 fld1
20 js 1f
21 # if |x|>=0x1p14 or nan return 2^trunc(x)
22 fscale
23 fstp %st(1)
24 ret
25 # if |x|<0x1p-32 return 1+x
261: faddp
27 ret
28
29 # should be 0x1.71547652b82fe178p0L == 0x3fff b8aa3b29 5c17f0bc
30 # it will be wrong on non-nearest rounding mode
312: fldl2e
32 sub $48, %esp
33 # hi = log2e_hi*x
34 # 2^hi = exp2l(hi)
35 fmul %st(1),%st
36 fld %st(0)
37 fstpt (%esp)
38 fstpt 16(%esp)
39 fstpt 32(%esp)
40 call exp2l@PLT
41 # if 2^hi == inf return 2^hi
42 fld %st(0)
43 fstpt (%esp)
44 cmpw $0x7fff, 8(%esp)
45 je 1f
46 fldt 32(%esp)
47 fldt 16(%esp)
48 # fpu stack: 2^hi x hi
49 # exact mult: x*log2e
50 fld %st(1)
51 # c = 0x1p32+1
52 movq $0x41f0000000100000,%rax
53 pushq %rax
54 fldl (%esp)
55 # xh = x - c*x + c*x
56 # xl = x - xh
57 fmulp
58 fld %st(2)
59 fsub %st(1), %st
60 faddp
61 fld %st(2)
62 fsub %st(1), %st
63 # yh = log2e_hi - c*log2e_hi + c*log2e_hi
64 movq $0x3ff7154765200000,%rax
65 pushq %rax
66 fldl (%esp)
67 # fpu stack: 2^hi x hi xh xl yh
68 # lo = hi - xh*yh + xl*yh
69 fld %st(2)
70 fmul %st(1), %st
71 fsubp %st, %st(4)
72 fmul %st(1), %st
73 faddp %st, %st(3)
74 # yl = log2e_hi - yh
75 movq $0x3de705fc2f000000,%rax
76 pushq %rax
77 fldl (%esp)
78 # fpu stack: 2^hi x lo xh xl yl
79 # lo += xh*yl + xl*yl
80 fmul %st, %st(2)
81 fmulp %st, %st(1)
82 fxch %st(2)
83 faddp
84 faddp
85 # log2e_lo
86 movq $0xbfbe,%rax
87 pushq %rax
88 movq $0x82f0025f2dc582ee,%rax
89 pushq %rax
90 fldt (%esp)
91 add $40,%esp
92 # fpu stack: 2^hi x lo log2e_lo
93 # lo += log2e_lo*x
94 # return 2^hi + 2^hi (2^lo - 1)
95 fmulp %st, %st(2)
96 faddp
97 f2xm1
98 fmul %st(1), %st
99 faddp
1001: add $48, %esp
101 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/expm1l.s deleted-1
......@@ -1 +0,0 @@
1# see exp2l.s
lib/libc/wasi/libc-top-half/musl/src/math/x32/fabs.s deleted-9
......@@ -1,9 +0,0 @@
1.global fabs
2.type fabs,@function
3fabs:
4 xor %eax,%eax
5 dec %rax
6 shr %rax
7 movq %rax,%xmm1
8 andpd %xmm1,%xmm0
9 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/fabsf.s deleted-7
......@@ -1,7 +0,0 @@
1.global fabsf
2.type fabsf,@function
3fabsf:
4 mov $0x7fffffff,%eax
5 movq %rax,%xmm1
6 andps %xmm1,%xmm0
7 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/fabsl.s deleted-6
......@@ -1,6 +0,0 @@
1.global fabsl
2.type fabsl,@function
3fabsl:
4 fldt 8(%esp)
5 fabs
6 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/floorl.s deleted-27
......@@ -1,27 +0,0 @@
1.global floorl
2.type floorl,@function
3floorl:
4 fldt 8(%esp)
51: mov $0x7,%al
61: fstcw 8(%esp)
7 mov 9(%esp),%ah
8 mov %al,9(%esp)
9 fldcw 8(%esp)
10 frndint
11 mov %ah,9(%esp)
12 fldcw 8(%esp)
13 ret
14
15.global ceill
16.type ceill,@function
17ceill:
18 fldt 8(%esp)
19 mov $0xb,%al
20 jmp 1b
21
22.global truncl
23.type truncl,@function
24truncl:
25 fldt 8(%esp)
26 mov $0xf,%al
27 jmp 1b
lib/libc/wasi/libc-top-half/musl/src/math/x32/fma.c deleted-23
......@@ -1,23 +0,0 @@
1#include <math.h>
2
3#if __FMA__
4
5double fma(double x, double y, double z)
6{
7 __asm__ ("vfmadd132sd %1, %2, %0" : "+x" (x) : "x" (y), "x" (z));
8 return x;
9}
10
11#elif __FMA4__
12
13double fma(double x, double y, double z)
14{
15 __asm__ ("vfmaddsd %3, %2, %1, %0" : "=x" (x) : "x" (x), "x" (y), "x" (z));
16 return x;
17}
18
19#else
20
21#include "../fma.c"
22
23#endif
lib/libc/wasi/libc-top-half/musl/src/math/x32/fmaf.c deleted-23
......@@ -1,23 +0,0 @@
1#include <math.h>
2
3#if __FMA__
4
5float fmaf(float x, float y, float z)
6{
7 __asm__ ("vfmadd132ss %1, %2, %0" : "+x" (x) : "x" (y), "x" (z));
8 return x;
9}
10
11#elif __FMA4__
12
13float fmaf(float x, float y, float z)
14{
15 __asm__ ("vfmaddss %3, %2, %1, %0" : "=x" (x) : "x" (x), "x" (y), "x" (z));
16 return x;
17}
18
19#else
20
21#include "../fmaf.c"
22
23#endif
lib/libc/wasi/libc-top-half/musl/src/math/x32/fmodl.s deleted-11
......@@ -1,11 +0,0 @@
1.global fmodl
2.type fmodl,@function
3fmodl:
4 fldt 24(%esp)
5 fldt 8(%esp)
61: fprem
7 fnstsw %ax
8 testb $4,%ah
9 jnz 1b
10 fstp %st(1)
11 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/llrint.s deleted-5
......@@ -1,5 +0,0 @@
1.global llrint
2.type llrint,@function
3llrint:
4 cvtsd2si %xmm0,%rax
5 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/llrintf.s deleted-5
......@@ -1,5 +0,0 @@
1.global llrintf
2.type llrintf,@function
3llrintf:
4 cvtss2si %xmm0,%rax
5 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/llrintl.s deleted-7
......@@ -1,7 +0,0 @@
1.global llrintl
2.type llrintl,@function
3llrintl:
4 fldt 8(%esp)
5 fistpll 8(%esp)
6 mov 8(%esp),%rax
7 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/log10l.s deleted-7
......@@ -1,7 +0,0 @@
1.global log10l
2.type log10l,@function
3log10l:
4 fldlg2
5 fldt 8(%esp)
6 fyl2x
7 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/log1pl.s deleted-15
......@@ -1,15 +0,0 @@
1.global log1pl
2.type log1pl,@function
3log1pl:
4 mov 14(%esp),%eax
5 fldln2
6 and $0x7fffffff,%eax
7 fldt 8(%esp)
8 cmp $0x3ffd9400,%eax
9 ja 1f
10 fyl2xp1
11 ret
121: fld1
13 faddp
14 fyl2x
15 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/log2l.s deleted-7
......@@ -1,7 +0,0 @@
1.global log2l
2.type log2l,@function
3log2l:
4 fld1
5 fldt 8(%esp)
6 fyl2x
7 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/logl.s deleted-7
......@@ -1,7 +0,0 @@
1.global logl
2.type logl,@function
3logl:
4 fldln2
5 fldt 8(%esp)
6 fyl2x
7 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/lrint.s deleted-5
......@@ -1,5 +0,0 @@
1.global lrint
2.type lrint,@function
3lrint:
4 cvtsd2si %xmm0,%rax
5 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/lrintf.s deleted-5
......@@ -1,5 +0,0 @@
1.global lrintf
2.type lrintf,@function
3lrintf:
4 cvtss2si %xmm0,%rax
5 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/lrintl.s deleted-7
......@@ -1,7 +0,0 @@
1.global lrintl
2.type lrintl,@function
3lrintl:
4 fldt 8(%esp)
5 fistpl 8(%esp)
6 movl 8(%esp),%eax
7 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/remainderl.s deleted-11
......@@ -1,11 +0,0 @@
1.global remainderl
2.type remainderl,@function
3remainderl:
4 fldt 24(%esp)
5 fldt 8(%esp)
61: fprem1
7 fnstsw %ax
8 testb $4,%ah
9 jnz 1b
10 fstp %st(1)
11 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/rintl.s deleted-6
......@@ -1,6 +0,0 @@
1.global rintl
2.type rintl,@function
3rintl:
4 fldt 8(%esp)
5 frndint
6 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/sqrt.s deleted-4
......@@ -1,4 +0,0 @@
1.global sqrt
2.type sqrt,@function
3sqrt: sqrtsd %xmm0, %xmm0
4 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/sqrtf.s deleted-4
......@@ -1,4 +0,0 @@
1.global sqrtf
2.type sqrtf,@function
3sqrtf: sqrtss %xmm0, %xmm0
4 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/sqrtl.s deleted-5
......@@ -1,5 +0,0 @@
1.global sqrtl
2.type sqrtl,@function
3sqrtl: fldt 8(%esp)
4 fsqrt
5 ret
lib/libc/wasi/libc-top-half/musl/src/math/x32/truncl.s deleted-1
......@@ -1 +0,0 @@
1# see floorl.s
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/__invtrigl.s deleted
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/acosl.s deleted-16
......@@ -1,16 +0,0 @@
1# see ../i386/acos.s
2
3.global acosl
4.type acosl,@function
5acosl:
6 fldt 8(%rsp)
71: fld %st(0)
8 fld1
9 fsub %st(0),%st(1)
10 fadd %st(2)
11 fmulp
12 fsqrt
13 fabs
14 fxch %st(1)
15 fpatan
16 ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/asinl.s deleted-12
......@@ -1,12 +0,0 @@
1.global asinl
2.type asinl,@function
3asinl:
4 fldt 8(%rsp)
51: fld %st(0)
6 fld1
7 fsub %st(0),%st(1)
8 fadd %st(2)
9 fmulp
10 fsqrt
11 fpatan
12 ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/atan2l.s deleted-7
......@@ -1,7 +0,0 @@
1.global atan2l
2.type atan2l,@function
3atan2l:
4 fldt 8(%rsp)
5 fldt 24(%rsp)
6 fpatan
7 ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/atanl.s deleted-7
......@@ -1,7 +0,0 @@
1.global atanl
2.type atanl,@function
3atanl:
4 fldt 8(%rsp)
5 fld1
6 fpatan
7 ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/ceill.s deleted-1
......@@ -1 +0,0 @@
1# see floorl.s
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/exp2l.s deleted-83
......@@ -1,83 +0,0 @@
1.global expm1l
2.type expm1l,@function
3expm1l:
4 fldt 8(%rsp)
5 fldl2e
6 fmulp
7 movl $0xc2820000,-4(%rsp)
8 flds -4(%rsp)
9 fucomip %st(1),%st
10 fld1
11 jb 1f
12 # x*log2e <= -65, return -1 without underflow
13 fstp %st(1)
14 fchs
15 ret
161: fld %st(1)
17 fabs
18 fucomip %st(1),%st
19 fstp %st(0)
20 ja 1f
21 f2xm1
22 ret
231: push %rax
24 call 1f
25 pop %rax
26 fld1
27 fsubrp
28 ret
29
30.global exp2l
31.type exp2l,@function
32exp2l:
33 fldt 8(%rsp)
341: fld %st(0)
35 sub $16,%rsp
36 fstpt (%rsp)
37 mov 8(%rsp),%ax
38 and $0x7fff,%ax
39 cmp $0x3fff+13,%ax
40 jb 4f # |x| < 8192
41 cmp $0x3fff+15,%ax
42 jae 3f # |x| >= 32768
43 fsts (%rsp)
44 cmpl $0xc67ff800,(%rsp)
45 jb 2f # x > -16382
46 movl $0x5f000000,(%rsp)
47 flds (%rsp) # 0x1p63
48 fld %st(1)
49 fsub %st(1)
50 faddp
51 fucomip %st(1),%st
52 je 2f # x - 0x1p63 + 0x1p63 == x
53 movl $1,(%rsp)
54 flds (%rsp) # 0x1p-149
55 fdiv %st(1)
56 fstps (%rsp) # raise underflow
572: fld1
58 fld %st(1)
59 frndint
60 fxch %st(2)
61 fsub %st(2) # st(0)=x-rint(x), st(1)=1, st(2)=rint(x)
62 f2xm1
63 faddp # 2^(x-rint(x))
641: fscale
65 fstp %st(1)
66 add $16,%rsp
67 ret
683: xor %eax,%eax
694: cmp $0x3fff-64,%ax
70 fld1
71 jb 1b # |x| < 0x1p-64
72 fstpt (%rsp)
73 fistl 8(%rsp)
74 fildl 8(%rsp)
75 fsubrp %st(1)
76 addl $0x3fff,8(%rsp)
77 f2xm1
78 fld1
79 faddp # 2^(x-rint(x))
80 fldt (%rsp) # 2^rint(x)
81 fmulp
82 add $16,%rsp
83 ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/expl.s deleted-101
......@@ -1,101 +0,0 @@
1# exp(x) = 2^hi + 2^hi (2^lo - 1)
2# where hi+lo = log2e*x with 128bit precision
3# exact log2e*x calculation depends on nearest rounding mode
4# using the exact multiplication method of Dekker and Veltkamp
5
6.global expl
7.type expl,@function
8expl:
9 fldt 8(%rsp)
10
11 # interesting case: 0x1p-32 <= |x| < 16384
12 # check if (exponent|0x8000) is in [0xbfff-32, 0xbfff+13]
13 mov 16(%rsp), %ax
14 or $0x8000, %ax
15 sub $0xbfdf, %ax
16 cmp $45, %ax
17 jbe 2f
18 test %ax, %ax
19 fld1
20 js 1f
21 # if |x|>=0x1p14 or nan return 2^trunc(x)
22 fscale
23 fstp %st(1)
24 ret
25 # if |x|<0x1p-32 return 1+x
261: faddp
27 ret
28
29 # should be 0x1.71547652b82fe178p0L == 0x3fff b8aa3b29 5c17f0bc
30 # it will be wrong on non-nearest rounding mode
312: fldl2e
32 subq $48, %rsp
33 # hi = log2e_hi*x
34 # 2^hi = exp2l(hi)
35 fmul %st(1),%st
36 fld %st(0)
37 fstpt (%rsp)
38 fstpt 16(%rsp)
39 fstpt 32(%rsp)
40 call exp2l@PLT
41 # if 2^hi == inf return 2^hi
42 fld %st(0)
43 fstpt (%rsp)
44 cmpw $0x7fff, 8(%rsp)
45 je 1f
46 fldt 32(%rsp)
47 fldt 16(%rsp)
48 # fpu stack: 2^hi x hi
49 # exact mult: x*log2e
50 fld %st(1)
51 # c = 0x1p32+1
52 movq $0x41f0000000100000,%rax
53 pushq %rax
54 fldl (%rsp)
55 # xh = x - c*x + c*x
56 # xl = x - xh
57 fmulp
58 fld %st(2)
59 fsub %st(1), %st
60 faddp
61 fld %st(2)
62 fsub %st(1), %st
63 # yh = log2e_hi - c*log2e_hi + c*log2e_hi
64 movq $0x3ff7154765200000,%rax
65 pushq %rax
66 fldl (%rsp)
67 # fpu stack: 2^hi x hi xh xl yh
68 # lo = hi - xh*yh + xl*yh
69 fld %st(2)
70 fmul %st(1), %st
71 fsubp %st, %st(4)
72 fmul %st(1), %st
73 faddp %st, %st(3)
74 # yl = log2e_hi - yh
75 movq $0x3de705fc2f000000,%rax
76 pushq %rax
77 fldl (%rsp)
78 # fpu stack: 2^hi x lo xh xl yl
79 # lo += xh*yl + xl*yl
80 fmul %st, %st(2)
81 fmulp %st, %st(1)
82 fxch %st(2)
83 faddp
84 faddp
85 # log2e_lo
86 movq $0xbfbe,%rax
87 pushq %rax
88 movq $0x82f0025f2dc582ee,%rax
89 pushq %rax
90 fldt (%rsp)
91 addq $40,%rsp
92 # fpu stack: 2^hi x lo log2e_lo
93 # lo += log2e_lo*x
94 # return 2^hi + 2^hi (2^lo - 1)
95 fmulp %st, %st(2)
96 faddp
97 f2xm1
98 fmul %st(1), %st
99 faddp
1001: addq $48, %rsp
101 ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/expm1l.s deleted-1
......@@ -1 +0,0 @@
1# see exp2l.s
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/fabs.c deleted-10
......@@ -1,10 +0,0 @@
1#include <math.h>
2
3double fabs(double x)
4{
5 double t;
6 __asm__ ("pcmpeqd %0, %0" : "=x"(t)); // t = ~0
7 __asm__ ("psrlq $1, %0" : "+x"(t)); // t >>= 1
8 __asm__ ("andps %1, %0" : "+x"(x) : "x"(t)); // x &= t
9 return x;
10}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/fabsf.c deleted-10
......@@ -1,10 +0,0 @@
1#include <math.h>
2
3float fabsf(float x)
4{
5 float t;
6 __asm__ ("pcmpeqd %0, %0" : "=x"(t)); // t = ~0
7 __asm__ ("psrld $1, %0" : "+x"(t)); // t >>= 1
8 __asm__ ("andps %1, %0" : "+x"(x) : "x"(t)); // x &= t
9 return x;
10}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/fabsl.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3long double fabsl(long double x)
4{
5 __asm__ ("fabs" : "+t"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/floorl.s deleted-27
......@@ -1,27 +0,0 @@
1.global floorl
2.type floorl,@function
3floorl:
4 fldt 8(%rsp)
51: mov $0x7,%al
61: fstcw 8(%rsp)
7 mov 9(%rsp),%ah
8 mov %al,9(%rsp)
9 fldcw 8(%rsp)
10 frndint
11 mov %ah,9(%rsp)
12 fldcw 8(%rsp)
13 ret
14
15.global ceill
16.type ceill,@function
17ceill:
18 fldt 8(%rsp)
19 mov $0xb,%al
20 jmp 1b
21
22.global truncl
23.type truncl,@function
24truncl:
25 fldt 8(%rsp)
26 mov $0xf,%al
27 jmp 1b
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/fma.c deleted-23
......@@ -1,23 +0,0 @@
1#include <math.h>
2
3#if __FMA__
4
5double fma(double x, double y, double z)
6{
7 __asm__ ("vfmadd132sd %1, %2, %0" : "+x" (x) : "x" (y), "x" (z));
8 return x;
9}
10
11#elif __FMA4__
12
13double fma(double x, double y, double z)
14{
15 __asm__ ("vfmaddsd %3, %2, %1, %0" : "=x" (x) : "x" (x), "x" (y), "x" (z));
16 return x;
17}
18
19#else
20
21#include "../fma.c"
22
23#endif
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/fmaf.c deleted-23
......@@ -1,23 +0,0 @@
1#include <math.h>
2
3#if __FMA__
4
5float fmaf(float x, float y, float z)
6{
7 __asm__ ("vfmadd132ss %1, %2, %0" : "+x" (x) : "x" (y), "x" (z));
8 return x;
9}
10
11#elif __FMA4__
12
13float fmaf(float x, float y, float z)
14{
15 __asm__ ("vfmaddss %3, %2, %1, %0" : "=x" (x) : "x" (x), "x" (y), "x" (z));
16 return x;
17}
18
19#else
20
21#include "../fmaf.c"
22
23#endif
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/fmodl.c deleted-9
......@@ -1,9 +0,0 @@
1#include <math.h>
2
3long double fmodl(long double x, long double y)
4{
5 unsigned short fpsr;
6 do __asm__ ("fprem; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y));
7 while (fpsr & 0x400);
8 return x;
9}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/llrint.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long long llrint(double x)
4{
5 long long r;
6 __asm__ ("cvtsd2si %1, %0" : "=r"(r) : "x"(x));
7 return r;
8}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/llrintf.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long long llrintf(float x)
4{
5 long long r;
6 __asm__ ("cvtss2si %1, %0" : "=r"(r) : "x"(x));
7 return r;
8}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/llrintl.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long long llrintl(long double x)
4{
5 long long r;
6 __asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st");
7 return r;
8}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/log10l.s deleted-7
......@@ -1,7 +0,0 @@
1.global log10l
2.type log10l,@function
3log10l:
4 fldlg2
5 fldt 8(%rsp)
6 fyl2x
7 ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/log1pl.s deleted-15
......@@ -1,15 +0,0 @@
1.global log1pl
2.type log1pl,@function
3log1pl:
4 mov 14(%rsp),%eax
5 fldln2
6 and $0x7fffffff,%eax
7 fldt 8(%rsp)
8 cmp $0x3ffd9400,%eax
9 ja 1f
10 fyl2xp1
11 ret
121: fld1
13 faddp
14 fyl2x
15 ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/log2l.s deleted-7
......@@ -1,7 +0,0 @@
1.global log2l
2.type log2l,@function
3log2l:
4 fld1
5 fldt 8(%rsp)
6 fyl2x
7 ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/logl.s deleted-7
......@@ -1,7 +0,0 @@
1.global logl
2.type logl,@function
3logl:
4 fldln2
5 fldt 8(%rsp)
6 fyl2x
7 ret
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/lrint.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long lrint(double x)
4{
5 long r;
6 __asm__ ("cvtsd2si %1, %0" : "=r"(r) : "x"(x));
7 return r;
8}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/lrintf.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long lrintf(float x)
4{
5 long r;
6 __asm__ ("cvtss2si %1, %0" : "=r"(r) : "x"(x));
7 return r;
8}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/lrintl.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long lrintl(long double x)
4{
5 long r;
6 __asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st");
7 return r;
8}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/remainderl.c deleted-9
......@@ -1,9 +0,0 @@
1#include <math.h>
2
3long double remainderl(long double x, long double y)
4{
5 unsigned short fpsr;
6 do __asm__ ("fprem1; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y));
7 while (fpsr & 0x400);
8 return x;
9}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/remquol.c deleted-32
......@@ -1,32 +0,0 @@
1#include <math.h>
2
3long double remquol(long double x, long double y, int *quo)
4{
5 signed char *cx = (void *)&x, *cy = (void *)&y;
6 /* By ensuring that addresses of x and y cannot be discarded,
7 * this empty asm guides GCC into representing extraction of
8 * their sign bits as memory loads rather than making x and y
9 * not-address-taken internally and using bitfield operations,
10 * which in the end wouldn't work out, as extraction from FPU
11 * registers needs to go through memory anyway. This way GCC
12 * should manage to use incoming stack slots without spills. */
13 __asm__ ("" :: "X"(cx), "X"(cy));
14
15 long double t = x;
16 unsigned fpsr;
17 do __asm__ ("fprem1; fnstsw %%ax" : "+t"(t), "=a"(fpsr) : "u"(y));
18 while (fpsr & 0x400);
19 /* C0, C1, C3 flags in x87 status word carry low bits of quotient:
20 * 15 14 13 12 11 10 9 8
21 * . C3 . . . C2 C1 C0
22 * . b1 . . . 0 b0 b2 */
23 unsigned char i = fpsr >> 8;
24 i = i>>4 | i<<4;
25 /* i[5:2] is now {b0 b2 ? b1}. Retrieve {0 b2 b1 b0} via
26 * in-register table lookup. */
27 unsigned qbits = 0x7575313164642020 >> (i & 60);
28 qbits &= 7;
29
30 *quo = (cx[9]^cy[9]) < 0 ? -qbits : qbits;
31 return t;
32}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/rintl.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3long double rintl(long double x)
4{
5 __asm__ ("frndint" : "+t"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/sqrt.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double sqrt(double x)
4{
5 __asm__ ("sqrtsd %1, %0" : "=x"(x) : "x"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/sqrtf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float sqrtf(float x)
4{
5 __asm__ ("sqrtss %1, %0" : "=x"(x) : "x"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/sqrtl.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3long double sqrtl(long double x)
4{
5 __asm__ ("fsqrt" : "+t"(x));
6 return x;
7}
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/truncl.s deleted-1
......@@ -1 +0,0 @@
1# see floorl.s
lib/libc/wasi/libc-top-half/musl/src/misc/forkpty.c deleted-57
......@@ -1,57 +0,0 @@
1#include <pty.h>
2#include <utmp.h>
3#include <unistd.h>
4#include <errno.h>
5#include <fcntl.h>
6#include <sys/wait.h>
7#include <pthread.h>
8
9int forkpty(int *pm, char *name, const struct termios *tio, const struct winsize *ws)
10{
11 int m, s, ec=0, p[2], cs;
12 pid_t pid=-1;
13 sigset_t set, oldset;
14
15 if (openpty(&m, &s, name, tio, ws) < 0) return -1;
16
17 sigfillset(&set);
18 pthread_sigmask(SIG_BLOCK, &set, &oldset);
19 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
20
21 if (pipe2(p, O_CLOEXEC)) {
22 close(s);
23 goto out;
24 }
25
26 pid = fork();
27 if (!pid) {
28 close(m);
29 close(p[0]);
30 if (login_tty(s)) {
31 write(p[1], &errno, sizeof errno);
32 _exit(127);
33 }
34 close(p[1]);
35 pthread_setcancelstate(cs, 0);
36 pthread_sigmask(SIG_SETMASK, &oldset, 0);
37 return 0;
38 }
39 close(s);
40 close(p[1]);
41 if (read(p[0], &ec, sizeof ec) > 0) {
42 int status;
43 waitpid(pid, &status, 0);
44 pid = -1;
45 errno = ec;
46 }
47 close(p[0]);
48
49out:
50 if (pid > 0) *pm = m;
51 else close(m);
52
53 pthread_setcancelstate(cs, 0);
54 pthread_sigmask(SIG_SETMASK, &oldset, 0);
55
56 return pid;
57}
lib/libc/wasi/libc-top-half/musl/src/misc/get_current_dir_name.c deleted-15
......@@ -1,15 +0,0 @@
1#define _GNU_SOURCE
2#include <stdlib.h>
3#include <string.h>
4#include <limits.h>
5#include <unistd.h>
6#include <sys/stat.h>
7
8char *get_current_dir_name(void) {
9 struct stat a, b;
10 char *res = getenv("PWD");
11 if (res && *res && !stat(res, &a) && !stat(".", &b)
12 && (a.st_dev == b.st_dev) && (a.st_ino == b.st_ino))
13 return strdup(res);
14 return getcwd(0, 0);
15}
lib/libc/wasi/libc-top-half/musl/src/misc/getauxval.c deleted-15
......@@ -1,15 +0,0 @@
1#include <sys/auxv.h>
2#include <errno.h>
3#include "libc.h"
4
5unsigned long __getauxval(unsigned long item)
6{
7 size_t *auxv = libc.auxv;
8 if (item == AT_SECURE) return libc.secure;
9 for (; *auxv; auxv+=2)
10 if (*auxv==item) return auxv[1];
11 errno = ENOENT;
12 return 0;
13}
14
15weak_alias(__getauxval, getauxval);
lib/libc/wasi/libc-top-half/musl/src/misc/getentropy.c deleted-33
......@@ -1,33 +0,0 @@
1#define _BSD_SOURCE
2#include <unistd.h>
3#include <sys/random.h>
4#include <pthread.h>
5#include <errno.h>
6
7int getentropy(void *buffer, size_t len)
8{
9 int cs, ret = 0;
10 char *pos = buffer;
11
12 if (len > 256) {
13 errno = EIO;
14 return -1;
15 }
16
17 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
18
19 while (len) {
20 ret = getrandom(pos, len, 0);
21 if (ret < 0) {
22 if (errno == EINTR) continue;
23 else break;
24 }
25 pos += ret;
26 len -= ret;
27 ret = 0;
28 }
29
30 pthread_setcancelstate(cs, 0);
31
32 return ret;
33}
lib/libc/wasi/libc-top-half/musl/src/misc/getpriority.c deleted-9
......@@ -1,9 +0,0 @@
1#include <sys/resource.h>
2#include "syscall.h"
3
4int getpriority(int which, id_t who)
5{
6 int ret = syscall(SYS_getpriority, which, who);
7 if (ret < 0) return ret;
8 return 20-ret;
9}
lib/libc/wasi/libc-top-half/musl/src/misc/getresgid.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include "syscall.h"
4
5int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid)
6{
7 return syscall(SYS_getresgid, rgid, egid, sgid);
8}
lib/libc/wasi/libc-top-half/musl/src/misc/getresuid.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include "syscall.h"
4
5int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid)
6{
7 return syscall(SYS_getresuid, ruid, euid, suid);
8}
lib/libc/wasi/libc-top-half/musl/src/misc/getrlimit.c deleted-26
......@@ -1,26 +0,0 @@
1#include <sys/resource.h>
2#include <errno.h>
3#include "syscall.h"
4
5#define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0)
6
7int getrlimit(int resource, struct rlimit *rlim)
8{
9 unsigned long k_rlim[2];
10 int ret = syscall(SYS_prlimit64, 0, resource, 0, rlim);
11 if (!ret) {
12 FIX(rlim->rlim_cur);
13 FIX(rlim->rlim_max);
14 }
15 if (!ret || errno != ENOSYS)
16 return ret;
17 if (syscall(SYS_getrlimit, resource, k_rlim) < 0)
18 return -1;
19 rlim->rlim_cur = k_rlim[0] == -1UL ? RLIM_INFINITY : k_rlim[0];
20 rlim->rlim_max = k_rlim[1] == -1UL ? RLIM_INFINITY : k_rlim[1];
21 FIX(rlim->rlim_cur);
22 FIX(rlim->rlim_max);
23 return 0;
24}
25
26weak_alias(getrlimit, getrlimit64);
lib/libc/wasi/libc-top-half/musl/src/misc/getrusage.c deleted-35
......@@ -1,35 +0,0 @@
1#include <sys/resource.h>
2#include <string.h>
3#include <errno.h>
4#include "syscall.h"
5
6int getrusage(int who, struct rusage *ru)
7{
8 int r;
9#ifdef SYS_getrusage_time64
10 long long kru64[18];
11 r = __syscall(SYS_getrusage_time64, who, kru64);
12 if (!r) {
13 ru->ru_utime = (struct timeval)
14 { .tv_sec = kru64[0], .tv_usec = kru64[1] };
15 ru->ru_stime = (struct timeval)
16 { .tv_sec = kru64[2], .tv_usec = kru64[3] };
17 char *slots = (char *)&ru->ru_maxrss;
18 for (int i=0; i<14; i++)
19 *(long *)(slots + i*sizeof(long)) = kru64[4+i];
20 }
21 if (SYS_getrusage_time64 == SYS_getrusage || r != -ENOSYS)
22 return __syscall_ret(r);
23#endif
24 char *dest = (char *)&ru->ru_maxrss - 4*sizeof(long);
25 r = __syscall(SYS_getrusage, who, dest);
26 if (!r && sizeof(time_t) > sizeof(long)) {
27 long kru[4];
28 memcpy(kru, dest, 4*sizeof(long));
29 ru->ru_utime = (struct timeval)
30 { .tv_sec = kru[0], .tv_usec = kru[1] };
31 ru->ru_stime = (struct timeval)
32 { .tv_sec = kru[2], .tv_usec = kru[3] };
33 }
34 return __syscall_ret(r);
35}
lib/libc/wasi/libc-top-half/musl/src/misc/initgroups.c deleted-11
......@@ -1,11 +0,0 @@
1#define _GNU_SOURCE
2#include <grp.h>
3#include <limits.h>
4
5int initgroups(const char *user, gid_t gid)
6{
7 gid_t groups[NGROUPS_MAX];
8 int count = NGROUPS_MAX;
9 if (getgrouplist(user, gid, groups, &count) < 0) return -1;
10 return setgroups(count, groups);
11}
lib/libc/wasi/libc-top-half/musl/src/misc/ioctl.c deleted-151
......@@ -1,151 +0,0 @@
1#include <sys/ioctl.h>
2#include <stdarg.h>
3#include <errno.h>
4#include <time.h>
5#include <sys/time.h>
6#include <stddef.h>
7#include <stdint.h>
8#include <string.h>
9#include <endian.h>
10#include "syscall.h"
11
12#define alignof(t) offsetof(struct { char c; t x; }, x)
13
14#define W 1
15#define R 2
16#define WR 3
17
18struct ioctl_compat_map {
19 int new_req, old_req;
20 unsigned char old_size, dir, force_align, noffs;
21 unsigned char offsets[8];
22};
23
24#define NINTH(a,b,c,d,e,f,g,h,i,...) i
25#define COUNT(...) NINTH(__VA_ARGS__,8,7,6,5,4,3,2,1,0)
26#define OFFS(...) COUNT(__VA_ARGS__), { __VA_ARGS__ }
27
28/* yields a type for a struct with original size n, with a misaligned
29 * timeval/timespec expanded from 32- to 64-bit. for use with ioctl
30 * number producing macros; only size of result is meaningful. */
31#define new_misaligned(n) struct { int i; time_t t; char c[(n)-4]; }
32
33struct v4l2_event {
34 uint32_t a;
35 uint64_t b[8];
36 uint32_t c[2], ts[2], d[9];
37};
38
39static const struct ioctl_compat_map compat_map[] = {
40 { SIOCGSTAMP, SIOCGSTAMP_OLD, 8, R, 0, OFFS(0, 4) },
41 { SIOCGSTAMPNS, SIOCGSTAMPNS_OLD, 8, R, 0, OFFS(0, 4) },
42
43 /* SNDRV_TIMER_IOCTL_STATUS */
44 { _IOR('T', 0x14, char[96]), _IOR('T', 0x14, 88), 88, R, 0, OFFS(0,4) },
45
46 /* SNDRV_PCM_IOCTL_STATUS[_EXT] */
47 { _IOR('A', 0x20, char[128]), _IOR('A', 0x20, char[108]), 108, R, 1, OFFS(4,8,12,16,52,56,60,64) },
48 { _IOWR('A', 0x24, char[128]), _IOWR('A', 0x24, char[108]), 108, WR, 1, OFFS(4,8,12,16,52,56,60,64) },
49
50 /* SNDRV_RAWMIDI_IOCTL_STATUS */
51 { _IOWR('W', 0x20, char[48]), _IOWR('W', 0x20, char[36]), 36, WR, 1, OFFS(4,8) },
52
53 /* SNDRV_PCM_IOCTL_SYNC_PTR - with 3 subtables */
54 { _IOWR('A', 0x23, char[136]), _IOWR('A', 0x23, char[132]), 0, WR, 1, 0 },
55 { 0, 0, 4, WR, 1, 0 }, /* snd_pcm_sync_ptr (flags only) */
56 { 0, 0, 32, WR, 1, OFFS(8,12,16,24,28) }, /* snd_pcm_mmap_status */
57 { 0, 0, 4, WR, 1, 0 }, /* snd_pcm_mmap_control (each member) */
58
59 /* VIDIOC_QUERYBUF, VIDIOC_QBUF, VIDIOC_DQBUF, VIDIOC_PREPARE_BUF */
60 { _IOWR('V', 9, new_misaligned(68)), _IOWR('V', 9, char[68]), 68, WR, 1, OFFS(20, 24) },
61 { _IOWR('V', 15, new_misaligned(68)), _IOWR('V', 15, char[68]), 68, WR, 1, OFFS(20, 24) },
62 { _IOWR('V', 17, new_misaligned(68)), _IOWR('V', 17, char[68]), 68, WR, 1, OFFS(20, 24) },
63 { _IOWR('V', 93, new_misaligned(68)), _IOWR('V', 93, char[68]), 68, WR, 1, OFFS(20, 24) },
64
65 /* VIDIOC_DQEVENT */
66 { _IOR('V', 89, new_misaligned(120)), _IOR('V', 89, struct v4l2_event), sizeof(struct v4l2_event),
67 R, 0, OFFS(offsetof(struct v4l2_event, ts[0]), offsetof(struct v4l2_event, ts[1])) },
68
69 /* VIDIOC_OMAP3ISP_STAT_REQ */
70 { _IOWR('V', 192+6, char[32]), _IOWR('V', 192+6, char[24]), 22, WR, 0, OFFS(0,4) },
71
72 /* PPPIOCGIDLE */
73 { _IOR('t', 63, char[16]), _IOR('t', 63, char[8]), 8, R, 0, OFFS(0,4) },
74
75 /* PPGETTIME, PPSETTIME */
76 { _IOR('p', 0x95, char[16]), _IOR('p', 0x95, char[8]), 8, R, 0, OFFS(0,4) },
77 { _IOW('p', 0x96, char[16]), _IOW('p', 0x96, char[8]), 8, W, 0, OFFS(0,4) },
78
79 /* LPSETTIMEOUT */
80 { _IOW(0x6, 0xf, char[16]), 0x060f, 8, W, 0, OFFS(0,4) },
81};
82
83static void convert_ioctl_struct(const struct ioctl_compat_map *map, char *old, char *new, int dir)
84{
85 int new_offset = 0;
86 int old_offset = 0;
87 int old_size = map->old_size;
88 if (!(dir & map->dir)) return;
89 if (!map->old_size) {
90 /* offsets hard-coded for SNDRV_PCM_IOCTL_SYNC_PTR;
91 * if another exception appears this needs changing. */
92 convert_ioctl_struct(map+1, old, new, dir);
93 convert_ioctl_struct(map+2, old+4, new+8, dir);
94 /* snd_pcm_mmap_control, special-cased due to kernel
95 * type definition having been botched. */
96 int adj = BYTE_ORDER==BIG_ENDIAN ? 4 : 0;
97 convert_ioctl_struct(map+3, old+68, new+72+adj, dir);
98 convert_ioctl_struct(map+3, old+72, new+76+3*adj, dir);
99 return;
100 }
101 for (int i=0; i < map->noffs; i++) {
102 int ts_offset = map->offsets[i];
103 int len = ts_offset-old_offset;
104 if (dir==W) memcpy(old+old_offset, new+new_offset, len);
105 else memcpy(new+new_offset, old+old_offset, len);
106 new_offset += len;
107 old_offset += len;
108 long long new_ts;
109 long old_ts;
110 int align = map->force_align ? sizeof(time_t) : alignof(time_t);
111 new_offset += (align-1) & -new_offset;
112 if (dir==W) {
113 memcpy(&new_ts, new+new_offset, sizeof new_ts);
114 old_ts = new_ts;
115 memcpy(old+old_offset, &old_ts, sizeof old_ts);
116 } else {
117 memcpy(&old_ts, old+old_offset, sizeof old_ts);
118 new_ts = old_ts;
119 memcpy(new+new_offset, &new_ts, sizeof new_ts);
120 }
121 new_offset += sizeof new_ts;
122 old_offset += sizeof old_ts;
123 }
124 if (dir==W) memcpy(old+old_offset, new+new_offset, old_size-old_offset);
125 else memcpy(new+new_offset, old+old_offset, old_size-old_offset);
126}
127
128int ioctl(int fd, int req, ...)
129{
130 void *arg;
131 va_list ap;
132 va_start(ap, req);
133 arg = va_arg(ap, void *);
134 va_end(ap);
135 int r = __syscall(SYS_ioctl, fd, req, arg);
136 if (SIOCGSTAMP != SIOCGSTAMP_OLD && req && r==-ENOTTY) {
137 for (int i=0; i<sizeof compat_map/sizeof *compat_map; i++) {
138 if (compat_map[i].new_req != req) continue;
139 union {
140 long long align;
141 char buf[256];
142 } u;
143 convert_ioctl_struct(&compat_map[i], u.buf, arg, W);
144 r = __syscall(SYS_ioctl, fd, compat_map[i].old_req, u.buf);
145 if (r<0) break;
146 convert_ioctl_struct(&compat_map[i], u.buf, arg, R);
147 break;
148 }
149 }
150 return __syscall_ret(r);
151}
lib/libc/wasi/libc-top-half/musl/src/misc/issetugid.c deleted-8
......@@ -1,8 +0,0 @@
1#define _BSD_SOURCE
2#include <unistd.h>
3#include "libc.h"
4
5int issetugid(void)
6{
7 return libc.secure;
8}
lib/libc/wasi/libc-top-half/musl/src/misc/lockf.c deleted-32
......@@ -1,32 +0,0 @@
1#include <unistd.h>
2#include <fcntl.h>
3#include <errno.h>
4
5int lockf(int fd, int op, off_t size)
6{
7 struct flock l = {
8 .l_type = F_WRLCK,
9 .l_whence = SEEK_CUR,
10 .l_len = size,
11 };
12 switch (op) {
13 case F_TEST:
14 l.l_type = F_RDLCK;
15 if (fcntl(fd, F_GETLK, &l) < 0)
16 return -1;
17 if (l.l_type == F_UNLCK || l.l_pid == getpid())
18 return 0;
19 errno = EACCES;
20 return -1;
21 case F_ULOCK:
22 l.l_type = F_UNLCK;
23 case F_TLOCK:
24 return fcntl(fd, F_SETLK, &l);
25 case F_LOCK:
26 return fcntl(fd, F_SETLKW, &l);
27 }
28 errno = EINVAL;
29 return -1;
30}
31
32weak_alias(lockf, lockf64);
lib/libc/wasi/libc-top-half/musl/src/misc/login_tty.c deleted-14
......@@ -1,14 +0,0 @@
1#include <utmp.h>
2#include <sys/ioctl.h>
3#include <unistd.h>
4
5int login_tty(int fd)
6{
7 setsid();
8 if (ioctl(fd, TIOCSCTTY, (char *)0)) return -1;
9 dup2(fd, 0);
10 dup2(fd, 1);
11 dup2(fd, 2);
12 if (fd>2) close(fd);
13 return 0;
14}
lib/libc/wasi/libc-top-half/musl/src/misc/mntent.c deleted-77
......@@ -1,77 +0,0 @@
1#include <stdio.h>
2#include <string.h>
3#include <mntent.h>
4#include <errno.h>
5
6static char *internal_buf;
7static size_t internal_bufsize;
8
9#define SENTINEL (char *)&internal_buf
10
11FILE *setmntent(const char *name, const char *mode)
12{
13 return fopen(name, mode);
14}
15
16int endmntent(FILE *f)
17{
18 if (f) fclose(f);
19 return 1;
20}
21
22struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int buflen)
23{
24 int cnt, n[8], use_internal = (linebuf == SENTINEL);
25
26 mnt->mnt_freq = 0;
27 mnt->mnt_passno = 0;
28
29 do {
30 if (use_internal) {
31 getline(&internal_buf, &internal_bufsize, f);
32 linebuf = internal_buf;
33 } else {
34 fgets(linebuf, buflen, f);
35 }
36 if (feof(f) || ferror(f)) return 0;
37 if (!strchr(linebuf, '\n')) {
38 fscanf(f, "%*[^\n]%*[\n]");
39 errno = ERANGE;
40 return 0;
41 }
42 cnt = sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d",
43 n, n+1, n+2, n+3, n+4, n+5, n+6, n+7,
44 &mnt->mnt_freq, &mnt->mnt_passno);
45 } while (cnt < 2 || linebuf[n[0]] == '#');
46
47 linebuf[n[1]] = 0;
48 linebuf[n[3]] = 0;
49 linebuf[n[5]] = 0;
50 linebuf[n[7]] = 0;
51
52 mnt->mnt_fsname = linebuf+n[0];
53 mnt->mnt_dir = linebuf+n[2];
54 mnt->mnt_type = linebuf+n[4];
55 mnt->mnt_opts = linebuf+n[6];
56
57 return mnt;
58}
59
60struct mntent *getmntent(FILE *f)
61{
62 static struct mntent mnt;
63 return getmntent_r(f, &mnt, SENTINEL, 0);
64}
65
66int addmntent(FILE *f, const struct mntent *mnt)
67{
68 if (fseek(f, 0, SEEK_END)) return 1;
69 return fprintf(f, "%s\t%s\t%s\t%s\t%d\t%d\n",
70 mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type, mnt->mnt_opts,
71 mnt->mnt_freq, mnt->mnt_passno) < 0;
72}
73
74char *hasmntopt(const struct mntent *mnt, const char *opt)
75{
76 return strstr(mnt->mnt_opts, opt);
77}
lib/libc/wasi/libc-top-half/musl/src/misc/openpty.c deleted-40
......@@ -1,40 +0,0 @@
1#include <stdlib.h>
2#include <fcntl.h>
3#include <unistd.h>
4#include <pty.h>
5#include <stdio.h>
6#include <pthread.h>
7
8/* Nonstandard, but vastly superior to the standard functions */
9
10int openpty(int *pm, int *ps, char *name, const struct termios *tio, const struct winsize *ws)
11{
12 int m, s, n=0, cs;
13 char buf[20];
14
15 m = open("/dev/ptmx", O_RDWR|O_NOCTTY);
16 if (m < 0) return -1;
17
18 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
19
20 if (ioctl(m, TIOCSPTLCK, &n) || ioctl (m, TIOCGPTN, &n))
21 goto fail;
22
23 if (!name) name = buf;
24 snprintf(name, sizeof buf, "/dev/pts/%d", n);
25 if ((s = open(name, O_RDWR|O_NOCTTY)) < 0)
26 goto fail;
27
28 if (tio) tcsetattr(s, TCSANOW, tio);
29 if (ws) ioctl(s, TIOCSWINSZ, ws);
30
31 *pm = m;
32 *ps = s;
33
34 pthread_setcancelstate(cs, 0);
35 return 0;
36fail:
37 close(m);
38 pthread_setcancelstate(cs, 0);
39 return -1;
40}
lib/libc/wasi/libc-top-half/musl/src/misc/ptsname.c deleted-13
......@@ -1,13 +0,0 @@
1#include <stdlib.h>
2#include <errno.h>
3
4char *ptsname(int fd)
5{
6 static char buf[9 + sizeof(int)*3 + 1];
7 int err = __ptsname_r(fd, buf, sizeof buf);
8 if (err) {
9 errno = err;
10 return 0;
11 }
12 return buf;
13}
lib/libc/wasi/libc-top-half/musl/src/misc/pty.c deleted-35
......@@ -1,35 +0,0 @@
1#include <stdlib.h>
2#include <sys/ioctl.h>
3#include <stdio.h>
4#include <fcntl.h>
5#include <errno.h>
6#include "syscall.h"
7
8int posix_openpt(int flags)
9{
10 int r = open("/dev/ptmx", flags);
11 if (r < 0 && errno == ENOSPC) errno = EAGAIN;
12 return r;
13}
14
15int grantpt(int fd)
16{
17 return 0;
18}
19
20int unlockpt(int fd)
21{
22 int unlock = 0;
23 return ioctl(fd, TIOCSPTLCK, &unlock);
24}
25
26int __ptsname_r(int fd, char *buf, size_t len)
27{
28 int pty, err;
29 if (!buf) len = 0;
30 if ((err = __syscall(SYS_ioctl, fd, TIOCGPTN, &pty))) return -err;
31 if (snprintf(buf, len, "/dev/pts/%d", pty) >= len) return ERANGE;
32 return 0;
33}
34
35weak_alias(__ptsname_r, ptsname_r);
lib/libc/wasi/libc-top-half/musl/src/misc/realpath.c deleted-156
......@@ -1,156 +0,0 @@
1#include <stdlib.h>
2#include <limits.h>
3#include <errno.h>
4#include <unistd.h>
5#include <string.h>
6
7static size_t slash_len(const char *s)
8{
9 const char *s0 = s;
10 while (*s == '/') s++;
11 return s-s0;
12}
13
14char *realpath(const char *restrict filename, char *restrict resolved)
15{
16 char stack[PATH_MAX+1];
17 char output[PATH_MAX];
18 size_t p, q, l, l0, cnt=0, nup=0;
19 int check_dir=0;
20
21 if (!filename) {
22 errno = EINVAL;
23 return 0;
24 }
25 l = strnlen(filename, sizeof stack);
26 if (!l) {
27 errno = ENOENT;
28 return 0;
29 }
30 if (l >= PATH_MAX) goto toolong;
31 p = sizeof stack - l - 1;
32 q = 0;
33 memcpy(stack+p, filename, l+1);
34
35 /* Main loop. Each iteration pops the next part from stack of
36 * remaining path components and consumes any slashes that follow.
37 * If not a link, it's moved to output; if a link, contents are
38 * pushed to the stack. */
39restart:
40 for (; ; p+=slash_len(stack+p)) {
41 /* If stack starts with /, the whole component is / or //
42 * and the output state must be reset. */
43 if (stack[p] == '/') {
44 check_dir=0;
45 nup=0;
46 q=0;
47 output[q++] = '/';
48 p++;
49 /* Initial // is special. */
50 if (stack[p] == '/' && stack[p+1] != '/')
51 output[q++] = '/';
52 continue;
53 }
54
55 char *z = __strchrnul(stack+p, '/');
56 l0 = l = z-(stack+p);
57
58 if (!l && !check_dir) break;
59
60 /* Skip any . component but preserve check_dir status. */
61 if (l==1 && stack[p]=='.') {
62 p += l;
63 continue;
64 }
65
66 /* Copy next component onto output at least temporarily, to
67 * call readlink, but wait to advance output position until
68 * determining it's not a link. */
69 if (q && output[q-1] != '/') {
70 if (!p) goto toolong;
71 stack[--p] = '/';
72 l++;
73 }
74 if (q+l >= PATH_MAX) goto toolong;
75 memcpy(output+q, stack+p, l);
76 output[q+l] = 0;
77 p += l;
78
79 int up = 0;
80 if (l0==2 && stack[p-2]=='.' && stack[p-1]=='.') {
81 up = 1;
82 /* Any non-.. path components we could cancel start
83 * after nup repetitions of the 3-byte string "../";
84 * if there are none, accumulate .. components to
85 * later apply to cwd, if needed. */
86 if (q <= 3*nup) {
87 nup++;
88 q += l;
89 continue;
90 }
91 /* When previous components are already known to be
92 * directories, processing .. can skip readlink. */
93 if (!check_dir) goto skip_readlink;
94 }
95 ssize_t k = readlink(output, stack, p);
96 if (k==p) goto toolong;
97 if (!k) {
98 errno = ENOENT;
99 return 0;
100 }
101 if (k<0) {
102 if (errno != EINVAL) return 0;
103skip_readlink:
104 check_dir = 0;
105 if (up) {
106 while(q && output[q-1]!='/') q--;
107 if (q>1 && (q>2 || output[0]!='/')) q--;
108 continue;
109 }
110 if (l0) q += l;
111 check_dir = stack[p];
112 continue;
113 }
114 if (++cnt == SYMLOOP_MAX) {
115 errno = ELOOP;
116 return 0;
117 }
118
119 /* If link contents end in /, strip any slashes already on
120 * stack to avoid /->// or //->/// or spurious toolong. */
121 if (stack[k-1]=='/') while (stack[p]=='/') p++;
122 p -= k;
123 memmove(stack+p, stack, k);
124
125 /* Skip the stack advancement in case we have a new
126 * absolute base path. */
127 goto restart;
128 }
129
130 output[q] = 0;
131
132 if (output[0] != '/') {
133 if (!getcwd(stack, sizeof stack)) return 0;
134 l = strlen(stack);
135 /* Cancel any initial .. components. */
136 p = 0;
137 while (nup--) {
138 while(l>1 && stack[l-1]!='/') l--;
139 if (l>1) l--;
140 p += 2;
141 if (p<q) p++;
142 }
143 if (q-p && stack[l-1]!='/') stack[l++] = '/';
144 if (l + (q-p) + 1 >= PATH_MAX) goto toolong;
145 memmove(output + l, output + p, q - p + 1);
146 memcpy(output, stack, l);
147 q = l + q-p;
148 }
149
150 if (resolved) return memcpy(resolved, output, q+1);
151 else return strdup(output);
152
153toolong:
154 errno = ENAMETOOLONG;
155 return 0;
156}
lib/libc/wasi/libc-top-half/musl/src/misc/setdomainname.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include "syscall.h"
4
5int setdomainname(const char *name, size_t len)
6{
7 return syscall(SYS_setdomainname, name, len);
8}
lib/libc/wasi/libc-top-half/musl/src/misc/setpriority.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/resource.h>
2#include "syscall.h"
3
4int setpriority(int which, id_t who, int prio)
5{
6 return syscall(SYS_setpriority, which, who, prio);
7}
lib/libc/wasi/libc-top-half/musl/src/misc/setrlimit.c deleted-47
......@@ -1,47 +0,0 @@
1#include <sys/resource.h>
2#include <errno.h>
3#include "syscall.h"
4#include "libc.h"
5
6#define MIN(a, b) ((a)<(b) ? (a) : (b))
7#define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0)
8
9struct ctx {
10 unsigned long lim[2];
11 int res;
12 int err;
13};
14
15static void do_setrlimit(void *p)
16{
17 struct ctx *c = p;
18 if (c->err>0) return;
19 c->err = -__syscall(SYS_setrlimit, c->res, c->lim);
20}
21
22int setrlimit(int resource, const struct rlimit *rlim)
23{
24 struct rlimit tmp;
25 if (SYSCALL_RLIM_INFINITY != RLIM_INFINITY) {
26 tmp = *rlim;
27 FIX(tmp.rlim_cur);
28 FIX(tmp.rlim_max);
29 rlim = &tmp;
30 }
31 int ret = __syscall(SYS_prlimit64, 0, resource, rlim, 0);
32 if (ret != -ENOSYS) return __syscall_ret(ret);
33
34 struct ctx c = {
35 .lim[0] = MIN(rlim->rlim_cur, MIN(-1UL, SYSCALL_RLIM_INFINITY)),
36 .lim[1] = MIN(rlim->rlim_max, MIN(-1UL, SYSCALL_RLIM_INFINITY)),
37 .res = resource, .err = -1
38 };
39 __synccall(do_setrlimit, &c);
40 if (c.err) {
41 if (c.err>0) errno = c.err;
42 return -1;
43 }
44 return 0;
45}
46
47weak_alias(setrlimit, setrlimit64);
lib/libc/wasi/libc-top-half/musl/src/misc/syscall.c deleted-21
......@@ -1,21 +0,0 @@
1#define _BSD_SOURCE
2#include <unistd.h>
3#include "syscall.h"
4#include <stdarg.h>
5
6#undef syscall
7
8long syscall(long n, ...)
9{
10 va_list ap;
11 syscall_arg_t a,b,c,d,e,f;
12 va_start(ap, n);
13 a=va_arg(ap, syscall_arg_t);
14 b=va_arg(ap, syscall_arg_t);
15 c=va_arg(ap, syscall_arg_t);
16 d=va_arg(ap, syscall_arg_t);
17 e=va_arg(ap, syscall_arg_t);
18 f=va_arg(ap, syscall_arg_t);
19 va_end(ap);
20 return __syscall_ret(__syscall(n,a,b,c,d,e,f));
21}
lib/libc/wasi/libc-top-half/musl/src/misc/syslog.c deleted-162
......@@ -1,162 +0,0 @@
1#include <stdarg.h>
2#include <sys/socket.h>
3#include <stdio.h>
4#include <unistd.h>
5#include <syslog.h>
6#include <time.h>
7#include <signal.h>
8#include <string.h>
9#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
10#include <pthread.h>
11#endif
12#include <errno.h>
13#include <fcntl.h>
14#include "lock.h"
15#include "fork_impl.h"
16
17static volatile int lock[1];
18static char log_ident[32];
19static int log_opt;
20static int log_facility = LOG_USER;
21static int log_mask = 0xff;
22static int log_fd = -1;
23volatile int *const __syslog_lockptr = lock;
24
25int setlogmask(int maskpri)
26{
27 LOCK(lock);
28 int ret = log_mask;
29 if (maskpri) log_mask = maskpri;
30 UNLOCK(lock);
31 return ret;
32}
33
34static const struct {
35 short sun_family;
36 char sun_path[9];
37} log_addr = {
38 AF_UNIX,
39 "/dev/log"
40};
41
42void closelog(void)
43{
44#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
45 int cs;
46 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
47#endif
48 LOCK(lock);
49 close(log_fd);
50 log_fd = -1;
51 UNLOCK(lock);
52#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
53 pthread_setcancelstate(cs, 0);
54#endif
55}
56
57static void __openlog()
58{
59 log_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
60 if (log_fd >= 0) connect(log_fd, (void *)&log_addr, sizeof log_addr);
61}
62
63void openlog(const char *ident, int opt, int facility)
64{
65#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
66 int cs;
67 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
68#endif
69 LOCK(lock);
70
71 if (ident) {
72 size_t n = strnlen(ident, sizeof log_ident - 1);
73 memcpy(log_ident, ident, n);
74 log_ident[n] = 0;
75 } else {
76 log_ident[0] = 0;
77 }
78 log_opt = opt;
79 log_facility = facility;
80
81 if ((opt & LOG_NDELAY) && log_fd<0) __openlog();
82
83 UNLOCK(lock);
84#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
85 pthread_setcancelstate(cs, 0);
86#endif
87}
88
89static int is_lost_conn(int e)
90{
91 return e==ECONNREFUSED || e==ECONNRESET || e==ENOTCONN || e==EPIPE;
92}
93
94static void _vsyslog(int priority, const char *message, va_list ap)
95{
96 char timebuf[16];
97 time_t now;
98 struct tm tm;
99 char buf[1024];
100 int errno_save = errno;
101 int pid;
102 int l, l2;
103 int hlen;
104 int fd;
105
106 if (log_fd < 0) __openlog();
107
108 if (!(priority & LOG_FACMASK)) priority |= log_facility;
109
110 now = time(NULL);
111 gmtime_r(&now, &tm);
112 strftime(timebuf, sizeof timebuf, "%b %e %T", &tm);
113
114 pid = (log_opt & LOG_PID) ? getpid() : 0;
115 l = snprintf(buf, sizeof buf, "<%d>%s %n%s%s%.0d%s: ",
116 priority, timebuf, &hlen, log_ident, "["+!pid, pid, "]"+!pid);
117 errno = errno_save;
118 l2 = vsnprintf(buf+l, sizeof buf - l, message, ap);
119 if (l2 >= 0) {
120 if (l2 >= sizeof buf - l) l = sizeof buf - 1;
121 else l += l2;
122 if (buf[l-1] != '\n') buf[l++] = '\n';
123 if (send(log_fd, buf, l, 0) < 0 && (!is_lost_conn(errno)
124 || connect(log_fd, (void *)&log_addr, sizeof log_addr) < 0
125 || send(log_fd, buf, l, 0) < 0)
126 && (log_opt & LOG_CONS)) {
127 fd = open("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
128 if (fd >= 0) {
129 dprintf(fd, "%.*s", l-hlen, buf+hlen);
130 close(fd);
131 }
132 }
133 if (log_opt & LOG_PERROR) dprintf(2, "%.*s", l-hlen, buf+hlen);
134 }
135}
136
137static void __vsyslog(int priority, const char *message, va_list ap)
138{
139#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
140 int cs;
141#endif
142 if (!(log_mask & LOG_MASK(priority&7)) || (priority&~0x3ff)) return;
143#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
144 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
145#endif
146 LOCK(lock);
147 _vsyslog(priority, message, ap);
148 UNLOCK(lock);
149#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
150 pthread_setcancelstate(cs, 0);
151#endif
152}
153
154void syslog(int priority, const char *message, ...)
155{
156 va_list ap;
157 va_start(ap, message);
158 __vsyslog(priority, message, ap);
159 va_end(ap);
160}
161
162weak_alias(__vsyslog, vsyslog);
lib/libc/wasi/libc-top-half/musl/src/misc/wordexp.c deleted-187
......@@ -1,187 +0,0 @@
1#include <wordexp.h>
2#include <unistd.h>
3#include <stdio.h>
4#include <string.h>
5#include <limits.h>
6#include <stdint.h>
7#include <stdlib.h>
8#include <sys/wait.h>
9#include <signal.h>
10#include <errno.h>
11#include <fcntl.h>
12#include "pthread_impl.h"
13
14static void reap(pid_t pid)
15{
16 int status;
17 while (waitpid(pid, &status, 0) < 0 && errno == EINTR);
18}
19
20static char *getword(FILE *f)
21{
22 char *s = 0;
23 return getdelim(&s, (size_t [1]){0}, 0, f) < 0 ? 0 : s;
24}
25
26static int do_wordexp(const char *s, wordexp_t *we, int flags)
27{
28 size_t i, l;
29 int sq=0, dq=0;
30 size_t np=0;
31 char *w, **tmp;
32 char *redir = (flags & WRDE_SHOWERR) ? "" : "2>/dev/null";
33 int err = 0;
34 FILE *f;
35 size_t wc = 0;
36 char **wv = 0;
37 int p[2];
38 pid_t pid;
39 sigset_t set;
40
41 if (flags & WRDE_REUSE) wordfree(we);
42
43 if (flags & WRDE_NOCMD) for (i=0; s[i]; i++) switch (s[i]) {
44 case '\\':
45 if (!sq && !s[++i]) return WRDE_SYNTAX;
46 break;
47 case '\'':
48 if (!dq) sq^=1;
49 break;
50 case '"':
51 if (!sq) dq^=1;
52 break;
53 case '(':
54 if (np) {
55 np++;
56 break;
57 }
58 case ')':
59 if (np) {
60 np--;
61 break;
62 }
63 case '\n':
64 case '|':
65 case '&':
66 case ';':
67 case '<':
68 case '>':
69 case '{':
70 case '}':
71 if (!(sq|dq|np)) return WRDE_BADCHAR;
72 break;
73 case '$':
74 if (sq) break;
75 if (s[i+1]=='(' && s[i+2]=='(') {
76 i += 2;
77 np += 2;
78 break;
79 } else if (s[i+1] != '(') break;
80 case '`':
81 if (sq) break;
82 return WRDE_CMDSUB;
83 }
84
85 if (flags & WRDE_APPEND) {
86 wc = we->we_wordc;
87 wv = we->we_wordv;
88 }
89
90 i = wc;
91 if (flags & WRDE_DOOFFS) {
92 if (we->we_offs > SIZE_MAX/sizeof(void *)/4)
93 goto nospace;
94 i += we->we_offs;
95 } else {
96 we->we_offs = 0;
97 }
98
99 if (pipe2(p, O_CLOEXEC) < 0) goto nospace;
100 __block_all_sigs(&set);
101 pid = fork();
102 __restore_sigs(&set);
103 if (pid < 0) {
104 close(p[0]);
105 close(p[1]);
106 goto nospace;
107 }
108 if (!pid) {
109 if (p[1] == 1) fcntl(1, F_SETFD, 0);
110 else dup2(p[1], 1);
111 execl("/bin/sh", "sh", "-c",
112 "eval \"printf %s\\\\\\\\0 x $1 $2\"",
113 "sh", s, redir, (char *)0);
114 _exit(1);
115 }
116 close(p[1]);
117
118 f = fdopen(p[0], "r");
119 if (!f) {
120 close(p[0]);
121 kill(pid, SIGKILL);
122 reap(pid);
123 goto nospace;
124 }
125
126 l = wv ? i+1 : 0;
127
128 free(getword(f));
129 if (feof(f)) {
130 fclose(f);
131 reap(pid);
132 return WRDE_SYNTAX;
133 }
134
135 while ((w = getword(f))) {
136 if (i+1 >= l) {
137 l += l/2+10;
138 tmp = realloc(wv, l*sizeof(char *));
139 if (!tmp) break;
140 wv = tmp;
141 }
142 wv[i++] = w;
143 wv[i] = 0;
144 }
145 if (!feof(f)) err = WRDE_NOSPACE;
146
147 fclose(f);
148 reap(pid);
149
150 if (!wv) wv = calloc(i+1, sizeof *wv);
151
152 we->we_wordv = wv;
153 we->we_wordc = i;
154
155 if (flags & WRDE_DOOFFS) {
156 if (wv) for (i=we->we_offs; i; i--)
157 we->we_wordv[i-1] = 0;
158 we->we_wordc -= we->we_offs;
159 }
160 return err;
161
162nospace:
163 if (!(flags & WRDE_APPEND)) {
164 we->we_wordc = 0;
165 we->we_wordv = 0;
166 }
167 return WRDE_NOSPACE;
168}
169
170int wordexp(const char *restrict s, wordexp_t *restrict we, int flags)
171{
172 int r, cs;
173 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
174 r = do_wordexp(s, we, flags);
175 pthread_setcancelstate(cs, 0);
176 return r;
177}
178
179void wordfree(wordexp_t *we)
180{
181 size_t i;
182 if (!we->we_wordv) return;
183 for (i=0; i<we->we_wordc; i++) free(we->we_wordv[we->we_offs+i]);
184 free(we->we_wordv);
185 we->we_wordv = 0;
186 we->we_wordc = 0;
187}
lib/libc/wasi/libc-top-half/musl/src/mman/madvise.c deleted-9
......@@ -1,9 +0,0 @@
1#include <sys/mman.h>
2#include "syscall.h"
3
4int __madvise(void *addr, size_t len, int advice)
5{
6 return syscall(SYS_madvise, addr, len, advice);
7}
8
9weak_alias(__madvise, madvise);
lib/libc/wasi/libc-top-half/musl/src/mman/mincore.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <sys/mman.h>
3#include "syscall.h"
4
5int mincore (void *addr, size_t len, unsigned char *vec)
6{
7 return syscall(SYS_mincore, addr, len, vec);
8}
lib/libc/wasi/libc-top-half/musl/src/mman/mlock.c deleted-11
......@@ -1,11 +0,0 @@
1#include <sys/mman.h>
2#include "syscall.h"
3
4int mlock(const void *addr, size_t len)
5{
6#ifdef SYS_mlock
7 return syscall(SYS_mlock, addr, len);
8#else
9 return syscall(SYS_mlock2, addr, len, 0);
10#endif
11}
lib/libc/wasi/libc-top-half/musl/src/mman/mlockall.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/mman.h>
2#include "syscall.h"
3
4int mlockall(int flags)
5{
6 return syscall(SYS_mlockall, flags);
7}
lib/libc/wasi/libc-top-half/musl/src/mman/mmap.c deleted-41
......@@ -1,41 +0,0 @@
1#include <unistd.h>
2#include <sys/mman.h>
3#include <errno.h>
4#include <stdint.h>
5#include <limits.h>
6#include "syscall.h"
7
8static void dummy(void) { }
9weak_alias(dummy, __vm_wait);
10
11#define UNIT SYSCALL_MMAP2_UNIT
12#define OFF_MASK ((-0x2000ULL << (8*sizeof(syscall_arg_t)-1)) | (UNIT-1))
13
14void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off)
15{
16 long ret;
17 if (off & OFF_MASK) {
18 errno = EINVAL;
19 return MAP_FAILED;
20 }
21 if (len >= PTRDIFF_MAX) {
22 errno = ENOMEM;
23 return MAP_FAILED;
24 }
25 if (flags & MAP_FIXED) {
26 __vm_wait();
27 }
28#ifdef SYS_mmap2
29 ret = __syscall(SYS_mmap2, start, len, prot, flags, fd, off/UNIT);
30#else
31 ret = __syscall(SYS_mmap, start, len, prot, flags, fd, off);
32#endif
33 /* Fixup incorrect EPERM from kernel. */
34 if (ret == -EPERM && !start && (flags&MAP_ANON) && !(flags&MAP_FIXED))
35 ret = -ENOMEM;
36 return (void *)__syscall_ret(ret);
37}
38
39weak_alias(__mmap, mmap);
40
41weak_alias(mmap, mmap64);
lib/libc/wasi/libc-top-half/musl/src/mman/mprotect.c deleted-13
......@@ -1,13 +0,0 @@
1#include <sys/mman.h>
2#include "libc.h"
3#include "syscall.h"
4
5int __mprotect(void *addr, size_t len, int prot)
6{
7 size_t start, end;
8 start = (size_t)addr & -PAGE_SIZE;
9 end = (size_t)((char *)addr + len + PAGE_SIZE-1) & -PAGE_SIZE;
10 return syscall(SYS_mprotect, start, end-start, prot);
11}
12
13weak_alias(__mprotect, mprotect);
lib/libc/wasi/libc-top-half/musl/src/mman/mremap.c deleted-32
......@@ -1,32 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include <sys/mman.h>
4#include <errno.h>
5#include <stdint.h>
6#include <stdarg.h>
7#include "syscall.h"
8
9static void dummy(void) { }
10weak_alias(dummy, __vm_wait);
11
12void *__mremap(void *old_addr, size_t old_len, size_t new_len, int flags, ...)
13{
14 va_list ap;
15 void *new_addr = 0;
16
17 if (new_len >= PTRDIFF_MAX) {
18 errno = ENOMEM;
19 return MAP_FAILED;
20 }
21
22 if (flags & MREMAP_FIXED) {
23 __vm_wait();
24 va_start(ap, flags);
25 new_addr = va_arg(ap, void *);
26 va_end(ap);
27 }
28
29 return (void *)syscall(SYS_mremap, old_addr, old_len, new_len, flags, new_addr);
30}
31
32weak_alias(__mremap, mremap);
lib/libc/wasi/libc-top-half/musl/src/mman/msync.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/mman.h>
2#include "syscall.h"
3
4int msync(void *start, size_t len, int flags)
5{
6 return syscall_cp(SYS_msync, start, len, flags);
7}
lib/libc/wasi/libc-top-half/musl/src/mman/munlock.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/mman.h>
2#include "syscall.h"
3
4int munlock(const void *addr, size_t len)
5{
6 return syscall(SYS_munlock, addr, len);
7}
lib/libc/wasi/libc-top-half/musl/src/mman/munlockall.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/mman.h>
2#include "syscall.h"
3
4int munlockall(void)
5{
6 return syscall(SYS_munlockall);
7}
lib/libc/wasi/libc-top-half/musl/src/mman/munmap.c deleted-13
......@@ -1,13 +0,0 @@
1#include <sys/mman.h>
2#include "syscall.h"
3
4static void dummy(void) { }
5weak_alias(dummy, __vm_wait);
6
7int __munmap(void *start, size_t len)
8{
9 __vm_wait();
10 return syscall(SYS_munmap, start, len);
11}
12
13weak_alias(__munmap, munmap);
lib/libc/wasi/libc-top-half/musl/src/mman/posix_madvise.c deleted-9
......@@ -1,9 +0,0 @@
1#define _GNU_SOURCE
2#include <sys/mman.h>
3#include "syscall.h"
4
5int posix_madvise(void *addr, size_t len, int advice)
6{
7 if (advice == MADV_DONTNEED) return 0;
8 return -__syscall(SYS_madvise, addr, len, advice);
9}
lib/libc/wasi/libc-top-half/musl/src/mman/shm_open.c deleted-43
......@@ -1,43 +0,0 @@
1#include <sys/mman.h>
2#include <errno.h>
3#include <fcntl.h>
4#include <unistd.h>
5#include <string.h>
6#include <limits.h>
7#include <pthread.h>
8
9char *__shm_mapname(const char *name, char *buf)
10{
11 char *p;
12 while (*name == '/') name++;
13 if (*(p = __strchrnul(name, '/')) || p==name ||
14 (p-name <= 2 && name[0]=='.' && p[-1]=='.')) {
15 errno = EINVAL;
16 return 0;
17 }
18 if (p-name > NAME_MAX) {
19 errno = ENAMETOOLONG;
20 return 0;
21 }
22 memcpy(buf, "/dev/shm/", 9);
23 memcpy(buf+9, name, p-name+1);
24 return buf;
25}
26
27int shm_open(const char *name, int flag, mode_t mode)
28{
29 int cs;
30 char buf[NAME_MAX+10];
31 if (!(name = __shm_mapname(name, buf))) return -1;
32 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
33 int fd = open(name, flag|O_NOFOLLOW|O_CLOEXEC|O_NONBLOCK, mode);
34 pthread_setcancelstate(cs, 0);
35 return fd;
36}
37
38int shm_unlink(const char *name)
39{
40 char buf[NAME_MAX+10];
41 if (!(name = __shm_mapname(name, buf))) return -1;
42 return unlink(name);
43}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_close.c deleted-7
......@@ -1,7 +0,0 @@
1#include <mqueue.h>
2#include "syscall.h"
3
4int mq_close(mqd_t mqd)
5{
6 return syscall(SYS_close, mqd);
7}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_getattr.c deleted-7
......@@ -1,7 +0,0 @@
1#include <mqueue.h>
2#include "syscall.h"
3
4int mq_getattr(mqd_t mqd, struct mq_attr *attr)
5{
6 return mq_setattr(mqd, 0, attr);
7}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_notify.c deleted-73
......@@ -1,73 +0,0 @@
1#include <mqueue.h>
2#include <pthread.h>
3#include <errno.h>
4#include <sys/socket.h>
5#include <signal.h>
6#include <unistd.h>
7#include "syscall.h"
8
9struct args {
10 pthread_barrier_t barrier;
11 int sock;
12 const struct sigevent *sev;
13};
14
15static void *start(void *p)
16{
17 struct args *args = p;
18 char buf[32];
19 ssize_t n;
20 int s = args->sock;
21 void (*func)(union sigval) = args->sev->sigev_notify_function;
22 union sigval val = args->sev->sigev_value;
23
24 pthread_barrier_wait(&args->barrier);
25 n = recv(s, buf, sizeof(buf), MSG_NOSIGNAL|MSG_WAITALL);
26 close(s);
27 if (n==sizeof buf && buf[sizeof buf - 1] == 1)
28 func(val);
29 return 0;
30}
31
32int mq_notify(mqd_t mqd, const struct sigevent *sev)
33{
34 struct args args = { .sev = sev };
35 pthread_attr_t attr;
36 pthread_t td;
37 int s;
38 struct sigevent sev2;
39 static const char zeros[32];
40
41 if (!sev || sev->sigev_notify != SIGEV_THREAD)
42 return syscall(SYS_mq_notify, mqd, sev);
43
44 s = socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, 0);
45 if (s < 0) return -1;
46 args.sock = s;
47
48 if (sev->sigev_notify_attributes) attr = *sev->sigev_notify_attributes;
49 else pthread_attr_init(&attr);
50 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
51 pthread_barrier_init(&args.barrier, 0, 2);
52
53 if (pthread_create(&td, &attr, start, &args)) {
54 __syscall(SYS_close, s);
55 errno = EAGAIN;
56 return -1;
57 }
58
59 pthread_barrier_wait(&args.barrier);
60 pthread_barrier_destroy(&args.barrier);
61
62 sev2.sigev_notify = SIGEV_THREAD;
63 sev2.sigev_signo = s;
64 sev2.sigev_value.sival_ptr = (void *)&zeros;
65
66 if (syscall(SYS_mq_notify, mqd, &sev2) < 0) {
67 pthread_cancel(td);
68 __syscall(SYS_close, s);
69 return -1;
70 }
71
72 return 0;
73}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_open.c deleted-19
......@@ -1,19 +0,0 @@
1#include <mqueue.h>
2#include <fcntl.h>
3#include <stdarg.h>
4#include "syscall.h"
5
6mqd_t mq_open(const char *name, int flags, ...)
7{
8 mode_t mode = 0;
9 struct mq_attr *attr = 0;
10 if (*name == '/') name++;
11 if (flags & O_CREAT) {
12 va_list ap;
13 va_start(ap, flags);
14 mode = va_arg(ap, mode_t);
15 attr = va_arg(ap, struct mq_attr *);
16 va_end(ap);
17 }
18 return syscall(SYS_mq_open, name, flags, mode, attr);
19}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_receive.c deleted-6
......@@ -1,6 +0,0 @@
1#include <mqueue.h>
2
3ssize_t mq_receive(mqd_t mqd, char *msg, size_t len, unsigned *prio)
4{
5 return mq_timedreceive(mqd, msg, len, prio, 0);
6}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_send.c deleted-6
......@@ -1,6 +0,0 @@
1#include <mqueue.h>
2
3int mq_send(mqd_t mqd, const char *msg, size_t len, unsigned prio)
4{
5 return mq_timedsend(mqd, msg, len, prio, 0);
6}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_setattr.c deleted-7
......@@ -1,7 +0,0 @@
1#include <mqueue.h>
2#include "syscall.h"
3
4int mq_setattr(mqd_t mqd, const struct mq_attr *restrict new, struct mq_attr *restrict old)
5{
6 return syscall(SYS_mq_getsetattr, mqd, new, old);
7}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_timedreceive.c deleted-24
......@@ -1,24 +0,0 @@
1#include <mqueue.h>
2#include <errno.h>
3#include "syscall.h"
4
5#define IS32BIT(x) !((x)+0x80000000ULL>>32)
6#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
7
8ssize_t mq_timedreceive(mqd_t mqd, char *restrict msg, size_t len, unsigned *restrict prio, const struct timespec *restrict at)
9{
10#ifdef SYS_mq_timedreceive_time64
11 time_t s = at ? at->tv_sec : 0;
12 long ns = at ? at->tv_nsec : 0;
13 long r = -ENOSYS;
14 if (SYS_mq_timedreceive == SYS_mq_timedreceive_time64 || !IS32BIT(s))
15 r = __syscall_cp(SYS_mq_timedreceive_time64, mqd, msg, len, prio,
16 at ? ((long long []){at->tv_sec, at->tv_nsec}) : 0);
17 if (SYS_mq_timedreceive == SYS_mq_timedreceive_time64 || r != -ENOSYS)
18 return __syscall_ret(r);
19 return syscall_cp(SYS_mq_timedreceive, mqd, msg, len, prio,
20 at ? ((long[]){CLAMP(s), ns}) : 0);
21#else
22 return syscall_cp(SYS_mq_timedreceive, mqd, msg, len, prio, at);
23#endif
24}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_timedsend.c deleted-24
......@@ -1,24 +0,0 @@
1#include <mqueue.h>
2#include <errno.h>
3#include "syscall.h"
4
5#define IS32BIT(x) !((x)+0x80000000ULL>>32)
6#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
7
8int mq_timedsend(mqd_t mqd, const char *msg, size_t len, unsigned prio, const struct timespec *at)
9{
10#ifdef SYS_mq_timedsend_time64
11 time_t s = at ? at->tv_sec : 0;
12 long ns = at ? at->tv_nsec : 0;
13 long r = -ENOSYS;
14 if (SYS_mq_timedsend == SYS_mq_timedsend_time64 || !IS32BIT(s))
15 r = __syscall_cp(SYS_mq_timedsend_time64, mqd, msg, len, prio,
16 at ? ((long long []){at->tv_sec, at->tv_nsec}) : 0);
17 if (SYS_mq_timedsend == SYS_mq_timedsend_time64 || r != -ENOSYS)
18 return __syscall_ret(r);
19 return syscall_cp(SYS_mq_timedsend, mqd, msg, len, prio,
20 at ? ((long[]){CLAMP(s), ns}) : 0);
21#else
22 return syscall_cp(SYS_mq_timedsend, mqd, msg, len, prio, at);
23#endif
24}
lib/libc/wasi/libc-top-half/musl/src/mq/mq_unlink.c deleted-16
......@@ -1,16 +0,0 @@
1#include <mqueue.h>
2#include <errno.h>
3#include "syscall.h"
4
5int mq_unlink(const char *name)
6{
7 int ret;
8 if (*name == '/') name++;
9 ret = __syscall(SYS_mq_unlink, name);
10 if (ret < 0) {
11 if (ret == -EPERM) ret = -EACCES;
12 errno = -ret;
13 return -1;
14 }
15 return ret;
16}
lib/libc/wasi/libc-top-half/musl/src/network/accept.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/socket.h>
2#include "syscall.h"
3
4int accept(int fd, struct sockaddr *restrict addr, socklen_t *restrict len)
5{
6 return socketcall_cp(accept, fd, addr, len, 0, 0, 0);
7}
lib/libc/wasi/libc-top-half/musl/src/network/accept4.c deleted-19
......@@ -1,19 +0,0 @@
1#define _GNU_SOURCE
2#include <sys/socket.h>
3#include <errno.h>
4#include <fcntl.h>
5#include "syscall.h"
6
7int accept4(int fd, struct sockaddr *restrict addr, socklen_t *restrict len, int flg)
8{
9 if (!flg) return accept(fd, addr, len);
10 int ret = socketcall_cp(accept4, fd, addr, len, flg, 0, 0);
11 if (ret>=0 || (errno != ENOSYS && errno != EINVAL)) return ret;
12 ret = accept(fd, addr, len);
13 if (ret<0) return ret;
14 if (flg & SOCK_CLOEXEC)
15 __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC);
16 if (flg & SOCK_NONBLOCK)
17 __syscall(SYS_fcntl, ret, F_SETFL, O_NONBLOCK);
18 return ret;
19}
lib/libc/wasi/libc-top-half/musl/src/network/bind.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/socket.h>
2#include "syscall.h"
3
4int bind(int fd, const struct sockaddr *addr, socklen_t len)
5{
6 return socketcall(bind, fd, addr, len, 0, 0, 0);
7}
lib/libc/wasi/libc-top-half/musl/src/network/connect.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/socket.h>
2#include "syscall.h"
3
4int connect(int fd, const struct sockaddr *addr, socklen_t len)
5{
6 return socketcall_cp(connect, fd, addr, len, 0, 0, 0);
7}
lib/libc/wasi/libc-top-half/musl/src/network/dn_comp.c deleted-107
......@@ -1,107 +0,0 @@
1#include <string.h>
2#include <resolv.h>
3
4/* RFC 1035 message compression */
5
6/* label start offsets of a compressed domain name s */
7static int getoffs(short *offs, const unsigned char *base, const unsigned char *s)
8{
9 int i=0;
10 for (;;) {
11 while (*s & 0xc0) {
12 if ((*s & 0xc0) != 0xc0) return 0;
13 s = base + ((s[0]&0x3f)<<8 | s[1]);
14 }
15 if (!*s) return i;
16 if (s-base >= 0x4000) return 0;
17 offs[i++] = s-base;
18 s += *s + 1;
19 }
20}
21
22/* label lengths of an ascii domain name s */
23static int getlens(unsigned char *lens, const char *s, int l)
24{
25 int i=0,j=0,k=0;
26 for (;;) {
27 for (; j<l && s[j]!='.'; j++);
28 if (j-k-1u > 62) return 0;
29 lens[i++] = j-k;
30 if (j==l) return i;
31 k = ++j;
32 }
33}
34
35/* longest suffix match of an ascii domain with a compressed domain name dn */
36static int match(int *offset, const unsigned char *base, const unsigned char *dn,
37 const char *end, const unsigned char *lens, int nlen)
38{
39 int l, o, m=0;
40 short offs[128];
41 int noff = getoffs(offs, base, dn);
42 if (!noff) return 0;
43 for (;;) {
44 l = lens[--nlen];
45 o = offs[--noff];
46 end -= l;
47 if (l != base[o] || memcmp(base+o+1, end, l))
48 return m;
49 *offset = o;
50 m += l;
51 if (nlen) m++;
52 if (!nlen || !noff) return m;
53 end--;
54 }
55}
56
57int dn_comp(const char *src, unsigned char *dst, int space, unsigned char **dnptrs, unsigned char **lastdnptr)
58{
59 int i, j, n, m=0, offset, bestlen=0, bestoff;
60 unsigned char lens[127];
61 unsigned char **p;
62 const char *end;
63 size_t l = strnlen(src, 255);
64 if (l && src[l-1] == '.') l--;
65 if (l>253 || space<=0) return -1;
66 if (!l) {
67 *dst = 0;
68 return 1;
69 }
70 end = src+l;
71 n = getlens(lens, src, l);
72 if (!n) return -1;
73
74 p = dnptrs;
75 if (p && *p) for (p++; *p; p++) {
76 m = match(&offset, *dnptrs, *p, end, lens, n);
77 if (m > bestlen) {
78 bestlen = m;
79 bestoff = offset;
80 if (m == l)
81 break;
82 }
83 }
84
85 /* encode unmatched part */
86 if (space < l-bestlen+2+(bestlen-1 < l-1)) return -1;
87 memcpy(dst+1, src, l-bestlen);
88 for (i=j=0; i<l-bestlen; i+=lens[j++]+1)
89 dst[i] = lens[j];
90
91 /* add tail */
92 if (bestlen) {
93 dst[i++] = 0xc0 | bestoff>>8;
94 dst[i++] = bestoff;
95 } else
96 dst[i++] = 0;
97
98 /* save dst pointer */
99 if (i>2 && lastdnptr && dnptrs && *dnptrs) {
100 while (*p) p++;
101 if (p+1 < lastdnptr) {
102 *p++ = dst;
103 *p=0;
104 }
105 }
106 return i;
107}
lib/libc/wasi/libc-top-half/musl/src/network/dn_expand.c deleted-33
......@@ -1,33 +0,0 @@
1#include <resolv.h>
2
3int __dn_expand(const unsigned char *base, const unsigned char *end, const unsigned char *src, char *dest, int space)
4{
5 const unsigned char *p = src;
6 char *dend, *dbegin = dest;
7 int len = -1, i, j;
8 if (p==end || space <= 0) return -1;
9 dend = dest + (space > 254 ? 254 : space);
10 /* detect reference loop using an iteration counter */
11 for (i=0; i < end-base; i+=2) {
12 /* loop invariants: p<end, dest<dend */
13 if (*p & 0xc0) {
14 if (p+1==end) return -1;
15 j = ((p[0] & 0x3f) << 8) | p[1];
16 if (len < 0) len = p+2-src;
17 if (j >= end-base) return -1;
18 p = base+j;
19 } else if (*p) {
20 if (dest != dbegin) *dest++ = '.';
21 j = *p++;
22 if (j >= end-p || j >= dend-dest) return -1;
23 while (j--) *dest++ = *p++;
24 } else {
25 *dest = 0;
26 if (len < 0) len = p+1-src;
27 return len;
28 }
29 }
30 return -1;
31}
32
33weak_alias(__dn_expand, dn_expand);
lib/libc/wasi/libc-top-half/musl/src/network/dn_skipname.c deleted-15
......@@ -1,15 +0,0 @@
1#include <resolv.h>
2
3int dn_skipname(const unsigned char *s, const unsigned char *end)
4{
5 const unsigned char *p = s;
6 while (p < end)
7 if (!*p) return p-s+1;
8 else if (*p>=192)
9 if (p+1<end) return p-s+2;
10 else break;
11 else
12 if (end-p<*p+1) break;
13 else p += *p + 1;
14 return -1;
15}
lib/libc/wasi/libc-top-half/musl/src/network/dns_parse.c deleted-33
......@@ -1,33 +0,0 @@
1#include <string.h>
2#include "lookup.h"
3
4int __dns_parse(const unsigned char *r, int rlen, int (*callback)(void *, int, const void *, int, const void *), void *ctx)
5{
6 int qdcount, ancount;
7 const unsigned char *p;
8 int len;
9
10 if (rlen<12) return -1;
11 if ((r[3]&15)) return 0;
12 p = r+12;
13 qdcount = r[4]*256 + r[5];
14 ancount = r[6]*256 + r[7];
15 if (qdcount+ancount > 64) return -1;
16 while (qdcount--) {
17 while (p-r < rlen && *p-1U < 127) p++;
18 if (*p>193 || (*p==193 && p[1]>254) || p>r+rlen-6)
19 return -1;
20 p += 5 + !!*p;
21 }
22 while (ancount--) {
23 while (p-r < rlen && *p-1U < 127) p++;
24 if (*p>193 || (*p==193 && p[1]>254) || p>r+rlen-6)
25 return -1;
26 p += 1 + !!*p;
27 len = p[8]*256 + p[9];
28 if (p+len > r+rlen) return -1;
29 if (callback(ctx, p[1], p+10, len, r) < 0) return -1;
30 p += 10 + len;
31 }
32 return 0;
33}
lib/libc/wasi/libc-top-half/musl/src/network/ent.c deleted-22
......@@ -1,22 +0,0 @@
1#include <netdb.h>
2
3void sethostent(int x)
4{
5}
6
7struct hostent *gethostent()
8{
9 return 0;
10}
11
12struct netent *getnetent()
13{
14 return 0;
15}
16
17void endhostent(void)
18{
19}
20
21weak_alias(sethostent, setnetent);
22weak_alias(endhostent, endnetent);
lib/libc/wasi/libc-top-half/musl/src/network/ether.c deleted-58
......@@ -1,58 +0,0 @@
1#include <stdlib.h>
2#include <netinet/ether.h>
3#include <stdio.h>
4
5struct ether_addr *ether_aton_r (const char *x, struct ether_addr *p_a)
6{
7 struct ether_addr a;
8 char *y;
9 for (int ii = 0; ii < 6; ii++) {
10 unsigned long int n;
11 if (ii != 0) {
12 if (x[0] != ':') return 0; /* bad format */
13 else x++;
14 }
15 n = strtoul (x, &y, 16);
16 x = y;
17 if (n > 0xFF) return 0; /* bad byte */
18 a.ether_addr_octet[ii] = n;
19 }
20 if (x[0] != 0) return 0; /* bad format */
21 *p_a = a;
22 return p_a;
23}
24
25struct ether_addr *ether_aton (const char *x)
26{
27 static struct ether_addr a;
28 return ether_aton_r (x, &a);
29}
30
31char *ether_ntoa_r (const struct ether_addr *p_a, char *x) {
32 char *y;
33 y = x;
34 for (int ii = 0; ii < 6; ii++) {
35 x += sprintf (x, ii == 0 ? "%.2X" : ":%.2X", p_a->ether_addr_octet[ii]);
36 }
37 return y;
38}
39
40char *ether_ntoa (const struct ether_addr *p_a) {
41 static char x[18];
42 return ether_ntoa_r (p_a, x);
43}
44
45int ether_line(const char *l, struct ether_addr *e, char *hostname)
46{
47 return -1;
48}
49
50int ether_ntohost(char *hostname, const struct ether_addr *e)
51{
52 return -1;
53}
54
55int ether_hostton(const char *hostname, struct ether_addr *e)
56{
57 return -1;
58}
lib/libc/wasi/libc-top-half/musl/src/network/freeaddrinfo.c deleted-16
......@@ -1,16 +0,0 @@
1#include <stdlib.h>
2#include <stddef.h>
3#include <netdb.h>
4#include "lookup.h"
5#include "lock.h"
6
7void freeaddrinfo(struct addrinfo *p)
8{
9 size_t cnt;
10 for (cnt=1; p->ai_next; cnt++, p=p->ai_next);
11 struct aibuf *b = (void *)((char *)p - offsetof(struct aibuf, ai));
12 b -= b->slot;
13 LOCK(b->lock);
14 if (!(b->ref -= cnt)) free(b);
15 else UNLOCK(b->lock);
16}
lib/libc/wasi/libc-top-half/musl/src/network/gai_strerror.c deleted-25
......@@ -1,25 +0,0 @@
1#include <netdb.h>
2#include "locale_impl.h"
3
4static const char msgs[] =
5 "Invalid flags\0"
6 "Name does not resolve\0"
7 "Try again\0"
8 "Non-recoverable error\0"
9 "Unknown error\0"
10 "Unrecognized address family or invalid length\0"
11 "Unrecognized socket type\0"
12 "Unrecognized service\0"
13 "Unknown error\0"
14 "Out of memory\0"
15 "System error\0"
16 "Overflow\0"
17 "\0Unknown error";
18
19const char *gai_strerror(int ecode)
20{
21 const char *s;
22 for (s=msgs, ecode++; ecode && *s; ecode++, s++) for (; *s; s++);
23 if (!*s) s++;
24 return LCTRANS_CUR(s);
25}
lib/libc/wasi/libc-top-half/musl/src/network/getaddrinfo.c deleted-135
......@@ -1,135 +0,0 @@
1#include <stdlib.h>
2#include <sys/socket.h>
3#include <netinet/in.h>
4#include <netdb.h>
5#include <string.h>
6#include <pthread.h>
7#include <unistd.h>
8#include <endian.h>
9#include <errno.h>
10#include "lookup.h"
11
12int getaddrinfo(const char *restrict host, const char *restrict serv, const struct addrinfo *restrict hint, struct addrinfo **restrict res)
13{
14 struct service ports[MAXSERVS];
15 struct address addrs[MAXADDRS];
16 char canon[256], *outcanon;
17 int nservs, naddrs, nais, canon_len, i, j, k;
18 int family = AF_UNSPEC, flags = 0, proto = 0, socktype = 0;
19 struct aibuf *out;
20
21 if (!host && !serv) return EAI_NONAME;
22
23 if (hint) {
24 family = hint->ai_family;
25 flags = hint->ai_flags;
26 proto = hint->ai_protocol;
27 socktype = hint->ai_socktype;
28
29 const int mask = AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST |
30 AI_V4MAPPED | AI_ALL | AI_ADDRCONFIG | AI_NUMERICSERV;
31 if ((flags & mask) != flags)
32 return EAI_BADFLAGS;
33
34 switch (family) {
35 case AF_INET:
36 case AF_INET6:
37 case AF_UNSPEC:
38 break;
39 default:
40 return EAI_FAMILY;
41 }
42 }
43
44 if (flags & AI_ADDRCONFIG) {
45 /* Define the "an address is configured" condition for address
46 * families via ability to create a socket for the family plus
47 * routability of the loopback address for the family. */
48 static const struct sockaddr_in lo4 = {
49 .sin_family = AF_INET, .sin_port = 65535,
50 .sin_addr.s_addr = __BYTE_ORDER == __BIG_ENDIAN
51 ? 0x7f000001 : 0x0100007f
52 };
53 static const struct sockaddr_in6 lo6 = {
54 .sin6_family = AF_INET6, .sin6_port = 65535,
55 .sin6_addr = IN6ADDR_LOOPBACK_INIT
56 };
57 int tf[2] = { AF_INET, AF_INET6 };
58 const void *ta[2] = { &lo4, &lo6 };
59 socklen_t tl[2] = { sizeof lo4, sizeof lo6 };
60 for (i=0; i<2; i++) {
61 if (family==tf[1-i]) continue;
62 int s = socket(tf[i], SOCK_CLOEXEC|SOCK_DGRAM,
63 IPPROTO_UDP);
64 if (s>=0) {
65 int cs;
66 pthread_setcancelstate(
67 PTHREAD_CANCEL_DISABLE, &cs);
68 int r = connect(s, ta[i], tl[i]);
69 pthread_setcancelstate(cs, 0);
70 close(s);
71 if (!r) continue;
72 }
73 switch (errno) {
74 case EADDRNOTAVAIL:
75 case EAFNOSUPPORT:
76 case EHOSTUNREACH:
77 case ENETDOWN:
78 case ENETUNREACH:
79 break;
80 default:
81 return EAI_SYSTEM;
82 }
83 if (family == tf[i]) return EAI_NONAME;
84 family = tf[1-i];
85 }
86 }
87
88 nservs = __lookup_serv(ports, serv, proto, socktype, flags);
89 if (nservs < 0) return nservs;
90
91 naddrs = __lookup_name(addrs, canon, host, family, flags);
92 if (naddrs < 0) return naddrs;
93
94 nais = nservs * naddrs;
95 canon_len = strlen(canon);
96 out = calloc(1, nais * sizeof(*out) + canon_len + 1);
97 if (!out) return EAI_MEMORY;
98
99 if (canon_len) {
100 outcanon = (void *)&out[nais];
101 memcpy(outcanon, canon, canon_len+1);
102 } else {
103 outcanon = 0;
104 }
105
106 for (k=i=0; i<naddrs; i++) for (j=0; j<nservs; j++, k++) {
107 out[k].slot = k;
108 out[k].ai = (struct addrinfo){
109 .ai_family = addrs[i].family,
110 .ai_socktype = ports[j].socktype,
111 .ai_protocol = ports[j].proto,
112 .ai_addrlen = addrs[i].family == AF_INET
113 ? sizeof(struct sockaddr_in)
114 : sizeof(struct sockaddr_in6),
115 .ai_addr = (void *)&out[k].sa,
116 .ai_canonname = outcanon };
117 if (k) out[k-1].ai.ai_next = &out[k].ai;
118 switch (addrs[i].family) {
119 case AF_INET:
120 out[k].sa.sin.sin_family = AF_INET;
121 out[k].sa.sin.sin_port = htons(ports[j].port);
122 memcpy(&out[k].sa.sin.sin_addr, &addrs[i].addr, 4);
123 break;
124 case AF_INET6:
125 out[k].sa.sin6.sin6_family = AF_INET6;
126 out[k].sa.sin6.sin6_port = htons(ports[j].port);
127 out[k].sa.sin6.sin6_scope_id = addrs[i].scopeid;
128 memcpy(&out[k].sa.sin6.sin6_addr, &addrs[i].addr, 16);
129 break;
130 }
131 }
132 out[0].ref = nais;
133 *res = &out->ai;
134 return 0;
135}
lib/libc/wasi/libc-top-half/musl/src/network/gethostbyaddr.c deleted-24
......@@ -1,24 +0,0 @@
1#define _GNU_SOURCE
2
3#include <netdb.h>
4#include <errno.h>
5#include <stdlib.h>
6
7struct hostent *gethostbyaddr(const void *a, socklen_t l, int af)
8{
9 static struct hostent *h;
10 size_t size = 63;
11 struct hostent *res;
12 int err;
13 do {
14 free(h);
15 h = malloc(size+=size+1);
16 if (!h) {
17 h_errno = NO_RECOVERY;
18 return 0;
19 }
20 err = gethostbyaddr_r(a, l, af, h,
21 (void *)(h+1), size-sizeof *h, &res, &h_errno);
22 } while (err == ERANGE);
23 return err ? 0 : h;
24}
lib/libc/wasi/libc-top-half/musl/src/network/gethostbyaddr_r.c deleted-71
......@@ -1,71 +0,0 @@
1#define _GNU_SOURCE
2
3#include <sys/socket.h>
4#include <netdb.h>
5#include <string.h>
6#include <netinet/in.h>
7#include <errno.h>
8#include <inttypes.h>
9
10int gethostbyaddr_r(const void *a, socklen_t l, int af,
11 struct hostent *h, char *buf, size_t buflen,
12 struct hostent **res, int *err)
13{
14 union {
15 struct sockaddr_in sin;
16 struct sockaddr_in6 sin6;
17 } sa = { .sin.sin_family = af };
18 socklen_t sl = af==AF_INET6 ? sizeof sa.sin6 : sizeof sa.sin;
19 int i;
20
21 *res = 0;
22
23 /* Load address argument into sockaddr structure */
24 if (af==AF_INET6 && l==16) memcpy(&sa.sin6.sin6_addr, a, 16);
25 else if (af==AF_INET && l==4) memcpy(&sa.sin.sin_addr, a, 4);
26 else {
27 *err = NO_RECOVERY;
28 return EINVAL;
29 }
30
31 /* Align buffer and check for space for pointers and ip address */
32 i = (uintptr_t)buf & sizeof(char *)-1;
33 if (!i) i = sizeof(char *);
34 if (buflen <= 5*sizeof(char *)-i + l) return ERANGE;
35 buf += sizeof(char *)-i;
36 buflen -= 5*sizeof(char *)-i + l;
37
38 h->h_addr_list = (void *)buf;
39 buf += 2*sizeof(char *);
40 h->h_aliases = (void *)buf;
41 buf += 2*sizeof(char *);
42
43 h->h_addr_list[0] = buf;
44 memcpy(h->h_addr_list[0], a, l);
45 buf += l;
46 h->h_addr_list[1] = 0;
47 h->h_aliases[0] = buf;
48 h->h_aliases[1] = 0;
49
50 switch (getnameinfo((void *)&sa, sl, buf, buflen, 0, 0, 0)) {
51 case EAI_AGAIN:
52 *err = TRY_AGAIN;
53 return EAGAIN;
54 case EAI_OVERFLOW:
55 return ERANGE;
56 default:
57 case EAI_MEMORY:
58 case EAI_SYSTEM:
59 case EAI_FAIL:
60 *err = NO_RECOVERY;
61 return errno;
62 case 0:
63 break;
64 }
65
66 h->h_addrtype = af;
67 h->h_length = l;
68 h->h_name = h->h_aliases[0];
69 *res = h;
70 return 0;
71}
lib/libc/wasi/libc-top-half/musl/src/network/gethostbyname.c deleted-11
......@@ -1,11 +0,0 @@
1#define _GNU_SOURCE
2
3#include <sys/socket.h>
4#include <netdb.h>
5#include <string.h>
6#include <netinet/in.h>
7
8struct hostent *gethostbyname(const char *name)
9{
10 return gethostbyname2(name, AF_INET);
11}
lib/libc/wasi/libc-top-half/musl/src/network/gethostbyname2.c deleted-25
......@@ -1,25 +0,0 @@
1#define _GNU_SOURCE
2
3#include <sys/socket.h>
4#include <netdb.h>
5#include <errno.h>
6#include <stdlib.h>
7
8struct hostent *gethostbyname2(const char *name, int af)
9{
10 static struct hostent *h;
11 size_t size = 63;
12 struct hostent *res;
13 int err;
14 do {
15 free(h);
16 h = malloc(size+=size+1);
17 if (!h) {
18 h_errno = NO_RECOVERY;
19 return 0;
20 }
21 err = gethostbyname2_r(name, af, h,
22 (void *)(h+1), size-sizeof *h, &res, &h_errno);
23 } while (err == ERANGE);
24 return err ? 0 : h;
25}
lib/libc/wasi/libc-top-half/musl/src/network/gethostbyname2_r.c deleted-80
......@@ -1,80 +0,0 @@
1#define _GNU_SOURCE
2
3#include <sys/socket.h>
4#include <netdb.h>
5#include <string.h>
6#include <netinet/in.h>
7#include <errno.h>
8#include <stdint.h>
9#include "lookup.h"
10
11int gethostbyname2_r(const char *name, int af,
12 struct hostent *h, char *buf, size_t buflen,
13 struct hostent **res, int *err)
14{
15 struct address addrs[MAXADDRS];
16 char canon[256];
17 int i, cnt;
18 size_t align, need;
19
20 *res = 0;
21 cnt = __lookup_name(addrs, canon, name, af, AI_CANONNAME);
22 if (cnt<0) switch (cnt) {
23 case EAI_NONAME:
24 *err = HOST_NOT_FOUND;
25 return ENOENT;
26 case EAI_AGAIN:
27 *err = TRY_AGAIN;
28 return EAGAIN;
29 default:
30 case EAI_FAIL:
31 *err = NO_RECOVERY;
32 return EBADMSG;
33 case EAI_MEMORY:
34 case EAI_SYSTEM:
35 *err = NO_RECOVERY;
36 return errno;
37 }
38
39 h->h_addrtype = af;
40 h->h_length = af==AF_INET6 ? 16 : 4;
41
42 /* Align buffer */
43 align = -(uintptr_t)buf & sizeof(char *)-1;
44
45 need = 4*sizeof(char *);
46 need += (cnt + 1) * (sizeof(char *) + h->h_length);
47 need += strlen(name)+1;
48 need += strlen(canon)+1;
49 need += align;
50
51 if (need > buflen) return ERANGE;
52
53 buf += align;
54 h->h_aliases = (void *)buf;
55 buf += 3*sizeof(char *);
56 h->h_addr_list = (void *)buf;
57 buf += (cnt+1)*sizeof(char *);
58
59 for (i=0; i<cnt; i++) {
60 h->h_addr_list[i] = (void *)buf;
61 buf += h->h_length;
62 memcpy(h->h_addr_list[i], addrs[i].addr, h->h_length);
63 }
64 h->h_addr_list[i] = 0;
65
66 h->h_name = h->h_aliases[0] = buf;
67 strcpy(h->h_name, canon);
68 buf += strlen(h->h_name)+1;
69
70 if (strcmp(h->h_name, name)) {
71 h->h_aliases[1] = buf;
72 strcpy(h->h_aliases[1], name);
73 buf += strlen(h->h_aliases[1])+1;
74 } else h->h_aliases[1] = 0;
75
76 h->h_aliases[2] = 0;
77
78 *res = h;
79 return 0;
80}
lib/libc/wasi/libc-top-half/musl/src/network/gethostbyname_r.c deleted-11
......@@ -1,11 +0,0 @@
1#define _GNU_SOURCE
2
3#include <sys/socket.h>
4#include <netdb.h>
5
6int gethostbyname_r(const char *name,
7 struct hostent *h, char *buf, size_t buflen,
8 struct hostent **res, int *err)
9{
10 return gethostbyname2_r(name, AF_INET, h, buf, buflen, res, err);
11}
lib/libc/wasi/libc-top-half/musl/src/network/getifaddrs.c deleted-216
......@@ -1,216 +0,0 @@
1#define _GNU_SOURCE
2#include <errno.h>
3#include <string.h>
4#include <stdlib.h>
5#include <unistd.h>
6#include <ifaddrs.h>
7#include <syscall.h>
8#include <net/if.h>
9#include <netinet/in.h>
10#include "netlink.h"
11
12#define IFADDRS_HASH_SIZE 64
13
14/* getifaddrs() reports hardware addresses with PF_PACKET that implies
15 * struct sockaddr_ll. But e.g. Infiniband socket address length is
16 * longer than sockaddr_ll.ssl_addr[8] can hold. Use this hack struct
17 * to extend ssl_addr - callers should be able to still use it. */
18struct sockaddr_ll_hack {
19 unsigned short sll_family, sll_protocol;
20 int sll_ifindex;
21 unsigned short sll_hatype;
22 unsigned char sll_pkttype, sll_halen;
23 unsigned char sll_addr[24];
24};
25
26union sockany {
27 struct sockaddr sa;
28 struct sockaddr_ll_hack ll;
29 struct sockaddr_in v4;
30 struct sockaddr_in6 v6;
31};
32
33struct ifaddrs_storage {
34 struct ifaddrs ifa;
35 struct ifaddrs_storage *hash_next;
36 union sockany addr, netmask, ifu;
37 unsigned int index;
38 char name[IFNAMSIZ+1];
39};
40
41struct ifaddrs_ctx {
42 struct ifaddrs_storage *first;
43 struct ifaddrs_storage *last;
44 struct ifaddrs_storage *hash[IFADDRS_HASH_SIZE];
45};
46
47void freeifaddrs(struct ifaddrs *ifp)
48{
49 struct ifaddrs *n;
50 while (ifp) {
51 n = ifp->ifa_next;
52 free(ifp);
53 ifp = n;
54 }
55}
56
57static void copy_addr(struct sockaddr **r, int af, union sockany *sa, void *addr, size_t addrlen, int ifindex)
58{
59 uint8_t *dst;
60 int len;
61
62 switch (af) {
63 case AF_INET:
64 dst = (uint8_t*) &sa->v4.sin_addr;
65 len = 4;
66 break;
67 case AF_INET6:
68 dst = (uint8_t*) &sa->v6.sin6_addr;
69 len = 16;
70 if (IN6_IS_ADDR_LINKLOCAL(addr) || IN6_IS_ADDR_MC_LINKLOCAL(addr))
71 sa->v6.sin6_scope_id = ifindex;
72 break;
73 default:
74 return;
75 }
76 if (addrlen < len) return;
77 sa->sa.sa_family = af;
78 memcpy(dst, addr, len);
79 *r = &sa->sa;
80}
81
82static void gen_netmask(struct sockaddr **r, int af, union sockany *sa, int prefixlen)
83{
84 uint8_t addr[16] = {0};
85 int i;
86
87 if (prefixlen > 8*sizeof(addr)) prefixlen = 8*sizeof(addr);
88 i = prefixlen / 8;
89 memset(addr, 0xff, i);
90 if (i < sizeof(addr)) addr[i++] = 0xff << (8 - (prefixlen % 8));
91 copy_addr(r, af, sa, addr, sizeof(addr), 0);
92}
93
94static void copy_lladdr(struct sockaddr **r, union sockany *sa, void *addr, size_t addrlen, int ifindex, unsigned short hatype)
95{
96 if (addrlen > sizeof(sa->ll.sll_addr)) return;
97 sa->ll.sll_family = AF_PACKET;
98 sa->ll.sll_ifindex = ifindex;
99 sa->ll.sll_hatype = hatype;
100 sa->ll.sll_halen = addrlen;
101 memcpy(sa->ll.sll_addr, addr, addrlen);
102 *r = &sa->sa;
103}
104
105static int netlink_msg_to_ifaddr(void *pctx, struct nlmsghdr *h)
106{
107 struct ifaddrs_ctx *ctx = pctx;
108 struct ifaddrs_storage *ifs, *ifs0;
109 struct ifinfomsg *ifi = NLMSG_DATA(h);
110 struct ifaddrmsg *ifa = NLMSG_DATA(h);
111 struct rtattr *rta;
112 int stats_len = 0;
113
114 if (h->nlmsg_type == RTM_NEWLINK) {
115 for (rta = NLMSG_RTA(h, sizeof(*ifi)); NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) {
116 if (rta->rta_type != IFLA_STATS) continue;
117 stats_len = RTA_DATALEN(rta);
118 break;
119 }
120 } else {
121 for (ifs0 = ctx->hash[ifa->ifa_index % IFADDRS_HASH_SIZE]; ifs0; ifs0 = ifs0->hash_next)
122 if (ifs0->index == ifa->ifa_index)
123 break;
124 if (!ifs0) return 0;
125 }
126
127 ifs = calloc(1, sizeof(struct ifaddrs_storage) + stats_len);
128 if (ifs == 0) return -1;
129
130 if (h->nlmsg_type == RTM_NEWLINK) {
131 ifs->index = ifi->ifi_index;
132 ifs->ifa.ifa_flags = ifi->ifi_flags;
133
134 for (rta = NLMSG_RTA(h, sizeof(*ifi)); NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) {
135 switch (rta->rta_type) {
136 case IFLA_IFNAME:
137 if (RTA_DATALEN(rta) < sizeof(ifs->name)) {
138 memcpy(ifs->name, RTA_DATA(rta), RTA_DATALEN(rta));
139 ifs->ifa.ifa_name = ifs->name;
140 }
141 break;
142 case IFLA_ADDRESS:
143 copy_lladdr(&ifs->ifa.ifa_addr, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifi->ifi_index, ifi->ifi_type);
144 break;
145 case IFLA_BROADCAST:
146 copy_lladdr(&ifs->ifa.ifa_broadaddr, &ifs->ifu, RTA_DATA(rta), RTA_DATALEN(rta), ifi->ifi_index, ifi->ifi_type);
147 break;
148 case IFLA_STATS:
149 ifs->ifa.ifa_data = (void*)(ifs+1);
150 memcpy(ifs->ifa.ifa_data, RTA_DATA(rta), RTA_DATALEN(rta));
151 break;
152 }
153 }
154 if (ifs->ifa.ifa_name) {
155 unsigned int bucket = ifs->index % IFADDRS_HASH_SIZE;
156 ifs->hash_next = ctx->hash[bucket];
157 ctx->hash[bucket] = ifs;
158 }
159 } else {
160 ifs->ifa.ifa_name = ifs0->ifa.ifa_name;
161 ifs->ifa.ifa_flags = ifs0->ifa.ifa_flags;
162 for (rta = NLMSG_RTA(h, sizeof(*ifa)); NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) {
163 switch (rta->rta_type) {
164 case IFA_ADDRESS:
165 /* If ifa_addr is already set we, received an IFA_LOCAL before
166 * so treat this as destination address */
167 if (ifs->ifa.ifa_addr)
168 copy_addr(&ifs->ifa.ifa_dstaddr, ifa->ifa_family, &ifs->ifu, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
169 else
170 copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
171 break;
172 case IFA_BROADCAST:
173 copy_addr(&ifs->ifa.ifa_broadaddr, ifa->ifa_family, &ifs->ifu, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
174 break;
175 case IFA_LOCAL:
176 /* If ifa_addr is set and we get IFA_LOCAL, assume we have
177 * a point-to-point network. Move address to correct field. */
178 if (ifs->ifa.ifa_addr) {
179 ifs->ifu = ifs->addr;
180 ifs->ifa.ifa_dstaddr = &ifs->ifu.sa;
181 memset(&ifs->addr, 0, sizeof(ifs->addr));
182 }
183 copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
184 break;
185 case IFA_LABEL:
186 if (RTA_DATALEN(rta) < sizeof(ifs->name)) {
187 memcpy(ifs->name, RTA_DATA(rta), RTA_DATALEN(rta));
188 ifs->ifa.ifa_name = ifs->name;
189 }
190 break;
191 }
192 }
193 if (ifs->ifa.ifa_addr)
194 gen_netmask(&ifs->ifa.ifa_netmask, ifa->ifa_family, &ifs->netmask, ifa->ifa_prefixlen);
195 }
196
197 if (ifs->ifa.ifa_name) {
198 if (!ctx->first) ctx->first = ifs;
199 if (ctx->last) ctx->last->ifa.ifa_next = &ifs->ifa;
200 ctx->last = ifs;
201 } else {
202 free(ifs);
203 }
204 return 0;
205}
206
207int getifaddrs(struct ifaddrs **ifap)
208{
209 struct ifaddrs_ctx _ctx, *ctx = &_ctx;
210 int r;
211 memset(ctx, 0, sizeof *ctx);
212 r = __rtnetlink_enumerate(AF_UNSPEC, AF_UNSPEC, netlink_msg_to_ifaddr, ctx);
213 if (r == 0) *ifap = &ctx->first->ifa;
214 else freeifaddrs(&ctx->first->ifa);
215 return r;
216}
lib/libc/wasi/libc-top-half/musl/src/network/getnameinfo.c deleted-200
......@@ -1,200 +0,0 @@
1#include <netdb.h>
2#include <limits.h>
3#include <string.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <sys/socket.h>
7#include <netinet/in.h>
8#include <arpa/inet.h>
9#include <net/if.h>
10#include <ctype.h>
11#include <resolv.h>
12#include "lookup.h"
13#include "stdio_impl.h"
14
15#define PTR_MAX (64 + sizeof ".in-addr.arpa")
16#define RR_PTR 12
17
18static char *itoa(char *p, unsigned x) {
19 p += 3*sizeof(int);
20 *--p = 0;
21 do {
22 *--p = '0' + x % 10;
23 x /= 10;
24 } while (x);
25 return p;
26}
27
28static void mkptr4(char *s, const unsigned char *ip)
29{
30 sprintf(s, "%d.%d.%d.%d.in-addr.arpa",
31 ip[3], ip[2], ip[1], ip[0]);
32}
33
34static void mkptr6(char *s, const unsigned char *ip)
35{
36 static const char xdigits[] = "0123456789abcdef";
37 int i;
38 for (i=15; i>=0; i--) {
39 *s++ = xdigits[ip[i]&15]; *s++ = '.';
40 *s++ = xdigits[ip[i]>>4]; *s++ = '.';
41 }
42 strcpy(s, "ip6.arpa");
43}
44
45static void reverse_hosts(char *buf, const unsigned char *a, unsigned scopeid, int family)
46{
47 char line[512], *p, *z;
48 unsigned char _buf[1032], atmp[16];
49 struct address iplit;
50 FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf);
51 if (!f) return;
52 if (family == AF_INET) {
53 memcpy(atmp+12, a, 4);
54 memcpy(atmp, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
55 a = atmp;
56 }
57 while (fgets(line, sizeof line, f)) {
58 if ((p=strchr(line, '#'))) *p++='\n', *p=0;
59
60 for (p=line; *p && !isspace(*p); p++);
61 *p++ = 0;
62 if (__lookup_ipliteral(&iplit, line, AF_UNSPEC)<=0)
63 continue;
64
65 if (iplit.family == AF_INET) {
66 memcpy(iplit.addr+12, iplit.addr, 4);
67 memcpy(iplit.addr, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
68 iplit.scopeid = 0;
69 }
70
71 if (memcmp(a, iplit.addr, 16) || iplit.scopeid != scopeid)
72 continue;
73
74 for (; *p && isspace(*p); p++);
75 for (z=p; *z && !isspace(*z); z++);
76 *z = 0;
77 if (z-p < 256) {
78 memcpy(buf, p, z-p+1);
79 break;
80 }
81 }
82 __fclose_ca(f);
83}
84
85static void reverse_services(char *buf, int port, int dgram)
86{
87 unsigned long svport;
88 char line[128], *p, *z;
89 unsigned char _buf[1032];
90 FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf);
91 if (!f) return;
92 while (fgets(line, sizeof line, f)) {
93 if ((p=strchr(line, '#'))) *p++='\n', *p=0;
94
95 for (p=line; *p && !isspace(*p); p++);
96 if (!*p) continue;
97 *p++ = 0;
98 svport = strtoul(p, &z, 10);
99
100 if (svport != port || z==p) continue;
101 if (dgram && strncmp(z, "/udp", 4)) continue;
102 if (!dgram && strncmp(z, "/tcp", 4)) continue;
103 if (p-line > 32) continue;
104
105 memcpy(buf, line, p-line);
106 break;
107 }
108 __fclose_ca(f);
109}
110
111static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet)
112{
113 if (rr != RR_PTR) return 0;
114 if (__dn_expand(packet, (const unsigned char *)packet + 512,
115 data, c, 256) <= 0)
116 *(char *)c = 0;
117 return 0;
118
119}
120
121int getnameinfo(const struct sockaddr *restrict sa, socklen_t sl,
122 char *restrict node, socklen_t nodelen,
123 char *restrict serv, socklen_t servlen,
124 int flags)
125{
126 char ptr[PTR_MAX];
127 char buf[256], num[3*sizeof(int)+1];
128 int af = sa->sa_family;
129 unsigned char *a;
130 unsigned scopeid;
131
132 switch (af) {
133 case AF_INET:
134 a = (void *)&((struct sockaddr_in *)sa)->sin_addr;
135 if (sl < sizeof(struct sockaddr_in)) return EAI_FAMILY;
136 mkptr4(ptr, a);
137 scopeid = 0;
138 break;
139 case AF_INET6:
140 a = (void *)&((struct sockaddr_in6 *)sa)->sin6_addr;
141 if (sl < sizeof(struct sockaddr_in6)) return EAI_FAMILY;
142 if (memcmp(a, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12))
143 mkptr6(ptr, a);
144 else
145 mkptr4(ptr, a+12);
146 scopeid = ((struct sockaddr_in6 *)sa)->sin6_scope_id;
147 break;
148 default:
149 return EAI_FAMILY;
150 }
151
152 if (node && nodelen) {
153 buf[0] = 0;
154 if (!(flags & NI_NUMERICHOST)) {
155 reverse_hosts(buf, a, scopeid, af);
156 }
157 if (!*buf && !(flags & NI_NUMERICHOST)) {
158 unsigned char query[18+PTR_MAX], reply[512];
159 int qlen = __res_mkquery(0, ptr, 1, RR_PTR,
160 0, 0, 0, query, sizeof query);
161 query[3] = 0; /* don't need AD flag */
162 int rlen = __res_send(query, qlen, reply, sizeof reply);
163 buf[0] = 0;
164 if (rlen > 0)
165 __dns_parse(reply, rlen, dns_parse_callback, buf);
166 }
167 if (!*buf) {
168 if (flags & NI_NAMEREQD) return EAI_NONAME;
169 inet_ntop(af, a, buf, sizeof buf);
170 if (scopeid) {
171 char *p = 0, tmp[IF_NAMESIZE+1];
172 if (!(flags & NI_NUMERICSCOPE) &&
173 (IN6_IS_ADDR_LINKLOCAL(a) ||
174 IN6_IS_ADDR_MC_LINKLOCAL(a)))
175 p = if_indextoname(scopeid, tmp+1);
176 if (!p)
177 p = itoa(num, scopeid);
178 *--p = '%';
179 strcat(buf, p);
180 }
181 }
182 if (strlen(buf) >= nodelen) return EAI_OVERFLOW;
183 strcpy(node, buf);
184 }
185
186 if (serv && servlen) {
187 char *p = buf;
188 int port = ntohs(((struct sockaddr_in *)sa)->sin_port);
189 buf[0] = 0;
190 if (!(flags & NI_NUMERICSERV))
191 reverse_services(buf, port, flags & NI_DGRAM);
192 if (!*p)
193 p = itoa(num, port);
194 if (strlen(p) >= servlen)
195 return EAI_OVERFLOW;
196 strcpy(serv, p);
197 }
198
199 return 0;
200}
lib/libc/wasi/libc-top-half/musl/src/network/getpeername.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/socket.h>
2#include "syscall.h"
3
4int getpeername(int fd, struct sockaddr *restrict addr, socklen_t *restrict len)
5{
6 return socketcall(getpeername, fd, addr, len, 0, 0, 0);
7}
lib/libc/wasi/libc-top-half/musl/src/network/getservbyname.c deleted-12
......@@ -1,12 +0,0 @@
1#define _GNU_SOURCE
2#include <netdb.h>
3
4struct servent *getservbyname(const char *name, const char *prots)
5{
6 static struct servent se;
7 static char *buf[2];
8 struct servent *res;
9 if (getservbyname_r(name, prots, &se, (void *)buf, sizeof buf, &res))
10 return 0;
11 return &se;
12}
lib/libc/wasi/libc-top-half/musl/src/network/getservbyname_r.c deleted-55
......@@ -1,55 +0,0 @@
1#define _GNU_SOURCE
2#include <sys/socket.h>
3#include <netinet/in.h>
4#include <netdb.h>
5#include <inttypes.h>
6#include <errno.h>
7#include <string.h>
8#include <stdlib.h>
9#include "lookup.h"
10
11#define ALIGN (sizeof(struct { char a; char *b; }) - sizeof(char *))
12
13int getservbyname_r(const char *name, const char *prots,
14 struct servent *se, char *buf, size_t buflen, struct servent **res)
15{
16 struct service servs[MAXSERVS];
17 int cnt, proto, align;
18
19 *res = 0;
20
21 /* Don't treat numeric port number strings as service records. */
22 char *end = "";
23 strtoul(name, &end, 10);
24 if (!*end) return ENOENT;
25
26 /* Align buffer */
27 align = -(uintptr_t)buf & ALIGN-1;
28 if (buflen < 2*sizeof(char *)+align)
29 return ERANGE;
30 buf += align;
31
32 if (!prots) proto = 0;
33 else if (!strcmp(prots, "tcp")) proto = IPPROTO_TCP;
34 else if (!strcmp(prots, "udp")) proto = IPPROTO_UDP;
35 else return EINVAL;
36
37 cnt = __lookup_serv(servs, name, proto, 0, 0);
38 if (cnt<0) switch (cnt) {
39 case EAI_MEMORY:
40 case EAI_SYSTEM:
41 return ENOMEM;
42 default:
43 return ENOENT;
44 }
45
46 se->s_name = (char *)name;
47 se->s_aliases = (void *)buf;
48 se->s_aliases[0] = se->s_name;
49 se->s_aliases[1] = 0;
50 se->s_port = htons(servs[0].port);
51 se->s_proto = servs[0].proto == IPPROTO_TCP ? "tcp" : "udp";
52
53 *res = se;
54 return 0;
55}
lib/libc/wasi/libc-top-half/musl/src/network/getservbyport.c deleted-12
......@@ -1,12 +0,0 @@
1#define _GNU_SOURCE
2#include <netdb.h>
3
4struct servent *getservbyport(int port, const char *prots)
5{
6 static struct servent se;
7 static long buf[32/sizeof(long)];
8 struct servent *res;
9 if (getservbyport_r(port, prots, &se, (void *)buf, sizeof buf, &res))
10 return 0;
11 return &se;
12}
lib/libc/wasi/libc-top-half/musl/src/network/getservbyport_r.c deleted-60
......@@ -1,60 +0,0 @@
1#define _GNU_SOURCE
2#include <sys/socket.h>
3#include <netinet/in.h>
4#include <netdb.h>
5#include <inttypes.h>
6#include <errno.h>
7#include <string.h>
8#include <stdlib.h>
9
10int getservbyport_r(int port, const char *prots,
11 struct servent *se, char *buf, size_t buflen, struct servent **res)
12{
13 int i;
14 struct sockaddr_in sin = {
15 .sin_family = AF_INET,
16 .sin_port = port,
17 };
18
19 if (!prots) {
20 int r = getservbyport_r(port, "tcp", se, buf, buflen, res);
21 if (r) r = getservbyport_r(port, "udp", se, buf, buflen, res);
22 return r;
23 }
24 *res = 0;
25
26 /* Align buffer */
27 i = (uintptr_t)buf & sizeof(char *)-1;
28 if (!i) i = sizeof(char *);
29 if (buflen < 3*sizeof(char *)-i)
30 return ERANGE;
31 buf += sizeof(char *)-i;
32 buflen -= sizeof(char *)-i;
33
34 if (strcmp(prots, "tcp") && strcmp(prots, "udp")) return EINVAL;
35
36 se->s_port = port;
37 se->s_proto = (char *)prots;
38 se->s_aliases = (void *)buf;
39 buf += 2*sizeof(char *);
40 buflen -= 2*sizeof(char *);
41 se->s_aliases[1] = 0;
42 se->s_aliases[0] = se->s_name = buf;
43
44 switch (getnameinfo((void *)&sin, sizeof sin, 0, 0, buf, buflen,
45 strcmp(prots, "udp") ? 0 : NI_DGRAM)) {
46 case EAI_MEMORY:
47 case EAI_SYSTEM:
48 return ENOMEM;
49 default:
50 return ENOENT;
51 case 0:
52 break;
53 }
54
55 /* A numeric port string is not a service record. */
56 if (strtol(buf, 0, 10)==ntohs(port)) return ENOENT;
57
58 *res = se;
59 return 0;
60}
lib/libc/wasi/libc-top-half/musl/src/network/getsockname.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/socket.h>
2#include "syscall.h"
3
4int getsockname(int fd, struct sockaddr *restrict addr, socklen_t *restrict len)
5{
6 return socketcall(getsockname, fd, addr, len, 0, 0, 0);
7}
lib/libc/wasi/libc-top-half/musl/src/network/getsockopt.c deleted-41
......@@ -1,41 +0,0 @@
1#include <sys/socket.h>
2#include <sys/time.h>
3#include <errno.h>
4#include "syscall.h"
5
6int getsockopt(int fd, int level, int optname, void *restrict optval, socklen_t *restrict optlen)
7{
8 long tv32[2];
9 struct timeval *tv;
10
11 int r = __socketcall(getsockopt, fd, level, optname, optval, optlen, 0);
12
13 if (r==-ENOPROTOOPT) switch (level) {
14 case SOL_SOCKET:
15 switch (optname) {
16 case SO_RCVTIMEO:
17 case SO_SNDTIMEO:
18 if (SO_RCVTIMEO == SO_RCVTIMEO_OLD) break;
19 if (*optlen < sizeof *tv) return __syscall_ret(-EINVAL);
20 if (optname==SO_RCVTIMEO) optname=SO_RCVTIMEO_OLD;
21 if (optname==SO_SNDTIMEO) optname=SO_SNDTIMEO_OLD;
22 r = __socketcall(getsockopt, fd, level, optname,
23 tv32, (socklen_t[]){sizeof tv32}, 0);
24 if (r<0) break;
25 tv = optval;
26 tv->tv_sec = tv32[0];
27 tv->tv_usec = tv32[1];
28 *optlen = sizeof *tv;
29 break;
30 case SO_TIMESTAMP:
31 case SO_TIMESTAMPNS:
32 if (SO_TIMESTAMP == SO_TIMESTAMP_OLD) break;
33 if (optname==SO_TIMESTAMP) optname=SO_TIMESTAMP_OLD;
34 if (optname==SO_TIMESTAMPNS) optname=SO_TIMESTAMPNS_OLD;
35 r = __socketcall(getsockopt, fd, level,
36 optname, optval, optlen, 0);
37 break;
38 }
39 }
40 return __syscall_ret(r);
41}
lib/libc/wasi/libc-top-half/musl/src/network/h_errno.c deleted-11
......@@ -1,11 +0,0 @@
1#include <netdb.h>
2#include "pthread_impl.h"
3
4#undef h_errno
5int h_errno;
6
7int *__h_errno_location(void)
8{
9 if (!__pthread_self()->stack) return &h_errno;
10 return &__pthread_self()->h_errno_val;
11}
lib/libc/wasi/libc-top-half/musl/src/network/herror.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <stdio.h>
3#include <netdb.h>
4
5void herror(const char *msg)
6{
7 fprintf(stderr, "%s%s%s\n", msg?msg:"", msg?": ":"", hstrerror(h_errno));
8}
lib/libc/wasi/libc-top-half/musl/src/network/hstrerror.c deleted-18
......@@ -1,18 +0,0 @@
1#define _GNU_SOURCE
2#include <netdb.h>
3#include "locale_impl.h"
4
5static const char msgs[] =
6 "Host not found\0"
7 "Try again\0"
8 "Non-recoverable error\0"
9 "Address not available\0"
10 "\0Unknown error";
11
12const char *hstrerror(int ecode)
13{
14 const char *s;
15 for (s=msgs, ecode--; ecode && *s; ecode--, s++) for (; *s; s++);
16 if (!*s) s++;
17 return LCTRANS_CUR(s);
18}
lib/libc/wasi/libc-top-half/musl/src/network/if_freenameindex.c deleted-7
......@@ -1,7 +0,0 @@
1#include <net/if.h>
2#include <stdlib.h>
3
4void if_freenameindex(struct if_nameindex *idx)
5{
6 free(idx);
7}
lib/libc/wasi/libc-top-half/musl/src/network/if_indextoname.c deleted-23
......@@ -1,23 +0,0 @@
1#define _GNU_SOURCE
2#include <net/if.h>
3#include <sys/socket.h>
4#include <sys/ioctl.h>
5#include <string.h>
6#include <errno.h>
7#include "syscall.h"
8
9char *if_indextoname(unsigned index, char *name)
10{
11 struct ifreq ifr;
12 int fd, r;
13
14 if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 0;
15 ifr.ifr_ifindex = index;
16 r = ioctl(fd, SIOCGIFNAME, &ifr);
17 __syscall(SYS_close, fd);
18 if (r < 0) {
19 if (errno == ENODEV) errno = ENXIO;
20 return 0;
21 }
22 return strncpy(name, ifr.ifr_name, IF_NAMESIZE);
23}
lib/libc/wasi/libc-top-half/musl/src/network/if_nameindex.c deleted-114
......@@ -1,114 +0,0 @@
1#define _GNU_SOURCE
2#include <net/if.h>
3#include <errno.h>
4#include <unistd.h>
5#include <stdlib.h>
6#include <string.h>
7#include <pthread.h>
8#include "netlink.h"
9
10#define IFADDRS_HASH_SIZE 64
11
12struct ifnamemap {
13 unsigned int hash_next;
14 unsigned int index;
15 unsigned char namelen;
16 char name[IFNAMSIZ];
17};
18
19struct ifnameindexctx {
20 unsigned int num, allocated, str_bytes;
21 struct ifnamemap *list;
22 unsigned int hash[IFADDRS_HASH_SIZE];
23};
24
25static int netlink_msg_to_nameindex(void *pctx, struct nlmsghdr *h)
26{
27 struct ifnameindexctx *ctx = pctx;
28 struct ifnamemap *map;
29 struct rtattr *rta;
30 unsigned int i;
31 int index, type, namelen, bucket;
32
33 if (h->nlmsg_type == RTM_NEWLINK) {
34 struct ifinfomsg *ifi = NLMSG_DATA(h);
35 index = ifi->ifi_index;
36 type = IFLA_IFNAME;
37 rta = NLMSG_RTA(h, sizeof(*ifi));
38 } else {
39 struct ifaddrmsg *ifa = NLMSG_DATA(h);
40 index = ifa->ifa_index;
41 type = IFA_LABEL;
42 rta = NLMSG_RTA(h, sizeof(*ifa));
43 }
44 for (; NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) {
45 if (rta->rta_type != type) continue;
46
47 namelen = RTA_DATALEN(rta) - 1;
48 if (namelen > IFNAMSIZ) return 0;
49
50 /* suppress duplicates */
51 bucket = index % IFADDRS_HASH_SIZE;
52 i = ctx->hash[bucket];
53 while (i) {
54 map = &ctx->list[i-1];
55 if (map->index == index &&
56 map->namelen == namelen &&
57 memcmp(map->name, RTA_DATA(rta), namelen) == 0)
58 return 0;
59 i = map->hash_next;
60 }
61
62 if (ctx->num >= ctx->allocated) {
63 size_t a = ctx->allocated ? ctx->allocated * 2 + 1 : 8;
64 if (a > SIZE_MAX/sizeof *map) return -1;
65 map = realloc(ctx->list, a * sizeof *map);
66 if (!map) return -1;
67 ctx->list = map;
68 ctx->allocated = a;
69 }
70 map = &ctx->list[ctx->num];
71 map->index = index;
72 map->namelen = namelen;
73 memcpy(map->name, RTA_DATA(rta), namelen);
74 ctx->str_bytes += namelen + 1;
75 ctx->num++;
76 map->hash_next = ctx->hash[bucket];
77 ctx->hash[bucket] = ctx->num;
78 return 0;
79 }
80 return 0;
81}
82
83struct if_nameindex *if_nameindex()
84{
85 struct ifnameindexctx _ctx, *ctx = &_ctx;
86 struct if_nameindex *ifs = 0, *d;
87 struct ifnamemap *s;
88 char *p;
89 int i;
90 int cs;
91
92 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
93 memset(ctx, 0, sizeof(*ctx));
94 if (__rtnetlink_enumerate(AF_UNSPEC, AF_INET, netlink_msg_to_nameindex, ctx) < 0) goto err;
95
96 ifs = malloc(sizeof(struct if_nameindex[ctx->num+1]) + ctx->str_bytes);
97 if (!ifs) goto err;
98
99 p = (char*)(ifs + ctx->num + 1);
100 for (i = ctx->num, d = ifs, s = ctx->list; i; i--, s++, d++) {
101 d->if_index = s->index;
102 d->if_name = p;
103 memcpy(p, s->name, s->namelen);
104 p += s->namelen;
105 *p++ = 0;
106 }
107 d->if_index = 0;
108 d->if_name = 0;
109err:
110 pthread_setcancelstate(cs, 0);
111 free(ctx->list);
112 errno = ENOBUFS;
113 return ifs;
114}
lib/libc/wasi/libc-top-half/musl/src/network/if_nametoindex.c deleted-18
......@@ -1,18 +0,0 @@
1#define _GNU_SOURCE
2#include <net/if.h>
3#include <sys/socket.h>
4#include <sys/ioctl.h>
5#include <string.h>
6#include "syscall.h"
7
8unsigned if_nametoindex(const char *name)
9{
10 struct ifreq ifr;
11 int fd, r;
12
13 if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 0;
14 strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
15 r = ioctl(fd, SIOCGIFINDEX, &ifr);
16 __syscall(SYS_close, fd);
17 return r < 0 ? 0 : ifr.ifr_ifindex;
18}
lib/libc/wasi/libc-top-half/musl/src/network/inet_addr.c deleted-10
......@@ -1,10 +0,0 @@
1#include <sys/socket.h>
2#include <netinet/in.h>
3#include <arpa/inet.h>
4
5in_addr_t inet_addr(const char *p)
6{
7 struct in_addr a;
8 if (!__inet_aton(p, &a)) return -1;
9 return a.s_addr;
10}
lib/libc/wasi/libc-top-half/musl/src/network/inet_legacy.c deleted-32
......@@ -1,32 +0,0 @@
1#include <sys/socket.h>
2#include <netinet/in.h>
3#include <arpa/inet.h>
4
5in_addr_t inet_network(const char *p)
6{
7 return ntohl(inet_addr(p));
8}
9
10struct in_addr inet_makeaddr(in_addr_t n, in_addr_t h)
11{
12 if (n < 256) h |= n<<24;
13 else if (n < 65536) h |= n<<16;
14 else h |= n<<8;
15 return (struct in_addr){ h };
16}
17
18in_addr_t inet_lnaof(struct in_addr in)
19{
20 uint32_t h = in.s_addr;
21 if (h>>24 < 128) return h & 0xffffff;
22 if (h>>24 < 192) return h & 0xffff;
23 return h & 0xff;
24}
25
26in_addr_t inet_netof(struct in_addr in)
27{
28 uint32_t h = in.s_addr;
29 if (h>>24 < 128) return h >> 24;
30 if (h>>24 < 192) return h >> 16;
31 return h >> 8;
32}
lib/libc/wasi/libc-top-half/musl/src/network/inet_ntoa.c deleted-10
......@@ -1,10 +0,0 @@
1#include <arpa/inet.h>
2#include <stdio.h>
3
4char *inet_ntoa(struct in_addr in)
5{
6 static char buf[16];
7 unsigned char *a = (void *)&in;
8 snprintf(buf, sizeof buf, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
9 return buf;
10}
lib/libc/wasi/libc-top-half/musl/src/network/listen.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/socket.h>
2#include "syscall.h"
3
4int listen(int fd, int backlog)
5{
6 return socketcall(listen, fd, backlog, 0, 0, 0, 0);
7}
lib/libc/wasi/libc-top-half/musl/src/network/lookup_ipliteral.c deleted-55
......@@ -1,55 +0,0 @@
1#include <sys/socket.h>
2#include <netinet/in.h>
3#include <netdb.h>
4#include <net/if.h>
5#include <arpa/inet.h>
6#include <limits.h>
7#include <stdlib.h>
8#include <string.h>
9#include <ctype.h>
10#include "lookup.h"
11
12int __lookup_ipliteral(struct address buf[static 1], const char *name, int family)
13{
14 struct in_addr a4;
15 struct in6_addr a6;
16 if (__inet_aton(name, &a4) > 0) {
17 if (family == AF_INET6) /* wrong family */
18 return EAI_NONAME;
19 memcpy(&buf[0].addr, &a4, sizeof a4);
20 buf[0].family = AF_INET;
21 buf[0].scopeid = 0;
22 return 1;
23 }
24
25 char tmp[64];
26 char *p = strchr(name, '%'), *z;
27 unsigned long long scopeid = 0;
28 if (p && p-name < 64) {
29 memcpy(tmp, name, p-name);
30 tmp[p-name] = 0;
31 name = tmp;
32 }
33
34 if (inet_pton(AF_INET6, name, &a6) <= 0)
35 return 0;
36 if (family == AF_INET) /* wrong family */
37 return EAI_NONAME;
38
39 memcpy(&buf[0].addr, &a6, sizeof a6);
40 buf[0].family = AF_INET6;
41 if (p) {
42 if (isdigit(*++p)) scopeid = strtoull(p, &z, 10);
43 else z = p-1;
44 if (*z) {
45 if (!IN6_IS_ADDR_LINKLOCAL(&a6) &&
46 !IN6_IS_ADDR_MC_LINKLOCAL(&a6))
47 return EAI_NONAME;
48 scopeid = if_nametoindex(p);
49 if (!scopeid) return EAI_NONAME;
50 }
51 if (scopeid > UINT_MAX) return EAI_NONAME;
52 }
53 buf[0].scopeid = scopeid;
54 return 1;
55}
lib/libc/wasi/libc-top-half/musl/src/network/lookup_name.c deleted-425
......@@ -1,425 +0,0 @@
1#include <sys/socket.h>
2#include <netinet/in.h>
3#include <netdb.h>
4#include <net/if.h>
5#include <arpa/inet.h>
6#include <ctype.h>
7#include <stdlib.h>
8#include <string.h>
9#include <fcntl.h>
10#include <unistd.h>
11#include <pthread.h>
12#include <errno.h>
13#include <resolv.h>
14#include "lookup.h"
15#include "stdio_impl.h"
16#include "syscall.h"
17
18static int is_valid_hostname(const char *host)
19{
20 const unsigned char *s;
21 if (strnlen(host, 255)-1 >= 254 || mbstowcs(0, host, 0) == -1) return 0;
22 for (s=(void *)host; *s>=0x80 || *s=='.' || *s=='-' || isalnum(*s); s++);
23 return !*s;
24}
25
26static int name_from_null(struct address buf[static 2], const char *name, int family, int flags)
27{
28 int cnt = 0;
29 if (name) return 0;
30 if (flags & AI_PASSIVE) {
31 if (family != AF_INET6)
32 buf[cnt++] = (struct address){ .family = AF_INET };
33 if (family != AF_INET)
34 buf[cnt++] = (struct address){ .family = AF_INET6 };
35 } else {
36 if (family != AF_INET6)
37 buf[cnt++] = (struct address){ .family = AF_INET, .addr = { 127,0,0,1 } };
38 if (family != AF_INET)
39 buf[cnt++] = (struct address){ .family = AF_INET6, .addr = { [15] = 1 } };
40 }
41 return cnt;
42}
43
44static int name_from_numeric(struct address buf[static 1], const char *name, int family)
45{
46 return __lookup_ipliteral(buf, name, family);
47}
48
49static int name_from_hosts(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family)
50{
51 char line[512];
52 size_t l = strlen(name);
53 int cnt = 0, badfam = 0, have_canon = 0;
54 unsigned char _buf[1032];
55 FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf);
56 if (!f) switch (errno) {
57 case ENOENT:
58 case ENOTDIR:
59 case EACCES:
60 return 0;
61 default:
62 return EAI_SYSTEM;
63 }
64 while (fgets(line, sizeof line, f) && cnt < MAXADDRS) {
65 char *p, *z;
66
67 if ((p=strchr(line, '#'))) *p++='\n', *p=0;
68 for(p=line+1; (p=strstr(p, name)) &&
69 (!isspace(p[-1]) || !isspace(p[l])); p++);
70 if (!p) continue;
71
72 /* Isolate IP address to parse */
73 for (p=line; *p && !isspace(*p); p++);
74 *p++ = 0;
75 switch (name_from_numeric(buf+cnt, line, family)) {
76 case 1:
77 cnt++;
78 break;
79 case 0:
80 continue;
81 default:
82 badfam = EAI_NONAME;
83 break;
84 }
85
86 if (have_canon) continue;
87
88 /* Extract first name as canonical name */
89 for (; *p && isspace(*p); p++);
90 for (z=p; *z && !isspace(*z); z++);
91 *z = 0;
92 if (is_valid_hostname(p)) {
93 have_canon = 1;
94 memcpy(canon, p, z-p+1);
95 }
96 }
97 __fclose_ca(f);
98 return cnt ? cnt : badfam;
99}
100
101struct dpc_ctx {
102 struct address *addrs;
103 char *canon;
104 int cnt;
105};
106
107#define RR_A 1
108#define RR_CNAME 5
109#define RR_AAAA 28
110
111static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet)
112{
113 char tmp[256];
114 struct dpc_ctx *ctx = c;
115 if (ctx->cnt >= MAXADDRS) return -1;
116 switch (rr) {
117 case RR_A:
118 if (len != 4) return -1;
119 ctx->addrs[ctx->cnt].family = AF_INET;
120 ctx->addrs[ctx->cnt].scopeid = 0;
121 memcpy(ctx->addrs[ctx->cnt++].addr, data, 4);
122 break;
123 case RR_AAAA:
124 if (len != 16) return -1;
125 ctx->addrs[ctx->cnt].family = AF_INET6;
126 ctx->addrs[ctx->cnt].scopeid = 0;
127 memcpy(ctx->addrs[ctx->cnt++].addr, data, 16);
128 break;
129 case RR_CNAME:
130 if (__dn_expand(packet, (const unsigned char *)packet + 512,
131 data, tmp, sizeof tmp) > 0 && is_valid_hostname(tmp))
132 strcpy(ctx->canon, tmp);
133 break;
134 }
135 return 0;
136}
137
138static int name_from_dns(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, const struct resolvconf *conf)
139{
140 unsigned char qbuf[2][280], abuf[2][512];
141 const unsigned char *qp[2] = { qbuf[0], qbuf[1] };
142 unsigned char *ap[2] = { abuf[0], abuf[1] };
143 int qlens[2], alens[2];
144 int i, nq = 0;
145 struct dpc_ctx ctx = { .addrs = buf, .canon = canon };
146 static const struct { int af; int rr; } afrr[2] = {
147 { .af = AF_INET6, .rr = RR_A },
148 { .af = AF_INET, .rr = RR_AAAA },
149 };
150
151 for (i=0; i<2; i++) {
152 if (family != afrr[i].af) {
153 qlens[nq] = __res_mkquery(0, name, 1, afrr[i].rr,
154 0, 0, 0, qbuf[nq], sizeof *qbuf);
155 if (qlens[nq] == -1)
156 return EAI_NONAME;
157 qbuf[nq][3] = 0; /* don't need AD flag */
158 nq++;
159 }
160 }
161
162 if (__res_msend_rc(nq, qp, qlens, ap, alens, sizeof *abuf, conf) < 0)
163 return EAI_SYSTEM;
164
165 for (i=0; i<nq; i++) {
166 if (alens[i] < 4 || (abuf[i][3] & 15) == 2) return EAI_AGAIN;
167 if ((abuf[i][3] & 15) == 3) return 0;
168 if ((abuf[i][3] & 15) != 0) return EAI_FAIL;
169 }
170
171 for (i=0; i<nq; i++)
172 __dns_parse(abuf[i], alens[i], dns_parse_callback, &ctx);
173
174 if (ctx.cnt) return ctx.cnt;
175 return EAI_NONAME;
176}
177
178static int name_from_dns_search(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family)
179{
180 char search[256];
181 struct resolvconf conf;
182 size_t l, dots;
183 char *p, *z;
184
185 if (__get_resolv_conf(&conf, search, sizeof search) < 0) return -1;
186
187 /* Count dots, suppress search when >=ndots or name ends in
188 * a dot, which is an explicit request for global scope. */
189 for (dots=l=0; name[l]; l++) if (name[l]=='.') dots++;
190 if (dots >= conf.ndots || name[l-1]=='.') *search = 0;
191
192 /* Strip final dot for canon, fail if multiple trailing dots. */
193 if (name[l-1]=='.') l--;
194 if (!l || name[l-1]=='.') return EAI_NONAME;
195
196 /* This can never happen; the caller already checked length. */
197 if (l >= 256) return EAI_NONAME;
198
199 /* Name with search domain appended is setup in canon[]. This both
200 * provides the desired default canonical name (if the requested
201 * name is not a CNAME record) and serves as a buffer for passing
202 * the full requested name to name_from_dns. */
203 memcpy(canon, name, l);
204 canon[l] = '.';
205
206 for (p=search; *p; p=z) {
207 for (; isspace(*p); p++);
208 for (z=p; *z && !isspace(*z); z++);
209 if (z==p) break;
210 if (z-p < 256 - l - 1) {
211 memcpy(canon+l+1, p, z-p);
212 canon[z-p+1+l] = 0;
213 int cnt = name_from_dns(buf, canon, canon, family, &conf);
214 if (cnt) return cnt;
215 }
216 }
217
218 canon[l] = 0;
219 return name_from_dns(buf, canon, name, family, &conf);
220}
221
222static const struct policy {
223 unsigned char addr[16];
224 unsigned char len, mask;
225 unsigned char prec, label;
226} defpolicy[] = {
227 { "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1", 15, 0xff, 50, 0 },
228 { "\0\0\0\0\0\0\0\0\0\0\xff\xff", 11, 0xff, 35, 4 },
229 { "\x20\2", 1, 0xff, 30, 2 },
230 { "\x20\1", 3, 0xff, 5, 5 },
231 { "\xfc", 0, 0xfe, 3, 13 },
232#if 0
233 /* These are deprecated and/or returned to the address
234 * pool, so despite the RFC, treating them as special
235 * is probably wrong. */
236 { "", 11, 0xff, 1, 3 },
237 { "\xfe\xc0", 1, 0xc0, 1, 11 },
238 { "\x3f\xfe", 1, 0xff, 1, 12 },
239#endif
240 /* Last rule must match all addresses to stop loop. */
241 { "", 0, 0, 40, 1 },
242};
243
244static const struct policy *policyof(const struct in6_addr *a)
245{
246 int i;
247 for (i=0; ; i++) {
248 if (memcmp(a->s6_addr, defpolicy[i].addr, defpolicy[i].len))
249 continue;
250 if ((a->s6_addr[defpolicy[i].len] & defpolicy[i].mask)
251 != defpolicy[i].addr[defpolicy[i].len])
252 continue;
253 return defpolicy+i;
254 }
255}
256
257static int labelof(const struct in6_addr *a)
258{
259 return policyof(a)->label;
260}
261
262static int scopeof(const struct in6_addr *a)
263{
264 if (IN6_IS_ADDR_MULTICAST(a)) return a->s6_addr[1] & 15;
265 if (IN6_IS_ADDR_LINKLOCAL(a)) return 2;
266 if (IN6_IS_ADDR_LOOPBACK(a)) return 2;
267 if (IN6_IS_ADDR_SITELOCAL(a)) return 5;
268 return 14;
269}
270
271static int prefixmatch(const struct in6_addr *s, const struct in6_addr *d)
272{
273 /* FIXME: The common prefix length should be limited to no greater
274 * than the nominal length of the prefix portion of the source
275 * address. However the definition of the source prefix length is
276 * not clear and thus this limiting is not yet implemented. */
277 unsigned i;
278 for (i=0; i<128 && !((s->s6_addr[i/8]^d->s6_addr[i/8])&(128>>(i%8))); i++);
279 return i;
280}
281
282#define DAS_USABLE 0x40000000
283#define DAS_MATCHINGSCOPE 0x20000000
284#define DAS_MATCHINGLABEL 0x10000000
285#define DAS_PREC_SHIFT 20
286#define DAS_SCOPE_SHIFT 16
287#define DAS_PREFIX_SHIFT 8
288#define DAS_ORDER_SHIFT 0
289
290static int addrcmp(const void *_a, const void *_b)
291{
292 const struct address *a = _a, *b = _b;
293 return b->sortkey - a->sortkey;
294}
295
296int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags)
297{
298 int cnt = 0, i, j;
299
300 *canon = 0;
301 if (name) {
302 /* reject empty name and check len so it fits into temp bufs */
303 size_t l = strnlen(name, 255);
304 if (l-1 >= 254)
305 return EAI_NONAME;
306 memcpy(canon, name, l+1);
307 }
308
309 /* Procedurally, a request for v6 addresses with the v4-mapped
310 * flag set is like a request for unspecified family, followed
311 * by filtering of the results. */
312 if (flags & AI_V4MAPPED) {
313 if (family == AF_INET6) family = AF_UNSPEC;
314 else flags -= AI_V4MAPPED;
315 }
316
317 /* Try each backend until there's at least one result. */
318 cnt = name_from_null(buf, name, family, flags);
319 if (!cnt) cnt = name_from_numeric(buf, name, family);
320 if (!cnt && !(flags & AI_NUMERICHOST)) {
321 cnt = name_from_hosts(buf, canon, name, family);
322 if (!cnt) cnt = name_from_dns_search(buf, canon, name, family);
323 }
324 if (cnt<=0) return cnt ? cnt : EAI_NONAME;
325
326 /* Filter/transform results for v4-mapped lookup, if requested. */
327 if (flags & AI_V4MAPPED) {
328 if (!(flags & AI_ALL)) {
329 /* If any v6 results exist, remove v4 results. */
330 for (i=0; i<cnt && buf[i].family != AF_INET6; i++);
331 if (i<cnt) {
332 for (j=0; i<cnt; i++) {
333 if (buf[i].family == AF_INET6)
334 buf[j++] = buf[i];
335 }
336 cnt = i = j;
337 }
338 }
339 /* Translate any remaining v4 results to v6 */
340 for (i=0; i<cnt; i++) {
341 if (buf[i].family != AF_INET) continue;
342 memcpy(buf[i].addr+12, buf[i].addr, 4);
343 memcpy(buf[i].addr, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
344 buf[i].family = AF_INET6;
345 }
346 }
347
348 /* No further processing is needed if there are fewer than 2
349 * results or if there are only IPv4 results. */
350 if (cnt<2 || family==AF_INET) return cnt;
351 for (i=0; i<cnt; i++) if (buf[i].family != AF_INET) break;
352 if (i==cnt) return cnt;
353
354 int cs;
355 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
356
357 /* The following implements a subset of RFC 3484/6724 destination
358 * address selection by generating a single 31-bit sort key for
359 * each address. Rules 3, 4, and 7 are omitted for having
360 * excessive runtime and code size cost and dubious benefit.
361 * So far the label/precedence table cannot be customized. */
362 for (i=0; i<cnt; i++) {
363 int family = buf[i].family;
364 int key = 0;
365 struct sockaddr_in6 sa6 = { 0 }, da6 = {
366 .sin6_family = AF_INET6,
367 .sin6_scope_id = buf[i].scopeid,
368 .sin6_port = 65535
369 };
370 struct sockaddr_in sa4 = { 0 }, da4 = {
371 .sin_family = AF_INET,
372 .sin_port = 65535
373 };
374 void *sa, *da;
375 socklen_t salen, dalen;
376 if (family == AF_INET6) {
377 memcpy(da6.sin6_addr.s6_addr, buf[i].addr, 16);
378 da = &da6; dalen = sizeof da6;
379 sa = &sa6; salen = sizeof sa6;
380 } else {
381 memcpy(sa6.sin6_addr.s6_addr,
382 "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
383 memcpy(da6.sin6_addr.s6_addr+12, buf[i].addr, 4);
384 memcpy(da6.sin6_addr.s6_addr,
385 "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
386 memcpy(da6.sin6_addr.s6_addr+12, buf[i].addr, 4);
387 memcpy(&da4.sin_addr, buf[i].addr, 4);
388 da = &da4; dalen = sizeof da4;
389 sa = &sa4; salen = sizeof sa4;
390 }
391 const struct policy *dpolicy = policyof(&da6.sin6_addr);
392 int dscope = scopeof(&da6.sin6_addr);
393 int dlabel = dpolicy->label;
394 int dprec = dpolicy->prec;
395 int prefixlen = 0;
396 int fd = socket(family, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_UDP);
397 if (fd >= 0) {
398 if (!connect(fd, da, dalen)) {
399 key |= DAS_USABLE;
400 if (!getsockname(fd, sa, &salen)) {
401 if (family == AF_INET) memcpy(
402 sa6.sin6_addr.s6_addr+12,
403 &sa4.sin_addr, 4);
404 if (dscope == scopeof(&sa6.sin6_addr))
405 key |= DAS_MATCHINGSCOPE;
406 if (dlabel == labelof(&sa6.sin6_addr))
407 key |= DAS_MATCHINGLABEL;
408 prefixlen = prefixmatch(&sa6.sin6_addr,
409 &da6.sin6_addr);
410 }
411 }
412 close(fd);
413 }
414 key |= dprec << DAS_PREC_SHIFT;
415 key |= (15-dscope) << DAS_SCOPE_SHIFT;
416 key |= prefixlen << DAS_PREFIX_SHIFT;
417 key |= (MAXADDRS-i) << DAS_ORDER_SHIFT;
418 buf[i].sortkey = key;
419 }
420 qsort(buf, cnt, sizeof *buf, addrcmp);
421
422 pthread_setcancelstate(cs, 0);
423
424 return cnt;
425}
lib/libc/wasi/libc-top-half/musl/src/network/lookup_serv.c deleted-114
......@@ -1,114 +0,0 @@
1#include <sys/socket.h>
2#include <netinet/in.h>
3#include <netdb.h>
4#include <ctype.h>
5#include <string.h>
6#include <stdlib.h>
7#include <fcntl.h>
8#include <errno.h>
9#include "lookup.h"
10#include "stdio_impl.h"
11
12int __lookup_serv(struct service buf[static MAXSERVS], const char *name, int proto, int socktype, int flags)
13{
14 char line[128];
15 int cnt = 0;
16 char *p, *z = "";
17 unsigned long port = 0;
18
19 switch (socktype) {
20 case SOCK_STREAM:
21 switch (proto) {
22 case 0:
23 proto = IPPROTO_TCP;
24 case IPPROTO_TCP:
25 break;
26 default:
27 return EAI_SERVICE;
28 }
29 break;
30 case SOCK_DGRAM:
31 switch (proto) {
32 case 0:
33 proto = IPPROTO_UDP;
34 case IPPROTO_UDP:
35 break;
36 default:
37 return EAI_SERVICE;
38 }
39 case 0:
40 break;
41 default:
42 if (name) return EAI_SERVICE;
43 buf[0].port = 0;
44 buf[0].proto = proto;
45 buf[0].socktype = socktype;
46 return 1;
47 }
48
49 if (name) {
50 if (!*name) return EAI_SERVICE;
51 port = strtoul(name, &z, 10);
52 }
53 if (!*z) {
54 if (port > 65535) return EAI_SERVICE;
55 if (proto != IPPROTO_UDP) {
56 buf[cnt].port = port;
57 buf[cnt].socktype = SOCK_STREAM;
58 buf[cnt++].proto = IPPROTO_TCP;
59 }
60 if (proto != IPPROTO_TCP) {
61 buf[cnt].port = port;
62 buf[cnt].socktype = SOCK_DGRAM;
63 buf[cnt++].proto = IPPROTO_UDP;
64 }
65 return cnt;
66 }
67
68 if (flags & AI_NUMERICSERV) return EAI_NONAME;
69
70 size_t l = strlen(name);
71
72 unsigned char _buf[1032];
73 FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf);
74 if (!f) switch (errno) {
75 case ENOENT:
76 case ENOTDIR:
77 case EACCES:
78 return EAI_SERVICE;
79 default:
80 return EAI_SYSTEM;
81 }
82
83 while (fgets(line, sizeof line, f) && cnt < MAXSERVS) {
84 if ((p=strchr(line, '#'))) *p++='\n', *p=0;
85
86 /* Find service name */
87 for(p=line; (p=strstr(p, name)); p++) {
88 if (p>line && !isspace(p[-1])) continue;
89 if (p[l] && !isspace(p[l])) continue;
90 break;
91 }
92 if (!p) continue;
93
94 /* Skip past canonical name at beginning of line */
95 for (p=line; *p && !isspace(*p); p++);
96
97 port = strtoul(p, &z, 10);
98 if (port > 65535 || z==p) continue;
99 if (!strncmp(z, "/udp", 4)) {
100 if (proto == IPPROTO_TCP) continue;
101 buf[cnt].port = port;
102 buf[cnt].socktype = SOCK_DGRAM;
103 buf[cnt++].proto = IPPROTO_UDP;
104 }
105 if (!strncmp(z, "/tcp", 4)) {
106 if (proto == IPPROTO_UDP) continue;
107 buf[cnt].port = port;
108 buf[cnt].socktype = SOCK_STREAM;
109 buf[cnt++].proto = IPPROTO_TCP;
110 }
111 }
112 __fclose_ca(f);
113 return cnt > 0 ? cnt : EAI_SERVICE;
114}
lib/libc/wasi/libc-top-half/musl/src/network/netlink.c deleted-52
......@@ -1,52 +0,0 @@
1#include <errno.h>
2#include <string.h>
3#include <syscall.h>
4#include <sys/socket.h>
5#include "netlink.h"
6
7static int __netlink_enumerate(int fd, unsigned int seq, int type, int af,
8 int (*cb)(void *ctx, struct nlmsghdr *h), void *ctx)
9{
10 struct nlmsghdr *h;
11 union {
12 uint8_t buf[8192];
13 struct {
14 struct nlmsghdr nlh;
15 struct rtgenmsg g;
16 } req;
17 struct nlmsghdr reply;
18 } u;
19 int r, ret;
20
21 memset(&u.req, 0, sizeof(u.req));
22 u.req.nlh.nlmsg_len = sizeof(u.req);
23 u.req.nlh.nlmsg_type = type;
24 u.req.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST;
25 u.req.nlh.nlmsg_seq = seq;
26 u.req.g.rtgen_family = af;
27 r = send(fd, &u.req, sizeof(u.req), 0);
28 if (r < 0) return r;
29
30 while (1) {
31 r = recv(fd, u.buf, sizeof(u.buf), MSG_DONTWAIT);
32 if (r <= 0) return -1;
33 for (h = &u.reply; NLMSG_OK(h, (void*)&u.buf[r]); h = NLMSG_NEXT(h)) {
34 if (h->nlmsg_type == NLMSG_DONE) return 0;
35 if (h->nlmsg_type == NLMSG_ERROR) return -1;
36 ret = cb(ctx, h);
37 if (ret) return ret;
38 }
39 }
40}
41
42int __rtnetlink_enumerate(int link_af, int addr_af, int (*cb)(void *ctx, struct nlmsghdr *h), void *ctx)
43{
44 int fd, r;
45
46 fd = socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, NETLINK_ROUTE);
47 if (fd < 0) return -1;
48 r = __netlink_enumerate(fd, 1, RTM_GETLINK, link_af, cb, ctx);
49 if (!r) r = __netlink_enumerate(fd, 2, RTM_GETADDR, addr_af, cb, ctx);
50 __syscall(SYS_close,fd);
51 return r;
52}
lib/libc/wasi/libc-top-half/musl/src/network/netname.c deleted-12
......@@ -1,12 +0,0 @@
1#include <netdb.h>
2
3struct netent *getnetbyaddr(uint32_t net, int type)
4{
5 return 0;
6}
7
8struct netent *getnetbyname(const char *name)
9{
10 return 0;
11}
12
lib/libc/wasi/libc-top-half/musl/src/network/ns_parse.c deleted-171
......@@ -1,171 +0,0 @@
1#define _BSD_SOURCE
2#include <errno.h>
3#include <stddef.h>
4#include <resolv.h>
5#include <arpa/nameser.h>
6
7const struct _ns_flagdata _ns_flagdata[16] = {
8 { 0x8000, 15 },
9 { 0x7800, 11 },
10 { 0x0400, 10 },
11 { 0x0200, 9 },
12 { 0x0100, 8 },
13 { 0x0080, 7 },
14 { 0x0040, 6 },
15 { 0x0020, 5 },
16 { 0x0010, 4 },
17 { 0x000f, 0 },
18 { 0x0000, 0 },
19 { 0x0000, 0 },
20 { 0x0000, 0 },
21 { 0x0000, 0 },
22 { 0x0000, 0 },
23 { 0x0000, 0 },
24};
25
26unsigned ns_get16(const unsigned char *cp)
27{
28 return cp[0]<<8 | cp[1];
29}
30
31unsigned long ns_get32(const unsigned char *cp)
32{
33 return (unsigned)cp[0]<<24 | cp[1]<<16 | cp[2]<<8 | cp[3];
34}
35
36void ns_put16(unsigned s, unsigned char *cp)
37{
38 *cp++ = s>>8;
39 *cp++ = s;
40}
41
42void ns_put32(unsigned long l, unsigned char *cp)
43{
44 *cp++ = l>>24;
45 *cp++ = l>>16;
46 *cp++ = l>>8;
47 *cp++ = l;
48}
49
50int ns_initparse(const unsigned char *msg, int msglen, ns_msg *handle)
51{
52 int i, r;
53
54 handle->_msg = msg;
55 handle->_eom = msg + msglen;
56 if (msglen < (2 + ns_s_max) * NS_INT16SZ) goto bad;
57 NS_GET16(handle->_id, msg);
58 NS_GET16(handle->_flags, msg);
59 for (i = 0; i < ns_s_max; i++) NS_GET16(handle->_counts[i], msg);
60 for (i = 0; i < ns_s_max; i++) {
61 if (handle->_counts[i]) {
62 handle->_sections[i] = msg;
63 r = ns_skiprr(msg, handle->_eom, i, handle->_counts[i]);
64 if (r < 0) return -1;
65 msg += r;
66 } else {
67 handle->_sections[i] = NULL;
68 }
69 }
70 if (msg != handle->_eom) goto bad;
71 handle->_sect = ns_s_max;
72 handle->_rrnum = -1;
73 handle->_msg_ptr = NULL;
74 return 0;
75bad:
76 errno = EMSGSIZE;
77 return -1;
78}
79
80int ns_skiprr(const unsigned char *ptr, const unsigned char *eom, ns_sect section, int count)
81{
82 const unsigned char *p = ptr;
83 int r;
84
85 while (count--) {
86 r = dn_skipname(p, eom);
87 if (r < 0) goto bad;
88 if (r + 2 * NS_INT16SZ > eom - p) goto bad;
89 p += r + 2 * NS_INT16SZ;
90 if (section != ns_s_qd) {
91 if (NS_INT32SZ + NS_INT16SZ > eom - p) goto bad;
92 p += NS_INT32SZ;
93 NS_GET16(r, p);
94 if (r > eom - p) goto bad;
95 p += r;
96 }
97 }
98 return p - ptr;
99bad:
100 errno = EMSGSIZE;
101 return -1;
102}
103
104int ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr)
105{
106 int r;
107
108 if (section < 0 || section >= ns_s_max) goto bad;
109 if (section != handle->_sect) {
110 handle->_sect = section;
111 handle->_rrnum = 0;
112 handle->_msg_ptr = handle->_sections[section];
113 }
114 if (rrnum == -1) rrnum = handle->_rrnum;
115 if (rrnum < 0 || rrnum >= handle->_counts[section]) goto bad;
116 if (rrnum < handle->_rrnum) {
117 handle->_rrnum = 0;
118 handle->_msg_ptr = handle->_sections[section];
119 }
120 if (rrnum > handle->_rrnum) {
121 r = ns_skiprr(handle->_msg_ptr, handle->_eom, section, rrnum - handle->_rrnum);
122 if (r < 0) return -1;
123 handle->_msg_ptr += r;
124 handle->_rrnum = rrnum;
125 }
126 r = ns_name_uncompress(handle->_msg, handle->_eom, handle->_msg_ptr, rr->name, NS_MAXDNAME);
127 if (r < 0) return -1;
128 handle->_msg_ptr += r;
129 if (2 * NS_INT16SZ > handle->_eom - handle->_msg_ptr) goto size;
130 NS_GET16(rr->type, handle->_msg_ptr);
131 NS_GET16(rr->rr_class, handle->_msg_ptr);
132 if (section != ns_s_qd) {
133 if (NS_INT32SZ + NS_INT16SZ > handle->_eom - handle->_msg_ptr) goto size;
134 NS_GET32(rr->ttl, handle->_msg_ptr);
135 NS_GET16(rr->rdlength, handle->_msg_ptr);
136 if (rr->rdlength > handle->_eom - handle->_msg_ptr) goto size;
137 rr->rdata = handle->_msg_ptr;
138 handle->_msg_ptr += rr->rdlength;
139 } else {
140 rr->ttl = 0;
141 rr->rdlength = 0;
142 rr->rdata = NULL;
143 }
144 handle->_rrnum++;
145 if (handle->_rrnum > handle->_counts[section]) {
146 handle->_sect = section + 1;
147 if (handle->_sect == ns_s_max) {
148 handle->_rrnum = -1;
149 handle->_msg_ptr = NULL;
150 } else {
151 handle->_rrnum = 0;
152 }
153 }
154 return 0;
155bad:
156 errno = ENODEV;
157 return -1;
158size:
159 errno = EMSGSIZE;
160 return -1;
161}
162
163int ns_name_uncompress(const unsigned char *msg, const unsigned char *eom,
164 const unsigned char *src, char *dst, size_t dstsiz)
165{
166 int r;
167 r = dn_expand(msg, eom, src, dst, dstsiz);
168 if (r < 0) errno = EMSGSIZE;
169 return r;
170}
171
lib/libc/wasi/libc-top-half/musl/src/network/proto.c deleted-84
......@@ -1,84 +0,0 @@
1#include <netdb.h>
2#include <string.h>
3
4/* do we really need all these?? */
5
6static int idx;
7static const unsigned char protos[] = {
8 "\000ip\0"
9 "\001icmp\0"
10 "\002igmp\0"
11 "\003ggp\0"
12 "\004ipencap\0"
13 "\005st\0"
14 "\006tcp\0"
15 "\010egp\0"
16 "\014pup\0"
17 "\021udp\0"
18 "\024hmp\0"
19 "\026xns-idp\0"
20 "\033rdp\0"
21 "\035iso-tp4\0"
22 "\044xtp\0"
23 "\045ddp\0"
24 "\046idpr-cmtp\0"
25 "\051ipv6\0"
26 "\053ipv6-route\0"
27 "\054ipv6-frag\0"
28 "\055idrp\0"
29 "\056rsvp\0"
30 "\057gre\0"
31 "\062esp\0"
32 "\063ah\0"
33 "\071skip\0"
34 "\072ipv6-icmp\0"
35 "\073ipv6-nonxt\0"
36 "\074ipv6-opts\0"
37 "\111rspf\0"
38 "\121vmtp\0"
39 "\131ospf\0"
40 "\136ipip\0"
41 "\142encap\0"
42 "\147pim\0"
43 "\377raw"
44};
45
46void endprotoent(void)
47{
48 idx = 0;
49}
50
51void setprotoent(int stayopen)
52{
53 idx = 0;
54}
55
56struct protoent *getprotoent(void)
57{
58 static struct protoent p;
59 static const char *aliases;
60 if (idx >= sizeof protos) return NULL;
61 p.p_proto = protos[idx];
62 p.p_name = (char *)&protos[idx+1];
63 p.p_aliases = (char **)&aliases;
64 idx += strlen(p.p_name) + 2;
65 return &p;
66}
67
68struct protoent *getprotobyname(const char *name)
69{
70 struct protoent *p;
71 endprotoent();
72 do p = getprotoent();
73 while (p && strcmp(name, p->p_name));
74 return p;
75}
76
77struct protoent *getprotobynumber(int num)
78{
79 struct protoent *p;
80 endprotoent();
81 do p = getprotoent();
82 while (p && p->p_proto != num);
83 return p;
84}
lib/libc/wasi/libc-top-half/musl/src/network/recv.c deleted-6
......@@ -1,6 +0,0 @@
1#include <sys/socket.h>
2
3ssize_t recv(int fd, void *buf, size_t len, int flags)
4{
5 return recvfrom(fd, buf, len, flags, 0, 0);
6}
lib/libc/wasi/libc-top-half/musl/src/network/recvfrom.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/socket.h>
2#include "syscall.h"
3
4ssize_t recvfrom(int fd, void *restrict buf, size_t len, int flags, struct sockaddr *restrict addr, socklen_t *restrict alen)
5{
6 return socketcall_cp(recvfrom, fd, buf, len, flags, addr, alen);
7}
lib/libc/wasi/libc-top-half/musl/src/network/recvmmsg.c deleted-39
......@@ -1,39 +0,0 @@
1#define _GNU_SOURCE
2#include <sys/socket.h>
3#include <limits.h>
4#include <errno.h>
5#include <time.h>
6#include "syscall.h"
7
8#define IS32BIT(x) !((x)+0x80000000ULL>>32)
9#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
10
11hidden void __convert_scm_timestamps(struct msghdr *, socklen_t);
12
13int recvmmsg(int fd, struct mmsghdr *msgvec, unsigned int vlen, unsigned int flags, struct timespec *timeout)
14{
15#if LONG_MAX > INT_MAX
16 struct mmsghdr *mh = msgvec;
17 unsigned int i;
18 for (i = vlen; i; i--, mh++)
19 mh->msg_hdr.__pad1 = mh->msg_hdr.__pad2 = 0;
20#endif
21#ifdef SYS_recvmmsg_time64
22 time_t s = timeout ? timeout->tv_sec : 0;
23 long ns = timeout ? timeout->tv_nsec : 0;
24 int r = __syscall_cp(SYS_recvmmsg_time64, fd, msgvec, vlen, flags,
25 timeout ? ((long long[]){s, ns}) : 0);
26 if (SYS_recvmmsg == SYS_recvmmsg_time64 || r!=-ENOSYS)
27 return __syscall_ret(r);
28 if (vlen > IOV_MAX) vlen = IOV_MAX;
29 socklen_t csize[vlen];
30 for (int i=0; i<vlen; i++) csize[i] = msgvec[i].msg_hdr.msg_controllen;
31 r = __syscall_cp(SYS_recvmmsg, fd, msgvec, vlen, flags,
32 timeout ? ((long[]){CLAMP(s), ns}) : 0);
33 for (int i=0; i<r; i++)
34 __convert_scm_timestamps(&msgvec[i].msg_hdr, csize[i]);
35 return __syscall_ret(r);
36#else
37 return syscall_cp(SYS_recvmmsg, fd, msgvec, vlen, flags, timeout);
38#endif
39}
lib/libc/wasi/libc-top-half/musl/src/network/recvmsg.c deleted-68
......@@ -1,68 +0,0 @@
1#include <sys/socket.h>
2#include <limits.h>
3#include <time.h>
4#include <sys/time.h>
5#include <string.h>
6#include "syscall.h"
7
8hidden void __convert_scm_timestamps(struct msghdr *, socklen_t);
9
10void __convert_scm_timestamps(struct msghdr *msg, socklen_t csize)
11{
12 if (SCM_TIMESTAMP == SCM_TIMESTAMP_OLD) return;
13 if (!msg->msg_control || !msg->msg_controllen) return;
14
15 struct cmsghdr *cmsg, *last=0;
16 long tmp;
17 long long tvts[2];
18 int type = 0;
19
20 for (cmsg=CMSG_FIRSTHDR(msg); cmsg; cmsg=CMSG_NXTHDR(msg, cmsg)) {
21 if (cmsg->cmsg_level==SOL_SOCKET) switch (cmsg->cmsg_type) {
22 case SCM_TIMESTAMP_OLD:
23 if (type) break;
24 type = SCM_TIMESTAMP;
25 goto common;
26 case SCM_TIMESTAMPNS_OLD:
27 type = SCM_TIMESTAMPNS;
28 common:
29 memcpy(&tmp, CMSG_DATA(cmsg), sizeof tmp);
30 tvts[0] = tmp;
31 memcpy(&tmp, CMSG_DATA(cmsg) + sizeof tmp, sizeof tmp);
32 tvts[1] = tmp;
33 break;
34 }
35 last = cmsg;
36 }
37 if (!last || !type) return;
38 if (CMSG_SPACE(sizeof tvts) > csize-msg->msg_controllen) {
39 msg->msg_flags |= MSG_CTRUNC;
40 return;
41 }
42 msg->msg_controllen += CMSG_SPACE(sizeof tvts);
43 cmsg = CMSG_NXTHDR(msg, last);
44 cmsg->cmsg_level = SOL_SOCKET;
45 cmsg->cmsg_type = type;
46 cmsg->cmsg_len = CMSG_LEN(sizeof tvts);
47 memcpy(CMSG_DATA(cmsg), &tvts, sizeof tvts);
48}
49
50ssize_t recvmsg(int fd, struct msghdr *msg, int flags)
51{
52 ssize_t r;
53 socklen_t orig_controllen = msg->msg_controllen;
54#if LONG_MAX > INT_MAX
55 struct msghdr h, *orig = msg;
56 if (msg) {
57 h = *msg;
58 h.__pad1 = h.__pad2 = 0;
59 msg = &h;
60 }
61#endif
62 r = socketcall_cp(recvmsg, fd, msg, flags, 0, 0, 0);
63 if (r >= 0) __convert_scm_timestamps(msg, orig_controllen);
64#if LONG_MAX > INT_MAX
65 if (orig) *orig = h;
66#endif
67 return r;
68}
lib/libc/wasi/libc-top-half/musl/src/network/res_init.c deleted-6
......@@ -1,6 +0,0 @@
1#include <resolv.h>
2
3int res_init()
4{
5 return 0;
6}
lib/libc/wasi/libc-top-half/musl/src/network/res_mkquery.c deleted-44
......@@ -1,44 +0,0 @@
1#include <resolv.h>
2#include <string.h>
3#include <time.h>
4
5int __res_mkquery(int op, const char *dname, int class, int type,
6 const unsigned char *data, int datalen,
7 const unsigned char *newrr, unsigned char *buf, int buflen)
8{
9 int id, i, j;
10 unsigned char q[280];
11 struct timespec ts;
12 size_t l = strnlen(dname, 255);
13 int n;
14
15 if (l && dname[l-1]=='.') l--;
16 n = 17+l+!!l;
17 if (l>253 || buflen<n || op>15u || class>255u || type>255u)
18 return -1;
19
20 /* Construct query template - ID will be filled later */
21 memset(q, 0, n);
22 q[2] = op*8 + 1;
23 q[3] = 32; /* AD */
24 q[5] = 1;
25 memcpy((char *)q+13, dname, l);
26 for (i=13; q[i]; i=j+1) {
27 for (j=i; q[j] && q[j] != '.'; j++);
28 if (j-i-1u > 62u) return -1;
29 q[i-1] = j-i;
30 }
31 q[i+1] = type;
32 q[i+3] = class;
33
34 /* Make a reasonably unpredictable id */
35 clock_gettime(CLOCK_REALTIME, &ts);
36 id = ts.tv_nsec + ts.tv_nsec/65536UL & 0xffff;
37 q[0] = id/256;
38 q[1] = id;
39
40 memcpy(buf, q, n);
41 return n;
42}
43
44weak_alias(__res_mkquery, res_mkquery);
lib/libc/wasi/libc-top-half/musl/src/network/res_msend.c deleted-188
......@@ -1,188 +0,0 @@
1#include <sys/socket.h>
2#include <netinet/in.h>
3#include <netdb.h>
4#include <arpa/inet.h>
5#include <stdint.h>
6#include <string.h>
7#include <poll.h>
8#include <time.h>
9#include <ctype.h>
10#include <unistd.h>
11#include <errno.h>
12#include <pthread.h>
13#include "stdio_impl.h"
14#include "syscall.h"
15#include "lookup.h"
16
17static void cleanup(void *p)
18{
19 __syscall(SYS_close, (intptr_t)p);
20}
21
22static unsigned long mtime()
23{
24 struct timespec ts;
25 clock_gettime(CLOCK_REALTIME, &ts);
26 return (unsigned long)ts.tv_sec * 1000
27 + ts.tv_nsec / 1000000;
28}
29
30int __res_msend_rc(int nqueries, const unsigned char *const *queries,
31 const int *qlens, unsigned char *const *answers, int *alens, int asize,
32 const struct resolvconf *conf)
33{
34 int fd;
35 int timeout, attempts, retry_interval, servfail_retry;
36 union {
37 struct sockaddr_in sin;
38 struct sockaddr_in6 sin6;
39 } sa = {0}, ns[MAXNS] = {{0}};
40 socklen_t sl = sizeof sa.sin;
41 int nns = 0;
42 int family = AF_INET;
43 int rlen;
44 int next;
45 int i, j;
46 int cs;
47 struct pollfd pfd;
48 unsigned long t0, t1, t2;
49
50 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
51
52 timeout = 1000*conf->timeout;
53 attempts = conf->attempts;
54
55 for (nns=0; nns<conf->nns; nns++) {
56 const struct address *iplit = &conf->ns[nns];
57 if (iplit->family == AF_INET) {
58 memcpy(&ns[nns].sin.sin_addr, iplit->addr, 4);
59 ns[nns].sin.sin_port = htons(53);
60 ns[nns].sin.sin_family = AF_INET;
61 } else {
62 sl = sizeof sa.sin6;
63 memcpy(&ns[nns].sin6.sin6_addr, iplit->addr, 16);
64 ns[nns].sin6.sin6_port = htons(53);
65 ns[nns].sin6.sin6_scope_id = iplit->scopeid;
66 ns[nns].sin6.sin6_family = family = AF_INET6;
67 }
68 }
69
70 /* Get local address and open/bind a socket */
71 sa.sin.sin_family = family;
72 fd = socket(family, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
73
74 /* Handle case where system lacks IPv6 support */
75 if (fd < 0 && family == AF_INET6 && errno == EAFNOSUPPORT) {
76 fd = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
77 family = AF_INET;
78 }
79 if (fd < 0 || bind(fd, (void *)&sa, sl) < 0) {
80 if (fd >= 0) close(fd);
81 pthread_setcancelstate(cs, 0);
82 return -1;
83 }
84
85 /* Past this point, there are no errors. Each individual query will
86 * yield either no reply (indicated by zero length) or an answer
87 * packet which is up to the caller to interpret. */
88
89 pthread_cleanup_push(cleanup, (void *)(intptr_t)fd);
90 pthread_setcancelstate(cs, 0);
91
92 /* Convert any IPv4 addresses in a mixed environment to v4-mapped */
93 if (family == AF_INET6) {
94 setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &(int){0}, sizeof 0);
95 for (i=0; i<nns; i++) {
96 if (ns[i].sin.sin_family != AF_INET) continue;
97 memcpy(ns[i].sin6.sin6_addr.s6_addr+12,
98 &ns[i].sin.sin_addr, 4);
99 memcpy(ns[i].sin6.sin6_addr.s6_addr,
100 "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
101 ns[i].sin6.sin6_family = AF_INET6;
102 ns[i].sin6.sin6_flowinfo = 0;
103 ns[i].sin6.sin6_scope_id = 0;
104 }
105 }
106
107 memset(alens, 0, sizeof *alens * nqueries);
108
109 pfd.fd = fd;
110 pfd.events = POLLIN;
111 retry_interval = timeout / attempts;
112 next = 0;
113 t0 = t2 = mtime();
114 t1 = t2 - retry_interval;
115
116 for (; t2-t0 < timeout; t2=mtime()) {
117 if (t2-t1 >= retry_interval) {
118 /* Query all configured namservers in parallel */
119 for (i=0; i<nqueries; i++)
120 if (!alens[i])
121 for (j=0; j<nns; j++)
122 sendto(fd, queries[i],
123 qlens[i], MSG_NOSIGNAL,
124 (void *)&ns[j], sl);
125 t1 = t2;
126 servfail_retry = 2 * nqueries;
127 }
128
129 /* Wait for a response, or until time to retry */
130 if (poll(&pfd, 1, t1+retry_interval-t2) <= 0) continue;
131
132 while ((rlen = recvfrom(fd, answers[next], asize, 0,
133 (void *)&sa, (socklen_t[1]){sl})) >= 0) {
134
135 /* Ignore non-identifiable packets */
136 if (rlen < 4) continue;
137
138 /* Ignore replies from addresses we didn't send to */
139 for (j=0; j<nns && memcmp(ns+j, &sa, sl); j++);
140 if (j==nns) continue;
141
142 /* Find which query this answer goes with, if any */
143 for (i=next; i<nqueries && (
144 answers[next][0] != queries[i][0] ||
145 answers[next][1] != queries[i][1] ); i++);
146 if (i==nqueries) continue;
147 if (alens[i]) continue;
148
149 /* Only accept positive or negative responses;
150 * retry immediately on server failure, and ignore
151 * all other codes such as refusal. */
152 switch (answers[next][3] & 15) {
153 case 0:
154 case 3:
155 break;
156 case 2:
157 if (servfail_retry && servfail_retry--)
158 sendto(fd, queries[i],
159 qlens[i], MSG_NOSIGNAL,
160 (void *)&ns[j], sl);
161 default:
162 continue;
163 }
164
165 /* Store answer in the right slot, or update next
166 * available temp slot if it's already in place. */
167 alens[i] = rlen;
168 if (i == next)
169 for (; next<nqueries && alens[next]; next++);
170 else
171 memcpy(answers[i], answers[next], rlen);
172
173 if (next == nqueries) goto out;
174 }
175 }
176out:
177 pthread_cleanup_pop(1);
178
179 return 0;
180}
181
182int __res_msend(int nqueries, const unsigned char *const *queries,
183 const int *qlens, unsigned char *const *answers, int *alens, int asize)
184{
185 struct resolvconf conf;
186 if (__get_resolv_conf(&conf, 0, 0) < 0) return -1;
187 return __res_msend_rc(nqueries, queries, qlens, answers, alens, asize, &conf);
188}
lib/libc/wasi/libc-top-half/musl/src/network/res_query.c deleted-26
......@@ -1,26 +0,0 @@
1#define _BSD_SOURCE
2#include <resolv.h>
3#include <netdb.h>
4
5int res_query(const char *name, int class, int type, unsigned char *dest, int len)
6{
7 unsigned char q[280];
8 int ql = __res_mkquery(0, name, class, type, 0, 0, 0, q, sizeof q);
9 if (ql < 0) return ql;
10 int r = __res_send(q, ql, dest, len);
11 if (r<12) {
12 h_errno = TRY_AGAIN;
13 return -1;
14 }
15 if ((dest[3] & 15) == 3) {
16 h_errno = HOST_NOT_FOUND;
17 return -1;
18 }
19 if ((dest[3] & 15) == 0 && !dest[6] && !dest[7]) {
20 h_errno = NO_DATA;
21 return -1;
22 }
23 return r;
24}
25
26weak_alias(res_query, res_search);
lib/libc/wasi/libc-top-half/musl/src/network/res_querydomain.c deleted-14
......@@ -1,14 +0,0 @@
1#include <resolv.h>
2#include <string.h>
3
4int res_querydomain(const char *name, const char *domain, int class, int type, unsigned char *dest, int len)
5{
6 char tmp[255];
7 size_t nl = strnlen(name, 255);
8 size_t dl = strnlen(domain, 255);
9 if (nl+dl+1 > 254) return -1;
10 memcpy(tmp, name, nl);
11 tmp[nl] = '.';
12 memcpy(tmp+nl+1, domain, dl+1);
13 return res_query(tmp, class, type, dest, len);
14}
lib/libc/wasi/libc-top-half/musl/src/network/res_send.c deleted-9
......@@ -1,9 +0,0 @@
1#include <resolv.h>
2
3int __res_send(const unsigned char *msg, int msglen, unsigned char *answer, int anslen)
4{
5 int r = __res_msend(1, &msg, &msglen, &answer, &anslen, anslen);
6 return r<0 || !anslen ? -1 : anslen;
7}
8
9weak_alias(__res_send, res_send);
lib/libc/wasi/libc-top-half/musl/src/network/res_state.c deleted-9
......@@ -1,9 +0,0 @@
1#include <resolv.h>
2
3/* This is completely unused, and exists purely to satisfy broken apps. */
4
5struct __res_state *__res_state()
6{
7 static struct __res_state res;
8 return &res;
9}
lib/libc/wasi/libc-top-half/musl/src/network/resolvconf.c deleted-94
......@@ -1,94 +0,0 @@
1#include "lookup.h"
2#include "stdio_impl.h"
3#include <ctype.h>
4#include <errno.h>
5#include <string.h>
6#include <stdlib.h>
7#include <netinet/in.h>
8
9int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
10{
11 char line[256];
12 unsigned char _buf[256];
13 FILE *f, _f;
14 int nns = 0;
15
16 conf->ndots = 1;
17 conf->timeout = 5;
18 conf->attempts = 2;
19 if (search) *search = 0;
20
21 f = __fopen_rb_ca("/etc/resolv.conf", &_f, _buf, sizeof _buf);
22 if (!f) switch (errno) {
23 case ENOENT:
24 case ENOTDIR:
25 case EACCES:
26 goto no_resolv_conf;
27 default:
28 return -1;
29 }
30
31 while (fgets(line, sizeof line, f)) {
32 char *p, *z;
33 if (!strchr(line, '\n') && !feof(f)) {
34 /* Ignore lines that get truncated rather than
35 * potentially misinterpreting them. */
36 int c;
37 do c = getc(f);
38 while (c != '\n' && c != EOF);
39 continue;
40 }
41 if (!strncmp(line, "options", 7) && isspace(line[7])) {
42 p = strstr(line, "ndots:");
43 if (p && isdigit(p[6])) {
44 p += 6;
45 unsigned long x = strtoul(p, &z, 10);
46 if (z != p) conf->ndots = x > 15 ? 15 : x;
47 }
48 p = strstr(line, "attempts:");
49 if (p && isdigit(p[9])) {
50 p += 9;
51 unsigned long x = strtoul(p, &z, 10);
52 if (z != p) conf->attempts = x > 10 ? 10 : x;
53 }
54 p = strstr(line, "timeout:");
55 if (p && (isdigit(p[8]) || p[8]=='.')) {
56 p += 8;
57 unsigned long x = strtoul(p, &z, 10);
58 if (z != p) conf->timeout = x > 60 ? 60 : x;
59 }
60 continue;
61 }
62 if (!strncmp(line, "nameserver", 10) && isspace(line[10])) {
63 if (nns >= MAXNS) continue;
64 for (p=line+11; isspace(*p); p++);
65 for (z=p; *z && !isspace(*z); z++);
66 *z=0;
67 if (__lookup_ipliteral(conf->ns+nns, p, AF_UNSPEC) > 0)
68 nns++;
69 continue;
70 }
71
72 if (!search) continue;
73 if ((strncmp(line, "domain", 6) && strncmp(line, "search", 6))
74 || !isspace(line[6]))
75 continue;
76 for (p=line+7; isspace(*p); p++);
77 size_t l = strlen(p);
78 /* This can never happen anyway with chosen buffer sizes. */
79 if (l >= search_sz) continue;
80 memcpy(search, p, l+1);
81 }
82
83 __fclose_ca(f);
84
85no_resolv_conf:
86 if (!nns) {
87 __lookup_ipliteral(conf->ns, "127.0.0.1", AF_UNSPEC);
88 nns = 1;
89 }
90
91 conf->nns = nns;
92
93 return 0;
94}
lib/libc/wasi/libc-top-half/musl/src/network/send.c deleted-6
......@@ -1,6 +0,0 @@
1#include <sys/socket.h>
2
3ssize_t send(int fd, const void *buf, size_t len, int flags)
4{
5 return sendto(fd, buf, len, flags, 0, 0);
6}
lib/libc/wasi/libc-top-half/musl/src/network/sendmmsg.c deleted-30
......@@ -1,30 +0,0 @@
1#define _GNU_SOURCE
2#include <sys/socket.h>
3#include <limits.h>
4#include <errno.h>
5#include "syscall.h"
6
7int sendmmsg(int fd, struct mmsghdr *msgvec, unsigned int vlen, unsigned int flags)
8{
9#if LONG_MAX > INT_MAX
10 /* Can't use the syscall directly because the kernel has the wrong
11 * idea for the types of msg_iovlen, msg_controllen, and cmsg_len,
12 * and the cmsg blocks cannot be modified in-place. */
13 int i;
14 if (vlen > IOV_MAX) vlen = IOV_MAX; /* This matches the kernel. */
15 if (!vlen) return 0;
16 for (i=0; i<vlen; i++) {
17 /* As an unfortunate inconsistency, the sendmmsg API uses
18 * unsigned int for the resulting msg_len, despite sendmsg
19 * returning ssize_t. However Linux limits the total bytes
20 * sent by sendmsg to INT_MAX, so the assignment is safe. */
21 ssize_t r = sendmsg(fd, &msgvec[i].msg_hdr, flags);
22 if (r < 0) goto error;
23 msgvec[i].msg_len = r;
24 }
25error:
26 return i ? i : -1;
27#else
28 return syscall_cp(SYS_sendmmsg, fd, msgvec, vlen, flags);
29#endif
30}
lib/libc/wasi/libc-top-half/musl/src/network/sendmsg.c deleted-29
......@@ -1,29 +0,0 @@
1#include <sys/socket.h>
2#include <limits.h>
3#include <string.h>
4#include <errno.h>
5#include "syscall.h"
6
7ssize_t sendmsg(int fd, const struct msghdr *msg, int flags)
8{
9#if LONG_MAX > INT_MAX
10 struct msghdr h;
11 struct cmsghdr chbuf[1024/sizeof(struct cmsghdr)+1], *c;
12 if (msg) {
13 h = *msg;
14 h.__pad1 = h.__pad2 = 0;
15 msg = &h;
16 if (h.msg_controllen) {
17 if (h.msg_controllen > 1024) {
18 errno = ENOMEM;
19 return -1;
20 }
21 memcpy(chbuf, h.msg_control, h.msg_controllen);
22 h.msg_control = chbuf;
23 for (c=CMSG_FIRSTHDR(&h); c; c=CMSG_NXTHDR(&h,c))
24 c->__pad1 = 0;
25 }
26 }
27#endif
28 return socketcall_cp(sendmsg, fd, msg, flags, 0, 0, 0);
29}
lib/libc/wasi/libc-top-half/musl/src/network/sendto.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/socket.h>
2#include "syscall.h"
3
4ssize_t sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen)
5{
6 return socketcall_cp(sendto, fd, buf, len, flags, addr, alen);
7}
lib/libc/wasi/libc-top-half/musl/src/network/serv.c deleted-14
......@@ -1,14 +0,0 @@
1#include <netdb.h>
2
3void endservent(void)
4{
5}
6
7void setservent(int stayopen)
8{
9}
10
11struct servent *getservent(void)
12{
13 return 0;
14}
lib/libc/wasi/libc-top-half/musl/src/network/setsockopt.c deleted-46
......@@ -1,46 +0,0 @@
1#include <sys/socket.h>
2#include <sys/time.h>
3#include <errno.h>
4#include "syscall.h"
5
6#define IS32BIT(x) !((x)+0x80000000ULL>>32)
7#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
8
9int setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
10{
11 const struct timeval *tv;
12 time_t s;
13 suseconds_t us;
14
15 int r = __socketcall(setsockopt, fd, level, optname, optval, optlen, 0);
16
17 if (r==-ENOPROTOOPT) switch (level) {
18 case SOL_SOCKET:
19 switch (optname) {
20 case SO_RCVTIMEO:
21 case SO_SNDTIMEO:
22 if (SO_RCVTIMEO == SO_RCVTIMEO_OLD) break;
23 if (optlen < sizeof *tv) return __syscall_ret(-EINVAL);
24 tv = optval;
25 s = tv->tv_sec;
26 us = tv->tv_usec;
27 if (!IS32BIT(s)) return __syscall_ret(-ENOTSUP);
28
29 if (optname==SO_RCVTIMEO) optname=SO_RCVTIMEO_OLD;
30 if (optname==SO_SNDTIMEO) optname=SO_SNDTIMEO_OLD;
31
32 r = __socketcall(setsockopt, fd, level, optname,
33 ((long[]){s, CLAMP(us)}), 2*sizeof(long), 0);
34 break;
35 case SO_TIMESTAMP:
36 case SO_TIMESTAMPNS:
37 if (SO_TIMESTAMP == SO_TIMESTAMP_OLD) break;
38 if (optname==SO_TIMESTAMP) optname=SO_TIMESTAMP_OLD;
39 if (optname==SO_TIMESTAMPNS) optname=SO_TIMESTAMPNS_OLD;
40 r = __socketcall(setsockopt, fd, level,
41 optname, optval, optlen, 0);
42 break;
43 }
44 }
45 return __syscall_ret(r);
46}
lib/libc/wasi/libc-top-half/musl/src/network/shutdown.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/socket.h>
2#include "syscall.h"
3
4int shutdown(int fd, int how)
5{
6 return socketcall(shutdown, fd, how, 0, 0, 0, 0);
7}
lib/libc/wasi/libc-top-half/musl/src/network/sockatmark.c deleted-10
......@@ -1,10 +0,0 @@
1#include <sys/socket.h>
2#include <sys/ioctl.h>
3
4int sockatmark(int s)
5{
6 int ret;
7 if (ioctl(s, SIOCATMARK, &ret) < 0)
8 return -1;
9 return ret;
10}
lib/libc/wasi/libc-top-half/musl/src/network/socket.c deleted-21
......@@ -1,21 +0,0 @@
1#include <sys/socket.h>
2#include <fcntl.h>
3#include <errno.h>
4#include "syscall.h"
5
6int socket(int domain, int type, int protocol)
7{
8 int s = __socketcall(socket, domain, type, protocol, 0, 0, 0);
9 if ((s==-EINVAL || s==-EPROTONOSUPPORT)
10 && (type&(SOCK_CLOEXEC|SOCK_NONBLOCK))) {
11 s = __socketcall(socket, domain,
12 type & ~(SOCK_CLOEXEC|SOCK_NONBLOCK),
13 protocol, 0, 0, 0);
14 if (s < 0) return __syscall_ret(s);
15 if (type & SOCK_CLOEXEC)
16 __syscall(SYS_fcntl, s, F_SETFD, FD_CLOEXEC);
17 if (type & SOCK_NONBLOCK)
18 __syscall(SYS_fcntl, s, F_SETFL, O_NONBLOCK);
19 }
20 return __syscall_ret(s);
21}
lib/libc/wasi/libc-top-half/musl/src/network/socketpair.c deleted-25
......@@ -1,25 +0,0 @@
1#include <sys/socket.h>
2#include <fcntl.h>
3#include <errno.h>
4#include "syscall.h"
5
6int socketpair(int domain, int type, int protocol, int fd[2])
7{
8 int r = socketcall(socketpair, domain, type, protocol, fd, 0, 0);
9 if (r<0 && (errno==EINVAL || errno==EPROTONOSUPPORT)
10 && (type&(SOCK_CLOEXEC|SOCK_NONBLOCK))) {
11 r = socketcall(socketpair, domain,
12 type & ~(SOCK_CLOEXEC|SOCK_NONBLOCK),
13 protocol, fd, 0, 0);
14 if (r < 0) return r;
15 if (type & SOCK_CLOEXEC) {
16 __syscall(SYS_fcntl, fd[0], F_SETFD, FD_CLOEXEC);
17 __syscall(SYS_fcntl, fd[1], F_SETFD, FD_CLOEXEC);
18 }
19 if (type & SOCK_NONBLOCK) {
20 __syscall(SYS_fcntl, fd[0], F_SETFL, O_NONBLOCK);
21 __syscall(SYS_fcntl, fd[1], F_SETFL, O_NONBLOCK);
22 }
23 }
24 return r;
25}
lib/libc/wasi/libc-top-half/musl/src/passwd/fgetgrent.c deleted-12
......@@ -1,12 +0,0 @@
1#define _GNU_SOURCE
2#include "pwf.h"
3
4struct group *fgetgrent(FILE *f)
5{
6 static char *line, **mem;
7 static struct group gr;
8 struct group *res;
9 size_t size=0, nmem=0;
10 __getgrent_a(f, &gr, &line, &size, &mem, &nmem, &res);
11 return res;
12}
lib/libc/wasi/libc-top-half/musl/src/passwd/fgetpwent.c deleted-12
......@@ -1,12 +0,0 @@
1#define _GNU_SOURCE
2#include "pwf.h"
3
4struct passwd *fgetpwent(FILE *f)
5{
6 static char *line;
7 static struct passwd pw;
8 size_t size=0;
9 struct passwd *res;
10 __getpwent_a(f, &pw, &line, &size, &res);
11 return res;
12}
lib/libc/wasi/libc-top-half/musl/src/passwd/fgetspent.c deleted-15
......@@ -1,15 +0,0 @@
1#include "pwf.h"
2#include <pthread.h>
3
4struct spwd *fgetspent(FILE *f)
5{
6 static char *line;
7 static struct spwd sp;
8 size_t size = 0;
9 struct spwd *res = 0;
10 int cs;
11 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
12 if (getline(&line, &size, f) >= 0 && __parsespent(line, &sp) >= 0) res = &sp;
13 pthread_setcancelstate(cs, 0);
14 return res;
15}
lib/libc/wasi/libc-top-half/musl/src/passwd/getgr_a.c deleted-169
......@@ -1,169 +0,0 @@
1#include <pthread.h>
2#include <byteswap.h>
3#include <string.h>
4#include <unistd.h>
5#include "pwf.h"
6#include "nscd.h"
7
8static char *itoa(char *p, uint32_t x)
9{
10 // number of digits in a uint32_t + NUL
11 p += 11;
12 *--p = 0;
13 do {
14 *--p = '0' + x % 10;
15 x /= 10;
16 } while (x);
17 return p;
18}
19
20int __getgr_a(const char *name, gid_t gid, struct group *gr, char **buf, size_t *size, char ***mem, size_t *nmem, struct group **res)
21{
22 FILE *f;
23 int rv = 0;
24 int cs;
25
26 *res = 0;
27
28 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
29 f = fopen("/etc/group", "rbe");
30 if (!f) {
31 rv = errno;
32 goto done;
33 }
34
35 while (!(rv = __getgrent_a(f, gr, buf, size, mem, nmem, res)) && *res) {
36 if (name && !strcmp(name, (*res)->gr_name)
37 || !name && (*res)->gr_gid == gid) {
38 break;
39 }
40 }
41 fclose(f);
42
43 if (!*res && (rv == 0 || rv == ENOENT || rv == ENOTDIR)) {
44 int32_t req = name ? GETGRBYNAME : GETGRBYGID;
45 int32_t i;
46 const char *key;
47 int32_t groupbuf[GR_LEN] = {0};
48 size_t len = 0;
49 size_t grlist_len = 0;
50 char gidbuf[11] = {0};
51 int swap = 0;
52 char *ptr;
53
54 if (name) {
55 key = name;
56 } else {
57 if (gid < 0 || gid > UINT32_MAX) {
58 rv = 0;
59 goto done;
60 }
61 key = itoa(gidbuf, gid);
62 }
63
64 f = __nscd_query(req, key, groupbuf, sizeof groupbuf, &swap);
65 if (!f) { rv = errno; goto done; }
66
67 if (!groupbuf[GRFOUND]) { rv = 0; goto cleanup_f; }
68
69 if (!groupbuf[GRNAMELEN] || !groupbuf[GRPASSWDLEN]) {
70 rv = EIO;
71 goto cleanup_f;
72 }
73
74 if (groupbuf[GRNAMELEN] > SIZE_MAX - groupbuf[GRPASSWDLEN]) {
75 rv = ENOMEM;
76 goto cleanup_f;
77 }
78 len = groupbuf[GRNAMELEN] + groupbuf[GRPASSWDLEN];
79
80 for (i = 0; i < groupbuf[GRMEMCNT]; i++) {
81 uint32_t name_len;
82 if (fread(&name_len, sizeof name_len, 1, f) < 1) {
83 rv = ferror(f) ? errno : EIO;
84 goto cleanup_f;
85 }
86 if (swap) {
87 name_len = bswap_32(name_len);
88 }
89 if (name_len > SIZE_MAX - grlist_len
90 || name_len > SIZE_MAX - len) {
91 rv = ENOMEM;
92 goto cleanup_f;
93 }
94 len += name_len;
95 grlist_len += name_len;
96 }
97
98 if (len > *size || !*buf) {
99 char *tmp = realloc(*buf, len);
100 if (!tmp) {
101 rv = errno;
102 goto cleanup_f;
103 }
104 *buf = tmp;
105 *size = len;
106 }
107
108 if (!fread(*buf, len, 1, f)) {
109 rv = ferror(f) ? errno : EIO;
110 goto cleanup_f;
111 }
112
113 if (groupbuf[GRMEMCNT] + 1 > *nmem) {
114 if (groupbuf[GRMEMCNT] + 1 > SIZE_MAX/sizeof(char*)) {
115 rv = ENOMEM;
116 goto cleanup_f;
117 }
118 char **tmp = realloc(*mem, (groupbuf[GRMEMCNT]+1)*sizeof(char*));
119 if (!tmp) {
120 rv = errno;
121 goto cleanup_f;
122 }
123 *mem = tmp;
124 *nmem = groupbuf[GRMEMCNT] + 1;
125 }
126
127 if (groupbuf[GRMEMCNT]) {
128 mem[0][0] = *buf + groupbuf[GRNAMELEN] + groupbuf[GRPASSWDLEN];
129 for (ptr = mem[0][0], i = 0; ptr != mem[0][0]+grlist_len; ptr++)
130 if (!*ptr) mem[0][++i] = ptr+1;
131 mem[0][i] = 0;
132
133 if (i != groupbuf[GRMEMCNT]) {
134 rv = EIO;
135 goto cleanup_f;
136 }
137 } else {
138 mem[0][0] = 0;
139 }
140
141 gr->gr_name = *buf;
142 gr->gr_passwd = gr->gr_name + groupbuf[GRNAMELEN];
143 gr->gr_gid = groupbuf[GRGID];
144 gr->gr_mem = *mem;
145
146 if (gr->gr_passwd[-1]
147 || gr->gr_passwd[groupbuf[GRPASSWDLEN]-1]) {
148 rv = EIO;
149 goto cleanup_f;
150 }
151
152 if (name && strcmp(name, gr->gr_name)
153 || !name && gid != gr->gr_gid) {
154 rv = EIO;
155 goto cleanup_f;
156 }
157
158 *res = gr;
159
160cleanup_f:
161 fclose(f);
162 goto done;
163 }
164
165done:
166 pthread_setcancelstate(cs, 0);
167 if (rv) errno = rv;
168 return rv;
169}
lib/libc/wasi/libc-top-half/musl/src/passwd/getgr_r.c deleted-49
......@@ -1,49 +0,0 @@
1#include "pwf.h"
2#include <pthread.h>
3
4#define FIX(x) (gr->gr_##x = gr->gr_##x-line+buf)
5
6static int getgr_r(const char *name, gid_t gid, struct group *gr, char *buf, size_t size, struct group **res)
7{
8 char *line = 0;
9 size_t len = 0;
10 char **mem = 0;
11 size_t nmem = 0;
12 int rv = 0;
13 size_t i;
14 int cs;
15
16 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
17
18 rv = __getgr_a(name, gid, gr, &line, &len, &mem, &nmem, res);
19 if (*res && size < len + (nmem+1)*sizeof(char *) + 32) {
20 *res = 0;
21 rv = ERANGE;
22 }
23 if (*res) {
24 buf += (16-(uintptr_t)buf)%16;
25 gr->gr_mem = (void *)buf;
26 buf += (nmem+1)*sizeof(char *);
27 memcpy(buf, line, len);
28 FIX(name);
29 FIX(passwd);
30 for (i=0; mem[i]; i++)
31 gr->gr_mem[i] = mem[i]-line+buf;
32 gr->gr_mem[i] = 0;
33 }
34 free(mem);
35 free(line);
36 pthread_setcancelstate(cs, 0);
37 if (rv) errno = rv;
38 return rv;
39}
40
41int getgrnam_r(const char *name, struct group *gr, char *buf, size_t size, struct group **res)
42{
43 return getgr_r(name, 0, gr, buf, size, res);
44}
45
46int getgrgid_r(gid_t gid, struct group *gr, char *buf, size_t size, struct group **res)
47{
48 return getgr_r(0, gid, gr, buf, size, res);
49}
lib/libc/wasi/libc-top-half/musl/src/passwd/getgrent.c deleted-39
......@@ -1,39 +0,0 @@
1#include "pwf.h"
2
3static FILE *f;
4static char *line, **mem;
5static struct group gr;
6
7void setgrent()
8{
9 if (f) fclose(f);
10 f = 0;
11}
12
13weak_alias(setgrent, endgrent);
14
15struct group *getgrent()
16{
17 struct group *res;
18 size_t size=0, nmem=0;
19 if (!f) f = fopen("/etc/group", "rbe");
20 if (!f) return 0;
21 __getgrent_a(f, &gr, &line, &size, &mem, &nmem, &res);
22 return res;
23}
24
25struct group *getgrgid(gid_t gid)
26{
27 struct group *res;
28 size_t size=0, nmem=0;
29 __getgr_a(0, gid, &gr, &line, &size, &mem, &nmem, &res);
30 return res;
31}
32
33struct group *getgrnam(const char *name)
34{
35 struct group *res;
36 size_t size=0, nmem=0;
37 __getgr_a(name, 0, &gr, &line, &size, &mem, &nmem, &res);
38 return res;
39}
lib/libc/wasi/libc-top-half/musl/src/passwd/getgrent_a.c deleted-68
......@@ -1,68 +0,0 @@
1#include "pwf.h"
2#include <pthread.h>
3
4static unsigned atou(char **s)
5{
6 unsigned x;
7 for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0');
8 return x;
9}
10
11int __getgrent_a(FILE *f, struct group *gr, char **line, size_t *size, char ***mem, size_t *nmem, struct group **res)
12{
13 ssize_t l;
14 char *s, *mems;
15 size_t i;
16 int rv = 0;
17 int cs;
18 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
19 for (;;) {
20 if ((l=getline(line, size, f)) < 0) {
21 rv = ferror(f) ? errno : 0;
22 free(*line);
23 *line = 0;
24 gr = 0;
25 goto end;
26 }
27 line[0][l-1] = 0;
28
29 s = line[0];
30 gr->gr_name = s++;
31 if (!(s = strchr(s, ':'))) continue;
32
33 *s++ = 0; gr->gr_passwd = s;
34 if (!(s = strchr(s, ':'))) continue;
35
36 *s++ = 0; gr->gr_gid = atou(&s);
37 if (*s != ':') continue;
38
39 *s++ = 0; mems = s;
40 break;
41 }
42
43 for (*nmem=!!*s; *s; s++)
44 if (*s==',') ++*nmem;
45 free(*mem);
46 *mem = calloc(sizeof(char *), *nmem+1);
47 if (!*mem) {
48 rv = errno;
49 free(*line);
50 *line = 0;
51 gr = 0;
52 goto end;
53 }
54 if (*mems) {
55 mem[0][0] = mems;
56 for (s=mems, i=0; *s; s++)
57 if (*s==',') *s++ = 0, mem[0][++i] = s;
58 mem[0][++i] = 0;
59 } else {
60 mem[0][0] = 0;
61 }
62 gr->gr_mem = *mem;
63end:
64 pthread_setcancelstate(cs, 0);
65 *res = gr;
66 if(rv) errno = rv;
67 return rv;
68}
lib/libc/wasi/libc-top-half/musl/src/passwd/getgrouplist.c deleted-81
......@@ -1,81 +0,0 @@
1#define _GNU_SOURCE
2#include "pwf.h"
3#include <grp.h>
4#include <string.h>
5#include <limits.h>
6#include <stdio.h>
7#include <stdlib.h>
8#include <byteswap.h>
9#include <errno.h>
10#include "nscd.h"
11
12int getgrouplist(const char *user, gid_t gid, gid_t *groups, int *ngroups)
13{
14 int rv, nlim, ret = -1;
15 ssize_t i, n = 1;
16 struct group gr;
17 struct group *res;
18 FILE *f;
19 int swap = 0;
20 int32_t resp[INITGR_LEN];
21 uint32_t *nscdbuf = 0;
22 char *buf = 0;
23 char **mem = 0;
24 size_t nmem = 0;
25 size_t size;
26 nlim = *ngroups;
27 if (nlim >= 1) *groups++ = gid;
28
29 f = __nscd_query(GETINITGR, user, resp, sizeof resp, &swap);
30 if (!f) goto cleanup;
31 if (resp[INITGRFOUND]) {
32 nscdbuf = calloc(resp[INITGRNGRPS], sizeof(uint32_t));
33 if (!nscdbuf) goto cleanup;
34 size_t nbytes = sizeof(*nscdbuf)*resp[INITGRNGRPS];
35 if (nbytes && !fread(nscdbuf, nbytes, 1, f)) {
36 if (!ferror(f)) errno = EIO;
37 goto cleanup;
38 }
39 if (swap) {
40 for (i = 0; i < resp[INITGRNGRPS]; i++)
41 nscdbuf[i] = bswap_32(nscdbuf[i]);
42 }
43 }
44 fclose(f);
45
46 f = fopen("/etc/group", "rbe");
47 if (!f && errno != ENOENT && errno != ENOTDIR)
48 goto cleanup;
49
50 if (f) {
51 while (!(rv = __getgrent_a(f, &gr, &buf, &size, &mem, &nmem, &res)) && res) {
52 if (nscdbuf)
53 for (i=0; i < resp[INITGRNGRPS]; i++) {
54 if (nscdbuf[i] == gr.gr_gid) nscdbuf[i] = gid;
55 }
56 for (i=0; gr.gr_mem[i] && strcmp(user, gr.gr_mem[i]); i++);
57 if (!gr.gr_mem[i]) continue;
58 if (++n <= nlim) *groups++ = gr.gr_gid;
59 }
60 if (rv) {
61 errno = rv;
62 goto cleanup;
63 }
64 }
65 if (nscdbuf) {
66 for(i=0; i < resp[INITGRNGRPS]; i++) {
67 if (nscdbuf[i] != gid)
68 if(++n <= nlim) *groups++ = nscdbuf[i];
69 }
70 }
71
72 ret = n > nlim ? -1 : n;
73 *ngroups = n;
74
75cleanup:
76 if (f) fclose(f);
77 free(nscdbuf);
78 free(buf);
79 free(mem);
80 return ret;
81}
lib/libc/wasi/libc-top-half/musl/src/passwd/getpw_a.c deleted-142
......@@ -1,142 +0,0 @@
1#include <pthread.h>
2#include <byteswap.h>
3#include <string.h>
4#include <unistd.h>
5#include "pwf.h"
6#include "nscd.h"
7
8static char *itoa(char *p, uint32_t x)
9{
10 // number of digits in a uint32_t + NUL
11 p += 11;
12 *--p = 0;
13 do {
14 *--p = '0' + x % 10;
15 x /= 10;
16 } while (x);
17 return p;
18}
19
20int __getpw_a(const char *name, uid_t uid, struct passwd *pw, char **buf, size_t *size, struct passwd **res)
21{
22 FILE *f;
23 int cs;
24 int rv = 0;
25
26 *res = 0;
27
28 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
29
30 f = fopen("/etc/passwd", "rbe");
31 if (!f) {
32 rv = errno;
33 goto done;
34 }
35
36 while (!(rv = __getpwent_a(f, pw, buf, size, res)) && *res) {
37 if (name && !strcmp(name, (*res)->pw_name)
38 || !name && (*res)->pw_uid == uid)
39 break;
40 }
41 fclose(f);
42
43 if (!*res && (rv == 0 || rv == ENOENT || rv == ENOTDIR)) {
44 int32_t req = name ? GETPWBYNAME : GETPWBYUID;
45 const char *key;
46 int32_t passwdbuf[PW_LEN] = {0};
47 size_t len = 0;
48 char uidbuf[11] = {0};
49
50 if (name) {
51 key = name;
52 } else {
53 /* uid outside of this range can't be queried with the
54 * nscd interface, but might happen if uid_t ever
55 * happens to be a larger type (this is not true as of
56 * now)
57 */
58 if(uid < 0 || uid > UINT32_MAX) {
59 rv = 0;
60 goto done;
61 }
62 key = itoa(uidbuf, uid);
63 }
64
65 f = __nscd_query(req, key, passwdbuf, sizeof passwdbuf, (int[]){0});
66 if (!f) { rv = errno; goto done; }
67
68 if(!passwdbuf[PWFOUND]) { rv = 0; goto cleanup_f; }
69
70 /* A zero length response from nscd is invalid. We ignore
71 * invalid responses and just report an error, rather than
72 * trying to do something with them.
73 */
74 if (!passwdbuf[PWNAMELEN] || !passwdbuf[PWPASSWDLEN]
75 || !passwdbuf[PWGECOSLEN] || !passwdbuf[PWDIRLEN]
76 || !passwdbuf[PWSHELLLEN]) {
77 rv = EIO;
78 goto cleanup_f;
79 }
80
81 if ((passwdbuf[PWNAMELEN]|passwdbuf[PWPASSWDLEN]
82 |passwdbuf[PWGECOSLEN]|passwdbuf[PWDIRLEN]
83 |passwdbuf[PWSHELLLEN]) >= SIZE_MAX/8) {
84 rv = ENOMEM;
85 goto cleanup_f;
86 }
87
88 len = passwdbuf[PWNAMELEN] + passwdbuf[PWPASSWDLEN]
89 + passwdbuf[PWGECOSLEN] + passwdbuf[PWDIRLEN]
90 + passwdbuf[PWSHELLLEN];
91
92 if (len > *size || !*buf) {
93 char *tmp = realloc(*buf, len);
94 if (!tmp) {
95 rv = errno;
96 goto cleanup_f;
97 }
98 *buf = tmp;
99 *size = len;
100 }
101
102 if (!fread(*buf, len, 1, f)) {
103 rv = ferror(f) ? errno : EIO;
104 goto cleanup_f;
105 }
106
107 pw->pw_name = *buf;
108 pw->pw_passwd = pw->pw_name + passwdbuf[PWNAMELEN];
109 pw->pw_gecos = pw->pw_passwd + passwdbuf[PWPASSWDLEN];
110 pw->pw_dir = pw->pw_gecos + passwdbuf[PWGECOSLEN];
111 pw->pw_shell = pw->pw_dir + passwdbuf[PWDIRLEN];
112 pw->pw_uid = passwdbuf[PWUID];
113 pw->pw_gid = passwdbuf[PWGID];
114
115 /* Don't assume that nscd made sure to null terminate strings.
116 * It's supposed to, but malicious nscd should be ignored
117 * rather than causing a crash.
118 */
119 if (pw->pw_passwd[-1] || pw->pw_gecos[-1] || pw->pw_dir[-1]
120 || pw->pw_shell[passwdbuf[PWSHELLLEN]-1]) {
121 rv = EIO;
122 goto cleanup_f;
123 }
124
125 if (name && strcmp(name, pw->pw_name)
126 || !name && uid != pw->pw_uid) {
127 rv = EIO;
128 goto cleanup_f;
129 }
130
131
132 *res = pw;
133cleanup_f:
134 fclose(f);
135 goto done;
136 }
137
138done:
139 pthread_setcancelstate(cs, 0);
140 if (rv) errno = rv;
141 return rv;
142}
lib/libc/wasi/libc-top-half/musl/src/passwd/getpw_r.c deleted-42
......@@ -1,42 +0,0 @@
1#include "pwf.h"
2#include <pthread.h>
3
4#define FIX(x) (pw->pw_##x = pw->pw_##x-line+buf)
5
6static int getpw_r(const char *name, uid_t uid, struct passwd *pw, char *buf, size_t size, struct passwd **res)
7{
8 char *line = 0;
9 size_t len = 0;
10 int rv = 0;
11 int cs;
12
13 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
14
15 rv = __getpw_a(name, uid, pw, &line, &len, res);
16 if (*res && size < len) {
17 *res = 0;
18 rv = ERANGE;
19 }
20 if (*res) {
21 memcpy(buf, line, len);
22 FIX(name);
23 FIX(passwd);
24 FIX(gecos);
25 FIX(dir);
26 FIX(shell);
27 }
28 free(line);
29 pthread_setcancelstate(cs, 0);
30 if (rv) errno = rv;
31 return rv;
32}
33
34int getpwnam_r(const char *name, struct passwd *pw, char *buf, size_t size, struct passwd **res)
35{
36 return getpw_r(name, 0, pw, buf, size, res);
37}
38
39int getpwuid_r(uid_t uid, struct passwd *pw, char *buf, size_t size, struct passwd **res)
40{
41 return getpw_r(0, uid, pw, buf, size, res);
42}
lib/libc/wasi/libc-top-half/musl/src/passwd/getpwent.c deleted-37
......@@ -1,37 +0,0 @@
1#include "pwf.h"
2
3static FILE *f;
4static char *line;
5static struct passwd pw;
6static size_t size;
7
8void setpwent()
9{
10 if (f) fclose(f);
11 f = 0;
12}
13
14weak_alias(setpwent, endpwent);
15
16struct passwd *getpwent()
17{
18 struct passwd *res;
19 if (!f) f = fopen("/etc/passwd", "rbe");
20 if (!f) return 0;
21 __getpwent_a(f, &pw, &line, &size, &res);
22 return res;
23}
24
25struct passwd *getpwuid(uid_t uid)
26{
27 struct passwd *res;
28 __getpw_a(0, uid, &pw, &line, &size, &res);
29 return res;
30}
31
32struct passwd *getpwnam(const char *name)
33{
34 struct passwd *res;
35 __getpw_a(name, 0, &pw, &line, &size, &res);
36 return res;
37}
lib/libc/wasi/libc-top-half/musl/src/passwd/getpwent_a.c deleted-54
......@@ -1,54 +0,0 @@
1#include "pwf.h"
2#include <pthread.h>
3
4static unsigned atou(char **s)
5{
6 unsigned x;
7 for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0');
8 return x;
9}
10
11int __getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *size, struct passwd **res)
12{
13 ssize_t l;
14 char *s;
15 int rv = 0;
16 int cs;
17 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
18 for (;;) {
19 if ((l=getline(line, size, f)) < 0) {
20 rv = ferror(f) ? errno : 0;
21 free(*line);
22 *line = 0;
23 pw = 0;
24 break;
25 }
26 line[0][l-1] = 0;
27
28 s = line[0];
29 pw->pw_name = s++;
30 if (!(s = strchr(s, ':'))) continue;
31
32 *s++ = 0; pw->pw_passwd = s;
33 if (!(s = strchr(s, ':'))) continue;
34
35 *s++ = 0; pw->pw_uid = atou(&s);
36 if (*s != ':') continue;
37
38 *s++ = 0; pw->pw_gid = atou(&s);
39 if (*s != ':') continue;
40
41 *s++ = 0; pw->pw_gecos = s;
42 if (!(s = strchr(s, ':'))) continue;
43
44 *s++ = 0; pw->pw_dir = s;
45 if (!(s = strchr(s, ':'))) continue;
46
47 *s++ = 0; pw->pw_shell = s;
48 break;
49 }
50 pthread_setcancelstate(cs, 0);
51 *res = pw;
52 if (rv) errno = rv;
53 return rv;
54}
lib/libc/wasi/libc-top-half/musl/src/passwd/getspent.c deleted-14
......@@ -1,14 +0,0 @@
1#include "pwf.h"
2
3void setspent()
4{
5}
6
7void endspent()
8{
9}
10
11struct spwd *getspent()
12{
13 return 0;
14}
lib/libc/wasi/libc-top-half/musl/src/passwd/getspnam.c deleted-18
......@@ -1,18 +0,0 @@
1#include "pwf.h"
2
3#define LINE_LIM 256
4
5struct spwd *getspnam(const char *name)
6{
7 static struct spwd sp;
8 static char *line;
9 struct spwd *res;
10 int e;
11 int orig_errno = errno;
12
13 if (!line) line = malloc(LINE_LIM);
14 if (!line) return 0;
15 e = getspnam_r(name, &sp, line, LINE_LIM, &res);
16 errno = e ? e : orig_errno;
17 return res;
18}
lib/libc/wasi/libc-top-half/musl/src/passwd/getspnam_r.c deleted-125
......@@ -1,125 +0,0 @@
1#include <fcntl.h>
2#include <unistd.h>
3#include <sys/stat.h>
4#include <ctype.h>
5#include <pthread.h>
6#include "pwf.h"
7
8/* This implementation support Openwall-style TCB passwords in place of
9 * traditional shadow, if the appropriate directories and files exist.
10 * Thus, it is careful to avoid following symlinks or blocking on fifos
11 * which a malicious user might create in place of his or her TCB shadow
12 * file. It also avoids any allocation to prevent memory-exhaustion
13 * attacks via huge TCB shadow files. */
14
15static long xatol(char **s)
16{
17 long x;
18 if (**s == ':' || **s == '\n') return -1;
19 for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0');
20 return x;
21}
22
23int __parsespent(char *s, struct spwd *sp)
24{
25 sp->sp_namp = s;
26 if (!(s = strchr(s, ':'))) return -1;
27 *s = 0;
28
29 sp->sp_pwdp = ++s;
30 if (!(s = strchr(s, ':'))) return -1;
31 *s = 0;
32
33 s++; sp->sp_lstchg = xatol(&s);
34 if (*s != ':') return -1;
35
36 s++; sp->sp_min = xatol(&s);
37 if (*s != ':') return -1;
38
39 s++; sp->sp_max = xatol(&s);
40 if (*s != ':') return -1;
41
42 s++; sp->sp_warn = xatol(&s);
43 if (*s != ':') return -1;
44
45 s++; sp->sp_inact = xatol(&s);
46 if (*s != ':') return -1;
47
48 s++; sp->sp_expire = xatol(&s);
49 if (*s != ':') return -1;
50
51 s++; sp->sp_flag = xatol(&s);
52 if (*s != '\n') return -1;
53 return 0;
54}
55
56static void cleanup(void *p)
57{
58 fclose(p);
59}
60
61int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t size, struct spwd **res)
62{
63 char path[20+NAME_MAX];
64 FILE *f = 0;
65 int rv = 0;
66 int fd;
67 size_t k, l = strlen(name);
68 int skip = 0;
69 int cs;
70 int orig_errno = errno;
71
72 *res = 0;
73
74 /* Disallow potentially-malicious user names */
75 if (*name=='.' || strchr(name, '/') || !l)
76 return errno = EINVAL;
77
78 /* Buffer size must at least be able to hold name, plus some.. */
79 if (size < l+100)
80 return errno = ERANGE;
81
82 /* Protect against truncation */
83 if (snprintf(path, sizeof path, "/etc/tcb/%s/shadow", name) >= sizeof path)
84 return errno = EINVAL;
85
86 fd = open(path, O_RDONLY|O_NOFOLLOW|O_NONBLOCK|O_CLOEXEC);
87 if (fd >= 0) {
88 struct stat st = { 0 };
89 errno = EINVAL;
90 if (fstat(fd, &st) || !S_ISREG(st.st_mode) || !(f = fdopen(fd, "rb"))) {
91 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
92 close(fd);
93 pthread_setcancelstate(cs, 0);
94 return errno;
95 }
96 } else {
97 if (errno != ENOENT && errno != ENOTDIR)
98 return errno;
99 f = fopen("/etc/shadow", "rbe");
100 if (!f) {
101 if (errno != ENOENT && errno != ENOTDIR)
102 return errno;
103 return 0;
104 }
105 }
106
107 pthread_cleanup_push(cleanup, f);
108 while (fgets(buf, size, f) && (k=strlen(buf))>0) {
109 if (skip || strncmp(name, buf, l) || buf[l]!=':') {
110 skip = buf[k-1] != '\n';
111 continue;
112 }
113 if (buf[k-1] != '\n') {
114 rv = ERANGE;
115 break;
116 }
117
118 if (__parsespent(buf, sp) < 0) continue;
119 *res = sp;
120 break;
121 }
122 pthread_cleanup_pop(1);
123 errno = rv ? rv : orig_errno;
124 return rv;
125}
lib/libc/wasi/libc-top-half/musl/src/passwd/lckpwdf.c deleted-11
......@@ -1,11 +0,0 @@
1#include <shadow.h>
2
3int lckpwdf()
4{
5 return 0;
6}
7
8int ulckpwdf()
9{
10 return 0;
11}
lib/libc/wasi/libc-top-half/musl/src/passwd/nscd_query.c deleted-115
......@@ -1,115 +0,0 @@
1#include <sys/socket.h>
2#include <byteswap.h>
3#include <unistd.h>
4#include <stdio.h>
5#include <string.h>
6#include <errno.h>
7#include <limits.h>
8#include "nscd.h"
9
10static const struct {
11 short sun_family;
12 char sun_path[21];
13} addr = {
14 AF_UNIX,
15 "/var/run/nscd/socket"
16};
17
18FILE *__nscd_query(int32_t req, const char *key, int32_t *buf, size_t len, int *swap)
19{
20 size_t i;
21 int fd;
22 FILE *f = 0;
23 int32_t req_buf[REQ_LEN] = {
24 NSCDVERSION,
25 req,
26 strnlen(key,LOGIN_NAME_MAX)+1
27 };
28 struct msghdr msg = {
29 .msg_iov = (struct iovec[]){
30 {&req_buf, sizeof(req_buf)},
31 {(char*)key, strlen(key)+1}
32 },
33 .msg_iovlen = 2
34 };
35 int errno_save = errno;
36
37 *swap = 0;
38retry:
39 memset(buf, 0, len);
40 buf[0] = NSCDVERSION;
41
42 fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
43 if (fd < 0) {
44 if (errno == EAFNOSUPPORT) {
45 f = fopen("/dev/null", "re");
46 if (f)
47 errno = errno_save;
48 return f;
49 }
50 return 0;
51 }
52
53 if(!(f = fdopen(fd, "r"))) {
54 close(fd);
55 return 0;
56 }
57
58 if (req_buf[2] > LOGIN_NAME_MAX)
59 return f;
60
61 if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
62 /* If there isn't a running nscd we simulate a "not found"
63 * result and the caller is responsible for calling
64 * fclose on the (unconnected) socket. The value of
65 * errno must be left unchanged in this case. */
66 if (errno == EACCES || errno == ECONNREFUSED || errno == ENOENT) {
67 errno = errno_save;
68 return f;
69 }
70 goto error;
71 }
72
73 if (sendmsg(fd, &msg, MSG_NOSIGNAL) < 0)
74 goto error;
75
76 if (!fread(buf, len, 1, f)) {
77 /* If the VERSION entry mismatches nscd will disconnect. The
78 * most likely cause is that the endianness mismatched. So, we
79 * byteswap and try once more. (if we already swapped, just
80 * fail out)
81 */
82 if (ferror(f)) goto error;
83 if (!*swap) {
84 fclose(f);
85 for (i = 0; i < sizeof(req_buf)/sizeof(req_buf[0]); i++) {
86 req_buf[i] = bswap_32(req_buf[i]);
87 }
88 *swap = 1;
89 goto retry;
90 } else {
91 errno = EIO;
92 goto error;
93 }
94 }
95
96 if (*swap) {
97 for (i = 0; i < len/sizeof(buf[0]); i++) {
98 buf[i] = bswap_32(buf[i]);
99 }
100 }
101
102 /* The first entry in every nscd response is the version number. This
103 * really shouldn't happen, and is evidence of some form of malformed
104 * response.
105 */
106 if(buf[0] != NSCDVERSION) {
107 errno = EIO;
108 goto error;
109 }
110
111 return f;
112error:
113 fclose(f);
114 return 0;
115}
lib/libc/wasi/libc-top-half/musl/src/passwd/putgrent.c deleted-17
......@@ -1,17 +0,0 @@
1#define _GNU_SOURCE
2#include <grp.h>
3#include <stdio.h>
4
5int putgrent(const struct group *gr, FILE *f)
6{
7 int r;
8 size_t i;
9 flockfile(f);
10 if ((r = fprintf(f, "%s:%s:%u:", gr->gr_name, gr->gr_passwd, gr->gr_gid))<0) goto done;
11 if (gr->gr_mem) for (i=0; gr->gr_mem[i]; i++)
12 if ((r = fprintf(f, "%s%s", i?",":"", gr->gr_mem[i]))<0) goto done;
13 r = fputc('\n', f);
14done:
15 funlockfile(f);
16 return r<0 ? -1 : 0;
17}
lib/libc/wasi/libc-top-half/musl/src/passwd/putpwent.c deleted-10
......@@ -1,10 +0,0 @@
1#define _GNU_SOURCE
2#include <pwd.h>
3#include <stdio.h>
4
5int putpwent(const struct passwd *pw, FILE *f)
6{
7 return fprintf(f, "%s:%s:%u:%u:%s:%s:%s\n",
8 pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid,
9 pw->pw_gecos, pw->pw_dir, pw->pw_shell)<0 ? -1 : 0;
10}
lib/libc/wasi/libc-top-half/musl/src/passwd/putspent.c deleted-13
......@@ -1,13 +0,0 @@
1#include <shadow.h>
2#include <stdio.h>
3
4#define NUM(n) ((n) == -1 ? 0 : -1), ((n) == -1 ? 0 : (n))
5#define STR(s) ((s) ? (s) : "")
6
7int putspent(const struct spwd *sp, FILE *f)
8{
9 return fprintf(f, "%s:%s:%.*ld:%.*ld:%.*ld:%.*ld:%.*ld:%.*ld:%.*lu\n",
10 STR(sp->sp_namp), STR(sp->sp_pwdp), NUM(sp->sp_lstchg),
11 NUM(sp->sp_min), NUM(sp->sp_max), NUM(sp->sp_warn),
12 NUM(sp->sp_inact), NUM(sp->sp_expire), NUM(sp->sp_flag)) < 0 ? -1 : 0;
13}
lib/libc/wasi/libc-top-half/musl/src/process/_Fork.c deleted-38
......@@ -1,38 +0,0 @@
1#include <unistd.h>
2#include <signal.h>
3#include "syscall.h"
4#include "libc.h"
5#include "lock.h"
6#include "pthread_impl.h"
7#include "aio_impl.h"
8
9static void dummy(int x) { }
10weak_alias(dummy, __aio_atfork);
11
12pid_t _Fork(void)
13{
14 pid_t ret;
15 sigset_t set;
16 __block_all_sigs(&set);
17 __aio_atfork(-1);
18 LOCK(__abort_lock);
19#ifdef SYS_fork
20 ret = __syscall(SYS_fork);
21#else
22 ret = __syscall(SYS_clone, SIGCHLD, 0);
23#endif
24 if (!ret) {
25 pthread_t self = __pthread_self();
26 self->tid = __syscall(SYS_gettid);
27 self->robust_list.off = 0;
28 self->robust_list.pending = 0;
29 self->next = self->prev = self;
30 __thread_list_lock = 0;
31 libc.threads_minus_1 = 0;
32 if (libc.need_locks) libc.need_locks = -1;
33 }
34 UNLOCK(__abort_lock);
35 __aio_atfork(!ret);
36 __restore_sigs(&set);
37 return __syscall_ret(ret);
38}
lib/libc/wasi/libc-top-half/musl/src/process/arm/vfork.s deleted-10
......@@ -1,10 +0,0 @@
1.syntax unified
2.global vfork
3.type vfork,%function
4vfork:
5 mov ip, r7
6 mov r7, 190
7 svc 0
8 mov r7, ip
9 .hidden __syscall_ret
10 b __syscall_ret
lib/libc/wasi/libc-top-half/musl/src/process/execl.c deleted-22
......@@ -1,22 +0,0 @@
1#include <unistd.h>
2#include <stdarg.h>
3
4int execl(const char *path, const char *argv0, ...)
5{
6 int argc;
7 va_list ap;
8 va_start(ap, argv0);
9 for (argc=1; va_arg(ap, const char *); argc++);
10 va_end(ap);
11 {
12 int i;
13 char *argv[argc+1];
14 va_start(ap, argv0);
15 argv[0] = (char *)argv0;
16 for (i=1; i<argc; i++)
17 argv[i] = va_arg(ap, char *);
18 argv[i] = NULL;
19 va_end(ap);
20 return execv(path, argv);
21 }
22}
lib/libc/wasi/libc-top-half/musl/src/process/execle.c deleted-23
......@@ -1,23 +0,0 @@
1#include <unistd.h>
2#include <stdarg.h>
3
4int execle(const char *path, const char *argv0, ...)
5{
6 int argc;
7 va_list ap;
8 va_start(ap, argv0);
9 for (argc=1; va_arg(ap, const char *); argc++);
10 va_end(ap);
11 {
12 int i;
13 char *argv[argc+1];
14 char **envp;
15 va_start(ap, argv0);
16 argv[0] = (char *)argv0;
17 for (i=1; i<=argc; i++)
18 argv[i] = va_arg(ap, char *);
19 envp = va_arg(ap, char **);
20 va_end(ap);
21 return execve(path, argv, envp);
22 }
23}
lib/libc/wasi/libc-top-half/musl/src/process/execlp.c deleted-22
......@@ -1,22 +0,0 @@
1#include <unistd.h>
2#include <stdarg.h>
3
4int execlp(const char *file, const char *argv0, ...)
5{
6 int argc;
7 va_list ap;
8 va_start(ap, argv0);
9 for (argc=1; va_arg(ap, const char *); argc++);
10 va_end(ap);
11 {
12 int i;
13 char *argv[argc+1];
14 va_start(ap, argv0);
15 argv[0] = (char *)argv0;
16 for (i=1; i<argc; i++)
17 argv[i] = va_arg(ap, char *);
18 argv[i] = NULL;
19 va_end(ap);
20 return execvp(file, argv);
21 }
22}
lib/libc/wasi/libc-top-half/musl/src/process/execv.c deleted-8
......@@ -1,8 +0,0 @@
1#include <unistd.h>
2
3extern char **__environ;
4
5int execv(const char *path, char *const argv[])
6{
7 return execve(path, argv, __environ);
8}
lib/libc/wasi/libc-top-half/musl/src/process/execve.c deleted-8
......@@ -1,8 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4int execve(const char *path, char *const argv[], char *const envp[])
5{
6 /* do we need to use environ if envp is null? */
7 return syscall(SYS_execve, path, argv, envp);
8}
lib/libc/wasi/libc-top-half/musl/src/process/execvp.c deleted-60
......@@ -1,60 +0,0 @@
1#include <stdlib.h>
2#include <string.h>
3#include <unistd.h>
4#include <errno.h>
5#include <limits.h>
6
7extern char **__environ;
8
9int __execvpe(const char *file, char *const argv[], char *const envp[])
10{
11 const char *p, *z, *path = getenv("PATH");
12 size_t l, k;
13 int seen_eacces = 0;
14
15 errno = ENOENT;
16 if (!*file) return -1;
17
18 if (strchr(file, '/'))
19 return execve(file, argv, envp);
20
21 if (!path) path = "/usr/local/bin:/bin:/usr/bin";
22 k = strnlen(file, NAME_MAX+1);
23 if (k > NAME_MAX) {
24 errno = ENAMETOOLONG;
25 return -1;
26 }
27 l = strnlen(path, PATH_MAX-1)+1;
28
29 for(p=path; ; p=z) {
30 char b[l+k+1];
31 z = __strchrnul(p, ':');
32 if (z-p >= l) {
33 if (!*z++) break;
34 continue;
35 }
36 memcpy(b, p, z-p);
37 b[z-p] = '/';
38 memcpy(b+(z-p)+(z>p), file, k+1);
39 execve(b, argv, envp);
40 switch (errno) {
41 case EACCES:
42 seen_eacces = 1;
43 case ENOENT:
44 case ENOTDIR:
45 break;
46 default:
47 return -1;
48 }
49 if (!*z++) break;
50 }
51 if (seen_eacces) errno = EACCES;
52 return -1;
53}
54
55int execvp(const char *file, char *const argv[])
56{
57 return __execvpe(file, argv, __environ);
58}
59
60weak_alias(__execvpe, execvpe);
lib/libc/wasi/libc-top-half/musl/src/process/fexecve.c deleted-16
......@@ -1,16 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include <errno.h>
4#include <fcntl.h>
5#include "syscall.h"
6
7int fexecve(int fd, char *const argv[], char *const envp[])
8{
9 int r = __syscall(SYS_execveat, fd, "", argv, envp, AT_EMPTY_PATH);
10 if (r != -ENOSYS) return __syscall_ret(r);
11 char buf[15 + 3*sizeof(int)];
12 __procfdname(buf, fd);
13 execve(buf, argv, envp);
14 if (errno == ENOENT) errno = EBADF;
15 return -1;
16}
lib/libc/wasi/libc-top-half/musl/src/process/fork.c deleted-86
......@@ -1,86 +0,0 @@
1#include <unistd.h>
2#include <errno.h>
3#include "libc.h"
4#include "lock.h"
5#include "pthread_impl.h"
6#include "fork_impl.h"
7
8static volatile int *const dummy_lockptr = 0;
9
10weak_alias(dummy_lockptr, __at_quick_exit_lockptr);
11weak_alias(dummy_lockptr, __atexit_lockptr);
12weak_alias(dummy_lockptr, __dlerror_lockptr);
13weak_alias(dummy_lockptr, __gettext_lockptr);
14weak_alias(dummy_lockptr, __locale_lockptr);
15weak_alias(dummy_lockptr, __random_lockptr);
16weak_alias(dummy_lockptr, __sem_open_lockptr);
17weak_alias(dummy_lockptr, __stdio_ofl_lockptr);
18weak_alias(dummy_lockptr, __syslog_lockptr);
19weak_alias(dummy_lockptr, __timezone_lockptr);
20weak_alias(dummy_lockptr, __bump_lockptr);
21
22weak_alias(dummy_lockptr, __vmlock_lockptr);
23
24static volatile int *const *const atfork_locks[] = {
25 &__at_quick_exit_lockptr,
26 &__atexit_lockptr,
27 &__dlerror_lockptr,
28 &__gettext_lockptr,
29 &__locale_lockptr,
30 &__random_lockptr,
31 &__sem_open_lockptr,
32 &__stdio_ofl_lockptr,
33 &__syslog_lockptr,
34 &__timezone_lockptr,
35 &__bump_lockptr,
36};
37
38static void dummy(int x) { }
39weak_alias(dummy, __fork_handler);
40weak_alias(dummy, __malloc_atfork);
41weak_alias(dummy, __ldso_atfork);
42
43static void dummy_0(void) { }
44weak_alias(dummy_0, __tl_lock);
45weak_alias(dummy_0, __tl_unlock);
46
47pid_t fork(void)
48{
49 sigset_t set;
50 __fork_handler(-1);
51 __block_app_sigs(&set);
52 int need_locks = libc.need_locks > 0;
53 if (need_locks) {
54 __ldso_atfork(-1);
55 __inhibit_ptc();
56 for (int i=0; i<sizeof atfork_locks/sizeof *atfork_locks; i++)
57 if (*atfork_locks[i]) LOCK(*atfork_locks[i]);
58 __malloc_atfork(-1);
59 __tl_lock();
60 }
61 pthread_t self=__pthread_self(), next=self->next;
62 pid_t ret = _Fork();
63 int errno_save = errno;
64 if (need_locks) {
65 if (!ret) {
66 for (pthread_t td=next; td!=self; td=td->next)
67 td->tid = -1;
68 if (__vmlock_lockptr) {
69 __vmlock_lockptr[0] = 0;
70 __vmlock_lockptr[1] = 0;
71 }
72 }
73 __tl_unlock();
74 __malloc_atfork(!ret);
75 for (int i=0; i<sizeof atfork_locks/sizeof *atfork_locks; i++)
76 if (*atfork_locks[i])
77 if (ret) UNLOCK(*atfork_locks[i]);
78 else **atfork_locks[i] = 0;
79 __release_ptc();
80 __ldso_atfork(!ret);
81 }
82 __restore_sigs(&set);
83 __fork_handler(!ret);
84 if (ret<0) errno = errno_save;
85 return ret;
86}
lib/libc/wasi/libc-top-half/musl/src/process/i386/vfork.s deleted-12
......@@ -1,12 +0,0 @@
1.global vfork
2.type vfork,@function
3vfork:
4 pop %edx
5 mov $190,%eax
6 int $128
7 push %edx
8 push %eax
9 .hidden __syscall_ret
10 call __syscall_ret
11 pop %edx
12 ret
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn.c deleted-214
......@@ -1,214 +0,0 @@
1#define _GNU_SOURCE
2#include <spawn.h>
3#include <sched.h>
4#include <unistd.h>
5#include <signal.h>
6#include <fcntl.h>
7#include <sys/wait.h>
8#include "syscall.h"
9#include "lock.h"
10#include "pthread_impl.h"
11#include "fdop.h"
12
13struct args {
14 int p[2];
15 sigset_t oldmask;
16 const char *path;
17 const posix_spawn_file_actions_t *fa;
18 const posix_spawnattr_t *restrict attr;
19 char *const *argv, *const *envp;
20};
21
22static int __sys_dup2(int old, int new)
23{
24#ifdef SYS_dup2
25 return __syscall(SYS_dup2, old, new);
26#else
27 return __syscall(SYS_dup3, old, new, 0);
28#endif
29}
30
31static int child(void *args_vp)
32{
33 int i, ret;
34 struct sigaction sa = {0};
35 struct args *args = args_vp;
36 int p = args->p[1];
37 const posix_spawn_file_actions_t *fa = args->fa;
38 const posix_spawnattr_t *restrict attr = args->attr;
39 sigset_t hset;
40
41 close(args->p[0]);
42
43 /* All signal dispositions must be either SIG_DFL or SIG_IGN
44 * before signals are unblocked. Otherwise a signal handler
45 * from the parent might get run in the child while sharing
46 * memory, with unpredictable and dangerous results. To
47 * reduce overhead, sigaction has tracked for us which signals
48 * potentially have a signal handler. */
49 __get_handler_set(&hset);
50 for (i=1; i<_NSIG; i++) {
51 if ((attr->__flags & POSIX_SPAWN_SETSIGDEF)
52 && sigismember(&attr->__def, i)) {
53 sa.sa_handler = SIG_DFL;
54 } else if (sigismember(&hset, i)) {
55 if (i-32<3U) {
56 sa.sa_handler = SIG_IGN;
57 } else {
58 __libc_sigaction(i, 0, &sa);
59 if (sa.sa_handler==SIG_IGN) continue;
60 sa.sa_handler = SIG_DFL;
61 }
62 } else {
63 continue;
64 }
65 __libc_sigaction(i, &sa, 0);
66 }
67
68 if (attr->__flags & POSIX_SPAWN_SETSID)
69 if ((ret=__syscall(SYS_setsid)) < 0)
70 goto fail;
71
72 if (attr->__flags & POSIX_SPAWN_SETPGROUP)
73 if ((ret=__syscall(SYS_setpgid, 0, attr->__pgrp)))
74 goto fail;
75
76 /* Use syscalls directly because the library functions attempt
77 * to do a multi-threaded synchronized id-change, which would
78 * trash the parent's state. */
79 if (attr->__flags & POSIX_SPAWN_RESETIDS)
80 if ((ret=__syscall(SYS_setgid, __syscall(SYS_getgid))) ||
81 (ret=__syscall(SYS_setuid, __syscall(SYS_getuid))) )
82 goto fail;
83
84 if (fa && fa->__actions) {
85 struct fdop *op;
86 int fd;
87 for (op = fa->__actions; op->next; op = op->next);
88 for (; op; op = op->prev) {
89 /* It's possible that a file operation would clobber
90 * the pipe fd used for synchronizing with the
91 * parent. To avoid that, we dup the pipe onto
92 * an unoccupied fd. */
93 if (op->fd == p) {
94 ret = __syscall(SYS_dup, p);
95 if (ret < 0) goto fail;
96 __syscall(SYS_close, p);
97 p = ret;
98 }
99 switch(op->cmd) {
100 case FDOP_CLOSE:
101 __syscall(SYS_close, op->fd);
102 break;
103 case FDOP_DUP2:
104 fd = op->srcfd;
105 if (fd == p) {
106 ret = -EBADF;
107 goto fail;
108 }
109 if (fd != op->fd) {
110 if ((ret=__sys_dup2(fd, op->fd))<0)
111 goto fail;
112 } else {
113 ret = __syscall(SYS_fcntl, fd, F_GETFD);
114 ret = __syscall(SYS_fcntl, fd, F_SETFD,
115 ret & ~FD_CLOEXEC);
116 if (ret<0)
117 goto fail;
118 }
119 break;
120 case FDOP_OPEN:
121 fd = __sys_open(op->path, op->oflag, op->mode);
122 if ((ret=fd) < 0) goto fail;
123 if (fd != op->fd) {
124 if ((ret=__sys_dup2(fd, op->fd))<0)
125 goto fail;
126 __syscall(SYS_close, fd);
127 }
128 break;
129 case FDOP_CHDIR:
130 ret = __syscall(SYS_chdir, op->path);
131 if (ret<0) goto fail;
132 break;
133 case FDOP_FCHDIR:
134 ret = __syscall(SYS_fchdir, op->fd);
135 if (ret<0) goto fail;
136 break;
137 }
138 }
139 }
140
141 /* Close-on-exec flag may have been lost if we moved the pipe
142 * to a different fd. We don't use F_DUPFD_CLOEXEC above because
143 * it would fail on older kernels and atomicity is not needed --
144 * in this process there are no threads or signal handlers. */
145 __syscall(SYS_fcntl, p, F_SETFD, FD_CLOEXEC);
146
147 pthread_sigmask(SIG_SETMASK, (attr->__flags & POSIX_SPAWN_SETSIGMASK)
148 ? &attr->__mask : &args->oldmask, 0);
149
150 int (*exec)(const char *, char *const *, char *const *) =
151 attr->__fn ? (int (*)())attr->__fn : execve;
152
153 exec(args->path, args->argv, args->envp);
154 ret = -errno;
155
156fail:
157 /* Since sizeof errno < PIPE_BUF, the write is atomic. */
158 ret = -ret;
159 if (ret) while (__syscall(SYS_write, p, &ret, sizeof ret) < 0);
160 _exit(127);
161}
162
163
164int posix_spawn(pid_t *restrict res, const char *restrict path,
165 const posix_spawn_file_actions_t *fa,
166 const posix_spawnattr_t *restrict attr,
167 char *const argv[restrict], char *const envp[restrict])
168{
169 pid_t pid;
170 char stack[1024+PATH_MAX];
171 int ec=0, cs;
172 struct args args;
173
174 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
175
176 args.path = path;
177 args.fa = fa;
178 args.attr = attr ? attr : &(const posix_spawnattr_t){0};
179 args.argv = argv;
180 args.envp = envp;
181 pthread_sigmask(SIG_BLOCK, SIGALL_SET, &args.oldmask);
182
183 /* The lock guards both against seeing a SIGABRT disposition change
184 * by abort and against leaking the pipe fd to fork-without-exec. */
185 LOCK(__abort_lock);
186
187 if (pipe2(args.p, O_CLOEXEC)) {
188 UNLOCK(__abort_lock);
189 ec = errno;
190 goto fail;
191 }
192
193 pid = __clone(child, stack+sizeof stack,
194 CLONE_VM|CLONE_VFORK|SIGCHLD, &args);
195 close(args.p[1]);
196 UNLOCK(__abort_lock);
197
198 if (pid > 0) {
199 if (read(args.p[0], &ec, sizeof ec) != sizeof ec) ec = 0;
200 else waitpid(pid, &(int){0}, 0);
201 } else {
202 ec = -pid;
203 }
204
205 close(args.p[0]);
206
207 if (!ec && res) *res = pid;
208
209fail:
210 pthread_sigmask(SIG_SETMASK, &args.oldmask, 0);
211 pthread_setcancelstate(cs, 0);
212
213 return ec;
214}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_addchdir.c deleted-18
......@@ -1,18 +0,0 @@
1#include <spawn.h>
2#include <stdlib.h>
3#include <string.h>
4#include <errno.h>
5#include "fdop.h"
6
7int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *restrict fa, const char *restrict path)
8{
9 struct fdop *op = malloc(sizeof *op + strlen(path) + 1);
10 if (!op) return ENOMEM;
11 op->cmd = FDOP_CHDIR;
12 op->fd = -1;
13 strcpy(op->path, path);
14 if ((op->next = fa->__actions)) op->next->prev = op;
15 op->prev = 0;
16 fa->__actions = op;
17 return 0;
18}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_addclose.c deleted-17
......@@ -1,17 +0,0 @@
1#include <spawn.h>
2#include <stdlib.h>
3#include <errno.h>
4#include "fdop.h"
5
6int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *fa, int fd)
7{
8 if (fd < 0) return EBADF;
9 struct fdop *op = malloc(sizeof *op);
10 if (!op) return ENOMEM;
11 op->cmd = FDOP_CLOSE;
12 op->fd = fd;
13 if ((op->next = fa->__actions)) op->next->prev = op;
14 op->prev = 0;
15 fa->__actions = op;
16 return 0;
17}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_adddup2.c deleted-18
......@@ -1,18 +0,0 @@
1#include <spawn.h>
2#include <stdlib.h>
3#include <errno.h>
4#include "fdop.h"
5
6int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *fa, int srcfd, int fd)
7{
8 if (srcfd < 0 || fd < 0) return EBADF;
9 struct fdop *op = malloc(sizeof *op);
10 if (!op) return ENOMEM;
11 op->cmd = FDOP_DUP2;
12 op->srcfd = srcfd;
13 op->fd = fd;
14 if ((op->next = fa->__actions)) op->next->prev = op;
15 op->prev = 0;
16 fa->__actions = op;
17 return 0;
18}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_addfchdir.c deleted-18
......@@ -1,18 +0,0 @@
1#include <spawn.h>
2#include <stdlib.h>
3#include <string.h>
4#include <errno.h>
5#include "fdop.h"
6
7int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *fa, int fd)
8{
9 if (fd < 0) return EBADF;
10 struct fdop *op = malloc(sizeof *op);
11 if (!op) return ENOMEM;
12 op->cmd = FDOP_FCHDIR;
13 op->fd = fd;
14 if ((op->next = fa->__actions)) op->next->prev = op;
15 op->prev = 0;
16 fa->__actions = op;
17 return 0;
18}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_addopen.c deleted-21
......@@ -1,21 +0,0 @@
1#include <spawn.h>
2#include <stdlib.h>
3#include <string.h>
4#include <errno.h>
5#include "fdop.h"
6
7int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *restrict fa, int fd, const char *restrict path, int flags, mode_t mode)
8{
9 if (fd < 0) return EBADF;
10 struct fdop *op = malloc(sizeof *op + strlen(path) + 1);
11 if (!op) return ENOMEM;
12 op->cmd = FDOP_OPEN;
13 op->fd = fd;
14 op->oflag = flags;
15 op->mode = mode;
16 strcpy(op->path, path);
17 if ((op->next = fa->__actions)) op->next->prev = op;
18 op->prev = 0;
19 fa->__actions = op;
20 return 0;
21}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_destroy.c deleted-14
......@@ -1,14 +0,0 @@
1#include <spawn.h>
2#include <stdlib.h>
3#include "fdop.h"
4
5int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *fa)
6{
7 struct fdop *op = fa->__actions, *next;
8 while (op) {
9 next = op->next;
10 free(op);
11 op = next;
12 }
13 return 0;
14}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_init.c deleted-7
......@@ -1,7 +0,0 @@
1#include <spawn.h>
2
3int posix_spawn_file_actions_init(posix_spawn_file_actions_t *fa)
4{
5 fa->__actions = 0;
6 return 0;
7}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_destroy.c deleted-6
......@@ -1,6 +0,0 @@
1#include <spawn.h>
2
3int posix_spawnattr_destroy(posix_spawnattr_t *attr)
4{
5 return 0;
6}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_getflags.c deleted-7
......@@ -1,7 +0,0 @@
1#include <spawn.h>
2
3int posix_spawnattr_getflags(const posix_spawnattr_t *restrict attr, short *restrict flags)
4{
5 *flags = attr->__flags;
6 return 0;
7}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_getpgroup.c deleted-7
......@@ -1,7 +0,0 @@
1#include <spawn.h>
2
3int posix_spawnattr_getpgroup(const posix_spawnattr_t *restrict attr, pid_t *restrict pgrp)
4{
5 *pgrp = attr->__pgrp;
6 return 0;
7}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_getsigdefault.c deleted-7
......@@ -1,7 +0,0 @@
1#include <spawn.h>
2
3int posix_spawnattr_getsigdefault(const posix_spawnattr_t *restrict attr, sigset_t *restrict def)
4{
5 *def = attr->__def;
6 return 0;
7}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_getsigmask.c deleted-7
......@@ -1,7 +0,0 @@
1#include <spawn.h>
2
3int posix_spawnattr_getsigmask(const posix_spawnattr_t *restrict attr, sigset_t *restrict mask)
4{
5 *mask = attr->__mask;
6 return 0;
7}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_init.c deleted-7
......@@ -1,7 +0,0 @@
1#include <spawn.h>
2
3int posix_spawnattr_init(posix_spawnattr_t *attr)
4{
5 *attr = (posix_spawnattr_t){ 0 };
6 return 0;
7}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_sched.c deleted-25
......@@ -1,25 +0,0 @@
1#include <spawn.h>
2#include <sched.h>
3#include <errno.h>
4
5int posix_spawnattr_getschedparam(const posix_spawnattr_t *restrict attr,
6 struct sched_param *restrict schedparam)
7{
8 return ENOSYS;
9}
10
11int posix_spawnattr_setschedparam(posix_spawnattr_t *restrict attr,
12 const struct sched_param *restrict schedparam)
13{
14 return ENOSYS;
15}
16
17int posix_spawnattr_getschedpolicy(const posix_spawnattr_t *restrict attr, int *restrict policy)
18{
19 return ENOSYS;
20}
21
22int posix_spawnattr_setschedpolicy(posix_spawnattr_t *attr, int policy)
23{
24 return ENOSYS;
25}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_setflags.c deleted-18
......@@ -1,18 +0,0 @@
1#include <spawn.h>
2#include <errno.h>
3
4int posix_spawnattr_setflags(posix_spawnattr_t *attr, short flags)
5{
6 const unsigned all_flags =
7 POSIX_SPAWN_RESETIDS |
8 POSIX_SPAWN_SETPGROUP |
9 POSIX_SPAWN_SETSIGDEF |
10 POSIX_SPAWN_SETSIGMASK |
11 POSIX_SPAWN_SETSCHEDPARAM |
12 POSIX_SPAWN_SETSCHEDULER |
13 POSIX_SPAWN_USEVFORK |
14 POSIX_SPAWN_SETSID;
15 if (flags & ~all_flags) return EINVAL;
16 attr->__flags = flags;
17 return 0;
18}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_setpgroup.c deleted-7
......@@ -1,7 +0,0 @@
1#include <spawn.h>
2
3int posix_spawnattr_setpgroup(posix_spawnattr_t *attr, pid_t pgrp)
4{
5 attr->__pgrp = pgrp;
6 return 0;
7}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_setsigdefault.c deleted-7
......@@ -1,7 +0,0 @@
1#include <spawn.h>
2
3int posix_spawnattr_setsigdefault(posix_spawnattr_t *restrict attr, const sigset_t *restrict def)
4{
5 attr->__def = *def;
6 return 0;
7}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_setsigmask.c deleted-7
......@@ -1,7 +0,0 @@
1#include <spawn.h>
2
3int posix_spawnattr_setsigmask(posix_spawnattr_t *restrict attr, const sigset_t *restrict mask)
4{
5 attr->__mask = *mask;
6 return 0;
7}
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnp.c deleted-13
......@@ -1,13 +0,0 @@
1#include <spawn.h>
2#include <unistd.h>
3
4int posix_spawnp(pid_t *restrict res, const char *restrict file,
5 const posix_spawn_file_actions_t *fa,
6 const posix_spawnattr_t *restrict attr,
7 char *const argv[restrict], char *const envp[restrict])
8{
9 posix_spawnattr_t spawnp_attr = { 0 };
10 if (attr) spawnp_attr = *attr;
11 spawnp_attr.__fn = (void *)__execvpe;
12 return posix_spawn(res, file, fa, &spawnp_attr, argv, envp);
13}
lib/libc/wasi/libc-top-half/musl/src/process/s390x/vfork.s deleted-6
......@@ -1,6 +0,0 @@
1 .global vfork
2 .type vfork,%function
3vfork:
4 svc 190
5 .hidden __syscall_ret
6 jg __syscall_ret
lib/libc/wasi/libc-top-half/musl/src/process/sh/vfork.s deleted-20
......@@ -1,20 +0,0 @@
1.global vfork
2.type vfork,@function
3vfork:
4 mov #95, r3
5 add r3, r3
6
7 trapa #31
8 or r0, r0
9 or r0, r0
10 or r0, r0
11 or r0, r0
12 or r0, r0
13
14 mov r0, r4
15 mov.l 1f, r0
162: braf r0
17 nop
18 .align 2
19 .hidden __syscall_ret
201: .long __syscall_ret@PLT-(2b+4-.)
lib/libc/wasi/libc-top-half/musl/src/process/system.c deleted-46
......@@ -1,46 +0,0 @@
1#include <unistd.h>
2#include <stdlib.h>
3#include <signal.h>
4#include <sys/wait.h>
5#include <spawn.h>
6#include <errno.h>
7#include "pthread_impl.h"
8
9extern char **__environ;
10
11int system(const char *cmd)
12{
13 pid_t pid;
14 sigset_t old, reset;
15 struct sigaction sa = { .sa_handler = SIG_IGN }, oldint, oldquit;
16 int status = -1, ret;
17 posix_spawnattr_t attr;
18
19 pthread_testcancel();
20
21 if (!cmd) return 1;
22
23 sigaction(SIGINT, &sa, &oldint);
24 sigaction(SIGQUIT, &sa, &oldquit);
25 sigaddset(&sa.sa_mask, SIGCHLD);
26 sigprocmask(SIG_BLOCK, &sa.sa_mask, &old);
27
28 sigemptyset(&reset);
29 if (oldint.sa_handler != SIG_IGN) sigaddset(&reset, SIGINT);
30 if (oldquit.sa_handler != SIG_IGN) sigaddset(&reset, SIGQUIT);
31 posix_spawnattr_init(&attr);
32 posix_spawnattr_setsigmask(&attr, &old);
33 posix_spawnattr_setsigdefault(&attr, &reset);
34 posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGDEF|POSIX_SPAWN_SETSIGMASK);
35 ret = posix_spawn(&pid, "/bin/sh", 0, &attr,
36 (char *[]){"sh", "-c", (char *)cmd, 0}, __environ);
37 posix_spawnattr_destroy(&attr);
38
39 if (!ret) while (waitpid(pid, &status, 0)<0 && errno == EINTR);
40 sigaction(SIGINT, &oldint, NULL);
41 sigaction(SIGQUIT, &oldquit, NULL);
42 sigprocmask(SIG_SETMASK, &old, NULL);
43
44 if (ret) errno = ret;
45 return status;
46}
lib/libc/wasi/libc-top-half/musl/src/process/vfork.c deleted-14
......@@ -1,14 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include <signal.h>
4#include "syscall.h"
5
6pid_t vfork(void)
7{
8 /* vfork syscall cannot be made from C code */
9#ifdef SYS_fork
10 return syscall(SYS_fork);
11#else
12 return syscall(SYS_clone, SIGCHLD, 0);
13#endif
14}
lib/libc/wasi/libc-top-half/musl/src/process/wait.c deleted-6
......@@ -1,6 +0,0 @@
1#include <sys/wait.h>
2
3pid_t wait(int *status)
4{
5 return waitpid((pid_t)-1, status, 0);
6}
lib/libc/wasi/libc-top-half/musl/src/process/waitid.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/wait.h>
2#include "syscall.h"
3
4int waitid(idtype_t type, id_t id, siginfo_t *info, int options)
5{
6 return syscall_cp(SYS_waitid, type, id, info, options, 0);
7}
lib/libc/wasi/libc-top-half/musl/src/process/waitpid.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/wait.h>
2#include "syscall.h"
3
4pid_t waitpid(pid_t pid, int *status, int options)
5{
6 return syscall_cp(SYS_wait4, pid, status, options, 0);
7}
lib/libc/wasi/libc-top-half/musl/src/process/x32/vfork.s deleted-10
......@@ -1,10 +0,0 @@
1.global vfork
2.type vfork,@function
3vfork:
4 pop %rdx
5 mov $0x4000003a,%eax /* SYS_vfork */
6 syscall
7 push %rdx
8 mov %rax,%rdi
9 .hidden __syscall_ret
10 jmp __syscall_ret
lib/libc/wasi/libc-top-half/musl/src/process/x86_64/vfork.s deleted-10
......@@ -1,10 +0,0 @@
1.global vfork
2.type vfork,@function
3vfork:
4 pop %rdx
5 mov $58,%eax
6 syscall
7 push %rdx
8 mov %rax,%rdi
9 .hidden __syscall_ret
10 jmp __syscall_ret
lib/libc/wasi/libc-top-half/musl/src/sched/affinity.c deleted-33
......@@ -1,33 +0,0 @@
1#define _GNU_SOURCE
2#include <sched.h>
3#include <string.h>
4#include "pthread_impl.h"
5#include "syscall.h"
6
7int sched_setaffinity(pid_t tid, size_t size, const cpu_set_t *set)
8{
9 return syscall(SYS_sched_setaffinity, tid, size, set);
10}
11
12int pthread_setaffinity_np(pthread_t td, size_t size, const cpu_set_t *set)
13{
14 return -__syscall(SYS_sched_setaffinity, td->tid, size, set);
15}
16
17static int do_getaffinity(pid_t tid, size_t size, cpu_set_t *set)
18{
19 long ret = __syscall(SYS_sched_getaffinity, tid, size, set);
20 if (ret < 0) return ret;
21 if (ret < size) memset((char *)set+ret, 0, size-ret);
22 return 0;
23}
24
25int sched_getaffinity(pid_t tid, size_t size, cpu_set_t *set)
26{
27 return __syscall_ret(do_getaffinity(tid, size, set));
28}
29
30int pthread_getaffinity_np(pthread_t td, size_t size, cpu_set_t *set)
31{
32 return -do_getaffinity(td->tid, size, set);
33}
lib/libc/wasi/libc-top-half/musl/src/sched/sched_cpucount.c deleted-11
......@@ -1,11 +0,0 @@
1#define _GNU_SOURCE
2#include <sched.h>
3
4int __sched_cpucount(size_t size, const cpu_set_t *set)
5{
6 size_t i, j, cnt=0;
7 const unsigned char *p = (const void *)set;
8 for (i=0; i<size; i++) for (j=0; j<8; j++)
9 if (p[i] & (1<<j)) cnt++;
10 return cnt;
11}
lib/libc/wasi/libc-top-half/musl/src/sched/sched_get_priority_max.c deleted-12
......@@ -1,12 +0,0 @@
1#include <sched.h>
2#include "syscall.h"
3
4int sched_get_priority_max(int policy)
5{
6 return syscall(SYS_sched_get_priority_max, policy);
7}
8
9int sched_get_priority_min(int policy)
10{
11 return syscall(SYS_sched_get_priority_min, policy);
12}
lib/libc/wasi/libc-top-half/musl/src/sched/sched_getcpu.c deleted-42
......@@ -1,42 +0,0 @@
1#define _GNU_SOURCE
2#include <errno.h>
3#include <sched.h>
4#include "syscall.h"
5#include "atomic.h"
6
7#ifdef VDSO_GETCPU_SYM
8
9static void *volatile vdso_func;
10
11typedef long (*getcpu_f)(unsigned *, unsigned *, void *);
12
13static long getcpu_init(unsigned *cpu, unsigned *node, void *unused)
14{
15 void *p = __vdsosym(VDSO_GETCPU_VER, VDSO_GETCPU_SYM);
16 getcpu_f f = (getcpu_f)p;
17 a_cas_p(&vdso_func, (void *)getcpu_init, p);
18 return f ? f(cpu, node, unused) : -ENOSYS;
19}
20
21static void *volatile vdso_func = (void *)getcpu_init;
22
23#endif
24
25int sched_getcpu(void)
26{
27 int r;
28 unsigned cpu;
29
30#ifdef VDSO_GETCPU_SYM
31 getcpu_f f = (getcpu_f)vdso_func;
32 if (f) {
33 r = f(&cpu, 0, 0);
34 if (!r) return cpu;
35 if (r != -ENOSYS) return __syscall_ret(r);
36 }
37#endif
38
39 r = __syscall(SYS_getcpu, &cpu, 0, 0);
40 if (!r) return cpu;
41 return __syscall_ret(r);
42}
lib/libc/wasi/libc-top-half/musl/src/sched/sched_getparam.c deleted-8
......@@ -1,8 +0,0 @@
1#include <sched.h>
2#include <errno.h>
3#include "syscall.h"
4
5int sched_getparam(pid_t pid, struct sched_param *param)
6{
7 return __syscall_ret(-ENOSYS);
8}
lib/libc/wasi/libc-top-half/musl/src/sched/sched_getscheduler.c deleted-8
......@@ -1,8 +0,0 @@
1#include <sched.h>
2#include <errno.h>
3#include "syscall.h"
4
5int sched_getscheduler(pid_t pid)
6{
7 return __syscall_ret(-ENOSYS);
8}
lib/libc/wasi/libc-top-half/musl/src/sched/sched_rr_get_interval.c deleted-21
......@@ -1,21 +0,0 @@
1#include <sched.h>
2#include "syscall.h"
3
4int sched_rr_get_interval(pid_t pid, struct timespec *ts)
5{
6#ifdef SYS_sched_rr_get_interval_time64
7 /* On a 32-bit arch, use the old syscall if it exists. */
8 if (SYS_sched_rr_get_interval != SYS_sched_rr_get_interval_time64) {
9 long ts32[2];
10 int r = __syscall(SYS_sched_rr_get_interval, pid, ts32);
11 if (!r) {
12 ts->tv_sec = ts32[0];
13 ts->tv_nsec = ts32[1];
14 }
15 return __syscall_ret(r);
16 }
17#endif
18 /* If reaching this point, it's a 64-bit arch or time64-only
19 * 32-bit arch and we can get result directly into timespec. */
20 return syscall(SYS_sched_rr_get_interval, pid, ts);
21}
lib/libc/wasi/libc-top-half/musl/src/sched/sched_setparam.c deleted-8
......@@ -1,8 +0,0 @@
1#include <sched.h>
2#include <errno.h>
3#include "syscall.h"
4
5int sched_setparam(pid_t pid, const struct sched_param *param)
6{
7 return __syscall_ret(-ENOSYS);
8}
lib/libc/wasi/libc-top-half/musl/src/sched/sched_setscheduler.c deleted-8
......@@ -1,8 +0,0 @@
1#include <sched.h>
2#include <errno.h>
3#include "syscall.h"
4
5int sched_setscheduler(pid_t pid, int sched, const struct sched_param *param)
6{
7 return __syscall_ret(-ENOSYS);
8}
lib/libc/wasi/libc-top-half/musl/src/sched/sched_yield.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sched.h>
2#include "syscall.h"
3
4int sched_yield()
5{
6 return syscall(SYS_sched_yield);
7}
lib/libc/wasi/libc-top-half/musl/src/select/poll.c deleted-15
......@@ -1,15 +0,0 @@
1#include <poll.h>
2#include <time.h>
3#include <signal.h>
4#include "syscall.h"
5
6int poll(struct pollfd *fds, nfds_t n, int timeout)
7{
8#ifdef SYS_poll
9 return syscall_cp(SYS_poll, fds, n, timeout);
10#else
11 return syscall_cp(SYS_ppoll, fds, n, timeout>=0 ?
12 &((struct timespec){ .tv_sec = timeout/1000,
13 .tv_nsec = timeout%1000*1000000 }) : 0, 0, _NSIG/8);
14#endif
15}
lib/libc/wasi/libc-top-half/musl/src/select/pselect.c deleted-26
......@@ -1,26 +0,0 @@
1#include <sys/select.h>
2#include <signal.h>
3#include <stdint.h>
4#include <errno.h>
5#include "syscall.h"
6
7#define IS32BIT(x) !((x)+0x80000000ULL>>32)
8#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
9
10int 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)
11{
12 syscall_arg_t data[2] = { (uintptr_t)mask, _NSIG/8 };
13 time_t s = ts ? ts->tv_sec : 0;
14 long ns = ts ? ts->tv_nsec : 0;
15#ifdef SYS_pselect6_time64
16 int r = -ENOSYS;
17 if (SYS_pselect6 == SYS_pselect6_time64 || !IS32BIT(s))
18 r = __syscall_cp(SYS_pselect6_time64, n, rfds, wfds, efds,
19 ts ? ((long long[]){s, ns}) : 0, data);
20 if (SYS_pselect6 == SYS_pselect6_time64 || r!=-ENOSYS)
21 return __syscall_ret(r);
22 s = CLAMP(s);
23#endif
24 return syscall_cp(SYS_pselect6, n, rfds, wfds, efds,
25 ts ? ((long[]){s, ns}) : 0, data);
26}
lib/libc/wasi/libc-top-half/musl/src/select/select.c deleted-44
......@@ -1,44 +0,0 @@
1#include <sys/select.h>
2#include <signal.h>
3#include <stdint.h>
4#include <errno.h>
5#include "syscall.h"
6
7#define IS32BIT(x) !((x)+0x80000000ULL>>32)
8#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
9
10int select(int n, fd_set *restrict rfds, fd_set *restrict wfds, fd_set *restrict efds, struct timeval *restrict tv)
11{
12 time_t s = tv ? tv->tv_sec : 0;
13 suseconds_t us = tv ? tv->tv_usec : 0;
14 long ns;
15 const time_t max_time = (1ULL<<8*sizeof(time_t)-1)-1;
16
17 if (s<0 || us<0) return __syscall_ret(-EINVAL);
18 if (us/1000000 > max_time - s) {
19 s = max_time;
20 us = 999999;
21 ns = 999999999;
22 } else {
23 s += us/1000000;
24 us %= 1000000;
25 ns = us*1000;
26 }
27
28#ifdef SYS_pselect6_time64
29 int r = -ENOSYS;
30 if (SYS_pselect6 == SYS_pselect6_time64 || !IS32BIT(s))
31 r = __syscall_cp(SYS_pselect6_time64, n, rfds, wfds, efds,
32 tv ? ((long long[]){s, ns}) : 0,
33 ((syscall_arg_t[]){ 0, _NSIG/8 }));
34 if (SYS_pselect6 == SYS_pselect6_time64 || r!=-ENOSYS)
35 return __syscall_ret(r);
36#endif
37#ifdef SYS_select
38 return syscall_cp(SYS_select, n, rfds, wfds, efds,
39 tv ? ((long[]){s, us}) : 0);
40#else
41 return syscall_cp(SYS_pselect6, n, rfds, wfds, efds,
42 tv ? ((long[]){s, ns}) : 0, ((syscall_arg_t[]){ 0, _NSIG/8 }));
43#endif
44}
lib/libc/wasi/libc-top-half/musl/src/setjmp/aarch64/longjmp.s deleted-23
......@@ -1,23 +0,0 @@
1.global _longjmp
2.global longjmp
3.type _longjmp,%function
4.type longjmp,%function
5_longjmp:
6longjmp:
7 // IHI0055B_aapcs64.pdf 5.1.1, 5.1.2 callee saved registers
8 ldp x19, x20, [x0,#0]
9 ldp x21, x22, [x0,#16]
10 ldp x23, x24, [x0,#32]
11 ldp x25, x26, [x0,#48]
12 ldp x27, x28, [x0,#64]
13 ldp x29, x30, [x0,#80]
14 ldr x2, [x0,#104]
15 mov sp, x2
16 ldp d8 , d9, [x0,#112]
17 ldp d10, d11, [x0,#128]
18 ldp d12, d13, [x0,#144]
19 ldp d14, d15, [x0,#160]
20
21 cmp w1, 0
22 csinc w0, w1, wzr, ne
23 br x30
lib/libc/wasi/libc-top-half/musl/src/setjmp/aarch64/setjmp.s deleted-24
......@@ -1,24 +0,0 @@
1.global __setjmp
2.global _setjmp
3.global setjmp
4.type __setjmp,@function
5.type _setjmp,@function
6.type setjmp,@function
7__setjmp:
8_setjmp:
9setjmp:
10 // IHI0055B_aapcs64.pdf 5.1.1, 5.1.2 callee saved registers
11 stp x19, x20, [x0,#0]
12 stp x21, x22, [x0,#16]
13 stp x23, x24, [x0,#32]
14 stp x25, x26, [x0,#48]
15 stp x27, x28, [x0,#64]
16 stp x29, x30, [x0,#80]
17 mov x2, sp
18 str x2, [x0,#104]
19 stp d8, d9, [x0,#112]
20 stp d10, d11, [x0,#128]
21 stp d12, d13, [x0,#144]
22 stp d14, d15, [x0,#160]
23 mov x0, #0
24 ret
lib/libc/wasi/libc-top-half/musl/src/setjmp/i386/longjmp.s deleted-16
......@@ -1,16 +0,0 @@
1.global _longjmp
2.global longjmp
3.type _longjmp,@function
4.type longjmp,@function
5_longjmp:
6longjmp:
7 mov 4(%esp),%edx
8 mov 8(%esp),%eax
9 cmp $1,%eax
10 adc $0, %al
11 mov (%edx),%ebx
12 mov 4(%edx),%esi
13 mov 8(%edx),%edi
14 mov 12(%edx),%ebp
15 mov 16(%edx),%esp
16 jmp *20(%edx)
lib/libc/wasi/libc-top-half/musl/src/setjmp/i386/setjmp.s deleted-23
......@@ -1,23 +0,0 @@
1.global ___setjmp
2.hidden ___setjmp
3.global __setjmp
4.global _setjmp
5.global setjmp
6.type __setjmp,@function
7.type _setjmp,@function
8.type setjmp,@function
9___setjmp:
10__setjmp:
11_setjmp:
12setjmp:
13 mov 4(%esp), %eax
14 mov %ebx, (%eax)
15 mov %esi, 4(%eax)
16 mov %edi, 8(%eax)
17 mov %ebp, 12(%eax)
18 lea 4(%esp), %ecx
19 mov %ecx, 16(%eax)
20 mov (%esp), %ecx
21 mov %ecx, 20(%eax)
22 xor %eax, %eax
23 ret
lib/libc/wasi/libc-top-half/musl/src/setjmp/longjmp.c deleted
lib/libc/wasi/libc-top-half/musl/src/setjmp/m68k/longjmp.s deleted-14
......@@ -1,14 +0,0 @@
1.global _longjmp
2.global longjmp
3.type _longjmp,@function
4.type longjmp,@function
5_longjmp:
6longjmp:
7 movea.l 4(%sp),%a0
8 move.l 8(%sp),%d0
9 bne 1f
10 move.l #1,%d0
111: movem.l (%a0),%d2-%d7/%a2-%a7
12 fmovem.x 52(%a0),%fp2-%fp7
13 move.l 48(%a0),(%sp)
14 rts
lib/libc/wasi/libc-top-half/musl/src/setjmp/m68k/setjmp.s deleted-18
......@@ -1,18 +0,0 @@
1.global ___setjmp
2.hidden ___setjmp
3.global __setjmp
4.global _setjmp
5.global setjmp
6.type __setjmp,@function
7.type _setjmp,@function
8.type setjmp,@function
9___setjmp:
10__setjmp:
11_setjmp:
12setjmp:
13 movea.l 4(%sp),%a0
14 movem.l %d2-%d7/%a2-%a7,(%a0)
15 move.l (%sp),48(%a0)
16 fmovem.x %fp2-%fp7,52(%a0)
17 clr.l %d0
18 rts
lib/libc/wasi/libc-top-half/musl/src/setjmp/microblaze/longjmp.s deleted-29
......@@ -1,29 +0,0 @@
1.global _longjmp
2.global longjmp
3.type _longjmp,@function
4.type longjmp,@function
5_longjmp:
6longjmp:
7 addi r3, r6, 0
8 bnei r3, 1f
9 addi r3, r3, 1
101: lwi r1, r5, 0
11 lwi r15, r5, 4
12 lwi r2, r5, 8
13 lwi r13, r5, 12
14 lwi r18, r5, 16
15 lwi r19, r5, 20
16 lwi r20, r5, 24
17 lwi r21, r5, 28
18 lwi r22, r5, 32
19 lwi r23, r5, 36
20 lwi r24, r5, 40
21 lwi r25, r5, 44
22 lwi r26, r5, 48
23 lwi r27, r5, 52
24 lwi r28, r5, 56
25 lwi r29, r5, 60
26 lwi r30, r5, 64
27 lwi r31, r5, 68
28 rtsd r15, 8
29 nop
lib/libc/wasi/libc-top-half/musl/src/setjmp/microblaze/setjmp.s deleted-32
......@@ -1,32 +0,0 @@
1.global ___setjmp
2.hidden ___setjmp
3.global __setjmp
4.global _setjmp
5.global setjmp
6.type __setjmp,@function
7.type _setjmp,@function
8.type setjmp,@function
9___setjmp:
10__setjmp:
11_setjmp:
12setjmp:
13 swi r1, r5, 0
14 swi r15, r5, 4
15 swi r2, r5, 8
16 swi r13, r5, 12
17 swi r18, r5, 16
18 swi r19, r5, 20
19 swi r20, r5, 24
20 swi r21, r5, 28
21 swi r22, r5, 32
22 swi r23, r5, 36
23 swi r24, r5, 40
24 swi r25, r5, 44
25 swi r26, r5, 48
26 swi r27, r5, 52
27 swi r28, r5, 56
28 swi r29, r5, 60
29 swi r30, r5, 64
30 swi r31, r5, 68
31 rtsd r15, 8
32 ori r3, r0, 0
lib/libc/wasi/libc-top-half/musl/src/setjmp/or1k/longjmp.s deleted-25
......@@ -1,25 +0,0 @@
1.global _longjmp
2.global longjmp
3.type _longjmp,@function
4.type longjmp,@function
5_longjmp:
6longjmp:
7 l.sfeqi r4, 0
8 l.bnf 1f
9 l.addi r11, r4,0
10 l.ori r11, r0, 1
111: l.lwz r1, 0(r3)
12 l.lwz r2, 4(r3)
13 l.lwz r9, 8(r3)
14 l.lwz r10, 12(r3)
15 l.lwz r14, 16(r3)
16 l.lwz r16, 20(r3)
17 l.lwz r18, 24(r3)
18 l.lwz r20, 28(r3)
19 l.lwz r22, 32(r3)
20 l.lwz r24, 36(r3)
21 l.lwz r26, 40(r3)
22 l.lwz r28, 44(r3)
23 l.lwz r30, 48(r3)
24 l.jr r9
25 l.nop
lib/libc/wasi/libc-top-half/musl/src/setjmp/or1k/setjmp.s deleted-27
......@@ -1,27 +0,0 @@
1.global ___setjmp
2.hidden ___setjmp
3.global __setjmp
4.global _setjmp
5.global setjmp
6.type __setjmp,@function
7.type _setjmp,@function
8.type setjmp,@function
9___setjmp:
10__setjmp:
11_setjmp:
12setjmp:
13 l.sw 0(r3), r1
14 l.sw 4(r3), r2
15 l.sw 8(r3), r9
16 l.sw 12(r3), r10
17 l.sw 16(r3), r14
18 l.sw 20(r3), r16
19 l.sw 24(r3), r18
20 l.sw 28(r3), r20
21 l.sw 32(r3), r22
22 l.sw 36(r3), r24
23 l.sw 40(r3), r26
24 l.sw 44(r3), r28
25 l.sw 48(r3), r30
26 l.jr r9
27 l.ori r11,r0,0
lib/libc/wasi/libc-top-half/musl/src/setjmp/powerpc64/longjmp.s deleted-81
......@@ -1,81 +0,0 @@
1 .global _longjmp
2 .global longjmp
3 .type _longjmp,@function
4 .type longjmp,@function
5_longjmp:
6longjmp:
7 # 0) move old return address into the link register
8 ld 0, 0*8(3)
9 mtlr 0
10 # 1) restore cr
11 ld 0, 1*8(3)
12 mtcr 0
13 # 2) restore SP
14 ld 1, 2*8(3)
15 # 3) restore TOC into both r2 and the caller's stack.
16 # Which location is required depends on whether setjmp was called
17 # locally or non-locally, but it's always safe to restore to both.
18 ld 2, 3*8(3)
19 std 2, 24(1)
20 # 4) restore r14-r31
21 ld 14, 4*8(3)
22 ld 15, 5*8(3)
23 ld 16, 6*8(3)
24 ld 17, 7*8(3)
25 ld 18, 8*8(3)
26 ld 19, 9*8(3)
27 ld 20, 10*8(3)
28 ld 21, 11*8(3)
29 ld 22, 12*8(3)
30 ld 23, 13*8(3)
31 ld 24, 14*8(3)
32 ld 25, 15*8(3)
33 ld 26, 16*8(3)
34 ld 27, 17*8(3)
35 ld 28, 18*8(3)
36 ld 29, 19*8(3)
37 ld 30, 20*8(3)
38 ld 31, 21*8(3)
39 # 5) restore floating point registers f14-f31
40 lfd 14, 22*8(3)
41 lfd 15, 23*8(3)
42 lfd 16, 24*8(3)
43 lfd 17, 25*8(3)
44 lfd 18, 26*8(3)
45 lfd 19, 27*8(3)
46 lfd 20, 28*8(3)
47 lfd 21, 29*8(3)
48 lfd 22, 30*8(3)
49 lfd 23, 31*8(3)
50 lfd 24, 32*8(3)
51 lfd 25, 33*8(3)
52 lfd 26, 34*8(3)
53 lfd 27, 35*8(3)
54 lfd 28, 36*8(3)
55 lfd 29, 37*8(3)
56 lfd 30, 38*8(3)
57 lfd 31, 39*8(3)
58
59 # 6) restore vector registers v20-v31
60 addi 3, 3, 40*8
61 lvx 20, 0, 3 ; addi 3, 3, 16
62 lvx 21, 0, 3 ; addi 3, 3, 16
63 lvx 22, 0, 3 ; addi 3, 3, 16
64 lvx 23, 0, 3 ; addi 3, 3, 16
65 lvx 24, 0, 3 ; addi 3, 3, 16
66 lvx 25, 0, 3 ; addi 3, 3, 16
67 lvx 26, 0, 3 ; addi 3, 3, 16
68 lvx 27, 0, 3 ; addi 3, 3, 16
69 lvx 28, 0, 3 ; addi 3, 3, 16
70 lvx 29, 0, 3 ; addi 3, 3, 16
71 lvx 30, 0, 3 ; addi 3, 3, 16
72 lvx 31, 0, 3
73
74 # 7) return r4 ? r4 : 1
75 mr 3, 4
76 cmpwi cr7, 4, 0
77 bne cr7, 1f
78 li 3, 1
791:
80 blr
81
lib/libc/wasi/libc-top-half/musl/src/setjmp/powerpc64/setjmp.s deleted-89
......@@ -1,89 +0,0 @@
1 .global __setjmp
2 .global _setjmp
3 .global setjmp
4 .type __setjmp,@function
5 .type _setjmp,@function
6 .type setjmp,@function
7__setjmp:
8_setjmp:
9setjmp:
10 ld 5, 24(1) # load from the TOC slot in the caller's stack frame
11 b __setjmp_toc
12
13 .localentry __setjmp,.-__setjmp
14 .localentry _setjmp,.-_setjmp
15 .localentry setjmp,.-setjmp
16 mr 5, 2
17
18 .global __setjmp_toc
19 .hidden __setjmp_toc
20 # same as normal setjmp, except TOC pointer to save is provided in r5.
21 # r4 would normally be the 2nd parameter, but we're using r5 to simplify calling from sigsetjmp.
22 # solves the problem of knowing whether to save the TOC pointer from r2 or the caller's stack frame.
23__setjmp_toc:
24 # 0) store IP into 0, then into the jmpbuf pointed to by r3 (first arg)
25 mflr 0
26 std 0, 0*8(3)
27 # 1) store cr
28 mfcr 0
29 std 0, 1*8(3)
30 # 2) store SP and TOC
31 std 1, 2*8(3)
32 std 5, 3*8(3)
33 # 3) store r14-31
34 std 14, 4*8(3)
35 std 15, 5*8(3)
36 std 16, 6*8(3)
37 std 17, 7*8(3)
38 std 18, 8*8(3)
39 std 19, 9*8(3)
40 std 20, 10*8(3)
41 std 21, 11*8(3)
42 std 22, 12*8(3)
43 std 23, 13*8(3)
44 std 24, 14*8(3)
45 std 25, 15*8(3)
46 std 26, 16*8(3)
47 std 27, 17*8(3)
48 std 28, 18*8(3)
49 std 29, 19*8(3)
50 std 30, 20*8(3)
51 std 31, 21*8(3)
52 # 4) store floating point registers f14-f31
53 stfd 14, 22*8(3)
54 stfd 15, 23*8(3)
55 stfd 16, 24*8(3)
56 stfd 17, 25*8(3)
57 stfd 18, 26*8(3)
58 stfd 19, 27*8(3)
59 stfd 20, 28*8(3)
60 stfd 21, 29*8(3)
61 stfd 22, 30*8(3)
62 stfd 23, 31*8(3)
63 stfd 24, 32*8(3)
64 stfd 25, 33*8(3)
65 stfd 26, 34*8(3)
66 stfd 27, 35*8(3)
67 stfd 28, 36*8(3)
68 stfd 29, 37*8(3)
69 stfd 30, 38*8(3)
70 stfd 31, 39*8(3)
71
72 # 5) store vector registers v20-v31
73 addi 3, 3, 40*8
74 stvx 20, 0, 3 ; addi 3, 3, 16
75 stvx 21, 0, 3 ; addi 3, 3, 16
76 stvx 22, 0, 3 ; addi 3, 3, 16
77 stvx 23, 0, 3 ; addi 3, 3, 16
78 stvx 24, 0, 3 ; addi 3, 3, 16
79 stvx 25, 0, 3 ; addi 3, 3, 16
80 stvx 26, 0, 3 ; addi 3, 3, 16
81 stvx 27, 0, 3 ; addi 3, 3, 16
82 stvx 28, 0, 3 ; addi 3, 3, 16
83 stvx 29, 0, 3 ; addi 3, 3, 16
84 stvx 30, 0, 3 ; addi 3, 3, 16
85 stvx 31, 0, 3
86
87 # 6) return 0
88 li 3, 0
89 blr
lib/libc/wasi/libc-top-half/musl/src/setjmp/s390x/longjmp.s deleted-23
......@@ -1,23 +0,0 @@
1 .global _longjmp
2 .global longjmp
3 .type _longjmp,@function
4 .type longjmp,@function
5_longjmp:
6longjmp:
7
81:
9 lmg %r6, %r15, 0(%r2)
10
11 ld %f8, 10*8(%r2)
12 ld %f9, 11*8(%r2)
13 ld %f10, 12*8(%r2)
14 ld %f11, 13*8(%r2)
15 ld %f12, 14*8(%r2)
16 ld %f13, 15*8(%r2)
17 ld %f14, 16*8(%r2)
18 ld %f15, 17*8(%r2)
19
20 ltgr %r2, %r3
21 bnzr %r14
22 lhi %r2, 1
23 br %r14
lib/libc/wasi/libc-top-half/musl/src/setjmp/s390x/setjmp.s deleted-25
......@@ -1,25 +0,0 @@
1 .global ___setjmp
2 .hidden ___setjmp
3 .global __setjmp
4 .global _setjmp
5 .global setjmp
6 .type __setjmp,@function
7 .type _setjmp,@function
8 .type setjmp,@function
9___setjmp:
10__setjmp:
11_setjmp:
12setjmp:
13 stmg %r6, %r15, 0(%r2)
14
15 std %f8, 10*8(%r2)
16 std %f9, 11*8(%r2)
17 std %f10, 12*8(%r2)
18 std %f11, 13*8(%r2)
19 std %f12, 14*8(%r2)
20 std %f13, 15*8(%r2)
21 std %f14, 16*8(%r2)
22 std %f15, 17*8(%r2)
23
24 lghi %r2, 0
25 br %r14
lib/libc/wasi/libc-top-half/musl/src/setjmp/setjmp.c deleted
lib/libc/wasi/libc-top-half/musl/src/setjmp/x32/longjmp.s deleted-18
......@@ -1,18 +0,0 @@
1/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
2.global _longjmp
3.global longjmp
4.type _longjmp,@function
5.type longjmp,@function
6_longjmp:
7longjmp:
8 xor %eax,%eax
9 cmp $1,%esi /* CF = val ? 0 : 1 */
10 adc %esi,%eax /* eax = val + !val */
11 mov (%rdi),%rbx /* rdi is the jmp_buf, restore regs from it */
12 mov 8(%rdi),%rbp
13 mov 16(%rdi),%r12
14 mov 24(%rdi),%r13
15 mov 32(%rdi),%r14
16 mov 40(%rdi),%r15
17 mov 48(%rdi),%rsp
18 jmp *56(%rdi) /* goto saved address without altering rsp */
lib/libc/wasi/libc-top-half/musl/src/setjmp/x32/setjmp.s deleted-22
......@@ -1,22 +0,0 @@
1/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
2.global __setjmp
3.global _setjmp
4.global setjmp
5.type __setjmp,@function
6.type _setjmp,@function
7.type setjmp,@function
8__setjmp:
9_setjmp:
10setjmp:
11 mov %rbx,(%rdi) /* rdi is jmp_buf, move registers onto it */
12 mov %rbp,8(%rdi)
13 mov %r12,16(%rdi)
14 mov %r13,24(%rdi)
15 mov %r14,32(%rdi)
16 mov %r15,40(%rdi)
17 lea 8(%rsp),%rdx /* this is our rsp WITHOUT current ret addr */
18 mov %rdx,48(%rdi)
19 mov (%rsp),%rdx /* save return addr ptr for new rip */
20 mov %rdx,56(%rdi)
21 xor %eax,%eax /* always return 0 */
22 ret
lib/libc/wasi/libc-top-half/musl/src/setjmp/x86_64/longjmp.s deleted-18
......@@ -1,18 +0,0 @@
1/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
2.global _longjmp
3.global longjmp
4.type _longjmp,@function
5.type longjmp,@function
6_longjmp:
7longjmp:
8 xor %eax,%eax
9 cmp $1,%esi /* CF = val ? 0 : 1 */
10 adc %esi,%eax /* eax = val + !val */
11 mov (%rdi),%rbx /* rdi is the jmp_buf, restore regs from it */
12 mov 8(%rdi),%rbp
13 mov 16(%rdi),%r12
14 mov 24(%rdi),%r13
15 mov 32(%rdi),%r14
16 mov 40(%rdi),%r15
17 mov 48(%rdi),%rsp
18 jmp *56(%rdi) /* goto saved address without altering rsp */
lib/libc/wasi/libc-top-half/musl/src/setjmp/x86_64/setjmp.s deleted-22
......@@ -1,22 +0,0 @@
1/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
2.global __setjmp
3.global _setjmp
4.global setjmp
5.type __setjmp,@function
6.type _setjmp,@function
7.type setjmp,@function
8__setjmp:
9_setjmp:
10setjmp:
11 mov %rbx,(%rdi) /* rdi is jmp_buf, move registers onto it */
12 mov %rbp,8(%rdi)
13 mov %r12,16(%rdi)
14 mov %r13,24(%rdi)
15 mov %r14,32(%rdi)
16 mov %r15,40(%rdi)
17 lea 8(%rsp),%rdx /* this is our rsp WITHOUT current ret addr */
18 mov %rdx,48(%rdi)
19 mov (%rsp),%rdx /* save return addr ptr for new rip */
20 mov %rdx,56(%rdi)
21 xor %eax,%eax /* always return 0 */
22 ret
lib/libc/wasi/libc-top-half/musl/src/signal/aarch64/restore.s deleted-10
......@@ -1,10 +0,0 @@
1.global __restore
2.hidden __restore
3.type __restore,%function
4__restore:
5.global __restore_rt
6.hidden __restore_rt
7.type __restore_rt,%function
8__restore_rt:
9 mov x8,#139 // SYS_rt_sigreturn
10 svc 0
lib/libc/wasi/libc-top-half/musl/src/signal/aarch64/sigsetjmp.s deleted-21
......@@ -1,21 +0,0 @@
1.global sigsetjmp
2.global __sigsetjmp
3.type sigsetjmp,%function
4.type __sigsetjmp,%function
5sigsetjmp:
6__sigsetjmp:
7 cbz x1,setjmp
8
9 str x30,[x0,#176]
10 str x19,[x0,#176+8+8]
11 mov x19,x0
12
13 bl setjmp
14
15 mov w1,w0
16 mov x0,x19
17 ldr x30,[x0,#176]
18 ldr x19,[x0,#176+8+8]
19
20.hidden __sigsetjmp_tail
21 b __sigsetjmp_tail
lib/libc/wasi/libc-top-half/musl/src/signal/arm/restore.s deleted-15
......@@ -1,15 +0,0 @@
1.syntax unified
2
3.global __restore
4.hidden __restore
5.type __restore,%function
6__restore:
7 mov r7,#119
8 swi 0x0
9
10.global __restore_rt
11.hidden __restore_rt
12.type __restore_rt,%function
13__restore_rt:
14 mov r7,#173
15 swi 0x0
lib/libc/wasi/libc-top-half/musl/src/signal/arm/sigsetjmp.s deleted-24
......@@ -1,24 +0,0 @@
1.syntax unified
2.global sigsetjmp
3.global __sigsetjmp
4.type sigsetjmp,%function
5.type __sigsetjmp,%function
6sigsetjmp:
7__sigsetjmp:
8 tst r1,r1
9 bne 1f
10 b setjmp
11
121: str lr,[r0,#256]
13 str r4,[r0,#260+8]
14 mov r4,r0
15
16 bl setjmp
17
18 mov r1,r0
19 mov r0,r4
20 ldr lr,[r0,#256]
21 ldr r4,[r0,#260+8]
22
23.hidden __sigsetjmp_tail
24 b __sigsetjmp_tail
lib/libc/wasi/libc-top-half/musl/src/signal/block.c deleted-44
......@@ -1,44 +0,0 @@
1#include "pthread_impl.h"
2#include "syscall.h"
3#include <signal.h>
4
5static const unsigned long all_mask[] = {
6#if ULONG_MAX == 0xffffffff && _NSIG > 65
7 -1UL, -1UL, -1UL, -1UL
8#elif ULONG_MAX == 0xffffffff || _NSIG > 65
9 -1UL, -1UL
10#else
11 -1UL
12#endif
13};
14
15static const unsigned long app_mask[] = {
16#if ULONG_MAX == 0xffffffff
17#if _NSIG == 65
18 0x7fffffff, 0xfffffffc
19#else
20 0x7fffffff, 0xfffffffc, -1UL, -1UL
21#endif
22#else
23#if _NSIG == 65
24 0xfffffffc7fffffff
25#else
26 0xfffffffc7fffffff, -1UL
27#endif
28#endif
29};
30
31void __block_all_sigs(void *set)
32{
33 __syscall(SYS_rt_sigprocmask, SIG_BLOCK, &all_mask, set, _NSIG/8);
34}
35
36void __block_app_sigs(void *set)
37{
38 __syscall(SYS_rt_sigprocmask, SIG_BLOCK, &app_mask, set, _NSIG/8);
39}
40
41void __restore_sigs(void *set)
42{
43 __syscall(SYS_rt_sigprocmask, SIG_SETMASK, set, 0, _NSIG/8);
44}
lib/libc/wasi/libc-top-half/musl/src/signal/getitimer.c deleted-18
......@@ -1,18 +0,0 @@
1#include <sys/time.h>
2#include "syscall.h"
3
4int getitimer(int which, struct itimerval *old)
5{
6 if (sizeof(time_t) > sizeof(long)) {
7 long old32[4];
8 int r = __syscall(SYS_getitimer, which, old32);
9 if (!r) {
10 old->it_interval.tv_sec = old32[0];
11 old->it_interval.tv_usec = old32[1];
12 old->it_value.tv_sec = old32[2];
13 old->it_value.tv_usec = old32[3];
14 }
15 return __syscall_ret(r);
16 }
17 return syscall(SYS_getitimer, which, old);
18}
lib/libc/wasi/libc-top-half/musl/src/signal/i386/restore.s deleted-14
......@@ -1,14 +0,0 @@
1.global __restore
2.hidden __restore
3.type __restore,@function
4__restore:
5 popl %eax
6 movl $119, %eax
7 int $0x80
8
9.global __restore_rt
10.hidden __restore_rt
11.type __restore_rt,@function
12__restore_rt:
13 movl $173, %eax
14 int $0x80
lib/libc/wasi/libc-top-half/musl/src/signal/i386/sigsetjmp.s deleted-26
......@@ -1,26 +0,0 @@
1.global sigsetjmp
2.global __sigsetjmp
3.type sigsetjmp,@function
4.type __sigsetjmp,@function
5sigsetjmp:
6__sigsetjmp:
7 mov 8(%esp),%ecx
8 jecxz 1f
9
10 mov 4(%esp),%eax
11 popl 24(%eax)
12 mov %ebx,28+8(%eax)
13 mov %eax,%ebx
14
15.hidden ___setjmp
16 call ___setjmp
17
18 pushl 24(%ebx)
19 mov %ebx,4(%esp)
20 mov %eax,8(%esp)
21 mov 28+8(%ebx),%ebx
22
23.hidden __sigsetjmp_tail
24 jmp __sigsetjmp_tail
25
261: jmp ___setjmp
lib/libc/wasi/libc-top-half/musl/src/signal/kill.c deleted-7
......@@ -1,7 +0,0 @@
1#include <signal.h>
2#include "syscall.h"
3
4int kill(pid_t pid, int sig)
5{
6 return syscall(SYS_kill, pid, sig);
7}
lib/libc/wasi/libc-top-half/musl/src/signal/killpg.c deleted-11
......@@ -1,11 +0,0 @@
1#include <signal.h>
2#include <errno.h>
3
4int killpg(pid_t pgid, int sig)
5{
6 if (pgid < 0) {
7 errno = EINVAL;
8 return -1;
9 }
10 return kill(-pgid, sig);
11}
lib/libc/wasi/libc-top-half/musl/src/signal/m68k/sigsetjmp.s deleted-29
......@@ -1,29 +0,0 @@
1.global sigsetjmp
2.global __sigsetjmp
3.type sigsetjmp,@function
4.type __sigsetjmp,@function
5sigsetjmp:
6__sigsetjmp:
7 move.l 8(%sp),%d0
8 beq 1f
9
10 movea.l 4(%sp),%a1
11 move.l (%sp)+,156(%a1)
12 move.l %a2,156+4+8(%a1)
13 movea.l %a1,%a2
14
15.hidden ___setjmp
16 lea ___setjmp-.-8,%a1
17 jsr (%pc,%a1)
18
19 move.l 156(%a2),-(%sp)
20 move.l %a2,4(%sp)
21 move.l %d0,8(%sp)
22 movea.l 156+4+8(%a2),%a2
23
24.hidden __sigsetjmp_tail
25 lea __sigsetjmp_tail-.-8,%a1
26 jmp (%pc,%a1)
27
281: lea ___setjmp-.-8,%a1
29 jmp (%pc,%a1)
lib/libc/wasi/libc-top-half/musl/src/signal/microblaze/restore.s deleted-13
......@@ -1,13 +0,0 @@
1.global __restore
2.hidden __restore
3.type __restore,@function
4__restore:
5 ori r12, r0, 119
6 brki r14, 0x8
7
8.global __restore_rt
9.hidden __restore_rt
10.type __restore_rt,@function
11__restore_rt:
12 ori r12, r0, 173
13 brki r14, 0x8
lib/libc/wasi/libc-top-half/musl/src/signal/microblaze/sigsetjmp.s deleted-22
......@@ -1,22 +0,0 @@
1.global sigsetjmp
2.global __sigsetjmp
3.type sigsetjmp,@function
4.type __sigsetjmp,@function
5sigsetjmp:
6__sigsetjmp:
7.hidden ___setjmp
8 beqi r6, ___setjmp
9
10 swi r15,r5,72
11 swi r19,r5,72+4+8
12
13 brlid r15,___setjmp
14 ori r19,r5,0
15
16 ori r6,r3,0
17 ori r5,r19,0
18 lwi r15,r5,72
19 lwi r19,r5,72+4+8
20
21.hidden __sigsetjmp_tail
22 bri __sigsetjmp_tail
lib/libc/wasi/libc-top-half/musl/src/signal/mips/restore.s deleted-15
......@@ -1,15 +0,0 @@
1.set noreorder
2
3.global __restore_rt
4.hidden __restore_rt
5.type __restore_rt,@function
6__restore_rt:
7 li $2, 4193
8 syscall
9
10.global __restore
11.hidden __restore
12.type __restore,@function
13__restore:
14 li $2, 4119
15 syscall
lib/libc/wasi/libc-top-half/musl/src/signal/mips/sigsetjmp.s deleted-33
......@@ -1,33 +0,0 @@
1.set noreorder
2
3.global sigsetjmp
4.global __sigsetjmp
5.type sigsetjmp,@function
6.type __sigsetjmp,@function
7sigsetjmp:
8__sigsetjmp:
9 lui $gp, %hi(_gp_disp)
10 addiu $gp, %lo(_gp_disp)
11 beq $5, $0, 1f
12 addu $gp, $gp, $25
13
14 sw $ra, 104($4)
15 sw $16, 104+4+16($4)
16
17 lw $25, %call16(setjmp)($gp)
18 jalr $25
19 move $16, $4
20
21 move $5,$2
22 move $4,$16
23 lw $ra, 104($4)
24 lw $16, 104+4+16($4)
25
26.hidden __sigsetjmp_tail
27 lw $25, %call16(__sigsetjmp_tail)($gp)
28 jr $25
29 nop
30
311: lw $25, %call16(setjmp)($gp)
32 jr $25
33 nop
lib/libc/wasi/libc-top-half/musl/src/signal/mips64/restore.s deleted-11
......@@ -1,11 +0,0 @@
1.set noreorder
2.global __restore_rt
3.global __restore
4.hidden __restore_rt
5.hidden __restore
6.type __restore_rt,@function
7.type __restore,@function
8__restore_rt:
9__restore:
10 li $2,5211
11 syscall
lib/libc/wasi/libc-top-half/musl/src/signal/mips64/sigsetjmp.s deleted-38
......@@ -1,38 +0,0 @@
1.set noreorder
2.global sigsetjmp
3.global __sigsetjmp
4.type sigsetjmp,@function
5.type __sigsetjmp,@function
6sigsetjmp:
7__sigsetjmp:
8 lui $3, %hi(%neg(%gp_rel(sigsetjmp)))
9 daddiu $3, $3, %lo(%neg(%gp_rel(sigsetjmp)))
10
11 # comparing save mask with 0, if equals to 0 then
12 # sigsetjmp is equal to setjmp.
13 beq $5, $0, 1f
14 daddu $3, $3, $25
15 sd $ra, 160($4)
16 sd $16, 168($4)
17
18 # save base of got so that we can use it later
19 # once we return from 'longjmp'
20 sd $3, 176($4)
21 ld $25, %got_disp(setjmp)($3)
22 jalr $25
23 move $16, $4
24
25 move $5, $2 # Return from 'setjmp' or 'longjmp'
26 move $4, $16 # Restore the pointer-to-sigjmp_buf
27 ld $ra, 160($4) # Restore ra of sigsetjmp
28 ld $16, 168($4) # Restore $16 of sigsetjmp
29 ld $3, 176($4) # Restore base of got
30
31.hidden __sigsetjmp_tail
32 ld $25, %got_disp(__sigsetjmp_tail)($3)
33 jr $25
34 nop
351:
36 ld $25, %got_disp(setjmp)($3)
37 jr $25
38 nop
lib/libc/wasi/libc-top-half/musl/src/signal/mipsn32/restore.s deleted-11
......@@ -1,11 +0,0 @@
1.set noreorder
2.global __restore_rt
3.global __restore
4.hidden __restore_rt
5.hidden __restore
6.type __restore_rt,@function
7.type __restore,@function
8__restore_rt:
9__restore:
10 li $2,6211
11 syscall
lib/libc/wasi/libc-top-half/musl/src/signal/mipsn32/sigsetjmp.s deleted-38
......@@ -1,38 +0,0 @@
1.set noreorder
2.global sigsetjmp
3.global __sigsetjmp
4.type sigsetjmp,@function
5.type __sigsetjmp,@function
6sigsetjmp:
7__sigsetjmp:
8 lui $3, %hi(%neg(%gp_rel(sigsetjmp)))
9 addiu $3, $3, %lo(%neg(%gp_rel(sigsetjmp)))
10
11 # comparing save mask with 0, if equals to 0 then
12 # sigsetjmp is equal to setjmp.
13 beq $5, $0, 1f
14 addu $3, $3, $25
15 sd $ra, 160($4)
16 sd $16, 168($4)
17
18 # save base of got so that we can use it later
19 # once we return from 'longjmp'
20 sd $3, 176($4)
21 lw $25, %got_disp(setjmp)($3)
22 jalr $25
23 move $16, $4
24
25 move $5, $2 # Return from 'setjmp' or 'longjmp'
26 move $4, $16 # Restore the pointer-to-sigjmp_buf
27 ld $ra, 160($4) # Restore ra of sigsetjmp
28 ld $16, 168($4) # Restore $16 of sigsetjmp
29 ld $3, 176($4) # Restore base of got
30
31.hidden __sigsetjmp_tail
32 lw $25, %got_disp(__sigsetjmp_tail)($3)
33 jr $25
34 nop
351:
36 lw $25, %got_disp(setjmp)($3)
37 jr $25
38 nop
lib/libc/wasi/libc-top-half/musl/src/signal/or1k/sigsetjmp.s deleted-24
......@@ -1,24 +0,0 @@
1.global sigsetjmp
2.global __sigsetjmp
3.type sigsetjmp,@function
4.type __sigsetjmp,@function
5sigsetjmp:
6__sigsetjmp:
7 l.sfeq r4, r0
8.hidden ___setjmp
9 l.bf ___setjmp
10
11 l.sw 52(r3), r9
12 l.sw 52+4+8(r3), r20
13
14 l.jal ___setjmp
15 l.ori r20, r3, 0
16
17 l.ori r4, r11, 0
18 l.ori r3, r20, 0
19
20 l.lwz r9, 52(r3)
21
22.hidden __sigsetjmp_tail
23 l.j __sigsetjmp_tail
24 l.lwz r20, 52+4+8(r3)
lib/libc/wasi/libc-top-half/musl/src/signal/powerpc/restore.s deleted-13
......@@ -1,13 +0,0 @@
1 .global __restore
2 .hidden __restore
3 .type __restore,%function
4__restore:
5 li 0, 119 #__NR_sigreturn
6 sc
7
8 .global __restore_rt
9 .hidden __restore_rt
10 .type __restore_rt,%function
11__restore_rt:
12 li 0, 172 # __NR_rt_sigreturn
13 sc
lib/libc/wasi/libc-top-half/musl/src/signal/powerpc/sigsetjmp.s deleted-27
......@@ -1,27 +0,0 @@
1 .global sigsetjmp
2 .global __sigsetjmp
3 .type sigsetjmp,%function
4 .type __sigsetjmp,%function
5sigsetjmp:
6__sigsetjmp:
7 cmpwi cr7, 4, 0
8 beq- cr7, 1f
9
10 mflr 5
11 stw 5, 448(3)
12 stw 16, 448+4+8(3)
13 mr 16, 3
14
15.hidden ___setjmp
16 bl ___setjmp
17
18 mr 4, 3
19 mr 3, 16
20 lwz 5, 448(3)
21 mtlr 5
22 lwz 16, 448+4+8(3)
23
24.hidden __sigsetjmp_tail
25 b __sigsetjmp_tail
26
271: b ___setjmp
lib/libc/wasi/libc-top-half/musl/src/signal/powerpc64/restore.s deleted-13
......@@ -1,13 +0,0 @@
1 .global __restore
2 .hidden __restore
3 .type __restore,%function
4__restore:
5 li 0, 119 #__NR_sigreturn
6 sc
7
8 .global __restore_rt
9 .hidden __restore_rt
10 .type __restore_rt,%function
11__restore_rt:
12 li 0, 172 # __NR_rt_sigreturn
13 sc
lib/libc/wasi/libc-top-half/musl/src/signal/powerpc64/sigsetjmp.s deleted-37
......@@ -1,37 +0,0 @@
1 .global sigsetjmp
2 .global __sigsetjmp
3 .type sigsetjmp,%function
4 .type __sigsetjmp,%function
5 .hidden __setjmp_toc
6sigsetjmp:
7__sigsetjmp:
8 addis 2, 12, .TOC.-__sigsetjmp@ha
9 addi 2, 2, .TOC.-__sigsetjmp@l
10 ld 5, 24(1) # load from the TOC slot in the caller's stack frame
11 b 1f
12
13 .localentry sigsetjmp,.-sigsetjmp
14 .localentry __sigsetjmp,.-__sigsetjmp
15 mr 5, 2
16
171:
18 cmpwi cr7, 4, 0
19 beq- cr7, __setjmp_toc
20
21 mflr 6
22 std 6, 512(3)
23 std 2, 512+16(3)
24 std 16, 512+24(3)
25 mr 16, 3
26
27 bl __setjmp_toc
28
29 mr 4, 3
30 mr 3, 16
31 ld 5, 512(3)
32 mtlr 5
33 ld 2, 512+16(3)
34 ld 16, 512+24(3)
35
36.hidden __sigsetjmp_tail
37 b __sigsetjmp_tail
lib/libc/wasi/libc-top-half/musl/src/signal/psiginfo.c deleted-6
......@@ -1,6 +0,0 @@
1#include <signal.h>
2
3void psiginfo(const siginfo_t *si, const char *msg)
4{
5 psignal(si->si_signo, msg);
6}
lib/libc/wasi/libc-top-half/musl/src/signal/raise.c deleted-13
......@@ -1,13 +0,0 @@
1#include <signal.h>
2#include <stdint.h>
3#include "syscall.h"
4#include "pthread_impl.h"
5
6int raise(int sig)
7{
8 sigset_t set;
9 __block_app_sigs(&set);
10 int ret = syscall(SYS_tkill, __pthread_self()->tid, sig);
11 __restore_sigs(&set);
12 return ret;
13}
lib/libc/wasi/libc-top-half/musl/src/signal/restore.c deleted-12
......@@ -1,12 +0,0 @@
1#include <features.h>
2
3/* These functions will not work, but suffice for targets where the
4 * kernel sigaction structure does not actually use sa_restorer. */
5
6hidden void __restore()
7{
8}
9
10hidden void __restore_rt()
11{
12}
lib/libc/wasi/libc-top-half/musl/src/signal/riscv64/restore.s deleted-8
......@@ -1,8 +0,0 @@
1.global __restore
2.type __restore, %function
3__restore:
4.global __restore_rt
5.type __restore_rt, %function
6__restore_rt:
7 li a7, 139 # SYS_rt_sigreturn
8 ecall
lib/libc/wasi/libc-top-half/musl/src/signal/riscv64/sigsetjmp.s deleted-23
......@@ -1,23 +0,0 @@
1.global sigsetjmp
2.global __sigsetjmp
3.type sigsetjmp, %function
4.type __sigsetjmp, %function
5sigsetjmp:
6__sigsetjmp:
7 bnez a1, 1f
8 tail setjmp
91:
10
11 sd ra, 208(a0)
12 sd s0, 224(a0)
13 mv s0, a0
14
15 call setjmp
16
17 mv a1, a0
18 mv a0, s0
19 ld s0, 224(a0)
20 ld ra, 208(a0)
21
22.hidden __sigsetjmp_tail
23 tail __sigsetjmp_tail
lib/libc/wasi/libc-top-half/musl/src/signal/s390x/restore.s deleted-11
......@@ -1,11 +0,0 @@
1 .global __restore
2 .hidden __restore
3 .type __restore,%function
4__restore:
5 svc 119 #__NR_sigreturn
6
7 .global __restore_rt
8 .hidden __restore_rt
9 .type __restore_rt,%function
10__restore_rt:
11 svc 173 # __NR_rt_sigreturn
lib/libc/wasi/libc-top-half/musl/src/signal/s390x/sigsetjmp.s deleted-23
......@@ -1,23 +0,0 @@
1 .global sigsetjmp
2 .global __sigsetjmp
3 .type sigsetjmp,%function
4 .type __sigsetjmp,%function
5 .hidden ___setjmp
6sigsetjmp:
7__sigsetjmp:
8 ltgr %r3, %r3
9 jz ___setjmp
10
11 stg %r14, 18*8(%r2)
12 stg %r6, 20*8(%r2)
13 lgr %r6, %r2
14
15 brasl %r14, ___setjmp
16
17 lgr %r3, %r2
18 lgr %r2, %r6
19 lg %r14, 18*8(%r2)
20 lg %r6, 20*8(%r2)
21
22.hidden __sigsetjmp_tail
23 jg __sigsetjmp_tail
lib/libc/wasi/libc-top-half/musl/src/signal/setitimer.c deleted-26
......@@ -1,26 +0,0 @@
1#include <sys/time.h>
2#include <errno.h>
3#include "syscall.h"
4
5#define IS32BIT(x) !((x)+0x80000000ULL>>32)
6
7int setitimer(int which, const struct itimerval *restrict new, struct itimerval *restrict old)
8{
9 if (sizeof(time_t) > sizeof(long)) {
10 time_t is = new->it_interval.tv_sec, vs = new->it_value.tv_sec;
11 long ius = new->it_interval.tv_usec, vus = new->it_value.tv_usec;
12 if (!IS32BIT(is) || !IS32BIT(vs))
13 return __syscall_ret(-ENOTSUP);
14 long old32[4];
15 int r = __syscall(SYS_setitimer, which,
16 ((long[]){is, ius, vs, vus}), old32);
17 if (!r && old) {
18 old->it_interval.tv_sec = old32[0];
19 old->it_interval.tv_usec = old32[1];
20 old->it_value.tv_sec = old32[2];
21 old->it_value.tv_usec = old32[3];
22 }
23 return __syscall_ret(r);
24 }
25 return syscall(SYS_setitimer, which, new, old);
26}
lib/libc/wasi/libc-top-half/musl/src/signal/sh/restore.s deleted-24
......@@ -1,24 +0,0 @@
1.global __restore
2.hidden __restore
3__restore:
4 mov #119, r3 !__NR_sigreturn
5 trapa #31
6
7 or r0, r0
8 or r0, r0
9 or r0, r0
10 or r0, r0
11 or r0, r0
12
13.global __restore_rt
14.hidden __restore_rt
15__restore_rt:
16 mov #100, r3 !__NR_rt_sigreturn
17 add #73, r3
18 trapa #31
19
20 or r0, r0
21 or r0, r0
22 or r0, r0
23 or r0, r0
24 or r0, r0
lib/libc/wasi/libc-top-half/musl/src/signal/sh/sigsetjmp.s deleted-41
......@@ -1,41 +0,0 @@
1.global sigsetjmp
2.global __sigsetjmp
3.type sigsetjmp,@function
4.type __sigsetjmp,@function
5sigsetjmp:
6__sigsetjmp:
7 tst r5, r5
8 bt 9f
9
10 mov r4, r6
11 add #60, r6
12 sts pr, r0
13 mov.l r0, @r6
14 mov.l r8, @(4+8,r6)
15
16 mov.l 1f, r0
172: bsrf r0
18 mov r4, r8
19
20 mov r0, r5
21 mov r8, r4
22 mov r4, r6
23 add #60, r6
24
25 mov.l @r6, r0
26 lds r0, pr
27
28 mov.l 3f, r0
294: braf r0
30 mov.l @(4+8,r4), r8
31
329: mov.l 5f, r0
336: braf r0
34 nop
35
36.align 2
37.hidden ___setjmp
381: .long ___setjmp@PLT-(2b+4-.)
39.hidden __sigsetjmp_tail
403: .long __sigsetjmp_tail@PLT-(4b+4-.)
415: .long ___setjmp@PLT-(6b+4-.)
lib/libc/wasi/libc-top-half/musl/src/signal/sigaction.c deleted-84
......@@ -1,84 +0,0 @@
1#include <signal.h>
2#include <errno.h>
3#include <string.h>
4#include "syscall.h"
5#include "pthread_impl.h"
6#include "libc.h"
7#include "lock.h"
8#include "ksigaction.h"
9
10static int unmask_done;
11static unsigned long handler_set[_NSIG/(8*sizeof(long))];
12
13void __get_handler_set(sigset_t *set)
14{
15 memcpy(set, handler_set, sizeof handler_set);
16}
17
18volatile int __eintr_valid_flag;
19
20int __libc_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
21{
22 struct k_sigaction ksa, ksa_old;
23 if (sa) {
24 if ((uintptr_t)sa->sa_handler > 1UL) {
25 a_or_l(handler_set+(sig-1)/(8*sizeof(long)),
26 1UL<<(sig-1)%(8*sizeof(long)));
27
28 /* If pthread_create has not yet been called,
29 * implementation-internal signals might not
30 * yet have been unblocked. They must be
31 * unblocked before any signal handler is
32 * installed, so that an application cannot
33 * receive an illegal sigset_t (with them
34 * blocked) as part of the ucontext_t passed
35 * to the signal handler. */
36 if (!libc.threaded && !unmask_done) {
37 __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK,
38 SIGPT_SET, 0, _NSIG/8);
39 unmask_done = 1;
40 }
41
42 if (!(sa->sa_flags & SA_RESTART)) {
43 a_store(&__eintr_valid_flag, 1);
44 }
45 }
46 ksa.handler = sa->sa_handler;
47 ksa.flags = sa->sa_flags | SA_RESTORER;
48 ksa.restorer = (sa->sa_flags & SA_SIGINFO) ? __restore_rt : __restore;
49 memcpy(&ksa.mask, &sa->sa_mask, _NSIG/8);
50 }
51 int r = __syscall(SYS_rt_sigaction, sig, sa?&ksa:0, old?&ksa_old:0, _NSIG/8);
52 if (old && !r) {
53 old->sa_handler = ksa_old.handler;
54 old->sa_flags = ksa_old.flags;
55 memcpy(&old->sa_mask, &ksa_old.mask, _NSIG/8);
56 }
57 return __syscall_ret(r);
58}
59
60int __sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
61{
62 unsigned long set[_NSIG/(8*sizeof(long))];
63
64 if (sig-32U < 3 || sig-1U >= _NSIG-1) {
65 errno = EINVAL;
66 return -1;
67 }
68
69 /* Doing anything with the disposition of SIGABRT requires a lock,
70 * so that it cannot be changed while abort is terminating the
71 * process and so any change made by abort can't be observed. */
72 if (sig == SIGABRT) {
73 __block_all_sigs(&set);
74 LOCK(__abort_lock);
75 }
76 int r = __libc_sigaction(sig, sa, old);
77 if (sig == SIGABRT) {
78 UNLOCK(__abort_lock);
79 __restore_sigs(&set);
80 }
81 return r;
82}
83
84weak_alias(__sigaction, sigaction);
lib/libc/wasi/libc-top-half/musl/src/signal/sigaddset.c deleted-13
......@@ -1,13 +0,0 @@
1#include <signal.h>
2#include <errno.h>
3
4int sigaddset(sigset_t *set, int sig)
5{
6 unsigned s = sig-1;
7 if (s >= _NSIG-1 || sig-32U < 3) {
8 errno = EINVAL;
9 return -1;
10 }
11 set->__bits[s/8/sizeof *set->__bits] |= 1UL<<(s&8*sizeof *set->__bits-1);
12 return 0;
13}
lib/libc/wasi/libc-top-half/musl/src/signal/sigaltstack.c deleted-18
......@@ -1,18 +0,0 @@
1#include <signal.h>
2#include <errno.h>
3#include "syscall.h"
4
5int sigaltstack(const stack_t *restrict ss, stack_t *restrict old)
6{
7 if (ss) {
8 if (!(ss->ss_flags & SS_DISABLE) && ss->ss_size < MINSIGSTKSZ) {
9 errno = ENOMEM;
10 return -1;
11 }
12 if (ss->ss_flags & SS_ONSTACK) {
13 errno = EINVAL;
14 return -1;
15 }
16 }
17 return syscall(SYS_sigaltstack, ss, old);
18}
lib/libc/wasi/libc-top-half/musl/src/signal/sigandset.c deleted-12
......@@ -1,12 +0,0 @@
1#define _GNU_SOURCE
2#include <signal.h>
3
4#define SST_SIZE (_NSIG/8/sizeof(long))
5
6int sigandset(sigset_t *dest, const sigset_t *left, const sigset_t *right)
7{
8 unsigned long i = 0, *d = (void*) dest, *l = (void*) left, *r = (void*) right;
9 for(; i < SST_SIZE; i++) d[i] = l[i] & r[i];
10 return 0;
11}
12
lib/libc/wasi/libc-top-half/musl/src/signal/sigdelset.c deleted-13
......@@ -1,13 +0,0 @@
1#include <signal.h>
2#include <errno.h>
3
4int sigdelset(sigset_t *set, int sig)
5{
6 unsigned s = sig-1;
7 if (s >= _NSIG-1 || sig-32U < 3) {
8 errno = EINVAL;
9 return -1;
10 }
11 set->__bits[s/8/sizeof *set->__bits] &=~(1UL<<(s&8*sizeof *set->__bits-1));
12 return 0;
13}
lib/libc/wasi/libc-top-half/musl/src/signal/sigemptyset.c deleted-13
......@@ -1,13 +0,0 @@
1#include <signal.h>
2#include <string.h>
3
4int sigemptyset(sigset_t *set)
5{
6 set->__bits[0] = 0;
7 if (sizeof(long)==4 || _NSIG > 65) set->__bits[1] = 0;
8 if (sizeof(long)==4 && _NSIG > 65) {
9 set->__bits[2] = 0;
10 set->__bits[3] = 0;
11 }
12 return 0;
13}
lib/libc/wasi/libc-top-half/musl/src/signal/sigfillset.c deleted-18
......@@ -1,18 +0,0 @@
1#include <signal.h>
2#include <limits.h>
3
4int sigfillset(sigset_t *set)
5{
6#if ULONG_MAX == 0xffffffff
7 set->__bits[0] = 0x7ffffffful;
8 set->__bits[1] = 0xfffffffcul;
9 if (_NSIG > 65) {
10 set->__bits[2] = 0xfffffffful;
11 set->__bits[3] = 0xfffffffful;
12 }
13#else
14 set->__bits[0] = 0xfffffffc7ffffffful;
15 if (_NSIG > 65) set->__bits[1] = 0xfffffffffffffffful;
16#endif
17 return 0;
18}
lib/libc/wasi/libc-top-half/musl/src/signal/sighold.c deleted-10
......@@ -1,10 +0,0 @@
1#include <signal.h>
2
3int sighold(int sig)
4{
5 sigset_t mask;
6
7 sigemptyset(&mask);
8 if (sigaddset(&mask, sig) < 0) return -1;
9 return sigprocmask(SIG_BLOCK, &mask, 0);
10}
lib/libc/wasi/libc-top-half/musl/src/signal/sigignore.c deleted-11
......@@ -1,11 +0,0 @@
1#include <signal.h>
2
3int sigignore(int sig)
4{
5 struct sigaction sa;
6
7 sigemptyset(&sa.sa_mask);
8 sa.sa_handler = SIG_IGN;
9 sa.sa_flags = 0;
10 return sigaction(sig, &sa, 0);
11}
lib/libc/wasi/libc-top-half/musl/src/signal/siginterrupt.c deleted-12
......@@ -1,12 +0,0 @@
1#include <signal.h>
2
3int siginterrupt(int sig, int flag)
4{
5 struct sigaction sa;
6
7 sigaction(sig, 0, &sa);
8 if (flag) sa.sa_flags &= ~SA_RESTART;
9 else sa.sa_flags |= SA_RESTART;
10
11 return sigaction(sig, &sa, 0);
12}
lib/libc/wasi/libc-top-half/musl/src/signal/sigisemptyset.c deleted-10
......@@ -1,10 +0,0 @@
1#define _GNU_SOURCE
2#include <signal.h>
3#include <string.h>
4
5int sigisemptyset(const sigset_t *set)
6{
7 for (size_t i=0; i<_NSIG/8/sizeof *set->__bits; i++)
8 if (set->__bits[i]) return 0;
9 return 1;
10}
lib/libc/wasi/libc-top-half/musl/src/signal/sigismember.c deleted-8
......@@ -1,8 +0,0 @@
1#include <signal.h>
2
3int sigismember(const sigset_t *set, int sig)
4{
5 unsigned s = sig-1;
6 if (s >= _NSIG-1) return 0;
7 return !!(set->__bits[s/8/sizeof *set->__bits] & 1UL<<(s&8*sizeof *set->__bits-1));
8}
lib/libc/wasi/libc-top-half/musl/src/signal/siglongjmp.c deleted-9
......@@ -1,9 +0,0 @@
1#include <setjmp.h>
2#include <signal.h>
3#include "syscall.h"
4#include "pthread_impl.h"
5
6_Noreturn void siglongjmp(sigjmp_buf buf, int ret)
7{
8 longjmp(buf, ret);
9}
lib/libc/wasi/libc-top-half/musl/src/signal/signal.c deleted-13
......@@ -1,13 +0,0 @@
1#include <signal.h>
2#include "syscall.h"
3
4void (*signal(int sig, void (*func)(int)))(int)
5{
6 struct sigaction sa_old, sa = { .sa_handler = func, .sa_flags = SA_RESTART };
7 if (__sigaction(sig, &sa, &sa_old) < 0)
8 return SIG_ERR;
9 return sa_old.sa_handler;
10}
11
12weak_alias(signal, bsd_signal);
13weak_alias(signal, __sysv_signal);
lib/libc/wasi/libc-top-half/musl/src/signal/sigorset.c deleted-12
......@@ -1,12 +0,0 @@
1#define _GNU_SOURCE
2#include <signal.h>
3
4#define SST_SIZE (_NSIG/8/sizeof(long))
5
6int sigorset(sigset_t *dest, const sigset_t *left, const sigset_t *right)
7{
8 unsigned long i = 0, *d = (void*) dest, *l = (void*) left, *r = (void*) right;
9 for(; i < SST_SIZE; i++) d[i] = l[i] | r[i];
10 return 0;
11}
12
lib/libc/wasi/libc-top-half/musl/src/signal/sigpause.c deleted-9
......@@ -1,9 +0,0 @@
1#include <signal.h>
2
3int sigpause(int sig)
4{
5 sigset_t mask;
6 sigprocmask(0, 0, &mask);
7 sigdelset(&mask, sig);
8 return sigsuspend(&mask);
9}
lib/libc/wasi/libc-top-half/musl/src/signal/sigpending.c deleted-7
......@@ -1,7 +0,0 @@
1#include <signal.h>
2#include "syscall.h"
3
4int sigpending(sigset_t *set)
5{
6 return syscall(SYS_rt_sigpending, set, _NSIG/8);
7}
lib/libc/wasi/libc-top-half/musl/src/signal/sigprocmask.c deleted-10
......@@ -1,10 +0,0 @@
1#include <signal.h>
2#include <errno.h>
3
4int sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old)
5{
6 int r = pthread_sigmask(how, set, old);
7 if (!r) return r;
8 errno = r;
9 return -1;
10}
lib/libc/wasi/libc-top-half/musl/src/signal/sigqueue.c deleted-22
......@@ -1,22 +0,0 @@
1#include <signal.h>
2#include <string.h>
3#include <unistd.h>
4#include "syscall.h"
5#include "pthread_impl.h"
6
7int sigqueue(pid_t pid, int sig, const union sigval value)
8{
9 siginfo_t si;
10 sigset_t set;
11 int r;
12 memset(&si, 0, sizeof si);
13 si.si_signo = sig;
14 si.si_code = SI_QUEUE;
15 si.si_value = value;
16 si.si_uid = getuid();
17 __block_app_sigs(&set);
18 si.si_pid = getpid();
19 r = syscall(SYS_rt_sigqueueinfo, pid, sig, &si);
20 __restore_sigs(&set);
21 return r;
22}
lib/libc/wasi/libc-top-half/musl/src/signal/sigrelse.c deleted-10
......@@ -1,10 +0,0 @@
1#include <signal.h>
2
3int sigrelse(int sig)
4{
5 sigset_t mask;
6
7 sigemptyset(&mask);
8 if (sigaddset(&mask, sig) < 0) return -1;
9 return sigprocmask(SIG_UNBLOCK, &mask, 0);
10}
lib/libc/wasi/libc-top-half/musl/src/signal/sigrtmax.c deleted-6
......@@ -1,6 +0,0 @@
1#include <signal.h>
2
3int __libc_current_sigrtmax()
4{
5 return _NSIG-1;
6}
lib/libc/wasi/libc-top-half/musl/src/signal/sigrtmin.c deleted-6
......@@ -1,6 +0,0 @@
1#include <signal.h>
2
3int __libc_current_sigrtmin()
4{
5 return 35;
6}
lib/libc/wasi/libc-top-half/musl/src/signal/sigset.c deleted-27
......@@ -1,27 +0,0 @@
1#include <signal.h>
2
3void (*sigset(int sig, void (*handler)(int)))(int)
4{
5 struct sigaction sa, sa_old;
6 sigset_t mask, mask_old;
7
8 sigemptyset(&mask);
9 if (sigaddset(&mask, sig) < 0)
10 return SIG_ERR;
11
12 if (handler == SIG_HOLD) {
13 if (sigaction(sig, 0, &sa_old) < 0)
14 return SIG_ERR;
15 if (sigprocmask(SIG_BLOCK, &mask, &mask_old) < 0)
16 return SIG_ERR;
17 } else {
18 sa.sa_handler = handler;
19 sa.sa_flags = 0;
20 sigemptyset(&sa.sa_mask);
21 if (sigaction(sig, &sa, &sa_old) < 0)
22 return SIG_ERR;
23 if (sigprocmask(SIG_UNBLOCK, &mask, &mask_old) < 0)
24 return SIG_ERR;
25 }
26 return sigismember(&mask_old, sig) ? SIG_HOLD : sa_old.sa_handler;
27}
lib/libc/wasi/libc-top-half/musl/src/signal/sigsetjmp.c deleted
lib/libc/wasi/libc-top-half/musl/src/signal/sigsetjmp_tail.c deleted-10
......@@ -1,10 +0,0 @@
1#include <setjmp.h>
2#include <signal.h>
3#include "syscall.h"
4
5hidden int __sigsetjmp_tail(sigjmp_buf jb, int ret)
6{
7 void *p = jb->__ss;
8 __syscall(SYS_rt_sigprocmask, SIG_SETMASK, ret?p:0, ret?0:p, _NSIG/8);
9 return ret;
10}
lib/libc/wasi/libc-top-half/musl/src/signal/sigsuspend.c deleted-7
......@@ -1,7 +0,0 @@
1#include <signal.h>
2#include "syscall.h"
3
4int sigsuspend(const sigset_t *mask)
5{
6 return syscall_cp(SYS_rt_sigsuspend, mask, _NSIG/8);
7}
lib/libc/wasi/libc-top-half/musl/src/signal/sigtimedwait.c deleted-32
......@@ -1,32 +0,0 @@
1#include <signal.h>
2#include <errno.h>
3#include "syscall.h"
4
5#define IS32BIT(x) !((x)+0x80000000ULL>>32)
6#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
7
8static int do_sigtimedwait(const sigset_t *restrict mask, siginfo_t *restrict si, const struct timespec *restrict ts)
9{
10#ifdef SYS_rt_sigtimedwait_time64
11 time_t s = ts ? ts->tv_sec : 0;
12 long ns = ts ? ts->tv_nsec : 0;
13 int r = -ENOSYS;
14 if (SYS_rt_sigtimedwait == SYS_rt_sigtimedwait_time64 || !IS32BIT(s))
15 r = __syscall_cp(SYS_rt_sigtimedwait_time64, mask, si,
16 ts ? ((long long[]){s, ns}) : 0, _NSIG/8);
17 if (SYS_rt_sigtimedwait == SYS_rt_sigtimedwait_time64 || r!=-ENOSYS)
18 return r;
19 return __syscall_cp(SYS_rt_sigtimedwait, mask, si,
20 ts ? ((long[]){CLAMP(s), ns}) : 0, _NSIG/8);;
21#else
22 return __syscall_cp(SYS_rt_sigtimedwait, mask, si, ts, _NSIG/8);
23#endif
24}
25
26int sigtimedwait(const sigset_t *restrict mask, siginfo_t *restrict si, const struct timespec *restrict timeout)
27{
28 int ret;
29 do ret = do_sigtimedwait(mask, si, timeout);
30 while (ret==-EINTR);
31 return __syscall_ret(ret);
32}
lib/libc/wasi/libc-top-half/musl/src/signal/sigwait.c deleted-10
......@@ -1,10 +0,0 @@
1#include <signal.h>
2
3int sigwait(const sigset_t *restrict mask, int *restrict sig)
4{
5 siginfo_t si;
6 if (sigtimedwait(mask, &si, 0) < 0)
7 return -1;
8 *sig = si.si_signo;
9 return 0;
10}
lib/libc/wasi/libc-top-half/musl/src/signal/sigwaitinfo.c deleted-6
......@@ -1,6 +0,0 @@
1#include <signal.h>
2
3int sigwaitinfo(const sigset_t *restrict mask, siginfo_t *restrict si)
4{
5 return sigtimedwait(mask, si, 0);
6}
lib/libc/wasi/libc-top-half/musl/src/signal/x32/getitimer.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/time.h>
2#include "syscall.h"
3
4int getitimer(int which, struct itimerval *old)
5{
6 return syscall(SYS_getitimer, which, old);
7}
lib/libc/wasi/libc-top-half/musl/src/signal/x32/restore.s deleted-8
......@@ -1,8 +0,0 @@
1 nop
2.global __restore_rt
3.hidden __restore_rt
4.type __restore_rt,@function
5__restore_rt:
6 mov $0x40000201, %rax /* SYS_rt_sigreturn */
7 syscall
8.size __restore_rt,.-__restore_rt
lib/libc/wasi/libc-top-half/musl/src/signal/x32/setitimer.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/time.h>
2#include "syscall.h"
3
4int setitimer(int which, const struct itimerval *restrict new, struct itimerval *restrict old)
5{
6 return syscall(SYS_setitimer, which, new, old);
7}
lib/libc/wasi/libc-top-half/musl/src/signal/x32/sigsetjmp.s deleted-25
......@@ -1,25 +0,0 @@
1.global sigsetjmp
2.global __sigsetjmp
3.type sigsetjmp,@function
4.type __sigsetjmp,@function
5sigsetjmp:
6__sigsetjmp:
7 test %esi,%esi
8 jz 1f
9
10 popq 64(%rdi)
11 mov %rbx,72+8(%rdi)
12 mov %rdi,%rbx
13
14 call setjmp@PLT
15
16 pushq 64(%rbx)
17 movl $0, 4(%rsp)
18 mov %rbx,%rdi
19 mov %eax,%esi
20 mov 72+8(%rbx),%rbx
21
22.hidden __sigsetjmp_tail
23 jmp __sigsetjmp_tail
24
251: jmp setjmp@PLT
lib/libc/wasi/libc-top-half/musl/src/signal/x86_64/restore.s deleted-8
......@@ -1,8 +0,0 @@
1 nop
2.global __restore_rt
3.hidden __restore_rt
4.type __restore_rt,@function
5__restore_rt:
6 mov $15, %rax
7 syscall
8.size __restore_rt,.-__restore_rt
lib/libc/wasi/libc-top-half/musl/src/signal/x86_64/sigsetjmp.s deleted-24
......@@ -1,24 +0,0 @@
1.global sigsetjmp
2.global __sigsetjmp
3.type sigsetjmp,@function
4.type __sigsetjmp,@function
5sigsetjmp:
6__sigsetjmp:
7 test %esi,%esi
8 jz 1f
9
10 popq 64(%rdi)
11 mov %rbx,72+8(%rdi)
12 mov %rdi,%rbx
13
14 call setjmp@PLT
15
16 pushq 64(%rbx)
17 mov %rbx,%rdi
18 mov %eax,%esi
19 mov 72+8(%rbx),%rbx
20
21.hidden __sigsetjmp_tail
22 jmp __sigsetjmp_tail
23
241: jmp setjmp@PLT
lib/libc/wasi/libc-top-half/musl/src/stat/__xstat.c deleted-40
......@@ -1,40 +0,0 @@
1#include <sys/stat.h>
2
3#if !_REDIR_TIME64
4
5int __fxstat(int ver, int fd, struct stat *buf)
6{
7 return fstat(fd, buf);
8}
9
10int __fxstatat(int ver, int fd, const char *path, struct stat *buf, int flag)
11{
12 return fstatat(fd, path, buf, flag);
13}
14
15int __lxstat(int ver, const char *path, struct stat *buf)
16{
17 return lstat(path, buf);
18}
19
20int __xstat(int ver, const char *path, struct stat *buf)
21{
22 return stat(path, buf);
23}
24
25weak_alias(__fxstat, __fxstat64);
26weak_alias(__fxstatat, __fxstatat64);
27weak_alias(__lxstat, __lxstat64);
28weak_alias(__xstat, __xstat64);
29
30#endif
31
32int __xmknod(int ver, const char *path, mode_t mode, dev_t *dev)
33{
34 return mknod(path, mode, *dev);
35}
36
37int __xmknodat(int ver, int fd, const char *path, mode_t mode, dev_t *dev)
38{
39 return mknodat(fd, path, mode, *dev);
40}
lib/libc/wasi/libc-top-half/musl/src/stat/chmod.c deleted-12
......@@ -1,12 +0,0 @@
1#include <sys/stat.h>
2#include <fcntl.h>
3#include "syscall.h"
4
5int chmod(const char *path, mode_t mode)
6{
7#ifdef SYS_chmod
8 return syscall(SYS_chmod, path, mode);
9#else
10 return syscall(SYS_fchmodat, AT_FDCWD, path, mode);
11#endif
12}
lib/libc/wasi/libc-top-half/musl/src/stat/fchmod.c deleted-19
......@@ -1,19 +0,0 @@
1#include <sys/stat.h>
2#include <errno.h>
3#include <fcntl.h>
4#include "syscall.h"
5
6int fchmod(int fd, mode_t mode)
7{
8 int ret = __syscall(SYS_fchmod, fd, mode);
9 if (ret != -EBADF || __syscall(SYS_fcntl, fd, F_GETFD) < 0)
10 return __syscall_ret(ret);
11
12 char buf[15+3*sizeof(int)];
13 __procfdname(buf, fd);
14#ifdef SYS_chmod
15 return syscall(SYS_chmod, buf, mode);
16#else
17 return syscall(SYS_fchmodat, AT_FDCWD, buf, mode);
18#endif
19}
lib/libc/wasi/libc-top-half/musl/src/stat/fchmodat.c deleted-38
......@@ -1,38 +0,0 @@
1#include <sys/stat.h>
2#include <fcntl.h>
3#include <errno.h>
4#include "syscall.h"
5#include "kstat.h"
6
7int fchmodat(int fd, const char *path, mode_t mode, int flag)
8{
9 if (!flag) return syscall(SYS_fchmodat, fd, path, mode, flag);
10
11 if (flag != AT_SYMLINK_NOFOLLOW)
12 return __syscall_ret(-EINVAL);
13
14 struct kstat st;
15 int ret, fd2;
16 char proc[15+3*sizeof(int)];
17
18 if ((ret = __syscall(SYS_fstatat, fd, path, &st, flag)))
19 return __syscall_ret(ret);
20 if (S_ISLNK(st.st_mode))
21 return __syscall_ret(-EOPNOTSUPP);
22
23 if ((fd2 = __syscall(SYS_openat, fd, path, O_RDONLY|O_PATH|O_NOFOLLOW|O_NOCTTY|O_CLOEXEC)) < 0) {
24 if (fd2 == -ELOOP)
25 return __syscall_ret(-EOPNOTSUPP);
26 return __syscall_ret(fd2);
27 }
28
29 __procfdname(proc, fd2);
30 ret = __syscall(SYS_fstatat, AT_FDCWD, proc, &st, 0);
31 if (!ret) {
32 if (S_ISLNK(st.st_mode)) ret = -EOPNOTSUPP;
33 else ret = __syscall(SYS_fchmodat, AT_FDCWD, proc, mode);
34 }
35
36 __syscall(SYS_close, fd2);
37 return __syscall_ret(ret);
38}
lib/libc/wasi/libc-top-half/musl/src/stat/fstat.c deleted-15
......@@ -1,15 +0,0 @@
1#define _BSD_SOURCE
2#include <sys/stat.h>
3#include <errno.h>
4#include <fcntl.h>
5#include "syscall.h"
6
7int fstat(int fd, struct stat *st)
8{
9 if (fd<0) return __syscall_ret(-EBADF);
10 return fstatat(fd, "", st, AT_EMPTY_PATH);
11}
12
13#if !_REDIR_TIME64
14weak_alias(fstat, fstat64);
15#endif
lib/libc/wasi/libc-top-half/musl/src/stat/fstatat.c deleted-147
......@@ -1,147 +0,0 @@
1#define _BSD_SOURCE
2#include <sys/stat.h>
3#include <string.h>
4#include <fcntl.h>
5#include <errno.h>
6#include <stdint.h>
7#include <sys/sysmacros.h>
8#include "syscall.h"
9#include "kstat.h"
10
11struct statx {
12 uint32_t stx_mask;
13 uint32_t stx_blksize;
14 uint64_t stx_attributes;
15 uint32_t stx_nlink;
16 uint32_t stx_uid;
17 uint32_t stx_gid;
18 uint16_t stx_mode;
19 uint16_t pad1;
20 uint64_t stx_ino;
21 uint64_t stx_size;
22 uint64_t stx_blocks;
23 uint64_t stx_attributes_mask;
24 struct {
25 int64_t tv_sec;
26 uint32_t tv_nsec;
27 int32_t pad;
28 } stx_atime, stx_btime, stx_ctime, stx_mtime;
29 uint32_t stx_rdev_major;
30 uint32_t stx_rdev_minor;
31 uint32_t stx_dev_major;
32 uint32_t stx_dev_minor;
33 uint64_t spare[14];
34};
35
36static int fstatat_statx(int fd, const char *restrict path, struct stat *restrict st, int flag)
37{
38 struct statx stx;
39
40 int ret = __syscall(SYS_statx, fd, path, flag, 0x7ff, &stx);
41 if (ret) return ret;
42
43 *st = (struct stat){
44 .st_dev = makedev(stx.stx_dev_major, stx.stx_dev_minor),
45 .st_ino = stx.stx_ino,
46 .st_mode = stx.stx_mode,
47 .st_nlink = stx.stx_nlink,
48 .st_uid = stx.stx_uid,
49 .st_gid = stx.stx_gid,
50 .st_rdev = makedev(stx.stx_rdev_major, stx.stx_rdev_minor),
51 .st_size = stx.stx_size,
52 .st_blksize = stx.stx_blksize,
53 .st_blocks = stx.stx_blocks,
54 .st_atim.tv_sec = stx.stx_atime.tv_sec,
55 .st_atim.tv_nsec = stx.stx_atime.tv_nsec,
56 .st_mtim.tv_sec = stx.stx_mtime.tv_sec,
57 .st_mtim.tv_nsec = stx.stx_mtime.tv_nsec,
58 .st_ctim.tv_sec = stx.stx_ctime.tv_sec,
59 .st_ctim.tv_nsec = stx.stx_ctime.tv_nsec,
60#if _REDIR_TIME64
61 .__st_atim32.tv_sec = stx.stx_atime.tv_sec,
62 .__st_atim32.tv_nsec = stx.stx_atime.tv_nsec,
63 .__st_mtim32.tv_sec = stx.stx_mtime.tv_sec,
64 .__st_mtim32.tv_nsec = stx.stx_mtime.tv_nsec,
65 .__st_ctim32.tv_sec = stx.stx_ctime.tv_sec,
66 .__st_ctim32.tv_nsec = stx.stx_ctime.tv_nsec,
67#endif
68 };
69 return 0;
70}
71
72static int fstatat_kstat(int fd, const char *restrict path, struct stat *restrict st, int flag)
73{
74 int ret;
75 struct kstat kst;
76
77 if (flag==AT_EMPTY_PATH && fd>=0 && !*path) {
78 ret = __syscall(SYS_fstat, fd, &kst);
79 if (ret==-EBADF && __syscall(SYS_fcntl, fd, F_GETFD)>=0) {
80 ret = __syscall(SYS_fstatat, fd, path, &kst, flag);
81 if (ret==-EINVAL) {
82 char buf[15+3*sizeof(int)];
83 __procfdname(buf, fd);
84#ifdef SYS_stat
85 ret = __syscall(SYS_stat, buf, &kst);
86#else
87 ret = __syscall(SYS_fstatat, AT_FDCWD, buf, &kst, 0);
88#endif
89 }
90 }
91 }
92#ifdef SYS_lstat
93 else if ((fd == AT_FDCWD || *path=='/') && flag==AT_SYMLINK_NOFOLLOW)
94 ret = __syscall(SYS_lstat, path, &kst);
95#endif
96#ifdef SYS_stat
97 else if ((fd == AT_FDCWD || *path=='/') && !flag)
98 ret = __syscall(SYS_stat, path, &kst);
99#endif
100 else ret = __syscall(SYS_fstatat, fd, path, &kst, flag);
101
102 if (ret) return ret;
103
104 *st = (struct stat){
105 .st_dev = kst.st_dev,
106 .st_ino = kst.st_ino,
107 .st_mode = kst.st_mode,
108 .st_nlink = kst.st_nlink,
109 .st_uid = kst.st_uid,
110 .st_gid = kst.st_gid,
111 .st_rdev = kst.st_rdev,
112 .st_size = kst.st_size,
113 .st_blksize = kst.st_blksize,
114 .st_blocks = kst.st_blocks,
115 .st_atim.tv_sec = kst.st_atime_sec,
116 .st_atim.tv_nsec = kst.st_atime_nsec,
117 .st_mtim.tv_sec = kst.st_mtime_sec,
118 .st_mtim.tv_nsec = kst.st_mtime_nsec,
119 .st_ctim.tv_sec = kst.st_ctime_sec,
120 .st_ctim.tv_nsec = kst.st_ctime_nsec,
121#if _REDIR_TIME64
122 .__st_atim32.tv_sec = kst.st_atime_sec,
123 .__st_atim32.tv_nsec = kst.st_atime_nsec,
124 .__st_mtim32.tv_sec = kst.st_mtime_sec,
125 .__st_mtim32.tv_nsec = kst.st_mtime_nsec,
126 .__st_ctim32.tv_sec = kst.st_ctime_sec,
127 .__st_ctim32.tv_nsec = kst.st_ctime_nsec,
128#endif
129 };
130
131 return 0;
132}
133
134int fstatat(int fd, const char *restrict path, struct stat *restrict st, int flag)
135{
136 int ret;
137 if (sizeof((struct kstat){0}.st_atime_sec) < sizeof(time_t)) {
138 ret = fstatat_statx(fd, path, st, flag);
139 if (ret!=-ENOSYS) return __syscall_ret(ret);
140 }
141 ret = fstatat_kstat(fd, path, st, flag);
142 return __syscall_ret(ret);
143}
144
145#if !_REDIR_TIME64
146weak_alias(fstatat, fstatat64);
147#endif
lib/libc/wasi/libc-top-half/musl/src/stat/futimens.c deleted-6
......@@ -1,6 +0,0 @@
1#include <sys/stat.h>
2
3int futimens(int fd, const struct timespec times[2])
4{
5 return utimensat(fd, 0, times, 0);
6}
lib/libc/wasi/libc-top-half/musl/src/stat/lchmod.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <sys/stat.h>
3#include <fcntl.h>
4
5int lchmod(const char *path, mode_t mode)
6{
7 return fchmodat(AT_FDCWD, path, mode, AT_SYMLINK_NOFOLLOW);
8}
lib/libc/wasi/libc-top-half/musl/src/stat/lstat.c deleted-11
......@@ -1,11 +0,0 @@
1#include <sys/stat.h>
2#include <fcntl.h>
3
4int lstat(const char *restrict path, struct stat *restrict buf)
5{
6 return fstatat(AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW);
7}
8
9#if !_REDIR_TIME64
10weak_alias(lstat, lstat64);
11#endif
lib/libc/wasi/libc-top-half/musl/src/stat/mkdir.c deleted-12
......@@ -1,12 +0,0 @@
1#include <sys/stat.h>
2#include <fcntl.h>
3#include "syscall.h"
4
5int mkdir(const char *path, mode_t mode)
6{
7#ifdef SYS_mkdir
8 return syscall(SYS_mkdir, path, mode);
9#else
10 return syscall(SYS_mkdirat, AT_FDCWD, path, mode);
11#endif
12}
lib/libc/wasi/libc-top-half/musl/src/stat/mkdirat.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/stat.h>
2#include "syscall.h"
3
4int mkdirat(int fd, const char *path, mode_t mode)
5{
6 return syscall(SYS_mkdirat, fd, path, mode);
7}
lib/libc/wasi/libc-top-half/musl/src/stat/mkfifo.c deleted-6
......@@ -1,6 +0,0 @@
1#include <sys/stat.h>
2
3int mkfifo(const char *path, mode_t mode)
4{
5 return mknod(path, mode | S_IFIFO, 0);
6}
lib/libc/wasi/libc-top-half/musl/src/stat/mkfifoat.c deleted-6
......@@ -1,6 +0,0 @@
1#include <sys/stat.h>
2
3int mkfifoat(int fd, const char *path, mode_t mode)
4{
5 return mknodat(fd, path, mode | S_IFIFO, 0);
6}
lib/libc/wasi/libc-top-half/musl/src/stat/mknod.c deleted-12
......@@ -1,12 +0,0 @@
1#include <sys/stat.h>
2#include <fcntl.h>
3#include "syscall.h"
4
5int mknod(const char *path, mode_t mode, dev_t dev)
6{
7#ifdef SYS_mknod
8 return syscall(SYS_mknod, path, mode, dev);
9#else
10 return syscall(SYS_mknodat, AT_FDCWD, path, mode, dev);
11#endif
12}
lib/libc/wasi/libc-top-half/musl/src/stat/mknodat.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/stat.h>
2#include "syscall.h"
3
4int mknodat(int fd, const char *path, mode_t mode, dev_t dev)
5{
6 return syscall(SYS_mknodat, fd, path, mode, dev);
7}
lib/libc/wasi/libc-top-half/musl/src/stat/stat.c deleted-11
......@@ -1,11 +0,0 @@
1#include <sys/stat.h>
2#include <fcntl.h>
3
4int stat(const char *restrict path, struct stat *restrict buf)
5{
6 return fstatat(AT_FDCWD, path, buf, 0);
7}
8
9#if !_REDIR_TIME64
10weak_alias(stat, stat64);
11#endif
lib/libc/wasi/libc-top-half/musl/src/stat/statvfs.c deleted-63
......@@ -1,63 +0,0 @@
1#include <sys/statvfs.h>
2#include <sys/statfs.h>
3#include "syscall.h"
4
5static int __statfs(const char *path, struct statfs *buf)
6{
7 *buf = (struct statfs){0};
8#ifdef SYS_statfs64
9 return syscall(SYS_statfs64, path, sizeof *buf, buf);
10#else
11 return syscall(SYS_statfs, path, buf);
12#endif
13}
14
15static int __fstatfs(int fd, struct statfs *buf)
16{
17 *buf = (struct statfs){0};
18#ifdef SYS_fstatfs64
19 return syscall(SYS_fstatfs64, fd, sizeof *buf, buf);
20#else
21 return syscall(SYS_fstatfs, fd, buf);
22#endif
23}
24
25weak_alias(__statfs, statfs);
26weak_alias(__fstatfs, fstatfs);
27
28static void fixup(struct statvfs *out, const struct statfs *in)
29{
30 *out = (struct statvfs){0};
31 out->f_bsize = in->f_bsize;
32 out->f_frsize = in->f_frsize ? in->f_frsize : in->f_bsize;
33 out->f_blocks = in->f_blocks;
34 out->f_bfree = in->f_bfree;
35 out->f_bavail = in->f_bavail;
36 out->f_files = in->f_files;
37 out->f_ffree = in->f_ffree;
38 out->f_favail = in->f_ffree;
39 out->f_fsid = in->f_fsid.__val[0];
40 out->f_flag = in->f_flags;
41 out->f_namemax = in->f_namelen;
42}
43
44int statvfs(const char *restrict path, struct statvfs *restrict buf)
45{
46 struct statfs kbuf;
47 if (__statfs(path, &kbuf)<0) return -1;
48 fixup(buf, &kbuf);
49 return 0;
50}
51
52int fstatvfs(int fd, struct statvfs *buf)
53{
54 struct statfs kbuf;
55 if (__fstatfs(fd, &kbuf)<0) return -1;
56 fixup(buf, &kbuf);
57 return 0;
58}
59
60weak_alias(statvfs, statvfs64);
61weak_alias(statfs, statfs64);
62weak_alias(fstatvfs, fstatvfs64);
63weak_alias(fstatfs, fstatfs64);
lib/libc/wasi/libc-top-half/musl/src/stat/umask.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/stat.h>
2#include "syscall.h"
3
4mode_t umask(mode_t mode)
5{
6 return syscall(SYS_umask, mode);
7}
lib/libc/wasi/libc-top-half/musl/src/stat/utimensat.c deleted-60
......@@ -1,60 +0,0 @@
1#include <sys/stat.h>
2#include <sys/time.h>
3#include <fcntl.h>
4#include <errno.h>
5#include "syscall.h"
6
7#define IS32BIT(x) !((x)+0x80000000ULL>>32)
8#define NS_SPECIAL(ns) ((ns)==UTIME_NOW || (ns)==UTIME_OMIT)
9
10int utimensat(int fd, const char *path, const struct timespec times[2], int flags)
11{
12 int r;
13 if (times && times[0].tv_nsec==UTIME_NOW && times[1].tv_nsec==UTIME_NOW)
14 times = 0;
15#ifdef SYS_utimensat_time64
16 r = -ENOSYS;
17 time_t s0=0, s1=0;
18 long ns0=0, ns1=0;
19 if (times) {
20 ns0 = times[0].tv_nsec;
21 ns1 = times[1].tv_nsec;
22 if (!NS_SPECIAL(ns0)) s0 = times[0].tv_sec;
23 if (!NS_SPECIAL(ns1)) s1 = times[1].tv_sec;
24 }
25 if (SYS_utimensat == SYS_utimensat_time64 || !IS32BIT(s0) || !IS32BIT(s1))
26 r = __syscall(SYS_utimensat_time64, fd, path, times ?
27 ((long long[]){s0, ns0, s1, ns1}) : 0, flags);
28 if (SYS_utimensat == SYS_utimensat_time64 || r!=-ENOSYS)
29 return __syscall_ret(r);
30 if (!IS32BIT(s0) || !IS32BIT(s1))
31 return __syscall_ret(-ENOTSUP);
32 r = __syscall(SYS_utimensat, fd, path,
33 times ? ((long[]){s0, ns0, s1, ns1}) : 0, flags);
34#else
35 r = __syscall(SYS_utimensat, fd, path, times, flags);
36#endif
37
38#ifdef SYS_futimesat
39 if (r != -ENOSYS || flags) return __syscall_ret(r);
40 long *tv=0, tmp[4];
41 if (times) {
42 int i;
43 tv = tmp;
44 for (i=0; i<2; i++) {
45 if (times[i].tv_nsec >= 1000000000ULL) {
46 if (NS_SPECIAL(times[i].tv_nsec))
47 return __syscall_ret(-ENOSYS);
48 return __syscall_ret(-EINVAL);
49 }
50 tmp[2*i+0] = times[i].tv_sec;
51 tmp[2*i+1] = times[i].tv_nsec / 1000;
52 }
53 }
54
55 r = __syscall(SYS_futimesat, fd, path, tv);
56 if (r != -ENOSYS || fd != AT_FDCWD) return __syscall_ret(r);
57 r = __syscall(SYS_utimes, path, tv);
58#endif
59 return __syscall_ret(r);
60}
lib/libc/wasi/libc-top-half/musl/src/stdio/__lockfile.c deleted-23
......@@ -1,23 +0,0 @@
1#include "stdio_impl.h"
2#include "pthread_impl.h"
3
4int __lockfile(FILE *f)
5{
6 int owner = f->lock, tid = __pthread_self()->tid;
7 if ((owner & ~MAYBE_WAITERS) == tid)
8 return 0;
9 owner = a_cas(&f->lock, 0, tid);
10 if (!owner) return 1;
11 while ((owner = a_cas(&f->lock, 0, tid|MAYBE_WAITERS))) {
12 if ((owner & MAYBE_WAITERS) ||
13 a_cas(&f->lock, owner, owner|MAYBE_WAITERS)==owner)
14 __futexwait(&f->lock, owner|MAYBE_WAITERS, 1);
15 }
16 return 1;
17}
18
19void __unlockfile(FILE *f)
20{
21 if (a_swap(&f->lock, 0) & MAYBE_WAITERS)
22 __wake(&f->lock, 1, 1);
23}
lib/libc/wasi/libc-top-half/musl/src/stdio/flockfile.c deleted-9
......@@ -1,9 +0,0 @@
1#include "stdio_impl.h"
2#include "pthread_impl.h"
3
4void flockfile(FILE *f)
5{
6 if (!ftrylockfile(f)) return;
7 __lockfile(f);
8 __register_locked_file(f, __pthread_self());
9}
lib/libc/wasi/libc-top-half/musl/src/stdio/ftrylockfile.c deleted-46
......@@ -1,46 +0,0 @@
1#include "stdio_impl.h"
2#include "pthread_impl.h"
3#include <limits.h>
4
5void __do_orphaned_stdio_locks()
6{
7 FILE *f;
8 for (f=__pthread_self()->stdio_locks; f; f=f->next_locked)
9 a_store(&f->lock, 0x40000000);
10}
11
12void __unlist_locked_file(FILE *f)
13{
14 if (f->lockcount) {
15 if (f->next_locked) f->next_locked->prev_locked = f->prev_locked;
16 if (f->prev_locked) f->prev_locked->next_locked = f->next_locked;
17 else __pthread_self()->stdio_locks = f->next_locked;
18 }
19}
20
21void __register_locked_file(FILE *f, pthread_t self)
22{
23 f->lockcount = 1;
24 f->prev_locked = 0;
25 f->next_locked = self->stdio_locks;
26 if (f->next_locked) f->next_locked->prev_locked = f;
27 self->stdio_locks = f;
28}
29
30int ftrylockfile(FILE *f)
31{
32 pthread_t self = __pthread_self();
33 int tid = self->tid;
34 int owner = f->lock;
35 if ((owner & ~MAYBE_WAITERS) == tid) {
36 if (f->lockcount == LONG_MAX)
37 return -1;
38 f->lockcount++;
39 return 0;
40 }
41 if (owner < 0) f->lock = owner = 0;
42 if (owner || a_cas(&f->lock, 0, tid))
43 return -1;
44 __register_locked_file(f, self);
45 return 0;
46}
lib/libc/wasi/libc-top-half/musl/src/stdio/funlockfile.c deleted-13
......@@ -1,13 +0,0 @@
1#include "stdio_impl.h"
2#include "pthread_impl.h"
3
4void funlockfile(FILE *f)
5{
6 if (f->lockcount == 1) {
7 __unlist_locked_file(f);
8 f->lockcount = 0;
9 __unlockfile(f);
10 } else {
11 f->lockcount--;
12 }
13}
lib/libc/wasi/libc-top-half/musl/src/stdio/gets.c deleted-15
......@@ -1,15 +0,0 @@
1#include "stdio_impl.h"
2#include <limits.h>
3#include <string.h>
4
5char *gets(char *s)
6{
7 size_t i=0;
8 int c;
9 FLOCK(stdin);
10 while ((c=getc_unlocked(stdin)) != EOF && c != '\n') s[i++] = c;
11 s[i] = 0;
12 if (c != '\n' && (!feof(stdin) || !i)) s = 0;
13 FUNLOCK(stdin);
14 return s;
15}
lib/libc/wasi/libc-top-half/musl/src/stdio/pclose.c deleted-13
......@@ -1,13 +0,0 @@
1#include "stdio_impl.h"
2#include <errno.h>
3#include <unistd.h>
4
5int pclose(FILE *f)
6{
7 int status, r;
8 pid_t pid = f->pipe_pid;
9 fclose(f);
10 while ((r=__syscall(SYS_wait4, pid, &status, 0, 0)) == -EINTR);
11 if (r<0) return __syscall_ret(r);
12 return status;
13}
lib/libc/wasi/libc-top-half/musl/src/stdio/popen.c deleted-61
......@@ -1,61 +0,0 @@
1#include <fcntl.h>
2#include <unistd.h>
3#include <errno.h>
4#include <string.h>
5#include <spawn.h>
6#include "stdio_impl.h"
7#include "syscall.h"
8
9extern char **__environ;
10
11FILE *popen(const char *cmd, const char *mode)
12{
13 int p[2], op, e;
14 pid_t pid;
15 FILE *f;
16 posix_spawn_file_actions_t fa;
17
18 if (*mode == 'r') {
19 op = 0;
20 } else if (*mode == 'w') {
21 op = 1;
22 } else {
23 errno = EINVAL;
24 return 0;
25 }
26
27 if (pipe2(p, O_CLOEXEC)) return NULL;
28 f = fdopen(p[op], mode);
29 if (!f) {
30 __syscall(SYS_close, p[0]);
31 __syscall(SYS_close, p[1]);
32 return NULL;
33 }
34
35 e = ENOMEM;
36 if (!posix_spawn_file_actions_init(&fa)) {
37 for (FILE *l = *__ofl_lock(); l; l=l->next)
38 if (l->pipe_pid && posix_spawn_file_actions_addclose(&fa, l->fd))
39 goto fail;
40 if (!posix_spawn_file_actions_adddup2(&fa, p[1-op], 1-op)) {
41 if (!(e = posix_spawn(&pid, "/bin/sh", &fa, 0,
42 (char *[]){ "sh", "-c", (char *)cmd, 0 }, __environ))) {
43 posix_spawn_file_actions_destroy(&fa);
44 f->pipe_pid = pid;
45 if (!strchr(mode, 'e'))
46 fcntl(p[op], F_SETFD, 0);
47 __syscall(SYS_close, p[1-op]);
48 __ofl_unlock();
49 return f;
50 }
51 }
52fail:
53 __ofl_unlock();
54 posix_spawn_file_actions_destroy(&fa);
55 }
56 fclose(f);
57 __syscall(SYS_close, p[1-op]);
58
59 errno = e;
60 return 0;
61}
lib/libc/wasi/libc-top-half/musl/src/stdio/remove.c deleted-19
......@@ -1,19 +0,0 @@
1#include <stdio.h>
2#include <errno.h>
3#include <fcntl.h>
4#include "syscall.h"
5
6int remove(const char *path)
7{
8#ifdef SYS_unlink
9 int r = __syscall(SYS_unlink, path);
10#else
11 int r = __syscall(SYS_unlinkat, AT_FDCWD, path, 0);
12#endif
13#ifdef SYS_rmdir
14 if (r==-EISDIR) r = __syscall(SYS_rmdir, path);
15#else
16 if (r==-EISDIR) r = __syscall(SYS_unlinkat, AT_FDCWD, path, AT_REMOVEDIR);
17#endif
18 return __syscall_ret(r);
19}
lib/libc/wasi/libc-top-half/musl/src/stdio/rename.c deleted-14
......@@ -1,14 +0,0 @@
1#include <stdio.h>
2#include <fcntl.h>
3#include "syscall.h"
4
5int rename(const char *old, const char *new)
6{
7#if defined(SYS_rename)
8 return syscall(SYS_rename, old, new);
9#elif defined(SYS_renameat)
10 return syscall(SYS_renameat, AT_FDCWD, old, AT_FDCWD, new);
11#else
12 return syscall(SYS_renameat2, AT_FDCWD, old, AT_FDCWD, new, 0);
13#endif
14}
lib/libc/wasi/libc-top-half/musl/src/stdio/tempnam.c deleted-49
......@@ -1,49 +0,0 @@
1#include <stdio.h>
2#include <fcntl.h>
3#include <errno.h>
4#include <sys/stat.h>
5#include <limits.h>
6#include <string.h>
7#include <stdlib.h>
8#include "syscall.h"
9#include "kstat.h"
10
11#define MAXTRIES 100
12
13char *tempnam(const char *dir, const char *pfx)
14{
15 char s[PATH_MAX];
16 size_t l, dl, pl;
17 int try;
18 int r;
19
20 if (!dir) dir = P_tmpdir;
21 if (!pfx) pfx = "temp";
22
23 dl = strlen(dir);
24 pl = strlen(pfx);
25 l = dl + 1 + pl + 1 + 6;
26
27 if (l >= PATH_MAX) {
28 errno = ENAMETOOLONG;
29 return 0;
30 }
31
32 memcpy(s, dir, dl);
33 s[dl] = '/';
34 memcpy(s+dl+1, pfx, pl);
35 s[dl+1+pl] = '_';
36 s[l] = 0;
37
38 for (try=0; try<MAXTRIES; try++) {
39 __randname(s+l-6);
40#ifdef SYS_lstat
41 r = __syscall(SYS_lstat, s, &(struct kstat){0});
42#else
43 r = __syscall(SYS_fstatat, AT_FDCWD, s,
44 &(struct kstat){0}, AT_SYMLINK_NOFOLLOW);
45#endif
46 if (r == -ENOENT) return strdup(s);
47 }
48 return 0;
49}
lib/libc/wasi/libc-top-half/musl/src/stdio/tmpfile.c deleted-31
......@@ -1,31 +0,0 @@
1#include <stdio.h>
2#include <fcntl.h>
3#include <stdlib.h>
4#include "stdio_impl.h"
5
6#define MAXTRIES 100
7
8FILE *tmpfile(void)
9{
10 char s[] = "/tmp/tmpfile_XXXXXX";
11 int fd;
12 FILE *f;
13 int try;
14 for (try=0; try<MAXTRIES; try++) {
15 __randname(s+13);
16 fd = sys_open(s, O_RDWR|O_CREAT|O_EXCL, 0600);
17 if (fd >= 0) {
18#ifdef SYS_unlink
19 __syscall(SYS_unlink, s);
20#else
21 __syscall(SYS_unlinkat, AT_FDCWD, s, 0);
22#endif
23 f = __fdopen(fd, "w+");
24 if (!f) __syscall(SYS_close, fd);
25 return f;
26 }
27 }
28 return 0;
29}
30
31weak_alias(tmpfile, tmpfile64);
lib/libc/wasi/libc-top-half/musl/src/stdio/tmpnam.c deleted-29
......@@ -1,29 +0,0 @@
1#include <stdio.h>
2#include <fcntl.h>
3#include <errno.h>
4#include <sys/stat.h>
5#include <string.h>
6#include <stdlib.h>
7#include "syscall.h"
8#include "kstat.h"
9
10#define MAXTRIES 100
11
12char *tmpnam(char *buf)
13{
14 static char internal[L_tmpnam];
15 char s[] = "/tmp/tmpnam_XXXXXX";
16 int try;
17 int r;
18 for (try=0; try<MAXTRIES; try++) {
19 __randname(s+12);
20#ifdef SYS_lstat
21 r = __syscall(SYS_lstat, s, &(struct kstat){0});
22#else
23 r = __syscall(SYS_fstatat, AT_FDCWD, s,
24 &(struct kstat){0}, AT_SYMLINK_NOFOLLOW);
25#endif
26 if (r == -ENOENT) return strcpy(buf ? buf : internal, s);
27 }
28 return 0;
29}
lib/libc/wasi/libc-top-half/musl/src/string/arm/__aeabi_memcpy.s deleted-45
......@@ -1,45 +0,0 @@
1.syntax unified
2
3.global __aeabi_memcpy8
4.global __aeabi_memcpy4
5.global __aeabi_memcpy
6.global __aeabi_memmove8
7.global __aeabi_memmove4
8.global __aeabi_memmove
9
10.type __aeabi_memcpy8,%function
11.type __aeabi_memcpy4,%function
12.type __aeabi_memcpy,%function
13.type __aeabi_memmove8,%function
14.type __aeabi_memmove4,%function
15.type __aeabi_memmove,%function
16
17__aeabi_memmove8:
18__aeabi_memmove4:
19__aeabi_memmove:
20 cmp r0, r1
21 bls 3f
22 cmp r2, #0
23 beq 2f
24 adds r0, r0, r2
25 adds r2, r1, r2
261: subs r2, r2, #1
27 ldrb r3, [r2]
28 subs r0, r0, #1
29 strb r3, [r0]
30 cmp r1, r2
31 bne 1b
322: bx lr
33__aeabi_memcpy8:
34__aeabi_memcpy4:
35__aeabi_memcpy:
363: cmp r2, #0
37 beq 2f
38 adds r2, r1, r2
391: ldrb r3, [r1]
40 adds r1, r1, #1
41 strb r3, [r0]
42 adds r0, r0, #1
43 cmp r1, r2
44 bne 1b
452: bx lr
lib/libc/wasi/libc-top-half/musl/src/string/arm/__aeabi_memset.s deleted-31
......@@ -1,31 +0,0 @@
1.syntax unified
2
3.global __aeabi_memclr8
4.global __aeabi_memclr4
5.global __aeabi_memclr
6.global __aeabi_memset8
7.global __aeabi_memset4
8.global __aeabi_memset
9
10.type __aeabi_memclr8,%function
11.type __aeabi_memclr4,%function
12.type __aeabi_memclr,%function
13.type __aeabi_memset8,%function
14.type __aeabi_memset4,%function
15.type __aeabi_memset,%function
16
17__aeabi_memclr8:
18__aeabi_memclr4:
19__aeabi_memclr:
20 movs r2, #0
21__aeabi_memset8:
22__aeabi_memset4:
23__aeabi_memset:
24 cmp r1, #0
25 beq 2f
26 adds r1, r0, r1
271: strb r2, [r0]
28 adds r0, r0, #1
29 cmp r1, r0
30 bne 1b
312: bx lr
lib/libc/wasi/libc-top-half/musl/src/string/i386/memcpy.s deleted-32
......@@ -1,32 +0,0 @@
1.global memcpy
2.global __memcpy_fwd
3.hidden __memcpy_fwd
4.type memcpy,@function
5memcpy:
6__memcpy_fwd:
7 push %esi
8 push %edi
9 mov 12(%esp),%edi
10 mov 16(%esp),%esi
11 mov 20(%esp),%ecx
12 mov %edi,%eax
13 cmp $4,%ecx
14 jc 1f
15 test $3,%edi
16 jz 1f
172: movsb
18 dec %ecx
19 test $3,%edi
20 jnz 2b
211: mov %ecx,%edx
22 shr $2,%ecx
23 rep
24 movsl
25 and $3,%edx
26 jz 1f
272: movsb
28 dec %edx
29 jnz 2b
301: pop %edi
31 pop %esi
32 ret
lib/libc/wasi/libc-top-half/musl/src/string/i386/memmove.s deleted-22
......@@ -1,22 +0,0 @@
1.global memmove
2.type memmove,@function
3memmove:
4 mov 4(%esp),%eax
5 sub 8(%esp),%eax
6 cmp 12(%esp),%eax
7.hidden __memcpy_fwd
8 jae __memcpy_fwd
9 push %esi
10 push %edi
11 mov 12(%esp),%edi
12 mov 16(%esp),%esi
13 mov 20(%esp),%ecx
14 lea -1(%edi,%ecx),%edi
15 lea -1(%esi,%ecx),%esi
16 std
17 rep movsb
18 cld
19 lea 1(%edi),%eax
20 pop %edi
21 pop %esi
22 ret
lib/libc/wasi/libc-top-half/musl/src/string/i386/memset.s deleted-76
......@@ -1,76 +0,0 @@
1.global memset
2.type memset,@function
3memset:
4 mov 12(%esp),%ecx
5 cmp $62,%ecx
6 ja 2f
7
8 mov 8(%esp),%dl
9 mov 4(%esp),%eax
10 test %ecx,%ecx
11 jz 1f
12
13 mov %dl,%dh
14
15 mov %dl,(%eax)
16 mov %dl,-1(%eax,%ecx)
17 cmp $2,%ecx
18 jbe 1f
19
20 mov %dx,1(%eax)
21 mov %dx,(-1-2)(%eax,%ecx)
22 cmp $6,%ecx
23 jbe 1f
24
25 shl $16,%edx
26 mov 8(%esp),%dl
27 mov 8(%esp),%dh
28
29 mov %edx,(1+2)(%eax)
30 mov %edx,(-1-2-4)(%eax,%ecx)
31 cmp $14,%ecx
32 jbe 1f
33
34 mov %edx,(1+2+4)(%eax)
35 mov %edx,(1+2+4+4)(%eax)
36 mov %edx,(-1-2-4-8)(%eax,%ecx)
37 mov %edx,(-1-2-4-4)(%eax,%ecx)
38 cmp $30,%ecx
39 jbe 1f
40
41 mov %edx,(1+2+4+8)(%eax)
42 mov %edx,(1+2+4+8+4)(%eax)
43 mov %edx,(1+2+4+8+8)(%eax)
44 mov %edx,(1+2+4+8+12)(%eax)
45 mov %edx,(-1-2-4-8-16)(%eax,%ecx)
46 mov %edx,(-1-2-4-8-12)(%eax,%ecx)
47 mov %edx,(-1-2-4-8-8)(%eax,%ecx)
48 mov %edx,(-1-2-4-8-4)(%eax,%ecx)
49
501: ret
51
522: movzbl 8(%esp),%eax
53 mov %edi,12(%esp)
54 imul $0x1010101,%eax
55 mov 4(%esp),%edi
56 test $15,%edi
57 mov %eax,-4(%edi,%ecx)
58 jnz 2f
59
601: shr $2, %ecx
61 rep
62 stosl
63 mov 4(%esp),%eax
64 mov 12(%esp),%edi
65 ret
66
672: xor %edx,%edx
68 sub %edi,%edx
69 and $15,%edx
70 mov %eax,(%edi)
71 mov %eax,4(%edi)
72 mov %eax,8(%edi)
73 mov %eax,12(%edi)
74 sub %edx,%ecx
75 add %edx,%edi
76 jmp 1b
lib/libc/wasi/libc-top-half/musl/src/string/x86_64/memcpy.s deleted-25
......@@ -1,25 +0,0 @@
1.global memcpy
2.global __memcpy_fwd
3.hidden __memcpy_fwd
4.type memcpy,@function
5memcpy:
6__memcpy_fwd:
7 mov %rdi,%rax
8 cmp $8,%rdx
9 jc 1f
10 test $7,%edi
11 jz 1f
122: movsb
13 dec %rdx
14 test $7,%edi
15 jnz 2b
161: mov %rdx,%rcx
17 shr $3,%rcx
18 rep
19 movsq
20 and $7,%edx
21 jz 1f
222: movsb
23 dec %edx
24 jnz 2b
251: ret
lib/libc/wasi/libc-top-half/musl/src/string/x86_64/memmove.s deleted-16
......@@ -1,16 +0,0 @@
1.global memmove
2.type memmove,@function
3memmove:
4 mov %rdi,%rax
5 sub %rsi,%rax
6 cmp %rdx,%rax
7.hidden __memcpy_fwd
8 jae __memcpy_fwd
9 mov %rdx,%rcx
10 lea -1(%rdi,%rdx),%rdi
11 lea -1(%rsi,%rdx),%rsi
12 std
13 rep movsb
14 cld
15 lea 1(%rdi),%rax
16 ret
lib/libc/wasi/libc-top-half/musl/src/string/x86_64/memset.s deleted-72
......@@ -1,72 +0,0 @@
1.global memset
2.type memset,@function
3memset:
4 movzbq %sil,%rax
5 mov $0x101010101010101,%r8
6 imul %r8,%rax
7
8 cmp $126,%rdx
9 ja 2f
10
11 test %edx,%edx
12 jz 1f
13
14 mov %sil,(%rdi)
15 mov %sil,-1(%rdi,%rdx)
16 cmp $2,%edx
17 jbe 1f
18
19 mov %ax,1(%rdi)
20 mov %ax,(-1-2)(%rdi,%rdx)
21 cmp $6,%edx
22 jbe 1f
23
24 mov %eax,(1+2)(%rdi)
25 mov %eax,(-1-2-4)(%rdi,%rdx)
26 cmp $14,%edx
27 jbe 1f
28
29 mov %rax,(1+2+4)(%rdi)
30 mov %rax,(-1-2-4-8)(%rdi,%rdx)
31 cmp $30,%edx
32 jbe 1f
33
34 mov %rax,(1+2+4+8)(%rdi)
35 mov %rax,(1+2+4+8+8)(%rdi)
36 mov %rax,(-1-2-4-8-16)(%rdi,%rdx)
37 mov %rax,(-1-2-4-8-8)(%rdi,%rdx)
38 cmp $62,%edx
39 jbe 1f
40
41 mov %rax,(1+2+4+8+16)(%rdi)
42 mov %rax,(1+2+4+8+16+8)(%rdi)
43 mov %rax,(1+2+4+8+16+16)(%rdi)
44 mov %rax,(1+2+4+8+16+24)(%rdi)
45 mov %rax,(-1-2-4-8-16-32)(%rdi,%rdx)
46 mov %rax,(-1-2-4-8-16-24)(%rdi,%rdx)
47 mov %rax,(-1-2-4-8-16-16)(%rdi,%rdx)
48 mov %rax,(-1-2-4-8-16-8)(%rdi,%rdx)
49
501: mov %rdi,%rax
51 ret
52
532: test $15,%edi
54 mov %rdi,%r8
55 mov %rax,-8(%rdi,%rdx)
56 mov %rdx,%rcx
57 jnz 2f
58
591: shr $3,%rcx
60 rep
61 stosq
62 mov %r8,%rax
63 ret
64
652: xor %edx,%edx
66 sub %edi,%edx
67 and $15,%edx
68 mov %rax,(%rdi)
69 mov %rax,8(%rdi)
70 sub %rdx,%rcx
71 add %rdx,%rdi
72 jmp 1b
lib/libc/wasi/libc-top-half/musl/src/temp/__randname.c deleted-18
......@@ -1,18 +0,0 @@
1#include <time.h>
2#include <stdint.h>
3
4/* This assumes that a check for the
5 template size has already been made */
6char *__randname(char *template)
7{
8 int i;
9 struct timespec ts;
10 unsigned long r;
11
12 __clock_gettime(CLOCK_REALTIME, &ts);
13 r = ts.tv_nsec*65537 ^ (uintptr_t)&ts / 16 + (uintptr_t)template;
14 for (i=0; i<6; i++, r>>=5)
15 template[i] = 'A'+(r&15)+(r&16)*2;
16
17 return template;
18}
lib/libc/wasi/libc-top-half/musl/src/temp/mkdtemp.c deleted-23
......@@ -1,23 +0,0 @@
1#include <string.h>
2#include <stdlib.h>
3#include <errno.h>
4#include <sys/stat.h>
5
6char *mkdtemp(char *template)
7{
8 size_t l = strlen(template);
9 int retries = 100;
10
11 if (l<6 || memcmp(template+l-6, "XXXXXX", 6)) {
12 errno = EINVAL;
13 return 0;
14 }
15
16 do {
17 __randname(template+l-6);
18 if (!mkdir(template, 0700)) return template;
19 } while (--retries && errno == EEXIST);
20
21 memcpy(template+l-6, "XXXXXX", 6);
22 return 0;
23}
lib/libc/wasi/libc-top-half/musl/src/temp/mkostemp.c deleted-9
......@@ -1,9 +0,0 @@
1#define _BSD_SOURCE
2#include <stdlib.h>
3
4int mkostemp(char *template, int flags)
5{
6 return __mkostemps(template, 0, flags);
7}
8
9weak_alias(mkostemp, mkostemp64);
lib/libc/wasi/libc-top-half/musl/src/temp/mkostemps.c deleted-29
......@@ -1,29 +0,0 @@
1#define _BSD_SOURCE
2#include <stdlib.h>
3#include <string.h>
4#include <fcntl.h>
5#include <unistd.h>
6#include <errno.h>
7
8int __mkostemps(char *template, int len, int flags)
9{
10 size_t l = strlen(template);
11 if (l<6 || len>l-6 || memcmp(template+l-len-6, "XXXXXX", 6)) {
12 errno = EINVAL;
13 return -1;
14 }
15
16 flags -= flags & O_ACCMODE;
17 int fd, retries = 100;
18 do {
19 __randname(template+l-len-6);
20 if ((fd = open(template, flags | O_RDWR | O_CREAT | O_EXCL, 0600))>=0)
21 return fd;
22 } while (--retries && errno == EEXIST);
23
24 memcpy(template+l-len-6, "XXXXXX", 6);
25 return -1;
26}
27
28weak_alias(__mkostemps, mkostemps);
29weak_alias(__mkostemps, mkostemps64);
lib/libc/wasi/libc-top-half/musl/src/temp/mkstemp.c deleted-8
......@@ -1,8 +0,0 @@
1#include <stdlib.h>
2
3int mkstemp(char *template)
4{
5 return __mkostemps(template, 0, 0);
6}
7
8weak_alias(mkstemp, mkstemp64);
lib/libc/wasi/libc-top-half/musl/src/temp/mkstemps.c deleted-9
......@@ -1,9 +0,0 @@
1#define _BSD_SOURCE
2#include <stdlib.h>
3
4int mkstemps(char *template, int len)
5{
6 return __mkostemps(template, len, 0);
7}
8
9weak_alias(mkstemps, mkstemps64);
lib/libc/wasi/libc-top-half/musl/src/temp/mktemp.c deleted-30
......@@ -1,30 +0,0 @@
1#define _GNU_SOURCE
2#include <string.h>
3#include <stdlib.h>
4#include <errno.h>
5#include <sys/stat.h>
6
7char *mktemp(char *template)
8{
9 size_t l = strlen(template);
10 int retries = 100;
11 struct stat st;
12
13 if (l < 6 || memcmp(template+l-6, "XXXXXX", 6)) {
14 errno = EINVAL;
15 *template = 0;
16 return template;
17 }
18
19 do {
20 __randname(template+l-6);
21 if (stat(template, &st)) {
22 if (errno != ENOENT) *template = 0;
23 return template;
24 }
25 } while (--retries);
26
27 *template = 0;
28 errno = EEXIST;
29 return template;
30}
lib/libc/wasi/libc-top-half/musl/src/termios/cfgetospeed.c deleted-13
......@@ -1,13 +0,0 @@
1#define _BSD_SOURCE
2#include <termios.h>
3#include <sys/ioctl.h>
4
5speed_t cfgetospeed(const struct termios *tio)
6{
7 return tio->c_cflag & CBAUD;
8}
9
10speed_t cfgetispeed(const struct termios *tio)
11{
12 return cfgetospeed(tio);
13}
lib/libc/wasi/libc-top-half/musl/src/termios/cfmakeraw.c deleted-13
......@@ -1,13 +0,0 @@
1#define _GNU_SOURCE
2#include <termios.h>
3
4void cfmakeraw(struct termios *t)
5{
6 t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
7 t->c_oflag &= ~OPOST;
8 t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
9 t->c_cflag &= ~(CSIZE|PARENB);
10 t->c_cflag |= CS8;
11 t->c_cc[VMIN] = 1;
12 t->c_cc[VTIME] = 0;
13}
lib/libc/wasi/libc-top-half/musl/src/termios/cfsetospeed.c deleted-22
......@@ -1,22 +0,0 @@
1#define _BSD_SOURCE
2#include <termios.h>
3#include <sys/ioctl.h>
4#include <errno.h>
5
6int cfsetospeed(struct termios *tio, speed_t speed)
7{
8 if (speed & ~CBAUD) {
9 errno = EINVAL;
10 return -1;
11 }
12 tio->c_cflag &= ~CBAUD;
13 tio->c_cflag |= speed;
14 return 0;
15}
16
17int cfsetispeed(struct termios *tio, speed_t speed)
18{
19 return speed ? cfsetospeed(tio, speed) : 0;
20}
21
22weak_alias(cfsetospeed, cfsetspeed);
lib/libc/wasi/libc-top-half/musl/src/termios/tcdrain.c deleted-8
......@@ -1,8 +0,0 @@
1#include <termios.h>
2#include <sys/ioctl.h>
3#include "syscall.h"
4
5int tcdrain(int fd)
6{
7 return syscall_cp(SYS_ioctl, fd, TCSBRK, 1);
8}
lib/libc/wasi/libc-top-half/musl/src/termios/tcflow.c deleted-7
......@@ -1,7 +0,0 @@
1#include <termios.h>
2#include <sys/ioctl.h>
3
4int tcflow(int fd, int action)
5{
6 return ioctl(fd, TCXONC, action);
7}
lib/libc/wasi/libc-top-half/musl/src/termios/tcflush.c deleted-7
......@@ -1,7 +0,0 @@
1#include <termios.h>
2#include <sys/ioctl.h>
3
4int tcflush(int fd, int queue)
5{
6 return ioctl(fd, TCFLSH, queue);
7}
lib/libc/wasi/libc-top-half/musl/src/termios/tcgetattr.c deleted-9
......@@ -1,9 +0,0 @@
1#include <termios.h>
2#include <sys/ioctl.h>
3
4int tcgetattr(int fd, struct termios *tio)
5{
6 if (ioctl(fd, TCGETS, tio))
7 return -1;
8 return 0;
9}
lib/libc/wasi/libc-top-half/musl/src/termios/tcgetsid.c deleted-10
......@@ -1,10 +0,0 @@
1#include <termios.h>
2#include <sys/ioctl.h>
3
4pid_t tcgetsid(int fd)
5{
6 int sid;
7 if (ioctl(fd, TIOCGSID, &sid) < 0)
8 return -1;
9 return sid;
10}
lib/libc/wasi/libc-top-half/musl/src/termios/tcgetwinsize.c deleted-8
......@@ -1,8 +0,0 @@
1#include <termios.h>
2#include <sys/ioctl.h>
3#include "syscall.h"
4
5int tcgetwinsize(int fd, struct winsize *wsz)
6{
7 return syscall(SYS_ioctl, fd, TIOCGWINSZ, wsz);
8}
lib/libc/wasi/libc-top-half/musl/src/termios/tcsendbreak.c deleted-8
......@@ -1,8 +0,0 @@
1#include <termios.h>
2#include <sys/ioctl.h>
3
4int tcsendbreak(int fd, int dur)
5{
6 /* nonzero duration is implementation-defined, so ignore it */
7 return ioctl(fd, TCSBRK, 0);
8}
lib/libc/wasi/libc-top-half/musl/src/termios/tcsetattr.c deleted-12
......@@ -1,12 +0,0 @@
1#include <termios.h>
2#include <sys/ioctl.h>
3#include <errno.h>
4
5int tcsetattr(int fd, int act, const struct termios *tio)
6{
7 if (act < 0 || act > 2) {
8 errno = EINVAL;
9 return -1;
10 }
11 return ioctl(fd, TCSETS+act, tio);
12}
lib/libc/wasi/libc-top-half/musl/src/termios/tcsetwinsize.c deleted-8
......@@ -1,8 +0,0 @@
1#include <termios.h>
2#include <sys/ioctl.h>
3#include "syscall.h"
4
5int tcsetwinsize(int fd, const struct winsize *wsz)
6{
7 return syscall(SYS_ioctl, fd, TIOCSWINSZ, wsz);
8}
lib/libc/wasi/libc-top-half/musl/src/thread/__lock.c deleted-62
......@@ -1,62 +0,0 @@
1#include "pthread_impl.h"
2
3/* This lock primitive combines a flag (in the sign bit) and a
4 * congestion count (= threads inside the critical section, CS) in a
5 * single int that is accessed through atomic operations. The states
6 * of the int for value x are:
7 *
8 * x == 0: unlocked and no thread inside the critical section
9 *
10 * x < 0: locked with a congestion of x-INT_MIN, including the thread
11 * that holds the lock
12 *
13 * x > 0: unlocked with a congestion of x
14 *
15 * or in an equivalent formulation x is the congestion count or'ed
16 * with INT_MIN as a lock flag.
17 */
18
19void __lock(volatile int *l)
20{
21 int need_locks = libc.need_locks;
22 if (!need_locks) return;
23 /* fast path: INT_MIN for the lock, +1 for the congestion */
24 int current = a_cas(l, 0, INT_MIN + 1);
25 if (need_locks < 0) libc.need_locks = 0;
26 if (!current) return;
27 /* A first spin loop, for medium congestion. */
28 for (unsigned i = 0; i < 10; ++i) {
29 if (current < 0) current -= INT_MIN + 1;
30 // assertion: current >= 0
31 int val = a_cas(l, current, INT_MIN + (current + 1));
32 if (val == current) return;
33 current = val;
34 }
35 // Spinning failed, so mark ourselves as being inside the CS.
36 current = a_fetch_add(l, 1) + 1;
37 /* The main lock acquisition loop for heavy congestion. The only
38 * change to the value performed inside that loop is a successful
39 * lock via the CAS that acquires the lock. */
40 for (;;) {
41 /* We can only go into wait, if we know that somebody holds the
42 * lock and will eventually wake us up, again. */
43 if (current < 0) {
44 __futexwait(l, current, 1);
45 current -= INT_MIN + 1;
46 }
47 /* assertion: current > 0, the count includes us already. */
48 int val = a_cas(l, current, INT_MIN + current);
49 if (val == current) return;
50 current = val;
51 }
52}
53
54void __unlock(volatile int *l)
55{
56 /* Check l[0] to see if we are multi-threaded. */
57 if (l[0] < 0) {
58 if (a_fetch_add(l, -(INT_MIN + 1)) != (INT_MIN + 1)) {
59 __wake(l, 1, 1);
60 }
61 }
62}
lib/libc/wasi/libc-top-half/musl/src/thread/__set_thread_area.c deleted-10
......@@ -1,10 +0,0 @@
1#include "pthread_impl.h"
2
3int __set_thread_area(void *p)
4{
5#ifdef SYS_set_thread_area
6 return __syscall(SYS_set_thread_area, p);
7#else
8 return -ENOSYS;
9#endif
10}
lib/libc/wasi/libc-top-half/musl/src/thread/__syscall_cp.c deleted-20
......@@ -1,20 +0,0 @@
1#include "pthread_impl.h"
2#include "syscall.h"
3
4hidden long __syscall_cp_c();
5
6static long sccp(syscall_arg_t nr,
7 syscall_arg_t u, syscall_arg_t v, syscall_arg_t w,
8 syscall_arg_t x, syscall_arg_t y, syscall_arg_t z)
9{
10 return __syscall(nr, u, v, w, x, y, z);
11}
12
13weak_alias(sccp, __syscall_cp_c);
14
15long (__syscall_cp)(syscall_arg_t nr,
16 syscall_arg_t u, syscall_arg_t v, syscall_arg_t w,
17 syscall_arg_t x, syscall_arg_t y, syscall_arg_t z)
18{
19 return __syscall_cp_c(nr, u, v, w, x, y, z);
20}
lib/libc/wasi/libc-top-half/musl/src/thread/__timedwait.c deleted-84
......@@ -1,84 +0,0 @@
1#include <pthread.h>
2#include <time.h>
3#include <errno.h>
4#include "futex.h"
5#include "syscall.h"
6#include "pthread_impl.h"
7
8#ifdef __wasilibc_unmodified_upstream
9#define IS32BIT(x) !((x)+0x80000000ULL>>32)
10#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
11
12static int __futex4_cp(volatile void *addr, int op, int val, const struct timespec *to)
13{
14 int r;
15#ifdef SYS_futex_time64
16 time_t s = to ? to->tv_sec : 0;
17 long ns = to ? to->tv_nsec : 0;
18 r = -ENOSYS;
19 if (SYS_futex == SYS_futex_time64 || !IS32BIT(s))
20 r = __syscall_cp(SYS_futex_time64, addr, op, val,
21 to ? ((long long[]){s, ns}) : 0);
22 if (SYS_futex == SYS_futex_time64 || r!=-ENOSYS) return r;
23 to = to ? (void *)(long[]){CLAMP(s), ns} : 0;
24#endif
25 r = __syscall_cp(SYS_futex, addr, op, val, to);
26 if (r != -ENOSYS) return r;
27 return __syscall_cp(SYS_futex, addr, op & ~FUTEX_PRIVATE, val, to);
28}
29
30static volatile int dummy = 0;
31weak_alias(dummy, __eintr_valid_flag);
32#else
33static int __futex4_cp(volatile void *addr, int op, int val, const struct timespec *to)
34{
35 int64_t max_wait_ns = -1;
36 if (to) {
37 max_wait_ns = (int64_t)(to->tv_sec * 1000000000 + to->tv_nsec);
38 }
39 return __wasilibc_futex_wait(addr, op, val, max_wait_ns);
40}
41#endif
42
43int __timedwait_cp(volatile int *addr, int val,
44 clockid_t clk, const struct timespec *at, int priv)
45{
46 int r;
47 struct timespec to, *top=0;
48
49 if (priv) priv = FUTEX_PRIVATE;
50
51 if (at) {
52 if (at->tv_nsec >= 1000000000UL) return EINVAL;
53 if (__clock_gettime(clk, &to)) return EINVAL;
54 to.tv_sec = at->tv_sec - to.tv_sec;
55 if ((to.tv_nsec = at->tv_nsec - to.tv_nsec) < 0) {
56 to.tv_sec--;
57 to.tv_nsec += 1000000000;
58 }
59 if (to.tv_sec < 0) return ETIMEDOUT;
60 top = &to;
61 }
62
63 r = -__futex4_cp(addr, FUTEX_WAIT|priv, val, top);
64 if (r != EINTR && r != ETIMEDOUT && r != ECANCELED) r = 0;
65#ifdef __wasilibc_unmodified_upstream
66 /* Mitigate bug in old kernels wrongly reporting EINTR for non-
67 * interrupting (SA_RESTART) signal handlers. This is only practical
68 * when NO interrupting signal handlers have been installed, and
69 * works by sigaction tracking whether that's the case. */
70 if (r == EINTR && !__eintr_valid_flag) r = 0;
71#endif
72
73 return r;
74}
75
76int __timedwait(volatile int *addr, int val,
77 clockid_t clk, const struct timespec *at, int priv)
78{
79 int cs, r;
80 __pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
81 r = __timedwait_cp(addr, val, clk, at, priv);
82 __pthread_setcancelstate(cs, 0);
83 return r;
84}
lib/libc/wasi/libc-top-half/musl/src/thread/__tls_get_addr.c deleted-7
......@@ -1,7 +0,0 @@
1#include "pthread_impl.h"
2
3void *__tls_get_addr(tls_mod_off_t *v)
4{
5 pthread_t self = __pthread_self();
6 return (void *)(self->dtv[v[0]] + v[1]);
7}
lib/libc/wasi/libc-top-half/musl/src/thread/__unmapself.c deleted-24
......@@ -1,24 +0,0 @@
1#include "pthread_impl.h"
2#include "atomic.h"
3#include "syscall.h"
4/* cheat and reuse CRTJMP macro from dynlink code */
5#include "dynlink.h"
6
7static void *unmap_base;
8static size_t unmap_size;
9static char shared_stack[256];
10
11static void do_unmap()
12{
13 __syscall(SYS_munmap, unmap_base, unmap_size);
14 __syscall(SYS_exit);
15}
16
17void __unmapself(void *base, size_t size)
18{
19 char *stack = shared_stack + sizeof shared_stack;
20 stack -= (uintptr_t)stack % 16;
21 unmap_base = base;
22 unmap_size = size;
23 CRTJMP(do_unmap, stack);
24}
lib/libc/wasi/libc-top-half/musl/src/thread/__wait.c deleted-55
......@@ -1,55 +0,0 @@
1#include "pthread_impl.h"
2#ifndef __wasilibc_unmodified_upstream
3#include "assert.h"
4#endif
5
6#ifndef __wasilibc_unmodified_upstream
7// Use WebAssembly's `wait` instruction to implement a futex. Note that `op` is
8// unused but retained as a parameter to match the original signature of the
9// syscall and that, for `max_wait_ns`, -1 (or any negative number) means wait
10// indefinitely.
11//
12// Adapted from Emscripten: see
13// https://github.com/emscripten-core/emscripten/blob/058a9fff/system/lib/pthread/emscripten_futex_wait.c#L111-L150.
14int __wasilibc_futex_wait(volatile void *addr, int op, int val, int64_t max_wait_ns)
15{
16 if ((((intptr_t)addr) & 3) != 0) {
17 return -EINVAL;
18 }
19
20 int ret = __builtin_wasm_memory_atomic_wait32((int *)addr, val, max_wait_ns);
21
22 // memory.atomic.wait32 returns:
23 // 0 => "ok", woken by another agent.
24 // 1 => "not-equal", loaded value != expected value
25 // 2 => "timed-out", the timeout expired
26 if (ret == 1) {
27 return -EWOULDBLOCK;
28 }
29 if (ret == 2) {
30 return -ETIMEDOUT;
31 }
32 assert(ret == 0);
33 return 0;
34}
35#endif
36
37void __wait(volatile int *addr, volatile int *waiters, int val, int priv)
38{
39 int spins=100;
40 if (priv) priv = FUTEX_PRIVATE;
41 while (spins-- && (!waiters || !*waiters)) {
42 if (*addr==val) a_spin();
43 else return;
44 }
45 if (waiters) a_inc(waiters);
46 while (*addr==val) {
47#ifdef __wasilibc_unmodified_upstream
48 __syscall(SYS_futex, addr, FUTEX_WAIT|priv, val, 0) != -ENOSYS
49 || __syscall(SYS_futex, addr, FUTEX_WAIT, val, 0);
50#else
51 __wasilibc_futex_wait(addr, FUTEX_WAIT, val, -1);
52#endif
53 }
54 if (waiters) a_dec(waiters);
55}
lib/libc/wasi/libc-top-half/musl/src/thread/aarch64/__set_thread_area.s deleted-7
......@@ -1,7 +0,0 @@
1.global __set_thread_area
2.hidden __set_thread_area
3.type __set_thread_area,@function
4__set_thread_area:
5 msr tpidr_el0,x0
6 mov w0,#0
7 ret
lib/libc/wasi/libc-top-half/musl/src/thread/aarch64/__unmapself.s deleted-7
......@@ -1,7 +0,0 @@
1.global __unmapself
2.type __unmapself,%function
3__unmapself:
4 mov x8,#215 // SYS_munmap
5 svc 0
6 mov x8,#93 // SYS_exit
7 svc 0
lib/libc/wasi/libc-top-half/musl/src/thread/aarch64/clone.s deleted-30
......@@ -1,30 +0,0 @@
1// __clone(func, stack, flags, arg, ptid, tls, ctid)
2// x0, x1, w2, x3, x4, x5, x6
3
4// syscall(SYS_clone, flags, stack, ptid, tls, ctid)
5// x8, x0, x1, x2, x3, x4
6
7.global __clone
8.hidden __clone
9.type __clone,%function
10__clone:
11 // align stack and save func,arg
12 and x1,x1,#-16
13 stp x0,x3,[x1,#-16]!
14
15 // syscall
16 uxtw x0,w2
17 mov x2,x4
18 mov x3,x5
19 mov x4,x6
20 mov x8,#220 // SYS_clone
21 svc #0
22
23 cbz x0,1f
24 // parent
25 ret
26 // child
271: ldp x1,x0,[sp],#16
28 blr x1
29 mov x8,#93 // SYS_exit
30 svc #0
lib/libc/wasi/libc-top-half/musl/src/thread/aarch64/syscall_cp.s deleted-32
......@@ -1,32 +0,0 @@
1// __syscall_cp_asm(&self->cancel, nr, u, v, w, x, y, z)
2// x0 x1 x2 x3 x4 x5 x6 x7
3
4// syscall(nr, u, v, w, x, y, z)
5// x8 x0 x1 x2 x3 x4 x5
6
7.global __cp_begin
8.hidden __cp_begin
9.global __cp_end
10.hidden __cp_end
11.global __cp_cancel
12.hidden __cp_cancel
13.hidden __cancel
14.global __syscall_cp_asm
15.hidden __syscall_cp_asm
16.type __syscall_cp_asm,%function
17__syscall_cp_asm:
18__cp_begin:
19 ldr w0,[x0]
20 cbnz w0,__cp_cancel
21 mov x8,x1
22 mov x0,x2
23 mov x1,x3
24 mov x2,x4
25 mov x3,x5
26 mov x4,x6
27 mov x5,x7
28 svc 0
29__cp_end:
30 ret
31__cp_cancel:
32 b __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/arm/__aeabi_read_tp.s deleted-10
......@@ -1,10 +0,0 @@
1.syntax unified
2.global __aeabi_read_tp
3.type __aeabi_read_tp,%function
4__aeabi_read_tp:
5 ldr r0,1f
6 add r0,r0,pc
7 ldr r0,[r0]
82: bx r0
9 .align 2
101: .word __a_gettp_ptr - 2b
lib/libc/wasi/libc-top-half/musl/src/thread/arm/__set_thread_area.c deleted-52
......@@ -1,52 +0,0 @@
1#include <stdint.h>
2#include <elf.h>
3#include "pthread_impl.h"
4#include "libc.h"
5
6#define HWCAP_TLS (1 << 15)
7
8extern hidden const unsigned char
9 __a_barrier_oldkuser[], __a_barrier_v6[], __a_barrier_v7[],
10 __a_cas_v6[], __a_cas_v7[],
11 __a_gettp_cp15[];
12
13#define __a_barrier_kuser 0xffff0fa0
14#define __a_barrier_oldkuser (uintptr_t)__a_barrier_oldkuser
15#define __a_barrier_v6 (uintptr_t)__a_barrier_v6
16#define __a_barrier_v7 (uintptr_t)__a_barrier_v7
17
18#define __a_cas_kuser 0xffff0fc0
19#define __a_cas_v6 (uintptr_t)__a_cas_v6
20#define __a_cas_v7 (uintptr_t)__a_cas_v7
21
22#define __a_gettp_kuser 0xffff0fe0
23#define __a_gettp_cp15 (uintptr_t)__a_gettp_cp15
24
25extern hidden uintptr_t __a_barrier_ptr, __a_cas_ptr, __a_gettp_ptr;
26
27int __set_thread_area(void *p)
28{
29#if !__ARM_ARCH_7A__ && !__ARM_ARCH_7R__ && __ARM_ARCH < 7
30 if (__hwcap & HWCAP_TLS) {
31 size_t *aux;
32 __a_cas_ptr = __a_cas_v7;
33 __a_barrier_ptr = __a_barrier_v7;
34 for (aux=libc.auxv; *aux; aux+=2) {
35 if (*aux != AT_PLATFORM) continue;
36 const char *s = (void *)aux[1];
37 if (s[0]!='v' || s[1]!='6' || s[2]-'0'<10u) break;
38 __a_cas_ptr = __a_cas_v6;
39 __a_barrier_ptr = __a_barrier_v6;
40 break;
41 }
42 } else {
43 int ver = *(int *)0xffff0ffc;
44 __a_gettp_ptr = __a_gettp_kuser;
45 __a_cas_ptr = __a_cas_kuser;
46 __a_barrier_ptr = __a_barrier_kuser;
47 if (ver < 2) a_crash();
48 if (ver < 3) __a_barrier_ptr = __a_barrier_oldkuser;
49 }
50#endif
51 return __syscall(0xf0005, p);
52}
lib/libc/wasi/libc-top-half/musl/src/thread/arm/__unmapself.s deleted-9
......@@ -1,9 +0,0 @@
1.syntax unified
2.text
3.global __unmapself
4.type __unmapself,%function
5__unmapself:
6 mov r7,#91
7 svc 0
8 mov r7,#1
9 svc 0
lib/libc/wasi/libc-top-half/musl/src/thread/arm/atomics.s deleted-106
......@@ -1,106 +0,0 @@
1.syntax unified
2.text
3
4.global __a_barrier_dummy
5.hidden __a_barrier_dummy
6.type __a_barrier_dummy,%function
7__a_barrier_dummy:
8 bx lr
9
10.global __a_barrier_oldkuser
11.hidden __a_barrier_oldkuser
12.type __a_barrier_oldkuser,%function
13__a_barrier_oldkuser:
14 push {r0,r1,r2,r3,ip,lr}
15 mov r1,r0
16 mov r2,sp
17 ldr ip,=0xffff0fc0
18 bl 1f
19 pop {r0,r1,r2,r3,ip,lr}
20 bx lr
211: bx ip
22
23.global __a_barrier_v6
24.hidden __a_barrier_v6
25.type __a_barrier_v6,%function
26__a_barrier_v6:
27 .arch armv6t2
28 mcr p15,0,r0,c7,c10,5
29 bx lr
30
31.global __a_barrier_v7
32.hidden __a_barrier_v7
33.type __a_barrier_v7,%function
34__a_barrier_v7:
35 .arch armv7-a
36 dmb ish
37 bx lr
38
39.global __a_cas_dummy
40.hidden __a_cas_dummy
41.type __a_cas_dummy,%function
42__a_cas_dummy:
43 mov r3,r0
44 ldr r0,[r2]
45 subs r0,r3,r0
46 streq r1,[r2]
47 bx lr
48
49.global __a_cas_v6
50.hidden __a_cas_v6
51.type __a_cas_v6,%function
52__a_cas_v6:
53 .arch armv6t2
54 mov r3,r0
55 mcr p15,0,r0,c7,c10,5
561: ldrex r0,[r2]
57 subs r0,r3,r0
58 strexeq r0,r1,[r2]
59 teqeq r0,#1
60 beq 1b
61 mcr p15,0,r0,c7,c10,5
62 bx lr
63
64.global __a_cas_v7
65.hidden __a_cas_v7
66.type __a_cas_v7,%function
67__a_cas_v7:
68 .arch armv7-a
69 mov r3,r0
70 dmb ish
711: ldrex r0,[r2]
72 subs r0,r3,r0
73 strexeq r0,r1,[r2]
74 teqeq r0,#1
75 beq 1b
76 dmb ish
77 bx lr
78
79.global __a_gettp_cp15
80.hidden __a_gettp_cp15
81.type __a_gettp_cp15,%function
82__a_gettp_cp15:
83 mrc p15,0,r0,c13,c0,3
84 bx lr
85
86/* Tag this file with minimum ISA level so as not to affect linking. */
87.object_arch armv4t
88.eabi_attribute 6,2
89
90.data
91.align 2
92
93.global __a_barrier_ptr
94.hidden __a_barrier_ptr
95__a_barrier_ptr:
96 .word __a_barrier_dummy
97
98.global __a_cas_ptr
99.hidden __a_cas_ptr
100__a_cas_ptr:
101 .word __a_cas_dummy
102
103.global __a_gettp_ptr
104.hidden __a_gettp_ptr
105__a_gettp_ptr:
106 .word __a_gettp_cp15
lib/libc/wasi/libc-top-half/musl/src/thread/arm/clone.s deleted-28
......@@ -1,28 +0,0 @@
1.syntax unified
2.text
3.global __clone
4.hidden __clone
5.type __clone,%function
6__clone:
7 stmfd sp!,{r4,r5,r6,r7}
8 mov r7,#120
9 mov r6,r3
10 mov r5,r0
11 mov r0,r2
12 and r1,r1,#-16
13 ldr r2,[sp,#16]
14 ldr r3,[sp,#20]
15 ldr r4,[sp,#24]
16 svc 0
17 tst r0,r0
18 beq 1f
19 ldmfd sp!,{r4,r5,r6,r7}
20 bx lr
21
221: mov r0,r6
23 bl 3f
242: mov r7,#1
25 svc 0
26 b 2b
27
283: bx r5
lib/libc/wasi/libc-top-half/musl/src/thread/arm/syscall_cp.s deleted-29
......@@ -1,29 +0,0 @@
1.syntax unified
2.global __cp_begin
3.hidden __cp_begin
4.global __cp_end
5.hidden __cp_end
6.global __cp_cancel
7.hidden __cp_cancel
8.hidden __cancel
9.global __syscall_cp_asm
10.hidden __syscall_cp_asm
11.type __syscall_cp_asm,%function
12__syscall_cp_asm:
13 mov ip,sp
14 stmfd sp!,{r4,r5,r6,r7}
15__cp_begin:
16 ldr r0,[r0]
17 cmp r0,#0
18 bne __cp_cancel
19 mov r7,r1
20 mov r0,r2
21 mov r1,r3
22 ldmfd ip,{r2,r3,r4,r5,r6}
23 svc 0
24__cp_end:
25 ldmfd sp!,{r4,r5,r6,r7}
26 bx lr
27__cp_cancel:
28 ldmfd sp!,{r4,r5,r6,r7}
29 b __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/call_once.c deleted-7
......@@ -1,7 +0,0 @@
1#include <threads.h>
2#include <pthread.h>
3
4void call_once(once_flag *flag, void (*func)(void))
5{
6 __pthread_once(flag, func);
7}
lib/libc/wasi/libc-top-half/musl/src/thread/clone.c deleted-7
......@@ -1,7 +0,0 @@
1#include <errno.h>
2#include "pthread_impl.h"
3
4int __clone(int (*func)(void *), void *stack, int flags, void *arg, ...)
5{
6 return -ENOSYS;
7}
lib/libc/wasi/libc-top-half/musl/src/thread/cnd_broadcast.c deleted-9
......@@ -1,9 +0,0 @@
1#include <threads.h>
2#include <pthread.h>
3
4int cnd_broadcast(cnd_t *c)
5{
6 /* This internal function never fails, and always returns zero,
7 * which matches the value thrd_success is defined with. */
8 return __private_cond_signal((pthread_cond_t *)c, -1);
9}
lib/libc/wasi/libc-top-half/musl/src/thread/cnd_destroy.c deleted-6
......@@ -1,6 +0,0 @@
1#include <threads.h>
2
3void cnd_destroy(cnd_t *c)
4{
5 /* For private cv this is a no-op */
6}
lib/libc/wasi/libc-top-half/musl/src/thread/cnd_init.c deleted-7
......@@ -1,7 +0,0 @@
1#include <threads.h>
2
3int cnd_init(cnd_t *c)
4{
5 *c = (cnd_t){ 0 };
6 return thrd_success;
7}
lib/libc/wasi/libc-top-half/musl/src/thread/cnd_signal.c deleted-9
......@@ -1,9 +0,0 @@
1#include <threads.h>
2#include <pthread.h>
3
4int cnd_signal(cnd_t *c)
5{
6 /* This internal function never fails, and always returns zero,
7 * which matches the value thrd_success is defined with. */
8 return __private_cond_signal((pthread_cond_t *)c, 1);
9}
lib/libc/wasi/libc-top-half/musl/src/thread/cnd_timedwait.c deleted-14
......@@ -1,14 +0,0 @@
1#include <threads.h>
2#include <pthread.h>
3#include <errno.h>
4
5int cnd_timedwait(cnd_t *restrict c, mtx_t *restrict m, const struct timespec *restrict ts)
6{
7 int ret = __pthread_cond_timedwait((pthread_cond_t *)c, (pthread_mutex_t *)m, ts);
8 switch (ret) {
9 /* May also return EINVAL or EPERM. */
10 default: return thrd_error;
11 case 0: return thrd_success;
12 case ETIMEDOUT: return thrd_timedout;
13 }
14}
lib/libc/wasi/libc-top-half/musl/src/thread/cnd_wait.c deleted-9
......@@ -1,9 +0,0 @@
1#include <threads.h>
2
3int cnd_wait(cnd_t *c, mtx_t *m)
4{
5 /* Calling cnd_timedwait with a null pointer is an extension.
6 * It is convenient here to avoid duplication of the logic
7 * for return values. */
8 return cnd_timedwait(c, m, 0);
9}
lib/libc/wasi/libc-top-half/musl/src/thread/default_attr.c deleted-4
......@@ -1,4 +0,0 @@
1#include "pthread_impl.h"
2
3unsigned __default_stacksize = DEFAULT_STACK_SIZE;
4unsigned __default_guardsize = DEFAULT_GUARD_SIZE;
lib/libc/wasi/libc-top-half/musl/src/thread/i386/__set_thread_area.s deleted-47
......@@ -1,47 +0,0 @@
1.text
2.global __set_thread_area
3.hidden __set_thread_area
4.type __set_thread_area,@function
5__set_thread_area:
6 push %ebx
7 push $0x51
8 push $0xfffff
9 push 16(%esp)
10 call 1f
111: addl $4f-1b,(%esp)
12 pop %ecx
13 mov (%ecx),%edx
14 push %edx
15 mov %esp,%ebx
16 xor %eax,%eax
17 mov $243,%al
18 int $128
19 testl %eax,%eax
20 jnz 2f
21 movl (%esp),%edx
22 movl %edx,(%ecx)
23 leal 3(,%edx,8),%edx
243: movw %dx,%gs
251:
26 addl $16,%esp
27 popl %ebx
28 ret
292:
30 mov %ebx,%ecx
31 xor %eax,%eax
32 xor %ebx,%ebx
33 xor %edx,%edx
34 mov %ebx,(%esp)
35 mov $1,%bl
36 mov $16,%dl
37 mov $123,%al
38 int $128
39 testl %eax,%eax
40 jnz 1b
41 mov $7,%dl
42 inc %al
43 jmp 3b
44
45.data
46 .align 4
474: .long -1
lib/libc/wasi/libc-top-half/musl/src/thread/i386/__unmapself.s deleted-11
......@@ -1,11 +0,0 @@
1.text
2.global __unmapself
3.type __unmapself,@function
4__unmapself:
5 movl $91,%eax
6 movl 4(%esp),%ebx
7 movl 8(%esp),%ecx
8 int $128
9 xorl %ebx,%ebx
10 movl $1,%eax
11 int $128
lib/libc/wasi/libc-top-half/musl/src/thread/i386/clone.s deleted-49
......@@ -1,49 +0,0 @@
1.text
2.global __clone
3.hidden __clone
4.type __clone,@function
5__clone:
6 push %ebp
7 mov %esp,%ebp
8 push %ebx
9 push %esi
10 push %edi
11
12 xor %eax,%eax
13 push $0x51
14 mov %gs,%ax
15 push $0xfffff
16 shr $3,%eax
17 push 28(%ebp)
18 push %eax
19 mov $120,%al
20
21 mov 12(%ebp),%ecx
22 mov 16(%ebp),%ebx
23 and $-16,%ecx
24 sub $16,%ecx
25 mov 20(%ebp),%edi
26 mov %edi,(%ecx)
27 mov 24(%ebp),%edx
28 mov %esp,%esi
29 mov 32(%ebp),%edi
30 mov 8(%ebp),%ebp
31 int $128
32 test %eax,%eax
33 jnz 1f
34
35 mov %ebp,%eax
36 xor %ebp,%ebp
37 call *%eax
38 mov %eax,%ebx
39 xor %eax,%eax
40 inc %eax
41 int $128
42 hlt
43
441: add $16,%esp
45 pop %edi
46 pop %esi
47 pop %ebx
48 pop %ebp
49 ret
lib/libc/wasi/libc-top-half/musl/src/thread/i386/syscall_cp.s deleted-41
......@@ -1,41 +0,0 @@
1.text
2.global __cp_begin
3.hidden __cp_begin
4.global __cp_end
5.hidden __cp_end
6.global __cp_cancel
7.hidden __cp_cancel
8.hidden __cancel
9.global __syscall_cp_asm
10.hidden __syscall_cp_asm
11.type __syscall_cp_asm,@function
12__syscall_cp_asm:
13 mov 4(%esp),%ecx
14 pushl %ebx
15 pushl %esi
16 pushl %edi
17 pushl %ebp
18__cp_begin:
19 movl (%ecx),%eax
20 testl %eax,%eax
21 jnz __cp_cancel
22 movl 24(%esp),%eax
23 movl 28(%esp),%ebx
24 movl 32(%esp),%ecx
25 movl 36(%esp),%edx
26 movl 40(%esp),%esi
27 movl 44(%esp),%edi
28 movl 48(%esp),%ebp
29 int $128
30__cp_end:
31 popl %ebp
32 popl %edi
33 popl %esi
34 popl %ebx
35 ret
36__cp_cancel:
37 popl %ebp
38 popl %edi
39 popl %esi
40 popl %ebx
41 jmp __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/i386/tls.s deleted-9
......@@ -1,9 +0,0 @@
1.text
2.global ___tls_get_addr
3.type ___tls_get_addr,@function
4___tls_get_addr:
5 mov %gs:4,%edx
6 mov (%eax),%ecx
7 mov 4(%eax),%eax
8 add (%edx,%ecx,4),%eax
9 ret
lib/libc/wasi/libc-top-half/musl/src/thread/lock_ptc.c deleted-18
......@@ -1,18 +0,0 @@
1#include <pthread.h>
2
3static pthread_rwlock_t lock = PTHREAD_RWLOCK_INITIALIZER;
4
5void __inhibit_ptc()
6{
7 pthread_rwlock_wrlock(&lock);
8}
9
10void __acquire_ptc()
11{
12 pthread_rwlock_rdlock(&lock);
13}
14
15void __release_ptc()
16{
17 pthread_rwlock_unlock(&lock);
18}
lib/libc/wasi/libc-top-half/musl/src/thread/m68k/__m68k_read_tp.s deleted-8
......@@ -1,8 +0,0 @@
1.text
2.global __m68k_read_tp
3.type __m68k_read_tp,@function
4__m68k_read_tp:
5 move.l #333,%d0
6 trap #0
7 move.l %d0,%a0
8 rts
lib/libc/wasi/libc-top-half/musl/src/thread/m68k/clone.s deleted-25
......@@ -1,25 +0,0 @@
1.text
2.global __clone
3.hidden __clone
4.type __clone,@function
5__clone:
6 movem.l %d2-%d5,-(%sp)
7 move.l #120,%d0
8 move.l 28(%sp),%d1
9 move.l 24(%sp),%d2
10 and.l #-16,%d2
11 move.l 36(%sp),%d3
12 move.l 44(%sp),%d4
13 move.l 40(%sp),%d5
14 move.l 20(%sp),%a0
15 move.l 32(%sp),%a1
16 trap #0
17 tst.l %d0
18 beq 1f
19 movem.l (%sp)+,%d2-%d5
20 rts
211: move.l %a1,-(%sp)
22 jsr (%a0)
23 move.l #1,%d0
24 trap #0
25 clr.b 0
lib/libc/wasi/libc-top-half/musl/src/thread/m68k/syscall_cp.s deleted-26
......@@ -1,26 +0,0 @@
1.text
2.global __cp_begin
3.hidden __cp_begin
4.global __cp_end
5.hidden __cp_end
6.global __cp_cancel
7.hidden __cp_cancel
8.hidden __cancel
9.global __syscall_cp_asm
10.hidden __syscall_cp_asm
11.type __syscall_cp_asm,@function
12__syscall_cp_asm:
13 movem.l %d2-%d5,-(%sp)
14 movea.l 20(%sp),%a0
15__cp_begin:
16 move.l (%a0),%d0
17 bne __cp_cancel
18 movem.l 24(%sp),%d0-%d5/%a0
19 trap #0
20__cp_end:
21 movem.l (%sp)+,%d2-%d5
22 rts
23__cp_cancel:
24 movem.l (%sp)+,%d2-%d5
25 move.l __cancel-.-8,%a1
26 jmp (%pc,%a1)
lib/libc/wasi/libc-top-half/musl/src/thread/microblaze/__set_thread_area.s deleted-7
......@@ -1,7 +0,0 @@
1.global __set_thread_area
2.hidden __set_thread_area
3.type __set_thread_area,@function
4__set_thread_area:
5 ori r21, r5, 0
6 rtsd r15, 8
7 ori r3, r0, 0
lib/libc/wasi/libc-top-half/musl/src/thread/microblaze/__unmapself.s deleted-8
......@@ -1,8 +0,0 @@
1.global __unmapself
2.type __unmapself,@function
3__unmapself:
4 ori r12, r0, 91
5 brki r14, 0x8
6 ori r12, r0, 1
7 brki r14, 0x8
8 nop
lib/libc/wasi/libc-top-half/musl/src/thread/microblaze/clone.s deleted-30
......@@ -1,30 +0,0 @@
1.global __clone
2.hidden __clone
3.type __clone,@function
4
5# r5, r6, r7, r8, r9, r10, stack
6# fn, st, fl, ar, pt, tl, ct
7# fl, st, __, pt, ct, tl
8
9__clone:
10 andi r6, r6, -16
11 addi r6, r6, -16
12 swi r5, r6, 0
13 swi r8, r6, 4
14
15 ori r5, r7, 0
16 ori r8, r9, 0
17 lwi r9, r1, 28
18 ori r12, r0, 120
19
20 brki r14, 8
21 beqi r3, 1f
22 rtsd r15, 8
23 nop
24
251: lwi r3, r1, 0
26 lwi r5, r1, 4
27 brald r15, r3
28 nop
29 ori r12, r0, 1
30 brki r14, 8
lib/libc/wasi/libc-top-half/musl/src/thread/microblaze/syscall_cp.s deleted-27
......@@ -1,27 +0,0 @@
1.global __cp_begin
2.hidden __cp_begin
3.global __cp_end
4.hidden __cp_end
5.global __cp_cancel
6.hidden __cp_cancel
7.hidden __cancel
8.global __syscall_cp_asm
9.hidden __syscall_cp_asm
10.type __syscall_cp_asm,@function
11__syscall_cp_asm:
12__cp_begin:
13 lwi r5, r5, 0
14 bnei r5, __cp_cancel
15 addi r12, r6, 0
16 add r5, r7, r0
17 add r6, r8, r0
18 add r7, r9, r0
19 add r8, r10, r0
20 lwi r9, r1, 28
21 lwi r10, r1, 32
22 brki r14, 0x8
23__cp_end:
24 rtsd r15, 8
25 nop
26__cp_cancel:
27 bri __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/mips/__unmapself.s deleted-10
......@@ -1,10 +0,0 @@
1.set noreorder
2.global __unmapself
3.type __unmapself,@function
4__unmapself:
5 move $sp, $25
6 li $2, 4091
7 syscall
8 li $4, 0
9 li $2, 4001
10 syscall
lib/libc/wasi/libc-top-half/musl/src/thread/mips/clone.s deleted-36
......@@ -1,36 +0,0 @@
1.set noreorder
2.global __clone
3.hidden __clone
4.type __clone,@function
5__clone:
6 # Save function pointer and argument pointer on new thread stack
7 and $5, $5, -8
8 subu $5, $5, 16
9 sw $4, 0($5)
10 sw $7, 4($5)
11 # Shuffle (fn,sp,fl,arg,ptid,tls,ctid) to (fl,sp,ptid,tls,ctid)
12 move $4, $6
13 lw $6, 16($sp)
14 lw $7, 20($sp)
15 lw $9, 24($sp)
16 subu $sp, $sp, 16
17 sw $9, 16($sp)
18 li $2, 4120
19 syscall
20 beq $7, $0, 1f
21 nop
22 addu $sp, $sp, 16
23 jr $ra
24 subu $2, $0, $2
251: beq $2, $0, 1f
26 nop
27 addu $sp, $sp, 16
28 jr $ra
29 nop
301: lw $25, 0($sp)
31 lw $4, 4($sp)
32 jalr $25
33 nop
34 move $4, $2
35 li $2, 4001
36 syscall
lib/libc/wasi/libc-top-half/musl/src/thread/mips/syscall_cp.s deleted-53
......@@ -1,53 +0,0 @@
1.set noreorder
2
3.global __cp_begin
4.hidden __cp_begin
5.type __cp_begin,@function
6.global __cp_end
7.hidden __cp_end
8.type __cp_end,@function
9.global __cp_cancel
10.hidden __cp_cancel
11.type __cp_cancel,@function
12.hidden __cancel
13.global __syscall_cp_asm
14.hidden __syscall_cp_asm
15.type __syscall_cp_asm,@function
16__syscall_cp_asm:
17 subu $sp, $sp, 32
18__cp_begin:
19 lw $4, 0($4)
20 bne $4, $0, __cp_cancel
21 move $2, $5
22 move $4, $6
23 move $5, $7
24 lw $6, 48($sp)
25 lw $7, 52($sp)
26 lw $8, 56($sp)
27 lw $9, 60($sp)
28 lw $10,64($sp)
29 sw $8, 16($sp)
30 sw $9, 20($sp)
31 sw $10,24($sp)
32 sw $2, 28($sp)
33 lw $2, 28($sp)
34 syscall
35__cp_end:
36 beq $7, $0, 1f
37 addu $sp, $sp, 32
38 subu $2, $0, $2
391: jr $ra
40 nop
41
42__cp_cancel:
43 move $2, $ra
44 bal 1f
45 addu $sp, $sp, 32
46 .gpword .
47 .gpword __cancel
481: lw $3, ($ra)
49 subu $3, $ra, $3
50 lw $25, 4($ra)
51 addu $25, $25, $3
52 jr $25
53 move $ra, $2
lib/libc/wasi/libc-top-half/musl/src/thread/mips64/__unmapself.s deleted-9
......@@ -1,9 +0,0 @@
1.set noreorder
2.global __unmapself
3.type __unmapself, @function
4__unmapself:
5 li $2, 5011
6 syscall
7 li $4, 0
8 li $2, 5058
9 syscall
lib/libc/wasi/libc-top-half/musl/src/thread/mips64/clone.s deleted-34
......@@ -1,34 +0,0 @@
1.set noreorder
2.global __clone
3.hidden __clone
4.type __clone,@function
5__clone:
6 # Save function pointer and argument pointer on new thread stack
7 and $5, $5, -16 # aligning stack to double word
8 dsubu $5, $5, 16
9 sd $4, 0($5) # save function pointer
10 sd $7, 8($5) # save argument pointer
11
12 # Shuffle (fn,sp,fl,arg,ptid,tls,ctid) to (fl,sp,ptid,tls,ctid)
13 # sys_clone(u64 flags, u64 ustack_base, u64 parent_tidptr, u64 child_tidptr, u64 tls)
14 move $4, $6
15 move $6, $8
16 move $7, $9
17 move $8, $10
18 li $2, 5055
19 syscall
20 beq $7, $0, 1f
21 nop
22 jr $ra
23 dsubu $2, $0, $2
241: beq $2, $0, 1f
25 nop
26 jr $ra
27 nop
281: ld $25, 0($sp) # function pointer
29 ld $4, 8($sp) # argument pointer
30 jalr $25 # call the user's function
31 nop
32 move $4, $2
33 li $2, 5058
34 syscall
lib/libc/wasi/libc-top-half/musl/src/thread/mips64/syscall_cp.s deleted-52
......@@ -1,52 +0,0 @@
1.set noreorder
2.global __cp_begin
3.hidden __cp_begin
4.type __cp_begin,@function
5.global __cp_end
6.hidden __cp_end
7.type __cp_end,@function
8.global __cp_cancel
9.hidden __cp_cancel
10.type __cp_cancel,@function
11.global __cp_cancel_data
12.hidden __cp_cancel_data
13.type __cp_cancel_data,@function
14.hidden __cancel
15.global __syscall_cp_asm
16.hidden __syscall_cp_asm
17.type __syscall_cp_asm,@function
18__syscall_cp_asm:
19__cp_begin:
20 lw $4, 0($4)
21 bne $4, $0, __cp_cancel
22 move $2, $5
23 move $4, $6
24 move $5, $7
25 move $6, $8
26 move $7, $9
27 move $8, $10
28 move $9, $11
29 ld $10, 0($sp)
30 syscall
31__cp_end:
32 beq $7, $0, 1f
33 nop
34 dsubu $2, $0, $2
351: jr $ra
36 nop
37
38 # if cancellation flag is 1 then call __cancel
39__cp_cancel:
40 move $2, $ra
41.align 8
42 bal 1f
43 nop
44__cp_cancel_data:
45 .gpdword __cp_cancel_data
46 .gpdword __cancel
471: ld $3, ($ra)
48 dsubu $3, $ra, $3
49 ld $25, 8($ra)
50 daddu $25, $25, $3
51 jr $25
52 move $ra, $2
lib/libc/wasi/libc-top-half/musl/src/thread/mipsn32/__unmapself.s deleted-9
......@@ -1,9 +0,0 @@
1.set noreorder
2.global __unmapself
3.type __unmapself,@function
4__unmapself:
5 li $2, 6011
6 syscall
7 li $4, 0
8 li $2, 6058
9 syscall
lib/libc/wasi/libc-top-half/musl/src/thread/mipsn32/clone.s deleted-34
......@@ -1,34 +0,0 @@
1.set noreorder
2.global __clone
3.hidden __clone
4.type __clone,@function
5__clone:
6 # Save function pointer and argument pointer on new thread stack
7 and $5, $5, -16 # aligning stack to double word
8 subu $5, $5, 16
9 sw $4, 0($5) # save function pointer
10 sw $7, 4($5) # save argument pointer
11
12 # Shuffle (fn,sp,fl,arg,ptid,tls,ctid) to (fl,sp,ptid,tls,ctid)
13 # sys_clone(u64 flags, u64 ustack_base, u64 parent_tidptr, u64 child_tidptr, u64 tls)
14 move $4, $6
15 move $6, $8
16 move $7, $9
17 move $8, $10
18 li $2, 6055
19 syscall
20 beq $7, $0, 1f
21 nop
22 jr $ra
23 subu $2, $0, $2
241: beq $2, $0, 1f
25 nop
26 jr $ra
27 nop
281: lw $25, 0($sp) # function pointer
29 lw $4, 4($sp) # argument pointer
30 jalr $25 # call the user's function
31 nop
32 move $4, $2
33 li $2, 6058
34 syscall
lib/libc/wasi/libc-top-half/musl/src/thread/mipsn32/syscall_cp.s deleted-51
......@@ -1,51 +0,0 @@
1.set noreorder
2.global __cp_begin
3.hidden __cp_begin
4.type __cp_begin,@function
5.global __cp_end
6.hidden __cp_end
7.type __cp_end,@function
8.global __cp_cancel
9.hidden __cp_cancel
10.type __cp_cancel,@function
11.global __cp_cancel_data
12.hidden __cp_cancel_data
13.type __cp_cancel_data,@function
14.hidden __cancel
15.global __syscall_cp_asm
16.hidden __syscall_cp_asm
17.type __syscall_cp_asm,@function
18__syscall_cp_asm:
19__cp_begin:
20 lw $4, 0($4)
21 bne $4, $0, __cp_cancel
22 move $2, $5
23 move $4, $6
24 move $5, $7
25 move $6, $8
26 move $7, $9
27 move $8, $10
28 move $9, $11
29 lw $10, 0($sp)
30 syscall
31__cp_end:
32 beq $7, $0, 1f
33 nop
34 subu $2, $0, $2
351: jr $ra
36 nop
37
38 # if cancellation flag is 1 then call __cancel
39__cp_cancel:
40 move $2, $ra
41 bal 1f
42 nop
43__cp_cancel_data:
44 .gpword __cp_cancel_data
45 .gpword __cancel
461: lw $3, 0($ra)
47 subu $3, $ra, $3
48 lw $25, 4($ra)
49 addu $25, $25, $3
50 jr $25
51 move $ra, $2
lib/libc/wasi/libc-top-half/musl/src/thread/mtx_destroy.c deleted-5
......@@ -1,5 +0,0 @@
1#include <threads.h>
2
3void mtx_destroy(mtx_t *mtx)
4{
5}
lib/libc/wasi/libc-top-half/musl/src/thread/mtx_init.c deleted-10
......@@ -1,10 +0,0 @@
1#include "pthread_impl.h"
2#include <threads.h>
3
4int mtx_init(mtx_t *m, int type)
5{
6 *m = (mtx_t){
7 ._m_type = ((type&mtx_recursive) ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL),
8 };
9 return thrd_success;
10}
lib/libc/wasi/libc-top-half/musl/src/thread/mtx_lock.c deleted-12
......@@ -1,12 +0,0 @@
1#include "pthread_impl.h"
2#include <threads.h>
3
4int mtx_lock(mtx_t *m)
5{
6 if (m->_m_type == PTHREAD_MUTEX_NORMAL && !a_cas(&m->_m_lock, 0, EBUSY))
7 return thrd_success;
8 /* Calling mtx_timedlock with a null pointer is an extension.
9 * It is convenient, here to avoid duplication of the logic
10 * for return values. */
11 return mtx_timedlock(m, 0);
12}
lib/libc/wasi/libc-top-half/musl/src/thread/mtx_timedlock.c deleted-13
......@@ -1,13 +0,0 @@
1#include <threads.h>
2#include <pthread.h>
3#include <errno.h>
4
5int mtx_timedlock(mtx_t *restrict m, const struct timespec *restrict ts)
6{
7 int ret = __pthread_mutex_timedlock((pthread_mutex_t *)m, ts);
8 switch (ret) {
9 default: return thrd_error;
10 case 0: return thrd_success;
11 case ETIMEDOUT: return thrd_timedout;
12 }
13}
lib/libc/wasi/libc-top-half/musl/src/thread/mtx_trylock.c deleted-15
......@@ -1,15 +0,0 @@
1#include "pthread_impl.h"
2#include <threads.h>
3
4int mtx_trylock(mtx_t *m)
5{
6 if (m->_m_type == PTHREAD_MUTEX_NORMAL)
7 return (a_cas(&m->_m_lock, 0, EBUSY) & EBUSY) ? thrd_busy : thrd_success;
8
9 int ret = __pthread_mutex_trylock((pthread_mutex_t *)m);
10 switch (ret) {
11 default: return thrd_error;
12 case 0: return thrd_success;
13 case EBUSY: return thrd_busy;
14 }
15}
lib/libc/wasi/libc-top-half/musl/src/thread/mtx_unlock.c deleted-10
......@@ -1,10 +0,0 @@
1#include <threads.h>
2#include <pthread.h>
3
4int mtx_unlock(mtx_t *mtx)
5{
6 /* The only cases where pthread_mutex_unlock can return an
7 * error are undefined behavior for C11 mtx_unlock, so we can
8 * assume it does not return an error and simply tail call. */
9 return __pthread_mutex_unlock((pthread_mutex_t *)mtx);
10}
lib/libc/wasi/libc-top-half/musl/src/thread/or1k/__set_thread_area.s deleted-7
......@@ -1,7 +0,0 @@
1.global __set_thread_area
2.hidden __set_thread_area
3.type __set_thread_area,@function
4__set_thread_area:
5 l.ori r10, r3, 0
6 l.jr r9
7 l.ori r11, r0, 0
lib/libc/wasi/libc-top-half/musl/src/thread/or1k/__unmapself.s deleted-8
......@@ -1,8 +0,0 @@
1.global __unmapself
2.type __unmapself,@function
3__unmapself:
4 l.ori r11, r0, 215 /* __NR_munmap */
5 l.sys 1
6 l.ori r3, r0, 0
7 l.ori r11, r0, 93 /* __NR_exit */
8 l.sys 1
lib/libc/wasi/libc-top-half/musl/src/thread/or1k/clone.s deleted-31
......@@ -1,31 +0,0 @@
1/* int clone(fn, stack, flags, arg, ptid, tls, ctid)
2 * r3 r4 r5 r6 sp+0 sp+4 sp+8
3 * sys_clone(flags, stack, ptid, ctid, tls)
4 */
5.global __clone
6.hidden __clone
7.type __clone,@function
8__clone:
9 l.addi r4, r4, -8
10 l.sw 0(r4), r3
11 l.sw 4(r4), r6
12 /* (fn, st, fl, ar, pt, tl, ct) => (fl, st, pt, ct, tl) */
13 l.ori r3, r5, 0
14 l.lwz r5, 0(r1)
15 l.lwz r6, 8(r1)
16 l.lwz r7, 4(r1)
17 l.ori r11, r0, 220 /* __NR_clone */
18 l.sys 1
19
20 l.sfeqi r11, 0
21 l.bf 1f
22 l.nop
23 l.jr r9
24 l.nop
25
261: l.lwz r11, 0(r1)
27 l.jalr r11
28 l.lwz r3, 4(r1)
29
30 l.ori r11, r0, 93 /* __NR_exit */
31 l.sys 1
lib/libc/wasi/libc-top-half/musl/src/thread/or1k/syscall_cp.s deleted-29
......@@ -1,29 +0,0 @@
1.global __cp_begin
2.hidden __cp_begin
3.global __cp_end
4.hidden __cp_end
5.global __cp_cancel
6.hidden __cp_cancel
7.hidden __cancel
8.global __syscall_cp_asm
9.hidden __syscall_cp_asm
10.type __syscall_cp_asm,@function
11__syscall_cp_asm:
12__cp_begin:
13 l.lwz r3, 0(r3)
14 l.sfeqi r3, 0
15 l.bnf __cp_cancel
16 l.ori r11, r4, 0
17 l.ori r3, r5, 0
18 l.ori r4, r6, 0
19 l.ori r5, r7, 0
20 l.ori r6, r8, 0
21 l.lwz r7, 0(r1)
22 l.lwz r8, 4(r1)
23 l.sys 1
24__cp_end:
25 l.jr r9
26 l.nop
27__cp_cancel:
28 l.j __cancel
29 l.nop
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc/__set_thread_area.s deleted-12
......@@ -1,12 +0,0 @@
1.text
2.global __set_thread_area
3.hidden __set_thread_area
4.type __set_thread_area, %function
5__set_thread_area:
6 # mov pointer in reg3 into r2
7 mr 2, 3
8 # put 0 into return reg
9 li 3, 0
10 # return
11 blr
12
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc/__unmapself.s deleted-9
......@@ -1,9 +0,0 @@
1 .text
2 .global __unmapself
3 .type __unmapself,%function
4__unmapself:
5 li 0, 91 # __NR_munmap
6 sc
7 li 0, 1 #__NR_exit
8 sc
9 blr
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc/clone.s deleted-73
......@@ -1,73 +0,0 @@
1.text
2.global __clone
3.hidden __clone
4.type __clone, %function
5__clone:
6# int clone(fn, stack, flags, arg, ptid, tls, ctid)
7# a b c d e f g
8# 3 4 5 6 7 8 9
9# pseudo C code:
10# tid = syscall(SYS_clone,c,b,e,f,g);
11# if (!tid) syscall(SYS_exit, a(d));
12# return tid;
13
14# SYS_clone = 120
15# SYS_exit = 1
16
17# store non-volatile regs r30, r31 on stack in order to put our
18# start func and its arg there
19stwu 30, -16(1)
20stw 31, 4(1)
21
22# save r3 (func) into r30, and r6(arg) into r31
23mr 30, 3
24mr 31, 6
25
26# create initial stack frame for new thread
27clrrwi 4, 4, 4
28li 0, 0
29stwu 0, -16(4)
30
31#move c into first arg
32mr 3, 5
33#mr 4, 4
34mr 5, 7
35mr 6, 8
36mr 7, 9
37
38# move syscall number into r0
39li 0, 120
40
41sc
42
43# check for syscall error
44bns+ 1f # jump to label 1 if no summary overflow.
45#else
46neg 3, 3 #negate the result (errno)
471:
48# compare sc result with 0
49cmpwi cr7, 3, 0
50
51# if not 0, jump to end
52bne cr7, 2f
53
54#else: we're the child
55#call funcptr: move arg (d) into r3
56mr 3, 31
57#move r30 (funcptr) into CTR reg
58mtctr 30
59# call CTR reg
60bctrl
61# mov SYS_exit into r0 (the exit param is already in r3)
62li 0, 1
63sc
64
652:
66
67# restore stack
68lwz 30, 0(1)
69lwz 31, 4(1)
70addi 1, 1, 16
71
72blr
73
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc/syscall_cp.s deleted-59
......@@ -1,59 +0,0 @@
1.global __cp_begin
2.hidden __cp_begin
3.global __cp_end
4.hidden __cp_end
5.global __cp_cancel
6.hidden __cp_cancel
7.hidden __cancel
8.global __syscall_cp_asm
9.hidden __syscall_cp_asm
10
11#r0: volatile. may be modified during linkage.
12#r1: stack frame: 16 byte alignment.
13#r2: tls/thread pointer on pp32
14#r3,r4: return values, first args
15#r5-r10: args
16#r11-r12: volatile. may be modified during linkage
17#r13: "small data area" pointer
18#r14 - r30: local vars
19#r31: local or environment pointer
20
21#r1, r14-31: belong to the caller, must be saved and restored
22#r0, r3-r12, ctr, xer: volatile, not preserved
23#r0,r11,r12: may be altered by cross-module call,
24#"a func cannot depend on that these regs have the values placed by the caller"
25
26#the fields CR2,CR2,CR4 of the cond reg must be preserved
27#LR (link reg) shall contain the funcs return address
28 .text
29 .type __syscall_cp_asm,%function
30__syscall_cp_asm:
31 # at enter: r3 = pointer to self->cancel, r4: syscall no, r5: first arg, r6: 2nd, r7: 3rd, r8: 4th, r9: 5th, r10: 6th
32__cp_begin:
33 # r3 holds first argument, its a pointer to self->cancel.
34 # we must compare the dereferenced value with 0 and jump to __cancel if its not
35
36 lwz 0, 0(3) #deref pointer into r0
37
38 cmpwi cr7, 0, 0 #compare r0 with 0, store result in cr7.
39 beq+ cr7, 1f #jump to label 1 if r0 was 0
40
41 b __cp_cancel #else call cancel
421:
43 #ok, the cancel flag was not set
44 # syscall: number goes to r0, the rest 3-8
45 mr 0, 4 # put the system call number into r0
46 mr 3, 5 # Shift the arguments: arg1
47 mr 4, 6 # arg2
48 mr 5, 7 # arg3
49 mr 6, 8 # arg4
50 mr 7, 9 # arg5
51 mr 8, 10 # arg6
52 sc
53__cp_end:
54 bnslr+ # return if no summary overflow.
55 #else negate result.
56 neg 3, 3
57 blr
58__cp_cancel:
59 b __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc64/__set_thread_area.s deleted-9
......@@ -1,9 +0,0 @@
1.text
2.global __set_thread_area
3.hidden __set_thread_area
4.type __set_thread_area, %function
5__set_thread_area:
6 mr 13, 3
7 li 3, 0
8 blr
9
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc64/__unmapself.s deleted-9
......@@ -1,9 +0,0 @@
1 .text
2 .global __unmapself
3 .type __unmapself,%function
4__unmapself:
5 li 0, 91 # __NR_munmap
6 sc
7 li 0, 1 #__NR_exit
8 sc
9 blr
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc64/clone.s deleted-48
......@@ -1,48 +0,0 @@
1.text
2.global __clone
3.hidden __clone
4.type __clone, %function
5__clone:
6 # int clone(fn, stack, flags, arg, ptid, tls, ctid)
7 # a b c d e f g
8 # 3 4 5 6 7 8 9
9 # pseudo C code:
10 # tid = syscall(SYS_clone,c,b,e,f,g);
11 # if (!tid) syscall(SYS_exit, a(d));
12 # return tid;
13
14 # create initial stack frame for new thread
15 clrrdi 4, 4, 4
16 li 0, 0
17 stdu 0,-32(4)
18
19 # save fn and arg to child stack
20 std 3, 8(4)
21 std 6, 16(4)
22
23 # shuffle args into correct registers and call SYS_clone
24 mr 3, 5
25 #mr 4, 4
26 mr 5, 7
27 mr 6, 8
28 mr 7, 9
29 li 0, 120 # SYS_clone = 120
30 sc
31
32 # if error, negate return (errno)
33 bns+ 1f
34 neg 3, 3
35
361: # if we're the parent, return
37 cmpwi cr7, 3, 0
38 bnelr cr7
39
40 # we're the child. call fn(arg)
41 ld 3, 16(1)
42 ld 12, 8(1)
43 mtctr 12
44 bctrl
45
46 # call SYS_exit. exit code is already in r3 from fn return value
47 li 0, 1 # SYS_exit = 1
48 sc
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc64/syscall_cp.s deleted-44
......@@ -1,44 +0,0 @@
1 .global __cp_begin
2 .hidden __cp_begin
3 .global __cp_end
4 .hidden __cp_end
5 .global __cp_cancel
6 .hidden __cp_cancel
7 .hidden __cancel
8 .global __syscall_cp_asm
9 .hidden __syscall_cp_asm
10 .text
11 .type __syscall_cp_asm,%function
12__syscall_cp_asm:
13 # at enter: r3 = pointer to self->cancel, r4: syscall no, r5: first arg, r6: 2nd, r7: 3rd, r8: 4th, r9: 5th, r10: 6th
14__cp_begin:
15 # if (self->cancel) goto __cp_cancel
16 lwz 0, 0(3)
17 cmpwi cr7, 0, 0
18 bne- cr7, __cp_cancel
19
20 # make syscall
21 mr 0, 4
22 mr 3, 5
23 mr 4, 6
24 mr 5, 7
25 mr 6, 8
26 mr 7, 9
27 mr 8, 10
28 sc
29
30__cp_end:
31 # return error ? -r3 : r3
32 bnslr+
33 neg 3, 3
34 blr
35
36__cp_cancel:
37 mflr 0
38 bl 1f
39 .long .TOC.-.
401: mflr 3
41 lwa 2, 0(3)
42 add 2, 2, 3
43 mtlr 0
44 b __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_atfork.c deleted-49
......@@ -1,49 +0,0 @@
1#include <pthread.h>
2#include "libc.h"
3#include "lock.h"
4
5static struct atfork_funcs {
6 void (*prepare)(void);
7 void (*parent)(void);
8 void (*child)(void);
9 struct atfork_funcs *prev, *next;
10} *funcs;
11
12static volatile int lock[1];
13
14void __fork_handler(int who)
15{
16 struct atfork_funcs *p;
17 if (!funcs) return;
18 if (who < 0) {
19 LOCK(lock);
20 for (p=funcs; p; p = p->next) {
21 if (p->prepare) p->prepare();
22 funcs = p;
23 }
24 } else {
25 for (p=funcs; p; p = p->prev) {
26 if (!who && p->parent) p->parent();
27 else if (who && p->child) p->child();
28 funcs = p;
29 }
30 UNLOCK(lock);
31 }
32}
33
34int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))
35{
36 struct atfork_funcs *new = malloc(sizeof *new);
37 if (!new) return -1;
38
39 LOCK(lock);
40 new->next = funcs;
41 new->prev = 0;
42 new->prepare = prepare;
43 new->parent = parent;
44 new->child = child;
45 if (funcs) funcs->prev = new;
46 funcs = new;
47 UNLOCK(lock);
48 return 0;
49}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_destroy.c deleted-6
......@@ -1,6 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_attr_destroy(pthread_attr_t *a)
4{
5 return 0;
6}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_get.c deleted-102
......@@ -1,102 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_attr_getdetachstate(const pthread_attr_t *a, int *state)
4{
5 *state = a->_a_detach;
6 return 0;
7}
8int pthread_attr_getguardsize(const pthread_attr_t *restrict a, size_t *restrict size)
9{
10 *size = a->_a_guardsize;
11 return 0;
12}
13
14int pthread_attr_getinheritsched(const pthread_attr_t *restrict a, int *restrict inherit)
15{
16 *inherit = a->_a_sched;
17 return 0;
18}
19
20#ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */
21int pthread_attr_getschedparam(const pthread_attr_t *restrict a, struct sched_param *restrict param)
22{
23 param->sched_priority = a->_a_prio;
24 return 0;
25}
26
27int pthread_attr_getschedpolicy(const pthread_attr_t *restrict a, int *restrict policy)
28{
29 *policy = a->_a_policy;
30 return 0;
31}
32#endif
33
34int pthread_attr_getscope(const pthread_attr_t *restrict a, int *restrict scope)
35{
36 *scope = PTHREAD_SCOPE_SYSTEM;
37 return 0;
38}
39
40int pthread_attr_getstack(const pthread_attr_t *restrict a, void **restrict addr, size_t *restrict size)
41{
42 if (!a->_a_stackaddr)
43 return EINVAL;
44 *size = a->_a_stacksize;
45 *addr = (void *)(a->_a_stackaddr - *size);
46 return 0;
47}
48
49int pthread_attr_getstacksize(const pthread_attr_t *restrict a, size_t *restrict size)
50{
51 *size = a->_a_stacksize;
52 return 0;
53}
54
55int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict a, int *restrict pshared)
56{
57 *pshared = !!a->__attr;
58 return 0;
59}
60
61#ifdef __wasilibc_unmodified_upstream /* Forward declaration of WASI's `__clockid` type. */
62int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk)
63{
64 *clk = a->__attr & 0x7fffffff;
65 return 0;
66}
67#endif
68
69int pthread_condattr_getpshared(const pthread_condattr_t *restrict a, int *restrict pshared)
70{
71 *pshared = a->__attr>>31;
72 return 0;
73}
74
75int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *restrict a, int *restrict protocol)
76{
77 *protocol = a->__attr / 8U % 2;
78 return 0;
79}
80int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict a, int *restrict pshared)
81{
82 *pshared = a->__attr / 128U % 2;
83 return 0;
84}
85
86int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict a, int *restrict robust)
87{
88 *robust = a->__attr / 4U % 2;
89 return 0;
90}
91
92int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict a, int *restrict type)
93{
94 *type = a->__attr & 3;
95 return 0;
96}
97
98int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *restrict a, int *restrict pshared)
99{
100 *pshared = a->__attr[0];
101 return 0;
102}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_init.c deleted-11
......@@ -1,11 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_attr_init(pthread_attr_t *a)
4{
5 *a = (pthread_attr_t){0};
6 __acquire_ptc();
7 a->_a_stacksize = __default_stacksize;
8 a->_a_guardsize = __default_guardsize;
9 __release_ptc();
10 return 0;
11}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setdetachstate.c deleted-8
......@@ -1,8 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_attr_setdetachstate(pthread_attr_t *a, int state)
4{
5 if (state > 1U) return EINVAL;
6 a->_a_detach = state;
7 return 0;
8}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setguardsize.c deleted-8
......@@ -1,8 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_attr_setguardsize(pthread_attr_t *a, size_t size)
4{
5 if (size > SIZE_MAX/8) return EINVAL;
6 a->_a_guardsize = size;
7 return 0;
8}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setinheritsched.c deleted-9
......@@ -1,9 +0,0 @@
1#include "pthread_impl.h"
2#include "syscall.h"
3
4int pthread_attr_setinheritsched(pthread_attr_t *a, int inherit)
5{
6 if (inherit > 1U) return EINVAL;
7 a->_a_sched = inherit;
8 return 0;
9}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setschedparam.c deleted-7
......@@ -1,7 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_attr_setschedparam(pthread_attr_t *restrict a, const struct sched_param *restrict param)
4{
5 a->_a_prio = param->sched_priority;
6 return 0;
7}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setschedpolicy.c deleted-7
......@@ -1,7 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_attr_setschedpolicy(pthread_attr_t *a, int policy)
4{
5 a->_a_policy = policy;
6 return 0;
7}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setscope.c deleted-13
......@@ -1,13 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_attr_setscope(pthread_attr_t *a, int scope)
4{
5 switch (scope) {
6 case PTHREAD_SCOPE_SYSTEM:
7 return 0;
8 case PTHREAD_SCOPE_PROCESS:
9 return ENOTSUP;
10 default:
11 return EINVAL;
12 }
13}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setstack.c deleted-9
......@@ -1,9 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_attr_setstack(pthread_attr_t *a, void *addr, size_t size)
4{
5 if (size-PTHREAD_STACK_MIN > SIZE_MAX/4) return EINVAL;
6 a->_a_stackaddr = (size_t)addr + size;
7 a->_a_stacksize = size;
8 return 0;
9}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setstacksize.c deleted-9
......@@ -1,9 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_attr_setstacksize(pthread_attr_t *a, size_t size)
4{
5 if (size-PTHREAD_STACK_MIN > SIZE_MAX/4) return EINVAL;
6 a->_a_stackaddr = 0;
7 a->_a_stacksize = size;
8 return 0;
9}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_barrier_destroy.c deleted-17
......@@ -1,17 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_barrier_destroy(pthread_barrier_t *b)
4{
5 if (b->_b_limit < 0) {
6 if (b->_b_lock) {
7 int v;
8 a_or(&b->_b_lock, INT_MIN);
9 while ((v = b->_b_lock) & INT_MAX)
10 __wait(&b->_b_lock, 0, v, 0);
11 }
12#ifdef __wasilibc_unmodified_upstream /* WASI does not understand processes or locking between them. */
13 __vm_wait();
14#endif
15 }
16 return 0;
17}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_barrier_init.c deleted-8
......@@ -1,8 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_barrier_init(pthread_barrier_t *restrict b, const pthread_barrierattr_t *restrict a, unsigned count)
4{
5 if (count-1 > INT_MAX-1) return EINVAL;
6 *b = (pthread_barrier_t){ ._b_limit = count-1 | (a?a->__attr:0) };
7 return 0;
8}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_barrier_wait.c deleted-119
......@@ -1,119 +0,0 @@
1#include "pthread_impl.h"
2
3static int pshared_barrier_wait(pthread_barrier_t *b)
4{
5 int limit = (b->_b_limit & INT_MAX) + 1;
6 int ret = 0;
7 int v, w;
8
9 if (limit==1) return PTHREAD_BARRIER_SERIAL_THREAD;
10
11 while ((v=a_cas(&b->_b_lock, 0, limit)))
12 __wait(&b->_b_lock, &b->_b_waiters, v, 0);
13
14 /* Wait for <limit> threads to get to the barrier */
15 if (++b->_b_count == limit) {
16 a_store(&b->_b_count, 0);
17 ret = PTHREAD_BARRIER_SERIAL_THREAD;
18 if (b->_b_waiters2) __wake(&b->_b_count, -1, 0);
19 } else {
20 a_store(&b->_b_lock, 0);
21 if (b->_b_waiters) __wake(&b->_b_lock, 1, 0);
22 while ((v=b->_b_count)>0)
23 __wait(&b->_b_count, &b->_b_waiters2, v, 0);
24 }
25
26#ifdef __wasilibc_unmodified_upstream /* WASI does not understand processes or locking between them. */
27 __vm_lock();
28#endif
29
30 /* Ensure all threads have a vm lock before proceeding */
31 if (a_fetch_add(&b->_b_count, -1)==1-limit) {
32 a_store(&b->_b_count, 0);
33 if (b->_b_waiters2) __wake(&b->_b_count, -1, 0);
34 } else {
35 while ((v=b->_b_count))
36 __wait(&b->_b_count, &b->_b_waiters2, v, 0);
37 }
38
39 /* Perform a recursive unlock suitable for self-sync'd destruction */
40 do {
41 v = b->_b_lock;
42 w = b->_b_waiters;
43 } while (a_cas(&b->_b_lock, v, v==INT_MIN+1 ? 0 : v-1) != v);
44
45 /* Wake a thread waiting to reuse or destroy the barrier */
46 if (v==INT_MIN+1 || (v==1 && w))
47 __wake(&b->_b_lock, 1, 0);
48
49#ifdef __wasilibc_unmodified_upstream /* WASI does not understand processes or locking between them. */
50 __vm_unlock();
51#endif
52
53 return ret;
54}
55
56struct instance
57{
58 volatile int count;
59 volatile int last;
60 volatile int waiters;
61 volatile int finished;
62};
63
64int pthread_barrier_wait(pthread_barrier_t *b)
65{
66 int limit = b->_b_limit;
67 struct instance *inst;
68
69 /* Trivial case: count was set at 1 */
70 if (!limit) return PTHREAD_BARRIER_SERIAL_THREAD;
71
72 /* Process-shared barriers require a separate, inefficient wait */
73 if (limit < 0) return pshared_barrier_wait(b);
74
75 /* Otherwise we need a lock on the barrier object */
76 while (a_swap(&b->_b_lock, 1))
77 __wait(&b->_b_lock, &b->_b_waiters, 1, 1);
78 inst = b->_b_inst;
79
80 /* First thread to enter the barrier becomes the "instance owner" */
81 if (!inst) {
82 struct instance new_inst = { 0 };
83 int spins = 200;
84 b->_b_inst = inst = &new_inst;
85 a_store(&b->_b_lock, 0);
86 if (b->_b_waiters) __wake(&b->_b_lock, 1, 1);
87 while (spins-- && !inst->finished)
88 a_spin();
89 a_inc(&inst->finished);
90 while (inst->finished == 1)
91#ifdef __wasilibc_unmodified_upstream
92 __syscall(SYS_futex,&inst->finished,FUTEX_WAIT|FUTEX_PRIVATE,1,0) != -ENOSYS
93 || __syscall(SYS_futex,&inst->finished,FUTEX_WAIT,1,0);
94#else
95 __futexwait(&inst->finished, 1, 0);
96#endif
97 return PTHREAD_BARRIER_SERIAL_THREAD;
98 }
99
100 /* Last thread to enter the barrier wakes all non-instance-owners */
101 if (++inst->count == limit) {
102 b->_b_inst = 0;
103 a_store(&b->_b_lock, 0);
104 if (b->_b_waiters) __wake(&b->_b_lock, 1, 1);
105 a_store(&inst->last, 1);
106 if (inst->waiters)
107 __wake(&inst->last, -1, 1);
108 } else {
109 a_store(&b->_b_lock, 0);
110 if (b->_b_waiters) __wake(&b->_b_lock, 1, 1);
111 __wait(&inst->last, &inst->waiters, 0, 1);
112 }
113
114 /* Last thread to exit the barrier wakes the instance owner */
115 if (a_fetch_add(&inst->count,-1)==1 && a_fetch_add(&inst->finished,1))
116 __wake(&inst->finished, 1, 1);
117
118 return 0;
119}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_barrierattr_destroy.c deleted-6
......@@ -1,6 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_barrierattr_destroy(pthread_barrierattr_t *a)
4{
5 return 0;
6}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_barrierattr_init.c deleted-7
......@@ -1,7 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_barrierattr_init(pthread_barrierattr_t *a)
4{
5 *a = (pthread_barrierattr_t){0};
6 return 0;
7}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_barrierattr_setpshared.c deleted-8
......@@ -1,8 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_barrierattr_setpshared(pthread_barrierattr_t *a, int pshared)
4{
5 if (pshared > 1U) return EINVAL;
6 a->__attr = pshared ? INT_MIN : 0;
7 return 0;
8}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cancel.c deleted-101
......@@ -1,101 +0,0 @@
1#define _GNU_SOURCE
2#include <string.h>
3#include "pthread_impl.h"
4#include "syscall.h"
5
6hidden long __cancel(), __syscall_cp_asm(), __syscall_cp_c();
7
8long __cancel()
9{
10 pthread_t self = __pthread_self();
11 if (self->canceldisable == PTHREAD_CANCEL_ENABLE || self->cancelasync)
12 pthread_exit(PTHREAD_CANCELED);
13 self->canceldisable = PTHREAD_CANCEL_DISABLE;
14 return -ECANCELED;
15}
16
17long __syscall_cp_asm(volatile void *, syscall_arg_t,
18 syscall_arg_t, syscall_arg_t, syscall_arg_t,
19 syscall_arg_t, syscall_arg_t, syscall_arg_t);
20
21long __syscall_cp_c(syscall_arg_t nr,
22 syscall_arg_t u, syscall_arg_t v, syscall_arg_t w,
23 syscall_arg_t x, syscall_arg_t y, syscall_arg_t z)
24{
25 pthread_t self;
26 long r;
27 int st;
28
29 if ((st=(self=__pthread_self())->canceldisable)
30 && (st==PTHREAD_CANCEL_DISABLE || nr==SYS_close))
31 return __syscall(nr, u, v, w, x, y, z);
32
33 r = __syscall_cp_asm(&self->cancel, nr, u, v, w, x, y, z);
34 if (r==-EINTR && nr!=SYS_close && self->cancel &&
35 self->canceldisable != PTHREAD_CANCEL_DISABLE)
36 r = __cancel();
37 return r;
38}
39
40static void _sigaddset(sigset_t *set, int sig)
41{
42 unsigned s = sig-1;
43 set->__bits[s/8/sizeof *set->__bits] |= 1UL<<(s&8*sizeof *set->__bits-1);
44}
45
46extern hidden const char __cp_begin[1], __cp_end[1], __cp_cancel[1];
47
48static void cancel_handler(int sig, siginfo_t *si, void *ctx)
49{
50 pthread_t self = __pthread_self();
51 ucontext_t *uc = ctx;
52 uintptr_t pc = uc->uc_mcontext.MC_PC;
53
54 a_barrier();
55 if (!self->cancel || self->canceldisable == PTHREAD_CANCEL_DISABLE) return;
56
57 _sigaddset(&uc->uc_sigmask, SIGCANCEL);
58
59 if (self->cancelasync || pc >= (uintptr_t)__cp_begin && pc < (uintptr_t)__cp_end) {
60 uc->uc_mcontext.MC_PC = (uintptr_t)__cp_cancel;
61#ifdef CANCEL_GOT
62 uc->uc_mcontext.MC_GOT = CANCEL_GOT;
63#endif
64 return;
65 }
66
67 __syscall(SYS_tkill, self->tid, SIGCANCEL);
68}
69
70void __testcancel()
71{
72 pthread_t self = __pthread_self();
73 if (self->cancel && !self->canceldisable)
74 __cancel();
75}
76
77static void init_cancellation()
78{
79 struct sigaction sa = {
80 .sa_flags = SA_SIGINFO | SA_RESTART,
81 .sa_sigaction = cancel_handler
82 };
83 memset(&sa.sa_mask, -1, _NSIG/8);
84 __libc_sigaction(SIGCANCEL, &sa, 0);
85}
86
87int pthread_cancel(pthread_t t)
88{
89 static int init;
90 if (!init) {
91 init_cancellation();
92 init = 1;
93 }
94 a_store(&t->cancel, 1);
95 if (t == pthread_self()) {
96 if (t->canceldisable == PTHREAD_CANCEL_ENABLE && t->cancelasync)
97 pthread_exit(PTHREAD_CANCELED);
98 return 0;
99 }
100 return pthread_kill(t, SIGCANCEL);
101}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cleanup_push.c deleted-20
......@@ -1,20 +0,0 @@
1#include "pthread_impl.h"
2
3static void dummy(struct __ptcb *cb)
4{
5}
6weak_alias(dummy, __do_cleanup_push);
7weak_alias(dummy, __do_cleanup_pop);
8
9void _pthread_cleanup_push(struct __ptcb *cb, void (*f)(void *), void *x)
10{
11 cb->__f = f;
12 cb->__x = x;
13 __do_cleanup_push(cb);
14}
15
16void _pthread_cleanup_pop(struct __ptcb *cb, int run)
17{
18 __do_cleanup_pop(cb);
19 if (run) cb->__f(cb->__x);
20}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cond_broadcast.c deleted-10
......@@ -1,10 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_cond_broadcast(pthread_cond_t *c)
4{
5 if (!c->_c_shared) return __private_cond_signal(c, -1);
6 if (!c->_c_waiters) return 0;
7 a_inc(&c->_c_seq);
8 __wake(&c->_c_seq, -1, 0);
9 return 0;
10}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cond_destroy.c deleted-14
......@@ -1,14 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_cond_destroy(pthread_cond_t *c)
4{
5 if (c->_c_shared && c->_c_waiters) {
6 int cnt;
7 a_or(&c->_c_waiters, 0x80000000);
8 a_inc(&c->_c_seq);
9 __wake(&c->_c_seq, -1, 0);
10 while ((cnt = c->_c_waiters) & 0x7fffffff)
11 __wait(&c->_c_waiters, 0, cnt, 0);
12 }
13 return 0;
14}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cond_init.c deleted-11
......@@ -1,11 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_cond_init(pthread_cond_t *restrict c, const pthread_condattr_t *restrict a)
4{
5 *c = (pthread_cond_t){0};
6 if (a) {
7 c->_c_clock = a->__attr & 0x7fffffff;
8 if (a->__attr>>31) c->_c_shared = (void *)-1;
9 }
10 return 0;
11}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cond_signal.c deleted-10
......@@ -1,10 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_cond_signal(pthread_cond_t *c)
4{
5 if (!c->_c_shared) return __private_cond_signal(c, 1);
6 if (!c->_c_waiters) return 0;
7 a_inc(&c->_c_seq);
8 __wake(&c->_c_seq, 1, 0);
9 return 0;
10}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cond_timedwait.c deleted-230
......@@ -1,230 +0,0 @@
1#include "pthread_impl.h"
2
3#ifndef __wasilibc_unmodified_upstream
4#include <common/clock.h>
5#endif
6
7/*
8 * struct waiter
9 *
10 * Waiter objects have automatic storage on the waiting thread, and
11 * are used in building a linked list representing waiters currently
12 * waiting on the condition variable or a group of waiters woken
13 * together by a broadcast or signal; in the case of signal, this is a
14 * degenerate list of one member.
15 *
16 * Waiter lists attached to the condition variable itself are
17 * protected by the lock on the cv. Detached waiter lists are never
18 * modified again, but can only be traversed in reverse order, and are
19 * protected by the "barrier" locks in each node, which are unlocked
20 * in turn to control wake order.
21 *
22 * Since process-shared cond var semantics do not necessarily allow
23 * one thread to see another's automatic storage (they may be in
24 * different processes), the waiter list is not used for the
25 * process-shared case, but the structure is still used to store data
26 * needed by the cancellation cleanup handler.
27 */
28
29struct waiter {
30 struct waiter *prev, *next;
31 volatile int state, barrier;
32 volatile int *notify;
33};
34
35/* Self-synchronized-destruction-safe lock functions */
36
37static inline void lock(volatile int *l)
38{
39 if (a_cas(l, 0, 1)) {
40 a_cas(l, 1, 2);
41 do __wait(l, 0, 2, 1);
42 while (a_cas(l, 0, 2));
43 }
44}
45
46static inline void unlock(volatile int *l)
47{
48 if (a_swap(l, 0)==2)
49 __wake(l, 1, 1);
50}
51
52static inline void unlock_requeue(volatile int *l, volatile int *r, int w)
53{
54 a_store(l, 0);
55#ifdef __wasilibc_unmodified_upstream
56 if (w) __wake(l, 1, 1);
57 else __syscall(SYS_futex, l, FUTEX_REQUEUE|FUTEX_PRIVATE, 0, 1, r) != -ENOSYS
58 || __syscall(SYS_futex, l, FUTEX_REQUEUE, 0, 1, r);
59#else
60 // Always wake due to lack of requeue system call in WASI
61 // This can impact the performance, so we might need to re-visit that decision
62 __wake(l, 1, 1);
63#endif
64}
65
66enum {
67 WAITING,
68 SIGNALED,
69 LEAVING,
70};
71
72int __pthread_cond_timedwait(pthread_cond_t *restrict c, pthread_mutex_t *restrict m, const struct timespec *restrict ts)
73{
74 struct waiter node = { 0 };
75 int e, seq, clock = c->_c_clock, cs, shared=0, oldstate, tmp;
76#ifndef __wasilibc_unmodified_upstream
77 struct __clockid clock_id = { .id = clock };
78#endif
79 volatile int *fut;
80
81 if ((m->_m_type&15) && (m->_m_lock&INT_MAX) != __pthread_self()->tid)
82 return EPERM;
83
84 if (ts && ts->tv_nsec >= 1000000000UL)
85 return EINVAL;
86
87 __pthread_testcancel();
88
89 if (c->_c_shared) {
90 shared = 1;
91 fut = &c->_c_seq;
92 seq = c->_c_seq;
93 a_inc(&c->_c_waiters);
94 } else {
95 lock(&c->_c_lock);
96
97 seq = node.barrier = 2;
98 fut = &node.barrier;
99 node.state = WAITING;
100 node.next = c->_c_head;
101 c->_c_head = &node;
102 if (!c->_c_tail) c->_c_tail = &node;
103 else node.next->prev = &node;
104
105 unlock(&c->_c_lock);
106 }
107
108 __pthread_mutex_unlock(m);
109
110 __pthread_setcancelstate(PTHREAD_CANCEL_MASKED, &cs);
111 if (cs == PTHREAD_CANCEL_DISABLE) __pthread_setcancelstate(cs, 0);
112
113#ifdef __wasilibc_unmodified_upstream
114 do e = __timedwait_cp(fut, seq, clock, ts, !shared);
115#else
116 do e = __timedwait_cp(fut, seq, &clock_id, ts, !shared);
117#endif
118 while (*fut==seq && (!e || e==EINTR));
119 if (e == EINTR) e = 0;
120
121 if (shared) {
122 /* Suppress cancellation if a signal was potentially
123 * consumed; this is a legitimate form of spurious
124 * wake even if not. */
125 if (e == ECANCELED && c->_c_seq != seq) e = 0;
126 if (a_fetch_add(&c->_c_waiters, -1) == -0x7fffffff)
127 __wake(&c->_c_waiters, 1, 0);
128 oldstate = WAITING;
129 goto relock;
130 }
131
132 oldstate = a_cas(&node.state, WAITING, LEAVING);
133
134 if (oldstate == WAITING) {
135 /* Access to cv object is valid because this waiter was not
136 * yet signaled and a new signal/broadcast cannot return
137 * after seeing a LEAVING waiter without getting notified
138 * via the futex notify below. */
139
140 lock(&c->_c_lock);
141
142 if (c->_c_head == &node) c->_c_head = node.next;
143 else if (node.prev) node.prev->next = node.next;
144 if (c->_c_tail == &node) c->_c_tail = node.prev;
145 else if (node.next) node.next->prev = node.prev;
146
147 unlock(&c->_c_lock);
148
149 if (node.notify) {
150 if (a_fetch_add(node.notify, -1)==1)
151 __wake(node.notify, 1, 1);
152 }
153 } else {
154 /* Lock barrier first to control wake order. */
155 lock(&node.barrier);
156 }
157
158relock:
159 /* Errors locking the mutex override any existing error or
160 * cancellation, since the caller must see them to know the
161 * state of the mutex. */
162 if ((tmp = pthread_mutex_lock(m))) e = tmp;
163
164 if (oldstate == WAITING) goto done;
165
166 if (!node.next && !(m->_m_type & 8))
167 a_inc(&m->_m_waiters);
168
169 /* Unlock the barrier that's holding back the next waiter, and
170 * either wake it or requeue it to the mutex. */
171 if (node.prev) {
172 int val = m->_m_lock;
173 if (val>0) a_cas(&m->_m_lock, val, val|0x80000000);
174 unlock_requeue(&node.prev->barrier, &m->_m_lock, m->_m_type & (8|128));
175 } else if (!(m->_m_type & 8)) {
176 a_dec(&m->_m_waiters);
177 }
178
179 /* Since a signal was consumed, cancellation is not permitted. */
180 if (e == ECANCELED) e = 0;
181
182done:
183 __pthread_setcancelstate(cs, 0);
184
185 if (e == ECANCELED) {
186 __pthread_testcancel();
187 __pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0);
188 }
189
190 return e;
191}
192
193int __private_cond_signal(pthread_cond_t *c, int n)
194{
195 struct waiter *p, *first=0;
196 volatile int ref = 0;
197 int cur;
198
199 lock(&c->_c_lock);
200 for (p=c->_c_tail; n && p; p=p->prev) {
201 if (a_cas(&p->state, WAITING, SIGNALED) != WAITING) {
202 ref++;
203 p->notify = &ref;
204 } else {
205 n--;
206 if (!first) first=p;
207 }
208 }
209 /* Split the list, leaving any remainder on the cv. */
210 if (p) {
211 if (p->next) p->next->prev = 0;
212 p->next = 0;
213 } else {
214 c->_c_head = 0;
215 }
216 c->_c_tail = p;
217 unlock(&c->_c_lock);
218
219 /* Wait for any waiters in the LEAVING state to remove
220 * themselves from the list before returning or allowing
221 * signaled threads to proceed. */
222 while ((cur = ref)) __wait(&ref, 0, cur, 1);
223
224 /* Allow first signaled waiter, if any, to proceed. */
225 if (first) unlock(&first->barrier);
226
227 return 0;
228}
229
230weak_alias(__pthread_cond_timedwait, pthread_cond_timedwait);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cond_wait.c deleted-6
......@@ -1,6 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_cond_wait(pthread_cond_t *restrict c, pthread_mutex_t *restrict m)
4{
5 return pthread_cond_timedwait(c, m, 0);
6}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_condattr_destroy.c deleted-6
......@@ -1,6 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_condattr_destroy(pthread_condattr_t *a)
4{
5 return 0;
6}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_condattr_init.c deleted-7
......@@ -1,7 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_condattr_init(pthread_condattr_t *a)
4{
5 *a = (pthread_condattr_t){0};
6 return 0;
7}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_condattr_setclock.c deleted-21
......@@ -1,21 +0,0 @@
1#include "pthread_impl.h"
2
3#ifndef __wasilibc_unmodified_upstream
4#include <common/clock.h>
5#endif
6
7int pthread_condattr_setclock(pthread_condattr_t *a, clockid_t clk)
8{
9#ifdef __wasilibc_unmodified_upstream
10 if (clk < 0 || clk-2U < 2) return EINVAL;
11#else
12 if (clk->id < 0 || clk->id-2U < 2) return EINVAL;
13#endif
14 a->__attr &= 0x80000000;
15#ifdef __wasilibc_unmodified_upstream
16 a->__attr |= clk;
17#else
18 a->__attr |= clk->id;
19#endif
20 return 0;
21}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_condattr_setpshared.c deleted-9
......@@ -1,9 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_condattr_setpshared(pthread_condattr_t *a, int pshared)
4{
5 if (pshared > 1U) return EINVAL;
6 a->__attr &= 0x7fffffff;
7 a->__attr |= (unsigned)pshared<<31;
8 return 0;
9}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_create.c deleted-585
......@@ -1,585 +0,0 @@
1#define _GNU_SOURCE
2#include "pthread_impl.h"
3#include "stdio_impl.h"
4#include "libc.h"
5#include "lock.h"
6#ifdef __wasilibc_unmodified_upstream
7#include <sys/mman.h>
8#endif
9#include <string.h>
10#include <stddef.h>
11#ifndef __wasilibc_unmodified_upstream
12#include <stdatomic.h>
13#endif
14
15#include <stdalign.h>
16
17static void dummy_0()
18{
19}
20weak_alias(dummy_0, __acquire_ptc);
21weak_alias(dummy_0, __release_ptc);
22weak_alias(dummy_0, __pthread_tsd_run_dtors);
23weak_alias(dummy_0, __do_orphaned_stdio_locks);
24#ifdef __wasilibc_unmodified_upstream
25weak_alias(dummy_0, __dl_thread_cleanup);
26weak_alias(dummy_0, __membarrier_init);
27#endif
28
29static int tl_lock_count;
30static int tl_lock_waiters;
31
32void __tl_lock(void)
33{
34 int tid = __pthread_self()->tid;
35 int val = __thread_list_lock;
36 if (val == tid) {
37 tl_lock_count++;
38 return;
39 }
40 while ((val = a_cas(&__thread_list_lock, 0, tid)))
41 __wait(&__thread_list_lock, &tl_lock_waiters, val, 0);
42}
43
44void __tl_unlock(void)
45{
46 if (tl_lock_count) {
47 tl_lock_count--;
48 return;
49 }
50 a_store(&__thread_list_lock, 0);
51 if (tl_lock_waiters) __wake(&__thread_list_lock, 1, 0);
52}
53
54void __tl_sync(pthread_t td)
55{
56 a_barrier();
57 int val = __thread_list_lock;
58 if (!val) return;
59 __wait(&__thread_list_lock, &tl_lock_waiters, val, 0);
60 if (tl_lock_waiters) __wake(&__thread_list_lock, 1, 0);
61}
62
63#ifdef __wasilibc_unmodified_upstream
64_Noreturn void __pthread_exit(void *result)
65#else
66static void __pthread_exit(void *result)
67#endif
68{
69 pthread_t self = __pthread_self();
70 sigset_t set;
71
72 self->canceldisable = 1;
73 self->cancelasync = 0;
74 self->result = result;
75
76 while (self->cancelbuf) {
77 void (*f)(void *) = self->cancelbuf->__f;
78 void *x = self->cancelbuf->__x;
79 self->cancelbuf = self->cancelbuf->__next;
80 f(x);
81 }
82
83 __pthread_tsd_run_dtors();
84
85#ifdef __wasilibc_unmodified_upstream
86 __block_app_sigs(&set);
87#endif
88
89 /* This atomic potentially competes with a concurrent pthread_detach
90 * call; the loser is responsible for freeing thread resources. */
91 int state = a_cas(&self->detach_state, DT_JOINABLE, DT_EXITING);
92
93 if (state==DT_DETACHED && self->map_base) {
94 /* Since __unmapself bypasses the normal munmap code path,
95 * explicitly wait for vmlock holders first. This must be
96 * done before any locks are taken, to avoid lock ordering
97 * issues that could lead to deadlock. */
98#ifdef __wasilibc_unmodified_upstream
99 __vm_wait();
100#endif
101 }
102
103 /* Access to target the exiting thread with syscalls that use
104 * its kernel tid is controlled by killlock. For detached threads,
105 * any use past this point would have undefined behavior, but for
106 * joinable threads it's a valid usage that must be handled.
107 * Signals must be blocked since pthread_kill must be AS-safe. */
108 LOCK(self->killlock);
109
110 /* The thread list lock must be AS-safe, and thus depends on
111 * application signals being blocked above. */
112 __tl_lock();
113
114 /* If this is the only thread in the list, don't proceed with
115 * termination of the thread, but restore the previous lock and
116 * signal state to prepare for exit to call atexit handlers. */
117 if (self->next == self) {
118 __tl_unlock();
119 UNLOCK(self->killlock);
120 self->detach_state = state;
121#ifdef __wasilibc_unmodified_upstream
122 __restore_sigs(&set);
123#endif
124 exit(0);
125 }
126
127 /* At this point we are committed to thread termination. */
128
129#ifdef __wasilibc_unmodified_upstream
130 /* Process robust list in userspace to handle non-pshared mutexes
131 * and the detached thread case where the robust list head will
132 * be invalid when the kernel would process it. */
133 __vm_lock();
134#endif
135 volatile void *volatile *rp;
136 while ((rp=self->robust_list.head) && rp != &self->robust_list.head) {
137 pthread_mutex_t *m = (void *)((char *)rp
138 - offsetof(pthread_mutex_t, _m_next));
139 int waiters = m->_m_waiters;
140 int priv = (m->_m_type & 128) ^ 128;
141 self->robust_list.pending = rp;
142 self->robust_list.head = *rp;
143 int cont = a_swap(&m->_m_lock, 0x40000000);
144 self->robust_list.pending = 0;
145 if (cont < 0 || waiters)
146 __wake(&m->_m_lock, 1, priv);
147 }
148#ifdef __wasilibc_unmodified_upstream
149 __vm_unlock();
150#endif
151
152 __do_orphaned_stdio_locks();
153#ifdef __wasilibc_unmodified_upstream
154 __dl_thread_cleanup();
155#endif
156
157 /* Last, unlink thread from the list. This change will not be visible
158 * until the lock is released, which only happens after SYS_exit
159 * has been called, via the exit futex address pointing at the lock.
160 * This needs to happen after any possible calls to LOCK() that might
161 * skip locking if process appears single-threaded. */
162 if (!--libc.threads_minus_1) libc.need_locks = -1;
163 self->next->prev = self->prev;
164 self->prev->next = self->next;
165 self->prev = self->next = self;
166
167#ifndef __wasilibc_unmodified_upstream
168 /* On Linux, the thread is created with CLONE_CHILD_CLEARTID,
169 * and this lock will unlock by kernel when this thread terminates.
170 * So we should unlock it here in WebAssembly.
171 * See also set_tid_address(2) */
172 __tl_unlock();
173#endif
174
175#ifdef __wasilibc_unmodified_upstream
176 if (state==DT_DETACHED && self->map_base) {
177 /* Detached threads must block even implementation-internal
178 * signals, since they will not have a stack in their last
179 * moments of existence. */
180 __block_all_sigs(&set);
181
182 /* Robust list will no longer be valid, and was already
183 * processed above, so unregister it with the kernel. */
184 if (self->robust_list.off)
185 __syscall(SYS_set_robust_list, 0, 3*sizeof(long));
186
187 /* The following call unmaps the thread's stack mapping
188 * and then exits without touching the stack. */
189 __unmapself(self->map_base, self->map_size);
190 }
191#else
192 if (state==DT_DETACHED && self->map_base) {
193 // __syscall(SYS_exit) would unlock the thread, list
194 // do it manually here
195 __tl_unlock();
196 free(self->map_base);
197 // Can't use `exit()` here, because it is too high level
198 return;
199 }
200#endif
201
202 /* Wake any joiner. */
203 a_store(&self->detach_state, DT_EXITED);
204 __wake(&self->detach_state, 1, 1);
205
206 /* After the kernel thread exits, its tid may be reused. Clear it
207 * to prevent inadvertent use and inform functions that would use
208 * it that it's no longer available. */
209 self->tid = 0;
210 UNLOCK(self->killlock);
211
212#ifdef __wasilibc_unmodified_upstream
213 for (;;) __syscall(SYS_exit, 0);
214#else
215 // __syscall(SYS_exit) would unlock the thread, list
216 // do it manually here
217 __tl_unlock();
218 // Can't use `exit()` here, because it is too high level
219#endif
220}
221
222void __do_cleanup_push(struct __ptcb *cb)
223{
224 struct pthread *self = __pthread_self();
225 cb->__next = self->cancelbuf;
226 self->cancelbuf = cb;
227}
228
229void __do_cleanup_pop(struct __ptcb *cb)
230{
231 __pthread_self()->cancelbuf = cb->__next;
232}
233
234struct start_args {
235#ifdef __wasilibc_unmodified_upstream
236 void *(*start_func)(void *);
237 void *start_arg;
238 volatile int control;
239 unsigned long sig_mask[_NSIG/8/sizeof(long)];
240#else
241 /*
242 * Note: the offset of the "stack" and "tls_base" members
243 * in this structure is hardcoded in wasi_thread_start.
244 */
245 void *stack;
246 void *tls_base;
247 void *(*start_func)(void *);
248 void *start_arg;
249#endif
250};
251
252#ifdef __wasilibc_unmodified_upstream
253static int start(void *p)
254{
255 struct start_args *args = p;
256 int state = args->control;
257 if (state) {
258 if (a_cas(&args->control, 1, 2)==1)
259 __wait(&args->control, 0, 2, 1);
260 if (args->control) {
261#ifdef __wasilibc_unmodified_upstream
262 __syscall(SYS_set_tid_address, &args->control);
263 for (;;) __syscall(SYS_exit, 0);
264#endif
265 }
266 }
267#ifdef __wasilibc_unmodified_upstream
268 __syscall(SYS_rt_sigprocmask, SIG_SETMASK, &args->sig_mask, 0, _NSIG/8);
269#endif
270 __pthread_exit(args->start_func(args->start_arg));
271 return 0;
272}
273
274static int start_c11(void *p)
275{
276 struct start_args *args = p;
277 int (*start)(void*) = (int(*)(void*)) args->start_func;
278 __pthread_exit((void *)(uintptr_t)start(args->start_arg));
279 return 0;
280}
281#else
282
283/*
284 * We want to ensure wasi_thread_start is linked whenever
285 * pthread_create is used. The following reference is to ensure that.
286 * Otherwise, the linker doesn't notice the dependency because
287 * wasi_thread_start is used indirectly via a wasm export.
288 */
289void wasi_thread_start(int tid, void *p);
290hidden void *__dummy_reference = wasi_thread_start;
291
292hidden void __wasi_thread_start_C(int tid, void *p)
293{
294 struct start_args *args = p;
295 pthread_t self = __pthread_self();
296 // Set the thread ID (TID) on the pthread structure. The TID is stored
297 // atomically since it is also stored by the parent thread; this way,
298 // whichever thread (parent or child) reaches this point first can proceed
299 // without waiting.
300 atomic_store((atomic_int *) &(self->tid), tid);
301 // Execute the user's start function.
302 __pthread_exit(args->start_func(args->start_arg));
303}
304#endif
305
306#ifdef __wasilibc_unmodified_upstream
307#define ROUND(x) (((x)+PAGE_SIZE-1)&-PAGE_SIZE)
308#else
309/*
310 * As we allocate stack with malloc() instead of mmap/mprotect,
311 * there is no point to round it up to PAGE_SIZE.
312 * Instead, round up to a sane alignment.
313 * Note: PAGE_SIZE is rather big on WASM. (65536)
314 */
315#define ROUND(x) (((x)+16-1)&-16)
316#endif
317
318/* pthread_key_create.c overrides this */
319static volatile size_t dummy = 0;
320weak_alias(dummy, __pthread_tsd_size);
321static void *dummy_tsd[1] = { 0 };
322weak_alias(dummy_tsd, __pthread_tsd_main);
323
324static FILE *volatile dummy_file = 0;
325weak_alias(dummy_file, __stdin_used);
326weak_alias(dummy_file, __stdout_used);
327weak_alias(dummy_file, __stderr_used);
328
329static void init_file_lock(FILE *f)
330{
331 if (f && f->lock<0) f->lock = 0;
332}
333
334int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp, void *(*entry)(void *), void *restrict arg)
335{
336 int ret, c11 = (attrp == __ATTRP_C11_THREAD);
337 size_t size, guard;
338 struct pthread *self, *new;
339 unsigned char *map = 0, *stack = 0, *tsd = 0, *stack_limit;
340#ifdef __wasilibc_unmodified_upstream
341 unsigned flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND
342 | CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS
343 | CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID | CLONE_DETACHED;
344#endif
345 pthread_attr_t attr = { 0 };
346 sigset_t set;
347#ifndef __wasilibc_unmodified_upstream
348 size_t tls_size = __builtin_wasm_tls_size();
349 size_t tls_align = __builtin_wasm_tls_align();
350 void* tls_base = __builtin_wasm_tls_base();
351 void* new_tls_base;
352 size_t tls_offset;
353 tls_size += tls_align;
354#endif
355
356#ifdef __wasilibc_unmodified_upstream
357 if (!libc.can_do_threads) return ENOSYS;
358#endif
359 self = __pthread_self();
360 if (!libc.threaded) {
361 for (FILE *f=*__ofl_lock(); f; f=f->next)
362 init_file_lock(f);
363 __ofl_unlock();
364 init_file_lock(__stdin_used);
365 init_file_lock(__stdout_used);
366 init_file_lock(__stderr_used);
367#ifdef __wasilibc_unmodified_upstream
368 __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, SIGPT_SET, 0, _NSIG/8);
369#endif
370 self->tsd = (void **)__pthread_tsd_main;
371#ifdef __wasilibc_unmodified_upstream
372 __membarrier_init();
373#endif
374 libc.threaded = 1;
375 }
376 if (attrp && !c11) attr = *attrp;
377
378 __acquire_ptc();
379 if (!attrp || c11) {
380 attr._a_stacksize = __default_stacksize;
381 attr._a_guardsize = __default_guardsize;
382 }
383
384 if (attr._a_stackaddr) {
385#ifdef __wasilibc_unmodified_upstream
386 size_t need = libc.tls_size + __pthread_tsd_size;
387#else
388 size_t need = tls_size + __pthread_tsd_size;
389#endif
390 size = attr._a_stacksize;
391 stack = (void *)(attr._a_stackaddr & -16);
392 stack_limit = (void *)(attr._a_stackaddr - size);
393 /* Use application-provided stack for TLS only when
394 * it does not take more than ~12% or 2k of the
395 * application's stack space. */
396 if (need < size/8 && need < 2048) {
397 tsd = stack - __pthread_tsd_size;
398#ifdef __wasilibc_unmodified_upstream
399 stack = tsd - libc.tls_size;
400#else
401 stack = tsd - tls_size;
402#endif
403 memset(stack, 0, need);
404 } else {
405 size = ROUND(need);
406 }
407 guard = 0;
408 } else {
409 guard = ROUND(attr._a_guardsize);
410 size = guard + ROUND(attr._a_stacksize
411#ifdef __wasilibc_unmodified_upstream
412 + libc.tls_size + __pthread_tsd_size);
413#else
414 + tls_size + __pthread_tsd_size);
415#endif
416 }
417
418 if (!tsd) {
419#ifdef __wasilibc_unmodified_upstream
420 if (guard) {
421 map = __mmap(0, size, PROT_NONE, MAP_PRIVATE|MAP_ANON, -1, 0);
422 if (map == MAP_FAILED) goto fail;
423 if (__mprotect(map+guard, size-guard, PROT_READ|PROT_WRITE)
424 && errno != ENOSYS) {
425 __munmap(map, size);
426 goto fail;
427 }
428 } else {
429 map = __mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
430 if (map == MAP_FAILED) goto fail;
431 }
432#else
433 map = malloc(size);
434 if (!map) goto fail;
435#endif
436 tsd = map + size - __pthread_tsd_size;
437 if (!stack) {
438#ifdef __wasilibc_unmodified_upstream
439 stack = tsd - libc.tls_size;
440#else
441 stack = tsd - tls_size;
442#endif
443 stack_limit = map + guard;
444 }
445 }
446
447#ifdef __wasilibc_unmodified_upstream
448 new = __copy_tls(tsd - libc.tls_size);
449#else
450 new_tls_base = __copy_tls(tsd - tls_size);
451 tls_offset = new_tls_base - tls_base;
452 new = (void*)((uintptr_t)self + tls_offset);
453#endif
454 new->map_base = map;
455 new->map_size = size;
456 new->stack = stack;
457 new->stack_size = stack - stack_limit;
458 new->guard_size = guard;
459 new->self = new;
460 new->tsd = (void *)tsd;
461 new->locale = &libc.global_locale;
462 if (attr._a_detach) {
463 new->detach_state = DT_DETACHED;
464 } else {
465 new->detach_state = DT_JOINABLE;
466 }
467 new->robust_list.head = &new->robust_list.head;
468 new->canary = self->canary;
469 new->sysinfo = self->sysinfo;
470
471 /* Setup argument structure for the new thread on its stack.
472 * It's safe to access from the caller only until the thread
473 * list is unlocked. */
474#ifdef __wasilibc_unmodified_upstream
475 stack -= (uintptr_t)stack % sizeof(uintptr_t);
476 stack -= sizeof(struct start_args);
477 struct start_args *args = (void *)stack;
478 args->start_func = entry;
479 args->start_arg = arg;
480 args->control = attr._a_sched ? 1 : 0;
481
482 /* Application signals (but not the synccall signal) must be
483 * blocked before the thread list lock can be taken, to ensure
484 * that the lock is AS-safe. */
485 __block_app_sigs(&set);
486
487 /* Ensure SIGCANCEL is unblocked in new thread. This requires
488 * working with a copy of the set so we can restore the
489 * original mask in the calling thread. */
490 memcpy(&args->sig_mask, &set, sizeof args->sig_mask);
491 args->sig_mask[(SIGCANCEL-1)/8/sizeof(long)] &=
492 ~(1UL<<((SIGCANCEL-1)%(8*sizeof(long))));
493#else
494 /* Align the stack to struct start_args */
495 stack -= sizeof(struct start_args);
496 stack -= (uintptr_t)stack % alignof(struct start_args);
497 struct start_args *args = (void *)stack;
498
499 /* Align the stack to 16 and store it */
500 new->stack = (void *)((uintptr_t) stack & -16);
501 /* Correct the stack size */
502 new->stack_size = stack - stack_limit;
503
504 args->stack = new->stack; /* just for convenience of asm trampoline */
505 args->start_func = entry;
506 args->start_arg = arg;
507 args->tls_base = (void*)new_tls_base;
508#endif
509
510 __tl_lock();
511 if (!libc.threads_minus_1++) libc.need_locks = 1;
512#ifdef __wasilibc_unmodified_upstream
513 ret = __clone((c11 ? start_c11 : start), stack, flags, args, &new->tid, TP_ADJ(new), &__thread_list_lock);
514#else
515 /* Instead of `__clone`, WASI uses a host API to instantiate a new version
516 * of the current module and start executing the entry function. The
517 * wasi-threads specification requires the module to export a
518 * `wasi_thread_start` function, which is invoked with `args`. */
519 ret = __wasi_thread_spawn((void *) args);
520#endif
521
522#ifdef __wasilibc_unmodified_upstream
523 /* All clone failures translate to EAGAIN. If explicit scheduling
524 * was requested, attempt it before unlocking the thread list so
525 * that the failed thread is never exposed and so that we can
526 * clean up all transient resource usage before returning. */
527 if (ret < 0) {
528 ret = -EAGAIN;
529 } else if (attr._a_sched) {
530 ret = __syscall(SYS_sched_setscheduler,
531 new->tid, attr._a_policy, &attr._a_prio);
532 if (a_swap(&args->control, ret ? 3 : 0)==2)
533 __wake(&args->control, 1, 1);
534 if (ret)
535 __wait(&args->control, 0, 3, 0);
536 }
537#else
538 /* `wasi_thread_spawn` will either return a host-provided thread ID (TID)
539 * (`>= 0`) or an error code (`< 0`). As in the unmodified version, all
540 * spawn failures translate to EAGAIN; unlike the modified version, there is
541 * no need to "start up" the child thread--the host does this. If the spawn
542 * did succeed, then we store the TID atomically, since this parent thread
543 * is racing with the child thread to set this field; this way, whichever
544 * thread reaches this point first can continue without waiting. */
545 if (ret < 0) {
546 ret = -EAGAIN;
547 } else {
548 atomic_store((atomic_int *) &(new->tid), ret);
549 }
550#endif
551
552 if (ret >= 0) {
553 new->next = self->next;
554 new->prev = self;
555 new->next->prev = new;
556 new->prev->next = new;
557 } else {
558 if (!--libc.threads_minus_1) libc.need_locks = 0;
559 }
560 __tl_unlock();
561#ifdef __wasilibc_unmodified_upstream
562 __restore_sigs(&set);
563#endif
564 __release_ptc();
565
566 if (ret < 0) {
567#ifdef __wasilibc_unmodified_upstream
568 if (map) __munmap(map, size);
569#else
570 free(map);
571#endif
572 return -ret;
573 }
574
575 *res = new;
576 return 0;
577fail:
578 __release_ptc();
579 return EAGAIN;
580}
581
582#ifdef __wasilibc_unmodified_upstream
583weak_alias(__pthread_exit, pthread_exit);
584#endif
585weak_alias(__pthread_create, pthread_create);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_detach.c deleted-14
......@@ -1,14 +0,0 @@
1#include "pthread_impl.h"
2#include <threads.h>
3
4static int __pthread_detach(pthread_t t)
5{
6 /* If the cas fails, detach state is either already-detached
7 * or exiting/exited, and pthread_join will trap or cleanup. */
8 if (a_cas(&t->detach_state, DT_JOINABLE, DT_DETACHED) != DT_JOINABLE)
9 return __pthread_join(t, 0);
10 return 0;
11}
12
13weak_alias(__pthread_detach, pthread_detach);
14weak_alias(__pthread_detach, thrd_detach);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_equal.c deleted-10
......@@ -1,10 +0,0 @@
1#include <pthread.h>
2#include <threads.h>
3
4static int __pthread_equal(pthread_t a, pthread_t b)
5{
6 return a==b;
7}
8
9weak_alias(__pthread_equal, pthread_equal);
10weak_alias(__pthread_equal, thrd_equal);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_getattr_np.c deleted-24
......@@ -1,24 +0,0 @@
1#define _GNU_SOURCE
2#include "pthread_impl.h"
3#include "libc.h"
4#include <sys/mman.h>
5
6int pthread_getattr_np(pthread_t t, pthread_attr_t *a)
7{
8 *a = (pthread_attr_t){0};
9 a->_a_detach = t->detach_state>=DT_DETACHED;
10 a->_a_guardsize = t->guard_size;
11 if (t->stack) {
12 a->_a_stackaddr = (uintptr_t)t->stack;
13 a->_a_stacksize = t->stack_size;
14 } else {
15 char *p = (void *)libc.auxv;
16 size_t l = PAGE_SIZE;
17 p += -(uintptr_t)p & PAGE_SIZE-1;
18 a->_a_stackaddr = (uintptr_t)p;
19 while (mremap(p-l-PAGE_SIZE, PAGE_SIZE, 2*PAGE_SIZE, 0)==MAP_FAILED && errno==ENOMEM)
20 l += PAGE_SIZE;
21 a->_a_stacksize = l;
22 }
23 return 0;
24}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_getconcurrency.c deleted-6
......@@ -1,6 +0,0 @@
1#include <pthread.h>
2
3int pthread_getconcurrency()
4{
5 return 0;
6}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_getcpuclockid.c deleted-7
......@@ -1,7 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_getcpuclockid(pthread_t t, clockid_t *clockid)
4{
5 *clockid = (-t->tid-1)*8U + 6;
6 return 0;
7}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_getname_np.c deleted-25
......@@ -1,25 +0,0 @@
1#define _GNU_SOURCE
2#include <fcntl.h>
3#include <unistd.h>
4#include <sys/prctl.h>
5
6#include "pthread_impl.h"
7
8int pthread_getname_np(pthread_t thread, char *name, size_t len)
9{
10 int fd, cs, status = 0;
11 char f[sizeof "/proc/self/task//comm" + 3*sizeof(int)];
12
13 if (len < 16) return ERANGE;
14
15 if (thread == pthread_self())
16 return prctl(PR_GET_NAME, (unsigned long)name, 0UL, 0UL, 0UL) ? errno : 0;
17
18 snprintf(f, sizeof f, "/proc/self/task/%d/comm", thread->tid);
19 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
20 if ((fd = open(f, O_RDONLY|O_CLOEXEC)) < 0 || (len = read(fd, name, len)) == -1) status = errno;
21 else name[len-1] = 0; /* remove trailing new line only if successful */
22 if (fd >= 0) close(fd);
23 pthread_setcancelstate(cs, 0);
24 return status;
25}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_getschedparam.c deleted-21
......@@ -1,21 +0,0 @@
1#include "pthread_impl.h"
2#include "lock.h"
3
4int pthread_getschedparam(pthread_t t, int *restrict policy, struct sched_param *restrict param)
5{
6 int r;
7 sigset_t set;
8 __block_app_sigs(&set);
9 LOCK(t->killlock);
10 if (!t->tid) {
11 r = ESRCH;
12 } else {
13 r = -__syscall(SYS_sched_getparam, t->tid, param);
14 if (!r) {
15 *policy = __syscall(SYS_sched_getscheduler, t->tid);
16 }
17 }
18 UNLOCK(t->killlock);
19 __restore_sigs(&set);
20 return r;
21}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_getspecific.c deleted-11
......@@ -1,11 +0,0 @@
1#include "pthread_impl.h"
2#include <threads.h>
3
4static void *__pthread_getspecific(pthread_key_t k)
5{
6 struct pthread *self = __pthread_self();
7 return self->tsd[k];
8}
9
10weak_alias(__pthread_getspecific, pthread_getspecific);
11weak_alias(__pthread_getspecific, tss_get);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_join.c deleted-46
......@@ -1,46 +0,0 @@
1#define _GNU_SOURCE
2#include "pthread_impl.h"
3#ifdef __wasilibc_unmodified_upstream
4#include <sys/mman.h>
5#endif
6
7static void dummy1(pthread_t t)
8{
9}
10weak_alias(dummy1, __tl_sync);
11
12static int __pthread_timedjoin_np(pthread_t t, void **res, const struct timespec *at)
13{
14 int state, cs, r = 0;
15 __pthread_testcancel();
16 __pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
17 if (cs == PTHREAD_CANCEL_ENABLE) __pthread_setcancelstate(cs, 0);
18 while ((state = t->detach_state) && r != ETIMEDOUT && r != EINVAL) {
19 if (state >= DT_DETACHED) a_crash();
20 r = __timedwait_cp(&t->detach_state, state, CLOCK_REALTIME, at, 1);
21 }
22 __pthread_setcancelstate(cs, 0);
23 if (r == ETIMEDOUT || r == EINVAL) return r;
24 __tl_sync(t);
25 if (res) *res = t->result;
26#ifdef __wasilibc_unmodified_upstream
27 if (t->map_base) __munmap(t->map_base, t->map_size);
28#else
29 if (t->map_base) free(t->map_base);
30#endif
31 return 0;
32}
33
34int __pthread_join(pthread_t t, void **res)
35{
36 return __pthread_timedjoin_np(t, res, 0);
37}
38
39static int __pthread_tryjoin_np(pthread_t t, void **res)
40{
41 return t->detach_state==DT_JOINABLE ? EBUSY : __pthread_join(t, res);
42}
43
44weak_alias(__pthread_tryjoin_np, pthread_tryjoin_np);
45weak_alias(__pthread_timedjoin_np, pthread_timedjoin_np);
46weak_alias(__pthread_join, pthread_join);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_key_create.c deleted-95
......@@ -1,95 +0,0 @@
1#include "pthread_impl.h"
2
3volatile size_t __pthread_tsd_size = sizeof(void *) * PTHREAD_KEYS_MAX;
4void *__pthread_tsd_main[PTHREAD_KEYS_MAX] = { 0 };
5
6static void (*keys[PTHREAD_KEYS_MAX])(void *);
7
8static pthread_rwlock_t key_lock = PTHREAD_RWLOCK_INITIALIZER;
9
10static pthread_key_t next_key;
11
12static void nodtor(void *dummy)
13{
14}
15
16static void dummy_0(void)
17{
18}
19
20weak_alias(dummy_0, __tl_lock);
21weak_alias(dummy_0, __tl_unlock);
22
23int __pthread_key_create(pthread_key_t *k, void (*dtor)(void *))
24{
25 pthread_t self = __pthread_self();
26
27 /* This can only happen in the main thread before
28 * pthread_create has been called. */
29 if (!self->tsd) self->tsd = __pthread_tsd_main;
30
31 /* Purely a sentinel value since null means slot is free. */
32 if (!dtor) dtor = nodtor;
33
34 __pthread_rwlock_wrlock(&key_lock);
35 pthread_key_t j = next_key;
36 do {
37 if (!keys[j]) {
38 keys[next_key = *k = j] = dtor;
39 __pthread_rwlock_unlock(&key_lock);
40 return 0;
41 }
42 } while ((j=(j+1)%PTHREAD_KEYS_MAX) != next_key);
43
44 __pthread_rwlock_unlock(&key_lock);
45 return EAGAIN;
46}
47
48int __pthread_key_delete(pthread_key_t k)
49{
50 sigset_t set;
51 pthread_t self = __pthread_self(), td=self;
52
53#ifdef __wasilibc_unmodified_upstream
54 __block_app_sigs(&set);
55#endif
56 __pthread_rwlock_wrlock(&key_lock);
57
58 __tl_lock();
59 do td->tsd[k] = 0;
60 while ((td=td->next)!=self);
61 __tl_unlock();
62
63 keys[k] = 0;
64
65 __pthread_rwlock_unlock(&key_lock);
66#ifdef __wasilibc_unmodified_upstream
67 __restore_sigs(&set);
68#endif
69
70 return 0;
71}
72
73void __pthread_tsd_run_dtors()
74{
75 pthread_t self = __pthread_self();
76 int i, j;
77 for (j=0; self->tsd_used && j<PTHREAD_DESTRUCTOR_ITERATIONS; j++) {
78 __pthread_rwlock_rdlock(&key_lock);
79 self->tsd_used = 0;
80 for (i=0; i<PTHREAD_KEYS_MAX; i++) {
81 void *val = self->tsd[i];
82 void (*dtor)(void *) = keys[i];
83 self->tsd[i] = 0;
84 if (val && dtor && dtor != nodtor) {
85 __pthread_rwlock_unlock(&key_lock);
86 dtor(val);
87 __pthread_rwlock_rdlock(&key_lock);
88 }
89 }
90 __pthread_rwlock_unlock(&key_lock);
91 }
92}
93
94weak_alias(__pthread_key_create, pthread_key_create);
95weak_alias(__pthread_key_delete, pthread_key_delete);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_kill.c deleted-18
......@@ -1,18 +0,0 @@
1#include "pthread_impl.h"
2#include "lock.h"
3
4int pthread_kill(pthread_t t, int sig)
5{
6 int r;
7 sigset_t set;
8 /* Block not just app signals, but internal ones too, since
9 * pthread_kill is used to implement pthread_cancel, which
10 * must be async-cancel-safe. */
11 __block_all_sigs(&set);
12 LOCK(t->killlock);
13 r = t->tid ? -__syscall(SYS_tkill, t->tid, sig)
14 : (sig+0U >= _NSIG ? EINVAL : 0);
15 UNLOCK(t->killlock);
16 __restore_sigs(&set);
17 return r;
18}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_consistent.c deleted-14
......@@ -1,14 +0,0 @@
1#include "pthread_impl.h"
2#include "atomic.h"
3
4int pthread_mutex_consistent(pthread_mutex_t *m)
5{
6 int old = m->_m_lock;
7 int own = old & 0x3fffffff;
8 if (!(m->_m_type & 4) || !own || !(old & 0x40000000))
9 return EINVAL;
10 if (own != __pthread_self()->tid)
11 return EPERM;
12 a_and(&m->_m_lock, ~0x40000000);
13 return 0;
14}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_destroy.c deleted-18
......@@ -1,18 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_mutex_destroy(pthread_mutex_t *mutex)
4{
5#ifdef __wasilibc_unmodified_upstream
6 /* If the mutex being destroyed is process-shared and has nontrivial
7 * type (tracking ownership), it might be in the pending slot of a
8 * robust_list; wait for quiescence. */
9 if (mutex->_m_type > 128) __vm_wait();
10#else
11 /* For now, wasi-libc chooses to avoid implementing robust mutex support
12 * though this could be added later. The error code indicates that the
13 * mutex was an invalid type, but it would be more accurate as
14 * "unimplemented". */
15 if (mutex->_m_type > 128) return EINVAL;
16#endif
17 return 0;
18}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_getprioceiling.c deleted-6
......@@ -1,6 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_mutex_getprioceiling(const pthread_mutex_t *restrict m, int *restrict ceiling)
4{
5 return EINVAL;
6}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_init.c deleted-8
......@@ -1,8 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_mutex_init(pthread_mutex_t *restrict m, const pthread_mutexattr_t *restrict a)
4{
5 *m = (pthread_mutex_t){0};
6 if (a) m->_m_type = a->__attr;
7 return 0;
8}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_lock.c deleted-12
......@@ -1,12 +0,0 @@
1#include "pthread_impl.h"
2
3int __pthread_mutex_lock(pthread_mutex_t *m)
4{
5 if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL
6 && !a_cas(&m->_m_lock, 0, EBUSY))
7 return 0;
8
9 return __pthread_mutex_timedlock(m, 0);
10}
11
12weak_alias(__pthread_mutex_lock, pthread_mutex_lock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_setprioceiling.c deleted-6
......@@ -1,6 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_mutex_setprioceiling(pthread_mutex_t *restrict m, int ceiling, int *restrict old)
4{
5 return EINVAL;
6}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_timedlock.c deleted-96
......@@ -1,96 +0,0 @@
1#include "pthread_impl.h"
2
3#ifdef __wasilibc_unmodified_upstream
4#define IS32BIT(x) !((x)+0x80000000ULL>>32)
5#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
6
7static int __futex4(volatile void *addr, int op, int val, const struct timespec *to)
8{
9#ifdef SYS_futex_time64
10 time_t s = to ? to->tv_sec : 0;
11 long ns = to ? to->tv_nsec : 0;
12 int r = -ENOSYS;
13 if (SYS_futex == SYS_futex_time64 || !IS32BIT(s))
14 r = __syscall(SYS_futex_time64, addr, op, val,
15 to ? ((long long[]){s, ns}) : 0);
16 if (SYS_futex == SYS_futex_time64 || r!=-ENOSYS) return r;
17 to = to ? (void *)(long[]){CLAMP(s), ns} : 0;
18#endif
19 return __syscall(SYS_futex, addr, op, val, to);
20}
21
22static int pthread_mutex_timedlock_pi(pthread_mutex_t *restrict m, const struct timespec *restrict at)
23{
24 int type = m->_m_type;
25 int priv = (type & 128) ^ 128;
26 pthread_t self = __pthread_self();
27 int e;
28
29 if (!priv) self->robust_list.pending = &m->_m_next;
30
31 do e = -__futex4(&m->_m_lock, FUTEX_LOCK_PI|priv, 0, at);
32 while (e==EINTR);
33 if (e) self->robust_list.pending = 0;
34
35 switch (e) {
36 case 0:
37 /* Catch spurious success for non-robust mutexes. */
38 if (!(type&4) && ((m->_m_lock & 0x40000000) || m->_m_waiters)) {
39 a_store(&m->_m_waiters, -1);
40 __syscall(SYS_futex, &m->_m_lock, FUTEX_UNLOCK_PI|priv);
41 self->robust_list.pending = 0;
42 break;
43 }
44 /* Signal to trylock that we already have the lock. */
45 m->_m_count = -1;
46 return __pthread_mutex_trylock(m);
47 case ETIMEDOUT:
48 return e;
49 case EDEADLK:
50 if ((type&3) == PTHREAD_MUTEX_ERRORCHECK) return e;
51 }
52 do e = __timedwait(&(int){0}, 0, CLOCK_REALTIME, at, 1);
53 while (e != ETIMEDOUT);
54 return e;
55}
56#endif
57
58int __pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec *restrict at)
59{
60 if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL
61 && !a_cas(&m->_m_lock, 0, EBUSY))
62 return 0;
63
64 int type = m->_m_type;
65 int r, t, priv = (type & 128) ^ 128;
66
67 r = __pthread_mutex_trylock(m);
68 if (r != EBUSY) return r;
69
70#ifdef __wasilibc_unmodified_upstream
71 if (type&8) return pthread_mutex_timedlock_pi(m, at);
72#endif
73
74 int spins = 100;
75 while (spins-- && m->_m_lock && !m->_m_waiters) a_spin();
76
77 while ((r=__pthread_mutex_trylock(m)) == EBUSY) {
78 r = m->_m_lock;
79 int own = r & 0x3fffffff;
80 if (!own && (!r || (type&4)))
81 continue;
82 if ((type&3) == PTHREAD_MUTEX_ERRORCHECK
83 && own == __pthread_self()->tid)
84 return EDEADLK;
85
86 a_inc(&m->_m_waiters);
87 t = r | 0x80000000;
88 a_cas(&m->_m_lock, r, t);
89 r = __timedwait(&m->_m_lock, t, CLOCK_REALTIME, at, priv);
90 a_dec(&m->_m_waiters);
91 if (r && r != EINTR) break;
92 }
93 return r;
94}
95
96weak_alias(__pthread_mutex_timedlock, pthread_mutex_timedlock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_trylock.c deleted-78
......@@ -1,78 +0,0 @@
1#include "pthread_impl.h"
2
3int __pthread_mutex_trylock_owner(pthread_mutex_t *m)
4{
5 int old, own;
6 int type = m->_m_type;
7 pthread_t self = __pthread_self();
8 int tid = self->tid;
9
10 old = m->_m_lock;
11 own = old & 0x3fffffff;
12 if (own == tid) {
13 if ((type&8) && m->_m_count<0) {
14 old &= 0x40000000;
15 m->_m_count = 0;
16 goto success;
17 }
18 if ((type&3) == PTHREAD_MUTEX_RECURSIVE) {
19 if ((unsigned)m->_m_count >= INT_MAX) return EAGAIN;
20 m->_m_count++;
21 return 0;
22 }
23 }
24 if (own == 0x3fffffff) return ENOTRECOVERABLE;
25 if (own || (old && !(type & 4))) return EBUSY;
26
27 if (type & 128) {
28 if (!self->robust_list.off) {
29 self->robust_list.off = (char*)&m->_m_lock-(char *)&m->_m_next;
30#ifdef __wasilibc_unmodified_upstream
31 __syscall(SYS_set_robust_list, &self->robust_list, 3*sizeof(long));
32#endif
33 }
34 if (m->_m_waiters) tid |= 0x80000000;
35 self->robust_list.pending = &m->_m_next;
36 }
37 tid |= old & 0x40000000;
38
39 if (a_cas(&m->_m_lock, old, tid) != old) {
40 self->robust_list.pending = 0;
41 if ((type&12)==12 && m->_m_waiters) return ENOTRECOVERABLE;
42 return EBUSY;
43 }
44
45success:
46 if ((type&8) && m->_m_waiters) {
47 int priv = (type & 128) ^ 128;
48#ifdef __wasilibc_unmodified_upstream
49 __syscall(SYS_futex, &m->_m_lock, FUTEX_UNLOCK_PI|priv);
50#endif
51 self->robust_list.pending = 0;
52 return (type&4) ? ENOTRECOVERABLE : EBUSY;
53 }
54
55 volatile void *next = self->robust_list.head;
56 m->_m_next = next;
57 m->_m_prev = &self->robust_list.head;
58 if (next != &self->robust_list.head) *(volatile void *volatile *)
59 ((char *)next - sizeof(void *)) = &m->_m_next;
60 self->robust_list.head = &m->_m_next;
61 self->robust_list.pending = 0;
62
63 if (old) {
64 m->_m_count = 0;
65 return EOWNERDEAD;
66 }
67
68 return 0;
69}
70
71int __pthread_mutex_trylock(pthread_mutex_t *m)
72{
73 if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL)
74 return a_cas(&m->_m_lock, 0, EBUSY) & EBUSY;
75 return __pthread_mutex_trylock_owner(m);
76}
77
78weak_alias(__pthread_mutex_trylock, pthread_mutex_trylock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_unlock.c deleted-60
......@@ -1,60 +0,0 @@
1#include "pthread_impl.h"
2
3int __pthread_mutex_unlock(pthread_mutex_t *m)
4{
5 pthread_t self;
6 int waiters = m->_m_waiters;
7 int cont;
8 int type = m->_m_type & 15;
9 int priv = (m->_m_type & 128) ^ 128;
10 int new = 0;
11 int old;
12
13 if (type != PTHREAD_MUTEX_NORMAL) {
14 self = __pthread_self();
15 old = m->_m_lock;
16 int own = old & 0x3fffffff;
17 if (own != self->tid)
18 return EPERM;
19 if ((type&3) == PTHREAD_MUTEX_RECURSIVE && m->_m_count)
20 return m->_m_count--, 0;
21 if ((type&4) && (old&0x40000000))
22 new = 0x7fffffff;
23 if (!priv) {
24 self->robust_list.pending = &m->_m_next;
25#ifdef __wasilibc_unmodified_upstream
26 __vm_lock();
27#endif
28 }
29 volatile void *prev = m->_m_prev;
30 volatile void *next = m->_m_next;
31 *(volatile void *volatile *)prev = next;
32 if (next != &self->robust_list.head) *(volatile void *volatile *)
33 ((char *)next - sizeof(void *)) = prev;
34 }
35#ifdef __wasilibc_unmodified_upstream
36 if (type&8) {
37 if (old<0 || a_cas(&m->_m_lock, old, new)!=old) {
38 if (new) a_store(&m->_m_waiters, -1);
39 __syscall(SYS_futex, &m->_m_lock, FUTEX_UNLOCK_PI|priv);
40 }
41 cont = 0;
42 waiters = 0;
43 } else {
44 cont = a_swap(&m->_m_lock, new);
45 }
46#else
47 cont = a_swap(&m->_m_lock, new);
48#endif
49 if (type != PTHREAD_MUTEX_NORMAL && !priv) {
50 self->robust_list.pending = 0;
51#ifdef __wasilibc_unmodified_upstream
52 __vm_unlock();
53#endif
54 }
55 if (waiters || cont<0)
56 __wake(&m->_m_lock, 1, priv);
57 return 0;
58}
59
60weak_alias(__pthread_mutex_unlock, pthread_mutex_unlock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_destroy.c deleted-6
......@@ -1,6 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_mutexattr_destroy(pthread_mutexattr_t *a)
4{
5 return 0;
6}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_init.c deleted-7
......@@ -1,7 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_mutexattr_init(pthread_mutexattr_t *a)
4{
5 *a = (pthread_mutexattr_t){0};
6 return 0;
7}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setprotocol.c deleted-32
......@@ -1,32 +0,0 @@
1#include "pthread_impl.h"
2#include "syscall.h"
3
4static volatile int check_pi_result = -1;
5
6int pthread_mutexattr_setprotocol(pthread_mutexattr_t *a, int protocol)
7{
8 int r;
9 switch (protocol) {
10 case PTHREAD_PRIO_NONE:
11 a->__attr &= ~8;
12 return 0;
13 case PTHREAD_PRIO_INHERIT:
14#ifdef __wasilibc_unmodified_upstream
15 r = check_pi_result;
16 if (r < 0) {
17 volatile int lk = 0;
18 r = -__syscall(SYS_futex, &lk, FUTEX_LOCK_PI, 0, 0);
19 a_store(&check_pi_result, r);
20 }
21 if (r) return r;
22 a->__attr |= 8;
23 return 0;
24#else
25 return ENOTSUP;
26#endif
27 case PTHREAD_PRIO_PROTECT:
28 return ENOTSUP;
29 default:
30 return EINVAL;
31 }
32}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setpshared.c deleted-9
......@@ -1,9 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_mutexattr_setpshared(pthread_mutexattr_t *a, int pshared)
4{
5 if (pshared > 1U) return EINVAL;
6 a->__attr &= ~128U;
7 a->__attr |= pshared<<7;
8 return 0;
9}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setrobust.c deleted-27
......@@ -1,27 +0,0 @@
1#include "pthread_impl.h"
2#include "syscall.h"
3
4static volatile int check_robust_result = -1;
5
6int pthread_mutexattr_setrobust(pthread_mutexattr_t *a, int robust)
7{
8#ifdef __wasilibc_unmodified_upstream
9 if (robust > 1U) return EINVAL;
10 if (robust) {
11 int r = check_robust_result;
12 if (r < 0) {
13 void *p;
14 size_t l;
15 r = -__syscall(SYS_get_robust_list, 0, &p, &l);
16 a_store(&check_robust_result, r);
17 }
18 if (r) return r;
19 a->__attr |= 4;
20 return 0;
21 }
22 a->__attr &= ~4;
23 return 0;
24#else
25 return EINVAL;
26#endif
27}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_settype.c deleted-8
......@@ -1,8 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_mutexattr_settype(pthread_mutexattr_t *a, int type)
4{
5 if ((unsigned)type > 2) return EINVAL;
6 a->__attr = (a->__attr & ~3) | type;
7 return 0;
8}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_once.c deleted-50
......@@ -1,50 +0,0 @@
1#include "pthread_impl.h"
2
3static void undo(void *control)
4{
5 /* Wake all waiters, since the waiter status is lost when
6 * resetting control to the initial state. */
7 if (a_swap(control, 0) == 3)
8 __wake(control, -1, 1);
9}
10
11hidden int __pthread_once_full(pthread_once_t *control, void (*init)(void))
12{
13 /* Try to enter initializing state. Four possibilities:
14 * 0 - we're the first or the other cancelled; run init
15 * 1 - another thread is running init; wait
16 * 2 - another thread finished running init; just return
17 * 3 - another thread is running init, waiters present; wait */
18
19 for (;;) switch (a_cas(control, 0, 1)) {
20 case 0:
21 pthread_cleanup_push(undo, control);
22 init();
23 pthread_cleanup_pop(0);
24
25 if (a_swap(control, 2) == 3)
26 __wake(control, -1, 1);
27 return 0;
28 case 1:
29 /* If this fails, so will __wait. */
30 a_cas(control, 1, 3);
31 case 3:
32 __wait(control, 0, 3, 1);
33 continue;
34 case 2:
35 return 0;
36 }
37}
38
39int __pthread_once(pthread_once_t *control, void (*init)(void))
40{
41 /* Return immediately if init finished before, but ensure that
42 * effects of the init routine are visible to the caller. */
43 if (*(volatile int *)control == 2) {
44 a_barrier();
45 return 0;
46 }
47 return __pthread_once_full(control, init);
48}
49
50weak_alias(__pthread_once, pthread_once);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_destroy.c deleted-6
......@@ -1,6 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_rwlock_destroy(pthread_rwlock_t *rw)
4{
5 return 0;
6}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_init.c deleted-8
......@@ -1,8 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_rwlock_init(pthread_rwlock_t *restrict rw, const pthread_rwlockattr_t *restrict a)
4{
5 *rw = (pthread_rwlock_t){0};
6 if (a) rw->_rw_shared = a->__attr[0]*128;
7 return 0;
8}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_rdlock.c deleted-8
......@@ -1,8 +0,0 @@
1#include "pthread_impl.h"
2
3int __pthread_rwlock_rdlock(pthread_rwlock_t *rw)
4{
5 return __pthread_rwlock_timedrdlock(rw, 0);
6}
7
8weak_alias(__pthread_rwlock_rdlock, pthread_rwlock_rdlock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_timedrdlock.c deleted-25
......@@ -1,25 +0,0 @@
1#include "pthread_impl.h"
2
3int __pthread_rwlock_timedrdlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at)
4{
5 int r, t;
6
7 r = pthread_rwlock_tryrdlock(rw);
8 if (r != EBUSY) return r;
9
10 int spins = 100;
11 while (spins-- && rw->_rw_lock && !rw->_rw_waiters) a_spin();
12
13 while ((r=__pthread_rwlock_tryrdlock(rw))==EBUSY) {
14 if (!(r=rw->_rw_lock) || (r&0x7fffffff)!=0x7fffffff) continue;
15 t = r | 0x80000000;
16 a_inc(&rw->_rw_waiters);
17 a_cas(&rw->_rw_lock, r, t);
18 r = __timedwait(&rw->_rw_lock, t, CLOCK_REALTIME, at, rw->_rw_shared^128);
19 a_dec(&rw->_rw_waiters);
20 if (r && r != EINTR) return r;
21 }
22 return r;
23}
24
25weak_alias(__pthread_rwlock_timedrdlock, pthread_rwlock_timedrdlock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_timedwrlock.c deleted-25
......@@ -1,25 +0,0 @@
1#include "pthread_impl.h"
2
3int __pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at)
4{
5 int r, t;
6
7 r = pthread_rwlock_trywrlock(rw);
8 if (r != EBUSY) return r;
9
10 int spins = 100;
11 while (spins-- && rw->_rw_lock && !rw->_rw_waiters) a_spin();
12
13 while ((r=__pthread_rwlock_trywrlock(rw))==EBUSY) {
14 if (!(r=rw->_rw_lock)) continue;
15 t = r | 0x80000000;
16 a_inc(&rw->_rw_waiters);
17 a_cas(&rw->_rw_lock, r, t);
18 r = __timedwait(&rw->_rw_lock, t, CLOCK_REALTIME, at, rw->_rw_shared^128);
19 a_dec(&rw->_rw_waiters);
20 if (r && r != EINTR) return r;
21 }
22 return r;
23}
24
25weak_alias(__pthread_rwlock_timedwrlock, pthread_rwlock_timedwrlock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_tryrdlock.c deleted-15
......@@ -1,15 +0,0 @@
1#include "pthread_impl.h"
2
3int __pthread_rwlock_tryrdlock(pthread_rwlock_t *rw)
4{
5 int val, cnt;
6 do {
7 val = rw->_rw_lock;
8 cnt = val & 0x7fffffff;
9 if (cnt == 0x7fffffff) return EBUSY;
10 if (cnt == 0x7ffffffe) return EAGAIN;
11 } while (a_cas(&rw->_rw_lock, val, val+1) != val);
12 return 0;
13}
14
15weak_alias(__pthread_rwlock_tryrdlock, pthread_rwlock_tryrdlock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_trywrlock.c deleted-9
......@@ -1,9 +0,0 @@
1#include "pthread_impl.h"
2
3int __pthread_rwlock_trywrlock(pthread_rwlock_t *rw)
4{
5 if (a_cas(&rw->_rw_lock, 0, 0x7fffffff)) return EBUSY;
6 return 0;
7}
8
9weak_alias(__pthread_rwlock_trywrlock, pthread_rwlock_trywrlock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_unlock.c deleted-20
......@@ -1,20 +0,0 @@
1#include "pthread_impl.h"
2
3int __pthread_rwlock_unlock(pthread_rwlock_t *rw)
4{
5 int val, cnt, waiters, new, priv = rw->_rw_shared^128;
6
7 do {
8 val = rw->_rw_lock;
9 cnt = val & 0x7fffffff;
10 waiters = rw->_rw_waiters;
11 new = (cnt == 0x7fffffff || cnt == 1) ? 0 : val-1;
12 } while (a_cas(&rw->_rw_lock, val, new) != val);
13
14 if (!new && (waiters || val<0))
15 __wake(&rw->_rw_lock, cnt, priv);
16
17 return 0;
18}
19
20weak_alias(__pthread_rwlock_unlock, pthread_rwlock_unlock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_wrlock.c deleted-8
......@@ -1,8 +0,0 @@
1#include "pthread_impl.h"
2
3int __pthread_rwlock_wrlock(pthread_rwlock_t *rw)
4{
5 return __pthread_rwlock_timedwrlock(rw, 0);
6}
7
8weak_alias(__pthread_rwlock_wrlock, pthread_rwlock_wrlock);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlockattr_destroy.c deleted-6
......@@ -1,6 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_rwlockattr_destroy(pthread_rwlockattr_t *a)
4{
5 return 0;
6}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlockattr_init.c deleted-7
......@@ -1,7 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_rwlockattr_init(pthread_rwlockattr_t *a)
4{
5 *a = (pthread_rwlockattr_t){0};
6 return 0;
7}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlockattr_setpshared.c deleted-8
......@@ -1,8 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *a, int pshared)
4{
5 if (pshared > 1U) return EINVAL;
6 a->__attr[0] = pshared;
7 return 0;
8}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_self.c deleted-15
......@@ -1,15 +0,0 @@
1#include "pthread_impl.h"
2#include <threads.h>
3
4#if !defined(__wasilibc_unmodified_upstream) && defined(__wasm__) && \
5 defined(_REENTRANT)
6_Thread_local struct pthread __wasilibc_pthread_self;
7#endif
8
9static pthread_t __pthread_self_internal()
10{
11 return __pthread_self();
12}
13
14weak_alias(__pthread_self_internal, pthread_self);
15weak_alias(__pthread_self_internal, thrd_current);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setattr_default_np.c deleted-37
......@@ -1,37 +0,0 @@
1#define _GNU_SOURCE
2#include "pthread_impl.h"
3#include <string.h>
4
5#define MIN(a,b) ((a)<(b) ? (a) : (b))
6#define MAX(a,b) ((a)>(b) ? (a) : (b))
7
8int pthread_setattr_default_np(const pthread_attr_t *attrp)
9{
10 /* Reject anything in the attr object other than stack/guard size. */
11 pthread_attr_t tmp = *attrp, zero = { 0 };
12 tmp._a_stacksize = 0;
13 tmp._a_guardsize = 0;
14 if (memcmp(&tmp, &zero, sizeof tmp))
15 return EINVAL;
16
17 unsigned stack = MIN(attrp->_a_stacksize, DEFAULT_STACK_MAX);
18 unsigned guard = MIN(attrp->_a_guardsize, DEFAULT_GUARD_MAX);
19
20 __inhibit_ptc();
21 __default_stacksize = MAX(__default_stacksize, stack);
22 __default_guardsize = MAX(__default_guardsize, guard);
23 __release_ptc();
24
25 return 0;
26}
27
28int pthread_getattr_default_np(pthread_attr_t *attrp)
29{
30 __acquire_ptc();
31 *attrp = (pthread_attr_t) {
32 ._a_stacksize = __default_stacksize,
33 ._a_guardsize = __default_guardsize,
34 };
35 __release_ptc();
36 return 0;
37}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setcancelstate.c deleted-14
......@@ -1,14 +0,0 @@
1#include "pthread_impl.h"
2
3int __pthread_setcancelstate(int new, int *old)
4{
5#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
6 if (new > 2U) return EINVAL;
7 struct pthread *self = __pthread_self();
8 if (old) *old = self->canceldisable;
9 self->canceldisable = new;
10#endif
11 return 0;
12}
13
14weak_alias(__pthread_setcancelstate, pthread_setcancelstate);
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setcanceltype.c deleted-11
......@@ -1,11 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_setcanceltype(int new, int *old)
4{
5 struct pthread *self = __pthread_self();
6 if (new > 1U) return EINVAL;
7 if (old) *old = self->cancelasync;
8 self->cancelasync = new;
9 if (new) pthread_testcancel();
10 return 0;
11}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setconcurrency.c deleted-9
......@@ -1,9 +0,0 @@
1#include <pthread.h>
2#include <errno.h>
3
4int pthread_setconcurrency(int val)
5{
6 if (val < 0) return EINVAL;
7 if (val > 0) return EAGAIN;
8 return 0;
9}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setname_np.c deleted-26
......@@ -1,26 +0,0 @@
1#define _GNU_SOURCE
2#include <fcntl.h>
3#include <string.h>
4#include <unistd.h>
5#include <sys/prctl.h>
6
7#include "pthread_impl.h"
8
9int pthread_setname_np(pthread_t thread, const char *name)
10{
11 int fd, cs, status = 0;
12 char f[sizeof "/proc/self/task//comm" + 3*sizeof(int)];
13 size_t len;
14
15 if ((len = strnlen(name, 16)) > 15) return ERANGE;
16
17 if (thread == pthread_self())
18 return prctl(PR_SET_NAME, (unsigned long)name, 0UL, 0UL, 0UL) ? errno : 0;
19
20 snprintf(f, sizeof f, "/proc/self/task/%d/comm", thread->tid);
21 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
22 if ((fd = open(f, O_WRONLY|O_CLOEXEC)) < 0 || write(fd, name, len) < 0) status = errno;
23 if (fd >= 0) close(fd);
24 pthread_setcancelstate(cs, 0);
25 return status;
26}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setschedparam.c deleted-14
......@@ -1,14 +0,0 @@
1#include "pthread_impl.h"
2#include "lock.h"
3
4int pthread_setschedparam(pthread_t t, int policy, const struct sched_param *param)
5{
6 int r;
7 sigset_t set;
8 __block_app_sigs(&set);
9 LOCK(t->killlock);
10 r = !t->tid ? ESRCH : -__syscall(SYS_sched_setscheduler, t->tid, policy, param);
11 UNLOCK(t->killlock);
12 __restore_sigs(&set);
13 return r;
14}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setschedprio.c deleted-14
......@@ -1,14 +0,0 @@
1#include "pthread_impl.h"
2#include "lock.h"
3
4int pthread_setschedprio(pthread_t t, int prio)
5{
6 int r;
7 sigset_t set;
8 __block_app_sigs(&set);
9 LOCK(t->killlock);
10 r = !t->tid ? ESRCH : -__syscall(SYS_sched_setparam, t->tid, &prio);
11 UNLOCK(t->killlock);
12 __restore_sigs(&set);
13 return r;
14}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setspecific.c deleted-12
......@@ -1,12 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_setspecific(pthread_key_t k, const void *x)
4{
5 struct pthread *self = __pthread_self();
6 /* Avoid unnecessary COW */
7 if (self->tsd[k] != x) {
8 self->tsd[k] = (void *)x;
9 self->tsd_used = 1;
10 }
11 return 0;
12}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_sigmask.c deleted-19
......@@ -1,19 +0,0 @@
1#include <signal.h>
2#include <errno.h>
3#include "syscall.h"
4
5int pthread_sigmask(int how, const sigset_t *restrict set, sigset_t *restrict old)
6{
7 int ret;
8 if (set && (unsigned)how - SIG_BLOCK > 2U) return EINVAL;
9 ret = -__syscall(SYS_rt_sigprocmask, how, set, old, _NSIG/8);
10 if (!ret && old) {
11 if (sizeof old->__bits[0] == 8) {
12 old->__bits[0] &= ~0x380000000ULL;
13 } else {
14 old->__bits[0] &= ~0x80000000UL;
15 old->__bits[1] &= ~0x3UL;
16 }
17 }
18 return ret;
19}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_spin_destroy.c deleted-6
......@@ -1,6 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_spin_destroy(pthread_spinlock_t *s)
4{
5 return 0;
6}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_spin_init.c deleted-6
......@@ -1,6 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_spin_init(pthread_spinlock_t *s, int shared)
4{
5 return *s = 0;
6}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_spin_lock.c deleted-8
......@@ -1,8 +0,0 @@
1#include "pthread_impl.h"
2#include <errno.h>
3
4int pthread_spin_lock(pthread_spinlock_t *s)
5{
6 while (*(volatile int *)s || a_cas(s, 0, EBUSY)) a_spin();
7 return 0;
8}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_spin_trylock.c deleted-7
......@@ -1,7 +0,0 @@
1#include "pthread_impl.h"
2#include <errno.h>
3
4int pthread_spin_trylock(pthread_spinlock_t *s)
5{
6 return a_cas(s, 0, EBUSY);
7}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_spin_unlock.c deleted-7
......@@ -1,7 +0,0 @@
1#include "pthread_impl.h"
2
3int pthread_spin_unlock(pthread_spinlock_t *s)
4{
5 a_store(s, 0);
6 return 0;
7}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_testcancel.c deleted-14
......@@ -1,14 +0,0 @@
1#include "pthread_impl.h"
2
3static void dummy()
4{
5}
6
7weak_alias(dummy, __testcancel);
8
9void __pthread_testcancel()
10{
11 __testcancel();
12}
13
14weak_alias(__pthread_testcancel, pthread_testcancel);
lib/libc/wasi/libc-top-half/musl/src/thread/riscv64/__set_thread_area.s deleted-6
......@@ -1,6 +0,0 @@
1.global __set_thread_area
2.type __set_thread_area, %function
3__set_thread_area:
4 mv tp, a0
5 li a0, 0
6 ret
lib/libc/wasi/libc-top-half/musl/src/thread/riscv64/__unmapself.s deleted-7
......@@ -1,7 +0,0 @@
1.global __unmapself
2.type __unmapself, %function
3__unmapself:
4 li a7, 215 # SYS_munmap
5 ecall
6 li a7, 93 # SYS_exit
7 ecall
lib/libc/wasi/libc-top-half/musl/src/thread/riscv64/clone.s deleted-34
......@@ -1,34 +0,0 @@
1# __clone(func, stack, flags, arg, ptid, tls, ctid)
2# a0, a1, a2, a3, a4, a5, a6
3
4# syscall(SYS_clone, flags, stack, ptid, tls, ctid)
5# a7 a0, a1, a2, a3, a4
6
7.global __clone
8.type __clone, %function
9__clone:
10 # Save func and arg to stack
11 addi a1, a1, -16
12 sd a0, 0(a1)
13 sd a3, 8(a1)
14
15 # Call SYS_clone
16 mv a0, a2
17 mv a2, a4
18 mv a3, a5
19 mv a4, a6
20 li a7, 220 # SYS_clone
21 ecall
22
23 beqz a0, 1f
24 # Parent
25 ret
26
27 # Child
281: ld a1, 0(sp)
29 ld a0, 8(sp)
30 jalr a1
31
32 # Exit
33 li a7, 93 # SYS_exit
34 ecall
lib/libc/wasi/libc-top-half/musl/src/thread/riscv64/syscall_cp.s deleted-29
......@@ -1,29 +0,0 @@
1.global __cp_begin
2.hidden __cp_begin
3.global __cp_end
4.hidden __cp_end
5.global __cp_cancel
6.hidden __cp_cancel
7.hidden __cancel
8.global __syscall_cp_asm
9.hidden __syscall_cp_asm
10.type __syscall_cp_asm, %function
11__syscall_cp_asm:
12__cp_begin:
13 lw t0, 0(a0)
14 bnez t0, __cp_cancel
15
16 mv t0, a1
17 mv a0, a2
18 mv a1, a3
19 mv a2, a4
20 mv a3, a5
21 mv a4, a6
22 mv a5, a7
23 ld a6, 0(sp)
24 mv a7, t0
25 ecall
26__cp_end:
27 ret
28__cp_cancel:
29 tail __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/s390x/__set_thread_area.s deleted-10
......@@ -1,10 +0,0 @@
1.text
2.global __set_thread_area
3.hidden __set_thread_area
4.type __set_thread_area, %function
5__set_thread_area:
6 sar %a1, %r2
7 srlg %r2, %r2, 32
8 sar %a0, %r2
9 lghi %r2, 0
10 br %r14
lib/libc/wasi/libc-top-half/musl/src/thread/s390x/__tls_get_offset.s deleted-17
......@@ -1,17 +0,0 @@
1 .global __tls_get_offset
2 .type __tls_get_offset,%function
3__tls_get_offset:
4 stmg %r14, %r15, 112(%r15)
5 aghi %r15, -160
6
7 la %r2, 0(%r2, %r12)
8 brasl %r14, __tls_get_addr
9
10 ear %r1, %a0
11 sllg %r1, %r1, 32
12 ear %r1, %a1
13
14 sgr %r2, %r1
15
16 lmg %r14, %r15, 272(%r15)
17 br %r14
lib/libc/wasi/libc-top-half/musl/src/thread/s390x/__unmapself.s deleted-6
......@@ -1,6 +0,0 @@
1.text
2.global __unmapself
3.type __unmapself, @function
4__unmapself:
5 svc 91 # SYS_munmap
6 svc 1 # SYS_exit
lib/libc/wasi/libc-top-half/musl/src/thread/s390x/clone.s deleted-54
......@@ -1,54 +0,0 @@
1.text
2.global __clone
3.hidden __clone
4.type __clone, %function
5__clone:
6 # int clone(
7 # fn, a = r2
8 # stack, b = r3
9 # flags, c = r4
10 # arg, d = r5
11 # ptid, e = r6
12 # tls, f = *(r15+160)
13 # ctid) g = *(r15+168)
14 #
15 # pseudo C code:
16 # tid = syscall(SYS_clone,b,c,e,g,f);
17 # if (!tid) syscall(SYS_exit, a(d));
18 # return tid;
19
20 # preserve call-saved register used as syscall arg
21 stg %r6, 48(%r15)
22
23 # create initial stack frame for new thread
24 nill %r3, 0xfff8
25 aghi %r3, -160
26 lghi %r0, 0
27 stg %r0, 0(%r3)
28
29 # save fn and arg to child stack
30 stg %r2, 8(%r3)
31 stg %r5, 16(%r3)
32
33 # shuffle args into correct registers and call SYS_clone
34 lgr %r2, %r3
35 lgr %r3, %r4
36 lgr %r4, %r6
37 lg %r5, 168(%r15)
38 lg %r6, 160(%r15)
39 svc 120
40
41 # restore call-saved register
42 lg %r6, 48(%r15)
43
44 # if error or if we're the parent, return
45 ltgr %r2, %r2
46 bnzr %r14
47
48 # we're the child. call fn(arg)
49 lg %r1, 8(%r15)
50 lg %r2, 16(%r15)
51 basr %r14, %r1
52
53 # call SYS_exit. exit code is already in r2 from fn return value
54 svc 1
lib/libc/wasi/libc-top-half/musl/src/thread/s390x/syscall_cp.s deleted-34
......@@ -1,34 +0,0 @@
1 .global __cp_begin
2 .hidden __cp_begin
3 .global __cp_end
4 .hidden __cp_end
5 .global __cp_cancel
6 .hidden __cp_cancel
7 .hidden __cancel
8 .global __syscall_cp_asm
9 .hidden __syscall_cp_asm
10 .text
11 .type __syscall_cp_asm,%function
12__syscall_cp_asm:
13__cp_begin:
14 icm %r2, 15, 0(%r2)
15 jne __cp_cancel
16
17 stg %r6, 48(%r15)
18 stg %r7, 56(%r15)
19 lgr %r1, %r3
20 lgr %r2, %r4
21 lgr %r3, %r5
22 lgr %r4, %r6
23 lg %r5, 160(%r15)
24 lg %r6, 168(%r15)
25 lg %r7, 176(%r15)
26 svc 0
27
28__cp_end:
29 lg %r7, 56(%r15)
30 lg %r6, 48(%r15)
31 br %r14
32
33__cp_cancel:
34 jg __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/sem_destroy.c deleted-6
......@@ -1,6 +0,0 @@
1#include <semaphore.h>
2
3int sem_destroy(sem_t *sem)
4{
5 return 0;
6}
lib/libc/wasi/libc-top-half/musl/src/thread/sem_getvalue.c deleted-8
......@@ -1,8 +0,0 @@
1#include <semaphore.h>
2
3int sem_getvalue(sem_t *restrict sem, int *restrict valp)
4{
5 int val = sem->__val[0];
6 *valp = val < 0 ? 0 : val;
7 return 0;
8}
lib/libc/wasi/libc-top-half/musl/src/thread/sem_init.c deleted-15
......@@ -1,15 +0,0 @@
1#include <semaphore.h>
2#include <limits.h>
3#include <errno.h>
4
5int sem_init(sem_t *sem, int pshared, unsigned value)
6{
7 if (value > SEM_VALUE_MAX) {
8 errno = EINVAL;
9 return -1;
10 }
11 sem->__val[0] = value;
12 sem->__val[1] = 0;
13 sem->__val[2] = pshared ? 0 : 128;
14 return 0;
15}
lib/libc/wasi/libc-top-half/musl/src/thread/sem_open.c deleted-182
......@@ -1,182 +0,0 @@
1#include <semaphore.h>
2#include <sys/mman.h>
3#include <limits.h>
4#include <fcntl.h>
5#include <unistd.h>
6#include <string.h>
7#include <stdarg.h>
8#include <errno.h>
9#include <time.h>
10#include <stdio.h>
11#include <sys/stat.h>
12#include <stdlib.h>
13#include <pthread.h>
14#include "lock.h"
15#include "fork_impl.h"
16
17#define malloc __libc_malloc
18#define calloc __libc_calloc
19#define realloc undef
20#define free undef
21
22static struct {
23 ino_t ino;
24 sem_t *sem;
25 int refcnt;
26} *semtab;
27static volatile int lock[1];
28volatile int *const __sem_open_lockptr = lock;
29
30#define FLAGS (O_RDWR|O_NOFOLLOW|O_CLOEXEC|O_NONBLOCK)
31
32sem_t *sem_open(const char *name, int flags, ...)
33{
34 va_list ap;
35 mode_t mode;
36 unsigned value;
37 int fd, i, e, slot, first=1, cnt, cs;
38 sem_t newsem;
39 void *map;
40 char tmp[64];
41 struct timespec ts;
42 struct stat st;
43 char buf[NAME_MAX+10];
44
45 if (!(name = __shm_mapname(name, buf)))
46 return SEM_FAILED;
47
48 LOCK(lock);
49 /* Allocate table if we don't have one yet */
50 if (!semtab && !(semtab = calloc(sizeof *semtab, SEM_NSEMS_MAX))) {
51 UNLOCK(lock);
52 return SEM_FAILED;
53 }
54
55 /* Reserve a slot in case this semaphore is not mapped yet;
56 * this is necessary because there is no way to handle
57 * failures after creation of the file. */
58 slot = -1;
59 for (cnt=i=0; i<SEM_NSEMS_MAX; i++) {
60 cnt += semtab[i].refcnt;
61 if (!semtab[i].sem && slot < 0) slot = i;
62 }
63 /* Avoid possibility of overflow later */
64 if (cnt == INT_MAX || slot < 0) {
65 errno = EMFILE;
66 UNLOCK(lock);
67 return SEM_FAILED;
68 }
69 /* Dummy pointer to make a reservation */
70 semtab[slot].sem = (sem_t *)-1;
71 UNLOCK(lock);
72
73 flags &= (O_CREAT|O_EXCL);
74
75 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
76
77 /* Early failure check for exclusive open; otherwise the case
78 * where the semaphore already exists is expensive. */
79 if (flags == (O_CREAT|O_EXCL) && access(name, F_OK) == 0) {
80 errno = EEXIST;
81 goto fail;
82 }
83
84 for (;;) {
85 /* If exclusive mode is not requested, try opening an
86 * existing file first and fall back to creation. */
87 if (flags != (O_CREAT|O_EXCL)) {
88 fd = open(name, FLAGS);
89 if (fd >= 0) {
90 if (fstat(fd, &st) < 0 ||
91 (map = mmap(0, sizeof(sem_t), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) {
92 close(fd);
93 goto fail;
94 }
95 close(fd);
96 break;
97 }
98 if (errno != ENOENT)
99 goto fail;
100 }
101 if (!(flags & O_CREAT))
102 goto fail;
103 if (first) {
104 first = 0;
105 va_start(ap, flags);
106 mode = va_arg(ap, mode_t) & 0666;
107 value = va_arg(ap, unsigned);
108 va_end(ap);
109 if (value > SEM_VALUE_MAX) {
110 errno = EINVAL;
111 goto fail;
112 }
113 sem_init(&newsem, 1, value);
114 }
115 /* Create a temp file with the new semaphore contents
116 * and attempt to atomically link it as the new name */
117 clock_gettime(CLOCK_REALTIME, &ts);
118 snprintf(tmp, sizeof(tmp), "/dev/shm/tmp-%d", (int)ts.tv_nsec);
119 fd = open(tmp, O_CREAT|O_EXCL|FLAGS, mode);
120 if (fd < 0) {
121 if (errno == EEXIST) continue;
122 goto fail;
123 }
124 if (write(fd, &newsem, sizeof newsem) != sizeof newsem || fstat(fd, &st) < 0 ||
125 (map = mmap(0, sizeof(sem_t), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) {
126 close(fd);
127 unlink(tmp);
128 goto fail;
129 }
130 close(fd);
131 e = link(tmp, name) ? errno : 0;
132 unlink(tmp);
133 if (!e) break;
134 munmap(map, sizeof(sem_t));
135 /* Failure is only fatal when doing an exclusive open;
136 * otherwise, next iteration will try to open the
137 * existing file. */
138 if (e != EEXIST || flags == (O_CREAT|O_EXCL))
139 goto fail;
140 }
141
142 /* See if the newly mapped semaphore is already mapped. If
143 * so, unmap the new mapping and use the existing one. Otherwise,
144 * add it to the table of mapped semaphores. */
145 LOCK(lock);
146 for (i=0; i<SEM_NSEMS_MAX && semtab[i].ino != st.st_ino; i++);
147 if (i<SEM_NSEMS_MAX) {
148 munmap(map, sizeof(sem_t));
149 semtab[slot].sem = 0;
150 slot = i;
151 map = semtab[i].sem;
152 }
153 semtab[slot].refcnt++;
154 semtab[slot].sem = map;
155 semtab[slot].ino = st.st_ino;
156 UNLOCK(lock);
157 pthread_setcancelstate(cs, 0);
158 return map;
159
160fail:
161 pthread_setcancelstate(cs, 0);
162 LOCK(lock);
163 semtab[slot].sem = 0;
164 UNLOCK(lock);
165 return SEM_FAILED;
166}
167
168int sem_close(sem_t *sem)
169{
170 int i;
171 LOCK(lock);
172 for (i=0; i<SEM_NSEMS_MAX && semtab[i].sem != sem; i++);
173 if (--semtab[i].refcnt) {
174 UNLOCK(lock);
175 return 0;
176 }
177 semtab[i].sem = 0;
178 semtab[i].ino = 0;
179 UNLOCK(lock);
180 munmap(sem, sizeof *sem);
181 return 0;
182}
lib/libc/wasi/libc-top-half/musl/src/thread/sem_post.c deleted-17
......@@ -1,17 +0,0 @@
1#include <semaphore.h>
2#include "pthread_impl.h"
3
4int sem_post(sem_t *sem)
5{
6 int val, waiters, priv = sem->__val[2];
7 do {
8 val = sem->__val[0];
9 waiters = sem->__val[1];
10 if (val == SEM_VALUE_MAX) {
11 errno = EOVERFLOW;
12 return -1;
13 }
14 } while (a_cas(sem->__val, val, val+1+(val<0)) != val);
15 if (val<0 || waiters) __wake(sem->__val, 1, priv);
16 return 0;
17}
lib/libc/wasi/libc-top-half/musl/src/thread/sem_timedwait.c deleted-31
......@@ -1,31 +0,0 @@
1#include <semaphore.h>
2#include "pthread_impl.h"
3
4static void cleanup(void *p)
5{
6 a_dec(p);
7}
8
9int sem_timedwait(sem_t *restrict sem, const struct timespec *restrict at)
10{
11 pthread_testcancel();
12
13 if (!sem_trywait(sem)) return 0;
14
15 int spins = 100;
16 while (spins-- && sem->__val[0] <= 0 && !sem->__val[1]) a_spin();
17
18 while (sem_trywait(sem)) {
19 int r;
20 a_inc(sem->__val+1);
21 a_cas(sem->__val, 0, -1);
22 pthread_cleanup_push(cleanup, (void *)(sem->__val+1));
23 r = __timedwait_cp(sem->__val, -1, CLOCK_REALTIME, at, sem->__val[2]);
24 pthread_cleanup_pop(1);
25 if (r) {
26 errno = r;
27 return -1;
28 }
29 }
30 return 0;
31}
lib/libc/wasi/libc-top-half/musl/src/thread/sem_trywait.c deleted-13
......@@ -1,13 +0,0 @@
1#include <semaphore.h>
2#include "pthread_impl.h"
3
4int sem_trywait(sem_t *sem)
5{
6 int val;
7 while ((val=sem->__val[0]) > 0) {
8 int new = val-1-(val==1 && sem->__val[1]);
9 if (a_cas(sem->__val, val, new)==val) return 0;
10 }
11 errno = EAGAIN;
12 return -1;
13}
lib/libc/wasi/libc-top-half/musl/src/thread/sem_unlink.c deleted-7
......@@ -1,7 +0,0 @@
1#include <semaphore.h>
2#include <sys/mman.h>
3
4int sem_unlink(const char *name)
5{
6 return shm_unlink(name);
7}
lib/libc/wasi/libc-top-half/musl/src/thread/sem_wait.c deleted-6
......@@ -1,6 +0,0 @@
1#include <semaphore.h>
2
3int sem_wait(sem_t *sem)
4{
5 return sem_timedwait(sem, 0);
6}
lib/libc/wasi/libc-top-half/musl/src/thread/sh/__set_thread_area.c deleted-37
......@@ -1,37 +0,0 @@
1#include "pthread_impl.h"
2#include "libc.h"
3#include <elf.h>
4
5/* Also perform sh-specific init */
6
7#define CPU_HAS_LLSC 0x0040
8#define CPU_HAS_CAS_L 0x0400
9
10extern hidden const char __sh_cas_gusa[], __sh_cas_llsc[], __sh_cas_imask[], __sh_cas_cas_l[];
11
12hidden const void *__sh_cas_ptr;
13
14hidden unsigned __sh_nommu;
15
16int __set_thread_area(void *p)
17{
18 size_t *aux;
19 __asm__ __volatile__ ( "ldc %0, gbr" : : "r"(p) : "memory" );
20#ifndef __SH4A__
21 __sh_cas_ptr = __sh_cas_gusa;
22#if !defined(__SH3__) && !defined(__SH4__)
23 for (aux=libc.auxv; *aux; aux+=2) {
24 if (*aux != AT_PLATFORM) continue;
25 const char *s = (void *)aux[1];
26 if (s[0]!='s' || s[1]!='h' || s[2]!='2' || s[3]-'0'<10u) break;
27 __sh_cas_ptr = __sh_cas_imask;
28 __sh_nommu = 1;
29 }
30#endif
31 if (__hwcap & CPU_HAS_CAS_L)
32 __sh_cas_ptr = __sh_cas_cas_l;
33 else if (__hwcap & CPU_HAS_LLSC)
34 __sh_cas_ptr = __sh_cas_llsc;
35#endif
36 return 0;
37}
lib/libc/wasi/libc-top-half/musl/src/thread/sh/__unmapself.c deleted-24
......@@ -1,24 +0,0 @@
1#include "pthread_impl.h"
2
3hidden void __unmapself_sh_mmu(void *, size_t);
4hidden void __unmapself_sh_nommu(void *, size_t);
5
6#if !defined(__SH3__) && !defined(__SH4__)
7#define __unmapself __unmapself_sh_nommu
8#include "dynlink.h"
9#undef CRTJMP
10#define CRTJMP(pc,sp) __asm__ __volatile__( \
11 "mov.l @%0+,r0 ; mov.l @%0,r12 ; jmp @r0 ; mov %1,r15" \
12 : : "r"(pc), "r"(sp) : "r0", "memory" )
13#include "../__unmapself.c"
14#undef __unmapself
15extern hidden unsigned __sh_nommu;
16#else
17#define __sh_nommu 0
18#endif
19
20void __unmapself(void *base, size_t size)
21{
22 if (__sh_nommu) __unmapself_sh_nommu(base, size);
23 else __unmapself_sh_mmu(base, size);
24}
lib/libc/wasi/libc-top-half/musl/src/thread/sh/__unmapself_mmu.s deleted-23
......@@ -1,23 +0,0 @@
1.text
2.global __unmapself_sh_mmu
3.hidden __unmapself_sh_mmu
4.type __unmapself_sh_mmu, @function
5__unmapself_sh_mmu:
6 mov #91, r3 ! SYS_munmap
7 trapa #31
8
9 or r0, r0
10 or r0, r0
11 or r0, r0
12 or r0, r0
13 or r0, r0
14
15 mov #1, r3 ! SYS_exit
16 mov #0, r4
17 trapa #31
18
19 or r0, r0
20 or r0, r0
21 or r0, r0
22 or r0, r0
23 or r0, r0
lib/libc/wasi/libc-top-half/musl/src/thread/sh/atomics.s deleted-65
......@@ -1,65 +0,0 @@
1/* Contract for all versions is same as cas.l r2,r3,@r0
2 * pr and r1 are also clobbered (by jsr & r1 as temp).
3 * r0,r2,r4-r15 must be preserved.
4 * r3 contains result (==r2 iff cas succeeded). */
5
6 .align 2
7.global __sh_cas_gusa
8.hidden __sh_cas_gusa
9__sh_cas_gusa:
10 mov.l r5,@-r15
11 mov.l r4,@-r15
12 mov r0,r4
13 mova 1f,r0
14 mov r15,r1
15 mov #(0f-1f),r15
160: mov.l @r4,r5
17 cmp/eq r5,r2
18 bf 1f
19 mov.l r3,@r4
201: mov r1,r15
21 mov r5,r3
22 mov r4,r0
23 mov.l @r15+,r4
24 rts
25 mov.l @r15+,r5
26
27.global __sh_cas_llsc
28.hidden __sh_cas_llsc
29__sh_cas_llsc:
30 mov r0,r1
31 .word 0x00ab /* synco */
320: .word 0x0163 /* movli.l @r1,r0 */
33 cmp/eq r0,r2
34 bf 1f
35 mov r3,r0
36 .word 0x0173 /* movco.l r0,@r1 */
37 bf 0b
38 mov r2,r0
391: .word 0x00ab /* synco */
40 mov r0,r3
41 rts
42 mov r1,r0
43
44.global __sh_cas_imask
45.hidden __sh_cas_imask
46__sh_cas_imask:
47 mov r0,r1
48 stc sr,r0
49 mov.l r0,@-r15
50 or #0xf0,r0
51 ldc r0,sr
52 mov.l @r1,r0
53 cmp/eq r0,r2
54 bf 1f
55 mov.l r3,@r1
561: ldc.l @r15+,sr
57 mov r0,r3
58 rts
59 mov r1,r0
60
61.global __sh_cas_cas_l
62.hidden __sh_cas_cas_l
63__sh_cas_cas_l:
64 rts
65 .word 0x2323 /* cas.l r2,r3,@r0 */
lib/libc/wasi/libc-top-half/musl/src/thread/sh/clone.s deleted-54
......@@ -1,54 +0,0 @@
1.text
2.global __clone
3.hidden __clone
4.type __clone, @function
5__clone:
6! incoming: fn stack flags arg ptid tls ctid
7! r4 r5 r6 r7 @r15 @(4,r15) @(8,r15)
8
9 mov #-16, r0
10 and r0, r5
11
12 mov r4, r1 ! r1 = fn
13 mov r7, r2 ! r2 = arg
14
15 mov #120, r3 ! r3 = __NR_clone
16 mov r6, r4 ! r4 = flags
17 !mov r5, r5 ! r5 = stack
18 mov.l @r15, r6 ! r6 = ptid
19 mov.l @(8,r15), r7 ! r7 = ctid
20 mov.l @(4,r15), r0 ! r0 = tls
21 trapa #31
22
23 or r0, r0
24 or r0, r0
25 or r0, r0
26 or r0, r0
27 or r0, r0
28
29 cmp/eq #0, r0
30 bt 1f
31
32 ! we are the parent, return
33 rts
34 nop
35
361: ! we are the child, call fn(arg)
37 mov.l 1f, r0
38 mov r1, r5
39 bsrf r0
40 mov r2, r4
41
422: mov #1, r3 ! __NR_exit
43 mov r0, r4
44 trapa #31
45
46 or r0, r0
47 or r0, r0
48 or r0, r0
49 or r0, r0
50 or r0, r0
51
52.align 2
53.hidden __shcall
541: .long __shcall@PCREL+(.-2b)
lib/libc/wasi/libc-top-half/musl/src/thread/sh/syscall_cp.s deleted-45
......@@ -1,45 +0,0 @@
1.text
2.global __cp_begin
3.hidden __cp_begin
4.global __cp_end
5.hidden __cp_end
6.global __cp_cancel
7.hidden __cp_cancel
8.hidden __cancel
9.global __syscall_cp_asm
10.hidden __syscall_cp_asm
11.type __syscall_cp_asm, @function
12__syscall_cp_asm:
13
14__cp_begin:
15 mov.l @r4, r4
16 tst r4, r4
17 bf __cp_cancel
18 mov r5, r3
19 mov r6, r4
20 mov r7, r5
21 mov.l @r15, r6
22 mov.l @(4,r15), r7
23 mov.l @(8,r15), r0
24 mov.l @(12,r15), r1
25 trapa #31
26
27__cp_end:
28 ! work around hardware bug
29 or r0, r0
30 or r0, r0
31 or r0, r0
32 or r0, r0
33 or r0, r0
34
35 rts
36 nop
37
38__cp_cancel:
39 mov.l 2f, r0
40 braf r0
41 nop
421:
43
44.align 2
452: .long __cancel@PCREL-(1b-.)
lib/libc/wasi/libc-top-half/musl/src/thread/synccall.c deleted-120
......@@ -1,120 +0,0 @@
1#include "pthread_impl.h"
2#include <semaphore.h>
3#include <string.h>
4
5static void dummy_0(void)
6{
7}
8
9weak_alias(dummy_0, __tl_lock);
10weak_alias(dummy_0, __tl_unlock);
11
12static int target_tid;
13static void (*callback)(void *), *context;
14static sem_t target_sem, caller_sem;
15
16static void dummy(void *p)
17{
18}
19
20static void handler(int sig)
21{
22 if (__pthread_self()->tid != target_tid) return;
23
24 int old_errno = errno;
25
26 /* Inform caller we have received signal and wait for
27 * the caller to let us make the callback. */
28 sem_post(&caller_sem);
29 sem_wait(&target_sem);
30
31 callback(context);
32
33 /* Inform caller we've complered the callback and wait
34 * for the caller to release us to return. */
35 sem_post(&caller_sem);
36 sem_wait(&target_sem);
37
38 /* Inform caller we are returning and state is destroyable. */
39 sem_post(&caller_sem);
40
41 errno = old_errno;
42}
43
44void __synccall(void (*func)(void *), void *ctx)
45{
46 sigset_t oldmask;
47 int cs, i, r;
48 struct sigaction sa = { .sa_flags = SA_RESTART, .sa_handler = handler };
49 pthread_t self = __pthread_self(), td;
50 int count = 0;
51
52 /* Blocking signals in two steps, first only app-level signals
53 * before taking the lock, then all signals after taking the lock,
54 * is necessary to achieve AS-safety. Blocking them all first would
55 * deadlock if multiple threads called __synccall. Waiting to block
56 * any until after the lock would allow re-entry in the same thread
57 * with the lock already held. */
58 __block_app_sigs(&oldmask);
59 __tl_lock();
60 __block_all_sigs(0);
61 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
62
63 sem_init(&target_sem, 0, 0);
64 sem_init(&caller_sem, 0, 0);
65
66 if (!libc.threads_minus_1 || __syscall(SYS_gettid) != self->tid)
67 goto single_threaded;
68
69 callback = func;
70 context = ctx;
71
72 /* Block even implementation-internal signals, so that nothing
73 * interrupts the SIGSYNCCALL handlers. The main possible source
74 * of trouble is asynchronous cancellation. */
75 memset(&sa.sa_mask, -1, sizeof sa.sa_mask);
76 __libc_sigaction(SIGSYNCCALL, &sa, 0);
77
78
79 for (td=self->next; td!=self; td=td->next) {
80 target_tid = td->tid;
81 while ((r = -__syscall(SYS_tkill, td->tid, SIGSYNCCALL)) == EAGAIN);
82 if (r) {
83 /* If we failed to signal any thread, nop out the
84 * callback to abort the synccall and just release
85 * any threads already caught. */
86 callback = func = dummy;
87 break;
88 }
89 sem_wait(&caller_sem);
90 count++;
91 }
92 target_tid = 0;
93
94 /* Serialize execution of callback in caught threads, or just
95 * release them all if synccall is being aborted. */
96 for (i=0; i<count; i++) {
97 sem_post(&target_sem);
98 sem_wait(&caller_sem);
99 }
100
101 sa.sa_handler = SIG_IGN;
102 __libc_sigaction(SIGSYNCCALL, &sa, 0);
103
104single_threaded:
105 func(ctx);
106
107 /* Only release the caught threads once all threads, including the
108 * caller, have returned from the callback function. */
109 for (i=0; i<count; i++)
110 sem_post(&target_sem);
111 for (i=0; i<count; i++)
112 sem_wait(&caller_sem);
113
114 sem_destroy(&caller_sem);
115 sem_destroy(&target_sem);
116
117 pthread_setcancelstate(cs, 0);
118 __tl_unlock();
119 __restore_sigs(&oldmask);
120}
lib/libc/wasi/libc-top-half/musl/src/thread/syscall_cp.c deleted
lib/libc/wasi/libc-top-half/musl/src/thread/thrd_create.c deleted-12
......@@ -1,12 +0,0 @@
1#include "pthread_impl.h"
2#include <threads.h>
3
4int thrd_create(thrd_t *thr, thrd_start_t func, void *arg)
5{
6 int ret = __pthread_create(thr, __ATTRP_C11_THREAD, (void *(*)(void *))func, arg);
7 switch (ret) {
8 case 0: return thrd_success;
9 case EAGAIN: return thrd_nomem;
10 default: return thrd_error;
11 }
12}
lib/libc/wasi/libc-top-half/musl/src/thread/thrd_exit.c deleted-8
......@@ -1,8 +0,0 @@
1#include <threads.h>
2#include <pthread.h>
3#include <stdint.h>
4
5_Noreturn void thrd_exit(int result)
6{
7 __pthread_exit((void*)(intptr_t)result);
8}
lib/libc/wasi/libc-top-half/musl/src/thread/thrd_join.c deleted-11
......@@ -1,11 +0,0 @@
1#include <stdint.h>
2#include <threads.h>
3#include <pthread.h>
4
5int thrd_join(thrd_t t, int *res)
6{
7 void *pthread_res;
8 __pthread_join(t, &pthread_res);
9 if (res) *res = (int)(intptr_t)pthread_res;
10 return thrd_success;
11}
lib/libc/wasi/libc-top-half/musl/src/thread/thrd_yield.c deleted-7
......@@ -1,7 +0,0 @@
1#include <threads.h>
2#include "syscall.h"
3
4void thrd_yield()
5{
6 __syscall(SYS_sched_yield);
7}
lib/libc/wasi/libc-top-half/musl/src/thread/tls.c deleted
lib/libc/wasi/libc-top-half/musl/src/thread/tss_create.c deleted-10
......@@ -1,10 +0,0 @@
1#include <threads.h>
2#include <pthread.h>
3
4int tss_create(tss_t *tss, tss_dtor_t dtor)
5{
6 /* Different error returns are possible. C glues them together into
7 * just failure notification. Can't be optimized to a tail call,
8 * unless thrd_error equals EAGAIN. */
9 return __pthread_key_create(tss, dtor) ? thrd_error : thrd_success;
10}
lib/libc/wasi/libc-top-half/musl/src/thread/tss_delete.c deleted-7
......@@ -1,7 +0,0 @@
1#include <threads.h>
2#include <pthread.h>
3
4void tss_delete(tss_t key)
5{
6 __pthread_key_delete(key);
7}
lib/libc/wasi/libc-top-half/musl/src/thread/tss_set.c deleted-13
......@@ -1,13 +0,0 @@
1#include "pthread_impl.h"
2#include <threads.h>
3
4int tss_set(tss_t k, void *x)
5{
6 struct pthread *self = __pthread_self();
7 /* Avoid unnecessary COW */
8 if (self->tsd[k] != x) {
9 self->tsd[k] = x;
10 self->tsd_used = 1;
11 }
12 return thrd_success;
13}
lib/libc/wasi/libc-top-half/musl/src/thread/vmlock.c deleted-23
......@@ -1,23 +0,0 @@
1#include "pthread_impl.h"
2#include "fork_impl.h"
3
4static volatile int vmlock[2];
5volatile int *const __vmlock_lockptr = vmlock;
6
7void __vm_wait()
8{
9 int tmp;
10 while ((tmp=vmlock[0]))
11 __wait(vmlock, vmlock+1, tmp, 1);
12}
13
14void __vm_lock()
15{
16 a_inc(vmlock);
17}
18
19void __vm_unlock()
20{
21 if (a_fetch_add(vmlock, -1)==1 && vmlock[1])
22 __wake(vmlock, -1, 1);
23}
lib/libc/wasi/libc-top-half/musl/src/thread/x32/__set_thread_area.s deleted-11
......@@ -1,11 +0,0 @@
1/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
2.text
3.global __set_thread_area
4.hidden __set_thread_area
5.type __set_thread_area,@function
6__set_thread_area:
7 mov %edi,%esi /* shift for syscall */
8 movl $0x1002,%edi /* SET_FS register */
9 movl $0x4000009e,%eax /* set fs segment to */
10 syscall /* arch_prctl(SET_FS, arg)*/
11 ret
lib/libc/wasi/libc-top-half/musl/src/thread/x32/__unmapself.s deleted-10
......@@ -1,10 +0,0 @@
1/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
2.text
3.global __unmapself
4.type __unmapself,@function
5__unmapself:
6 movl $0x4000000b,%eax /* SYS_munmap */
7 syscall /* munmap(arg2,arg3) */
8 xor %rdi,%rdi /* exit() args: always return success */
9 movl $0x4000003c,%eax /* SYS_exit */
10 syscall /* exit(0) */
lib/libc/wasi/libc-top-half/musl/src/thread/x32/clone.s deleted-26
......@@ -1,26 +0,0 @@
1.text
2.global __clone
3.hidden __clone
4.type __clone,@function
5__clone:
6 movl $0x40000038,%eax /* SYS_clone */
7 mov %rdi,%r11
8 mov %rdx,%rdi
9 mov %r8,%rdx
10 mov %r9,%r8
11 mov 8(%rsp),%r10
12 mov %r11,%r9
13 and $-16,%rsi
14 sub $8,%rsi
15 mov %rcx,(%rsi)
16 syscall
17 test %eax,%eax
18 jnz 1f
19 xor %ebp,%ebp
20 pop %rdi
21 call *%r9
22 mov %eax,%edi
23 movl $0x4000003c,%eax /* SYS_exit */
24 syscall
25 hlt
261: ret
lib/libc/wasi/libc-top-half/musl/src/thread/x32/syscall_cp.s deleted-31
......@@ -1,31 +0,0 @@
1.text
2.global __cp_begin
3.hidden __cp_begin
4.global __cp_end
5.hidden __cp_end
6.global __cp_cancel
7.hidden __cp_cancel
8.hidden __cancel
9.global __syscall_cp_asm
10.hidden __syscall_cp_asm
11.type __syscall_cp_asm,@function
12__syscall_cp_asm:
13
14__cp_begin:
15 mov (%rdi),%eax
16 test %eax,%eax
17 jnz __cp_cancel
18 mov %rdi,%r11
19 mov %rsi,%rax
20 mov %rdx,%rdi
21 mov %rcx,%rsi
22 mov %r8,%rdx
23 mov %r9,%r10
24 mov 8(%rsp),%r8
25 mov 16(%rsp),%r9
26 mov %r11,8(%rsp)
27 syscall
28__cp_end:
29 ret
30__cp_cancel:
31 jmp __cancel
lib/libc/wasi/libc-top-half/musl/src/thread/x86_64/__set_thread_area.s deleted-11
......@@ -1,11 +0,0 @@
1/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
2.text
3.global __set_thread_area
4.hidden __set_thread_area
5.type __set_thread_area,@function
6__set_thread_area:
7 mov %rdi,%rsi /* shift for syscall */
8 movl $0x1002,%edi /* SET_FS register */
9 movl $158,%eax /* set fs segment to */
10 syscall /* arch_prctl(SET_FS, arg)*/
11 ret
lib/libc/wasi/libc-top-half/musl/src/thread/x86_64/__unmapself.s deleted-10
......@@ -1,10 +0,0 @@
1/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
2.text
3.global __unmapself
4.type __unmapself,@function
5__unmapself:
6 movl $11,%eax /* SYS_munmap */
7 syscall /* munmap(arg2,arg3) */
8 xor %rdi,%rdi /* exit() args: always return success */
9 movl $60,%eax /* SYS_exit */
10 syscall /* exit(0) */
lib/libc/wasi/libc-top-half/musl/src/thread/x86_64/clone.s deleted-28
......@@ -1,28 +0,0 @@
1.text
2.global __clone
3.hidden __clone
4.type __clone,@function
5__clone:
6 xor %eax,%eax
7 mov $56,%al
8 mov %rdi,%r11
9 mov %rdx,%rdi
10 mov %r8,%rdx
11 mov %r9,%r8
12 mov 8(%rsp),%r10
13 mov %r11,%r9
14 and $-16,%rsi
15 sub $8,%rsi
16 mov %rcx,(%rsi)
17 syscall
18 test %eax,%eax
19 jnz 1f
20 xor %ebp,%ebp
21 pop %rdi
22 call *%r9
23 mov %eax,%edi
24 xor %eax,%eax
25 mov $60,%al
26 syscall
27 hlt
281: ret
lib/libc/wasi/libc-top-half/musl/src/thread/x86_64/syscall_cp.s deleted-31
......@@ -1,31 +0,0 @@
1.text
2.global __cp_begin
3.hidden __cp_begin
4.global __cp_end
5.hidden __cp_end
6.global __cp_cancel
7.hidden __cp_cancel
8.hidden __cancel
9.global __syscall_cp_asm
10.hidden __syscall_cp_asm
11.type __syscall_cp_asm,@function
12__syscall_cp_asm:
13
14__cp_begin:
15 mov (%rdi),%eax
16 test %eax,%eax
17 jnz __cp_cancel
18 mov %rdi,%r11
19 mov %rsi,%rax
20 mov %rdx,%rdi
21 mov %rcx,%rsi
22 mov %r8,%rdx
23 mov %r9,%r10
24 mov 8(%rsp),%r8
25 mov 16(%rsp),%r9
26 mov %r11,8(%rsp)
27 syscall
28__cp_end:
29 ret
30__cp_cancel:
31 jmp __cancel
lib/libc/wasi/libc-top-half/musl/src/time/__map_file.c deleted-19
......@@ -1,19 +0,0 @@
1#include <sys/mman.h>
2#include <fcntl.h>
3#include <sys/stat.h>
4#include "syscall.h"
5#include "kstat.h"
6
7const char unsigned *__map_file(const char *pathname, size_t *size)
8{
9 struct kstat st;
10 const unsigned char *map = MAP_FAILED;
11 int fd = sys_open(pathname, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
12 if (fd < 0) return 0;
13 if (!syscall(SYS_fstat, fd, &st)) {
14 map = __mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
15 *size = st.st_size;
16 }
17 __syscall(SYS_close, fd);
18 return map == MAP_FAILED ? 0 : map;
19}
lib/libc/wasi/libc-top-half/musl/src/time/clock.c deleted-16
......@@ -1,16 +0,0 @@
1#include <time.h>
2#include <limits.h>
3
4clock_t clock()
5{
6 struct timespec ts;
7
8 if (__clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts))
9 return -1;
10
11 if (ts.tv_sec > LONG_MAX/1000000
12 || ts.tv_nsec/1000 > LONG_MAX-1000000*ts.tv_sec)
13 return -1;
14
15 return ts.tv_sec*1000000 + ts.tv_nsec/1000;
16}
lib/libc/wasi/libc-top-half/musl/src/time/clock_getcpuclockid.c deleted-14
......@@ -1,14 +0,0 @@
1#include <time.h>
2#include <errno.h>
3#include <unistd.h>
4#include "syscall.h"
5
6int clock_getcpuclockid(pid_t pid, clockid_t *clk)
7{
8 struct timespec ts;
9 clockid_t id = (-pid-1)*8U + 2;
10 int ret = __syscall(SYS_clock_getres, id, &ts);
11 if (ret) return -ret;
12 *clk = id;
13 return 0;
14}
lib/libc/wasi/libc-top-half/musl/src/time/clock_getres.c deleted-21
......@@ -1,21 +0,0 @@
1#include <time.h>
2#include "syscall.h"
3
4int clock_getres(clockid_t clk, struct timespec *ts)
5{
6#ifdef SYS_clock_getres_time64
7 /* On a 32-bit arch, use the old syscall if it exists. */
8 if (SYS_clock_getres != SYS_clock_getres_time64) {
9 long ts32[2];
10 int r = __syscall(SYS_clock_getres, clk, ts32);
11 if (!r && ts) {
12 ts->tv_sec = ts32[0];
13 ts->tv_nsec = ts32[1];
14 }
15 return __syscall_ret(r);
16 }
17#endif
18 /* If reaching this point, it's a 64-bit arch or time64-only
19 * 32-bit arch and we can get result directly into timespec. */
20 return syscall(SYS_clock_getres, clk, ts);
21}
lib/libc/wasi/libc-top-half/musl/src/time/clock_gettime.c deleted-107
......@@ -1,107 +0,0 @@
1#include <time.h>
2#include <errno.h>
3#include <stdint.h>
4#include "syscall.h"
5#include "atomic.h"
6
7#ifdef VDSO_CGT_SYM
8
9static void *volatile vdso_func;
10
11#ifdef VDSO_CGT32_SYM
12static void *volatile vdso_func_32;
13static int cgt_time32_wrap(clockid_t clk, struct timespec *ts)
14{
15 long ts32[2];
16 int (*f)(clockid_t, long[2]) =
17 (int (*)(clockid_t, long[2]))vdso_func_32;
18 int r = f(clk, ts32);
19 if (!r) {
20 /* Fallback to syscalls if time32 overflowed. Maybe
21 * we lucked out and somehow migrated to a kernel with
22 * time64 syscalls available. */
23 if (ts32[0] < 0) {
24 a_cas_p(&vdso_func, (void *)cgt_time32_wrap, 0);
25 return -ENOSYS;
26 }
27 ts->tv_sec = ts32[0];
28 ts->tv_nsec = ts32[1];
29 }
30 return r;
31}
32#endif
33
34static int cgt_init(clockid_t clk, struct timespec *ts)
35{
36 void *p = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM);
37#ifdef VDSO_CGT32_SYM
38 if (!p) {
39 void *q = __vdsosym(VDSO_CGT32_VER, VDSO_CGT32_SYM);
40 if (q) {
41 a_cas_p(&vdso_func_32, 0, q);
42 p = cgt_time32_wrap;
43 }
44 }
45#endif
46 int (*f)(clockid_t, struct timespec *) =
47 (int (*)(clockid_t, struct timespec *))p;
48 a_cas_p(&vdso_func, (void *)cgt_init, p);
49 return f ? f(clk, ts) : -ENOSYS;
50}
51
52static void *volatile vdso_func = (void *)cgt_init;
53
54#endif
55
56int __clock_gettime(clockid_t clk, struct timespec *ts)
57{
58 int r;
59
60#ifdef VDSO_CGT_SYM
61 int (*f)(clockid_t, struct timespec *) =
62 (int (*)(clockid_t, struct timespec *))vdso_func;
63 if (f) {
64 r = f(clk, ts);
65 if (!r) return r;
66 if (r == -EINVAL) return __syscall_ret(r);
67 /* Fall through on errors other than EINVAL. Some buggy
68 * vdso implementations return ENOSYS for clocks they
69 * can't handle, rather than making the syscall. This
70 * also handles the case where cgt_init fails to find
71 * a vdso function to use. */
72 }
73#endif
74
75#ifdef SYS_clock_gettime64
76 r = -ENOSYS;
77 if (sizeof(time_t) > 4)
78 r = __syscall(SYS_clock_gettime64, clk, ts);
79 if (SYS_clock_gettime == SYS_clock_gettime64 || r!=-ENOSYS)
80 return __syscall_ret(r);
81 long ts32[2];
82 r = __syscall(SYS_clock_gettime, clk, ts32);
83 if (r==-ENOSYS && clk==CLOCK_REALTIME) {
84 r = __syscall(SYS_gettimeofday, ts32, 0);
85 ts32[1] *= 1000;
86 }
87 if (!r) {
88 ts->tv_sec = ts32[0];
89 ts->tv_nsec = ts32[1];
90 return r;
91 }
92 return __syscall_ret(r);
93#else
94 r = __syscall(SYS_clock_gettime, clk, ts);
95 if (r == -ENOSYS) {
96 if (clk == CLOCK_REALTIME) {
97 __syscall(SYS_gettimeofday, ts, 0);
98 ts->tv_nsec = (int)ts->tv_nsec * 1000;
99 return 0;
100 }
101 r = -EINVAL;
102 }
103 return __syscall_ret(r);
104#endif
105}
106
107weak_alias(__clock_gettime, clock_gettime);
lib/libc/wasi/libc-top-half/musl/src/time/clock_nanosleep.c deleted-38
......@@ -1,38 +0,0 @@
1#include <time.h>
2#include <errno.h>
3#include "syscall.h"
4
5#define IS32BIT(x) !((x)+0x80000000ULL>>32)
6#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
7
8int __clock_nanosleep(clockid_t clk, int flags, const struct timespec *req, struct timespec *rem)
9{
10 if (clk == CLOCK_THREAD_CPUTIME_ID) return EINVAL;
11#ifdef SYS_clock_nanosleep_time64
12 time_t s = req->tv_sec;
13 long ns = req->tv_nsec;
14 int r = -ENOSYS;
15 if (SYS_clock_nanosleep == SYS_clock_nanosleep_time64 || !IS32BIT(s))
16 r = __syscall_cp(SYS_clock_nanosleep_time64, clk, flags,
17 ((long long[]){s, ns}), rem);
18 if (SYS_clock_nanosleep == SYS_clock_nanosleep_time64 || r!=-ENOSYS)
19 return -r;
20 long long extra = s - CLAMP(s);
21 long ts32[2] = { CLAMP(s), ns };
22 if (clk == CLOCK_REALTIME && !flags)
23 r = __syscall_cp(SYS_nanosleep, &ts32, &ts32);
24 else
25 r = __syscall_cp(SYS_clock_nanosleep, clk, flags, &ts32, &ts32);
26 if (r==-EINTR && rem && !(flags & TIMER_ABSTIME)) {
27 rem->tv_sec = ts32[0] + extra;
28 rem->tv_nsec = ts32[1];
29 }
30 return -r;
31#else
32 if (clk == CLOCK_REALTIME && !flags)
33 return -__syscall_cp(SYS_nanosleep, req, rem);
34 return -__syscall_cp(SYS_clock_nanosleep, clk, flags, req, rem);
35#endif
36}
37
38weak_alias(__clock_nanosleep, clock_nanosleep);
lib/libc/wasi/libc-top-half/musl/src/time/clock_settime.c deleted-24
......@@ -1,24 +0,0 @@
1#include <time.h>
2#include <errno.h>
3#include "syscall.h"
4
5#define IS32BIT(x) !((x)+0x80000000ULL>>32)
6
7int clock_settime(clockid_t clk, const struct timespec *ts)
8{
9#ifdef SYS_clock_settime64
10 time_t s = ts->tv_sec;
11 long ns = ts->tv_nsec;
12 int r = -ENOSYS;
13 if (SYS_clock_settime == SYS_clock_settime64 || !IS32BIT(s))
14 r = __syscall(SYS_clock_settime64, clk,
15 ((long long[]){s, ns}));
16 if (SYS_clock_settime == SYS_clock_settime64 || r!=-ENOSYS)
17 return __syscall_ret(r);
18 if (!IS32BIT(s))
19 return __syscall_ret(-ENOTSUP);
20 return syscall(SYS_clock_settime, clk, ((long[]){s, ns}));
21#else
22 return syscall(SYS_clock_settime, clk, ts);
23#endif
24}
lib/libc/wasi/libc-top-half/musl/src/time/gettimeofday.c deleted-13
......@@ -1,13 +0,0 @@
1#include <time.h>
2#include <sys/time.h>
3#include "syscall.h"
4
5int gettimeofday(struct timeval *restrict tv, void *restrict tz)
6{
7 struct timespec ts;
8 if (!tv) return 0;
9 clock_gettime(CLOCK_REALTIME, &ts);
10 tv->tv_sec = ts.tv_sec;
11 tv->tv_usec = (int)ts.tv_nsec / 1000;
12 return 0;
13}
lib/libc/wasi/libc-top-half/musl/src/time/nanosleep.c deleted-7
......@@ -1,7 +0,0 @@
1#include <time.h>
2#include "syscall.h"
3
4int nanosleep(const struct timespec *req, struct timespec *rem)
5{
6 return __syscall_ret(-__clock_nanosleep(CLOCK_REALTIME, 0, req, rem));
7}
lib/libc/wasi/libc-top-half/musl/src/time/time.c deleted-10
......@@ -1,10 +0,0 @@
1#include <time.h>
2#include "syscall.h"
3
4time_t time(time_t *t)
5{
6 struct timespec ts;
7 __clock_gettime(CLOCK_REALTIME, &ts);
8 if (t) *t = ts.tv_sec;
9 return ts.tv_sec;
10}
lib/libc/wasi/libc-top-half/musl/src/time/timer_create.c deleted-129
......@@ -1,129 +0,0 @@
1#include <time.h>
2#include <setjmp.h>
3#include <limits.h>
4#include "pthread_impl.h"
5#include "atomic.h"
6
7struct ksigevent {
8 union sigval sigev_value;
9 int sigev_signo;
10 int sigev_notify;
11 int sigev_tid;
12};
13
14struct start_args {
15 pthread_barrier_t b;
16 struct sigevent *sev;
17};
18
19static void dummy_0()
20{
21}
22weak_alias(dummy_0, __pthread_tsd_run_dtors);
23
24static void cleanup_fromsig(void *p)
25{
26 pthread_t self = __pthread_self();
27 __pthread_tsd_run_dtors();
28 self->cancel = 0;
29 self->cancelbuf = 0;
30 self->canceldisable = 0;
31 self->cancelasync = 0;
32 __reset_tls();
33 longjmp(p, 1);
34}
35
36static void *start(void *arg)
37{
38 pthread_t self = __pthread_self();
39 struct start_args *args = arg;
40 jmp_buf jb;
41
42 void (*notify)(union sigval) = args->sev->sigev_notify_function;
43 union sigval val = args->sev->sigev_value;
44
45 pthread_barrier_wait(&args->b);
46 for (;;) {
47 siginfo_t si;
48 while (sigwaitinfo(SIGTIMER_SET, &si) < 0);
49 if (si.si_code == SI_TIMER && !setjmp(jb)) {
50 pthread_cleanup_push(cleanup_fromsig, jb);
51 notify(val);
52 pthread_cleanup_pop(1);
53 }
54 if (self->timer_id < 0) break;
55 }
56 __syscall(SYS_timer_delete, self->timer_id & INT_MAX);
57 return 0;
58}
59
60int timer_create(clockid_t clk, struct sigevent *restrict evp, timer_t *restrict res)
61{
62 volatile static int init = 0;
63 pthread_t td;
64 pthread_attr_t attr;
65 int r;
66 struct start_args args;
67 struct ksigevent ksev, *ksevp=0;
68 int timerid;
69 sigset_t set;
70
71 switch (evp ? evp->sigev_notify : SIGEV_SIGNAL) {
72 case SIGEV_NONE:
73 case SIGEV_SIGNAL:
74 case SIGEV_THREAD_ID:
75 if (evp) {
76 ksev.sigev_value = evp->sigev_value;
77 ksev.sigev_signo = evp->sigev_signo;
78 ksev.sigev_notify = evp->sigev_notify;
79 if (evp->sigev_notify == SIGEV_THREAD_ID)
80 ksev.sigev_tid = evp->sigev_notify_thread_id;
81 else
82 ksev.sigev_tid = 0;
83 ksevp = &ksev;
84 }
85 if (syscall(SYS_timer_create, clk, ksevp, &timerid) < 0)
86 return -1;
87 *res = (void *)(intptr_t)timerid;
88 break;
89 case SIGEV_THREAD:
90 if (!init) {
91 struct sigaction sa = { .sa_handler = SIG_DFL };
92 __libc_sigaction(SIGTIMER, &sa, 0);
93 a_store(&init, 1);
94 }
95 if (evp->sigev_notify_attributes)
96 attr = *evp->sigev_notify_attributes;
97 else
98 pthread_attr_init(&attr);
99 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
100 pthread_barrier_init(&args.b, 0, 2);
101 args.sev = evp;
102
103 __block_app_sigs(&set);
104 __syscall(SYS_rt_sigprocmask, SIG_BLOCK, SIGTIMER_SET, 0, _NSIG/8);
105 r = pthread_create(&td, &attr, start, &args);
106 __restore_sigs(&set);
107 if (r) {
108 errno = r;
109 return -1;
110 }
111
112 ksev.sigev_value.sival_ptr = 0;
113 ksev.sigev_signo = SIGTIMER;
114 ksev.sigev_notify = SIGEV_THREAD_ID;
115 ksev.sigev_tid = td->tid;
116 if (syscall(SYS_timer_create, clk, &ksev, &timerid) < 0)
117 timerid = -1;
118 td->timer_id = timerid;
119 pthread_barrier_wait(&args.b);
120 if (timerid < 0) return -1;
121 *res = (void *)(INTPTR_MIN | (uintptr_t)td>>1);
122 break;
123 default:
124 errno = EINVAL;
125 return -1;
126 }
127
128 return 0;
129}
lib/libc/wasi/libc-top-half/musl/src/time/timer_delete.c deleted-14
......@@ -1,14 +0,0 @@
1#include <time.h>
2#include <limits.h>
3#include "pthread_impl.h"
4
5int timer_delete(timer_t t)
6{
7 if ((intptr_t)t < 0) {
8 pthread_t td = (void *)((uintptr_t)t << 1);
9 a_store(&td->timer_id, td->timer_id | INT_MIN);
10 __syscall(SYS_tkill, td->tid, SIGTIMER);
11 return 0;
12 }
13 return __syscall(SYS_timer_delete, t);
14}
lib/libc/wasi/libc-top-half/musl/src/time/timer_getoverrun.c deleted-12
......@@ -1,12 +0,0 @@
1#include <time.h>
2#include <limits.h>
3#include "pthread_impl.h"
4
5int timer_getoverrun(timer_t t)
6{
7 if ((intptr_t)t < 0) {
8 pthread_t td = (void *)((uintptr_t)t << 1);
9 t = (void *)(uintptr_t)(td->timer_id & INT_MAX);
10 }
11 return syscall(SYS_timer_getoverrun, t);
12}
lib/libc/wasi/libc-top-half/musl/src/time/timer_gettime.c deleted-28
......@@ -1,28 +0,0 @@
1#include <time.h>
2#include <limits.h>
3#include "pthread_impl.h"
4
5int timer_gettime(timer_t t, struct itimerspec *val)
6{
7 if ((intptr_t)t < 0) {
8 pthread_t td = (void *)((uintptr_t)t << 1);
9 t = (void *)(uintptr_t)(td->timer_id & INT_MAX);
10 }
11#ifdef SYS_timer_gettime64
12 int r = -ENOSYS;
13 if (sizeof(time_t) > 4)
14 r = __syscall(SYS_timer_gettime64, t, val);
15 if (SYS_timer_gettime == SYS_timer_gettime64 || r!=-ENOSYS)
16 return __syscall_ret(r);
17 long val32[4];
18 r = __syscall(SYS_timer_gettime, t, val32);
19 if (!r) {
20 val->it_interval.tv_sec = val32[0];
21 val->it_interval.tv_nsec = val32[1];
22 val->it_value.tv_sec = val32[2];
23 val->it_value.tv_nsec = val32[3];
24 }
25 return __syscall_ret(r);
26#endif
27 return syscall(SYS_timer_gettime, t, val);
28}
lib/libc/wasi/libc-top-half/musl/src/time/timer_settime.c deleted-37
......@@ -1,37 +0,0 @@
1#include <time.h>
2#include <limits.h>
3#include "pthread_impl.h"
4
5#define IS32BIT(x) !((x)+0x80000000ULL>>32)
6
7int timer_settime(timer_t t, int flags, const struct itimerspec *restrict val, struct itimerspec *restrict old)
8{
9 if ((intptr_t)t < 0) {
10 pthread_t td = (void *)((uintptr_t)t << 1);
11 t = (void *)(uintptr_t)(td->timer_id & INT_MAX);
12 }
13#ifdef SYS_timer_settime64
14 time_t is = val->it_interval.tv_sec, vs = val->it_value.tv_sec;
15 long ins = val->it_interval.tv_nsec, vns = val->it_value.tv_nsec;
16 int r = -ENOSYS;
17 if (SYS_timer_settime == SYS_timer_settime64
18 || !IS32BIT(is) || !IS32BIT(vs) || (sizeof(time_t)>4 && old))
19 r = __syscall(SYS_timer_settime64, t, flags,
20 ((long long[]){is, ins, vs, vns}), old);
21 if (SYS_timer_settime == SYS_timer_settime64 || r!=-ENOSYS)
22 return __syscall_ret(r);
23 if (!IS32BIT(is) || !IS32BIT(vs))
24 return __syscall_ret(-ENOTSUP);
25 long old32[4];
26 r = __syscall(SYS_timer_settime, t, flags,
27 ((long[]){is, ins, vs, vns}), old32);
28 if (!r && old) {
29 old->it_interval.tv_sec = old32[0];
30 old->it_interval.tv_nsec = old32[1];
31 old->it_value.tv_sec = old32[2];
32 old->it_value.tv_nsec = old32[3];
33 }
34 return __syscall_ret(r);
35#endif
36 return syscall(SYS_timer_settime, t, flags, val, old);
37}
lib/libc/wasi/libc-top-half/musl/src/time/times.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/times.h>
2#include "syscall.h"
3
4clock_t times(struct tms *tms)
5{
6 return __syscall(SYS_times, tms);
7}
lib/libc/wasi/libc-top-half/musl/src/time/utime.c deleted-11
......@@ -1,11 +0,0 @@
1#include <utime.h>
2#include <sys/stat.h>
3#include <time.h>
4#include <fcntl.h>
5
6int utime(const char *path, const struct utimbuf *times)
7{
8 return utimensat(AT_FDCWD, path, times ? ((struct timespec [2]){
9 { .tv_sec = times->actime }, { .tv_sec = times->modtime }})
10 : 0, 0);
11}
lib/libc/wasi/libc-top-half/musl/src/unistd/_exit.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include <stdlib.h>
3
4_Noreturn void _exit(int status)
5{
6 _Exit(status);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/access.c deleted-12
......@@ -1,12 +0,0 @@
1#include <unistd.h>
2#include <fcntl.h>
3#include "syscall.h"
4
5int access(const char *filename, int amode)
6{
7#ifdef SYS_access
8 return syscall(SYS_access, filename, amode);
9#else
10 return syscall(SYS_faccessat, AT_FDCWD, filename, amode, 0);
11#endif
12}
lib/libc/wasi/libc-top-half/musl/src/unistd/acct.c deleted-8
......@@ -1,8 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include "syscall.h"
4
5int acct(const char *filename)
6{
7 return syscall(SYS_acct, filename);
8}
lib/libc/wasi/libc-top-half/musl/src/unistd/alarm.c deleted-10
......@@ -1,10 +0,0 @@
1#include <unistd.h>
2#include <sys/time.h>
3#include "syscall.h"
4
5unsigned alarm(unsigned seconds)
6{
7 struct itimerval it = { .it_value.tv_sec = seconds }, old = { 0 };
8 setitimer(ITIMER_REAL, &it, &old);
9 return old.it_value.tv_sec + !!old.it_value.tv_usec;
10}
lib/libc/wasi/libc-top-half/musl/src/unistd/chdir.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4int chdir(const char *path)
5{
6 return syscall(SYS_chdir, path);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/chown.c deleted-12
......@@ -1,12 +0,0 @@
1#include <unistd.h>
2#include <fcntl.h>
3#include "syscall.h"
4
5int chown(const char *path, uid_t uid, gid_t gid)
6{
7#ifdef SYS_chown
8 return syscall(SYS_chown, path, uid, gid);
9#else
10 return syscall(SYS_fchownat, AT_FDCWD, path, uid, gid, 0);
11#endif
12}
lib/libc/wasi/libc-top-half/musl/src/unistd/close.c deleted-19
......@@ -1,19 +0,0 @@
1#include <unistd.h>
2#include <errno.h>
3#include "aio_impl.h"
4#include "syscall.h"
5
6static int dummy(int fd)
7{
8 return fd;
9}
10
11weak_alias(dummy, __aio_close);
12
13int close(int fd)
14{
15 fd = __aio_close(fd);
16 int r = __syscall_cp(SYS_close, fd);
17 if (r == -EINTR) r = 0;
18 return __syscall_ret(r);
19}
lib/libc/wasi/libc-top-half/musl/src/unistd/ctermid.c deleted-7
......@@ -1,7 +0,0 @@
1#include <stdio.h>
2#include <string.h>
3
4char *ctermid(char *s)
5{
6 return s ? strcpy(s, "/dev/tty") : "/dev/tty";
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/dup.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4int dup(int fd)
5{
6 return syscall(SYS_dup, fd);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/dup2.c deleted-20
......@@ -1,20 +0,0 @@
1#include <unistd.h>
2#include <errno.h>
3#include <fcntl.h>
4#include "syscall.h"
5
6int dup2(int old, int new)
7{
8 int r;
9#ifdef SYS_dup2
10 while ((r=__syscall(SYS_dup2, old, new))==-EBUSY);
11#else
12 if (old==new) {
13 r = __syscall(SYS_fcntl, old, F_GETFD);
14 if (r >= 0) return old;
15 } else {
16 while ((r=__syscall(SYS_dup3, old, new, 0))==-EBUSY);
17 }
18#endif
19 return __syscall_ret(r);
20}
lib/libc/wasi/libc-top-half/musl/src/unistd/dup3.c deleted-24
......@@ -1,24 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include <errno.h>
4#include <fcntl.h>
5#include "syscall.h"
6
7int __dup3(int old, int new, int flags)
8{
9 int r;
10#ifdef SYS_dup2
11 if (old==new) return __syscall_ret(-EINVAL);
12 if (flags & O_CLOEXEC) {
13 while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY);
14 if (r!=-ENOSYS) return __syscall_ret(r);
15 }
16 while ((r=__syscall(SYS_dup2, old, new))==-EBUSY);
17 if (flags & O_CLOEXEC) __syscall(SYS_fcntl, new, F_SETFD, FD_CLOEXEC);
18#else
19 while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY);
20#endif
21 return __syscall_ret(r);
22}
23
24weak_alias(__dup3, dup3);
lib/libc/wasi/libc-top-half/musl/src/unistd/faccessat.c deleted-61
......@@ -1,61 +0,0 @@
1#include <unistd.h>
2#include <fcntl.h>
3#include <sys/wait.h>
4#include "syscall.h"
5#include "pthread_impl.h"
6
7struct ctx {
8 int fd;
9 const char *filename;
10 int amode;
11 int p;
12};
13
14static int checker(void *p)
15{
16 struct ctx *c = p;
17 int ret;
18 if (__syscall(SYS_setregid, __syscall(SYS_getegid), -1)
19 || __syscall(SYS_setreuid, __syscall(SYS_geteuid), -1))
20 __syscall(SYS_exit, 1);
21 ret = __syscall(SYS_faccessat, c->fd, c->filename, c->amode, 0);
22 __syscall(SYS_write, c->p, &ret, sizeof ret);
23 return 0;
24}
25
26int faccessat(int fd, const char *filename, int amode, int flag)
27{
28 if (flag) {
29 int ret = __syscall(SYS_faccessat2, fd, filename, amode, flag);
30 if (ret != -ENOSYS) return __syscall_ret(ret);
31 }
32
33 if (flag & ~AT_EACCESS)
34 return __syscall_ret(-EINVAL);
35
36 if (!flag || (getuid()==geteuid() && getgid()==getegid()))
37 return syscall(SYS_faccessat, fd, filename, amode);
38
39 char stack[1024];
40 sigset_t set;
41 pid_t pid;
42 int status;
43 int ret, p[2];
44
45 if (pipe2(p, O_CLOEXEC)) return __syscall_ret(-EBUSY);
46 struct ctx c = { .fd = fd, .filename = filename, .amode = amode, .p = p[1] };
47
48 __block_all_sigs(&set);
49
50 pid = __clone(checker, stack+sizeof stack, 0, &c);
51 __syscall(SYS_close, p[1]);
52
53 if (pid<0 || __syscall(SYS_read, p[0], &ret, sizeof ret) != sizeof(ret))
54 ret = -EBUSY;
55 __syscall(SYS_close, p[0]);
56 __syscall(SYS_wait4, pid, &status, __WCLONE, 0);
57
58 __restore_sigs(&set);
59
60 return __syscall_ret(ret);
61}
lib/libc/wasi/libc-top-half/musl/src/unistd/fchdir.c deleted-15
......@@ -1,15 +0,0 @@
1#include <unistd.h>
2#include <errno.h>
3#include <fcntl.h>
4#include "syscall.h"
5
6int fchdir(int fd)
7{
8 int ret = __syscall(SYS_fchdir, fd);
9 if (ret != -EBADF || __syscall(SYS_fcntl, fd, F_GETFD) < 0)
10 return __syscall_ret(ret);
11
12 char buf[15+3*sizeof(int)];
13 __procfdname(buf, fd);
14 return syscall(SYS_chdir, buf);
15}
lib/libc/wasi/libc-top-half/musl/src/unistd/fchown.c deleted-20
......@@ -1,20 +0,0 @@
1#include <unistd.h>
2#include <errno.h>
3#include <fcntl.h>
4#include "syscall.h"
5
6int fchown(int fd, uid_t uid, gid_t gid)
7{
8 int ret = __syscall(SYS_fchown, fd, uid, gid);
9 if (ret != -EBADF || __syscall(SYS_fcntl, fd, F_GETFD) < 0)
10 return __syscall_ret(ret);
11
12 char buf[15+3*sizeof(int)];
13 __procfdname(buf, fd);
14#ifdef SYS_chown
15 return syscall(SYS_chown, buf, uid, gid);
16#else
17 return syscall(SYS_fchownat, AT_FDCWD, buf, uid, gid, 0);
18#endif
19
20}
lib/libc/wasi/libc-top-half/musl/src/unistd/fchownat.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4int fchownat(int fd, const char *path, uid_t uid, gid_t gid, int flag)
5{
6 return syscall(SYS_fchownat, fd, path, uid, gid, flag);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/fdatasync.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4int fdatasync(int fd)
5{
6 return syscall_cp(SYS_fdatasync, fd);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/fsync.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4int fsync(int fd)
5{
6 return syscall_cp(SYS_fsync, fd);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/ftruncate.c deleted-9
......@@ -1,9 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4int ftruncate(int fd, off_t length)
5{
6 return syscall(SYS_ftruncate, fd, __SYSCALL_LL_O(length));
7}
8
9weak_alias(ftruncate, ftruncate64);
lib/libc/wasi/libc-top-half/musl/src/unistd/getcwd.c deleted-25
......@@ -1,25 +0,0 @@
1#include <unistd.h>
2#include <errno.h>
3#include <limits.h>
4#include <string.h>
5#include "syscall.h"
6
7char *getcwd(char *buf, size_t size)
8{
9 char tmp[buf ? 1 : PATH_MAX];
10 if (!buf) {
11 buf = tmp;
12 size = sizeof tmp;
13 } else if (!size) {
14 errno = EINVAL;
15 return 0;
16 }
17 long ret = syscall(SYS_getcwd, buf, size);
18 if (ret < 0)
19 return 0;
20 if (ret == 0 || buf[0] != '/') {
21 errno = ENOENT;
22 return 0;
23 }
24 return buf == tmp ? strdup(buf) : buf;
25}
lib/libc/wasi/libc-top-half/musl/src/unistd/getegid.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4gid_t getegid(void)
5{
6 return __syscall(SYS_getegid);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/geteuid.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4uid_t geteuid(void)
5{
6 return __syscall(SYS_geteuid);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/getgid.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4gid_t getgid(void)
5{
6 return __syscall(SYS_getgid);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/getgroups.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4int getgroups(int count, gid_t list[])
5{
6 return syscall(SYS_getgroups, count, list);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/gethostname.c deleted-13
......@@ -1,13 +0,0 @@
1#include <unistd.h>
2#include <sys/utsname.h>
3
4int gethostname(char *name, size_t len)
5{
6 size_t i;
7 struct utsname uts;
8 if (uname(&uts)) return -1;
9 if (len > sizeof uts.nodename) len = sizeof uts.nodename;
10 for (i=0; i<len && (name[i] = uts.nodename[i]); i++);
11 if (i && i==len) name[i-1] = 0;
12 return 0;
13}
lib/libc/wasi/libc-top-half/musl/src/unistd/getlogin.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include <stdlib.h>
3
4char *getlogin(void)
5{
6 return getenv("LOGNAME");
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/getlogin_r.c deleted-12
......@@ -1,12 +0,0 @@
1#include <unistd.h>
2#include <string.h>
3#include <errno.h>
4
5int getlogin_r(char *name, size_t size)
6{
7 char *logname = getlogin();
8 if (!logname) return ENXIO; /* or...? */
9 if (strlen(logname) >= size) return ERANGE;
10 strcpy(name, logname);
11 return 0;
12}
lib/libc/wasi/libc-top-half/musl/src/unistd/getpgid.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4pid_t getpgid(pid_t pid)
5{
6 return syscall(SYS_getpgid, pid);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/getpgrp.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4pid_t getpgrp(void)
5{
6 return __syscall(SYS_getpgid, 0);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/getpid.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4pid_t getpid(void)
5{
6 return __syscall(SYS_getpid);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/getppid.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4pid_t getppid(void)
5{
6 return __syscall(SYS_getppid);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/getsid.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4pid_t getsid(pid_t pid)
5{
6 return syscall(SYS_getsid, pid);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/getuid.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4uid_t getuid(void)
5{
6 return __syscall(SYS_getuid);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/isatty.c deleted-13
......@@ -1,13 +0,0 @@
1#include <unistd.h>
2#include <errno.h>
3#include <sys/ioctl.h>
4#include "syscall.h"
5
6int isatty(int fd)
7{
8 struct winsize wsz;
9 unsigned long r = syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz);
10 if (r == 0) return 1;
11 if (errno != EBADF) errno = ENOTTY;
12 return 0;
13}
lib/libc/wasi/libc-top-half/musl/src/unistd/lchown.c deleted-12
......@@ -1,12 +0,0 @@
1#include <unistd.h>
2#include <fcntl.h>
3#include "syscall.h"
4
5int lchown(const char *path, uid_t uid, gid_t gid)
6{
7#ifdef SYS_lchown
8 return syscall(SYS_lchown, path, uid, gid);
9#else
10 return syscall(SYS_fchownat, AT_FDCWD, path, uid, gid, AT_SYMLINK_NOFOLLOW);
11#endif
12}
lib/libc/wasi/libc-top-half/musl/src/unistd/link.c deleted-12
......@@ -1,12 +0,0 @@
1#include <unistd.h>
2#include <fcntl.h>
3#include "syscall.h"
4
5int link(const char *existing, const char *new)
6{
7#ifdef SYS_link
8 return syscall(SYS_link, existing, new);
9#else
10 return syscall(SYS_linkat, AT_FDCWD, existing, AT_FDCWD, new, 0);
11#endif
12}
lib/libc/wasi/libc-top-half/musl/src/unistd/linkat.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4int linkat(int fd1, const char *existing, int fd2, const char *new, int flag)
5{
6 return syscall(SYS_linkat, fd1, existing, fd2, new, flag);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/lseek.c deleted-23
......@@ -1,23 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4off_t __lseek(int fd, off_t offset, int whence)
5{
6#ifdef SYS__llseek
7 off_t result;
8#ifdef __wasilibc_unmodified_upstream // WASI has no syscall
9 return syscall(SYS__llseek, fd, offset>>32, offset, &result, whence) ? -1 : result;
10#else
11 return llseek(fd, offset>>32, offset, &result, whence) ? -1 : result;
12#endif
13#else
14#ifdef __wasilibc_unmodified_upstream // WASI has no syscall
15 return syscall(SYS_lseek, fd, offset, whence);
16#else
17 return lseek(fd, offset, whence);
18#endif
19#endif
20}
21
22weak_alias(__lseek, lseek);
23weak_alias(__lseek, lseek64);
lib/libc/wasi/libc-top-half/musl/src/unistd/mips/pipe.s deleted-20
......@@ -1,20 +0,0 @@
1.set noreorder
2
3.global pipe
4.type pipe,@function
5pipe:
6 lui $gp, %hi(_gp_disp)
7 addiu $gp, %lo(_gp_disp)
8 addu $gp, $gp, $25
9 li $2, 4042
10 syscall
11 beq $7, $0, 1f
12 nop
13 lw $25, %call16(__syscall_ret)($gp)
14 jr $25
15 subu $4, $0, $2
161: sw $2, 0($4)
17 sw $3, 4($4)
18 move $2, $0
19 jr $ra
20 nop
lib/libc/wasi/libc-top-half/musl/src/unistd/mips64/pipe.s deleted-19
......@@ -1,19 +0,0 @@
1.set noreorder
2.global pipe
3.type pipe,@function
4pipe:
5 lui $3, %hi(%neg(%gp_rel(pipe)))
6 daddiu $3, $3, %lo(%neg(%gp_rel(pipe)))
7 daddu $3, $3, $25
8 li $2, 5021
9 syscall
10 beq $7, $0, 1f
11 nop
12 ld $25, %got_disp(__syscall_ret)($3)
13 jr $25
14 dsubu $4, $0, $2
151: sw $2, 0($4)
16 sw $3, 4($4)
17 move $2, $0
18 jr $ra
19 nop
lib/libc/wasi/libc-top-half/musl/src/unistd/mipsn32/lseek.c deleted-20
......@@ -1,20 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4off_t __lseek(int fd, off_t offset, int whence)
5{
6 register long long r4 __asm__("$4") = fd;
7 register long long r5 __asm__("$5") = offset;
8 register long long r6 __asm__("$6") = whence;
9 register long long r7 __asm__("$7");
10 register long long r2 __asm__("$2") = SYS_lseek;
11 __asm__ __volatile__ (
12 "syscall"
13 : "+&r"(r2), "=r"(r7)
14 : "r"(r4), "r"(r5), "r"(r6)
15 : SYSCALL_CLOBBERLIST);
16 return r7 ? __syscall_ret(-r2) : r2;
17}
18
19weak_alias(__lseek, lseek);
20weak_alias(__lseek, lseek64);
lib/libc/wasi/libc-top-half/musl/src/unistd/mipsn32/pipe.s deleted-19
......@@ -1,19 +0,0 @@
1.set noreorder
2.global pipe
3.type pipe,@function
4pipe:
5 lui $3, %hi(%neg(%gp_rel(pipe)))
6 addiu $3, $3, %lo(%neg(%gp_rel(pipe)))
7 addu $3, $3, $25
8 li $2, 6021
9 syscall
10 beq $7, $0, 1f
11 nop
12 lw $25, %got_disp(__syscall_ret)($3)
13 jr $25
14 subu $4, $0, $2
151: sw $2, 0($4)
16 sw $3, 4($4)
17 move $2, $0
18 jr $ra
19 nop
lib/libc/wasi/libc-top-half/musl/src/unistd/nice.c deleted-23
......@@ -1,23 +0,0 @@
1#include <unistd.h>
2#include <errno.h>
3#include <sys/resource.h>
4#include <limits.h>
5#include "syscall.h"
6
7int nice(int inc)
8{
9 int prio = inc;
10 // Only query old priority if it can affect the result.
11 // This also avoids issues with integer overflow.
12 if (inc > -2*NZERO && inc < 2*NZERO)
13 prio += getpriority(PRIO_PROCESS, 0);
14 if (prio > NZERO-1) prio = NZERO-1;
15 if (prio < -NZERO) prio = -NZERO;
16 if (setpriority(PRIO_PROCESS, 0, prio)) {
17 if (errno == EACCES)
18 errno = EPERM;
19 return -1;
20 } else {
21 return prio;
22 }
23}
lib/libc/wasi/libc-top-half/musl/src/unistd/pause.c deleted-11
......@@ -1,11 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4int pause(void)
5{
6#ifdef SYS_pause
7 return syscall_cp(SYS_pause);
8#else
9 return syscall_cp(SYS_ppoll, 0, 0, 0, 0);
10#endif
11}
lib/libc/wasi/libc-top-half/musl/src/unistd/pipe.c deleted-11
......@@ -1,11 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4int pipe(int fd[2])
5{
6#ifdef SYS_pipe
7 return syscall(SYS_pipe, fd);
8#else
9 return syscall(SYS_pipe2, fd, 0);
10#endif
11}
lib/libc/wasi/libc-top-half/musl/src/unistd/pipe2.c deleted-22
......@@ -1,22 +0,0 @@
1#include <unistd.h>
2#include <errno.h>
3#include <fcntl.h>
4#include "syscall.h"
5
6int pipe2(int fd[2], int flag)
7{
8 if (!flag) return pipe(fd);
9 int ret = __syscall(SYS_pipe2, fd, flag);
10 if (ret != -ENOSYS) return __syscall_ret(ret);
11 ret = pipe(fd);
12 if (ret) return ret;
13 if (flag & O_CLOEXEC) {
14 __syscall(SYS_fcntl, fd[0], F_SETFD, FD_CLOEXEC);
15 __syscall(SYS_fcntl, fd[1], F_SETFD, FD_CLOEXEC);
16 }
17 if (flag & O_NONBLOCK) {
18 __syscall(SYS_fcntl, fd[0], F_SETFL, O_NONBLOCK);
19 __syscall(SYS_fcntl, fd[1], F_SETFL, O_NONBLOCK);
20 }
21 return 0;
22}
lib/libc/wasi/libc-top-half/musl/src/unistd/pread.c deleted-9
......@@ -1,9 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4ssize_t pread(int fd, void *buf, size_t size, off_t ofs)
5{
6 return syscall_cp(SYS_pread, fd, buf, size, __SYSCALL_LL_PRW(ofs));
7}
8
9weak_alias(pread, pread64);
lib/libc/wasi/libc-top-half/musl/src/unistd/preadv.c deleted-12
......@@ -1,12 +0,0 @@
1#define _BSD_SOURCE
2#include <sys/uio.h>
3#include <unistd.h>
4#include "syscall.h"
5
6ssize_t preadv(int fd, const struct iovec *iov, int count, off_t ofs)
7{
8 return syscall_cp(SYS_preadv, fd, iov, count,
9 (long)(ofs), (long)(ofs>>32));
10}
11
12weak_alias(preadv, preadv64);
lib/libc/wasi/libc-top-half/musl/src/unistd/pwrite.c deleted-9
......@@ -1,9 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs)
5{
6 return syscall_cp(SYS_pwrite, fd, buf, size, __SYSCALL_LL_PRW(ofs));
7}
8
9weak_alias(pwrite, pwrite64);
lib/libc/wasi/libc-top-half/musl/src/unistd/pwritev.c deleted-12
......@@ -1,12 +0,0 @@
1#define _BSD_SOURCE
2#include <sys/uio.h>
3#include <unistd.h>
4#include "syscall.h"
5
6ssize_t pwritev(int fd, const struct iovec *iov, int count, off_t ofs)
7{
8 return syscall_cp(SYS_pwritev, fd, iov, count,
9 (long)(ofs), (long)(ofs>>32));
10}
11
12weak_alias(pwritev, pwritev64);
lib/libc/wasi/libc-top-half/musl/src/unistd/read.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4ssize_t read(int fd, void *buf, size_t count)
5{
6 return syscall_cp(SYS_read, fd, buf, count);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/readlink.c deleted-19
......@@ -1,19 +0,0 @@
1#include <unistd.h>
2#include <fcntl.h>
3#include "syscall.h"
4
5ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize)
6{
7 char dummy[1];
8 if (!bufsize) {
9 buf = dummy;
10 bufsize = 1;
11 }
12#ifdef SYS_readlink
13 int r = __syscall(SYS_readlink, path, buf, bufsize);
14#else
15 int r = __syscall(SYS_readlinkat, AT_FDCWD, path, buf, bufsize);
16#endif
17 if (buf == dummy && r > 0) r = 0;
18 return __syscall_ret(r);
19}
lib/libc/wasi/libc-top-half/musl/src/unistd/readlinkat.c deleted-14
......@@ -1,14 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize)
5{
6 char dummy[1];
7 if (!bufsize) {
8 buf = dummy;
9 bufsize = 1;
10 }
11 int r = __syscall(SYS_readlinkat, fd, path, buf, bufsize);
12 if (buf == dummy && r > 0) r = 0;
13 return __syscall_ret(r);
14}
lib/libc/wasi/libc-top-half/musl/src/unistd/readv.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/uio.h>
2#include "syscall.h"
3
4ssize_t readv(int fd, const struct iovec *iov, int count)
5{
6 return syscall_cp(SYS_readv, fd, iov, count);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/renameat.c deleted-11
......@@ -1,11 +0,0 @@
1#include <stdio.h>
2#include "syscall.h"
3
4int renameat(int oldfd, const char *old, int newfd, const char *new)
5{
6#ifdef SYS_renameat
7 return syscall(SYS_renameat, oldfd, old, newfd, new);
8#else
9 return syscall(SYS_renameat2, oldfd, old, newfd, new, 0);
10#endif
11}
lib/libc/wasi/libc-top-half/musl/src/unistd/rmdir.c deleted-12
......@@ -1,12 +0,0 @@
1#include <unistd.h>
2#include <fcntl.h>
3#include "syscall.h"
4
5int rmdir(const char *path)
6{
7#ifdef SYS_rmdir
8 return syscall(SYS_rmdir, path);
9#else
10 return syscall(SYS_unlinkat, AT_FDCWD, path, AT_REMOVEDIR);
11#endif
12}
lib/libc/wasi/libc-top-half/musl/src/unistd/setegid.c deleted-8
......@@ -1,8 +0,0 @@
1#include <unistd.h>
2#include "libc.h"
3#include "syscall.h"
4
5int setegid(gid_t egid)
6{
7 return __setxid(SYS_setresgid, -1, egid, -1);
8}
lib/libc/wasi/libc-top-half/musl/src/unistd/seteuid.c deleted-8
......@@ -1,8 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3#include "libc.h"
4
5int seteuid(uid_t euid)
6{
7 return __setxid(SYS_setresuid, -1, euid, -1);
8}
lib/libc/wasi/libc-top-half/musl/src/unistd/setgid.c deleted-8
......@@ -1,8 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3#include "libc.h"
4
5int setgid(gid_t gid)
6{
7 return __setxid(SYS_setgid, gid, 0, 0);
8}
lib/libc/wasi/libc-top-half/musl/src/unistd/setpgid.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4int setpgid(pid_t pid, pid_t pgid)
5{
6 return syscall(SYS_setpgid, pid, pgid);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/setpgrp.c deleted-6
......@@ -1,6 +0,0 @@
1#include <unistd.h>
2
3pid_t setpgrp(void)
4{
5 return setpgid(0, 0);
6}
lib/libc/wasi/libc-top-half/musl/src/unistd/setregid.c deleted-8
......@@ -1,8 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3#include "libc.h"
4
5int setregid(gid_t rgid, gid_t egid)
6{
7 return __setxid(SYS_setregid, rgid, egid, 0);
8}
lib/libc/wasi/libc-top-half/musl/src/unistd/setresgid.c deleted-9
......@@ -1,9 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include "syscall.h"
4#include "libc.h"
5
6int setresgid(gid_t rgid, gid_t egid, gid_t sgid)
7{
8 return __setxid(SYS_setresgid, rgid, egid, sgid);
9}
lib/libc/wasi/libc-top-half/musl/src/unistd/setresuid.c deleted-9
......@@ -1,9 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include "syscall.h"
4#include "libc.h"
5
6int setresuid(uid_t ruid, uid_t euid, uid_t suid)
7{
8 return __setxid(SYS_setresuid, ruid, euid, suid);
9}
lib/libc/wasi/libc-top-half/musl/src/unistd/setreuid.c deleted-8
......@@ -1,8 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3#include "libc.h"
4
5int setreuid(uid_t ruid, uid_t euid)
6{
7 return __setxid(SYS_setreuid, ruid, euid, 0);
8}
lib/libc/wasi/libc-top-half/musl/src/unistd/setsid.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4pid_t setsid(void)
5{
6 return syscall(SYS_setsid);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/setuid.c deleted-8
......@@ -1,8 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3#include "libc.h"
4
5int setuid(uid_t uid)
6{
7 return __setxid(SYS_setuid, uid, 0, 0);
8}
lib/libc/wasi/libc-top-half/musl/src/unistd/setxid.c deleted-34
......@@ -1,34 +0,0 @@
1#include <unistd.h>
2#include <signal.h>
3#include "syscall.h"
4#include "libc.h"
5
6struct ctx {
7 int id, eid, sid;
8 int nr, ret;
9};
10
11static void do_setxid(void *p)
12{
13 struct ctx *c = p;
14 if (c->ret<0) return;
15 int ret = __syscall(c->nr, c->id, c->eid, c->sid);
16 if (ret && !c->ret) {
17 /* If one thread fails to set ids after another has already
18 * succeeded, forcibly killing the process is the only safe
19 * thing to do. State is inconsistent and dangerous. Use
20 * SIGKILL because it is uncatchable. */
21 __block_all_sigs(0);
22 __syscall(SYS_kill, __syscall(SYS_getpid), SIGKILL);
23 }
24 c->ret = ret;
25}
26
27int __setxid(int nr, int id, int eid, int sid)
28{
29 /* ret is initially nonzero so that failure of the first thread does not
30 * trigger the safety kill above. */
31 struct ctx c = { .nr = nr, .id = id, .eid = eid, .sid = sid, .ret = 1 };
32 __synccall(do_setxid, &c);
33 return __syscall_ret(c.ret);
34}
lib/libc/wasi/libc-top-half/musl/src/unistd/sh/pipe.s deleted-27
......@@ -1,27 +0,0 @@
1.global pipe
2.type pipe, @function
3pipe:
4 mov #42, r3
5 trapa #31
6
7 ! work around hardware bug
8 or r0, r0
9 or r0, r0
10 or r0, r0
11 or r0, r0
12 or r0, r0
13
14 cmp/pz r0
15 bt 1f
16
17 mov.l L1, r1
18 braf r1
19 mov r0, r4
20
211: mov.l r0, @(0,r4)
22 mov.l r1, @(4,r4)
23 rts
24 mov #0, r0
25
26.align 2
27L1: .long __syscall_ret@PLT-(1b-.)
lib/libc/wasi/libc-top-half/musl/src/unistd/sleep.c deleted-10
......@@ -1,10 +0,0 @@
1#include <unistd.h>
2#include <time.h>
3
4unsigned sleep(unsigned seconds)
5{
6 struct timespec tv = { .tv_sec = seconds, .tv_nsec = 0 };
7 if (nanosleep(&tv, &tv))
8 return tv.tv_sec;
9 return 0;
10}
lib/libc/wasi/libc-top-half/musl/src/unistd/symlink.c deleted-12
......@@ -1,12 +0,0 @@
1#include <unistd.h>
2#include <fcntl.h>
3#include "syscall.h"
4
5int symlink(const char *existing, const char *new)
6{
7#ifdef SYS_symlink
8 return syscall(SYS_symlink, existing, new);
9#else
10 return syscall(SYS_symlinkat, existing, AT_FDCWD, new);
11#endif
12}
lib/libc/wasi/libc-top-half/musl/src/unistd/symlinkat.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4int symlinkat(const char *existing, int fd, const char *new)
5{
6 return syscall(SYS_symlinkat, existing, fd, new);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/sync.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4void sync(void)
5{
6 __syscall(SYS_sync);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/tcgetpgrp.c deleted-11
......@@ -1,11 +0,0 @@
1#include <unistd.h>
2#include <termios.h>
3#include <sys/ioctl.h>
4
5pid_t tcgetpgrp(int fd)
6{
7 int pgrp;
8 if (ioctl(fd, TIOCGPGRP, &pgrp) < 0)
9 return -1;
10 return pgrp;
11}
lib/libc/wasi/libc-top-half/musl/src/unistd/tcsetpgrp.c deleted-9
......@@ -1,9 +0,0 @@
1#include <unistd.h>
2#include <termios.h>
3#include <sys/ioctl.h>
4
5int tcsetpgrp(int fd, pid_t pgrp)
6{
7 int pgrp_int = pgrp;
8 return ioctl(fd, TIOCSPGRP, &pgrp_int);
9}
lib/libc/wasi/libc-top-half/musl/src/unistd/truncate.c deleted-9
......@@ -1,9 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4int truncate(const char *path, off_t length)
5{
6 return syscall(SYS_truncate, path, __SYSCALL_LL_O(length));
7}
8
9weak_alias(truncate, truncate64);
lib/libc/wasi/libc-top-half/musl/src/unistd/ttyname.c deleted-14
......@@ -1,14 +0,0 @@
1#include <unistd.h>
2#include <errno.h>
3#include <limits.h>
4
5char *ttyname(int fd)
6{
7 static char buf[TTY_NAME_MAX];
8 int result;
9 if ((result = ttyname_r(fd, buf, sizeof buf))) {
10 errno = result;
11 return NULL;
12 }
13 return buf;
14}
lib/libc/wasi/libc-top-half/musl/src/unistd/ttyname_r.c deleted-28
......@@ -1,28 +0,0 @@
1#include <unistd.h>
2#include <errno.h>
3#include <sys/stat.h>
4#include "syscall.h"
5
6int ttyname_r(int fd, char *name, size_t size)
7{
8 struct stat st1, st2;
9 char procname[sizeof "/proc/self/fd/" + 3*sizeof(int) + 2];
10 ssize_t l;
11
12 if (!isatty(fd)) return errno;
13
14 __procfdname(procname, fd);
15 l = readlink(procname, name, size);
16
17 if (l < 0) return errno;
18 else if (l == size) return ERANGE;
19
20 name[l] = 0;
21
22 if (stat(name, &st1) || fstat(fd, &st2))
23 return errno;
24 if (st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino)
25 return ENODEV;
26
27 return 0;
28}
lib/libc/wasi/libc-top-half/musl/src/unistd/ualarm.c deleted-13
......@@ -1,13 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include <sys/time.h>
4
5unsigned ualarm(unsigned value, unsigned interval)
6{
7 struct itimerval it = {
8 .it_interval.tv_usec = interval,
9 .it_value.tv_usec = value
10 }, it_old;
11 setitimer(ITIMER_REAL, &it, &it_old);
12 return it_old.it_value.tv_sec*1000000 + it_old.it_value.tv_usec;
13}
lib/libc/wasi/libc-top-half/musl/src/unistd/unlink.c deleted-12
......@@ -1,12 +0,0 @@
1#include <unistd.h>
2#include <fcntl.h>
3#include "syscall.h"
4
5int unlink(const char *path)
6{
7#ifdef SYS_unlink
8 return syscall(SYS_unlink, path);
9#else
10 return syscall(SYS_unlinkat, AT_FDCWD, path, 0);
11#endif
12}
lib/libc/wasi/libc-top-half/musl/src/unistd/unlinkat.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4int unlinkat(int fd, const char *path, int flag)
5{
6 return syscall(SYS_unlinkat, fd, path, flag);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/usleep.c deleted-12
......@@ -1,12 +0,0 @@
1#define _GNU_SOURCE
2#include <unistd.h>
3#include <time.h>
4
5int usleep(unsigned useconds)
6{
7 struct timespec tv = {
8 .tv_sec = useconds/1000000,
9 .tv_nsec = (useconds%1000000)*1000
10 };
11 return nanosleep(&tv, &tv);
12}
lib/libc/wasi/libc-top-half/musl/src/unistd/write.c deleted-7
......@@ -1,7 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4ssize_t write(int fd, const void *buf, size_t count)
5{
6 return syscall_cp(SYS_write, fd, buf, count);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/writev.c deleted-7
......@@ -1,7 +0,0 @@
1#include <sys/uio.h>
2#include "syscall.h"
3
4ssize_t writev(int fd, const struct iovec *iov, int count)
5{
6 return syscall_cp(SYS_writev, fd, iov, count);
7}
lib/libc/wasi/libc-top-half/musl/src/unistd/x32/lseek.c deleted-15
......@@ -1,15 +0,0 @@
1#include <unistd.h>
2#include "syscall.h"
3
4off_t __lseek(int fd, off_t offset, int whence)
5{
6 off_t ret;
7 __asm__ __volatile__ ("syscall"
8 : "=a"(ret)
9 : "a"(SYS_lseek), "D"(fd), "S"(offset), "d"(whence)
10 : "rcx", "r11", "memory");
11 return ret < 0 ? __syscall_ret(ret) : ret;
12}
13
14weak_alias(__lseek, lseek);
15weak_alias(__lseek, lseek64);
src/wasi_libc.zig+1
......@@ -459,6 +459,7 @@ const libc_bottom_half_src_files = [_][]const u8{
459459 "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c",
460460 "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c",
461461 "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/write.c",
462 "wasi/libc-bottom-half/sources/__errno_location.c",
462463 "wasi/libc-bottom-half/sources/__main_void.c",
463464 "wasi/libc-bottom-half/sources/__wasilibc_dt.c",
464465 "wasi/libc-bottom-half/sources/__wasilibc_environ.c",