MemoryObject.cpp 946 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //===- MemoryObject.cpp - Abstract memory interface -----------------------===//
  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. #include "llvm/Support/MemoryObject.h"
  10. using namespace llvm;
  11. MemoryObject::~MemoryObject() {
  12. }
  13. int MemoryObject::readBytes(uint64_t address,
  14. uint64_t size,
  15. uint8_t* buf,
  16. uint64_t* copied) const {
  17. uint64_t current = address;
  18. uint64_t limit = getBase() + getExtent();
  19. if (current + size > limit)
  20. return -1;
  21. while (current - address < size) {
  22. if (readByte(current, &buf[(current - address)]))
  23. return -1;
  24. current++;
  25. }
  26. if (copied)
  27. *copied = current - address;
  28. return 0;
  29. }