misc cleanup

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3942 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Shawn Hoffman 2009-08-06 06:18:22 +00:00
parent 43adc4f194
commit 95344be674
10 changed files with 52 additions and 46 deletions

View File

@ -93,7 +93,8 @@ void CPUInfo::Detect()
#ifdef _WIN32 #ifdef _WIN32
#ifdef _M_IX86 #ifdef _M_IX86
BOOL f64 = false; BOOL f64 = false;
OS64bit = IsWow64Process(GetCurrentProcess(), &f64); IsWow64Process(GetCurrentProcess(), &f64);
OS64bit = (f64 == TRUE) ? true : false;
#endif #endif
#endif #endif

View File

@ -92,7 +92,7 @@
#ifndef _SECURE_SCL #ifndef _SECURE_SCL
#error Please define _SECURE_SCL=0 in the project settings #error Please define _SECURE_SCL=0 in the project settings
#else #else
CompileTimeAssert<_SECURE_SCL==0> x; CompileTimeAssert<_SECURE_SCL==0> EnsureNoSecureSCL;
#endif #endif
} }

View File

@ -487,10 +487,10 @@ bool DeleteDirRecursively(const char *directory)
return true; return true;
} }
// Returns the current directory, caller should free // Returns the current directory
const char *GetCurrentDir() std::string GetCurrentDir()
{ {
const char *dir; char *dir;
// Get the current working directory (getcwd uses malloc) // Get the current working directory (getcwd uses malloc)
if (!(dir = __getcwd(NULL, 0))) { if (!(dir = __getcwd(NULL, 0))) {
@ -498,7 +498,9 @@ const char *GetCurrentDir()
GetLastErrorMsg()); GetLastErrorMsg());
return NULL; return NULL;
} }
return dir; std::string strDir = dir;
free(dir);
return strDir;
} }
// Sets the current directory to the given directory // Sets the current directory to the given directory
@ -577,14 +579,15 @@ std::string GetSysDirectory()
sysDir = GetBundleDirectory(); sysDir = GetBundleDirectory();
sysDir += DIR_SEP; sysDir += DIR_SEP;
sysDir += SYSDATA_DIR; sysDir += SYSDATA_DIR;
sysDir += DIR_SEP;
#elif defined __linux__ #elif defined __linux__
sysDir = SYSDATA_DIR; sysDir = SYSDATA_DIR;
sysDir += DIR_SEP;
// FIXME global install // FIXME global install
#else #else
sysDir = SYSDATA_DIR; sysDir = FULL_SYSDATA_DIR;
#endif #endif
sysDir += DIR_SEP;
INFO_LOG(COMMON, "GetSysDirectory: Setting to %s:", sysDir.c_str()); INFO_LOG(COMMON, "GetSysDirectory: Setting to %s:", sysDir.c_str());
return sysDir; return sysDir;
} }

View File

@ -75,8 +75,8 @@ u32 ScanDirectoryTree(const char *directory, FSTEntry& parentEntry);
// deletes the given directory and anything under it. Returns true on success. // deletes the given directory and anything under it. Returns true on success.
bool DeleteDirRecursively(const char *directory); bool DeleteDirRecursively(const char *directory);
// Returns the current directory, caller should free // Returns the current directory
const char *GetCurrentDir(); std::string GetCurrentDir();
// Set the current directory to given directory // Set the current directory to given directory
bool SetCurrentDir(const char *directory); bool SetCurrentDir(const char *directory);

View File

