Compare commits
2 Commits
4ef764e62e
...
49d1e4f011
Author | SHA1 | Date | |
---|---|---|---|
49d1e4f011 | |||
401a807551 |
12
README.md
12
README.md
@ -1,18 +1,6 @@
|
|||||||
# Luna
|
# Luna
|
||||||
A simple kernel and userspace for the x86_64 platform, written mostly in C++ and C.
|
A simple kernel and userspace for the x86_64 platform, written mostly in C++ and C.
|
||||||
|
|
||||||
## WARNING
|
|
||||||
This branch is no longer actively updated. I have started rewriting the kernel for three different reasons:
|
|
||||||
|
|
||||||
- To switch to CMake, which is a lot more convenient than manually writing Makefiles.
|
|
||||||
- The code in this branch is so unportable that it doesn't have ANY hope of moving outside x86_64. I wanted to change that.
|
|
||||||
- To start fresh without my 3-month-old bad code, with a new way of doing things, kind of inspired by my recent adventures with the Rust programming language (it's still C++ though, I found Rust to be too limiting for kernel development).
|
|
||||||
|
|
||||||
The code for this rewrite can be found in the [restart](https://git.cloudapio.eu/apio/Luna/src/branch/restart) branch.
|
|
||||||
The changes in this branch will be merged as soon as the rewrite has reached a level of functionality similar to the `main` branch.
|
|
||||||
|
|
||||||
Until then, this version of Luna will stay in the `main` branch, although not actively developed.
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
- x86_64-compatible [kernel](kernel/).
|
- x86_64-compatible [kernel](kernel/).
|
||||||
- Keeps track of which [memory](kernel/src/memory/) is used and which memory is free, and can allocate memory for itself and [user programs](kernel/src/sys/mem.cpp).
|
- Keeps track of which [memory](kernel/src/memory/) is used and which memory is free, and can allocate memory for itself and [user programs](kernel/src/sys/mem.cpp).
|
||||||
|
@ -45,10 +45,10 @@ uint64_t Memory::get_usable()
|
|||||||
|
|
||||||
bool Memory::is_kernel_address(uintptr_t address)
|
bool Memory::is_kernel_address(uintptr_t address)
|
||||||
{
|
{
|
||||||
return address >= 0xffff800000000000;
|
return address >= 0xfffffffff8000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Memory::is_user_address(uintptr_t address)
|
bool Memory::is_user_address(uintptr_t address)
|
||||||
{
|
{
|
||||||
return address && address < 0x00007fffffffffff;
|
return address && address < 0xfffffffff8000000;
|
||||||
}
|
}
|
@ -55,9 +55,9 @@ void sys_mmap(Context* context, void* address, size_t size, int prot, int fd, of
|
|||||||
if (address)
|
if (address)
|
||||||
{
|
{
|
||||||
kdbgln("mmap(): %ld pages at address %p, %s, fd %d", size / PAGE_SIZE, address, format_prot(prot), fd);
|
kdbgln("mmap(): %ld pages at address %p, %s, fd %d", size / PAGE_SIZE, address, format_prot(prot), fd);
|
||||||
if (!Memory::is_user_address((uintptr_t)address))
|
if (Memory::is_kernel_address((uintptr_t)address))
|
||||||
{
|
{
|
||||||
kwarnln("mmap() failed: attempted to map a non-user page");
|
kwarnln("munmap() failed: attempted to unmap a kernel page");
|
||||||
context->rax = MAP_FAIL(ENOMEM);
|
context->rax = MAP_FAIL(ENOMEM);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -153,9 +153,9 @@ void sys_munmap(Context* context, void* address, size_t size)
|
|||||||
context->rax = -EINVAL;
|
context->rax = -EINVAL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!Memory::is_user_address((uintptr_t)address))
|
if (Memory::is_kernel_address((uintptr_t)address))
|
||||||
{
|
{
|
||||||
kwarnln("munmap() failed: attempted to unmap a non-user page");
|
kwarnln("munmap() failed: attempted to unmap a kernel page");
|
||||||
context->rax = -EINVAL;
|
context->rax = -EINVAL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -202,16 +202,9 @@ void sys_mprotect(Context* context, void* address, size_t size, int prot)
|
|||||||
context->rax = -EINVAL;
|
context->rax = -EINVAL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!Memory::is_user_address((uintptr_t)address))
|
if (Memory::is_kernel_address((uintptr_t)address))
|
||||||
{
|
{
|
||||||
kwarnln("mprotect() failed: attempted to protect a non-user page");
|
kwarnln("mprotect() failed: attempted to protect a kernel page");
|
||||||
context->rax = -EINVAL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// FIXME: Check for overflow when adding address + size.
|
|
||||||
if (!Memory::is_user_address((uintptr_t)address + size))
|
|
||||||
{
|
|
||||||
kwarnln("mprotect() failed: end of given range is out of user memory");
|
|
||||||
context->rax = -EINVAL;
|
context->rax = -EINVAL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user