Lines Matching +full:libelf +full:- +full:dev

39 #include <libelf.h>
104 * previously worked; for example, adding a new built-in variable could break
107 * do not affect backward compatibility -- this is merely to make capabilities
552 * Tables of ILP32 intrinsic integer and floating-point type templates to use
588 * Tables of LP64 intrinsic integer and floating-point type templates to use
680 * Tables of ILP32 integer type templates used to populate the dtp->dt_ints[]
693 * Tables of LP64 integer type templates used to populate the dtp->dt_ints[]
725 * Hard-wired definition string to be compiled and cached every time a new
798 const char *_dtrace_provdir = "/dev/dtrace/provider"; /* provider directory */
801 const char *_dtrace_provdir = "/dev/dtrace"; /* provider directory */
833 for (; _dtrace_rdvers > 0; _dtrace_rdvers--) {
838 /* make long doubles 64 bits -sson */
870 if (dp->d_name[0] == '.')
873 if (dfp->df_ents == dfp->df_size) {
874 uint_t size = dfp->df_size ? dfp->df_size * 2 : 16;
875 int *fds = realloc(dfp->df_fds, size * sizeof (int));
880 dfp->df_fds = fds;
881 dfp->df_size = size;
885 _dtrace_provdir, dp->d_name);
887 if ((fd = open(path, O_RDONLY)) == -1)
891 (prov->dp_name = malloc(strlen(dp->d_name) + 1)) == NULL) {
897 (void) strcpy(prov->dp_name, dp->d_name);
898 prov->dp_next = *provmod;
901 dt_dprintf("opened provider %s\n", dp->d_name);
902 dfp->df_fds[dfp->df_ents++] = fd;
935 } else if (error == -1 && errno == ENOMEM) {
960 if (dfp->df_ents == dfp->df_size) {
961 uint_t size = dfp->df_size ? dfp->df_size * 2 : 16;
962 int *fds = realloc(dfp->df_fds, size * sizeof (int));
967 dfp->df_fds = fds;
968 dfp->df_size = size;
971 (void) snprintf(path, sizeof (path), "/dev/dtrace/%s", p1);
973 if ((fd = open(path, O_RDONLY | O_CLOEXEC)) == -1)
977 (prov->dp_name = malloc(strlen(p1) + 1)) == NULL) {
983 (void) strcpy(prov->dp_name, p1);
984 prov->dp_next = *provmod;
988 dfp->df_fds[dfp->df_ents++] = fd;
1002 next = current->dp_next;
1003 free(current->dp_name);
1032 int dtfd = -1, ftfd = -1, fterr = 0;
1116 dtfd = open("/dev/dtrace/dtrace", O_RDWR | O_CLOEXEC);
1117 err = dtfd == -1 ? errno : 0; /* save errno from opening dtfd */
1134 dtfd = open("/dev/dtrace/dtrace", O_RDWR | O_CLOEXEC);
1139 ftfd = open("/dev/dtrace/provider/fasttrap", O_RDWR);
1141 ftfd = open("/dev/dtrace/fasttrap", O_RDWR | O_CLOEXEC);
1143 fterr = ftfd == -1 ? errno : 0; /* save errno from open ftfd */
1145 while (df.df_ents-- != 0)
1155 if (dtfd == -1) {
1178 dtp->dt_oflags = flags;
1180 dtp->dt_prcmode = DT_PROC_STOP_PREINIT;
1182 dtp->dt_prcmode = DT_PROC_STOP_POSTINIT;
1184 dtp->dt_linkmode = DT_LINK_KERNEL;
1185 dtp->dt_linktype = DT_LTYP_ELF;
1186 dtp->dt_xlatemode = DT_XL_STATIC;
1187 dtp->dt_stdcmode = DT_STDC_XA;
1188 dtp->dt_encoding = DT_ENCODING_UNSET;
1189 dtp->dt_version = version;
1190 dtp->dt_fd = dtfd;
1191 dtp->dt_ftfd = ftfd;
1192 dtp->dt_kinstfd = -1;
1193 dtp->dt_fterr = fterr;
1194 dtp->dt_cdefs_fd = -1;
1195 dtp->dt_ddefs_fd = -1;
1197 dtp->dt_stdout_fd = -1;
1199 dtp->dt_freopen_fp = NULL;
1201 dtp->dt_modbuckets = _dtrace_strbuckets;
1202 dtp->dt_mods = calloc(dtp->dt_modbuckets, sizeof (dt_module_t *));
1204 dtp->dt_kmods = calloc(dtp->dt_modbuckets, sizeof (dt_module_t *));
1206 dtp->dt_provbuckets = _dtrace_strbuckets;
1207 dtp->dt_provs = calloc(dtp->dt_provbuckets, sizeof (dt_provider_t *));
1209 dtp->dt_vmax = DT_VERS_LATEST;
1210 dtp->dt_cpp_path = strdup(_dtrace_defcpp);
1211 dtp->dt_cpp_argv = malloc(sizeof (char *));
1212 dtp->dt_cpp_argc = 1;
1213 dtp->dt_cpp_args = 1;
1214 dtp->dt_ld_path = strdup(_dtrace_defld);
1216 dtp->dt_objcopy_path = strdup(_dtrace_defobjcopy);
1218 dtp->dt_provmod = provmod;
1219 dtp->dt_vector = vector;
1220 dtp->dt_varg = arg;
1222 (void) uname(&dtp->dt_uts);
1224 if (dtp->dt_mods == NULL || dtp->dt_provs == NULL ||
1225 dtp->dt_procs == NULL || dtp->dt_proc_env == NULL ||
1226 dtp->dt_ld_path == NULL || dtp->dt_cpp_path == NULL ||
1228 dtp->dt_kmods == NULL ||
1229 dtp->dt_objcopy_path == NULL ||
1231 dtp->dt_cpp_argv == NULL)
1235 dtp->dt_options[i] = DTRACEOPT_UNSET;
1237 dtp->dt_cpp_argv[0] = (char *)strbasename(dtp->dt_cpp_path);
1240 (void) snprintf(isadef, sizeof (isadef), "-D__SUNW_D_%u",
1243 (void) snprintf(utsdef, sizeof (utsdef), "-D__%s_%s",
1247 if (dt_cpp_add_arg(dtp, "-D__sun") == NULL ||
1248 dt_cpp_add_arg(dtp, "-D__unix") == NULL ||
1249 dt_cpp_add_arg(dtp, "-D__SVR4") == NULL ||
1250 dt_cpp_add_arg(dtp, "-D__SUNW_D=1") == NULL ||
1257 bcopy(&_dtrace_conf, &dtp->dt_conf, sizeof (_dtrace_conf));
1258 else if (dt_ioctl(dtp, DTRACEIOC_CONF, &dtp->dt_conf) != 0)
1262 dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_LP64;
1264 dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_ILP32;
1269 * and __sparcv9 is defined if we are doing a 64-bit compile.
1271 if (dt_cpp_add_arg(dtp, "-D__sparc") == NULL)
1274 if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64 &&
1275 dt_cpp_add_arg(dtp, "-D__sparcv9") == NULL)
1282 * On x86 systems, __i386 is defined for <sys/isa_defs.h> for 32-bit
1283 * compiles and __amd64 is defined for 64-bit compiles. Unlike SPARC,
1286 if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64) {
1287 if (dt_cpp_add_arg(dtp, "-D__amd64") == NULL)
1290 if (dt_cpp_add_arg(dtp, "-D__i386") == NULL)
1296 if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64) {
1297 if (dt_cpp_add_arg(dtp, "-m64") == NULL)
1300 if (dt_cpp_add_arg(dtp, "-m32") == NULL)
1306 if (dtp->dt_conf.dtc_difversion < DIF_VERSION)
1309 if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32)
1310 bcopy(_dtrace_ints_32, dtp->dt_ints, sizeof (_dtrace_ints_32));
1312 bcopy(_dtrace_ints_64, dtp->dt_ints, sizeof (_dtrace_ints_64));
1315 * On FreeBSD the kernel module name can't be hard-coded. The
1346 dtp->dt_macros = dt_idhash_create("macro", NULL, 0, UINT_MAX);
1347 dtp->dt_aggs = dt_idhash_create("aggregation", NULL,
1350 dtp->dt_globals = dt_idhash_create("global", _dtrace_globals,
1353 dtp->dt_tls = dt_idhash_create("thread local", NULL,
1356 if (dtp->dt_macros == NULL || dtp->dt_aggs == NULL ||
1357 dtp->dt_globals == NULL || dtp->dt_tls == NULL)
1365 for (idp = _dtrace_macros; idp->di_name != NULL; idp++) {
1366 if (dt_idhash_insert(dtp->dt_macros, idp->di_name,
1367 idp->di_kind, idp->di_flags, idp->di_id, idp->di_attr,
1368 idp->di_vers, idp->di_ops ? idp->di_ops : &dt_idops_thaw,
1369 idp->di_iarg, 0) == NULL)
1383 if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32) {
1393 * types and types defined in ANSI-C header files that are included.
1395 if ((dmp = dtp->dt_cdefs = dt_module_create(dtp, "C")) == NULL)
1398 if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL)
1402 dmp->dm_name, (void *)dmp->dm_ctfp);
1404 (void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel);
1405 ctf_setspecific(dmp->dm_ctfp, dmp);
1407 dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */
1408 dmp->dm_modid = -1; /* no module ID */
1412 * integer and floating-point types appropriate for this data model.
1414 for (; dinp->din_name != NULL; dinp++) {
1415 if (dinp->din_kind == CTF_K_INTEGER) {
1416 err = ctf_add_integer(dmp->dm_ctfp, CTF_ADD_ROOT,
1417 dinp->din_name, &dinp->din_data);
1419 err = ctf_add_float(dmp->dm_ctfp, CTF_ADD_ROOT,
1420 dinp->din_name, &dinp->din_data);
1425 dinp->din_name, ctf_errmsg(
1426 ctf_errno(dmp->dm_ctfp)));
1431 if (ctf_update(dmp->dm_ctfp) != 0) {
1433 ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1441 (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT,
1442 ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1444 (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT,
1445 ctf_lookup_by_name(dmp->dm_ctfp, "char"));
1447 (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT,
1448 ctf_lookup_by_name(dmp->dm_ctfp, "int"));
1450 if (ctf_update(dmp->dm_ctfp) != 0) {
1452 ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1458 * are defined by the D program itself or on-the-fly by the D compiler.
1461 if ((dmp = dtp->dt_ddefs = dt_module_create(dtp, "D")) == NULL)
1464 if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL)
1468 dmp->dm_name, (void *)dmp->dm_ctfp);
1470 (void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel);
1471 ctf_setspecific(dmp->dm_ctfp, dmp);
1473 dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */
1474 dmp->dm_modid = -1; /* no module ID */
1476 if (ctf_import(dmp->dm_ctfp, dtp->dt_cdefs->dm_ctfp) == CTF_ERR) {
1478 ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1483 * Fill the dynamic "D" CTF container with all of the built-in typedefs
1487 for (; dtyp->dty_src != NULL; dtyp++) {
1488 if (ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1489 dtyp->dty_dst, ctf_lookup_by_name(dmp->dm_ctfp,
1490 dtyp->dty_src)) == CTF_ERR) {
1492 "container: %s\n", dtyp->dty_src, dtyp->dty_dst,
1493 ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1503 ctc.ctc_return = ctf_lookup_by_name(dmp->dm_ctfp, "int");
1507 dtp->dt_type_func = ctf_add_function(dmp->dm_ctfp,
1510 dtp->dt_type_fptr = ctf_add_pointer(dmp->dm_ctfp,
1511 CTF_ADD_ROOT, dtp->dt_type_func);
1519 ctr.ctr_contents = ctf_lookup_by_name(dmp->dm_ctfp, "char");
1520 ctr.ctr_index = ctf_lookup_by_name(dmp->dm_ctfp, "long");
1523 dtp->dt_type_str = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1524 "string", ctf_add_array(dmp->dm_ctfp, CTF_ADD_ROOT, &ctr));
1526 dtp->dt_type_dyn = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1527 "<DYN>", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1529 dtp->dt_type_stack = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1530 "stack", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1532 dtp->dt_type_symaddr = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1533 "_symaddr", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1535 dtp->dt_type_usymaddr = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1536 "_usymaddr", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1538 if (dtp->dt_type_func == CTF_ERR || dtp->dt_type_fptr == CTF_ERR ||
1539 dtp->dt_type_str == CTF_ERR || dtp->dt_type_dyn == CTF_ERR ||
1540 dtp->dt_type_stack == CTF_ERR || dtp->dt_type_symaddr == CTF_ERR ||
1541 dtp->dt_type_usymaddr == CTF_ERR) {
1543 ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1547 if (ctf_update(dmp->dm_ctfp) != 0) {
1549 ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1558 for (i = 0; i < sizeof (dtp->dt_ints) / sizeof (dtp->dt_ints[0]); i++) {
1560 dtp->dt_ints[i].did_name, &dtt) != 0) {
1562 dtp->dt_ints[i].did_name,
1564 return (set_open_errno(dtp, errp, dtp->dt_errno));
1566 dtp->dt_ints[i].did_ctfp = dtt.dtt_ctfp;
1567 dtp->dt_ints[i].did_type = dtt.dtt_type;
1575 dt_list_delete(&dtp->dt_modlist, dtp->dt_ddefs);
1576 dt_list_prepend(&dtp->dt_modlist, dtp->dt_ddefs);
1578 dt_list_delete(&dtp->dt_modlist, dtp->dt_cdefs);
1579 dt_list_prepend(&dtp->dt_modlist, dtp->dt_cdefs);
1581 if (dt_pfdict_create(dtp) == -1)
1582 return (set_open_errno(dtp, errp, dtp->dt_errno));
1586 * because without /dev/dtrace open, we will not be able to load the
1590 dtp->dt_cflags |= DTRACE_C_ZDEFS;
1593 * Load hard-wired inlines into the definition cache by calling the
1598 dt_dprintf("failed to load hard-wired definitions: %s\n",
1614 if ((dtp->dt_oflags & DTRACE_O_ILP32) != 0) {
1616 return (set_open_errno(dtp, errp, dtp->dt_errno));
1620 return (set_open_errno(dtp, errp, dtp->dt_errno));
1623 return (set_open_errno(dtp, errp, dtp->dt_errno));
1657 if (dtp->dt_procs != NULL)
1660 while ((pgp = dt_list_next(&dtp->dt_programs)) != NULL)
1663 while ((dxp = dt_list_next(&dtp->dt_xlators)) != NULL)
1666 dt_free(dtp, dtp->dt_xlatormap);
1668 for (idp = dtp->dt_externs; idp != NULL; idp = ndp) {
1669 ndp = idp->di_next;
1673 if (dtp->dt_macros != NULL)
1674 dt_idhash_destroy(dtp->dt_macros);
1675 if (dtp->dt_aggs != NULL)
1676 dt_idhash_destroy(dtp->dt_aggs);
1677 if (dtp->dt_globals != NULL)
1678 dt_idhash_destroy(dtp->dt_globals);
1679 if (dtp->dt_tls != NULL)
1680 dt_idhash_destroy(dtp->dt_tls);
1683 for (h = 0; h < dtp->dt_modbuckets; h++)
1684 while ((dkm = dtp->dt_kmods[h]) != NULL) {
1685 dtp->dt_kmods[h] = dkm->dkm_next;
1686 free(dkm->dkm_name);
1691 while ((dmp = dt_list_next(&dtp->dt_modlist)) != NULL)
1694 while ((pvp = dt_list_next(&dtp->dt_provlist)) != NULL)
1697 if (dtp->dt_fd != -1)
1698 (void) close(dtp->dt_fd);
1699 if (dtp->dt_ftfd != -1)
1700 (void) close(dtp->dt_ftfd);
1701 if (dtp->dt_kinstfd != -1)
1702 (void) close(dtp->dt_kinstfd);
1703 if (dtp->dt_cdefs_fd != -1)
1704 (void) close(dtp->dt_cdefs_fd);
1705 if (dtp->dt_ddefs_fd != -1)
1706 (void) close(dtp->dt_ddefs_fd);
1708 if (dtp->dt_stdout_fd != -1)
1709 (void) close(dtp->dt_stdout_fd);
1711 if (dtp->dt_freopen_fp != NULL)
1712 (void) fclose(dtp->dt_freopen_fp);
1722 dt_provmod_destroy(&dtp->dt_provmod);
1725 for (i = 1; i < dtp->dt_cpp_argc; i++)
1726 free(dtp->dt_cpp_argv[i]);
1728 while ((dirp = dt_list_next(&dtp->dt_lib_path)) != NULL) {
1729 dt_list_delete(&dtp->dt_lib_path, dirp);
1730 free(dirp->dir_path);
1734 free(dtp->dt_cpp_argv);
1735 free(dtp->dt_cpp_path);
1736 free(dtp->dt_ld_path);
1738 free(dtp->dt_objcopy_path);
1741 free(dtp->dt_mods);
1743 free(dtp->dt_kmods);
1745 free(dtp->dt_provs);
1757 for (prov = dtp->dt_provmod; prov != NULL; prov = prov->dp_next, i++) {
1759 mods[i] = prov->dp_name;
1768 return (dtp->dt_fd);