Something went wrong. Try again.
Cider Isn't Darwin Emulation, Really
Something went wrong. Try again.
5.5 kB · 334 lines
C++
at android
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335/*This file is part of Darling.
Copyright (C) 2013 Lubos Dolezel
Darling is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.
Darling is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.
You should have received a copy of the GNU General Public Licensealong with Darling. If not, see <http://www.gnu.org/licenses/>.*/
#include "CoreEndian.h"#include <stdint.h>#include <map>#include <TargetConditionals.h>#include "MacErrors.h"#include <mutex>
static std::map< std::pair<uint32_t,uint32_t>, std::pair<CEFlipper,void*> > g_flippers;static std::mutex g_flippersMutex;
template <typename T> T bswap(T value);
template <> uint16_t bswap(uint16_t value){ return __builtin_bswap16(value);}
template <> uint32_t bswap(uint32_t value){ return __builtin_bswap32(value);}
template <> uint64_t bswap(uint64_t value){ return __builtin_bswap64(value);}
template <> int16_t bswap(int16_t value){ return __builtin_bswap16(value);}
template <> int32_t bswap(int32_t value){ return __builtin_bswap32(value);}
template <> int64_t bswap(int64_t value){ return __builtin_bswap64(value);}
#ifdef __i386__template <> long bswap(long value){ return __builtin_bswap32(value);}
template <> unsigned long bswap(unsigned long value){ return __builtin_bswap32(value);}#endif
template <typename T> T LtoN(T value){#if TARGET_RT_LITTLE_ENDIAN return value;#else return bswap(value);#endif}
template <typename T> T BtoN(T value){#if TARGET_RT_BIG_ENDIAN return value;#else return bswap(value);#endif}
template <typename T> T NtoL(T value){ return LtoN(value);}
template <typename T> T NtoB(T value){ return BtoN(value);}
UInt16 Endian16_Swap(UInt16 value){ return bswap(value);}
UInt32 Endian32_Swap(UInt32 value){ return bswap(value);}
UInt64 Endian64_Swap(UInt64 value){ return bswap(value);}
SInt16 EndianS16_BtoL(SInt16 value){ return bswap(value);}
SInt16 EndianS16_BtoN(SInt16 value){ return BtoN(value);}
SInt16 EndianS16_LtoB(SInt16 value){ return bswap(value);}
SInt16 EndianS16_LtoN(SInt16 value){ return LtoN(value);}
SInt16 EndianS16_NtoB(SInt16 value){ return NtoB(value);}
SInt16 EndianS16_NtoL(SInt16 value){ return NtoL(value);}
SInt32 EndianS32_BtoL(SInt32 value){ return bswap(value);}
SInt32 EndianS32_BtoN(SInt32 value){ return BtoN(value);}
SInt32 EndianS32_LtoB(SInt32 value){ return bswap(value);}
SInt32 EndianS32_LtoN(SInt32 value){ return LtoN(value);}
SInt32 EndianS32_NtoB(SInt32 value){ return NtoB(value);}
SInt32 EndianS32_NtoL(SInt32 value){ return NtoL(value);}
SInt64 EndianS64_BtoL(SInt64 value){ return bswap(value);}
SInt64 EndianS64_BtoN(SInt64 value){ return BtoN(value);}
SInt64 EndianS64_LtoB(SInt64 value){ return bswap(value);}
SInt64 EndianS64_LtoN(SInt64 value){ return LtoN(value);}
SInt64 EndianS64_NtoB(SInt64 value){ return NtoB(value);}
SInt64 EndianS64_NtoL(SInt64 value){ return NtoL(value);}
UInt16 EndianU16_BtoL(UInt16 value){ return bswap(value);}
UInt16 EndianU16_BtoN(UInt16 value){ return BtoN(value);}
UInt16 EndianU16_LtoB(UInt16 value){ return bswap(value);}
UInt16 EndianU16_LtoN(UInt16 value){ return LtoN(value);}
UInt16 EndianU16_NtoB(UInt16 value){ return NtoB(value);}
UInt16 EndianU16_NtoL(UInt16 value){ return NtoL(value);}
UInt32 EndianU32_BtoL(UInt32 value){ return bswap(value);}
UInt32 EndianU32_BtoN(UInt32 value){ return BtoN(value);}
UInt32 EndianU32_LtoB(UInt32 value){ return bswap(value);}
UInt32 EndianU32_LtoN(UInt32 value){ return LtoN(value);}
UInt32 EndianU32_NtoB(UInt32 value){ return NtoB(value);}
UInt32 EndianU32_NtoL(UInt32 value){ return NtoL(value);}
UInt64 EndianU64_BtoL(UInt64 value){ return bswap(value);}
UInt64 EndianU64_BtoN(UInt64 value){ return BtoN(value);}
UInt64 EndianU64_LtoB(UInt64 value){ return bswap(value);}
UInt64 EndianU64_LtoN(UInt64 value){ return LtoN(value);}
UInt64 EndianU64_NtoB(UInt64 value){ return NtoB(value);}
UInt64 EndianU64_NtoL(UInt64 value){ return NtoL(value);}
OSStatus CoreEndianFlipData(uint32_t dataDomain, uint32_t dataType, int16_t id, void* data, unsigned long length, Boolean isNative){ std::lock_guard<std::mutex> l(g_flippersMutex); auto it = g_flippers.find(std::make_pair(dataDomain, dataType)); if (it == g_flippers.end()) return handlerNotFoundErr; return it->second.first(dataDomain, dataType, id, data, length, isNative, it->second.second);}
OSStatus CoreEndianInstallFlipper(uint32_t dataDomain, uint32_t dataType, CEFlipper flipper, void* opaque){ std::lock_guard<std::mutex> l(g_flippersMutex); g_flippers[std::make_pair(dataDomain, dataType)] = std::make_pair(flipper, opaque); return noErr;}
OSStatus CoreEndianGetFlipper(uint32_t dataDomain, uint32_t dataType, CEFlipper* flipper, void** opaque){ std::lock_guard<std::mutex> l(g_flippersMutex); auto it = g_flippers.find(std::make_pair(dataDomain, dataType)); *opaque = nullptr; *flipper = nullptr; if (it == g_flippers.end()) return paramErr; *flipper = it->second.first; *opaque = it->second.second; return noErr;}