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