{
size_t size = npages * XC_PAGE_SIZE;
void *p;
+ int rc, saved_errno;
/* Address returned by mmap is page aligned. */
p = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_LOCKED, -1, 0);
+ if ( p == MAP_FAILED )
+ {
+ PERROR("xc_alloc_hypercall_buffer: mmap failed");
+ return NULL;
+ }
/* Do not copy the VMA to child process on fork. Avoid the page being COW
on hypercall. */
- madvise(p, npages * XC_PAGE_SIZE, MADV_DONTFORK);
+ rc = madvise(p, npages * XC_PAGE_SIZE, MADV_DONTFORK);
+ if ( rc < 0 )
+ {
+ PERROR("xc_alloc_hypercall_buffer: madvise failed");
+ goto out;
+ }
+
return p;
+
+out:
+ saved_errno = errno;
+ (void)munmap(p, size);
+ errno = saved_errno;
+ return NULL;
}
static void linux_privcmd_free_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages)