Currently, the task-size-overrun tests determines TASK_SIZE by
searching the address space from the top of the stack mapping, until
it gets an mmap() error indicating that it's run out of address space.

For this to work safely, the stack must be the highest existing
mapping, which is not always true for recent kernels, at least on i386
and x86_64.

This patch fixes the test by having it search from the top of the
highest existing mapping, whether or not that is the stack.

Signed-off-by: David Gibson <[EMAIL PROTECTED]>

Index: libhugetlbfs/tests/task-size-overrun.c
===================================================================
--- libhugetlbfs.orig/tests/task-size-overrun.c 2007-03-07 13:31:11.000000000 
+1100
+++ libhugetlbfs/tests/task-size-overrun.c      2007-03-07 13:39:21.000000000 
+1100
@@ -33,14 +33,7 @@
 
 #define MAPS_BUF_SZ 4096
 
-static int endswith(const char *buf, const char *tail)
-{
-       const char *p = buf + strlen(buf) - strlen(tail);
-
-       return strcmp(p, tail) == 0;
-}
-
-static unsigned long find_end_stack(void)
+static unsigned long find_last_mapped(void)
 {
        FILE *f;
        char line[MAPS_BUF_SZ];
@@ -56,18 +49,15 @@
 
        do {
                tmp = fgets(line, MAPS_BUF_SZ, f);
-               if (!tmp)
-                       FAIL("Couldn't find maps line for stack");
-       } while (! endswith(line, "[stack]\n"));
-
+       } while (tmp);
        fclose(f);
 
-       verbose_printf("Stack map: %s", line);
+       verbose_printf("Last map: %s", line);
        ret = sscanf(line, "%lx-%lx %*s %lx %*s %ld %*s", &start, &end, &off, 
&ino);
        if (ret != 4)
                FAIL("Couldn't parse /proc/self/maps line: %s\n", line);
 
-       verbose_printf("Stack mapped at 0x%lx-0x%lx\n", start, end);
+       verbose_printf("Last map at 0x%lx-0x%lx\n", start, end);
        return end;
 }
 
@@ -76,7 +66,7 @@
        unsigned long addr;
        void *p;
 
-       addr = find_end_stack();
+       addr = find_last_mapped();
        if (!addr || ((addr % getpagesize()) != 0))
                FAIL("Bogus stack end address, 0x%lx!?", addr);
 

-- 
David Gibson                    | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
                                | _way_ _around_!
http://www.ozlabs.org/~dgibson

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Libhugetlbfs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to