Compare commits
No commits in common. "613f8170b6c4ea783d9aa59a7e5a6cd6101d3d2b" and "a002e75725b8143723d80b4ef9f799ca9856d331" have entirely different histories.
613f8170b6
...
a002e75725
@ -17,7 +17,6 @@
|
||||
#define SYS_seek 12
|
||||
#define SYS_exec 13
|
||||
#define SYS_fcntl 14
|
||||
#define SYS_mprotect 15
|
||||
|
||||
namespace Syscall
|
||||
{
|
||||
@ -33,12 +32,11 @@ void sys_write(Context* context, int fd, size_t size, const char* addr);
|
||||
void sys_paint(Context* context, uint64_t x, uint64_t y, uint64_t w, uint64_t h, uint64_t col);
|
||||
void sys_rand(Context* context);
|
||||
void sys_gettid(Context* context);
|
||||
void sys_mmap(Context* context, void* address, size_t size, int prot);
|
||||
void sys_mmap(Context* context, void* address, size_t size, int flags);
|
||||
void sys_munmap(Context* context, void* address, size_t size);
|
||||
void sys_open(Context* context, const char* filename, int flags);
|
||||
void sys_read(Context* context, int fd, size_t size, char* buffer);
|
||||
void sys_close(Context* context, int fd);
|
||||
void sys_seek(Context* context, int fd, long offset, int whence);
|
||||
void sys_exec(Context* context, const char* pathname);
|
||||
void sys_fcntl(Context* context, int fd, int command, uintptr_t arg);
|
||||
void sys_mprotect(Context* context, void* address, size_t size, int prot);
|
||||
void sys_fcntl(Context* context, int fd, int command, uintptr_t arg);
|
@ -1,7 +1,7 @@
|
||||
#define MODULE "gdt"
|
||||
|
||||
#include "gdt/GDT.h"
|
||||
#include "kassert.h"
|
||||
#include "assert.h"
|
||||
#include "log/Log.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "std/string.h"
|
||||
|
@ -1,12 +1,12 @@
|
||||
#define MODULE "init"
|
||||
|
||||
#include "init/Init.h"
|
||||
#include "assert.h"
|
||||
#include "bootboot.h"
|
||||
#include "cpu/CPU.h"
|
||||
#include "init/InitRD.h"
|
||||
#include "interrupts/Interrupts.h"
|
||||
#include "io/Serial.h"
|
||||
#include "kassert.h"
|
||||
#include "log/Log.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "memory/PMM.h"
|
||||
|
@ -1,10 +1,10 @@
|
||||
#define MODULE "isr"
|
||||
|
||||
#include "assert.h"
|
||||
#include "interrupts/Context.h"
|
||||
#include "interrupts/IRQ.h"
|
||||
#include "interrupts/Interrupts.h"
|
||||
#include "io/Serial.h"
|
||||
#include "kassert.h"
|
||||
#include "log/Log.h"
|
||||
#include "misc/hang.h"
|
||||
#include "panic/Panic.h"
|
||||
|
@ -1,7 +1,7 @@
|
||||
#define MODULE "idt"
|
||||
|
||||
#include "interrupts/IDT.h"
|
||||
#include "kassert.h"
|
||||
#include "assert.h"
|
||||
#include "log/Log.h"
|
||||
|
||||
struct IDTEntry
|
||||
|
@ -1,6 +1,7 @@
|
||||
#define MODULE "main"
|
||||
|
||||
#include "acpi/RSDT.h"
|
||||
#include "assert.h"
|
||||
#include "config.h"
|
||||
#include "cpu/CPU.h"
|
||||
#include "fs/VFS.h"
|
||||
@ -14,7 +15,6 @@
|
||||
#include "io/PCI.h"
|
||||
#include "io/PIC.h"
|
||||
#include "io/Serial.h"
|
||||
#include "kassert.h"
|
||||
#include "log/Log.h"
|
||||
#include "memory/AddressSpace.h"
|
||||
#include "memory/Memory.h"
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "log/Log.h"
|
||||
#endif
|
||||
|
||||
#include "kassert.h"
|
||||
#include "assert.h"
|
||||
#include "memory/KernelHeap.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "memory/PMM.h"
|
||||
|
@ -1,8 +1,8 @@
|
||||
#define MODULE "mem"
|
||||
|
||||
#include "memory/PMM.h"
|
||||
#include "assert.h"
|
||||
#include "bootboot.h"
|
||||
#include "kassert.h"
|
||||
#include "memory/Memory.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "misc/utils.h"
|
||||
|
@ -1,7 +1,7 @@
|
||||
#define MODULE "vmm"
|
||||
|
||||
#include "memory/VMM.h"
|
||||
#include "kassert.h"
|
||||
#include "assert.h"
|
||||
#include "log/Log.h"
|
||||
#include "memory/PMM.h"
|
||||
#include "misc/utils.h"
|
||||
|
@ -1,7 +1,7 @@
|
||||
#define MODULE "rand"
|
||||
|
||||
#include "rand/Mersenne.h"
|
||||
#include "kassert.h"
|
||||
#include "assert.h"
|
||||
#include <stddef.h>
|
||||
|
||||
typedef uint64_t word_t;
|
||||
|
@ -26,7 +26,6 @@ void Syscall::entry(Context* context)
|
||||
case SYS_seek: sys_seek(context, (int)context->rdi, (long)context->rsi, (int)context->rdx); break;
|
||||
case SYS_exec: sys_exec(context, (const char*)context->rdi); break;
|
||||
case SYS_fcntl: sys_fcntl(context, (int)context->rdi, (int)context->rsi, context->rdx); break;
|
||||
case SYS_mprotect: sys_mprotect(context, (void*)context->rdi, context->rsi, (int)context->rdx); break;
|
||||
default: context->rax = -ENOSYS; break;
|
||||
}
|
||||
VMM::exit_syscall_context();
|
||||
|
@ -1,10 +1,10 @@
|
||||
#define MODULE "elf"
|
||||
|
||||
#include "sys/elf/ELFLoader.h"
|
||||
#include "assert.h"
|
||||
#include "errno.h"
|
||||
#include "fs/VFS.h"
|
||||
#include "init/InitRD.h"
|
||||
#include "kassert.h"
|
||||
#include "log/Log.h"
|
||||
#include "memory/Memory.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
|
@ -1,8 +1,8 @@
|
||||
#define MODULE "exec"
|
||||
|
||||
#include "assert.h"
|
||||
#include "errno.h"
|
||||
#include "interrupts/Interrupts.h"
|
||||
#include "kassert.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "memory/PMM.h"
|
||||
#include "memory/VMM.h"
|
||||
|
@ -8,30 +8,9 @@
|
||||
#include "misc/utils.h"
|
||||
#include <stddef.h>
|
||||
|
||||
#define MAP_READ 1
|
||||
#define MAP_WRITE 2
|
||||
#define MAP_NONE 0
|
||||
|
||||
#define MAP_FAIL(errno) 0xffffffffffffff00 | (unsigned char)(errno)
|
||||
|
||||
static const char* format_prot(int prot)
|
||||
{
|
||||
static char prot_string[3];
|
||||
prot_string[2] = 0;
|
||||
prot_string[0] = ((prot & MAP_READ) > 0) ? 'r' : '-';
|
||||
prot_string[1] = ((prot & MAP_WRITE) > 0) ? 'w' : '-';
|
||||
return prot_string;
|
||||
}
|
||||
|
||||
static int mman_flags_from_prot(int prot)
|
||||
{
|
||||
prot &= 0b11;
|
||||
if (prot == MAP_NONE) return 0;
|
||||
if ((prot & MAP_WRITE) > 0) return MAP_USER | MAP_READ_WRITE;
|
||||
return MAP_USER;
|
||||
}
|
||||
|
||||
void sys_mmap(Context* context, void* address, size_t size, int prot)
|
||||
void sys_mmap(Context* context, void* address, size_t size, int flags)
|
||||
{
|
||||
if (size < PAGE_SIZE)
|
||||
{
|
||||
@ -45,10 +24,12 @@ void sys_mmap(Context* context, void* address, size_t size, int prot)
|
||||
context->rax = MAP_FAIL(EINVAL);
|
||||
return;
|
||||
}
|
||||
int real_flags = mman_flags_from_prot(prot);
|
||||
int real_flags = MAP_USER;
|
||||
if (flags & MAP_READ_WRITE) real_flags |= MAP_READ_WRITE;
|
||||
if (address)
|
||||
{
|
||||
kdbgln("mmap(): %ld pages at address %p, %s", size / PAGE_SIZE, address, format_prot(prot));
|
||||
kdbgln("mmap(): %ld pages at address %p, %s", size / PAGE_SIZE, address,
|
||||
real_flags & MAP_READ_WRITE ? "rw" : "ro");
|
||||
if (VMM::get_physical((uint64_t)address) != (uint64_t)-1) // Address is already used.
|
||||
{
|
||||
kwarnln("attempt to map an already mapped address");
|
||||
@ -71,7 +52,8 @@ void sys_mmap(Context* context, void* address, size_t size, int prot)
|
||||
return;
|
||||
}
|
||||
}
|
||||
kdbgln("mmap(): %ld pages at any address, %s", Utilities::get_blocks_from_size(PAGE_SIZE, size), format_prot(prot));
|
||||
kdbgln("mmap(): %ld pages at any address, %s", Utilities::get_blocks_from_size(PAGE_SIZE, size),
|
||||
real_flags & MAP_READ_WRITE ? "rw" : "ro");
|
||||
void* result = MemoryManager::get_pages(Utilities::get_blocks_from_size(PAGE_SIZE, size), real_flags);
|
||||
if (result)
|
||||
{
|
||||
@ -120,43 +102,4 @@ void sys_munmap(Context* context, void* address, size_t size)
|
||||
kdbgln("munmap() succeeded");
|
||||
context->rax = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
void sys_mprotect(Context* context, void* address, size_t size, int prot)
|
||||
{
|
||||
kdbgln("mprotect(): attempting to protect %p with %s", address, format_prot(prot));
|
||||
|
||||
if (size < PAGE_SIZE)
|
||||
{
|
||||
kwarnln("mprotect() failed: size is too small");
|
||||
context->rax = -EINVAL;
|
||||
return;
|
||||
}
|
||||
if (size % PAGE_SIZE)
|
||||
{
|
||||
kwarnln("mprotect() failed: size is not a multiple of PAGE_SIZE");
|
||||
context->rax = -EINVAL;
|
||||
return;
|
||||
}
|
||||
if (!address)
|
||||
{
|
||||
kwarnln("mprotect() failed: attempted to unmap page 0");
|
||||
context->rax = -EINVAL;
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t flags = VMM::get_flags((uint64_t)address);
|
||||
if (!(flags & MAP_USER))
|
||||
{
|
||||
kwarnln("mprotect() failed: attempted to protect a non-existent or kernel page");
|
||||
context->rax = -EINVAL;
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t offset = (uint64_t)address % PAGE_SIZE;
|
||||
MemoryManager::protect((void*)((uint64_t)address - offset), Utilities::get_blocks_from_size(PAGE_SIZE, size),
|
||||
mman_flags_from_prot(prot));
|
||||
kdbgln("mprotect() succeeded");
|
||||
context->rax = 0;
|
||||
return;
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
#define MODULE "sched"
|
||||
|
||||
#include "thread/Scheduler.h"
|
||||
#include "assert.h"
|
||||
#include "interrupts/Interrupts.h"
|
||||
#include "kassert.h"
|
||||
#include "log/Log.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "memory/VMM.h"
|
||||
|
@ -7,9 +7,7 @@
|
||||
/* Address returned by mmap when it fails. */
|
||||
#define MAP_FAILED (void*)-1
|
||||
|
||||
#define PROT_NONE 0
|
||||
#define PROT_READ 1
|
||||
#define PROT_WRITE 2
|
||||
#define PROT_READ_WRITE 1
|
||||
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
@ -26,9 +24,6 @@ extern "C"
|
||||
* address space. */
|
||||
int munmap(void* addr, size_t size);
|
||||
|
||||
/* Protects size bytes of memory according to the prot argument. */
|
||||
int mprotect(void* addr, size_t size, int prot);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -13,7 +13,7 @@ int liballoc_unlock()
|
||||
|
||||
void* liballoc_alloc(size_t size)
|
||||
{
|
||||
void* result = mmap(NULL, size * PAGE_SIZE, PROT_READ | PROT_WRITE, 0, 0, 0);
|
||||
void* result = mmap(NULL, size * PAGE_SIZE, PROT_READ_WRITE, 0, 0, 0);
|
||||
if (result == MAP_FAILED) return 0;
|
||||
return (void*)result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user