Compare commits

...

32 Commits

Author SHA1 Message Date
wash 1db6de6bc2 meta: rename kernel to Magenta 2026-04-30 20:30:36 +01:00
wash 560da0daa0 syscall: fix TLB not being flushed when necessary 2026-04-30 19:15:30 +01:00
wash 61f0aa1aba vm: address-space: update pmap API usage 2026-04-30 19:14:34 +01:00
wash ed54dca3ba syscall: handle: fix lock-related bugs 2026-04-30 19:12:47 +01:00
wash 4a6809e2df sched: task: fix leftover invalid pmap pointer 2026-04-30 19:10:51 +01:00
wash d63c2dbd12 vm: object: add prefetch function to fetch missing pages 2026-04-30 19:09:41 +01:00
wash 607efa961f sched: task: implement task_config_get and task_config_set 2026-04-30 19:08:02 +01:00
wash 02a44f67b9 sched: task: implement task creation flags 2026-04-30 19:06:46 +01:00
wash 562b856488 libmango: add a task config key to get the task ID 2026-04-30 19:05:14 +01:00
wash 8f77eb1ed0 libmango: add syscall to reset a particular task 2026-04-30 19:04:54 +01:00
wash 3ad479aa17 libmango: add flags parameter to task_create 2026-04-30 19:04:28 +01:00
wash 546fee7890 x86_64: adjust formatting 2026-04-30 19:02:56 +01:00
wash 5654c02f36 x86_64: pmap: implement pmap_flush and pmap_remove_range 2026-04-30 18:59:46 +01:00
wash d5c7a9f030 pmap: add functions for flushing all/parts of the TLB 2026-04-30 18:59:08 +01:00
wash 278fe39c0d vm: implement private and shared address space mappings
whether a mapping is private or shared determines how the mapping is handled
when a task is duplicated.
2026-04-21 21:12:00 +01:00
wash 8b7382fa13 libmango: add flags parameter to address_space_map 2026-04-21 21:11:42 +01:00
wash bc575aa1a1 x86_64: thread: remove log when cloning user thread 2026-04-20 22:20:43 +01:00
wash 982e518cf7 kernel: formatting tweaks 2026-04-19 20:17:31 +01:00
wash a30401d8b1 syscall: task: fix task_duplicate not taking a reference to the new task's address space 2026-04-19 20:17:05 +01:00
wash 4a9e907a75 vm: implement lazy-attach cow-duplication of vm-objects attached to a controller 2026-04-19 20:16:19 +01:00
wash b3be4c541b libmango: rename page requests to vm requests 2026-04-19 20:13:07 +01:00
wash 61a8e6fc40 libmango: add syscalls to handle cow-attached vm-objects 2026-04-19 20:12:11 +01:00
wash c105e17be9 kernel: printk: keep log_buffer_lock locked while flushing printk buffer 2026-04-19 20:08:29 +01:00
wash f1dd9d8564 kernel: handle: init handle table duplication 2026-04-19 20:07:51 +01:00
wash c87c29366d x86_64: irq: initialise tr_irqctx before running syscall handler 2026-04-19 20:05:11 +01:00
wash 9a9b0f63ba sched: task: optional handle_table pointer can now be passed to task_create 2026-04-19 20:04:18 +01:00
wash b52890d842 kernel: object: add missing parentheses to OBJECT_CAST 2026-04-19 20:00:16 +01:00
wash a2f370f326 cmake: change minimum cmake version to 3.31 2026-04-19 19:58:30 +01:00
wash 3584f6831b x86_64: thread: copy fs- and gs-base pointers to cloned thread context 2026-04-19 19:36:16 +01:00
wash c7c497cd66 x86_64: serial: write COM1 output to Bochs console 2026-04-19 19:34:49 +01:00
wash 05b1d39241 x86_64: pmap: fix pmap_get setting vm flags in wrong output variable 2026-04-19 19:34:19 +01:00
wash 5e66083355 x86_64: formatting tweaks 2026-04-19 19:33:10 +01:00
85 changed files with 1045 additions and 338 deletions
+5 -5
View File
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 4.0) cmake_minimum_required(VERSION 3.31)
project(mango C ASM) project(magenta C ASM)
if (NOT BUILD_TOOLS_DIR) if (NOT BUILD_TOOLS_DIR)
message(FATAL_ERROR "No build tools directory specified. Please run build.sh") message(FATAL_ERROR "No build tools directory specified. Please run build.sh")
@@ -9,8 +9,8 @@ set(CMAKE_C_STANDARD 17)
set(kernel_arch x86_64) set(kernel_arch x86_64)
set(kernel_name "Mango") set(kernel_name "Magenta")
set(kernel_exe_name "mango_kernel") set(kernel_exe_name "magenta_kernel")
set(generic_src_dirs ds init kernel libc sched util vm syscall) set(generic_src_dirs ds init kernel libc sched util vm syscall)
set(kernel_sources "") set(kernel_sources "")
@@ -38,7 +38,7 @@ add_executable(${kernel_exe_name}
target_include_directories(${kernel_exe_name} PRIVATE target_include_directories(${kernel_exe_name} PRIVATE
include include
libc/include libc/include
libmango/include libmagenta/include
arch/${kernel_arch}/include) arch/${kernel_arch}/include)
target_compile_options(${kernel_exe_name} PRIVATE target_compile_options(${kernel_exe_name} PRIVATE
-nostdlib -ffreestanding -nostdlib -ffreestanding
+1 -1
View File
@@ -1,4 +1,4 @@
Mango Magenta
===== =====
It's a kernel! It's a kernel!
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef MANGO_USER_CPU_H_ #ifndef MAGENTA_USER_CPU_H_
#define MANGO_USER_CPU_H_ #define MAGENTA_USER_CPU_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef MANGO_USER_HWLOCK_H_ #ifndef MAGENTA_USER_HWLOCK_H_
#define MANGO_USER_HWLOCK_H_ #define MAGENTA_USER_HWLOCK_H_
#define ML_HWLOCK_INIT (0) #define ML_HWLOCK_INIT (0)
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef MANGO_X86_64_INIT_H_ #ifndef MAGENTA_X86_64_INIT_H_
#define MANGO_X86_64_INIT_H_ #define MAGENTA_X86_64_INIT_H_
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef MANGO_X86_64_IRQ_H_ #ifndef MAGENTA_X86_64_IRQ_H_
#define MANGO_X86_64_IRQ_H_ #define MAGENTA_X86_64_IRQ_H_
#endif #endif
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef MANGO_USER_PMAP_H_ #ifndef MAGENTA_USER_PMAP_H_
#define MANGO_USER_PMAP_H_ #define MAGENTA_USER_PMAP_H_
#include <stdint.h> #include <stdint.h>
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef MANGO_USER_VM_H_ #ifndef MAGENTA_USER_VM_H_
#define MANGO_USER_VM_H_ #define MAGENTA_USER_VM_H_
#include <stdint.h> #include <stdint.h>
+3 -1
View File
@@ -34,7 +34,9 @@ extern kern_status_t ml_thread_prepare_user_context(
/* prepare the stack so that ml_thread_switch_user can jump to usermode /* prepare the stack so that ml_thread_switch_user can jump to usermode
* with the specified register context */ * with the specified register context */
extern kern_status_t ml_thread_clone_user_context( extern kern_status_t ml_thread_clone_user_context(
const struct ml_cpu_context *ctx, const struct ml_cpu_context *src_regs,
const struct ml_thread *src_ml,
struct ml_thread *dest_ml,
uintptr_t return_value, uintptr_t return_value,
virt_addr_t *kernel_sp); virt_addr_t *kernel_sp);
+1 -1
View File
@@ -20,7 +20,7 @@
#include <kernel/util.h> #include <kernel/util.h>
#include <kernel/vm.h> #include <kernel/vm.h>
#undef HARDWARE_RNG #define HARDWARE_RNG
#define PTR32(x) ((void *)((uintptr_t)(x))) #define PTR32(x) ((void *)((uintptr_t)(x)))
+6
View File
@@ -217,6 +217,12 @@ void irq_dispatch(struct ml_cpu_context *regs)
void syscall_dispatch(struct ml_cpu_context *regs) void syscall_dispatch(struct ml_cpu_context *regs)
{ {
struct thread *thr = get_current_thread();
if (thr) {
thr->tr_irqctx = regs;
put_current_thread(thr);
}
unsigned int sysid = regs->rax; unsigned int sysid = regs->rax;
virt_addr_t syscall_impl = syscall_get_function(sysid); virt_addr_t syscall_impl = syscall_get_function(sysid);
+16 -4
View File
@@ -9,7 +9,7 @@
#include <kernel/types.h> #include <kernel/types.h>
#include <kernel/vm-object.h> #include <kernel/vm-object.h>
#include <kernel/vm.h> #include <kernel/vm.h>
#include <mango/status.h> #include <magenta/status.h>
/* some helpful datasize constants */ /* some helpful datasize constants */
#define C_1GiB 0x40000000ULL #define C_1GiB 0x40000000ULL
@@ -196,15 +196,15 @@ kern_status_t pmap_get(
} }
if (pte & PTE_RW) { if (pte & PTE_RW) {
*out_pfn |= (VM_PROT_READ | VM_PROT_WRITE); *out_prot |= (VM_PROT_READ | VM_PROT_WRITE);
} }
if (pte & PTE_USR) { if (pte & PTE_USR) {
*out_pfn |= VM_PROT_USER; *out_prot |= VM_PROT_USER;
} }
if (!(pte & PTE_NX)) { if (!(pte & PTE_NX)) {
*out_pfn |= VM_PROT_EXEC; *out_prot |= VM_PROT_EXEC;
} }
} }
@@ -321,6 +321,10 @@ static kern_status_t do_pmap_remove(
virt_addr_t pv, virt_addr_t pv,
enum page_size size) enum page_size size)
{ {
if (pmap == PMAP_INVALID) {
return KERN_OK;
}
unsigned int pml4t_index = BAD_INDEX, pdpt_index = BAD_INDEX, unsigned int pml4t_index = BAD_INDEX, pdpt_index = BAD_INDEX,
pd_index = BAD_INDEX, pt_index = BAD_INDEX; pd_index = BAD_INDEX, pt_index = BAD_INDEX;
@@ -622,5 +626,13 @@ kern_status_t pmap_remove(pmap_t pmap, virt_addr_t p)
kern_status_t pmap_remove_range(pmap_t pmap, virt_addr_t p, size_t len) kern_status_t pmap_remove_range(pmap_t pmap, virt_addr_t p, size_t len)
{ {
if (pmap == PMAP_INVALID) {
return KERN_OK;
}
for (size_t i = p; i < p + len; i += VM_PAGE_SIZE) {
pmap_remove(pmap, i);
}
return KERN_OK; return KERN_OK;
} }
+9
View File
@@ -1,3 +1,11 @@
.global pmap_flush
.type pmap_flush, @function
pmap_flush:
mov %cr3, %rax
mov %rax, %cr3
ret
.global pmap_switch .global pmap_switch
.type pmap_switch, @function .type pmap_switch, @function
@@ -6,6 +14,7 @@ pmap_switch:
mov %rdi, %cr3 mov %rdi, %cr3
ret ret
.global gigabyte_pages .global gigabyte_pages
.type gigabyte_pages, @function .type gigabyte_pages, @function
+4
View File
@@ -28,6 +28,10 @@ void serial_send_byte(int device, char out)
outportb(device, out); outportb(device, out);
if (device == COM1) {
outportb(0xe9, out);
}
while (!transmit_empty(device)) { while (!transmit_empty(device)) {
_count++; _count++;
} }
+9 -4
View File
@@ -81,16 +81,21 @@ extern kern_status_t ml_thread_prepare_user_context(
} }
kern_status_t ml_thread_clone_user_context( kern_status_t ml_thread_clone_user_context(
const struct ml_cpu_context *src_ctx, const struct ml_cpu_context *src_regs,
const struct ml_thread *src_ml,
struct ml_thread *dest_ml,
uintptr_t return_value, uintptr_t return_value,
virt_addr_t *kernel_sp) virt_addr_t *kernel_sp)
{ {
(*kernel_sp) -= sizeof(struct ml_cpu_context); (*kernel_sp) -= sizeof(struct ml_cpu_context);
struct ml_cpu_context *ctx = (struct ml_cpu_context *)(*kernel_sp); struct ml_cpu_context *regs = (struct ml_cpu_context *)(*kernel_sp);
memcpy(ctx, src_ctx, sizeof *ctx); memcpy(regs, src_regs, sizeof *regs);
ctx->rax = return_value; regs->rax = return_value;
dest_ml->tr_fsbase = src_ml->tr_fsbase;
dest_ml->tr_gsbase = src_ml->tr_gsbase;
return KERN_OK; return KERN_OK;
} }
+1 -1
View File
@@ -1,5 +1,5 @@
# the name of the target operating system # the name of the target operating system
set(CMAKE_SYSTEM_NAME Mango) set(CMAKE_SYSTEM_NAME Magenta)
# which compilers to use for C and C++ # which compilers to use for C and C++
set(CMAKE_C_COMPILER x86_64-elf-gcc) set(CMAKE_C_COMPILER x86_64-elf-gcc)
+3
View File
@@ -22,6 +22,8 @@ struct vm_area {
struct address_space *vma_space; struct address_space *vma_space;
/* used to link to vm_object->vo_mappings */ /* used to link to vm_object->vo_mappings */
struct queue_entry vma_object_entry; struct queue_entry vma_object_entry;
/* the memory control flags applied to this area */
vm_flags_t vma_flags;
/* the memory protection flags applied to this area */ /* the memory protection flags applied to this area */
vm_prot_t vma_prot; vm_prot_t vma_prot;
/* offset in bytes to the start of the object data that was mapped */ /* offset in bytes to the start of the object data that was mapped */
@@ -83,6 +85,7 @@ extern kern_status_t address_space_map(
struct vm_object *object, struct vm_object *object,
off_t object_offset, off_t object_offset,
size_t length, size_t length,
vm_flags_t flags,
vm_prot_t prot, vm_prot_t prot,
virt_addr_t *out); virt_addr_t *out);
extern kern_status_t address_space_unmap( extern kern_status_t address_space_unmap(
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef KERNEL_ARG_H_ #ifndef KERNEL_ARG_H_
#define KERNEL_ARG_H_ #define KERNEL_ARG_H_
#include <mango/types.h> #include <magenta/types.h>
#include <stdbool.h> #include <stdbool.h>
#define CMDLINE_MAX 4096 #define CMDLINE_MAX 4096
+1 -1
View File
@@ -2,7 +2,7 @@
#define KERNEL_BSP_H_ #define KERNEL_BSP_H_
#include <kernel/compiler.h> #include <kernel/compiler.h>
#include <mango/status.h> #include <magenta/status.h>
#include <kernel/types.h> #include <kernel/types.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
+2 -2
View File
@@ -16,8 +16,8 @@
*/ */
#include <kernel/locks.h> #include <kernel/locks.h>
#include <kernel/queue.h> #include <kernel/queue.h>
#include <mango/status.h> #include <magenta/status.h>
#include <mango/types.h> #include <magenta/types.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
+1 -1
View File
@@ -4,7 +4,7 @@
#include <kernel/locks.h> #include <kernel/locks.h>
#include <kernel/object.h> #include <kernel/object.h>
#include <kernel/sched.h> #include <kernel/sched.h>
#include <mango/types.h> #include <magenta/types.h>
#define EQUEUE_PACKET_MAX 100 #define EQUEUE_PACKET_MAX 100
+1 -1
View File
@@ -3,7 +3,7 @@
#include <kernel/btree.h> #include <kernel/btree.h>
#include <kernel/wait.h> #include <kernel/wait.h>
#include <mango/types.h> #include <magenta/types.h>
struct task; struct task;
struct address_space; struct address_space;
+5 -2
View File
@@ -2,8 +2,8 @@
#define KERNEL_HANDLE_H_ #define KERNEL_HANDLE_H_
#include <kernel/bitmap.h> #include <kernel/bitmap.h>
#include <mango/status.h> #include <magenta/status.h>
#include <mango/types.h> #include <magenta/types.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
@@ -44,6 +44,9 @@ struct handle_table {
extern struct handle_table *handle_table_create(void); extern struct handle_table *handle_table_create(void);
extern void handle_table_destroy(struct handle_table *tab); extern void handle_table_destroy(struct handle_table *tab);
extern kern_status_t handle_table_duplicate(
struct handle_table *src,
struct handle_table **dest);
extern kern_status_t handle_table_alloc_handle( extern kern_status_t handle_table_alloc_handle(
struct handle_table *tab, struct handle_table *tab,
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef KERNEL_IOVEC_H_ #ifndef KERNEL_IOVEC_H_
#define KERNEL_IOVEC_H_ #define KERNEL_IOVEC_H_
#include <mango/types.h> #include <magenta/types.h>
#include <stddef.h> #include <stddef.h>
struct address_space; struct address_space;
+2 -2
View File
@@ -3,8 +3,8 @@
#include <kernel/btree.h> #include <kernel/btree.h>
#include <kernel/locks.h> #include <kernel/locks.h>
#include <mango/status.h> #include <magenta/status.h>
#include <mango/types.h> #include <magenta/types.h>
struct port; struct port;
struct thread; struct thread;
+2 -2
View File
@@ -5,7 +5,7 @@
#include <kernel/locks.h> #include <kernel/locks.h>
#include <kernel/vm.h> #include <kernel/vm.h>
#include <kernel/wait.h> #include <kernel/wait.h>
#include <mango/status.h> #include <magenta/status.h>
#include <stddef.h> #include <stddef.h>
#ifdef __cplusplus #ifdef __cplusplus
@@ -65,7 +65,7 @@ extern "C" {
#define OBJECT_PATH_MAX 256 #define OBJECT_PATH_MAX 256
#define OBJECT_CAST(to_type, to_type_member, p) \ #define OBJECT_CAST(to_type, to_type_member, p) \
((to_type *)((uintptr_t)p) - offsetof(to_type, to_type_member)) ((to_type *)(((uintptr_t)p) - offsetof(to_type, to_type_member)))
#define OBJECT_C_CAST(c_type, c_type_member, obj_type, objp) \ #define OBJECT_C_CAST(c_type, c_type_member, obj_type, objp) \
OBJECT_IS_TYPE(objp, obj_type) \ OBJECT_IS_TYPE(objp, obj_type) \
? OBJECT_CAST(c_type, c_type_member, (objp)) : NULL ? OBJECT_CAST(c_type, c_type_member, (objp)) : NULL
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef KERNEL_PERCPU_H_ #ifndef KERNEL_PERCPU_H_
#define KERNEL_PERCPU_H_ #define KERNEL_PERCPU_H_
#include <mango/status.h> #include <magenta/status.h>
#include <kernel/compiler.h> #include <kernel/compiler.h>
#include <kernel/sched.h> #include <kernel/sched.h>
+5 -1
View File
@@ -5,7 +5,7 @@
#include <kernel/machine/pmap.h> #include <kernel/machine/pmap.h>
#include <kernel/vm.h> #include <kernel/vm.h>
#include <mango/status.h> #include <magenta/status.h>
#include <stddef.h> #include <stddef.h>
#define PMAP_INVALID ML_PMAP_INVALID #define PMAP_INVALID ML_PMAP_INVALID
@@ -52,6 +52,10 @@ extern pmap_t pmap_create(void);
extern void pmap_destroy(pmap_t pmap); extern void pmap_destroy(pmap_t pmap);
extern void pmap_switch(pmap_t pmap); extern void pmap_switch(pmap_t pmap);
extern void pmap_flush(void);
extern void pmap_flush_page(virt_addr_t p);
extern void pmap_flush_range(virt_addr_t start, size_t length);
extern kern_status_t pmap_handle_fault( extern kern_status_t pmap_handle_fault(
virt_addr_t fault_addr, virt_addr_t fault_addr,
enum pmap_fault_flags flags); enum pmap_fault_flags flags);
+1 -1
View File
@@ -6,7 +6,7 @@
#include <kernel/locks.h> #include <kernel/locks.h>
#include <kernel/queue.h> #include <kernel/queue.h>
#include <kernel/types.h> #include <kernel/types.h>
#include <mango/status.h> #include <magenta/status.h>
#define PRIO_MAX 32 #define PRIO_MAX 32
+13 -3
View File
@@ -5,8 +5,8 @@
#include <kernel/handle.h> #include <kernel/handle.h>
#include <kernel/task.h> #include <kernel/task.h>
#include <kernel/vm.h> #include <kernel/vm.h>
#include <mango/status.h> #include <magenta/status.h>
#include <mango/syscall.h> #include <magenta/syscall.h>
#define validate_access(task, ptr, len, flags) \ #define validate_access(task, ptr, len, flags) \
__validate_access(task, (const void *)ptr, len, flags) __validate_access(task, (const void *)ptr, len, flags)
@@ -42,6 +42,7 @@ extern kern_status_t sys_task_exit(int status);
extern kern_status_t sys_task_self(kern_handle_t *out); extern kern_status_t sys_task_self(kern_handle_t *out);
extern kern_status_t sys_task_create( extern kern_status_t sys_task_create(
kern_handle_t parent_handle, kern_handle_t parent_handle,
task_flags_t flags,
const char *name, const char *name,
size_t name_len, size_t name_len,
kern_handle_t *out_task, kern_handle_t *out_task,
@@ -128,6 +129,7 @@ extern kern_status_t sys_address_space_map(
kern_handle_t object, kern_handle_t object,
off_t object_offset, off_t object_offset,
size_t length, size_t length,
vm_flags_t flags,
vm_prot_t prot, vm_prot_t prot,
virt_addr_t *out_base_address); virt_addr_t *out_base_address);
extern kern_status_t sys_address_space_unmap( extern kern_status_t sys_address_space_unmap(
@@ -211,7 +213,7 @@ extern kern_status_t sys_kern_object_query(
extern kern_status_t sys_vm_controller_create(kern_handle_t *out); extern kern_status_t sys_vm_controller_create(kern_handle_t *out);
extern kern_status_t sys_vm_controller_recv( extern kern_status_t sys_vm_controller_recv(
kern_handle_t ctrl, kern_handle_t ctrl,
equeue_packet_page_request_t *out); equeue_packet_vm_request_t *out);
extern kern_status_t sys_vm_controller_recv_async( extern kern_status_t sys_vm_controller_recv_async(
kern_handle_t ctrl, kern_handle_t ctrl,
kern_handle_t eq, kern_handle_t eq,
@@ -224,6 +226,14 @@ extern kern_status_t sys_vm_controller_create_object(
size_t data_len, size_t data_len,
vm_prot_t prot, vm_prot_t prot,
kern_handle_t *out); kern_handle_t *out);
extern kern_status_t sys_vm_controller_prepare_attach(
kern_handle_t ctrl,
uint64_t req_id,
kern_handle_t *out_vmo);
extern kern_status_t sys_vm_controller_finish_attach(
kern_handle_t ctrl,
uint64_t req_id,
equeue_key_t new_key);
extern kern_status_t sys_vm_controller_detach_object( extern kern_status_t sys_vm_controller_detach_object(
kern_handle_t ctrl, kern_handle_t ctrl,
kern_handle_t vmo); kern_handle_t vmo);
+15 -1
View File
@@ -39,7 +39,11 @@ struct task {
extern struct task *task_alloc(void); extern struct task *task_alloc(void);
extern struct task *task_cast(struct object *obj); extern struct task *task_cast(struct object *obj);
extern struct task *task_create(const char *name, size_t name_len); extern struct task *task_create(
struct task *parent,
task_flags_t flags,
const char *name,
size_t name_len);
static inline struct task *task_ref(struct task *task) static inline struct task *task_ref(struct task *task)
{ {
return OBJECT_CAST(struct task, t_base, object_ref(&task->t_base)); return OBJECT_CAST(struct task, t_base, object_ref(&task->t_base));
@@ -66,6 +70,16 @@ extern kern_status_t task_resolve_handle(
kern_handle_t handle, kern_handle_t handle,
struct object **out_obj, struct object **out_obj,
handle_flags_t *out_flags); handle_flags_t *out_flags);
extern kern_status_t task_config_get(
struct task *task,
kern_config_key_t key,
void *out,
size_t max);
extern kern_status_t task_config_set(
struct task *task,
kern_config_key_t key,
const void *ptr,
size_t len);
extern kern_status_t task_close_handle(struct task *task, kern_handle_t handle); extern kern_status_t task_close_handle(struct task *task, kern_handle_t handle);
extern struct thread *task_create_thread(struct task *parent); extern struct thread *task_create_thread(struct task *parent);
extern struct task *kernel_task(void); extern struct task *kernel_task(void);
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef KERNEL_TYPES_H_ #ifndef KERNEL_TYPES_H_
#define KERNEL_TYPES_H_ #define KERNEL_TYPES_H_
#include <mango/types.h> #include <magenta/types.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef KERNEL_UTIL_H_ #ifndef KERNEL_UTIL_H_
#define KERNEL_UTIL_H_ #define KERNEL_UTIL_H_
#include <mango/types.h> #include <magenta/types.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
+29 -14
View File
@@ -3,40 +3,41 @@
#include <kernel/locks.h> #include <kernel/locks.h>
#include <kernel/object.h> #include <kernel/object.h>
#include <mango/types.h> #include <magenta/types.h>
struct thread; struct thread;
struct equeue; struct equeue;
struct vm_object; struct vm_object;
enum page_request_status { enum vm_request_status {
PAGE_REQUEST_PENDING = 0, VM_REQUEST_PENDING = 0,
PAGE_REQUEST_IN_PROGRESS, VM_REQUEST_IN_PROGRESS,
PAGE_REQUEST_COMPLETE, VM_REQUEST_COMPLETE,
PAGE_REQUEST_ASYNC, VM_REQUEST_ASYNC,
}; };
struct vm_controller { struct vm_controller {
struct object vc_base; struct object vc_base;
/* tree of pending page requests */ /* tree of pending vm requests */
struct btree vc_requests; struct btree vc_requests;
/* the equeue to send async page requests to */
struct equeue *vc_eq; struct equeue *vc_eq;
equeue_key_t vc_eq_key; equeue_key_t vc_eq_key;
/* the number of page requests queued with status PAGE_REQUEST_PENDING. /* the number of page requests queued with status VM_REQUEST_PENDING.
* used to assert/clear VM_CONTROLLER_SIGNAL_REQUEST_RECEIVED */ * used to assert/clear VM_CONTROLLER_SIGNAL_REQUEST_RECEIVED */
size_t vc_requests_waiting; size_t vc_requests_waiting;
}; };
struct page_request { struct vm_request {
uint64_t req_id; uint64_t req_id;
unsigned int req_type; unsigned int req_type;
enum page_request_status req_status; enum vm_request_status req_status;
kern_status_t req_result; kern_status_t req_result;
spin_lock_t req_lock; spin_lock_t req_lock;
equeue_key_t req_object; struct vm_object *req_object;
struct thread *req_sender; struct thread *req_sender;
/* this node is added to vm-controller vc_requests list */
struct btree_node req_node; struct btree_node req_node;
/* these values are used for VM_REQUEST_READ and VM_REQUEST_DIRTY */
off_t req_offset; off_t req_offset;
size_t req_length; size_t req_length;
}; };
@@ -48,7 +49,7 @@ extern struct vm_controller *vm_controller_create(void);
extern kern_status_t vm_controller_recv( extern kern_status_t vm_controller_recv(
struct vm_controller *ctrl, struct vm_controller *ctrl,
equeue_packet_page_request_t *out); equeue_packet_vm_request_t *out);
extern kern_status_t vm_controller_recv_async( extern kern_status_t vm_controller_recv_async(
struct vm_controller *ctrl, struct vm_controller *ctrl,
struct equeue *eq, struct equeue *eq,
@@ -62,6 +63,14 @@ extern kern_status_t vm_controller_create_object(
size_t data_len, size_t data_len,
vm_prot_t prot, vm_prot_t prot,
struct vm_object **out); struct vm_object **out);
extern kern_status_t vm_controller_prepare_attach(
struct vm_controller *ctrl,
uint64_t req_id,
struct vm_object **out_vmo);
extern kern_status_t vm_controller_finish_attach(
struct vm_controller *ctrl,
uint64_t req_id,
equeue_key_t new_key);
extern kern_status_t vm_controller_detach_object( extern kern_status_t vm_controller_detach_object(
struct vm_controller *ctrl, struct vm_controller *ctrl,
struct vm_object *vmo); struct vm_object *vmo);
@@ -72,10 +81,16 @@ extern kern_status_t vm_controller_supply_pages(
struct vm_object *src, struct vm_object *src,
off_t src_offset, off_t src_offset,
size_t count); size_t count);
extern void vm_controller_fulfill_requests(
struct vm_controller *ctrl,
equeue_key_t object,
off_t offset,
size_t length,
kern_status_t result);
extern kern_status_t vm_controller_send_request( extern kern_status_t vm_controller_send_request(
struct vm_controller *ctrl, struct vm_controller *ctrl,
struct page_request *req, struct vm_request *req,
unsigned long *irq_flags); unsigned long *irq_flags);
DEFINE_OBJECT_LOCK_FUNCTION(vm_controller, vc_base) DEFINE_OBJECT_LOCK_FUNCTION(vm_controller, vc_base)
+23 -2
View File
@@ -20,19 +20,25 @@ enum vm_object_flags {
* be detached, allowing the server to close the last handle to the * be detached, allowing the server to close the last handle to the
* object and dispose of it. */ * object and dispose of it. */
VMO_AUTO_DETACH = 0x04u, VMO_AUTO_DETACH = 0x04u,
/* this vmo is a duplicate of a vmo that is attached to a vm-controller.
* the duplicate vmo is scheduled to be attached to the same controller,
* but this won't actually happen until the controller is needed to
* fulfill a page request. once the duplicate vmo has been attached to
* the controller, this flag will be cleared. */
VMO_LAZY_ATTACH = 0x08u,
/* these flags are for use with vm_object_get_page */ /* these flags are for use with vm_object_get_page */
/**************************************************/ /**************************************************/
/* if the relevant page hasn't been allocated yet, it will be allocated /* if the relevant page hasn't been allocated yet, it will be allocated
* and returned. if this flag isn't specified, NULL will be returned. */ * and returned. if this flag isn't specified, NULL will be returned. */
VMO_ALLOCATE_MISSING_PAGE = 0x08u, VMO_ALLOCATE_MISSING_PAGE = 0x0100u,
/* if the vm-object is attached to a vm-controller, and the relevant /* if the vm-object is attached to a vm-controller, and the relevant
* page is uncommitted, send a request to the vm-controller to provide * page is uncommitted, send a request to the vm-controller to provide
* the missing page. will result in the vm-object being unlocked and * the missing page. will result in the vm-object being unlocked and
* the current thread sleeping until the request is fulfilled. the * the current thread sleeping until the request is fulfilled. the
* vm-object will be re-locked before the function returns. */ * vm-object will be re-locked before the function returns. */
VMO_REQUEST_MISSING_PAGE = 0x10u, VMO_REQUEST_MISSING_PAGE = 0x0200u,
}; };
struct vm_object { struct vm_object {
@@ -86,6 +92,21 @@ extern struct vm_object *vm_object_create_in_place(
/* create a copy-on-write duplicate of a vm-object */ /* create a copy-on-write duplicate of a vm-object */
extern struct vm_object *vm_object_duplicate_cow(struct vm_object *vmo); extern struct vm_object *vm_object_duplicate_cow(struct vm_object *vmo);
/* attach a copy-on-write duplicate of a vm-object to the vm-controller that
* controlled the original vm-object */
extern kern_status_t vm_object_attach_cow(
struct vm_object *vmo,
unsigned long *irq_flags);
/* prefetch any missing pages in the specified range of a vm-object.
* any lazy-allocated pages will be allocated.
* any missing pages will be requested from the vm-controller, if one is
* attached. */
extern kern_status_t vm_object_prefetch(
struct vm_object *vo,
off_t offset,
size_t length,
unsigned long *irq_flags);
extern struct vm_page *vm_object_get_page( extern struct vm_page *vm_object_get_page(
struct vm_object *vo, struct vm_object *vo,
+1 -1
View File
@@ -8,7 +8,7 @@
#include <kernel/machine/vm.h> #include <kernel/machine/vm.h>
#include <kernel/queue.h> #include <kernel/queue.h>
#include <kernel/types.h> #include <kernel/types.h>
#include <mango/status.h> #include <magenta/status.h>
#include <stddef.h> #include <stddef.h>
#ifdef __cplusplus #ifdef __cplusplus
+3 -2
View File
@@ -23,7 +23,7 @@ extern char __pstart[], __pend[];
void print_kernel_banner(void) void print_kernel_banner(void)
{ {
printk("Mango kernel version " BUILD_ID); printk("Magenta kernel version " BUILD_ID);
} }
static void hang(void) static void hang(void)
@@ -108,7 +108,8 @@ void kernel_init(uintptr_t arg)
bsp.bsp_trailer.bsp_exec_entry, bsp.bsp_trailer.bsp_exec_entry,
bsp.bsp_vmo); bsp.bsp_vmo);
struct task *bootstrap_task = task_create("bootstrap", 9); struct task *bootstrap_task
= task_create(NULL, TASK_F_DEFAULT, "bootstrap", 9);
tracek("created bootstrap task (pid=%u)", bootstrap_task->t_id); tracek("created bootstrap task (pid=%u)", bootstrap_task->t_id);
status = bsp_launch_async(&bsp, bootstrap_task); status = bsp_launch_async(&bsp, bootstrap_task);
+1 -1
View File
@@ -1,7 +1,7 @@
#include <kernel/arg.h> #include <kernel/arg.h>
#include <kernel/libc/ctype.h> #include <kernel/libc/ctype.h>
#include <kernel/libc/string.h> #include <kernel/libc/string.h>
#include <mango/status.h> #include <magenta/status.h>
static char g_cmdline[CMDLINE_MAX + 1] = {0}; static char g_cmdline[CMDLINE_MAX + 1] = {0};
+4
View File
@@ -120,6 +120,7 @@ static kern_status_t map_executable_exec(
bsp->bsp_vmo, bsp->bsp_vmo,
text_foffset, text_foffset,
bsp->bsp_trailer.bsp_text_size, bsp->bsp_trailer.bsp_text_size,
VM_SHARED,
VM_PROT_READ | VM_PROT_EXEC | VM_PROT_USER, VM_PROT_READ | VM_PROT_EXEC | VM_PROT_USER,
&text_base); &text_base);
if (status != KERN_OK) { if (status != KERN_OK) {
@@ -132,6 +133,7 @@ static kern_status_t map_executable_exec(
data, data,
data_foffset, data_foffset,
bsp->bsp_trailer.bsp_data_size, bsp->bsp_trailer.bsp_data_size,
VM_PRIVATE,
VM_PROT_READ | VM_PROT_WRITE | VM_PROT_USER, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_USER,
&data_base); &data_base);
if (status != KERN_OK) { if (status != KERN_OK) {
@@ -165,6 +167,7 @@ kern_status_t bsp_launch_async(struct bsp *bsp, struct task *task)
user_stack, user_stack,
0, 0,
BOOTSTRAP_STACK_SIZE, BOOTSTRAP_STACK_SIZE,
VM_PRIVATE,
VM_PROT_READ | VM_PROT_WRITE | VM_PROT_USER, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_USER,
&stack_buffer); &stack_buffer);
@@ -178,6 +181,7 @@ kern_status_t bsp_launch_async(struct bsp *bsp, struct task *task)
bsp->bsp_vmo, bsp->bsp_vmo,
0, 0,
bsp->bsp_trailer.bsp_exec_offset, bsp->bsp_trailer.bsp_exec_offset,
VM_PRIVATE,
VM_PROT_READ | VM_PROT_USER, VM_PROT_READ | VM_PROT_USER,
&bsp_data_base); &bsp_data_base);
+1 -1
View File
@@ -6,7 +6,7 @@
#include <kernel/task.h> #include <kernel/task.h>
#include <kernel/thread.h> #include <kernel/thread.h>
#include <kernel/util.h> #include <kernel/util.h>
#include <mango/signal.h> #include <magenta/signal.h>
#define CHANNEL_CAST(p) OBJECT_C_CAST(struct channel, c_base, &channel_type, p) #define CHANNEL_CAST(p) OBJECT_C_CAST(struct channel, c_base, &channel_type, p)
+1 -1
View File
@@ -2,7 +2,7 @@
#include <kernel/futex.h> #include <kernel/futex.h>
#include <kernel/sched.h> #include <kernel/sched.h>
#include <kernel/task.h> #include <kernel/task.h>
#include <mango/status.h> #include <magenta/status.h>
#define FUTEX_CREATE 0x40u #define FUTEX_CREATE 0x40u
+76 -1
View File
@@ -5,7 +5,7 @@
#include <kernel/sched.h> #include <kernel/sched.h>
#include <kernel/util.h> #include <kernel/util.h>
#include <kernel/vm.h> #include <kernel/vm.h>
#include <mango/types.h> #include <magenta/types.h>
/* depth=3 gives a maximum of ~66.6 million handles */ /* depth=3 gives a maximum of ~66.6 million handles */
#define MAX_TABLE_DEPTH 3 #define MAX_TABLE_DEPTH 3
@@ -77,6 +77,81 @@ void handle_table_destroy(struct handle_table *tab)
do_handle_table_destroy(tab, 0); do_handle_table_destroy(tab, 0);
} }
static kern_status_t do_handle_table_duplicate_leaf(
struct handle_table *src,
struct handle_table **dest)
{
struct handle_table *out
= vm_cache_alloc(&handle_table_cache, VM_NORMAL);
if (!out) {
return KERN_NO_MEMORY;
}
memcpy(out, src, sizeof *out);
for (size_t i = 0; i < HANDLES_PER_TABLE; i++) {
struct object *obj = src->t_handles.t_handle_list[i].h_object;
if (obj) {
object_ref(obj);
}
}
*dest = out;
return KERN_OK;
}
static kern_status_t do_handle_table_duplicate(
struct handle_table *src,
struct handle_table **dest,
unsigned int depth)
{
if (depth == MAX_TABLE_DEPTH - 1) {
return do_handle_table_duplicate_leaf(src, dest);
}
struct handle_table *out
= vm_cache_alloc(&handle_table_cache, VM_NORMAL);
if (!out) {
return KERN_NO_MEMORY;
}
memcpy(out->t_subtables.t_subtable_map,
src->t_subtables.t_subtable_map,
sizeof out->t_subtables.t_subtable_map);
memset(out->t_subtables.t_subtable_list,
0x0,
sizeof out->t_subtables.t_subtable_list);
for (size_t i = 0; i < REFS_PER_TABLE; i++) {
struct handle_table *child
= src->t_subtables.t_subtable_list[i];
struct handle_table *dup = NULL;
kern_status_t status = KERN_OK;
if (child) {
status = do_handle_table_duplicate(
child,
&dup,
depth + 1);
}
if (status == KERN_OK) {
out->t_subtables.t_subtable_list[i] = dup;
} else {
return status;
}
}
*dest = out;
return KERN_OK;
}
kern_status_t handle_table_duplicate(
struct handle_table *src,
struct handle_table **dest)
{
return do_handle_table_duplicate(src, dest, 0);
}
static kern_status_t decode_handle_indices( static kern_status_t decode_handle_indices(
kern_handle_t handle, kern_handle_t handle,
unsigned int indices[MAX_TABLE_DEPTH]) unsigned int indices[MAX_TABLE_DEPTH])
+1 -2
View File
@@ -98,9 +98,8 @@ int printk(const char *format, ...)
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&log_buffer_lock, &flags); spin_lock_irqsave(&log_buffer_lock, &flags);
save_log_message(msg); save_log_message(msg);
spin_unlock_irqrestore(&log_buffer_lock, flags);
flush_log_buffer(); flush_log_buffer();
spin_unlock_irqrestore(&log_buffer_lock, flags);
return 0; return 0;
} }
+2 -2
View File
@@ -1,5 +1,5 @@
#include <mango/status.h> #include <magenta/status.h>
#include <mango/types.h> #include <magenta/types.h>
#define ERROR_STRING_CASE(code) \ #define ERROR_STRING_CASE(code) \
case code: \ case code: \
@@ -1,4 +1,4 @@
file(GLOB headers ${CMAKE_CURRENT_SOURCE_DIR}/include/mango/*.h) file(GLOB headers ${CMAKE_CURRENT_SOURCE_DIR}/include/magenta/*.h)
file(GLOB asm_sources file(GLOB asm_sources
${CMAKE_CURRENT_SOURCE_DIR}/arch/${CMAKE_SYSTEM_PROCESSOR}/*.S) ${CMAKE_CURRENT_SOURCE_DIR}/arch/${CMAKE_SYSTEM_PROCESSOR}/*.S)
@@ -6,7 +6,7 @@ set(public_include_dirs
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include-user) ${CMAKE_CURRENT_SOURCE_DIR}/include-user)
add_library(libmango STATIC ${asm_sources}) add_library(libmagenta STATIC ${asm_sources})
target_include_directories(libmango PUBLIC target_include_directories(libmagenta PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include-user) ${CMAKE_CURRENT_SOURCE_DIR}/include-user)
@@ -1,4 +1,4 @@
#include "mango/syscall.h" #include "magenta/syscall.h"
# Registers: # Registers:
# rax = syscall ID + return value # rax = syscall ID + return value
@@ -57,7 +57,7 @@
SYSCALL_GATE task_exit SYS_TASK_EXIT 1 SYSCALL_GATE task_exit SYS_TASK_EXIT 1
SYSCALL_GATE task_self SYS_TASK_SELF 1 SYSCALL_GATE task_self SYS_TASK_SELF 1
SYSCALL_GATE task_create SYS_TASK_CREATE 5 SYSCALL_GATE task_create SYS_TASK_CREATE 6
SYSCALL_GATE task_duplicate SYS_TASK_DUPLICATE 2 SYSCALL_GATE task_duplicate SYS_TASK_DUPLICATE 2
SYSCALL_GATE task_create_thread SYS_TASK_CREATE_THREAD 6 SYSCALL_GATE task_create_thread SYS_TASK_CREATE_THREAD 6
SYSCALL_GATE task_get_address_space SYS_TASK_GET_ADDRESS_SPACE 1 SYSCALL_GATE task_get_address_space SYS_TASK_GET_ADDRESS_SPACE 1
@@ -77,7 +77,7 @@ SYSCALL_GATE vm_object_copy SYS_VM_OBJECT_COPY 6
SYSCALL_GATE address_space_read SYS_ADDRESS_SPACE_READ 5 SYSCALL_GATE address_space_read SYS_ADDRESS_SPACE_READ 5
SYSCALL_GATE address_space_write SYS_ADDRESS_SPACE_WRITE 5 SYSCALL_GATE address_space_write SYS_ADDRESS_SPACE_WRITE 5
SYSCALL_GATE address_space_map SYS_ADDRESS_SPACE_MAP 7 SYSCALL_GATE address_space_map SYS_ADDRESS_SPACE_MAP 8
SYSCALL_GATE address_space_unmap SYS_ADDRESS_SPACE_UNMAP 3 SYSCALL_GATE address_space_unmap SYS_ADDRESS_SPACE_UNMAP 3
SYSCALL_GATE address_space_reserve SYS_ADDRESS_SPACE_RESERVE 4 SYSCALL_GATE address_space_reserve SYS_ADDRESS_SPACE_RESERVE 4
SYSCALL_GATE address_space_release SYS_ADDRESS_SPACE_RELEASE 3 SYSCALL_GATE address_space_release SYS_ADDRESS_SPACE_RELEASE 3
@@ -102,6 +102,8 @@ SYSCALL_GATE vm_controller_create SYS_VM_CONTROLLER_CREATE 1
SYSCALL_GATE vm_controller_recv SYS_VM_CONTROLLER_RECV 2 SYSCALL_GATE vm_controller_recv SYS_VM_CONTROLLER_RECV 2
SYSCALL_GATE vm_controller_recv_async SYS_VM_CONTROLLER_RECV_ASYNC 3 SYSCALL_GATE vm_controller_recv_async SYS_VM_CONTROLLER_RECV_ASYNC 3
SYSCALL_GATE vm_controller_create_object SYS_VM_CONTROLLER_CREATE_OBJECT 7 SYSCALL_GATE vm_controller_create_object SYS_VM_CONTROLLER_CREATE_OBJECT 7
SYSCALL_GATE vm_controller_prepare_attach SYS_VM_CONTROLLER_PREPARE_ATTACH 3
SYSCALL_GATE vm_controller_finish_attach SYS_VM_CONTROLLER_FINISH_ATTACH 3
SYSCALL_GATE vm_controller_detach_object SYS_VM_CONTROLLER_DETACH_OBJECT 2 SYSCALL_GATE vm_controller_detach_object SYS_VM_CONTROLLER_DETACH_OBJECT 2
SYSCALL_GATE vm_controller_supply_pages SYS_VM_CONTROLLER_SUPPLY_PAGES 6 SYSCALL_GATE vm_controller_supply_pages SYS_VM_CONTROLLER_SUPPLY_PAGES 6
@@ -1,8 +1,8 @@
#ifndef MANGO_CONFIG_H_ #ifndef MAGENTA_CONFIG_H_
#define MANGO_CONFIG_H_ #define MAGENTA_CONFIG_H_
#include <mango/status.h> #include <magenta/status.h>
#include <mango/types.h> #include <magenta/types.h>
#include <stddef.h> #include <stddef.h>
extern kern_status_t kern_config_get( extern kern_status_t kern_config_get(
@@ -1,7 +1,7 @@
#ifndef MANGO_EQUEUE_H_ #ifndef MAGENTA_EQUEUE_H_
#define MANGO_EQUEUE_H_ #define MAGENTA_EQUEUE_H_
#include <mango/types.h> #include <magenta/types.h>
extern kern_status_t equeue_create(kern_handle_t *out); extern kern_status_t equeue_create(kern_handle_t *out);
extern kern_status_t equeue_dequeue(kern_handle_t eq, equeue_packet_t *out); extern kern_status_t equeue_dequeue(kern_handle_t eq, equeue_packet_t *out);
@@ -1,8 +1,8 @@
#ifndef MANGO_FUTEX_H_ #ifndef MAGENTA_FUTEX_H_
#define MANGO_FUTEX_H_ #define MAGENTA_FUTEX_H_
#include <mango/status.h> #include <magenta/status.h>
#include <mango/types.h> #include <magenta/types.h>
extern kern_status_t futex_wait( extern kern_status_t futex_wait(
kern_futex_t *futex, kern_futex_t *futex,
@@ -1,8 +1,8 @@
#ifndef MANGO_HANDLE_H_ #ifndef MAGENTA_HANDLE_H_
#define MANGO_HANDLE_H_ #define MAGENTA_HANDLE_H_
#include <mango/status.h> #include <magenta/status.h>
#include <mango/types.h> #include <magenta/types.h>
extern kern_status_t kern_handle_close(kern_handle_t handle); extern kern_status_t kern_handle_close(kern_handle_t handle);
extern kern_status_t kern_handle_transfer( extern kern_status_t kern_handle_transfer(
@@ -1,8 +1,8 @@
#ifndef MANGO_LOG_H_ #ifndef MAGENTA_LOG_H_
#define MANGO_LOG_H_ #define MAGENTA_LOG_H_
#include <mango/status.h> #include <magenta/status.h>
#include <mango/types.h> #include <magenta/types.h>
#undef TRACE #undef TRACE
@@ -1,8 +1,8 @@
#ifndef MANGO_MSG_H_ #ifndef MAGENTA_MSG_H_
#define MANGO_MSG_H_ #define MAGENTA_MSG_H_
#include <mango/status.h> #include <magenta/status.h>
#include <mango/types.h> #include <magenta/types.h>
extern kern_status_t channel_create(unsigned int id, kern_handle_t *out); extern kern_status_t channel_create(unsigned int id, kern_handle_t *out);
extern kern_status_t port_create(kern_handle_t *out); extern kern_status_t port_create(kern_handle_t *out);
@@ -1,7 +1,7 @@
#ifndef MANGO_OBJECT_H_ #ifndef MAGENTA_OBJECT_H_
#define MANGO_OBJECT_H_ #define MAGENTA_OBJECT_H_
#include <mango/types.h> #include <magenta/types.h>
extern kern_status_t kern_object_wait(kern_wait_item_t *items, size_t nr_items); extern kern_status_t kern_object_wait(kern_wait_item_t *items, size_t nr_items);
extern kern_status_t kern_object_query( extern kern_status_t kern_object_query(
@@ -1,14 +1,15 @@
#ifndef MANGO_TASK_H_ #ifndef MAGENTA_TASK_H_
#define MANGO_TASK_H_ #define MAGENTA_TASK_H_
#include <mango/status.h> #include <magenta/status.h>
#include <mango/types.h> #include <magenta/types.h>
extern kern_status_t task_exit(int status); extern kern_status_t task_exit(int status);
extern kern_status_t task_self(kern_handle_t *out); extern kern_status_t task_self(kern_handle_t *out);
extern kern_status_t task_create( extern kern_status_t task_create(
kern_handle_t parent, kern_handle_t parent,
task_flags_t flags,
const char *name, const char *name,
size_t name_len, size_t name_len,
kern_handle_t *out_task, kern_handle_t *out_task,
@@ -36,6 +37,13 @@ extern kern_status_t task_config_set(
extern kern_status_t task_duplicate( extern kern_status_t task_duplicate(
kern_handle_t *out_task, kern_handle_t *out_task,
kern_handle_t *out_address_space); kern_handle_t *out_address_space);
extern kern_status_t task_reset(
virt_addr_t ip,
virt_addr_t sp,
uintptr_t *args,
size_t nr_args,
virt_addr_t unmap_base,
size_t unmap_length);
extern kern_status_t thread_self(kern_handle_t *out); extern kern_status_t thread_self(kern_handle_t *out);
extern kern_status_t thread_start(kern_handle_t thread); extern kern_status_t thread_start(kern_handle_t thread);
@@ -1,8 +1,8 @@
#ifndef MANGO_VM_H_ #ifndef MAGENTA_VM_H_
#define MANGO_VM_H_ #define MAGENTA_VM_H_
#include <mango/status.h> #include <magenta/status.h>
#include <mango/types.h> #include <magenta/types.h>
extern kern_status_t vm_object_create( extern kern_status_t vm_object_create(
const char *name, const char *name,
@@ -48,6 +48,7 @@ extern kern_status_t address_space_map(
kern_handle_t object, kern_handle_t object,
off_t object_offset, off_t object_offset,
size_t length, size_t length,
vm_flags_t flags,
vm_prot_t prot, vm_prot_t prot,
virt_addr_t *out_base_address); virt_addr_t *out_base_address);
extern kern_status_t address_space_unmap( extern kern_status_t address_space_unmap(
@@ -67,7 +68,7 @@ extern kern_status_t address_space_release(
extern kern_status_t vm_controller_create(kern_handle_t *out); extern kern_status_t vm_controller_create(kern_handle_t *out);
extern kern_status_t vm_controller_recv( extern kern_status_t vm_controller_recv(
kern_handle_t ctrl, kern_handle_t ctrl,
equeue_packet_page_request_t *out); equeue_packet_vm_request_t *out);
extern kern_status_t vm_controller_recv_async( extern kern_status_t vm_controller_recv_async(
kern_handle_t ctrl, kern_handle_t ctrl,
kern_handle_t eq, kern_handle_t eq,
@@ -80,6 +81,14 @@ extern kern_status_t vm_controller_create_object(
size_t data_len, size_t data_len,
vm_prot_t prot, vm_prot_t prot,
kern_handle_t *out); kern_handle_t *out);
extern kern_status_t vm_controller_prepare_attach(
kern_handle_t ctrl,
uint64_t req_id,
kern_handle_t *out_vmo);
extern kern_status_t vm_controller_finish_attach(
kern_handle_t ctrl,
uint64_t req_id,
equeue_key_t new_key);
extern kern_status_t vm_controller_detach_object( extern kern_status_t vm_controller_detach_object(
kern_handle_t ctrl, kern_handle_t ctrl,
kern_handle_t vmo); kern_handle_t vmo);
@@ -1,5 +1,5 @@
#ifndef MANGO_SIGNAL_H_ #ifndef MAGENTA_SIGNAL_H_
#define MANGO_SIGNAL_H_ #define MAGENTA_SIGNAL_H_
#define THREAD_SIGNAL_STOPPED 0x01u #define THREAD_SIGNAL_STOPPED 0x01u
@@ -1,5 +1,5 @@
#ifndef MANGO_STATUS_H_ #ifndef MAGENTA_STATUS_H_
#define MANGO_STATUS_H_ #define MAGENTA_STATUS_H_
#define KERN_OK (0) #define KERN_OK (0)
#define KERN_UNIMPLEMENTED (1) #define KERN_UNIMPLEMENTED (1)
+58
View File
@@ -0,0 +1,58 @@
#ifndef MAGENTA_SYSCALL_H_
#define MAGENTA_SYSCALL_H_
#define SYS_KERN_LOG 1
#define SYS_KERN_HANDLE_CLOSE 2
#define SYS_KERN_HANDLE_TRANSFER 3
#define SYS_KERN_HANDLE_CONTROL 4
#define SYS_KERN_CONFIG_GET 5
#define SYS_KERN_CONFIG_SET 6
#define SYS_KERN_OBJECT_WAIT 7
#define SYS_KERN_OBJECT_WAIT_ASYNC 8
#define SYS_TASK_EXIT 9
#define SYS_TASK_SELF 10
#define SYS_TASK_CREATE 11
#define SYS_TASK_CREATE_THREAD 12
#define SYS_TASK_GET_ADDRESS_SPACE 13
#define SYS_TASK_CONFIG_GET 14
#define SYS_TASK_CONFIG_SET 15
#define SYS_TASK_DUPLICATE 16
#define SYS_THREAD_SELF 17
#define SYS_THREAD_START 18
#define SYS_THREAD_EXIT 19
#define SYS_THREAD_CONFIG_GET 20
#define SYS_THREAD_CONFIG_SET 21
#define SYS_VM_OBJECT_CREATE 22
#define SYS_VM_OBJECT_READ 23
#define SYS_VM_OBJECT_WRITE 24
#define SYS_VM_OBJECT_COPY 25
#define SYS_ADDRESS_SPACE_READ 26
#define SYS_ADDRESS_SPACE_WRITE 27
#define SYS_ADDRESS_SPACE_MAP 28
#define SYS_ADDRESS_SPACE_UNMAP 29
#define SYS_ADDRESS_SPACE_RESERVE 30
#define SYS_ADDRESS_SPACE_RELEASE 31
#define SYS_MSG_SEND 32
#define SYS_MSG_RECV 33
#define SYS_MSG_REPLY 34
#define SYS_MSG_READ 35
#define SYS_MSG_WRITE 36
#define SYS_CHANNEL_CREATE 37
#define SYS_PORT_CREATE 38
#define SYS_PORT_CONNECT 39
#define SYS_PORT_DISCONNECT 40
#define SYS_EQUEUE_CREATE 41
#define SYS_EQUEUE_DEQUEUE 42
#define SYS_VM_CONTROLLER_CREATE 43
#define SYS_VM_CONTROLLER_RECV 44
#define SYS_VM_CONTROLLER_RECV_ASYNC 45
#define SYS_VM_CONTROLLER_CREATE_OBJECT 46
#define SYS_VM_CONTROLLER_PREPARE_ATTACH 47
#define SYS_VM_CONTROLLER_FINISH_ATTACH 48
#define SYS_VM_CONTROLLER_DETACH_OBJECT 49
#define SYS_VM_CONTROLLER_SUPPLY_PAGES 50
#define SYS_FUTEX_WAIT 51
#define SYS_FUTEX_WAKE 52
#define SYS_KERN_OBJECT_QUERY 53
#endif
@@ -1,5 +1,5 @@
#ifndef MANGO_TYPES_H_ #ifndef MAGENTA_TYPES_H_
#define MANGO_TYPES_H_ #define MAGENTA_TYPES_H_
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
@@ -16,12 +16,17 @@
#define MAP_ADDRESS_INVALID ((virt_addr_t)0) #define MAP_ADDRESS_INVALID ((virt_addr_t)0)
#define KERN_HANDLE_INVALID ((kern_handle_t)0xFFFFFFFF) #define KERN_HANDLE_INVALID ((kern_handle_t)0xFFFFFFFF)
/* task creation flags */
#define TASK_F_DEFAULT 0x0000u
#define TASK_F_CLONE_ALL_HANDLES 0x0001u
/* config keys for use with kern_config_get/kern_config_set */ /* config keys for use with kern_config_get/kern_config_set */
#define KERN_CFG_INVALID 0x00000u #define KERN_CFG_INVALID 0x00000u
#define KERN_CFG_PAGE_SIZE 0x00001u #define KERN_CFG_PAGE_SIZE 0x00001u
/* config keys for use with task_config_get/task_config_set */ /* config keys for use with task_config_get/task_config_set */
#define TASK_CFG_INVALID 0x00000u #define TASK_CFG_INVALID 0x00000u
#define TASK_CFG_ID 0x10001u
/* config keys for use with thread_config_get/thread_config_set */ /* config keys for use with thread_config_get/thread_config_set */
#define THREAD_CFG_INVALID 0x00000u #define THREAD_CFG_INVALID 0x00000u
@@ -34,6 +39,16 @@
#define KERN_HANDLE_FLAG2 0x40000000UL #define KERN_HANDLE_FLAG2 0x40000000UL
#define KERN_HANDLE_FLAG3 0x80000000UL #define KERN_HANDLE_FLAG3 0x80000000UL
/* flags to specify when creating address-space mappings */
/* this mapping is private. if a task with this mapping is duplicated,
the duplicate task will receive a copy-on-write mapping. changes to one
mapping will not be visible to the other. */
#define VM_PRIVATE 0x0000u
/* this mapping is shared. if a task with this mapping is duplicated,
* the duplicate will receive a mapping of the same data. changes to one mapping
* will be visibile to the other */
#define VM_SHARED 0x0001u
/* maximum number of handles that can be sent in a single message */ /* maximum number of handles that can be sent in a single message */
#define KERN_MSG_MAX_HANDLES 64 #define KERN_MSG_MAX_HANDLES 64
@@ -61,13 +76,14 @@
#define KERN_MSG_EVENT_DISCONNECTION 2 #define KERN_MSG_EVENT_DISCONNECTION 2
/* equeue packet types */ /* equeue packet types */
#define EQUEUE_PKT_PAGE_REQUEST 0x01u #define EQUEUE_PKT_VM_REQUEST 0x01u
#define EQUEUE_PKT_ASYNC_SIGNAL 0x02u #define EQUEUE_PKT_ASYNC_SIGNAL 0x02u
/* page request types */ /* vm request types */
#define PAGE_REQUEST_READ 0x01u #define VM_REQUEST_READ 0x01u
#define PAGE_REQUEST_DIRTY 0x02u #define VM_REQUEST_DIRTY 0x02u
#define PAGE_REQUEST_DETACH 0x03u #define VM_REQUEST_ATTACH 0x03u
#define VM_REQUEST_DETACH 0x04u
/* futex special values */ /* futex special values */
#define FUTEX_WAKE_ALL ((size_t)-1) #define FUTEX_WAKE_ALL ((size_t)-1)
@@ -106,6 +122,8 @@ typedef unsigned int kern_status_t;
typedef uint32_t kern_handle_t; typedef uint32_t kern_handle_t;
typedef uint32_t kern_config_key_t; typedef uint32_t kern_config_key_t;
typedef uint32_t vm_prot_t; typedef uint32_t vm_prot_t;
typedef uint32_t vm_flags_t;
typedef uint32_t task_flags_t;
typedef int64_t ssize_t; typedef int64_t ssize_t;
typedef uint32_t kern_futex_t; typedef uint32_t kern_futex_t;
typedef uint32_t kern_msg_type_t; typedef uint32_t kern_msg_type_t;
@@ -175,14 +193,33 @@ typedef struct {
/* the key of the vm-object for which the page request relates, as /* the key of the vm-object for which the page request relates, as
* specified when the vm-object was created */ * specified when the vm-object was created */
equeue_key_t req_vmo; equeue_key_t req_vmo;
/* page request type. one of PAGE_REQUEST_* */ /* page request type. one of VM_REQUEST_* */
unsigned short req_type; unsigned short req_type;
/* of the offset into the vm-object for which pages are being requested /* the offset into the vm-object for which pages are being requested */
*/ union {
off_t req_offset; /* used for:
/* the length in bytes of the region being requested */ * VM_REQUEST_READ
size_t req_length; * VM_REQUEST_DIRTY
} equeue_packet_page_request_t; */
struct {
off_t req_offset;
/* the length in bytes of the region being requested */
size_t req_length;
};
/* used for:
* VM_REQUEST_ATTACH
*/
struct {
/* the key of the original/source vmo. */
equeue_key_t req_src_vmo;
/* a request ID. used to retrieve information about
* the newly-attached object, as the server won't know
* about it yet, and won't have a handle to it. */
uint64_t req_id;
};
};
} equeue_packet_vm_request_t;
typedef struct { typedef struct {
/* the type of packet. one of EQUEUE_PKT_* */ /* the type of packet. one of EQUEUE_PKT_* */
@@ -192,8 +229,8 @@ typedef struct {
equeue_key_t p_key; equeue_key_t p_key;
union { union {
/* p_type = EQUEUE_PKT_PAGE_REQUEST */ /* p_type = EQUEUE_PKT_VM_REQUEST */
equeue_packet_page_request_t page_request; equeue_packet_vm_request_t vm_request;
/* p_type = EQUEUE_PKT_ASYNC_SIGNAL */ /* p_type = EQUEUE_PKT_ASYNC_SIGNAL */
equeue_packet_async_signal_t async_signal; equeue_packet_async_signal_t async_signal;
}; };
View File
-56
View File
@@ -1,56 +0,0 @@
#ifndef MANGO_SYSCALL_H_
#define MANGO_SYSCALL_H_
#define SYS_KERN_LOG 1
#define SYS_KERN_HANDLE_CLOSE 2
#define SYS_KERN_HANDLE_TRANSFER 3
#define SYS_KERN_CONFIG_GET 4
#define SYS_KERN_CONFIG_SET 5
#define SYS_KERN_OBJECT_WAIT 6
#define SYS_KERN_OBJECT_WAIT_ASYNC 7
#define SYS_TASK_EXIT 8
#define SYS_TASK_SELF 9
#define SYS_TASK_CREATE 10
#define SYS_TASK_CREATE_THREAD 11
#define SYS_TASK_GET_ADDRESS_SPACE 12
#define SYS_TASK_CONFIG_GET 13
#define SYS_TASK_CONFIG_SET 14
#define SYS_THREAD_SELF 15
#define SYS_THREAD_START 16
#define SYS_THREAD_EXIT 17
#define SYS_THREAD_CONFIG_GET 18
#define SYS_THREAD_CONFIG_SET 19
#define SYS_VM_OBJECT_CREATE 20
#define SYS_VM_OBJECT_READ 21
#define SYS_VM_OBJECT_WRITE 22
#define SYS_VM_OBJECT_COPY 23
#define SYS_ADDRESS_SPACE_READ 24
#define SYS_ADDRESS_SPACE_WRITE 25
#define SYS_ADDRESS_SPACE_MAP 26
#define SYS_ADDRESS_SPACE_UNMAP 27
#define SYS_ADDRESS_SPACE_RESERVE 28
#define SYS_ADDRESS_SPACE_RELEASE 29
#define SYS_MSG_SEND 30
#define SYS_MSG_RECV 31
#define SYS_MSG_REPLY 32
#define SYS_MSG_READ 33
#define SYS_MSG_WRITE 34
#define SYS_CHANNEL_CREATE 35
#define SYS_PORT_CREATE 36
#define SYS_PORT_CONNECT 37
#define SYS_PORT_DISCONNECT 38
#define SYS_EQUEUE_CREATE 39
#define SYS_EQUEUE_DEQUEUE 40
#define SYS_VM_CONTROLLER_CREATE 41
#define SYS_VM_CONTROLLER_RECV 42
#define SYS_VM_CONTROLLER_RECV_ASYNC 43
#define SYS_VM_CONTROLLER_CREATE_OBJECT 44
#define SYS_VM_CONTROLLER_DETACH_OBJECT 45
#define SYS_VM_CONTROLLER_SUPPLY_PAGES 46
#define SYS_FUTEX_WAIT 47
#define SYS_FUTEX_WAKE 48
#define SYS_KERN_OBJECT_QUERY 49
#define SYS_TASK_DUPLICATE 50
#define SYS_KERN_HANDLE_CONTROL 51
#endif
+54 -2
View File
@@ -171,8 +171,13 @@ struct task *task_alloc(void)
return t; return t;
} }
struct task *task_create(const char *name, size_t name_len) struct task *task_create(
struct task *parent,
task_flags_t task_flags,
const char *name,
size_t name_len)
{ {
kern_status_t status = KERN_OK;
struct task *task = task_alloc(); struct task *task = task_alloc();
if (!task) { if (!task) {
return NULL; return NULL;
@@ -191,9 +196,21 @@ struct task *task_create(const char *name, size_t name_len)
VM_USER_LIMIT, VM_USER_LIMIT,
&task->t_address_space); &task->t_address_space);
if (task_flags & TASK_F_CLONE_ALL_HANDLES) {
status = handle_table_duplicate(
parent->t_handles,
&task->t_handles);
} else {
task->t_handles = handle_table_create();
}
if (status != KERN_OK) {
object_unref(&task->t_base);
return NULL;
}
task->t_address_space->s_pmap = pmap; task->t_address_space->s_pmap = pmap;
task->t_state = TASK_RUNNING; task->t_state = TASK_RUNNING;
task->t_handles = handle_table_create();
if (name) { if (name) {
name_len = MIN(name_len, sizeof task->t_name - 1); name_len = MIN(name_len, sizeof task->t_name - 1);
@@ -280,6 +297,40 @@ struct task *task_from_tid(tid_t id)
return t; return t;
} }
kern_status_t task_config_get(
struct task *task,
kern_config_key_t key,
void *out,
size_t max)
{
switch (key) {
case TASK_CFG_ID: {
if (max != sizeof(tid_t)) {
return KERN_INVALID_ARGUMENT;
}
tid_t *value = out;
*value = task->t_id;
return KERN_OK;
}
default:
return KERN_INVALID_ARGUMENT;
}
}
kern_status_t task_config_set(
struct task *task,
kern_config_key_t key,
const void *ptr,
size_t len)
{
switch (key) {
default:
return KERN_INVALID_ARGUMENT;
}
}
void task_exit(int status) void task_exit(int status)
{ {
struct task *self = get_current_task(); struct task *self = get_current_task();
@@ -325,6 +376,7 @@ void task_exit(int status)
spin_lock(&self->t_handles_lock); spin_lock(&self->t_handles_lock);
pmap_switch(get_kernel_pmap()); pmap_switch(get_kernel_pmap());
self->t_address_space->s_pmap = PMAP_INVALID;
pmap_destroy(self->t_pmap); pmap_destroy(self->t_pmap);
task_unlock(self); task_unlock(self);
+7 -2
View File
@@ -5,7 +5,7 @@
#include <kernel/printk.h> #include <kernel/printk.h>
#include <kernel/task.h> #include <kernel/task.h>
#include <kernel/thread.h> #include <kernel/thread.h>
#include <mango/signal.h> #include <magenta/signal.h>
#define THREAD_CAST(p) OBJECT_C_CAST(struct thread, tr_base, &thread_type, p) #define THREAD_CAST(p) OBJECT_C_CAST(struct thread, tr_base, &thread_type, p)
@@ -131,7 +131,12 @@ kern_status_t thread_init_user_clone(
/* this context will be used by ml_user_return to jump to userspace /* this context will be used by ml_user_return to jump to userspace
* with the specified instruction pointer and user stack */ * with the specified instruction pointer and user stack */
ml_thread_clone_user_context(src->tr_irqctx, return_value, &thr->tr_sp); ml_thread_clone_user_context(
src->tr_irqctx,
&src->tr_ml,
&thr->tr_ml,
return_value,
&thr->tr_sp);
/* this context will be used by the scheduler and ml_thread_switch to /* this context will be used by the scheduler and ml_thread_switch to
* jump to ml_user_return in kernel mode with the thread's kernel stack. * jump to ml_user_return in kernel mode with the thread's kernel stack.
*/ */
+11 -9
View File
@@ -125,6 +125,7 @@ kern_status_t sys_address_space_map(
kern_handle_t object_handle, kern_handle_t object_handle,
off_t object_offset, off_t object_offset,
size_t length, size_t length,
vm_flags_t flags,
vm_prot_t prot, vm_prot_t prot,
virt_addr_t *out_base_address) virt_addr_t *out_base_address)
{ {
@@ -140,8 +141,8 @@ kern_status_t sys_address_space_map(
} }
kern_status_t status = KERN_OK; kern_status_t status = KERN_OK;
unsigned long flags; unsigned long irq_flags;
task_lock_irqsave(self, &flags); task_lock_irqsave(self, &irq_flags);
struct object *region_obj = NULL, *vmo_obj = NULL; struct object *region_obj = NULL, *vmo_obj = NULL;
handle_flags_t region_flags = 0, vmo_flags = 0; handle_flags_t region_flags = 0, vmo_flags = 0;
@@ -151,34 +152,34 @@ kern_status_t sys_address_space_map(
&region_obj, &region_obj,
&region_flags); &region_flags);
if (status != KERN_OK) { if (status != KERN_OK) {
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, irq_flags);
put_current_task(self); put_current_task(self);
return status; return status;
} }
status = task_resolve_handle(self, object_handle, &vmo_obj, &vmo_flags); status = task_resolve_handle(self, object_handle, &vmo_obj, &vmo_flags);
if (status != KERN_OK) { if (status != KERN_OK) {
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, irq_flags);
put_current_task(self); put_current_task(self);
return status; return status;
} }
struct address_space *region = address_space_cast(region_obj); struct address_space *region = address_space_cast(region_obj);
if (!region) { if (!region) {
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, irq_flags);
put_current_task(self); put_current_task(self);
return KERN_INVALID_ARGUMENT; return KERN_INVALID_ARGUMENT;
} }
struct vm_object *vmo = vm_object_cast(vmo_obj); struct vm_object *vmo = vm_object_cast(vmo_obj);
if (!vmo) { if (!vmo) {
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, irq_flags);
put_current_task(self); put_current_task(self);
return KERN_INVALID_ARGUMENT; return KERN_INVALID_ARGUMENT;
} }
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, irq_flags);
address_space_lock_irqsave(region, &flags); address_space_lock_irqsave(region, &irq_flags);
/* address_space_map will take care of locking `vmo` */ /* address_space_map will take care of locking `vmo` */
status = address_space_map( status = address_space_map(
region, region,
@@ -186,9 +187,10 @@ kern_status_t sys_address_space_map(
vmo, vmo,
object_offset, object_offset,
length, length,
flags,
prot, prot,
out_base_address); out_base_address);
address_space_unlock_irqrestore(region, flags); address_space_unlock_irqrestore(region, irq_flags);
object_unref(vmo_obj); object_unref(vmo_obj);
object_unref(region_obj); object_unref(region_obj);
+8
View File
@@ -11,6 +11,8 @@ static const virt_addr_t syscall_table[] = {
SYSCALL_TABLE_ENTRY(TASK_CREATE_THREAD, task_create_thread), SYSCALL_TABLE_ENTRY(TASK_CREATE_THREAD, task_create_thread),
SYSCALL_TABLE_ENTRY(TASK_GET_ADDRESS_SPACE, task_get_address_space), SYSCALL_TABLE_ENTRY(TASK_GET_ADDRESS_SPACE, task_get_address_space),
SYSCALL_TABLE_ENTRY(TASK_DUPLICATE, task_duplicate), SYSCALL_TABLE_ENTRY(TASK_DUPLICATE, task_duplicate),
SYSCALL_TABLE_ENTRY(TASK_CONFIG_GET, task_config_get),
SYSCALL_TABLE_ENTRY(TASK_CONFIG_SET, task_config_set),
SYSCALL_TABLE_ENTRY(THREAD_SELF, thread_self), SYSCALL_TABLE_ENTRY(THREAD_SELF, thread_self),
SYSCALL_TABLE_ENTRY(THREAD_START, thread_start), SYSCALL_TABLE_ENTRY(THREAD_START, thread_start),
SYSCALL_TABLE_ENTRY(THREAD_EXIT, thread_exit), SYSCALL_TABLE_ENTRY(THREAD_EXIT, thread_exit),
@@ -47,6 +49,12 @@ static const virt_addr_t syscall_table[] = {
SYSCALL_TABLE_ENTRY( SYSCALL_TABLE_ENTRY(
VM_CONTROLLER_CREATE_OBJECT, VM_CONTROLLER_CREATE_OBJECT,
vm_controller_create_object), vm_controller_create_object),
SYSCALL_TABLE_ENTRY(
VM_CONTROLLER_PREPARE_ATTACH,
vm_controller_prepare_attach),
SYSCALL_TABLE_ENTRY(
VM_CONTROLLER_FINISH_ATTACH,
vm_controller_finish_attach),
SYSCALL_TABLE_ENTRY( SYSCALL_TABLE_ENTRY(
VM_CONTROLLER_DETACH_OBJECT, VM_CONTROLLER_DETACH_OBJECT,
vm_controller_detach_object), vm_controller_detach_object),
+4 -2
View File
@@ -61,6 +61,7 @@ kern_status_t sys_kern_handle_transfer(
src_task = task_cast(obj); src_task = task_cast(obj);
if (!src_task) { if (!src_task) {
status = KERN_INVALID_ARGUMENT; status = KERN_INVALID_ARGUMENT;
task_unlock_irqrestore(self, flags);
goto cleanup; goto cleanup;
} }
} else { } else {
@@ -81,6 +82,7 @@ kern_status_t sys_kern_handle_transfer(
dest_task = task_cast(obj); dest_task = task_cast(obj);
if (!dest_task) { if (!dest_task) {
status = KERN_INVALID_ARGUMENT; status = KERN_INVALID_ARGUMENT;
task_unlock_irqrestore(self, flags);
goto cleanup; goto cleanup;
} }
} else { } else {
@@ -92,12 +94,12 @@ kern_status_t sys_kern_handle_transfer(
src_handle, src_handle,
&src_object, &src_object,
&handle_flags); &handle_flags);
task_unlock_irqrestore(self, flags);
if (status != KERN_OK) { if (status != KERN_OK) {
goto cleanup; goto cleanup;
} }
task_unlock_irqrestore(self, flags);
struct handle *dest = NULL; struct handle *dest = NULL;
task_lock_irqsave(dest_task, &flags); task_lock_irqsave(dest_task, &flags);
status = handle_table_alloc_handle( status = handle_table_alloc_handle(
+2 -2
View File
@@ -4,8 +4,8 @@
#include <kernel/task.h> #include <kernel/task.h>
#include <kernel/thread.h> #include <kernel/thread.h>
#include <kernel/wait.h> #include <kernel/wait.h>
#include <mango/status.h> #include <magenta/status.h>
#include <mango/types.h> #include <magenta/types.h>
kern_status_t sys_kern_object_wait(kern_wait_item_t *items, size_t nr_items) kern_status_t sys_kern_object_wait(kern_wait_item_t *items, size_t nr_items)
{ {
+97 -8
View File
@@ -53,6 +53,7 @@ kern_status_t sys_task_self(kern_handle_t *out)
kern_status_t sys_task_create( kern_status_t sys_task_create(
kern_handle_t parent_handle, kern_handle_t parent_handle,
task_flags_t task_flags,
const char *name, const char *name,
size_t name_len, size_t name_len,
kern_handle_t *out_task, kern_handle_t *out_task,
@@ -124,7 +125,7 @@ kern_status_t sys_task_create(
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
struct task *child = task_create(name, name_len); struct task *child = task_create(parent, task_flags, name, name_len);
if (!child) { if (!child) {
object_unref(parent_obj); object_unref(parent_obj);
@@ -291,6 +292,89 @@ kern_status_t sys_task_get_address_space(
return KERN_OK; return KERN_OK;
} }
kern_status_t sys_task_config_get(
kern_handle_t task_handle,
kern_config_key_t key,
void *ptr,
size_t len)
{
unsigned long flags;
struct task *self = get_current_task();
if (!validate_access_w(self, ptr, len)) {
put_current_task(self);
return KERN_MEMORY_FAULT;
}
struct object *task_obj;
handle_flags_t task_flags;
task_lock_irqsave(self, &flags);
kern_status_t status = task_resolve_handle(
self,
task_handle,
&task_obj,
&task_flags);
put_current_task(self);
task_unlock_irqrestore(self, flags);
if (status != KERN_OK) {
return status;
}
struct task *task = task_cast(task_obj);
task_unlock_irqrestore(self, flags);
if (task) {
status = task_config_get(task, key, ptr, len);
} else {
status = KERN_INVALID_ARGUMENT;
}
object_unref(task_obj);
return status;
}
kern_status_t sys_task_config_set(
kern_handle_t task_handle,
kern_config_key_t key,
const void *ptr,
size_t len)
{
unsigned long flags;
struct task *self = get_current_task();
if (!validate_access_w(self, ptr, len)) {
put_current_task(self);
return KERN_MEMORY_FAULT;
}
struct object *task_obj;
handle_flags_t task_flags;
task_lock_irqsave(self, &flags);
kern_status_t status = task_resolve_handle(
self,
task_handle,
&task_obj,
&task_flags);
task_unlock_irqrestore(self, flags);
put_current_task(self);
if (status != KERN_OK) {
return status;
}
struct task *task = task_cast(task_obj);
if (task) {
status = task_config_set(task, key, ptr, len);
} else {
status = KERN_INVALID_ARGUMENT;
}
object_unref(task_obj);
return status;
}
kern_status_t sys_thread_self(kern_handle_t *out) kern_status_t sys_thread_self(kern_handle_t *out)
{ {
struct task *self = get_current_task(); struct task *self = get_current_task();
@@ -493,7 +577,11 @@ kern_status_t sys_task_duplicate(
return status; return status;
} }
struct task *new_task = task_create(self->t_name, strlen(self->t_name)); struct task *new_task = task_create(
self,
TASK_F_CLONE_ALL_HANDLES,
self->t_name,
strlen(self->t_name));
if (!new_task) { if (!new_task) {
put_current_task(self); put_current_task(self);
return KERN_NO_MEMORY; return KERN_NO_MEMORY;
@@ -526,18 +614,19 @@ kern_status_t sys_task_duplicate(
return status; return status;
} }
schedule_thread_on_cpu(new_thread);
child_handle_slot->h_object = &new_task->t_base; child_handle_slot->h_object = &new_task->t_base;
space_handle_slot->h_object = &new_task->t_address_space->s_base; space_handle_slot->h_object
= object_ref(&new_task->t_address_space->s_base);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
/* clear TLB */
pmap_flush();
put_current_task(self);
*out_task = child_handle; *out_task = child_handle;
*out_address_space = space_handle; *out_address_space = space_handle;
/* clear TLB */ schedule_thread_on_cpu(new_thread);
pmap_switch(self->t_pmap);
put_current_task(self);
return KERN_OK; return KERN_OK;
} }
+130 -9
View File
@@ -32,7 +32,7 @@ kern_status_t sys_vm_controller_create(kern_handle_t *out)
kern_status_t sys_vm_controller_recv( kern_status_t sys_vm_controller_recv(
kern_handle_t ctrl_handle, kern_handle_t ctrl_handle,
equeue_packet_page_request_t *out) equeue_packet_vm_request_t *out)
{ {
struct task *self = get_current_task(); struct task *self = get_current_task();
@@ -148,8 +148,8 @@ kern_status_t sys_vm_controller_create_object(
} }
kern_status_t status = KERN_OK; kern_status_t status = KERN_OK;
unsigned long flags; unsigned long irq_flags;
task_lock_irqsave(self, &flags); task_lock_irqsave(self, &irq_flags);
struct object *ctrl_obj = NULL; struct object *ctrl_obj = NULL;
handle_flags_t handle_flags = 0; handle_flags_t handle_flags = 0;
@@ -159,7 +159,7 @@ kern_status_t sys_vm_controller_create_object(
&ctrl_obj, &ctrl_obj,
&handle_flags); &handle_flags);
if (status != KERN_OK) { if (status != KERN_OK) {
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, irq_flags);
put_current_task(self); put_current_task(self);
return status; return status;
} }
@@ -173,14 +173,14 @@ kern_status_t sys_vm_controller_create_object(
&out_handle); &out_handle);
struct vm_controller *ctrl = vm_controller_cast(ctrl_obj); struct vm_controller *ctrl = vm_controller_cast(ctrl_obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, irq_flags);
if (!ctrl) { if (!ctrl) {
object_unref(ctrl_obj); object_unref(ctrl_obj);
put_current_task(self); put_current_task(self);
return KERN_INVALID_ARGUMENT; return KERN_INVALID_ARGUMENT;
} }
vm_controller_lock_irqsave(ctrl, &flags); vm_controller_lock_irqsave(ctrl, &irq_flags);
struct vm_object *out_vmo = NULL; struct vm_object *out_vmo = NULL;
status = vm_controller_create_object( status = vm_controller_create_object(
ctrl, ctrl,
@@ -190,14 +190,14 @@ kern_status_t sys_vm_controller_create_object(
data_len, data_len,
prot, prot,
&out_vmo); &out_vmo);
vm_controller_unlock_irqrestore(ctrl, flags); vm_controller_unlock_irqrestore(ctrl, irq_flags);
object_unref(ctrl_obj); object_unref(ctrl_obj);
if (status != KERN_OK) { if (status != KERN_OK) {
task_lock_irqsave(self, &flags); task_lock_irqsave(self, &irq_flags);
handle_table_free_handle(self->t_handles, out_handle); handle_table_free_handle(self->t_handles, out_handle);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, irq_flags);
put_current_task(self); put_current_task(self);
return status; return status;
} }
@@ -209,6 +209,116 @@ kern_status_t sys_vm_controller_create_object(
return KERN_OK; return KERN_OK;
} }
kern_status_t sys_vm_controller_prepare_attach(
kern_handle_t ctrl_handle,
uint64_t req_id,
kern_handle_t *out_vmo)
{
struct task *self = get_current_task();
if (!out_vmo || !validate_access_w(self, out_vmo, sizeof *out_vmo)) {
return KERN_MEMORY_FAULT;
}
kern_status_t status = KERN_OK;
unsigned long flags;
task_lock_irqsave(self, &flags);
struct object *ctrl_obj = NULL;
handle_flags_t ctrl_flags = 0;
status = task_resolve_handle(self, ctrl_handle, &ctrl_obj, &ctrl_flags);
if (status != KERN_OK) {
task_unlock_irqrestore(self, flags);
put_current_task(self);
return status;
}
struct handle *out_slot = NULL;
kern_handle_t out_handle = KERN_HANDLE_INVALID;
status = handle_table_alloc_handle(
self->t_handles,
KERN_HANDLE_INVALID,
&out_slot,
&out_handle);
if (status != KERN_OK) {
object_unref(ctrl_obj);
task_unlock_irqrestore(self, flags);
put_current_task(self);
return status;
}
struct vm_controller *ctrl = vm_controller_cast(ctrl_obj);
task_unlock_irqrestore(self, flags);
if (!ctrl) {
object_unref(ctrl_obj);
return KERN_INVALID_ARGUMENT;
}
vm_controller_lock_irqsave(ctrl, &flags);
struct vm_object *vmo = NULL;
status = vm_controller_prepare_attach(ctrl, req_id, &vmo);
vm_controller_unlock_irqrestore(ctrl, flags);
object_unref(ctrl_obj);
if (status != KERN_OK) {
task_lock_irqsave(self, &flags);
handle_table_free_handle(self->t_handles, out_handle);
task_unlock_irqrestore(self, flags);
return status;
}
out_slot->h_object = &vmo->vo_base;
put_current_task(self);
*out_vmo = out_handle;
return KERN_OK;
}
kern_status_t sys_vm_controller_finish_attach(
kern_handle_t ctrl_handle,
uint64_t req_id,
equeue_key_t new_key)
{
struct task *self = get_current_task();
kern_status_t status = KERN_OK;
unsigned long flags;
task_lock_irqsave(self, &flags);
struct object *ctrl_obj = NULL;
handle_flags_t ctrl_flags = 0;
status = task_resolve_handle(self, ctrl_handle, &ctrl_obj, &ctrl_flags);
if (status != KERN_OK) {
task_unlock_irqrestore(self, flags);
put_current_task(self);
return status;
}
struct vm_controller *ctrl = vm_controller_cast(ctrl_obj);
task_unlock_irqrestore(self, flags);
put_current_task(self);
if (!ctrl) {
object_unref(ctrl_obj);
return KERN_INVALID_ARGUMENT;
}
vm_controller_lock_irqsave(ctrl, &flags);
status = vm_controller_finish_attach(ctrl, req_id, new_key);
vm_controller_unlock_irqrestore(ctrl, flags);
object_unref(ctrl_obj);
if (status != KERN_OK) {
return status;
}
return KERN_OK;
}
kern_status_t sys_vm_controller_detach_object( kern_status_t sys_vm_controller_detach_object(
kern_handle_t ctrl_handle, kern_handle_t ctrl_handle,
kern_handle_t vmo_handle) kern_handle_t vmo_handle)
@@ -315,6 +425,8 @@ kern_status_t sys_vm_controller_supply_pages(
vm_controller_lock_irqsave(ctrl, &flags); vm_controller_lock_irqsave(ctrl, &flags);
vm_object_lock_pair(src, dst); vm_object_lock_pair(src, dst);
equeue_key_t requester_key = dst->vo_key;
status = vm_controller_supply_pages( status = vm_controller_supply_pages(
ctrl, ctrl,
dst, dst,
@@ -323,6 +435,12 @@ kern_status_t sys_vm_controller_supply_pages(
src_offset, src_offset,
count); count);
vm_object_unlock_pair(src, dst); vm_object_unlock_pair(src, dst);
vm_controller_fulfill_requests(
ctrl,
requester_key,
dst_offset,
count,
status);
vm_controller_unlock_irqrestore(ctrl, flags); vm_controller_unlock_irqrestore(ctrl, flags);
object_unref(ctrl_obj); object_unref(ctrl_obj);
@@ -330,5 +448,8 @@ kern_status_t sys_vm_controller_supply_pages(
object_unref(src_obj); object_unref(src_obj);
put_current_task(self); put_current_task(self);
/* TODO flush individual pages in vm_object_transfer */
pmap_flush();
return status; return status;
} }
+41 -9
View File
@@ -58,20 +58,31 @@ kern_status_t sys_vm_object_read(
struct object *obj = NULL; struct object *obj = NULL;
handle_flags_t flags = 0; handle_flags_t flags = 0;
unsigned long irq_flags = 0;
task_lock_irqsave(self, &irq_flags);
kern_status_t status = task_resolve_handle(self, object, &obj, &flags); kern_status_t status = task_resolve_handle(self, object, &obj, &flags);
task_unlock_irqrestore(self, irq_flags);
put_current_task(self);
if (status != KERN_OK) { if (status != KERN_OK) {
put_current_task(self);
return status; return status;
} }
struct vm_object *vmo = vm_object_cast(obj); struct vm_object *vmo = vm_object_cast(obj);
if (!vmo) { if (!vmo) {
put_current_task(self); object_unref(obj);
return KERN_INVALID_ARGUMENT; return KERN_INVALID_ARGUMENT;
} }
status = vm_object_read(vmo, dst, offset, count, nr_read); vm_object_lock_irqsave(vmo, &irq_flags);
put_current_task(self); status = vm_object_prefetch(vmo, offset, count, &irq_flags);
if (status == KERN_OK) {
status = vm_object_read(vmo, dst, offset, count, nr_read);
}
vm_object_unlock_irqrestore(vmo, irq_flags);
object_unref(obj);
return status; return status;
} }
@@ -97,20 +108,25 @@ kern_status_t sys_vm_object_write(
struct object *obj = NULL; struct object *obj = NULL;
handle_flags_t flags = 0; handle_flags_t flags = 0;
unsigned long irq_flags = 0;
task_lock_irqsave(self, &irq_flags);
kern_status_t status = task_resolve_handle(self, object, &obj, &flags); kern_status_t status = task_resolve_handle(self, object, &obj, &flags);
task_unlock_irqrestore(self, irq_flags);
put_current_task(self);
if (status != KERN_OK) { if (status != KERN_OK) {
put_current_task(self);
return status; return status;
} }
struct vm_object *vmo = vm_object_cast(obj); struct vm_object *vmo = vm_object_cast(obj);
if (!vmo) { if (!vmo) {
put_current_task(self);
return KERN_INVALID_ARGUMENT; return KERN_INVALID_ARGUMENT;
} }
vm_object_lock_irqsave(vmo, &irq_flags);
status = vm_object_write(vmo, src, offset, count, nr_written); status = vm_object_write(vmo, src, offset, count, nr_written);
put_current_task(self); vm_object_unlock_irqrestore(vmo, irq_flags);
return status; return status;
} }
@@ -162,13 +178,28 @@ kern_status_t sys_vm_object_copy(
put_current_task(self); put_current_task(self);
struct vm_object *dst_vmo = vm_object_cast(dst_obj); struct vm_object *dst_vmo = vm_object_cast(dst_obj);
if (!dst_vmo) {
return KERN_INVALID_ARGUMENT;
}
struct vm_object *src_vmo = vm_object_cast(src_obj); struct vm_object *src_vmo = vm_object_cast(src_obj);
if (!dst_vmo || !src_vmo) { if (!src_vmo) {
object_unref(src_obj);
object_unref(dst_obj); object_unref(dst_obj);
return KERN_INVALID_ARGUMENT; return KERN_INVALID_ARGUMENT;
} }
unsigned long irq_flags = 0;
vm_object_lock_irqsave(src_vmo, &irq_flags);
status = vm_object_prefetch(src_vmo, src_offset, count, &irq_flags);
vm_object_unlock_irqrestore(src_vmo, irq_flags);
if (status != KERN_OK) {
object_unref(src_obj);
object_unref(dst_obj);
return status;
}
vm_object_lock_pair_irqsave(src_vmo, dst_vmo, &irq_flags);
status = vm_object_copy( status = vm_object_copy(
dst_vmo, dst_vmo,
dst_offset, dst_offset,
@@ -176,6 +207,7 @@ kern_status_t sys_vm_object_copy(
src_offset, src_offset,
count, count,
nr_copied); nr_copied);
vm_object_unlock_pair_irqrestore(src_vmo, dst_vmo, irq_flags);
object_unref(src_obj); object_unref(src_obj);
object_unref(dst_obj); object_unref(dst_obj);
+1 -1
View File
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.13)
project(mango-tools C) project(magenta-tools C)
set(tool_dirs e64patch) set(tool_dirs e64patch)
+1 -1
View File
@@ -10,7 +10,7 @@ floppy_bootsig_check: disabled=0
floppya: type=1_44 floppya: type=1_44
# no floppyb # no floppyb
ata0: enabled=true, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14 ata0: enabled=true, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=cdrom, path="build/mango-kernel.iso", status=inserted, model="Generic 1234", biosdetect=auto ata0-master: type=cdrom, path="build/magenta-kernel.iso", status=inserted, model="Generic 1234", biosdetect=auto
ata0-slave: type=none ata0-slave: type=none
ata1: enabled=true, ioaddr1=0x170, ioaddr2=0x370, irq=15 ata1: enabled=true, ioaddr1=0x170, ioaddr2=0x370, irq=15
ata1-master: type=none ata1-master: type=none
+2 -2
View File
@@ -1,4 +1,4 @@
menuentry "Mango Kernel" { menuentry "Magenta Kernel" {
multiboot /boot/mango_kernel multiboot /boot/magenta_kernel
boot boot
} }
+6 -6
View File
@@ -5,9 +5,9 @@ lldb_cfg=$2
shift 2 shift 2
if command -v gdb &> /dev/null; then if command -v gdb &> /dev/null; then
printf " \033[93;1mGDB\033[0m boot/mango_kernel\n" printf " \033[93;1mGDB\033[0m boot/magenta_kernel\n"
tmux \ tmux \
new-session -d -s mango-debug "sleep 0.3; gdb -tui -x $gdb_cfg" \; \ new-session -d -s magenta-debug "sleep 0.3; gdb -tui -x $gdb_cfg" \; \
split-window -h -l 80 \; \ split-window -h -l 80 \; \
split-window -v -l 25 "$@"\; \ split-window -v -l 25 "$@"\; \
select-pane -t 1 \; \ select-pane -t 1 \; \
@@ -15,9 +15,9 @@ if command -v gdb &> /dev/null; then
select-pane -t 0 select-pane -t 0
elif command -v lldb &> /dev/null; then elif command -v lldb &> /dev/null; then
printf " \033[93;1mLLDB\033[0m boot/mango_kernel\n" printf " \033[93;1mLLDB\033[0m boot/magenta_kernel\n"
tmux \ tmux \
new-session -d -s mango-debug "sleep 0.1; lldb --source $lldb_cfg" \; \ new-session -d -s magenta-debug "sleep 0.1; lldb --source $lldb_cfg" \; \
split-window -h -l 160 \; \ split-window -h -l 160 \; \
split-window -v -l 25 "$@"\; \ split-window -v -l 25 "$@"\; \
select-pane -t 1 \; \ select-pane -t 1 \; \
@@ -28,6 +28,6 @@ else
exit -1 exit -1
fi fi
tmux a -t mango-debug tmux a -t magenta-debug
tmux kill-session -t mango-debug tmux kill-session -t magenta-debug
+1 -1
View File
@@ -1,4 +1,4 @@
set confirm off set confirm off
symbol-file mango_kernel.debug symbol-file magenta_kernel.debug
target remote localhost:1234 target remote localhost:1234
set confirm on set confirm on
+1 -1
View File
@@ -1,2 +1,2 @@
file mango_kernel.debug file magenta_kernel.debug
gdb-remote localhost:1234 gdb-remote localhost:1234
@@ -116,7 +116,7 @@ def choice_options(num_devices):
return '1-{}'.format(num_devices) return '1-{}'.format(num_devices)
if not os.path.isfile('build/mango-kernel.iso'): if not os.path.isfile('build/magenta-kernel.iso'):
print('No system ISO image found.') print('No system ISO image found.')
print('Please run \'make cd\' to generate an ISO image') print('Please run \'make cd\' to generate an ISO image')
exit(-1) exit(-1)
@@ -157,7 +157,7 @@ disk_prewrite(devices[choice][0])
dd_args = [ dd_args = [
'sudo', 'sudo',
'dd', 'dd',
'if=build/mango-kernel.iso', 'if=build/magenta-kernel.iso',
'of={}'.format(devices[choice][0]), 'of={}'.format(devices[choice][0]),
'bs=1{}'.format('m' if sys.platform == 'darwin' else 'M') 'bs=1{}'.format('m' if sys.platform == 'darwin' else 'M')
] ]
@@ -7,22 +7,22 @@ import sys
import os import os
import shutil import shutil
kernel_src_path = os.path.join('build', 'mango_kernel') kernel_src_path = os.path.join('build', 'magenta_kernel')
grub_cfg_src_path = os.path.join('tools', 'boot-image', 'grub.cfg') grub_cfg_src_path = os.path.join('tools', 'boot-image', 'grub.cfg')
iso_build_dir = os.path.join('build', 'mango-kernel.iso-build') iso_build_dir = os.path.join('build', 'magenta-kernel.iso-build')
iso_path = os.path.join('build', 'mango-kernel.iso') iso_path = os.path.join('build', 'magenta-kernel.iso')
def in_source_tree(): def in_source_tree():
return os.path.isfile('tools/mango.sync') return os.path.isfile('tools/magenta.sync')
if not in_source_tree(): if not in_source_tree():
print('This script must be executed from the root of the Mango source tree') print('This script must be executed from the root of the Magenta source tree')
exit(-1) exit(-1)
if not os.path.isdir('build'): if not os.path.isdir('build'):
print('Please build the Mango kernel before using this tool') print('Please build the Magenta kernel before using this tool')
exit(-1) exit(-1)
if os.path.isdir(iso_build_dir): if os.path.isdir(iso_build_dir):
@@ -33,7 +33,7 @@ os.mkdir(iso_build_dir)
os.mkdir(os.path.join(iso_build_dir, 'boot')) os.mkdir(os.path.join(iso_build_dir, 'boot'))
os.mkdir(os.path.join(iso_build_dir, 'boot', 'grub')) os.mkdir(os.path.join(iso_build_dir, 'boot', 'grub'))
shutil.copyfile(kernel_src_path, os.path.join(iso_build_dir, 'boot', 'mango_kernel')) shutil.copyfile(kernel_src_path, os.path.join(iso_build_dir, 'boot', 'magenta_kernel'))
shutil.copyfile(grub_cfg_src_path, os.path.join(iso_build_dir, 'boot', 'grub', 'grub.cfg')) shutil.copyfile(grub_cfg_src_path, os.path.join(iso_build_dir, 'boot', 'grub', 'grub.cfg'))
subprocess.run(['grub-mkrescue', '-o', iso_path, iso_build_dir]) subprocess.run(['grub-mkrescue', '-o', iso_path, iso_build_dir])
+2 -2
View File
@@ -16,7 +16,7 @@ rsync_path = os.getenv('RSYNC_PATH', default = 'rsync')
def in_source_tree(): def in_source_tree():
return os.path.isfile('tools/mango.sync') return os.path.isfile('tools/magenta.sync')
def create_sample_config(): def create_sample_config():
@@ -78,7 +78,7 @@ def print_available_targets(targets):
if not in_source_tree(): if not in_source_tree():
print('This script must be executed from the root of the Mango source tree') print('This script must be executed from the root of the Magenta source tree')
exit(-1) exit(-1)
config = read_config() config = read_config()
+61 -27
View File
@@ -6,10 +6,11 @@
#include <kernel/printk.h> #include <kernel/printk.h>
#include <kernel/sched.h> #include <kernel/sched.h>
#include <kernel/task.h> #include <kernel/task.h>
#include <kernel/thread.h>
#include <kernel/util.h> #include <kernel/util.h>
#include <kernel/vm-controller.h> #include <kernel/vm-controller.h>
#include <kernel/vm-object.h> #include <kernel/vm-object.h>
#include <mango/status.h> #include <magenta/status.h>
/*** STATIC DATA + MACROS *****************************************************/ /*** STATIC DATA + MACROS *****************************************************/
@@ -660,9 +661,8 @@ static void area_unmap(struct vm_area *area)
pmap_t pmap = area->vma_space->s_pmap; pmap_t pmap = area->vma_space->s_pmap;
virt_addr_t base = area->vma_base; virt_addr_t base = area->vma_base;
virt_addr_t limit = area->vma_limit; virt_addr_t limit = area->vma_limit;
for (virt_addr_t i = base; i < limit; i += VM_PAGE_SIZE) { pmap_remove_range(pmap, base, limit - base);
pmap_remove(pmap, i); pmap_flush();
}
} }
static kern_status_t address_space_cleanup(struct object *obj) static kern_status_t address_space_cleanup(struct object *obj)
@@ -705,6 +705,7 @@ kern_status_t address_space_map(
struct vm_object *object, struct vm_object *object,
off_t object_offset, off_t object_offset,
size_t length, size_t length,
vm_flags_t flags,
vm_prot_t prot, vm_prot_t prot,
virt_addr_t *out) virt_addr_t *out)
{ {
@@ -762,6 +763,7 @@ kern_status_t address_space_map(
area->vma_space = root; area->vma_space = root;
area->vma_object = object; area->vma_object = object;
area->vma_prot = prot; area->vma_prot = prot;
area->vma_flags = flags;
area->vma_object_offset = object_offset; area->vma_object_offset = object_offset;
area->vma_base = map_address; area->vma_base = map_address;
area->vma_limit = map_address + length - 1; area->vma_limit = map_address + length - 1;
@@ -841,11 +843,9 @@ static kern_status_t split_area(
} }
put_entry(&root->s_mappings, right); put_entry(&root->s_mappings, right);
for (size_t i = unmap_base; i < unmap_limit; i += VM_PAGE_SIZE) {
tracek("pmap_remove %zx", i);
pmap_remove(root->s_pmap, i);
}
pmap_remove_range(root->s_pmap, unmap_base, unmap_limit - unmap_base);
pmap_flush();
return KERN_OK; return KERN_OK;
} }
@@ -880,10 +880,8 @@ static kern_status_t left_reduce_area(
} }
tracek(" pmap_remove %zx-%zx (%zx bytes)", base, base + length, length); tracek(" pmap_remove %zx-%zx (%zx bytes)", base, base + length, length);
for (size_t i = base; i < limit; i += VM_PAGE_SIZE) { pmap_remove_range(root->s_pmap, base, length);
pmap_remove(root->s_pmap, i); pmap_flush();
}
return KERN_OK; return KERN_OK;
} }
@@ -917,10 +915,8 @@ static kern_status_t right_reduce_area(
} }
tracek(" pmap_remove %zx-%zx (%zx bytes)", base, base + length, length); tracek(" pmap_remove %zx-%zx (%zx bytes)", base, base + length, length);
for (size_t i = base; i < limit; i += VM_PAGE_SIZE) { pmap_remove_range(root->s_pmap, base, limit - base);
pmap_remove(root->s_pmap, i); pmap_flush();
}
return KERN_OK; return KERN_OK;
} }
@@ -939,10 +935,11 @@ static kern_status_t delete_area(
mapping->vma_limit, mapping->vma_limit,
mapping->vma_limit - mapping->vma_base); mapping->vma_limit - mapping->vma_base);
for (size_t i = mapping->vma_base; i < mapping->vma_limit; pmap_remove_range(
i += VM_PAGE_SIZE) { root->s_pmap,
pmap_remove(root->s_pmap, i); mapping->vma_base,
} mapping->vma_limit - mapping->vma_base);
pmap_flush();
struct vm_object *object = mapping->vma_object; struct vm_object *object = mapping->vma_object;
unsigned long flags; unsigned long flags;
@@ -1214,6 +1211,7 @@ static struct vm_area *area_duplicate(struct vm_area *area)
} }
out->vma_prot = area->vma_prot; out->vma_prot = area->vma_prot;
out->vma_flags = area->vma_flags;
out->vma_object_offset = area->vma_object_offset; out->vma_object_offset = area->vma_object_offset;
out->vma_base = area->vma_base; out->vma_base = area->vma_base;
out->vma_limit = area->vma_limit; out->vma_limit = area->vma_limit;
@@ -1280,7 +1278,8 @@ static kern_status_t prepare_duplicate_areas(
struct vm_object *src_vmo = tmp_area->vma_object; struct vm_object *src_vmo = tmp_area->vma_object;
vm_object_lock(src_vmo); vm_object_lock(src_vmo);
struct vm_object *dest_vmo = NULL; struct vm_object *dest_vmo_link = NULL;
struct vm_object *dest_vmo_cow = NULL;
struct queue_entry *cur_entry struct queue_entry *cur_entry
= queue_first(&src_vmo->vo_mappings); = queue_first(&src_vmo->vo_mappings);
@@ -1311,6 +1310,13 @@ static kern_status_t prepare_duplicate_areas(
continue; continue;
} }
struct vm_object *dest_vmo = NULL;
if (src_area->vma_flags & VM_SHARED) {
dest_vmo = dest_vmo_link;
} else {
dest_vmo = dest_vmo_cow;
}
if (!dest_vmo) { if (!dest_vmo) {
tracek("[%zx-%zx %x] creating COW duplicate of " tracek("[%zx-%zx %x] creating COW duplicate of "
"vmo %p", "vmo %p",
@@ -1318,7 +1324,18 @@ static kern_status_t prepare_duplicate_areas(
src_area->vma_limit, src_area->vma_limit,
src_area->vma_prot, src_area->vma_prot,
src_vmo); src_vmo);
dest_vmo = vm_object_duplicate_cow(src_vmo);
if (src_area->vma_flags & VM_SHARED) {
dest_vmo_link = src_vmo;
object_ref(&dest_vmo_link->vo_base);
dest_vmo = dest_vmo_link;
} else {
dest_vmo_cow = vm_object_duplicate_cow(
src_vmo);
dest_vmo = dest_vmo_cow;
}
tracek("[%zx-%zx %x] created COW duplicate of " tracek("[%zx-%zx %x] created COW duplicate of "
"vmo %p -> %p", "vmo %p -> %p",
src_area->vma_base, src_area->vma_base,
@@ -1328,11 +1345,20 @@ static kern_status_t prepare_duplicate_areas(
dest_vmo); dest_vmo);
} }
object_ref(&dest_vmo->vo_base);
dest_area->vma_object = dest_vmo; dest_area->vma_object = dest_vmo;
update_area_pte_cow(src, dest, src_area); update_area_pte_cow(src, dest, src_area);
cur_entry = queue_next(cur_entry); cur_entry = queue_next(cur_entry);
} }
if (dest_vmo_link) {
object_unref(&dest_vmo_link->vo_base);
}
if (dest_vmo_cow) {
object_unref(&dest_vmo_cow->vo_base);
}
vm_object_unlock(src_vmo); vm_object_unlock(src_vmo);
cur_node = btree_next(cur_node); cur_node = btree_next(cur_node);
@@ -1502,6 +1528,17 @@ static kern_status_t request_missing_page(
vm_object_lock(object); vm_object_lock(object);
address_space_unlock(region); address_space_unlock(region);
kern_status_t status = KERN_OK;
if (object->vo_flags & VMO_LAZY_ATTACH) {
status = vm_object_attach_cow(object, irq_flags);
}
if (status != KERN_OK) {
vm_object_unlock_irqrestore(object, *irq_flags);
return status;
}
struct vm_page *pg = vm_object_get_page( struct vm_page *pg = vm_object_get_page(
object, object,
object_offset, object_offset,
@@ -1515,7 +1552,7 @@ static kern_status_t request_missing_page(
/* now: `region` is unlocked, and `object` is locked */ /* now: `region` is unlocked, and `object` is locked */
kern_status_t status = pmap_add( status = pmap_add(
region->s_pmap, region->s_pmap,
addr, addr,
vm_page_get_pfn(pg), vm_page_get_pfn(pg),
@@ -1550,9 +1587,6 @@ static kern_status_t handle_cow_access(
} }
tracek("cow access %zx", addr); tracek("cow access %zx", addr);
if (area->vma_object->vo_ctrl) {
panic("COW on controlled vm-object");
}
off_t object_offset = addr - area->vma_base + area->vma_object_offset; off_t object_offset = addr - area->vma_base + area->vma_object_offset;
vm_object_lock(area->vma_object); vm_object_lock(area->vma_object);
@@ -1663,7 +1697,7 @@ kern_status_t address_space_demand_map(
address_space_lock_irqsave(region, &irq_flags); address_space_lock_irqsave(region, &irq_flags);
const enum pmap_fault_flags cow_flags const enum pmap_fault_flags cow_flags
= PMAP_FAULT_WRITE | PMAP_FAULT_PRESENT | PMAP_FAULT_USER; = PMAP_FAULT_WRITE | PMAP_FAULT_PRESENT;
if ((flags & cow_flags) == cow_flags) { if ((flags & cow_flags) == cow_flags) {
return handle_cow_access(region, addr, flags, &irq_flags); return handle_cow_access(region, addr, flags, &irq_flags);
+1 -1
View File
@@ -6,7 +6,7 @@
#include <kernel/vm-object.h> #include <kernel/vm-object.h>
#include <kernel/vm.h> #include <kernel/vm.h>
#include <limits.h> #include <limits.h>
#include <mango/status.h> #include <magenta/status.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
+102 -44
View File
@@ -4,18 +4,17 @@
#include <kernel/util.h> #include <kernel/util.h>
#include <kernel/vm-controller.h> #include <kernel/vm-controller.h>
#include <kernel/vm-object.h> #include <kernel/vm-object.h>
#include <mango/signal.h> #include <magenta/signal.h>
#define VM_CONTROLLER_CAST(p) \ #define VM_CONTROLLER_CAST(p) \
OBJECT_C_CAST(struct vm_controller, vc_base, &vm_controller_type, p) OBJECT_C_CAST(struct vm_controller, vc_base, &vm_controller_type, p)
BTREE_DEFINE_SIMPLE_INSERT(struct vm_object, vo_ctrl_node, vo_key, put_object)
BTREE_DEFINE_SIMPLE_GET( BTREE_DEFINE_SIMPLE_GET(
struct vm_object, struct vm_request,
equeue_key_t, uint64_t,
vo_ctrl_node, req_node,
vo_key, req_id,
get_object) get_request)
static struct object_type vm_controller_type = { static struct object_type vm_controller_type = {
.ob_name = "vm-controller", .ob_name = "vm-controller",
@@ -23,14 +22,14 @@ static struct object_type vm_controller_type = {
.ob_header_offset = offsetof(struct vm_controller, vc_base), .ob_header_offset = offsetof(struct vm_controller, vc_base),
}; };
static struct vm_cache page_request_cache = { static struct vm_cache vm_request_cache = {
.c_name = "page-request", .c_name = "vm-request",
.c_obj_size = sizeof(struct page_request), .c_obj_size = sizeof(struct vm_request),
}; };
kern_status_t vm_controller_type_init(void) kern_status_t vm_controller_type_init(void)
{ {
vm_cache_init(&page_request_cache); vm_cache_init(&vm_request_cache);
return object_type_register(&vm_controller_type); return object_type_register(&vm_controller_type);
} }
@@ -51,19 +50,19 @@ struct vm_controller *vm_controller_create(void)
return ctrl; return ctrl;
} }
static struct page_request *get_next_request(struct vm_controller *ctrl) static struct vm_request *get_next_request(struct vm_controller *ctrl)
{ {
struct btree_node *cur = btree_first(&ctrl->vc_requests); struct btree_node *cur = btree_first(&ctrl->vc_requests);
while (cur) { while (cur) {
struct page_request *req struct vm_request *req
= BTREE_CONTAINER(struct page_request, req_node, cur); = BTREE_CONTAINER(struct vm_request, req_node, cur);
spin_lock(&req->req_lock); spin_lock(&req->req_lock);
switch (req->req_status) { switch (req->req_status) {
case PAGE_REQUEST_PENDING: case VM_REQUEST_PENDING:
req->req_status = PAGE_REQUEST_IN_PROGRESS; req->req_status = VM_REQUEST_IN_PROGRESS;
ctrl->vc_requests_waiting--; ctrl->vc_requests_waiting--;
return req; return req;
case PAGE_REQUEST_ASYNC: case VM_REQUEST_ASYNC:
btree_delete(&ctrl->vc_requests, &req->req_node); btree_delete(&ctrl->vc_requests, &req->req_node);
ctrl->vc_requests_waiting--; ctrl->vc_requests_waiting--;
return req; return req;
@@ -78,7 +77,7 @@ static struct page_request *get_next_request(struct vm_controller *ctrl)
return NULL; return NULL;
} }
static kern_status_t try_enqueue(struct btree *tree, struct page_request *req) static kern_status_t try_enqueue(struct btree *tree, struct vm_request *req)
{ {
if (!tree->b_root) { if (!tree->b_root) {
tree->b_root = &req->req_node; tree->b_root = &req->req_node;
@@ -88,8 +87,8 @@ static kern_status_t try_enqueue(struct btree *tree, struct page_request *req)
struct btree_node *cur = tree->b_root; struct btree_node *cur = tree->b_root;
while (1) { while (1) {
struct page_request *cur_node struct vm_request *cur_node
= BTREE_CONTAINER(struct page_request, req_node, cur); = BTREE_CONTAINER(struct vm_request, req_node, cur);
struct btree_node *next = NULL; struct btree_node *next = NULL;
if (req->req_id > cur_node->req_id) { if (req->req_id > cur_node->req_id) {
@@ -119,7 +118,7 @@ static kern_status_t try_enqueue(struct btree *tree, struct page_request *req)
static kern_status_t send_request_async( static kern_status_t send_request_async(
struct vm_controller *ctrl, struct vm_controller *ctrl,
struct page_request *req) struct vm_request *req)
{ {
fill_random(&req->req_id, sizeof req->req_id); fill_random(&req->req_id, sizeof req->req_id);
while (!try_enqueue(&ctrl->vc_requests, req)) { while (!try_enqueue(&ctrl->vc_requests, req)) {
@@ -136,9 +135,9 @@ static kern_status_t send_request_async(
kern_status_t vm_controller_recv( kern_status_t vm_controller_recv(
struct vm_controller *ctrl, struct vm_controller *ctrl,
equeue_packet_page_request_t *out) equeue_packet_vm_request_t *out)
{ {
struct page_request *req = NULL; struct vm_request *req = NULL;
req = get_next_request(ctrl); req = get_next_request(ctrl);
if (!req) { if (!req) {
@@ -151,16 +150,30 @@ kern_status_t vm_controller_recv(
VM_CONTROLLER_SIGNAL_REQUEST_RECEIVED); VM_CONTROLLER_SIGNAL_REQUEST_RECEIVED);
} }
out->req_vmo = req->req_object; vm_object_lock(req->req_object);
out->req_id = req->req_id;
out->req_vmo = req->req_object->vo_key;
out->req_type = req->req_type; out->req_type = req->req_type;
out->req_offset = req->req_offset;
out->req_length = req->req_length;
switch (req->req_type) {
case VM_REQUEST_READ:
case VM_REQUEST_DIRTY:
out->req_offset = req->req_offset;
out->req_length = req->req_length;
break;
case VM_REQUEST_ATTACH:
out->req_src_vmo = req->req_object->vo_key;
break;
default:
break;
}
vm_object_unlock(req->req_object);
spin_unlock(&req->req_lock); spin_unlock(&req->req_lock);
if (req->req_status == PAGE_REQUEST_ASYNC) { if (req->req_status == VM_REQUEST_ASYNC) {
put_current_thread(req->req_sender); put_current_thread(req->req_sender);
vm_cache_free(&page_request_cache, req); vm_cache_free(&vm_request_cache, req);
} }
return KERN_OK; return KERN_OK;
@@ -208,6 +221,52 @@ kern_status_t vm_controller_create_object(
return KERN_OK; return KERN_OK;
} }
kern_status_t vm_controller_prepare_attach(
struct vm_controller *ctrl,
uint64_t req_id,
struct vm_object **out_vmo)
{
struct vm_request *req = get_request(&ctrl->vc_requests, req_id);
if (!req) {
return KERN_INVALID_ARGUMENT;
}
spin_lock(&req->req_lock);
req->req_status = VM_REQUEST_IN_PROGRESS;
*out_vmo = req->req_object;
spin_unlock(&req->req_lock);
return KERN_OK;
}
kern_status_t vm_controller_finish_attach(
struct vm_controller *ctrl,
uint64_t req_id,
equeue_key_t new_key)
{
struct vm_request *req = get_request(&ctrl->vc_requests, req_id);
if (!req) {
return KERN_INVALID_ARGUMENT;
}
spin_lock(&req->req_lock);
struct vm_object *vmo = req->req_object;
spin_unlock(&req->req_lock);
vm_object_lock(vmo);
vmo->vo_key = new_key;
vmo->vo_flags &= ~VMO_LAZY_ATTACH;
vm_object_unlock(vmo);
spin_lock(&req->req_lock);
req->req_status = VM_REQUEST_COMPLETE;
req->req_result = KERN_OK;
thread_awaken(req->req_sender);
spin_unlock(&req->req_lock);
return KERN_OK;
}
kern_status_t vm_controller_detach_object( kern_status_t vm_controller_detach_object(
struct vm_controller *ctrl, struct vm_controller *ctrl,
struct vm_object *vmo) struct vm_object *vmo)
@@ -216,7 +275,7 @@ kern_status_t vm_controller_detach_object(
return KERN_INVALID_ARGUMENT; return KERN_INVALID_ARGUMENT;
} }
if (vmo->vo_key == 0) { if (vmo->vo_flags & VMO_LAZY_ATTACH) {
/* this vmo isn't actually attached to this controller yet. /* this vmo isn't actually attached to this controller yet.
* this can happen if a controller-attached vmo was duplicated * this can happen if a controller-attached vmo was duplicated
* via copy-on-write, and the duplicate vmo has not yet been * via copy-on-write, and the duplicate vmo has not yet been
@@ -225,16 +284,14 @@ kern_status_t vm_controller_detach_object(
return KERN_OK; return KERN_OK;
} }
struct page_request *req struct vm_request *req = vm_cache_alloc(&vm_request_cache, VM_NORMAL);
= vm_cache_alloc(&page_request_cache, VM_NORMAL); req->req_type = VM_REQUEST_DETACH;
req->req_type = PAGE_REQUEST_DETACH; req->req_status = VM_REQUEST_ASYNC;
req->req_status = PAGE_REQUEST_ASYNC; req->req_object = vmo;
req->req_object = vmo->vo_key;
req->req_sender = get_current_thread(); req->req_sender = get_current_thread();
send_request_async(ctrl, req); send_request_async(ctrl, req);
vmo->vo_ctrl = NULL; vmo->vo_ctrl = NULL;
vmo->vo_key = 0;
object_unref(&ctrl->vc_base); object_unref(&ctrl->vc_base);
return KERN_OK; return KERN_OK;
@@ -242,7 +299,7 @@ kern_status_t vm_controller_detach_object(
static void wait_for_reply( static void wait_for_reply(
struct vm_controller *ctrl, struct vm_controller *ctrl,
struct page_request *req, struct vm_request *req,
unsigned long *lock_flags) unsigned long *lock_flags)
{ {
struct wait_item waiter; struct wait_item waiter;
@@ -251,7 +308,7 @@ static void wait_for_reply(
wait_item_init(&waiter, self); wait_item_init(&waiter, self);
for (;;) { for (;;) {
self->tr_state = THREAD_SLEEPING; self->tr_state = THREAD_SLEEPING;
if (req->req_status == PAGE_REQUEST_COMPLETE) { if (req->req_status == VM_REQUEST_COMPLETE) {
break; break;
} }
@@ -264,7 +321,7 @@ static void wait_for_reply(
put_current_thread(self); put_current_thread(self);
} }
static void fulfill_requests( void vm_controller_fulfill_requests(
struct vm_controller *ctrl, struct vm_controller *ctrl,
equeue_key_t object, equeue_key_t object,
off_t offset, off_t offset,
@@ -274,8 +331,8 @@ static void fulfill_requests(
off_t limit = offset + length - 1; off_t limit = offset + length - 1;
struct btree_node *cur = btree_first(&ctrl->vc_requests); struct btree_node *cur = btree_first(&ctrl->vc_requests);
while (cur) { while (cur) {
struct page_request *req struct vm_request *req
= BTREE_CONTAINER(struct page_request, req_node, cur); = BTREE_CONTAINER(struct vm_request, req_node, cur);
spin_lock(&req->req_lock); spin_lock(&req->req_lock);
bool match = false; bool match = false;
off_t req_base = req->req_offset; off_t req_base = req->req_offset;
@@ -287,12 +344,14 @@ static void fulfill_requests(
match = true; match = true;
} }
if (req->req_object != object) { vm_object_lock(req->req_object);
if (req->req_object->vo_key != object) {
match = false; match = false;
} }
vm_object_unlock(req->req_object);
if (match) { if (match) {
req->req_status = PAGE_REQUEST_COMPLETE; req->req_status = VM_REQUEST_COMPLETE;
req->req_result = result; req->req_result = result;
thread_awaken(req->req_sender); thread_awaken(req->req_sender);
} }
@@ -325,14 +384,13 @@ kern_status_t vm_controller_supply_pages(
src_offset, src_offset,
count, count,
NULL); NULL);
fulfill_requests(ctrl, dst->vo_key, dst_offset, count, status);
return status; return status;
} }
kern_status_t vm_controller_send_request( kern_status_t vm_controller_send_request(
struct vm_controller *ctrl, struct vm_controller *ctrl,
struct page_request *req, struct vm_request *req,
unsigned long *irq_flags) unsigned long *irq_flags)
{ {
fill_random(&req->req_id, sizeof req->req_id); fill_random(&req->req_id, sizeof req->req_id);
+64 -5
View File
@@ -288,8 +288,9 @@ struct vm_object *vm_object_duplicate_cow(struct vm_object *vmo)
struct vm_object *out = VM_OBJECT_CAST(obj); struct vm_object *out = VM_OBJECT_CAST(obj);
memcpy(out->vo_name, vmo->vo_name, sizeof out->vo_name); memcpy(out->vo_name, vmo->vo_name, sizeof out->vo_name);
out->vo_flags = vmo->vo_flags; out->vo_flags = vmo->vo_flags | VMO_LAZY_ATTACH;
out->vo_ctrl = vmo->vo_ctrl; out->vo_ctrl = vmo->vo_ctrl;
out->vo_key = vmo->vo_key;
out->vo_prot = vmo->vo_prot; out->vo_prot = vmo->vo_prot;
out->vo_size = vmo->vo_size; out->vo_size = vmo->vo_size;
memcpy(out->vo_name, vmo->vo_name, sizeof vmo->vo_name); memcpy(out->vo_name, vmo->vo_name, sizeof vmo->vo_name);
@@ -315,6 +316,37 @@ struct vm_object *vm_object_duplicate_cow(struct vm_object *vmo)
return out; return out;
} }
kern_status_t vm_object_attach_cow(
struct vm_object *vmo,
unsigned long *irq_flags)
{
struct vm_controller *ctrl = vmo->vo_ctrl;
struct vm_request req = {0};
req.req_status = VM_REQUEST_PENDING;
req.req_type = VM_REQUEST_ATTACH;
req.req_length = vm_page_order_to_bytes(VM_PAGE_4K);
req.req_sender = get_current_thread();
object_ref(&vmo->vo_base);
req.req_object = vmo;
vm_object_unlock_irqrestore(vmo, *irq_flags);
vm_controller_lock_irqsave(ctrl, irq_flags);
spin_lock(&req.req_lock);
kern_status_t status
= vm_controller_send_request(ctrl, &req, irq_flags);
put_current_thread(req.req_sender);
spin_unlock(&req.req_lock);
vm_controller_unlock_irqrestore(ctrl, *irq_flags);
object_unref(&vmo->vo_base);
vm_object_lock_irqsave(vmo, irq_flags);
return status;
}
static struct vm_page *alloc_page(struct vm_object *vo, off_t offset) static struct vm_page *alloc_page(struct vm_object *vo, off_t offset)
{ {
struct vm_page *page = NULL; struct vm_page *page = NULL;
@@ -458,15 +490,15 @@ static kern_status_t request_page(
unsigned long *irq_flags) unsigned long *irq_flags)
{ {
struct vm_controller *ctrl = vo->vo_ctrl; struct vm_controller *ctrl = vo->vo_ctrl;
struct page_request req = {0}; struct vm_request req = {0};
req.req_status = PAGE_REQUEST_PENDING; req.req_status = VM_REQUEST_PENDING;
req.req_type = PAGE_REQUEST_READ; req.req_type = VM_REQUEST_READ;
req.req_offset = offset; req.req_offset = offset;
req.req_length = vm_page_order_to_bytes(VM_PAGE_4K); req.req_length = vm_page_order_to_bytes(VM_PAGE_4K);
req.req_sender = get_current_thread(); req.req_sender = get_current_thread();
object_ref(&vo->vo_base); object_ref(&vo->vo_base);
req.req_object = vo->vo_key; req.req_object = vo;
vm_object_unlock_irqrestore(vo, *irq_flags); vm_object_unlock_irqrestore(vo, *irq_flags);
vm_controller_lock_irqsave(ctrl, irq_flags); vm_controller_lock_irqsave(ctrl, irq_flags);
@@ -484,6 +516,33 @@ static kern_status_t request_page(
return status; return status;
} }
kern_status_t vm_object_prefetch(
struct vm_object *vo,
off_t offset,
size_t length,
unsigned long *irq_flags)
{
offset &= ~VM_PAGE_MASK;
if (length & VM_PAGE_MASK) {
length &= ~VM_PAGE_MASK;
length += VM_PAGE_SIZE;
}
for (off_t i = offset; i < offset + length; i += VM_PAGE_SIZE) {
struct vm_page *pg = vm_object_get_page(
vo,
i,
VMO_ALLOCATE_MISSING_PAGE | VMO_REQUEST_MISSING_PAGE,
irq_flags);
if (!pg) {
/* TODO get error code from vm_object_get_page */
return KERN_NO_MEMORY;
}
}
return KERN_OK;
}
struct vm_page *vm_object_get_page( struct vm_page *vm_object_get_page(
struct vm_object *vo, struct vm_object *vo,
off_t offset, off_t offset,