@ecmaos-apps/make-src 0.0.0-stage → 4.4.1-ecmaos.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/README.md +8 -2
  2. package/build/build.sh +45 -0
  3. package/package.json +35 -4
  4. package/share/licenses/make/COPYING +674 -0
  5. package/share/licenses/make/SOURCE +24 -0
  6. package/sources/make-4.4.1.tar.gz +0 -0
  7. package/toolchain/emscripten-version +1 -0
  8. package/toolchain/rust-wali-version +3 -0
  9. package/toolchain/wali/asyncify-reach.mjs +107 -0
  10. package/toolchain/wali/asyncify.sh +57 -0
  11. package/toolchain/wali/build-sysroot.sh +158 -0
  12. package/toolchain/wali/patches/compiler-rt/0001-wasm-compare-result.patch +18 -0
  13. package/toolchain/wali/patches/musl/0001-environment-through-imports.patch +143 -0
  14. package/toolchain/wali/patches/musl/0002-setjmp-with-wasm-exceptions.patch +133 -0
  15. package/toolchain/wali/patches/musl/0003-unknown-syscall-is-enosys.patch +31 -0
  16. package/toolchain/wali/patches/musl/0004-return-from-main-is-exit.patch +53 -0
  17. package/toolchain/wali/patches/musl/0005-posix-spawn-through-the-host.patch +278 -0
  18. package/toolchain/wali/patches/musl/0006-detached-thread-frees-its-stack.patch +34 -0
  19. package/toolchain/wali/patches/musl/0007-wordexp-without-fork.patch +62 -0
  20. package/toolchain/wali/patches/musl/0008-progname-from-argv.patch +34 -0
  21. package/toolchain/wali/patches/musl/0009-no-basename-in-string-h.patch +15 -0
  22. package/toolchain/wali/patches/musl/0010-ssize-max-is-pointer-sized.patch +15 -0
  23. package/toolchain/wali/patches/musl/0011-startup-without-malloc.patch +85 -0
  24. package/toolchain/wali/patches/musl/0012-floatscan-fixes-from-musl.patch +39 -0
  25. package/toolchain/wali/patches/musl/0013-strptime-from-musl-with-glibc-s-and-z.patch +169 -0
  26. package/toolchain/wali/patches/musl/0014-wordexp-fixes-from-musl.patch +43 -0
  27. package/toolchain/wali/patches/musl/0015-long-double-is-ieee-quad.patch +202 -0
  28. package/toolchain/wali/patches/musl/0016-wordexp-nocmd-and-undef.patch +285 -0
  29. package/toolchain/wali/rust.sh +116 -0
  30. package/toolchain/wali/signal-checks.mjs +373 -0
  31. package/toolchain/wali-version +13 -0
