From 8bee58e4c32a1962ae0107fc3db6bafb4ba3f20a Mon Sep 17 00:00:00 2001 From: Alexander Graf Date: Thu, 2 Feb 2012 18:02:33 +0100 Subject: [PATCH] linux-user: binfmt: support host binaries When we have a working host binary equivalent for the guest binary we're trying to run, let's just use that instead as it will be a lot faster. Signed-off-by: Alexander Graf --- linux-user/binfmt.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/linux-user/binfmt.c b/linux-user/binfmt.c index cd1f513..8c294da 100644 --- a/linux-user/binfmt.c +++ b/linux-user/binfmt.c @@ -5,6 +5,10 @@ #include #include +#define GNEMUL_PATH "/usr/bin/gnemul/qemu-" +#ifdef __x86_64__ +#define ARCH_NAME "x86_64" +#endif int main(int argc, char **argv, char **envp) { @@ -25,6 +29,21 @@ int main(int argc, char **argv, char **envp) exit(1); } +#ifdef ARCH_NAME + { + char *hostbin; + hostbin = malloc(strlen(argv[1] + strlen(GNEMUL_PATH) + 1)); + sprintf(hostbin, GNEMUL_PATH ARCH_NAME "%s", argv[1]); + if (!access(hostbin, X_OK)) { + /* + * We found a host binary replacement for the non-host binary. Let's + * use that instead! + */ + return execve(hostbin, &argv[2], envp); + } + } +#endif + binfmt[0] = '\0'; /* Now argv[0] is the real qemu binary name */ -- 1.6.0.2