2020-01-13 02:39:24 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
|
|
#include "kvmfr.h"
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int fd = open("/dev/kvmfr0", O_RDWR);
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
perror("open");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long size = ioctl(fd, KVMFR_DMABUF_GETSIZE , 0);
|
2020-01-13 04:42:45 +00:00
|
|
|
printf("Size: %lu MiB\n", size / 1024 / 1024);
|
2020-01-13 02:39:24 +00:00
|
|
|
|
|
|
|
struct kvmfr_dmabuf_create create =
|
|
|
|
{
|
|
|
|
.flags = KVMFR_DMABUF_FLAG_CLOEXEC,
|
|
|
|
.offset = 0x0,
|
|
|
|
.size = size,
|
|
|
|
};
|
|
|
|
int dmaFd = ioctl(fd, KVMFR_DMABUF_CREATE, &create);
|
|
|
|
if (dmaFd < 0)
|
|
|
|
{
|
|
|
|
perror("ioctl");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void * mem = mmap(NULL, create.size, PROT_READ | PROT_WRITE, MAP_SHARED, dmaFd, 0);
|
|
|
|
if (!mem)
|
|
|
|
{
|
|
|
|
perror("mmap");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(mem, 0xAA, create.size);
|
|
|
|
munmap(mem, create.size);
|
|
|
|
close(fd);
|
|
|
|
return 0;
|
|
|
|
}
|