4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
38 #include <libproc_compat.h>
42 dt_pid_create_entry_probe(struct ps_prochandle *P, dtrace_hdl_t *dtp,
43 fasttrap_probe_spec_t *ftp, const GElf_Sym *symp)
45 ftp->ftps_type = DTFTP_ENTRY;
46 ftp->ftps_pc = (uintptr_t)symp->st_value;
47 ftp->ftps_size = (size_t)symp->st_size;
49 ftp->ftps_offs[0] = 0;
51 if (ioctl(dtp->dt_ftfd, FASTTRAPIOC_MAKEPROBE, ftp) != 0) {
52 dt_dprintf("fasttrap probe creation ioctl failed: %s\n",
54 return (dt_set_errno(dtp, errno));
61 dt_pid_create_return_probe(struct ps_prochandle *P, dtrace_hdl_t *dtp,
62 fasttrap_probe_spec_t *ftp, const GElf_Sym *symp, uint64_t *stret)
70 if ((text = malloc(symp->st_size + 4)) == NULL) {
71 dt_dprintf("mr sparkle: malloc() failed\n");
75 if (Pread(P, text, symp->st_size, symp->st_value) != symp->st_size) {
76 dt_dprintf("mr sparkle: Pread() failed\n");
82 * Leave a dummy instruction in the last slot to simplify edge
85 text[symp->st_size / 4] = 0;
87 ftp->ftps_type = DTFTP_RETURN;
88 ftp->ftps_pc = symp->st_value;
89 ftp->ftps_size = symp->st_size;
92 for (i = 0; i < symp->st_size / 4; i++) {
94 if ((text[i] & 0xfc000001) != 0x48000000 &&
95 text[i] != 0x4e800020)
99 * Check for a jump within this function. If it's outside this
100 * function then it's a tail-call, so a return point.
102 if ((text[i] & 0xfc000000) == 0x48000000) {
103 temp = (text[i] & 0x03fffffc);
104 /* Bit 30 denotes an absolute address. */
105 if (!(text[i] & 0x02)) {
106 temp += symp->st_value + i * 4;
109 /* Sign extend the absolute address. */
110 if (temp & 0x02000000) {
111 temp |= (UINTPTR_MAX - 0x03ffffff);
114 if (temp >= symp->st_value &&
115 temp <= (symp->st_value + symp->st_size))
118 dt_dprintf("return at offset %x\n", i * 4);
119 ftp->ftps_offs[ftp->ftps_noffs++] = i * 4;
123 if (ftp->ftps_noffs > 0) {
124 if (ioctl(dtp->dt_ftfd, FASTTRAPIOC_MAKEPROBE, ftp) != 0) {
125 dt_dprintf("fasttrap probe creation ioctl failed: %s\n",
127 return (dt_set_errno(dtp, errno));
132 return (ftp->ftps_noffs);
137 dt_pid_create_offset_probe(struct ps_prochandle *P, dtrace_hdl_t *dtp,
138 fasttrap_probe_spec_t *ftp, const GElf_Sym *symp, ulong_t off)
141 return (DT_PROC_ALIGN);
143 ftp->ftps_type = DTFTP_OFFSETS;
144 ftp->ftps_pc = (uintptr_t)symp->st_value;
145 ftp->ftps_size = (size_t)symp->st_size;
147 ftp->ftps_offs[0] = off;
149 if (ioctl(dtp->dt_ftfd, FASTTRAPIOC_MAKEPROBE, ftp) != 0) {
150 dt_dprintf("fasttrap probe creation ioctl failed: %s\n",
152 return (dt_set_errno(dtp, errno));
160 dt_pid_create_glob_offset_probes(struct ps_prochandle *P, dtrace_hdl_t *dtp,
161 fasttrap_probe_spec_t *ftp, const GElf_Sym *symp, const char *pattern)
165 ftp->ftps_type = DTFTP_OFFSETS;
166 ftp->ftps_pc = (uintptr_t)symp->st_value;
167 ftp->ftps_size = (size_t)symp->st_size;
171 * If we're matching against everything, just iterate through each
172 * instruction in the function, otherwise look for matching offset
173 * names by constructing the string and comparing it against the
176 if (strcmp("*", pattern) == 0) {
177 for (i = 0; i < symp->st_size; i += 4) {
178 ftp->ftps_offs[ftp->ftps_noffs++] = i;
181 char name[sizeof (i) * 2 + 1];
183 for (i = 0; i < symp->st_size; i += 4) {
184 (void) sprintf(name, "%lx", i);
185 if (gmatch(name, pattern))
186 ftp->ftps_offs[ftp->ftps_noffs++] = i;
190 if (ioctl(dtp->dt_ftfd, FASTTRAPIOC_MAKEPROBE, ftp) != 0) {
191 dt_dprintf("fasttrap probe creation ioctl failed: %s\n",
193 return (dt_set_errno(dtp, errno));
196 return (ftp->ftps_noffs);