__program_executable_name is not always mapped when argc == 0

Author: G4ViCreated Aug 28, 2026Updated Aug 28, 2026

When running an APE with the APE loader without any arguments, for example: ./ape.elf - /path/to/ape-program, the program executable path is not always included in cosmopolitan's memory maps (kisdangerous(__program_executable_name) sometimes returns true). This causes the path returned by GetProgramExecutableName() to be un openable, breaking zipos.

The culprit is:

https://github.com/jart/cosmopolitan/blob/5ddb5c2adad79407fb800fce47f389611f90a511/libc/intrin/getmainstack.c#L76-L88

This function determines the top of stack for the mappings. When argc > 0; ./ape.elf - /path/to/ape-program argv0, as argv0 is placed at a higher address than /path/to/ape-program, /path/to/ape-program is included in the stack. When argc == 0, the fallback case uses the end of auxv as the top of the stack. When /path/to/ape-program occurs on a page at a higher address than auxv, it is excluded from the stack mapping.