Hi!
> +static int page_check(void)
> +{
> +     int pid;
> +     int ret;
> +     int pm;
> +     int num_pages;
> +     long index;
> +     off_t offset;
> +     size_t page_sz;
> +     char maps_dev[PATHLEN];
> +     char pagemap_dev[PATHLEN];
> +     char line[LINELEN];
> +     FILE *maps;
> +     unsigned long vm_start;
> +     unsigned long vm_end;
> +     unsigned long long pagemap;
> +
> +     page_sz = getpagesize();
> +
> +     pid = getpid();
> +     sprintf(maps_dev, "/proc/%d/maps", pid);
> +     sprintf(pagemap_dev, "/proc/%d/pagemap", pid);

Just use "/proc/self/maps" and "/proc/self/pagemap" instead.

> +     maps = fopen(maps_dev, "r");
> +     if (maps == NULL)
> +             tst_brkm(TFAIL | TERRNO, NULL, "Open dev maps failed");
> +
> +     while (fgets(line, LINELEN, maps) != NULL)
> +             if (strstr(line, TEMPFILE) != NULL)
> +                     break;
> +
> +     ret = sscanf(line, "%lX-%lX", &vm_start, &vm_end);
> +     if (ret != 2)
> +             tst_brkm(TFAIL | TERRNO, NULL, "Get address space failed");

This part of the code does not cope with unlikely condition that
TEMPFILE is missing from /proc/self/maps we should fail the test in this
case with proper error message.

> +     num_pages = (vm_end - vm_start) / page_sz;
> +     index = (vm_start / page_sz) * sizeof(unsigned long long);
> +
> +     pm = open(pagemap_dev, O_RDONLY);
> +     if (pm == -1)
> +             tst_brkm(TFAIL | TERRNO, NULL, "Open dev pagemap failed");
> +
> +     offset = lseek(pm, index, SEEK_SET);
> +     if (offset != index)
> +             tst_brkm(TFAIL | TERRNO, NULL, "Reposition offset failed");
> +
> +     while (num_pages > 0) {
> +             ret = read(pm, &pagemap, sizeof(unsigned long long));
> +             if (ret < 0)
> +                     tst_brkm(TFAIL | TERRNO, NULL, "Read pagemap failed");
> +             /*
> +              * Check if the page is present.
> +              */
> +             if (!(pagemap & (1ULL<<63))) {
> +                     close(pm);
> +                     fclose(maps);
> +                     return 1;

I would perpahs be more verbose here and go over all of the pages and
list these that are not mapped, but that is a minor nitpick. 

> +             }
> +             num_pages--;
> +     }
> +
> +     close(pm);
> +     fclose(maps);
> +
> +     return 0;
> +}

-- 
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to