mirror of
https://github.com/alliedmodders/metamod-source.git
synced 2024-12-01 13:24:25 +01:00
Fixed SourceHook v5 includes in core to be usable on Mac OS X (bug 3514, r=ds).
This commit is contained in:
parent
15e694bce8
commit
2e4b4c9f62
@ -1,7 +1,11 @@
|
||||
#/bin/sh
|
||||
|
||||
./shworker.bin iter sourcehook.hxx sourcehook.h $1
|
||||
./shworker.bin iter sh_memfuncinfo.hxx sh_memfuncinfo.h $1
|
||||
./shworker.bin hopter FastDelegate.hxx FastDelegate.h $1
|
||||
cd shworker
|
||||
make
|
||||
cd ..
|
||||
|
||||
shworker/bin/shworker.bin iter sourcehook.hxx sourcehook.h $1
|
||||
shworker/bin/shworker.bin iter sh_memfuncinfo.hxx sh_memfuncinfo.h $1
|
||||
shworker/bin/shworker.bin hopter FastDelegate.hxx FastDelegate.h $1
|
||||
|
||||
cp *.h ..
|
||||
|
@ -1,13 +1,15 @@
|
||||
CPP = gcc
|
||||
|
||||
default: shworker
|
||||
|
||||
bin:
|
||||
mkdir bin
|
||||
|
||||
fd_hopter.o: fd_hopter.cpp bin
|
||||
gcc -fPIC -O2 -o bin/$@ -c $<
|
||||
$(CPP) -fPIC -O2 -o bin/$@ -c $<
|
||||
|
||||
main.o: shworker.cpp bin
|
||||
gcc -fPIC -O2 -o bin/$@ -c $<
|
||||
$(CPP) -fPIC -O2 -o bin/$@ -c $<
|
||||
|
||||
shworker: fd_hopter.o main.o bin
|
||||
gcc -ldl -lstdc++ bin/fd_hopter.o bin/main.o -o bin/shworker.bin
|
||||
$(CPP) -ldl -lstdc++ bin/fd_hopter.o bin/main.o -o bin/shworker.bin
|
||||
|
@ -743,7 +743,7 @@ int main(int argc, const char **argv)
|
||||
|
||||
const char *action = argv[1];
|
||||
|
||||
if (stricmp(action, "hopter") == 0)
|
||||
if (strcasecmp(action, "hopter") == 0)
|
||||
{
|
||||
const char *filenamein = argv[2];
|
||||
const char *filenameout = argv[3];
|
||||
@ -751,7 +751,7 @@ int main(int argc, const char **argv)
|
||||
|
||||
return action_hopter(argsnum, filenamein, filenameout);
|
||||
}
|
||||
else if (stricmp(action, "iter") == 0)
|
||||
else if (strcasecmp(action, "iter") == 0)
|
||||
{
|
||||
const char *filenamein = argv[2];
|
||||
const char *filenameout = argv[3];
|
||||
|
@ -73,11 +73,21 @@
|
||||
// System
|
||||
#define SH_SYS_WIN32 1
|
||||
#define SH_SYS_LINUX 2
|
||||
#define SH_SYS_APPLE 3
|
||||
|
||||
// Platform
|
||||
#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
|
||||
|
@ -73,11 +73,21 @@
|
||||
// System
|
||||
#define SH_SYS_WIN32 1
|
||||
#define SH_SYS_LINUX 2
|
||||
#define SH_SYS_APPLE 3
|
||||
|
||||
// Platform
|
||||
#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
|
||||
|
@ -12,7 +12,7 @@
|
||||
#define _INCLUDE_SMM_LIST_H
|
||||
|
||||
#include <new>
|
||||
#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace SourceHook
|
||||
{
|
||||
|
@ -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 <windows.h>
|
||||
# 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 <sys/mman.h>
|
||||
# include <stdio.h>
|
||||
# include <signal.h>
|
||||
@ -50,9 +50,9 @@ 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
|
||||
# elif SH_XP == SH_XP_WINAPI
|
||||
DWORD tmp;
|
||||
DWORD prot;
|
||||
switch (access)
|
||||
@ -71,17 +71,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
|
||||
|
||||
@ -95,7 +103,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<long>(addr);
|
||||
long upper = lower + len;
|
||||
@ -177,7 +185,31 @@ 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<const char *>(addr);
|
||||
char dummy;
|
||||
|
||||
for (size_t i = 0; i < len; i++)
|
||||
dummy = p[i];
|
||||
|
||||
g_BadReadCalled = false;
|
||||
|
||||
sigaction(SIGBUS, &osa, NULL);
|
||||
|
||||
return true;
|
||||
#elif SH_XP == SH_XP_WINAPI
|
||||
// On Win32, simply use IsBadReadPtr
|
||||
return !IsBadReadPtr(addr, len);
|
||||
#endif
|
||||
|
@ -1,9 +1,9 @@
|
||||
#ifndef __SH_PAGEALLOC_H__
|
||||
#define __SH_PAGEALLOC_H__
|
||||
|
||||
# if /********/ defined _WIN32
|
||||
# if SH_XP == SH_XP_WINAPI
|
||||
# include <windows.h>
|
||||
# elif /******/ defined __linux__
|
||||
# elif SH_XP == SH_XP_POSIX
|
||||
# include <sys/mman.h>
|
||||
# include <unistd.h>
|
||||
# else
|
||||
@ -140,9 +140,9 @@ namespace SourceHook
|
||||
|
||||
void FreeRegion()
|
||||
{
|
||||
#ifdef __linux__
|
||||
#if SH_XP == SH_XP_POSIX
|
||||
munmap(startPtr, size);
|
||||
#else
|
||||
#elif SH_XP == SH_XP_WINAPI
|
||||
VirtualFree(startPtr, 0, MEM_RELEASE);
|
||||
#endif
|
||||
}
|
||||
@ -167,9 +167,12 @@ namespace SourceHook
|
||||
if (newRegion.size < minSize)
|
||||
newRegion.size += m_PageSize;
|
||||
|
||||
#ifdef __linux__
|
||||
#if SH_XP == SH_XP_POSIX
|
||||
# if !defined MAP_ANONYMOUS
|
||||
# define MAP_ANONYMOUS MAP_ANON
|
||||
# endif
|
||||
newRegion.startPtr = mmap(0, newRegion.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
#else
|
||||
#elif SH_XP == SH_XP_WINAPI
|
||||
newRegion.startPtr = VirtualAlloc(NULL, newRegion.size, MEM_COMMIT, PAGE_READWRITE);
|
||||
#endif
|
||||
|
||||
@ -209,9 +212,9 @@ namespace SourceHook
|
||||
public:
|
||||
CPageAlloc(size_t minAlignment = 1 /* power of 2 */ ) : m_MinAlignment(minAlignment)
|
||||
{
|
||||
#ifdef __linux__
|
||||
#if SH_XP == SH_XP_POSIX
|
||||
m_PageSize = sysconf(_SC_PAGESIZE);
|
||||
#else
|
||||
#elif SH_XP == SH_XP_WINAPI
|
||||
SYSTEM_INFO sysInfo;
|
||||
GetSystemInfo(&sysInfo);
|
||||
m_PageSize = sysInfo.dwPageSize;
|
||||
|
@ -73,11 +73,21 @@
|
||||
// System
|
||||
#define SH_SYS_WIN32 1
|
||||
#define SH_SYS_LINUX 2
|
||||
#define SH_SYS_APPLE 3
|
||||
|
||||
// Platform
|
||||
#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
|
||||
|
@ -54,7 +54,7 @@ all:
|
||||
|
||||
|
||||
$(BINARY): $(OBJ_LINUX)
|
||||
$(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -o$(BIN_DIR)/$(BINARY)
|
||||
$(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -o $(BIN_DIR)/$(BINARY)
|
||||
|
||||
clean:
|
||||
rm -rf Release/*.o
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "testevents.h"
|
||||
|
||||
// This should probably be done the other way round!
|
||||
#ifdef __linux__
|
||||
#if SH_XP == SH_XP_POSIX
|
||||
#define _snprintf snprintf
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user