Refactor back ends into implementations of BackEnd.
[hiphop-php.git] / hphp / runtime / vm / unwind.h
blob0b9f813d1c96dcd90790ba6b9f19a410481afdc5
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
16 #ifndef incl_HPHP_UNWIND_H_
17 #define incl_HPHP_UNWIND_H_
19 #include <stdexcept>
21 namespace HPHP {
23 //////////////////////////////////////////////////////////////////////
26 * Enumerates actions that should be taken by the enterVM loop after
27 * unwinding an exception.
29 enum class UnwindAction {
31 * The exception was not handled in this nesting of the VM---it
32 * needs to be rethrown.
34 Propagate,
37 * A catch or fault handler was identified and the VM state has been
38 * prepared for entry to it.
40 ResumeVM,
42 /**
43 * An exception thrown from an eagerly executed async function was
44 * wrapped into a StaticExceptionWaitHandle. The async function was
45 * running in the top frame, so we need to return from the VM instance.
47 Return,
51 * The main entry point to the unwinder.
53 * When an exception propagates up to the top-level try/catch in
54 * enterVM, it calls to this module to perform stack unwinding as
55 * appropriate. This function must be called from within the catch
56 * handler (it rethrows the exception to determine what to do).
58 * The returned UnwindAction instructs enterVM on how to proceed.
60 UnwindAction exception_handler() noexcept;
62 //////////////////////////////////////////////////////////////////////
65 * This exception is thrown when executing an Unwind bytecode, which
66 * will reraise the current fault and resume propagating it.
68 struct VMPrepareUnwind : std::exception {
69 const char* what() const throw() { return "VMPrepareUnwind"; }
73 * Thrown when we need to "switch modes" by re-starting the current VM
74 * invocation. For example, if we need to break for the debugger, or
75 * enable code coverage mode.
77 struct VMSwitchMode : std::exception {
78 const char* what() const throw() { return "VMSwitchMode"; }
82 * Thrown for stack overflow thrown from a prolog while
83 * re-entering
85 struct VMReenterStackOverflow : std::exception {
86 const char* what() const throw() { return "VMReenterStackOverflow"; }
90 * Same as VMSwitchMode, except for use from a builtin---the frame for
91 * the builtin function should be unwound before resuming the VM.
93 struct VMSwitchModeBuiltin : std::exception {
94 const char* what() const throw() { return "VMSwitchModeBuiltin"; }
97 //////////////////////////////////////////////////////////////////////
101 #endif