blob: 95e5be25dc4ee82b4817cd68831c8909d2abf805 [file] [log] [blame]
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001/*
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 Project99409882009-03-18 22:20:24 -070016
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080017/*
18 * System utilities.
19 */
20#ifndef _LIBDEX_SYSUTIL
21#define _LIBDEX_SYSUTIL
22
23#include <sys/types.h>
24
25/*
Andy McFadden96516932009-10-28 17:39:02 -070026 * System page size. Normally you're expected to get this from
27 * sysconf(_SC_PAGESIZE) or some system-specific define (usually PAGESIZE
28 * or PAGE_SIZE). If we use a simple #define the compiler can generate
29 * appropriate masks directly, so we define it here and verify it as the
30 * VM is starting up.
31 *
32 * Must be a power of 2.
33 */
34#define SYSTEM_PAGE_SIZE 4096
35
36/*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080037 * Use this to keep track of mapped segments.
38 */
39typedef struct MemMapping {
40 void* addr; /* start of data */
41 size_t length; /* length of data */
42
43 void* baseAddr; /* page-aligned base address */
44 size_t baseLength; /* length of mapping */
45} MemMapping;
46
47/*
48 * Copy a map.
49 */
50void sysCopyMap(MemMapping* dst, const MemMapping* src);
51
52/*
53 * Load a file into a new shared memory segment. All data from the current
54 * offset to the end of the file is pulled in.
55 *
56 * The segment is read-write, allowing VM fixups. (It should be modified
57 * to support .gz/.zip compressed data.)
58 *
59 * On success, "pMap" is filled in, and zero is returned.
60 */
61int sysLoadFileInShmem(int fd, MemMapping* pMap);
62
63/*
64 * Map a file (from fd's current offset) into a shared,
65 * read-only memory segment.
66 *
67 * On success, "pMap" is filled in, and zero is returned.
68 */
Andy McFaddenb5ebe472009-11-16 16:14:54 -080069int sysMapFileInShmemReadOnly(int fd, MemMapping* pMap);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080070
71/*
Andy McFaddenb5ebe472009-11-16 16:14:54 -080072 * Map a file (from fd's current offset) into a shared, read-only memory
73 * segment that can be made writable. (In some cases, such as when
74 * mapping a file on a FAT filesystem, the result may be fully writable.)
75 *
76 * On success, "pMap" is filled in, and zero is returned.
77 */
78int sysMapFileInShmemWritableReadOnly(int fd, MemMapping* pMap);
79
80/*
81 * Like sysMapFileInShmemReadOnly, but on only part of a file.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080082 */
Andy McFadden80a4e242010-04-23 16:34:52 -070083int sysMapFileSegmentInShmem(int fd, off_t start, size_t length,
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080084 MemMapping* pMap);
85
86/*
The Android Open Source Project99409882009-03-18 22:20:24 -070087 * Create a private anonymous mapping, useful for large allocations.
88 *
89 * On success, "pMap" is filled in, and zero is returned.
90 */
91int sysCreatePrivateMap(size_t length, MemMapping* pMap);
92
93/*
Andy McFadden96516932009-10-28 17:39:02 -070094 * Change the access rights on one or more pages. If "wantReadWrite" is
95 * zero, the pages will be made read-only; otherwise they will be read-write.
96 *
97 * Returns 0 on success.
98 */
99int sysChangeMapAccess(void* addr, size_t length, int wantReadWrite,
100 MemMapping* pmap);
101
102/*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800103 * Release the pages associated with a shared memory segment.
104 *
105 * This does not free "pMap"; it just releases the memory.
106 */
107void sysReleaseShmem(MemMapping* pMap);
108
109#endif /*_DALVIK_SYSUTIL*/