mempool-system.c revision cbe4d8212ec8b9014ae7ae892e90abb98a15d797
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* @UNSAFE: whole file */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* no extra includes needed */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenstatic const char *pool_system_get_name(pool_t pool);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenstatic void *pool_system_malloc(pool_t pool, size_t size);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenstatic void *pool_system_realloc(pool_t pool, void *mem,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenstatic size_t pool_system_get_max_easy_alloc_size(pool_t pool);
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainenstatic struct pool_vfuncs static_system_pool_vfuncs = {
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainenstatic const char *pool_system_get_name(pool_t pool ATTR_UNUSED)
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen return "system";
e5fd6dfd0a492e4708d4dbb7971d7fc5d7b8fd85Timo Sirainenstatic void pool_system_ref(pool_t pool ATTR_UNUSED)
57a8c6a95e4bce3eeaba36985adb81c07dd683ffTimo Sirainenstatic void pool_system_unref(pool_t *pool ATTR_UNUSED)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void *pool_system_malloc(pool_t pool ATTR_UNUSED, size_t size)
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainen if (unlikely(size == 0 || size > SSIZE_T_MAX))
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainen i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size);
ff7056842f14fd3b30a2d327dfab165b9d15dd30Timo Sirainen i_fatal_status(FATAL_OUTOFMEM, "pool_system_malloc(%"PRIuSIZE_T
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen /* we rely on errno not changing. it shouldn't. */
ee116df08d0fdab703483e18fe8076b2ef9fd9d7Timo Sirainenvoid pool_system_free(pool_t pool ATTR_UNUSED, void *mem ATTR_UNUSED)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#if defined(HAVE_MALLOC_USABLE_SIZE) && defined(DEBUG)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen safe_memset(mem, CLEAR_CHR, malloc_usable_size(mem));
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen /* we rely on errno not changing. it shouldn't. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void *pool_system_realloc(pool_t pool ATTR_UNUSED, void *mem,
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen if (unlikely(new_size == 0 || new_size > SSIZE_T_MAX))
e03d986a74128f5ba30fcfda9f6e36578f5d8decTimo Sirainen i_panic("Trying to allocate %"PRIuSIZE_T" bytes", new_size);
2649b237dd4690575e75a30b2bf3b39ebd37b835Timo Sirainen i_assert(old_size == (size_t)-1 || mem == NULL ||
d3442384ca53d4b18a493db7dd0b000f470419cfTimo Sirainen i_fatal_status(FATAL_OUTOFMEM, "pool_system_realloc(%"PRIuSIZE_T
d3442384ca53d4b18a493db7dd0b000f470419cfTimo Sirainen /* clear new data */
d3442384ca53d4b18a493db7dd0b000f470419cfTimo Sirainen memset((char *) mem + old_size, 0, new_size - old_size);
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen i_panic("pool_system_clear() must not be called");