xref: /illumos-gate/usr/src/cmd/mdb/common/kmdb/kmdb_stubs.c (revision 7c478bd95313f5f23a4c958a745db2134aa0324)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * Stubs for basic system services otherwise unavailable to the debugger.
31*7c478bd9Sstevel@tonic-gate  */
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
34*7c478bd9Sstevel@tonic-gate #include <unistd.h>
35*7c478bd9Sstevel@tonic-gate #include <libproc.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/time.h>
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #include <kmdb/kmdb_dpi.h>
39*7c478bd9Sstevel@tonic-gate #include <kmdb/kmdb_promif.h>
40*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_debug.h>
41*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_signal.h>
42*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_io_impl.h>
43*7c478bd9Sstevel@tonic-gate #include <mdb/mdb.h>
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
46*7c478bd9Sstevel@tonic-gate char *
47*7c478bd9Sstevel@tonic-gate getenv(const char *name)
48*7c478bd9Sstevel@tonic-gate {
49*7c478bd9Sstevel@tonic-gate 	/* There aren't any environment variables here */
50*7c478bd9Sstevel@tonic-gate 	return (NULL);
51*7c478bd9Sstevel@tonic-gate }
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate char *
54*7c478bd9Sstevel@tonic-gate strerror(int errnum)
55*7c478bd9Sstevel@tonic-gate {
56*7c478bd9Sstevel@tonic-gate 	static char errnostr[16];
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate 	(void) mdb_snprintf(errnostr, sizeof (errnostr), "Error %d", errnum);
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate 	return (errnostr);
61*7c478bd9Sstevel@tonic-gate }
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate pid_t
64*7c478bd9Sstevel@tonic-gate getpid(void)
65*7c478bd9Sstevel@tonic-gate {
66*7c478bd9Sstevel@tonic-gate 	return (1);
67*7c478bd9Sstevel@tonic-gate }
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate /*
70*7c478bd9Sstevel@tonic-gate  * We're trying to isolate ourselves from the rest of the world as much as
71*7c478bd9Sstevel@tonic-gate  * possible, so we can't rely on the time in the kernel proper.  For now, we
72*7c478bd9Sstevel@tonic-gate  * just bump a counter whenever time is requested, thus guaranteeing that
73*7c478bd9Sstevel@tonic-gate  * things with timestamps can be compared according to order of occurrance.
74*7c478bd9Sstevel@tonic-gate  */
75*7c478bd9Sstevel@tonic-gate hrtime_t
76*7c478bd9Sstevel@tonic-gate gethrtime(void)
77*7c478bd9Sstevel@tonic-gate {
78*7c478bd9Sstevel@tonic-gate 	static hrtime_t kmdb_timestamp;
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate 	return (++kmdb_timestamp);
81*7c478bd9Sstevel@tonic-gate }
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate /*
84*7c478bd9Sstevel@tonic-gate  * Signal handling
85*7c478bd9Sstevel@tonic-gate  */
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
88*7c478bd9Sstevel@tonic-gate int
89*7c478bd9Sstevel@tonic-gate sigemptyset(sigset_t *set)
90*7c478bd9Sstevel@tonic-gate {
91*7c478bd9Sstevel@tonic-gate 	return (0);
92*7c478bd9Sstevel@tonic-gate }
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
95*7c478bd9Sstevel@tonic-gate int
96*7c478bd9Sstevel@tonic-gate sigaddset(sigset_t *set, int signo)
97*7c478bd9Sstevel@tonic-gate {
98*7c478bd9Sstevel@tonic-gate 	return (0);
99*7c478bd9Sstevel@tonic-gate }
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
102*7c478bd9Sstevel@tonic-gate int
103*7c478bd9Sstevel@tonic-gate sigfillset(sigset_t *set)
104*7c478bd9Sstevel@tonic-gate {
105*7c478bd9Sstevel@tonic-gate 	return (0);
106*7c478bd9Sstevel@tonic-gate }
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
109*7c478bd9Sstevel@tonic-gate int
110*7c478bd9Sstevel@tonic-gate sigprocmask(int how, const sigset_t *set, sigset_t *oset)
111*7c478bd9Sstevel@tonic-gate {
112*7c478bd9Sstevel@tonic-gate 	return (0);
113*7c478bd9Sstevel@tonic-gate }
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
116*7c478bd9Sstevel@tonic-gate int
117*7c478bd9Sstevel@tonic-gate sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
118*7c478bd9Sstevel@tonic-gate {
119*7c478bd9Sstevel@tonic-gate 	return (0);
120*7c478bd9Sstevel@tonic-gate }
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
123*7c478bd9Sstevel@tonic-gate int
124*7c478bd9Sstevel@tonic-gate kill(pid_t pid, int sig)
125*7c478bd9Sstevel@tonic-gate {
126*7c478bd9Sstevel@tonic-gate 	if (sig == SIGABRT) {
127*7c478bd9Sstevel@tonic-gate 		mdb_printf("Debugger aborted\n");
128*7c478bd9Sstevel@tonic-gate 		exit(1);
129*7c478bd9Sstevel@tonic-gate 	}
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate 	return (0);
132*7c478bd9Sstevel@tonic-gate }
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
135*7c478bd9Sstevel@tonic-gate int
136*7c478bd9Sstevel@tonic-gate proc_str2flt(const char *buf, int *ptr)
137*7c478bd9Sstevel@tonic-gate {
138*7c478bd9Sstevel@tonic-gate 	return (-1);
139*7c478bd9Sstevel@tonic-gate }
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
142*7c478bd9Sstevel@tonic-gate int
143*7c478bd9Sstevel@tonic-gate proc_str2sig(const char *buf, int *ptr)
144*7c478bd9Sstevel@tonic-gate {
145*7c478bd9Sstevel@tonic-gate 	return (-1);
146*7c478bd9Sstevel@tonic-gate }
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
149*7c478bd9Sstevel@tonic-gate int
150*7c478bd9Sstevel@tonic-gate proc_str2sys(const char *buf, int *ptr)
151*7c478bd9Sstevel@tonic-gate {
152*7c478bd9Sstevel@tonic-gate 	return (-1);
153*7c478bd9Sstevel@tonic-gate }
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
156*7c478bd9Sstevel@tonic-gate void
157*7c478bd9Sstevel@tonic-gate exit(int status)
158*7c478bd9Sstevel@tonic-gate {
159*7c478bd9Sstevel@tonic-gate #ifdef __sparc
160*7c478bd9Sstevel@tonic-gate 	kmdb_prom_exit_to_mon();
161*7c478bd9Sstevel@tonic-gate #else
162*7c478bd9Sstevel@tonic-gate 	extern void kmdb_dpi_reboot(void) __NORETURN;
163*7c478bd9Sstevel@tonic-gate 	static int recurse = 0;
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 	if (!recurse) {
166*7c478bd9Sstevel@tonic-gate 		char c;
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate 		recurse = 1;
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate 		mdb_iob_printf(mdb.m_out, "Press any key to reboot\n");
171*7c478bd9Sstevel@tonic-gate 		mdb_iob_flush(mdb.m_out);
172*7c478bd9Sstevel@tonic-gate 
173*7c478bd9Sstevel@tonic-gate 		while (IOP_READ(mdb.m_term, &c, 1) != 1)
174*7c478bd9Sstevel@tonic-gate 			continue;
175*7c478bd9Sstevel@tonic-gate 		mdb_iob_printf(mdb.m_out, "%c%s", c, (c == '\n' ? "" : "\n"));
176*7c478bd9Sstevel@tonic-gate 	}
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate 	kmdb_dpi_reboot();
179*7c478bd9Sstevel@tonic-gate #endif
180*7c478bd9Sstevel@tonic-gate }
181