From a73c63f7345f4aa48de3db0cbb50cc4930099619 Mon Sep 17 00:00:00 2001 From: Nika Layzell Date: Wed, 19 Apr 2023 22:10:11 +0000 Subject: [PATCH] Bug 1824465 - Part 24: Require toplevel protocols to be refcounted, r=ipc-reviewers,mccr8 Differential Revision: https://phabricator.services.mozilla.com/D173739 --- ipc/glue/ProtocolUtils.h | 3 +++ ipc/ipdl/ipdl/lower.py | 11 ++++++----- ipc/ipdl/ipdl/type.py | 3 +++ ipc/ipdl/test/ipdl/error/PToplevelManualDealloc.ipdl | 6 ++++++ .../test/ipdl/ok/PExtendedAttrMultipleAttributes.ipdl | 2 +- ipc/ipdl/test/ipdl/ok/PManualDealloc.ipdl | 4 ++++ ipc/ipdl/test/ipdl/ok/PManualDealloc_manager.ipdl | 7 +++++++ 7 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 ipc/ipdl/test/ipdl/error/PToplevelManualDealloc.ipdl create mode 100644 ipc/ipdl/test/ipdl/ok/PManualDealloc_manager.ipdl diff --git a/ipc/glue/ProtocolUtils.h b/ipc/glue/ProtocolUtils.h index 657b95cc4823..c73a7560ae8c 100644 --- a/ipc/glue/ProtocolUtils.h +++ b/ipc/glue/ProtocolUtils.h @@ -385,6 +385,9 @@ class IToplevelProtocol : public IProtocol { ~IToplevelProtocol() = default; public: + // All top-level protocols are refcounted. + NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING + // Shadow methods on IProtocol which are implemented directly on toplevel // actors. int32_t Register(IProtocol* aRouted); diff --git a/ipc/ipdl/ipdl/lower.py b/ipc/ipdl/ipdl/lower.py index 67011b6d6355..b8ef219b9bf2 100644 --- a/ipc/ipdl/ipdl/lower.py +++ b/ipc/ipdl/ipdl/lower.py @@ -3838,11 +3838,12 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor): self.cls.addstmts([dtor, Whitespace.NL]) if ptype.isRefcounted(): - self.cls.addcode( - """ - NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING - """ - ) + if not ptype.isToplevel(): + self.cls.addcode( + """ + NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING + """ + ) self.cls.addstmt(Label.PROTECTED) self.cls.addcode( """ diff --git a/ipc/ipdl/ipdl/type.py b/ipc/ipdl/ipdl/type.py index ed0ea4831df6..76f908dd41fc 100644 --- a/ipc/ipdl/ipdl/type.py +++ b/ipc/ipdl/ipdl/type.py @@ -1278,6 +1278,9 @@ class GatherDecls(TcheckVisitor): if not p.decl.type.isToplevel() and p.decl.type.needsotherpid: self.error(p.loc, "[NeedsOtherPid] only applies to toplevel protocols") + if p.decl.type.isToplevel() and not p.decl.type.isRefcounted(): + self.error(p.loc, "Toplevel protocols cannot be [ManualDealloc]") + # FIXME/cjones declare all the little C++ thingies that will # be generated. they're not relevant to IPDL itself, but # those ("invisible") symbols can clash with others in the diff --git a/ipc/ipdl/test/ipdl/error/PToplevelManualDealloc.ipdl b/ipc/ipdl/test/ipdl/error/PToplevelManualDealloc.ipdl new file mode 100644 index 000000000000..97822b65bd68 --- /dev/null +++ b/ipc/ipdl/test/ipdl/error/PToplevelManualDealloc.ipdl @@ -0,0 +1,6 @@ +//error: Toplevel protocols cannot be [ManualDealloc] + +[ManualDealloc] async protocol PToplevelManualDealloc { +child: + async __delete__(); +}; diff --git a/ipc/ipdl/test/ipdl/ok/PExtendedAttrMultipleAttributes.ipdl b/ipc/ipdl/test/ipdl/ok/PExtendedAttrMultipleAttributes.ipdl index a7ac82c8d35d..4b1c9085b766 100644 --- a/ipc/ipdl/test/ipdl/ok/PExtendedAttrMultipleAttributes.ipdl +++ b/ipc/ipdl/test/ipdl/ok/PExtendedAttrMultipleAttributes.ipdl @@ -1,4 +1,4 @@ -[NestedUpTo=inside_sync, ManualDealloc] async protocol PExtendedAttrMultipleAttributes { +[NestedUpTo=inside_sync, NeedsOtherPid] async protocol PExtendedAttrMultipleAttributes { parent: async Msg(); }; diff --git a/ipc/ipdl/test/ipdl/ok/PManualDealloc.ipdl b/ipc/ipdl/test/ipdl/ok/PManualDealloc.ipdl index 62675f962dcf..53660762ad03 100644 --- a/ipc/ipdl/test/ipdl/ok/PManualDealloc.ipdl +++ b/ipc/ipdl/test/ipdl/ok/PManualDealloc.ipdl @@ -1,4 +1,8 @@ +include protocol PManualDealloc_manager; + [ManualDealloc] async protocol PManualDealloc { + manager PManualDealloc_manager; + child: async __delete__(); }; diff --git a/ipc/ipdl/test/ipdl/ok/PManualDealloc_manager.ipdl b/ipc/ipdl/test/ipdl/ok/PManualDealloc_manager.ipdl new file mode 100644 index 000000000000..224c7a5e46cc --- /dev/null +++ b/ipc/ipdl/test/ipdl/ok/PManualDealloc_manager.ipdl @@ -0,0 +1,7 @@ +include protocol PManualDealloc; + +// [ManualDealloc] types must have a manager, as all toplevel protocols are +// refcounted. +async protocol PManualDealloc_manager { + manages PManualDealloc; +};