diff --git a/src/core/sys/posix/config.d b/src/core/sys/posix/config.d index 1185597748..e66ed8ec26 100644 --- a/src/core/sys/posix/config.d +++ b/src/core/sys/posix/config.d @@ -65,6 +65,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 9893e3906e..a0f12067e8 100644 --- a/src/core/sys/posix/dirent.d +++ b/src/core/sys/posix/dirent.d @@ -317,6 +317,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"); @@ -415,6 +453,10 @@ else version (Solaris) else version( CRuntime_Bionic ) { int readdir_r(DIR*, dirent*, dirent**); +} +else version( CRuntime_Musl ) +{ + } else { @@ -485,6 +527,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/fcntl.d b/src/core/sys/posix/fcntl.d index c7c4d4e7ac..280636a274 100644 --- a/src/core/sys/posix/fcntl.d +++ b/src/core/sys/posix/fcntl.d @@ -784,6 +784,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 e1d9366d2b..dbdf714b44 100644 --- a/src/core/sys/posix/netdb.d +++ b/src/core/sys/posix/netdb.d @@ -866,6 +866,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 db4b07ae1f..7bb2cb86b1 100644 --- a/src/core/sys/posix/netinet/in_.d +++ b/src/core/sys/posix/netinet/in_.d @@ -345,7 +345,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 @@ -1333,6 +1334,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/pthread.d b/src/core/sys/posix/pthread.d index 2786f481f4..23df7895f9 100644 --- a/src/core/sys/posix/pthread.d +++ b/src/core/sys/posix/pthread.d @@ -380,6 +380,10 @@ else version( CRuntime_Bionic ) PTHREAD_PROCESS_PRIVATE, PTHREAD_PROCESS_SHARED } +} +else version( CRuntime_Musl ) +{ + } else { @@ -599,6 +603,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"); @@ -743,6 +772,10 @@ else version (Solaris) } else version (CRuntime_Bionic) { +} +else version (CRuntime_Musl) +{ + } else { @@ -821,6 +854,10 @@ else version (Solaris) } else version (CRuntime_Bionic) { +} +else version (CRuntime_Musl) +{ + } else { @@ -976,6 +1013,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"); @@ -1016,6 +1063,10 @@ else version (Solaris) else version( CRuntime_Bionic ) { int pthread_getcpuclockid(pthread_t, clockid_t*); +} +else version( CRuntime_Musl ) +{ + } else { @@ -1077,6 +1128,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 { @@ -1289,6 +1344,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"); @@ -1378,6 +1445,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"); @@ -1460,6 +1532,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 26faaf80dc..4b08c18408 100644 --- a/src/core/sys/posix/pwd.d +++ b/src/core/sys/posix/pwd.d @@ -170,6 +170,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"); @@ -230,6 +242,9 @@ else version (Solaris) else version( CRuntime_Bionic ) { } +else version( CRuntime_Musl ) +{ +} else { static assert(false, "Unsupported platform"); @@ -290,6 +305,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/semaphore.d b/src/core/sys/posix/semaphore.d index 94ce3246f6..d5e3147328 100644 --- a/src/core/sys/posix/semaphore.d +++ b/src/core/sys/posix/semaphore.d @@ -140,6 +140,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"); @@ -194,6 +200,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 163fc7db2d..172b6e9e5f 100644 --- a/src/core/sys/posix/signal.d +++ b/src/core/sys/posix/signal.d @@ -596,6 +596,28 @@ version( CRuntime_Glibc ) void function() sa_restorer; } } +else 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 @@ -1508,6 +1530,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"); @@ -2676,6 +2778,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"); @@ -2927,6 +3032,10 @@ else version( CRuntime_Bionic ) } _sigev_thread_t _sigev_thread; } _sigev_un_t _sigev_un; } +} +else version( CRuntime_Musl ) +{ + } else { @@ -2981,6 +3090,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/sys/ioctl.d b/src/core/sys/posix/sys/ioctl.d index 31e495b1c8..627a3b7c7c 100644 --- a/src/core/sys/posix/sys/ioctl.d +++ b/src/core/sys/posix/sys/ioctl.d @@ -404,6 +404,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 fcbe485e9d..53f18c6ca7 100644 --- a/src/core/sys/posix/sys/mman.d +++ b/src/core/sys/posix/sys/mman.d @@ -109,6 +109,9 @@ else version (Solaris) else version (CRuntime_Bionic) { } +else version (CRuntime_Musl) +{ +} else { static assert(false, "Unsupported platform"); @@ -173,6 +176,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"); @@ -225,6 +235,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"); @@ -440,6 +460,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"); @@ -541,6 +574,9 @@ else version (CRuntime_Bionic) int mlockall(int); int munlockall(); } +else version (CRuntime_Musl) +{ +} else { static assert(false, "Unsupported platform"); @@ -589,6 +625,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"); @@ -629,6 +668,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"); @@ -675,6 +718,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/select.d b/src/core/sys/posix/sys/select.d index 0408a5ff0f..323f307171 100644 --- a/src/core/sys/posix/sys/select.d +++ b/src/core/sys/posix/sys/select.d @@ -411,6 +411,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 ebd1ae984d..2301af4a67 100644 --- a/src/core/sys/posix/sys/socket.d +++ b/src/core/sys/posix/sys/socket.d @@ -1826,6 +1826,116 @@ else version( CRuntime_Bionic ) int sockatmark(int) @safe; int socketpair(int, int, int, ref int[2]) @safe; } +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"); @@ -1887,6 +1997,10 @@ else version( CRuntime_Bionic ) AF_INET6 = 10 } } +else version( CRuntime_Musl ) +{ + enum AF_INET6 = 10; +} else { static assert(false, "Unsupported platform"); @@ -1948,6 +2062,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 086a2a8dae..842910590d 100644 --- a/src/core/sys/posix/sys/stat.d +++ b/src/core/sys/posix/sys/stat.d @@ -1254,6 +1254,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"); @@ -1368,6 +1432,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) @@ -1485,6 +1559,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/types.d b/src/core/sys/posix/sys/types.d index c78de17bdd..00a9be730d 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; @@ -360,6 +377,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"); @@ -629,6 +662,43 @@ version (CRuntime_Glibc) alias c_ulong pthread_t; } +else version( CRuntime_Musl ) +{ + version(X86_64) { + 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 + { + static assert (false, "Architecture unsupported"); + } +} else version( Darwin ) { version( D_LP64 ) @@ -1017,6 +1087,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 0a893ba094..fa6075a54a 100644 --- a/src/core/sys/posix/sys/uio.d +++ b/src/core/sys/posix/sys/uio.d @@ -123,6 +123,17 @@ 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; + } + + ssize_t readv(int, in iovec*, int); + ssize_t writev(int, in iovec*, int); +} 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 26b3a18d93..71ab1a8968 100644 --- a/src/core/sys/posix/sys/wait.d +++ b/src/core/sys/posix/sys/wait.d @@ -191,6 +191,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"); @@ -312,6 +325,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 328eac3363..e646257f92 100644 --- a/src/core/sys/posix/time.d +++ b/src/core/sys/posix/time.d @@ -77,6 +77,10 @@ else version (CRuntime_Bionic) { // Not supported. } +else version (CRuntime_Musl) +{ + time_t timegm(tm*); +} else { static assert(false, "Unsupported platform"); @@ -384,6 +388,46 @@ 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; + alias void* timer_t; + + struct itimerspec + { + timespec it_interval; + timespec it_value; + } + + enum TIMER_ABSTIME = 1; + + enum CLOCK_REALTIME = 0; + enum CLOCK_MONOTONIC = 1; + enum CLOCK_PROCESS_CPUTIME_ID = 2; + enum CLOCK_THREAD_CPUTIME_ID = 3; + enum CLOCK_MONOTONIC_RAW = 4; + enum CLOCK_REALTIME_COARSE = 5; + enum CLOCK_MONOTONIC_COARSE = 6; + enum CLOCK_BOOTTIME = 7; + enum CLOCK_REALTIME_ALARM = 8; + enum CLOCK_BOOTTIME_ALARM = 9; + enum CLOCK_SGI_CYCLE = 10; + enum CLOCK_TAI = 11; + + int nanosleep(in timespec*, timespec*); + + 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*); + int clock_getcpuclockid(pid_t, clockid_t *); + + int timer_create(clockid_t, sigevent*, timer_t*); + int timer_delete(timer_t); + int timer_gettime(timer_t, itimerspec*); + int timer_settime(timer_t, int, in itimerspec*, itimerspec*); + int timer_getoverrun(timer_t); +} else { static assert(false, "Unsupported platform"); @@ -448,6 +492,13 @@ else version (CRuntime_Bionic) tm* gmtime_r(in time_t*, tm*); tm* localtime_r(in time_t*, tm*); } +else version (CRuntime_Musl) +{ + char* asctime_r(in tm*, char*); + char* ctime_r(in time_t*, char*); + tm* gmtime_r(in time_t*, tm*); + tm* localtime_r(in time_t*, tm*); +} else { static assert(false, "Unsupported platform"); @@ -513,6 +564,11 @@ else version( CRuntime_Bionic ) char* strptime(in char*, in char*, tm*); } +else version( CRuntime_Musl ) +{ + tm* getdate(in char*); + char* strptime(in char*, in char*, tm*); +} else { static assert(false, "Unsupported platform"); diff --git a/src/core/sys/posix/unistd.d b/src/core/sys/posix/unistd.d index 9540d9ca3e..6bceeaec11 100644 --- a/src/core/sys/posix/unistd.d +++ b/src/core/sys/posix/unistd.d @@ -172,6 +172,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) @trusted; + off_t lseek(int, off_t, int) @trusted; + alias ftruncate ftruncate64; + alias lseek lseek64; +} version( CRuntime_Glibc ) { @@ -1397,6 +1404,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) @@ -1429,6 +1678,10 @@ else version( CRuntime_Bionic ) { int fsync(int) @trusted; } +else version( CRuntime_Musl ) +{ + int fsync(int) @trusted; +} else version( Solaris ) { int fsync(int) @trusted; @@ -1529,6 +1782,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*);