WSACreateEvent/CloseEvent/SetEvent.

This commit is contained in:
Ben Vanik 2015-08-30 21:31:52 -07:00
parent 7233df2778
commit a4ed79695d
3 changed files with 52 additions and 31 deletions

View File

@ -23,7 +23,7 @@ namespace frontend {
#define XEREGISTERINSTR(name, opcode) \
RegisterInstrEmit(opcode, (InstrEmitFn)InstrEmit_##name);
#define XEINSTRNOTIMPLEMENTED() \
#define XEINSTRNOTIMPLEMENTED() \
XELOGE("Unimplemented instruction: %s", __FUNCTION__); \
assert_always("Instruction not implemented");

View File

@ -253,8 +253,7 @@ dword_result_t NetDll_WSARecvFrom(dword_t caller, dword_t socket,
return 0;
}
DECLARE_XAM_EXPORT(NetDll_WSARecvFrom,
ExportTag::kNetworking | ExportTag::kStub);
DECLARE_XAM_EXPORT(NetDll_WSARecvFrom, ExportTag::kNetworking);
dword_result_t NtWaitForMultipleObjectsEx(
dword_t count, pointer_t<xe::be<uint32_t>> handles, dword_t wait_type,
@ -284,27 +283,58 @@ dword_result_t NetDll_WSAWaitForMultipleEvents(
XThread::GetCurrentThread()->set_last_error(error);
return ~0u;
}
return 0;
}
DECLARE_XAM_EXPORT(NetDll_WSAWaitForMultipleEvents,
ExportTag::kNetworking | ExportTag::kStub);
ExportTag::kNetworking | ExportTag::kThreading);
dword_result_t NtClearEvent(dword_t handle);
dword_result_t NetDll_WSAResetEvent(dword_t event_handle) {
X_STATUS result = NtClearEvent(event_handle);
dword_result_t NetDll_WSACreateEvent() {
XEvent* ev = new XEvent(kernel_state());
ev->Initialize(true, false);
return ev->handle();
}
DECLARE_XAM_EXPORT(NetDll_WSACreateEvent,
ExportTag::kNetworking | ExportTag::kThreading);
dword_result_t NetDll_WSACloseEvent(dword_t event_handle) {
X_STATUS result = kernel_state()->object_table()->ReleaseHandle(event_handle);
if (XFAILED(result)) {
uint32_t error = RtlNtStatusToDosError(result);
XThread::GetCurrentThread()->set_last_error(error);
return 0;
}
return 1;
}
DECLARE_XAM_EXPORT(NetDll_WSACloseEvent,
ExportTag::kNetworking | ExportTag::kThreading);
dword_result_t NtClearEvent(dword_t handle);
dword_result_t NetDll_WSAResetEvent(dword_t event_handle) {
X_STATUS result = NtClearEvent(event_handle);
if (XFAILED(result)) {
uint32_t error = RtlNtStatusToDosError(result);
XThread::GetCurrentThread()->set_last_error(error);
return 0;
}
return 1;
}
DECLARE_XAM_EXPORT(NetDll_WSAResetEvent,
ExportTag::kNetworking | ExportTag::kStub);
ExportTag::kNetworking | ExportTag::kThreading);
dword_result_t NtSetEvent(dword_t handle, lpdword_t previous_state_ptr);
dword_result_t NetDll_WSASetEvent(dword_t event_handle) {
X_STATUS result = NtSetEvent(event_handle, nullptr);
if (XFAILED(result)) {
uint32_t error = RtlNtStatusToDosError(result);
XThread::GetCurrentThread()->set_last_error(error);
return 0;
}
return 1;
}
DECLARE_XAM_EXPORT(NetDll_WSASetEvent,
ExportTag::kNetworking | ExportTag::kThreading);
struct XnAddrStatus {
// Address acquisition is not yet complete

View File

@ -512,48 +512,41 @@ SHIM_CALL NtCreateEvent_shim(PPCContext* ppc_context,
SHIM_SET_RETURN_32(X_STATUS_SUCCESS);
}
SHIM_CALL NtSetEvent_shim(PPCContext* ppc_context, KernelState* kernel_state) {
uint32_t event_handle = SHIM_GET_ARG_32(0);
uint32_t previous_state_ptr = SHIM_GET_ARG_32(1);
XELOGD("NtSetEvent(%.8X, %.8X)", event_handle, previous_state_ptr);
dword_result_t NtSetEvent(dword_t handle, lpdword_t previous_state_ptr) {
X_STATUS result = X_STATUS_SUCCESS;
auto ev = kernel_state->object_table()->LookupObject<XEvent>(event_handle);
auto ev = kernel_state()->object_table()->LookupObject<XEvent>(handle);
if (ev) {
int32_t was_signalled = ev->Set(0, false);
if (previous_state_ptr) {
SHIM_SET_MEM_32(previous_state_ptr, was_signalled);
*previous_state_ptr = static_cast<uint32_t>(was_signalled);
}
} else {
result = X_STATUS_INVALID_HANDLE;
}
SHIM_SET_RETURN_32(result);
return result;
}
DECLARE_XBOXKRNL_EXPORT(NtSetEvent,
ExportTag::kImplemented | ExportTag::kThreading);
SHIM_CALL NtPulseEvent_shim(PPCContext* ppc_context,
KernelState* kernel_state) {
uint32_t event_handle = SHIM_GET_ARG_32(0);
uint32_t previous_state_ptr = SHIM_GET_ARG_32(1);
XELOGD("NtPulseEvent(%.8X, %.8X)", event_handle, previous_state_ptr);
dword_result_t NtPulseEvent(dword_t handle, lpdword_t previous_state_ptr) {
X_STATUS result = X_STATUS_SUCCESS;
auto ev = kernel_state->object_table()->LookupObject<XEvent>(event_handle);
auto ev = kernel_state()->object_table()->LookupObject<XEvent>(handle);
if (ev) {
int32_t was_signalled = ev->Pulse(0, false);
if (previous_state_ptr) {
SHIM_SET_MEM_32(previous_state_ptr, was_signalled);
*previous_state_ptr = static_cast<uint32_t>(was_signalled);
}
} else {
result = X_STATUS_INVALID_HANDLE;
}
SHIM_SET_RETURN_32(result);
return result;
}
DECLARE_XBOXKRNL_EXPORT(NtPulseEvent,
ExportTag::kImplemented | ExportTag::kThreading);
dword_result_t NtClearEvent(dword_t handle) {
X_STATUS result = X_STATUS_SUCCESS;
@ -1390,8 +1383,6 @@ void xe::kernel::xboxkrnl::RegisterThreadingExports(
SHIM_SET_MAPPING("xboxkrnl.exe", KeTlsSetValue, state);
SHIM_SET_MAPPING("xboxkrnl.exe", NtCreateEvent, state);
SHIM_SET_MAPPING("xboxkrnl.exe", NtSetEvent, state);
SHIM_SET_MAPPING("xboxkrnl.exe", NtPulseEvent, state);
SHIM_SET_MAPPING("xboxkrnl.exe", NtCreateSemaphore, state);
SHIM_SET_MAPPING("xboxkrnl.exe", NtReleaseSemaphore, state);