Skip to content
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

Fix ESP-IDF constants and structs #3920

Merged
merged 2 commits into from
Oct 13, 2024
Merged
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
16 changes: 8 additions & 8 deletions src/unix/newlib/espidf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ pub const MSG_EOR: ::c_int = 0x08;

pub const PTHREAD_STACK_MIN: ::size_t = 768;

pub const SIGABRT: ::c_int = 1;
pub const SIGFPE: ::c_int = 1;
pub const SIGILL: ::c_int = 1;
pub const SIGINT: ::c_int = 1;
pub const SIGSEGV: ::c_int = 1;
pub const SIGTERM: ::c_int = 1;
pub const SIGABRT: ::c_int = 6;
pub const SIGFPE: ::c_int = 8;
pub const SIGILL: ::c_int = 4;
pub const SIGINT: ::c_int = 2;
pub const SIGSEGV: ::c_int = 11;
pub const SIGTERM: ::c_int = 15;
pub const SIGHUP: ::c_int = 1;
pub const SIGQUIT: ::c_int = 1;
pub const NSIG: ::size_t = 2;
pub const SIGQUIT: ::c_int = 3;
pub const NSIG: ::size_t = 32;

extern "C" {
pub fn pthread_create(
Expand Down
3 changes: 3 additions & 0 deletions src/unix/newlib/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

s! {
pub struct sigset_t {
#[cfg(target_os = "horizon")]
__val: [::c_ulong; 16],
#[cfg(not(target_os = "horizon"))]
__val: u32,
}

pub struct stat {
Expand Down
157 changes: 134 additions & 23 deletions src/unix/newlib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ cfg_if! {
pub type socklen_t = u32;
pub type speed_t = u32;
pub type suseconds_t = i32;
pub type tcflag_t = ::c_uint;
cfg_if! {
if #[cfg(target_os = "espidf")] {
pub type tcflag_t = u16;
} else {
pub type tcflag_t = ::c_uint;
}
}
pub type useconds_t = u32;

cfg_if! {
Expand Down Expand Up @@ -197,6 +203,10 @@ s! {
pub c_lflag: ::tcflag_t,
pub c_line: ::cc_t,
pub c_cc: [::cc_t; ::NCCS],
#[cfg(target_os = "espidf")]
pub c_ispeed: u32,
#[cfg(target_os = "espidf")]
pub c_ospeed: u32,
}

pub struct sem_t { // Unverified
Expand Down Expand Up @@ -224,7 +234,24 @@ s! {
}

pub struct pthread_attr_t { // Unverified
__size: [u8; __SIZEOF_PTHREAD_ATTR_T]
#[cfg(not(target_os = "espidf"))]
__size: [u8; __SIZEOF_PTHREAD_ATTR_T],
#[cfg(target_os = "espidf")]
pub is_initialized: i32,
#[cfg(target_os = "espidf")]
pub stackaddr: *mut crate::c_void,
#[cfg(target_os = "espidf")]
pub stacksize: i32,
#[cfg(target_os = "espidf")]
pub contentionscope: i32,
#[cfg(target_os = "espidf")]
pub inheritsched: i32,
#[cfg(target_os = "espidf")]
pub schedpolicy: i32,
#[cfg(target_os = "espidf")]
pub schedparam: i32,
#[cfg(target_os = "espidf")]
pub detachstate: i32,
}

pub struct pthread_rwlockattr_t { // Unverified
Expand All @@ -241,7 +268,14 @@ pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
size: [__PTHREAD_INITIALIZER_BYTE; __SIZEOF_PTHREAD_RWLOCK_T],
};
pub const NCCS: usize = 32;

cfg_if! {
if #[cfg(target_os = "espidf")] {
pub const NCCS: usize = 11;
} else {
pub const NCCS: usize = 32;
}
}

cfg_if! {
if #[cfg(target_os = "espidf")] {
Expand Down Expand Up @@ -410,7 +444,13 @@ pub const O_SYNC: ::c_int = 8192;
pub const O_NONBLOCK: ::c_int = 16384;

pub const O_ACCMODE: ::c_int = 3;
pub const O_CLOEXEC: ::c_int = 0x80000;
cfg_if! {
if #[cfg(target_os = "espidf")] {
pub const O_CLOEXEC: ::c_int = 0x40000;
} else {
pub const O_CLOEXEC: ::c_int = 0x80000;
}
}

pub const RTLD_LAZY: ::c_int = 0x1;

Expand Down Expand Up @@ -452,7 +492,13 @@ pub const SOL_TCP: ::c_int = 6;

pub const PF_UNSPEC: ::c_int = 0;
pub const PF_INET: ::c_int = 2;
pub const PF_INET6: ::c_int = 23;
cfg_if! {
if #[cfg(target_os = "espidf")] {
pub const PF_INET6: ::c_int = 10;
} else {
pub const PF_INET6: ::c_int = 23;
}
}

pub const AF_UNSPEC: ::c_int = 0;
pub const AF_INET: ::c_int = 2;
Expand Down Expand Up @@ -537,6 +583,9 @@ cfg_if! {
if #[cfg(target_os = "vita")] {
pub const TCP_NODELAY: ::c_int = 1;
pub const TCP_MAXSEG: ::c_int = 2;
} else if #[cfg(target_os = "espidf")] {
pub const TCP_NODELAY: ::c_int = 1;
pub const TCP_MAXSEG: ::c_int = 8194;
} else {
pub const TCP_NODELAY: ::c_int = 8193;
pub const TCP_MAXSEG: ::c_int = 8194;
Expand All @@ -545,69 +594,131 @@ cfg_if! {

pub const TCP_NOPUSH: ::c_int = 4;
pub const TCP_NOOPT: ::c_int = 8;
pub const TCP_KEEPIDLE: ::c_int = 256;
pub const TCP_KEEPINTVL: ::c_int = 512;
pub const TCP_KEEPCNT: ::c_int = 1024;
cfg_if! {
if #[cfg(target_os = "espidf")] {
pub const TCP_KEEPIDLE: ::c_int = 3;
pub const TCP_KEEPINTVL: ::c_int = 4;
pub const TCP_KEEPCNT: ::c_int = 5;
} else {
pub const TCP_KEEPIDLE: ::c_int = 256;
pub const TCP_KEEPINTVL: ::c_int = 512;
pub const TCP_KEEPCNT: ::c_int = 1024;
}
}

cfg_if! {
if #[cfg(target_os = "horizon")] {
pub const IP_TOS: ::c_int = 7;
} else if #[cfg(target_os = "espidf")] {
pub const IP_TOS: ::c_int = 1;
} else {
pub const IP_TOS: ::c_int = 3;
}
}
cfg_if! {
if #[cfg(target_os = "vita")] {
pub const IP_TTL: ::c_int = 4;
} else if #[cfg(target_os = "espidf")] {
pub const IP_TTL: ::c_int = 2;
} else {
pub const IP_TTL: ::c_int = 8;
}
}
pub const IP_MULTICAST_IF: ::c_int = 9;
pub const IP_MULTICAST_TTL: ::c_int = 10;
pub const IP_MULTICAST_LOOP: ::c_int = 11;

