ibm-information-center/dist/eclipse/plugins/i5OS.ic.apis_5.4.0.1/ipcshmat.htm

359 lines
10 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
<title>shmat()-Attach Shared Memory Segment to Current Process</title>
<!-- Begin Header Records ========================================== -->
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<!-- Change History: -->
<!-- YYMMDD USERID Change description -->
<!-- Direct1 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
<!-- Edited by Kersten Feb 02 -->
<!-- This file has undergone html cleanup on 05/01/02 by JET -->
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body>
<!--End Header Records -->
<!-- Java sync-link -->
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
</script>
<a name="Top_Of_Page"></a>
<h2>shmat()--Attach Shared Memory Segment to Current Process</h2>
<div class="box" style="width: 70%;">
<br>
&nbsp;&nbsp;Syntax<br>
<pre>
#include &lt;sys/shm.h&gt;
void *shmat(int <em>shmid</em>, const void <em>*shmaddr</em>,
int <em>shmflg</em>);
</pre>
<br>
&nbsp;&nbsp;Service Program Name: QP0ZUSHR<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: Yes<br>
<!-- iddvc RMBR -->
<br>
</div>
<p>The <strong>shmat()</strong> function attaches to the shared memory segment
specified by <em>shmid</em> and returns the address of the shared
memory segment.</p>
<p>The address specified by <em>shmaddr</em> is only used when <strong>
shmat()</strong> is called from a program that uses data model *LLP64 and
attaches to a teraspace shared memory segment. Otherwise the address specified
by <em>shmaddr</em> is ignored and the actual shared memory segment address
is returned regardless of the value of <em>shmaddr</em>.</p>
<p>The system maintains status information about a shared memory segment which can
be retrieved with the <a href="ipcshmct.htm">shmctl()</a> function. When a shared
memory segment is successfully attached, the system sets the members of the
<samp>shmid_ds</samp> structure as follows:<p>
<ul>
<li><samp>shm_nattch</samp> is incremented by 1.<p></li>
<li><samp>shm_lpid</samp> is set to the process ID of the calling thread.<p></li>
<li><samp>shm_atime</samp> is set to the current time.</li>
</ul>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong>shmid</strong></dt>
<dd>(Input) Shared memory identifier, a positive integer. It is returned by the
<a href="ipcshmgt.htm">shmget()</a> function and used to identify the shared memory
segment.<br>
<br>
</dd>
<dt><strong>shmaddr</strong></dt>
<dd>(Input) Shared memory address. The address at which the calling thread
would like the shared memory segment attached.<br>
<br>
</dd>
<dt><strong>shmflg</strong></dt>
<dd>(Input) Operations flags. The value of the <em>shmflg</em> parameter is either zero
or is obtained by performing an OR operation on one or more of the
following constants:<p>
<dl>
<dt><strong>SHM_RDONLY (0x00001000)</strong></dt>
<dd>Attach the shared memory segment in read-only
mode. This flag is valid only for teraspace shared memory segments.</dd>
</dl>
</dd>
</dl>
<br>
<h3>Authorities</h3>
<p><strong><a name="TBLAHAT1">Authorization Required for shmat()</a></strong></p>
<table border cellpadding="5">
<!-- cols="60 20 20" -->
<tr>
<th align="left" valign="bottom">Object Referred to</th>
<th align="left" valign="bottom">Authority Required</th>
<th align="left" valign="bottom">errno</th>
</tr>
<tr>
<td align="left" valign="top">Shared memory segment to be attached in
read/write memory</td>
<td align="left" valign="top">Read and Write</td>
<td align="left" valign="top">EACCES</td>
</tr>
<tr>
<td align="left" valign="top">Shared memory segment to be attached in read-only
memory in a process's teraspace.</td>
<td align="left" valign="top">Read</td>
<td align="left" valign="top">EACCES</td>
</tr>
</table>
<br>
<h3>Return Value</h3>
<table cellpadding="5">
<!-- cols="15 85" -->
<tr>
<td align="left" valign="top"><em>value</em></td>
<td align="left" valign="top"><strong>shmat()</strong> was successful. The
value returned is a pointer to the shared memory segment associated with the
specified identifier.</td>
</tr>
<tr>
<td align="left" valign="top"><em>NULL</em></td>
<td align="left" valign="top"><strong>shmat()</strong> was not successful. The
<em>errno</em> variable is set to indicate the error.</td>
</tr>
</table>
<br>
<h3>Error Conditions</h3>
<p>If <strong>shmat()</strong> is not successful, <em>errno</em> usually
indicates one of the following errors. Under some conditions, <em>errno</em>
could indicate an error other than those listed here.</p>
<dl>
<dt><em>[EACCES]</em></dt>
<dd>
<p>Permission denied.</p>
<p>An attempt was made to access an object in a way forbidden by its object
access permissions.</p>
<p>The thread does not have access to the specified file, directory, component,
or path.</p>
<p>Operation permission is denied to the calling thread.</p>
<p>Shared memory operations are not permitted because the QSHRMEMCTL system
value is set to 0.</p>
<p>The shared memory segment is to be attached in read/write mode and the calling
thread does not read and write permission to the shared memory segment.</p>
<p>The shared memory segment is to be attached in read-only mode and the calling
thread does not read permission to the shared memory segment.</p>
</dd>
<dt><em>[EADDRINUSE]</em></dt>
<dd>
<p>A damaged object was encountered.</p>
<p>Address already in use.</p>
<p>An attempt was made to attach to a teraspace shared memory segment with the
SHM_MAP_FIXED_NP attribute and the address range is not available in the
teraspace of the current job.</p>
</dd>
<dt><em>[EDAMAGE]</em></dt>
<dd>
<p>A damaged object was encountered.</p>
<p>The shared memory segment has been damaged by a previous shared memory
operation.</p>
</dd>
<dt><em>[EFAULT]</em></dt>
<dd>
<p>The address used for an argument is not correct.</p>
<p>In attempting to use an argument in a call, the system detected an address
that is not valid.</p>
<p>While attempting to access a parameter passed to this function, the system
detected an address that is not valid.</p>
</dd>
<dt><em>[EINVAL]</em></dt>
<dd>
<p>The value specified for the argument is not correct.</p>
<p>A function was passed incorrect argument values, or an operation was
attempted on an object and the operation specified is not supported for that
type of object.</p>
<p>An argument value is not valid, out of range, or NULL.</p>
<p>The <em>shmid</em> parameter is not a valid shared memory identifier.</p>
</dd>
<dt><em>[EOPNOTSUPP]</em></dt>
<dd>
<p>Operation not supported.</p>
<p>The operation, though supported in general, is not supported for the
requested object or the requested arguments.</p>
<p>The SHM_RDONLY flag is set in the <em>shmflg</em> parameter.
Read-only shared memory segments are not supported for
nonteraspace shared memory segments and for shared memory segments
created with the SHM_MAP_FIXED_NP attribute.</p>
</dd>
<dt><em>[ENOMEM]</em></dt>
<dd>
<p>Storage allocation request failed.</p>
<p>A function needed to allocate storage, but no storage is available.</p>
<p>The available data space is not large enough to accommodate the shared
memory segment.</p>
</dd>
<dt><em>[EUNKNOWN]</em></dt>
<dd>
<p>Unknown system state.</p>
<p>The operation failed because of an unknown system state. See any messages in
the job log and correct any errors that are indicated, then retry the
operation.</p>
</dd>
</dl>
<br>
<h3>Error Messages</h3>
<p>None.</p>
<br>
<h3><a name="USAGE_NOTES">Usage Notes</a></h3>
<ol>
<li>The only supported operation flag is SHM_RDONLY. This operation flag is
supported only when you attach to a teraspace shared memory segment. If <em>
shmflg</em> specifies SHM_RDONLY for a nonteraspace shared memory segment,
then an [EOPNOTSUPP] error is returned. All other values for <em>shmflg</em>
are ignored.<br>
<br>
</li>
<li>A module that was not created with teraspace memory enabled should not
attach to a teraspace shared memory segment. The call to <em>shmat()</em>
will succeed and return a pointer. Any attempt, however, by a module not
created with teraspace memory enabled to use the returned pointer will result
in an MCH3601 (Pointer not set for location referenced) exception.<br>
<br>
</li>
<li>When a job attaches to a shared memory segment that was created with the
SHM_MAP_FIXED_NP attribute, an address range within the job's teraspace is used for
the shared memory mapping. When a subsequent job attaches to the shared
memory segment, the same address range within its teraspace must be available.
If the address range is not available, the call to <em>shmat()</em> will fail
with an [EADDRINUSE] error.<br>
<br>
</li>
<li>The storage for a shared memory segment is allocated when the first job
attaches to the shared memory segment. The storage is charged against the
job's temporary storage limit. If the job does not have enough
temporary storage to satisfy the request, the call to <em>shmat()</em> will
fail with an [ENOMEM] error.</li>
</ol>
<br>
<h3>Related Information</h3>
<ul>
<li>The &lt;<strong>sys/shm.h</strong>&gt; file (see <a href="unix13.htm">
Header Files for UNIX-Type Functions</a>)<br>
<br>
</li>
<li><a href="ipcshmat.htm">shmctl()</a>--Perform Shared Memory Control
Operations<br>
<br>
</li>
<li><a href="ipcshmgt.htm">shmget()</a>--Get ID of Shared Memory Segment with
Key<br>
<br>
</li>
<li><a href="ipcshmdt.htm">shmdt()</a>--Detach Shared Memory Segment from
Calling Process</li>
</ul>
<br>
<h3>Example</h3>
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
for information pertaining to code examples.</p>
<p>For an example of using this function, see <a href="../apiref/apiexusmem.htm">
Using Semaphores and Shared Memory</a> in Examples: APIs.</p>
<br>
<hr>
API introduced: V3R6
<hr>
<center>
<table cellpadding="2" cellspacing="2">
<tr align="center">
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> | <a href=
"unix.htm">UNIX-Type APIs</a> | <a href="aplist.htm">APIs by category</a></td>
</tr>
</table>
</center>
</body>
</html>