Skip to content

Commit 8304e06

Browse files
Correct solaris libc definitions:
* pthread_t is defined as uint_t, so must be c_uint, not uintptr_t, just as pthread_key_t is already defined * fd_set is defined as long, so must be i32/i64 based on target_pointer_width; this also fixes an indirect endianness issue encountered on sparc * FD_SETSIZE should be defined as 65536 when target_pointer_width = 64 Fixes #515
1 parent 6813109 commit 8304e06

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/unix/solaris/mod.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use dox::mem;
2+
13
pub type c_char = i8;
24
pub type c_long = i64;
35
pub type c_ulong = u64;
@@ -27,7 +29,7 @@ pub type off_t = i64;
2729
pub type useconds_t = ::c_uint;
2830
pub type socklen_t = u32;
2931
pub type sa_family_t = u8;
30-
pub type pthread_t = ::uintptr_t;
32+
pub type pthread_t = ::c_uint;
3133
pub type pthread_key_t = ::c_uint;
3234
pub type blksize_t = u32;
3335
pub type fflags_t = u32;
@@ -123,6 +125,9 @@ s! {
123125
}
124126

125127
pub struct fd_set {
128+
#[cfg(target_pointer_width = "64")]
129+
fds_bits: [i64; FD_SETSIZE / 64],
130+
#[cfg(target_pointer_width = "32")]
126131
fds_bits: [i32; FD_SETSIZE / 32],
127132
}
128133

@@ -448,6 +453,9 @@ pub const SIG_SETMASK: ::c_int = 3;
448453
pub const IPV6_MULTICAST_LOOP: ::c_int = 0x8;
449454
pub const IPV6_V6ONLY: ::c_int = 0x27;
450455

456+
#[cfg(target_pointer_width = "64")]
457+
pub const FD_SETSIZE: usize = 65536;
458+
#[cfg(target_pointer_width = "32")]
451459
pub const FD_SETSIZE: usize = 1024;
452460

453461
pub const ST_RDONLY: ::c_ulong = 1;
@@ -946,19 +954,22 @@ pub const RTLD_CONFGEN: ::c_int = 0x10000;
946954

947955
f! {
948956
pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
957+
let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8;
949958
let fd = fd as usize;
950-
(*set).fds_bits[fd / 32] &= !(1 << (fd % 32));
959+
(*set).fds_bits[fd / bits] &= !(1 << (fd % bits));
951960
return
952961
}
953962

954963
pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool {
964+
let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8;
955965
let fd = fd as usize;
956-
return ((*set).fds_bits[fd / 32] & (1 << (fd % 32))) != 0
966+
return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0
957967
}
958968

959969
pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () {
970+
let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8;
960971
let fd = fd as usize;
961-
(*set).fds_bits[fd / 32] |= 1 << (fd % 32);
972+
(*set).fds_bits[fd / bits] |= 1 << (fd % bits);
962973
return
963974
}
964975

0 commit comments

Comments
 (0)