Subject: Re: A UTF-8 environment specification; an alternative to assuming UTF-8 based on choice of literal encoding
From: Charlie Barto (Charles.Barto_at_[hidden])
Date: 2021-07-30 14:20:24
> On Windows, GetCommandLineW() is always valid.
well, GetCommandLineW is going to pull the arguments from memory pointed to by process environment block, I don't think there's anything preventing you from writing into that memory, just as you can write to the beginning of the stack on linux.
As far as I can tell neither linux nor windows store the program parameters anywhere besides this location (either the beginning of the stack or the memory pointed to by the PEB. Runtimes may copy them for transcoding or splitting (for example the ucrt's quoting and escaping rules). Still; I don't think they are stored anywhere that isn't under the complete control of the process in question on either platform.
The environment block may be an exception to this on windows, but on linux I'm under the impression that it's treated essentially the same as parameters but with inheritance behavior (I wonder if initial unixes got the inheritance "for free" because of fork/exec cleverness...)
From: Thiago Macieira <thiago_at_[hidden]>
Sent: Friday, July 30, 2021 9:22 AM
To: sg16_at_[hidden] <sg16_at_[hidden]>; Corentin Jabot <corentinjabot_at_[hidden]>; Charlie Barto <Charles.Barto_at_[hidden]>; Tom Honermann <tom_at_[hidden]>
Subject: Re: [SG16] A UTF-8 environment specification; an alternative to assuming UTF-8 based on choice of literal encoding
On Friday, 30 July 2021 08:41:13 PDT Tom Honermann wrote:
> True today, but I suspect their location is subject to change (though
> probably unlikely).
It's guaranteed by ABI.
> Is there a straight forward way to determine their location in memory?
Yes from main, because you got a pointer to argv and nothing can have modified
After main(), even if you get a pointer to them, you can't be sure they
haven't been modified / clobbered / overwritten, so that's not useful.
On Windows, GetCommandLineW() is always valid.
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Software Architect - Intel DPG Cloud Engineering
SG16 list run by email@example.com