#include #include #include #include #include static const off_t map_address = 0xa0000; static const size_t map_size = 0x1000; static int testit(int fd) { void *p; int rv; p = mmap(NULL, 2 * map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, map_address); if (p == MAP_FAILED) { perror("mmap"); return -1; } rv = *(char *) p; if (munmap(p, map_size) == -1) { perror("munmap"); return -1; } return rv; } int main(void) { int fd, rv; fd = open("/dev/mem", O_RDWR); if (fd == -1) { perror("open"); return 1; } rv = testit(fd); close(fd); return rv; }