~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/elfnote.h

Version: ~ [ linux-5.3-rc5 ] ~ [ linux-5.2.9 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.67 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.139 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.189 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.189 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.72 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #ifndef _LINUX_ELFNOTE_H
  2 #define _LINUX_ELFNOTE_H
  3 /*
  4  * Helper macros to generate ELF Note structures, which are put into a
  5  * PT_NOTE segment of the final vmlinux image.  These are useful for
  6  * including name-value pairs of metadata into the kernel binary (or
  7  * modules?) for use by external programs.
  8  *
  9  * Each note has three parts: a name, a type and a desc.  The name is
 10  * intended to distinguish the note's originator, so it would be a
 11  * company, project, subsystem, etc; it must be in a suitable form for
 12  * use in a section name.  The type is an integer which is used to tag
 13  * the data, and is considered to be within the "name" namespace (so
 14  * "FooCo"'s type 42 is distinct from "BarProj"'s type 42).  The
 15  * "desc" field is the actual data.  There are no constraints on the
 16  * desc field's contents, though typically they're fairly small.
 17  *
 18  * All notes from a given NAME are put into a section named
 19  * .note.NAME.  When the kernel image is finally linked, all the notes
 20  * are packed into a single .notes section, which is mapped into the
 21  * PT_NOTE segment.  Because notes for a given name are grouped into
 22  * the same section, they'll all be adjacent the output file.
 23  *
 24  * This file defines macros for both C and assembler use.  Their
 25  * syntax is slightly different, but they're semantically similar.
 26  *
 27  * See the ELF specification for more detail about ELF notes.
 28  */
 29 
 30 #ifdef __ASSEMBLER__
 31 /*
 32  * Generate a structure with the same shape as Elf{32,64}_Nhdr (which
 33  * turn out to be the same size and shape), followed by the name and
 34  * desc data with appropriate padding.  The 'desctype' argument is the
 35  * assembler pseudo op defining the type of the data e.g. .asciz while
 36  * 'descdata' is the data itself e.g.  "hello, world".
 37  *
 38  * e.g. ELFNOTE(XYZCo, 42, .asciz, "forty-two")
 39  *      ELFNOTE(XYZCo, 12, .long, 0xdeadbeef)
 40  */
 41 #define ELFNOTE_START(name, type, flags)        \
 42 .pushsection .note.name, flags,@note    ;       \
 43   .balign 4                             ;       \
 44   .long 2f - 1f         /* namesz */    ;       \
 45   .long 4484f - 3f      /* descsz */    ;       \
 46   .long type                            ;       \
 47 1:.asciz #name                          ;       \
 48 2:.balign 4                             ;       \
 49 3:
 50 
 51 #define ELFNOTE_END                             \
 52 4484:.balign 4                          ;       \
 53 .popsection                             ;
 54 
 55 #define ELFNOTE(name, type, desc)               \
 56         ELFNOTE_START(name, type, "")           \
 57                 desc                    ;       \
 58         ELFNOTE_END
 59 
 60 #else   /* !__ASSEMBLER__ */
 61 #include <linux/elf.h>
 62 /*
 63  * Use an anonymous structure which matches the shape of
 64  * Elf{32,64}_Nhdr, but includes the name and desc data.  The size and
 65  * type of name and desc depend on the macro arguments.  "name" must
 66  * be a literal string, and "desc" must be passed by value.  You may
 67  * only define one note per line, since __LINE__ is used to generate
 68  * unique symbols.
 69  */
 70 #define _ELFNOTE_PASTE(a,b)     a##b
 71 #define _ELFNOTE(size, name, unique, type, desc)                        \
 72         static const struct {                                           \
 73                 struct elf##size##_note _nhdr;                          \
 74                 unsigned char _name[sizeof(name)]                       \
 75                 __attribute__((aligned(sizeof(Elf##size##_Word))));     \
 76                 typeof(desc) _desc                                      \
 77                              __attribute__((aligned(sizeof(Elf##size##_Word)))); \
 78         } _ELFNOTE_PASTE(_note_, unique)                                \
 79                 __used                                                  \
 80                 __attribute__((section(".note." name),                  \
 81                                aligned(sizeof(Elf##size##_Word)),       \
 82                                unused)) = {                             \
 83                 {                                                       \
 84                         sizeof(name),                                   \
 85                         sizeof(desc),                                   \
 86                         type,                                           \
 87                 },                                                      \
 88                 name,                                                   \
 89                 desc                                                    \
 90         }
 91 #define ELFNOTE(size, name, type, desc)         \
 92         _ELFNOTE(size, name, __LINE__, type, desc)
 93 
 94 #define ELFNOTE32(name, type, desc) ELFNOTE(32, name, type, desc)
 95 #define ELFNOTE64(name, type, desc) ELFNOTE(64, name, type, desc)
 96 #endif  /* __ASSEMBLER__ */
 97 
 98 #endif /* _LINUX_ELFNOTE_H */
 99 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp