This repository was archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathphp_v8_isolate_limits.h
72 lines (53 loc) · 2.56 KB
/
php_v8_isolate_limits.h
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
/*
* This file is part of the pinepain/php-v8 PHP extension.
*
* Copyright (c) 2015-2018 Bogdan Padalko <pinepain@gmail.com>
*
* Licensed under the MIT license: http://opensource.org/licenses/MIT
*
* For the full copyright and license information, please view the
* LICENSE file that was distributed with this source or visit
* http://opensource.org/licenses/MIT
*/
#ifndef PHP_V8_ISOLATE_LIMITS_H
#define PHP_V8_ISOLATE_LIMITS_H
typedef struct _php_v8_isolate_limits_t php_v8_isolate_limits_t;
#include "php_v8_exceptions.h"
#include <v8.h>
#include <atomic>
#include <mutex>
#include <thread>
#include <chrono>
extern void php_v8_isolate_limits_thread(php_v8_isolate_t *php_v8_isolate);
extern void php_v8_isolate_limits_maybe_start_timer(php_v8_isolate_t *php_v8_isolate);
extern void php_v8_isolate_limits_maybe_stop_timer(php_v8_isolate_t *php_v8_isolate);
extern void php_v8_isolate_limits_free(php_v8_isolate_t *php_v8_isolate);
extern void php_v8_isolate_limits_ctor(php_v8_isolate_t *php_v8_isolate);
extern void php_v8_isolate_limits_set_time_limit(php_v8_isolate_t *php_v8_isolate, double time_limit_in_seconds);
extern void php_v8_isolate_limits_set_memory_limit(php_v8_isolate_t *php_v8_isolate, size_t memory_limit_in_bytes);
extern void php_v8_isolate_limits_set_limits(php_v8_isolate_t *php_v8_isolate, double time_limit_in_seconds, size_t memory_limit_in_bytes);
#define PHP_V8_DECLARE_ISOLATE_LOCAL_ALIAS(i) v8::Isolate *isolate = (i);
#define PHP_V8_DECLARE_LIMITS(php_v8_isolate) \
php_v8_isolate_limits_t *limits = &(php_v8_isolate)->limits;
#define PHP_V8_INIT_ISOLATE_LIMITS_ON_SCRIPT(php_v8_script) \
PHP_V8_THROW_EXCEPTION_WHEN_LIMITS_HIT((php_v8_script)->php_v8_context); \
php_v8_isolate_limits_maybe_start_timer((php_v8_script)->php_v8_isolate);
#define PHP_V8_INIT_ISOLATE_LIMITS_ON_OBJECT_VALUE(php_v8_value) \
PHP_V8_THROW_EXCEPTION_WHEN_LIMITS_HIT((php_v8_value)->php_v8_context); \
php_v8_isolate_limits_maybe_start_timer((php_v8_value)->php_v8_isolate);
#define PHP_V8_INIT_ISOLATE_LIMITS_ON_CONTEXT(php_v8_context) \
PHP_V8_THROW_EXCEPTION_WHEN_LIMITS_HIT(php_v8_context); \
php_v8_isolate_limits_maybe_start_timer((php_v8_context)->php_v8_isolate);
struct _php_v8_isolate_limits_t {
std::atomic_bool active;
uint32_t depth;
std::thread *thread;
std::mutex *mutex;
std::chrono::time_point<std::chrono::high_resolution_clock> time_point;
double time_limit;
bool time_limit_hit;
size_t memory_limit;
bool memory_limit_hit;
bool memory_limit_in_progress;
};
#endif //PHP_V8_ISOLATE_LIMITS_H