1
0
mirror of https://github.com/alliedmodders/metamod-source.git synced 2025-01-30 19:52:17 +01:00

First step to gcc support: it compiles now

--HG--
branch : hookman_autogen
extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/branches/hookman_autogen%40542
This commit is contained in:
Pavol Marko 2007-11-02 20:15:19 +00:00
parent b7e00841b0
commit b6f0b74f5b
9 changed files with 118 additions and 87 deletions

Binary file not shown.

View File

@ -24,7 +24,10 @@
# elif /******/ defined __linux__
# include <sys/mman.h>
# include <stdio.h>
namespace LinuxSignal
{
# include <signal.h>
}
# include <setjmp.h>
// http://www.die.net/doc/linux/man/man2/mprotect.2.html
# include <limits.h>
@ -163,7 +166,7 @@ namespace SourceHook
if (setjmp(g_BadReadJmpBuf))
return true;
prevHandler = signal(SIGSEGV, BadReadHandler);
prevHandler = LinuxSignal::signal(SIGSEGV, BadReadHandler);
volatile const char *p = reinterpret_cast<const char*>(addr);
char dummy;
@ -173,7 +176,7 @@ namespace SourceHook
g_BadReadCalled = false;
signal(SIGSEGV, prevHandler);
LinuxSignal::signal(SIGSEGV, prevHandler);
return false;
#else
@ -320,7 +323,7 @@ namespace SourceHook
newRegion.size += m_PageSize;
#ifdef __linux__
newRegion.startPtr = mmap(0, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAN_ANONYMOUS, -1);
newRegion.startPtr = mmap(0, newRegion.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
#else
newRegion.startPtr = VirtualAlloc(NULL, newRegion.size, MEM_COMMIT, PAGE_READWRITE);
#endif

View File

@ -1119,7 +1119,7 @@ namespace SourceHook
#endif
}
unsigned char * GenContext::GenerateHookFunc()
void * GenContext::GenerateHookFunc()
{
// prologue
IA32_Push_Reg(&m_HookFunc, REG_EBP);
@ -1317,7 +1317,7 @@ namespace SourceHook
}
// Pre-condition: GenerateHookFunc() has been called!
unsigned char * GenContext::GeneratePubFunc()
void * GenContext::GeneratePubFunc()
{
jitoffs_t counter, tmppos;
@ -1525,7 +1525,7 @@ namespace SourceHook
BuildProtoInfo();
GenerateHookFunc();
return reinterpret_cast<HookManagerPubFunc>(GeneratePubFunc());
return fastdelegate::detail::horrible_cast<HookManagerPubFunc>(GeneratePubFunc());
}
}
}
}

View File

@ -12,7 +12,6 @@
#define __SOURCEHOOK_HOOKMANGEN_H__
#include "sourcehook_impl.h"
#include "windows.h"
namespace SourceHook
{
@ -20,7 +19,7 @@ namespace SourceHook
{
// Code gen stuff
#if defined HAVE_STDINT_H && !defined WIN32
#if SH_COMP == SH_COMP_GCC
#include <stdint.h>
typedef int8_t jit_int8_t;
typedef uint8_t jit_uint8_t;
@ -28,7 +27,7 @@ namespace SourceHook
typedef uint32_t jit_uint32_t;
typedef int64_t jit_int64_t;
typedef uint64_t jit_uint64_t;
#elif defined WIN32
#elif SH_COMP == SH_COMP_MSVC
typedef __int8 jit_int8_t;
typedef unsigned __int8 jit_uint8_t;
typedef __int32 jit_int32_t;
@ -123,9 +122,9 @@ namespace SourceHook
ms_Allocator.SetRE(reinterpret_cast<void*>(m_pData));
}
operator unsigned char *()
operator void *()
{
return GetData();
return reinterpret_cast<void*>(GetData());
}
void write_ubyte(jit_uint8_t x) { push(x); }
@ -223,8 +222,8 @@ namespace SourceHook
bool PassInfoSupported(const IntPassInfo &pi, bool is_ret);
void Clear();
void BuildProtoInfo();
unsigned char *GenerateHookFunc();
unsigned char *GeneratePubFunc();
void *GenerateHookFunc();
void *GeneratePubFunc();
public:
// Level 1 -> Public interface
GenContext(const ProtoInfo *proto, int vtbl_offs, int vtbl_idx, ISourceHook *pSHPtr);
@ -236,4 +235,4 @@ namespace SourceHook
}
#endif
#endif

