aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Carson <bill4carson@gmail.com>2011-11-08 14:49:38 +0800
committerEric B Munson <emunson@mgebm.net>2011-12-07 10:42:32 -0500
commit87485135bae76e5961afa432aa3b954c712d7b52 (patch)
tree77138a2b573edaf46cc80829f3aff156e57c1690
parentd6f3e749dd1206e84e4ba338d3cd62f08655296b (diff)
downloadlibhugetlbfs-87485135bae76e5961afa432aa3b954c712d7b52.tar.gz
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 <bill4carson@gmail.com> Signed-off-by: Eric B Munson <emunson@mgebm.net>
-rw-r--r--tests/shm-perms.c13
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);
}