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 );
libc
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 large-file support 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().
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 |