MemoryMappedFile.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma once
  2. #include <string>
  3. #include "File.h"
  4. #include <map>
  5. #include "os/Mutex.h"
  6. namespace il2cpp
  7. {
  8. namespace os
  9. {
  10. // This enum must match the same enum in the Mono code, as it is used on the icall boundary.
  11. enum MemoryMappedFileAccess
  12. {
  13. MMAP_FILE_ACCESS_READ_WRITE = 0,
  14. MMAP_FILE_ACCESS_READ = 1,
  15. MMAP_FILE_ACCESS_WRITE = 2,
  16. MMAP_FILE_ACCESS_COPY_ON_WRITE = 3,
  17. MMAP_FILE_ACCESS_READ_EXECUTE = 4,
  18. MMAP_FILE_ACCESS_READ_WRITE_EXECUTE = 5,
  19. };
  20. // This enum must match the same enum in the Mono code, as it is used on the icall boundary.
  21. enum MemoryMappedFileError
  22. {
  23. NO_MEMORY_MAPPED_FILE_ERROR = 0,
  24. BAD_CAPACITY_FOR_FILE_BACKED,
  25. CAPACITY_SMALLER_THAN_FILE_SIZE,
  26. FILE_NOT_FOUND,
  27. FILE_ALREADY_EXISTS,
  28. PATH_TOO_LONG,
  29. COULD_NOT_OPEN,
  30. CAPACITY_MUST_BE_POSITIVE,
  31. INVALID_FILE_MODE,
  32. COULD_NOT_MAP_MEMORY,
  33. ACCESS_DENIED,
  34. CAPACITY_LARGER_THAN_LOGICAL_ADDRESS_SPACE
  35. };
  36. // This enum must match the same enum in the Mono code, as it is used on the icall boundary.
  37. enum MemoryMappedFileMode
  38. {
  39. FILE_MODE_CREATE_NEW = 1,
  40. FILE_MODE_CREATE = 2,
  41. FILE_MODE_OPEN = 3,
  42. FILE_MODE_OPEN_OR_CREATE = 4,
  43. FILE_MODE_TRUNCATE = 5,
  44. FILE_MODE_APPEND = 6,
  45. };
  46. class MemoryMappedFile
  47. {
  48. public:
  49. typedef void* MemoryMappedFileHandle;
  50. static FileHandle* Create(FileHandle* file, const char* mapName, int32_t mode, int64_t *capacity, MemoryMappedFileAccess access, int32_t options, MemoryMappedFileError* error);
  51. static MemoryMappedFileHandle View(FileHandle* mappedFileHandle, int64_t* length, int64_t offset, MemoryMappedFileAccess access, int64_t* actualOffset, MemoryMappedFileError* error);
  52. static void Flush(MemoryMappedFileHandle memoryMappedFileData, int64_t length);
  53. static bool UnmapView(MemoryMappedFileHandle memoryMappedFileData, int64_t length);
  54. static bool Close(FileHandle* file);
  55. static void ConfigureHandleInheritability(FileHandle* file, bool inheritability);
  56. static bool OwnsDuplicatedFileHandle(FileHandle* file);
  57. };
  58. }
  59. }