Last active
December 15, 2016 23:12
-
-
Save travispaul/eba34627ec69516fd4a8b03d6daff3ac to your computer and use it in GitHub Desktop.
mmap /dev/mmem0.0c test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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