diff options
author | Robert Mustacchi <rm@fingolfin.org> | 2021-07-31 18:32:39 -0700 |
---|---|---|
committer | Robert Mustacchi <rm@fingolfin.org> | 2021-11-11 14:12:38 -0800 |
commit | 8e458de0baeb1fee50643403223bc7e909a48464 (patch) | |
tree | 56fb55c9127badcfdd124858bc930e1f7ba693a5 /usr/src/common | |
parent | 1dee82f4f45d5f7651c78ce447f9829386d9d9c5 (diff) | |
download | illumos-joyent-8e458de0baeb1fee50643403223bc7e909a48464.tar.gz |
13925 core files should include DWARF
Reviewed by: Rich Lowe <richlowe@richlowe.net>
Reviewed by: C Fraire <cfraire@me.com>
Reviewed by: Adam Leventhal <adam.leventhal@gmail.com>
Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/common')
-rw-r--r-- | usr/src/common/core/core_shstrtab.c | 145 | ||||
-rw-r--r-- | usr/src/common/core/core_shstrtab.h | 73 |
2 files changed, 218 insertions, 0 deletions
diff --git a/usr/src/common/core/core_shstrtab.c b/usr/src/common/core/core_shstrtab.c new file mode 100644 index 0000000000..b1bcbce682 --- /dev/null +++ b/usr/src/common/core/core_shstrtab.c @@ -0,0 +1,145 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * Copyright 2021 Oxide Computer Company + */ + +#ifndef _KERNEL +#include <stdlib.h> +#include <strings.h> +#include <stddef.h> +#else +#include <sys/types.h> +#include <sys/kmem.h> +#include <sys/ddi.h> +#include <sys/sunddi.h> +#include <sys/stddef.h> +#endif /* _KERNEL */ + +#include <core_shstrtab.h> + +const char *shstrtab_data[STR_NUM] = { + "", + ".SUNW_ctf", + ".symtab", + ".dynsym", + ".strtab", + ".dynstr", + ".shstrtab" +}; + +static void * +shstrtab_alloc(void) +{ +#ifdef _KERNEL + return (kmem_zalloc(sizeof (shstrtab_ent_t), + KM_NOSLEEP | KM_NORMALPRI)); +#else + return (calloc(1, sizeof (shstrtab_ent_t))); +#endif +} + +static void +shstrtab_free(shstrtab_ent_t *ent) +{ +#ifdef _KERNEL + if (ent->sste_name != NULL) { + strfree(ent->sste_name); + } + kmem_free(ent, sizeof (*ent)); +#else + free(ent->sste_name); + free(ent); +#endif +} + + +boolean_t +shstrtab_ndx(shstrtab_t *s, const char *name, Elf32_Word *offp) +{ + shstrtab_ent_t *ent; + + for (ent = list_head(&s->sst_names); ent != NULL; + ent = list_next(&s->sst_names, ent)) { + if (strcmp(name, ent->sste_name) == 0) { + if (offp != NULL) + *offp = ent->sste_offset; + return (B_TRUE); + } + } + + ent = shstrtab_alloc(); + if (ent == NULL) { + return (B_FALSE); + } + + ent->sste_name = strdup(name); + if (ent->sste_name == NULL) { + shstrtab_free(ent); + return (B_FALSE); + } + ent->sste_len = strlen(name) + 1; + ent->sste_offset = s->sst_len; + s->sst_len += ent->sste_len; + + list_insert_tail(&s->sst_names, ent); + + if (offp != NULL) + *offp = ent->sste_offset; + return (B_TRUE); +} + +boolean_t +shstrtab_init(shstrtab_t *s) +{ + bzero(s, sizeof (*s)); + list_create(&s->sst_names, sizeof (shstrtab_ent_t), + offsetof(shstrtab_ent_t, sste_link)); + + return (shstrtab_ndx(s, shstrtab_data[STR_NONE], NULL)); +} + +void +shstrtab_fini(shstrtab_t *s) +{ + shstrtab_ent_t *ent; + + if (s->sst_len == 0) + return; + + while ((ent = list_remove_head(&s->sst_names)) != NULL) { + shstrtab_free(ent); + } +} + +size_t +shstrtab_size(const shstrtab_t *s) +{ + return (s->sst_len); +} + +void +shstrtab_dump(shstrtab_t *s, void *buf) +{ + size_t off = 0; + + for (shstrtab_ent_t *ent = list_head(&s->sst_names); ent != NULL; + ent = list_next(&s->sst_names, ent)) { + bcopy(ent->sste_name, buf + off, ent->sste_len); + off += ent->sste_len; + } +} diff --git a/usr/src/common/core/core_shstrtab.h b/usr/src/common/core/core_shstrtab.h new file mode 100644 index 0000000000..111c3226a8 --- /dev/null +++ b/usr/src/common/core/core_shstrtab.h @@ -0,0 +1,73 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * Copyright 2021 Oxide Computer Company + */ + +#ifndef _CORE_SHSTRTAB_H +#define _CORE_SHSTRTAB_H + +/* + * This header contains common definitions that are used to generate a + * shstrtab_t for core files. This is used by libproc and the kernel to generate + * core files in a similar way. + */ + +#include <sys/list.h> +#include <sys/stdint.h> +#include <sys/elf.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + STR_NONE, + STR_CTF, + STR_SYMTAB, + STR_DYNSYM, + STR_STRTAB, + STR_DYNSTR, + STR_SHSTRTAB, + STR_NUM +} shstrtype_t; + +extern const char *shstrtab_data[STR_NUM]; + +typedef struct shstrtab_ent { + list_node_t sste_link; + char *sste_name; + size_t sste_len; + uint32_t sste_offset; +} shstrtab_ent_t; + +typedef struct shstrtab { + list_t sst_names; + uint32_t sst_len; +} shstrtab_t; + +extern boolean_t shstrtab_init(shstrtab_t *s); +extern boolean_t shstrtab_ndx(shstrtab_t *, const char *, Elf32_Word *); +extern void shstrtab_fini(shstrtab_t *); +extern size_t shstrtab_size(const shstrtab_t *); +extern void shstrtab_dump(shstrtab_t *, void *); + +#ifdef __cplusplus +} +#endif + +#endif /* _CORE_SHSTRTAB_H */ |