void modules_init(multiboot_info_t * multiboot_info) { printf("[ "MODULE_NAME" ] loading multiboot modules\n"); uint32 i; void * proc_mem; module_t *modules = (module_t *)multiboot_info->mods_addr; for (i = 0; i < multiboot_info->mods_count; i++) { /** ELF EXEC */ /* if (*((char *)(modules[i].mod_start)) == 0x7f) { elf_dump(modules[i].mod_start); printf("%s ", modules[i].string); elf_exec(modules[i].string, modules[i].mod_start, modules[i].mod_end - modules[i].mod_start); continue; } */ //printf(" %s\n", modules[i].string); proc_mem = proc_createenv(modules[i].mod_end - modules[i].mod_start); memcpy(get_physical_address(proc_mem, KERNEL_MEMORY), modules[i].mod_start, modules[i].mod_end - modules[i].mod_start); proc_add(modules[i].string, PROC_CLASS_A, proc_mem, modules[i].mod_end - modules[i].mod_start, KERNEL_MEMORY); } }
/* * fork() support. * * It creates new process data and update all process relations. * The task creation and the thread creation are done by the * fork() library stub. */ int proc_fork(struct msg *msg) { struct proc *p; struct pgrp *pgrp; task_t child; pid_t pid; int vfork_flag; if (curproc == NULL) return EINVAL; child = (task_t)msg->data[0]; vfork_flag = msg->data[1]; DPRINTF(("fork: parent=%x child=%x vfork=%d\n", msg->hdr.task, child, vfork_flag)); if (task_to_proc(child) != NULL) return EINVAL; /* Process already exists */ if ((pid = pid_assign()) == 0) return EAGAIN; /* Too many processes */ if ((p = malloc(sizeof(struct proc))) == NULL) return ENOMEM; p->p_parent = curproc; p->p_pgrp = curproc->p_pgrp; p->p_stat = SRUN; p->p_exitcode = 0; p->p_pid = pid; p->p_task = child; list_init(&p->p_children); proc_add(p); list_insert(&curproc->p_children, &p->p_sibling); pgrp = p->p_pgrp; list_insert(&pgrp->pg_members, &p->p_pgrp_link); list_insert(&allproc, &p->p_link); if (vfork_flag) vfork_start(curproc); DPRINTF(("fork: new pid=%d\n", p->p_pid)); msg->data[0] = (int)p->p_pid; return 0; }
//respond to scheduler static int respond(int sock){ int cmd[3]; //read fixed length header info. if(streadintarr(sock, cmd, 3)){ return -1;//failed } int ihost=host_from_sock(sock); if(ihost>=0){ htime[ihost]=myclockd(); } int pid=cmd[2]; switch(cmd[0]){ case -1:{//server request shutdown info("disconnect from %s\n", hosts[ihost]); return -1; } break; case MON_VERSION: break; case MON_STATUS: { if(ihost<0){ warning("Host not found\n"); return -1; } PROC_T *p=proc_get(ihost,pid); if(!p){ p=proc_add(ihost,pid); } if(stread(sock, &p->status, sizeof(STATUS_T))){ return -1; } if(p->status.info==S_REMOVE){ proc_remove(ihost, pid); }else{ if(cmd[1]!=ihost && cmd[1]!=cmd[2]){ /*A new mean to replace the ID of a job.*/ p->pid=cmd[1]; } gdk_threads_add_idle((GSourceFunc)refresh, p); } } break; case MON_PATH: { if(ihost<0){ warning("Host not found\n"); return -1; } PROC_T *p=proc_get(ihost,pid); if(!p){ p=proc_add(ihost,pid); } if(streadstr(sock, &p->path)){ return -1; } char *tmp=NULL; while((tmp=strchr(p->path, '\n'))){ tmp[0]=' '; } } break; case MON_LOAD: { if(ihost<0){ warning("Host not found\n"); return -1; } usage_cpu[ihost]=(double)((pid>>16) & 0xFFFF)/100.; usage_mem[ihost]=(double)(pid & 0xFFFF)/100.; usage_cpu[ihost]=MAX(MIN(1,usage_cpu[ihost]),0); usage_mem[ihost]=MAX(MIN(1,usage_mem[ihost]),0); gdk_threads_add_idle((GSourceFunc)update_progress, GINT_TO_POINTER(ihost)); } break; case MON_ADDHOST: if(cmd[1]>-1 && cmd[1]<nhost){ pthread_t tmp; pthread_create(&tmp, NULL, (void*(*)(void*))add_host, GINT_TO_POINTER(cmd[1])); }else if(cmd[1]==-2){ return -2; } break; default: warning_time("Invalid cmd %d\n",cmd[0]); return -1; } return 0; }