View File

@ -14,6 +14,16 @@
#include <limits.h>
#undef REG_EAX
#undef REG_ECX
#undef REG_EDX
#undef REG_EBX
#undef REG_ESP
#undef REG_SIB
#undef REG_EBP
#undef REG_ESI
#undef REG_EDI
//MOD R/M
#define MOD_MEM_REG 0
#define MOD_DISP8 1

View File

@ -9,7 +9,7 @@ INCLUDE = -I. -I..
MAX_PARAMS=20
BINARY = sourcehook_test
OBJECTS = main.cpp sourcehook.cpp $(shell ls -t test*.cpp)
OBJECTS = main.cpp sourcehook.cpp ../sourcehook_hookmangen.cpp $(shell ls -t test*.cpp)
HEADERS = ../sh_list.h ../sh_tinyhash.h ../sh_memory.h ../sh_string.h ../sh_vector.h ../sourcehook_impl.h ../FastDelegate.h ../sourcehook.h ../sh_memfuncinfo.h
ifeq "$(DEBUG)" "true"

View File

@ -18,6 +18,17 @@
namespace
{
StateList g_States;
SourceHook::ISourceHook *g_SHPtr;
SourceHook::Plugin g_PLID;
// PtrBuf(ptr) gives ptrs unique numbers
// in the order they appear
SourceHook::List<const void*> g_PtrHash;
bool g_Inside_LeafFunc = false; // inside a hook or a func
// POD / Object types
template <int MYSIZE>
struct POD
@ -151,52 +162,6 @@ namespace
} \
};
#include "testhookmangen.h"
StateList g_States;
SourceHook::ISourceHook *g_SHPtr;
SourceHook::Plugin g_PLID;
// PtrBuf(ptr) gives ptrs unique numbers
// in the order they appear
SourceHook::List<const void*> g_PtrHash;
bool g_Inside_LeafFunc = false; // inside a hook or a func
template <class T>
int PtrBuf(T ptr)
{
int a = 0;
const void *vptr = reinterpret_cast<const void*>(ptr);
for (SourceHook::List<const void*>::iterator iter = g_PtrHash.begin(); iter != g_PtrHash.end(); ++iter)
{
if (*iter == vptr)
return a;
else
++a;
}
g_PtrHash.push_back(vptr);
return static_cast<int>(g_PtrHash.size()) - 1;
}
template <class T>
T PtrBufPtr(T ptr)
{
PtrBuf(ptr);
return ptr;
}
void PtrBuf_Clear(int leave_in = 0)
{
for (SourceHook::List<const void*>::iterator iter = g_PtrHash.begin(); iter != g_PtrHash.end();)
{
if (--leave_in < 0)
iter = g_PtrHash.erase(iter);
else
++iter;
}
}
// "Increment" something: (reproducible change for recall tests)
@ -250,6 +215,44 @@ namespace
}
};
#include "testhookmangen.h"
template <class T>
int PtrBuf(T ptr)
{
int a = 0;
const void *vptr = reinterpret_cast<const void*>(ptr);
for (SourceHook::List<const void*>::iterator iter = g_PtrHash.begin(); iter != g_PtrHash.end(); ++iter)
{
if (*iter == vptr)
return a;
else
++a;
}
g_PtrHash.push_back(vptr);
return static_cast<int>(g_PtrHash.size()) - 1;
}
template <class T>
T PtrBufPtr(T ptr)
{
PtrBuf(ptr);
return ptr;
}
void PtrBuf_Clear(int leave_in = 0)
{
for (SourceHook::List<const void*>::iterator iter = g_PtrHash.begin(); iter != g_PtrHash.end();)
{
if (--leave_in < 0)
iter = g_PtrHash.erase(iter);
else
++iter;
}
}
// MyDelegate base class for other delegates
class MyDelegate : public SourceHook::ISHDelegate
{
@ -879,4 +882,4 @@ bool TestCPageAlloc(std::string &error)
memset((void*)test4[2], 0, ps / 4);
return true;
}
}

