mmap.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /* Copyright (c) 2003-2004, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #ifndef TOR_MMAP_H
  6. #define TOR_MMAP_H
  7. #include "lib/cc/compat_compiler.h"
  8. #include <stddef.h>
  9. #ifdef _WIN32
  10. #include <windef.h>
  11. #endif
  12. /** Represents an mmaped file. Allocated via tor_mmap_file; freed with
  13. * tor_munmap_file. */
  14. typedef struct tor_mmap_t {
  15. const char *data; /**< Mapping of the file's contents. */
  16. size_t size; /**< Size of the file. */
  17. /* None of the fields below should be accessed from outside compat.c */
  18. #ifdef HAVE_MMAP
  19. size_t mapping_size; /**< Size of the actual mapping. (This is this file
  20. * size, rounded up to the nearest page.) */
  21. #elif defined _WIN32
  22. HANDLE mmap_handle;
  23. #endif /* defined(HAVE_MMAP) || ... */
  24. } tor_mmap_t;
  25. tor_mmap_t *tor_mmap_file(const char *filename) ATTR_NONNULL((1));
  26. int tor_munmap_file(tor_mmap_t *handle) ATTR_NONNULL((1));
  27. #endif