mem_offset(), mem_offset64()

QNX SDP8.0C Library ReferenceAPIDeveloper

Get the physical address and length of a virtually mapped memory block

Synopsis:

#include <sys/mman.h>

int mem_offset( const void * addr,
                int fd,
                size_t length,
                off_t * offset,
                size_t * contig_len );

int mem_offset64( const void * addr,
                  int fd,
                  size_t length,
                  off64_t * offset,
                  size_t * contig_len );

Arguments:

addr
The virtual address of the memory block whose physical address you want to get. This address doesn't have to be page-aligned (i.e., a multiple of PAGESIZE) because the function reports the physical address that backs the virtual address.
fd
This must be NOFD, or the function fails.
length
The length of the memory block that you want the location of.
offset
NULL, or a pointer to a location for storing the physical address that the virtual address (addr) maps to.
contig_len
NULL, or a pointer to a location for storing either length or the length of the physically contiguous block of memory that starts at addr, whichever is smaller.

Library:

libc

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

Description:

The mem_offset() and mem_offset64() functions set the variable pointed to by offset to the physical address of addr. The length of the physically contiguous block of memory at addr is written into the variable pointed to by contig_len if this argument is not NULL.

Note:
  • The mem_offset64() function is a large-file support version of mem_offset(). If you're using large-file support functions and data types, you should define _LARGEFILE64_SOURCE with a value of 1 to ensure they appear in the name space. For more information, see Classification in What's in a Function Description?.
  • For best performance results, you should cache the result of mem_offset(), rather than repeatedly call the function for a given virtual address or contiguous block.

Returns:

0
Success.
-1
An error occurred (errno is set).

Errors:

EACCES
The virtual address is mapped but not backed by physical memory.
ENODEV
The file descriptor fd isn't NOFD.

Examples:

off64_t offset;

if (mem_offset64(addr, NOFD, 1, &offset, NULL) == -1)
{
  /* Error */
}
else
{
  /* offset contains the physical address of the memory mapped at addr. */
}

Classification:

QNX OS

Safety:
Cancellation point No
Signal handler Yes
Thread Yes
Page updated: