Merge.
Merge.
1.1 --- a/core-legacy/sourcehook/sh_list.h Mon Dec 22 22:55:55 2008 -0600
1.2 +++ b/core-legacy/sourcehook/sh_list.h Mon Dec 22 22:57:16 2008 -0600
1.3 @@ -12,7 +12,7 @@
1.4 #define _INCLUDE_SMM_LIST_H
1.5
1.6 #include <new>
1.7 -#include <malloc.h>
1.8 +#include <stdlib.h>
1.9
1.10 namespace SourceHook
1.11 {
2.1 --- a/core-legacy/sourcehook/sh_memory.h Mon Dec 22 22:55:55 2008 -0600
2.2 +++ b/core-legacy/sourcehook/sh_memory.h Mon Dec 22 22:57:16 2008 -0600
2.3 @@ -16,12 +16,12 @@
2.4 // Unprotect now sets to readwrite
2.5 // The vtable doesn't need to be executable anyway
2.6
2.7 -# if /********/ defined _WIN32
2.8 +# if SH_XP == SH_XP_WINAPI
2.9 # include <windows.h>
2.10 # define SH_MEM_READ 1
2.11 # define SH_MEM_WRITE 2
2.12 # define SH_MEM_EXEC 4
2.13 -# elif /******/ defined __linux__
2.14 +# elif SH_XP == SH_XP_POSIX
2.15 # include <sys/mman.h>
2.16 # include <stdio.h>
2.17 # include <signal.h>
2.18 @@ -48,7 +48,7 @@
2.19 {
2.20 inline bool SetMemAccess(void *addr, size_t len, int access)
2.21 {
2.22 -# ifdef __linux__
2.23 +# if SH_XP == SH_XP_POSIX
2.24 return mprotect(SH_LALIGN(addr), len + SH_LALDIF(addr), access)==0 ? true : false;
2.25 # else
2.26 DWORD tmp;
2.27 @@ -69,17 +69,25 @@
2.28 # endif
2.29 }
2.30
2.31 -#ifdef __linux__
2.32 +#if SH_XP == SH_XP_POSIX
2.33 namespace
2.34 {
2.35 bool g_BadReadCalled;
2.36 jmp_buf g_BadReadJmpBuf;
2.37
2.38 +# if SH_SYS == SH_SYS_LINUX
2.39 static void BadReadHandler(int sig)
2.40 {
2.41 if (g_BadReadCalled)
2.42 longjmp(g_BadReadJmpBuf, 1);
2.43 }
2.44 +# elif SH_SYS == SH_SYS_APPLE
2.45 + static void BadReadHandler(int signal, siginfo_t* my_siginfo, void* my_context)
2.46 + {
2.47 + if (g_BadReadCalled)
2.48 + longjmp(g_BadReadJmpBuf, 1);
2.49 + }
2.50 +# endif
2.51 }
2.52 #endif
2.53
2.54 @@ -93,7 +101,7 @@
2.55 {
2.56 bool ModuleInMemory(char *addr, size_t len)
2.57 {
2.58 -#ifdef __linux__
2.59 +#if SH_SYS == SH_SYS_LINUX
2.60 // On linux, first check /proc/self/maps
2.61 long lower = reinterpret_cast<long>(addr);
2.62 long upper = lower + len;
2.63 @@ -175,7 +183,29 @@
2.64 signal(SIGSEGV, prevHandler);
2.65
2.66 return false;
2.67 -#else
2.68 +#elif SH_SYS == SH_SYS_APPLE
2.69 + struct sigaction sa, osa;
2.70 + sa.sa_sigaction = BadReadHandler;
2.71 + sa.sa_flags = SA_SIGINFO | SA_RESTART;
2.72 +
2.73 + g_BadReadCalled = true;
2.74 +
2.75 + if (setjmp(g_BadReadJmpBuf))
2.76 + return false;
2.77 +
2.78 + if (sigaction(SIGBUS, &sa, &osa) == -1)
2.79 + return false;
2.80 +
2.81 + volatile const char *p = reinterpret_cast<const char *>(addr);
2.82 + char dummy;
2.83 +
2.84 + for (size_t i = 0; i < len; i++)
2.85 + dummy = p[i];
2.86 +
2.87 + g_BadReadCalled = false;
2.88 +
2.89 + return true;
2.90 +#elif SH_SYS == SH_SYS_WINAPI
2.91 // On Win32, simply use IsBadReadPtr
2.92 return !IsBadReadPtr(addr, len);
2.93 #endif
3.1 --- a/core-legacy/sourcehook/sourcehook.h Mon Dec 22 22:55:55 2008 -0600
3.2 +++ b/core-legacy/sourcehook/sourcehook.h Mon Dec 22 22:57:16 2008 -0600
3.3 @@ -61,11 +61,21 @@
3.4 // System
3.5 #define SH_SYS_WIN32 1
3.6 #define SH_SYS_LINUX 2
3.7 +#define SH_SYS_APPLE 3
3.8 +
3.9 +// OS
3.10 +#define SH_XP_POSIX 10
3.11 +#define SH_XP_WINAPI 20
3.12
3.13 #ifdef _WIN32
3.14 # define SH_SYS SH_SYS_WIN32
3.15 +# define SH_XP SH_XP_WINAPI
3.16 #elif defined __linux__
3.17 # define SH_SYS SH_SYS_LINUX
3.18 +# define SH_XP SH_XP_POSIX
3.19 +#elif defined __APPLE__
3.20 +# define SH_SYS SH_SYS_APPLE
3.21 +# define SH_XP SH_XP_POSIX
3.22 #else
3.23 # error Unsupported system
3.24 #endif