Original fixed address at 0x80000000 will fail when calling shmat on ARM.
Use the address system provide for us will prevent this failure.
Moreover, add cleanup when shmat failed to release reserved huge pages
otherwise paranoid pool check will fail on this.

Signed-off-by: Bill Carson <bill4car...@gmail.com>
---
 tests/shm-perms.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/tests/shm-perms.c b/tests/shm-perms.c
index 841c155..590a101 100644
--- a/tests/shm-perms.c
+++ b/tests/shm-perms.c
@@ -34,11 +34,10 @@
 
 #define SEGMENT_SIZE   ((size_t)0x4000000)
 #define SEGMENT_KEY    0x82ba15ff
-#define SEGMENT_ADDR   ((void *)0x80000000)
-
 #define STRIDE         0x200000
 
 static int global_shmid = -1;
+void *shm_addr = NULL;
 
 void cleanup(void)
 {
@@ -53,12 +52,14 @@ int attach_segment(size_t segsize, int shmflags, int 
shmperms)
        shmid = shmget(SEGMENT_KEY, segsize, shmflags);
        if (shmid == -1) {
                perror("shmget(SEGMENT)");
+               cleanup();
                exit(EXIT_FAILURE);
        }
 
        /* Attach large segment */
-       if (shmat(shmid, SEGMENT_ADDR, shmperms) == (void *)-1) {
+       if ( (shm_addr = shmat(shmid, shm_addr, shmperms)) == (void *)-1) {
                perror("shmat(SEGMENT)");
+               cleanup();
                exit(EXIT_FAILURE);
        }
 
@@ -90,12 +91,12 @@ int main(int argc, char **argv)
 
        /* Create, attach and part init segment */
        attach_segment(SEGMENT_SIZE, IPC_CREAT|SHM_HUGETLB|0640, 0);
-       p = (char *)SEGMENT_ADDR;
+       p = (char *)shm_addr;
        for (i = 0; i < 4; i++, p += STRIDE)
                memset(p, 0x55, STRIDE);
 
        /* Detach segment */
-       if (shmdt(SEGMENT_ADDR) != 0)
+       if (shmdt(shm_addr) != 0)
                FAIL("shmdt(SEGMENT)");
 
        /* Create children to reattach read-only */
@@ -109,7 +110,7 @@ int main(int argc, char **argv)
                        wait_list[i] = pid;
                } else {
                        attach_segment(0, 0, SHM_RDONLY);
-                       if (shmdt(SEGMENT_ADDR) != 0) {
+                       if (shmdt(shm_addr) != 0) {
                                perror("shmdt(SEGMENT)");
                                exit(EXIT_FAILURE);
                        }
-- 
1.7.1


------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Libhugetlbfs-devel mailing list
Libhugetlbfs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to