munmap_peer()

Updated: October 26, 2022

Unmap a part of the virtual address space in another process

Synopsis:

#include <sys/mman_peer.h>

int munmap_peer( pid_t pid,
                 void *addr,
                 size_t len );

Arguments:

pid
The ID of the process in which you want to unmap memory.
addr
A pointer to where you want to unmap the object in the specified process's address space. The addr is the beginning of the range of addresses that you want to unmap.
len
The number of bytes to unmap into the specified process's address space. Note that length of the range of addresses can't be 0.

Library:

libc

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

Description:

The munmap_peer() function removes any mappings for pages in the address range for the specified process starting at addr and continuing for len bytes, rounded up to the next multiple of the page size. References to unmapped pages cause a SIGSEGV signal to be set on the process.

If there are no mappings in the specified address range, then munmap_peer() has no effect.

CAUTION:
We recommend that mmap_peer() and munmap_peer() be called only by a server on behalf of a client that's currently reply-blocked on the server and expects the message that it sent to result in a change to its address space. For example, the server can define a protocol that includes ALLOC_BUFFER and FREE_BUFFER messages, making it explicit that the message will result in memory mapping and unmapping, respectively. Otherwise the client's address space layout could unexpectedly change, leading to race conditions.

Consider using shm_create_handle() instead of mmap_peer().

Returns:

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

Errors:

EINTR
The call was interrupted by a signal.
EINVAL
The addresses in the specified range are outside the range allowed for the address space of a process.
ENOMEM
The memory manager failed to allocate memory to handle a user's munmap_peer() request. This allocation of memory is necessary for internal structures to represent the new state of mapped memory.
ESRCH
The process pid doesn't exist, is loading, or is terminating.

Classification:

QNX Neutrino

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