Coverage Report

Created: 2025-06-13 06:43

/src/php-src/main/streams/mmap.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
  +----------------------------------------------------------------------+
3
  | Copyright (c) The PHP Group                                          |
4
  +----------------------------------------------------------------------+
5
  | This source file is subject to version 3.01 of the PHP license,      |
6
  | that is bundled with this package in the file LICENSE, and is        |
7
  | available through the world-wide-web at the following url:           |
8
  | https://www.php.net/license/3_01.txt                                 |
9
  | If you did not receive a copy of the PHP license and are unable to   |
10
  | obtain it through the world-wide-web, please send a note to          |
11
  | license@php.net so we can mail you a copy immediately.               |
12
  +----------------------------------------------------------------------+
13
  | Author: Wez Furlong <wez@thebrainroom.com>                           |
14
  +----------------------------------------------------------------------+
15
*/
16
17
/* Memory Mapping interface for streams */
18
#include "php.h"
19
#include "php_streams_int.h"
20
21
PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t length, php_stream_mmap_access_t mode, size_t *mapped_len)
22
0
{
23
0
  php_stream_mmap_range range;
24
25
0
  range.offset = offset;
26
0
  range.length = length;
27
0
  range.mode = mode;
28
0
  range.mapped = NULL;
29
30
0
  if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_MAP_RANGE, &range)) {
31
0
    if (mapped_len) {
32
0
      *mapped_len = range.length;
33
0
    }
34
0
    return range.mapped;
35
0
  }
36
0
  return NULL;
37
0
}
38
39
PHPAPI int _php_stream_mmap_unmap(php_stream *stream)
40
0
{
41
0
  return php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_UNMAP, NULL) == PHP_STREAM_OPTION_RETURN_OK;
42
0
}
43
44
PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, zend_off_t readden)
45
0
{
46
0
  int ret = 1;
47
48
0
  if (php_stream_seek(stream, readden, SEEK_CUR) != 0) {
49
0
    ret = 0;
50
0
  }
51
0
  if (php_stream_mmap_unmap(stream) == 0) {
52
0
    ret = 0;
53
0
  }
54
55
0
  return ret;
56
0
}