summaryrefslogtreecommitdiff
path: root/TSRM
diff options
context:
space:
mode:
Diffstat (limited to 'TSRM')
-rw-r--r--TSRM/Makefile.am6
-rw-r--r--TSRM/TSRM.c179
-rw-r--r--TSRM/TSRM.h36
-rw-r--r--TSRM/acinclude.m43
-rw-r--r--TSRM/build.mk40
-rwxr-xr-xTSRM/buildconf33
-rw-r--r--TSRM/configure.ac35
-rw-r--r--TSRM/m4/ax_func_which_gethostbyname_r.m4196
-rw-r--r--TSRM/readdir.h3
-rw-r--r--TSRM/threads.m425
-rw-r--r--TSRM/tsrm.m477
-rw-r--r--TSRM/tsrm_config.w32.h9
-rw-r--r--TSRM/tsrm_config_common.h13
-rw-r--r--TSRM/tsrm_strtok_r.c9
-rw-r--r--TSRM/tsrm_win32.c26
-rw-r--r--TSRM/tsrm_win32.h11
16 files changed, 221 insertions, 480 deletions
diff --git a/TSRM/Makefile.am b/TSRM/Makefile.am
deleted file mode 100644
index e232381a01..0000000000
--- a/TSRM/Makefile.am
+++ /dev/null
@@ -1,6 +0,0 @@
-## process this file with automake to produce Makefile.am
-AUTOMAKE_OPTIONS=foreign
-noinst_LTLIBRARIES=libtsrm.la
-libtsrm_la_SOURCES = TSRM.c tsrm_strtok_r.c
-
-depend:
diff --git a/TSRM/TSRM.c b/TSRM/TSRM.c
index 01433db53b..34080eed96 100644
--- a/TSRM/TSRM.c
+++ b/TSRM/TSRM.c
@@ -15,16 +15,12 @@
#ifdef ZTS
#include <stdio.h>
-
-#if HAVE_STDARG_H
#include <stdarg.h>
-#endif
typedef struct _tsrm_tls_entry tsrm_tls_entry;
-#if defined(TSRM_WIN32)
/* TSRMLS_CACHE_DEFINE; is already done in Zend, this is being always compiled statically. */
-#endif
+TSRMLS_CACHE_EXTERN();
struct _tsrm_tls_entry {
void **storage;
@@ -38,6 +34,7 @@ typedef struct {
size_t size;
ts_allocate_ctor ctor;
ts_allocate_dtor dtor;
+ size_t fast_offset;
int done;
} tsrm_resource_type;
@@ -51,8 +48,12 @@ static ts_rsrc_id id_count;
static tsrm_resource_type *resource_types_table=NULL;
static int resource_types_table_size;
+/* Reserved space for fast globals access */
+static size_t tsrm_reserved_pos = 0;
+static size_t tsrm_reserved_size = 0;
-static MUTEX_T tsmm_mutex; /* thread-safe memory manager mutex */
+static MUTEX_T tsmm_mutex; /* thread-safe memory manager mutex */
+static MUTEX_T tsrm_env_mutex; /* tsrm environ mutex */
/* New thread handlers */
static tsrm_thread_begin_func_t tsrm_new_thread_begin_handler = NULL;
@@ -164,6 +165,12 @@ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debu
tsmm_mutex = tsrm_mutex_alloc();
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Started up TSRM, %d expected threads, %d expected resources", expected_threads, expected_resources));
+
+ tsrm_reserved_pos = 0;
+ tsrm_reserved_size = 0;
+
+ tsrm_env_mutex = tsrm_mutex_alloc();
+
return 1;
}/*}}}*/
@@ -191,7 +198,9 @@ TSRM_API void tsrm_shutdown(void)
if (resource_types_table && !resource_types_table[j].done && resource_types_table[j].dtor) {
resource_types_table[j].dtor(p->storage[j]);
}
- free(p->storage[j]);
+ if (!resource_types_table[j].fast_offset) {
+ free(p->storage[j]);
+ }
}
}
free(p->storage);
@@ -208,6 +217,8 @@ TSRM_API void tsrm_shutdown(void)
}
tsrm_mutex_free(tsmm_mutex);
tsmm_mutex = NULL;
+ tsrm_mutex_free(tsrm_env_mutex);
+ tsrm_env_mutex = NULL;
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Shutdown TSRM"));
if (tsrm_error_file!=stderr) {
fclose(tsrm_error_file);
@@ -226,14 +237,55 @@ TSRM_API void tsrm_shutdown(void)
tsrm_new_thread_begin_handler = NULL;
tsrm_new_thread_end_handler = NULL;
tsrm_shutdown_handler = NULL;
+
+ tsrm_reserved_pos = 0;
+ tsrm_reserved_size = 0;
}/*}}}*/
+/* {{{ */
+/* environ lock api */
+TSRM_API void tsrm_env_lock() {
+ tsrm_mutex_lock(tsrm_env_mutex);
+}
-/* allocates a new thread-safe-resource id */
-TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor)
+TSRM_API void tsrm_env_unlock() {
+ tsrm_mutex_unlock(tsrm_env_mutex);
+} /* }}} */
+
+/* enlarge the arrays for the already active threads */
+static void tsrm_update_active_threads(void)
{/*{{{*/
int i;
+ for (i=0; i<tsrm_tls_table_size; i++) {
+ tsrm_tls_entry *p = tsrm_tls_table[i];
+
+ while (p) {
+ if (p->count < id_count) {
+ int j;
+
+ p->storage = (void *) realloc(p->storage, sizeof(void *)*id_count);
+ for (j=p->count; j<id_count; j++) {
+ if (resource_types_table[j].fast_offset) {
+ p->storage[j] = (void *) (((char*)p) + resource_types_table[j].fast_offset);
+ } else {
+ p->storage[j] = (void *) malloc(resource_types_table[j].size);
+ }
+ if (resource_types_table[j].ctor) {
+ resource_types_table[j].ctor(p->storage[j]);
+ }
+ }
+ p->count = id_count;
+ }
+ p = p->next;
+ }
+ }
+}/*}}}*/
+
+
+/* allocates a new thread-safe-resource id */
+TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor)
+{/*{{{*/
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Obtaining a new resource id, %d bytes", size));
tsrm_mutex_lock(tsmm_mutex);
@@ -258,28 +310,68 @@ TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate
resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].size = size;
resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].ctor = ctor;
resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].dtor = dtor;
+ resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].fast_offset = 0;
resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].done = 0;
- /* enlarge the arrays for the already active threads */
- for (i=0; i<tsrm_tls_table_size; i++) {
- tsrm_tls_entry *p = tsrm_tls_table[i];
+ tsrm_update_active_threads();
+ tsrm_mutex_unlock(tsmm_mutex);
- while (p) {
- if (p->count < id_count) {
- int j;
+ TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Successfully allocated new resource id %d", *rsrc_id));
+ return *rsrc_id;
+}/*}}}*/
- p->storage = (void *) realloc(p->storage, sizeof(void *)*id_count);
- for (j=p->count; j<id_count; j++) {
- p->storage[j] = (void *) malloc(resource_types_table[j].size);
- if (resource_types_table[j].ctor) {
- resource_types_table[j].ctor(p->storage[j]);
- }
- }
- p->count = id_count;
- }
- p = p->next;
+
+/* Reserve space for fast thread-safe-resources */
+TSRM_API void tsrm_reserve(size_t size)
+{/*{{{*/
+ tsrm_reserved_pos = 0;
+ tsrm_reserved_size = TSRM_ALIGNED_SIZE(size);
+}/*}}}*/
+
+
+/* allocates a new fast thread-safe-resource id */
+TSRM_API ts_rsrc_id ts_allocate_fast_id(ts_rsrc_id *rsrc_id, size_t *offset, size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor)
+{/*{{{*/
+ TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Obtaining a new fast resource id, %d bytes", size));
+
+ tsrm_mutex_lock(tsmm_mutex);
+
+ /* obtain a resource id */
+ *rsrc_id = TSRM_SHUFFLE_RSRC_ID(id_count++);
+ TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Obtained resource id %d", *rsrc_id));
+
+ size = TSRM_ALIGNED_SIZE(size);
+ if (tsrm_reserved_size - tsrm_reserved_pos < size) {
+ tsrm_mutex_unlock(tsmm_mutex);
+ TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Unable to allocate space for fast resource"));
+ *rsrc_id = 0;
+ *offset = 0;
+ return 0;
+ }
+
+ *offset = TSRM_ALIGNED_SIZE(sizeof(tsrm_tls_entry)) + tsrm_reserved_pos;
+ tsrm_reserved_pos += size;
+
+ /* store the new resource type in the resource sizes table */
+ if (resource_types_table_size < id_count) {
+ tsrm_resource_type *_tmp;
+ _tmp = (tsrm_resource_type *) realloc(resource_types_table, sizeof(tsrm_resource_type)*id_count);
+ if (!_tmp) {
+ tsrm_mutex_unlock(tsmm_mutex);
+ TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Unable to allocate storage for resource"));
+ *rsrc_id = 0;
+ return 0;
}
+ resource_types_table = _tmp;
+ resource_types_table_size = id_count;
}
+ resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].size = size;
+ resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].ctor = ctor;
+ resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].dtor = dtor;
+ resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].fast_offset = *offset;
+ resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].done = 0;
+
+ tsrm_update_active_threads();
tsrm_mutex_unlock(tsmm_mutex);
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Successfully allocated new resource id %d", *rsrc_id));
@@ -292,7 +384,7 @@ static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_
int i;
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Creating data structures for thread %x", thread_id));
- (*thread_resources_ptr) = (tsrm_tls_entry *) malloc(sizeof(tsrm_tls_entry));
+ (*thread_resources_ptr) = (tsrm_tls_entry *) malloc(TSRM_ALIGNED_SIZE(sizeof(tsrm_tls_entry)) + tsrm_reserved_size);
(*thread_resources_ptr)->storage = NULL;
if (id_count > 0) {
(*thread_resources_ptr)->storage = (void **) malloc(sizeof(void *)*id_count);
@@ -303,6 +395,7 @@ static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_
/* Set thread local storage to this new thread resources structure */
tsrm_tls_set(*thread_resources_ptr);
+ TSRMLS_CACHE = *thread_resources_ptr;
if (tsrm_new_thread_begin_handler) {
tsrm_new_thread_begin_handler(thread_id);
@@ -310,9 +403,12 @@ static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_
for (i=0; i<id_count; i++) {
if (resource_types_table[i].done) {
(*thread_resources_ptr)->storage[i] = NULL;
- } else
- {
- (*thread_resources_ptr)->storage[i] = (void *) malloc(resource_types_table[i].size);
+ } else {
+ if (resource_types_table[i].fast_offset) {
+ (*thread_resources_ptr)->storage[i] = (void *) (((char*)(*thread_resources_ptr)) + resource_types_table[i].fast_offset);
+ } else {
+ (*thread_resources_ptr)->storage[i] = (void *) malloc(resource_types_table[i].size);
+ }
if (resource_types_table[i].ctor) {
resource_types_table[i].ctor((*thread_resources_ptr)->storage[i]);
}
@@ -405,7 +501,9 @@ void tsrm_free_interpreter_context(void *context)
}
}
for (i=0; i<thread_resources->count; i++) {
- free(thread_resources->storage[i]);
+ if (!resource_types_table[i].fast_offset) {
+ free(thread_resources->storage[i]);
+ }
}
free(thread_resources->storage);
free(thread_resources);
@@ -470,7 +568,9 @@ void ts_free_thread(void)
}
}
for (i=0; i<thread_resources->count; i++) {
- free(thread_resources->storage[i]);
+ if (!resource_types_table[i].fast_offset) {
+ free(thread_resources->storage[i]);
+ }
}
free(thread_resources->storage);
if (last) {
@@ -512,7 +612,9 @@ void ts_free_worker_threads(void)
}
}
for (i=0; i<thread_resources->count; i++) {
- free(thread_resources->storage[i]);
+ if (!resource_types_table[i].fast_offset) {
+ free(thread_resources->storage[i]);
+ }
}
free(thread_resources->storage);
if (last) {
@@ -556,7 +658,9 @@ void ts_free_id(ts_rsrc_id id)
if (resource_types_table && resource_types_table[j].dtor) {
resource_types_table[j].dtor(p->storage[j]);
}
- free(p->storage[j]);
+ if (!resource_types_table[j].fast_offset) {
+ free(p->storage[j]);
+ }
p->storage[j] = NULL;
}
p = p->next;
@@ -797,12 +901,3 @@ TSRM_API const char *tsrm_api_name(void)
}/*}}}*/
#endif /* ZTS */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */
diff --git a/TSRM/TSRM.h b/TSRM/TSRM.h
index ad18012f3d..3e3e7d656e 100644
--- a/TSRM/TSRM.h
+++ b/TSRM/TSRM.h
@@ -17,7 +17,7 @@
# define TSRM_WIN32
# include "tsrm_config.w32.h"
#else
-# include <tsrm_config.h>
+# include "main/php_config.h"
#endif
#include "main/php_stdint.h"
@@ -57,6 +57,14 @@ typedef uintptr_t tsrm_uintptr_t;
#include <TLS.h>
#endif
+#if SIZEOF_SIZE_T == 4
+# define TSRM_ALIGNED_SIZE(size) \
+ (((size) + INT32_C(15)) & ~INT32_C(15))
+#else
+# define TSRM_ALIGNED_SIZE(size) \
+ (((size) + INT64_C(15)) & ~INT64_C(15))
+#endif
+
typedef int ts_rsrc_id;
/* Define THREAD_T and MUTEX_T */
@@ -74,9 +82,7 @@ typedef int ts_rsrc_id;
# define MUTEX_T st_mutex_t
#endif
-#ifdef HAVE_SIGNAL_H
#include <signal.h>
-#endif
typedef void (*ts_allocate_ctor)(void *);
typedef void (*ts_allocate_dtor)(void *);
@@ -91,9 +97,17 @@ extern "C" {
TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, char *debug_filename);
TSRM_API void tsrm_shutdown(void);
+/* environ lock API */
+TSRM_API void tsrm_env_lock();
+TSRM_API void tsrm_env_unlock();
+
/* allocates a new thread-safe-resource id */
TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor);
+/* Fast resource in reserved (pre-allocated) space */
+TSRM_API void tsrm_reserve(size_t size);
+TSRM_API ts_rsrc_id ts_allocate_fast_id(ts_rsrc_id *rsrc_id, size_t *offset, size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor);
+
/* fetches the requested resource for the current thread */
TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id);
#define ts_resource(id) ts_resource_ex(id, NULL)
@@ -162,9 +176,13 @@ TSRM_API const char *tsrm_api_name(void);
#define TSRMLS_SET_CTX(ctx) ctx = (void ***) tsrm_get_ls_cache()
#define TSRMG(id, type, element) (TSRMG_BULK(id, type)->element)
#define TSRMG_BULK(id, type) ((type) (*((void ***) tsrm_get_ls_cache()))[TSRM_UNSHUFFLE_RSRC_ID(id)])
+#define TSRMG_FAST(offset, type, element) (TSRMG_FAST_BULK(offset, type)->element)
+#define TSRMG_FAST_BULK(offset, type) ((type) (((char*) tsrm_get_ls_cache())+(offset)))
#define TSRMG_STATIC(id, type, element) (TSRMG_BULK_STATIC(id, type)->element)
#define TSRMG_BULK_STATIC(id, type) ((type) (*((void ***) TSRMLS_CACHE))[TSRM_UNSHUFFLE_RSRC_ID(id)])
+#define TSRMG_FAST_STATIC(offset, type, element) (TSRMG_FAST_BULK_STATIC(offset, type)->element)
+#define TSRMG_FAST_BULK_STATIC(offset, type) ((type) (((char*) TSRMLS_CACHE)+(offset)))
#define TSRMLS_CACHE_EXTERN() extern TSRM_TLS void *TSRMLS_CACHE;
#define TSRMLS_CACHE_DEFINE() TSRM_TLS void *TSRMLS_CACHE = NULL;
#define TSRMLS_CACHE_UPDATE() TSRMLS_CACHE = tsrm_get_ls_cache()
@@ -183,6 +201,9 @@ TSRM_API const char *tsrm_api_name(void);
#else /* non ZTS */
+#define tsrm_env_lock()
+#define tsrm_env_unlock()
+
#define TSRMLS_FETCH()
#define TSRMLS_FETCH_FROM_CTX(ctx)
#define TSRMLS_SET_CTX(ctx)
@@ -204,12 +225,3 @@ TSRM_API const char *tsrm_api_name(void);
#endif /* ZTS */
#endif /* TSRM_H */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */
diff --git a/TSRM/acinclude.m4 b/TSRM/acinclude.m4
deleted file mode 100644
index f886570c77..0000000000
--- a/TSRM/acinclude.m4
+++ /dev/null
@@ -1,3 +0,0 @@
-AC_DEFUN([AM_SET_LIBTOOL_VARIABLE],[
- LIBTOOL='$(SHELL) $(top_builddir)/libtool $1'
-])
diff --git a/TSRM/build.mk b/TSRM/build.mk
deleted file mode 100644
index e5e46b7eaa..0000000000
--- a/TSRM/build.mk
+++ /dev/null
@@ -1,40 +0,0 @@
-# Makefile to generate build tools
-#
-# Standard usage:
-# make -f build.mk
-#
-# Written by Sascha Schumann
-
-LT_TARGETS = ltmain.sh ltconfig
-
-config_h_in = tsrm_config.h.in
-
-makefile_am_files = Makefile.am
-makefile_in_files = $(makefile_am_files:.am=.in)
-makefile_files = $(makefile_am_files:e.am=e)
-
-targets = $(makefile_in_files) $(LT_TARGETS) configure $(config_h_in)
-
-all: $(targets)
-
-clean:
- rm -f $(targets)
-
-$(LT_TARGETS):
- rm -f $(LT_TARGETS)
- libtoolize --automake $(AMFLAGS) -f
-
-$(makefile_in_files): $(makefile_am_files)
- automake -a -i $(AMFLAGS) $(makefile_files)
-
-aclocal.m4: configure.ac acinclude.m4
- aclocal
-
-$(config_h_in): configure.ac
-# explicitly remove target since autoheader does not seem to work
-# correctly otherwise (timestamps are not updated)
- @rm -f $@
- autoheader
-
-configure: aclocal.m4 configure.ac
- autoconf
diff --git a/TSRM/buildconf b/TSRM/buildconf
deleted file mode 100755
index fe8dee6f76..0000000000
--- a/TSRM/buildconf
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/sh
-
-case "$1" in
---copy)
- automake_flags=--copy
- shift
-;;
-esac
-
-libtoolize --force --automake $automake_flags
-
-mv aclocal.m4 aclocal.m4.old 2>/dev/null
-aclocal
-if cmp aclocal.m4.old aclocal.m4 > /dev/null 2>&1; then
- echo "buildconf: keeping ${1}aclocal.m4"
- mv aclocal.m4.old aclocal.m4
-else
- echo "buildconf: created or modified ${1}aclocal.m4"
-fi
-
-autoheader
-
-automake --add-missing --include-deps $automake_flags
-
-mv configure configure.old 2>/dev/null
-autoconf
-if cmp configure.old configure > /dev/null 2>&1; then
- echo "buildconf: keeping ${1}configure"
- mv configure.old configure
-else
- echo "buildconf: created or modified ${1}configure"
-fi
-
diff --git a/TSRM/configure.ac b/TSRM/configure.ac
deleted file mode 100644
index c3ed326bce..0000000000
--- a/TSRM/configure.ac
+++ /dev/null
@@ -1,35 +0,0 @@
-dnl
-dnl Minimalistic configure.ac for TSRM.
-dnl
-
-AC_INIT(TSRM.c)
-AM_INIT_AUTOMAKE(TSRM, 1.0, nodefine)
-AM_CONFIG_HEADER(tsrm_config.h)
-
-AH_TOP([
-#undef PTHREADS
-])
-
-sinclude(tsrm.m4)
-
-TSRM_BASIC_CHECKS
-TSRM_THREADS_CHECKS
-
-AM_PROG_LIBTOOL
-if test "$enable_debug" != "yes"; then
- AM_SET_LIBTOOL_VARIABLE([--silent])
-fi
-
-dnl TSRM_PTHREAD
-
-AC_CHECK_HEADERS(
-utime.h \
-dirent.h \
-stdarg.h \
-alloca.h \
-unistd.h \
-limits.h
-)
-
-AC_CONFIG_FILES([Makefile])
-AC_OUTPUT
diff --git a/TSRM/m4/ax_func_which_gethostbyname_r.m4 b/TSRM/m4/ax_func_which_gethostbyname_r.m4
deleted file mode 100644
index bb6bc959e7..0000000000
--- a/TSRM/m4/ax_func_which_gethostbyname_r.m4
+++ /dev/null
@@ -1,196 +0,0 @@
-# ==================================================================================
-# https://www.gnu.org/software/autoconf-archive/ax_func_which_gethostbyname_r.html
-# ==================================================================================
-#
-# SYNOPSIS
-#
-# AX_FUNC_WHICH_GETHOSTBYNAME_R
-#
-# DESCRIPTION
-#
-# Determines which historical variant of the gethostbyname_r() call
-# (taking three, five, or six arguments) is available on the system and
-# defines one of the following macros accordingly:
-#
-# HAVE_FUNC_GETHOSTBYNAME_R_6
-# HAVE_FUNC_GETHOSTBYNAME_R_5
-# HAVE_FUNC_GETHOSTBYNAME_R_3
-#
-# as well as
-#
-# HAVE_GETHOSTBYNAME_R
-#
-# If used in conjunction with gethostname.c, the API demonstrated in
-# test.c can be used regardless of which gethostbyname_r() is available.
-# These example files can be found at
-# http://www.csn.ul.ie/~caolan/publink/gethostbyname_r
-#
-# based on David Arnold's autoconf suggestion in the threads faq
-#
-# Originally named "AC_caolan_FUNC_WHICH_GETHOSTBYNAME_R". Rewritten for
-# Autoconf 2.5x, and updated for 2.68 by Daniel Richard G.
-#
-# LICENSE
-#
-# Copyright (c) 2008 Caolan McNamara <caolan@skynet.ie>
-# Copyright (c) 2008 Daniel Richard G. <skunk@iskunk.org>
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation; either version 2 of the License, or (at your
-# option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
-# Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program. If not, see <https://www.gnu.org/licenses/>.
-#
-# As a special exception, the respective Autoconf Macro's copyright owner
-# gives unlimited permission to copy, distribute and modify the configure
-# scripts that are the output of Autoconf when processing the Macro. You
-# need not follow the terms of the GNU General Public License when using
-# or distributing such scripts, even though portions of the text of the
-# Macro appear in them. The GNU General Public License (GPL) does govern
-# all other use of the material that constitutes the Autoconf Macro.
-#
-# This special exception to the GPL applies to versions of the Autoconf
-# Macro released by the Autoconf Archive. When you make and distribute a
-# modified version of the Autoconf Macro, you may extend this special
-# exception to the GPL to apply to your modified version as well.
-
-#serial 8
-
-AC_DEFUN([AX_FUNC_WHICH_GETHOSTBYNAME_R], [
-
- AC_LANG_PUSH([C])
- AC_MSG_CHECKING([how many arguments gethostbyname_r() takes])
-
- AC_CACHE_VAL([ac_cv_func_which_gethostbyname_r], [
-
-################################################################
-
-ac_cv_func_which_gethostbyname_r=unknown
-
-#
-# ONE ARGUMENT (sanity check)
-#
-
-# This should fail, as there is no variant of gethostbyname_r() that takes
-# a single argument. If it actually compiles, then we can assume that
-# netdb.h is not declaring the function, and the compiler is thereby
-# assuming an implicit prototype. In which case, we're out of luck.
-#
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>],
- [
- char *name = "www.gnu.org";
- (void)gethostbyname_r(name) /* ; */
- ])],
- [ac_cv_func_which_gethostbyname_r=no])
-
-#
-# SIX ARGUMENTS
-# (e.g. Linux)
-#
-
-if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then
-
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>],
- [
- char *name = "www.gnu.org";
- struct hostent ret, *retp;
- char buf@<:@1024@:>@;
- int buflen = 1024;
- int my_h_errno;
- (void)gethostbyname_r(name, &ret, buf, buflen, &retp, &my_h_errno) /* ; */
- ])],
- [ac_cv_func_which_gethostbyname_r=six])
-
-fi
-
-#
-# FIVE ARGUMENTS
-# (e.g. Solaris)
-#
-
-if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then
-
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>],
- [
- char *name = "www.gnu.org";
- struct hostent ret;
- char buf@<:@1024@:>@;
- int buflen = 1024;
- int my_h_errno;
- (void)gethostbyname_r(name, &ret, buf, buflen, &my_h_errno) /* ; */
- ])],
- [ac_cv_func_which_gethostbyname_r=five])
-
-fi
-
-#
-# THREE ARGUMENTS
-# (e.g. AIX, HP-UX, Tru64)
-#
-
-if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then
-
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>],
- [
- char *name = "www.gnu.org";
- struct hostent ret;
- struct hostent_data data;
- (void)gethostbyname_r(name, &ret, &data) /* ; */
- ])],
- [ac_cv_func_which_gethostbyname_r=three])
-
-fi
-
-################################################################
-
-]) dnl end AC_CACHE_VAL
-
-case "$ac_cv_func_which_gethostbyname_r" in
- three|five|six)
- AC_DEFINE([HAVE_GETHOSTBYNAME_R], [1],
- [Define to 1 if you have some form of gethostbyname_r().])
- ;;
-esac
-
-case "$ac_cv_func_which_gethostbyname_r" in
- three)
- AC_MSG_RESULT([three])
- AC_DEFINE([HAVE_FUNC_GETHOSTBYNAME_R_3], [1],
- [Define to 1 if you have the three-argument form of gethostbyname_r().])
- ;;
-
- five)
- AC_MSG_RESULT([five])
- AC_DEFINE([HAVE_FUNC_GETHOSTBYNAME_R_5], [1],
- [Define to 1 if you have the five-argument form of gethostbyname_r().])
- ;;
-
- six)
- AC_MSG_RESULT([six])
- AC_DEFINE([HAVE_FUNC_GETHOSTBYNAME_R_6], [1],
- [Define to 1 if you have the six-argument form of gethostbyname_r().])
- ;;
-
- no)
- AC_MSG_RESULT([cannot find function declaration in netdb.h])
- ;;
-
- unknown)
- AC_MSG_RESULT([can't tell])
- ;;
-
- *)
- AC_MSG_ERROR([internal error])
- ;;
-esac
-
-AC_LANG_POP
-
-]) dnl end AC_DEFUN
diff --git a/TSRM/readdir.h b/TSRM/readdir.h
deleted file mode 100644
index 11c0f31ea1..0000000000
--- a/TSRM/readdir.h
+++ /dev/null
@@ -1,3 +0,0 @@
-/* Keep this header for compatibility with external code, it's currently not
- used anywhere in the core and there are no implementations in TSRM. */
-#include "win32/readdir.h"
diff --git a/TSRM/threads.m4 b/TSRM/threads.m4
index 55864c8982..dde7f17257 100644
--- a/TSRM/threads.m4
+++ b/TSRM/threads.m4
@@ -28,7 +28,7 @@ dnl OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
dnl PTHREADS_FLAGS
dnl
-dnl Set some magic defines to achieve POSIX threads conformance
+dnl Set some magic defines to achieve POSIX threads conformance.
dnl
AC_DEFUN([PTHREADS_FLAGS],[
if test -z "$host_alias" && test -n "$host"; then
@@ -52,18 +52,17 @@ AC_DEFUN([PTHREADS_FLAGS],[
PTHREAD_FLAGS=-D_REENTRANT;;
*sco*)
PTHREAD_FLAGS=-D_REENTRANT;;
-dnl Solves sigwait() problem, creates problems with u_long etc.
-dnl PTHREAD_FLAGS="-D_REENTRANT -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=199506 -D_XOPEN_SOURCE_EXTENDED=1";;
esac
if test -n "$PTHREAD_FLAGS"; then
CPPFLAGS="$CPPFLAGS $PTHREAD_FLAGS"
fi
-])dnl
+])
+
dnl
dnl PTHREADS_CHECK_COMPILE
dnl
-dnl Check whether the current setup can use POSIX threads calls
+dnl Check whether the current setup can use POSIX threads calls.
dnl
AC_DEFUN([PTHREADS_CHECK_COMPILE], [
AC_LINK_IFELSE([ AC_LANG_SOURCE([
@@ -85,11 +84,12 @@ int main() {
], [
pthreads_checked=no
]
-) ] )dnl
+) ] )
+
dnl
-dnl PTHREADS_CHECK()
+dnl PTHREADS_CHECK
dnl
-dnl Try to find a way to enable POSIX threads
+dnl Try to find a way to enable POSIX threads.
dnl
dnl Magic flags
dnl -kthread gcc (FreeBSD)
@@ -102,7 +102,6 @@ dnl -qthreaded AIX cc V5
dnl -threads gcc (HP-UX)
dnl
AC_DEFUN([PTHREADS_CHECK],[
-
save_CFLAGS=$CFLAGS
save_LIBS=$LIBS
PTHREADS_ASSIGN_VARS
@@ -151,8 +150,12 @@ if test "$pthreads_working" = "yes"; then
else
threads_result="POSIX-Threads not found"
fi
-])dnl
+])
+
dnl
+dnl PTHREADS_ASSIGN_VARS
+dnl
+dnl Adds pthreads linker and compiler flags.
dnl
AC_DEFUN([PTHREADS_ASSIGN_VARS],[
if test -n "$ac_cv_pthreads_lib"; then
@@ -162,4 +165,4 @@ fi
if test -n "$ac_cv_pthreads_cflags"; then
CFLAGS="$CFLAGS $ac_cv_pthreads_cflags"
fi
-])dnl
+])
diff --git a/TSRM/tsrm.m4 b/TSRM/tsrm.m4
index d02f88ee94..f269abf8a6 100644
--- a/TSRM/tsrm.m4
+++ b/TSRM/tsrm.m4
@@ -1,23 +1,19 @@
-m4_include([TSRM/m4/ax_func_which_gethostbyname_r.m4])
+dnl This file contains TSRM specific autoconf macros.
+dnl
+dnl TSRM_BASIC_CHECKS
+dnl
AC_DEFUN([TSRM_BASIC_CHECKS],[
-
AC_REQUIRE([AC_PROG_CC])dnl
-dnl AC_REQUIRE([AM_PROG_CC_STDC])dnl
-AC_REQUIRE([AC_PROG_CC_C_O])dnl
AC_REQUIRE([AC_PROG_RANLIB])dnl
-AC_CHECK_HEADERS(stdarg.h)
-
AC_CHECK_FUNCS(sigprocmask)
-
-AX_FUNC_WHICH_GETHOSTBYNAME_R()
-
])
-
+dnl
+dnl TSRM_CHECK_PTH
+dnl
AC_DEFUN([TSRM_CHECK_PTH],[
-
AC_MSG_CHECKING(for GNU Pth)
PTH_PREFIX="`$1 --prefix`"
if test -z "$PTH_PREFIX"; then
@@ -30,9 +26,11 @@ LIBS="$LIBS `$1 --libs`"
AC_DEFINE(GNUPTH, 1, [Whether you use GNU Pth])
AC_MSG_RESULT(yes - installed in $PTH_PREFIX)
-
])
+dnl
+dnl TSRM_CHECK_ST
+dnl
AC_DEFUN([TSRM_CHECK_ST],[
if test -r "$1/include/st.h"; then
CPPFLAGS="$CPPFLAGS -I$1/include"
@@ -50,10 +48,10 @@ AC_DEFUN([TSRM_CHECK_ST],[
AC_DEFINE(TSRM_ST, 1, [ ])
])
-sinclude(threads.m4)
-
+dnl
+dnl TSRM_CHECK_PTHREADS
+dnl
AC_DEFUN([TSRM_CHECK_PTHREADS],[
-
PTHREADS_CHECK
if test "$pthreads_working" != "yes"; then
@@ -66,32 +64,30 @@ AC_MSG_CHECKING(for POSIX threads)
AC_MSG_RESULT(yes)
])
+dnl
+dnl TSRM_THREADS_CHECKS
+dnl
+dnl For the thread implementations, we always use --with-* to maintain
+dnl consistency.
+dnl
AC_DEFUN([TSRM_THREADS_CHECKS],[
-
-dnl For the thread implementations, we always use --with-*
-dnl to maintain consistency
-
-AC_ARG_WITH(tsrm-pth,
-[ --with-tsrm-pth[=pth-config]
- Use GNU Pth],[
- TSRM_PTH=$withval
-],[
- TSRM_PTH=no
-])
-
-AC_ARG_WITH(tsrm-st,
-[ --with-tsrm-st Use SGI's State Threads],[
- TSRM_ST=$withval
-],[
- TSRM_ST=no
-])
-
-AC_ARG_WITH(tsrm-pthreads,
-[ --with-tsrm-pthreads Use POSIX threads (default)],[
- TSRM_PTHREADS=$withval
-],[
- TSRM_PTHREADS=yes
-])
+AC_ARG_WITH([tsrm-pth],
+ [AS_HELP_STRING([[--with-tsrm-pth[=pth-config]]],
+ [Use GNU Pth])],
+ [TSRM_PTH=$withval],
+ [TSRM_PTH=no])
+
+AC_ARG_WITH([tsrm-st],
+ [AS_HELP_STRING([--with-tsrm-st],
+ [Use SGI's State Threads])],
+ [TSRM_ST=$withval],
+ [TSRM_ST=no])
+
+AC_ARG_WITH([tsrm-pthreads],
+ [AS_HELP_STRING([--with-tsrm-pthreads],
+ [Use POSIX threads (default)])],
+ [TSRM_PTHREADS=$withval],
+ [TSRM_PTHREADS=yes])
test "$TSRM_PTH" = "yes" && TSRM_PTH=pth-config
@@ -102,5 +98,4 @@ elif test "$TSRM_ST" != "no"; then
elif test "$TSRM_PTHREADS" != "no"; then
TSRM_CHECK_PTHREADS
fi
-
])
diff --git a/TSRM/tsrm_config.w32.h b/TSRM/tsrm_config.w32.h
index ab45141179..ec5c576298 100644
--- a/TSRM/tsrm_config.w32.h
+++ b/TSRM/tsrm_config.w32.h
@@ -12,12 +12,3 @@
#include <crtdbg.h>
#endif
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */
diff --git a/TSRM/tsrm_config_common.h b/TSRM/tsrm_config_common.h
index f70f7a5c41..dac64b0400 100644
--- a/TSRM/tsrm_config_common.h
+++ b/TSRM/tsrm_config_common.h
@@ -10,7 +10,7 @@
#ifdef TSRM_WIN32
# include "tsrm_config.w32.h"
#else
-# include <tsrm_config.h>
+# include "main/php_config.h"
# include <sys/param.h>
#endif
@@ -35,9 +35,7 @@ char *alloca ();
#include <unistd.h>
#endif
-#if HAVE_LIMITS_H
#include <limits.h>
-#endif
#ifndef MAXPATHLEN
# if _WIN32
@@ -69,12 +67,3 @@ char *alloca ();
#endif
#endif /* TSRM_CONFIG_COMMON_H */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */
diff --git a/TSRM/tsrm_strtok_r.c b/TSRM/tsrm_strtok_r.c
index cf0b0e672c..472105b43e 100644
--- a/TSRM/tsrm_strtok_r.c
+++ b/TSRM/tsrm_strtok_r.c
@@ -61,12 +61,3 @@ main()
}
#endif
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */
diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c
index a7956caf90..af875fa2a0 100644
--- a/TSRM/tsrm_win32.c
+++ b/TSRM/tsrm_win32.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2018 The PHP Group |
+ | Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -458,7 +458,6 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd,
process_pair *proc;
char *cmd = NULL;
wchar_t *cmdw = NULL, *cwdw = NULL, *envw = NULL;
- int i;
char *ptype = (char *)type;
HANDLE thread_token = NULL;
HANDLE token_user = NULL;
@@ -468,17 +467,17 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd,
return NULL;
}
- /*The following two checks can be removed once we drop XP support */
type_len = (int)strlen(type);
- if (type_len <1 || type_len > 2) {
+ if (type_len < 1 || type_len > 2) {
return NULL;
}
- for (i=0; i < type_len; i++) {
- if (!(*ptype == 'r' || *ptype == 'w' || *ptype == 'b' || *ptype == 't')) {
- return NULL;
- }
- ptype++;
+ if (ptype[0] != 'r' && ptype[0] != 'w') {
+ return NULL;
+ }
+
+ if (type_len > 1 && (ptype[1] != 'b' && ptype[1] != 't')) {
+ return NULL;
}
cmd = (char*)malloc(strlen(command)+strlen(TWG(comspec))+sizeof(" /c ")+2);
@@ -820,12 +819,3 @@ TSRM_API int win32_utime(const char *filename, struct utimbuf *buf) /* {{{ */
/* }}} */
#endif
#endif
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */
diff --git a/TSRM/tsrm_win32.h b/TSRM/tsrm_win32.h
index b24224c66a..1ae9beaf2c 100644
--- a/TSRM/tsrm_win32.h
+++ b/TSRM/tsrm_win32.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2018 The PHP Group |
+ | Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -109,12 +109,3 @@ TSRM_API void *shmat(int key, const void *shmaddr, int flags);
TSRM_API int shmdt(const void *shmaddr);
TSRM_API int shmctl(int key, int cmd, struct shmid_ds *buf);
#endif
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */