In-progress work: refactoring PAL not to be instanced.

This removes a lot of useless passing around of the PAL object.
This commit is contained in:
Ben Vanik 2013-03-29 05:07:32 -07:00
parent c46093266e
commit 85bdbd24d1
45 changed files with 444 additions and 189 deletions

View File

@ -23,8 +23,7 @@ typedef struct xe_file {
#endif // WIN32 #endif // WIN32
xe_file_ref xe_file_open(xe_pal_ref pal, const xe_file_mode mode, xe_file_ref xe_file_open(const xe_file_mode mode, const xechar_t *path) {
const xechar_t *path) {
xe_file_ref file = (xe_file_ref)xe_calloc(sizeof(xe_file_t)); xe_file_ref file = (xe_file_ref)xe_calloc(sizeof(xe_file_t));
xe_ref_init((xe_ref)file); xe_ref_init((xe_ref)file);
@ -83,27 +82,3 @@ size_t xe_file_read(xe_file_ref file, const size_t offset,
return fread(buffer, 1, buffer_size, handle); return fread(buffer, 1, buffer_size, handle);
} }
void xe_path_join(const xechar_t* left, const xechar_t* right,
xechar_t* out_path, size_t out_path_size) {
#if XE_WCHAR
xesnprintf(out_path, out_path_size, XT("%ls%c%ls"),
left, XE_PATH_SEPARATOR, right);
#else
xesnprintf(out_path, out_path_size, XT("%s%c%s"),
left, XE_PATH_SEPARATOR, right);
#endif // XE_WCHAR
}
void xe_path_get_absolute(const xechar_t* path, xechar_t* out_abs_path,
size_t abs_path_size) {
#if XE_PLATFORM(WIN32)
#if XE_WCHAR
_wfullpath(out_abs_path, path, abs_path_size);
#else
_fullpath(out_abs_path, path, abs_path_size);
#endif // XE_WCHAR
#else
realpath(path, out_abs_path);
#endif // WIN32
}

View File

@ -11,7 +11,7 @@
#define XENIA_CORE_FILE_H_ #define XENIA_CORE_FILE_H_
#include <xenia/common.h> #include <xenia/common.h>
#include <xenia/core/pal.h> #include <xenia/core/path.h>
#include <xenia/core/ref.h> #include <xenia/core/ref.h>
@ -25,18 +25,12 @@ typedef enum {
} xe_file_mode; } xe_file_mode;
xe_file_ref xe_file_open(xe_pal_ref pal, const xe_file_mode mode, xe_file_ref xe_file_open(const xe_file_mode mode, const xechar_t *path);
const xechar_t *path);
xe_file_ref xe_file_retain(xe_file_ref file); xe_file_ref xe_file_retain(xe_file_ref file);
void xe_file_release(xe_file_ref file); void xe_file_release(xe_file_ref file);
size_t xe_file_get_length(xe_file_ref file); size_t xe_file_get_length(xe_file_ref file);
size_t xe_file_read(xe_file_ref file, const size_t offset, size_t xe_file_read(xe_file_ref file, const size_t offset,
uint8_t *buffer, const size_t buffer_size); uint8_t *buffer, const size_t buffer_size);
void xe_path_join(const xechar_t* left, const xechar_t* right,
xechar_t* out_path, size_t out_path_size);
void xe_path_get_absolute(const xechar_t* path, xechar_t* out_abs_path,
size_t abs_path_size);
#endif // XENIA_CORE_FILE_H_ #endif // XENIA_CORE_FILE_H_

View File

@ -53,7 +53,7 @@ struct xe_memory {
}; };
xe_memory_ref xe_memory_create(xe_pal_ref pal, xe_memory_options_t options) { xe_memory_ref xe_memory_create(xe_memory_options_t options) {
uint32_t offset; uint32_t offset;
uint32_t mspace_size; uint32_t mspace_size;

View File

@ -11,7 +11,6 @@
#define XENIA_CORE_MEMORY_H_ #define XENIA_CORE_MEMORY_H_
#include <xenia/common.h> #include <xenia/common.h>
#include <xenia/core/pal.h>
#include <xenia/core/ref.h> #include <xenia/core/ref.h>
@ -24,7 +23,7 @@ struct xe_memory;
typedef struct xe_memory* xe_memory_ref; typedef struct xe_memory* xe_memory_ref;
xe_memory_ref xe_memory_create(xe_pal_ref pal, xe_memory_options_t options); xe_memory_ref xe_memory_create(xe_memory_options_t options);
xe_memory_ref xe_memory_retain(xe_memory_ref memory); xe_memory_ref xe_memory_retain(xe_memory_ref memory);
void xe_memory_release(xe_memory_ref memory); void xe_memory_release(xe_memory_ref memory);

View File

@ -12,7 +12,6 @@
#include <xenia/common.h> #include <xenia/common.h>
#include <xenia/core/file.h> #include <xenia/core/file.h>
#include <xenia/core/pal.h>
#include <xenia/core/ref.h> #include <xenia/core/ref.h>
@ -20,8 +19,7 @@ struct xe_mmap;
typedef struct xe_mmap* xe_mmap_ref; typedef struct xe_mmap* xe_mmap_ref;
xe_mmap_ref xe_mmap_open(xe_pal_ref pal, const xe_file_mode mode, xe_mmap_ref xe_mmap_open(const xe_file_mode mode, const xechar_t *path,
const xechar_t *path,
const size_t offset, const size_t length); const size_t offset, const size_t length);
xe_mmap_ref xe_mmap_retain(xe_mmap_ref mmap); xe_mmap_ref xe_mmap_retain(xe_mmap_ref mmap);
void xe_mmap_release(xe_mmap_ref mmap); void xe_mmap_release(xe_mmap_ref mmap);

View File

@ -23,8 +23,7 @@ typedef struct xe_mmap {
} xe_mmap_t; } xe_mmap_t;
xe_mmap_ref xe_mmap_open(xe_pal_ref pal, const xe_file_mode mode, xe_mmap_ref xe_mmap_open(const xe_file_mode mode, const xechar_t *path,
const xechar_t *path,
const size_t offset, const size_t length) { const size_t offset, const size_t length) {
xe_mmap_ref mmap = (xe_mmap_ref)xe_calloc(sizeof(xe_mmap_t)); xe_mmap_ref mmap = (xe_mmap_ref)xe_calloc(sizeof(xe_mmap_t));
xe_ref_init((xe_ref)mmap); xe_ref_init((xe_ref)mmap);

View File

@ -21,8 +21,7 @@ typedef struct xe_mmap {
} xe_mmap_t; } xe_mmap_t;
xe_mmap_ref xe_mmap_open(xe_pal_ref pal, const xe_file_mode mode, xe_mmap_ref xe_mmap_open(const xe_file_mode mode, const xechar_t *path,
const xechar_t *path,
const size_t offset, const size_t length) { const size_t offset, const size_t length) {
xe_mmap_ref mmap = (xe_mmap_ref)xe_calloc(sizeof(xe_mmap_t)); xe_mmap_ref mmap = (xe_mmap_ref)xe_calloc(sizeof(xe_mmap_t));
xe_ref_init((xe_ref)mmap); xe_ref_init((xe_ref)mmap);

View File

@ -19,13 +19,19 @@ typedef struct {
} xe_pal_options_t; } xe_pal_options_t;
struct xe_pal; int xe_pal_init(xe_pal_options_t options);
typedef struct xe_pal* xe_pal_ref;
xe_pal_ref xe_pal_create(xe_pal_options_t options); typedef struct {
xe_pal_ref xe_pal_retain(xe_pal_ref pal); struct {
void xe_pal_release(xe_pal_ref pal); uint32_t physical_count;
uint32_t logical_count;
} processors;
} xe_system_info;
int xe_pal_get_system_info(xe_system_info* out_info);
double xe_pal_now();
#endif // XENIA_CORE_PAL_H_ #endif // XENIA_CORE_PAL_H_

84
src/xenia/core/pal_mac.cc Normal file
View File

@ -0,0 +1,84 @@
/**
******************************************************************************
* 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/core/pal.h>
#include <CoreFoundation/CoreFoundation.h>
#include <asl.h>
#include <mach/mach_time.h>
#include <mach/kern_return.h>
#include <sys/types.h>
#include <sys/sysctl.h>
namespace {
typedef struct xe_pal_mac {
double time_to_sec;
} xe_pal_mac_t;
xe_pal_mac_t* pal;
}
void xe_pal_dealloc();
int xe_pal_init(xe_pal_options_t options) {
pal = (xe_pal_mac_t)xe_calloc(sizeof(pal));
mach_timebase_info_data_t info;
mach_timebase_info(&info);
pal->time_to_sec = (double)((info.numer / info.denom) / 1000000000.0);
atexit(xe_pal_dealloc);
return 0;
}
void xe_pal_dealloc() {
//
xe_free(pal);
}
int xe_pal_get_system_info(xe_system_info* out_info) {
xe_zero_struct(out_info, sizeof(xe_system_info));
out_info->processors.physical_count = 1;
out_info->processors.logical_count = 1;
// http://geekinfo.googlecode.com/svn-history/r74/trunk/src/macosxsystem.cpp
int count;
size_t size = sizeof(int);
if (!sysctlbyname("hw.physicalcpu", &count, &size, NULL, 0)) {
out_info->processors.physical_count = count;
} else if (!sysctlbyname("hw.packages", &count, &size, NULL, 0)) {
out_info->processors.physical_count = count;
} else {
out_info->processors.physical_count = 1;
}
if (!sysctlbyname("hw.logicalcpu", &count, &size, NULL, 0)) {
out_info->processors.logical_count = count;
} else if (!sysctlbyname("hw.ncpu", &count, &size, NULL, 0)) {
out_info->processors.logical_count = count;
} else {
out_info->processors.logical_count = 1;
}
return 0;
}
double xe_pal_now() {
// According to a bunch of random posts, CACurrentMediaTime is a better call:
// https://devforums.apple.com/message/118806#118806
// CACurrentMediaTime is based on mach_absolute_time(), which doesn't have a
// dependency on QuartzCore:
// http://developer.apple.com/library/mac/#qa/qa2004/qa1398.html
// return (double)CFAbsoluteTimeGetCurrent();
// return (double)CACurrentMediaTime();
return (double)(mach_absolute_time() * pal->time_to_sec);
}

View File

@ -0,0 +1,62 @@
/**
******************************************************************************
* 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/core/pal.h>
namespace {
typedef struct xe_pal_posix {
} xe_pal_posix_t;
xe_pal_posix_t* pal;
}
void xe_pal_dealloc();
int xe_pal_init(xe_pal_options_t options) {
pal = (xe_pal_posix_t)xe_calloc(sizeof(pal));
//
atexit(xe_pal_dealloc);
return 0;
}
void xe_pal_dealloc() {
//
xe_free(pal);
}
int xe_pal_get_system_info(xe_system_info* out_info) {
xe_zero_struct(out_info, sizeof(xe_system_info));
out_info->processors.physical_count = 1;
out_info->processors.logical_count = 1;
#if defined(_SC_NPROCESSORS_ONLN)
int nproc = sysconf(_SC_NPROCESSORS_ONLN);
if (nproc >= 1) {
// Only able to get logical count.
sysInfo->processors.logicalCount = nproc;
}
#else
#warning no calls to get processor counts
#endif // _SC_NPROCESSORS_ONLN
return 0;
}
double xe_pal_now() {
// http://www.kernel.org/doc/man-pages/online/pages/man2/clock_gettime.2.html
// http://juliusdavies.ca/posix_clocks/clock_realtime_linux_faq.html
struct timespec ts;
CPIGNORE(clock_gettime(CLOCK_MONOTONIC, &ts));
return (double)(ts.tv_sec + (ts.tv_nsec * 1000000000.0));
}

145
src/xenia/core/pal_win.cc Normal file
View File

@ -0,0 +1,145 @@
/**
******************************************************************************
* 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/core/pal.h>
namespace {
typedef struct xe_pal_win {
bool use_high_perf_timer;
double inv_ticks_per_sec;
} xe_pal_win_t;
xe_pal_win_t* pal;
}
void xe_pal_dealloc();
int xe_pal_init(xe_pal_options_t options) {
pal = (xe_pal_win_t)xe_calloc(sizeof(pal));
// Get QPC timing frequency... hopefully stable over the life of the app,
// but likely not.
// TODO(benvanik): requery periodically/etc.
LARGE_INTEGER ticks_per_sec;
if (QueryPerformanceFrequency(&ticks_per_sec)) {
pal->use_high_perf_timer = true;
pal->inv_ticks_per_sec = 1.0 / (double)ticks_per_sec.QuadPart;
} else {
pal->use_high_perf_timer = false;
XELOGW("Falling back from high performance timer");
}
// Setup COM on the main thread.
// NOTE: this may fail if COM has already been initialized - that's OK.
XEIGNORE(CoInitializeEx(NULL, COINIT_MULTITHREADED));
atexit(xe_pal_dealloc);
return 0;
}
void xe_pal_dealloc() {
//
xe_free(pal);
}
// http://msdn.microsoft.com/en-us/library/ms683194.aspx
namespace {
DWORD CountSetBits(ULONG_PTR bitMask) {
DWORD LSHIFT = sizeof(ULONG_PTR)*8 - 1;
DWORD bitSetCount = 0;
ULONG_PTR bitTest = (ULONG_PTR)1 << LSHIFT;
for (DWORD i = 0; i <= LSHIFT; ++i, bitTest /= 2) {
bitSetCount += ((bitMask & bitTest)?1:0);
}
return bitSetCount;
}
}
int xe_pal_get_system_info(xe_system_info* out_info) {
int result_code = 1;
xe_zero_struct(out_info, sizeof(xe_system_info));
out_info->processors.physical_count = 1;
out_info->processors.logical_count = 1;
typedef BOOL (WINAPI *LPFN_GLPI)(
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD);
HMODULE kernel32 = NULL;
LPFN_GLPI glpi = NULL;
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = NULL;
kernel32 = GetModuleHandle(TEXT("kernel32"));
XEEXPECTNOTNULL(kernel32);
glpi = (LPFN_GLPI)GetProcAddress(kernel32, "GetLogicalProcessorInfomration");
XEEXPECTNOTNULL(glpi);
// Call GLPI once to get the buffer size, allocate it, then call again.
DWORD buffer_length = 0;
XEEXPECTFALSE(glpi(NULL, &buffer_length));
XEEXPECT(GetLastError() == ERROR_INSUFFICIENT_BUFFER);
buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)xe_malloc(buffer_length);
XEEXPECTNOTNULL(buffer);
XEEXPECTTRUE(glpi(buffer, &buffer_length));
XEEXPECTNOTZERO(buffer_length);
out_info->processors.physical_count = 0;
out_info->processors.logical_count = 0;
size_t info_count = buffer_length /
sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
for (size_t n = 0; n < info_count; n++) {
switch (buffer[n].Relationship) {
case RelationProcessorPackage:
out_info->processors.physical_count++;
break;
case RelationProcessorCore:
if (buffer[n].ProcessorCore.Flags == 1) {
// Hyper-threaded.
// The number of processors is set as bits in ProcessorMask.
out_info.processors.logical_count +=
CountSetBits(buffer[n].ProcessorMask);
} else {
// A real core - just count as one.
out_info->processors.logical_count++;
}
break;
}
}
out_info->processors.physical_count =
MAX(1, out_info->processors.physical_count);
out_info->processors.logical_count =
MAX(1, out_info->processors.logical_count);
result_code = 0;
XECLEANUP:
xe_free(buffer);
if (kernel32) {
FreeLibrary(kernel32);
}
return result_code;
}
double xe_pal_now() {
if (pal->use_high_perf_timer) {
LARGE_INTEGER counter;
QueryPerformanceCounter(&counter);
return counter.QuadPart * pal->inv_ticks_per_sec;
} else {
// Using GetSystemTimeAsFileTime instead of GetSystemTime() as it has a
// 100ns resolution.
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
ULARGE_INTEGER uli;
uli.LowPart = ft.dwLowDateTime;
uli.HighPart = ft.dwHighDateTime;
return uli.QuadPart / 10000000.0;
}
}

35
src/xenia/core/path.cc Normal file
View File

@ -0,0 +1,35 @@
/**
******************************************************************************
* 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/core/path.h>
void xe_path_join(const xechar_t* left, const xechar_t* right,
xechar_t* out_path, size_t out_path_size) {
#if XE_WCHAR
xesnprintf(out_path, out_path_size, XT("%ls%c%ls"),
left, XE_PATH_SEPARATOR, right);
#else
xesnprintf(out_path, out_path_size, XT("%s%c%s"),
left, XE_PATH_SEPARATOR, right);
#endif // XE_WCHAR
}
void xe_path_get_absolute(const xechar_t* path, xechar_t* out_abs_path,
size_t abs_path_size) {
#if XE_PLATFORM(WIN32)
#if XE_WCHAR
_wfullpath(out_abs_path, path, abs_path_size);
#else
_fullpath(out_abs_path, path, abs_path_size);
#endif // XE_WCHAR
#else
realpath(path, out_abs_path);
#endif // WIN32
}

View File

@ -7,33 +7,19 @@
****************************************************************************** ******************************************************************************
*/ */
#ifndef XENIA_CORE_PATH_H_
#define XENIA_CORE_PATH_H_
#include <xenia/common.h>
#include <xenia/core/pal.h> #include <xenia/core/pal.h>
#include <xenia/core/ref.h>
typedef struct xe_pal { void xe_path_join(const xechar_t* left, const xechar_t* right,
xe_ref_t ref; xechar_t* out_path, size_t out_path_size);
void xe_path_get_absolute(const xechar_t* path, xechar_t* out_abs_path,
size_t abs_path_size);
} xe_pal_t; const xechar_t* xe_path_get_tmp(const xechar_t* prefix);
#endif // XENIA_CORE_PATH_H_
xe_pal_ref xe_pal_create(xe_pal_options_t options) {
xe_pal_ref pal = (xe_pal_ref)xe_calloc(sizeof(xe_pal_t));
xe_ref_init((xe_ref)pal);
//
return pal;
}
void xe_pal_dealloc(xe_pal_ref pal) {
//
}
xe_pal_ref xe_pal_retain(xe_pal_ref pal) {
xe_ref_retain((xe_ref)pal);
return pal;
}
void xe_pal_release(xe_pal_ref pal) {
xe_ref_release((xe_ref)pal, (xe_ref_dealloc_t)xe_pal_dealloc);
}

View File

@ -0,0 +1,15 @@
/**
******************************************************************************
* 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/core/path.h>
const xechar_t* xe_path_get_tmp(const xechar_t* prefix) {
//
}

View File

@ -0,0 +1,15 @@
/**
******************************************************************************
* 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/core/path.h>
const xechar_t* xe_path_get_tmp(const xechar_t* prefix) {
//
}

View File

@ -7,8 +7,9 @@
'memory.h', 'memory.h',
'mmap.h', 'mmap.h',
'mutex.h', 'mutex.h',
'pal.cc',
'pal.h', 'pal.h',
'path.cc',
'path.h',
'ref.cc', 'ref.cc',
'ref.h', 'ref.h',
'socket.h', 'socket.h',
@ -21,13 +22,26 @@
'sources': [ 'sources': [
'mmap_posix.cc', 'mmap_posix.cc',
'mutex_posix.cc', 'mutex_posix.cc',
'path_posix.cc',
'socket_posix.cc', 'socket_posix.cc',
], ],
}], }],
['OS == "linux"', {
'sources': [
'pal_posix.cc',
],
}],
['OS == "mac"', {
'sources': [
'pal_mac.cc',
],
}],
['OS == "win"', { ['OS == "win"', {
'sources': [ 'sources': [
'mmap_win.cc', 'mmap_win.cc',
'mutex_win.cc', 'mutex_win.cc',
'pal_win.cc',
'path_win.cc',
'socket_win.cc', 'socket_win.cc',
], ],
}], }],

View File

@ -24,8 +24,7 @@ typedef struct xe_thread {
xe_thread_ref xe_thread_create( xe_thread_ref xe_thread_create(
xe_pal_ref pal, const char* name, xe_thread_callback callback, const char* name, xe_thread_callback callback, void* param) {
void* param) {
xe_thread_ref thread = (xe_thread_ref)xe_calloc(sizeof(xe_thread_t)); xe_thread_ref thread = (xe_thread_ref)xe_calloc(sizeof(xe_thread_t));
xe_ref_init((xe_ref)thread); xe_ref_init((xe_ref)thread);

View File

@ -23,7 +23,7 @@ typedef void (*xe_thread_callback)(void* param);
xe_thread_ref xe_thread_create( xe_thread_ref xe_thread_create(
xe_pal_ref pal, const char* name, xe_thread_callback callback, void* param); const char* name, xe_thread_callback callback, void* param);
xe_thread_ref xe_thread_retain(xe_thread_ref thread); xe_thread_ref xe_thread_retain(xe_thread_ref thread);
void xe_thread_release(xe_thread_ref thread); void xe_thread_release(xe_thread_ref thread);

View File

@ -32,10 +32,9 @@ namespace cpu {
class Processor { class Processor {
public: public:
Processor(xe_pal_ref pal, xe_memory_ref memory); Processor(xe_memory_ref memory);
~Processor(); ~Processor();
xe_pal_ref pal();
xe_memory_ref memory(); xe_memory_ref memory();
int Setup(); int Setup();
@ -56,7 +55,6 @@ public:
private: private:
llvm::Function* GetFunction(uint32_t address); llvm::Function* GetFunction(uint32_t address);
xe_pal_ref pal_;
xe_memory_ref memory_; xe_memory_ref memory_;
shared_ptr<llvm::ExecutionEngine> engine_; shared_ptr<llvm::ExecutionEngine> engine_;

View File

@ -25,11 +25,8 @@ DEFINE_int32(remote_debug_port, 6200,
"Websocket port to listen for debugger connections on."); "Websocket port to listen for debugger connections on.");
Debugger::Debugger(xe_pal_ref pal) { Debugger::Debugger() {
pal_ = xe_pal_retain(pal); listener_ = auto_ptr<Listener>(new WsListener(this, FLAGS_remote_debug_port));
listener_ = auto_ptr<Listener>(new WsListener(
this, pal_, FLAGS_remote_debug_port));
} }
Debugger::~Debugger() { Debugger::~Debugger() {
@ -45,12 +42,6 @@ Debugger::~Debugger() {
delete it->second; delete it->second;
} }
content_sources_.clear(); content_sources_.clear();
xe_pal_release(pal_);
}
xe_pal_ref Debugger::pal() {
return xe_pal_retain(pal_);
} }
void Debugger::RegisterContentSource(ContentSource* content_source) { void Debugger::RegisterContentSource(ContentSource* content_source) {

View File

@ -28,11 +28,9 @@ class Listener;
class Debugger { class Debugger {
public: public:
Debugger(xe_pal_ref pal); Debugger();
virtual ~Debugger(); virtual ~Debugger();
xe_pal_ref pal();
void RegisterContentSource(ContentSource* content_source); void RegisterContentSource(ContentSource* content_source);
int Startup(); int Startup();
@ -47,7 +45,6 @@ private:
friend class Client; friend class Client;
private: private:
xe_pal_ref pal_;
auto_ptr<Listener> listener_; auto_ptr<Listener> listener_;
std::vector<Client*> clients_; std::vector<Client*> clients_;
std::map<uint32_t, ContentSource*> content_sources_; std::map<uint32_t, ContentSource*> content_sources_;

View File

@ -14,11 +14,9 @@ using namespace xe;
using namespace xe::dbg; using namespace xe::dbg;
Listener::Listener(Debugger* debugger, xe_pal_ref pal) : Listener::Listener(Debugger* debugger) :
debugger_(debugger) { debugger_(debugger) {
pal_ = xe_pal_retain(pal);
} }
Listener::~Listener() { Listener::~Listener() {
xe_pal_release(pal_);
} }

View File

@ -23,7 +23,7 @@ class Debugger;
class Listener { class Listener {
public: public:
Listener(Debugger* debugger, xe_pal_ref pal); Listener(Debugger* debugger);
virtual ~Listener(); virtual ~Listener();
virtual int Setup() = 0; virtual int Setup() = 0;
@ -31,7 +31,6 @@ public:
protected: protected:
Debugger* debugger_; Debugger* debugger_;
xe_pal_ref pal_;
}; };

View File

@ -60,10 +60,7 @@ int WsClient::Setup() {
xe_socket_set_keepalive(socket_id_, true); xe_socket_set_keepalive(socket_id_, true);
xe_socket_set_nodelay(socket_id_, true); xe_socket_set_nodelay(socket_id_, true);
xe_pal_ref pal = debugger_->pal(); thread_ = xe_thread_create("Debugger Client", StartCallback, this);
thread_ = xe_thread_create(pal, "Debugger Client",
StartCallback, this);
xe_pal_release(pal);
return xe_thread_start(thread_); return xe_thread_start(thread_);
} }

View File

@ -16,8 +16,8 @@ using namespace xe;
using namespace xe::dbg; using namespace xe::dbg;
WsListener::WsListener(Debugger* debugger, xe_pal_ref pal, uint32_t port) : WsListener::WsListener(Debugger* debugger, uint32_t port) :
Listener(debugger, pal), Listener(debugger),
port_(port) { port_(port) {
} }

View File

@ -25,7 +25,7 @@ class Debugger;
class WsListener : public Listener { class WsListener : public Listener {
public: public:
WsListener(Debugger* debugger, xe_pal_ref pal, uint32_t port); WsListener(Debugger* debugger, uint32_t port);
virtual ~WsListener(); virtual ~WsListener();
virtual int Setup(); virtual int Setup();

View File

@ -15,18 +15,12 @@ using namespace xe::kernel;
using namespace xe::kernel::fs; using namespace xe::kernel::fs;
Device::Device(xe_pal_ref pal, const char* path) { Device::Device(const char* path) {
pal_ = xe_pal_retain(pal);
path_ = xestrdupa(path); path_ = xestrdupa(path);
} }
Device::~Device() { Device::~Device() {
xe_free(path_); xe_free(path_);
xe_pal_release(pal_);
}
xe_pal_ref Device::pal() {
return xe_pal_retain(pal_);
} }
const char* Device::path() { const char* Device::path() {

View File

@ -23,16 +23,14 @@ namespace fs {
class Device { class Device {
public: public:
Device(xe_pal_ref pal, const char* path); Device(const char* path);
virtual ~Device(); virtual ~Device();
xe_pal_ref pal();
const char* path(); const char* path();
virtual Entry* ResolvePath(const char* path) = 0; virtual Entry* ResolvePath(const char* path) = 0;
protected: protected:
xe_pal_ref pal_;
char* path_; char* path_;
}; };

View File

@ -74,9 +74,8 @@ private:
} }
DiscImageDevice::DiscImageDevice(xe_pal_ref pal, const char* path, DiscImageDevice::DiscImageDevice(const char* path, const xechar_t* local_path) :
const xechar_t* local_path) : Device(path) {
Device(pal, path) {
local_path_ = xestrdup(local_path); local_path_ = xestrdup(local_path);
mmap_ = NULL; mmap_ = NULL;
gdfx_ = NULL; gdfx_ = NULL;
@ -89,7 +88,7 @@ DiscImageDevice::~DiscImageDevice() {
} }
int DiscImageDevice::Init() { int DiscImageDevice::Init() {
mmap_ = xe_mmap_open(pal_, kXEFileModeRead, local_path_, 0, 0); mmap_ = xe_mmap_open(kXEFileModeRead, local_path_, 0, 0);
if (!mmap_) { if (!mmap_) {
XELOGE("Disc image could not be mapped"); XELOGE("Disc image could not be mapped");
return 1; return 1;

View File

@ -26,7 +26,7 @@ class GDFX;
class DiscImageDevice : public Device { class DiscImageDevice : public Device {
public: public:
DiscImageDevice(xe_pal_ref pal, const char* path, const xechar_t* local_path); DiscImageDevice(const char* path, const xechar_t* local_path);
virtual ~DiscImageDevice(); virtual ~DiscImageDevice();
int Init(); int Init();

View File

@ -46,10 +46,7 @@ public:
virtual MemoryMapping* CreateMemoryMapping( virtual MemoryMapping* CreateMemoryMapping(
xe_file_mode file_mode, const size_t offset, const size_t length) { xe_file_mode file_mode, const size_t offset, const size_t length) {
xe_pal_ref pal = device()->pal(); xe_mmap_ref mmap = xe_mmap_open(file_mode, local_path_, offset, length);
xe_mmap_ref mmap = xe_mmap_open(pal, file_mode, local_path_,
offset, length);
xe_pal_release(pal);
if (!mmap) { if (!mmap) {
return NULL; return NULL;
} }
@ -70,9 +67,9 @@ private:
} }
LocalDirectoryDevice::LocalDirectoryDevice(xe_pal_ref pal, const char* path, LocalDirectoryDevice::LocalDirectoryDevice(const char* path,
const xechar_t* local_path) : const xechar_t* local_path) :
Device(pal, path) { Device(path) {
local_path_ = xestrdup(local_path); local_path_ = xestrdup(local_path);
} }

View File

@ -23,8 +23,7 @@ namespace fs {
class LocalDirectoryDevice : public Device { class LocalDirectoryDevice : public Device {
public: public:
LocalDirectoryDevice(xe_pal_ref pal, const char* path, LocalDirectoryDevice(const char* path, const xechar_t* local_path);
const xechar_t* local_path);
virtual ~LocalDirectoryDevice(); virtual ~LocalDirectoryDevice();
virtual Entry* ResolvePath(const char* path); virtual Entry* ResolvePath(const char* path);

View File

@ -18,8 +18,7 @@ using namespace xe::kernel;
using namespace xe::kernel::fs; using namespace xe::kernel::fs;
FileSystem::FileSystem(xe_pal_ref pal) { FileSystem::FileSystem() {
pal_ = xe_pal_retain(pal);
} }
FileSystem::~FileSystem() { FileSystem::~FileSystem() {
@ -31,8 +30,6 @@ FileSystem::~FileSystem() {
} }
devices_.clear(); devices_.clear();
symlinks_.clear(); symlinks_.clear();
xe_pal_release(pal_);
} }
int FileSystem::RegisterDevice(const char* path, Device* device) { int FileSystem::RegisterDevice(const char* path, Device* device) {
@ -42,13 +39,13 @@ int FileSystem::RegisterDevice(const char* path, Device* device) {
int FileSystem::RegisterLocalDirectoryDevice( int FileSystem::RegisterLocalDirectoryDevice(
const char* path, const xechar_t* local_path) { const char* path, const xechar_t* local_path) {
Device* device = new LocalDirectoryDevice(pal_, path, local_path); Device* device = new LocalDirectoryDevice(path, local_path);
return RegisterDevice(path, device); return RegisterDevice(path, device);
} }
int FileSystem::RegisterDiscImageDevice( int FileSystem::RegisterDiscImageDevice(
const char* path, const xechar_t* local_path) { const char* path, const xechar_t* local_path) {
DiscImageDevice* device = new DiscImageDevice(pal_, path, local_path); DiscImageDevice* device = new DiscImageDevice(path, local_path);
if (device->Init()) { if (device->Init()) {
return 1; return 1;
} }

View File

@ -28,7 +28,7 @@ class Device;
class FileSystem { class FileSystem {
public: public:
FileSystem(xe_pal_ref pal); FileSystem();
~FileSystem(); ~FileSystem();
int RegisterDevice(const char* path, Device* device); int RegisterDevice(const char* path, Device* device);
@ -42,7 +42,6 @@ public:
Entry* ResolvePath(const char* path); Entry* ResolvePath(const char* path);
private: private:
xe_pal_ref pal_;
std::vector<Device*> devices_; std::vector<Device*> devices_;
std::tr1::unordered_map<std::string, std::string> symlinks_; std::tr1::unordered_map<std::string, std::string> symlinks_;
}; };

View File

@ -28,7 +28,6 @@ class KernelModule {
public: public:
KernelModule(Runtime* runtime) { KernelModule(Runtime* runtime) {
runtime_ = runtime; runtime_ = runtime;
pal_ = runtime->pal();
memory_ = runtime->memory(); memory_ = runtime->memory();
export_resolver_ = runtime->export_resolver(); export_resolver_ = runtime->export_resolver();
} }
@ -36,12 +35,10 @@ public:
virtual ~KernelModule() { virtual ~KernelModule() {
export_resolver_.reset(); export_resolver_.reset();
xe_memory_release(memory_); xe_memory_release(memory_);
xe_pal_release(pal_);
} }
protected: protected:
Runtime* runtime_; Runtime* runtime_;
xe_pal_ref pal_;
xe_memory_ref memory_; xe_memory_ref memory_;
shared_ptr<ExportResolver> export_resolver_; shared_ptr<ExportResolver> export_resolver_;
}; };

View File

@ -24,7 +24,7 @@ XamModule::XamModule(Runtime* runtime) :
"xam.xex", xam_export_table, XECOUNT(xam_export_table)); "xam.xex", xam_export_table, XECOUNT(xam_export_table));
// Setup the xam state instance. // Setup the xam state instance.
xam_state = auto_ptr<XamState>(new XamState(pal_, memory_, export_resolver_)); xam_state = auto_ptr<XamState>(new XamState(memory_, export_resolver_));
// Register all exported functions. // Register all exported functions.
RegisterInfoExports(export_resolver_.get(), xam_state.get()); RegisterInfoExports(export_resolver_.get(), xam_state.get());

View File

@ -20,14 +20,12 @@ namespace {
} }
XamState::XamState(xe_pal_ref pal, xe_memory_ref memory, XamState::XamState(xe_memory_ref memory,
shared_ptr<ExportResolver> export_resolver) { shared_ptr<ExportResolver> export_resolver) {
this->pal = xe_pal_retain(pal);
this->memory = xe_memory_retain(memory); this->memory = xe_memory_retain(memory);
export_resolver_ = export_resolver; export_resolver_ = export_resolver;
} }
XamState::~XamState() { XamState::~XamState() {
xe_memory_release(memory); xe_memory_release(memory);
xe_pal_release(pal);
} }

View File

@ -24,11 +24,9 @@ namespace xam {
class XamState { class XamState {
public: public:
XamState(xe_pal_ref pal, xe_memory_ref memory, XamState(xe_memory_ref memory, shared_ptr<ExportResolver> export_resolver);
shared_ptr<ExportResolver> export_resolver);
~XamState(); ~XamState();
xe_pal_ref pal;
xe_memory_ref memory; xe_memory_ref memory;
private: private:

View File

@ -28,7 +28,6 @@ KernelState::KernelState(Runtime* runtime) :
runtime_(runtime), runtime_(runtime),
executable_module_(NULL), executable_module_(NULL),
next_handle_(0) { next_handle_(0) {
pal_ = runtime->pal();
memory_ = runtime->memory(); memory_ = runtime->memory();
processor_ = runtime->processor(); processor_ = runtime->processor();
filesystem_ = runtime->filesystem(); filesystem_ = runtime->filesystem();
@ -69,17 +68,12 @@ KernelState::~KernelState() {
filesystem_.reset(); filesystem_.reset();
processor_.reset(); processor_.reset();
xe_memory_release(memory_); xe_memory_release(memory_);
xe_pal_release(pal_);
} }
Runtime* KernelState::runtime() { Runtime* KernelState::runtime() {
return runtime_; return runtime_;
} }
xe_pal_ref KernelState::pal() {
return pal_;
}
xe_memory_ref KernelState::memory() { xe_memory_ref KernelState::memory() {
return memory_; return memory_;
} }

View File

@ -35,7 +35,6 @@ public:
~KernelState(); ~KernelState();
Runtime* runtime(); Runtime* runtime();
xe_pal_ref pal();
xe_memory_ref memory(); xe_memory_ref memory();
cpu::Processor* processor(); cpu::Processor* processor();
fs::FileSystem* filesystem(); fs::FileSystem* filesystem();
@ -51,7 +50,6 @@ private:
void RemoveObject(XObject* obj); void RemoveObject(XObject* obj);
Runtime* runtime_; Runtime* runtime_;
xe_pal_ref pal_;
xe_memory_ref memory_; xe_memory_ref memory_;
shared_ptr<cpu::Processor> processor_; shared_ptr<cpu::Processor> processor_;
shared_ptr<fs::FileSystem> filesystem_; shared_ptr<fs::FileSystem> filesystem_;

View File

@ -92,8 +92,7 @@ X_STATUS XModule::LoadFromMemory(const void* addr, const size_t length) {
XEEXPECTNOTNULL(xex_); XEEXPECTNOTNULL(xex_);
// Prepare the module for execution. // Prepare the module for execution.
XEEXPECTZERO(kernel_state()->processor()->PrepareModule( XEEXPECTZERO(kernel_state()->processor()->LoadXexModule(name_, path_, xex_));
name_, path_, xex_, runtime()->export_resolver()));
return X_STATUS_SUCCESS; return X_STATUS_SUCCESS;

View File

@ -18,15 +18,14 @@ using namespace xe::kernel;
using namespace xe::kernel::fs; using namespace xe::kernel::fs;
Runtime::Runtime(xe_pal_ref pal, shared_ptr<cpu::Processor> processor, Runtime::Runtime(shared_ptr<cpu::Processor> processor,
const xechar_t* command_line) { const xechar_t* command_line) {
pal_ = xe_pal_retain(pal);
memory_ = processor->memory(); memory_ = processor->memory();
processor_ = processor; processor_ = processor;
XEIGNORE(xestrcpy(command_line_, XECOUNT(command_line_), command_line)); XEIGNORE(xestrcpy(command_line_, XECOUNT(command_line_), command_line));
export_resolver_ = shared_ptr<ExportResolver>(new ExportResolver()); export_resolver_ = shared_ptr<ExportResolver>(new ExportResolver());
filesystem_ = shared_ptr<FileSystem>(new FileSystem(pal_)); filesystem_ = shared_ptr<FileSystem>(new FileSystem());
xboxkrnl_ = auto_ptr<xboxkrnl::XboxkrnlModule>( xboxkrnl_ = auto_ptr<xboxkrnl::XboxkrnlModule>(
new xboxkrnl::XboxkrnlModule(this)); new xboxkrnl::XboxkrnlModule(this));
@ -36,17 +35,12 @@ Runtime::Runtime(xe_pal_ref pal, shared_ptr<cpu::Processor> processor,
Runtime::~Runtime() { Runtime::~Runtime() {
xe_memory_release(memory_); xe_memory_release(memory_);
xe_pal_release(pal_);
} }
const xechar_t* Runtime::command_line() { const xechar_t* Runtime::command_line() {
return command_line_; return command_line_;
} }
xe_pal_ref Runtime::pal() {
return xe_pal_retain(pal_);
}
xe_memory_ref Runtime::memory() { xe_memory_ref Runtime::memory() {
return xe_memory_retain(memory_); return xe_memory_retain(memory_);
} }

View File

@ -42,13 +42,11 @@ class KernelModule;
class Runtime { class Runtime {
public: public:
Runtime(xe_pal_ref pal, shared_ptr<cpu::Processor> processor, Runtime(shared_ptr<cpu::Processor> processor, const xechar_t* command_line);
const xechar_t* command_line);
~Runtime(); ~Runtime();
const xechar_t* command_line(); const xechar_t* command_line();
xe_pal_ref pal();
xe_memory_ref memory(); xe_memory_ref memory();
shared_ptr<cpu::Processor> processor(); shared_ptr<cpu::Processor> processor();
shared_ptr<ExportResolver> export_resolver(); shared_ptr<ExportResolver> export_resolver();
@ -60,7 +58,6 @@ public:
private: private:
xechar_t command_line_[XE_MAX_PATH]; xechar_t command_line_[XE_MAX_PATH];
xe_pal_ref pal_;
xe_memory_ref memory_; xe_memory_ref memory_;
shared_ptr<cpu::Processor> processor_; shared_ptr<cpu::Processor> processor_;
shared_ptr<ExportResolver> export_resolver_; shared_ptr<ExportResolver> export_resolver_;

View File

@ -27,7 +27,6 @@ public:
int Launch(const xechar_t* path); int Launch(const xechar_t* path);
private: private:
xe_pal_ref pal_;
xe_memory_ref memory_; xe_memory_ref memory_;
shared_ptr<Processor> processor_; shared_ptr<Processor> processor_;
shared_ptr<Runtime> runtime_; shared_ptr<Runtime> runtime_;
@ -39,26 +38,24 @@ Run::Run() {
Run::~Run() { Run::~Run() {
xe_memory_release(memory_); xe_memory_release(memory_);
xe_pal_release(pal_);
} }
int Run::Setup() { int Run::Setup() {
xe_pal_options_t pal_options; xe_pal_options_t pal_options;
xe_zero_struct(&pal_options, sizeof(pal_options)); xe_zero_struct(&pal_options, sizeof(pal_options));
pal_ = xe_pal_create(pal_options); XEEXPECTZERO(xe_pal_init(pal_options));
XEEXPECTNOTNULL(pal_);
debugger_ = shared_ptr<Debugger>(new Debugger(pal_)); debugger_ = shared_ptr<Debugger>(new Debugger());
xe_memory_options_t memory_options; xe_memory_options_t memory_options;
xe_zero_struct(&memory_options, sizeof(memory_options)); xe_zero_struct(&memory_options, sizeof(memory_options));
memory_ = xe_memory_create(pal_, memory_options); memory_ = xe_memory_create(memory_options);
XEEXPECTNOTNULL(memory_); XEEXPECTNOTNULL(memory_);
processor_ = shared_ptr<Processor>(new Processor(pal_, memory_)); processor_ = shared_ptr<Processor>(new Processor(memory_));
XEEXPECTZERO(processor_->Setup()); XEEXPECTZERO(processor_->Setup());
runtime_ = shared_ptr<Runtime>(new Runtime(pal_, processor_, XT(""))); runtime_ = shared_ptr<Runtime>(new Runtime(processor_, XT("")));
return 0; return 0;
XECLEANUP: XECLEANUP:

View File

@ -26,8 +26,7 @@ DEFINE_string(test_path, "test/codegen/",
typedef vector<pair<string, string> > annotations_list_t; typedef vector<pair<string, string> > annotations_list_t;
int read_annotations(xe_pal_ref pal, string& src_file_path, int read_annotations(string& src_file_path, annotations_list_t& annotations) {
annotations_list_t& annotations) {
// TODO(benvanik): use PAL instead of this // TODO(benvanik): use PAL instead of this
FILE* f = fopen(src_file_path.c_str(), "r"); FILE* f = fopen(src_file_path.c_str(), "r");
char line_buffer[BUFSIZ]; char line_buffer[BUFSIZ];
@ -98,7 +97,7 @@ int check_test_results(xe_memory_ref memory, Processor* processor,
return any_failed; return any_failed;
} }
int run_test(xe_pal_ref pal, string& src_file_path) { int run_test(string& src_file_path) {
int result_code = 1; int result_code = 1;
// test.s -> test.bin // test.s -> test.bin
@ -126,11 +125,10 @@ int run_test(xe_pal_ref pal, string& src_file_path) {
runtime = shared_ptr<Runtime>(new Runtime(pal, processor, XT(""))); runtime = shared_ptr<Runtime>(new Runtime(pal, processor, XT("")));
// Load the binary module. // Load the binary module.
XEEXPECTZERO(processor->LoadBinary(bin_file_path.c_str(), 0x82010000, XEEXPECTZERO(processor->LoadRawBinary(bin_file_path.c_str(), 0x82010000));
runtime->export_resolver()));
// Simulate a thread. // Simulate a thread.
thread_state = processor->AllocThread(256 * 1024 * 1024, 0); thread_state = processor->AllocThread(256 * 1024, 0);
// Setup test state from annotations. // Setup test state from annotations.
XEEXPECTZERO(setup_test_state(memory, processor.get(), thread_state, XEEXPECTZERO(setup_test_state(memory, processor.get(), thread_state,
@ -186,13 +184,11 @@ int run_tests(const xechar_t* test_name) {
int failed_count = 0; int failed_count = 0;
int passed_count = 0; int passed_count = 0;
xe_pal_ref pal = NULL;
vector<string> test_files; vector<string> test_files;
xe_pal_options_t pal_options; xe_pal_options_t pal_options;
xe_zero_struct(&pal_options, sizeof(pal_options)); xe_zero_struct(&pal_options, sizeof(pal_options));
pal = xe_pal_create(pal_options); XEEXPECTZERO(xe_pal_init(pal_options));
XEEXPECTNOTNULL(pal);
XEEXPECTZERO(discover_tests(FLAGS_test_path, test_files)); XEEXPECTZERO(discover_tests(FLAGS_test_path, test_files));
if (!test_files.size()) { if (!test_files.size()) {
@ -225,7 +221,6 @@ int run_tests(const xechar_t* test_name) {
result_code = failed_count ? 1 : 0; result_code = failed_count ? 1 : 0;
XECLEANUP: XECLEANUP:
xe_pal_release(pal);
return result_code; return result_code;
} }