What is Linux or POSIX equivalent of VirtualAlloc with MEM_TOP_DOWN, if there's any?
POSIX does not seem to have anything when it comes to mmap
.
The GNU C Library version of mmap
(BSD libc also has these flags) extends its functionality though, with a MAP_FIXED
(allocate at specific address) and MAP_GROWSDOWN
(which is named similarly but MEM_TOP_DOWN
actually has nothing to do with this option). Both GNU and BSD's manpages discourage use of these functions, because of portability issues (you're bound to the specific C library, and not fully OS independent anymore).
You'd need to determine a way to find the topmost address. I suggest trying to allocate at the top, and moving the passed address down until it does succeed. The step size and "search" algorithm will depend on your need of precision and performance.