From: Magnus Reftel <reftel@spotify.com>
To: qemu-devel@nongnu.org
Cc: Magnus Reftel <reftel@spotify.com>
Subject: [Qemu-devel] [PATCH] linux-user: Let user specify random seed
Date: Thu, 9 Oct 2014 10:36:25 +0200 [thread overview]
Message-ID: <1412843785-960-2-git-send-email-reftel@spotify.com> (raw)
In-Reply-To: <1412843785-960-1-git-send-email-reftel@spotify.com>
This patch introduces the -seed command line option and the
QEMU_RAND_SEED environment variable for setting the random seed, which
is used for the AT_RANDOM ELF aux entry.
Signed-off-by: Magnus Reftel <reftel@spotify.com>
---
linux-user/elfload.c | 1 -
linux-user/main.c | 20 ++++++++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 1c04fcf..f2e2197 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1539,7 +1539,6 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
* Generate 16 random bytes for userspace PRNG seeding (not
* cryptically secure but it's not the aim of QEMU).
*/
- srand((unsigned int) time(NULL));
for (i = 0; i < 16; i++) {
k_rand_bytes[i] = rand();
}
diff --git a/linux-user/main.c b/linux-user/main.c
index 483eb3f..e80255c 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3546,6 +3546,18 @@ static void handle_arg_pagesize(const char *arg)
}
}
+static void handle_arg_randseed(const char *arg)
+{
+ unsigned long seed;
+ char* end;
+ seed = strtoul(arg, &end, 0);
+ if (end==arg || *end!='\0' || seed > UINT_MAX) {
+ fprintf(stderr, "Invalid seed number: %s\n", arg);
+ exit(1);
+ }
+ srand(seed);
+}
+
static void handle_arg_gdb(const char *arg)
{
gdbstub_port = atoi(arg);
@@ -3674,6 +3686,8 @@ static const struct qemu_argument arg_table[] = {
"", "run in singlestep mode"},
{"strace", "QEMU_STRACE", false, handle_arg_strace,
"", "log system calls"},
+ {"seed", "QEMU_RAND_SEED", true, handle_arg_randseed,
+ "", "Seed for pseudo-random number generator"},
{"version", "QEMU_VERSION", false, handle_arg_version,
"", "display version information and exit"},
{NULL, NULL, false, NULL, NULL, NULL}
@@ -3856,6 +3870,8 @@ int main(int argc, char **argv, char **envp)
cpudef_setup(); /* parse cpu definitions in target config file (TBD) */
#endif
+ srand(time(NULL));
+
optind = parse_args(argc, argv);
/* Zero out regs */
@@ -3926,6 +3942,10 @@ int main(int argc, char **argv, char **envp)
do_strace = 1;
}
+ if (getenv("QEMU_RAND_SEED")) {
+ handle_arg_randseed(getenv("QEMU_RAND_SEED"));
+ }
+
target_environ = envlist_to_environ(envlist, NULL);
envlist_free(envlist);
--
1.9.1
next prev parent reply other threads:[~2014-10-09 8:37 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-09 8:36 [Qemu-devel] [PATCH v2] linux-user: Let user specify random seed Magnus Reftel
2014-10-09 8:36 ` Magnus Reftel [this message]
2014-10-09 15:27 ` [Qemu-devel] [PATCH] " Eric Blake
2014-10-09 19:10 ` Magnus Reftel
2014-10-09 19:43 ` [Qemu-devel] [PATCH v2] " Tom Musta
2014-10-10 8:00 ` Magnus Reftel
-- strict thread matches above, loose matches on Subject: below --
2014-10-14 15:18 [Qemu-devel] [PATCH v5] " Magnus Reftel
2014-10-14 15:18 ` [Qemu-devel] [PATCH] " Magnus Reftel
2014-10-14 9:50 [Qemu-devel] [PATCH v4] " Magnus Reftel
2014-10-14 9:50 ` [Qemu-devel] [PATCH] " Magnus Reftel
2014-10-14 15:07 ` Eric Blake
2014-10-09 19:12 [Qemu-devel] [PATCH v3] " Magnus Reftel
2014-10-09 19:12 ` [Qemu-devel] [PATCH] " Magnus Reftel
2014-10-09 21:30 ` Eric Blake
2014-10-10 8:16 ` Magnus Reftel
2014-10-10 16:20 ` Eric Blake
2014-10-14 9:46 ` Magnus Reftel
2014-10-08 12:13 [Qemu-devel] [PATCH] Let user specify random seed for linux-user Magnus Reftel
2014-10-08 12:13 ` [Qemu-devel] [PATCH] linux-user: Let user specify random seed Magnus Reftel
2014-10-08 14:45 ` Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1412843785-960-2-git-send-email-reftel@spotify.com \
--to=reftel@spotify.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).