summaryrefslogtreecommitdiff
path: root/zend/executestate.h
blob: edd7d5e9a32a4a7d29616b580222fb4efe7cf819 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
 *  ExecuteState.h
 *
 *  Class that keeps the current execution state (this is used when a different
 *  script or file is eval'ed to store the execution state so that we can switch
 *  back to the original state.
 *
 *  @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
 *  @copyright 2014 Copernica BV
 */

/**
 *  Set up namespace
 */
namespace Php {

/**
 *  Helper class to store and restore the current opcode state
 *
 *  When we're going to execute a set of instructions, we need to store the
 *  current state of the Zend engine. After the instructions have been processed,
 *  we can switch back to the original instructions
 */
class ExecuteState
{
private:
    /**
     *  All the original settings
     *  @var mixed
     */
    zend_op_array *_active_op_array;
    zval *_return_value;
    const zend_op *_opline;

    /**
     *  The new value for 'no-extensions'
     *  @var int
     */
    int _no_extensions;

#ifdef ZTS
    /**
     *  When in thread safety mode, we also keep track of the TSRM_LS var
     *  @var void***
     */
    void ***tsrm_ls;
#endif

public:
    /**
     *  No trivial constructor
     */
    ExecuteState() = delete;

    /**
     *  Constructor
     *  @param  no_extensions
     */
    ExecuteState(int no_extensions TSRMLS_DC)
    {
        // store all the original stuff
        _active_op_array = CG(active_op_array);
        _return_value  = EG(current_execute_data)->return_value;
        _opline = EG(current_execute_data)->opline;
        _no_extensions = no_extensions;

#ifdef ZTS
        // copy tsrm_ls param
        this->tsrm_ls = tsrm_ls;
#endif
    }

    /**
     *  Destructor
     */
    virtual ~ExecuteState()
    {
        // restore all settings
        EG(no_extensions) = _no_extensions;
        EG(current_execute_data)->opline = _opline;
        CG(active_op_array) = _active_op_array;
        EG(current_execute_data)->return_value = _return_value;
    }
};

/**
 *  End of namespace
 */
}