give another process shared access to a segment


#include <sys/seginfo.h>
unsigned qnx_segment_put( pid_t pid,
                          unsigned segment,
                          unsigned flags );


The qnx_segment_put() function is used to give process pid shared access to the calling process's segment. If pid is zero, the calling process is used. Otherwise, the other process must have given you access to give the segment by calling qnx_segment_arm().

Note: The segment returned by this call won't, in general, be the same as the segment passed as an argument:
  • The one passed as an argument is local to your process (your Local Descriptor Table).
  • The one returned is local to the pids process (its LDT), and you cannot use it directly.

You would typically pass the value of the new segment to the other process using a message exchange. If the flags argument contains _PMF_ALIGN, a segment is allocated in both your LDT and the pid's LDT, which are the same. This can sometimes be useful if a segment is in a common table accessed by two processes.

By default, the flags of the source segment are inherited. If the flags argument contains _PMF_INUSE, the following flags are taken from the flags argument:

In this case you MUST specify all flags that you want passed to the new segment.



The segment doesn't exist.
Insufficient local process manager memory to manage the segment.
You don't have permission to put the segment.
The pid is invalid.


#include <stdio.h>
#include <i86.h>
#include <process.h>
#include <unistd.h>
#include <sys/kernel.h>
#include <sys/seginfo.h>

pid_t childpid;
struct {
  unsigned seg;
  } msg;

void main()
    if( childpid = fork() )

void parent()
    unsigned seg;

    qnx_segment_arm( childpid, -1, 0 );
    Send( childpid, &msg, &msg,
          sizeof( msg ), sizeof( msg ) );
    seg = msg.seg;
    printf( "Parent seg %4.4X.\n", seg );

void child()
    unsigned seg;
    unsigned char buf[100];
    pid_t pid;

    seg = FP_SEG( buf );
    printf( "Child seg %4.4X.\n", seg );
    pid = Receive( 0, &msg, sizeof( msg ) );
    msg.seg = qnx_segment_put( pid, seg, 0 );
    Reply( pid, &msg, sizeof( msg ) );



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_flags(), qnx_segment_overlay(), qnx_segment_raw_alloc(), qnx_segment_raw_free(), qnx_segment_realloc()