sourcehook/sourcehook.cpp
changeset 90 828fa4d35bdf
parent 88 2586c2eb900e
child 91 8386e9627595
     1.1 --- a/sourcehook/sourcehook.cpp	Thu Jul 07 20:58:05 2005 +0000
     1.2 +++ b/sourcehook/sourcehook.cpp	Thu Jul 07 21:07:43 2005 +0000
     1.3 @@ -473,38 +473,6 @@
     1.4  		}
     1.5  	}
     1.6  
     1.7 -#ifdef __linux__
     1.8 -	// Windows has an implentation for this already, but Linux does not :(
     1.9 -	static bool CSourceHookImpl::IsBadReadPtr(const void *ptr, size_t len)
    1.10 -	{
    1.11 -		void(*prevHandler)(int sig);
    1.12 -		m_BadReadCalled = true;
    1.13 -
    1.14 -		if (setjmp(m_BadReadJmpBuf))
    1.15 -			return true;
    1.16 -
    1.17 -		prevHandler = signal(SIGSEGV, BadReadHandler);
    1.18 -
    1.19 -		volatile const char *p = reinterpret_cast<const char*>(ptr);
    1.20 -		char dummy;
    1.21 -
    1.22 -		for (size_t i = 0; i < len; i++)
    1.23 -			dummy = p[i];
    1.24 -
    1.25 -		m_BadReadCalled = false;
    1.26 -
    1.27 -		signal(SIGSEGV, prevHandler);
    1.28 -
    1.29 -		return false;
    1.30 -	}
    1.31 -
    1.32 -	static void CSourceHookImpl::BadReadHandler(int sig)
    1.33 -	{
    1.34 -		if (m_BadReadCalled)
    1.35 -			longjmp(m_BadReadJmpBuf, 1);
    1.36 -	}
    1.37 -#endif
    1.38 -
    1.39  	CSourceHookImpl::HookManInfoList::iterator CSourceHookImpl::FindHookMan(HookManInfoList::iterator begin,
    1.40  		HookManInfoList::iterator end, const char *proto, int vtblofs, int vtblidx)
    1.41  	{
    1.42 @@ -619,4 +587,36 @@
    1.43  	{
    1.44  		return m_IfacePtr;
    1.45  	}
    1.46 +
    1.47 +#ifdef __linux__
    1.48 +	// Windows has an implementation for this already, but Linux does not :(
    1.49 +	bool IsBadReadPtr(const void *ptr, size_t len)
    1.50 +	{
    1.51 +		void(*prevHandler)(int sig);
    1.52 +		g_BadReadCalled = true;
    1.53 +
    1.54 +		if (setjmp(g_BadReadJmpBuf))
    1.55 +			return true;
    1.56 +
    1.57 +		prevHandler = signal(SIGSEGV, BadReadHandler);
    1.58 +
    1.59 +		volatile const char *p = reinterpret_cast<const char*>(ptr);
    1.60 +		char dummy;
    1.61 +
    1.62 +		for (size_t i = 0; i < len; i++)
    1.63 +			dummy = p[i];
    1.64 +
    1.65 +		g_BadReadCalled = false;
    1.66 +
    1.67 +		signal(SIGSEGV, prevHandler);
    1.68 +
    1.69 +		return false;
    1.70 +	}
    1.71 +
    1.72 +	void CSourceHookImpl::BadReadHandler(int sig)
    1.73 +	{
    1.74 +		if (g_BadReadCalled)
    1.75 +			longjmp(g_BadReadJmpBuf, 1);
    1.76 +	}
    1.77 +#endif
    1.78  }