forked from win32ss/supermium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for mojom RuntimeFeature on interfaces
This CL adds support for the `RuntimeFeature` attribute on mojom interfaces in C++. See doc[0] for details. ``` module foo.mojom; feature kTastyFeature { const string name = "TastyFeature"; const bool default_state = false; }; [RuntimeFeature=kTastyFeature] interface GatedInterface { // GatedInterface cannot be bound to a remote<> or receiver<>. }; interface OtherInterface { // Sending disabled interfaces will result in bad messages. PassInterface(pending_remote<GatedInterface>? iface); } ``` Developers should test the runtime feature to avoid binding or calling a disabled interface: ``` remote<OtherInterface> remote = ...; if (base::FeatureList::IsEnabled(kTastyFeature)) { PendingRemote<GatedInterface> pending_guarded; PendingReceiver<GatedInterface> pending_recv = pending_guarded.InitWithNewEndpointAndPassReceiver(); auto impl = std::make_unique<GatedImpl>(); auto weak_ref = MakeSelfOwnedReceiver(std::move(impl), std::move(pending_recv)); remote->PassInterface(std::move(pending_guarded)); } ``` The annotation exists to allow feature-flags to be enforced by the IPC system - but attempting to use a disabled interface may lead to safe crashes in production builds - it is up to developers to consult the exposed underlying feature before attempting to use a disabled feature. DCHECKS in test builds should validate this by crashing early. In the example above - if kTastyFeature is not enabled and the if() statement omitted:- * pending_guarded & pending_recv will never bind. * MakeSelfOwnedReceiver will return a null weak_ref. * remote->PassInterface() will not serialize or deserialize the gated interface. Details Feature tests happen via a templated function defined in runtime_features.h and specialized in mojom-module.h files for interfaces that define a RuntimeEnabled attribute. Interfaces not guarded with a feature will work as before - checks for these are emitted as constexpr templates so should not incur a runtime cost. In release (non-DCHECK) builds mojo C++ bindings will (often silently) not bind mojo message pipes to concrete receiver<T>, remote<T> or SelfOwnedReceiver<T>, and will refuse to serialize pending disabled interfaces (resulting in a bad message). In debug (DCHECK) builds mojo C++ bindings will crash if an attempt is made to use a concrete remote<T> or receiver<T> for an interface annotated with a disabled feature. Compromised processes can still request or serialize disabled interfaces, but the non-compromised end will consult its view of the feature state and refuse to concretely bind such faked requests. Remote & Receiver sets gain Add() methods which return an optional<Id> - these can replace uses of .Add() in contexts where generic code might host feature guarded interfaces in future. "casting" generic receivers via the .As<Interface>() method will return null receivers or DCHECK. ServiceFactory will safely skip .Add()ing binders for disabled interfaces. RuntimeFeature is not yet implemented for methods, and non-C++ bindings are not yet aware of mojo-hosted features. [0] https://docs.google.com/document/d/1kKFHu73SNwpBfPJzrVH2vLbpu9_1WuZhngFBqtJhwqw/edit?pli=1#heading=h.2s5rrpm5k56k Tests: mojo_unittests --gtest_filter=FeatureBindingsTest.* Bug: 1278253 Change-Id: I2cace494dd766bdd59f4cf781c8432ee7ec00ca2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4779888 Reviewed-by: Daniel Cheng <[email protected]> Commit-Queue: Alex Gough <[email protected]> Cr-Commit-Position: refs/heads/main@{#1230224}
- Loading branch information
Showing
33 changed files
with
1,276 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.