Utility Process
Warning
Please reach out to #ipc on https://chat.mozilla.org/ if you intent to add a new utility.
The utility process is used to provide a simple way to implement IPC actor with some more specific sandboxing properties, in case where you don’t need or want to deal with the extra complexity of adding a whole new process type but you just want to apply different sandboxing policies. To implement such an actor, you will have to follow a few steps like for implementing the trivial example visible in EmptyUtil:
Define a new IPC actor, e.g.,
PEmptyUtilthat allows to get some string viaGetSomeString()from the child to the parentIn the
PUtilityProcessdefinition, expose a new child-level method, e.g.,StartEmptyUtilService(Endpoint<PEmptyUtilChild>)Implement
EmptyUtilChildandEmptyUtilParentclasses both deriving from theirPEmptyUtilXX. If you want or need to run things from a different thread, you can have a look atUtilityProcessGenericActorMake sure both are refcounted
Expose your new service on
UtilityProcessManagerwith a method performing the heavy lifting of starting your process, you can take inspiration fromStartEmptyUtil()in the sample.Ideally, this starting method should rely on StartUtility()
To use
StartUtility()mentioned above, please ensure that you provide ansresult BindToUtilityProcess(RefPtr<UtilityProcessParent> aUtilityParent). Usually, it should be in charge of creating a set of endpoints and performingBind()to setup the IPC. You can see some example for UtilityMediaServiceFor proper user-facing exposition in
about:processesyou will have to also provide an actor name via a methodUtilityActorName GetActorName() { return UtilityActorName::EmptyUtil; }
Add member within enum WebIDLUtilityActorName in
Handle reception of
StartEmptyUtilServiceon the child side ofUtilityProcesswithinRecvStartEmptyUtilService()In
UtilityProcessChild::ActorDestroy, release any resources that you stored a reference to inRecvStartEmptyUtilService(). This will probably include a reference to theEmptyUtilChild.The specific sandboxing requirements can be implemented by tracking
SandboxingKind, and it starts within UtilityProcessSandboxing headerTry and make sure you at least add some
gtestcoverage of your new actor, for example like in existing gtestAlso ensure actual sandbox testing within
SandboxTestto start your new process, https://searchfox.org/mozilla-central/source/security/sandbox/common/test/SandboxTest.cpp
SandboxTestingChildTeststo define the test https://searchfox.org/mozilla-central/source/security/sandbox/common/test/SandboxTestingChildTests.h
SandboxTestingChildto run your test https://searchfox.org/mozilla-central/source/security/sandbox/common/test/SandboxTestingChild.cppPlease also consider having a look at Process Bookkeeping for anything you may want to ensure is supported by your new process, like e.g. profiler, crash reporting, etc.