[LTP] [PATCH 1/5] mremap01: Convert to new API
Cyril Hrubis
chrubis@suse.cz
Thu Aug 6 13:45:43 CEST 2026
Hi!
> - /*
> - * Call mmap to map virtual memory (memsize bytes) from the
> - * beginning of temporary file (offset is 0) into memory.
> - */
> - addr = mmap(0, memsize, PROT_WRITE, MAP_SHARED, fildes, 0);
> + for (ind = 0; ind < newsize; ind++)
> + addr[ind] = (char)ind;
>
> - /* Check for the return value of mmap() */
> - if (addr == (char *)MAP_FAILED) {
> - tst_brkm(TBROK, cleanup, "mmaping Failed on %s", TEMPFILE);
> - }
> + SAFE_MSYNC(addr, newsize, MS_SYNC);
>
> - /* Stretch the file to newsize of virtual memory block */
> - if (lseek(fildes, (off_t) newsize, SEEK_SET) != (off_t) newsize) {
> - tst_brkm(TBROK, cleanup, "lseek() to %d offset pos. Failed, "
> - "error=%d : %s", newsize, errno, strerror(errno));
> - }
> + if (verify_file())
> + tst_res(TFAIL, "mremap()'d region did not sync to the file");
> + else
> + tst_res(TPASS, "Functionality of mremap() is correct");
>
> - /* Write one byte data into temporary file */
> - if (write(fildes, "\0", 1) != 1) {
> - tst_brkm(TBROK | TERRNO, cleanup, "writing to %s failed",
> - TEMPFILE);
> - }
We should probably ftruncate(fd, 0) here so that we start with the same
state on -i 10.
> + SAFE_MUNMAP(addr, newsize);
> + addr = MAP_FAILED;
Can we patch SAFE_MUNMAP() to set the addr to MAP_FAILED as we do in
SAFE_CLOSE()?
Otherwise:
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list