[Zion] Add a mutex object with appropriate syscalls.
This commit is contained in:
parent
4c2237fa72
commit
4c04f9d561
19 changed files with 160 additions and 60 deletions
31
zion/syscall/synchronization.cpp
Normal file
31
zion/syscall/synchronization.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#include "syscall/synchronization.h"
|
||||
|
||||
#include "object/mutex.h"
|
||||
#include "scheduler/scheduler.h"
|
||||
|
||||
glcr::ErrorCode MutexCreate(ZMutexCreateReq* req) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
*req->mutex_cap = curr_proc.AddNewCapability(Mutex::Create());
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
glcr::ErrorCode MutexLock(ZMutexLockReq* req) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
auto cap = curr_proc.GetCapability(req->mutex_cap);
|
||||
RET_ERR(ValidateCapability<Mutex>(cap, kZionPerm_Lock));
|
||||
|
||||
auto mutex = cap->obj<Mutex>();
|
||||
mutex->Lock();
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
glcr::ErrorCode MutexRelease(ZMutexReleaseReq* req) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
auto cap = curr_proc.GetCapability(req->mutex_cap);
|
||||
// TODO: We may not want a separate permission for releasing the mutex.
|
||||
RET_ERR(ValidateCapability<Mutex>(cap, kZionPerm_Release));
|
||||
|
||||
auto mutex = cap->obj<Mutex>();
|
||||
mutex->Release();
|
||||
return glcr::OK;
|
||||
}
|
||||
9
zion/syscall/synchronization.h
Normal file
9
zion/syscall/synchronization.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/status/error.h>
|
||||
|
||||
#include "include/zcall.h"
|
||||
|
||||
glcr::ErrorCode MutexCreate(ZMutexCreateReq* req);
|
||||
glcr::ErrorCode MutexLock(ZMutexLockReq* req);
|
||||
glcr::ErrorCode MutexRelease(ZMutexReleaseReq* req);
|
||||
|
|
@ -11,6 +11,7 @@
|
|||
#include "syscall/ipc.h"
|
||||
#include "syscall/memory_object.h"
|
||||
#include "syscall/process.h"
|
||||
#include "syscall/synchronization.h"
|
||||
#include "syscall/thread.h"
|
||||
|
||||
#define EFER 0xC0000080
|
||||
|
|
@ -80,6 +81,10 @@ extern "C" z_err_t SyscallHandler(uint64_t call_id, void* req) {
|
|||
CASE(ReplyPortRecv);
|
||||
// syscall/capability.h
|
||||
CASE(CapDuplicate);
|
||||
// syscall/syncronization.h
|
||||
CASE(MutexCreate);
|
||||
CASE(MutexLock);
|
||||
CASE(MutexRelease);
|
||||
// syscall/debug.h
|
||||
CASE(Debug);
|
||||
default:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue