[LTP] [PATCH] mmap01: Convert to new API
Ricardo B. Marliere
rbm@suse.com
Sat Nov 16 15:13:52 CET 2024
On 15 Nov 24 14:57, Jan Stancek wrote:
> On Wed, Nov 13, 2024 at 8:15 PM Ricardo B. Marliere via ltp
> <ltp@lists.linux.it> wrote:
> <snip>
> > + addr = mmap(NULL, page_sz, PROT_READ | PROT_WRITE,
> > + MAP_FILE | MAP_SHARED, fildes, 0);
> > +
> > + if (addr == MAP_FAILED) {
> > + tst_res(TFAIL | TERRNO, "mmap of %s failed", TEMPFILE);
> > + return;
> > + }
>
> Can we use SAFE_MMAP here?
>
> > +
> > + /*
> > + * Check if mapped memory area beyond EOF are
> > + * zeros and changes beyond EOF are not written
> > + * to file.
> > + */
> > + if (memcmp(&addr[file_sz], dummy, page_sz - file_sz))
> > + tst_brk(TFAIL, "mapped memory area contains invalid data");
> > +
> > + /*
> > + * Initialize memory beyond file size
> > + */
> > + addr[file_sz] = 'X';
> > + addr[file_sz + 1] = 'Y';
> > + addr[file_sz + 2] = 'Z';
> > +
> > + /*
> > + * Synchronize the mapped memory region
> > + * with the file.
> > + */
> > + if (msync(addr, page_sz, MS_SYNC) != 0) {
> > + tst_res(TFAIL | TERRNO, "failed to synchronize mapped file");
> > + return;
> > + }
> > +
> > + /*
> > + * Now, search for the pattern 'XYZ' in the temporary file.
> > + * The pattern should not be found and the return value should be 1.
> > + */
> > + if (system(cmd_buffer) != 0) {
> > + tst_res(TPASS, "Functionality of mmap() successful");
> > + } else {
> > + tst_res(TFAIL, "Specified pattern found in file");
> > + return;
> > }
> >
> > - cleanup();
> > - tst_exit();
> > + /*
> > + * Clean up things in case we are looping
> > + * Unmap the mapped memory
> > + */
> > + if (munmap(addr, page_sz) != 0) {
> > + tst_res(TFAIL | TERRNO, "munmap failed");
> > + return;
> > + }
>
> and SAFE_MUNMAP here? Otherwise this looks OK to me.
Thanks for the review! I'll send a new version.
- Ricardo.
>
> Regards,
> Jan
>
More information about the ltp
mailing list