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

Environ shim #1208

Merged
merged 9 commits into from
Mar 8, 2020
Merged

Environ shim #1208

merged 9 commits into from
Mar 8, 2020

Conversation

pvdrz
Copy link
Contributor

@pvdrz pvdrz commented Mar 4, 2020

Remake of #1147. There are three main problems with this:

  1. For some reason update_environ is not updating environ when setenv or unsetenv are called. Even then it works during initialization.
  2. I am not deallocating the old array with the variables in update_environ.
  3. I had to store the environ place into MemoryExtra as a field to update it. I was thinking about changing extern_statics to store places instead of AllocIDs to avoid this.

@RalfJung

Fixes #756

src/machine.rs Outdated Show resolved Hide resolved
src/shims/env.rs Outdated Show resolved Hide resolved
src/shims/env.rs Outdated Show resolved Hide resolved
src/shims/env.rs Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member

RalfJung commented Mar 5, 2020

For some reason update_environ is not updating environ when setenv or unsetenv are called. Even then it works during initialization.

That is curious. Could you please add a testcase demonstrating the problem?

@RalfJung
Copy link
Member

RalfJung commented Mar 5, 2020

I had to store the environ place into MemoryExtra as a field to update it. I was thinking about changing extern_statics to store places instead of AllocIDs to avoid this.

No I think what you did makes sense. There's just multiple parties that care about this particular allocation.
It is crucial though that the field in MemoryExtra never gets changed after initialization; maybe add a comment along those lines.

@pvdrz
Copy link
Contributor Author

pvdrz commented Mar 5, 2020

That is curious. Could you please add a testcase demonstrating the problem?

sure, check 18f0339

src/shims/env.rs Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member

RalfJung commented Mar 5, 2020

What remains is to deallocate the old memory, and to add a test that make sure it got deallocated.

@bors
Copy link
Collaborator

bors commented Mar 6, 2020

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

@pvdrz
Copy link
Contributor Author

pvdrz commented Mar 6, 2020

add a test that make sure it got deallocated.

How can I do that?

@RalfJung
Copy link
Member

RalfJung commented Mar 6, 2020

Yeah it's a bit tricky... it has to be a compile-fail test I think.
I suggest you declare environ as an extern static in that file, then get the ptr once early and deref it to test if that works. Then change the env, and try re-using the old ptr, now Miri should error.

src/shims/env.rs Outdated Show resolved Hide resolved
@pvdrz
Copy link
Contributor Author

pvdrz commented Mar 6, 2020

Yeah it's a bit tricky... it has to be a compile-fail test I think.
I suggest you declare environ as an extern static in that file, then get the ptr once early and deref it to test if that works. Then change the env, and try re-using the old ptr, now Miri should error.

That sounds really nasty... I like it

src/machine.rs Outdated Show resolved Hide resolved
src/shims/env.rs Outdated Show resolved Hide resolved
src/eval.rs Outdated Show resolved Hide resolved
src/eval.rs Outdated Show resolved Hide resolved
src/machine.rs Outdated Show resolved Hide resolved
@pvdrz pvdrz force-pushed the environ-shim branch 2 times, most recently from b069f06 to d868712 Compare March 8, 2020 00:04
src/shims/env.rs Outdated Show resolved Hide resolved
src/shims/env.rs Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member

RalfJung commented Mar 8, 2020

Looking great, thanks. :)

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 8, 2020

📌 Commit 8392a0c has been approved by RalfJung

@bors
Copy link
Collaborator

bors commented Mar 8, 2020

⌛ Testing commit 8392a0c with merge 574d81c...

@bors
Copy link
Collaborator

bors commented Mar 8, 2020

☀️ Test successful - checks-travis, status-appveyor
Approved by: RalfJung
Pushing 574d81c to master...

@bors bors merged commit 574d81c into rust-lang:master Mar 8, 2020
@pvdrz pvdrz deleted the environ-shim branch March 8, 2020 16:03
Comment on lines +88 to +89
/// Place where the `environ` static is stored. Lazily initialized, but then never changes.
pub(crate) environ: Option<MPlaceTy<'tcx, Tag>>,
Copy link
Member

@RalfJung RalfJung Mar 8, 2020

Choose a reason for hiding this comment

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

I just realized we already have the EnvVars struct for extra state for environment variables... @christianpoveda would you mind submitting a follow-up PR to move environ over to that struct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

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.

Cannot list environment variables
3 participants