apr_rmm.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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_RMM_H
  17. #define APR_RMM_H
  18. /**
  19. * @file apr_rmm.h
  20. * @brief APR-UTIL Relocatable Memory Management Routines
  21. */
  22. /**
  23. * @defgroup APR_Util_RMM Relocatable Memory Management Routines
  24. * @ingroup APR_Util
  25. * @{
  26. */
  27. #include "apr.h"
  28. #include "apr_pools.h"
  29. #include "apr_errno.h"
  30. #include "apu.h"
  31. #include "apr_anylock.h"
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif /* __cplusplus */
  35. /** Structure to access Relocatable, Managed Memory */
  36. typedef struct apr_rmm_t apr_rmm_t;
  37. /** Fundamental allocation unit, within a specific apr_rmm_t */
  38. typedef apr_size_t apr_rmm_off_t;
  39. /**
  40. * Initialize a relocatable memory block to be managed by the apr_rmm API.
  41. * @param rmm The relocatable memory block
  42. * @param lock An apr_anylock_t of the appropriate type of lock, or NULL
  43. * if no locking is required.
  44. * @param membuf The block of relocatable memory to be managed
  45. * @param memsize The size of relocatable memory block to be managed
  46. * @param cont The pool to use for local storage and management
  47. * @remark Both @param membuf and @param memsize must be aligned
  48. * (for instance using APR_ALIGN_DEFAULT).
  49. */
  50. APU_DECLARE(apr_status_t) apr_rmm_init(apr_rmm_t **rmm, apr_anylock_t *lock,
  51. void *membuf, apr_size_t memsize,
  52. apr_pool_t *cont);
  53. /**
  54. * Destroy a managed memory block.
  55. * @param rmm The relocatable memory block to destroy
  56. */
  57. APU_DECLARE(apr_status_t) apr_rmm_destroy(apr_rmm_t *rmm);
  58. /**
  59. * Attach to a relocatable memory block already managed by the apr_rmm API.
  60. * @param rmm The relocatable memory block
  61. * @param lock An apr_anylock_t of the appropriate type of lock
  62. * @param membuf The block of relocatable memory already under management
  63. * @param cont The pool to use for local storage and management
  64. */
  65. APU_DECLARE(apr_status_t) apr_rmm_attach(apr_rmm_t **rmm, apr_anylock_t *lock,
  66. void *membuf, apr_pool_t *cont);
  67. /**
  68. * Detach from the managed block of memory.
  69. * @param rmm The relocatable memory block to detach from
  70. */
  71. APU_DECLARE(apr_status_t) apr_rmm_detach(apr_rmm_t *rmm);
  72. /**
  73. * Allocate memory from the block of relocatable memory.
  74. * @param rmm The relocatable memory block
  75. * @param reqsize How much memory to allocate
  76. */
  77. APU_DECLARE(apr_rmm_off_t) apr_rmm_malloc(apr_rmm_t *rmm, apr_size_t reqsize);
  78. /**
  79. * Realloc memory from the block of relocatable memory.
  80. * @param rmm The relocatable memory block
  81. * @param entity The memory allocation to realloc
  82. * @param reqsize The new size
  83. */
  84. APU_DECLARE(apr_rmm_off_t) apr_rmm_realloc(apr_rmm_t *rmm, void *entity, apr_size_t reqsize);
  85. /**
  86. * Allocate memory from the block of relocatable memory and initialize it to zero.
  87. * @param rmm The relocatable memory block
  88. * @param reqsize How much memory to allocate
  89. */
  90. APU_DECLARE(apr_rmm_off_t) apr_rmm_calloc(apr_rmm_t *rmm, apr_size_t reqsize);
  91. /**
  92. * Free allocation returned by apr_rmm_malloc or apr_rmm_calloc.
  93. * @param rmm The relocatable memory block
  94. * @param entity The memory allocation to free
  95. */
  96. APU_DECLARE(apr_status_t) apr_rmm_free(apr_rmm_t *rmm, apr_rmm_off_t entity);
  97. /**
  98. * Retrieve the physical address of a relocatable allocation of memory
  99. * @param rmm The relocatable memory block
  100. * @param entity The memory allocation to free
  101. * @return address The address, aligned with APR_ALIGN_DEFAULT.
  102. */
  103. APU_DECLARE(void *) apr_rmm_addr_get(apr_rmm_t *rmm, apr_rmm_off_t entity);
  104. /**
  105. * Compute the offset of a relocatable allocation of memory
  106. * @param rmm The relocatable memory block
  107. * @param entity The physical address to convert to an offset
  108. */
  109. APU_DECLARE(apr_rmm_off_t) apr_rmm_offset_get(apr_rmm_t *rmm, void *entity);
  110. /**
  111. * Compute the required overallocation of memory needed to fit n allocs
  112. * @param n The number of alloc/calloc regions desired
  113. */
  114. APU_DECLARE(apr_size_t) apr_rmm_overhead_get(int n);
  115. #ifdef __cplusplus
  116. }
  117. #endif
  118. /** @} */
  119. #endif /* ! APR_RMM_H */