2017-10-04 00:19:51 +02:00
|
|
|
From 8bcafa995d4d2b4a29135a6cdfffc58d13480ddb Mon Sep 17 00:00:00 2001
|
2012-02-02 18:07:17 +01:00
|
|
|
From: Alexander Graf <agraf@suse.de>
|
|
|
|
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 <agraf@suse.de>
|
|
|
|
---
|
2014-08-22 12:38:44 +02:00
|
|
|
linux-user/binfmt.c | 26 ++++++++++++++++++++++++++
|
|
|
|
1 file changed, 26 insertions(+)
|
2012-02-02 18:07:17 +01:00
|
|
|
|
|
|
|
diff --git a/linux-user/binfmt.c b/linux-user/binfmt.c
|
2017-05-05 17:05:43 +02:00
|
|
|
index cd1f513b33..458f136fb4 100644
|
2012-02-02 18:07:17 +01:00
|
|
|
--- a/linux-user/binfmt.c
|
|
|
|
+++ b/linux-user/binfmt.c
|
2012-02-03 14:30:55 +01:00
|
|
|
@@ -5,6 +5,9 @@
|
2012-02-02 18:07:17 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
+#ifdef __x86_64__
|
|
|
|
+#define ARCH_NAME "x86_64"
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
int main(int argc, char **argv, char **envp)
|
|
|
|
{
|
2014-08-22 12:38:44 +02:00
|
|
|
@@ -28,6 +31,29 @@ int main(int argc, char **argv, char **envp)
|
2012-02-03 14:30:55 +01:00
|
|
|
binfmt[0] = '\0';
|
|
|
|
/* Now argv[0] is the real qemu binary name */
|
2012-02-02 18:07:17 +01:00
|
|
|
|
|
|
|
+#ifdef ARCH_NAME
|
|
|
|
+ {
|
|
|
|
+ char *hostbin;
|
2012-02-03 14:30:55 +01:00
|
|
|
+ char *guestarch;
|
2014-08-22 12:38:44 +02:00
|
|
|
+ int r;
|
2012-02-03 14:30:55 +01:00
|
|
|
+
|
|
|
|
+ guestarch = strrchr(argv[0], '-') ;
|
|
|
|
+ if (!guestarch) {
|
|
|
|
+ goto skip;
|
|
|
|
+ }
|
|
|
|
+ guestarch++;
|
2014-08-22 12:38:44 +02:00
|
|
|
+ r = asprintf(&hostbin, "/emul/" ARCH_NAME "-for-%s/%s", guestarch, argv[1]);
|
2016-04-05 15:18:15 +02:00
|
|
|
+ if ((r > 0) && !access(hostbin, X_OK)) {
|
2012-02-02 18:07:17 +01:00
|
|
|
+ /*
|
|
|
|
+ * We found a host binary replacement for the non-host binary. Let's
|
|
|
|
+ * use that instead!
|
|
|
|
+ */
|
|
|
|
+ return execve(hostbin, &argv[2], envp);
|
|
|
|
+ }
|
|
|
|
+ }
|
2012-02-03 14:30:55 +01:00
|
|
|
+skip:
|
2012-02-02 18:07:17 +01:00
|
|
|
+#endif
|
|
|
|
+
|
2012-02-03 14:30:55 +01:00
|
|
|
new_argv = (char **)malloc((argc + 2) * sizeof(*new_argv));
|
|
|
|
if (argc > 3) {
|
|
|
|
memcpy(&new_argv[4], &argv[3], (argc - 3) * sizeof(*new_argv));
|