Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_ctf.c
Show All 34 Lines | |||||
* (annoyingly) covered by the CDDL. We will just use a few bytes from | * (annoyingly) covered by the CDDL. We will just use a few bytes from | ||||
* it as an integer array where we 'know' what they mean. | * it as an integer array where we 'know' what they mean. | ||||
*/ | */ | ||||
#define CTF_HDR_SIZE 36 | #define CTF_HDR_SIZE 36 | ||||
#define CTF_HDR_STRTAB_U32 7 | #define CTF_HDR_STRTAB_U32 7 | ||||
#define CTF_HDR_STRLEN_U32 8 | #define CTF_HDR_STRLEN_U32 8 | ||||
#ifdef DDB_CTF | #ifdef DDB_CTF | ||||
static void * | #include <zlib.h> | ||||
z_alloc(void *nil, u_int items, u_int size) | |||||
{ | |||||
void *ptr; | |||||
ptr = malloc(items * size, M_TEMP, M_NOWAIT); | |||||
return ptr; | |||||
} | |||||
static void | |||||
z_free(void *nil, void *ptr) | |||||
{ | |||||
free(ptr, M_TEMP); | |||||
} | |||||
#endif | #endif | ||||
static int | static int | ||||
link_elf_ctf_get(linker_file_t lf, linker_ctf_t *lc) | link_elf_ctf_get(linker_file_t lf, linker_ctf_t *lc) | ||||
{ | { | ||||
#ifdef DDB_CTF | #ifdef DDB_CTF | ||||
Elf_Ehdr *hdr = NULL; | Elf_Ehdr *hdr = NULL; | ||||
Elf_Shdr *shdr = NULL; | Elf_Shdr *shdr = NULL; | ||||
▲ Show 20 Lines • Show All 183 Lines • ▼ Show 20 Lines | #ifdef DDB_CTF | ||||
*/ | */ | ||||
if ((error = vn_rdwr(UIO_READ, nd.ni_vp, raw == NULL ? ctftab : raw, | if ((error = vn_rdwr(UIO_READ, nd.ni_vp, raw == NULL ? ctftab : raw, | ||||
shdr[i].sh_size, shdr[i].sh_offset, UIO_SYSSPACE, IO_NODELOCKED, | shdr[i].sh_size, shdr[i].sh_offset, UIO_SYSSPACE, IO_NODELOCKED, | ||||
td->td_ucred, NOCRED, NULL, td)) != 0) | td->td_ucred, NOCRED, NULL, td)) != 0) | ||||
goto out; | goto out; | ||||
/* Check if decompression is required. */ | /* Check if decompression is required. */ | ||||
if (raw != NULL) { | if (raw != NULL) { | ||||
z_stream zs; | z_uLongf destLen; | ||||
int ret; | int ret; | ||||
/* | /* | ||||
* The header isn't compressed, so copy that into the | * The header isn't compressed, so copy that into the | ||||
* CTF buffer first. | * CTF buffer first. | ||||
*/ | */ | ||||
bcopy(ctf_hdr, ctftab, sizeof(ctf_hdr)); | bcopy(ctf_hdr, ctftab, sizeof(ctf_hdr)); | ||||
/* Initialise the zlib structure. */ | destLen = sz - sizeof(ctf_hdr); | ||||
bzero(&zs, sizeof(zs)); | ret = z_uncompress(((uint8_t *) ctftab) + sizeof(ctf_hdr), | ||||
zs.zalloc = z_alloc; | &destLen, ((uint8_t *) raw) + sizeof(ctf_hdr), | ||||
zs.zfree = z_free; | shdr[i].sh_size - sizeof(ctf_hdr)); | ||||
if (ret != Z_OK) { | |||||
if (inflateInit(&zs) != Z_OK) { | printf("%s(%d): zlib z_uncompress returned %d\n", __func__, __LINE__, ret); | ||||
error = EIO; | |||||
goto out; | |||||
} | |||||
zs.avail_in = shdr[i].sh_size - sizeof(ctf_hdr); | |||||
zs.next_in = ((uint8_t *) raw) + sizeof(ctf_hdr); | |||||
zs.avail_out = sz - sizeof(ctf_hdr); | |||||
zs.next_out = ((uint8_t *) ctftab) + sizeof(ctf_hdr); | |||||
ret = inflate(&zs, Z_FINISH); | |||||
inflateEnd(&zs); | |||||
if (ret != Z_STREAM_END) { | |||||
printf("%s(%d): zlib inflate returned %d\n", __func__, __LINE__, ret); | |||||
error = EIO; | error = EIO; | ||||
goto out; | goto out; | ||||
} | } | ||||
} | } | ||||
/* Got the CTF data! */ | /* Got the CTF data! */ | ||||
ef->ctftab = ctftab; | ef->ctftab = ctftab; | ||||
ef->ctfcnt = shdr[i].sh_size; | ef->ctfcnt = shdr[i].sh_size; | ||||
Show All 35 Lines |