From de140796a56e75a6affebcc084d2ff44d599dc11 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Tue, 7 Jan 2014 23:16:31 -0800 Subject: [PATCH] RtlTimeToTimeFields / RtlTimeFieldsToTime. TZ may be wrong. --- src/xenia/kernel/objects/xtimer.cc | 2 ++ src/xenia/kernel/xboxkrnl_rtl.cc | 57 ++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/xenia/kernel/objects/xtimer.cc b/src/xenia/kernel/objects/xtimer.cc index 63f2bf17a..f38aae6c0 100644 --- a/src/xenia/kernel/objects/xtimer.cc +++ b/src/xenia/kernel/objects/xtimer.cc @@ -76,6 +76,8 @@ void XTimer::CompletionRoutine( // Queue APC to call back routine with (arg, low, high). // TODO(benvanik): APC dispatch. XELOGE("Timer needs APC!"); + + DebugBreak(); } X_STATUS XTimer::Cancel() { diff --git a/src/xenia/kernel/xboxkrnl_rtl.cc b/src/xenia/kernel/xboxkrnl_rtl.cc index a558d1f22..bcd8ec70e 100644 --- a/src/xenia/kernel/xboxkrnl_rtl.cc +++ b/src/xenia/kernel/xboxkrnl_rtl.cc @@ -867,6 +867,60 @@ SHIM_CALL RtlLeaveCriticalSection_shim( } +SHIM_CALL RtlTimeToTimeFields_shim( + PPCContext* ppc_state, KernelState* state) { + uint32_t time_ptr = SHIM_GET_ARG_32(0); + uint32_t time_fields_ptr = SHIM_GET_ARG_32(1); + + XELOGD("RtlTimeToTimeFields(%.8X, %.8X)", time_ptr, time_fields_ptr); + + uint64_t time = SHIM_MEM_64(time_ptr); + FILETIME ft; + ft.dwHighDateTime = time >> 32; + ft.dwLowDateTime = (uint32_t)time; + + SYSTEMTIME st; + FileTimeToSystemTime(&ft, &st); + + SHIM_SET_MEM_16(time_fields_ptr + 0, st.wYear); + SHIM_SET_MEM_16(time_fields_ptr + 2, st.wMonth); + SHIM_SET_MEM_16(time_fields_ptr + 4, st.wDay); + SHIM_SET_MEM_16(time_fields_ptr + 6, st.wHour); + SHIM_SET_MEM_16(time_fields_ptr + 8, st.wMinute); + SHIM_SET_MEM_16(time_fields_ptr + 10, st.wSecond); + SHIM_SET_MEM_16(time_fields_ptr + 12, st.wMilliseconds); +} + + +SHIM_CALL RtlTimeFieldsToTime_shim( + PPCContext* ppc_state, KernelState* state) { + uint32_t time_fields_ptr = SHIM_GET_ARG_32(0); + uint32_t time_ptr = SHIM_GET_ARG_32(1); + + XELOGD("RtlTimeFieldsToTime(%.8X, %.8X)", time_fields_ptr, time_ptr); + + SYSTEMTIME st; + st.wYear = SHIM_MEM_16(time_fields_ptr + 0); + st.wMonth = SHIM_MEM_16(time_fields_ptr + 2); + st.wDay = SHIM_MEM_16(time_fields_ptr + 4); + st.wHour = SHIM_MEM_16(time_fields_ptr + 6); + st.wMinute = SHIM_MEM_16(time_fields_ptr + 8); + st.wSecond = SHIM_MEM_16(time_fields_ptr + 10); + st.wMilliseconds = SHIM_MEM_16(time_fields_ptr + 12); + + FILETIME ft; + if (!SystemTimeToFileTime(&st, &ft)) { + // set last error = ERROR_INVALID_PARAMETER + SHIM_SET_RETURN(0); + return; + } + + uint64_t time = (uint64_t(ft.dwHighDateTime) << 32) | ft.dwLowDateTime; + SHIM_SET_MEM_64(time_ptr, time); + SHIM_SET_RETURN(1); +} + + } // namespace kernel } // namespace xe @@ -885,6 +939,9 @@ void xe::kernel::xboxkrnl::RegisterRtlExports( SHIM_SET_MAPPING("xboxkrnl.exe", _vsnprintf, state); + SHIM_SET_MAPPING("xboxkrnl.exe", RtlTimeToTimeFields, state); + SHIM_SET_MAPPING("xboxkrnl.exe", RtlTimeFieldsToTime, state); + SHIM_SET_MAPPING("xboxkrnl.exe", RtlNtStatusToDosError, state); SHIM_SET_MAPPING("xboxkrnl.exe", RtlImageXexHeaderField, state);