MMAP是否总是返回较高地址 [英] Does mmap always return higher address

查看:152
本文介绍了MMAP是否总是返回较高地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确实 MMAP (与MAP_ANONYMOUS叫,就是分配内存)总是返回更高的内存地址超过previous电话吗?如果不是这样,有什么办法让它返回一个更高的地址总是?

Does mmap (when called with MAP_ANONYMOUS, that is, for allocating memory) always return higher memory address than a previous call? If not so, Is there any way to make it return a higher address always?

推荐答案

不一定,至少不会根据它的定义。

Not necessarily, at least not according to its definition.

和我相信,随着 ASLR 是可能发生的上限地址没有更多的可用,所以 MMAP 必须选择一些较低地址范围。

And I would believe that with ASLR it could happen that upper addresses are no more available, so mmap has to choose some lower address range.

显然,在32位处理器(安培;内核)的存储空间,可以几乎占满,所以要求一个大的 MMAP -ed范围时,内核应该找到一个其中配合,并且可以在任何地方。

Obviously, on 32 bits processors (& kernels) the memory space could be nearly filled, so when asking for a big mmap-ed range the kernel should find one which fits, and that could be anywhere.

如果你想有一个单调的方向,使用 SBRK (但我真的不推荐使用它)。

If you want a monotone direction, use sbrk (but I really recommend against using it).

另一种可能性是,以pre-分配一个非常大的量使用(例如数TB)的地址空间 MMAP MAP_NORESERVE 在程序初始化,并调用 MMAP MAP_FIXED 里面那个范围再次得到真正可用空间(以更易于管理的数据块,比如几十兆)。

Another possibility could be to pre-allocate a very large amount (e.g. several terabytes) of address space using mmap with MAP_NORESERVE at program initialization, and call mmap with MAP_FIXED inside that range again to get the really usable space (in more manageable chunks, e.g. dozens of megabytes).

@MetallicPriest:你真的应该鼓励,并解释更您的问题。有那么神秘和古怪(甚至我无法猜测所有的上下文中),这是不是很有趣的回答。

@MetallicPriest: you really should motivate and explain much more your questions. There are so mysterious and weird (and even I cannot guess all the context) that it is not very fun to answer them.

这篇关于MMAP是否总是返回较高地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