Skip to content

Commit

Permalink
PROOT_UNBUNDLE_LOADER_NAME[_32] macros and a fix of old bad relocatab…
Browse files Browse the repository at this point in the history
…le behavior
  • Loading branch information
green-green-avk committed Oct 18, 2020
1 parent 14cc60e commit 4600c09
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ It is a clone of the Termux version of PRoot with some additional adaptations fo
## Features

* In case of unbundled loader, relocation does not require to set `PROOT_LOADER` / `PROOT_LOADER_32` variables
and these variables can be relative to the `proot` binary location and resolved as `<proot_location>/../$PROOT_LOADER`.
Defaults are `libexec/proot/loader` / `libexec/proot/loader32` respectively.
and these variables can be relative to the `proot` binary location and resolved as `<proot_location>/$PROOT_LOADER`.
Defaults are `../libexec/proot/loader` / `../libexec/proot/loader32` respectively.

* `--tcsetsf2tcsets` option as long as `TCSETSF` is forbidden in Android and substitution with `TCSETS` can be an acceptable workaround.
`tcsetattr(TCSAFLUSH, ...)` => `tcsetattr(TCSANOW, ...)` in other words.
Expand Down
22 changes: 12 additions & 10 deletions src/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
VPATH := $(dir $(lastword $(MAKEFILE_LIST)))
SRC = $(dir $(firstword $(MAKEFILE_LIST)))

# Prefix on the target (relocatable by default)
TARGET_ROOT ?= ..

GIT = git
RM = rm
INSTALL = install
Expand Down Expand Up @@ -100,8 +97,13 @@ endef
$(eval $(call define_from_arch.h,,HAS_LOADER_32BIT))
$(eval $(call define_from_arch.h,,HAS_POKEDATA_WORKAROUND))

PROOT_UNBUNDLE_LOADER_NAME ?= loader
PROOT_UNBUNDLE_LOADER_NAME_32 ?= loader32

ifdef PROOT_UNBUNDLE_LOADER
CFLAGS += "-DPROOT_UNBUNDLE_LOADER=\"$(TARGET_ROOT)/$(PROOT_UNBUNDLE_LOADER)\""
CFLAGS += "-DPROOT_UNBUNDLE_LOADER=\"$(PROOT_UNBUNDLE_LOADER)\"" \
"-DPROOT_UNBUNDLE_LOADER_NAME=\"$(PROOT_UNBUNDLE_LOADER_NAME)\"" \
"-DPROOT_UNBUNDLE_LOADER_NAME_32=\"$(PROOT_UNBUNDLE_LOADER_NAME_32)\""
proot: | loader/loader
ifdef HAS_LOADER_32BIT
proot: | loader/loader-m32
Expand Down Expand Up @@ -258,24 +260,24 @@ DEPS = $(OBJECTS:.o=.d) $(LOADER_OBJECTS:.o=.d) $(LOADER-m32_OBJECTS:.o=.d) $(CH
# PHONY targets

PREFIX ?= /usr/local
DESTDIR = $(PREFIX)/bin
LOADERDIR = $(PREFIX)/$(PROOT_UNBUNDLE_LOADER)
BINDIR ?= $(PREFIX)/bin
LOADERDIR ?= $(BINDIR)/$(PROOT_UNBUNDLE_LOADER)

.PHONY: clean distclean install uninstall
clean distclean:
-$(RM) -f $(CHECK_OBJECTS) $(CHECK_PROGRAMS) $(CHECK_RESULTS) $(OBJECTS) $(LOADER_OBJECTS) $(LOADER-m32_OBJECTS) proot loader/loader loader/loader-m32 loader/loader-info.{c,d,o} $(DEPS) build.h licenses

install: proot
$($(quiet)INSTALL) -D $< $(DESTDIR)/$<
$($(quiet)INSTALL) -D $< $(BINDIR)/$<
ifdef PROOT_UNBUNDLE_LOADER
$(INSTALL) -D loader/loader $(LOADERDIR)/loader
$(INSTALL) -D loader/loader $(LOADERDIR)/$(PROOT_UNBUNDLE_LOADER_NAME)
ifdef HAS_LOADER_32BIT
$(INSTALL) -D loader/loader-m32 $(LOADERDIR)/loader32
$(INSTALL) -D loader/loader-m32 $(LOADERDIR)/$(PROOT_UNBUNDLE_LOADER_NAME_32)
endif
endif

uninstall:
-$(RM) -f $(DESTDIR)/proot
-$(RM) -f $(BINDIR)/proot
ifdef PROOT_UNBUNDLE_LOADER
$(INSTALL) -D loader/loader $(LOADERDIR)/loader
$(INSTALL) -D loader/loader-m32 $(LOADERDIR)/loader32
Expand Down
14 changes: 12 additions & 2 deletions src/execve/enter.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,12 +576,22 @@ static inline const char *resolve_path(const char *const path)
static inline const char *get_loader_path(const Tracee *tracee)
{
#if defined(PROOT_UNBUNDLE_LOADER)

#ifndef PROOT_UNBUNDLE_LOADER_NAME
#define PROOT_UNBUNDLE_LOADER_NAME "loader"
#endif

#if defined(HAS_LOADER_32BIT)

#ifndef PROOT_UNBUNDLE_LOADER_NAME_32
#define PROOT_UNBUNDLE_LOADER_NAME_32 "loader32"
#endif

if (IS_CLASS32(tracee->load_info->elf_header)) {
return resolve_path(getenv("PROOT_LOADER_32") ?: PROOT_UNBUNDLE_LOADER "/loader32");
return resolve_path(getenv("PROOT_LOADER_32") ?: PROOT_UNBUNDLE_LOADER "/" PROOT_UNBUNDLE_LOADER_NAME_32);
}
#endif
return resolve_path(getenv("PROOT_LOADER") ?: PROOT_UNBUNDLE_LOADER "/loader");
return resolve_path(getenv("PROOT_LOADER") ?: PROOT_UNBUNDLE_LOADER "/" PROOT_UNBUNDLE_LOADER_NAME);
#else
static char *loader_path = NULL;

Expand Down

0 comments on commit 4600c09

Please sign in to comment.