In progress XNotify stuff. Going to merge xam/xboxkrnl next.
This commit is contained in:
parent
f23c330353
commit
aad4d7bebf
|
@ -11,6 +11,8 @@
|
||||||
'xam_module.h',
|
'xam_module.h',
|
||||||
'xam_net.cc',
|
'xam_net.cc',
|
||||||
'xam_net.h',
|
'xam_net.h',
|
||||||
|
'xam_notify.cc',
|
||||||
|
'xam_notify.h',
|
||||||
'xam_ordinals.h',
|
'xam_ordinals.h',
|
||||||
'xam_private.h',
|
'xam_private.h',
|
||||||
'xam_state.cc',
|
'xam_state.cc',
|
||||||
|
|
|
@ -45,6 +45,7 @@ XamModule::XamModule(Emulator* emulator) :
|
||||||
RegisterInfoExports(export_resolver_, xam_state_);
|
RegisterInfoExports(export_resolver_, xam_state_);
|
||||||
RegisterInputExports(export_resolver_, xam_state_);
|
RegisterInputExports(export_resolver_, xam_state_);
|
||||||
RegisterNetExports(export_resolver_, xam_state_);
|
RegisterNetExports(export_resolver_, xam_state_);
|
||||||
|
RegisterNotifyExports(export_resolver_, xam_state_);
|
||||||
RegisterUserExports(export_resolver_, xam_state_);
|
RegisterUserExports(export_resolver_, xam_state_);
|
||||||
RegisterVideoExports(export_resolver_, xam_state_);
|
RegisterVideoExports(export_resolver_, xam_state_);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* Xenia : Xbox 360 Emulator Research Project *
|
||||||
|
******************************************************************************
|
||||||
|
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||||
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <xenia/kernel/xam/xam_notify.h>
|
||||||
|
|
||||||
|
#include <xenia/kernel/shim_utils.h>
|
||||||
|
#include <xenia/kernel/xam/xam_private.h>
|
||||||
|
#include <xenia/kernel/xam/xam_state.h>
|
||||||
|
#include <xenia/kernel/xboxkrnl/objects/xnotify_listener.h>
|
||||||
|
|
||||||
|
|
||||||
|
using namespace xe;
|
||||||
|
using namespace xe::kernel;
|
||||||
|
using namespace xe::kernel::xam;
|
||||||
|
using namespace xe::kernel::xboxkrnl;
|
||||||
|
|
||||||
|
|
||||||
|
namespace xe {
|
||||||
|
namespace kernel {
|
||||||
|
namespace xam {
|
||||||
|
|
||||||
|
|
||||||
|
SHIM_CALL XamNotifyCreateListener_shim(
|
||||||
|
PPCContext* ppc_state, XamState* state) {
|
||||||
|
uint64_t mask = SHIM_GET_ARG_64(0);
|
||||||
|
uint32_t one = SHIM_GET_ARG_32(1);
|
||||||
|
|
||||||
|
XELOGD(
|
||||||
|
"XamNotifyCreateListener(%.8llX, %d)",
|
||||||
|
mask,
|
||||||
|
one);
|
||||||
|
|
||||||
|
// r4=1 may indicate user process?
|
||||||
|
|
||||||
|
//return handle;
|
||||||
|
|
||||||
|
SHIM_SET_RETURN(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// http://ffplay360.googlecode.com/svn/Test/Common/AtgSignIn.cpp
|
||||||
|
SHIM_CALL XNotifyGetNext_shim(
|
||||||
|
PPCContext* ppc_state, XamState* state) {
|
||||||
|
uint32_t handle = SHIM_GET_ARG_32(0);
|
||||||
|
uint32_t match_id = SHIM_GET_ARG_32(1);
|
||||||
|
uint32_t id_ptr = SHIM_GET_ARG_32(2);
|
||||||
|
uint32_t param_ptr = SHIM_GET_ARG_32(3);
|
||||||
|
|
||||||
|
XELOGD(
|
||||||
|
"XNotifyGetNext(%.8X, %.8X, %.8X, %.8X)",
|
||||||
|
handle,
|
||||||
|
match_id,
|
||||||
|
id_ptr,
|
||||||
|
param_ptr);
|
||||||
|
|
||||||
|
// get from handle
|
||||||
|
XNotifyListener* listener = 0;
|
||||||
|
|
||||||
|
bool dequeued = false;
|
||||||
|
uint32_t id = 0;
|
||||||
|
uint32_t param = 0;
|
||||||
|
if (match_id) {
|
||||||
|
// Asking for a specific notification
|
||||||
|
id = match_id;
|
||||||
|
dequeued = listener->DequeueNotification(match_id, ¶m);
|
||||||
|
} else {
|
||||||
|
// Just get next.
|
||||||
|
dequeued = listener->DequeueNotification(&id, ¶m);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dequeued) {
|
||||||
|
SHIM_SET_MEM_32(id_ptr, id);
|
||||||
|
SHIM_SET_MEM_32(param_ptr, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
SHIM_SET_RETURN(dequeued ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace xam
|
||||||
|
} // namespace kernel
|
||||||
|
} // namespace xe
|
||||||
|
|
||||||
|
|
||||||
|
void xe::kernel::xam::RegisterNotifyExports(
|
||||||
|
ExportResolver* export_resolver, XamState* state) {
|
||||||
|
SHIM_SET_MAPPING("xam.xex", XamNotifyCreateListener, state);
|
||||||
|
SHIM_SET_MAPPING("xam.xex", XNotifyGetNext, state);
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* Xenia : Xbox 360 Emulator Research Project *
|
||||||
|
******************************************************************************
|
||||||
|
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||||
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef XENIA_KERNEL_XAM_NOTIFY_H_
|
||||||
|
#define XENIA_KERNEL_XAM_NOTIFY_H_
|
||||||
|
|
||||||
|
#include <xenia/common.h>
|
||||||
|
#include <xenia/core.h>
|
||||||
|
|
||||||
|
#include <xenia/xbox.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace xe {
|
||||||
|
namespace kernel {
|
||||||
|
namespace xam {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace xam
|
||||||
|
} // namespace kernel
|
||||||
|
} // namespace xe
|
||||||
|
|
||||||
|
|
||||||
|
#endif // XENIA_KERNEL_XAM_NOTIFY_H_
|
|
@ -34,6 +34,7 @@ void RegisterContentExports(ExportResolver* export_resolver, XamState* state);
|
||||||
void RegisterInfoExports(ExportResolver* export_resolver, XamState* state);
|
void RegisterInfoExports(ExportResolver* export_resolver, XamState* state);
|
||||||
void RegisterInputExports(ExportResolver* export_resolver, XamState* state);
|
void RegisterInputExports(ExportResolver* export_resolver, XamState* state);
|
||||||
void RegisterNetExports(ExportResolver* export_resolver, XamState* state);
|
void RegisterNetExports(ExportResolver* export_resolver, XamState* state);
|
||||||
|
void RegisterNotifyExports(ExportResolver* export_resolver, XamState* state);
|
||||||
void RegisterUserExports(ExportResolver* export_resolver, XamState* state);
|
void RegisterUserExports(ExportResolver* export_resolver, XamState* state);
|
||||||
void RegisterVideoExports(ExportResolver* export_resolver, XamState* state);
|
void RegisterVideoExports(ExportResolver* export_resolver, XamState* state);
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
'xfile.h',
|
'xfile.h',
|
||||||
'xmodule.cc',
|
'xmodule.cc',
|
||||||
'xmodule.h',
|
'xmodule.h',
|
||||||
|
'xnotify_listener.cc',
|
||||||
|
'xnotify_listener.h',
|
||||||
'xsemaphore.cc',
|
'xsemaphore.cc',
|
||||||
'xsemaphore.h',
|
'xsemaphore.h',
|
||||||
'xthread.cc',
|
'xthread.cc',
|
||||||
|
|
|
@ -0,0 +1,126 @@
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* Xenia : Xbox 360 Emulator Research Project *
|
||||||
|
******************************************************************************
|
||||||
|
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||||
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <xenia/kernel/xboxkrnl/objects/xnotify_listener.h>
|
||||||
|
|
||||||
|
|
||||||
|
using namespace xe;
|
||||||
|
using namespace xe::kernel;
|
||||||
|
using namespace xe::kernel::xboxkrnl;
|
||||||
|
|
||||||
|
|
||||||
|
XNotifyListener::XNotifyListener(KernelState* kernel_state) :
|
||||||
|
XObject(kernel_state, kTypeNotifyListener),
|
||||||
|
wait_handle_(NULL), lock_(0), mask_(0), notification_count_(0) {
|
||||||
|
}
|
||||||
|
|
||||||
|
XNotifyListener::~XNotifyListener() {
|
||||||
|
xe_mutex_free(lock_);
|
||||||
|
if (wait_handle_) {
|
||||||
|
CloseHandle(wait_handle_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void XNotifyListener::Initialize(uint64_t mask) {
|
||||||
|
XEASSERTNULL(wait_handle_);
|
||||||
|
|
||||||
|
lock_ = xe_mutex_alloc();
|
||||||
|
wait_handle_ = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||||
|
mask_ = mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
void XNotifyListener::EnqueueNotification(XNotificationID id, uint32_t data) {
|
||||||
|
xe_mutex_lock(lock_);
|
||||||
|
auto existing = notifications_.find(id);
|
||||||
|
if (existing != notifications_.end()) {
|
||||||
|
// Already exists. Overwrite.
|
||||||
|
notifications_[id] = data;
|
||||||
|
} else {
|
||||||
|
// New.
|
||||||
|
notification_count_++;
|
||||||
|
}
|
||||||
|
SetEvent(wait_handle_);
|
||||||
|
xe_mutex_unlock(lock_);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool XNotifyListener::DequeueNotification(
|
||||||
|
XNotificationID* out_id, uint32_t* out_data) {
|
||||||
|
bool dequeued = false;
|
||||||
|
xe_mutex_lock(lock_);
|
||||||
|
if (notification_count_) {
|
||||||
|
dequeued = true;
|
||||||
|
auto it = notifications_.begin();
|
||||||
|
*out_id = it->first;
|
||||||
|
*out_data = it->second;
|
||||||
|
notifications_.erase(it);
|
||||||
|
notification_count_--;
|
||||||
|
if (!notification_count_) {
|
||||||
|
ResetEvent(wait_handle_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xe_mutex_unlock(lock_);
|
||||||
|
return dequeued;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool XNotifyListener::DequeueNotification(
|
||||||
|
XNotificationID id, uint32_t* out_data) {
|
||||||
|
bool dequeued = false;
|
||||||
|
xe_mutex_lock(lock_);
|
||||||
|
if (notification_count_) {
|
||||||
|
dequeued = true;
|
||||||
|
auto it = notifications_.find(id);
|
||||||
|
if (it != notifications_.end()) {
|
||||||
|
*out_data = it->second;
|
||||||
|
notifications_.erase(it);
|
||||||
|
notification_count_--;
|
||||||
|
if (!notification_count_) {
|
||||||
|
ResetEvent(wait_handle_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xe_mutex_unlock(lock_);
|
||||||
|
return dequeued;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(benvanik): move this to common class
|
||||||
|
X_STATUS XNotifyListener::Wait(uint32_t wait_reason, uint32_t processor_mode,
|
||||||
|
uint32_t alertable, uint64_t* opt_timeout) {
|
||||||
|
DWORD timeout_ms;
|
||||||
|
if (opt_timeout) {
|
||||||
|
int64_t timeout_ticks = (int64_t)(*opt_timeout);
|
||||||
|
if (timeout_ticks > 0) {
|
||||||
|
// Absolute time, based on January 1, 1601.
|
||||||
|
// TODO(benvanik): convert time to relative time.
|
||||||
|
XEASSERTALWAYS();
|
||||||
|
timeout_ms = 0;
|
||||||
|
} else if (timeout_ticks < 0) {
|
||||||
|
// Relative time.
|
||||||
|
timeout_ms = (DWORD)(-timeout_ticks / 10000); // Ticks -> MS
|
||||||
|
} else {
|
||||||
|
timeout_ms = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
timeout_ms = INFINITE;
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD result = WaitForSingleObjectEx(wait_handle_, timeout_ms, alertable);
|
||||||
|
switch (result) {
|
||||||
|
case WAIT_OBJECT_0:
|
||||||
|
return X_STATUS_SUCCESS;
|
||||||
|
case WAIT_IO_COMPLETION:
|
||||||
|
// Or X_STATUS_ALERTED?
|
||||||
|
return X_STATUS_USER_APC;
|
||||||
|
case WAIT_TIMEOUT:
|
||||||
|
return X_STATUS_TIMEOUT;
|
||||||
|
default:
|
||||||
|
case WAIT_FAILED:
|
||||||
|
case WAIT_ABANDONED:
|
||||||
|
return X_STATUS_ABANDONED_WAIT_0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* Xenia : Xbox 360 Emulator Research Project *
|
||||||
|
******************************************************************************
|
||||||
|
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||||
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This should probably be in XAM, but I don't want to build an extensible
|
||||||
|
// object system. Meh.
|
||||||
|
|
||||||
|
#ifndef XENIA_KERNEL_XBOXKRNL_XNOTIFY_LISTENER_H_
|
||||||
|
#define XENIA_KERNEL_XBOXKRNL_XNOTIFY_LISTENER_H_
|
||||||
|
|
||||||
|
#include <xenia/kernel/xboxkrnl/xobject.h>
|
||||||
|
|
||||||
|
#include <xenia/xbox.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace xe {
|
||||||
|
namespace kernel {
|
||||||
|
namespace xboxkrnl {
|
||||||
|
|
||||||
|
// Values seem to be all over the place - GUIDs?
|
||||||
|
typedef uint32_t XNotificationID;
|
||||||
|
|
||||||
|
|
||||||
|
class XNotifyListener : public XObject {
|
||||||
|
public:
|
||||||
|
XNotifyListener(KernelState* kernel_state);
|
||||||
|
virtual ~XNotifyListener();
|
||||||
|
|
||||||
|
void Initialize(uint64_t mask);
|
||||||
|
|
||||||
|
void EnqueueNotification(XNotificationID id, uint32_t data);
|
||||||
|
bool DequeueNotification(XNotificationID* out_id, uint32_t* out_data);
|
||||||
|
bool DequeueNotification(XNotificationID id, uint32_t* out_data);
|
||||||
|
|
||||||
|
virtual X_STATUS Wait(uint32_t wait_reason, uint32_t processor_mode,
|
||||||
|
uint32_t alertable, uint64_t* opt_timeout);
|
||||||
|
|
||||||
|
private:
|
||||||
|
HANDLE wait_handle_;
|
||||||
|
xe_mutex_t* lock_;
|
||||||
|
std::unordered_map<XNotificationID, uint32_t> notifications_;
|
||||||
|
size_t notification_count_;
|
||||||
|
uint64_t mask_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace xboxkrnl
|
||||||
|
} // namespace kernel
|
||||||
|
} // namespace xe
|
||||||
|
|
||||||
|
|
||||||
|
#endif // XENIA_KERNEL_XBOXKRNL_XNOTIFY_LISTENER_H_
|
|
@ -32,11 +32,12 @@ typedef struct {
|
||||||
class XObject {
|
class XObject {
|
||||||
public:
|
public:
|
||||||
enum Type {
|
enum Type {
|
||||||
kTypeModule = 0x00000001,
|
kTypeModule,
|
||||||
kTypeThread = 0x00000002,
|
kTypeThread,
|
||||||
kTypeEvent = 0x00000003,
|
kTypeEvent,
|
||||||
kTypeFile = 0x00000004,
|
kTypeFile,
|
||||||
kTypeSemaphore = 0x00000005,
|
kTypeSemaphore,
|
||||||
|
kTypeNotifyListener,
|
||||||
};
|
};
|
||||||
|
|
||||||
XObject(KernelState* kernel_state, Type type);
|
XObject(KernelState* kernel_state, Type type);
|
||||||
|
|
Loading…
Reference in New Issue