1 : // Copyright 2015 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #ifndef SYZYGY_REFINERY_CORE_BIT_SOURCE_H_
16 : #define SYZYGY_REFINERY_CORE_BIT_SOURCE_H_
17 :
18 : #include "base/logging.h"
19 : #include "base/macros.h"
20 : #include "syzygy/refinery/core/address.h"
21 :
22 : namespace refinery {
23 :
24 : // An interface to the contents of an address space. Typically, the address
25 : // space's contents are only partially known. Access to the memory is
26 : // copy-based to avoid any alignment issues.
27 : class BitSource {
28 : public:
29 E : virtual ~BitSource() = 0 {}
30 :
31 : // Retrieves all bytes from a range.
32 : // @pre @p range must be a valid range.
33 : // @param range the requested range.
34 : // @param data_ptr a buffer of size at least that of @p range. On success,
35 : // contains the returned data.
36 : // @returns true iff the full contents of @p range are available.
37 : virtual bool GetAll(const AddressRange& range, void* data_ptr) = 0;
38 :
39 : // Determine how many bytes are available from the head of a range and
40 : // optionally retrieve them.
41 : // @pre @p range must be a valid range.
42 : // @param range the requested range.
43 : // @param data_cnt on success, contains the number of bytes returned from the
44 : // head of @p range.
45 : // @param data_ptr a buffer of size at least that of @p range or nullptr. On
46 : // success, a valid buffer contains the returned data.
47 : // @returns true iff some data is available from the head of @p range.
48 : virtual bool GetFrom(const AddressRange& range,
49 : size_t* data_cnt,
50 : void* data_ptr) = 0;
51 :
52 : // Determines whether any bytes are available for a range.
53 : // @param range the range.
54 : // @returns true iff some data is available in the desired range.
55 : virtual bool HasSome(const AddressRange& range) = 0;
56 : };
57 :
58 : } // namespace refinery
59 :
60 : #endif // SYZYGY_REFINERY_CORE_BIT_SOURCE_H_
|