1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 02:57:42 +00:00

Kernel: Factor address space management out of the Process class

This patch adds Space, a class representing a process's address space.

- Each Process has a Space.
- The Space owns the PageDirectory and all Regions in the Process.

This allows us to reorganize sys$execve() so that it constructs and
populates a new Space fully before committing to it.

Previously, we would construct the new address space while still
running in the old one, and encountering an error meant we had to do
tedious and error-prone rollback.

Those problems are now gone, replaced by what's hopefully a set of much
smaller problems and missing cleanups. :^)
This commit is contained in:
Andreas Kling 2021-02-08 15:45:40 +01:00
parent b2cba3036e
commit f1b5def8fd
27 changed files with 494 additions and 404 deletions

View file

@ -59,7 +59,7 @@ OwnPtr<CoreDump> CoreDump::create(NonnullRefPtr<Process> process, const String&
CoreDump::CoreDump(NonnullRefPtr<Process> process, NonnullRefPtr<FileDescription>&& fd)
: m_process(move(process))
, m_fd(move(fd))
, m_num_program_headers(m_process->m_regions.size() + 1) // +1 for NOTE segment
, m_num_program_headers(m_process->space().region_count() + 1) // +1 for NOTE segment
{
}
@ -137,7 +137,7 @@ KResult CoreDump::write_elf_header()
KResult CoreDump::write_program_headers(size_t notes_size)
{
size_t offset = sizeof(Elf32_Ehdr) + m_num_program_headers * sizeof(Elf32_Phdr);
for (auto& region : m_process->m_regions) {
for (auto& region : m_process->space().regions()) {
Elf32_Phdr phdr {};
phdr.p_type = PT_LOAD;
@ -178,7 +178,7 @@ KResult CoreDump::write_program_headers(size_t notes_size)
KResult CoreDump::write_regions()
{
for (auto& region : m_process->m_regions) {
for (auto& region : m_process->space().regions()) {
if (region.is_kernel())
continue;
@ -258,13 +258,13 @@ ByteBuffer CoreDump::create_notes_threads_data() const
ByteBuffer CoreDump::create_notes_regions_data() const
{
ByteBuffer regions_data;
for (size_t region_index = 0; region_index < m_process->m_regions.size(); ++region_index) {
for (size_t region_index = 0; region_index < m_process->space().region_count(); ++region_index) {
ByteBuffer memory_region_info_buffer;
ELF::Core::MemoryRegionInfo info {};
info.header.type = ELF::Core::NotesEntryHeader::Type::MemoryRegionInfo;
auto& region = m_process->m_regions[region_index];
auto& region = m_process->space().regions()[region_index];
info.region_start = reinterpret_cast<uint32_t>(region.vaddr().as_ptr());
info.region_end = reinterpret_cast<uint32_t>(region.vaddr().as_ptr() + region.size());
info.program_header_index = region_index;
@ -316,7 +316,7 @@ ByteBuffer CoreDump::create_notes_segment_data() const
KResult CoreDump::write()
{
ScopedSpinLock lock(m_process->get_lock());
ScopedSpinLock lock(m_process->space().get_lock());
ProcessPagingScope scope(m_process);
ByteBuffer notes_segment = create_notes_segment_data();