diff --git a/src/core/sys/posix/pthread.d b/src/core/sys/posix/pthread.d index b4cb78a037d..f282991fde0 100644 --- a/src/core/sys/posix/pthread.d +++ b/src/core/sys/posix/pthread.d @@ -218,6 +218,46 @@ else version( FreeBSD ) enum PTHREAD_COND_INITIALIZER = null; enum PTHREAD_RWLOCK_INITIALIZER = null; } +else version( OpenBSD ) +{ + enum + { + PTHREAD_DETACHED = 0x1, + PTHREAD_INHERIT_SCHED = 0x4, + PTHREAD_NOFLOAT = 0x8, + + PTHREAD_CREATE_DETACHED = PTHREAD_DETACHED, + PTHREAD_CREATE_JOINABLE = 0, + PTHREAD_EXPLICIT_SCHED = 0, + } + + enum + { + PTHREAD_PROCESS_PRIVATE = 0, + PTHREAD_PROCESS_SHARED = 1, + } + + enum + { + PTHREAD_CANCEL_ENABLE = 0, + PTHREAD_CANCEL_DISABLE = 1, + PTHREAD_CANCEL_DEFERRED = 0, + PTHREAD_CANCEL_ASYNCHRONOUS = 2, + } + + enum PTHREAD_CANCELED = cast(void*) 1; + + enum + { + PTHREAD_NEEDS_INIT = 0, + PTHREAD_DONE_INIT = 1, + } + + enum PTHREAD_MUTEX_INITIALIZER = null; + //enum PTHREAD_ONCE_INIT = { PTHREAD_NEEDS_INIT, PTHREAD_MUTEX_INITIALIZER }; + enum PTHREAD_COND_INITIALIZER = null; + enum PTHREAD_RWLOCK_INITIALIZER = null; +} else version (Solaris) { enum @@ -371,6 +411,11 @@ else version( FreeBSD ) void __pthread_cleanup_push_imp(_pthread_cleanup_routine, void*, _pthread_cleanup_info*); void __pthread_cleanup_pop_imp(int); } +else version ( OpenBSD ) +{ + void pthread_cleanup_push(void function(void*), void*); + void pthread_cleanup_pop(int); +} else version (Solaris) { alias void function(void*) _pthread_cleanup_routine; @@ -516,6 +561,18 @@ else version( FreeBSD ) int pthread_barrierattr_init(pthread_barrierattr_t*); int pthread_barrierattr_setpshared(pthread_barrierattr_t*, int); } +else version( OpenBSD ) +{ + enum PTHREAD_BARRIER_SERIAL_THREAD = -1; + + int pthread_barrier_destroy(pthread_barrier_t*); + int pthread_barrier_init(pthread_barrier_t*, in pthread_barrierattr_t*, uint); + int pthread_barrier_wait(pthread_barrier_t*); + int pthread_barrierattr_destroy(pthread_barrierattr_t*); + int pthread_barrierattr_getpshared(in pthread_barrierattr_t*, int*); + int pthread_barrierattr_init(pthread_barrierattr_t*); + int pthread_barrierattr_setpshared(pthread_barrierattr_t*, int); +} else version (Darwin) { } @@ -574,6 +631,14 @@ else version( FreeBSD ) int pthread_spin_trylock(pthread_spinlock_t*); int pthread_spin_unlock(pthread_spinlock_t*); } +else version( OpenBSD ) +{ + 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 (Darwin) { } @@ -657,6 +722,25 @@ else version( FreeBSD ) int pthread_mutexattr_settype(pthread_mutexattr_t*, int) @trusted; int pthread_setconcurrency(int); } +else version( OpenBSD ) +{ + enum + { + PTHREAD_MUTEX_ERRORCHECK = 1, + PTHREAD_MUTEX_RECURSIVE = 2, + PTHREAD_MUTEX_NORMAL = 3, + PTHREAD_MUTEX_ADAPTIVE_NP = 4, + PTHREAD_MUTEX_TYPE_MAX + } + enum PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_ERRORCHECK; + + 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) @trusted; + int pthread_setconcurrency(int); +} else version (Solaris) { enum @@ -707,6 +791,10 @@ else version( FreeBSD ) { int pthread_getcpuclockid(pthread_t, clockid_t*); } +else version( OpenBSD ) +{ + int pthread_getcpuclockid(pthread_t, clockid_t*); +} else version (Darwin) { } @@ -749,6 +837,12 @@ else version( FreeBSD ) int pthread_rwlock_timedrdlock(pthread_rwlock_t*, in timespec*); int pthread_rwlock_timedwrlock(pthread_rwlock_t*, in timespec*); } +else version( OpenBSD ) +{ + 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*); @@ -885,6 +979,24 @@ else version( FreeBSD ) int pthread_setschedparam(pthread_t, int, sched_param*); // int pthread_setschedprio(pthread_t, int); // not implemented } +else version( OpenBSD ) +{ + enum + { + PTHREAD_SCOPE_PROCESS = 0, + PTHREAD_SCOPE_SYSTEM = 0x2 + } + + 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, sched_param*); + // int pthread_setschedprio(pthread_t, int); // not implemented +} else version (Solaris) { enum @@ -962,6 +1074,15 @@ else version( FreeBSD ) int pthread_attr_setstackaddr(pthread_attr_t*, void*); int pthread_attr_setstacksize(pthread_attr_t*, size_t); } +else version( OpenBSD ) +{ + 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 +1136,9 @@ else version( FreeBSD ) int pthread_rwlockattr_getpshared(in pthread_rwlockattr_t*, int*); int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int); } +else version( OpenBSD ) +{ +} else version( Darwin ) { 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 d73286237c2..ddd35f9952d 100644 --- a/src/core/sys/posix/pwd.d +++ b/src/core/sys/posix/pwd.d @@ -94,6 +94,22 @@ else version( FreeBSD ) int pw_fields; /* internal: fields filled in */ } } +else version( OpenBSD ) +{ + struct passwd + { + char* pw_name; /* user name */ + char* pw_passwd; /* encrypted password */ + uid_t pw_uid; /* user uid */ + gid_t pw_gid; /* user gid */ + time_t pw_change; /* password change time */ + char* pw_class; /* user access class */ + char* pw_gecos; /* Honeywell login info */ + char* pw_dir; /* home directory */ + char* pw_shell; /* default shell */ + time_t pw_expire; /* account expiration */ + } +} else version (Solaris) { struct passwd @@ -152,6 +168,11 @@ 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( OpenBSD ) +{ + int getpwnam_r(in char*, passwd*, char*, size_t, passwd**); + int getpwuid_r(uid_t, passwd*, char*, size_t, passwd**); +} else version (Solaris) { int getpwnam_r(in char*, passwd*, char*, size_t, passwd**); @@ -192,6 +213,12 @@ else version ( FreeBSD ) passwd* getpwent(); void setpwent(); } +else version ( OpenBSD ) +{ + 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 c3597ca9848..637545cf164 100644 --- a/src/core/sys/posix/sched.d +++ b/src/core/sys/posix/sched.d @@ -95,6 +95,17 @@ else version( FreeBSD ) enum SCHED_OTHER = 2; enum SCHED_RR = 3; } +else version( OpenBSD ) +{ + struct sched_param + { + int sched_priority; + } + + enum SCHED_FIFO = 1; + enum SCHED_OTHER = 2; + enum SCHED_RR = 3; +} else version (Solaris) { struct sched_param @@ -153,6 +164,10 @@ else version( FreeBSD ) { int sched_yield(); } +else version( OpenBSD ) +{ + int sched_yield(); +} else version (Solaris) { int sched_yield(); @@ -193,6 +208,12 @@ else version( FreeBSD ) int sched_get_priority_max(int); int sched_rr_get_interval(pid_t, timespec*); } +else version( OpenBSD ) +{ + 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 72741d097cf..ba294822850 100644 --- a/src/core/sys/posix/semaphore.d +++ b/src/core/sys/posix/semaphore.d @@ -90,6 +90,13 @@ else version( FreeBSD ) enum SEM_FAILED = cast(sem_t*) null; } +else version( OpenBSD ) +{ + struct __sem { } + alias sem_t = __sem*; + + enum SEM_FAILED = cast(sem_t*) null; +} else version (Solaris) { struct sem_t @@ -146,6 +153,10 @@ else version( FreeBSD ) { int sem_timedwait(sem_t*, in timespec*); } +else version( OpenBSD ) +{ + int sem_timedwait(sem_t*, in timespec*); +} else version (Solaris) { int sem_timedwait(sem_t*, in timespec*); diff --git a/src/core/sys/posix/setjmp.d b/src/core/sys/posix/setjmp.d index e5758c524b3..8a1d4cc59f3 100644 --- a/src/core/sys/posix/setjmp.d +++ b/src/core/sys/posix/setjmp.d @@ -170,6 +170,45 @@ else version( FreeBSD ) int setjmp(ref jmp_buf); void longjmp(ref jmp_buf, int); } +else version( OpenBSD ) +{ + // + version( X86 ) + { + enum _JBLEN = 10; + } + else version( X86_64) + { + enum _JBLEN = 11; + } + else version( ARM ) + { + enum _JBLEN = 64; + } + else version( PPC ) + { + enum _JBLEN = 100; + } + else version( MIPS64 ) + { + enum _JBLEN = 83; + } + else version( SPARC ) + { + enum _JBLEN = 10; + } + else version( SPARC64 ) + { + enum _JBLEN = 14; + } + else + static assert(0); + + alias jmp_buf = c_long[_JBLEN]; + + int setjmp(ref jmp_buf); + void longjmp(ref jmp_buf, int); +} else version( CRuntime_Bionic ) { // @@ -238,6 +277,13 @@ else version( FreeBSD ) int sigsetjmp(ref sigjmp_buf); void siglongjmp(ref sigjmp_buf, int); } +else version( OpenBSD ) +{ + alias sigjmp_buf = c_long[_JBLEN + 1]; + + int sigsetjmp(ref sigjmp_buf); + void siglongjmp(ref sigjmp_buf, int); +} else version( CRuntime_Bionic ) { alias c_long[_JBLEN + 1] sigjmp_buf; @@ -264,6 +310,11 @@ else version( FreeBSD ) int _setjmp(ref jmp_buf); void _longjmp(ref jmp_buf, int); } +else version( OpenBSD ) +{ + int _setjmp(ref jmp_buf); + void _longjmp(ref jmp_buf, int); +} else version( CRuntime_Bionic ) { int _setjmp(ref jmp_buf); diff --git a/src/core/sys/posix/signal.d b/src/core/sys/posix/signal.d index fb57e9c5af6..dcdac9ab102 100644 --- a/src/core/sys/posix/signal.d +++ b/src/core/sys/posix/signal.d @@ -434,6 +434,30 @@ else version( FreeBSD ) enum SIGUSR2 = 31; enum SIGURG = 16; } +else version( OpenBSD ) +{ + //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; @@ -492,6 +516,21 @@ else version( FreeBSD ) sigset_t sa_mask; } } +else version( OpenBSD ) +{ + struct sigaction_t + { + union + { + sigfn_t __sa_handler; + alias sa_handler = __sa_handler; + sigactfn_t __sa_sigaction; + alias sa_sigaction = __sa_sigaction; + } + sigset_t sa_mask; + int sa_flags; + } +} else version (Solaris) { struct sigaction_t @@ -894,6 +933,82 @@ else version( FreeBSD ) int sigsuspend(in sigset_t *); int sigwait(in sigset_t*, int*); } +else version( OpenBSD ) +{ + enum SIG_CATCH = cast(sigfn_t2) 2; + enum SIG_HOLD = cast(sigfn_t2) 3; + + alias sigset_t = uint; + + enum SA_NOCLDSTOP = 0x0008; + + enum SIG_BLOCK = 1; + enum SIG_UNBLOCK = 2; + enum SIG_SETMASK = 3; + + private enum SI_MAXSZ = 128; + private enum SI_PAD = (SI_MAXSZ / int.sizeof) - 3; + + struct siginfo_t + { + int si_signo; + int si_errno; + int si_code; + union _data + { + int[SI_PAD] _pad; + struct _proc + { + pid_t _pid; + union _pdata + { + struct _kill + { + uid_t _uid; + sigval _value; + } + struct _cld + { + clock_t _utime; + clock_t _stime; + int _status; + } + } + } + struct _fault + { + caddr_t _addr; + int _trapno; + } + } + alias si_pid = _data._proc._pid; + alias si_status = _data._proc._pdata._cld._status; + alias si_stime = _data._proc._pdata._cld._stime; + alias si_utime = _data._proc._pdata._cld._utime; + alias si_uid = _data._proc._pdata._kill._uid; + alias si_value = _data._proc._pdata._kill._value; + alias si_addr = _data._fault._addr; + alias si_trapno = _data._fault._trapno; + } + + enum SI_NOINFO = 32767; + enum SI_USER = 0; + enum SI_LWP = -1; + enum SI_QUEUE = -2; + enum SI_TIMER = -3; + + 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 version (Solaris) { enum SIG_HOLD = cast(sigfn_t2)2; @@ -1665,6 +1780,122 @@ else version( FreeBSD ) int sigpause(int); int sigrelse(int); } +else version (OpenBSD) +{ + // No SIGPOLL on *BSD + enum SIGPROF = 27; + enum SIGSYS = 12; + enum SIGTRAP = 5; + enum SIGVTALRM = 26; + enum SIGXCPU = 24; + enum SIGXFSZ = 25; + + enum + { + SA_ONSTACK = 0x0001, + SA_RESTART = 0x0002, + SA_RESETHAND = 0x0004, + SA_NODEFER = 0x0010, + SA_NOCLDWAIT = 0x0020, + SA_SIGINFO = 0x0040, + } + + enum + { + SS_ONSTACK = 0x0001, + SS_DISABLE = 0x0004, + } + + enum MINSIGSTKSZ = 8192; + enum SIGSTKSZ = (MINSIGSTKSZ + 32768); + + //ucontext_t (defined in core.sys.posix.ucontext) + //mcontext_t (defined in core.sys.posix.ucontext) + + struct stack_t + { + void* ss_sp; + size_t ss_size; + int ss_flags; + } + + enum + { + ILL_ILLOPC = 1, + ILL_ILLOPN, + ILL_ILLADR, + ILL_ILLTRP, + ILL_PRVOPC, + ILL_PRVREG, + ILL_COPROC, + ILL_BADSTK, + NSIGILL = ILL_BADSTK, + } + + enum + { + BUS_ADRALN = 1, + BUS_ADRERR, + BUS_OBJERR, + NSIGBUS = BUS_OBJERR, + } + + enum + { + SEGV_MAPERR = 1, + SEGV_ACCERR, + NSIGSEGV = SEGV_ACCERR, + } + + enum + { + FPE_INTDIV = 1, + FPE_INTOVF, + FPE_FLTDIV, + FPE_FLTOVF, + FPE_FLTUND, + FPE_FLTRES, + FPE_FLTINV, + FPE_FLTSUB, + NSIGFPE = FPE_FLTSUB, + } + + enum + { + TRAP_BRKPT = 1, + TRAP_TRACE, + NSIGTRAP = TRAP_TRACE, + } + + enum + { + CLD_EXITED = 1, + CLD_KILLED, + CLD_DUMPED, + CLD_TRAPPED, + CLD_STOPPED, + CLD_CONTINUED, + NSIGCLD = CLD_CONTINUED, + } + + enum + { + POLL_IN = 1, + POLL_OUT, + POLL_MSG, + POLL_ERR, + POLL_PRI, + POLL_HUP, + NSIGPOLL = POLL_HUP, + } + + nothrow: + @nogc: + int killpg(pid_t, int); + int sigaltstack(in stack_t*, stack_t*); + int siginterrupt(int, int); + int sigpause(int); +} else version (Solaris) { enum SIGPOLL = 22; @@ -1968,6 +2199,14 @@ else version( FreeBSD ) c_long tv_nsec; } } +else version( OpenBSD ) +{ + struct timespec + { + time_t tv_sec; + c_long tv_nsec; + } +} else version (Solaris) { struct timespec @@ -2063,6 +2302,9 @@ else version( FreeBSD ) int sigtimedwait(in sigset_t*, siginfo_t*, in timespec*); int sigwaitinfo(in sigset_t*, siginfo_t*); } +else version (OpenBSD) +{ +} else version (Darwin) { } @@ -2136,6 +2378,11 @@ else version( FreeBSD ) int pthread_kill(pthread_t, int); int pthread_sigmask(int, in sigset_t*, sigset_t*); } +else version( OpenBSD ) +{ + 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/stdio.d b/src/core/sys/posix/stdio.d index de75ffc0c96..4fb3655888c 100644 --- a/src/core/sys/posix/stdio.d +++ b/src/core/sys/posix/stdio.d @@ -246,6 +246,16 @@ version( CRuntime_Glibc ) int putc_unlocked(int, FILE*); int putchar_unlocked(int); } +else version( OpenBSD ) +{ + void flockfile(FILE*); + int ftrylockfile(FILE*); + void funlockfile(FILE*); + int getc_unlocked(FILE*); + int getchar_unlocked(); + int putc_unlocked(int, FILE*); + int putchar_unlocked(int); +} else version( Solaris ) { void flockfile(FILE*); @@ -281,6 +291,10 @@ version( FreeBSD ) { enum P_tmpdir = "/var/tmp/"; } +version( OpenBSD ) +{ + enum P_tmpdir = "/tmp/"; +} version( Solaris ) { enum P_tmpdir = "/var/tmp/"; diff --git a/src/core/sys/posix/stdlib.d b/src/core/sys/posix/stdlib.d index 3727eb44f25..4afd346d460 100644 --- a/src/core/sys/posix/stdlib.d +++ b/src/core/sys/posix/stdlib.d @@ -100,6 +100,10 @@ else version( FreeBSD ) { int posix_memalign(void**, size_t, size_t); } +else version( OpenBSD ) +{ + int posix_memalign(void**, size_t, size_t); +} else version( Solaris ) { int posix_memalign(void**, size_t, size_t); @@ -134,6 +138,13 @@ else version( FreeBSD ) void* valloc(size_t); // LEGACY non-standard } +else version( OpenBSD ) +{ + int setenv(in char*, in char*, int); + int unsetenv(in char*); + + void* valloc(size_t); // LEGACY non-standard +} else version( CRuntime_Bionic ) { int setenv(in char*, in char*, int); @@ -168,6 +179,10 @@ else version( FreeBSD ) { int rand_r(uint*); } +else version( OpenBSD ) +{ + int rand_r(uint*); +} else version( Solaris ) { int rand_r(uint*); @@ -351,6 +366,47 @@ else version( FreeBSD ) void srandom(uint); int unlockpt(int); } +else version( OpenBSD ) +{ + //WNOHANG (defined in core.sys.posix.sys.wait) + //WUNTRACED (defined in core.sys.posix.sys.wait) + //WEXITSTATUS (defined in core.sys.posix.sys.wait) + //WIFEXITED (defined in core.sys.posix.sys.wait) + //WIFSIGNALED (defined in core.sys.posix.sys.wait) + //WIFSTOPPED (defined in core.sys.posix.sys.wait) + //WSTOPSIG (defined in core.sys.posix.sys.wait) + //WTERMSIG (defined in core.sys.posix.sys.wait) + + c_long a64l(in char*); + double drand48(); + //char* ecvt(double, int, int *, int *); // LEGACY + double erand48(ref ushort[3]); + //char* fcvt(double, int, int *, int *); // LEGACY + //char* gcvt(double, int, char*); // LEGACY + int getsubopt(char**, in char**, char**); + int grantpt(int); + char* initstate(uint, char*, size_t); + c_long jrand48(ref ushort[3]); + char* l64a(c_long); + void lcong48(ref ushort[7]); + c_long lrand48(); + char* mktemp(char*); // LEGACY + int mkstemp(char*); + char* mkdtemp(char*); // Defined in IEEE 1003.1, 2008 Edition + c_long mrand48(); + c_long nrand48(ref ushort[3]); + int posix_openpt(int); + char* ptsname(int); + int putenv(char*); + c_long random(); + char* realpath(in char*, char*); + ushort *seed48(ref ushort[3]); + // void setkey(in char*); // not implemented + char* setstate(in char*); + void srand48(c_long); + void srandom(uint); + int unlockpt(int); +} else version( CRuntime_Bionic ) { double drand48();