diff --git a/sys/kern/kern_ctf.c b/sys/kern/kern_ctf.c --- a/sys/kern/kern_ctf.c +++ b/sys/kern/kern_ctf.c @@ -28,16 +28,11 @@ * $FreeBSD$ */ +#include + /* * Note this file is included by both link_elf.c and link_elf_obj.c. - * - * The CTF header structure definition can't be used here because it's - * (annoyingly) covered by the CDDL. We will just use a few bytes from - * it as an integer array where we 'know' what they mean. */ -#define CTF_HDR_SIZE 36 -#define CTF_HDR_STRTAB_U32 7 -#define CTF_HDR_STRLEN_U32 8 #ifdef DDB_CTF #include @@ -59,7 +54,7 @@ size_t sz; struct nameidata nd; struct thread *td = curthread; - uint8_t ctf_hdr[CTF_HDR_SIZE]; + struct ctf_header cth; #endif int error = 0; @@ -174,17 +169,13 @@ } /* Read the CTF header. */ - if ((error = vn_rdwr(UIO_READ, nd.ni_vp, ctf_hdr, sizeof(ctf_hdr), + if ((error = vn_rdwr(UIO_READ, nd.ni_vp, &cth, sizeof(cth), shdr[i].sh_offset, UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED, NULL, td)) != 0) goto out; /* Check the CTF magic number. */ -#ifdef __LITTLE_ENDIAN__ - if (ctf_hdr[0] != 0xf1 || ctf_hdr[1] != 0xcf) { -#else - if (ctf_hdr[0] != 0xcf || ctf_hdr[1] != 0xf1) { -#endif + if (cth.cth_magic != CTF_MAGIC) { printf("%s(%d): module %s has invalid format\n", __func__, __LINE__, lf->pathname); error = EFTYPE; @@ -192,27 +183,24 @@ } /* Check if version 2. */ - if (ctf_hdr[2] != 2) { + if (cth.cth_version != CTF_VERSION_2) { printf("%s(%d): module %s CTF format version is %d " "(2 expected)\n", - __func__, __LINE__, lf->pathname, ctf_hdr[2]); + __func__, __LINE__, lf->pathname, cth.cth_version); error = EFTYPE; goto out; } /* Check if the data is compressed. */ - if ((ctf_hdr[3] & 0x1) != 0) { - uint32_t *u32 = (uint32_t *) ctf_hdr; - + if ((cth.cth_flags & CTF_F_COMPRESS) != 0) { /* * The last two fields in the CTF header are the offset * from the end of the header to the start of the string - * data and the length of that string data. se this + * data and the length of that string data. Use this * information to determine the decompressed CTF data * buffer required. */ - sz = u32[CTF_HDR_STRTAB_U32] + u32[CTF_HDR_STRLEN_U32] + - sizeof(ctf_hdr); + sz = cth.cth_stroff + cth.cth_strlen + sizeof(cth); /* * Allocate memory for the compressed CTF data, including @@ -251,14 +239,14 @@ * The header isn't compressed, so copy that into the * CTF buffer first. */ - bcopy(ctf_hdr, ctftab, sizeof(ctf_hdr)); + bcopy(&cth, ctftab, sizeof(cth)); - destlen = sz - sizeof(ctf_hdr); - ret = uncompress(((uint8_t *) ctftab) + sizeof(ctf_hdr), - &destlen, ((uint8_t *) raw) + sizeof(ctf_hdr), - shdr[i].sh_size - sizeof(ctf_hdr)); + destlen = sz - sizeof(cth); + ret = uncompress(ctftab + sizeof(cth), &destlen, + raw + sizeof(cth), shdr[i].sh_size - sizeof(cth)); if (ret != Z_OK) { - printf("%s(%d): zlib uncompress returned %d\n", __func__, __LINE__, ret); + printf("%s(%d): zlib uncompress returned %d\n", + __func__, __LINE__, ret); error = EIO; goto out; }