Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2003 - 2007 Pekka Riikonen
+ Copyright (C) 2003 - 2008 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
if (stack_size < SILC_STACK_DEFAULT_SIZE)
stack_size = SILC_STACK_DEFAULT_SIZE;
+ /* Align by 8 */
+ stack_size += ((-stack_size) % 8);
+
if (parent) {
/* Get stack from parent. The stack itself is allocated from the
parent (but does not consume parent's own stack). */
if (stack->stack->data[si]->bytes_left + old_size +
((unsigned char *)ptr - (unsigned char *)sptr) != bsize) {
SILC_LOG_DEBUG(("Cannot reallocate"));
- silc_set_errno_nofail(SILC_ERR_BAD_ADDRESS);
+ silc_set_errno_nofail(SILC_ERR_INVALID_ARGUMENT);
SILC_STACK_STAT(stack, num_errors, 1);
return NULL;
}
}
SILC_LOG_DEBUG(("Cannot reallocate in this block"));
- silc_set_errno_nofail(SILC_ERR_OUT_OF_MEMORY);
+ silc_set_errno_reason_nofail(SILC_ERR_TOO_LARGE_ALLOCATION,
+ "Cannot reallocate in this memory block");
SILC_STACK_STAT(stack, num_errors, 1);
return NULL;
}
return ret;
}
+/* Set global stack */
+
+void silc_stack_set_global(SilcStack stack)
+{
+ SilcTls tls = silc_thread_get_tls();
+
+ if (!tls) {
+ /* Try to initialize Tls */
+ tls = silc_thread_tls_init();
+ SILC_VERIFY(tls);
+ if (!tls)
+ return;
+ }
+
+ tls->stack = stack;
+}
+
+/* Return global stack */
+
+SilcStack silc_stack_get_global(void)
+{
+ SilcTls tls = silc_thread_get_tls();
+
+ if (!tls)
+ return NULL;
+
+ return tls->stack;
+}
+
#ifdef SILC_DIST_INPLACE
/* Statistics dumping. */