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

Remove need to truncate mach IPC results #162

Merged
merged 5 commits into from May 10, 2017
Merged

Remove need to truncate mach IPC results #162

merged 5 commits into from May 10, 2017

Conversation

@jdm
Copy link
Member

jdm commented May 10, 2017

Mach's IPC requires 4 byte alignment. The code that receives data does not account for that right now; these changes ensure that the returned buffer is the same size as the original buffer that was sent. Fixes #83. Fixes #103.

Copy link
Collaborator

pcwalton left a comment

Awesome! Just had a couple of nits and this is good to go.

@@ -371,7 +371,7 @@ fn embedded_bytes_receivers() {
let (super_tx, super_rx) = ipc::channel().unwrap();
super_tx.send(sub_tx).unwrap();
let sub_tx = super_rx.recv().unwrap();
let bytes = [1, 2, 3, 4, 5, 6, 7, 8];
let bytes = [1, 2, 3, 4, 5, 6, 7];

This comment has been minimized.

@pcwalton

pcwalton May 10, 2017

Collaborator

Add a comment linking to this PR saying that the odd number of bytes is intentional.

@@ -836,123 +877,213 @@ impl From<MachError> for bincode::Error {
}
}

impl From<kern_return_t> for MachError {
fn from(code: kern_return_t) -> MachError {
if code == MACH_MSG_SUCCESS {

This comment has been minimized.

@pcwalton

pcwalton May 10, 2017

Collaborator

Can this be a match statement instead?

Copy link
Contributor

antrik left a comment

I suggest putting the commit that changes the test case after the actual fix, to improve bisectability.

(Might actually want to add this as a separate test case, instead of changing the existing one... Not sure though it's really worth the effort.)

Have you considered sending the size in a separate data item? It might be considered more elegant... Though to be honest I'm not quite sure it's really a good idea, since it would actually complicate the code I think?

I wonder whether putting the size header before the actual data causes a performance hit on i386, because it breaks alignment... (Unless the alignment is already bad because of other things -- haven't checked that.) To avoid that, it might be preferable to put it after the actual data.

BTW, the error handling commit seems like a completely orthogonal thing, that could be committed independently? Personally, I'd submit it as a separate PR... (Not really a problem, though.)

ptr = ptr.offset(1);
}
data_dest = data_dest.offset(mem::size_of::<usize>() as isize);
ptr::copy_nonoverlapping(data.as_ptr(), data_dest, data_size);

This comment has been minimized.

@antrik

antrik May 10, 2017

Contributor

I can't see the message size being adjusted anywhere for the extra space taken up by the size header -- am I missing something?...

(This kind of pointer manipulation is so damn fragile -- it's actually worse than in C :-( Can't really blame you for that though I guess: probably not much point trying to use slices for this particular bit, without rewriting the rest of function in a more defensive way too...)

This comment has been minimized.

@jdm

jdm May 10, 2017

Author Member

I definitely had code which adjusted the header size. I'm confused by how it disappeared!

This comment has been minimized.

@antrik

antrik May 10, 2017

Contributor

To clarify, I do see code doing the adjustment in the receiver -- but not in the sender...

This comment has been minimized.

@jdm

jdm May 10, 2017

Author Member

I understood your original question. I remain confused about how code that I wrote and committed in Message::size_of somehow did not make it to github both times I added it. I have verified that it is now present in the commits in this PR.

@jdm
Copy link
Member Author

jdm commented May 10, 2017

@antrik Github is showing the commits in the wrong order; they are actually ordered in the way you recommend.

@jdm
Copy link
Member Author

jdm commented May 10, 2017

I am not going to make a separate PR for the error changes. They were useful for diagnosing the issue here, and it's not worth separating them out.

@pcwalton
Copy link
Collaborator

pcwalton commented May 10, 2017

@bors-servo: r+

🎉

@bors-servo
Copy link
Contributor

bors-servo commented May 10, 2017

📌 Commit 377028b has been approved by pcwalton

@bors-servo
Copy link
Contributor

bors-servo commented May 10, 2017

Testing commit 377028b with merge ab3ed55...

bors-servo added a commit that referenced this pull request May 10, 2017
Remove need to truncate mach IPC results

Mach's IPC requires 4 byte alignment. The code that receives data does not account for that right now; these changes ensure that the returned buffer is the same size as the original buffer that was sent. Fixes #83. Fixes #103.
@antrik
Copy link
Contributor

antrik commented May 10, 2017

@jdm the reason I prefer to submit independently useful changes as separate PRs is that in the (hopefully unlikely) case that the main PR doesn't get accepted for some reason, or turns out problematic and needs to be reverted later, it would be good to have the independent changes in nevertheless. But as I said, it's not really a problem...

@bors-servo
Copy link
Contributor

bors-servo commented May 10, 2017

💔 Test failed - status-travis

@jdm
Copy link
Member Author

jdm commented May 10, 2017

@bors-servo: r=pcwalton

@bors-servo
Copy link
Contributor

bors-servo commented May 10, 2017

📌 Commit 48deb5f has been approved by pcwalton

@bors-servo
Copy link
Contributor

bors-servo commented May 10, 2017

Testing commit 48deb5f with merge 46395ca...

bors-servo added a commit that referenced this pull request May 10, 2017
Remove need to truncate mach IPC results

Mach's IPC requires 4 byte alignment. The code that receives data does not account for that right now; these changes ensure that the returned buffer is the same size as the original buffer that was sent. Fixes #83. Fixes #103.
@bors-servo
Copy link
Contributor

bors-servo commented May 10, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: pcwalton
Pushing 46395ca to master...

@bors-servo bors-servo merged commit 48deb5f into master May 10, 2017
6 checks passed
6 checks passed
continuous-integration/appveyor/branch AppVeyor build succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
dependency-ci Dependencies checked
Details
homu Test successful
Details
@Gankra
Copy link
Contributor

Gankra commented May 11, 2017

omg, thanks for fixing this, @jdm!

@frewsxcv frewsxcv deleted the macipc branch May 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.