spice/0004-server-red_memslots-don-t-assume-64-bit-environment.patch
2012-04-24 17:22:10 +03:00

84 lines
3.2 KiB
Diff

From 3d0448314812457e027e513c2d0dc163c421914a Mon Sep 17 00:00:00 2001
From: Alon Levy <alevy@redhat.com>
Date: Tue, 20 Mar 2012 19:00:49 +0200
Subject: [PATCH 4/4] server/red_memslots: don't assume 64 bit environment
assumption that unsigned long == QXLPHYSICAL causes get_virt to compute
the wrong slot. Fix by replacing addr variables to be of type
QXLPHYSICAL.
---
server/red_memslots.c | 13 ++++++++-----
server/red_memslots.h | 4 ++--
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/server/red_memslots.c b/server/red_memslots.c
index 8c8f3cc..249b241 100644
--- a/server/red_memslots.c
+++ b/server/red_memslots.c
@@ -19,10 +19,12 @@
#include <config.h>
#endif
+#include <inttypes.h>
+
#include "red_common.h"
#include "red_memslots.h"
-static unsigned long __get_clean_virt(RedMemSlotInfo *info, unsigned long addr)
+static unsigned long __get_clean_virt(RedMemSlotInfo *info, QXLPHYSICAL addr)
{
return addr & info->memslot_clean_virt_mask;
}
@@ -46,7 +48,7 @@ static void print_memslots(RedMemSlotInfo *info)
}
}
-unsigned long get_virt_delta(RedMemSlotInfo *info, unsigned long addr, int group_id)
+unsigned long get_virt_delta(RedMemSlotInfo *info, QXLPHYSICAL addr, int group_id)
{
MemSlot *slot;
int slot_id;
@@ -107,7 +109,7 @@ unsigned long get_virt(RedMemSlotInfo *info, QXLPHYSICAL addr, uint32_t add_size
slot_id = get_memslot_id(info, addr);
if (slot_id > info->num_memslots) {
print_memslots(info);
- PANIC("slot_id too big, addr=%lx", addr);
+ PANIC("slot_id too big, addr=%" PRIx64, addr);
}
slot = &info->mem_slots[group_id][slot_id];
@@ -165,10 +167,11 @@ void red_memslot_info_init(RedMemSlotInfo *info,
info->mem_slots[i] = spice_new0(MemSlot, num_slots);
}
+ /* TODO: use QXLPHYSICAL_BITS */
info->memslot_id_shift = 64 - info->mem_slot_bits;
info->memslot_gen_shift = 64 - (info->mem_slot_bits + info->generation_bits);
- info->memslot_gen_mask = ~((unsigned long)-1 << info->generation_bits);
- info->memslot_clean_virt_mask = (((unsigned long)(-1)) >>
+ info->memslot_gen_mask = ~((QXLPHYSICAL)-1 << info->generation_bits);
+ info->memslot_clean_virt_mask = (((QXLPHYSICAL)(-1)) >>
(info->mem_slot_bits + info->generation_bits));
}
diff --git a/server/red_memslots.h b/server/red_memslots.h
index 75754d0..d50587f 100644
--- a/server/red_memslots.h
+++ b/server/red_memslots.h
@@ -53,10 +53,10 @@ static inline int get_generation(RedMemSlotInfo *info, uint64_t addr)
return (addr >> info->memslot_gen_shift) & info->memslot_gen_mask;
}
-unsigned long get_virt_delta(RedMemSlotInfo *info, unsigned long addr, int group_id);
+unsigned long get_virt_delta(RedMemSlotInfo *info, QXLPHYSICAL addr, int group_id);
void validate_virt(RedMemSlotInfo *info, unsigned long virt, int slot_id,
uint32_t add_size, uint32_t group_id);
-unsigned long get_virt(RedMemSlotInfo *info, unsigned long addr, uint32_t add_size,
+unsigned long get_virt(RedMemSlotInfo *info, QXLPHYSICAL addr, uint32_t add_size,
int group_id);
void *validate_chunk (RedMemSlotInfo *info, QXLPHYSICAL data, uint32_t group_id, uint32_t *data_size_out, QXLPHYSICAL *next_out);
--
1.7.10