fspr_shm.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef APR_SHM_H
  17. #define APR_SHM_H
  18. /**
  19. * @file fspr_shm.h
  20. * @brief APR Shared Memory Routines
  21. */
  22. #include "fspr.h"
  23. #include "fspr_pools.h"
  24. #include "fspr_errno.h"
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif /* __cplusplus */
  28. /**
  29. * @defgroup fspr_shm Shared Memory Routines
  30. * @ingroup APR
  31. * @{
  32. */
  33. /**
  34. * Private, platform-specific data struture representing a shared memory
  35. * segment.
  36. */
  37. typedef struct fspr_shm_t fspr_shm_t;
  38. /**
  39. * Create and make accessable a shared memory segment.
  40. * @param m The shared memory structure to create.
  41. * @param reqsize The desired size of the segment.
  42. * @param filename The file to use for shared memory on platforms that
  43. * require it.
  44. * @param pool the pool from which to allocate the shared memory
  45. * structure.
  46. * @remark A note about Anonymous vs. Named shared memory segments:
  47. * Not all plaforms support anonymous shared memory segments, but in
  48. * some cases it is prefered over other types of shared memory
  49. * implementations. Passing a NULL 'file' parameter to this function
  50. * will cause the subsystem to use anonymous shared memory segments.
  51. * If such a system is not available, APR_ENOTIMPL is returned.
  52. * @remark A note about allocation sizes:
  53. * On some platforms it is necessary to store some metainformation
  54. * about the segment within the actual segment. In order to supply
  55. * the caller with the requested size it may be necessary for the
  56. * implementation to request a slightly greater segment length
  57. * from the subsystem. In all cases, the fspr_shm_baseaddr_get()
  58. * function will return the first usable byte of memory.
  59. *
  60. */
  61. APR_DECLARE(fspr_status_t) fspr_shm_create(fspr_shm_t **m,
  62. fspr_size_t reqsize,
  63. const char *filename,
  64. fspr_pool_t *pool);
  65. /**
  66. * Remove shared memory segment associated with a filename.
  67. * @param filename The filename associated with shared-memory segment which
  68. * needs to be removed
  69. * @param pool The pool used for file operations
  70. * @remark This function is only supported on platforms which support
  71. * name-based shared memory segments, and will return APR_ENOTIMPL on
  72. * platforms without such support.
  73. */
  74. APR_DECLARE(fspr_status_t) fspr_shm_remove(const char *filename,
  75. fspr_pool_t *pool);
  76. /**
  77. * Destroy a shared memory segment and associated memory.
  78. * @param m The shared memory segment structure to destroy.
  79. */
  80. APR_DECLARE(fspr_status_t) fspr_shm_destroy(fspr_shm_t *m);
  81. /**
  82. * Attach to a shared memory segment that was created
  83. * by another process.
  84. * @param m The shared memory structure to create.
  85. * @param filename The file used to create the original segment.
  86. * (This MUST match the original filename.)
  87. * @param pool the pool from which to allocate the shared memory
  88. * structure for this process.
  89. */
  90. APR_DECLARE(fspr_status_t) fspr_shm_attach(fspr_shm_t **m,
  91. const char *filename,
  92. fspr_pool_t *pool);
  93. /**
  94. * Detach from a shared memory segment without destroying it.
  95. * @param m The shared memory structure representing the segment
  96. * to detach from.
  97. */
  98. APR_DECLARE(fspr_status_t) fspr_shm_detach(fspr_shm_t *m);
  99. /**
  100. * Retrieve the base address of the shared memory segment.
  101. * NOTE: This address is only usable within the callers address
  102. * space, since this API does not guarantee that other attaching
  103. * processes will maintain the same address mapping.
  104. * @param m The shared memory segment from which to retrieve
  105. * the base address.
  106. * @return address, aligned by APR_ALIGN_DEFAULT.
  107. */
  108. APR_DECLARE(void *) fspr_shm_baseaddr_get(const fspr_shm_t *m);
  109. /**
  110. * Retrieve the length of a shared memory segment in bytes.
  111. * @param m The shared memory segment from which to retrieve
  112. * the segment length.
  113. */
  114. APR_DECLARE(fspr_size_t) fspr_shm_size_get(const fspr_shm_t *m);
  115. /**
  116. * Get the pool used by this shared memory segment.
  117. */
  118. APR_POOL_DECLARE_ACCESSOR(shm);
  119. /** @} */
  120. #ifdef __cplusplus
  121. }
  122. #endif
  123. #endif /* APR_SHM_T */