/* probe readable KVA ranges via /dev/kmem */
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>

int
main(int argc, char **argv)
{
	uint64_t start = strtoull(argv[1], NULL, 16);
	uint64_t end = strtoull(argv[2], NULL, 16);
	uint64_t step = strtoull(argv[3], NULL, 16);
	uint64_t a;
	int fd = open("/dev/kmem", O_RDONLY);
	unsigned char b[8];
	int readable = -1;

	for (a = start; a < end; a += step) {
		int ok = (pread(fd, b, 8, (off_t)a) == 8);
		if (ok != readable) {
			printf("%s 0x%llx\n", ok ? "R " : "UR", (unsigned long long)a);
			readable = ok;
		}
	}
	return 0;
}
