FreeBSD Bugzilla – Attachment 218664 Details for
Bug 250271
[arm64] Weird pmap bug when using O_WRONLY and mmap with PROT_WRITE
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
repro
segv_accerr.c (text/plain), 1.14 KB, created by
Emmanuel Vadot
on 2020-10-11 12:51:49 UTC
(
hide
)
Description:
repro
Filename:
MIME Type:
Creator:
Emmanuel Vadot
Created:
2020-10-11 12:51:49 UTC
Size:
1.14 KB
patch
obsolete
>#include <sys/mman.h> >#include <sys/stat.h> >#include <err.h> >#include <fcntl.h> >#include <unistd.h> >#include <string.h> > >int >main(int argc, char *argv[]) >{ > int dir; > int fd1, fd2; > char *buf1, *buf2; > struct stat s1; > > if (argc != 2) > errx(1, "Usage: segv_accerr directory"); > > dir = open(argv[1], O_DIRECTORY |O_RDONLY|O_CLOEXEC); > if (dir == -1) > errx(1, "Can't open %s", argv[1]); > > if (fstatat(dir, "file.sample", &s1, 0) == -1) { > errx(1, "Can't stat file.sample"); > } > > fd1 = openat(dir, "file.sample", O_RDONLY); > if (fd1 == -1) { > errx(1, "Can't open file.sample"); > } > fd2 = openat(dir, "file", O_WRONLY | O_CREAT | O_TRUNC, DEFFILEMODE); > if (fd2 == -1) { > errx(1, "Can't open file"); > } > > if (ftruncate(fd2, s1.st_size) != 0) { > errx(1, "Can't ftruncate file"); > } > buf1 = mmap(NULL, s1.st_size, PROT_READ, MAP_SHARED, fd1, 0); > if (buf1 == NULL) { > errx(1, "Can't mmap file.sample"); > } > buf2 = mmap(NULL, s1.st_size, PROT_WRITE, MAP_SHARED, fd2, 0); > if (buf2 == NULL) { > errx(1, "Can't mmap file"); > } > > memcpy(buf2, buf1, s1.st_size); > > munmap(buf1, s1.st_size); > munmap(buf2, s1.st_size); > fsync(fd2); > > close(fd1); > close(fd2); > > return (0); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 250271
: 218664