[kernel] Change VMA syscall addr param to inout

This change allows the `vma_map` and `vma_create_map` syscalls to map to
addresses other than the one specified, and therefore makes the address
parameter to those syscalls `inout` in order to return the mapped
address.

Also add the `exact` flag for specifying that mapping needs to be done
at the exact address given. If the mapping collides with another, the
new `j6_err_collision` error is returned.
This commit is contained in:
Justin C. Miller
2023-08-31 19:40:02 -07:00
parent 8cbde13139
commit fc16ed54b3
16 changed files with 93 additions and 69 deletions

View File

@@ -56,7 +56,7 @@ channel::create(size_t size)
channel_addr += size * 2; // account for ring buffer virtual space doubling
lock.release();
result = j6_vma_create_map(&vma, size, addr, j6_vm_flag_write|j6_vm_flag_ring);
result = j6_vma_create_map(&vma, size, &addr, j6_vm_flag_write|j6_vm_flag_ring);
if (result != j6_status_ok) {
syslog("Failed to create channel VMA. Error: %lx", result);
return nullptr;
@@ -77,7 +77,7 @@ channel::open(j6_handle_t vma)
util::scoped_lock lock {addr_spinlock};
uintptr_t addr = channel_addr;
result = j6_vma_map(vma, 0, addr);
result = j6_vma_map(vma, 0, &addr, 0);
if (result != j6_status_ok) {
syslog("Failed to map channel VMA. Error: %lx", result);
return nullptr;

View File

@@ -24,4 +24,5 @@
#define j6_err_insufficient j6_err(0x0005)
#define j6_err_timed_out j6_err(0x0006)
#define j6_err_denied j6_err(0x0007)
#define j6_err_collision j6_err(0x0008)

View File

@@ -12,5 +12,5 @@ enum j6_vm_flags {
enum j6_flags {
j6_flag_block = 0x01,
j6_flags_COUNT // custom per-type flags should start here
j6_flags_MAX // custom per-type flags should start here
};

View File

@@ -1,10 +1,15 @@
VM_FLAG( none, 0x00000000 )
VM_FLAG( write, 0x00000001 )
VM_FLAG( exec, 0x00000002 )
VM_FLAG( contiguous, 0x00000020 )
VM_FLAG( large_pages, 0x00000100 )
VM_FLAG( huge_pages, 0x00000200 )
VM_FLAG( write_combine, 0x00001000 )
VM_FLAG( ring, 0x00002000 )
VM_FLAG( mmio, 0x00010000 )
VM_FLAG( contiguous, 0x00000010 )
VM_FLAG( large_pages, 0x00000020 )
VM_FLAG( huge_pages, 0x00000040 )
VM_FLAG( write_combine, 0x00000100 )
VM_FLAG( mmio, 0x00001000 )
VM_FLAG( exact, 0x00010000 )
VM_FLAG( ring, 0x00020000 )

View File

@@ -19,22 +19,25 @@ template <typename Proc>
class thread
{
public:
static constexpr uintptr_t stack_base_start = 0x7f0'0000'0000;
/// Constructor. Create a thread and its stack space, but
/// do not start executing the thread.
/// \arg p The function where the thread will begin execution
/// \arg stack_top The address where the top of this thread's stack should be mapped
/// \arg stack_size Size of the stack, in bytes (default 64KiB)
thread(Proc p, uintptr_t stack_top, size_t stack_size = 0x10000) :
/// \arg stack_size Size of the stack, in bytes (default 16MiB)
thread(Proc p, size_t stack_size = 0x100'0000) :
m_stack {j6_handle_invalid},
m_thread {j6_handle_invalid},
m_stack_top {stack_top},
m_proc {p}
{
uintptr_t stack_base = stack_top - stack_size;
m_status = j6_vma_create_map(&m_stack, stack_size, stack_base, j6_vm_flag_write);
uintptr_t stack_base = stack_base_start;
m_status = j6_vma_create_map(&m_stack, stack_size, &stack_base, j6_vm_flag_write);
if (m_status != j6_status_ok)
return;
m_stack_top = stack_base + stack_size;
static constexpr size_t zeros_size = 0x10;
m_stack_top -= zeros_size; // Sentinel
memset(reinterpret_cast<void*>(m_stack_top), 0, zeros_size);