Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions system/lib/libc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ and use a script (`system/lib/update_musl.py`) to pull in updates.

Some changes have been made to the version that was taken from upstream, including:

* Emscripten-specific changes (from before this readme existed). These should be marked with `XXX EMSCRIPTEN` in the source, or ifdefed with `#if __EMSCRIPTEN__`. They are mostly in pthreads code and hopefully temporary.
* Backporting an operator-precedence warning fix from 6e76e1540fc58a418494bf5eb832b556f9c5763e in the upstream version.
* Emscripten-specific changes (from before this readme existed). These should be marked with `XXX EMSCRIPTEN` in the source, or ifdefed with `#ifdef __EMSCRIPTEN__`. They are mostly in pthreads code and hopefully temporary.
* Switch to using the wasi `fd_write` syscall instead of `writev`.
* Simplify stdout stream handling: do not support seeking, terminal handling, etc., as it just increases code size and Emscripten doesn't have those features anyhow.
* Setting `_POSIX_REALTIME_SIGNALS` and `_POSIX_SPAWN` macros to -1, to exclude unsupported functions.
Expand Down
18 changes: 1 addition & 17 deletions system/lib/libc/musl/arch/emscripten/bits/fenv.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,6 @@
#define FE_TOWARDZERO 0xc00

typedef unsigned short fexcept_t;

typedef struct {
unsigned short __control_word;
unsigned short __unused1;
unsigned short __status_word;
unsigned short __unused2;
unsigned short __tags;
unsigned short __unused3;
unsigned int __eip;
unsigned short __cs_selector;
unsigned int __opcode:11;
unsigned int __unused4:5;
unsigned int __data_offset;
unsigned short __data_selector;
unsigned short __unused5;
unsigned int __mxcsr;
} fenv_t;
typedef unsigned short fenv_t;

#define FE_DFL_ENV ((const fenv_t *) -1)
4 changes: 3 additions & 1 deletion system/lib/libc/musl/arch/emscripten/bits/limits.h
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#define PAGE_SIZE 65536
// A value used historically in Emscripten, and which we don't have a strong
// reason to change so far.
#define PAGESIZE 65536
4 changes: 4 additions & 0 deletions system/lib/libc/musl/arch/emscripten/bits/mman.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// XXX Emscripten in sync with both:
// - musl/arch/x86_64/bits/mman.h
// - musl/arch/i386/bits/mman.h
#define MAP_32BIT 0x40
7 changes: 7 additions & 0 deletions system/lib/libc/musl/arch/emscripten/bits/posix.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
#ifdef __wasm64__
// 64-bit wide pointers under wasm64
#define _POSIX_V6_LP64_OFF64 1
#define _POSIX_V7_LP64_OFF64 1
#else
// 32-bit wide pointers under wasm32
#define _POSIX_V6_ILP32_OFFBIG 1
#define _POSIX_V7_ILP32_OFFBIG 1
#endif
1 change: 1 addition & 0 deletions system/lib/libc/musl/arch/emscripten/bits/setjmp.h
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// XXX Emscripten in sync with musl/arch/i386/bits/setjmp.h
typedef unsigned long __jmp_buf[6];
58 changes: 39 additions & 19 deletions system/lib/libc/musl/arch/emscripten/bits/signal.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// XXX Emscripten in sync with musl/arch/i386/bits/signal.h
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)

Expand All @@ -7,25 +8,44 @@
#endif

