linux-user: Initialize pseudo-random seeds for all guest cpus
When the -seed option is given, call qemu_guest_random_seed_main, putting the subsystem into deterministic mode. Pass derived seeds to each cpu created during clone; which is a no-op unless the subsystem is in deterministic mode. Reviewed-by: Laurent Vivier <lvivier@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
9c09a2518e
commit
5ebdd77494
@ -34,6 +34,7 @@
|
|||||||
#include "tcg.h"
|
#include "tcg.h"
|
||||||
#include "qemu/timer.h"
|
#include "qemu/timer.h"
|
||||||
#include "qemu/envlist.h"
|
#include "qemu/envlist.h"
|
||||||
|
#include "qemu/guest-random.h"
|
||||||
#include "elf.h"
|
#include "elf.h"
|
||||||
#include "trace/control.h"
|
#include "trace/control.h"
|
||||||
#include "target_elf.h"
|
#include "target_elf.h"
|
||||||
@ -48,6 +49,7 @@ static int gdbstub_port;
|
|||||||
static envlist_t *envlist;
|
static envlist_t *envlist;
|
||||||
static const char *cpu_model;
|
static const char *cpu_model;
|
||||||
static const char *cpu_type;
|
static const char *cpu_type;
|
||||||
|
static const char *seed_optarg;
|
||||||
unsigned long mmap_min_addr;
|
unsigned long mmap_min_addr;
|
||||||
unsigned long guest_base;
|
unsigned long guest_base;
|
||||||
int have_guest_base;
|
int have_guest_base;
|
||||||
@ -290,15 +292,9 @@ static void handle_arg_pagesize(const char *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_arg_randseed(const char *arg)
|
static void handle_arg_seed(const char *arg)
|
||||||
{
|
{
|
||||||
unsigned long long seed;
|
seed_optarg = arg;
|
||||||
|
|
||||||
if (parse_uint_full(arg, &seed, 0) != 0 || seed > UINT_MAX) {
|
|
||||||
fprintf(stderr, "Invalid seed number: %s\n", arg);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
srand(seed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_arg_gdb(const char *arg)
|
static void handle_arg_gdb(const char *arg)
|
||||||
@ -433,7 +429,7 @@ static const struct qemu_argument arg_table[] = {
|
|||||||
"", "run in singlestep mode"},
|
"", "run in singlestep mode"},
|
||||||
{"strace", "QEMU_STRACE", false, handle_arg_strace,
|
{"strace", "QEMU_STRACE", false, handle_arg_strace,
|
||||||
"", "log system calls"},
|
"", "log system calls"},
|
||||||
{"seed", "QEMU_RAND_SEED", true, handle_arg_randseed,
|
{"seed", "QEMU_RAND_SEED", true, handle_arg_seed,
|
||||||
"", "Seed for pseudo-random number generator"},
|
"", "Seed for pseudo-random number generator"},
|
||||||
{"trace", "QEMU_TRACE", true, handle_arg_trace,
|
{"trace", "QEMU_TRACE", true, handle_arg_trace,
|
||||||
"", "[[enable=]<pattern>][,events=<file>][,file=<file>]"},
|
"", "[[enable=]<pattern>][,events=<file>][,file=<file>]"},
|
||||||
@ -689,8 +685,20 @@ int main(int argc, char **argv, char **envp)
|
|||||||
do_strace = 1;
|
do_strace = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getenv("QEMU_RAND_SEED")) {
|
if (seed_optarg == NULL) {
|
||||||
handle_arg_randseed(getenv("QEMU_RAND_SEED"));
|
seed_optarg = getenv("QEMU_RAND_SEED");
|
||||||
|
}
|
||||||
|
if (seed_optarg != NULL) {
|
||||||
|
unsigned long long seed;
|
||||||
|
|
||||||
|
/* This will go away with the last user of rand(). */
|
||||||
|
if (parse_uint_full(seed_optarg, &seed, 0) != 0) {
|
||||||
|
fprintf(stderr, "Invalid seed number: %s\n", seed_optarg);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
srand(seed);
|
||||||
|
|
||||||
|
qemu_guest_random_seed_main(seed_optarg, &error_fatal);
|
||||||
}
|
}
|
||||||
|
|
||||||
target_environ = envlist_to_environ(envlist, NULL);
|
target_environ = envlist_to_environ(envlist, NULL);
|
||||||
|
@ -107,6 +107,7 @@
|
|||||||
#include "uname.h"
|
#include "uname.h"
|
||||||
|
|
||||||
#include "qemu.h"
|
#include "qemu.h"
|
||||||
|
#include "qemu/guest-random.h"
|
||||||
#include "fd-trans.h"
|
#include "fd-trans.h"
|
||||||
|
|
||||||
#ifndef CLONE_IO
|
#ifndef CLONE_IO
|
||||||
@ -5482,6 +5483,7 @@ static void *clone_func(void *arg)
|
|||||||
put_user_u32(info->tid, info->child_tidptr);
|
put_user_u32(info->tid, info->child_tidptr);
|
||||||
if (info->parent_tidptr)
|
if (info->parent_tidptr)
|
||||||
put_user_u32(info->tid, info->parent_tidptr);
|
put_user_u32(info->tid, info->parent_tidptr);
|
||||||
|
qemu_guest_random_seed_thread_part2(cpu->random_seed);
|
||||||
/* Enable signals. */
|
/* Enable signals. */
|
||||||
sigprocmask(SIG_SETMASK, &info->sigmask, NULL);
|
sigprocmask(SIG_SETMASK, &info->sigmask, NULL);
|
||||||
/* Signal to the parent that we're ready. */
|
/* Signal to the parent that we're ready. */
|
||||||
@ -5568,6 +5570,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,
|
|||||||
initializing, so temporarily block all signals. */
|
initializing, so temporarily block all signals. */
|
||||||
sigfillset(&sigmask);
|
sigfillset(&sigmask);
|
||||||
sigprocmask(SIG_BLOCK, &sigmask, &info.sigmask);
|
sigprocmask(SIG_BLOCK, &sigmask, &info.sigmask);
|
||||||
|
cpu->random_seed = qemu_guest_random_seed_thread_part1();
|
||||||
|
|
||||||
/* If this is our first additional thread, we need to ensure we
|
/* If this is our first additional thread, we need to ensure we
|
||||||
* generate code for parallel execution and flush old translations.
|
* generate code for parallel execution and flush old translations.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user