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 (c) 1994, by Sun Microsytems, Inc.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * Interface to close a tnfctl handle
32 #include "tnfctl_int.h"
33 #include "kernel_int.h"
40 /* for bug 1253419 - guard against multiple tracing */
42 extern mutex_t _tnfctl_internalguard_lock
;
45 * Close a tnfctl handle - close any open fds and free up any memory
49 tnfctl_close(tnfctl_handle_t
*hdl
, tnfctl_targ_op_t action
)
51 tnfctl_errcode_t prexstat
;
53 prb_proc_ctl_t
*proc_p
;
54 tnfctl_probe_t
*probe_hdl
, *tmp_hdl
;
57 return (TNFCTL_ERR_NONE
);
59 if (hdl
->mode
== KERNEL_MODE
) {
60 prexstat
= _tnfctl_prbk_close(hdl
);
65 if (hdl
->mode
== INTERNAL_MODE
) {
66 _tnfctl_internal_releaselock();
67 } else if (hdl
->mode
!= KERNEL_MODE
) {
68 _tnfctl_external_releaselock(hdl
);
71 _tnfctl_free_objs_and_probes(hdl
);
73 /* free probe handles */
74 probe_hdl
= hdl
->probe_handle_list_head
;
75 while (probe_hdl
!= NULL
) {
76 /* call the destructor function for client probe data */
77 if (hdl
->destroy_func
)
78 hdl
->destroy_func(probe_hdl
->client_registered_data
);
80 probe_hdl
= probe_hdl
->next
;
83 hdl
->probe_handle_list_head
= NULL
;
85 if (hdl
->mode
!= DIRECT_MODE
) {
86 /* indirect, internal, or kernel mode */
88 return (TNFCTL_ERR_NONE
);
96 return (TNFCTL_ERR_NONE
);
100 case TNFCTL_TARG_DEFAULT
:
102 case TNFCTL_TARG_KILL
:
103 prbstat
= prb_proc_setklc(proc_p
, B_TRUE
);
105 return (_tnfctl_map_to_errcode(prbstat
));
106 prbstat
= prb_proc_setrlc(proc_p
, B_FALSE
);
108 return (_tnfctl_map_to_errcode(prbstat
));
110 case TNFCTL_TARG_RESUME
:
111 prbstat
= prb_proc_setklc(proc_p
, B_FALSE
);
113 return (_tnfctl_map_to_errcode(prbstat
));
114 prbstat
= prb_proc_setrlc(proc_p
, B_TRUE
);
116 return (_tnfctl_map_to_errcode(prbstat
));
118 case TNFCTL_TARG_SUSPEND
:
119 prbstat
= prb_proc_setklc(proc_p
, B_FALSE
);
121 return (_tnfctl_map_to_errcode(prbstat
));
122 prbstat
= prb_proc_setrlc(proc_p
, B_FALSE
);
124 return (_tnfctl_map_to_errcode(prbstat
));
127 return (TNFCTL_ERR_BADARG
);
129 prbstat
= prb_proc_close(proc_p
);
131 return (_tnfctl_map_to_errcode(prbstat
));
135 _tnfctl_internal_releaselock()
137 mutex_lock(&_tnfctl_internalguard_lock
);
138 _tnfctl_internal_tracing_flag
= 0;
139 mutex_unlock(&_tnfctl_internalguard_lock
);
140 return (TNFCTL_ERR_NONE
);
144 _tnfctl_external_releaselock(tnfctl_handle_t
*hdl
)
146 tnfctl_errcode_t prexstat
;
147 prb_status_t prbstat
;
148 uintptr_t targ_symbol_ptr
;
151 prexstat
= _tnfctl_sym_find(hdl
, TNFCTL_EXTERNAL_TRACEDPID
,
156 prbstat
= hdl
->p_write(hdl
->proc_p
, targ_symbol_ptr
,
157 &pidzero
, sizeof (pidzero
));
159 return (_tnfctl_map_to_errcode(prbstat
));
161 return (TNFCTL_ERR_NONE
);