void DoExit (int status) { int t; struct Process *current; current = GetCurrentProcess(); current->task_state.flags |= TSF_EXIT; DisablePreemption(); for (t=0; t < max_handle; t++) CloseHandle(t); FreeAddressSpace(); ClosePendingHandles(); DisableInterrupts(); current->state = PROC_STATE_ZOMBIE; DoRaiseEvent (current->handle); SchedUnready (current); EnableInterrupts(); __KernelExit(); // FIXME: Use pragma/attribute to indicate // This __KernelExit doesn't return }
CRecompMemory::~CRecompMemory() { if (m_RecompCode) { FreeAddressSpace(m_RecompCode,MaxCompileBufferSize + 4); m_RecompCode = NULL; } m_RecompPos = NULL; }
int Fork (void) { struct Process *newproc; KPRINTF ("Fork()"); if ((newproc = AllocProcess(PROC_TYPE_USER)) != NULL) { StrLCpy (newproc->exe_name, current_process->exe_name, PROC_NAME_SZ); if (*newproc->exe_name == '\0') { KPRINTF ("Fork() exe_name == 0"); while(1) KWait(0); } if (DuplicateAddressSpace (¤t_process->as, &newproc->as) == 0) { newproc->user_as = &newproc->as; if (0 == FSCreateProcess (current_process, newproc, current_process->current_dir, DUP_FD)) { USigFork (current_process, newproc); if (ArchInitFork (newproc) == 0) { DisableInterrupts(); newproc->state = PROC_STATE_READY; newproc->priority = 0; SchedReady (newproc); Reschedule(); EnableInterrupts(); return newproc->pid; } FSExitProcess (newproc); } FreeAddressSpace (&newproc->as); } FreeProcess (newproc); } return -1; }
bool CRecompMemory::AllocateMemory() { uint8_t * RecompCodeBase = (uint8_t *)AllocateAddressSpace(MaxCompileBufferSize + 4); if (RecompCodeBase == NULL) { WriteTrace(TraceRecompiler, TraceError, "failed to allocate RecompCodeBase"); g_Notify->DisplayError(MSG_MEM_ALLOC_ERROR); return false; } m_RecompCode = (uint8_t *)CommitMemory(RecompCodeBase, InitialCompileBufferSize, MEM_EXECUTE_READWRITE); if (m_RecompCode == NULL) { WriteTrace(TraceRecompiler, TraceError, "failed to commit initial buffer"); FreeAddressSpace(RecompCodeBase,MaxCompileBufferSize + 4); g_Notify->DisplayError(MSG_MEM_ALLOC_ERROR); return false; } m_RecompSize = InitialCompileBufferSize; m_RecompPos = m_RecompCode; memset(m_RecompCode, 0, InitialCompileBufferSize); return true; }
int DuplicateAddressSpace (struct AddressSpace *src_as, struct AddressSpace *dst_as) { struct MemRegion *mr; struct Pageframe *pf; int error = 0; uint32 prot; struct AddressSpace *old_as; if (AllocDupAddressSpace (src_as, dst_as) == 0) { mr = LIST_HEAD (&dst_as->sorted_memregion_list); while (mr != NULL && error == 0) { if (mr->type == MR_TYPE_ANON) { prot = mr->prot; old_as = SwitchAddressSpace (dst_as); UProtect (mr->base_addr, VM_PROT_READWRITE); SwitchAddressSpace (old_as); /* IMPROVEMENT: * * Try to copy upto 64k (VM_TEMP_BUF_SZ) worth of linear * pages at a time, reduces number of task switches * and concentrates on inner loops */ pf = LIST_HEAD (&mr->pageframe_list); while (pf != NULL && error == 0) { error = CopyIn (src_as, (void *)vm_temp_buf, (void *)pf->virtual_addr, PAGE_SIZE); if (error == 0) error = CopyOut (dst_as, (void *)pf->virtual_addr, (void *)vm_temp_buf, PAGE_SIZE); pf = LIST_NEXT (pf, memregion_entry); } old_as = SwitchAddressSpace (dst_as); UProtect (mr->base_addr, prot); SwitchAddressSpace (old_as); } mr = LIST_NEXT (mr, sorted_entry); } if (error != 0) FreeAddressSpace (dst_as); } else error = -1; KASSERT (error != -1); return error; }