예제 #1
0
static int
copy_fs(uint32_t clone_flags, struct proc_struct *proc) {
    struct fs_struct *fs_struct, *old_fs_struct = current->fs_struct;
    assert(old_fs_struct != NULL);

    if (clone_flags & CLONE_FS) {
        fs_struct = old_fs_struct;
        goto good_fs_struct;
    }

    int ret = -E_NO_MEM;
    if ((fs_struct = fs_create()) == NULL) {
        goto bad_fs_struct;
    }

    if ((ret = dup_fs(fs_struct, old_fs_struct)) != 0) {
        goto bad_dup_cleanup_fs;
    }

good_fs_struct:
    fs_count_inc(fs_struct);
    proc->fs_struct = fs_struct;
    return 0;

bad_dup_cleanup_fs:
    fs_destroy(fs_struct);
bad_fs_struct:
    return ret;
}
예제 #2
0
void
proc_init_ap(void)
{
	int lcpu_idx = pls_read(lcpu_idx);
	int lapic_id = pls_read(lapic_id);

	pls_write(idleproc, alloc_proc());
	if (idleproc == NULL) {
        panic("cannot alloc idleproc.\n");
    }

    idleproc->pid = lcpu_idx;
    idleproc->state = PROC_RUNNABLE;
	// XXX
    // idleproc->kstack = (uintptr_t)bootstack;
    idleproc->need_resched = 1;
	idleproc->tf = NULL;
    if ((idleproc->fs_struct = fs_create()) == NULL) {
        panic("create fs_struct (idleproc) failed.\n");
    }
    fs_count_inc(idleproc->fs_struct);

	char namebuf[32];
	snprintf(namebuf, 32, "idle/%d", lapic_id);
	
    set_proc_name(idleproc, namebuf);
    nr_process ++;

	pls_write(current, idleproc);

	assert(idleproc != NULL && idleproc->pid == lcpu_idx);
}
예제 #3
0
파일: proc.c 프로젝트: xuchiheng/ucore_plus
void proc_init_ap(void)
{
	int cpuid = myid();
	struct proc_struct *idle;

	idle = alloc_proc();
	if (idle == NULL) {
		panic("cannot alloc idleproc.\n");
	}

	idle->pid = cpuid;
	idle->state = PROC_RUNNABLE;
	// XXX
	// idle->kstack = (uintptr_t)bootstack;
	idle->need_resched = 1;
	idle->tf = NULL;
	if ((idle->fs_struct = fs_create()) == NULL) {
		panic("create fs_struct (idleproc) failed.\n");
	}
	fs_count_inc(idle->fs_struct);

	char namebuf[32];
	snprintf(namebuf, 32, "idle/%d", cpuid);

	set_proc_name(idle, namebuf);
	nr_process++;

	idleproc = idle;
	current = idle;

	assert(idleproc != NULL && idleproc->pid == cpuid);
}
예제 #4
0
파일: proc.c 프로젝트: liangchao1992/ucore
// proc_init - set up the first kernel thread idleproc "idle" by itself and 
//           - create the second kernel thread init_main
void proc_init(void)
{
	int i;
	int cpuid = myid();
	struct proc_struct *idle;

	spinlock_init(&proc_lock);
	list_init(&proc_list);
	list_init(&proc_mm_list);
	for (i = 0; i < HASH_LIST_SIZE; i++) {
		list_init(hash_list + i);
	}

	idle = alloc_proc();
	if (idle == NULL) {
		panic("cannot alloc idleproc.\n");
	}

	idle->pid = cpuid;
	idle->state = PROC_RUNNABLE;
	// No need to be set for kthread (no privilege switch)
	// idleproc->kstack = (uintptr_t)bootstack;
	idle->need_resched = 1;
	idle->tf = NULL;
	if ((idle->fs_struct = fs_create()) == NULL) {
		panic("create fs_struct (idleproc) failed.\n");
	}
	fs_count_inc(idle->fs_struct);

	char namebuf[32];
	snprintf(namebuf, 32, "idle/%d", cpuid);

	set_proc_name(idle, namebuf);
	nr_process++;

	idleproc = idle;
	current = idle;

	int pid = ucore_kernel_thread(init_main, NULL, 0);
	if (pid <= 0) {
		panic("create init_main failed.\n");
	}

	initproc = find_proc(pid);
	set_proc_name(initproc, "kinit");
	char *proc_init="Proc init OK";
	assert(idleproc != NULL && idleproc->pid == cpuid);
	assert(initproc != NULL && initproc->pid == sysconf.lcpu_count);
}
예제 #5
0
// proc_init - set up the first kernel thread idleproc "idle" by itself and 
//           - create the second kernel thread init_main
void
proc_init(void) {
    int i;
	int lcpu_idx = pls_read(lcpu_idx);
	int lapic_id = pls_read(lapic_id);
	int lcpu_count = pls_read(lcpu_count);

    list_init(&proc_list);
    list_init(&proc_mm_list);
    for (i = 0; i < HASH_LIST_SIZE; i ++) {
        list_init(hash_list + i);
    }

	pls_write(idleproc, alloc_proc());
    if (idleproc == NULL) {
        panic("cannot alloc idleproc.\n");
    }

    idleproc->pid = lcpu_idx;
    idleproc->state = PROC_RUNNABLE;
	// XXX
    // idleproc->kstack = (uintptr_t)bootstack;
    idleproc->need_resched = 1;
	idleproc->tf = NULL;
    if ((idleproc->fs_struct = fs_create()) == NULL) {
        panic("create fs_struct (idleproc) failed.\n");
    }
    fs_count_inc(idleproc->fs_struct);

	char namebuf[32];
	snprintf(namebuf, 32, "idle/%d", lapic_id);
	
    set_proc_name(idleproc, namebuf);
    nr_process ++;

    pls_write(current, idleproc);

    int pid = kernel_thread(init_main, NULL, 0);
    if (pid <= 0) {
        panic("create init_main failed.\n");
    }

    initproc = find_proc(pid);
    set_proc_name(initproc, "init");

    assert(idleproc != NULL && idleproc->pid == lcpu_idx);
    assert(initproc != NULL && initproc->pid == lcpu_count);
}
예제 #6
0
파일: proc.c 프로젝트: liangchao1992/ucore
void proc_init_ap(void)
{
	int cpuid = myid();
	struct proc_struct *idle;

	idle = alloc_proc();
	if (idle == NULL) {
		panic("cannot alloc idleproc.\n");
	}

	idle->pid = cpuid;
	idle->state = PROC_RUNNABLE;
	// No need to be set for kthread (no privilege switch)
	// idle->kstack = (uintptr_t)bootstack;
	idle->need_resched = 1;
	idle->tf = NULL;
	if ((idle->fs_struct = fs_create()) == NULL) {
		panic("create fs_struct (idleproc) failed.\n");
	}
	fs_count_inc(idle->fs_struct);

	char namebuf[32];
	snprintf(namebuf, 32, "idle/%d", cpuid);

	set_proc_name(idle, namebuf);
	nr_process++;

	idleproc = idle;
	current = idle;
#if 1
	int pid;
	char proc_name[32];
	if((pid = ucore_kernel_thread(krefcache_cleaner, NULL, 0)) <= 0){
		panic("krefcache_cleaner init failed.\n");
	}
	struct proc_struct* cleaner = find_proc(pid);
	snprintf(proc_name, 32, "krefcache/%d", myid());
	set_proc_name(cleaner, proc_name);
	set_proc_cpu_affinity(cleaner, myid());
	nr_process++;
#endif

	assert(idleproc != NULL && idleproc->pid == cpuid);
}