Get the offset and length of a mapped typed memory block
#include <sys/mman.h> int posix_mem_offset(const void *restrict addr, size_t len, off_t *restrict off, size_t *restrict contig_len, int *restrict fildes); int posix_mem_offset64(const void *restrict addr, size_t len, off64_t *restrict off, size_t *restrict contig_len, int *restrict 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 typed memory 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 for the typed memory object.
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The posix_mem_offset() function sets the variable pointed to by off to the offset (or location), within a typed memory object, of the memory block currently mapped at addr.
The posix_mem_offset() function uses a variable to return the descriptor that establishes the mapping containing addr. This variable is pointed to by fildes; its value is -1 when the descriptor closes after the mapping is established.
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 typed memory that's currently mapped to the calling process starting at addr, whichever is smaller.
If the off and contig_len values obtained from calling posix_mem_offset() are used 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), the typed memory area that is mapped is exactly the same area that was mapped at addr of the process that called posix_mem_offset(). Note that neither of the two flags (such as the POSIX_TYPED_MEMORY_ALLOCATE or the POSIX_TYPED_MEM_ALLOCATE_CONTIG) did open the file descriptor.
- The process hasn't mapped a memory object at the given address addr.