Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous portability fixes #7772

Merged
merged 19 commits into from
May 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ if(CMAKE_SYSTEM_PROCESSOR)
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^armv7")
set(ARMV7 ON)
endif()
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^x86" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "i.86")
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^x86" OR
${CMAKE_SYSTEM_PROCESSOR} MATCHES "^amd64" OR
${CMAKE_SYSTEM_PROCESSOR} MATCHES "i.86")
set(X86 ON)
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^mips")
set(MIPS ON)
Expand Down Expand Up @@ -250,7 +252,7 @@ if(NOT MSVC)
if (NOT CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_definitions(-Wno-psabi)
endif()
add_definitions(-D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED -D__BSD_VISIBLE=1)
add_definitions(-D_XOPEN_SOURCE=700 -D_XOPEN_SOURCE_EXTENDED -D__BSD_VISIBLE=1)
add_definitions(-D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
Expand Down
12 changes: 1 addition & 11 deletions Common/CPUDetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,7 @@ static unsigned long long _xgetbv(unsigned int index)
#define _XCR_XFEATURE_ENABLED_MASK 0
#endif

#if defined __FreeBSD__
#include <sys/types.h>
#include <machine/cpufunc.h>

void do_cpuidex(u32 regs[4], u32 cpuid_leaf, u32 ecxval) {
__cpuidex((int *)regs, cpuid_leaf, ecxval);
}
void do_cpuid(u32 regs[4], u32 cpuid_leaf) {
__cpuid((int *)regs, cpuid_leaf);
}
#elif !defined(MIPS)
#if !defined(MIPS)

void do_cpuidex(u32 regs[4], u32 cpuid_leaf, u32 ecxval) {
#if defined(__i386__) && defined(__PIC__)
Expand Down
4 changes: 4 additions & 0 deletions Common/ColorConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include <xmmintrin.h>
#endif

#if _M_SSE >= 0x401
#include <smmintrin.h>
#endif

inline u16 RGBA8888toRGB565(u32 px) {
return ((px >> 3) & 0x001F) | ((px >> 5) & 0x07E0) | ((px >> 8) & 0xF800);
}
Expand Down
17 changes: 16 additions & 1 deletion Common/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
#include <stdlib.h>
#endif

#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#include <sys/sysctl.h> // KERN_PROC_PATHNAME
#include <unistd.h> // getpid
#endif

#if defined(__APPLE__)
#include <CoreFoundation/CFString.h>
#include <CoreFoundation/CFURL.h>
Expand Down Expand Up @@ -703,14 +708,24 @@ const std::string &GetExeDirectory()
ExePath = program_path;
#endif

#elif (defined(__APPLE__) && !defined(IOS)) || defined(__linux__)
#elif (defined(__APPLE__) && !defined(IOS)) || defined(__linux__) || defined(KERN_PROC_PATHNAME)
char program_path[4096];
uint32_t program_path_size = sizeof(program_path) - 1;

#if defined(__linux__)
if (readlink("/proc/self/exe", program_path, 4095) > 0)
#elif defined(__APPLE__) && !defined(IOS)
if (_NSGetExecutablePath(program_path, &program_path_size) == 0)
#elif defined(KERN_PROC_PATHNAME)
int mib[4] = {
CTL_KERN,
KERN_PROC,
KERN_PROC_PATHNAME,
getpid()
};
size_t sz = program_path_size;

if (sysctl(mib, 4, program_path, &sz, NULL, 0) == 0)
#else
#error Unmatched ifdef.
#endif
Expand Down
2 changes: 1 addition & 1 deletion Common/MemArena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void *MemArena::CreateView(s64 offset, size_t size, void *base)
// Do not sync memory to underlying file. Linux has this by default.
#ifdef BLACKBERRY
MAP_NOSYNCFILE |
#elif defined(__FreeBSD__)
#elif defined(__DragonFly__) || defined(__FreeBSD__)
MAP_NOSYNC |
#endif
((base == 0) ? 0 : MAP_FIXED), fd, offset);
Expand Down
2 changes: 1 addition & 1 deletion Common/MemoryUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void* AllocateExecutableMemory(size_t size, bool exec)
// printf("Mapped executable memory at %p (size %ld)\n", ptr,
// (unsigned long)size);

#if defined(__FreeBSD__)
#if !defined(_WIN32) && !defined(__SYMBIAN32__)
if (ptr == MAP_FAILED)
{
ptr = NULL;
Expand Down
3 changes: 2 additions & 1 deletion Common/StdMutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#define GCC_VERSION GCC_VER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)

// Note: __MAC_10_7 is defined on 10.7+.
#if (GCC_VERSION >= GCC_VER(4,4,0) && __GXX_EXPERIMENTAL_CXX0X__ || defined(__APPLE__)) \
#if (__cplusplus >= 201103L || defined(__APPLE__) \
|| (GCC_VERSION >= GCC_VER(4,4,0) && __GXX_EXPERIMENTAL_CXX0X__)) \
/* GCC 4.4 provides <mutex>, except on these platforms: */ \
&& !defined(ANDROID) && !defined(__SYMBIAN32__) && !defined(MACGNUSTD)
#include <mutex>
Expand Down
9 changes: 9 additions & 0 deletions Common/Swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ inline unsigned long long bswap64(unsigned long long x) { return __loaddoublewor
inline unsigned int bswap32(unsigned int x) { return __loadwordbytereverse(0, &x); }
inline unsigned short bswap16(unsigned short x) { return __loadshortbytereverse(0, &x); }
#endif
#elif defined(__DragonFly__) || defined(__FreeBSD__) || \
defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/endian.h>
# ifdef __OpenBSD__
#define bswap16 swap16
#define bswap32 swap32
#define bswap64 swap64
#define
# endif
#else
// TODO: speedup
inline unsigned short bswap16(unsigned short x) { return (x << 8) | (x >> 8); }
Expand Down
3 changes: 0 additions & 3 deletions Core/FileSystems/tlzrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if !defined(__SYMBIAN32__) && !defined(__MAC_10_6)
#include <malloc.h>
#endif

#include "Common.h"

Expand Down
2 changes: 2 additions & 0 deletions Core/HLE/ReplaceTables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,8 @@ static int Hook_youkosohitsujimura_download_frame() {
#define JITFUNC(f) (&MIPSComp::Jit::f)
#elif defined(MIPS)
#define JITFUNC(f) (&MIPSComp::Jit::f)
#else
#define JITFUNC(f) (&MIPSComp::FakeJit::f)
#endif

// Can either replace with C functions or functions emitted in Asm/ArmAsm.
Expand Down
48 changes: 20 additions & 28 deletions Core/HLE/sceRtc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,16 +459,14 @@ static int sceRtcConvertLocalTimeToUTC(u32 tickLocalPtr,u32 tickUTCPtr)
{
u64 srcTick = Memory::Read_U64(tickLocalPtr);
// TODO : Let the user select his timezone / daylight saving instead of taking system param ?
#if defined(__GLIBC__) || defined(BLACKBERRY) || defined(__SYMBIAN32__)
time_t timezone = 0;
tm *time = localtime(&timezone);
srcTick -= time->tm_gmtoff*1000000ULL;
#elif defined(_MSC_VER)
#ifdef _MSC_VER
long timezone_val;
_get_timezone(&timezone_val);
srcTick -= -timezone_val * 1000000ULL;
#else
srcTick -= -timezone * 1000000ULL;
#elif !defined(_AIX) && !defined(__sgi) && !defined(__hpux)
time_t timezone = 0;
tm *time = localtime(&timezone);
srcTick -= time->tm_gmtoff*1000000ULL;
#endif
Memory::Write_U64(srcTick, tickUTCPtr);
}
Expand All @@ -486,16 +484,14 @@ static int sceRtcConvertUtcToLocalTime(u32 tickUTCPtr,u32 tickLocalPtr)
{
u64 srcTick = Memory::Read_U64(tickUTCPtr);
// TODO : Let the user select his timezone / daylight saving instead of taking system param ?
#if defined(__GLIBC__) || defined(BLACKBERRY) || defined(__SYMBIAN32__)
time_t timezone = 0;
tm *time = localtime(&timezone);
srcTick += time->tm_gmtoff*1000000ULL;
#elif defined(_MSC_VER)
#ifdef _MSC_VER
long timezone_val;
_get_timezone(&timezone_val);
srcTick += -timezone_val * 1000000ULL;
#else
srcTick += -timezone * 1000000ULL;
#elif !defined(_AIX) && !defined(__sgi) && !defined(__hpux)
time_t timezone = 0;
tm *time = localtime(&timezone);
srcTick += time->tm_gmtoff*1000000ULL;
#endif
Memory::Write_U64(srcTick, tickLocalPtr);
}
Expand Down Expand Up @@ -1023,16 +1019,14 @@ static int sceRtcFormatRFC2822LocalTime(u32 outPtr, u32 srcTickPtr)
}

int tz_seconds;
#if defined(__GLIBC__) || defined(BLACKBERRY) || defined(__SYMBIAN32__)
time_t timezone = 0;
tm *time = localtime(&timezone);
tz_seconds = time->tm_gmtoff;
#elif defined(_MSC_VER)
#ifdef _MSC_VER
long timezone_val;
_get_timezone(&timezone_val);
tz_seconds = -timezone_val;
#else
tz_seconds = -timezone;
#elif !defined(_AIX) && !defined(__sgi) && !defined(__hpux)
time_t timezone = 0;
tm *time = localtime(&timezone);
tz_seconds = time->tm_gmtoff;
#endif

DEBUG_LOG(SCERTC, "sceRtcFormatRFC2822LocalTime(%08x, %08x)", outPtr, srcTickPtr);
Expand Down Expand Up @@ -1062,16 +1056,14 @@ static int sceRtcFormatRFC3339LocalTime(u32 outPtr, u32 srcTickPtr)
}

int tz_seconds;
#if defined(__GLIBC__) || defined(BLACKBERRY) || defined(__SYMBIAN32__)
time_t timezone = 0;
tm *time = localtime(&timezone);
tz_seconds = time->tm_gmtoff;
#elif defined(_MSC_VER)
#ifdef _MSC_VER
long timezone_val;
_get_timezone(&timezone_val);
tz_seconds = -timezone_val;
#else
tz_seconds = -timezone;
#elif !defined(_AIX) && !defined(__sgi) && !defined(__hpux)
time_t timezone = 0;
tm *time = localtime(&timezone);
tz_seconds = time->tm_gmtoff;
#endif

DEBUG_LOG(SCERTC, "sceRtcFormatRFC3339LocalTime(%08x, %08x)", outPtr, srcTickPtr);
Expand Down
6 changes: 4 additions & 2 deletions Core/MIPS/JitCommon/JitCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ namespace MIPSComp {
ArmJit *jit;
#elif defined(ARM64)
Arm64Jit *jit;
#else
#elif defined(_M_IX86) || defined(_M_X64) || defined(MIPS)
Jit *jit;
#else
FakeJit *jit;
#endif
void JitAt() {
jit->Compile(currentMIPS->pc);
Expand Down Expand Up @@ -138,7 +140,7 @@ std::vector<std::string> DisassembleArm64(const u8 *data, int size) {
}
#endif

#if !defined(ARM) && !defined(ARM64)
#if defined(_M_IX86) || defined(_M_X64)

const char *ppsspp_resolver(struct ud*,
uint64_t addr,
Expand Down
2 changes: 1 addition & 1 deletion Core/MIPS/fake/FakeJit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void FakeJit::RunLoopUntil(u64 globalticks)
((void (*)())enterCode)();
}

const u8 *FakeJit::DoFakeJit(u32 em_address, FakeJitBlock *b)
const u8 *FakeJit::DoJit(u32 em_address, JitBlock *b)
{
return b->normalEntry;
}
Expand Down
2 changes: 1 addition & 1 deletion Core/MemMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ static bool Memory_TryBase(u32 flags) {
if (!*view.out_ptr_low)
goto bail;
}
#if defined(_M_X64) || defined(ARM64)
#if defined(_ARCH_64)
*view.out_ptr = (u8*)g_arena.CreateView(
position, view.size, base + view.virtual_address);
#else
Expand Down
12 changes: 10 additions & 2 deletions Core/Reporting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ namespace Reporting
return "Mac";
#elif defined(__SYMBIAN32__)
return "Symbian";
#elif defined(__FreeBSD__)
return "BSD";
#elif defined(BLACKBERRY)
return "Blackberry";
#elif defined(LOONGSON)
Expand All @@ -199,6 +197,16 @@ namespace Reporting
return "Nokia Maemo";
#elif defined(__linux__)
return "Linux";
#elif defined(__Bitrig__)
return "Bitrig";
#elif defined(__DragonFly__)
return "DragonFly";
#elif defined(__FreeBSD__)
return "FreeBSD";
#elif defined(__NetBSD__)
return "NetBSD";
#elif defined(__OpenBSD__)
return "OpenBSD";
#else
return "Unknown";
#endif
Expand Down
4 changes: 2 additions & 2 deletions GPU/Common/TextureScalerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
#include "Common/CPUDetect.h"
#include "ext/xbrz/xbrz.h"

#if _M_SSE >= 0x402
#include <nmmintrin.h>
#if _M_SSE >= 0x401
#include <smmintrin.h>
#endif

// Report the time and throughput for each larger scaling operation in the log
Expand Down
2 changes: 1 addition & 1 deletion Qt/PPSSPP.pro
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ mobile_platform {
INCLUDEPATH += $$P/Qt $$P/Qt/Debugger

# Creating translations should be done by Qt, really
LREL_TOOL = lrelease
isEmpty(LREL_TOOL): LREL_TOOL = lrelease
# Grab all possible directories (win32/unix)
win32: PATHS = $$split($$(PATH), ;)
else: PATHS = $$split($$(PATH), :)
Expand Down
3 changes: 2 additions & 1 deletion Qt/Platform/linux.pri
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
}

# Executable
LIBS += -ldl -lrt
LIBS += $$QMAKE_LIBS_DYNLOAD # dlopen
linux-*|hpux-*|solaris-*: LIBS += -lrt # clock_gettime

# Packaging
icon16.files = $$P/assets/unix-icons/hicolor/16x16/apps/ppsspp.png
Expand Down
3 changes: 2 additions & 1 deletion Qt/Settings.pri
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ RCC_DIR = $$CONFIG_DIR/.rcc/$$TARGET
QMAKE_CLEAN += -r $$OBJECTS_DIR $$MOC_DIR $$UI_DIR $$RCC_DIR

P = $$_PRO_FILE_PWD_/..
INCLUDEPATH += $$P/ext/zlib $$P/Common
INCLUDEPATH += $$P/Common
win32|contains(QT_CONFIG, no-zlib): INCLUDEPATH += $$P/ext/zlib

# Work out arch name
include(Platform/ArchDetection.pri)
Expand Down
10 changes: 5 additions & 5 deletions UI/CwCheatScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void CwCheatScreen::CreateViews() {
leftColumn->Add(new Choice(d->T("Back")))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
//leftColumn->Add(new Choice(k->T("Add Cheat")))->OnClick.Handle(this, &CwCheatScreen::OnAddCheat);
leftColumn->Add(new Choice(k->T("Import Cheats")))->OnClick.Handle(this, &CwCheatScreen::OnImportCheat);
#if defined(_WIN32) || defined(__APPLE__) || defined(__linux__)
#if !defined(MOBILE_DEVICE)
leftColumn->Add(new Choice(k->T("Edit Cheat File")))->OnClick.Handle(this, &CwCheatScreen::OnEditCheatFile);
#endif
leftColumn->Add(new Choice(k->T("Enable/Disable All")))->OnClick.Handle(this, &CwCheatScreen::OnEnableAll);
Expand Down Expand Up @@ -180,11 +180,11 @@ UI::EventReturn CwCheatScreen::OnEditCheatFile(UI::EventParams &params) {
if (!retval) {
ERROR_LOG(COMMON, "Failed creating notepad process");
}
#elif defined(__APPLE__) || defined(__linux__)
#if defined(__linux__)
cheatFile = "xdg-open ";
#elif defined(__APPLE__)
#elif !defined(MOBILE_DEVICE)
#if defined(__APPLE__)
cheatFile = "open ";
#else
cheatFile = "xdg-open ";
#endif
cheatFile.append(activeCheatFile);
NOTICE_LOG(BOOT, "Launching %s", cheatFile.c_str());
Expand Down
4 changes: 3 additions & 1 deletion UI/DevScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,12 +622,14 @@ void JitCompareScreen::UpdateDisasm() {
std::vector<std::string> targetDis = DisassembleArm2(block->normalEntry, block->codeSize);
#elif defined(ARM64)
std::vector<std::string> targetDis = DisassembleArm64(block->normalEntry, block->codeSize);
#else
#elif defined(_M_IX86) || defined(_M_X64)
std::vector<std::string> targetDis = DisassembleX86(block->normalEntry, block->codeSize);
#endif
#if defined(ARM) || defined(ARM64) || defined(_M_IX86) || defined(_M_X64)
for (size_t i = 0; i < targetDis.size(); i++) {
rightDisasm_->Add(new TextView(targetDis[i]))->SetFocusable(true);
}
#endif

int numMips = leftDisasm_->GetNumSubviews();
int numHost = rightDisasm_->GetNumSubviews();
Expand Down
2 changes: 1 addition & 1 deletion UI/NativeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void NativeInit(int argc, const char *argv[],
#elif defined(BLACKBERRY) || defined(IOS)
// Packed assets are included in app
VFSRegister("", new DirectoryAssetReader(external_directory));
#elif defined(__APPLE__) || (defined(__linux__) && !defined(ANDROID))
#elif !defined(MOBILE_DEVICE) && !defined(_WIN32)
VFSRegister("", new DirectoryAssetReader((File::GetExeDirectory() + "assets/").c_str()));
VFSRegister("", new DirectoryAssetReader((File::GetExeDirectory()).c_str()));
VFSRegister("", new DirectoryAssetReader("/usr/share/ppsspp/assets/"));
Expand Down