aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/vm/RuntimeProcess.hpp
blob: 4ab8eb0e376599ddce1789596201295184bb6cdd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once

#include "vm/RuntimeFiber.hpp"
#include "vm/Stacktrace.hpp"
#include "vm/Utility.hpp"
#include <lauf/runtime/memory.h>
#include <lauf/runtime/process.h>
#include <lauf/runtime/stacktrace.h>

namespace OpenVic::Vm {
   struct VirtualMachine;

   struct RuntimeProcess : utility::MoveOnlyHandleBase<RuntimeProcess, lauf_runtime_process> {
      using MoveOnlyHandleBase::MoveOnlyHandleBase;
      using MoveOnlyHandleBase::operator=;

      ~RuntimeProcess() {
         lauf_runtime_destroy_process(*this);
         _handle = nullptr;
      }

      RuntimeFiber create_fiber(const lauf_asm_function* fn) {
         return RuntimeFiber(this, lauf_runtime_create_fiber(*this, fn));
      }

      RuntimeFiberRef get_current_fiber() {
         return lauf_runtime_get_current_fiber(*this);
      }

      RuntimeFiberRef get_fiber_ptr(lauf_runtime_address addr) {
         return lauf_runtime_get_fiber_ptr(*this, addr);
      }

   private:
      friend struct VirtualMachine;
      RuntimeProcess(lauf_runtime_process* process) : MoveOnlyHandleBase(process) {}
   };
}