Linux_Win32Wrapper.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <CryAssert.h>
  10. #include <dirent.h>
  11. #include <vector>
  12. #include <AzCore/std/string/string.h>
  13. /* Memory block identification */
  14. #define _FREE_BLOCK 0
  15. #define _NORMAL_BLOCK 1
  16. #define _CRT_BLOCK 2
  17. #define _IGNORE_BLOCK 3
  18. #define _CLIENT_BLOCK 4
  19. #define _MAX_BLOCKS 5
  20. typedef void* HMODULE;
  21. typedef struct _MEMORYSTATUS
  22. {
  23. DWORD dwLength;
  24. DWORD dwMemoryLoad;
  25. SIZE_T dwTotalPhys;
  26. SIZE_T dwAvailPhys;
  27. SIZE_T dwTotalPageFile;
  28. SIZE_T dwAvailPageFile;
  29. SIZE_T dwTotalVirtual;
  30. SIZE_T dwAvailVirtual;
  31. } MEMORYSTATUS, * LPMEMORYSTATUS;
  32. extern void GlobalMemoryStatus(LPMEMORYSTATUS lpmem);
  33. #if defined(PLATFORM_64BIT)
  34. # define MEMORY_ALLOCATION_ALIGNMENT 16
  35. #else
  36. # define MEMORY_ALLOCATION_ALIGNMENT 8
  37. #endif
  38. #define S_OK 0
  39. #define THREAD_PRIORITY_NORMAL 0
  40. #define THREAD_PRIORITY_IDLE 0
  41. #define THREAD_PRIORITY_LOWEST 0
  42. #define THREAD_PRIORITY_BELOW_NORMAL 0
  43. #define THREAD_PRIORITY_ABOVE_NORMAL 0
  44. #define THREAD_PRIORITY_HIGHEST 0
  45. #define THREAD_PRIORITY_TIME_CRITICAL 0
  46. #define MAX_COMPUTERNAME_LENGTH 15 // required by CryOnline module
  47. #if 0
  48. //for compatibility reason we got to create a class which actually contains an int rather than a void* and make sure it does not get mistreated
  49. template <class T, T U>
  50. //U is default type for invalid handle value, T the encapsulated handle type to be used instead of void* (as under windows and never linux)
  51. class CHandle
  52. {
  53. public:
  54. typedef T HandleType;
  55. typedef void* PointerType; //for compatibility reason to encapsulate a void* as an int
  56. static const HandleType sciInvalidHandleValue = U;
  57. CHandle(const CHandle<T, U>& cHandle)
  58. : m_Value(cHandle.m_Value){}
  59. CHandle(const HandleType cHandle = U)
  60. : m_Value(cHandle){}
  61. //CHandle(const PointerType cpHandle) : m_Value(reinterpret_cast<HandleType>(cpHandle)){}
  62. //CHandle(INVALID_HANDLE_VALUE_ENUM) : m_Value(U){}//to be able to use a common value for all InvalidHandle - types
  63. operator HandleType(){
  64. return m_Value;
  65. }
  66. bool operator!() const{return m_Value == sciInvalidHandleValue; }
  67. const CHandle& operator =(const CHandle& crHandle){m_Value = crHandle.m_Value; return *this; }
  68. const CHandle& operator =(const PointerType cpHandle){m_Value = reinterpret_cast<HandleType>(cpHandle); return *this; }
  69. const bool operator ==(const CHandle& crHandle) const{return m_Value == crHandle.m_Value; }
  70. const bool operator ==(const HandleType cHandle) const{return m_Value == cHandle; }
  71. //const bool operator ==(const PointerType cpHandle)const{return m_Value == reinterpret_cast<HandleType>(cpHandle);}
  72. const bool operator !=(const HandleType cHandle) const{return m_Value != cHandle; }
  73. const bool operator !=(const CHandle& crHandle) const{return m_Value != crHandle.m_Value; }
  74. //const bool operator !=(const PointerType cpHandle)const{return m_Value != reinterpret_cast<HandleType>(cpHandle);}
  75. const bool operator < (const CHandle& crHandle) const{return m_Value < crHandle.m_Value; }
  76. HandleType Handle() const{return m_Value; }
  77. private:
  78. HandleType m_Value; //the actual value, remember that file descriptors are ints under linux
  79. typedef void ReferenceType;//for compatibility reason to encapsulate a void* as an int
  80. //forbid these function which would actually not work on an int
  81. PointerType operator->();
  82. PointerType operator->() const;
  83. ReferenceType operator*();
  84. ReferenceType operator*() const;
  85. operator PointerType();
  86. };
  87. typedef CHandle<INT_PTR, (INT_PTR) 0> HANDLE;
  88. typedef HANDLE EVENT_HANDLE;
  89. typedef HANDLE THREAD_HANDLE;
  90. #define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1)
  91. #endif
  92. //#define __TIMESTAMP__ __DATE__" "__TIME__
  93. // stdlib.h stuff
  94. #define _MAX_DRIVE 3 // max. length of drive component
  95. #define _MAX_DIR 256 // max. length of path component
  96. #define _MAX_FNAME 256 // max. length of file name component
  97. #define _MAX_EXT 256 // max. length of extension component
  98. // fcntl.h
  99. #define _O_RDONLY 0x0000 /* open for reading only */
  100. #define _O_WRONLY 0x0001 /* open for writing only */
  101. #define _O_RDWR 0x0002 /* open for reading and writing */
  102. #define _O_APPEND 0x0008 /* writes done at eof */
  103. #define _O_CREAT 0x0100 /* create and open file */
  104. #define _O_TRUNC 0x0200 /* open and truncate */
  105. #define _O_EXCL 0x0400 /* open only if file doesn't already exist */
  106. #define _O_TEXT 0x4000 /* file mode is text (translated) */
  107. #define _O_BINARY 0x8000 /* file mode is binary (untranslated) */
  108. #define _O_RAW _O_BINARY
  109. #define _O_NOINHERIT 0x0080 /* child process doesn't inherit file */
  110. #define _O_TEMPORARY 0x0040 /* temporary file bit */
  111. #define _O_SHORT_LIVED 0x1000 /* temporary storage file, try not to flush */
  112. #define _O_SEQUENTIAL 0x0020 /* file access is primarily sequential */
  113. #define _O_RANDOM 0x0010 /* file access is primarily random */
  114. inline void MemoryBarrier() {
  115. __sync_synchronize();
  116. }
  117. // Memory barrier implementation taken from https://code.google.com/p/gperftools/
  118. //inline void MemoryBarrier() {
  119. // __asm__ __volatile__("mfence" : : : "memory");
  120. //}
  121. #if !defined(_CPU_SSE)
  122. typedef int64 __m128;
  123. #endif
  124. //////////////////////////////////////////////////////////////////////////
  125. // io.h stuff
  126. #if !defined(ANDROID)
  127. extern int errno;
  128. #endif
  129. typedef unsigned int _fsize_t;
  130. struct _OVERLAPPED;
  131. typedef _OVERLAPPED* LPOVERLAPPED;
  132. typedef void (* LPOVERLAPPED_COMPLETION_ROUTINE)(DWORD dwErrorCode, DWORD dwNumberOfBytesTransfered, struct _OVERLAPPED* lpOverlapped);
  133. typedef struct tagRECT
  134. {
  135. LONG left;
  136. LONG top;
  137. LONG right;
  138. LONG bottom;
  139. } RECT, * PRECT;
  140. typedef struct tagPOINT
  141. {
  142. LONG x;
  143. LONG y;
  144. } POINT, * PPOINT;
  145. #ifndef _FILETIME_
  146. #define _FILETIME_
  147. typedef struct _FILETIME
  148. {
  149. DWORD dwLowDateTime;
  150. DWORD dwHighDateTime;
  151. } FILETIME, * PFILETIME, * LPFILETIME;
  152. #endif
  153. typedef union _ULARGE_INTEGER
  154. {
  155. struct
  156. {
  157. DWORD LowPart;
  158. DWORD HighPart;
  159. };
  160. unsigned long long QuadPart;
  161. } ULARGE_INTEGER;
  162. typedef ULARGE_INTEGER* PULARGE_INTEGER;
  163. #ifdef __cplusplus
  164. inline LONG CompareFileTime(const FILETIME* lpFileTime1, const FILETIME* lpFileTime2)
  165. #else
  166. static LONG CompareFileTime(const FILETIME* lpFileTime1, const FILETIME* lpFileTime2)
  167. #endif
  168. {
  169. ULARGE_INTEGER u1, u2;
  170. memcpy(&u1, lpFileTime1, sizeof u1);
  171. memcpy(&u2, lpFileTime2, sizeof u2);
  172. if (u1.QuadPart < u2.QuadPart)
  173. {
  174. return -1;
  175. }
  176. else
  177. if (u1.QuadPart > u2.QuadPart)
  178. {
  179. return 1;
  180. }
  181. return 0;
  182. }
  183. typedef struct _SYSTEMTIME
  184. {
  185. WORD wYear;
  186. WORD wMonth;
  187. WORD wDayOfWeek;
  188. WORD wDay;
  189. WORD wHour;
  190. WORD wMinute;
  191. WORD wSecond;
  192. WORD wMilliseconds;
  193. } SYSTEMTIME, * PSYSTEMTIME, * LPSYSTEMTIME;
  194. typedef struct _TIME_FIELDS
  195. {
  196. short Year;
  197. short Month;
  198. short Day;
  199. short Hour;
  200. short Minute;
  201. short Second;
  202. short Milliseconds;
  203. short Weekday;
  204. } TIME_FIELDS, * PTIME_FIELDS;
  205. #define DAYSPERNORMALYEAR 365
  206. #define DAYSPERLEAPYEAR 366
  207. #define MONSPERYEAR 12
  208. inline void ZeroMemory(void* pPtr, int nSize)
  209. {
  210. memset(pPtr, 0, nSize);
  211. }
  212. inline BOOL InflateRect(RECT* pRect, int dx, int dy)
  213. {
  214. pRect->left -= dx;
  215. pRect->right += dx;
  216. pRect->top -= dy;
  217. pRect->bottom += dy;
  218. return TRUE;
  219. }
  220. //////////////////////////////////////////////////////////////////////////
  221. extern BOOL SystemTimeToFileTime(const SYSTEMTIME* syst, LPFILETIME ft);
  222. //Win32API function declarations actually used
  223. extern bool IsBadReadPtr(void* ptr, unsigned int size);
  224. // Defined in the launcher.
  225. AZ_DLL_IMPORT void OutputDebugString(const char*);
  226. AZ_DLL_IMPORT void DebugBreak();
  227. /*
  228. //critical section stuff
  229. #define pthread_attr_default NULL
  230. typedef pthread_mutex_t CRITICAL_SECTION;
  231. #ifdef __cplusplus
  232. inline void InitializeCriticalSection(CRITICAL_SECTION *lpCriticalSection)
  233. {
  234. pthread_mutexattr_t pthread_mutexattr_def;
  235. pthread_mutexattr_settype(&pthread_mutexattr_def, PTHREAD_MUTEX_RECURSIVE_NP);
  236. pthread_mutex_init(lpCriticalSection, &pthread_mutexattr_def);
  237. }
  238. inline void EnterCriticalSection(CRITICAL_SECTION *lpCriticalSection){pthread_mutex_lock(lpCriticalSection);}
  239. inline void LeaveCriticalSection(CRITICAL_SECTION *lpCriticalSection){pthread_mutex_unlock(lpCriticalSection);}
  240. inline void DeleteCriticalSection(CRITICAL_SECTION *lpCriticalSection){}
  241. #else
  242. static void InitializeCriticalSection(CRITICAL_SECTION *lpCriticalSection)
  243. {
  244. pthread_mutexattr_t pthread_mutexattr_def;
  245. pthread_mutexattr_settype(&pthread_mutexattr_def, PTHREAD_MUTEX_RECURSIVE_NP);
  246. pthread_mutex_init(lpCriticalSection, &pthread_mutexattr_def);
  247. }
  248. static void EnterCriticalSection(CRITICAL_SECTION *lpCriticalSection){pthread_mutex_lock(lpCriticalSection);}
  249. static void LeaveCriticalSection(CRITICAL_SECTION *lpCriticalSection){pthread_mutex_unlock(lpCriticalSection);}
  250. static void DeleteCriticalSection(CRITICAL_SECTION *lpCriticalSection){}
  251. #endif
  252. */
  253. extern bool QueryPerformanceCounter(LARGE_INTEGER* counter);
  254. extern bool QueryPerformanceFrequency(LARGE_INTEGER* frequency);
  255. #ifdef __cplusplus
  256. inline uint32 GetTickCount()
  257. {
  258. LARGE_INTEGER count, freq;
  259. QueryPerformanceCounter(&count);
  260. QueryPerformanceFrequency(&freq);
  261. return uint32(count.QuadPart * 1000 / freq.QuadPart);
  262. }
  263. #define IGNORE 0 // Ignore signal
  264. #define INFINITE 0xFFFFFFFF // Infinite timeout
  265. #endif
  266. //begin--------------------------------findfirst/-next declaration/implementation----------------------------------------------------
  267. //////////////////////////////////////////////////////////////////////////
  268. // function renaming
  269. #define _TRUNCATE (size_t(-1))
  270. #define _chmod chmod
  271. #define _snprintf snprintf
  272. #define stricmp strcasecmp
  273. #define _stricmp strcasecmp
  274. #define strnicmp strncasecmp
  275. #define _strnicmp strncasecmp
  276. #define _strlwr strlwr
  277. #define _strlwr_s(BUF, SIZE) strlwr(BUF)
  278. #define _strups strupr
  279. extern BOOL GetUserName(LPSTR lpBuffer, LPDWORD nSize);
  280. //error code stuff
  281. //not thread specific, just a coarse implementation for the main thread
  282. inline DWORD GetLastError() { return errno; }
  283. inline void SetLastError(DWORD dwErrCode) { errno = dwErrCode; }
  284. //////////////////////////////////////////////////////////////////////////
  285. #define GENERIC_READ (0x80000000L)
  286. #define GENERIC_WRITE (0x40000000L)
  287. #define GENERIC_EXECUTE (0x20000000L)
  288. #define GENERIC_ALL (0x10000000L)
  289. #define CREATE_NEW 1
  290. #define CREATE_ALWAYS 2
  291. #define OPEN_EXISTING 3
  292. #define OPEN_ALWAYS 4
  293. #define TRUNCATE_EXISTING 5
  294. #define FILE_SHARE_READ 0x00000001
  295. #define FILE_SHARE_WRITE 0x00000002
  296. #define OPEN_EXISTING 3
  297. #define FILE_FLAG_OVERLAPPED 0x40000000
  298. #define INVALID_FILE_SIZE ((DWORD)0xFFFFFFFFl)
  299. #define FILE_BEGIN 0
  300. #define FILE_CURRENT 1
  301. #define FILE_END 2
  302. #define ERROR_NO_SYSTEM_RESOURCES 1450L
  303. #define ERROR_INVALID_USER_BUFFER 1784L
  304. #define ERROR_NOT_ENOUGH_MEMORY 8L
  305. #define ERROR_PATH_NOT_FOUND 3L
  306. #define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000
  307. //////////////////////////////////////////////////////////////////////////
  308. extern threadID GetCurrentThreadId();
  309. //////////////////////////////////////////////////////////////////////////
  310. extern DWORD Sleep(DWORD dwMilliseconds);
  311. //////////////////////////////////////////////////////////////////////////
  312. extern DWORD SleepEx(DWORD dwMilliseconds, BOOL bAlertable);
  313. extern BOOL GetComputerName(LPSTR lpBuffer, LPDWORD lpnSize); //required for CryOnline
  314. extern DWORD GetCurrentProcessId(void);
  315. //////////////////////////////////////////////////////////////////////////
  316. //////////////////////////////////////////////////////////////////////////
  317. #ifdef __cplusplus
  318. //helper function
  319. extern void adaptFilenameToLinux(char* rAdjustedFilename);
  320. extern void replaceDoublePathFilename(char* szFileName);//removes "\.\" to "\" and "/./" to "/"
  321. //////////////////////////////////////////////////////////////////////////
  322. extern void _makepath(char* path, const char* drive, const char* dir, const char* filename, const char* ext);
  323. template <size_t size>
  324. void _makepath_s(char(&path)[size], const char *drive, const char *dir, const char *fname, const char *ext)
  325. {
  326. _makepath(path, drive, dir, fname, ext);
  327. }
  328. extern void _splitpath(const char* inpath, char* drv, char* dir, char* fname, char* ext);
  329. template <size_t drivesize, size_t dirsize, size_t fnamesize, size_t extsize>
  330. void _splitpath_s(const char *path, char(&drive)[drivesize], char(&dir)[dirsize], char(&fname)[fnamesize], char(&ext)[extsize])
  331. {
  332. _splitpath(path, drive, dir, fname, ext);
  333. }
  334. //////////////////////////////////////////////////////////////////////////
  335. extern int memicmp(LPCSTR s1, LPCSTR s2, DWORD len);
  336. extern "C" char* strlwr (char* str);
  337. extern "C" char* strupr(char* str);
  338. extern char* _ui64toa(unsigned long long value, char* str, int radix);
  339. extern long long _atoi64(const char* str);
  340. extern int* _errno();
  341. template <size_t SIZE>
  342. int vsprintf_s(char (&dst)[SIZE], const char* format, va_list argptr)
  343. {
  344. vsnprintf(dst, SIZE, format, argptr);
  345. dst[SIZE - 1] = 0;
  346. return 0;
  347. }
  348. inline int vsprintf_s(char* dst, size_t size, const char* format, va_list argptr)
  349. {
  350. vsnprintf(dst, size, format, argptr);
  351. dst[size - 1] = 0;
  352. return 0;
  353. }
  354. //note that behaviour is different from strncpy.
  355. //this will not pad string with zeroes if length of src is less than 'size'
  356. inline int strncpy_s(char* dst, size_t buf_size, const char* src, size_t size)
  357. {
  358. size_t to_copy = std::min(size, strlen(src));
  359. size_t term = std::min(buf_size - 1, to_copy);//length of result
  360. strncpy(dst, src, term);
  361. dst[term] = 0;
  362. return 0;
  363. }
  364. template <size_t SIZE>
  365. inline int strncpy_s(char(&dst)[SIZE], const char* src, size_t size)
  366. {
  367. size_t to_copy = std::min(size, strlen(src));
  368. size_t term = std::min(SIZE - 1, to_copy);//length of result
  369. strncpy(dst, src, term);
  370. dst[term] = 0;
  371. return 0;
  372. }
  373. inline int strcat_s(char* dst, size_t size, const char* src)
  374. {
  375. if (!dst || !src)
  376. {
  377. return EINVAL;
  378. }
  379. size_t len_dst = strlen(dst);
  380. size_t len_src = strlen(src);
  381. if (size == 0 || len_dst + len_src + 1 >= size)
  382. {
  383. return ERANGE;
  384. }
  385. memcpy(dst + len_dst, src, len_src);
  386. dst[len_dst + len_src] = 0;
  387. return 0;
  388. }
  389. template <size_t SIZE>
  390. int strcat_s(char(&dst)[SIZE], const char* src)
  391. {
  392. return strcat_s(dst, SIZE, src);
  393. }
  394. template <size_t SIZE>
  395. int strcpy_s(char(&dst)[SIZE], const char* src)
  396. {
  397. strncpy(dst, src, SIZE);
  398. dst[SIZE - 1] = 0;
  399. return 0;
  400. }
  401. inline int strcpy_s(char* dst, size_t size, const char* src)
  402. {
  403. strncpy(dst, src, size);
  404. dst[size - 1] = 0;
  405. return 0;
  406. }
  407. inline int sprintf_s(char* buffer, size_t sizeOfBuffer, const char* format, ...)
  408. {
  409. va_list args;
  410. va_start(args, format);
  411. int err = vsnprintf(buffer, sizeOfBuffer, format, args);
  412. va_end(args);
  413. return err;
  414. }
  415. template <size_t size>
  416. int sprintf_s(char (&buffer)[size], const char* format, ...)
  417. {
  418. va_list args;
  419. va_start(args, format);
  420. int err = vsnprintf(buffer, size, format, args);
  421. va_end(args);
  422. return err;
  423. }
  424. #ifdef _isnan
  425. #undef _isnan
  426. template <typename T>
  427. bool _isnan(T value)
  428. {
  429. return value != value;
  430. }
  431. #endif
  432. #define vsnprintf_s(BUF, SIZE, COUNT, FORMAT, ARGVLIST) vsnprintf(BUF, SIZE, FORMAT, ARGVLIST)
  433. #define _vsnwprintf_s(BUF, SIZE, COUNT, FORMAT, ARGVLIST) vswprintf(BUF, SIZE, FORMAT, ARGVLIST)
  434. #define fprintf_s fprintf
  435. #define sscanf_s sscanf
  436. #define fread_s(BUF, SIZE, NMEMB, MAX, HANDLE) fread(BUF, SIZE, NMEMB, HANDLE)
  437. //////////////////////////////////////////////////////////////////////////
  438. #ifndef __TRLTOA__
  439. #define __TRLTOA__
  440. extern char* ltoa (long i, char* a, int radix);
  441. #endif
  442. #define itoa ltoa
  443. //////////////////////////////////////////////////////////////////////////
  444. #if 0
  445. inline long int abs(long int x)
  446. {
  447. return labs(x);
  448. }
  449. inline float abs(float x)
  450. {
  451. return fabsf(x);
  452. }
  453. inline double abs(double x)
  454. {
  455. return fabs(x);
  456. }
  457. inline float sqrt(float x)
  458. {
  459. return sqrtf(x);
  460. }
  461. #else
  462. #include <cmath>
  463. using std::abs;
  464. using std::sqrt;
  465. using std::fabs;
  466. #endif
  467. extern char* _strtime(char* date);
  468. extern char* _strdate(char* date);
  469. #if !defined(_CPU_SSE)
  470. #define _MM_HINT_T0 (1)
  471. #define _MM_HINT_T1 (2)
  472. #define _MM_HINT_T2 (3)
  473. #define _MM_HINT_NTA (0)
  474. inline void _mm_prefetch(const char*, int) { }
  475. #endif // !_CPU_SSE
  476. #endif //__cplusplus
  477. //////////////////////////////////////////////////////////////////////////
  478. // Byte Swapping functions
  479. inline unsigned short _byteswap_ushort(unsigned short input)
  480. {
  481. return ((input & 0xff) << 8) | ((input & 0xff00) >> 8);
  482. }
  483. inline LONG _byteswap_ulong(LONG input)
  484. {
  485. return (input & 0x000000ff) << 24 |
  486. (input & 0x0000ff00) << 8 |
  487. (input & 0x00ff0000) >> 8 |
  488. (input & 0xff000000) >> 24;
  489. }
  490. inline unsigned long long _byteswap_uint64(unsigned long long input)
  491. {
  492. return (((input & 0xff00000000000000ull) >> 56) |
  493. ((input & 0x00ff000000000000ull) >> 40) |
  494. ((input & 0x0000ff0000000000ull) >> 24) |
  495. ((input & 0x000000ff00000000ull) >> 8) |
  496. ((input & 0x00000000ff000000ull) << 8) |
  497. ((input & 0x0000000000ff0000ull) << 24) |
  498. ((input & 0x000000000000ff00ull) << 40) |
  499. ((input & 0x00000000000000ffull) << 56));
  500. }