[Previous]
[Contents]
[Next]

qnx_segment_alloc_flags()

allocate a segment, setting option flags

Synopsis:

#include <sys/seginfo.h>
unsigned qnx_segment_alloc_flags( long nbytes,
                                  unsigned flags );

Description:

The qnx_segment_alloc_flags() function allocates a segment of memory nbytes long from the operating system. It's identical to qnx_segment_alloc() except it allows you to specify some option flags on the allocated segment.

The following special flags are supported. Note that _PMF_MODIFY is always set for you. You can remove it using qnx_segment_flags().

_PMF_GLOBAL
Return a segment that's addressable by all processes. In protected mode, this returns a selector in the Global Descriptor Table (GDT). Note that unless the _PMF_GLOBAL_OWN flag is also set, a global segment isn't owned by the calling process and persists after its death. The segment may be explicitly released using qnx_segment_free().
_PMF_GLOBAL_OWN
Bind a global segment to the calling process. When the process terminates, global segments allocated with this flag are released in the same manner as local segments.
_PMF_DMA_SAFE
Allocate a segment that's guaranteed not to cross a 64K page boundary (unless, of course, the size is greater than 64K) and resides in the first 16 megabytes of physical memory. This is necessary if you're going to perform DMA into the segment, since the PC/AT supports only a 16-bit DMA controller with an 8-bit page register. This flag is often used by disk drivers.
_PMF_DMA_HIGH
Remove the restriction the a DMA-safe segment be in the first 16M of physical memory.
_PMF_NOCACHE
Disable external caching of this segment. This flag is supported only on the 32-bit version of QNX using the pager.

Note: Although this function is available in both the 16-bit and 32-bit libraries, the qnx_segment_... family of calls is primarily intended for the 16-bit segmented version of QNX. To allocate and share memory in the 32-bit version you should look at using the POSIX shm_open() and mmap() functions.

Returns:

A segment number on success. On error, it returns -1, and errno is set.

Errors:

EINVAL
The parameter nbytes is 0.
ENOMEM
Insufficient system memory to allocate the segment, or insufficient local process manager memory to manage the segment.
EPERM
Insufficient privilege to allocate segment.

Examples:

#include <i86.h>
#include <sys/seginfo.h>

void main()
  {
    unsigned base;
    char __far *p;

    /* Allocate a globally accessible 32 Kbyte array */
    base = qnx_segment_alloc_flags( 32768, _PMF_GLOBAL |
                       _PMF_GLOBAL_OWN );

    /* Point at byte 16,000 in the array */
    p = MK_FP( base, 16000 );

    /* Set the byte and read it back */
    *p = 'a';
    printf( "base = %u, p = %08lx\n", base, p );
    printf( "*p = %c\n", *p );
    /*
     * The pointer 'p' can now be passed to any other
     * process that may want to access this shared
     * memory.
     */
  }

Classification:

QNX

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

See also:

errno, qnx_segment_alloc(), qnx_segment_arm(), qnx_segment_flags(), qnx_segment_free(), qnx_segment_get(), qnx_segment_huge(), qnx_segment_index(), qnx_segment_info(), qnx_segment_overlay_flags(), qnx_segment_overlay(), qnx_segment_put(), qnx_segment_raw_alloc(), qnx_segment_raw_free(), qnx_segment_realloc()


[Previous]
[Contents]
[Next]