mm - GetHandleInfo

This commit is contained in:
Kelvin Sherlock 2015-02-07 12:30:12 -05:00
parent acf93dacbf
commit 33ba7e076a
2 changed files with 56 additions and 13 deletions

View File

@ -44,6 +44,7 @@
using ToolBox::Log; using ToolBox::Log;
namespace namespace
{ {
mplite_t pool; mplite_t pool;
@ -58,28 +59,23 @@ namespace
// map of ptr -> size // map of ptr -> size
std::map<uint32_t, uint32_t> PtrMap; std::map<uint32_t, uint32_t> PtrMap;
struct HandleInfo
{
uint32_t address;
uint32_t size;
bool locked;
bool purgeable;
bool resource;
HandleInfo(uint32_t a = 0, uint32_t s = 0) :
address(a), size(s), locked(false), purgeable(false), resource(false)
{}
};
// map of handle -> size [? just use Ptr map?] // map of handle -> size [? just use Ptr map?]
std::map<uint32_t, HandleInfo> HandleMap; std::map<uint32_t, MM::HandleInfo> HandleMap;
inline int16_t SetMemError(int16_t error) inline MacOS::macos_error SetMemError(MacOS::macos_error error)
{ {
memoryWriteWord(error, MacOS::MemErr); memoryWriteWord(error, MacOS::MemErr);
return error; return error;
} }
inline MacOS::macos_error SetMemError(int16_t error)
{
return SetMemError((MacOS::macos_error)error);
}
bool alloc_handle_block() bool alloc_handle_block()
{ {
const unsigned HandleCount = 128; // 512 bytes of handle blocks. const unsigned HandleCount = 128; // 512 bytes of handle blocks.
@ -584,6 +580,31 @@ namespace MM
} }
#pragma mark --
tool_return<uint32_t> GetHandleSize(uint32_t handle)
{
const auto iter = HandleMap.find(handle);
if (iter == HandleMap.end()) return SetMemError(MacOS::memWZErr);
SetMemError(0);
return iter->second.size;
}
tool_return<HandleInfo> GetHandleInfo(uint32_t handle)
{
const auto iter = HandleMap.find(handle);
if (iter == HandleMap.end()) return SetMemError(MacOS::memWZErr);
SetMemError(0);
return iter->second;
}
#pragma mark --
uint16_t BlockMove(uint16_t trap) uint16_t BlockMove(uint16_t trap)
{ {

View File

@ -3,6 +3,8 @@
#include <cstdint> #include <cstdint>
#include <macos/tool_return.h>
namespace MM namespace MM
{ {
// native functions. // native functions.
@ -35,6 +37,26 @@ namespace MM
bool Init(uint8_t *memory, uint32_t memorySize, uint32_t globals, uint32_t stack); bool Init(uint8_t *memory, uint32_t memorySize, uint32_t globals, uint32_t stack);
struct HandleInfo
{
uint32_t address = 0;
uint32_t size = 0;
bool locked = false;
bool purgeable = false;
bool resource = false;
HandleInfo(uint32_t a = 0, uint32_t s = 0) :
address(a), size(s)
{}
};
using MacOS::tool_return;
tool_return<HandleInfo> GetHandleInfo(uint32_t handle);
tool_return<uint32_t> GetHandleSize(uint32_t handle);
uint16_t BlockMove(uint16_t trap); uint16_t BlockMove(uint16_t trap);
uint32_t CompactMem(uint16_t trap); uint32_t CompactMem(uint16_t trap);
uint32_t MaxMem(uint16_t trap); uint32_t MaxMem(uint16_t trap);