Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ PHP 8.7 INTERNALS UPGRADE NOTES
freed with zend_hash_destroy() + pefree().
- The ZTS symbols compiler_globals_offset and executor_globals_offset have been
removed: CG()/EG() now reach the globals through a __thread struct.
- PG(), SG(), CWDG(), SIGG(), ZCG(), JIT_G() and INI_SCNG() use native TLS.
The core_globals_offset, sapi_globals_offset, cwd_globals_offset,
zend_signal_globals_offset, accel_globals_offset, jit_globals_offset and
ini_scanner_globals_offset symbols have been removed.
- php_reserve_tsrm_memory() has been removed.
Comment on lines 54 to +60

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the conventions here, could I just amend the initial upgrading entry?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

- Removed zend_error_noreturn_unchecked().

========================
Expand Down
3 changes: 2 additions & 1 deletion Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ ZEND_TLS_API TSRM_TLS TSRM_TLS_MODEL_ATTR zend_tsrm_ls_cache _tsrm_ls_cache = {0
static void *executor_globals_tls_addr(void) { return &_tsrm_ls_cache.eg; }
static void *compiler_globals_tls_addr(void) { return &_tsrm_ls_cache.cg; }
static void *language_scanner_globals_tls_addr(void) { return &language_scanner_globals; }
static void *ini_scanner_globals_tls_addr(void) { return &ini_scanner_globals; }
static HashTable *global_function_table = NULL;
static HashTable *global_class_table = NULL;
static HashTable *global_constants_table = NULL;
Expand Down Expand Up @@ -1034,7 +1035,7 @@ void zend_startup(zend_utility_functions *utility_functions) /* {{{ */
ts_allocate_tls_id(&compiler_globals_id, compiler_globals_tls_addr, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor);
ts_allocate_tls_id(&executor_globals_id, executor_globals_tls_addr, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor);
ts_allocate_tls_id(&language_scanner_globals_id, language_scanner_globals_tls_addr, sizeof(zend_php_scanner_globals), (ts_allocate_ctor) php_scanner_globals_ctor, NULL);
ts_allocate_fast_id(&ini_scanner_globals_id, &ini_scanner_globals_offset, sizeof(zend_ini_scanner_globals), (ts_allocate_ctor) ini_scanner_globals_ctor, NULL);
ts_allocate_tls_id(&ini_scanner_globals_id, ini_scanner_globals_tls_addr, sizeof(zend_ini_scanner_globals), (ts_allocate_ctor) ini_scanner_globals_ctor, NULL);
compiler_globals = ts_resource(compiler_globals_id);
executor_globals = ts_resource(executor_globals_id);

Expand Down
8 changes: 6 additions & 2 deletions Zend/zend_globals_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ extern ZEND_API zend_php_scanner_globals language_scanner_globals;

/* INI Scanner */
#ifdef ZTS
# define INI_SCNG(v) ZEND_TSRMG_FAST(ini_scanner_globals_offset, zend_ini_scanner_globals *, v)
extern ZEND_API ts_rsrc_id ini_scanner_globals_id;
extern ZEND_API size_t ini_scanner_globals_offset;
# ifdef ZEND_TLS_DIRECT
extern ZEND_TLS_API TSRM_TLS TSRM_TLS_MODEL_ATTR zend_ini_scanner_globals ini_scanner_globals;
# define INI_SCNG(v) (ini_scanner_globals.v)
# else
# define INI_SCNG(v) ZEND_TSRMG(ini_scanner_globals_id, zend_ini_scanner_globals *, v)
# endif
#else
# define INI_SCNG(v) (ini_scanner_globals.v)
extern ZEND_API zend_ini_scanner_globals ini_scanner_globals;
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_ini_scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
#define SCNG INI_SCNG
#ifdef ZTS
ZEND_API ts_rsrc_id ini_scanner_globals_id;
ZEND_API size_t ini_scanner_globals_offset;
ZEND_TLS_API TSRM_TLS TSRM_TLS_MODEL_ATTR zend_ini_scanner_globals ini_scanner_globals;
#else
ZEND_API zend_ini_scanner_globals ini_scanner_globals;
#endif
Expand Down
5 changes: 3 additions & 2 deletions Zend/zend_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@

#ifdef ZTS
ZEND_API int zend_signal_globals_id;
ZEND_API size_t zend_signal_globals_offset;
ZEND_TLS_API TSRM_TLS TSRM_TLS_MODEL_ATTR zend_signal_globals_t zend_signal_globals;
static void *zend_signal_globals_tls_addr(void) { return &zend_signal_globals; }
#else
ZEND_API zend_signal_globals_t zend_signal_globals;
#endif /* not ZTS */
Expand Down Expand Up @@ -412,7 +413,7 @@ ZEND_API void zend_signal_startup(void)
{

#ifdef ZTS
ts_allocate_fast_id(&zend_signal_globals_id, &zend_signal_globals_offset, sizeof(zend_signal_globals_t), (ts_allocate_ctor) zend_signal_globals_ctor, NULL);
ts_allocate_tls_id(&zend_signal_globals_id, zend_signal_globals_tls_addr, sizeof(zend_signal_globals_t), (ts_allocate_ctor) zend_signal_globals_ctor, NULL);
#else
zend_signal_globals_ctor(&zend_signal_globals);
#endif
Expand Down
8 changes: 6 additions & 2 deletions Zend/zend_signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ typedef struct _zend_signal_globals_t {
} zend_signal_globals_t;

# ifdef ZTS
# define SIGG(v) ZEND_TSRMG_FAST(zend_signal_globals_offset, zend_signal_globals_t *, v)
BEGIN_EXTERN_C()
ZEND_API extern int zend_signal_globals_id;
ZEND_API extern size_t zend_signal_globals_offset;
# ifdef ZEND_TLS_DIRECT
# define SIGG(v) (zend_signal_globals.v)
extern ZEND_TLS_API TSRM_TLS TSRM_TLS_MODEL_ATTR zend_signal_globals_t zend_signal_globals;
# else
# define SIGG(v) ZEND_TSRMG(zend_signal_globals_id, zend_signal_globals_t *, v)
# endif
END_EXTERN_C()
# else
# define SIGG(v) (zend_signal_globals.v)
Expand Down
7 changes: 4 additions & 3 deletions Zend/zend_virtual_cwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ MUTEX_T cwd_mutex;
#endif

#ifdef ZTS
ts_rsrc_id cwd_globals_id;
size_t cwd_globals_offset;
CWD_API ts_rsrc_id cwd_globals_id;
ZEND_TLS_API TSRM_TLS TSRM_TLS_MODEL_ATTR virtual_cwd_globals cwd_globals;
static void *cwd_globals_tls_addr(void) { return &cwd_globals; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto (not API)

#else
virtual_cwd_globals cwd_globals;
#endif
Expand Down Expand Up @@ -204,7 +205,7 @@ CWD_API void virtual_cwd_startup(void) /* {{{ */
{
virtual_cwd_main_cwd_init(0);
#ifdef ZTS
ts_allocate_fast_id(&cwd_globals_id, &cwd_globals_offset, sizeof(virtual_cwd_globals), (ts_allocate_ctor) cwd_globals_ctor, (ts_allocate_dtor) cwd_globals_dtor);
ts_allocate_tls_id(&cwd_globals_id, cwd_globals_tls_addr, sizeof(virtual_cwd_globals), (ts_allocate_ctor) cwd_globals_ctor, (ts_allocate_dtor) cwd_globals_dtor);
#else
cwd_globals_ctor(&cwd_globals);
#endif
Expand Down
10 changes: 7 additions & 3 deletions Zend/zend_virtual_cwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,13 @@ typedef struct _virtual_cwd_globals {
} virtual_cwd_globals;

#ifdef ZTS
extern ts_rsrc_id cwd_globals_id;
extern size_t cwd_globals_offset;
# define CWDG(v) ZEND_TSRMG_FAST(cwd_globals_offset, virtual_cwd_globals *, v)
extern CWD_API ts_rsrc_id cwd_globals_id;
# ifdef ZEND_TLS_DIRECT
# define CWDG(v) (cwd_globals.v)
extern ZEND_TLS_API TSRM_TLS TSRM_TLS_MODEL_ATTR virtual_cwd_globals cwd_globals;
# else
# define CWDG(v) ZEND_TSRMG(cwd_globals_id, virtual_cwd_globals *, v)
# endif
#else
extern virtual_cwd_globals cwd_globals;
# define CWDG(v) (cwd_globals.v)
Expand Down
7 changes: 4 additions & 3 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ static zend_extension opcache_extension_entry;
#ifndef ZTS
zend_accel_globals accel_globals;
#else
int accel_globals_id;
size_t accel_globals_offset;
ZEND_API int accel_globals_id;
ZEND_TLS_API TSRM_TLS TSRM_TLS_MODEL_ATTR zend_accel_globals accel_globals;
static void *accel_globals_tls_addr(void) { return &accel_globals; }
#endif

/* Points to the structure shared across all PHP processes */
Expand Down Expand Up @@ -3426,7 +3427,7 @@ void start_accel_extension(void)
static int accel_startup(zend_extension *extension)
{
#ifdef ZTS
accel_globals_id = ts_allocate_fast_id(&accel_globals_id, &accel_globals_offset, sizeof(zend_accel_globals), (ts_allocate_ctor) accel_globals_ctor, (ts_allocate_dtor) accel_globals_dtor);
accel_globals_id = ts_allocate_tls_id(&accel_globals_id, accel_globals_tls_addr, sizeof(zend_accel_globals), (ts_allocate_ctor) accel_globals_ctor, (ts_allocate_dtor) accel_globals_dtor);
#else
accel_globals_ctor(&accel_globals);
#endif
Expand Down
10 changes: 7 additions & 3 deletions ext/opcache/ZendAccelerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,13 @@ extern zend_accel_shared_globals *accel_shared_globals;
#define ZCSG(element) (accel_shared_globals->element)

#ifdef ZTS
# define ZCG(v) ZEND_TSRMG_FAST(accel_globals_offset, zend_accel_globals *, v)
extern int accel_globals_id;
extern size_t accel_globals_offset;
extern ZEND_API int accel_globals_id;
# ifdef ZEND_TLS_DIRECT
# define ZCG(v) (accel_globals.v)
extern ZEND_TLS_API TSRM_TLS TSRM_TLS_MODEL_ATTR zend_accel_globals accel_globals;
# else
# define ZCG(v) ZEND_TSRMG(accel_globals_id, zend_accel_globals *, v)
# endif
#else
# define ZCG(v) (accel_globals.v)
extern zend_accel_globals accel_globals;
Expand Down
7 changes: 4 additions & 3 deletions ext/opcache/jit/zend_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
#endif

#ifdef ZTS
int jit_globals_id;
size_t jit_globals_offset;
ZEND_API int jit_globals_id;
ZEND_TLS_API TSRM_TLS TSRM_TLS_MODEL_ATTR zend_jit_globals jit_globals;
Comment on lines +50 to +51

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine removing the ZEND_API / ZEND_TLS_API here, as JIT_G() is not supposed to be used outside of ext/opcache and zend_jit.h is not installed.

In zend_jit.h, we can assume ZEND_TLS_DIRECT as these globals are not accessed by other modules.

Ditto for ext/opcache/ZendAccelerator.c / ext/opcache/ZendAccelerator.h.

static void *jit_globals_tls_addr(void) { return &jit_globals; }
#else
zend_jit_globals jit_globals;
#endif
Expand Down Expand Up @@ -3770,7 +3771,7 @@ int zend_jit_debug_config(zend_long old_val, zend_long new_val, int stage)
void zend_jit_init(void)
{
#ifdef ZTS
jit_globals_id = ts_allocate_fast_id(&jit_globals_id, &jit_globals_offset, sizeof(zend_jit_globals), (ts_allocate_ctor) zend_jit_globals_ctor, (ts_allocate_dtor) zend_jit_globals_dtor);
jit_globals_id = ts_allocate_tls_id(&jit_globals_id, jit_globals_tls_addr, sizeof(zend_jit_globals), (ts_allocate_ctor) zend_jit_globals_ctor, (ts_allocate_dtor) zend_jit_globals_dtor);
#else
zend_jit_globals_ctor(&jit_globals);
#endif
Expand Down
10 changes: 7 additions & 3 deletions ext/opcache/jit/zend_jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,13 @@ typedef struct _zend_jit_globals {
} zend_jit_globals;

#ifdef ZTS
# define JIT_G(v) ZEND_TSRMG_FAST(jit_globals_offset, zend_jit_globals *, v)
extern int jit_globals_id;
extern size_t jit_globals_offset;
extern ZEND_API int jit_globals_id;
# ifdef ZEND_TLS_DIRECT
# define JIT_G(v) (jit_globals.v)
extern ZEND_TLS_API TSRM_TLS TSRM_TLS_MODEL_ATTR zend_jit_globals jit_globals;
# else
# define JIT_G(v) ZEND_TSRMG(jit_globals_id, zend_jit_globals *, v)
# endif
#else
# define JIT_G(v) (jit_globals.v)
extern zend_jit_globals jit_globals;
Expand Down
5 changes: 3 additions & 2 deletions main/SAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

#ifdef ZTS
SAPI_API int sapi_globals_id;
SAPI_API size_t sapi_globals_offset;
ZEND_TLS_API TSRM_TLS TSRM_TLS_MODEL_ATTR sapi_globals_struct sapi_globals;
static void *sapi_globals_tls_addr(void) { return &sapi_globals; }
#else
sapi_globals_struct sapi_globals;
#endif
Expand Down Expand Up @@ -69,7 +70,7 @@ SAPI_API void sapi_startup(sapi_module_struct *sf)
sapi_module = *sf;

#ifdef ZTS
ts_allocate_fast_id(&sapi_globals_id, &sapi_globals_offset, sizeof(sapi_globals_struct), (ts_allocate_ctor) sapi_globals_ctor, (ts_allocate_dtor) sapi_globals_dtor);
ts_allocate_tls_id(&sapi_globals_id, sapi_globals_tls_addr, sizeof(sapi_globals_struct), (ts_allocate_ctor) sapi_globals_ctor, (ts_allocate_dtor) sapi_globals_dtor);
# ifdef PHP_WIN32
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
# endif
Expand Down
8 changes: 6 additions & 2 deletions main/SAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,13 @@ typedef struct _sapi_globals_struct {

BEGIN_EXTERN_C()
#ifdef ZTS
# define SG(v) ZEND_TSRMG_FAST(sapi_globals_offset, sapi_globals_struct *, v)
SAPI_API extern int sapi_globals_id;
SAPI_API extern size_t sapi_globals_offset;
# ifdef ZEND_TLS_DIRECT
# define SG(v) (sapi_globals.v)
extern ZEND_TLS_API TSRM_TLS TSRM_TLS_MODEL_ATTR sapi_globals_struct sapi_globals;
# else
# define SG(v) ZEND_TSRMG(sapi_globals_id, sapi_globals_struct *, v)
# endif
#else
# define SG(v) (sapi_globals.v)
extern SAPI_API sapi_globals_struct sapi_globals;
Expand Down
28 changes: 3 additions & 25 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ PHPAPI int (*php_register_internal_extensions_func)(void) = php_register_interna
php_core_globals core_globals;
#else
PHPAPI int core_globals_id;
PHPAPI size_t core_globals_offset;
ZEND_TLS_API TSRM_TLS TSRM_TLS_MODEL_ATTR php_core_globals core_globals;
static void *core_globals_tls_addr(void) { return &core_globals; }
#endif

#define SAFE_FILENAME(f) ((f)?(f):"-")
Expand Down Expand Up @@ -2214,7 +2215,7 @@ zend_result php_module_startup(sapi_module_struct *sf, zend_module_entry *additi
php_output_startup();

#ifdef ZTS
ts_allocate_fast_id(&core_globals_id, &core_globals_offset, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, (ts_allocate_dtor) core_globals_dtor);
ts_allocate_tls_id(&core_globals_id, core_globals_tls_addr, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, (ts_allocate_dtor) core_globals_dtor);
#ifdef PHP_WIN32
ts_allocate_id(&php_win32_core_globals_id, sizeof(php_win32_core_globals), (ts_allocate_ctor) php_win32_core_globals_ctor, (ts_allocate_dtor) php_win32_core_globals_dtor);
#endif
Expand Down Expand Up @@ -2794,32 +2795,9 @@ PHPAPI zend_result php_lint_script(zend_file_handle *file)
/* }}} */

#ifdef ZTS
/* {{{ php_reserve_tsrm_memory */
PHPAPI void php_reserve_tsrm_memory(void)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume it's fine to remove this in one go?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes 👍

{
/* CG/EG/GC globals live in native __thread storage and need no
* reserved TSRM space. */
tsrm_reserve(
TSRM_ALIGNED_SIZE(sizeof(zend_ini_scanner_globals)) +
TSRM_ALIGNED_SIZE(sizeof(virtual_cwd_globals)) +
#ifdef ZEND_SIGNALS
TSRM_ALIGNED_SIZE(sizeof(zend_signal_globals_t)) +
#endif
TSRM_ALIGNED_SIZE(sizeof(php_core_globals)) +
TSRM_ALIGNED_SIZE(sizeof(sapi_globals_struct)) +
TSRM_ALIGNED_SIZE(sizeof(zend_accel_globals)) +
#ifdef HAVE_JIT
TSRM_ALIGNED_SIZE(sizeof(zend_jit_globals)) +
#endif
0
);
}
/* }}} */

PHPAPI bool php_tsrm_startup_ex(int expected_threads)
{
bool ret = tsrm_startup(expected_threads, 1, 0, NULL);
php_reserve_tsrm_memory();
(void)ts_resource(0);
return ret;
}
Expand Down
8 changes: 6 additions & 2 deletions main/php_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
typedef struct _php_core_globals php_core_globals;

#ifdef ZTS
# define PG(v) ZEND_TSRMG_FAST(core_globals_offset, php_core_globals *, v)
extern PHPAPI int core_globals_id;
extern PHPAPI size_t core_globals_offset;
# ifdef ZEND_TLS_DIRECT
# define PG(v) (core_globals.v)
extern ZEND_TLS_API TSRM_TLS TSRM_TLS_MODEL_ATTR php_core_globals core_globals;
# else
# define PG(v) ZEND_TSRMG(core_globals_id, php_core_globals *, v)
# endif
#else
# define PG(v) (core_globals.v)
extern ZEND_API struct _php_core_globals core_globals;
Expand Down
1 change: 0 additions & 1 deletion main/php_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ extern int php_init_environ(void);
extern int php_shutdown_environ(void);

#ifdef ZTS
PHPAPI void php_reserve_tsrm_memory(void);
PHPAPI bool php_tsrm_startup_ex(int expected_threads);
PHPAPI bool php_tsrm_startup(void);

Expand Down
Loading