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/mm | |
parent | 0f3f2d5095043776fc32c2f802bbbf2ed3865533 (diff) | |
download | px4-nuttx-0ab7598b044d6520db91211abe62a75c51a9ea81.tar.gz px4-nuttx-0ab7598b044d6520db91211abe62a75c51a9ea81.tar.bz2 px4-nuttx-0ab7598b044d6520db91211abe62a75c51a9ea81.zip |
Add shared memory initializatin logic
Diffstat (limited to 'nuttx/mm')
-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 |
5 files changed, 229 insertions, 7 deletions
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) |