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

Implement minimal socket shim #3426

Closed
wants to merge 6 commits into from
Closed

Conversation

ZoeS17
Copy link

@ZoeS17 ZoeS17 commented Mar 29, 2024

I vaguely followed socketpair as to implementation details. I attempted to make a test too but there's not exactly a good way, that I can figure out, besides simply checking that an file descriptor gets made. I dd so for both the libc crate and the version I implemented.

Free feel to ask question and/or adjust if needed.

@ZoeS17 ZoeS17 marked this pull request as draft March 29, 2024 04:11
@ZoeS17 ZoeS17 marked this pull request as ready for review March 29, 2024 05:59
Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

However, as-is I don't think landing this would be very useful. Does it even make sense to support socket alone? As you said we can't really write any tests, so this doesn't actually make any program work with Miri. Likely this entire function will have to be rewritten as we discover how sockets can actually be implemented.

I think we need a plan for what the support for socket + bind + connect looks like. Once we have a plan we can land it step-by-step, but it makes no sense to start going without a plan for where we want to go. In particular, clearly the Socket type can't just be a unit struct. We need a sketch for what that type should look like. Then we can land this in multiple PRs, but at least there will be a perspective for where we are going.

If we land this as-is it will just be another useless stub next to socketpair, a half-finished construction site without any plan or vision or idea for what to do next -- that's not really useful for anything. I don't like the existing construction site, I regret that we landed it. I don't want us to add another one.


let _domain = this.read_scalar(domain)?.to_i32()?;
let _type_ = this.read_scalar(type_)?.to_i32()?;
let _protocol = this.read_scalar(protocol)?.to_i32()?;
Copy link
Member

Choose a reason for hiding this comment

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

Unless we intend to support all values here, we should throw_unsupported! for socket types we do not support.

@@ -88,6 +88,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let ptr = this.mremap(old_address, old_size, new_size, flags)?;
this.write_scalar(ptr, dest)?;
}
"socket" => {
Copy link
Member

@RalfJung RalfJung Apr 1, 2024

Choose a reason for hiding this comment

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

socket is a standard Unix/POSIX function, why is this in the "linux" module?

Don't copy the existing socketpair, it was landed with a "we'll fix the issues later" attitude but "later" never happened.

@bors
Copy link
Contributor

bors commented Apr 3, 2024

☔ The latest upstream changes (presumably #3441) made this pull request unmergeable. Please resolve the merge conflicts.

@RalfJung
Copy link
Member

RalfJung commented Apr 3, 2024

IOW, I think this should follow the proposed "project" process: #3443.
We're happy to help you through that process! This is probably best done on Zulip, but you can also open an issue dedicated to the project and we can discuss there.

@RalfJung
Copy link
Member

RalfJung commented Apr 4, 2024

I have opened an issue to track this: #3449.

I think blocking sockets are actually highly non-trivial to implement.

@ZoeS17 ZoeS17 marked this pull request as draft April 5, 2024 10:59
@RalfJung
Copy link
Member

RalfJung commented Apr 5, 2024

So to be clear I think before any implementation work is done, we need a clear description of which part of the socket API is intended to be implemented (TCP/UDP/..., blocking/non-blocking, which shims are involved). And since this will be non-trivial to implement, we also need a description of what the implementation plan is -- which new state is needed in Miri, how do we handle waking up the right threads when the sockets they are blocked on get ready, things like that. I laid out some of the complications in #3449.

Adding sockets is not an easy project. And with projects of this scale it's not a good idea to just go implement something -- that has a pretty high risk that we'll ask you to re-write it entirely as we see flaws with the fundamental structure of the approach, and it also makes review much harder when we have to reverse engineer the high-level approach from the code.

@ZoeS17 what is your goal with this PR? Is there a motivation for wanting to land just the socket shim without actually supporting sockets at all?

@bors
Copy link
Contributor

bors commented Apr 5, 2024

☔ The latest upstream changes (presumably #3451) made this pull request unmergeable. Please resolve the merge conflicts.

@ZoeS17
Copy link
Author

ZoeS17 commented Apr 5, 2024

Adding sockets is not an easy project. And with projects of this scale it's not a good idea to just go implement something -- that has a pretty high risk that we'll ask you to re-write it entirely as we see flaws with the fundamental structure of the approach, and it also makes review much harder when we have to reverse engineer the high-level approach from the code.

Agreed.

what is your goal with this PR? Is there a motivation for wanting to land just the socket shim without actually supporting sockets at all?

My intent was originally to land this as a shim without supporting sockets at all but given what has been said in the #3449 I agree that it seems foolish to continue as a "hollow" implementation. I originally come upon the desire to pick up this work because I was attempting to run miri against a program I was building that utilizes sockets to connect to IRC. Since obviously that needs a deeper implementation then I originally understood I'm up for closing this PR with an understanding that I'm willing to admit I may be out of my depth here.

@RalfJung
Copy link
Member

RalfJung commented Apr 5, 2024

I originally come upon the desire to pick up this work because I was attempting to run miri against a program I was building that utilizes sockets to connect to IRC.

Ah, yes makes sense. I'm afraid that's a pretty hard problem and quite far off currently, unfortunately.

I'll close this PR then. Thanks anyway!

@RalfJung RalfJung closed this Apr 5, 2024
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.

3 participants