Skip to content

Commit 0124440

Browse files
authored
Merge pull request #1748 from reitermarkus/xtensa-support
Add types for newlib on Xtensa.
2 parents d791c50 + a422e34 commit 0124440

File tree

5 files changed

+133
-9
lines changed

5 files changed

+133
-9
lines changed

src/unix/linux_like/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ s! {
5050
pub sin6_scope_id: u32,
5151
}
5252

53+
// The order of the `ai_addr` field in this struct is crucial
54+
// for converting between the Rust and C types.
5355
pub struct addrinfo {
5456
pub ai_flags: ::c_int,
5557
pub ai_family: ::c_int,

src/unix/newlib/aarch64/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub type clock_t = ::c_long;
12
pub type c_char = u8;
23
pub type wchar_t = u32;
34

@@ -29,5 +30,13 @@ s! {
2930
}
3031
}
3132

33+
pub const FIONBIO: ::c_ulong = 1;
34+
35+
pub const POLLIN: ::c_short = 0x1;
36+
pub const POLLPRI: ::c_short = 0x2;
3237
pub const POLLOUT: ::c_short = 0x4;
38+
pub const POLLERR: ::c_short = 0x8;
3339
pub const POLLHUP: ::c_short = 0x10;
40+
pub const POLLNVAL: ::c_short = 0x20;
41+
42+
pub const SOL_SOCKET: ::c_int = 65535;

src/unix/newlib/arm/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub type clock_t = ::c_long;
12
pub type c_char = u8;
23
pub type wchar_t = u32;
34

@@ -31,5 +32,13 @@ s! {
3132
}
3233
}
3334

34-
pub const POLLOUT: ::c_short = 0x10;
35+
pub const FIONBIO: ::c_ulong = 1;
36+
37+
pub const POLLIN: ::c_short = 0x1;
38+
pub const POLLPRI: ::c_short = 0x2;
3539
pub const POLLHUP: ::c_short = 0x4;
40+
pub const POLLERR: ::c_short = 0x8;
41+
pub const POLLOUT: ::c_short = 0x10;
42+
pub const POLLNVAL: ::c_short = 0x20;
43+
44+
pub const SOL_SOCKET: ::c_int = 65535;

src/unix/newlib/mod.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
pub type blkcnt_t = i32;
22
pub type blksize_t = i32;
3-
pub type clock_t = i32;
43
pub type clockid_t = ::c_ulong;
54
pub type dev_t = u32;
65
pub type fsblkcnt_t = u64;
@@ -25,14 +24,23 @@ pub type time_t = i32;
2524
pub type useconds_t = u32;
2625