View File

@ -43,7 +43,15 @@ void *FindFuncAddr(T mfp)
if (sizeof(mfp) != sizeof(void*))
return NULL;
else
return fastdelegate::detail::horrible_cast<void*>(mfp);
{
union
{
T a;
void *b;
} u;
u.a = mfp;
return u.b;
}
}
// Reference carrier
@ -166,7 +174,7 @@ struct ParamState1
int i;
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p1 >::type>::Incr(m_1);
Increment<typename StripRef< p1 >::type >::Incr(m_1);
return *this;
@ -202,10 +210,10 @@ struct ParamState2
int i;
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p1 >::type>::Incr(m_1);
Increment<typename StripRef< p1 >::type >::Incr(m_1);
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p2 >::type>::Incr(m_2);
Increment<typename StripRef< p2 >::type >::Incr(m_2);
return *this;
@ -241,13 +249,13 @@ struct ParamState3
int i;
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p1 >::type>::Incr(m_1);
Increment<typename StripRef< p1 >::type >::Incr(m_1);
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p2 >::type>::Incr(m_2);
Increment<typename StripRef< p2 >::type >::Incr(m_2);
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p3 >::type>::Incr(m_3);
Increment<typename StripRef< p3 >::type >::Incr(m_3);
return *this;
@ -283,16 +291,16 @@ struct ParamState4
int i;
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p1 >::type>::Incr(m_1);
Increment<typename StripRef< p1 >::type >::Incr(m_1);
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p2 >::type>::Incr(m_2);
Increment<typename StripRef< p2 >::type >::Incr(m_2);
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p3 >::type>::Incr(m_3);
Increment<typename StripRef< p3 >::type >::Incr(m_3);
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p4 >::type>::Incr(m_4);
Increment<typename StripRef< p4 >::type >::Incr(m_4);
return *this;
@ -328,19 +336,19 @@ struct ParamState5
int i;
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p1 >::type>::Incr(m_1);
Increment<typename StripRef< p1 >::type >::Incr(m_1);
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p2 >::type>::Incr(m_2);
Increment<typename StripRef< p2 >::type >::Incr(m_2);
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p3 >::type>::Incr(m_3);
Increment<typename StripRef< p3 >::type >::Incr(m_3);
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p4 >::type>::Incr(m_4);
Increment<typename StripRef< p4 >::type >::Incr(m_4);
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p5 >::type>::Incr(m_5);
Increment<typename StripRef< p5 >::type >::Incr(m_5);
return *this;
@ -376,22 +384,22 @@ struct ParamState6
int i;
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p1 >::type>::Incr(m_1);
Increment<typename StripRef< p1 >::type >::Incr(m_1);
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p2 >::type>::Incr(m_2);
Increment<typename StripRef< p2 >::type >::Incr(m_2);
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p3 >::type>::Incr(m_3);
Increment<typename StripRef< p3 >::type >::Incr(m_3);
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p4 >::type>::Incr(m_4);
Increment<typename StripRef< p4 >::type >::Incr(m_4);
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p5 >::type>::Incr(m_5);
Increment<typename StripRef< p5 >::type >::Incr(m_5);
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p6 >::type>::Incr(m_6);
Increment<typename StripRef< p6 >::type >::Incr(m_6);
return *this;

View File

@ -43,7 +43,15 @@ void *FindFuncAddr(T mfp)
if (sizeof(mfp) != sizeof(void*))
return NULL;
else
return fastdelegate::detail::horrible_cast<void*>(mfp);
{
union
{
T a;
void *b;
} u;
u.a = mfp;
return u.b;
}
}
// Reference carrier
@ -133,7 +141,7 @@ struct ParamState$1
@[$1!=0:int i;@]
@[$2,1,$1:
for (i = 0; i < incrsteps; ++i)
Increment<StripRef< p$2 >::type>::Incr(m_$2);
Increment<typename StripRef< p$2 >::type >::Incr(m_$2);
@]
return *this;