/* 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();
#elif defined(PTHREADS)
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) {
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));
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));
}
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;
* changes to the structure as we read it.
*/
TSRM_SAFE_RETURN_RSRC(thread_resources->storage, id, thread_resources->count);
-}
+}/*}}}*/
/* 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;
free(thread_resources);
thread_resources = next;
}
-}
+}/*}}}*/
void *tsrm_set_interpreter_context(void *new_ctx)
-{
+{/*{{{*/
tsrm_tls_entry *current;
current = tsrm_tls_get();
/* 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;
/* 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();
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();
}
}
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);
tsrm_mutex_unlock(tsmm_mutex);
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Successfully freed resource id %d", id));
-}
+}/*}}}*/
/* Obtain the current thread id */
TSRM_API THREAD_T tsrm_thread_id(void)
-{
+{/*{{{*/
#ifdef TSRM_WIN32
return GetCurrentThreadId();
#elif defined(GNUPTH)
#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));
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);
#ifdef THR_DEBUG
printf("Mutex freed thread: %d\n",mythreadid());
#endif
-}
+}/*}}}*/
/*
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);
return acquire_sem(mutexp->sem);
return 0;
#endif
-}
+}/*}}}*/
/*
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);
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
#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;
-}
+}/*}}}*/
/*
#if TSRM_DEBUG
int tsrm_error(int level, const char *format, ...)
-{
+{/*{{{*/
if (level<=tsrm_error_level) {
va_list args;
int size;
} else {
return 0;
}
-}
+}/*}}}*/
#endif
void tsrm_error_set(int level, char *debug_filename)
-{
+{/*{{{*/
tsrm_error_level = level;
#if TSRM_DEBUG
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
+ */
#endif
static void tsrm_win32_ctor(tsrm_win32_globals *globals)
-{
+{/*{{{*/
#ifdef ZTS
TSRMLS_CACHE_UPDATE();
#endif
*/
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) {
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, size_t pathname_len, size_t *key_len)
-{
+{/*{{{*/
PSID pSid = TWG(impersonation_token_sid);
char *ptcSid = NULL;
char *bucket_key = NULL;
LocalFree(ptcSid);
return bucket_key;
-}
+}/*}}}*/
PSID tsrm_win32_get_token_sid(HANDLE hToken)
-{
+{/*{{{*/
DWORD dwLength = 0;
PTOKEN_USER pTokenUser = NULL;
DWORD sid_len;
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;
return 0;
}
}
-}
+}/*}}}*/
static process_pair *process_get(FILE *stream)
-{
+{/*{{{*/
process_pair *ptr;
process_pair *newptr;
ptr = newptr + TWG(process_size);
TWG(process_size)++;
return ptr;
-}
+}/*}}}*/
static shm_pair *shm_get(key_t key, void *addr)
-{
+{/*{{{*/
shm_pair *ptr;
shm_pair *newptr;
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, ©, 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;
proc->prochnd = process.hProcess;
proc->stream = stream;
return stream;
-}
+}/*}}}*/
TSRM_API int pclose(FILE *stream)
-{
+{/*{{{*/
DWORD termstat = 0;
process_pair *process;
CloseHandle(process->prochnd);
return termstat;
-}
+}/*}}}*/
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;
}
return key;
-}
+}/*}}}*/
TSRM_API void *shmat(int key, const void *shmaddr, int flags)
-{
+{/*{{{*/
shm_pair *shm = shm_get(key, NULL);
if (!shm->segment) {
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) {
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) {
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) /* {{{ */
/* }}} */
#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
+ */