bool InitializeShims() { if (initialized) return true; #define get_proc(name, proc) \ do { \ name = (proc)eglGetProcAddress(#name); \ assert(name); \ } while (0) get_proc(eglCreateImageKHR, PFNEGLCREATEIMAGEKHRPROC); get_proc(eglCreateSyncKHR, PFNEGLCREATESYNCKHRPROC); get_proc(eglDestroySyncKHR, PFNEGLDESTROYSYNCKHRPROC); get_proc(eglWaitSyncKHR, PFNEGLWAITSYNCKHRPROC); get_proc(eglDestroyImageKHR, PFNEGLDESTROYIMAGEKHRPROC); get_proc(glEGLImageTargetTexture2DOES, PFNGLEGLIMAGETARGETTEXTURE2DOESPROC); get_proc(glDeleteVertexArraysOES, PFNGLDELETEVERTEXARRAYSOESPROC); get_proc(glGenVertexArraysOES, PFNGLGENVERTEXARRAYSOESPROC); get_proc(glBindVertexArrayOES, PFNGLBINDVERTEXARRAYOESPROC); #ifndef USE_ANDROID_SHIM get_proc(eglDupNativeFenceFDANDROID, PFNEGLDUPNATIVEFENCEFDANDROIDPROC); #endif initialized = true; return true; }
static struct pidset filter_out_forks(struct pidset in) { /* * Discard any process whose parent is also in our remaining match * set and looks sufficiently like it for us to decide this one's * an uninteresting fork (e.g. of a shell script executing a * complex pipeline). */ struct pidset ret; int pid; pidset_init(&ret); for (pid = pidset_first(&in); pid >= 0; pid = pidset_next(&in)) { const struct procdata *proc = get_proc(pid); if (pidset_in(&in, proc->ppid)) { /* The parent is in our set too. Is it similar? */ const struct procdata *parent = get_proc(proc->ppid); if (!strnullcmp(parent->exe, proc->exe) && !argcmp(parent->argv, proc->argv)) { /* Yes; don't list it. */ continue; } } pidset_add(&ret, pid); } return ret; }
bool storm::load() { if (!mod_) return false; if (!(fn_sfile_load_file_ = get_proc(281))) return false; if (!(fn_sfile_unload_file_ = get_proc(280))) return false; return true; }
bool storm::load() { if (!mod_) return false; fn_sfile_load_file_ = get_proc(281); if (!(fn_sfile_load_file_)) return false; fn_sfile_unload_file_ = get_proc(280); if (!(fn_sfile_unload_file_)) return false; fn_sfile_exists_ = get_proc(288); if (!(fn_sfile_exists_)) return false; return true; }
static void init_nv_functions(void) { jimglDXSetResourceShareHandleNV = get_proc("wglDXSetResourceShareHandleNV"); jimglDXOpenDeviceNV = get_proc("wglDXOpenDeviceNV"); jimglDXCloseDeviceNV = get_proc("wglDXCloseDeviceNV"); jimglDXRegisterObjectNV = get_proc("wglDXRegisterObjectNV"); jimglDXUnregisterObjectNV = get_proc("wglDXUnregisterObjectNV"); jimglDXObjectAccessNV = get_proc("wglDXObjectAccessNV"); jimglDXLockObjectsNV = get_proc("wglDXLockObjectsNV"); jimglDXUnlockObjectsNV = get_proc("wglDXUnlockObjectsNV"); nv_capture_available = !!jimglDXSetResourceShareHandleNV && !!jimglDXOpenDeviceNV && !!jimglDXCloseDeviceNV && !!jimglDXRegisterObjectNV && !!jimglDXUnregisterObjectNV && !!jimglDXObjectAccessNV && !!jimglDXLockObjectsNV && !!jimglDXUnlockObjectsNV; if (nv_capture_available) hlog("Shared-texture OpenGL capture available"); }
static struct pidset filter_by_command(struct pidset in, const char **words) { /* * Look for processes matching the user-supplied command name and * subsequent arguments. */ struct pidset ret; int pid; pidset_init(&ret); for (pid = pidset_first(&in); pid >= 0; pid = pidset_next(&in)) { const struct procdata *proc = get_proc(pid); int i, j; if (!proc->argv || proc->argc < 1) goto no_match; /* Find the command, whether it's a binary or a script. */ i = find_command(proc->argc, proc->argv, words[0]); if (i < 0) goto no_match; /* Now check that subsequent arguments match. */ for (j = 1; words[j]; j++) if (!proc->argv[i+j] || strcmp(proc->argv[i+j], words[j])) goto no_match; /* If we get here, we have a match! */ pidset_add(&ret, pid); no_match:; } return ret; }
void _CUDAMALLOC(int sd,proc_data* data){ printf("CUDAMALLOC(%d)\n",sd); proc* p; nvmlReturn_t res; nvmlMemory_t mem; int devp; p = get_proc(sd); memcpy(p->data,data,sizeof(proc_data)); devp = data->pos; printf("DEVPOS : %d\n",data->pos); printf("\tPID : %d\n",p->data->pid); res = nvmlDeviceGetMemoryInfo(dem.devs[devp],&mem); if(res != NVML_SUCCESS){ printf("Failed to get Memory Information\n"); exit(-1); } if(mem.free > p->data->req + M64 + dem.flags[devp].reserved){ printf("\tGOAHEAD (REQ : %lu[MB])\n",p->data->req >> 20); MSEND(sd,GOAHEAD,0,0,0,0,0); dem.flags[devp].reserved += p->data->req; }else{
void _MALLOCDONE(int sd,proc_data* data){ printf("MALLOCDONE(%d)\n",sd); proc* p; int devp; p = get_proc(sd); printf("\tPID : %d\n",p->data->pid); memcpy(p->data,data,sizeof(proc_data)); devp = p->data->pos; if(!p->suspended){ dem.flags[devp].reserved -= p->data->req; }else{ p->suspended = 0; } p->data->mem += p->data->req; p->data->req = 0; }
void _FAILEDTOALLOC(int sd,proc_data* data){ printf("FAILEDTOALLOC(%d)\n",sd); proc* p; int i; p = get_proc(sd); printf("\tPID : %d\n",p->data->pid); memcpy(p->data,data,sizeof(proc_data)); p->queued = BACKUP; for(i = 0 ; i < dem.ndev ; i ++){ if(dem.flags[i].sd == p->sd){ printf("Failed to MIGRATE!!!!!!!!!!!!!!\n"); dem.flags[i].flag = 0; dem.flags[i].sd = -1; } } dequeueSpecifyProc(p); cons_renew(p); }
static string port_get(port *p) { char *(*get_proc)(port *, char **); char *error = NULL; char *result; if (p->status & INPUT_CLOSED) { var_set_variable("error", "Attempt to read from a port whose input has been closed"); return(string_Copy("")); } get_proc = p->get; if (!get_proc) { var_set_variable("error", "Attempt to read from a port which does not support reading"); return(string_Copy("")); } result = get_proc(p, &error); if (!result) { var_set_variable("error", error); return(string_Copy("")); } else return(result); }
void _FIN(int sd){ dem.procCounter--; printf("FIN(NUM OF PROCS:%d)\n",dem.procCounter); proc* p; int devNum,i; for(i = 0 ; i < dem.ndev ; i ++){ if(dem.flags[i].sd == sd){ printf("\tFIND FAILED PROC(SD:%d)\n",sd); dem.flags[i].flag = 0; dem.flags[i].sd = 0; } } p = get_proc(sd); devNum = p->data->pos; remove_proc(p); dequeueSpecifyDevNO(devNum); }
int init() { PROC *p; int i; for (i=0; i<=NPROC; i++) { p = &proc[i]; p->pid = i; p->status = FREE; p->priority = 0; str p->next = &proc[i+1]; } p->next=NULL; printf("\n"); proc[NPROC-1].next = NULL; // freeList freeList=&proc[0]; readyQueue = NULL; sleepList=NULL; /**** create P0 as running ******/ p = get_proc(&freeList); // get PROC from freeList p->ppid=0; p->status = READY; running = p; nproc=1; }
// function to create a process DYNAMICALLY PROC *kfork() { int i; // will be used for the kstack initialization... // get the proc... PROC *p = get_proc(); if (p == 0) return 0; // if there were no procs, report kfork's failure // initialize the proc... p->status = READY; // it must be ready to run... p->priority = 1; // it has no particular preference on when to run... p->ppid = running->pid; // its parent is the current processor, of course! p->parent = running; // now to setup the kstack! // first things first, lets clean up the registers by setting them to 0. for (i = 1; i < 10; i++) p->kstack[SSIZE - i] = 0; p->kstack[SSIZE - 1] = (int)body; // now we need to make sure to call tswitch from body when the proc runs... p->ksp = &(p->kstack[SSIZE - 9]); // set the ksp to point to the top of the stack // enter the proc into the readyQueue, since it's now ready for primetime! enqueue(&readyQueue, p); // return the new proc!!! return p; }
PROC *kfork(){ //PROC *p = get_proc(&freeList); //to get a FREE PROC from freeList; if none, return 0 for FAIL; int i; PROC *p; p = get_proc(&freeList); if(p == 0){ printf("no more PROC, kfork() failed\n"); return 0; //FAIL } p->status = READY; p->priority = 1; p->ppid = running->pid; p->parent = running; for (i = 1; i < 10; ++i){ //SAVED CPU registers p->kstack[SSIZE - i] = 0; //all 0's } p->kstack[SSIZE - 1] = (int) body; //resume point = address of body() p->ksp = &p->kstack[SSIZE - 9]; //prock saved sp enqueue(&readyQueue, p); // enter p into readyQueue by priority return p; //return child PROC pointer }
int init() { PROC *p; int i, j; /* initialize all proc's */ for (i=0; i<NPROC; i++){ p = &proc[i]; p->pid = i; // pid = 0,1,2,..NPROC-1 p->next = &proc[i+1]; // point to next proc p->priority = 0; p->status = FREE; if (i){ // not for P0 p->kstack[SSIZE-1] = (int)body; // entry address of body() for (j=2; j<10; j++) // kstack[ ] high end entries = 0 p->kstack[SSIZE-j] = 0; p->ksp = &(p->kstack[SSIZE-9]); } } proc[NPROC-1].next = 0; // all procs form a circular link list freeList = &proc[0]; readyQueue = 0; p = get_proc(&freeList); p->ppid = 0; p->status = READY; running = p; // P0 is running printQueue(freeList); printf("\n"); printf("init complete\n"); }
void _CONNECT(int sd){ dem.procCounter++; printf("CONNECT (QUEUESIZE :%d)\n",queue_size()); printf(" (NUM OF PROCS:%d)\n",dem.procCounter); proc_data* sendProc; proc* p; sendProc = (proc_data*)malloc(sizeof(proc_data)); p = get_proc(sd); if(queue_size() > 0 || dem.procCounter > MAXPROC){ sendProc->REQUEST = CANNOTENTER; p->queued = 1; }else{ sendProc->REQUEST = CONNECT; usleep(500000);//1.0[sec] } send(sd,sendProc,sizeof(proc_data),0); }
PROC *kfork() // create a child process, begin from body() { int i; PROC *p = get_proc(&freeList); if (!p) { printf("no more PROC, kfork() failed\n"); return 0; } p->status = READY; p->priority = 1; // priority = 1 for all proc except P0 p->ppid = running->pid; // parent = running /* initialize new proc's kstack[ ] */ for (i=1; i<10; i++) // saved CPU registers p->kstack[SSIZE-i]= 0 ; // all 0's //ADD these lines because we have two new registers to deal with p->kstack[SSIZE-10] = 0x1000; p->kstack[SSIZE-11] = 0x1000; p->kstack[SSIZE-1] = (int)body; // resume point=address of body() //Edit this to handle two new registers p->ksp = &p->kstack[SSIZE-11]; // stores a local reference to the current proc's stack pointer for later use enqueue(&readyQueue, p); // enter p into readyQueue by priority return p; // return child PROC pointer }
void _MIGDONE(int sd,proc_data* data){ proc* p; int devPos; devPos = data->pos; printf("MIGDONE(%d)\n",devPos); p = get_proc(sd); if(dem.flags[devPos].sd == sd){ printf("\tSUCCESS TO MIGRATE\n"); }else{ printf("\tFAILED TO MIGRATE(GET INCORRECT INFORMATION)\n"); printf("\tTHE RECEIVED DATA IS %d(SD)\n",sd); printf("\tTHE REGISTERD DATA IS %d(FLAG)\n",dem.flags[devPos]); } dem.flags[devPos].sd = -1; dem.flags[devPos].flag = 0; renew_proc(data,sd); }
PROC *kfork() { int i = 0; PROC *p = get_proc(&freeList); //empty free list if(p == 0) { printf("freeList is empty (kfork fail)\n"); return p; } nproc++; p->status = READY; p->priority = 1; p->ppid = running->pid; p->parent = running; //init p's kstack for(i = 1; i <= 9; i++) { p->kstack[SSIZE - i] = 0; } p->kstack[SSIZE - 1] = (int)body; //point stack pointer to top of stack (lower addr) p->ksp = &(p->kstack[SSIZE - 9]); enqueue(&readyQueue, p); return p; }
/* ================================================================================ NAME : loadProcessInfo DESCRIPTION : get process info from system into internal data struct ASSUMPTIONS : None PRE-CONDITIONS : POST-CONDITIONS : NOTES : ================================================================================ */ Boolean Process::loadProcessInfo(int &pIndex) { // This routine fills in the protected member pInfo by calling // get_proc. Because Linux process entries are not contiguous // this routine modifies pIndex so that the caller, after // incrementing pIndex, will be able to fetch the next process in // a subsequent call. // It returns true if it succeeded in fetching a process, otherwise // false, incidating that there are no more processes to be fetched. // get_proc() an empty peg_proc_t to fill in, an integer , // and flag: either GET_PROC_BY_INDEX or GET_PROC_BY_PID // if GET_PROC_BY_INDEX is set, get_proc takes the integer (pIndex) // and locates the (pIndex)th process in the proc filesystem. // After the call is completed pIndex is incremented. // How this works: get_proc walks through the /proc directory and // counts as it steps through process dirs within proc. When it // encounters the pIndex'th process dir within /proc it instantiates // pInfo with that reference and update pIndex // If GET_PROC_BY_PID is set, get_proc will find the process by the pid // get_proc(&pInfo, pid, GET_PROC_BY_PID); return get_proc(&pInfo, pIndex, GET_PROC_BY_INDEX); // get_proc returns true if it successfully located a process dir at the // pIndex search if we return a false, we either can't open /proc, which // will be logger, or we are out of processes }
// the tricky way is call system("grep 'xxx' /proc/version") int get_dis() { const char *regex = "Ubuntu|Red Hat|SUSE|Debian|Gentoo|Gentoo Hardened|AliCloud"; char *proc_version = get_proc(); regex_t *reg = reg_compile( regex ); regmatch_t pmatch[5]; if (regexec(reg, proc_version, (size_t) 5, pmatch, 0)) { printf("error to match against the proc version"); exit (1); } int issue; int idx=0; for ( ; idx < 5; idx++) { if ( pmatch[idx].rm_so == -1) continue; *(proc_version + pmatch[idx].rm_eo) = '\0'; // printf("%s\n", (proc_version + pmatch[idx].rm_so)); issue = _get_dis(proc_version + pmatch[idx].rm_so); } free(proc_version); regfree(reg); vm_issue=issue; return issue; }
//modified for this lab PROC *kfork(char *filename) // create a child process, begin from body() { int i; //get the proc from the free list PROC *p = get_proc(&freeList); //make sure you got a process! if (!p) { printf("no more PROC, kfork() failed\n"); return 0; } //set the status and priority and parent id p->status = READY; p->priority = 1; // priority = 1 for all proc except P0 p->ppid = running->pid; // parent = running /* initialize new proc's kstack[ ] */ for (i=1; i<10; i++) // saved CPU registers p->kstack[SSIZE-i]= 0 ; // all 0's to show that it's an "empty process" p->kstack[SSIZE-1] = (int)body; // resume point=address of body() p->ksp = &p->kstack[SSIZE-9]; // proc saved sp enqueue(&readyQueue, p); // enter p into readyQueue by priority if (filename) { } return p; // return child PROC pointer }
int init() { PROC *p; int i; color = 0x0C; printf("init ...."); for (i=0; i<NPROC; i++){ // initialize all procs p = &proc[i]; p->pid = i; p->status = FREE; p->priority = 0; strcpy(proc[i].name, pname[i]); p->next = &proc[i+1]; } freeList = &proc[0]; // all procs are in freeList proc[NPROC-1].next = 0; readyQueue = sleepList = 0; /**** create P0 as running ******/ p = get_proc(&freeList); p->status = RUNNING; p->ppid = 0; p->parent = p; running = p; nproc = 1; printf("done\n"); }
//initializes all the procs int init() { //placeholder proc and index PROC *p; int i; printf("init ...."); for (i=0; i<NPROC; i++) // initialize all procs { p = &proc[i]; p->pid = i; p->status = FREE; p->priority = 0; p->next = &proc[i+1]; } proc[NPROC-1].next = 0; freeList = &proc[0]; // all procs are in freeList readyQueue = 0; sleepList = 0; /**** create P0 as running ******/ p = get_proc(&freeList); // allocate a PROC from freeList p->ppid = 0; // P0’s parent is itself p->status = READY; running = p; // P0 is now running nproc++; printf("done\n"); }
int init() { PROC *p; int i, j; printf("init ...."); for (i=0; i<NPROC; i++){ // initialize all procs p = &proc[i]; p->pid = i; p->status = FREE; p->priority = 0; strcpy(proc[i].name, pname[i]); p->next = &proc[i+1]; for (j=0; j<NFD; j++) p->fd[j] = 0; } freeList = &proc[0]; // all procs are in freeList proc[NPROC-1].next = 0; readyQueue = sleepList = 0; for (i=0; i<NOFT; i++) oft[i].refCount = 0; for (i=0; i<NPIPE; i++) pipe[i].busy = 0; /**** create P0 as running ******/ p = get_proc(&freeList); p->status = RUNNING; p->ppid = 0; p->parent = p; running = p; nproc = 1; printf("done\n"); }
int init() { PROC *p; int i; printf("init ...."); for (i=0; i<NPROC; i++){ // initialize all procs p = &proc[i]; p->pid = i; p->status = FREE; p->priority = 0; strcpy(proc[i].name, pname[i]); p->inkmode = 1; p->next = &proc[i+1]; } freeList = &proc[0]; // all procs are in freeList proc[NPROC-1].next = 0; readyQueue = sleepList = 0; /**** create P0 as running ******/ p = get_proc(&freeList); p->status = READY; p->ppid = 0; p->parent = p; p->inkmode = 1; running = p; nproc = 1; // initialize HD and CD drivers pr_init(); }
int Thread::asynch_handler() { if (asynch & THREAD_ASYNCH_CLEANING) { //kinfo("Cleaning process %d, %d\n", get_pid(), get_id()); if (get_proc()->complete_exit() == true) { // We are done sys.m_sched.block(THR_ST_ZOMBIE); die(); } else { // We will reschedule ourselves to finish later sys.m_sched.block(THR_ST_STOPPED); sys.m_sched.add(this, 0); } return 0; } /* The running thread must end */ else if (get_proc()->m_state == PROC_ST_EXITING) { //kinfo("Destroy process %d, %d\n", get_pid(), get_id()); sys.m_sched.block(THR_ST_ZOMBIE); die(); return 0; } else if (get_proc()->m_state == PROC_ST_STOPPED) { kinfo("Stop process %d, %d\n", get_pid(), get_id()); sys.m_sched.block(THR_ST_STOPPED); return 0; } if (asynch & THREAD_ASYNCH_DESTROY) { kinfo("Destroy thread %d, %d\n", get_pid(), get_id()); sys.m_sched.block(THR_ST_ZOMBIE); die(); return 0; } else if (asynch & THREAD_ASYNCH_SIGNAL) { handle_signal(); } return 0; }
int ufork(){ PROC *p; int i, child; u16 segment; /*** get a PROC for child process: **/ if ( (p = get_proc(&freeList)) == NULL){ printf("no more proc\n"); return(-1); } printf("ufork\n"); /* set procs values to running and ready so we can use it */ p->status = READY; p->next = NULL; p->ppid = running->pid; p->parent = running; p->priority = running->priority; /* zero out kstack registers*/ for (i = 1; i < 10; i++) { p->kstack[SSIZE -i] = 0; } // set address to resume to p->kstack[SSIZE -1] =(int)goUmode; p->ksp = &(p->kstack[SSIZE-9]); // set segment to processes data position segment = (p->pid + 1)*0x1000; // copy the segment copy_image(segment); printf("loaded at %u\n", segment); // clean the registers and set flag and uCs and uDs to runnings values for (i = 1; i < 13; i++) { child = 0x1000 - i*2; switch(i){ case 1: put_word(segment, segment, child); break; case 2: put_word(segment, segment, child); break; case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: put_word(0,segment, child); break; case 11: case 12: put_word(segment, segment, child); break; } } // same as kfork p->uss = segment; p->usp = 0x1000 - 24; put_word(0, segment, p->usp + 8*2); printf("Proc%d forked a child %d segment=%x\n", running->pid,p->pid,segment); enqueue(&readyQueue, p); nproc++; return(p->pid); }
int ServerProcess::cimserver_kill(int id) { FILE *pid_file; pid_t pid = 0; // open the file containing the CIMServer process ID pid_file = fopen(getPIDFileName(), "r"); if (!pid_file) { return (-1); } // get the pid from the file fscanf(pid_file, "%d\n", &pid); fclose(pid_file); if (pid == 0) { System::removeFile(getPIDFileName()); return (-1); } // // kill the process if it is still alive // #if defined(PEGASUS_OS_HPUX) struct pst_status pstru; int ret_code; ret_code = pstat_getproc(&pstru, sizeof(struct pst_status), (size_t)0, pid); if ( (ret_code != -1 ) && (strcmp(pstru.pst_ucomm, getProcessName())) == 0) { // cimserver is running, kill the process kill(pid, SIGKILL); } #endif #if defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) if (get_proc(pid) != -1 ) { kill(pid, SIGKILL); } #endif #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) if (isProcRunning(pid)) { kill(pid, SIGKILL); } #endif #if defined(PEGASUS_OS_AIX) if (!aixcimsrvrunning(pid, getProcessName())) kill(pid,SIGKILL); #endif // remove the file System::removeFile(getPIDFileName()); return(0); }
static int ext2_mountroot() { #if !defined(__FreeBSD__) extern struct vnode *rootvp; #endif register struct ext2_sb_info *fs; register struct mount *mp; #if defined(__FreeBSD__) struct proc *p = curproc; #else struct proc *p = get_proc(); /* XXX */ #endif struct ufsmount *ump; u_int size; int error; /* * Get vnodes for swapdev and rootdev. */ if (bdevvp(swapdev, &swapdev_vp) || bdevvp(rootdev, &rootvp)) panic("ext2_mountroot: can't setup bdevvp's"); mp = bsd_malloc((u_long)sizeof(struct mount), M_MOUNT, M_WAITOK); bzero((char *)mp, (u_long)sizeof(struct mount)); mp->mnt_op = &ext2fs_vfsops; mp->mnt_flag = MNT_RDONLY; if (error = ext2_mountfs(rootvp, mp, p)) { bsd_free(mp, M_MOUNT); return (error); } if (error = vfs_lock(mp)) { (void)ext2_unmount(mp, 0, p); bsd_free(mp, M_MOUNT); return (error); } #if defined(__FreeBSD__) CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list); #else TAILQ_INSERT_TAIL(&mountlist, mp, mnt_list); #endif mp->mnt_flag |= MNT_ROOTFS; mp->mnt_vnodecovered = NULLVP; ump = VFSTOUFS(mp); fs = ump->um_e2fs; bzero(fs->fs_fsmnt, sizeof(fs->fs_fsmnt)); fs->fs_fsmnt[0] = '/'; bcopy((caddr_t)fs->fs_fsmnt, (caddr_t)mp->mnt_stat.f_mntonname, MNAMELEN); (void) copystr(ROOTNAME, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size); bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size); (void)ext2_statfs(mp, &mp->mnt_stat, p); vfs_unlock(mp); inittodr(fs->s_es->s_wtime); /* this helps to set the time */ return (0); }