static void _process_dispose_thread_map(uint32_t pid) { // Unmap thread map uintptr_t thread_map = MEMORY_THREAD_MAP_VADDR + pid * THREAD_MAP_SIZE; size_t offset = 0; for (offset = 0; offset < THREAD_MAP_SIZE; offset += 0x1000) { uintptr_t phys = memory_physical(thread_map + offset); memory_unmap(thread_map + offset); frame_free(phys); } }
static void loadsection(FILE *f, unsigned f_offset, unsigned f_len, memory_t *m, uint32_t m_addr, size_t m_len, elf_info_t *info) { memory_ensure_mapped_range(m, m_addr, m_len); info->section_start[info->nsections] = m_addr; info->section_size[info->nsections++] = m_len; assert(info->nsections < sizeof info->section_start / sizeof(unsigned)); /* * We clear memory so that BBS doesn't need special * initialization */ void *buf = memory_physical(m, m_addr, m_len); fseek(f, f_offset, SEEK_SET); memset(buf, 0, m_len); fread(buf, f_len, 1, f); }
void stack_resize(stack_t *stack, uintptr_t new_len, process_t *process) { // Check address space if (UNLIKELY(process->addr_space != memory_space_get())) PANIC("Failed trying to resize a stack for a process while not being in " "its address space."); // Greater than maximum length? if (UNLIKELY(new_len > STACK_LENGTH_MAX)) PANIC("Failed trying to increase a stack's size over the maximum stack " "size."); // Size increased or decreased? if (new_len > stack->length) { // Increased // Map region uintptr_t reg_end = stack->address - stack->length; uintptr_t reg_addr; uint16_t flags = PAGE_FLAG_WRITEABLE | PAGE_FLAG_USER; for (reg_addr = stack->address - new_len; reg_addr < reg_end; reg_addr += PAGE_SIZE) { uintptr_t phys = frame_alloc(); memory_map(reg_addr, phys, flags); } } else if (new_len < stack->length) { // Unmap region uintptr_t reg_end = stack->address - new_len; uintptr_t reg_addr; for (reg_addr = stack->address - stack->length; reg_addr < reg_end; reg_addr += 0x1000) { uintptr_t phys = memory_physical(reg_addr); memory_unmap(reg_addr); frame_free(phys); } } // Set new size stack->length = new_len; }