提交 6516367f 编写于 作者: T Thomas Huth 提交者: Michael Tokarev

hw/core/generic-loader: Fix crash when running without CPU

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: NLaurent Vivier <laurent@vivier.eu>
Signed-off-by: NThomas Huth <thuth@redhat.com>
Reviewed-by: NLaurent Vivier <laurent@vivier.eu>
Reviewed-by: NAlistair Francis <alistair.francis@xilinx.com>
Signed-off-by: NMichael Tokarev <mjt@tls.msk.ru>
上级 1d29b5b0
...@@ -137,20 +137,21 @@ static void generic_loader_realize(DeviceState *dev, Error **errp) ...@@ -137,20 +137,21 @@ static void generic_loader_realize(DeviceState *dev, Error **errp)
#endif #endif
if (s->file) { if (s->file) {
AddressSpace *as = s->cpu ? s->cpu->as : NULL;
if (!s->force_raw) { if (!s->force_raw) {
size = load_elf_as(s->file, NULL, NULL, &entry, NULL, NULL, 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) { if (size < 0) {
size = load_uimage_as(s->file, &entry, NULL, NULL, NULL, NULL, size = load_uimage_as(s->file, &entry, NULL, NULL, NULL, NULL,
s->cpu->as); as);
} }
} }
if (size < 0 || s->force_raw) { if (size < 0 || s->force_raw) {
/* Default to the maximum size being the machine's ram size */ /* Default to the maximum size being the machine's ram size */
size = load_image_targphys_as(s->file, s->addr, ram_size, size = load_image_targphys_as(s->file, s->addr, ram_size, as);
s->cpu->as);
} else { } else {
s->addr = entry; s->addr = entry;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册