-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add HelenOS support #4355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add HelenOS support #4355
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| } |
| 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; |
| 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; |
| 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); | ||
|
|
||
| } | ||
| 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; | ||
| } |
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional nit: (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, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Callbacks should take an |
||
| 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; | ||
| } | ||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you also want rwlock for use in |
||
|
|
||
| f! { | ||
| pub fn fibril_mutex_initialize(fm: *mut fibril_mutex_t) -> () { | ||
| let fm = &mut *fm; | ||
|
Comment on lines
+26
to
+27
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe take a |
||
| fm.oi.owned_by = core::ptr::null_mut(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: If you use the prelude, |
||
| fm.counter = 1; | ||
| list_initialize(&mut fm.waiters); | ||
| } | ||
|
Comment on lines
+26
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 You may want to uppercase to match the definitions too.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
| 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, | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, extra space