From 075a21cc07d72a566d1fbc49debe85a4dc4ca013 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 22 Dec 2008 23:38:06 -0500 Subject: [PATCH 1/4] Fixed SourceHook includes to be usable on Mac OS X (bug 3514, r=ds). --- core-legacy/sourcehook/sh_list.h | 2 +- core-legacy/sourcehook/sh_memory.h | 42 ++++++++++++++++++++++++----- core-legacy/sourcehook/sourcehook.h | 10 +++++++ 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/core-legacy/sourcehook/sh_list.h b/core-legacy/sourcehook/sh_list.h index b672361..700a7a6 100644 --- a/core-legacy/sourcehook/sh_list.h +++ b/core-legacy/sourcehook/sh_list.h @@ -12,7 +12,7 @@ #define _INCLUDE_SMM_LIST_H #include -#include +#include namespace SourceHook { diff --git a/core-legacy/sourcehook/sh_memory.h b/core-legacy/sourcehook/sh_memory.h index d2d3531..0e185e8 100644 --- a/core-legacy/sourcehook/sh_memory.h +++ b/core-legacy/sourcehook/sh_memory.h @@ -16,12 +16,12 @@ // Unprotect now sets to readwrite // The vtable doesn't need to be executable anyway -# if /********/ defined _WIN32 +# if SH_XP == SH_XP_WINAPI # include # define SH_MEM_READ 1 # define SH_MEM_WRITE 2 # define SH_MEM_EXEC 4 -# elif /******/ defined __linux__ +# elif SH_XP == SH_XP_POSIX # include # include # include @@ -48,7 +48,7 @@ namespace SourceHook { inline bool SetMemAccess(void *addr, size_t len, int access) { -# ifdef __linux__ +# if SH_XP == SH_XP_POSIX return mprotect(SH_LALIGN(addr), len + SH_LALDIF(addr), access)==0 ? true : false; # else DWORD tmp; @@ -69,17 +69,25 @@ namespace SourceHook # endif } -#ifdef __linux__ +#if SH_XP == SH_XP_POSIX namespace { bool g_BadReadCalled; jmp_buf g_BadReadJmpBuf; +# if SH_SYS == SH_SYS_LINUX static void BadReadHandler(int sig) { if (g_BadReadCalled) longjmp(g_BadReadJmpBuf, 1); } +# elif SH_SYS == SH_SYS_APPLE + static void BadReadHandler(int signal, siginfo_t* my_siginfo, void* my_context) + { + if (g_BadReadCalled) + longjmp(g_BadReadJmpBuf, 1); + } +# endif } #endif @@ -93,7 +101,7 @@ namespace SourceHook { bool ModuleInMemory(char *addr, size_t len) { -#ifdef __linux__ +#if SH_SYS == SH_SYS_LINUX // On linux, first check /proc/self/maps long lower = reinterpret_cast(addr); long upper = lower + len; @@ -175,7 +183,29 @@ namespace SourceHook signal(SIGSEGV, prevHandler); return false; -#else +#elif SH_SYS == SH_SYS_APPLE + struct sigaction sa, osa; + sa.sa_sigaction = BadReadHandler; + sa.sa_flags = SA_SIGINFO | SA_RESTART; + + g_BadReadCalled = true; + + if (setjmp(g_BadReadJmpBuf)) + return false; + + if (sigaction(SIGBUS, &sa, &osa) == -1) + return false; + + volatile const char *p = reinterpret_cast(addr); + char dummy; + + for (size_t i = 0; i < len; i++) + dummy = p[i]; + + g_BadReadCalled = false; + + return true; +#elif SH_SYS == SH_SYS_WINAPI // On Win32, simply use IsBadReadPtr return !IsBadReadPtr(addr, len); #endif diff --git a/core-legacy/sourcehook/sourcehook.h b/core-legacy/sourcehook/sourcehook.h index 92ff0c0..1958bd8 100644 --- a/core-legacy/sourcehook/sourcehook.h +++ b/core-legacy/sourcehook/sourcehook.h @@ -61,11 +61,21 @@ // System #define SH_SYS_WIN32 1 #define SH_SYS_LINUX 2 +#define SH_SYS_APPLE 3 + +// OS +#define SH_XP_POSIX 10 +#define SH_XP_WINAPI 20 #ifdef _WIN32 # define SH_SYS SH_SYS_WIN32 +# define SH_XP SH_XP_WINAPI #elif defined __linux__ # define SH_SYS SH_SYS_LINUX +# define SH_XP SH_XP_POSIX +#elif defined __APPLE__ +# define SH_SYS SH_SYS_APPLE +# define SH_XP SH_XP_POSIX #else # error Unsupported system #endif From 774af581031d379404f3ed1b38e9735ebb9462d8 Mon Sep 17 00:00:00 2001 From: Scott Ehlert Date: Mon, 22 Dec 2008 22:55:55 -0600 Subject: [PATCH 2/4] Fixed bug where plugin aliases defined in VDF files on core (Orange Box and L4D engines) didn't work. --- core/metamod.cpp | 28 ++++++++++++++++++++++++++-- core/provider/provider_ep2.cpp | 26 ++------------------------ 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/core/metamod.cpp b/core/metamod.cpp index 07b1035..64e217c 100644 --- a/core/metamod.cpp +++ b/core/metamod.cpp @@ -1114,7 +1114,7 @@ ProcessVDF(const char *path, bool &skipped) { PluginId id; bool already; - char alias[24], file[255], error[255]; + char alias[24], file[255], full_path[255], error[255]; if (!provider->ProcessVDF(path, file, sizeof(file), alias, sizeof(alias))) { @@ -1125,7 +1125,31 @@ ProcessVDF(const char *path, bool &skipped) if (alias[0] != '\0') g_PluginMngr.SetAlias(alias, file); - id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error)); + /* Attempt to find a file extension */ + if (UTIL_GetExtension(file) == NULL) + { + g_pMetamod->PathFormat(full_path, + sizeof(full_path), + "%s/%s%s", + g_pMetamod->GetBaseDir(), + file, +#if defined WIN32 || defined _WIN32 + ".dll" +#else + "_i486.so" +#endif + ); + } + else + { + g_pMetamod->PathFormat(full_path, + sizeof(full_path), + "%s/%s", + g_pMetamod->GetBaseDir(), + file); + } + + id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error)); skipped = already; if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused) { diff --git a/core/provider/provider_ep2.cpp b/core/provider/provider_ep2.cpp index 907ff29..fedf300 100644 --- a/core/provider/provider_ep2.cpp +++ b/core/provider/provider_ep2.cpp @@ -417,6 +417,8 @@ bool BaseProvider::ProcessVDF(const char *file, char path[], size_t path_len, ch return false; } + UTIL_Format(path, path_len, "%s", plugin_file); + if ((p_alias = pValues->GetString("alias", NULL)) != NULL) { UTIL_Format(alias, alias_len, "%s", p_alias); @@ -426,30 +428,6 @@ bool BaseProvider::ProcessVDF(const char *file, char path[], size_t path_len, ch UTIL_Format(alias, alias_len, ""); } - /* Attempt to find a file extension */ - if (UTIL_GetExtension(plugin_file) == NULL) - { - g_pMetamod->PathFormat(path, - path_len, - "%s/%s%s", - g_pMetamod->GetBaseDir(), - plugin_file, -#if defined WIN32 || defined _WIN32 - ".dll" -#else - "_i486.so" -#endif - ); - } - else - { - g_pMetamod->PathFormat(path, - path_len, - "%s/%s", - g_pMetamod->GetBaseDir(), - plugin_file); - } - pValues->deleteThis(); return true; From 15dbd8d9ffefb32068fb8dfcba25d477ff195244 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 23 Dec 2008 00:03:33 -0500 Subject: [PATCH 3/4] Whitespace fix. --- core-legacy/sourcehook/sh_memory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-legacy/sourcehook/sh_memory.h b/core-legacy/sourcehook/sh_memory.h index 0e185e8..0d58c19 100644 --- a/core-legacy/sourcehook/sh_memory.h +++ b/core-legacy/sourcehook/sh_memory.h @@ -204,7 +204,7 @@ namespace SourceHook g_BadReadCalled = false; - return true; + return true; #elif SH_SYS == SH_SYS_WINAPI // On Win32, simply use IsBadReadPtr return !IsBadReadPtr(addr, len); From b2b6c22b30fdf78f90ce49cd2d5e2d93093eb22c Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 23 Dec 2008 00:08:01 -0500 Subject: [PATCH 4/4] Fixed build failure (no bug, r=ds). --- core-legacy/sourcehook/sh_memory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-legacy/sourcehook/sh_memory.h b/core-legacy/sourcehook/sh_memory.h index 0d58c19..d5517fd 100644 --- a/core-legacy/sourcehook/sh_memory.h +++ b/core-legacy/sourcehook/sh_memory.h @@ -205,7 +205,7 @@ namespace SourceHook g_BadReadCalled = false; return true; -#elif SH_SYS == SH_SYS_WINAPI +#elif SH_XP == SH_XP_WINAPI // On Win32, simply use IsBadReadPtr return !IsBadReadPtr(addr, len); #endif