-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[unix] Don't clone command-line args on startup #47165
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
Conversation
r? @shepmaster (rust_highfive has picked a reviewer for you, use r? to override) |
Thanks! I think though this may run a risk of memory unsafety? There can be a brief moment after the main thread has returned that other threads could try to access I'm not sure if there's a way around that other than cloning on startup. Does cloning on startup cause problems though? |
Ah, this is because argv may point to data on the main thread's stack, right? Does this mean the current Mac and iOS implementations are unsafe, since they may try to read from argv after main thread exit?
We could reset the pointer to null in
It's a small time and memory overhead for every Rust binary that uses libstd, though probably too tiny to matter for most such programs. Removing it also simplifies the code somewhat. |
Ah yeah I dunno about the OSX implementation. I think we're praying that the library function gets it right? I'm not sure of the exact semantics of it though. You're right though in that I think nulling out before main returns could work! It seems reasonable to me to panic in other threads at that time. |
Update: I re-added a |
Oh, now I see why. :) Fix coming up. |
@bors: r+ |
📌 Commit 91c3eee has been approved by |
[unix] Don't clone command-line args on startup Fixes part of rust-lang#47164 and simplifies the `args` code on non-Apple Unix platforms. Note: This could change behavior for programs that use both `std::env::args` *and* unsafe code that mutates `argv` directly. However, these programs already behave differently on different platforms. The new behavior on non-Apple platforms is closer to the existing behavior on Apple platforms.
Fixes part of #47164 and simplifies the
args
code on non-Apple Unix platforms.Note: This could change behavior for programs that use both
std::env::args
and unsafe code that mutatesargv
directly. However, these programs already behave differently on different platforms. The new behavior on non-Apple platforms is closer to the existing behavior on Apple platforms.