Skip to content

Commit

Permalink
Fixed issue #2029: Properly initialize nanotime for each thread
Browse files Browse the repository at this point in the history
The MINIT based initialization of the `nanotime_context` leaves the
struct unitialized for ZTS environments.  Therefore, we move that
initialization to the GINIT stage.
  • Loading branch information
cmb69 authored and derickr committed Oct 7, 2021
1 parent 9f167b9 commit 60ff2b6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
2 changes: 0 additions & 2 deletions src/base/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -1113,8 +1113,6 @@ void xdebug_base_minit(INIT_FUNC_ARGS)
XG_BASE(error_reporting_overridden) = 0;
XG_BASE(output_is_tty) = OUTPUT_NOT_CHECKED;

xdebug_nanotime_init();

#if PHP_VERSION_ID >= 80100
zend_observer_fiber_switch_register(xdebug_fiber_switch_observer);
#endif
Expand Down
21 changes: 20 additions & 1 deletion src/base/base_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,28 @@

#include "lib/hash.h"
#include "lib/llist.h"
#include "lib/timing.h"
#include "lib/vector.h"


#if PHP_WIN32
typedef void (WINAPI *WIN_PRECISE_TIME_FUNC)(LPFILETIME);
#endif

typedef struct _xdebug_nanotime_context {
uint64_t start_abs;
uint64_t last_abs;
#if PHP_WIN32 | HAVE_XDEBUG_CLOCK_GETTIME | HAVE_XDEBUG_CLOCK_GETTIME_NSEC_NP
uint64_t start_rel;
uint64_t last_rel;
int use_rel_time;
#endif
#if PHP_WIN32
WIN_PRECISE_TIME_FUNC win_precise_time_func;
uint64_t win_freq;
#endif
} xdebug_nanotime_context;


typedef struct _xdebug_base_globals_t {
xdebug_vector *stack;
#if PHP_VERSION_ID >= 80100
Expand Down
5 changes: 3 additions & 2 deletions src/lib/timing.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#include "php_xdebug.h"

#if PHP_WIN32
# include "win32/time.h"
# include <versionhelpers.h>
Expand Down Expand Up @@ -125,7 +126,7 @@ static uint64_t xdebug_get_nanotime_rel(xdebug_nanotime_context *nanotime_contex
}
#endif

void xdebug_nanotime_init(void)
void xdebug_nanotime_init(xdebug_base_globals_t *base)
{
xdebug_nanotime_context context = {0};

Expand Down Expand Up @@ -155,7 +156,7 @@ void xdebug_nanotime_init(void)
context.last_rel = 0;
#endif

XG_BASE(nanotime_context) = context;
base->nanotime_context = context;
}

uint64_t xdebug_get_nanotime(void)
Expand Down
20 changes: 1 addition & 19 deletions src/lib/timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,7 @@
#define NANOS_IN_MILLISEC 1000000
#define NANOS_IN_SEC 1000000000

#if PHP_WIN32
typedef void (WINAPI *WIN_PRECISE_TIME_FUNC)(LPFILETIME);
#endif

typedef struct _xdebug_nanotime_context {
uint64_t start_abs;
uint64_t last_abs;
#if PHP_WIN32 | HAVE_XDEBUG_CLOCK_GETTIME | HAVE_XDEBUG_CLOCK_GETTIME_NSEC_NP
uint64_t start_rel;
uint64_t last_rel;
int use_rel_time;
#endif
#if PHP_WIN32
WIN_PRECISE_TIME_FUNC win_precise_time_func;
uint64_t win_freq;
#endif
} xdebug_nanotime_context;

void xdebug_nanotime_init(void);
void xdebug_nanotime_init(xdebug_base_globals_t *xg);

uint64_t xdebug_get_nanotime(void);

Expand Down
2 changes: 2 additions & 0 deletions xdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ static void xdebug_init_base_globals(xdebug_base_globals_t *xg)
xg->filters_code_coverage = NULL;
xg->filters_stack = NULL;
xg->filters_tracing = NULL;

xdebug_nanotime_init(xg);
}

static void php_xdebug_init_globals(zend_xdebug_globals *xg)
Expand Down

0 comments on commit 60ff2b6

Please sign in to comment.