summaryrefslogtreecommitdiffstats
path: root/cddl/contrib/opensolaris/lib/libdtrace/common
diff options
context:
space:
mode:
Diffstat (limited to 'cddl/contrib/opensolaris/lib/libdtrace/common')
-rw-r--r--cddl/contrib/opensolaris/lib/libdtrace/common/drti.c124
-rw-r--r--cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c11
-rw-r--r--cddl/contrib/opensolaris/lib/libdtrace/common/dt_dof.c2
-rw-r--r--cddl/contrib/opensolaris/lib/libdtrace/common/dt_grammar.y23
-rw-r--r--cddl/contrib/opensolaris/lib/libdtrace/common/dt_impl.h5
-rw-r--r--cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c172
-rw-r--r--cddl/contrib/opensolaris/lib/libdtrace/common/dt_map.c5
-rw-r--r--cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c5
-rw-r--r--cddl/contrib/opensolaris/lib/libdtrace/common/dt_pid.c20
-rw-r--r--cddl/contrib/opensolaris/lib/libdtrace/common/dt_pragma.c1
-rw-r--r--cddl/contrib/opensolaris/lib/libdtrace/common/dt_print.c4
-rw-r--r--cddl/contrib/opensolaris/lib/libdtrace/common/dt_provider.c37
-rw-r--r--cddl/contrib/opensolaris/lib/libdtrace/common/dt_provider.h4
-rw-r--r--cddl/contrib/opensolaris/lib/libdtrace/common/dt_work.c9
14 files changed, 96 insertions, 326 deletions
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/drti.c b/cddl/contrib/opensolaris/lib/libdtrace/common/drti.c
index bb02d8c..ccd4f9b 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/drti.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/drti.c
@@ -90,36 +90,6 @@ dprintf(int debug, const char *fmt, ...)
va_end(ap);
}
-#if !defined(sun)
-static void
-fixsymbol(Elf *e, Elf_Data *data, size_t idx, int nprobes, char *buf,
- dof_sec_t *sec, int *fixedprobes, char *dofstrtab)
-{
- GElf_Sym sym;
- char *s;
- unsigned char *funcname;
- dof_probe_t *prb;
- int j = 0;
- int ndx;
-
- while (gelf_getsym(data, j++, &sym) != NULL) {
- prb = (dof_probe_t *)(void *)(buf + sec->dofs_offset);
-
- for (ndx = nprobes; ndx; ndx--, prb += 1) {
- funcname = dofstrtab + prb->dofpr_func;
- s = elf_strptr(e, idx, sym.st_name);
- if (strcmp(s, funcname) == 0) {
- dprintf(1, "fixing %s() symbol\n", s);
- prb->dofpr_addr = sym.st_value;
- (*fixedprobes)++;
- }
- }
- if (*fixedprobes == nprobes)
- break;
- }
-}
-#endif
-
#if defined(sun)
#pragma init(dtrace_dof_init)
#else
@@ -145,24 +115,18 @@ dtrace_dof_init(void)
Lmid_t lmid;
#else
u_long lmid = 0;
- dof_sec_t *sec, *secstart, *dofstrtab, *dofprobes;
- dof_provider_t *dofprovider;
- size_t i;
#endif
int fd;
const char *p;
#if !defined(sun)
Elf *e;
Elf_Scn *scn = NULL;
- Elf_Data *symtabdata = NULL, *dynsymdata = NULL, *dofdata = NULL;
+ Elf_Data *dofdata = NULL;
dof_hdr_t *dof_next = NULL;
GElf_Shdr shdr;
- int efd, nprobes;
+ int efd;
char *s;
- char *dofstrtabraw;
- size_t shstridx, symtabidx = 0, dynsymidx = 0;
- unsigned char *buf;
- int fixedprobes;
+ size_t shstridx;
#endif
if (getenv("DTRACE_DOF_INIT_DISABLE") != NULL)
@@ -183,7 +147,6 @@ dtrace_dof_init(void)
}
#endif
-
if ((modname = strrchr(lmp->l_name, '/')) == NULL)
modname = lmp->l_name;
else
@@ -203,15 +166,9 @@ dtrace_dof_init(void)
dof = NULL;
while ((scn = elf_nextscn(e, scn)) != NULL) {
gelf_getshdr(scn, &shdr);
- if (shdr.sh_type == SHT_SYMTAB) {
- symtabidx = shdr.sh_link;
- symtabdata = elf_getdata(scn, NULL);
- } else if (shdr.sh_type == SHT_DYNSYM) {
- dynsymidx = shdr.sh_link;
- dynsymdata = elf_getdata(scn, NULL);
- } else if (shdr.sh_type == SHT_PROGBITS) {
+ if (shdr.sh_type == SHT_SUNW_dof) {
s = elf_strptr(e, shstridx, shdr.sh_name);
- if (s && strcmp(s, ".SUNW_dof") == 0) {
+ if (s != NULL && strcmp(s, ".SUNW_dof") == 0) {
dofdata = elf_getdata(scn, NULL);
dof = dofdata->d_buf;
}
@@ -225,7 +182,6 @@ dtrace_dof_init(void)
}
while ((char *) dof < (char *) dofdata->d_buf + dofdata->d_size) {
- fixedprobes = 0;
dof_next = (void *) ((char *) dof + dof->dofh_filesz);
#endif
@@ -273,76 +229,6 @@ dtrace_dof_init(void)
return;
#endif
}
-#if !defined(sun)
- /*
- * We need to fix the base address of each probe since this wasn't
- * done by ld(1). (ld(1) needs to grow support for parsing the
- * SUNW_dof section).
- *
- * The complexity of this is not that great. The first for loop
- * iterates over the sections inside the DOF file. There are usually
- * 10 sections here. We asume the STRTAB section comes first and the
- * PROBES section comes after. Since we are only interested in fixing
- * data inside the PROBES section we quit the for loop after processing
- * the PROBES section. It's usually the case that the first section
- * is the STRTAB section and the second section is the PROBES section,
- * so this for loop is not meaningful when doing complexity analysis.
- *
- * After finding the probes section, we iterate over the symbols
- * in the symtab section. When we find a symbol name that matches
- * the probe function name, we fix it. If we have fixed all the
- * probes, we exit all the loops and we are done.
- * The number of probes is given by the variable 'nprobes' and this
- * depends entirely on the user, but some optimizations were done.
- *
- * We are assuming the number of probes is less than the number of
- * symbols (libc can have 4k symbols, for example).
- */
- secstart = sec = (dof_sec_t *)(dof + 1);
- buf = (char *)dof;
- for (i = 0; i < dof->dofh_secnum; i++, sec++) {
- if (sec->dofs_type != DOF_SECT_PROVIDER)
- continue;
-
- dofprovider = (void *) (buf + sec->dofs_offset);
- dofstrtab = secstart + dofprovider->dofpv_strtab;
- dofprobes = secstart + dofprovider->dofpv_probes;
-
- if (dofstrtab->dofs_type != DOF_SECT_STRTAB) {
- fprintf(stderr, "WARNING: expected STRTAB section, but got %d\n",
- dofstrtab->dofs_type);
- break;
- }
- if (dofprobes->dofs_type != DOF_SECT_PROBES) {
- fprintf(stderr, "WARNING: expected PROBES section, but got %d\n",
- dofprobes->dofs_type);
- break;
- }
-
- dprintf(1, "found provider %p\n", dofprovider);
- dofstrtabraw = (char *)(buf + dofstrtab->dofs_offset);
- nprobes = dofprobes->dofs_size / dofprobes->dofs_entsize;
- fixsymbol(e, symtabdata, symtabidx, nprobes, buf, dofprobes, &fixedprobes,
- dofstrtabraw);
- if (fixedprobes != nprobes) {
- /*
- * If we haven't fixed all the probes using the
- * symtab section, look inside the dynsym
- * section.
- */
- fixsymbol(e, dynsymdata, dynsymidx, nprobes, buf, dofprobes,
- &fixedprobes, dofstrtabraw);
- }
- if (fixedprobes != nprobes) {
- fprintf(stderr, "WARNING: number of probes "
- "fixed does not match the number of "
- "defined probes (%d != %d, "
- "respectively)\n", fixedprobes, nprobes);
- fprintf(stderr, "WARNING: some probes might "
- "not fire or your program might crash\n");
- }
- }
-#endif
if ((gen = ioctl(fd, DTRACEHIOC_ADDDOF, &dh)) == -1)
dprintf(1, "DTrace ioctl failed for DOF at %p", dof);
else {
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c
index ae1ed00..072cb05 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c
@@ -2944,7 +2944,7 @@ dt_get_buf(dtrace_hdl_t *dtp, int cpu, dtrace_bufdesc_t **bufp)
{
dtrace_optval_t size;
dtrace_bufdesc_t *buf = dt_zalloc(dtp, sizeof (*buf));
- int error;
+ int error, rval;
if (buf == NULL)
return (-1);
@@ -2963,7 +2963,6 @@ dt_get_buf(dtrace_hdl_t *dtp, int cpu, dtrace_bufdesc_t **bufp)
#else
if (dt_ioctl(dtp, DTRACEIOC_BUFSNAP, &buf) == -1) {
#endif
- dt_put_buf(dtp, buf);
/*
* If we failed with ENOENT, it may be because the
* CPU was unconfigured -- this is okay. Any other
@@ -2971,10 +2970,12 @@ dt_get_buf(dtrace_hdl_t *dtp, int cpu, dtrace_bufdesc_t **bufp)
*/
if (errno == ENOENT) {
*bufp = NULL;
- return (0);
- }
+ rval = 0;
+ } else
+ rval = dt_set_errno(dtp, errno);
- return (dt_set_errno(dtp, errno));
+ dt_put_buf(dtp, buf);
+ return (rval);
}
error = dt_unring_buf(dtp, buf);
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_dof.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_dof.c
index 5442683..0b531c5 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_dof.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_dof.c
@@ -469,7 +469,7 @@ dof_add_probe(dt_idhash_t *dhp, dt_ident_t *idp, void *data)
* locally so an alternate symbol is added for the purpose
* of this relocation.
*/
- if (pip->pi_rname[0] == '\0')
+ if (pip->pi_rname == NULL)
dofr.dofr_name = dofpr.dofpr_func;
else
dofr.dofr_name = dof_add_string(ddo, pip->pi_rname);
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_grammar.y b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_grammar.y
index 07790f4..6321b65 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_grammar.y
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_grammar.y
@@ -207,6 +207,8 @@
%type <l_tok> unary_operator
%type <l_tok> struct_or_union
+%type <l_str> dtrace_keyword_ident
+
%%
dtrace_program: d_expression DT_TOK_EOF { return (dt_node_root($1)); }
@@ -391,12 +393,18 @@ postfix_expression:
| postfix_expression DT_TOK_DOT DT_TOK_TNAME {
$$ = OP2(DT_TOK_DOT, $1, dt_node_ident($3));
}
+ | postfix_expression DT_TOK_DOT dtrace_keyword_ident {
+ $$ = OP2(DT_TOK_DOT, $1, dt_node_ident($3));
+ }
| postfix_expression DT_TOK_PTR DT_TOK_IDENT {
$$ = OP2(DT_TOK_PTR, $1, dt_node_ident($3));
}
| postfix_expression DT_TOK_PTR DT_TOK_TNAME {
$$ = OP2(DT_TOK_PTR, $1, dt_node_ident($3));
}
+ | postfix_expression DT_TOK_PTR dtrace_keyword_ident {
+ $$ = OP2(DT_TOK_PTR, $1, dt_node_ident($3));
+ }
| postfix_expression DT_TOK_ADDADD {
$$ = OP1(DT_TOK_POSTINC, $1);
}
@@ -411,6 +419,10 @@ postfix_expression:
DT_TOK_TNAME DT_TOK_RPAR {
$$ = dt_node_offsetof($3, $5);
}
+ | DT_TOK_OFFSETOF DT_TOK_LPAR type_name DT_TOK_COMMA
+ dtrace_keyword_ident DT_TOK_RPAR {
+ $$ = dt_node_offsetof($3, $5);
+ }
| DT_TOK_XLATE DT_TOK_LT type_name DT_TOK_GT
DT_TOK_LPAR expression DT_TOK_RPAR {
$$ = OP2(DT_TOK_XLATE, dt_node_type($3), $6);
@@ -835,4 +847,15 @@ function_parameters:
| parameter_type_list { $$ = $1; }
;
+dtrace_keyword_ident:
+ DT_KEY_PROBE { $$ = DUP("probe"); }
+ | DT_KEY_PROVIDER { $$ = DUP("provider"); }
+ | DT_KEY_SELF { $$ = DUP("self"); }
+ | DT_KEY_STRING { $$ = DUP("string"); }
+ | DT_TOK_STRINGOF { $$ = DUP("stringof"); }
+ | DT_KEY_USERLAND { $$ = DUP("userland"); }
+ | DT_TOK_XLATE { $$ = DUP("xlate"); }
+ | DT_KEY_XLATOR { $$ = DUP("translator"); }
+ ;
+
%%
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_impl.h b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_impl.h
index b7abbc2..8cf5fe2 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_impl.h
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_impl.h
@@ -723,6 +723,11 @@ extern int _dtrace_argmax; /* default maximum probe arguments */
extern const char *_dtrace_libdir; /* default library directory */
extern const char *_dtrace_moddir; /* default kernel module directory */
+#ifdef __FreeBSD__
+extern int gmatch(const char *, const char *);
+extern int yylex(void);
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c
index 2a43211..597fef4 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c
@@ -322,7 +322,11 @@ prepare_elf64(dtrace_hdl_t *dtp, const dof_hdr_t *dof, dof_elf64_t *dep)
char *strtab;
int i, j, nrel;
size_t strtabsz = 1;
+#if defined(sun)
uint32_t count = 0;
+#else
+ uint64_t count = 0;
+#endif
size_t base;
Elf64_Sym *sym;
Elf64_Rela *rel;
@@ -418,7 +422,6 @@ prepare_elf64(dtrace_hdl_t *dtp, const dof_hdr_t *dof, dof_elf64_t *dep)
s = &dofs[dofrh->dofr_tgtsec];
for (j = 0; j < nrel; j++) {
-#ifdef DOODAD
#if defined(__arm__)
/* XXX */
#elif defined(__mips__)
@@ -431,8 +434,13 @@ prepare_elf64(dtrace_hdl_t *dtp, const dof_hdr_t *dof, dof_elf64_t *dep)
#elif defined(__i386) || defined(__amd64)
rel->r_offset = s->dofs_offset +
dofr[j].dofr_offset;
+#if defined(sun)
rel->r_info = ELF64_R_INFO(count + dep->de_global,
R_AMD64_64);
+#else
+ rel->r_info = ELF64_R_INFO(count + dep->de_global,
+ R_X86_64_RELATIVE);
+#endif
#elif defined(__sparc)
rel->r_offset = s->dofs_offset +
dofr[j].dofr_offset;
@@ -441,7 +449,6 @@ prepare_elf64(dtrace_hdl_t *dtp, const dof_hdr_t *dof, dof_elf64_t *dep)
#else
#error unknown ISA
#endif
-#endif
sym->st_name = base + dofr[j].dofr_name - 1;
sym->st_value = 0;
@@ -704,7 +711,11 @@ dump_elf64(dtrace_hdl_t *dtp, const dof_hdr_t *dof, int fd)
shp = &elf_file.shdr[ESHDR_DOF];
shp->sh_name = 11; /* DTRACE_SHSTRTAB64[11] = ".SUNW_dof" */
+#if defined(sun)
shp->sh_flags = SHF_ALLOC;
+#else
+ shp->sh_flags = SHF_WRITE | SHF_ALLOC;
+#endif
shp->sh_type = SHT_SUNW_dof;
shp->sh_offset = off;
shp->sh_size = dof->dofh_filesz;
@@ -1662,19 +1673,6 @@ dtrace_program_link(dtrace_hdl_t *dtp, dtrace_prog_t *pgp, uint_t dflags,
{
#if !defined(sun)
char tfile[PATH_MAX];
- Elf *e;
- Elf_Scn *scn;
- Elf_Data *data;
- GElf_Shdr shdr;
- int efd;
- size_t stridx;
- unsigned char *buf;
- char *s;
- int loc;
- GElf_Ehdr ehdr;
- Elf_Scn *scn0;
- GElf_Shdr shdr0;
- uint64_t off, rc;
#endif
char drti[PATH_MAX];
dof_hdr_t *dof;
@@ -1810,21 +1808,21 @@ dtrace_program_link(dtrace_hdl_t *dtp, dtrace_prog_t *pgp, uint_t dflags,
(void) unlink(file);
#endif
-#if defined(sun)
if (dtp->dt_oflags & DTRACE_O_LP64)
status = dump_elf64(dtp, dof, fd);
else
status = dump_elf32(dtp, dof, fd);
+#if defined(sun)
if (status != 0 || lseek(fd, 0, SEEK_SET) != 0) {
return (dt_link_error(dtp, NULL, -1, NULL,
"failed to write %s: %s", file, strerror(errno)));
}
#else
- /* We don't write the ELF header, just the DOF section */
- if (dt_write(dtp, fd, dof, dof->dofh_filesz) < dof->dofh_filesz)
+ if (status != 0)
return (dt_link_error(dtp, NULL, -1, NULL,
- "failed to write %s: %s", tfile, strerror(errno)));
+ "failed to write %s: %s", tfile,
+ strerror(dtrace_errno(dtp))));
#endif
if (!dtp->dt_lazyload) {
@@ -1846,7 +1844,7 @@ dtrace_program_link(dtrace_hdl_t *dtp, dtrace_prog_t *pgp, uint_t dflags,
(void) snprintf(cmd, len, fmt, dtp->dt_ld_path, file, fd, drti);
#else
- const char *fmt = "%s -o %s -r %s";
+ const char *fmt = "%s -o %s -r %s %s";
#if defined(__amd64__)
/*
@@ -1868,10 +1866,9 @@ dtrace_program_link(dtrace_hdl_t *dtp, dtrace_prog_t *pgp, uint_t dflags,
len = snprintf(&tmp, 1, fmt, dtp->dt_ld_path, file, tfile,
drti) + 1;
- len *= 2;
cmd = alloca(len);
- (void) snprintf(cmd, len, fmt, dtp->dt_ld_path, file,
+ (void) snprintf(cmd, len, fmt, dtp->dt_ld_path, file, tfile,
drti);
#endif
if ((status = system(cmd)) == -1) {
@@ -1894,137 +1891,6 @@ dtrace_program_link(dtrace_hdl_t *dtp, dtrace_prog_t *pgp, uint_t dflags,
file, dtp->dt_ld_path, WEXITSTATUS(status));
goto done;
}
-#if !defined(sun)
-#define BROKEN_LIBELF
- /*
- * FreeBSD's ld(1) is not instructed to interpret and add
- * correctly the SUNW_dof section present in tfile.
- * We use libelf to add this section manually and hope the next
- * ld invocation won't remove it.
- */
- elf_version(EV_CURRENT);
- if ((efd = open(file, O_RDWR, 0)) < 0) {
- ret = dt_link_error(dtp, NULL, -1, NULL,
- "failed to open file %s: %s",
- file, strerror(errno));
- goto done;
- }
- if ((e = elf_begin(efd, ELF_C_RDWR, NULL)) == NULL) {
- close(efd);
- ret = dt_link_error(dtp, NULL, -1, NULL,
- "failed to open elf file: %s",
- elf_errmsg(elf_errno()));
- goto done;
- }
- /*
- * Add the string '.SUWN_dof' to the shstrtab section.
- */
-#ifdef BROKEN_LIBELF
- elf_flagelf(e, ELF_C_SET, ELF_F_LAYOUT);
-#endif
- elf_getshdrstrndx(e, &stridx);
- scn = elf_getscn(e, stridx);
- gelf_getshdr(scn, &shdr);
- data = elf_newdata(scn);
- data->d_off = shdr.sh_size;
- data->d_buf = ".SUNW_dof";
- data->d_size = 10;
- data->d_type = ELF_T_BYTE;
- loc = shdr.sh_size;
- shdr.sh_size += data->d_size;
- gelf_update_shdr(scn, &shdr);
-#ifdef BROKEN_LIBELF
- off = shdr.sh_offset;
- rc = shdr.sh_offset + shdr.sh_size;
- gelf_getehdr(e, &ehdr);
- if (ehdr.e_shoff > off) {
- off = ehdr.e_shoff + ehdr.e_shnum * ehdr.e_shentsize;
- rc = roundup(rc, 8);
- ehdr.e_shoff = rc;
- gelf_update_ehdr(e, &ehdr);
- rc += ehdr.e_shnum * ehdr.e_shentsize;
- }
- for (;;) {
- scn0 = NULL;
- scn = NULL;
- while ((scn = elf_nextscn(e, scn)) != NULL) {
- gelf_getshdr(scn, &shdr);
- if (shdr.sh_type == SHT_NOBITS ||
- shdr.sh_offset < off)
- continue;
- /* Find the immediately adjcent section. */
- if (scn0 == NULL ||
- shdr.sh_offset < shdr0.sh_offset) {
- scn0 = scn;
- gelf_getshdr(scn0, &shdr0);
- }
- }
- if (scn0 == NULL)
- break;
- /* Load section data to work around another bug */
- elf_getdata(scn0, NULL);
- /* Update section header, assure section alignment */
- off = shdr0.sh_offset + shdr0.sh_size;
- rc = roundup(rc, shdr0.sh_addralign);
- shdr0.sh_offset = rc;
- gelf_update_shdr(scn0, &shdr0);
- rc += shdr0.sh_size;
- }
- if (elf_update(e, ELF_C_WRITE) < 0) {
- ret = dt_link_error(dtp, NULL, -1, NULL,
- "failed to add append the shstrtab section: %s",
- elf_errmsg(elf_errno()));
- elf_end(e);
- close(efd);
- goto done;
- }
- elf_end(e);
- e = elf_begin(efd, ELF_C_RDWR, NULL);
-#endif
- /*
- * Construct the .SUNW_dof section.
- */
- scn = elf_newscn(e);
- data = elf_newdata(scn);
- buf = mmap(NULL, dof->dofh_filesz, PROT_READ, MAP_SHARED,
- fd, 0);
- if (buf == MAP_FAILED) {
- ret = dt_link_error(dtp, NULL, -1, NULL,
- "failed to mmap buffer %s", strerror(errno));
- elf_end(e);
- close(efd);
- goto done;
- }
- data->d_buf = buf;
- data->d_align = 4;
- data->d_size = dof->dofh_filesz;
- data->d_version = EV_CURRENT;
- gelf_getshdr(scn, &shdr);
- shdr.sh_name = loc;
- shdr.sh_flags = SHF_ALLOC;
- /*
- * Actually this should be SHT_SUNW_dof, but FreeBSD's ld(1)
- * will remove this 'unknown' section when we try to create an
- * executable using the object we are modifying, so we stop
- * playing by the rules and use SHT_PROGBITS.
- * Also, note that our drti has modifications to handle this.
- */
- shdr.sh_type = SHT_PROGBITS;
- shdr.sh_addralign = 4;
- gelf_update_shdr(scn, &shdr);
- if (elf_update(e, ELF_C_WRITE) < 0) {
- ret = dt_link_error(dtp, NULL, -1, NULL,
- "failed to add the SUNW_dof section: %s",
- elf_errmsg(elf_errno()));
- munmap(buf, dof->dofh_filesz);
- elf_end(e);
- close(efd);
- goto done;
- }
- munmap(buf, dof->dofh_filesz);
- elf_end(e);
- close(efd);
-#endif
(void) close(fd); /* release temporary file */
} else {
(void) close(fd);
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_map.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_map.c
index c6d92c8..6ab7cd9 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_map.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_map.c
@@ -39,7 +39,7 @@
static int
dt_strdata_add(dtrace_hdl_t *dtp, dtrace_recdesc_t *rec, void ***data, int *max)
{
- int maxformat;
+ int maxformat, rval;
dtrace_fmtdesc_t fmt;
void *result;
@@ -63,8 +63,9 @@ dt_strdata_add(dtrace_hdl_t *dtp, dtrace_recdesc_t *rec, void ***data, int *max)
return (dt_set_errno(dtp, EDT_NOMEM));
if (dt_ioctl(dtp, DTRACEIOC_FORMAT, &fmt) == -1) {
+ rval = dt_set_errno(dtp, errno);
free(fmt.dtfd_string);
- return (dt_set_errno(dtp, errno));
+ return (rval);
}
while (rec->dtrd_format > (maxformat = *max)) {
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c
index f6c140b..0eb2a2c 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c
@@ -29,6 +29,11 @@
#if defined(sun)
#include <sys/modctl.h>
#include <sys/systeminfo.h>
+#else
+/* FreeBSD */
+#include <sys/param.h>
+#include <sys/module.h>
+#include <sys/linker.h>
#endif
#include <sys/resource.h>
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pid.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pid.c
index c865a2d..6c529e5 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pid.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pid.c
@@ -434,15 +434,10 @@ static const prmap_t *
dt_pid_fix_mod(dtrace_probedesc_t *pdp, struct ps_prochandle *P)
{
char m[MAXPATHLEN];
-#if defined(sun)
Lmid_t lmid = PR_LMID_EVERY;
-#else
- Lmid_t lmid = 0;
-#endif
const char *obj;
const prmap_t *pmp;
-#if defined(sun)
/*
* Pick apart the link map from the library name.
*/
@@ -463,20 +458,17 @@ dt_pid_fix_mod(dtrace_probedesc_t *pdp, struct ps_prochandle *P)
} else {
obj = pdp->dtpd_mod;
}
-#else
- obj = pdp->dtpd_mod;
-#endif
if ((pmp = Plmid_to_map(P, lmid, obj)) == NULL)
return (NULL);
-#if defined(sun)
(void) Pobjname(P, pmp->pr_vaddr, m, sizeof (m));
if ((obj = strrchr(m, '/')) == NULL)
obj = &m[0];
else
obj++;
+#if defined(sun)
(void) Plmid(P, pmp->pr_vaddr, &lmid);
#endif
@@ -571,9 +563,7 @@ dt_pid_usdt_mapping(void *data, const prmap_t *pmp, const char *oname)
{
struct ps_prochandle *P = data;
GElf_Sym sym;
-#if defined(sun)
prsyminfo_t sip;
-#endif
dof_helper_t dh;
GElf_Half e_type;
const char *mname;
@@ -852,11 +842,7 @@ dt_pid_get_types(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp,
ctf_funcinfo_t f;
ctf_id_t argv[32];
GElf_Sym sym;
-#if defined(sun)
prsyminfo_t si;
-#else
- void *si;
-#endif
struct ps_prochandle *p;
int i, args;
char buf[DTRACE_ARGTYPELEN];
@@ -941,13 +927,11 @@ dt_pid_get_types(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp,
pdp->dtpd_func, pdp->dtpd_provider, pdp->dtpd_mod);
goto out;
}
-#if defined(sun)
if (ctf_func_info(fp, si.prs_id, &f) == CTF_ERR) {
dt_dprintf("failed to get ctf information for %s in %s`%s\n",
pdp->dtpd_func, pdp->dtpd_provider, pdp->dtpd_mod);
goto out;
}
-#endif
(void) snprintf(buf, sizeof (buf), "%s`%s", pdp->dtpd_provider,
pdp->dtpd_mod);
@@ -977,7 +961,6 @@ dt_pid_get_types(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp,
(void) ctf_type_qname(fp, f.ctc_return, adp->dtargd_native +
ret, DTRACE_ARGTYPELEN - ret, buf);
*nargs = 2;
-#if defined(sun)
} else {
if (ctf_func_args(fp, si.prs_id, argc, argv) == CTF_ERR)
goto out;
@@ -993,7 +976,6 @@ dt_pid_get_types(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp,
(void) ctf_type_qname(fp, argv[i], adp->dtargd_native +
ret, DTRACE_ARGTYPELEN - ret, buf);
}
-#endif
}
out:
dt_proc_unlock(dtp, p);
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pragma.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pragma.c
index 760c2f6..7f49f64 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pragma.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pragma.c
@@ -36,6 +36,7 @@
#include <stdio.h>
#include <sys/types.h>
+#include <sys/sysctl.h>
#include <sys/stat.h>
#include <dt_parser.h>
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_print.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_print.c
index fb8ea16..4be0f03 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_print.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_print.c
@@ -167,7 +167,7 @@ print_bitfield(dt_printarg_t *pap, ulong_t off, ctf_encoding_t *ep)
* to the lowest 'size' bytes in 'value', and we need to shift based on
* the offset from the end of the data, not the offset of the start.
*/
-#ifdef _BIG_ENDIAN
+#if BYTE_ORDER == _BIG_ENDIAN
buf += sizeof (value) - size;
off += ep->cte_bits;
#endif
@@ -178,7 +178,7 @@ print_bitfield(dt_printarg_t *pap, ulong_t off, ctf_encoding_t *ep)
* Offsets are counted from opposite ends on little- and
* big-endian machines.
*/
-#ifdef _BIG_ENDIAN
+#if BYTE_ORDER == _BIG_ENDIAN
shift = NBBY - shift;
#endif
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_provider.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_provider.c
index 0f1bfe0..6acb86b 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_provider.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_provider.c
@@ -520,6 +520,8 @@ dt_probe_destroy(dt_probe_t *prp)
for (pip = prp->pr_inst; pip != NULL; pip = pip_next) {
pip_next = pip->pi_next;
+ dt_free(dtp, pip->pi_rname);
+ dt_free(dtp, pip->pi_fname);
dt_free(dtp, pip->pi_offs);
dt_free(dtp, pip->pi_enoffs);
dt_free(dtp, pip);
@@ -552,28 +554,18 @@ dt_probe_define(dt_provider_t *pvp, dt_probe_t *prp,
if ((pip = dt_zalloc(dtp, sizeof (*pip))) == NULL)
return (-1);
- if ((pip->pi_offs = dt_zalloc(dtp,
- sizeof (uint32_t))) == NULL) {
- dt_free(dtp, pip);
- return (-1);
- }
+ if ((pip->pi_offs = dt_zalloc(dtp, sizeof (uint32_t))) == NULL)
+ goto nomem;
if ((pip->pi_enoffs = dt_zalloc(dtp,
- sizeof (uint32_t))) == NULL) {
- dt_free(dtp, pip->pi_offs);
- dt_free(dtp, pip);
- return (-1);
- }
+ sizeof (uint32_t))) == NULL)
+ goto nomem;
- (void) strlcpy(pip->pi_fname, fname, sizeof (pip->pi_fname));
- if (rname != NULL) {
- if (strlen(rname) + 1 > sizeof (pip->pi_rname)) {
- dt_free(dtp, pip->pi_offs);
- dt_free(dtp, pip);
- return (dt_set_errno(dtp, EDT_COMPILER));
- }
- (void) strcpy(pip->pi_rname, rname);
- }
+ if ((pip->pi_fname = strdup(fname)) == NULL)
+ goto nomem;
+
+ if (rname != NULL && (pip->pi_rname = strdup(rname)) == NULL)
+ goto nomem;
pip->pi_noffs = 0;
pip->pi_maxoffs = 1;
@@ -618,6 +610,13 @@ dt_probe_define(dt_provider_t *pvp, dt_probe_t *prp,
(*offs)[(*noffs)++] = offset;
return (0);
+
+nomem:
+ dt_free(dtp, pip->pi_fname);
+ dt_free(dtp, pip->pi_enoffs);
+ dt_free(dtp, pip->pi_offs);
+ dt_free(dtp, pip);
+ return (dt_set_errno(dtp, EDT_NOMEM));
}
/*
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_provider.h b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_provider.h
index af4ec33..2752baa 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_provider.h
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_provider.h
@@ -64,8 +64,8 @@ typedef struct dt_probe_iter {
} dt_probe_iter_t;
typedef struct dt_probe_instance {
- char pi_fname[DTRACE_FUNCNAMELEN]; /* function name */
- char pi_rname[DTRACE_FUNCNAMELEN + 20]; /* mangled relocation name */
+ char *pi_fname; /* function name */
+ char *pi_rname; /* mangled relocation name */
uint32_t *pi_offs; /* offsets into the function */
uint32_t *pi_enoffs; /* is-enabled offsets */
uint_t pi_noffs; /* number of offsets */
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_work.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_work.c
index 68e64bb..d19fb88 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_work.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_work.c
@@ -184,7 +184,7 @@ dtrace_go(dtrace_hdl_t *dtp)
{
dtrace_enable_io_t args;
void *dof;
- int err;
+ int error, r;
if (dtp->dt_active)
return (dt_set_errno(dtp, EINVAL));
@@ -206,11 +206,12 @@ dtrace_go(dtrace_hdl_t *dtp)
args.dof = dof;
args.n_matched = 0;
- err = dt_ioctl(dtp, DTRACEIOC_ENABLE, &args);
+ r = dt_ioctl(dtp, DTRACEIOC_ENABLE, &args);
+ error = errno;
dtrace_dof_destroy(dtp, dof);
- if (err == -1 && (errno != ENOTTY || dtp->dt_vector == NULL))
- return (dt_set_errno(dtp, errno));
+ if (r == -1 && (error != ENOTTY || dtp->dt_vector == NULL))
+ return (dt_set_errno(dtp, error));
if (dt_ioctl(dtp, DTRACEIOC_GO, &dtp->dt_beganon) == -1) {
if (errno == EACCES)
OpenPOWER on IntegriCloud