Skip to contentSkip to conversation

64 bit truncation in code_gen_buffer_size calculation

PATCH Applied Jes Sorensen 2 participants 2 messages Sep 24, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 64 bit truncation in code_gen_buffer_size calculation

Hi,

This one is pretty obvious, don't truncate the result of code_gen_buffer_size calculation to int when the target is an unsigned long. Gives funny results when trying to boot something with a lot of memory on a 64 bit system.

Cheers,
Jes

Don't truncate code_gen_buffer_size calculation to int, as it will give unpredicted results on 64 bit systems when booting large guests.

---
 exec.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
exec.c +1 -1
Index: qemu/exec.c
===================================================================
@@ -410,7 +410,7 @@ static void code_gen_alloc(unsigned long
         code_gen_buffer_size = DEFAULT_CODE_GEN_BUFFER_SIZE;
 #else
         /* XXX: needs ajustments */
-        code_gen_buffer_size = (int)(phys_ram_size / 4);
+        code_gen_buffer_size = (unsigned long)(phys_ram_size / 4);
 #endif
     }
     if (code_gen_buffer_size < MIN_CODE_GEN_BUFFER_SIZE)
#1 lore raw
Quoted 6 lines · Jes Sorensen

Hi,

This one is pretty obvious, don't truncate the result of code_gen_buffer_size calculation to int when the target is an unsigned long. Gives funny results when trying to boot something with a lot of memory on a 64 bit system.

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 5 lines

Cheers,
Jes