Ejemplo n.º 1
0
static smx_context_t
smx_ctx_sysv_create_context_sized(size_t size, xbt_main_func_t code,
                                  int argc, char **argv,
                                  void_pfn_smxprocess_t cleanup_func,
                                  void *data)
{
  int ctx_addr[CTX_ADDR_LEN];
  smx_ctx_sysv_t context =
      (smx_ctx_sysv_t) smx_ctx_base_factory_create_context_sized(size,
                                                                 code,
                                                                 argc,
                                                                 argv,
                                                                 cleanup_func,
                                                                 data);

  /* if the user provided a function for the process then use it,
     otherwise it is the context for maestro */
  if (code) {

    getcontext(&(context->uc));

    context->uc.uc_link = NULL;

    context->uc.uc_stack.ss_sp =
        pth_skaddr_makecontext(context->stack, smx_context_stack_size);

    context->uc.uc_stack.ss_size =
        pth_sksize_makecontext(context->stack, smx_context_stack_size);

#ifdef HAVE_VALGRIND_VALGRIND_H
    context->valgrind_stack_id =
        VALGRIND_STACK_REGISTER(context->uc.uc_stack.ss_sp,
                                ((char *) context->uc.uc_stack.ss_sp) +
                                context->uc.uc_stack.ss_size);
#endif                          /* HAVE_VALGRIND_VALGRIND_H */
    memcpy(ctx_addr, &context, sizeof(smx_ctx_sysv_t));
    switch (CTX_ADDR_LEN) {
    case 1:
      makecontext(&context->uc, (void (*)())smx_ctx_sysv_wrapper,
                  1, ctx_addr[0]);
      break;
    case 2:
      makecontext(&context->uc, (void (*)())smx_ctx_sysv_wrapper,
                  2, ctx_addr[0], ctx_addr[1]);
      break;
    default:
      xbt_die("Ucontexts are not supported on this arch yet (addr len = %zu/%zu = %zu)",
              sizeof(smx_ctx_sysv_t), sizeof(int), CTX_ADDR_LEN);
    }
  } else {
    if(data != NULL && sysv_maestro_context == NULL)
      sysv_maestro_context = context;
  }

  if(MC_is_active() && code)
    MC_new_stack_area(context, ((smx_process_t)((smx_context_t)context)->data)->name, &(context->uc), size);

  return (smx_context_t) context;
}
Ejemplo n.º 2
0
static smx_context_t
smx_ctx_sysv_create_context(xbt_main_func_t code, int argc, char **argv,
                            void_pfn_smxprocess_t cleanup_func,
                            smx_process_t process)
{
  int ctx_addr[CTX_ADDR_LEN];
  smx_ctx_sysv_t context =
    (smx_ctx_sysv_t) smx_ctx_base_factory_create_context_sized(
      sizeof(s_smx_ctx_sysv_t),
      code,
      argc,
      argv,
      cleanup_func,
      process);

  /* if the user provided a function for the process then use it,
     otherwise it is the context for maestro */
  if (code) {

    context->stack = SIMIX_context_stack_new();
    getcontext(&(context->uc));

    context->uc.uc_link = NULL;

    context->uc.uc_stack.ss_sp =
        pth_skaddr_makecontext(context->stack, smx_context_usable_stack_size);

    context->uc.uc_stack.ss_size =
        pth_sksize_makecontext(context->stack, smx_context_usable_stack_size);

    memcpy(ctx_addr, &context, sizeof(smx_ctx_sysv_t));
    switch (CTX_ADDR_LEN) {
    case 1:
      makecontext(&context->uc, (void (*)())smx_ctx_sysv_wrapper,
                  1, ctx_addr[0]);
      break;
    case 2:
      makecontext(&context->uc, (void (*)())smx_ctx_sysv_wrapper,
                  2, ctx_addr[0], ctx_addr[1]);
      break;
    default:
      xbt_die("Ucontexts are not supported on this arch yet (addr len = %zu/%zu = %zu)",
              sizeof(smx_ctx_sysv_t), sizeof(int), CTX_ADDR_LEN);
    }
  } else {
    if (process != NULL && sysv_maestro_context == NULL)
      sysv_maestro_context = context;
  }

#ifdef HAVE_MC
  if (MC_is_active() && code) {
    MC_register_stack_area(context->stack, ((smx_context_t)context)->process,
                      &(context->uc), smx_context_usable_stack_size);
  }
#endif

  return (smx_context_t) context;
}