> 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@macieira.org>
Sent: Friday, July 30, 2021 9:22 AM
To: sg16@lists.isocpp.org <sg16@lists.isocpp.org>; Corentin Jabot <corentinjabot@gmail.com>; Charlie Barto <Charles.Barto@microsoft.com>; Tom Honermann <tom@honermann.net>
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
them yet.

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