+ void *stack;
+
+ if (smx_context_guard_size > 0 && !MC_is_active()) {
+ size_t size = smx_context_stack_size + smx_context_guard_size;
+#ifdef HAVE_MC
+ /* Cannot use posix_memalign when HAVE_MC. Align stack by hand, and save the
+ * pointer returned by xbt_malloc0. */
+ char *alloc = xbt_malloc0(size + xbt_pagesize);
+ stack = alloc - ((uintptr_t)alloc & (xbt_pagesize - 1)) + xbt_pagesize;
+ *((void **)stack - 1) = alloc;
+#else
+ posix_memalign(&stack, xbt_pagesize, size);
+#endif
+ if (!stack || mprotect(stack, smx_context_guard_size, PROT_NONE) == -1)
+ xbt_die("Failed to allocate stack: %s", strerror(errno));
+ stack = (char *)stack + smx_context_guard_size;
+ } else {
+ stack = xbt_malloc0(smx_context_stack_size);
+ }