[Previous]
[Contents]
[Next]

qnx_segment_raw_alloc()

allocate a contiguous segment that is removed from the system memory map

Synopsis:

#include <sys/seginfo.h>
unsigned qnx_segment_raw_alloc( 
             long nbytes,
             struct _seginfo *buf );

Description:

The qnx_segment_raw_alloc() function allocates a contiguous segment of memory that's removed from the system memory map. The physical address and size of the memory are returned in buf. Note that the size returned is rounded up to be a multiple of the page size used by the operating system (4K for 32-bit QNX).

This memory won't be returned to the memory map on the death of the process that allocated it. Once allocated, the system no longer believes that the memory exists. It can be returned only by explicitly calling qnx_segment_raw_free().

The _seginfo structure contains valid values for the following members:

long addr
The physical memory address where the segment starts.
long nbytes
The size of the segment.

Returns:

0
Success
-1
An error occurred. errno is set to indicate the error.

Errors:

EPERM
Process doesn't have sufficient privilege.
ENOMEM
Insufficient system memory.

Examples:

#include <stdio.h>
#include <errno.h>
#include <process.h>
#include <stdlib.h>
#include <sys/seginfo.h>

/* You must be root (uid == 0) to do raw allocations */

void main()
{
  struct _seginfo buf;

  /* Display system memory, then alloc a chunk */
  system( "sin in" );
  if( qnx_segment_raw_alloc( 200000L, &buf ) == -1 ) {
    printf( "Alloc failed. Errno %d.\n", errno );
    exit( 1 );
    }

  /* Display system memory, then free a chunk */
  system( "sin in" );
  if( qnx_segment_raw_free( &buf ) == -1 )
    printf( "Free failed (memory lost). Errno %d.\n",
            errno );

  /* Display system memory */
  system( "sin in" );
}

Classification:

QNX

Safety:
Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes

Caveats:

Your application must run as root to call this function.

See also:

errno, qnx_segment_raw_free()


[Previous]
[Contents]
[Next]