v8js_class.cc 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2017 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | http://www.opensource.org/licenses/mit-license.php MIT License |
  8. +----------------------------------------------------------------------+
  9. | Author: Jani Taskinen <[email protected]> |
  10. | Author: Patrick Reilly <[email protected]> |
  11. | Author: Stefan Siegl <[email protected]> |
  12. +----------------------------------------------------------------------+
  13. */
  14. #ifdef HAVE_CONFIG_H
  15. #include "config.h"
  16. #endif
  17. #include <functional>
  18. #include <algorithm>
  19. #include "php_v8js_macros.h"
  20. #include "v8js_v8.h"
  21. #include "v8js_exceptions.h"
  22. #include "v8js_v8object_class.h"
  23. #include "v8js_object_export.h"
  24. #include "v8js_timer.h"
  25. extern "C" {
  26. #include "php.h"
  27. #include "ext/date/php_date.h"
  28. #include "ext/standard/php_string.h"
  29. #include "zend_interfaces.h"
  30. #include "zend_closures.h"
  31. #include "ext/spl/spl_exceptions.h"
  32. #include "zend_exceptions.h"
  33. #include "zend_attributes.h"
  34. }
  35. #define PHP_V8JS_SCRIPT_RES_NAME "V8Js script"
  36. /* {{{ Class Entries */
  37. static zend_class_entry *php_ce_v8js;
  38. /* }}} */
  39. /* {{{ Object Handlers */
  40. static zend_object_handlers v8js_object_handlers;
  41. /* }}} */
  42. /* Forward declare v8js_methods, actually "static" but not possible in C++ */
  43. extern const zend_function_entry v8js_methods[];
  44. typedef struct _v8js_script {
  45. char *name;
  46. v8js_ctx *ctx;
  47. v8::Persistent<v8::Script, v8::CopyablePersistentTraits<v8::Script>> *script;
  48. } v8js_script;
  49. static void v8js_script_free(v8js_script *res);
  50. int le_v8js_script;
  51. #ifdef USE_INTERNAL_ALLOCATOR
  52. class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
  53. public:
  54. virtual void* Allocate(size_t length) {
  55. void* data = AllocateUninitialized(length);
  56. return data == NULL ? data : memset(data, 0, length);
  57. }
  58. virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
  59. virtual void Free(void* data, size_t) { free(data); }
  60. };
  61. #endif /** USE_INTERNAL_ALLOCATOR */
  62. static void v8js_free_storage(zend_object *object) /* {{{ */
  63. {
  64. v8js_ctx *c = v8js_ctx_fetch_object(object);
  65. zend_object_std_dtor(&c->std);
  66. zval_ptr_dtor(&c->module_normaliser);
  67. zval_ptr_dtor(&c->module_loader);
  68. zval_ptr_dtor(&c->exception_filter);
  69. /* Delete PHP global object from JavaScript */
  70. if (!c->context.IsEmpty()) {
  71. v8::Locker locker(c->isolate);
  72. v8::Isolate::Scope isolate_scope(c->isolate);
  73. v8::HandleScope handle_scope(c->isolate);
  74. v8::Local<v8::Context> v8_context = v8::Local<v8::Context>::New(c->isolate, c->context);
  75. v8::Context::Scope context_scope(v8_context);
  76. v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(c->isolate, c->object_name);
  77. V8JS_GLOBAL(c->isolate)->Delete(v8_context, object_name_js);
  78. }
  79. c->object_name.Reset();
  80. c->object_name.~Persistent();
  81. c->global_template.Reset();
  82. c->global_template.~Persistent();
  83. c->array_tmpl.Reset();
  84. c->array_tmpl.~Persistent();
  85. /* Clear persistent call_impl & method_tmpls templates */
  86. for (std::map<v8js_function_tmpl_t *, v8js_function_tmpl_t>::iterator it = c->call_impls.begin();
  87. it != c->call_impls.end(); ++it) {
  88. // No need to free it->first, as it is stored in c->template_cache and freed below
  89. it->second.Reset();
  90. }
  91. c->call_impls.~map();
  92. for (std::map<std::pair<zend_class_entry *, zend_function *>, v8js_function_tmpl_t>::iterator it = c->method_tmpls.begin();
  93. it != c->method_tmpls.end(); ++it) {
  94. it->second.Reset();
  95. }
  96. c->method_tmpls.~map();
  97. /* Clear persistent handles in template cache */
  98. for (std::map<const zend_string *,v8js_function_tmpl_t>::iterator it = c->template_cache.begin();
  99. it != c->template_cache.end(); ++it) {
  100. it->second.Reset();
  101. }
  102. c->template_cache.~map();
  103. /* Clear contexts */
  104. for (std::vector<v8js_accessor_ctx*>::iterator it = c->accessor_list.begin();
  105. it != c->accessor_list.end(); ++it) {
  106. v8js_accessor_ctx_dtor(*it);
  107. }
  108. c->accessor_list.~vector();
  109. /* Clear global object, dispose context */
  110. if (!c->context.IsEmpty()) {
  111. c->context.Reset();
  112. }
  113. c->context.~Persistent();
  114. /* Dispose yet undisposed weak refs */
  115. for (std::map<zend_object *, v8js_persistent_obj_t>::iterator it = c->weak_objects.begin();
  116. it != c->weak_objects.end(); ++it) {
  117. zend_object *object = it->first;
  118. zval value;
  119. ZVAL_OBJ(&value, object);
  120. zval_ptr_dtor(&value);
  121. c->isolate->AdjustAmountOfExternalAllocatedMemory(-c->average_object_size);
  122. it->second.Reset();
  123. }
  124. c->weak_objects.~map();
  125. for (std::map<v8js_function_tmpl_t *, v8js_persistent_obj_t>::iterator it = c->weak_closures.begin();
  126. it != c->weak_closures.end(); ++it) {
  127. v8js_function_tmpl_t *persist_tpl_ = it->first;
  128. persist_tpl_->Reset();
  129. delete persist_tpl_;
  130. it->second.Reset();
  131. }
  132. c->weak_closures.~map();
  133. for (std::list<v8js_v8object *>::iterator it = c->v8js_v8objects.begin();
  134. it != c->v8js_v8objects.end(); it ++) {
  135. (*it)->v8obj.Reset();
  136. (*it)->ctx = NULL;
  137. }
  138. c->v8js_v8objects.~list();
  139. for (std::vector<v8js_script *>::iterator it = c->script_objects.begin();
  140. it != c->script_objects.end(); it ++) {
  141. (*it)->ctx = NULL;
  142. (*it)->script->Reset();
  143. }
  144. c->script_objects.~vector();
  145. /* Clear persistent handles in module cache */
  146. for (std::map<char *, v8js_persistent_value_t>::iterator it = c->modules_loaded.begin();
  147. it != c->modules_loaded.end(); ++it) {
  148. efree(it->first);
  149. it->second.Reset();
  150. }
  151. c->modules_loaded.~map();
  152. if(c->isolate) {
  153. /* c->isolate is initialized by V8Js::__construct, but __wakeup calls
  154. * are not fully constructed and hence this would cause a NPE. */
  155. c->isolate->Dispose();
  156. }
  157. if(c->tz != NULL) {
  158. free(c->tz);
  159. }
  160. c->modules_stack.~vector();
  161. zval_ptr_dtor(&c->zval_snapshot_blob);
  162. #ifndef USE_INTERNAL_ALLOCATOR
  163. delete c->create_params.array_buffer_allocator;
  164. #endif
  165. }
  166. /* }}} */
  167. static zend_object* v8js_new(zend_class_entry *ce) /* {{{ */
  168. {
  169. v8js_ctx *c;
  170. c = (v8js_ctx *) ecalloc(1, sizeof(*c) + zend_object_properties_size(ce));
  171. zend_object_std_init(&c->std, ce);
  172. object_properties_init(&c->std, ce);
  173. c->std.handlers = &v8js_object_handlers;
  174. new(&c->object_name) v8::Persistent<v8::String>();
  175. new(&c->context) v8::Persistent<v8::Context>();
  176. new(&c->global_template) v8::Persistent<v8::FunctionTemplate>();
  177. new(&c->array_tmpl) v8::Persistent<v8::FunctionTemplate>();
  178. new(&c->modules_stack) std::vector<char*>();
  179. new(&c->modules_loaded) std::map<char *, v8js_persistent_value_t, cmp_str>;
  180. new(&c->template_cache) std::map<const zend_string *,v8js_function_tmpl_t>();
  181. new(&c->accessor_list) std::vector<v8js_accessor_ctx *>();
  182. new(&c->weak_closures) std::map<v8js_function_tmpl_t *, v8js_persistent_obj_t>();
  183. new(&c->weak_objects) std::map<zend_object *, v8js_persistent_obj_t>();
  184. new(&c->call_impls) std::map<v8js_function_tmpl_t *, v8js_function_tmpl_t>();
  185. new(&c->method_tmpls) std::map<std::pair<zend_class_entry *, zend_function *>, v8js_function_tmpl_t>();
  186. new(&c->v8js_v8objects) std::list<v8js_v8object *>();
  187. new(&c->script_objects) std::vector<v8js_script *>();
  188. // @fixme following is const, run on startup
  189. v8js_object_handlers.offset = XtOffsetOf(struct v8js_ctx, std);
  190. v8js_object_handlers.free_obj = v8js_free_storage;
  191. c->average_object_size = 1024;
  192. return &c->std;
  193. }
  194. /* }}} */
  195. static void v8js_fatal_error_handler(const char *location, const char *message) /* {{{ */
  196. {
  197. if (location) {
  198. zend_error(E_WARNING, "Fatal V8 error in %s: %s", location, message);
  199. } else {
  200. zend_error(E_WARNING, "Fatal V8 error: %s", message);
  201. }
  202. }
  203. /* }}} */
  204. #define IS_MAGIC_FUNC(mname) \
  205. ((ZSTR_LEN(key) == sizeof(mname) - 1) && \
  206. !strncasecmp(ZSTR_VAL(key), mname, ZSTR_LEN(key)))
  207. /* {{{ proto void V8Js::__construct([string object_name [, array variables [, string snapshot_blob]]])
  208. __construct for V8Js */
  209. static PHP_METHOD(V8Js, __construct)
  210. {
  211. zend_string *object_name = NULL;
  212. zval *vars_arr = NULL;
  213. zval *snapshot_blob = NULL;
  214. v8js_ctx *c = Z_V8JS_CTX_OBJ_P(getThis())
  215. if (!c->context.IsEmpty()) {
  216. /* called __construct() twice, bail out */
  217. return;
  218. }
  219. if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!az", &object_name, &vars_arr, &snapshot_blob) == FAILURE) {
  220. return;
  221. }
  222. /* Initialize V8 */
  223. v8js_v8_init();
  224. /* Throw PHP exception if uncaught exceptions exist */
  225. c->in_execution = 0;
  226. new (&c->create_params) v8::Isolate::CreateParams();
  227. #ifdef USE_INTERNAL_ALLOCATOR
  228. static ArrayBufferAllocator array_buffer_allocator;
  229. c->create_params.array_buffer_allocator = &array_buffer_allocator;
  230. #else
  231. c->create_params.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator();
  232. #endif
  233. new (&c->snapshot_blob) v8::StartupData();
  234. if (snapshot_blob) {
  235. if (Z_TYPE_P(snapshot_blob) == IS_STRING) {
  236. ZVAL_COPY(&c->zval_snapshot_blob, snapshot_blob);
  237. if (Z_STRLEN_P(snapshot_blob) > std::numeric_limits<int>::max()) {
  238. zend_throw_exception(php_ce_v8js_exception,
  239. "Snapshot size exceeds maximum supported length", 0);
  240. return;
  241. }
  242. c->snapshot_blob.data = Z_STRVAL_P(snapshot_blob);
  243. c->snapshot_blob.raw_size = static_cast<int>(Z_STRLEN_P(snapshot_blob));
  244. c->create_params.snapshot_blob = &c->snapshot_blob;
  245. } else {
  246. php_error_docref(NULL, E_WARNING, "Argument snapshot_blob expected to be of string type");
  247. }
  248. }
  249. c->isolate = v8::Isolate::New(c->create_params);
  250. c->isolate->SetData(0, c);
  251. c->time_limit = 0;
  252. c->time_limit_hit = false;
  253. c->memory_limit = 0;
  254. c->memory_limit_hit = false;
  255. ZVAL_NULL(&c->module_normaliser);
  256. ZVAL_NULL(&c->module_loader);
  257. ZVAL_NULL(&c->exception_filter);
  258. // Isolate execution
  259. v8::Isolate *isolate = c->isolate;
  260. v8::Locker locker(isolate);
  261. v8::Isolate::Scope isolate_scope(isolate);
  262. /* Handle scope */
  263. v8::HandleScope handle_scope(isolate);
  264. /* Redirect fatal errors to PHP error handler */
  265. isolate->SetFatalErrorHandler(v8js_fatal_error_handler);
  266. /* Create global template for global object */
  267. // Now we are using multiple isolates this needs to be created for every context
  268. v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(c->isolate);
  269. c->global_template.Reset(isolate, global_template);
  270. /* Register builtin methods */
  271. v8js_register_methods(global_template, c);
  272. /* Create context */
  273. v8::Local<v8::Context> context = v8::Context::New(isolate, nullptr, global_template);
  274. if (context.IsEmpty()) {
  275. zend_throw_exception(php_ce_v8js_exception, "Failed to create V8 context.", 0);
  276. return;
  277. }
  278. context->SetAlignedPointerInEmbedderData(1, c);
  279. context->Global()->Set(context, V8JS_SYM("global"), context->Global());
  280. c->context.Reset(isolate, context);
  281. /* Enter context */
  282. v8::Context::Scope context_scope(context);
  283. /* Create the PHP container object's function template */
  284. v8::Local<v8::FunctionTemplate> php_obj_t = v8::FunctionTemplate::New(isolate, 0);
  285. /* Set class name for PHP object */
  286. zend_class_entry *ce = Z_OBJCE_P(getThis());
  287. if (ZSTR_LEN(ce->name) > std::numeric_limits<int>::max()) {
  288. zend_throw_exception(php_ce_v8js_exception,
  289. "PHP object class name exceeds maximum supported length", 0);
  290. return;
  291. }
  292. php_obj_t->SetClassName(V8JS_SYML(ZSTR_VAL(ce->name), static_cast<int>(ZSTR_LEN(ce->name))));
  293. /* Register Get accessor for passed variables */
  294. if (vars_arr && zend_hash_num_elements(Z_ARRVAL_P(vars_arr)) > 0) {
  295. v8js_register_accessors(&c->accessor_list, php_obj_t, vars_arr, isolate);
  296. }
  297. /* Set name for the PHP JS object */
  298. v8::Local<v8::String> object_name_js;
  299. if (object_name && ZSTR_LEN(object_name)) {
  300. if (ZSTR_LEN(object_name) > std::numeric_limits<int>::max()) {
  301. zend_throw_exception(php_ce_v8js_exception,
  302. "PHP JS object class name exceeds maximum supported length", 0);
  303. return;
  304. }
  305. object_name_js = V8JS_ZSYM(object_name);
  306. }
  307. else {
  308. object_name_js = V8JS_SYM("PHP");
  309. }
  310. c->object_name.Reset(isolate, object_name_js);
  311. /* Add the PHP object into global object */
  312. php_obj_t->InstanceTemplate()->SetInternalFieldCount(2);
  313. v8::Local<v8::Object> php_obj = php_obj_t->InstanceTemplate()->NewInstance(context).ToLocalChecked();
  314. V8JS_GLOBAL(isolate)->DefineOwnProperty(context, object_name_js, php_obj, v8::ReadOnly);
  315. /* Export public property values */
  316. HashTable *properties = zend_std_get_properties(Z_OBJ_P(getThis()));
  317. zval *value;
  318. zend_string *member;
  319. ZEND_HASH_FOREACH_STR_KEY(properties, member) {
  320. zend_property_info *property_info = zend_get_property_info(c->std.ce, member, 1);
  321. if(property_info &&
  322. property_info != ZEND_WRONG_PROPERTY_INFO &&
  323. (property_info->flags & ZEND_ACC_PUBLIC)) {
  324. if (ZSTR_LEN(member) > std::numeric_limits<int>::max()) {
  325. zend_throw_exception(php_ce_v8js_exception,
  326. "Property name exceeds maximum supported length", 0);
  327. return;
  328. }
  329. v8::Local<v8::Name> key = V8JS_ZSYM(member);
  330. /* Write value to PHP JS object */
  331. value = OBJ_PROP(Z_OBJ_P(getThis()), property_info->offset);
  332. php_obj->DefineOwnProperty(context, key, zval_to_v8js(value, isolate), v8::ReadOnly);
  333. }
  334. } ZEND_HASH_FOREACH_END();
  335. /* Add pointer to zend object */
  336. php_obj->SetAlignedPointerInInternalField(1, Z_OBJ_P(getThis()));
  337. /* Export public methods */
  338. void *ptr;
  339. zend_string *key;
  340. ZEND_HASH_FOREACH_STR_KEY_PTR(&c->std.ce->function_table, key, ptr) {
  341. zend_function *method_ptr = reinterpret_cast<zend_function *>(ptr);
  342. if ((method_ptr->common.fn_flags & ZEND_ACC_PUBLIC) == 0) {
  343. /* Allow only public methods */
  344. continue;
  345. }
  346. if ((method_ptr->common.fn_flags & (ZEND_ACC_CTOR|ZEND_ACC_DTOR)) != 0) {
  347. /* no __construct, __destruct(), or __clone() functions */
  348. continue;
  349. }
  350. /* hide (do not export) other PHP magic functions */
  351. if (IS_MAGIC_FUNC(ZEND_CALLSTATIC_FUNC_NAME) ||
  352. IS_MAGIC_FUNC(ZEND_SLEEP_FUNC_NAME) ||
  353. IS_MAGIC_FUNC(ZEND_WAKEUP_FUNC_NAME) ||
  354. IS_MAGIC_FUNC(ZEND_SET_STATE_FUNC_NAME) ||
  355. IS_MAGIC_FUNC(ZEND_GET_FUNC_NAME) ||
  356. IS_MAGIC_FUNC(ZEND_SET_FUNC_NAME) ||
  357. IS_MAGIC_FUNC(ZEND_UNSET_FUNC_NAME) ||
  358. IS_MAGIC_FUNC(ZEND_CALL_FUNC_NAME) ||
  359. IS_MAGIC_FUNC(ZEND_INVOKE_FUNC_NAME) ||
  360. IS_MAGIC_FUNC(ZEND_TOSTRING_FUNC_NAME) ||
  361. IS_MAGIC_FUNC(ZEND_ISSET_FUNC_NAME)) {
  362. continue;
  363. }
  364. const zend_function_entry *fe;
  365. for (fe = v8js_methods; fe->fname; fe ++) {
  366. if (strcmp(fe->fname, ZSTR_VAL(method_ptr->common.function_name)) == 0) {
  367. break;
  368. }
  369. }
  370. if(fe->fname) {
  371. /* Method belongs to \V8Js class itself, never export to V8, even if
  372. * it is overriden in a derived class. */
  373. continue;
  374. }
  375. if (ZSTR_LEN(method_ptr->common.function_name) > std::numeric_limits<int>::max()) {
  376. zend_throw_exception(php_ce_v8js_exception,
  377. "Method name exceeds maximum supported length", 0);
  378. return;
  379. }
  380. v8::Local<v8::String> method_name = V8JS_ZSYM(method_ptr->common.function_name);
  381. v8::Local<v8::FunctionTemplate> ft;
  382. ft = v8::FunctionTemplate::New(isolate, v8js_php_callback,
  383. v8::External::New((isolate), method_ptr));
  384. // @fixme add/check Signature v8::Signature::New((isolate), tmpl));
  385. v8js_function_tmpl_t *persistent_ft = &c->method_tmpls[std::make_pair(ce, method_ptr)];
  386. persistent_ft->Reset(isolate, ft);
  387. php_obj->CreateDataProperty(context, method_name, ft->GetFunction(context).ToLocalChecked());
  388. } ZEND_HASH_FOREACH_END();
  389. }
  390. /* }}} */
  391. /* {{{ proto V8JS::__sleep()
  392. */
  393. PHP_METHOD(V8Js, __sleep)
  394. {
  395. zend_throw_exception(php_ce_v8js_exception,
  396. "You cannot serialize or unserialize V8Js instances", 0);
  397. RETURN_FALSE;
  398. }
  399. /* }}} */
  400. /* {{{ proto V8JS::__wakeup()
  401. */
  402. PHP_METHOD(V8Js, __wakeup)
  403. {
  404. zend_throw_exception(php_ce_v8js_exception,
  405. "You cannot serialize or unserialize V8Js instances", 0);
  406. RETURN_FALSE;
  407. }
  408. /* }}} */
  409. static void v8js_compile_script(zval *this_ptr, const zend_string *str, const zend_string *identifier, v8js_script **ret)
  410. {
  411. v8js_script *res = NULL;
  412. V8JS_BEGIN_CTX(c, this_ptr)
  413. /* Catch JS exceptions */
  414. v8::TryCatch try_catch(isolate);
  415. /* Set script identifier */
  416. if (identifier && ZSTR_LEN(identifier) > std::numeric_limits<int>::max()) {
  417. zend_throw_exception(php_ce_v8js_exception,
  418. "Script identifier exceeds maximum supported length", 0);
  419. return;
  420. }
  421. v8::Local<v8::String> sname = identifier
  422. ? V8JS_ZSTR(identifier)
  423. : V8JS_SYM("V8Js::compileString()");
  424. v8::ScriptOrigin origin(isolate, sname);
  425. if (ZSTR_LEN(str) > std::numeric_limits<int>::max()) {
  426. zend_throw_exception(php_ce_v8js_exception,
  427. "Script source exceeds maximum supported length", 0);
  428. return;
  429. }
  430. v8::Local<v8::String> source = V8JS_ZSTR(str);
  431. v8::MaybeLocal<v8::Script> script = v8::Script::Compile(v8::Local<v8::Context>::New(isolate, c->context), source, &origin);
  432. /* Compile errors? */
  433. if (script.IsEmpty()) {
  434. v8js_throw_script_exception(c->isolate, &try_catch);
  435. return;
  436. }
  437. res = (v8js_script *)emalloc(sizeof(v8js_script));
  438. res->script = new v8::Persistent<v8::Script, v8::CopyablePersistentTraits<v8::Script>>(c->isolate, script.ToLocalChecked());
  439. v8::String::Utf8Value _sname(isolate, sname);
  440. res->name = estrndup(ToCString(_sname), _sname.length());
  441. res->ctx = c;
  442. *ret = res;
  443. return;
  444. }
  445. static void v8js_execute_script(zval *this_ptr, v8js_script *res, long flags, long time_limit, size_t memory_limit, zval **return_value)
  446. {
  447. v8js_ctx *c = Z_V8JS_CTX_OBJ_P(this_ptr);
  448. if (res->ctx != c) {
  449. zend_error(E_WARNING, "Script resource from wrong V8Js object passed");
  450. ZVAL_BOOL(*return_value, 0);
  451. return;
  452. }
  453. if (!c->in_execution && time_limit == 0) {
  454. time_limit = c->time_limit;
  455. }
  456. if (!c->in_execution && memory_limit == 0) {
  457. memory_limit = c->memory_limit;
  458. }
  459. /* std::function relies on its dtor to be executed, otherwise it leaks
  460. * some memory on bailout. */
  461. {
  462. std::function< v8::MaybeLocal<v8::Value>(v8::Isolate *) > v8_call = [c, res](v8::Isolate *isolate) {
  463. v8::Local<v8::Script> script = v8::Local<v8::Script>::New(isolate, *res->script);
  464. return script->Run(v8::Local<v8::Context>::New(isolate, c->context));
  465. };
  466. v8js_v8_call(c, return_value, flags, time_limit, memory_limit, v8_call);
  467. }
  468. if(V8JSG(fatal_error_abort)) {
  469. /* Check for fatal error marker possibly set by v8js_error_handler; just
  470. * rethrow the error since we're now out of V8. */
  471. zend_bailout();
  472. }
  473. }
  474. /* {{{ proto mixed V8Js::executeString(string script [, string identifier [, int flags]])
  475. */
  476. static PHP_METHOD(V8Js, executeString)
  477. {
  478. zend_string *str = NULL, *identifier = NULL;
  479. long flags = V8JS_FLAG_NONE, time_limit = 0, memory_limit = 0;
  480. v8js_script *res = NULL;
  481. if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|S!lll", &str, &identifier, &flags, &time_limit, &memory_limit) == FAILURE) {
  482. return;
  483. }
  484. if (memory_limit < 0) {
  485. zend_throw_exception(php_ce_v8js_exception,
  486. "memory_limit must not be negative", 0);
  487. return;
  488. }
  489. v8js_compile_script(getThis(), str, identifier, &res);
  490. if (!res) {
  491. RETURN_FALSE;
  492. }
  493. zend_try {
  494. v8js_execute_script(getThis(), res, flags, time_limit, static_cast<size_t>(memory_limit), &return_value);
  495. v8js_script_free(res);
  496. }
  497. zend_catch {
  498. v8js_script_free(res);
  499. zend_bailout();
  500. }
  501. zend_end_try()
  502. efree(res);
  503. }
  504. /* }}} */
  505. /* {{{ proto mixed V8Js::compileString(string script [, string identifier])
  506. */
  507. static PHP_METHOD(V8Js, compileString)
  508. {
  509. zend_string *str = NULL, *identifier = NULL;
  510. v8js_script *res = NULL;
  511. if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|S", &str, &identifier) == FAILURE) {
  512. return;
  513. }
  514. v8js_compile_script(getThis(), str, identifier, &res);
  515. if (res) {
  516. RETVAL_RES(zend_register_resource(res, le_v8js_script));
  517. v8js_ctx *ctx;
  518. ctx = Z_V8JS_CTX_OBJ_P(getThis());
  519. ctx->script_objects.push_back(res);
  520. }
  521. }
  522. /* }}} */
  523. /* {{{ proto mixed V8Js::executeScript(resource script [, int flags]])
  524. */
  525. static PHP_METHOD(V8Js, executeScript)
  526. {
  527. long flags = V8JS_FLAG_NONE, time_limit = 0, memory_limit = 0;
  528. zval *zscript;
  529. v8js_script *res;
  530. if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|lll", &zscript, &flags, &time_limit, &memory_limit) == FAILURE) {
  531. return;
  532. }
  533. if (memory_limit < 0) {
  534. zend_throw_exception(php_ce_v8js_exception,
  535. "memory_limit must not be negative", 0);
  536. return;
  537. }
  538. if((res = (v8js_script *)zend_fetch_resource(Z_RES_P(zscript), PHP_V8JS_SCRIPT_RES_NAME, le_v8js_script)) == NULL) {
  539. RETURN_FALSE;
  540. }
  541. v8js_execute_script(getThis(), res, flags, time_limit, static_cast<size_t>(memory_limit), &return_value);
  542. }
  543. /* }}} */
  544. /* {{{ proto void V8Js::setModuleNormaliser(string base, string module_id)
  545. */
  546. static PHP_METHOD(V8Js, setModuleNormaliser)
  547. {
  548. v8js_ctx *c;
  549. zval *callable;
  550. if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &callable) == FAILURE) {
  551. return;
  552. }
  553. c = Z_V8JS_CTX_OBJ_P(getThis());
  554. ZVAL_COPY(&c->module_normaliser, callable);
  555. }
  556. /* }}} */
  557. /* {{{ proto void V8Js::setModuleLoader(string module)
  558. */
  559. static PHP_METHOD(V8Js, setModuleLoader)
  560. {
  561. v8js_ctx *c;
  562. zval *callable;
  563. if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &callable) == FAILURE) {
  564. return;
  565. }
  566. c = Z_V8JS_CTX_OBJ_P(getThis());
  567. ZVAL_COPY(&c->module_loader, callable);
  568. }
  569. /* }}} */
  570. /* {{{ proto void V8Js::setExceptionFilter(callable factory)
  571. */
  572. static PHP_METHOD(V8Js, setExceptionFilter)
  573. {
  574. zval *callable;
  575. if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &callable) == FAILURE) {
  576. return;
  577. }
  578. v8js_ctx *c = Z_V8JS_CTX_OBJ_P(getThis());
  579. ZVAL_COPY(&c->exception_filter, callable);
  580. }
  581. /* }}} */
  582. /* {{{ proto void V8Js::setTimeLimit(int time_limit)
  583. */
  584. static PHP_METHOD(V8Js, setTimeLimit)
  585. {
  586. v8js_ctx *c;
  587. long time_limit = 0;
  588. if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &time_limit) == FAILURE) {
  589. return;
  590. }
  591. c = Z_V8JS_CTX_OBJ_P(getThis());
  592. c->time_limit = time_limit;
  593. V8JSG(timer_mutex).lock();
  594. for (std::deque< v8js_timer_ctx* >::iterator it = V8JSG(timer_stack).begin();
  595. it != V8JSG(timer_stack).end(); it ++) {
  596. if((*it)->ctx == c && !(*it)->killed) {
  597. (*it)->time_limit = time_limit;
  598. // Calculate the time point when the time limit is exceeded
  599. std::chrono::milliseconds duration(time_limit);
  600. std::chrono::time_point<std::chrono::high_resolution_clock> from = std::chrono::high_resolution_clock::now();
  601. (*it)->time_point = from + duration;
  602. }
  603. }
  604. V8JSG(timer_mutex).unlock();
  605. if (c->in_execution && time_limit && !V8JSG(timer_thread)) {
  606. /* If timer thread is not started already and we now impose a time limit
  607. * finally install the timer. */
  608. V8JSG(timer_thread) = new std::thread(v8js_timer_thread, ZEND_MODULE_GLOBALS_BULK(v8js));
  609. }
  610. }
  611. /* }}} */
  612. /* {{{ proto void V8Js::setMemoryLimit(int memory_limit)
  613. */
  614. static PHP_METHOD(V8Js, setMemoryLimit)
  615. {
  616. v8js_ctx *c;
  617. long memory_limit = 0;
  618. if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &memory_limit) == FAILURE) {
  619. return;
  620. }
  621. if (memory_limit < 0) {
  622. zend_throw_exception(php_ce_v8js_exception,
  623. "memory_limit must not be negative", 0);
  624. return;
  625. }
  626. c = Z_V8JS_CTX_OBJ_P(getThis());
  627. c->memory_limit = static_cast<size_t>(memory_limit);
  628. V8JSG(timer_mutex).lock();
  629. for (std::deque< v8js_timer_ctx* >::iterator it = V8JSG(timer_stack).begin();
  630. it != V8JSG(timer_stack).end(); it ++) {
  631. if((*it)->ctx == c && !(*it)->killed) {
  632. (*it)->memory_limit = static_cast<size_t>(memory_limit);
  633. }
  634. }
  635. V8JSG(timer_mutex).unlock();
  636. if (c->in_execution && memory_limit && !V8JSG(timer_thread)) {
  637. /* If timer thread is not started already and we now impose a memory limit
  638. * finally install the timer. */
  639. V8JSG(timer_thread) = new std::thread(v8js_timer_thread, ZEND_MODULE_GLOBALS_BULK(v8js));
  640. }
  641. }
  642. /* }}} */
  643. /* {{{ proto void V8Js::setAverageObjectSize(average_object_size)
  644. */
  645. static PHP_METHOD(V8Js, setAverageObjectSize)
  646. {
  647. v8js_ctx *c;
  648. long average_object_size = 0;
  649. if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &average_object_size) == FAILURE) {
  650. return;
  651. }
  652. c = Z_V8JS_CTX_OBJ_P(getThis());
  653. c->average_object_size = average_object_size;
  654. }
  655. /* }}} */
  656. static void v8js_persistent_zval_ctor(zval *p) /* {{{ */
  657. {
  658. assert(Z_TYPE_P(p) == IS_STRING);
  659. Z_STR_P(p) = zend_string_dup(Z_STR_P(p), 1);
  660. }
  661. /* }}} */
  662. static void v8js_persistent_zval_dtor(zval *p) /* {{{ */
  663. {
  664. assert(Z_TYPE_P(p) == IS_STRING);
  665. if (!ZSTR_IS_INTERNED(Z_STR_P(p))) {
  666. free(Z_STR_P(p));
  667. }
  668. }
  669. /* }}} */
  670. static void v8js_script_free(v8js_script *res)
  671. {
  672. efree(res->name);
  673. delete res->script; // does Reset()
  674. }
  675. static void v8js_script_dtor(zend_resource *rsrc) /* {{{ */
  676. {
  677. v8js_script *res = (v8js_script *)rsrc->ptr;
  678. if (res) {
  679. if(res->ctx) {
  680. std::vector<v8js_script *>::iterator it = std::find(res->ctx->script_objects.begin(), res->ctx->script_objects.end(), res);
  681. res->ctx->script_objects.erase(it);
  682. }
  683. v8js_script_free(res);
  684. efree(res);
  685. }
  686. }
  687. /* }}} */
  688. /* ## Static methods ## */
  689. static v8::StartupData createSnapshotDataBlob(v8::SnapshotCreator *snapshot_creator, zend_string *str) /* {{{ */
  690. {
  691. v8::Isolate *isolate = snapshot_creator->GetIsolate();
  692. {
  693. v8::HandleScope scope(isolate);
  694. v8::Local<v8::Context> context = v8::Context::New(isolate);
  695. v8::Context::Scope context_scope(context);
  696. v8::TryCatch try_catch(isolate);
  697. v8::Local<v8::String> source = V8JS_ZSTR(str);
  698. v8::MaybeLocal<v8::Script> script = v8::Script::Compile(context, source);
  699. if (script.IsEmpty() || script.ToLocalChecked()->Run(context).IsEmpty())
  700. {
  701. return {nullptr, 0};
  702. }
  703. snapshot_creator->SetDefaultContext(context);
  704. }
  705. return snapshot_creator->CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
  706. } /* }}} */
  707. /* {{{ proto string|bool V8Js::createSnapshot(string embed_source)
  708. */
  709. static PHP_METHOD(V8Js, createSnapshot)
  710. {
  711. zend_string *script;
  712. if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &script) == FAILURE) {
  713. return;
  714. }
  715. if (!ZSTR_LEN(script)) {
  716. php_error_docref(NULL, E_WARNING, "Script cannot be empty");
  717. RETURN_FALSE;
  718. }
  719. /* Initialize V8, if not already done. */
  720. v8js_v8_init();
  721. v8::Isolate *isolate = v8::Isolate::Allocate();
  722. v8::SnapshotCreator snapshot_creator(isolate);
  723. v8::StartupData snapshot_blob = createSnapshotDataBlob(&snapshot_creator, script);
  724. if (!snapshot_blob.data) {
  725. php_error_docref(NULL, E_WARNING, "Failed to create V8 heap snapshot. Check $embed_source for errors.");
  726. RETURN_FALSE;
  727. }
  728. RETVAL_STRINGL(snapshot_blob.data, snapshot_blob.raw_size);
  729. delete[] snapshot_blob.data;
  730. }
  731. /* }}} */
  732. /* {{{ arginfo */
  733. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_construct, 0, 0, 0)
  734. ZEND_ARG_INFO(0, object_name)
  735. ZEND_ARG_INFO(0, variables)
  736. ZEND_ARG_INFO(0, snapshot_blob)
  737. ZEND_END_ARG_INFO()
  738. ZEND_BEGIN_ARG_INFO(arginfo_v8js_sleep, 0)
  739. ZEND_END_ARG_INFO()
  740. ZEND_BEGIN_ARG_INFO(arginfo_v8js_wakeup, 0)
  741. ZEND_END_ARG_INFO()
  742. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_executestring, 0, 0, 1)
  743. ZEND_ARG_INFO(0, script)
  744. ZEND_ARG_INFO(0, identifier)
  745. ZEND_ARG_INFO(0, flags)
  746. ZEND_ARG_INFO(0, time_limit)
  747. ZEND_ARG_INFO(0, memory_limit)
  748. ZEND_END_ARG_INFO()
  749. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_compilestring, 0, 0, 1)
  750. ZEND_ARG_INFO(0, script)
  751. ZEND_ARG_INFO(0, identifier)
  752. ZEND_END_ARG_INFO()
  753. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_executescript, 0, 0, 1)
  754. ZEND_ARG_INFO(0, script)
  755. ZEND_ARG_INFO(0, flags)
  756. ZEND_ARG_INFO(0, time_limit)
  757. ZEND_ARG_INFO(0, memory_limit)
  758. ZEND_END_ARG_INFO()
  759. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_checkstring, 0, 0, 1)
  760. ZEND_ARG_INFO(0, script)
  761. ZEND_END_ARG_INFO()
  762. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setmodulenormaliser, 0, 0, 2)
  763. ZEND_ARG_INFO(0, base)
  764. ZEND_ARG_INFO(0, module_id)
  765. ZEND_END_ARG_INFO()
  766. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setmoduleloader, 0, 0, 1)
  767. ZEND_ARG_INFO(0, callable)
  768. ZEND_END_ARG_INFO()
  769. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setexceptionfilter, 0, 0, 1)
  770. ZEND_ARG_INFO(0, callable)
  771. ZEND_END_ARG_INFO()
  772. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setaverageobjectsize, 0, 0, 1)
  773. ZEND_ARG_INFO(0, average_object_size)
  774. ZEND_END_ARG_INFO()
  775. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_createsnapshot, 0, 0, 1)
  776. ZEND_ARG_INFO(0, script)
  777. ZEND_END_ARG_INFO()
  778. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_settimelimit, 0, 0, 1)
  779. ZEND_ARG_INFO(0, time_limit)
  780. ZEND_END_ARG_INFO()
  781. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setmemorylimit, 0, 0, 1)
  782. ZEND_ARG_INFO(0, memory_limit)
  783. ZEND_END_ARG_INFO()
  784. const zend_function_entry v8js_methods[] = { /* {{{ */
  785. PHP_ME(V8Js, __construct, arginfo_v8js_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
  786. PHP_ME(V8Js, __sleep, arginfo_v8js_sleep, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
  787. PHP_ME(V8Js, __wakeup, arginfo_v8js_wakeup, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
  788. PHP_ME(V8Js, executeString, arginfo_v8js_executestring, ZEND_ACC_PUBLIC)
  789. PHP_ME(V8Js, compileString, arginfo_v8js_compilestring, ZEND_ACC_PUBLIC)
  790. PHP_ME(V8Js, executeScript, arginfo_v8js_executescript, ZEND_ACC_PUBLIC)
  791. PHP_ME(V8Js, setModuleNormaliser, arginfo_v8js_setmodulenormaliser, ZEND_ACC_PUBLIC)
  792. PHP_ME(V8Js, setModuleLoader, arginfo_v8js_setmoduleloader, ZEND_ACC_PUBLIC)
  793. PHP_ME(V8Js, setExceptionFilter, arginfo_v8js_setexceptionfilter, ZEND_ACC_PUBLIC)
  794. PHP_ME(V8Js, setTimeLimit, arginfo_v8js_settimelimit, ZEND_ACC_PUBLIC)
  795. PHP_ME(V8Js, setMemoryLimit, arginfo_v8js_setmemorylimit, ZEND_ACC_PUBLIC)
  796. PHP_ME(V8Js, setAverageObjectSize, arginfo_v8js_setaverageobjectsize, ZEND_ACC_PUBLIC)
  797. PHP_ME(V8Js, createSnapshot, arginfo_v8js_createsnapshot, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
  798. {NULL, NULL, NULL}
  799. };
  800. /* }}} */
  801. /* V8Js object handlers */
  802. static zval* v8js_write_property(zend_object *object, zend_string *member, zval *value, void **cache_slot) /* {{{ */
  803. {
  804. v8js_ctx *c = Z_V8JS_CTX_OBJ(object);
  805. V8JS_CTX_PROLOGUE_EX(c, value);
  806. /* Check whether member is public, if so, export to V8. */
  807. zend_property_info *property_info = zend_get_property_info(c->std.ce, member, 1);
  808. if(!property_info ||
  809. (property_info != ZEND_WRONG_PROPERTY_INFO &&
  810. (property_info->flags & ZEND_ACC_PUBLIC))) {
  811. /* Global PHP JS object */
  812. v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(isolate, c->object_name);
  813. v8::Local<v8::Object> jsobj = V8JS_GLOBAL(isolate)->Get(v8_context, object_name_js).ToLocalChecked()->ToObject(v8_context).ToLocalChecked();
  814. if (ZSTR_LEN(member) > std::numeric_limits<int>::max()) {
  815. zend_throw_exception(php_ce_v8js_exception,
  816. "Property name exceeds maximum supported length", 0);
  817. return value;
  818. }
  819. /* Write value to PHP JS object */
  820. v8::Local<v8::Name> key = V8JS_SYML(ZSTR_VAL(member), static_cast<int>(ZSTR_LEN(member)));
  821. jsobj->DefineOwnProperty(v8_context, key, zval_to_v8js(value, isolate), v8::ReadOnly);
  822. }
  823. /* Write value to PHP object */
  824. return std_object_handlers.write_property(object, member, value, NULL);
  825. }
  826. /* }}} */
  827. static void v8js_unset_property(zend_object *object, zend_string *member, void **cache_slot) /* {{{ */
  828. {
  829. V8JS_BEGIN_CTX_OBJ(c, object);
  830. /* Global PHP JS object */
  831. v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(isolate, c->object_name);
  832. v8::Local<v8::Object> jsobj = V8JS_GLOBAL(isolate)->Get(v8_context, object_name_js).ToLocalChecked()->ToObject(v8_context).ToLocalChecked();
  833. if (ZSTR_LEN(member) > std::numeric_limits<int>::max()) {
  834. zend_throw_exception(php_ce_v8js_exception,
  835. "Property name exceeds maximum supported length", 0);
  836. return;
  837. }
  838. /* Delete value from PHP JS object */
  839. v8::Local<v8::Value> key = V8JS_SYML(ZSTR_VAL(member), static_cast<int>(ZSTR_LEN(member)));
  840. jsobj->Delete(v8_context, key);
  841. /* Unset from PHP object */
  842. std_object_handlers.unset_property(object, member, NULL);
  843. }
  844. /* }}} */
  845. PHP_MINIT_FUNCTION(v8js_class) /* {{{ */
  846. {
  847. zend_class_entry ce;
  848. /* V8Js Class */
  849. INIT_CLASS_ENTRY(ce, "V8Js", v8js_methods);
  850. php_ce_v8js = zend_register_internal_class(&ce);
  851. php_ce_v8js->create_object = v8js_new;
  852. #if PHP_VERSION_ID >= 80200
  853. php_ce_v8js->ce_flags |= ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES;
  854. zend_string *attribute_name_AllowDynamicProperties_class_V8Js = zend_string_init_interned("AllowDynamicProperties", sizeof("AllowDynamicProperties") - 1, 1);
  855. zend_add_class_attribute(php_ce_v8js, attribute_name_AllowDynamicProperties_class_V8Js, 0);
  856. zend_string_release(attribute_name_AllowDynamicProperties_class_V8Js);
  857. #endif
  858. /* V8Js handlers */
  859. memcpy(&v8js_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
  860. v8js_object_handlers.clone_obj = NULL;
  861. v8js_object_handlers.write_property = v8js_write_property;
  862. v8js_object_handlers.unset_property = v8js_unset_property;
  863. /* V8Js Class Constants */
  864. zend_declare_class_constant_string(php_ce_v8js, ZEND_STRL("V8_VERSION"), PHP_V8_VERSION);
  865. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("FLAG_NONE"), V8JS_FLAG_NONE);
  866. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("FLAG_FORCE_ARRAY"), V8JS_FLAG_FORCE_ARRAY);
  867. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("FLAG_PROPAGATE_PHP_EXCEPTIONS"), V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS);
  868. le_v8js_script = zend_register_list_destructors_ex(v8js_script_dtor, NULL, PHP_V8JS_SCRIPT_RES_NAME, module_number);
  869. return SUCCESS;
  870. } /* }}} */
  871. /*
  872. * Local variables:
  873. * tab-width: 4
  874. * c-basic-offset: 4
  875. * indent-tabs-mode: t
  876. * End:
  877. * vim600: noet sw=4 ts=4 fdm=marker
  878. * vim<600: noet sw=4 ts=4
  879. */