Fixing VC++ warnings and errors.

This commit is contained in:
Ben Vanik 2013-02-08 22:07:38 -08:00
parent c1e2119db4
commit 338b890ef5
26 changed files with 147 additions and 58 deletions

View File

@ -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': [

View File

@ -16,10 +16,11 @@
#include <xenia/config.h>
#include <xenia/platform.h>
#include <xenia/platform_includes.h>
#include <xenia/string.h>
#include <xenia/types.h>
#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

View File

@ -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);

View File

@ -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);

View File

@ -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.

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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]);
}
}

View File

@ -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;
}

View File

@ -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.

View File

@ -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
};

View File

@ -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,

View File

@ -9,6 +9,11 @@
#include <xenia/dbg/simple_sha1.h>
#if XE_PLATFORM(WIN32)
#include <winsock2.h>
#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)),

View File

@ -12,6 +12,11 @@
#include <xenia/dbg/debugger.h>
#include <xenia/dbg/simple_sha1.h>
#if XE_PLATFORM(WIN32)
// Required for wslay.
typedef SSIZE_T ssize_t;
#endif // WIN32
#include <wslay/wslay.h>
@ -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<WsClient*>(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<WsClient*>(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;
}

View File

@ -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 != '\\') {

View File

@ -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_);

View File

@ -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);

View File

@ -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*
};

62
src/xenia/platform.cc Normal file
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/platform.h>
#include <gflags/gflags.h>
#include <xenia/common.h>
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

View File

@ -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

View File

@ -11,6 +11,7 @@
'logging.h',
'malloc.cc',
'malloc.h',
'platform.cc',
'platform.h',
'platform_includes.h',
'string.cc',

View File

@ -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)'\\')

View File

@ -31,7 +31,7 @@
['OS == "win"', {
'defines': [
'HAVE_WINSOCK2_H=1',
'ssize_t=unsigned long long',
'ssize_t=long long',
],
}],
],

View File

@ -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");

View File

@ -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");