[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v3 05/10] linux-user: Implement native-bypass option support
From: |
Yeqi Fu |
Subject: |
[RFC v3 05/10] linux-user: Implement native-bypass option support |
Date: |
Mon, 26 Jun 2023 05:27:02 +0800 |
This commit implements the -native-bypass support in linux-user. The
native_calls_enabled() function can be true only when the
'-native-bypass' option is given.
Signed-off-by: Yeqi Fu <fufuyqqqqqq@gmail.com>
---
linux-user/main.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/linux-user/main.c b/linux-user/main.c
index 5e6b2e1714..98e31c77d5 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -60,6 +60,13 @@
#include "semihosting/semihost.h"
#endif
+#if defined(CONFIG_NATIVE_CALL)
+#include "native/native-defs.h"
+
+static const char *native_lib;
+bool native_bypass_enabled;
+#endif
+
#ifndef AT_FLAGS_PRESERVE_ARGV0
#define AT_FLAGS_PRESERVE_ARGV0_BIT 0
#define AT_FLAGS_PRESERVE_ARGV0 (1 << AT_FLAGS_PRESERVE_ARGV0_BIT)
@@ -125,6 +132,7 @@ static void usage(int exitcode);
static const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX;
const char *qemu_uname_release;
+
#if !defined(TARGET_DEFAULT_STACK_SIZE)
/* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
we allocate a bigger stack. Need a better solution, for example
@@ -293,6 +301,18 @@ static void handle_arg_set_env(const char *arg)
free(r);
}
+#if defined(CONFIG_NATIVE_CALL)
+static void handle_arg_native_bypass(const char *arg)
+{
+ if (access(arg, F_OK) != 0) {
+ fprintf(stderr, "native library %s does not exist\n", arg);
+ exit(EXIT_FAILURE);
+ }
+ native_lib = arg;
+ native_bypass_enabled = true;
+}
+#endif
+
static void handle_arg_unset_env(const char *arg)
{
char *r, *p, *token;
@@ -522,6 +542,10 @@ static const struct qemu_argument arg_table[] = {
"", "Generate a /tmp/perf-${pid}.map file for perf"},
{"jitdump", "QEMU_JITDUMP", false, handle_arg_jitdump,
"", "Generate a jit-${pid}.dump file for perf"},
+#if defined(CONFIG_NATIVE_CALL)
+ {"native-bypass", "QEMU_NATIVE_BYPASS", true, handle_arg_native_bypass,
+ "", "native bypass for library calls in user mode only."},
+#endif
{NULL, NULL, false, NULL, NULL, NULL}
};
@@ -826,6 +850,18 @@ int main(int argc, char **argv, char **envp)
}
}
+#if defined(CONFIG_NATIVE_CALL)
+ /* Set the library for native bypass */
+ if (native_bypass_enabled) {
+ GString *lib = g_string_new(native_lib);
+ lib = g_string_prepend(lib, "LD_PRELOAD=");
+ if (envlist_appendenv(envlist, g_string_free(lib, false), ":") != 0) {
+ fprintf(stderr,
+ "failed to append the native library to environment.\n");
+ exit(EXIT_FAILURE);
+ }
+ }
+#endif
target_environ = envlist_to_environ(envlist, NULL);
envlist_free(envlist);
--
2.34.1
- [RFC v3 00/10] Native Library Calls, Yeqi Fu, 2023/06/25
- [RFC v3 01/10] docs: Add specification for native library calls, Yeqi Fu, 2023/06/25
- [RFC v3 02/10] build: Add configure options for native calls, Yeqi Fu, 2023/06/25
- [RFC v3 03/10] build: Implement libnative library and configure options, Yeqi Fu, 2023/06/25
- [RFC v3 04/10] linux-user: Implement envlist_appendenv, Yeqi Fu, 2023/06/25
- [RFC v3 05/10] linux-user: Implement native-bypass option support,
Yeqi Fu <=
- [RFC v3 06/10] accel/tcg: Add support for native library calls, Yeqi Fu, 2023/06/25
- [RFC v3 07/10] target/i386: Add support for native library calls, Yeqi Fu, 2023/06/25
- [RFC v3 08/10] target/mips: Add support for native library calls, Yeqi Fu, 2023/06/25
- [RFC v3 09/10] target/arm: Add support for native library calls, Yeqi Fu, 2023/06/25
- [RFC v3 10/10] tests/tcg/multiarch: Add nativecalls.c test, Yeqi Fu, 2023/06/25