[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:
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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 )
|
||||
@@ -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);
|
||||
|
||||
@@ -1,26 +1,17 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <j6/errors.h>
|
||||
#include <j6/syscalls.h>
|
||||
|
||||
namespace __j6libc {
|
||||
|
||||
using j6_status_t = uint64_t;
|
||||
using j6_handle_t = uint64_t;
|
||||
|
||||
constexpr j6_handle_t j6_handle_invalid = -1ull;
|
||||
constexpr j6_status_t j6_status_ok = 0;
|
||||
|
||||
static j6_handle_t core_handle = j6_handle_invalid;
|
||||
static intptr_t core_size = 0;
|
||||
|
||||
static const uintptr_t core_base = 0x1c0000000;
|
||||
static uintptr_t core_base = 0x1c0000000;
|
||||
|
||||
static const void *error_val = (void*)-1;
|
||||
|
||||
extern "C" {
|
||||
j6_status_t j6_vma_create_map(j6_handle_t *, size_t, uintptr_t, unsigned);
|
||||
j6_status_t j6_vma_resize(j6_handle_t, size_t *);
|
||||
}
|
||||
|
||||
void * increase_core(intptr_t i)
|
||||
{
|
||||
if (i == 0)
|
||||
@@ -30,7 +21,7 @@ void * increase_core(intptr_t i)
|
||||
if (i < 0)
|
||||
return (void*)-1;
|
||||
|
||||
j6_status_t result = j6_vma_create_map(&core_handle, i, core_base, 1);
|
||||
j6_status_t result = j6_vma_create_map(&core_handle, i, &core_base, 1);
|
||||
if (result != j6_status_ok)
|
||||
return (void*)-1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user