php-internal-docs
8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
fpm_shm.c
Go to the documentation of this file.
1
/* (c) 2007,2008 Andrei Nigmatulin, Jerome Loyet */
2
3
#include <sys/mman.h>
4
#include <errno.h>
5
#include <string.h>
6
7
#include "
fpm_shm.h
"
8
#include "
zlog.h
"
9
10
11
/* MAP_ANON is deprecated, but not in macOS */
12
#if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
13
#define MAP_ANONYMOUS MAP_ANON
14
#endif
15
16
static
size_t
fpm_shm_size = 0;
17
18
void
*
fpm_shm_alloc
(
size_t
size
)
/* {{{ */
19
{
20
void
*mem;
21
22
mem = mmap(0,
size
,
PROT_READ
|
PROT_WRITE
, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
23
24
#ifdef MAP_FAILED
25
if
(mem ==
MAP_FAILED
) {
26
zlog
(
ZLOG_SYSERROR
,
"unable to allocate %zu bytes in shared memory: %s"
,
size
, strerror(
errno
));
27
return
NULL
;
28
}
29
#endif
30
31
if
(!mem) {
32
zlog
(
ZLOG_SYSERROR
,
"unable to allocate %zu bytes in shared memory"
,
size
);
33
return
NULL
;
34
}
35
36
fpm_shm_size +=
size
;
37
return
mem;
38
}
39
/* }}} */
40
41
int
fpm_shm_free
(
void
*mem,
size_t
size
)
/* {{{ */
42
{
43
if
(!mem) {
44
zlog
(
ZLOG_ERROR
,
"mem is NULL"
);
45
return
0;
46
}
47
48
if
(munmap(mem,
size
) == -1) {
49
zlog
(
ZLOG_SYSERROR
,
"Unable to free shm"
);
50
return
0;
51
}
52
53
if
(fpm_shm_size >
size
) {
54
fpm_shm_size -=
size
;
55
}
else
{
56
fpm_shm_size = 0;
57
}
58
59
return
1;
60
}
61
/* }}} */
62
63
size_t
fpm_shm_get_size_allocated
(
void
)
64
{
65
return
fpm_shm_size;
66
}
size
new_type size
Definition
ffi.c:4365
fpm_shm_get_size_allocated
size_t fpm_shm_get_size_allocated(void)
Definition
fpm_shm.c:63
fpm_shm_free
int fpm_shm_free(void *mem, size_t size)
Definition
fpm_shm.c:41
fpm_shm_alloc
void * fpm_shm_alloc(size_t size)
Definition
fpm_shm.c:18
fpm_shm.h
NULL
#define NULL
Definition
gdcache.h:45
PROT_READ
#define PROT_READ
Definition
phpdbg_win.h:26
PROT_WRITE
#define PROT_WRITE
Definition
phpdbg_win.h:27
errno
#define errno
Definition
windows_common.h:29
MAP_FAILED
#define MAP_FAILED
Definition
zend_alloc.c:98
zlog.h
ZLOG_SYSERROR
#define ZLOG_SYSERROR
Definition
zlog.h:53
ZLOG_ERROR
@ ZLOG_ERROR
Definition
zlog.h:45
zlog
#define zlog(flags,...)
Definition
zlog.h:9
sapi
fpm
fpm
fpm_shm.c
Generated on Sat Aug 23 2025 01:46:13 for php-internal-docs by
1.13.2