Skip to content
Open
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 @@ -22,6 +22,7 @@ targets = [
"aarch64-pc-windows-msvc",
"aarch64-unknown-freebsd",
"aarch64-unknown-fuchsia",
"aarch64-unknown-helenos",
"aarch64-unknown-hermit",
"aarch64-unknown-linux-gnu",
"aarch64-unknown-linux-musl",
Expand Down Expand Up @@ -53,6 +54,7 @@ targets = [
"i686-pc-windows-msvc",
"i686-unknown-freebsd",
"i686-unknown-haiku",
"i686-unknown-helenos",
"i686-unknown-linux-gnu",
"i686-unknown-linux-musl",
"i686-unknown-netbsd",
Expand All @@ -68,6 +70,7 @@ targets = [
"mipsel-unknown-linux-gnu",
"mipsel-unknown-linux-musl",
"nvptx64-nvidia-cuda",
"powerpc-unknown-helenos",
"powerpc-unknown-linux-gnu",
"powerpc-unknown-linux-gnuspe",
"powerpc-unknown-netbsd",
Expand All @@ -94,6 +97,7 @@ targets = [
"s390x-unknown-linux-gnu",
"s390x-unknown-linux-musl",
"sparc-unknown-linux-gnu",
"sparc64-unknown-helenos",
"sparc64-unknown-linux-gnu",
"sparc64-unknown-netbsd",
"sparcv9-sun-solaris",
Expand All @@ -116,6 +120,7 @@ targets = [
"x86_64-unknown-freebsd",
"x86_64-unknown-fuchsia",
"x86_64-unknown-haiku",
"x86_64-unknown-helenos",
"x86_64-unknown-hermit",
"x86_64-unknown-illumos",
"x86_64-unknown-l4re-uclibc",
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const CHECK_CFG_EXTRA: &[(&str, &[&str])] = &[
(
"target_os",
&[
"switch", "aix", "ohos", "hurd", "rtems", "visionos", "nuttx", "cygwin",
"switch", "aix", "ohos", "hurd", "rtems", "visionos", "nuttx", "cygwin", "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 @@ -137,6 +137,7 @@ def __post_init__(self):
# 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 @@ -151,6 +152,7 @@ def __post_init__(self):
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 @@ -164,6 +166,7 @@ def __post_init__(self):
Target("mipsel-unknown-linux-gnu", dist=False),
Target("mipsel-unknown-linux-musl", dist=False),
Target("nvptx64-nvidia-cuda", 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 @@ -185,6 +188,7 @@ def __post_init__(self):
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),
Expand All @@ -193,6 +197,7 @@ def __post_init__(self):
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
78 changes: 78 additions & 0 deletions src/helenos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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 fn list_initialize(list: *mut list_t) -> () {
let list = &mut *list;
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: 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 @@ -93,6 +93,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;
29 changes: 29 additions & 0 deletions src/new/helenos/dirent_mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! 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::{
c_char,
c_int,
};

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

extern_ty! {
pub enum 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);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, extra space

}
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;
}
36 changes: 36 additions & 0 deletions src/new/helenos/fibril.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//! HelenOS fibrils API
//!
//! * Header file: <https://github.com/HelenOS/helenos/tree/master/uspace/lib/c/include/fibril.h>

pub use crate::time::*;
use crate::{
c_void,
errno_t,
size_t,
};
Comment on lines +6 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional nit: use crate::prelude::* is a bit preferred to import the ints since most refactoring assumes they are in scope, and it brings a few other useful things.

(Applies to a few of these files)


pub type fid_t = *mut fibril_t;

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

extern_ty! {
pub enum fibril_t {}
}

extern "C" {
pub fn fibril_create_generic(
func: extern "C" fn(*mut c_void) -> errno_t,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Callbacks should take an unsafe extern "C" fn

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;
}
49 changes: 49 additions & 0 deletions src/new/helenos/fibril_synch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//! 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::{
c_int,
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_condvar_t {
pub waiters: list_t,
}
}
Comment on lines +13 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you also want rwlock for use in RwLock? Noblocking of course, I'm not sure whether you plan to use these APIs or the fallback in std anyway.


f! {
pub fn fibril_mutex_initialize(fm: *mut fibril_mutex_t) -> () {
let fm = &mut *fm;
Comment on lines +26 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe take a &mut fibril_mutex_t as the arg and make the function safe? Allows the caller to avoid a bit of unsafe if they have a known good reference.

fm.oi.owned_by = core::ptr::null_mut();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: If you use the prelude, core::ptr will be in scope

fm.counter = 1;
list_initialize(&mut fm.waiters);
}
Comment on lines +26 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/HelenOS/helenos/blob/144fafda7cb6d43dfda1c93b8e46b8d51635e0c2/uspace/lib/c/include/fibril_synch.h#L55-L66 seems to effectively return a definition. Any reason not to do similar here and directly return a fibril_mutex_t, rather than using a pointer?

You may want to uppercase to match the definitions too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I now see it has a self-referential list. I guess this is about as good as it gets, unfortunately.

}

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_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 {
ip_any,
ip_v4,
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
Loading