aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimir Chtchetkine <vchtchetkine@google.com>2012-05-14 13:54:06 -0700
committerandroid code review <noreply-gerritcodereview@google.com>2012-05-14 13:54:07 -0700
commit86daf2d663697d86d4c20cf571c3c4b66c67d1a5 (patch)
treed14602cb7817a456b17a24c3422d890d27a51a59
parent10a4d62985dbafe9d40cae9b6fbcb9605b4c3af5 (diff)
parentcf289fbe0669ad54965e9f378b7e7b4edea9d814 (diff)
downloadexternal_qemu-86daf2d663697d86d4c20cf571c3c4b66c67d1a5.zip
external_qemu-86daf2d663697d86d4c20cf571c3c4b66c67d1a5.tar.gz
external_qemu-86daf2d663697d86d4c20cf571c3c4b66c67d1a5.tar.bz2
Merge "Check RAM availability before VM is initialized."
-rw-r--r--vl-android.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/vl-android.c b/vl-android.c
index f9afa5c..7b661b6 100644
--- a/vl-android.c
+++ b/vl-android.c
@@ -4046,6 +4046,32 @@ int main(int argc, char **argv, char **envp)
}
}
+ /* Quite often (especially on older XP machines) attempts to allocate large
+ * VM RAM is going to fail, and crash the emulator. Since it's failing deep
+ * inside QEMU, it's not really possible to provide the user with a
+ * meaningful explanation for the crash. So, lets see if QEMU is going to be
+ * able to allocate requested amount of RAM, and if not, lets try to come up
+ * with a recomendation. */
+ {
+ ram_addr_t r_ram = ram_size;
+ void* alloc_check = malloc(r_ram);
+ while (alloc_check == NULL && r_ram > 1024 * 1024) {
+ /* Make it 25% less */
+ r_ram -= r_ram / 4;
+ alloc_check = malloc(r_ram);
+ }
+ if (alloc_check != NULL) {
+ free(alloc_check);
+ }
+ if (r_ram != ram_size) {
+ /* Requested RAM is too large. Report this, as well as calculated
+ * recomendation. */
+ dwarning("Requested RAM size of %dMB is too large for your environment, and is reduced to %dMB.",
+ (int)(ram_size / 1024 / 1024), (int)(r_ram / 1024 / 1024));
+ ram_size = r_ram;
+ }
+ }
+
#ifdef CONFIG_KQEMU
/* FIXME: This is a nasty hack because kqemu can't cope with dynamic
guest ram allocation. It needs to go away. */