| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 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. |
| 15 | */ |
| The Android Open Source Project | 9940988 | 2009-03-18 22:20:24 -0700 | [diff] [blame^] | 16 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 17 | /* |
| 18 | * System utilities. |
| 19 | */ |
| 20 | #ifndef _LIBDEX_SYSUTIL |
| 21 | #define _LIBDEX_SYSUTIL |
| 22 | |
| 23 | #include <sys/types.h> |
| 24 | |
| 25 | /* |
| 26 | * Use this to keep track of mapped segments. |
| 27 | */ |
| 28 | typedef struct MemMapping { |
| 29 | void* addr; /* start of data */ |
| 30 | size_t length; /* length of data */ |
| 31 | |
| 32 | void* baseAddr; /* page-aligned base address */ |
| 33 | size_t baseLength; /* length of mapping */ |
| 34 | } MemMapping; |
| 35 | |
| 36 | /* |
| 37 | * Copy a map. |
| 38 | */ |
| 39 | void sysCopyMap(MemMapping* dst, const MemMapping* src); |
| 40 | |
| 41 | /* |
| 42 | * Load a file into a new shared memory segment. All data from the current |
| 43 | * offset to the end of the file is pulled in. |
| 44 | * |
| 45 | * The segment is read-write, allowing VM fixups. (It should be modified |
| 46 | * to support .gz/.zip compressed data.) |
| 47 | * |
| 48 | * On success, "pMap" is filled in, and zero is returned. |
| 49 | */ |
| 50 | int sysLoadFileInShmem(int fd, MemMapping* pMap); |
| 51 | |
| 52 | /* |
| 53 | * Map a file (from fd's current offset) into a shared, |
| 54 | * read-only memory segment. |
| 55 | * |
| 56 | * On success, "pMap" is filled in, and zero is returned. |
| 57 | */ |
| 58 | int sysMapFileInShmem(int fd, MemMapping* pMap); |
| 59 | |
| 60 | /* |
| 61 | * Like sysMapFileInShmem, but on only part of a file. |
| 62 | */ |
| 63 | int sysMapFileSegmentInShmem(int fd, off_t start, long length, |
| 64 | MemMapping* pMap); |
| 65 | |
| 66 | /* |
| The Android Open Source Project | 9940988 | 2009-03-18 22:20:24 -0700 | [diff] [blame^] | 67 | * Create a private anonymous mapping, useful for large allocations. |
| 68 | * |
| 69 | * On success, "pMap" is filled in, and zero is returned. |
| 70 | */ |
| 71 | int sysCreatePrivateMap(size_t length, MemMapping* pMap); |
| 72 | |
| 73 | /* |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 74 | * Release the pages associated with a shared memory segment. |
| 75 | * |
| 76 | * This does not free "pMap"; it just releases the memory. |
| 77 | */ |
| 78 | void sysReleaseShmem(MemMapping* pMap); |
| 79 | |
| 80 | #endif /*_DALVIK_SYSUTIL*/ |