1
2/* Test for aspacem bug reported by Alex Bennee, reported on users
3   list around 9 Aug 06, resulting in
4
5   > > --1515:0:aspacem  Valgrind: FATAL: aspacem assertion failed:
6   > > --1515:0:aspacem    holeEnd <= aspacem_maxAddr
7   > > --1515:0:aspacem    at m_aspacemgr/aspacemgr.c:1998
8   > > (vgPlain_am_get_advisory)
9   > > --1515:0:aspacem  Exiting now.
10
11   TomH writes:
12
13   > I think the problem here is that you've done an mmap (either fixed or
14   > hinted) above aspacem_maxAddr and then munmaped it which leaves you
15   > with a free segment above aspacem_maxAddr.
16
17   The sequence seems to be that you have to allocate memory somewhere
18   above aspacem_maxAddr, then free it, then do another hinted
19   allocation that is above aspacem_maxAddr but which can't be done
20   due to the memory already being in use. This program will reproduce
21   it.
22
23   On investigation: the problem was the munmap returns its space in
24   the form of SkFree even though the space above aspacem_maxAddr is
25   supposed to be SkResvn.  This is now fixed.
26*/
27
28#include <stdio.h>
29#include <stdlib.h>
30#include "tests/sys_mman.h"
31
32int main(int argc, char **argv)
33{
34   void *p;
35   if ((p = mmap((void*)0x1F7F100000, 4096, PROT_READ|PROT_WRITE,
36                 MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0)) == (void *)-1)
37   {
38      perror("mmap");
39      exit(1);
40   }
41   if (munmap(p, 4096) < 0)
42   {
43      perror("munmap");
44      exit(1);
45   }
46   if ((p = mmap((void*)0x1F7F101000, 4096, PROT_READ,
47                 MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)) == (void *)-1)
48   {
49      perror("mmap");
50      exit(1);
51   }
52   if ((p = mmap((void*)0x1F7F101000, 4096, PROT_READ,
53                 MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)) == (void *)-1)
54   {
55      perror("mmap");
56      exit(1);
57   }
58
59   printf("made it through alive!\n");
60   exit(0);
61}
62