Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/core/stdc/fenv.d
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
19 changes: 4 additions & 15 deletions src/core/stdc/stdlib.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/core/sys/posix/fcntl.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This turned up when trying to run this Phobos test on linux/AArch64, dug this fix out of the Glibc headers. It appears Glibc uses these constants on AArch64 regardless of whether __USE_FILE_OFFSET64 is set or not, just like on x64.

I don't want to go digging through the rat's nest of platform-specific Glibc headers to figure out why this is, so I just added this exception. If someone wants to do that digging and suggest a better way to normalize this, I'd be glad to make that change.

else
static if( __USE_FILE_OFFSET64 )
{
Expand Down Expand Up @@ -760,6 +766,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.");
Expand Down
4 changes: 4 additions & 0 deletions src/core/sys/posix/setjmp.d
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ else version( CRuntime_Bionic )
{
enum _JBLEN = 64;
}
else version( AArch64 )
{
enum _JBLEN = 32;
}
else
{
static assert(false, "Architecture not supported.");
Expand Down
85 changes: 73 additions & 12 deletions src/core/sys/posix/signal.d
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be a template?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a straight copy-and-paste of the Glibc block above, as Bionic switched to using the same function-calling scheme as Glibc. If you'd prefer that both blocks use template functions, I can modify them to that, don't care.

__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 )
{
Expand Down Expand Up @@ -760,7 +773,7 @@ else version( CRuntime_UClibc )
static assert(false, "Architecture not supported.");
}
}
else version (linux)
else version (CRuntime_Bionic)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched this to linux a couple years ago, maybe thinking it matched the kernel APIs, but now see that it doesn't. All other C runtimes that usually run on linux have their own version blocks above, so nobody other than Bionic users were likely using this.

{
version (X86)
{
Expand All @@ -773,7 +786,7 @@ else version (linux)
}

sigset_t sa_mask;
c_ulong sa_flags;
int sa_flags;
void function() sa_restorer;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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.");
Expand Down
13 changes: 13 additions & 0 deletions src/core/sys/posix/sys/ipc.d
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
4 changes: 4 additions & 0 deletions src/core/sys/posix/sys/mman.d
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
36 changes: 36 additions & 0 deletions src/core/sys/posix/sys/socket.d
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
27 changes: 27 additions & 0 deletions src/core/sys/posix/sys/stat.d
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
12 changes: 9 additions & 3 deletions src/core/sys/posix/sys/types.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the bindings will only ever support one version of Android?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I believe every version since uses this now, just noting the version where the switch was made.

}
else version( CRuntime_Musl )
{
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/core/sys/posix/sys/uio.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/core/sys/posix/time.d
Original file line number Diff line number Diff line change
Expand Up @@ -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*);
Expand Down