Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ targets = [
# Tier 3 targets that are distinct enough to be useful, or have historically
# been documented.
"aarch64-unknown-freebsd",
"aarch64-unknown-helenos",
"aarch64-unknown-hermit",
"aarch64-unknown-illumos",
"aarch64-unknown-netbsd",
Expand All @@ -117,6 +118,7 @@ targets = [
"armv7r-none-eabihf",
"hexagon-unknown-linux-musl",
"i686-unknown-haiku",
"i686-unknown-helenos",
"i686-unknown-netbsd",
"i686-unknown-openbsd",
"i686-wrs-vxworks",
Expand All @@ -128,6 +130,7 @@ targets = [
"mips64el-unknown-linux-muslabi64",
"mipsel-unknown-linux-gnu",
"mipsel-unknown-linux-musl",
"powerpc-unknown-helenos",
"powerpc-unknown-linux-gnuspe",
"powerpc-unknown-netbsd",
"powerpc-wrs-vxworks",
Expand All @@ -149,6 +152,7 @@ targets = [
"riscv64imac-unknown-none-elf",
"s390x-unknown-linux-musl",
"sparc-unknown-linux-gnu",
"sparc64-unknown-helenos",
"sparc64-unknown-netbsd",
"thumbv6m-none-eabi",
"thumbv7em-none-eabi",
Expand All @@ -159,6 +163,7 @@ targets = [
"x86_64-pc-cygwin",
"x86_64-unknown-dragonfly",
"x86_64-unknown-haiku",
"x86_64-unknown-helenos",
"x86_64-unknown-hermit",
"x86_64-unknown-hurd-gnu",
"x86_64-unknown-l4re-uclibc",
Expand Down
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const CHECK_CFG_EXTRA: &[(&str, &[&str])] = &[
"target_os",
&[
"switch", "aix", "ohos", "hurd", "rtems", "visionos", "nuttx", "cygwin", "qurt", "qnx",
"helenos",
],
),
(
Expand Down
5 changes: 5 additions & 0 deletions ci/verify-build.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class TargetResult:
# there is no need to do this given the target tier policy, but the cost is small
# and the saved churn from accidental breakage is significant, so we keep it around.
Target("aarch64-unknown-freebsd", dist=False),
Target("aarch64-unknown-helenos", dist=False),
Target("aarch64-unknown-hermit", dist=False),
Target("aarch64-unknown-illumos", dist=False),
Target("aarch64-unknown-netbsd", dist=False),
Expand All @@ -171,6 +172,7 @@ class TargetResult:
Target("i386-apple-ios", dist=False),
Target("i686-apple-darwin", dist=False),
Target("i686-unknown-haiku", dist=False),
Target("i686-unknown-helenos", dist=False),
Target("i686-unknown-hurd-gnu", dist=False),
Target("i686-unknown-netbsd", dist=False),
Target("i686-unknown-openbsd", dist=False),
Expand All @@ -183,6 +185,7 @@ class TargetResult:
Target("mips64el-unknown-linux-muslabi64", dist=False),
Target("mipsel-unknown-linux-gnu", dist=False),
Target("mipsel-unknown-linux-musl", dist=False),
Target("powerpc-unknown-helenos", dist=False),
Target("powerpc-unknown-linux-gnuspe", dist=False),
Target("powerpc-unknown-netbsd", dist=False),
Target("powerpc-wrs-vxworks", dist=False),
Expand All @@ -204,12 +207,14 @@ class TargetResult:
Target("riscv64imac-unknown-none-elf", dist=False),
Target("s390x-unknown-linux-musl", dist=False),
Target("sparc-unknown-linux-gnu", dist=False),
Target("sparc64-unknown-helenos", dist=False),
Target("sparc64-unknown-netbsd", dist=False),
Target("thumbv7em-none-eabihf", dist=False),
Target("thumbv7m-none-eabi", dist=False),
Target("thumbv8m.main-none-eabi", dist=False),
Target("x86_64-unknown-dragonfly", dist=False),
Target("x86_64-unknown-haiku", dist=False),
Target("x86_64-unknown-helenos", dist=False),
Target("x86_64-unknown-hermit", dist=False),
Target("x86_64-unknown-l4re-uclibc", dist=False),
Target("x86_64-unknown-openbsd", dist=False),
Expand Down
77 changes: 77 additions & 0 deletions src/helenos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use crate::prelude::*;
use crate::{
errno_t,
timespec,
};

pub type intmax_t = i64;
pub type uintmax_t = u64;
pub type intptr_t = isize;
pub type uintptr_t = usize;
pub type size_t = usize;
pub type ssize_t = isize;

// uspace/lib/posix/include/posix/pthread.h
pub type pthread_key_t = c_int;

// uspace/lib/posix/include/posix/sys/types.h
pub type clockid_t = c_int;
pub type pid_t = c_int;

s! {
// common/include/adt/list.h
pub struct link_t {
pub next: *mut link_t,
pub prev: *mut link_t,
}

pub struct list_t {
pub head: link_t,
}
}

// uspace/lib/posix/include/posix/time.h
pub const CLOCK_REALTIME: clockid_t = 0;
pub const CLOCK_MONOTONIC: clockid_t = 1;

// 'static inline' functions from libc
// common/include/adt/list.h
f! {
pub safe fn list_initialize(list: &mut list_t) -> () {
list.head.next = &mut list.head;
list.head.prev = &mut list.head;
}
}

extern "C" {
// common/include/str_error.h
pub fn str_error(err: errno_t) -> *const c_char;
pub fn str_error_name(err: errno_t) -> *const c_char;

// uspace/lib/posix/include/posix/pthread.h
pub fn pthread_key_create(
key: *mut pthread_key_t,
destructor: Option<unsafe extern "C" fn(*mut c_void)>,
) -> c_int;
pub fn pthread_getspecific(key: pthread_key_t) -> *mut c_void;
pub fn pthread_setspecific(key: pthread_key_t, value: *const c_void) -> c_int;
pub fn pthread_key_delete(key: pthread_key_t) -> c_int;

// uspace/lib/posix/include/posix/time.h
pub fn clock_getres(clock_id: clockid_t, res: *mut timespec) -> c_int;
pub fn clock_gettime(clock_id: clockid_t, tp: *mut timespec) -> c_int;
pub fn clock_settime(clock_id: clockid_t, tp: *const timespec) -> c_int;
pub fn clock_nanosleep(
clock_id: clockid_t,
flags: c_int,
rqtp: *const timespec,
rmtp: *mut timespec,
) -> c_int;

// uspace/lib/posix/include/posix/unistd.h
pub fn getpid() -> pid_t;
pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char;
pub fn chdir(buf: *const c_char) -> c_int;
pub static environ: *const *const c_char;
pub fn isatty(fd: c_int) -> c_int;
}
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ cfg_if! {
mod unix;
pub use crate::unix::*;

prelude!();
} else if #[cfg(target_os = "helenos")] {
mod primitives;
pub use primitives::*;

mod helenos;
pub use self::helenos::*;

prelude!();
} else if #[cfg(target_os = "hermit")] {
mod primitives;
Expand Down
43 changes: 43 additions & 0 deletions src/new/helenos/abi/errno.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//! HelenOS errno codes
//!
//! * Header file: <https://github.com/HelenOS/helenos/tree/master/abi/include/abi/errno.h>

use crate::errno_t;

pub const EOK: errno_t = 0;
pub const ENOENT: errno_t = 1;
pub const ENOMEM: errno_t = 2;
pub const ELIMIT: errno_t = 3;
pub const EREFUSED: errno_t = 4;
pub const EFORWARD: errno_t = 5;
pub const EPERM: errno_t = 6;
pub const EHANGUP: errno_t = 7;
pub const EPARTY: errno_t = 8;
pub const EEXIST: errno_t = 9;
pub const EBADMEM: errno_t = 10;
pub const ENOTSUP: errno_t = 11;
pub const EADDRNOTAVAIL: errno_t = 12;
pub const ETIMEOUT: errno_t = 13;
pub const EINVAL: errno_t = 14;
pub const EBUSY: errno_t = 15;
pub const EOVERFLOW: errno_t = 16;
pub const EINTR: errno_t = 17;
pub const EMFILE: errno_t = 18;
pub const ENAMETOOLONG: errno_t = 19;
pub const EISDIR: errno_t = 20;
pub const ENOTDIR: errno_t = 21;
pub const ENOSPC: errno_t = 22;
pub const ENOTEMPTY: errno_t = 23;
pub const EBADF: errno_t = 24;
pub const EDOM: errno_t = 25;
pub const ERANGE: errno_t = 26;
pub const EXDEV: errno_t = 27;
pub const EIO: errno_t = 28;
pub const EMLINK: errno_t = 29;
pub const ENXIO: errno_t = 30;
pub const ENOFS: errno_t = 31;
pub const EBADCHECKSUM: errno_t = 32;
pub const ESTALL: errno_t = 33;
pub const EEMPTY: errno_t = 34;
pub const ENAK: errno_t = 35;
pub const EAGAIN: errno_t = 36;
9 changes: 9 additions & 0 deletions src/new/helenos/bits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! HelenOS ABI bits
//!
//! * Headers: <https://github.com/HelenOS/helenos/tree/master/abi/include/_bits>

// `errno.h`
pub type errno_t = crate::c_int;

// `native.h`
pub type sysarg_t = crate::uintptr_t;
25 changes: 25 additions & 0 deletions src/new/helenos/dirent_mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! HelenOS directory entry API
//!
//! * Header file: <https://github.com/HelenOS/helenos/tree/master/uspace/lib/c/include/dirent.h>

// The module is named to avoid name collision with the dirent struct, which causes issues with
// wildcard imports in the parent module.

use crate::prelude::*;

s! {
pub struct dirent {
pub d_name: [c_char; 256],
}
}

extern_ty! {
pub type DIR;
}

extern "C" {
pub fn opendir(name: *const c_char) -> *mut DIR;
pub fn readdir(dir: *mut DIR) -> *mut dirent;
pub fn closedir(dir: *mut DIR) -> c_int;
pub fn rewinddir(dir: *mut DIR);
}
7 changes: 7 additions & 0 deletions src/new/helenos/errno.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! HelenOS errno handling
//!
//! * Header file: <https://github.com/HelenOS/helenos/tree/master/uspace/lib/c/include/errno.h>

extern "C" {
pub fn __errno() -> *mut crate::errno_t;
}
33 changes: 33 additions & 0 deletions src/new/helenos/fibril.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//! HelenOS fibrils API
//!
//! * Header file: <https://github.com/HelenOS/helenos/tree/master/uspace/lib/c/include/fibril.h>

use crate::errno_t;
use crate::prelude::*;
pub use crate::time::*;

pub type fid_t = *mut fibril_t;

s! {
pub struct fibril_owner_info_t {
pub owned_by: *mut fibril_t,
}
}

extern_ty! {
pub type fibril_t;
}

extern "C" {
pub fn fibril_create_generic(
func: unsafe extern "C" fn(*mut c_void) -> errno_t,
arg: *mut c_void,
stacksize: size_t,
) -> fid_t;
pub fn fibril_start(f: fid_t);
pub fn fibril_exit(retval: c_long) -> !;
pub fn fibril_detach(f: fid_t);
pub fn fibril_yield();
pub fn fibril_usleep(usec: usec_t);
pub fn fibril_get_id() -> fid_t;
}
64 changes: 64 additions & 0 deletions src/new/helenos/fibril_synch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//! HelenOS fibril synchronization primitives
//!
//! * Header file: <https://github.com/HelenOS/helenos/tree/master/uspace/lib/c/include/fibril_synch.h>

pub use crate::fibril::*;
use crate::prelude::*;
use crate::{
errno_t,
list_initialize,
list_t,
};

s! {
pub struct fibril_mutex_t {
pub oi: fibril_owner_info_t,
pub counter: c_int,
pub waiters: list_t,
}

pub struct fibril_rwlock_t {
pub oi: fibril_owner_info_t,
pub writers: c_uint,
pub readers: c_uint,
pub waiters: list_t,
}

pub struct fibril_condvar_t {
pub waiters: list_t,
}
}
Comment thread
tgross35 marked this conversation as resolved.

f! {
pub safe fn fibril_mutex_initialize(fm: &mut fibril_mutex_t) -> () {
fm.oi.owned_by = ptr::null_mut();
fm.counter = 1;
list_initialize(&mut fm.waiters);
}
}

extern "C" {
pub fn fibril_mutex_lock(mutex: *mut fibril_mutex_t);
pub fn fibril_mutex_unlock(mutex: *mut fibril_mutex_t);
pub fn fibril_mutex_trylock(mutex: *mut fibril_mutex_t) -> bool;
pub fn fibril_mutex_is_locked(mutex: *mut fibril_mutex_t) -> bool;

pub fn fibril_rwlock_initialize(rwlock: *mut fibril_rwlock_t);
pub fn fibril_rwlock_read_lock(rwlock: *mut fibril_rwlock_t);
pub fn fibril_rwlock_write_lock(rwlock: *mut fibril_rwlock_t);
pub fn fibril_rwlock_read_unlock(rwlock: *mut fibril_rwlock_t);
pub fn fibril_rwlock_write_unlock(rwlock: *mut fibril_rwlock_t);
pub fn fibril_rwlock_is_read_locked(rwlock: *mut fibril_rwlock_t) -> bool;
pub fn fibril_rwlock_is_write_locked(rwlock: *mut fibril_rwlock_t) -> bool;
pub fn fibril_rwlock_is_locked(rwlock: *mut fibril_rwlock_t) -> bool;

pub fn fibril_condvar_initialize(condvar: *mut fibril_condvar_t);
pub fn fibril_condvar_wait(condvar: *mut fibril_condvar_t, mutex: *mut fibril_mutex_t);
pub fn fibril_condvar_wait_timeout(
condvar: *mut fibril_condvar_t,
mutex: *mut fibril_mutex_t,
timeout: usec_t,
) -> errno_t;
pub fn fibril_condvar_signal(condvar: *mut fibril_condvar_t);
pub fn fibril_condvar_broadcast(condvar: *mut fibril_condvar_t);
}
26 changes: 26 additions & 0 deletions src/new/helenos/inet/addr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! HelenOS internet address types
//!
//! * Header file: <https://github.com/HelenOS/helenos/tree/master/uspace/lib/inet/include/inet/addr.h>

pub type addr32_t = u32;
pub type addr128_t = [u8; 16];

c_enum! {
#[repr(u32)]
pub enum ip_ver_t {
pub ip_any,
pub ip_v4,
pub ip_v6,
}
}
s_no_extra_traits! {
pub union __inet_addr_t_addr_union {
pub addr: addr32_t,
pub addr6: addr128_t,
}

pub struct inet_addr_t {
pub version: ip_ver_t,
pub addr: __inet_addr_t_addr_union,
}
}
Loading