This is an archive of the discontinued LLVM Phabricator instance.

[libc] Prevent changing ownership of the port once opened
ClosedPublic

Authored by jhuber6 on May 8 2023, 7:07 AM.

Details

Summary

The Port type has stipuations that the same exact mask used to open it
needs to close it. This can currently be violated by calling its move
constructor to put it somewhere else. We still need the move constructor
to handle the open and closing functions. So, we simply make these
constructors private and only allow a few classes to have move
priviledges on it.

Diff Detail

Event Timeline

jhuber6 created this revision.May 8 2023, 7:07 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 8 2023, 7:07 AM
jhuber6 requested review of this revision.May 8 2023, 7:07 AM
JonChesterfield added a comment.EditedMay 8 2023, 7:16 AM

Let's put port.close in the destructor in the same commit as that's available branch-free for non-movable types. Also write a comment to the effect of "move only modulo optional" or similar as otherwise it's not obvious why the move ctors are not deleted.

I'm assuming that optional doesn't call the destructor on a value that isn't there but that's not a safe assumption. Let's go with this patch as-is and work out what to do with raii separately.

lntue accepted this revision.May 10 2023, 1:25 PM
This revision is now accepted and ready to land.May 10 2023, 1:25 PM
lntue added a comment.May 10 2023, 1:27 PM

Ok after @JonChesterfield 's comments are addressed.

Ok after @JonChesterfield 's comments are addressed.

I tried implementing the destructor as an RAII interface, but it had some issues I didn't delve too far into at the time.

JonChesterfield accepted this revision.May 10 2023, 2:02 PM

Diff is ok by me as currently written

libc/src/__support/RPC/rpc.h
261

Guessing we can't have delete here while using an optional that requires move?

jhuber6 added inline comments.May 10 2023, 2:03 PM
libc/src/__support/RPC/rpc.h
261

Yep, so next best thing is making it private.

This revision was automatically updated to reflect the committed changes.