Ejemplo n.º 1
0
Archivo: env.c Proyecto: ren85/jos2006
//
// 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);
}
Ejemplo n.º 2
0
//
// 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);
}
Ejemplo n.º 3
0
//
// 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);
}
Ejemplo n.º 4
0
Archivo: env.c Proyecto: ichaos/jos
//
// 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");
}
Ejemplo n.º 5
0
Archivo: env.c Proyecto: mainboy/xv6
//
// 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);
}
Ejemplo n.º 6
0
//
// 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
}
Ejemplo n.º 7
0
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.
}
Ejemplo n.º 8
0
Archivo: env.c Proyecto: gzs715/JOS
//
// 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);
	
}
Ejemplo n.º 9
0
//
// 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 ;
}
Ejemplo n.º 10
0
Archivo: env.c Proyecto: kay21s/JOS-Lab
//
// 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)
{
	// LAB 3: Your code here.
	struct Env *env;
	switch(env_alloc(&env, 0))
	{
		case -E_NO_FREE_ENV:
			panic("All NENVS environments are allocated\n");
			return;
		case -E_NO_MEM:
			panic("No memory\n");
			return;
		default:
			break;
	}

	env->env_status = ENV_RUNNABLE;
	load_icode(env, binary, size);
}
Ejemplo n.º 11
0
int
do_execve(const char *filename, const char **argv, const char **envp) {
    static_assert(EXEC_MAX_ARG_LEN >= FS_MAX_FPATH_LEN);
    
    struct mm_struct *mm = current->mm;

    char local_name[PROC_NAME_LEN + 1];
    memset(local_name, 0, sizeof(local_name));

    char *kargv[EXEC_MAX_ARG_NUM], *kenvp[EXEC_MAX_ENV_NUM];
    const char *path;

    int ret = -E_INVAL;
    lock_mm(mm);
#if 0
    if (name == NULL) {
        snprintf(local_name, sizeof(local_name), "<null> %d", current->pid);
    }
    else {
        if (!copy_string(mm, local_name, name, sizeof(local_name))) {
            unlock_mm(mm);
            return ret;
        }
    }
#endif
    snprintf(local_name, sizeof(local_name), "<null> %d", current->pid);

    int argc = 0, envc = 0;
    if ((ret = copy_kargv(mm, kargv, argv, EXEC_MAX_ARG_NUM, &argc)) != 0) {
      unlock_mm(mm);
      return ret;
    }
    if ((ret = copy_kargv(mm, kenvp, envp, EXEC_MAX_ENV_NUM, &envc)) != 0) {
      unlock_mm(mm);
      put_kargv(argc, kargv);
      return ret;
    }

#if 0
    int i;
    kprintf("## fn %s\n", filename);
    kprintf("## argc %d\n", argc);
    for(i=0;i<argc;i++)
      kprintf("## %08x %s\n", kargv[i], kargv[i]);
    kprintf("## envc %d\n", envc);
    for(i=0;i<envc;i++)
      kprintf("## %08x %s\n", kenvp[i], kenvp[i]);
#endif
    //path = argv[0];
    //copy_from_user (mm, &path, argv, sizeof (char*), 0);
    path = filename;
    unlock_mm(mm);

    /* linux never do this */
    //fs_closeall(current->fs_struct);

    /* sysfile_open will check the first argument path, thus we have to use a user-space pointer, and argv[0] may be incorrect */

    int fd;
    if ((ret = fd = sysfile_open(path, O_RDONLY)) < 0) {
      goto execve_exit;
    }

    if (mm != NULL) {
      mm->lapic = -1;
      mp_set_mm_pagetable(NULL);
      if (mm_count_dec(mm) == 0) {
        exit_mmap(mm);
        put_pgdir(mm);
        bool intr_flag;
        local_intr_save(intr_flag);
        {
          list_del(&(mm->proc_mm_link));
        }
            local_intr_restore(intr_flag);
            mm_destroy(mm);
        }
        current->mm = NULL;
    }
    put_sem_queue(current);

    ret = -E_NO_MEM;
    /* init signal */
    put_sighand(current);
    if ((current->signal_info.sighand = sighand_create()) == NULL) {
      goto execve_exit;
    }
    sighand_count_inc(current->signal_info.sighand);

    put_signal(current);
    if ((current->signal_info.signal = signal_create()) == NULL) {
      goto execve_exit;
    }
    signal_count_inc(current->signal_info.signal);

    if ((current->sem_queue = sem_queue_create()) == NULL) {
      goto execve_exit;
    }
    sem_queue_count_inc(current->sem_queue);

    if ((ret = load_icode(fd, argc, kargv, envc, kenvp)) != 0) {
      goto execve_exit;
    }

    set_proc_name(current, local_name);

	if (do_execve_arch_hook (argc, kargv) < 0)
		goto execve_exit;
	
    put_kargv(argc, kargv);
    return 0;

execve_exit:
    put_kargv(argc, kargv);
    put_kargv(envc, kenvp);
/* exec should return -1 if failed */
    //return ret;
    do_exit(ret);
    panic("already exit: %e.\n", ret);
}