#ifdef _GNU_SOURCE
#define REG_GS 0
#define REG_FS 1
#define REG_ES 2
#define REG_DS 3
#define REG_EDI 4
#define REG_ESI 5
#define REG_EBP 6
#define REG_ESP 7
#define REG_EBX 8
#define REG_EDX 9
#define REG_ECX 10
#define REG_EAX 11
#define REG_TRAPNO 12
#define REG_ERR 13
#define REG_EIP 14
#define REG_CS 15
#define REG_EFL 16
#define REG_UESP 17
#define REG_SS 18
enum { REG_GS = 0 };
#define REG_GS REG_GS
enum { REG_FS = 1 };
#define REG_FS REG_FS
enum { REG_ES = 2 };
#define REG_ES REG_ES
enum { REG_DS = 3 };
#define REG_DS REG_DS
enum { REG_EDI = 4 };
#define REG_EDI REG_EDI
enum { REG_ESI = 5 };
#define REG_ESI REG_ESI
enum { REG_EBP = 6 };
#define REG_EBP REG_EBP
enum { REG_ESP = 7 };
#define REG_ESP REG_ESP
enum { REG_EBX = 8 };
#define REG_EBX REG_EBX
enum { REG_EDX = 9 };
#define REG_EDX REG_EDX
enum { REG_ECX = 10 };
#define REG_ECX REG_ECX
enum { REG_EAX = 11 };
#define REG_EAX REG_EAX
enum { REG_TRAPNO = 12 };
#define REG_TRAPNO REG_TRAPNO
enum { REG_ERR = 13 };
#define REG_ERR REG_ERR
enum { REG_EIP = 14 };
#define REG_EIP REG_EIP
enum { REG_CS = 15 };
#define REG_CS REG_CS
enum { REG_EFL = 16 };
#define REG_EFL REG_EFL
enum { REG_UESP = 17 };
#define REG_UESP REG_UESP
enum { REG_SS = 18 };
#define REG_SS REG_SS
#endif

