create a segment that overlays memory, specifying options


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


The qnx_segment_overlay_flags() function allows you to create a segment nbytes long that overlays memory at physical address address. This function is identical to qnx_segment_overlay() 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().

This flag returns 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().
This flag binds 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.
This flag treats the passed address as virtual, not physical, when running the 32-bit version of QNX using the pager. In the 16-bit version of QNX, the physical and virtual address are the same, so this flag is ignored.

This flag may need to be set if you pass an address as returned from qnx_segment_info(), since it returns a virtual address (unless the _PMF_DMA_SAFE flag is set).

This flag disables 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, or greater than 65536 bytes if you're running the 16-bit version of QNX.
Insufficient local process manager memory to manage the segment.
Insufficient permission to change a flag.


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

void main()
    unsigned color_base, mono_base;
    char __far *cp, __far *mp;

    /* Create a selector for color video memory */
    color_base = qnx_segment_overlay_flags(
            0xb8000, 32786, _PMF_GLOBAL );
    /* Create a selector for monochrome video memory */
    mono_base = qnx_segment_overlay_flags(
            0xb0000, 32786, _PMF_GLOBAL );
    /* Point at byte 100 in the display */
    cp = MK_FP( color_base, 100 );
    mp = MK_FP( mono_base, 100 );

    putchar( '\014' );
    fflush( stdout );
    /* Set the byte and read it back */
    *cp = 'a';
    *mp = 'a';
    printf( "color_base = %x, cp = %08lx\n",
         color_base, cp );
    printf( "mono_base = %x, mp = %08lx\n",
         mono_base, mp );
     * The cp and mp pointers can now be passed to any
     * process that wants to be able to write to
     * either color or monochrome text video memory.



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

See also:

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