extern "C" FUNC_RET_TYPE FUNC_NAME(ARGS_WITH_NAME){ typedef FUNC_RET_TYPE (*orig_func_type)(ARGS_WITHOUT_NAME); static orig_func_type orig_func; void * handle; FUNC_RET_TYPE ret; void *eip = 0; if (!orig_func) { if(!(handle=dlopen("LIB_PATH", RTLD_LAZY))) { perror("dlopen"); puts("here dlopen"); abort(); } orig_func = (orig_func_type) dlsym(handle, "FUNC_NAME"); if(dlerror()) { perror("dlsym"); puts("here dlsym"); abort(); } dlclose(handle); } #ifdef __USE_TERN_RUNTIME if (Space::isApp()) { if (options::DMT) { //fprintf(stderr, "Parrot hook: pid %d self %u calls %s\n", getpid(), (unsigned)pthread_self(), "FUNC_NAME"); #ifdef __NEED_INPUT_INSID if (options::dync_geteip) { Space::enterSys(); eip = get_eip(); Space::exitSys(); } record_rdtsc_op("FUNC_NAME", "START", 0, eip); ret = tern_FUNC_NAME((unsigned)(uint64_t) eip, ARGS_ONLY_NAME); #else ret = tern_FUNC_NAME(ARGS_ONLY_NAME); #endif record_rdtsc_op("FUNC_NAME", "END", 0, eip); return ret; } else {// For performance debugging, by doing this, we are still able to get the sync wait time for non-det mode. if (options::dync_geteip) { Space::enterSys(); eip = get_eip(); Space::exitSys(); } record_rdtsc_op("FUNC_NAME", "START", 0, eip); Space::enterSys(); ret = orig_func(ARGS_ONLY_NAME); Space::exitSys(); record_rdtsc_op("FUNC_NAME", "END", 0, eip); return ret; } } #endif ret = orig_func(ARGS_ONLY_NAME); return ret; }
static void ps_print_level(int level, proc_p p) { /* pid ppid envid pgrp session xstat stat flag nxch */ #define MAXLEVEL 4 int i; int epilogue_count, yield_count; #if 0 char state[] = "XIRSHZ"; #endif if (level == -1) { printf("PID "); for (i = 0; i < MAXLEVEL; i++) printf(" "); #if 0 printf("PPID PG SES "); printf("sta xst flag nx "); printf("ticks ctxcnt eip name\n"); #else printf (" TICKS\tCTXCNT\tEIP\t\tNAME\t\tEID\n\n"); #endif return; } if (level > MAXLEVEL) level = MAXLEVEL; for (i = 0; i < level; i++) printf(" "); if (p == NULL) {printf(" null proc entry\n");return;} printf("%-3d",p->p_pid); for (i = level; i <= MAXLEVEL; i++) printf(" "); #if 0 printf("%3d ",(p->p_pptr) ? p->p_pptr->p_pid : -1); printf("%3d ",(p->p_pgrp) ? p->p_pgrp->pg_id : -1); printf("%3d ",(p->p_session->s_leader) ? p->p_session->s_leader->p_pid : -1); printf("%c %3d %4s %3d ", state[p->p_stat], p->p_xstat, ps_get_flags(p->p_flag), p->nxchildren); #endif epilogue_count = 0; yield_count = 0; get_counts(p->envid, &epilogue_count, &yield_count); printf("\t%5d\t%6d\t%08x\t%.10s", __envs[envidx(p->envid)].env_ticks, __envs[envidx(p->envid)].env_ctxcnt, /* epilogue_count, */ (p->envid == __envid || p->p_stat == SZOMB) ? 0 : get_eip(p->envid), ps_get_comm(p->envid,1)); if (strlen (ps_get_comm (p->envid,1)) < 8) printf ("\t\t"); else printf ("\t"); printf ("%d\n", p->envid); for (p = p->p_children.lh_first; p != 0; p = p->p_sibling.le_next) { ps_print_level(level+1,p); } }
//exception dispatcher void _on_exception(int code, int codedata, CPUState *cpudata) { e9printf("_on_exception called. code: %d, codedata: %d, cpudata: %p\n", code, codedata, cpudata); e9printf(" eax: %x, ebx: %x, edx: %x\n", read_eax(), read_ebx(), read_edx()); e9printf(" ebp: %x, esp: %x, eip: %x\n\n", read_ebp(), read_esp(), get_eip()); //sanitize code, just to be safe code = code & 31; int handled = 0; for (LinkNode *node=exception_stacks[code].first; node; node=node->next) { ExceptionHandler handler = node->data; if (handler(code, codedata, cpudata)) { handled = 1; break; } } if (!handled) { e9printf("Unhandled exception %d\n", code); kerror(-1, "Unhandled exception"); } }