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 | ||||
#include <zlib.h> | |||||
static void * | static void * | ||||
z_alloc(void *nil, u_int items, u_int size) | ctf_zalloc(void *nil, u_int items, u_int size) | ||||
{ | { | ||||
void *ptr; | void *ptr; | ||||
ptr = malloc(items * size, M_TEMP, M_NOWAIT); | ptr = malloc(items * size, M_TEMP, M_NOWAIT); /* HIRO - can we use kernl malloc/free? */ | ||||
return ptr; | return ptr; | ||||
} | } | ||||
static void | static void | ||||
z_free(void *nil, void *ptr) | ctf_zfree(void *nil, void *ptr) | ||||
{ | { | ||||
free(ptr, M_TEMP); | 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) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | if (raw != NULL) { | ||||
/* | /* | ||||
* 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. */ | /* Initialise the zlib structure. */ | ||||
bzero(&zs, sizeof(zs)); | bzero(&zs, sizeof(zs)); | ||||
zs.zalloc = z_alloc; | zs.zalloc = ctf_zalloc; | ||||
zs.zfree = z_free; | zs.zfree = ctf_zfree; | ||||
if (inflateInit(&zs) != Z_OK) { | if (z_inflateInit(&zs) != Z_OK) { | ||||
error = EIO; | error = EIO; | ||||
goto out; | goto out; | ||||
} | } | ||||
zs.avail_in = shdr[i].sh_size - sizeof(ctf_hdr); | zs.avail_in = shdr[i].sh_size - sizeof(ctf_hdr); | ||||
zs.next_in = ((uint8_t *) raw) + sizeof(ctf_hdr); | zs.next_in = ((uint8_t *) raw) + sizeof(ctf_hdr); | ||||
zs.avail_out = sz - sizeof(ctf_hdr); | zs.avail_out = sz - sizeof(ctf_hdr); | ||||
zs.next_out = ((uint8_t *) ctftab) + sizeof(ctf_hdr); | zs.next_out = ((uint8_t *) ctftab) + sizeof(ctf_hdr); | ||||
ret = inflate(&zs, Z_FINISH); | ret = z_inflate(&zs, Z_FINISH); | ||||
inflateEnd(&zs); | z_inflateEnd(&zs); | ||||
if (ret != Z_STREAM_END) { | if (ret != Z_STREAM_END) { | ||||
printf("%s(%d): zlib inflate returned %d\n", __func__, __LINE__, ret); | printf("%s(%d): zlib z_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 |