From 53b4662f245bba0a2bcaa2eabf8e05ac98cbe5e0 Mon Sep 17 00:00:00 2001 From: kai Date: Sun, 16 Nov 2014 20:46:52 +0100 Subject: [PATCH] Add declarations for AIX. Add all declarations required to support D on AIX. Work is based on AIX 7.1 See the technical reference for information about the added routines: http://www-01.ibm.com/support/knowledgecenter/ssw_aix_71/com.ibm.aix.base/technicalreferences.htm?lang=en --- src/core/stdc/stdio.d | 81 +++++++++++ src/core/stdc/stdlib.d | 1 + src/core/stdc/time.d | 9 ++ src/core/sys/aix/dlfcn.d | 34 +++++ src/core/sys/posix/dirent.d | 38 +++++ src/core/sys/posix/dlfcn.d | 12 ++ src/core/sys/posix/grp.d | 24 ++++ src/core/sys/posix/pthread.d | 146 +++++++++++++++++++ src/core/sys/posix/pwd.d | 27 ++++ src/core/sys/posix/sched.d | 31 ++++ src/core/sys/posix/semaphore.d | 13 ++ src/core/sys/posix/signal.d | 253 ++++++++++++++++++++++++++++++++- src/core/sys/posix/sys/stat.d | 80 +++++++++++ src/core/sys/posix/sys/types.d | 92 ++++++++++++ src/core/sys/posix/time.d | 58 ++++++++ 15 files changed, 898 insertions(+), 1 deletion(-) create mode 100644 src/core/sys/aix/dlfcn.d diff --git a/src/core/stdc/stdio.d b/src/core/stdc/stdio.d index 35473c4ddd..9e5df59973 100644 --- a/src/core/stdc/stdio.d +++ b/src/core/stdc/stdio.d @@ -166,6 +166,19 @@ else version ( FreeBSD ) long _mbstateL; } } +else version (AIX) +{ + enum + { + BUFSIZ = 4096, + EOF = -1, + FOPEN_MAX = 32767, + FILENAME_MAX = 255, + TMP_MAX = 16384, + L_tmpnam = 21 + } + enum int _NFILE = 16; +} else version (Solaris) { enum @@ -392,6 +405,42 @@ else version( FreeBSD ) /// alias shared(__sFILE) FILE; } +else version (AIX) +{ + alias c_long fpos_t; + + struct _iobuf + { + ubyte*_ptr; + version (D_LP64) {} + else + { + int _cnt; + } + ubyte* _base; + ubyte* _bufendp; + version (D_LP64) {} + else + { + short _flag; + short _file; + int __stdioid; + } + char* __newbase; + void* _lock; + version (D_LP64) + { + int _cnt; + int _file; + int __stdioid; + short _flag; + short _unused; + c_long[4] _unused1; + } + } + + alias shared(_iobuf) FILE; +} else version (Solaris) { /// @@ -637,6 +686,23 @@ else version( FreeBSD ) /// alias __stderrp stderr; } +else version (AIX) +{ + enum + { + _IOFBF = 0x00, + _IOLBF = 0x40, + _IONBF = 0x04, + _IOEOF = 0x10, + _IOERR = 0x20, + } + + private extern shared FILE[_NFILE] _iob; + + shared stdin = &_iob[0]; + shared stdout = &_iob[1]; + shared stderr = &_iob[2]; +} else version (Solaris) { enum @@ -1039,6 +1105,21 @@ else version( FreeBSD ) /// int vsnprintf(char* s, size_t n, in char* format, va_list arg); } +else version (AIX) +{ + // No unsafe pointer manipulation. + @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(char* s, size_t n, in char* format, ...); + int vsnprintf(char* s, size_t n, in char* format, va_list arg); +} else version (Solaris) { // No unsafe pointer manipulation. diff --git a/src/core/stdc/stdlib.d b/src/core/stdc/stdlib.d index cecb0f184e..f9ecd869d8 100644 --- a/src/core/stdc/stdlib.d +++ b/src/core/stdc/stdlib.d @@ -66,6 +66,7 @@ version(Windows) enum RAND_MAX = 0x7fff; else version(CRuntime_Glibc) enum RAND_MAX = 0x7fffffff; else version(OSX) enum RAND_MAX = 0x7fffffff; else version(FreeBSD) enum RAND_MAX = 0x7fffffff; +else version(AIX) enum RAND_MAX = 0x7ffff; else version(Solaris) enum RAND_MAX = 0x7fff; else version(CRuntime_Bionic) enum RAND_MAX = 0x7fffffff; else static assert( false, "Unsupported platform" ); diff --git a/src/core/stdc/time.d b/src/core/stdc/time.d index 9bb3afc7fb..a5ae9c09f3 100644 --- a/src/core/stdc/time.d +++ b/src/core/stdc/time.d @@ -82,6 +82,10 @@ else version( FreeBSD ) { enum clock_t CLOCKS_PER_SEC = 128; } +else version( AIX ) +{ + enum clock_t CLOCKS_PER_SEC = 1_000_000; +} else version (CRuntime_Glibc) { enum clock_t CLOCKS_PER_SEC = 1_000_000; @@ -145,6 +149,11 @@ else version( FreeBSD ) /// extern __gshared const(char)*[2] tzname; // non-standard } +else version( AIX ) +{ + void tzset(); + extern __gshared const(char)*[2] tzname; +} else version (Solaris) { /// diff --git a/src/core/sys/aix/dlfcn.d b/src/core/sys/aix/dlfcn.d new file mode 100644 index 0000000000..b4f67dc6d0 --- /dev/null +++ b/src/core/sys/aix/dlfcn.d @@ -0,0 +1,34 @@ +/** + * D header file for AIX. + * + * Copyright: Copyright Kai Nacke 2014. + * License: Boost License 1.0. + * Authors: Kai Nacke + */ +module core.sys.aix.dlfcn; + +public import core.sys.posix.dlfcn; + +version (AIX): +extern (C): +nothrow: + +/* + * Modes and flags for dlopen(). + */ +static assert(RTLD_NOW == 0x00000002); +static assert(RTLD_LAZY == 0x00000004); +static assert(RTLD_GLOBAL == 0x00010000); +enum RTLD_NOAUTODEFER = 0x00020000; +enum RTLD_MEMBER = 0x00040000; +static assert(RTLD_LOCAL == 0x00080000); + +/* + * Special handle arguments for dlsym(). + */ +enum RTLD_DEFAULT = cast(void *)-1; /* Start search from the executable module. */ +enum RTLD_MYSELF = cast(void *)-2; /* Start search from the module calling dlsym(). */ +enum RTLD_NEXT = cast(void *)-3; /* Start search from the module after the module which called dlsym(). */ + +enum RTLD_ENTRY = cast(char *)-1; /* Return the module's entry point from dlsym(). */ + diff --git a/src/core/sys/posix/dirent.d b/src/core/sys/posix/dirent.d index 80c31f8d06..9325442d7c 100644 --- a/src/core/sys/posix/dirent.d +++ b/src/core/sys/posix/dirent.d @@ -142,6 +142,35 @@ else version( FreeBSD ) dirent* readdir(DIR*); } +else version (AIX) +{ + struct dirent + { + ulong d_offset; + ino_t d_ino; + ushort d_reclen; + ushort d_namlen; + char[256] d_name; + } + + struct DIR + { + int dd_fd; + blksize_t dd_blksize; + char* dd_buf; + c_long dd_size; + c_long dd_flag; + off_t dd_loc; + off_t dd_curoff; + /* Only for the thread safe functions, used for inter-thread locking */ + void* dd_lock; + } + + dirent *readdir(DIR*); + + DIR* fdopendir(int); + int dirfd(DIR*); +} else version (Solaris) { struct dirent @@ -237,6 +266,10 @@ else version( FreeBSD ) { int readdir_r(DIR*, dirent*, dirent**); } +else version (AIX) +{ + int readdir_r(DIR*, dirent*, dirent**); +} else version (Solaris) { static if (__USE_LARGEFILE64) @@ -279,6 +312,11 @@ else version( FreeBSD ) else version (OSX) { } +else version (AIX) +{ + void seekdir(DIR*, c_long); + c_long telldir(DIR*); +} else version (Solaris) { c_long telldir(DIR*); diff --git a/src/core/sys/posix/dlfcn.d b/src/core/sys/posix/dlfcn.d index bd5b8eab70..2eccb6fc27 100644 --- a/src/core/sys/posix/dlfcn.d +++ b/src/core/sys/posix/dlfcn.d @@ -165,6 +165,18 @@ else version( FreeBSD ) void* dli_saddr; } } +else version( AIX ) +{ + enum RTLD_LAZY = 0x00000004; + enum RTLD_NOW = 0x00000002; + enum RTLD_GLOBAL = 0x00010000; + enum RTLD_LOCAL = 0x00080000; + + int dlclose(void*); + char* dlerror(); + void* dlopen(in char*, int); + void* dlsym(void*, in char*); +} else version( Solaris ) { enum RTLD_LAZY = 1; diff --git a/src/core/sys/posix/grp.d b/src/core/sys/posix/grp.d index d96e292499..5cfcba5bfa 100644 --- a/src/core/sys/posix/grp.d +++ b/src/core/sys/posix/grp.d @@ -68,6 +68,16 @@ else version( FreeBSD ) char** gr_mem; } } +else version( AIX ) +{ + struct group + { + char* gr_name; + char* gr_passwd; + gid_t gr_gid; + char** gr_mem; + } +} else version( Solaris ) { struct group @@ -119,6 +129,14 @@ else version( FreeBSD ) int getgrnam_r(in char*, group*, char*, size_t, group**); int getgrgid_r(gid_t, group*, char*, size_t, group**); } +else version( AIX ) +{ + int _posix_getgrnam_r(in char*, group*, char*, size_t, group**); + int _posix_getgrgid_r(gid_t, group*, char*, size_t, group**); + + alias _posix_getgrnam_r getgrnam_r; // Named differently + alias _posix_getgrgid_r getgrgid_r; +} else version( Solaris ) { int getgrnam_r(in char*, group*, char*, int, group**); @@ -159,6 +177,12 @@ else version( FreeBSD ) @trusted void endgrent(); @trusted void setgrent(); } +else version( AIX ) +{ + group* getgrent(); + @trusted void endgrent(); + @trusted void setgrent(); +} else version( Solaris ) { group* getgrent(); diff --git a/src/core/sys/posix/pthread.d b/src/core/sys/posix/pthread.d index 3a9e7e9c21..1bb2574068 100644 --- a/src/core/sys/posix/pthread.d +++ b/src/core/sys/posix/pthread.d @@ -208,6 +208,46 @@ else version( FreeBSD ) enum PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP = null; enum PTHREAD_COND_INITIALIZER = null; enum PTHREAD_RWLOCK_INITIALIZER = null; + + enum + { + PTHREAD_PROCESS_SHARED = 0, + PTHREAD_PROCESS_PRIVATE = 1, + } +} +else version (AIX) +{ + enum + { + PTHREAD_CANCEL_DISABLE = 0, + PTHREAD_CANCEL_ENABLE = 1, + } + + enum + { + PTHREAD_CANCEL_DEFERRED = 0, + PTHREAD_CANCEL_ASYNCHRONOUS = 1, + } + + enum PTHREAD_CANCELED = cast(void*) -1; + + enum + { + PTHREAD_CREATE_JOINABLE = 0, + PTHREAD_CREATE_DETACHED = 1, + } + + enum + { + PTHREAD_INHERIT_SCHED = 0, + PTHREAD_EXPLICIT_SCHED = 1, + } + + // FIXME + // PTHREAD_MUTEX_INITIALIZER + // PTHREAD_COND_INITIALIZER + // PTHREAD_RWLOCK_INITIALIZER + // PTHREAD_ONCE_INIT } else version (Solaris) { @@ -510,6 +550,18 @@ else version( FreeBSD ) else version (OSX) { } +else version (AIX) +{ + enum PTHREAD_BARRIER_SERIAL_THREAD = 2; + + int pthread_barrier_init(pthread_barrier_t*, in pthread_barrierattr_t*, uint); + int pthread_barrier_destroy(pthread_barrier_t*); + int pthread_barrier_wait(pthread_barrier_t*); + int pthread_barrierattr_init(pthread_barrierattr_t*); + int pthread_barrierattr_destroy(pthread_barrierattr_t*); + int pthread_barrierattr_getpshared(in pthread_barrierattr_t*, int*); + int pthread_barrierattr_setpshared(pthread_barrierattr_t*, int); +} else version (Solaris) { enum PTHREAD_BARRIER_SERIAL_THREAD = -2; @@ -538,6 +590,12 @@ int pthread_condattr_getclock(in pthread_condattr_t*, clockid_t*); int pthread_condattr_setclock(pthread_condattr_t*, clockid_t); */ +version (AIX) +{ + int pthread_condattr_getclock(in pthread_condattr_t*, clockid_t*); + int pthread_condattr_setclock(pthread_condattr_t*, clockid_t); +} + // // Spinlock (SPI) // @@ -565,6 +623,14 @@ else version( FreeBSD ) int pthread_spin_trylock(pthread_spinlock_t*); int pthread_spin_unlock(pthread_spinlock_t*); } +else version (AIX) +{ + int pthread_spin_init(pthread_spinlock_t*, int); + int pthread_spin_destroy(pthread_spinlock_t*); + int pthread_spin_lock(pthread_spinlock_t*); + int pthread_spin_trylock(pthread_spinlock_t*); + int pthread_spin_unlock(pthread_spinlock_t*); +} else version (OSX) { } @@ -648,6 +714,23 @@ else version( FreeBSD ) int pthread_mutexattr_settype(pthread_mutexattr_t*, int) @trusted; int pthread_setconcurrency(int); } +else version (AIX) +{ + enum + { + PTHREAD_MUTEX_ERRORCHECK = 3, + PTHREAD_MUTEX_RECURSIVE = 4, + PTHREAD_MUTEX_NORMAL = 5, + } + 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_getconcurrency(); + int pthread_mutexattr_gettype(pthread_mutexattr_t*, int*); + int pthread_mutexattr_settype(pthread_mutexattr_t*, int); + int pthread_setconcurrency(int); +} else version (Solaris) { enum @@ -701,6 +784,10 @@ else version( FreeBSD ) else version (OSX) { } +else version (AIX) +{ + int pthread_getcpuclockid(pthread_t, clockid_t*); +} else version (Solaris) { } @@ -740,6 +827,12 @@ else version( FreeBSD ) int pthread_rwlock_timedrdlock(pthread_rwlock_t*, in timespec*); int pthread_rwlock_timedwrlock(pthread_rwlock_t*, in timespec*); } +else version (AIX) +{ + int pthread_mutex_timedlock(pthread_mutex_t*, in timespec*); + int pthread_rwlock_timedrdlock(pthread_rwlock_t*, in timespec*); + int pthread_rwlock_timedwrlock(pthread_rwlock_t*, in timespec*); +} else version (Solaris) { int pthread_mutex_timedlock(pthread_mutex_t*, in timespec*); @@ -787,6 +880,23 @@ version( OSX ) int pthread_mutexattr_setprioceiling(pthread_mutexattr_t*, int); int pthread_mutexattr_setprotocol(pthread_mutexattr_t*, int); } +else version (AIX) +{ + enum + { + PTHREAD_PRIO_DEFAULT = 0, + PTHREAD_PRIO_NONE = 1, + PTHREAD_PRIO_PROTECT = 2, + PTHREAD_PRIO_INHERIT = 3, + } + + int pthread_mutex_getprioceiling(in pthread_mutex_t*, int*); + int pthread_mutex_setprioceiling(pthread_mutex_t*, int, int*); + int pthread_mutexattr_getprioceiling(in pthread_mutexattr_t*, int*); + int pthread_mutexattr_getprotocol(in pthread_mutexattr_t*, int*); + int pthread_mutexattr_setprioceiling(pthread_mutexattr_t*, int); + int pthread_mutexattr_setprotocol(pthread_mutexattr_t*, int); +} else version( Solaris ) { enum @@ -876,6 +986,24 @@ else version( FreeBSD ) int pthread_setschedparam(pthread_t, int, sched_param*); // int pthread_setschedprio(pthread_t, int); // not implemented } +else version (AIX) +{ + enum + { + PTHREAD_SCOPE_SYSTEM = 0, + PTHREAD_SCOPE_PROCESS = 1, + } + + int pthread_attr_getinheritsched(in pthread_attr_t*, int*); + int pthread_attr_getschedpolicy(in pthread_attr_t*, int*); + int pthread_attr_getscope(in pthread_attr_t*, int*); + int pthread_attr_setinheritsched(pthread_attr_t*, int); + int pthread_attr_setschedpolicy(pthread_attr_t*, int); + int pthread_attr_setscope(in pthread_attr_t*, int); + int pthread_getschedparam(pthread_t, int*, sched_param*); + int pthread_setschedparam(pthread_t, int, in sched_param*); + int pthread_setschedprio(pthread_t, int); +} else version (Solaris) { enum @@ -953,6 +1081,15 @@ else version( FreeBSD ) int pthread_attr_setstackaddr(pthread_attr_t*, void*); int pthread_attr_setstacksize(pthread_attr_t*, size_t); } +else version (AIX) +{ + 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 version (Solaris) { int pthread_attr_getstack(in pthread_attr_t*, void**, size_t*); @@ -1015,6 +1152,15 @@ else version( OSX ) int pthread_rwlockattr_getpshared(in pthread_rwlockattr_t*, int*); int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int); } +else version (AIX) +{ + int pthread_condattr_getpshared(in pthread_condattr_t*, int*); + int pthread_condattr_setpshared(pthread_condattr_t*, int); + int pthread_mutexattr_getpshared(in pthread_mutexattr_t*, int*); + int pthread_mutexattr_setpshared(pthread_mutexattr_t*, int); + int pthread_rwlockattr_getpshared(in pthread_rwlockattr_t*, int*); + int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int); +} else version (Solaris) { int pthread_condattr_getpshared(in pthread_condattr_t*, int*); diff --git a/src/core/sys/posix/pwd.d b/src/core/sys/posix/pwd.d index 69dcd3021f..57b7bd1625 100644 --- a/src/core/sys/posix/pwd.d +++ b/src/core/sys/posix/pwd.d @@ -85,6 +85,19 @@ else version( FreeBSD ) int pw_fields; /* internal: fields filled in */ } } +else version (AIX) +{ + 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 version (Solaris) { struct passwd @@ -143,6 +156,14 @@ else version( FreeBSD ) int getpwnam_r(in char*, passwd*, char*, size_t, passwd**); int getpwuid_r(uid_t, passwd*, char*, size_t, passwd**); } +else version (AIX) +{ + int _posix_getpwnam_r(in char*, passwd*, char*, size_t, passwd**); + int _posix_getpwuid_r(uid_t, passwd*, char*, size_t, passwd**); + + alias _posix_getpwnam_r getpwnam_r; + alias _posix_getpwuid_r getpwuid_r; +} else version (Solaris) { int getpwnam_r(in char*, passwd*, char*, size_t, passwd**); @@ -183,6 +204,12 @@ else version ( FreeBSD ) passwd* getpwent(); void setpwent(); } +else version (AIX) +{ + void endpwent(); + passwd* getpwent(); + void setpwent(); +} else version (Solaris) { void endpwent(); diff --git a/src/core/sys/posix/sched.d b/src/core/sys/posix/sched.d index 3a2309aa7a..986a036721 100644 --- a/src/core/sys/posix/sched.d +++ b/src/core/sys/posix/sched.d @@ -86,6 +86,27 @@ else version( FreeBSD ) enum SCHED_OTHER = 2; enum SCHED_RR = 3; } +else version (AIX) +{ + struct sched_param + { + int sched_priority; + int sched_policy; + int[6] sched_reserved; + } + + enum + { + SCHED_OTHER = 0, + SCHED_FIFO = 1, + SCHED_RR = 2, + SCHED_LOCAL = 3, + SCHED_GLOBAL = 4, + SCHED_FIFO2 = 5, + SCHED_FIFO3 = 6, + SCHED_FIFO4 = 7, + } +} else version (Solaris) { struct sched_param @@ -144,6 +165,10 @@ else version( FreeBSD ) { int sched_yield(); } +else version (AIX) +{ + int sched_yield(); +} else version (Solaris) { int sched_yield(); @@ -184,6 +209,12 @@ else version( FreeBSD ) int sched_get_priority_max(int); int sched_rr_get_interval(pid_t, timespec*); } +else version (AIX) +{ + int sched_get_priority_min(int); + int sched_get_priority_max(int); + int sched_rr_get_interval(pid_t, timespec*); +} else version (Solaris) { int sched_get_priority_max(int); diff --git a/src/core/sys/posix/semaphore.d b/src/core/sys/posix/semaphore.d index b9bf5fb15b..81a2756785 100644 --- a/src/core/sys/posix/semaphore.d +++ b/src/core/sys/posix/semaphore.d @@ -81,6 +81,15 @@ else version( FreeBSD ) enum SEM_FAILED = cast(sem_t*) null; } +else version (AIX) +{ + struct sem_t + { + /* Managed by OS */ + } + + enum SEM_FAILED = cast(sem_t*) -1; +} else version (Solaris) { struct sem_t @@ -137,6 +146,10 @@ else version( FreeBSD ) { int sem_timedwait(sem_t*, in timespec*); } +else version (AIX) +{ + int sem_timedwait(sem_t*, in timespec*); +} else version (Solaris) { int sem_timedwait(sem_t*, in timespec*); diff --git a/src/core/sys/posix/signal.d b/src/core/sys/posix/signal.d index 8417153f3d..8b9a1eb6f1 100644 --- a/src/core/sys/posix/signal.d +++ b/src/core/sys/posix/signal.d @@ -105,7 +105,32 @@ union sigval void* sival_ptr; } -version( Solaris ) +version( AIX ) +{ + union sigval + { + int sival_ptr; // Always 32bit! + int sival_int; + } +} +else +{ + union sigval + { + int sival_int; + void* sival_ptr; + } +} + +version( AIX ) +{ + // TODO Check if a sysconf call is possible. + // There is at least sysconf(_SC_RTSIG_MAX) available. + // See: http://www-01.ibm.com/support/knowledgecenter/ssw_aix_71/com.ibm.aix.basetrf2/sysconf.htm?lang=en + enum SIGRTMIN = 50; + enum SIGRTMAX = 57; +} +else version( Solaris ) { import core.sys.posix.unistd; private int _sigrtmin() { return cast(int) sysconf(_SC_SIGRT_MIN); } @@ -395,6 +420,30 @@ else version( FreeBSD ) enum SIGUSR2 = 31; enum SIGURG = 16; } +else version (AIX) +{ + //SIGABRT (defined in core.stdc.signal) + enum SIGALRM = 14; + enum SIGBUS = 10; + enum SIGCHLD = 20; + enum SIGCONT = 19; + //SIGFPE (defined in core.stdc.signal) + enum SIGHUP = 1; + //SIGILL (defined in core.stdc.signal) + //SIGINT (defined in core.stdc.signal) + enum SIGKILL = 9; + enum SIGPIPE = 13; + enum SIGQUIT = 3; + //SIGSEGV (defined in core.stdc.signal) + enum SIGSTOP = 17; + //SIGTERM (defined in core.stdc.signal) + enum SIGTSTP = 18; + enum SIGTTIN = 21; + enum SIGTTOU = 22; + enum SIGUSR1 = 30; + enum SIGUSR2 = 31; + enum SIGURG = 16; +} else version (Solaris) { enum SIGALRM = 14; @@ -453,6 +502,19 @@ else version( FreeBSD ) sigset_t sa_mask; } } +else version (AIX) +{ + struct sigaction_t + { + union + { + sigfn_t sa_handler; + sigactfn_t sa_sigaction; + } + sigset_t sa_mask; + int sa_flags; + } +} else version (Solaris) { struct sigaction_t @@ -855,6 +917,54 @@ else version( FreeBSD ) int sigsuspend(in sigset_t *); int sigwait(in sigset_t*, int*); } +else version (AIX) +{ + struct sigset_t + { + c_ulong[4] ss_set; + uint losigs; + uint hisigs; + } + + // TODO: This is buggy. + struct siginfo_t + { + int si_signo; + int si_errno; + int si_code; + int si_pid; + uid_t si_uid; + version (D_LP64) + { + int si_status; + void *si_addr; + } + else + { + void *si_addr; + int si_status; + } + + c_long si_band; + sigval si_value; + int __si_flags; + version (D_LP64) + int __pad[3]; + else + int __pad[6]; + } + + 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*); +} else version (Solaris) { enum SIG_HOLD = cast(sigfn_t2)2; @@ -1626,6 +1736,119 @@ else version( FreeBSD ) int sigpause(int); int sigrelse(int); } +else version (AIX) +{ + enum SIGPOLL = 23; + enum SIGPROF = 32; + enum SIGSYS = 12; + enum SIGTRAP = 5; + enum SIGVTALRM = 34; + enum SIGXCPU = 24; + enum SIGXFSZ = 25; + + enum + { + SA_ONSTACK = 0x00000001, + SA_RESTART = 0x00000008, + SA_RESETHAND = 0x00000002, + SA_SIGINFO = 0x00000100, + SA_NODEFER = 0x00000200, + SA_NOCLDWAIT = 0x00000400, + } + + enum + { + SS_ONSTACK = 0x00000001, + SS_DISABLE = 0x00000002, + } + + struct stack_t + { + uint ss_sp; // Always 32bit + uint ss_size; // Always 32bit + int ss_flags; + int[4] __pad; + } + + enum + { + ILL_ILLOPC = 30, + ILL_ILLOPN = 31, + ILL_ILLADR = 32, + ILL_ILLTRP = 33, + ILL_PRVOPC = 34, + ILL_PRVREG = 35, + ILL_COPROC = 36, + ILL_BADSTK = 37, + } + + enum + { + BUS_ADRALN = 1, + BUS_ADRERR = 2, + BUS_OBJERR = 3, + BUS_UEGARD = 4, + } + + enum + { + SEGV_MAPERR = 50, + SEGV_ACCERR = 51, + SEGV_KEYERR = 52, + } + + enum + { + FPE_INTDIV = 20, + FPE_INTOVF = 21, + FPE_FLTDIV = 22, + FPE_FLTOVF = 23, + FPE_FLTUND = 24, + FPE_FLTRES = 25, + FPE_FLTINV = 26, + FPE_FLTSUB = 27, + } + + enum + { + TRAP_BRKPT = 60, + TRAP_TRACE = 61, + } + + enum + { + CLD_EXITED = 10, + CLD_KILLED = 11, + CLD_DUMPED = 12, + CLD_TRAPPED = 13, + CLD_STOPPED = 14, + CLD_CONTINUED = 15, + } + + enum + { + POLL_IN = 40, + POLL_OUT = 41, + POLL_MSG = -3, + POLL_ERR = 43, + POLL_PRI = 44, + POLL_HUP = 45, + } + + nothrow: + @nogc: + sigfn_t2 bsd_signal(int sig, sigfn_t2 func); + sigfn_t2 sigset(int sig, sigfn_t2 func); + + int killpg(pid_t, int); + int sigaltstack(in stack_t*, stack_t*); + int sighold(int); + int sigignore(int); + int siginterrupt(int, int); + int sigpause(int); + int sigrelse(int); + //int sigstack(sigstack *, sigstack *); +} else version (Solaris) { enum SIGPOLL = 22; @@ -1929,6 +2152,14 @@ else version( FreeBSD ) c_long tv_nsec; } } +else version (AIX) +{ + struct timespec + { + time_t tv_sec; + c_long tv_nsec; + } +} else version (Solaris) { struct timespec @@ -2027,6 +2258,21 @@ else version( FreeBSD ) else version (OSX) { } +else version (AIX) +{ + struct sigevent + { + sigval sigev_value; + int sigev_signo; + int sigev_notify; + int sigev_notify_function; // Always 23bit. + int sigev_notify_attributes; // Always 23bit. + } + + int sigqueue(pid_t, int, sigval); + int sigtimedwait(in sigset_t*, siginfo_t*, in timespec *); + int sigwaitinfo(in sigset_t*, siginfo_t*); +} else version (Solaris) { struct sigevent @@ -2097,6 +2343,11 @@ else version( FreeBSD ) int pthread_kill(pthread_t, int); int pthread_sigmask(int, in sigset_t*, sigset_t*); } +else version (AIX) +{ + int pthread_kill(pthread_t, int); + int pthread_sigmask(int, in sigset_t*, sigset_t*); +} else version (Solaris) { int pthread_kill(pthread_t, int); diff --git a/src/core/sys/posix/sys/stat.d b/src/core/sys/posix/sys/stat.d index b2cb663a26..669ff1a36b 100644 --- a/src/core/sys/posix/sys/stat.d +++ b/src/core/sys/posix/sys/stat.d @@ -777,6 +777,80 @@ else version( FreeBSD ) 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 version (AIX) +{ + struct stat_t + { + dev_t st_dev; + ino_t st_ino; + mode_t st_mode; + nlink_t st_nlink; + ushort_t st_flag; + uid_t st_uid; + gid_t st_gid; + + dev_t st_rdev; + version (D_LP64) + int st_ssize; + else + off_t st_size; + version (false /*_XOPEN_SOURCE>=700*/) + { + st_timespec_t st_atim; + st_timespec_t st_mtim; + st_timespec_t st_ctim; + } + else + { + time_t st_atime; + int st_atime_n; + time_t st_mtime; + int st_mtime_n; + time_t st_ctime; + int st_ctime_n; + } + blksize_t st_blksize; + blkcnt_t st_blocks; + int st_vfstype; + uint_t st_vfs; + uint_t st_type; + uint_t st_gen; + uint_t st_reserved[9]; + version (D_LP64) + { + uint_t st_padto_ll; + off_t st_size; + } + } + + enum S_IFMT = 0xF000; // octal 0170000 + enum + { + S_IFSOCK = 0xC000, // octal 0140000 + S_IFLNK = 0xA000, // octal 0120000 + S_IFREG = 0x8000, // octal 0100000 + S_IFDIR = 0x4000, // octal 0040000 + S_IFBLK = 0x6000, // octal 0060000 + S_IFCHR = 0x2000, // octal 0020000 + S_IFIFO = 0x1000, // octal 0010000 + } + + 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 version (Solaris) { private enum _ST_FSTYPSZ = 16; @@ -892,6 +966,8 @@ else version (Solaris) } + pragma(message, "TODO: Add 64bit / _LARGEFILE support") + enum S_IRUSR = 0x100; enum S_IWUSR = 0x080; enum S_IXUSR = 0x040; @@ -1056,6 +1132,10 @@ version( CRuntime_Glibc ) int lstat(in char*, stat_t*); int stat(in char*, stat_t*); } +} +else version (AIX) +{ + } else version (Solaris) { diff --git a/src/core/sys/posix/sys/types.d b/src/core/sys/posix/sys/types.d index 6e1adef62f..0687dc7c09 100644 --- a/src/core/sys/posix/sys/types.d +++ b/src/core/sys/posix/sys/types.d @@ -138,6 +138,23 @@ else version( FreeBSD ) alias uint uid_t; alias uint fflags_t; } +else version (AIX) +{ + alias c_long blkcnt_t; + alias c_long blksize_t; + alias c_long dev_t; + alias uint gid_t; + alias ulong ino_t; + alias uint mode_t; + alias short nlink_t; + alias long off_t; + alias c_long pid_t; + //size_t (defined in core.stdc.stddef) + alias c_long ssize_t; + alias c_long time_t; + alias uint uid_t; + alias uint rid_t; +} else version (Solaris) { alias char* caddr_t; @@ -269,6 +286,16 @@ else version( FreeBSD ) alias c_long suseconds_t; alias uint useconds_t; } +else version (AIX) +{ + alias c_ulong fsblkcnt_t; + alias c_ulong fsfilcnt_t; + alias int clock_t; + alias c_long id_t; + alias c_long key_t; + alias int suseconds_t; + alias uint useconds_t; +} else version (Solaris) { static if (__USE_FILE_OFFSET64) @@ -645,6 +672,50 @@ else version( FreeBSD ) alias void* pthread_rwlockattr_t; alias void* pthread_t; } +else version (AIX) +{ + alias void* pthread_attr_t; + + struct pthread_cond_t + { + version (D_LP64) + long[6] __cv_word; + else + int[11] __cv_word; + } + + alias void* pthread_condattr_t; + alias uint pthread_key_t; + + struct pthread_mutex_t + { + version (D_LP64) + long[8] __mt_word; + else + int[13] __mt_word; + } + + alias void* pthread_mutexattr_t; + + struct pthread_once_t + { + version (D_LP64) + long[9] __on_word; + else + int[28] __on_word; + } + + struct pthread_rwlock_t + { + version (D_LP64) + long[10] __rw_word; + else + int[52] __rw_word; + } + + alias void* pthread_rwlockattr_t; + alias uint pthread_t; +} else version (Solaris) { alias uint pthread_t; @@ -809,6 +880,17 @@ else version( FreeBSD ) alias void* pthread_barrier_t; alias void* pthread_barrierattr_t; } +else version( AIX ) +{ + struct pthread_barrier_t + { + version (D_LP64) + long[5] __br_word; + else + int[8] __br_word; + } + alias void* pthread_barrierattr_t; +} else version( OSX ) { } @@ -852,6 +934,16 @@ else version( FreeBSD ) { alias void* pthread_spinlock_t; } +else version (AIX) +{ + struct pthread_spinlock_t + { + version (D_LP64) + long[3] __sp_word; + else + int[6] __sp_word; + } +} else version (Solaris) { alias pthread_mutex_t pthread_spinlock_t; diff --git a/src/core/sys/posix/time.d b/src/core/sys/posix/time.d index 41fa358a62..6818f36b3a 100644 --- a/src/core/sys/posix/time.d +++ b/src/core/sys/posix/time.d @@ -52,6 +52,10 @@ else version( FreeBSD ) { time_t timegm(tm*); // non-standard } +else version (AIX) +{ + // Not supported. +} else version (Solaris) { time_t timegm(tm*); // non-standard @@ -119,6 +123,13 @@ else version (OSX) { // No CLOCK_MONOTONIC defined } +else version (AIX) +{ + enum : clockid_t + { + CLOCK_MONOTONIC = 10, + } +} else version (Solaris) { enum CLOCK_MONOTONIC = 4; @@ -245,6 +256,38 @@ else version( FreeBSD ) int timer_getoverrun(timer_t); int timer_settime(timer_t, int, in itimerspec*, itimerspec*); } +else version (AIX) +{ + enum : clockid_t + { + CLOCK_PROCESS_CPUTIME_ID = 11, + CLOCK_THREAD_CPUTIME_ID = 12, + } + struct itimerspec { + timespec it_interval; + timespec it_value; + } + + enum : clockid_t + { + CLOCK_REALTIME = 9, + } + enum TIMER_ABSTIME = 999; + + alias long clockid_t; // + alias long timer_t; + + int clock_getres(clockid_t, timespec*); + int clock_gettime(clockid_t, timespec*); + int clock_settime(clockid_t, in timespec*); + int clock_getcpuclockid(pid_t, clockid_t*); + int nanosleep(in timespec*, timespec*); + int timer_create(clockid_t, sigevent*, timer_t*); + int timer_delete(timer_t); + int timer_gettime(timer_t, itimerspec*); + int timer_getoverrun(timer_t); + int timer_settime(timer_t, int, in itimerspec*, itimerspec*); +} else version (Solaris) { enum CLOCK_PROCESS_CPUTIME_ID = 5; // @@ -338,6 +381,13 @@ else version( FreeBSD ) tm* gmtime_r(in time_t*, tm*); tm* localtime_r(in time_t*, tm*); } +else version (AIX) +{ + 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 version (Solaris) { char* asctime_r(in tm*, char*); @@ -391,6 +441,14 @@ else version( FreeBSD ) //tm* getdate(in char*); char* strptime(in char*, in char*, tm*); } +else version (AIX) +{ + extern __gshared int daylight; + extern __gshared c_long timezone; + + tm* getdate(in char*); + char* strptime(in char*, in char*, tm*); +} else version (Solaris) { extern __gshared c_long timezone, altzone;