Add infrastructure required for Linux coredump support
This adds `sv_elf_core_osabi`, `sv_elf_core_abi_vendor`, and `sv_elf_core_prepare_notes` fields to `struct sysentvec`, and modifies imgact_elf.c to make use of them instead of hardcoding FreeBSD-specific values. It also updates all of the ABI definitions to preserve current behaviour. This makes it possible to implement non-native ELF coredump support without unnecessary code duplication. It will be used for Linux coredumps. Reviewed By: kib Sponsored By: EPSRC Differential Revision: https://reviews.freebsd.org/D30921
This commit is contained in:
@@ -59,6 +59,9 @@ struct sysentvec elf64_freebsd_sysvec_la48 = {
|
|||||||
.sv_szsigcode = &szsigcode,
|
.sv_szsigcode = &szsigcode,
|
||||||
.sv_name = "FreeBSD ELF64",
|
.sv_name = "FreeBSD ELF64",
|
||||||
.sv_coredump = __elfN(coredump),
|
.sv_coredump = __elfN(coredump),
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = __elfN(prepare_notes),
|
||||||
.sv_imgact_try = NULL,
|
.sv_imgact_try = NULL,
|
||||||
.sv_minsigstksz = MINSIGSTKSZ,
|
.sv_minsigstksz = MINSIGSTKSZ,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
@@ -94,6 +97,9 @@ struct sysentvec elf64_freebsd_sysvec_la57 = {
|
|||||||
.sv_szsigcode = &szsigcode,
|
.sv_szsigcode = &szsigcode,
|
||||||
.sv_name = "FreeBSD ELF64",
|
.sv_name = "FreeBSD ELF64",
|
||||||
.sv_coredump = __elfN(coredump),
|
.sv_coredump = __elfN(coredump),
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = __elfN(prepare_notes),
|
||||||
.sv_imgact_try = NULL,
|
.sv_imgact_try = NULL,
|
||||||
.sv_minsigstksz = MINSIGSTKSZ,
|
.sv_minsigstksz = MINSIGSTKSZ,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
|
|||||||
@@ -209,6 +209,9 @@ static struct sysentvec cloudabi32_elf_sysvec = {
|
|||||||
.sv_fixup = cloudabi32_fixup_tcb,
|
.sv_fixup = cloudabi32_fixup_tcb,
|
||||||
.sv_name = "CloudABI ELF32",
|
.sv_name = "CloudABI ELF32",
|
||||||
.sv_coredump = elf32_coredump,
|
.sv_coredump = elf32_coredump,
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = elf32_prepare_notes,
|
||||||
.sv_minuser = FREEBSD32_MINUSER,
|
.sv_minuser = FREEBSD32_MINUSER,
|
||||||
.sv_maxuser = FREEBSD32_MAXUSER,
|
.sv_maxuser = FREEBSD32_MAXUSER,
|
||||||
.sv_stackprot = VM_PROT_READ | VM_PROT_WRITE,
|
.sv_stackprot = VM_PROT_READ | VM_PROT_WRITE,
|
||||||
|
|||||||
@@ -197,6 +197,9 @@ static struct sysentvec cloudabi64_elf_sysvec = {
|
|||||||
.sv_fixup = cloudabi64_fixup_tcb,
|
.sv_fixup = cloudabi64_fixup_tcb,
|
||||||
.sv_name = "CloudABI ELF64",
|
.sv_name = "CloudABI ELF64",
|
||||||
.sv_coredump = elf64_coredump,
|
.sv_coredump = elf64_coredump,
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = elf64_prepare_notes,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
/* Keep top page reserved to work around AMD Ryzen stability issues. */
|
/* Keep top page reserved to work around AMD Ryzen stability issues. */
|
||||||
.sv_maxuser = VM_MAXUSER_ADDRESS - PAGE_SIZE,
|
.sv_maxuser = VM_MAXUSER_ADDRESS - PAGE_SIZE,
|
||||||
|
|||||||
@@ -740,6 +740,9 @@ struct sysentvec elf_linux_sysvec = {
|
|||||||
.sv_szsigcode = &linux_szsigcode,
|
.sv_szsigcode = &linux_szsigcode,
|
||||||
.sv_name = "Linux ELF64",
|
.sv_name = "Linux ELF64",
|
||||||
.sv_coredump = elf64_coredump,
|
.sv_coredump = elf64_coredump,
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_NONE,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = elf64_prepare_notes,
|
||||||
.sv_imgact_try = linux_exec_imgact_try,
|
.sv_imgact_try = linux_exec_imgact_try,
|
||||||
.sv_minsigstksz = LINUX_MINSIGSTKSZ,
|
.sv_minsigstksz = LINUX_MINSIGSTKSZ,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
|
|||||||
@@ -912,6 +912,9 @@ struct sysentvec elf_linux_sysvec = {
|
|||||||
.sv_szsigcode = &linux_szsigcode,
|
.sv_szsigcode = &linux_szsigcode,
|
||||||
.sv_name = "Linux ELF32",
|
.sv_name = "Linux ELF32",
|
||||||
.sv_coredump = elf32_coredump,
|
.sv_coredump = elf32_coredump,
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = elf32_prepare_notes,
|
||||||
.sv_imgact_try = linux_exec_imgact_try,
|
.sv_imgact_try = linux_exec_imgact_try,
|
||||||
.sv_minsigstksz = LINUX_MINSIGSTKSZ,
|
.sv_minsigstksz = LINUX_MINSIGSTKSZ,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ struct sysentvec elf32_freebsd_sysvec = {
|
|||||||
.sv_szsigcode = &szsigcode,
|
.sv_szsigcode = &szsigcode,
|
||||||
.sv_name = "FreeBSD ELF32",
|
.sv_name = "FreeBSD ELF32",
|
||||||
.sv_coredump = __elfN(coredump),
|
.sv_coredump = __elfN(coredump),
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = __elfN(prepare_notes),
|
||||||
.sv_imgact_try = NULL,
|
.sv_imgact_try = NULL,
|
||||||
.sv_minsigstksz = MINSIGSTKSZ,
|
.sv_minsigstksz = MINSIGSTKSZ,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
|
|||||||
@@ -173,6 +173,9 @@ static struct sysentvec cloudabi32_elf_sysvec = {
|
|||||||
.sv_fixup = cloudabi32_fixup,
|
.sv_fixup = cloudabi32_fixup,
|
||||||
.sv_name = "CloudABI ELF32",
|
.sv_name = "CloudABI ELF32",
|
||||||
.sv_coredump = elf32_coredump,
|
.sv_coredump = elf32_coredump,
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = elf32_prepare_notes,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
.sv_maxuser = VM_MAXUSER_ADDRESS,
|
.sv_maxuser = VM_MAXUSER_ADDRESS,
|
||||||
.sv_stackprot = VM_PROT_READ | VM_PROT_WRITE,
|
.sv_stackprot = VM_PROT_READ | VM_PROT_WRITE,
|
||||||
|
|||||||
@@ -87,6 +87,9 @@ static struct sysentvec elf32_freebsd_sysvec = {
|
|||||||
.sv_szsigcode = &sz_aarch32_sigcode,
|
.sv_szsigcode = &sz_aarch32_sigcode,
|
||||||
.sv_name = "FreeBSD ELF32",
|
.sv_name = "FreeBSD ELF32",
|
||||||
.sv_coredump = elf32_coredump,
|
.sv_coredump = elf32_coredump,
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = elf32_prepare_notes,
|
||||||
.sv_imgact_try = NULL,
|
.sv_imgact_try = NULL,
|
||||||
.sv_minsigstksz = MINSIGSTKSZ,
|
.sv_minsigstksz = MINSIGSTKSZ,
|
||||||
.sv_minuser = FREEBSD32_MINUSER,
|
.sv_minuser = FREEBSD32_MINUSER,
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ static struct sysentvec elf64_freebsd_sysvec = {
|
|||||||
.sv_szsigcode = &szsigcode,
|
.sv_szsigcode = &szsigcode,
|
||||||
.sv_name = "FreeBSD ELF64",
|
.sv_name = "FreeBSD ELF64",
|
||||||
.sv_coredump = __elfN(coredump),
|
.sv_coredump = __elfN(coredump),
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = __elfN(prepare_notes),
|
||||||
.sv_imgact_try = NULL,
|
.sv_imgact_try = NULL,
|
||||||
.sv_minsigstksz = MINSIGSTKSZ,
|
.sv_minsigstksz = MINSIGSTKSZ,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
|
|||||||
@@ -181,6 +181,9 @@ static struct sysentvec cloudabi32_elf_sysvec = {
|
|||||||
.sv_fixup = cloudabi32_fixup,
|
.sv_fixup = cloudabi32_fixup,
|
||||||
.sv_name = "CloudABI ELF32",
|
.sv_name = "CloudABI ELF32",
|
||||||
.sv_coredump = elf32_coredump,
|
.sv_coredump = elf32_coredump,
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = elf32_prepare_notes,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
.sv_maxuser = (uintmax_t)1 << 32,
|
.sv_maxuser = (uintmax_t)1 << 32,
|
||||||
.sv_stackprot = VM_PROT_READ | VM_PROT_WRITE,
|
.sv_stackprot = VM_PROT_READ | VM_PROT_WRITE,
|
||||||
|
|||||||
@@ -165,6 +165,9 @@ static struct sysentvec cloudabi64_elf_sysvec = {
|
|||||||
.sv_fixup = cloudabi64_fixup,
|
.sv_fixup = cloudabi64_fixup,
|
||||||
.sv_name = "CloudABI ELF64",
|
.sv_name = "CloudABI ELF64",
|
||||||
.sv_coredump = elf64_coredump,
|
.sv_coredump = elf64_coredump,
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = elf64_prepare_notes,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
.sv_maxuser = VM_MAXUSER_ADDRESS,
|
.sv_maxuser = VM_MAXUSER_ADDRESS,
|
||||||
.sv_stackprot = VM_PROT_READ | VM_PROT_WRITE,
|
.sv_stackprot = VM_PROT_READ | VM_PROT_WRITE,
|
||||||
|
|||||||
@@ -416,6 +416,9 @@ struct sysentvec elf_linux_sysvec = {
|
|||||||
.sv_szsigcode = &linux_szsigcode,
|
.sv_szsigcode = &linux_szsigcode,
|
||||||
.sv_name = "Linux ELF64",
|
.sv_name = "Linux ELF64",
|
||||||
.sv_coredump = elf64_coredump,
|
.sv_coredump = elf64_coredump,
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_NONE,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = elf64_prepare_notes,
|
||||||
.sv_imgact_try = linux_exec_imgact_try,
|
.sv_imgact_try = linux_exec_imgact_try,
|
||||||
.sv_minsigstksz = LINUX_MINSIGSTKSZ,
|
.sv_minsigstksz = LINUX_MINSIGSTKSZ,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
|
|||||||
@@ -105,6 +105,9 @@ struct sysentvec ia32_freebsd_sysvec = {
|
|||||||
.sv_szsigcode = &sz_ia32_sigcode,
|
.sv_szsigcode = &sz_ia32_sigcode,
|
||||||
.sv_name = "FreeBSD ELF32",
|
.sv_name = "FreeBSD ELF32",
|
||||||
.sv_coredump = elf32_coredump,
|
.sv_coredump = elf32_coredump,
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = elf32_prepare_notes,
|
||||||
.sv_imgact_try = NULL,
|
.sv_imgact_try = NULL,
|
||||||
.sv_minsigstksz = MINSIGSTKSZ,
|
.sv_minsigstksz = MINSIGSTKSZ,
|
||||||
.sv_minuser = FREEBSD32_MINUSER,
|
.sv_minuser = FREEBSD32_MINUSER,
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ struct sysentvec elf32_freebsd_sysvec = {
|
|||||||
.sv_szsigcode = &szsigcode,
|
.sv_szsigcode = &szsigcode,
|
||||||
.sv_name = "FreeBSD ELF32",
|
.sv_name = "FreeBSD ELF32",
|
||||||
.sv_coredump = __elfN(coredump),
|
.sv_coredump = __elfN(coredump),
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = __elfN(prepare_notes),
|
||||||
.sv_imgact_try = NULL,
|
.sv_imgact_try = NULL,
|
||||||
.sv_minsigstksz = MINSIGSTKSZ,
|
.sv_minsigstksz = MINSIGSTKSZ,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
|
|||||||
@@ -854,6 +854,9 @@ struct sysentvec elf_linux_sysvec = {
|
|||||||
.sv_szsigcode = &linux_szsigcode,
|
.sv_szsigcode = &linux_szsigcode,
|
||||||
.sv_name = "Linux ELF32",
|
.sv_name = "Linux ELF32",
|
||||||
.sv_coredump = elf32_coredump,
|
.sv_coredump = elf32_coredump,
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = elf32_prepare_notes,
|
||||||
.sv_imgact_try = linux_exec_imgact_try,
|
.sv_imgact_try = linux_exec_imgact_try,
|
||||||
.sv_minsigstksz = LINUX_MINSIGSTKSZ,
|
.sv_minsigstksz = LINUX_MINSIGSTKSZ,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
|
|||||||
+33
-33
@@ -197,8 +197,6 @@ static Elf_Brandinfo *elf_brand_list[MAX_BRANDS];
|
|||||||
|
|
||||||
#define aligned(a, t) (rounddown2((u_long)(a), sizeof(t)) == (u_long)(a))
|
#define aligned(a, t) (rounddown2((u_long)(a), sizeof(t)) == (u_long)(a))
|
||||||
|
|
||||||
static const char FREEBSD_ABI_VENDOR[] = "FreeBSD";
|
|
||||||
|
|
||||||
Elf_Brandnote __elfN(freebsd_brandnote) = {
|
Elf_Brandnote __elfN(freebsd_brandnote) = {
|
||||||
.hdr.n_namesz = sizeof(FREEBSD_ABI_VENDOR),
|
.hdr.n_namesz = sizeof(FREEBSD_ABI_VENDOR),
|
||||||
.hdr.n_descsz = sizeof(int32_t),
|
.hdr.n_descsz = sizeof(int32_t),
|
||||||
@@ -1434,8 +1432,6 @@ struct phdr_closure {
|
|||||||
Elf_Off offset; /* Offset of segment in core file */
|
Elf_Off offset; /* Offset of segment in core file */
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*outfunc_t)(void *, struct sbuf *, size_t *);
|
|
||||||
|
|
||||||
struct note_info {
|
struct note_info {
|
||||||
int type; /* Note type. */
|
int type; /* Note type. */
|
||||||
outfunc_t outfunc; /* Output function. */
|
outfunc_t outfunc; /* Output function. */
|
||||||
@@ -1455,10 +1451,7 @@ static void each_dumpable_segment(struct thread *, segment_callback, void *,
|
|||||||
int);
|
int);
|
||||||
static int __elfN(corehdr)(struct coredump_params *, int, void *, size_t,
|
static int __elfN(corehdr)(struct coredump_params *, int, void *, size_t,
|
||||||
struct note_info_list *, size_t, int);
|
struct note_info_list *, size_t, int);
|
||||||
static void __elfN(prepare_notes)(struct thread *, struct note_info_list *,
|
static void __elfN(putnote)(struct thread *td, struct note_info *, struct sbuf *);
|
||||||
size_t *);
|
|
||||||
static void __elfN(putnote)(struct note_info *, struct sbuf *);
|
|
||||||
static size_t register_note(struct note_info_list *, int, outfunc_t, void *);
|
|
||||||
|
|
||||||
static void __elfN(note_fpregset)(void *, struct sbuf *, size_t *);
|
static void __elfN(note_fpregset)(void *, struct sbuf *, size_t *);
|
||||||
static void __elfN(note_prpsinfo)(void *, struct sbuf *, size_t *);
|
static void __elfN(note_prpsinfo)(void *, struct sbuf *, size_t *);
|
||||||
@@ -1509,7 +1502,7 @@ __elfN(coredump)(struct thread *td, struct vnode *vp, off_t limit, int flags)
|
|||||||
hdrsize = sizeof(Elf_Ehdr) + sizeof(Elf_Phdr) * (1 + seginfo.count);
|
hdrsize = sizeof(Elf_Ehdr) + sizeof(Elf_Phdr) * (1 + seginfo.count);
|
||||||
if (seginfo.count + 1 >= PN_XNUM)
|
if (seginfo.count + 1 >= PN_XNUM)
|
||||||
hdrsize += sizeof(Elf_Shdr);
|
hdrsize += sizeof(Elf_Shdr);
|
||||||
__elfN(prepare_notes)(td, ¬elst, ¬esz);
|
td->td_proc->p_sysent->sv_elf_core_prepare_notes(td, ¬elst, ¬esz);
|
||||||
coresize = round_page(hdrsize + notesz) + seginfo.size;
|
coresize = round_page(hdrsize + notesz) + seginfo.size;
|
||||||
|
|
||||||
/* Set up core dump parameters. */
|
/* Set up core dump parameters. */
|
||||||
@@ -1735,7 +1728,7 @@ __elfN(corehdr)(struct coredump_params *p, int numsegs, void *hdr,
|
|||||||
sbuf_start_section(sb, NULL);
|
sbuf_start_section(sb, NULL);
|
||||||
sbuf_bcat(sb, hdr, hdrsize);
|
sbuf_bcat(sb, hdr, hdrsize);
|
||||||
TAILQ_FOREACH(ninfo, notelst, link)
|
TAILQ_FOREACH(ninfo, notelst, link)
|
||||||
__elfN(putnote)(ninfo, sb);
|
__elfN(putnote)(p->td, ninfo, sb);
|
||||||
/* Align up to a page boundary for the program segments. */
|
/* Align up to a page boundary for the program segments. */
|
||||||
sbuf_end_section(sb, -1, PAGE_SIZE, 0);
|
sbuf_end_section(sb, -1, PAGE_SIZE, 0);
|
||||||
error = sbuf_finish(sb);
|
error = sbuf_finish(sb);
|
||||||
@@ -1744,7 +1737,7 @@ __elfN(corehdr)(struct coredump_params *p, int numsegs, void *hdr,
|
|||||||
return (error);
|
return (error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
__elfN(prepare_notes)(struct thread *td, struct note_info_list *list,
|
__elfN(prepare_notes)(struct thread *td, struct note_info_list *list,
|
||||||
size_t *sizep)
|
size_t *sizep)
|
||||||
{
|
{
|
||||||
@@ -1755,7 +1748,7 @@ __elfN(prepare_notes)(struct thread *td, struct note_info_list *list,
|
|||||||
p = td->td_proc;
|
p = td->td_proc;
|
||||||
size = 0;
|
size = 0;
|
||||||
|
|
||||||
size += register_note(list, NT_PRPSINFO, __elfN(note_prpsinfo), p);
|
size += __elfN(register_note)(td, list, NT_PRPSINFO, __elfN(note_prpsinfo), p);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* To have the debugger select the right thread (LWP) as the initial
|
* To have the debugger select the right thread (LWP) as the initial
|
||||||
@@ -1765,15 +1758,15 @@ __elfN(prepare_notes)(struct thread *td, struct note_info_list *list,
|
|||||||
*/
|
*/
|
||||||
thr = td;
|
thr = td;
|
||||||
while (thr != NULL) {
|
while (thr != NULL) {
|
||||||
size += register_note(list, NT_PRSTATUS,
|
size += __elfN(register_note)(td, list, NT_PRSTATUS,
|
||||||
__elfN(note_prstatus), thr);
|
__elfN(note_prstatus), thr);
|
||||||
size += register_note(list, NT_FPREGSET,
|
size += __elfN(register_note)(td, list, NT_FPREGSET,
|
||||||
__elfN(note_fpregset), thr);
|
__elfN(note_fpregset), thr);
|
||||||
size += register_note(list, NT_THRMISC,
|
size += __elfN(register_note)(td, list, NT_THRMISC,
|
||||||
__elfN(note_thrmisc), thr);
|
__elfN(note_thrmisc), thr);
|
||||||
size += register_note(list, NT_PTLWPINFO,
|
size += __elfN(register_note)(td, list, NT_PTLWPINFO,
|
||||||
__elfN(note_ptlwpinfo), thr);
|
__elfN(note_ptlwpinfo), thr);
|
||||||
size += register_note(list, -1,
|
size += __elfN(register_note)(td, list, -1,
|
||||||
__elfN(note_threadmd), thr);
|
__elfN(note_threadmd), thr);
|
||||||
|
|
||||||
thr = thr == td ? TAILQ_FIRST(&p->p_threads) :
|
thr = thr == td ? TAILQ_FIRST(&p->p_threads) :
|
||||||
@@ -1782,23 +1775,23 @@ __elfN(prepare_notes)(struct thread *td, struct note_info_list *list,
|
|||||||
thr = TAILQ_NEXT(thr, td_plist);
|
thr = TAILQ_NEXT(thr, td_plist);
|
||||||
}
|
}
|
||||||
|
|
||||||
size += register_note(list, NT_PROCSTAT_PROC,
|
size += __elfN(register_note)(td, list, NT_PROCSTAT_PROC,
|
||||||
__elfN(note_procstat_proc), p);
|
__elfN(note_procstat_proc), p);
|
||||||
size += register_note(list, NT_PROCSTAT_FILES,
|
size += __elfN(register_note)(td, list, NT_PROCSTAT_FILES,
|
||||||
note_procstat_files, p);
|
note_procstat_files, p);
|
||||||
size += register_note(list, NT_PROCSTAT_VMMAP,
|
size += __elfN(register_note)(td, list, NT_PROCSTAT_VMMAP,
|
||||||
note_procstat_vmmap, p);
|
note_procstat_vmmap, p);
|
||||||
size += register_note(list, NT_PROCSTAT_GROUPS,
|
size += __elfN(register_note)(td, list, NT_PROCSTAT_GROUPS,
|
||||||
note_procstat_groups, p);
|
note_procstat_groups, p);
|
||||||
size += register_note(list, NT_PROCSTAT_UMASK,
|
size += __elfN(register_note)(td, list, NT_PROCSTAT_UMASK,
|
||||||
note_procstat_umask, p);
|
note_procstat_umask, p);
|
||||||
size += register_note(list, NT_PROCSTAT_RLIMIT,
|
size += __elfN(register_note)(td, list, NT_PROCSTAT_RLIMIT,
|
||||||
note_procstat_rlimit, p);
|
note_procstat_rlimit, p);
|
||||||
size += register_note(list, NT_PROCSTAT_OSREL,
|
size += __elfN(register_note)(td, list, NT_PROCSTAT_OSREL,
|
||||||
note_procstat_osrel, p);
|
note_procstat_osrel, p);
|
||||||
size += register_note(list, NT_PROCSTAT_PSSTRINGS,
|
size += __elfN(register_note)(td, list, NT_PROCSTAT_PSSTRINGS,
|
||||||
__elfN(note_procstat_psstrings), p);
|
__elfN(note_procstat_psstrings), p);
|
||||||
size += register_note(list, NT_PROCSTAT_AUXV,
|
size += __elfN(register_note)(td, list, NT_PROCSTAT_AUXV,
|
||||||
__elfN(note_procstat_auxv), p);
|
__elfN(note_procstat_auxv), p);
|
||||||
|
|
||||||
*sizep = size;
|
*sizep = size;
|
||||||
@@ -1822,7 +1815,7 @@ __elfN(puthdr)(struct thread *td, void *hdr, size_t hdrsize, int numsegs,
|
|||||||
ehdr->e_ident[EI_CLASS] = ELF_CLASS;
|
ehdr->e_ident[EI_CLASS] = ELF_CLASS;
|
||||||
ehdr->e_ident[EI_DATA] = ELF_DATA;
|
ehdr->e_ident[EI_DATA] = ELF_DATA;
|
||||||
ehdr->e_ident[EI_VERSION] = EV_CURRENT;
|
ehdr->e_ident[EI_VERSION] = EV_CURRENT;
|
||||||
ehdr->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
|
ehdr->e_ident[EI_OSABI] = td->td_proc->p_sysent->sv_elf_core_osabi;
|
||||||
ehdr->e_ident[EI_ABIVERSION] = 0;
|
ehdr->e_ident[EI_ABIVERSION] = 0;
|
||||||
ehdr->e_ident[EI_PAD] = 0;
|
ehdr->e_ident[EI_PAD] = 0;
|
||||||
ehdr->e_type = ET_CORE;
|
ehdr->e_type = ET_CORE;
|
||||||
@@ -1888,12 +1881,15 @@ __elfN(puthdr)(struct thread *td, void *hdr, size_t hdrsize, int numsegs,
|
|||||||
each_dumpable_segment(td, cb_put_phdr, &phc, flags);
|
each_dumpable_segment(td, cb_put_phdr, &phc, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
size_t
|
||||||
register_note(struct note_info_list *list, int type, outfunc_t out, void *arg)
|
__elfN(register_note)(struct thread *td, struct note_info_list *list,
|
||||||
|
int type, outfunc_t out, void *arg)
|
||||||
{
|
{
|
||||||
|
const struct sysentvec *sv;
|
||||||
struct note_info *ninfo;
|
struct note_info *ninfo;
|
||||||
size_t size, notesize;
|
size_t size, notesize;
|
||||||
|
|
||||||
|
sv = td->td_proc->p_sysent;
|
||||||
size = 0;
|
size = 0;
|
||||||
out(arg, NULL, &size);
|
out(arg, NULL, &size);
|
||||||
ninfo = malloc(sizeof(*ninfo), M_TEMP, M_ZERO | M_WAITOK);
|
ninfo = malloc(sizeof(*ninfo), M_TEMP, M_ZERO | M_WAITOK);
|
||||||
@@ -1907,7 +1903,7 @@ register_note(struct note_info_list *list, int type, outfunc_t out, void *arg)
|
|||||||
return (size);
|
return (size);
|
||||||
|
|
||||||
notesize = sizeof(Elf_Note) + /* note header */
|
notesize = sizeof(Elf_Note) + /* note header */
|
||||||
roundup2(sizeof(FREEBSD_ABI_VENDOR), ELF_NOTE_ROUNDSIZE) +
|
roundup2(strlen(sv->sv_elf_core_abi_vendor) + 1, ELF_NOTE_ROUNDSIZE) +
|
||||||
/* note name */
|
/* note name */
|
||||||
roundup2(size, ELF_NOTE_ROUNDSIZE); /* note description */
|
roundup2(size, ELF_NOTE_ROUNDSIZE); /* note description */
|
||||||
|
|
||||||
@@ -1957,9 +1953,10 @@ __elfN(populate_note)(int type, void *src, void *dst, size_t size, void **descp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
__elfN(putnote)(struct note_info *ninfo, struct sbuf *sb)
|
__elfN(putnote)(struct thread *td, struct note_info *ninfo, struct sbuf *sb)
|
||||||
{
|
{
|
||||||
Elf_Note note;
|
Elf_Note note;
|
||||||
|
const struct sysentvec *sv;
|
||||||
ssize_t old_len, sect_len;
|
ssize_t old_len, sect_len;
|
||||||
size_t new_len, descsz, i;
|
size_t new_len, descsz, i;
|
||||||
|
|
||||||
@@ -1968,13 +1965,16 @@ __elfN(putnote)(struct note_info *ninfo, struct sbuf *sb)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
note.n_namesz = sizeof(FREEBSD_ABI_VENDOR);
|
sv = td->td_proc->p_sysent;
|
||||||
|
|
||||||
|
note.n_namesz = strlen(sv->sv_elf_core_abi_vendor) + 1;
|
||||||
note.n_descsz = ninfo->outsize;
|
note.n_descsz = ninfo->outsize;
|
||||||
note.n_type = ninfo->type;
|
note.n_type = ninfo->type;
|
||||||
|
|
||||||
sbuf_bcat(sb, ¬e, sizeof(note));
|
sbuf_bcat(sb, ¬e, sizeof(note));
|
||||||
sbuf_start_section(sb, &old_len);
|
sbuf_start_section(sb, &old_len);
|
||||||
sbuf_bcat(sb, FREEBSD_ABI_VENDOR, sizeof(FREEBSD_ABI_VENDOR));
|
sbuf_bcat(sb, sv->sv_elf_core_abi_vendor,
|
||||||
|
strlen(sv->sv_elf_core_abi_vendor) + 1);
|
||||||
sbuf_end_section(sb, old_len, ELF_NOTE_ROUNDSIZE, 0);
|
sbuf_end_section(sb, old_len, ELF_NOTE_ROUNDSIZE, 0);
|
||||||
if (note.n_descsz == 0)
|
if (note.n_descsz == 0)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ static struct sysentvec elf_freebsd_sysvec = {
|
|||||||
.sv_name = "FreeBSD ELF32",
|
.sv_name = "FreeBSD ELF32",
|
||||||
#endif
|
#endif
|
||||||
.sv_coredump = __elfN(coredump),
|
.sv_coredump = __elfN(coredump),
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = __elfN(prepare_notes),
|
||||||
.sv_imgact_try = NULL,
|
.sv_imgact_try = NULL,
|
||||||
.sv_minsigstksz = MINSIGSTKSZ,
|
.sv_minsigstksz = MINSIGSTKSZ,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
|
|||||||
@@ -85,6 +85,9 @@ struct sysentvec elf32_freebsd_sysvec = {
|
|||||||
.sv_szsigcode = &szsigcode32,
|
.sv_szsigcode = &szsigcode32,
|
||||||
.sv_name = "FreeBSD ELF32",
|
.sv_name = "FreeBSD ELF32",
|
||||||
.sv_coredump = __elfN(coredump),
|
.sv_coredump = __elfN(coredump),
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = __elfN(prepare_notes),
|
||||||
.sv_imgact_try = NULL,
|
.sv_imgact_try = NULL,
|
||||||
.sv_minsigstksz = MINSIGSTKSZ,
|
.sv_minsigstksz = MINSIGSTKSZ,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
|
|||||||
@@ -98,6 +98,9 @@ struct sysentvec elf32_freebsd_sysvec = {
|
|||||||
.sv_szsigcode = &szsigcode32,
|
.sv_szsigcode = &szsigcode32,
|
||||||
.sv_name = "FreeBSD ELF32",
|
.sv_name = "FreeBSD ELF32",
|
||||||
.sv_coredump = __elfN(coredump),
|
.sv_coredump = __elfN(coredump),
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = __elfN(prepare_notes),
|
||||||
.sv_imgact_try = NULL,
|
.sv_imgact_try = NULL,
|
||||||
.sv_minsigstksz = MINSIGSTKSZ,
|
.sv_minsigstksz = MINSIGSTKSZ,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
|
|||||||
@@ -69,6 +69,9 @@ struct sysentvec elf64_freebsd_sysvec_v1 = {
|
|||||||
.sv_szsigcode = &szsigcode64,
|
.sv_szsigcode = &szsigcode64,
|
||||||
.sv_name = "FreeBSD ELF64",
|
.sv_name = "FreeBSD ELF64",
|
||||||
.sv_coredump = __elfN(coredump),
|
.sv_coredump = __elfN(coredump),
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = __elfN(prepare_notes),
|
||||||
.sv_imgact_try = NULL,
|
.sv_imgact_try = NULL,
|
||||||
.sv_minsigstksz = MINSIGSTKSZ,
|
.sv_minsigstksz = MINSIGSTKSZ,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
@@ -105,6 +108,9 @@ struct sysentvec elf64_freebsd_sysvec_v2 = {
|
|||||||
.sv_szsigcode = &szsigcode64,
|
.sv_szsigcode = &szsigcode64,
|
||||||
.sv_name = "FreeBSD ELF64 V2",
|
.sv_name = "FreeBSD ELF64 V2",
|
||||||
.sv_coredump = __elfN(coredump),
|
.sv_coredump = __elfN(coredump),
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = __elfN(prepare_notes),
|
||||||
.sv_imgact_try = NULL,
|
.sv_imgact_try = NULL,
|
||||||
.sv_minsigstksz = MINSIGSTKSZ,
|
.sv_minsigstksz = MINSIGSTKSZ,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ struct sysentvec elf64_freebsd_sysvec = {
|
|||||||
.sv_szsigcode = &szsigcode,
|
.sv_szsigcode = &szsigcode,
|
||||||
.sv_name = "FreeBSD ELF64",
|
.sv_name = "FreeBSD ELF64",
|
||||||
.sv_coredump = __elfN(coredump),
|
.sv_coredump = __elfN(coredump),
|
||||||
|
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
|
||||||
|
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
|
||||||
|
.sv_elf_core_prepare_notes = __elfN(prepare_notes),
|
||||||
.sv_imgact_try = NULL,
|
.sv_imgact_try = NULL,
|
||||||
.sv_minsigstksz = MINSIGSTKSZ,
|
.sv_minsigstksz = MINSIGSTKSZ,
|
||||||
.sv_minuser = VM_MIN_ADDRESS,
|
.sv_minuser = VM_MIN_ADDRESS,
|
||||||
|
|||||||
@@ -50,6 +50,8 @@
|
|||||||
struct image_params;
|
struct image_params;
|
||||||
struct thread;
|
struct thread;
|
||||||
struct vnode;
|
struct vnode;
|
||||||
|
struct note_info_list;
|
||||||
|
struct sbuf;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Structure used to pass information from the loader to the
|
* Structure used to pass information from the loader to the
|
||||||
@@ -99,6 +101,9 @@ __ElfType(Auxargs);
|
|||||||
__ElfType(Brandinfo);
|
__ElfType(Brandinfo);
|
||||||
|
|
||||||
#define MAX_BRANDS 8
|
#define MAX_BRANDS 8
|
||||||
|
#define FREEBSD_ABI_VENDOR "FreeBSD"
|
||||||
|
|
||||||
|
typedef void (*outfunc_t)(void *, struct sbuf *, size_t *);
|
||||||
|
|
||||||
/* Closure for __elfN(size_segments)(). */
|
/* Closure for __elfN(size_segments)(). */
|
||||||
struct sseg_closure {
|
struct sseg_closure {
|
||||||
@@ -115,7 +120,11 @@ size_t __elfN(populate_note)(int, void *, void *, size_t, void **);
|
|||||||
void __elfN(stackgap)(struct image_params *, uintptr_t *);
|
void __elfN(stackgap)(struct image_params *, uintptr_t *);
|
||||||
int __elfN(freebsd_copyout_auxargs)(struct image_params *, uintptr_t);
|
int __elfN(freebsd_copyout_auxargs)(struct image_params *, uintptr_t);
|
||||||
void __elfN(puthdr)(struct thread *, void *, size_t, int, size_t, int);
|
void __elfN(puthdr)(struct thread *, void *, size_t, int, size_t, int);
|
||||||
|
void __elfN(prepare_notes)(struct thread *, struct note_info_list *,
|
||||||
|
size_t *);
|
||||||
void __elfN(size_segments)(struct thread *, struct sseg_closure *, int);
|
void __elfN(size_segments)(struct thread *, struct sseg_closure *, int);
|
||||||
|
size_t __elfN(register_note)(struct thread *, struct note_info_list *,
|
||||||
|
int, outfunc_t, void *);
|
||||||
|
|
||||||
/* Machine specific function to dump per-thread information. */
|
/* Machine specific function to dump per-thread information. */
|
||||||
void __elfN(dump_thread)(struct thread *, void *, size_t *);
|
void __elfN(dump_thread)(struct thread *, void *, size_t *);
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ struct proc;
|
|||||||
struct __sigset;
|
struct __sigset;
|
||||||
struct trapframe;
|
struct trapframe;
|
||||||
struct vnode;
|
struct vnode;
|
||||||
|
struct note_info_list;
|
||||||
|
|
||||||
struct sysentvec {
|
struct sysentvec {
|
||||||
int sv_size; /* number of entries */
|
int sv_size; /* number of entries */
|
||||||
@@ -113,6 +114,10 @@ struct sysentvec {
|
|||||||
char *sv_name; /* name of binary type */
|
char *sv_name; /* name of binary type */
|
||||||
int (*sv_coredump)(struct thread *, struct vnode *, off_t, int);
|
int (*sv_coredump)(struct thread *, struct vnode *, off_t, int);
|
||||||
/* function to dump core, or NULL */
|
/* function to dump core, or NULL */
|
||||||
|
int sv_elf_core_osabi;
|
||||||
|
const char *sv_elf_core_abi_vendor;
|
||||||
|
void (*sv_elf_core_prepare_notes)(struct thread *,
|
||||||
|
struct note_info_list *, size_t *);
|
||||||
int (*sv_imgact_try)(struct image_params *);
|
int (*sv_imgact_try)(struct image_params *);
|
||||||
void (*sv_stackgap)(struct image_params *, uintptr_t *);
|
void (*sv_stackgap)(struct image_params *, uintptr_t *);
|
||||||
int (*sv_copyout_auxargs)(struct image_params *,
|
int (*sv_copyout_auxargs)(struct image_params *,
|
||||||
|
|||||||
Reference in New Issue
Block a user