{"id":18635782,"url":"https://github.com/xpack-dev-tools/ms-spawn-issue","last_synced_at":"2025-06-29T18:03:43.261Z","repository":{"id":89188060,"uuid":"422882414","full_name":"xpack-dev-tools/ms-spawn-issue","owner":"xpack-dev-tools","description":"Attempt to diagnose the Microsoft spawn() issue","archived":false,"fork":false,"pushed_at":"2021-11-01T12:48:04.000Z","size":511,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-17T13:09:23.690Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xpack-dev-tools.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-30T13:01:37.000Z","updated_at":"2021-11-01T12:48:07.000Z","dependencies_parsed_at":"2023-06-14T08:45:16.247Z","dependency_job_id":null,"html_url":"https://github.com/xpack-dev-tools/ms-spawn-issue","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/xpack-dev-tools/ms-spawn-issue","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpack-dev-tools%2Fms-spawn-issue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpack-dev-tools%2Fms-spawn-issue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpack-dev-tools%2Fms-spawn-issue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpack-dev-tools%2Fms-spawn-issue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xpack-dev-tools","download_url":"https://codeload.github.com/xpack-dev-tools/ms-spawn-issue/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpack-dev-tools%2Fms-spawn-issue/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262642960,"owners_count":23341816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T05:26:33.678Z","updated_at":"2025-06-29T18:03:43.221Z","avatar_url":"https://github.com/xpack-dev-tools.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Microsoft `spawnve()` issue\n\n## The problem\n\nIt seems that the implementation of `spawnve()` in the modern Microsoft\nUCRT API has a problem, and in certain conditions, calling the `spawn*e()`\nfunctions with a non-NULL environment, crashes with _Error -1073741819_\nwhich is 0xC0000005, or ERROR_ACCESS_DENIED.\n\nThese conditions are met by **GNU make**, and some programs invoked\nby `make.exe` that try to create sub-processes with `spawn*e()`, fail.\n\nSince `spawnve()` is also called by BusyBox in its `sh.exe` implementation,\nthis is a major issue, because it affects most common build tools.\n\n## History\n\nThe problem was detected when attempting to rebuild the\n[xPack Windows Build Tools](https://github.com/xpack-dev-tools/windows-build-tools-xpack)\npackage with a new build environment (xPack Build Box - XBB v3.3), which\nupgraded the mingw-gcc compiler to use the UCRT API\n([#19](https://github.com/xpack-dev-tools/windows-build-tools-xpack/issues/19)).\n\nUCRT is the Microsoft\n[Universal C Runtime](https://www.microsoft.com/en-us/download/details.aspx?id=48234),\nand is available since Windows 7 SP1 from 2011.\n\nThe problem did not occur in the past, because `sh.exe` was built\nto use the legacy MSVCRT API, which is not affected.\n\n## Project overview\n\nThis open source project provides several test programs to diagnose\nthis problem. It is available from GitHub as\n[xpack-dev-tools/ms-spawn-issue](https://github.com/xpack-dev-tools/ms-spawn-issue).\n\nSome programs are avalable in binary form (`make.exe` and `ninja.exe`),\nand some both as source code and in binary form, compiled with Microsoft\nVisual Studio.\n\nThe `spawn-*.exe` binaries behave like a very simple shell used to\nstart a child process `dump-env.exe`.\n\n- `spawn-env.exe` creates a new sub-process and passes the unmodified\nenvironment, as received by `main()`.\n- `spawn-null.exe` is identical to `spawn-env.exe`, except that it passes\na NULL pointer for the environment, which is a shortcut for inheriting\nthe full environment from the parent process.\n\nThe tests show the environment before the `spawn()` call\nand in the child process.\n\n## How to test\n\n### Prerequisites\n\n- a Windows 10 system or later.\n- when using the Git repository, a Git client is needed, for example\n[Git for Windows](https://git-scm.com/download/win).\n\n### Download/clone the project\n\nThe tests can be downloaded either as a ZIP archive or as a full Git repository.\n\n#### Download the ZIP archive\n\nThe latest version of this project can be downloaded as a ZIP archive from:\n\n- \u003chttps://github.com/xpack-dev-tools/ms-spawn-issue/archive/refs/heads/master.zip\u003e\n\nIt can be unpacked in any folder, for example in `tmp\\ms-spawn-issue`.\n\n#### Clone the full Git repository\n\nThe full Git repository can be cloned with:\n\n```doscmd\nC:\\Users\\ilg\u003emkdir tmp\nC:\\Users\\ilg\u003ecd tmp\nC:\\Users\\ilg\\tmp\u003egit clone https://github.com/xpack-dev-tools/ms-spawn-issue.git\nCloning into 'ms-spawn-issue'...\nremote: Enumerating objects: 114, done.\nremote: Counting objects: 100% (114/114), done.\nremote: Compressing objects: 100% (74/74), done.\nReceiving objects:  85% (97/114)used 92 (delta 36), pack-reused 0R\nReceiving objects: 100% (114/114), 468.93 KiB | 3.47 MiB/s, done.\nResolving deltas: 100% (54/54), done.\n\nC:\\Users\\ilg\\tmp\u003e\n```\n\n### PowerShell\n\nThe following tests were executed in a `cmd.exe` terminal, but behave\nthe same in a PowerShell terminal. The only difference is that the\ntests should be started with a relative path, like `.\\make`.\n\n### Run the `make` test\n\nChange to the `ms-spawn-issue\\tests` folder and run the tests:\n\n```doscmd\nC:\\Users\\ilg\\tmp\u003ecd ms-spawn-issue\\tests\n\nC:\\Users\\ilg\\tmp\\ms-spawn-issue\\tests\u003emake\nspawn-env -c \"dump-env one two\"\n\nSpawn test:\nspawn env[0]='ALLUSERSPROFILE=C:\\ProgramData'\nspawn env[1]='APPDATA=C:\\Users\\ilg\\AppData\\Roaming'\nspawn env[2]='CommonProgramFiles(x86)=C:\\Program Files (x86)\\Common Files'\nspawn env[3]='CommonProgramFiles=C:\\Program Files\\Common Files'\nspawn env[4]='CommonProgramW6432=C:\\Program Files\\Common Files'\nspawn env[5]='COMPUTERNAME=ILG-W11-TEST'\nspawn env[6]='ComSpec=C:\\Windows\\system32\\cmd.exe'\nspawn env[7]='DriverData=C:\\Windows\\System32\\Drivers\\DriverData'\nspawn env[8]='HOMEDRIVE=C:'\nspawn env[9]='HOMEPATH=\\Users\\ilg'\nspawn env[10]='LOCALAPPDATA=C:\\Users\\ilg\\AppData\\Local'\nspawn env[11]='LOGONSERVER=\\\\ILG-W11-TEST'\nspawn env[12]='MAKE_TERMERR=true'\nspawn env[13]='MAKE_TERMOUT=true'\nspawn env[14]='MAKEFLAGS='\nspawn env[15]='MAKELEVEL=1'\nspawn env[16]='MFLAGS='\nspawn env[17]='NUMBER_OF_PROCESSORS=4'\nspawn env[18]='OS=Windows_NT'\nspawn env[19]='PATH=C:\\Program Files (x86)\\Parallels\\Parallels Tools\\Applications;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files\\nodejs\\;C:\\Program Files\\Git\\cmd;C:\\Users\\ilg\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\ilg\\AppData\\Roaming\\npm;C:\\Users\\ilg\\AppData\\Local\\Programs\\Microsoft VS Code\\bin'\nspawn env[20]='PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC'\nspawn env[21]='PROCESSOR_ARCHITECTURE=AMD64'\nspawn env[22]='PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 158 Stepping 10, GenuineIntel'\nspawn env[23]='PROCESSOR_LEVEL=6'\nspawn env[24]='PROCESSOR_REVISION=9e0a'\nspawn env[25]='ProgramData=C:\\ProgramData'\nspawn env[26]='ProgramFiles(x86)=C:\\Program Files (x86)'\nspawn env[27]='ProgramFiles=C:\\Program Files'\nspawn env[28]='ProgramW6432=C:\\Program Files'\nspawn env[29]='PROMPT=$P$G'\nspawn env[30]='PSModulePath=C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules'\nspawn env[31]='PUBLIC=C:\\Users\\Public'\nspawn env[32]='SESSIONNAME=Console'\nspawn env[33]='SystemDrive=C:'\nspawn env[34]='SystemRoot=C:\\Windows'\nspawn env[35]='TEMP=C:\\Users\\ilg\\AppData\\Local\\Temp'\nspawn env[36]='TMP=C:\\Users\\ilg\\AppData\\Local\\Temp'\nspawn env[37]='USERDOMAIN_ROAMINGPROFILE=ILG-W11-TEST'\nspawn env[38]='USERDOMAIN=ILG-W11-TEST'\nspawn env[39]='USERNAME=ilg'\nspawn env[40]='USERPROFILE=C:\\Users\\ilg'\nspawn env[41]='windir=C:\\Windows'\nspawn argv[0]='spawn-env'\nspawn argv[1]='-c'\nspawn argv[2]='dump-env one two'\nspawn command 'dump-env.exe'...\nmake: *** [makefile:3: all] Error -1073741819\n\nC:\\Users\\ilg\\tmp\\ms-spawn-issue\\tests\u003e\n```\n\nThis test, which passes the environment received by `main()` fails\nexactly inside the `_spawnvpe()` call.\n\n```doscon\nC:\\Users\\ilg\\tmp\\ms-spawn-issue\\tests\u003emake null\nspawn-null -c \"dump-env three four\"\n\nSpawn test:\nspawn env[0]='ALLUSERSPROFILE=C:\\ProgramData'\nspawn env[1]='APPDATA=C:\\Users\\ilg\\AppData\\Roaming'\nspawn env[2]='CommonProgramFiles(x86)=C:\\Program Files (x86)\\Common Files'\nspawn env[3]='CommonProgramFiles=C:\\Program Files\\Common Files'\nspawn env[4]='CommonProgramW6432=C:\\Program Files\\Common Files'\nspawn env[5]='COMPUTERNAME=ILG-W11-TEST'\nspawn env[6]='ComSpec=C:\\Windows\\system32\\cmd.exe'\nspawn env[7]='DriverData=C:\\Windows\\System32\\Drivers\\DriverData'\nspawn env[8]='HOMEDRIVE=C:'\nspawn env[9]='HOMEPATH=\\Users\\ilg'\nspawn env[10]='LOCALAPPDATA=C:\\Users\\ilg\\AppData\\Local'\nspawn env[11]='LOGONSERVER=\\\\ILG-W11-TEST'\nspawn env[12]='MAKE_TERMERR=true'\nspawn env[13]='MAKE_TERMOUT=true'\nspawn env[14]='MAKEFLAGS='\nspawn env[15]='MAKELEVEL=1'\nspawn env[16]='MFLAGS='\nspawn env[17]='NUMBER_OF_PROCESSORS=4'\nspawn env[18]='OS=Windows_NT'\nspawn env[19]='PATH=C:\\Program Files (x86)\\Parallels\\Parallels Tools\\Applications;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files\\nodejs\\;C:\\Program Files\\Git\\cmd;C:\\Users\\ilg\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\ilg\\AppData\\Roaming\\npm;C:\\Users\\ilg\\AppData\\Local\\Programs\\Microsoft VS Code\\bin'\nspawn env[20]='PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC'\nspawn env[21]='PROCESSOR_ARCHITECTURE=AMD64'\nspawn env[22]='PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 158 Stepping 10, GenuineIntel'\nspawn env[23]='PROCESSOR_LEVEL=6'\nspawn env[24]='PROCESSOR_REVISION=9e0a'\nspawn env[25]='ProgramData=C:\\ProgramData'\nspawn env[26]='ProgramFiles(x86)=C:\\Program Files (x86)'\nspawn env[27]='ProgramFiles=C:\\Program Files'\nspawn env[28]='ProgramW6432=C:\\Program Files'\nspawn env[29]='PROMPT=$P$G'\nspawn env[30]='PSModulePath=C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules'\nspawn env[31]='PUBLIC=C:\\Users\\Public'\nspawn env[32]='SESSIONNAME=Console'\nspawn env[33]='SystemDrive=C:'\nspawn env[34]='SystemRoot=C:\\Windows'\nspawn env[35]='TEMP=C:\\Users\\ilg\\AppData\\Local\\Temp'\nspawn env[36]='TMP=C:\\Users\\ilg\\AppData\\Local\\Temp'\nspawn env[37]='USERDOMAIN_ROAMINGPROFILE=ILG-W11-TEST'\nspawn env[38]='USERDOMAIN=ILG-W11-TEST'\nspawn env[39]='USERNAME=ilg'\nspawn env[40]='USERPROFILE=C:\\Users\\ilg'\nspawn env[41]='windir=C:\\Windows'\nspawn argv[0]='spawn-null'\nspawn argv[1]='-c'\nspawn argv[2]='dump-env three four'\nspawn command 'dump-env.exe'...\n\nDump process environment:\nenvp[0]='ALLUSERSPROFILE=C:\\ProgramData'\nenvp[1]='APPDATA=C:\\Users\\ilg\\AppData\\Roaming'\nenvp[2]='CommonProgramFiles(x86)=C:\\Program Files (x86)\\Common Files'\nenvp[3]='CommonProgramFiles=C:\\Program Files\\Common Files'\nenvp[4]='CommonProgramW6432=C:\\Program Files\\Common Files'\nenvp[5]='COMPUTERNAME=ILG-W11-TEST'\nenvp[6]='ComSpec=C:\\Windows\\system32\\cmd.exe'\nenvp[7]='DriverData=C:\\Windows\\System32\\Drivers\\DriverData'\nenvp[8]='HOMEDRIVE=C:'\nenvp[9]='HOMEPATH=\\Users\\ilg'\nenvp[10]='LOCALAPPDATA=C:\\Users\\ilg\\AppData\\Local'\nenvp[11]='LOGONSERVER=\\\\ILG-W11-TEST'\nenvp[12]='MAKE_TERMERR=true'\nenvp[13]='MAKE_TERMOUT=true'\nenvp[14]='MAKEFLAGS='\nenvp[15]='MAKELEVEL=1'\nenvp[16]='MFLAGS='\nenvp[17]='NUMBER_OF_PROCESSORS=4'\nenvp[18]='OS=Windows_NT'\nenvp[19]='PATH=C:\\Program Files (x86)\\Parallels\\Parallels Tools\\Applications;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files\\nodejs\\;C:\\Program Files\\Git\\cmd;C:\\Users\\ilg\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\ilg\\AppData\\Roaming\\npm;C:\\Users\\ilg\\AppData\\Local\\Programs\\Microsoft VS Code\\bin'\nenvp[20]='PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC'\nenvp[21]='PROCESSOR_ARCHITECTURE=AMD64'\nenvp[22]='PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 158 Stepping 10, GenuineIntel'\nenvp[23]='PROCESSOR_LEVEL=6'\nenvp[24]='PROCESSOR_REVISION=9e0a'\nenvp[25]='ProgramData=C:\\ProgramData'\nenvp[26]='ProgramFiles(x86)=C:\\Program Files (x86)'\nenvp[27]='ProgramFiles=C:\\Program Files'\nenvp[28]='ProgramW6432=C:\\Program Files'\nenvp[29]='PROMPT=$P$G'\nenvp[30]='PSModulePath=C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules'\nenvp[31]='PUBLIC=C:\\Users\\Public'\nenvp[32]='SESSIONNAME=Console'\nenvp[33]='SystemDrive=C:'\nenvp[34]='SystemRoot=C:\\Windows'\nenvp[35]='TEMP=C:\\Users\\ilg\\AppData\\Local\\Temp'\nenvp[36]='TMP=C:\\Users\\ilg\\AppData\\Local\\Temp'\nenvp[37]='USERDOMAIN_ROAMINGPROFILE=ILG-W11-TEST'\nenvp[38]='USERDOMAIN=ILG-W11-TEST'\nenvp[39]='USERNAME=ilg'\nenvp[40]='USERPROFILE=C:\\Users\\ilg'\nenvp[41]='windir=C:\\Windows'\nargv[0]='dump-env'\nargv[1]='three'\nargv[2]='four'\nspawn ret=0 errno=0\n\nC:\\Users\\ilg\\tmp\\ms-spawn-issue\\tests\u003e\n```\n\nThis test, which passes a NULL pointer as environment, passes.\n\nStarting exactly the same command that failed when invoked from make,\nbut this time from a terminal, works as expected:\n\n```doscmd\nC:\\Users\\ilg\\tmp\\ms-spawn-issue\\tests\u003espawn-env -c \"dump-env one two\"\n\nSpawn test:\nspawn env[0]='ALLUSERSPROFILE=C:\\ProgramData'\nspawn env[1]='APPDATA=C:\\Users\\ilg\\AppData\\Roaming'\nspawn env[2]='CommonProgramFiles=C:\\Program Files\\Common Files'\nspawn env[3]='CommonProgramFiles(x86)=C:\\Program Files (x86)\\Common Files'\nspawn env[4]='CommonProgramW6432=C:\\Program Files\\Common Files'\nspawn env[5]='COMPUTERNAME=ILG-W11-TEST'\nspawn env[6]='ComSpec=C:\\Windows\\system32\\cmd.exe'\nspawn env[7]='DriverData=C:\\Windows\\System32\\Drivers\\DriverData'\nspawn env[8]='HOMEDRIVE=C:'\nspawn env[9]='HOMEPATH=\\Users\\ilg'\nspawn env[10]='LOCALAPPDATA=C:\\Users\\ilg\\AppData\\Local'\nspawn env[11]='LOGONSERVER=\\\\ILG-W11-TEST'\nspawn env[12]='NUMBER_OF_PROCESSORS=4'\nspawn env[13]='OS=Windows_NT'\nspawn env[14]='Path=C:\\Program Files (x86)\\Parallels\\Parallels Tools\\Applications;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files\\nodejs\\;C:\\Program Files\\Git\\cmd;C:\\Users\\ilg\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\ilg\\AppData\\Roaming\\npm;C:\\Users\\ilg\\AppData\\Local\\Programs\\Microsoft VS Code\\bin'\nspawn env[15]='PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC'\nspawn env[16]='PROCESSOR_ARCHITECTURE=AMD64'\nspawn env[17]='PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 158 Stepping 10, GenuineIntel'\nspawn env[18]='PROCESSOR_LEVEL=6'\nspawn env[19]='PROCESSOR_REVISION=9e0a'\nspawn env[20]='ProgramData=C:\\ProgramData'\nspawn env[21]='ProgramFiles=C:\\Program Files'\nspawn env[22]='ProgramFiles(x86)=C:\\Program Files (x86)'\nspawn env[23]='ProgramW6432=C:\\Program Files'\nspawn env[24]='PROMPT=$P$G'\nspawn env[25]='PSModulePath=C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules'\nspawn env[26]='PUBLIC=C:\\Users\\Public'\nspawn env[27]='SESSIONNAME=Console'\nspawn env[28]='SystemDrive=C:'\nspawn env[29]='SystemRoot=C:\\Windows'\nspawn env[30]='TEMP=C:\\Users\\ilg\\AppData\\Local\\Temp'\nspawn env[31]='TMP=C:\\Users\\ilg\\AppData\\Local\\Temp'\nspawn env[32]='USERDOMAIN=ILG-W11-TEST'\nspawn env[33]='USERDOMAIN_ROAMINGPROFILE=ILG-W11-TEST'\nspawn env[34]='USERNAME=ilg'\nspawn env[35]='USERPROFILE=C:\\Users\\ilg'\nspawn env[36]='windir=C:\\Windows'\nspawn argv[0]='spawn-env'\nspawn argv[1]='-c'\nspawn argv[2]='dump-env one two'\nspawn command 'dump-env.exe'...\n\nDump process environment:\nenvp[0]='ALLUSERSPROFILE=C:\\ProgramData'\nenvp[1]='APPDATA=C:\\Users\\ilg\\AppData\\Roaming'\nenvp[2]='CommonProgramFiles=C:\\Program Files\\Common Files'\nenvp[3]='CommonProgramFiles(x86)=C:\\Program Files (x86)\\Common Files'\nenvp[4]='CommonProgramW6432=C:\\Program Files\\Common Files'\nenvp[5]='COMPUTERNAME=ILG-W11-TEST'\nenvp[6]='ComSpec=C:\\Windows\\system32\\cmd.exe'\nenvp[7]='DriverData=C:\\Windows\\System32\\Drivers\\DriverData'\nenvp[8]='HOMEDRIVE=C:'\nenvp[9]='HOMEPATH=\\Users\\ilg'\nenvp[10]='LOCALAPPDATA=C:\\Users\\ilg\\AppData\\Local'\nenvp[11]='LOGONSERVER=\\\\ILG-W11-TEST'\nenvp[12]='NUMBER_OF_PROCESSORS=4'\nenvp[13]='OS=Windows_NT'\nenvp[14]='Path=C:\\Program Files (x86)\\Parallels\\Parallels Tools\\Applications;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files\\nodejs\\;C:\\Program Files\\Git\\cmd;C:\\Users\\ilg\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\ilg\\AppData\\Roaming\\npm;C:\\Users\\ilg\\AppData\\Local\\Programs\\Microsoft VS Code\\bin'\nenvp[15]='PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC'\nenvp[16]='PROCESSOR_ARCHITECTURE=AMD64'\nenvp[17]='PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 158 Stepping 10, GenuineIntel'\nenvp[18]='PROCESSOR_LEVEL=6'\nenvp[19]='PROCESSOR_REVISION=9e0a'\nenvp[20]='ProgramData=C:\\ProgramData'\nenvp[21]='ProgramFiles=C:\\Program Files'\nenvp[22]='ProgramFiles(x86)=C:\\Program Files (x86)'\nenvp[23]='ProgramW6432=C:\\Program Files'\nenvp[24]='PROMPT=$P$G'\nenvp[25]='PSModulePath=C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules'\nenvp[26]='PUBLIC=C:\\Users\\Public'\nenvp[27]='SESSIONNAME=Console'\nenvp[28]='SystemDrive=C:'\nenvp[29]='SystemRoot=C:\\Windows'\nenvp[30]='TEMP=C:\\Users\\ilg\\AppData\\Local\\Temp'\nenvp[31]='TMP=C:\\Users\\ilg\\AppData\\Local\\Temp'\nenvp[32]='USERDOMAIN=ILG-W11-TEST'\nenvp[33]='USERDOMAIN_ROAMINGPROFILE=ILG-W11-TEST'\nenvp[34]='USERNAME=ilg'\nenvp[35]='USERPROFILE=C:\\Users\\ilg'\nenvp[36]='windir=C:\\Windows'\nargv[0]='dump-env'\nargv[1]='one'\nargv[2]='two'\nspawn ret=0 errno=0\n\nC:\\Users\\ilg\\tmp\\ms-spawn-issue\\tests\u003e\n```\n\n### Run the `ninja` test\n\nA similar test can be performed with the Ninja Build system instead of\nGNU make.\n\nThe commands are similar:\n\n```doscmd\nC:\\Users\\ilg\\tmp\\ms-spawn-issue\\tests\u003eninja\n[1/1] spawn-env -c \"dump-env one two\"\n\nDump process environment:\nenvp[0]='ALLUSERSPROFILE=C:\\ProgramData'\nenvp[1]='APPDATA=C:\\Users\\ilg\\AppData\\Roaming'\n...\nenvp[35]='USERPROFILE=C:\\Users\\ilg'\nenvp[36]='windir=C:\\Windows'\nargv[0]='dump-env'\nargv[1]='one'\nargv[2]='two'\n\nSpawn test:\nspawn env[0]='ALLUSERSPROFILE=C:\\ProgramData'\nspawn env[1]='APPDATA=C:\\Users\\ilg\\AppData\\Roaming'\n...\nspawn env[35]='USERPROFILE=C:\\Users\\ilg'\nspawn env[36]='windir=C:\\Windows'\nspawn argv[0]='spawn-env'\nspawn argv[1]='-c'\nspawn argv[2]='dump-env one two'\nspawn command 'dump-env.exe'...\nspawn ret=0 errno=0\n\nC:\\Users\\ilg\\tmp\\ms-spawn-issue\\tests\u003eninja null\n[1/1] spawn-null -c \"dump-env three four\"\n\nDump process environment:\nenvp[0]='ALLUSERSPROFILE=C:\\ProgramData'\nenvp[1]='APPDATA=C:\\Users\\ilg\\AppData\\Roaming'\n...\nenvp[35]='USERPROFILE=C:\\Users\\ilg'\nenvp[36]='windir=C:\\Windows'\nargv[0]='dump-env'\nargv[1]='three'\nargv[2]='four'\n\nSpawn test:\nspawn env[0]='ALLUSERSPROFILE=C:\\ProgramData'\nspawn env[1]='APPDATA=C:\\Users\\ilg\\AppData\\Roaming'\n...\nspawn env[35]='USERPROFILE=C:\\Users\\ilg'\nspawn env[36]='windir=C:\\Windows'\nspawn argv[0]='spawn-null'\nspawn argv[1]='-c'\nspawn argv[2]='dump-env three four'\nspawn command 'dump-env.exe'...\nspawn ret=0 errno=0\n\nC:\\Users\\ilg\\tmp\\ms-spawn-issue\\tests\u003e\n```\n\nAs it can be seen, both tests pass, so the problem is specific to `make.exe`;\nthe method used by Ninja to\ncreate sub-processes is probably different and does not trigger the bug,\nso projects using `ninja.exe` are not affected.\n\nNote: At first sight, the output seems out of order, but in fact it\nis even more ordered than for `make.exe`, since it shows the output\nin dependency order, after each command completes.\n\n## Source files\n\nBoth tests are based on the same source code (`sources/spawn/spawn.c`),\nthe first compiled to\nforward the environment to the child process, then compiled to pass a NULL\npointer as environment, which is a shortcut to inherit the entire environment.\n\nThe `spawn-env.exe` and `spawn-null.exe` binaries were compiled with\nVisual Studio 2022 on a Windows 11 machine, but with Platform Tools v142 and\nthe Windows 10 SDK, so the build should also be possible with Visual\nStudio 2019 on Windows 10.\n\nThe VS solution (`sources/projects.sln`) and the project files are included.\n\n## Conclusion\n\nThe current theory is that when Microsoft migrated from MSVCRT to UCRT\nthey changed the implementation and introduced a subtle bug that does not\nshow in the common use case.\n\nHowever, `make.exe` uses an elaborate mechanism to create sub-processes, and\nthe context of the process running the `spawn-*.exe` is somehow different; this\ndifference triggers the bug when this process tries to spawn a new process\nwith an explicit environment.\n\n## Suggestions\n\nThe issue is quite tricky, and it involves three parties, GNU make,\nBusyBox and Microsoft. At any point, each party may try to shift the\nblame to the other, but in fact all three should improve their code:\n\n- **GNU make** should rewrite the code which creates sub-processes to run\n  with the current Windows and BusyBox; Ninja Build can be a source of\n  inspiration, since their code seems ok\n- **BusyBox** should not rely on the unreliable `spawnve()` available in\n  the new Windows releases, and reimplement it with a code that is\n  functional with the current make and Windows\n- **Microsoft** should fix their `spawnve()` code and prevent it from\n  crashing when BusyBox is invoked from `make`\n\n## Bug reports\n\nThe following tickets were opened:\n\n- \u003chttps://github.com/rmyorston/busybox-w32/issues/234\u003e\n- \u003chttps://savannah.gnu.org/bugs/index.php?61409\u003e\n\n## Contributions\n\nAll contributions to clarify this issue will be highly appreciated.\n\nPlease use the GitHub\n[Issues](https://github.com/xpack-dev-tools/ms-spawn-issue/issues)\nto post your findings.\n\nThank you,\n\nLiviu\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxpack-dev-tools%2Fms-spawn-issue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxpack-dev-tools%2Fms-spawn-issue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxpack-dev-tools%2Fms-spawn-issue/lists"}