Refactoring of function types. Also fixes some library import bugs.
This commit is contained in:
@@ -17,8 +17,9 @@ using namespace alloy;
|
||||
using namespace alloy::runtime;
|
||||
|
||||
|
||||
Function::Function(Type type, uint64_t address) :
|
||||
type_(type), address_(address), debug_info_(0) {
|
||||
Function::Function(FunctionInfo* symbol_info) :
|
||||
address_(symbol_info->address()),
|
||||
symbol_info_(symbol_info), debug_info_(0) {
|
||||
// TODO(benvanik): create on demand?
|
||||
lock_ = AllocMutex();
|
||||
}
|
||||
@@ -77,43 +78,27 @@ int Function::Call(ThreadState* thread_state) {
|
||||
if (original_thread_state != thread_state) {
|
||||
ThreadState::Bind(thread_state);
|
||||
}
|
||||
int result = CallImpl(thread_state);
|
||||
|
||||
int result = 0;
|
||||
|
||||
if (symbol_info_->behavior() == FunctionInfo::BEHAVIOR_EXTERN) {
|
||||
auto handler = symbol_info_->extern_handler();
|
||||
if (handler) {
|
||||
handler(thread_state->raw_context(),
|
||||
symbol_info_->extern_arg0(),
|
||||
symbol_info_->extern_arg1());
|
||||
} else {
|
||||
XELOGW("undefined extern call to %.8X %s",
|
||||
symbol_info_->address(),
|
||||
symbol_info_->name());
|
||||
result = 1;
|
||||
}
|
||||
} else {
|
||||
CallImpl(thread_state);
|
||||
}
|
||||
|
||||
if (original_thread_state != thread_state) {
|
||||
ThreadState::Bind(original_thread_state);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ExternFunction::ExternFunction(
|
||||
uint64_t address, Handler handler, void* arg0, void* arg1) :
|
||||
name_(0),
|
||||
handler_(handler), arg0_(arg0), arg1_(arg1),
|
||||
Function(Function::EXTERN_FUNCTION, address) {
|
||||
}
|
||||
|
||||
ExternFunction::~ExternFunction() {
|
||||
if (name_) {
|
||||
xe_free(name_);
|
||||
}
|
||||
}
|
||||
|
||||
void ExternFunction::set_name(const char* name) {
|
||||
name_ = xestrdupa(name);
|
||||
}
|
||||
|
||||
int ExternFunction::CallImpl(ThreadState* thread_state) {
|
||||
if (!handler_) {
|
||||
XELOGW("undefined extern call to %.8X %s", address(), name());
|
||||
return 0;
|
||||
}
|
||||
handler_(thread_state->raw_context(), arg0_, arg1_);
|
||||
return 0;
|
||||
}
|
||||
|
||||
GuestFunction::GuestFunction(FunctionInfo* symbol_info) :
|
||||
symbol_info_(symbol_info),
|
||||
Function(Function::USER_FUNCTION, symbol_info->address()) {
|
||||
}
|
||||
|
||||
GuestFunction::~GuestFunction() {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user