-/**
- * \brief Sets the number of parallel threads to use
- * for the user contexts.
- *
- * This function should be called before initializing SIMIX.
- * A value of 1 means no parallelism.
- * If the value is greater than 1, the thread support must be enabled.
- *
- * \param nb_threads the number of threads to use
- */
-XBT_INLINE void SIMIX_context_set_nthreads(int nb_threads) {
+void *SIMIX_context_stack_new(void)
+{
+ 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
+ if (posix_memalign(&stack, xbt_pagesize, size) != 0)
+ xbt_die("Failed to allocate stack.");
+#endif
+ if (mprotect(stack, smx_context_guard_size, PROT_NONE) == -1) {
+ XBT_WARN("Failed to protect stack: %s", strerror(errno));
+ /* That's not fatal, pursue anyway. */
+ }
+ stack = (char *)stack + smx_context_guard_size;
+ } else {
+ stack = xbt_malloc0(smx_context_stack_size);
+ }