]> granicus.if.org Git - php/commitdiff
Fix issues with phpdbg SIGINT handler
authorBob Weinand <bobwei9@hotmail.com>
Fri, 21 Aug 2015 22:36:31 +0000 (23:36 +0100)
committerBob Weinand <bobwei9@hotmail.com>
Fri, 21 Aug 2015 22:36:31 +0000 (23:36 +0100)
Also fix valgrind warnings in allocator when not using mmap()ed memory

Zend/zend_alloc.c
sapi/phpdbg/phpdbg.c
sapi/phpdbg/phpdbg_cmd.c
sapi/phpdbg/phpdbg_prompt.c
sapi/phpdbg/phpdbg_sigsafe.c
sapi/phpdbg/phpdbg_sigsafe.h

index 493cf1f728de884681b391e8a7f11acc624dd48b..16838e04dae17e1792027c513743fc32af628a38 100644 (file)
@@ -2765,6 +2765,7 @@ ZEND_API zend_mm_heap *zend_mm_startup_ex(const zend_mm_handlers *handlers, void
 #endif
        heap->storage = &tmp_storage;
        heap->huge_list = NULL;
+       memset(heap->free_slot, 0, sizeof(heap->free_slot));
        storage = _zend_mm_alloc(heap, sizeof(zend_mm_storage) + data_size ZEND_FILE_LINE_CC ZEND_FILE_LINE_CC);
        if (!storage) {
                handlers->chunk_free(&tmp_storage, chunk, ZEND_MM_CHUNK_SIZE);
index 831d4fc4721967243c9d22e00c19ff6442367fda..4c5dfdea224954c98792d5b1766058b666ba2a2b 100644 (file)
@@ -220,7 +220,7 @@ static PHP_RSHUTDOWN_FUNCTION(phpdbg) /* {{{ */
        zend_llist_destroy(&PHPDBG_G(watchlist_mem));
 
        if (PHPDBG_G(buffer)) {
-               efree(PHPDBG_G(buffer));
+               free(PHPDBG_G(buffer));
                PHPDBG_G(buffer) = NULL;
        }
 
@@ -1085,17 +1085,21 @@ static inline void phpdbg_sigint_handler(int signo) /* {{{ */
                }
        } else {
                /* set signalled only when not interactive */
-               if (!(PHPDBG_G(flags) & PHPDBG_IS_INTERACTIVE)) {
-                       if (PHPDBG_G(flags) & PHPDBG_IS_SIGNALED) {
-                               char mem[PHPDBG_SIGSAFE_MEM_SIZE + 1];
-
-                               phpdbg_set_sigsafe_mem(mem);
-                               zend_try {
-                                       phpdbg_force_interruption();
-                               } zend_end_try()
-                               phpdbg_clear_sigsafe_mem();
-                               return;
+               if (PHPDBG_G(flags) & PHPDBG_IS_SIGNALED) {
+                       char mem[PHPDBG_SIGSAFE_MEM_SIZE + 1];
+
+                       phpdbg_set_sigsafe_mem(mem);
+                       zend_try {
+                               phpdbg_force_interruption();
+                       } zend_end_try()
+                       phpdbg_clear_sigsafe_mem();
+
+                       PHPDBG_G(flags) &= ~PHPDBG_IS_SIGNALED;
+
+                       if (PHPDBG_G(flags) & PHPDBG_IS_STOPPING) {
+                               zend_bailout();
                        }
+               } else {
                        PHPDBG_G(flags) |= PHPDBG_IS_SIGNALED;
                }
        }
@@ -1182,9 +1186,13 @@ void phpdbg_sigio_handler(int sig, siginfo_t *info, void *context) /* {{{ */
                                                        phpdbg_force_interruption();
                                                } zend_end_try();
                                                phpdbg_clear_sigsafe_mem();
-                                               break;
-                                       }
-                                       if (!(PHPDBG_G(flags) & PHPDBG_IS_INTERACTIVE)) {
+
+                                               PHPDBG_G(flags) &= ~PHPDBG_IS_SIGNALED;
+
+                                               if (PHPDBG_G(flags) & PHPDBG_IS_STOPPING) {
+                                                       zend_bailout();
+                                               }
+                                       } else if (!(PHPDBG_G(flags) & PHPDBG_IS_INTERACTIVE)) {
                                                PHPDBG_G(flags) |= PHPDBG_IS_SIGNALED;
                                        }
                                        break;
