Skip to content

Add types for newlib on Xtensa. #1748

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

Merged
merged 2 commits into from
May 25, 2020
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
2 changes: 2 additions & 0 deletions src/unix/linux_like/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ s! {
pub sin6_scope_id: u32,
}

// The order of the `ai_addr` field in this struct is crucial
// for converting between the Rust and C types.
pub struct addrinfo {
pub ai_flags: ::c_int,
pub ai_family: ::c_int,
Expand Down
9 changes: 9 additions & 0 deletions src/unix/newlib/aarch64/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub type clock_t = ::c_long;
pub type c_char = u8;
pub type wchar_t = u32;

Expand Down Expand Up @@ -29,5 +30,13 @@ s! {
}
}

pub const FIONBIO: ::c_ulong = 1;

pub const POLLIN: ::c_short = 0x1;
pub const POLLPRI: ::c_short = 0x2;
pub const POLLOUT: ::c_short = 0x4;
pub const POLLERR: ::c_short = 0x8;
pub const POLLHUP: ::c_short = 0x10;
pub const POLLNVAL: ::c_short = 0x20;

pub const SOL_SOCKET: ::c_int = 65535;
11 changes: 10 additions & 1 deletion src/unix/newlib/arm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub type clock_t = ::c_long;
pub type c_char = u8;
pub type wchar_t = u32;

Expand Down Expand Up @@ -31,5 +32,13 @@ s! {
}
}

pub const POLLOUT: ::c_short = 0x10;
pub const FIONBIO: ::c_ulong = 1;

pub const POLLIN: ::c_short = 0x1;
pub const POLLPRI: ::c_short = 0x2;
pub const POLLHUP: ::c_short = 0x4;
pub const POLLERR: ::c_short = 0x8;
pub const POLLOUT: ::c_short = 0x10;
pub const POLLNVAL: ::c_short = 0x20;

pub const SOL_SOCKET: ::c_int = 65535;
23 changes: 15 additions & 8 deletions src/unix/newlib/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub type blkcnt_t = i32;
pub type blksize_t = i32;
pub type clock_t = i32;
pub type clockid_t = ::c_ulong;
pub type dev_t = u32;
pub type fsblkcnt_t = u64;
Expand All @@ -25,14 +24,23 @@ pub type time_t = i32;
pub type useconds_t = u32;

