Пример #1
0
void zero_process_structure(process_t *proc, int new_pid)
{
    if (!proc)
        return;

    proc->name[0] = 0;

    if ( new_pid < 0 )
        proc->pid = generate_pid();
    else
        proc->pid = new_pid;

    proc->ppid = -1;
    proc->page_table_base = NULL;
    proc->state = PROCESS_NONE;
    memset(&proc->registers, 0, sizeof(proc->registers));

    proc->next = NULL;
    proc->mm.vma_list = NULL;
    proc->kernel_stack = NULL;
    proc->currentDirectory = root;
    proc->homeDirectory = root;
}
Пример #2
0
void build_process_address_space(struct PCB* process)
{
	
	uint64_t entry = 0;
	uint64_t e_rsp = UXSTACKTOP;
	struct page* page_temp;
	//struct vma* vma_temp;
	//int ab=0;


	//Allocate for user pml4 table and initialize it
	//Since its in user space, will already be mapped.
	if(!process->pml4)
	{
		page_temp = page_alloc();
		if(page_temp->ref_count==1)
			printf("PANIC\n");
		memset((void *)getVA(page_temp),0,PAGE_SIZE);
		process->cr3 = (uint64_t *)getPA(page_temp);
		process->pml4 = (uint64_t *)getVA(page_temp); 

		
		//Copy 1 entry from kernel_pml4 to this pml4
		*(process->pml4 + PML4OFF(KERNBASE)) = *(kernel_pml4 + PML4OFF(KERNBASE));	
	}
	//printf("K: %x , U: %x\n", *(kernel_pml4 + PML4OFF(KERNBASE)), *(process->pml4 + PML4OFF(KERNBASE)));


	//New cr3 
	//loadcr3((void *)process->cr3);

	//ELF
	entry = getELF(process -> fileName, process);
   	//printf("entry = %x\n", entry);	
	(process -> reg).rip = entry;

	add_heap_vma(process);
	add_stack_vma(process);
	
	//AADY: 30 Apr
	if(process->processID < 0)
	{
		process -> processID = generate_pid(); 
		e_rsp = UXSTACKTOP - (process->processID * PAGE_SIZE);
		(process -> ersp) = e_rsp;
		process -> hasRan = 0; //Already done in pcb_alloc, a safety check here.
	}
	
	
	
	/*
	//TEMP: 26th APR
	//ASM to set up tss
        __asm__ __volatile__("movq %%rsp, %0; \
                movq $0x28,%%rax; \
                ltr %%ax;"
                : "=r" (tss.rsp0)
                :
                : "rax");	
	
	//tss.rsp0 = process->ersp;
	
	//ASM to set up tss    
        __asm__ __volatile__("movq $0x28,%%rax; \
                ltr %%ax;"
                : 
                :
                : "rax");
	
        //printf("tss setting: %x\n",tss.rsp0);
	*/
	
	//switch_to_user_space(entry);		
	
}