@@ -92,6 +92,33 @@ void OS::Guard(void* address, const size_t size) {
9292}
9393#endif // __CYGWIN__
9494
95+ // For our illumos/Solaris mmap hint, we pick a random address in the bottom
96+ // half of the top half of the address space (that is, the third quarter).
97+ // Because we do not MAP_FIXED, this will be treated only as a hint -- the
98+ // system will not fail to mmap() because something else happens to already be
99+ // mapped at our random address. We deliberately set the hint high enough to
100+ // get well above the system's break (that is, the heap); illumos and Solaris
101+ // will try the hint and if that fails allocate as if there were no hint at
102+ // all. The high hint prevents the break from getting hemmed in at low values,
103+ // ceding half of the address space to the system heap.
104+
105+ // On all other 32bit platforms the range 0x20000000 - 0x60000000 is relatively
106+ // unpopulated across a variety of ASLR modes (PAE kernel, NX compat mode, etc)
107+ // and on macos 10.6 and 10.7.
108+
109+ #ifdef V8_TARGET_ARCH_X64
110+ # ifdef __sun
111+ # define V8_ASLR_MEMORY_SHIFT 0x400000000000ULL
112+ # else
113+ # define V8_ASLR_MEMORY_SHIFT 0
114+ # endif // __sun
115+ #else
116+ # ifdef __sun
117+ # define V8_ASLR_MEMORY_SHIFT 0x80000000
118+ # else
119+ # define V8_ASLR_MEMORY_SHIFT 0x20000000
120+ # endif // __sun
121+ #endif // V8_TARGET_ARCH_X64
95122
96123void * OS::GetRandomMmapAddr () {
97124 Isolate* isolate = Isolate::UncheckedCurrent ();
@@ -111,25 +138,8 @@ void* OS::GetRandomMmapAddr() {
111138 uint32_t raw_addr = V8::RandomPrivate (isolate);
112139
113140 raw_addr &= 0x3ffff000 ;
114-
115- # ifdef __sun
116- // For our Solaris/illumos mmap hint, we pick a random address in the bottom
117- // half of the top half of the address space (that is, the third quarter).
118- // Because we do not MAP_FIXED, this will be treated only as a hint -- the
119- // system will not fail to mmap() because something else happens to already
120- // be mapped at our random address. We deliberately set the hint high enough
121- // to get well above the system's break (that is, the heap); Solaris and
122- // illumos will try the hint and if that fails allocate as if there were
123- // no hint at all. The high hint prevents the break from getting hemmed in
124- // at low values, ceding half of the address space to the system heap.
125- raw_addr += 0x80000000 ;
126- # else
127- // The range 0x20000000 - 0x60000000 is relatively unpopulated across a
128- // variety of ASLR modes (PAE kernel, NX compat mode, etc) and on macos
129- // 10.6 and 10.7.
130- raw_addr += 0x20000000 ;
131- # endif
132141#endif
142+ raw_addr += V8_ASLR_MEMORY_SHIFT;
133143 return reinterpret_cast <void *>(raw_addr);
134144 }
135145 return NULL ;
0 commit comments