php_stream_mmap.h 3.1 KB

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