Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable Mach.Port #129

Merged
merged 18 commits into from
Aug 16, 2023
Merged

Re-enable Mach.Port #129

merged 18 commits into from
Aug 16, 2023

Conversation

glessard
Copy link
Contributor

@glessard glessard commented Jun 10, 2023

Re-enabling was blocked on this issue: apple/swift#66299 (rdar://110496872)
Now it is blocked on rdar://110926824.

Mach.Port was disabled in commit 7bcc01f of #127

Once the fix is merged to https://github.com/apple/swift, then this can be merged.

@glessard glessard marked this pull request as draft June 10, 2023 07:14
@glessard
Copy link
Contributor Author

Once apple/swift#66505 is in the nightly compiler, we should be able to merge this.

@glessard
Copy link
Contributor Author

@swift-ci please test macOS platform

@glessard glessard added this to the 1.3.0 milestone Jun 21, 2023
@glessard glessard requested a review from loffgren July 8, 2023 01:05
@glessard glessard marked this pull request as ready for review August 9, 2023 22:57
@glessard
Copy link
Contributor Author

@swift-ci please test

@glessard
Copy link
Contributor Author

@swift-ci please test

@glessard
Copy link
Contributor Author

@swift-ci please test

@glessard glessard requested a review from milseman August 16, 2023 17:13
RightType.self == SendRight.self ||
RightType.self == SendOnceRight.self
)
_machPrecondition(mach_port_deallocate(mach_task_self_, _name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this does simplify the logic, it also means the kernel will no longer validate the right type on deinit. e.g. If you have a Mach.Port<Mach.RecieveRight> incorrectly wrapping a send right, the old code would fail this precondition (the mach call would return KERN_INVALID_RIGHT, whereas this new code would (silently, but not incorrectly) decrement the reference count of the send right.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point. I went this way because it had ballooned to 6 branches; there is probably a reasonable alternative somewhere in the middle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note from an out-of-band conversation: the previously-used mach_port_mod_refs() calls do not succeed when _name has become a dead name, because it is no longer a send right (or a send-once right.) It is unclear whether there's a reasonable and performant way to re-validate the type of _name in the deinit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we find a better solution for the deinit, we'll update it in another PR.

_ = consume recv
// `send` and `send1` have become dead names
_ = consume send
_ = consume send1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this test case, but no assertions?

Copy link
Contributor Author

@glessard glessard Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure what we should assert here, to be honest (other than "it did not crash"). I'm open to suggestions.

Tests/SystemTests/MachPortTests.swift Outdated Show resolved Hide resolved
Tests/SystemTests/MachPortTests.swift Outdated Show resolved Hide resolved
glessard and others added 2 commits August 16, 2023 13:19
This better communicates the intention.

Co-authored-by: loffgren <117697138+loffgren@users.noreply.github.com>
- It can’t return `Mach.Port<SendRight>`, because a noncopyable type cannot currently be a generic type argument.
@glessard
Copy link
Contributor Author

@swift-ci please test

@glessard glessard merged commit 8a8552f into apple:main Aug 16, 2023
2 checks passed
@glessard glessard deleted the reenable-mach-port branch August 16, 2023 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants