X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=bsd-user%2Fmain.c;h=a12b4be80f1de18b94c32e721e9a6b1c26405e78;hb=f28a1e4bab4cfdd067bde3d958529575aa8e8f6b;hp=cb5ea402361fbc695b7fc7bc4296fbc5aabd2e47;hpb=362534a643b4a34bcb223996538ce9de5cdab946;p=mirror_qemu.git
diff --git a/bsd-user/main.c b/bsd-user/main.c
index cb5ea40236..a12b4be80f 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -18,16 +18,13 @@
* along with this program; if not, see .
*/
-#include
-#include
+#include "qemu/osdep.h"
#include
#include
-#include "qemu/osdep.h"
-#include "qemu-common.h"
+#include "qemu/help-texts.h"
#include "qemu/units.h"
#include "qemu/accel.h"
-#include "sysemu/tcg.h"
#include "qemu-version.h"
#include
@@ -47,11 +44,12 @@
#include "trace/control.h"
#include "crypto/init.h"
#include "qemu/guest-random.h"
+#include "gdbstub/user.h"
#include "host-os.h"
#include "target_arch_cpu.h"
-int singlestep;
+static bool opt_one_insn_per_tb;
uintptr_t guest_base;
bool have_guest_base;
/*
@@ -70,13 +68,9 @@ bool have_guest_base;
# if HOST_LONG_BITS > TARGET_VIRT_ADDR_SPACE_BITS
# if TARGET_VIRT_ADDR_SPACE_BITS == 32 && \
(TARGET_LONG_BITS == 32 || defined(TARGET_ABI32))
-/*
- * There are a number of places where we assign reserved_va to a variable
- * of type abi_ulong and expect it to fit. Avoid the last page.
- */
-# define MAX_RESERVED_VA (0xfffffffful & TARGET_PAGE_MASK)
+# define MAX_RESERVED_VA 0xfffffffful
# else
-# define MAX_RESERVED_VA (1ul << TARGET_VIRT_ADDR_SPACE_BITS)
+# define MAX_RESERVED_VA ((1ul << TARGET_VIRT_ADDR_SPACE_BITS) - 1)
# endif
# else
# define MAX_RESERVED_VA 0
@@ -94,9 +88,8 @@ unsigned long reserved_va = MAX_RESERVED_VA;
unsigned long reserved_va;
#endif
-static const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX;
+const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX;
const char *qemu_uname_release;
-enum BSDType bsd_type;
char qemu_proc_pathname[PATH_MAX]; /* full path to exeutable */
unsigned long target_maxtsiz = TARGET_MAXTSIZ; /* max text size */
@@ -164,13 +157,13 @@ static void usage(void)
"-E var=value sets/modifies targets environment variable(s)\n"
"-U var unsets targets environment variable(s)\n"
"-B address set guest_base address to address\n"
- "-bsd type select emulated BSD type FreeBSD/NetBSD/OpenBSD (default)\n"
"\n"
"Debug options:\n"
"-d item1[,...] enable logging of specified items\n"
" (use '-d help' for a list of log items)\n"
"-D logfile write logs to 'logfile' (default stderr)\n"
- "-singlestep always run in singlestep mode\n"
+ "-one-insn-per-tb run with one guest instruction per emulated TB\n"
+ "-singlestep deprecated synonym for -one-insn-per-tb\n"
"-strace log system calls\n"
"-trace [[enable=]][,events=][,file=]\n"
" specify tracing options\n"
@@ -215,15 +208,13 @@ void qemu_cpu_kick(CPUState *cpu)
}
/* Assumes contents are already zeroed. */
-void init_task_state(TaskState *ts)
+static void init_task_state(TaskState *ts)
{
- int i;
-
- ts->first_free = ts->sigqueue_table;
- for (i = 0; i < MAX_SIGQUEUE_SIZE - 1; i++) {
- ts->sigqueue_table[i].next = &ts->sigqueue_table[i + 1];
- }
- ts->sigqueue_table[i].next = NULL;
+ ts->sigaltstack_used = (struct target_sigaltstack) {
+ .ss_sp = 0,
+ .ss_size = 0,
+ .ss_flags = TARGET_SS_DISABLE,
+ };
}
void gemu_log(const char *fmt, ...)
@@ -287,7 +278,6 @@ int main(int argc, char **argv)
const char *gdbstub = NULL;
char **target_environ, **wrk;
envlist_t *envlist = NULL;
- bsd_type = HOST_DEFAULT_BSD_TYPE;
char *argv0 = NULL;
adjust_ssize();
@@ -305,8 +295,16 @@ int main(int argc, char **argv)
envlist = envlist_create();
- /* add current environment into the list */
+ /*
+ * add current environment into the list
+ * envlist_setenv adds to the front of the list; to preserve environ
+ * order add from back to front
+ */
for (wrk = environ; *wrk != NULL; wrk++) {
+ continue;
+ }
+ while (wrk != environ) {
+ wrk--;
(void) envlist_setenv(envlist, *wrk);
}
@@ -394,21 +392,10 @@ int main(int argc, char **argv)
have_guest_base = true;
} else if (!strcmp(r, "drop-ld-preload")) {
(void) envlist_unsetenv(envlist, "LD_PRELOAD");
- } else if (!strcmp(r, "bsd")) {
- if (!strcasecmp(argv[optind], "freebsd")) {
- bsd_type = target_freebsd;
- } else if (!strcasecmp(argv[optind], "netbsd")) {
- bsd_type = target_netbsd;
- } else if (!strcasecmp(argv[optind], "openbsd")) {
- bsd_type = target_openbsd;
- } else {
- usage();
- }
- optind++;
} else if (!strcmp(r, "seed")) {
seed_optarg = optarg;
- } else if (!strcmp(r, "singlestep")) {
- singlestep = 1;
+ } else if (!strcmp(r, "singlestep") || !strcmp(r, "one-insn-per-tb")) {
+ opt_one_insn_per_tb = true;
} else if (!strcmp(r, "strace")) {
do_strace = 1;
} else if (!strcmp(r, "trace")) {
@@ -421,17 +408,16 @@ int main(int argc, char **argv)
}
/* init debug */
- qemu_log_needs_buffers();
- qemu_set_log_filename(log_file, &error_fatal);
- if (log_mask) {
- int mask;
-
- mask = qemu_str_to_log_mask(log_mask);
- if (!mask) {
- qemu_print_log_usage(stdout);
- exit(1);
+ {
+ int mask = 0;
+ if (log_mask) {
+ mask = qemu_str_to_log_mask(log_mask);
+ if (!mask) {
+ qemu_print_log_usage(stdout);
+ exit(1);
+ }
}
- qemu_set_log(mask);
+ qemu_set_log_filename_flags(log_file, mask, &error_fatal);
}
if (optind >= argc) {
@@ -467,9 +453,12 @@ int main(int argc, char **argv)
/* init tcg before creating CPUs and to get qemu_host_page_size */
{
- AccelClass *ac = ACCEL_GET_CLASS(current_accel());
+ AccelState *accel = current_accel();
+ AccelClass *ac = ACCEL_GET_CLASS(accel);
accel_init_interfaces(ac);
+ object_property_set_bool(OBJECT(accel), "one-insn-per-tb",
+ opt_one_insn_per_tb, &error_abort);
ac->init_machine(NULL);
}
cpu = cpu_create(cpu_type);
@@ -484,10 +473,6 @@ int main(int argc, char **argv)
target_environ = envlist_to_environ(envlist, NULL);
envlist_free(envlist);
- if (reserved_va) {
- mmap_next_start = reserved_va;
- }
-
{
Error *err = NULL;
if (seed_optarg != NULL) {
@@ -505,7 +490,49 @@ int main(int argc, char **argv)
* Now that page sizes are configured we can do
* proper page alignment for guest_base.
*/
- guest_base = HOST_PAGE_ALIGN(guest_base);
+ if (have_guest_base) {
+ if (guest_base & ~qemu_host_page_mask) {
+ error_report("Selected guest base not host page aligned");
+ exit(1);
+ }
+ }
+
+ /*
+ * If reserving host virtual address space, do so now.
+ * Combined with '-B', ensure that the chosen range is free.
+ */
+ if (reserved_va) {
+ void *p;
+
+ if (have_guest_base) {
+ p = mmap((void *)guest_base, reserved_va + 1, PROT_NONE,
+ MAP_ANON | MAP_PRIVATE | MAP_FIXED | MAP_EXCL, -1, 0);
+ } else {
+ p = mmap(NULL, reserved_va + 1, PROT_NONE,
+ MAP_ANON | MAP_PRIVATE, -1, 0);
+ }
+ if (p == MAP_FAILED) {
+ const char *err = strerror(errno);
+ char *sz = size_to_str(reserved_va + 1);
+
+ if (have_guest_base) {
+ error_report("Cannot allocate %s bytes at -B %p for guest "
+ "address space: %s", sz, (void *)guest_base, err);
+ } else {
+ error_report("Cannot allocate %s bytes for guest "
+ "address space: %s", sz, err);
+ }
+ exit(1);
+ }
+ guest_base = (uintptr_t)p;
+ have_guest_base = true;
+
+ /* Ensure that mmap_next_start is within range. */
+ if (reserved_va <= mmap_next_start) {
+ mmap_next_start = (reserved_va / 4 * 3)
+ & TARGET_PAGE_MASK & qemu_host_page_mask;
+ }
+ }
if (loader_exec(filename, argv + optind, target_environ, regs, info,
&bprm) != 0) {
@@ -520,20 +547,27 @@ int main(int argc, char **argv)
g_free(target_environ);
if (qemu_loglevel_mask(CPU_LOG_PAGE)) {
- qemu_log("guest_base %p\n", (void *)guest_base);
- log_page_dump("binary load");
-
- qemu_log("start_brk 0x" TARGET_ABI_FMT_lx "\n", info->start_brk);
- qemu_log("end_code 0x" TARGET_ABI_FMT_lx "\n", info->end_code);
- qemu_log("start_code 0x" TARGET_ABI_FMT_lx "\n",
- info->start_code);
- qemu_log("start_data 0x" TARGET_ABI_FMT_lx "\n",
- info->start_data);
- qemu_log("end_data 0x" TARGET_ABI_FMT_lx "\n", info->end_data);
- qemu_log("start_stack 0x" TARGET_ABI_FMT_lx "\n",
- info->start_stack);
- qemu_log("brk 0x" TARGET_ABI_FMT_lx "\n", info->brk);
- qemu_log("entry 0x" TARGET_ABI_FMT_lx "\n", info->entry);
+ FILE *f = qemu_log_trylock();
+ if (f) {
+ fprintf(f, "guest_base %p\n", (void *)guest_base);
+ fprintf(f, "page layout changed following binary load\n");
+ page_dump(f);
+
+ fprintf(f, "end_code 0x" TARGET_ABI_FMT_lx "\n",
+ info->end_code);
+ fprintf(f, "start_code 0x" TARGET_ABI_FMT_lx "\n",
+ info->start_code);
+ fprintf(f, "start_data 0x" TARGET_ABI_FMT_lx "\n",
+ info->start_data);
+ fprintf(f, "end_data 0x" TARGET_ABI_FMT_lx "\n",
+ info->end_data);
+ fprintf(f, "start_stack 0x" TARGET_ABI_FMT_lx "\n",
+ info->start_stack);
+ fprintf(f, "brk 0x" TARGET_ABI_FMT_lx "\n", info->brk);
+ fprintf(f, "entry 0x" TARGET_ABI_FMT_lx "\n", info->entry);
+
+ qemu_log_unlock(f);
+ }
}
/* build Task State */