gelf_getnote3
Get class-independent note information at the supplied offset
Usage
#include <gelf.h> size_t gelf_getnote (Elf_Data *data, size_t offset, GElf_Nhdr *result, size_t *name_offset, size_t *desc_offset);
Overview
Retrieve the ELF note header from data at offset offset and store it in a class-independent representation pointed to by result. The note name and note descriptor offsets relative to the start of data are stored in *name_offset and *desc_offset, respectively. GElf_Nhdr fields n_namesz, n_descsz, and n_type describe the note's name length, descriptor length and type, respectively. Alignment and padding of the note data entry are handled automatically by this function. See elf(5) for more information regarding ELF notes.
Parameters
- data
-
Pointer to an
Elf_Dataassociated with aSHT_NOTEsection or aPT_NOTEsegment. data->d_type should beELF_T_NHDRorELF_T_NHDR8.
- offset
-
Offset of a note header within data.
- result
-
Pointer to a caller-provided
GElf_Nhdrstructure for storing the requested note header. result must not be NULL.
- name_offset
-
Pointer to a caller-provided
size_tfor storing the name offset of the requested note. This offset is relative to data->d_buf. name_offset must not be NULL.
- desc_offset
-
Pointer to a caller-provided
size_tfor storing the descriptor offset of the requested note. This offset is relative to data->d_buf. desc_offset must not be NULL.
Return value
On success, this function updates *result, *name_offset, and *desc_offset and returns the offset of the next note. If there are no notes remaining then the return value will be greater than or equal to the d_size of data. On failure, this function returns zero and sets elf_errno. If data is NULL then zero is returned without setting elf_errno.
Examples
size_t offset = 0;
GElf_Nhdr nhdr;
size_t name_offset;
size_t desc_offset;
while (offset < data->d_size
&& (offset = gelf_getnote (data, offset,
&nhdr, &name_offset, &desc_offset)) > 0)
{
const char *name = nhdr.n_namesz == 0 ? "" : data->d_buf + name_offset;
const char *desc = nhdr.n_descsz == 0 ? "" : data->d_buf + desc_offset;
/* Process note here. name and desc are not guaranteed to be
zero-terminated. The presence of null characters should be
verified using n_namesz and n_descsz. */
[...]
}
Attributes
| Interface | Attribute | Value |
| gelf_getnote() | Thread safety | MT-Safe |