Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62115 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51849 invoked from network); 10 Aug 2012 19:27:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Aug 2012 19:27:36 -0000 Authentication-Results: pb1.pair.com smtp.mail=eantoranz@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=eantoranz@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: eantoranz@gmail.com X-Host-Fingerprint: 209.85.215.42 mail-lpp01m010-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:37509] helo=mail-lpp01m010-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 69/10-00812-7A065205 for ; Fri, 10 Aug 2012 15:27:36 -0400 Received: by lahl5 with SMTP id l5so1085266lah.29 for ; Fri, 10 Aug 2012 12:27:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=ex5FC+FtS5J+vbL7NsAOFJDPpvUKHU2VWyr/Cdwa/Do=; b=Oh4RSt7YHwXUGyrN5tMap6D8iFQPKoamBtcSyMo+YE/t5EtH+Fb1Gn6czALAOg0d1/ GMj9p3kYeVJKjfmE4iT113z9cjM1PHTpYy4xJaeGbXj64DTBM6MpgYdHnBKjJkz+15OO mRmvXlsjdfjx1aKGM0hUPzsj5f6YMSI+UhSmbtF2plyRh+pOtpN8BT2LDuSD+q+qdp8E na5y8UhZxg5VN02g+ItiHwAUPtjZeG0RWhxeX3xiQiAiNbyfHxFXAljy2R7X+RM78IiP 0ockcFEj6psQaHLaS8BFTHmJZO+HlcrpSJRDVePZKCZi+fPw+B4xgmtaatqwIoibRSka P+4Q== MIME-Version: 1.0 Received: by 10.112.36.130 with SMTP id q2mr2787585lbj.44.1344626852463; Fri, 10 Aug 2012 12:27:32 -0700 (PDT) Received: by 10.112.27.73 with HTTP; Fri, 10 Aug 2012 12:27:32 -0700 (PDT) Date: Fri, 10 Aug 2012 14:27:32 -0500 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: How to implement a custom php_stream? From: eantoranz@gmail.com (Edmundo Carmona) Hi! I'm in the process of implementing a custom php_stream that has to do some things to meet our demands. I have already gotten it to (mostly) work (php 5.2.19, just in case.... I will move to later versions when we move our PHP codebase to 5.3 and 5.4 so please bear with me... probably the issue is the same for later API versions) but I'm hitting a SIGSEGV that I bet is happening because I'm short-circuiting the php_stream process and probably skipping some required things that are making php explote. Program received signal SIGSEGV, Segmentation fault. zend_mm_remove_from_free_list (heap=0x84711f8, mm_block=0x88dd7bc) at /home/antoranz/Descargas/php/php-5.2.17/Zend/zend_alloc.c:837 837 if (UNEXPECTED(prev->next_free_block != mm_block) || UNEXPECTED(next->prev_free_block != mm_block)) { (gdb) backtrace #0 zend_mm_remove_from_free_list (heap=0x84711f8, mm_block=0x88dd7bc) at /home/antoranz/Descargas/php/php-5.2.17/Zend/zend_alloc.c:837 #1 0x0828bbcb in _zend_mm_free_int (heap=0x84711f8, p=0x88dd7c4) at /home/antoranz/Descargas/php/php-5.2.17/Zend/zend_alloc.c:1979 #2 0x0827b5a6 in php_stdiop_close (stream=0x88deca0, close_handle=0) at /home/antoranz/Descargas/php/php-5.2.17/main/streams/plain_wrapper.c:432 #3 0x082780fa in _php_stream_free (stream=0x88deca0, close_options=11) at /home/antoranz/Descargas/php/php-5.2.17/main/streams/streams.c:283 #4 0x08278529 in stream_resource_regular_dtor (rsrc=0x88ded24) at /home/antoranz/Descargas/php/php-5.2.17/main/streams/streams.c:1426 #5 0x082b2acc in list_entry_destructor (ptr=0x88ded24) at /home/antoranz/Descargas/php/php-5.2.17/Zend/zend_list.c:184 #6 0x082afdf5 in zend_hash_apply_deleter (ht=0x846fec0, p=0x88dec74) at /home/antoranz/Descargas/php/php-5.2.17/Zend/zend_hash.c:611 #7 0x082b11f7 in zend_hash_graceful_reverse_destroy (ht=0x846fec0) at /home/antoranz/Descargas/php/php-5.2.17/Zend/zend_hash.c:646 #8 0x082a67fd in zend_deactivate () at /home/antoranz/Descargas/php/php-5.2.17/Zend/zend.c:866 #9 0x08263a56 in php_request_shutdown (dummy=0x0) at /home/antoranz/Descargas/php/php-5.2.17/main/main.c:1504 #10 0x0808b0f7 in main (argc=2, argv=0xbffff214) at /home/antoranz/Descargas/php/php-5.2.17/sapi/cli/php_cli.c:1346 What I'm doing at the moment is: - Detour in the beginning of _php_stream_fopen_with_path to see if the file requested can be handled by my php_stream. If it can, I just create a struct our_structure (which has a struct php_stream member) with emalloc(), I populate the our_structure instance with whatever we need, I create a new struct php_stream_ops instance (again, with emalloc), set its read, write, seek, close, flush prototypes to our custom functions for that, set the php_stream's ops of our our_structure to this new ops instance.... if everything is OK, I just return this php_stream from _php_stream_fopen_with_path _without_ doing any of its later processing. Under some conditions (for example, when most of the scripts I need to run are handled by our custom php_stream) it works, no complains from php.... in this case it's crashing because one script can't be found (which means that it's following PHP's normal flow to find a php script). So.... long story short: what things do I have to keep in mind when I create a new kind of php_stream? Perhaps there's a safer way to do this? Thanks in advance.