Skip to content

Make GetProgramExecutableName reliable on X86_64 XNU (macOS) assimilated binaries #1169

Open
@mrdomino

Description

@mrdomino

Writing a somewhat long-ish description in the hopes that this might make a good starter bug for somebody who is not scared of a little assembly.

XNU doesn't do auxv the way other platforms do; instead, it has a sort of addendum to envp, i.e. more env-style key-value pairs after the sentinel NULL at the end of envp. The (generally?) first of these begins executable_path= and contains the path of the running binary.

If we are running assimilated on x86_64 XNU, that value is the only reliable way we have of locating the path of the running binary for use in GetProgramExecutableName (and hence the ZipOS /zip filesystem.)

In libc/crt/crt.S, the pseudo-auxv is currently zeroed out:

cosmopolitan/libc/crt/crt.S

Lines 104 to 111 in 06d916b

#if SupportsXnu()
// xnu doesn't have auxiliary values
testb IsXnu()
jz 1f // polyfill xnu auxv
push $0 // auxv[1][1]=0
push $0 // auxv[1][0]=0
mov %rsp,%rcx // auxv
#endif

It would be good if the executable path were stored in __program_executable_name prior to this happening, if we are running assimilated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions