From 2b50ba99f0b4474cd404018f91d425837b379852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Wed, 23 Sep 2026 09:59:27 +0200 Subject: [PATCH 1/3] nuttx: fix poll definition References: - pollfd: https://github.com/apache/nuttx/blob/fa1bbce9c9bba74217501a80f4ca585e024f663d/include/sys/poll.h#L119 - pollevent_t: https://github.com/apache/nuttx/blob/fa1bbce9c9bba74217501a80f4ca585e024f663d/include/sys/poll.h#L103 --- src/unix/mod.rs | 2 +- src/unix/nuttx/mod.rs | 34 +++++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 8d06955bfc00..d083f7668800 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -178,7 +178,7 @@ s2! { } #[exhaustive] // FIXME(exhaustive): review for 1.0 - #[cfg(not(target_os = "horizon"))] + #[cfg(not(any(target_os = "horizon", target_os = "nuttx")))] pub struct pollfd { pub fd: c_int, pub events: c_short, diff --git a/src/unix/nuttx/mod.rs b/src/unix/nuttx/mod.rs index 2380bba1ba40..780014a1e5f3 100644 --- a/src/unix/nuttx/mod.rs +++ b/src/unix/nuttx/mod.rs @@ -35,6 +35,7 @@ pub type suseconds_t = i32; pub type tcflag_t = u32; pub type clockid_t = c_int; pub type time_t = i64; +pub type pollevent_t = u32; cfg_if! { if #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] { @@ -274,6 +275,17 @@ s! { pub imr_interface: in_addr, pub imr_sourceaddr: in_addr, } + + pub struct pollfd { + pub fd: c_int, + pub events: pollevent_t, + pub revents: pollevent_t, + + // Used internally by NuttX + pub arg: *const c_void, + pub cb: *const c_void, + pub r#priv: *const c_void, + } } // Reserved two pointer size for reserved area for some structures. @@ -518,17 +530,17 @@ pub const S_IWOTH: u32 = 0x002; pub const S_IXOTH: u32 = 0x001; // sys/poll.h -pub const POLLIN: i16 = 0x01; -pub const POLLRDNORM: i16 = 0x01; -pub const POLLRDBAND: i16 = 0x01; -pub const POLLPRI: i16 = 0x02; -pub const POLLOUT: i16 = 0x04; -pub const POLLWRNORM: i16 = 0x04; -pub const POLLWRBAND: i16 = 0x04; -pub const POLLHUP: i16 = 0x10; -pub const POLLRDHUP: i16 = 0x10; -pub const POLLERR: i16 = 0x08; -pub const POLLNVAL: i16 = 0x20; +pub const POLLIN: pollevent_t = 0x01; +pub const POLLRDNORM: pollevent_t = 0x01; +pub const POLLRDBAND: pollevent_t = 0x01; +pub const POLLPRI: pollevent_t = 0x02; +pub const POLLOUT: pollevent_t = 0x04; +pub const POLLWRNORM: pollevent_t = 0x04; +pub const POLLWRBAND: pollevent_t = 0x04; +pub const POLLHUP: pollevent_t = 0x10; +pub const POLLRDHUP: pollevent_t = 0x10; +pub const POLLERR: pollevent_t = 0x08; +pub const POLLNVAL: pollevent_t = 0x20; // sys/socket.h // Supported Protocol Families From 9565d62e2ec30304d05a252f20ae53ee43fcb1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Wed, 23 Sep 2026 10:00:01 +0200 Subject: [PATCH 2/3] nuttx: add semaphore method definitions Reference: https://github.com/apache/nuttx/blob/fa1bbce9c9bba74217501a80f4ca585e024f663d/include/semaphore.h#L186 --- src/unix/nuttx/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/unix/nuttx/mod.rs b/src/unix/nuttx/mod.rs index 780014a1e5f3..774d2674515c 100644 --- a/src/unix/nuttx/mod.rs +++ b/src/unix/nuttx/mod.rs @@ -708,4 +708,8 @@ extern "C" { pub fn eventfd(count: c_uint, flags: c_int) -> c_int; // unistd.h pub fn pipe2(fds: *mut c_int, flags: c_int) -> c_int; + + pub fn sem_init(sem: *mut sem_t, pshared: c_int, value: c_uint) -> c_int; + pub fn sem_destroy(sem: *mut sem_t) -> c_int; + pub fn sem_getvalue(sem: *mut sem_t, sval: *mut c_int) -> c_int; } From e6fdcb6130f221df5b0561909f466ff958a50309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Wed, 23 Sep 2026 10:03:06 +0200 Subject: [PATCH 3/3] nuttx: fix maximum struct sizes for pthread_mutex_t, pthread_cond_t, pthread_rwlock_t and sem_t References: - https://github.com/apache/nuttx/blob/fa1bbce9c9bba74217501a80f4ca585e024f663d/include/pthread.h - https://github.com/apache/nuttx/blob/fa1bbce9c9bba74217501a80f4ca585e024f663d/include/nuttx/mutex.h - https://github.com/apache/nuttx/blob/fa1bbce9c9bba74217501a80f4ca585e024f663d/include/semaphore.h --- src/unix/nuttx/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/unix/nuttx/mod.rs b/src/unix/nuttx/mod.rs index 774d2674515c..8273e1739dfc 100644 --- a/src/unix/nuttx/mod.rs +++ b/src/unix/nuttx/mod.rs @@ -307,11 +307,11 @@ const __DEFAULT_RESERVED_SIZE__: usize = 2; const __SOCKADDR_STORAGE_SIZE__: usize = 36; const __PTHREAD_ATTR_SIZE__: usize = 5; -const __PTHREAD_MUTEX_SIZE__: usize = 9; -const __PTHREAD_COND_SIZE__: usize = 7; +const __PTHREAD_MUTEX_SIZE__: usize = 13; // Assumes CONFIG_LIBC_MUTEX_BACKTRACE=0 +const __PTHREAD_COND_SIZE__: usize = 12; const __PTHREAD_CONDATTR_SIZE__: usize = 5; -const __PTHREAD_RWLOCK_SIZE__: usize = 17; -const __SEM_SIZE__: usize = 6; +const __PTHREAD_RWLOCK_SIZE__: usize = 28; +const __SEM_SIZE__: usize = 10; const __NAME_MAX__: usize = 64; const __FDSET_SIZE__: usize = 10; const __SIGSET_SIZE__: usize = 8;