Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #734 from joakim-noah/android
Browse files Browse the repository at this point in the history
First Android/x86 patch that produces a working D executable
  • Loading branch information
MartinNowak committed Mar 12, 2014
2 parents feb4560 + 085d559 commit b5ef120
Show file tree
Hide file tree
Showing 15 changed files with 861 additions and 16 deletions.
52 changes: 52 additions & 0 deletions src/core/sys/posix/fcntl.d
Expand Up @@ -413,6 +413,58 @@ else version (Solaris)
int open(in char*, int, ...);
}
}
else version( Android )
{
enum F_DUPFD = 0;
enum F_GETFD = 1;
enum F_SETFD = 2;
enum F_GETFL = 3;
enum F_SETFL = 4;
enum F_GETLK = 5;
enum F_SETLK = 6;
enum F_SETLKW = 7;
enum F_SETOWN = 8;
enum F_GETOWN = 9;

enum FD_CLOEXEC = 1;

enum F_RDLCK = 0;
enum F_WRLCK = 1;
enum F_UNLCK = 2;

version (X86)
{
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 = 0x1000; // octal 010000
}
else
{
static assert(false, "Architecture not supported.");
}

enum O_ACCMODE = 0x3;
enum O_RDONLY = 0x0;
enum O_WRONLY = 0x1;
enum O_RDWR = 0x2;

struct flock
{
short l_type;
short l_whence;
off_t l_start;
off_t l_len;
pid_t l_pid;
}

int creat(in char*, mode_t);
int open(in char*, int, ...);
}
else
{
static assert(false, "Unsupported platform");
Expand Down
107 changes: 107 additions & 0 deletions src/core/sys/posix/pthread.d
Expand Up @@ -239,6 +239,23 @@ else version (Solaris)
enum PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t.init;
enum PTHREAD_ONCE_INIT = pthread_once_t.init;
}
else version( Android )
{
enum
{
PTHREAD_CREATE_JOINABLE,
PTHREAD_CREATE_DETACHED
}

enum PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t.init;
enum PTHREAD_ONCE_INIT = pthread_once_t.init;

enum
{
PTHREAD_PROCESS_PRIVATE,
PTHREAD_PROCESS_SHARED
}
}
else
{
static assert(false, "Unsupported platform");
Expand Down Expand Up @@ -377,6 +394,36 @@ else version (Solaris)
void __pthread_cleanup_push(_pthread_cleanup_routine, void*, caddr_t, _pthread_cleanup_info*);
void __pthread_cleanup_pop(int, _pthread_cleanup_info*);
}
else version( Android )
{
alias void function(void*) __pthread_cleanup_func_t;

struct __pthread_cleanup_t
{
__pthread_cleanup_t* __cleanup_prev;
__pthread_cleanup_func_t __cleanup_routine;
void* __cleanup_arg;
}

void __pthread_cleanup_push(__pthread_cleanup_t*, __pthread_cleanup_func_t,
void*);
void __pthread_cleanup_pop(__pthread_cleanup_t*, int);

struct pthread_cleanup
{
__pthread_cleanup_t __cleanup = void;

extern (D) void push()( __pthread_cleanup_func_t routine, void* arg )
{
__pthread_cleanup_push( &__cleanup, routine, arg );
}

extern (D) void pop()( int execute )
{
__pthread_cleanup_pop( &__cleanup, execute );
}
}
}
else version( Posix )
{
void pthread_cleanup_push(void function(void*), void*);
Expand Down Expand Up @@ -479,6 +526,9 @@ else version (Solaris)
int pthread_barrierattr_init(pthread_barrierattr_t*);
int pthread_barrierattr_setpshared(pthread_barrierattr_t*, int);
}
else version (Android)
{
}
else
{
static assert(false, "Unsupported platform");
Expand Down Expand Up @@ -530,6 +580,9 @@ else version (Solaris)
int pthread_spin_trylock(pthread_spinlock_t*);
int pthread_spin_unlock(pthread_spinlock_t*);
}
else version (Android)
{
}
else
{
static assert(false, "Unsupported platform");
Expand Down Expand Up @@ -617,6 +670,18 @@ else version (Solaris)
int pthread_mutexattr_settype(pthread_mutexattr_t*, int);
int pthread_setconcurrency(int);
}
else version (Android)
{
enum PTHREAD_MUTEX_NORMAL = 0;
enum PTHREAD_MUTEX_RECURSIVE = 1;
enum PTHREAD_MUTEX_ERRORCHECK = 2;
enum PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL;

int pthread_attr_getguardsize(in pthread_attr_t*, size_t*);
int pthread_attr_setguardsize(pthread_attr_t*, size_t);
int pthread_mutexattr_gettype(in pthread_mutexattr_t*, int*);
int pthread_mutexattr_settype(pthread_mutexattr_t*, int);
}
else
{
static assert(false, "Unsupported platform");
Expand All @@ -643,6 +708,10 @@ else version (OSX)
else version (Solaris)
{
}
else version( Android )
{
int pthread_getcpuclockid(pthread_t, clockid_t*);
}
else
{
static assert(false, "Unsupported platform");
Expand Down Expand Up @@ -681,6 +750,11 @@ else version (Solaris)
int pthread_rwlock_timedrdlock(pthread_rwlock_t*, in timespec*);
int pthread_rwlock_timedwrlock(pthread_rwlock_t*, in timespec*);
}
else version( Android )
{
int pthread_rwlock_timedrdlock(pthread_rwlock_t*, in timespec*);
int pthread_rwlock_timedwrlock(pthread_rwlock_t*, in timespec*);
}
else
{
static assert(false, "Unsupported platform");
Expand Down Expand Up @@ -808,6 +882,21 @@ else version (Solaris)
int pthread_setschedparam(pthread_t, int, sched_param*);
int pthread_setschedprio(pthread_t, int);
}
else version (Android)
{
enum
{
PTHREAD_SCOPE_SYSTEM,
PTHREAD_SCOPE_PROCESS
}

int pthread_attr_getschedpolicy(in pthread_attr_t*, int*);
int pthread_attr_getscope(in pthread_attr_t*);
int pthread_attr_setschedpolicy(pthread_attr_t*, int);
int pthread_attr_setscope(pthread_attr_t*, int);
int pthread_getschedparam(pthread_t, int*, sched_param*);
int pthread_setschedparam(pthread_t, int, in sched_param*);
}
else
{
static assert(false, "Unsupported platform");
Expand Down Expand Up @@ -861,6 +950,15 @@ else version (Solaris)
int pthread_attr_setstackaddr(pthread_attr_t*, void*);
int pthread_attr_setstacksize(pthread_attr_t*, size_t);
}
else version (Android)
{
int pthread_attr_getstack(in pthread_attr_t*, void**, size_t*);
int pthread_attr_getstackaddr(in pthread_attr_t*, void**);
int pthread_attr_getstacksize(in pthread_attr_t*, size_t*);
int pthread_attr_setstack(pthread_attr_t*, void*, size_t);
int pthread_attr_setstackaddr(pthread_attr_t*, void*);
int pthread_attr_setstacksize(pthread_attr_t*, size_t);
}
else
{
static assert(false, "Unsupported platform");
Expand Down Expand Up @@ -914,6 +1012,15 @@ else version (Solaris)
int pthread_rwlockattr_getpshared(in pthread_rwlockattr_t*, int*);
int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int);
}
else version (Android)
{
int pthread_condattr_getpshared(pthread_condattr_t*, int*);
int pthread_condattr_setpshared(pthread_condattr_t*, int);
int pthread_mutexattr_getpshared(pthread_mutexattr_t*, int*);
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
{
static assert(false, "Unsupported platform");
Expand Down
22 changes: 22 additions & 0 deletions src/core/sys/posix/sched.d
Expand Up @@ -101,6 +101,18 @@ else version (Solaris)
enum SCHED_FX = 6;
enum _SCHED_NEXT = 7;
}
else version( Android )
{
struct sched_param
{
int sched_priority;
}

enum SCHED_NORMAL = 0;
enum SCHED_OTHER = 0;
enum SCHED_FIFO = 1;
enum SCHED_RR = 2;
}
else
{
static assert(false, "Unsupported platform");
Expand Down Expand Up @@ -137,6 +149,10 @@ else version (Solaris)
{
int sched_yield();
}
else version (Android)
{
int sched_yield();
}
else
{
static assert(false, "Unsupported platform");
Expand Down Expand Up @@ -175,6 +191,12 @@ else version (Solaris)
int sched_get_priority_min(int);
int sched_rr_get_interval(pid_t, timespec*);
}
else version (Android)
{
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");
Expand Down
13 changes: 13 additions & 0 deletions src/core/sys/posix/semaphore.d
Expand Up @@ -92,6 +92,15 @@ else version (Solaris)

enum SEM_FAILED = cast(sem_t*)-1;
}
else version( Android )
{
struct sem_t
{
uint count; //volatile
}

enum SEM_FAILED = null;
}
else
{
static assert(false, "Unsupported platform");
Expand Down Expand Up @@ -133,6 +142,10 @@ else version (Solaris)
{
int sem_timedwait(sem_t*, in timespec*);
}
else version( Android )
{
int sem_timedwait(sem_t*, in timespec*);
}
else
{
static assert(false, "Unsupported platform");
Expand Down

0 comments on commit b5ef120

Please sign in to comment.