Merged changes from mmsource-1.7 branch.
authorScott Ehlert <ds@alliedmods.net>
Mon Dec 29 11:42:44 2008 -0600 (2008-12-29)
changeset 63286c612397e90
parent 625 29f215bc23a0
parent 631 326e468615ed
child 654 b91f45b92fe5
Merged changes from mmsource-1.7 branch.
     1.1 --- a/core-legacy/sourcehook/sh_list.h	Sun Dec 07 23:51:58 2008 -0600
     1.2 +++ b/core-legacy/sourcehook/sh_list.h	Mon Dec 29 11:42:44 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	Sun Dec 07 23:51:58 2008 -0600
     2.2 +++ b/core-legacy/sourcehook/sh_memory.h	Mon Dec 29 11:42:44 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_XP == SH_XP_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	Sun Dec 07 23:51:58 2008 -0600
     3.2 +++ b/core-legacy/sourcehook/sourcehook.h	Mon Dec 29 11:42:44 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
     4.1 --- a/core/metamod.cpp	Sun Dec 07 23:51:58 2008 -0600
     4.2 +++ b/core/metamod.cpp	Mon Dec 29 11:42:44 2008 -0600
     4.3 @@ -1114,7 +1114,7 @@
     4.4  {
     4.5  	PluginId id;
     4.6  	bool already;
     4.7 -	char alias[24], file[255], error[255];
     4.8 +	char alias[24], file[255], full_path[255], error[255];
     4.9  
    4.10  	if (!provider->ProcessVDF(path, file, sizeof(file), alias, sizeof(alias)))
    4.11  	{
    4.12 @@ -1125,7 +1125,31 @@
    4.13  	if (alias[0] != '\0')
    4.14  		g_PluginMngr.SetAlias(alias, file);
    4.15  
    4.16 -	id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
    4.17 +	/* Attempt to find a file extension */
    4.18 +	if (UTIL_GetExtension(file) == NULL)
    4.19 +	{
    4.20 +		g_pMetamod->PathFormat(full_path, 
    4.21 +			sizeof(full_path), 
    4.22 +			"%s/%s%s", 
    4.23 +			g_pMetamod->GetBaseDir(), 
    4.24 +			file, 
    4.25 +#if defined WIN32 || defined _WIN32
    4.26 +			".dll"
    4.27 +#else
    4.28 +			"_i486.so"
    4.29 +#endif
    4.30 +			);
    4.31 +	}
    4.32 +	else
    4.33 +	{
    4.34 +		g_pMetamod->PathFormat(full_path,
    4.35 +			sizeof(full_path),
    4.36 +			"%s/%s", 
    4.37 +			g_pMetamod->GetBaseDir(),
    4.38 +			file);
    4.39 +	}
    4.40 +
    4.41 +	id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
    4.42  	skipped = already;
    4.43  	if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
    4.44  	{
     5.1 --- a/core/provider/provider_ep2.cpp	Sun Dec 07 23:51:58 2008 -0600
     5.2 +++ b/core/provider/provider_ep2.cpp	Mon Dec 29 11:42:44 2008 -0600
     5.3 @@ -417,6 +417,8 @@
     5.4  		return false;
     5.5  	}
     5.6  
     5.7 +	UTIL_Format(path, path_len, "%s", plugin_file);
     5.8 +
     5.9  	if ((p_alias = pValues->GetString("alias", NULL)) != NULL)
    5.10  	{
    5.11  		UTIL_Format(alias, alias_len, "%s", p_alias);
    5.12 @@ -426,30 +428,6 @@
    5.13  		UTIL_Format(alias, alias_len, "");
    5.14  	}
    5.15  
    5.16 -	/* Attempt to find a file extension */
    5.17 -	if (UTIL_GetExtension(plugin_file) == NULL)
    5.18 -	{
    5.19 -		g_pMetamod->PathFormat(path, 
    5.20 -			path_len, 
    5.21 -			"%s/%s%s", 
    5.22 -			g_pMetamod->GetBaseDir(), 
    5.23 -			plugin_file, 
    5.24 -#if defined WIN32 || defined _WIN32
    5.25 -			".dll"
    5.26 -#else
    5.27 -			"_i486.so"
    5.28 -#endif
    5.29 -			);
    5.30 -	}
    5.31 -	else
    5.32 -	{
    5.33 -		g_pMetamod->PathFormat(path,
    5.34 -			path_len,
    5.35 -			"%s/%s", 
    5.36 -			g_pMetamod->GetBaseDir(),
    5.37 -			plugin_file);
    5.38 -	}
    5.39 -
    5.40  	pValues->deleteThis();
    5.41  
    5.42  	return true;