GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Data Structures | Macros | Functions
gp_elf_note.h File Reference

An ELF note implementation. More...

#include <core/gp_common.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  gp_elf_note_hdr
 ELF note header as defined in ELF ABI. More...
 

Macros

#define GP_ELF_NOTE(note_namespace, note_type, note_c_type, note_c_type_size, ...)
 Declares a gfxprim ELF note.
 
#define GP_ELF_NOTE_STR(note_namespace, note_type, note_str)    GP_ELF_NOTE(note_namespace, note_type, char desc[sizeof(note_str)], sizeof(note_str), note_str)
 Declares a gfxprim string note.
 

Functions

void gp_elf_notes_process (void(*callback)(uint32_t note_type, const void *note_desc, void *priv), void *priv)
 Runs a callback on each gfxprim ELF note.
 

Detailed Description

An ELF note implementation.

Definition in file gp_elf_note.h.

Macro Definition Documentation

◆ GP_ELF_NOTE

#define GP_ELF_NOTE (   note_namespace,
  note_type,
  note_c_type,
  note_c_type_size,
  ... 
)
Value:
__attribute__((used, section(".note." GP_ELF_NOTE_VENDOR "." note_namespace), aligned(4))) \
static const struct { \
const struct gp_elf_note_hdr hdr; \
const note_c_type; \
} GP_UNIQUE_ID(gp_elf_note_) = { \
.hdr = { \
.namesz = sizeof(GP_ELF_NOTE_VENDOR), \
.descsz = note_c_type_size, \
.type = note_type, \
.name = GP_ELF_NOTE_VENDOR, \
}, \
.desc = __VA_ARGS__, \
};
#define GP_UNIQUE_ID(prefix)
Generates an unique C identifier with a given prefix.
Definition gp_common.h:102
ELF note header as defined in ELF ABI.
Definition gp_elf_note.h:24
uint32_t type
4 bytes of note type.
Definition gp_elf_note.h:30
uint32_t descsz
4 bytes of note description size.
Definition gp_elf_note.h:28
uint32_t namesz
4 bytes of note name size.
Definition gp_elf_note.h:26
char name[sizeof("gfxprim")]
A namesz long null terminated string of the entry owner, i.e. "gfxprim".
Definition gp_elf_note.h:32

Declares a gfxprim ELF note.

This macro is supposed to be used as:

struct payload_type1 {
int val;
char str[64];
};
enum payload_types {
...
PAYLOAD_TYPE1,
...
};
GP_ELF_NOTE("namespace", PAYLOAD_TYPE1, struct payload desc,
sizeof(struct payload), {.val = 1, .str = "test"});
#define GP_ELF_NOTE(note_namespace, note_type, note_c_type, note_c_type_size,...)
Declares a gfxprim ELF note.
Definition gp_elf_note.h:74
Parameters
note_namespaceA subsection to store the note to. The section is constructed as ".note.vendor.namespace". The namespace is stored in ELF headers however it's not accessible to the program at runtime.
note_typeThis is usually an enum of all note types defined by the vendor and identifies what is stored in the note payload.
note_c_typeA C type that is used to store the payload to.
note_c_type_sizeA C type size, usually sizeof(note_c_type), but can be larger in the case of a flexible array.
...An initializer for note_c_type, e.g. {.foo = bar, ...}.

Definition at line 74 of file gp_elf_note.h.

◆ GP_ELF_NOTE_STR

#define GP_ELF_NOTE_STR (   note_namespace,
  note_type,
  note_str 
)     GP_ELF_NOTE(note_namespace, note_type, char desc[sizeof(note_str)], sizeof(note_str), note_str)

Declares a gfxprim string note.

This is a simplified interface for the GP_ELF_NOTE().

Parameters
note_namespaceA subsection to store the note to. The section is constructed as ".note.vendor.namespace". The namespace is stored in ELF headers however it's not accessible to the program at runtime.
note_typeThis is usually an enum of all note types defined by the vendor and identifies what is stored in the note payload.
note_strA string that is stored in the note, i.e. the note payload.

Definition at line 104 of file gp_elf_note.h.

Function Documentation

◆ gp_elf_notes_process()

void gp_elf_notes_process ( void(*)(uint32_t note_type, const void *note_desc, void *priv)  callback,
void *  priv 
)

Runs a callback on each gfxprim ELF note.

This function is build on a top of a dl_iterate_phdr() and filters out everything that does not have vendor set to 'gfxprim'.

@callback A callback to be called for each note. @priv A priv pointer to be passed to the callback.