diff --git a/src/core/stdc/assert_.d b/src/core/stdc/assert_.d index a3675b70a6..f7c5a27e67 100644 --- a/src/core/stdc/assert_.d +++ b/src/core/stdc/assert_.d @@ -63,6 +63,10 @@ else version (CRuntime_Glibc) void __assert_fail(const(char)* exp, const(char)* file, uint line, const(char)* func); /// void __assert_perror_fail(int errnum, const(char)* file, uint line, const(char)* func); +} +else version (CRuntime_Musl) +{ + } else { diff --git a/src/core/stdc/fenv.d b/src/core/stdc/fenv.d index 769c59a48e..c03d02b8c5 100644 --- a/src/core/stdc/fenv.d +++ b/src/core/stdc/fenv.d @@ -298,6 +298,25 @@ else version( Solaris ) alias int fexcept_t; } +else version( CRuntime_Musl ) +{ + struct fenv_t { + ushort __control_word; + ushort __unused1; + ushort __status_word; + ushort __unused2; + ushort __tags; + ushort __unused3; + uint __eip; + ushort __cs_selector; + ushort __opcode; + uint __data_offset; + ushort __data_selector; + ushort __unused5; + uint __mxcsr; + } + alias ushort fexcept_t; +} else { static assert( false, "Unsupported platform" ); @@ -623,6 +642,9 @@ else version( Solaris ) /// enum FE_DFL_ENV = &__fenv_def_env; } +else version( CRuntime_Musl ) +{ +} else { static assert( false, "Unsupported platform" ); diff --git a/src/core/stdc/locale.d b/src/core/stdc/locale.d index aa7c61ed98..f9cd1eb4df 100644 --- a/src/core/stdc/locale.d +++ b/src/core/stdc/locale.d @@ -218,6 +218,9 @@ else version(Solaris) /// enum LC_ALL = 6; } +else version(CRuntime_Musl) +{ +} else { static assert(false, "Unsupported platform"); diff --git a/src/core/stdc/math.d b/src/core/stdc/math.d index 7f8285b031..10755668e5 100644 --- a/src/core/stdc/math.d +++ b/src/core/stdc/math.d @@ -601,6 +601,136 @@ else version( CRuntime_Glibc ) } } } +else version( CRuntime_Musl ) +{ + enum + { + /// + FP_NAN, + /// + FP_INFINITE, + /// + FP_ZERO, + /// + FP_SUBNORMAL, + /// + FP_NORMAL, + } + + enum + { + /// + FP_FAST_FMA = 0, + /// + FP_FAST_FMAF = 0, + /// + FP_FAST_FMAL = 0, + } + + int __fpclassifyf(float x); + int __fpclassify(double x); + int __fpclassifyl(real x); + + int __signbitf(float x); + int __signbit(double x); + int __signbitl(real x); + + extern (D) + { + //int fpclassify(real-floating x); + /// + int fpclassify(float x) { return __fpclassifyf(x); } + /// + int fpclassify(double x) { return __fpclassify(x); } + /// + int fpclassify(real x) + { + return (real.sizeof == double.sizeof) + ? __fpclassify(x) + : __fpclassifyl(x); + } + static uint __FLOAT_BITS(float __f) + { + union __u_t { + float __f; + uint __i; + } + __u_t __u; + __u.__f = __f; + return __u.__i; + } + static ulong __DOUBLE_BITS(double __f) + { + union __u_t { + double __f; + ulong __i; + } + __u_t __u; + __u.__f = __f; + return __u.__i; + } + + //int isfinite(real-floating x); + /// + int isfinite(float x) { return (__FLOAT_BITS(x) & 0x7fffffff) < 0x7f800000; } + /// + int isfinite(double x) { return (__DOUBLE_BITS(x) & -1UL>>1) < 0x7ffUL<<52; } + /// + int isfinite(real x) + { + return (real.sizeof == double.sizeof) + ? isfinite(cast(double)x) + : __fpclassifyl(x) > FP_INFINITE; + } + + //int isinf(real-floating x); + /// + int isinf(float x) { return (__FLOAT_BITS(x) & 0x7fffffff) == 0x7f800000; } + /// + int isinf(double x) { return (__DOUBLE_BITS(x) & -1UL>>1) == 0x7ffUL<<52; } + /// + int isinf(real x) + { + return (real.sizeof == double.sizeof) + ? isinf(cast(double)x) + : __fpclassifyl(x) == FP_INFINITE; + } + + //int isnan(real-floating x); + /// + int isnan(float x) { return (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000; } + /// + int isnan(double x) { return (__DOUBLE_BITS(x) & -1UL>>1) > 0x7ffUL<<52; } + /// + int isnan(real x) + { + return (real.sizeof == double.sizeof) + ? isnan(cast(double)x) + : __fpclassifyl(x) == FP_NAN; + } + + //int isnormal(real-floating x); + /// + int isnormal(float x) { return fpclassify(x) == FP_NORMAL; } + /// + int isnormal(double x) { return fpclassify(x) == FP_NORMAL; } + /// + int isnormal(real x) { return fpclassify(x) == FP_NORMAL; } + + //int signbit(real-floating x); + /// + int signbit(float x) { return __signbitf(x); } + /// + int signbit(double x) { return __signbit(x); } + /// + int signbit(real x) + { + return (real.sizeof == double.sizeof) + ? __signbit(x) + : __signbitl(x); + } + } +} else version( MinGW ) { enum diff --git a/src/core/stdc/stdio.d b/src/core/stdc/stdio.d index 7e1476f0e7..0be8bfb323 100644 --- a/src/core/stdc/stdio.d +++ b/src/core/stdc/stdio.d @@ -121,6 +121,24 @@ else version( CRuntime_Glibc ) L_tmpnam = 20 } } +else version( CRuntime_Musl ) +{ + enum + { + /// + BUFSIZ = 8192, + /// + EOF = -1, + /// + FOPEN_MAX = 16, + /// + FILENAME_MAX = 4095, + /// + TMP_MAX = 238328, + /// + L_tmpnam = 20 + } +} else version( Darwin ) { enum @@ -292,6 +310,14 @@ else version( CRuntime_Bionic ) int _size; } } +else version( CRuntime_Musl ) +{ + enum + { + EOF = -1, + } + +} else { static assert( false, "Unsupported platform" ); @@ -383,6 +409,16 @@ else version( CRuntime_Glibc ) /// alias shared(_IO_FILE) FILE; } +else version( CRuntime_Musl ) +{ + struct fpos_t { + char[16] __opaque; + double __align; + } + struct _IO_FILE; + alias _IO_FILE _iobuf; + alias shared(_IO_FILE) FILE; +} else version( Darwin ) { /// @@ -917,6 +953,20 @@ else version( CRuntime_Bionic ) /// shared stderr = &__sF[2]; } +else version( CRuntime_Musl ) +{ + /// needs tail const + extern shared FILE* stdin; + /// + extern shared FILE* stdout; + /// + extern shared FILE* stderr; + enum { + _IOFBF = 0, + _IOLBF = 1, + _IONBF = 2, + } +} else { static assert( false, "Unsupported platform" ); @@ -1416,6 +1466,30 @@ else version( CRuntime_Bionic ) /// int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg); } +else version( CRuntime_Musl ) +{ + import core.sys.posix.sys.types : off_t; + /// + int fseeko(FILE *, off_t, int); + @trusted + { + /// + void rewind(FILE* stream); + /// + pure void clearerr(FILE* stream); + /// + pure int feof(FILE* stream); + /// + pure int ferror(FILE* stream); + /// + int fileno(FILE *); + } + + /// + int snprintf(scope char* s, size_t n, scope const char* format, ...); + /// + int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg); +} else { static assert( false, "Unsupported platform" ); diff --git a/src/core/stdc/stdlib.d b/src/core/stdc/stdlib.d index f3b8a7b7fb..863cfb0aff 100644 --- a/src/core/stdc/stdlib.d +++ b/src/core/stdc/stdlib.d @@ -79,6 +79,7 @@ else version(NetBSD) enum RAND_MAX = 0x7fffffff; else version(OpenBSD) enum RAND_MAX = 0x7fffffff; else version(Solaris) enum RAND_MAX = 0x7fff; else version(CRuntime_Bionic) enum RAND_MAX = 0x7fffffff; +else version(CRuntime_Musl) enum RAND_MAX = 0x7fffffff; else static assert( false, "Unsupported platform" ); /// diff --git a/src/core/stdc/string.d b/src/core/stdc/string.d index 8135cfe9b5..a8499b832c 100644 --- a/src/core/stdc/string.d +++ b/src/core/stdc/string.d @@ -106,6 +106,11 @@ else version (CRuntime_Bionic) /// int strerror_r(int errnum, scope char* buf, size_t buflen); } +else version (CRuntime_Musl) +{ + /// + int strerror_r (int, char *, size_t); +} /// pure size_t strlen(scope const char* s); /// diff --git a/src/core/stdc/time.d b/src/core/stdc/time.d index 4325ca3429..5c4408c00a 100644 --- a/src/core/stdc/time.d +++ b/src/core/stdc/time.d @@ -194,6 +194,13 @@ else version( CRuntime_Bionic ) /// extern __gshared const(char)*[2] tzname; } +else version( CRuntime_Musl ) +{ + /// + void tzset(); // non-standard + /// + extern __gshared const(char)*[2] tzname; // non-standard +} else { static assert(false, "Unsupported platform"); diff --git a/src/core/sys/posix/arpa/inet.d b/src/core/sys/posix/arpa/inet.d index 675a197e6d..9a582d7768 100644 --- a/src/core/sys/posix/arpa/inet.d +++ b/src/core/sys/posix/arpa/inet.d @@ -222,6 +222,31 @@ else version( CRuntime_Bionic ) const(char)* inet_ntop(int, in void*, char*, size_t); int inet_pton(int, in char*, void*); } +else version( CRuntime_Musl ) +{ + alias uint16_t in_port_t; + alias uint32_t in_addr_t; + + struct in_addr + { + in_addr_t s_addr; + } + + enum INET_ADDRSTRLEN = 16; + + @trusted pure + { + uint32_t htonl(uint32_t); + uint16_t htons(uint16_t); + uint32_t ntohl(uint32_t); + uint16_t ntohs(uint16_t); + } + + in_addr_t inet_addr(in char*); + char* inet_ntoa(in_addr); + const(char)* inet_ntop(int, in void*, char*, socklen_t); + int inet_pton(int, in char*, void*); +} // // IPV6 (IP6) diff --git a/src/core/sys/posix/config.d b/src/core/sys/posix/config.d index a6c4352321..0cb8153104 100644 --- a/src/core/sys/posix/config.d +++ b/src/core/sys/posix/config.d @@ -61,6 +61,18 @@ version (CRuntime_Glibc) else enum __WORDSIZE=32; } +else version (CRuntime_Musl) +{ + enum _FILE_OFFSET_BITS = 64; + + enum __REDIRECT = false; + + enum __USE_FILE_OFFSET64 = _FILE_OFFSET_BITS == 64; + enum __USE_LARGEFILE = __USE_FILE_OFFSET64 && !__REDIRECT; + enum __USE_LARGEFILE64 = __USE_FILE_OFFSET64 && !__REDIRECT; + + enum __WORDSIZE=64; +} else version (Solaris) { enum _FILE_OFFSET_BITS = 64; diff --git a/src/core/sys/posix/dirent.d b/src/core/sys/posix/dirent.d index 5a51cc7378..3381647050 100644 --- a/src/core/sys/posix/dirent.d +++ b/src/core/sys/posix/dirent.d @@ -287,6 +287,44 @@ else version( CRuntime_Bionic ) dirent* readdir(DIR*); } +else version( CRuntime_Musl ) +{ + enum + { + DT_UNKNOWN = 0, + DT_FIFO = 1, + DT_CHR = 2, + DT_DIR = 4, + DT_BLK = 6, + DT_REG = 8, + DT_LNK = 10, + DT_SOCK = 12, + DT_WHT = 14 + } + + struct dirent + { + ino_t d_ino; + off_t d_off; + ushort d_reclen; + ubyte d_type; + char[256] d_name; + } + + struct DIR + { + } + + static if( __USE_FILE_OFFSET64 ) + { + dirent* readdir64(DIR*); + alias readdir64 readdir; + } + else + { + dirent* readdir(DIR*); + } +} else { static assert(false, "Unsupported platform"); @@ -381,6 +419,10 @@ else version (Solaris) else version( CRuntime_Bionic ) { int readdir_r(DIR*, dirent*, dirent**); +} +else version( CRuntime_Musl ) +{ + } else { @@ -446,6 +488,9 @@ else version (Solaris) else version (CRuntime_Bionic) { } +else version (CRuntime_Musl) +{ +} else { static assert(false, "Unsupported platform"); diff --git a/src/core/sys/posix/dlfcn.d b/src/core/sys/posix/dlfcn.d index b227d1025d..6253e39dfb 100644 --- a/src/core/sys/posix/dlfcn.d +++ b/src/core/sys/posix/dlfcn.d @@ -263,3 +263,18 @@ else version( CRuntime_Bionic ) void* dli_saddr; } } +else version( CRuntime_Musl ) +{ + enum { + RTLD_LAZY = 1, + RTLD_NOW = 2, + RTLD_NOLOAD = 4, + RTLD_NODELETE = 4096, + RTLD_GLOBAL = 256, + RTLD_LOCAL = 0, + } + int dlclose(void*); + const(char)* dlerror(); + void* dlopen(in char*, int); + void* dlsym(void*, in char*); +} diff --git a/src/core/sys/posix/fcntl.d b/src/core/sys/posix/fcntl.d index e102b53b36..bbd70ad553 100644 --- a/src/core/sys/posix/fcntl.d +++ b/src/core/sys/posix/fcntl.d @@ -682,6 +682,66 @@ else version( CRuntime_Bionic ) enum AT_FDCWD = -100; } +else version( CRuntime_Musl ) +{ + enum { + O_CREAT = 0x40, // octal 0100 + O_EXCL = 0x80, // octal 0200 + O_NOCTTY = 0x100, // octal 0400 + O_TRUNC = 0x200, // octal 01000 + + O_APPEND = 0x400, // octal 02000 + O_NONBLOCK = 0x800, // octal 04000 + O_DSYNC = 0x1000, // octal 010000 + O_SYNC = 0x101000, // octal 04010000 + O_RSYNC = O_SYNC, + O_DIRECTORY = 0x10000, + O_NOFOLLOW = 0x20000, + O_CLOEXEC = 0x80000, + + O_ASYNC = 0x2000, + O_DIRECT = 0x4000, + O_LARGEFILE = 0, + O_NOATIME = 0x40000, + O_PATH = 0x200000, + O_TMPFILE = 0x410000, + O_NDELAY = O_NONBLOCK, + O_SEARCH = O_PATH, + O_EXEC = O_PATH, + + O_ACCMODE = (03|O_SEARCH), + O_RDONLY = 00, + O_WRONLY = 01, + O_RDWR = 02, + } + enum { + F_DUPFD = 0, + F_GETFD = 1, + F_SETFD = 2, + F_GETFL = 3, + F_SETFL = 4, + F_GETLK = 5, + F_SETLK = 6, + F_SETLKW = 7, + F_SETOWN = 8, + F_GETOWN = 9, + } + enum { + F_RDLCK = 0, + F_WRLCK = 1, + F_UNLCK = 2, + } + struct flock + { + short l_type; + short l_whence; + off_t l_start; + off_t l_len; + pid_t l_pid; + } + enum FD_CLOEXEC = 1; + int open(in char*, int, ...); +} else { static assert(false, "Unsupported platform"); diff --git a/src/core/sys/posix/netdb.d b/src/core/sys/posix/netdb.d index 60ae944d89..46b816943c 100644 --- a/src/core/sys/posix/netdb.d +++ b/src/core/sys/posix/netdb.d @@ -765,6 +765,81 @@ else version( CRuntime_Bionic ) enum EAI_SYSTEM = 11; enum EAI_OVERFLOW = 14; } +else version( CRuntime_Musl ) +{ + struct hostent + { + char* h_name; + char** h_aliases; + int h_addrtype; + int h_length; + char** h_addr_list; + char* h_addr() @property { return h_addr_list[0]; } // non-standard + } + + struct netent + { + char* n_name; + char** n_aliases; + int n_addrtype; + uint32_t n_net; + } + + struct protoent + { + char* p_name; + char** p_aliases; + int p_proto; + } + + struct servent + { + char* s_name; + char** s_aliases; + int s_port; + char* s_proto; + } + + struct addrinfo + { + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + socklen_t ai_addrlen; + sockaddr* ai_addr; + char* ai_canonname; + addrinfo* ai_next; + } + + enum { + AI_PASSIVE = 0x1, + AI_CANONNAME = 0x2, + AI_NUMERICHOST = 0x4, + AI_NUMERICSERV = 0x8 + } + enum { + NI_NUMERICHOST = 1, + NI_NUMERICSERV = 2, + NI_NOFQDN = 4, + NI_NAMEREQD = 8, + NI_DGRAM = 16, + NI_MAXSERV = 32, + NI_MAXHOST = 255, + } + enum { + EAI_BADFLAGS = -1, + EAI_NONAME = -2, + EAI_AGAIN = -3, + EAI_FAIL = -4, + EAI_FAMILY = -6, + EAI_SOCKTYPE = -7, + EAI_SERVICE = -8, + EAI_MEMORY = -10, + EAI_SYSTEM = -11, + EAI_OVERFLOW = -12, + } +} else { static assert(false, "Unsupported platform"); diff --git a/src/core/sys/posix/netinet/in_.d b/src/core/sys/posix/netinet/in_.d index 061ed48933..87bd251113 100644 --- a/src/core/sys/posix/netinet/in_.d +++ b/src/core/sys/posix/netinet/in_.d @@ -302,7 +302,8 @@ else version( linux ) IPPROTO_TCP = 6, IPPROTO_PUP = 12, IPPROTO_UDP = 17, - IPPROTO_IDP = 22 + IPPROTO_IDP = 22, + IPPROTO_IPV6 = 41 } enum : c_ulong @@ -1151,6 +1152,37 @@ else version( CRuntime_Bionic ) } } } +else version( CRuntime_Musl ) +{ + + struct in6_addr { + union { + uint8_t[16] s6_addr; + uint16_t[8] s6_addr16; + uint32_t[4] s6_addr32; + } + } + struct sockaddr_in6 { + sa_family_t sin6_family; + in_port_t sin6_port; + uint32_t sin6_flowinfo; + in6_addr sin6_addr; + uint32_t sin6_scope_id; + } + + enum : uint + { + IPV6_UNICAST_HOPS = 16, + IPV6_MULTICAST_IF = 17, + IPV6_MULTICAST_HOPS = 18, + IPV6_MULTICAST_LOOP = 19, + IPV6_JOIN_GROUP = 20, + IPV6_LEAVE_GROUP = 21, + IPV6_V6ONLY = 26 + } + extern __gshared immutable in6_addr in6addr_any; + extern __gshared immutable in6_addr in6addr_loopback; +} // diff --git a/src/core/sys/posix/poll.d b/src/core/sys/posix/poll.d index 4e67b4a37e..f1379c65d2 100644 --- a/src/core/sys/posix/poll.d +++ b/src/core/sys/posix/poll.d @@ -271,3 +271,30 @@ else version( CRuntime_Bionic ) int poll(pollfd*, nfds_t, c_long); } +else version( CRuntime_Musl ) +{ + struct pollfd + { + int fd; + short events; + short revents; + } + + alias uint nfds_t; + + enum + { + POLLIN = 0x001, + POLLPRI = 0x002, + POLLOUT = 0x004, + POLLERR = 0x008, + POLLHUP = 0x010, + POLLNVAL = 0x020, + POLLRDNORM = 0x040, + POLLRDBAND = 0x080, + POLLWRNORM = 0x100, + POLLWRBAND = 0x200, + } + + int poll(pollfd*, nfds_t, c_long); +} diff --git a/src/core/sys/posix/pthread.d b/src/core/sys/posix/pthread.d index 488eee5d7a..451e5ca676 100644 --- a/src/core/sys/posix/pthread.d +++ b/src/core/sys/posix/pthread.d @@ -340,6 +340,10 @@ else version( CRuntime_Bionic ) PTHREAD_PROCESS_PRIVATE, PTHREAD_PROCESS_SHARED } +} +else version( CRuntime_Musl ) +{ + } else { @@ -534,6 +538,31 @@ else version( CRuntime_Bionic ) } } } +else version( CRuntime_Musl ) +{ + struct __ptcb { + _pthread_cleanup_routine f; + void* __x; + __ptcb* __next; + } + void _pthread_cleanup_push(__ptcb*, _pthread_cleanup_routine, void*); + void _pthread_cleanup_pop(__ptcb*, int); + + struct pthread_cleanup + { + __ptcb __cleanup = void; + + extern (D) void push(F: _pthread_cleanup_routine)(F routine, void* arg ) + { + _pthread_cleanup_push( &__cleanup, routine, arg ); + } + + extern (D) void pop()( int execute ) + { + _pthread_cleanup_pop( &__cleanup, execute ); + } + } +} else { static assert(false, "Unsupported platform"); @@ -663,6 +692,10 @@ else version (Solaris) } else version (CRuntime_Bionic) { +} +else version (CRuntime_Musl) +{ + } else { @@ -733,6 +766,10 @@ else version (Solaris) } else version (CRuntime_Bionic) { +} +else version (CRuntime_Musl) +{ + } else { @@ -870,6 +907,16 @@ else version (CRuntime_Bionic) int pthread_mutexattr_gettype(in pthread_mutexattr_t*, int*); int pthread_mutexattr_settype(pthread_mutexattr_t*, int) @trusted; } +else version (CRuntime_Musl) +{ + enum { + PTHREAD_MUTEX_NORMAL = 0, + PTHREAD_MUTEX_RECURSIVE = 1, + PTHREAD_MUTEX_ERRORCHECK = 2, + PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL, + } + int pthread_mutexattr_settype(pthread_mutexattr_t*, int) @trusted; +} else { static assert(false, "Unsupported platform"); @@ -906,6 +953,10 @@ else version (Solaris) else version( CRuntime_Bionic ) { int pthread_getcpuclockid(pthread_t, clockid_t*); +} +else version( CRuntime_Musl ) +{ + } else { @@ -961,6 +1012,10 @@ else version( CRuntime_Bionic ) { int pthread_rwlock_timedrdlock(pthread_rwlock_t*, in timespec*); int pthread_rwlock_timedwrlock(pthread_rwlock_t*, in timespec*); +} +else version( CRuntime_Musl ) +{ + } else { @@ -1156,6 +1211,18 @@ else version (CRuntime_Bionic) int pthread_getschedparam(pthread_t, int*, sched_param*); int pthread_setschedparam(pthread_t, int, in sched_param*); } +else version (CRuntime_Musl) +{ + enum + { + PTHREAD_SCOPE_SYSTEM, + PTHREAD_SCOPE_PROCESS + } + + int pthread_getschedparam(pthread_t, int*, sched_param*); + int pthread_setschedparam(pthread_t, int, in sched_param*); + int pthread_setschedprio(pthread_t, int); +} else { static assert(false, "Unsupported platform"); @@ -1236,6 +1303,11 @@ else version (CRuntime_Bionic) int pthread_attr_setstackaddr(pthread_attr_t*, void*); int pthread_attr_setstacksize(pthread_attr_t*, size_t); } +else version (CRuntime_Musl) +{ + int pthread_attr_getstack(in pthread_attr_t*, void**, size_t*); + int pthread_attr_setstacksize(pthread_attr_t*, size_t); +} else { static assert(false, "Unsupported platform"); @@ -1309,6 +1381,10 @@ else version (CRuntime_Bionic) int pthread_mutexattr_setpshared(pthread_mutexattr_t*, int); int pthread_rwlockattr_getpshared(pthread_rwlockattr_t*, int*); int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int); +} +else version (CRuntime_Musl) +{ + } else { diff --git a/src/core/sys/posix/pwd.d b/src/core/sys/posix/pwd.d index 34590c7fe5..8b012d8123 100644 --- a/src/core/sys/posix/pwd.d +++ b/src/core/sys/posix/pwd.d @@ -153,6 +153,18 @@ else version( CRuntime_Bionic ) char* pw_shell; } } +else version( CRuntime_Musl ) +{ + struct passwd { + char *pw_name; + char *pw_passwd; + uid_t pw_uid; + gid_t pw_gid; + char *pw_gecos; + char *pw_dir; + char *pw_shell; + } +} else { static assert(false, "Unsupported platform"); @@ -204,6 +216,9 @@ else version (Solaris) else version( CRuntime_Bionic ) { } +else version( CRuntime_Musl ) +{ +} else { static assert(false, "Unsupported platform"); @@ -258,6 +273,11 @@ else version ( CRuntime_Bionic ) { void endpwent(); } +else version( CRuntime_Musl ) +{ + int getpwnam_r(in char*, passwd*, char*, size_t, passwd**); + int getpwuid_r(uid_t, passwd*, char*, size_t, passwd**); +} else { static assert(false, "Unsupported platform"); diff --git a/src/core/sys/posix/sched.d b/src/core/sys/posix/sched.d index 3f93b989bb..0d4c8e0925 100644 --- a/src/core/sys/posix/sched.d +++ b/src/core/sys/posix/sched.d @@ -69,6 +69,16 @@ version( CRuntime_Glibc ) enum SCHED_RR = 2; //SCHED_SPORADIC (SS|TSP) } +else version( CRuntime_Musl ) +{ + struct sched_param { + int sched_priority; + int sched_ss_low_priority; + timespec sched_ss_repl_period; + timespec sched_ss_init_budget; + int sched_ss_max_repl; + } +} else version( Darwin ) { enum SCHED_OTHER = 1; @@ -191,6 +201,10 @@ else version (CRuntime_Bionic) { int sched_yield(); } +else version (CRuntime_Musl) +{ + int sched_yield(); +} else { static assert(false, "Unsupported platform"); @@ -247,6 +261,12 @@ else version (CRuntime_Bionic) int sched_get_priority_min(int); int sched_rr_get_interval(pid_t, timespec*); } +else version (CRuntime_Musl) +{ + int sched_get_priority_max(int); + int sched_get_priority_min(int); + int sched_rr_get_interval(pid_t, timespec*); +} else { static assert(false, "Unsupported platform"); diff --git a/src/core/sys/posix/semaphore.d b/src/core/sys/posix/semaphore.d index 32027eefb9..0d0d2367e6 100644 --- a/src/core/sys/posix/semaphore.d +++ b/src/core/sys/posix/semaphore.d @@ -125,6 +125,12 @@ else version( CRuntime_Bionic ) enum SEM_FAILED = null; } +else version( CRuntime_Musl ) +{ + struct sem_t { + int[4*long.sizeof/int.sizeof] __val; + } +} else { static assert(false, "Unsupported platform"); @@ -175,6 +181,10 @@ else version( CRuntime_Bionic ) { int sem_timedwait(sem_t*, in timespec*); } +else version( CRuntime_Musl ) +{ + int sem_timedwait(sem_t*, in timespec*); +} else { static assert(false, "Unsupported platform"); diff --git a/src/core/sys/posix/signal.d b/src/core/sys/posix/signal.d index 350df9940c..208d4a130e 100644 --- a/src/core/sys/posix/signal.d +++ b/src/core/sys/posix/signal.d @@ -544,6 +544,28 @@ version( CRuntime_Glibc ) void function() sa_restorer; } } +version( CRuntime_Musl ) +{ + struct sigaction_t + { + static if( true /* __USE_POSIX199309 */ ) + { + union + { + sigfn_t sa_handler; + sigactfn_t sa_sigaction; + } + } + else + { + sigfn_t sa_handler; + } + sigset_t sa_mask; + int sa_flags; + + void function() sa_restorer; + } +} else version( FreeBSD ) { struct sigaction_t @@ -1394,6 +1416,86 @@ else version( CRuntime_Bionic ) int sigsuspend(in sigset_t*); int sigwait(in sigset_t*, int*); } +else version( CRuntime_Musl ) +{ + struct sigset_t { + ulong[128/long.sizeof] __bits; + } + struct siginfo_t { + int si_signo, si_errno, si_code; + union __si_fields_t { + char[128 - 2*int.sizeof - long.sizeof] __pad; + struct __si_common_t { + union __first_t { + struct __piduid_t { + pid_t si_pid; + uid_t si_uid; + } + __piduid_t __piduid; + + struct __timer_t { + int si_timerid; + int si_overrun; + } + __timer_t __timer; + } + __first_t __first; + + union __second_t { + sigval si_value; + struct __sigchld_t { + int si_status; + clock_t si_utime, si_stime; + } + __sigchld_t __sigchld; + } + __second_t __second; + } + __si_common_t __si_common; + + struct __sigfault_t { + void *si_addr; + short si_addr_lsb; + union __first_t { + struct __addr_bnd_t { + void *si_lower; + void *si_upper; + } + __addr_bnd_t __addr_bnd; + uint si_pkey; + } + __first_t __first; + } + __sigfault_t __sigfault; + + struct __sigpoll_t { + long si_band; + int si_fd; + } + __sigpoll_t __sigpoll; + + struct __sigsys_t { + void *si_call_addr; + int si_syscall; + uint si_arch; + } + __sigsys_t __sigsys; + } + __si_fields_t __si_fields; + } + + int kill(pid_t, int); + int sigaction(int, in sigaction_t*, sigaction_t*); + int sigaddset(sigset_t*, int); + int sigdelset(sigset_t*, int); + int sigemptyset(sigset_t*); + int sigfillset(sigset_t*); + int sigismember(in sigset_t*, int); + int sigpending(sigset_t*); + int sigprocmask(int, in sigset_t*, sigset_t*); + int sigsuspend(in sigset_t*); + int sigwait(in sigset_t*, int*); +} else { static assert(false, "Unsupported platform"); @@ -2428,6 +2530,9 @@ else version (CRuntime_Bionic) int sigaltstack(in stack_t*, stack_t*); int siginterrupt(int, int); } +else version( CRuntime_Musl ) +{ +} else { static assert(false, "Unsupported platform"); @@ -2644,6 +2749,10 @@ else version( CRuntime_Bionic ) } _sigev_thread_t _sigev_thread; } _sigev_un_t _sigev_un; } +} +else version( CRuntime_Musl ) +{ + } else { @@ -2693,6 +2802,11 @@ else version( CRuntime_Bionic ) int pthread_kill(pthread_t, int); int pthread_sigmask(int, in sigset_t*, sigset_t*); } +else version( CRuntime_Musl ) +{ + int pthread_kill(pthread_t, int); + int pthread_sigmask(int, in sigset_t*, sigset_t*); +} else { static assert(false, "Unsupported platform"); diff --git a/src/core/sys/posix/stdio.d b/src/core/sys/posix/stdio.d index 2650af5f9d..f3697a3cd6 100644 --- a/src/core/sys/posix/stdio.d +++ b/src/core/sys/posix/stdio.d @@ -283,6 +283,10 @@ version( CRuntime_Glibc ) { enum P_tmpdir = "/tmp"; } +version( CRuntime_Musl ) +{ + enum P_tmpdir = "/tmp"; +} version( Darwin ) { enum P_tmpdir = "/var/tmp"; diff --git a/src/core/sys/posix/stdlib.d b/src/core/sys/posix/stdlib.d index 3d239469f2..f187682e2f 100644 --- a/src/core/sys/posix/stdlib.d +++ b/src/core/sys/posix/stdlib.d @@ -179,6 +179,11 @@ else version( Solaris ) void* valloc(size_t); // LEGACY non-standard } +else version( CRuntime_Musl ) +{ + int setenv(in char*, in char*, int); + int unsetenv(in char*); +} // // Thread-Safe Functions (TSF) @@ -493,6 +498,13 @@ else version( CRuntime_Bionic ) void srandom(uint s) { srand48(s); } int unlockpt(int); } +else version( CRuntime_Musl ) +{ + char* realpath(in char*, char*); + int putenv(char*); + int mkstemp(char*); + +} else version( Solaris ) { //WNOHANG (defined in core.sys.posix.sys.wait) diff --git a/src/core/sys/posix/sys/ioctl.d b/src/core/sys/posix/sys/ioctl.d index 8c2e778d82..143a12c539 100644 --- a/src/core/sys/posix/sys/ioctl.d +++ b/src/core/sys/posix/sys/ioctl.d @@ -386,6 +386,10 @@ else version (Solaris) else version (CRuntime_Bionic) { int ioctl(int, int, ...); +} +else version (CRuntime_Musl) +{ + } else { diff --git a/src/core/sys/posix/sys/mman.d b/src/core/sys/posix/sys/mman.d index c3cfec645d..e02b2e77ba 100644 --- a/src/core/sys/posix/sys/mman.d +++ b/src/core/sys/posix/sys/mman.d @@ -100,6 +100,9 @@ else version (Solaris) else version (CRuntime_Bionic) { } +else version (CRuntime_Musl) +{ +} else { static assert(false, "Unsupported platform"); @@ -157,6 +160,13 @@ else version (CRuntime_Bionic) enum PROT_WRITE = 0x02; enum PROT_EXEC = 0x04; } +else version (CRuntime_Musl) +{ + enum PROT_NONE = 0x0; + enum PROT_READ = 0x1; + enum PROT_WRITE = 0x2; + enum PROT_EXEC = 0x4; +} else { static assert(false, "Unsupported platform"); @@ -204,6 +214,16 @@ else version (CRuntime_Bionic) void* mmap(void*, size_t, int, int, int, off_t); int munmap(void*, size_t); } +else version (CRuntime_Musl) +{ + static if (__USE_LARGEFILE64) void* mmap64(void*, size_t, int, int, int, off_t); + static if (__USE_FILE_OFFSET64) + alias mmap = mmap64; + else + void* mmap(void*, size_t, int, int, int, off_t); + int munmap(void*, size_t); + +} else { static assert(false, "Unsupported platform"); @@ -404,6 +424,19 @@ else version (CRuntime_Bionic) int msync(in void*, size_t, int); } +else version (CRuntime_Musl) +{ + enum MAP_SHARED = 0x01; + enum MAP_PRIVATE = 0x02; + enum MAP_FIXED = 0x10; + + enum MAP_FAILED = cast(void*) -1; + enum MAP_ANON = 0x20; + enum MS_ASYNC = 1; + enum MS_INVALIDATE = 2; + enum MS_SYNC = 4; + int msync(void*, size_t, int); +} else { static assert(false, "Unsupported platform"); @@ -497,6 +530,9 @@ else version (CRuntime_Bionic) int mlockall(int); int munlockall(); } +else version (CRuntime_Musl) +{ +} else { static assert(false, "Unsupported platform"); @@ -540,6 +576,9 @@ else version (CRuntime_Bionic) int mlock(in void*, size_t); int munlock(in void*, size_t); } +else version (CRuntime_Musl) +{ +} else { static assert(false, "Unsupported platform"); @@ -576,6 +615,10 @@ else version (CRuntime_Bionic) { int mprotect(in void*, size_t, int); } +else version (CRuntime_Musl) +{ + int mprotect(void*, size_t, int); +} else { static assert(false, "Unsupported platform"); @@ -617,6 +660,9 @@ else version (Solaris) else version (CRuntime_Bionic) { } +else version (CRuntime_Musl) +{ +} else { static assert(false, "Unsupported platform"); diff --git a/src/core/sys/posix/sys/resource.d b/src/core/sys/posix/sys/resource.d index 2823aa5069..08d288668c 100644 --- a/src/core/sys/posix/sys/resource.d +++ b/src/core/sys/posix/sys/resource.d @@ -405,6 +405,24 @@ else version (CRuntime_Bionic) RLIMIT_AS = 9, } } +else version (CRuntime_Musl) +{ + alias ulong rlim_t; + enum + { + RLIMIT_CPU = 0, + RLIMIT_FSIZE = 1, + RLIMIT_DATA = 2, + RLIMIT_STACK = 3, + RLIMIT_CORE = 4, + RLIMIT_NOFILE = 7, + RLIMIT_AS = 9, + } + int getrlimit(int, rlimit*); + int setrlimit(int, in rlimit*); + alias getrlimit getrlimit64; + alias setrlimit setrlimit64; +} else static assert (false, "Unsupported platform"); struct rlimit diff --git a/src/core/sys/posix/sys/select.d b/src/core/sys/posix/sys/select.d index 47fe922de1..7ecf65d7c5 100644 --- a/src/core/sys/posix/sys/select.d +++ b/src/core/sys/posix/sys/select.d @@ -362,6 +362,53 @@ else version( CRuntime_Bionic ) int pselect(int, fd_set*, fd_set*, fd_set*, in timespec*, in sigset_t*); int select(int, fd_set*, fd_set*, fd_set*, timeval*); } +else version( CRuntime_Musl ) +{ + enum FD_SETSIZE = 1024; + + alias ulong fd_mask; + + private + { + enum uint __NFDBITS = 8 * fd_mask.sizeof; + + extern (D) auto __FDELT( int d ) pure + { + return d / __NFDBITS; + } + + extern (D) auto __FDMASK( int d ) pure + { + return cast(fd_mask) 1 << ( d % __NFDBITS ); + } + } + + struct fd_set { + ulong[FD_SETSIZE / 8 / long.sizeof] fds_bits; + } + + extern (D) void FD_CLR( int fd, fd_set* fdset ) pure + { + fdset.fds_bits[__FDELT( fd )] &= ~__FDMASK( fd ); + } + + extern (D) bool FD_ISSET( int fd, const(fd_set)* fdset ) pure + { + return (fdset.fds_bits[__FDELT( fd )] & __FDMASK( fd )) != 0; + } + + extern (D) void FD_SET( int fd, fd_set* fdset ) pure + { + fdset.fds_bits[__FDELT( fd )] |= __FDMASK( fd ); + } + + extern (D) void FD_ZERO( fd_set* fdset ) pure + { + fdset.fds_bits[0 .. $] = 0; + } + int pselect(int, fd_set*, fd_set*, fd_set*, in timespec*, in sigset_t*); + int select(int, fd_set*, fd_set*, fd_set*, timeval*); +} else { static assert(false, "Unsupported platform"); diff --git a/src/core/sys/posix/sys/socket.d b/src/core/sys/posix/sys/socket.d index d5635ab200..bad2500da0 100644 --- a/src/core/sys/posix/sys/socket.d +++ b/src/core/sys/posix/sys/socket.d @@ -1368,7 +1368,7 @@ else version( CRuntime_Bionic ) enum { - SOL_SOCKET = 1 + SOL_SOCKET = 1 } enum @@ -1484,6 +1484,116 @@ else version( CRuntime_Bionic ) int socket(int, int, int); int socketpair(int, int, int, ref int[2]); } +else version( CRuntime_Musl ) +{ + alias uint socklen_t; + alias ubyte sa_family_t; + + struct sockaddr + { + sa_family_t sa_family; + byte[14] sa_data; + } + enum { + SOCK_STREAM = 1, + SOCK_DGRAM = 2, + SOCK_RAW = 3, + SOCK_RDM = 4, + SOCK_SEQPACKET = 5, + SOCK_DCCP = 6, + SOCK_PACKET = 10 + } + enum + { + AF_UNSPEC = 0, + AF_LOCAL = 1, + AF_UNIX = AF_LOCAL, + AF_FILE = AF_LOCAL, + AF_INET = 2, + AF_AX25 = 3, + AF_IPX = 4, + AF_APPLETALK = 5, + PF_APPLETALK = AF_APPLETALK, + PF_IPX = AF_IPX + } + + enum + { + SHUT_RD, + SHUT_WR, + SHUT_RDWR + } + + enum + { + SOL_SOCKET = 1 + } + + enum + { + SO_DEBUG = 1, + SO_REUSEADDR = 2, + SO_TYPE = 3, + SO_ERROR = 4, + SO_DONTROUTE = 5, + SO_BROADCAST = 6, + SO_SNDBUF = 7, + SO_RCVBUF = 8, + SO_KEEPALIVE = 9, + SO_OOBINLINE = 10, + SO_LINGER = 13, + SO_RCVLOWAT = 18, + SO_SNDLOWAT = 19, + SO_RCVTIMEO = 20, + SO_SNDTIMEO = 21, + SO_ACCEPTCONN = 30 + } + + enum : uint + { + MSG_OOB = 0x01, + MSG_PEEK = 0x02, + MSG_DONTROUTE = 0x04, + MSG_CTRUNC = 0x08, + MSG_TRUNC = 0x20, + MSG_EOR = 0x80, + MSG_WAITALL = 0x100, + MSG_NOSIGNAL = 0x4000 + } + + struct linger + { + int l_onoff; + int l_linger; + } + struct msghdr { + void *msg_name; + socklen_t msg_namelen; + iovec *msg_iov; + int msg_iovlen, __pad1; + void *msg_control; + socklen_t msg_controllen, __pad2; + int msg_flags; + } + int accept(int, sockaddr*, socklen_t*); + int bind(int, in sockaddr*, socklen_t); + int connect(int, in sockaddr*, socklen_t); + int getpeername(int, sockaddr*, socklen_t*); + int getsockname(int, sockaddr*, socklen_t*); + int getsockopt(int, int, int, void*, socklen_t*); + int listen(int, int); + ssize_t recv(int, void*, size_t, int); + ssize_t recvfrom(int, void*, size_t, int, sockaddr*, socklen_t*); + ssize_t recvmsg(int, msghdr*, int); + ssize_t send(int, in void*, size_t, int); + ssize_t sendmsg(int, in msghdr*, int); + ssize_t sendto(int, in void*, size_t, int, in sockaddr*, socklen_t); + int setsockopt(int, int, int, in void*, socklen_t); + int shutdown(int, int); + int socket(int, int, int); + int sockatmark(int); + int socketpair(int, int, int, ref int[2]); +} else { static assert(false, "Unsupported platform"); @@ -1538,6 +1648,10 @@ else version( CRuntime_Bionic ) AF_INET6 = 10 } } +else version( CRuntime_Musl ) +{ + enum AF_INET6 = 10; +} else { static assert(false, "Unsupported platform"); @@ -1592,6 +1706,9 @@ else version( CRuntime_Bionic ) SOCK_RAW = 3 } } +else version( CRuntime_Musl ) +{ +} else { static assert(false, "Unsupported platform"); diff --git a/src/core/sys/posix/sys/stat.d b/src/core/sys/posix/sys/stat.d index 29c1423d95..c125e58c50 100644 --- a/src/core/sys/posix/sys/stat.d +++ b/src/core/sys/posix/sys/stat.d @@ -1115,6 +1115,70 @@ else version( CRuntime_Bionic ) int utimensat(int dirfd, const char *pathname, ref const(timespec)[2] times, int flags); } +else version (CRuntime_Musl) +{ + alias __mode_t = uint; + enum { + S_IRUSR = 0x100, // octal 0400 + S_IWUSR = 0x080, // octal 0200 + S_IXUSR = 0x040, // octal 0100 + S_IRWXU = S_IRUSR | S_IWUSR | S_IXUSR, + + S_IRGRP = S_IRUSR >> 3, + S_IWGRP = S_IWUSR >> 3, + S_IXGRP = S_IXUSR >> 3, + S_IRWXG = S_IRWXU >> 3, + + S_IROTH = S_IRGRP >> 3, + S_IWOTH = S_IWGRP >> 3, + S_IXOTH = S_IXGRP >> 3, + S_IRWXO = S_IRWXG >> 3, + + S_ISUID = 0x800, // octal 04000 + S_ISGID = 0x400, // octal 02000 + S_ISVTX = 0x200, // octal 01000 + } + struct stat_t { + dev_t st_dev; + ino_t st_ino; + nlink_t st_nlink; + + mode_t st_mode; + uid_t st_uid; + gid_t st_gid; + uint __pad0; + dev_t st_rdev; + off_t st_size; + blksize_t st_blksize; + blkcnt_t st_blocks; + + timespec st_atim; + timespec st_mtim; + timespec st_ctim; + extern(D) + { + @property ref time_t st_atime() return { return st_atim.tv_sec; } + @property ref time_t st_mtime() return { return st_mtim.tv_sec; } + @property ref time_t st_ctime() return { return st_ctim.tv_sec; } + } + long[3] __unused; + } + private + { + extern (D) bool S_ISTYPE( mode_t mode, uint mask ) + { + return ( mode & S_IFMT ) == mask; + } + } + + extern (D) bool S_ISBLK( mode_t mode ) { return S_ISTYPE( mode, S_IFBLK ); } + extern (D) bool S_ISCHR( mode_t mode ) { return S_ISTYPE( mode, S_IFCHR ); } + extern (D) bool S_ISDIR( mode_t mode ) { return S_ISTYPE( mode, S_IFDIR ); } + extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO ); } + extern (D) bool S_ISREG( mode_t mode ) { return S_ISTYPE( mode, S_IFREG ); } + extern (D) bool S_ISLNK( mode_t mode ) { return S_ISTYPE( mode, S_IFLNK ); } + extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); } +} else { static assert(false, "Unsupported platform"); @@ -1223,6 +1287,16 @@ else version( CRuntime_Bionic ) int lstat(in char*, stat_t*); int stat(in char*, stat_t*); } +else version( CRuntime_Musl ) +{ + int stat(in char*, stat_t*); + int fstat(int, stat_t*); + int lstat(in char*, stat_t*); + + alias fstat fstat64; + alias lstat lstat64; + alias stat stat64; +} // // Typed Memory Objects (TYM) @@ -1327,6 +1401,21 @@ else version( CRuntime_Bionic ) int mknod(in char*, mode_t, dev_t); } +else version( CRuntime_Musl ) +{ + enum { + S_IFMT = 0xF000, // octal 0170000 + S_IFBLK = 0x6000, // octal 0060000 + S_IFCHR = 0x2000, // octal 0020000 + S_IFIFO = 0x1000, // octal 0010000 + S_IFREG = 0x8000, // octal 0100000 + S_IFDIR = 0x4000, // octal 0040000 + S_IFLNK = 0xA000, // octal 0120000 + S_IFSOCK = 0xC000, // octal 0140000 + } + + int mknod(in char*, mode_t, dev_t); +} else { static assert(false, "Unsupported platform"); diff --git a/src/core/sys/posix/sys/time.d b/src/core/sys/posix/sys/time.d index a4bfd68f09..f599eb0bf2 100644 --- a/src/core/sys/posix/sys/time.d +++ b/src/core/sys/posix/sys/time.d @@ -82,6 +82,15 @@ version( CRuntime_Glibc ) int setitimer(int, in itimerval*, itimerval*); int utimes(in char*, ref const(timeval)[2]); // LEGACY } +else version( CRuntime_Musl ) +{ + struct timeval + { + time_t tv_sec; + suseconds_t tv_usec; + } + int gettimeofday(timeval*, void*); +} else version( Darwin ) { struct timeval diff --git a/src/core/sys/posix/sys/types.d b/src/core/sys/posix/sys/types.d index ae87677c9e..6ebee8424e 100644 --- a/src/core/sys/posix/sys/types.d +++ b/src/core/sys/posix/sys/types.d @@ -110,6 +110,23 @@ version( CRuntime_Glibc ) alias slong_t time_t; alias uint uid_t; } +else version( CRuntime_Musl ) +{ + alias long blksize_t; + alias ulong nlink_t; + alias long dev_t; + alias long blkcnt_t; + alias ulong ino_t; + alias long off_t; + alias long _Addr; + alias int pid_t; + alias uint uid_t; + alias uint gid_t; + alias long time_t; + alias long clock_t; + alias ulong pthread_t; + alias _Addr ssize_t; +} else version( Darwin ) { alias long blkcnt_t; @@ -335,6 +352,22 @@ else version( CRuntime_Bionic ) alias c_long suseconds_t; alias c_long useconds_t; } +else version( CRuntime_Musl ) +{ + static if( __USE_FILE_OFFSET64 ) + { + alias ulong fsblkcnt_t; + alias ulong fsfilcnt_t; + } + else + { + alias ulong_t fsblkcnt_t; + alias ulong_t fsfilcnt_t; + } + alias uint mode_t; + alias uint id_t; + alias long suseconds_t; +} else { static assert(false, "Unsupported platform"); @@ -604,6 +637,37 @@ version (CRuntime_Glibc) alias c_ulong pthread_t; } +else version( CRuntime_Musl ) +{ + union pthread_attr_t + { + int[14] __i; + ulong[7] __s; + } + union pthread_cond_t + { + int[12] __i; + void*[6] __p; + } + union pthread_mutex_t + { + int[10] __i; + void*[5] __p; + } + union pthread_rwlock_t + { + int[14] __i; + void*[7] __p; + } + struct pthread_rwlockattr_t + { + uint[2] __attr; + } + alias uint pthread_key_t; + alias uint pthread_condattr_t; + alias uint pthread_mutexattr_t; + alias int pthread_once_t; +} else version( Darwin ) { version( D_LP64 ) @@ -972,6 +1036,9 @@ else version (Solaris) else version( CRuntime_Bionic ) { } +else version( CRuntime_Musl ) +{ +} else { static assert(false, "Unsupported platform"); diff --git a/src/core/sys/posix/sys/uio.d b/src/core/sys/posix/sys/uio.d index 9b5758742c..6a1e02ce17 100644 --- a/src/core/sys/posix/sys/uio.d +++ b/src/core/sys/posix/sys/uio.d @@ -112,6 +112,14 @@ else version( CRuntime_Bionic ) int readv(int, in iovec*, int); int writev(int, in iovec*, int); } +else version( CRuntime_Musl ) +{ + struct iovec + { + void* iov_base; + uint iov_len; + } +} else { static assert(false, "Unsupported platform"); diff --git a/src/core/sys/posix/sys/wait.d b/src/core/sys/posix/sys/wait.d index 6d39de7f8f..6f85a8dd43 100644 --- a/src/core/sys/posix/sys/wait.d +++ b/src/core/sys/posix/sys/wait.d @@ -169,6 +169,19 @@ else version( CRuntime_Bionic ) extern (D) int WSTOPSIG( int status ) { return WEXITSTATUS(status); } extern (D) int WTERMSIG( int status ) { return status & 0x7F; } } +else version( CRuntime_Musl ) +{ + enum WNOHANG = 1; + enum WUNTRACED = 2; + + extern (D) int WEXITSTATUS( int status ) { return ( status & 0xFF00 ) >> 8; } + extern (D) int WIFCONTINUED( int status ) { return status == 0xffff; } + extern (D) bool WIFEXITED( int status ) { return WTERMSIG( status ) == 0; } + extern (D) bool WIFSIGNALED( int status ) { return (status&0xffff)-1U < 0xffU; } + extern (D) bool WIFSTOPPED( int status ) { return cast(short)(((status&0xffff)*0x10001)>>8) > 0x7f00; } + extern (D) int WTERMSIG( int status ) { return status & 0x7F; } + alias WEXITSTATUS WSTOPSIG; +} else { static assert(false, "Unsupported platform"); @@ -284,6 +297,9 @@ else version( CRuntime_Bionic ) int waitid(idtype_t, id_t, siginfo_t*, int); } +else version( CRuntime_Musl ) +{ +} else { static assert(false, "Unsupported platform"); diff --git a/src/core/sys/posix/time.d b/src/core/sys/posix/time.d index 2bf9e96fdc..b369c3fa85 100644 --- a/src/core/sys/posix/time.d +++ b/src/core/sys/posix/time.d @@ -72,6 +72,10 @@ else version (Solaris) else version (CRuntime_Bionic) { // Not supported. +} +else version (CRuntime_Musl) +{ + } else { @@ -344,6 +348,16 @@ else version( CRuntime_Bionic ) int timer_getoverrun(timer_t); int timer_settime(timer_t, int, in itimerspec*, itimerspec*); } +else version( CRuntime_Musl ) +{ + alias int clockid_t; + + enum CLOCK_REALTIME = 0; + int clock_getres(clockid_t, timespec*); + int clock_gettime(clockid_t, timespec*); + int clock_settime(clockid_t, in timespec*); + int clock_nanosleep(clockid_t, int, in timespec*, timespec*); +} else { static assert(false, "Unsupported platform"); @@ -400,6 +414,10 @@ else version (CRuntime_Bionic) char* ctime_r(in time_t*, char*); tm* gmtime_r(in time_t*, tm*); tm* localtime_r(in time_t*, tm*); +} +else version (CRuntime_Musl) +{ + } else { @@ -461,6 +479,10 @@ else version( CRuntime_Bionic ) char* strptime(in char*, in char*, tm*); } +else version( CRuntime_Musl ) +{ + int nanosleep(in timespec*, timespec*); +} else { static assert(false, "Unsupported platform"); diff --git a/src/core/sys/posix/unistd.d b/src/core/sys/posix/unistd.d index 8821e544dd..fa59833f65 100644 --- a/src/core/sys/posix/unistd.d +++ b/src/core/sys/posix/unistd.d @@ -167,6 +167,13 @@ else version( CRuntime_Bionic ) off_t lseek(int, off_t, int) @trusted; int ftruncate(int, off_t) @trusted; } +else version( CRuntime_Musl ) +{ + int ftruncate(int, off_t); + alias ftruncate ftruncate64; + off_t lseek(int, off_t, int) @trusted; + alias lseek lseek64; +} version( CRuntime_Glibc ) { @@ -1237,6 +1244,248 @@ else version( Solaris ) enum _PC_LAST = 101; } +else version( CRuntime_Musl ) +{ + enum F_OK = 0; + enum R_OK = 4; + enum W_OK = 2; + enum X_OK = 1; + + enum F_ULOCK = 0; + enum F_LOCK = 1; + enum F_TLOCK = 2; + enum F_TEST = 3; + + enum + { + _CS_PATH, + _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS, + _CS_GNU_LIBC_VERSION, + _CS_GNU_LIBPTHREAD_VERSION, + _CS_POSIX_V5_WIDTH_RESTRICTED_ENVS, + _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS, + + _CS_POSIX_V6_ILP32_OFF32_CFLAGS = 1116, + _CS_POSIX_V6_ILP32_OFF32_LDFLAGS, + _CS_POSIX_V6_ILP32_OFF32_LIBS, + _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS, + _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS, + _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS, + _CS_POSIX_V6_ILP32_OFFBIG_LIBS, + _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS, + _CS_POSIX_V6_LP64_OFF64_CFLAGS, + _CS_POSIX_V6_LP64_OFF64_LDFLAGS, + _CS_POSIX_V6_LP64_OFF64_LIBS, + _CS_POSIX_V6_LP64_OFF64_LINTFLAGS, + _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS, + _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS, + _CS_POSIX_V6_LPBIG_OFFBIG_LIBS, + _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS, + _CS_POSIX_V7_ILP32_OFF32_CFLAGS, + _CS_POSIX_V7_ILP32_OFF32_LDFLAGS, + _CS_POSIX_V7_ILP32_OFF32_LIBS, + _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS, + _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS, + _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS, + _CS_POSIX_V7_ILP32_OFFBIG_LIBS, + _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS, + _CS_POSIX_V7_LP64_OFF64_CFLAGS, + _CS_POSIX_V7_LP64_OFF64_LDFLAGS, + _CS_POSIX_V7_LP64_OFF64_LIBS, + _CS_POSIX_V7_LP64_OFF64_LINTFLAGS, + _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS, + _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS, + _CS_POSIX_V7_LPBIG_OFFBIG_LIBS, + _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS, + _CS_V6_ENV, + _CS_V7_ENV + } + + enum + { + _PC_LINK_MAX, + _PC_MAX_CANON, + _PC_MAX_INPUT, + _PC_NAME_MAX, + _PC_PATH_MAX, + _PC_PIPE_BUF, + _PC_CHOWN_RESTRICTED, + _PC_NO_TRUNC, + _PC_VDISABLE, + _PC_SYNC_IO, + _PC_ASYNC_IO, + _PC_PRIO_IO, + _PC_SOCK_MAXBUF, + _PC_FILESIZEBITS, + _PC_REC_INCR_XFER_SIZE, + _PC_REC_MAX_XFER_SIZE, + _PC_REC_MIN_XFER_SIZE, + _PC_REC_XFER_ALIGN, + _PC_ALLOC_SIZE_MIN, + _PC_SYMLINK_MAX, + _PC_2_SYMLINKS + } + + enum + { + _SC_ARG_MAX, + _SC_CHILD_MAX, + _SC_CLK_TCK, + _SC_NGROUPS_MAX, + _SC_OPEN_MAX, + _SC_STREAM_MAX, + _SC_TZNAME_MAX, + _SC_JOB_CONTROL, + _SC_SAVED_IDS, + _SC_REALTIME_SIGNALS, + _SC_PRIORITY_SCHEDULING, + _SC_TIMERS, + _SC_ASYNCHRONOUS_IO, + _SC_PRIORITIZED_IO, + _SC_SYNCHRONIZED_IO, + _SC_FSYNC, + _SC_MAPPED_FILES, + _SC_MEMLOCK, + _SC_MEMLOCK_RANGE, + _SC_MEMORY_PROTECTION, + _SC_MESSAGE_PASSING, + _SC_SEMAPHORES, + _SC_SHARED_MEMORY_OBJECTS, + _SC_AIO_LISTIO_MAX, + _SC_AIO_MAX, + _SC_AIO_PRIO_DELTA_MAX, + _SC_DELAYTIMER_MAX, + _SC_MQ_OPEN_MAX, + _SC_MQ_PRIO_MAX, + _SC_VERSION, + _SC_PAGE_SIZE, + _SC_PAGESIZE = _SC_PAGE_SIZE, + _SC_RTSIG_MAX, + _SC_SEM_NSEMS_MAX, + _SC_SEM_VALUE_MAX, + _SC_SIGQUEUE_MAX, + _SC_TIMER_MAX, + _SC_BC_BASE_MAX, + _SC_BC_DIM_MAX, + _SC_BC_SCALE_MAX, + _SC_BC_STRING_MAX, + _SC_COLL_WEIGHTS_MAX, + + _SC_EXPR_NEST_MAX = 42, + _SC_LINE_MAX, + _SC_RE_DUP_MAX, + + _SC_2_VERSION = 46, + _SC_2_C_BIND, + _SC_2_C_DEV, + _SC_2_FORT_DEV, + _SC_2_FORT_RUN, + _SC_2_SW_DEV, + _SC_2_LOCALEDEF, + + _SC_UIO_MAXIOV = 60, + _SC_IOV_MAX = _SC_UIO_MAXIOV, + + _SC_THREADS = 67, + _SC_THREAD_SAFE_FUNCTIONS, + _SC_GETGR_R_SIZE_MAX, + _SC_GETPW_R_SIZE_MAX, + _SC_LOGIN_NAME_MAX, + _SC_TTY_NAME_MAX, + _SC_THREAD_DESTRUCTOR_ITERATIONS, + _SC_THREAD_KEYS_MAX, + _SC_THREAD_STACK_MIN, + _SC_THREAD_THREADS_MAX, + _SC_THREAD_ATTR_STACKADDR, + _SC_THREAD_ATTR_STACKSIZE, + _SC_THREAD_PRIORITY_SCHEDULING, + _SC_THREAD_PRIO_INHERIT, + _SC_THREAD_PRIO_PROTECT, + _SC_THREAD_PROCESS_SHARED, + + _SC_NPROCESSORS_CONF, + _SC_NPROCESSORS_ONLN, + _SC_PHYS_PAGES, + _SC_AVPHYS_PAGES, + _SC_ATEXIT_MAX, + _SC_PASS_MAX, + + _SC_XOPEN_VERSION, + _SC_XOPEN_XCU_VERSION, + _SC_XOPEN_UNIX, + _SC_XOPEN_CRYPT, + _SC_XOPEN_ENH_I18N, + _SC_XOPEN_SHM, + + _SC_2_CHAR_TERM, + _SC_2_UPE = 97, + + _SC_XOPEN_XPG2, + _SC_XOPEN_XPG3, + _SC_XOPEN_XPG4, + + _SC_NZERO = 109, + + _SC_XBS5_ILP32_OFF32 = 125, + _SC_XBS5_ILP32_OFFBIG, + _SC_XBS5_LP64_OFF64, + _SC_XBS5_LPBIG_OFFBIG, + + _SC_XOPEN_LEGACY, + _SC_XOPEN_REALTIME, + _SC_XOPEN_REALTIME_THREADS, + + _SC_ADVISORY_INFO, + _SC_BARRIERS, + _SC_CLOCK_SELECTION = 137, + _SC_CPUTIME, + _SC_THREAD_CPUTIME, + _SC_MONOTONIC_CLOCK = 149, + _SC_READER_WRITER_LOCKS = 153, + _SC_SPIN_LOCKS, + _SC_REGEXP, + _SC_SHELL = 157, + _SC_SPAWN = 159, + _SC_SPORADIC_SERVER, + _SC_THREAD_SPORADIC_SERVER, + _SC_TIMEOUTS = 164, + _SC_TYPED_MEMORY_OBJECTS, + _SC_2_PBS = 168, + _SC_2_PBS_ACCOUNTING, + _SC_2_PBS_LOCATE, + _SC_2_PBS_MESSAGE, + _SC_2_PBS_TRACK, + _SC_SYMLOOP_MAX, + _SC_STREAMS, + _SC_2_PBS_CHECKPOINT, + + _SC_V6_ILP32_OFF32, + _SC_V6_ILP32_OFFBIG, + _SC_V6_LP64_OFF64, + _SC_V6_LPBIG_OFFBIG, + + _SC_HOST_NAME_MAX, + _SC_TRACE, + _SC_TRACE_EVENT_FILTER, + _SC_TRACE_INHERIT, + _SC_TRACE_LOG, + + _SC_IPV6 = 235, + _SC_RAW_SOCKETS, + _SC_V7_ILP32_OFF32, + _SC_V7_ILP32_OFFBIG, + _SC_V7_LP64_OFF64, + _SC_V7_LPBIG_OFFBIG, + _SC_SS_REPL_MAX, + _SC_TRACE_EVENT_NAME_MAX, + _SC_TRACE_NAME_MAX, + _SC_TRACE_SYS_MAX, + _SC_TRACE_USER_EVENT_MAX, + _SC_XOPEN_STREAMS, + _SC_THREAD_ROBUST_PRIO_INHERIT, + _SC_THREAD_ROBUST_PRIO_PROTECT + } +} // // File Synchronization (FSC) @@ -1265,6 +1514,10 @@ else version( CRuntime_Bionic ) { int fsync(int) @trusted; } +else version( CRuntime_Musl ) +{ + int fsync(int) @trusted; +} else version( Solaris ) { int fsync(int) @trusted; @@ -1365,6 +1618,12 @@ version( CRuntime_Glibc ) int truncate(in char*, off_t); } } +else version( CRuntime_Musl ) +{ + int fchdir(int) @trusted; + int lockf(int, int, off_t); + alias lockf lockf64; +} else version( Darwin ) { char* crypt(in char*, in char*); diff --git a/src/core/sys/posix/utime.d b/src/core/sys/posix/utime.d index 89d15f56e7..ce8af7967d 100644 --- a/src/core/sys/posix/utime.d +++ b/src/core/sys/posix/utime.d @@ -54,6 +54,16 @@ version( CRuntime_Glibc ) int utime(in char*, in utimbuf*); } +else version( CRuntime_Musl ) +{ + struct utimbuf + { + time_t actime; + time_t modtime; + } + + int utime(in char*, in utimbuf*); +} else version( Darwin ) { struct utimbuf diff --git a/src/core/thread.d b/src/core/thread.d index cac02033a1..8b73f35cba 100644 --- a/src/core/thread.d +++ b/src/core/thread.d @@ -3192,6 +3192,7 @@ extern (C) @nogc nothrow version (NetBSD) int pthread_attr_get_np(pthread_t thread, pthread_attr_t* attr); version (Solaris) int thr_stksegment(stack_t* stk); version (CRuntime_Bionic) int pthread_getattr_np(pthread_t thid, pthread_attr_t* attr); + version (CRuntime_Musl) int pthread_getattr_np(pthread_t, pthread_attr_t*); } @@ -3278,6 +3279,16 @@ private void* getStackBottom() nothrow @nogc pthread_attr_destroy(&attr); return addr + size; } + else version (CRuntime_Musl) + { + pthread_attr_t attr; + void* addr; size_t size; + + pthread_getattr_np(pthread_self(), &attr); + pthread_attr_getstack(&attr, &addr, &size); + pthread_attr_destroy(&attr); + return addr + size; + } else static assert(false, "Platform not supported."); } diff --git a/src/core/time.d b/src/core/time.d index c5a1037de2..9dbccc4966 100644 --- a/src/core/time.d +++ b/src/core/time.d @@ -292,7 +292,7 @@ else version(Darwin) enum ClockType precise = 3, second = 6, } -else version(linux) enum ClockType +else version(CRuntime_Glibc) enum ClockType { normal = 0, bootTime = 1, @@ -303,6 +303,15 @@ else version(linux) enum ClockType second = 6, threadCPUTime = 7, } +else version(CRuntime_Musl) enum ClockType +{ + normal = 0, + bootTime = 1, + coarse = 2, + precise = 3, + raw = 5, + second = 6, +} else version(FreeBSD) enum ClockType { normal = 0, @@ -355,9 +364,11 @@ version(Posix) case coarse: return CLOCK_MONOTONIC_COARSE; case normal: return CLOCK_MONOTONIC; case precise: return CLOCK_MONOTONIC; - case processCPUTime: return CLOCK_PROCESS_CPUTIME_ID; case raw: return CLOCK_MONOTONIC_RAW; - case threadCPUTime: return CLOCK_THREAD_CPUTIME_ID; + version(CRuntime_Glibc) { + case processCPUTime: return CLOCK_PROCESS_CPUTIME_ID; + case threadCPUTime: return CLOCK_THREAD_CPUTIME_ID; + } case second: assert(0); } } diff --git a/src/rt/sections.d b/src/rt/sections.d index 21c580af66..c28a216a37 100644 --- a/src/rt/sections.d +++ b/src/rt/sections.d @@ -21,6 +21,8 @@ else version (WatchOS) version (CRuntime_Glibc) public import rt.sections_elf_shared; +else version (CRuntime_Musl) + public import rt.sections_elf_shared; else version (FreeBSD) public import rt.sections_elf_shared; else version (NetBSD) diff --git a/src/rt/sections_elf_shared.d b/src/rt/sections_elf_shared.d index 37f84f5368..8967a77f48 100644 --- a/src/rt/sections_elf_shared.d +++ b/src/rt/sections_elf_shared.d @@ -11,6 +11,7 @@ module rt.sections_elf_shared; version (CRuntime_Glibc) enum SharedELF = true; +else version (CRuntime_Musl) enum SharedELF = true; else version (FreeBSD) enum SharedELF = true; else version (NetBSD) enum SharedELF = true; else enum SharedELF = false;