com php-src: add INI option to control exit() on OOM: Zend/zend_alloc.c Zend/zend_alloc.h main/main.c main/php_globals.h
| From: | Antony Dovgal | Date: | Thu, 27 Feb 2014 08:37:42 +0000 |
| Subject: | com php-src: add INI option to control exit() on OOM: Zend/zend_alloc.c Zend/zend_alloc.h main/main.c main/php_globals.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-76619@lists.php.net to get a copy of this message | ||
Commit: cfa58da8084d7e280e189557863034add9b9a233
Author: Antony Dovgal <tony2001@php.net> Thu, 27 Feb 2014 12:37:42 +0400
Parents: ca0481ed178ad3f61319f454bb703dfd885b62d1
Branches: badoo-5.5_mysqlnd
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=cfa58da8084d7e280e189557863034add9b9a233
Log:
add INI option to control exit() on OOM
Changed paths:
M Zend/zend_alloc.c
M Zend/zend_alloc.h
M main/main.c
M main/php_globals.h
Diff:
diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c
index adb94fe..eb940d0 100644
--- a/Zend/zend_alloc.c
+++ b/Zend/zend_alloc.c
@@ -1740,6 +1740,19 @@ ZEND_API void zend_mm_shutdown(zend_mm_heap *heap, int full_shutdown, int
silent
}
}
+typedef struct _zend_alloc_globals {
+ zend_mm_heap *mm_heap;
+ zend_bool exit_on_oom;
+} zend_alloc_globals;
+
+#ifdef ZTS
+static int alloc_globals_id;
+# define AG(v) TSRMG(alloc_globals_id, zend_alloc_globals *, v)
+#else
+# define AG(v) (alloc_globals.v)
+static zend_alloc_globals alloc_globals;
+#endif
+
static void zend_mm_safe_error(zend_mm_heap *heap,
const char *format,
size_t limit,
@@ -1801,8 +1814,12 @@ static void zend_mm_safe_error(zend_mm_heap *heap,
} else {
heap->overflow = 2;
}
- /* zend_bailout(); */
- abort();
+
+ if (AG(exit_on_oom)) {
+ exit(-1);
+ } else {
+ zend_bailout();
+ }
}
static zend_mm_free_block *zend_mm_search_large_block(zend_mm_heap *heap, size_t true_size)
@@ -2403,18 +2420,6 @@ ZEND_API size_t _zend_mm_block_size(zend_mm_heap *heap, void *p
ZEND_FILE_LINE_D
/* Allocation Manager */
/**********************/
-typedef struct _zend_alloc_globals {
- zend_mm_heap *mm_heap;
-} zend_alloc_globals;
-
-#ifdef ZTS
-static int alloc_globals_id;
-# define AG(v) TSRMG(alloc_globals_id, zend_alloc_globals *, v)
-#else
-# define AG(v) (alloc_globals.v)
-static zend_alloc_globals alloc_globals;
-#endif
-
ZEND_API int is_zend_mm(TSRMLS_D)
{
return AG(mm_heap)->use_zend_alloc;
@@ -2692,6 +2697,15 @@ ZEND_API int zend_set_memory_limit(size_t memory_limit)
return SUCCESS;
}
+ZEND_API int zend_set_exit_on_oom(int value)
+{
+ TSRMLS_FETCH();
+
+ AG(exit_on_oom) = value ? 1 : 0;
+
+ return SUCCESS;
+}
+
ZEND_API size_t zend_memory_usage(int real_usage TSRMLS_DC)
{
if (real_usage) {
@@ -2733,6 +2747,7 @@ static void alloc_globals_ctor(zend_alloc_globals *alloc_globals TSRMLS_DC)
} else {
alloc_globals->mm_heap = zend_mm_startup();
}
+ alloc_globals->exit_on_oom = 0;
}
#ifdef ZTS
diff --git a/Zend/zend_alloc.h b/Zend/zend_alloc.h
index 0b4e74d..b9b4c2a 100644
--- a/Zend/zend_alloc.h
+++ b/Zend/zend_alloc.h
@@ -140,6 +140,7 @@ inline static void * __zend_realloc(void *p, size_t len)
#define safe_estrndup(ptr, len) ((ptr)?(estrndup((ptr), (len))):STR_EMPTY_ALLOC())
ZEND_API int zend_set_memory_limit(size_t memory_limit);
+ZEND_API int zend_set_exit_on_oom(int value);
ZEND_API void start_memory_manager(TSRMLS_D);
ZEND_API void shutdown_memory_manager(int silent, int full_shutdown TSRMLS_DC);
diff --git a/main/main.c b/main/main.c
index 7702ace..91b1f80 100644
--- a/main/main.c
+++ b/main/main.c
@@ -183,6 +183,16 @@ static PHP_INI_MH(OnChangeMemoryLimit)
}
/* }}} */
+/* {{{ PHP_INI_MH
+ */
+static PHP_INI_MH(OnChangeExitOnOOM)
+{
+ int i = atoi(new_value);
+ PG(exit_on_oom) = i ? 1 : 0;
+ return zend_set_exit_on_oom(PG(exit_on_oom));
+}
+/* }}} */
+
/* {{{ php_disable_functions
*/
@@ -552,6 +562,7 @@ PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("mail.log", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateMailLog, mail_log, php_core_globals, core_globals)
PHP_INI_ENTRY("browscap", NULL, PHP_INI_SYSTEM, OnChangeBrowscap)
PHP_INI_ENTRY("memory_limit", "128M", PHP_INI_ALL, OnChangeMemoryLimit)
+ PHP_INI_ENTRY("exit_on_oom", "0", PHP_INI_ALL, OnChangeExitOnOOM)
PHP_INI_ENTRY("precision", "14", PHP_INI_ALL, OnSetPrecision)
PHP_INI_ENTRY("sendmail_from", NULL, PHP_INI_ALL, NULL)
PHP_INI_ENTRY("sendmail_path", DEFAULT_SENDMAIL_PATH, PHP_INI_SYSTEM, NULL)
diff --git a/main/php_globals.h b/main/php_globals.h
index a317da4..6b855c6 100644
--- a/main/php_globals.h
+++ b/main/php_globals.h
@@ -164,6 +164,7 @@ struct _php_core_globals {
zend_bool windows_show_crt_warning;
#endif
long error_log_mode;
+ zend_bool exit_on_oom;
};