On Thu, 26 Nov 2015 12:22:23 +0500
Ruslan Osmanov <rrosma...@gmail.com> wrote:

> On Wed, 25 Nov 2015 22:45:29 +0100
> Ángel González <keis...@gmail.com> wrote:
> 
> > On 25/11/15 20:25, Ruslan Osmanov wrote:
> > > I'll try to explain the problem.
> > >
> > > I have a function(let's call it `execF`), which is passed to a
> > > library(libeio) as a callback. This function is invoked afterwards
> > > by the library in separate thread.
> > >
> > > The function is calling Zend API, particularly ZVAL_STRINGL(). The
> > > Zend API uses TSRMLS_CACHE internally. For instance,
> > > ZVAL_STRINGL() allocates zend_string which implies using AG()
> > > macro. The AG() macro relies on TSRMLS_CACHE.
> > >
> > > Since TSRMLS_CACHE becomes invalid in new thread, the AG() macro
> > > (as well as other macros relying on TSRMLS_CACHE) fails with
> > > segmentation fault.
> > Why are you allocating a string? Are you expecting to later use it
> > on the php request?
> > What's the goal of your extension? I suspect you may have an
> > earlier misstep.
> 
> I'm allocating a string for zend_fcall_info.function_name:
> https://goo.gl/MYoJcw (just like zend_call_method). Called by
> php_eio_custom_execute().
> 
> Well, I can pre-allocate zend_string for the callback. Then a few
> lines further I'm trying to fetch EG(function_table), which
> eventually refers to TSRMLS_CACHE. Since the latter is invalid, I
> catch a segmentation fault, again.
> 
> So I'm asking how do I save the context for a thread created by libeio
> library.
> 
> The flow looks like the following:
> 
> 1. User passes a callable to eio_custom()
> 2. The callable is saved as libeio user custom data(void*):
> eio_custom(php_eio_custom_execute, pri, php_eio_res_cb_custom,
> eio_cb); 3. User calls eio_event_loop()
> 4. Libeio invokes php_eio_custom_execute() *in separate thread*
> 5. php_eio_custom_execute() unsuccessfully tries to use Zend API

By the way, TSRMLS_SET_CTX and TSRMLS_FETCH_FROM_CTX macros look redundant.
They're making just a pointer assignment which is scarcely useful in context of
thread-local variable in global scope.

--
Ruslan Osmanov

Attachment: signature.asc
Description: PGP signature

Reply via email to