1
0
Files
irix-657m-src/eoe/man/man2/shmop.2
2022-09-29 17:59:04 +03:00

210 lines
5.3 KiB
Groff

'\"macro stdmacro
.if n .pH g2.shmop @(#)shmop 41.3 of 5/26/91
.\" Copyright 1991 UNIX System Laboratories, Inc.
.\" Copyright 1989, 1990 AT&T
.nr X
.if \nX=0 .ds x} shmop 2 "" "\&"
.if \nX=1 .ds x} shmop 2 ""
.if \nX=2 .ds x} shmop 2 "" "\&"
.if \nX=3 .ds x} shmop "" "" "\&"
.TH \*(x}
.SH NAME
\f4shmop\f1: \f4shmat\fP, \f4shmdt\fP \- shared memory operations
.Op c p a
.SH C SYNOPSIS
\f4#include <sys/types.h>\f1
.br
\f4#include <sys/ipc.h>\f1
.br
\f4#include <sys/shm.h>\f1
.PP
\f4void \(**shmat(int shmid, void \(**shmaddr, int shmflg);\f1
.PP
\f4int shmdt (void \(**shmaddr);\f1
.Op
.Op f
.SH FORTRAN SYNOPSIS
\f4integer \(**4 function shmdt (shmaddr)\f1
.br
\f4integer\(**4 shmaddr\f1
.br
\f4integer \(**4 function shmat (shmid, shmaddr, shmflg)\f1
.br
\f4integer\(**4 shmid\f1
.br
\f4integer\(**4 shmaddr\f1
.br
\f4integer\(**4 shmflg\f1
.Op
.SH DESCRIPTION
\f4shmat\fP
attaches the shared memory segment associated with the shared memory identifier
specified by
.I shmid
to the data segment of the calling process.
The segment is attached at the address specified by one of the following
criteria:
.IP
If
.I shmaddr
is equal to \f4(void *) 0\f1, the segment is attached at the first available
address as selected by the system.
.IP
If
.I shmaddr
is not equal to \f4(void *) 0\f1 and
(\f2shmflg\f4&SHM_RND\f1)
is true, the segment is attached at the address given by
(\f2shmaddr \f4-\f1
(\f2shmaddr\f1
modulus
\f4SHMLBA\f1)).
.IP
If
.I shmaddr
is not equal to \f4(void *) 0\f1 and
(\f2shmflg\f4&SHM_RND\f1)
is false, the segment is attached at the address given by
.IR shmaddr .
.PP
The actual argument corresponding to shmaddr is evaluated by
setting an INTEGER*4 variable to the location of the process's
data segment i.e. the value returned by \f4%loc\f1(3F).
.PP
Under certain conditions, performance
can be greatly improved by sharing mapping resources
among processes attached to the same SHM
segment. In order to achieve sharing of mapping resources, the following
conditions must hold:
.ta 0.65i
.TP 4
-
the size of the SHM segment is a multiple of the constant
\f4SHMSUS\f1 (SHM Segment Unit Size).
.TP
-
the attaching address \f3shmaddr\f1 is not equal to \f4(void *) 0\f1
and it's a multiple of \f4SHMSUS\f1.
.TP
-
(\f2shmflg\f4&SHM_RDONLY\f1) is false
.PP
The caller authorizes the system to use shared mapping resources
by setting the flag \f4SHM_SHATTR\f1 in \f2shmflg\f1.
.PP
If (\f2shmflg\f4&SHM_SHATTR\f1) is true and the above
conditions are met the system uses shared mapping resources.
.PP
If (\f2shmflg\f4&SHM_SHATTR\f1) is true and any of the
above conditions are false the system call fails.
.PP
Use of the \f4SHM_SHATTR\f1 flag is discouraged in the following
situations:
.TP
-
if the calling process is likely to unmap (\f2munmap\f1(2))
or to re-map (\f2mmap\f1(2)) large portions of the SHM
segment, or
.TP
-
if the calling process is likely to change the mapping attributes
(access permissions and cache policies) on large portions
of the SHM segment (\f2mprotect\f1(2)).
.PP
These behaviors cause the system to
make private copies of mapping resources
and stop sharing, thereby defeating the
purpose of the \f4SHM_SHATTR\f1 capability.
.PP
\f4shmdt\fP
detaches from the calling process's data segment
the shared memory segment located at the address specified by
.IR shmaddr .
.PP
The segment is attached for reading if
(\f2shmflg\f4&SHM_RDONLY\f1)
is true
.SM \%{READ}\*S,
otherwise it is attached for reading and writing
.SM \%{READ/WRITE}\*S.
.PP
\f4shmat\fP
fails and does not attach the shared memory segment if one or more of the
following are true:
.TP 15
\f4EINVAL\fP
.I shmid
is not a valid shared memory identifier.
.TP
\f4EACCES\fP
Operation permission is denied to the calling process [see
\f4intro\fP(2)].
.TP
\f4ENOMEM\fP
The available data space
is not large enough to accommodate the shared memory segment.
.TP
\f4EINVAL\fP
.I shmaddr
is not equal to zero, and the value of
(\f2shmaddr \f4-\f1
(\f2shmaddr\f1
modulus
\f4SHMLBA\f1)).
is an illegal address.
.TP
\f4EINVAL\fP
.I shmaddr
is not equal to zero,
(\f2shmflg\f4&SHM_RND\f1)
is false, and the value of
.I shmaddr
is an illegal address.
.TP
\f4EMFILE\fP
The number of shared memory segments attached to the calling process would
exceed the system-imposed limit.
.TP
\f4EINVAL\fP
.I shmaddr
is equal to zero and (\f2shmflg\f4&SHM_SHATTR\f1) is true, or
\f2shmddr\f1 is not a multiple of SHMSUS and
(\f2shmflg\f4&SHM_SHATTR\f1) is true, or the size
of the SHM segment is not a multiple of SHMSUS and
(\f2shmflg\f4&SHM_SHATTR\f1) is true.
.TP
\f4EACCESS\fP
.I
(\f2shmflg\f4&SHM_SHATTR\f1) is true and
(\f2shmflg\f4&SHM_RDONLY\f1) is true.
.PP
.TP 15
\f4EINVAL\fP
\f4shmdt\fP
fails and does not detach the shared memory segment if
.I shmaddr
is not the data segment start address of a shared memory segment.
.SH SEE ALSO
\f4intro\fP(2),
\f4exec\fP(2), \f4exit\fP(2), \f4fork\fP(2),
\f4shmctl\fP(2), \f4shmget\fP(2),
\f4sproc\fP(2).
.SH DIAGNOSTICS
Upon successful completion, the return value is as follows:
.ne 8v
.IP
\f4shmat\fP
returns the data segment start address of the attached shared memory segment.
.IP
\f4shmdt\fP
returns a value of 0.
.PP
Otherwise, a value of \-1 is returned and
\f4errno\fP
is set to indicate the error.
.SH NOTES
The user must explicitly remove shared memory segments
after the last reference to them has been removed.
.\" @(#)shmop.2 6.2 of 9/6/83
.Ee