diff --git a/common.gypi b/common.gypi index d07332760..3454d7b27 100644 --- a/common.gypi +++ b/common.gypi @@ -85,8 +85,9 @@ '__STDC_CONSTANT_MACROS=1', '_ISOC99_SOURCE=1', - 'OPENSSL_NO_INLINE_ASM', - 'OPENSSL_NO_NEXTPROTONEG', + # Force xechar_t to char on Win32 (and use all the A functions). + # This makes life easier when string formatting/etc. + 'XE_CHAR=1', ], 'conditions': [ diff --git a/src/xenia/assert.h b/src/xenia/assert.h index 824fba073..d1ea701b4 100644 --- a/src/xenia/assert.h +++ b/src/xenia/assert.h @@ -16,10 +16,11 @@ #include #include #include +#include #include -#if XE_COMPILER(MSVC) +#if XE_COMPILER(MSVC) && XE_WCHAR // http://msdn.microsoft.com/en-us/library/b0084kay.aspx #if !defined(__WFILE__) #define WIDEN2(x) L##x diff --git a/src/xenia/core/file.cc b/src/xenia/core/file.cc index 429b01899..ba188a3ca 100644 --- a/src/xenia/core/file.cc +++ b/src/xenia/core/file.cc @@ -38,7 +38,7 @@ xe_file_ref xe_file_open(xe_pal_ref pal, const xe_file_mode mode, } XEIGNORE(xestrcat(mode_string, XECOUNT(mode_string), XT("b"))); -#if XE_LIKE(WIN32) +#if XE_LIKE(WIN32) && XE_WCHAR XEEXPECTZERO(_wfopen_s((FILE**)&file->handle, path, mode_string)); #else file->handle = fopen(path, mode_string); diff --git a/src/xenia/core/memory.cc b/src/xenia/core/memory.cc index c57aa041d..dc9e871f4 100644 --- a/src/xenia/core/memory.cc +++ b/src/xenia/core/memory.cc @@ -122,12 +122,12 @@ size_t xe_memory_get_length(xe_memory_ref memory) { return memory->length; } -uint8_t *xe_memory_addr(xe_memory_ref memory, uint32_t guest_addr) { +uint8_t *xe_memory_addr(xe_memory_ref memory, size_t guest_addr) { return (uint8_t*)memory->ptr + guest_addr; } -uint32_t xe_memory_search_aligned(xe_memory_ref memory, uint32_t start, - uint32_t end, const uint32_t *values, +uint32_t xe_memory_search_aligned(xe_memory_ref memory, size_t start, + size_t end, const uint32_t *values, const size_t value_count) { XEASSERT(start <= end); const uint32_t *p = (const uint32_t*)xe_memory_addr(memory, start); diff --git a/src/xenia/core/memory.h b/src/xenia/core/memory.h index beb2640ba..4e319e5f2 100644 --- a/src/xenia/core/memory.h +++ b/src/xenia/core/memory.h @@ -29,10 +29,10 @@ xe_memory_ref xe_memory_retain(xe_memory_ref memory); void xe_memory_release(xe_memory_ref memory); size_t xe_memory_get_length(xe_memory_ref memory); -uint8_t *xe_memory_addr(xe_memory_ref memory, uint32_t guest_addr); +uint8_t *xe_memory_addr(xe_memory_ref memory, size_t guest_addr); -uint32_t xe_memory_search_aligned(xe_memory_ref memory, uint32_t start, - uint32_t end, const uint32_t *values, +uint32_t xe_memory_search_aligned(xe_memory_ref memory, size_t start, + size_t end, const uint32_t *values, const size_t value_count); // These methods slice off memory from the virtual address space. diff --git a/src/xenia/core/socket.h b/src/xenia/core/socket.h index 930ed0028..c19b82308 100644 --- a/src/xenia/core/socket.h +++ b/src/xenia/core/socket.h @@ -37,9 +37,9 @@ typedef struct { } xe_socket_connection_t; int xe_socket_accept(socket_t socket, xe_socket_connection_t* out_client_info); -ssize_t xe_socket_send(socket_t socket, const uint8_t* data, size_t length, +int64_t xe_socket_send(socket_t socket, const uint8_t* data, size_t length, int flags, int* out_error_code); -ssize_t xe_socket_recv(socket_t socket, uint8_t* data, size_t length, int flags, +int64_t xe_socket_recv(socket_t socket, uint8_t* data, size_t length, int flags, int* out_error_code); typedef struct xe_socket_loop xe_socket_loop_t; diff --git a/src/xenia/core/socket_posix.cc b/src/xenia/core/socket_posix.cc index ebbbad9db..7ffb7508f 100644 --- a/src/xenia/core/socket_posix.cc +++ b/src/xenia/core/socket_posix.cc @@ -103,14 +103,14 @@ int xe_socket_accept(socket_t socket, xe_socket_connection_t* out_client_info) { return 0; } -ssize_t xe_socket_send(socket_t socket, const uint8_t* data, size_t length, +int64_t xe_socket_send(socket_t socket, const uint8_t* data, size_t length, int flags, int* out_error_code) { ssize_t result = send(socket, data, length, flags); *out_error_code = errno; return result; } -ssize_t xe_socket_recv(socket_t socket, uint8_t* data, size_t length, int flags, +int64_t xe_socket_recv(socket_t socket, uint8_t* data, size_t length, int flags, int* out_error_code) { ssize_t result = recv(socket, data, length, flags); *out_error_code = errno; diff --git a/src/xenia/core/socket_win.cc b/src/xenia/core/socket_win.cc index 988e10b80..dec54c8e3 100644 --- a/src/xenia/core/socket_win.cc +++ b/src/xenia/core/socket_win.cc @@ -20,6 +20,7 @@ void xe_socket_init() { } socket_t xe_socket_create_tcp() { + return 0; } void xe_socket_close(socket_t socket) { @@ -38,21 +39,25 @@ void xe_socket_set_nonblock(socket_t socket, bool value) { } int xe_socket_bind(socket_t socket, uint32_t port) { + return 0; } int xe_socket_listen(socket_t socket) { + return 0; } int xe_socket_accept(socket_t socket, xe_socket_connection_t* out_client_info) { return 0; } -ssize_t xe_socket_send(socket_t socket, const uint8_t* data, size_t length, +int64_t xe_socket_send(socket_t socket, const uint8_t* data, size_t length, int flags, int* out_error_code) { + return 0; } -ssize_t xe_socket_recv(socket_t socket, uint8_t* data, size_t length, int flags, +int64_t xe_socket_recv(socket_t socket, uint8_t* data, size_t length, int flags, int* out_error_code) { + return 0; } struct xe_socket_loop { @@ -81,10 +86,13 @@ void xe_socket_loop_set_queued_write(xe_socket_loop_t* loop) { } bool xe_socket_loop_check_queued_write(xe_socket_loop_t* loop) { + return false; } bool xe_socket_loop_check_socket_recv(xe_socket_loop_t* loop) { + return false; } bool xe_socket_loop_check_socket_send(xe_socket_loop_t* loop) { + return false; } diff --git a/src/xenia/cpu/codegen/function_generator.cc b/src/xenia/cpu/codegen/function_generator.cc index 020bad57b..3e575443e 100644 --- a/src/xenia/cpu/codegen/function_generator.cc +++ b/src/xenia/cpu/codegen/function_generator.cc @@ -623,7 +623,7 @@ void FunctionGenerator::FillRegisters() { for (size_t n = 0; n < XECOUNT(locals_.gpr); n++) { if (locals_.gpr[n]) { b.CreateStore(LoadStateValue( - offsetof(xe_ppc_state_t, r) + 8 * n, + (uint32_t)offsetof(xe_ppc_state_t, r) + 8 * n, b.getInt64Ty()), locals_.gpr[n]); } } @@ -631,7 +631,7 @@ void FunctionGenerator::FillRegisters() { for (size_t n = 0; n < XECOUNT(locals_.fpr); n++) { if (locals_.fpr[n]) { b.CreateStore(LoadStateValue( - offsetof(xe_ppc_state_t, f) + 8 * n, + (uint32_t)offsetof(xe_ppc_state_t, f) + 8 * n, b.getDoubleTy()), locals_.fpr[n]); } } diff --git a/src/xenia/cpu/processor.cc b/src/xenia/cpu/processor.cc index f0d0f36a7..06062e6fe 100644 --- a/src/xenia/cpu/processor.cc +++ b/src/xenia/cpu/processor.cc @@ -141,7 +141,8 @@ int Processor::LoadBinary(const xechar_t* path, uint32_t start_address, exec_module = new ExecModule( memory_, export_resolver, name_a, path_a, engine_); - if (exec_module->PrepareRawBinary(start_address, start_address + length)) { + if (exec_module->PrepareRawBinary(start_address, + start_address + (uint32_t)length)) { delete exec_module; return 1; } diff --git a/src/xenia/cpu/sdb/symbol_database.cc b/src/xenia/cpu/sdb/symbol_database.cc index 976926a1c..90604874d 100644 --- a/src/xenia/cpu/sdb/symbol_database.cc +++ b/src/xenia/cpu/sdb/symbol_database.cc @@ -209,7 +209,7 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) { // Function starts with 0x00000000 - we want to skip this and split. symbols_.erase(fn->start_address); // Scan ahead until the first non-zero or the end of the valid range. - size_t next_addr = fn->start_address + 4; + uint32_t next_addr = fn->start_address + 4; while (true) { if (!IsValueInTextRange(next_addr)) { // Ran out of the range. Abort. diff --git a/src/xenia/cpu/sdb/xex_symbol_database.cc b/src/xenia/cpu/sdb/xex_symbol_database.cc index daea7b0b1..8ca26f8fa 100644 --- a/src/xenia/cpu/sdb/xex_symbol_database.cc +++ b/src/xenia/cpu/sdb/xex_symbol_database.cc @@ -42,8 +42,8 @@ typedef struct IMAGE_XBOX_RUNTIME_FUNCTION_ENTRY_t { class PEMethodInfo { public: uint32_t address; - size_t total_length; // in bytes - size_t prolog_length; // in bytes + uint32_t total_length; // in bytes + uint32_t prolog_length; // in bytes }; diff --git a/src/xenia/dbg/debugger.cc b/src/xenia/dbg/debugger.cc index 2e41b8336..9f4b54d63 100644 --- a/src/xenia/dbg/debugger.cc +++ b/src/xenia/dbg/debugger.cc @@ -83,7 +83,7 @@ void Debugger::Broadcast(uint32_t source_id, 0x00000001, source_id, 0, - length, + (uint32_t)length, }; uint8_t* buffers[] = { (uint8_t*)header, diff --git a/src/xenia/dbg/simple_sha1.cc b/src/xenia/dbg/simple_sha1.cc index f331b9b97..daa112470 100644 --- a/src/xenia/dbg/simple_sha1.cc +++ b/src/xenia/dbg/simple_sha1.cc @@ -9,6 +9,11 @@ #include +#if XE_PLATFORM(WIN32) +#include +#else +#endif // WIN32 + using namespace xe; using namespace xe::dbg; @@ -211,7 +216,7 @@ void xe::dbg::SHA1(const uint8_t* data, size_t length, uint8_t out_hash[20]) { { 0 } }; - SHA1_Update(&ctx, data, length); + SHA1_Update(&ctx, data, (unsigned long)length); uint32_t padlen[2] = { htonl((uint32_t)(ctx.size >> 29)), diff --git a/src/xenia/dbg/ws_client.cc b/src/xenia/dbg/ws_client.cc index c170b5aaa..39380c280 100644 --- a/src/xenia/dbg/ws_client.cc +++ b/src/xenia/dbg/ws_client.cc @@ -12,6 +12,11 @@ #include #include +#if XE_PLATFORM(WIN32) +// Required for wslay. +typedef SSIZE_T ssize_t; +#endif // WIN32 + #include @@ -69,13 +74,13 @@ void WsClient::StartCallback(void* param) { namespace { -ssize_t WsClientSendCallback(wslay_event_context_ptr ctx, +int64_t WsClientSendCallback(wslay_event_context_ptr ctx, const uint8_t* data, size_t len, int flags, void* user_data) { WsClient* client = reinterpret_cast(user_data); int error_code = 0; - ssize_t r; + int64_t r; while ((r = xe_socket_send(client->socket_id(), data, len, 0, &error_code)) == -1 && error_code == EINTR); if (r == -1) { @@ -88,13 +93,13 @@ ssize_t WsClientSendCallback(wslay_event_context_ptr ctx, return r; } -ssize_t WsClientRecvCallback(wslay_event_context_ptr ctx, +int64_t WsClientRecvCallback(wslay_event_context_ptr ctx, uint8_t* data, size_t len, int flags, void* user_data) { WsClient* client = reinterpret_cast(user_data); int error_code = 0; - ssize_t r; + int64_t r; while ((r = xe_socket_recv(client->socket_id(), data, len, 0, &error_code)) == -1 && error_code == EINTR); if (r == -1) { @@ -167,7 +172,7 @@ int WsClient::PerformHandshake() { std::string headers; uint8_t buffer[4096]; int error_code = 0; - ssize_t r; + int64_t r; while (true) { while ((r = xe_socket_recv(socket_id_, buffer, sizeof(buffer), 0, &error_code)) == -1 && error_code == EINTR); @@ -279,8 +284,8 @@ void WsClient::EventThread() { while (wslay_event_want_read(ctx) || wslay_event_want_write(ctx)) { // Wait on the event. if (xe_socket_loop_poll(loop_, - wslay_event_want_read(ctx), - wslay_event_want_write(ctx))) { + !!wslay_event_want_read(ctx), + !!wslay_event_want_write(ctx))) { break; } diff --git a/src/xenia/kernel/fs/devices/local_directory_device.cc b/src/xenia/kernel/fs/devices/local_directory_device.cc index b0673f5bb..cc4080ac2 100644 --- a/src/xenia/kernel/fs/devices/local_directory_device.cc +++ b/src/xenia/kernel/fs/devices/local_directory_device.cc @@ -88,8 +88,13 @@ Entry* LocalDirectoryDevice::ResolvePath(const char* path) { XELOGFS(XT("LocalDirectoryDevice::ResolvePath(%s)"), path); xechar_t full_path[XE_MAX_PATH]; +#if XE_WCHAR + xesnprintf(full_path, XECOUNT(full_path), XT("%ls%c%hs"), + local_path_, XE_PATH_SEPARATOR, path); +#else xesnprintf(full_path, XECOUNT(full_path), XT("%s%c%s"), local_path_, XE_PATH_SEPARATOR, path); +#endif // XE_WCHAR // Swap around path separators. if (XE_PATH_SEPARATOR != '\\') { diff --git a/src/xenia/kernel/modules/xboxkrnl/objects/xmodule.cc b/src/xenia/kernel/modules/xboxkrnl/objects/xmodule.cc index 6d7858087..4590b5129 100644 --- a/src/xenia/kernel/modules/xboxkrnl/objects/xmodule.cc +++ b/src/xenia/kernel/modules/xboxkrnl/objects/xmodule.cc @@ -87,6 +87,7 @@ X_STATUS XModule::LoadFromFile(const char* path) { X_STATUS XModule::LoadFromMemory(const void* addr, const size_t length) { // Load the XEX into memory and decrypt. xe_xex2_options_t xex_options; + xe_zero_struct(&xex_options, sizeof(xex_options)); xex_ = xe_xex2_load(kernel_state()->memory(), addr, length, xex_options); XEEXPECTNOTNULL(xex_); diff --git a/src/xenia/kernel/modules/xboxkrnl/objects/xthread.cc b/src/xenia/kernel/modules/xboxkrnl/objects/xthread.cc index 6b65e571f..898364c5d 100644 --- a/src/xenia/kernel/modules/xboxkrnl/objects/xthread.cc +++ b/src/xenia/kernel/modules/xboxkrnl/objects/xthread.cc @@ -141,8 +141,6 @@ static uint32_t __stdcall XThreadStartCallbackWin32(void* param) { } X_STATUS XThread::PlatformCreate() { - XEASSERTALWAYS(); - thread_handle_ = CreateThread( NULL, creation_params_.stack_size, @@ -235,7 +233,7 @@ void XThread::Execute() { } // Run user code. - int exit_code = kernel_state()->processor()->Execute( + int exit_code = (int)kernel_state()->processor()->Execute( processor_state_, creation_params_.start_address, creation_params_.start_context); diff --git a/src/xenia/kernel/xex2.h b/src/xenia/kernel/xex2.h index e3b15d092..d5777a1b4 100644 --- a/src/xenia/kernel/xex2.h +++ b/src/xenia/kernel/xex2.h @@ -40,9 +40,9 @@ class PESection { public: char name[9]; // 8 + 1 for \0 uint32_t raw_address; - size_t raw_size; + uint32_t raw_size; uint32_t address; - size_t size; + uint32_t size; uint32_t flags; // kXEPESection* }; diff --git a/src/xenia/platform.cc b/src/xenia/platform.cc new file mode 100644 index 000000000..03f4da60c --- /dev/null +++ b/src/xenia/platform.cc @@ -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 + +#include + +#include + + +namespace { + +typedef int (*user_main_t)(int argc, xechar_t** argv); + +} + + +#if XE_PLATFORM(WIN32) && XE_WCHAR + +int xe_main_thunk( + int argc, wchar_t* argv[], + void* user_main, const char* usage) { + google::SetUsageMessage(std::string("usage: ") + usage); + google::SetVersionString("1.0"); + + char** argva = new char*[argc]; + for (int n = 0; n < argc; n++) { + size_t len = xestrlenw(argv[n]); + argva[n] = (char*)malloc(len); + xestrnarrow(argva[n], len, argv[n]); + } + + google::ParseCommandLineFlags(&argc, &argva, true); + + int result = ((user_main_t)user_main)(argc, (xechar_t**)argv); + + for (int n = 0; n < argc; n++) { + free(argva[n]); + } + delete[] argva; + + return result; +} + +#else + +int xe_main_thunk( + int argc, char** argv, + void* user_main, const char* usage) { + google::SetUsageMessage(std::string("usage: ") + usage); + google::SetVersionString("1.0"); + google::ParseCommandLineFlags(&argc, &argv, true); + return ((user_main_t)user_main)(argc, argv); +} + +#endif // WIN32 diff --git a/src/xenia/platform.h b/src/xenia/platform.h index a15de7962..84e0e941c 100644 --- a/src/xenia/platform.h +++ b/src/xenia/platform.h @@ -139,15 +139,21 @@ XE_CPU: 32BIT | 64BIT | BIGENDIAN | LITTLEENDIAN #define XE_ALIGNMENT 16 #endif // 32BIT -#if XE_LIKE(WIN32) -#define XE_MAIN_THUNK(name) \ +#if XE_LIKE(WIN32) && !defined(XE_CHAR) +int xe_main_thunk( + int argc, wchar_t* argv[], + void* user_main, const char* usage); +#define XE_MAIN_THUNK(NAME, USAGE) \ int wmain(int argc, wchar_t *argv[]) { \ - return name(argc, (xechar_t**)argv); \ + return xe_main_thunk(argc, argv, NAME, USAGE); \ } #else -#define XE_MAIN_THUNK(name) \ +int xe_main_thunk( + int argc, char** argv, + void* user_main, const char* usage); +#define XE_MAIN_THUNK(NAME, USAGE) \ int main(int argc, char **argv) { \ - return name(argc, argv); \ + return xe_main_thunk(argc, argv, NAME, USAGE); \ } #endif // WIN32 diff --git a/src/xenia/sources.gypi b/src/xenia/sources.gypi index fde3c9179..82fbe4627 100644 --- a/src/xenia/sources.gypi +++ b/src/xenia/sources.gypi @@ -11,6 +11,7 @@ 'logging.h', 'malloc.cc', 'malloc.h', + 'platform.cc', 'platform.h', 'platform_includes.h', 'string.cc', diff --git a/src/xenia/string.h b/src/xenia/string.h index 200ca6445..f86311a98 100644 --- a/src/xenia/string.h +++ b/src/xenia/string.h @@ -38,7 +38,7 @@ char* xestrcasestra(const char* str, const char* substr); #define xestrlenw wcslen #define xestrcmpw wcscmp #define xestrcasecmpw _wcsicmp -#define xestrdupw wcsdup +#define xestrdupw _wcsdup #define xestrchrw wcschr #define xestrrchrw wcsrchr #define xestrstrw wcsstr @@ -62,11 +62,12 @@ char* xestrcasestra(const char* str, const char* substr); #define xesnprintfa(buffer, bufferCount, format, ...) _snprintf_s(buffer, bufferCount, bufferCount, format, ##__VA_ARGS__) #define xevsnprintfa(buffer, bufferCount, format, args) vsnprintf(buffer, bufferCount, format, args) -#if XE_PLATFORM(WIN32) +#if !defined(XE_CHAR) && XE_PLATFORM(WIN32) typedef wchar_t xechar_t; #define XE_WCHAR 1 #define XETEXT(s) L ## s +#define XESTRFORMAT L"%ls" #define xestrlen xestrlenw #define xestrcmp xestrcmpw @@ -90,6 +91,7 @@ typedef wchar_t xechar_t; typedef char xechar_t; #define XE_CHAR 1 #define XETEXT(s) s +#define XESTRFORMAT "%s" #define xestrlen xestrlena #define xestrcmp xestrcmpa @@ -111,6 +113,7 @@ typedef char xechar_t; #endif // WIN32 #define XT XETEXT +#define XTS XESTRFORMAT #if XE_LIKE(WIN32) #define XE_PATH_SEPARATOR ((xechar_t)'\\') diff --git a/third_party/wslay.gypi b/third_party/wslay.gypi index 5f8edbf63..de99a01f1 100644 --- a/third_party/wslay.gypi +++ b/third_party/wslay.gypi @@ -31,7 +31,7 @@ ['OS == "win"', { 'defines': [ 'HAVE_WINSOCK2_H=1', - 'ssize_t=unsigned long long', + 'ssize_t=long long', ], }], ], diff --git a/tools/xenia-run/xenia-run.cc b/tools/xenia-run/xenia-run.cc index 477a30b0d..1818606a2 100644 --- a/tools/xenia-run/xenia-run.cc +++ b/tools/xenia-run/xenia-run.cc @@ -70,7 +70,11 @@ int Run::Launch(const xechar_t* path) { // TODO(benvanik): move this someplace common. xechar_t abs_path[XE_MAX_PATH]; #if XE_PLATFORM(WIN32) +#if XE_WCHAR _wfullpath(abs_path, path, XECOUNT(abs_path)); +#else + _fullpath(abs_path, path, sizeof(abs_path)); +#endif // XE_WCHAR #else realpath(path, abs_path); #endif // WIN32 @@ -102,12 +106,6 @@ int Run::Launch(const xechar_t* path) { } int xenia_run(int argc, xechar_t **argv) { - std::string usage = "usage: "; - usage += "xenia-run some.xex"; - google::SetUsageMessage(usage); - google::SetVersionString("1.0"); - google::ParseCommandLineFlags(&argc, &argv, true); - // Dummy call to keep the GPU code linking in to ensure it's working. do_gpu_stuff(); @@ -135,4 +133,4 @@ XECLEANUP: google::ShutDownCommandLineFlags(); return result_code; } -XE_MAIN_THUNK(xenia_run); +XE_MAIN_THUNK(xenia_run, "xenia-run some.xex"); diff --git a/tools/xenia-test/xenia-test.cc b/tools/xenia-test/xenia-test.cc index a36069036..9c3609593 100644 --- a/tools/xenia-test/xenia-test.cc +++ b/tools/xenia-test/xenia-test.cc @@ -230,12 +230,6 @@ XECLEANUP: } int xenia_test(int argc, xechar_t **argv) { - string usage = "usage: "; - usage += "xenia-test some.xex"; - google::SetUsageMessage(usage); - google::SetVersionString("1.0"); - google::ParseCommandLineFlags(&argc, &argv, true); - int result_code = 1; // Grab test name, if present. @@ -249,4 +243,4 @@ int xenia_test(int argc, xechar_t **argv) { google::ShutDownCommandLineFlags(); return result_code; } -XE_MAIN_THUNK(xenia_test); +XE_MAIN_THUNK(xenia_test, "xenia-test some.xex");