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