The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2006 The Android Open Source Project |
| 3 | * |
Tao Bao | 9c05a82 | 2016-11-04 10:52:13 -0700 | [diff] [blame] | 4 | * 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 Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 15 | */ |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 16 | |
Tao Bao | 9c05a82 | 2016-11-04 10:52:13 -0700 | [diff] [blame] | 17 | #ifndef _OTAUTIL_SYSUTIL |
| 18 | #define _OTAUTIL_SYSUTIL |
| 19 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 20 | #include <sys/types.h> |
| 21 | |
Tao Bao | 9c05a82 | 2016-11-04 10:52:13 -0700 | [diff] [blame] | 22 | #include <vector> |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 23 | |
Tao Bao | 9c05a82 | 2016-11-04 10:52:13 -0700 | [diff] [blame] | 24 | struct MappedRange { |
| 25 | void* addr; |
| 26 | size_t length; |
| 27 | }; |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 28 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 29 | /* |
| 30 | * Use this to keep track of mapped segments. |
| 31 | */ |
Tao Bao | 9c05a82 | 2016-11-04 10:52:13 -0700 | [diff] [blame] | 32 | struct MemMapping { |
| 33 | unsigned char* addr; /* start of data */ |
| 34 | size_t length; /* length of data */ |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 35 | |
Tao Bao | 9c05a82 | 2016-11-04 10:52:13 -0700 | [diff] [blame] | 36 | std::vector<MappedRange> ranges; |
| 37 | }; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 38 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 39 | /* |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 40 | * Map a file into a private, read-only memory segment. If 'fn' |
| 41 | * begins with an '@' character, it is a map of blocks to be mapped, |
| 42 | * otherwise it is treated as an ordinary file. |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 43 | * |
| 44 | * On success, "pMap" is filled in, and zero is returned. |
| 45 | */ |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 46 | int sysMapFile(const char* fn, MemMapping* pMap); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 47 | |
| 48 | /* |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 49 | * Release the pages associated with a shared memory segment. |
| 50 | * |
| 51 | * This does not free "pMap"; it just releases the memory. |
| 52 | */ |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 53 | void sysReleaseMap(MemMapping* pMap); |
| 54 | |
Tao Bao | 9c05a82 | 2016-11-04 10:52:13 -0700 | [diff] [blame] | 55 | #endif // _OTAUTIL_SYSUTIL |