Get the offset and length of a mapped memory block
#include <sys/mman.h> int posix_mem_offset( const void *addr, size_t len, off_t *off, size_t *contig_len, int *fildes ); int posix_mem_offset64( const void *addr, size_t len, off64_t *off, size_t *contig_len, int *fildes );
- The address that the memory block is currently mapped at.
- The length of the block of memory object that you want the offset of.
- A pointer to a location where the function can store the offset (or location) within the memory block.
- A pointer to a location where the function can store either the value of len or the length of the largest contiguous block of the memory object that's currently mapped to the calling process starting at addr, whichever is smaller.
- A pointer to a location where the function can store the file descriptor used to establish the mapping that contains addr.
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The posix_mem_offset() and posix_mem_offset64() functions set the variable pointed to by off to the offset (or location), within a memory object, of the memory block currently mapped at addr. The posix_mem_offset64() function is a 64-bit version of posix_mem_offset().
The posix_mem_offset() function sets the variable pointed to by fildes to the descriptor used (via mmap()) to establish the mapping that contains addr, or -1 if the descriptor has since been closed.
This function supports typed memory, shared memory, and memory-mapped files, but not anonymous memory.
The len argument specifies the length of the block of memory you want the offset for. On return, the value pointed to by contig_len is either len or the length of the largest contiguous block of the memory object that's currently mapped to the calling process starting at addr, whichever is smaller.
If the memory object mapped at addr is a typed memory object, then if you use the off and contig_len values that you obtained by calling posix_mem_offset() in a call to mmap() with a file descriptor that refers to the same memory pool as fildes (either through the same port or through a different port), and that was opened with neither the POSIX_TYPED_MEM_ALLOCATE nor the POSIX_TYPED_MEM_ALLOCATE_CONTIG flag, the typed memory area that is mapped is exactly the same area that was mapped at addr in the address space of the process that called posix_mem_offset().
- The process hasn't mapped a memory object at the given address addr.
- This error is specific to posix_mem_offset() and is returned when the address is too large for the 32-bit off_t; use posix_mem_offset64() instead.
Last modified: 2014-06-24