语境
- Linux 4.4.0-57-generic #78-Ubuntu SMP Fri Dec 9 23:50:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
- 法语语言环境
代码
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/mman.h>
int main() {
int fd = open( "/tmp/mapped.bin", O_CREAT|O_RDWR|O_SYNC, 0666 );
perror("open");
unsigned char * dst =
(unsigned char *)mmap(
NULL, 64*1024, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0 );
perror("mmap");
static unsigned char src[] = { 1, 3, 5, 7 };
printf("memcpy( %p, {%d,%d,%d,%d}, %zd )\n", dst, src[0], src[1], src[2], src[3], sizeof(src));
memcpy(dst, src, sizeof(src));
perror("memcpy");
return 0;
}
生产
$ gcc -W -Wall -std=c11 src/org/hpms/filemap/BusError.c -o bin/BusError
(no warning, no error)
执行
$ bin/BusError
open: Success
mmap: Success
memcpy( 0x7f51291fe000, {1,3,5,7}, 4 )
Erreur du bus
数据库
(gdb) run
Starting program: /home/aubin/Dev/Java/2017/org.hpms.filemap/bin/BusError
open: Success
mmap: Success
memcpy( 0x7ffff7fe6000, {1,3,5,7}, 4 )
Program received signal SIGBUS, Bus error.
0x00000000004005ac in main () at src/org/hpms/filemap/BusError.c:15
15 memcpy(dst, src, sizeof(src));
(gdb)