diff --git a/.travis.yml b/.travis.yml index 74678d9..f6807fd 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,17 @@ 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++; brew update; brew install lz4; fi + + + +script: make LD=$Ld CC=$CC + 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; 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 { 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 {