Search code examples
cmalloc

How to malloc in address range > 4 GiB


I am trying to do some tests on X86_64 Linux, and I want to know how to make malloc() allocate return addresses in the range higher than 4 GiB

Do I have to override malloc with a separate/custom library or is there any other simple way to do this?

Thanks.

----Edit----

What I am interested is in the address when taken as value (uintptr_t) and it does not matter whether its virtual or physical address, because, all that I want is the address must be a value greater than 4GiB

I am using gcc (4.2.1) with -m64, on Linux x86_64

(hope I made the question clear)


Solution

  • malloc() is the wrong tool. You want to mmap() /dev/zero (which is what malloc() is doing behind the scenes in modern glibc), IIRC. (On Unix. I believe there is a similar API for Win32, but I couldn't tell you what it is.)