Skip to content

Instantly share code, notes, and snippets.

@travispaul
Last active December 15, 2016 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save travispaul/eba34627ec69516fd4a8b03d6daff3ac to your computer and use it in GitHub Desktop.
Save travispaul/eba34627ec69516fd4a8b03d6daff3ac to your computer and use it in GitHub Desktop.
mmap /dev/mmem0.0c test
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
int
main(int argc, char **argv)
{
int fd;
unsigned char *data;
printf("fopen %s\n", argv[1]);
fd = open(argv[1], O_RDONLY);
if (fd == -1) {
fprintf(stderr, "error:\n open %s: %s\n",
argv[1], strerror(errno));
exit(1);
}
data = mmap(0, 1, PROT_READ, MAP_PRIVATE, fd, 0);
if (data == MAP_FAILED) {
fprintf(stderr, "error:\n mmap %d: \n",
argv[1], strerror(errno));
exit(1);
}
if (argc > 2)
printf("data[0] = '%c'\n", data[0]);
}
# echo X > test.txt
# ./mtest test.txt Y
fopen test.txt
data[0] = 'X'
# ./mtest /dev/mmem0.0c
fopen /dev/mmem0.0c
# echo $?
0
# ./mtest /dev/mmem0.0c Y
fopen /dev/mmem0.0c
panic: tlb_exception: invalid user-space access from kernel mode
... (didn't copy this) ...
cpu0: Begin traceback
trace by frame address is not supported
cpu0: End traceback...
rebooting...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment