Skip to content

Commit 47e8acb

Browse files
committed
Merge remote-tracking branch 'remotes/riku/tags/pull-linux-user-20141101' into staging
linux-user pull for 2.2 Two minor fixes and new a feature, addition of QEMU_RAND_SEED for testing needs. # gpg: Signature made Mon 03 Nov 2014 11:49:39 GMT using RSA key ID DE3C9BC0 # gpg: Good signature from "Riku Voipio <[email protected]>" # gpg: aka "Riku Voipio <[email protected]>" * remotes/riku/tags/pull-linux-user-20141101: elf: take phdr offset into account when calculating the program load address linux-user: Fix fault address truncation AArch64 linux-user: Let user specify random seed Signed-off-by: Peter Maydell <[email protected]>
2 parents 9a33c0c + a93934f commit 47e8acb

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

linux-user/elfload.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,6 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
15391539
* Generate 16 random bytes for userspace PRNG seeding (not
15401540
* cryptically secure but it's not the aim of QEMU).
15411541
*/
1542-
srand((unsigned int) time(NULL));
15431542
for (i = 0; i < 16; i++) {
15441543
k_rand_bytes[i] = rand();
15451544
}
@@ -1821,7 +1820,7 @@ static void load_elf_image(const char *image_name, int image_fd,
18211820
loaddr = -1, hiaddr = 0;
18221821
for (i = 0; i < ehdr->e_phnum; ++i) {
18231822
if (phdr[i].p_type == PT_LOAD) {
1824-
abi_ulong a = phdr[i].p_vaddr;
1823+
abi_ulong a = phdr[i].p_vaddr - phdr[i].p_offset;
18251824
if (a < loaddr) {
18261825
loaddr = a;
18271826
}

linux-user/main.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,6 @@ void cpu_loop(CPUARMState *env)
10061006
CPUState *cs = CPU(arm_env_get_cpu(env));
10071007
int trapnr, sig;
10081008
target_siginfo_t info;
1009-
uint32_t addr;
10101009

10111010
for (;;) {
10121011
cpu_exec_start(cs);
@@ -1042,12 +1041,11 @@ void cpu_loop(CPUARMState *env)
10421041
/* fall through for segv */
10431042
case EXCP_PREFETCH_ABORT:
10441043
case EXCP_DATA_ABORT:
1045-
addr = env->exception.vaddress;
10461044
info.si_signo = SIGSEGV;
10471045
info.si_errno = 0;
10481046
/* XXX: check env->error_code */
10491047
info.si_code = TARGET_SEGV_MAPERR;
1050-
info._sifields._sigfault._addr = addr;
1048+
info._sifields._sigfault._addr = env->exception.vaddress;
10511049
queue_signal(env, info.si_signo, &info);
10521050
break;
10531051
case EXCP_DEBUG:
@@ -3546,6 +3544,17 @@ static void handle_arg_pagesize(const char *arg)
35463544
}
35473545
}
35483546

3547+
static void handle_arg_randseed(const char *arg)
3548+
{
3549+
unsigned long long seed;
3550+
3551+
if (parse_uint_full(arg, &seed, 0) != 0 || seed > UINT_MAX) {
3552+
fprintf(stderr, "Invalid seed number: %s\n", arg);
3553+
exit(1);
3554+
}
3555+
srand(seed);
3556+
}
3557+
35493558
static void handle_arg_gdb(const char *arg)
35503559
{
35513560
gdbstub_port = atoi(arg);
@@ -3674,6 +3683,8 @@ static const struct qemu_argument arg_table[] = {
36743683
"", "run in singlestep mode"},
36753684
{"strace", "QEMU_STRACE", false, handle_arg_strace,
36763685
"", "log system calls"},
3686+
{"seed", "QEMU_RAND_SEED", true, handle_arg_randseed,
3687+
"", "Seed for pseudo-random number generator"},
36773688
{"version", "QEMU_VERSION", false, handle_arg_version,
36783689
"", "display version information and exit"},
36793690
{NULL, NULL, false, NULL, NULL, NULL}
@@ -3856,6 +3867,8 @@ int main(int argc, char **argv, char **envp)
38563867
cpudef_setup(); /* parse cpu definitions in target config file (TBD) */
38573868
#endif
38583869

3870+
srand(time(NULL));
3871+
38593872
optind = parse_args(argc, argv);
38603873

38613874
/* Zero out regs */
@@ -3926,6 +3939,10 @@ int main(int argc, char **argv, char **envp)
39263939
do_strace = 1;
39273940
}
39283941

3942+
if (getenv("QEMU_RAND_SEED")) {
3943+
handle_arg_randseed(getenv("QEMU_RAND_SEED"));
3944+
}
3945+
39293946
target_environ = envlist_to_environ(envlist, NULL);
39303947
envlist_free(envlist);
39313948

0 commit comments

Comments
 (0)