| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#define _GNU_SOURCE |
| 21 |
|
| 22 |
#include <stdio.h> |
| 23 |
#include <stdlib.h> |
| 24 |
#include <string.h> |
| 25 |
#include <unistd.h> |
| 26 |
#include <fcntl.h> |
| 27 |
#include <dlfcn.h> |
| 28 |
#include <stdarg.h> |
| 29 |
|
| 30 |
#include <hugetlbfs.h> |
| 31 |
|
| 32 |
#include "hugetests.h" |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
int open(const char *path, int flags, ...) |
| 37 |
{ |
| 38 |
int (*old_open)(const char *, int, ...); |
| 39 |
int fd; |
| 40 |
|
| 41 |
if (strcmp(path, "/proc/meminfo") == 0) { |
| 42 |
FILE *f; |
| 43 |
|
| 44 |
f = popen("/bin/grep -vi ^hugepage /proc/meminfo", "r"); |
| 45 |
return fileno(f); |
| 46 |
} |
| 47 |
|
| 48 |
if (strcmp(path, "/proc/mounts") == 0) { |
| 49 |
FILE *f; |
| 50 |
|
| 51 |
f = popen("/bin/grep -vi hugetlbfs /proc/mounts", "r"); |
| 52 |
return fileno(f); |
| 53 |
} |
| 54 |
|
| 55 |
old_open = dlsym(RTLD_NEXT, "open"); |
| 56 |
if (flags & O_CREAT) { |
| 57 |
va_list ap; |
| 58 |
|
| 59 |
va_start(ap, flags); |
| 60 |
fd = (*old_open)(path, flags, va_arg(ap, mode_t)); |
| 61 |
va_end(ap); |
| 62 |
return fd; |
| 63 |
} else { |
| 64 |
return (*old_open)(path, flags); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
int main(int argc, char *argv[]) |
| 69 |
{ |
| 70 |
long hpage_size; |
| 71 |
|
| 72 |
test_init(argc, argv); |
| 73 |
|
| 74 |
hpage_size = gethugepagesize(); |
| 75 |
if (hpage_size == -1) |
| 76 |
PASS(); |
| 77 |
|
| 78 |
FAIL("Mysteriously found a hugepage size of %ld\n", hpage_size); |
| 79 |
} |