2 Copyright (c) 2008, STMicroelectronics
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
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 #include <gelf.h> /* elf*(3), */
34 #include <stdlib.h> /* NULL, */
38 int meminfo_read_fd(int fd
, struct meminfo
*meminfo
[])
40 size_t meminfo_nb_entries
= 0;
41 unsigned version
= EV_NONE
;
44 /* This check is mandatory to initialize the libelf. */
45 version
= elf_version(EV_CURRENT
);
46 if (version
== EV_NONE
)
47 return MEMINFO_ERROR_ELF
;
49 /* Create an Elf descriptor from the file descriptor. */
50 elf
= elf_begin(fd
, ELF_C_READ
, NULL
);
52 return MEMINFO_ERROR_ELF
;
54 meminfo_nb_entries
= meminfo_read_elf(elf
, meminfo
);
56 /* Ignore errors when closing the ELF descriptor. */
59 return meminfo_nb_entries
;