| 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 <unistd.h> |
| 22 |
#include <signal.h> |
| 23 |
#include <sys/mman.h> |
| 24 |
|
| 25 |
#include <hugetlbfs.h> |
| 26 |
|
| 27 |
#include "hugetests.h" |
| 28 |
|
| 29 |
#define RANDOM_CONSTANT 0x1234ABCD |
| 30 |
|
| 31 |
static void sigbus_handler(int signum, siginfo_t *si, void *uc) |
| 32 |
{ |
| 33 |
PASS(); |
| 34 |
} |
| 35 |
|
| 36 |
int main(int argc, char *argv[]) |
| 37 |
{ |
| 38 |
long hpage_size; |
| 39 |
int fd; |
| 40 |
void *p; |
| 41 |
volatile unsigned int *q; |
| 42 |
int err; |
| 43 |
struct sigaction sa = { |
| 44 |
.sa_sigaction = sigbus_handler, |
| 45 |
.sa_flags = SA_SIGINFO, |
| 46 |
}; |
| 47 |
|
| 48 |
test_init(argc, argv); |
| 49 |
|
| 50 |
hpage_size = check_hugepagesize(); |
| 51 |
|
| 52 |
fd = hugetlbfs_unlinked_fd(); |
| 53 |
if (fd < 0) |
| 54 |
FAIL("hugetlbfs_unlinked_fd()"); |
| 55 |
|
| 56 |
p = mmap(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED, |
| 57 |
fd, 0); |
| 58 |
if (p == MAP_FAILED) |
| 59 |
FAIL("mmap(): %s", strerror(errno)); |
| 60 |
|
| 61 |
q = p; |
| 62 |
|
| 63 |
|
| 64 |
*q = 0; |
| 65 |
|
| 66 |
err = sigaction(SIGBUS, &sa, NULL); |
| 67 |
if (err) |
| 68 |
FAIL("sigaction(): %s", strerror(errno)); |
| 69 |
|
| 70 |
|
| 71 |
err = ftruncate(fd, 0); |
| 72 |
if (err) |
| 73 |
FAIL("ftruncate(): %s", strerror(errno)); |
| 74 |
|
| 75 |
*q; |
| 76 |
|
| 77 |
|
| 78 |
FAIL("Didn't SIGBUS"); |
| 79 |
} |