index a50b340e7df09bf4716d5ef49f0172e57af55ad9..ed4cf3b6d6b258b2c3316e33f16c3b9dc2d01719 100644 (file)
@@ -768,16 +768,14 @@ PHPDBG_API char *phpdbg_read_input(char *buffered) /* {{{ */
 
        if (buffer && strlen(buffer)) {
                if (PHPDBG_G(buffer)) {
-                       efree(PHPDBG_G(buffer));
+                       free(PHPDBG_G(buffer));
                }
-               PHPDBG_G(buffer) = estrdup(buffer);
-       } else {
-               if (PHPDBG_G(buffer)) {
-                       if (buffer) {
-                               efree(buffer);
-                       }
-                       buffer = estrdup(PHPDBG_G(buffer));
+               PHPDBG_G(buffer) = strdup(buffer);
+       } else if (PHPDBG_G(buffer)) {
+               if (buffer) {
+                       efree(buffer);
                }
+               buffer = estrdup(PHPDBG_G(buffer));
        }
 
        return buffer;
index 2001129ec8021950ffcdda298648a51ab5863057..5d5ed2822a088fd7282a15d9808a7cd67a575e53 100644 (file)
@@ -1628,7 +1628,13 @@ void phpdbg_force_interruption(void) /* {{{ */ {
 
        if (data) {
                if (data->func) {
-                       phpdbg_notice("hardinterrupt", "opline=\"%p\" num=\"%lu\" file=\"%s\" line=\"%u\"", "Current opline: %p (op #%lu) in %s:%u", data->opline, (data->opline - data->func->op_array.opcodes) / sizeof(data->opline), data->func->op_array.filename, data->opline->lineno);
+                       if (ZEND_USER_CODE(data->func->type)) {
+                               phpdbg_notice("hardinterrupt", "opline=\"%p\" num=\"%lu\" file=\"%s\" line=\"%u\"", "Current opline: %p (op #%lu) in %s:%u", data->opline, (data->opline - data->func->op_array.opcodes) / sizeof(data->opline), data->func->op_array.filename, data->opline->lineno);
+                       } else if (data->func->internal_function.function_name) {
+                               phpdbg_notice("hardinterrupt", "func=\"%s\"", "Current opline: in internal function %s", data->func->internal_function.function_name->val);
+                       } else {
+                               phpdbg_notice("hardinterrupt", "", "Current opline: executing internal code");
+                       }
                } else {
                        phpdbg_notice("hardinterrupt", "opline=\"%p\"", "Current opline: %p (op_array information unavailable)", data->opline);
                }
index 82cb7aba015fdd005141c96987f52cb560bb4d87..54af08ec5b9d553f3ae64245bcf2ad326ef5b3cb 100644 (file)
@@ -8,9 +8,9 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
 
 static void* zend_mm_mem_alloc(zend_mm_storage *storage, size_t size, size_t alignment) {
 
-       if (EXPECTED(size == PHPDBG_SIGSAFE_MEM_SIZE && !PHPDBG_G(sigsafe_mem).allocated)) {
+       if (EXPECTED(size <= PHPDBG_SIGSAFE_MEM_SIZE && !PHPDBG_G(sigsafe_mem).allocated)) {
                PHPDBG_G(sigsafe_mem).allocated = 1;
-               return PHPDBG_G(sigsafe_mem).mem;
+               return (void *) (((size_t) PHPDBG_G(sigsafe_mem).mem & ~(alignment - 1)) + alignment);
        }
 
        quiet_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"));
index e27b12c76cada525618c3b6eddfdc747c6640066..ab689a38d8c26e1968d457afc64c7272e5a59ea4 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef PHPDBG_SIGSAFE_H
 #define PHPDBG_SIGSAFE_H
 
-#define PHPDBG_SIGSAFE_MEM_SIZE ZEND_MM_CHUNK_SIZE // (1 << 20)
+#define PHPDBG_SIGSAFE_MEM_SIZE (ZEND_MM_CHUNK_SIZE * 2)
 
 #include "zend.h"