Skip to content

Commit cfb272d

Browse files
committed
Add zend_accel_error_noreturn() helper
Avoid confusing the compiler when code relies on the fact that LOG_FATAL/LOG_ERROR will bailout/abort.
1 parent 9426c6e commit cfb272d

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

ext/opcache/ZendAccelerator.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ static inline void kill_all_lockers(struct flock *mem_usage_check)
802802
/* errno is not ESRCH or we ran out of tries to kill the locker */
803803
ZCSG(force_restart_time) = time(NULL); /* restore forced restart request */
804804
/* cannot kill the locker, bail out with error */
805-
zend_accel_error(ACCEL_LOG_ERROR, "Cannot kill process %d!", mem_usage_check->l_pid);
805+
zend_accel_error_noreturn(ACCEL_LOG_ERROR, "Cannot kill process %d!", mem_usage_check->l_pid);
806806
}
807807

808808
mem_usage_check->l_type = F_WRLCK;
@@ -2637,7 +2637,7 @@ static int zend_accel_init_shm(void)
26372637
accel_shared_globals = zend_shared_alloc(sizeof(zend_accel_shared_globals));
26382638
}
26392639
if (!accel_shared_globals) {
2640-
zend_accel_error(ACCEL_LOG_FATAL, "Insufficient shared memory!");
2640+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Insufficient shared memory!");
26412641
zend_shared_alloc_unlock();
26422642
return FAILURE;
26432643
}
@@ -2977,7 +2977,7 @@ static zend_result accel_post_startup(void)
29772977
page_size = getpagesize();
29782978
# endif
29792979
if (!page_size || (page_size & (page_size - 1))) {
2980-
zend_accel_error(ACCEL_LOG_FATAL, "Failure to initialize shared memory structures - can't get page size.");
2980+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Failure to initialize shared memory structures - can't get page size.");
29812981
abort();
29822982
}
29832983
jit_size = JIT_G(buffer_size);
@@ -2997,7 +2997,7 @@ static zend_result accel_post_startup(void)
29972997
break;
29982998
case ALLOC_FAILURE:
29992999
accel_startup_ok = 0;
3000-
zend_accel_error(ACCEL_LOG_FATAL, "Failure to initialize shared memory structures - probably not enough shared memory.");
3000+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Failure to initialize shared memory structures - probably not enough shared memory.");
30013001
return SUCCESS;
30023002
case SUCCESSFULLY_REATTACHED:
30033003
#if defined(HAVE_JIT) && !defined(ZEND_WIN32)
@@ -3010,7 +3010,7 @@ static zend_result accel_post_startup(void)
30103010
break;
30113011
case FAILED_REATTACHED:
30123012
accel_startup_ok = 0;
3013-
zend_accel_error(ACCEL_LOG_FATAL, "Failure to initialize shared memory structures - can not reattach to exiting shared memory.");
3013+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Failure to initialize shared memory structures - can not reattach to exiting shared memory.");
30143014
return SUCCESS;
30153015
break;
30163016
#if ENABLE_FILE_CACHE_FALLBACK
@@ -3050,7 +3050,7 @@ static zend_result accel_post_startup(void)
30503050
SHM_PROTECT();
30513051
} else if (!ZCG(accel_directives).file_cache) {
30523052
accel_startup_ok = 0;
3053-
zend_accel_error(ACCEL_LOG_FATAL, "opcache.file_cache_only is set without a proper setting of opcache.file_cache");
3053+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "opcache.file_cache_only is set without a proper setting of opcache.file_cache");
30543054
return SUCCESS;
30553055
} else {
30563056
accel_shared_globals = calloc(1, sizeof(zend_accel_shared_globals));
@@ -4213,7 +4213,7 @@ static zend_persistent_script* preload_script_in_shared_memory(zend_persistent_s
42134213
uint32_t checkpoint;
42144214

42154215
if (zend_accel_hash_is_full(&ZCSG(hash))) {
4216-
zend_accel_error(ACCEL_LOG_FATAL, "Not enough entries in hash table for preloading. Consider increasing the value for the opcache.max_accelerated_files directive in php.ini.");
4216+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Not enough entries in hash table for preloading. Consider increasing the value for the opcache.max_accelerated_files directive in php.ini.");
42174217
return NULL;
42184218
}
42194219

@@ -4265,7 +4265,7 @@ static zend_persistent_script* preload_script_in_shared_memory(zend_persistent_s
42654265
}
42664266
#endif
42674267
if (!ZCG(mem)) {
4268-
zend_accel_error(ACCEL_LOG_FATAL, "Not enough shared memory for preloading. Consider increasing the value for the opcache.memory_consumption directive in php.ini.");
4268+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Not enough shared memory for preloading. Consider increasing the value for the opcache.memory_consumption directive in php.ini.");
42694269
return NULL;
42704270
}
42714271

@@ -4583,7 +4583,7 @@ static int accel_preload(const char *config, zend_bool in_child)
45834583
CG(map_ptr_last) = orig_map_ptr_last;
45844584

45854585
if (EG(full_tables_cleanup)) {
4586-
zend_accel_error(ACCEL_LOG_FATAL, "Preloading is not compatible with dl() function.");
4586+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Preloading is not compatible with dl() function.");
45874587
ret = FAILURE;
45884588
goto finish;
45894589
}
@@ -4666,7 +4666,7 @@ static int accel_preload(const char *config, zend_bool in_child)
46664666
zend_hash_sort_ex(&script->script.class_table, preload_sort_classes, NULL, 0);
46674667

46684668
if (preload_optimize(script) != SUCCESS) {
4669-
zend_accel_error(ACCEL_LOG_FATAL, "Optimization error during preloading!");
4669+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Optimization error during preloading!");
46704670
return FAILURE;
46714671
}
46724672

@@ -4765,7 +4765,7 @@ static int accel_finish_startup(void)
47654765

47664766
if (ZCG(accel_directives).preload && *ZCG(accel_directives).preload) {
47674767
#ifdef ZEND_WIN32
4768-
zend_accel_error(ACCEL_LOG_ERROR, "Preloading is not supported on Windows");
4768+
zend_accel_error_noreturn(ACCEL_LOG_ERROR, "Preloading is not supported on Windows");
47694769
return FAILURE;
47704770
#else
47714771
int in_child = 0;
@@ -4808,21 +4808,21 @@ static int accel_finish_startup(void)
48084808
if (!ZCG(accel_directives).preload_user
48094809
|| !*ZCG(accel_directives).preload_user) {
48104810
zend_shared_alloc_unlock();
4811-
zend_accel_error(ACCEL_LOG_FATAL, "\"opcache.preload_user\" has not been defined");
4811+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "\"opcache.preload_user\" has not been defined");
48124812
return FAILURE;
48134813
}
48144814

48154815
pw = getpwnam(ZCG(accel_directives).preload_user);
48164816
if (pw == NULL) {
48174817
zend_shared_alloc_unlock();
4818-
zend_accel_error(ACCEL_LOG_FATAL, "Preloading failed to getpwnam(\"%s\")", ZCG(accel_directives).preload_user);
4818+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Preloading failed to getpwnam(\"%s\")", ZCG(accel_directives).preload_user);
48194819
return FAILURE;
48204820
}
48214821

48224822
pid = fork();
48234823
if (pid == -1) {
48244824
zend_shared_alloc_unlock();
4825-
zend_accel_error(ACCEL_LOG_FATAL, "Preloading failed to fork()");
4825+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Preloading failed to fork()");
48264826
return FAILURE;
48274827
} else if (pid == 0) { /* children */
48284828
if (setgid(pw->pw_gid) < 0) {
@@ -4843,7 +4843,7 @@ static int accel_finish_startup(void)
48434843

48444844
if (waitpid(pid, &status, 0) < 0) {
48454845
zend_shared_alloc_unlock();
4846-
zend_accel_error(ACCEL_LOG_FATAL, "Preloading failed to waitpid(%d)", pid);
4846+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Preloading failed to waitpid(%d)", pid);
48474847
return FAILURE;
48484848
}
48494849

ext/opcache/zend_accelerator_debug.c

+20-4
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828
#endif
2929
#include "ZendAccelerator.h"
3030

31-
void zend_accel_error(int type, const char *format, ...)
31+
static void zend_accel_error_va_args(int type, const char *format, va_list args)
3232
{
33-
va_list args;
3433
time_t timestamp;
3534
char *time_string;
3635
FILE * fLog = NULL;
@@ -77,9 +76,7 @@ void zend_accel_error(int type, const char *format, ...)
7776
break;
7877
}
7978

80-
va_start(args, format);
8179
vfprintf(fLog, format, args);
82-
va_end(args);
8380
fprintf(fLog, "\n");
8481

8582
fflush(fLog);
@@ -98,3 +95,22 @@ void zend_accel_error(int type, const char *format, ...)
9895
}
9996

10097
}
98+
99+
void zend_accel_error(int type, const char *format, ...)
100+
{
101+
va_list args;
102+
va_start(args, format);
103+
zend_accel_error_va_args(type, format, args);
104+
va_end(args);
105+
}
106+
107+
ZEND_NORETURN void zend_accel_error_noreturn(int type, const char *format, ...)
108+
{
109+
va_list args;
110+
va_start(args, format);
111+
ZEND_ASSERT(type == ACCEL_LOG_FATAL || type == ACCEL_LOG_ERROR);
112+
zend_accel_error_va_args(type, format, args);
113+
va_end(args);
114+
/* Should never reach this. */
115+
abort();
116+
}

ext/opcache/zend_accelerator_debug.h

+1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@
2929
#define ACCEL_LOG_DEBUG 4
3030

3131
void zend_accel_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
32+
ZEND_NORETURN void zend_accel_error_noreturn(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
3233

3334
#endif /* _ZEND_ACCELERATOR_DEBUG_H */

0 commit comments

Comments
 (0)