| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-08-05 17:52:01 -06:00
										 |  |  |  *  qemu bsd user main | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  *  Copyright (c) 2003-2008 Fabrice Bellard | 
					
						
							| 
									
										
										
										
											2021-08-05 17:52:01 -06:00
										 |  |  |  *  Copyright (c) 2013-14 Stacey Son | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  *  This program is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  |  *  it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |  *  the Free Software Foundation; either version 2 of the License, or | 
					
						
							|  |  |  |  *  (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  *  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  *  GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  You should have received a copy of the GNU General Public License | 
					
						
							| 
									
										
										
										
											2009-07-16 20:47:01 +00:00
										 |  |  |  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-05-23 16:35:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-02 14:38:15 +01:00
										 |  |  | #include "qemu/osdep.h"
 | 
					
						
							| 
									
										
										
										
											2021-08-06 18:48:37 -06:00
										 |  |  | #include <sys/resource.h>
 | 
					
						
							|  |  |  | #include <sys/sysctl.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-20 17:25:49 +04:00
										 |  |  | #include "qemu/help-texts.h"
 | 
					
						
							| 
									
										
										
										
											2018-06-25 09:42:38 -03:00
										 |  |  | #include "qemu/units.h"
 | 
					
						
							| 
									
										
										
										
											2021-02-04 17:39:24 +01:00
										 |  |  | #include "qemu/accel.h"
 | 
					
						
							| 
									
										
										
										
											2016-08-22 10:57:13 -04:00
										 |  |  | #include "qemu-version.h"
 | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | #include <machine/trap.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-15 19:27:16 +02:00
										 |  |  | #include "qapi/error.h"
 | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | #include "qemu.h"
 | 
					
						
							| 
									
										
										
										
											2016-07-15 19:08:43 +02:00
										 |  |  | #include "qemu/config-file.h"
 | 
					
						
							| 
									
										
											  
											
												log: Make glib logging go through QEMU
This commit adds a error_init() helper which calls
g_log_set_default_handler() so that glib logs (g_log, g_warning, ...)
are handled similarly to other QEMU logs. This means they will get a
timestamp if timestamps are enabled, and they will go through the
HMP monitor if one is configured.
This commit also adds a call to error_init() to the binaries
installed by QEMU. Since error_init() also calls error_set_progname(),
this means that *-linux-user, *-bsd-user and qemu-pr-helper messages
output with error_report, info_report, ... will slightly change: they
will be prefixed by the binary name.
glib debug messages are enabled through G_MESSAGES_DEBUG similarly to
the glib default log handler.
At the moment, this change will mostly impact SPICE logging if your
spice version is >= 0.14.1. With older spice versions, this is not going
to work as expected, but will not have any ill effect, so this call is
not conditional on the SPICE version.
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20190131164614.19209-3-cfergeau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
											
										 
											2019-01-31 17:46:14 +01:00
										 |  |  | #include "qemu/error-report.h"
 | 
					
						
							| 
									
										
										
										
											2016-03-20 19:16:19 +02:00
										 |  |  | #include "qemu/path.h"
 | 
					
						
							|  |  |  | #include "qemu/help_option.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-23 16:35:07 +02:00
										 |  |  | #include "qemu/module.h"
 | 
					
						
							| 
									
										
										
										
											2016-03-15 13:18:37 +01:00
										 |  |  | #include "exec/exec-all.h"
 | 
					
						
							| 
									
										
										
										
											2020-01-01 12:23:00 +01:00
										 |  |  | #include "tcg/tcg.h"
 | 
					
						
							| 
									
										
										
										
											2012-12-17 18:20:00 +01:00
										 |  |  | #include "qemu/timer.h"
 | 
					
						
							|  |  |  | #include "qemu/envlist.h"
 | 
					
						
							| 
									
										
										
										
											2021-04-23 11:00:34 -06:00
										 |  |  | #include "qemu/cutils.h"
 | 
					
						
							| 
									
										
										
										
											2016-01-07 16:55:28 +03:00
										 |  |  | #include "exec/log.h"
 | 
					
						
							| 
									
										
										
										
											2016-07-15 19:08:43 +02:00
										 |  |  | #include "trace/control.h"
 | 
					
						
							| 
									
										
										
										
											2021-09-02 16:52:45 -06:00
										 |  |  | #include "crypto/init.h"
 | 
					
						
							|  |  |  | #include "qemu/guest-random.h"
 | 
					
						
							| 
									
										
										
										
											2023-03-02 18:57:47 -08:00
										 |  |  | #include "gdbstub/user.h"
 | 
					
						
							| 
									
										
										
										
											2009-08-15 10:35:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-27 11:28:16 -06:00
										 |  |  | #include "host-os.h"
 | 
					
						
							| 
									
										
										
										
											2021-08-03 19:05:40 -06:00
										 |  |  | #include "target_arch_cpu.h"
 | 
					
						
							| 
									
										
										
										
											2021-08-27 11:28:16 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-17 17:40:32 +01:00
										 |  |  | static bool opt_one_insn_per_tb; | 
					
						
							| 
									
										
										
										
											2021-02-12 10:48:34 -08:00
										 |  |  | uintptr_t guest_base; | 
					
						
							| 
									
										
										
										
											2020-05-13 18:51:29 +01:00
										 |  |  | bool have_guest_base; | 
					
						
							| 
									
										
										
										
											2021-08-05 18:15:47 -06:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * When running 32-on-64 we should make sure we can fit all of the possible | 
					
						
							|  |  |  |  * guest address space into a contiguous chunk of virtual host memory. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This way we will never overlap with our own libraries or binaries or stack | 
					
						
							|  |  |  |  * or anything else that QEMU maps. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Many cpus reserve the high bit (or more than one for some 64-bit cpus) | 
					
						
							|  |  |  |  * of the address for the kernel.  Some cpus rely on this and user space | 
					
						
							|  |  |  |  * uses the high bit(s) for pointer tagging and the like.  For them, we | 
					
						
							|  |  |  |  * must preserve the expected address space. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #ifndef MAX_RESERVED_VA
 | 
					
						
							|  |  |  | # if HOST_LONG_BITS > TARGET_VIRT_ADDR_SPACE_BITS
 | 
					
						
							|  |  |  | #  if TARGET_VIRT_ADDR_SPACE_BITS == 32 && \
 | 
					
						
							|  |  |  |       (TARGET_LONG_BITS == 32 || defined(TARGET_ABI32)) | 
					
						
							| 
									
										
										
										
											2023-03-06 01:26:29 +03:00
										 |  |  | #   define MAX_RESERVED_VA  0xfffffffful
 | 
					
						
							| 
									
										
										
										
											2021-08-05 18:15:47 -06:00
										 |  |  | #  else
 | 
					
						
							| 
									
										
										
										
											2023-03-06 01:26:29 +03:00
										 |  |  | #   define MAX_RESERVED_VA  ((1ul << TARGET_VIRT_ADDR_SPACE_BITS) - 1)
 | 
					
						
							| 
									
										
										
										
											2021-08-05 18:15:47 -06:00
										 |  |  | #  endif
 | 
					
						
							|  |  |  | # else
 | 
					
						
							|  |  |  | #  define MAX_RESERVED_VA  0
 | 
					
						
							|  |  |  | # endif
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * That said, reserving *too* much vm space via mmap can run into problems | 
					
						
							|  |  |  |  * with rlimits, oom due to page table creation, etc.  We will still try it, | 
					
						
							|  |  |  |  * if directed by the command-line option, but not by default. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #if HOST_LONG_BITS == 64 && TARGET_VIRT_ADDR_SPACE_BITS <= 32
 | 
					
						
							|  |  |  | unsigned long reserved_va = MAX_RESERVED_VA; | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2012-04-12 12:43:41 +01:00
										 |  |  | unsigned long reserved_va; | 
					
						
							| 
									
										
										
										
											2021-08-05 18:15:47 -06:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-04-05 20:08:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-26 16:08:22 +02:00
										 |  |  | static const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX; | 
					
						
							| 
									
										
										
										
											2014-05-09 16:06:41 +01:00
										 |  |  | const char *qemu_uname_release; | 
					
						
							| 
									
										
										
										
											2021-08-03 13:39:31 -06:00
										 |  |  | char qemu_proc_pathname[PATH_MAX];  /* full path to exeutable */ | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-06 18:48:37 -06:00
										 |  |  | unsigned long target_maxtsiz = TARGET_MAXTSIZ;   /* max text size */ | 
					
						
							|  |  |  | unsigned long target_dfldsiz = TARGET_DFLDSIZ;   /* initial data size limit */ | 
					
						
							|  |  |  | unsigned long target_maxdsiz = TARGET_MAXDSIZ;   /* max data size */ | 
					
						
							|  |  |  | unsigned long target_dflssiz = TARGET_DFLSSIZ;   /* initial data size limit */ | 
					
						
							|  |  |  | unsigned long target_maxssiz = TARGET_MAXSSIZ;   /* max stack size */ | 
					
						
							|  |  |  | unsigned long target_sgrowsiz = TARGET_SGROWSIZ; /* amount to grow stack */ | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-07 14:22:34 -06:00
										 |  |  | /* Helper routines for implementing atomic operations. */ | 
					
						
							| 
									
										
										
										
											2009-03-07 18:59:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void fork_start(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-08-07 14:22:34 -06:00
										 |  |  |     start_exclusive(); | 
					
						
							|  |  |  |     cpu_list_lock(); | 
					
						
							|  |  |  |     mmap_fork_start(); | 
					
						
							| 
									
										
										
										
											2009-03-07 18:59:05 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void fork_end(int child) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (child) { | 
					
						
							| 
									
										
										
										
											2021-08-07 14:22:34 -06:00
										 |  |  |         CPUState *cpu, *next_cpu; | 
					
						
							|  |  |  |         /*
 | 
					
						
							|  |  |  |          * Child processes created by fork() only have a single thread.  Discard | 
					
						
							|  |  |  |          * information about the parent threads. | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         CPU_FOREACH_SAFE(cpu, next_cpu) { | 
					
						
							|  |  |  |             if (cpu != thread_cpu) { | 
					
						
							|  |  |  |                 QTAILQ_REMOVE_RCU(&cpus, cpu, node); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         mmap_fork_end(child); | 
					
						
							|  |  |  |         /*
 | 
					
						
							|  |  |  |          * qemu_init_cpu_list() takes care of reinitializing the exclusive | 
					
						
							|  |  |  |          * state, so we don't need to end_exclusive() here. | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         qemu_init_cpu_list(); | 
					
						
							| 
									
										
										
										
											2015-06-23 19:31:16 -07:00
										 |  |  |         gdbserver_fork(thread_cpu); | 
					
						
							| 
									
										
										
										
											2021-08-07 14:22:34 -06:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         mmap_fork_end(child); | 
					
						
							|  |  |  |         cpu_list_unlock(); | 
					
						
							|  |  |  |         end_exclusive(); | 
					
						
							| 
									
										
										
										
											2009-03-07 18:59:05 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-03 19:05:40 -06:00
										 |  |  | void cpu_loop(CPUArchState *env) | 
					
						
							| 
									
										
										
										
											2009-04-11 11:09:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-08-03 19:05:40 -06:00
										 |  |  |     target_cpu_loop(env); | 
					
						
							| 
									
										
										
										
											2009-04-11 11:09:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | static void usage(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-15 12:06:47 +01:00
										 |  |  |     printf("qemu-" TARGET_NAME " version " QEMU_FULL_VERSION | 
					
						
							| 
									
										
										
										
											2016-10-05 11:54:44 +02:00
										 |  |  |            "\n" QEMU_COPYRIGHT "\n" | 
					
						
							| 
									
										
										
										
											2013-06-04 14:45:27 +02:00
										 |  |  |            "usage: qemu-" TARGET_NAME " [options] program [arguments...]\n" | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |            "BSD CPU emulator (compiled for %s emulation)\n" | 
					
						
							|  |  |  |            "\n" | 
					
						
							|  |  |  |            "Standard options:\n" | 
					
						
							|  |  |  |            "-h                print this help\n" | 
					
						
							|  |  |  |            "-g port           wait gdb connection to port\n" | 
					
						
							|  |  |  |            "-L path           set the elf interpreter prefix (default=%s)\n" | 
					
						
							|  |  |  |            "-s size           set the stack size in bytes (default=%ld)\n" | 
					
						
							| 
									
										
										
										
											2012-08-02 13:45:54 +01:00
										 |  |  |            "-cpu model        select CPU (-cpu help for list)\n" | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |            "-drop-ld-preload  drop LD_PRELOAD for target process\n" | 
					
						
							| 
									
										
										
										
											2009-08-15 10:35:42 +00:00
										 |  |  |            "-E var=value      sets/modifies targets environment variable(s)\n" | 
					
						
							|  |  |  |            "-U var            unsets targets environment variable(s)\n" | 
					
						
							| 
									
										
										
										
											2009-09-27 19:30:51 +00:00
										 |  |  |            "-B address        set guest_base address to address\n" | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |            "\n" | 
					
						
							|  |  |  |            "Debug options:\n" | 
					
						
							| 
									
										
										
										
											2013-02-26 17:52:40 +00:00
										 |  |  |            "-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" | 
					
						
							| 
									
										
										
										
											2023-04-17 17:40:36 +01:00
										 |  |  |            "-one-insn-per-tb  run with one guest instruction per emulated TB\n" | 
					
						
							|  |  |  |            "-singlestep       deprecated synonym for -one-insn-per-tb\n" | 
					
						
							| 
									
										
										
										
											2013-02-26 17:52:40 +00:00
										 |  |  |            "-strace           log system calls\n" | 
					
						
							| 
									
										
										
										
											2016-07-15 19:08:43 +02:00
										 |  |  |            "-trace            [[enable=]<pattern>][,events=<file>][,file=<file>]\n" | 
					
						
							|  |  |  |            "                  specify tracing options\n" | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |            "\n" | 
					
						
							|  |  |  |            "Environment variables:\n" | 
					
						
							|  |  |  |            "QEMU_STRACE       Print system calls and arguments similar to the\n" | 
					
						
							|  |  |  |            "                  'strace' program.  Enable by setting to any value.\n" | 
					
						
							| 
									
										
										
										
											2009-08-15 10:35:42 +00:00
										 |  |  |            "You can use -E and -U options to set/unset environment variables\n" | 
					
						
							|  |  |  |            "for target process.  It is possible to provide several variables\n" | 
					
						
							|  |  |  |            "by repeating the option.  For example:\n" | 
					
						
							|  |  |  |            "    -E var1=val2 -E var2=val2 -U LD_PRELOAD -U LD_DEBUG\n" | 
					
						
							|  |  |  |            "Note that if you provide several changes to single variable\n" | 
					
						
							|  |  |  |            "last change will stay in effect.\n" | 
					
						
							| 
									
										
										
										
											2017-08-03 11:33:53 -05:00
										 |  |  |            "\n" | 
					
						
							|  |  |  |            QEMU_HELP_BOTTOM "\n" | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |            , | 
					
						
							| 
									
										
										
										
											2013-06-04 14:45:27 +02:00
										 |  |  |            TARGET_NAME, | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |            interp_prefix, | 
					
						
							| 
									
										
										
										
											2021-08-06 18:48:37 -06:00
										 |  |  |            target_dflssiz); | 
					
						
							| 
									
										
										
										
											2009-02-28 20:14:00 +00:00
										 |  |  |     exit(1); | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-03 12:34:52 -06:00
										 |  |  | __thread CPUState *thread_cpu; | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-19 01:11:43 -06:00
										 |  |  | void stop_all_tasks(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /*
 | 
					
						
							|  |  |  |      * We trust when using NPTL (pthreads) start_exclusive() handles thread | 
					
						
							|  |  |  |      * stopping correctly. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     start_exclusive(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-04 16:02:49 -04:00
										 |  |  | bool qemu_cpu_is_self(CPUState *cpu) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return thread_cpu == cpu; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void qemu_cpu_kick(CPUState *cpu) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     cpu_exit(cpu); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | /* Assumes contents are already zeroed.  */ | 
					
						
							| 
									
										
										
										
											2022-01-16 16:14:18 -07:00
										 |  |  | static void init_task_state(TaskState *ts) | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-01-08 21:40:28 -07:00
										 |  |  |     ts->sigaltstack_used = (struct target_sigaltstack) { | 
					
						
							|  |  |  |         .ss_sp = 0, | 
					
						
							|  |  |  |         .ss_size = 0, | 
					
						
							|  |  |  |         .ss_flags = TARGET_SS_DISABLE, | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-07 08:43:57 -06:00
										 |  |  | void gemu_log(const char *fmt, ...) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     va_list ap; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     va_start(ap, fmt); | 
					
						
							|  |  |  |     vfprintf(stderr, fmt, ap); | 
					
						
							|  |  |  |     va_end(ap); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-06 18:48:37 -06:00
										 |  |  | static void | 
					
						
							|  |  |  | adjust_ssize(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     struct rlimit rl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (getrlimit(RLIMIT_STACK, &rl) != 0) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     target_maxssiz = MIN(target_maxssiz, rl.rlim_max); | 
					
						
							|  |  |  |     target_dflssiz = MIN(MAX(target_dflssiz, rl.rlim_cur), target_maxssiz); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     rl.rlim_max = target_maxssiz; | 
					
						
							|  |  |  |     rl.rlim_cur = target_dflssiz; | 
					
						
							|  |  |  |     setrlimit(RLIMIT_STACK, &rl); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-03 13:39:31 -06:00
										 |  |  | static void save_proc_pathname(char *argv0) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int mib[4]; | 
					
						
							|  |  |  |     size_t len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     mib[0] = CTL_KERN; | 
					
						
							|  |  |  |     mib[1] = KERN_PROC; | 
					
						
							|  |  |  |     mib[2] = KERN_PROC_PATHNAME; | 
					
						
							|  |  |  |     mib[3] = -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     len = sizeof(qemu_proc_pathname); | 
					
						
							|  |  |  |     if (sysctl(mib, 4, qemu_proc_pathname, &len, NULL, 0)) { | 
					
						
							|  |  |  |         perror("sysctl"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | int main(int argc, char **argv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const char *filename; | 
					
						
							|  |  |  |     const char *cpu_model; | 
					
						
							| 
									
										
										
										
											2018-02-07 11:40:26 +01:00
										 |  |  |     const char *cpu_type; | 
					
						
							| 
									
										
										
										
											2013-02-26 17:52:40 +00:00
										 |  |  |     const char *log_file = NULL; | 
					
						
							| 
									
										
										
										
											2011-06-07 16:32:40 +00:00
										 |  |  |     const char *log_mask = NULL; | 
					
						
							| 
									
										
										
										
											2021-09-02 16:52:45 -06:00
										 |  |  |     const char *seed_optarg = NULL; | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |     struct target_pt_regs regs1, *regs = ®s1; | 
					
						
							|  |  |  |     struct image_info info1, *info = &info1; | 
					
						
							| 
									
										
										
										
											2021-04-29 18:45:13 -06:00
										 |  |  |     struct bsd_binprm bprm; | 
					
						
							| 
									
										
										
										
											2021-08-03 19:05:40 -06:00
										 |  |  |     TaskState *ts; | 
					
						
							| 
									
										
										
										
											2012-03-14 01:38:32 +01:00
										 |  |  |     CPUArchState *env; | 
					
						
							| 
									
										
										
										
											2013-06-27 19:49:31 +02:00
										 |  |  |     CPUState *cpu; | 
					
						
							| 
									
										
										
										
											2021-04-23 11:00:34 -06:00
										 |  |  |     int optind, rv; | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |     const char *r; | 
					
						
							| 
									
										
										
										
											2020-04-30 20:01:19 +01:00
										 |  |  |     const char *gdbstub = NULL; | 
					
						
							| 
									
										
										
										
											2009-08-15 10:35:42 +00:00
										 |  |  |     char **target_environ, **wrk; | 
					
						
							|  |  |  |     envlist_t *envlist = NULL; | 
					
						
							| 
									
										
										
										
											2021-08-07 14:34:21 -06:00
										 |  |  |     char *argv0 = NULL; | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-06 18:48:37 -06:00
										 |  |  |     adjust_ssize(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-23 10:58:11 -06:00
										 |  |  |     if (argc <= 1) { | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |         usage(); | 
					
						
							| 
									
										
										
										
											2021-04-23 10:58:11 -06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-03 13:39:31 -06:00
										 |  |  |     save_proc_pathname(argv[0]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												log: Make glib logging go through QEMU
This commit adds a error_init() helper which calls
g_log_set_default_handler() so that glib logs (g_log, g_warning, ...)
are handled similarly to other QEMU logs. This means they will get a
timestamp if timestamps are enabled, and they will go through the
HMP monitor if one is configured.
This commit also adds a call to error_init() to the binaries
installed by QEMU. Since error_init() also calls error_set_progname(),
this means that *-linux-user, *-bsd-user and qemu-pr-helper messages
output with error_report, info_report, ... will slightly change: they
will be prefixed by the binary name.
glib debug messages are enabled through G_MESSAGES_DEBUG similarly to
the glib default log handler.
At the moment, this change will mostly impact SPICE logging if your
spice version is >= 0.14.1. With older spice versions, this is not going
to work as expected, but will not have any ill effect, so this call is
not conditional on the SPICE version.
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20190131164614.19209-3-cfergeau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
											
										 
											2019-01-31 17:46:14 +01:00
										 |  |  |     error_init(argv[0]); | 
					
						
							| 
									
										
										
										
											2016-10-04 14:35:52 +01:00
										 |  |  |     module_call_init(MODULE_INIT_TRACE); | 
					
						
							| 
									
										
										
										
											2016-08-28 03:45:14 +02:00
										 |  |  |     qemu_init_cpu_list(); | 
					
						
							| 
									
										
										
										
											2012-03-04 21:32:36 +01:00
										 |  |  |     module_call_init(MODULE_INIT_QOM); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-20 17:38:28 +00:00
										 |  |  |     envlist = envlist_create(); | 
					
						
							| 
									
										
										
										
											2009-08-15 10:35:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-29 17:00:06 +02:00
										 |  |  |     /*
 | 
					
						
							|  |  |  |      * add current environment into the list | 
					
						
							|  |  |  |      * envlist_setenv adds to the front of the list; to preserve environ | 
					
						
							|  |  |  |      * order add from back to front | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2009-08-15 10:35:42 +00:00
										 |  |  |     for (wrk = environ; *wrk != NULL; wrk++) { | 
					
						
							| 
									
										
										
										
											2023-03-29 17:00:06 +02:00
										 |  |  |         continue; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     while (wrk != environ) { | 
					
						
							|  |  |  |         wrk--; | 
					
						
							| 
									
										
										
										
											2009-08-15 10:35:42 +00:00
										 |  |  |         (void) envlist_setenv(envlist, *wrk); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |     cpu_model = NULL; | 
					
						
							| 
									
										
										
										
											2010-03-22 19:12:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-15 19:08:43 +02:00
										 |  |  |     qemu_add_opts(&qemu_trace_opts); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |     optind = 1; | 
					
						
							| 
									
										
										
										
											2016-07-15 19:08:43 +02:00
										 |  |  |     for (;;) { | 
					
						
							| 
									
										
										
										
											2021-04-23 10:58:11 -06:00
										 |  |  |         if (optind >= argc) { | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |             break; | 
					
						
							| 
									
										
										
										
											2021-04-23 10:58:11 -06:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |         r = argv[optind]; | 
					
						
							| 
									
										
										
										
											2021-04-23 10:58:11 -06:00
										 |  |  |         if (r[0] != '-') { | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |             break; | 
					
						
							| 
									
										
										
										
											2021-04-23 10:58:11 -06:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |         optind++; | 
					
						
							|  |  |  |         r++; | 
					
						
							|  |  |  |         if (!strcmp(r, "-")) { | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } else if (!strcmp(r, "d")) { | 
					
						
							| 
									
										
										
										
											2011-06-07 16:32:40 +00:00
										 |  |  |             if (optind >= argc) { | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-06-07 16:32:40 +00:00
										 |  |  |             log_mask = argv[optind++]; | 
					
						
							|  |  |  |         } else if (!strcmp(r, "D")) { | 
					
						
							|  |  |  |             if (optind >= argc) { | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             log_file = argv[optind++]; | 
					
						
							| 
									
										
										
										
											2009-08-15 10:35:42 +00:00
										 |  |  |         } else if (!strcmp(r, "E")) { | 
					
						
							|  |  |  |             r = argv[optind++]; | 
					
						
							| 
									
										
										
										
											2021-04-23 10:58:11 -06:00
										 |  |  |             if (envlist_setenv(envlist, r) != 0) { | 
					
						
							| 
									
										
										
										
											2009-08-15 10:35:42 +00:00
										 |  |  |                 usage(); | 
					
						
							| 
									
										
										
										
											2021-04-23 10:58:11 -06:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-07-15 22:28:02 +02:00
										 |  |  |         } else if (!strcmp(r, "ignore-environment")) { | 
					
						
							|  |  |  |             envlist_free(envlist); | 
					
						
							| 
									
										
										
										
											2017-03-20 17:38:28 +00:00
										 |  |  |             envlist = envlist_create(); | 
					
						
							| 
									
										
										
										
											2009-08-15 10:35:42 +00:00
										 |  |  |         } else if (!strcmp(r, "U")) { | 
					
						
							|  |  |  |             r = argv[optind++]; | 
					
						
							| 
									
										
										
										
											2021-04-23 10:58:11 -06:00
										 |  |  |             if (envlist_unsetenv(envlist, r) != 0) { | 
					
						
							| 
									
										
										
										
											2009-08-15 10:35:42 +00:00
										 |  |  |                 usage(); | 
					
						
							| 
									
										
										
										
											2021-04-23 10:58:11 -06:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |         } else if (!strcmp(r, "s")) { | 
					
						
							|  |  |  |             r = argv[optind++]; | 
					
						
							| 
									
										
										
										
											2021-08-06 18:48:37 -06:00
										 |  |  |             rv = qemu_strtoul(r, &r, 0, &target_dflssiz); | 
					
						
							|  |  |  |             if (rv < 0 || target_dflssiz <= 0) { | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |                 usage(); | 
					
						
							| 
									
										
										
										
											2021-04-23 10:58:11 -06:00
										 |  |  |             } | 
					
						
							|  |  |  |             if (*r == 'M') { | 
					
						
							| 
									
										
										
										
											2021-08-06 18:48:37 -06:00
										 |  |  |                 target_dflssiz *= 1024 * 1024; | 
					
						
							| 
									
										
										
										
											2021-04-23 10:58:11 -06:00
										 |  |  |             } else if (*r == 'k' || *r == 'K') { | 
					
						
							| 
									
										
										
										
											2021-08-06 18:48:37 -06:00
										 |  |  |                 target_dflssiz *= 1024; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (target_dflssiz > target_maxssiz) { | 
					
						
							|  |  |  |                 usage(); | 
					
						
							| 
									
										
										
										
											2021-04-23 10:58:11 -06:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |         } else if (!strcmp(r, "L")) { | 
					
						
							|  |  |  |             interp_prefix = argv[optind++]; | 
					
						
							|  |  |  |         } else if (!strcmp(r, "p")) { | 
					
						
							|  |  |  |             qemu_host_page_size = atoi(argv[optind++]); | 
					
						
							|  |  |  |             if (qemu_host_page_size == 0 || | 
					
						
							|  |  |  |                 (qemu_host_page_size & (qemu_host_page_size - 1)) != 0) { | 
					
						
							|  |  |  |                 fprintf(stderr, "page size must be a power of two\n"); | 
					
						
							|  |  |  |                 exit(1); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else if (!strcmp(r, "g")) { | 
					
						
							| 
									
										
										
										
											2020-04-30 20:01:19 +01:00
										 |  |  |             gdbstub = g_strdup(argv[optind++]); | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |         } else if (!strcmp(r, "r")) { | 
					
						
							|  |  |  |             qemu_uname_release = argv[optind++]; | 
					
						
							|  |  |  |         } else if (!strcmp(r, "cpu")) { | 
					
						
							|  |  |  |             cpu_model = argv[optind++]; | 
					
						
							| 
									
										
										
										
											2012-08-02 13:45:54 +01:00
										 |  |  |             if (is_help_option(cpu_model)) { | 
					
						
							| 
									
										
										
										
											2021-04-23 09:05:57 -06:00
										 |  |  |                 /* XXX: implement xxx_cpu_list for targets that still miss it */ | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | #if defined(cpu_list)
 | 
					
						
							| 
									
										
										
										
											2021-04-23 09:05:57 -06:00
										 |  |  |                 cpu_list(); | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-02-28 20:14:00 +00:00
										 |  |  |                 exit(1); | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2009-09-27 19:30:51 +00:00
										 |  |  |         } else if (!strcmp(r, "B")) { | 
					
						
							| 
									
										
										
										
											2021-04-23 11:00:34 -06:00
										 |  |  |             rv = qemu_strtoul(argv[optind++], NULL, 0, &guest_base); | 
					
						
							|  |  |  |             if (rv < 0) { | 
					
						
							|  |  |  |                 usage(); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-04-23 09:05:57 -06:00
										 |  |  |             have_guest_base = true; | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |         } else if (!strcmp(r, "drop-ld-preload")) { | 
					
						
							| 
									
										
										
										
											2009-08-15 10:35:42 +00:00
										 |  |  |             (void) envlist_unsetenv(envlist, "LD_PRELOAD"); | 
					
						
							| 
									
										
										
										
											2021-09-02 16:52:45 -06:00
										 |  |  |         } else if (!strcmp(r, "seed")) { | 
					
						
							|  |  |  |             seed_optarg = optarg; | 
					
						
							| 
									
										
										
										
											2023-04-17 17:40:36 +01:00
										 |  |  |         } else if (!strcmp(r, "singlestep") || !strcmp(r, "one-insn-per-tb")) { | 
					
						
							| 
									
										
										
										
											2023-04-17 17:40:32 +01:00
										 |  |  |             opt_one_insn_per_tb = true; | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |         } else if (!strcmp(r, "strace")) { | 
					
						
							|  |  |  |             do_strace = 1; | 
					
						
							| 
									
										
										
										
											2016-07-15 19:08:43 +02:00
										 |  |  |         } else if (!strcmp(r, "trace")) { | 
					
						
							| 
									
										
										
										
											2020-11-02 06:58:41 -05:00
										 |  |  |             trace_opt_parse(optarg); | 
					
						
							| 
									
										
										
										
											2021-08-07 14:34:21 -06:00
										 |  |  |         } else if (!strcmp(r, "0")) { | 
					
						
							|  |  |  |             argv0 = argv[optind++]; | 
					
						
							| 
									
										
										
										
											2016-07-15 19:08:43 +02:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |             usage(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-07 16:32:40 +00:00
										 |  |  |     /* init debug */ | 
					
						
							| 
									
										
										
										
											2022-04-17 11:30:08 -07:00
										 |  |  |     { | 
					
						
							|  |  |  |         int mask = 0; | 
					
						
							|  |  |  |         if (log_mask) { | 
					
						
							|  |  |  |             mask = qemu_str_to_log_mask(log_mask); | 
					
						
							|  |  |  |             if (!mask) { | 
					
						
							|  |  |  |                 qemu_print_log_usage(stdout); | 
					
						
							|  |  |  |                 exit(1); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-06-07 16:32:40 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-04-17 11:30:08 -07:00
										 |  |  |         qemu_set_log_filename_flags(log_file, mask, &error_fatal); | 
					
						
							| 
									
										
										
										
											2011-06-07 16:32:40 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-18 11:44:09 +01:00
										 |  |  |     if (optind >= argc) { | 
					
						
							|  |  |  |         usage(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     filename = argv[optind]; | 
					
						
							| 
									
										
										
										
											2021-08-07 14:34:21 -06:00
										 |  |  |     if (argv0) { | 
					
						
							|  |  |  |         argv[optind] = argv0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-07-18 11:44:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-15 19:08:43 +02:00
										 |  |  |     if (!trace_init_backends()) { | 
					
						
							|  |  |  |         exit(1); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-11-02 06:58:41 -05:00
										 |  |  |     trace_init_file(); | 
					
						
							| 
									
										
										
										
											2016-07-15 19:08:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |     /* Zero out regs */ | 
					
						
							|  |  |  |     memset(regs, 0, sizeof(struct target_pt_regs)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-29 18:45:13 -06:00
										 |  |  |     /* Zero bsd params */ | 
					
						
							|  |  |  |     memset(&bprm, 0, sizeof(bprm)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |     /* Zero out image_info */ | 
					
						
							|  |  |  |     memset(info, 0, sizeof(struct image_info)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Scan interp_prefix dir for replacement files. */ | 
					
						
							|  |  |  |     init_paths(interp_prefix); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (cpu_model == NULL) { | 
					
						
							| 
									
										
										
										
											2021-08-03 19:05:40 -06:00
										 |  |  |         cpu_model = TARGET_DEFAULT_CPU_MODEL; | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-05-17 13:51:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 17:39:25 +01:00
										 |  |  |     cpu_type = parse_cpu_option(cpu_model); | 
					
						
							| 
									
										
										
										
											2021-08-03 19:05:40 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 13:51:17 +02:00
										 |  |  |     /* init tcg before creating CPUs and to get qemu_host_page_size */ | 
					
						
							| 
									
										
										
										
											2021-02-04 17:39:24 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-04-17 17:40:32 +01:00
										 |  |  |         AccelState *accel = current_accel(); | 
					
						
							|  |  |  |         AccelClass *ac = ACCEL_GET_CLASS(accel); | 
					
						
							| 
									
										
										
										
											2018-05-17 13:51:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 17:39:25 +01:00
										 |  |  |         accel_init_interfaces(ac); | 
					
						
							| 
									
										
										
										
											2023-04-17 17:40:32 +01:00
										 |  |  |         object_property_set_bool(OBJECT(accel), "one-insn-per-tb", | 
					
						
							|  |  |  |                                  opt_one_insn_per_tb, &error_abort); | 
					
						
							| 
									
										
										
										
											2021-03-22 14:27:58 +01:00
										 |  |  |         ac->init_machine(NULL); | 
					
						
							| 
									
										
										
										
											2021-02-04 17:39:24 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-02-07 11:40:26 +01:00
										 |  |  |     cpu = cpu_create(cpu_type); | 
					
						
							| 
									
										
										
										
											2015-02-26 17:37:49 -03:00
										 |  |  |     env = cpu->env_ptr; | 
					
						
							| 
									
										
										
										
											2013-06-27 19:49:31 +02:00
										 |  |  |     cpu_reset(cpu); | 
					
						
							|  |  |  |     thread_cpu = cpu; | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (getenv("QEMU_STRACE")) { | 
					
						
							|  |  |  |         do_strace = 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-15 10:35:42 +00:00
										 |  |  |     target_environ = envlist_to_environ(envlist, NULL); | 
					
						
							|  |  |  |     envlist_free(envlist); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-02 16:52:45 -06:00
										 |  |  |     { | 
					
						
							|  |  |  |         Error *err = NULL; | 
					
						
							|  |  |  |         if (seed_optarg != NULL) { | 
					
						
							|  |  |  |             qemu_guest_random_seed_main(seed_optarg, &err); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             qcrypto_init(&err); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (err) { | 
					
						
							|  |  |  |             error_reportf_err(err, "cannot initialize crypto: "); | 
					
						
							|  |  |  |             exit(1); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-27 19:30:51 +00:00
										 |  |  |     /*
 | 
					
						
							| 
									
										
										
										
											2021-03-09 17:42:16 -06:00
										 |  |  |      * Now that page sizes are configured we can do | 
					
						
							| 
									
										
										
										
											2009-09-27 19:30:51 +00:00
										 |  |  |      * proper page alignment for guest_base. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2023-07-27 09:11:48 -07:00
										 |  |  |     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; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-09-27 19:30:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-29 18:45:13 -06:00
										 |  |  |     if (loader_exec(filename, argv + optind, target_environ, regs, info, | 
					
						
							|  |  |  |                     &bprm) != 0) { | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |         printf("Error loading %s\n", filename); | 
					
						
							|  |  |  |         _exit(1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (wrk = target_environ; *wrk; wrk++) { | 
					
						
							| 
									
										
										
										
											2017-03-20 17:38:28 +00:00
										 |  |  |         g_free(*wrk); | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-20 17:38:28 +00:00
										 |  |  |     g_free(target_environ); | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-13 12:32:19 +01:00
										 |  |  |     if (qemu_loglevel_mask(CPU_LOG_PAGE)) { | 
					
						
							| 
									
										
										
										
											2022-04-17 11:30:01 -07:00
										 |  |  |         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); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-01-20 16:57:34 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-03 19:05:40 -06:00
										 |  |  |     /* build Task State */ | 
					
						
							|  |  |  |     ts = g_new0(TaskState, 1); | 
					
						
							|  |  |  |     init_task_state(ts); | 
					
						
							|  |  |  |     ts->info = info; | 
					
						
							|  |  |  |     ts->bprm = &bprm; | 
					
						
							|  |  |  |     cpu->opaque = ts; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |     target_set_brk(info->brk); | 
					
						
							|  |  |  |     syscall_init(); | 
					
						
							|  |  |  |     signal_init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-23 10:38:55 -06:00
										 |  |  |     /*
 | 
					
						
							|  |  |  |      * Now that we've loaded the binary, GUEST_BASE is fixed.  Delay | 
					
						
							|  |  |  |      * generating the prologue until now so that the prologue can take | 
					
						
							|  |  |  |      * the real value of GUEST_BASE into account. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-07-12 17:15:52 -04:00
										 |  |  |     tcg_prologue_init(tcg_ctx); | 
					
						
							| 
									
										
										
										
											2010-05-06 08:50:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-03 19:05:40 -06:00
										 |  |  |     target_cpu_init(env, regs); | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-30 20:01:19 +01:00
										 |  |  |     if (gdbstub) { | 
					
						
							|  |  |  |         gdbserver_start(gdbstub); | 
					
						
							| 
									
										
										
										
											2013-06-27 19:49:31 +02:00
										 |  |  |         gdb_handlesig(cpu, 0); | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-10-17 00:34:26 +02:00
										 |  |  |     cpu_loop(env); | 
					
						
							| 
									
										
										
										
											2008-10-26 20:33:16 +00:00
										 |  |  |     /* never exits */ | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } |