Commit 8610c520 authored by Dominik Charousset's avatar Dominik Charousset

rmdir third_party/ ; {detail => .}/logging.hpp

CMake uses official Boost.Config if available and otherwise disables
context-switching + logging.hpp is no longer a detail header
parent 1d0d815e
......@@ -67,8 +67,6 @@ endif ()
if (CPPA_LOG_LEVEL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCPPA_LOG_LEVEL=${CPPA_LOG_LEVEL}")
else ()
set(CPPA_LOG_LEVEL "0")
endif()
# set build default build type if not set
......@@ -152,49 +150,29 @@ set(LIBCPPA_SRC
src/weak_ptr_anchor.cpp
src/yield_interface.cpp)
set(boost_context third_party/boost_context)
# add third party Boost.Context sources if context-switching is enabled
if (NOT DISABLE_CONTEXT_SWITCHING)
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
if (APPLE)
set(fcontext_asm ${boost_context}/src/asm/fcontext_i386_sysv_macho_gas.S)
else ()
set(fcontext_asm ${boost_context}/src/asm/fcontext_i386_sysv_elf_gas.S)
endif ()
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
if (APPLE)
set(fcontext_asm ${boost_context}/src/asm/fcontext_x86_64_sysv_macho_gas.S)
else ()
set(fcontext_asm ${boost_context}/src/asm/fcontext_x86_64_sysv_elf_gas.S)
endif ()
else ()
message(FATAL_ERROR "Unsupported platform (neither 32 nor 64 bit)")
endif ()
set_property(SOURCE ${fcontext_asm} PROPERTY LANGUAGE CXX)
set(LIBCPPA_SRC
${LIBCPPA_SRC}
${fcontext_asm}
${boost_context}/src/stack_utils_posix.cpp
${boost_context}/src/stack_allocator_posix.cpp
${boost_context}/src/fcontext.cpp
)
endif ()
if (BOOST_ROOT)
# Prevent falling back to system paths when using a custom Boost prefix.
set(Boost_NO_SYSTEM_PATHS true)
endif ()
find_package(Boost REQUIRED)
find_package(PTHREAD REQUIRED)
link_directories(${Boost_LIBRARY_DIRS})
include_directories(. ${Boost_INCLUDE_DIRS} ${boost_context}/include ${PTHREAD_INCLUDE_DIR})
find_package(PTHREAD REQUIRED)
find_package(Boost COMPONENTS thread REQUIRED)
add_library(libcppa SHARED ${LIBCPPA_SRC})
set(INCLUDE_DIRS . ${PTHREAD_INCLUDE_DIR} ${Boost_INCLUDE_DIRS})
set(LD_DIRS ${Boost_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS})
set(LD_FLAGS ${CMAKE_LD_LIBS} ${PTHREAD_LIBRARIES} ${Boost_THREAD_LIBRARY})
target_link_libraries(libcppa ${CMAKE_LD_LIBS} ${Boost_THREAD_LIBRARY} ${PTHREAD_LIBRARIES})
if (NOT DISABLE_CONTEXT_SWITCHING)
find_package(Boost COMPONENTS context)
# without REQUIRED, find_package(Boost...) returns with Boost_FOUND=FALSE
if (NOT Boost_FOUND)
set(DISABLE_CONTEXT_SWITCHING true)
else (NOT Boost_FOUND)
set(LD_FLAGS ${LD_FLAGS} ${Boost_CONTEXT_LIBRARY})
endif (NOT Boost_FOUND)
endif (NOT DISABLE_CONTEXT_SWITCHING)
add_library(libcppa SHARED ${LIBCPPA_SRC})
set(LIBRARY_VERSION ${LIBCPPA_VERSION_MAJOR}.${LIBCPPA_VERSION_MINOR}.${LIBCPPA_VERSION_PATCH})
set(LIBRARY_SOVERSION ${LIBCPPA_VERSION_MAJOR})
......@@ -204,6 +182,10 @@ set_target_properties(libcppa
VERSION ${LIBRARY_VERSION}
OUTPUT_NAME cppa)
link_directories(${LD_DIRS})
include_directories(${INCLUDE_DIRS})
target_link_libraries(libcppa ${LD_FLAGS})
# install shared library
install(TARGETS libcppa LIBRARY DESTINATION lib)
......@@ -259,9 +241,9 @@ add_dependencies(all_benchmarks libcppa)
# set optional flags
string(TOUPPER ${CMAKE_BUILD_TYPE} build_type)
set(CONTEXT_SWITCHING true)
set(CONTEXT_SWITCHING "yes")
if (DISABLE_CONTEXT_SWITCHING)
set(CONTEXT_SWITCHING false)
set(CONTEXT_SWITCHING "no")
endif ()
# check for doxygen and add custom "doc" target to Makefile
......@@ -273,7 +255,30 @@ if (DOXYGEN_FOUND)
WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
endif ()
endif (DOXYGEN_FOUND)
set(LOG_LEVEL_STR "none")
if (CPPA_LOG_LEVEL)
if (${CPPA_LOG_LEVEL} EQUAL 0)
set(LOG_LEVEL_STR "ERROR")
elseif (${CPPA_LOG_LEVEL} EQUAL 1)
set(LOG_LEVEL_STR "WARNING")
elseif (${CPPA_LOG_LEVEL} EQUAL 2)
set(LOG_LEVEL_STR "INFO")
elseif (${CPPA_LOG_LEVEL} EQUAL 3)
set(LOG_LEVEL_STR "DEBUG")
elseif (${CPPA_LOG_LEVEL} EQUAL 4)
set(LOG_LEVEL_STR "TRACE")
else ()
set(LOG_LEVEL_STR "invalid")
endif ()
endif (CPPA_LOG_LEVEL)
if (ENABLE_DEBUG)
set(DEBUG_MODE_STR "yes")
else (ENABLE_DEBUG)
set(DEBUG_MODE_STR "no")
endif (ENABLE_DEBUG)
# done (print summary)
message("\n====================| Build Summary |===================="
......@@ -281,12 +286,14 @@ message("\n====================| Build Summary |===================="
"\nLibcppa version: ${LIBRARY_VERSION}"
"\n"
"\nBuild type: ${CMAKE_BUILD_TYPE}"
"\nDebug mode: ${ENABLE_DEBUG}"
"\nLog level: ${CPPA_LOG_LEVEL}"
"\nDebug mode: ${DEBUG_MODE_STR}"
"\nLog level: ${LOG_LEVEL_STR}"
"\nContext switching: ${CONTEXT_SWITCHING}"
"\n"
"\nCXX: ${CMAKE_CXX_COMPILER}"
"\nCXXFLAGS: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${build_type}}"
"\nLD_DIRS: ${LD_DIRS}"
"\nLIBRARIES: ${LD_FLAGS}"
"\n"
"\nSource directory: ${CMAKE_SOURCE_DIR}"
"\nBuild directory: ${CMAKE_BINARY_DIR}"
......
......@@ -47,7 +47,7 @@ Usage: $0 [OPTION]... [VAR=VALUE]...
Platform-Dependent Adjustments:
--disable-context-switching compile libcppa without context-switching actors
on platforms where Boost.Context is not available
even if Boost.Context is available
Required Packages in Non-Standard Locations:
--with-boost=PATH path to Boost install root
......
......@@ -282,7 +282,7 @@ cppa/network/protocol.hpp
src/protocol.cpp
cppa/network/default_protocol.hpp
src/default_protocol.cpp
cppa/detail/logging.hpp
cppa/logging.hpp
src/logging.cpp
cppa/network/continuable_writer.hpp
src/continuable_writer.cpp
......
......@@ -35,6 +35,7 @@
namespace cppa {
class logging;
class scheduler;
class msg_content;
......@@ -44,7 +45,6 @@ namespace cppa { namespace network { class middleman; } }
namespace cppa { namespace detail {
class logging;
class empty_tuple;
class group_manager;
class abstract_tuple;
......
......@@ -48,13 +48,13 @@
* using a log4j viewer, e.g., http://code.google.com/p/otroslogviewer/
*
*/
namespace cppa {
namespace cppa { namespace detail {
namespace detail { class singleton_manager; }
class logging {
friend class singleton_manager;
friend class detail::singleton_manager;
public:
......@@ -110,11 +110,11 @@ class logging {
};
} } // namespace cppa::detail
} // namespace cppa
#define CPPA_VOID_STMT static_cast<void>(0)
#ifndef CPPA_DEBUG
#ifndef CPPA_LOG_LEVEL
#define CPPA_LOG_ERROR(unused) CPPA_VOID_STMT
#define CPPA_LOG_ERROR_IF(unused1,unused2) CPPA_VOID_STMT
......@@ -158,10 +158,6 @@ class logging {
#define CPPA_LOG_ERROR(message) CPPA_DO_LOG_MEMBER_FUN("ERROR ", message)
#define CPPA_LOGF_ERROR(message) CPPA_DO_LOG_FUN("ERROR ", message)
#ifndef CPPA_LOG_LEVEL
#define CPPA_LOG_LEVEL 0
#endif
#if CPPA_LOG_LEVEL > 0
# define CPPA_LOG_WARNING(message) CPPA_DO_LOG_MEMBER_FUN("WARNING", message)
# define CPPA_LOGF_WARNING(message) CPPA_DO_LOG_FUN("WARNING", message)
......
......@@ -35,12 +35,11 @@
#include <utility>
#include "cppa/config.hpp"
#include "cppa/logging.hpp"
#include "cppa/network/continuable_reader.hpp"
#include "cppa/network/continuable_writer.hpp"
#include "cppa/detail/logging.hpp"
namespace cppa { namespace network {
typedef int event_bitmask;
......
......@@ -32,14 +32,13 @@
#include <limits>
#include <stdexcept>
#include "cppa/logging.hpp"
#include "cppa/attachable.hpp"
#include "cppa/exit_reason.hpp"
#include "cppa/detail/actor_registry.hpp"
#include "cppa/util/shared_lock_guard.hpp"
#include "cppa/util/upgrade_lock_guard.hpp"
#include "cppa/detail/logging.hpp"
namespace {
typedef std::lock_guard<cppa::util::shared_spinlock> exclusive_guard;
......
......@@ -38,7 +38,7 @@
#include <stdexcept>
#include <type_traits>
#include "cppa/detail/logging.hpp"
#include "cppa/logging.hpp"
#include "cppa/binary_deserializer.hpp"
using namespace std;
......
......@@ -126,6 +126,6 @@ resume_result context_switching_actor::resume(util::fiber* from) {
#else // ifdef CPPA_DISABLE_CONTEXT_SWITCHING
namespace { int keep_compiler_happy() { return 42; } }
namespace cppa { int keep_compiler_happy_function() { return 42; } }
#endif // ifdef CPPA_DISABLE_CONTEXT_SWITCHING
......@@ -30,6 +30,7 @@
#include <cstdint>
#include "cppa/logging.hpp"
#include "cppa/to_string.hpp"
#include "cppa/serializer.hpp"
#include "cppa/deserializer.hpp"
......@@ -38,7 +39,6 @@
#include "cppa/network/default_actor_proxy.hpp"
#include "cppa/network/default_actor_addressing.hpp"
#include "cppa/detail/logging.hpp"
#include "cppa/detail/actor_registry.hpp"
#include "cppa/detail/singleton_manager.hpp"
......
......@@ -30,10 +30,10 @@
#include "cppa/to_string.hpp"
#include "cppa/logging.hpp"
#include "cppa/network/middleman.hpp"
#include "cppa/network/default_actor_proxy.hpp"
#include "cppa/detail/logging.hpp"
#include "cppa/detail/singleton_manager.hpp"
using namespace std;
......
......@@ -34,13 +34,13 @@
#include "cppa/on.hpp"
#include "cppa/actor.hpp"
#include "cppa/match.hpp"
#include "cppa/logging.hpp"
#include "cppa/to_string.hpp"
#include "cppa/exit_reason.hpp"
#include "cppa/actor_proxy.hpp"
#include "cppa/binary_serializer.hpp"
#include "cppa/binary_deserializer.hpp"
#include "cppa/detail/logging.hpp"
#include "cppa/detail/demangle.hpp"
#include "cppa/detail/actor_registry.hpp"
#include "cppa/detail/singleton_manager.hpp"
......
......@@ -31,6 +31,7 @@
#include <iostream>
#include <exception>
#include "cppa/logging.hpp"
#include "cppa/to_string.hpp"
#include "cppa/process_information.hpp"
......@@ -38,7 +39,6 @@
#include "cppa/network/default_peer.hpp"
#include "cppa/network/default_peer_acceptor.hpp"
#include "cppa/detail/logging.hpp"
#include "cppa/detail/demangle.hpp"
using namespace std;
......
......@@ -32,6 +32,7 @@
#include <cstdint>
#include <iostream>
#include "cppa/logging.hpp"
#include "cppa/to_string.hpp"
#include "cppa/network/middleman.hpp"
......@@ -41,7 +42,6 @@
#include "cppa/network/default_protocol.hpp"
#include "cppa/network/default_peer_acceptor.hpp"
#include "cppa/detail/logging.hpp"
#include "cppa/detail/actor_registry.hpp"
#include "cppa/detail/singleton_manager.hpp"
......
......@@ -33,9 +33,9 @@
#include <errno.h>
#include <iostream>
#include "cppa/logging.hpp"
#include "cppa/exception.hpp"
#include "cppa/detail/fd_util.hpp"
#include "cppa/detail/logging.hpp"
#include "cppa/network/ipv4_io_stream.hpp"
#ifdef CPPA_WINDOWS
......
......@@ -38,13 +38,13 @@
#include <sys/types.h>
#endif
#include "cppa/detail/logging.hpp"
#include "cppa/logging.hpp"
#include "cppa/detail/singleton_manager.hpp"
#include "cppa/intrusive/single_reader_queue.hpp"
using namespace std;
namespace cppa { namespace detail {
namespace cppa {
namespace {
......@@ -135,8 +135,8 @@ class logging_impl : public logging {
logging::~logging() { }
logging* logging::instance() { return singleton_manager::get_logger(); }
logging* logging::instance() { return detail::singleton_manager::get_logger(); }
logging* logging::create_singleton() { return new logging_impl; }
} } // namespace cppa::detail
} // namespace cppa
......@@ -41,6 +41,7 @@
#include "cppa/match.hpp"
#include "cppa/config.hpp"
#include "cppa/either.hpp"
#include "cppa/logging.hpp"
#include "cppa/to_string.hpp"
#include "cppa/actor_proxy.hpp"
#include "cppa/binary_serializer.hpp"
......@@ -58,7 +59,6 @@
#include "cppa/network/addressed_message.hpp"
#include "cppa/network/middleman_event_handler_base.hpp"
#include "cppa/detail/logging.hpp"
#include "cppa/detail/fd_util.hpp"
#include "cppa/detail/actor_registry.hpp"
......
......@@ -28,11 +28,10 @@
\******************************************************************************/
#include "cppa/logging.hpp"
#include "cppa/network/protocol.hpp"
#include "cppa/network/middleman.hpp"
#include "cppa/detail/logging.hpp"
namespace cppa { namespace network {
protocol::protocol(abstract_middleman* parent) : m_parent(parent) { }
......
......@@ -31,6 +31,7 @@
#include <atomic>
#include <iostream>
#include "cppa/logging.hpp"
#include "cppa/scheduler.hpp"
#include "cppa/exception.hpp"
#include "cppa/any_tuple.hpp"
......@@ -39,7 +40,6 @@
#include "cppa/network/middleman.hpp"
#include "cppa/detail/logging.hpp"
#include "cppa/detail/actor_count.hpp"
#include "cppa/detail/empty_tuple.hpp"
#include "cppa/detail/group_manager.hpp"
......
......@@ -43,6 +43,7 @@
#include "cppa/atom.hpp"
#include "cppa/actor.hpp"
#include "cppa/object.hpp"
#include "cppa/logging.hpp"
#include "cppa/any_tuple.hpp"
#include "cppa/announce.hpp"
#include "cppa/any_tuple.hpp"
......@@ -53,7 +54,6 @@
#include "cppa/util/duration.hpp"
#include "cppa/util/void_type.hpp"
#include "cppa/detail/logging.hpp"
#include "cppa/detail/demangle.hpp"
#include "cppa/detail/object_array.hpp"
#include "cppa/detail/actor_registry.hpp"
......
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CTX_ALL_H
#define BOOST_CTX_ALL_H
#include <boost/context/fcontext.hpp>
#include <boost/context/stack_allocator.hpp>
#include <boost/context/stack_utils.hpp>
#endif // BOOST_CTX_ALL_H
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CTX_DETAIL_CONFIG_H
#define BOOST_CTX_DETAIL_CONFIG_H
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#ifdef BOOST_CONTEXT_DECL
# undef BOOST_CONTEXT_DECL
#endif
#if defined(BOOST_HAS_DECLSPEC)
# if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_CONTEXT_DYN_LINK)
# if ! defined(BOOST_DYN_LINK)
# define BOOST_DYN_LINK
# endif
# if defined(BOOST_CONTEXT_SOURCE)
# define BOOST_CONTEXT_DECL BOOST_SYMBOL_EXPORT
# else
# define BOOST_CONTEXT_DECL BOOST_SYMBOL_IMPORT
# endif
# endif
#endif
#if ! defined(BOOST_CONTEXT_DECL)
# define BOOST_CONTEXT_DECL
#endif
#if ! defined(BOOST_CONTEXT_SOURCE) && ! defined(BOOST_ALL_NO_LIB) && ! defined(BOOST_CONTEXT_NO_LIB)
# define BOOST_LIB_NAME boost_context
# if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_CONTEXT_DYN_LINK)
# define BOOST_DYN_LINK
# endif
# include <boost/config/auto_link.hpp>
#endif
#endif // BOOST_CTX_DETAIL_CONFIG_H
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CTX_DETAIL_FCONTEXT_ARM_H
#define BOOST_CTX_DETAIL_FCONTEXT_ARM_H
#include <boost/config.hpp>
#include <boost/cstdint.hpp>
#include <boost/context/detail/config.hpp>
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
namespace boost {
namespace ctx {
extern "C" {
#define BOOST_CONTEXT_CALLDECL
struct stack_t
{
void * base;
void * limit;
stack_t() :
base( 0), limit( 0)
{}
};
struct fp_t
{
boost::uint32_t fc_freg[16];
fp_t() :
fc_freg()
{}
};
struct fcontext_t
{
boost::uint32_t fc_greg[11];
stack_t fc_stack;
fp_t fc_fp;
fcontext_t() :
fc_greg(),
fc_stack(),
fc_fp()
{}
};
}
}}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#endif // BOOST_CTX_DETAIL_FCONTEXT_ARM_H
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CTX_DETAIL_FCONTEXT_I386H
#define BOOST_CTX_DETAIL_FCONTEXT_I386H
#include <cstddef>
#include <boost/config.hpp>
#include <boost/cstdint.hpp>
#include <boost/context/detail/config.hpp>
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
namespace boost {
namespace ctx {
extern "C" {
#define BOOST_CONTEXT_CALLDECL __attribute__((cdecl))
struct stack_t
{
void * base;
void * limit;
stack_t() :
base( 0), limit( 0)
{}
};
struct fp_t
{
boost::uint32_t fc_freg[2];
fp_t() :
fc_freg()
{}
};
struct fcontext_t
{
boost::uint32_t fc_greg[6];
stack_t fc_stack;
fp_t fc_fp;
fcontext_t() :
fc_greg(),
fc_stack(),
fc_fp()
{}
};
}
}}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#endif // BOOST_CTX_DETAIL_FCONTEXT_I386_H
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CTX_DETAIL_FCONTEXT_I386H
#define BOOST_CTX_DETAIL_FCONTEXT_I386H
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
#include <boost/config.hpp>
#include <boost/cstdint.hpp>
#include <boost/context/detail/config.hpp>
#pragma warning(push)
#pragma warning(disable:4351)
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
namespace boost {
namespace ctx {
extern "C" {
#define BOOST_CONTEXT_CALLDECL __cdecl
struct stack_t
{
void * base;
void * limit;
stack_t() :
base( 0), limit( 0)
{}
};
struct fp_t
{
boost::uint32_t fc_freg[2];
fp_t() :
fc_freg()
{}
};
struct fcontext_t
{
boost::uint32_t fc_greg[6];
stack_t fc_stack;
void * fc_excpt_lst;
void * fc_local_storage;
fp_t fc_fp;
fcontext_t() :
fc_greg(),
fc_stack(),
fc_excpt_lst( 0),
fc_local_storage( 0),
fc_fp()
{}
};
}
}}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#pragma warning(pop)
#endif // BOOST_CTX_DETAIL_FCONTEXT_I386_H
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CTX_DETAIL_FCONTEXT_MIPS_H
#define BOOST_CTX_DETAIL_FCONTEXT_MIPS_H
#include <boost/config.hpp>
#include <boost/cstdint.hpp>
#include <boost/context/detail/config.hpp>
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
namespace boost {
namespace ctx {
extern "C" {
#define BOOST_CONTEXT_CALLDECL
// on MIPS we assume 64bit regsiters - even for 32bit ABIs
struct stack_t
{
void * base;
void * limit;
stack_t() :
base( 0), limit( 0)
{}
};
struct fp_t
{
boost::uint64_t fc_freg[6];
fp_t() :
fc_freg()
{}
};
struct fcontext_t
{
boost::uint64_t fc_greg[13];
stack_t fc_stack;
fp_t fc_fp;
fcontext_t() :
fc_greg(),
fc_stack(),
fc_fp()
{}
};
}
}}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#endif // BOOST_CTX_DETAIL_FCONTEXT_MIPS_H
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CTX_DETAIL_FCONTEXT_PPC_H
#define BOOST_CTX_DETAIL_FCONTEXT_PPC_H
#include <boost/config.hpp>
#include <boost/cstdint.hpp>
#include <boost/context/detail/config.hpp>
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
namespace boost {
namespace ctx {
extern "C" {
#define BOOST_CONTEXT_CALLDECL
struct stack_t
{
void * base;
void * limit;
stack_t() :
base( 0), limit( 0)
{}
};
struct fp_t
{
boost::uint64_t fc_freg[19];
fp_t() :
fc_freg()
{}
};
struct fcontext_t
{
# if defined(__powerpc64__)
boost::uint64_t fc_greg[23];
# else
boost::uint32_t fc_greg[23];
# endif
stack_t fc_stack;
fp_t fc_fp;
fcontext_t() :
fc_greg(),
fc_stack(),
fc_fp()
{}
};
}
}}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#endif // BOOST_CTX_DETAIL_FCONTEXT_PPC_H
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CTX_DETAIL_FCONTEXT_X86_64_H
#define BOOST_CTX_DETAIL_FCONTEXT_X86_64_H
#include <boost/config.hpp>
#include <boost/cstdint.hpp>
#include <boost/context/detail/config.hpp>
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
namespace boost {
namespace ctx {
extern "C" {
#define BOOST_CONTEXT_CALLDECL
struct stack_t
{
void * base;
void * limit;
stack_t() :
base( 0), limit( 0)
{}
};
struct fp_t
{
boost::uint32_t fc_freg[2];
fp_t() :
fc_freg()
{}
};
struct fcontext_t
{
boost::uint64_t fc_greg[8];
stack_t fc_stack;
fp_t fc_fp;
fcontext_t() :
fc_greg(),
fc_stack(),
fc_fp()
{}
};
}
}}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#endif // BOOST_CTX_DETAIL_FCONTEXT_X86_64_H
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CTX_DETAIL_FCONTEXT_X86_64_H
#define BOOST_CTX_DETAIL_FCONTEXT_X86_64_H
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <boost/cstdint.hpp>
#include <boost/context/detail/config.hpp>
#pragma warning(push)
#pragma warning(disable:4351)
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
namespace boost {
namespace ctx {
extern "C" {
#define BOOST_CONTEXT_CALLDECL
struct stack_t
{
void * base;
void * limit;
stack_t() :
base( 0), limit( 0)
{}
};
struct fp_t
{
boost::uint32_t fc_freg[2];
void * fc_xmm;
char fc_buffer[175];
fp_t() :
fc_freg(),
fc_xmm( 0),
fc_buffer()
{
fc_xmm = fc_buffer;
if ( 0 != ( ( ( uintptr_t) fc_xmm) & 15) )
fc_xmm = ( char *) ( ( ( ( uintptr_t) fc_xmm) + 15) & ~0x0F);
}
};
struct fcontext_t
{
boost::uint64_t fc_greg[10];
stack_t fc_stack;
void * fc_local_storage;
fp_t fc_fp;
fcontext_t() :
fc_greg(),
fc_stack(),
fc_local_storage( 0),
fc_fp()
{}
};
}
}}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#pragma warning(pop)
#endif // BOOST_CTX_DETAIL_FCONTEXT_X86_64_H
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CTX_FCONTEXT_H
#define BOOST_CTX_FCONTEXT_H
#if defined(__PGI)
#include <stdint.h>
#endif
#include <boost/config.hpp>
#include <boost/cstdint.hpp>
#include <boost/context/detail/config.hpp>
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
// x86_64
// test x86_64 before i386 because icc might
// define __i686__ for x86_64 too
#if defined(__x86_64__) || defined(__x86_64) \
|| defined(__amd64__) || defined(__amd64) \
|| defined(_M_X64) || defined(_M_AMD64)
# if defined(BOOST_WINDOWS)
# include <boost/context/detail/fcontext_x86_64_win.hpp>
# else
# include <boost/context/detail/fcontext_x86_64.hpp>
# endif
// i386
#elif defined(i386) || defined(__i386__) || defined(__i386) \
|| defined(__i486__) || defined(__i586__) || defined(__i686__) \
|| defined(__X86__) || defined(_X86_) || defined(__THW_INTEL__) \
|| defined(__I86__) || defined(__INTEL__) || defined(__IA32__) \
|| defined(_M_IX86) || defined(_I86_)
# if defined(BOOST_WINDOWS)
# include <boost/context/detail/fcontext_i386_win.hpp>
# else
# include <boost/context/detail/fcontext_i386.hpp>
# endif
// arm
#elif defined(__arm__) || defined(__thumb__) || defined(__TARGET_ARCH_ARM) \
|| defined(__TARGET_ARCH_THUMB) || defined(_ARM)
# include <boost/context/detail/fcontext_arm.hpp>
// mips
#elif (defined(__mips) && __mips == 1) || defined(_MIPS_ISA_MIPS1) \
|| defined(_R3000)
# include <boost/context/detail/fcontext_mips.hpp>
// powerpc
#elif defined(__powerpc) || defined(__powerpc__) || defined(__ppc) \
|| defined(__ppc__) || defined(_ARCH_PPC) || defined(__POWERPC__) \
|| defined(__PPCGECKO__) || defined(__PPCBROADWAY) || defined(_XENON)
# include <boost/context/detail/fcontext_ppc.hpp>
#else
# error "platform not supported"
#endif
namespace boost {
namespace ctx {
namespace detail {
extern "C" BOOST_CONTEXT_DECL void * BOOST_CONTEXT_CALLDECL align_stack( void * vp);
}
extern "C" BOOST_CONTEXT_DECL
intptr_t BOOST_CONTEXT_CALLDECL jump_fcontext( fcontext_t * ofc, fcontext_t const* nfc, intptr_t vp, bool preserve_fpu = true);
extern "C" BOOST_CONTEXT_DECL
void BOOST_CONTEXT_CALLDECL make_fcontext( fcontext_t * fc, void (* fn)( intptr_t) );
}}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#endif // BOOST_CTX_FCONTEXT_H
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CTX_STACK_ALLOCATOR_H
#define BOOST_CTX_STACK_ALLOCATOR_H
#include <cstddef>
#include <boost/config.hpp>
#include <boost/context/detail/config.hpp>
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
namespace boost {
namespace ctx {
class BOOST_CONTEXT_DECL stack_allocator
{
public:
void * allocate( std::size_t) const;
void deallocate( void *, std::size_t) const;
};
}}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#endif // BOOST_CTX_STACK_ALLOCATOR_H
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CTX_STACK_UTILS_H
#define BOOST_CTX_STACK_UTILS_H
#include <cstddef>
#include <boost/config.hpp>
#include <boost/context/detail/config.hpp>
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
namespace boost {
namespace ctx {
BOOST_CONTEXT_DECL std::size_t default_stacksize();
BOOST_CONTEXT_DECL std::size_t minimum_stacksize();
BOOST_CONTEXT_DECL std::size_t maximum_stacksize();
BOOST_CONTEXT_DECL std::size_t pagesize();
BOOST_CONTEXT_DECL std::size_t page_count( std::size_t stacksize);
BOOST_CONTEXT_DECL bool is_stack_unbound();
}}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#endif // BOOST_CTX_STACK_UTILS_H
/*
Copyright Oliver Kowalke 2009.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
/*******************************************************************
* *
* ------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | *
* ------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| 0x20| 0x24| *
* ------------------------------------------------------------- *
* | v1 | v2 | v3 | v4 | v5 | v6 | v7 | v8 | sp | lr | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 10 | | *
* ------------------------------------------------------------- *
* | 0x28| | *
* ------------------------------------------------------------- *
* | pc | | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 11 | 12 | | *
* ------------------------------------------------------------- *
* | 0x2c| 0x30| | *
* ------------------------------------------------------------- *
* |sbase|slimit| | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | *
* ------------------------------------------------------------- *
* | 0x34| 0x38|0x3c| 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58 | *
* ------------------------------------------------------------- *
* | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | s24 | s25 | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 23 | 24 | 25 | 26 | 27 | 28 | | *
* ------------------------------------------------------------- *
* | 0x5c| 0x60| 0x64| 0x68| 0x6c| 0x70| | *
* ------------------------------------------------------------- *
* | s26 | s27 | s28 | s29 | s30 | s31 | | *
* ------------------------------------------------------------- *
* *
* *****************************************************************/
.text
.globl jump_fcontext
.align 2
.type jump_fcontext,%function
jump_fcontext:
stmia a1, {v1-v8,sp-lr} @ save V1-V8,SP-LR
str lr, [a1,#40] @ save LR as PC
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
cmp a4, #0 @ test if fpu env should be preserved
be 1f
ldr a4, [a1,#52]
stmia a4, {s16-s31} @ save S16-S31
ldr a4, [a2,#52]
ldmia a4, {s16-s31} @ restore S16-S31
1:
#endif
mov a1, a3 @ use third arg as return value after jump
@ and as first arg in context function
ldmia a2, {v1-v8,sp-pc} @ restore v1-V8,SP-PC
.size jump_fcontext,.-jump_fcontext
.text
.globl make_fcontext
.align 2
.type make_fcontext,%function
make_fcontext:
str a1, [a1,#0] @ save the address of passed context
str a2, [a1,#40] @ save address of the context function
ldr a2, [a1,#44] @ load the stack base
push {a1,lr} @ save pointer to fcontext_t
mov a1, a2 @ stack pointer as arg for align_stack
bl align_stack@PLT @ align stack
mov a2, a1 @ begin of aligned stack
pop {a1,lr} @ restore pointer to fcontext_t
str a2, [a1,#32] @ save the aligned stack base
adr a2, finish @ address of finish; called after context function returns
str a2, [a1,#36]
mov a1, #0
bx lr
finish:
mov a1, #0 @ exit code is zero
bl _exit@PLT @ exit application
.size make_fcontext,.-make_fcontext
; Copyright Oliver Kowalke 2009.
; Distributed under the Boost Software License, Version 1.0.
; (See accompanying file LICENSE_1_0.txt or copy at
; http://www.boost.org/LICENSE_1_0.txt)
; --------------------------------------------------------------
; | 0 | 1 | 2 | 3 | 4 | 5 |
; --------------------------------------------------------------
; | 0h | 04h | 08h | 0ch | 010h | 014h |
; --------------------------------------------------------------
; | EDI | ESI | EBX | EBP | ESP | EIP |
; --------------------------------------------------------------
; --------------------------------------------------------------
; | 6 | 7 | |
; --------------------------------------------------------------
; | 018h | 01ch | |
; --------------------------------------------------------------
; | ss_base | ss_limit| |
; --------------------------------------------------------------
; --------------------------------------------------------------
; | 8 | |
; --------------------------------------------------------------
; | 020h | |
; --------------------------------------------------------------
; |fc_execpt| |
; --------------------------------------------------------------
; --------------------------------------------------------------
; | 9 | |
; --------------------------------------------------------------
; | 024h | |
; --------------------------------------------------------------
; |fc_strage| |
; --------------------------------------------------------------
; --------------------------------------------------------------
; | 10 | 11 | |
; --------------------------------------------------------------
; | 028h | 02ch | |
; --------------------------------------------------------------
; | fc_mxcsr|fc_x87_cw| |
; --------------------------------------------------------------
.386
.XMM
.model flat, c
_exit PROTO, value:SDWORD
align_stack PROTO, vp:DWORD
seh_fcontext PROTO, except:DWORD, frame:DWORD, context:DWORD, dispatch:DWORD
.code
jump_fcontext PROC EXPORT
mov ecx, [esp+04h] ; load address of the first fcontext_t arg
mov [ecx], edi ; save EDI
mov [ecx+04h], esi ; save ESI
mov [ecx+08h], ebx ; save EBX
mov [ecx+0ch], ebp ; save EBP
assume fs:nothing
mov edx, fs:[018h] ; load NT_TIB
assume fs:error
mov eax, [edx] ; load current SEH exception list
mov [ecx+020h], eax ; save current exception list
mov eax, [edx+04h] ; load current stack base
mov [ecx+018h], eax ; save current stack base
mov eax, [edx+08h] ; load current stack limit
mov [ecx+01ch], eax ; save current stack limit
mov eax, [edx+010h] ; load fiber local storage
mov [ecx+024h], eax ; save fiber local storage
lea eax, [esp+04h] ; exclude the return address
mov [ecx+010h], eax ; save as stack pointer
mov eax, [esp] ; load return address
mov [ecx+014h], eax ; save return address
mov edx, [esp+08h] ; load address of the second fcontext_t arg
mov edi, [edx] ; restore EDI
mov esi, [edx+04h] ; restore ESI
mov ebx, [edx+08h] ; restore EBX
mov ebp, [edx+0ch] ; restore EBP
mov eax, [esp+010h] ; check if fpu enve preserving was requested
test eax, eax
je nxt
stmxcsr [ecx+028h] ; save MMX control word
fnstcw [ecx+02ch] ; save x87 control word
ldmxcsr [edx+028h] ; restore MMX control word
fldcw [edx+02ch] ; restore x87 control word
nxt:
mov ecx, edx
assume fs:nothing
mov edx, fs:[018h] ; load NT_TIB
assume fs:error
mov eax, [ecx+020h] ; load SEH exception list
mov [edx], eax ; restore next SEH item
mov eax, [ecx+018h] ; load stack base
mov [edx+04h], eax ; restore stack base
mov eax, [ecx+01ch] ; load stack limit
mov [edx+08h], eax ; restore stack limit
mov eax, [ecx+024h] ; load fiber local storage
mov [edx+010h], eax ; restore fiber local storage
mov eax, [esp+0ch] ; use third arg as return value after jump
mov esp, [ecx+010h] ; restore ESP
mov [esp+04h], eax ; use third arg as first arg in context function
mov ecx, [ecx+014h] ; fetch the address to return to
jmp ecx ; indirect jump to context
jump_fcontext ENDP
make_fcontext PROC EXPORT
mov eax, [esp+04h] ; load address of the fcontext_t arg0
mov [eax], eax ; save the address of passed context
mov ecx, [esp+08h] ; load the address of the context function
mov [eax+014h], ecx ; save the address of the context function
mov edx, [eax+018h] ; load the stack base
push eax ; save pointer to fcontext_t
push edx ; stack pointer as arg for align_stack
call align_stack ; align stack
mov edx, eax ; begin of aligned stack
pop eax ; remove arg for align_stack
pop eax ; restore pointer to fcontext_t
lea edx, [edx-014h] ; reserve space for last frame on stack, (ESP + 4) & 15 == 0
mov [eax+010h], edx ; save the aligned stack
mov ecx, seh_fcontext ; set ECX to exception-handler
mov [edx+0ch], ecx ; save ECX as SEH handler
mov ecx, 0ffffffffh ; set ECX to -1
mov [edx+08h], ecx ; save ECX as next SEH item
lea ecx, [edx+08h] ; load address of next SEH item
mov [eax+02ch], ecx ; save next SEH
stmxcsr [eax+028h] ; save MMX control word
fnstcw [eax+02ch] ; save x87 control word
mov ecx, finish ; address of finish
mov [edx], ecx
xor eax, eax
ret
finish:
xor eax, eax
push eax ; exit code is zero
call _exit ; exit application
hlt
make_fcontext ENDP
END
/*
Copyright Oliver Kowalke 2009.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
/********************************************************************
* *
* -------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | *
* -------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | *
* -------------------------------------------------------------- *
* | EDI | ESI | EBX | EBP | ESP | EIP | *
* -------------------------------------------------------------- *
* -------------------------------------------------------------- *
* | 6 | 7 | | *
* -------------------------------------------------------------- *
* | 0x18 | 0x1c | | *
* -------------------------------------------------------------- *
* | sbase | slimit | | *
* -------------------------------------------------------------- *
* -------------------------------------------------------------- *
* | 8 | 9 | | *
* -------------------------------------------------------------- *
* | 0x20 | 0x24 | | *
* -------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| | *
* -------------------------------------------------------------- *
* *
* *****************************************************************/
.text
.globl jump_fcontext
.align 2
.type jump_fcontext,@function
jump_fcontext:
movl 0x4(%esp), %ecx /* load address of the first fcontext_t arg */
movl %edi, (%ecx) /* save EDI */
movl %esi, 0x4(%ecx) /* save ESI */
movl %ebx, 0x8(%ecx) /* save EBX */
movl %ebp, 0xc(%ecx) /* save EBP */
leal 0x4(%esp), %eax /* exclude the return address */
movl %eax, 0x10(%ecx) /* save as stack pointer */
movl (%esp), %eax /* load return address */
movl %eax, 0x14(%ecx) /* save return address */
movl 0x8(%esp), %edx /* load address of the second fcontext_t arg */
movl (%edx), %edi /* restore EDI */
movl 0x4(%edx), %esi /* restore ESI */
movl 0x8(%edx), %ebx /* restore EBX */
movl 0xc(%edx), %ebp /* restore EBP */
movl 0x10(%esp), %eax /* check if fpu enve preserving was requested */
test %eax, %eax
je 1f
stmxcsr 0x20(%ecx) /* save MMX control and status word */
fnstcw 0x24(%ecx) /* save x87 control word */
ldmxcsr 0x20(%edx) /* restore MMX control and status word */
fldcw 0x24(%edx) /* restore x87 control word */
1:
movl 0xc(%esp), %eax /* use third arg as return value after jump */
movl 0x10(%edx), %esp /* restore ESP */
movl %eax, 0x4(%esp) /* use third arg as first arg in context function */
movl 0x14(%edx), %edx /* fetch the address to return to */
jmp *%edx /* indirect jump to context */
.size jump_fcontext,.-jump_fcontext
.text
.globl make_fcontext
.align 2
.type make_fcontext,@function
make_fcontext:
movl 0x4(%esp), %eax /* load address of the fcontext_t */
movl %eax, (%eax) /* save the address of current context */
movl 0x8(%esp), %ecx /* load the address of the context function */
movl %ecx, 0x14(%eax) /* save the address of the context function */
movl 0x18(%eax), %edx /* load the stack base */
pushl %eax /* save pointer to fcontext_t */
pushl %ebx /* save EBX */
pushl %edx /* stack pointer as arg for align_stack */
call 1f
1: popl %ebx /* address of label 1 */
addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx /* compute address of GOT and store it in EBX */
call align_stack@PLT /* align stack */
movl %eax, %edx /* begin of aligned stack */
popl %eax /* remove arg for align_stack */
popl %ebx /* restore EBX */
popl %eax /* restore pointer to fcontext_t */
leal -0x14(%edx), %edx /* reserve space for the last frame on stack, (ESP + 4) % 16 == 0 */
movl %edx, 0x10(%eax) /* save the aligned stack base */
stmxcsr 0x20(%eax) /* save MMX control and status word */
fnstcw 0x24(%eax) /* save x87 control word */
call 2f
2: popl %ecx /* address of label 2 */
addl $finish-2b, %ecx /* helper code executed after context function returns */
movl %ecx, (%edx)
xorl %eax, %eax
ret
finish:
leal -0xc(%esp), %esp
call 3f
3: popl %ebx /* address of label 3 */
addl $_GLOBAL_OFFSET_TABLE_+[.-3b], %ebx /* compute address of GOT and store it in EBX */
xorl %eax, %eax
pushl %eax /* exit code is zero */
call _exit@PLT /* exit application */
hlt
.size make_fcontext,.-make_fcontext
/*
Copyright Oliver Kowalke 2009.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
/********************************************************************
* *
* -------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | *
* -------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | *
* -------------------------------------------------------------- *
* | EDI | ESI | EBX | EBP | ESP | EIP | *
* -------------------------------------------------------------- *
* -------------------------------------------------------------- *
* | 6 | 7 | | *
* -------------------------------------------------------------- *
* | 0x18 | 0x1c | | *
* -------------------------------------------------------------- *
* | sbase | slimit | | *
* -------------------------------------------------------------- *
* -------------------------------------------------------------- *
* | 8 | 9 | | *
* -------------------------------------------------------------- *
* | 0x20 | 0x24 | | *
* -------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| | *
* -------------------------------------------------------------- *
* *
* *****************************************************************/
.text
.globl _jump_fcontext
.align 2
_jump_fcontext:
movl 0x4(%esp), %ecx /* load address of the first fcontext_t arg */
movl %edi, (%ecx) /* save EDI */
movl %esi, 0x4(%ecx) /* save ESI */
movl %ebx, 0x8(%ecx) /* save EBX */
movl %ebp, 0xc(%ecx) /* save EBP */
leal 0x4(%esp), %eax /* exclude the return address */
movl %eax, 0x10(%ecx) /* save as stack pointer */
movl (%esp), %eax /* load return address */
movl %eax, 0x14(%ecx) /* save return address */
movl 0x8(%esp), %edx /* load address of the second fcontext_t arg */
movl (%edx), %edi /* restore EDI */
movl 0x4(%edx), %esi /* restore ESI */
movl 0x8(%edx), %ebx /* restore EBX */
movl 0xc(%edx), %ebp /* restore EBP */
movl 0x10(%esp), %eax /* check if fpu enve preserving was requested */
test %eax, %eax
je 1f
stmxcsr 0x20(%ecx) /* save MMX control and status word */
fnstcw 0x24(%ecx) /* save x87 control word */
ldmxcsr 0x20(%edx) /* restore MMX control and status word */
fldcw 0x24(%edx) /* restore x87 control word */
1:
movl 0xc(%esp), %eax /* use third arg as return value after jump */
movl 0x10(%edx), %esp /* restore ESP */
movl %eax, 0x4(%esp) /* use third arg as first arg in context function */
movl 0x14(%edx), %edx /* fetch the address to return to */
jmp *%edx /* indirect jump to context */
.text
.globl _make_fcontext
.align 2
_make_fcontext:
movl 0x4(%esp), %eax /* load address of the fcontext_t */
movl %eax, (%eax) /* save the address of current context */
movl 0x8(%esp), %ecx /* load the address of the context function */
movl %ecx, 0x14(%eax) /* save the address of the context function */
movl 0x18(%eax), %edx /* load the stack base */
pushl %eax /* save pointer to fcontext_t */
pushl %ebx /* save EBX */
pushl %edx /* stack pointer as arg for align_stack */
call 1f
1: popl %ebx /* address of label 1 */
addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx /* compute address of GOT and store it in EBX */
call align_stack@PLT /* align stack */
movl %eax, %edx /* begin of aligned stack */
popl %eax /* remove arg for align_stack */
popl %ebx /* restore EBX */
popl %eax /* restore pointer to fcontext_t */
leal -0x14(%edx), %edx /* reserve space for the last frame on stack, (ESP + 4) % 16 == 0 */
movl %edx, 0x10(%eax) /* save the aligned stack base */
stmxcsr 0x20(%eax) /* save MMX control and status word */
fnstcw 0x24(%eax) /* save x87 control word */
call 2f
2: popl %ecx /* address of label 2 */
addl $finish-2b, %ecx /* helper code executed after context function returns */
movl %ecx, (%edx)
xorl %eax, %eax
ret
finish:
leal -0xc(%esp), %esp
call 3f
3: popl %ebx /* address of label 3 */
addl $_GLOBAL_OFFSET_TABLE_+[.-3b], %ebx /* compute address of GOT and store it in EBX */
xorl %eax, %eax
pushl %eax /* exit code is zero */
call _exit@PLT /* exit application */
hlt
/*
Copyright Oliver Kowalke 2009.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
/*******************************************************************
* *
* ------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | *
* ------------------------------------------------------------- *
* | 0 | 8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | *
* ------------------------------------------------------------- *
* | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | GP | SP | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 10 | 11 | 12 | | *
* ------------------------------------------------------------- *
* | 80 | 88 | 96 | | *
* ------------------------------------------------------------- *
* | S8 | RA | PC | | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 13 | 14 | | *
* ------------------------------------------------------------- *
* | 104 | 112 | | *
* ------------------------------------------------------------- *
* |sbase|slimt| | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 15 | 16 | 17 | 18 | 19 | 20 | | *
* ------------------------------------------------------------- *
* | 120 | 128 | 136 | 144 | 152 | 160 | | *
* ------------------------------------------------------------- *
* | F20 | F22 | F24 | F26 | F28 | F30 | | *
* ------------------------------------------------------------- *
* *
* *****************************************************************/
.text
.globl jump_fcontext
.align 2
.type jump_fcontext,@function
.ent jump_fcontext
jump_fcontext:
sw $s0, ($a0) # save S0
sw $s1, 8($a0) # save S1
sw $s2, 16($a0) # save S2
sw $s3, 24($a0) # save S3
sw $s4, 32($a0) # save S4
sw $s5, 40($a0) # save S5
sw $s6, 48($a0) # save S6
sw $s7, 56($a0) # save S7
sw $gp, 64($a0) # save GP
sw $sp, 72($a0) # save SP
sw $s8, 80($a0) # save S8
sw $ra, 88($a0) # save RA
sw $ra, 96($a0) # save RA as PC
#if defined(__mips_hard_float)
beqz $a3, 1f # test if fpu env should be preserved
s.d $f20, 120($a0) # save F20
s.d $f22, 128($a0) # save F22
s.d $f24, 136($a0) # save F24
s.d $f26, 144($a0) # save F26
s.d $f28, 152($a0) # save F28
s.d $f30, 160($a0) # save F30
l.d $f20, 120($a1) # restore F20
l.d $f22, 128($a1) # restore F22
l.d $f24, 136($a1) # restore F24
l.d $f26, 144($a1) # restore F26
l.d $f28, 152($a1) # restore F28
l.d $f30, 160($a1) # restore F30
1:
#endif
lw $s0, ($a1) # restore S0
lw $s1, 8($a1) # restore S1
lw $s2, 16($a1) # restore S2
lw $s3, 24($a1) # restore S3
lw $s4, 32($a1) # restore S4
lw $s5, 40($a1) # restore S5
lw $s6, 48($a1) # restore S6
lw $s7, 56($a1) # restore S7
lw $gp, 64($a1) # restore GP
lw $sp, 72($a1) # restore SP
lw $s8, 80($a1) # restore S8
lw $ra, 88($a1) # restore RA
move $a0, $s2 # restore void pointer as argument
move $v0, $a2 # use third arg as return value after jump
move $a0, $a2 # use third arg as first arg in context function
lw $t9, 96($a1) # load PC
jr $t9 # jump to context
.end jump_fcontext
.size jump_fcontext, .-jump_fcontext
.text
.globl make_fcontext
.align 2
.type make_fcontext,@function
.ent make_fcontext
make_fcontext:
#ifdef __PIC__
.set noreorder
.cpload $t9
.set reorder
#endif
sw $a0, ($a0) # save the current context
sw $gp, 24($a0) # save global pointer
sw $a1, 96($a0) # save the address of the context function
lw $t0, 104($a0) # load the stack base
sub $sp, $sp, 28
sw $ra, 24($sp)
sw $a0, 20($sp)
move $a0, $t0 # stack pointer as arg for align_stack
lw $t9, %call16(align_stack)($gp) # align stack
jalr $t9
nop
move $t0, $v0 # begin of aligned stack
lw $ra, 24($sp)
lw $a0, 20($sp)
addi $sp, $sp, 28
sub $t0, $t0, 16 # reserve 16 byte of argument space
sw $t0, 72($a0) # save the algned stack base
la $t9, finish # helper code executed after context function returns
sw $t9, 88($a0)
move $v0, $zero
jr $ra
finish:
move $gp, $s3 # restore GP (global pointer)
move $a0, $zero # exit code is zero
lw $t9, %call16(_exit)($gp) # exit application
jalr $t9
.end make_fcontext
.size make_fcontext, .-make_fcontext
/*
Copyright Oliver Kowalke 2009.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
/*******************************************************************
* *
* ------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | *
* ------------------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | 32 | 36 | *
* ------------------------------------------------------------- *
* | R13 | R14 | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | *
* ------------------------------------------------------------- *
* | 40 | 44 | 48 | 52 | 56 | 60 | 64 | 68 | 72 | 76 | *
* ------------------------------------------------------------- *
* | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | R31 | SP | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 20 | 21 | 22 | | *
* ------------------------------------------------------------- *
* | 80 | 84 | 88 | | *
* ------------------------------------------------------------- *
* | CR | LR | PC | | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 23 | 24 | | *
* ------------------------------------------------------------- *
* | 92 | 96 | | *
* ------------------------------------------------------------- *
* |sbase|slimt| | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | *
* ------------------------------------------------------------- *
* | 100 | 104 | 108 | 112 | 116 | 120 | 124 | 128 | 132 | 136 | *
* ------------------------------------------------------------- *
* | F14 | F15 | F16 | F17 | F18 | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | *
* ------------------------------------------------------------- *
* | 140 | 144 | 148 | 152 | 156 | 160 | 164 | 168 | 172 | 176 | *
* ------------------------------------------------------------- *
* | F19 | F20 | F21 | F22 | F23 | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | *
* ------------------------------------------------------------- *
* | 180 | 184 | 188 | 192 | 196 | 200 | 204 | 208 | 212 | 216 | *
* ------------------------------------------------------------- *
* | F24 | F25 | F26 | F27 | F28 | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | | *
* ------------------------------------------------------------- *
* | 220 | 224 | 228 | 232 | 236 | 240 | 244 | 248 | | *
* ------------------------------------------------------------- *
* | F29 | F30 | F31 | fpscr | | *
* ------------------------------------------------------------- *
* *
* *****************************************************************/
.text
.globl jump_fcontext
.align 2
.type jump_fcontext,@function
jump_fcontext:
stw %r13, 0(%r3) # save R13
stw %r14, 4(%r3) # save R14
stw %r15, 8(%r3) # save R15
stw %r16, 12(%r3) # save R16
stw %r17, 16(%r3) # save R17
stw %r18, 20(%r3) # save R18
stw %r19, 24(%r3) # save R19
stw %r20, 28(%r3) # save R20
stw %r21, 32(%r3) # save R21
stw %r22, 36(%r3) # save R22
stw %r23, 40(%r3) # save R23
stw %r24, 44(%r3) # save R24
stw %r25, 48(%r3) # save R25
stw %r26, 52(%r3) # save R26
stw %r27, 56(%r3) # save R27
stw %r28, 60(%r3) # save R28
stw %r29, 64(%r3) # save R29
stw %r30, 68(%r3) # save R30
stw %r31, 72(%r3) # save R31
stw %r1, 76(%r3) # save SP
mfcr %r0 # load CR
stw %r0, 80(%r3) # save CR
mflr %r0 # load LR
stw %r0, 84(%r3) # save LR
stw %r0, 88(%r3) # save LR as PC
cmpwi cr7, %r6, 0 # test if fpu env should be preserved
beq cr7, 1f
stfd %f14, 100(%r3) # save F14
stfd %f15, 108(%r3) # save F15
stfd %f16, 116(%r3) # save F16
stfd %f17, 124(%r3) # save F17
stfd %f18, 132(%r3) # save F18
stfd %f19, 140(%r3) # save F19
stfd %f20, 148(%r3) # save F20
stfd %f21, 156(%r3) # save F21
stfd %f22, 164(%r3) # save F22
stfd %f23, 172(%r3) # save F23
stfd %f24, 180(%r3) # save F24
stfd %f25, 188(%r3) # save F25
stfd %f26, 196(%r3) # save F26
stfd %f27, 204(%r3) # save F27
stfd %f28, 212(%r3) # save F28
stfd %f29, 220(%r3) # save F29
stfd %f30, 228(%r3) # save F30
stfd %f31, 236(%r3) # save F31
mffs %f0 # load FPSCR
stfd %f0, 244(%r3) # save FPSCR
lfd %f14, 100(%r4) # restore F14
lfd %f15, 108(%r4) # restore F15
lfd %f16, 116(%r4) # restore F16
lfd %f17, 124(%r4) # restore F17
lfd %f18, 132(%r4) # restore F18
lfd %f19, 140(%r4) # restore F19
lfd %f20, 148(%r4) # restore F20
lfd %f21, 156(%r4) # restore F21
lfd %f22, 164(%r4) # restore F22
lfd %f23, 172(%r4) # restore F23
lfd %f24, 180(%r4) # restore F24
lfd %f25, 188(%r4) # restore F25
lfd %f26, 196(%r4) # restore F26
lfd %f27, 204(%r4) # restore F27
lfd %f28, 212(%r4) # restore F28
lfd %f29, 220(%r4) # restore F29
lfd %f30, 228(%r4) # restore F30
lfd %f31, 236(%r4) # restore F31
lfd %f0, 244(%r4) # load FPSCR
mtfsf 0xff, %f0 # restore FPSCR
1:
lwz %r13, 0(%r4) # restore R13
lwz %r14, 4(%r4) # restore R14
lwz %r15, 8(%r4) # restore R15
lwz %r16, 12(%r4) # restore R16
lwz %r17, 16(%r4) # restore R17
lwz %r18, 20(%r4) # restore R18
lwz %r19, 24(%r4) # restore R19
lwz %r20, 28(%r4) # restore R20
lwz %r21, 32(%r4) # restore R21
lwz %r22, 36(%r4) # restore R22
lwz %r23, 40(%r4) # restore R23
lwz %r24, 44(%r4) # restore R24
lwz %r25, 48(%r4) # restore R25
lwz %r26, 52(%r4) # restore R26
lwz %r27, 56(%r4) # restore R27
lwz %r28, 60(%r4) # restore R28
lwz %r29, 64(%r4) # restore R29
lwz %r30, 68(%r4) # restore R30
lwz %r31, 72(%r4) # restore R31
lwz %r1, 76(%r4) # restore SP
lwz %r0, 80(%r4) # load CR
mtcr %r0 # restore CR
lwz %r0, 84(%r4) # load LR
mtlr %r0 # restore LR
mr. %r3, %r5 # use third arg as return value after jump
# and as first arg in context function
lwz %r0, 88(%r4) # load PC
mtctr %r0 # restore CTR
bctr # jump to context
.size jump_fcontext, .-jump_fcontext
.text
.globl make_fcontext
.align 2
.type make_fcontext,@function
make_fcontext:
stw %r3, 0(%r3) # save the current context
stw %r4, 88(%r3) # save the address of the context function
lwz %r0, 92(%r3) # load the stack base
li %r4, 28
subf %r1, %r4, %r1 # reserve space on stack
stw %r3, 24(%r1) # store pointer to fcontext_t on stack
mflr %r4 # load LR
stw %r4, 20(%r1) # store LR on stack
mr. %r3, %r0 # context stack as arg to align_stack
bl align_stack@plt # call align_stack
mr. %r0, %r3 # load result into R0
lwz %r4, 20(%r1) # pop LR from stack
mtlr %r4 # restore LR
lwz %r3, 24(%r1) # pop pointer to fcontext_t from stack
addi %r1, %r1, 28 # release space on stack
li %r4, 32
subf %r0, %r4, %r0 # 32 bytes on stack for parameter area(== 8 registers)
stw %r0, 76(%r3) # save the aligned stack base
mflr %r0 # load LR
bl 1f # jump to label 1
1:
mflr %r4 # load LR
addi %r4, %r4, finish - 1b # address of finish; called after context function returns
mtlr %r0 # restore LR
stw %r4, 84(%r3)
li %r3, 0
blr
finish:
li %r3, 0 # exit code is zero
bl _exit@plt # exit application
.size make_fcontext, .-make_fcontext
/*
Copyright Oliver Kowalke 2009.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
/*******************************************************************
* *
* ------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | *
* ------------------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | 32 | 36 | *
* ------------------------------------------------------------- *
* | R13 | R14 | R15 | R16 | R17 | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | *
* ------------------------------------------------------------- *
* | 40 | 44 | 48 | 52 | 56 | 60 | 64 | 68 | 72 | 76 | *
* ------------------------------------------------------------- *
* | R18 | R19 | R20 | R21 | R22 | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | *
* ------------------------------------------------------------- *
* | 80 | 84 | 88 | 92 | 96 | 100 | 104 | 108 | 112 | 116 | *
* ------------------------------------------------------------- *
* | R23 | R24 | R25 | R26 | R27 | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------------------- *
* | 120 | 124 | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------------------- *
* | R28 | R29 | R30 | R31 | SP | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 40 | 41 | 42 | 43 | 44 | 45 | | *
* ------------------------------------------------------------- *
* | 160 | 164 | 168 | 172 | 176 | 180 | | *
* ------------------------------------------------------------- *
* | CR | LR | PC | | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 46 | 47 | 48 | 49 | | *
* ------------------------------------------------------------- *
* | 184 | 188 | 192 | 196 | | *
* ------------------------------------------------------------- *
* | sbase | slimt | | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | *
* ------------------------------------------------------------- *
* | 200 | 204 | 208 | 212 | 216 | 220 | 224 | 228 | 232 | 236 | *
* ------------------------------------------------------------- *
* | F14 | F15 | F16 | F17 | F18 | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | *
* ------------------------------------------------------------- *
* | 240 | 244 | 248 | 252 | 256 | 260 | 264 | 268 | 272 | 276 | *
* ------------------------------------------------------------- *
* | F19 | F20 | F21 | F22 | F23 | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | *
* ------------------------------------------------------------- *
* | 280 | 284 | 288 | 292 | 296 | 300 | 304 | 308 | 312 | 316 | *
* ------------------------------------------------------------- *
* | F24 | F25 | F26 | F27 | F28 | *
* ------------------------------------------------------------- *
* ------------------------------------------------------------- *
* | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | | *
* ------------------------------------------------------------- *
* | 320 | 324 | 328 | 332 | 336 | 340 | 344 | 348 | | *
* ------------------------------------------------------------- *
* | F29 | F30 | F31 | fpscr | | *
* ------------------------------------------------------------- *
* *
* *****************************************************************/
.section ".text"
.align 2
.globl jump_fcontext
.section ".opd","aw"
.align 3
jump_fcontext:
.quad .jump_fcontext,.TOC.@tocbase,0
.previous
.size jump_fcontext,24
.type .jump_fcontext,@function
.globl .jump_fcontext
.jump_fcontext:
std %r13, 0(%r3) # save R13
std %r14, 8(%r3) # save R14
std %r15, 16(%r3) # save R15
std %r16, 24(%r3) # save R16
std %r17, 32(%r3) # save R17
std %r18, 40(%r3) # save R18
std %r19, 48(%r3) # save R19
std %r20, 56(%r3) # save R20
std %r21, 64(%r3) # save R21
std %r22, 72(%r3) # save R22
std %r23, 80(%r3) # save R23
std %r24, 88(%r3) # save R24
std %r25, 96(%r3) # save R25
std %r26, 104(%r3) # save R26
std %r27, 112(%r3) # save R27
std %r28, 120(%r3) # save R28
std %r29, 128(%r3) # save R29
std %r30, 136(%r3) # save R30
std %r31, 144(%r3) # save R31
std %r1, 152(%r3) # save SP
mfcr %r0 # load CR
std %r0, 160(%r3) # save CR
mflr %r0 # load LR
std %r0, 168(%r3) # save LR
std %r0, 176(%r3) # save LR as PC
cmpwi cr7, %r6, 0 # test if fpu env should be preserved
beq cr7, 1f
stfd %f14, 200(%r3) # save F14
stfd %f15, 208(%r3) # save F15
stfd %f16, 216(%r3) # save F16
stfd %f17, 224(%r3) # save F17
stfd %f18, 232(%r3) # save F18
stfd %f19, 240(%r3) # save F19
stfd %f20, 248(%r3) # save F20
stfd %f21, 256(%r3) # save F21
stfd %f22, 264(%r3) # save F22
stfd %f23, 272(%r3) # save F23
stfd %f24, 280(%r3) # save F24
stfd %f25, 288(%r3) # save F25
stfd %f26, 296(%r3) # save F26
stfd %f27, 304(%r3) # save F27
stfd %f28, 312(%r3) # save F28
stfd %f29, 320(%r3) # save F29
stfd %f30, 328(%r3) # save F30
stfd %f31, 336(%r3) # save F31
mffs %f0 # load FPSCR
stfd %f0, 344(%r3) # save FPSCR
lfd %f14, 200(%r4) # restore F14
lfd %f15, 208(%r4) # restore F15
lfd %f16, 216(%r4) # restore F16
lfd %f17, 224(%r4) # restore F17
lfd %f18, 232(%r4) # restore F18
lfd %f19, 240(%r4) # restore F19
lfd %f20, 248(%r4) # restore F20
lfd %f21, 256(%r4) # restore F21
lfd %f22, 264(%r4) # restore F22
lfd %f23, 272(%r4) # restore F23
lfd %f24, 280(%r4) # restore F24
lfd %f25, 288(%r4) # restore F25
lfd %f26, 296(%r4) # restore F26
lfd %f27, 304(%r4) # restore F27
lfd %f28, 312(%r4) # restore F28
lfd %f29, 320(%r4) # restore F29
lfd %f30, 328(%r4) # restore F30
lfd %f31, 336(%r4) # restore F31
lfd %f0, 344(%r4) # load FPSCR
mtfsf 0xff, %f0 # restore FPSCR
1:
ld %r13, 0(%r4) # restore R13
ld %r14, 8(%r4) # restore R14
ld %r15, 16(%r4) # restore R15
ld %r16, 24(%r4) # restore R16
ld %r17, 32(%r4) # restore R17
ld %r18, 40(%r4) # restore R18
ld %r19, 48(%r4) # restore R19
ld %r20, 56(%r4) # restore R20
ld %r21, 64(%r4) # restore R21
ld %r22, 72(%r4) # restore R22
ld %r23, 80(%r4) # restore R23
ld %r24, 88(%r4) # restore R24
ld %r25, 96(%r4) # restore R25
ld %r26, 104(%r4) # restore R26
ld %r27, 112(%r4) # restore R27
ld %r28, 120(%r4) # restore R28
ld %r29, 128(%r4) # restore R29
ld %r30, 136(%r4) # restore r30
ld %r31, 144(%r4) # restore r31
ld %r1, 152(%r4) # restore SP
ld %r0, 160(%r4) # load CR
mtcr %r0 # restore CR
ld %r0, 168(%r4) # load LR
mtlr %r0 # restore LR
mr. %r3, %r5 # use third arg as return value after jump
# and as first arg in context function
ld %r0, 176(%r4) # load PC
mtctr %r0 # restore CTR
bctr # jump to context
.size .jump_fcontext, .-.jump_fcontext
.section ".text"
.align 2
.globl make_fcontext
.section ".opd","aw"
.align 3
make_fcontext:
.quad .make_fcontext,.TOC.@tocbase,0
.previous
.size make_fcontext,24
.type .make_fcontext,@function
.globl .make_fcontext
.make_fcontext:
std %r3, 0(%r3) # save the current context
std %r4, 176(%r3) # save the address of the function supposed to be run
ld %r0, 184(%r3) # load the stack base
li %r4, 56
subf %r1, %r4, %r1 # reserve space on stack
stw %r3, 48(%r1) # store pointer to fcontext_t on stack
mflr %r4 # load LR
stw %r4, 40(%r1) # store LR on stack
mr. %r3, %r0 # context stack as arg to align_stack
bl align_stack@plt # call align_stack
mr. %r0, %r3 # load result into R0
lwz %r4, 40(%r1) # pop LR from stack
mtlr %r4 # restore LR
lwz %r3, 48(%r1) # pop pointer to fcontext_t from stack
addi %r1, %r1, 56 # release space on stack
li %r4, 64
subf %r0, %r4, %r0 # 64 bytes on stack for parameter area (== 8 registers)
std %r0, 152(%r3) # save the stack base
mflr %r0 # load LR
bl 1f # jump to label 1
1:
mflr %r4 # load LR
addi %r4, %r4, finish - 1b # calulate absolute address of finish
mtlr %r0 # restore LR
std %r4, 168(%r3) # save address of finish
li %r3, 0 # set return value to zero
blr
finish:
li %r3, 0 # set return value to zero
bl _exit@plt # exit application
.size .make_fcontext, .-.make_fcontext
; Copyright Oliver Kowalke 2009.
; Distributed under the Boost Software License, Version 1.0.
; (See accompanying file LICENSE_1_0.txt or copy at
; http://www.boost.org/LICENSE_1_0.txt)
; ----------------------------------------------------------------------------------
; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
; ----------------------------------------------------------------------------------
; | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c |
; ----------------------------------------------------------------------------------
; | R12 | R13 | R14 | R15 |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
; ----------------------------------------------------------------------------------
; | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c |
; ----------------------------------------------------------------------------------
; | RDI | RSI | RBX | RBP |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 16 | 17 | 18 | 19 | |
; ----------------------------------------------------------------------------------
; | 0x40 | 0x44 | 0x48 | 0x4c | |
; ----------------------------------------------------------------------------------
; | RSP | RIP | |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 20 | 21 | 22 | 23 | |
; ----------------------------------------------------------------------------------
; | 0x50 | 0x54 | 0x58 | 0x5c | |
; ----------------------------------------------------------------------------------
; | sbase | slimit | |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 24 | 25 | |
; ----------------------------------------------------------------------------------
; | 0x60 | 0x64 | |
; ----------------------------------------------------------------------------------
; | fbr_strg | |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 26 | 27 | 28 | 29 | |
; ----------------------------------------------------------------------------------
; | 0x68 | 0x6c | 0x70 | 0x74 | |
; ----------------------------------------------------------------------------------
; | fc_mxcsr|fc_x87_cw| fc_xmm | |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 |
; ----------------------------------------------------------------------------------
; | 0x78 | 0x7c | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 |
; ----------------------------------------------------------------------------------
; | XMM6 | XMM7 |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
; ----------------------------------------------------------------------------------
; | 0x98 | 0x9c | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 |
; ----------------------------------------------------------------------------------
; | XMM8 | XMM9 |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
; ----------------------------------------------------------------------------------
; | 0x118 | 0x11c | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 |
; ----------------------------------------------------------------------------------
; | XMM10 | XMM11 |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
; ----------------------------------------------------------------------------------
; | 0x138 | 0x13c | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 |
; ----------------------------------------------------------------------------------
; | XMM12 | XMM13 |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
; ----------------------------------------------------------------------------------
; | 0x158 | 0x15c | 0x160 | 0x164 | 0x168 | 0x16c | 0x170 | 0x174 |
; ----------------------------------------------------------------------------------
; | XMM14 | XMM15 |
; ----------------------------------------------------------------------------------
EXTERN _exit:PROC ; standard C library function
EXTERN align_stack:PROC ; stack alignment
EXTERN seh_fcontext:PROC ; exception handler
.code
jump_fcontext PROC EXPORT FRAME:seh_fcontext
.endprolog
mov [rcx], r12 ; save R12
mov [rcx+08h], r13 ; save R13
mov [rcx+010h], r14 ; save R14
mov [rcx+018h], r15 ; save R15
mov [rcx+020h], rdi ; save RDI
mov [rcx+028h], rsi ; save RSI
mov [rcx+030h], rbx ; save RBX
mov [rcx+038h], rbp ; save RBP
mov r10, gs:[030h] ; load NT_TIB
mov rax, [r10+08h] ; load current stack base
mov [rcx+050h], rax ; save current stack base
mov rax, [r10+010h] ; load current stack limit
mov [rcx+058h], rax ; save current stack limit
mov rax, [r10+018h] ; load fiber local storage
mov [rcx+060h], rax ; save fiber local storage
test r9, r9
je nxt
stmxcsr [rcx+068h] ; save MMX control and status word
fnstcw [rcx+06ch] ; save x87 control word
mov r10, [rcx+070h] ; address of aligned XMM storage
movaps [r10], xmm6
movaps [r10+010h], xmm7
movaps [r10+020h], xmm8
movaps [r10+030h], xmm9
movaps [r10+040h], xmm10
movaps [r10+050h], xmm11
movaps [r10+060h], xmm12
movaps [r10+070h], xmm13
movaps [r10+080h], xmm14
movaps [r10+090h], xmm15
ldmxcsr [rdx+068h] ; restore MMX control and status word
fldcw [rdx+06ch] ; restore x87 control word
mov r10, [rdx+070h] ; address of aligned XMM storage
movaps xmm6, [r10]
movaps xmm7, [r10+010h]
movaps xmm8, [r10+020h]
movaps xmm9, [r10+030h]
movaps xmm10, [r10+040h]
movaps xmm11, [r10+050h]
movaps xmm12, [r10+060h]
movaps xmm13, [r10+070h]
movaps xmm14, [r10+080h]
movaps xmm15, [r10+090h]
nxt:
lea rax, [rsp+08h] ; exclude the return address
mov [rcx+040h], rax ; save as stack pointer
mov rax, [rsp] ; load return address
mov [rcx+048h], rax ; save return address
mov r12, [rdx] ; restore R12
mov r13, [rdx+08h] ; restore R13
mov r14, [rdx+010h] ; restore R14
mov r15, [rdx+018h] ; restore R15
mov rdi, [rdx+020h] ; restore RDI
mov rsi, [rdx+028h] ; restore RSI
mov rbx, [rdx+030h] ; restore RBX
mov rbp, [rdx+038h] ; restore RBP
mov r10, gs:[030h] ; load NT_TIB
mov rax, [rdx+050h] ; load stack base
mov [r10+08h], rax ; restore stack base
mov rax, [rdx+058h] ; load stack limit
mov [r10+010h], rax ; restore stack limit
mov rax, [rdx+060h] ; load fiber local storage
mov [r10+018h], rax ; restore fiber local storage
mov rsp, [rdx+040h] ; restore RSP
mov r10, [rdx+048h] ; fetch the address to returned to
mov rax, r8 ; use third arg as return value after jump
mov rcx, r8 ; use third arg as first arg in context function
jmp r10 ; indirect jump to caller
jump_fcontext ENDP
make_fcontext PROC EXPORT FRAME ; generate function table entry in .pdata and unwind information in E
.endprolog ; .xdata for a function's structured exception handling unwind behavior
mov [rcx], rcx ; store the address of current context
mov [rcx+048h], rdx ; save the address of the function supposed to run
mov rdx, [rcx+050h] ; load the address where the context stack beginns
push rcx ; save pointer to fcontext_t
sub rsp, 028h ; reserve shadow space for align_stack
mov rcx, rdx ; stack pointer as arg for align_stack
mov [rsp+8], rcx
call align_stack ; align stack
mov rdx, rax ; begin of aligned stack
add rsp, 028h
pop rcx ; restore pointer to fcontext_t
lea rdx, [rdx-028h] ; reserve 32byte shadow space + return address on stack, (RSP + 8) % 16 == 0
mov [rcx+040h], rdx ; save the address where the context stack beginns
stmxcsr [rcx+068h] ; save MMX control and status word
fnstcw [rcx+06ch] ; save x87 control word
lea rax, finish ; helper code executed after fn() returns
mov [rdx], rax ; store address off the helper function as return address
xor rax, rax ; set RAX to zero
ret
finish:
xor rcx, rcx
mov [rsp+08h], rcx
call _exit ; exit application
hlt
make_fcontext ENDP
END
/*
Copyright Oliver Kowalke 2009.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
/****************************************************************************************
* *
* ---------------------------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | RBX | R12 | R13 | R14 | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ---------------------------------------------------------------------------------- *
* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | *
* ---------------------------------------------------------------------------------- *
* | R15 | RBP | RSP | RIP | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 16 | 17 | 18 | 19 | | *
* ---------------------------------------------------------------------------------- *
* | 0x40 | 0x44 | 0x48 | 0x4c | | *
* ---------------------------------------------------------------------------------- *
* | sbase | slimit | | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 20 | 21 | | *
* ---------------------------------------------------------------------------------- *
* | 0x50 | 0x54 | | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| | *
* ---------------------------------------------------------------------------------- *
* *
* **************************************************************************************/
.text
.globl jump_fcontext
.type jump_fcontext,@function
.align 16
jump_fcontext:
movq %rbx, (%rdi) /* save RBX */
movq %r12, 0x8(%rdi) /* save R12 */
movq %r13, 0x10(%rdi) /* save R13 */
movq %r14, 0x18(%rdi) /* save R14 */
movq %r15, 0x20(%rdi) /* save R15 */
movq %rbp, 0x28(%rdi) /* save RBP */
cmp $0, %rcx
je 1f
stmxcsr 0x50(%rdi) /* save MMX control and status word */
fnstcw 0x54(%rdi) /* save x87 control word */
ldmxcsr 0x50(%rsi) /* restore MMX control and status word */
fldcw 0x54(%rsi) /* restore x87 control word */
1:
leaq 0x8(%rsp), %rax /* exclude the return address and save as stack pointer */
movq %rax, 0x30(%rdi) /* save as stack pointer */
movq (%rsp), %rax /* save return address */
movq %rax, 0x38(%rdi) /* save return address as RIP */
movq (%rsi), %rbx /* restore RBX */
movq 0x8(%rsi), %r12 /* restore R12 */
movq 0x10(%rsi), %r13 /* restore R13 */
movq 0x18(%rsi), %r14 /* restore R14 */
movq 0x20(%rsi), %r15 /* restore R15 */
movq 0x28(%rsi), %rbp /* restore RBP */
movq 0x30(%rsi), %rsp /* restore RSP */
movq 0x38(%rsi), %rcx /* fetch the address to return to */
movq %rdx, %rax /* use third arg as return value after jump */
movq %rdx, %rdi /* use third arg as first arg in context function */
jmp *%rcx /* indirect jump to context */
.size jump_fcontext,.-jump_fcontext
.text
.globl make_fcontext
.type make_fcontext,@function
.align 16
make_fcontext:
movq %rdi, (%rdi) /* save the address of passed context */
movq %rsi, 0x38(%rdi) /* save the address of the context function */
movq 0x40(%rdi), %rdx /* load the stack base */
pushq %rdi /* save pointer to fcontext_t */
movq %rdx, %rdi /* stack pointer as arg for align_stack */
call align_stack@PLT /* align stack */
movq %rax, %rdx /* begin of aligned stack */
popq %rdi /* restore pointer to fcontext_t */
leaq -0x8(%rdx), %rdx /* reserve space for the last frame on stack, (RSP + 8) & 15 == 0 */
movq %rdx, 0x30(%rdi) /* save the algined stack base */
stmxcsr 0x50(%rdi) /* save MMX control and status word */
fnstcw 0x54(%rdi) /* save x87 control word */
leaq finish(%rip), %rcx /* address of finish; called after context function returns */
movq %rcx, (%rdx)
xorq %rax, %rax
ret
finish:
xorq %rdi, %rdi /* exit code is zero */
call _exit@PLT /* exit application */
hlt
.size make_fcontext,.-make_fcontext
/*
Copyright Oliver Kowalke 2009.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
/****************************************************************************************
* *
* ---------------------------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | RBX | R12 | R13 | R14 | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ---------------------------------------------------------------------------------- *
* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | *
* ---------------------------------------------------------------------------------- *
* | R15 | RBP | RSP | RIP | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 16 | 17 | 18 | 19 | | *
* ---------------------------------------------------------------------------------- *
* | 0x40 | 0x44 | 0x48 | 0x4c | | *
* ---------------------------------------------------------------------------------- *
* | sbase | slimit | | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 20 | 21 | | *
* ---------------------------------------------------------------------------------- *
* | 0x50 | 0x54 | | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| | *
* ---------------------------------------------------------------------------------- *
* *
* **************************************************************************************/
.text
.globl _jump_fcontext
.align 8
_jump_fcontext:
movq %rbx, (%rdi) /* save RBX */
movq %r12, 0x8(%rdi) /* save R12 */
movq %r13, 0x10(%rdi) /* save R13 */
movq %r14, 0x18(%rdi) /* save R14 */
movq %r15, 0x20(%rdi) /* save R15 */
movq %rbp, 0x28(%rdi) /* save RBP */
cmp $0, %rcx
je 1f
stmxcsr 0x50(%rdi) /* save MMX control and status word */
fnstcw 0x54(%rdi) /* save x87 control word */
ldmxcsr 0x50(%rsi) /* restore MMX control and status word */
fldcw 0x54(%rsi) /* restore x87 control word */
1:
leaq 0x8(%rsp), %rax /* exclude the return address and save as stack pointer */
movq %rax, 0x30(%rdi) /* save as stack pointer */
movq (%rsp), %rax /* save return address */
movq %rax, 0x38(%rdi) /* save return address as RIP */
movq (%rsi), %rbx /* restore RBX */
movq 0x8(%rsi), %r12 /* restore R12 */
movq 0x10(%rsi), %r13 /* restore R13 */
movq 0x18(%rsi), %r14 /* restore R14 */
movq 0x20(%rsi), %r15 /* restore R15 */
movq 0x28(%rsi), %rbp /* restore RBP */
movq 0x30(%rsi), %rsp /* restore RSP */
movq 0x38(%rsi), %rcx /* fetch the address to return to */
movq %rdx, %rax /* use third arg as return value after jump */
movq %rdx, %rdi /* use third arg as first arg in context function */
jmp *%rcx /* indirect jump to context */
.text
.globl _make_fcontext
.align 8
_make_fcontext:
movq %rdi, (%rdi) /* save the address of current context */
movq %rsi, 0x38(%rdi) /* save the address of the function supposed to run */
movq 0x40(%rdi), %rdx /* load the stack base */
pushq %rdi /* save pointer to fcontext_t */
movq %rdx, %rdi /* stack pointer as arg for align_stack */
call _align_stack /* align stack */
//call align_stack@PLT /* align stack */
movq %rax, %rdx /* begin of aligned stack */
popq %rdi /* restore pointer to fcontext_t */
leaq -0x8(%rdx), %rdx /* reserve space for the last frame on stack, (RSP + 8) % 16 == 0 */
movq %rdx, 0x30(%rdi) /* save the address */
stmxcsr 0x50(%rdi) /* save MMX control and status word */
fnstcw 0x54(%rdi) /* save x87 control word */
leaq finish(%rip), %rcx /* helper code executed after context function returns */
movq %rcx, (%rdx)
xorq %rax, %rax /* set RAX to zero */
ret
finish:
xorq %rdi, %rdi /* exit code is zero */
//call _exit@PLT /* exit application */
call _exit /* exit application */
hlt
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_CONTEXT_SOURCE
#include <boost/context/fcontext.hpp>
#include <cstddef>
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
namespace boost {
namespace ctx {
namespace detail {
extern "C" BOOST_CONTEXT_DECL
void * BOOST_CONTEXT_CALLDECL align_stack( void * vp)
{
void * base = vp;
if ( 0 != ( ( ( uintptr_t) base) & 15) )
base = ( char * ) ( ( ( ( uintptr_t) base) - 15) & ~0x0F);
return base;
}
}
}}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_CONTEXT_SOURCE
extern "C" {
#include <stddef.h>
#include <stdio.h>
#include <excpt.h>
#include <windows.h>
#include <winnt.h>
#if defined(_MSC_VER)
# define SNPRINTF _snprintf
#else
# define SNPRINTF snprintf
#endif
static char * exception_description(
_EXCEPTION_RECORD const* record, char * description, size_t len)
{
const DWORD code = record->ExceptionCode;
const ULONG_PTR * info = record->ExceptionInformation;
switch ( code)
{
case EXCEPTION_ACCESS_VIOLATION:
{
const char * accessType = ( info[0]) ? "writing" : "reading";
const ULONG_PTR address = info[1];
SNPRINTF( description, len, "Access violation %s 0x%08lX", accessType, address);
return description;
}
case EXCEPTION_DATATYPE_MISALIGNMENT: return "Datatype misalignment";
case EXCEPTION_BREAKPOINT: return "Breakpoint";
case EXCEPTION_SINGLE_STEP: return "Single step";
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: return "Array bounds exceeded";
case EXCEPTION_FLT_DENORMAL_OPERAND: return "FPU denormal operand";
case EXCEPTION_FLT_DIVIDE_BY_ZERO: return "FPU divide by zero";
case EXCEPTION_FLT_INEXACT_RESULT: return "FPU inexact result";
case EXCEPTION_FLT_INVALID_OPERATION: return "FPU invalid operation";
case EXCEPTION_FLT_OVERFLOW: return "FPU overflow";
case EXCEPTION_FLT_STACK_CHECK: return "FPU stack check";
case EXCEPTION_FLT_UNDERFLOW: return "FPU underflow";
case EXCEPTION_INT_DIVIDE_BY_ZERO: return "Integer divide by zero";
case EXCEPTION_INT_OVERFLOW: return "Integer overflow";
case EXCEPTION_PRIV_INSTRUCTION: return "Privileged instruction";
case EXCEPTION_IN_PAGE_ERROR: return "In page error";
case EXCEPTION_ILLEGAL_INSTRUCTION: return "Illegal instruction";
case EXCEPTION_NONCONTINUABLE_EXCEPTION: return "Noncontinuable exception";
case EXCEPTION_STACK_OVERFLOW: return "Stack overflow";
case EXCEPTION_INVALID_DISPOSITION: return "Invalid disposition";
case EXCEPTION_GUARD_PAGE: return "Guard page";
case EXCEPTION_INVALID_HANDLE: return "Invalid handle";
}
SNPRINTF( description, len, "Unknown (0x%08lX)", code);
return description;
}
EXCEPTION_DISPOSITION seh_fcontext(
struct _EXCEPTION_RECORD * record,
void *,
struct _CONTEXT *,
void *)
{
char description[255];
fprintf( stderr, "exception: %s (%08lX)\n",
exception_description( record, description, sizeof( description) ),
record->ExceptionCode);
ExitProcess( -1);
return ExceptionContinueSearch; // never reached
}
}
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_CONTEXT_SOURCE
#include <boost/context/stack_allocator.hpp>
extern "C" {
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
}
#include <stdexcept>
#include <boost/config.hpp>
#include <boost/assert.hpp>
#include <boost/format.hpp>
#include <boost/context/stack_utils.hpp>
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
namespace boost {
namespace ctx {
void *
stack_allocator::allocate( std::size_t size) const
{
if ( minimum_stacksize() > size)
throw std::invalid_argument(
boost::str( boost::format("invalid stack size: must be at least %d bytes")
% minimum_stacksize() ) );
if ( ! is_stack_unbound() && ( maximum_stacksize() < size) )
throw std::invalid_argument(
boost::str( boost::format("invalid stack size: must not be larger than %d bytes")
% maximum_stacksize() ) );
const std::size_t pages( page_count( size) + 1); // add +1 for guard page
std::size_t size_ = pages * pagesize();
const int fd( ::open("/dev/zero", O_RDONLY) );
BOOST_ASSERT( -1 != fd);
void * limit =
# if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
::mmap( 0, size_, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
# else
::mmap( 0, size_, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
# endif
::close( fd);
if ( ! limit) throw std::bad_alloc();
const int result( ::mprotect( limit, pagesize(), PROT_NONE) );
BOOST_ASSERT( 0 == result);
return static_cast< char * >( limit) + size_;
}
void
stack_allocator::deallocate( void * vp, std::size_t size) const
{
if ( vp)
{
const std::size_t pages( page_count( size) + 1); // add +1 for guard page
std::size_t size_ = pages * pagesize();
BOOST_ASSERT( 0 < size && 0 < size_);
void * limit = static_cast< char * >( vp) - size_;
::munmap( limit, size_);
}
}
}}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_CONTEXT_SOURCE
#include <boost/context/stack_allocator.hpp>
extern "C" {
#include <windows.h>
}
#include <stdexcept>
#include <boost/config.hpp>
#include <boost/assert.hpp>
#include <boost/format.hpp>
#include <boost/context/stack_utils.hpp>
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
# if defined(BOOST_MSVC)
# pragma warning(push)
# pragma warning(disable:4244 4267)
# endif
namespace boost {
namespace ctx {
void *
stack_allocator::allocate( std::size_t size) const
{
if ( minimum_stacksize() > size)
throw std::invalid_argument(
boost::str( boost::format("invalid stack size: must be at least %d bytes")
% minimum_stacksize() ) );
if ( ! is_stack_unbound() && ( maximum_stacksize() < size) )
throw std::invalid_argument(
boost::str( boost::format("invalid stack size: must not be larger than %d bytes")
% maximum_stacksize() ) );
const std::size_t pages( page_count( size) + 1); // add +1 for guard page
std::size_t size_ = pages * pagesize();
#ifndef BOOST_CONTEXT_FIBER
void * limit = ::VirtualAlloc( 0, size_, MEM_COMMIT, PAGE_READWRITE);
if ( ! limit) throw std::bad_alloc();
DWORD old_options;
const BOOL result = ::VirtualProtect(
limit, pagesize(), PAGE_READWRITE | PAGE_GUARD /*PAGE_NOACCESS*/, & old_options);
BOOST_ASSERT( FALSE != result);
return static_cast< char * >( limit) + size_;
#endif
}
void
stack_allocator::deallocate( void * vp, std::size_t size) const
{
if ( vp)
{
const std::size_t pages( page_count( size) + 1); // add +1 for guard page
std::size_t size_ = pages * pagesize();
BOOST_ASSERT( 0 < size && 0 < size_);
void * limit = static_cast< char * >( vp) - size_;
::VirtualFree( limit, 0, MEM_RELEASE);
}
}
}}
# if defined(BOOST_MSVC)
# pragma warning(pop)
# endif
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_CONTEXT_SOURCE
#include <boost/context/stack_utils.hpp>
extern "C" {
#include <sys/resource.h>
#include <sys/time.h>
#include <unistd.h>
}
#include <cmath>
#include <csignal>
#include <boost/assert.hpp>
namespace {
static rlimit stacksize_limit_()
{
rlimit limit;
const int result = ::getrlimit( RLIMIT_STACK, & limit);
BOOST_ASSERT( 0 == result);
return limit;
}
static rlimit stacksize_limit()
{
static rlimit limit = stacksize_limit_();
return limit;
}
}
namespace boost {
namespace ctx {
BOOST_CONTEXT_DECL
std::size_t default_stacksize()
{
static std::size_t size = 256 * 1024;
return size;
}
BOOST_CONTEXT_DECL
std::size_t minimum_stacksize()
{ return SIGSTKSZ; }
BOOST_CONTEXT_DECL
std::size_t maximum_stacksize()
{
BOOST_ASSERT( ! is_stack_unbound() );
return static_cast< std::size_t >( stacksize_limit().rlim_max);
}
BOOST_CONTEXT_DECL
bool is_stack_unbound()
{ return RLIM_INFINITY == stacksize_limit().rlim_max; }
BOOST_CONTEXT_DECL
std::size_t pagesize()
{
static std::size_t pagesize( ::getpagesize() );
return pagesize;
}
BOOST_CONTEXT_DECL
std::size_t page_count( std::size_t stacksize)
{
return static_cast< std::size_t >(
std::ceil(
static_cast< float >( stacksize) / pagesize() ) );
}
}}
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_CONTEXT_SOURCE
#include <boost/context/stack_utils.hpp>
extern "C" {
#include <windows.h>
}
#include <cmath>
#include <csignal>
#include <boost/assert.hpp>
namespace {
static SYSTEM_INFO system_info_()
{
SYSTEM_INFO si;
::GetSystemInfo( & si);
return si;
}
static SYSTEM_INFO system_info()
{
static SYSTEM_INFO si = system_info_();
return si;
}
}
namespace boost {
namespace ctx {
BOOST_CONTEXT_DECL
std::size_t default_stacksize()
{
static std::size_t size = 256 * 1024;
return size;
}
BOOST_CONTEXT_DECL
std::size_t minimum_stacksize()
{
static std::size_t stacksize(
static_cast< std::size_t >( system_info().dwAllocationGranularity) );
return stacksize;
}
BOOST_CONTEXT_DECL
std::size_t maximum_stacksize()
{
BOOST_ASSERT( ! is_stack_unbound() );
static std::size_t stacksize = 8 * 1024 * 1024;
return stacksize;
}
// Windows seams not to provide a limit for the stacksize
BOOST_CONTEXT_DECL
bool is_stack_unbound()
{ return true; }
BOOST_CONTEXT_DECL
std::size_t pagesize()
{
static std::size_t pagesize(
static_cast< std::size_t >( system_info().dwPageSize) );
return pagesize;
}
BOOST_CONTEXT_DECL
std::size_t page_count( std::size_t stacksize)
{
return static_cast< std::size_t >(
std::ceil(
static_cast< float >( stacksize) / pagesize() ) );
}
}}
......@@ -3,11 +3,10 @@
#include "ping_pong.hpp"
#include "cppa/cppa.hpp"
#include "cppa/logging.hpp"
#include "cppa/sb_actor.hpp"
#include "cppa/to_string.hpp"
#include "cppa/detail/logging.hpp"
using std::cout;
using std::endl;
using namespace cppa;
......
......@@ -7,8 +7,8 @@
#include "test.hpp"
#include "ping_pong.hpp"
#include "cppa/cppa.hpp"
#include "cppa/logging.hpp"
#include "cppa/exception.hpp"
#include "cppa/detail/logging.hpp"
using namespace std;
using namespace cppa;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment