Initial commit of NetBSD port

This commit is contained in:
Andreas T Jonsson
2024-04-16 14:27:29 +02:00
parent 97db075e45
commit 4558f3992a
20 changed files with 1154 additions and 17 deletions
+103
View File
@@ -0,0 +1,103 @@
//+build netbsd
package unix
import "core:c"
pthread_t :: distinct u64
SEM_T_SIZE :: 8
PTHREAD_CONDATTR_T_SIZE :: 16
PTHREAD_MUTEXATTR_T_SIZE :: 16
PTHREAD_RWLOCKATTR_T_SIZE :: 16
PTHREAD_BARRIERATTR_T_SIZE :: 16
PTHREAD_COND_T_SIZE :: 40
PTHREAD_MUTEX_T_SIZE :: 48
PTHREAD_RWLOCK_T_SIZE :: 64
PTHREAD_BARRIER_T_SIZE :: 48
PTHREAD_ATTR_T_SIZE :: 16
pthread_cond_t :: struct #align(16) {
_: [PTHREAD_COND_T_SIZE] c.char
}
pthread_mutex_t :: struct #align(16) {
_: [PTHREAD_MUTEX_T_SIZE] c.char
}
pthread_rwlock_t :: struct #align(16) {
_: [PTHREAD_RWLOCK_T_SIZE] c.char
}
pthread_barrier_t :: struct #align(16) {
_: [PTHREAD_BARRIER_T_SIZE] c.char
}
pthread_attr_t :: struct #align(16) {
_: [PTHREAD_ATTR_T_SIZE] c.char
}
pthread_condattr_t :: struct #align(16) {
_: [PTHREAD_CONDATTR_T_SIZE] c.char
}
pthread_mutexattr_t :: struct #align(16) {
_: [PTHREAD_MUTEXATTR_T_SIZE] c.char
}
pthread_rwlockattr_t :: struct #align(16) {
_: [PTHREAD_RWLOCKATTR_T_SIZE] c.char
}
pthread_barrierattr_t :: struct #align(16) {
_: [PTHREAD_BARRIERATTR_T_SIZE] c.char
}
PTHREAD_MUTEX_NORMAL :: 0
PTHREAD_MUTEX_ERRORCHECK :: 1
PTHREAD_MUTEX_RECURSIVE :: 2
PTHREAD_CREATE_JOINABLE :: 0
PTHREAD_CREATE_DETACHED :: 1
PTHREAD_INHERIT_SCHED :: 0
PTHREAD_EXPLICIT_SCHED :: 1
PTHREAD_PROCESS_PRIVATE :: 0
PTHREAD_PROCESS_SHARED :: 1
SCHED_NONE :: -1
SCHED_OTHER :: 0
SCHED_FIFO :: 1
SCHED_RR :: 3
sched_param :: struct {
sched_priority: c.int,
}
sem_t :: struct #align(16) {
_: [SEM_T_SIZE] c.char
}
PTHREAD_CANCEL_ENABLE :: 0
PTHREAD_CANCEL_DISABLE :: 1
PTHREAD_CANCEL_DEFERRED :: 0
PTHREAD_CANCEL_ASYNCHRONOUS :: 1
foreign import "system:pthread"
@(default_calling_convention="c")
foreign pthread {
sem_open :: proc(name: cstring, flags: c.int) -> ^sem_t ---
sem_init :: proc(sem: ^sem_t, pshared: c.int, initial_value: c.uint) -> c.int ---
sem_destroy :: proc(sem: ^sem_t) -> c.int ---
sem_post :: proc(sem: ^sem_t) -> c.int ---
sem_wait :: proc(sem: ^sem_t) -> c.int ---
sem_trywait :: proc(sem: ^sem_t) -> c.int ---
pthread_yield :: proc() ---
pthread_setcancelstate :: proc (state: c.int, old_state: ^c.int) -> c.int ---
pthread_setcanceltype :: proc (type: c.int, old_type: ^c.int) -> c.int ---
pthread_cancel :: proc (thread: pthread_t) -> c.int ---
}
+1 -1
View File
@@ -1,4 +1,4 @@
//+build linux, darwin, freebsd, openbsd, haiku
//+build linux, darwin, freebsd, openbsd, netbsd, haiku
package unix
foreign import "system:pthread"
+31
View File
@@ -0,0 +1,31 @@
package unix
import "core:c"
foreign import libc "system:c"
ERROR_NONE :: 0
EAGAIN :: 35
SIGCONT :: 19
SIG_BLOCK :: 1
SIG_UNBLOCK :: 2
SIG_SETMASK :: 3
siginfo_t :: struct { si_pad: [128]c.char }
sigset_t :: struct { bits: [4]c.uint }
foreign libc {
sigemptyset :: proc(set: ^sigset_t) -> c.int ---
sigaddset :: proc(set: ^sigset_t, _signal: c.int) -> c.int ---
sigtimedwait :: proc(set: ^sigset_t, info: ^siginfo_t, timeout: ^timespec) -> c.int ---
sigwait :: proc(set: ^sigset_t, _signal: ^c.int) -> c.int ---
@(private="file", link_name="__errno") get_error_location :: proc() -> ^c.int ---
}
errno :: #force_inline proc "contextless" () -> int {
return int(get_error_location()^)
}
+3 -2
View File
@@ -1,4 +1,4 @@
//+build linux, darwin, freebsd, openbsd, haiku
//+build linux, darwin, freebsd, openbsd, netbsd, haiku
package unix
when ODIN_OS == .Darwin {
@@ -65,7 +65,8 @@ seconds_since_boot :: proc "c" () -> f64 {
return f64(ts_boottime.tv_sec) + f64(ts_boottime.tv_nsec) / 1e9
}
// TODO(phix): 'nanosleep' here might refere to the wrong version on NetBSD. Need to investigate this further.
// Normally this is solved by just including 'time.h'. So I need to understand the macro-magic going on in there.
inline_nanosleep :: proc "c" (nanoseconds: i64) -> (remaining: timespec, res: i32) {
s, ns := nanoseconds / 1e9, nanoseconds % 1e9
requested := timespec{tv_sec=s, tv_nsec=ns}