man-pages/man3p/shmat.3p

124 lines
4.2 KiB
Plaintext

.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
.TH "SHMAT" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\" shmat
.SH NAME
shmat \- XSI shared memory attach operation
.SH SYNOPSIS
.LP
\fB#include <sys/shm.h>
.br
.sp
void *shmat(int\fP \fIshmid\fP\fB, const void *\fP\fIshmaddr\fP\fB,
int\fP \fIshmflg\fP\fB); \fP
\fB
.br
\fP
.SH DESCRIPTION
.LP
The \fIshmat\fP() function operates on XSI shared memory (see the
Base Definitions volume of IEEE\ Std\ 1003.1-2001, Section 3.340,
Shared Memory Object). It is unspecified whether this function
interoperates with the realtime interprocess communication facilities
defined in \fIRealtime\fP .
.LP
The \fIshmat\fP() function attaches the shared memory segment associated
with the shared memory identifier specified by
\fIshmid\fP to the address space of the calling process. The segment
is attached at the address specified by one of the following
criteria:
.IP " *" 3
If \fIshmaddr\fP is a null pointer, the segment is attached at the
first available address as selected by the system.
.LP
.IP " *" 3
If \fIshmaddr\fP is not a null pointer and (\fIshmflg\fP &SHM_RND)
is non-zero, the segment is attached at the address
given by (\fIshmaddr\fP -((\fIuintptr_t\fP)\fIshmaddr\fP %SHMLBA)).
The character \fB'%'\fP is the C-language remainder
operator.
.LP
.IP " *" 3
If \fIshmaddr\fP is not a null pointer and (\fIshmflg\fP &SHM_RND)
is 0, the segment is attached at the address given by
\fIshmaddr\fP.
.LP
.IP " *" 3
The segment is attached for reading if (\fIshmflg\fP &SHM_RDONLY)
is non-zero and the calling process has read permission;
otherwise, if it is 0 and the calling process has read and write permission,
the segment is attached for reading and writing.
.LP
.SH RETURN VALUE
.LP
Upon successful completion, \fIshmat\fP() shall increment the value
of \fIshm_nattch\fP in the data structure associated with
the shared memory ID of the attached shared memory segment and return
the segment's start address.
.LP
Otherwise, the shared memory segment shall not be attached, \fIshmat\fP()
shall return -1, and \fIerrno\fP shall be set to
indicate the error.
.SH ERRORS
.LP
The \fIshmat\fP() function shall fail if:
.TP 7
.B EACCES
Operation permission is denied to the calling process; see \fIXSI
Interprocess
Communication\fP .
.TP 7
.B EINVAL
The value of \fIshmid\fP is not a valid shared memory identifier,
the \fIshmaddr\fP is not a null pointer, and the value of
(\fIshmaddr\fP -((\fIuintptr_t\fP)\fIshmaddr\fP %SHMLBA)) is an illegal
address for attaching shared memory; or the
\fIshmaddr\fP is not a null pointer, (\fIshmflg\fP &SHM_RND) is 0,
and the value of \fIshmaddr\fP is an illegal address for
attaching shared memory.
.TP 7
.B EMFILE
The number of shared memory segments attached to the calling process
would exceed the system-imposed limit.
.TP 7
.B ENOMEM
The available data space is not large enough to accommodate the shared
memory segment.
.sp
.LP
\fIThe following sections are informative.\fP
.SH EXAMPLES
.LP
None.
.SH APPLICATION USAGE
.LP
The POSIX Realtime Extension defines alternative interfaces for interprocess
communication. Application developers who need to
use IPC should design their applications so that modules using the
IPC routines described in \fIXSI Interprocess Communication\fP can
be easily modified to use the alternative
interfaces.
.SH RATIONALE
.LP
None.
.SH FUTURE DIRECTIONS
.LP
None.
.SH SEE ALSO
.LP
\fIXSI Interprocess Communication\fP , \fIRealtime\fP , \fIexec\fP()
,
\fIexit\fP() , \fIfork\fP() , \fIshmctl\fP() , \fIshmdt\fP() , \fIshmget\fP()
, \fIshm_open\fP() ,
\fIshm_unlink\fP() , the Base Definitions volume of IEEE\ Std\ 1003.1-2001,
\fI<sys/shm.h>\fP
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group. In the
event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .