Skip to content

Commit

Permalink
hw/core/generic-loader: Fix crash when running without CPU
Browse files Browse the repository at this point in the history
When running QEMU with "-M none -device loader,file=kernel.elf", it
currently crashes with a segmentation fault, because the "none"-machine
does not have any CPU by default and the generic loader code tries
to dereference s->cpu. Fix it by adding an appropriate check for a
NULL pointer.

Reported-by: Laurent Vivier <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
Reviewed-by: Laurent Vivier <[email protected]>
Reviewed-by: Alistair Francis <[email protected]>
Signed-off-by: Michael Tokarev <[email protected]>
  • Loading branch information
huth authored and Michael Tokarev committed May 10, 2017
1 parent 1d29b5b commit 6516367
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions hw/core/generic-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,21 @@ static void generic_loader_realize(DeviceState *dev, Error **errp)
#endif

if (s->file) {
AddressSpace *as = s->cpu ? s->cpu->as : NULL;

if (!s->force_raw) {
size = load_elf_as(s->file, NULL, NULL, &entry, NULL, NULL,
big_endian, 0, 0, 0, s->cpu->as);
big_endian, 0, 0, 0, as);

if (size < 0) {
size = load_uimage_as(s->file, &entry, NULL, NULL, NULL, NULL,
s->cpu->as);
as);
}
}

if (size < 0 || s->force_raw) {
/* Default to the maximum size being the machine's ram size */
size = load_image_targphys_as(s->file, s->addr, ram_size,
s->cpu->as);
size = load_image_targphys_as(s->file, s->addr, ram_size, as);
} else {
s->addr = entry;
}
Expand Down

0 comments on commit 6516367

Please sign in to comment.