From 5e9bd1977d55722335904036f10fbdbd32cfc685 Mon Sep 17 00:00:00 2001 From: Joakim Date: Thu, 22 Mar 2018 12:51:17 +0530 Subject: [PATCH 1/2] Bionic bindings for AArch64 --- src/core/stdc/fenv.d | 10 ++++ src/core/stdc/stdlib.d | 19 ++------ src/core/sys/posix/fcntl.d | 11 +++++ src/core/sys/posix/setjmp.d | 4 ++ src/core/sys/posix/signal.d | 85 ++++++++++++++++++++++++++++----- src/core/sys/posix/sys/ipc.d | 13 +++++ src/core/sys/posix/sys/mman.d | 4 ++ src/core/sys/posix/sys/socket.d | 36 ++++++++++++++ src/core/sys/posix/sys/stat.d | 27 +++++++++++ src/core/sys/posix/sys/types.d | 12 +++-- src/core/sys/posix/sys/uio.d | 4 +- src/core/sys/posix/time.d | 4 +- 12 files changed, 195 insertions(+), 34 deletions(-) diff --git a/src/core/stdc/fenv.d b/src/core/stdc/fenv.d index 7da97dd1b0..330b3b09ff 100644 --- a/src/core/stdc/fenv.d +++ b/src/core/stdc/fenv.d @@ -302,6 +302,16 @@ else version( CRuntime_Bionic ) alias uint fenv_t; alias uint fexcept_t; } + else version(AArch64) + { + struct fenv_t + { + uint __control; + uint __status; + } + + alias uint fexcept_t; + } else { static assert(false, "Architecture not supported."); diff --git a/src/core/stdc/stdlib.d b/src/core/stdc/stdlib.d index 088aeaf227..0332fae655 100644 --- a/src/core/stdc/stdlib.d +++ b/src/core/stdc/stdlib.d @@ -151,21 +151,10 @@ else // No unsafe pointer manipulation. @trusted { - version(CRuntime_Bionic) - { - import core.sys.posix.stdlib: lrand48, srand48; - /// - alias core.sys.posix.stdlib.lrand48 rand; - /// - alias core.sys.posix.stdlib.srand48 srand; - } - else - { - /// - int rand(); - /// - void srand(uint seed); - } + /// These two were added to Bionic in Lollipop. + int rand(); + /// + void srand(uint seed); } // We don't mark these @trusted. Given that they return a void*, one has diff --git a/src/core/sys/posix/fcntl.d b/src/core/sys/posix/fcntl.d index ee4700a538..adc01879bd 100644 --- a/src/core/sys/posix/fcntl.d +++ b/src/core/sys/posix/fcntl.d @@ -760,6 +760,17 @@ else version( CRuntime_Bionic ) enum O_NONBLOCK = 0x800; // octal 04000 enum O_SYNC = 0x1000; // octal 010000 } + else version (AArch64) + { + enum O_CREAT = 0x40; // octal 0100 + enum O_EXCL = 0x80; // octal 0200 + enum O_NOCTTY = 0x100; // octal 0400 + enum O_TRUNC = 0x200; // octal 01000 + + enum O_APPEND = 0x400; // octal 02000 + enum O_NONBLOCK = 0x800; // octal 04000 + enum O_SYNC = 0x101000; // octal 04010000 + } else { static assert(false, "Architecture not supported."); diff --git a/src/core/sys/posix/setjmp.d b/src/core/sys/posix/setjmp.d index 44ac2fa630..d795db076d 100644 --- a/src/core/sys/posix/setjmp.d +++ b/src/core/sys/posix/setjmp.d @@ -259,6 +259,10 @@ else version( CRuntime_Bionic ) { enum _JBLEN = 64; } + else version( AArch64 ) + { + enum _JBLEN = 32; + } else { static assert(false, "Architecture not supported."); diff --git a/src/core/sys/posix/signal.d b/src/core/sys/posix/signal.d index 8410614aa9..0baa0bb14c 100644 --- a/src/core/sys/posix/signal.d +++ b/src/core/sys/posix/signal.d @@ -175,15 +175,28 @@ else version(NetBSD) } else version (CRuntime_Bionic) { - enum SIGRTMIN = 32; - version(ARM) - enum SIGRTMAX = 64; - else version(X86) - enum SIGRTMAX = 64; - else version(MIPS32) - enum SIGRTMAX = 128; - else - static assert(false, "Architecture not supported."); + // Switched to calling these functions since Lollipop + private extern (C) nothrow @nogc + { + int __libc_current_sigrtmin(); + int __libc_current_sigrtmax(); + } + + @property int SIGRTMIN() nothrow @nogc { + __gshared static int sig = -1; + if (sig == -1) { + sig = __libc_current_sigrtmin(); + } + return sig; + } + + @property int SIGRTMAX() nothrow @nogc { + __gshared static int sig = -1; + if (sig == -1) { + sig = __libc_current_sigrtmax(); + } + return sig; + } } else version( CRuntime_UClibc ) { @@ -760,7 +773,7 @@ else version( CRuntime_UClibc ) static assert(false, "Architecture not supported."); } } -else version (linux) +else version (CRuntime_Bionic) { version (X86) { @@ -773,7 +786,7 @@ else version (linux) } sigset_t sa_mask; - c_ulong sa_flags; + int sa_flags; void function() sa_restorer; } } @@ -788,7 +801,22 @@ else version (linux) } sigset_t sa_mask; - c_ulong sa_flags; + int sa_flags; + void function() sa_restorer; + } + } + else version (AArch64) + { + struct sigaction_t + { + int sa_flags; + union + { + sigfn_t sa_handler; + sigactfn_t sa_sigaction; + } + + sigset_t sa_mask; void function() sa_restorer; } } @@ -1487,6 +1515,11 @@ else version( CRuntime_Bionic ) alias c_ulong sigset_t; enum int LONG_BIT = 32; } + else version (AArch64) + { + struct sigset_t { ulong[1] sig; } + enum int LONG_BIT = 64; + } else { static assert(false, "Architecture not supported."); @@ -3018,6 +3051,34 @@ else version (CRuntime_Bionic) size_t ss_size; } } + else version (AArch64) + { + enum SIGPOLL = 29; + enum SIGPROF = 27; + enum SIGSYS = 31; + enum SIGTRAP = 5; + enum SIGVTALRM = 26; + enum SIGXCPU = 24; + enum SIGXFSZ = 25; + + enum SA_ONSTACK = 0x08000000; + enum SA_RESETHAND = 0x80000000; + enum SA_RESTART = 0x10000000; + enum SA_SIGINFO = 4; + enum SA_NOCLDWAIT = 2; + enum SA_NODEFER = 0x40000000; + enum SS_ONSTACK = 1; + enum SS_DISABLE = 2; + enum MINSIGSTKSZ = 2048; + enum SIGSTKSZ = 8192; + + struct stack_t + { + void* ss_sp; + int ss_flags; + size_t ss_size; + } + } else { static assert(false, "Architecture not supported."); diff --git a/src/core/sys/posix/sys/ipc.d b/src/core/sys/posix/sys/ipc.d index cb3b2bd084..e0636d9283 100644 --- a/src/core/sys/posix/sys/ipc.d +++ b/src/core/sys/posix/sys/ipc.d @@ -203,6 +203,19 @@ else version( CRuntime_Bionic ) ushort seq; } } + else version (AArch64) + { + struct ipc_perm + { + key_t key; + uint uid; + uint gid; + uint cuid; + uint cgid; + mode_t mode; + ushort seq; + } + } else { static assert(false, "Architecture not supported."); diff --git a/src/core/sys/posix/sys/mman.d b/src/core/sys/posix/sys/mman.d index 7937471163..3deb6ef445 100644 --- a/src/core/sys/posix/sys/mman.d +++ b/src/core/sys/posix/sys/mman.d @@ -474,6 +474,10 @@ else version (CRuntime_Bionic) { enum MAP_ANON = 0x0020; } + else version (AArch64) + { + enum MAP_ANON = 0x0020; + } else { static assert(false, "Architecture not supported."); diff --git a/src/core/sys/posix/sys/socket.d b/src/core/sys/posix/sys/socket.d index 038f10e250..e00bc59d94 100644 --- a/src/core/sys/posix/sys/socket.d +++ b/src/core/sys/posix/sys/socket.d @@ -1768,6 +1768,42 @@ else version( CRuntime_Bionic ) SO_TYPE = 3 } } + else version (AArch64) + { + alias ulong __kernel_size_t; + + enum + { + SOCK_DGRAM = 2, + SOCK_SEQPACKET = 5, + SOCK_STREAM = 1 + } + + enum + { + SOL_SOCKET = 1 + } + + enum + { + SO_ACCEPTCONN = 30, + SO_BROADCAST = 6, + SO_DEBUG = 1, + SO_DONTROUTE = 5, + SO_ERROR = 4, + SO_KEEPALIVE = 9, + SO_LINGER = 13, + SO_OOBINLINE = 10, + SO_RCVBUF = 8, + SO_RCVLOWAT = 18, + SO_RCVTIMEO = 20, + SO_REUSEADDR = 2, + SO_SNDBUF = 7, + SO_SNDLOWAT = 19, + SO_SNDTIMEO = 21, + SO_TYPE = 3 + } + } else { static assert(false, "Architecture not supported."); diff --git a/src/core/sys/posix/sys/stat.d b/src/core/sys/posix/sys/stat.d index cfbd8bb818..067a79a06e 100644 --- a/src/core/sys/posix/sys/stat.d +++ b/src/core/sys/posix/sys/stat.d @@ -1212,6 +1212,33 @@ else version( CRuntime_Bionic ) ulong st_ino; } } + else version (AArch64) + { + struct stat_t + { + ulong st_dev; + ulong st_ino; + uint st_mode; + uint st_nlink; + uid_t st_uid; + gid_t st_gid; + ulong st_rdev; + ulong __pad1; + + long st_size; + int st_blksize; + int __pad2; + long st_blocks; + long st_atime; + ulong st_atime_nsec; + long st_mtime; + ulong st_mtime_nsec; + long st_ctime; + ulong st_ctime_nsec; + uint __unused4; + uint __unused5; + } + } else { static assert(false, "Architecture not supported."); diff --git a/src/core/sys/posix/sys/types.d b/src/core/sys/posix/sys/types.d index 1e0c60eb5b..416f4064cd 100644 --- a/src/core/sys/posix/sys/types.d +++ b/src/core/sys/posix/sys/types.d @@ -238,12 +238,12 @@ else version( CRuntime_Bionic ) { alias c_ulong blkcnt_t; alias c_ulong blksize_t; - alias uint dev_t; + alias size_t dev_t; alias uint gid_t; alias c_ulong ino_t; alias c_long off_t; alias int pid_t; - alias int ssize_t; + alias c_long ssize_t; alias c_long time_t; alias uint uid_t; @@ -262,6 +262,11 @@ else version( CRuntime_Bionic ) alias ushort mode_t; alias ushort nlink_t; } + else version(AArch64) + { + alias uint mode_t; + alias uint nlink_t; + } else version(MIPS32) { alias uint mode_t; @@ -418,7 +423,7 @@ else version( CRuntime_Bionic ) alias uint id_t; alias int key_t; alias c_long suseconds_t; - alias c_long useconds_t; + alias uint useconds_t; // Updated in Lollipop } else version( CRuntime_Musl ) { @@ -1051,6 +1056,7 @@ else version( CRuntime_Bionic ) size_t guard_size; int sched_policy; int sched_priority; + version(AArch64) char[16] __reserved; } struct pthread_cond_t diff --git a/src/core/sys/posix/sys/uio.d b/src/core/sys/posix/sys/uio.d index 5c3dabb0da..851f21c20e 100644 --- a/src/core/sys/posix/sys/uio.d +++ b/src/core/sys/posix/sys/uio.d @@ -116,8 +116,8 @@ else version( CRuntime_Bionic ) { struct iovec { - void* iov_base; - uint iov_len; + void* iov_base; + size_t iov_len; } int readv(int, in iovec*, int); diff --git a/src/core/sys/posix/time.d b/src/core/sys/posix/time.d index 68da229f27..0b63e62ff2 100644 --- a/src/core/sys/posix/time.d +++ b/src/core/sys/posix/time.d @@ -380,8 +380,8 @@ else version( CRuntime_Bionic ) enum CLOCK_REALTIME_HR = 4; enum TIMER_ABSTIME = 0x01; - alias int clockid_t; - alias int timer_t; + alias int clockid_t; + alias void* timer_t; // Updated since Lollipop int clock_getres(int, timespec*); int clock_gettime(int, timespec*); From df4cafb2d0b1aab0bdfd69d7af67071a2f89d8cd Mon Sep 17 00:00:00 2001 From: Joakim Date: Sun, 3 Jun 2018 14:08:54 +0530 Subject: [PATCH 2/2] core.sys.posix.fcntl: Add correct locking constants for Glibc/AArch64 --- src/core/sys/posix/fcntl.d | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/core/sys/posix/fcntl.d b/src/core/sys/posix/fcntl.d index adc01879bd..80b248d243 100644 --- a/src/core/sys/posix/fcntl.d +++ b/src/core/sys/posix/fcntl.d @@ -98,6 +98,12 @@ version( CRuntime_Glibc ) enum F_SETLK = 6; enum F_SETLKW = 7; } + else version(AArch64) + { + enum F_GETLK = 5; + enum F_SETLK = 6; + enum F_SETLKW = 7; + } else static if( __USE_FILE_OFFSET64 ) {