You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mem_pool_internal.h 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*-
  2. * Copyright 2019 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * 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 RSPAMD_MEM_POOL_INTERNAL_H
  17. #define RSPAMD_MEM_POOL_INTERNAL_H
  18. /*
  19. * Internal memory pool stuff
  20. */
  21. #define align_ptr(p, a) \
  22. ((guint8 *) ((uintptr_t) (p) + ((-(intptr_t) (p)) & ((a) -1))))
  23. enum rspamd_mempool_chain_type {
  24. RSPAMD_MEMPOOL_NORMAL = 0,
  25. RSPAMD_MEMPOOL_SHARED,
  26. RSPAMD_MEMPOOL_MAX
  27. };
  28. #define ENTRY_LEN 128
  29. #define ENTRY_NELTS 64
  30. struct entry_elt {
  31. uint32_t fragmentation;
  32. uint32_t leftover;
  33. };
  34. struct rspamd_mempool_entry_point {
  35. gchar src[ENTRY_LEN];
  36. uint32_t cur_suggestion;
  37. uint32_t cur_elts;
  38. uint32_t cur_vars;
  39. struct entry_elt elts[ENTRY_NELTS];
  40. };
  41. /**
  42. * Destructors list item structure
  43. */
  44. struct _pool_destructors {
  45. rspamd_mempool_destruct_t func; /**< pointer to destructor */
  46. void *data; /**< data to free */
  47. const gchar *function; /**< function from which this destructor was added */
  48. const gchar *loc; /**< line number */
  49. struct _pool_destructors *next;
  50. };
  51. struct rspamd_mempool_variable {
  52. gpointer data;
  53. rspamd_mempool_destruct_t dtor;
  54. };
  55. KHASH_INIT(rspamd_mempool_vars_hash,
  56. uint32_t, struct rspamd_mempool_variable, 1,
  57. kh_int_hash_func, kh_int_hash_equal);
  58. struct rspamd_mempool_specific {
  59. struct _pool_chain *pools[RSPAMD_MEMPOOL_MAX];
  60. struct _pool_destructors *dtors_head, *dtors_tail;
  61. GPtrArray *trash_stack;
  62. khash_t(rspamd_mempool_vars_hash) * variables;
  63. struct rspamd_mempool_entry_point *entry;
  64. gsize elt_len; /**< size of an element */
  65. gsize used_memory;
  66. guint wasted_memory;
  67. gint flags;
  68. };
  69. /**
  70. * Pool page structure
  71. */
  72. struct _pool_chain {
  73. guint8 *begin; /**< begin of pool chain block */
  74. guint8 *pos; /**< current start of free space in block */
  75. gsize slice_size; /**< length of block */
  76. struct _pool_chain *next;
  77. };
  78. #endif