Skip to content

Instantly share code, notes, and snippets.

@nilsding
Created August 31, 2015 15:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilsding/cdd387ea8d32846a0b4c to your computer and use it in GitHub Desktop.
Save nilsding/cdd387ea8d32846a0b4c to your computer and use it in GitHub Desktop.
--- src/arch/ArchHooks/ArchHooks.h.orig
+++ src/arch/ArchHooks/ArchHooks.h
@@ -1,6 +1,8 @@
#ifndef ARCH_HOOKS_H
#define ARCH_HOOKS_H
+#include <ctime>
+
struct lua_State;
class ArchHooks
{
--- ./src/archutils/Common/gcc_byte_swaps.h.orig 2015-08-31 15:27:15.488012447 +0200
+++ ./src/archutils/Common/gcc_byte_swaps.h 2015-08-31 15:47:43.516466547 +0200
@@ -5,34 +5,18 @@
#include <stdint.h>
-inline uint32_t ArchSwap32( uint32_t n )
-{
- asm(
- "xchg %b0, %h0\n"
- "rorl $16, %0\n"
- "xchg %b0, %h0":
- "=q" (n): "0" (n) );
- return n;
-}
-
-inline uint32_t ArchSwap24( uint32_t n )
-{
- asm(
- "xchg %b0, %h0\n"
- "rorl $16, %0\n"
- "xchg %b0, %h0\n"
- "shrl $8, %0\n":
- "=q" (n): "0" (n) );
- return n;
-}
-
-inline uint16_t ArchSwap16( uint16_t n )
-{
- asm(
- "xchg %b0, %h0\n":
- "=q" (n): "0" (n) );
- return n;
-}
+// taken from XNU's libkern/libkern/OSByteOrder.h
+#define ArchSwap32(n) \
+ ((uint32_t)((((uint32_t)(n) & 0xff000000) >> 24) | \
+ (((uint32_t)(n) & 0x00ff0000) >> 8) | \
+ (((uint32_t)(n) & 0x0000ff00) << 8) | \
+ (((uint32_t)(n) & 0x000000ff) << 24)))
+
+#define ArchSwap24(n) (ArchSwap32((n)) >> 8)
+
+#define ArchSwap16(n) \
+ ((uint16_t)((((uint16_t)(n) & 0xff00) >> 8) | \
+ (((uint16_t)(n) & 0x00ff) << 8)))
#define HAVE_BYTE_SWAPS
#endif
--- ./src/archutils/Unix/RunningUnderValgrind.cpp.orig 2015-08-31 15:54:18.428899357 +0200
+++ ./src/archutils/Unix/RunningUnderValgrind.cpp 2015-08-31 15:59:09.521879145 +0200
@@ -1,35 +1,10 @@
#include "global.h"
#include "RunningUnderValgrind.h"
-#if defined(CPU_X86) && defined(__GNUC__)
-bool RunningUnderValgrind()
-{
- /* Valgrind crashes and burns on pthread_mutex_timedlock. */
- static int under_valgrind = -1;
- if( under_valgrind == -1 )
- {
- unsigned int magic[8] = { 0x00001001, 0, 0, 0, 0, 0, 0, 0 };
- asm(
- "mov %1, %%eax\n"
- "mov $0, %%edx\n"
- "rol $29, %%eax\n"
- "rol $3, %%eax\n"
- "ror $27, %%eax\n"
- "ror $5, %%eax\n"
- "rol $13, %%eax\n"
- "rol $19, %%eax\n"
- "mov %%edx, %0\t"
- : "=r" (under_valgrind): "r" (magic): "eax", "edx" );
- }
-
- return under_valgrind != 0;
-}
-#else
bool RunningUnderValgrind()
{
return false;
}
-#endif
/*
* (c) 2004 Glenn Maynard
--- src/libtomcrypt/src/headers/tomcrypt_macros.h.orig 2012-08-06 07:23:37.000000000 +0200
+++ src/libtomcrypt/src/headers/tomcrypt_macros.h 2015-03-02 21:40:07.785177000 +0100
@@ -262,21 +262,19 @@
#ifndef LTC_NO_ROLC
-static inline __attribute__((always_inline)) unsigned ROLc(unsigned word, const int i)
-{
- asm ("roll %2,%0"
- :"=r" (word)
- :"0" (word),"I" (i));
- return word;
-}
-
-static inline __attribute__((always_inline)) unsigned RORc(unsigned word, const int i)
-{
- asm ("rorl %2,%0"
- :"=r" (word)
- :"0" (word),"I" (i));
- return word;
-}
+#define ROLc(word, i) ({ \
+ unsigned _word = word; \
+ asm ("roll %2,%0" \
+ :"=r" (_word) \
+ :"0" (_word),"I" (i)); \
+ _word; })
+
+#define RORc(word, i) ({ \
+ unsigned _word = word; \
+ asm ("rorl %2,%0" \
+ :"=r" (_word) \
+ :"0" (_word),"I" (i)); \
+ _word; })
#else
@@ -305,21 +303,19 @@
#ifndef LTC_NO_ROLC
-static inline __attribute__((always_inline)) unsigned ROLc(unsigned word, const int i)
-{
- asm ("rotlwi %0,%0,%2"
- :"=r" (word)
- :"0" (word),"I" (i));
- return word;
-}
-
-static inline __attribute__((always_inline)) unsigned RORc(unsigned word, const int i)
-{
- asm ("rotrwi %0,%0,%2"
- :"=r" (word)
- :"0" (word),"I" (i));
- return word;
-}
+#define ROLc(word, i) ({ \
+ unsigned _word = word; \
+ asm ("rotlwi %0,%0,%2" \
+ :"=r" (_word) \
+ :"0" (_word),"I" (i)); \
+ _word; })
+
+#define RORc(word, i) ({ \
+ unsigned _word = word; \
+ asm ("rotrwi %0,%0,%2" \
+ :"=r" (_word) \
+ :"0" (_word),"I" (i)); \
+ _word; })
#else
@@ -361,21 +357,19 @@
#ifndef LTC_NO_ROLC
-static inline __attribute__((always_inline)) unsigned long ROL64c(unsigned long word, const int i)
-{
- asm("rolq %2,%0"
- :"=r" (word)
- :"0" (word),"J" (i));
- return word;
-}
-
-static inline __attribute__((always_inline)) unsigned long ROR64c(unsigned long word, const int i)
-{
- asm("rorq %2,%0"
- :"=r" (word)
- :"0" (word),"J" (i));
- return word;
-}
+#define ROL64c(word, i) ({ \
+ unsigned long _word = word; \
+ asm ("rolq %2,%0" \
+ :"=r" (_word) \
+ :"0" (_word),"J" (i)); \
+ _word; })
+
+#define ROR64c(word, i) ({ \
+ unsigned long _word = word; \
+ asm ("rorq %2,%0" \
+ :"=r" (_word) \
+ :"0" (_word),"J" (i)); \
+ _word; })
#else /* LTC_NO_ROLC */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment