1/*
2 *  Copyright 2001-2008 Texas Instruments - http://www.ti.com/
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
18#ifndef _GETSECTION_H_
19#define _GETSECTION_H_
20
21#ifndef _SIZE_T_DEFINED_	/* Android sets _SIZE_T_DEFINED_ on defining size_t */
22typedef unsigned int size_t;
23#define _SIZE_T_DEFINED_
24#endif
25#include "dynamic_loader.h"
26
27#ifdef __cplusplus
28extern "C" {			/* C-only version */
29#endif
30
31/*
32 * Get Section Information
33 *
34 * This file provides an API add-on to the dynamic loader that allows the user
35 * to query section information and extract section data from dynamic load
36 * modules.
37 *
38 * NOTE:
39 * Functions in this API assume that the supplied Dynamic_Loader_Stream object
40 * supports the set_file_posn method.
41 */
42
43	typedef void *DLOAD_module_info;	/* opaque handle for module information */
44
45/*****************************************************************************
46 * Procedure DLOAD_module_open
47 *
48 * Parameters:
49 *  module  The input stream that supplies the module image
50 *  syms    Host-side malloc/free and error reporting functions.
51 *          Other methods are unused.
52 *
53 * Effect:
54 *  Reads header information from a dynamic loader module using the specified
55 * stream object, and returns a handle for the module information.  This
56 * handle may be used in subsequent query calls to obtain information
57 * contained in the module.
58 *
59 * Returns:
60 *  NULL if an error is encountered, otherwise a module handle for use
61 * in subsequent operations.
62 *****************************************************************************/
63	extern DLOAD_module_info DLOAD_module_open(struct Dynamic_Loader_Stream *
64						   module,
65						   struct Dynamic_Loader_Sym * syms);
66
67/*****************************************************************************
68 * Procedure DLOAD_GetSectionInfo
69 *
70 * Parameters:
71 *  minfo       Handle from DLOAD_module_open for this module
72 *  sectionName Pointer to the string name of the section desired
73 *  sectionInfo Address of a section info structure pointer to be initialized
74 *
75 * Effect:
76 *  Finds the specified section in the module information, and fills in
77 * the provided LDR_SECTION_INFO structure.
78 *
79 * Returns:
80 *  TRUE for success, FALSE for section not found
81 *****************************************************************************/
82	extern int DLOAD_GetSectionInfo(DLOAD_module_info minfo,
83					const char *sectionName,
84					const struct LDR_SECTION_INFO **
85					const sectionInfo);
86
87/*****************************************************************************
88 * Procedure DLOAD_GetSectionNum
89 *
90 * Parameters:
91 *  minfo       Handle from DLOAD_module_open for this module
92 *  secn        Section number 0..
93 *  sectionInfo Address of a section info structure pointer to be initialized
94 *
95 * Effect:
96 *  Finds the secn'th section in the specified module, and fills in
97 * the provided LDR_SECTION_INFO structure.  If there are less than "secn+1"
98 * sections in the module, returns NULL.
99 *
100 * Returns:
101 *  TRUE for success, FALSE for failure
102 *****************************************************************************/
103	extern int DLOAD_GetSectionNum(DLOAD_module_info minfo,
104				       const unsigned secn,
105				       const struct LDR_SECTION_INFO **
106				       const sectionInfo);
107
108/*****************************************************************************
109 * Procedure DLOAD_RoundUpSectionSize
110 *
111 * Parameters:
112 *  sectSize    The actual size of the section in target addressable units
113 *
114 * Effect:
115 *  Rounds up the section size to the next multiple of 32 bits.
116 *
117 * Returns:
118 *  The rounded-up section size.
119 *****************************************************************************/
120	extern size_t DLOAD_RoundUpSectionSize(LDR_ADDR sectSize);
121
122/*****************************************************************************
123 * Procedure DLOAD_GetSection
124 *
125 * Parameters:
126 *  minfo       Handle from DLOAD_module_open for this module
127 *  sectionInfo Pointer to a section info structure for the desired section
128 *  sectionData Buffer to contain the section initialized data
129 *
130 * Effect:
131 *  Copies the initialized data for the specified section into the
132 * supplied buffer.
133 *
134 * Returns:
135 *  TRUE for success, FALSE for section not found
136 *****************************************************************************/
137	extern int DLOAD_GetSection(DLOAD_module_info minfo,
138				    const struct LDR_SECTION_INFO * sectionInfo,
139				    void *sectionData);
140
141/*****************************************************************************
142 * Procedure DLOAD_module_close
143 *
144 * Parameters:
145 *  minfo       Handle from DLOAD_module_open for this module
146 *
147 * Effect:
148 *  Releases any storage associated with the module handle.  On return,
149 * the module handle is invalid.
150 *
151 * Returns:
152 *  Zero for success. On error, the number of errors detected is returned.
153 * Individual errors are reported using syms->Error_Report(), where syms was
154 * an argument to DLOAD_module_open
155 *****************************************************************************/
156	extern void DLOAD_module_close(DLOAD_module_info minfo);
157
158#ifdef __cplusplus
159}
160#endif
161#endif				/* _GETSECTION_H_ */
162