/* The new domain's shared-info frame number. */
unsigned long shared_info_frame;
unsigned char shared_info_page[PAGE_SIZE]; /* saved contents from file */
- shared_info_either_t *old_shared_info = (shared_info_either_t *)shared_info_page;
+ shared_info_either_t *old_shared_info =
+ (shared_info_either_t *)shared_info_page;
shared_info_either_t *new_shared_info;
/* A copy of the CPU context of the guest. */
guest_width = sizeof(unsigned long);
pt_levels = (guest_width == 8) ? 4 : (pt_levels == 2) ? 2 : 3;
- if ( lock_pages(&ctxt, sizeof(ctxt)) )
- {
- /* needed for build domctl, but might as well do early */
- ERROR("Unable to lock ctxt");
- return 1;
- }
-
if ( !hvm )
{
/* Load the p2m frame list, plus potential extended info chunk */
/* We want zeroed memory so use calloc rather than malloc. */
p2m = calloc(p2m_size, MAX(guest_width, sizeof (xen_pfn_t)));
pfn_type = calloc(p2m_size, sizeof(unsigned long));
- region_mfn = calloc(MAX_BATCH_SIZE, sizeof(xen_pfn_t));
- p2m_batch = calloc(MAX_BATCH_SIZE, sizeof(xen_pfn_t));
+
+ region_mfn = xg_memalign(PAGE_SIZE, ROUNDUP(
+ MAX_BATCH_SIZE * sizeof(xen_pfn_t), PAGE_SHIFT));
+ p2m_batch = xg_memalign(PAGE_SIZE, ROUNDUP(
+ MAX_BATCH_SIZE * sizeof(xen_pfn_t), PAGE_SHIFT));
if ( (p2m == NULL) || (pfn_type == NULL) ||
(region_mfn == NULL) || (p2m_batch == NULL) )
goto out;
}
+ memset(region_mfn, 0,
+ ROUNDUP(MAX_BATCH_SIZE * sizeof(xen_pfn_t), PAGE_SHIFT));
+ memset(p2m_batch, 0,
+ ROUNDUP(MAX_BATCH_SIZE * sizeof(xen_pfn_t), PAGE_SHIFT));
+
if ( lock_pages(region_mfn, sizeof(xen_pfn_t) * MAX_BATCH_SIZE) )
{
ERROR("Could not lock region_mfn");
}
}
+ if ( lock_pages(&ctxt, sizeof(ctxt)) )
+ {
+ ERROR("Unable to lock ctxt");
+ return 1;
+ }
+
for ( i = 0; i <= max_vcpu_id; i++ )
{
if ( !(vcpumap & (1ULL << i)) )
sent_last_iter = p2m_size;
/* Setup to_send / to_fix and to_skip bitmaps */
- to_send = malloc(BITMAP_SIZE);
+ to_send = xg_memalign(PAGE_SIZE, ROUNDUP(BITMAP_SIZE, PAGE_SHIFT));
to_fix = calloc(1, BITMAP_SIZE);
- to_skip = malloc(BITMAP_SIZE);
+ to_skip = xg_memalign(PAGE_SIZE, ROUNDUP(BITMAP_SIZE, PAGE_SHIFT));
if ( !to_send || !to_fix || !to_skip )
{
analysis_phase(xc_handle, dom, p2m_size, to_skip, 0);
- /* We want zeroed memory so use calloc rather than malloc. */
- pfn_type = calloc(MAX_BATCH_SIZE, sizeof(*pfn_type));
+ pfn_type = xg_memalign(PAGE_SIZE, ROUNDUP(
+ MAX_BATCH_SIZE * sizeof(*pfn_type), PAGE_SHIFT));
pfn_batch = calloc(MAX_BATCH_SIZE, sizeof(*pfn_batch));
if ( (pfn_type == NULL) || (pfn_batch == NULL) )
{
errno = ENOMEM;
goto out;
}
+ memset(pfn_type, 0,
+ ROUNDUP(MAX_BATCH_SIZE * sizeof(*pfn_type), PAGE_SHIFT));
if ( lock_pages(pfn_type, MAX_BATCH_SIZE * sizeof(*pfn_type)) )
{
- ERROR("Unable to lock");
+ ERROR("Unable to lock pfn_type array");
goto out;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <malloc.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
int pin_table(int xc_handle, unsigned int type, unsigned long mfn,
domid_t dom);
+/* Grrr portability */
+static inline void *xg_memalign(size_t alignment, size_t size)
+{
+#if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 600
+ int ret;
+ void *ptr;
+ ret = posix_memalign(&ptr, alignment, size);
+ if (ret != 0)
+ return NULL;
+ return ptr;
+#elif defined(_BSD)
+ return valloc(size);
+#else
+ return memalign(alignment, size);
+#endif
+}
+
#endif /* XG_PRIVATE_H */