php_stream_mmap.h 3.3 KB

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