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