From 17dbc5b542d7e77b262dfa192dab56ea7186700e Mon Sep 17 00:00:00 2001 From: Caden Kline Date: Sun, 22 Oct 2017 14:16:00 -0400 Subject: [PATCH 1/5] travis osx https://github.com/reswitched/Mephisto/issues/9 --- .travis.yml | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 74678d9..aeb83a0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,14 @@ -dist: trusty -sudo: required language: c++ +matrix: + include: + - os: linux + dist: trusty + sudo: required + - os: osx + osx_image: xcode9.1 + compiler: clang + + addons: apt: @@ -14,10 +22,15 @@ addons: - lld-5.0 - liblz4-dev install: - - sudo pip2 install -r requirements.txt + - pip2 install --user -r requirements.txt - git clone https://github.com/reswitched/unicorn.git - cd unicorn - UNICORN_ARCHS="aarch64" ./make.sh - sudo ./make.sh install - cd .. -script: make LD=ld.lld-5.0 + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then CC=clang++-5.0; Ld=ld.lld-5.0; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then CC=clang++; fi + + +script: make LD=$Ld CC=$CC + From b1007d44f5b6c85a682caed827fc0408ad15cf4b Mon Sep 17 00:00:00 2001 From: vgmoose Date: Tue, 14 Nov 2017 20:42:20 -0500 Subject: [PATCH 2/5] use different printf format on macos --- Cpu.cpp | 2 +- Ctu.h | 9 +++++++-- GdbStub.cpp | 8 ++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Cpu.cpp b/Cpu.cpp index cb6e99d..680f00a 100644 --- a/Cpu.cpp +++ b/Cpu.cpp @@ -37,7 +37,7 @@ void mmioHook(uc_engine *uc, uc_mem_type type, gptr address, uint32_t size, gptr break; case UC_MEM_WRITE: - LOG_DEBUG(Cpu, "MMIO Write at " ADDRFMT " size %x data %lx", physicalAddress, size, value); + LOG_DEBUG(Cpu, "MMIO Write at " ADDRFMT " size %x data " LONGFMT, physicalAddress, size, value); mmio->write(physicalAddress, size, value); break; } diff --git a/Ctu.h b/Ctu.h index 01e721e..cb23915 100644 --- a/Ctu.h +++ b/Ctu.h @@ -47,8 +47,13 @@ const gptr TERMADDR = 1ULL << 61; #define FOURCC(a, b, c, d) (((d) << 24) | ((c) << 16) | ((b) << 8) | (a)) -#define ADDRFMT "%016lx" -#define LONGFMT "%lx" +#ifdef __APPLE__ + #define ADDRFMT "%016llx" + #define LONGFMT "%llx" +#else + #define ADDRFMT "%016lx" + #define LONGFMT "%lx" +#endif enum LogLevel { None = 0, diff --git a/GdbStub.cpp b/GdbStub.cpp index 91177f0..7a01c84 100644 --- a/GdbStub.cpp +++ b/GdbStub.cpp @@ -243,7 +243,7 @@ void GdbStub::removeBreakpoint(BreakpointType type, gptr addr) { auto bp = p.find(addr); if(bp != p.end()) { - LOG_DEBUG(GdbStub, "gdb: removed a breakpoint: %016lx bytes at %016lx of type %d", + LOG_DEBUG(GdbStub, "gdb: removed a breakpoint: " ADDRFMT " bytes at " ADDRFMT " of type %d", bp->second.len, bp->second.addr, type); ctu->cpu.removeBreakpoint(bp->second.hook); p.erase(addr); @@ -275,7 +275,7 @@ bool GdbStub::checkBreakpoint(gptr addr, BreakpointType type) { if(bp->second.active && (addr >= bp->second.addr && addr < bp->second.addr + len)) { LOG_DEBUG(GdbStub, - "Found breakpoint type %d @ %016lx, range: %016lx - %016lx (%d bytes)", type, + "Found breakpoint type %d @ " ADDRFMT ", range: " ADDRFMT " - " ADDRFMT " (%d bytes)", type, addr, bp->second.addr, bp->second.addr + len, (uint32_t) len); return true; } @@ -508,7 +508,7 @@ void GdbStub::readMemory() { start_offset = addr_pos + 1; auto len = hexToInt(start_offset, static_cast((commandBuffer + commandLength) - start_offset)); - LOG_DEBUG(GdbStub, "gdb: addr: %016lx len: %016lx", addr, len); + LOG_DEBUG(GdbStub, "gdb: addr: " ADDRFMT " len: " ADDRFMT, addr, len); if(len * 2 > sizeof(reply)) { sendReply("E01"); @@ -580,7 +580,7 @@ bool GdbStub::commitBreakpoint(BreakpointType type, gptr addr, uint32_t len) { p.insert({addr, breakpoint}); - LOG_DEBUG(GdbStub, "gdb: added %d breakpoint: %016lx bytes at %016lx", type, breakpoint.len, + LOG_DEBUG(GdbStub, "gdb: added %d breakpoint: " ADDRFMT " bytes at " ADDRFMT, type, breakpoint.len, breakpoint.addr); return true; From 76d620665d732c1a8d833c5eee20cb2418c01e77 Mon Sep 17 00:00:00 2001 From: vgmoose Date: Tue, 14 Nov 2017 21:01:52 -0500 Subject: [PATCH 3/5] add lz4 to travis.yml for macos --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index aeb83a0..b5784f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ install: - sudo ./make.sh install - cd .. - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then CC=clang++-5.0; Ld=ld.lld-5.0; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then CC=clang++; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then CC=clang++; brew update; brew install lz4; fi script: make LD=$Ld CC=$CC From 2f5d0555400e5604e2d4e3cb2413ad90799c414f Mon Sep 17 00:00:00 2001 From: vgmoose Date: Tue, 14 Nov 2017 22:37:04 -0500 Subject: [PATCH 4/5] remove unused byteswap.h include (per 1955569) --- ipcimpl/lm.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/ipcimpl/lm.cpp b/ipcimpl/lm.cpp index 279452b..7f70516 100644 --- a/ipcimpl/lm.cpp +++ b/ipcimpl/lm.cpp @@ -1,5 +1,4 @@ #include "Ctu.h" -#include /*$IPC$ partial nn::lm::ILogger { From 1f891f27a92400a9b8e6ae511c7b9728dcda32ce Mon Sep 17 00:00:00 2001 From: vgmoose Date: Wed, 22 Nov 2017 21:40:42 -0500 Subject: [PATCH 5/5] passthrough htons/ntohs values on macos for sa_family --- ipcimpl/bsd.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/ipcimpl/bsd.cpp b/ipcimpl/bsd.cpp index 4720d47..a30326c 100644 --- a/ipcimpl/bsd.cpp +++ b/ipcimpl/bsd.cpp @@ -14,6 +14,15 @@ } */ +#ifdef __APPLE__ +#define fam_ntohs passthru_uint8 +#define fam_htons passthru_uint8 +__uint8_t passthru_uint8(__uint8_t a) { return a; } +#else +#define fam_htons htons +#define fam_ntohs ntohs +#endif + nn::socket::sf::IClient::IClient(Ctu *_ctu) : IpcService(_ctu) { passthrough = _ctu->socketsEnabled; } @@ -26,7 +35,7 @@ uint32_t nn::socket::sf::IClient::Accept(IN uint32_t socket, OUT int32_t& ret, O ret = ::accept(socket, addr, &size); bsd_errno = errno; sockaddr_len = size; - addr->sa_family = htons(addr->sa_family); + addr->sa_family = fam_htons(addr->sa_family); } else { ret = 888; bsd_errno = 0; @@ -37,7 +46,7 @@ uint32_t nn::socket::sf::IClient::Bind(IN uint32_t socket, IN sockaddr * _1, gui LOG_DEBUG(IpcStubs, "Stub implementation for nn::socket::sf::IClient::bind"); if(passthrough) { struct sockaddr *addr = (struct sockaddr *) _1; - addr->sa_family = ntohs(addr->sa_family); + addr->sa_family = fam_ntohs(addr->sa_family); ret = ::bind(socket, addr, (uint32_t) _1_size); bsd_errno = errno; } else { @@ -61,7 +70,7 @@ uint32_t nn::socket::sf::IClient::Connect(IN uint32_t socket, IN sockaddr * _1, LOG_DEBUG(IpcStubs, "Stub implementation for nn::socket::sf::IClient::connect"); if(passthrough) { struct sockaddr *addr = (struct sockaddr *) _1; - addr->sa_family = ntohs(addr->sa_family); // yes, this is network byte order on the switch and host byte order on linux + addr->sa_family = fam_ntohs(addr->sa_family); // yes, this is network byte order on the switch and host byte order on linux ret = ::connect(socket, (struct sockaddr *) addr, (socklen_t) _1_size); bsd_errno = errno; } else { @@ -78,7 +87,7 @@ uint32_t nn::socket::sf::IClient::GetSockName(IN uint32_t socket, OUT int32_t& r ret = ::getsockname(socket, addr, &addr_len); errno = bsd_errno; sockaddr_len = addr_len; - addr->sa_family = htons(addr->sa_family); + addr->sa_family = fam_htons(addr->sa_family); } else { sockaddr_len = 0; ret = 0; @@ -123,7 +132,7 @@ uint32_t nn::socket::sf::IClient::SendTo(IN uint32_t socket, IN uint32_t flags, LOG_DEBUG(IpcStubs, "Stub implementation for nn::socket::sf::IClient::sendto"); if(passthrough) { struct sockaddr *addr = (struct sockaddr *) _3; - addr->sa_family = ntohs(addr->sa_family); + addr->sa_family = fam_ntohs(addr->sa_family); ret = (uint32_t) ::sendto(socket, _2, (size_t) _2_size, flags, (struct sockaddr *) addr, (socklen_t) _3_size); bsd_errno = errno; } else {