getrusage: Fix memory_stat_mapped_file when SIGBUS occurs in file map
Change-Id: Ia4686f32a3c888d5c886ab6cc6c2b510885447f5 Refs: #1422
This commit is contained in:
committed by
Masamichi Takagi
parent
baa7a6adcb
commit
9c7d0cfaec
49
test/issues/1422/filemap_sigbus.c
Normal file
49
test/issues/1422/filemap_sigbus.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/* filemap_sigbus.c COPYRIGHT FUJITSU LIMITED 2019 */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int ret = -1;
|
||||
int fd = -1;
|
||||
int i = 0;
|
||||
unsigned long *buf = NULL;
|
||||
const long pgsize = sysconf(_SC_PAGESIZE);
|
||||
|
||||
if (argc != 2) {
|
||||
printf("args invalid.\n");
|
||||
ret = 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
fd = open(argv[1], O_RDWR);
|
||||
if (fd == -1) {
|
||||
perror("open");
|
||||
goto out;
|
||||
}
|
||||
|
||||
buf = (unsigned long *)mmap(0, 3 * pgsize, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE, fd, 0);
|
||||
if (buf == MAP_FAILED) {
|
||||
perror("mmap");
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Generate SIGBUS */
|
||||
for (i = 0; i < 3 * pgsize / sizeof(unsigned long); i++) {
|
||||
buf[i] = i;
|
||||
}
|
||||
|
||||
munmap(buf, 3 * pgsize);
|
||||
|
||||
close(fd);
|
||||
|
||||
ret = 0;
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user