mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-21 21:17:19 +00:00
a46a3a2668
This makes it a compile-time error to call a function that semantically takes no parameters with a nonzero number of arguments. Previously, such code would still compile, but risk blowing up the stack if a compiler chose to use something other than caller-cleanup calling conventions.
50 lines
933 B
C
50 lines
933 B
C
#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(void)
|
|
{
|
|
int fd = open("/dev/kvmfr0", O_RDWR);
|
|
if (fd < 0)
|
|
{
|
|
perror("open");
|
|
return -1;
|
|
}
|
|
|
|
unsigned long size = ioctl(fd, KVMFR_DMABUF_GETSIZE , 0);
|
|
printf("Size: %lu MiB\n", size / 1024 / 1024);
|
|
|
|
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;
|
|
} |