diff --git a/Common/ArmEmitter.h b/Common/ArmEmitter.h index 0af0e636aa..5368487caa 100644 --- a/Common/ArmEmitter.h +++ b/Common/ArmEmitter.h @@ -22,6 +22,9 @@ #include "Common.h" #include "MemoryUtil.h" +#ifdef __SYMBIAN32__ +#include +#endif #undef _SP diff --git a/Common/FileUtil.cpp b/Common/FileUtil.cpp index 47ef592e62..3a2fb47ed1 100644 --- a/Common/FileUtil.cpp +++ b/Common/FileUtil.cpp @@ -53,6 +53,22 @@ #define fstat64 fstat #endif +#if !defined(readdir_r) +static inline int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) { + struct dirent *readdir_entry; + + readdir_entry = readdir(dirp); + if (readdir_entry == NULL) { + *result = NULL; + return errno; + } + + *entry = *readdir_entry; + *result = entry; + return 0; +} +#endif + // This namespace has various generic functions related to files and paths. // The code still needs a ton of cleanup. // REMEMBER: strdup considered harmful! diff --git a/Common/Log.h b/Common/Log.h index ff788063e6..07c90072f4 100644 --- a/Common/Log.h +++ b/Common/Log.h @@ -23,6 +23,10 @@ #define INFO_LEVEL 4 // General information. #define DEBUG_LEVEL 5 // Detailed debugging - might make things slow. +#ifdef __SYMBIAN32__ +#include +#endif + namespace LogTypes { diff --git a/Common/LogManager.cpp b/Common/LogManager.cpp index bbce7a7a80..48843266fb 100644 --- a/Common/LogManager.cpp +++ b/Common/LogManager.cpp @@ -22,6 +22,9 @@ #include "Timer.h" #include "Thread.h" #include "FileUtil.h" +#ifdef __SYMBIAN32__ +#include +#endif void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char *file, int line, const char* fmt, ...) @@ -197,7 +200,11 @@ void FileLogListener::Log(LogTypes::LOG_LEVELS, const char *msg) return; std::lock_guard lk(m_log_lock); +#ifdef __SYMBIAN32__ + RDebug::Printf("%s",msg); +#else m_logfile << msg << std::flush; +#endif } void DebuggerLogListener::Log(LogTypes::LOG_LEVELS, const char *msg) diff --git a/Common/MemArena.cpp b/Common/MemArena.cpp index 0765f16b8b..22acf02f73 100644 --- a/Common/MemArena.cpp +++ b/Common/MemArena.cpp @@ -33,6 +33,11 @@ #endif #endif +#if defined(__SYMBIAN32__) + // Also Xbox 360 + #define UNUSABLE_MMAP 1 +#endif + #ifdef ANDROID @@ -108,12 +113,12 @@ SYSTEM_INFO sysInfo; // Windows mappings need to be on 64K boundaries, due to Alpha legacy. #ifdef _WIN32 size_t roundup(size_t x) { - int gran = sysInfo.dwAllocationGranularity ? sysInfo.dwAllocationGranularity : 0x10000; - return (x + gran - 1) & ~(gran - 1); + int gran = sysInfo.dwAllocationGranularity ? sysInfo.dwAllocationGranularity : 0x10000; + return (x + gran - 1) & ~(gran - 1); } #else size_t roundup(size_t x) { - return x; + return x; } #endif @@ -122,8 +127,8 @@ void MemArena::GrabLowMemSpace(size_t size) { #ifdef _WIN32 hMemoryMapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, (DWORD)(size), NULL); - GetSystemInfo(&sysInfo); -#elif ANDROID + GetSystemInfo(&sysInfo); +#elif defined(ANDROID) // Use ashmem so we don't have to allocate a file on disk! fd = ashmem_create_region("PPSSPP_RAM", size); // Note that it appears that ashmem is pinned by default, so no need to pin. @@ -132,6 +137,8 @@ void MemArena::GrabLowMemSpace(size_t size) ERROR_LOG(MEMMAP, "Failed to grab ashmem space of size: %08x errno: %d", (int)size, (int)(errno)); return; } +#elif defined(UNUSABLE_MMAP) + // Do nothing as we are using malloc() #else mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; fd = open(ram_temp_file.c_str(), O_RDWR | O_CREAT, mode); @@ -156,6 +163,8 @@ void MemArena::ReleaseSpace() #ifdef _WIN32 CloseHandle(hMemoryMapping); hMemoryMapping = 0; +#elif defined(UNUSABLE_MMAP) + // Do nothing as we are using malloc() #else close(fd); #endif @@ -165,30 +174,32 @@ void MemArena::ReleaseSpace() void *MemArena::CreateView(s64 offset, size_t size, void *base) { #ifdef _WIN32 - size = roundup(size); - void *ptr = MapViewOfFileEx(hMemoryMapping, FILE_MAP_ALL_ACCESS, 0, (DWORD)((u64)offset), size, base); - if (!ptr) { - //ERROR_LOG(MEMMAP, "Failed to map memory: %08x %08x %08x : %s", (u32)offset, (u32)size, (u32)base, GetLastErrorMsg()); - } else { - //ERROR_LOG(MEMMAP, "Mapped memory: %08x %08x %08x : %s", (u32)offset, (u32)size, (u32)base, GetLastErrorMsg()); - } - return ptr; + size = roundup(size); + void *ptr = MapViewOfFileEx(hMemoryMapping, FILE_MAP_ALL_ACCESS, 0, (DWORD)((u64)offset), size, base); + if (!ptr) { + //ERROR_LOG(MEMMAP, "Failed to map memory: %08x %08x %08x : %s", (u32)offset, (u32)size, (u32)base, GetLastErrorMsg()); + } else { + //ERROR_LOG(MEMMAP, "Mapped memory: %08x %08x %08x : %s", (u32)offset, (u32)size, (u32)base, GetLastErrorMsg()); + } + return ptr; +#elif defined(UNUSABLE_MMAP) + void *retval = malloc(size); + if (!retval) + { + NOTICE_LOG(MEMMAP, "malloc failed: %s", strerror(errno)); + return 0; + } + return retval; #else - void *retval = mmap( - base, size, - PROT_READ | PROT_WRITE, - MAP_SHARED | ((base == 0) ? 0 : MAP_FIXED), - fd, offset); + void *retval = mmap(base, size, PROT_READ | PROT_WRITE, MAP_SHARED | + ((base == 0) ? 0 : MAP_FIXED), fd, offset); if (retval == MAP_FAILED) { NOTICE_LOG(MEMMAP, "mmap on %s (fd: %d) failed", ram_temp_file.c_str(), (int)fd); return 0; } - else - { - return retval; - } + return retval; #endif } @@ -197,6 +208,8 @@ void MemArena::ReleaseView(void* view, size_t size) { #ifdef _WIN32 UnmapViewOfFile(view); +#elif defined(UNUSABLE_MMAP) + free(view); #else munmap(view, size); #endif @@ -226,6 +239,9 @@ u8* MemArena::Find4GBBase() VirtualFree(base, 0, MEM_RELEASE); } return base; +#elif defined(UNUSABLE_MMAP) + // We are unable to use relative addresses due to lack of mmap() + return NULL; #else void* base = mmap(0, 0x5000000, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0); @@ -391,7 +407,7 @@ void MemoryMap_Shutdown(const MemoryView *views, int num_views, u32 flags, MemAr if (*views[i].out_ptr && (views[i].out_ptr_low && *views[i].out_ptr != *views[i].out_ptr_low)) arena->ReleaseView(*views[i].out_ptr, views[i].size); *views[i].out_ptr = NULL; - if (views[i].out_ptr_low) + if (views[i].out_ptr_low) *views[i].out_ptr_low = NULL; } } diff --git a/Common/MemoryUtil.cpp b/Common/MemoryUtil.cpp index 4595cddf16..2a4d74a469 100644 --- a/Common/MemoryUtil.cpp +++ b/Common/MemoryUtil.cpp @@ -53,6 +53,9 @@ void* AllocateExecutableMemory(size_t size, bool low) { #if defined(_WIN32) void* ptr = VirtualAlloc(0, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); +#elif defined(__SYMBIAN32__) + // On Symbian, we will need to create an RChunk and allocate with ->CreateLocalCode(size, size); + void* ptr = mmap(map_hint, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, -1, 0); #else static char *map_hint = 0; #if defined(__x86_64__) && !defined(MAP_32BIT) @@ -130,9 +133,12 @@ void* AllocateAlignedMemory(size_t size,size_t alignment) #else void* ptr = NULL; #ifdef ANDROID - ptr = memalign(alignment, size); + ptr = memalign(alignment, size); +#elif defined(__SYMBIAN32__) + // On Symbian, we will want to create an RChunk. + ptr = malloc(size); #else - posix_memalign(&ptr, alignment, size); + posix_memalign(&ptr, alignment, size); #endif #endif diff --git a/Common/Misc.cpp b/Common/Misc.cpp index 53f37c2bf2..1d4bd15b09 100644 --- a/Common/Misc.cpp +++ b/Common/Misc.cpp @@ -17,7 +17,7 @@ #include "Common.h" -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__SYMBIAN32__) #define __thread #endif diff --git a/Common/StdConditionVariable.h b/Common/StdConditionVariable.h index c72185ce8b..b6ffd5d424 100644 --- a/Common/StdConditionVariable.h +++ b/Common/StdConditionVariable.h @@ -5,7 +5,7 @@ #define GCC_VER(x,y,z) ((x) * 10000 + (y) * 100 + (z)) #define GCC_VERSION GCC_VER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) -#if GCC_VERSION >= GCC_VER(4,4,0) && __GXX_EXPERIMENTAL_CXX0X__ && !defined(ANDROID) +#if GCC_VERSION >= GCC_VER(4,4,0) && __GXX_EXPERIMENTAL_CXX0X__ && !defined(ANDROID) && !defined(__SYMBIAN32__) // GCC 4.4 provides #include #else diff --git a/Common/StdMutex.h b/Common/StdMutex.h index 695ae5ce95..b71d0dccbe 100644 --- a/Common/StdMutex.h +++ b/Common/StdMutex.h @@ -5,7 +5,7 @@ #define GCC_VER(x,y,z) ((x) * 10000 + (y) * 100 + (z)) #define GCC_VERSION GCC_VER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) -#if GCC_VERSION >= GCC_VER(4,4,0) && __GXX_EXPERIMENTAL_CXX0X__ && !defined(ANDROID) +#if GCC_VERSION >= GCC_VER(4,4,0) && __GXX_EXPERIMENTAL_CXX0X__ && !defined(ANDROID) && !defined(__SYMBIAN32__) // GCC 4.4 provides #include #else diff --git a/Common/StdThread.h b/Common/StdThread.h index 23dfee63e0..f32a96be92 100644 --- a/Common/StdThread.h +++ b/Common/StdThread.h @@ -5,7 +5,7 @@ #define GCC_VER(x,y,z) ((x) * 10000 + (y) * 100 + (z)) #define GCC_VERSION GCC_VER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) -#if GCC_VERSION >= GCC_VER(4,4,0) && __GXX_EXPERIMENTAL_CXX0X__ && !defined(ANDROID) +#if GCC_VERSION >= GCC_VER(4,4,0) && __GXX_EXPERIMENTAL_CXX0X__ && !defined(ANDROID) && !defined(__SYMBIAN32__) // GCC 4.4 provides #ifndef _GLIBCXX_USE_SCHED_YIELD #define _GLIBCXX_USE_SCHED_YIELD diff --git a/Common/StringUtil.cpp b/Common/StringUtil.cpp index ffa9434ef1..8d96eae2b8 100644 --- a/Common/StringUtil.cpp +++ b/Common/StringUtil.cpp @@ -258,31 +258,31 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st // Uri encode and decode. // RFC1630, RFC1738, RFC2396 -//#include -//#include - -const char HEX2DEC[256] = +// Some compilers don't like to assume (int)-1 will safely cast to (char)-1 as +// the MSBs aren't 0's. Workaround the issue while maintaining table spacing. +#define N1 (char)-1 +const char HEX2DEC[256] = { - /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ - /* 0 */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, - /* 1 */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, - /* 2 */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, - /* 3 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1, -1,-1,-1,-1, + /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ + /* 0 */ N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, + /* 1 */ N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, + /* 2 */ N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, + /* 3 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,N1,N1, N1,N1,N1,N1, - /* 4 */ -1,10,11,12, 13,14,15,-1, -1,-1,-1,-1, -1,-1,-1,-1, - /* 5 */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, - /* 6 */ -1,10,11,12, 13,14,15,-1, -1,-1,-1,-1, -1,-1,-1,-1, - /* 7 */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, + /* 4 */ N1,10,11,12, 13,14,15,N1, N1,N1,N1,N1, N1,N1,N1,N1, + /* 5 */ N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, + /* 6 */ N1,10,11,12, 13,14,15,N1, N1,N1,N1,N1, N1,N1,N1,N1, + /* 7 */ N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, - /* 8 */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, - /* 9 */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, - /* A */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, - /* B */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, + /* 8 */ N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, + /* 9 */ N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, + /* A */ N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, + /* B */ N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, - /* C */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, - /* D */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, - /* E */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, - /* F */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1 + /* C */ N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, + /* D */ N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, + /* E */ N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, + /* F */ N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1, N1,N1,N1,N1 }; std::string UriDecode(const std::string & sSrc) diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index eb921c4455..462c40b278 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -37,11 +37,10 @@ #include "sceKernelMemory.h" #include "sceKernelThread.h" -#define ERROR_ERRNO_FILE_NOT_FOUND 0x80010002 +#define ERROR_ERRNO_FILE_NOT_FOUND 0x80010002 - -#define ERROR_MEMSTICK_DEVCTL_BAD_PARAMS 0x80220081 -#define ERROR_MEMSTICK_DEVCTL_TOO_MANY_CALLBACKS 0x80220082 +#define ERROR_MEMSTICK_DEVCTL_BAD_PARAMS 0x80220081 +#define ERROR_MEMSTICK_DEVCTL_TOO_MANY_CALLBACKS 0x80220082 /* @@ -95,6 +94,12 @@ enum { TYPE_FILE=0x20 }; +#ifdef __SYMBIAN32__ +#undef st_ctime +#undef st_atime +#undef st_mtime +#endif + struct SceIoStat { SceMode st_mode; unsigned int st_attr; @@ -110,7 +115,7 @@ struct SceIoDirEnt { char d_name[256]; u32 d_private; }; - +#ifndef __SYMBIAN32__ struct dirent { u32 unk0; u32 type; @@ -118,6 +123,7 @@ struct dirent { u32 unk[19]; char name[0x108]; }; +#endif class FileNode : public KernelObject { public: diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index 68513ab1c9..8f0fbdf9eb 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -822,7 +822,7 @@ void sceKernelCheckThreadStack() { u32 error; Thread *t = kernelObjects.Get(__KernelGetCurThread(), error); - u32 diff = (u32)abs((s64)t->stackBlock - (s64)currentMIPS->r[MIPS_REG_SP]); + u32 diff = abs((long)((s64)t->stackBlock - (s64)currentMIPS->r[MIPS_REG_SP])); ERROR_LOG(HLE, "%i=sceKernelCheckThreadStack()", diff); RETURN(diff); //Blatant lie } diff --git a/Core/MemMap.h b/Core/MemMap.h index 0e5fe2a20e..d264560e98 100644 --- a/Core/MemMap.h +++ b/Core/MemMap.h @@ -36,6 +36,10 @@ #if defined(_DEBUG) //#define SAFE_MEMORY #endif +// Required for UNUSABLE_MMAP. Can define this in cmake instead later +#ifdef __SYMBIAN32__ +#define SAFE_MEMORY +#endif // Global declarations diff --git a/android/jni/MenuScreens.cpp b/android/jni/MenuScreens.cpp index 2bacdd2310..6cdbd87488 100644 --- a/android/jni/MenuScreens.cpp +++ b/android/jni/MenuScreens.cpp @@ -387,8 +387,10 @@ static const char *credits[] = "Free tools used:", #ifdef ANDROID "Android SDK + NDK", -#elif BLACKBERRY +#elif defined(BLACKBERRY) "Blackberry NDK", +#elif defined(__SYMBIAN32__) + "Qt", #else "SDL", #endif diff --git a/android/jni/NativeApp.cpp b/android/jni/NativeApp.cpp index 14daeeecf6..6f0ae119e7 100644 --- a/android/jni/NativeApp.cpp +++ b/android/jni/NativeApp.cpp @@ -209,7 +209,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_directory, co g_Config.Load(config_filename.c_str()); if (g_Config.currentDirectory == "") { -#if defined(ANDROID) || defined(BLACKBERRY) +#if defined(ANDROID) || defined(BLACKBERRY) || defined(__SYMBIAN32__) g_Config.currentDirectory = external_directory; #else g_Config.currentDirectory = getenv("HOME");