Delete copy constructor and operator= for SerializedStructuredCloneBuffer
Categories
(Core :: IPC, enhancement, P3)
Tracking
()
Tracking | Status | |
---|---|---|
firefox74 | --- | fixed |
People
(Reporter: mccr8, Assigned: sg)
References
(Depends on 1 open bug)
Details
Attachments
(1 file)
Copying a SerializedStructuredCloneBuffer can potentially involve allocating a lot of memory. In bug 1539261, I'm making it so that we at least check if the allocation succeeded, but there's nothing that can be done inside an operator= if it fails, so it just crashes. It seems like a bad idea to have this implicit copy operator, so we should probably delete it.
It looks like this is called from the copy constructors for a few IPDL structures that AFAICT aren't actually called. I'm not sure how we can deal with that.
Reporter | ||
Comment 1•5 years ago
|
||
Another possibility would be to just get rid of SerializedStructuredCloneBuffer, which looks like a very thin wrapper around JSStructuredCloneData.
Updated•5 years ago
|
Updated•5 years ago
|
Assignee | ||
Comment 2•4 years ago
|
||
This depends on Bug 1572054, since any IPDL type containing a SerializedStructureCloneBuffer
will declare a constructor copying it.
Comment 3•4 years ago
|
||
You can annotate SerializedStructuredCloneBuffer in ipdl as
moveonly`, and IPDL should do the right thing with it.
Assignee | ||
Comment 4•4 years ago
|
||
(In reply to Nathan Froyd [:froydnj] from comment #3)
You can annotate
SerializedStructuredCloneBuffer in ipdl as
moveonly`, and IPDL should do the right thing with it.
Oh, thanks! I wasn't aware of that possibility.
Assignee | ||
Comment 5•4 years ago
|
||
Hm, when I add moveonly
in https://searchfox.org/mozilla-central/rev/dd1dafd5c9c05640e76af30b58749076e0199704/dom/ipc/DOMTypes.ipdlh#20, from https://searchfox.org/mozilla-central/rev/dd1dafd5c9c05640e76af30b58749076e0199704/dom/ipc/DOMTypes.ipdlh#64 the constructor accepts SerializedStructuredCloneBuffer
by rvalue-reference, which is fine. However, also the following code will be generated:
SerializedStructuredCloneBuffer&
data()
{
return data_;
}
SerializedStructuredCloneBuffer&
data() const
{
return data_;
}
which yields
/home/simon/work/mozilla-unified/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders/mozilla/dom/DOMTypes.h:200:16: error: binding reference of type 'mozilla::dom::ClonedMessageData::SerializedStructuredCloneBuffer' (aka 'mozilla::SerializedStructuredCloneBuffer') to value of type 'const mozilla::dom::ClonedMessageData::SerializedStructuredCloneBuffer' (aka 'const mozilla::SerializedStructuredCloneBuffer') drops 'const' qualifier
return data_;
^~~~~
Note the missing const
on the return type of the const
overload. Do I need to change anything else in DOMTypes.ipdlh
or is this a defect in the IPDL generator?
Comment 6•4 years ago
|
||
That looks like a bug. If I'm reading the code right, I don't think any of our moveonly
types actually get stored in structures (?), so it's definitely possible there are some untried codepaths in there. ISTR a bug about propagating moveonly
-ness through structures as well (?).
Comment 7•4 years ago
|
||
I think this case should set t.const = True
: https://searchfox.org/mozilla-central/source/ipc/ipdl/ipdl/lower.py#587-589 which might solve the problem in comment 5. Propagation of moveonly
-ness is still an open question, though.
Assignee | ||
Comment 8•4 years ago
|
||
https://searchfox.org/mozilla-central/rev/dd1dafd5c9c05640e76af30b58749076e0199704/dom/broadcastchannel/BroadcastChannelService.cpp#121 deliberately makes a copy of an IPDL structure containing a SerializedStructuredCloneBuffer
. We can probably explicitly clone it at this place.
Assignee | ||
Comment 9•4 years ago
|
||
Replace all implicit copies by moves, or explicit clone operations.
Depends on D59726
Updated•4 years ago
|
Comment 10•4 years ago
|
||
So, historically, the way this kind of thing worked is that rvalue references didn't exist yet, so move-only-ish types like Shmem
used lvalue references, and the Recv
methods would get const references to the containing struct, and this is why the const accessors for those types use const_cast
to return non-const lvalue references.
I don't think we propgate moveonly
to structs/unions yet (or allow setting it on them manually), but that also isn't necessary until someone wants to move out of a field, and it looks like that's not the case for ClonedMessageData::data
.
Assignee | ||
Comment 11•4 years ago
|
||
Well, what's not really that nice is that const_cast
is required in the overrides of the generated virtual Alloc*
and Recv*
functions.
Comment 12•4 years ago
|
||
Pushed by sgiesecke@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/0f906da3634a Make SerializedStructuredCloneBuffer move-only. r=asuth,jld,baku
Comment 13•4 years ago
|
||
Backed out 3 changesets (bug 1539498, bug 1545196) for build bustages failures in DOMTypes.h
/builds/worker/workspace/build/src/obj-firefox/ipc/ipdl/_ipdlheaders/mozilla/dom/DOMTypes.h
/builds/worker/workspace/build/src/obj-firefox/ipc/ipdl/_ipdlheaders/mozilla/dom/ClientIPCTypes.h
/builds/worker/workspace/build/src/obj-firefox/ipc/ipdl/_ipdlheaders/mozilla/dom/ServiceWorkerOpArgs.h
Push that started the failures: https://treeherder.mozilla.org/#/jobs?repo=autoland&selectedJob=287169576&resultStatus=superseded%2Ctestfailed%2Cbusted%2Cexception%2Crunnable&revision=0f906da3634aaebe1267d030e31facb82feb2cfc
Failure log: https://treeherder.mozilla.org/logviewer.html#/jobs?job_id=287169576&repo=autoland&lineNumber=22644
Backout: https://hg.mozilla.org/integration/autoland/rev/3f81d87f402e1ffe15f31548b4ac03d01a66fec0
Assignee | ||
Comment 14•4 years ago
|
||
(In reply to Oana Pop-Rus from comment #13)
Backed out 3 changesets (bug 1539498, bug 1545196) for build bustages failures in DOMTypes.h
See https://bugzilla.mozilla.org/show_bug.cgi?id=1545196#c19
Comment 15•4 years ago
|
||
Pushed by sgiesecke@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/1d0bcf861a6c Make SerializedStructuredCloneBuffer move-only. r=asuth,jld,baku
Comment 16•4 years ago
|
||
bugherder |
Description
•