struct sigaltstack {
Expand Down
12 changes: 9 additions & 3 deletions system/lib/libc/musl/arch/emscripten/bits/stat.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// XXX Emscripten in sync with musl/arch/i386/bits/stat.h except for the padding and 64-bit time_t redirections change.

/* copied from kernel definition, but with padding replaced
* by the corresponding correctly-sized userspace types. */

struct stat
{
struct stat {
dev_t st_dev;
#ifndef __EMSCRIPTEN__
int __st_dev_padding;
Expand All @@ -19,6 +19,12 @@ struct stat
off_t st_size;
blksize_t st_blksize;
blkcnt_t st_blocks;
#ifndef __EMSCRIPTEN__ // XXX Emscripten no need to activate the symbol redirections for 64-bit time_t.
struct {
long tv_sec;
long tv_nsec;
} __st_atim32, __st_mtim32, __st_ctim32;
#endif
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
Expand Down
48 changes: 0 additions & 48 deletions system/lib/libc/musl/arch/emscripten/bits/user.h
Original file line number Diff line number Diff line change
@@ -1,48 +0,0 @@
#undef __WORDSIZE
#define __WORDSIZE 32

typedef struct user_fpregs_struct
{
long cwd, swd, twd, fip, fcs, foo, fos, st_space[20];
} elf_fpregset_t;

typedef struct user_fpxregs_struct
{
unsigned short cwd, swd, twd, fop;
long fip, fcs, foo, fos, mxcsr, reserved;
long st_space[32], xmm_space[32], padding[56];
} elf_fpxregset_t;

struct user_regs_struct
{
long ebx, ecx, edx, esi, edi, ebp, eax, xds, xes, xfs, xgs;
long orig_eax, eip, xcs, eflags, esp, xss;
};

#define ELF_NGREG 17
typedef unsigned long elf_greg_t, elf_gregset_t[ELF_NGREG];

struct user
{
struct user_regs_struct regs;
int u_fpvalid;
struct user_fpregs_struct i387;
unsigned long u_tsize;
unsigned long u_dsize;
unsigned long u_ssize;
unsigned long start_code;
unsigned long start_stack;
long signal;
int reserved;
struct user_regs_struct *u_ar0;
struct user_fpregs_struct *u_fpstate;
unsigned long magic;
char u_comm[32];
int u_debugreg[8];
};

#define PAGE_MASK (~(PAGE_SIZE-1))
#define NBPG PAGE_SIZE
#define UPAGES 1
#define HOST_TEXT_START_ADDR (u.start_code)
#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG)
2 changes: 2 additions & 0 deletions system/lib/libc/musl/arch/generic/bits/ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ struct ipc_perm {
long __pad1;
long __pad2;
};

#define IPC_64 0x100
2 changes: 1 addition & 1 deletion system/lib/libc/musl/include/setjmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef struct __jmp_buf_tag {
|| defined(_BSD_SOURCE)
typedef jmp_buf sigjmp_buf;
/* XXX EMSCRIPTEN: No signals support, alias sigsetjmp and siglongjmp to their non-signals counterparts. */
#if __EMSCRIPTEN__ && !defined(LLVM_LIBC)
#if defined(__EMSCRIPTEN__) && !defined(LLVM_LIBC)
#define sigsetjmp(buf, x) setjmp((buf))
#define siglongjmp(buf, val) longjmp(buf, val)
#else
Expand Down
18 changes: 9 additions & 9 deletions system/lib/libc/musl/include/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,20 @@ pid_t gettid(void);
#define _POSIX_NO_TRUNC 1
#define _POSIX_RAW_SOCKETS _POSIX_VERSION

#ifndef __EMSCRIPTEN__
#define _POSIX_REALTIME_SIGNALS _POSIX_VERSION
#else
#ifdef __EMSCRIPTEN__
#define _POSIX_REALTIME_SIGNALS -1
#else
#define _POSIX_REALTIME_SIGNALS _POSIX_VERSION
#endif

#define _POSIX_REGEXP 1
#define _POSIX_SAVED_IDS 1
#define _POSIX_SHELL 1

#ifndef __EMSCRIPTEN__
#define _POSIX_SPAWN _POSIX_VERSION
#else
#ifdef __EMSCRIPTEN__
#define _POSIX_SPAWN -1
#else
#define _POSIX_SPAWN _POSIX_VERSION
#endif

#define _POSIX_VDISABLE 0
Expand All @@ -263,10 +263,10 @@ pid_t gettid(void);
#else
#define _POSIX_THREADS _POSIX_VERSION
#endif
#ifndef __EMSCRIPTEN__
#define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION
#else
#ifdef __EMSCRIPTEN__
#define _POSIX_THREAD_PROCESS_SHARED -1
#else
#define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION
#endif
#define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION
#define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION
Expand Down
4 changes: 2 additions & 2 deletions system/lib/libc/musl/src/exit/abort.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
#include "lock.h"
#include "ksigaction.h"

#if __EMSCRIPTEN__
#ifdef __EMSCRIPTEN__
#include "emscripten_internal.h"
#endif

_Noreturn void abort(void)
{
#if __EMSCRIPTEN__
#ifdef __EMSCRIPTEN__
/* In emscripten we call out to JS to perform the actual abort where it can
* produce a nice error.
* Note that the JS library function is not called `abort` to avoid conflict
Expand Down
17 changes: 10 additions & 7 deletions system/lib/libc/musl/src/internal/libm.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ static inline long double fp_barrierl(long double x)
}
#endif

#ifdef __EMSCRIPTEN__
/*
* wasm doesn't have user-accessible floating point exceptions, so there's
* no point in trying to force expression evaluations to produce them.
*/
#define fp_force_evalf(x)
#define fp_force_eval(x)
#define fp_force_evall(x)
#define FORCE_EVAL(x)
#else
/* fp_force_eval ensures that the input value is computed when that's
otherwise unused. To prevent the constant folding of the input
expression, an additional fp_barrier may be needed or a compilation
Expand Down Expand Up @@ -177,13 +187,6 @@ static inline void fp_force_evall(long double x)
}
#endif

#ifdef __EMSCRIPTEN__
/*
* asm.js doesn't have user-accessible floating point exceptions, so there's
* no point in trying to force expression evaluations to produce them.
*/
#define FORCE_EVAL(x)
#else
#define FORCE_EVAL(x) do { \
if (sizeof(x) == sizeof(float)) { \
fp_force_evalf(x); \
Expand Down
2 changes: 1 addition & 1 deletion system/lib/libc/musl/src/internal/locale_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ hidden char *__gettextdomain(void);

#define LOC_MAP_FAILED ((const struct __locale_map *)-1)

#if __EMSCRIPTEN__
#ifdef __EMSCRIPTEN__
// Disable message translation completely under emscripten since we don't
// support loading any actual locale data, and even looking up the current
// local via CURRENT_LOCALE via TLS is not free.
Expand Down
2 changes: 1 addition & 1 deletion system/lib/libc/musl/src/internal/pthread_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static inline void __wake(volatile void *addr, int cnt, int priv)
if (priv) priv = FUTEX_PRIVATE;
if (cnt<0) cnt = INT_MAX;
#ifdef __EMSCRIPTEN__
emscripten_futex_wake(addr, (cnt)<0?INT_MAX:(cnt));
emscripten_futex_wake(addr, cnt);
#else
__syscall(SYS_futex, addr, FUTEX_WAKE|priv, cnt) != -ENOSYS ||
__syscall(SYS_futex, addr, FUTEX_WAKE, cnt);
Expand Down
Loading
Loading