__ptr_t mmap(__ptr_t addr, size_t len, int prot, int flags, int fd, __off_t offset) { unsigned long page_size = sysconf(_SC_PAGESIZE); unsigned long pgoff; if (offset & (page_size - 1)) { __set_errno(EINVAL); return MAP_FAILED; } pgoff = (unsigned long)offset >> (31 - __builtin_clz(page_size)); return mmap2(addr, len, prot, flags, fd, pgoff); }
int main(int argc, char *argv[]) { char *msg; int lc; void *map, *remap; off_t pgoff; #if __WORDSIZE != 32 tst_brkm(TCONF, NULL, "test is designed for 32-bit system only."); #endif msg = parse_opts(argc, argv, NULL, NULL); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); pgsz = sysconf(_SC_PAGE_SIZE); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; fd = open(TESTFILE, O_RDWR); if (fd == -1) tst_brkm(TBROK | TERRNO, NULL, "open %s", TESTFILE); pgoff = ULONG_MAX - 1; map = mmap2(NULL, pgsz, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, pgoff); if (map == MAP_FAILED) tst_brkm(TBROK | TERRNO, cleanup, "mmap2"); remap = mremap(map, pgsz, 2 * pgsz, 0); if (remap == MAP_FAILED) { if (errno == EINVAL) tst_resm(TPASS, "mremap failed as expected."); else tst_resm(TFAIL | TERRNO, "mremap"); munmap(map, pgsz); } else { tst_resm(TFAIL, "mremap succeeded unexpectedly."); munmap(remap, 2 * pgsz); } close(fd); } cleanup(); tst_exit(); }