MemoryObject.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //===- MemoryObject.h - Abstract memory interface ---------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef LLVM_SUPPORT_MEMORYOBJECT_H
  10. #define LLVM_SUPPORT_MEMORYOBJECT_H
  11. #include "llvm/Support/DataTypes.h"
  12. namespace llvm {
  13. /// Interface to data which might be streamed. Streamability has 2 important
  14. /// implications/restrictions. First, the data might not yet exist in memory
  15. /// when the request is made. This just means that readByte/readBytes might have
  16. /// to block or do some work to get it. More significantly, the exact size of
  17. /// the object might not be known until it has all been fetched. This means that
  18. /// to return the right result, getExtent must also wait for all the data to
  19. /// arrive; therefore it should not be called on objects which are actually
  20. /// streamed (this would defeat the purpose of streaming). Instead,
  21. /// isValidAddress can be used to test addresses without knowing the exact size
  22. /// of the stream. Finally, getPointer can be used instead of readBytes to avoid
  23. /// extra copying.
  24. class MemoryObject {
  25. public:
  26. virtual ~MemoryObject();
  27. /// Returns the size of the region in bytes. (The region is contiguous, so
  28. /// the highest valid address of the region is getExtent() - 1).
  29. ///
  30. /// @result - The size of the region.
  31. virtual uint64_t getExtent() const = 0;
  32. /// Tries to read a contiguous range of bytes from the region, up to the end
  33. /// of the region.
  34. ///
  35. /// @param Buf - A pointer to a buffer to be filled in. Must be non-NULL
  36. /// and large enough to hold size bytes.
  37. /// @param Size - The number of bytes to copy.
  38. /// @param Address - The address of the first byte, in the same space as
  39. /// getBase().
  40. /// @result - The number of bytes read.
  41. virtual uint64_t readBytes(uint8_t *Buf, uint64_t Size,
  42. uint64_t Address) const = 0;
  43. /// Ensures that the requested data is in memory, and returns a pointer to it.
  44. /// More efficient than using readBytes if the data is already in memory. May
  45. /// block until (address - base + size) bytes have been read
  46. /// @param address - address of the byte, in the same space as getBase()
  47. /// @param size - amount of data that must be available on return
  48. /// @result - valid pointer to the requested data
  49. virtual const uint8_t *getPointer(uint64_t address, uint64_t size) const = 0;
  50. /// Returns true if the address is within the object (i.e. between base and
  51. /// base + extent - 1 inclusive). May block until (address - base) bytes have
  52. /// been read
  53. /// @param address - address of the byte, in the same space as getBase()
  54. /// @result - true if the address may be read with readByte()
  55. virtual bool isValidAddress(uint64_t address) const = 0;
  56. };
  57. }
  58. #endif