Skip to content

Nuttx work with tokio net features#5258

Open
wllenyj wants to merge 9 commits into
rust-lang:mainfrom
wllenyj:nuttx
Open

Nuttx work with tokio net features#5258
wllenyj wants to merge 9 commits into
rust-lang:mainfrom
wllenyj:nuttx

Conversation

@wllenyj

@wllenyj wllenyj commented Jul 7, 2026

Copy link
Copy Markdown

Description

Currently the nuttx rust app is not compiled, when using the tokio net feature.
Therefore, added support Nuttx definitions.

Sources

Added strerror_r function for errno crate. And errno crate 's pr lambda-fairy/rust-errno#129.
Added socket interrelated structs, functions and constants.
Added netinet interrelated structs and constants.
Added eventfd definitions, and poll/fcntl/tcp/pipe2 definitions.

Other interrelated pr rust-lang/socket2#663, tokio-rs/mio#1966, tokio-rs/tokio#8259.

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI

@wllenyj wllenyj changed the title Nuttx Nuttx work with tokio net features Jul 7, 2026

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you please add permalinks to the nuttx sources in your commits messages?

Cc nuttx maintainer @no1wudi to take a look

View changes since this review

@rustbot

rustbot commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@wllenyj wllenyj force-pushed the nuttx branch 2 times, most recently from 40fdd3a to d9f7696 Compare July 9, 2026 02:53
@wllenyj

wllenyj commented Jul 9, 2026

Copy link
Copy Markdown
Author

Could you please add permalinks to the nuttx sources in your commits messages?

@tgross35 Added comments about version and repos.

///! Definitions for Apache NuttX RTOS.
///!
///! Following definitions are based on NuttX 13.0.0.
///! See https://github.com/apache/nuttx/tree/releases/13.0 for more details.
///! Comments use relative paths specific to the source code repository.

@tgross35

tgross35 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

That's not what I meant - please update commit messages adding permalinks to the headers for each added/changed API. The PR template asks for this so maintainers don't need to dig finding the API to check against.

fixes missing `strerror_r` for compiling errno crate.
The original definition at
https://github.com/apache/nuttx/blob/releases/13.0/include/string.h#L69

Signed-off-by: wanglei <wllenyj@gmail.com>
@wllenyj

wllenyj commented Jul 9, 2026

Copy link
Copy Markdown
Author

That's not what I meant - please update commit messages adding permalinks to the headers for each added/changed API. The PR template asks for this so maintainers don't need to dig finding the API to check against.

Thanks, Done

@tgross35 tgross35 added the stable-nominated This PR should be considered for cherry-pick to libc's stable release branch label Jul 9, 2026

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Noticed a few small things but otherwise looks reasonable to me, though I'll wait for the maintainer to ack.

Thank you for splitting this up nicely!

View changes since this review

Comment thread src/unix/nuttx/mod.rs Outdated
Comment on lines +510 to +511
pub const SOCK_CLOEXEC: i32 = 0x02000000;
pub const SOCK_NONBLOCK: i32 = 0x00004000;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"nuttx: add socket structs, functions and constants" these are not correct, the C versions are octal. Use the 0o prefix here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Oh, you're right, Thanks for your thorough review, it was my oversight...

Fixed.

Comment thread src/unix/nuttx/mod.rs Outdated
Comment on lines +605 to +623
/// SOL_IP protocol-level socket options.
pub const IP_MULTICAST_IF: i32 = 16 + 1;
pub const IP_MULTICAST_TTL: i32 = 16 + 2;
pub const IP_MULTICAST_LOOP: i32 = 16 + 3;
pub const IP_ADD_MEMBERSHIP: i32 = 16 + 4;
pub const IP_DROP_MEMBERSHIP: i32 = 16 + 5;
pub const IP_ADD_SOURCE_MEMBERSHIP: i32 = 16 + 8;
pub const IP_DROP_SOURCE_MEMBERSHIP: i32 = 16 + 9;
pub const IP_TOS: i32 = 16 + 13;
pub const IP_TTL: i32 = 16 + 14;
/// SOL_IPV6 protocol-level socket options.
pub const IPV6_JOIN_GROUP: i32 = 16 + 1;
pub const IPV6_LEAVE_GROUP: i32 = 16 + 2;
pub const IPV6_MULTICAST_HOPS: i32 = 16 + 3;
pub const IPV6_MULTICAST_IF: i32 = 16 + 4;
pub const IPV6_MULTICAST_LOOP: i32 = 16 + 5;
pub const IPV6_UNICAST_HOPS: i32 = 16 + 6;
pub const IPV6_V6ONLY: i32 = 16 + 7;
pub const IPV6_RECVHOPLIMIT: i32 = 16 + 11;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"nuttx: add netinet structs and constants": just add const __SO_PROTOCOL: i32 = 16 and use that rather than hardcoding its value.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

Comment thread src/unix/nuttx/mod.rs Outdated
pub const TCP_KEEPIDLE: i32 = 0x11;
pub const TCP_KEEPINTVL: i32 = 0x12;
pub const TCP_KEEPCNT: i32 = 0x13;
pub const TCP_MAXSEG: i32 = 0x14;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"nuttx: add TCP_MAXSEG definitions": Ditto regarding __SO_PROTOCOL

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

Comment thread src/unix/nuttx/mod.rs Outdated
Comment on lines 460 to 468
/// fcntl() commands
pub const FIOCLEX: i32 = 0x30b;
pub const F_SETFL: i32 = 0x9;
pub const F_DUPFD_CLOEXEC: i32 = 0x12;
pub const F_GETFD: i32 = 0x1;
pub const F_GETFL: i32 = 0x2;
pub const F_SETFD: i32 = 8;
pub const F_SETFL: i32 = 9;
/// open flag settings for open() (and related APIs)
pub const O_RDONLY: i32 = 0x1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall comment: in a lot of places you use doc comments that seem like they should be section headers. Change them to regular comments instead, currently they're user-facing documentation for only the first item in the list.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

wllenyj added 8 commits July 9, 2026 17:09
The original definition at
https://github.com/apache/nuttx/blob/releases/13.0/include/sys/eventfd.h

Signed-off-by: wanglei <wllenyj@gmail.com>
The original definition at
https://github.com/apache/nuttx/blob/releases/13.0/include/fcntl.h

Signed-off-by: wanglei <wllenyj@gmail.com>
The original definition at
https://github.com/apache/nuttx/blob/releases/13.0/include/sys/poll.h

Signed-off-by: wanglei <wllenyj@gmail.com>
It's used by `mio` crate.
The original definition at
https://github.com/apache/nuttx/blob/releases/13.0/include/unistd.h

Signed-off-by: wanglei <wllenyj@gmail.com>
It's used by `socket2` crate in `tcp_mss` and `set_tcp_mss`.
The original definition at
https://github.com/apache/nuttx/blob/releases/13.0/include/netinet/tcp.h#L59

Signed-off-by: wanglei <wllenyj@gmail.com>
Signed-off-by: wanglei <wllenyj@gmail.com>

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Latest changes LGTM, but will hold off on maintainer ack

View changes since this review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-maintainer S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants