4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2015, Joyent, Inc.
25 * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
26 */
27
28 #include <sys/types.h>
29 #include <sys/modctl.h>
30 #include <sys/systeminfo.h>
31 #include <sys/resource.h>
32
33 #include <libelf.h>
34 #include <strings.h>
35 #include <alloca.h>
36 #include <limits.h>
37 #include <unistd.h>
38 #include <stdlib.h>
39 #include <stdio.h>
40 #include <fcntl.h>
41 #include <errno.h>
42 #include <assert.h>
43 #include <zone.h>
44
1130 }
1131
1132 if (err == CTF_ERR) {
1133 dt_dprintf("failed to add %s to C container: %s\n",
1134 dinp->din_name, ctf_errmsg(
1135 ctf_errno(dmp->dm_ctfp)));
1136 return (set_open_errno(dtp, errp, EDT_CTF));
1137 }
1138 }
1139
1140 if (ctf_update(dmp->dm_ctfp) != 0) {
1141 dt_dprintf("failed to update C container: %s\n",
1142 ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1143 return (set_open_errno(dtp, errp, EDT_CTF));
1144 }
1145
1146 /*
1147 * Add intrinsic pointer types that are needed to initialize printf
1148 * format dictionary types (see table in dt_printf.c).
1149 */
1150 (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, NULL,
1151 ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1152
1153 (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, NULL,
1154 ctf_lookup_by_name(dmp->dm_ctfp, "char"));
1155
1156 (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, NULL,
1157 ctf_lookup_by_name(dmp->dm_ctfp, "int"));
1158
1159 if (ctf_update(dmp->dm_ctfp) != 0) {
1160 dt_dprintf("failed to update C container: %s\n",
1161 ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1162 return (set_open_errno(dtp, errp, EDT_CTF));
1163 }
1164
1165 /*
1166 * Create a dynamic CTF container under the "D" scope for types that
1167 * are defined by the D program itself or on-the-fly by the D compiler.
1168 * The "D" CTF container is a child of the "C" CTF container.
1169 */
1170 if ((dmp = dtp->dt_ddefs = dt_module_create(dtp, "D")) == NULL)
1171 return (set_open_errno(dtp, errp, EDT_NOMEM));
1172
1173 if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL)
1174 return (set_open_errno(dtp, errp, EDT_CTF));
1175
1176 dt_dprintf("created CTF container for %s (%p)\n",
1196 for (; dtyp->dty_src != NULL; dtyp++) {
1197 if (ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1198 dtyp->dty_dst, ctf_lookup_by_name(dmp->dm_ctfp,
1199 dtyp->dty_src)) == CTF_ERR) {
1200 dt_dprintf("failed to add typedef %s %s to D "
1201 "container: %s", dtyp->dty_src, dtyp->dty_dst,
1202 ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1203 return (set_open_errno(dtp, errp, EDT_CTF));
1204 }
1205 }
1206
1207 /*
1208 * Insert a CTF ID corresponding to a pointer to a type of kind
1209 * CTF_K_FUNCTION we can use in the compiler for function pointers.
1210 * CTF treats all function pointers as "int (*)()" so we only need one.
1211 */
1212 ctc.ctc_return = ctf_lookup_by_name(dmp->dm_ctfp, "int");
1213 ctc.ctc_argc = 0;
1214 ctc.ctc_flags = 0;
1215
1216 dtp->dt_type_func = ctf_add_funcptr(dmp->dm_ctfp,
1217 CTF_ADD_ROOT, &ctc, NULL);
1218
1219 dtp->dt_type_fptr = ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, NULL,
1220 dtp->dt_type_func);
1221
1222 /*
1223 * We also insert CTF definitions for the special D intrinsic types
1224 * string and <DYN> into the D container. The string type is added
1225 * as a typedef of char[n]. The <DYN> type is an alias for void.
1226 * We compare types to these special CTF ids throughout the compiler.
1227 */
1228 ctr.ctr_contents = ctf_lookup_by_name(dmp->dm_ctfp, "char");
1229 ctr.ctr_index = ctf_lookup_by_name(dmp->dm_ctfp, "long");
1230 ctr.ctr_nelems = _dtrace_strsize;
1231
1232 dtp->dt_type_str = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1233 "string", ctf_add_array(dmp->dm_ctfp, CTF_ADD_ROOT, &ctr));
1234
1235 dtp->dt_type_dyn = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1236 "<DYN>", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1237
1238 dtp->dt_type_stack = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1239 "stack", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1240
|
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
25 * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
26 */
27
28 #include <sys/types.h>
29 #include <sys/modctl.h>
30 #include <sys/systeminfo.h>
31 #include <sys/resource.h>
32
33 #include <libelf.h>
34 #include <strings.h>
35 #include <alloca.h>
36 #include <limits.h>
37 #include <unistd.h>
38 #include <stdlib.h>
39 #include <stdio.h>
40 #include <fcntl.h>
41 #include <errno.h>
42 #include <assert.h>
43 #include <zone.h>
44
1130 }
1131
1132 if (err == CTF_ERR) {
1133 dt_dprintf("failed to add %s to C container: %s\n",
1134 dinp->din_name, ctf_errmsg(
1135 ctf_errno(dmp->dm_ctfp)));
1136 return (set_open_errno(dtp, errp, EDT_CTF));
1137 }
1138 }
1139
1140 if (ctf_update(dmp->dm_ctfp) != 0) {
1141 dt_dprintf("failed to update C container: %s\n",
1142 ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1143 return (set_open_errno(dtp, errp, EDT_CTF));
1144 }
1145
1146 /*
1147 * Add intrinsic pointer types that are needed to initialize printf
1148 * format dictionary types (see table in dt_printf.c).
1149 */
1150 (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT,
1151 ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1152
1153 (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT,
1154 ctf_lookup_by_name(dmp->dm_ctfp, "char"));
1155
1156 (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT,
1157 ctf_lookup_by_name(dmp->dm_ctfp, "int"));
1158
1159 if (ctf_update(dmp->dm_ctfp) != 0) {
1160 dt_dprintf("failed to update C container: %s\n",
1161 ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1162 return (set_open_errno(dtp, errp, EDT_CTF));
1163 }
1164
1165 /*
1166 * Create a dynamic CTF container under the "D" scope for types that
1167 * are defined by the D program itself or on-the-fly by the D compiler.
1168 * The "D" CTF container is a child of the "C" CTF container.
1169 */
1170 if ((dmp = dtp->dt_ddefs = dt_module_create(dtp, "D")) == NULL)
1171 return (set_open_errno(dtp, errp, EDT_NOMEM));
1172
1173 if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL)
1174 return (set_open_errno(dtp, errp, EDT_CTF));
1175
1176 dt_dprintf("created CTF container for %s (%p)\n",
1196 for (; dtyp->dty_src != NULL; dtyp++) {
1197 if (ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1198 dtyp->dty_dst, ctf_lookup_by_name(dmp->dm_ctfp,
1199 dtyp->dty_src)) == CTF_ERR) {
1200 dt_dprintf("failed to add typedef %s %s to D "
1201 "container: %s", dtyp->dty_src, dtyp->dty_dst,
1202 ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1203 return (set_open_errno(dtp, errp, EDT_CTF));
1204 }
1205 }
1206
1207 /*
1208 * Insert a CTF ID corresponding to a pointer to a type of kind
1209 * CTF_K_FUNCTION we can use in the compiler for function pointers.
1210 * CTF treats all function pointers as "int (*)()" so we only need one.
1211 */
1212 ctc.ctc_return = ctf_lookup_by_name(dmp->dm_ctfp, "int");
1213 ctc.ctc_argc = 0;
1214 ctc.ctc_flags = 0;
1215
1216 dtp->dt_type_func = ctf_add_function(dmp->dm_ctfp,
1217 CTF_ADD_ROOT, &ctc, NULL);
1218
1219 dtp->dt_type_fptr = ctf_add_pointer(dmp->dm_ctfp,
1220 CTF_ADD_ROOT, dtp->dt_type_func);
1221
1222 /*
1223 * We also insert CTF definitions for the special D intrinsic types
1224 * string and <DYN> into the D container. The string type is added
1225 * as a typedef of char[n]. The <DYN> type is an alias for void.
1226 * We compare types to these special CTF ids throughout the compiler.
1227 */
1228 ctr.ctr_contents = ctf_lookup_by_name(dmp->dm_ctfp, "char");
1229 ctr.ctr_index = ctf_lookup_by_name(dmp->dm_ctfp, "long");
1230 ctr.ctr_nelems = _dtrace_strsize;
1231
1232 dtp->dt_type_str = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1233 "string", ctf_add_array(dmp->dm_ctfp, CTF_ADD_ROOT, &ctr));
1234
1235 dtp->dt_type_dyn = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1236 "<DYN>", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1237
1238 dtp->dt_type_stack = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1239 "stack", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1240
|