diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-09-23 08:46:31 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-09-23 08:46:31 -0600 |
commit | 0ab7598b044d6520db91211abe62a75c51a9ea81 (patch) | |
tree | a3f5ab01f1b662b2be927c02fe64a139d6fcf380 /nuttx | |
parent | 0f3f2d5095043776fc32c2f802bbbf2ed3865533 (diff) | |
download | nuttx-0ab7598b044d6520db91211abe62a75c51a9ea81.tar.gz nuttx-0ab7598b044d6520db91211abe62a75c51a9ea81.tar.bz2 nuttx-0ab7598b044d6520db91211abe62a75c51a9ea81.zip |
Add shared memory initializatin logic
Diffstat (limited to 'nuttx')
-rw-r--r-- | nuttx/Documentation/NuttxUserGuide.html | 16 | ||||
-rw-r--r-- | nuttx/Kconfig | 7 | ||||
-rw-r--r-- | nuttx/arch/Kconfig | 2 | ||||
-rw-r--r-- | nuttx/include/nuttx/shm.h | 123 | ||||
-rw-r--r-- | nuttx/include/sys/ipc.h | 2 | ||||
-rw-r--r-- | nuttx/include/sys/shm.h | 1 | ||||
-rw-r--r-- | nuttx/mm/mm_gran/mm_gran.h | 8 | ||||
-rw-r--r-- | nuttx/mm/shm/Make.defs | 1 | ||||
-rw-r--r-- | nuttx/mm/shm/shm.h | 106 | ||||
-rwxr-xr-x | nuttx/mm/shm/shm_initialize.c | 111 | ||||
-rwxr-xr-x | nuttx/mm/shm/shmget.c | 10 | ||||
-rw-r--r-- | nuttx/sched/init/os_start.c | 7 |
12 files changed, 381 insertions, 13 deletions
diff --git a/nuttx/Documentation/NuttxUserGuide.html b/nuttx/Documentation/NuttxUserGuide.html index 480c7daf7..ee5d45ae1 100644 --- a/nuttx/Documentation/NuttxUserGuide.html +++ b/nuttx/Documentation/NuttxUserGuide.html @@ -9087,11 +9087,6 @@ int shmget(key_t key, size_t size, int shmflg); <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> @@ -9162,6 +9157,17 @@ int shmget(key_t key, size_t size, int shmflg); 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> +<p> + <b>POSIX Deviations</b> +<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> should be set equal to the effective user ID and effective group ID, respectively, of the calling process. + The NuttX <code>ipc_perm</code> structure, however, does not support these fields because user and group IDs are not yet supported by NuttX. + </p> + </li> +</ul> <h3><a name="shmat">2.12.2 <code>shmat</code></a></h3> <p> diff --git a/nuttx/Kconfig b/nuttx/Kconfig index a2b700409..c285096bd 100644 --- a/nuttx/Kconfig +++ b/nuttx/Kconfig @@ -458,6 +458,13 @@ config DEBUG_MM ---help--- Enable memory management debug SYSLOG output (disabled by default) +config DEBUG_SHM + bool "Shared Memory Debug Output" + default n + depends on MM_SHM + ---help--- + Enable shared memory management debug SYSLOG output (disabled by default) + config DEBUG_NET bool "Network Debug Output" default n diff --git a/nuttx/arch/Kconfig b/nuttx/arch/Kconfig index c586595a9..2c024d0b8 100644 --- a/nuttx/arch/Kconfig +++ b/nuttx/arch/Kconfig @@ -200,7 +200,7 @@ config ARCH_HEAP_VBASE The virtual address of the beginning of the heap region. config ARCH_SHM_VBASE - hex "Virtual heap base" + hex "Shared memory base" depends on MM_SHM ---help--- The virtual address of the beginning of the shared memory region. diff --git a/nuttx/include/nuttx/shm.h b/nuttx/include/nuttx/shm.h new file mode 100644 index 000000000..baff3df9e --- /dev/null +++ b/nuttx/include/nuttx/shm.h @@ -0,0 +1,123 @@ +/**************************************************************************** + * include/nuttx/shm.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_SHM_H +#define __INCLUDE_NUTTX_SHM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <debug.h> + +#ifdef CONFIG_MM_SHM + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ + +#ifndef CONFIG_ARCH_ADDRENV +# error CONFIG_ARCH_ADDRENV must be selected with CONFIG_MM_SHM +#endif + +#ifndef CONFIG_BUILD_KERNEL +# error CONFIG_BUILD_KERNEL must be selected with CONFIG_MM_SHM +#endif + +#ifndef CONFIG_GRAN +# error CONFIG_GRAN must be selected with CONFIG_MM_SHM +#endif + +#ifdef CONFIG_GRAN_SINGLE +# error CONFIG_GRAN_SINGLE must NOT be selected with CONFIG_MM_SHM +#endif + +#ifndef CONFIG_MM_PGALLOC +# error CONFIG_MM_PGALLOC must be selected with CONFIG_MM_SHM +#endif + +/* Debug */ + +#ifdef CONFIG_CPP_HAVE_VARARGS +# ifdef CONFIG_DEBUG_SHM +# define shmdbg(format, ...) dbg(format, ##__VA_ARGS__) +# define shmvdbg(format, ...) vdbg(format, ##__VA_ARGS__) +# else +# define shmdbg(format, ...) mdbg(format, ##__VA_ARGS__) +# define shmvdbg(format, ...) mvdbg(format, ##__VA_ARGS__) +# endif +#else +# ifdef CONFIG_DEBUG_SHM +# define shmdbg dbg +# define shmvdbg vdbg +# else +# define shmdbg (void) +# define shmvdbg (void) +# endif +#endif + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: shm_initialize + * + * Description: + * Perform one time, start-up initialization of the shared memor logic. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +void shm_initialize(void); + +#endif /* CONFIG_MM_SHM */ +#endif /* __INCLUDE_NUTTX_SHM_H */ diff --git a/nuttx/include/sys/ipc.h b/nuttx/include/sys/ipc.h index a1340dc24..42cf5b1ef 100644 --- a/nuttx/include/sys/ipc.h +++ b/nuttx/include/sys/ipc.h @@ -89,10 +89,12 @@ extern "C" struct ipc_perm { +#if 0 /* User and group IDs not yet supported by NuttX */ 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 */ +#endif mode_t mode; /* Read/write permission */ }; diff --git a/nuttx/include/sys/shm.h b/nuttx/include/sys/shm.h index c59b3e143..73ecbca98 100644 --- a/nuttx/include/sys/shm.h +++ b/nuttx/include/sys/shm.h @@ -49,6 +49,7 @@ /**************************************************************************** * Pre-Processor Definitions ****************************************************************************/ +/* Definitions required by POSIX */ #define SHM_RDONLY 0x01 /* Attach read-only (else read-write) */ #define SHM_RND 0x02 /* Round attach address to SHMLBA */ diff --git a/nuttx/mm/mm_gran/mm_gran.h b/nuttx/mm/mm_gran/mm_gran.h index 2156f96ef..cb9316ae4 100644 --- a/nuttx/mm/mm_gran/mm_gran.h +++ b/nuttx/mm/mm_gran/mm_gran.h @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __MM_MM_GRAN_MM_GRAHN_H -#define __MM_MM_GRAN_MM_GRAHN_H +#ifndef __MM_MM_GRAN_MM_GRAN_H +#define __MM_MM_GRAN_MM_GRAN_H /**************************************************************************** * Included Files @@ -83,7 +83,7 @@ * Public Types ****************************************************************************/ -/* This structure represents the state of on granule allocation */ +/* This structure represents the state of one granule allocation */ struct gran_s { @@ -148,4 +148,4 @@ void gran_leave_critical(FAR struct gran_s *priv); void gran_mark_allocated(FAR struct gran_s *priv, uintptr_t alloc, unsigned int ngranules); -#endif /* __MM_MM_GRAN_MM_GRAHN_H */ +#endif /* __MM_MM_GRAN_MM_GRAN_H */ diff --git a/nuttx/mm/shm/Make.defs b/nuttx/mm/shm/Make.defs index c0fb12a81..f02e5864f 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 += shm_initialize.c CSRCS += shmat.c shmctl.c shmdt.c shmget.c # Add the shared memory directory to the build diff --git a/nuttx/mm/shm/shm.h b/nuttx/mm/shm/shm.h new file mode 100644 index 000000000..0a05dce29 --- /dev/null +++ b/nuttx/mm/shm/shm.h @@ -0,0 +1,106 @@ +/**************************************************************************** + * mm/shm/shm.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __MM_SHM_SHM_H +#define __MM_SHM_SHM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <sys/ipc.h> +#include <sys/shm.h> +#include <stdint.h> +#include <semaphore.h> + +#include <nuttx/addrenv.h> + +#ifdef CONFIG_MM_SHM + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* IPC_PRIVATE is the only value for the the SHM key that is guaranteed to + * be invalid. + */ + +#define SHM_INVALID_KEY IPC_PRIVATE + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* This structure represents the state of one shared memory region + * allocation. Cast compatible with struct shmid_ds. + */ + +struct shm_region_s +{ + struct shmid_ds sr_ds; /* Region info */ + key_t sr_key; /* Lookup key. IPC_PRIVATE means unused */ + sem_t sr_sem; /* Manages exclusive access to this region */ + + /* List of physical pages allocated for this memory region */ + + uintptr_t sr_pages[CONFIG_ARCH_SHM_NPAGES]; +}; + +/* This structure represents the set of all shared memory regions. + * Access to the region + */ + +struct shm_info_s +{ + sem_t si_sem; /* Manages exclusive access to the region list */ + struct shm_region_s si_region[CONFIG_ARCH_SHM_MAXREGIONS]; +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* State of the all shared memory */ + +extern struct shm_info_s g_shminfo; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#endif /* CONFIG_MM_SHM */ +#endif /* __MM_SHM_SHM_H */ diff --git a/nuttx/mm/shm/shm_initialize.c b/nuttx/mm/shm/shm_initialize.c new file mode 100755 index 000000000..1da2d4e2e --- /dev/null +++ b/nuttx/mm/shm/shm_initialize.c @@ -0,0 +1,111 @@ +/**************************************************************************** + * mm/shm/shm_initialize.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 "shm/shm.h" + +#ifdef CONFIG_MM_SHM + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* State of the all shared memory */ + +struct shm_info_s g_shminfo; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: shm_initialize + * + * Description: + * Perform one time, start-up initialization of the shared memor logic. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +void shm_initialize(void) +{ +#if SHM_INVALID_KEY != 0 + FAR struct shm_region_s *region; + int i; +#endif + + /* Initialize the shared memory region list */ + + sem_init(&g_shminfo.si_sem, 0, 1); + +#if SHM_INVALID_KEY != 0 + /* Initialize each shared memory region */ + + for (i = 0; i < CONFIG_ARCH_SHM_NPAGES; i++) + { + region = &g_shminfo.si_region[i]; + + /* Markk the key invalid for each region. The invalid key is an + * indication that the region is not in use. + */ + + region->sr_key = SHM_INVALID_KEY; + } +#endif +} + +#endif /* CONFIG_MM_SHM */ diff --git a/nuttx/mm/shm/shmget.c b/nuttx/mm/shm/shmget.c index f5e718b4a..3df1dd763 100755 --- a/nuttx/mm/shm/shmget.c +++ b/nuttx/mm/shm/shmget.c @@ -83,9 +83,6 @@ * 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. @@ -136,6 +133,13 @@ * limit on the maximum number of allowed shared memory identifiers * system-wide would be exceeded. * + * POSIX Deviations: + * - The values of shm_perm.cuid, shm_perm.uid, shm_perm.cgid, and + * shm_perm.gid should be set equal to the effective user ID and + * effective group ID, respectively, of the calling process. + * The NuttX ipc_perm structure, however, does not support these + * fields because user and group IDs are not yet supported by NuttX. + * ****************************************************************************/ int shmget(key_t key, size_t size, int shmflg) diff --git a/nuttx/sched/init/os_start.c b/nuttx/sched/init/os_start.c index 62f150c92..91902b82e 100644 --- a/nuttx/sched/init/os_start.c +++ b/nuttx/sched/init/os_start.c @@ -49,6 +49,7 @@ #include <nuttx/net/net.h> #include <nuttx/lib.h> #include <nuttx/mm.h> +#include <nuttx/shm.h> #include <nuttx/kmalloc.h> #include <nuttx/init.h> @@ -485,6 +486,12 @@ void os_start(void) up_initialize(); +#ifdef CONFIG_MM_SHM + /* Initialize shared memory support */ + + shm_initialize(); +#endif + /* Initialize the C libraries. This is done last because the libraries * may depend on the above. */ |