.. | .. |
---|
2 | 2 | #include <malloc.h> |
---|
3 | 3 | #include <stdlib.h> |
---|
4 | 4 | #include <string.h> |
---|
| 5 | +#include <sys/mman.h> |
---|
5 | 6 | #include <time.h> |
---|
| 7 | + |
---|
6 | 8 | #include "utils.h" |
---|
7 | 9 | |
---|
8 | 10 | #define SIZE 256 |
---|
.. | .. |
---|
12 | 14 | #define LARGE_ITERATIONS 1000 |
---|
13 | 15 | #define LARGE_MAX_OFFSET 32 |
---|
14 | 16 | #define LARGE_SIZE_START 4096 |
---|
| 17 | + |
---|
| 18 | +/* This is big enough to fit LARGE_SIZE and works on 4K & 64K kernels */ |
---|
| 19 | +#define MAP_SIZE (64 * 1024) |
---|
15 | 20 | |
---|
16 | 21 | #define MAX_OFFSET_DIFF_S1_S2 48 |
---|
17 | 22 | |
---|
.. | .. |
---|
68 | 73 | |
---|
69 | 74 | static int testcase(bool islarge) |
---|
70 | 75 | { |
---|
71 | | - char *s1; |
---|
72 | | - char *s2; |
---|
73 | | - unsigned long i; |
---|
| 76 | + unsigned long i, comp_size, alloc_size; |
---|
| 77 | + char *p, *s1, *s2; |
---|
| 78 | + int iterations; |
---|
74 | 79 | |
---|
75 | | - unsigned long comp_size = (islarge ? LARGE_SIZE : SIZE); |
---|
76 | | - unsigned long alloc_size = comp_size + MAX_OFFSET_DIFF_S1_S2; |
---|
77 | | - int iterations = islarge ? LARGE_ITERATIONS : ITERATIONS; |
---|
| 80 | + comp_size = (islarge ? LARGE_SIZE : SIZE); |
---|
| 81 | + alloc_size = comp_size + MAX_OFFSET_DIFF_S1_S2; |
---|
| 82 | + iterations = islarge ? LARGE_ITERATIONS : ITERATIONS; |
---|
78 | 83 | |
---|
79 | | - s1 = memalign(128, alloc_size); |
---|
80 | | - if (!s1) { |
---|
81 | | - perror("memalign"); |
---|
82 | | - exit(1); |
---|
83 | | - } |
---|
| 84 | + p = mmap(NULL, 4 * MAP_SIZE, PROT_READ | PROT_WRITE, |
---|
| 85 | + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); |
---|
| 86 | + FAIL_IF(p == MAP_FAILED); |
---|
84 | 87 | |
---|
85 | | - s2 = memalign(128, alloc_size); |
---|
86 | | - if (!s2) { |
---|
87 | | - perror("memalign"); |
---|
88 | | - exit(1); |
---|
89 | | - } |
---|
| 88 | + /* Put s1/s2 at the end of a page */ |
---|
| 89 | + s1 = p + MAP_SIZE - alloc_size; |
---|
| 90 | + s2 = p + 3 * MAP_SIZE - alloc_size; |
---|
| 91 | + |
---|
| 92 | + /* And unmap the subsequent page to force a fault if we overread */ |
---|
| 93 | + munmap(p + MAP_SIZE, MAP_SIZE); |
---|
| 94 | + munmap(p + 3 * MAP_SIZE, MAP_SIZE); |
---|
90 | 95 | |
---|
91 | 96 | srandom(time(0)); |
---|
92 | 97 | |
---|
.. | .. |
---|
147 | 152 | |
---|
148 | 153 | static int testcases(void) |
---|
149 | 154 | { |
---|
| 155 | +#ifdef __powerpc64__ |
---|
| 156 | + // vcmpequd used in memcmp_64.S is v2.07 |
---|
| 157 | + SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_2_07)); |
---|
| 158 | +#endif |
---|
| 159 | + |
---|
150 | 160 | testcase(0); |
---|
151 | 161 | testcase(1); |
---|
152 | 162 | return 0; |
---|