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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
#ifndef PHP_LUASANDBOX_H
#define PHP_LUASANDBOX_H
#ifdef CLOCK_REALTIME
# ifdef CLOCK_THREAD_CPUTIME_ID
# define LUASANDBOX_CLOCK_ID CLOCK_THREAD_CPUTIME_ID
# else
# define LUASANDBOX_CLOCK_ID CLOCK_REALTIME
# endif
#else /*CLOCK_REALTIME*/
# define LUASANDBOX_NO_CLOCK
#endif /*CLOCK_REALTIME*/
#include <lua.h>
#include <lualib.h>
#include <signal.h>
#include "luasandbox_types.h"
#include "luasandbox_timer.h"
/* alloc.c */
lua_State * luasandbox_alloc_new_state(php_luasandbox_alloc * alloc, php_luasandbox_obj * sandbox);
void luasandbox_alloc_delete_state(php_luasandbox_alloc * alloc, lua_State * L);
/* luasandbox.c */
extern zend_module_entry luasandbox_module_entry;
#define phpext_luasandbox_ptr &luasandbox_module_entry
#ifdef PHP_WIN32
# define PHP_LUASANDBOX_API __declspec(dllexport)
#elif defined(__GNUC__) && __GNUC__ >= 4
# define PHP_LUASANDBOX_API __attribute__ ((visibility("default")))
#else
# define PHP_LUASANDBOX_API
#endif
#ifdef ZTS
#include "TSRM.h"
#endif
int luasandbox_call_php(lua_State * L);
int luasandbox_call_lua(php_luasandbox_obj * sandbox, zval * sandbox_zval,
int nargs, int nresults, int errfunc);
PHP_MINIT_FUNCTION(luasandbox);
PHP_MSHUTDOWN_FUNCTION(luasandbox);
PHP_RSHUTDOWN_FUNCTION(luasandbox);
PHP_MINFO_FUNCTION(luasandbox);
PHP_METHOD(LuaSandbox, getVersionInfo);
PHP_METHOD(LuaSandbox, loadString);
PHP_METHOD(LuaSandbox, loadBinary);
PHP_METHOD(LuaSandbox, setMemoryLimit);
PHP_METHOD(LuaSandbox, getMemoryUsage);
PHP_METHOD(LuaSandbox, getPeakMemoryUsage);
PHP_METHOD(LuaSandbox, setCPULimit);
PHP_METHOD(LuaSandbox, getCPUUsage);
PHP_METHOD(LuaSandbox, pauseUsageTimer);
PHP_METHOD(LuaSandbox, unpauseUsageTimer);
PHP_METHOD(LuaSandbox, enableProfiler);
PHP_METHOD(LuaSandbox, disableProfiler);
PHP_METHOD(LuaSandbox, getProfilerFunctionReport);
PHP_METHOD(LuaSandbox, callFunction);
PHP_METHOD(LuaSandbox, wrapPhpFunction);
PHP_METHOD(LuaSandbox, registerLibrary);
PHP_METHOD(LuaSandboxFunction, __construct);
PHP_METHOD(LuaSandboxFunction, call);
PHP_METHOD(LuaSandboxFunction, dump);
#ifdef ZTS
#define LUASANDBOX_G(v) TSRMG(luasandbox_globals_id, zend_luasandbox_globals *, v)
#else
#define LUASANDBOX_G(v) (luasandbox_globals.v)
#endif
php_luasandbox_obj * luasandbox_get_php_obj(lua_State * L);
/** {{{ luasandbox_enter_php
*
* This function must be called each time a C function is entered from Lua
* and the PHP state needs to be accessed in any way. Before exiting the
* function, luasandbox_leave_php() must be called.
*
* This sets a flag which indicates to the timeout signal handler that it is
* unsafe to call longjmp() to return control to PHP. If the flag is not
* correctly set, memory may be corrupted and security compromised.
*/
static inline void luasandbox_enter_php(lua_State * L, php_luasandbox_obj * intern)
{
intern->in_php ++;
if (intern->timed_out) {
intern->in_php --;
luasandbox_timer_timeout_error(L);
}
}
/* }}} */
/**
* {{ luasandbox_enter_php_ignore_timeouts
*
* Like luasandbox_enter_php except that no error is raised if a timeout has occurred
*/
static inline void luasandbox_enter_php_ignore_timeouts(lua_State * L, php_luasandbox_obj * intern)
{
intern->in_php ++;
}
/** {{{ luasandbox_leave_php
*
* This function must be called after luasandbox_enter_php, before the callback
* from Lua returns.
*/
static inline void luasandbox_leave_php(lua_State * L, php_luasandbox_obj * intern)
{
intern->in_php --;
}
/* }}} */
/* library.c */
void luasandbox_lib_register(lua_State * L);
void luasandbox_lib_destroy_globals();
/* luasandbox_lstrlib.c */
int luasandbox_open_string(lua_State * L);
/* data_conversion.c */
void luasandbox_data_conversion_init(lua_State * L);
int luasandbox_push_zval(lua_State * L, zval * z, HashTable *recursionGuard);
void luasandbox_push_zval_userdata(lua_State * L, zval * z);
int luasandbox_lua_to_zval(zval * z, lua_State * L, int index,
zval * sandbox_zval, HashTable * recursionGuard);
void luasandbox_wrap_fatal(lua_State * L);
int luasandbox_is_fatal(lua_State * L, int index);
int luasandbox_is_trace_error(lua_State * L, int index);
const char * luasandbox_error_to_string(lua_State * L, int index);
int luasandbox_attach_trace(lua_State * L);
void luasandbox_push_structured_trace(lua_State * L, int level);
#endif /* PHP_LUASANDBOX_H */
|