compositing: Split Servo up into multiple sandboxed processes.

Multiprocess mode is enabled with the `-M` switch, and sandboxing is
enabled with the `-S` switch.
This commit is contained in:
Patrick Walton 2015-07-24 17:00:10 -07:00 committed by Josh Matthews
parent ff4171170d
commit 1c130819ca
33 changed files with 688 additions and 265 deletions

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use font_template::{FontTemplate, FontTemplateDescriptor};
use ipc_channel::ipc;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use net_traits::{AsyncResponseTarget, PendingAsyncLoad, ResourceTask, ResponseAction};
use platform::font_context::FontContextHandle;
@ -15,7 +15,7 @@ use platform::font_template::FontTemplateData;
use std::borrow::ToOwned;
use std::collections::HashMap;
use std::mem;
use std::sync::mpsc::{Sender, Receiver, channel};
use std::sync::mpsc::channel;
use std::sync::{Arc, Mutex};
use string_cache::Atom;
use style::font_face::Source;
@ -77,15 +77,17 @@ impl FontFamily {
}
/// Commands that the FontContext sends to the font cache task.
#[derive(Deserialize, Serialize)]
pub enum Command {
GetFontTemplate(String, FontTemplateDescriptor, Sender<Reply>),
GetLastResortFontTemplate(FontTemplateDescriptor, Sender<Reply>),
AddWebFont(Atom, Source, Sender<()>),
AddDownloadedWebFont(LowercaseString, Url, Vec<u8>, Sender<()>),
Exit(Sender<()>),
GetFontTemplate(String, FontTemplateDescriptor, IpcSender<Reply>),
GetLastResortFontTemplate(FontTemplateDescriptor, IpcSender<Reply>),
AddWebFont(Atom, Source, IpcSender<()>),
AddDownloadedWebFont(LowercaseString, Url, Vec<u8>, IpcSender<()>),
Exit(IpcSender<()>),
}
/// Reply messages sent from the font cache task to the FontContext caller.
#[derive(Deserialize, Serialize)]
pub enum Reply {
GetFontTemplateReply(Option<Arc<FontTemplateData>>),
}
@ -93,8 +95,8 @@ pub enum Reply {
/// The font cache task itself. It maintains a list of reference counted
/// font templates that are currently in use.
struct FontCache {
port: Receiver<Command>,
channel_to_self: Sender<Command>,
port: IpcReceiver<Command>,
channel_to_self: IpcSender<Command>,
generic_fonts: HashMap<LowercaseString, LowercaseString>,
local_families: HashMap<LowercaseString, FontFamily>,
web_families: HashMap<LowercaseString, FontFamily>,
@ -269,14 +271,14 @@ impl FontCache {
/// The public interface to the font cache task, used exclusively by
/// the per-thread/task FontContext structures.
#[derive(Clone)]
#[derive(Clone, Deserialize, Serialize)]
pub struct FontCacheTask {
chan: Sender<Command>,
chan: IpcSender<Command>,
}
impl FontCacheTask {
pub fn new(resource_task: ResourceTask) -> FontCacheTask {
let (chan, port) = channel();
let (chan, port) = ipc::channel().unwrap();
let channel_to_self = chan.clone();
spawn_named("FontCacheTask".to_owned(), move || {
@ -310,7 +312,7 @@ impl FontCacheTask {
pub fn find_font_template(&self, family: String, desc: FontTemplateDescriptor)
-> Option<Arc<FontTemplateData>> {
let (response_chan, response_port) = channel();
let (response_chan, response_port) = ipc::channel().unwrap();
self.chan.send(Command::GetFontTemplate(family, desc, response_chan)).unwrap();
let reply = response_port.recv().unwrap();
@ -325,7 +327,7 @@ impl FontCacheTask {
pub fn last_resort_font_template(&self, desc: FontTemplateDescriptor)
-> Arc<FontTemplateData> {
let (response_chan, response_port) = channel();
let (response_chan, response_port) = ipc::channel().unwrap();
self.chan.send(Command::GetLastResortFontTemplate(desc, response_chan)).unwrap();
let reply = response_port.recv().unwrap();
@ -337,12 +339,12 @@ impl FontCacheTask {
}
}
pub fn add_web_font(&self, family: Atom, src: Source, sender: Sender<()>) {
pub fn add_web_font(&self, family: Atom, src: Source, sender: IpcSender<()>) {
self.chan.send(Command::AddWebFont(family, src, sender)).unwrap();
}
pub fn exit(&self) {
let (response_chan, response_port) = channel();
let (response_chan, response_port) = ipc::channel().unwrap();
self.chan.send(Command::Exit(response_chan)).unwrap();
response_port.recv().unwrap();
}

View file

@ -14,7 +14,7 @@ use style::computed_values::{font_stretch, font_weight};
/// to be expanded or refactored when we support more of the font styling parameters.
///
/// NB: If you change this, you will need to update `style::properties::compute_font_hash()`.
#[derive(Clone, Copy, Eq, Hash)]
#[derive(Clone, Copy, Eq, Hash, Deserialize, Serialize)]
pub struct FontTemplateDescriptor {
pub weight: font_weight::T,
pub stretch: font_stretch::T,

View file

@ -36,8 +36,7 @@ use std::sync::mpsc::{Receiver, Select, Sender, channel};
use url::Url;
use util::geometry::{ExpandToPixelBoundaries, ZERO_POINT};
use util::opts;
use util::task::spawn_named;
use util::task::spawn_named_with_send_on_failure;
use util::task;
use util::task_state;
#[derive(Clone, Deserialize, Serialize, HeapSizeOf)]
@ -255,9 +254,11 @@ impl<C> PaintTask<C> where C: PaintListener + Send + 'static {
failure_msg: Failure,
time_profiler_chan: time::ProfilerChan,
mem_profiler_chan: mem::ProfilerChan,
shutdown_chan: Sender<()>) {
shutdown_chan: IpcSender<()>) {
let ConstellationChan(c) = constellation_chan.clone();
spawn_named_with_send_on_failure(format!("PaintTask {:?}", id), task_state::PAINT, move || {
task::spawn_named_with_send_on_failure(format!("PaintTask {:?}", id),
task_state::PAINT,
move || {
{
// Ensures that the paint task and graphics context are destroyed before the
// shutdown message.
@ -572,7 +573,7 @@ impl WorkerThreadProxy {
let (to_worker_sender, to_worker_receiver) = channel();
let font_cache_task = font_cache_task.clone();
let time_profiler_chan = time_profiler_chan.clone();
spawn_named("PaintWorker".to_owned(), move || {
task::spawn_named("PaintWorker".to_owned(), move || {
let mut worker_thread = WorkerThread::new(from_worker_sender,
to_worker_receiver,
native_display,