posix_mem_offset(), posix_mem_offset64()

Get the offset and length of a mapped memory block

Synopsis:

#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 );

Arguments:

addr
The address that the memory block is currently mapped at.
len
The length of the block of memory object that you want the offset of.
off
A pointer to a location where the function can store the offset (or location) within the memory block.
contig_len
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.
fildes
A pointer to a location where the function can store the file descriptor used to establish the mapping that contains addr.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The posix_mem_offset() function sets the variable pointed to by off to the offset (or location), within a memory object, of the memory block currently mapped at addr. It 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().

Returns:

0
Success.
EACCES
The process hasn't mapped a memory object at the given address addr.
EOVERFLOW
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.

Classification:

posix_mem_offset() is POSIX 1003.1 TYM; posix_mem_offset64() is for large-file support

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes