1 /*
2 * Copyright 2006 The Android Open Source Project
3 *
4 * System utilities.
5 */
6 #ifndef _MINZIP_SYSUTIL
7 #define _MINZIP_SYSUTIL
8
9 #include "Hash.h"
10
11 #include <sys/types.h>
12
13 /*
14 * Use this to keep track of mapped segments.
15 */
16 typedef struct MemMapping {
17 void* addr; /* start of data */
18 size_t length; /* length of data */
19
20 void* baseAddr; /* page-aligned base address */
21 size_t baseLength; /* length of mapping */
22 } MemMapping;
23
24 /* copy a map */
sysCopyMap(MemMapping * dst,const MemMapping * src)25 INLINE void sysCopyMap(MemMapping* dst, const MemMapping* src)
26 {
27 *dst = *src;
28 }
29
30 /*
31 * Load a file into a new shared memory segment. All data from the current
32 * offset to the end of the file is pulled in.
33 *
34 * The segment is read-write, allowing VM fixups. (It should be modified
35 * to support .gz/.zip compressed data.)
36 *
37 * On success, "pMap" is filled in, and zero is returned.
38 */
39 int sysLoadFileInShmem(int fd, MemMapping* pMap);
40
41 /*
42 * Map a file (from fd's current offset) into a shared,
43 * read-only memory segment.
44 *
45 * On success, "pMap" is filled in, and zero is returned.
46 */
47 int sysMapFileInShmem(int fd, MemMapping* pMap);
48
49 /*
50 * Like sysMapFileInShmem, but on only part of a file.
51 */
52 int sysMapFileSegmentInShmem(int fd, off_t start, long length,
53 MemMapping* pMap);
54
55 /*
56 * Release the pages associated with a shared memory segment.
57 *
58 * This does not free "pMap"; it just releases the memory.
59 */
60 void sysReleaseShmem(MemMapping* pMap);
61
62 #endif /*_MINZIP_SYSUTIL*/
63