@@ -0,0 +1,31 @@
1
+ ecmaOS: syscall() with a number this port has no import for fails with ENOSYS and says nothing, as Linux does.
2
+ It printed a line on standard output, into whatever the program was writing there.
3
+
4
+ diff --git i/arch/wasm32/syscall_var.h w/arch/wasm32/syscall_var.h
5
+ index 22d8816..e69d1bc 100644
6
+ --- i/arch/wasm32/syscall_var.h
7
+ +++ w/arch/wasm32/syscall_var.h
8
+ @@ -149,10 +149,8 @@ static long __syscall_vargs(long n, va_list ap) {
9
+ CASE_SYSCALL (getrandom, va_arg(ap, void*),va_arg(ap, unsigned int),va_arg(ap, int));
10
+ CASE_SYSCALL (statx, va_arg(ap, int),va_arg(ap, void*),va_arg(ap, int),va_arg(ap, unsigned int),va_arg(ap, void*));
11
+ CASE_SYSCALL (faccessat2, va_arg(ap, int),va_arg(ap, void*),va_arg(ap, int),va_arg(ap, int));
12
+ - default: {
13
+ - printf("Invalid syscall var call -- NR %d\n", n);
14
+ + default:
15
+ return -ENOSYS;
16
+ - }
17
+ }
18
+ }
19
+
20
+ @@ -300,10 +298,8 @@ static long __syscall_var(long n, long a1, long a2, long a3, long a4, long a5, l
21
+ CASE_SYSCALL (getrandom, (void*)a1,(unsigned int)a2,(int)a3);
22
+ CASE_SYSCALL (statx, (int)a1,(char*)a2,(int)a3,(unsigned int)a4,(void*)a5);
23
+ CASE_SYSCALL (faccessat2, (int)a1,(char*)a2,(int)a3,(int)a4);
24
+ - default: {
25
+ - printf("Invalid syscall var call -- NR %d\n", n);
26
+ + default:
27
+ return -ENOSYS;
28
+ - }
29
+ }
30
+ }
31
+
@@ -0,0 +1,53 @@
1
+ ecmaOS: returning from main is exit() with its value, as C requires: atexit handlers, static destructors and the
2
+ stdio flush run. WALI's _start called the host's __proc_exit directly, so output still in a buffer was lost.
3
+
4
+ diff --git i/crt/crt1-command.c w/crt/crt1-command.c
5
+ index 86ea440..0f1b9a8 100644
6
+ --- i/crt/crt1-command.c
7
+ +++ w/crt/crt1-command.c
8
+ @@ -1,3 +1,5 @@
9
+ +#include <stdlib.h>
10
+ +
11
+ extern int __main_void(void);
12
+ extern int __wali_startup(void);
13
+ extern int __wali_cleanup(void);
14
+ @@ -7,26 +9,19 @@ void __wali_proc_exit(int) __attribute((
15
+ __import_name__("__proc_exit")
16
+ ));
17
+
18
+ +/* ecmaOS: returning from main is exit() with its value, so atexit handlers, destructors and the stdio flush run
19
+ + * (WALI's _start called __proc_exit directly, and output still in a buffer was lost). The engine's cleanup runs as
20
+ + * the first handler registered, so last. */
21
+ +static void cleanup(void) {
22
+ + __wali_cleanup();
23
+ +}
24
+ +
25
+ __attribute__((export_name("_start")))
26
+ void _start(void) {
27
+ - // Return code for exit
28
+ - int r;
29
+ - r = __wali_startup();
30
+ - if (r) {
31
+ - goto exit_label;
32
+ - }
33
+ - // Call `__main_void` which will either be the application's zero-argument
34
+ - // `__main_void` function or a libc routine which obtains the command-line
35
+ - // arguments and calls `__main_argv_argc`.
36
+ - r = __main_void();
37
+ - if (r) {
38
+ - goto exit_label;
39
+ - }
40
+ - int s = __wali_cleanup();
41
+ - if (s) {
42
+ - // Update the reutrn code with cleanup's error, if it has one
43
+ - r = s;
44
+ - }
45
+ -exit_label:
46
+ - __wali_proc_exit(r);
47
+ + int r = __wali_startup();
48
+ + if (r) __wali_proc_exit(r);
49
+ + atexit(cleanup);
50
+ + // `__main_void` is the application's zero-argument main, or a libc routine that gathers the command-line
51
+ + // arguments and calls `__main_argc_argv`
52
+ + exit(__main_void());
53
+ }
@@ -0,0 +1,278 @@
1
+ ecmaOS: posix_spawn hands the whole request to the host (__ecmaos_spawn), which starts the child as a new process:
2
+ there is no fork to run musl's child code in. File actions keep their order; posix_spawnp searches PATH first.
3
+
4
+ diff --git i/src/process/posix_spawn.c w/src/process/posix_spawn.c
5
+ index 69f1728..e656ee8 100644
6
+ --- i/src/process/posix_spawn.c
7
+ +++ w/src/process/posix_spawn.c
8
+ @@ -1,214 +1,79 @@
9
+ +/* ecmaOS: there is no fork here, so the child is not this process run on another stack (musl's __clone with
10
+ + * CLONE_VFORK) but a new process the host starts: the file actions, flags and signal sets are handed over whole, in
11
+ + * the order the file actions were added, and the host replays them against a copy of this process's descriptor table
12
+ + * (core/kernel/src/bin/wali-host.mjs). posix_spawnp searches PATH here, as execvpe would in the child. */
13
+ #define _GNU_SOURCE
14
+ #include <spawn.h>
15
+ -#include <sched.h>
16
+ -#include <unistd.h>
17
+ +#include <errno.h>
18
+ +#include <limits.h>
19
+ #include <signal.h>
20
+ -#include <fcntl.h>
21
+ -#include <sys/wait.h>
22
+ -#include "syscall.h"
23
+ -#include "lock.h"
24
+ -#include "pthread_impl.h"
25
+ +#include <stdlib.h>
26
+ +#include <string.h>
27
+ +#include <unistd.h>
28
+ #include "fdop.h"
29
+
30
+ -struct args {
31
+ - int p[2];
32
+ - sigset_t oldmask;
33
+ +/* One file action: its FDOP_* command and operands. 24 bytes, read by the host. */
34
+ +struct spawn_op {
35
+ + int cmd, fd, srcfd, oflag, mode;
36
+ const char *path;
37
+ - const posix_spawn_file_actions_t *fa;
38
+ - const posix_spawnattr_t *restrict attr;
39
+ - char *const *argv, *const *envp;
40
+ };
41
+
42
+ -static int __sys_dup2(int old, int new)
43
+ +long __ecmaos_spawn(const char *, char *const *, char *const *, const struct spawn_op *, int, int, int,
44
+ + const sigset_t *, const sigset_t *) __attribute__((__import_module__("wali"), __import_name__("__ecmaos_spawn")));
45
+ +
46
+ +extern char **__environ;
47
+ +
48
+ +/* The file posix_spawnp's search finds for `file`: the first entry of PATH it is executable in */
49
+ +static int search(const char *file, char *buf)
50
+ {
51
+ -#ifdef SYS_dup2
52
+ - return __syscall_SYS_dup2(old, new);
53
+ -#else
54
+ - return __syscall_SYS_dup3(old, new, 0);
55
+ -#endif
56
+ -}
57
+ -
58
+ -static int child(void *args_vp)
59
+ -{
60
+ - int i, ret;
61
+ - struct sigaction sa = {0};
62
+ - struct args *args = args_vp;
63
+ - int p = args->p[1];
64
+ - const posix_spawn_file_actions_t *fa = args->fa;
65
+ - const posix_spawnattr_t *restrict attr = args->attr;
66
+ - sigset_t hset;
67
+ -
68
+ - close(args->p[0]);
69
+ -
70
+ - /* All signal dispositions must be either SIG_DFL or SIG_IGN
71
+ - * before signals are unblocked. Otherwise a signal handler
72
+ - * from the parent might get run in the child while sharing
73
+ - * memory, with unpredictable and dangerous results. To
74
+ - * reduce overhead, sigaction has tracked for us which signals
75
+ - * potentially have a signal handler. */
76
+ - __get_handler_set(&hset);
77
+ - for (i=1; i<_NSIG; i++) {
78
+ - if ((attr->__flags & POSIX_SPAWN_SETSIGDEF)
79
+ - && sigismember(&attr->__def, i)) {
80
+ - sa.sa_handler = SIG_DFL;
81
+ - } else if (sigismember(&hset, i)) {
82
+ - if (i-32<3U) {
83
+ - sa.sa_handler = SIG_IGN;
84
+ - } else {
85
+ - __libc_sigaction(i, 0, &sa);
86
+ - if (sa.sa_handler==SIG_IGN) continue;
87
+ - sa.sa_handler = SIG_DFL;
88
+ - }
89
+ - } else {
90
+ - continue;
91
+ + const char *path = getenv("PATH");
92
+ + size_t length = strnlen(file, NAME_MAX+1);
93
+ + int denied = 0;
94
+ + if (!path) path = "/usr/local/bin:/bin:/usr/bin";
95
+ + if (length > NAME_MAX) return ENAMETOOLONG;
96
+ + for (const char *p = path, *z; ; p = z + 1) {
97
+ + z = strchrnul(p, ':');
98
+ + size_t dir = z - p;
99
+ + if (dir + length + 2 <= PATH_MAX) {
100
+ + memcpy(buf, p, dir);
101
+ + buf[dir] = '/';
102
+ + memcpy(buf + dir + (dir > 0), file, length + 1);
103
+ + if (!access(buf, X_OK)) return 0;
104
+ + if (errno == EACCES) denied = 1;
105
+ }
106
+ - __libc_sigaction(i, &sa, 0);
107
+ + if (!*z) break;
108
+ }
109
+ -
110
+ - if (attr->__flags & POSIX_SPAWN_SETSID)
111
+ - if ((ret=__syscall_SYS_setsid()) < 0)
112
+ - goto fail;
113
+ -
114
+ - if (attr->__flags & POSIX_SPAWN_SETPGROUP)
115
+ - if ((ret=__syscall_SYS_setpgid(0, attr->__pgrp)))
116
+ - goto fail;
117
+ -
118
+ - /* Use syscalls directly because the library functions attempt
119
+ - * to do a multi-threaded synchronized id-change, which would
120
+ - * trash the parent's state. */
121
+ - if (attr->__flags & POSIX_SPAWN_RESETIDS)
122
+ - if ((ret=__syscall_SYS_setgid(__syscall_SYS_getgid())) ||
123
+ - (ret=__syscall_SYS_setuid(__syscall_SYS_getuid())) )
124
+ - goto fail;
125
+ -
126
+ - if (fa && fa->__actions) {
127
+ - struct fdop *op;
128
+ - int fd;
129
+ - for (op = fa->__actions; op->next; op = op->next);
130
+ - for (; op; op = op->prev) {
131
+ - /* It's possible that a file operation would clobber
132
+ - * the pipe fd used for synchronizing with the
133
+ - * parent. To avoid that, we dup the pipe onto
134
+ - * an unoccupied fd. */
135
+ - if (op->fd == p) {
136
+ - ret = __syscall_SYS_dup(p);
137
+ - if (ret < 0) goto fail;
138
+ - __syscall_SYS_close(p);
139
+ - p = ret;
140
+ - }
141
+ - switch(op->cmd) {
142
+ - case FDOP_CLOSE:
143
+ - __syscall_SYS_close(op->fd);
144
+ - break;
145
+ - case FDOP_DUP2:
146
+ - fd = op->srcfd;
147
+ - if (fd == p) {
148
+ - ret = -EBADF;
149
+ - goto fail;
150
+ - }
151
+ - if (fd != op->fd) {
152
+ - if ((ret=__sys_dup2(fd, op->fd))<0)
153
+ - goto fail;
154
+ - } else {
155
+ - ret = __syscall_SYS_fcntl(fd, F_GETFD, 0);
156
+ - ret = __syscall_SYS_fcntl(fd, F_SETFD,
157
+ - ret & ~FD_CLOEXEC);
158
+ - if (ret<0)
159
+ - goto fail;
160
+ - }
161
+ - break;
162
+ - case FDOP_OPEN:
163
+ - fd = __sys_open(op->path, op->oflag, op->mode);
164
+ - if ((ret=fd) < 0) goto fail;
165
+ - if (fd != op->fd) {
166
+ - if ((ret=__sys_dup2(fd, op->fd))<0)
167
+ - goto fail;
168
+ - __syscall_SYS_close(fd);
169
+ - }
170
+ - break;
171
+ - case FDOP_CHDIR:
172
+ - ret = __syscall_SYS_chdir(op->path);
173
+ - if (ret<0) goto fail;
174
+ - break;
175
+ - case FDOP_FCHDIR:
176
+ - ret = __syscall_SYS_fchdir(op->fd);
177
+ - if (ret<0) goto fail;
178
+ - break;
179
+ - }
180
+ - }
181
+ - }
182
+ -
183
+ - /* Close-on-exec flag may have been lost if we moved the pipe
184
+ - * to a different fd. We don't use F_DUPFD_CLOEXEC above because
185
+ - * it would fail on older kernels and atomicity is not needed --
186
+ - * in this process there are no threads or signal handlers. */
187
+ - __syscall_SYS_fcntl(p, F_SETFD, FD_CLOEXEC);
188
+ -
189
+ - pthread_sigmask(SIG_SETMASK, (attr->__flags & POSIX_SPAWN_SETSIGMASK)
190
+ - ? &attr->__mask : &args->oldmask, 0);
191
+ -
192
+ - int (*exec)(const char *, char *const *, char *const *) =
193
+ - attr->__fn ? (int (*)())attr->__fn : execve;
194
+ -
195
+ - exec(args->path, args->argv, args->envp);
196
+ - ret = -errno;
197
+ -
198
+ -fail:
199
+ - /* Since sizeof errno < PIPE_BUF, the write is atomic. */
200
+ - ret = -ret;
201
+ - if (ret) while (__syscall_SYS_write(p, &ret, sizeof ret) < 0);
202
+ - _exit(127);
203
+ + return denied ? EACCES : ENOENT;
204
+ }
205
+
206
+ -
207
+ int posix_spawn(pid_t *restrict res, const char *restrict path,
208
+ const posix_spawn_file_actions_t *fa,
209
+ const posix_spawnattr_t *restrict attr,
210
+ char *const argv[restrict], char *const envp[restrict])
211
+ {
212
+ - pid_t pid;
213
+ - char stack[1024+PATH_MAX];
214
+ - int ec=0, cs;
215
+ - struct args args;
216
+ + static const posix_spawnattr_t none;
217
+ + const posix_spawnattr_t *a = attr ? attr : &none;
218
+ + char found[PATH_MAX];
219
+ + struct spawn_op *ops = 0;
220
+ + struct fdop *op;
221
+ + int count = 0, ec;
222
+
223
+ - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
224
+ -
225
+ - args.path = path;
226
+ - args.fa = fa;
227
+ - args.attr = attr ? attr : &(const posix_spawnattr_t){0};
228
+ - args.argv = argv;
229
+ - args.envp = envp;
230
+ - pthread_sigmask(SIG_BLOCK, SIGALL_SET, &args.oldmask);
231
+ -
232
+ - /* The lock guards both against seeing a SIGABRT disposition change
233
+ - * by abort and against leaking the pipe fd to fork-without-exec. */
234
+ - LOCK(__abort_lock);
235
+ -
236
+ - if (pipe2(args.p, O_CLOEXEC)) {
237
+ - UNLOCK(__abort_lock);
238
+ - ec = errno;
239
+ - goto fail;
240
+ + if (a->__fn && !strchr(path, '/')) {
241
+ + if (!*path) return ENOENT;
242
+ + if ((ec = search(path, found))) return ec;
243
+ + path = found;
244
+ }
245
+
246
+ - pid = __clone(child, stack+sizeof stack,
247
+ - CLONE_VM|CLONE_VFORK|SIGCHLD, &args);
248
+ - close(args.p[1]);
249
+ - UNLOCK(__abort_lock);
250
+ + /* the list's head is the action added last, and each is applied in the order it was added */
251
+ + if (fa) for (op = fa->__actions; op; op = op->next) count++;
252
+ + if (count && !(ops = malloc(count * sizeof *ops))) return ENOMEM;
253
+ + int i = count;
254
+ + if (fa) for (op = fa->__actions; op; op = op->next)
255
+ + ops[--i] = (struct spawn_op){ op->cmd, op->fd, op->srcfd, op->oflag, op->mode, op->path };
256
+
257
+ - if (pid > 0) {
258
+ - if (read(args.p[0], &ec, sizeof ec) != sizeof ec) ec = 0;
259
+ - else waitpid(pid, &(int){0}, 0);
260
+ - } else {
261
+ - ec = -pid;
262
+ - }
263
+ -
264
+ - close(args.p[0]);
265
+ -
266
+ - if (!ec && res) *res = pid;
267
+ -
268
+ -fail:
269
+ - pthread_sigmask(SIG_SETMASK, &args.oldmask, 0);
270
+ - pthread_setcancelstate(cs, 0);
271
+ -
272
+ - return ec;
273
+ + long pid = __ecmaos_spawn(path, argv, envp ? envp : __environ, ops, count, a->__flags, a->__pgrp, &a->__def, &a->__mask);
274
+ + free(ops);
275
+ + if (pid < 0) return -pid;
276
+ + if (res) *res = pid;
277
+ + return 0;
278
+ }
@@ -0,0 +1,34 @@
1
+ ecmaOS: a detached thread that ends hands its stack mapping to the host, which frees it and ends the thread
2
+ (__ecmaos_unmapself). WALI printed a line to stdout there and kept the stack.
3
+
4
+ --- i/src/internal/pthread_impl.h
5
+ +++ w/src/internal/pthread_impl.h
6
+ @@ -166,6 +166,12 @@
7
+ __import_name__("__wasm_thread_spawn")
8
+ ));
9
+
10
+ +/* ecmaOS: frees a detached thread's stack mapping and ends the thread; it does not return */
11
+ +hidden _Noreturn void __ecmaos_unmapself(void *, size_t) __attribute((
12
+ + __import_module__("wali"),
13
+ + __import_name__("__ecmaos_unmapself")
14
+ +));
15
+ +
16
+ hidden int __set_thread_area(void *) __attribute((
17
+ __import_module__("wali"),
18
+ __import_name__("__set_thread_area")
19
+ --- i/src/thread/pthread_create.c
20
+ +++ w/src/thread/pthread_create.c
21
+ @@ -168,10 +168,9 @@
22
+ if (self->robust_list.off)
23
+ __syscall_SYS_set_robust_list(0, 3*sizeof(long));
24
+
25
+ - printf("== Detached Thread End: unmapself TBD\n");
26
+ - /* The following call unmaps the thread's stack mapping
27
+ - * and then exits without touching the stack. */
28
+ - //__unmapself(self->map_base, self->map_size);
29
+ + /* ecmaOS: the host frees the thread's stack and ends the thread, without returning to code that would run on
30
+ + * the stack it freed. */
31
+ + __ecmaos_unmapself(self->map_base, self->map_size);
32
+ }
33
+
34
+ /* Wake any joiner. */
@@ -0,0 +1,62 @@
1
+ ecmaOS: wordexp starts the shell with posix_spawn, as there is no fork to run it in. The write end of the pipe
2
+ becomes the child's stdout through a file action, and the child has the caller's signal mask, as the forked one did
3
+ once fork returned, so the signals blocked around the fork are not blocked here.
4
+
5
+ --- i/src/misc/wordexp.c
6
+ +++ w/src/misc/wordexp.c
7
+ @@ -8,9 +8,12 @@
8
+ #include <sys/wait.h>
9
+ #include <signal.h>
10
+ #include <errno.h>
11
+ +#include <spawn.h>
12
+ #include <fcntl.h>
13
+ #include "pthread_impl.h"
14
+
15
+ +extern char **__environ;
16
+ +
17
+ static void reap(pid_t pid)
18
+ {
19
+ int status;
20
+ @@ -36,7 +39,6 @@
21
+ char **wv = 0;
22
+ int p[2];
23
+ pid_t pid;
24
+ - sigset_t set;
25
+
26
+ if (flags & WRDE_REUSE) wordfree(we);
27
+
28
+ @@ -96,22 +98,23 @@
29
+ we->we_offs = 0;
30
+ }
31
+
32
+ + /* ecmaOS: there is no fork, so the shell is started with posix_spawn, its stdout the pipe's write end */
33
+ if (pipe2(p, O_CLOEXEC) < 0) goto nospace;
34
+ - __block_all_sigs(&set);
35
+ - pid = fork();
36
+ - __restore_sigs(&set);
37
+ - if (pid < 0) {
38
+ + posix_spawn_file_actions_t fa;
39
+ + if (posix_spawn_file_actions_init(&fa)) {
40
+ close(p[0]);
41
+ close(p[1]);
42
+ goto nospace;
43
+ }
44
+ - if (!pid) {
45
+ - if (p[1] == 1) fcntl(1, F_SETFD, 0);
46
+ - else dup2(p[1], 1);
47
+ - execl("/bin/sh", "sh", "-c",
48
+ - "eval \"printf %s\\\\\\\\0 x $1 $2\"",
49
+ - "sh", s, redir, (char *)0);
50
+ - _exit(1);
51
+ + posix_spawn_file_actions_adddup2(&fa, p[1], 1);
52
+ + int spawned = posix_spawn(&pid, "/bin/sh", &fa, 0, (char *[]){ "sh", "-c",
53
+ + "eval \"printf %s\\\\\\\\0 x $1 $2\"",
54
+ + "sh", (char *)s, (char *)redir, 0 }, __environ);
55
+ + posix_spawn_file_actions_destroy(&fa);
56
+ + if (spawned) {
57
+ + close(p[0]);
58
+ + close(p[1]);
59
+ + goto nospace;
60
+ }
61
+ close(p[1]);
62
+
@@ -0,0 +1,34 @@
1
+ ecmaOS: __progname and __progname_full (program_invocation_short_name and program_invocation_name) come from
2
+ argv[0], as __init_libc sets them. WALI's _start does not go through __libc_start_main, so they were NULL, and a
3
+ program naming itself by them (err(), warn(), usage messages) printed "(null)".
4
+
5
+ --- i/src/startup/__main_void.c
6
+ +++ w/src/startup/__main_void.c
7
+ @@ -5,6 +5,19 @@
8
+
9
+ extern void __wasm_init_tp(void);
10
+
11
+ +/* ecmaOS: __progname and __progname_full (program_invocation_short_name and program_invocation_name, what err()
12
+ + * and warn() name the program by) from argv[0], as __init_libc sets them; WALI's _start does not go through
13
+ + * __libc_start_main */
14
+ +extern char *__progname, *__progname_full;
15
+ +static void init_progname(void) {
16
+ + if (__cl_get_argc() < 1) return;
17
+ + char *pn = calloc(__cl_get_argv_len(0) + 1, 1);
18
+ + if (!pn) return;
19
+ + __cl_copy_argv(pn, 0);
20
+ + __progname = __progname_full = pn;
21
+ + for (char *p = pn; *p; p++) if (*p == '/') __progname = p + 1;
22
+ +}
23
+ +
24
+ // __wali_init must be run before any main or other exported functions
25
+ //
26
+ // This is called by default in `crt`, but can be exported for users to
27
+ @@ -24,6 +37,7 @@
28
+ if (r) {
29
+ return r;
30
+ }
31
+ + init_progname();
32
+ return 0;
33
+ }
34
+
@@ -0,0 +1,15 @@
1
+ ecmaOS: <string.h> no longer declares basename() without a prototype for _GNU_SOURCE, as upstream musl 1.2.5 does
2
+ not. In C23 `char *basename();` takes no arguments, so it conflicts with <libgen.h>'s declaration in a program that
3
+ includes both (xz's file_io.c, built with -std=gnu23).
4
+
5
+ --- i/include/string.h
6
+ +++ w/include/string.h
7
+ @@ -95,8 +95,5 @@
8
+ void *memmem(const void *, size_t, const void *, size_t);
9
+ void *memrchr(const void *, int, size_t);
10
+ void *mempcpy(void *, const void *, size_t);
11
+ -#ifndef __cplusplus
12
+ -char *basename();
13
+ -#endif
14
+ #endif
15
+
@@ -0,0 +1,15 @@
1
+ ecmaOS: SSIZE_MAX is the largest ssize_t, which on this target is a pointer-sized int (_Addr), not a long: musl's
2
+ LONG_MAX holds on its other targets, where the two are one size, but here long is 8 bytes and ssize_t 4, so a check
3
+ against it never failed (open_memstream's seek bound, gnulib's regex size limits).
4
+
5
+ --- i/include/limits.h
6
+ +++ w/include/limits.h
7
+ @@ -50,7 +50,7 @@
8
+ #define IOV_MAX 1024
9
+ #define SYMLOOP_MAX 40
10
+ #define WORD_BIT 32
11
+ -#define SSIZE_MAX LONG_MAX
12
+ +#define SSIZE_MAX __INTPTR_MAX__
13
+ #define TZNAME_MAX 6
14
+ #define TTY_NAME_MAX 32
15
+ #define HOST_NAME_MAX 255
@@ -0,0 +1,85 @@
1
+ ecmaOS: argv is copied in once at startup, into one mapping that holds the array and the strings, as it lies on the
2
+ stack on Linux, and __progname_full is argv[0] itself. WALI's startup took argv, each of its strings and a copy of
3
+ argv[0] from malloc before main, which a program that brings its own malloc saw (libc-test's flockfile-list lays its
4
+ blocks end to end from an aligned start, so libc's odd-sized ones left its FILEs unaligned, and their atomic lock
5
+ trapped).
6
+
7
+ --- i/src/startup/__main_void.c
8
+ +++ w/src/startup/__main_void.c
9
+ @@ -1,19 +1,39 @@
10
+ #include <stdlib.h>
11
+ #include <stdio.h>
12
+ +#include <sys/mman.h>
13
+ #include "init_env.h"
14
+ #include "atomic.h"
15
+
16
+ extern void __wasm_init_tp(void);
17
+
18
+ +/* ecmaOS: argv is copied in once, into one mapping, the array and the strings after it, as it lies on the stack on
19
+ + * Linux: nothing of the program's malloc is used before main (a program may bring its own, which libc-test's
20
+ + * flockfile-list does, laying its blocks end to end where the first was aligned). */
21
+ +static char **startup_argv;
22
+ +static int init_argv(void) {
23
+ + int argc = __cl_get_argc();
24
+ + size_t size = (argc + 1) * sizeof(char *);
25
+ + for (int i = 0; i < argc; i++) size += __cl_get_argv_len(i) + 1;
26
+ + char **argv = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
27
+ + if (argv == MAP_FAILED) return WALI_STARTUP_FAIL;
28
+ + char *at = (char *)(argv + argc + 1);
29
+ + for (int i = 0; i < argc; i++) {
30
+ + argv[i] = at;
31
+ + __cl_copy_argv(at, i);
32
+ + at += __cl_get_argv_len(i) + 1;
33
+ + }
34
+ + argv[argc] = 0;
35
+ + startup_argv = argv;
36
+ + return 0;
37
+ +}
38
+ +
39
+ /* ecmaOS: __progname and __progname_full (program_invocation_short_name and program_invocation_name, what err()
40
+ * and warn() name the program by) from argv[0], as __init_libc sets them; WALI's _start does not go through
41
+ * __libc_start_main */
42
+ extern char *__progname, *__progname_full;
43
+ static void init_progname(void) {
44
+ - if (__cl_get_argc() < 1) return;
45
+ - char *pn = calloc(__cl_get_argv_len(0) + 1, 1);
46
+ + char *pn = startup_argv[0];
47
+ if (!pn) return;
48
+ - __cl_copy_argv(pn, 0);
49
+ __progname = __progname_full = pn;
50
+ for (char *p = pn; *p; p++) if (*p == '/') __progname = p + 1;
51
+ }
52
+ @@ -37,6 +57,10 @@
53
+ if (r) {
54
+ return r;
55
+ }
56
+ + r = init_argv();
57
+ + if (r) {
58
+ + return r;
59
+ + }
60
+ init_progname();
61
+ return 0;
62
+ }
63
+ @@ -56,19 +80,7 @@
64
+ /* Main void if not defined by clang (i.e, if the argument main is used) */
65
+ __attribute__((__weak__, nodebug))
66
+ int __main_void(void) {
67
+ - int argc = __cl_get_argc();
68
+ - char **argv = (char**) malloc((argc+1) * sizeof(char*));
69
+ - if (argv == NULL) {
70
+ - return 1;
71
+ - }
72
+ - for (int i = 0; i < argc; i++) {
73
+ - int argv_len = __cl_get_argv_len(i);
74
+ - argv[i] = (char *) malloc(argv_len+1);
75
+ - if (argv[i] == NULL) {
76
+ - return 1;
77
+ - }
78
+ - __cl_copy_argv(argv[i], i);
79
+ - }
80
+ - argv[argc] = NULL;
81
+ - return __main_argc_argv(argc, argv);
82
+ + int argc = 0;
83
+ + while (startup_argv[argc]) argc++;
84
+ + return __main_argc_argv(argc, startup_argv);
85
+ }
@@ -0,0 +1,39 @@
1
+ musl's own fixes to floatscan (strtod, strtof, strtold and scanf) since 1.2.5: 50979c5b (a hex float read one digit
2
+ too few where LDBL_MANT_DIG is not a multiple of 4, plus one, so 0x1.111111111111281 rounded down and
3
+ 0x1.11111111111111 up), dd856098 (a store at index -1 of the mantissa buffer when it wrapped) and 6426a515 (an inexact
4
+ denormal result that rounded up lost its ERANGE).
5
+
6
+ diff --git i/src/internal/floatscan.c w/src/internal/floatscan.c
7
+ index a0e3332..474b1ff 100644
8
+ --- i/src/internal/floatscan.c
9
+ +++ w/src/internal/floatscan.c
10
+ @@ -256,7 +256,7 @@ static long_double_pr_t decfloat(FILE *f, int c, int bits, int emin, int sign, i
11
+
12
+ /* Assemble desired bits into floating point variable */
13
+ for (y=i=0; i<LD_B1B_DIG; i++) {
14
+ - if ((a+i & MASK)==z) x[(z=(z+1 & MASK))-1] = 0;
15
+ + if ((a+i & MASK)==z) x[z] = 0, z = z+1 & MASK;
16
+ #if !defined(__wali_printscan_enable_long_double)
17
+ y = 1000000000.0 * y + x[a+i & MASK];
18
+ #else
19
+ @@ -303,10 +303,9 @@ static long_double_pr_t decfloat(FILE *f, int c, int bits, int emin, int sign, i
20
+
21
+ if ((e2+LDBL_MANT_DIG & INT_MAX) > emax-5) {
22
+ if (fabsl(y) >= 2/LDBL_EPSILON) {
23
+ - if (denormal && bits==LDBL_MANT_DIG+e2-emin)
24
+ - denormal = 0;
25
+ y *= 0.5;
26
+ e2++;
27
+ + if (e2+LDBL_MANT_DIG >= -emax+3) denormal = 0;
28
+ }
29
+ if (e2+LDBL_MANT_DIG>emax || (denormal && frac))
30
+ errno = ERANGE;
31
+ @@ -351,7 +350,7 @@ static long_double_pr_t hexfloat(FILE *f, int bits, int emin, int sign, int pok)
32
+ else d = c-'0';
33
+ if (dc<8) {
34
+ x = x*16 + d;
35
+ - } else if (dc < LDBL_MANT_DIG/4+1) {
36
+ + } else if (dc < (LDBL_MANT_DIG+3)/4+1) {
37
+ y += d*(scale/=16);
38
+ } else if (d && !gottail) {
39
+ y += 0.5*scale;