Add patch against GNU Binutils-2.20 to support "meminfo".
[libmeminfo.git] / meminfo.h
blob1ec8908c269e872ccdb4d1fdbac115bc5e9026a3
1 /*
2 Copyright (c) 2008, STMicroelectronics
3 All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 * Neither the name of STMicroelectronics nor the names of its
15 contributors may be used to endorse or promote products derived
16 from this software without specific prior written permission.
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 Contact: cedric.vincent@st.com
33 #ifndef MEMINFO_H
34 #define MEMINFO_H
36 /** @mainpage
37 The program mind.c is a very good example on how to use this library.
40 #include <stdint.h> /* uint32_t, uint8_t, */
42 /** Structure of an entry in the meminfo table. */
43 struct meminfo {
44 uint32_t origin; /*!< Start address of the memory. */
45 uint32_t length; /*!< Length (in bytes) of the memory. */
46 uint32_t flags; /*!< Memory attributes. */
47 uint32_t not_flags; /*!< Negated memory attributes. */
48 uint8_t name[32]; /*!< Name of the memory. */
49 } __attribute__((__packed__));
51 /** Extract the meminfo table from a file.
52 @param filename is the name of the file to read.
53 @param meminfo is a pointer to a non-allocated table of struct meminfo,
54 this table is automatically calloc(3)-ated to store the extracted
55 meminfo table.
56 @return the number of entries stored in the parameter meminfo. See the
57 enum meminfo_error if this value is negative.
59 extern int meminfo_read_file(char *filename, struct meminfo *meminfo[]);
61 /** Extract the meminfo table from a file descriptor.
62 @param fd is a file descriptor.
63 @param meminfo is a pointer to a non-allocated table of struct meminfo,
64 this table is automatically calloc(3)-ated to store the extracted
65 meminfo table.
66 @return the number of entries stored in the parameter meminfo. See the
67 enum meminfo_error if this value is negative.
69 extern int meminfo_read_fd(int fd, struct meminfo *meminfo[]);
71 /** Extract the meminfo table from an ELF.
72 @param elf is a pointer to a LibELF descriptor.
73 @param meminfo is a pointer to a non-allocated table of struct meminfo,
74 this table is automatically calloc(3)-ated to store the extracted
75 meminfo table.
76 @return the number of entries stored in the parameter meminfo. See the
77 enum meminfo_error if this value is negative.
79 extern int meminfo_read_elf(void *elf, struct meminfo *meminfo[]);
81 /** Enumeration of possible errors. */
82 enum meminfo_error {
83 MEMINFO_ERROR_STRUCTURE = -1, /*<! The meminfo table is missing or incoherent. */
84 MEMINFO_ERROR_SYSTEM = -2, /*<! Check errno(3). */
85 MEMINFO_ERROR_ELF = -3, /*<! Check elf_errno. */
88 /** Extracted from ldlang.c:meminfo_flags(). Names are explicit enough. */
89 enum {
90 MEMINFO_READONLY = 0x1,
91 MEMINFO_READWRITE = 0x2,
92 MEMINFO_EXECUTABLE = 0x4,
93 MEMINFO_ALLOCATABLE = 0x8,
94 MEMINFO_INITIALIZED = 0x10
97 #endif /* MEMINFO_H */