Files
boost_regex/src/regex.cpp
T

121 lines
3.0 KiB
C++
Raw Normal View History

2000-09-26 11:48:28 +00:00
/*
*
2005-01-13 17:06:21 +00:00
* Copyright (c) 1998-2004
2005-01-21 17:28:42 +00:00
* John Maddock
2000-09-26 11:48:28 +00:00
*
2003-10-04 11:29:20 +00:00
* Use, modification and distribution are subject to the
2003-09-30 13:02:51 +00:00
* Boost Software License, Version 1.0. (See accompanying file
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
2000-09-26 11:48:28 +00:00
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE: regex.cpp
* VERSION: see <boost/version.hpp>
2000-09-26 11:48:28 +00:00
* DESCRIPTION: Misc boost::regbase member funnctions.
*/
#define BOOST_REGEX_SOURCE
2020-11-29 19:10:05 +00:00
#include <boost/regex/config.hpp>
2000-09-26 11:48:28 +00:00
2005-01-13 17:06:21 +00:00
#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD
2020-11-29 19:10:05 +00:00
#include <malloc.h>
#ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
#endif
2006-03-20 10:36:12 +00:00
#ifndef NOMINMAX
# define NOMINMAX
#endif
2005-01-13 17:06:21 +00:00
#define NOGDI
#define NOUSER
#include <windows.h>
2020-11-29 19:10:05 +00:00
#include <stdexcept>
#include <boost/regex/pattern_except.hpp>
#include <boost/regex/v4/protected_call.hpp>
2000-09-26 11:48:28 +00:00
2020-11-29 19:10:05 +00:00
namespace boost {
namespace BOOST_REGEX_DETAIL_NS {
2003-05-17 11:45:48 +00:00
2005-01-13 17:06:21 +00:00
static void execute_eror()
{
// we only get here after a stack overflow,
// this has to be a separate proceedure because we
// can't mix __try{}__except block with local objects
// that have destructors:
reset_stack_guard_page();
std::runtime_error err("Out of stack space, while attempting to match a regular expression.");
raise_runtime_error(err);
}
bool BOOST_REGEX_CALL abstract_protected_call::execute()const
{
__try{
return this->call();
}__except(EXCEPTION_STACK_OVERFLOW == GetExceptionCode())
{
execute_eror();
}
// We never really get here at all:
return false;
}
2003-05-17 11:45:48 +00:00
BOOST_REGEX_DECL void BOOST_REGEX_CALL reset_stack_guard_page()
{
#if defined(BOOST_REGEX_HAS_MS_STACK_GUARD) && defined(_MSC_VER) && (_MSC_VER >= 1300)
_resetstkoflw();
#else
//
// We need to locate the current page being used by the stack,
// move to the page below it and then deallocate and protect
// that page. Note that ideally we would protect only the lowest
// stack page that has been allocated: in practice there
// seems to be no easy way to locate this page, in any case as
// long as the next page is protected, then Windows will figure
// the rest out for us...
//
SYSTEM_INFO si;
GetSystemInfo(&si);
MEMORY_BASIC_INFORMATION mi;
DWORD previous_protection_status;
//
// this is an address in our stack space:
//
LPBYTE page = (LPBYTE)&page;
//
// Get the current memory page in use:
//
VirtualQuery(page, &mi, sizeof(mi));
//
// Go to the page one below this:
//
page = (LPBYTE)(mi.BaseAddress)-si.dwPageSize;
//
// Free and protect everything from the start of the
// allocation range, to the end of the page below the
// one in use:
//
if (!VirtualFree(mi.AllocationBase, (LPBYTE)page - (LPBYTE)mi.AllocationBase, MEM_DECOMMIT)
|| !VirtualProtect(page, si.dwPageSize, PAGE_GUARD | PAGE_READWRITE, &previous_protection_status))
{
throw std::bad_exception();
}
#endif
}
2003-07-07 11:44:00 +00:00
}
2020-11-29 19:10:05 +00:00
} // namspaces
2005-01-13 17:06:21 +00:00
#endif
2003-05-17 11:45:48 +00:00
2003-12-30 12:09:03 +00:00
#if defined(BOOST_RE_USE_VCL) && defined(BOOST_REGEX_DYN_LINK)
2000-09-26 11:48:28 +00:00
int WINAPI DllEntryPoint(HINSTANCE , unsigned long , void*)
{
return 1;
}
#endif