allocate a segment, setting option flags


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


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().

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().
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.
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.
Remove the restriction the a DMA-safe segment be in the first 16M of physical memory.
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.


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


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


#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.



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()