com php-src: Fix issues with phpdbg SIGINT handler Also fix valgrind warnings in allocator when not using mmap()ed memory: Zend/zend_alloc.c
sapi/phpdbg/phpdbg.c sapi/phpdbg/ph pdbg_cmd.c sapi/phpdbg/phpdbg_prompt.c sapi/phpdbg/ phpdbg_sigsafe.c sapi/phpdbg/phpdbg_sigsafe.h
| From: | Bob Weinand | Date: | Fri, 21 Aug 2015 22:36:31 +0000 |
| Subject: | com php-src: Fix issues with phpdbg SIGINT handler Also fix valgrind warnings in allocator when not using mmap()ed memory: Zend/zend_alloc.c sapi/phpdbg/phpdbg.c sapi/phpdbg/ph pdbg_cmd.c sapi/phpdbg/phpdbg_prompt.c sapi/phpdbg/ phpdbg_sigsafe.c sapi/phpdbg/phpdbg_sigsafe.h |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-88724@lists.php.net to get a copy of this message | ||
Commit: 76e3e99dd674fe98130ba110564c607b12a7772c
Author: Bob Weinand <bobwei9@hotmail.com> Fri, 21 Aug 2015 23:36:31 +0100
Parents: f9ae74a4c05584983add5ab68042419d44032b1b
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=76e3e99dd674fe98130ba110564c607b12a7772c
Log:
Fix issues with phpdbg SIGINT handler
Also fix valgrind warnings in allocator when not using mmap()ed memory
Changed paths:
M Zend/zend_alloc.c
M sapi/phpdbg/phpdbg.c
M sapi/phpdbg/phpdbg_cmd.c
M sapi/phpdbg/phpdbg_prompt.c
M sapi/phpdbg/phpdbg_sigsafe.c
M sapi/phpdbg/phpdbg_sigsafe.h
Diff:
diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c
index 493cf1f..16838e0 100644
--- a/Zend/zend_alloc.c
+++ b/Zend/zend_alloc.c
@@ -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);
diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c
index 831d4fc..4c5dfde 100644
--- a/sapi/phpdbg/phpdbg.c
+++ b/sapi/phpdbg/phpdbg.c
@@ -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;
diff --git a/sapi/phpdbg/phpdbg_cmd.c b/sapi/phpdbg/phpdbg_cmd.c
index a50b340..ed4cf3b 100644
--- a/sapi/phpdbg/phpdbg_cmd.c
+++ b/sapi/phpdbg/phpdbg_cmd.c
@@ -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;
diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c
index 2001129..5d5ed28 100644
--- a/sapi/phpdbg/phpdbg_prompt.c
+++ b/sapi/phpdbg/phpdbg_prompt.c
@@ -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);
}
diff --git a/sapi/phpdbg/phpdbg_sigsafe.c b/sapi/phpdbg/phpdbg_sigsafe.c
index 82cb7ab..54af08e 100644
--- a/sapi/phpdbg/phpdbg_sigsafe.c
+++ b/sapi/phpdbg/phpdbg_sigsafe.c
@@ -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"));
diff --git a/sapi/phpdbg/phpdbg_sigsafe.h b/sapi/phpdbg/phpdbg_sigsafe.h
index e27b12c..ab689a3 100644
--- a/sapi/phpdbg/phpdbg_sigsafe.h
+++ b/sapi/phpdbg/phpdbg_sigsafe.h
@@ -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"