1 /* 2 +----------------------------------------------------------------------+ 3 | PHP Version 7 | 4 +----------------------------------------------------------------------+ 5 | Copyright (c) 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 | Author: Wez Furlong <wez@thebrainroom.com> | 16 +----------------------------------------------------------------------+ 17 */ 18 19 /* Memory Mapping interface for streams. 20 * The intention is to provide a uniform interface over the most common 21 * operations that are used within PHP itself, rather than a complete 22 * API for all memory mapping needs. 23 * 24 * ATM, we support only mmap(), but win32 memory mapping support will 25 * follow soon. 26 * */ 27 28 typedef enum { 29 /* Does the stream support mmap ? */ 30 PHP_STREAM_MMAP_SUPPORTED, 31 /* Request a range and offset to be mapped; 32 * while mapped, you MUST NOT use any read/write functions 33 * on the stream (win9x compatibility) */ 34 PHP_STREAM_MMAP_MAP_RANGE, 35 /* Unmap the last range that was mapped for the stream */ 36 PHP_STREAM_MMAP_UNMAP 37 } php_stream_mmap_operation_t; 38 39 typedef enum { 40 PHP_STREAM_MAP_MODE_READONLY, 41 PHP_STREAM_MAP_MODE_READWRITE, 42 PHP_STREAM_MAP_MODE_SHARED_READONLY, 43 PHP_STREAM_MAP_MODE_SHARED_READWRITE 44 } php_stream_mmap_access_t; 45 46 typedef struct { 47 /* requested offset and length. 48 * If length is 0, the whole file is mapped */ 49 size_t offset; 50 size_t length; 51 52 php_stream_mmap_access_t mode; 53 54 /* returned mapped address */ 55 char *mapped; 56 57 } php_stream_mmap_range; 58 59 #define PHP_STREAM_MMAP_ALL 0 60 61 #define PHP_STREAM_MMAP_MAX (512 * 1024 * 1024) 62 63 #define php_stream_mmap_supported(stream) (_php_stream_set_option((stream), PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_SUPPORTED, NULL) == 0 ? 1 : 0) 64 65 /* Returns 1 if the stream in its current state can be memory mapped, 66 * 0 otherwise */ 67 #define php_stream_mmap_possible(stream) (!php_stream_is_filtered((stream)) && php_stream_mmap_supported((stream))) 68 69 BEGIN_EXTERN_C() 70 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); 71 #define php_stream_mmap_range(stream, offset, length, mode, mapped_len) _php_stream_mmap_range((stream), (offset), (length), (mode), (mapped_len)) 72 73 /* un-maps the last mapped range */ 74 PHPAPI int _php_stream_mmap_unmap(php_stream *stream); 75 #define php_stream_mmap_unmap(stream) _php_stream_mmap_unmap((stream)) 76 77 PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, zend_off_t readden); 78 #define php_stream_mmap_unmap_ex(stream, readden) _php_stream_mmap_unmap_ex((stream), (readden)) 79 END_EXTERN_C() 80