llvm.org GIT mirror llvm / 49a6a8d
Remove the Copied parameter from MemoryObject::readBytes. There was exactly one caller using this API right, the others were relying on specific behavior of the default implementation. Since it's too hard to use it right just remove it and standardize on the default behavior. Defines away PR16132. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182636 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 7 years ago
14 changed file(s) with 35 addition(s) and 61 deletion(s). Raw diff Collapse all Expand all
243243
244244 uint32_t getWord(size_t pos) {
245245 uint8_t buf[4] = { 0xFF, 0xFF, 0xFF, 0xFF };
246 BitStream->getBitcodeBytes().readBytes(pos, sizeof(buf), buf, NULL);
246 BitStream->getBitcodeBytes().readBytes(pos, sizeof(buf), buf);
247247 return *reinterpret_cast(buf);
248248 }
249249
365365 // Read the next word from the stream.
366366 uint8_t Array[sizeof(word_t)] = {0};
367367
368 BitStream->getBitcodeBytes().readBytes(NextChar, sizeof(Array),
369 Array, NULL);
368 BitStream->getBitcodeBytes().readBytes(NextChar, sizeof(Array), Array);
370369
371370 // Handle big-endian byte-swapping if necessary.
372371 support::detail::packed_endian_specific_integral
4141 /// @param ptr - A pointer to a byte to be filled in. Must be non-NULL.
4242 /// @result - 0 if successful; -1 if not. Failure may be due to a
4343 /// bounds violation or an implementation-specific error.
44 virtual int readByte(uint64_t address, uint8_t* ptr) const = 0;
44 virtual int readByte(uint64_t address, uint8_t *ptr) const = 0;
4545
4646 /// readBytes - Tries to read a contiguous range of bytes from the
4747 /// region, up to the end of the region.
5050 ///
5151 /// @param address - The address of the first byte, in the same space as
5252 /// getBase().
53 /// @param size - The maximum number of bytes to copy.
53 /// @param size - The number of bytes to copy.
5454 /// @param buf - A pointer to a buffer to be filled in. Must be non-NULL
5555 /// and large enough to hold size bytes.
56 /// @param copied - A pointer to a nunber that is filled in with the number
57 /// of bytes actually read. May be NULL.
5856 /// @result - 0 if successful; -1 if not. Failure may be due to a
5957 /// bounds violation or an implementation-specific error.
60 virtual int readBytes(uint64_t address,
61 uint64_t size,
62 uint8_t* buf,
63 uint64_t* copied) const;
58 virtual int readBytes(uint64_t address, uint64_t size, uint8_t *buf) const;
6459 };
6560
6661 }
3737 /// getBase - Returns the lowest valid address in the region.
3838 ///
3939 /// @result - The lowest valid address.
40 virtual uint64_t getBase() const = 0;
40 virtual uint64_t getBase() const LLVM_OVERRIDE = 0;
4141
4242 /// getExtent - Returns the size of the region in bytes. (The region is
4343 /// contiguous, so the highest valid address of the region
4545 /// May block until all bytes in the stream have been read
4646 ///
4747 /// @result - The size of the region.
48 virtual uint64_t getExtent() const = 0;
48 virtual uint64_t getExtent() const LLVM_OVERRIDE = 0;
4949
5050 /// readByte - Tries to read a single byte from the region.
5151 /// May block until (address - base) bytes have been read
5353 /// @param ptr - A pointer to a byte to be filled in. Must be non-NULL.
5454 /// @result - 0 if successful; -1 if not. Failure may be due to a
5555 /// bounds violation or an implementation-specific error.
56 virtual int readByte(uint64_t address, uint8_t* ptr) const = 0;
56 virtual int readByte(uint64_t address, uint8_t *ptr) const LLVM_OVERRIDE = 0;
5757
5858 /// readBytes - Tries to read a contiguous range of bytes from the
5959 /// region, up to the end of the region.
6464 ///
6565 /// @param address - The address of the first byte, in the same space as
6666 /// getBase().
67 /// @param size - The maximum number of bytes to copy.
67 /// @param size - The number of bytes to copy.
6868 /// @param buf - A pointer to a buffer to be filled in. Must be non-NULL
6969 /// and large enough to hold size bytes.
70 /// @param copied - A pointer to a nunber that is filled in with the number
71 /// of bytes actually read. May be NULL.
7270 /// @result - 0 if successful; -1 if not. Failure may be due to a
7371 /// bounds violation or an implementation-specific error.
7472 virtual int readBytes(uint64_t address,
7573 uint64_t size,
76 uint8_t* buf,
77 uint64_t* copied) const = 0;
74 uint8_t *buf) const LLVM_OVERRIDE = 0;
7875
7976 /// getPointer - Ensures that the requested data is in memory, and returns
8077 /// A pointer to it. More efficient than using readBytes if the
109106 StreamingMemoryObject(DataStreamer *streamer);
110107 virtual uint64_t getBase() const LLVM_OVERRIDE { return 0; }
111108 virtual uint64_t getExtent() const LLVM_OVERRIDE;
112 virtual int readByte(uint64_t address, uint8_t* ptr) const LLVM_OVERRIDE;
109 virtual int readByte(uint64_t address, uint8_t *ptr) const LLVM_OVERRIDE;
113110 virtual int readBytes(uint64_t address,
114111 uint64_t size,
115 uint8_t* buf,
116 uint64_t* copied) const LLVM_OVERRIDE;
112 uint8_t *buf) const LLVM_OVERRIDE;
117113 virtual const uint8_t *getPointer(uint64_t address,
118114 uint64_t size) const LLVM_OVERRIDE {
119115 // This could be fixed by ensuring the bytes are fetched and making a copy,
1515 #define LLVM_SUPPORT_STRINGREFMEMORYOBJECT_H
1616
1717 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/Compiler.h"
1819 #include "llvm/Support/MemoryObject.h"
1920
2021 namespace llvm {
2728 StringRefMemoryObject(StringRef Bytes, uint64_t Base = 0)
2829 : Bytes(Bytes), Base(Base) {}
2930
30 uint64_t getBase() const { return Base; }
31 uint64_t getExtent() const { return Bytes.size(); }
31 uint64_t getBase() const LLVM_OVERRIDE { return Base; }
32 uint64_t getExtent() const LLVM_OVERRIDE { return Bytes.size(); }
3233
33 int readByte(uint64_t Addr, uint8_t *Byte) const;
34 int readBytes(uint64_t Addr, uint64_t Size,
35 uint8_t *Buf, uint64_t *Copied) const;
36
34 int readByte(uint64_t Addr, uint8_t *Byte) const LLVM_OVERRIDE;
35 int readBytes(uint64_t Addr, uint64_t Size, uint8_t *Buf) const LLVM_OVERRIDE;
3736 };
3837
3938 }
30093009 Stream.init(*StreamFile);
30103010
30113011 unsigned char buf[16];
3012 if (Bytes->readBytes(0, 16, buf, NULL) == -1)
3012 if (Bytes->readBytes(0, 16, buf) == -1)
30133013 return Error("Bitcode stream must be at least 16 bytes in length");
30143014
30153015 if (!isBitcode(buf, buf + 16))
1414
1515 int MemoryObject::readBytes(uint64_t address,
1616 uint64_t size,
17 uint8_t* buf,
18 uint64_t* copied) const {
17 uint8_t* buf) const {
1918 uint64_t current = address;
2019 uint64_t limit = getBase() + getExtent();
2120
2928 current++;
3029 }
3130
32 if (copied)
33 *copied = current - address;
34
3531 return 0;
3632 }
3030 virtual int readByte(uint64_t address, uint8_t* ptr) const LLVM_OVERRIDE;
3131 virtual int readBytes(uint64_t address,
3232 uint64_t size,
33 uint8_t* buf,
34 uint64_t* copied) const LLVM_OVERRIDE;
33 uint8_t *buf) const LLVM_OVERRIDE;
3534 virtual const uint8_t *getPointer(uint64_t address,
3635 uint64_t size) const LLVM_OVERRIDE;
3736 virtual bool isValidAddress(uint64_t address) const LLVM_OVERRIDE {
6665
6766 int RawMemoryObject::readBytes(uint64_t address,
6867 uint64_t size,
69 uint8_t* buf,
70 uint64_t* copied) const {
68 uint8_t *buf) const {
7169 if (!validAddress(address) || !validAddress(address + size - 1)) return -1;
7270 memcpy(buf, (uint8_t *)(uintptr_t)(address + FirstChar), size);
73 if (copied) *copied = size;
7471 return size;
7572 }
7673
110107
111108 int StreamingMemoryObject::readBytes(uint64_t address,
112109 uint64_t size,
113 uint8_t* buf,
114 uint64_t* copied) const {
110 uint8_t *buf) const {
115111 if (!fetchToPos(address + size - 1)) return -1;
116112 memcpy(buf, &Bytes[address + BytesSkipped], size);
117 if (copied) *copied = size;
118113 return 0;
119114 }
120115
1919
2020 int StringRefMemoryObject::readBytes(uint64_t Addr,
2121 uint64_t Size,
22 uint8_t *Buf,
23 uint64_t *Copied) const {
24 if (Addr >= Base + getExtent() || Addr < Base)
22 uint8_t *Buf) const {
23 uint64_t Offset = Addr - Base;
24 if (Addr >= Base + getExtent() || Offset + Size > getExtent() || Addr < Base)
2525 return -1;
26 uint64_t Offset = Addr - Base;
27 if (Size > getExtent() - Offset)
28 Size = getExtent() - Offset;
2926 memcpy(Buf, Bytes.data() + Offset, Size);
30 if (Copied)
31 *Copied = Size;
3227 return 0;
3328 }
207207 uint8_t bytes[4];
208208
209209 // We want to read exactly 4 bytes of data.
210 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1) {
210 if (Region.readBytes(Address, 4, bytes) == -1) {
211211 Size = 0;
212212 return MCDisassembler::Fail;
213213 }
412412 "Asked to disassemble an ARM instruction but Subtarget is in Thumb mode!");
413413
414414 // We want to read exactly 4 bytes of data.
415 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1) {
415 if (Region.readBytes(Address, 4, bytes) == -1) {
416416 Size = 0;
417417 return MCDisassembler::Fail;
418418 }
658658 "Asked to disassemble in Thumb mode but Subtarget is in ARM mode!");
659659
660660 // We want to read exactly 2 bytes of data.
661 if (Region.readBytes(Address, 2, (uint8_t*)bytes, NULL) == -1) {
661 if (Region.readBytes(Address, 2, bytes) == -1) {
662662 Size = 0;
663663 return MCDisassembler::Fail;
664664 }
710710 }
711711
712712 // We want to read exactly 4 bytes of data.
713 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1) {
713 if (Region.readBytes(Address, 4, bytes) == -1) {
714714 Size = 0;
715715 return MCDisassembler::Fail;
716716 }
500500 raw_ostream &cStream) const {
501501 // The machine instruction.
502502 uint32_t insn;
503 uint64_t read;
504503 uint8_t bytes[4];
505504
506505 // By default we consume 1 byte on failure
507506 size = 1;
508507
509508 // We want to read exactly 4 bytes of data.
510 if (region.readBytes(address, 4, (uint8_t*)bytes, &read) == -1 || read < 4)
509 if (region.readBytes(address, 4, bytes) == -1)
511510 return Fail;
512511
513512 // Encoded as a big-endian 32-bit word in the stream.
251251 uint8_t Bytes[4];
252252
253253 // We want to read exactly 4 Bytes of data.
254 if (region.readBytes(address, 4, (uint8_t*)Bytes, NULL) == -1) {
254 if (region.readBytes(address, 4, Bytes) == -1) {
255255 size = 0;
256256 return MCDisassembler::Fail;
257257 }
271271 // Get the first two bytes of the instruction.
272272 uint8_t Bytes[6];
273273 Size = 0;
274 if (Region.readBytes(Address, 2, Bytes, 0) == -1)
274 if (Region.readBytes(Address, 2, Bytes) == -1)
275275 return MCDisassembler::Fail;
276276
277277 // The top 2 bits of the first byte specify the size.
288288 }
289289
290290 // Read any remaining bytes.
291 if (Size > 2 && Region.readBytes(Address + 2, Size - 2, Bytes + 2, 0) == -1)
291 if (Size > 2 && Region.readBytes(Address + 2, Size - 2, Bytes + 2) == -1)
292292 return MCDisassembler::Fail;
293293
294294 // Construct the instruction.
5252 uint8_t Bytes[4];
5353
5454 // We want to read exactly 2 Bytes of data.
55 if (region.readBytes(address, 2, Bytes, NULL) == -1) {
55 if (region.readBytes(address, 2, Bytes) == -1) {
5656 size = 0;
5757 return false;
5858 }
6868 uint8_t Bytes[4];
6969
7070 // We want to read exactly 4 Bytes of data.
71 if (region.readBytes(address, 4, Bytes, NULL) == -1) {
71 if (region.readBytes(address, 4, Bytes) == -1) {
7272 size = 0;
7373 return false;
7474 }