@ -40,7 +40,7 @@ static const char* ram_temp_file = "/tmp/gc_mem.tmp";
void MemArena::GrabLowMemSpace(size_t size) void MemArena::GrabLowMemSpace(size_t size)
{ {
#ifdef _WIN32 #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 #else
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
fd = open(ram_temp_file, O_RDWR | O_CREAT, mode); fd = open(ram_temp_file, O_RDWR | O_CREAT, mode);

View File

@ -35,7 +35,7 @@
#define MAP_VARIABLE 0 #define MAP_VARIABLE 0
#endif #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. // provides exactly the primitive operations that Dolphin needs.
void* AllocateExecutableMemory(size_t size, bool low) 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. // If this happens, we have to implement a free ram search scheme. ector knows how.
} }
return(ptr); return ptr;
#else #else
void* retval = mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, 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); PanicAlert("Failed to allocate executable memory, errno=%i", errno);
} }
return(retval); return retval;
#endif #endif
} }
void* AllocateMemoryPages(size_t size) void* AllocateMemoryPages(size_t size)
{ {
#ifdef _WIN32 #ifdef _WIN32
@ -81,7 +80,7 @@ void* AllocateMemoryPages(size_t size)
PanicAlert("Failed to allocate raw memory"); PanicAlert("Failed to allocate raw memory");
} }
return(ptr); return ptr;
#else #else
void* retval = mmap(0, size, PROT_READ | PROT_WRITE, 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); PanicAlert("Failed to allocate raw memory, errno=%i", errno);
} }
return(retval); return retval;
#endif #endif
} }
void FreeMemoryPages(void* ptr, size_t size) void FreeMemoryPages(void* ptr, size_t size)
{ {
#ifdef _WIN32 #ifdef _WIN32
if (ptr) if (ptr)
{ {
VirtualFree(ptr, 0, MEM_RELEASE); if (!VirtualFree(ptr, 0, MEM_RELEASE))
ptr = NULL; PanicAlert("FreeMemoryPages failed!\n%s", GetLastErrorMsg());
ptr = NULL; // Is this our responsibility?
} }
#else #else
munmap(ptr, size); munmap(ptr, size);
#endif #endif
} }
void WriteProtectMemory(void* ptr, size_t size, bool allowExecute) void WriteProtectMemory(void* ptr, size_t size, bool allowExecute)
{ {
#ifdef _WIN32 #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 #else
mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_EXEC) : PROT_READ); mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_EXEC) : PROT_READ);
#endif #endif
} }
void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute) void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute)
{ {
#ifdef _WIN32 #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 #else
mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) : PROT_WRITE | PROT_READ); mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) : PROT_WRITE | PROT_READ);
#endif #endif
} }

View File

@ -206,7 +206,10 @@ bool SDCardCreate(u32 disk_size /*in MB*/, char* filename)
f = fopen(filename, "wb"); f = fopen(filename, "wb");
if (!f) if (!f)
{
ERROR_LOG(COMMON, "could not create file '%s', aborting...\n", filename); ERROR_LOG(COMMON, "could not create file '%s', aborting...\n", filename);
return false;
}
/* here's the layout: /* here's the layout:
* *
@ -246,7 +249,8 @@ bool SDCardCreate(u32 disk_size /*in MB*/, char* filename)
FailWrite: FailWrite:
ERROR_LOG(COMMON, "could not write to '%s', aborting...\n", filename); 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); fclose(f);
return false; return false;
} }

View File

@ -17,7 +17,7 @@
#include "Setup.h" #include "Setup.h"
#include "Thread.h" #include "Thread.h"
#include "Log.h" #include "Common.h"
#ifdef USE_BEGINTHREADEX #ifdef USE_BEGINTHREADEX
#include <process.h> #include <process.h>
@ -37,7 +37,8 @@ CriticalSection::CriticalSection(int spincount)
{ {
if (spincount) if (spincount)
{ {
InitializeCriticalSectionAndSpinCount(&section, spincount); if (!InitializeCriticalSectionAndSpinCount(&section, spincount))
ERROR_LOG(COMMON, "CriticalSection could not be initialized!\n%s", GetLastErrorMsg());
} }
else else
{ {
@ -195,6 +196,8 @@ typedef struct tagTHREADNAME_INFO
// Uses undocumented (actually, it is now documented) trick. // Uses undocumented (actually, it is now documented) trick.
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/vxtsksettingthreadname.asp // 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) void SetCurrentThreadName(const TCHAR* szThreadName)
{ {
THREADNAME_INFO info; THREADNAME_INFO info;

View File

@ -19,10 +19,6 @@
#include <string> #include <string>
#include "svnrev.h" #include "svnrev.h"
#ifdef WIN32
#include <crtdbg.h>
#endif
#ifdef __APPLE__ #ifdef __APPLE__
#include <sys/param.h> #include <sys/param.h>
#endif #endif