Skip to content

Commit 8c9f4b6

Browse files
committed
Remove unused code disabled by define APC_MEMPROTECT
1 parent 426ac32 commit 8c9f4b6

File tree

4 files changed

+0
-108
lines changed

4 files changed

+0
-108
lines changed

apc_mmap.c

-24
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ apc_segment_t apc_mmap(char *file_mask, size_t size)
5757

5858
int fd = -1;
5959
int flags = MAP_SHARED | MAP_NOSYNC;
60-
#ifdef APC_MEMPROTECT
61-
int remap = 1;
62-
#endif
6360

6461
/* If no filename was provided, do an anonymous mmap */
6562
if(!file_mask || (file_mask && !strlen(file_mask))) {
@@ -68,18 +65,12 @@ apc_segment_t apc_mmap(char *file_mask, size_t size)
6865
#else
6966
fd = -1;
7067
flags = MAP_SHARED | MAP_ANON;
71-
#ifdef APC_MEMPROTECT
72-
remap = 0;
73-
#endif
7468
#endif
7569
} else if(!strcmp(file_mask,"/dev/zero")) {
7670
fd = open("/dev/zero", O_RDWR, S_IRUSR | S_IWUSR);
7771
if(fd == -1) {
7872
zend_error_noreturn(E_CORE_ERROR, "apc_mmap: open on /dev/zero failed");
7973
}
80-
#ifdef APC_MEMPROTECT
81-
remap = 0; /* cannot remap */
82-
#endif
8374
} else {
8475
/*
8576
* Otherwise we do a normal filesystem mmap
@@ -99,14 +90,6 @@ apc_segment_t apc_mmap(char *file_mask, size_t size)
9990
segment.shmaddr = (void *)mmap(NULL, size, PROT_READ | PROT_WRITE, flags, fd, 0);
10091
segment.size = size;
10192

102-
#ifdef APC_MEMPROTECT
103-
if(remap) {
104-
segment.roaddr = (void *)mmap(NULL, size, PROT_READ, flags, fd, 0);
105-
} else {
106-
segment.roaddr = NULL;
107-
}
108-
#endif
109-
11093
if ((long)segment.shmaddr == -1) {
11194
zend_error_noreturn(E_CORE_ERROR, "apc_mmap: Failed to mmap %zu bytes. Is your apc.shm_size too large?", size);
11295
}
@@ -127,13 +110,6 @@ void apc_unmap(apc_segment_t *segment)
127110
if (munmap(segment->shmaddr, segment->size) < 0) {
128111
apc_warning("apc_unmap: munmap failed");
129112
}
130-
131-
#ifdef APC_MEMPROTECT
132-
if (segment->roaddr && munmap(segment->roaddr, segment->size) < 0) {
133-
apc_warning("apc_unmap: munmap failed");
134-
}
135-
#endif
136-
137113
}
138114

139115
#endif

apc_shm.c

-14
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@ apc_segment_t apc_shm_attach(int shmid, size_t size)
7373
zend_error_noreturn(E_CORE_ERROR, "apc_shm_attach: shmat failed:");
7474
}
7575

76-
#ifdef APC_MEMPROTECT
77-
78-
if ((zend_long)(segment.roaddr = shmat(shmid, 0, SHM_RDONLY)) == -1) {
79-
segment.roaddr = NULL;
80-
}
81-
82-
#endif
83-
8476
segment.size = size;
8577

8678
/*
@@ -96,12 +88,6 @@ void apc_shm_detach(apc_segment_t* segment)
9688
if (shmdt(segment->shmaddr) < 0) {
9789
apc_warning("apc_shm_detach: shmdt failed:");
9890
}
99-
100-
#ifdef APC_MEMPROTECT
101-
if (segment->roaddr && shmdt(segment->roaddr) < 0) {
102-
apc_warning("apc_shm_detach: shmdt failed:");
103-
}
104-
#endif
10591
}
10692

10793
/*

apc_sma.c

-57
Original file line numberDiff line numberDiff line change
@@ -492,63 +492,6 @@ PHP_APCU_API void apc_sma_free(apc_sma_t* sma, void* p) {
492492
apc_error("apc_sma_free: could not locate address %p", p);
493493
}
494494

495-
#ifdef APC_MEMPROTECT
496-
PHP_APCU_API void* apc_sma_protect(apc_sma_t* sma, void* p) {
497-
unsigned int i = 0;
498-
size_t offset;
499-
500-
if (p == NULL) {
501-
return NULL;
502-
}
503-
504-
if(SMA_RO(sma, sma->last) == NULL) return p;
505-
506-
offset = (size_t)((char *)p - SMA_ADDR(sma, sma->last));
507-
508-
if(p >= (void*)SMA_ADDR(sma, sma->last) && offset < sma->size) {
509-
return SMA_RO(sma, sma->last) + offset;
510-
}
511-
512-
for (i = 0; i < sma->num; i++) {
513-
offset = (size_t)((char *)p - SMA_ADDR(sma, i));
514-
if (p >= (void*)SMA_ADDR(sma, i) && offset < sma->size) {
515-
return SMA_RO(sma, i) + offset;
516-
}
517-
}
518-
519-
return NULL;
520-
}
521-
522-
PHP_APCU_API void* apc_sma_unprotect(apc_sma_t* sma, void* p){
523-
unsigned int i = 0;
524-
size_t offset;
525-
526-
if (p == NULL) {
527-
return NULL;
528-
}
529-
530-
if(SMA_RO(sma, sma->last) == NULL) return p;
531-
532-
offset = (size_t)((char *)p - SMA_RO(sma, sma->last));
533-
534-
if(p >= (void*)SMA_RO(sma, sma->last) && offset < sma->size) {
535-
return SMA_ADDR(sma, sma->last) + offset;
536-
}
537-
538-
for (i = 0; i < sma->num; i++) {
539-
offset = (size_t)((char *)p - SMA_RO(sma, i));
540-
if (p >= (void*)SMA_RO(sma, i) && offset < sma->size) {
541-
return SMA_ADDR(sma, i) + offset;
542-
}
543-
}
544-
545-
return NULL;
546-
}
547-
#else
548-
PHP_APCU_API void* apc_sma_protect(apc_sma_t* sma, void *p) { return p; }
549-
PHP_APCU_API void* apc_sma_unprotect(apc_sma_t* sma, void *p) { return p; }
550-
#endif
551-
552495
PHP_APCU_API apc_sma_info_t *apc_sma_info(apc_sma_t* sma, zend_bool limited) {
553496
apc_sma_info_t *info;
554497
apc_sma_link_t **link;

apc_sma.h

-13
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939
typedef struct _apc_segment_t {
4040
size_t size; /* size of this segment */
4141
void* shmaddr; /* address of shared memory */
42-
#ifdef APC_MEMPROTECT
43-
void* roaddr; /* read only (mprotect'd) address */
44-
#endif
4542
} apc_segment_t; /* }}} */
4643

4744
/* {{{ struct definition: apc_sma_link_t */
@@ -113,16 +110,6 @@ PHP_APCU_API void *apc_sma_malloc_ex(
113110
*/
114111
PHP_APCU_API void apc_sma_free(apc_sma_t* sma, void* p);
115112

116-
/*
117-
* apc_sma_api_protect will protect p (which should be a pointer to a block allocated from sma)
118-
*/
119-
PHP_APCU_API void* apc_sma_protect(apc_sma_t* sma, void* p);
120-
121-
/*
122-
* apc_sma_api_protect will uprotect p (which should be a pointer to a block allocated from sma)
123-
*/
124-
PHP_APCU_API void* apc_sma_unprotect(apc_sma_t* sma, void *p);
125-
126113
/*
127114
* apc_sma_api_info returns information about the allocator
128115
*/

0 commit comments

Comments
 (0)