syscall: add task_self, task_get_address_space, and vm_region_kill
This commit is contained in:
@@ -6,14 +6,17 @@
|
||||
|
||||
static const virt_addr_t syscall_table[] = {
|
||||
SYSCALL_TABLE_ENTRY(TASK_EXIT, task_exit),
|
||||
SYSCALL_TABLE_ENTRY(TASK_SELF, task_self),
|
||||
SYSCALL_TABLE_ENTRY(TASK_CREATE, task_create),
|
||||
SYSCALL_TABLE_ENTRY(TASK_CREATE_THREAD, task_create_thread),
|
||||
SYSCALL_TABLE_ENTRY(TASK_GET_ADDRESS_SPACE, task_get_address_space),
|
||||
SYSCALL_TABLE_ENTRY(THREAD_START, thread_start),
|
||||
SYSCALL_TABLE_ENTRY(VM_OBJECT_CREATE, vm_object_create),
|
||||
SYSCALL_TABLE_ENTRY(VM_OBJECT_READ, vm_object_read),
|
||||
SYSCALL_TABLE_ENTRY(VM_OBJECT_WRITE, vm_object_write),
|
||||
SYSCALL_TABLE_ENTRY(VM_OBJECT_COPY, vm_object_copy),
|
||||
SYSCALL_TABLE_ENTRY(VM_REGION_CREATE, vm_region_create),
|
||||
SYSCALL_TABLE_ENTRY(VM_REGION_KILL, vm_region_kill),
|
||||
SYSCALL_TABLE_ENTRY(VM_REGION_READ, vm_region_read),
|
||||
SYSCALL_TABLE_ENTRY(VM_REGION_WRITE, vm_region_write),
|
||||
SYSCALL_TABLE_ENTRY(VM_REGION_MAP_ABSOLUTE, vm_region_map_absolute),
|
||||
|
||||
@@ -14,6 +14,35 @@ extern kern_status_t sys_task_exit(int status)
|
||||
return KERN_UNIMPLEMENTED;
|
||||
}
|
||||
|
||||
kern_status_t sys_task_self(kern_handle_t *out)
|
||||
{
|
||||
struct task *self = current_task();
|
||||
if (!validate_access_w(self, out, sizeof *out)) {
|
||||
return KERN_MEMORY_FAULT;
|
||||
}
|
||||
|
||||
unsigned long flags;
|
||||
task_lock_irqsave(self, &flags);
|
||||
|
||||
struct handle *handle_slot = NULL;
|
||||
kern_handle_t handle;
|
||||
kern_status_t status = handle_table_alloc_handle(
|
||||
self->t_handles,
|
||||
&handle_slot,
|
||||
&handle);
|
||||
task_unlock_irqrestore(self, flags);
|
||||
|
||||
if (status != KERN_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
object_add_handle(&self->t_base);
|
||||
handle_slot->h_object = &self->t_base;
|
||||
|
||||
*out = handle;
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
kern_status_t sys_task_create(
|
||||
kern_handle_t parent_handle,
|
||||
const char *name,
|
||||
@@ -175,6 +204,57 @@ kern_status_t sys_task_create_thread(
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
kern_status_t sys_task_get_address_space(
|
||||
kern_handle_t task_handle,
|
||||
kern_handle_t *out)
|
||||
{
|
||||
struct task *self = current_task();
|
||||
if (!validate_access_w(self, out, sizeof *out)) {
|
||||
return KERN_MEMORY_FAULT;
|
||||
}
|
||||
|
||||
unsigned long flags;
|
||||
task_lock_irqsave(self, &flags);
|
||||
|
||||
struct handle *handle_slot = NULL;
|
||||
kern_handle_t handle;
|
||||
struct object *task_obj = NULL;
|
||||
handle_flags_t handle_flags = 0;
|
||||
kern_status_t status = task_resolve_handle(
|
||||
self,
|
||||
task_handle,
|
||||
&task_obj,
|
||||
&handle_flags);
|
||||
if (status != KERN_OK) {
|
||||
task_unlock_irqrestore(self, flags);
|
||||
return status;
|
||||
}
|
||||
|
||||
status = handle_table_alloc_handle(
|
||||
self->t_handles,
|
||||
&handle_slot,
|
||||
&handle);
|
||||
if (status != KERN_OK) {
|
||||
task_unlock_irqrestore(self, flags);
|
||||
return status;
|
||||
}
|
||||
|
||||
struct task *task = task_cast(task_obj);
|
||||
|
||||
if (!task) {
|
||||
handle_table_free_handle(self->t_handles, handle);
|
||||
task_unlock_irqrestore(self, flags);
|
||||
return KERN_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
handle_slot->h_object = &task->t_address_space->vr_base;
|
||||
object_add_handle(&task->t_address_space->vr_base);
|
||||
task_unlock_irqrestore(self, flags);
|
||||
|
||||
*out = handle;
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
kern_status_t sys_thread_start(kern_handle_t thread_handle)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
Reference in New Issue
Block a user