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