FreeBSD is free to ignore the address hint if MAP_FIXED wasn't
passed. However, some Linux applications, like the ART runtime,
depend on the hint. If the MAP_FIXED wasn't passed, but the
address is not zero, try with MAP_FIXED and MAP_EXCL first,
and fall back to the normal behaviour if that fails.
Details
Diff Detail
- Repository
- rS FreeBSD src repository - subversion
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
Dmitry, could you test it?
Also, the description should probably mention that the application that does this is the native Linux version of ART (the Android component).
FreeBSD does not ignore hint address for mmap(2). We start searching for the free gap starting at the hint, up in the direction of higher addresses. What FreeBSD does which might confuse Linux apps is the superpage alignment of the start address. Look at the sys/vm/vm_mmap.c:vm_mmap_object(), the fitit and findspace variables.
The proper solution is probably to allow your caller of vm_mmap.c to request that findspace was set to VMFS_ANY_SPACE. This would require some plumbing, but definitely it is much cleaner than MAP_EXCL hack (assuming my guess about superalign is correct).
I'm not sure if I want to clutter other parts of the system just for this. This is specific to Linux, and not even Linux in general - it's a workaround for arguably buggy behaviour of some linux apps (ART in this case). In other words it's a bug compatibility. We already have lots of those in linuxulator.