s! {
// The order of the `ai_addr` field in this struct is crucial
// for converting between the Rust and C types.
pub struct addrinfo {
pub ai_flags: ::c_int,
pub ai_family: ::c_int,
pub ai_socktype: ::c_int,
pub ai_protocol: ::c_int,
pub ai_addrlen: socklen_t,

#[cfg(target_arch = "xtensa")]
pub ai_addr: *mut sockaddr,

pub ai_canonname: *mut ::c_char,

#[cfg(not(target_arch = "xtensa"))]
pub ai_addr: *mut sockaddr,

pub ai_next: *mut addrinfo,
}

Expand Down Expand Up @@ -364,11 +372,6 @@ pub const O_NONBLOCK: ::c_int = 16384;
pub const O_ACCMODE: ::c_int = 3;
pub const O_CLOEXEC: ::c_int = 0x80000;

pub const POLLIN: ::c_short = 0x1;
pub const POLLPRI: ::c_short = 0x2;
pub const POLLERR: ::c_short = 0x8;
pub const POLLNVAL: ::c_short = 0x20;

pub const RTLD_LAZY: ::c_int = 0x1;

pub const STDIN_FILENO: ::c_int = 0;
Expand All @@ -379,7 +382,6 @@ pub const SEEK_SET: ::c_int = 0;
pub const SEEK_CUR: ::c_int = 1;
pub const SEEK_END: ::c_int = 2;

pub const FIONBIO: ::c_ulong = 1;
pub const FIOCLEX: ::c_ulong = 0x20006601;
pub const FIONCLEX: ::c_ulong = 0x20006602;

Expand All @@ -406,7 +408,6 @@ pub const S_IROTH: ::mode_t = 4;
pub const S_IWOTH: ::mode_t = 2;
pub const S_IXOTH: ::mode_t = 1;

pub const SOL_SOCKET: ::c_int = 65535;
pub const SOL_TCP: ::c_int = 6;

pub const PF_UNSPEC: ::c_int = 0;
Expand Down Expand Up @@ -547,6 +548,9 @@ pub const EAI_MEMORY: ::c_int = -304;
pub const EAI_NONAME: ::c_int = -305;
pub const EAI_SOCKTYPE: ::c_int = -307;

pub const EXIT_SUCCESS: ::c_int = 0;
pub const EXIT_FAILURE: ::c_int = 1;

pub const PRIO_PROCESS: ::c_int = 0;
pub const PRIO_PGRP: ::c_int = 1;
pub const PRIO_USER: ::c_int = 2;
Expand Down Expand Up @@ -702,6 +706,9 @@ cfg_if! {
} else if #[cfg(target_arch = "aarch64")] {
mod aarch64;
pub use self::aarch64::*;
} else if #[cfg(target_arch = "xtensa")] {
mod xtensa;
pub use self::xtensa::*;
} else {
// Only tested on ARM so far. Other platforms might have different
// definitions for types and constants.
Expand Down
97 changes: 97 additions & 0 deletions src/unix/newlib/xtensa/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
pub type clock_t = ::c_ulong;
pub type c_char = i8;
pub type wchar_t = u32;

pub type c_long = i32;
pub type c_ulong = u32;

s! {
pub struct cmsghdr {
pub cmsg_len: ::socklen_t,
pub cmsg_level: ::c_int,
pub cmsg_type: ::c_int,
}

pub struct msghdr {
pub msg_name: *mut ::c_void,
pub msg_namelen: ::socklen_t,
pub msg_iov: *mut ::iovec,
pub msg_iovlen: ::c_int,
pub msg_control: *mut ::c_void,
pub msg_controllen: ::socklen_t,
pub msg_flags: ::c_int,
}

pub struct sockaddr_un {
pub sun_family: ::sa_family_t,
pub sun_path: [::c_char; 108],
}

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

pub struct sockaddr_in6 {
pub sin6_len: u8,
pub sin6_family: ::sa_family_t,
pub sin6_port: ::in_port_t,
pub sin6_flowinfo: u32,
pub sin6_addr: ::in6_addr,
pub sin6_scope_id: u32,
}

pub struct sockaddr_in {
pub sin_len: u8,
pub sin_family: ::sa_family_t,
pub sin_port: ::in_port_t,
pub sin_addr: ::in_addr,
pub sin_zero: [::c_char; 8],
}

pub struct sockaddr_storage {
pub s2_len: u8,
pub ss_family: ::sa_family_t,
pub s2_data1: [::c_char; 2],
pub s2_data2: [u32; 3],
pub s2_data3: [u32; 3],
}
}

pub const AF_UNIX: ::c_int = 1;

pub const FIONBIO: ::c_ulong = 2147772030;

pub const POLLIN: ::c_short = 1 << 0;
pub const POLLRDNORM: ::c_short = 1 << 1;
pub const POLLRDBAND: ::c_short = 1 << 2;
pub const POLLPRI: ::c_short = POLLRDBAND;
pub const POLLOUT: ::c_short = 1 << 3;
pub const POLLWRNORM: ::c_short = POLLOUT;
pub const POLLWRBAND: ::c_short = 1 << 4;
pub const POLLERR: ::c_short = 1 << 5;
pub const POLLHUP: ::c_short = 1 << 6;

pub const SOL_SOCKET: ::c_int = 0xfff;

extern "C" {
pub fn sendmsg(
s: ::c_int,
msg: *const ::msghdr,
flags: ::c_int,
) -> ::ssize_t;
pub fn recvmsg(
s: ::c_int,
msg: *mut ::msghdr,
flags: ::c_int,
) -> ::ssize_t;

pub fn writev(s: ::c_int, iov: *const ::iovec, iovcnt: ::c_int)
-> ::c_int;
pub fn readv(
fd: ::c_int,
iov: *const ::iovec,
iovcnt: ::c_int,
) -> ::ssize_t;
}