forked from php/php-src
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphpdbg_sigsafe.c
58 lines (42 loc) · 1.56 KB
/
phpdbg_sigsafe.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include"phpdbg_sigsafe.h"
#include"phpdbg.h"
ZEND_EXTERN_MODULE_GLOBALS(phpdbg)
#defineSTR(x) #x
#defineEXP_STR(x) STR(x)
staticvoid*zend_mm_mem_alloc(zend_mm_storage*storage, size_tsize, size_talignment) {
if (EXPECTED(size <= PHPDBG_SIGSAFE_MEM_SIZE&& !PHPDBG_G(sigsafe_mem).allocated)) {
PHPDBG_G(sigsafe_mem).allocated=1;
return (void*) (((size_t) PHPDBG_G(sigsafe_mem).mem& ~(alignment-1)) +alignment);
}
zend_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"));
if (*EG(bailout)) {
LONGJMP(*EG(bailout), FAILURE);
}
zend_quiet_write(PHPDBG_G(io)[PHPDBG_STDERR].fd, ZEND_STRL("Bailed out without a bailout address in signal handler!\n"));
returnNULL;
}
staticvoidzend_mm_mem_free(zend_mm_storage*storage, void*ptr, size_tsize) {
}
voidphpdbg_set_sigsafe_mem(char*buffer) {
phpdbg_signal_safe_mem*mem=&PHPDBG_G(sigsafe_mem);
constzend_mm_handlersphpdbg_handlers= {
zend_mm_mem_alloc,
zend_mm_mem_free,
NULL,
NULL,
};
mem->mem=buffer;
mem->allocated=0;
mem->heap=zend_mm_startup_ex(&phpdbg_handlers, NULL, 0);
mem->old_heap=zend_mm_set_heap(mem->heap);
}
zend_mm_heap*phpdbg_original_heap_sigsafe_mem(void) {
returnPHPDBG_G(sigsafe_mem).old_heap;
}
voidphpdbg_clear_sigsafe_mem(void) {
zend_mm_set_heap(phpdbg_original_heap_sigsafe_mem());
PHPDBG_G(sigsafe_mem).mem=NULL;
}
boolphpdbg_active_sigsafe_mem(void) {
return !!PHPDBG_G(sigsafe_mem).mem;
}