Skip to content

Commit

Permalink
AArch64: Check if we launched with FD argument
Browse files Browse the repository at this point in the history
This will give us another way to check if the interpreter is installed rather than file checks.
The binfmt_misc files won't exist inside of a rootfs
  • Loading branch information
Sonicadvance1 committed Aug 3, 2021
1 parent c49fa5a commit 83bdbc8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Source/Tests/FEXLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ desc: Glues the ELF loader, FEXCore and LinuxSyscalls to launch an elf under fex
namespace {
static bool SilentLog;
static int OutputFD {STDERR_FILENO};
static bool ExecutedWithFD {false};

void MsgHandler(LogMan::DebugLevels Level, char const *Message) {
const char *CharLevel{nullptr};
Expand Down Expand Up @@ -163,8 +164,10 @@ bool RanAsInterpreter(char *Program) {

bool IsInterpreterInstalled() {
// The interpreter is installed if both the binfmt_misc handlers are available
return std::filesystem::exists("/proc/sys/fs/binfmt_misc/FEX-x86") &&
std::filesystem::exists("/proc/sys/fs/binfmt_misc/FEX-x86_64");
// Or if we were originally executed with FD. Which means the interpreter is installed
return ExecutedWithFD ||
(std::filesystem::exists("/proc/sys/fs/binfmt_misc/FEX-x86") &&
std::filesystem::exists("/proc/sys/fs/binfmt_misc/FEX-x86_64"));
}

void AOTGenSection(FEXCore::Context::Context *CTX, ELFCodeLoader2::LoadedSection &Section) {
Expand Down Expand Up @@ -317,6 +320,9 @@ void AOTGenSection(FEXCore::Context::Context *CTX, ELFCodeLoader2::LoadedSection

int main(int argc, char **argv, char **const envp) {
bool IsInterpreter = RanAsInterpreter(argv[0]);

ExecutedWithFD = getauxval(AT_EXECFD) != 0;

LogMan::Throw::InstallHandler(AssertHandler);
LogMan::Msg::InstallHandler(MsgHandler);

Expand Down

0 comments on commit 83bdbc8

Please sign in to comment.