Fix issues with phpdbg SIGINT handler

Also fix valgrind warnings in allocator when not using mmap()ed memory
This commit is contained in:
Bob Weinand 2015-08-21 23:36:31 +01:00
parent f9ae74a4c0
commit 76e3e99dd6
6 changed files with 38 additions and 25 deletions

View 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);

View 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];
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;
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;

View 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;

View 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);
}

View 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"));

View 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"