From 1b8388cde9c85a294ef7085a1e7c54a44a7cc906 Mon Sep 17 00:00:00 2001 From: Mikolaj Golub Date: Wed, 1 May 2013 14:59:16 +0000 Subject: [PATCH] Introduce a constant, ELF_NOTE_ROUNDSIZE, which evidently declare our intention to use 4-byte padding for elf notes. MFC after: 3 weeks --- sys/kern/imgact_elf.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index 5bbdef560867..61a2aefe4e06 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -81,6 +81,7 @@ __FBSDID("$FreeBSD$"); #include #include +#define ELF_NOTE_ROUNDSIZE 4 #define OLD_EI_BRAND 8 static int __elfN(check_header)(const Elf_Ehdr *hdr); @@ -161,7 +162,7 @@ __elfN(freebsd_trans_osrel)(const Elf_Note *note, int32_t *osrel) uintptr_t p; p = (uintptr_t)(note + 1); - p += roundup2(note->n_namesz, sizeof(Elf32_Addr)); + p += roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE); *osrel = *(const int32_t *)(p); return (TRUE); @@ -186,7 +187,7 @@ kfreebsd_trans_osrel(const Elf_Note *note, int32_t *osrel) uintptr_t p; p = (uintptr_t)(note + 1); - p += roundup2(note->n_namesz, sizeof(Elf32_Addr)); + p += roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE); desc = (const Elf32_Word *)p; if (desc[0] != GNU_KFREEBSD_ABI_DESC) @@ -1546,7 +1547,7 @@ __elfN(puthdr)(struct thread *td, void *hdr, size_t hdrsize, int numsegs, phdr->p_filesz = notesz; phdr->p_memsz = 0; phdr->p_flags = PF_R; - phdr->p_align = sizeof(Elf32_Size); + phdr->p_align = ELF_NOTE_ROUNDSIZE; phdr++; /* All the writable segments from the program. */ @@ -1574,8 +1575,8 @@ register_note(struct note_info_list *list, int type, outfunc_t out, void *arg) return (size); notesize = sizeof(Elf_Note) + /* note header */ - roundup2(8, sizeof(Elf32_Size)) + /* note name ("FreeBSD") */ - roundup2(size, sizeof(Elf32_Size)); /* note description */ + roundup2(8, ELF_NOTE_ROUNDSIZE) + /* note name ("FreeBSD") */ + roundup2(size, ELF_NOTE_ROUNDSIZE); /* note description */ return (notesize); } @@ -1598,12 +1599,12 @@ __elfN(putnote)(struct note_info *ninfo, struct sbuf *sb) sbuf_bcat(sb, ¬e, sizeof(note)); sbuf_start_section(sb, &old_len); sbuf_bcat(sb, "FreeBSD", note.n_namesz); - sbuf_end_section(sb, old_len, sizeof(Elf32_Size), 0); + sbuf_end_section(sb, old_len, ELF_NOTE_ROUNDSIZE, 0); if (note.n_descsz == 0) return; sbuf_start_section(sb, &old_len); ninfo->outfunc(ninfo->outarg, sb, &ninfo->outsize); - sbuf_end_section(sb, old_len, sizeof(Elf32_Size), 0); + sbuf_end_section(sb, old_len, ELF_NOTE_ROUNDSIZE, 0); } /* @@ -2004,8 +2005,8 @@ __elfN(parse_notes)(struct image_params *imgp, Elf_Brandnote *checknote, nextnote: note = (const Elf_Note *)((const char *)(note + 1) + - roundup2(note->n_namesz, sizeof(Elf32_Addr)) + - roundup2(note->n_descsz, sizeof(Elf32_Addr))); + roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE) + + roundup2(note->n_descsz, ELF_NOTE_ROUNDSIZE)); } return (FALSE);