KfAcquireSpinLock/KfReleaesSpinLock.

This commit is contained in:
Ben Vanik 2013-10-18 19:11:37 -07:00
parent 28e7102a02
commit 6a02ae3768
2 changed files with 49 additions and 0 deletions

View File

@ -559,6 +559,49 @@ SHIM_CALL NtWaitForSingleObjectEx_shim(
}
uint32_t xeKfAcquireSpinLock(void* lock_ptr) {
while (!xe_atomic_cas_32(0, 1, lock_ptr)) {
// Spin!
}
// TODO(benvanik): set dispatch level.
return 0;
}
SHIM_CALL KfAcquireSpinLock_shim(
xe_ppc_state_t* ppc_state, KernelState* state) {
uint32_t lock_ptr = SHIM_GET_ARG_32(0);
XELOGD(
"KfAcquireSpinLock(%.8X)",
lock_ptr);
uint32_t old_irql = xeKfAcquireSpinLock(SHIM_MEM_ADDR(lock_ptr));
SHIM_SET_RETURN(old_irql);
}
void xeKfReleaseSpinLock(void* lock_ptr, uint32_t old_irql) {
// TODO(benvanik): reset dispatch level.
xe_atomic_dec_32(lock_ptr);
}
SHIM_CALL KfReleaseSpinLock_shim(
xe_ppc_state_t* ppc_state, KernelState* state) {
uint32_t lock_ptr = SHIM_GET_ARG_32(0);
uint32_t old_irql = SHIM_GET_ARG_32(1);
XELOGD(
"KfReleaseSpinLock(%.8X, %d)",
lock_ptr,
old_irql);
xeKfReleaseSpinLock(SHIM_MEM_ADDR(lock_ptr), old_irql);
}
} // namespace xboxkrnl
} // namespace kernel
} // namespace xe
@ -586,4 +629,7 @@ void xe::kernel::xboxkrnl::RegisterThreadingExports(
SHIM_SET_MAPPING("xboxkrnl.exe", KeWaitForSingleObject, state);
SHIM_SET_MAPPING("xboxkrnl.exe", NtWaitForSingleObjectEx, state);
SHIM_SET_MAPPING("xboxkrnl.exe", KfAcquireSpinLock, state);
SHIM_SET_MAPPING("xboxkrnl.exe", KfReleaseSpinLock, state);
}

View File

@ -47,6 +47,9 @@ X_STATUS xeKeWaitForSingleObject(
void* object_ptr, uint32_t wait_reason, uint32_t processor_mode,
uint32_t alertable, uint64_t* opt_timeout);
uint32_t xeKfAcquireSpinLock(void* lock_ptr);
void xeKfReleaseSpinLock(void* lock_ptr, uint32_t old_irql);
} // namespace xboxkrnl
} // namespace kernel