Add README files and configuration support for the shared memory logic
This commit is contained in:
parent
826f703669
commit
242d5f2068
@ -8,7 +8,7 @@
|
||||
<tr align="center" bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<h1><big><font color="#3c34ec"><i>NuttX README Files</i></font></big></h1>
|
||||
<p>Last Updated: September 9, 2014</p>
|
||||
<p>Last Updated: September 23, 2014</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@ -281,6 +281,8 @@
|
||||
| |- libxx/
|
||||
| | `- <a href="http://sourceforge.net/p/nuttx/git/ci/master/tree/nuttx/libxx/README.txt"><b><i>README.txt</i></b></a>
|
||||
| |- mm/
|
||||
| | |- shm/
|
||||
| | | `- <a href="http://sourceforge.net/p/nuttx/git/ci/master/tree/nuttx/mm/shm/README.txt"><b><i>README.txt</i></b></a>
|
||||
| | `- <a href="http://sourceforge.net/p/nuttx/git/ci/master/tree/nuttx/mm/README.txt"><b><i>README.txt</i></b></a>
|
||||
| |- net/
|
||||
| | `- <a href="http://sourceforge.net/p/nuttx/git/ci/master/tree/nuttx/net/README.txt"><b><i>README.txt</i></b></a>
|
||||
|
@ -1149,6 +1149,8 @@ nuttx
|
||||
|- libxx/
|
||||
| `- README.txt
|
||||
|- mm/
|
||||
| |- shm/
|
||||
| | `- README.txt
|
||||
| `- README.txt
|
||||
|- net/
|
||||
| `- README.txt
|
||||
|
36
arch/Kconfig
36
arch/Kconfig
@ -199,6 +199,12 @@ config ARCH_HEAP_VBASE
|
||||
---help---
|
||||
The virtual address of the beginning of the heap region.
|
||||
|
||||
config ARCH_SHM_VBASE
|
||||
hex "Virtual heap base"
|
||||
depends on MM_SHM
|
||||
---help---
|
||||
The virtual address of the beginning of the shared memory region.
|
||||
|
||||
config ARCH_TEXT_NPAGES
|
||||
int "Max .text pages"
|
||||
default 1
|
||||
@ -223,6 +229,36 @@ config ARCH_HEAP_NPAGES
|
||||
This, along with knowledge of the page size, determines the size of
|
||||
the heap virtual address space. Default is 1.
|
||||
|
||||
if MM_SHM
|
||||
|
||||
config ARCH_SHM_MAXREGIONS
|
||||
int "Max shared memory regions"
|
||||
default 1
|
||||
---help---
|
||||
The maximum number of regions that can allocated for the shared
|
||||
memory space. This hard-coded value permits static allocation of
|
||||
the shared memory data structures and serves no other purpose.
|
||||
Default is 1.
|
||||
|
||||
The size of the virtual shared memory address space is then
|
||||
determined by the product of the maximum number of regions, the
|
||||
maximum number of pages per region, and the configured size of
|
||||
each page.
|
||||
|
||||
config ARCH_SHM_NPAGES
|
||||
int "Max shared memory pages"
|
||||
default 1
|
||||
---help---
|
||||
The maximum number of pages that can allocated per region for the shared memory
|
||||
region. Default is 1.
|
||||
|
||||
The size of the virtual shared memory address space is then
|
||||
determined by the product of the maximum number of regions, the
|
||||
maximum number of pages per region, and the configured size of
|
||||
each page.
|
||||
|
||||
endif # MM_SHM
|
||||
|
||||
config ARCH_STACK_DYNAMIC
|
||||
bool "Dynamic user stack"
|
||||
default n
|
||||
|
@ -168,11 +168,42 @@
|
||||
|
||||
/* A single page scratch region used for temporary mappings */
|
||||
|
||||
# define ARCH_SCRATCH_VBASE ARCH_STACK_VEND
|
||||
# define __ARCH_SHM_VBASE ARCH_STACK_VEND
|
||||
#else
|
||||
/* A single page scratch region used for temporary mappings */
|
||||
|
||||
# define ARCH_SCRATCH_VBASE ARCH_HEAP_VEND
|
||||
# define __ARCH_SHM_VBASE ARCH_HEAP_VEND
|
||||
#endif
|
||||
|
||||
/* Shared memory regions */
|
||||
|
||||
#ifdef CONFIG_MM_SHM
|
||||
# ifndef CONFIG_ARCH_SHM_VBASE
|
||||
# error CONFIG_ARCH_SHM_VBASE not defined
|
||||
# define CONFIG_ARCH_SHM_VBASE __ARCH_SHM_VBASE
|
||||
# endif
|
||||
|
||||
# if (CONFIG_ARCH_SHM_VBASE & CONFIG_MM_MASK) != 0
|
||||
# error CONFIG_ARCH_SHM_VBASE not aligned to page boundary
|
||||
# endif
|
||||
|
||||
# ifndef CONFIG_ARCH_SHM_MAXREGIONS
|
||||
# warning CONFIG_ARCH_SHM_MAXREGIONS not defined
|
||||
# define CONFIG_ARCH_SHM_MAXREGIONS 1
|
||||
# endif
|
||||
|
||||
# ifndef CONFIG_ARCH_SHM_NPAGES
|
||||
# warning CONFIG_ARCH_SHM_NPAGES not defined
|
||||
# define CONFIG_ARCH_SHM_NPAGES 1
|
||||
# endif
|
||||
|
||||
# define ARCH_SHM_REGIONSIZE (CONFIG_ARCH_SHM_NPAGES * CONFIG_MM_PGSIZE)
|
||||
# define ARCH_SHM_SIZE (CONFIG_ARCH_SHM_MAXREGIONS * ARCH_SHM_REGIONSIZE)
|
||||
# define ARCH_SHM_VEND (CONFIG_ARCH_SHM_VBASE + ARCH_SHM_SIZE)
|
||||
|
||||
# define ARCH_SCRATCH_VBASE ARCH_SHM_VEND
|
||||
#else
|
||||
# define ARCH_SCRATCH_VBASE __ARCH_SHM_VBASE
|
||||
#endif
|
||||
|
||||
/* There is no need to use the scratch memory region if the page pool memory
|
||||
|
19
mm/Kconfig
19
mm/Kconfig
@ -79,15 +79,6 @@ 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
|
||||
@ -158,3 +149,13 @@ config DEBUG_PGALLOC
|
||||
allocation logic.
|
||||
|
||||
endif # MM_PGALLOC
|
||||
|
||||
config MM_SHM
|
||||
bool "Shared memory support"
|
||||
default n
|
||||
depends on MM_PGALLOC && BUILD_KERNEL && EXPERIMENTAL
|
||||
---help---
|
||||
Build in support for the shared memory interfaces shmget(), shmat(),
|
||||
shmctl(), and shmdt().
|
||||
|
||||
|
||||
|
@ -5,6 +5,8 @@ This directory contains the NuttX memory management logic. This include:
|
||||
|
||||
1) Standard Memory Management Functions:
|
||||
|
||||
Standard Functions:
|
||||
|
||||
The standard memory management functions as prototyped in stdlib.h as
|
||||
specified in the Base definitions volume of IEEE Std 1003.1-2001. This
|
||||
include the files:
|
||||
@ -61,6 +63,17 @@ This directory contains the NuttX memory management logic. This include:
|
||||
In fact, the standard malloc(), realloc(), free() use this same mechanism,
|
||||
but with a global heap structure called g_mmheap.
|
||||
|
||||
User/Kernel Heaps
|
||||
|
||||
This multiple heap capability is exploited in some of the more complex NuttX
|
||||
build configurations to provide separate kernel-mode and user-mode heaps.
|
||||
|
||||
Sub-Directories:
|
||||
|
||||
mm/mm_heap - Holds the common base logic for all heap allocators
|
||||
mm/umm_heap - Holds the user-mode memory allocation interfaces
|
||||
mm/kmm_heap - Holds the kernel-mode memory allocation interfaces
|
||||
|
||||
2) Granule Allocator.
|
||||
|
||||
A non-standard granule allocator is also available in this directory The
|
||||
@ -110,3 +123,33 @@ This directory contains the NuttX memory management logic. This include:
|
||||
|
||||
The actual memory allocates will be 64 byte (wasting 17 bytes) and
|
||||
will be aligned at least to (1 << log2align).
|
||||
|
||||
Sub-Directories:
|
||||
|
||||
mm/mm_gran - Holds the granule allocation logic
|
||||
|
||||
3) Page Allocator
|
||||
|
||||
The page allocator is an application of the granule allocator. It is a
|
||||
special purpose memory allocator intended to allocate physical memory
|
||||
pages for use with systems that have a memory management unit (MMU).
|
||||
|
||||
Sub-Directories:
|
||||
|
||||
mm/mm_gran - The page allocator cohabits the same directory as the
|
||||
granule allocator.
|
||||
|
||||
4) Shared Memory Management
|
||||
|
||||
When NuttX is build in kernel mode with a separate, privileged, kernel-
|
||||
mode address space and multiple, unprivileged, user-mode address spaces,
|
||||
then shared memory regions must also be managed. Shared memory regions
|
||||
are user-accessible memory regions that can be attached into the user
|
||||
process address space for sharing between user process.
|
||||
|
||||
Sub-Directories:
|
||||
|
||||
mm/shm - The shared memory logic
|
||||
|
||||
The shared memory management logic has its own README file that can be
|
||||
found at nuttx/mm/shm/README.txt.
|
||||
|
117
mm/shm/README.txt
Executable file
117
mm/shm/README.txt
Executable file
@ -0,0 +1,117 @@
|
||||
Shared Memory Support
|
||||
=====================
|
||||
|
||||
Prerequisites
|
||||
-------------
|
||||
These features must be enabled before shared memory support can be
|
||||
provided:
|
||||
|
||||
CONFIG_ARCH_ADDRENV=y - Support for per-task address environment using a
|
||||
MMU.
|
||||
CONFIG_BUILD_KERNEL=y - Support for protected kernel-/user-space memory
|
||||
regions must be provided by the MMU.
|
||||
CONFIG_GRAN=y - The granule allocation is the allocation underlying all
|
||||
paged allocations.
|
||||
CONFIG_GRAN_SINGLE=n - Multiple granule allocators are needed: One for
|
||||
the physical page allocation and one virtual page allocator for each
|
||||
process.
|
||||
CONFIG_MM_PGALLOC=y - Enables the physical page allocator
|
||||
CONFIG_MM_PGSIZE - Determines the size of one page that can be mapped by
|
||||
the MMU.
|
||||
|
||||
And then finally:
|
||||
|
||||
CONFIG_MM_SHM=y - Enables shared memory support
|
||||
CONFIG_ARCH_SHM_VBASE - The virtual address of the beginning of the
|
||||
shared memory region.
|
||||
CONFIG_ARCH_SHM_MAXREGIONS - The maximum number of regions that can
|
||||
allocated for the shared memory space. This hard-coded value permits
|
||||
static allocation of the shared memory data structures and serves no
|
||||
other purpose. Default is 1.
|
||||
CONFIG_ARCH_SHM_NPAGES - The maximum number of pages that can allocated
|
||||
for the shared memory region. Default is 1.
|
||||
|
||||
The size of the virtual shared memory address space is then determined by
|
||||
the product of the maximum number of regions, the maximum number of pages
|
||||
per region, and the configured size of each page.
|
||||
|
||||
Concepts
|
||||
--------
|
||||
Each process has a task group structure, struct task_group_s, that holds
|
||||
information common to all threads in the group. If CONFIG_MM_SHM=y, then
|
||||
this includes data structures for the per-process shared memory virtual
|
||||
page allocator.
|
||||
|
||||
A memory region is accessed using:
|
||||
|
||||
int shmget(key_t key, size_t size, int shmflg);
|
||||
|
||||
by a lookup using internal shared memory data sets with key as the lookup
|
||||
match value. On success, shmget returns the shared memory identifier for
|
||||
the match -- in this implementation that identifier is simply the table
|
||||
index of the match.
|
||||
|
||||
If the memory region does not exist, it may also be created by shmget (if
|
||||
the IPC_CREAT bit is set in the shmflag). When a shared memory region is
|
||||
created, the following things happen:
|
||||
|
||||
- A new entry is set aside in the internal data set. The key value is
|
||||
assigned to the entry and the table index is the new shared memory
|
||||
identifier.
|
||||
|
||||
- The requested size is rounded up to rounded up to full pages, each of
|
||||
size CONFIG_MM_PGSIZE.
|
||||
|
||||
- A set of physical pages are allocated and the physical address of
|
||||
these pages is retained in the internel data set.
|
||||
|
||||
Now the key maps to and shared memory identifier (the table index) and
|
||||
the table index provides access to the list of physical pages making up
|
||||
the shared memory region.
|
||||
|
||||
NOTE: An improved implementation my perform a "lazy" back up of the
|
||||
physical memory, i.e., do not allocate the physical memory until the
|
||||
memory is required, for example, when a page fault occurs when a
|
||||
application tries to allocate the memory.
|
||||
|
||||
A shared memory region is destroyed via:
|
||||
|
||||
int shmctl(int shmid, int cmd, struct shmid_ds *buf);
|
||||
|
||||
In order for a process to make use of the memory region, it must be
|
||||
"attached" the the process using:
|
||||
|
||||
FAR void *shmat(int shmid, FAR const void *shmaddr, int shmflg);
|
||||
|
||||
shmat() returns the virtual address where the shared memory can be found
|
||||
in the user process. Attaching the shared memory region involves the
|
||||
following steps:
|
||||
|
||||
- Use the shmid as a table index to look up the mapping in the shared
|
||||
memory internal data structures.
|
||||
|
||||
- Allocate a virtual address spaces of the same size as the physical
|
||||
address space using the per-process virtual shared memory virtual
|
||||
page allocator that can be found in the calling process' task group
|
||||
structure.
|
||||
|
||||
- Use platform specific interfaces to mapy the physical memory to the
|
||||
selected virtual address space, and
|
||||
|
||||
- Return the allocated virtual base address to the caller.
|
||||
|
||||
The memory region can be detached from the user process using:
|
||||
|
||||
int shmdt(FAR const void *shmaddr);
|
||||
|
||||
Relevant header files:
|
||||
---------------------
|
||||
|
||||
include/sys/shm.h - Shared memory interface declarations
|
||||
include/sys/ipc.h - Provides additional definitions used by the shared
|
||||
memory interfaces
|
||||
include/nuttx/addrenv.h - Defines the virtual address space of the
|
||||
process.
|
||||
include/nuttx/pgalloc.h - Page allocator interfaces
|
||||
mm/shm/shm.h - Internal shared memory definitions. This includes the
|
||||
definitions of the internal shared memory data structures.
|
254
mm/shm/shmat.c
254
mm/shm/shmat.c
@ -1,127 +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 */
|
||||
/****************************************************************************
|
||||
* 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 */
|
||||
|
271
mm/shm/shmctl.c
271
mm/shm/shmctl.c
@ -1,135 +1,136 @@
|
||||
/****************************************************************************
|
||||
* 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 */
|
||||
/****************************************************************************
|
||||
* 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 */
|
||||
|
298
mm/shm/shmget.c
298
mm/shm/shmget.c
@ -1,149 +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 */
|
||||
|
||||
/****************************************************************************
|
||||
* 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 */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user