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.
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.
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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * Copyright (c) 2012 by Delphix. All rights reserved.
32 * This is the basis for drti.o which dt_link.c links into the object file
33 * generated by dtrace(1M) -G by default (note that -xlazyload disables this).
43 static int gen
; /* DOF helper generation */
44 extern dof_hdr_t __SUNW_dof
; /* DOF defined in the .SUNW_dof section */
46 #pragma init(dtrace_drti_init)
48 dtrace_drti_init(void)
55 if (dlinfo(RTLD_SELF
, RTLD_DI_LINKMAP
, &lmp
) == -1 || lmp
== NULL
) {
56 dprintf(1, "couldn't discover module name or address\n");
60 if (dlinfo(RTLD_SELF
, RTLD_DI_LMID
, &lmid
) == -1) {
61 dprintf(1, "couldn't discover link map ID\n");
65 dtrace_link_dof(&__SUNW_dof
, lmid
, lmp
->l_name
, lmp
->l_addr
);
68 #pragma fini(dtrace_drti_fini)
70 dtrace_drti_fini(void)
74 if ((fd
= open64(devname
, O_RDWR
)) < 0) {
75 dprintf(1, "failed to open helper device %s", devname
);
79 if ((gen
= ioctl(fd
, DTRACEHIOC_REMOVE
, gen
)) == -1)
80 dprintf(1, "DTrace ioctl failed to remove DOF (%d)\n", gen
);
82 dprintf(1, "DTrace ioctl removed DOF (%d)\n", gen
);