Add more wrapper functions to ppc_context_t in kernel, want to switch…
… over to referencing state through ppc_context as much as possible, it'll make implementing things like kernel processes much easier in the future Move forward definitions of kernel types into kernel_fwd.h Stub implementation of XamLoaderGetMediaInfoEx Partially implement XamSetDashContext implement XamGetDashContext Stub implementation of XamUserIsUnsafeProgrammingAllowed Stub implementation of XamUserGetSubscriptionType Expanded the supported object types for ObReferenceObjectByHandle and wrapped the logic for encoding the type in a constexpr function ObReferenceObjectByName was taking lpstring_t for first param, but the function actually takes X_ANSI_STRING ptr NtReleaseMutant actually does not return anything from KeReleaseMutant, it just checks the handle and returns whether it was invalid. Changed the raise/lower irql functions to just set the irql on the pcr instead of setting it on field of Processor, processor is a shared object and irql is per-thread Semi-stub implementation of KeGetImagePageTableEntry. I locked at it in the HV and got it so the values are in the same range the HV returns + actually reflect the page & memory range, but i doubt its equal to the values the hv returns on real hw. Used by modern dashboards, don't know for what. Log error message for ObDereferenceObject w/ null ptr. Allocate a special fixed page that dashboards reference, currently don't know what the data on that page is supposed to be. Add current_irql field to X_KPCR Added Device object member of XObject::Type enum Added some notes about other gpu registers, found a table of register names and indices in xam
This commit is contained in:
@@ -632,9 +632,30 @@ void ExFreePool_entry(lpvoid_t base_address) {
|
||||
}
|
||||
DECLARE_XBOXKRNL_EXPORT1(ExFreePool, kMemory, kImplemented);
|
||||
|
||||
dword_result_t KeGetImagePageTableEntry_entry(lpvoid_t address) {
|
||||
// Unknown
|
||||
return 1;
|
||||
// hv syscall 15, jumps into (bootloader function table??) alternative table ptr
|
||||
// offset 224
|
||||
// this is not a correct implementation. i just wanted to get it to return a
|
||||
// value thats in the same range as the hv's values that kind of reflects the
|
||||
// pages index and heap
|
||||
dword_result_t KeGetImagePageTableEntry_entry(dword_t address,
|
||||
const ppc_context_t& ctx) {
|
||||
auto kernel_state = ctx->kernel_state;
|
||||
xe::BaseHeap* image_heap = kernel_state->memory()->LookupHeap(address);
|
||||
if (image_heap->heap_type() != HeapType::kGuestXex) {
|
||||
return 0;
|
||||
}
|
||||
uint32_t returned_value = address - image_heap->heap_base();
|
||||
|
||||
// todo: its always a power of two, should shift
|
||||
returned_value /= image_heap->page_size();
|
||||
|
||||
if (image_heap->page_size() < 65536) {
|
||||
returned_value |= 0x40000000;
|
||||
}
|
||||
|
||||
return returned_value & 0x400FFFFF; // this is actually the mask it applies
|
||||
// to the final
|
||||
// result before returning it
|
||||
}
|
||||
DECLARE_XBOXKRNL_EXPORT1(KeGetImagePageTableEntry, kMemory, kStub);
|
||||
|
||||
|
||||
@@ -83,12 +83,25 @@ dword_result_t ObLookupThreadByThreadId_entry(dword_t thread_id,
|
||||
return X_STATUS_SUCCESS;
|
||||
}
|
||||
DECLARE_XBOXKRNL_EXPORT1(ObLookupThreadByThreadId, kNone, kImplemented);
|
||||
|
||||
template <uint32_t ordinal>
|
||||
static constexpr uint32_t object_type_id_for_ordinal_v =
|
||||
0xD000BEEF | (ordinal << 16);
|
||||
// These values come from how Xenia handles uninitialized kernel data exports.
|
||||
// D###BEEF where ### is the ordinal.
|
||||
const static std::unordered_map<XObject::Type, uint32_t> object_types = {
|
||||
{XObject::Type::Event, 0xD00EBEEF},
|
||||
{XObject::Type::Semaphore, 0xD017BEEF},
|
||||
{XObject::Type::Thread, 0xD01BBEEF}};
|
||||
{XObject::Type::Event,
|
||||
object_type_id_for_ordinal_v<ordinals::ExEventObjectType>},
|
||||
{XObject::Type::Semaphore,
|
||||
object_type_id_for_ordinal_v<ordinals::ExSemaphoreObjectType>},
|
||||
{XObject::Type::Thread,
|
||||
object_type_id_for_ordinal_v<ordinals::ExThreadObjectType>},
|
||||
{XObject::Type::File,
|
||||
object_type_id_for_ordinal_v<ordinals::IoFileObjectType>},
|
||||
{XObject::Type::Mutant,
|
||||
object_type_id_for_ordinal_v<ordinals::ExMutantObjectType>},
|
||||
{XObject::Type::Device,
|
||||
object_type_id_for_ordinal_v<ordinals::IoDeviceObjectType>}};
|
||||
dword_result_t ObReferenceObjectByHandle_entry(dword_t handle,
|
||||
dword_t object_type_ptr,
|
||||
lpdword_t out_object_ptr) {
|
||||
@@ -113,6 +126,8 @@ dword_result_t ObReferenceObjectByHandle_entry(dword_t handle,
|
||||
// Caller takes the reference.
|
||||
// It's released in ObDereferenceObject.
|
||||
object->RetainHandle();
|
||||
|
||||
xenia_assert(native_ptr != 0);
|
||||
if (out_object_ptr.guest_address()) {
|
||||
*out_object_ptr = native_ptr;
|
||||
}
|
||||
@@ -120,14 +135,17 @@ dword_result_t ObReferenceObjectByHandle_entry(dword_t handle,
|
||||
}
|
||||
DECLARE_XBOXKRNL_EXPORT1(ObReferenceObjectByHandle, kNone, kImplemented);
|
||||
|
||||
dword_result_t ObReferenceObjectByName_entry(lpstring_t name,
|
||||
dword_result_t ObReferenceObjectByName_entry(pointer_t<X_ANSI_STRING> name,
|
||||
dword_t attributes,
|
||||
dword_t object_type_ptr,
|
||||
lpvoid_t parse_context,
|
||||
lpdword_t out_object_ptr) {
|
||||
lpdword_t out_object_ptr,
|
||||
const ppc_context_t& ctx) {
|
||||
X_HANDLE handle = X_INVALID_HANDLE_VALUE;
|
||||
|
||||
char* name_str = ctx.TranslateVirtual<char*>(name->pointer);
|
||||
X_STATUS result =
|
||||
kernel_state()->object_table()->GetObjectByName(name.value(), &handle);
|
||||
kernel_state()->object_table()->GetObjectByName(name_str, &handle);
|
||||
if (XSUCCEEDED(result)) {
|
||||
return ObReferenceObjectByHandle_entry(handle, object_type_ptr,
|
||||
out_object_ptr);
|
||||
@@ -142,6 +160,10 @@ void ObDereferenceObject_entry(dword_t native_ptr, const ppc_context_t& ctx) {
|
||||
if (native_ptr == 0xDEADF00D) {
|
||||
return;
|
||||
}
|
||||
if (!native_ptr) {
|
||||
XELOGE("Null native ptr in ObDereferenceObject!");
|
||||
return;
|
||||
}
|
||||
|
||||
auto object = XObject::GetNativeObject<XObject>(
|
||||
kernel_state(), kernel_memory()->TranslateVirtual(native_ptr));
|
||||
|
||||
@@ -245,7 +245,7 @@ void KeSetCurrentStackPointers_entry(lpvoid_t stack_ptr,
|
||||
pcr->stack_base_ptr = stack_base.guest_address();
|
||||
pcr->stack_end_ptr = stack_limit.guest_address();
|
||||
context->r[1] = stack_ptr.guest_address();
|
||||
|
||||
|
||||
// If a fiber is set, and the thread matches, reenter to avoid issues with
|
||||
// host stack overflowing.
|
||||
if (thread->fiber_ptr &&
|
||||
@@ -337,8 +337,8 @@ DECLARE_XBOXKRNL_EXPORT2(KeQueryPerformanceFrequency, kThreading, kImplemented,
|
||||
kHighFrequency);
|
||||
|
||||
uint32_t KeDelayExecutionThread(uint32_t processor_mode,
|
||||
uint32_t alertable,
|
||||
uint64_t* interval_ptr) {
|
||||
uint32_t alertable,
|
||||
uint64_t* interval_ptr) {
|
||||
XThread* thread = XThread::GetCurrentThread();
|
||||
X_STATUS result = thread->Delay(processor_mode, alertable, *interval_ptr);
|
||||
|
||||
@@ -521,7 +521,7 @@ uint32_t xeNtSetEvent(uint32_t handle, xe::be<uint32_t>* previous_state_ptr) {
|
||||
//d3 ros does this
|
||||
if (ev->type() != XObject::Type::Event) {
|
||||
return X_STATUS_OBJECT_TYPE_MISMATCH;
|
||||
}
|
||||
}
|
||||
int32_t was_signalled = ev->Set(0, false);
|
||||
if (previous_state_ptr) {
|
||||
*previous_state_ptr = static_cast<uint32_t>(was_signalled);
|
||||
@@ -746,7 +746,7 @@ dword_result_t NtReleaseMutant_entry(dword_t mutant_handle, dword_t unknown) {
|
||||
auto mutant =
|
||||
kernel_state()->object_table()->LookupObject<XMutant>(mutant_handle);
|
||||
if (mutant) {
|
||||
result = mutant->ReleaseMutant(priority_increment, abandon, wait);
|
||||
mutant->ReleaseMutant(priority_increment, abandon, wait);
|
||||
} else {
|
||||
result = X_STATUS_INVALID_HANDLE;
|
||||
}
|
||||
@@ -992,11 +992,7 @@ dword_result_t NtSignalAndWaitForSingleObjectEx_entry(dword_t signal_handle,
|
||||
DECLARE_XBOXKRNL_EXPORT3(NtSignalAndWaitForSingleObjectEx, kThreading,
|
||||
kImplemented, kBlocking, kHighFrequency);
|
||||
|
||||
static void PrefetchForCAS(const void* value) {
|
||||
if (amd64::GetFeatureFlags() & amd64::kX64EmitPrefetchW) {
|
||||
swcache::PrefetchW(value);
|
||||
}
|
||||
}
|
||||
static void PrefetchForCAS(const void* value) { swcache::PrefetchW(value); }
|
||||
|
||||
uint32_t xeKeKfAcquireSpinLock(uint32_t* lock, uint64_t r13 = 1) {
|
||||
// XELOGD(
|
||||
@@ -1111,21 +1107,58 @@ void KeLeaveCriticalRegion_entry() {
|
||||
DECLARE_XBOXKRNL_EXPORT2(KeLeaveCriticalRegion, kThreading, kImplemented,
|
||||
kHighFrequency);
|
||||
|
||||
dword_result_t KeRaiseIrqlToDpcLevel_entry() {
|
||||
auto old_value = kernel_state()->processor()->RaiseIrql(cpu::Irql::DPC);
|
||||
return (uint32_t)old_value;
|
||||
dword_result_t KeRaiseIrqlToDpcLevel_entry(const ppc_context_t& ctx) {
|
||||
auto pcr = ctx.GetPCR();
|
||||
uint32_t old_irql = pcr->current_irql;
|
||||
|
||||
if (old_irql > 2) {
|
||||
XELOGE("KeRaiseIrqlToDpcLevel - old_irql > 2");
|
||||
}
|
||||
|
||||
pcr->current_irql = 2;
|
||||
|
||||
return old_irql;
|
||||
}
|
||||
DECLARE_XBOXKRNL_EXPORT2(KeRaiseIrqlToDpcLevel, kThreading, kImplemented,
|
||||
kHighFrequency);
|
||||
|
||||
void KfLowerIrql_entry(dword_t old_value) {
|
||||
kernel_state()->processor()->LowerIrql(
|
||||
static_cast<cpu::Irql>((uint32_t)old_value));
|
||||
// irql is supposed to be per thread afaik...
|
||||
void KfLowerIrql_entry(dword_t new_irql, const ppc_context_t& ctx) {
|
||||
X_KPCR* kpcr = ctx.GetPCR();
|
||||
|
||||
XThread::GetCurrentThread()->CheckApcs();
|
||||
if (new_irql > kpcr->current_irql) {
|
||||
XELOGE("KfLowerIrql : new_irql > kpcr->current_irql!");
|
||||
}
|
||||
kpcr->current_irql = new_irql;
|
||||
if (new_irql < 2) {
|
||||
{
|
||||
// this actually calls a function that eventually calls checkapcs.
|
||||
// the called function does a ton of other stuff including changing the
|
||||
// irql and interrupt_related
|
||||
ctx.CurrentXThread()->CheckApcs();
|
||||
}
|
||||
}
|
||||
}
|
||||
DECLARE_XBOXKRNL_EXPORT2(KfLowerIrql, kThreading, kImplemented, kHighFrequency);
|
||||
|
||||
// used by aurora's nova plugin
|
||||
// like the other irql related functions, writes to an unknown mmio range (
|
||||
// 0x7FFF ). The range is indexed by the low 16 bits of the KPCR's pointer (so
|
||||
// r13)
|
||||
dword_result_t KfRaiseIrql_entry(dword_t new_irql, const ppc_context_t& ctx) {
|
||||
X_KPCR* v1 = ctx.GetPCR();
|
||||
|
||||
uint32_t old_irql = v1->current_irql;
|
||||
v1->current_irql = new_irql;
|
||||
|
||||
if (old_irql > (unsigned int)new_irql) {
|
||||
XELOGE("KfRaiseIrql - old_irql > new_irql!");
|
||||
}
|
||||
return old_irql;
|
||||
}
|
||||
|
||||
DECLARE_XBOXKRNL_EXPORT2(KfRaiseIrql, kThreading, kImplemented, kHighFrequency);
|
||||
|
||||
void NtQueueApcThread_entry(dword_t thread_handle, lpvoid_t apc_routine,
|
||||
lpvoid_t apc_routine_context, lpvoid_t arg1,
|
||||
lpvoid_t arg2) {
|
||||
|
||||
Reference in New Issue
Block a user