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