[Lldb-commits] [lldb] b4a6e63 - [lldb/Target] Rework the way the inferior environment is created

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 26 03:48:12 PDT 2020


On 25/03/2020 17:51, Adrian McCarthy via lldb-commits wrote:
> 
> 
> On Wed, Mar 25, 2020 at 9:49 AM Adrian McCarthy <amccarth at google.com
> <mailto:amccarth at google.com>> wrote:
> 
> 
> 
>     On Wed, Mar 25, 2020 at 9:10 AM Pavel Labath <pavelo at centrum.sk
>     <mailto:pavelo at centrum.sk>> wrote:
> 
>         On 25/03/2020 01:04, Adrian McCarthy wrote:
>         > I took a stab at this, but I'm not seeing any new test failures.
> 
>         That is odd.
> 
>         I was doing some stuff on windows today, so I figured I'd take a
>         stab at
>         this. I was kind of right that the check in ProcessLauncher windows
>         prevents us from passing an empty environment.
> 
>         However, the interesting part starts when I tried to remove that
>         check.
>         Then the test started behaving nondeterministically -- sometimes
>         passing
>         and sometimes failing due to ERROR_INVALID_PARAMETER being
>         returned from
>         CreateProcessW. I can see how windows might need some environment
>         variables to start up a process correctly, but I do not
>         understand why
>         this should be nondeterministic...
> 
> 
>     Oh, I have a guess.  CreateProcessW takes a pointer to an
>     environment block.  If that pointer is null, the process will
>     inherit the parent environment.  If you want to pass it an empty
>     environment, you have to have a valid pointer to an empty string (or
>     possibly to a string with TWO terminating '\0's).
> 
> 
> Scratch the "or possibly."  You definitely need two terminating zeros. 
> Since it's in UTF-16, it wants two L'\0', which is four consecutive zero
> bytes.
>  

Thanks. This is exactly what was needed. It's not what I would have
expected, as the documentation says this is "null-terminated block of
null-terminated strings" -- in my book that would mean that an empty
list of null-terminated strings ends with a single L'\0'. But I guess
this is a very weird corner case, as an empty environment is literally
the only way to *not* need a double null terminator.

Anyway, D76835 is the patch for that.

pl


More information about the lldb-commits mailing list