| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <stdio.h> |
| 20 |
#include <stdlib.h> |
| 21 |
#include <string.h> |
| 22 |
#include <errno.h> |
| 23 |
#include <unistd.h> |
| 24 |
#include <sys/mman.h> |
| 25 |
|
| 26 |
#include <hugetlbfs.h> |
| 27 |
|
| 28 |
#include "hugetests.h" |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
#ifdef __powerpc64__ |
| 41 |
void *next_chunk(void *addr) |
| 42 |
{ |
| 43 |
if (!arch_has_slice_support()) |
| 44 |
return PALIGN(addr, gethugepagesize()); |
| 45 |
|
| 46 |
if ((unsigned long)addr < 0x100000000UL) |
| 47 |
|
| 48 |
return PALIGN(addr, 0x10000000UL); |
| 49 |
else |
| 50 |
|
| 51 |
return PALIGN(addr, 0x10000000000UL); |
| 52 |
} |
| 53 |
#elif defined(__powerpc__) && !defined(PPC_NO_SEGMENTS) |
| 54 |
void *next_chunk(void *addr) |
| 55 |
{ |
| 56 |
return PALIGN(addr, 0x10000000UL); |
| 57 |
} |
| 58 |
#elif defined(__ia64__) |
| 59 |
void *next_chunk(void *addr) |
| 60 |
{ |
| 61 |
return PALIGN(addr, 0x8000000000000000UL); |
| 62 |
} |
| 63 |
#else |
| 64 |
void *next_chunk(void *addr) |
| 65 |
{ |
| 66 |
return PALIGN(addr, gethugepagesize()); |
| 67 |
} |
| 68 |
#endif |
| 69 |
|
| 70 |
int main(int argc, char *argv[]) |
| 71 |
{ |
| 72 |
long hpage_size; |
| 73 |
int fd; |
| 74 |
void *brk0, *hugemap_addr, *newbrk; |
| 75 |
char *p; |
| 76 |
int err; |
| 77 |
|
| 78 |
test_init(argc, argv); |
| 79 |
|
| 80 |
hpage_size = check_hugepagesize(); |
| 81 |
|
| 82 |
fd = hugetlbfs_unlinked_fd(); |
| 83 |
if (fd < 0) |
| 84 |
FAIL("hugetlbfs_unlinked_fd()"); |
| 85 |
|
| 86 |
brk0 = sbrk(0); |
| 87 |
verbose_printf("Initial break at %p\n", brk0); |
| 88 |
|
| 89 |
hugemap_addr = next_chunk(brk0) + hpage_size; |
| 90 |
|
| 91 |
p = mmap(hugemap_addr, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, |
| 92 |
fd, 0); |
| 93 |
if (p == MAP_FAILED) |
| 94 |
FAIL("mmap(): %s", strerror(errno)); |
| 95 |
if (p != hugemap_addr) |
| 96 |
FAIL("mmap() at unexpected address %p instead of %p\n", p, |
| 97 |
hugemap_addr); |
| 98 |
|
| 99 |
verbose_printf("Hugepage mapped at %p-%p\n", p, p+hpage_size-1); |
| 100 |
|
| 101 |
err = test_addr_huge((void *)p); |
| 102 |
if (err != 1) |
| 103 |
FAIL("Mapped address is not hugepage"); |
| 104 |
|
| 105 |
newbrk = next_chunk(brk0) + getpagesize(); |
| 106 |
err = brk((void *)newbrk); |
| 107 |
if (err == -1) |
| 108 |
|
| 109 |
PASS(); |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
memset(brk0, 0, newbrk-brk0); |
| 115 |
|
| 116 |
PASS(); |
| 117 |
} |