| 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 <unistd.h> |
| 23 |
#include <errno.h> |
| 24 |
#include <signal.h> |
| 25 |
#include <sys/mman.h> |
| 26 |
|
| 27 |
#include <hugetlbfs.h> |
| 28 |
|
| 29 |
#include "hugetests.h" |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
static void sigbus_handler(int signum, siginfo_t *si, void *uc) |
| 42 |
{ |
| 43 |
PASS(); |
| 44 |
} |
| 45 |
|
| 46 |
int main(int argc, char *argv[]) |
| 47 |
{ |
| 48 |
long hpage_size; |
| 49 |
int fd, fdx; |
| 50 |
unsigned long totpages; |
| 51 |
void *p, *q; |
| 52 |
int i; |
| 53 |
int err; |
| 54 |
struct sigaction sa = { |
| 55 |
.sa_sigaction = sigbus_handler, |
| 56 |
.sa_flags = SA_SIGINFO, |
| 57 |
}; |
| 58 |
|
| 59 |
test_init(argc, argv); |
| 60 |
|
| 61 |
hpage_size = check_hugepagesize(); |
| 62 |
totpages = get_huge_page_counter(hpage_size, HUGEPAGES_TOTAL); |
| 63 |
|
| 64 |
fd = hugetlbfs_unlinked_fd(); |
| 65 |
if (fd < 0) |
| 66 |
FAIL("hugetlbfs_unlinked_fd()"); |
| 67 |
|
| 68 |
p = mmap(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); |
| 69 |
if (p == MAP_FAILED) |
| 70 |
FAIL("mmap(): %s", strerror(errno)); |
| 71 |
err = ftruncate(fd, 0); |
| 72 |
if (err) |
| 73 |
FAIL("ftruncate(): %s", strerror(errno)); |
| 74 |
|
| 75 |
|
| 76 |
fdx = hugetlbfs_unlinked_fd(); |
| 77 |
if (fdx < 0) |
| 78 |
FAIL("hugetlbfs_unlinked_fd() 2"); |
| 79 |
|
| 80 |
q = mmap(NULL, totpages * hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED, |
| 81 |
fdx, 0); |
| 82 |
if (q == MAP_FAILED) |
| 83 |
FAIL("mmap() reserving all pages: %s", strerror(errno)); |
| 84 |
|
| 85 |
|
| 86 |
for (i = 0; i < totpages; i++) { |
| 87 |
volatile char *x = (volatile char *)q + i*hpage_size; |
| 88 |
*x = 0; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
err = sigaction(SIGBUS, &sa, NULL); |
| 93 |
if (err) |
| 94 |
FAIL("sigaction(): %s", strerror(errno)); |
| 95 |
|
| 96 |
*((volatile unsigned int *)p); |
| 97 |
|
| 98 |
|
| 99 |
FAIL("Didn't SIGBUS or OOM"); |
| 100 |
} |