Documentation
¶
Overview ¶
Package linkerexec starts programs on Android builds that forbid executing files in an app's data directory.
Termux from Google Play cannot execve its own binaries: Android's SELinux policy blocks the execution of an app data file. Termux works around it with termux-exec, an LD_PRELOAD library that rewrites a libc execve into "/system/bin/linker64 <program> <args>", where the linker maps a PIE executable itself. PiG's Go runtime issues the execve system call without libc, so the library never sees it; this package makes the same rewrite before os/exec starts a program. The rewrite also covers a script: the kernel cannot run its "#!" line either, so the script starts through its interpreter, with the interpreter paths /bin and /usr/bin that Android lacks mapped to $PREFIX/bin as termux-exec maps them.
A process the linker started has the linker as /proc/self/exe, so Executable replaces os.Executable.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommandContext ¶
CommandContext is exec.CommandContext for a command that starts through the linker when the running process needs it.
func Executable ¶
Executable returns the path of the running program, as os.Executable does. A process the linker started has the linker as /proc/self/exe, so the program is the one termux-exec records in TERMUX_EXEC__PROC_SELF_EXE, or argv[0] when the linker made it absolute.
func SetStarterForTest ¶
func SetStarterForTest(s Starter) (restore func())
SetStarterForTest makes s the running process's Starter until the returned function runs. It is not safe for concurrent use.
Types ¶
type Starter ¶
type Starter struct {
// Linker is the system linker that maps a PIE executable, such as
// /system/bin/linker64. It is empty when programs start directly.
Linker string
// DataDir is the app data directory. Only a program below it needs the
// linker; a system program such as /system/bin/sh starts directly.
DataDir string
// Prefix is Termux's $PREFIX, the home of the interpreters a script's
// "#!/usr/bin/env" or "#!/bin/sh" line names.
Prefix string
// ReadHead returns the first bytes of the file at path.
ReadHead func(path string) ([]byte, error)
// LookPath finds a command in the PATH of the program being started.
LookPath func(name string) (string, error)
}
Starter rewrites program starts for one Android environment. The zero value rewrites nothing.
func (Starter) Active ¶
Active reports whether programs below the data directory start through the linker.
func (Starter) Prepare ¶
Prepare makes cmd start through the linker when s requires it. It returns without a change for an Err already set or a program that starts directly.