1
0
mirror of https://github.com/alliedmodders/metamod-source.git synced 2024-12-01 13:24:25 +01:00

Merged changes from mmsource-1.7 branch.

This commit is contained in:
Scott Ehlert 2008-12-29 11:42:44 -06:00
commit 1f263e3c88
5 changed files with 75 additions and 33 deletions

View File

@ -12,7 +12,7 @@
#define _INCLUDE_SMM_LIST_H #define _INCLUDE_SMM_LIST_H
#include <new> #include <new>
#include <malloc.h> #include <stdlib.h>
namespace SourceHook namespace SourceHook
{ {

View File

@ -16,12 +16,12 @@
// Unprotect now sets to readwrite // Unprotect now sets to readwrite
// The vtable doesn't need to be executable anyway // The vtable doesn't need to be executable anyway
# if /********/ defined _WIN32 # if SH_XP == SH_XP_WINAPI
# include <windows.h> # include <windows.h>
# define SH_MEM_READ 1 # define SH_MEM_READ 1
# define SH_MEM_WRITE 2 # define SH_MEM_WRITE 2
# define SH_MEM_EXEC 4 # define SH_MEM_EXEC 4
# elif /******/ defined __linux__ # elif SH_XP == SH_XP_POSIX
# include <sys/mman.h> # include <sys/mman.h>
# include <stdio.h> # include <stdio.h>
# include <signal.h> # include <signal.h>
@ -48,7 +48,7 @@ namespace SourceHook
{ {
inline bool SetMemAccess(void *addr, size_t len, int access) 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; return mprotect(SH_LALIGN(addr), len + SH_LALDIF(addr), access)==0 ? true : false;
# else # else
DWORD tmp; DWORD tmp;
@ -69,17 +69,25 @@ namespace SourceHook
# endif # endif
} }
#ifdef __linux__ #if SH_XP == SH_XP_POSIX
namespace namespace
{ {
bool g_BadReadCalled; bool g_BadReadCalled;
jmp_buf g_BadReadJmpBuf; jmp_buf g_BadReadJmpBuf;
# if SH_SYS == SH_SYS_LINUX
static void BadReadHandler(int sig) static void BadReadHandler(int sig)
{ {
if (g_BadReadCalled) if (g_BadReadCalled)
longjmp(g_BadReadJmpBuf, 1); 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 #endif
@ -93,7 +101,7 @@ namespace SourceHook
{ {
bool ModuleInMemory(char *addr, size_t len) bool ModuleInMemory(char *addr, size_t len)
{ {
#ifdef __linux__ #if SH_SYS == SH_SYS_LINUX
// On linux, first check /proc/self/maps // On linux, first check /proc/self/maps
long lower = reinterpret_cast<long>(addr); long lower = reinterpret_cast<long>(addr);
long upper = lower + len; long upper = lower + len;
@ -175,7 +183,29 @@ namespace SourceHook
signal(SIGSEGV, prevHandler); signal(SIGSEGV, prevHandler);
return false; 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<const char *>(addr);
char dummy;
for (size_t i = 0; i < len; i++)
dummy = p[i];
g_BadReadCalled = false;
return true;
#elif SH_XP == SH_XP_WINAPI
// On Win32, simply use IsBadReadPtr // On Win32, simply use IsBadReadPtr
return !IsBadReadPtr(addr, len); return !IsBadReadPtr(addr, len);
#endif #endif

View File

@ -61,11 +61,21 @@
// System // System
#define SH_SYS_WIN32 1 #define SH_SYS_WIN32 1
#define SH_SYS_LINUX 2 #define SH_SYS_LINUX 2
#define SH_SYS_APPLE 3
// OS
#define SH_XP_POSIX 10
#define SH_XP_WINAPI 20
#ifdef _WIN32 #ifdef _WIN32
# define SH_SYS SH_SYS_WIN32 # define SH_SYS SH_SYS_WIN32
# define SH_XP SH_XP_WINAPI
#elif defined __linux__ #elif defined __linux__
# define SH_SYS SH_SYS_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 #else
# error Unsupported system # error Unsupported system
#endif #endif

View File

@ -1114,7 +1114,7 @@ ProcessVDF(const char *path, bool &skipped)
{ {
PluginId id; PluginId id;
bool already; 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))) if (!provider->ProcessVDF(path, file, sizeof(file), alias, sizeof(alias)))
{ {
@ -1125,7 +1125,31 @@ ProcessVDF(const char *path, bool &skipped)
if (alias[0] != '\0') if (alias[0] != '\0')
g_PluginMngr.SetAlias(alias, file); 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; skipped = already;
if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused) if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
{ {

View File

@ -417,6 +417,8 @@ bool BaseProvider::ProcessVDF(const char *file, char path[], size_t path_len, ch
return false; return false;
} }
UTIL_Format(path, path_len, "%s", plugin_file);
if ((p_alias = pValues->GetString("alias", NULL)) != NULL) if ((p_alias = pValues->GetString("alias", NULL)) != NULL)
{ {
UTIL_Format(alias, alias_len, "%s", p_alias); 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, ""); 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(); pValues->deleteThis();
return true; return true;