Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys - use the unused section in the array to put a NetBSD no...
details: https://anonhg.NetBSD.org/src/rev/905ecbe878ba
branches: trunk
changeset: 334831:905ecbe878ba
user: christos <christos%NetBSD.org@localhost>
date: Tue Dec 09 02:30:09 2014 +0000
description:
- use the unused section in the array to put a NetBSD note in it
- cleanup the hard-coded constants in the stringtab
diffstat:
sys/kern/kern_ksyms.c | 57 ++++++++++++++++++++++++++++++++------------------
sys/sys/ksyms.h | 7 ++++-
2 files changed, 41 insertions(+), 23 deletions(-)
diffs (156 lines):
diff -r 6414298bc241 -r 905ecbe878ba sys/kern/kern_ksyms.c
--- a/sys/kern/kern_ksyms.c Mon Dec 08 20:54:33 2014 +0000
+++ b/sys/kern/kern_ksyms.c Tue Dec 09 02:30:09 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_ksyms.c,v 1.73 2014/08/17 21:17:44 joerg Exp $ */
+/* $NetBSD: kern_ksyms.c,v 1.74 2014/12/09 02:30:09 christos Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.73 2014/08/17 21:17:44 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.74 2014/12/09 02:30:09 christos Exp $");
#if defined(_KERNEL) && defined(_KERNEL_OPT)
#include "opt_ddb.h"
@@ -843,9 +843,19 @@
}
static void
+ksyms_fill_note(void)
+{
+ int32_t *note = ksyms_hdr.kh_note;
+ note[0] = ELF_NOTE_NETBSD_NAMESZ;
+ note[1] = ELF_NOTE_NETBSD_DESCSZ;
+ note[2] = ELF_NOTE_TYPE_NETBSD_TAG;
+ memcpy(¬e[3], "NetBSD\0", 8);
+ note[5] = __NetBSD_Version__;
+}
+
+static void
ksyms_hdr_init(void *hdraddr)
{
-
/* Copy the loaded elf exec header */
memcpy(&ksyms_hdr.kh_ehdr, hdraddr, sizeof(Elf_Ehdr));
@@ -863,59 +873,64 @@
ksyms_hdr.kh_phdr[0].p_memsz = (unsigned long)-1L;
ksyms_hdr.kh_phdr[0].p_flags = PF_R | PF_X | PF_W;
- /* First section is null */
+#define SHTCOPY(name) strlcpy(&ksyms_hdr.kh_strtab[offs], (name), \
+ sizeof(ksyms_hdr.kh_strtab) - offs), offs += sizeof(name)
+
+ uint32_t offs = 1;
+ /* First section header ".note.netbsd.ident" */
+ ksyms_hdr.kh_shdr[SHNOTE].sh_name = offs; /* Section 6 offset */
+ ksyms_hdr.kh_shdr[SHNOTE].sh_type = SHT_NOTE;
+ ksyms_hdr.kh_shdr[SHNOTE].sh_offset =
+ offsetof(struct ksyms_hdr, kh_note[0]);
+ ksyms_hdr.kh_shdr[SHNOTE].sh_size = sizeof(ksyms_hdr.kh_note);
+ ksyms_hdr.kh_shdr[SHNOTE].sh_addralign = sizeof(int);
+ SHTCOPY(".note.netbsd.ident");
+ ksyms_fill_note();
/* Second section header; ".symtab" */
- ksyms_hdr.kh_shdr[SYMTAB].sh_name = 1; /* Section 3 offset */
+ ksyms_hdr.kh_shdr[SYMTAB].sh_name = offs;
ksyms_hdr.kh_shdr[SYMTAB].sh_type = SHT_SYMTAB;
ksyms_hdr.kh_shdr[SYMTAB].sh_offset = sizeof(struct ksyms_hdr);
/* ksyms_hdr.kh_shdr[SYMTAB].sh_size = filled in at open */
ksyms_hdr.kh_shdr[SYMTAB].sh_link = 2; /* Corresponding strtab */
ksyms_hdr.kh_shdr[SYMTAB].sh_addralign = sizeof(long);
ksyms_hdr.kh_shdr[SYMTAB].sh_entsize = sizeof(Elf_Sym);
+ SHTCOPY(".symtab");
/* Third section header; ".strtab" */
- ksyms_hdr.kh_shdr[STRTAB].sh_name = 9; /* Section 3 offset */
+ ksyms_hdr.kh_shdr[STRTAB].sh_name = offs;
ksyms_hdr.kh_shdr[STRTAB].sh_type = SHT_STRTAB;
/* ksyms_hdr.kh_shdr[STRTAB].sh_offset = filled in at open */
/* ksyms_hdr.kh_shdr[STRTAB].sh_size = filled in at open */
ksyms_hdr.kh_shdr[STRTAB].sh_addralign = sizeof(char);
+ SHTCOPY(".strtab");
/* Fourth section, ".shstrtab" */
- ksyms_hdr.kh_shdr[SHSTRTAB].sh_name = 17; /* This section name offset */
+ ksyms_hdr.kh_shdr[SHSTRTAB].sh_name = offs;
ksyms_hdr.kh_shdr[SHSTRTAB].sh_type = SHT_STRTAB;
ksyms_hdr.kh_shdr[SHSTRTAB].sh_offset =
offsetof(struct ksyms_hdr, kh_strtab);
ksyms_hdr.kh_shdr[SHSTRTAB].sh_size = SHSTRSIZ;
ksyms_hdr.kh_shdr[SHSTRTAB].sh_addralign = sizeof(char);
+ SHTCOPY(".shstrtab");
/* Fifth section, ".bss". All symbols reside here. */
- ksyms_hdr.kh_shdr[SHBSS].sh_name = 27; /* This section name offset */
+ ksyms_hdr.kh_shdr[SHBSS].sh_name = offs;
ksyms_hdr.kh_shdr[SHBSS].sh_type = SHT_NOBITS;
ksyms_hdr.kh_shdr[SHBSS].sh_offset = 0;
ksyms_hdr.kh_shdr[SHBSS].sh_size = (unsigned long)-1L;
ksyms_hdr.kh_shdr[SHBSS].sh_addralign = PAGE_SIZE;
ksyms_hdr.kh_shdr[SHBSS].sh_flags = SHF_ALLOC | SHF_EXECINSTR;
+ SHTCOPY(".bss");
/* Sixth section header; ".SUNW_ctf" */
- ksyms_hdr.kh_shdr[SHCTF].sh_name = 32; /* Section 6 offset */
+ ksyms_hdr.kh_shdr[SHCTF].sh_name = offs;
ksyms_hdr.kh_shdr[SHCTF].sh_type = SHT_PROGBITS;
/* ksyms_hdr.kh_shdr[SHCTF].sh_offset = filled in at open */
/* ksyms_hdr.kh_shdr[SHCTF].sh_size = filled in at open */
ksyms_hdr.kh_shdr[SHCTF].sh_link = SYMTAB; /* Corresponding symtab */
ksyms_hdr.kh_shdr[SHCTF].sh_addralign = sizeof(char);
-
- /* Set section names */
- strlcpy(&ksyms_hdr.kh_strtab[1], ".symtab",
- sizeof(ksyms_hdr.kh_strtab) - 1);
- strlcpy(&ksyms_hdr.kh_strtab[9], ".strtab",
- sizeof(ksyms_hdr.kh_strtab) - 9);
- strlcpy(&ksyms_hdr.kh_strtab[17], ".shstrtab",
- sizeof(ksyms_hdr.kh_strtab) - 17);
- strlcpy(&ksyms_hdr.kh_strtab[27], ".bss",
- sizeof(ksyms_hdr.kh_strtab) - 27);
- strlcpy(&ksyms_hdr.kh_strtab[32], ".SUNW_ctf",
- sizeof(ksyms_hdr.kh_strtab) - 32);
+ SHTCOPY(".SUNW_ctf");
}
static int
diff -r 6414298bc241 -r 905ecbe878ba sys/sys/ksyms.h
--- a/sys/sys/ksyms.h Mon Dec 08 20:54:33 2014 +0000
+++ b/sys/sys/ksyms.h Tue Dec 09 02:30:09 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ksyms.h,v 1.28 2012/11/18 00:06:56 chs Exp $ */
+/* $NetBSD: ksyms.h,v 1.29 2014/12/09 02:30:09 christos Exp $ */
/*
* Copyright (c) 2001, 2003 Anders Magnusson (ragge%ludd.luth.se@localhost).
@@ -58,6 +58,7 @@
* Static allocated ELF header.
* Basic info is filled in at attach, sizes at open.
*/
+#define SHNOTE 0
#define SYMTAB 1
#define STRTAB 2
#define SHSTRTAB 3
@@ -66,13 +67,15 @@
#define NSECHDR 6
#define NPRGHDR 1
-#define SHSTRSIZ 42
+#define SHSTRSIZ 64
struct ksyms_hdr {
Elf_Ehdr kh_ehdr;
Elf_Phdr kh_phdr[NPRGHDR];
Elf_Shdr kh_shdr[NSECHDR];
char kh_strtab[SHSTRSIZ];
+ /* 0=NameSize, 1=DescSize, 2=Tag, 3="NetB", 4="SD\0\0", 5=Version */
+ int32_t kh_note[6];
};
#endif /* _KSYMS_PRIVATE */
Home |
Main Index |
Thread Index |
Old Index