LCOV - code coverage report
Current view: top level - src - php_luasandbox.h (source / functions) Hit Total Coverage
Test: mediawiki/php/luasandbox test coverage report Lines: 10 12 83.3 %
Date: 2023-12-12 07:35:14 Functions: 3 3 100.0 %

          Line data    Source code
       1             : 
       2             : #ifndef PHP_LUASANDBOX_H
       3             : #define PHP_LUASANDBOX_H
       4             : 
       5             : #ifdef CLOCK_REALTIME
       6             : #   ifdef CLOCK_THREAD_CPUTIME_ID
       7             : #       define LUASANDBOX_CLOCK_ID CLOCK_THREAD_CPUTIME_ID
       8             : #   else
       9             : #       define LUASANDBOX_CLOCK_ID CLOCK_REALTIME
      10             : #   endif
      11             : #else /*CLOCK_REALTIME*/
      12             : #   define LUASANDBOX_NO_CLOCK
      13             : #endif /*CLOCK_REALTIME*/
      14             : 
      15             : #include <lua.h>
      16             : #include <lualib.h>
      17             : #include <signal.h>
      18             : 
      19             : #include "luasandbox_types.h"
      20             : #include "luasandbox_timer.h"
      21             : 
      22             : /* alloc.c */
      23             : 
      24             : 
      25             : lua_State * luasandbox_alloc_new_state(php_luasandbox_alloc * alloc, php_luasandbox_obj * sandbox);
      26             : void luasandbox_alloc_delete_state(php_luasandbox_alloc * alloc, lua_State * L);
      27             : 
      28             : /* luasandbox.c */
      29             : 
      30             : extern zend_module_entry luasandbox_module_entry;
      31             : 
      32             : #define phpext_luasandbox_ptr &luasandbox_module_entry
      33             : 
      34             : #ifdef PHP_WIN32
      35             : #   define PHP_LUASANDBOX_API __declspec(dllexport)
      36             : #elif defined(__GNUC__) && __GNUC__ >= 4
      37             : #   define PHP_LUASANDBOX_API __attribute__ ((visibility("default")))
      38             : #else
      39             : #   define PHP_LUASANDBOX_API
      40             : #endif
      41             : 
      42             : #ifdef ZTS
      43             : #include "TSRM.h"
      44             : #endif
      45             : 
      46             : int luasandbox_call_php(lua_State * L);
      47             : int luasandbox_call_lua(php_luasandbox_obj * sandbox, zval * sandbox_zval,
      48             :     int nargs, int nresults, int errfunc);
      49             : 
      50             : PHP_MINIT_FUNCTION(luasandbox);
      51             : PHP_MSHUTDOWN_FUNCTION(luasandbox);
      52             : PHP_RSHUTDOWN_FUNCTION(luasandbox);
      53             : PHP_MINFO_FUNCTION(luasandbox);
      54             : 
      55             : PHP_METHOD(LuaSandbox, getVersionInfo);
      56             : PHP_METHOD(LuaSandbox, loadString);
      57             : PHP_METHOD(LuaSandbox, loadBinary);
      58             : PHP_METHOD(LuaSandbox, setMemoryLimit);
      59             : PHP_METHOD(LuaSandbox, getMemoryUsage);
      60             : PHP_METHOD(LuaSandbox, getPeakMemoryUsage);
      61             : PHP_METHOD(LuaSandbox, setCPULimit);
      62             : PHP_METHOD(LuaSandbox, getCPUUsage);
      63             : PHP_METHOD(LuaSandbox, pauseUsageTimer);
      64             : PHP_METHOD(LuaSandbox, unpauseUsageTimer);
      65             : PHP_METHOD(LuaSandbox, enableProfiler);
      66             : PHP_METHOD(LuaSandbox, disableProfiler);
      67             : PHP_METHOD(LuaSandbox, getProfilerFunctionReport);
      68             : PHP_METHOD(LuaSandbox, callFunction);
      69             : PHP_METHOD(LuaSandbox, wrapPhpFunction);
      70             : PHP_METHOD(LuaSandbox, registerLibrary);
      71             : 
      72             : PHP_METHOD(LuaSandboxFunction, __construct);
      73             : PHP_METHOD(LuaSandboxFunction, call);
      74             : PHP_METHOD(LuaSandboxFunction, dump);
      75             : 
      76             : #ifdef ZTS
      77             : #define LUASANDBOX_G(v) TSRMG(luasandbox_globals_id, zend_luasandbox_globals *, v)
      78             : #else
      79             : #define LUASANDBOX_G(v) (luasandbox_globals.v)
      80             : #endif
      81             : 
      82             : 
      83             : php_luasandbox_obj * luasandbox_get_php_obj(lua_State * L);
      84             : 
      85             : /** {{{ luasandbox_enter_php
      86             :  *
      87             :  * This function must be called each time a C function is entered from Lua
      88             :  * and the PHP state needs to be accessed in any way. Before exiting the
      89             :  * function, luasandbox_leave_php() must be called.
      90             :  *
      91             :  * This sets a flag which indicates to the timeout signal handler that it is
      92             :  * unsafe to call longjmp() to return control to PHP. If the flag is not
      93             :  * correctly set, memory may be corrupted and security compromised.
      94             :  */
      95         246 : static inline void luasandbox_enter_php(lua_State * L, php_luasandbox_obj * intern)
      96             : {
      97         246 :     intern->in_php ++;
      98         246 :     if (intern->timed_out) {
      99           0 :         intern->in_php --;
     100           0 :         luasandbox_timer_timeout_error(L);
     101             :     }
     102         246 : }
     103             : /* }}} */
     104             : 
     105             : /**
     106             :  * {{ luasandbox_enter_php_ignore_timeouts
     107             :  *
     108             :  * Like luasandbox_enter_php except that no error is raised if a timeout has occurred
     109             :  */
     110         125 : static inline void luasandbox_enter_php_ignore_timeouts(lua_State * L, php_luasandbox_obj * intern)
     111             : {
     112         125 :     intern->in_php ++;
     113         125 : }
     114             : 
     115             : /** {{{ luasandbox_leave_php
     116             :  *
     117             :  * This function must be called after luasandbox_enter_php, before the callback
     118             :  * from Lua returns.
     119             :  */
     120         371 : static inline void luasandbox_leave_php(lua_State * L, php_luasandbox_obj * intern)
     121             : {
     122         371 :     intern->in_php --;
     123         371 : }
     124             : /* }}} */
     125             : 
     126             : /* library.c */
     127             : 
     128             : void luasandbox_lib_register(lua_State * L);
     129             : void luasandbox_lib_destroy_globals();
     130             : 
     131             : /* luasandbox_lstrlib.c */
     132             : 
     133             : int luasandbox_open_string(lua_State * L);
     134             : 
     135             : /* data_conversion.c */
     136             : 
     137             : void luasandbox_data_conversion_init(lua_State * L);
     138             : 
     139             : int luasandbox_push_zval(lua_State * L, zval * z, HashTable *recursionGuard);
     140             : void luasandbox_push_zval_userdata(lua_State * L, zval * z);
     141             : int luasandbox_lua_to_zval(zval * z, lua_State * L, int index,
     142             :     zval * sandbox_zval, HashTable * recursionGuard);
     143             : void luasandbox_wrap_fatal(lua_State * L);
     144             : int luasandbox_is_fatal(lua_State * L, int index);
     145             : int luasandbox_is_trace_error(lua_State * L, int index);
     146             : const char * luasandbox_error_to_string(lua_State * L, int index);
     147             : int luasandbox_attach_trace(lua_State * L);
     148             : void luasandbox_push_structured_trace(lua_State * L, int level);
     149             : 
     150             : #endif  /* PHP_LUASANDBOX_H */
     151             : 

Generated by: LCOV version 1.13