Compare commits
No commits in common. "a5c4d40575cb1fc65108a5783d7274773f3528d6" and "6c10c57bfaacf47883c1d828f43ac39c707911da" have entirely different histories.
a5c4d40575
...
6c10c57bfa
|
@ -12,17 +12,17 @@ void check(uint64_t code) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case Z_OK:
|
case Z_OK:
|
||||||
return;
|
return;
|
||||||
case Z_ERR_UNIMPLEMENTED:
|
case ZE_NOT_FOUND:
|
||||||
|
dbgln("crash: NOT_FOUND");
|
||||||
|
break;
|
||||||
|
case ZE_INVALID:
|
||||||
|
dbgln("crash: INVALID");
|
||||||
|
break;
|
||||||
|
case ZE_DENIED:
|
||||||
|
dbgln("crash: DENIED");
|
||||||
|
break;
|
||||||
|
case ZE_UNIMPLEMENTED:
|
||||||
dbgln("crash: UNIMPLEMENTED");
|
dbgln("crash: UNIMPLEMENTED");
|
||||||
case Z_ERR_CAP_NOT_FOUND:
|
|
||||||
dbgln("crash: missing capability");
|
|
||||||
break;
|
|
||||||
case Z_ERR_CAP_TYPE:
|
|
||||||
dbgln("crash: capability of the wrong type");
|
|
||||||
break;
|
|
||||||
case Z_ERR_CAP_DENIED:
|
|
||||||
dbgln("crash: capability permissions error");
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
dbgln("Unhandled code");
|
dbgln("Unhandled code");
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -83,16 +83,10 @@ uint64_t LoadElfProgram(uint64_t base, uint64_t as_cap) {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
uint64_t SpawnProcessFromElfRegion(uint64_t program) {
|
uint64_t SpawnProcessFromElfRegion(uint64_t program) {
|
||||||
dbgln("Channel Create");
|
|
||||||
uint64_t local_chan;
|
|
||||||
uint64_t foreign_chan;
|
|
||||||
check(ZChannelCreate(&local_chan, &foreign_chan));
|
|
||||||
|
|
||||||
dbgln("Spawn");
|
dbgln("Spawn");
|
||||||
uint64_t proc_cap;
|
uint64_t proc_cap;
|
||||||
uint64_t as_cap;
|
uint64_t as_cap;
|
||||||
check(ZProcessSpawn(Z_INIT_PROC_SELF, foreign_chan, &proc_cap, &as_cap,
|
check(ZProcessSpawn(Z_INIT_PROC_SELF, &proc_cap, &as_cap));
|
||||||
&foreign_chan));
|
|
||||||
|
|
||||||
uint64_t entry_point = LoadElfProgram(program, as_cap);
|
uint64_t entry_point = LoadElfProgram(program, as_cap);
|
||||||
dbgln("Thread Create");
|
dbgln("Thread Create");
|
||||||
|
@ -100,10 +94,7 @@ uint64_t SpawnProcessFromElfRegion(uint64_t program) {
|
||||||
check(ZThreadCreate(proc_cap, &thread_cap));
|
check(ZThreadCreate(proc_cap, &thread_cap));
|
||||||
|
|
||||||
dbgln("Thread start");
|
dbgln("Thread start");
|
||||||
check(ZThreadStart(thread_cap, entry_point, foreign_chan, 0));
|
check(ZThreadStart(thread_cap, entry_point, 0, 0));
|
||||||
|
|
||||||
const uint8_t* msg = reinterpret_cast<const uint8_t*>("Hello!");
|
|
||||||
check(ZChannelSend(local_chan, 0, 7, msg, 0, 0));
|
|
||||||
|
|
||||||
return Z_OK;
|
return Z_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include <mammoth/debug.h>
|
#include <mammoth/debug.h>
|
||||||
#include <mammoth/thread.h>
|
#include <mammoth/thread.h>
|
||||||
#include <zcall.h>
|
|
||||||
|
|
||||||
#define CHECK(expr) \
|
#define CHECK(expr) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -16,7 +15,7 @@ void thread_entry(void* a) {
|
||||||
dbgln(static_cast<const char*>(a));
|
dbgln(static_cast<const char*>(a));
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(uint64_t bootstrap_cap) {
|
int main() {
|
||||||
dbgln("Main thread");
|
dbgln("Main thread");
|
||||||
|
|
||||||
const char* a = "a";
|
const char* a = "a";
|
||||||
|
@ -25,13 +24,5 @@ int main(uint64_t bootstrap_cap) {
|
||||||
const char* d = "dee";
|
const char* d = "dee";
|
||||||
Thread t1(thread_entry, a);
|
Thread t1(thread_entry, a);
|
||||||
Thread t2(thread_entry, b);
|
Thread t2(thread_entry, b);
|
||||||
|
|
||||||
uint64_t num_bytes = 10;
|
|
||||||
uint64_t num_caps;
|
|
||||||
uint8_t bytes[10];
|
|
||||||
uint64_t type;
|
|
||||||
check(ZChannelRecv(bootstrap_cap, num_bytes, bytes, 0, 0, &type, &num_bytes,
|
|
||||||
&num_caps));
|
|
||||||
dbgln(reinterpret_cast<char*>(bytes));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ add_executable(zion
|
||||||
memory/physical_memory.cpp
|
memory/physical_memory.cpp
|
||||||
memory/user_stack_manager.cpp
|
memory/user_stack_manager.cpp
|
||||||
object/address_space.cpp
|
object/address_space.cpp
|
||||||
object/channel.cpp
|
|
||||||
object/memory_object.cpp
|
object/memory_object.cpp
|
||||||
object/process.cpp
|
object/process.cpp
|
||||||
object/thread.cpp
|
object/thread.cpp
|
||||||
|
|
|
@ -34,11 +34,3 @@ RefPtr<MemoryObject> Capability::obj<MemoryObject>() {
|
||||||
}
|
}
|
||||||
return StaticCastRefPtr<MemoryObject>(obj_);
|
return StaticCastRefPtr<MemoryObject>(obj_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
|
||||||
RefPtr<Channel> Capability::obj<Channel>() {
|
|
||||||
if (type_ != CHANNEL) {
|
|
||||||
panic("Accessing %u cap as object.", type_);
|
|
||||||
}
|
|
||||||
return StaticCastRefPtr<Channel>(obj_);
|
|
||||||
}
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
class Process;
|
class Process;
|
||||||
class Thread;
|
class Thread;
|
||||||
|
|
||||||
class Capability : public RefCounted<Capability> {
|
class Capability {
|
||||||
public:
|
public:
|
||||||
enum Type {
|
enum Type {
|
||||||
UNDEFINED,
|
UNDEFINED,
|
||||||
|
@ -16,7 +16,6 @@ class Capability : public RefCounted<Capability> {
|
||||||
THREAD,
|
THREAD,
|
||||||
ADDRESS_SPACE,
|
ADDRESS_SPACE,
|
||||||
MEMORY_OBJECT,
|
MEMORY_OBJECT,
|
||||||
CHANNEL,
|
|
||||||
};
|
};
|
||||||
Capability(const RefPtr<KernelObject>& obj, Type type, uint64_t id,
|
Capability(const RefPtr<KernelObject>& obj, Type type, uint64_t id,
|
||||||
uint64_t permissions)
|
uint64_t permissions)
|
||||||
|
@ -31,7 +30,6 @@ class Capability : public RefCounted<Capability> {
|
||||||
RefPtr<T> obj();
|
RefPtr<T> obj();
|
||||||
|
|
||||||
uint64_t id() { return id_; }
|
uint64_t id() { return id_; }
|
||||||
void set_id(uint64_t id) { id_ = id; }
|
|
||||||
|
|
||||||
bool CheckType(Type type) { return type_ == type; }
|
bool CheckType(Type type) { return type_ == type; }
|
||||||
|
|
||||||
|
|
|
@ -2,20 +2,6 @@
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "include/zerrors.h"
|
|
||||||
|
|
||||||
void dbg(const char* fmt, ...);
|
void dbg(const char* fmt, ...);
|
||||||
void dbgln(const char* str, ...);
|
void dbgln(const char* str, ...);
|
||||||
void panic(const char* str, ...);
|
void panic(const char* str, ...);
|
||||||
|
|
||||||
#define RET_ERR(expr) \
|
|
||||||
{ \
|
|
||||||
z_err_t _tmp_err = expr; \
|
|
||||||
if (_tmp_err != Z_OK) { \
|
|
||||||
return _tmp_err; \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define UNREACHABLE \
|
|
||||||
panic("Unreachable %s, %s", __FILE__, __LINE__); \
|
|
||||||
__builtin_unreachable();
|
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "zerrors.h"
|
|
||||||
|
|
||||||
#define Z_INVALID 0x0
|
#define Z_INVALID 0x0
|
||||||
|
|
||||||
#define ZC_WRITE 0x01
|
#define ZC_WRITE 0x01
|
||||||
|
@ -34,46 +32,28 @@
|
||||||
|
|
||||||
#define Z_INIT_BOOT_VMMO 0x31
|
#define Z_INIT_BOOT_VMMO 0x31
|
||||||
|
|
||||||
// IPC Calls
|
|
||||||
#define Z_CHANNEL_CREATE 0x40
|
|
||||||
#define Z_CHANNEL_SEND 0x41
|
|
||||||
#define Z_CHANNEL_RECV 0x42
|
|
||||||
#define Z_CHANNEL_SENDRECV 0x43
|
|
||||||
|
|
||||||
// Debugging Calls.
|
// Debugging Calls.
|
||||||
#define Z_DEBUG_PRINT 0x10000000
|
#define Z_DEBUG_PRINT 0x10000000
|
||||||
|
|
||||||
void ZProcessExit(uint64_t code);
|
void ZProcessExit(uint64_t code);
|
||||||
|
|
||||||
[[nodiscard]] z_err_t ZProcessSpawn(uint64_t proc_cap, uint64_t bootstrap_cap,
|
[[nodiscard]] uint64_t ZProcessSpawn(uint64_t proc_cap, uint64_t* new_proc_cap,
|
||||||
uint64_t* new_proc_cap,
|
uint64_t* new_vmas_cap);
|
||||||
uint64_t* new_vmas_cap,
|
|
||||||
uint64_t* new_bootstrap_cap);
|
|
||||||
|
|
||||||
// UNUSED for now, I think we can get away with just starting a thread.
|
// UNUSED for now, I think we can get away with just starting a thread.
|
||||||
[[nodiscard]] z_err_t ZProcessStart(uint64_t proc_cap, uint64_t thread_cap,
|
[[nodiscard]] uint64_t ZProcessStart(uint64_t proc_cap, uint64_t thread_cap,
|
||||||
uint64_t entry, uint64_t arg1,
|
uint64_t entry, uint64_t arg1,
|
||||||
uint64_t arg2);
|
uint64_t arg2);
|
||||||
|
|
||||||
[[nodiscard]] z_err_t ZThreadCreate(uint64_t proc_cap, uint64_t* thread_cap);
|
[[nodiscard]] uint64_t ZThreadCreate(uint64_t proc_cap, uint64_t* thread_cap);
|
||||||
|
|
||||||
[[nodiscard]] z_err_t ZThreadStart(uint64_t thread_cap, uint64_t entry,
|
[[nodiscard]] uint64_t ZThreadStart(uint64_t thread_cap, uint64_t entry,
|
||||||
uint64_t arg1, uint64_t arg2);
|
uint64_t arg1, uint64_t arg2);
|
||||||
|
|
||||||
void ZThreadExit();
|
void ZThreadExit();
|
||||||
|
|
||||||
[[nodiscard]] z_err_t ZAddressSpaceMap(uint64_t vmas_cap, uint64_t vmas_offset,
|
[[nodiscard]] uint64_t ZAddressSpaceMap(uint64_t vmas_cap, uint64_t vmas_offset,
|
||||||
uint64_t vmmo_cap, uint64_t* vaddr);
|
uint64_t vmmo_cap, uint64_t* vaddr);
|
||||||
[[nodiscard]] z_err_t ZMemoryObjectCreate(uint64_t size, uint64_t* vmmo_cap);
|
[[nodiscard]] uint64_t ZMemoryObjectCreate(uint64_t size, uint64_t* vmmo_cap);
|
||||||
|
|
||||||
[[nodiscard]] z_err_t ZChannelCreate(uint64_t* channel1, uint64_t* channel2);
|
[[nodiscard]] uint64_t ZDebug(const char* message);
|
||||||
[[nodiscard]] z_err_t ZChannelSend(uint64_t chan_cap, uint64_t type,
|
|
||||||
uint64_t num_bytes, const uint8_t* bytes,
|
|
||||||
uint64_t num_caps, const uint64_t* caps);
|
|
||||||
[[nodiscard]] z_err_t ZChannelRecv(uint64_t chan_cap, uint64_t num_bytes,
|
|
||||||
uint8_t* bytes, uint64_t num_caps,
|
|
||||||
uint64_t* caps, uint64_t* type,
|
|
||||||
uint64_t* actual_bytes,
|
|
||||||
uint64_t* actual_caps);
|
|
||||||
|
|
||||||
[[nodiscard]] z_err_t ZDebug(const char* message);
|
|
||||||
|
|
|
@ -1,16 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#define Z_OK 0x0
|
#define Z_OK 0x0
|
||||||
#define Z_ERR_NOT_FOUND 0x1
|
#define ZE_NOT_FOUND 0x1
|
||||||
#define Z_ERR_INVALID 0x2
|
#define ZE_INVALID 0x2
|
||||||
#define Z_ERR_DENIED 0x3
|
#define ZE_DENIED 0x4
|
||||||
#define Z_ERR_UNIMPLEMENTED 0x4
|
#define ZE_UNIMPLEMENTED 0x8
|
||||||
#define Z_ERR_BUFF_SIZE 0x05
|
|
||||||
|
|
||||||
#define Z_ERR_CAP_NOT_FOUND 0x100
|
|
||||||
#define Z_ERR_CAP_TYPE 0x101
|
|
||||||
#define Z_ERR_CAP_DENIED 0x102
|
|
||||||
|
|
||||||
typedef uint64_t z_err_t;
|
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
template <typename T, typename U>
|
|
||||||
class Pair {
|
|
||||||
public:
|
|
||||||
Pair(const T& first, const U& second) : first_(first), second_(second) {}
|
|
||||||
T& first() { return first_; }
|
|
||||||
U& second() { return second_; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
T first_;
|
|
||||||
U second_;
|
|
||||||
};
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "debug/debug.h"
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class SharedPtr {
|
||||||
|
public:
|
||||||
|
SharedPtr() : init_(false), ptr_(0), ref_cnt_(0) {}
|
||||||
|
// Takes ownership.
|
||||||
|
SharedPtr(T* ptr) {
|
||||||
|
ptr_ = ptr;
|
||||||
|
ref_cnt_ = new uint64_t(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedPtr(const SharedPtr<T>& other)
|
||||||
|
: init_(other.init_), ptr_(other.ptr_), ref_cnt_(other.ref_cnt_) {
|
||||||
|
(*ref_cnt_)++;
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedPtr& operator=(const SharedPtr<T>& other) {
|
||||||
|
Cleanup();
|
||||||
|
init_ = other.init_;
|
||||||
|
ptr_ = other.ptr_;
|
||||||
|
ref_cnt_ = other.ref_cnt_;
|
||||||
|
(*ref_cnt_)++;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
~SharedPtr() { Cleanup(); }
|
||||||
|
|
||||||
|
T& operator*() {
|
||||||
|
CheckValid();
|
||||||
|
return *ptr_;
|
||||||
|
}
|
||||||
|
const T& operator*() const {
|
||||||
|
CheckValid();
|
||||||
|
return *ptr_;
|
||||||
|
}
|
||||||
|
T* operator->() {
|
||||||
|
CheckValid();
|
||||||
|
return ptr_;
|
||||||
|
}
|
||||||
|
const T* operator->() const {
|
||||||
|
CheckValid();
|
||||||
|
return ptr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
T* ptr() {
|
||||||
|
CheckValid();
|
||||||
|
return ptr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const SharedPtr<T>& other) {
|
||||||
|
CheckValid();
|
||||||
|
other.CheckValid();
|
||||||
|
return ptr_ == other.ptr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool empty() { return !init_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool init_ = true;
|
||||||
|
T* ptr_;
|
||||||
|
uint64_t* ref_cnt_;
|
||||||
|
|
||||||
|
void Cleanup() {
|
||||||
|
if (!init_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (--(*ref_cnt_) == 0) {
|
||||||
|
dbgln("Deleting shared ptr: %m", ptr_);
|
||||||
|
delete ptr_;
|
||||||
|
delete ref_cnt_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckValid() const {
|
||||||
|
if (!init_) {
|
||||||
|
panic("Accessing invalid shared ptr");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T, class... A>
|
||||||
|
SharedPtr<T> MakeShared(A... args) {
|
||||||
|
return {new T(args...)};
|
||||||
|
}
|
|
@ -1,61 +0,0 @@
|
||||||
#include "object/channel.h"
|
|
||||||
|
|
||||||
#include "include/zerrors.h"
|
|
||||||
|
|
||||||
Pair<RefPtr<Channel>, RefPtr<Channel>> Channel::CreateChannelPair() {
|
|
||||||
auto c1 = MakeRefCounted<Channel>();
|
|
||||||
auto c2 = MakeRefCounted<Channel>();
|
|
||||||
c1->SetPeer(c2);
|
|
||||||
c2->SetPeer(c1);
|
|
||||||
return {c1, c2};
|
|
||||||
}
|
|
||||||
|
|
||||||
z_err_t Channel::Write(const ZMessage& msg) {
|
|
||||||
return peer_->EnqueueMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
z_err_t Channel::Read(ZMessage& msg) {
|
|
||||||
if (pending_messages_.size() == 0) {
|
|
||||||
dbgln("Unimplemented add blocking.");
|
|
||||||
return Z_ERR_UNIMPLEMENTED;
|
|
||||||
}
|
|
||||||
Message next_msg = pending_messages_.PeekFront();
|
|
||||||
if (next_msg.num_bytes > msg.num_bytes) {
|
|
||||||
return Z_ERR_BUFF_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.type = next_msg.type;
|
|
||||||
msg.num_bytes = next_msg.num_bytes;
|
|
||||||
msg.num_caps = 0;
|
|
||||||
|
|
||||||
for (uint64_t i = 0; i < msg.num_bytes; i++) {
|
|
||||||
msg.bytes[i] = next_msg.bytes[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
pending_messages_.PopFront();
|
|
||||||
|
|
||||||
return Z_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
z_err_t Channel::EnqueueMessage(const ZMessage& msg) {
|
|
||||||
if (msg.num_caps > 0) {
|
|
||||||
dbgln("Unimplemented passing caps on channel");
|
|
||||||
return Z_ERR_UNIMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.num_bytes > 0x1000) {
|
|
||||||
dbgln("Large message size unimplemented: %x", msg.num_bytes);
|
|
||||||
return Z_ERR_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
Message message{
|
|
||||||
.type = msg.type,
|
|
||||||
.num_bytes = msg.num_bytes,
|
|
||||||
.bytes = new uint8_t[msg.num_bytes],
|
|
||||||
};
|
|
||||||
for (uint64_t i = 0; i < msg.num_bytes; i++) {
|
|
||||||
message.bytes[i] = msg.bytes[i];
|
|
||||||
}
|
|
||||||
pending_messages_.PushBack(message);
|
|
||||||
return Z_OK;
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "capability/capability.h"
|
|
||||||
#include "include/zerrors.h"
|
|
||||||
#include "lib/linked_list.h"
|
|
||||||
#include "lib/pair.h"
|
|
||||||
#include "lib/ref_ptr.h"
|
|
||||||
#include "object/kernel_object.h"
|
|
||||||
#include "usr/zcall_internal.h"
|
|
||||||
|
|
||||||
class Channel : public KernelObject {
|
|
||||||
public:
|
|
||||||
static Pair<RefPtr<Channel>, RefPtr<Channel>> CreateChannelPair();
|
|
||||||
|
|
||||||
RefPtr<Channel> peer() { return peer_; }
|
|
||||||
|
|
||||||
z_err_t Write(const ZMessage& msg);
|
|
||||||
z_err_t Read(ZMessage& msg);
|
|
||||||
|
|
||||||
private:
|
|
||||||
// FIXME: We will likely never close the channel based on this
|
|
||||||
// circular dependency.
|
|
||||||
RefPtr<Channel> peer_{nullptr};
|
|
||||||
|
|
||||||
struct Message {
|
|
||||||
uint64_t type;
|
|
||||||
|
|
||||||
uint64_t num_bytes;
|
|
||||||
uint8_t* bytes;
|
|
||||||
};
|
|
||||||
|
|
||||||
// FIXME: This is probably dangerous because of an
|
|
||||||
// implicit shallow copy.
|
|
||||||
LinkedList<Message> pending_messages_;
|
|
||||||
|
|
||||||
friend class MakeRefCountedFriend<Channel>;
|
|
||||||
Channel() {}
|
|
||||||
void SetPeer(const RefPtr<Channel>& peer) { peer_ = peer; }
|
|
||||||
|
|
||||||
z_err_t EnqueueMessage(const ZMessage& msg);
|
|
||||||
};
|
|
|
@ -23,10 +23,10 @@ RefPtr<Process> Process::RootProcess() {
|
||||||
RefPtr<Process> Process::Create() {
|
RefPtr<Process> Process::Create() {
|
||||||
auto proc = MakeRefCounted<Process>();
|
auto proc = MakeRefCounted<Process>();
|
||||||
proc->caps_.PushBack(
|
proc->caps_.PushBack(
|
||||||
MakeRefCounted<Capability>(proc, Capability::PROCESS, Z_INIT_PROC_SELF,
|
new Capability(proc, Capability::PROCESS, Z_INIT_PROC_SELF,
|
||||||
ZC_PROC_SPAWN_PROC | ZC_PROC_SPAWN_THREAD));
|
ZC_PROC_SPAWN_PROC | ZC_PROC_SPAWN_THREAD));
|
||||||
proc->caps_.PushBack(MakeRefCounted<Capability>(
|
proc->caps_.PushBack(new Capability(proc->vmas(), Capability::ADDRESS_SPACE,
|
||||||
proc->vmas(), Capability::ADDRESS_SPACE, Z_INIT_VMAS_SELF, ZC_WRITE));
|
Z_INIT_VMAS_SELF, ZC_WRITE));
|
||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,25 +62,10 @@ void Process::CheckState() {
|
||||||
state_ = FINISHED;
|
state_ = FINISHED;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Capability> Process::ReleaseCapability(uint64_t cid) {
|
SharedPtr<Capability> Process::GetCapability(uint64_t cid) {
|
||||||
auto iter = caps_.begin();
|
auto iter = caps_.begin();
|
||||||
while (iter != caps_.end()) {
|
while (iter != caps_.end()) {
|
||||||
if (*iter && iter->id() == cid) {
|
if (iter->id() == cid) {
|
||||||
auto cap = *iter;
|
|
||||||
*iter = {nullptr};
|
|
||||||
return cap;
|
|
||||||
}
|
|
||||||
++iter;
|
|
||||||
}
|
|
||||||
dbgln("Bad cap access");
|
|
||||||
dbgln("Num caps: %u", caps_.size());
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
RefPtr<Capability> Process::GetCapability(uint64_t cid) {
|
|
||||||
auto iter = caps_.begin();
|
|
||||||
while (iter != caps_.end()) {
|
|
||||||
if (*iter && iter->id() == cid) {
|
|
||||||
return *iter;
|
return *iter;
|
||||||
}
|
}
|
||||||
++iter;
|
++iter;
|
||||||
|
@ -90,44 +75,32 @@ RefPtr<Capability> Process::GetCapability(uint64_t cid) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Process::AddCapability(const RefPtr<Capability>& cap) {
|
|
||||||
cap->set_id(next_cap_id_++);
|
|
||||||
caps_.PushBack(cap);
|
|
||||||
return cap->id();
|
|
||||||
}
|
|
||||||
uint64_t Process::AddCapability(const RefPtr<Thread>& thread) {
|
uint64_t Process::AddCapability(const RefPtr<Thread>& thread) {
|
||||||
uint64_t cap_id = next_cap_id_++;
|
uint64_t cap_id = next_cap_id_++;
|
||||||
caps_.PushBack(
|
caps_.PushBack(new Capability(thread, Capability::THREAD, cap_id, ZC_WRITE));
|
||||||
MakeRefCounted<Capability>(thread, Capability::THREAD, cap_id, ZC_WRITE));
|
|
||||||
return cap_id;
|
return cap_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Process::AddCapability(const RefPtr<Process>& p) {
|
uint64_t Process::AddCapability(const RefPtr<Process>& p) {
|
||||||
uint64_t cap_id = next_cap_id_++;
|
uint64_t cap_id = next_cap_id_++;
|
||||||
caps_.PushBack(MakeRefCounted<Capability>(p, Capability::PROCESS, cap_id,
|
caps_.PushBack(new Capability(p, Capability::PROCESS, cap_id,
|
||||||
ZC_WRITE | ZC_PROC_SPAWN_THREAD));
|
ZC_WRITE | ZC_PROC_SPAWN_THREAD));
|
||||||
return cap_id;
|
return cap_id;
|
||||||
}
|
}
|
||||||
uint64_t Process::AddCapability(const RefPtr<AddressSpace>& vmas) {
|
uint64_t Process::AddCapability(const RefPtr<AddressSpace>& vmas) {
|
||||||
uint64_t cap_id = next_cap_id_++;
|
uint64_t cap_id = next_cap_id_++;
|
||||||
caps_.PushBack(MakeRefCounted<Capability>(vmas, Capability::ADDRESS_SPACE,
|
caps_.PushBack(
|
||||||
cap_id, ZC_WRITE));
|
new Capability(vmas, Capability::ADDRESS_SPACE, cap_id, ZC_WRITE));
|
||||||
return cap_id;
|
return cap_id;
|
||||||
}
|
}
|
||||||
uint64_t Process::AddCapability(const RefPtr<MemoryObject>& vmmo) {
|
uint64_t Process::AddCapability(const RefPtr<MemoryObject>& vmmo) {
|
||||||
uint64_t cap_id = next_cap_id_++;
|
uint64_t cap_id = next_cap_id_++;
|
||||||
caps_.PushBack(MakeRefCounted<Capability>(vmmo, Capability::MEMORY_OBJECT,
|
caps_.PushBack(
|
||||||
cap_id, ZC_WRITE));
|
new Capability(vmmo, Capability::MEMORY_OBJECT, cap_id, ZC_WRITE));
|
||||||
return cap_id;
|
|
||||||
}
|
|
||||||
uint64_t Process::AddCapability(const RefPtr<Channel>& chan) {
|
|
||||||
uint64_t cap_id = next_cap_id_++;
|
|
||||||
caps_.PushBack(MakeRefCounted<Capability>(chan, Capability::CHANNEL, cap_id,
|
|
||||||
ZC_WRITE | ZC_READ));
|
|
||||||
return cap_id;
|
return cap_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process::AddCapability(uint64_t cap_id, const RefPtr<MemoryObject>& vmmo) {
|
void Process::AddCapability(uint64_t cap_id, const RefPtr<MemoryObject>& vmmo) {
|
||||||
caps_.PushBack(MakeRefCounted<Capability>(vmmo, Capability::MEMORY_OBJECT,
|
caps_.PushBack(
|
||||||
cap_id, ZC_WRITE));
|
new Capability(vmmo, Capability::MEMORY_OBJECT, cap_id, ZC_WRITE));
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
#include "capability/capability.h"
|
#include "capability/capability.h"
|
||||||
#include "lib/linked_list.h"
|
#include "lib/linked_list.h"
|
||||||
#include "lib/ref_ptr.h"
|
#include "lib/ref_ptr.h"
|
||||||
|
#include "lib/shared_ptr.h"
|
||||||
#include "object/address_space.h"
|
#include "object/address_space.h"
|
||||||
#include "object/channel.h"
|
|
||||||
|
|
||||||
// Forward decl due to cyclic dependency.
|
// Forward decl due to cyclic dependency.
|
||||||
class Thread;
|
class Thread;
|
||||||
|
@ -28,15 +28,11 @@ class Process : public KernelObject {
|
||||||
RefPtr<Thread> CreateThread();
|
RefPtr<Thread> CreateThread();
|
||||||
RefPtr<Thread> GetThread(uint64_t tid);
|
RefPtr<Thread> GetThread(uint64_t tid);
|
||||||
|
|
||||||
RefPtr<Capability> ReleaseCapability(uint64_t cid);
|
SharedPtr<Capability> GetCapability(uint64_t cid);
|
||||||
RefPtr<Capability> GetCapability(uint64_t cid);
|
|
||||||
// FIXME: We can't reset the cap id here.
|
|
||||||
uint64_t AddCapability(const RefPtr<Capability>& cap);
|
|
||||||
uint64_t AddCapability(const RefPtr<Thread>& t);
|
uint64_t AddCapability(const RefPtr<Thread>& t);
|
||||||
uint64_t AddCapability(const RefPtr<Process>& p);
|
uint64_t AddCapability(const RefPtr<Process>& p);
|
||||||
uint64_t AddCapability(const RefPtr<AddressSpace>& vmas);
|
uint64_t AddCapability(const RefPtr<AddressSpace>& vmas);
|
||||||
uint64_t AddCapability(const RefPtr<MemoryObject>& vmmo);
|
uint64_t AddCapability(const RefPtr<MemoryObject>& vmmo);
|
||||||
uint64_t AddCapability(const RefPtr<Channel>& chan);
|
|
||||||
|
|
||||||
void AddCapability(uint64_t cap_id, const RefPtr<MemoryObject>& vmmo);
|
void AddCapability(uint64_t cap_id, const RefPtr<MemoryObject>& vmmo);
|
||||||
// Checks the state of all child threads and transitions to
|
// Checks the state of all child threads and transitions to
|
||||||
|
@ -57,5 +53,5 @@ class Process : public KernelObject {
|
||||||
uint64_t next_cap_id_ = 0x100;
|
uint64_t next_cap_id_ = 0x100;
|
||||||
|
|
||||||
LinkedList<RefPtr<Thread>> threads_;
|
LinkedList<RefPtr<Thread>> threads_;
|
||||||
LinkedList<RefPtr<Capability>> caps_;
|
LinkedList<SharedPtr<Capability>> caps_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include "debug/debug.h"
|
#include "debug/debug.h"
|
||||||
#include "include/zcall.h"
|
#include "include/zcall.h"
|
||||||
#include "include/zerrors.h"
|
#include "include/zerrors.h"
|
||||||
#include "object/channel.h"
|
|
||||||
#include "object/process.h"
|
#include "object/process.h"
|
||||||
#include "scheduler/process_manager.h"
|
#include "scheduler/process_manager.h"
|
||||||
#include "scheduler/scheduler.h"
|
#include "scheduler/scheduler.h"
|
||||||
|
@ -57,47 +56,40 @@ void InitSyscall() {
|
||||||
SetMSR(LSTAR, reinterpret_cast<uint64_t>(syscall_enter));
|
SetMSR(LSTAR, reinterpret_cast<uint64_t>(syscall_enter));
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t ValidateCap(const RefPtr<Capability>& cap, Capability::Type type,
|
uint64_t ProcessSpawn(ZProcessSpawnReq* req, ZProcessSpawnResp* resp) {
|
||||||
uint64_t permissions) {
|
|
||||||
if (!cap) {
|
|
||||||
return Z_ERR_CAP_NOT_FOUND;
|
|
||||||
}
|
|
||||||
if (!cap->CheckType(type)) {
|
|
||||||
return Z_ERR_CAP_TYPE;
|
|
||||||
}
|
|
||||||
if (!cap->HasPermissions(permissions)) {
|
|
||||||
return Z_ERR_CAP_DENIED;
|
|
||||||
}
|
|
||||||
return Z_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
z_err_t ProcessSpawn(ZProcessSpawnReq* req, ZProcessSpawnResp* resp) {
|
|
||||||
auto& curr_proc = gScheduler->CurrentProcess();
|
auto& curr_proc = gScheduler->CurrentProcess();
|
||||||
auto cap = curr_proc.GetCapability(req->proc_cap);
|
auto cap = curr_proc.GetCapability(req->proc_cap);
|
||||||
RET_ERR(ValidateCap(cap, Capability::PROCESS, ZC_PROC_SPAWN_PROC));
|
if (cap.empty()) {
|
||||||
|
return ZE_NOT_FOUND;
|
||||||
|
}
|
||||||
|
if (!cap->CheckType(Capability::PROCESS)) {
|
||||||
|
return ZE_INVALID;
|
||||||
|
}
|
||||||
|
if (!cap->HasPermissions(ZC_PROC_SPAWN_PROC)) {
|
||||||
|
return ZE_DENIED;
|
||||||
|
}
|
||||||
RefPtr<Process> proc = Process::Create();
|
RefPtr<Process> proc = Process::Create();
|
||||||
gProcMan->InsertProcess(proc);
|
gProcMan->InsertProcess(proc);
|
||||||
|
|
||||||
resp->proc_cap = curr_proc.AddCapability(proc);
|
resp->proc_cap = curr_proc.AddCapability(proc);
|
||||||
resp->vmas_cap = curr_proc.AddCapability(proc->vmas());
|
resp->vmas_cap = curr_proc.AddCapability(proc->vmas());
|
||||||
|
|
||||||
if (req->bootstrap_cap != 0) {
|
|
||||||
auto cap = curr_proc.ReleaseCapability(req->bootstrap_cap);
|
|
||||||
if (!cap) {
|
|
||||||
return Z_ERR_CAP_NOT_FOUND;
|
|
||||||
}
|
|
||||||
// FIXME: Check permissions.
|
|
||||||
resp->bootstrap_cap = proc->AddCapability(cap);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Z_OK;
|
return Z_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t ThreadCreate(ZThreadCreateReq* req, ZThreadCreateResp* resp) {
|
uint64_t ThreadCreate(ZThreadCreateReq* req, ZThreadCreateResp* resp) {
|
||||||
auto& curr_proc = gScheduler->CurrentProcess();
|
auto& curr_proc = gScheduler->CurrentProcess();
|
||||||
auto cap = curr_proc.GetCapability(req->proc_cap);
|
auto cap = curr_proc.GetCapability(req->proc_cap);
|
||||||
RET_ERR(ValidateCap(cap, Capability::PROCESS, ZC_PROC_SPAWN_THREAD));
|
if (cap.empty()) {
|
||||||
|
return ZE_NOT_FOUND;
|
||||||
|
}
|
||||||
|
if (!cap->CheckType(Capability::PROCESS)) {
|
||||||
|
return ZE_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cap->HasPermissions(ZC_PROC_SPAWN_THREAD)) {
|
||||||
|
return ZE_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
auto parent_proc = cap->obj<Process>();
|
auto parent_proc = cap->obj<Process>();
|
||||||
auto thread = parent_proc->CreateThread();
|
auto thread = parent_proc->CreateThread();
|
||||||
|
@ -106,10 +98,19 @@ z_err_t ThreadCreate(ZThreadCreateReq* req, ZThreadCreateResp* resp) {
|
||||||
return Z_OK;
|
return Z_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t ThreadStart(ZThreadStartReq* req) {
|
uint64_t ThreadStart(ZThreadStartReq* req) {
|
||||||
auto& curr_proc = gScheduler->CurrentProcess();
|
auto& curr_proc = gScheduler->CurrentProcess();
|
||||||
auto cap = curr_proc.GetCapability(req->thread_cap);
|
auto cap = curr_proc.GetCapability(req->thread_cap);
|
||||||
RET_ERR(ValidateCap(cap, Capability::THREAD, ZC_WRITE));
|
if (cap.empty()) {
|
||||||
|
return ZE_NOT_FOUND;
|
||||||
|
}
|
||||||
|
if (!cap->CheckType(Capability::THREAD)) {
|
||||||
|
return ZE_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cap->HasPermissions(ZC_WRITE)) {
|
||||||
|
return ZE_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
auto thread = cap->obj<Thread>();
|
auto thread = cap->obj<Thread>();
|
||||||
// FIXME: validate entry point is in user space.
|
// FIXME: validate entry point is in user space.
|
||||||
|
@ -117,13 +118,21 @@ z_err_t ThreadStart(ZThreadStartReq* req) {
|
||||||
return Z_OK;
|
return Z_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t AddressSpaceMap(ZAddressSpaceMapReq* req, ZAddressSpaceMapResp* resp) {
|
uint64_t AddressSpaceMap(ZAddressSpaceMapReq* req, ZAddressSpaceMapResp* resp) {
|
||||||
auto& curr_proc = gScheduler->CurrentProcess();
|
auto& curr_proc = gScheduler->CurrentProcess();
|
||||||
auto vmas_cap = curr_proc.GetCapability(req->vmas_cap);
|
auto vmas_cap = curr_proc.GetCapability(req->vmas_cap);
|
||||||
auto vmmo_cap = curr_proc.GetCapability(req->vmmo_cap);
|
auto vmmo_cap = curr_proc.GetCapability(req->vmmo_cap);
|
||||||
RET_ERR(ValidateCap(vmas_cap, Capability::ADDRESS_SPACE, ZC_WRITE));
|
if (vmas_cap.empty() || vmmo_cap.empty()) {
|
||||||
RET_ERR(ValidateCap(vmmo_cap, Capability::MEMORY_OBJECT, ZC_WRITE));
|
return ZE_NOT_FOUND;
|
||||||
|
}
|
||||||
|
if (!vmas_cap->CheckType(Capability::ADDRESS_SPACE) ||
|
||||||
|
!vmmo_cap->CheckType(Capability::MEMORY_OBJECT)) {
|
||||||
|
return ZE_INVALID;
|
||||||
|
}
|
||||||
|
if (!vmas_cap->HasPermissions(ZC_WRITE) ||
|
||||||
|
!vmmo_cap->HasPermissions(ZC_WRITE)) {
|
||||||
|
return ZE_DENIED;
|
||||||
|
}
|
||||||
auto vmas = vmas_cap->obj<AddressSpace>();
|
auto vmas = vmas_cap->obj<AddressSpace>();
|
||||||
auto vmmo = vmmo_cap->obj<MemoryObject>();
|
auto vmmo = vmmo_cap->obj<MemoryObject>();
|
||||||
// FIXME: Validation necessary.
|
// FIXME: Validation necessary.
|
||||||
|
@ -133,46 +142,17 @@ z_err_t AddressSpaceMap(ZAddressSpaceMapReq* req, ZAddressSpaceMapResp* resp) {
|
||||||
} else {
|
} else {
|
||||||
resp->vaddr = vmas->MapInMemoryObject(vmmo);
|
resp->vaddr = vmas->MapInMemoryObject(vmmo);
|
||||||
}
|
}
|
||||||
return Z_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t MemoryObjectCreate(ZMemoryObjectCreateReq* req,
|
uint64_t MemoryObjectCreate(ZMemoryObjectCreateReq* req,
|
||||||
ZMemoryObjectCreateResp* resp) {
|
ZMemoryObjectCreateResp* resp) {
|
||||||
auto& curr_proc = gScheduler->CurrentProcess();
|
auto& curr_proc = gScheduler->CurrentProcess();
|
||||||
resp->vmmo_cap =
|
resp->vmmo_cap =
|
||||||
curr_proc.AddCapability(MakeRefCounted<MemoryObject>(req->size));
|
curr_proc.AddCapability(MakeRefCounted<MemoryObject>(req->size));
|
||||||
return Z_OK;
|
return Z_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t ChannelCreate(ZChannelCreateResp* resp) {
|
extern "C" uint64_t SyscallHandler(uint64_t call_id, void* req, void* resp) {
|
||||||
auto& proc = gScheduler->CurrentProcess();
|
|
||||||
auto chan_pair = Channel::CreateChannelPair();
|
|
||||||
resp->chan_cap1 = proc.AddCapability(chan_pair.first());
|
|
||||||
resp->chan_cap2 = proc.AddCapability(chan_pair.second());
|
|
||||||
return Z_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
z_err_t ChannelSend(ZChannelSendReq* req) {
|
|
||||||
auto& proc = gScheduler->CurrentProcess();
|
|
||||||
auto chan_cap = proc.GetCapability(req->chan_cap);
|
|
||||||
RET_ERR(ValidateCap(chan_cap, Capability::CHANNEL, ZC_WRITE));
|
|
||||||
|
|
||||||
auto chan = chan_cap->obj<Channel>();
|
|
||||||
chan->Write(req->message);
|
|
||||||
return Z_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
z_err_t ChannelRecv(ZChannelRecvReq* req) {
|
|
||||||
auto& proc = gScheduler->CurrentProcess();
|
|
||||||
auto chan_cap = proc.GetCapability(req->chan_cap);
|
|
||||||
RET_ERR(ValidateCap(chan_cap, Capability::CHANNEL, ZC_READ));
|
|
||||||
|
|
||||||
auto chan = chan_cap->obj<Channel>();
|
|
||||||
chan->Read(req->message);
|
|
||||||
return Z_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" z_err_t SyscallHandler(uint64_t call_id, void* req, void* resp) {
|
|
||||||
Thread& thread = gScheduler->CurrentThread();
|
Thread& thread = gScheduler->CurrentThread();
|
||||||
switch (call_id) {
|
switch (call_id) {
|
||||||
case Z_PROCESS_EXIT:
|
case Z_PROCESS_EXIT:
|
||||||
|
@ -201,18 +181,11 @@ extern "C" z_err_t SyscallHandler(uint64_t call_id, void* req, void* resp) {
|
||||||
return MemoryObjectCreate(
|
return MemoryObjectCreate(
|
||||||
reinterpret_cast<ZMemoryObjectCreateReq*>(req),
|
reinterpret_cast<ZMemoryObjectCreateReq*>(req),
|
||||||
reinterpret_cast<ZMemoryObjectCreateResp*>(resp));
|
reinterpret_cast<ZMemoryObjectCreateResp*>(resp));
|
||||||
case Z_CHANNEL_CREATE:
|
|
||||||
return ChannelCreate(reinterpret_cast<ZChannelCreateResp*>(resp));
|
|
||||||
case Z_CHANNEL_SEND:
|
|
||||||
return ChannelSend(reinterpret_cast<ZChannelSendReq*>(req));
|
|
||||||
case Z_CHANNEL_RECV:
|
|
||||||
return ChannelRecv(reinterpret_cast<ZChannelRecvReq*>(req));
|
|
||||||
case Z_DEBUG_PRINT:
|
case Z_DEBUG_PRINT:
|
||||||
dbgln("[Debug] %s", req);
|
dbgln("[Debug] %s", req);
|
||||||
return Z_OK;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
panic("Unhandled syscall number: %x", call_id);
|
panic("Unhandled syscall number: %x", call_id);
|
||||||
}
|
}
|
||||||
UNREACHABLE
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,20 @@
|
||||||
|
|
||||||
#include "usr/zcall_internal.h"
|
#include "usr/zcall_internal.h"
|
||||||
|
|
||||||
z_err_t SysCall2(uint64_t number, const void* first, const void* second) {
|
uint64_t SysCall0(uint64_t number) {
|
||||||
z_err_t return_code;
|
uint64_t return_code;
|
||||||
|
asm("syscall" : "=a"(return_code) : "D"(number));
|
||||||
|
return return_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t SysCall1(uint64_t number, const void* first) {
|
||||||
|
uint64_t return_code;
|
||||||
|
asm("syscall" : "=a"(return_code) : "D"(number), "S"(first) : "rcx", "r11");
|
||||||
|
return return_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t SysCall2(uint64_t number, const void* first, const void* second) {
|
||||||
|
uint64_t return_code;
|
||||||
asm("syscall"
|
asm("syscall"
|
||||||
: "=a"(return_code)
|
: "=a"(return_code)
|
||||||
: "D"(number), "S"(first), "d"(second)
|
: "D"(number), "S"(first), "d"(second)
|
||||||
|
@ -13,43 +25,34 @@ z_err_t SysCall2(uint64_t number, const void* first, const void* second) {
|
||||||
return return_code;
|
return return_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t SysCall0(uint64_t number) { return SysCall2(number, 0, 0); }
|
|
||||||
|
|
||||||
z_err_t SysCall1(uint64_t number, const void* first) {
|
|
||||||
return SysCall2(number, first, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ZProcessExit(uint64_t code) {
|
void ZProcessExit(uint64_t code) {
|
||||||
SysCall1(Z_PROCESS_EXIT, reinterpret_cast<void*>(code));
|
SysCall1(Z_PROCESS_EXIT, reinterpret_cast<void*>(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t ZProcessSpawn(uint64_t proc_cap, uint64_t bootstrap_cap,
|
uint64_t ZProcessSpawn(uint64_t proc_cap, uint64_t* new_proc_cap,
|
||||||
uint64_t* new_proc_cap, uint64_t* new_vmas_cap,
|
uint64_t* new_vmas_cap) {
|
||||||
uint64_t* new_bootstrap_cap) {
|
|
||||||
ZProcessSpawnReq req{
|
ZProcessSpawnReq req{
|
||||||
.proc_cap = proc_cap,
|
.proc_cap = proc_cap,
|
||||||
.bootstrap_cap = bootstrap_cap,
|
|
||||||
};
|
};
|
||||||
ZProcessSpawnResp resp;
|
ZProcessSpawnResp resp;
|
||||||
z_err_t ret = SysCall2(Z_PROCESS_SPAWN, &req, &resp);
|
uint64_t ret = SysCall2(Z_PROCESS_SPAWN, &req, &resp);
|
||||||
*new_proc_cap = resp.proc_cap;
|
*new_proc_cap = resp.proc_cap;
|
||||||
*new_vmas_cap = resp.vmas_cap;
|
*new_vmas_cap = resp.vmas_cap;
|
||||||
*new_bootstrap_cap = resp.bootstrap_cap;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t ZThreadCreate(uint64_t proc_cap, uint64_t* thread_cap) {
|
uint64_t ZThreadCreate(uint64_t proc_cap, uint64_t* thread_cap) {
|
||||||
ZThreadCreateReq req{
|
ZThreadCreateReq req{
|
||||||
.proc_cap = proc_cap,
|
.proc_cap = proc_cap,
|
||||||
};
|
};
|
||||||
ZThreadCreateResp resp;
|
ZThreadCreateResp resp;
|
||||||
z_err_t ret = SysCall2(Z_THREAD_CREATE, &req, &resp);
|
uint64_t ret = SysCall2(Z_THREAD_CREATE, &req, &resp);
|
||||||
*thread_cap = resp.thread_cap;
|
*thread_cap = resp.thread_cap;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t ZThreadStart(uint64_t thread_cap, uint64_t entry, uint64_t arg1,
|
uint64_t ZThreadStart(uint64_t thread_cap, uint64_t entry, uint64_t arg1,
|
||||||
uint64_t arg2) {
|
uint64_t arg2) {
|
||||||
ZThreadStartReq req{
|
ZThreadStartReq req{
|
||||||
.thread_cap = thread_cap,
|
.thread_cap = thread_cap,
|
||||||
.entry = entry,
|
.entry = entry,
|
||||||
|
@ -61,72 +64,28 @@ z_err_t ZThreadStart(uint64_t thread_cap, uint64_t entry, uint64_t arg1,
|
||||||
|
|
||||||
void ZThreadExit() { SysCall0(Z_THREAD_EXIT); }
|
void ZThreadExit() { SysCall0(Z_THREAD_EXIT); }
|
||||||
|
|
||||||
z_err_t ZAddressSpaceMap(uint64_t vmas_cap, uint64_t vmas_offset,
|
uint64_t ZAddressSpaceMap(uint64_t vmas_cap, uint64_t vmas_offset,
|
||||||
uint64_t vmmo_cap, uint64_t* vaddr) {
|
uint64_t vmmo_cap, uint64_t* vaddr) {
|
||||||
ZAddressSpaceMapReq req{
|
ZAddressSpaceMapReq req{
|
||||||
.vmas_cap = vmas_cap,
|
.vmas_cap = vmas_cap,
|
||||||
.vmas_offset = vmas_offset,
|
.vmas_offset = vmas_offset,
|
||||||
.vmmo_cap = vmmo_cap,
|
.vmmo_cap = vmmo_cap,
|
||||||
};
|
};
|
||||||
ZAddressSpaceMapResp resp;
|
ZAddressSpaceMapResp resp;
|
||||||
z_err_t ret = SysCall2(Z_ADDRESS_SPACE_MAP, &req, &resp);
|
uint64_t ret = SysCall2(Z_ADDRESS_SPACE_MAP, &req, &resp);
|
||||||
*vaddr = resp.vaddr;
|
*vaddr = resp.vaddr;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
z_err_t ZMemoryObjectCreate(uint64_t size, uint64_t* vmmo_cap) {
|
uint64_t ZMemoryObjectCreate(uint64_t size, uint64_t* vmmo_cap) {
|
||||||
ZMemoryObjectCreateReq req{
|
ZMemoryObjectCreateReq req{
|
||||||
.size = size,
|
.size = size,
|
||||||
};
|
};
|
||||||
ZMemoryObjectCreateResp resp;
|
ZMemoryObjectCreateResp resp;
|
||||||
z_err_t ret = SysCall2(Z_MEMORY_OBJECT_CREATE, &req, &resp);
|
uint64_t ret = SysCall2(Z_MEMORY_OBJECT_CREATE, &req, &resp);
|
||||||
*vmmo_cap = resp.vmmo_cap;
|
*vmmo_cap = resp.vmmo_cap;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t ZChannelCreate(uint64_t* channel1, uint64_t* channel2) {
|
uint64_t ZDebug(const char* message) {
|
||||||
ZChannelCreateResp resp;
|
return SysCall1(Z_DEBUG_PRINT, message);
|
||||||
z_err_t ret = SysCall2(Z_CHANNEL_CREATE, 0, &resp);
|
|
||||||
*channel1 = resp.chan_cap1;
|
|
||||||
*channel2 = resp.chan_cap2;
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t ZChannelSend(uint64_t chan_cap, uint64_t type, uint64_t num_bytes,
|
|
||||||
const uint8_t* bytes, uint64_t num_caps,
|
|
||||||
const uint64_t* caps) {
|
|
||||||
ZChannelSendReq req{
|
|
||||||
.chan_cap = chan_cap,
|
|
||||||
.message =
|
|
||||||
{
|
|
||||||
.type = type,
|
|
||||||
.num_bytes = num_bytes,
|
|
||||||
.bytes = const_cast<uint8_t*>(bytes),
|
|
||||||
.num_caps = num_caps,
|
|
||||||
.caps = const_cast<uint64_t*>(caps),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
return SysCall1(Z_CHANNEL_SEND, &req);
|
|
||||||
}
|
|
||||||
|
|
||||||
z_err_t ZChannelRecv(uint64_t chan_cap, uint64_t num_bytes, uint8_t* bytes,
|
|
||||||
uint64_t num_caps, uint64_t* caps, uint64_t* type,
|
|
||||||
uint64_t* actual_bytes, uint64_t* actual_caps) {
|
|
||||||
ZChannelRecvReq req{
|
|
||||||
.chan_cap = chan_cap,
|
|
||||||
.message =
|
|
||||||
{
|
|
||||||
.type = 0,
|
|
||||||
.num_bytes = num_bytes,
|
|
||||||
.bytes = bytes,
|
|
||||||
.num_caps = num_caps,
|
|
||||||
.caps = caps,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
z_err_t ret = SysCall1(Z_CHANNEL_RECV, &req);
|
|
||||||
*type = req.message.type;
|
|
||||||
*actual_bytes = req.message.num_bytes;
|
|
||||||
*actual_caps = req.message.num_caps;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
z_err_t ZDebug(const char* message) { return SysCall1(Z_DEBUG_PRINT, message); }
|
|
||||||
|
|
|
@ -4,13 +4,11 @@
|
||||||
|
|
||||||
struct ZProcessSpawnReq {
|
struct ZProcessSpawnReq {
|
||||||
uint64_t proc_cap;
|
uint64_t proc_cap;
|
||||||
uint64_t bootstrap_cap;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ZProcessSpawnResp {
|
struct ZProcessSpawnResp {
|
||||||
uint64_t proc_cap;
|
uint64_t proc_cap;
|
||||||
uint64_t vmas_cap;
|
uint64_t vmas_cap;
|
||||||
uint64_t bootstrap_cap;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ZThreadCreateReq {
|
struct ZThreadCreateReq {
|
||||||
|
@ -45,28 +43,3 @@ struct ZMemoryObjectCreateReq {
|
||||||
struct ZMemoryObjectCreateResp {
|
struct ZMemoryObjectCreateResp {
|
||||||
uint64_t vmmo_cap;
|
uint64_t vmmo_cap;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ZChannelCreateResp {
|
|
||||||
uint64_t chan_cap1;
|
|
||||||
uint64_t chan_cap2;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ZMessage {
|
|
||||||
uint64_t type;
|
|
||||||
|
|
||||||
uint64_t num_bytes;
|
|
||||||
uint8_t* bytes;
|
|
||||||
|
|
||||||
uint64_t num_caps;
|
|
||||||
uint64_t* caps;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ZChannelSendReq {
|
|
||||||
uint64_t chan_cap;
|
|
||||||
ZMessage message;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ZChannelRecvReq {
|
|
||||||
uint64_t chan_cap;
|
|
||||||
ZMessage message;
|
|
||||||
};
|
|
||||||
|
|
Loading…
Reference in New Issue