summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-09-22 14:53:56 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-09-22 14:53:56 -0600
commit43563c78b859b26a888ff191b3fb96cac64f509a (patch)
tree0f359cd2c1ab4c04c7703e459627e3af7fee94be
parent8680c863eeac9dd459224573465ba336ee2cd834 (diff)
downloadnuttx-43563c78b859b26a888ff191b3fb96cac64f509a.tar.gz
nuttx-43563c78b859b26a888ff191b3fb96cac64f509a.tar.bz2
nuttx-43563c78b859b26a888ff191b3fb96cac64f509a.zip
Add the build framework and skeleton files for the shared memory feature (no logic yet provided)
-rw-r--r--nuttx/Documentation/NuttxUserGuide.html344
-rw-r--r--nuttx/configs/mikroe-stm32f4/src/up_nsh.c4
-rw-r--r--nuttx/include/sys/ipc.h13
-rw-r--r--nuttx/include/sys/shm.h2
-rw-r--r--nuttx/mm/Kconfig9
-rw-r--r--nuttx/mm/shm/Make.defs1
-rwxr-xr-xnuttx/mm/shm/shmat.c127
-rwxr-xr-xnuttx/mm/shm/shmctl.c135
-rwxr-xr-xnuttx/mm/shm/shmdt.c99
-rwxr-xr-xnuttx/mm/shm/shmget.c149
10 files changed, 853 insertions, 30 deletions
diff --git a/nuttx/Documentation/NuttxUserGuide.html b/nuttx/Documentation/NuttxUserGuide.html
index 07246ff7e..480c7daf7 100644
--- a/nuttx/Documentation/NuttxUserGuide.html
+++ b/nuttx/Documentation/NuttxUserGuide.html
@@ -13,7 +13,7 @@
<h1><big><font color="#3c34ec"><i>NuttX Operating System<p>User's Manual</i></font></big></h1>
<p><small>by</small></p>
<p>Gregory Nutt<p>
- <p>Last Updated: August 21, 2014</p>
+ <p>Last Updated: September 22, 2014</p>
</td>
</tr>
</table>
@@ -63,6 +63,7 @@
<li>Paragraph 2.9 <a href="#Environ">Environment Variables</a></li>
<li>Paragraph 2.10 <a href="#FileSystem">File System Interfaces</a></li>
<li>Paragraph 2.11 <a href="#Network">Network Interfaces</a></li>
+ <li>Paragraph 2.12 <a href="#SharedMemory">Shared Memory Interfaces</a></li>
</ul>
</li>
<li>
@@ -8419,25 +8420,24 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags, int fd, off_
</tr>
</table>
-<p>NuttX includes a simple interface layer based on uIP (see <a href="http://www.sics.se/~adam/uip/index.php/Main_Page">http://www.sics.se</a>).
-NuttX supports subset of a standard socket interface to uIP.
-These network feature can be enabled by settings in the architecture
-<a href="NuttXConfigVariables.html">configuration file</a>.
-Those socket APIs are discussed in the following paragraphs.</p>
+<p>
+ NuttX includes a simple interface layer based on uIP (see <a href="http://www.sics.se/~adam/uip/index.php/Main_Page">http://www.sics.se</a>).
+ NuttX supports subset of a standard socket interface to uIP.
+ These network feature can be enabled by settings in the architecture <a href="NuttXConfigVariables.html">configuration file</a>.
+ Those socket APIs are discussed in the following paragraphs.
+</p>
<ul>
-<li>
-</li>
-<li><a href="#socket">2.11.1 socket</a></li>
-<li><a href="#bind">2.11.2 bind</a></li>
-<li><a href="#connect">2.11.3 connect</a></li>
-<li><a href="#listen">2.11.4 listen</a></li>
-<li><a href="#accept">2.11.5 accept</a></li>
-<li><a href="#send">2.11.6 send</a></li>
-<li><a href="#sendto">2.11.7 sendto</a></li>
-<li><a href="#recv">2.11.8 recv</a></li>
-<li><a href="#recvfrom">2.11.9 recvfrom</a></li>
-<li><a href="#setsockopt">2.11.10 setsockopt</a></li>
-<li><a href="#getsockopt">2.11.11 getsockopt</a></li>
+ <li><a href="#socket">2.11.1 socket</a></li>
+ <li><a href="#bind">2.11.2 bind</a></li>
+ <li><a href="#connect">2.11.3 connect</a></li>
+ <li><a href="#listen">2.11.4 listen</a></li>
+ <li><a href="#accept">2.11.5 accept</a></li>
+ <li><a href="#send">2.11.6 send</a></li>
+ <li><a href="#sendto">2.11.7 sendto</a></li>
+ <li><a href="#recv">2.11.8 recv</a></li>
+ <li><a href="#recvfrom">2.11.9 recvfrom</a></li>
+ <li><a href="#setsockopt">2.11.10 setsockopt</a></li>
+ <li><a href="#getsockopt">2.11.11 getsockopt</a></li>
</ul>
<h3><a name="socket">2.11.1 <code>socket</code></a></h3>
@@ -8983,8 +8983,7 @@ int setsockopt(int sockfd, int level, int option,
</p>
<ul><pre>
#include &lt;sys/socket.h&gt;
-int getsockopt(int sockfd, int level, int option,
- void *value, socklen_t *value_len);
+int getsockopt(int sockfd, int level, int option, void *value, socklen_t *value_len);
</pre></ul>
<p>
<b>Description:</b>
@@ -9035,6 +9034,309 @@ int getsockopt(int sockfd, int level, int option,
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
+ <a name="SharedMemory"><h2>2.12 Shared Memory Interfaces</h2></a>
+ </td>
+ </tr>
+</table>
+<p>
+ Shared memory interfaces are only available with the NuttX kernel build (<code>CONFIG_BUILD_KERNEL=y</code>).
+ These interfaces support user memory regions that can be shared between multiple user processes.
+ Shared memory interfaces:
+</p>
+<ul>
+ <li><a href="#shmget">2.12.1 shmget</a></li>
+ <li><a href="#shmat">2.12.2 shmat</a></li>
+ <li><a href="#shmctl">2.12.3 shmctl</a></li>
+ <li><a href="#shmdt">2.12.4 shmdt</a></li>
+</ul>
+<p>
+ <b>NOTE</b>: This is advance documentation. These interfaces are not yet available as of this writing. If you are reading this note, then double check; since these interfaces are under development now, I may have simply failed to remove it.
+</p>
+
+<h3><a name="shmget">2.12.1 <code>shmget</code></a></h3>
+<p>
+ <b>Function Prototype:</b>
+</p>
+<ul><pre>
+#include &lt;sys/shm.h&gt;
+#include &lt;sys/ipc.h&gt;
+int shmget(key_t key, size_t size, int shmflg);
+</pre></ul>
+<p>
+ <b>Description:</b>
+ The <code>shmget()</code> function will return the shared memory identifier associated with <code>key</code>.
+</p>
+<p>
+ A shared memory identifier, associated data structure, and shared memory segment of at least size bytes is created for <code>key</code> if one of the following is true:
+</p>
+<ul>
+ <li>
+ <p>
+ The argument <code>key</code> is equal to <code>IPC_PRIVATE</code>.
+ </p>
+ </li>
+ <li>
+ <p>
+ The argument <code>key</code> does not already have a shared memory identifier associated with it and <code>(shmflg & IPC_CREAT)</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>
+ <li>
+ <p>
+ The values of <code>shm_perm.cuid</code>, <code>shm_perm.uid</code>, <code>shm_perm.cgid</code>, and <code>shm_perm.gid</code> are set equal to the effective user ID and effective group ID, respectively, of the calling process.
+ </p>
+ </li>
+ <li>
+ <p>
+ The low-order nine bits of <code>shm_perm.mode</code> are set equal to the low-order nine bits of <code>shmflg</code>.
+ </p>
+ </li>
+ <li>
+ <p>
+ The value of <code>shm_segsz</code> is set equal to the value of size.
+ </p>
+ </li>
+ <li>
+ <p>
+ The values of <code>shm_lpid</code>, <code>shm_nattch</code>, <code>shm_atime</code>, and <code>shm_dtime</code> are set equal to 0.
+ </p>
+ </li>
+ <li>
+ <p>
+ The value of <code>shm_ctime</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>
+<p>
+ <b>Input Parameters:</b>
+</p>
+<ul>
+ <li>
+ <code>key</code>: The key that is used to access the unique shared memory identifier.
+ </li>
+ <li>
+ <code>size</code>: The shared memory region that is created will be at least this size in bytes.
+ </li>
+ <li>
+ <code>shmflg</code>: See <code>IPC_*</code> definitions in <code>sys/ipc.h</code>. Only the values <code>IPC_PRIVATE</code> or <code>IPC_CREAT</code> are supported.
+ </li>
+</ul>
+<p>
+ <b>Returned Value:</b>
+ Upon successful completion, <code>shmget()</code> will return a non-negative integer, namely a shared memory identifier; otherwise, it will return -1 and set <code>errno</code> to indicate the error.
+</p>
+<ul>
+ <li>
+ <code>EACCES</code>.
+ A shared memory identifier exists for key but operation permission as specified by the low-order nine bits of <code>shmflg</code> would not be granted.
+ </li>
+ <li>
+ <code>EEXIST</code>.
+ A shared memory identifier exists for the argument key but <code>(shmflg & IPC_CREAT) && (shmflg & IPC_EXCL)</code> are non-zero.
+ </li>
+ <li>
+ <code>EINVAL</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.
+ </li>
+ <li>
+ <code>EINVAL</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.
+ </li>
+ <li>
+ <code>ENOENT</code>.
+ A shared memory identifier does not exist for the argument key and <code>(shmflg & IPC_CREAT)</code> is 0.
+ </li>
+ <li>
+ <code>ENOMEM</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.
+ </li>
+ <li>
+ <code>ENOSPC</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.
+ </li>
+</ul>
+
+<h3><a name="shmat">2.12.2 <code>shmat</code></a></h3>
+<p>
+ <b>Function Prototype:</b>
+</p>
+<ul><pre>
+#include &lt;sys/shm.h&gt;
+void *shmat(int shmid, FAR const void *shmaddr, int shmflg);
+</pre></ul>
+<p>
+ <b>Description:</b>
+ The <code>shmat()</code> function attaches the shared memory segment associated with the shared memory identifier specified by <code>shmid</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>
+ <li>
+ <p>
+ If <code>shmaddr</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>shmaddr</code> is not a null pointer and <code>(shmflg & SHM_RND)</code> is non-zero, the segment is attached at the address given by <code>(shmaddr - ((uintptr_t)shmaddr % SHMLBA))</code>.
+ </p>
+ </li>
+ <li>
+ <p>
+ If <code>shmaddr</code> is not a null pointer and <code>(shmflg & SHM_RND)</code> is 0, the segment is attached at the address given by <code>shmaddr</code>.
+ </p>
+ </li>
+ <li>
+ <p>
+ The segment is attached for reading if <code>(shmflg & SHM_RDONLY)</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>
+<p>
+ <b>Input Parameters:</b>
+</p>
+<ul>
+ <li><code>shmid</code>: Shared memory identifier</li>
+ <li><code>smaddr</code>: Determines mapping of the shared memory region</li>
+ <li><code>shmflg</code>: See <code>SHM_*</code> definitions in <code>include/sys/shm.h</code>. Only <code>SHM_RDONLY</code> and <code>SHM_RND</code> are supported.</li>
+</ul>
+<p>
+ <b>Returned Value:</b>
+ Upon successful completion, <code>shmat()</code> will increment the value of <code>shm_nattch</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>shmat()</code> will return -1, and <code>errno</code> will be set to indicate the error.
+</p>
+<ul>
+ <li>
+ <code>EACCES</code>.
+ Operation permission is denied to the calling process
+ </li>
+ <li>
+ <code>EINVAL</code>.
+ The value of <code>shmid</code> is not a valid shared memory identifier, the <code>shmaddr</code> is not a null pointer, and the value of <code>(shmaddr -((uintptr_t)shmaddr % SHMLBA))</code> is an illegal address for attaching shared memory; or the <code>shmaddr</code> is not a null pointer, <code>(shmflg & SHM_RND)</code> is 0, and the value of <code>shmaddr</code> is an illegal address for attaching shared memory.
+ </li>
+ <li>
+ <code>EMFILE</code>.
+ The number of shared memory segments attached to the calling process would exceed the system-imposed limit.
+ </li>
+ <li>
+ <code>ENOMEM</code>.
+ The available data space is not large enough to accommodate the shared memory segment.
+ </li>
+</ul>
+
+<h3><a name="shmctl">2.12.3 <code>shmctl</code></a></h3>
+<p>
+ <b>Function Prototype:</b>
+</p>
+<ul><pre>
+#include &lt;sys/shm.h&gt;
+#include &lt;sys/ipc.h&gt;
+int shmctl(int shmid, int cmd, FAR struct shmid_ds *buf);
+</pre></ul>
+<p>
+ <b>Description:</b>
+ The <code>shmctl()</code> function provides a variety of shared memory control operations as specified by <code>cmd</code>. The following values for <code>cmd</code> are available:
+</p>
+<ul>
+ <li>
+ <p>
+ <code>IPC_STAT</code>.
+ Place the current value of each member of the <code>shmid_ds</code> data structure associated with <code>shmid</code> into the structure pointed to by <code>buf</code>.
+ </p>
+ </li>
+ <li>
+ <p>
+ <code>IPC_SET</code>.
+ Set the value of the following members of the <code>shmid_ds</code> data structure associated with <code>shmid</code> to the corresponding value found in the structure pointed to by <code>buf</code>:
+ </p>
+ <ul>
+ <code>shm_perm.uid</code><br>
+ <code>shm_perm.gid</code><br>
+ <code>shm_perm.mode</code> (Low-order nine bits).
+ </ul>
+ <p>
+ <code>IPC_SET</code> can only be executed by a process that has an effective user ID equal to either that of a process with appropriate privileges or to the value of <code>shm_perm.cuid</code> or <code>shm_perm.uid</code> in the <code>shmid_ds</code> data structure associated with <code>shmid</code>.
+ </p>
+ </li>
+ <li>
+ <p>
+ <code>IPC_RMID</code>.
+ Remove the shared memory identifier specified by <code>shmid</code> from the system and destroy the shared memory segment and <code>shmid_ds</code> data structure associated with it. <code>IPC_RMID</code> can only be executed by a process that has an effective user ID equal to either that of a process with appropriate privileges or to the value of <code>shm_perm.cuid</code> or <code>shm_perm.uid</code> in the <code>shmid_ds</code> data structure associated with <code>shmid</code>.
+ </p>
+ </li>
+</ul>
+<p>
+ <b>Input Parameters:</b>
+</p>
+<ul>
+ <li><code>shmid</code>: Shared memory identifier</li>
+ <li><code>cmd</code>: <code>shmctl()</code> command</li>
+ <li><code>buf</code>: Data associated with the <code>shmctl()</code> command</li>
+</ul>
+<p>
+ <b>Returned Value:</b>
+ Upon successful completion, <code>shmctl()</code> will return 0; otherwise, it will return -1 and set <code>errno</code> to indicate the error.
+</p>
+<ul>
+ <li>
+ <code>EACCES</code>.
+ The argument <code>cmd</code> is equal to <code>IPC_STAT</code> and the calling process does not have read permission.
+ </li>
+ <li>
+ <code>EINVAL</code>.
+ The value of <code>shmid</code> is not a valid shared memory identifier, or the value of <code>cmd </code>is not a valid command.
+ </li>
+ <li>
+ <code>EPERM</code>.
+ The argument <code>cmd</code> is equal to <code>IPC_RMID</code> or <code>IPC_SET</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>shm_perm.cuid</code> or <code>shm_perm.uid</code> in the data structure associated with <code>shmid</code>.
+ </li>
+ <li>
+ <code>EOVERFLOW</code>.
+ The <code>cmd</code> argument is <code>IPC_STAT</code> and the <code>gid</code> or <code>uid</code> value is too large to be stored in the structure pointed to by the <code>buf</code> argument.
+ </li>
+</ul>
+
+<h3><a name="shmdt">2.12.4 <code>shmdt</code></a></h3>
+<p>
+ <b>Function Prototype:</b>
+</p>
+<ul><pre>
+#include &lt;sys/shm.h&gt;
+int shmdt(FAR const void *shmaddr);
+</pre></ul>
+<p>
+ <b>Description:</b>
+ The <code>shmdt()</code> function detaches the shared memory segment located at the address specified by <code>shmaddr</code> from the address space of the calling process.
+</p>
+<p>
+ <b>Input Parameters:</b>
+</p>
+<ul>
+ <li><code>shmid</code>: Shared memory identifier</li>
+</ul>
+<p>
+ <b>Returned Value:</b>
+ Upon successful completion, <code>shmdt()</code> will decrement the value of <code>shm_nattch</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>shmdt()</code> will return -1, and <code>errno</code> will be set to indicate the error.
+</p>
+<ul>
+ <li>
+ <code>EINVAL</code>.
+ The value of <code>shmaddr</code> is not the data segment start address of a shared memory segment.
+ </li>
+</ul>
+
+<table width ="100%">
+ <tr bgcolor="#e4e4e4">
+ <td>
<a name="Data_Structures"><h1>3.0 OS Data Structures</h1></a>
</td>
</tr>
diff --git a/nuttx/configs/mikroe-stm32f4/src/up_nsh.c b/nuttx/configs/mikroe-stm32f4/src/up_nsh.c
index 8346f4908..31e9be21d 100644
--- a/nuttx/configs/mikroe-stm32f4/src/up_nsh.c
+++ b/nuttx/configs/mikroe-stm32f4/src/up_nsh.c
@@ -280,9 +280,9 @@ int nsh_archinitialize(void)
}
#else /* CONFIG_MIKROE_FLASH_PART */
- /* Configure the device with no partition support */
+ /* Configure the device with no partition support */
- smart_initialize(CONFIG_MIKROE_FLASH_MINOR, mtd, NULL);
+ smart_initialize(CONFIG_MIKROE_FLASH_MINOR, mtd, NULL);
#endif /* CONFIG_MIKROE_FLASH_PART */
}
diff --git a/nuttx/include/sys/ipc.h b/nuttx/include/sys/ipc.h
index e30e59986..a1340dc24 100644
--- a/nuttx/include/sys/ipc.h
+++ b/nuttx/include/sys/ipc.h
@@ -56,7 +56,7 @@
/* Keys: */
-#define IPC_PRIVATE 0 /* Private key */
+#define IPC_PRIVATE 0 /* Private key */
/* Control commands: */
@@ -89,11 +89,12 @@ extern "C"
struct ipc_perm
{
- uid_t uid /* Owner's user ID */
- gid_t gid /* Owner's group ID */
- uid_t cuid /* Creator's user ID */
- gid_t cgid /* Creator's group ID */
- mode_t mode /* Read/write permission */
+ uid_t uid; /* Owner's user ID */
+ gid_t gid; /* Owner's group ID */
+ uid_t cuid; /* Creator's user ID */
+ gid_t cgid; /* Creator's group ID */
+ mode_t mode; /* Read/write permission */
+};
/****************************************************************************
* Public Function Prototypes
diff --git a/nuttx/include/sys/shm.h b/nuttx/include/sys/shm.h
index 99faf2251..c59b3e143 100644
--- a/nuttx/include/sys/shm.h
+++ b/nuttx/include/sys/shm.h
@@ -51,7 +51,7 @@
****************************************************************************/
#define SHM_RDONLY 0x01 /* Attach read-only (else read-write) */
-#defube SHM_RND 0x02 /* Round attach address to SHMLBA */
+#define SHM_RND 0x02 /* Round attach address to SHMLBA */
/* Segment low boundary address multiple */
diff --git a/nuttx/mm/Kconfig b/nuttx/mm/Kconfig
index fd01ad5ce..38288a845 100644
--- a/nuttx/mm/Kconfig
+++ b/nuttx/mm/Kconfig
@@ -79,6 +79,15 @@ config HEAP2_SIZE
endif # ARCH_HAVE_HEAP2
+
+config MM_SHM
+ bool "Shared memory support"
+ default n
+ depends on BUILD_KERNEL && EXPERIMENTAL
+ ---help---
+ Build in support for the shared memory interfaces shmget(), shmat(),
+ shmctl(), and shmdt().
+
config GRAN
bool "Enable Granule Allocator"
default n
diff --git a/nuttx/mm/shm/Make.defs b/nuttx/mm/shm/Make.defs
index 66aee8502..c0fb12a81 100644
--- a/nuttx/mm/shm/Make.defs
+++ b/nuttx/mm/shm/Make.defs
@@ -36,6 +36,7 @@
# Shared memory allocator
ifeq ($(CONFIG_MM_SHM),y)
+CSRCS += shmat.c shmctl.c shmdt.c shmget.c
# Add the shared memory directory to the build
diff --git a/nuttx/mm/shm/shmat.c b/nuttx/mm/shm/shmat.c
new file mode 100755
index 000000000..4f4cf89e9
--- /dev/null
+++ b/nuttx/mm/shm/shmat.c
@@ -0,0 +1,127 @@
+/****************************************************************************
+ * mm/shm/shmat.c
+ *
+ * Copyright (C) 2014 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/shm.h>
+#include <errno.h>
+
+#ifdef CONFIG_MM_SHM
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: shmat
+ *
+ * Description:
+ * The shmat() function attaches the shared memory segment associated with
+ * the shared memory identifier specified by shmid to the address space of
+ * the calling process. The segment is attached at the address specified
+ * by one of the following criteria:
+ *
+ * - If shmaddr is a null pointer, the segment is attached at the first
+ * available address as selected by the system.
+ * - If shmaddr is not a null pointer and (shmflg & SHM_RND) is non-
+ * zero, the segment is attached at the address given by
+ * (shmaddr - ((uintptr_t)shmaddr % SHMLBA)).
+ * - If shmaddr is not a null pointer and (shmflg & SHM_RND) is 0, the
+ * segment is attached at the address given by shmaddr.
+ * - The segment is attached for reading if (shmflg & 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.
+ *
+ * Input Parameters:
+ * shmid - Shared memory identifier
+ * smaddr - Determines mapping of the shared memory region
+ * shmflg - See SHM_* definitions in include/sys/shm.h. Only SHM_RDONLY
+ * and SHM_RND are supported.
+ *
+ * Returned Value:
+ * Upon successful completion, shmat() will increment the value of
+ * shm_nattch 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, shmat() will
+ * return -1, and errno will be set to indicate the error.
+ *
+ * - EACCES
+ * Operation permission is denied to the calling process
+ * - EINVAL
+ * The value of shmid is not a valid shared memory identifier, the
+ * shmaddr is not a null pointer, and the value of
+ * (shmaddr -((uintptr_t)shmaddr % SHMLBA)) is an illegal address for
+ * attaching shared memory; or the shmaddr is not a null pointer,
+ * (shmflg & SHM_RND) is 0, and the value of shmaddr is an illegal
+ * address for attaching shared memory.
+ * - EMFILE
+ * The number of shared memory segments attached to the calling
+ * process would exceed the system-imposed limit.
+ * - ENOMEM
+ * The available data space is not large enough to accommodate the
+ * shared memory segment.
+ *
+ ****************************************************************************/
+
+FAR void *shmat(int shmid, FAR const void *shmaddr, int shmflg)
+{
+#warning Not implemented
+ set_errno(ENOSYS);
+ return (FAR void *)ERROR;
+}
+
+#endif /* CONFIG_MM_SHM */
diff --git a/nuttx/mm/shm/shmctl.c b/nuttx/mm/shm/shmctl.c
new file mode 100755
index 000000000..04f59dd64
--- /dev/null
+++ b/nuttx/mm/shm/shmctl.c
@@ -0,0 +1,135 @@
+/****************************************************************************
+ * mm/shm/shmctl.c
+ *
+ * Copyright (C) 2014 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/shm.h>
+#include <sys/ipc.h>
+#include <errno.h>
+
+#ifdef CONFIG_MM_SHM
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: shmctl
+ *
+ * Description:
+ * The shmctl() function provides a variety of shared memory control
+ * operations as specified by cmd. The following values for cmd are
+ * available:
+ *
+ * - IPC_STAT
+ * Place the current value of each member of the shmid_ds data
+ * structure associated with shmid into the structure pointed to by buf.
+ * - IPC_SET
+ * Set the value of the following members of the shmid_ds data
+ * structure associated with shmid to the corresponding value found
+ * in the structure pointed to by buf:
+ *
+ * shm_perm.uid
+ * shm_perm.gid
+ * shm_perm.mode Low-order nine bits.
+ *
+ * IPC_SET can only be executed by a process that has an effective
+ * user ID equal to either that of a process with appropriate
+ * privileges or to the value of shm_perm.cuid or shm_perm.uid in the
+ * shmid_ds data structure associated with shmid.
+ * - IPC_RMID
+ * Remove the shared memory identifier specified by shmid from the
+ * system and destroy the shared memory segment and shmid_ds data
+ * structure associated with it. IPC_RMID can only be executed by a
+ * process that has an effective user ID equal to either that of a
+ * process with appropriate privileges or to the value of
+ * shm_perm.cuid or shm_perm.uid in the shmid_ds data structure
+ * associated with shmid.
+ *
+ * Input Parameters:
+ * shmid - Shared memory identifier
+ * cmd - shmctl() command
+ * buf - Data associated with the shmctl() command
+ *
+ * Returned Value:
+ * Upon successful completion, shmctl() will return 0; otherwise, it will
+ * return -1 and set errno to indicate the error.
+ *
+ * - EACCES
+ * The argument cmd is equal to IPC_STAT and the calling process does
+ * not have read permission.
+ * - EINVAL
+ * The value of shmid is not a valid shared memory identifier, or the
+ * value of cmd is not a valid command.
+ * - EPERM
+ * The argument cmd is equal to IPC_RMID or IPC_SET 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
+ * shm_perm.cuid or shm_perm.uid in the data structure associated with
+ * shmid.
+ * - EOVERFLOW
+ * The cmd argument is IPC_STAT and the gid or uid value is too large
+ * to be stored in the structure pointed to by the buf argument.
+ *
+ ****************************************************************************/
+
+int shmctl(int shmid, int cmd, struct shmid_ds *buf)
+{
+#warning Not implemented
+ set_errno(ENOSYS);
+ return ERROR;
+}
+
+#endif /* CONFIG_MM_SHM */
diff --git a/nuttx/mm/shm/shmdt.c b/nuttx/mm/shm/shmdt.c
new file mode 100755
index 000000000..a350e5ca0
--- /dev/null
+++ b/nuttx/mm/shm/shmdt.c
@@ -0,0 +1,99 @@
+/****************************************************************************
+ * mm/shm/shmdt.c
+ *
+ * Copyright (C) 2014 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/shm.h>
+#include <errno.h>
+
+#ifdef CONFIG_MM_SHM
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: shmdt
+ *
+ * Description:
+ * The shmdt() function detaches the shared memory segment located at the
+ * address specified by shmaddr from the address space of the calling
+ * process.
+ *
+ * Input Parameters:
+ * shmid - Shared memory identifier
+ *
+ * Returned Value:
+ * Upon successful completion, shmdt() will decrement the value of
+ * shm_nattch in the data structure associated with the shared memory ID
+ * of the attached shared memory segment and return 0.
+ *
+ * Otherwise, the shared memory segment will not be detached, shmdt()
+ & will return -1, and errno will be set to indicate the error.
+ *
+ * - EINVAL
+ * The value of shmaddr is not the data segment start address of a
+ * shared memory segment.
+ *
+ ****************************************************************************/
+
+int shmdt(FAR const void *shmaddr)
+{
+#warning Not implemented
+ set_errno(ENOSYS);
+ return ERROR;
+}
+
+#endif /* CONFIG_MM_SHM */
diff --git a/nuttx/mm/shm/shmget.c b/nuttx/mm/shm/shmget.c
new file mode 100755
index 000000000..2c733d88f
--- /dev/null
+++ b/nuttx/mm/shm/shmget.c
@@ -0,0 +1,149 @@
+/****************************************************************************
+ * mm/shm/shmget.c
+ *
+ * Copyright (C) 2014 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/shm.h>
+#include <sys/ipc.h>
+#include <errno.h>
+
+#ifdef CONFIG_MM_SHM
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: shmget
+ *
+ * Description:
+ * The shmget() function will return the shared memory identifier
+ * associated with key.
+ *
+ * A shared memory identifier, associated data structure, and shared
+ * memory segment of at least size bytes is created for key if one of the
+ * following is true:
+ *
+ * - The argument key is equal to IPC_PRIVATE.
+ * - The argument key does not already have a shared memory identifier
+ * associated with it and (shmflg & IPC_CREAT) is non-zero.
+ *
+ * Upon creation, the data structure associated with the new shared memory
+ * identifier will be initialized as follows:
+ *
+ * - The values of shm_perm.cuid, shm_perm.uid, shm_perm.cgid, and
+ * shm_perm.gid are set equal to the effective user ID and effective
+ * group ID, respectively, of the calling process.
+ * - The low-order nine bits of shm_perm.mode are set equal to the low-
+ * order nine bits of shmflg.
+ * - The value of shm_segsz is set equal to the value of size.
+ * - The values of shm_lpid, shm_nattch, shm_atime, and shm_dtime are
+ * set equal to 0.
+ * - The value of shm_ctime is set equal to the current time.
+ *
+ * When the shared memory segment is created, it will be initialized with
+ * all zero values.
+ *
+ * Input Parameters:
+ * key - The key that is used to access the unique shared memory
+ * identifier.
+ * size - The shared memory region that is created will be at least
+ * this size in bytes.
+ * shmflgs - See IPC_* definitions in sys/ipc.h. Only the values
+ * IPC_PRIVATE or IPC_CREAT are supported.
+ *
+ * Returned Value:
+ * Upon successful completion, shmget() will return a non-negative
+ * integer, namely a shared memory identifier; otherwise, it will return
+ * -1 and set errno to indicate the error.
+ *
+ * - EACCES
+ * A shared memory identifier exists for key but operation permission
+ * as specified by the low-order nine bits of shmflg would not be
+ * granted.
+ * - EEXIST
+ * A shared memory identifier exists for the argument key but
+ * (shmflg & IPC_CREAT) && (shmflg & IPC_EXCL) are non-zero.
+ * - EINVAL
+ * 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.
+ * - EINVAL
+ * 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.
+ * - ENOENT
+ * A shared memory identifier does not exist for the argument key and
+ * (shmflg & IPC_CREAT) is 0.
+ * - ENOMEM
+ * 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.
+ * - ENOSPC
+ * 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.
+ *
+ ****************************************************************************/
+
+int shmget(key_t key, size_t size, int shmflg)
+{
+#warning Not implemented
+ set_errno(ENOSYS);
+ return ERROR;
+}
+
+#endif /* CONFIG_MM_SHM */
+