blob: 52f6d20a7c6896e9acf80940a006d43da0682a67 [file] [log] [blame]
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -08001/*
2 * Copyright 2006 The Android Open Source Project
3 *
Tao Baoc3292f32016-11-04 10:52:13 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080015 */
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080016
Tao Baoc3292f32016-11-04 10:52:13 -070017#ifndef _OTAUTIL_SYSUTIL
18#define _OTAUTIL_SYSUTIL
19
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080020#include <sys/types.h>
21
Tao Baob656a152017-04-18 23:54:29 -070022#include <string>
Tao Baoc3292f32016-11-04 10:52:13 -070023#include <vector>
Doug Zongker99916f02014-01-13 14:16:58 -080024
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080025/*
26 * Use this to keep track of mapped segments.
27 */
Tao Baob656a152017-04-18 23:54:29 -070028class MemMapping {
29 public:
30 ~MemMapping();
31 // Map a file into a private, read-only memory segment. If 'filename' begins with an '@'
32 // character, it is a map of blocks to be mapped, otherwise it is treated as an ordinary file.
33 bool MapFile(const std::string& filename);
34 size_t ranges() const {
35 return ranges_.size();
36 };
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080037
Tao Baob656a152017-04-18 23:54:29 -070038 unsigned char* addr; // start of data
39 size_t length; // length of data
40
41 private:
42 struct MappedRange {
43 void* addr;
44 size_t length;
45 };
46
47 bool MapBlockFile(const std::string& filename);
48 bool MapFD(int fd);
49
50 std::vector<MappedRange> ranges_;
Tao Baoc3292f32016-11-04 10:52:13 -070051};
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080052
Tao Baoc3292f32016-11-04 10:52:13 -070053#endif // _OTAUTIL_SYSUTIL