cosmopolitan/ape
Jōshin 2a3813c6cf
$prog.ape support (#977)
* ape loader: $prog.ape + login shell support

If the ape loader is invoked with `$0 = $prog.ape`, then it searches for
a `$prog` in the same directory as it and loads that. In particular, the
loader searches the `PATH` for an executable named `$prog.ape`, then for
an executable named `$prog` in the same directory. If the former but not
the latter is found, the search terminates with an error.

It also handles the special case of getting started as `-$SHELL`, which
getty uses to indicate that the shell is a login shell. The path is not
searched in this case, and the program location is read straight out of
the `SHELL` variable.

It is now possible to have `/usr/local/bin/zsh.ape` act as a login shell
for a `/usr/local/bin/zsh` αpε, insofar as the program will get started
with the 'correct' args. Unfortunately, many things break if `$0` is not
the actual full path of the executable being run; for example, backspace
does not update the display properly.

To work around the brokenness introduced by not having `$0` be the full
path of the binary, we cut the leading `-` out of `argv[0]` if present.
This gets the loader's behavior with `$prog.ape` up to par, but doesn't
tell login shells that they are login shells.

So we introduce a hack to accomplish that: if ape is run as `-$prog.ape`
and the shell is `$prog`, the binary that is loaded has a `-l` flag put
into its first argument.

As of this commit, αpε binaries can be used as login shells on OSX.

* if islogin, execfn = shell

Prior to this, execfn was not being properly set for login shells that
did not receive `$_`, which was the case for iTerm2 on Mac. There were
no observable consequences of this, but fixing it seems good anyway.

* Fix auxv location calculation

In the non-login-shell case, it was leaving a word of uninitialized
memory at `envp[i] + 1`. This reuses the previous calculation based
on `envp`.
2023-12-03 19:39:32 -08:00
..
public Improve open source compatibility 2022-09-08 03:19:35 -07:00
aarch64.lds Remove IMAGE_BASE_VIRTUAL 2023-09-12 01:21:36 -07:00
ape-m1.c $prog.ape support (#977) 2023-12-03 19:39:32 -08:00
ape.h Mint APE Loader v1.9 2023-11-05 13:11:34 -08:00
ape.internal.h Get aarch64 hello world working 2023-05-10 04:20:47 -07:00
ape.lds Remove IMAGE_BASE_VIRTUAL 2023-09-12 01:21:36 -07:00
ape.S Redesign cosmocc toolchain 2023-11-11 14:18:08 -08:00
apeinstall.sh Redesign cosmocc toolchain 2023-11-11 14:18:08 -08:00
apeuninstall.sh Redesign cosmocc toolchain 2023-11-11 14:18:08 -08:00
blink-linux-aarch64.gz Make blink support conditionally linkable into APE 2023-06-17 07:55:35 -07:00
blink-xnu-aarch64.gz Make blink support conditionally linkable into APE 2023-06-17 07:55:35 -07:00
BUILD.mk Reduce header complexity 2023-11-28 14:39:42 -08:00
idata.internal.h Introduce new linker for fat ape binaries 2023-08-11 04:39:19 -07:00
launch.S Mint APE Loader v1.5 2023-07-26 13:54:49 -07:00
loader-macho.S Mint APE Loader v1.3 2023-07-23 17:08:14 -07:00
loader.c Fix stack alignment and auxv for macho APE loader (#931) 2023-11-05 13:06:10 -08:00
loader.lds Mint APE Loader v1.3 2023-07-23 17:08:14 -07:00
macros.internal.h [metal] Fix bug: do not initialize IDT & TSS if unneeded (#654) 2022-10-10 20:54:46 -07:00
mz.ansi Initial import 2020-06-15 07:18:57 -07:00
notice.inc Initial import 2020-06-15 07:18:57 -07:00
relocations.h Optimize memory layout 2022-09-12 04:26:52 -07:00
sections.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
start.S Fix stack alignment and auxv for macho APE loader (#931) 2023-11-05 13:06:10 -08:00
systemcall.S Mint APE Loader v1.5 2023-07-26 13:54:49 -07:00