static int do_exec(int proc_e, char *exec, size_t exec_len, char *progname, char *frame, int frame_len) { int r; vir_bytes vsp; struct exec_info execi; int i; memset(&execi, 0, sizeof(execi)); execi.stack_size = DEFAULT_STACK_LIMIT; execi.proc_e = proc_e; execi.hdr = exec; execi.hdr_len = exec_len; strncpy(execi.progname, progname, PROC_NAME_LEN-1); execi.progname[PROC_NAME_LEN-1] = '\0'; execi.frame_len = frame_len; /* callback functions and data */ execi.copymem = read_seg; execi.clearproc = libexec_clearproc_vm_procctl; execi.clearmem = libexec_clear_sys_memset; execi.allocmem_prealloc = libexec_alloc_mmap_prealloc; execi.allocmem_ondemand = libexec_alloc_mmap_ondemand; for(i = 0; exec_loaders[i].load_object != NULL; i++) { r = (*exec_loaders[i].load_object)(&execi); /* Loaded successfully, so no need to try other loaders */ if (r == OK) break; } /* No exec loader could load the object */ if (r != OK) { printf("RS: do_exec: loading error %d\n", r); return r; } /* Inform PM */ if((r = libexec_pm_newexec(execi.proc_e, &execi)) != OK) return r; /* Patch up stack and copy it from RS to new core image. */ vsp = execi.stack_high; vsp -= frame_len; libexec_patch_ptr(frame, vsp); r = sys_datacopy(SELF, (vir_bytes) frame, proc_e, (vir_bytes) vsp, (phys_bytes)frame_len); if (r != OK) { printf("do_exec: copying out new stack failed: %d\n", r); exec_restart(proc_e, r, execi.pc); return r; } return exec_restart(proc_e, OK, execi.pc); }
static int do_exec(int proc_e, char *exec, size_t exec_len, char *progname, char *frame, int frame_len) { int r; vir_bytes vsp; struct exec_info execi; int i; execi.proc_e = proc_e; execi.image = exec; execi.image_len = exec_len; strncpy(execi.progname, progname, PROC_NAME_LEN-1); execi.progname[PROC_NAME_LEN-1] = '\0'; execi.frame_len = frame_len; for(i = 0; exec_loaders[i].load_object != NULL; i++) { r = (*exec_loaders[i].load_object)(&execi); /* Loaded successfully, so no need to try other loaders */ if (r == OK) break; } /* No exec loader could load the object */ if (r != OK) { printf("RS: do_exec: loading error %d\n", r); return r; } /* Patch up stack and copy it from RS to new core image. */ vsp = execi.stack_top; vsp -= frame_len; patch_ptr(frame, vsp); r = sys_datacopy(SELF, (vir_bytes) frame, proc_e, (vir_bytes) vsp, (phys_bytes)frame_len); if (r != OK) { printf("RS: stack_top is 0x%lx; tried to copy to 0x%lx in %d\n", execi.stack_top, vsp, proc_e); printf("do_exec: copying out new stack failed: %d\n", r); exec_restart(proc_e, r, execi.pc); return r; } return exec_restart(proc_e, OK, execi.pc); }
/*===========================================================================* * do_execrestart * *===========================================================================*/ PUBLIC int do_execrestart() { int proc_e, proc_n, result; struct mproc *rmp; vir_bytes pc; if (who_e != RS_PROC_NR) return EPERM; proc_e= m_in.EXC_RS_PROC; if (pm_isokendpt(proc_e, &proc_n) != OK) { panic("do_execrestart: got bad endpoint: %d", proc_e); } rmp= &mproc[proc_n]; result= m_in.EXC_RS_RESULT; pc= (vir_bytes)m_in.EXC_RS_PC; exec_restart(rmp, result, pc); return OK; }
/*===========================================================================* * do_execrestart * *===========================================================================*/ int do_execrestart(void) { int proc_e, proc_n, result; struct mproc *rmp; vir_bytes pc, ps_str; if (who_e != RS_PROC_NR) return EPERM; proc_e = m_in.m_rs_pm_exec_restart.endpt; if (pm_isokendpt(proc_e, &proc_n) != OK) { panic("do_execrestart: got bad endpoint: %d", proc_e); } rmp = &mproc[proc_n]; result = m_in.m_rs_pm_exec_restart.result; pc = m_in.m_rs_pm_exec_restart.pc; ps_str = m_in.m_rs_pm_exec_restart.ps_str; exec_restart(rmp, result, pc, rmp->mp_frame_addr, ps_str); return OK; }
/*===========================================================================* * do_execrestart * *===========================================================================*/ int do_execrestart() { int proc_e, proc_n, result; struct mproc *rmp; if (who_e != RS_PROC_NR) return -EPERM; proc_e= m_in.EXC_RS_PROC; if (pm_isokendpt(proc_e, &proc_n) != 0) { panic(__FILE__, "do_execrestart: got bad endpoint", proc_e); } rmp= &mproc[proc_n]; result= m_in.EXC_RS_RESULT; exec_restart(rmp, result); return 0; }
/** * Execute a parse tree and return the result set or runtime error * * @param dcb The DCB that connects to the client * @param tree The parse tree for the query */ void maxinfo_execute(DCB *dcb, MAXINFO_TREE *tree) { switch (tree->op) { case MAXOP_SHOW: exec_show(dcb, tree); break; case MAXOP_SELECT: exec_select(dcb, tree); break; case MAXOP_FLUSH: exec_flush(dcb, tree); break; case MAXOP_SET: exec_set(dcb, tree); break; case MAXOP_CLEAR: exec_clear(dcb, tree); break; case MAXOP_SHUTDOWN: exec_shutdown(dcb, tree); break; case MAXOP_RESTART: exec_restart(dcb, tree); break; case MAXOP_TABLE: case MAXOP_COLUMNS: case MAXOP_LITERAL: case MAXOP_PREDICATE: case MAXOP_LIKE: case MAXOP_EQUAL: default: maxinfo_send_error(dcb, 0, "Unexpected operator in parse tree"); } }
static int load_elf(struct exec_info *execi) { int r; int proc_e; phys_bytes tot_bytes; /* total space for program, including gap */ vir_bytes text_addr, text_filebytes, text_membytes; vir_bytes data_addr, data_filebytes, data_membytes; off_t text_offset, data_offset; int sep_id, is_elf, load_text, allow_setuid; uid_t new_uid; gid_t new_gid; assert(execi != NULL); assert(execi->image != NULL); proc_e = execi->proc_e; /* Read the file header and extract the segment sizes. */ r = read_header_elf(execi->image, &text_addr, &text_filebytes, &text_membytes, &data_addr, &data_filebytes, &data_membytes, &tot_bytes, &execi->pc, &text_offset, &data_offset); if (r != OK) { return(r); } new_uid= getuid(); new_gid= getgid(); sep_id = 1; is_elf = 1; r = exec_newmem(proc_e, trunc_page(text_addr), text_membytes, trunc_page(data_addr), data_membytes, tot_bytes, execi->frame_len, sep_id, is_elf, 0 /*dev*/, proc_e /*inum*/, 0 /*ctime*/, execi->progname, new_uid, new_gid, &execi->stack_top, &load_text, &allow_setuid); if (r != OK) { printf("RS: load_elf: exec_newmem failed: %d\n", r); exec_restart(proc_e, r, execi->pc); return r; } /* Read in text and data segments. */ if (load_text) { r = read_seg(execi, text_offset, proc_e, T, text_addr, text_filebytes); if (r != OK) { printf("RS: load_elf: read_seg failed: %d\n", r); exec_restart(proc_e, r, execi->pc); return r; } } else printf("RS: load_elf: not loading text segment\n"); r = read_seg(execi, data_offset, proc_e, D, data_addr, data_filebytes); if (r != OK) { printf("RS: load_elf: read_seg failed: %d\n", r); exec_restart(proc_e, r, execi->pc); return r; } return(OK); }
static int load_aout(struct exec_info *execi) { int r; int hdrlen, sep_id, load_text, allow_setuid; vir_bytes text_bytes, data_bytes, bss_bytes; phys_bytes tot_bytes; off_t off; uid_t new_uid; gid_t new_gid; int proc_e; assert(execi != NULL); assert(execi->image != NULL); proc_e = execi->proc_e; /* Read the file header and extract the segment sizes. */ r = read_header_aout(execi->image, execi->image_len, &sep_id, &text_bytes, &data_bytes, &bss_bytes, &tot_bytes, &execi->pc, &hdrlen); if (r != OK) { return r; } new_uid= getuid(); new_gid= getgid(); /* XXX what should we use to identify the executable? */ r= exec_newmem(proc_e, 0 /*text_addr*/, text_bytes, 0 /*data_addr*/, data_bytes + bss_bytes, tot_bytes, execi->frame_len, sep_id, 0 /*is_elf*/, 0 /*dev*/, proc_e /*inum*/, 0 /*ctime*/, execi->progname, new_uid, new_gid, &execi->stack_top, &load_text, &allow_setuid); if (r != OK) { printf("RS: load_aout: exec_newmem failed: %d\n", r); exec_restart(proc_e, r, execi->pc); return r; } off = hdrlen; /* Read in text and data segments. */ if (load_text) { r= read_seg(execi, off, proc_e, T, 0, text_bytes); if (r != OK) { printf("RS: load_aout: read_seg failed: %d\n", r); exec_restart(proc_e, r, execi->pc); return r; } } else printf("RS: load_aout: not loading text segment\n"); off += text_bytes; r= read_seg(execi, off, proc_e, D, 0, data_bytes); if (r != OK) { printf("RS: load_aout: read_seg failed: %d\n", r); exec_restart(proc_e, r, execi->pc); return r; } return OK; }