summaryrefslogtreecommitdiff
path: root/TSRM
diff options
context:
space:
mode:
Diffstat (limited to 'TSRM')
-rw-r--r--TSRM/TSRM.c145
-rw-r--r--TSRM/TSRM.h22
-rw-r--r--TSRM/build.mk6
-rw-r--r--TSRM/configure.ac (renamed from TSRM/configure.in)2
-rw-r--r--TSRM/readdir.h48
-rw-r--r--TSRM/tsrm_config.w32.h9
-rw-r--r--TSRM/tsrm_config_common.h11
-rw-r--r--TSRM/tsrm_nw.c240
-rw-r--r--TSRM/tsrm_nw.h29
-rw-r--r--TSRM/tsrm_strtok_r.c17
-rw-r--r--TSRM/tsrm_win32.c128
-rw-r--r--TSRM/tsrm_win32.h20
12 files changed, 227 insertions, 450 deletions
diff --git a/TSRM/TSRM.c b/TSRM/TSRM.c
index 9fb8abd3a4..ed1f24f8b8 100644
--- a/TSRM/TSRM.c
+++ b/TSRM/TSRM.c
@@ -55,8 +55,9 @@ static int resource_types_table_size;
static MUTEX_T tsmm_mutex; /* thread-safe memory manager mutex */
/* New thread handlers */
-static tsrm_thread_begin_func_t tsrm_new_thread_begin_handler;
-static tsrm_thread_end_func_t tsrm_new_thread_end_handler;
+static tsrm_thread_begin_func_t tsrm_new_thread_begin_handler = NULL;
+static tsrm_thread_end_func_t tsrm_new_thread_end_handler = NULL;
+static tsrm_shutdown_func_t tsrm_shutdown_handler = NULL;
/* Debug support */
int tsrm_error(int level, const char *format, ...);
@@ -125,9 +126,11 @@ static int32 tls_key;
# warning tsrm_set_interpreter_context is probably broken on this platform
#endif
+TSRM_TLS uint8_t in_main_thread = 0;
+
/* Startup TSRM (call once for the entire process) */
TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, char *debug_filename)
-{
+{/*{{{*/
#if defined(GNUPTH)
pth_init();
pth_key_create(&tls_key, 0);
@@ -142,6 +145,9 @@ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debu
tls_key = tls_allocate();
#endif
+ /* ensure singleton */
+ in_main_thread = 1;
+
tsrm_error_file = stderr;
tsrm_error_set(debug_level, debug_filename);
tsrm_tls_table_size = expected_threads;
@@ -164,18 +170,21 @@ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debu
tsmm_mutex = tsrm_mutex_alloc();
- tsrm_new_thread_begin_handler = tsrm_new_thread_end_handler = NULL;
-
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Started up TSRM, %d expected threads, %d expected resources", expected_threads, expected_resources));
return 1;
-}
+}/*}}}*/
/* Shutdown TSRM (call once for the entire process) */
TSRM_API void tsrm_shutdown(void)
-{
+{/*{{{*/
int i;
+ if (!in_main_thread) {
+ /* ensure singleton */
+ return;
+ }
+
if (tsrm_tls_table) {
for (i=0; i<tsrm_tls_table_size; i++) {
tsrm_tls_entry *p = tsrm_tls_table[i], *next_p;
@@ -218,12 +227,18 @@ TSRM_API void tsrm_shutdown(void)
#elif defined(TSRM_WIN32)
TlsFree(tls_key);
#endif
-}
+ if (tsrm_shutdown_handler) {
+ tsrm_shutdown_handler();
+ }
+ tsrm_new_thread_begin_handler = NULL;
+ tsrm_new_thread_end_handler = NULL;
+ tsrm_shutdown_handler = NULL;
+}/*}}}*/
/* 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)
-{
+{/*{{{*/
int i;
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Obtaining a new resource id, %d bytes", size));
@@ -274,11 +289,11 @@ TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Successfully allocated new resource id %d", *rsrc_id));
return *rsrc_id;
-}
+}/*}}}*/
static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_T thread_id)
-{
+{/*{{{*/
int i;
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Creating data structures for thread %x", thread_id));
@@ -314,25 +329,16 @@ static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_
}
tsrm_mutex_unlock(tsmm_mutex);
-}
+}/*}}}*/
/* fetches the requested resource for the current thread */
TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id)
-{
+{/*{{{*/
THREAD_T thread_id;
int hash_value;
tsrm_tls_entry *thread_resources;
-#ifdef NETWARE
- /* The below if loop is added for NetWare to fix an abend while unloading PHP
- * when an Apache unload command is issued on the system console.
- * While exiting from PHP, at the end for some reason, this function is called
- * with tsrm_tls_table = NULL. When this happened, the server abends when
- * tsrm_tls_table is accessed since it is NULL.
- */
- if(tsrm_tls_table) {
-#endif
if (!th_id) {
/* Fast path for looking up the resources for the current
* thread. Its used by just about every call to
@@ -386,15 +392,12 @@ TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id)
* changes to the structure as we read it.
*/
TSRM_SAFE_RETURN_RSRC(thread_resources->storage, id, thread_resources->count);
-#ifdef NETWARE
- } /* if(tsrm_tls_table) */
-#endif
-}
+}/*}}}*/
/* frees an interpreter context. You are responsible for making sure that
* it is not linked into the TSRM hash, and not marked as the current interpreter */
void tsrm_free_interpreter_context(void *context)
-{
+{/*{{{*/
tsrm_tls_entry *next, *thread_resources = (tsrm_tls_entry*)context;
int i;
@@ -413,10 +416,10 @@ void tsrm_free_interpreter_context(void *context)
free(thread_resources);
thread_resources = next;
}
-}
+}/*}}}*/
void *tsrm_set_interpreter_context(void *new_ctx)
-{
+{/*{{{*/
tsrm_tls_entry *current;
current = tsrm_tls_get();
@@ -429,12 +432,12 @@ void *tsrm_set_interpreter_context(void *new_ctx)
/* return old context, so caller can restore it when they're done */
return current;
-}
+}/*}}}*/
/* allocates a new interpreter context */
void *tsrm_new_interpreter_context(void)
-{
+{/*{{{*/
tsrm_tls_entry *new_ctx, *current;
THREAD_T thread_id;
@@ -448,12 +451,12 @@ void *tsrm_new_interpreter_context(void)
/* switch back to the context that was in use prior to our creation
* of the new one */
return tsrm_set_interpreter_context(current);
-}
+}/*}}}*/
/* frees all resources allocated for the current thread */
void ts_free_thread(void)
-{
+{/*{{{*/
tsrm_tls_entry *thread_resources;
int i;
THREAD_T thread_id = tsrm_thread_id();
@@ -490,12 +493,12 @@ void ts_free_thread(void)
thread_resources = thread_resources->next;
}
tsrm_mutex_unlock(tsmm_mutex);
-}
+}/*}}}*/
/* frees all resources allocated for all threads except current */
void ts_free_worker_threads(void)
-{
+{/*{{{*/
tsrm_tls_entry *thread_resources;
int i;
THREAD_T thread_id = tsrm_thread_id();
@@ -536,12 +539,12 @@ void ts_free_worker_threads(void)
}
}
tsrm_mutex_unlock(tsmm_mutex);
-}
+}/*}}}*/
/* deallocates all occurrences of a given id */
void ts_free_id(ts_rsrc_id id)
-{
+{/*{{{*/
int i;
int j = TSRM_UNSHUFFLE_RSRC_ID(id);
@@ -570,7 +573,7 @@ void ts_free_id(ts_rsrc_id id)
tsrm_mutex_unlock(tsmm_mutex);
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Successfully freed resource id %d", id));
-}
+}/*}}}*/
@@ -581,7 +584,7 @@ void ts_free_id(ts_rsrc_id id)
/* Obtain the current thread id */
TSRM_API THREAD_T tsrm_thread_id(void)
-{
+{/*{{{*/
#ifdef TSRM_WIN32
return GetCurrentThreadId();
#elif defined(GNUPTH)
@@ -597,12 +600,12 @@ TSRM_API THREAD_T tsrm_thread_id(void)
#elif defined(BETHREADS)
return find_thread(NULL);
#endif
-}
+}/*}}}*/
/* Allocate a mutex */
TSRM_API MUTEX_T tsrm_mutex_alloc(void)
-{
+{/*{{{*/
MUTEX_T mutexp;
#ifdef TSRM_WIN32
mutexp = malloc(sizeof(CRITICAL_SECTION));
@@ -628,12 +631,12 @@ TSRM_API MUTEX_T tsrm_mutex_alloc(void)
printf("Mutex created thread: %d\n",mythreadid());
#endif
return( mutexp );
-}
+}/*}}}*/
/* Free a mutex */
TSRM_API void tsrm_mutex_free(MUTEX_T mutexp)
-{
+{/*{{{*/
if (mutexp) {
#ifdef TSRM_WIN32
DeleteCriticalSection(mutexp);
@@ -657,7 +660,7 @@ TSRM_API void tsrm_mutex_free(MUTEX_T mutexp)
#ifdef THR_DEBUG
printf("Mutex freed thread: %d\n",mythreadid());
#endif
-}
+}/*}}}*/
/*
@@ -665,7 +668,7 @@ TSRM_API void tsrm_mutex_free(MUTEX_T mutexp)
A return value of 0 indicates success
*/
TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp)
-{
+{/*{{{*/
TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Mutex locked thread: %ld", tsrm_thread_id()));
#ifdef TSRM_WIN32
EnterCriticalSection(mutexp);
@@ -689,7 +692,7 @@ TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp)
return acquire_sem(mutexp->sem);
return 0;
#endif
-}
+}/*}}}*/
/*
@@ -697,7 +700,7 @@ TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp)
A return value of 0 indicates success
*/
TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp)
-{
+{/*{{{*/
TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Mutex unlocked thread: %ld", tsrm_thread_id()));
#ifdef TSRM_WIN32
LeaveCriticalSection(mutexp);
@@ -721,14 +724,14 @@ TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp)
return release_sem(mutexp->sem);
return 0;
#endif
-}
+}/*}}}*/
/*
Changes the signal mask of the calling thread
*/
#ifdef HAVE_SIGPROCMASK
TSRM_API int tsrm_sigmask(int how, const sigset_t *set, sigset_t *oldset)
-{
+{/*{{{*/
TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Changed sigmask in thread: %ld", tsrm_thread_id()));
/* TODO: add support for other APIs */
#ifdef PTHREADS
@@ -736,27 +739,35 @@ TSRM_API int tsrm_sigmask(int how, const sigset_t *set, sigset_t *oldset)
#else
return sigprocmask(how, set, oldset);
#endif
-}
+}/*}}}*/
#endif
TSRM_API void *tsrm_set_new_thread_begin_handler(tsrm_thread_begin_func_t new_thread_begin_handler)
-{
+{/*{{{*/
void *retval = (void *) tsrm_new_thread_begin_handler;
tsrm_new_thread_begin_handler = new_thread_begin_handler;
return retval;
-}
+}/*}}}*/
TSRM_API void *tsrm_set_new_thread_end_handler(tsrm_thread_end_func_t new_thread_end_handler)
-{
+{/*{{{*/
void *retval = (void *) tsrm_new_thread_end_handler;
tsrm_new_thread_end_handler = new_thread_end_handler;
return retval;
-}
+}/*}}}*/
+
+TSRM_API void *tsrm_set_shutdown_handler(tsrm_shutdown_func_t shutdown_handler)
+{/*{{{*/
+ void *retval = (void *) tsrm_shutdown_handler;
+
+ tsrm_shutdown_handler = shutdown_handler;
+ return retval;
+}/*}}}*/
/*
@@ -765,7 +776,7 @@ TSRM_API void *tsrm_set_new_thread_end_handler(tsrm_thread_end_func_t new_thread
#if TSRM_DEBUG
int tsrm_error(int level, const char *format, ...)
-{
+{/*{{{*/
if (level<=tsrm_error_level) {
va_list args;
int size;
@@ -780,12 +791,12 @@ int tsrm_error(int level, const char *format, ...)
} else {
return 0;
}
-}
+}/*}}}*/
#endif
void tsrm_error_set(int level, char *debug_filename)
-{
+{/*{{{*/
tsrm_error_level = level;
#if TSRM_DEBUG
@@ -802,11 +813,25 @@ void tsrm_error_set(int level, char *debug_filename)
tsrm_error_file = stderr;
}
#endif
-}
+}/*}}}*/
TSRM_API void *tsrm_get_ls_cache(void)
-{
+{/*{{{*/
return tsrm_tls_get();
-}
+}/*}}}*/
+
+TSRM_API uint8_t tsrm_is_main_thread(void)
+{/*{{{*/
+ return in_main_thread;
+}/*}}}*/
#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 458843a689..1485b38e7d 100644
--- a/TSRM/TSRM.h
+++ b/TSRM/TSRM.h
@@ -128,6 +128,7 @@ TSRM_API void ts_free_id(ts_rsrc_id id);
typedef void (*tsrm_thread_begin_func_t)(THREAD_T thread_id);
typedef void (*tsrm_thread_end_func_t)(THREAD_T thread_id);
+typedef void (*tsrm_shutdown_func_t)(void);
TSRM_API int tsrm_error(int level, const char *format, ...);
@@ -145,6 +146,7 @@ TSRM_API int tsrm_sigmask(int how, const sigset_t *set, sigset_t *oldset);
TSRM_API void *tsrm_set_new_thread_begin_handler(tsrm_thread_begin_func_t new_thread_begin_handler);
TSRM_API void *tsrm_set_new_thread_end_handler(tsrm_thread_end_func_t new_thread_end_handler);
+TSRM_API void *tsrm_set_shutdown_handler(tsrm_shutdown_func_t shutdown_handler);
/* these 3 APIs should only be used by people that fully understand the threading model
* used by PHP/Zend and the selected SAPI. */
@@ -153,11 +155,16 @@ TSRM_API void *tsrm_set_interpreter_context(void *new_ctx);
TSRM_API void tsrm_free_interpreter_context(void *context);
TSRM_API void *tsrm_get_ls_cache(void);
+TSRM_API uint8_t tsrm_is_main_thread(void);
-#ifdef TSRM_WIN32
-# define TSRM_TLS __declspec(thread)
+#if defined(__cplusplus) && __cplusplus > 199711L
+# define TSRM_TLS thread_local
#else
-# define TSRM_TLS __thread
+# ifdef TSRM_WIN32
+# define TSRM_TLS __declspec(thread)
+# else
+# define TSRM_TLS __thread
+# endif
#endif
#define TSRM_SHUFFLE_RSRC_ID(rsrc_id) ((rsrc_id)+1)
@@ -215,3 +222,12 @@ TSRM_API void *tsrm_get_ls_cache(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/build.mk b/TSRM/build.mk
index f5756af72c..f98109fa06 100644
--- a/TSRM/build.mk
+++ b/TSRM/build.mk
@@ -30,14 +30,14 @@ $(LT_TARGETS):
$(makefile_in_files): $(makefile_am_files)
automake -a -i $(AMFLAGS) $(makefile_files)
-aclocal.m4: configure.in acinclude.m4
+aclocal.m4: configure.ac acinclude.m4
aclocal
-$(config_h_in): configure.in
+$(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.in
+configure: aclocal.m4 configure.ac
autoconf
diff --git a/TSRM/configure.in b/TSRM/configure.ac
index 6f10f5ab13..8bf35d33b0 100644
--- a/TSRM/configure.in
+++ b/TSRM/configure.ac
@@ -1,6 +1,6 @@
dnl $Id$
dnl
-dnl Minimalistic configure.in for TSRM.
+dnl Minimalistic configure.ac for TSRM.
dnl
AC_INIT(TSRM.c)
diff --git a/TSRM/readdir.h b/TSRM/readdir.h
index 0665810c85..11c0f31ea1 100644
--- a/TSRM/readdir.h
+++ b/TSRM/readdir.h
@@ -1,45 +1,3 @@
-#ifndef READDIR_H
-#define READDIR_H
-
-
-/*
- * Structures and types used to implement opendir/readdir/closedir
- * on Windows 95/NT.
- */
-
-#include <windows.h>
-
-#include <io.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <direct.h>
-
-/* struct dirent - same as Unix */
-
-struct dirent {
- long d_ino; /* inode (always 1 in WIN32) */
- off_t d_off; /* offset to this dirent */
- unsigned short d_reclen; /* length of d_name */
- char d_name[_MAX_FNAME + 1]; /* filename (null terminated) */
-};
-
-
-/* typedef DIR - not the same as Unix */
-typedef struct {
- HANDLE handle; /* _findfirst/_findnext handle */
- short offset; /* offset into directory */
- short finished; /* 1 if there are not more files */
- WIN32_FIND_DATA fileinfo; /* from _findfirst/_findnext */
- char *dir; /* the dir we are reading */
- struct dirent dent; /* the dirent to return */
-} DIR;
-
-/* Function prototypes */
-DIR *opendir(const char *);
-struct dirent *readdir(DIR *);
-int readdir_r(DIR *, struct dirent *, struct dirent **);
-int closedir(DIR *);
-int rewinddir(DIR *);
-
-#endif /* READDIR_H */
+/* 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/tsrm_config.w32.h b/TSRM/tsrm_config.w32.h
index 1443e7cca9..a58d47517c 100644
--- a/TSRM/tsrm_config.w32.h
+++ b/TSRM/tsrm_config.w32.h
@@ -13,3 +13,12 @@
#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 829cf677f0..f70f7a5c41 100644
--- a/TSRM/tsrm_config_common.h
+++ b/TSRM/tsrm_config_common.h
@@ -25,9 +25,7 @@
#pragma alloca
# else
# ifndef alloca /* predefined by HP cc +Olibcalls */
-# ifndef NETWARE
char *alloca ();
-# endif
# endif
# endif
# endif
@@ -71,3 +69,12 @@ 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_nw.c b/TSRM/tsrm_nw.c
deleted file mode 100644
index 5503294fca..0000000000
--- a/TSRM/tsrm_nw.c
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2018 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 |
- | available through the world-wide-web at the following url: |
- | http://www.php.net/license/3_01.txt |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Venkat Raghavan S <rvenkat@novell.com> |
- | Anantha Kesari H Y <hyanantha@novell.com> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <fcntl.h>
-
-#include "TSRM.h"
-
-#ifdef NETWARE
-
-#ifdef USE_MKFIFO
-#include <sys/stat.h>
-#elif !defined(USE_PIPE_OPEN) /* NXFifoOpen */
-#include <nks/fsio.h>
-#endif
-
-#include <nks/vm.h>
-#include <nks/memory.h>
-
-#include <string.h>
-
-#include "mktemp.h"
-
-/* strtok() call in LibC is abending when used in a different address space
- * -- hence using PHP's version itself for now
- */
-#include "tsrm_strtok_r.h"
-#define tsrm_strtok_r(a,b,c) strtok((a),(b))
-
-#define WHITESPACE " \t"
-#define MAX_ARGS 10
-
-
-TSRM_API FILE* popen(const char *commandline, const char *type)
-{
- char *command = NULL, *argv[MAX_ARGS] = {'\0'}, **env = NULL;
- char *tempName = "sys:/php/temp/phpXXXXXX.tmp";
- char *filePath = NULL;
- char *ptr = NULL;
- int ptrLen = 0, argc = 0, i = 0, envCount = 0, err = 0;
- FILE *stream = NULL;
-#if defined(USE_PIPE_OPEN) || defined(USE_MKFIFO)
- int pipe_handle;
- int mode = O_RDONLY;
-#else
- NXHandle_t pipe_handle;
- NXMode_t mode = NX_O_RDONLY;
-#endif
- NXExecEnvSpec_t envSpec;
- NXNameSpec_t nameSpec;
- NXVmId_t newVM = 0;
-
- /* Check for validity of input parameters */
- if (!commandline || !type)
- return NULL;
-
- /* Get temporary file name */
- filePath = mktemp(tempName);
- if (!filePath)
- return NULL;
-
- /* Set pipe mode according to type -- for now allow only "r" or "w" */
- if (strcmp(type, "r") == 0)
-#if defined(USE_PIPE_OPEN) || defined(USE_MKFIFO)
- mode = O_RDONLY;
-#else
- mode = NX_O_RDONLY;
-#endif
- else if (strcmp(type, "w") == 0)
-#if defined(USE_PIPE_OPEN) || defined(USE_MKFIFO)
- mode = O_WRONLY;
-#else
- mode = NX_O_WRONLY;
-#endif
- else
- return NULL;
-
-#ifdef USE_PIPE_OPEN
- pipe_handle = pipe_open(filePath, mode);
- if (pipe_handle == -1)
- return NULL;
-#elif defined(USE_MKFIFO)
- pipe_handle = mkfifo(filePath, mode);
- if (pipe_handle == -1)
- return NULL;
-#else
- /* - NetWare doesn't require first parameter
- * - Allowing LibC to choose the buffer size for now
- */
- err = NXFifoOpen(0, filePath, mode, 0, &pipe_handle);
- if (err)
- return NULL;
-#endif
-
- /* Copy the environment variables in preparation for the spawn call */
- envCount = NXGetEnvCount() + 1; /* add one for NULL */
- env = (char **) NXMemAlloc(sizeof(char *) * envCount, 0);
- if (!env)
- return NULL;
-
- err = NXCopyEnv(env, envCount);
- if (err) {
- NXMemFree (env);
- return NULL;
- }
-
- /* Separate commandline string into words */
- ptr = tsrm_strtok_r((char*)commandline, WHITESPACE, NULL);
- ptrLen = strlen(ptr);
-
- command = (char*)malloc(ptrLen + 1);
- if (!command) {
- NXMemFree (env);
- return NULL;
- }
-
- strcpy (command, ptr);
-
- ptr = tsrm_strtok_r(NULL, WHITESPACE, NULL);
- while (ptr && (argc < MAX_ARGS)) {
- ptrLen = strlen(ptr);
-
- argv[argc] = (char*)malloc(ptrLen + 1);
- if (!argv[argc]) {
- NXMemFree (env);
- if (command)
- free (command);
-
- for (i = 0; i < argc; i++) {
- if (argv[i])
- free (argv[i]);
- }
-
- return NULL;
- }
-
- strcpy (argv[argc], ptr);
- argc++;
- ptr = tsrm_strtok_r(NULL, WHITESPACE, NULL);
- }
-
- /* Setup the execution environment and spawn new process */
- envSpec.esFlags = 0; /* Not used */
- envSpec.esArgc = argc;
- envSpec.esArgv = (void **) argv;
- envSpec.esEnv = (void **) env;
-
-/* envSpec.esStdin.ssType = */
- envSpec.esStdout.ssType = NX_OBJ_FIFO;
- envSpec.esStderr.ssType = NX_OBJ_FILE;
-
- /* 'ssHandle' is not a struct/union/class member */
-/*
- envSpec.esStdin.ssHandle =
- envSpec.esStdout.ssHandle =
- envSpec.esStderr.ssHandle = -1;
-*/
- envSpec.esStdin.ssPathCtx = NULL;
- envSpec.esStdout.ssPathCtx = NULL;
- envSpec.esStderr.ssPathCtx = NULL;
-
-#if defined(USE_PIPE_OPEN) || defined(USE_MKFIFO)
- if (mode == O_RDONLY) {
-#else
- if (mode == NX_O_RDONLY) {
-#endif
- envSpec.esStdin.ssPath = filePath;
- envSpec.esStdout.ssPath = stdout;
- } else { /* Write Only */
- envSpec.esStdin.ssPath = stdin;
- envSpec.esStdout.ssPath = filePath;
- }
-
- envSpec.esStderr.ssPath = stdout;
-
- nameSpec.ssType = NX_OBJ_FIFO;
-/* nameSpec.ssHandle = 0; */ /* 'ssHandle' is not a struct/union/class member */
- nameSpec.ssPathCtx = NULL; /* Not used */
- nameSpec.ssPath = argv[0];
- err = NXVmSpawn(&nameSpec, &envSpec, 0, &newVM);
- if (!err)
- /* Get file pointer corresponding to the pipe (file) opened */
- stream = fdopen(pipe_handle, type);
-
- /* Clean-up */
- if (env)
- NXMemFree (env);
-
- if (pipe_handle)
-#if defined(USE_PIPE_OPEN) || defined(USE_MKFIFO)
- close(pipe_handle);
-#else
- NXClose(pipe_handle);
-#endif
-
- if (command)
- free (command);
-
- for (i = 0; i < argc; i++) {
- if (argv[i])
- free (argv[i]);
- }
-
- return stream;
-}
-
-TSRM_API int pclose(FILE* stream)
-{
- int err = 0;
- NXHandle_t fd = 0;
-
- /* Get the process associated with this pipe (file) handle and terminate it */
- fd = fileno(stream);
- NXClose (fd);
-
- err = fclose(stream);
-
- return err;
-}
-
-#endif /* NETWARE */
diff --git a/TSRM/tsrm_nw.h b/TSRM/tsrm_nw.h
deleted file mode 100644
index cadf5ee02a..0000000000
--- a/TSRM/tsrm_nw.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2018 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 |
- | available through the world-wide-web at the following url: |
- | http://www.php.net/license/3_01.txt |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Venkat Raghavan S <rvenkat@novell.com> |
- | Anantha Kesari H Y <hyanantha@novell.com> |
- +----------------------------------------------------------------------+
-*/
-
-
-#ifndef TSRM_NW_H
-#define TSRM_NW_H
-
-#include "TSRM.h"
-
-TSRM_API FILE* popen(const char *command, const char *type);
-TSRM_API int pclose(FILE* stream);
-
-#endif
diff --git a/TSRM/tsrm_strtok_r.c b/TSRM/tsrm_strtok_r.c
index b84e32567c..cf0b0e672c 100644
--- a/TSRM/tsrm_strtok_r.c
+++ b/TSRM/tsrm_strtok_r.c
@@ -4,7 +4,7 @@
#include "tsrm_strtok_r.h"
static inline int in_character_class(char ch, const char *delim)
-{
+{/*{{{*/
while (*delim) {
if (*delim == ch) {
return 1;
@@ -12,10 +12,10 @@ static inline int in_character_class(char ch, const char *delim)
delim++;
}
return 0;
-}
+}/*}}}*/
TSRM_API char *tsrm_strtok_r(char *s, const char *delim, char **last)
-{
+{/*{{{*/
char *token;
if (s == NULL) {
@@ -41,7 +41,7 @@ TSRM_API char *tsrm_strtok_r(char *s, const char *delim, char **last)
*last = s + 1;
}
return token;
-}
+}/*}}}*/
#if 0
@@ -61,3 +61,12 @@ 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 5ac8124c33..039fef7cc2 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) 1997-2017 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 |
@@ -42,7 +42,7 @@ static tsrm_win32_globals win32_globals;
#endif
static void tsrm_win32_ctor(tsrm_win32_globals *globals)
-{
+{/*{{{*/
#ifdef ZTS
TSRMLS_CACHE_UPDATE();
#endif
@@ -61,10 +61,10 @@ TSRMLS_CACHE_UPDATE();
*/
globals->impersonation_token = INVALID_HANDLE_VALUE;
globals->impersonation_token_sid = NULL;
-}
+}/*}}}*/
static void tsrm_win32_dtor(tsrm_win32_globals *globals)
-{
+{/*{{{*/
shm_pair *ptr;
if (globals->process) {
@@ -89,51 +89,48 @@ static void tsrm_win32_dtor(tsrm_win32_globals *globals)
if (globals->impersonation_token_sid) {
free(globals->impersonation_token_sid);
}
-}
+}/*}}}*/
TSRM_API void tsrm_win32_startup(void)
-{
+{/*{{{*/
#ifdef ZTS
ts_allocate_id(&win32_globals_id, sizeof(tsrm_win32_globals), (ts_allocate_ctor)tsrm_win32_ctor, (ts_allocate_ctor)tsrm_win32_dtor);
#else
tsrm_win32_ctor(&win32_globals);
#endif
-}
+}/*}}}*/
TSRM_API void tsrm_win32_shutdown(void)
-{
+{/*{{{*/
#ifndef ZTS
tsrm_win32_dtor(&win32_globals);
#endif
-}
+}/*}}}*/
-char * tsrm_win32_get_path_sid_key(const char *pathname)
-{
+char * tsrm_win32_get_path_sid_key(const char *pathname, size_t pathname_len, size_t *key_len)
+{/*{{{*/
PSID pSid = TWG(impersonation_token_sid);
- TCHAR *ptcSid = NULL;
+ char *ptcSid = NULL;
char *bucket_key = NULL;
- size_t ptc_sid_len, pathname_len;
-
- pathname_len = strlen(pathname);
+ size_t ptc_sid_len;
if (!pSid) {
- bucket_key = (char *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pathname_len + 1);
- if (!bucket_key) {
- return NULL;
- }
- memcpy(bucket_key, pathname, pathname_len);
- return bucket_key;
+ *key_len = pathname_len;
+ return pathname;
}
if (!ConvertSidToStringSid(pSid, &ptcSid)) {
+ *key_len = 0;
return NULL;
}
ptc_sid_len = strlen(ptcSid);
- bucket_key = (char *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pathname_len + ptc_sid_len + 1);
+ *key_len = pathname_len + ptc_sid_len;
+ bucket_key = (char *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *key_len + 1);
if (!bucket_key) {
LocalFree(ptcSid);
+ *key_len = 0;
return NULL;
}
@@ -142,11 +139,11 @@ char * tsrm_win32_get_path_sid_key(const char *pathname)
LocalFree(ptcSid);
return bucket_key;
-}
+}/*}}}*/
PSID tsrm_win32_get_token_sid(HANDLE hToken)
-{
+{/*{{{*/
DWORD dwLength = 0;
PTOKEN_USER pTokenUser = NULL;
DWORD sid_len;
@@ -193,10 +190,10 @@ Finished:
HeapFree(GetProcessHeap(), 0, (LPVOID)pTokenUser);
}
return NULL;
-}
+}/*}}}*/
TSRM_API int tsrm_win32_access(const char *pathname, int mode)
-{
+{/*{{{*/
time_t t;
HANDLE thread_token = NULL;
PSID token_sid;
@@ -208,6 +205,7 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode)
DWORD sec_desc_length = 0, desired_access = 0, granted_access = 0;
BYTE * psec_desc = NULL;
BOOL fAccess = FALSE;
+
realpath_cache_bucket * bucket = NULL;
char * real_path = NULL;
@@ -295,14 +293,14 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode)
if (CWDG(realpath_cache_size_limit)) {
t = time(0);
- bucket = realpath_cache_lookup(pathname, (int)strlen(pathname), t);
+ bucket = realpath_cache_lookup(pathname, strlen(pathname), t);
if(bucket == NULL && real_path == NULL) {
/* We used the pathname directly. Call tsrm_realpath */
/* so that entry is created in realpath cache */
real_path = (char *)malloc(MAXPATHLEN);
if(tsrm_realpath(pathname, real_path) != NULL) {
pathname = real_path;
- bucket = realpath_cache_lookup(pathname, (int)strlen(pathname), t);
+ bucket = realpath_cache_lookup(pathname, strlen(pathname), t);
PHP_WIN32_IOUTIL_REINIT_W(pathname);
}
}
@@ -396,11 +394,11 @@ Finished:
return 0;
}
}
-}
+}/*}}}*/
static process_pair *process_get(FILE *stream)
-{
+{/*{{{*/
process_pair *ptr;
process_pair *newptr;
@@ -423,10 +421,10 @@ static process_pair *process_get(FILE *stream)
ptr = newptr + TWG(process_size);
TWG(process_size)++;
return ptr;
-}
+}/*}}}*/
-static shm_pair *shm_get(int key, void *addr)
-{
+static shm_pair *shm_get(key_t key, void *addr)
+{/*{{{*/
shm_pair *ptr;
shm_pair *newptr;
@@ -455,24 +453,25 @@ static shm_pair *shm_get(int key, void *addr)
TWG(shm_size)++;
memset(ptr, 0, sizeof(*ptr));
return ptr;
-}
+}/*}}}*/
-static HANDLE dupHandle(HANDLE fh, BOOL inherit) {
+static HANDLE dupHandle(HANDLE fh, BOOL inherit)
+{/*{{{*/
HANDLE copy, self = GetCurrentProcess();
if (!DuplicateHandle(self, fh, self, &copy, 0, inherit, DUPLICATE_SAME_ACCESS|DUPLICATE_CLOSE_SOURCE)) {
return NULL;
}
return copy;
-}
+}/*}}}*/
TSRM_API FILE *popen(const char *command, const char *type)
-{
+{/*{{{*/
return popen_ex(command, type, NULL, NULL);
-}
+}/*}}}*/
TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, char *env)
-{
+{/*{{{*/
FILE *stream = NULL;
int fno, type_len, read, mode;
STARTUPINFOW startup;
@@ -616,10 +615,10 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd,
proc->prochnd = process.hProcess;
proc->stream = stream;
return stream;
-}
+}/*}}}*/
TSRM_API int pclose(FILE *stream)
-{
+{/*{{{*/
DWORD termstat = 0;
process_pair *process;
@@ -636,19 +635,15 @@ TSRM_API int pclose(FILE *stream)
CloseHandle(process->prochnd);
return termstat;
-}
+}/*}}}*/
-TSRM_API int shmget(int key, int size, int flags)
-{
+TSRM_API int shmget(key_t key, size_t size, int flags)
+{/*{{{*/
shm_pair *shm;
char shm_segment[26], shm_info[29];
HANDLE shm_handle, info_handle;
BOOL created = FALSE;
- if (size < 0) {
- return -1;
- }
-
snprintf(shm_segment, sizeof(shm_segment), "TSRM_SHM_SEGMENT:%d", key);
snprintf(shm_info, sizeof(shm_info), "TSRM_SHM_DESCRIPTOR:%d", key);
@@ -657,7 +652,14 @@ TSRM_API int shmget(int key, int size, int flags)
if (!shm_handle && !info_handle) {
if (flags & IPC_CREAT) {
- shm_handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, size, shm_segment);
+#if SIZEOF_SIZE_T == 8
+ DWORD high = size >> 32;
+ DWORD low = (DWORD)size;
+#else
+ DWORD high = 0;
+ DWORD low = size;
+#endif
+ shm_handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, high, low, shm_segment);
info_handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(shm->descriptor), shm_info);
created = TRUE;
}
@@ -716,10 +718,10 @@ TSRM_API int shmget(int key, int size, int flags)
}
return key;
-}
+}/*}}}*/
TSRM_API void *shmat(int key, const void *shmaddr, int flags)
-{
+{/*{{{*/
shm_pair *shm = shm_get(key, NULL);
if (!shm->segment) {
@@ -739,10 +741,10 @@ TSRM_API void *shmat(int key, const void *shmaddr, int flags)
shm->descriptor->shm_nattch++;
return shm->addr;
-}
+}/*}}}*/
TSRM_API int shmdt(const void *shmaddr)
-{
+{/*{{{*/
shm_pair *shm = shm_get(0, (void*)shmaddr);
if (!shm->segment) {
@@ -754,9 +756,10 @@ TSRM_API int shmdt(const void *shmaddr)
shm->descriptor->shm_nattch--;
return UnmapViewOfFile(shm->addr) ? 0 : -1;
-}
+}/*}}}*/
-TSRM_API int shmctl(int key, int cmd, struct shmid_ds *buf) {
+TSRM_API int shmctl(int key, int cmd, struct shmid_ds *buf)
+{/*{{{*/
shm_pair *shm = shm_get(key, NULL);
if (!shm->segment) {
@@ -784,16 +787,16 @@ TSRM_API int shmctl(int key, int cmd, struct shmid_ds *buf) {
default:
return -1;
}
-}
+}/*}}}*/
TSRM_API char *realpath(char *orig_path, char *buffer)
-{
+{/*{{{*/
int ret = GetFullPathName(orig_path, _MAX_PATH, buffer, NULL);
if(!ret || ret > _MAX_PATH) {
return NULL;
}
return buffer;
-}
+}/*}}}*/
#if HAVE_UTIME
static zend_always_inline void UnixTimeToFileTime(time_t t, LPFILETIME pft) /* {{{ */
@@ -851,3 +854,12 @@ 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 ee3f6d1e61..b90791cd59 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) 1997-2017 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 |
@@ -26,9 +26,10 @@
#if HAVE_UTIME
# include <sys/utime.h>
#endif
+#include "win32/ipc.h"
struct ipc_perm {
- int key;
+ key_t key;
unsigned short uid;
unsigned short gid;
unsigned short cuid;
@@ -39,7 +40,7 @@ struct ipc_perm {
struct shmid_ds {
struct ipc_perm shm_perm;
- int shm_segsz;
+ size_t shm_segsz;
time_t shm_atime;
time_t shm_dtime;
time_t shm_ctime;
@@ -94,7 +95,7 @@ TSRMLS_CACHE_EXTERN()
#define SHM_RND FILE_MAP_WRITE
#define SHM_REMAP FILE_MAP_COPY
-char * tsrm_win32_get_path_sid_key(const char *pathname );
+char * tsrm_win32_get_path_sid_key(const char *pathname, size_t pathname_len, size_t *key_len);
TSRM_API void tsrm_win32_startup(void);
TSRM_API void tsrm_win32_shutdown(void);
@@ -105,10 +106,19 @@ TSRM_API int pclose(FILE *stream);
TSRM_API int tsrm_win32_access(const char *pathname, int mode);
TSRM_API int win32_utime(const char *filename, struct utimbuf *buf);
-TSRM_API int shmget(int key, int size, int flags);
+TSRM_API int shmget(key_t key, size_t size, int flags);
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);
TSRM_API char *realpath(char *orig_path, char *buffer);
#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */