+ rc = mmap_tst7_func(mnt, 0);
+ if (rc != 0)
+ return rc;
+ rc = mmap_tst7_func(mnt, 1);
+ return rc;
+}
+
+static int mmap_tst8(char *mnt)
+{
+ char fname[256];
+ char *buf = MAP_FAILED;
+ int fd = -1;
+ int rc = 0;
+ pid_t pid;
+ char xyz[page_size * 2];
+
+ if (snprintf(fname, 256, "%s/mmap_tst8", mnt) >= 256) {
+ fprintf(stderr, "dir name too long\n");
+ rc = -ENAMETOOLONG;
+ goto out;
+ }
+ fd = open(fname, O_RDWR | O_CREAT, 0644);
+ if (fd == -1) {
+ perror("open");
+ rc = -errno;
+ goto out;
+ }
+ if (ftruncate(fd, page_size) == -1) {
+ perror("truncate");
+ rc = -errno;
+ goto out;
+ }
+ buf = mmap(NULL, page_size * 2,
+ PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (buf == MAP_FAILED) {
+ perror("mmap");
+ rc = -errno;
+ goto out;
+ }
+
+ pid = fork();
+ if (pid == 0) { /* child */
+ memcpy(xyz, buf, page_size * 2);
+ /* shouldn't reach here. */
+ exit(0);
+ } else if (pid > 0) { /* parent */
+ int status = 0;
+
+ pid = waitpid(pid, &status, 0);
+ if (pid < 0) {
+ perror("wait");
+ rc = -errno;
+ goto out;
+ }
+
+ rc = -EFAULT;
+ if (WIFSIGNALED(status) && SIGBUS == WTERMSIG(status))
+ rc = 0;
+ } else {
+ perror("fork");
+ rc = -errno;
+ }
+
+out:
+ if (buf != MAP_FAILED)
+ munmap(buf, page_size);
+ if (fd != -1)
+ close(fd);
+ return rc;
+}
+
+static int mmap_tst9(char *mnt)
+{
+ char fname[256];
+ char *buf = MAP_FAILED;
+ int fd = -1;
+ int rc = 0;
+
+ if (snprintf(fname, 256, "%s/mmap_tst9", mnt) >= 256) {
+ fprintf(stderr, "dir name too long\n");
+ rc = -ENAMETOOLONG;
+ goto out;
+ }
+ if (unlink(fname) == -1 && errno != ENOENT) {
+ perror("unlink");
+ rc = -errno;
+ goto out;
+ }
+ fd = open(fname, O_RDWR | O_CREAT, 0644);
+ if (fd == -1) {
+ perror("open");
+ rc = -errno;
+ goto out;
+ }
+ buf = mmap(NULL, page_size * 2,
+ PROT_READ, MAP_PRIVATE, fd, (loff_t)(-10 * page_size));
+ if (buf == MAP_FAILED) {
+ perror("mmap");
+ rc = -errno;
+ goto out;
+ }
+ rc = write(STDOUT_FILENO, buf, 2 * page_size);
+ if (rc != -1) {
+ fprintf(stderr, "write succeded with %d instead of failing\n",
+ rc);
+ rc = -EINVAL;
+ goto out;
+ } else if (errno != EFAULT) {
+ fprintf(stderr, "write failed with %d instead of EFAULT(%d)\n",
+ errno, EFAULT);
+ rc = -errno;
+ goto out;
+ }
+ rc = 0;
+out:
+ if (buf != MAP_FAILED)
+ munmap(buf, page_size * 2);
+ if (fd != -1)
+ close(fd);
+ return rc;