Skip to content

Commit

Permalink
Add OS specific types
Browse files Browse the repository at this point in the history
Add OS specific types that address alignment problems and their
respective libc definitions.
  • Loading branch information
dlrobertson committed Oct 11, 2016
1 parent bee50e7 commit 601b464
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/platform/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ const TEMP_FILE_TEMPLATE: &'static str = "/sdcard/servo/ipc-channel-shared-memor
#[cfg(not(target_os="android"))]
const TEMP_FILE_TEMPLATE: &'static str = "/tmp/ipc-channel-shared-memory.XXXXXX";

#[cfg(target_os = "linux")]
type IovLen = usize;
#[cfg(target_os = "linux")]
type MsgControlLen = size_t;

#[cfg(target_os = "freebsd")]
type IovLen = i32;
#[cfg(target_os = "freebsd")]
type MsgControlLen = socklen_t;

unsafe fn new_sockaddr_un(path: *const c_char) -> (sockaddr_un, socklen_t) {
let mut sockaddr: sockaddr_un = mem::zeroed();
libc::strncpy(sockaddr.sun_path.as_mut_ptr(),
Expand Down Expand Up @@ -209,7 +219,7 @@ impl OsIpcSender {
let cmsg_length = mem::size_of_val(fds);
let (cmsg_buffer, cmsg_space) = if cmsg_length > 0 {
let cmsg_buffer = libc::malloc(CMSG_SPACE(cmsg_length)) as *mut cmsghdr;
(*cmsg_buffer).cmsg_len = CMSG_LEN(cmsg_length);
(*cmsg_buffer).cmsg_len = CMSG_LEN(cmsg_length) as MsgControlLen;
(*cmsg_buffer).cmsg_level = libc::SOL_SOCKET;
(*cmsg_buffer).cmsg_type = SCM_RIGHTS;

Expand Down Expand Up @@ -241,9 +251,9 @@ impl OsIpcSender {
msg_name: ptr::null_mut(),
msg_namelen: 0,
msg_iov: iovec.as_mut_ptr(),
msg_iovlen: iovec.len(),
msg_iovlen: iovec.len() as IovLen,
msg_control: cmsg_buffer as *mut c_void,
msg_controllen: cmsg_space,
msg_controllen: cmsg_space as MsgControlLen,
msg_flags: 0,
};

Expand Down Expand Up @@ -895,9 +905,9 @@ impl UnixCmsg {
msg_name: ptr::null_mut(),
msg_namelen: 0,
msg_iov: iovec.as_mut_ptr(),
msg_iovlen: iovec.len(),
msg_iovlen: iovec.len() as IovLen,
msg_control: cmsg_buffer as *mut c_void,
msg_controllen: cmsg_length,
msg_controllen: cmsg_length as MsgControlLen,
msg_flags: 0,
},
}
Expand Down Expand Up @@ -929,7 +939,7 @@ impl UnixCmsg {
}

unsafe fn cmsg_len(&self) -> size_t {
(*(self.msghdr.msg_control as *const cmsghdr)).cmsg_len
(*(self.msghdr.msg_control as *const cmsghdr)).cmsg_len as size_t
}
}

Expand Down Expand Up @@ -978,7 +988,7 @@ extern {

#[repr(C)]
struct cmsghdr {
cmsg_len: size_t,
cmsg_len: MsgControlLen,
cmsg_level: c_int,
cmsg_type: c_int,
}
Expand Down

0 comments on commit 601b464

Please sign in to comment.