Skip to content

Commit

Permalink
Add support for NuttX
Browse files Browse the repository at this point in the history
Define the essential types that from NuttX

Signed-off-by: Huang Qi <[email protected]>
  • Loading branch information
no1wudi committed Aug 25, 2024
1 parent f9aa12d commit 9cfda97
Show file tree
Hide file tree
Showing 2 changed files with 206 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,11 @@ pub const ATF_PUBL: ::c_int = 0x08;
pub const ATF_USETRAILERS: ::c_int = 0x10;

cfg_if! {
if #[cfg(any(target_os = "l4re", target_os = "espidf"))] {
// required libraries for L4Re and the ESP-IDF framework are linked externally, ATM
if #[cfg(any(target_os = "l4re", target_os = "espidf", target_os = "nuttx"))] {
// required libraries are linked externally for these platforms:
// * L4Re
// * ESP-IDF
// * NuttX
} else if #[cfg(feature = "std")] {
// cargo build, don't pull in anything extra as the std dep
// already pulls in all libs.
Expand Down Expand Up @@ -1443,7 +1446,7 @@ cfg_if! {
}

cfg_if! {
if #[cfg(not(target_os = "aix"))] {
if #[cfg(not(target_os = "aix"))]{
extern "C" {
pub fn dladdr(addr: *const ::c_void, info: *mut Dl_info) -> ::c_int;
}
Expand Down Expand Up @@ -1612,6 +1615,9 @@ cfg_if! {
} else if #[cfg(target_os = "hurd")] {
mod hurd;
pub use self::hurd::*;
} else if #[cfg(target_os = "nuttx")] {
mod nuttx;
pub use self::nuttx::*;
} else {
// Unknown target_os
}
Expand Down
197 changes: 197 additions & 0 deletions src/unix/nuttx/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
pub type blkcnt_t = u64;
pub type blksize_t = i16;
pub type c_char = i8;
pub type c_long = isize;
pub type c_ulong = usize;
pub type cc_t = u8;
pub type clock_t = i64;
pub type dev_t = i32;
pub type fsblkcnt_t = u64;
pub type locale_t = *mut i8;
pub type mode_t = u32;
pub type nfds_t = u32;
pub type off_t = i64;
pub type pthread_condattr_t = u64;
pub type pthread_key_t = i32;
pub type pthread_mutexattr_t = u8;
pub type pthread_rwlockattr_t = i32;
pub type pthread_t = i32;
pub type rlim_t = i64;
pub type sa_family_t = u16;
pub type socklen_t = u32;
pub type speed_t = usize;
pub type suseconds_t = i32;
pub type tcflag_t = u32;
pub type time_t = i64;
pub type wchar_t = i32;

use c_void;
use timespec;

s! {
pub struct dq_entry_t {
flink: *mut dq_entry_t,
blink: *mut dq_entry_t,
}

pub struct dq_queue_t {
head: *mut dq_entry_t,
tail: *mut dq_entry_t,
}

pub struct stat {
st_dev: dev_t,
st_ino: u64,
st_mode: mode_t,
st_nlink: u64,
st_uid: u32,
st_gid: u32,
st_rdev: dev_t,
st_size: off_t,
st_atim: timespec,
st_mtim: timespec,
st_ctim: timespec,
st_blksize: blksize_t,
st_blocks: i64,
}

pub struct sockaddr {
pub sa_family: sa_family_t,
pub sa_data: [u8; 14],
}

pub struct passwd {
pw_name: *const c_char,
pw_uid: u32,
pw_gid: u32,
pw_gecos: *const c_char,
pw_dir: *const c_char,
pw_shell: *const c_char,
}

pub struct sem_t {
semcount: i16,
flags: u8,
waitlist: dq_queue_t,
holder: [usize; 5],
}

pub struct pthread_attr_t { __val: [u8; 0x40] }

pub struct pthread_mutex_t { __val: [u8; 0x40] }

pub struct pthread_cond_t {
sem: sem_t,
clockid: i32,
}

pub struct Dl_info {
dli_fname: *const c_char,
dli_fbase: *mut c_void,
dli_sname: *const c_char,
dli_saddr: *mut c_void,
}

pub struct lconv {
pub decimal_point: *const c_char,
pub thousands_sep: *const c_char,
pub grouping: *const c_char,
pub int_curr_symbol: *const c_char,
pub currency_symbol: *const c_char,
pub mon_decimal_point: *const c_char,
pub mon_thousands_sep: *const c_char,
pub mon_grouping: *const c_char,
pub positive_sign: *const c_char,
pub negative_sign: *const c_char,
pub int_frac_digits: i8,
pub frac_digits: i8,
pub p_cs_precedes: i8,
pub p_sep_by_space: i8,
pub n_cs_precedes: i8,
pub n_sep_by_space: i8,
pub p_sign_posn: i8,
pub n_sign_posn: i8,
pub int_n_cs_precedes: i8,
pub int_n_sep_by_space: i8,
pub int_n_sign_posn: i8,
pub int_p_cs_precedes: i8,
pub int_p_sep_by_space: i8,
pub int_p_sign_posn: i8,
}

pub struct tm {
pub tm_sec: i32,
pub tm_min: i32,
pub tm_hour: i32,
pub tm_mday: i32,
pub tm_mon: i32,
pub tm_year: i32,
pub tm_wday: i32,
pub tm_yday: i32,
pub tm_isdst: i32,
pub tm_gmtoff: isize,
pub tm_zone: *const i8,
}

pub struct addrinfo {
pub ai_flags: i32,
pub ai_family: i32,
pub ai_socktype: i32,
pub ai_protocol: i32,
pub ai_addrlen: socklen_t,
pub ai_addr: *mut sockaddr,
pub ai_canonname: *mut c_char,
pub ai_next: *mut addrinfo,
}

pub struct pthread_rwlock_t {
lock: pthread_mutex_t,
cv: pthread_cond_t,
num_readers: u32,
num_writers: u32,
write_in_progress: u8,
}

pub struct statvfs {
pub f_bsize: usize,
pub f_frsize: usize,
pub f_blocks: fsblkcnt_t,
pub f_bfree: fsblkcnt_t,
pub f_bavail: fsblkcnt_t,
pub f_files: fsblkcnt_t,
pub f_ffree: fsblkcnt_t,
pub f_favail: fsblkcnt_t,
pub f_fsid: usize,
pub f_flag: usize,
pub f_namemax: usize,
}

pub struct dirent {
pub d_type: u8,
pub d_name: [u8; 33],
}

pub struct fd_set {
pub __val: [u32; 8],
}

pub struct sigset_t {
pub __val: [u32; 2],
}

pub struct sigaction {
pub sa_handler: usize,
pub sa_mask: sigset_t,
pub sa_flags: i32,
pub sa_user: usize,
}

pub struct termios {
pub c_iflag: tcflag_t,
pub c_oflag: tcflag_t,
pub c_cflag: tcflag_t,
pub c_lflag: tcflag_t,
pub c_cc: [cc_t; 12],
pub c_speed: speed_t,
}
}

0 comments on commit 9cfda97

Please sign in to comment.