cfg_if! {
if #[cfg(target_os = "espidf")] {
pub const IP_MULTICAST_IF: ::c_int = 6;
pub const IP_MULTICAST_TTL: ::c_int = 5;
pub const IP_MULTICAST_LOOP: ::c_int = 7;
} else {
pub const IP_MULTICAST_IF: ::c_int = 9;
pub const IP_MULTICAST_TTL: ::c_int = 10;
pub const IP_MULTICAST_LOOP: ::c_int = 11;
}
}

cfg_if! {
if #[cfg(target_os = "vita")] {
pub const IP_ADD_MEMBERSHIP: ::c_int = 12;
pub const IP_DROP_MEMBERSHIP: ::c_int = 13;
} else if #[cfg(target_os = "espidf")] {
pub const IP_ADD_MEMBERSHIP: ::c_int = 3;
pub const IP_DROP_MEMBERSHIP: ::c_int = 4;
} else {
pub const IP_ADD_MEMBERSHIP: ::c_int = 11;
pub const IP_DROP_MEMBERSHIP: ::c_int = 12;
}
}
pub const IPV6_UNICAST_HOPS: ::c_int = 4;
pub const IPV6_MULTICAST_IF: ::c_int = 9;
pub const IPV6_MULTICAST_HOPS: ::c_int = 10;
pub const IPV6_MULTICAST_LOOP: ::c_int = 11;
cfg_if! {
if #[cfg(target_os = "espidf")] {
pub const IPV6_MULTICAST_IF: ::c_int = 768;
pub const IPV6_MULTICAST_HOPS: ::c_int = 769;
pub const IPV6_MULTICAST_LOOP: ::c_int = 770;
} else {
pub const IPV6_MULTICAST_IF: ::c_int = 9;
pub const IPV6_MULTICAST_HOPS: ::c_int = 10;
pub const IPV6_MULTICAST_LOOP: ::c_int = 11;
}
}
pub const IPV6_V6ONLY: ::c_int = 27;
pub const IPV6_JOIN_GROUP: ::c_int = 12;
pub const IPV6_LEAVE_GROUP: ::c_int = 13;
pub const IPV6_ADD_MEMBERSHIP: ::c_int = 12;
pub const IPV6_DROP_MEMBERSHIP: ::c_int = 13;

