shm.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /****************************************************************************
  2. * mm/shm/shm.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __MM_SHM_SHM_H
  21. #define __MM_SHM_SHM_H
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <sys/ipc.h>
  27. #include <sys/shm.h>
  28. #include <stdint.h>
  29. #include <nuttx/addrenv.h>
  30. #include <nuttx/semaphore.h>
  31. #ifdef CONFIG_MM_SHM
  32. /****************************************************************************
  33. * Pre-processor Definitions
  34. ****************************************************************************/
  35. /* Bit definitions for the struct shm_region_s sr_flags field */
  36. #define SRFLAG_AVAILABLE 0 /* Available if no flag bits set */
  37. #define SRFLAG_INUSE (1 << 0) /* Bit 0: Region is in use */
  38. #define SRFLAG_UNLINKED (1 << 1) /* Bit 1: Region perists while references */
  39. /****************************************************************************
  40. * Public Types
  41. ****************************************************************************/
  42. /* This structure represents the state of one shared memory region
  43. * allocation. Cast compatible with struct shmid_ds.
  44. */
  45. struct shm_region_s
  46. {
  47. struct shmid_ds sr_ds; /* Region info */
  48. bool sr_flags; /* See SRFLAGS_* definitions */
  49. key_t sr_key; /* Lookup key */
  50. sem_t sr_sem; /* Manages exclusive access to this region */
  51. /* List of physical pages allocated for this memory region */
  52. uintptr_t sr_pages[CONFIG_ARCH_SHM_NPAGES];
  53. };
  54. /* This structure represents the set of all shared memory regions.
  55. * Access to the region
  56. */
  57. struct shm_info_s
  58. {
  59. sem_t si_sem; /* Manages exclusive access to the region list */
  60. struct shm_region_s si_region[CONFIG_ARCH_SHM_MAXREGIONS];
  61. };
  62. /****************************************************************************
  63. * Public Data
  64. ****************************************************************************/
  65. /* State of the all shared memory */
  66. extern struct shm_info_s g_shminfo;
  67. /****************************************************************************
  68. * Public Function Prototypes
  69. ****************************************************************************/
  70. /****************************************************************************
  71. * Name: shm_destroy
  72. *
  73. * Description:
  74. * Destroy a memory region. This function is called:
  75. *
  76. * - On certain conditions when shmget() is not successful in instantiating
  77. * the full memory region and we need to clean up and free a table entry.
  78. * - When shmctl() is called with cmd == IPC_RMID and there are no
  79. * processes attached to the memory region.
  80. * - When shmdt() is called after the last process detaches from memory
  81. * region after it was previously marked for deletion by shmctl().
  82. *
  83. * Input Parameters:
  84. * shmid - Shared memory identifier
  85. *
  86. * Returned Value:
  87. * None
  88. *
  89. * Assumption:
  90. * The caller holds either the region table semaphore or else the
  91. * semaphore on the particular entry being deleted.
  92. *
  93. ****************************************************************************/
  94. void shm_destroy(int shmid);
  95. #endif /* CONFIG_MM_SHM */
  96. #endif /* __MM_SHM_SHM_H */