Begin defining the process/thread api

This commit is contained in:
Drew Galbraith 2023-06-06 15:01:31 -07:00
parent e3661e7848
commit a092a57483
6 changed files with 31 additions and 18 deletions

View File

@ -6,7 +6,7 @@ constexpr uint64_t prog2 = 0x00000020'00000000;
int main() {
ZDebug("Testing");
uint64_t err = ZProcessSpawn(0x100, prog2, 0x1000);
uint64_t err = ZProcessSpawnElf(0x100, prog2, 0x1000);
if (err != Z_OK) {
ZDebug("Error");
} else {

View File

@ -1,3 +0,0 @@
#pragma once
#define ZC_PROC_SPAWN_CHILD 0x1

View File

@ -2,19 +2,34 @@
#include <stdint.h>
#define Z_THREAD_EXIT 0x01
#define Z_INVALID 0x0
#define Z_PROCESS_SPAWN 0x10
#define ZC_WRITE 0x01
#define ZC_READ 0x02
#define Z_DEBUG_PRINT 0x100
#define Z_PROCESS_EXIT 0x01
#define Z_PROCESS_SPAWN 0x02
#define Z_PROCESS_START 0x03
#define Z_PROCESS_SPAWN_ELF 0x1'00000002
#define ZC_PROC_SPAWN_PROC 0x100
#define ZC_PROC_SPAWN_THREAD 0x101
#define Z_THREAD_CREATE 0x10
#define Z_THREAD_START 0x11
#define Z_THREAD_EXIT 0x12
#define Z_DEBUG_PRINT 0x10000000
uint64_t ZDebug(const char* message);
// TODO: Move structs into an internal header.
struct ZProcessSpawnReq {
struct ZProcessSpawnElfReq {
uint64_t cap_id;
uint64_t elf_base;
uint64_t elf_size;
};
uint64_t ZProcessSpawn(uint64_t cap_id, uint64_t elf_base, uint64_t elf_size);
uint64_t ZProcessSpawnElf(uint64_t cap_id, uint64_t elf_base,
uint64_t elf_size);

View File

@ -1,7 +1,7 @@
#include "scheduler/process.h"
#include "debug/debug.h"
#include "include/cap_types.h"
#include "include/zcall.h"
#include "memory/paging_util.h"
#include "memory/physical_memory.h"
#include "scheduler/scheduler.h"
@ -27,7 +27,7 @@ void Process::CreateThread(uint64_t entry) {
Thread* thread = new Thread(*this, next_thread_id_++, entry);
threads_.PushBack(thread);
caps_.PushBack(new Capability(this, Capability::PROCESS, next_cap_id_++,
ZC_PROC_SPAWN_CHILD));
ZC_PROC_SPAWN_PROC));
gScheduler->Enqueue(thread);
}

View File

@ -3,7 +3,6 @@
#include <stdint.h>
#include "debug/debug.h"
#include "include/cap_types.h"
#include "include/zcall.h"
#include "include/zerrors.h"
#include "loader/elf_loader.h"
@ -58,7 +57,7 @@ void InitSyscall() {
SetMSR(LSTAR, reinterpret_cast<uint64_t>(syscall_enter));
}
uint64_t ProcessSpawn(ZProcessSpawnReq* req) {
uint64_t ProcessSpawnElf(ZProcessSpawnElfReq* req) {
auto& curr_proc = gScheduler->CurrentProcess();
auto cap = curr_proc.GetCapability(req->cap_id);
if (cap.empty()) {
@ -68,7 +67,7 @@ uint64_t ProcessSpawn(ZProcessSpawnReq* req) {
return ZE_INVALID;
}
if (!cap->HasPermissions(ZC_PROC_SPAWN_CHILD)) {
if (!cap->HasPermissions(ZC_PROC_SPAWN_PROC)) {
return ZE_DENIED;
}
dbgln("Proc spawn: %u:%u", req->elf_base, req->elf_size);
@ -82,7 +81,8 @@ uint64_t ProcessSpawn(ZProcessSpawnReq* req) {
extern "C" uint64_t SyscallHandler(uint64_t call_id, char* message) {
Thread& thread = gScheduler->CurrentThread();
switch (call_id) {
case Z_THREAD_EXIT:
case Z_PROCESS_EXIT:
// FIXME: kill process here.
thread.Exit();
panic("Returned from thread exit");
break;
@ -90,7 +90,7 @@ extern "C" uint64_t SyscallHandler(uint64_t call_id, char* message) {
dbgln("[Debug] %s", message);
break;
case Z_PROCESS_SPAWN:
return ProcessSpawn(reinterpret_cast<ZProcessSpawnReq*>(message));
return ProcessSpawnElf(reinterpret_cast<ZProcessSpawnElfReq*>(message));
default:
panic("Unhandled syscall number: %u", call_id);
}

View File

@ -12,8 +12,9 @@ uint64_t ZDebug(const char* message) {
return SysCall1(Z_DEBUG_PRINT, message);
}
uint64_t ZProcessSpawn(uint64_t cap_id, uint64_t elf_base, uint64_t elf_size) {
ZProcessSpawnReq req{
uint64_t ZProcessSpawnElf(uint64_t cap_id, uint64_t elf_base,
uint64_t elf_size) {
ZProcessSpawnElfReq req{
.cap_id = cap_id,
.elf_base = elf_base,
.elf_size = elf_size,