linkerexec

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 10 Imported by: 0

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

func CommandContext(ctx context.Context, name string, args ...string) *exec.Cmd

CommandContext is exec.CommandContext for a command that starts through the linker when the running process needs it.

func Executable

func Executable() (string, error)

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 Prepare

func Prepare(cmd *exec.Cmd)

Prepare makes cmd start through the linker when the running process needs it.

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 Current

func Current() Starter

Current returns the Starter for the running process.

func (Starter) Active

func (s Starter) Active() bool

Active reports whether programs below the data directory start through the linker.

func (Starter) Prepare

func (s Starter) Prepare(cmd *exec.Cmd)

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.

func (Starter) Resolve

func (s Starter) Resolve(path string, args []string) (string, []string, error)

Resolve returns the program and argument vector (argv[0] first) that start the program at path with args, which hold argv[0] first. A program that the kernel can start directly comes back unchanged.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL