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