[Previous]
[Contents]
[Next]

qnx_segment_get()

get shared access to a segment

Synopsis:

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

Description:

The qnx_segment_get() function is used to get shared access to the segment segment owned by process pid.

If pid is zero, the calling process is used. Otherwise, the other process must have given you access to the segment by calling qnx_segment_arm().

You would typically learn the value of the segment from another process via a message exchange. Note that the segment returned by this function won't, in general, be the same as the segment passed to it as an argument:

You should only attempt to use the segment local to you.

If the flags argument contains _PMF_ALIGN, a segment is allocated in both your LDT and the pid's LDT, which is the same. This can sometimes be useful if a segment is in a common table accessed by two processes. In this case, you would have to inform the other process of the value of this segment, typically in a reply message. The only flag that's valid is _PMF_ALIGN.

Returns:

Errors:

EINVAL
The segment doesn't exist.
ENOMEM
Insufficient local process manager memory to manage the segment.
EPERM
You don't have permission to get the segment.
ESRCH
Process pid doesn't exist.

Examples:

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

pid_t childpid;
struct {
  unsigned seg;
  } msg;

void main()
  {
    if( childpid = fork() )
      parent();
    else
      child();
  }

void parent()
  {
    unsigned char buf[100];
    unsigned seg;

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

void child()
  {
    unsigned seg;
    pid_t pid;

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

Classification:

QNX

Safety:
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_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]