1 /*
2 * Copyright 1991-1998 by Open Software Foundation, Inc.
3 * All Rights Reserved
4 *
5 * Permission to use, copy, modify, and distribute this software and
6 * its documentation for any purpose and without fee is hereby granted,
7 * provided that the above copyright notice appears in all copies and
8 * that both the copyright notice and this permission notice appear in
9 * supporting documentation.
10 *
11 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
12 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE.
14 *
15 * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
16 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
18 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
19 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 */
21 /*
22 * Mach Operating System
23 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
24 * All Rights Reserved.
25 *
26 * Permission to use, copy, modify and distribute this software and its
27 * documentation is hereby granted, provided that both the copyright
28 * notice and this permission notice appear in all copies of the
29 * software, derivative works or modified versions, and any portions
30 * thereof, and that both notices appear in supporting documentation.
31 *
32 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
33 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
34 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
35 *
36 * Carnegie Mellon requests users of this software to return to
37 *
38 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
39 * School of Computer Science
40 * Carnegie Mellon University
41 * Pittsburgh PA 15213-3890
42 *
43 * any improvements or extensions that they make and grant Carnegie Mellon
44 * the rights to redistribute these changes.
45 */
46 /*
47 * MkLinux
48 */
49
50 #include <mach/boolean.h>
51 #include <mach/error.h>
52 #include <mach/mach_error.h>
53 #include "errorlib.h"
54 #include "externs.h"
55
56 static void do_compat(mach_error_t *);
57
58 static void
do_compat(mach_error_t * org_err)59 do_compat(mach_error_t *org_err)
60 {
61 mach_error_t err = *org_err;
62
63 /*
64 * map old error numbers to
65 * to new error sys & subsystem
66 */
67
68 if ((-200 < err) && (err <= -100))
69 err = -(err + 100) | IPC_SEND_MOD;
70 else if ((-300 < err) && (err <= -200))
71 err = -(err + 200) | IPC_RCV_MOD;
72 else if ((-400 < err) && (err <= -300))
73 err = -(err + 300) | MACH_IPC_MIG_MOD;
74 else if ((1000 <= err) && (err < 1100))
75 err = (err - 1000) | SERV_NETNAME_MOD;
76 else if ((1600 <= err) && (err < 1700))
77 err = (err - 1600) | SERV_ENV_MOD;
78 else if ((27600 <= err) && (err < 27700))
79 err = (err - 27600) | SERV_EXECD_MOD;
80
81 *org_err = err;
82 }
83
84 const char *
mach_error_type(mach_error_t err)85 mach_error_type(mach_error_t err)
86 {
87 int sub, system;
88
89 do_compat( &err );
90
91 sub = err_get_sub(err);
92 system = err_get_system(err);
93
94 if (system > err_max_system || sub >= errors[system].max_sub)
95 return((const char *)"(?/?)");
96 return(errors[system].subsystem[sub].subsys_name);
97 }
98
99 static boolean_t mach_error_full_diag = FALSE;
100
101 const char *
mach_error_string_int(mach_error_t err,boolean_t * diag)102 mach_error_string_int(mach_error_t err, boolean_t *diag)
103 {
104 int sub, system, code;
105
106 do_compat( &err );
107
108 sub = err_get_sub(err);
109 system = err_get_system(err);
110 code = err_get_code(err);
111
112 *diag = TRUE;
113
114 if (system > err_max_system)
115 return((const char *)"(?/?) unknown error system");
116 if (sub >= errors[system].max_sub)
117 return(errors[system].bad_sub);
118 if (code >= errors[system].subsystem[sub].max_code)
119 return ((const char *)NO_SUCH_ERROR);
120
121 *diag = mach_error_full_diag;
122 return( errors[system].subsystem[sub].codes[code] );
123 }
124
125 const char *
mach_error_string(mach_error_t err)126 mach_error_string(mach_error_t err)
127 {
128 boolean_t diag;
129
130 return mach_error_string_int( err, &diag );
131
132 }
133