mem_map_fuchsia.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //===-- mem_map_fuchsia.h ---------------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef SCUDO_MEM_MAP_FUCHSIA_H_
  9. #define SCUDO_MEM_MAP_FUCHSIA_H_
  10. #include "mem_map_base.h"
  11. #if SCUDO_FUCHSIA
  12. #include <stdint.h>
  13. #error #include <zircon/types.h>
  14. namespace scudo {
  15. class MemMapFuchsia final : public MemMapBase<MemMapFuchsia> {
  16. public:
  17. constexpr MemMapFuchsia() = default;
  18. // Impls for base functions.
  19. bool mapImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);
  20. void unmapImpl(uptr Addr, uptr Size);
  21. bool remapImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);
  22. void setMemoryPermissionImpl(uptr Addr, uptr Size, uptr Flags);
  23. void releasePagesToOSImpl(uptr From, uptr Size) {
  24. return releaseAndZeroPagesToOSImpl(From, Size);
  25. }
  26. void releaseAndZeroPagesToOSImpl(uptr From, uptr Size);
  27. uptr getBaseImpl() { return WindowBase; }
  28. uptr getCapacityImpl() { return WindowSize; }
  29. private:
  30. friend class ReservedMemoryFuchsia;
  31. // Used by ReservedMemoryFuchsia::dispatch.
  32. MemMapFuchsia(uptr Base, uptr Capacity);
  33. // Virtual memory address corresponding to VMO offset 0.
  34. uptr MapAddr = 0;
  35. // Virtual memory base address and size of the VMO subrange that is still in
  36. // use. unmapImpl() can shrink this range, either at the beginning or at the
  37. // end.
  38. uptr WindowBase = 0;
  39. uptr WindowSize = 0;
  40. zx_handle_t Vmo = ZX_HANDLE_INVALID;
  41. };
  42. class ReservedMemoryFuchsia final
  43. : public ReservedMemory<ReservedMemoryFuchsia, MemMapFuchsia> {
  44. public:
  45. constexpr ReservedMemoryFuchsia() = default;
  46. bool createImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);
  47. void releaseImpl();
  48. MemMapT dispatchImpl(uptr Addr, uptr Size);
  49. uptr getBaseImpl() { return Base; }
  50. uptr getCapacityImpl() { return Capacity; }
  51. private:
  52. uptr Base = 0;
  53. uptr Capacity = 0;
  54. };
  55. } // namespace scudo
  56. #endif // SCUDO_FUCHSIA
  57. #endif // SCUDO_MEM_MAP_FUCHSIA_H_