Skip to content

Commit 35d577f

Browse files
MatthieuSarterianlancetaylor
authored andcommitted
runtime: adapt memory management to AIX mmap
On AIX: * mmap does not allow to map an already mapped range, * mmap range start at 0x30000000 for 32 bits processes, * mmap range start at 0x70000000_00000000 for 64 bits processes Issue golang/go#19200 Change-Id: I1a71214adc44cfff53077534e17962770e7b57a1 Reviewed-on: https://go-review.googlesource.com/37845 Reviewed-by: Ian Lance Taylor <iant@golang.org>
1 parent 83ea2d6 commit 35d577f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

libgo/runtime/malloc.goc

+9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ package runtime
3939
#ifdef __aarch64__
4040
#define HeapBase(i) ((void*)(uintptr)(0x40ULL<<32))
4141
#define HeapBaseOptions 1
42+
#elif defined(_AIX)
43+
// mmap adresses range start at 0x07000000_00000000 on AIX for 64 bits processes
44+
#define HeapBase(i) ((void*)(uintptr)(0x70ULL<<52))
45+
#define HeapBaseOptions 1
4246
#else
4347
#define HeapBase(i) ((void*)(uintptr)(i<<40|0x00c0ULL<<32))
4448
#define HeapBaseOptions 0x80
@@ -498,10 +502,15 @@ runtime_mallocinit(void)
498502
// away from the running binary image and then round up
499503
// to a MB boundary.
500504

505+
#ifdef _AIX
506+
// mmap adresses range start at 0x30000000 on AIX for 32 bits processes
507+
end = 0x30000000U;
508+
#else
501509
end = 0;
502510
pend = &__go_end;
503511
if(pend != nil)
504512
end = *pend;
513+
#endif
505514
p = (byte*)ROUND(end + (1<<18), 1<<20);
506515
p_size = bitmap_size + spans_size + arena_size + PageSize;
507516
p = runtime_SysReserve(p, p_size, &reserved);

libgo/runtime/mem.c

+6
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,12 @@ runtime_SysMap(void *v, uintptr n, bool reserved, uint64 *stat)
222222
return;
223223
}
224224

225+
#ifdef _AIX
226+
// AIX does not allow mapping a range that is already mapped.
227+
// So always unmap first even if it is already unmapped.
228+
runtime_munmap(v, n);
229+
#endif
230+
225231
p = runtime_mmap(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_FIXED|MAP_PRIVATE, fd, 0);
226232
if(p == MAP_FAILED && errno == ENOMEM)
227233
runtime_throw("runtime: out of memory");

0 commit comments

Comments
 (0)