pub const HOST_NOT_FOUND: ::c_int = 1;
pub const NO_DATA: ::c_int = 2;
cfg_if! {
if #[cfg(target_os = "espidf")] {
pub const HOST_NOT_FOUND: ::c_int = 210;
pub const NO_DATA: ::c_int = 211;
pub const NO_RECOVERY: ::c_int = 212;
pub const TRY_AGAIN: ::c_int = 213;

} else {
pub const HOST_NOT_FOUND: ::c_int = 1;
pub const NO_DATA: ::c_int = 2;
pub const NO_RECOVERY: ::c_int = 3;
pub const TRY_AGAIN: ::c_int = 4;
}
}
pub const NO_ADDRESS: ::c_int = 2;
pub const NO_RECOVERY: ::c_int = 3;
pub const TRY_AGAIN: ::c_int = 4;

pub const AI_PASSIVE: ::c_int = 1;
pub const AI_CANONNAME: ::c_int = 2;
pub const AI_NUMERICHOST: ::c_int = 4;
pub const AI_NUMERICSERV: ::c_int = 0;
pub const AI_ADDRCONFIG: ::c_int = 0;
cfg_if! {
if #[cfg(target_os = "espidf")] {
pub const AI_NUMERICSERV: ::c_int = 8;
pub const AI_ADDRCONFIG: ::c_int = 64;
} else {
pub const AI_NUMERICSERV: ::c_int = 0;
pub const AI_ADDRCONFIG: ::c_int = 0;
}
}

pub const NI_MAXHOST: ::c_int = 1025;
pub const NI_MAXSERV: ::c_int = 32;
pub const NI_NOFQDN: ::c_int = 1;
pub const NI_NUMERICHOST: ::c_int = 2;
pub const NI_NAMEREQD: ::c_int = 4;
pub const NI_NUMERICSERV: ::c_int = 0;
pub const NI_DGRAM: ::c_int = 0;
cfg_if! {
if #[cfg(target_os = "espidf")] {
pub const NI_NUMERICSERV: ::c_int = 8;
pub const NI_DGRAM: ::c_int = 16;
} else {
pub const NI_NUMERICSERV: ::c_int = 0;
pub const NI_DGRAM: ::c_int = 0;
}
}

cfg_if! {
// Defined in vita/mod.rs for "vita"
if #[cfg(not(target_os = "vita"))] {
if #[cfg(target_os = "espidf")] {
pub const EAI_FAMILY: ::c_int = 204;
pub const EAI_MEMORY: ::c_int = 203;
pub const EAI_NONAME: ::c_int = 200;
pub const EAI_SOCKTYPE: ::c_int = 10;
} else if #[cfg(not(target_os = "vita"))] {
pub const EAI_FAMILY: ::c_int = -303;
pub const EAI_MEMORY: ::c_int = -304;
pub const EAI_NONAME: ::c_int = -305;
Expand Down