#include <xen/sys/gntdev.h>
+#include <xenctrl.h>
#include <xen-tools/libs.h>
#include "private.h"
-#define PAGE_SHIFT 12
-#define PAGE_SIZE (1UL << PAGE_SHIFT)
-#define PAGE_MASK (~(PAGE_SIZE-1))
-
#define DEVXEN "/dev/xen/gntdev"
int osdep_gnttab_open(xengnttab_handle *xgt)
int domids_stride;
unsigned int refs_size = ROUNDUP(count *
sizeof(struct ioctl_gntdev_grant_ref),
- PAGE_SHIFT);
+ XC_PAGE_SHIFT);
+ int os_page_size = getpagesize();
domids_stride = (flags & XENGNTTAB_GRANT_MAP_SINGLE_DOMAIN) ? 0 : 1;
- if ( refs_size <= PAGE_SIZE )
+ if ( refs_size <= os_page_size )
map.refs = malloc(refs_size);
else
{
goto out;
}
- addr = mmap(NULL, PAGE_SIZE * count, prot, MAP_SHARED, fd,
+ addr = mmap(NULL, XC_PAGE_SIZE * count, prot, MAP_SHARED, fd,
map.index);
if ( addr != MAP_FAILED )
{
notify.index = map.index;
notify.action = 0;
- if ( notify_offset < PAGE_SIZE * count )
+ if ( notify_offset < XC_PAGE_SIZE * count )
{
notify.index += notify_offset;
notify.action |= UNMAP_NOTIFY_CLEAR_BYTE;
if ( rv )
{
GTERROR(xgt->logger, "ioctl SET_UNMAP_NOTIFY failed");
- munmap(addr, count * PAGE_SIZE);
+ munmap(addr, count * XC_PAGE_SIZE);
addr = MAP_FAILED;
}
}
}
out:
- if ( refs_size > PAGE_SIZE )
+ if ( refs_size > os_page_size )
munmap(map.refs, refs_size);
else
free(map.refs);
}
/* Next, unmap the memory. */
- if ( (rc = munmap(start_address, count * PAGE_SIZE)) )
+ if ( (rc = munmap(start_address, count * XC_PAGE_SIZE)) )
return rc;
/* Finally, unmap the driver slots used to store the grant information. */
goto out;
}
- area = mmap(NULL, count * PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
+ area = mmap(NULL, count * XC_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
fd, gref_info.index);
if ( area == MAP_FAILED )
notify.index = gref_info.index;
notify.action = 0;
- if ( notify_offset < PAGE_SIZE * count )
+ if ( notify_offset < XC_PAGE_SIZE * count )
{
notify.index += notify_offset;
notify.action |= UNMAP_NOTIFY_CLEAR_BYTE;
if ( err )
{
GSERROR(xgs->logger, "ioctl SET_UNMAP_NOTIFY failed");
- munmap(area, count * PAGE_SIZE);
+ munmap(area, count * XC_PAGE_SIZE);
area = NULL;
}
int osdep_gntshr_unshare(xengntshr_handle *xgs,
void *start_address, uint32_t count)
{
- return munmap(start_address, count * PAGE_SIZE);
+ return munmap(start_address, count * XC_PAGE_SIZE);
}
/*
#include <xen/sys/gntdev.h>
#include <xen/sys/gntalloc.h>
+#include <xenctrl.h>
#include <xen-tools/libs.h>
#include "private.h"
-#define PAGE_SHIFT 12
-#define PAGE_SIZE (1UL << PAGE_SHIFT)
-#define PAGE_MASK (~(PAGE_SIZE-1))
-
#define DEVXEN "/dev/xen/"
#ifndef O_CLOEXEC
int fd = xgt->fd;
struct ioctl_gntdev_map_grant_ref *map;
unsigned int map_size = sizeof(*map) + (count - 1) * sizeof(map->refs[0]);
+ int os_page_size = sysconf(_SC_PAGESIZE);
void *addr = NULL;
int domids_stride = 1;
int i;
if (flags & XENGNTTAB_GRANT_MAP_SINGLE_DOMAIN)
domids_stride = 0;
- if ( map_size <= PAGE_SIZE )
+ if ( map_size <= os_page_size )
map = alloca(map_size);
else
{
- map_size = ROUNDUP(map_size, PAGE_SHIFT);
+ map_size = ROUNDUP(map_size, XC_PAGE_SHIFT);
map = mmap(NULL, map_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON | MAP_POPULATE, -1, 0);
if ( map == MAP_FAILED )
}
retry:
- addr = mmap(NULL, PAGE_SIZE * count, prot, MAP_SHARED, fd,
+ addr = mmap(NULL, XC_PAGE_SIZE * count, prot, MAP_SHARED, fd,
map->index);
if (addr == MAP_FAILED && errno == EAGAIN)
struct ioctl_gntdev_unmap_notify notify;
notify.index = map->index;
notify.action = 0;
- if (notify_offset < PAGE_SIZE * count) {
+ if (notify_offset < XC_PAGE_SIZE * count) {
notify.index += notify_offset;
notify.action |= UNMAP_NOTIFY_CLEAR_BYTE;
}
rv = ioctl(fd, IOCTL_GNTDEV_SET_UNMAP_NOTIFY, ¬ify);
if (rv) {
GTERROR(xgt->logger, "ioctl SET_UNMAP_NOTIFY failed");
- munmap(addr, count * PAGE_SIZE);
+ munmap(addr, count * XC_PAGE_SIZE);
addr = MAP_FAILED;
}
}
}
out:
- if ( map_size > PAGE_SIZE )
+ if ( map_size > os_page_size )
munmap(map, map_size);
return addr;
}
/* Next, unmap the memory. */
- if ( (rc = munmap(start_address, count * PAGE_SIZE)) )
+ if ( (rc = munmap(start_address, count * XC_PAGE_SIZE)) )
return rc;
/* Finally, unmap the driver slots used to store the grant information. */
goto out;
}
- area = mmap(NULL, count * PAGE_SIZE, PROT_READ | PROT_WRITE,
+ area = mmap(NULL, count * XC_PAGE_SIZE, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, gref_info->index);
if (area == MAP_FAILED) {
notify.index = gref_info->index;
notify.action = 0;
- if (notify_offset < PAGE_SIZE * count) {
+ if (notify_offset < XC_PAGE_SIZE * count) {
notify.index += notify_offset;
notify.action |= UNMAP_NOTIFY_CLEAR_BYTE;
}
err = ioctl(fd, IOCTL_GNTALLOC_SET_UNMAP_NOTIFY, ¬ify);
if (err) {
GSERROR(xgs->logger, "ioctl SET_UNMAP_NOTIFY failed");
- munmap(area, count * PAGE_SIZE);
+ munmap(area, count * XC_PAGE_SIZE);
area = NULL;
}
int osdep_gntshr_unshare(xengntshr_handle *xgs,
void *start_address, uint32_t count)
{
- return munmap(start_address, count * PAGE_SIZE);
+ return munmap(start_address, count * XC_PAGE_SIZE);
}
/*
#include <sys/ioctl.h>
#include <sys/mman.h>
+#include <xenctrl.h>
#include <xen/xen.h>
#include <xen/xenio.h>
#include "private.h"
-#define PAGE_SHIFT 12
-#define PAGE_SIZE (1UL << PAGE_SHIFT)
-#define PAGE_MASK (~(PAGE_SIZE-1))
-
#define DEVXEN "/kern/xen/privcmd"
int osdep_gnttab_open(xengnttab_handle *xgt)
}
map.count = count;
- addr = mmap(NULL, count * PAGE_SIZE,
+ addr = mmap(NULL, count * XC_PAGE_SIZE,
prot, flags | MAP_ANON | MAP_SHARED, -1, 0);
if ( map.va == MAP_FAILED )
{
GTERROR(xgt->logger, "osdep_gnttab_grant_map: mmap failed");
- munmap((void *)map.va, count * PAGE_SIZE);
+ munmap((void *)map.va, count * XC_PAGE_SIZE);
addr = MAP_FAILED;
}
map.va = addr;
map.notify.offset = 0;
map.notify.action = 0;
- if ( notify_offset < PAGE_SIZE * count )
+ if ( notify_offset < XC_PAGE_SIZE * count )
{
map.notify.offset = notify_offset;
map.notify.action |= UNMAP_NOTIFY_CLEAR_BYTE;
{
GTERROR(xgt->logger,
"ioctl IOCTL_GNTDEV_MMAP_GRANT_REF failed: %d", rv);
- munmap(addr, count * PAGE_SIZE);
+ munmap(addr, count * XC_PAGE_SIZE);
addr = MAP_FAILED;
}
}
/* Next, unmap the memory. */
- rc = munmap(start_address, count * PAGE_SIZE);
+ rc = munmap(start_address, count * XC_PAGE_SIZE);
return rc;
}
alloc.domid = domid;
alloc.flags = writable ? GNTDEV_ALLOC_FLAG_WRITABLE : 0;
alloc.count = count;
- area = mmap(NULL, count * PAGE_SIZE,
+ area = mmap(NULL, count * XC_PAGE_SIZE,
PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0);
if ( area == MAP_FAILED )
alloc.notify.offset = 0;
alloc.notify.action = 0;
- if ( notify_offset < PAGE_SIZE * count )
+ if ( notify_offset < XC_PAGE_SIZE * count )
{
alloc.notify.offset = notify_offset;
alloc.notify.action |= UNMAP_NOTIFY_CLEAR_BYTE;
if ( err )
{
GSERROR(xgs->logger, "IOCTL_GNTDEV_ALLOC_GRANT_REF failed");
- munmap(area, count * PAGE_SIZE);
+ munmap(area, count * XC_PAGE_SIZE);
area = MAP_FAILED;
goto out;
}
int osdep_gntshr_unshare(xengntshr_handle *xgs,
void *start_address, uint32_t count)
{
- return munmap(start_address, count * PAGE_SIZE);
+ return munmap(start_address, count * XC_PAGE_SIZE);
}
/*