@@ -68,6 +68,20 @@ static bool smbios_type1_defaults = true;
static bool gigabyte_align = true;
static bool has_reserved_memory = true;
+ram_addr_t get_above_4g_mem_size(ram_addr_t ram_size)
+{
+ ram_addr_t above_4g_mem_size;
+
+ if (ram_size >= 0xe0000000) {
+ ram_addr_t lowmem = gigabyte_align ? 0xc0000000 : 0xe0000000;
+ above_4g_mem_size = ram_size - lowmem;
+ } else {
+ above_4g_mem_size = 0;
+ }
+
+ return above_4g_mem_size;
+}
+
/* PC hardware initialisation */
static void pc_init1(QEMUMachineInitArgs *args,
int pci_enabled,
@@ -273,6 +273,7 @@ void pc_system_firmware_init(MemoryRegion *rom_memory,
/* pvpanic.c */
uint16_t pvpanic_port(void);
+ram_addr_t get_above_4g_mem_size(ram_addr_t ram_size);
/* e820 types */
#define E820_RAM 1
@@ -3378,6 +3378,14 @@ int main(int argc, char **argv, char **envp)
exit(EXIT_FAILURE);
}
+ ram_addr_t above_4g_mem = get_above_4g_mem_size(ram_size);
+ if (sz - ram_size > UINT64_MAX - 0x100000000 - above_4g_mem) {
+ fprintf(stderr, "qemu: invalid -m option value: maxmem "
+ "(%" PRIu64 ") out of range.\n", sz);
+ fprintf(stderr, "maxmem: %" PRIu64 "\n", UINT64_MAX - 0x100000000 - above_4g_mem + ram_size);
+ exit(EXIT_FAILURE);
+ }
+
slots = qemu_opt_get_number(opts, "slots", 0);
if ((sz > ram_size) && !slots) {
fprintf(stderr, "qemu: invalid -m option value: maxmem "