void getjobnum(void) { uint4 status; int4 item_code; DCL_THREADGBL_ACCESS; SETUP_THREADGBL_ACCESS; item_code = JPI$_PID; if (SS$_NORMAL !=(status = lib$getjpi(&item_code, 0, 0, &process_id, 0, 0))) rts_error(VARLSTCNT(1) status); get_proc_info(process_id, TADR(login_time), &image_count); }
proc_info* exec_forg(char** exec, proc_info* status) { struct rusage *r = (struct rusage*)(malloc(sizeof(struct rusage))); int pid = fork(); inject_time(status); if (pid == 0) { // this is the child process execvp(exec[0], exec); } else { // this is the parent process wait(pid); getrusage(RUSAGE_SELF, r); return get_proc_info(r, status); } }
// params: int pid void proc_info(int argc, char *argv[]) { int pid, err, i; pcbinfo res; pid = stoi(get_arg(argv, 1)); err = get_proc_info(pid, &res); if (err == 0) { print("Information about process pid = "); printi(pid); print("\n\tname:\t\t\t"); print(res.name); print("\n\tpriority:\t\t"); printi(res.pri); print("\n\tsupervised processes:\t"); for (i = 0; i < MAXPCB; i++) { if (res.supervised[i] != -1) { printi(res.supervised[i]); print(" "); } } print("\n\tsupervisor process:\t"); printi(res.supervisor); print("\n\tprocess state:\t\t"); printi(res.state); print("\n\ttime to sleep:\t\t"); printi(res.sleep); print("\n\twaiting for process:\t"); printi(res.waitfor); //print("\n\tlast error:\t\t"); //printi(res.error); printn(); } else { print("An error occured! (code:"); printi(err); print(")\n"); } exit(0); }
/* * Get process list and send to person connected to our socket */ void ps(char *addl_args) { register int i; int num_procs; struct process_info *sp = NULL; if (addl_args != NULL) { transmit(" ** %s\n", addl_args); } num_procs = get_proc_info(&sp); for (i = 0; i < num_procs; ++i) { transmit("%d: %s\r\n", sp[i].pid, sp[i].name); } free_get_proc_info(sp); end_transmission(); return; }
/* * kill all processes for the prison. */ void kill_procs(void) { int procs_left = 0; /* Number of processes that didn't TERMinate */ int num_procs; struct process_info *sp = NULL; pid_t my_pid = getpid(); /* We play nice */ kill(-1, SIGTERM); sleep(1); num_procs = get_proc_info(&sp); if (num_procs != 0) { while (sp->pid != -1) { if (my_pid == sp->pid) { break; } else { printf("%s (%d) didn't die, will send SIGKILL in 5 seconds.\n", sp->name, sp->pid); ++procs_left; } ++sp; } if (procs_left > 0) { /* They might possibly exit gracefully if we give them a little time ... */ sleep(5); /* Get tough */ kill(-1, SIGKILL); } free_get_proc_info(sp); } }
void render_swap_and_blit(struct render *render) { char proc_info[1024]; struct drm_i915_mask_update update; EGLContext context; EGLSurface draw, read; uint32_t winx, winy, winw, winh; uint8_t state; float xscale, yscale; float *vertices = render->vertices; float *texcoords = render->tc_src; int r, b; if(render == NULL) return; get_proc_info(proc_info); winx = *(uint32_t*)(proc_info+34); winy = *(uint32_t*)(proc_info+38); winw = *(uint32_t*)(proc_info+42)+1; winh = *(uint32_t*)(proc_info+46)+1; state = *(uint8_t*)(proc_info+70); if(state & (WIN_STATE_MINIMIZED|WIN_STATE_ROLLED)) return; context = eglGetCurrentContext(); draw = eglGetCurrentSurface(EGL_DRAW); read = eglGetCurrentSurface(EGL_READ); eglSwapBuffers(render->dpy,draw); render->back_buffer++; render->back_buffer&=1; update.handle = render->mask_handle; update.dx = render->dx; update.dy = render->dy; update.width = render->width; update.height = render->height; update.bo_pitch = (render->width+15) & ~15; update.bo_map = (int)render->mask_buffer; if(drm_ioctl(render->fd, SRV_MASK_UPDATE_EX, &update)) return; if (!eglMakeCurrent(render->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, render->context)) { printf("failed to make window current"); goto err1; }; glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, render->tx_buffers[render->back_buffer]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, render->tx_mask); xscale = 1.0/render->scr_width; yscale = 1.0/render->scr_height; r = winx + render->dx + render->width; b = winy + render->dy + render->height; float t0, t1, t2, t5; vertices[0] = t0 = 2*(winx+render->dx)*xscale - 1.0; vertices[1 * 2] = t2 = 2*r*xscale - 1.0; vertices[2 * 2] = t2; vertices[3 * 2] = t0; vertices[1] = t1 = 2*(winy+render->dy)*yscale - 1.0; vertices[2*2+1] = t5 = 2*b*yscale - 1.0; vertices[1*2+1] = t1; vertices[3*2+1] = t5; glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glFinish(); err1: eglMakeCurrent(render->dpy, draw, read, context); }
// params: no param void ps(int argc, char *argv[]) { int pid[MAXPCB]; //char buf[255]; //char num[15]; int i, len; pcbinfo pinf; // init the pid list for (i = 0; i < MAXPCB; i++) pid[i] = -1; len = get_ps(pid); print("Process: "); printi(len); printn(); print("PID\tNAME\tSTATE\tPRIO\n"); print("_______________________________\n"); for (i = 0; i < len; i++) { if (pid[i] != -1) { get_proc_info(pid[i], &pinf); printi(pid[i]); print("\t"); print(pinf.name); print("\t"); switch (pinf.state) { case READY: print("READY"); break; case RUNNING: print("RUNNING"); break; case BLOCKED: print("BLOCKED"); break; case SLEEPING: print("SLEEPING"); break; case WAITING_IO: print("WAITING_IO"); break; case DOING_IO: print("DOING_IO"); break; case WAITING_PCB: print("WAITING_PCB"); break; case OMG_ZOMBIE: print("OMG_ZOMBIE"); break; } print("\t"); printi(pinf.pri); printn(); } } print("_______________________________\n"); exit(0); }
window_t *create_window(char *caption, int style, int x, int y, int w, int h, handler_t handler) { char proc_info[1024]; int stride; // __asm__ __volatile__("int3"); // ctx_t *ctx = &Window.client_ctx; if(handler==0) return 0; BeginDraw(); DrawWindow(x, y, w, h, NULL,0,0x41); EndDraw(); get_proc_info(proc_info); x = *(uint32_t*)(proc_info+34); y = *(uint32_t*)(proc_info+38); w = *(uint32_t*)(proc_info+42)+1; h = *(uint32_t*)(proc_info+46)+1; Window.handler = handler; // Window.ctx = ctx; list_initialize(&Window.link); list_initialize(&Window.child); // Window.bitmap.width = 1920; // Window.bitmap.height = 1080; // Window.bitmap.flags = 0; // if( create_bitmap(&Window.bitmap) ) // { // printf("not enough memory for window bitmap\n"); // return 0; // } // ctx->pixmap = &Window.bitmap; // ctx->offset_x = 0; // ctx->offset_y = 0; Window.rc.l = x; Window.rc.t = y; Window.rc.r = x + w; Window.rc.b = y + h; Window.w = w; Window.h = h; Window.caption_txt = caption; Window.style = style; Window.child_over = NULL; Window.child_focus = NULL; init_caption(&Window); init_panel(&Window); init_frame(&Window); send_message((ctrl_t*)&Window, MSG_SIZE, 0, 0); return &Window; };
void window_update_layout(window_t *win) { char proc_info[1024]; int new_w, new_h; uint8_t state; int winx, winy, winw, winh; // __asm__ __volatile__("int3"); get_proc_info(proc_info); winx = *(uint32_t*)(proc_info+34); winy = *(uint32_t*)(proc_info+38); winw = *(uint32_t*)(proc_info+42)+1; winh = *(uint32_t*)(proc_info+46)+1; state = *(uint8_t*)(proc_info+70); if(state & 2) { win->win_state = MINIMIZED; return; } if(state & 4) { win->win_state = ROLLED; return; }; if(state & 1) state = MAXIMIZED; else state = NORMAL; if( (winx != win->rc.l) || (winy != win->rc.t) ) { win->rc.l = winx; win->rc.t = winy; win->rc.r = winx + win->w; win->rc.b = winy + win->h; }; // if( winw == win->w && // winh == win->h && // state == win->win_state) // return; if(win->win_state != FULLSCREEN) win->win_state = state; #if 0 int old_size; int new_size; int pitch; old_size = win->bitmap.pitch * win->bitmap.height; old_size = (old_size+4095) & ~4095; pitch = ALIGN(win->w*4, 16); new_size = pitch * win->h; new_size = (new_size+4095) & ~4095; if( new_size < old_size) user_unmap(win->bitmap.data, new_size, old_size-new_size); win->bitmap.width = win->w; win->bitmap.pitch = pitch; #endif win->rc.r = winx + winw; win->rc.b = winy + winh; win->w = winw; win->h = winh; update_caption_size(win); update_panel_size(win); adjust_frame(win); send_message((ctrl_t*)win, MSG_SIZE, 0, 0); draw_window(win); };
void render_blit(struct render *render, enum px_buffer buffer) { char proc_info[1024]; EGLContext context; EGLSurface draw, read; int winx, winy; float dst_xscale, dst_yscale; float *vertices = render->vertices; float *texcoords = render->tc_src; int r, b; if(render == NULL) return; get_proc_info(proc_info); winx = *(uint32_t*)(proc_info+34); winy = *(uint32_t*)(proc_info+38); context = eglGetCurrentContext(); draw = eglGetCurrentSurface(EGL_DRAW); read = eglGetCurrentSurface(EGL_READ); if (!eglMakeCurrent(render->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, render->context)) { printf("failed to make window current"); goto err1; }; glUseProgram(render->blit_prog); glUniform1i(render->sampler, 0); glVertexAttribPointer(0, 2, GL_FLOAT,GL_FALSE, 2 * sizeof(float),render->vertices); glEnableVertexAttribArray(0); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, render->tx_buffers[buffer]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float),render->tc_src); glEnableVertexAttribArray(1); dst_xscale = 1.0/render->scr_width; dst_yscale = 1.0/render->scr_height; r = winx + render->dx + render->width; b = winy + render->dy + render->height; float t0, t1, t2, t5; vertices[0] = t0 = 2*(winx+render->dx)*dst_xscale - 1.0; vertices[1 * 2] = t2 = 2*r*dst_xscale - 1.0; vertices[2 * 2] = t2; vertices[3 * 2] = t0; vertices[1] = t1 = 2*(winy+render->dy)*dst_yscale - 1.0; vertices[2*2+1] = t5 = 2*b*dst_yscale - 1.0; vertices[1*2+1] = t1; vertices[3*2+1] = t5; texcoords[0] = 0.0; texcoords[1] = 0.0; texcoords[1*2] = 1.0; texcoords[1*2+1]= 0.0; texcoords[2*2] = 1.0; texcoords[2*2+1]= 1.0; texcoords[3*2] = 0.0; texcoords[3*2+1]= 1.0; glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glDisable(GL_TEXTURE_2D); glUseProgram(0); err1: eglMakeCurrent(render->dpy, draw, read, context); }
void getAndShow(process &currProcess) { procinfo pinfo; switch(get_proc_info(&pinfo, currProcess.get_pid())) { case -3: //error condition //TODO error handling #ifdef DEBUG print_string("Not all pinfo values filled"); #endif break; case -2: //error condition #ifdef DEBUG print_string("Extraneous values, some not read"); #endif break; case -1: //error condition currProcess.clear_keepLogging(); print_string("Error while opening stat file"); break; case 0: //do nothing break; default: currProcess.clear_keepLogging(); print_string("Unkown exit condition"); break; } currProcess.set_pinfo(pinfo); if(currProcess.get_fname() == "") //use the pid { #ifdef DEBUG print_string("Using PID"); #endif if(currProcess.get_pname() == "") //set the pname for the log file. { #ifdef DEBUG print_string("Setting pname"); #endif currProcess.set_pname(pinfo.values[cpu_comm]); if(currProcess.get_terminalOutput()) //show pname if not set and outputting to terminal { print_string(std::to_string(currProcess.get_pid()) + " pname is: " + currProcess.get_pname()); } } if(!currProcess.get_terminalOutput()) //don't care about the log file if not logging.... { #ifdef DEBUG print_string("Setting logname"); #endif currProcess.set_fname(currProcess.get_pname()+ "." + pinfo.values[cpu_pid] + ".log"); } } //only show logname once, and only if outputting to a log if(currProcess.get_showOnce() && !currProcess.get_terminalOutput()) { #ifdef DEBUG print_string("Show Once, not terminalOutput"); #endif print_string("Log File: " + currProcess.get_fpath() + currProcess.get_fname()); } if(pinfo.values[cpu_state] == "D") //D for DEAD { #ifdef DEBUG print_string("DEAD"); #endif /* No idea what pid will be if it comes back! Execution will never * stop if search is set and it never comes back. pname should be set * by now. * Will continue to search, by pname only. */ currProcess.set_pid(0); currProcess.clear_running(); if(!currProcess.get_search()) { currProcess.clear_keepLogging(); } } currProcess.clear_showOnce(); currProcess.outputData(); }
gtcm_server() { static readonly int4 reptim[2] = {-100000, -1}; /* 10ms */ static readonly int4 wait[2] = {-1000000, -1}; /* 100ms */ void gtcm_ch(), gtcm_exi_handler(), gtcm_init_ast(), gtcm_int_unpack(), gtcm_mbxread_ast(), gtcm_neterr(), gtcm_read_ast(), gtcm_remove_from_action_queue(), gtcm_shutdown_ast(), gtcm_write_ast(), la_freedb(); bool gtcm_link_accept(); bool alid; char buff[512]; char *h = NULL; char *la_getdb(); char nbuff[256]; char *pak = NULL; char reply; unsigned short outlen; int4 closewait[2] = {0, -1}; int4 inid = 0, mdl = 0, nid = 0, days = 0; int4 lic_status; int4 lic_x; int4 lm_mdl_nid(); uint4 status; int i, receive(), value; mstr name1, name2; struct NTD *cmu_ntdroot(); connection_struct *prev_curr_entry; struct dsc$descriptor_s dprd; struct dsc$descriptor_s dver; $DESCRIPTOR(node_name, nbuff); $DESCRIPTOR(proc_name, "GTCM_SERVER"); $DESCRIPTOR(timout, buff); DCL_THREADGBL_ACCESS; GTM_THREADGBL_INIT; assert(0 == EMPTY_QUEUE); /* check so dont need gdsfhead everywhere */ common_startup_init(GTCM_GNP_SERVER_IMAGE); /* Side-effect: Sets skip_dbtriggers to TRUE for non-trigger platforms */ gtm_env_init(); /* read in all environment variables */ name1.addr = "GTCMSVRNAM"; name1.len = SIZEOF("GTCMSVRNAM") - 1; status = trans_log_name(&name1, &name2, nbuff); if (SS$_NORMAL == status) { proc_name.dsc$a_pointer = nbuff; proc_name.dsc$w_length = node_name.dsc$w_length = name2.len; } else if (SS$_NOLOGNAM == status) { MEMCPY_LIT(nbuff, "GTCMSVR"); node_name.dsc$w_length = SIZEOF("GTCMSVR") - 1; } else rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) status); sys$setprn(&proc_name); status = lib$get_foreign(&timout, 0, &outlen, 0); if ((status & 1) && (6 > outlen)) { for (i = 0; i < outlen; i++) { value = value * 10; if (buff[i] <= '9' && buff[i] >= '0') value += buff[i] - 48; else break; } if (outlen && (i == outlen)) { cm_timeout = TRUE; closewait[0] = value * -10000000; } } dprd.dsc$w_length = cm_prd_len; dprd.dsc$b_dtype = DSC$K_DTYPE_T; dprd.dsc$b_class = DSC$K_CLASS_S; dprd.dsc$a_pointer= cm_prd_name; dver.dsc$w_length = cm_ver_len; dver.dsc$b_dtype = DSC$K_DTYPE_T; dver.dsc$b_class = DSC$K_CLASS_S; dver.dsc$a_pointer= cm_ver_name; ast_init(); licensed = TRUE; lkid = 2; # ifdef NOLICENSE lid = 1; # else /* this code used to be scattered to discourage reverse engineering, but since it now disabled, that seems pointless */ lic_status = ((NULL == (h = la_getdb(LMDB))) ? LP_NOCNFDB : SS$_NORMAL); lic_status = ((1 == (lic_status & 1)) ? lm_mdl_nid(&mdl, &nid, &inid) : lic_status); lic_status = ((1 == (lic_status & 1)) ? lp_licensed(h, &dprd, &dver, mdl, nid, &lid, &lic_x, &days, pak) : lic_status); if (LP_NOCNFDB != lic_status) la_freedb(h); if (1 == (lic_status & 1)) { licensed = TRUE; if (days < 14) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_WILLEXPIRE); } else { licensed = FALSE; sys$exit(lic_status); } # endif gtcm_ast_avail = astq_dyn_avail - GTCM_AST_OVRHD; stp_init(STP_INITSIZE); rts_stringpool = stringpool; cache_init(); procnum = 0; get_proc_info(0, TADR(login_time), &image_count); memset(proc_to_clb, 0, SIZEOF(proc_to_clb)); status = cmi_init(&node_name, 0, 0, gtcm_init_ast, gtcm_link_accept); if (!(status & 1)) { rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ((status ^ 3) | 4)); sys$exit(status); } ntd_root = cmu_ntdroot(); ntd_root->mbx_ast = gtcm_mbxread_ast; ntd_root->err = gtcm_neterr; gtcm_connection = FALSE; lib$establish(gtcm_ch); gtcm_exi_blk.exit_hand = >cm_exi_handler; gtcm_exi_blk.arg_cnt = 1; gtcm_exi_blk.cond_val = >cm_exi_condition; sys$dclexh(>cm_exi_blk); INVOKE_INIT_SECSHR_ADDRS; initialize_pattern_table(); assert(run_time); /* Should have been set by common_startup_init */ while (!cm_shutdown) { if (blkdlist) gtcml_chkreg(); assert(!lib$ast_in_prog()); status = sys$dclast(>cm_remove_from_action_queue, 0, 0); if (SS$_NORMAL != status) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) CMERR_CMSYSSRV, 0, status, 0); if (INTERLOCK_FAIL == curr_entry) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) CMERR_CMINTQUE); if (EMPTY_QUEUE != curr_entry) { switch (*curr_entry->clb_ptr->mbf) { case CMMS_L_LKCANALL: reply = gtcmtr_lkcanall(); break; case CMMS_L_LKCANCEL: reply = gtcmtr_lkcancel(); break; case CMMS_L_LKREQIMMED: reply = gtcmtr_lkreqimmed(); break; case CMMS_L_LKREQNODE: reply = gtcmtr_lkreqnode(); break; case CMMS_L_LKREQUEST: reply = gtcmtr_lkrequest(); break; case CMMS_L_LKRESUME: reply = gtcmtr_lkresume(); break; case CMMS_L_LKACQUIRE: reply = gtcmtr_lkacquire(); break; case CMMS_L_LKSUSPEND: reply = gtcmtr_lksuspend(); break; case CMMS_L_LKDELETE: reply = gtcmtr_lkdelete(); break; case CMMS_Q_DATA: reply = gtcmtr_data(); break; case CMMS_Q_GET: reply = gtcmtr_get(); break; case CMMS_Q_KILL: reply = gtcmtr_kill(); break; case CMMS_Q_ORDER: reply = gtcmtr_order(); break; case CMMS_Q_PREV: reply = gtcmtr_zprevious(); break; case CMMS_Q_PUT: reply = gtcmtr_put(); break; case CMMS_Q_QUERY: reply = gtcmtr_query(); break; case CMMS_Q_ZWITHDRAW: reply = gtcmtr_zwithdraw(); break; case CMMS_S_INITPROC: reply = gtcmtr_initproc(); break; case CMMS_S_INITREG: reply = gtcmtr_initreg(); break; case CMMS_S_TERMINATE: reply = gtcmtr_terminate(TRUE); break; case CMMS_E_TERMINATE: reply = gtcmtr_terminate(FALSE); break; case CMMS_U_LKEDELETE: reply = gtcmtr_lke_clearrep(curr_entry->clb_ptr, curr_entry->clb_ptr->mbf); break; case CMMS_U_LKESHOW: reply = gtcmtr_lke_showrep(curr_entry->clb_ptr, curr_entry->clb_ptr->mbf); break; case CMMS_B_BUFRESIZE: reply = CM_WRITE; value = *(unsigned short *)(curr_entry->clb_ptr->mbf + 1); if (value > curr_entry->clb_ptr->mbl) { free(curr_entry->clb_ptr->mbf); curr_entry->clb_ptr->mbf = malloc(value); } *curr_entry->clb_ptr->mbf = CMMS_C_BUFRESIZE; curr_entry->clb_ptr->mbl = value; curr_entry->clb_ptr->cbl = 1; break; case CMMS_B_BUFFLUSH: reply = gtcmtr_bufflush(); break; case CMMS_Q_INCREMENT: reply = gtcmtr_increment(); break; default: reply = FALSE; if (SS$_NORMAL == status) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_BADGTMNETMSG, 1, (int)*curr_entry->clb_ptr->mbf); break; } if (curr_entry) /* curr_entry can be NULL if went through gtcmtr_terminate */ { status = sys$gettim(&curr_entry->lastact[0]); if (SS$_NORMAL != status) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) status); /* curr_entry is used by gtcm_mbxread_ast to determine if it needs to defer the interrupt message */ prev_curr_entry = curr_entry; if (CM_WRITE == reply) { /* if ast == gtcm_write_ast, let it worry */ curr_entry->clb_ptr->ast = gtcm_write_ast; curr_entry = EMPTY_QUEUE; cmi_write(prev_curr_entry->clb_ptr); } else { curr_entry = EMPTY_QUEUE; if (1 == (prev_curr_entry->int_cancel.laflag & 1)) { /* valid interrupt cancel msg, handle in gtcm_mbxread_ast */ status = sys$dclast(gtcm_int_unpack, prev_curr_entry, 0); if (SS$_NORMAL != status) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) status); } else if (CM_READ == reply) { prev_curr_entry->clb_ptr->ast = gtcm_read_ast; cmi_read(prev_curr_entry->clb_ptr); } } } } else if (1 < astq_dyn_avail) { # ifdef GTCM_REPTIM /* if reptim is not needed - and smw doesn't know why it would be - remove this */ status = sys$schdwk(0, 0, &wait[0], &reptim[0]); # else status = sys$schdwk(0, 0, &wait[0], 0); # endif sys$hiber(); sys$canwak(0, 0); } if (cm_timeout && (0 == gtcm_users)) sys$setimr(efn_ignore, closewait, gtcm_shutdown_ast, &cm_shutdown, 0); } }