#define MPX_RT_MODE "CHKP_RT_MODE"
#define MPX_RT_MODE_DEFAULT MPX_RT_COUNT
#define MPX_RT_MODE_DEFAULT_STR "count"
+#define MPX_RT_STOP_HANDLER "CHKP_RT_STOP_HANDLER"
+#define MPX_RT_STOP_HANDLER_DEFAULT MPX_RT_STOP_HANDLER_ABORT
+#define MPX_RT_STOP_HANDLER_DEFAULT_STR "abort"
#define MPX_RT_HELP "CHKP_RT_HELP"
#define MPX_RT_ADDPID "CHKP_RT_ADDPID"
#define MPX_RT_BNDPRESERVE "CHKP_RT_BNDPRESERVE"
static int summary;
static int add_pid;
static mpx_rt_mode_t mode;
+static mpx_rt_stop_mode_handler_t stop_handler;
static env_var_list_t env_var_list;
static verbose_type verbose_val;
static FILE *out;
}
}
+static mpx_rt_stop_mode_handler_t
+set_mpx_rt_stop_handler (const char *env)
+{
+ if (env == 0)
+ return MPX_RT_STOP_HANDLER_DEFAULT;
+ else if (strcmp (env, "abort") == 0)
+ return MPX_RT_STOP_HANDLER_ABORT;
+ else if (strcmp (env, "exit") == 0)
+ return MPX_RT_STOP_HANDLER_EXIT;
+ {
+ __mpxrt_print (VERB_ERROR, "Illegal value '%s' for %s. Legal values are"
+ "[abort | exit]\nUsing default value %s\n",
+ env, MPX_RT_STOP_HANDLER, MPX_RT_STOP_HANDLER_DEFAULT);
+ return MPX_RT_STOP_HANDLER_DEFAULT;
+ }
+}
+
static void
print_help (void)
{
fprintf (out, "%s \t\t set MPX runtime behavior on #BR exception."
" [stop | count]\n"
"\t\t\t [default: %s]\n", MPX_RT_MODE, MPX_RT_MODE_DEFAULT_STR);
+ fprintf (out, "%s \t set the handler function MPX runtime will call\n"
+ "\t\t\t on #BR exception when %s is set to \'stop\'."
+ " [abort | exit]\n"
+ "\t\t\t [default: %s]\n", MPX_RT_STOP_HANDLER, MPX_RT_MODE,
+ MPX_RT_STOP_HANDLER_DEFAULT_STR);
fprintf (out, "%s \t\t generate out,err file for each process.\n"
"\t\t\t generated file will be MPX_RT_{OUT,ERR}_FILE.pid\n"
"\t\t\t [default: no]\n", MPX_RT_ADDPID);
env_var_list_add (MPX_RT_MODE, env);
mode = set_mpx_rt_mode (env);
+ env = secure_getenv (MPX_RT_STOP_HANDLER);
+ env_var_list_add (MPX_RT_STOP_HANDLER, env);
+ stop_handler = set_mpx_rt_stop_handler (env);
+
env = secure_getenv (MPX_RT_BNDPRESERVE);
env_var_list_add (MPX_RT_BNDPRESERVE, env);
validate_bndpreserve (env, bndpreserve);
return mode;
}
+mpx_rt_mode_t
+__mpxrt_stop_handler (void)
+{
+ return stop_handler;
+}
+
+void __attribute__ ((noreturn))
+__mpxrt_stop (void)
+{
+ if (__mpxrt_stop_handler () == MPX_RT_STOP_HANDLER_ABORT)
+ abort ();
+ else if (__mpxrt_stop_handler () == MPX_RT_STOP_HANDLER_EXIT)
+ exit (255);
+ __builtin_unreachable ();
+}
+
void
__mpxrt_print_summary (uint64_t num_brs, uint64_t l1_size)
{
uctxt->uc_mcontext.gregs[REG_IP_IDX] =
(greg_t)get_next_inst_ip ((uint8_t *)ip);
if (__mpxrt_mode () == MPX_RT_STOP)
- exit (255);
+ __mpxrt_stop ();
return;
default:
__mpxrt_write (VERB_ERROR, ", ip = 0x");
__mpxrt_write_uint (VERB_ERROR, ip, 16);
__mpxrt_write (VERB_ERROR, "\n");
- exit (255);
+ __mpxrt_stop ();
}
else
{
__mpxrt_write (VERB_ERROR, "! at 0x");
__mpxrt_write_uint (VERB_ERROR, ip, 16);
__mpxrt_write (VERB_ERROR, "\n");
- exit (255);
+ __mpxrt_stop ();
}
}