2007-06-03 01:57:37 +00:00
|
|
|
#ifndef SYSTEM_H
|
|
|
|
#define SYSTEM_H
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
2007-06-18 19:23:44 +00:00
|
|
|
namespace vm {
|
|
|
|
|
2007-06-03 01:57:37 +00:00
|
|
|
class System {
|
|
|
|
public:
|
2007-06-20 21:27:22 +00:00
|
|
|
typedef intptr_t Status;
|
2007-06-03 01:57:37 +00:00
|
|
|
|
|
|
|
class Thread {
|
|
|
|
public:
|
|
|
|
virtual ~Thread() { }
|
|
|
|
virtual void run() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Monitor {
|
|
|
|
public:
|
|
|
|
virtual ~Monitor() { }
|
2007-06-15 00:50:55 +00:00
|
|
|
virtual bool tryAcquire(void* id) = 0;
|
|
|
|
virtual void acquire(void* id) = 0;
|
|
|
|
virtual void release(void* id) = 0;
|
|
|
|
virtual void wait(void* id) = 0;
|
|
|
|
virtual void notify(void* id) = 0;
|
|
|
|
virtual void notifyAll(void* id) = 0;
|
2007-06-03 01:57:37 +00:00
|
|
|
virtual void dispose() = 0;
|
|
|
|
};
|
|
|
|
|
2007-06-24 01:39:49 +00:00
|
|
|
class Library {
|
|
|
|
public:
|
|
|
|
virtual ~Library() { }
|
|
|
|
virtual void* resolve(const char* function) = 0;
|
|
|
|
virtual Library* next() = 0;
|
2007-06-24 19:57:00 +00:00
|
|
|
virtual void dispose() = 0;
|
2007-06-24 01:39:49 +00:00
|
|
|
};
|
|
|
|
|
2007-06-03 01:57:37 +00:00
|
|
|
virtual ~System() { }
|
|
|
|
|
|
|
|
virtual bool success(Status) = 0;
|
2007-06-22 02:13:17 +00:00
|
|
|
virtual void* tryAllocate(unsigned size) = 0;
|
2007-06-20 19:20:25 +00:00
|
|
|
virtual void free(const void*) = 0;
|
2007-06-03 01:57:37 +00:00
|
|
|
virtual Status start(Thread*) = 0;
|
|
|
|
virtual Status make(Monitor**) = 0;
|
2007-06-24 01:39:49 +00:00
|
|
|
virtual uint64_t call(void* function, unsigned argumentCount,
|
|
|
|
uint32_t* argumentTable, uint8_t* argumentSizeTable,
|
|
|
|
unsigned returnSize);
|
|
|
|
virtual Status load(Library**, const char* name, Library* next);
|
2007-06-18 04:25:42 +00:00
|
|
|
virtual void abort() = 0;
|
2007-06-20 19:20:25 +00:00
|
|
|
|
|
|
|
void* allocate(unsigned size) {
|
2007-06-22 02:13:17 +00:00
|
|
|
void* p = tryAllocate(size);
|
|
|
|
if (p == 0) {
|
2007-06-20 19:20:25 +00:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
2007-06-03 01:57:37 +00:00
|
|
|
};
|
|
|
|
|
2007-06-22 23:17:13 +00:00
|
|
|
inline void NO_RETURN
|
|
|
|
abort(System* s)
|
|
|
|
{
|
|
|
|
s->abort(); // this should not return
|
|
|
|
::abort();
|
|
|
|
}
|
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
inline void
|
|
|
|
expect(System* s, bool v)
|
|
|
|
{
|
|
|
|
if (UNLIKELY(not v)) abort(s);
|
|
|
|
}
|
|
|
|
|
2007-06-22 23:17:13 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
inline void
|
|
|
|
assert(System*, bool)
|
|
|
|
{ }
|
|
|
|
#else
|
|
|
|
inline void
|
|
|
|
assert(System* s, bool v)
|
|
|
|
{
|
2007-06-24 19:57:00 +00:00
|
|
|
expect(s, v);
|
2007-06-22 23:17:13 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-06-18 19:23:44 +00:00
|
|
|
} // namespace vm
|
|
|
|
|
2007-06-03 01:57:37 +00:00
|
|
|
#endif//SYSTEM_H
|