blob: 6ee352b8037ef4e994d0db687a66b01bdacbb65e [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 */
69int sysMapFileInShmem(int fd, MemMapping* pMap);
70
71/*
72 * Like sysMapFileInShmem, but on only part of a file.
73 */
74int sysMapFileSegmentInShmem(int fd, off_t start, long length,
75 MemMapping* pMap);
76
77/*
The Android Open Source Project99409882009-03-18 22:20:24 -070078 * Create a private anonymous mapping, useful for large allocations.
79 *
80 * On success, "pMap" is filled in, and zero is returned.
81 */
82int sysCreatePrivateMap(size_t length, MemMapping* pMap);
83
84/*
Andy McFadden96516932009-10-28 17:39:02 -070085 * Change the access rights on one or more pages. If "wantReadWrite" is
86 * zero, the pages will be made read-only; otherwise they will be read-write.
87 *
88 * Returns 0 on success.
89 */
90int sysChangeMapAccess(void* addr, size_t length, int wantReadWrite,
91 MemMapping* pmap);
92
93/*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080094 * Release the pages associated with a shared memory segment.
95 *
96 * This does not free "pMap"; it just releases the memory.
97 */
98void sysReleaseShmem(MemMapping* pMap);
99
100#endif /*_DALVIK_SYSUTIL*/