mem_map_linux.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //===-- mem_map_linux.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_LINUX_H_
  9. #define SCUDO_MEM_MAP_LINUX_H_
  10. #include "platform.h"
  11. #if SCUDO_LINUX
  12. #include "common.h"
  13. #include "mem_map_base.h"
  14. namespace scudo {
  15. class MemMapLinux final : public MemMapBase<MemMapLinux> {
  16. public:
  17. constexpr MemMapLinux() = default;
  18. MemMapLinux(uptr Base, uptr Capacity)
  19. : MapBase(Base), MapCapacity(Capacity) {}
  20. // Impls for base functions.
  21. bool mapImpl(uptr Addr, uptr Size, const char *Name, uptr Flags = 0);
  22. void unmapImpl(uptr Addr, uptr Size);
  23. bool remapImpl(uptr Addr, uptr Size, const char *Name, uptr Flags = 0);
  24. void setMemoryPermissionImpl(uptr Addr, uptr Size, uptr Flags);
  25. void releasePagesToOSImpl(uptr From, uptr Size) {
  26. return releaseAndZeroPagesToOSImpl(From, Size);
  27. }
  28. void releaseAndZeroPagesToOSImpl(uptr From, uptr Size);
  29. uptr getBaseImpl() { return MapBase; }
  30. uptr getCapacityImpl() { return MapCapacity; }
  31. private:
  32. uptr MapBase = 0;
  33. uptr MapCapacity = 0;
  34. };
  35. // This will be deprecated when every allocator has been supported by each
  36. // platform's `MemMap` implementation.
  37. class ReservedMemoryLinux final
  38. : public ReservedMemory<ReservedMemoryLinux, MemMapLinux> {
  39. public:
  40. // The following two are the Impls for function in `MemMapBase`.
  41. uptr getBaseImpl() { return MapBase; }
  42. uptr getCapacityImpl() { return MapCapacity; }
  43. // These threes are specific to `ReservedMemory`.
  44. bool createImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);
  45. void releaseImpl();
  46. MemMapT dispatchImpl(uptr Addr, uptr Size);
  47. private:
  48. uptr MapBase = 0;
  49. uptr MapCapacity = 0;
  50. };
  51. } // namespace scudo
  52. #endif // SCUDO_LINUX
  53. #endif // SCUDO_MEM_MAP_LINUX_H_