Fixing some misc bugs.

This commit is contained in:
Ben Vanik 2015-03-28 15:45:39 -07:00
parent ea28c563ad
commit 71eabf7f2b
4 changed files with 24 additions and 12 deletions

View File

@ -364,11 +364,22 @@ void X64Emitter::DebugBreak() {
db(0xCC);
}
uint64_t TrapDebugPrint(void* raw_context, uint64_t address) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
uint32_t str_ptr = uint32_t(thread_state->context()->r[3]);
uint16_t str_len = uint16_t(thread_state->context()->r[4]);
const char* str =
reinterpret_cast<const char*>(thread_state->memory()->Translate(str_ptr));
// TODO(benvanik): truncate to length?
PLOGD("(DebugPrint) %s", str);
return 0;
}
void X64Emitter::Trap(uint16_t trap_type) {
switch (trap_type) {
case 20:
case 26:
// 0x0FE00014 is a 'debug print' where r3 = buffer r4 = length
// TODO(benvanik): debug print at runtime.
CallNative(TrapDebugPrint, 0);
break;
case 0:
case 22:
@ -378,6 +389,9 @@ void X64Emitter::Trap(uint16_t trap_type) {
db(0xCC);
}
break;
case 25:
// ?
break;
default:
PLOGW("Unknown trap type %d", trap_type);
db(0xCC);

View File

@ -60,7 +60,7 @@ class XThread : public XObject {
void SetPriority(int32_t increment);
void SetAffinity(uint32_t affinity);
X_STATUS Resume(uint32_t* out_suspend_count);
X_STATUS Resume(uint32_t* out_suspend_count = nullptr);
X_STATUS Suspend(uint32_t* out_suspend_count);
X_STATUS Delay(uint32_t processor_mode, uint32_t alertable,
uint64_t interval);

View File

@ -539,6 +539,7 @@ int xe_xex2_read_image_uncompressed(const xe_xex2_header_t *header,
return 2;
}
uint8_t *buffer = memory->Translate(header->exe_address);
std::memset(buffer, 0, uncompressed_size);
const uint8_t *p = (const uint8_t *)xex_addr + header->exe_offset;
@ -589,6 +590,7 @@ int xe_xex2_read_image_basic_compressed(const xe_xex2_header_t *header,
}
uint8_t *buffer = memory->Translate(header->exe_address);
uint8_t *d = buffer;
std::memset(buffer, 0, uncompressed_size);
uint32_t rk[4 * (MAXNR + 1)];
uint8_t ivec[16] = {0};
@ -725,6 +727,7 @@ int xe_xex2_read_image_compressed(const xe_xex2_header_t *header,
goto XECLEANUP;
}
uint8_t *buffer = memory->Translate(header->exe_address);
std::memset(buffer, 0, uncompressed_size);
// Setup decompressor and decompress.
sys = mspack_memory_sys_create();

View File

@ -159,21 +159,14 @@ SHIM_CALL NtResumeThread_shim(PPCContext* ppc_state, KernelState* state) {
SHIM_CALL KeResumeThread_shim(PPCContext* ppc_state, KernelState* state) {
uint32_t thread_ptr = SHIM_GET_ARG_32(0);
uint32_t suspend_count_ptr = SHIM_GET_ARG_32(1);
XELOGD("KeResumeThread(%.8X, %.8X)", thread_ptr, suspend_count_ptr);
XELOGD("KeResumeThread(%.8X)", thread_ptr);
X_STATUS result;
XThread* thread =
(XThread*)XObject::GetObject(state, SHIM_MEM_ADDR(thread_ptr));
uint32_t suspend_count;
if (thread) {
result = thread->Resume(&suspend_count);
}
if (XSUCCEEDED(result)) {
if (suspend_count_ptr) {
SHIM_SET_MEM_32(suspend_count_ptr, suspend_count);
}
result = thread->Resume();
}
SHIM_SET_RETURN_32(result);
@ -447,7 +440,9 @@ SHIM_CALL NtCreateEvent_shim(PPCContext* ppc_state, KernelState* state) {
// TODO(benvanik): check for name collision. May return existing object if
// type matches.
AssertNoNameCollision(state, obj_attributes_ptr);
if (obj_attributes_ptr) {
AssertNoNameCollision(state, obj_attributes_ptr);
}
XEvent* ev = new XEvent(state);
ev->Initialize(!event_type, !!initial_state);