Skip to content

Commit 0a092a8

Browse files
committed
auto merge of #14455 : crabtw/rust/mips, r=alexcrichton
Because IPv4 address conversion doesn't consider big-endian target, I add functions to handle that. These function names may need to be changed, but I can't come up with a good one.
2 parents a183829 + abc2a92 commit 0a092a8

File tree

5 files changed

+113
-22
lines changed

5 files changed

+113
-22
lines changed

src/libgreen/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ fn initialize_call_frame(regs: &mut Registers, fptr: InitFn, arg: uint,
270270
type Registers = [uint, ..32];
271271

272272
#[cfg(target_arch = "mips")]
273-
fn new_regs() -> Box<Registers> { box [0, .. 32] }
273+
fn new_regs() -> Box<Registers> { box {[0, .. 32]} }
274274

275275
#[cfg(target_arch = "mips")]
276276
fn initialize_call_frame(regs: &mut Registers, fptr: InitFn, arg: uint,

src/liblibc/lib.rs

+46
Original file line numberDiff line numberDiff line change
@@ -2476,6 +2476,9 @@ pub mod consts {
24762476
}
24772477
pub mod posix08 {
24782478
}
2479+
#[cfg(target_arch = "arm")]
2480+
#[cfg(target_arch = "x86")]
2481+
#[cfg(target_arch = "x86_64")]
24792482
pub mod bsd44 {
24802483
use types::os::arch::c95::c_int;
24812484

@@ -2518,6 +2521,49 @@ pub mod consts {
25182521
pub static SHUT_WR: c_int = 1;
25192522
pub static SHUT_RDWR: c_int = 2;
25202523
}
2524+
#[cfg(target_arch = "mips")]
2525+
pub mod bsd44 {
2526+
use types::os::arch::c95::c_int;
2527+
2528+
pub static MADV_NORMAL : c_int = 0;
2529+
pub static MADV_RANDOM : c_int = 1;
2530+
pub static MADV_SEQUENTIAL : c_int = 2;
2531+
pub static MADV_WILLNEED : c_int = 3;
2532+
pub static MADV_DONTNEED : c_int = 4;
2533+
pub static MADV_REMOVE : c_int = 9;
2534+
pub static MADV_DONTFORK : c_int = 10;
2535+
pub static MADV_DOFORK : c_int = 11;
2536+
pub static MADV_MERGEABLE : c_int = 12;
2537+
pub static MADV_UNMERGEABLE : c_int = 13;
2538+
pub static MADV_HWPOISON : c_int = 100;
2539+
2540+
pub static AF_UNIX: c_int = 1;
2541+
pub static AF_INET: c_int = 2;
2542+
pub static AF_INET6: c_int = 10;
2543+
pub static SOCK_STREAM: c_int = 2;
2544+
pub static SOCK_DGRAM: c_int = 1;
2545+
pub static IPPROTO_TCP: c_int = 6;
2546+
pub static IPPROTO_IP: c_int = 0;
2547+
pub static IPPROTO_IPV6: c_int = 41;
2548+
pub static IP_MULTICAST_TTL: c_int = 33;
2549+
pub static IP_MULTICAST_LOOP: c_int = 34;
2550+
pub static IP_TTL: c_int = 2;
2551+
pub static IP_ADD_MEMBERSHIP: c_int = 35;
2552+
pub static IP_DROP_MEMBERSHIP: c_int = 36;
2553+
pub static IPV6_ADD_MEMBERSHIP: c_int = 20;
2554+
pub static IPV6_DROP_MEMBERSHIP: c_int = 21;
2555+
2556+
pub static TCP_NODELAY: c_int = 1;
2557+
pub static SOL_SOCKET: c_int = 65535;
2558+
pub static SO_KEEPALIVE: c_int = 8;
2559+
pub static SO_BROADCAST: c_int = 32;
2560+
pub static SO_REUSEADDR: c_int = 4;
2561+
pub static SO_ERROR: c_int = 4103;
2562+
2563+
pub static SHUT_RD: c_int = 0;
2564+
pub static SHUT_WR: c_int = 1;
2565+
pub static SHUT_RDWR: c_int = 2;
2566+
}
25212567
#[cfg(target_arch = "x86")]
25222568
#[cfg(target_arch = "x86_64")]
25232569
#[cfg(target_arch = "arm")]

src/libnative/io/c_unix.rs

+46-3
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,20 @@ use libc;
2222
#[cfg(target_os = "macos")]
2323
#[cfg(target_os = "freebsd")]
2424
pub static FIONBIO: libc::c_ulong = 0x8004667e;
25-
#[cfg(target_os = "linux")]
25+
#[cfg(target_os = "linux", not(target_arch = "mips"))]
2626
#[cfg(target_os = "android")]
2727
pub static FIONBIO: libc::c_ulong = 0x5421;
28+
#[cfg(target_os = "linux", target_arch = "mips")]
29+
pub static FIONBIO: libc::c_ulong = 0x667e;
30+
2831
#[cfg(target_os = "macos")]
2932
#[cfg(target_os = "freebsd")]
3033
pub static FIOCLEX: libc::c_ulong = 0x20006601;
31-
#[cfg(target_os = "linux")]
34+
#[cfg(target_os = "linux", not(target_arch = "mips"))]
3235
#[cfg(target_os = "android")]
3336
pub static FIOCLEX: libc::c_ulong = 0x5451;
37+
#[cfg(target_os = "linux", target_arch = "mips")]
38+
pub static FIOCLEX: libc::c_ulong = 0x6601;
3439

3540
#[cfg(target_os = "macos")]
3641
#[cfg(target_os = "freebsd")]
@@ -100,7 +105,7 @@ mod select {
100105
}
101106
}
102107

103-
#[cfg(target_os = "linux")]
108+
#[cfg(target_os = "linux", not(target_arch = "mips"))]
104109
#[cfg(target_os = "android")]
105110
mod signal {
106111
use libc;
@@ -143,6 +148,44 @@ mod signal {
143148
}
144149
}
145150

151+
#[cfg(target_os = "linux", target_arch = "mips")]
152+
mod signal {
153+
use libc;
154+
155+
pub static SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
156+
pub static SA_NOCLDWAIT: libc::c_ulong = 0x00010000;
157+
pub static SA_NODEFER: libc::c_ulong = 0x40000000;
158+
pub static SA_ONSTACK: libc::c_ulong = 0x08000000;
159+
pub static SA_RESETHAND: libc::c_ulong = 0x80000000;
160+
pub static SA_RESTART: libc::c_ulong = 0x10000000;
161+
pub static SA_SIGINFO: libc::c_ulong = 0x00000008;
162+
pub static SIGCHLD: libc::c_int = 18;
163+
164+
// This definition is not as accurate as it could be, {pid, uid, status} is
165+
// actually a giant union. Currently we're only interested in these fields,
166+
// however.
167+
pub struct siginfo {
168+
si_signo: libc::c_int,
169+
si_code: libc::c_int,
170+
si_errno: libc::c_int,
171+
pub pid: libc::pid_t,
172+
pub uid: libc::uid_t,
173+
pub status: libc::c_int,
174+
}
175+
176+
pub struct sigaction {
177+
pub sa_flags: libc::c_uint,
178+
pub sa_handler: extern fn(libc::c_int),
179+
pub sa_mask: sigset_t,
180+
sa_restorer: *mut libc::c_void,
181+
sa_resv: [libc::c_int, ..1],
182+
}
183+
184+
pub struct sigset_t {
185+
__val: [libc::c_ulong, ..32],
186+
}
187+
}
188+
146189
#[cfg(target_os = "macos")]
147190
#[cfg(target_os = "freebsd")]
148191
mod signal {

src/libnative/io/net.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ enum InAddr {
4242
fn ip_to_inaddr(ip: ip::IpAddr) -> InAddr {
4343
match ip {
4444
ip::Ipv4Addr(a, b, c, d) => {
45+
let ip = (a as u32 << 24) |
46+
(b as u32 << 16) |
47+
(c as u32 << 8) |
48+
(d as u32 << 0);
4549
InAddr(libc::in_addr {
46-
s_addr: (d as u32 << 24) |
47-
(c as u32 << 16) |
48-
(b as u32 << 8) |
49-
(a as u32 << 0)
50+
s_addr: mem::from_be32(ip)
5051
})
5152
}
5253
ip::Ipv6Addr(a, b, c, d, e, f, g, h) => {
@@ -174,11 +175,11 @@ pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage,
174175
let storage: &libc::sockaddr_in = unsafe {
175176
mem::transmute(storage)
176177
};
177-
let addr = storage.sin_addr.s_addr as u32;
178-
let a = (addr >> 0) as u8;
179-
let b = (addr >> 8) as u8;
180-
let c = (addr >> 16) as u8;
181-
let d = (addr >> 24) as u8;
178+
let ip = mem::to_be32(storage.sin_addr.s_addr as u32);
179+
let a = (ip >> 24) as u8;
180+
let b = (ip >> 16) as u8;
181+
let c = (ip >> 8) as u8;
182+
let d = (ip >> 0) as u8;
182183
Ok(ip::SocketAddr {
183184
ip: ip::Ipv4Addr(a, b, c, d),
184185
port: ntohs(storage.sin_port),

src/librustuv/net.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage,
4343
let storage: &libc::sockaddr_in = unsafe {
4444
mem::transmute(storage)
4545
};
46-
let addr = storage.sin_addr.s_addr as u32;
47-
let a = (addr >> 0) as u8;
48-
let b = (addr >> 8) as u8;
49-
let c = (addr >> 16) as u8;
50-
let d = (addr >> 24) as u8;
46+
let ip = mem::to_be32(storage.sin_addr.s_addr as u32);
47+
let a = (ip >> 24) as u8;
48+
let b = (ip >> 16) as u8;
49+
let c = (ip >> 8) as u8;
50+
let d = (ip >> 0) as u8;
5151
ip::SocketAddr {
5252
ip: ip::Ipv4Addr(a, b, c, d),
5353
port: ntohs(storage.sin_port),
@@ -82,15 +82,16 @@ fn addr_to_sockaddr(addr: ip::SocketAddr) -> (libc::sockaddr_storage, uint) {
8282
let mut storage: libc::sockaddr_storage = mem::zeroed();
8383
let len = match addr.ip {
8484
ip::Ipv4Addr(a, b, c, d) => {
85+
let ip = (a as u32 << 24) |
86+
(b as u32 << 16) |
87+
(c as u32 << 8) |
88+
(d as u32 << 0);
8589
let storage: &mut libc::sockaddr_in =
8690
mem::transmute(&mut storage);
8791
(*storage).sin_family = libc::AF_INET as libc::sa_family_t;
8892
(*storage).sin_port = htons(addr.port);
8993
(*storage).sin_addr = libc::in_addr {
90-
s_addr: (d as u32 << 24) |
91-
(c as u32 << 16) |
92-
(b as u32 << 8) |
93-
(a as u32 << 0)
94+
s_addr: mem::from_be32(ip)
9495
};
9596
mem::size_of::<libc::sockaddr_in>()
9697
}

0 commit comments

Comments
 (0)