2726
s! {
27+
// The order of the `ai_addr` field in this struct is crucial
28+
// for converting between the Rust and C types.
2829
pub struct addrinfo {
2930
pub ai_flags: ::c_int,
3031
pub ai_family: ::c_int,
3132
pub ai_socktype: ::c_int,
3233
pub ai_protocol: ::c_int,
3334
pub ai_addrlen: socklen_t,
35+
36+
#[cfg(target_arch = "xtensa")]
37+
pub ai_addr: *mut sockaddr,
38+
3439
pub ai_canonname: *mut ::c_char,
40+
41+
#[cfg(not(target_arch = "xtensa"))]
3542
pub ai_addr: *mut sockaddr,
43+
3644
pub ai_next: *mut addrinfo,
3745
}
3846

@@ -364,11 +372,6 @@ pub const O_NONBLOCK: ::c_int = 16384;
364372
pub const O_ACCMODE: ::c_int = 3;
365373
pub const O_CLOEXEC: ::c_int = 0x80000;
366374

367-
pub const POLLIN: ::c_short = 0x1;
368-
pub const POLLPRI: ::c_short = 0x2;
369-
pub const POLLERR: ::c_short = 0x8;
370-
pub const POLLNVAL: ::c_short = 0x20;
371-
372375
pub const RTLD_LAZY: ::c_int = 0x1;
373376

374377
pub const STDIN_FILENO: ::c_int = 0;
@@ -379,7 +382,6 @@ pub const SEEK_SET: ::c_int = 0;
379382
pub const SEEK_CUR: ::c_int = 1;
380383
pub const SEEK_END: ::c_int = 2;
381384

382-
pub const FIONBIO: ::c_ulong = 1;
383385
pub const FIOCLEX: ::c_ulong = 0x20006601;
384386
pub const FIONCLEX: ::c_ulong = 0x20006602;
385387

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

409-
pub const SOL_SOCKET: ::c_int = 65535;
410411
pub const SOL_TCP: ::c_int = 6;
411412

412413
pub const PF_UNSPEC: ::c_int = 0;
@@ -547,6 +548,9 @@ pub const EAI_MEMORY: ::c_int = -304;
547548
pub const EAI_NONAME: ::c_int = -305;
548549
pub const EAI_SOCKTYPE: ::c_int = -307;
549550

551+
pub const EXIT_SUCCESS: ::c_int = 0;
552+
pub const EXIT_FAILURE: ::c_int = 1;
553+
550554
pub const PRIO_PROCESS: ::c_int = 0;
551555
pub const PRIO_PGRP: ::c_int = 1;
552556
pub const PRIO_USER: ::c_int = 2;
@@ -702,6 +706,9 @@ cfg_if! {
702706
} else if #[cfg(target_arch = "aarch64")] {
703707
mod aarch64;
704708
pub use self::aarch64::*;
709+
} else if #[cfg(target_arch = "xtensa")] {
710+
mod xtensa;
711+
pub use self::xtensa::*;
705712
} else {
706713
// Only tested on ARM so far. Other platforms might have different
707714
// definitions for types and constants.

src/unix/newlib/xtensa/mod.rs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
pub type clock_t = ::c_ulong;
2+
pub type c_char = i8;
3+
pub type wchar_t = u32;
4+
5+
pub type c_long = i32;
6+
pub type c_ulong = u32;
7+
8+
s! {
9+
pub struct cmsghdr {
10+
pub cmsg_len: ::socklen_t,
11+
pub cmsg_level: ::c_int,
12+
pub cmsg_type: ::c_int,
13+
}
14+
15+
pub struct msghdr {
16+
pub msg_name: *mut ::c_void,
17+
pub msg_namelen: ::socklen_t,
18+
pub msg_iov: *mut ::iovec,
19+
pub msg_iovlen: ::c_int,
20+
pub msg_control: *mut ::c_void,
21+
pub msg_controllen: ::socklen_t,
22+
pub msg_flags: ::c_int,
23+
}
24+
25+
pub struct sockaddr_un {
26+
pub sun_family: ::sa_family_t,
27+
pub sun_path: [::c_char; 108],
28+
}
29+
30+
pub struct sockaddr {
31+
pub sa_len: u8,
32+
pub sa_family: ::sa_family_t,
33+
pub sa_data: [::c_char; 14],
34+
}
35+
36+
pub struct sockaddr_in6 {
37+
pub sin6_len: u8,
38+
pub sin6_family: ::sa_family_t,
39+
pub sin6_port: ::in_port_t,
40+
pub sin6_flowinfo: u32,
41+
pub sin6_addr: ::in6_addr,
42+
pub sin6_scope_id: u32,
43+
}
44+
45+
pub struct sockaddr_in {
46+
pub sin_len: u8,
47+
pub sin_family: ::sa_family_t,
48+
pub sin_port: ::in_port_t,
49+
pub sin_addr: ::in_addr,
50+
pub sin_zero: [::c_char; 8],
51+
}
52+
53+
pub struct sockaddr_storage {
54+
pub s2_len: u8,
55+
pub ss_family: ::sa_family_t,
56+
pub s2_data1: [::c_char; 2],
57+
pub s2_data2: [u32; 3],
58+
pub s2_data3: [u32; 3],
59+
}
60+
}
61+
62+
pub const AF_UNIX: ::c_int = 1;
63+
64+
pub const FIONBIO: ::c_ulong = 2147772030;
65+
66+
pub const POLLIN: ::c_short = 1 << 0;
67+
pub const POLLRDNORM: ::c_short = 1 << 1;
68+
pub const POLLRDBAND: ::c_short = 1 << 2;
69+
pub const POLLPRI: ::c_short = POLLRDBAND;
70+
pub const POLLOUT: ::c_short = 1 << 3;
71+
pub const POLLWRNORM: ::c_short = POLLOUT;
72+
pub const POLLWRBAND: ::c_short = 1 << 4;
73+
pub const POLLERR: ::c_short = 1 << 5;
74+
pub const POLLHUP: ::c_short = 1 << 6;
75+
76+
pub const SOL_SOCKET: ::c_int = 0xfff;
77+
78+
extern "C" {
79+
pub fn sendmsg(
80+
s: ::c_int,
81+
msg: *const ::msghdr,
82+
flags: ::c_int,
83+
) -> ::ssize_t;
84+
pub fn recvmsg(
85+
s: ::c_int,
86+
msg: *mut ::msghdr,
87+
flags: ::c_int,
88+
) -> ::ssize_t;
89+
90+
pub fn writev(s: ::c_int, iov: *const ::iovec, iovcnt: ::c_int)
91+
-> ::c_int;
92+
pub fn readv(
93+
fd: ::c_int,
94+
iov: *const ::iovec,
95+
iovcnt: ::c_int,
96+
) -> ::ssize_t;
97+
}

0 commit comments

Comments
 (0)