Compare commits

..

No commits in common. "a2c05de60482fc5ec0bc3af878cca11bb7c8ad67" and "593daba65153fadfa81b87c38486fc302155a197" have entirely different histories.

2 changed files with 10 additions and 35 deletions

View File

@ -11,7 +11,6 @@ Not so much at the moment.
- Can [load userspace ELF programs](kernel/src/sys/elf/) from the initial ramdisk as user tasks.
- [System call](kernel/src/sys/) interface and bare-bones [C Library](libs/libc/).
- Some very simple [example programs](apps/), written in C, that the kernel then loads from the initial ramdisk.
- UNIX-like [multitasking primitives](kernel/src/sys/exec.cpp).
## Setup
To build and run Luna, you will need to build a [GCC Cross-Compiler](https://wiki.osdev.org/Why_do_I_need_a_Cross_Compiler%3F) and cross-binutils for `x86_64-luna`. (Yes, Luna is advanced enough that it can use its own [OS-Specific Toolchain](https://wiki.osdev.org/OS_Specific_Toolchain), instead of a bare metal target like `x86_64-elf`. It is the first of my OS projects to be able to do so. The patches for Binutils and GCC are [binutils.patch](tools/binutils.patch) and [gcc.patch](tools/gcc.patch)).

View File

@ -3,7 +3,6 @@
#include "errno.h"
#include "interrupts/Context.h"
#include "log/Log.h"
#include "memory/Memory.h"
#include "memory/MemoryManager.h"
#include "memory/VMM.h"
#include "misc/utils.h"
@ -51,12 +50,6 @@ void sys_mmap(Context* context, void* address, size_t size, int prot)
if (address)
{
kdbgln("mmap(): %ld pages at address %p, %s", size / PAGE_SIZE, address, format_prot(prot));
if (Memory::is_kernel_address((uintptr_t)address))
{
kwarnln("munmap() failed: attempted to unmap a kernel page");
context->rax = MAP_FAIL(ENOMEM);
return;
}
if (VMM::get_physical((uint64_t)address) != (uint64_t)-1) // Address is already used.
{
kwarnln("attempt to map an already mapped address");
@ -74,7 +67,7 @@ void sys_mmap(Context* context, void* address, size_t size, int prot)
}
else
{
kwarnln("mmap() failed: failed to allocate physical memory");
kwarnln("mmap() failed");
context->rax = MAP_FAIL(ENOMEM);
return;
}
@ -82,12 +75,6 @@ void sys_mmap(Context* context, void* address, size_t size, int prot)
kdbgln("mmap(): %ld pages at any address, %s", Utilities::get_blocks_from_size(PAGE_SIZE, size), format_prot(prot));
uint64_t ptr =
Scheduler::current_task()->allocator.request_virtual_pages(Utilities::get_blocks_from_size(PAGE_SIZE, size));
if (!ptr)
{
kwarnln("mmap() failed: failed to allocate virtual address");
context->rax = MAP_FAIL(ENOMEM);
return;
}
void* result = MemoryManager::get_pages_at(ptr, Utilities::get_blocks_from_size(PAGE_SIZE, size), real_flags);
if (result)
{
@ -97,7 +84,7 @@ void sys_mmap(Context* context, void* address, size_t size, int prot)
}
else
{
kwarnln("mmap() failed: failed to allocate physical memory");
kwarnln("mmap() failed");
context->rax = MAP_FAIL(ENOMEM);
return;
}
@ -124,16 +111,10 @@ void sys_munmap(Context* context, void* address, size_t size)
context->rax = -EINVAL;
return;
}
if (Memory::is_kernel_address((uintptr_t)address))
uint64_t flags = VMM::get_flags((uint64_t)address);
if (!(flags & MAP_USER))
{
kwarnln("munmap() failed: attempted to unmap a kernel page");
context->rax = -EINVAL;
return;
}
uint64_t phys = VMM::get_physical((uint64_t)address);
if (phys == (uint64_t)-1)
{
kwarnln("munmap() failed: attempted to unmap a non-existent page");
kwarnln("munmap() failed: attempted to unmap a non-existent or kernel page");
context->rax = -EINVAL;
return;
}
@ -164,20 +145,15 @@ void sys_mprotect(Context* context, void* address, size_t size, int prot)
}
if (!address)
{
kwarnln("mprotect() failed: attempted to protect page 0");
kwarnln("mprotect() failed: attempted to unmap page 0");
context->rax = -EINVAL;
return;
}
if (Memory::is_kernel_address((uintptr_t)address))
uint64_t flags = VMM::get_flags((uint64_t)address);
if (!(flags & MAP_USER))
{
kwarnln("mprotect() failed: attempted to protect a kernel page");
context->rax = -EINVAL;
return;
}
uint64_t phys = VMM::get_physical((uint64_t)address);
if (phys == (uint64_t)-1)
{
kwarnln("mprotect() failed: attempted to protect a non-existent page");
kwarnln("mprotect() failed: attempted to protect a non-existent or kernel page");
context->rax = -EINVAL;
return;
}