PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/opcache - shared_alloc_mmap.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 16 20 80.0 %
Date: 2014-07-21 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend OPcache                                                         |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2014 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Zeev Suraski <zeev@zend.com>                                |
      17             :    |          Stanislav Malyshev <stas@zend.com>                          |
      18             :    |          Dmitry Stogov <dmitry@zend.com>                             |
      19             :    +----------------------------------------------------------------------+
      20             : */
      21             : 
      22             : #include "zend_shared_alloc.h"
      23             : 
      24             : #ifdef USE_MMAP
      25             : 
      26             : #include <sys/types.h>
      27             : #include <sys/stat.h>
      28             : #include <stdio.h>
      29             : #include <stdlib.h>
      30             : #include <sys/mman.h>
      31             : 
      32             : #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
      33             : # define MAP_ANONYMOUS MAP_ANON
      34             : #endif
      35             : 
      36         368 : static int create_segments(size_t requested_size, zend_shared_segment ***shared_segments_p, int *shared_segments_count, char **error_in)
      37             : {
      38             :         zend_shared_segment *shared_segment;
      39             : 
      40         368 :         *shared_segments_count = 1;
      41         368 :         *shared_segments_p = (zend_shared_segment **) calloc(1, sizeof(zend_shared_segment) + sizeof(void *));
      42         368 :         if (!*shared_segments_p) {
      43           0 :                 *error_in = "calloc";
      44           0 :                 return ALLOC_FAILURE;
      45             :         }
      46         368 :         shared_segment = (zend_shared_segment *)((char *)(*shared_segments_p) + sizeof(void *));
      47         368 :         (*shared_segments_p)[0] = shared_segment;
      48             : 
      49         368 :         shared_segment->p = mmap(0, requested_size, PROT_READ | PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
      50         368 :         if (shared_segment->p == MAP_FAILED) {
      51           0 :                 *error_in = "mmap";
      52           0 :                 return ALLOC_FAILURE;
      53             :         }
      54             : 
      55         368 :         shared_segment->pos = 0;
      56         368 :         shared_segment->size = requested_size;
      57             : 
      58         368 :         return ALLOC_SUCCESS;
      59             : }
      60             : 
      61         368 : static int detach_segment(zend_shared_segment *shared_segment)
      62             : {
      63         368 :         munmap(shared_segment->p, shared_segment->size);
      64         368 :         return 0;
      65             : }
      66             : 
      67        1472 : static size_t segment_type_size(void)
      68             : {
      69        1472 :         return sizeof(zend_shared_segment);
      70             : }
      71             : 
      72             : zend_shared_memory_handlers zend_alloc_mmap_handlers = {
      73             :         create_segments,
      74             :         detach_segment,
      75             :         segment_type_size
      76             : };
      77             : 
      78             : #endif /* USE_MMAP */

Generated by: LCOV version 1.10

Generated at Tue, 22 Jul 2014 01:33:14 +0000 (3 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.