Changeset View
Changeset View
Standalone View
Standalone View
head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_options.c
Show All 32 Lines | |||||
#include <sys/mman.h> | #include <sys/mman.h> | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <strings.h> | #include <strings.h> | ||||
#include <signal.h> | #include <signal.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <limits.h> | #include <limits.h> | ||||
#ifdef illumos | |||||
#include <alloca.h> | |||||
#endif | |||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <dt_impl.h> | #include <dt_impl.h> | ||||
#include <dt_string.h> | #include <dt_string.h> | ||||
static int | static int | ||||
dt_opt_agg(dtrace_hdl_t *dtp, const char *arg, uintptr_t option) | dt_opt_agg(dtrace_hdl_t *dtp, const char *arg, uintptr_t option) | ||||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | dt_opt_cpp_path(dtrace_hdl_t *dtp, const char *arg, uintptr_t option) | ||||
dtp->dt_cpp_path = cpp; | dtp->dt_cpp_path = cpp; | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
dt_opt_cpp_opts(dtrace_hdl_t *dtp, const char *arg, uintptr_t option) | dt_opt_cpp_opts(dtrace_hdl_t *dtp, const char *arg, uintptr_t option) | ||||
{ | { | ||||
char *buf; | char *buf = NULL; | ||||
size_t len; | size_t len; | ||||
const char *opt = (const char *)option; | const char *opt = (const char *)option; | ||||
int ret; | |||||
if (opt == NULL || arg == NULL) | if (opt == NULL || arg == NULL) { | ||||
return (dt_set_errno(dtp, EDT_BADOPTVAL)); | ret = dt_set_errno(dtp, EDT_BADOPTVAL); | ||||
goto out; | |||||
} | |||||
if (dtp->dt_pcb != NULL) | if (dtp->dt_pcb != NULL) { | ||||
return (dt_set_errno(dtp, EDT_BADOPTCTX)); | ret = dt_set_errno(dtp, EDT_BADOPTCTX); | ||||
goto out; | |||||
} | |||||
len = strlen(opt) + strlen(arg) + 1; | len = strlen(opt) + strlen(arg) + 1; | ||||
buf = alloca(len); | if ((buf = dt_alloc(dtp, len)) == NULL) { | ||||
ret = dt_set_errno(dtp, EDT_NOMEM); | |||||
goto out; | |||||
} | |||||
(void) strcpy(buf, opt); | (void) strcpy(buf, opt); | ||||
(void) strcat(buf, arg); | (void) strcat(buf, arg); | ||||
if (dt_cpp_add_arg(dtp, buf) == NULL) | if (dt_cpp_add_arg(dtp, buf) == NULL) { | ||||
return (dt_set_errno(dtp, EDT_NOMEM)); | ret = dt_set_errno(dtp, EDT_NOMEM); | ||||
goto out; | |||||
} | |||||
return (0); | ret = 0; | ||||
out: | |||||
if (buf != NULL) | |||||
dt_free(dtp, buf); | |||||
return (ret); | |||||
} | } | ||||
/*ARGSUSED*/ | /*ARGSUSED*/ | ||||
static int | static int | ||||
dt_opt_ctypes(dtrace_hdl_t *dtp, const char *arg, uintptr_t option) | dt_opt_ctypes(dtrace_hdl_t *dtp, const char *arg, uintptr_t option) | ||||
{ | { | ||||
int fd; | int fd; | ||||
▲ Show 20 Lines • Show All 687 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
int | int | ||||
dt_options_load(dtrace_hdl_t *dtp) | dt_options_load(dtrace_hdl_t *dtp) | ||||
{ | { | ||||
dof_hdr_t hdr, *dof; | dof_hdr_t hdr, *dof; | ||||
dof_sec_t *sec; | dof_sec_t *sec; | ||||
size_t offs; | size_t offs; | ||||
int i; | int i, ret; | ||||
/* | /* | ||||
* To load the option values, we need to ask the kernel to provide its | * To load the option values, we need to ask the kernel to provide its | ||||
* DOF, which we'll sift through to look for OPTDESC sections. | * DOF, which we'll sift through to look for OPTDESC sections. | ||||
*/ | */ | ||||
dof = &hdr; | |||||
bzero(&hdr, sizeof (dof_hdr_t)); | bzero(&hdr, sizeof (dof_hdr_t)); | ||||
hdr.dofh_loadsz = sizeof (dof_hdr_t); | hdr.dofh_loadsz = sizeof (dof_hdr_t); | ||||
#ifdef illumos | #ifdef illumos | ||||
if (dt_ioctl(dtp, DTRACEIOC_DOFGET, &hdr) == -1) | if (dt_ioctl(dtp, DTRACEIOC_DOFGET, dof) == -1) | ||||
#else | #else | ||||
dof = &hdr; | |||||
if (dt_ioctl(dtp, DTRACEIOC_DOFGET, &dof) == -1) | if (dt_ioctl(dtp, DTRACEIOC_DOFGET, &dof) == -1) | ||||
#endif | #endif | ||||
return (dt_set_errno(dtp, errno)); | { | ||||
ret = dt_set_errno(dtp, errno); | |||||
goto out; | |||||
} | |||||
if (hdr.dofh_loadsz < sizeof (dof_hdr_t)) | if (hdr.dofh_loadsz < sizeof (dof_hdr_t)) { | ||||
return (dt_set_errno(dtp, EINVAL)); | ret = dt_set_errno(dtp, EINVAL); | ||||
goto out; | |||||
} | |||||
dof = alloca(hdr.dofh_loadsz); | if ((dof = dt_alloc(dtp, hdr.dofh_loadsz)) == NULL) { | ||||
ret = dt_set_errno(dtp, EDT_NOMEM); | |||||
goto out; | |||||
} | |||||
bzero(dof, sizeof (dof_hdr_t)); | bzero(dof, sizeof (dof_hdr_t)); | ||||
dof->dofh_loadsz = hdr.dofh_loadsz; | dof->dofh_loadsz = hdr.dofh_loadsz; | ||||
for (i = 0; i < DTRACEOPT_MAX; i++) | for (i = 0; i < DTRACEOPT_MAX; i++) | ||||
dtp->dt_options[i] = DTRACEOPT_UNSET; | dtp->dt_options[i] = DTRACEOPT_UNSET; | ||||
#ifdef illumos | #ifdef illumos | ||||
if (dt_ioctl(dtp, DTRACEIOC_DOFGET, dof) == -1) | if (dt_ioctl(dtp, DTRACEIOC_DOFGET, dof) == -1) | ||||
#else | #else | ||||
if (dt_ioctl(dtp, DTRACEIOC_DOFGET, &dof) == -1) | if (dt_ioctl(dtp, DTRACEIOC_DOFGET, &dof) == -1) | ||||
#endif | #endif | ||||
return (dt_set_errno(dtp, errno)); | { | ||||
ret = dt_set_errno(dtp, errno); | |||||
goto out; | |||||
} | |||||
for (i = 0; i < dof->dofh_secnum; i++) { | for (i = 0; i < dof->dofh_secnum; i++) { | ||||
sec = (dof_sec_t *)(uintptr_t)((uintptr_t)dof + | sec = (dof_sec_t *)(uintptr_t)((uintptr_t)dof + | ||||
dof->dofh_secoff + i * dof->dofh_secsize); | dof->dofh_secoff + i * dof->dofh_secsize); | ||||
if (sec->dofs_type != DOF_SECT_OPTDESC) | if (sec->dofs_type != DOF_SECT_OPTDESC) | ||||
continue; | continue; | ||||
break; | break; | ||||
} | } | ||||
for (offs = 0; offs < sec->dofs_size; offs += sec->dofs_entsize) { | for (offs = 0; offs < sec->dofs_size; offs += sec->dofs_entsize) { | ||||
dof_optdesc_t *opt = (dof_optdesc_t *)(uintptr_t) | dof_optdesc_t *opt = (dof_optdesc_t *)(uintptr_t) | ||||
((uintptr_t)dof + sec->dofs_offset + offs); | ((uintptr_t)dof + sec->dofs_offset + offs); | ||||
if (opt->dofo_strtab != DOF_SECIDX_NONE) | if (opt->dofo_strtab != DOF_SECIDX_NONE) | ||||
continue; | continue; | ||||
if (opt->dofo_option >= DTRACEOPT_MAX) | if (opt->dofo_option >= DTRACEOPT_MAX) | ||||
continue; | continue; | ||||
dtp->dt_options[opt->dofo_option] = opt->dofo_value; | dtp->dt_options[opt->dofo_option] = opt->dofo_value; | ||||
} | } | ||||
return (0); | ret = 0; | ||||
out: | |||||
if (dof != NULL && dof != &hdr) | |||||
dt_free(dtp, dof); | |||||
return (ret); | |||||
} | } | ||||
typedef struct dt_option { | typedef struct dt_option { | ||||
const char *o_name; | const char *o_name; | ||||
int (*o_func)(dtrace_hdl_t *, const char *, uintptr_t); | int (*o_func)(dtrace_hdl_t *, const char *, uintptr_t); | ||||
uintptr_t o_option; | uintptr_t o_option; | ||||
} dt_option_t; | } dt_option_t; | ||||
▲ Show 20 Lines • Show All 160 Lines • Show Last 20 Lines |