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

Commit

Permalink
OpenBSD: Additions for core.sys.posix.*, part 2
Browse files Browse the repository at this point in the history
Add OpenBSD definitions to core.sys.posix.* modules.
  • Loading branch information
redstar committed Jul 17, 2016
1 parent 56698f6 commit 940af5c
Show file tree
Hide file tree
Showing 8 changed files with 551 additions and 0 deletions.
124 changes: 124 additions & 0 deletions src/core/sys/posix/pthread.d
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
}
Expand Down Expand Up @@ -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)
{
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
}
Expand Down Expand Up @@ -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*);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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*);
Expand Down Expand Up @@ -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*);
Expand Down
27 changes: 27 additions & 0 deletions src/core/sys/posix/pwd.d
Expand Up @@ -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
Expand Down Expand Up @@ -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**);
Expand Down Expand Up @@ -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();
Expand Down
21 changes: 21 additions & 0 deletions src/core/sys/posix/sched.d
Expand Up @@ -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
Expand Down Expand Up @@ -153,6 +164,10 @@ else version( FreeBSD )
{
int sched_yield();
}
else version( OpenBSD )
{
int sched_yield();
}
else version (Solaris)
{
int sched_yield();
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/core/sys/posix/semaphore.d
Expand Up @@ -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
Expand Down Expand Up @@ -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*);
Expand Down
51 changes: 51 additions & 0 deletions src/core/sys/posix/setjmp.d
Expand Up @@ -170,6 +170,45 @@ else version( FreeBSD )
int setjmp(ref jmp_buf);
void longjmp(ref jmp_buf, int);
}
else version( OpenBSD )
{
// <machine/setjmp.h>
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 )
{
// <machine/setjmp.h>
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 940af5c

Please sign in to comment.