summaryrefslogtreecommitdiff
path: root/contrib/libdha/kernelhelper/test.c
blob: d2d807f3fdc9dea2b8dc23645662c6d2d2462c8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <string.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <stdlib.h>

#include "dhahelper.h"

int main(int argc, char *argv[])
{
    int fd;
    int ret;

    fd = open("/dev/dhahelper", O_RDWR);
    if(fd < 0){
	perror("dev/dhahelper");
	exit(1);
    }

    ioctl(fd, DHAHELPER_GET_VERSION, &ret);

    printf("api version: %d\n", ret);
    if (ret != API_VERSION)
	printf("incompatible api!\n");

    {
	void *mem;
	unsigned long size=256;
	mem = mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
	printf("allocated to %p\n", mem); 

	if (argc > 1)
	    if (mem != 0)
	    {
 		int i;
 
		for (i = 0; i < 256; i++)
		    printf("[%x] ", *(int *)(mem+i));
		printf("\n");
	    }

	munmap((void *)mem, size);
    }

    return(0);
}