Ejemplo n.º 1
0
/*
 * child process'in bitmesini bekle ve child process idsini dondur.
 * child process yoksa -1 dondur.
 */
SYSCALL_DEFINE1(wait, int*, state) {

	// FIXME: bunu yapan fonksiyon var ...
	if ( task_curr->pgdir.verify_user_addr(state, 4, PTE_U) < 0 ) {
		print_warning(">> wait not verified: 0x%08x - 0x%08x\n", state, state+1);
		do_exit(111);
	}
	state = (int*)uaddr2kaddr((uint32_t)state);

	pushcli();

	if (task_curr->childs.size() == 0) {
		popif();
		return set_return(tf, -1);
	}

	/* cagriyi yapan taski runnable_list'den cikar */
	remove_from_runnable_list(task_curr);
	task_curr->state = Task::State_interruptible;
	task_curr->waiting_child = 1;

	popif();

	schedule();

	task_curr->waiting_child = 0;
	Task *t = task_curr->wait_notify_next;
	ASSERT(t);
	task_curr->wait_notify_next = t->wait_notify_next;

	/* return ve state degiskenlerini ata */
	*state = t->exit_code;

	return set_return(task_curr->registers(), t->id);
}
Ejemplo n.º 2
0
SYSCALL_DEFINE1(close, unsigned int, fd) {
	pushcli();

	if (task_curr->fs.files[fd] == NULL) {
		popif();
		return SYSCALL_RETURN(-1);
	}

	file_close(task_curr->fs.files[fd]);
	task_curr->fs.files[fd] = NULL;

	popif();
	return SYSCALL_RETURN(0);
}
Ejemplo n.º 3
0
asmlink void do_exit(int code) {
	pushcli();

	if (task_curr->id == 1)
		PANIC(">> exit task 1");

	remove_from_runnable_list(task_curr);
	task_curr->state = Task::State_zombie;
	task_zombie_list.push_back(&task_curr->list_node);

	task_free(task_curr);
	task_curr->time_end = jiffies;
	task_curr->exit_code = code;

	// FIXME: ???
	if (task_curr->exit_signal == 0)
		task_curr->exit_signal = SIGCHLD;

	notify_parent(task_curr);
	print_info(">> [%d] exit OK\n", task_curr->id);

	popif();

	schedule();
	PANIC("do_exit return");
}
Ejemplo n.º 4
0
SYSCALL_DEFINE2(kill, int, pid, int, sig) {
	pushcli();

	Task *t = task_id_ht.get(pid);

	popif();

	if (t == NULL)
		return SYSCALL_RETURN(-1);

	send_signal(sig, t);
	return SYSCALL_RETURN(0);
}
Ejemplo n.º 5
0
int getline(int listflag)
/*
 * Read in a line, preprocess it, and dump it to the list and preproc files
 * Also strip comments and alter trigraphs
 */
{
    int rv, rvc, prepping, temp;
    static int inpreprocess;
    char ibuf[4096], xbuf[4096],  *xptr;
    char *ptr = ibuf;
    if (cantnewline)
    {
        return (0);
    }
    repeatit: 
    do
    {
        rv = FALSE;
        prepping = FALSE;
        rvc = 0;
//        add: 
        while (rvc + 131 < 4096 && !rv)
        {
            ++lineno;
            ++errlineno;
            rv = getstring(ibuf + rvc, 4096 - rvc, inputFile);
            if (rv)
            {
                break;
            }
            rvc = strlen(ibuf);
            if (ibuf[rvc - 1] != '\n')
            {
                ibuf[rvc++] = '\n';
                ibuf[rvc] = 0;
            }
            rvc -= 2;
            while (ibuf[rvc] == ' ')
                rvc--;
            //					if (ibuf[rvc] != '\\')
            break;
        }
        if (rvc)
            rv = FALSE;
        if (rv)
        {
            if (ifs)
                generror(ERR_PREPROCMATCH, 0);
            if (commentlevel)
                generror(ERR_COMMENTMATCH, 0);
            if (incldepth > 0)
            {
                if (inSymFile && !strcmp(infile, rcIdFile))
                    inSymFile = FALSE;
                fclose(inputFile);
                inputFile = inclfile[--incldepth];
                lineno = inclline[incldepth];
                inhfile = inclhfile[incldepth];
                infile = inclfname[incldepth];
                free(inputBuffer);
                inputBuffer = inclInputBuffer[incldepth];
                inputLen = inclInputLen[incldepth];
                ibufPtr = inclibufPtr[incldepth];
                errlineno = lineno;
                errfile = infile;
                ifs = ifshold[incldepth];
                commentlevel = 0;
                popif();
                goto repeatit;
            }
        }
        if (rv)
            return 1;
        lptr = inputline;
        ptr = ibuf;
        xptr = xbuf;
        while ((temp = *ptr++) != 0)
        {
            *lptr++ = (unsigned char)temp;
            *xptr++ = (unsigned char)temp;
        }
        *lptr = 0;
        *xptr = 0;
        stripcomment(inputline);
        lptr = inputline;
        while (iswhitespacechar(*lptr))
            lptr++;
        CacheLine((WCHAR *)lptr, xbuf);
        if (lptr[0] == '#')
        {
            inpreprocess++;
            listflag = preprocess();
            inpreprocess--;
            prepping = TRUE;
            lastst = eol;
        }
        if (incldepth)
            lastst = eol;
    }
    while (ifskip || prepping || (inhfile && !inpreprocess))
        ;
    rvc = strlen(ibuf);
    /*
    if (defcheck(inputline) ==  - 10 && rvc + 131 < 4096)
    {
        if (ibuf[rvc - 1] == '\n')
            ibuf[rvc - 1] = ' ';
        goto add;
    }
    */
    return 0;
}
Ejemplo n.º 6
0
// TODO: fork kurallari duzenlenmeli (neler kopyalanacak, neler kopyalanmayacak?)
int do_fork() {
	CLOBBERED_REGISTERS_ALL();

	/* debug only */
	uint32_t mem_before_setup_vm = 0;
	uint32_t mem_before_copy_pages = 0;
	uint32_t mem_before_kernel_stack = 0;
	/* */
	int r;
	Task *t;
	uint32_t eip;
	int e = 0; // error (bad_fork_* icin)

	pushcli();
	// ASSERT_int_disable();

	t = (Task*)kmalloc(sizeof(Task));
	if (!t)
		goto bad_fork_task_alloc;

	memcpy(t, task_curr, sizeof(Task));
	t->init();
	t->parent = task_curr;
	t->state = Task::State_not_runnable;

	/* -- */
	mem_before_setup_vm = mem_free();
	r = task_setup_vm(t, &task_curr->pgdir);
	if (r < 0)
		goto bad_fork_setup_vm;

	/* user adres uzayini kopyala */
	mem_before_copy_pages = mem_free();
	r = t->pgdir.copy_pages(&task_curr->pgdir, MMAP_USER_BASE,
							MMAP_USER_SHARED_MEM_BASE);
	if (r < 0)
		goto bad_fork_copy_vm_user;
	/* shared memory kismini kopyalama, shm_fork fonksiyonu kopyalayacak */
	r = t->pgdir.copy_pages(&task_curr->pgdir, MMAP_USER_SHARED_MEM_TOP,
							MMAP_USER_TOP);
	if (r < 0)
		goto bad_fork_copy_vm_user;
	t->pgdir.count_program = task_curr->pgdir.count_program;
	t->pgdir.count_stack = task_curr->pgdir.count_stack;
	t->pgdir.start_brk = task_curr->pgdir.start_brk;
	t->pgdir.end_brk = task_curr->pgdir.end_brk;
	/* */

	/* ipc veriyapilari icin, ipc_fork */
	r = ipc_fork(t);
	if (r < 0)
		goto bad_fork_ipc;

	r = fs_fork(t);
	if (r < 0)
		goto bad_fork_fs;

	/* kernel stackini kopyala */
	mem_before_kernel_stack = mem_free();
	r = t->pgdir.copy_pages(&task_curr->pgdir, MMAP_KERNEL_STACK_BASE, MMAP_KERNEL_STACK_TOP);
	if (r < 0)
		goto bad_fork_copy_kernel_stack;

	/* burasi 2 kere calisiyor */
	eip = read_eip();
	if (eip == 1) /* child process'de popif yapilmamali */
		return 0;

	/* child prosesin register bilgileri */
	t->k_eip = eip;
	read_reg(%esp, t->k_esp);
	read_reg(%ebp, t->k_ebp);

	/* child prosesin baslangic zamani */
	t->time_start = jiffies;


	/* child listesine ekle */
	ASSERT( task_curr->childs.push_back(&t->childlist_node) );
	/* process id ata ve runnable listesine ekle */
	set_task_id(t);
	add_to_runnable_list(t);

	popif();

	return t->id;

bad_fork_copy_kernel_stack:
	if (e++ == 0)
		print_warning("!! bad_fork_copy_kernel_stack\n");
	task_free_kernel_stack(t);
	ASSERT(mem_free() == mem_before_kernel_stack);
bad_fork_fs:
	// TODO: --
bad_fork_ipc:
	// TODO: --
bad_fork_copy_vm_user:
	if (e++ == 0)
		print_warning("!! bad_fork_copy_vm_user\n");
	task_free_vm_user(t);
	ASSERT(mem_free() == mem_before_copy_pages);
bad_fork_setup_vm:
	if (e++ == 0)
		print_warning("!! bad_fork_setup_vm\n");
	task_delete_vm(t);
	ASSERT(mem_free() == mem_before_setup_vm);
	kfree(t);
	t = NULL;
bad_fork_task_alloc:
	if (e++ == 0)
		print_warning("!! bad_fork_task_alloc\n");
	ASSERT(t == NULL);

	popif();
	return -1;
}