Skip to content

Commit

Permalink
Backed out 5 changesets (bug 1590249) for Build bustage in AudioThrea…
Browse files Browse the repository at this point in the history
…dPriorityError. CLOSED TREE

Backed out changeset 301b1a49db9b (bug 1590249)
Backed out changeset c675b890508d (bug 1590249)
Backed out changeset ed1cd65eedae (bug 1590249)
Backed out changeset 0a7873a6b522 (bug 1590249)
Backed out changeset 36f6505b50c9 (bug 1590249)
  • Loading branch information
dgluca committed Jan 25, 2020
1 parent 13cc7e6 commit 3025fdd
Show file tree
Hide file tree
Showing 37 changed files with 547 additions and 312 deletions.
5 changes: 5 additions & 0 deletions .cargo/config.in
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ git = "https://github.com/PLSysSec/lucet_sandbox_compiler"
replace-with = "vendored-sources"
rev = "58498599272e23ef797bb4304d0f181d7455ca57"

[source."https://github.com/NikVolf/tokio-named-pipes"]
branch = "stable"
git = "https://github.com/NikVolf/tokio-named-pipes"
replace-with = "vendored-sources"

[source."https://github.com/ChunMinChang/cubeb-coreaudio-rs"]
git = "https://github.com/ChunMinChang/cubeb-coreaudio-rs"
replace-with = "vendored-sources"
Expand Down
26 changes: 20 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dom/media/CubebUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# include "mozilla/mscom/EnsureMTA.h"
#endif

#define AUDIOIPC_POOL_SIZE_DEFAULT 1
#define AUDIOIPC_POOL_SIZE_DEFAULT 2
#define AUDIOIPC_STACK_SIZE_DEFAULT (64 * 4096)

#define PREF_VOLUME_SCALE "media.volume_scale"
Expand Down
2 changes: 1 addition & 1 deletion media/audioipc/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Cubeb Audio Remoting Prototype
# Cubeb Audio Remoting Prototype
2 changes: 1 addition & 1 deletion media/audioipc/README_MOZILLA
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Makefile.in build files for the Mozilla build system.

The audioipc-2 git repository is: https://github.com/djg/audioipc-2.git

The git commit ID used was 86d49ddfca8b016a4b60b0b3fef76052194b8aa3 (2020-01-25 20:43:03 +1300)
The git commit ID used was 8af8083a9a6179bc9fe041c9e5059cea0a0e6fe0 (2019-10-22 14:11:23 +1300)
4 changes: 2 additions & 2 deletions media/audioipc/audioipc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ serde = "1.*.*"
serde_derive = "1.*.*"
tokio = "0.1"
tokio-io = "0.1"
audio_thread_priority = "0.21"
audio_thread_priority = "0.20.2"

[target.'cfg(unix)'.dependencies]
iovec = "0.1"
Expand All @@ -29,9 +29,9 @@ mio-uds = "0.6.7"
tokio-reactor = "0.1"

[target.'cfg(windows)'.dependencies]
mio = "0.6.19"
miow = "0.3.3"
mio-named-pipes = { git = "https://github.com/alexcrichton/mio-named-pipes" }
tokio-named-pipes = { git = "https://github.com/NikVolf/tokio-named-pipes", branch = "stable" }
winapi = { version = "0.3.6", features = ["combaseapi", "objbase"] }

[dependencies.error-chain]
Expand Down
62 changes: 38 additions & 24 deletions media/audioipc/audioipc/src/cmsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use bytes::{BufMut, Bytes, BytesMut};
use libc::{self, cmsghdr};
use std::convert::TryInto;
use std::os::unix::io::RawFd;
use std::{convert, mem, ops, slice};

