-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathzend_shared_alloc.c
105 lines (93 loc) · 3.2 KB
/
zend_shared_alloc.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
+----------------------------------------------------------------------+
| Zend BCgen |
+----------------------------------------------------------------------+
| Copyright (c) 1998-2018 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Andi Gutmans <[email protected]> |
| Zeev Suraski <[email protected]> |
| Stanislav Malyshev <[email protected]> |
| Dmitry Stogov <[email protected]> |
+----------------------------------------------------------------------+
*/
#include <errno.h>
#include "ZendAccelerator.h"
#include "zend_shared_alloc.h"
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <fcntl.h>
#ifndef ZEND_WIN32
# include <sys/types.h>
# include <dirent.h>
# include <signal.h>
# include <sys/stat.h>
# include <stdio.h>
#endif
#ifndef ZEND_WIN32
#ifdef ZTS
static MUTEX_T zts_lock;
#endif
int lock_file;
static char lockfile_name[MAXPATHLEN];
#endif
int zend_shared_memdup_size(void *source, size_t size)
{
void *old_p;
if ((old_p = zend_hash_index_find_ptr(&ZCG(xlat_table), (zend_ulong)source)) != NULL) {
/* we already duplicated this pointer */
return 0;
}
zend_shared_alloc_register_xlat_entry(source, source);
return ZEND_ALIGNED_SIZE(size);
}
void *_zend_shared_memdup(void *source, size_t size, zend_bool free_source)
{
void *old_p, *retval;
if ((old_p = zend_hash_index_find_ptr(&ZCG(xlat_table), (zend_ulong)source)) != NULL) {
/* we already duplicated this pointer */
return old_p;
}
retval = ZCG(mem);
ZCG(mem) = (void*)(((char*)ZCG(mem)) + ZEND_ALIGNED_SIZE(size));
memcpy(retval, source, size);
zend_shared_alloc_register_xlat_entry(source, retval);
if (free_source) {
efree(source);
}
return retval;
}
void zend_shared_alloc_init_xlat_table(void)
{
/* Prepare translation table */
zend_hash_init(&ZCG(xlat_table), 128, NULL, NULL, 0);
}
void zend_shared_alloc_destroy_xlat_table(void)
{
/* Destroy translation table */
zend_hash_destroy(&ZCG(xlat_table));
}
void zend_shared_alloc_clear_xlat_table(void)
{
zend_hash_clean(&ZCG(xlat_table));
}
void zend_shared_alloc_register_xlat_entry(const void *old, const void *new)
{
zend_hash_index_add_new_ptr(&ZCG(xlat_table), (zend_ulong)old, (void*)new);
}
void *zend_shared_alloc_get_xlat_entry(const void *old)
{
void *retval;
if ((retval = zend_hash_index_find_ptr(&ZCG(xlat_table), (zend_ulong)old)) == NULL) {
return NULL;
}
return retval;
}