Created
February 12, 2019 03:17
-
-
Save hankliu5/13613855fc2941afefc15605849d07af to your computer and use it in GitHub Desktop.
This file contains 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 <fcntl.h> /* O_ constants */ | |
#include <unistd.h> /* ftruncate */ | |
#include <sys/mman.h> /* mmap */ | |
#include <string.h> | |
int main() { | |
int fd; | |
char *map; | |
char *name = "test.txt"; | |
fd = open(name, O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600); | |
posix_fallocate(fd, 0, 0); | |
/* THIS is the cause of the problem. */ | |
/*ftruncate(fd, size);*/ | |
map = mmap(NULL, 4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); | |
/* This is what generates the SIGBUS. */ | |
*map = 0; | |
munmap(map, 4); | |
close(fd); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment