diff --git a/Source/Core/Common/Src/CPUDetect.cpp b/Source/Core/Common/Src/CPUDetect.cpp index b0908758d5..cd77d37346 100644 --- a/Source/Core/Common/Src/CPUDetect.cpp +++ b/Source/Core/Common/Src/CPUDetect.cpp @@ -93,7 +93,8 @@ void CPUInfo::Detect() #ifdef _WIN32 #ifdef _M_IX86 BOOL f64 = false; - OS64bit = IsWow64Process(GetCurrentProcess(), &f64); + IsWow64Process(GetCurrentProcess(), &f64); + OS64bit = (f64 == TRUE) ? true : false; #endif #endif diff --git a/Source/Core/Common/Src/Common.h b/Source/Core/Common/Src/Common.h index a2ae46ff52..7f942476ff 100644 --- a/Source/Core/Common/Src/Common.h +++ b/Source/Core/Common/Src/Common.h @@ -92,7 +92,7 @@ #ifndef _SECURE_SCL #error Please define _SECURE_SCL=0 in the project settings #else - CompileTimeAssert<_SECURE_SCL==0> x; + CompileTimeAssert<_SECURE_SCL==0> EnsureNoSecureSCL; #endif } diff --git a/Source/Core/Common/Src/CommonPaths.h b/Source/Core/Common/Src/CommonPaths.h index f32236f9b4..3250c4fe7f 100644 --- a/Source/Core/Common/Src/CommonPaths.h +++ b/Source/Core/Common/Src/CommonPaths.h @@ -115,10 +115,10 @@ // Shorts - dirs // User dirs #define FULL_USERDATA_DIR ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP -#define T_FULLUSERDATA_DIR _T(ROOT_DIR) _T(DIR_SEP) _T(USERDATA_DIR) _T(DIR_SEP) +#define T_FULLUSERDATA_DIR _T(ROOT_DIR) _T(DIR_SEP) _T(USERDATA_DIR) _T(DIR_SEP) #define FULL_GC_USER_DIR FULL_USERDATA_DIR GC_USER_DIR DIR_SEP -#define T_FULL_GC_USER_DIR T_FULLUSERDATA_DIR _T(GC_USER_DIR) _T(DIR_SEP) +#define T_FULL_GC_USER_DIR T_FULLUSERDATA_DIR _T(GC_USER_DIR) _T(DIR_SEP) #define FULL_WII_USER_DIR FULL_USERDATA_DIR WII_USER_DIR DIR_SEP #define FULL_WII_ROOT_DIR FULL_USERDATA_DIR WII_USER_DIR // This is the "root" for Wii fs, so that it may be used with created devices diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index 4c86d071e4..0879ede119 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -487,18 +487,20 @@ bool DeleteDirRecursively(const char *directory) return true; } -// Returns the current directory, caller should free -const char *GetCurrentDir() +// Returns the current directory +std::string GetCurrentDir() { - const char *dir; + char *dir; // Get the current working directory (getcwd uses malloc) if (!(dir = __getcwd(NULL, 0))) { ERROR_LOG(COMMON, "GetCurrentDirectory failed: %s", GetLastErrorMsg()); - return NULL; + return NULL; } - return dir; + std::string strDir = dir; + free(dir); + return strDir; } // Sets the current directory to the given directory @@ -577,14 +579,15 @@ std::string GetSysDirectory() sysDir = GetBundleDirectory(); sysDir += DIR_SEP; sysDir += SYSDATA_DIR; + sysDir += DIR_SEP; #elif defined __linux__ sysDir = SYSDATA_DIR; + sysDir += DIR_SEP; // FIXME global install #else - sysDir = SYSDATA_DIR; + sysDir = FULL_SYSDATA_DIR; #endif - sysDir += DIR_SEP; INFO_LOG(COMMON, "GetSysDirectory: Setting to %s:", sysDir.c_str()); return sysDir; } diff --git a/Source/Core/Common/Src/FileUtil.h b/Source/Core/Common/Src/FileUtil.h index 48871644ab..c4a4abd2a7 100644 --- a/Source/Core/Common/Src/FileUtil.h +++ b/Source/Core/Common/Src/FileUtil.h @@ -26,7 +26,7 @@ namespace File { - + // FileSystem tree node/ struct FSTEntry { @@ -36,10 +36,10 @@ struct FSTEntry std::string virtualName; // name in FST names table std::vector children; }; - + // Returns true if file filename exists bool Exists(const char *filename); - + // Returns true if filename is a directory bool IsDirectory(const char *filename); @@ -64,31 +64,31 @@ bool Rename(const char *srcFilename, const char *destFilename); // copies file srcFilename to destFilename, returns true on success bool Copy(const char *srcFilename, const char *destFilename); - + // creates an empty file filename, returns true on success bool CreateEmptyFile(const char *filename); // Scans the directory tree gets, starting from _Directory and adds the // results into parentEntry. Returns the number of files+directories found u32 ScanDirectoryTree(const char *directory, FSTEntry& parentEntry); - + // deletes the given directory and anything under it. Returns true on success. bool DeleteDirRecursively(const char *directory); - -// Returns the current directory, caller should free -const char *GetCurrentDir(); - + +// Returns the current directory +std::string GetCurrentDir(); + // Set the current directory to given directory bool SetCurrentDir(const char *directory); - + // Returns a pointer to a string with a Dolphin data dir in the user's home // directory. To be used in "multi-user" mode (that is, installed). const char *GetUserDirectory(); - + // Returns the path to where the plugins are std::string GetPluginsDirectory(); - + // Returns the path to where the sys file are std::string GetSysDirectory(); diff --git a/Source/Core/Common/Src/MemArena.cpp b/Source/Core/Common/Src/MemArena.cpp index ace189a3ec..fb9e6e03af 100644 --- a/Source/Core/Common/Src/MemArena.cpp +++ b/Source/Core/Common/Src/MemArena.cpp @@ -40,7 +40,7 @@ static const char* ram_temp_file = "/tmp/gc_mem.tmp"; void MemArena::GrabLowMemSpace(size_t size) { #ifdef _WIN32 - hMemoryMapping = CreateFileMapping(NULL, NULL, PAGE_READWRITE, 0, (DWORD)(size), _T("All GC Memory")); + hMemoryMapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, (DWORD)(size), _T("All GC Memory")); #else mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; fd = open(ram_temp_file, O_RDWR | O_CREAT, mode); diff --git a/Source/Core/Common/Src/MemoryUtil.cpp b/Source/Core/Common/Src/MemoryUtil.cpp index abdd0dfaa6..acbdaabcbe 100644 --- a/Source/Core/Common/Src/MemoryUtil.cpp +++ b/Source/Core/Common/Src/MemoryUtil.cpp @@ -35,7 +35,7 @@ #define MAP_VARIABLE 0 #endif -// This is purposedely not a full wrapper for virtualalloc/mmap, but it +// This is purposely not a full wrapper for virtualalloc/mmap, but it // provides exactly the primitive operations that Dolphin needs. void* AllocateExecutableMemory(size_t size, bool low) @@ -49,7 +49,7 @@ void* AllocateExecutableMemory(size_t size, bool low) // If this happens, we have to implement a free ram search scheme. ector knows how. } - return(ptr); + return ptr; #else void* retval = mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, @@ -65,12 +65,11 @@ void* AllocateExecutableMemory(size_t size, bool low) PanicAlert("Failed to allocate executable memory, errno=%i", errno); } - return(retval); + return retval; #endif } - void* AllocateMemoryPages(size_t size) { #ifdef _WIN32 @@ -81,7 +80,7 @@ void* AllocateMemoryPages(size_t size) PanicAlert("Failed to allocate raw memory"); } - return(ptr); + return ptr; #else void* retval = mmap(0, size, PROT_READ | PROT_WRITE, @@ -93,43 +92,43 @@ void* AllocateMemoryPages(size_t size) PanicAlert("Failed to allocate raw memory, errno=%i", errno); } - return(retval); + return retval; #endif } - void FreeMemoryPages(void* ptr, size_t size) { #ifdef _WIN32 if (ptr) { - VirtualFree(ptr, 0, MEM_RELEASE); - ptr = NULL; + if (!VirtualFree(ptr, 0, MEM_RELEASE)) + PanicAlert("FreeMemoryPages failed!\n%s", GetLastErrorMsg()); + ptr = NULL; // Is this our responsibility? } #else munmap(ptr, size); #endif } - void WriteProtectMemory(void* ptr, size_t size, bool allowExecute) { #ifdef _WIN32 - VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READ : PAGE_READONLY, 0); + DWORD oldValue; + if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READ : PAGE_READONLY, &oldValue)) + PanicAlert("WriteProtectMemory failed!\n%s", GetLastErrorMsg()); #else mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_EXEC) : PROT_READ); #endif } - void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute) { #ifdef _WIN32 - VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READWRITE : PAGE_READONLY, 0); + DWORD oldValue; + if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, &oldValue)) + PanicAlert("UnWriteProtectMemory failed!\n%s", GetLastErrorMsg()); #else mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) : PROT_WRITE | PROT_READ); #endif } - - diff --git a/Source/Core/Common/Src/SDCardUtil.cpp b/Source/Core/Common/Src/SDCardUtil.cpp index 90f8451c4a..689fc1ffd2 100644 --- a/Source/Core/Common/Src/SDCardUtil.cpp +++ b/Source/Core/Common/Src/SDCardUtil.cpp @@ -206,7 +206,10 @@ bool SDCardCreate(u32 disk_size /*in MB*/, char* filename) f = fopen(filename, "wb"); if (!f) + { ERROR_LOG(COMMON, "could not create file '%s', aborting...\n", filename); + return false; + } /* here's the layout: * @@ -246,7 +249,8 @@ bool SDCardCreate(u32 disk_size /*in MB*/, char* filename) FailWrite: ERROR_LOG(COMMON, "could not write to '%s', aborting...\n", filename); - unlink(filename); + if (unlink(filename) < 0) + ERROR_LOG(COMMON, "unlink(%s) failed\n%s", filename, GetLastErrorMsg()); fclose(f); return false; } diff --git a/Source/Core/Common/Src/Thread.cpp b/Source/Core/Common/Src/Thread.cpp index aa9f5c4a2e..0cd237e2f8 100644 --- a/Source/Core/Common/Src/Thread.cpp +++ b/Source/Core/Common/Src/Thread.cpp @@ -17,7 +17,7 @@ #include "Setup.h" #include "Thread.h" -#include "Log.h" +#include "Common.h" #ifdef USE_BEGINTHREADEX #include @@ -37,7 +37,8 @@ CriticalSection::CriticalSection(int spincount) { if (spincount) { - InitializeCriticalSectionAndSpinCount(§ion, spincount); + if (!InitializeCriticalSectionAndSpinCount(§ion, spincount)) + ERROR_LOG(COMMON, "CriticalSection could not be initialized!\n%s", GetLastErrorMsg()); } else { @@ -195,6 +196,8 @@ typedef struct tagTHREADNAME_INFO // Uses undocumented (actually, it is now documented) trick. // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/vxtsksettingthreadname.asp +// This is implemented much nicer in upcoming msvc++, see: +// http://msdn.microsoft.com/en-us/library/xcb2z8hs(VS.100).aspx void SetCurrentThreadName(const TCHAR* szThreadName) { THREADNAME_INFO info; diff --git a/Source/Core/DolphinWX/Src/Main.cpp b/Source/Core/DolphinWX/Src/Main.cpp index 7f6e7250e2..47a09e1a9d 100644 --- a/Source/Core/DolphinWX/Src/Main.cpp +++ b/Source/Core/DolphinWX/Src/Main.cpp @@ -19,10 +19,6 @@ #include #include "svnrev.h" -#ifdef WIN32 -#include -#endif - #ifdef __APPLE__ #include #endif