Expand Down Expand Up @@ -41,10 +40,12 @@ pub fn iterator(c: Bytes) -> ControlMsgIter {
impl Iterator for ControlMsgIter {
type Item = Fds;

// This follows the logic in __cmsg_nxthdr from glibc
// /usr/include/bits/socket.h
fn next(&mut self) -> Option<Self::Item> {
loop {
let control = self.control.clone();
let cmsghdr_len = len(0);
let cmsghdr_len = align(mem::size_of::<cmsghdr>());

if control.len() < cmsghdr_len {
// No more entries---not enough data in `control` for a
Expand All @@ -56,14 +57,14 @@ impl Iterator for ControlMsgIter {
// The offset to the next cmsghdr in control. This must be
// aligned to a boundary that matches the type used to
// represent the length of the message.
let cmsg_len = cmsg.cmsg_len as usize;
let cmsg_space = space(cmsg_len - cmsghdr_len);
self.control = if cmsg_space > control.len() {
let cmsg_len = cmsg.cmsg_len;
let next_cmsghdr = align(cmsg_len as _);
self.control = if next_cmsghdr > control.len() {
// No more entries---not enough data in `control` for a
// complete message.
Bytes::new()
} else {
control.slice_from(cmsg_space)
control.slice_from(next_cmsghdr)
};

match (cmsg.cmsg_level, cmsg.cmsg_type) {
Expand Down Expand Up @@ -99,9 +100,9 @@ pub fn builder(buf: &mut BytesMut) -> ControlMsgBuilder {

impl ControlMsgBuilder {
fn msg(mut self, level: libc::c_int, kind: libc::c_int, msg: &[u8]) -> Self {
self.result = self.result.and_then(|mut cmsg| {
let cmsg_space = space(msg.len());
if cmsg.remaining_mut() < cmsg_space {
self.result = self.result.and_then(align_buf).and_then(|mut cmsg| {
let cmsg_len = len(msg.len());
if cmsg.remaining_mut() < cmsg_len {
return Err(Error::NoSpace);
}

Expand All @@ -112,19 +113,18 @@ impl ControlMsgBuilder {
let zeroed = unsafe { mem::zeroed() };
#[allow(clippy::needless_update)]
let cmsghdr = cmsghdr {
cmsg_len: len(msg.len()).try_into().unwrap(),
cmsg_len: cmsg_len as _,
cmsg_level: level,
cmsg_type: kind,
..zeroed
};

unsafe {
let cmsghdr_ptr = cmsg.bytes_mut().as_mut_ptr();
std::ptr::copy_nonoverlapping(&cmsghdr as *const _ as *const _, cmsghdr_ptr, mem::size_of::<cmsghdr>());
let cmsg_data_ptr = libc::CMSG_DATA(cmsghdr_ptr as _);
std::ptr::copy_nonoverlapping(msg.as_ptr(), cmsg_data_ptr, msg.len());
cmsg.advance_mut(cmsg_space);
}
let cmsghdr = unsafe {
slice::from_raw_parts(&cmsghdr as *const _ as *const _, mem::size_of::<cmsghdr>())
};
cmsg.put_slice(cmsghdr);
let mut cmsg = align_buf(cmsg)?;
cmsg.put_slice(msg);

Ok(cmsg)
});
Expand All @@ -141,7 +141,7 @@ impl ControlMsgBuilder {
}
}

trait AsBytes {
pub trait AsBytes {
fn as_bytes(&self) -> &[u8];
}

Expand All @@ -165,14 +165,28 @@ fn aligned(buf: &BytesMut) -> BytesMut {
aligned_buf
}

fn len(len: usize) -> usize {
unsafe {
libc::CMSG_LEN(len.try_into().unwrap()) as usize
fn align_buf(mut cmsg: BytesMut) -> Result<BytesMut, Error> {
let offset = unsafe { cmsg.bytes_mut().as_ptr() } as usize;
let adjust = align(offset) - offset;
if cmsg.remaining_mut() < adjust {
return Err(Error::NoSpace);
}

for _ in 0..adjust {
cmsg.put_u8(0);
}
Ok(cmsg)
}

fn align(len: usize) -> usize {
let cmsghdr_align = mem::align_of::<cmsghdr>();
(len + cmsghdr_align - 1) & !(cmsghdr_align - 1)
}

pub fn len(len: usize) -> usize {
align(mem::size_of::<cmsghdr>()) + len
}

pub fn space(len: usize) -> usize {
unsafe {
libc::CMSG_SPACE(len.try_into().unwrap()) as usize
}
align(mem::size_of::<cmsghdr>()) + align(len)
}
68 changes: 24 additions & 44 deletions media/audioipc/audioipc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ pub mod shm;
#[cfg(unix)]
mod tokio_uds_stream;

#[cfg(windows)]
mod tokio_named_pipes;

pub use crate::messages::{ClientMessage, ServerMessage};
use std::env::temp_dir;
use std::path::PathBuf;
Expand All @@ -56,8 +53,6 @@ use std::os::unix::io::{FromRawFd, IntoRawFd};
#[cfg(windows)]
use std::os::windows::io::{FromRawHandle, IntoRawHandle};

use std::cell::RefCell;

// This must match the definition of
// ipc::FileDescriptor::PlatformHandleType in Gecko.
#[cfg(windows)]
Expand All @@ -66,19 +61,11 @@ pub type PlatformHandleType = std::os::windows::raw::HANDLE;
pub type PlatformHandleType = libc::c_int;

// This stands in for RawFd/RawHandle.
#[derive(Clone, Debug)]
pub struct PlatformHandle(RefCell<Inner>);

#[derive(Clone, Debug)]
struct Inner {
handle: PlatformHandleType,
owned: bool,
}
#[derive(Copy, Clone, Debug)]
pub struct PlatformHandle(PlatformHandleType);

unsafe impl Send for PlatformHandle {}

pub const INVALID_HANDLE_VALUE: PlatformHandleType = -1isize as PlatformHandleType;

// Custom serialization to treat HANDLEs as i64. This is not valid in
// general, but after sending the HANDLE value to a remote process we
// use it to create a valid HANDLE via DuplicateHandle.
Expand All @@ -89,8 +76,7 @@ impl serde::Serialize for PlatformHandle {
where
S: serde::Serializer,
{
let h = self.0.borrow();
serializer.serialize_i64(h.handle as i64)
serializer.serialize_i64(self.0 as i64)
}
}

Expand All @@ -106,8 +92,7 @@ impl<'de> serde::de::Visitor<'de> for PlatformHandleVisitor {
where
E: serde::de::Error,
{
let owned = cfg!(windows);
Ok(PlatformHandle::new(value as PlatformHandleType, owned))
Ok(PlatformHandle::new(value as PlatformHandleType))
}
}

Expand All @@ -127,54 +112,49 @@ fn valid_handle(handle: PlatformHandleType) -> bool {

#[cfg(windows)]
fn valid_handle(handle: PlatformHandleType) -> bool {
const INVALID_HANDLE_VALUE: PlatformHandleType = -1isize as PlatformHandleType;
const NULL_HANDLE_VALUE: PlatformHandleType = 0isize as PlatformHandleType;
handle != INVALID_HANDLE_VALUE && handle != NULL_HANDLE_VALUE
}

impl PlatformHandle {
pub fn new(raw: PlatformHandleType, owned: bool) -> PlatformHandle {
assert!(valid_handle(raw));
let inner = Inner {
handle: raw,
owned: owned,
};
PlatformHandle(RefCell::new(inner))
pub fn new(raw: PlatformHandleType) -> PlatformHandle {
PlatformHandle(raw)
}

pub fn try_new(raw: PlatformHandleType) -> Option<PlatformHandle> {
if !valid_handle(raw) {
return None;
}
Some(PlatformHandle::new(raw))
}

#[cfg(windows)]
pub fn from<T: IntoRawHandle>(from: T) -> PlatformHandle {
PlatformHandle::new(from.into_raw_handle(), true)
PlatformHandle::new(from.into_raw_handle())
}

#[cfg(unix)]
pub fn from<T: IntoRawFd>(from: T) -> PlatformHandle {
PlatformHandle::new(from.into_raw_fd(), true)
PlatformHandle::new(from.into_raw_fd())
}

#[cfg(windows)]
pub unsafe fn into_file(&self) -> std::fs::File {
std::fs::File::from_raw_handle(self.into_raw())
pub unsafe fn into_file(self) -> std::fs::File {
std::fs::File::from_raw_handle(self.0)
}

#[cfg(unix)]
pub unsafe fn into_file(&self) -> std::fs::File {
std::fs::File::from_raw_fd(self.into_raw())
pub unsafe fn into_file(self) -> std::fs::File {
std::fs::File::from_raw_fd(self.0)
}

pub unsafe fn into_raw(&self) -> PlatformHandleType {
let mut h = self.0.borrow_mut();
assert!(h.owned);
h.owned = false;
h.handle
pub fn as_raw(self) -> PlatformHandleType {
self.0
}
}

impl Drop for PlatformHandle {
fn drop(&mut self) {
let inner = self.0.borrow();
if inner.owned {
unsafe { close_platformhandle(inner.handle) }
}
pub unsafe fn close(self) {
close_platformhandle(self.0);
}
}

Expand Down
Loading

0 comments on commit 3025fdd

Please sign in to comment.