GNU Info

Info Node: (ipc.info)shmat

(ipc.info)shmat


Next: shmdt Prev: shmget Up: Shared Memory
Enter node , (file) or (file)node

shmat
-----

Maps a shared segment into the process' address space.

     char *virt_addr;
     virt_addr =  shmat (int shmid, char *shmaddr, int shmflg);

   * shmid : id got from call to shmget.

   * shmaddr : requested attach address.
     If shmaddr is 0 the system finds an unmapped region.
     If a non-zero value is indicated the value must be page
     aligned or the user must specify the SHM_RND flag.

   * shmflg :
     SHM_RDONLY : request read-only attach.
     SHM_RND : attach address is rounded DOWN to a multiple of SHMLBA.

   * returns: virtual address of attached segment. -1 on failure.

   When shmaddr is 0, the attach address is determined by finding an
unmapped region in the address range 1G to 1.5G, starting at 1.5G and
coming down from there. The algorithm is very simple so you are
encouraged to avoid non-specific attaches.

Algorithm:
     Determine attach address as described above.
     Check region (shmaddr, shmaddr + size) is not mapped and allocate
     page tables (undocumented SHM_REMAP flag!).
     Map the region by setting up pointers into the internal page table.
     Add a descriptor for the attach to the task struct for the process.
     `shm_nattch', `shm_lpid', `shm_atime' are updated.

Notes:
The `brk' value is not altered.  The segment is automatically detached
when the process exits.  The same segment may be attached as read-only
or read-write and more than once in the process' address space.  A
shmat can succeed on a segment marked for destruction.  The request for
a particular type of attach is made using the SHM_RDONLY flag.  There
is no notion of a write-only attach. The requested attach permissions
must fall within those allowed by `shm_perm.mode'.

Errors:
EACCES : Do not have permission for requested access.
EINVAL : shmid < 0 or unused, shmaddr not aligned, attach at brk failed.
EIDRM  : resource was removed.
ENOMEM : Could not allocate memory for descriptor or page tables.


automatically generated by info2www version 1.2.2.9