0

How to read mmap function from specific address, if knew it (0x6A6F7444)? I tried:

mmap(0x6A6F7444, 100, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0)

But it doen't works. Compile says:

warning: passing argument 1 of ‘munmap’ makes pointer from integer without a cast [-Wint-conversion] 
Restman
  • 95
  • 1
  • 8
  • Please describe the behaviour better than "doesn't work". What exactly is observed? – kaylum Oct 05 '20 at 10:25
  • Compile says: warning: passing argument 1 of ‘munmap’ makes pointer from integer without a cast [-Wint-conversion] – Restman Oct 05 '20 at 10:34
  • Bear in mind that `0x6A6F7444` is not aligned to a memory page (usually 4KiB) neither is the page size `100`, and that function call will likely return an error. If that happens, I would try with `mmap((void *)0x6A6F7000, 4096, ...)` instead. – Jorge Bellon Oct 05 '20 at 10:36
  • @Restman Please [edit] the question with that info. It should be common sense that if you are asking about an error you should provide the actual error. Also, please note that the first arg is just a hint and the OS may not actually use that address unless `MAP_FIXED` is set. But if `MAP_FIXED` is set then `addr` also needs to be page aligned. – kaylum Oct 05 '20 at 10:38

2 Answers2

1
#include <stdint.h> // for uintptr_t

uintptr_t addr = 0x6A6F7444;

mmap((void *)addr, 100, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);

will disable the warning.

Jorge Bellon
  • 2,901
  • 15
  • 25
David Ranieri
  • 39,972
  • 7
  • 52
  • 94
0

For mmap to use your address it needs MAP_FIXED flag, see man mmap for full details.

Maxim Egorushkin
  • 131,725
  • 17
  • 180
  • 271