Removed IsBadReadPtr and BadReadHandler from CSourceHookImpl to fix Linux compile bug
authorScott Ehlert <ds@alliedmods.net>
Thu Jul 07 21:07:43 2005 +0000 (2005-07-07)
changeset 90828fa4d35bdf
parent 89 79be0cd8f6c9
child 91 8386e9627595
Removed IsBadReadPtr and BadReadHandler from CSourceHookImpl to fix Linux compile bug
sourcehook/sourcehook.cpp
sourcehook/sourcehook_impl.h
     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  }
     2.1 --- a/sourcehook/sourcehook_impl.h	Thu Jul 07 20:58:05 2005 +0000
     2.2 +++ b/sourcehook/sourcehook_impl.h	Thu Jul 07 21:07:43 2005 +0000
     2.3 @@ -82,22 +82,6 @@
     2.4  		void RemoveCallClassPatch(CallClassInfo &cc, int vtbl_offs, int vtbl_idx);
     2.5  		void RemoveCallClassPatches(void *ifaceptr, int vtbl_offs, int vtbl_idx);
     2.6  
     2.7 -#ifdef __linux__
     2.8 -		/**
     2.9 -		*	@brief Checks to see if a memory value can be read from a given pointer.
    2.10 -		*
    2.11 -		*	@return True if the value can be read and false if it cannot.
    2.12 -		*
    2.13 -		*	@param ptr The pointer to the memory value.
    2.14 -		*	@param len The length of the memory value to be read from the pointer.
    2.15 -		*/
    2.16 -		static bool IsBadReadPtr(const void *ptr, size_t len);
    2.17 -		static void BadReadHandler(int sig);
    2.18 -
    2.19 -		bool m_BadReadCalled;
    2.20 -		jmp_buf m_BadReadJmpBuf;
    2.21 -#endif
    2.22 -
    2.23  		META_RES m_Status, m_PrevRes, m_CurRes;
    2.24  		const void *m_OrigRet;
    2.25  		const void *m_OverrideRet;
    2.26 @@ -215,6 +199,22 @@
    2.27  		virtual void SetOrigRet(const void *ptr);		//!< Sets the original return pointer
    2.28  		virtual void SetOverrideRet(const void *ptr);	//!< Sets the override result pointer
    2.29  	};
    2.30 +
    2.31 +#ifdef __linux__
    2.32 +	/**
    2.33 +	*	@brief Checks to see if a memory value can be read from a given pointer.
    2.34 +	*
    2.35 +	*	@return True if the value can be read and false if it cannot.
    2.36 +	*
    2.37 +	*	@param ptr The pointer to the memory value.
    2.38 +	*	@param len The length of the memory value to be read from the pointer.
    2.39 +	*/
    2.40 +	bool IsBadReadPtr(const void *ptr, size_t len);
    2.41 +	void BadReadHandler(int sig);
    2.42 +
    2.43 +	bool g_BadReadCalled;
    2.44 +	jmp_buf g_BadReadJmpBuf;
    2.45 +#endif
    2.46  }
    2.47  
    2.48  #endif