| 1 |
/* { dg-do run { target { { *-*-linux* *-*-gnu* *-*-uclinux* } && mmap } } } */ |
| 2 |
|
| 3 |
#include <unistd.h> |
| 4 |
#include <stdlib.h> |
| 5 |
#include <sys/mman.h> |
| 6 |
|
| 7 |
struct S |
| 8 |
{ |
| 9 |
struct S *next; |
| 10 |
}; |
| 11 |
|
| 12 |
static void __attribute__((noipa)) |
| 13 |
allocate(void *addr, unsigned long long size) |
| 14 |
{ |
| 15 |
void *ptr = mmap((void *)addr, size, |
| 16 |
PROT_READ | PROT_WRITE, |
| 17 |
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE, |
| 18 |
-1, 0); |
| 19 |
if(ptr != addr) |
| 20 |
exit(0); |
| 21 |
} |
| 22 |
|
| 23 |
int main (void) |
| 24 |
{ |
| 25 |
int size = 0x8000; |
| 26 |
char *ptr = (char *)0x288000ull; |
| 27 |
allocate((void *)ptr, size); |
| 28 |
|
| 29 |
struct S *s1 = (struct S *)ptr; |
| 30 |
struct S *s2 = (struct S *)256; |
| 31 |
for (int i = 0; i < 3; i++) |
| 32 |
{ |
| 33 |
for(char *addr = (char *)s1; addr < (char *)s1 + sizeof(*s1); ++addr) |
| 34 |
*addr = 0; |
| 35 |
|
| 36 |
if(s1->next) |
| 37 |
s1->next = s1->next->next = s2; |
| 38 |
else |
| 39 |
s1->next = s2; |
| 40 |
} |
| 41 |
return 0; |
| 42 |
} |