// Allocate a new environment. // Returns envid of new environment, or < 0 on error. Errors are: // -E_NO_FREE_ENV if no free environment is available. // -E_NO_MEM on memory exhaustion. static envid_t sys_exofork(void) { // Create the new environment with env_alloc(), from kern/env.c. // It should be left as env_alloc created it, except that // status is set to ENV_NOT_RUNNABLE, and the register set is copied // from the current environment -- but tweaked so sys_exofork // will appear to return 0. // LAB 4: Your code here. struct Env *newenv_store; uint32_t result = 0; result= env_alloc(&newenv_store, curenv->env_id); if(result != 0) return result; //cprintf("curenv->env_id [%d], newenv_store->env_parent_id [%d], newenv_store->env_id [%d]\n",curenv->env_id, newenv_store->env_parent_id,newenv_store->env_id); newenv_store->env_status = ENV_NOT_RUNNABLE; newenv_store->env_tf = curenv->env_tf; newenv_store->env_tf.tf_regs.reg_rax = 0x00; return newenv_store->env_id; //panic("sys_exofork not implemented"); }
// Allocate a new environment. // Returns envid of new environment, or < 0 on error. Errors are: // -E_NO_FREE_ENV if no free environment is available. // -E_NO_MEM on memory exhaustion. static envid_t sys_exofork(void) { // Create the new environment with env_alloc(), from kern/env.c. // It should be left as env_alloc created it, except that // status is set to ENV_NOT_RUNNABLE, and the register set is copied // from the current environment -- but tweaked so sys_exofork // will appear to return 0. // LAB 4: Your code here. struct Env *e; if(env_alloc(&e,curenv->env_id)<0) return -E_NO_FREE_ENV; else { e->env_status = ENV_NOT_RUNNABLE; e->env_tf=curenv->env_tf; //when child env runs value of e e->env_tf.tf_regs.reg_eax=0; return e->env_id; } //panic("sys_exofork not implemented"); }
// Allocate a new environment. // Returns envid of new environment, or < 0 on error. Errors are: // -E_NO_FREE_ENV if no free environment is available. // -E_NO_MEM on memory exhaustion. static envid_t sys_exofork(void) { // Create the new environment with env_alloc(), from kern/env.c. // It should be left as env_alloc created it, except that // status is set to ENV_NOT_RUNNABLE, and the register set is copied // from the current environment -- but tweaked so sys_exofork // will appear to return 0. // LAB 4: Your code here. //panic("sys_exofork not implemented"); struct Env *e; int r; r = env_alloc(&e,curenv->env_id); if(r<0) return r; e->env_status = ENV_NOT_RUNNABLE; e->env_tf = curenv->env_tf; //cprintf("new env eflags is %p\n",e->env_tf.tf_eflags); //e->env_tf.tf_eflags |= FL_IF; //memmove((void *) &(e->env_tf),(const void*) &(curenv->env_tf),sizeof(struct Trapframe)); (e->env_tf).tf_regs.reg_eax = 0; //cprintf("[sys_exofork]the child eid is %d\n",e->env_id); return e->env_id; }
// Allocate a new environment. // Returns envid of new environment, or < 0 on error. Errors are: // -E_NO_FREE_ENV if no free environment is available. // -E_NO_MEM on memory exhaustion. static envid_t sys_exofork(void) { // Create the new environment with env_alloc(), from kern/env.c. // It should be left as env_alloc created it, except that // status is set to ENV_NOT_RUNNABLE, and the register set is copied // from the current environment -- but tweaked so sys_exofork // will appear to return 0. // LAB 4: Your code here. cprintf("DEBUG sys_exofork() called\n"); struct Env * e; int err = env_alloc(&e, curenv->env_id); if (err) { cprintf("1 err %d", err); return err; } e->env_status = ENV_NOT_RUNNABLE; e->env_tf = curenv->env_tf; e->env_tf.tf_regs.reg_eax = 0; //tweak return e->env_id; //panic("sys_exofork not implemented"); }
// Allocate a new environment. // Returns envid of new environment, or < 0 on error. Errors are: // -E_NO_FREE_ENV if no free environment is available. static envid_t sys_exofork(void) { // Create the new environment with env_alloc(), from kern/env.c. // It should be left as env_alloc created it, except that // status is set to ENV_NOT_RUNNABLE, and the register set is copied // from the current environment -- but tweaked so sys_exofork // will appear to return 0. // LAB 4: Your code here. //cprintf("in kern/sys_exofork\n"); envid_t parent_id = sys_getenvid(); struct Env* envn; int ret = env_alloc(&envn, parent_id); if(ret!=0 || !envn){ cprintf("sys_exofork : env_alloc failed.\n"); return -E_NO_FREE_ENV; } struct Env* penv; if(envid2env(parent_id, &penv, 1)!=0){ cprintf("sys_exofork : can't find penv.\n"); return -E_INVAL; } ret = envn->env_id; envn->env_status = ENV_NOT_RUNNABLE; envn->env_tf = penv->env_tf; envn->env_tf.tf_regs.reg_eax = 0; //cprintf("out kern/sys_exofork\n"); return ret; }
// Allocate a new environment. // Returns envid of new environment, or < 0 on error. Errors are: // -E_NO_FREE_ENV if no free environment is available. static envid_t sys_exofork(void) { // Create the new environment with env_alloc(), from kern/env.c. // It should be left as env_alloc created it, except that // status is set to ENV_NOT_RUNNABLE, and the register set is copied // from the current environment -- but tweaked so sys_exofork // will appear to return 0. // LAB 4: Your code here. struct Env *child; if (env_alloc(&child, curenv->env_id) < 0) return -E_NO_FREE_ENV; child->env_status = ENV_NOT_RUNNABLE; child->env_tf = curenv->env_tf; // install the pgfault upcall to the child child->env_pgfault_upcall = curenv->env_pgfault_upcall; // tweak the register eax of the child, // thus, the child will look like the return value // of the the system call is zero. child->env_tf.tf_regs.reg_eax = 0; // but notice that the return value of the parent // is the env id of the child return child->env_id; }
// Allocate a new environment. // Returns envid of new environment, or < 0 on error. Errors are: // -E_NO_FREE_ENV if no free environment is available. // -E_NO_MEM on memory exhaustion. static envid_t sys_exofork(void) { // Create the new environment with env_alloc(), from kern/env.c. // It should be left as env_alloc created it, except that // status is set to ENV_NOT_RUNNABLE, and the register set is copied // from the current environment -- but tweaked so sys_exofork // will appear to return 0. // LAB 4: Your code here. struct Env *e=NULL; int result; result = env_alloc(&e, thiscpu->cpu_env->env_id); if (result) { return -E_NO_FREE_ENV; } e->env_status = ENV_NOT_RUNNABLE; /* e->env_tf.tf_ds = thiscpu->cpu_env->env_tf.tf_ds; e->env_tf.tf_es = thiscpu->cpu_env->env_tf.tf_es; e->env_tf.tf_ss = thiscpu->cpu_env->env_tf.tf_ss; e->env_tf.tf_rsp = thiscpu->cpu_env->env_tf.tf_rsp; e->env_tf.tf_cs = thiscpu->cpu_env->env_tf.tf_cs; */ //cprintf("thiscpu->cpu_env->env_tf = %0x\n", thiscpu->cpu_env->env_tf); e->env_tf = thiscpu->cpu_env->env_tf; e->env_tf.tf_regs.reg_rax = 0; return e->env_id; panic("sys_exofork not implemented"); }
// Allocate a new environment. // Returns envid of new environment, or < 0 on error. Errors are: // -E_NO_FREE_ENV if no free environment is available. // -E_NO_MEM on memory exhaustion. static envid_t sys_exofork(void) { // Create the new environment with env_alloc(), from kern/env.c. // It should be left as env_alloc created it, except that // status is set to ENV_NOT_RUNNABLE, and the register set is copied // from the current environment -- but tweaked so sys_exofork // will appear to return 0. // LAB 4: Your code here. struct Env * new_env; int ret; ret = env_alloc(&new_env,curenv->env_id); //cprintf("sys_exofork ret: %d\n",ret); if(ret < 0 ) return ret; new_env->env_status = ENV_NOT_RUNNABLE; new_env->env_tf = curenv->env_tf; new_env->env_tf.tf_regs.reg_eax = 0; new_env->user= curenv->user; //cprintf("New child is born!: %08x\n",new_env->env_id); return new_env->env_id; }
// Allocate a new environment. // Returns envid of new environment, or < 0 on error. Errors are: // -E_NO_FREE_ENV if no free environment is available. // -E_NO_MEM on memory exhaustion. static envid_t sys_exofork(void) { // Create the new environment with env_alloc(), from kern/env.c. // It should be left as env_alloc created it, except that // status is set to ENV_NOT_RUNNABLE, and the register set is copied // from the current environment -- but tweaked so sys_exofork // will appear to return 0. // LAB 4: Your code here. //cprintf("In sysexofork\n"); struct Env* cur_env; int status = envid2env(0, &cur_env, 1); if(status < 0) return status; struct Env* new_env; status = env_alloc(&new_env, cur_env -> env_id); if(status < 0) return status; if((status = sys_env_set_status(new_env -> env_id, ENV_NOT_RUNNABLE)) < 0) return status; // Copy registers // Change return value to 0. Stored in the EAX register (new_env -> env_tf) = (cur_env -> env_tf); (new_env -> env_tf).tf_regs.reg_eax = 0; //cprintf("Out sysexofork %x\n", new_env -> env_id); return new_env -> env_id; //panic("sys_exofork not implemented"); }
// Allocate a new environment. // Returns envid of new environment, or < 0 on error. Errors are: // -E_NO_FREE_ENV if no free environment is available. // -E_NO_MEM on memory exhaustion. static envid_t sys_exofork(void) { // Create the new environment with env_alloc(), from kern/env.c. // It should be left as env_alloc created it, except that // status is set to ENV_NOT_RUNNABLE, and the register set is copied // from the current environment -- but tweaked so sys_exofork // will appear to return 0. // LAB 4: Your code here. /* lj */ int ret = 0; struct Env *env = NULL; if((ret = env_alloc(&env, thiscpu->cpu_env->env_id)) < 0) { return ret; } assert(env); env->env_status = ENV_NOT_RUNNABLE; env->env_tf = thiscpu->cpu_env->env_tf; env->env_tf.tf_regs.reg_eax = 0; return env->env_id; //panic("sys_exofork not implemented"); }
static envid_t sys_exofork(void) { // Create the new environment with env_alloc(), from kern/env.c. // It should be left as env_alloc created it, except that // status is set to ENV_NOT_RUNNABLE, and the register set is copied // from the current environment -- but tweaked so sys_exofork // will appear to return 0. int ret; struct Env *newenv; // cprintf("%d Exofork a child\n", curenv->env_id); if ((ret = env_alloc(&newenv, curenv->env_id)) < 0){ return ret; } // set the status to be ENV_NOT_RUNNABLE newenv->env_status = ENV_NOT_RUNNABLE; // register set newenv->env_tf = curenv->env_tf; newenv->env_tf.tf_regs.reg_eax = 0; // Lab 7 Project // memset(newenv->env_curdir, 0, ENV_PATHLEN); // strcpy(newenv->env_curdir, curenv->env_curdir); return newenv->env_id; }
// Allocate a new environment. // Returns envid of new environment, or < 0 on error. Errors are: // -E_NO_FREE_ENV if no free environment is available. static envid_t sys_exofork(void) { // Create the new environment with env_alloc(), from kern/env.c. // It should be left as env_alloc created it, except that // status is set to ENV_NOT_RUNNABLE, and the register set is copied // from the current environment -- but tweaked so sys_exofork // will appear to return 0. // LAB 4: Your code here. struct Env *new_env; int errno; if ((errno = env_alloc(&new_env, curenv->env_id)) < 0) { return errno; } new_env->env_status = ENV_NOT_RUNNABLE; new_env->env_tf = curenv->env_tf; // child process return 0 new_env->env_tf.tf_regs.reg_eax = 0; return new_env->env_id; //panic("sys_exofork not implemented"); }
// Allocate a new environment. // Returns envid of new environment, or < 0 on error. Errors are: // -E_NO_FREE_ENV if no free environment is available. // -E_NO_MEM on memory exhaustion. static envid_t sys_exofork(void) { // Create the new environment with env_alloc(), from kern/env.c. // It should be left as env_alloc created it, except that // status is set to ENV_NOT_RUNNABLE, and the register set is copied // from the current environment -- but tweaked so sys_exofork // will appear to return 0. // LAB 4: Your code here. // Lab 4 ex 7 struct Env *childEnv = NULL; if(curenv == NULL) panic("No parent env -- invalid fork"); int i = env_alloc(&childEnv,curenv->env_id); if(i == 0){ childEnv->env_status = ENV_NOT_RUNNABLE; childEnv->env_tf = curenv->env_tf; //memcpy(&childEnv->env_tf , &curenv->env_tf,sizeof(struct Trapframe)); childEnv->env_tf.tf_regs.reg_rax = 0; //return val childEnv->env_pgfault_upcall = curenv->env_pgfault_upcall; return childEnv->env_id; } else{ //panic("problem exofork"); return (envid_t)i; // E_NO_MEM } //panic("sys_exofork not implemented"); }
/* getenvp: * Build an environment string consisting of all shell variables and * their values concatenated into one string. The format is * * NAME=VALUE LF NAME=VALUE LF NAME=VALUE LF NULL * * with the limit in size being driven only by the space * available on the heap. Note that this uses malloc, and it * the responsibility of the caller to free the pointer when done. */ char * getenvp(void) { int size; char *envp, *cp; register struct s_shell *sp; size = 0; /* Get total size of the current environment vars */ for(sp = shell_vars;sp != (struct s_shell *)0;sp = sp->next) { if (sp->name != (char *)0) { size += (strlen(sp->name) + strlen(sp->val) + 2); } } if (size == 0) return((char *)0); envp = env_alloc(size+1); /* leave room for final NULL */ if (envp == 0) return((char *)0); cp = envp; for(sp = shell_vars;sp != (struct s_shell *)0;sp = sp->next) { if (sp->name != (char *)0) cp += sprintf(cp,"%s=%s\n",sp->name,sp->val); } *cp = 0; /* Append NULL after final separator */ return(envp); }
// Allocate a new environment. // Returns envid of new environment, or < 0 on error. Errors are: // -E_NO_FREE_ENV if no free environment is available. // -E_NO_MEM on memory exhaustion. static envid_t sys_exofork(void) { // Create the new environment with env_alloc(), from kern/env.c. // It should be left as env_alloc created it, except that // status is set to ENV_NOT_RUNNABLE, and the register set is copied // from the current environment -- but tweaked so sys_exofork // will appear to return 0. // LAB 4: Your code here. int ret; struct Env *newEnv; struct Env *thisEnv = curenv; if ((ret = env_alloc(&newEnv, curenv->env_id)) < 0) return ret; // Set status newEnv->env_status = ENV_NOT_RUNNABLE; // Copy over registers, but set eax to 0 memmove(&newEnv->env_tf, &curenv->env_tf, sizeof(struct Trapframe)); newEnv->env_tf.tf_regs.reg_eax = 0; return newEnv->env_id; }
// Allocate a new environment. // Returns envid of new environment, or < 0 on error. Errors are: // -E_NO_FREE_ENV if no free environment is available. // -E_NO_MEM on memory exhaustion. static envid_t sys_exofork(void) { // Create the new environment with env_alloc(), from kern/env.c. // It should be left as env_alloc created it, except that // status is set to ENV_NOT_RUNNABLE, and the register set is copied // from the current environment -- but tweaked so sys_exofork // will appear to return 0. // LAB 4: Your code here. struct Env *new_env; int return_code; return_code = env_alloc(&new_env, curenv->env_id); if (return_code < 0) { cprintf("sys_exofork: %e\n", return_code); return return_code; } new_env->env_status = ENV_NOT_RUNNABLE; memmove((void *) &new_env->env_tf, (void *) &curenv->env_tf, sizeof(struct Trapframe)); new_env->env_tf.tf_regs.reg_eax = 0; return new_env->env_id; }
// Allocate a new environment. // Returns envid of new environment, or < 0 on error. Errors are: // -E_NO_FREE_ENV if no free environment is available. // -E_NO_MEM on memory exhaustion. static envid_t sys_exofork(void) { // Create the new environment with env_alloc(), from kern/env.c. // It should be left as env_alloc created it, except that // status is set to ENV_NOT_RUNNABLE, and the register set is copied // from the current environment -- but tweaked so sys_exofork // will appear to return 0. // LAB 4: Your code here. struct Env *chld,*prnt; int ret; ret = envid2env(0, &prnt, 1); if(ret < 0){ cprintf("Envid2env error in sys_exofork \n"); return (envid_t)ret; } ret = env_alloc(&chld, prnt->env_id); if(ret < 0){ cprintf("Failed to create child \n"); return (envid_t)ret; } chld->env_status = ENV_NOT_RUNNABLE; chld->env_tf = prnt->env_tf; (chld->env_tf).tf_regs.reg_rax = 0; return (chld->env_id); // panic("sys_exofork not implemented"); }
// // Creates a new env running a specific binary. // The new env's parent ID is set to 0. // The implementation is a simple wrapper around env_alloc and load_elf. // void env_create(uint8_t *binary, size_t size) { struct Env *e; if(env_alloc(&e, 0)) panic("env_create: Environment allocation failed"); load_elf(e, binary, size); }
// // Allocates a new env and loads the named elf binary into it. // This function is ONLY called during kernel initialization, // before running the first user-mode environment. // The new env's parent ID is set to 0. // // Where does the result go? // By convention, envs[0] is the first environment allocated, so // whoever calls env_create simply looks for the newly created // environment there. void env_create(uint8_t *binary, size_t size) { // LAB 3: Your code here. if (env_alloc(&envs, 0) < 0) panic("env_create - env_alloc"); load_icode(envs, binary, size); }
// // Allocates a new env and loads the named elf binary into it. // This function is ONLY called during kernel initialization, // before running the first user-mode environment. // The new env's parent ID is set to 0. // void env_create(uint8_t *binary, size_t size) { struct Env *e; int ret = env_alloc(&e, 0); if (ret) panic("env_create: %e", ret); load_icode(e, binary, size); }
static int sys_env_lease(struct Env *src, envid_t *dst_id) { int r; struct Env *e; r = env_alloc(&e, src->env_parent_id); if (r < 0) return r; }
// // Allocates a new env with env_alloc and loads the named elf // binary into it with load_icode. // This function is ONLY called during kernel initialization, // before running the first user-mode environment. // The new env's parent ID is set to 0. // void env_create(uint8_t *binary, size_t size) { // LAB 3: Your code here. struct Env *newenv; int r; if((r = env_alloc(&newenv,0)) != 0) panic("%e\n",r); load_icode(newenv, binary, size); }
// // Allocates a new env and loads the named elf binary into it. // This function is ONLY called during kernel initialization, // before running the first user-mode environment. // The new env's parent ID is set to 0. // // Where does the result go? // By convention, envs[0] is the first environment allocated, so // whoever calls env_create simply looks for the newly created // environment there. void env_create(uint8_t *binary, size_t size) { // LAB 3: Your code here. struct Env *env; if( env_alloc(&env, 0) != 0){ cprintf("env_create env_alloc fail!!\n"); return; } load_icode(env,binary,size); }
// // Allocates a new env and loads the named elf binary into it. // This function is ONLY called during kernel initialization, // before running the first user-mode environment. // The new env's parent ID is set to 0. // // Where does the result go? // By convention, envs[0] is the first environment allocated, so // whoever calls env_create simply looks for the newly created // environment there. void env_create(uint8_t *binary, size_t size) { // LAB 3: Your code here. struct Env *nenv; //cprintf("++\n"); env_alloc(&nenv, 0); //cprintf("--\n"); load_icode(nenv, binary, size); //cprintf("%%\n"); }
// // Allocates a new env and loads the named elf binary into it. // This function is ONLY called during kernel initialization, // before running the first user-mode environment. // The new env's parent ID is set to 0. // // Where does the result go? // By convention, envs[0] is the first environment allocated, so // whoever calls env_create simply looks for the newly created // environment there. void env_create(uint8_t *binary, size_t size) { // LAB 3: Your code here struct Env *e; int r = env_alloc(&e, 0);//0 to set it // cprintf("%d \n",r); if(r<0){//failed panic("env_create failed\n"); } load_icode(e, binary, size);//load program }
void env_create(uint8_t *binary, size_t size) { struct Env *env; int r; if (!(r=env_alloc(&env, 0))) { load_icode(env, binary, size); } else { panic("Failed: %e", r); } // LAB 3: Your code here. }
// // Allocates a new env and loads the named elf binary into it. // This function is ONLY called during kernel initialization, // before running the first user-mode environment. // The new env's parent ID is set to 0. // // Where does the result go? // By convention, envs[0] is the first environment allocated, so // whoever calls env_create simply looks for the newly created // environment there. void env_create(uint8_t *binary, size_t size) { // LAB 3: Your code here. //cprintf("env begin to create\n"); struct Env * newenv; int state; if((state = env_alloc(&newenv, 0)) < 0) panic("env alloc error:%e",state); //cprintf("env create %08x\n",newenv->env_id); load_icode(newenv, binary, size); }
// // Allocates a new env and loads the named elf binary into it. // This function is ONLY called during kernel initialization, // before running the first user-mode environment. // The new env's parent ID is set to 0. // // Where does the result go? // By convention, envs[0] is the first environment allocated, so // whoever calls env_create simply looks for the newly created // environment there. void env_create(uint8_t *binary, size_t size) { // LAB 3: Your code here. struct Env *env; //cprintf("env_create start!\n"); if(env_alloc(&env, 0) != 0){ panic("env_create env_alloc fail!!\n"); } //cprintf("env_alloc success!!\n"); load_icode(env, binary, size); //cprintf("env_create end\n"); return ; }
globle void kernel_mem_init(env_ref env) { int i; env_alloc(env, MEMORY_DATA_INDEX, sizeof(struct memory_data_t)); // TODO: out of mem function get_mem_data(env)->mem_table = (struct memory_pool_t **) malloc((size_t)(sizeof(struct memory_pool_t *) *MEM_TABLE_SIZE)); assert(get_mem_data(env)->mem_table == NULL); for(i = 0; i < MEM_TABLE_SIZE; i++) get_mem_data(env)->mem_table[i] = NULL; }
// Allocate a new environment. static envid_t sys_exofork(void) { struct Env *e; if (env_alloc(&e, curenv->env_id) < 0) return -E_NO_FREE_ENV; spin_lock(&e->env_lock); assert(e->env_status == ENV_RUNNABLE); e->env_status = ENV_NOT_RUNNABLE; spin_unlock(&e->env_lock); e->env_tf = curenv->env_tf; e->env_tf.tf_regs.reg_eax = 0; /* For child */ return e->env_id; }