From 87485135bae76e5961afa432aa3b954c712d7b52 Mon Sep 17 00:00:00 2001 From: Bill Carson Date: Tue, 8 Nov 2011 14:49:38 +0800 Subject: Replace fixed address shm attachment by an random one 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 Signed-off-by: Eric B Munson --- tests/shm-perms.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'tests') 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); } -- cgit v1.2.1