blob: f9964f8e6f47859957a4a984bb2f6a6f55a0a14c [file] [log] [blame]
<!--
Documentation/_templates/layout.html
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. The
ASF licenses this file to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
-->
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Shared Memory Interfaces &mdash; NuttX latest documentation</title>
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/tabs.css" type="text/css" />
<link rel="stylesheet" href="../../_static/custom.css" type="text/css" />
<link rel="shortcut icon" href="../../_static/favicon.ico"/>
<!--[if lt IE 9]>
<script src="../../_static/js/html5shiv.min.js"></script>
<![endif]-->
<script src="../../_static/jquery.js"></script>
<script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script>
<script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/sphinx_highlight.js"></script>
<script src="../../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="Board IOCTL" href="13_boardctl.html" />
<link rel="prev" title="Network Interfaces" href="11_network.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> NuttX
</a>
<!-- this version selector is quite ugly, should be probably replaced by something
more modern -->
<div class="version-selector">
<select onchange="javascript:location.href = this.value;">
<option value="../../../latest" selected="selected">latest</option>
<option value="../../../10.0.0" >10.0.0</option>
<option value="../../../10.0.1" >10.0.1</option>
<option value="../../../10.1.0" >10.1.0</option>
<option value="../../../10.2.0" >10.2.0</option>
<option value="../../../10.3.0" >10.3.0</option>
<option value="../../../11.0.0" >11.0.0</option>
<option value="../../../12.0.0" >12.0.0</option>
<option value="../../../12.1.0" >12.1.0</option>
<option value="../../../12.2.0" >12.2.0</option>
<option value="../../../12.2.1" >12.2.1</option>
<option value="../../../12.3.0" >12.3.0</option>
<option value="../../../12.4.0" >12.4.0</option>
<option value="../../../12.5.0" >12.5.0</option>
<option value="../../../12.5.1" >12.5.1</option>
</select>
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">Table of Contents</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../introduction/index.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../quickstart/index.html">Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../contributing/index.html">Contributing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../introduction/inviolables.html">The Inviolable Principles of NuttX</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../platforms/index.html">Supported Platforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../components/index.html">OS Components</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../applications/index.html">Applications</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">API Reference</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="index.html">Userspace API</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="01_task_control.html">Task Control Interfaces</a></li>
<li class="toctree-l3"><a class="reference internal" href="02_task_scheduling.html">Task Scheduling Interfaces</a></li>
<li class="toctree-l3"><a class="reference internal" href="03_task_control.html">Task Control Interfaces</a></li>
<li class="toctree-l3"><a class="reference internal" href="04_message_queue.html">Named Message Queue Interfaces</a></li>
<li class="toctree-l3"><a class="reference internal" href="05_counting_semaphore.html">Counting Semaphore Interfaces</a></li>
<li class="toctree-l3"><a class="reference internal" href="06_clocks_timers.html">Clocks and Timers</a></li>
<li class="toctree-l3"><a class="reference internal" href="07_signals.html">Signal Interfaces</a></li>
<li class="toctree-l3"><a class="reference internal" href="08_pthread.html">Pthread Interfaces</a></li>
<li class="toctree-l3"><a class="reference internal" href="09_env_vars.html">Environment Variables</a></li>
<li class="toctree-l3"><a class="reference internal" href="10_filesystem.html">File System Interfaces</a></li>
<li class="toctree-l3"><a class="reference internal" href="11_network.html">Network Interfaces</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">Shared Memory Interfaces</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#functions">Functions</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="13_boardctl.html">Board IOCTL</a></li>
<li class="toctree-l3"><a class="reference internal" href="13_logging.html">Logging</a></li>
<li class="toctree-l3"><a class="reference internal" href="structures.html">OS Data Structures</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../os/index.html">Architecture APIs</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../faq/index.html">FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../guides/index.html">Guides</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary.html">Glossary</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">NuttX</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item"><a href="../index.html">API Reference</a></li>
<li class="breadcrumb-item"><a href="index.html">Userspace API</a></li>
<li class="breadcrumb-item active">Shared Memory Interfaces</li>
<li class="wy-breadcrumbs-aside">
<a href="../../_sources/reference/user/12_shared_memory.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<section id="shared-memory-interfaces">
<h1>Shared Memory Interfaces<a class="headerlink" href="#shared-memory-interfaces" title="Permalink to this heading"></a></h1>
<p>Shared memory interfaces are only available with the NuttX kernel build
(<code class="docutils literal notranslate"><span class="pre">CONFIG_BUILD_KERNEL=y</span></code>). These interfaces support user memory
regions that can be shared between multiple user processes. Shared
memory interfaces:</p>
<blockquote>
<div><ul class="simple">
<li><p><a class="reference internal" href="#c.shmget" title="shmget"><code class="xref c c-func docutils literal notranslate"><span class="pre">shmget()</span></code></a></p></li>
<li><p><a class="reference internal" href="#c.shmat" title="shmat"><code class="xref c c-func docutils literal notranslate"><span class="pre">shmat()</span></code></a></p></li>
<li><p><a class="reference internal" href="#c.shmctl" title="shmctl"><code class="xref c c-func docutils literal notranslate"><span class="pre">shmctl()</span></code></a></p></li>
<li><p><a class="reference internal" href="#c.shmdt" title="shmdt"><code class="xref c c-func docutils literal notranslate"><span class="pre">shmdt()</span></code></a></p></li>
</ul>
</div></blockquote>
<section id="functions">
<h2>Functions<a class="headerlink" href="#functions" title="Permalink to this heading"></a></h2>
<dl class="c function">
<dt class="sig sig-object c" id="c.shmget">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">shmget</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">key_t</span></span><span class="w"> </span><span class="n"><span class="pre">key</span></span>, <a class="reference internal" href="structures.html#c.size_t" title="size_t"><span class="n"><span class="pre">size_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">size</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">shmflg</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.shmget" title="Permalink to this definition"></a><br /></dt>
<dd><p>Returns the shared memory identifier associated with <code class="docutils literal notranslate"><span class="pre">key</span></code>.</p>
<p>A shared memory identifier, associated data structure, and shared memory
segment of at least size bytes is created for <code class="docutils literal notranslate"><span class="pre">key</span></code> if one of the
following is true:</p>
<ul class="simple">
<li><p>The argument <code class="docutils literal notranslate"><span class="pre">key</span></code> is equal to <code class="docutils literal notranslate"><span class="pre">IPC_PRIVATE</span></code>.</p></li>
<li><p>The argument <code class="docutils literal notranslate"><span class="pre">key</span></code> does not already have a shared memory identifier
associated with it and <code class="docutils literal notranslate"><span class="pre">(shmflg</span> <span class="pre">&amp;</span> <span class="pre">IPC_CREAT)</span></code> is non-zero.</p></li>
</ul>
<p>Upon creation, the data structure associated with the new shared memory
identifier will be initialized as follows:</p>
<ul class="simple">
<li><p>The low-order nine bits of <code class="docutils literal notranslate"><span class="pre">shm_perm.mode</span></code> are set equal to the
low-order nine bits of <code class="docutils literal notranslate"><span class="pre">shmflg</span></code>.</p></li>
<li><p>The value of <code class="docutils literal notranslate"><span class="pre">shm_segsz</span></code> is set equal to the value of size.</p></li>
<li><p>The values of <code class="docutils literal notranslate"><span class="pre">shm_lpid</span></code>, <code class="docutils literal notranslate"><span class="pre">shm_nattch</span></code>, <code class="docutils literal notranslate"><span class="pre">shm_atime</span></code>, and
<code class="docutils literal notranslate"><span class="pre">shm_dtime</span></code> are set equal to 0.</p></li>
<li><p>The value of <code class="docutils literal notranslate"><span class="pre">shm_ctime</span></code> is set equal to the current time.</p></li>
</ul>
<p>When the shared memory segment is created, it will be initialized with
all zero values.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>key</strong> – The key that is used to access the unique shared memory
identifier.</p></li>
<li><p><strong>size</strong> – The shared memory region that is created will be at least
this size in bytes.</p></li>
<li><p><strong>shmflg</strong> – See <code class="docutils literal notranslate"><span class="pre">IPC_*</span></code> definitions in <code class="docutils literal notranslate"><span class="pre">sys/ipc.h</span></code>. Only the
values <code class="docutils literal notranslate"><span class="pre">IPC_PRIVATE</span></code> or <code class="docutils literal notranslate"><span class="pre">IPC_CREAT</span></code> are supported.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p><p>Upon successful completion, <code class="docutils literal notranslate"><span class="pre">shmget()</span></code> will return
a non-negative integer, namely a shared memory identifier; otherwise, it
will return -1 and set <code class="docutils literal notranslate"><span class="pre">errno</span></code> to indicate the error.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">EACCES</span></code>. A shared memory identifier exists for key but operation
permission as specified by the low-order nine bits of <code class="docutils literal notranslate"><span class="pre">shmflg</span></code>
would not be granted.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">EEXIST</span></code>. A shared memory identifier exists for the argument key
but <code class="docutils literal notranslate"><span class="pre">(shmflg</span> <span class="pre">&amp;</span> <span class="pre">IPC_CREAT)</span> <span class="pre">&amp;&amp;</span> <span class="pre">(shmflg</span> <span class="pre">&amp;</span> <span class="pre">IPC_EXCL)</span></code> are non-zero.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">EINVAL</span></code>. A shared memory segment is to be created and the value of
size is less than the system-imposed minimum or greater than the
system-imposed maximum.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">EINVAL</span></code>. No shared memory segment is to be created and a shared
memory segment exists for key but the size of the segment associated
with it is less than size and size is not 0.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ENOENT</span></code>. A shared memory identifier does not exist for the
argument key and <code class="docutils literal notranslate"><span class="pre">(shmflg</span> <span class="pre">&amp;</span> <span class="pre">IPC_CREAT)</span></code> is 0.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ENOMEM</span></code>. A shared memory identifier and associated shared memory
segment will be created, but the amount of available physical memory
is not sufficient to fill the request.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ENOSPC</span></code>. A shared memory identifier is to be created, but the
system-imposed limit on the maximum number of allowed shared memory
identifiers system-wide would be exceeded.</p></li>
</ul>
</p>
</dd>
</dl>
<p><strong>POSIX Deviations</strong></p>
<ul class="simple">
<li><p>The values of <code class="docutils literal notranslate"><span class="pre">shm_perm.cuid</span></code>, <code class="docutils literal notranslate"><span class="pre">shm_perm.uid</span></code>, <code class="docutils literal notranslate"><span class="pre">shm_perm.cgid</span></code>,
and <code class="docutils literal notranslate"><span class="pre">shm_perm.gid</span></code> should be set equal to the effective user ID and
effective group ID, respectively, of the calling process. The NuttX
<code class="docutils literal notranslate"><span class="pre">ipc_perm</span></code> structure, however, does not support these fields
because user and group IDs are not yet supported by NuttX.</p></li>
</ul>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.shmat">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">shmat</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">shmid</span></span>, <span class="pre">FAR</span><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">shmaddr</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">shmflg</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.shmat" title="Permalink to this definition"></a><br /></dt>
<dd><p>Attaches the shared memory
segment associated with the shared memory identifier specified by
<code class="docutils literal notranslate"><span class="pre">shmid</span></code> to the address space of the calling process. The segment is
attached at the address specified by one of the following criteria:</p>
<ul class="simple">
<li><p>If <code class="docutils literal notranslate"><span class="pre">shmaddr</span></code> is a null pointer, the segment is attached at the
first available address as selected by the system.</p></li>
<li><p>If <code class="docutils literal notranslate"><span class="pre">shmaddr</span></code> is not a null pointer and <code class="docutils literal notranslate"><span class="pre">(shmflg</span> <span class="pre">&amp;</span> <span class="pre">SHM_RND)</span></code> is
non-zero, the segment is attached at the address given by
<code class="docutils literal notranslate"><span class="pre">(shmaddr</span> <span class="pre">-</span> <span class="pre">((uintptr_t)shmaddr</span> <span class="pre">%</span> <span class="pre">SHMLBA))</span></code>.</p></li>
<li><p>If <code class="docutils literal notranslate"><span class="pre">shmaddr</span></code> is not a null pointer and <code class="docutils literal notranslate"><span class="pre">(shmflg</span> <span class="pre">&amp;</span> <span class="pre">SHM_RND)</span></code> is 0,
the segment is attached at the address given by <code class="docutils literal notranslate"><span class="pre">shmaddr</span></code>.</p></li>
<li><p>The segment is attached for reading if <code class="docutils literal notranslate"><span class="pre">(shmflg</span> <span class="pre">&amp;</span> <span class="pre">SHM_RDONLY)</span></code> 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.</p></li>
</ul>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>shmid</strong> – Shared memory identifier</p></li>
<li><p><strong>smaddr</strong> – Determines mapping of the shared memory region</p></li>
<li><p><strong>shmflg</strong> – See <code class="docutils literal notranslate"><span class="pre">SHM_*</span></code> definitions in <code class="docutils literal notranslate"><span class="pre">include/sys/shm.h</span></code>. Only
<code class="docutils literal notranslate"><span class="pre">SHM_RDONLY</span></code> and <code class="docutils literal notranslate"><span class="pre">SHM_RND</span></code> are supported.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p><p>Upon successful completion, <code class="docutils literal notranslate"><span class="pre">shmat()</span></code> will
increment the value of <code class="docutils literal notranslate"><span class="pre">shm_nattch</span></code> in the data structure associated
with the shared memory ID of the attached shared memory segment and
return the segment’s start address. Otherwise, the shared memory segment
will not be attached, <code class="docutils literal notranslate"><span class="pre">shmat()</span></code> will return -1, and <code class="docutils literal notranslate"><span class="pre">errno</span></code> will be
set to indicate the error.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">EACCES</span></code>. Operation permission is denied to the calling process</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">EINVAL</span></code>. The value of <code class="docutils literal notranslate"><span class="pre">shmid</span></code> is not a valid shared memory
identifier, the <code class="docutils literal notranslate"><span class="pre">shmaddr</span></code> is not a null pointer, and the value of
<code class="docutils literal notranslate"><span class="pre">(shmaddr</span> <span class="pre">-((uintptr_t)shmaddr</span> <span class="pre">%</span> <span class="pre">SHMLBA))</span></code> is an illegal address
for attaching shared memory; or the <code class="docutils literal notranslate"><span class="pre">shmaddr</span></code> is not a null
pointer, <code class="docutils literal notranslate"><span class="pre">(shmflg</span> <span class="pre">&amp;</span> <span class="pre">SHM_RND)</span></code> is 0, and the value of <code class="docutils literal notranslate"><span class="pre">shmaddr</span></code> is
an illegal address for attaching shared memory.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">EMFILE</span></code>. The number of shared memory segments attached to the
calling process would exceed the system-imposed limit.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ENOMEM</span></code>. The available data space is not large enough to
accommodate the shared memory segment.</p></li>
</ul>
</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.shmctl">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">shmctl</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">shmid</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">cmd</span></span>, <span class="pre">FAR</span><span class="w"> </span><span class="k"><span class="pre">struct</span></span><span class="w"> </span><span class="n"><span class="pre">shmid_ds</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">buf</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.shmctl" title="Permalink to this definition"></a><br /></dt>
<dd><p>Provides a variety of shared
memory control operations as specified by <code class="docutils literal notranslate"><span class="pre">cmd</span></code>. The following values
for <code class="docutils literal notranslate"><span class="pre">cmd</span></code> are available:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">IPC_STAT</span></code>. Place the current value of each member of the
<code class="docutils literal notranslate"><span class="pre">shmid_ds</span></code> data structure associated with <code class="docutils literal notranslate"><span class="pre">shmid</span></code> into the
structure pointed to by <code class="docutils literal notranslate"><span class="pre">buf</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">IPC_SET</span></code>. Set the value of the <code class="docutils literal notranslate"><span class="pre">shm_perm.mode</span></code> member of the
<code class="docutils literal notranslate"><span class="pre">shmid_ds</span></code> data structure associated with <code class="docutils literal notranslate"><span class="pre">shmid</span></code> to the
corresponding value found in the structure pointed to by <code class="docutils literal notranslate"><span class="pre">buf</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">IPC_RMID</span></code>. Remove the shared memory identifier specified by
<code class="docutils literal notranslate"><span class="pre">shmid</span></code> from the system and destroy the shared memory segment and
<code class="docutils literal notranslate"><span class="pre">shmid_ds</span></code> data structure associated with it.</p></li>
</ul>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>shmid</strong> – Shared memory identifier</p></li>
<li><p><strong>cmd</strong><code class="docutils literal notranslate"><span class="pre">shmctl()</span></code> command</p></li>
<li><p><strong>buf</strong> – Data associated with the <code class="docutils literal notranslate"><span class="pre">shmctl()</span></code> command</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p><p>Upon successful completion, <code class="docutils literal notranslate"><span class="pre">shmctl()</span></code> will return
0; otherwise, it will return -1 and set <code class="docutils literal notranslate"><span class="pre">errno</span></code> to indicate the error.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">EACCES</span></code>. The argument <code class="docutils literal notranslate"><span class="pre">cmd</span></code> is equal to <code class="docutils literal notranslate"><span class="pre">IPC_STAT</span></code> and the
calling process does not have read permission.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">EINVAL</span></code>. The value of <code class="docutils literal notranslate"><span class="pre">shmid</span></code> is not a valid shared memory
identifier, or the value of <code class="docutils literal notranslate"><span class="pre">cmd</span></code>is not a valid command.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">EPERM</span></code>. The argument <code class="docutils literal notranslate"><span class="pre">cmd</span></code> is equal to <code class="docutils literal notranslate"><span class="pre">IPC_RMID</span></code> or
<code class="docutils literal notranslate"><span class="pre">IPC_SET</span></code> and the effective user ID of the calling process is not
equal to that of a process with appropriate privileges and it is not
equal to the value of <code class="docutils literal notranslate"><span class="pre">shm_perm.cuid</span></code> or <code class="docutils literal notranslate"><span class="pre">shm_perm.uid</span></code> in the
data structure associated with <code class="docutils literal notranslate"><span class="pre">shmid</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">EOVERFLOW</span></code>. The <code class="docutils literal notranslate"><span class="pre">cmd</span></code> argument is <code class="docutils literal notranslate"><span class="pre">IPC_STAT</span></code> and the <code class="docutils literal notranslate"><span class="pre">gid</span></code>
or <code class="docutils literal notranslate"><span class="pre">uid</span></code> value is too large to be stored in the structure pointed
to by the <code class="docutils literal notranslate"><span class="pre">buf</span></code> argument.</p></li>
</ul>
</p>
</dd>
</dl>
<p><strong>POSIX Deviations</strong></p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">IPC_SET</span></code>. Does not set the <code class="docutils literal notranslate"><span class="pre">shm_perm.uid</span></code> or
<code class="docutils literal notranslate"><span class="pre">shm_perm.gid</span></code>members of the <code class="docutils literal notranslate"><span class="pre">shmid_ds</span></code> data structure
associated with <code class="docutils literal notranslate"><span class="pre">shmid</span></code> because user and group IDs are not yet
supported by NuttX</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">IPC_SET</span></code>. Does not restrict the operation to processes with
appropriate privileges or matching user IDs in <code class="docutils literal notranslate"><span class="pre">shmid_ds</span></code> data
structure associated with <code class="docutils literal notranslate"><span class="pre">shmid</span></code>. Again because user IDs and
user/group privileges are are not yet supported by NuttX</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">IPC_RMID</span></code>. Does not restrict the operation to processes with
appropriate privileges or matching user IDs in <code class="docutils literal notranslate"><span class="pre">shmid_ds</span></code> data
structure associated with <code class="docutils literal notranslate"><span class="pre">shmid</span></code>. Again because user IDs and
user/group privileges are are not yet supported by NuttX</p></li>
</ul>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.shmdt">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">shmdt</span></span></span><span class="sig-paren">(</span><span class="pre">FAR</span><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">shmaddr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.shmdt" title="Permalink to this definition"></a><br /></dt>
<dd><p>Detaches the shared memory
segment located at the address specified by <code class="docutils literal notranslate"><span class="pre">shmaddr</span></code> from the address
space of the calling process.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>shmid</strong> – Shared memory identifier</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p><p>Upon successful completion, <code class="docutils literal notranslate"><span class="pre">shmdt()</span></code> will
decrement the value of <code class="docutils literal notranslate"><span class="pre">shm_nattch</span></code> in the data structure associated
with the shared memory ID of the attached shared memory segment and
return 0.</p>
<p>Otherwise, the shared memory segment will not be detached, <code class="docutils literal notranslate"><span class="pre">shmdt()</span></code>
will return -1, and <code class="docutils literal notranslate"><span class="pre">errno</span></code> will be set to indicate the error.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">EINVAL</span></code>. The value of <code class="docutils literal notranslate"><span class="pre">shmaddr</span></code> is not the data segment start
address of a shared memory segment.</p></li>
</ul>
</p>
</dd>
</dl>
</dd></dl>
</section>
</section>
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="11_network.html" class="btn btn-neutral float-left" title="Network Interfaces" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="13_boardctl.html" class="btn btn-neutral float-right" title="Board IOCTL" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
<div role="contentinfo">
<p>&#169; Copyright 2020, The Apache Software Foundation.</p>
</div>
</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>