root/ext/opcache/ZendAccelerator.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2    +----------------------------------------------------------------------+
   3    | Zend OPcache                                                         |
   4    +----------------------------------------------------------------------+
   5    | Copyright (c) 1998-2016 The PHP Group                                |
   6    +----------------------------------------------------------------------+
   7    | This source file is subject to version 3.01 of the PHP license,      |
   8    | that is bundled with this package in the file LICENSE, and is        |
   9    | available through the world-wide-web at the following url:           |
  10    | http://www.php.net/license/3_01.txt                                  |
  11    | If you did not receive a copy of the PHP license and are unable to   |
  12    | obtain it through the world-wide-web, please send a note to          |
  13    | license@php.net so we can mail you a copy immediately.               |
  14    +----------------------------------------------------------------------+
  15    | Authors: Andi Gutmans <andi@zend.com>                                |
  16    |          Zeev Suraski <zeev@zend.com>                                |
  17    |          Stanislav Malyshev <stas@zend.com>                          |
  18    |          Dmitry Stogov <dmitry@zend.com>                             |
  19    +----------------------------------------------------------------------+
  20 */
  21 
  22 #ifndef ZEND_ACCELERATOR_H
  23 #define ZEND_ACCELERATOR_H
  24 
  25 #ifdef HAVE_CONFIG_H
  26 # include <config.h>
  27 #endif
  28 
  29 #define ACCELERATOR_PRODUCT_NAME        "Zend OPcache"
  30 #define PHP_ZENDOPCACHE_VERSION         "7.0.6-dev"
  31 #define ACCELERATOR_VERSION PHP_ZENDOPCACHE_VERSION
  32 /* 2 - added Profiler support, on 20010712 */
  33 /* 3 - added support for Optimizer's encoded-only-files mode */
  34 /* 4 - works with the new Optimizer, that supports the file format with licenses */
  35 /* 5 - API 4 didn't really work with the license-enabled file format.  v5 does. */
  36 /* 6 - Monitor was removed from ZendPlatform.so, to a module of its own */
  37 /* 7 - Optimizer was embedded into Accelerator */
  38 /* 8 - Standalone Open Source Zend OPcache */
  39 #define ACCELERATOR_API_NO 8
  40 
  41 #if ZEND_WIN32
  42 # include "zend_config.w32.h"
  43 #else
  44 #include "zend_config.h"
  45 # include <sys/time.h>
  46 # include <sys/resource.h>
  47 #endif
  48 
  49 #if HAVE_UNISTD_H
  50 # include "unistd.h"
  51 #endif
  52 
  53 #include "zend_extensions.h"
  54 #include "zend_compile.h"
  55 
  56 #include "Optimizer/zend_optimizer.h"
  57 #include "zend_accelerator_hash.h"
  58 #include "zend_accelerator_debug.h"
  59 
  60 #ifndef PHPAPI
  61 # ifdef ZEND_WIN32
  62 #  define PHPAPI __declspec(dllimport)
  63 # else
  64 #  define PHPAPI
  65 # endif
  66 #endif
  67 
  68 #ifndef ZEND_EXT_API
  69 # if WIN32|WINNT
  70 #  define ZEND_EXT_API __declspec(dllexport)
  71 # elif defined(__GNUC__) && __GNUC__ >= 4
  72 #  define ZEND_EXT_API __attribute__ ((visibility("default")))
  73 # else
  74 #  define ZEND_EXT_API
  75 # endif
  76 #endif
  77 
  78 #ifdef ZEND_WIN32
  79 # ifndef MAXPATHLEN
  80 #  define MAXPATHLEN     _MAX_PATH
  81 # endif
  82 # include <direct.h>
  83 #else
  84 # ifndef MAXPATHLEN
  85 #  define MAXPATHLEN     4096
  86 # endif
  87 # include <sys/param.h>
  88 #endif
  89 
  90 #define PHP_5_0_X_API_NO                220040412
  91 #define PHP_5_1_X_API_NO                220051025
  92 #define PHP_5_2_X_API_NO                220060519
  93 #define PHP_5_3_X_API_NO                220090626
  94 #define PHP_5_4_X_API_NO                220100525
  95 #define PHP_5_5_X_API_NO                220121212
  96 #define PHP_5_6_X_API_NO                220131226
  97 
  98 /*** file locking ***/
  99 #ifndef ZEND_WIN32
 100 extern int lock_file;
 101 
 102 # if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || (defined(__APPLE__) && defined(__MACH__)/* Darwin */) || defined(__OpenBSD__) || defined(__NetBSD__)
 103 #  define FLOCK_STRUCTURE(name, type, whence, start, len) \
 104                 struct flock name = {start, len, -1, type, whence}
 105 # elif defined(__svr4__)
 106 #  define FLOCK_STRUCTURE(name, type, whence, start, len) \
 107                 struct flock name = {type, whence, start, len}
 108 # elif defined(__linux__) || defined(__hpux) || defined(__GNU__)
 109 #  define FLOCK_STRUCTURE(name, type, whence, start, len) \
 110                 struct flock name = {type, whence, start, len, 0}
 111 # elif defined(_AIX)
 112 #  if defined(_LARGE_FILES) || defined(__64BIT__)
 113 #   define FLOCK_STRUCTURE(name, type, whence, start, len) \
 114                 struct flock name = {type, whence, 0, 0, 0, start, len }
 115 #  else
 116 #   define FLOCK_STRUCTURE(name, type, whence, start, len) \
 117                 struct flock name = {type, whence, start, len}
 118 #  endif
 119 # elif defined(HAVE_FLOCK_BSD)
 120 #  define FLOCK_STRUCTURE(name, type, whence, start, len) \
 121                 struct flock name = {start, len, -1, type, whence}
 122 # elif defined(HAVE_FLOCK_LINUX)
 123 #  define FLOCK_STRUCTURE(name, type, whence, start, len) \
 124                 struct flock name = {type, whence, start, len}
 125 # else
 126 #  error "Don't know how to define struct flock"
 127 # endif
 128 #endif
 129 
 130 #define PZ_REFCOUNT_P(pz)                               (pz)->refcount__gc
 131 #define PZ_SET_REFCOUNT_P(pz, v)                (pz)->refcount__gc = (v)
 132 #define PZ_ADDREF_P(pz)                                 ++((pz)->refcount__gc)
 133 #define PZ_DELREF_P(pz)                                 --((pz)->refcount__gc)
 134 #define PZ_ISREF_P(pz)                                  (pz)->is_ref__gc
 135 #define PZ_SET_ISREF_P(pz)                              Z_SET_ISREF_TO_P(pz, 1)
 136 #define PZ_UNSET_ISREF_P(pz)                    Z_SET_ISREF_TO_P(pz, 0)
 137 #define PZ_SET_ISREF_TO_P(pz, isref)    (pz)->is_ref__gc = (isref)
 138 
 139 #define DO_ALLOCA(x)    do_alloca(x, use_heap)
 140 #define FREE_ALLOCA(x)  free_alloca(x, use_heap)
 141 
 142 #if defined(HAVE_OPCACHE_FILE_CACHE) && defined(ZEND_WIN32)
 143 # define ENABLE_FILE_CACHE_FALLBACK 1
 144 #endif
 145 
 146 #if ZEND_WIN32
 147 typedef unsigned __int64 accel_time_t;
 148 #else
 149 typedef time_t accel_time_t;
 150 #endif
 151 
 152 typedef enum _zend_accel_restart_reason {
 153         ACCEL_RESTART_OOM,    /* restart because of out of memory */
 154         ACCEL_RESTART_HASH,   /* restart because of hash overflow */
 155         ACCEL_RESTART_USER    /* restart scheduled by opcache_reset() */
 156 } zend_accel_restart_reason;
 157 
 158 typedef struct _zend_persistent_script {
 159         zend_string   *full_path;              /* full real path with resolved symlinks */
 160         zend_op_array  main_op_array;
 161         HashTable      function_table;
 162         HashTable      class_table;
 163         zend_long           compiler_halt_offset;   /* position of __HALT_COMPILER or -1 */
 164         int            ping_auto_globals_mask; /* which autoglobals are used by the script */
 165         accel_time_t   timestamp;              /* the script modification time */
 166         zend_bool      corrupted;
 167         zend_bool      is_phar;
 168 
 169         void          *mem;                    /* shared memory area used by script structures */
 170         size_t         size;                   /* size of used shared memory */
 171         void          *arena_mem;              /* part that should be copied into process */
 172         size_t         arena_size;
 173 
 174         /* All entries that shouldn't be counted in the ADLER32
 175          * checksum must be declared in this struct
 176          */
 177         struct zend_persistent_script_dynamic_members {
 178                 time_t       last_used;
 179 #ifdef ZEND_WIN32
 180                 LONGLONG   hits;
 181 #else
 182                 zend_ulong        hits;
 183 #endif
 184                 unsigned int memory_consumption;
 185                 unsigned int checksum;
 186                 time_t       revalidate;
 187         } dynamic_members;
 188 } zend_persistent_script;
 189 
 190 typedef struct _zend_accel_directives {
 191         zend_long           memory_consumption;
 192         zend_long           max_accelerated_files;
 193         double         max_wasted_percentage;
 194         char          *user_blacklist_filename;
 195         zend_long           consistency_checks;
 196         zend_long           force_restart_timeout;
 197         zend_bool      use_cwd;
 198         zend_bool      ignore_dups;
 199         zend_bool      validate_timestamps;
 200         zend_bool      revalidate_path;
 201         zend_bool      save_comments;
 202         zend_bool      fast_shutdown;
 203         zend_bool      protect_memory;
 204         zend_bool      file_override_enabled;
 205         zend_bool      inherited_hack;
 206         zend_bool      enable_cli;
 207         zend_ulong  revalidate_freq;
 208         zend_ulong  file_update_protection;
 209         char          *error_log;
 210 #ifdef ZEND_WIN32
 211         char          *mmap_base;
 212 #endif
 213         char          *memory_model;
 214         zend_long           log_verbosity_level;
 215 
 216         zend_long           optimization_level;
 217         zend_long           max_file_size;
 218         zend_long           interned_strings_buffer;
 219         char          *restrict_api;
 220 #ifdef HAVE_OPCACHE_FILE_CACHE
 221         char          *file_cache;
 222         zend_bool      file_cache_only;
 223         zend_bool      file_cache_consistency_checks;
 224 #endif
 225 #if ENABLE_FILE_CACHE_FALLBACK
 226         zend_bool      file_cache_fallback;
 227 #endif
 228 #ifdef HAVE_HUGE_CODE_PAGES
 229         zend_bool      huge_code_pages;
 230 #endif
 231 } zend_accel_directives;
 232 
 233 typedef struct _zend_accel_globals {
 234     /* copy of CG(function_table) used for compilation scripts into cache */
 235     /* initially it contains only internal functions */
 236         HashTable               function_table;
 237         int                     internal_functions_count;
 238         int                     counted;   /* the process uses shared memory */
 239         zend_bool               enabled;
 240         zend_bool               locked;    /* thread obtained exclusive lock */
 241         HashTable               bind_hash; /* prototype and zval lookup table */
 242         zend_accel_directives   accel_directives;
 243         zend_string            *cwd;                  /* current working directory or NULL */
 244         zend_string            *include_path;         /* current value of "include_path" directive */
 245         char                    include_path_key[32]; /* key of current "include_path" */
 246         char                    cwd_key[32];          /* key of current working directory */
 247         int                     include_path_key_len;
 248         int                     include_path_check;
 249         int                     cwd_key_len;
 250         int                     cwd_check;
 251         int                     auto_globals_mask;
 252         time_t                  request_time;
 253         time_t                  last_restart_time; /* used to synchronize SHM and in-process caches */
 254         char                    system_id[32];
 255         HashTable               xlat_table;
 256         /* preallocated shared-memory block to save current script */
 257         void                   *mem;
 258         void                   *arena_mem;
 259         zend_persistent_script *current_persistent_script;
 260         /* cache to save hash lookup on the same INCLUDE opcode */
 261         const zend_op          *cache_opline;
 262         zend_persistent_script *cache_persistent_script;
 263         /* preallocated buffer for keys */
 264         int                     key_len;
 265         char                    key[MAXPATHLEN * 8];
 266 } zend_accel_globals;
 267 
 268 typedef struct _zend_accel_shared_globals {
 269         /* Cache Data Structures */
 270         zend_ulong   hits;
 271         zend_ulong   misses;
 272         zend_ulong   blacklist_misses;
 273         zend_ulong   oom_restarts;     /* number of restarts because of out of memory */
 274         zend_ulong   hash_restarts;    /* number of restarts because of hash overflow */
 275         zend_ulong   manual_restarts;  /* number of restarts scheduled by opcache_reset() */
 276         zend_accel_hash hash;             /* hash table for cached scripts */
 277 
 278         /* Directives & Maintenance */
 279         time_t          start_time;
 280         time_t          last_restart_time;
 281         time_t          force_restart_time;
 282         zend_bool       accelerator_enabled;
 283         zend_bool       restart_pending;
 284         zend_accel_restart_reason restart_reason;
 285         zend_bool       cache_status_before_restart;
 286 #ifdef ZEND_WIN32
 287         LONGLONG   mem_usage;
 288         LONGLONG   restart_in;
 289 #endif
 290         zend_bool       restart_in_progress;
 291         /* Interned Strings Support */
 292         char           *interned_strings_start;
 293         char           *interned_strings_top;
 294         char           *interned_strings_end;
 295         char           *interned_strings_saved_top;
 296         HashTable       interned_strings;
 297 } zend_accel_shared_globals;
 298 
 299 extern zend_bool accel_startup_ok;
 300 #if ENABLE_FILE_CACHE_FALLBACK
 301 extern zend_bool fallback_process;
 302 #endif
 303 
 304 extern zend_accel_shared_globals *accel_shared_globals;
 305 #define ZCSG(element)   (accel_shared_globals->element)
 306 
 307 #ifdef ZTS
 308 # define ZCG(v) ZEND_TSRMG(accel_globals_id, zend_accel_globals *, v)
 309 extern int accel_globals_id;
 310 # ifdef COMPILE_DL_OPCACHE
 311 ZEND_TSRMLS_CACHE_EXTERN()
 312 # endif
 313 #else
 314 # define ZCG(v) (accel_globals.v)
 315 extern zend_accel_globals accel_globals;
 316 #endif
 317 
 318 extern char *zps_api_failure_reason;
 319 
 320 void accel_shutdown(void);
 321 int  accel_post_deactivate(void);
 322 void zend_accel_schedule_restart(zend_accel_restart_reason reason);
 323 void zend_accel_schedule_restart_if_necessary(zend_accel_restart_reason reason);
 324 accel_time_t zend_get_file_handle_timestamp(zend_file_handle *file_handle, size_t *size);
 325 int  validate_timestamp_and_record(zend_persistent_script *persistent_script, zend_file_handle *file_handle);
 326 int  zend_accel_invalidate(const char *filename, int filename_len, zend_bool force);
 327 int  zend_accel_script_optimize(zend_persistent_script *persistent_script);
 328 int  accelerator_shm_read_lock(void);
 329 void accelerator_shm_read_unlock(void);
 330 
 331 char *accel_make_persistent_key(const char *path, int path_length, int *key_len);
 332 zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type);
 333 
 334 #if !defined(ZEND_DECLARE_INHERITED_CLASS_DELAYED)
 335 # define ZEND_DECLARE_INHERITED_CLASS_DELAYED 145
 336 #endif
 337 
 338 #define ZEND_DECLARE_INHERITED_CLASS_DELAYED_FLAG 0x80
 339 
 340 #define IS_ACCEL_INTERNED(str) \
 341         ((char*)(str) >= ZCSG(interned_strings_start) && (char*)(str) < ZCSG(interned_strings_end))
 342 
 343 zend_string *accel_new_interned_string(zend_string *str);
 344 
 345 # define ZEND_RESULT_TYPE(opline)       (opline)->result_type
 346 # define ZEND_RESULT(opline)            (opline)->result
 347 # define ZEND_OP1_TYPE(opline)          (opline)->op1_type
 348 # define ZEND_OP1(opline)                       (opline)->op1
 349 # define ZEND_OP1_CONST(opline)         (*(opline)->op1.zv)
 350 # define ZEND_OP1_LITERAL(opline)       (op_array)->literals[(opline)->op1.constant]
 351 # define ZEND_OP2_TYPE(opline)          (opline)->op2_type
 352 # define ZEND_OP2(opline)                       (opline)->op2
 353 # define ZEND_OP2_CONST(opline)         (*(opline)->op2.zv)
 354 # define ZEND_OP2_LITERAL(opline)       (op_array)->literals[(opline)->op2.constant]
 355 # define ZEND_DONE_PASS_TWO(op_array)   (((op_array)->fn_flags & ZEND_ACC_DONE_PASS_TWO) != 0)
 356 # define ZEND_CE_FILENAME(ce)                   (ce)->info.user.filename
 357 # define ZEND_CE_DOC_COMMENT(ce)        (ce)->info.user.doc_comment
 358 # define ZEND_CE_DOC_COMMENT_LEN(ce)    (ce)->info.user.doc_comment_len
 359 
 360 #endif /* ZEND_ACCELERATOR_H */

/* [<][>][^][v][top][bottom][index][help] */