+class XBT_PRIVATE args {
+private:
+ int argc_;
+ char** argv_;
+public:
+
+ // Main constructors
+ args() : argc_(0), argv_(nullptr) {}
+ args(int argc, char** argv) : argc_(argc), argv_(argv) {}
+
+ // Free
+ void clear()
+ {
+ for (int i = 0; i < this->argc_; i++)
+ free(this->argv_[i]);
+ free(this->argv_);
+ this->argc_ = 0;
+ this->argv_ = nullptr;
+ }
+ ~args() { clear(); }
+
+ // Copy
+ args(args const& that) = delete;
+ args& operator=(args const& that) = delete;
+
+ // Move:
+ args(args&& that) : argc_(that.argc_), argv_(that.argv_)
+ {
+ that.argc_ = 0;
+ that.argv_ = nullptr;
+ }
+ args& operator=(args&& that)
+ {
+ this->argc_ = that.argc_;
+ this->argv_ = that.argv_;
+ that.argc_ = 0;
+ that.argv_ = nullptr;
+ return *this;
+ }
+
+ int argc() const { return argc_; }
+ char** argv() { return argv_; }
+ const char*const* argv() const { return argv_; }
+ char* operator[](std::size_t i) { return argv_[i]; }
+};
+
+}
+}
+
+static
+std::function<void()> wrap_main(xbt_main_func_t code, int argc, char **argv)
+{
+ if (code) {
+ auto arg = std::make_shared<simgrid::simix::args>(argc, argv);
+ return [=]() {
+ code(arg->argc(), arg->argv());
+ };
+ } else return std::function<void()>();
+}
+
+/**
+ * \brief creates a new context for a user level process
+ * \param code a main function
+ * \param argc the number of arguments of the main function
+ * \param argv the vector of arguments of the main function
+ * \param cleanup_func the function to call when the context stops
+ * \param cleanup_arg the argument of the cleanup_func function
+ */
+smx_context_t SIMIX_context_new(
+ xbt_main_func_t code, int argc, char **argv,
+ void_pfn_smxprocess_t cleanup_func,
+ smx_process_t simix_process)
+{
+ if (!simix_global)
+ xbt_die("simix is not initialized, please call MSG_init first");
+ return simix_global->context_factory->create_context(
+ wrap_main(code, argc, argv), cleanup_func, simix_process);
+}
+
+namespace simgrid {
+namespace simix {
+