summaryrefslogtreecommitdiff
path: root/sapi/phpdbg/phpdbg_sigsafe.c
diff options
context:
space:
mode:
authorRasmus Lerdorf <rasmus@php.net>2014-10-26 16:58:45 -0700
committerRasmus Lerdorf <rasmus@php.net>2014-10-26 16:58:45 -0700
commit8d84b1f67adb71bdb2394b62faad04b22f6226f3 (patch)
tree0c1c1ed2aaef8eee971575eb5e336631295f4951 /sapi/phpdbg/phpdbg_sigsafe.c
parentfb85d0322d39d49f37e32df6f68c9769f2cce0e4 (diff)
parent09da8952d0434b53e740ffaca66a8051cd39cf93 (diff)
downloadphp-git-8d84b1f67adb71bdb2394b62faad04b22f6226f3.tar.gz
Merge branch 'master' of git.php.net:php-src
* 'master' of git.php.net:php-src: (240 commits) Do not execute anything after quit or clean command Fix last commit, and do not output unnecessary information Stabilize execution, always run destructors and extended file breakpoints Fix nullptr dereference in clean without exec context remove dodgy param parser, bring userland breakpoint api inline with PHP7 disable output buffering by default Add question to reset execution in run/exec/clean - Updated to version 2014.9 (2014i) actually remove this disable output buffering, better breakpoint api for userland, remove hand parsing of params Fix phpdbg output when outputting via php with active output handlers Fixed Closure::call() NEWS/UPGRADING Set engine back to initial state after fatal-ed ev command Fix eventual stack overflow after clean cmd Fix listing of files with no absolute path updated libmagic.patch in master updated libmagic.patch in 5.6 updated libmagic.patch in 5.5 NEWS NEWS ...
Diffstat (limited to 'sapi/phpdbg/phpdbg_sigsafe.c')
-rw-r--r--sapi/phpdbg/phpdbg_sigsafe.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/sapi/phpdbg/phpdbg_sigsafe.c b/sapi/phpdbg/phpdbg_sigsafe.c
new file mode 100644
index 0000000000..1ca7bf230c
--- /dev/null
+++ b/sapi/phpdbg/phpdbg_sigsafe.c
@@ -0,0 +1,56 @@
+#include "phpdbg_sigsafe.h"
+#include "phpdbg.h"
+
+ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
+
+#define STR(x) #x
+#define EXP_STR(x) STR(x)
+
+static void* zend_mm_mem_alloc(zend_mm_storage *storage, size_t size, size_t alignment) {
+ TSRMLS_FETCH();
+
+ if (EXPECTED(size == PHPDBG_SIGSAFE_MEM_SIZE && !PHPDBG_G(sigsafe_mem).allocated)) {
+ PHPDBG_G(sigsafe_mem).allocated = 1;
+ return PHPDBG_G(sigsafe_mem).mem;
+ }
+
+ write(PHPDBG_G(io)[PHPDBG_STDERR].fd, ZEND_STRL("Tried to allocate more than " EXP_STR(PHPDBG_SIGSAFE_MEM_SIZE) " bytes from stack memory in signal handler ... bailing out of signal handler\n"));
+
+ if (*EG(bailout)) {
+ LONGJMP(*EG(bailout), FAILURE);
+ }
+
+ write(PHPDBG_G(io)[PHPDBG_STDERR].fd, ZEND_STRL("Bailed out without a bailout address in signal handler!\n"));
+
+ return NULL;
+}
+
+static void zend_mm_mem_free(zend_mm_storage *storage, void *ptr, size_t size) {
+}
+
+void phpdbg_set_sigsafe_mem(char *buffer TSRMLS_DC) {
+ phpdbg_signal_safe_mem *mem = &PHPDBG_G(sigsafe_mem);
+ mem->mem = buffer;
+ mem->allocated = 0;
+
+ mem->storage.chunk_alloc = zend_mm_mem_alloc;
+ mem->storage.chunk_free = zend_mm_mem_free;
+
+ mem->heap = zend_mm_startup_ex(&mem->storage);
+
+ mem->old_heap = zend_mm_set_heap(mem->heap TSRMLS_CC);
+}
+
+zend_mm_heap *phpdbg_original_heap_sigsafe_mem(TSRMLS_D) {
+ return PHPDBG_G(sigsafe_mem).old_heap;
+}
+
+void phpdbg_clear_sigsafe_mem(TSRMLS_D) {
+ zend_mm_set_heap(phpdbg_original_heap_sigsafe_mem(TSRMLS_C) TSRMLS_CC);
+ PHPDBG_G(sigsafe_mem).mem = NULL;
+}
+
+zend_bool phpdbg_active_sigsafe_mem(TSRMLS_D) {
+ return !!PHPDBG_G(sigsafe_mem).mem;
+}
+