How to change the _particular_ region in memory?

I have a program. I want it to be able to display a specific memory area on different runs.

  • I have the source code for the program. C / C ++
  • I control how the program is compiled. NCA
  • I control how the program is connected. NCA
  • I control how the program runs (Linux).

I just want to have this specific memory region, say 0xabcdabcd in 0xdeadbeef, which I mmap for a specific file. Is there any way to guarantee this? (I have to somehow make sure that other things are not loaded in this particular region).

EDIT:

How can I make sure nothing else occupies this particular region in my memory?

+3
source share
3 answers

You cannot make sure that nothing else occupies this memory area - first, first served. However, since you need a certain amount of memory, I assume that you have a rather specialized environment, so you just need to make sure that you are in the first place (using start scripts)

0
source

You need to do two things:

  • Specify the start address as the first argument to mmap.
  • Enable the MAP_FIXED flag.

For the start address you need to make sure that it is a multiple of the page size. To get the page size, use the sysconf(_SC_PAGESIZE) call (which is the corresponding call on Linux, other platforms may be different).

+7
source

Pass the address to the card in addr . Try to get it at the 8KB border. You can try mlock() .

+1
source

All Articles