0

I am trying to determine whether a group of contiguous memory locations on my Linux system are currently holding data for a process. If they are not then I want to allocate these locations to my programme and ensure that other processes know that those memory locations are reserved for my programme.

I need to access a specific memory location, e.g. 0xF0A35194. Any old location will not do.

I have been searching for solutions but have not been brave enough to execute and test any code for fear that I will destroy my system.

I do not want to run this code in kernel-space so a user-space solution is preferable.

Any help would be greatly appreciated!

deanshanahan
  • 318
  • 5
  • 14
  • 1
    You're talking about *physical* addresses, right? Out of curiosity - why do you want to reserve specific physical addresses? – Oliver Charlesworth Aug 11 '16 at 11:51
  • 2
    Of course you can't "destroy your system", unless there's something *really scary* using memory-mapped I/O at that location. – unwind Aug 11 '16 at 11:54
  • 1
    Yes I am talking about specific physical addresses. Using specific hardware addresses can be useful if you have an embedded system with memory-mapped I/O. @unwind I am worried that a process will take a value from that location and store it in ROM destroying one of my files TBH. – deanshanahan Aug 11 '16 at 11:54
  • 3
    XY problem. Why don't you use the standard way(s) for allocating and sharing memory? For embedded systems with Linux, that's what drivers are for! Even **iff** you did hardware-IO from user-space (a bad idea at least for production code), you definitively don't want to share the peripheral with other processes. – too honest for this site Aug 11 '16 at 12:05
  • this seems to be a duplicate of: `http://stackoverflow.com/questions/12040303/accessing-physical-address-from-user-space` – user3629249 Aug 11 '16 at 12:08
  • 1
    You can do that at kernel level, not surely at app level. For example using [mmap](http://man7.org/linux/man-pages/man2/mmap.2.html) with `MAP_FIXED` option – LPs Aug 11 '16 at 12:08
  • 1
    Oh, and if they cover hardware-registers, they are not unallocated. – too honest for this site Aug 11 '16 at 12:09
  • It looks like you need to write a device driver. – n. m. could be an AI Aug 11 '16 at 12:18

1 Answers1

1

There are a lot of issues at play here. To start, each process has its own memory address space. Even if a particular memory address is allocated for one process, it won't be for a different process. Memory virtualize and paging is a complex and opaque abstraction that can't be broken from within user space.

Next, the only reason that I can imagine you want to do something like this is to go hunting for particular DMA ranges for devices. That is also not allowed from user space and there are much better ways to accomplish that.

If you can post what you are trying to achieve more directly, we can provide a better solution.

Holly
  • 5,270
  • 1
  • 24
  • 27